void () { doTestStringHighlighting(LanguageLevel.PYTHON36, "f'foo\\nbar'", "Py:FSTRING_START", "Py:FSTRING_TEXT", "VALID_STRING_ESCAPE_TOKEN", "Py:FSTRING_TEXT", "Py:FSTRING_END"); doTestStringHighlighting(LanguageLevel.PYTHON36, "f'foo\\\nbar'", "Py:FSTRING_START", "Py:FSTRING_TEXT", "VALID_STRING_ESCAPE_TOKEN", "Py:FSTRING_TEXT", "Py:FSTRING_END"); doTestStringHighlighting(LanguageLevel.PYTHON36, "f'foo\\u0041bar'", "Py:FSTRING_START", "Py:FSTRING_TEXT", "VALID_STRING_ESCAPE_TOKEN", "Py:FSTRING_TEXT", "Py:FSTRING_END"); doTestStringHighlighting(LanguageLevel.PYTHON36, "f'foo\\x41bar'", "Py:FSTRING_START", "Py:FSTRING_TEXT", "VALID_STRING_ESCAPE_TOKEN", "Py:FSTRING_TEXT", "Py:FSTRING_END"); doTestStringHighlighting(LanguageLevel.PYTHON36, "f'foo\\101bar'", "Py:FSTRING_START", "Py:FSTRING_TEXT", "VALID_STRING_ESCAPE_TOKEN", "Py:FSTRING_TEXT", "Py:FSTRING_END"); doTestStringHighlighting(LanguageLevel.PYTHON36, "f'foo\\N{GREEK SMALL LETTER ALPHA}bar'", "Py:FSTRING_START", "Py:FSTRING_TEXT", "VALID_STRING_ESCAPE_TOKEN", "Py:FSTRING_TEXT", "Py:FSTRING_END"); doTestStringHighlighting(LanguageLevel.PYTHON36, "f'foo\\", "Py:FSTRING_START", "Py:FSTRING_TEXT", "INVALID_CHARACTER_ESCAPE_TOKEN"); doTestStringHighlighting(LanguageLevel.PYTHON36, "f'foo\\u00'", "Py:FSTRING_START", "Py:FSTRING_TEXT", "INVALID_UNICODE_ESCAPE_TOKEN", "Py:FSTRING_END"); doTestStringHighlighting(LanguageLevel.PYTHON36, "f'foo\\uZZZZbar'", "Py:FSTRING_START", "Py:FSTRING_TEXT", "INVALID_UNICODE_ESCAPE_TOKEN", "Py:FSTRING_TEXT", "Py:FSTRING_END"); doTestStringHighlighting(LanguageLevel.PYTHON36, "f'foo\\x0'", "Py:FSTRING_START", "Py:FSTRING_TEXT", "INVALID_UNICODE_ESCAPE_TOKEN", "Py:FSTRING_END"); doTestStringHighlighting(LanguageLevel.PYTHON36, "f'foo\\xZZbar'", "Py:FSTRING_START", "Py:FSTRING_TEXT", "INVALID_UNICODE_ESCAPE_TOKEN", "Py:FSTRING_TEXT", "Py:FSTRING_END"); doTestStringHighlighting(LanguageLevel.PYTHON36, "f'foo\\10'", "Py:FSTRING_START", "Py:FSTRING_TEXT", "VALID_STRING_ESCAPE_TOKEN", "Py:FSTRING_END"); doTestStringHighlighting(LanguageLevel.PYTHON36, "f'foo\\777'", "Py:FSTRING_START", "Py:FSTRING_TEXT", "VALID_STRING_ESCAPE_TOKEN", "Py:FSTRING_TEXT", "Py:FSTRING_END"); doTestStringHighlighting(LanguageLevel.PYTHON36, "f'foo\\N{GREEK SMALL LETTER ALPHA'", "Py:FSTRING_START", "Py:FSTRING_TEXT", "INVALID_UNICODE_ESCAPE_TOKEN", "Py:FSTRING_END"); doTestStringHighlighting(LanguageLevel.PYTHON36, "f'{x:\\n}'", "Py:FSTRING_START", "Py:FSTRING_FRAGMENT_START", "Py:IDENTIFIER", "Py:FSTRING_FRAGMENT_FORMAT_START", "VALID_STRING_ESCAPE_TOKEN", "Py:FSTRING_FRAGMENT_END", "Py:FSTRING_END"); } // PY-32123 public void testRawFStringEscapeSequences() { doTestStringHighlighting(LanguageLevel.PYTHON36, "rf'foo\\nbar'", "Py:FSTRING_START", "Py:FSTRING_RAW_TEXT", "Py:FSTRING_RAW_TEXT", "Py:FSTRING_RAW_TEXT", "Py:FSTRING_END"); doTestStringHighlighting(LanguageLevel.PYTHON36, "rf'foo\\\nbar'", "Py:FSTRING_START", "Py:FSTRING_RAW_TEXT", "Py:FSTRING_RAW_TEXT", "Py:FSTRING_RAW_TEXT", "Py:FSTRING_END"); doTestStringHighlighting(LanguageLevel.PYTHON36, "rf'foo\\", "Py:FSTRING_START", "Py:FSTRING_RAW_TEXT", "Py:FSTRING_RAW_TEXT"); doTestStringHighlighting(LanguageLevel.PYTHON36, "rf'{x:\\n}'", "Py:FSTRING_START", "Py:FSTRING_FRAGMENT_START", "Py:IDENTIFIER", "Py:FSTRING_FRAGMENT_FORMAT_START", "Py:FSTRING_RAW_TEXT", "Py:FSTRING_RAW_TEXT", "Py:FSTRING_FRAGMENT_END", "Py:FSTRING_END"); doTestStringHighlighting(LanguageLevel.PYTHON36, "rf'{f\"\\n\"}'", "Py:FSTRING_START", "Py:FSTRING_FRAGMENT_START", "Py:FSTRING_START", "VALID_STRING_ESCAPE_TOKEN", "Py:FSTRING_END", "Py:FSTRING_FRAGMENT_END", "Py:FSTRING_END"); doTestStringHighlighting(LanguageLevel.PYTHON36, "f'{rf\"\\n\"}'", "Py:FSTRING_START", "Py:FSTRING_FRAGMENT_START", "Py:FSTRING_START", "Py:FSTRING_RAW_TEXT", "Py:FSTRING_RAW_TEXT", "Py:FSTRING_END", "Py:FSTRING_FRAGMENT_END", "Py:FSTRING_END"); } private static void doTest(LanguageLevel languageLevel, String text, String... expectedTokens) { PyLexerTestCase.doLexerTest(text, new PythonHighlightingLexer(languageLevel), expectedTokens); } private static void doTestStringHighlighting(LanguageLevel languageLevel, String text, String... expectedTokens) { PyLexerTestCase.doLexerTest(text, new PyHighlighter(languageLevel).getHighlightingLexer(), expectedTokens); } }