From 0d0ea521c8ac20c4ccab2da9e75a6ae4e710e42a Mon Sep 17 00:00:00 2001 From: Mikhail Golubev Date: Tue, 4 Sep 2018 12:22:29 +0300 Subject: [PATCH] PY-31442 Add tests on handling of line comments inside fragments --- ...eFStringContainsCommentInsideExpression.py | 3 +++ ...FStringContainsCommentInsideExpression.txt | 22 +++++++++++++++++++ ...tringContainsCommentInsteadOfExpression.py | 3 +++ ...ringContainsCommentInsteadOfExpression.txt | 21 ++++++++++++++++++ ...eFStringContainsCommentInsideExpression.py | 1 + ...FStringContainsCommentInsideExpression.txt | 20 +++++++++++++++++ ...tringContainsCommentInsteadOfExpression.py | 1 + ...ringContainsCommentInsteadOfExpression.txt | 19 ++++++++++++++++ .../jetbrains/python/PythonParsingTest.java | 16 ++++++++++++++ 9 files changed, 106 insertions(+) create mode 100644 python/testData/psi/MultilineFStringContainsCommentInsideExpression.py create mode 100644 python/testData/psi/MultilineFStringContainsCommentInsideExpression.txt create mode 100644 python/testData/psi/MultilineFStringContainsCommentInsteadOfExpression.py create mode 100644 python/testData/psi/MultilineFStringContainsCommentInsteadOfExpression.txt create mode 100644 python/testData/psi/SingleLineFStringContainsCommentInsideExpression.py create mode 100644 python/testData/psi/SingleLineFStringContainsCommentInsideExpression.txt create mode 100644 python/testData/psi/SingleLineFStringContainsCommentInsteadOfExpression.py create mode 100644 python/testData/psi/SingleLineFStringContainsCommentInsteadOfExpression.txt diff --git a/python/testData/psi/MultilineFStringContainsCommentInsideExpression.py b/python/testData/psi/MultilineFStringContainsCommentInsideExpression.py new file mode 100644 index 000000000000..66da8a65f19d --- /dev/null +++ b/python/testData/psi/MultilineFStringContainsCommentInsideExpression.py @@ -0,0 +1,3 @@ +s = f'''{[ + # comment +]}''' \ No newline at end of file diff --git a/python/testData/psi/MultilineFStringContainsCommentInsideExpression.txt b/python/testData/psi/MultilineFStringContainsCommentInsideExpression.txt new file mode 100644 index 000000000000..b8e069902589 --- /dev/null +++ b/python/testData/psi/MultilineFStringContainsCommentInsideExpression.txt @@ -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)(''''') \ No newline at end of file diff --git a/python/testData/psi/MultilineFStringContainsCommentInsteadOfExpression.py b/python/testData/psi/MultilineFStringContainsCommentInsteadOfExpression.py new file mode 100644 index 000000000000..23e6fe9e71b4 --- /dev/null +++ b/python/testData/psi/MultilineFStringContainsCommentInsteadOfExpression.py @@ -0,0 +1,3 @@ +s = f'''{ + # comment +}''' \ No newline at end of file diff --git a/python/testData/psi/MultilineFStringContainsCommentInsteadOfExpression.txt b/python/testData/psi/MultilineFStringContainsCommentInsteadOfExpression.txt new file mode 100644 index 000000000000..01ed5a8652f4 --- /dev/null +++ b/python/testData/psi/MultilineFStringContainsCommentInsteadOfExpression.txt @@ -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 + + PsiWhiteSpace('\n ') + PsiComment(Py:END_OF_LINE_COMMENT)('# comment') + PsiWhiteSpace('\n') + PsiElement(Py:FSTRING_FRAGMENT_END)('}') + PsiElement(Py:FSTRING_END)(''''') \ No newline at end of file diff --git a/python/testData/psi/SingleLineFStringContainsCommentInsideExpression.py b/python/testData/psi/SingleLineFStringContainsCommentInsideExpression.py new file mode 100644 index 000000000000..e945ef2658cf --- /dev/null +++ b/python/testData/psi/SingleLineFStringContainsCommentInsideExpression.py @@ -0,0 +1 @@ +s = f'{42 # comment}' \ No newline at end of file diff --git a/python/testData/psi/SingleLineFStringContainsCommentInsideExpression.txt b/python/testData/psi/SingleLineFStringContainsCommentInsideExpression.txt new file mode 100644 index 000000000000..530ac7614221 --- /dev/null +++ b/python/testData/psi/SingleLineFStringContainsCommentInsideExpression.txt @@ -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 + + PsiErrorElement:Unexpected f-string token + + PsiWhiteSpace(' ') + PsiComment(Py:END_OF_LINE_COMMENT)('# comment}'') \ No newline at end of file diff --git a/python/testData/psi/SingleLineFStringContainsCommentInsteadOfExpression.py b/python/testData/psi/SingleLineFStringContainsCommentInsteadOfExpression.py new file mode 100644 index 000000000000..c1534acf743a --- /dev/null +++ b/python/testData/psi/SingleLineFStringContainsCommentInsteadOfExpression.py @@ -0,0 +1 @@ +s = f'{# comment}' \ No newline at end of file diff --git a/python/testData/psi/SingleLineFStringContainsCommentInsteadOfExpression.txt b/python/testData/psi/SingleLineFStringContainsCommentInsteadOfExpression.txt new file mode 100644 index 000000000000..7b73da8de576 --- /dev/null +++ b/python/testData/psi/SingleLineFStringContainsCommentInsteadOfExpression.txt @@ -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 + + PsiErrorElement:type conversion, : or } expected + + PsiErrorElement:Unexpected f-string token + + PsiComment(Py:END_OF_LINE_COMMENT)('# comment}'') \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PythonParsingTest.java b/python/testSrc/com/jetbrains/python/PythonParsingTest.java index 46a66d229db5..69733ef62492 100644 --- a/python/testSrc/com/jetbrains/python/PythonParsingTest.java +++ b/python/testSrc/com/jetbrains/python/PythonParsingTest.java @@ -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);