void () { doTestInjectedText(""" import re re.search(rf'<caret>.*{42.*', 'foo')""", ".*missing_value"); } // PY-21493 public void testFStringSingleStringNestedFragments() { doTestInjectedText(""" import re re.search(rf'<caret>.*{42:{42}}.*{42}', 'foo')""", ".*missing_value.*missing_value"); } // PY-18881 public void testVerboseSyntaxWithShortFlag() { final PsiElement element = doTestInjectedText(""" import re re.search(""\" .* # <caret>comment ""\", re.I | re.M | re.X)""", "\n.* # comment\n"); assertEquals(PythonVerboseRegexpLanguage.INSTANCE, element.getLanguage()); } // PY-16404 public void testFullmatchPy3() { doTestInjectedText("import re\n" + "re.fullmatch(\"<caret>\\w+\", \"string\"", "\\w+"); } @Nullable @Override protected LightProjectDescriptor getProjectDescriptor() { return getName().endsWith("Py3") ? super.getProjectDescriptor() : ourPy2Descriptor; } @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()); assertNotNull(host); final List<Pair<PsiElement, TextRange>> files = languageManager.getInjectedPsiFiles(host); assertNotNull(files); assertFalse(files.isEmpty()); final PsiElement injected = files.get(0).getFirst(); assertEquals(expected, injected.getText()); return injected; } private void doTestHighlighting() { myFixture.testHighlighting(true, false, true, "regexp/" + getTestName(true) + ".py"); } private void doTestLexer(final String text, String... expectedTokens) { Lexer lexer = new PythonRegexpParserDefinition().createLexer(myFixture.getProject()); PyLexerTestCase.doLexerTest(text, lexer, expectedTokens); } }