Index: pkg/analyzer/test/generated/parser_test.dart |
diff --git a/pkg/analyzer/test/generated/parser_test.dart b/pkg/analyzer/test/generated/parser_test.dart |
index 06740395e50809bdfa34f8cf58300f996ffdfb91..58c7c6f0b6339d38abda07b0fce1909a406fa5e4 100644 |
--- a/pkg/analyzer/test/generated/parser_test.dart |
+++ b/pkg/analyzer/test/generated/parser_test.dart |
@@ -1216,6 +1216,50 @@ class Foo { |
"external typedef F();", [ParserErrorCode.EXTERNAL_TYPEDEF]); |
} |
+ void test_extraCommaInParameterList() { |
+ parseTrailingCommas = true; |
+ parse4("parseFormalParameterList", "(int a, , int b)", |
+ [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); |
+ parseTrailingCommas = false; |
+ parse4("parseFormalParameterList", "(int a, , int b)", |
+ [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); |
+ } |
+ |
+ void test_extraCommaTrailingNamedParameterGroup() { |
+ parseTrailingCommas = true; |
+ parse4("parseFormalParameterList", "({int b},)", [ |
+ ParserErrorCode.MISSING_IDENTIFIER, |
+ ParserErrorCode.NORMAL_BEFORE_OPTIONAL_PARAMETERS |
+ ]); |
+ parseTrailingCommas = false; |
+ parse4("parseFormalParameterList", "({int b},)", [ |
+ ParserErrorCode.MISSING_IDENTIFIER, |
+ ParserErrorCode.NORMAL_BEFORE_OPTIONAL_PARAMETERS |
+ ]); |
+ } |
+ |
+ void test_extraCommaTrailingPositionalParameterGroup() { |
+ parseTrailingCommas = true; |
+ parse4("parseFormalParameterList", "([int b],)", [ |
+ ParserErrorCode.MISSING_IDENTIFIER, |
+ ParserErrorCode.NORMAL_BEFORE_OPTIONAL_PARAMETERS |
+ ]); |
+ parseTrailingCommas = false; |
+ parse4("parseFormalParameterList", "([int b],)", [ |
+ ParserErrorCode.MISSING_IDENTIFIER, |
+ ParserErrorCode.NORMAL_BEFORE_OPTIONAL_PARAMETERS |
+ ]); |
+ } |
+ |
+ void test_extraTrailingCommaInParameterList() { |
+ parseTrailingCommas = true; |
+ parse4("parseFormalParameterList", "(a,,)", |
+ [ParserErrorCode.MISSING_IDENTIFIER]); |
+ parseTrailingCommas = false; |
+ parse4("parseFormalParameterList", "(a,,)", |
+ [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); |
+ } |
+ |
void test_factoryTopLevelDeclaration_class() { |
ParserTestCase.parseCompilationUnit( |
"factory class C {}", [ParserErrorCode.FACTORY_TOP_LEVEL_DECLARATION]); |
@@ -1322,7 +1366,7 @@ class Foo { |
"0++", [ParserErrorCode.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE]); |
} |
- void test_illegalAssignmentToNonAssignable_postfix_plusPlus_parethesized() { |
+ void test_illegalAssignmentToNonAssignable_postfix_plusPlus_parenthesized() { |
parseExpression( |
"(x)++", [ParserErrorCode.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE]); |
} |
@@ -1715,6 +1759,12 @@ class Foo { |
expect(expression.isSynthetic, isTrue); |
} |
+ void test_missingIdentifierForParameterGroup() { |
+ parseTrailingCommas = true; |
+ parse4("parseFormalParameterList", "(,)", |
+ [ParserErrorCode.MISSING_IDENTIFIER]); |
+ } |
+ |
void test_missingKeywordOperator() { |
parse3("parseOperator", <Object>[emptyCommentAndMetadata(), null, null], |
"+(x) {}", [ParserErrorCode.MISSING_KEYWORD_OPERATOR]); |
@@ -2777,6 +2827,12 @@ class ParserTestCase extends EngineTestCase { |
bool enableGenericMethodComments = false; |
/** |
+ * A flag indicating whether parsing trailing commas in parameter and argument |
+ * lists should be enabled for this test. |
+ */ |
+ bool parseTrailingCommas = false; |
+ |
+ /** |
* Return a CommentAndMetadata object with the given values that can be used for testing. |
* |
* @param comment the comment to be wrapped in the object |
@@ -2830,6 +2886,7 @@ class ParserTestCase extends EngineTestCase { |
parser.parseGenericMethods = enableGenericMethods; |
parser.parseGenericMethodComments = enableGenericMethodComments; |
parser.parseFunctionBodies = parseFunctionBodies; |
+ parser.parseTrailingCommas = parseTrailingCommas; |
Object result = |
invokeParserMethodImpl(parser, methodName, objects, tokenStream); |
// |
@@ -4755,6 +4812,13 @@ class SimpleParserTest extends ParserTestCase { |
expect(arguments, hasLength(2)); |
} |
+ void test_parseArgumentList_trailing_comma() { |
+ parseTrailingCommas = true; |
+ ArgumentList argumentList = parse4("parseArgumentList", "(x, y, z,)"); |
+ NodeList<Expression> arguments = argumentList.arguments; |
+ expect(arguments, hasLength(3)); |
+ } |
+ |
void test_parseAssertStatement() { |
AssertStatement statement = parse4("parseAssertStatement", "assert (x);"); |
expect(statement.assertKeyword, isNotNull); |
@@ -5937,6 +6001,22 @@ class SimpleParserTest extends ParserTestCase { |
expect(method.body, isNotNull); |
} |
+ void test_parseClassMember_method_trailing_commas() { |
+ parseTrailingCommas = true; |
+ MethodDeclaration method = |
+ parse("parseClassMember", <Object>["C"], "void f(int x, int y,) {}"); |
+ expect(method.documentationComment, isNull); |
+ expect(method.externalKeyword, isNull); |
+ expect(method.modifierKeyword, isNull); |
+ expect(method.propertyKeyword, isNull); |
+ expect(method.returnType, isNotNull); |
+ expect(method.name, isNotNull); |
+ expect(method.operatorKeyword, isNull); |
+ expect(method.typeParameters, isNull); |
+ expect(method.parameters, isNotNull); |
+ expect(method.body, isNotNull); |
+ } |
+ |
void test_parseClassMember_operator_index() { |
MethodDeclaration method = |
parse("parseClassMember", <Object>["C"], "int operator [](int i) {}"); |
@@ -6327,12 +6407,13 @@ void'''); |
void test_parseCommentReferences_notClosed_withIdentifier() { |
DocumentationCommentToken docToken = new DocumentationCommentToken( |
- TokenType.MULTI_LINE_COMMENT, "/** [namePrefix some text", 5); |
- List<CommentReference> references = |
- parse("parseCommentReferences", <Object>[<DocumentationCommentToken>[ |
- docToken |
- ]], "") |
- as List<CommentReference>; |
+ TokenType.MULTI_LINE_COMMENT, "/** [namePrefix some text", 5); |
+ List<CommentReference> references = parse( |
+ "parseCommentReferences", |
+ <Object>[ |
+ <DocumentationCommentToken>[docToken] |
+ ], |
+ "") as List<CommentReference>; |
expect(docToken.references, hasLength(1)); |
expect(references, hasLength(1)); |
Token referenceToken = docToken.references[0]; |
@@ -7777,6 +7858,17 @@ void'''); |
expect(parameterList.rightParenthesis, isNotNull); |
} |
+ void test_parseFormalParameterList_named_trailing_comma() { |
+ parseTrailingCommas = true; |
+ FormalParameterList parameterList = |
+ parse4("parseFormalParameterList", "(A a, {B b,})"); |
+ expect(parameterList.leftParenthesis, isNotNull); |
+ expect(parameterList.leftDelimiter, isNotNull); |
+ expect(parameterList.parameters, hasLength(2)); |
+ expect(parameterList.rightDelimiter, isNotNull); |
+ expect(parameterList.rightParenthesis, isNotNull); |
+ } |
+ |
void test_parseFormalParameterList_normal_multiple() { |
FormalParameterList parameterList = |
parse4("parseFormalParameterList", "(A a, B b, C c)"); |
@@ -7817,6 +7909,17 @@ void'''); |
expect(parameterList.rightParenthesis, isNotNull); |
} |
+ void test_parseFormalParameterList_normal_single_trailing_comma() { |
+ parseTrailingCommas = true; |
+ FormalParameterList parameterList = |
+ parse4("parseFormalParameterList", "(A a,)"); |
+ expect(parameterList.leftParenthesis, isNotNull); |
+ expect(parameterList.leftDelimiter, isNull); |
+ expect(parameterList.parameters, hasLength(1)); |
+ expect(parameterList.rightDelimiter, isNull); |
+ expect(parameterList.rightParenthesis, isNotNull); |
+ } |
+ |
void test_parseFormalParameterList_positional_multiple() { |
FormalParameterList parameterList = |
parse4("parseFormalParameterList", "([A a = null, B b, C c = null])"); |
@@ -7837,6 +7940,17 @@ void'''); |
expect(parameterList.rightParenthesis, isNotNull); |
} |
+ void test_parseFormalParameterList_positional_trailing_comma() { |
+ parseTrailingCommas = true; |
+ FormalParameterList parameterList = |
+ parse4("parseFormalParameterList", "(A a, [B b,])"); |
+ expect(parameterList.leftParenthesis, isNotNull); |
+ expect(parameterList.leftDelimiter, isNotNull); |
+ expect(parameterList.parameters, hasLength(2)); |
+ expect(parameterList.rightDelimiter, isNotNull); |
+ expect(parameterList.rightParenthesis, isNotNull); |
+ } |
+ |
void test_parseFormalParameterList_prefixedType() { |
FormalParameterList parameterList = |
parse4("parseFormalParameterList", "(io.File f)"); |