PY-79967 Add a couple of tests for template strings to PythonParsingTest

GitOrigin-RevId: df2ec2ac92e21fb307cb17f446c2e5eca8e09eb3
This commit is contained in:
Daniil Kalinin
2025-05-07 15:14:42 +00:00
committed by intellij-monorepo-bot
parent 246fd7cd88
commit b47b5beb3d
13 changed files with 224 additions and 0 deletions
@@ -0,0 +1,5 @@
s = (t'',
T"",
rt"""""",
TR'''''',
)
@@ -0,0 +1,35 @@
PyFile:EmptyTemplateStrings.py
PyAssignmentStatement
PyTargetExpression: s
PsiElement(Py:IDENTIFIER)('s')
PsiWhiteSpace(' ')
PsiElement(Py:EQ)('=')
PsiWhiteSpace(' ')
PyParenthesizedExpression
PsiElement(Py:LPAR)('(')
PyTupleExpression
PyStringLiteralExpression:
PyFormattedStringElement
PsiElement(Py:FSTRING_START)('t'')
PsiElement(Py:FSTRING_END)(''')
PsiElement(Py:COMMA)(',')
PsiWhiteSpace('\n ')
PyStringLiteralExpression:
PyFormattedStringElement
PsiElement(Py:FSTRING_START)('T"')
PsiElement(Py:FSTRING_END)('"')
PsiElement(Py:COMMA)(',')
PsiWhiteSpace('\n ')
PyStringLiteralExpression:
PyFormattedStringElement
PsiElement(Py:FSTRING_START)('rt"""')
PsiElement(Py:FSTRING_END)('"""')
PsiElement(Py:COMMA)(',')
PsiWhiteSpace('\n ')
PyStringLiteralExpression:
PyFormattedStringElement
PsiElement(Py:FSTRING_START)('TR'''')
PsiElement(Py:FSTRING_END)(''''')
PsiElement(Py:COMMA)(',')
PsiWhiteSpace('\n ')
PsiElement(Py:RPAR)(')')
@@ -0,0 +1 @@
s = t"{f''}"
@@ -0,0 +1,18 @@
PyFile:FStringInsideTemplateString.py
PyAssignmentStatement
PyTargetExpression: s
PsiElement(Py:IDENTIFIER)('s')
PsiWhiteSpace(' ')
PsiElement(Py:EQ)('=')
PsiWhiteSpace(' ')
PyStringLiteralExpression: {f''}
PyFormattedStringElement
PsiElement(Py:FSTRING_START)('t"')
PyFStringFragment
PsiElement(Py:FSTRING_FRAGMENT_START)('{')
PyStringLiteralExpression:
PyFormattedStringElement
PsiElement(Py:FSTRING_START)('f'')
PsiElement(Py:FSTRING_END)(''')
PsiElement(Py:FSTRING_FRAGMENT_END)('}')
PsiElement(Py:FSTRING_END)('"')
@@ -0,0 +1 @@
s = t"""1{t'''2{t"3{t'4'}"}'''}"""
@@ -0,0 +1,36 @@
PyFile:NestedTemplateStrings.py
PyAssignmentStatement
PyTargetExpression: s
PsiElement(Py:IDENTIFIER)('s')
PsiWhiteSpace(' ')
PsiElement(Py:EQ)('=')
PsiWhiteSpace(' ')
PyStringLiteralExpression: 1{t'''2{t"3{t'4'}"}'''}
PyFormattedStringElement
PsiElement(Py:FSTRING_START)('t"""')
PsiElement(Py:FSTRING_TEXT)('1')
PyFStringFragment
PsiElement(Py:FSTRING_FRAGMENT_START)('{')
PyStringLiteralExpression: 2{t"3{t'4'}"}
PyFormattedStringElement
PsiElement(Py:FSTRING_START)('t'''')
PsiElement(Py:FSTRING_TEXT)('2')
PyFStringFragment
PsiElement(Py:FSTRING_FRAGMENT_START)('{')
PyStringLiteralExpression: 3{t'4'}
PyFormattedStringElement
PsiElement(Py:FSTRING_START)('t"')
PsiElement(Py:FSTRING_TEXT)('3')
PyFStringFragment
PsiElement(Py:FSTRING_FRAGMENT_START)('{')
PyStringLiteralExpression: 4
PyFormattedStringElement
PsiElement(Py:FSTRING_START)('t'')
PsiElement(Py:FSTRING_TEXT)('4')
PsiElement(Py:FSTRING_END)(''')
PsiElement(Py:FSTRING_FRAGMENT_END)('}')
PsiElement(Py:FSTRING_END)('"')
PsiElement(Py:FSTRING_FRAGMENT_END)('}')
PsiElement(Py:FSTRING_END)(''''')
PsiElement(Py:FSTRING_FRAGMENT_END)('}')
PsiElement(Py:FSTRING_END)('"""')
@@ -0,0 +1 @@
s = f"{t''}"
@@ -0,0 +1,18 @@
PyFile:TemplateStringInsideFString.py
PyAssignmentStatement
PyTargetExpression: s
PsiElement(Py:IDENTIFIER)('s')
PsiWhiteSpace(' ')
PsiElement(Py:EQ)('=')
PsiWhiteSpace(' ')
PyStringLiteralExpression: {t''}
PyFormattedStringElement
PsiElement(Py:FSTRING_START)('f"')
PyFStringFragment
PsiElement(Py:FSTRING_FRAGMENT_START)('{')
PyStringLiteralExpression:
PyFormattedStringElement
PsiElement(Py:FSTRING_START)('t'')
PsiElement(Py:FSTRING_END)(''')
PsiElement(Py:FSTRING_FRAGMENT_END)('}')
PsiElement(Py:FSTRING_END)('"')
@@ -0,0 +1 @@
s = t'foo{42}bar'
@@ -0,0 +1,18 @@
PyFile:TemplateStringWithFragment.py
PyAssignmentStatement
PyTargetExpression: s
PsiElement(Py:IDENTIFIER)('s')
PsiWhiteSpace(' ')
PsiElement(Py:EQ)('=')
PsiWhiteSpace(' ')
PyStringLiteralExpression: foo{42}bar
PyFormattedStringElement
PsiElement(Py:FSTRING_START)('t'')
PsiElement(Py:FSTRING_TEXT)('foo')
PyFStringFragment
PsiElement(Py:FSTRING_FRAGMENT_START)('{')
PyNumericLiteralExpression
PsiElement(Py:INTEGER_LITERAL)('42')
PsiElement(Py:FSTRING_FRAGMENT_END)('}')
PsiElement(Py:FSTRING_TEXT)('bar')
PsiElement(Py:FSTRING_END)(''')
+5
View File
@@ -0,0 +1,5 @@
s1 = t''
s2 = tr''
s3 = rt''
s4 = T''
s5 = RT''
+55
View File
@@ -0,0 +1,55 @@
PyFile:TemplateStrings.py
PyAssignmentStatement
PyTargetExpression: s1
PsiElement(Py:IDENTIFIER)('s1')
PsiWhiteSpace(' ')
PsiElement(Py:EQ)('=')
PsiWhiteSpace(' ')
PyStringLiteralExpression:
PyFormattedStringElement
PsiElement(Py:FSTRING_START)('t'')
PsiElement(Py:FSTRING_END)(''')
PsiWhiteSpace('\n')
PyAssignmentStatement
PyTargetExpression: s2
PsiElement(Py:IDENTIFIER)('s2')
PsiWhiteSpace(' ')
PsiElement(Py:EQ)('=')
PsiWhiteSpace(' ')
PyStringLiteralExpression:
PyFormattedStringElement
PsiElement(Py:FSTRING_START)('tr'')
PsiElement(Py:FSTRING_END)(''')
PsiWhiteSpace('\n')
PyAssignmentStatement
PyTargetExpression: s3
PsiElement(Py:IDENTIFIER)('s3')
PsiWhiteSpace(' ')
PsiElement(Py:EQ)('=')
PsiWhiteSpace(' ')
PyStringLiteralExpression:
PyFormattedStringElement
PsiElement(Py:FSTRING_START)('rt'')
PsiElement(Py:FSTRING_END)(''')
PsiWhiteSpace('\n')
PyAssignmentStatement
PyTargetExpression: s4
PsiElement(Py:IDENTIFIER)('s4')
PsiWhiteSpace(' ')
PsiElement(Py:EQ)('=')
PsiWhiteSpace(' ')
PyStringLiteralExpression:
PyFormattedStringElement
PsiElement(Py:FSTRING_START)('T'')
PsiElement(Py:FSTRING_END)(''')
PsiWhiteSpace('\n')
PyAssignmentStatement
PyTargetExpression: s5
PsiElement(Py:IDENTIFIER)('s5')
PsiWhiteSpace(' ')
PsiElement(Py:EQ)('=')
PsiWhiteSpace(' ')
PyStringLiteralExpression:
PyFormattedStringElement
PsiElement(Py:FSTRING_START)('RT'')
PsiElement(Py:FSTRING_END)(''')
@@ -1383,6 +1383,36 @@ public class PythonParsingTest extends ParsingTestCase {
doTest(LanguageLevel.PYTHON312);
}
// PY-79967
public void testTemplateStrings() {
doTest(LanguageLevel.PYTHON314);
}
// PY-79967
public void testTemplateStringWithFragment() {
doTest(LanguageLevel.PYTHON314);
}
// PY-79967
public void testEmptyTemplateStrings() {
doTest(LanguageLevel.PYTHON314);
}
// PY-79967
public void testNestedTemplateStrings() {
doTest(LanguageLevel.PYTHON314);
}
// PY-79967
public void testTemplateStringInsideFString() {
doTest(LanguageLevel.PYTHON314);
}
// PY-79967
public void testFStringInsideTemplateString() {
doTest(LanguageLevel.PYTHON314);
}
public void doTest() {
doTest(LanguageLevel.PYTHON26);
}