mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-18881 Recognize flag "X" in functions of re module to inject verbose regex fragments
This commit is contained in:
@@ -134,7 +134,8 @@ public class PythonRegexpInjector implements MultiHostInjector {
|
||||
return isVerbose(keywordArgument.getValueExpression());
|
||||
}
|
||||
if (expr instanceof PyReferenceExpression) {
|
||||
return "VERBOSE".equals(((PyReferenceExpression)expr).getReferencedName());
|
||||
final String flagName = ((PyReferenceExpression)expr).getReferencedName();
|
||||
return "VERBOSE".equals(flagName) || "X".equals(flagName);
|
||||
}
|
||||
if (expr instanceof PyBinaryExpression) {
|
||||
return isVerbose(((PyBinaryExpression)expr).getLeftExpression()) || isVerbose(((PyBinaryExpression)expr).getRightExpression());
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiLanguageInjectionHost;
|
||||
import com.jetbrains.python.codeInsight.regexp.PythonRegexpParserDefinition;
|
||||
import com.jetbrains.python.codeInsight.regexp.PythonVerboseRegexpLanguage;
|
||||
import com.jetbrains.python.codeInsight.regexp.PythonVerboseRegexpParserDefinition;
|
||||
import com.jetbrains.python.fixtures.PyLexerTestCase;
|
||||
import com.jetbrains.python.fixtures.PyTestCase;
|
||||
@@ -158,7 +159,20 @@ public class PyRegexpTest extends PyTestCase {
|
||||
"(foomissing_valuebaz$)");
|
||||
}
|
||||
|
||||
private void doTestInjectedText(@NotNull String text, @NotNull String expected) {
|
||||
// PY-18881
|
||||
public void testVerboseSyntaxWithShortFlag() {
|
||||
final PsiElement element =
|
||||
doTestInjectedText("import re\n" +
|
||||
"\n" +
|
||||
"re.search(\"\"\"\n" +
|
||||
".* # <caret>comment\n" +
|
||||
"\"\"\", re.I | re.M | re.X)",
|
||||
"\n.* # comment\n");
|
||||
assertEquals(element.getLanguage(), PythonVerboseRegexpLanguage.INSTANCE);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private PsiElement doTestInjectedText(@NotNull String text, @NotNull String expected) {
|
||||
myFixture.configureByText(PythonFileType.INSTANCE, text);
|
||||
final InjectedLanguageManager languageManager = InjectedLanguageManager.getInstance(myFixture.getProject());
|
||||
final PsiLanguageInjectionHost host = languageManager.getInjectionHost(getElementAtCaret());
|
||||
@@ -168,6 +182,7 @@ public class PyRegexpTest extends PyTestCase {
|
||||
assertFalse(files.isEmpty());
|
||||
final PsiElement injected = files.get(0).getFirst();
|
||||
assertEquals(expected, injected.getText());
|
||||
return injected;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user