mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extracted tests for PyConvertFormatOperatorToMethodIntention
This commit is contained in:
+4
-5
@@ -84,7 +84,8 @@ public class PyStringConcatenationToFormatIntention extends BaseIntentionAction
|
||||
List<PyExpression> res = new ArrayList<PyExpression>();
|
||||
if (expression.getLeftExpression() instanceof PyBinaryExpression) {
|
||||
res.addAll(getSimpleExpressions((PyBinaryExpression) expression.getLeftExpression()));
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
res.add(expression.getLeftExpression());
|
||||
}
|
||||
if (expression.getRightExpression() instanceof PyBinaryExpression) {
|
||||
@@ -108,10 +109,8 @@ public class PyStringConcatenationToFormatIntention extends BaseIntentionAction
|
||||
}
|
||||
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
PsiElement element = PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PyBinaryExpression.class, false);
|
||||
while (element != null && element.getParent() instanceof PyBinaryExpression) {
|
||||
element = element.getParent();
|
||||
}
|
||||
PsiElement element = PsiTreeUtil.getTopmostParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PyBinaryExpression.class);
|
||||
|
||||
if (element == null) return;
|
||||
final LanguageLevel languageLevel = LanguageLevel.forElement(element);
|
||||
final boolean useFormatMethod = languageLevel.isAtLeast(LanguageLevel.PYTHON27);
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
'x' +<caret> u'привет'
|
||||
+1
@@ -0,0 +1 @@
|
||||
u'xпривет'
|
||||
+4
-4
@@ -9,18 +9,18 @@ import com.jetbrains.python.psi.LanguageLevel;
|
||||
public class PyConvertFormatOperatorToMethodIntentionTest extends PyIntentionTestCase {
|
||||
|
||||
public void testSimple() {
|
||||
doIntentionTest(PyBundle.message("INTN.replace.with.method"), LanguageLevel.PYTHON26);
|
||||
doTest(PyBundle.message("INTN.replace.with.method"), LanguageLevel.PYTHON26);
|
||||
}
|
||||
|
||||
public void testMulti() {
|
||||
doIntentionTest(PyBundle.message("INTN.replace.with.method"), LanguageLevel.PYTHON26);
|
||||
doTest(PyBundle.message("INTN.replace.with.method"), LanguageLevel.PYTHON26);
|
||||
}
|
||||
|
||||
public void testEscaped() {
|
||||
doIntentionTest(PyBundle.message("INTN.replace.with.method"), LanguageLevel.PYTHON26);
|
||||
doTest(PyBundle.message("INTN.replace.with.method"), LanguageLevel.PYTHON26);
|
||||
}
|
||||
|
||||
public void testUnicode() {
|
||||
doIntentionTest(PyBundle.message("INTN.replace.with.method"), LanguageLevel.PYTHON26);
|
||||
doTest(PyBundle.message("INTN.replace.with.method"), LanguageLevel.PYTHON26);
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -8,7 +8,7 @@ import com.jetbrains.python.PyBundle;
|
||||
public class PyConvertMethodToPropertyIntentionTest extends PyIntentionTestCase {
|
||||
|
||||
public void testParamList() throws Exception {
|
||||
doNegateIntentionTest(PyBundle.message("INTN.convert.method.to.property"));
|
||||
doNegativeTest(PyBundle.message("INTN.convert.method.to.property"));
|
||||
}
|
||||
|
||||
public void testSimple() throws Exception {
|
||||
@@ -16,11 +16,11 @@ public class PyConvertMethodToPropertyIntentionTest extends PyIntentionTestCase
|
||||
}
|
||||
|
||||
public void testProperty() throws Exception {
|
||||
doNegateIntentionTest(PyBundle.message("INTN.convert.method.to.property"));
|
||||
doNegativeTest(PyBundle.message("INTN.convert.method.to.property"));
|
||||
}
|
||||
|
||||
public void testEmptyReturn() throws Exception {
|
||||
doNegateIntentionTest(PyBundle.message("INTN.convert.method.to.property"));
|
||||
doNegativeTest(PyBundle.message("INTN.convert.method.to.property"));
|
||||
}
|
||||
|
||||
public void testYield() throws Exception {
|
||||
@@ -28,7 +28,7 @@ public class PyConvertMethodToPropertyIntentionTest extends PyIntentionTestCase
|
||||
}
|
||||
|
||||
public void testNoReturn() throws Exception {
|
||||
doNegateIntentionTest(PyBundle.message("INTN.convert.method.to.property"));
|
||||
doNegativeTest(PyBundle.message("INTN.convert.method.to.property"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -128,38 +128,6 @@ public class PyIntentionTest extends PyTestCase {
|
||||
doTest(PyBundle.message("INTN.negate.$0.to.$1", ">", "<="));
|
||||
}
|
||||
|
||||
public void testStringConcatToFormat() {
|
||||
doTest(PyBundle.message("INTN.replace.plus.with.format.operator"), LanguageLevel.PYTHON25);
|
||||
}
|
||||
|
||||
public void testStringConcatToFormat1() { //PY-5226
|
||||
doTest(PyBundle.message("INTN.replace.plus.with.format.operator"), LanguageLevel.PYTHON25);
|
||||
}
|
||||
|
||||
public void testStringConcatToFormat2() { //PY-6505
|
||||
runWithLanguageLevel(LanguageLevel.PYTHON25, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
doNegativeTest(PyBundle.message("INTN.replace.plus.with.format.operator"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testStringConcatToFormat3() { //PY-6505
|
||||
doTest(PyBundle.message("INTN.replace.plus.with.format.operator"), LanguageLevel.PYTHON25);
|
||||
}
|
||||
|
||||
public void testStringConcatToFormat4() { //PY-7969
|
||||
doNegativeTest(PyBundle.message("INTN.replace.plus.with.format.operator"));
|
||||
}
|
||||
|
||||
public void testStringConcatToFormat5() { //PY-7968
|
||||
doNegativeTest(PyBundle.message("INTN.replace.plus.with.format.operator"));
|
||||
}
|
||||
|
||||
public void testStringConcatToFormatPy3() { //PY-4706
|
||||
doTest(PyBundle.message("INTN.replace.plus.with.str.format"), LanguageLevel.PYTHON33);
|
||||
}
|
||||
|
||||
public void testFlipComparison() {
|
||||
doTest(PyBundle.message("INTN.flip.$0.to.$1", ">", "<"));
|
||||
@@ -390,20 +358,6 @@ public class PyIntentionTest extends PyTestCase {
|
||||
doTest(PyBundle.message("INTN.yield.from"), LanguageLevel.PYTHON33);
|
||||
}
|
||||
|
||||
public void testUnicodeStringConcatToFormat() { //PY-7463
|
||||
doTest(PyBundle.message("INTN.replace.plus.with.format.operator"), LanguageLevel.PYTHON25);
|
||||
}
|
||||
|
||||
// PY-8366
|
||||
public void testStringConcatToFormatEscapingPy3() {
|
||||
doTest(PyBundle.message("INTN.replace.plus.with.str.format"), LanguageLevel.PYTHON33);
|
||||
}
|
||||
|
||||
// PY-8588
|
||||
public void testStringConcatToFormatEscaping() {
|
||||
doTest(PyBundle.message("INTN.replace.plus.with.format.operator"), LanguageLevel.PYTHON25);
|
||||
}
|
||||
|
||||
public void testConvertStaticMethodToFunction() {
|
||||
doTest(PyBundle.message("INTN.convert.static.method.to.function"));
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public abstract class PyIntentionTestCase extends PyTestCase {
|
||||
return PythonTestUtil.getTestDataPath() + "/intentions/" + getClass().getSimpleName();
|
||||
}
|
||||
|
||||
protected void doIntentionTest(String hint, LanguageLevel languageLevel) {
|
||||
protected void doTest(String hint, LanguageLevel languageLevel) {
|
||||
PythonLanguageLevelPusher.setForcedLanguageLevel(myFixture.getProject(), languageLevel);
|
||||
try {
|
||||
doIntentionTest(hint);
|
||||
@@ -36,7 +36,7 @@ public abstract class PyIntentionTestCase extends PyTestCase {
|
||||
myFixture.checkResultByFile(testFileName + "_after.py", true);
|
||||
}
|
||||
|
||||
protected void doNegateIntentionTest(final String hint) {
|
||||
protected void doNegativeTest(final String hint) {
|
||||
final String testFileName = getTestName(true);
|
||||
myFixture.configureByFile(testFileName + ".py");
|
||||
final IntentionAction intentionAction = myFixture.getAvailableIntention(hint);
|
||||
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package com.jetbrains.python.intentions;
|
||||
|
||||
import com.jetbrains.python.PyBundle;
|
||||
import com.jetbrains.python.psi.LanguageLevel;
|
||||
|
||||
/**
|
||||
* User : ktisha
|
||||
*/
|
||||
public class PyStringConcatenationToFormatIntentionTest extends PyIntentionTestCase {
|
||||
|
||||
public void testSimple() {
|
||||
doTest(PyBundle.message("INTN.replace.plus.with.format.operator"), LanguageLevel.PYTHON25);
|
||||
}
|
||||
|
||||
public void testAugmentAssignment() { //PY-5226
|
||||
doTest(PyBundle.message("INTN.replace.plus.with.format.operator"), LanguageLevel.PYTHON25);
|
||||
}
|
||||
|
||||
public void testNegative() { //PY-6505
|
||||
runWithLanguageLevel(LanguageLevel.PYTHON25, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
doNegativeTest(PyBundle.message("INTN.replace.plus.with.format.operator"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testTwoStrings() { //PY-6505
|
||||
doTest(PyBundle.message("INTN.replace.plus.with.format.operator"), LanguageLevel.PYTHON25);
|
||||
}
|
||||
|
||||
public void testUnknownType() { //PY-7969
|
||||
doNegativeTest(PyBundle.message("INTN.replace.plus.with.format.operator"));
|
||||
}
|
||||
|
||||
public void testEmptyStrings() { //PY-7968
|
||||
doNegativeTest(PyBundle.message("INTN.replace.plus.with.format.operator"));
|
||||
}
|
||||
|
||||
public void testUnicodeString() { //PY-7463
|
||||
doTest(PyBundle.message("INTN.replace.plus.with.format.operator"), LanguageLevel.PYTHON25);
|
||||
}
|
||||
|
||||
public void testUnicodeSecondString() { //PY-7463
|
||||
doTest(PyBundle.message("INTN.replace.plus.with.format.operator"), LanguageLevel.PYTHON25);
|
||||
}
|
||||
|
||||
// PY-8366
|
||||
public void testEscapingPy3() {
|
||||
doTest(PyBundle.message("INTN.replace.plus.with.str.format"), LanguageLevel.PYTHON33);
|
||||
}
|
||||
|
||||
// PY-8588
|
||||
public void testEscaping() {
|
||||
doTest(PyBundle.message("INTN.replace.plus.with.format.operator"), LanguageLevel.PYTHON25);
|
||||
}
|
||||
|
||||
public void testPy3() { //PY-4706
|
||||
doTest(PyBundle.message("INTN.replace.plus.with.str.format"), LanguageLevel.PYTHON33);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user