PY-31442 Add tests on handling of line comments inside fragments

This commit is contained in:
Mikhail Golubev
2018-10-01 12:46:44 +03:00
parent 77e47676b4
commit 0d0ea521c8
9 changed files with 106 additions and 0 deletions
@@ -0,0 +1,3 @@
s = f'''{[
# comment
]}'''
@@ -0,0 +1,22 @@
PyFile:MultilineFStringContainsCommentInsideExpression.py
PyAssignmentStatement
PyTargetExpression: s
PsiElement(Py:IDENTIFIER)('s')
PsiWhiteSpace(' ')
PsiElement(Py:EQ)('=')
PsiWhiteSpace(' ')
PyStringLiteralExpression: {[
# comment
]}
PyFormattedStringNode
PsiElement(Py:FSTRING_START)('f'''')
PyFStringFragment
PsiElement(Py:FSTRING_FRAGMENT_START)('{')
PyListLiteralExpression
PsiElement(Py:LBRACKET)('[')
PsiWhiteSpace('\n ')
PsiComment(Py:END_OF_LINE_COMMENT)('# comment')
PsiWhiteSpace('\n')
PsiElement(Py:RBRACKET)(']')
PsiElement(Py:FSTRING_FRAGMENT_END)('}')
PsiElement(Py:FSTRING_END)(''''')
@@ -0,0 +1,3 @@
s = f'''{
# comment
}'''
@@ -0,0 +1,21 @@
PyFile:MultilineFStringContainsCommentInsteadOfExpression.py
PyAssignmentStatement
PyTargetExpression: s
PsiElement(Py:IDENTIFIER)('s')
PsiWhiteSpace(' ')
PsiElement(Py:EQ)('=')
PsiWhiteSpace(' ')
PyStringLiteralExpression: {
# comment
}
PyFormattedStringNode
PsiElement(Py:FSTRING_START)('f'''')
PyFStringFragment
PsiElement(Py:FSTRING_FRAGMENT_START)('{')
PsiErrorElement:expression expected
<empty list>
PsiWhiteSpace('\n ')
PsiComment(Py:END_OF_LINE_COMMENT)('# comment')
PsiWhiteSpace('\n')
PsiElement(Py:FSTRING_FRAGMENT_END)('}')
PsiElement(Py:FSTRING_END)(''''')
@@ -0,0 +1 @@
s = f'{42 # comment}'
@@ -0,0 +1,20 @@
PyFile:SingleLineFStringContainsCommentInsideExpression.py
PyAssignmentStatement
PyTargetExpression: s
PsiElement(Py:IDENTIFIER)('s')
PsiWhiteSpace(' ')
PsiElement(Py:EQ)('=')
PsiWhiteSpace(' ')
PyStringLiteralExpression: {42
PyFormattedStringNode
PsiElement(Py:FSTRING_START)('f'')
PyFStringFragment
PsiElement(Py:FSTRING_FRAGMENT_START)('{')
PyNumericLiteralExpression
PsiElement(Py:INTEGER_LITERAL)('42')
PsiErrorElement:type conversion, : or } expected
<empty list>
PsiErrorElement:Unexpected f-string token
<empty list>
PsiWhiteSpace(' ')
PsiComment(Py:END_OF_LINE_COMMENT)('# comment}'')
@@ -0,0 +1 @@
s = f'{# comment}'
@@ -0,0 +1,19 @@
PyFile:SingleLineFStringContainsCommentInsteadOfExpression.py
PyAssignmentStatement
PyTargetExpression: s
PsiElement(Py:IDENTIFIER)('s')
PsiWhiteSpace(' ')
PsiElement(Py:EQ)('=')
PsiWhiteSpace(' ')
PyStringLiteralExpression: {
PyFormattedStringNode
PsiElement(Py:FSTRING_START)('f'')
PyFStringFragment
PsiElement(Py:FSTRING_FRAGMENT_START)('{')
PsiErrorElement:expression expected
<empty list>
PsiErrorElement:type conversion, : or } expected
<empty list>
PsiErrorElement:Unexpected f-string token
<empty list>
PsiComment(Py:END_OF_LINE_COMMENT)('# comment}'')
@@ -761,6 +761,22 @@ public class PythonParsingTest extends ParsingTestCase {
doTest(LanguageLevel.PYTHON36);
}
public void testSingleLineFStringContainsCommentInsideExpression() {
doTest(LanguageLevel.PYTHON36);
}
public void testSingleLineFStringContainsCommentInsteadOfExpression() {
doTest(LanguageLevel.PYTHON36);
}
public void testMultilineFStringContainsCommentInsideExpression() {
doTest(LanguageLevel.PYTHON36);
}
public void testMultilineFStringContainsCommentInsteadOfExpression() {
doTest(LanguageLevel.PYTHON36);
}
// PY-19036
public void testAwaitInNonAsyncNestedFunction() {
doTest(LanguageLevel.PYTHON35);