Chromium Code Reviews| 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 d6e5e3d4ee2b77e521398bc55582cc8c1643d69f..f6ad937d4c1173606d65d6bb7ca0bcba38462102 100644 |
| --- a/pkg/analyzer/test/generated/parser_test.dart |
| +++ b/pkg/analyzer/test/generated/parser_test.dart |
| @@ -28,6 +28,7 @@ main() { |
| defineReflectiveTests(ClassMemberParserTest); |
| defineReflectiveTests(ComplexParserTest); |
| defineReflectiveTests(ErrorParserTest); |
| + defineReflectiveTests(ExpressionParserText); |
| defineReflectiveTests(FormalParameterParserTest); |
| defineReflectiveTests(NonErrorParserTest); |
| defineReflectiveTests(RecoveryParserTest); |
| @@ -45,6 +46,8 @@ abstract class AbstractParserTestCase implements ParserTestHelpers { |
| void set enableGenericMethodComments(bool value); |
| + void set enableLazyAssignmentOperators(bool value); |
| + |
| void set enableNnbd(bool value); |
| /** |
| @@ -3947,7732 +3950,7971 @@ void main() { |
| } |
| } |
| -/** |
| - * Tests of the analyzer parser based on [FormalParameterParserTestMixin]. |
| - */ |
| @reflectiveTest |
| -class FormalParameterParserTest extends ParserTestCase |
| - with FormalParameterParserTestMixin {} |
| +class ExpressionParserText extends ParserTestCase |
|
Paul Berry
2017/02/27 20:39:39
I think you mean "ExpressionParserTest"
|
| + with ExpressionParserTextMixin {} |
| -/** |
| - * The class [FormalParameterParserTestMixin] defines parser tests that test |
| - * the parsing of formal parameters. |
| - */ |
| -abstract class FormalParameterParserTestMixin |
| - implements AbstractParserTestCase { |
| - void test_parseFormalParameter_covariant_final_named() { |
| - ParameterKind kind = ParameterKind.NAMED; |
| - FormalParameter parameter = |
| - parseFormalParameter('covariant final a : null', kind); |
| - expect(parameter, isNotNull); |
| +abstract class ExpressionParserTextMixin implements AbstractParserTestCase { |
|
Paul Berry
2017/02/27 20:39:39
Similarly, this should be "ExpressionParserTestMix
|
| + void test_parseAdditiveExpression_normal() { |
| + createParser('x + y'); |
| + Expression expression = parser.parseAdditiveExpression(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| - DefaultFormalParameter defaultParameter = parameter; |
| - SimpleFormalParameter simpleParameter = |
| - defaultParameter.parameter as SimpleFormalParameter; |
| - expect(simpleParameter.covariantKeyword, isNotNull); |
| - expect(simpleParameter.identifier, isNotNull); |
| - expect(simpleParameter.keyword, isNotNull); |
| - expect(simpleParameter.type, isNull); |
| - expect(simpleParameter.kind, kind); |
| - expect(defaultParameter.separator, isNotNull); |
| - expect(defaultParameter.defaultValue, isNotNull); |
| - expect(defaultParameter.kind, kind); |
| + expect(expression, new isInstanceOf<BinaryExpression>()); |
| + BinaryExpression binaryExpression = expression; |
| + expect(binaryExpression.leftOperand, isNotNull); |
| + expect(binaryExpression.operator, isNotNull); |
| + expect(binaryExpression.operator.type, TokenType.PLUS); |
| + expect(binaryExpression.rightOperand, isNotNull); |
| } |
| - void test_parseFormalParameter_covariant_final_normal() { |
| - ParameterKind kind = ParameterKind.REQUIRED; |
| - FormalParameter parameter = parseFormalParameter('covariant final a', kind); |
| - expect(parameter, isNotNull); |
| + void test_parseAdditiveExpression_super() { |
| + createParser('super + y'); |
| + Expression expression = parser.parseAdditiveExpression(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| - SimpleFormalParameter simpleParameter = parameter; |
| - expect(simpleParameter.covariantKeyword, isNotNull); |
| - expect(simpleParameter.identifier, isNotNull); |
| - expect(simpleParameter.keyword, isNotNull); |
| - expect(simpleParameter.type, isNull); |
| - expect(simpleParameter.kind, kind); |
| + expect(expression, new isInstanceOf<BinaryExpression>()); |
| + BinaryExpression binaryExpression = expression; |
| + expect(binaryExpression.leftOperand, new isInstanceOf<SuperExpression>()); |
| + expect(binaryExpression.operator, isNotNull); |
| + expect(binaryExpression.operator.type, TokenType.PLUS); |
| + expect(binaryExpression.rightOperand, isNotNull); |
| } |
| - void test_parseFormalParameter_covariant_final_positional() { |
| - ParameterKind kind = ParameterKind.POSITIONAL; |
| - FormalParameter parameter = |
| - parseFormalParameter('covariant final a = null', kind); |
| - expect(parameter, isNotNull); |
| + void test_parseAssignableExpression_expression_args_dot() { |
| + createParser('(x)(y).z'); |
| + Expression expression = parser.parseAssignableExpression(false); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| - DefaultFormalParameter defaultParameter = parameter; |
| - SimpleFormalParameter simpleParameter = |
| - defaultParameter.parameter as SimpleFormalParameter; |
| - expect(simpleParameter.covariantKeyword, isNotNull); |
| - expect(simpleParameter.identifier, isNotNull); |
| - expect(simpleParameter.keyword, isNotNull); |
| - expect(simpleParameter.type, isNull); |
| - expect(simpleParameter.kind, kind); |
| - expect(defaultParameter.separator, isNotNull); |
| - expect(defaultParameter.defaultValue, isNotNull); |
| - expect(defaultParameter.kind, kind); |
| + expect(expression, new isInstanceOf<PropertyAccess>()); |
| + PropertyAccess propertyAccess = expression; |
| + FunctionExpressionInvocation invocation = |
| + propertyAccess.target as FunctionExpressionInvocation; |
| + expect(invocation.function, isNotNull); |
| + expect(invocation.typeArguments, isNull); |
| + ArgumentList argumentList = invocation.argumentList; |
| + expect(argumentList, isNotNull); |
| + expect(argumentList.arguments, hasLength(1)); |
| + expect(propertyAccess.operator, isNotNull); |
| + expect(propertyAccess.propertyName, isNotNull); |
| } |
| - void test_parseFormalParameter_covariant_final_type_named() { |
| - ParameterKind kind = ParameterKind.NAMED; |
| - FormalParameter parameter = |
| - parseFormalParameter('covariant final A a : null', kind); |
| - expect(parameter, isNotNull); |
| + void |
| + test_parseAssignableExpression_expression_args_dot_typeParameterComments() { |
| + enableGenericMethodComments = true; |
| + createParser('(x)/*<F>*/(y).z'); |
| + Expression expression = parser.parseAssignableExpression(false); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| - DefaultFormalParameter defaultParameter = parameter; |
| - SimpleFormalParameter simpleParameter = |
| - defaultParameter.parameter as SimpleFormalParameter; |
| - expect(simpleParameter.covariantKeyword, isNotNull); |
| - expect(simpleParameter.identifier, isNotNull); |
| - expect(simpleParameter.keyword, isNotNull); |
| - expect(simpleParameter.type, isNotNull); |
| - expect(simpleParameter.kind, kind); |
| - expect(defaultParameter.separator, isNotNull); |
| - expect(defaultParameter.defaultValue, isNotNull); |
| - expect(defaultParameter.kind, kind); |
| + expect(expression, new isInstanceOf<PropertyAccess>()); |
| + PropertyAccess propertyAccess = expression; |
| + FunctionExpressionInvocation invocation = |
| + propertyAccess.target as FunctionExpressionInvocation; |
| + expect(invocation.function, isNotNull); |
| + expect(invocation.typeArguments, isNotNull); |
| + ArgumentList argumentList = invocation.argumentList; |
| + expect(argumentList, isNotNull); |
| + expect(argumentList.arguments, hasLength(1)); |
| + expect(propertyAccess.operator, isNotNull); |
| + expect(propertyAccess.propertyName, isNotNull); |
| } |
| - void test_parseFormalParameter_covariant_final_type_normal() { |
| - ParameterKind kind = ParameterKind.REQUIRED; |
| - FormalParameter parameter = |
| - parseFormalParameter('covariant final A a', kind); |
| - expect(parameter, isNotNull); |
| + void test_parseAssignableExpression_expression_args_dot_typeParameters() { |
| + createParser('(x)<F>(y).z'); |
| + Expression expression = parser.parseAssignableExpression(false); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| - SimpleFormalParameter simpleParameter = parameter; |
| - expect(simpleParameter.covariantKeyword, isNotNull); |
| - expect(simpleParameter.identifier, isNotNull); |
| - expect(simpleParameter.keyword, isNotNull); |
| - expect(simpleParameter.type, isNotNull); |
| - expect(simpleParameter.kind, kind); |
| + expect(expression, new isInstanceOf<PropertyAccess>()); |
| + PropertyAccess propertyAccess = expression; |
| + FunctionExpressionInvocation invocation = |
| + propertyAccess.target as FunctionExpressionInvocation; |
| + expect(invocation.function, isNotNull); |
| + expect(invocation.typeArguments, isNotNull); |
| + ArgumentList argumentList = invocation.argumentList; |
| + expect(argumentList, isNotNull); |
| + expect(argumentList.arguments, hasLength(1)); |
| + expect(propertyAccess.operator, isNotNull); |
| + expect(propertyAccess.propertyName, isNotNull); |
| } |
| - void test_parseFormalParameter_covariant_final_type_positional() { |
| - ParameterKind kind = ParameterKind.POSITIONAL; |
| - FormalParameter parameter = |
| - parseFormalParameter('covariant final A a = null', kind); |
| - expect(parameter, isNotNull); |
| + void test_parseAssignableExpression_expression_dot() { |
| + createParser('(x).y'); |
| + Expression expression = parser.parseAssignableExpression(false); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| - DefaultFormalParameter defaultParameter = parameter; |
| - SimpleFormalParameter simpleParameter = |
| - defaultParameter.parameter as SimpleFormalParameter; |
| - expect(simpleParameter.covariantKeyword, isNotNull); |
| - expect(simpleParameter.identifier, isNotNull); |
| - expect(simpleParameter.keyword, isNotNull); |
| - expect(simpleParameter.type, isNotNull); |
| - expect(simpleParameter.kind, kind); |
| - expect(defaultParameter.separator, isNotNull); |
| - expect(defaultParameter.defaultValue, isNotNull); |
| - expect(defaultParameter.kind, kind); |
| + expect(expression, new isInstanceOf<PropertyAccess>()); |
| + PropertyAccess propertyAccess = expression; |
| + expect(propertyAccess.target, isNotNull); |
| + expect(propertyAccess.operator.type, TokenType.PERIOD); |
| + expect(propertyAccess.propertyName, isNotNull); |
| } |
| - void test_parseFormalParameter_covariant_type_function() { |
| - ParameterKind kind = ParameterKind.REQUIRED; |
| - FormalParameter parameter = |
| - parseFormalParameter('covariant String Function(int) a', kind); |
| - expect(parameter, isNotNull); |
| + void test_parseAssignableExpression_expression_index() { |
| + createParser('(x)[y]'); |
| + Expression expression = parser.parseAssignableExpression(false); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| - SimpleFormalParameter simpleParameter = parameter; |
| - expect(simpleParameter.covariantKeyword, isNotNull); |
| - expect(simpleParameter.identifier, isNotNull); |
| - expect(simpleParameter.keyword, isNull); |
| - expect(simpleParameter.type, new isInstanceOf<GenericFunctionType>()); |
| - expect(simpleParameter.kind, kind); |
| + expect(expression, new isInstanceOf<IndexExpression>()); |
| + IndexExpression indexExpression = expression; |
| + expect(indexExpression.target, isNotNull); |
| + expect(indexExpression.leftBracket, isNotNull); |
| + expect(indexExpression.index, isNotNull); |
| + expect(indexExpression.rightBracket, isNotNull); |
| } |
| - void test_parseFormalParameter_covariant_type_named() { |
| - ParameterKind kind = ParameterKind.NAMED; |
| - FormalParameter parameter = |
| - parseFormalParameter('covariant A a : null', kind); |
| - expect(parameter, isNotNull); |
| + void test_parseAssignableExpression_expression_question_dot() { |
| + createParser('(x)?.y'); |
| + Expression expression = parser.parseAssignableExpression(false); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| - DefaultFormalParameter defaultParameter = parameter; |
| - SimpleFormalParameter simpleParameter = |
| - defaultParameter.parameter as SimpleFormalParameter; |
| - expect(simpleParameter.covariantKeyword, isNotNull); |
| - expect(simpleParameter.identifier, isNotNull); |
| - expect(simpleParameter.keyword, isNull); |
| - expect(simpleParameter.type, isNotNull); |
| - expect(simpleParameter.kind, kind); |
| - expect(defaultParameter.separator, isNotNull); |
| - expect(defaultParameter.defaultValue, isNotNull); |
| - expect(defaultParameter.kind, kind); |
| + expect(expression, new isInstanceOf<PropertyAccess>()); |
| + PropertyAccess propertyAccess = expression; |
| + expect(propertyAccess.target, isNotNull); |
| + expect(propertyAccess.operator.type, TokenType.QUESTION_PERIOD); |
| + expect(propertyAccess.propertyName, isNotNull); |
| } |
| - void test_parseFormalParameter_covariant_type_normal() { |
| - ParameterKind kind = ParameterKind.REQUIRED; |
| - FormalParameter parameter = |
| - parseFormalParameter('covariant A<B<C>> a', kind); |
| - expect(parameter, isNotNull); |
| + void test_parseAssignableExpression_identifier() { |
| + createParser('x'); |
| + Expression expression = parser.parseAssignableExpression(false); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| - SimpleFormalParameter simpleParameter = parameter; |
| - expect(simpleParameter.covariantKeyword, isNotNull); |
| - expect(simpleParameter.identifier, isNotNull); |
| - expect(simpleParameter.keyword, isNull); |
| - expect(simpleParameter.type, isNotNull); |
| - expect(simpleParameter.kind, kind); |
| + expect(expression, new isInstanceOf<SimpleIdentifier>()); |
| + SimpleIdentifier identifier = expression; |
| + expect(identifier, isNotNull); |
| } |
| - void test_parseFormalParameter_covariant_type_positional() { |
| - ParameterKind kind = ParameterKind.POSITIONAL; |
| - FormalParameter parameter = |
| - parseFormalParameter('covariant A a = null', kind); |
| - expect(parameter, isNotNull); |
| + void test_parseAssignableExpression_identifier_args_dot() { |
| + createParser('x(y).z'); |
| + Expression expression = parser.parseAssignableExpression(false); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| - DefaultFormalParameter defaultParameter = parameter; |
| - SimpleFormalParameter simpleParameter = |
| - defaultParameter.parameter as SimpleFormalParameter; |
| - expect(simpleParameter.covariantKeyword, isNotNull); |
| - expect(simpleParameter.identifier, isNotNull); |
| - expect(simpleParameter.keyword, isNull); |
| - expect(simpleParameter.type, isNotNull); |
| - expect(simpleParameter.kind, kind); |
| - expect(defaultParameter.separator, isNotNull); |
| - expect(defaultParameter.defaultValue, isNotNull); |
| - expect(defaultParameter.kind, kind); |
| + expect(expression, new isInstanceOf<PropertyAccess>()); |
| + PropertyAccess propertyAccess = expression; |
| + MethodInvocation invocation = propertyAccess.target as MethodInvocation; |
| + expect(invocation.methodName.name, "x"); |
| + expect(invocation.typeArguments, isNull); |
| + ArgumentList argumentList = invocation.argumentList; |
| + expect(argumentList, isNotNull); |
| + expect(argumentList.arguments, hasLength(1)); |
| + expect(propertyAccess.operator, isNotNull); |
| + expect(propertyAccess.propertyName, isNotNull); |
| } |
| - void test_parseFormalParameter_covariant_var_named() { |
| - ParameterKind kind = ParameterKind.NAMED; |
| - FormalParameter parameter = |
| - parseFormalParameter('covariant var a : null', kind); |
| - expect(parameter, isNotNull); |
| + void |
| + test_parseAssignableExpression_identifier_args_dot_typeParameterComments() { |
| + enableGenericMethodComments = true; |
| + createParser('x/*<E>*/(y).z'); |
| + Expression expression = parser.parseAssignableExpression(false); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| - DefaultFormalParameter defaultParameter = parameter; |
| - SimpleFormalParameter simpleParameter = |
| - defaultParameter.parameter as SimpleFormalParameter; |
| - expect(simpleParameter.covariantKeyword, isNotNull); |
| - expect(simpleParameter.identifier, isNotNull); |
| - expect(simpleParameter.keyword, isNotNull); |
| - expect(simpleParameter.type, isNull); |
| - expect(simpleParameter.kind, kind); |
| - expect(defaultParameter.separator, isNotNull); |
| - expect(defaultParameter.defaultValue, isNotNull); |
| - expect(defaultParameter.kind, kind); |
| + expect(expression, new isInstanceOf<PropertyAccess>()); |
| + PropertyAccess propertyAccess = expression; |
| + MethodInvocation invocation = propertyAccess.target as MethodInvocation; |
| + expect(invocation.methodName.name, "x"); |
| + expect(invocation.typeArguments, isNotNull); |
| + ArgumentList argumentList = invocation.argumentList; |
| + expect(argumentList, isNotNull); |
| + expect(argumentList.arguments, hasLength(1)); |
| + expect(propertyAccess.operator, isNotNull); |
| + expect(propertyAccess.propertyName, isNotNull); |
| } |
| - void test_parseFormalParameter_covariant_var_normal() { |
| - ParameterKind kind = ParameterKind.REQUIRED; |
| - FormalParameter parameter = parseFormalParameter('covariant var a', kind); |
| - expect(parameter, isNotNull); |
| + void test_parseAssignableExpression_identifier_args_dot_typeParameters() { |
| + createParser('x<E>(y).z'); |
| + Expression expression = parser.parseAssignableExpression(false); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| - SimpleFormalParameter simpleParameter = parameter; |
| - expect(simpleParameter.covariantKeyword, isNotNull); |
| - expect(simpleParameter.identifier, isNotNull); |
| - expect(simpleParameter.keyword, isNotNull); |
| - expect(simpleParameter.type, isNull); |
| - expect(simpleParameter.kind, kind); |
| + expect(expression, new isInstanceOf<PropertyAccess>()); |
| + PropertyAccess propertyAccess = expression; |
| + MethodInvocation invocation = propertyAccess.target as MethodInvocation; |
| + expect(invocation.methodName.name, "x"); |
| + expect(invocation.typeArguments, isNotNull); |
| + ArgumentList argumentList = invocation.argumentList; |
| + expect(argumentList, isNotNull); |
| + expect(argumentList.arguments, hasLength(1)); |
| + expect(propertyAccess.operator, isNotNull); |
| + expect(propertyAccess.propertyName, isNotNull); |
| } |
| - void test_parseFormalParameter_covariant_var_positional() { |
| - ParameterKind kind = ParameterKind.POSITIONAL; |
| - FormalParameter parameter = |
| - parseFormalParameter('covariant var a = null', kind); |
| - expect(parameter, isNotNull); |
| + void test_parseAssignableExpression_identifier_dot() { |
| + createParser('x.y'); |
| + Expression expression = parser.parseAssignableExpression(false); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| - DefaultFormalParameter defaultParameter = parameter; |
| - SimpleFormalParameter simpleParameter = |
| - defaultParameter.parameter as SimpleFormalParameter; |
| - expect(simpleParameter.covariantKeyword, isNotNull); |
| - expect(simpleParameter.identifier, isNotNull); |
| - expect(simpleParameter.keyword, isNotNull); |
| - expect(simpleParameter.type, isNull); |
| - expect(simpleParameter.kind, kind); |
| - expect(defaultParameter.separator, isNotNull); |
| - expect(defaultParameter.defaultValue, isNotNull); |
| - expect(defaultParameter.kind, kind); |
| + expect(expression, new isInstanceOf<PropertyAccess>()); |
| + PropertyAccess propertyAccess = expression; |
| + expect(propertyAccess.target, isNotNull); |
| + expect(propertyAccess.operator, isNotNull); |
| + expect(propertyAccess.operator.type, TokenType.PERIOD); |
| + expect(propertyAccess.propertyName, isNotNull); |
| } |
| - void test_parseFormalParameter_final_named() { |
| - ParameterKind kind = ParameterKind.NAMED; |
| - FormalParameter parameter = parseFormalParameter('final a : null', kind); |
| - expect(parameter, isNotNull); |
| + void test_parseAssignableExpression_identifier_index() { |
| + createParser('x[y]'); |
| + Expression expression = parser.parseAssignableExpression(false); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| - DefaultFormalParameter defaultParameter = parameter; |
| - SimpleFormalParameter simpleParameter = |
| - defaultParameter.parameter as SimpleFormalParameter; |
| - expect(simpleParameter.covariantKeyword, isNull); |
| - expect(simpleParameter.identifier, isNotNull); |
| - expect(simpleParameter.keyword, isNotNull); |
| - expect(simpleParameter.type, isNull); |
| - expect(simpleParameter.kind, kind); |
| - expect(defaultParameter.separator, isNotNull); |
| - expect(defaultParameter.defaultValue, isNotNull); |
| - expect(defaultParameter.kind, kind); |
| + expect(expression, new isInstanceOf<IndexExpression>()); |
| + IndexExpression indexExpression = expression; |
| + expect(indexExpression.target, isNotNull); |
| + expect(indexExpression.leftBracket, isNotNull); |
| + expect(indexExpression.index, isNotNull); |
| + expect(indexExpression.rightBracket, isNotNull); |
| } |
| - void test_parseFormalParameter_final_normal() { |
| - ParameterKind kind = ParameterKind.REQUIRED; |
| - FormalParameter parameter = parseFormalParameter('final a', kind); |
| - expect(parameter, isNotNull); |
| + void test_parseAssignableExpression_identifier_question_dot() { |
| + createParser('x?.y'); |
| + Expression expression = parser.parseAssignableExpression(false); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| - SimpleFormalParameter simpleParameter = parameter; |
| - expect(simpleParameter.covariantKeyword, isNull); |
| - expect(simpleParameter.identifier, isNotNull); |
| - expect(simpleParameter.keyword, isNotNull); |
| - expect(simpleParameter.type, isNull); |
| - expect(simpleParameter.kind, kind); |
| + expect(expression, new isInstanceOf<PropertyAccess>()); |
| + PropertyAccess propertyAccess = expression; |
| + expect(propertyAccess.target, isNotNull); |
| + expect(propertyAccess.operator.type, TokenType.QUESTION_PERIOD); |
| + expect(propertyAccess.propertyName, isNotNull); |
| } |
| - void test_parseFormalParameter_final_positional() { |
| - ParameterKind kind = ParameterKind.POSITIONAL; |
| - FormalParameter parameter = parseFormalParameter('final a = null', kind); |
| - expect(parameter, isNotNull); |
| + void test_parseAssignableExpression_super_dot() { |
| + createParser('super.y'); |
| + Expression expression = parser.parseAssignableExpression(false); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| - DefaultFormalParameter defaultParameter = parameter; |
| - SimpleFormalParameter simpleParameter = |
| - defaultParameter.parameter as SimpleFormalParameter; |
| - expect(simpleParameter.covariantKeyword, isNull); |
| - expect(simpleParameter.identifier, isNotNull); |
| - expect(simpleParameter.keyword, isNotNull); |
| - expect(simpleParameter.type, isNull); |
| - expect(simpleParameter.kind, kind); |
| - expect(defaultParameter.separator, isNotNull); |
| - expect(defaultParameter.defaultValue, isNotNull); |
| - expect(defaultParameter.kind, kind); |
| + expect(expression, new isInstanceOf<PropertyAccess>()); |
| + PropertyAccess propertyAccess = expression; |
| + EngineTestCase.assertInstanceOf((obj) => obj is SuperExpression, |
| + SuperExpression, propertyAccess.target); |
| + expect(propertyAccess.operator, isNotNull); |
| + expect(propertyAccess.propertyName, isNotNull); |
| } |
| - void test_parseFormalParameter_final_type_named() { |
| - ParameterKind kind = ParameterKind.NAMED; |
| - FormalParameter parameter = parseFormalParameter('final A a : null', kind); |
| - expect(parameter, isNotNull); |
| + void test_parseAssignableExpression_super_index() { |
| + createParser('super[y]'); |
| + Expression expression = parser.parseAssignableExpression(false); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| - DefaultFormalParameter defaultParameter = parameter; |
| - SimpleFormalParameter simpleParameter = |
| - defaultParameter.parameter as SimpleFormalParameter; |
| - expect(simpleParameter.covariantKeyword, isNull); |
| - expect(simpleParameter.identifier, isNotNull); |
| - expect(simpleParameter.keyword, isNotNull); |
| - expect(simpleParameter.type, isNotNull); |
| - expect(simpleParameter.kind, kind); |
| - expect(defaultParameter.separator, isNotNull); |
| - expect(defaultParameter.defaultValue, isNotNull); |
| - expect(defaultParameter.kind, kind); |
| + expect(expression, new isInstanceOf<IndexExpression>()); |
| + IndexExpression indexExpression = expression; |
| + expect(indexExpression.target, new isInstanceOf<SuperExpression>()); |
| + expect(indexExpression.leftBracket, isNotNull); |
| + expect(indexExpression.index, isNotNull); |
| + expect(indexExpression.rightBracket, isNotNull); |
| } |
| - void test_parseFormalParameter_final_type_normal() { |
| - ParameterKind kind = ParameterKind.REQUIRED; |
| - FormalParameter parameter = parseFormalParameter('final A a', kind); |
| - expect(parameter, isNotNull); |
| + void test_parseAssignableSelector_dot() { |
| + createParser('.x'); |
| + Expression expression = parser.parseAssignableSelector(null, true); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| - SimpleFormalParameter simpleParameter = parameter; |
| - expect(simpleParameter.covariantKeyword, isNull); |
| - expect(simpleParameter.identifier, isNotNull); |
| - expect(simpleParameter.keyword, isNotNull); |
| - expect(simpleParameter.type, isNotNull); |
| - expect(simpleParameter.kind, kind); |
| + expect(expression, new isInstanceOf<PropertyAccess>()); |
| + PropertyAccess propertyAccess = expression; |
| + expect(propertyAccess.operator.type, TokenType.PERIOD); |
| + expect(propertyAccess.propertyName, isNotNull); |
| } |
| - void test_parseFormalParameter_final_type_positional() { |
| - ParameterKind kind = ParameterKind.POSITIONAL; |
| - FormalParameter parameter = parseFormalParameter('final A a = null', kind); |
| - expect(parameter, isNotNull); |
| + void test_parseAssignableSelector_index() { |
| + createParser('[x]'); |
| + Expression expression = parser.parseAssignableSelector(null, true); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| - DefaultFormalParameter defaultParameter = parameter; |
| - SimpleFormalParameter simpleParameter = |
| - defaultParameter.parameter as SimpleFormalParameter; |
| - expect(simpleParameter.covariantKeyword, isNull); |
| - expect(simpleParameter.identifier, isNotNull); |
| - expect(simpleParameter.keyword, isNotNull); |
| - expect(simpleParameter.type, isNotNull); |
| - expect(simpleParameter.kind, kind); |
| - expect(defaultParameter.separator, isNotNull); |
| - expect(defaultParameter.defaultValue, isNotNull); |
| - expect(defaultParameter.kind, kind); |
| + expect(expression, new isInstanceOf<IndexExpression>()); |
| + IndexExpression indexExpression = expression; |
| + expect(indexExpression.leftBracket, isNotNull); |
| + expect(indexExpression.index, isNotNull); |
| + expect(indexExpression.rightBracket, isNotNull); |
| } |
| - void test_parseFormalParameter_type_function() { |
| - ParameterKind kind = ParameterKind.REQUIRED; |
| - FormalParameter parameter = |
| - parseFormalParameter('String Function(int) a', kind); |
| - expect(parameter, isNotNull); |
| - assertNoErrors(); |
| - expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| - SimpleFormalParameter simpleParameter = parameter; |
| - expect(simpleParameter.covariantKeyword, isNull); |
| - expect(simpleParameter.identifier, isNotNull); |
| - expect(simpleParameter.keyword, isNull); |
| - expect(simpleParameter.type, new isInstanceOf<GenericFunctionType>()); |
| - expect(simpleParameter.kind, kind); |
| - } |
| - |
| - void test_parseFormalParameter_type_named() { |
| - ParameterKind kind = ParameterKind.NAMED; |
| - FormalParameter parameter = parseFormalParameter('A a : null', kind); |
| - expect(parameter, isNotNull); |
| + void test_parseAssignableSelector_none() { |
| + createParser(';'); |
| + Expression expression = |
| + parser.parseAssignableSelector(astFactory.simpleIdentifier(null), true); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| - DefaultFormalParameter defaultParameter = parameter; |
| - SimpleFormalParameter simpleParameter = |
| - defaultParameter.parameter as SimpleFormalParameter; |
| - expect(simpleParameter.covariantKeyword, isNull); |
| - expect(simpleParameter.identifier, isNotNull); |
| - expect(simpleParameter.keyword, isNull); |
| - expect(simpleParameter.type, isNotNull); |
| - expect(simpleParameter.kind, kind); |
| - expect(defaultParameter.separator, isNotNull); |
| - expect(defaultParameter.defaultValue, isNotNull); |
| - expect(defaultParameter.kind, kind); |
| + expect(expression, new isInstanceOf<SimpleIdentifier>()); |
| + SimpleIdentifier identifier = expression; |
| + expect(identifier, isNotNull); |
| } |
| - void test_parseFormalParameter_type_normal() { |
| - ParameterKind kind = ParameterKind.REQUIRED; |
| - FormalParameter parameter = parseFormalParameter('A a', kind); |
| - expect(parameter, isNotNull); |
| + void test_parseAssignableSelector_question_dot() { |
| + createParser('?.x'); |
| + Expression expression = parser.parseAssignableSelector(null, true); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| - SimpleFormalParameter simpleParameter = parameter; |
| - expect(simpleParameter.covariantKeyword, isNull); |
| - expect(simpleParameter.identifier, isNotNull); |
| - expect(simpleParameter.keyword, isNull); |
| - expect(simpleParameter.type, isNotNull); |
| - expect(simpleParameter.kind, kind); |
| + expect(expression, new isInstanceOf<PropertyAccess>()); |
| + PropertyAccess propertyAccess = expression; |
| + expect(propertyAccess.operator.type, TokenType.QUESTION_PERIOD); |
| + expect(propertyAccess.propertyName, isNotNull); |
| } |
| - void test_parseFormalParameter_type_positional() { |
| - ParameterKind kind = ParameterKind.POSITIONAL; |
| - FormalParameter parameter = parseFormalParameter('A a = null', kind); |
| - expect(parameter, isNotNull); |
| + void test_parseAwaitExpression() { |
| + createParser('await x;'); |
| + AwaitExpression expression = parser.parseAwaitExpression(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| - DefaultFormalParameter defaultParameter = parameter; |
| - SimpleFormalParameter simpleParameter = |
| - defaultParameter.parameter as SimpleFormalParameter; |
| - expect(simpleParameter.covariantKeyword, isNull); |
| - expect(simpleParameter.identifier, isNotNull); |
| - expect(simpleParameter.keyword, isNull); |
| - expect(simpleParameter.type, isNotNull); |
| - expect(simpleParameter.kind, kind); |
| - expect(defaultParameter.separator, isNotNull); |
| - expect(defaultParameter.defaultValue, isNotNull); |
| - expect(defaultParameter.kind, kind); |
| + expect(expression.awaitKeyword, isNotNull); |
| + expect(expression.expression, isNotNull); |
| } |
| - void test_parseFormalParameter_var_named() { |
| - ParameterKind kind = ParameterKind.NAMED; |
| - FormalParameter parameter = parseFormalParameter('var a : null', kind); |
| - expect(parameter, isNotNull); |
| + void test_parseBitwiseAndExpression_normal() { |
| + createParser('x & y'); |
| + Expression expression = parser.parseBitwiseAndExpression(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| - DefaultFormalParameter defaultParameter = parameter; |
| - SimpleFormalParameter simpleParameter = |
| - defaultParameter.parameter as SimpleFormalParameter; |
| - expect(simpleParameter.covariantKeyword, isNull); |
| - expect(simpleParameter.identifier, isNotNull); |
| - expect(simpleParameter.keyword, isNotNull); |
| - expect(simpleParameter.type, isNull); |
| - expect(simpleParameter.kind, kind); |
| - expect(defaultParameter.separator, isNotNull); |
| - expect(defaultParameter.defaultValue, isNotNull); |
| - expect(defaultParameter.kind, kind); |
| + expect(expression, new isInstanceOf<BinaryExpression>()); |
| + BinaryExpression binaryExpression = expression; |
| + expect(binaryExpression.leftOperand, isNotNull); |
| + expect(binaryExpression.operator, isNotNull); |
| + expect(binaryExpression.operator.type, TokenType.AMPERSAND); |
| + expect(binaryExpression.rightOperand, isNotNull); |
| } |
| - void test_parseFormalParameter_var_normal() { |
| - ParameterKind kind = ParameterKind.REQUIRED; |
| - FormalParameter parameter = parseFormalParameter('var a', kind); |
| - expect(parameter, isNotNull); |
| + void test_parseBitwiseAndExpression_super() { |
| + createParser('super & y'); |
| + Expression expression = parser.parseBitwiseAndExpression(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| - SimpleFormalParameter simpleParameter = parameter; |
| - expect(simpleParameter.covariantKeyword, isNull); |
| - expect(simpleParameter.identifier, isNotNull); |
| - expect(simpleParameter.keyword, isNotNull); |
| - expect(simpleParameter.type, isNull); |
| - expect(simpleParameter.kind, kind); |
| + expect(expression, new isInstanceOf<BinaryExpression>()); |
| + BinaryExpression binaryExpression = expression; |
| + expect(binaryExpression.leftOperand, new isInstanceOf<SuperExpression>()); |
| + expect(binaryExpression.operator, isNotNull); |
| + expect(binaryExpression.operator.type, TokenType.AMPERSAND); |
| + expect(binaryExpression.rightOperand, isNotNull); |
| } |
| - void test_parseFormalParameter_var_positional() { |
| - ParameterKind kind = ParameterKind.POSITIONAL; |
| - FormalParameter parameter = parseFormalParameter('var a = null', kind); |
| - expect(parameter, isNotNull); |
| + void test_parseBitwiseOrExpression_normal() { |
| + createParser('x | y'); |
| + Expression expression = parser.parseBitwiseOrExpression(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| - DefaultFormalParameter defaultParameter = parameter; |
| - SimpleFormalParameter simpleParameter = |
| - defaultParameter.parameter as SimpleFormalParameter; |
| - expect(simpleParameter.covariantKeyword, isNull); |
| - expect(simpleParameter.identifier, isNotNull); |
| - expect(simpleParameter.keyword, isNotNull); |
| - expect(simpleParameter.type, isNull); |
| - expect(simpleParameter.kind, kind); |
| - expect(defaultParameter.separator, isNotNull); |
| - expect(defaultParameter.defaultValue, isNotNull); |
| - expect(defaultParameter.kind, kind); |
| + expect(expression, new isInstanceOf<BinaryExpression>()); |
| + BinaryExpression binaryExpression = expression; |
| + expect(binaryExpression.leftOperand, isNotNull); |
| + expect(binaryExpression.operator, isNotNull); |
| + expect(binaryExpression.operator.type, TokenType.BAR); |
| + expect(binaryExpression.rightOperand, isNotNull); |
| } |
| - void test_parseFormalParameterList_empty() { |
| - FormalParameterList list = parseFormalParameterList('()'); |
| - expect(list, isNotNull); |
| + void test_parseBitwiseOrExpression_super() { |
| + createParser('super | y'); |
| + Expression expression = parser.parseBitwiseOrExpression(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(list.leftParenthesis, isNotNull); |
| - expect(list.leftDelimiter, isNull); |
| - expect(list.parameters, hasLength(0)); |
| - expect(list.rightDelimiter, isNull); |
| - expect(list.rightParenthesis, isNotNull); |
| + expect(expression, new isInstanceOf<BinaryExpression>()); |
| + BinaryExpression binaryExpression = expression; |
| + expect(binaryExpression.leftOperand, new isInstanceOf<SuperExpression>()); |
| + expect(binaryExpression.operator, isNotNull); |
| + expect(binaryExpression.operator.type, TokenType.BAR); |
| + expect(binaryExpression.rightOperand, isNotNull); |
| } |
| - void test_parseFormalParameterList_named_multiple() { |
| - FormalParameterList list = |
| - parseFormalParameterList('({A a : 1, B b, C c : 3})'); |
| - expect(list, isNotNull); |
| + void test_parseBitwiseXorExpression_normal() { |
| + createParser('x ^ y'); |
| + Expression expression = parser.parseBitwiseXorExpression(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(list.leftParenthesis, isNotNull); |
| - expect(list.leftDelimiter, isNotNull); |
| - expect(list.parameters, hasLength(3)); |
| - expect(list.rightDelimiter, isNotNull); |
| - expect(list.rightParenthesis, isNotNull); |
| + expect(expression, new isInstanceOf<BinaryExpression>()); |
| + BinaryExpression binaryExpression = expression; |
| + expect(binaryExpression.leftOperand, isNotNull); |
| + expect(binaryExpression.operator, isNotNull); |
| + expect(binaryExpression.operator.type, TokenType.CARET); |
| + expect(binaryExpression.rightOperand, isNotNull); |
| } |
| - void test_parseFormalParameterList_named_single() { |
| - FormalParameterList list = parseFormalParameterList('({A a})'); |
| - expect(list, isNotNull); |
| + void test_parseBitwiseXorExpression_super() { |
| + createParser('super ^ y'); |
| + Expression expression = parser.parseBitwiseXorExpression(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(list.leftParenthesis, isNotNull); |
| - expect(list.leftDelimiter, isNotNull); |
| - expect(list.parameters, hasLength(1)); |
| - expect(list.rightDelimiter, isNotNull); |
| - expect(list.rightParenthesis, isNotNull); |
| + expect(expression, new isInstanceOf<BinaryExpression>()); |
| + BinaryExpression binaryExpression = expression; |
| + expect(binaryExpression.leftOperand, new isInstanceOf<SuperExpression>()); |
| + expect(binaryExpression.operator, isNotNull); |
| + expect(binaryExpression.operator.type, TokenType.CARET); |
| + expect(binaryExpression.rightOperand, isNotNull); |
| } |
| - void test_parseFormalParameterList_named_trailing_comma() { |
| - FormalParameterList list = parseFormalParameterList('(A a, {B b,})'); |
| - expect(list, isNotNull); |
| + void test_parseCascadeSection_i() { |
| + createParser('..[i]'); |
| + Expression expression = parser.parseCascadeSection(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(list.leftParenthesis, isNotNull); |
| - expect(list.leftDelimiter, isNotNull); |
| - expect(list.parameters, hasLength(2)); |
| - expect(list.rightDelimiter, isNotNull); |
| - expect(list.rightParenthesis, isNotNull); |
| + expect(expression, new isInstanceOf<IndexExpression>()); |
| + IndexExpression section = expression; |
| + expect(section.target, isNull); |
| + expect(section.leftBracket, isNotNull); |
| + expect(section.index, isNotNull); |
| + expect(section.rightBracket, isNotNull); |
| } |
| - void test_parseFormalParameterList_normal_multiple() { |
| - FormalParameterList list = parseFormalParameterList('(A a, B b, C c)'); |
| - expect(list, isNotNull); |
| + void test_parseCascadeSection_ia() { |
| + createParser('..[i](b)'); |
| + Expression expression = parser.parseCascadeSection(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(list.leftParenthesis, isNotNull); |
| - expect(list.leftDelimiter, isNull); |
| - expect(list.parameters, hasLength(3)); |
| - expect(list.rightDelimiter, isNull); |
| - expect(list.rightParenthesis, isNotNull); |
| + expect(expression, new isInstanceOf<FunctionExpressionInvocation>()); |
| + FunctionExpressionInvocation section = expression; |
| + expect(section.function, new isInstanceOf<IndexExpression>()); |
| + expect(section.typeArguments, isNull); |
| + expect(section.argumentList, isNotNull); |
| } |
| - void test_parseFormalParameterList_normal_named() { |
| - FormalParameterList list = parseFormalParameterList('(A a, {B b})'); |
| - expect(list, isNotNull); |
| + void test_parseCascadeSection_ia_typeArgumentComments() { |
| + enableGenericMethodComments = true; |
| + createParser('..[i]/*<E>*/(b)'); |
| + Expression expression = parser.parseCascadeSection(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(list.leftParenthesis, isNotNull); |
| - expect(list.leftDelimiter, isNotNull); |
| - expect(list.parameters, hasLength(2)); |
| - expect(list.rightDelimiter, isNotNull); |
| - expect(list.rightParenthesis, isNotNull); |
| + expect(expression, new isInstanceOf<FunctionExpressionInvocation>()); |
| + FunctionExpressionInvocation section = expression; |
| + expect(section.function, new isInstanceOf<IndexExpression>()); |
| + expect(section.typeArguments, isNotNull); |
| + expect(section.argumentList, isNotNull); |
| } |
| - void test_parseFormalParameterList_normal_named_inFunctionType() { |
| - FormalParameterList list = |
| - parseFormalParameterList('(A, {B b})', inFunctionType: true); |
| - expect(list, isNotNull); |
| + void test_parseCascadeSection_ia_typeArguments() { |
| + createParser('..[i]<E>(b)'); |
| + Expression expression = parser.parseCascadeSection(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(list.leftParenthesis, isNotNull); |
| - expect(list.leftDelimiter, isNotNull); |
| - expect(list.rightDelimiter, isNotNull); |
| - expect(list.rightParenthesis, isNotNull); |
| - NodeList<FormalParameter> parameters = list.parameters; |
| - expect(parameters, hasLength(2)); |
| - |
| - expect(parameters[0], new isInstanceOf<SimpleFormalParameter>()); |
| - SimpleFormalParameter required = parameters[0]; |
| - expect(required.identifier, isNull); |
| - expect(required.type, new isInstanceOf<TypeName>()); |
| - expect((required.type as TypeName).name.name, 'A'); |
| - |
| - expect(parameters[1], new isInstanceOf<DefaultFormalParameter>()); |
| - DefaultFormalParameter named = parameters[1]; |
| - expect(named.identifier, isNotNull); |
| - expect(named.parameter, new isInstanceOf<SimpleFormalParameter>()); |
| - SimpleFormalParameter simple = named.parameter; |
| - expect(simple.type, new isInstanceOf<TypeName>()); |
| - expect((simple.type as TypeName).name.name, 'B'); |
| + expect(expression, new isInstanceOf<FunctionExpressionInvocation>()); |
| + FunctionExpressionInvocation section = expression; |
| + expect(section.function, new isInstanceOf<IndexExpression>()); |
| + expect(section.typeArguments, isNotNull); |
| + expect(section.argumentList, isNotNull); |
| } |
| - void test_parseFormalParameterList_normal_positional() { |
| - FormalParameterList list = parseFormalParameterList('(A a, [B b])'); |
| - expect(list, isNotNull); |
| + void test_parseCascadeSection_ii() { |
| + createParser('..a(b).c(d)'); |
| + Expression expression = parser.parseCascadeSection(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(list.leftParenthesis, isNotNull); |
| - expect(list.leftDelimiter, isNotNull); |
| - expect(list.parameters, hasLength(2)); |
| - expect(list.rightDelimiter, isNotNull); |
| - expect(list.rightParenthesis, isNotNull); |
| + expect(expression, new isInstanceOf<MethodInvocation>()); |
| + MethodInvocation section = expression; |
| + expect(section.target, new isInstanceOf<MethodInvocation>()); |
| + expect(section.operator, isNotNull); |
| + expect(section.methodName, isNotNull); |
| + expect(section.typeArguments, isNull); |
| + expect(section.argumentList, isNotNull); |
| + expect(section.argumentList.arguments, hasLength(1)); |
| } |
| - void test_parseFormalParameterList_normal_single() { |
| - FormalParameterList list = parseFormalParameterList('(A a)'); |
| - expect(list, isNotNull); |
| + void test_parseCascadeSection_ii_typeArgumentComments() { |
| + enableGenericMethodComments = true; |
| + createParser('..a/*<E>*/(b).c/*<F>*/(d)'); |
| + Expression expression = parser.parseCascadeSection(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(list.leftParenthesis, isNotNull); |
| - expect(list.leftDelimiter, isNull); |
| - expect(list.parameters, hasLength(1)); |
| - expect(list.rightDelimiter, isNull); |
| - expect(list.rightParenthesis, isNotNull); |
| + expect(expression, new isInstanceOf<MethodInvocation>()); |
| + MethodInvocation section = expression; |
| + expect(section.target, new isInstanceOf<MethodInvocation>()); |
| + expect(section.operator, isNotNull); |
| + expect(section.methodName, isNotNull); |
| + expect(section.typeArguments, isNotNull); |
| + expect(section.argumentList, isNotNull); |
| + expect(section.argumentList.arguments, hasLength(1)); |
| } |
| - void test_parseFormalParameterList_normal_single_Function() { |
| - FormalParameterList list = parseFormalParameterList('(Function f)'); |
| - expect(list, isNotNull); |
| + void test_parseCascadeSection_ii_typeArguments() { |
| + createParser('..a<E>(b).c<F>(d)'); |
| + Expression expression = parser.parseCascadeSection(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(list.leftParenthesis, isNotNull); |
| - expect(list.leftDelimiter, isNull); |
| - expect(list.parameters, hasLength(1)); |
| - expect(list.rightDelimiter, isNull); |
| - expect(list.rightParenthesis, isNotNull); |
| + expect(expression, new isInstanceOf<MethodInvocation>()); |
| + MethodInvocation section = expression; |
| + expect(section.target, new isInstanceOf<MethodInvocation>()); |
| + expect(section.operator, isNotNull); |
| + expect(section.methodName, isNotNull); |
| + expect(section.typeArguments, isNotNull); |
| + expect(section.argumentList, isNotNull); |
| + expect(section.argumentList.arguments, hasLength(1)); |
| } |
| - void test_parseFormalParameterList_normal_single_trailing_comma() { |
| - FormalParameterList list = parseFormalParameterList('(A a,)'); |
| - expect(list, isNotNull); |
| + void test_parseCascadeSection_p() { |
| + createParser('..a'); |
| + Expression expression = parser.parseCascadeSection(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(list.leftParenthesis, isNotNull); |
| - expect(list.leftDelimiter, isNull); |
| - expect(list.parameters, hasLength(1)); |
| - expect(list.rightDelimiter, isNull); |
| - expect(list.rightParenthesis, isNotNull); |
| + expect(expression, new isInstanceOf<PropertyAccess>()); |
| + PropertyAccess section = expression; |
| + expect(section.target, isNull); |
| + expect(section.operator, isNotNull); |
| + expect(section.propertyName, isNotNull); |
| } |
| - void test_parseFormalParameterList_positional_multiple() { |
| - FormalParameterList list = |
| - parseFormalParameterList('([A a = null, B b, C c = null])'); |
| - expect(list, isNotNull); |
| + void test_parseCascadeSection_p_assign() { |
| + createParser('..a = 3'); |
| + Expression expression = parser.parseCascadeSection(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(list.leftParenthesis, isNotNull); |
| - expect(list.leftDelimiter, isNotNull); |
| - expect(list.parameters, hasLength(3)); |
| - expect(list.rightDelimiter, isNotNull); |
| - expect(list.rightParenthesis, isNotNull); |
| + expect(expression, new isInstanceOf<AssignmentExpression>()); |
| + AssignmentExpression section = expression; |
| + expect(section.leftHandSide, isNotNull); |
| + expect(section.operator, isNotNull); |
| + Expression rhs = section.rightHandSide; |
| + expect(rhs, isNotNull); |
| } |
| - void test_parseFormalParameterList_positional_single() { |
| - FormalParameterList list = parseFormalParameterList('([A a = null])'); |
| - expect(list, isNotNull); |
| + void test_parseCascadeSection_p_assign_withCascade() { |
| + createParser('..a = 3..m()'); |
| + Expression expression = parser.parseCascadeSection(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(list.leftParenthesis, isNotNull); |
| - expect(list.leftDelimiter, isNotNull); |
| - expect(list.parameters, hasLength(1)); |
| - expect(list.rightDelimiter, isNotNull); |
| - expect(list.rightParenthesis, isNotNull); |
| + expect(expression, new isInstanceOf<AssignmentExpression>()); |
| + AssignmentExpression section = expression; |
| + expect(section.leftHandSide, isNotNull); |
| + expect(section.operator, isNotNull); |
| + Expression rhs = section.rightHandSide; |
| + EngineTestCase.assertInstanceOf( |
| + (obj) => obj is IntegerLiteral, IntegerLiteral, rhs); |
| } |
| - void test_parseFormalParameterList_positional_trailing_comma() { |
| - FormalParameterList list = parseFormalParameterList('(A a, [B b,])'); |
| - expect(list, isNotNull); |
| + void test_parseCascadeSection_p_assign_withCascade_typeArgumentComments() { |
| + enableGenericMethodComments = true; |
| + createParser('..a = 3..m/*<E>*/()'); |
| + Expression expression = parser.parseCascadeSection(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(list.leftParenthesis, isNotNull); |
| - expect(list.leftDelimiter, isNotNull); |
| - expect(list.parameters, hasLength(2)); |
| - expect(list.rightDelimiter, isNotNull); |
| - expect(list.rightParenthesis, isNotNull); |
| + expect(expression, new isInstanceOf<AssignmentExpression>()); |
| + AssignmentExpression section = expression; |
| + expect(section.leftHandSide, isNotNull); |
| + expect(section.operator, isNotNull); |
| + Expression rhs = section.rightHandSide; |
| + EngineTestCase.assertInstanceOf( |
| + (obj) => obj is IntegerLiteral, IntegerLiteral, rhs); |
| } |
| - void test_parseFormalParameterList_prefixedType() { |
| - FormalParameterList list = parseFormalParameterList('(io.File f)'); |
| - expect(list, isNotNull); |
| + void test_parseCascadeSection_p_assign_withCascade_typeArguments() { |
| + createParser('..a = 3..m<E>()'); |
| + Expression expression = parser.parseCascadeSection(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(list.leftParenthesis, isNotNull); |
| - expect(list.leftDelimiter, isNull); |
| - expect(list.parameters, hasLength(1)); |
| - expect(list.parameters[0].toSource(), 'io.File f'); |
| - expect(list.rightDelimiter, isNull); |
| - expect(list.rightParenthesis, isNotNull); |
| - } |
| - |
| - void test_parseFormalParameterList_prefixedType_partial() { |
| - FormalParameterList list = parseFormalParameterList('(io.)', errorCodes: [ |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER |
| - ]); |
| - expect(list, isNotNull); |
| - expect(list.leftParenthesis, isNotNull); |
| - expect(list.leftDelimiter, isNull); |
| - expect(list.parameters, hasLength(1)); |
| - expect(list.parameters[0].toSource(), 'io. '); |
| - expect(list.rightDelimiter, isNull); |
| - expect(list.rightParenthesis, isNotNull); |
| - } |
| - |
| - void test_parseFormalParameterList_prefixedType_partial2() { |
| - FormalParameterList list = parseFormalParameterList('(io.,a)', errorCodes: [ |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER |
| - ]); |
| - expect(list, isNotNull); |
| - expect(list.leftParenthesis, isNotNull); |
| - expect(list.leftDelimiter, isNull); |
| - expect(list.parameters, hasLength(2)); |
| - expect(list.parameters[0].toSource(), 'io. '); |
| - expect(list.parameters[1].toSource(), 'a'); |
| - expect(list.rightDelimiter, isNull); |
| - expect(list.rightParenthesis, isNotNull); |
| + expect(expression, new isInstanceOf<AssignmentExpression>()); |
| + AssignmentExpression section = expression; |
| + expect(section.leftHandSide, isNotNull); |
| + expect(section.operator, isNotNull); |
| + Expression rhs = section.rightHandSide; |
| + EngineTestCase.assertInstanceOf( |
| + (obj) => obj is IntegerLiteral, IntegerLiteral, rhs); |
| } |
| - void test_parseNormalFormalParameter_field_const_noType() { |
| - NormalFormalParameter parameter = |
| - parseNormalFormalParameter('const this.a'); |
| - expect(parameter, isNotNull); |
| + void test_parseCascadeSection_p_builtIn() { |
| + createParser('..as'); |
| + Expression expression = parser.parseCascadeSection(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<FieldFormalParameter>()); |
| - FieldFormalParameter fieldParameter = parameter; |
| - expect(fieldParameter.keyword, isNotNull); |
| - expect(fieldParameter.type, isNull); |
| - expect(fieldParameter.identifier, isNotNull); |
| - expect(fieldParameter.parameters, isNull); |
| + expect(expression, new isInstanceOf<PropertyAccess>()); |
| + PropertyAccess section = expression; |
| + expect(section.target, isNull); |
| + expect(section.operator, isNotNull); |
| + expect(section.propertyName, isNotNull); |
| } |
| - void test_parseNormalFormalParameter_field_const_type() { |
| - NormalFormalParameter parameter = |
| - parseNormalFormalParameter('const A this.a'); |
| - expect(parameter, isNotNull); |
| + void test_parseCascadeSection_pa() { |
| + createParser('..a(b)'); |
| + Expression expression = parser.parseCascadeSection(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<FieldFormalParameter>()); |
| - FieldFormalParameter fieldParameter = parameter; |
| - expect(fieldParameter.keyword, isNotNull); |
| - expect(fieldParameter.type, isNotNull); |
| - expect(fieldParameter.identifier, isNotNull); |
| - expect(fieldParameter.parameters, isNull); |
| + expect(expression, new isInstanceOf<MethodInvocation>()); |
| + MethodInvocation section = expression; |
| + expect(section.target, isNull); |
| + expect(section.operator, isNotNull); |
| + expect(section.methodName, isNotNull); |
| + expect(section.typeArguments, isNull); |
| + expect(section.argumentList, isNotNull); |
| + expect(section.argumentList.arguments, hasLength(1)); |
| } |
| - void test_parseNormalFormalParameter_field_final_noType() { |
| - NormalFormalParameter parameter = |
| - parseNormalFormalParameter('final this.a'); |
| - expect(parameter, isNotNull); |
| + void test_parseCascadeSection_pa_typeArgumentComments() { |
| + enableGenericMethodComments = true; |
| + createParser('..a/*<E>*/(b)'); |
| + Expression expression = parser.parseCascadeSection(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<FieldFormalParameter>()); |
| - FieldFormalParameter fieldParameter = parameter; |
| - expect(fieldParameter.keyword, isNotNull); |
| - expect(fieldParameter.type, isNull); |
| - expect(fieldParameter.identifier, isNotNull); |
| - expect(fieldParameter.parameters, isNull); |
| + expect(expression, new isInstanceOf<MethodInvocation>()); |
| + MethodInvocation section = expression; |
| + expect(section.target, isNull); |
| + expect(section.operator, isNotNull); |
| + expect(section.methodName, isNotNull); |
| + expect(section.typeArguments, isNotNull); |
| + expect(section.argumentList, isNotNull); |
| + expect(section.argumentList.arguments, hasLength(1)); |
| } |
| - void test_parseNormalFormalParameter_field_final_type() { |
| - NormalFormalParameter parameter = |
| - parseNormalFormalParameter('final A this.a'); |
| - expect(parameter, isNotNull); |
| + void test_parseCascadeSection_pa_typeArguments() { |
| + createParser('..a<E>(b)'); |
| + Expression expression = parser.parseCascadeSection(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<FieldFormalParameter>()); |
| - FieldFormalParameter fieldParameter = parameter; |
| - expect(fieldParameter.keyword, isNotNull); |
| - expect(fieldParameter.type, isNotNull); |
| - expect(fieldParameter.identifier, isNotNull); |
| - expect(fieldParameter.parameters, isNull); |
| + expect(expression, new isInstanceOf<MethodInvocation>()); |
| + MethodInvocation section = expression; |
| + expect(section.target, isNull); |
| + expect(section.operator, isNotNull); |
| + expect(section.methodName, isNotNull); |
| + expect(section.typeArguments, isNotNull); |
| + expect(section.argumentList, isNotNull); |
| + expect(section.argumentList.arguments, hasLength(1)); |
| } |
| - void test_parseNormalFormalParameter_field_function_nested() { |
| - NormalFormalParameter parameter = parseNormalFormalParameter('this.a(B b)'); |
| - expect(parameter, isNotNull); |
| + void test_parseCascadeSection_paa() { |
| + createParser('..a(b)(c)'); |
| + Expression expression = parser.parseCascadeSection(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<FieldFormalParameter>()); |
| - FieldFormalParameter fieldParameter = parameter; |
| - expect(fieldParameter.keyword, isNull); |
| - expect(fieldParameter.type, isNull); |
| - expect(fieldParameter.identifier, isNotNull); |
| - FormalParameterList parameterList = fieldParameter.parameters; |
| - expect(parameterList, isNotNull); |
| - expect(parameterList.parameters, hasLength(1)); |
| + expect(expression, new isInstanceOf<FunctionExpressionInvocation>()); |
| + FunctionExpressionInvocation section = expression; |
| + expect(section.function, new isInstanceOf<MethodInvocation>()); |
| + expect(section.typeArguments, isNull); |
| + expect(section.argumentList, isNotNull); |
| + expect(section.argumentList.arguments, hasLength(1)); |
| } |
| - void test_parseNormalFormalParameter_field_function_noNested() { |
| - NormalFormalParameter parameter = parseNormalFormalParameter('this.a()'); |
| - expect(parameter, isNotNull); |
| + void test_parseCascadeSection_paa_typeArgumentComments() { |
| + enableGenericMethodComments = true; |
| + createParser('..a/*<E>*/(b)/*<F>*/(c)'); |
| + Expression expression = parser.parseCascadeSection(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<FieldFormalParameter>()); |
| - FieldFormalParameter fieldParameter = parameter; |
| - expect(fieldParameter.keyword, isNull); |
| - expect(fieldParameter.type, isNull); |
| - expect(fieldParameter.identifier, isNotNull); |
| - FormalParameterList parameterList = fieldParameter.parameters; |
| - expect(parameterList, isNotNull); |
| - expect(parameterList.parameters, hasLength(0)); |
| + expect(expression, new isInstanceOf<FunctionExpressionInvocation>()); |
| + FunctionExpressionInvocation section = expression; |
| + expect(section.function, new isInstanceOf<MethodInvocation>()); |
| + expect(section.typeArguments, isNotNull); |
| + expect(section.argumentList, isNotNull); |
| + expect(section.argumentList.arguments, hasLength(1)); |
| } |
| - void test_parseNormalFormalParameter_field_noType() { |
| - NormalFormalParameter parameter = parseNormalFormalParameter('this.a'); |
| - expect(parameter, isNotNull); |
| + void test_parseCascadeSection_paa_typeArguments() { |
| + createParser('..a<E>(b)<F>(c)'); |
| + Expression expression = parser.parseCascadeSection(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<FieldFormalParameter>()); |
| - FieldFormalParameter fieldParameter = parameter; |
| - expect(fieldParameter.keyword, isNull); |
| - expect(fieldParameter.type, isNull); |
| - expect(fieldParameter.identifier, isNotNull); |
| - expect(fieldParameter.parameters, isNull); |
| + expect(expression, new isInstanceOf<FunctionExpressionInvocation>()); |
| + FunctionExpressionInvocation section = expression; |
| + expect(section.function, new isInstanceOf<MethodInvocation>()); |
| + expect(section.typeArguments, isNotNull); |
| + expect(section.argumentList, isNotNull); |
| + expect(section.argumentList.arguments, hasLength(1)); |
| } |
| - void test_parseNormalFormalParameter_field_type() { |
| - NormalFormalParameter parameter = parseNormalFormalParameter('A this.a'); |
| - expect(parameter, isNotNull); |
| + void test_parseCascadeSection_paapaa() { |
| + createParser('..a(b)(c).d(e)(f)'); |
| + Expression expression = parser.parseCascadeSection(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<FieldFormalParameter>()); |
| - FieldFormalParameter fieldParameter = parameter; |
| - expect(fieldParameter.keyword, isNull); |
| - expect(fieldParameter.type, isNotNull); |
| - expect(fieldParameter.identifier, isNotNull); |
| - expect(fieldParameter.parameters, isNull); |
| + expect(expression, new isInstanceOf<FunctionExpressionInvocation>()); |
| + FunctionExpressionInvocation section = expression; |
| + expect(section.function, new isInstanceOf<MethodInvocation>()); |
| + expect(section.typeArguments, isNull); |
| + expect(section.argumentList, isNotNull); |
| + expect(section.argumentList.arguments, hasLength(1)); |
| } |
| - void test_parseNormalFormalParameter_field_var() { |
| - NormalFormalParameter parameter = parseNormalFormalParameter('var this.a'); |
| - expect(parameter, isNotNull); |
| + void test_parseCascadeSection_paapaa_typeArgumentComments() { |
| + enableGenericMethodComments = true; |
| + createParser('..a/*<E>*/(b)/*<F>*/(c).d/*<G>*/(e)/*<H>*/(f)'); |
| + Expression expression = parser.parseCascadeSection(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<FieldFormalParameter>()); |
| - FieldFormalParameter fieldParameter = parameter; |
| - expect(fieldParameter.keyword, isNotNull); |
| - expect(fieldParameter.type, isNull); |
| - expect(fieldParameter.identifier, isNotNull); |
| - expect(fieldParameter.parameters, isNull); |
| + expect(expression, new isInstanceOf<FunctionExpressionInvocation>()); |
| + FunctionExpressionInvocation section = expression; |
| + expect(section.function, new isInstanceOf<MethodInvocation>()); |
| + expect(section.typeArguments, isNotNull); |
| + expect(section.argumentList, isNotNull); |
| + expect(section.argumentList.arguments, hasLength(1)); |
| } |
| - void test_parseNormalFormalParameter_function_noType() { |
| - NormalFormalParameter parameter = parseNormalFormalParameter('a()'); |
| - expect(parameter, isNotNull); |
| + void test_parseCascadeSection_paapaa_typeArguments() { |
| + createParser('..a<E>(b)<F>(c).d<G>(e)<H>(f)'); |
| + Expression expression = parser.parseCascadeSection(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| - FunctionTypedFormalParameter functionParameter = parameter; |
| - expect(functionParameter.returnType, isNull); |
| - expect(functionParameter.identifier, isNotNull); |
| - expect(functionParameter.typeParameters, isNull); |
| - expect(functionParameter.parameters, isNotNull); |
| + expect(expression, new isInstanceOf<FunctionExpressionInvocation>()); |
| + FunctionExpressionInvocation section = expression; |
| + expect(section.function, new isInstanceOf<MethodInvocation>()); |
| + expect(section.typeArguments, isNotNull); |
| + expect(section.argumentList, isNotNull); |
| + expect(section.argumentList.arguments, hasLength(1)); |
| } |
| - void test_parseNormalFormalParameter_function_noType_nullable() { |
| - enableNnbd = true; |
| - NormalFormalParameter parameter = parseNormalFormalParameter('a()?'); |
| - expect(parameter, isNotNull); |
| + void test_parseCascadeSection_pap() { |
| + createParser('..a(b).c'); |
| + Expression expression = parser.parseCascadeSection(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| - FunctionTypedFormalParameter functionParameter = parameter; |
| - expect(functionParameter.returnType, isNull); |
| - expect(functionParameter.identifier, isNotNull); |
| - expect(functionParameter.typeParameters, isNull); |
| - expect(functionParameter.parameters, isNotNull); |
| - expect(functionParameter.question, isNotNull); |
| + expect(expression, new isInstanceOf<PropertyAccess>()); |
| + PropertyAccess section = expression; |
| + expect(section.target, isNotNull); |
| + expect(section.operator, isNotNull); |
| + expect(section.propertyName, isNotNull); |
| } |
| - void test_parseNormalFormalParameter_function_noType_typeParameterComments() { |
| + void test_parseCascadeSection_pap_typeArgumentComments() { |
| enableGenericMethodComments = true; |
| - NormalFormalParameter parameter = parseNormalFormalParameter('a/*<E>*/()'); |
| - expect(parameter, isNotNull); |
| + createParser('..a/*<E>*/(b).c'); |
| + Expression expression = parser.parseCascadeSection(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| - FunctionTypedFormalParameter functionParameter = parameter; |
| - expect(functionParameter.returnType, isNull); |
| - expect(functionParameter.identifier, isNotNull); |
| - expect(functionParameter.typeParameters, isNotNull); |
| - expect(functionParameter.parameters, isNotNull); |
| + expect(expression, new isInstanceOf<PropertyAccess>()); |
| + PropertyAccess section = expression; |
| + expect(section.target, isNotNull); |
| + expect(section.operator, isNotNull); |
| + expect(section.propertyName, isNotNull); |
| } |
| - void test_parseNormalFormalParameter_function_noType_typeParameters() { |
| - NormalFormalParameter parameter = parseNormalFormalParameter('a<E>()'); |
| - expect(parameter, isNotNull); |
| + void test_parseCascadeSection_pap_typeArguments() { |
| + createParser('..a<E>(b).c'); |
| + Expression expression = parser.parseCascadeSection(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| - FunctionTypedFormalParameter functionParameter = parameter; |
| - expect(functionParameter.returnType, isNull); |
| - expect(functionParameter.identifier, isNotNull); |
| - expect(functionParameter.typeParameters, isNotNull); |
| - expect(functionParameter.parameters, isNotNull); |
| - expect(functionParameter.question, isNull); |
| - expect(functionParameter.question, isNull); |
| + expect(expression, new isInstanceOf<PropertyAccess>()); |
| + PropertyAccess section = expression; |
| + expect(section.target, isNotNull); |
| + expect(section.operator, isNotNull); |
| + expect(section.propertyName, isNotNull); |
| } |
| - void |
| - test_parseNormalFormalParameter_function_noType_typeParameters_nullable() { |
| - enableNnbd = true; |
| - NormalFormalParameter parameter = parseNormalFormalParameter('a<E>()?'); |
| - expect(parameter, isNotNull); |
| + void test_parseConditionalExpression() { |
| + createParser('x ? y : z'); |
| + ConditionalExpression expression = parser.parseConditionalExpression(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| - FunctionTypedFormalParameter functionParameter = parameter; |
| - expect(functionParameter.returnType, isNull); |
| - expect(functionParameter.identifier, isNotNull); |
| - expect(functionParameter.typeParameters, isNotNull); |
| - expect(functionParameter.parameters, isNotNull); |
| - expect(functionParameter.question, isNotNull); |
| + expect(expression.condition, isNotNull); |
| + expect(expression.question, isNotNull); |
| + expect(expression.thenExpression, isNotNull); |
| + expect(expression.colon, isNotNull); |
| + expect(expression.elseExpression, isNotNull); |
| } |
| - void test_parseNormalFormalParameter_function_type() { |
| - NormalFormalParameter parameter = parseNormalFormalParameter('A a()'); |
| - expect(parameter, isNotNull); |
| + void test_parseConstExpression_instanceCreation() { |
| + createParser('const A()'); |
| + Expression expression = parser.parseConstExpression(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| - FunctionTypedFormalParameter functionParameter = parameter; |
| - expect(functionParameter.returnType, isNotNull); |
| - expect(functionParameter.identifier, isNotNull); |
| - expect(functionParameter.typeParameters, isNull); |
| - expect(functionParameter.parameters, isNotNull); |
| - expect(functionParameter.question, isNull); |
| + expect(expression, new isInstanceOf<InstanceCreationExpression>()); |
| + InstanceCreationExpression instanceCreation = expression; |
| + expect(instanceCreation.keyword, isNotNull); |
| + ConstructorName name = instanceCreation.constructorName; |
| + expect(name, isNotNull); |
| + expect(name.type, isNotNull); |
| + expect(name.period, isNull); |
| + expect(name.name, isNull); |
| + expect(instanceCreation.argumentList, isNotNull); |
| } |
| - void test_parseNormalFormalParameter_function_type_nullable() { |
| - enableNnbd = true; |
| - NormalFormalParameter parameter = parseNormalFormalParameter('A a()?'); |
| - expect(parameter, isNotNull); |
| + void test_parseConstExpression_listLiteral_typed() { |
| + createParser('const <A> []'); |
| + Expression expression = parser.parseConstExpression(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| - FunctionTypedFormalParameter functionParameter = parameter; |
| - expect(functionParameter.returnType, isNotNull); |
| - expect(functionParameter.identifier, isNotNull); |
| - expect(functionParameter.typeParameters, isNull); |
| - expect(functionParameter.parameters, isNotNull); |
| - expect(functionParameter.question, isNotNull); |
| + expect(expression, new isInstanceOf<ListLiteral>()); |
| + ListLiteral literal = expression; |
| + expect(literal.constKeyword, isNotNull); |
| + expect(literal.typeArguments, isNotNull); |
| + expect(literal.leftBracket, isNotNull); |
| + expect(literal.elements, hasLength(0)); |
| + expect(literal.rightBracket, isNotNull); |
| } |
| - void test_parseNormalFormalParameter_function_type_typeParameterComments() { |
| + void test_parseConstExpression_listLiteral_typed_genericComment() { |
| enableGenericMethodComments = true; |
| - NormalFormalParameter parameter = |
| - parseNormalFormalParameter('A a/*<E>*/()'); |
| - expect(parameter, isNotNull); |
| + createParser('const /*<A>*/ []'); |
| + Expression expression = parser.parseConstExpression(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| - FunctionTypedFormalParameter functionParameter = parameter; |
| - expect(functionParameter.returnType, isNotNull); |
| - expect(functionParameter.identifier, isNotNull); |
| - expect(functionParameter.typeParameters, isNotNull); |
| - expect(functionParameter.parameters, isNotNull); |
| - expect(functionParameter.question, isNull); |
| + expect(expression, new isInstanceOf<ListLiteral>()); |
| + ListLiteral literal = expression; |
| + expect(literal.constKeyword, isNotNull); |
| + expect(literal.typeArguments, isNotNull); |
| + expect(literal.leftBracket, isNotNull); |
| + expect(literal.elements, hasLength(0)); |
| + expect(literal.rightBracket, isNotNull); |
| } |
| - void test_parseNormalFormalParameter_function_type_typeParameters() { |
| - NormalFormalParameter parameter = parseNormalFormalParameter('A a<E>()'); |
| - expect(parameter, isNotNull); |
| + void test_parseConstExpression_listLiteral_untyped() { |
| + createParser('const []'); |
| + Expression expression = parser.parseConstExpression(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| - FunctionTypedFormalParameter functionParameter = parameter; |
| - expect(functionParameter.returnType, isNotNull); |
| - expect(functionParameter.identifier, isNotNull); |
| - expect(functionParameter.typeParameters, isNotNull); |
| - expect(functionParameter.parameters, isNotNull); |
| - expect(functionParameter.question, isNull); |
| + expect(expression, new isInstanceOf<ListLiteral>()); |
| + ListLiteral literal = expression; |
| + expect(literal.constKeyword, isNotNull); |
| + expect(literal.typeArguments, isNull); |
| + expect(literal.leftBracket, isNotNull); |
| + expect(literal.elements, hasLength(0)); |
| + expect(literal.rightBracket, isNotNull); |
| } |
| - void test_parseNormalFormalParameter_function_type_typeParameters_nullable() { |
| - enableNnbd = true; |
| - NormalFormalParameter parameter = parseNormalFormalParameter('A a<E>()?'); |
| - expect(parameter, isNotNull); |
| + void test_parseConstExpression_mapLiteral_typed() { |
| + createParser('const <A, B> {}'); |
| + Expression expression = parser.parseConstExpression(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| - FunctionTypedFormalParameter functionParameter = parameter; |
| - expect(functionParameter.returnType, isNotNull); |
| - expect(functionParameter.identifier, isNotNull); |
| - expect(functionParameter.typeParameters, isNotNull); |
| - expect(functionParameter.parameters, isNotNull); |
| - expect(functionParameter.question, isNotNull); |
| + expect(expression, new isInstanceOf<MapLiteral>()); |
| + MapLiteral literal = expression; |
| + expect(literal.leftBracket, isNotNull); |
| + expect(literal.entries, hasLength(0)); |
| + expect(literal.rightBracket, isNotNull); |
| + expect(literal.typeArguments, isNotNull); |
| } |
| - void test_parseNormalFormalParameter_function_void() { |
| - NormalFormalParameter parameter = parseNormalFormalParameter('void a()'); |
| - expect(parameter, isNotNull); |
| + void test_parseConstExpression_mapLiteral_typed_genericComment() { |
| + enableGenericMethodComments = true; |
| + createParser('const /*<A, B>*/ {}'); |
| + Expression expression = parser.parseConstExpression(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| - FunctionTypedFormalParameter functionParameter = parameter; |
| - expect(functionParameter.returnType, isNotNull); |
| - expect(functionParameter.identifier, isNotNull); |
| - expect(functionParameter.typeParameters, isNull); |
| - expect(functionParameter.parameters, isNotNull); |
| - expect(functionParameter.question, isNull); |
| + expect(expression, new isInstanceOf<MapLiteral>()); |
| + MapLiteral literal = expression; |
| + expect(literal.leftBracket, isNotNull); |
| + expect(literal.entries, hasLength(0)); |
| + expect(literal.rightBracket, isNotNull); |
| + expect(literal.typeArguments, isNotNull); |
| } |
| - void test_parseNormalFormalParameter_function_void_nullable() { |
| - enableNnbd = true; |
| - NormalFormalParameter parameter = parseNormalFormalParameter('void a()?'); |
| - expect(parameter, isNotNull); |
| + void test_parseConstExpression_mapLiteral_untyped() { |
| + createParser('const {}'); |
| + Expression expression = parser.parseConstExpression(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| - FunctionTypedFormalParameter functionParameter = parameter; |
| - expect(functionParameter.returnType, isNotNull); |
| - expect(functionParameter.identifier, isNotNull); |
| - expect(functionParameter.typeParameters, isNull); |
| - expect(functionParameter.parameters, isNotNull); |
| - expect(functionParameter.question, isNotNull); |
| + expect(expression, new isInstanceOf<MapLiteral>()); |
| + MapLiteral literal = expression; |
| + expect(literal.leftBracket, isNotNull); |
| + expect(literal.entries, hasLength(0)); |
| + expect(literal.rightBracket, isNotNull); |
| + expect(literal.typeArguments, isNull); |
| } |
| - void test_parseNormalFormalParameter_function_void_typeParameterComments() { |
| - enableGenericMethodComments = true; |
| - NormalFormalParameter parameter = |
| - parseNormalFormalParameter('void a/*<E>*/()'); |
| - expect(parameter, isNotNull); |
| + void test_parseEqualityExpression_normal() { |
| + createParser('x == y'); |
| + BinaryExpression expression = parser.parseEqualityExpression(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| - FunctionTypedFormalParameter functionParameter = parameter; |
| - expect(functionParameter.returnType, isNotNull); |
| - expect(functionParameter.identifier, isNotNull); |
| - expect(functionParameter.typeParameters, isNotNull); |
| - expect(functionParameter.parameters, isNotNull); |
| - expect(functionParameter.question, isNull); |
| + expect(expression.leftOperand, isNotNull); |
| + expect(expression.operator, isNotNull); |
| + expect(expression.operator.type, TokenType.EQ_EQ); |
| + expect(expression.rightOperand, isNotNull); |
| } |
| - void test_parseNormalFormalParameter_function_void_typeParameters() { |
| - NormalFormalParameter parameter = parseNormalFormalParameter('void a<E>()'); |
| - expect(parameter, isNotNull); |
| + void test_parseEqualityExpression_super() { |
| + createParser('super == y'); |
| + BinaryExpression expression = parser.parseEqualityExpression(); |
| + expect(expression, isNotNull); |
| assertNoErrors(); |
| - expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| - FunctionTypedFormalParameter functionParameter = parameter; |
| - expect(functionParameter.returnType, isNotNull); |
| - expect(functionParameter.identifier, isNotNull); |
| - expect(functionParameter.typeParameters, isNotNull); |
| - expect(functionParameter.parameters, isNotNull); |
| - expect(functionParameter.question, isNull); |
| + expect(expression.leftOperand, new isInstanceOf<SuperExpression>()); |
| + expect(expression.operator, isNotNull); |
| + expect(expression.operator.type, TokenType.EQ_EQ); |
| + expect(expression.rightOperand, isNotNull); |
| } |
| - void test_parseNormalFormalParameter_function_void_typeParameters_nullable() { |
| - enableNnbd = true; |
| - NormalFormalParameter parameter = |
| - parseNormalFormalParameter('void a<E>()?'); |
| - expect(parameter, isNotNull); |
| - assertNoErrors(); |
| - expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| - FunctionTypedFormalParameter functionParameter = parameter; |
| - expect(functionParameter.returnType, isNotNull); |
| - expect(functionParameter.identifier, isNotNull); |
| - expect(functionParameter.typeParameters, isNotNull); |
| - expect(functionParameter.parameters, isNotNull); |
| - expect(functionParameter.question, isNotNull); |
| + void test_parseExpression_assign() { |
| + // TODO(brianwilkerson) Implement more tests for this method. |
| + Expression expression = parseExpression('x = y'); |
| + expect(expression, new isInstanceOf<AssignmentExpression>()); |
| + AssignmentExpression assignmentExpression = expression; |
| + expect(assignmentExpression.leftHandSide, isNotNull); |
| + expect(assignmentExpression.operator, isNotNull); |
| + expect(assignmentExpression.operator.type, TokenType.EQ); |
| + expect(assignmentExpression.rightHandSide, isNotNull); |
| } |
| - void test_parseNormalFormalParameter_simple_const_noType() { |
| - NormalFormalParameter parameter = parseNormalFormalParameter('const a'); |
| - expect(parameter, isNotNull); |
| - assertNoErrors(); |
| - expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| - SimpleFormalParameter simpleParameter = parameter; |
| - expect(simpleParameter.keyword, isNotNull); |
| - expect(simpleParameter.type, isNull); |
| - expect(simpleParameter.identifier, isNotNull); |
| + void test_parseExpression_assign_compound() { |
| + enableLazyAssignmentOperators = true; |
| + Expression expression = parseExpression('x ||= y'); |
| + expect(expression, new isInstanceOf<AssignmentExpression>()); |
| + AssignmentExpression assignmentExpression = expression; |
| + expect(assignmentExpression.leftHandSide, isNotNull); |
| + expect(assignmentExpression.operator, isNotNull); |
| + expect(assignmentExpression.operator.type, TokenType.BAR_BAR_EQ); |
| + expect(assignmentExpression.rightHandSide, isNotNull); |
| } |
| - void test_parseNormalFormalParameter_simple_const_type() { |
| - NormalFormalParameter parameter = parseNormalFormalParameter('const A a'); |
| - expect(parameter, isNotNull); |
| - assertNoErrors(); |
| - expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| - SimpleFormalParameter simpleParameter = parameter; |
| - expect(simpleParameter.keyword, isNotNull); |
| - expect(simpleParameter.type, isNotNull); |
| - expect(simpleParameter.identifier, isNotNull); |
| + void test_parseExpression_comparison() { |
| + Expression expression = parseExpression('--a.b == c'); |
| + expect(expression, new isInstanceOf<BinaryExpression>()); |
| + BinaryExpression binaryExpression = expression; |
| + expect(binaryExpression.leftOperand, isNotNull); |
| + expect(binaryExpression.operator, isNotNull); |
| + expect(binaryExpression.operator.type, TokenType.EQ_EQ); |
| + expect(binaryExpression.rightOperand, isNotNull); |
| } |
| - void test_parseNormalFormalParameter_simple_final_noType() { |
| - NormalFormalParameter parameter = parseNormalFormalParameter('final a'); |
| - expect(parameter, isNotNull); |
| - assertNoErrors(); |
| - expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| - SimpleFormalParameter simpleParameter = parameter; |
| - expect(simpleParameter.keyword, isNotNull); |
| - expect(simpleParameter.type, isNull); |
| - expect(simpleParameter.identifier, isNotNull); |
| + void test_parseExpression_function_async() { |
| + Expression expression = parseExpression('() async {}'); |
| + expect(expression, new isInstanceOf<FunctionExpression>()); |
| + FunctionExpression functionExpression = expression; |
| + expect(functionExpression.body, isNotNull); |
| + expect(functionExpression.body.isAsynchronous, isTrue); |
| + expect(functionExpression.body.isGenerator, isFalse); |
| + expect(functionExpression.parameters, isNotNull); |
| } |
| - void test_parseNormalFormalParameter_simple_final_type() { |
| - NormalFormalParameter parameter = parseNormalFormalParameter('final A a'); |
| - expect(parameter, isNotNull); |
| - assertNoErrors(); |
| - expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| - SimpleFormalParameter simpleParameter = parameter; |
| - expect(simpleParameter.keyword, isNotNull); |
| - expect(simpleParameter.type, isNotNull); |
| - expect(simpleParameter.identifier, isNotNull); |
| + void test_parseExpression_function_asyncStar() { |
| + Expression expression = parseExpression('() async* {}'); |
| + expect(expression, new isInstanceOf<FunctionExpression>()); |
| + FunctionExpression functionExpression = expression; |
| + expect(functionExpression.body, isNotNull); |
| + expect(functionExpression.body.isAsynchronous, isTrue); |
| + expect(functionExpression.body.isGenerator, isTrue); |
| + expect(functionExpression.parameters, isNotNull); |
| } |
| - void test_parseNormalFormalParameter_simple_noName() { |
| - NormalFormalParameter parameter = |
| - parseNormalFormalParameter('a', inFunctionType: true); |
| - expect(parameter, isNotNull); |
| - assertNoErrors(); |
| - expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| - SimpleFormalParameter simpleParameter = parameter; |
| - expect(simpleParameter.keyword, isNull); |
| - expect(simpleParameter.type, isNotNull); |
| - expect(simpleParameter.identifier, isNull); |
| + void test_parseExpression_function_sync() { |
| + Expression expression = parseExpression('() {}'); |
| + expect(expression, new isInstanceOf<FunctionExpression>()); |
| + FunctionExpression functionExpression = expression; |
| + expect(functionExpression.body, isNotNull); |
| + expect(functionExpression.body.isAsynchronous, isFalse); |
| + expect(functionExpression.body.isGenerator, isFalse); |
| + expect(functionExpression.parameters, isNotNull); |
| } |
| - void test_parseNormalFormalParameter_simple_noType() { |
| - NormalFormalParameter parameter = parseNormalFormalParameter('a'); |
| - expect(parameter, isNotNull); |
| - assertNoErrors(); |
| - expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| - SimpleFormalParameter simpleParameter = parameter; |
| - expect(simpleParameter.keyword, isNull); |
| - expect(simpleParameter.type, isNull); |
| - expect(simpleParameter.identifier, isNotNull); |
| + void test_parseExpression_function_syncStar() { |
| + Expression expression = parseExpression('() sync* {}'); |
| + expect(expression, new isInstanceOf<FunctionExpression>()); |
| + FunctionExpression functionExpression = expression; |
| + expect(functionExpression.body, isNotNull); |
| + expect(functionExpression.body.isAsynchronous, isFalse); |
| + expect(functionExpression.body.isGenerator, isTrue); |
| + expect(functionExpression.parameters, isNotNull); |
| } |
| - void test_parseNormalFormalParameter_simple_noType_namedCovariant() { |
| - NormalFormalParameter parameter = parseNormalFormalParameter('covariant'); |
| - expect(parameter, isNotNull); |
| - assertNoErrors(); |
| - expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| - SimpleFormalParameter simpleParameter = parameter; |
| - expect(simpleParameter.covariantKeyword, isNull); |
| - expect(simpleParameter.keyword, isNull); |
| - expect(simpleParameter.type, isNull); |
| - expect(simpleParameter.identifier, isNotNull); |
| + void test_parseExpression_invokeFunctionExpression() { |
| + Expression expression = parseExpression('(a) {return a + a;} (3)'); |
| + expect(expression, new isInstanceOf<FunctionExpressionInvocation>()); |
| + FunctionExpressionInvocation invocation = expression; |
| + expect(invocation.function, new isInstanceOf<FunctionExpression>()); |
| + FunctionExpression functionExpression = |
| + invocation.function as FunctionExpression; |
| + expect(functionExpression.parameters, isNotNull); |
| + expect(functionExpression.body, isNotNull); |
| + expect(invocation.typeArguments, isNull); |
| + ArgumentList list = invocation.argumentList; |
| + expect(list, isNotNull); |
| + expect(list.arguments, hasLength(1)); |
| } |
| - void test_parseNormalFormalParameter_simple_type() { |
| - NormalFormalParameter parameter = parseNormalFormalParameter('A a'); |
| - expect(parameter, isNotNull); |
| - assertNoErrors(); |
| - expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| - SimpleFormalParameter simpleParameter = parameter; |
| - expect(simpleParameter.keyword, isNull); |
| - expect(simpleParameter.type, isNotNull); |
| - expect(simpleParameter.identifier, isNotNull); |
| + void test_parseExpression_nonAwait() { |
| + Expression expression = parseExpression('await()'); |
| + expect(expression, new isInstanceOf<MethodInvocation>()); |
| + MethodInvocation invocation = expression; |
| + expect(invocation.methodName.name, 'await'); |
| + expect(invocation.typeArguments, isNull); |
| + expect(invocation.argumentList, isNotNull); |
| } |
| -} |
| -@reflectiveTest |
| -class NonErrorParserTest extends ParserTestCase { |
| - void test_constFactory_external() { |
| - createParser('external const factory C();'); |
| - ClassMember member = parser.parseClassMember('C'); |
| - expectNotNullIfNoErrors(member); |
| - listener.assertNoErrors(); |
| + void test_parseExpression_superMethodInvocation() { |
| + Expression expression = parseExpression('super.m()'); |
| + expect(expression, new isInstanceOf<MethodInvocation>()); |
| + MethodInvocation invocation = expression; |
| + expect(invocation.target, isNotNull); |
| + expect(invocation.methodName, isNotNull); |
| + expect(invocation.typeArguments, isNull); |
| + expect(invocation.argumentList, isNotNull); |
| } |
| - void test_staticMethod_notParsingFunctionBodies() { |
| - ParserTestCase.parseFunctionBodies = false; |
| - try { |
| - createParser('class C { static void m() {} }'); |
| - CompilationUnit unit = parser.parseCompilationUnit2(); |
| - expectNotNullIfNoErrors(unit); |
| - listener.assertNoErrors(); |
| - } finally { |
| - ParserTestCase.parseFunctionBodies = true; |
| - } |
| + void test_parseExpression_superMethodInvocation_typeArgumentComments() { |
| + enableGenericMethodComments = true; |
| + Expression expression = parseExpression('super.m/*<E>*/()'); |
| + expect(expression, new isInstanceOf<MethodInvocation>()); |
| + MethodInvocation invocation = expression; |
| + expect(invocation.target, isNotNull); |
| + expect(invocation.methodName, isNotNull); |
| + expect(invocation.typeArguments, isNotNull); |
| + expect(invocation.argumentList, isNotNull); |
| } |
| -} |
| - |
| -/** |
| - * Implementation of [AbstractParserTestCase] specialized for testing the |
| - * analyzer parser. |
| - */ |
| -class ParserTestCase extends EngineTestCase |
| - with ParserTestHelpers |
| - implements AbstractParserTestCase { |
| - /** |
| - * A flag indicating whether parser is to parse function bodies. |
| - */ |
| - static bool parseFunctionBodies = true; |
| - |
| - /** |
| - * A flag indicating whether the parser is to parse asserts in the initializer |
| - * list of a constructor. |
| - */ |
| - bool enableAssertInitializer = false; |
| - |
| - /** |
| - * A flag indicating whether parser is to parse async. |
| - */ |
| - bool parseAsync = true; |
| - |
| - /** |
| - * Whether generic method comments should be enabled for the test. |
| - */ |
| - bool enableGenericMethodComments = false; |
| - /** |
| - * A flag indicating whether lazy assignment operators should be enabled for |
| - * the test. |
| - */ |
| - bool enableLazyAssignmentOperators = false; |
| + void test_parseExpression_superMethodInvocation_typeArguments() { |
| + Expression expression = parseExpression('super.m<E>()'); |
| + expect(expression, new isInstanceOf<MethodInvocation>()); |
| + MethodInvocation invocation = expression; |
| + expect(invocation.target, isNotNull); |
| + expect(invocation.methodName, isNotNull); |
| + expect(invocation.typeArguments, isNotNull); |
| + expect(invocation.argumentList, isNotNull); |
| + } |
| - /** |
| - * A flag indicating whether the parser is to parse the non-nullable modifier |
| - * in type names. |
| - */ |
| - bool enableNnbd = false; |
| + void test_parseExpressionList_multiple() { |
| + createParser('1, 2, 3'); |
| + List<Expression> result = parser.parseExpressionList(); |
| + expect(result, isNotNull); |
| + assertNoErrors(); |
| + expect(result, hasLength(3)); |
| + } |
| - /** |
| - * A flag indicating whether the parser is to parse part-of directives that |
| - * specify a URI rather than a library name. |
| - */ |
| - bool enableUriInPartOf = false; |
| + void test_parseExpressionList_single() { |
| + createParser('1'); |
| + List<Expression> result = parser.parseExpressionList(); |
| + expect(result, isNotNull); |
| + assertNoErrors(); |
| + expect(result, hasLength(1)); |
| + } |
| - /** |
| - * The error listener to which scanner and parser errors will be reported. |
| - * |
| - * This field is typically initialized by invoking [createParser]. |
| - */ |
| - GatheringErrorListener listener; |
| + void test_parseExpressionWithoutCascade_assign() { |
| + // TODO(brianwilkerson) Implement more tests for this method. |
| + createParser('x = y'); |
| + Expression expression = parser.parseExpressionWithoutCascade(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<AssignmentExpression>()); |
| + AssignmentExpression assignmentExpression = expression; |
| + expect(assignmentExpression.leftHandSide, isNotNull); |
| + expect(assignmentExpression.operator, isNotNull); |
| + expect(assignmentExpression.operator.type, TokenType.EQ); |
| + expect(assignmentExpression.rightHandSide, isNotNull); |
| + } |
| - /** |
| - * The parser used by the test. |
| - * |
| - * This field is typically initialized by invoking [createParser]. |
| - */ |
| - Parser parser; |
| + void test_parseExpressionWithoutCascade_comparison() { |
| + createParser('--a.b == c'); |
| + Expression expression = parser.parseExpressionWithoutCascade(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<BinaryExpression>()); |
| + BinaryExpression binaryExpression = expression; |
| + expect(binaryExpression.leftOperand, isNotNull); |
| + expect(binaryExpression.operator, isNotNull); |
| + expect(binaryExpression.operator.type, TokenType.EQ_EQ); |
| + expect(binaryExpression.rightOperand, isNotNull); |
| + } |
| - @override |
| - void assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) { |
| - listener.assertErrorsWithCodes(expectedErrorCodes); |
| + void test_parseExpressionWithoutCascade_superMethodInvocation() { |
| + createParser('super.m()'); |
| + Expression expression = parser.parseExpressionWithoutCascade(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<MethodInvocation>()); |
| + MethodInvocation invocation = expression; |
| + expect(invocation.target, isNotNull); |
| + expect(invocation.methodName, isNotNull); |
| + expect(invocation.typeArguments, isNull); |
| + expect(invocation.argumentList, isNotNull); |
| } |
| - @override |
| - void assertNoErrors() { |
| - listener.assertNoErrors(); |
| + void |
| + test_parseExpressionWithoutCascade_superMethodInvocation_typeArgumentComments() { |
| + enableGenericMethodComments = true; |
| + createParser('super.m/*<E>*/()'); |
| + Expression expression = parser.parseExpressionWithoutCascade(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<MethodInvocation>()); |
| + MethodInvocation invocation = expression; |
| + expect(invocation.target, isNotNull); |
| + expect(invocation.methodName, isNotNull); |
| + expect(invocation.typeArguments, isNotNull); |
| + expect(invocation.argumentList, isNotNull); |
| } |
| - /** |
| - * Create the [parser] and [listener] used by a test. The [parser] will be |
| - * prepared to parse the tokens scanned from the given [content]. |
| - */ |
| - void createParser(String content) { |
| - listener = new GatheringErrorListener(); |
| - // |
| - // Scan the source. |
| - // |
| - TestSource source = new TestSource(); |
| - CharacterReader reader = new CharSequenceReader(content); |
| - Scanner scanner = new Scanner(source, reader, listener); |
| - scanner.scanGenericMethodComments = enableGenericMethodComments; |
| - scanner.scanLazyAssignmentOperators = enableLazyAssignmentOperators; |
| - Token tokenStream = scanner.tokenize(); |
| - listener.setLineInfo(source, scanner.lineStarts); |
| - // |
| - // Create and initialize the parser. |
| - // |
| - parser = new Parser(source, listener); |
| - parser.enableAssertInitializer = enableAssertInitializer; |
| - parser.parseGenericMethodComments = enableGenericMethodComments; |
| - parser.parseFunctionBodies = parseFunctionBodies; |
| - parser.enableNnbd = enableNnbd; |
| - parser.enableUriInPartOf = enableUriInPartOf; |
| - parser.currentToken = tokenStream; |
| + void |
| + test_parseExpressionWithoutCascade_superMethodInvocation_typeArguments() { |
| + createParser('super.m<E>()'); |
| + Expression expression = parser.parseExpressionWithoutCascade(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<MethodInvocation>()); |
| + MethodInvocation invocation = expression; |
| + expect(invocation.target, isNotNull); |
| + expect(invocation.methodName, isNotNull); |
| + expect(invocation.typeArguments, isNotNull); |
| + expect(invocation.argumentList, isNotNull); |
| } |
| - void expectNotNullIfNoErrors(Object result) { |
| - if (!listener.hasErrors) { |
| - expect(result, isNotNull); |
| - } |
| + void test_parseFunctionExpression_body_inExpression() { |
| + createParser('(int i) => i++'); |
| + FunctionExpression expression = parser.parseFunctionExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression.body, isNotNull); |
| + expect(expression.typeParameters, isNull); |
| + expect(expression.parameters, isNotNull); |
| + expect((expression.body as ExpressionFunctionBody).semicolon, isNull); |
| } |
| - /** |
| - * Parse the given source as a compilation unit. |
| - * |
| - * @param source the source to be parsed |
| - * @param errorCodes the error codes of the errors that are expected to be found |
| - * @return the compilation unit that was parsed |
| - * @throws Exception if the source could not be parsed, if the compilation errors in the source do |
| - * not match those that are expected, or if the result would have been `null` |
| - */ |
| - CompilationUnit parseCompilationUnit(String source, |
| - [List<ErrorCode> errorCodes = const <ErrorCode>[]]) { |
| - GatheringErrorListener listener = new GatheringErrorListener(); |
| - Scanner scanner = |
| - new Scanner(null, new CharSequenceReader(source), listener); |
| - listener.setLineInfo(new TestSource(), scanner.lineStarts); |
| - Token token = scanner.tokenize(); |
| - Parser parser = new Parser(null, listener); |
| - CompilationUnit unit = parser.parseCompilationUnit(token); |
| - expect(unit, isNotNull); |
| - listener.assertErrorsWithCodes(errorCodes); |
| - return unit; |
| + void test_parseFunctionExpression_typeParameterComments() { |
| + enableGenericMethodComments = true; |
| + createParser('/*<E>*/(/*=E*/ i) => i++'); |
| + FunctionExpression expression = parser.parseFunctionExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression.body, isNotNull); |
| + expect(expression.typeParameters, isNotNull); |
| + expect(expression.parameters, isNotNull); |
| + expect((expression.body as ExpressionFunctionBody).semicolon, isNull); |
| + SimpleFormalParameter p = expression.parameters.parameters[0]; |
| + expect(p.type, isNotNull); |
| } |
| - /** |
| - * Parse the given [code] as a compilation unit. |
| - */ |
| - CompilationUnit parseCompilationUnit2(String code, |
| - {AnalysisErrorListener listener}) { |
| - listener ??= AnalysisErrorListener.NULL_LISTENER; |
| - Scanner scanner = new Scanner(null, new CharSequenceReader(code), listener); |
| - Token token = scanner.tokenize(); |
| - Parser parser = new Parser(null, listener); |
| - CompilationUnit unit = parser.parseCompilationUnit(token); |
| - unit.lineInfo = new LineInfo(scanner.lineStarts); |
| - return unit; |
| + void test_parseFunctionExpression_typeParameters() { |
| + createParser('<E>(E i) => i++'); |
| + FunctionExpression expression = parser.parseFunctionExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression.body, isNotNull); |
| + expect(expression.typeParameters, isNotNull); |
| + expect(expression.parameters, isNotNull); |
| + expect((expression.body as ExpressionFunctionBody).semicolon, isNull); |
| } |
| - /** |
| - * Parse the given [source] as a compilation unit. Throw an exception if the |
| - * source could not be parsed, if the compilation errors in the source do not |
| - * match those that are expected, or if the result would have been `null`. |
| - */ |
| - CompilationUnit parseCompilationUnitWithOptions(String source, |
| - [List<ErrorCode> errorCodes = const <ErrorCode>[]]) { |
| - createParser(source); |
| - CompilationUnit unit = parser.parseCompilationUnit2(); |
| - expect(unit, isNotNull); |
| - listener.assertErrorsWithCodes(errorCodes); |
| - return unit; |
| + void test_parseInstanceCreationExpression_qualifiedType() { |
| + Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| + createParser('A.B()'); |
| + InstanceCreationExpression expression = |
| + parser.parseInstanceCreationExpression(token); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression.keyword, token); |
| + ConstructorName name = expression.constructorName; |
| + expect(name, isNotNull); |
| + TypeName type = name.type; |
| + expect(type, isNotNull); |
| + expect(type.typeArguments, isNull); |
| + expect(name.period, isNull); |
| + expect(name.name, isNull); |
| + expect(expression.argumentList, isNotNull); |
| } |
| - @override |
| - CompilationUnit parseDirectives(String source, |
| - [List<ErrorCode> errorCodes = const <ErrorCode>[]]) { |
| - createParser(source); |
| - CompilationUnit unit = parser.parseDirectives2(); |
| - expect(unit, isNotNull); |
| - expect(unit.declarations, hasLength(0)); |
| - listener.assertErrorsWithCodes(errorCodes); |
| - return unit; |
| + void test_parseInstanceCreationExpression_qualifiedType_named() { |
| + Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| + createParser('A.B.c()'); |
| + InstanceCreationExpression expression = |
| + parser.parseInstanceCreationExpression(token); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression.keyword, token); |
| + ConstructorName name = expression.constructorName; |
| + expect(name, isNotNull); |
| + TypeName type = name.type; |
| + expect(type, isNotNull); |
| + expect(type.typeArguments, isNull); |
| + expect(name.period, isNotNull); |
| + expect(name.name, isNotNull); |
| + expect(expression.argumentList, isNotNull); |
| } |
| - /** |
| - * Parse the given source as an expression. |
| - * |
| - * @param source the source to be parsed |
| - * @param errorCodes the error codes of the errors that are expected to be found |
| - * @return the expression that was parsed |
| - * @throws Exception if the source could not be parsed, if the compilation errors in the source do |
| - * not match those that are expected, or if the result would have been `null` |
| - */ |
| - Expression parseExpression(String source, |
| - [List<ErrorCode> errorCodes = const <ErrorCode>[]]) { |
| - createParser(source); |
| - Expression expression = parser.parseExpression2(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertErrorsWithCodes(errorCodes); |
| - return expression; |
| + void |
| + test_parseInstanceCreationExpression_qualifiedType_named_typeParameterComment() { |
| + enableGenericMethodComments = true; |
| + Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| + createParser('A.B/*<E>*/.c()'); |
| + InstanceCreationExpression expression = |
| + parser.parseInstanceCreationExpression(token); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression.keyword, token); |
| + ConstructorName name = expression.constructorName; |
| + expect(name, isNotNull); |
| + TypeName type = name.type; |
| + expect(type, isNotNull); |
| + expect(type.typeArguments.arguments, hasLength(1)); |
| + expect(name.period, isNotNull); |
| + expect(name.name, isNotNull); |
| + expect(expression.argumentList, isNotNull); |
| } |
| - @override |
| - FormalParameter parseFormalParameter(String code, ParameterKind kind, |
| - {List<ErrorCode> errorCodes: const <ErrorCode>[]}) { |
| - createParser(code); |
| - FormalParameter parameter = parser.parseFormalParameter(kind); |
| - assertErrorsWithCodes(errorCodes); |
| - return parameter; |
| + void |
| + test_parseInstanceCreationExpression_qualifiedType_named_typeParameters() { |
| + Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| + createParser('A.B<E>.c()'); |
| + InstanceCreationExpression expression = |
| + parser.parseInstanceCreationExpression(token); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression.keyword, token); |
| + ConstructorName name = expression.constructorName; |
| + expect(name, isNotNull); |
| + TypeName type = name.type; |
| + expect(type, isNotNull); |
| + expect(type.typeArguments.arguments, hasLength(1)); |
| + expect(name.period, isNotNull); |
| + expect(name.name, isNotNull); |
| + expect(expression.argumentList, isNotNull); |
| } |
| - @override |
| - FormalParameterList parseFormalParameterList(String code, |
| - {bool inFunctionType: false, |
| - List<ErrorCode> errorCodes: const <ErrorCode>[]}) { |
| - createParser(code); |
| - FormalParameterList list = |
| - parser.parseFormalParameterList(inFunctionType: inFunctionType); |
| - assertErrorsWithCodes(errorCodes); |
| - return list; |
| + void |
| + test_parseInstanceCreationExpression_qualifiedType_typeParameterComment() { |
| + enableGenericMethodComments = true; |
| + Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| + createParser('A.B/*<E>*/()'); |
| + InstanceCreationExpression expression = |
| + parser.parseInstanceCreationExpression(token); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression.keyword, token); |
| + ConstructorName name = expression.constructorName; |
| + expect(name, isNotNull); |
| + TypeName type = name.type; |
| + expect(type, isNotNull); |
| + expect(type.typeArguments.arguments, hasLength(1)); |
| + expect(name.period, isNull); |
| + expect(name.name, isNull); |
| + expect(expression.argumentList, isNotNull); |
| } |
| - /** |
| - * Parses a single top level member of a compilation unit (other than a |
| - * directive), including any comment and/or metadata that precedes it. |
| - */ |
| - CompilationUnitMember parseFullCompilationUnitMember() => |
| - parser.parseCompilationUnitMember(parser.parseCommentAndMetadata()); |
| + void test_parseInstanceCreationExpression_qualifiedType_typeParameters() { |
| + Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| + createParser('A.B<E>()'); |
| + InstanceCreationExpression expression = |
| + parser.parseInstanceCreationExpression(token); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression.keyword, token); |
| + ConstructorName name = expression.constructorName; |
| + expect(name, isNotNull); |
| + TypeName type = name.type; |
| + expect(type, isNotNull); |
| + expect(type.typeArguments.arguments, hasLength(1)); |
| + expect(name.period, isNull); |
| + expect(name.name, isNull); |
| + expect(expression.argumentList, isNotNull); |
| + } |
| - @override |
| - Directive parseFullDirective() => |
| - parser.parseDirective(parser.parseCommentAndMetadata()); |
| + void test_parseInstanceCreationExpression_type() { |
| + Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| + createParser('A()'); |
| + InstanceCreationExpression expression = |
| + parser.parseInstanceCreationExpression(token); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression.keyword, token); |
| + ConstructorName name = expression.constructorName; |
| + expect(name, isNotNull); |
| + TypeName type = name.type; |
| + expect(type, isNotNull); |
| + expect(type.typeArguments, isNull); |
| + expect(name.period, isNull); |
| + expect(name.name, isNull); |
| + expect(expression.argumentList, isNotNull); |
| + } |
| - /** |
| - * Parses a variable declaration list (equivalent to a variable declaration |
| - * statement, but without the final comma). |
| - */ |
| - VariableDeclarationList parseFullVariableDeclarationList() => |
| - parser.parseVariableDeclarationListAfterMetadata( |
| - parser.parseCommentAndMetadata()); |
| + void test_parseInstanceCreationExpression_type_named() { |
| + enableGenericMethodComments = true; |
| + Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| + createParser('A.c()'); |
| + InstanceCreationExpression expression = |
| + parser.parseInstanceCreationExpression(token); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression.keyword, token); |
| + ConstructorName name = expression.constructorName; |
| + expect(name, isNotNull); |
| + TypeName type = name.type; |
| + expect(type, isNotNull); |
| + expect(type.typeArguments, isNull); |
| + expect(name.period, isNull); |
| + expect(name.name, isNull); |
| + expect(expression.argumentList, isNotNull); |
| + } |
| - @override |
| - NormalFormalParameter parseNormalFormalParameter(String code, |
| - {bool inFunctionType: false, |
| - List<ErrorCode> errorCodes: const <ErrorCode>[]}) { |
| - createParser(code); |
| - FormalParameter parameter = |
| - parser.parseNormalFormalParameter(inFunctionType: inFunctionType); |
| - assertErrorsWithCodes(errorCodes); |
| - return parameter; |
| + void test_parseInstanceCreationExpression_type_named_typeParameterComment() { |
| + enableGenericMethodComments = true; |
| + Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| + createParser('A/*<B>*/.c()'); |
| + InstanceCreationExpression expression = |
| + parser.parseInstanceCreationExpression(token); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression.keyword, token); |
| + ConstructorName name = expression.constructorName; |
| + expect(name, isNotNull); |
| + TypeName type = name.type; |
| + expect(type, isNotNull); |
| + expect(type.typeArguments.arguments, hasLength(1)); |
| + expect(name.period, isNotNull); |
| + expect(name.name, isNotNull); |
| + expect(expression.argumentList, isNotNull); |
| } |
| - /** |
| - * Parse the given [source] as a statement. The [errorCodes] are the error |
| - * codes of the errors that are expected to be found. If |
| - * [enableLazyAssignmentOperators] is `true`, then lazy assignment operators |
| - * should be enabled. |
| - */ |
| - Statement parseStatement(String source, |
| - [List<ErrorCode> errorCodes = const <ErrorCode>[], |
| - bool enableLazyAssignmentOperators]) { |
| - GatheringErrorListener listener = new GatheringErrorListener(); |
| - Scanner scanner = |
| - new Scanner(null, new CharSequenceReader(source), listener); |
| - scanner.scanLazyAssignmentOperators = enableLazyAssignmentOperators; |
| - listener.setLineInfo(new TestSource(), scanner.lineStarts); |
| - Token token = scanner.tokenize(); |
| - Parser parser = new Parser(null, listener); |
| - Statement statement = parser.parseStatement(token); |
| - expect(statement, isNotNull); |
| - listener.assertErrorsWithCodes(errorCodes); |
| - return statement; |
| + void test_parseInstanceCreationExpression_type_named_typeParameters() { |
| + Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| + createParser('A<B>.c()'); |
| + InstanceCreationExpression expression = |
| + parser.parseInstanceCreationExpression(token); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression.keyword, token); |
| + ConstructorName name = expression.constructorName; |
| + expect(name, isNotNull); |
| + TypeName type = name.type; |
| + expect(type, isNotNull); |
| + expect(type.typeArguments.arguments, hasLength(1)); |
| + expect(name.period, isNotNull); |
| + expect(name.name, isNotNull); |
| + expect(expression.argumentList, isNotNull); |
| } |
| - /** |
| - * Parse the given source as a sequence of statements. |
| - * |
| - * @param source the source to be parsed |
| - * @param expectedCount the number of statements that are expected |
| - * @param errorCodes the error codes of the errors that are expected to be found |
| - * @return the statements that were parsed |
| - * @throws Exception if the source could not be parsed, if the number of statements does not match |
| - * the expected count, if the compilation errors in the source do not match those that |
| - * are expected, or if the result would have been `null` |
| - */ |
| - List<Statement> parseStatements(String source, int expectedCount, |
| - [List<ErrorCode> errorCodes = const <ErrorCode>[]]) { |
| - GatheringErrorListener listener = new GatheringErrorListener(); |
| - Scanner scanner = |
| - new Scanner(null, new CharSequenceReader(source), listener); |
| - listener.setLineInfo(new TestSource(), scanner.lineStarts); |
| - Token token = scanner.tokenize(); |
| - Parser parser = new Parser(null, listener); |
| - List<Statement> statements = parser.parseStatements(token); |
| - expect(statements, hasLength(expectedCount)); |
| - listener.assertErrorsWithCodes(errorCodes); |
| - return statements; |
| + void test_parseInstanceCreationExpression_type_typeParameterComment() { |
| + enableGenericMethodComments = true; |
| + Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| + createParser('A/*<B>*/()'); |
| + InstanceCreationExpression expression = |
| + parser.parseInstanceCreationExpression(token); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression.keyword, token); |
| + ConstructorName name = expression.constructorName; |
| + expect(name, isNotNull); |
| + TypeName type = name.type; |
| + expect(type, isNotNull); |
| + expect(type.typeArguments.arguments, hasLength(1)); |
| + expect(name.period, isNull); |
| + expect(name.name, isNull); |
| + expect(expression.argumentList, isNotNull); |
| } |
| - @override |
| - void setUp() { |
| - super.setUp(); |
| - parseFunctionBodies = true; |
| + void test_parseInstanceCreationExpression_type_typeParameters() { |
| + Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| + createParser('A<B>()'); |
| + InstanceCreationExpression expression = |
| + parser.parseInstanceCreationExpression(token); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression.keyword, token); |
| + ConstructorName name = expression.constructorName; |
| + expect(name, isNotNull); |
| + TypeName type = name.type; |
| + expect(type, isNotNull); |
| + expect(type.typeArguments.arguments, hasLength(1)); |
| + expect(name.period, isNull); |
| + expect(name.name, isNull); |
| + expect(expression.argumentList, isNotNull); |
| } |
| -} |
| -/** |
| - * Helper methods that aid in parser tests. |
| - * |
| - * Intended to be mixed in to parser test case classes. |
| - */ |
| -class ParserTestHelpers { |
| - void expectCommentText(Comment comment, String expectedText) { |
| - expect(comment.beginToken, same(comment.endToken)); |
| - expect(comment.beginToken.lexeme, expectedText); |
| + void test_parseInstanceCreationExpression_type_typeParameters_nullable() { |
| + enableNnbd = true; |
| + Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| + createParser('A<B?>()'); |
| + InstanceCreationExpression expression = |
| + parser.parseInstanceCreationExpression(token); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression.keyword, token); |
| + ConstructorName name = expression.constructorName; |
| + expect(name, isNotNull); |
| + TypeName type = name.type; |
| + expect(type, isNotNull); |
| + expect(name.period, isNull); |
| + expect(name.name, isNull); |
| + expect(expression.argumentList, isNotNull); |
| + NodeList<TypeAnnotation> arguments = type.typeArguments.arguments; |
| + expect(arguments, hasLength(1)); |
| + expect((arguments[0] as TypeName).question, isNotNull); |
| } |
| - void expectDottedName(DottedName name, List<String> expectedComponents) { |
| - int count = expectedComponents.length; |
| - NodeList<SimpleIdentifier> components = name.components; |
| - expect(components, hasLength(count)); |
| - for (int i = 0; i < count; i++) { |
| - SimpleIdentifier component = components[i]; |
| - expect(component, isNotNull); |
| - expect(component.name, expectedComponents[i]); |
| - } |
| + void test_parseListLiteral_empty_oneToken() { |
| + Token token = TokenFactory.tokenFromKeyword(Keyword.CONST); |
| + TypeArgumentList typeArguments = null; |
| + createParser('[]'); |
| + ListLiteral literal = parser.parseListLiteral(token, typeArguments); |
| + expect(literal, isNotNull); |
| + assertNoErrors(); |
| + expect(literal.constKeyword, token); |
| + expect(literal.typeArguments, typeArguments); |
| + expect(literal.leftBracket, isNotNull); |
| + expect(literal.elements, hasLength(0)); |
| + expect(literal.rightBracket, isNotNull); |
| } |
| -} |
| -/** |
| - * The class `RecoveryParserTest` defines parser tests that test the parsing of invalid code |
| - * sequences to ensure that the correct recovery steps are taken in the parser. |
| - */ |
| -@reflectiveTest |
| -class RecoveryParserTest extends ParserTestCase { |
| - void test_additiveExpression_missing_LHS() { |
| - BinaryExpression expression = |
| - parseExpression("+ y", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.leftOperand); |
| - expect(expression.leftOperand.isSynthetic, isTrue); |
| + void test_parseListLiteral_empty_oneToken_withComment() { |
| + Token token = null; |
| + TypeArgumentList typeArguments = null; |
| + createParser('/* 0 */ []'); |
| + ListLiteral literal = parser.parseListLiteral(token, typeArguments); |
| + expect(literal, isNotNull); |
| + assertNoErrors(); |
| + expect(literal.constKeyword, token); |
| + expect(literal.typeArguments, typeArguments); |
| + Token leftBracket = literal.leftBracket; |
| + expect(leftBracket, isNotNull); |
| + expect(leftBracket.precedingComments, isNotNull); |
| + expect(literal.elements, hasLength(0)); |
| + expect(literal.rightBracket, isNotNull); |
| } |
| - void test_additiveExpression_missing_LHS_RHS() { |
| - BinaryExpression expression = parseExpression("+", [ |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER |
| - ]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.leftOperand); |
| - expect(expression.leftOperand.isSynthetic, isTrue); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.rightOperand); |
| - expect(expression.rightOperand.isSynthetic, isTrue); |
| + void test_parseListLiteral_empty_twoTokens() { |
| + Token token = TokenFactory.tokenFromKeyword(Keyword.CONST); |
| + TypeArgumentList typeArguments = null; |
| + createParser('[ ]'); |
| + ListLiteral literal = parser.parseListLiteral(token, typeArguments); |
| + expect(literal, isNotNull); |
| + assertNoErrors(); |
| + expect(literal.constKeyword, token); |
| + expect(literal.typeArguments, typeArguments); |
| + expect(literal.leftBracket, isNotNull); |
| + expect(literal.elements, hasLength(0)); |
| + expect(literal.rightBracket, isNotNull); |
| } |
| - void test_additiveExpression_missing_RHS() { |
| - BinaryExpression expression = |
| - parseExpression("x +", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.rightOperand); |
| - expect(expression.rightOperand.isSynthetic, isTrue); |
| + void test_parseListLiteral_multiple() { |
| + createParser('[1, 2, 3]'); |
| + ListLiteral literal = parser.parseListLiteral(null, null); |
| + expect(literal, isNotNull); |
| + assertNoErrors(); |
| + expect(literal.constKeyword, isNull); |
| + expect(literal.typeArguments, isNull); |
| + expect(literal.leftBracket, isNotNull); |
| + expect(literal.elements, hasLength(3)); |
| + expect(literal.rightBracket, isNotNull); |
| } |
| - void test_additiveExpression_missing_RHS_super() { |
| - BinaryExpression expression = |
| - parseExpression("super +", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.rightOperand); |
| - expect(expression.rightOperand.isSynthetic, isTrue); |
| + void test_parseListLiteral_single() { |
| + createParser('[1]'); |
| + ListLiteral literal = parser.parseListLiteral(null, null); |
| + expect(literal, isNotNull); |
| + assertNoErrors(); |
| + expect(literal.constKeyword, isNull); |
| + expect(literal.typeArguments, isNull); |
| + expect(literal.leftBracket, isNotNull); |
| + expect(literal.elements, hasLength(1)); |
| + expect(literal.rightBracket, isNotNull); |
| } |
| - void test_additiveExpression_precedence_multiplicative_left() { |
| - BinaryExpression expression = parseExpression("* +", [ |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER |
| - ]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| - BinaryExpression, expression.leftOperand); |
| + void test_parseListOrMapLiteral_list_noType() { |
| + createParser('[1]'); |
| + TypedLiteral literal = parser.parseListOrMapLiteral(null); |
| + expect(literal, isNotNull); |
| + assertNoErrors(); |
| + expect(literal, new isInstanceOf<ListLiteral>()); |
| + ListLiteral listLiteral = literal; |
| + expect(listLiteral.constKeyword, isNull); |
| + expect(listLiteral.typeArguments, isNull); |
| + expect(listLiteral.leftBracket, isNotNull); |
| + expect(listLiteral.elements, hasLength(1)); |
| + expect(listLiteral.rightBracket, isNotNull); |
| } |
| - void test_additiveExpression_precedence_multiplicative_right() { |
| - BinaryExpression expression = parseExpression("+ *", [ |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER |
| - ]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| - BinaryExpression, expression.rightOperand); |
| + void test_parseListOrMapLiteral_list_type() { |
| + createParser('<int> [1]'); |
| + TypedLiteral literal = parser.parseListOrMapLiteral(null); |
| + expect(literal, isNotNull); |
| + assertNoErrors(); |
| + expect(literal, new isInstanceOf<ListLiteral>()); |
| + ListLiteral listLiteral = literal; |
| + expect(listLiteral.constKeyword, isNull); |
| + expect(listLiteral.typeArguments, isNotNull); |
| + expect(listLiteral.leftBracket, isNotNull); |
| + expect(listLiteral.elements, hasLength(1)); |
| + expect(listLiteral.rightBracket, isNotNull); |
| } |
| - void test_additiveExpression_super() { |
| - BinaryExpression expression = parseExpression("super + +", [ |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER |
| - ]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| - BinaryExpression, expression.leftOperand); |
| + void test_parseListOrMapLiteral_map_noType() { |
| + createParser("{'1' : 1}"); |
| + TypedLiteral literal = parser.parseListOrMapLiteral(null); |
| + expect(literal, isNotNull); |
| + assertNoErrors(); |
| + expect(literal, new isInstanceOf<MapLiteral>()); |
| + MapLiteral mapLiteral = literal; |
| + expect(mapLiteral.constKeyword, isNull); |
| + expect(mapLiteral.typeArguments, isNull); |
| + expect(mapLiteral.leftBracket, isNotNull); |
| + expect(mapLiteral.entries, hasLength(1)); |
| + expect(mapLiteral.rightBracket, isNotNull); |
| } |
| - void test_assignableSelector() { |
| - IndexExpression expression = |
| - parseExpression("a.b[]", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - Expression index = expression.index; |
| - expect(index, new isInstanceOf<SimpleIdentifier>()); |
| - expect(index.isSynthetic, isTrue); |
| + void test_parseListOrMapLiteral_map_type() { |
| + createParser("<String, int> {'1' : 1}"); |
| + TypedLiteral literal = parser.parseListOrMapLiteral(null); |
| + expect(literal, isNotNull); |
| + assertNoErrors(); |
| + expect(literal, new isInstanceOf<MapLiteral>()); |
| + MapLiteral mapLiteral = literal; |
| + expect(mapLiteral.constKeyword, isNull); |
| + expect(mapLiteral.typeArguments, isNotNull); |
| + expect(mapLiteral.leftBracket, isNotNull); |
| + expect(mapLiteral.entries, hasLength(1)); |
| + expect(mapLiteral.rightBracket, isNotNull); |
| } |
| - void test_assignmentExpression_missing_compound1() { |
| - AssignmentExpression expression = |
| - parseExpression("= y = 0", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - Expression syntheticExpression = expression.leftHandSide; |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, syntheticExpression); |
| - expect(syntheticExpression.isSynthetic, isTrue); |
| + void test_parseLogicalAndExpression() { |
| + createParser('x && y'); |
| + Expression expression = parser.parseLogicalAndExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<BinaryExpression>()); |
| + BinaryExpression binaryExpression = expression; |
| + expect(binaryExpression.leftOperand, isNotNull); |
| + expect(binaryExpression.operator, isNotNull); |
| + expect(binaryExpression.operator.type, TokenType.AMPERSAND_AMPERSAND); |
| + expect(binaryExpression.rightOperand, isNotNull); |
| } |
| - void test_assignmentExpression_missing_compound2() { |
| - AssignmentExpression expression = |
| - parseExpression("x = = 0", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - Expression syntheticExpression = |
| - (expression.rightHandSide as AssignmentExpression).leftHandSide; |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, syntheticExpression); |
| - expect(syntheticExpression.isSynthetic, isTrue); |
| + void test_parseLogicalOrExpression() { |
| + createParser('x || y'); |
| + Expression expression = parser.parseLogicalOrExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<BinaryExpression>()); |
| + BinaryExpression binaryExpression = expression; |
| + expect(binaryExpression.leftOperand, isNotNull); |
| + expect(binaryExpression.operator, isNotNull); |
| + expect(binaryExpression.operator.type, TokenType.BAR_BAR); |
| + expect(binaryExpression.rightOperand, isNotNull); |
| } |
| - void test_assignmentExpression_missing_compound3() { |
| - AssignmentExpression expression = |
| - parseExpression("x = y =", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - Expression syntheticExpression = |
| - (expression.rightHandSide as AssignmentExpression).rightHandSide; |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, syntheticExpression); |
| - expect(syntheticExpression.isSynthetic, isTrue); |
| + void test_parseMapLiteral_empty() { |
| + Token token = TokenFactory.tokenFromKeyword(Keyword.CONST); |
| + TypeArgumentList typeArguments = AstTestFactory.typeArgumentList( |
| + [AstTestFactory.typeName4("String"), AstTestFactory.typeName4("int")]); |
| + createParser('{}'); |
| + MapLiteral literal = parser.parseMapLiteral(token, typeArguments); |
| + expect(literal, isNotNull); |
| + assertNoErrors(); |
| + expect(literal.constKeyword, token); |
| + expect(literal.typeArguments, typeArguments); |
| + expect(literal.leftBracket, isNotNull); |
| + expect(literal.entries, hasLength(0)); |
| + expect(literal.rightBracket, isNotNull); |
| } |
| - void test_assignmentExpression_missing_LHS() { |
| - AssignmentExpression expression = |
| - parseExpression("= 0", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.leftHandSide); |
| - expect(expression.leftHandSide.isSynthetic, isTrue); |
| + void test_parseMapLiteral_multiple() { |
| + createParser("{'a' : b, 'x' : y}"); |
| + MapLiteral literal = parser.parseMapLiteral(null, null); |
| + expect(literal, isNotNull); |
| + assertNoErrors(); |
| + expect(literal.leftBracket, isNotNull); |
| + expect(literal.entries, hasLength(2)); |
| + expect(literal.rightBracket, isNotNull); |
| } |
| - void test_assignmentExpression_missing_RHS() { |
| - AssignmentExpression expression = |
| - parseExpression("x =", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.leftHandSide); |
| - expect(expression.rightHandSide.isSynthetic, isTrue); |
| + void test_parseMapLiteral_single() { |
| + createParser("{'x' : y}"); |
| + MapLiteral literal = parser.parseMapLiteral(null, null); |
| + expect(literal, isNotNull); |
| + assertNoErrors(); |
| + expect(literal.leftBracket, isNotNull); |
| + expect(literal.entries, hasLength(1)); |
| + expect(literal.rightBracket, isNotNull); |
| } |
| - void test_bitwiseAndExpression_missing_LHS() { |
| - BinaryExpression expression = |
| - parseExpression("& y", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.leftOperand); |
| - expect(expression.leftOperand.isSynthetic, isTrue); |
| + void test_parseMapLiteralEntry_complex() { |
| + createParser('2 + 2 : y'); |
| + MapLiteralEntry entry = parser.parseMapLiteralEntry(); |
| + expect(entry, isNotNull); |
| + assertNoErrors(); |
| + expect(entry.key, isNotNull); |
| + expect(entry.separator, isNotNull); |
| + expect(entry.value, isNotNull); |
| } |
| - void test_bitwiseAndExpression_missing_LHS_RHS() { |
| - BinaryExpression expression = parseExpression("&", [ |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER |
| - ]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.leftOperand); |
| - expect(expression.leftOperand.isSynthetic, isTrue); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.rightOperand); |
| - expect(expression.rightOperand.isSynthetic, isTrue); |
| + void test_parseMapLiteralEntry_int() { |
| + createParser('0 : y'); |
| + MapLiteralEntry entry = parser.parseMapLiteralEntry(); |
| + expect(entry, isNotNull); |
| + assertNoErrors(); |
| + expect(entry.key, isNotNull); |
| + expect(entry.separator, isNotNull); |
| + expect(entry.value, isNotNull); |
| } |
| - void test_bitwiseAndExpression_missing_RHS() { |
| - BinaryExpression expression = |
| - parseExpression("x &", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.rightOperand); |
| - expect(expression.rightOperand.isSynthetic, isTrue); |
| + void test_parseMapLiteralEntry_string() { |
| + createParser("'x' : y"); |
| + MapLiteralEntry entry = parser.parseMapLiteralEntry(); |
| + expect(entry, isNotNull); |
| + assertNoErrors(); |
| + expect(entry.key, isNotNull); |
| + expect(entry.separator, isNotNull); |
| + expect(entry.value, isNotNull); |
| } |
| - void test_bitwiseAndExpression_missing_RHS_super() { |
| - BinaryExpression expression = |
| - parseExpression("super &", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.rightOperand); |
| - expect(expression.rightOperand.isSynthetic, isTrue); |
| + void test_parseMultiplicativeExpression_normal() { |
| + createParser('x * y'); |
| + Expression expression = parser.parseMultiplicativeExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<BinaryExpression>()); |
| + BinaryExpression binaryExpression = expression; |
| + expect(binaryExpression.leftOperand, isNotNull); |
| + expect(binaryExpression.operator, isNotNull); |
| + expect(binaryExpression.operator.type, TokenType.STAR); |
| + expect(binaryExpression.rightOperand, isNotNull); |
| } |
| - void test_bitwiseAndExpression_precedence_equality_left() { |
| - BinaryExpression expression = parseExpression("== &&", [ |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER |
| - ]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| - BinaryExpression, expression.leftOperand); |
| + void test_parseMultiplicativeExpression_super() { |
| + createParser('super * y'); |
| + Expression expression = parser.parseMultiplicativeExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<BinaryExpression>()); |
| + BinaryExpression binaryExpression = expression; |
| + expect(binaryExpression.leftOperand, new isInstanceOf<SuperExpression>()); |
| + expect(binaryExpression.operator, isNotNull); |
| + expect(binaryExpression.operator.type, TokenType.STAR); |
| + expect(binaryExpression.rightOperand, isNotNull); |
| } |
| - void test_bitwiseAndExpression_precedence_equality_right() { |
| - BinaryExpression expression = parseExpression("&& ==", [ |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER |
| - ]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| - BinaryExpression, expression.rightOperand); |
| + void test_parseNewExpression() { |
| + createParser('new A()'); |
| + InstanceCreationExpression expression = parser.parseNewExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression.keyword, isNotNull); |
| + ConstructorName name = expression.constructorName; |
| + expect(name, isNotNull); |
| + expect(name.type, isNotNull); |
| + expect(name.period, isNull); |
| + expect(name.name, isNull); |
| + expect(expression.argumentList, isNotNull); |
| } |
| - void test_bitwiseAndExpression_super() { |
| - BinaryExpression expression = parseExpression("super & &", [ |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER |
| - ]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| - BinaryExpression, expression.leftOperand); |
| + void test_parsePostfixExpression_decrement() { |
| + createParser('i--'); |
| + Expression expression = parser.parsePostfixExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<PostfixExpression>()); |
| + PostfixExpression postfixExpression = expression; |
| + expect(postfixExpression.operand, isNotNull); |
| + expect(postfixExpression.operator, isNotNull); |
| + expect(postfixExpression.operator.type, TokenType.MINUS_MINUS); |
| } |
| - void test_bitwiseOrExpression_missing_LHS() { |
| - BinaryExpression expression = |
| - parseExpression("| y", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.leftOperand); |
| - expect(expression.leftOperand.isSynthetic, isTrue); |
| + void test_parsePostfixExpression_increment() { |
| + createParser('i++'); |
| + Expression expression = parser.parsePostfixExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<PostfixExpression>()); |
| + PostfixExpression postfixExpression = expression; |
| + expect(postfixExpression.operand, isNotNull); |
| + expect(postfixExpression.operator, isNotNull); |
| + expect(postfixExpression.operator.type, TokenType.PLUS_PLUS); |
| } |
| - void test_bitwiseOrExpression_missing_LHS_RHS() { |
| - BinaryExpression expression = parseExpression("|", [ |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER |
| - ]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.leftOperand); |
| - expect(expression.leftOperand.isSynthetic, isTrue); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.rightOperand); |
| - expect(expression.rightOperand.isSynthetic, isTrue); |
| + void test_parsePostfixExpression_none_indexExpression() { |
| + createParser('a[0]'); |
| + Expression expression = parser.parsePostfixExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<IndexExpression>()); |
| + IndexExpression indexExpression = expression; |
| + expect(indexExpression.target, isNotNull); |
| + expect(indexExpression.index, isNotNull); |
| } |
| - void test_bitwiseOrExpression_missing_RHS() { |
| - BinaryExpression expression = |
| - parseExpression("x |", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.rightOperand); |
| - expect(expression.rightOperand.isSynthetic, isTrue); |
| + void test_parsePostfixExpression_none_methodInvocation() { |
| + createParser('a.m()'); |
| + Expression expression = parser.parsePostfixExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<MethodInvocation>()); |
| + MethodInvocation methodInvocation = expression; |
| + expect(methodInvocation.target, isNotNull); |
| + expect(methodInvocation.operator.type, TokenType.PERIOD); |
| + expect(methodInvocation.methodName, isNotNull); |
| + expect(methodInvocation.typeArguments, isNull); |
| + expect(methodInvocation.argumentList, isNotNull); |
| } |
| - void test_bitwiseOrExpression_missing_RHS_super() { |
| - BinaryExpression expression = |
| - parseExpression("super |", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.rightOperand); |
| - expect(expression.rightOperand.isSynthetic, isTrue); |
| + void test_parsePostfixExpression_none_methodInvocation_question_dot() { |
| + createParser('a?.m()'); |
| + Expression expression = parser.parsePostfixExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<MethodInvocation>()); |
| + MethodInvocation methodInvocation = expression; |
| + expect(methodInvocation.target, isNotNull); |
| + expect(methodInvocation.operator.type, TokenType.QUESTION_PERIOD); |
| + expect(methodInvocation.methodName, isNotNull); |
| + expect(methodInvocation.typeArguments, isNull); |
| + expect(methodInvocation.argumentList, isNotNull); |
| } |
| - void test_bitwiseOrExpression_precedence_xor_left() { |
| - BinaryExpression expression = parseExpression("^ |", [ |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER |
| - ]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| - BinaryExpression, expression.leftOperand); |
| + void |
| + test_parsePostfixExpression_none_methodInvocation_question_dot_typeArgumentComments() { |
| + enableGenericMethodComments = true; |
| + createParser('a?.m/*<E>*/()'); |
| + Expression expression = parser.parsePostfixExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<MethodInvocation>()); |
| + MethodInvocation methodInvocation = expression; |
| + expect(methodInvocation.target, isNotNull); |
| + expect(methodInvocation.operator.type, TokenType.QUESTION_PERIOD); |
| + expect(methodInvocation.methodName, isNotNull); |
| + expect(methodInvocation.typeArguments, isNotNull); |
| + expect(methodInvocation.argumentList, isNotNull); |
| } |
| - void test_bitwiseOrExpression_precedence_xor_right() { |
| - BinaryExpression expression = parseExpression("| ^", [ |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER |
| - ]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| - BinaryExpression, expression.rightOperand); |
| + void |
| + test_parsePostfixExpression_none_methodInvocation_question_dot_typeArguments() { |
| + createParser('a?.m<E>()'); |
| + Expression expression = parser.parsePostfixExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<MethodInvocation>()); |
| + MethodInvocation methodInvocation = expression; |
| + expect(methodInvocation.target, isNotNull); |
| + expect(methodInvocation.operator.type, TokenType.QUESTION_PERIOD); |
| + expect(methodInvocation.methodName, isNotNull); |
| + expect(methodInvocation.typeArguments, isNotNull); |
| + expect(methodInvocation.argumentList, isNotNull); |
| } |
| - void test_bitwiseOrExpression_super() { |
| - BinaryExpression expression = parseExpression("super | |", [ |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER |
| - ]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| - BinaryExpression, expression.leftOperand); |
| + void |
| + test_parsePostfixExpression_none_methodInvocation_typeArgumentComments() { |
| + enableGenericMethodComments = true; |
| + createParser('a.m/*<E>*/()'); |
| + Expression expression = parser.parsePostfixExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<MethodInvocation>()); |
| + MethodInvocation methodInvocation = expression; |
| + expect(methodInvocation.target, isNotNull); |
| + expect(methodInvocation.operator.type, TokenType.PERIOD); |
| + expect(methodInvocation.methodName, isNotNull); |
| + expect(methodInvocation.typeArguments, isNotNull); |
| + expect(methodInvocation.argumentList, isNotNull); |
| + } |
| + |
| + void test_parsePostfixExpression_none_methodInvocation_typeArguments() { |
| + createParser('a.m<E>()'); |
| + Expression expression = parser.parsePostfixExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<MethodInvocation>()); |
| + MethodInvocation methodInvocation = expression; |
| + expect(methodInvocation.target, isNotNull); |
| + expect(methodInvocation.operator.type, TokenType.PERIOD); |
| + expect(methodInvocation.methodName, isNotNull); |
| + expect(methodInvocation.typeArguments, isNotNull); |
| + expect(methodInvocation.argumentList, isNotNull); |
| } |
| - void test_bitwiseXorExpression_missing_LHS() { |
| - BinaryExpression expression = |
| - parseExpression("^ y", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.leftOperand); |
| - expect(expression.leftOperand.isSynthetic, isTrue); |
| + void test_parsePostfixExpression_none_propertyAccess() { |
| + createParser('a.b'); |
| + Expression expression = parser.parsePostfixExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<PrefixedIdentifier>()); |
| + PrefixedIdentifier identifier = expression; |
| + expect(identifier.prefix, isNotNull); |
| + expect(identifier.identifier, isNotNull); |
| } |
| - void test_bitwiseXorExpression_missing_LHS_RHS() { |
| - BinaryExpression expression = parseExpression("^", [ |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER |
| - ]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.leftOperand); |
| - expect(expression.leftOperand.isSynthetic, isTrue); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.rightOperand); |
| - expect(expression.rightOperand.isSynthetic, isTrue); |
| + void test_parsePrefixedIdentifier_noPrefix() { |
| + String lexeme = "bar"; |
| + createParser(lexeme); |
| + Identifier identifier = parser.parsePrefixedIdentifier(); |
| + expect(identifier, isNotNull); |
| + assertNoErrors(); |
| + expect(identifier, new isInstanceOf<SimpleIdentifier>()); |
| + SimpleIdentifier simpleIdentifier = identifier; |
| + expect(simpleIdentifier.token, isNotNull); |
| + expect(simpleIdentifier.name, lexeme); |
| } |
| - void test_bitwiseXorExpression_missing_RHS() { |
| - BinaryExpression expression = |
| - parseExpression("x ^", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.rightOperand); |
| - expect(expression.rightOperand.isSynthetic, isTrue); |
| + void test_parsePrefixedIdentifier_prefix() { |
| + String lexeme = "foo.bar"; |
| + createParser(lexeme); |
| + Identifier identifier = parser.parsePrefixedIdentifier(); |
| + expect(identifier, isNotNull); |
| + assertNoErrors(); |
| + expect(identifier, new isInstanceOf<PrefixedIdentifier>()); |
| + PrefixedIdentifier prefixedIdentifier = identifier; |
| + expect(prefixedIdentifier.prefix.name, "foo"); |
| + expect(prefixedIdentifier.period, isNotNull); |
| + expect(prefixedIdentifier.identifier.name, "bar"); |
| } |
| - void test_bitwiseXorExpression_missing_RHS_super() { |
| - BinaryExpression expression = |
| - parseExpression("super ^", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.rightOperand); |
| - expect(expression.rightOperand.isSynthetic, isTrue); |
| + void test_parsePrimaryExpression_const() { |
| + createParser('const A()'); |
| + Expression expression = parser.parsePrimaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, isNotNull); |
| } |
| - void test_bitwiseXorExpression_precedence_and_left() { |
| - BinaryExpression expression = parseExpression("& ^", [ |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER |
| - ]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| - BinaryExpression, expression.leftOperand); |
| + void test_parsePrimaryExpression_double() { |
| + String doubleLiteral = "3.2e4"; |
| + createParser(doubleLiteral); |
| + Expression expression = parser.parsePrimaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<DoubleLiteral>()); |
| + DoubleLiteral literal = expression; |
| + expect(literal.literal, isNotNull); |
| + expect(literal.value, double.parse(doubleLiteral)); |
| } |
| - void test_bitwiseXorExpression_precedence_and_right() { |
| - BinaryExpression expression = parseExpression("^ &", [ |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER |
| - ]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| - BinaryExpression, expression.rightOperand); |
| + void test_parsePrimaryExpression_false() { |
| + createParser('false'); |
| + Expression expression = parser.parsePrimaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<BooleanLiteral>()); |
| + BooleanLiteral literal = expression; |
| + expect(literal.literal, isNotNull); |
| + expect(literal.value, isFalse); |
| } |
| - void test_bitwiseXorExpression_super() { |
| - BinaryExpression expression = parseExpression("super ^ ^", [ |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER |
| - ]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| - BinaryExpression, expression.leftOperand); |
| + void test_parsePrimaryExpression_function_arguments() { |
| + createParser('(int i) => i + 1'); |
| + Expression expression = parser.parsePrimaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<FunctionExpression>()); |
| + FunctionExpression functionExpression = expression; |
| + expect(functionExpression.parameters, isNotNull); |
| + expect(functionExpression.body, isNotNull); |
| } |
| - void test_classTypeAlias_withBody() { |
| - parseCompilationUnit( |
| - r''' |
| -class A {} |
| -class B = Object with A {}''', |
| - [ParserErrorCode.EXPECTED_TOKEN]); |
| + void test_parsePrimaryExpression_function_noArguments() { |
| + createParser('() => 42'); |
| + Expression expression = parser.parsePrimaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<FunctionExpression>()); |
| + FunctionExpression functionExpression = expression; |
| + expect(functionExpression.parameters, isNotNull); |
| + expect(functionExpression.body, isNotNull); |
| } |
| - void test_conditionalExpression_missingElse() { |
| - createParser('x ? y :'); |
| - Expression expression = parser.parseConditionalExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| - expect(expression, new isInstanceOf<ConditionalExpression>()); |
| - ConditionalExpression conditionalExpression = expression; |
| - expect(conditionalExpression.elseExpression, |
| - new isInstanceOf<SimpleIdentifier>()); |
| - expect(conditionalExpression.elseExpression.isSynthetic, isTrue); |
| + void test_parsePrimaryExpression_genericFunctionExpression() { |
| + createParser('<X, Y>(Map<X, Y> m, X x) => m[x]'); |
| + Expression expression = parser.parsePrimaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<FunctionExpression>()); |
| + FunctionExpression function = expression; |
| + expect(function.typeParameters, isNotNull); |
| } |
| - void test_conditionalExpression_missingThen() { |
| - createParser('x ? : z'); |
| - Expression expression = parser.parseConditionalExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| - expect(expression, new isInstanceOf<ConditionalExpression>()); |
| - ConditionalExpression conditionalExpression = expression; |
| - expect(conditionalExpression.thenExpression, |
| - new isInstanceOf<SimpleIdentifier>()); |
| - expect(conditionalExpression.thenExpression.isSynthetic, isTrue); |
| + void test_parsePrimaryExpression_hex() { |
| + String hexLiteral = "3F"; |
| + createParser('0x$hexLiteral'); |
| + Expression expression = parser.parsePrimaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<IntegerLiteral>()); |
| + IntegerLiteral literal = expression; |
| + expect(literal.literal, isNotNull); |
| + expect(literal.value, int.parse(hexLiteral, radix: 16)); |
| } |
| - void test_declarationBeforeDirective() { |
| - CompilationUnit unit = parseCompilationUnit( |
| - "class foo { } import 'bar.dart';", |
| - [ParserErrorCode.DIRECTIVE_AFTER_DECLARATION]); |
| - expect(unit.directives, hasLength(1)); |
| - expect(unit.declarations, hasLength(1)); |
| - ClassDeclaration classDecl = unit.childEntities.first; |
| - expect(classDecl, isNotNull); |
| - expect(classDecl.name.name, 'foo'); |
| + void test_parsePrimaryExpression_identifier() { |
| + createParser('a'); |
| + Expression expression = parser.parsePrimaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<SimpleIdentifier>()); |
| + SimpleIdentifier identifier = expression; |
| + expect(identifier, isNotNull); |
| } |
| - void test_equalityExpression_missing_LHS() { |
| - BinaryExpression expression = |
| - parseExpression("== y", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.leftOperand); |
| - expect(expression.leftOperand.isSynthetic, isTrue); |
| + void test_parsePrimaryExpression_int() { |
| + String intLiteral = "472"; |
| + createParser(intLiteral); |
| + Expression expression = parser.parsePrimaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<IntegerLiteral>()); |
| + IntegerLiteral literal = expression; |
| + expect(literal.literal, isNotNull); |
| + expect(literal.value, int.parse(intLiteral)); |
| } |
| - void test_equalityExpression_missing_LHS_RHS() { |
| - BinaryExpression expression = parseExpression("==", [ |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER |
| - ]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.leftOperand); |
| - expect(expression.leftOperand.isSynthetic, isTrue); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.rightOperand); |
| - expect(expression.rightOperand.isSynthetic, isTrue); |
| + void test_parsePrimaryExpression_listLiteral() { |
| + createParser('[ ]'); |
| + Expression expression = parser.parsePrimaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<ListLiteral>()); |
| + ListLiteral literal = expression; |
| + expect(literal, isNotNull); |
| } |
| - void test_equalityExpression_missing_RHS() { |
| - BinaryExpression expression = |
| - parseExpression("x ==", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.rightOperand); |
| - expect(expression.rightOperand.isSynthetic, isTrue); |
| + void test_parsePrimaryExpression_listLiteral_index() { |
| + createParser('[]'); |
| + Expression expression = parser.parsePrimaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<ListLiteral>()); |
| + ListLiteral literal = expression; |
| + expect(literal, isNotNull); |
| } |
| - void test_equalityExpression_missing_RHS_super() { |
| - BinaryExpression expression = |
| - parseExpression("super ==", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.rightOperand); |
| - expect(expression.rightOperand.isSynthetic, isTrue); |
| + void test_parsePrimaryExpression_listLiteral_typed() { |
| + createParser('<A>[ ]'); |
| + Expression expression = parser.parsePrimaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<ListLiteral>()); |
| + ListLiteral literal = expression; |
| + expect(literal.typeArguments, isNotNull); |
| + expect(literal.typeArguments.arguments, hasLength(1)); |
| + } |
| + |
| + void test_parsePrimaryExpression_listLiteral_typed_genericComment() { |
| + enableGenericMethodComments = true; |
| + createParser('/*<A>*/[ ]'); |
| + Expression expression = parser.parsePrimaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<ListLiteral>()); |
| + ListLiteral literal = expression; |
| + expect(literal.typeArguments, isNotNull); |
| + expect(literal.typeArguments.arguments, hasLength(1)); |
| } |
| - void test_equalityExpression_precedence_relational_left() { |
| - BinaryExpression expression = parseExpression("is ==", [ |
| - ParserErrorCode.EXPECTED_TYPE_NAME, |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER |
| - ]); |
| - EngineTestCase.assertInstanceOf( |
| - (obj) => obj is IsExpression, IsExpression, expression.leftOperand); |
| + void test_parsePrimaryExpression_mapLiteral() { |
| + createParser('{}'); |
| + Expression expression = parser.parsePrimaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<MapLiteral>()); |
| + MapLiteral literal = expression; |
| + expect(literal.typeArguments, isNull); |
| + expect(literal, isNotNull); |
| } |
| - void test_equalityExpression_precedence_relational_right() { |
| - BinaryExpression expression = parseExpression("== is", [ |
| - ParserErrorCode.EXPECTED_TYPE_NAME, |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER |
| - ]); |
| - EngineTestCase.assertInstanceOf( |
| - (obj) => obj is IsExpression, IsExpression, expression.rightOperand); |
| + void test_parsePrimaryExpression_mapLiteral_typed() { |
| + createParser('<A, B>{}'); |
| + Expression expression = parser.parsePrimaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<MapLiteral>()); |
| + MapLiteral literal = expression; |
| + expect(literal.typeArguments, isNotNull); |
| + expect(literal.typeArguments.arguments, hasLength(2)); |
| } |
| - void test_equalityExpression_super() { |
| - BinaryExpression expression = parseExpression("super == ==", [ |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND |
| - ]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| - BinaryExpression, expression.leftOperand); |
| + void test_parsePrimaryExpression_mapLiteral_typed_genericComment() { |
| + enableGenericMethodComments = true; |
| + createParser('/*<A, B>*/{}'); |
| + Expression expression = parser.parsePrimaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<MapLiteral>()); |
| + MapLiteral literal = expression; |
| + expect(literal.typeArguments, isNotNull); |
| + expect(literal.typeArguments.arguments, hasLength(2)); |
| } |
| - void test_expressionList_multiple_end() { |
| - createParser(', 2, 3, 4'); |
| - List<Expression> result = parser.parseExpressionList(); |
| - expectNotNullIfNoErrors(result); |
| - listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| - expect(result, hasLength(4)); |
| - Expression syntheticExpression = result[0]; |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, syntheticExpression); |
| - expect(syntheticExpression.isSynthetic, isTrue); |
| + void test_parsePrimaryExpression_new() { |
| + createParser('new A()'); |
| + Expression expression = parser.parsePrimaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<InstanceCreationExpression>()); |
| + InstanceCreationExpression creation = expression; |
| + expect(creation, isNotNull); |
| } |
| - void test_expressionList_multiple_middle() { |
| - createParser('1, 2, , 4'); |
| - List<Expression> result = parser.parseExpressionList(); |
| - expectNotNullIfNoErrors(result); |
| - listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| - expect(result, hasLength(4)); |
| - Expression syntheticExpression = result[2]; |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, syntheticExpression); |
| - expect(syntheticExpression.isSynthetic, isTrue); |
| + void test_parsePrimaryExpression_null() { |
| + createParser('null'); |
| + Expression expression = parser.parsePrimaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<NullLiteral>()); |
| + NullLiteral literal = expression; |
| + expect(literal.literal, isNotNull); |
| } |
| - void test_expressionList_multiple_start() { |
| - createParser('1, 2, 3,'); |
| - List<Expression> result = parser.parseExpressionList(); |
| - expectNotNullIfNoErrors(result); |
| - listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| - expect(result, hasLength(4)); |
| - Expression syntheticExpression = result[3]; |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, syntheticExpression); |
| - expect(syntheticExpression.isSynthetic, isTrue); |
| + void test_parsePrimaryExpression_parenthesized() { |
| + createParser('(x)'); |
| + Expression expression = parser.parsePrimaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<ParenthesizedExpression>()); |
| + ParenthesizedExpression parens = expression; |
| + expect(parens, isNotNull); |
| } |
| - void test_functionExpression_in_ConstructorFieldInitializer() { |
| - CompilationUnit unit = parseCompilationUnit( |
| - "class A { A() : a = (){}; var v; }", |
| - [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.UNEXPECTED_TOKEN]); |
| - // Make sure we recovered and parsed "var v" correctly |
| - ClassDeclaration declaration = unit.declarations[0] as ClassDeclaration; |
| - NodeList<ClassMember> members = declaration.members; |
| - ClassMember fieldDecl = members[1]; |
| - EngineTestCase.assertInstanceOf( |
| - (obj) => obj is FieldDeclaration, FieldDeclaration, fieldDecl); |
| - NodeList<VariableDeclaration> vars = |
| - (fieldDecl as FieldDeclaration).fields.variables; |
| - expect(vars, hasLength(1)); |
| - expect(vars[0].name.name, "v"); |
| + void test_parsePrimaryExpression_string() { |
| + createParser('"string"'); |
| + Expression expression = parser.parsePrimaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| + SimpleStringLiteral literal = expression; |
| + expect(literal.isMultiline, isFalse); |
| + expect(literal.isRaw, isFalse); |
| + expect(literal.value, "string"); |
| } |
| - void test_functionExpression_named() { |
| - parseExpression("m(f() => 0);", [ParserErrorCode.EXPECTED_TOKEN]); |
| + void test_parsePrimaryExpression_string_multiline() { |
| + createParser("'''string'''"); |
| + Expression expression = parser.parsePrimaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| + SimpleStringLiteral literal = expression; |
| + expect(literal.isMultiline, isTrue); |
| + expect(literal.isRaw, isFalse); |
| + expect(literal.value, "string"); |
| } |
| - void test_importDirectivePartial_as() { |
| - CompilationUnit unit = parseCompilationUnit( |
| - "import 'b.dart' d as b;", [ParserErrorCode.UNEXPECTED_TOKEN]); |
| - ImportDirective importDirective = unit.childEntities.first; |
| - expect(importDirective.asKeyword, isNotNull); |
| - expect(unit.directives, hasLength(1)); |
| - expect(unit.declarations, hasLength(0)); |
| + void test_parsePrimaryExpression_string_raw() { |
| + createParser("r'string'"); |
| + Expression expression = parser.parsePrimaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| + SimpleStringLiteral literal = expression; |
| + expect(literal.isMultiline, isFalse); |
| + expect(literal.isRaw, isTrue); |
| + expect(literal.value, "string"); |
| } |
| - void test_importDirectivePartial_hide() { |
| - CompilationUnit unit = parseCompilationUnit( |
| - "import 'b.dart' d hide foo;", [ParserErrorCode.UNEXPECTED_TOKEN]); |
| - ImportDirective importDirective = unit.childEntities.first; |
| - expect(importDirective.combinators, hasLength(1)); |
| - expect(unit.directives, hasLength(1)); |
| - expect(unit.declarations, hasLength(0)); |
| + void test_parsePrimaryExpression_super() { |
| + createParser('super.x'); |
| + Expression expression = parser.parsePrimaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<PropertyAccess>()); |
| + PropertyAccess propertyAccess = expression; |
| + expect(propertyAccess.target is SuperExpression, isTrue); |
| + expect(propertyAccess.operator, isNotNull); |
| + expect(propertyAccess.operator.type, TokenType.PERIOD); |
| + expect(propertyAccess.propertyName, isNotNull); |
| } |
| - void test_importDirectivePartial_show() { |
| - CompilationUnit unit = parseCompilationUnit( |
| - "import 'b.dart' d show foo;", [ParserErrorCode.UNEXPECTED_TOKEN]); |
| - ImportDirective importDirective = unit.childEntities.first; |
| - expect(importDirective.combinators, hasLength(1)); |
| - expect(unit.directives, hasLength(1)); |
| - expect(unit.declarations, hasLength(0)); |
| + void test_parsePrimaryExpression_this() { |
| + createParser('this'); |
| + Expression expression = parser.parsePrimaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<ThisExpression>()); |
| + ThisExpression thisExpression = expression; |
| + expect(thisExpression.thisKeyword, isNotNull); |
| } |
| - void test_incomplete_conditionalExpression() { |
| - parseExpression("x ? 0", |
| - [ParserErrorCode.EXPECTED_TOKEN, ParserErrorCode.MISSING_IDENTIFIER]); |
| + void test_parsePrimaryExpression_true() { |
| + createParser('true'); |
| + Expression expression = parser.parsePrimaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<BooleanLiteral>()); |
| + BooleanLiteral literal = expression; |
| + expect(literal.literal, isNotNull); |
| + expect(literal.value, isTrue); |
| } |
| - void test_incomplete_constructorInitializers_empty() { |
| - createParser('C() : {}'); |
| - ClassMember member = parser.parseClassMember('C'); |
| - expectNotNullIfNoErrors(member); |
| - listener.assertErrorsWithCodes([ParserErrorCode.MISSING_INITIALIZER]); |
| + void test_parseRelationalExpression_as_functionType_noReturnType() { |
| + createParser('x as Function(int)'); |
| + Expression expression = parser.parseRelationalExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<AsExpression>()); |
| + AsExpression asExpression = expression; |
| + expect(asExpression.expression, isNotNull); |
| + expect(asExpression.asOperator, isNotNull); |
| + expect(asExpression.type, new isInstanceOf<GenericFunctionType>()); |
| } |
| - void test_incomplete_constructorInitializers_missingEquals() { |
| - createParser('C() : x(3) {}'); |
| - ClassMember member = parser.parseClassMember('C'); |
| - expectNotNullIfNoErrors(member); |
| - listener.assertErrorsWithCodes( |
| - [ParserErrorCode.MISSING_ASSIGNMENT_IN_INITIALIZER]); |
| - expect(member, new isInstanceOf<ConstructorDeclaration>()); |
| - NodeList<ConstructorInitializer> initializers = |
| - (member as ConstructorDeclaration).initializers; |
| - expect(initializers, hasLength(1)); |
| - ConstructorInitializer initializer = initializers[0]; |
| - expect(initializer, new isInstanceOf<ConstructorFieldInitializer>()); |
| - Expression expression = |
| - (initializer as ConstructorFieldInitializer).expression; |
| + void test_parseRelationalExpression_as_functionType_returnType() { |
| + createParser('x as String Function(int)'); |
| + Expression expression = parser.parseRelationalExpression(); |
| expect(expression, isNotNull); |
| - expect(expression, new isInstanceOf<ParenthesizedExpression>()); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<AsExpression>()); |
| + AsExpression asExpression = expression; |
| + expect(asExpression.expression, isNotNull); |
| + expect(asExpression.asOperator, isNotNull); |
| + expect(asExpression.type, new isInstanceOf<GenericFunctionType>()); |
| } |
| - void test_incomplete_constructorInitializers_variable() { |
| - createParser('C() : x {}'); |
| - ClassMember member = parser.parseClassMember('C'); |
| - expectNotNullIfNoErrors(member); |
| - listener.assertErrorsWithCodes( |
| - [ParserErrorCode.MISSING_ASSIGNMENT_IN_INITIALIZER]); |
| + void test_parseRelationalExpression_as_generic() { |
| + createParser('x as C<D>'); |
| + Expression expression = parser.parseRelationalExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<AsExpression>()); |
| + AsExpression asExpression = expression; |
| + expect(asExpression.expression, isNotNull); |
| + expect(asExpression.asOperator, isNotNull); |
| + expect(asExpression.type, new isInstanceOf<TypeName>()); |
| } |
| - @failingTest |
| - void test_incomplete_returnType() { |
| - parseCompilationUnit(r''' |
| -Map<Symbol, convertStringToSymbolMap(Map<String, dynamic> map) { |
| - if (map == null) return null; |
| - Map<Symbol, dynamic> result = new Map<Symbol, dynamic>(); |
| - map.forEach((name, value) { |
| - result[new Symbol(name)] = value; |
| - }); |
| - return result; |
| -}'''); |
| + void test_parseRelationalExpression_as_nullable() { |
| + enableNnbd = true; |
| + createParser('x as Y?)'); |
| + Expression expression = parser.parseRelationalExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<AsExpression>()); |
| + AsExpression asExpression = expression; |
| + expect(asExpression.expression, isNotNull); |
| + expect(asExpression.asOperator, isNotNull); |
| + expect(asExpression.type, new isInstanceOf<TypeName>()); |
| } |
| - void test_incomplete_topLevelFunction() { |
| - parseCompilationUnit("foo();", [ParserErrorCode.MISSING_FUNCTION_BODY]); |
| + void test_parseRelationalExpression_as_simple() { |
| + createParser('x as Y'); |
| + Expression expression = parser.parseRelationalExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<AsExpression>()); |
| + AsExpression asExpression = expression; |
| + expect(asExpression.expression, isNotNull); |
| + expect(asExpression.asOperator, isNotNull); |
| + expect(asExpression.type, new isInstanceOf<TypeName>()); |
| } |
| - void test_incomplete_topLevelVariable() { |
| - CompilationUnit unit = |
| - parseCompilationUnit("String", [ParserErrorCode.EXPECTED_EXECUTABLE]); |
| - NodeList<CompilationUnitMember> declarations = unit.declarations; |
| - expect(declarations, hasLength(1)); |
| - CompilationUnitMember member = declarations[0]; |
| - EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableDeclaration, |
| - TopLevelVariableDeclaration, member); |
| - NodeList<VariableDeclaration> variables = |
| - (member as TopLevelVariableDeclaration).variables.variables; |
| - expect(variables, hasLength(1)); |
| - SimpleIdentifier name = variables[0].name; |
| - expect(name.isSynthetic, isTrue); |
| + void test_parseRelationalExpression_as_simple_function() { |
| + createParser('x as Function'); |
| + Expression expression = parser.parseRelationalExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<AsExpression>()); |
| + AsExpression asExpression = expression; |
| + expect(asExpression.expression, isNotNull); |
| + expect(asExpression.asOperator, isNotNull); |
| + expect(asExpression.type, new isInstanceOf<TypeName>()); |
| } |
| - void test_incomplete_topLevelVariable_const() { |
| - CompilationUnit unit = parseCompilationUnit("const ", |
| - [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); |
| - NodeList<CompilationUnitMember> declarations = unit.declarations; |
| - expect(declarations, hasLength(1)); |
| - CompilationUnitMember member = declarations[0]; |
| - EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableDeclaration, |
| - TopLevelVariableDeclaration, member); |
| - NodeList<VariableDeclaration> variables = |
| - (member as TopLevelVariableDeclaration).variables.variables; |
| - expect(variables, hasLength(1)); |
| - SimpleIdentifier name = variables[0].name; |
| - expect(name.isSynthetic, isTrue); |
| + void test_parseRelationalExpression_is() { |
| + createParser('x is y'); |
| + Expression expression = parser.parseRelationalExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<IsExpression>()); |
| + IsExpression isExpression = expression; |
| + expect(isExpression.expression, isNotNull); |
| + expect(isExpression.isOperator, isNotNull); |
| + expect(isExpression.notOperator, isNull); |
| + expect(isExpression.type, isNotNull); |
| } |
| - void test_incomplete_topLevelVariable_final() { |
| - CompilationUnit unit = parseCompilationUnit("final ", |
| - [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); |
| - NodeList<CompilationUnitMember> declarations = unit.declarations; |
| - expect(declarations, hasLength(1)); |
| - CompilationUnitMember member = declarations[0]; |
| - EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableDeclaration, |
| - TopLevelVariableDeclaration, member); |
| - NodeList<VariableDeclaration> variables = |
| - (member as TopLevelVariableDeclaration).variables.variables; |
| - expect(variables, hasLength(1)); |
| - SimpleIdentifier name = variables[0].name; |
| - expect(name.isSynthetic, isTrue); |
| + void test_parseRelationalExpression_is_nullable() { |
| + enableNnbd = true; |
| + createParser('x is y?)'); |
| + Expression expression = parser.parseRelationalExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<IsExpression>()); |
| + IsExpression isExpression = expression; |
| + expect(isExpression.expression, isNotNull); |
| + expect(isExpression.isOperator, isNotNull); |
| + expect(isExpression.notOperator, isNull); |
| + expect(isExpression.type, isNotNull); |
| } |
| - void test_incomplete_topLevelVariable_var() { |
| - CompilationUnit unit = parseCompilationUnit("var ", |
| - [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); |
| - NodeList<CompilationUnitMember> declarations = unit.declarations; |
| - expect(declarations, hasLength(1)); |
| - CompilationUnitMember member = declarations[0]; |
| - EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableDeclaration, |
| - TopLevelVariableDeclaration, member); |
| - NodeList<VariableDeclaration> variables = |
| - (member as TopLevelVariableDeclaration).variables.variables; |
| - expect(variables, hasLength(1)); |
| - SimpleIdentifier name = variables[0].name; |
| - expect(name.isSynthetic, isTrue); |
| + void test_parseRelationalExpression_isNot() { |
| + createParser('x is! y'); |
| + Expression expression = parser.parseRelationalExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<IsExpression>()); |
| + IsExpression isExpression = expression; |
| + expect(isExpression.expression, isNotNull); |
| + expect(isExpression.isOperator, isNotNull); |
| + expect(isExpression.notOperator, isNotNull); |
| + expect(isExpression.type, isNotNull); |
| } |
| - void test_incompleteField_const() { |
| - CompilationUnit unit = parseCompilationUnit( |
| - r''' |
| -class C { |
| - const |
| -}''', |
| - [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); |
| - NodeList<CompilationUnitMember> declarations = unit.declarations; |
| - expect(declarations, hasLength(1)); |
| - CompilationUnitMember unitMember = declarations[0]; |
| - EngineTestCase.assertInstanceOf( |
| - (obj) => obj is ClassDeclaration, ClassDeclaration, unitMember); |
| - NodeList<ClassMember> members = (unitMember as ClassDeclaration).members; |
| - expect(members, hasLength(1)); |
| - ClassMember classMember = members[0]; |
| - EngineTestCase.assertInstanceOf( |
| - (obj) => obj is FieldDeclaration, FieldDeclaration, classMember); |
| - VariableDeclarationList fieldList = |
| - (classMember as FieldDeclaration).fields; |
| - expect(fieldList.keyword.keyword, Keyword.CONST); |
| - NodeList<VariableDeclaration> fields = fieldList.variables; |
| - expect(fields, hasLength(1)); |
| - VariableDeclaration field = fields[0]; |
| - expect(field.name.isSynthetic, isTrue); |
| + void test_parseRelationalExpression_normal() { |
| + createParser('x < y'); |
| + Expression expression = parser.parseRelationalExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<BinaryExpression>()); |
| + BinaryExpression binaryExpression = expression; |
| + expect(binaryExpression.leftOperand, isNotNull); |
| + expect(binaryExpression.operator, isNotNull); |
| + expect(binaryExpression.operator.type, TokenType.LT); |
| + expect(binaryExpression.rightOperand, isNotNull); |
| } |
| - void test_incompleteField_final() { |
| - CompilationUnit unit = parseCompilationUnit( |
| - r''' |
| -class C { |
| - final |
| -}''', |
| - [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); |
| - NodeList<CompilationUnitMember> declarations = unit.declarations; |
| - expect(declarations, hasLength(1)); |
| - CompilationUnitMember unitMember = declarations[0]; |
| - EngineTestCase.assertInstanceOf( |
| - (obj) => obj is ClassDeclaration, ClassDeclaration, unitMember); |
| - NodeList<ClassMember> members = (unitMember as ClassDeclaration).members; |
| - expect(members, hasLength(1)); |
| - ClassMember classMember = members[0]; |
| - EngineTestCase.assertInstanceOf( |
| - (obj) => obj is FieldDeclaration, FieldDeclaration, classMember); |
| - VariableDeclarationList fieldList = |
| - (classMember as FieldDeclaration).fields; |
| - expect(fieldList.keyword.keyword, Keyword.FINAL); |
| - NodeList<VariableDeclaration> fields = fieldList.variables; |
| - expect(fields, hasLength(1)); |
| - VariableDeclaration field = fields[0]; |
| - expect(field.name.isSynthetic, isTrue); |
| + void test_parseRelationalExpression_super() { |
| + createParser('super < y'); |
| + Expression expression = parser.parseRelationalExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<BinaryExpression>()); |
| + BinaryExpression binaryExpression = expression; |
| + expect(binaryExpression.leftOperand, isNotNull); |
| + expect(binaryExpression.operator, isNotNull); |
| + expect(binaryExpression.operator.type, TokenType.LT); |
| + expect(binaryExpression.rightOperand, isNotNull); |
| } |
| - void test_incompleteField_var() { |
| - CompilationUnit unit = parseCompilationUnit( |
| - r''' |
| -class C { |
| - var |
| -}''', |
| - [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); |
| - NodeList<CompilationUnitMember> declarations = unit.declarations; |
| - expect(declarations, hasLength(1)); |
| - CompilationUnitMember unitMember = declarations[0]; |
| - EngineTestCase.assertInstanceOf( |
| - (obj) => obj is ClassDeclaration, ClassDeclaration, unitMember); |
| - NodeList<ClassMember> members = (unitMember as ClassDeclaration).members; |
| - expect(members, hasLength(1)); |
| - ClassMember classMember = members[0]; |
| - EngineTestCase.assertInstanceOf( |
| - (obj) => obj is FieldDeclaration, FieldDeclaration, classMember); |
| - VariableDeclarationList fieldList = |
| - (classMember as FieldDeclaration).fields; |
| - expect(fieldList.keyword.keyword, Keyword.VAR); |
| - NodeList<VariableDeclaration> fields = fieldList.variables; |
| - expect(fields, hasLength(1)); |
| - VariableDeclaration field = fields[0]; |
| - expect(field.name.isSynthetic, isTrue); |
| + void test_parseRethrowExpression() { |
| + createParser('rethrow;'); |
| + RethrowExpression expression = parser.parseRethrowExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression.rethrowKeyword, isNotNull); |
| } |
| - void test_incompleteForEach() { |
| - ForStatement statement = parseStatement('for (String item i) {}', |
| - [ParserErrorCode.EXPECTED_TOKEN, ParserErrorCode.EXPECTED_TOKEN]); |
| - expect(statement, new isInstanceOf<ForStatement>()); |
| - expect(statement.toSource(), 'for (String item; i;) {}'); |
| - expect(statement.leftSeparator, isNotNull); |
| - expect(statement.leftSeparator.type, TokenType.SEMICOLON); |
| - expect(statement.rightSeparator, isNotNull); |
| - expect(statement.rightSeparator.type, TokenType.SEMICOLON); |
| + void test_parseShiftExpression_normal() { |
| + createParser('x << y'); |
| + BinaryExpression expression = parser.parseShiftExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression.leftOperand, isNotNull); |
| + expect(expression.operator, isNotNull); |
| + expect(expression.operator.type, TokenType.LT_LT); |
| + expect(expression.rightOperand, isNotNull); |
| } |
| - void test_incompleteLocalVariable_atTheEndOfBlock() { |
| - Statement statement = |
| - parseStatement('String v }', [ParserErrorCode.EXPECTED_TOKEN]); |
| - expect(statement, new isInstanceOf<VariableDeclarationStatement>()); |
| - expect(statement.toSource(), 'String v;'); |
| + void test_parseShiftExpression_super() { |
| + createParser('super << y'); |
| + BinaryExpression expression = parser.parseShiftExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression.leftOperand, isNotNull); |
| + expect(expression.operator, isNotNull); |
| + expect(expression.operator.type, TokenType.LT_LT); |
| + expect(expression.rightOperand, isNotNull); |
| } |
| - void test_incompleteLocalVariable_beforeIdentifier() { |
| - Statement statement = |
| - parseStatement('String v String v2;', [ParserErrorCode.EXPECTED_TOKEN]); |
| - expect(statement, new isInstanceOf<VariableDeclarationStatement>()); |
| - expect(statement.toSource(), 'String v;'); |
| + void test_parseSimpleIdentifier1_normalIdentifier() { |
| + // TODO(brianwilkerson) Implement tests for this method. |
| } |
| - void test_incompleteLocalVariable_beforeKeyword() { |
| - Statement statement = parseStatement( |
| - 'String v if (true) {}', [ParserErrorCode.EXPECTED_TOKEN]); |
| - expect(statement, new isInstanceOf<VariableDeclarationStatement>()); |
| - expect(statement.toSource(), 'String v;'); |
| + void test_parseSimpleIdentifier_builtInIdentifier() { |
| + String lexeme = "as"; |
| + createParser(lexeme); |
| + SimpleIdentifier identifier = parser.parseSimpleIdentifier(); |
| + expect(identifier, isNotNull); |
| + assertNoErrors(); |
| + expect(identifier.token, isNotNull); |
| + expect(identifier.name, lexeme); |
| } |
| - void test_incompleteLocalVariable_beforeNextBlock() { |
| - Statement statement = |
| - parseStatement('String v {}', [ParserErrorCode.EXPECTED_TOKEN]); |
| - expect(statement, new isInstanceOf<VariableDeclarationStatement>()); |
| - expect(statement.toSource(), 'String v;'); |
| + void test_parseSimpleIdentifier_normalIdentifier() { |
| + String lexeme = "foo"; |
| + createParser(lexeme); |
| + SimpleIdentifier identifier = parser.parseSimpleIdentifier(); |
| + expect(identifier, isNotNull); |
| + assertNoErrors(); |
| + expect(identifier.token, isNotNull); |
| + expect(identifier.name, lexeme); |
| } |
| - void test_incompleteLocalVariable_parameterizedType() { |
| - Statement statement = |
| - parseStatement('List<String> v {}', [ParserErrorCode.EXPECTED_TOKEN]); |
| - expect(statement, new isInstanceOf<VariableDeclarationStatement>()); |
| - expect(statement.toSource(), 'List<String> v;'); |
| + void test_parseStringLiteral_adjacent() { |
| + createParser("'a' 'b'"); |
| + Expression expression = parser.parseStringLiteral(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<AdjacentStrings>()); |
| + AdjacentStrings literal = expression; |
| + NodeList<StringLiteral> strings = literal.strings; |
| + expect(strings, hasLength(2)); |
| + StringLiteral firstString = strings[0]; |
| + StringLiteral secondString = strings[1]; |
| + expect((firstString as SimpleStringLiteral).value, "a"); |
| + expect((secondString as SimpleStringLiteral).value, "b"); |
| } |
| - void test_incompleteTypeArguments_field() { |
| - CompilationUnit unit = parseCompilationUnit( |
| - r''' |
| -class C { |
| - final List<int f; |
| -}''', |
| - [ParserErrorCode.EXPECTED_TOKEN]); |
| - // one class |
| - List<CompilationUnitMember> declarations = unit.declarations; |
| - expect(declarations, hasLength(1)); |
| - ClassDeclaration classDecl = declarations[0] as ClassDeclaration; |
| - // one field declaration |
| - List<ClassMember> members = classDecl.members; |
| - expect(members, hasLength(1)); |
| - FieldDeclaration fieldDecl = members[0] as FieldDeclaration; |
| - // one field |
| - VariableDeclarationList fieldList = fieldDecl.fields; |
| - List<VariableDeclaration> fields = fieldList.variables; |
| - expect(fields, hasLength(1)); |
| - VariableDeclaration field = fields[0]; |
| - expect(field.name.name, 'f'); |
| - // validate the type |
| - TypeArgumentList typeArguments = (fieldList.type as TypeName).typeArguments; |
| - expect(typeArguments.arguments, hasLength(1)); |
| - // synthetic '>' |
| - Token token = typeArguments.endToken; |
| - expect(token.type, TokenType.GT); |
| - expect(token.isSynthetic, isTrue); |
| + void test_parseStringLiteral_endsWithInterpolation() { |
| + createParser(r"'x$y'"); |
| + Expression expression = parser.parseStringLiteral(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<StringInterpolation>()); |
| + StringInterpolation interpolation = expression; |
| + expect(interpolation.elements, hasLength(3)); |
| + expect(interpolation.elements[0], new isInstanceOf<InterpolationString>()); |
| + InterpolationString element0 = interpolation.elements[0]; |
| + expect(element0.value, 'x'); |
| + expect( |
| + interpolation.elements[1], new isInstanceOf<InterpolationExpression>()); |
| + InterpolationExpression element1 = interpolation.elements[1]; |
| + expect(element1.expression, new isInstanceOf<SimpleIdentifier>()); |
| + expect(interpolation.elements[2], new isInstanceOf<InterpolationString>()); |
| + InterpolationString element2 = interpolation.elements[2]; |
| + expect(element2.value, ''); |
| } |
| - void test_incompleteTypeParameters() { |
| - CompilationUnit unit = parseCompilationUnit( |
| - r''' |
| -class C<K { |
| -}''', |
| - [ParserErrorCode.EXPECTED_TOKEN]); |
| - // one class |
| - List<CompilationUnitMember> declarations = unit.declarations; |
| - expect(declarations, hasLength(1)); |
| - ClassDeclaration classDecl = declarations[0] as ClassDeclaration; |
| - // validate the type parameters |
| - TypeParameterList typeParameters = classDecl.typeParameters; |
| - expect(typeParameters.typeParameters, hasLength(1)); |
| - // synthetic '>' |
| - Token token = typeParameters.endToken; |
| - expect(token.type, TokenType.GT); |
| - expect(token.isSynthetic, isTrue); |
| + void test_parseStringLiteral_interpolated() { |
| + createParser("'a \${b} c \$this d'"); |
| + Expression expression = parser.parseStringLiteral(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<StringInterpolation>()); |
| + StringInterpolation literal = expression; |
| + NodeList<InterpolationElement> elements = literal.elements; |
| + expect(elements, hasLength(5)); |
| + expect(elements[0] is InterpolationString, isTrue); |
| + expect(elements[1] is InterpolationExpression, isTrue); |
| + expect(elements[2] is InterpolationString, isTrue); |
| + expect(elements[3] is InterpolationExpression, isTrue); |
| + expect(elements[4] is InterpolationString, isTrue); |
| } |
| - void test_invalidFunctionBodyModifier() { |
| - parseCompilationUnit( |
| - "f() sync {}", [ParserErrorCode.MISSING_STAR_AFTER_SYNC]); |
| + void test_parseStringLiteral_multiline_encodedSpace() { |
| + createParser("'''\\x20\na'''"); |
| + Expression expression = parser.parseStringLiteral(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| + SimpleStringLiteral literal = expression; |
| + expect(literal.literal, isNotNull); |
| + expect(literal.value, " \na"); |
| } |
| - void test_isExpression_noType() { |
| - CompilationUnit unit = parseCompilationUnit( |
| - "class Bar<T extends Foo> {m(x){if (x is ) return;if (x is !)}}", [ |
| - ParserErrorCode.EXPECTED_TYPE_NAME, |
| - ParserErrorCode.EXPECTED_TYPE_NAME, |
| - ParserErrorCode.MISSING_STATEMENT |
| - ]); |
| - ClassDeclaration declaration = unit.declarations[0] as ClassDeclaration; |
| - MethodDeclaration method = declaration.members[0] as MethodDeclaration; |
| - BlockFunctionBody body = method.body as BlockFunctionBody; |
| - IfStatement ifStatement = body.block.statements[1] as IfStatement; |
| - IsExpression expression = ifStatement.condition as IsExpression; |
| - expect(expression.expression, isNotNull); |
| - expect(expression.isOperator, isNotNull); |
| - expect(expression.notOperator, isNotNull); |
| - TypeAnnotation type = expression.type; |
| - expect(type, isNotNull); |
| - expect(type is TypeName && type.name.isSynthetic, isTrue); |
| - EngineTestCase.assertInstanceOf((obj) => obj is EmptyStatement, |
| - EmptyStatement, ifStatement.thenStatement); |
| + void test_parseStringLiteral_multiline_endsWithInterpolation() { |
| + createParser(r"'''x$y'''"); |
| + Expression expression = parser.parseStringLiteral(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<StringInterpolation>()); |
| + StringInterpolation interpolation = expression; |
| + expect(interpolation.elements, hasLength(3)); |
| + expect(interpolation.elements[0], new isInstanceOf<InterpolationString>()); |
| + InterpolationString element0 = interpolation.elements[0]; |
| + expect(element0.value, 'x'); |
| + expect( |
| + interpolation.elements[1], new isInstanceOf<InterpolationExpression>()); |
| + InterpolationExpression element1 = interpolation.elements[1]; |
| + expect(element1.expression, new isInstanceOf<SimpleIdentifier>()); |
| + expect(interpolation.elements[2], new isInstanceOf<InterpolationString>()); |
| + InterpolationString element2 = interpolation.elements[2]; |
| + expect(element2.value, ''); |
| } |
| - void test_keywordInPlaceOfIdentifier() { |
| - // TODO(brianwilkerson) We could do better with this. |
| - parseCompilationUnit("do() {}", [ |
| - ParserErrorCode.EXPECTED_EXECUTABLE, |
| - ParserErrorCode.UNEXPECTED_TOKEN |
| - ]); |
| + void test_parseStringLiteral_multiline_escapedBackslash() { |
| + createParser("'''\\\\\na'''"); |
| + Expression expression = parser.parseStringLiteral(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| + SimpleStringLiteral literal = expression; |
| + expect(literal.literal, isNotNull); |
| + expect(literal.value, "\\\na"); |
| } |
| - void test_logicalAndExpression_missing_LHS() { |
| - BinaryExpression expression = |
| - parseExpression("&& y", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.leftOperand); |
| - expect(expression.leftOperand.isSynthetic, isTrue); |
| + void test_parseStringLiteral_multiline_escapedBackslash_raw() { |
| + createParser("r'''\\\\\na'''"); |
| + Expression expression = parser.parseStringLiteral(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| + SimpleStringLiteral literal = expression; |
| + expect(literal.literal, isNotNull); |
| + expect(literal.value, "\\\\\na"); |
| } |
| - void test_logicalAndExpression_missing_LHS_RHS() { |
| - BinaryExpression expression = parseExpression("&&", [ |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER |
| - ]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.leftOperand); |
| - expect(expression.leftOperand.isSynthetic, isTrue); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.rightOperand); |
| - expect(expression.rightOperand.isSynthetic, isTrue); |
| + void test_parseStringLiteral_multiline_escapedEolMarker() { |
| + createParser("'''\\\na'''"); |
| + Expression expression = parser.parseStringLiteral(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| + SimpleStringLiteral literal = expression; |
| + expect(literal.literal, isNotNull); |
| + expect(literal.value, "a"); |
| } |
| - void test_logicalAndExpression_missing_RHS() { |
| - BinaryExpression expression = |
| - parseExpression("x &&", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.rightOperand); |
| - expect(expression.rightOperand.isSynthetic, isTrue); |
| + void test_parseStringLiteral_multiline_escapedEolMarker_raw() { |
| + createParser("r'''\\\na'''"); |
| + Expression expression = parser.parseStringLiteral(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| + SimpleStringLiteral literal = expression; |
| + expect(literal.literal, isNotNull); |
| + expect(literal.value, "a"); |
| } |
| - void test_logicalAndExpression_precedence_bitwiseOr_left() { |
| - BinaryExpression expression = parseExpression("| &&", [ |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER |
| - ]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| - BinaryExpression, expression.leftOperand); |
| + void test_parseStringLiteral_multiline_escapedSpaceAndEolMarker() { |
| + createParser("'''\\ \\\na'''"); |
| + Expression expression = parser.parseStringLiteral(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| + SimpleStringLiteral literal = expression; |
| + expect(literal.literal, isNotNull); |
| + expect(literal.value, "a"); |
| } |
| - void test_logicalAndExpression_precedence_bitwiseOr_right() { |
| - BinaryExpression expression = parseExpression("&& |", [ |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER |
| - ]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| - BinaryExpression, expression.rightOperand); |
| + void test_parseStringLiteral_multiline_escapedSpaceAndEolMarker_raw() { |
| + createParser("r'''\\ \\\na'''"); |
| + Expression expression = parser.parseStringLiteral(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| + SimpleStringLiteral literal = expression; |
| + expect(literal.literal, isNotNull); |
| + expect(literal.value, "a"); |
| } |
| - void test_logicalOrExpression_missing_LHS() { |
| - BinaryExpression expression = |
| - parseExpression("|| y", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.leftOperand); |
| - expect(expression.leftOperand.isSynthetic, isTrue); |
| + void test_parseStringLiteral_multiline_escapedTab() { |
| + createParser("'''\\t\na'''"); |
| + Expression expression = parser.parseStringLiteral(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| + SimpleStringLiteral literal = expression; |
| + expect(literal.literal, isNotNull); |
| + expect(literal.value, "\t\na"); |
| } |
| - void test_logicalOrExpression_missing_LHS_RHS() { |
| - BinaryExpression expression = parseExpression("||", [ |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER |
| - ]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.leftOperand); |
| - expect(expression.leftOperand.isSynthetic, isTrue); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.rightOperand); |
| - expect(expression.rightOperand.isSynthetic, isTrue); |
| + void test_parseStringLiteral_multiline_escapedTab_raw() { |
| + createParser("r'''\\t\na'''"); |
| + Expression expression = parser.parseStringLiteral(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| + SimpleStringLiteral literal = expression; |
| + expect(literal.literal, isNotNull); |
| + expect(literal.value, "\\t\na"); |
| } |
| - void test_logicalOrExpression_missing_RHS() { |
| - BinaryExpression expression = |
| - parseExpression("x ||", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.rightOperand); |
| - expect(expression.rightOperand.isSynthetic, isTrue); |
| + void test_parseStringLiteral_multiline_quoteAfterInterpolation() { |
| + createParser(r"""'''$x'y'''"""); |
| + Expression expression = parser.parseStringLiteral(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<StringInterpolation>()); |
| + StringInterpolation interpolation = expression; |
| + expect(interpolation.elements, hasLength(3)); |
| + expect(interpolation.elements[0], new isInstanceOf<InterpolationString>()); |
| + InterpolationString element0 = interpolation.elements[0]; |
| + expect(element0.value, ''); |
| + expect( |
| + interpolation.elements[1], new isInstanceOf<InterpolationExpression>()); |
| + InterpolationExpression element1 = interpolation.elements[1]; |
| + expect(element1.expression, new isInstanceOf<SimpleIdentifier>()); |
| + expect(interpolation.elements[2], new isInstanceOf<InterpolationString>()); |
| + InterpolationString element2 = interpolation.elements[2]; |
| + expect(element2.value, "'y"); |
| } |
| - void test_logicalOrExpression_precedence_logicalAnd_left() { |
| - BinaryExpression expression = parseExpression("&& ||", [ |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER |
| - ]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| - BinaryExpression, expression.leftOperand); |
| + void test_parseStringLiteral_multiline_startsWithInterpolation() { |
| + createParser(r"'''${x}y'''"); |
| + Expression expression = parser.parseStringLiteral(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<StringInterpolation>()); |
| + StringInterpolation interpolation = expression; |
| + expect(interpolation.elements, hasLength(3)); |
| + expect(interpolation.elements[0], new isInstanceOf<InterpolationString>()); |
| + InterpolationString element0 = interpolation.elements[0]; |
| + expect(element0.value, ''); |
| + expect( |
| + interpolation.elements[1], new isInstanceOf<InterpolationExpression>()); |
| + InterpolationExpression element1 = interpolation.elements[1]; |
| + expect(element1.expression, new isInstanceOf<SimpleIdentifier>()); |
| + expect(interpolation.elements[2], new isInstanceOf<InterpolationString>()); |
| + InterpolationString element2 = interpolation.elements[2]; |
| + expect(element2.value, 'y'); |
| } |
| - void test_logicalOrExpression_precedence_logicalAnd_right() { |
| - BinaryExpression expression = parseExpression("|| &&", [ |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER |
| - ]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| - BinaryExpression, expression.rightOperand); |
| + void test_parseStringLiteral_multiline_twoSpaces() { |
| + createParser("''' \na'''"); |
| + Expression expression = parser.parseStringLiteral(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| + SimpleStringLiteral literal = expression; |
| + expect(literal.literal, isNotNull); |
| + expect(literal.value, "a"); |
| } |
| - void test_missing_commaInArgumentList() { |
| - parseExpression("f(x: 1 y: 2)", [ParserErrorCode.EXPECTED_TOKEN]); |
| + void test_parseStringLiteral_multiline_twoSpaces_raw() { |
| + createParser("r''' \na'''"); |
| + Expression expression = parser.parseStringLiteral(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| + SimpleStringLiteral literal = expression; |
| + expect(literal.literal, isNotNull); |
| + expect(literal.value, "a"); |
| } |
| - void test_missingGet() { |
| - CompilationUnit unit = parseCompilationUnit( |
| - r''' |
| -class C { |
| - int length {} |
| - void foo() {} |
| -}''', |
| - [ParserErrorCode.MISSING_GET]); |
| - expect(unit, isNotNull); |
| - ClassDeclaration classDeclaration = |
| - unit.declarations[0] as ClassDeclaration; |
| - NodeList<ClassMember> members = classDeclaration.members; |
| - expect(members, hasLength(2)); |
| - EngineTestCase.assertInstanceOf( |
| - (obj) => obj is MethodDeclaration, MethodDeclaration, members[0]); |
| - ClassMember member = members[1]; |
| - EngineTestCase.assertInstanceOf( |
| - (obj) => obj is MethodDeclaration, MethodDeclaration, member); |
| - expect((member as MethodDeclaration).name.name, "foo"); |
| + void test_parseStringLiteral_multiline_untrimmed() { |
| + createParser("''' a\nb'''"); |
| + Expression expression = parser.parseStringLiteral(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| + SimpleStringLiteral literal = expression; |
| + expect(literal.literal, isNotNull); |
| + expect(literal.value, " a\nb"); |
| } |
| - void test_missingIdentifier_afterAnnotation() { |
| - createParser('@override }'); |
| - ClassMember member = parser.parseClassMember('C'); |
| - expectNotNullIfNoErrors(member); |
| - listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_CLASS_MEMBER]); |
| - expect(member, new isInstanceOf<MethodDeclaration>()); |
| - MethodDeclaration method = member; |
| - expect(method.documentationComment, isNull); |
| - NodeList<Annotation> metadata = method.metadata; |
| - expect(metadata, hasLength(1)); |
| - expect(metadata[0].name.name, "override"); |
| + void test_parseStringLiteral_quoteAfterInterpolation() { |
| + createParser(r"""'$x"'"""); |
| + Expression expression = parser.parseStringLiteral(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<StringInterpolation>()); |
| + StringInterpolation interpolation = expression; |
| + expect(interpolation.elements, hasLength(3)); |
| + expect(interpolation.elements[0], new isInstanceOf<InterpolationString>()); |
| + InterpolationString element0 = interpolation.elements[0]; |
| + expect(element0.value, ''); |
| + expect( |
| + interpolation.elements[1], new isInstanceOf<InterpolationExpression>()); |
| + InterpolationExpression element1 = interpolation.elements[1]; |
| + expect(element1.expression, new isInstanceOf<SimpleIdentifier>()); |
| + expect(interpolation.elements[2], new isInstanceOf<InterpolationString>()); |
| + InterpolationString element2 = interpolation.elements[2]; |
| + expect(element2.value, '"'); |
| } |
| - void test_missingSemicolon_varialeDeclarationList() { |
| - void verify(CompilationUnitMember member, String expectedTypeName, |
| - String expectedName, String expectedSemicolon) { |
| - expect(member, new isInstanceOf<TopLevelVariableDeclaration>()); |
| - TopLevelVariableDeclaration declaration = member; |
| - VariableDeclarationList variableList = declaration.variables; |
| - expect(variableList, isNotNull); |
| - NodeList<VariableDeclaration> variables = variableList.variables; |
| - expect(variables, hasLength(1)); |
| - VariableDeclaration variable = variables[0]; |
| - expect(variableList.type.toString(), expectedTypeName); |
| - expect(variable.name.name, expectedName); |
| - expect(declaration.semicolon.lexeme, expectedSemicolon); |
| - } |
| - |
| - CompilationUnit unit = parseCompilationUnit('String n x = "";', [ |
| - ParserErrorCode.EXPECTED_TOKEN, |
| - ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE |
| - ]); |
| - expect(unit, isNotNull); |
| - NodeList<CompilationUnitMember> declarations = unit.declarations; |
| - expect(declarations, hasLength(2)); |
| - verify(declarations[0], 'String', 'n', ''); |
| - verify(declarations[1], 'null', 'x', ';'); |
| + void test_parseStringLiteral_single() { |
| + createParser("'a'"); |
| + Expression expression = parser.parseStringLiteral(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| + SimpleStringLiteral literal = expression; |
| + expect(literal.literal, isNotNull); |
| + expect(literal.value, "a"); |
| } |
| - void test_multiplicativeExpression_missing_LHS() { |
| - BinaryExpression expression = |
| - parseExpression("* y", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.leftOperand); |
| - expect(expression.leftOperand.isSynthetic, isTrue); |
| + void test_parseStringLiteral_startsWithInterpolation() { |
| + createParser(r"'${x}y'"); |
| + Expression expression = parser.parseStringLiteral(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<StringInterpolation>()); |
| + StringInterpolation interpolation = expression; |
| + expect(interpolation.elements, hasLength(3)); |
| + expect(interpolation.elements[0], new isInstanceOf<InterpolationString>()); |
| + InterpolationString element0 = interpolation.elements[0]; |
| + expect(element0.value, ''); |
| + expect( |
| + interpolation.elements[1], new isInstanceOf<InterpolationExpression>()); |
| + InterpolationExpression element1 = interpolation.elements[1]; |
| + expect(element1.expression, new isInstanceOf<SimpleIdentifier>()); |
| + expect(interpolation.elements[2], new isInstanceOf<InterpolationString>()); |
| + InterpolationString element2 = interpolation.elements[2]; |
| + expect(element2.value, 'y'); |
| } |
| - void test_multiplicativeExpression_missing_LHS_RHS() { |
| - BinaryExpression expression = parseExpression("*", [ |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER |
| - ]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.leftOperand); |
| - expect(expression.leftOperand.isSynthetic, isTrue); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.rightOperand); |
| - expect(expression.rightOperand.isSynthetic, isTrue); |
| + void test_parseSuperConstructorInvocation_named() { |
| + createParser('super.a()'); |
| + SuperConstructorInvocation invocation = |
| + parser.parseSuperConstructorInvocation(); |
| + expect(invocation, isNotNull); |
| + assertNoErrors(); |
| + expect(invocation.argumentList, isNotNull); |
| + expect(invocation.constructorName, isNotNull); |
| + expect(invocation.superKeyword, isNotNull); |
| + expect(invocation.period, isNotNull); |
| } |
| - void test_multiplicativeExpression_missing_RHS() { |
| - BinaryExpression expression = |
| - parseExpression("x *", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.rightOperand); |
| - expect(expression.rightOperand.isSynthetic, isTrue); |
| + void test_parseSuperConstructorInvocation_unnamed() { |
| + createParser('super()'); |
| + SuperConstructorInvocation invocation = |
| + parser.parseSuperConstructorInvocation(); |
| + expect(invocation, isNotNull); |
| + assertNoErrors(); |
| + expect(invocation.argumentList, isNotNull); |
| + expect(invocation.constructorName, isNull); |
| + expect(invocation.superKeyword, isNotNull); |
| + expect(invocation.period, isNull); |
| } |
| - void test_multiplicativeExpression_missing_RHS_super() { |
| - BinaryExpression expression = |
| - parseExpression("super *", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.rightOperand); |
| - expect(expression.rightOperand.isSynthetic, isTrue); |
| + void test_parseSymbolLiteral_builtInIdentifier() { |
| + createParser('#dynamic.static.abstract'); |
| + SymbolLiteral literal = parser.parseSymbolLiteral(); |
| + expect(literal, isNotNull); |
| + assertNoErrors(); |
| + expect(literal.poundSign, isNotNull); |
| + List<Token> components = literal.components; |
| + expect(components, hasLength(3)); |
| + expect(components[0].lexeme, "dynamic"); |
| + expect(components[1].lexeme, "static"); |
| + expect(components[2].lexeme, "abstract"); |
| } |
| - void test_multiplicativeExpression_precedence_unary_left() { |
| - BinaryExpression expression = |
| - parseExpression("-x *", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is PrefixExpression, |
| - PrefixExpression, expression.leftOperand); |
| + void test_parseSymbolLiteral_multiple() { |
| + createParser('#a.b.c'); |
| + SymbolLiteral literal = parser.parseSymbolLiteral(); |
| + expect(literal, isNotNull); |
| + assertNoErrors(); |
| + expect(literal.poundSign, isNotNull); |
| + List<Token> components = literal.components; |
| + expect(components, hasLength(3)); |
| + expect(components[0].lexeme, "a"); |
| + expect(components[1].lexeme, "b"); |
| + expect(components[2].lexeme, "c"); |
| } |
| - void test_multiplicativeExpression_precedence_unary_right() { |
| - BinaryExpression expression = |
| - parseExpression("* -y", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is PrefixExpression, |
| - PrefixExpression, expression.rightOperand); |
| + void test_parseSymbolLiteral_operator() { |
| + createParser('#=='); |
| + SymbolLiteral literal = parser.parseSymbolLiteral(); |
| + expect(literal, isNotNull); |
| + assertNoErrors(); |
| + expect(literal.poundSign, isNotNull); |
| + List<Token> components = literal.components; |
| + expect(components, hasLength(1)); |
| + expect(components[0].lexeme, "=="); |
| } |
| - void test_multiplicativeExpression_super() { |
| - BinaryExpression expression = parseExpression("super == ==", [ |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND |
| - ]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| - BinaryExpression, expression.leftOperand); |
| + void test_parseSymbolLiteral_single() { |
| + createParser('#a'); |
| + SymbolLiteral literal = parser.parseSymbolLiteral(); |
| + expect(literal, isNotNull); |
| + assertNoErrors(); |
| + expect(literal.poundSign, isNotNull); |
| + List<Token> components = literal.components; |
| + expect(components, hasLength(1)); |
| + expect(components[0].lexeme, "a"); |
| } |
| - void test_nonStringLiteralUri_import() { |
| - parseCompilationUnit("import dart:io; class C {}", |
| - [ParserErrorCode.NON_STRING_LITERAL_AS_URI]); |
| + void test_parseSymbolLiteral_void() { |
| + createParser('#void'); |
| + SymbolLiteral literal = parser.parseSymbolLiteral(); |
| + expect(literal, isNotNull); |
| + assertNoErrors(); |
| + expect(literal.poundSign, isNotNull); |
| + List<Token> components = literal.components; |
| + expect(components, hasLength(1)); |
| + expect(components[0].lexeme, "void"); |
| } |
| - void test_prefixExpression_missing_operand_minus() { |
| - PrefixExpression expression = |
| - parseExpression("-", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - EngineTestCase.assertInstanceOf( |
| - (obj) => obj is SimpleIdentifier, SimpleIdentifier, expression.operand); |
| - expect(expression.operand.isSynthetic, isTrue); |
| - expect(expression.operator.type, TokenType.MINUS); |
| + void test_parseThrowExpression() { |
| + createParser('throw x;'); |
| + Expression expression = parser.parseThrowExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<ThrowExpression>()); |
| + ThrowExpression throwExpression = expression; |
| + expect(throwExpression.throwKeyword, isNotNull); |
| + expect(throwExpression.expression, isNotNull); |
| } |
| - void test_primaryExpression_argumentDefinitionTest() { |
| - createParser('?a'); |
| - Expression expression = parser.parsePrimaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertErrorsWithCodes([ParserErrorCode.UNEXPECTED_TOKEN]); |
| - expect(expression, new isInstanceOf<SimpleIdentifier>()); |
| + void test_parseThrowExpressionWithoutCascade() { |
| + createParser('throw x;'); |
| + Expression expression = parser.parseThrowExpressionWithoutCascade(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression, new isInstanceOf<ThrowExpression>()); |
| + ThrowExpression throwExpression = expression; |
| + expect(throwExpression.throwKeyword, isNotNull); |
| + expect(throwExpression.expression, isNotNull); |
| } |
| - void test_relationalExpression_missing_LHS() { |
| - IsExpression expression = |
| - parseExpression("is y", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.expression); |
| - expect(expression.expression.isSynthetic, isTrue); |
| + void test_parseUnaryExpression_decrement_normal() { |
| + createParser('--x'); |
| + PrefixExpression expression = parser.parseUnaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression.operator, isNotNull); |
| + expect(expression.operator.type, TokenType.MINUS_MINUS); |
| + expect(expression.operand, isNotNull); |
| } |
| - void test_relationalExpression_missing_LHS_RHS() { |
| - IsExpression expression = parseExpression("is", [ |
| - ParserErrorCode.EXPECTED_TYPE_NAME, |
| - ParserErrorCode.MISSING_IDENTIFIER |
| - ]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.expression); |
| - expect(expression.expression.isSynthetic, isTrue); |
| - EngineTestCase.assertInstanceOf( |
| - (obj) => obj is TypeName, TypeName, expression.type); |
| - expect(expression.type.isSynthetic, isTrue); |
| + void test_parseUnaryExpression_decrement_super() { |
| + createParser('--super'); |
| + PrefixExpression expression = parser.parseUnaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression.operator, isNotNull); |
| + expect(expression.operator.type, TokenType.MINUS); |
| + Expression innerExpression = expression.operand; |
| + expect(innerExpression, isNotNull); |
| + expect(innerExpression is PrefixExpression, isTrue); |
| + PrefixExpression operand = innerExpression as PrefixExpression; |
| + expect(operand.operator, isNotNull); |
| + expect(operand.operator.type, TokenType.MINUS); |
| + expect(operand.operand, isNotNull); |
| } |
| - void test_relationalExpression_missing_RHS() { |
| - IsExpression expression = |
| - parseExpression("x is", [ParserErrorCode.EXPECTED_TYPE_NAME]); |
| - EngineTestCase.assertInstanceOf( |
| - (obj) => obj is TypeName, TypeName, expression.type); |
| - expect(expression.type.isSynthetic, isTrue); |
| + void test_parseUnaryExpression_decrement_super_propertyAccess() { |
| + createParser('--super.x'); |
| + PrefixExpression expression = parser.parseUnaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression.operator, isNotNull); |
| + expect(expression.operator.type, TokenType.MINUS_MINUS); |
| + expect(expression.operand, isNotNull); |
| + PropertyAccess operand = expression.operand as PropertyAccess; |
| + expect(operand.target is SuperExpression, isTrue); |
| + expect(operand.propertyName.name, "x"); |
| } |
| - void test_relationalExpression_precedence_shift_right() { |
| - IsExpression expression = parseExpression("<< is", [ |
| - ParserErrorCode.EXPECTED_TYPE_NAME, |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER |
| - ]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| - BinaryExpression, expression.expression); |
| + void test_parseUnaryExpression_decrement_super_withComment() { |
| + createParser('/* 0 */ --super'); |
| + PrefixExpression expression = parser.parseUnaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression.operator, isNotNull); |
| + expect(expression.operator.type, TokenType.MINUS); |
| + expect(expression.operator.precedingComments, isNotNull); |
| + Expression innerExpression = expression.operand; |
| + expect(innerExpression, isNotNull); |
| + expect(innerExpression is PrefixExpression, isTrue); |
| + PrefixExpression operand = innerExpression as PrefixExpression; |
| + expect(operand.operator, isNotNull); |
| + expect(operand.operator.type, TokenType.MINUS); |
| + expect(operand.operand, isNotNull); |
| } |
| - void test_shiftExpression_missing_LHS() { |
| - BinaryExpression expression = |
| - parseExpression("<< y", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.leftOperand); |
| - expect(expression.leftOperand.isSynthetic, isTrue); |
| + void test_parseUnaryExpression_increment_normal() { |
| + createParser('++x'); |
| + PrefixExpression expression = parser.parseUnaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression.operator, isNotNull); |
| + expect(expression.operator.type, TokenType.PLUS_PLUS); |
| + expect(expression.operand, isNotNull); |
| } |
| - void test_shiftExpression_missing_LHS_RHS() { |
| - BinaryExpression expression = parseExpression("<<", [ |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER |
| - ]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.leftOperand); |
| - expect(expression.leftOperand.isSynthetic, isTrue); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.rightOperand); |
| - expect(expression.rightOperand.isSynthetic, isTrue); |
| + void test_parseUnaryExpression_increment_super_index() { |
| + createParser('++super[0]'); |
| + PrefixExpression expression = parser.parseUnaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression.operator, isNotNull); |
| + expect(expression.operator.type, TokenType.PLUS_PLUS); |
| + expect(expression.operand, isNotNull); |
| + IndexExpression operand = expression.operand as IndexExpression; |
| + expect(operand.realTarget is SuperExpression, isTrue); |
| + expect(operand.index is IntegerLiteral, isTrue); |
| } |
| - void test_shiftExpression_missing_RHS() { |
| - BinaryExpression expression = |
| - parseExpression("x <<", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.rightOperand); |
| - expect(expression.rightOperand.isSynthetic, isTrue); |
| + void test_parseUnaryExpression_increment_super_propertyAccess() { |
| + createParser('++super.x'); |
| + PrefixExpression expression = parser.parseUnaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression.operator, isNotNull); |
| + expect(expression.operator.type, TokenType.PLUS_PLUS); |
| + expect(expression.operand, isNotNull); |
| + PropertyAccess operand = expression.operand as PropertyAccess; |
| + expect(operand.target is SuperExpression, isTrue); |
| + expect(operand.propertyName.name, "x"); |
| } |
| - void test_shiftExpression_missing_RHS_super() { |
| - BinaryExpression expression = |
| - parseExpression("super <<", [ParserErrorCode.MISSING_IDENTIFIER]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, expression.rightOperand); |
| - expect(expression.rightOperand.isSynthetic, isTrue); |
| + void test_parseUnaryExpression_minus_normal() { |
| + createParser('-x'); |
| + PrefixExpression expression = parser.parseUnaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression.operator, isNotNull); |
| + expect(expression.operator.type, TokenType.MINUS); |
| + expect(expression.operand, isNotNull); |
| } |
| - void test_shiftExpression_precedence_unary_left() { |
| - BinaryExpression expression = parseExpression("+ <<", [ |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER |
| - ]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| - BinaryExpression, expression.leftOperand); |
| + void test_parseUnaryExpression_minus_super() { |
| + createParser('-super'); |
| + PrefixExpression expression = parser.parseUnaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression.operator, isNotNull); |
| + expect(expression.operator.type, TokenType.MINUS); |
| + expect(expression.operand, isNotNull); |
| } |
| - void test_shiftExpression_precedence_unary_right() { |
| - BinaryExpression expression = parseExpression("<< +", [ |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER |
| - ]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| - BinaryExpression, expression.rightOperand); |
| + void test_parseUnaryExpression_not_normal() { |
| + createParser('!x'); |
| + PrefixExpression expression = parser.parseUnaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression.operator, isNotNull); |
| + expect(expression.operator.type, TokenType.BANG); |
| + expect(expression.operand, isNotNull); |
| } |
| - void test_shiftExpression_super() { |
| - BinaryExpression expression = parseExpression("super << <<", [ |
| - ParserErrorCode.MISSING_IDENTIFIER, |
| - ParserErrorCode.MISSING_IDENTIFIER |
| - ]); |
| - EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| - BinaryExpression, expression.leftOperand); |
| + void test_parseUnaryExpression_not_super() { |
| + createParser('!super'); |
| + PrefixExpression expression = parser.parseUnaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression.operator, isNotNull); |
| + expect(expression.operator.type, TokenType.BANG); |
| + expect(expression.operand, isNotNull); |
| } |
| - void test_typedef_eof() { |
| - CompilationUnit unit = parseCompilationUnit("typedef n", [ |
| - ParserErrorCode.EXPECTED_TOKEN, |
| - ParserErrorCode.MISSING_TYPEDEF_PARAMETERS |
| - ]); |
| - NodeList<CompilationUnitMember> declarations = unit.declarations; |
| - expect(declarations, hasLength(1)); |
| - CompilationUnitMember member = declarations[0]; |
| - EngineTestCase.assertInstanceOf( |
| - (obj) => obj is FunctionTypeAlias, FunctionTypeAlias, member); |
| + void test_parseUnaryExpression_tilda_normal() { |
| + createParser('~x'); |
| + PrefixExpression expression = parser.parseUnaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression.operator, isNotNull); |
| + expect(expression.operator.type, TokenType.TILDE); |
| + expect(expression.operand, isNotNull); |
| } |
| - void test_unaryPlus() { |
| - parseExpression("+2", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + void test_parseUnaryExpression_tilda_super() { |
| + createParser('~super'); |
| + PrefixExpression expression = parser.parseUnaryExpression(); |
| + expect(expression, isNotNull); |
| + assertNoErrors(); |
| + expect(expression.operator, isNotNull); |
| + expect(expression.operator.type, TokenType.TILDE); |
| + expect(expression.operand, isNotNull); |
| } |
| } |
| /** |
| - * The class `SimpleParserTest` defines parser tests that test individual parsing method. The |
| - * code fragments should be as minimal as possible in order to test the method, but should not test |
| - * the interactions between the method under test and other methods. |
| - * |
| - * More complex tests should be defined in the class [ComplexParserTest]. |
| + * Tests of the analyzer parser based on [FormalParameterParserTestMixin]. |
| */ |
| @reflectiveTest |
| -class SimpleParserTest extends ParserTestCase { |
| - void test_computeStringValue_emptyInterpolationPrefix() { |
| - expect(_computeStringValue("'''", true, false), ""); |
| +class FormalParameterParserTest extends ParserTestCase |
| + with FormalParameterParserTestMixin {} |
| + |
| +/** |
| + * The class [FormalParameterParserTestMixin] defines parser tests that test |
| + * the parsing of formal parameters. |
| + */ |
| +abstract class FormalParameterParserTestMixin |
| + implements AbstractParserTestCase { |
| + void test_parseFormalParameter_covariant_final_named() { |
| + ParameterKind kind = ParameterKind.NAMED; |
| + FormalParameter parameter = |
| + parseFormalParameter('covariant final a : null', kind); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| + DefaultFormalParameter defaultParameter = parameter; |
| + SimpleFormalParameter simpleParameter = |
| + defaultParameter.parameter as SimpleFormalParameter; |
| + expect(simpleParameter.covariantKeyword, isNotNull); |
| + expect(simpleParameter.identifier, isNotNull); |
| + expect(simpleParameter.keyword, isNotNull); |
| + expect(simpleParameter.type, isNull); |
| + expect(simpleParameter.kind, kind); |
| + expect(defaultParameter.separator, isNotNull); |
| + expect(defaultParameter.defaultValue, isNotNull); |
| + expect(defaultParameter.kind, kind); |
| } |
| - void test_computeStringValue_escape_b() { |
| - expect(_computeStringValue("'\\b'", true, true), "\b"); |
| + void test_parseFormalParameter_covariant_final_normal() { |
| + ParameterKind kind = ParameterKind.REQUIRED; |
| + FormalParameter parameter = parseFormalParameter('covariant final a', kind); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| + SimpleFormalParameter simpleParameter = parameter; |
| + expect(simpleParameter.covariantKeyword, isNotNull); |
| + expect(simpleParameter.identifier, isNotNull); |
| + expect(simpleParameter.keyword, isNotNull); |
| + expect(simpleParameter.type, isNull); |
| + expect(simpleParameter.kind, kind); |
| } |
| - void test_computeStringValue_escape_f() { |
| - expect(_computeStringValue("'\\f'", true, true), "\f"); |
| + void test_parseFormalParameter_covariant_final_positional() { |
| + ParameterKind kind = ParameterKind.POSITIONAL; |
| + FormalParameter parameter = |
| + parseFormalParameter('covariant final a = null', kind); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| + DefaultFormalParameter defaultParameter = parameter; |
| + SimpleFormalParameter simpleParameter = |
| + defaultParameter.parameter as SimpleFormalParameter; |
| + expect(simpleParameter.covariantKeyword, isNotNull); |
| + expect(simpleParameter.identifier, isNotNull); |
| + expect(simpleParameter.keyword, isNotNull); |
| + expect(simpleParameter.type, isNull); |
| + expect(simpleParameter.kind, kind); |
| + expect(defaultParameter.separator, isNotNull); |
| + expect(defaultParameter.defaultValue, isNotNull); |
| + expect(defaultParameter.kind, kind); |
| } |
| - void test_computeStringValue_escape_n() { |
| - expect(_computeStringValue("'\\n'", true, true), "\n"); |
| + void test_parseFormalParameter_covariant_final_type_named() { |
| + ParameterKind kind = ParameterKind.NAMED; |
| + FormalParameter parameter = |
| + parseFormalParameter('covariant final A a : null', kind); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| + DefaultFormalParameter defaultParameter = parameter; |
| + SimpleFormalParameter simpleParameter = |
| + defaultParameter.parameter as SimpleFormalParameter; |
| + expect(simpleParameter.covariantKeyword, isNotNull); |
| + expect(simpleParameter.identifier, isNotNull); |
| + expect(simpleParameter.keyword, isNotNull); |
| + expect(simpleParameter.type, isNotNull); |
| + expect(simpleParameter.kind, kind); |
| + expect(defaultParameter.separator, isNotNull); |
| + expect(defaultParameter.defaultValue, isNotNull); |
| + expect(defaultParameter.kind, kind); |
| } |
| - void test_computeStringValue_escape_notSpecial() { |
| - expect(_computeStringValue("'\\:'", true, true), ":"); |
| + void test_parseFormalParameter_covariant_final_type_normal() { |
| + ParameterKind kind = ParameterKind.REQUIRED; |
| + FormalParameter parameter = |
| + parseFormalParameter('covariant final A a', kind); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| + SimpleFormalParameter simpleParameter = parameter; |
| + expect(simpleParameter.covariantKeyword, isNotNull); |
| + expect(simpleParameter.identifier, isNotNull); |
| + expect(simpleParameter.keyword, isNotNull); |
| + expect(simpleParameter.type, isNotNull); |
| + expect(simpleParameter.kind, kind); |
| } |
| - void test_computeStringValue_escape_r() { |
| - expect(_computeStringValue("'\\r'", true, true), "\r"); |
| + void test_parseFormalParameter_covariant_final_type_positional() { |
| + ParameterKind kind = ParameterKind.POSITIONAL; |
| + FormalParameter parameter = |
| + parseFormalParameter('covariant final A a = null', kind); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| + DefaultFormalParameter defaultParameter = parameter; |
| + SimpleFormalParameter simpleParameter = |
| + defaultParameter.parameter as SimpleFormalParameter; |
| + expect(simpleParameter.covariantKeyword, isNotNull); |
| + expect(simpleParameter.identifier, isNotNull); |
| + expect(simpleParameter.keyword, isNotNull); |
| + expect(simpleParameter.type, isNotNull); |
| + expect(simpleParameter.kind, kind); |
| + expect(defaultParameter.separator, isNotNull); |
| + expect(defaultParameter.defaultValue, isNotNull); |
| + expect(defaultParameter.kind, kind); |
| } |
| - void test_computeStringValue_escape_t() { |
| - expect(_computeStringValue("'\\t'", true, true), "\t"); |
| + void test_parseFormalParameter_covariant_type_function() { |
| + ParameterKind kind = ParameterKind.REQUIRED; |
| + FormalParameter parameter = |
| + parseFormalParameter('covariant String Function(int) a', kind); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| + SimpleFormalParameter simpleParameter = parameter; |
| + expect(simpleParameter.covariantKeyword, isNotNull); |
| + expect(simpleParameter.identifier, isNotNull); |
| + expect(simpleParameter.keyword, isNull); |
| + expect(simpleParameter.type, new isInstanceOf<GenericFunctionType>()); |
| + expect(simpleParameter.kind, kind); |
| + } |
| + |
| + void test_parseFormalParameter_covariant_type_named() { |
| + ParameterKind kind = ParameterKind.NAMED; |
| + FormalParameter parameter = |
| + parseFormalParameter('covariant A a : null', kind); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| + DefaultFormalParameter defaultParameter = parameter; |
| + SimpleFormalParameter simpleParameter = |
| + defaultParameter.parameter as SimpleFormalParameter; |
| + expect(simpleParameter.covariantKeyword, isNotNull); |
| + expect(simpleParameter.identifier, isNotNull); |
| + expect(simpleParameter.keyword, isNull); |
| + expect(simpleParameter.type, isNotNull); |
| + expect(simpleParameter.kind, kind); |
| + expect(defaultParameter.separator, isNotNull); |
| + expect(defaultParameter.defaultValue, isNotNull); |
| + expect(defaultParameter.kind, kind); |
| } |
| - void test_computeStringValue_escape_u_fixed() { |
| - expect(_computeStringValue("'\\u4321'", true, true), "\u4321"); |
| + void test_parseFormalParameter_covariant_type_normal() { |
| + ParameterKind kind = ParameterKind.REQUIRED; |
| + FormalParameter parameter = |
| + parseFormalParameter('covariant A<B<C>> a', kind); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| + SimpleFormalParameter simpleParameter = parameter; |
| + expect(simpleParameter.covariantKeyword, isNotNull); |
| + expect(simpleParameter.identifier, isNotNull); |
| + expect(simpleParameter.keyword, isNull); |
| + expect(simpleParameter.type, isNotNull); |
| + expect(simpleParameter.kind, kind); |
| } |
| - void test_computeStringValue_escape_u_variable() { |
| - expect(_computeStringValue("'\\u{123}'", true, true), "\u0123"); |
| + void test_parseFormalParameter_covariant_type_positional() { |
| + ParameterKind kind = ParameterKind.POSITIONAL; |
| + FormalParameter parameter = |
| + parseFormalParameter('covariant A a = null', kind); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| + DefaultFormalParameter defaultParameter = parameter; |
| + SimpleFormalParameter simpleParameter = |
| + defaultParameter.parameter as SimpleFormalParameter; |
| + expect(simpleParameter.covariantKeyword, isNotNull); |
| + expect(simpleParameter.identifier, isNotNull); |
| + expect(simpleParameter.keyword, isNull); |
| + expect(simpleParameter.type, isNotNull); |
| + expect(simpleParameter.kind, kind); |
| + expect(defaultParameter.separator, isNotNull); |
| + expect(defaultParameter.defaultValue, isNotNull); |
| + expect(defaultParameter.kind, kind); |
| } |
| - void test_computeStringValue_escape_v() { |
| - expect(_computeStringValue("'\\v'", true, true), "\u000B"); |
| + void test_parseFormalParameter_covariant_var_named() { |
| + ParameterKind kind = ParameterKind.NAMED; |
| + FormalParameter parameter = |
| + parseFormalParameter('covariant var a : null', kind); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| + DefaultFormalParameter defaultParameter = parameter; |
| + SimpleFormalParameter simpleParameter = |
| + defaultParameter.parameter as SimpleFormalParameter; |
| + expect(simpleParameter.covariantKeyword, isNotNull); |
| + expect(simpleParameter.identifier, isNotNull); |
| + expect(simpleParameter.keyword, isNotNull); |
| + expect(simpleParameter.type, isNull); |
| + expect(simpleParameter.kind, kind); |
| + expect(defaultParameter.separator, isNotNull); |
| + expect(defaultParameter.defaultValue, isNotNull); |
| + expect(defaultParameter.kind, kind); |
| } |
| - void test_computeStringValue_escape_x() { |
| - expect(_computeStringValue("'\\xFF'", true, true), "\u00FF"); |
| + void test_parseFormalParameter_covariant_var_normal() { |
| + ParameterKind kind = ParameterKind.REQUIRED; |
| + FormalParameter parameter = parseFormalParameter('covariant var a', kind); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| + SimpleFormalParameter simpleParameter = parameter; |
| + expect(simpleParameter.covariantKeyword, isNotNull); |
| + expect(simpleParameter.identifier, isNotNull); |
| + expect(simpleParameter.keyword, isNotNull); |
| + expect(simpleParameter.type, isNull); |
| + expect(simpleParameter.kind, kind); |
| } |
| - void test_computeStringValue_noEscape_single() { |
| - expect(_computeStringValue("'text'", true, true), "text"); |
| + void test_parseFormalParameter_covariant_var_positional() { |
| + ParameterKind kind = ParameterKind.POSITIONAL; |
| + FormalParameter parameter = |
| + parseFormalParameter('covariant var a = null', kind); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| + DefaultFormalParameter defaultParameter = parameter; |
| + SimpleFormalParameter simpleParameter = |
| + defaultParameter.parameter as SimpleFormalParameter; |
| + expect(simpleParameter.covariantKeyword, isNotNull); |
| + expect(simpleParameter.identifier, isNotNull); |
| + expect(simpleParameter.keyword, isNotNull); |
| + expect(simpleParameter.type, isNull); |
| + expect(simpleParameter.kind, kind); |
| + expect(defaultParameter.separator, isNotNull); |
| + expect(defaultParameter.defaultValue, isNotNull); |
| + expect(defaultParameter.kind, kind); |
| } |
| - void test_computeStringValue_noEscape_triple() { |
| - expect(_computeStringValue("'''text'''", true, true), "text"); |
| + void test_parseFormalParameter_final_named() { |
| + ParameterKind kind = ParameterKind.NAMED; |
| + FormalParameter parameter = parseFormalParameter('final a : null', kind); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| + DefaultFormalParameter defaultParameter = parameter; |
| + SimpleFormalParameter simpleParameter = |
| + defaultParameter.parameter as SimpleFormalParameter; |
| + expect(simpleParameter.covariantKeyword, isNull); |
| + expect(simpleParameter.identifier, isNotNull); |
| + expect(simpleParameter.keyword, isNotNull); |
| + expect(simpleParameter.type, isNull); |
| + expect(simpleParameter.kind, kind); |
| + expect(defaultParameter.separator, isNotNull); |
| + expect(defaultParameter.defaultValue, isNotNull); |
| + expect(defaultParameter.kind, kind); |
| } |
| - void test_computeStringValue_raw_single() { |
| - expect(_computeStringValue("r'text'", true, true), "text"); |
| + void test_parseFormalParameter_final_normal() { |
| + ParameterKind kind = ParameterKind.REQUIRED; |
| + FormalParameter parameter = parseFormalParameter('final a', kind); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| + SimpleFormalParameter simpleParameter = parameter; |
| + expect(simpleParameter.covariantKeyword, isNull); |
| + expect(simpleParameter.identifier, isNotNull); |
| + expect(simpleParameter.keyword, isNotNull); |
| + expect(simpleParameter.type, isNull); |
| + expect(simpleParameter.kind, kind); |
| } |
| - void test_computeStringValue_raw_triple() { |
| - expect(_computeStringValue("r'''text'''", true, true), "text"); |
| + void test_parseFormalParameter_final_positional() { |
| + ParameterKind kind = ParameterKind.POSITIONAL; |
| + FormalParameter parameter = parseFormalParameter('final a = null', kind); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| + DefaultFormalParameter defaultParameter = parameter; |
| + SimpleFormalParameter simpleParameter = |
| + defaultParameter.parameter as SimpleFormalParameter; |
| + expect(simpleParameter.covariantKeyword, isNull); |
| + expect(simpleParameter.identifier, isNotNull); |
| + expect(simpleParameter.keyword, isNotNull); |
| + expect(simpleParameter.type, isNull); |
| + expect(simpleParameter.kind, kind); |
| + expect(defaultParameter.separator, isNotNull); |
| + expect(defaultParameter.defaultValue, isNotNull); |
| + expect(defaultParameter.kind, kind); |
| } |
| - void test_computeStringValue_raw_withEscape() { |
| - expect(_computeStringValue("r'two\\nlines'", true, true), "two\\nlines"); |
| + void test_parseFormalParameter_final_type_named() { |
| + ParameterKind kind = ParameterKind.NAMED; |
| + FormalParameter parameter = parseFormalParameter('final A a : null', kind); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| + DefaultFormalParameter defaultParameter = parameter; |
| + SimpleFormalParameter simpleParameter = |
| + defaultParameter.parameter as SimpleFormalParameter; |
| + expect(simpleParameter.covariantKeyword, isNull); |
| + expect(simpleParameter.identifier, isNotNull); |
| + expect(simpleParameter.keyword, isNotNull); |
| + expect(simpleParameter.type, isNotNull); |
| + expect(simpleParameter.kind, kind); |
| + expect(defaultParameter.separator, isNotNull); |
| + expect(defaultParameter.defaultValue, isNotNull); |
| + expect(defaultParameter.kind, kind); |
| } |
| - void test_computeStringValue_triple_internalQuote_first_empty() { |
| - expect(_computeStringValue("''''", true, false), "'"); |
| + void test_parseFormalParameter_final_type_normal() { |
| + ParameterKind kind = ParameterKind.REQUIRED; |
| + FormalParameter parameter = parseFormalParameter('final A a', kind); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| + SimpleFormalParameter simpleParameter = parameter; |
| + expect(simpleParameter.covariantKeyword, isNull); |
| + expect(simpleParameter.identifier, isNotNull); |
| + expect(simpleParameter.keyword, isNotNull); |
| + expect(simpleParameter.type, isNotNull); |
| + expect(simpleParameter.kind, kind); |
| } |
| - void test_computeStringValue_triple_internalQuote_first_nonEmpty() { |
| - expect(_computeStringValue("''''text", true, false), "'text"); |
| + void test_parseFormalParameter_final_type_positional() { |
| + ParameterKind kind = ParameterKind.POSITIONAL; |
| + FormalParameter parameter = parseFormalParameter('final A a = null', kind); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| + DefaultFormalParameter defaultParameter = parameter; |
| + SimpleFormalParameter simpleParameter = |
| + defaultParameter.parameter as SimpleFormalParameter; |
| + expect(simpleParameter.covariantKeyword, isNull); |
| + expect(simpleParameter.identifier, isNotNull); |
| + expect(simpleParameter.keyword, isNotNull); |
| + expect(simpleParameter.type, isNotNull); |
| + expect(simpleParameter.kind, kind); |
| + expect(defaultParameter.separator, isNotNull); |
| + expect(defaultParameter.defaultValue, isNotNull); |
| + expect(defaultParameter.kind, kind); |
| } |
| - void test_computeStringValue_triple_internalQuote_last_empty() { |
| - expect(_computeStringValue("'''", false, true), ""); |
| + void test_parseFormalParameter_type_function() { |
| + ParameterKind kind = ParameterKind.REQUIRED; |
| + FormalParameter parameter = |
| + parseFormalParameter('String Function(int) a', kind); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| + SimpleFormalParameter simpleParameter = parameter; |
| + expect(simpleParameter.covariantKeyword, isNull); |
| + expect(simpleParameter.identifier, isNotNull); |
| + expect(simpleParameter.keyword, isNull); |
| + expect(simpleParameter.type, new isInstanceOf<GenericFunctionType>()); |
| + expect(simpleParameter.kind, kind); |
| } |
| - void test_computeStringValue_triple_internalQuote_last_nonEmpty() { |
| - expect(_computeStringValue("text'''", false, true), "text"); |
| + void test_parseFormalParameter_type_named() { |
| + ParameterKind kind = ParameterKind.NAMED; |
| + FormalParameter parameter = parseFormalParameter('A a : null', kind); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| + DefaultFormalParameter defaultParameter = parameter; |
| + SimpleFormalParameter simpleParameter = |
| + defaultParameter.parameter as SimpleFormalParameter; |
| + expect(simpleParameter.covariantKeyword, isNull); |
| + expect(simpleParameter.identifier, isNotNull); |
| + expect(simpleParameter.keyword, isNull); |
| + expect(simpleParameter.type, isNotNull); |
| + expect(simpleParameter.kind, kind); |
| + expect(defaultParameter.separator, isNotNull); |
| + expect(defaultParameter.defaultValue, isNotNull); |
| + expect(defaultParameter.kind, kind); |
| } |
| - void test_createSyntheticIdentifier() { |
| - createParser(''); |
| - SimpleIdentifier identifier = parser.createSyntheticIdentifier(); |
| - expectNotNullIfNoErrors(identifier); |
| - expect(identifier.isSynthetic, isTrue); |
| + void test_parseFormalParameter_type_normal() { |
| + ParameterKind kind = ParameterKind.REQUIRED; |
| + FormalParameter parameter = parseFormalParameter('A a', kind); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| + SimpleFormalParameter simpleParameter = parameter; |
| + expect(simpleParameter.covariantKeyword, isNull); |
| + expect(simpleParameter.identifier, isNotNull); |
| + expect(simpleParameter.keyword, isNull); |
| + expect(simpleParameter.type, isNotNull); |
| + expect(simpleParameter.kind, kind); |
| } |
| - void test_createSyntheticStringLiteral() { |
| - createParser(''); |
| - SimpleStringLiteral literal = parser.createSyntheticStringLiteral(); |
| - expectNotNullIfNoErrors(literal); |
| - expect(literal.isSynthetic, isTrue); |
| + void test_parseFormalParameter_type_positional() { |
| + ParameterKind kind = ParameterKind.POSITIONAL; |
| + FormalParameter parameter = parseFormalParameter('A a = null', kind); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| + DefaultFormalParameter defaultParameter = parameter; |
| + SimpleFormalParameter simpleParameter = |
| + defaultParameter.parameter as SimpleFormalParameter; |
| + expect(simpleParameter.covariantKeyword, isNull); |
| + expect(simpleParameter.identifier, isNotNull); |
| + expect(simpleParameter.keyword, isNull); |
| + expect(simpleParameter.type, isNotNull); |
| + expect(simpleParameter.kind, kind); |
| + expect(defaultParameter.separator, isNotNull); |
| + expect(defaultParameter.defaultValue, isNotNull); |
| + expect(defaultParameter.kind, kind); |
| } |
| - void test_isFunctionDeclaration_nameButNoReturn_block() { |
| - expect(_isFunctionDeclaration("f() {}"), isTrue); |
| + void test_parseFormalParameter_var_named() { |
| + ParameterKind kind = ParameterKind.NAMED; |
| + FormalParameter parameter = parseFormalParameter('var a : null', kind); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| + DefaultFormalParameter defaultParameter = parameter; |
| + SimpleFormalParameter simpleParameter = |
| + defaultParameter.parameter as SimpleFormalParameter; |
| + expect(simpleParameter.covariantKeyword, isNull); |
| + expect(simpleParameter.identifier, isNotNull); |
| + expect(simpleParameter.keyword, isNotNull); |
| + expect(simpleParameter.type, isNull); |
| + expect(simpleParameter.kind, kind); |
| + expect(defaultParameter.separator, isNotNull); |
| + expect(defaultParameter.defaultValue, isNotNull); |
| + expect(defaultParameter.kind, kind); |
| } |
| - void test_isFunctionDeclaration_nameButNoReturn_expression() { |
| - expect(_isFunctionDeclaration("f() => e"), isTrue); |
| + void test_parseFormalParameter_var_normal() { |
| + ParameterKind kind = ParameterKind.REQUIRED; |
| + FormalParameter parameter = parseFormalParameter('var a', kind); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| + SimpleFormalParameter simpleParameter = parameter; |
| + expect(simpleParameter.covariantKeyword, isNull); |
| + expect(simpleParameter.identifier, isNotNull); |
| + expect(simpleParameter.keyword, isNotNull); |
| + expect(simpleParameter.type, isNull); |
| + expect(simpleParameter.kind, kind); |
| } |
| - void test_isFunctionDeclaration_nameButNoReturn_typeParameters_block() { |
| - expect(_isFunctionDeclaration("f<E>() {}"), isTrue); |
| + void test_parseFormalParameter_var_positional() { |
| + ParameterKind kind = ParameterKind.POSITIONAL; |
| + FormalParameter parameter = parseFormalParameter('var a = null', kind); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| + DefaultFormalParameter defaultParameter = parameter; |
| + SimpleFormalParameter simpleParameter = |
| + defaultParameter.parameter as SimpleFormalParameter; |
| + expect(simpleParameter.covariantKeyword, isNull); |
| + expect(simpleParameter.identifier, isNotNull); |
| + expect(simpleParameter.keyword, isNotNull); |
| + expect(simpleParameter.type, isNull); |
| + expect(simpleParameter.kind, kind); |
| + expect(defaultParameter.separator, isNotNull); |
| + expect(defaultParameter.defaultValue, isNotNull); |
| + expect(defaultParameter.kind, kind); |
| } |
| - void test_isFunctionDeclaration_nameButNoReturn_typeParameters_expression() { |
| - expect(_isFunctionDeclaration("f<E>() => e"), isTrue); |
| + void test_parseFormalParameterList_empty() { |
| + FormalParameterList list = parseFormalParameterList('()'); |
| + expect(list, isNotNull); |
| + assertNoErrors(); |
| + expect(list.leftParenthesis, isNotNull); |
| + expect(list.leftDelimiter, isNull); |
| + expect(list.parameters, hasLength(0)); |
| + expect(list.rightDelimiter, isNull); |
| + expect(list.rightParenthesis, isNotNull); |
| } |
| - void test_isFunctionDeclaration_normalReturn_block() { |
| - expect(_isFunctionDeclaration("C f() {}"), isTrue); |
| + void test_parseFormalParameterList_named_multiple() { |
| + FormalParameterList list = |
| + parseFormalParameterList('({A a : 1, B b, C c : 3})'); |
| + expect(list, isNotNull); |
| + assertNoErrors(); |
| + expect(list.leftParenthesis, isNotNull); |
| + expect(list.leftDelimiter, isNotNull); |
| + expect(list.parameters, hasLength(3)); |
| + expect(list.rightDelimiter, isNotNull); |
| + expect(list.rightParenthesis, isNotNull); |
| } |
| - void test_isFunctionDeclaration_normalReturn_expression() { |
| - expect(_isFunctionDeclaration("C f() => e"), isTrue); |
| + void test_parseFormalParameterList_named_single() { |
| + FormalParameterList list = parseFormalParameterList('({A a})'); |
| + expect(list, isNotNull); |
| + assertNoErrors(); |
| + expect(list.leftParenthesis, isNotNull); |
| + expect(list.leftDelimiter, isNotNull); |
| + expect(list.parameters, hasLength(1)); |
| + expect(list.rightDelimiter, isNotNull); |
| + expect(list.rightParenthesis, isNotNull); |
| } |
| - void test_isFunctionDeclaration_normalReturn_typeParameters_block() { |
| - expect(_isFunctionDeclaration("C f<E>() {}"), isTrue); |
| + void test_parseFormalParameterList_named_trailing_comma() { |
| + FormalParameterList list = parseFormalParameterList('(A a, {B b,})'); |
| + expect(list, isNotNull); |
| + assertNoErrors(); |
| + expect(list.leftParenthesis, isNotNull); |
| + expect(list.leftDelimiter, isNotNull); |
| + expect(list.parameters, hasLength(2)); |
| + expect(list.rightDelimiter, isNotNull); |
| + expect(list.rightParenthesis, isNotNull); |
| } |
| - void test_isFunctionDeclaration_normalReturn_typeParameters_expression() { |
| - expect(_isFunctionDeclaration("C f<E>() => e"), isTrue); |
| + void test_parseFormalParameterList_normal_multiple() { |
| + FormalParameterList list = parseFormalParameterList('(A a, B b, C c)'); |
| + expect(list, isNotNull); |
| + assertNoErrors(); |
| + expect(list.leftParenthesis, isNotNull); |
| + expect(list.leftDelimiter, isNull); |
| + expect(list.parameters, hasLength(3)); |
| + expect(list.rightDelimiter, isNull); |
| + expect(list.rightParenthesis, isNotNull); |
| } |
| - void test_isFunctionDeclaration_voidReturn_block() { |
| - expect(_isFunctionDeclaration("void f() {}"), isTrue); |
| + void test_parseFormalParameterList_normal_named() { |
| + FormalParameterList list = parseFormalParameterList('(A a, {B b})'); |
| + expect(list, isNotNull); |
| + assertNoErrors(); |
| + expect(list.leftParenthesis, isNotNull); |
| + expect(list.leftDelimiter, isNotNull); |
| + expect(list.parameters, hasLength(2)); |
| + expect(list.rightDelimiter, isNotNull); |
| + expect(list.rightParenthesis, isNotNull); |
| } |
| - void test_isFunctionDeclaration_voidReturn_expression() { |
| - expect(_isFunctionDeclaration("void f() => e"), isTrue); |
| - } |
| + void test_parseFormalParameterList_normal_named_inFunctionType() { |
| + FormalParameterList list = |
| + parseFormalParameterList('(A, {B b})', inFunctionType: true); |
| + expect(list, isNotNull); |
| + assertNoErrors(); |
| + expect(list.leftParenthesis, isNotNull); |
| + expect(list.leftDelimiter, isNotNull); |
| + expect(list.rightDelimiter, isNotNull); |
| + expect(list.rightParenthesis, isNotNull); |
| + NodeList<FormalParameter> parameters = list.parameters; |
| + expect(parameters, hasLength(2)); |
| - void test_isFunctionDeclaration_voidReturn_typeParameters_block() { |
| - expect(_isFunctionDeclaration("void f<E>() {}"), isTrue); |
| - } |
| + expect(parameters[0], new isInstanceOf<SimpleFormalParameter>()); |
| + SimpleFormalParameter required = parameters[0]; |
| + expect(required.identifier, isNull); |
| + expect(required.type, new isInstanceOf<TypeName>()); |
| + expect((required.type as TypeName).name.name, 'A'); |
| - void test_isFunctionDeclaration_voidReturn_typeParameters_expression() { |
| - expect(_isFunctionDeclaration("void f<E>() => e"), isTrue); |
| + expect(parameters[1], new isInstanceOf<DefaultFormalParameter>()); |
| + DefaultFormalParameter named = parameters[1]; |
| + expect(named.identifier, isNotNull); |
| + expect(named.parameter, new isInstanceOf<SimpleFormalParameter>()); |
| + SimpleFormalParameter simple = named.parameter; |
| + expect(simple.type, new isInstanceOf<TypeName>()); |
| + expect((simple.type as TypeName).name.name, 'B'); |
| } |
| - void test_isFunctionExpression_false_noBody() { |
| - expect(_isFunctionExpression("f();"), isFalse); |
| + void test_parseFormalParameterList_normal_positional() { |
| + FormalParameterList list = parseFormalParameterList('(A a, [B b])'); |
| + expect(list, isNotNull); |
| + assertNoErrors(); |
| + expect(list.leftParenthesis, isNotNull); |
| + expect(list.leftDelimiter, isNotNull); |
| + expect(list.parameters, hasLength(2)); |
| + expect(list.rightDelimiter, isNotNull); |
| + expect(list.rightParenthesis, isNotNull); |
| } |
| - void test_isFunctionExpression_false_notParameters() { |
| - expect(_isFunctionExpression("(a + b) {"), isFalse); |
| + void test_parseFormalParameterList_normal_single() { |
| + FormalParameterList list = parseFormalParameterList('(A a)'); |
| + expect(list, isNotNull); |
| + assertNoErrors(); |
| + expect(list.leftParenthesis, isNotNull); |
| + expect(list.leftDelimiter, isNull); |
| + expect(list.parameters, hasLength(1)); |
| + expect(list.rightDelimiter, isNull); |
| + expect(list.rightParenthesis, isNotNull); |
| } |
| - void test_isFunctionExpression_noParameters_block() { |
| - expect(_isFunctionExpression("() {}"), isTrue); |
| + void test_parseFormalParameterList_normal_single_Function() { |
| + FormalParameterList list = parseFormalParameterList('(Function f)'); |
| + expect(list, isNotNull); |
| + assertNoErrors(); |
| + expect(list.leftParenthesis, isNotNull); |
| + expect(list.leftDelimiter, isNull); |
| + expect(list.parameters, hasLength(1)); |
| + expect(list.rightDelimiter, isNull); |
| + expect(list.rightParenthesis, isNotNull); |
| } |
| - void test_isFunctionExpression_noParameters_expression() { |
| - expect(_isFunctionExpression("() => e"), isTrue); |
| + void test_parseFormalParameterList_normal_single_trailing_comma() { |
| + FormalParameterList list = parseFormalParameterList('(A a,)'); |
| + expect(list, isNotNull); |
| + assertNoErrors(); |
| + expect(list.leftParenthesis, isNotNull); |
| + expect(list.leftDelimiter, isNull); |
| + expect(list.parameters, hasLength(1)); |
| + expect(list.rightDelimiter, isNull); |
| + expect(list.rightParenthesis, isNotNull); |
| } |
| - void test_isFunctionExpression_noParameters_typeParameters_block() { |
| - expect(_isFunctionExpression("<E>() {}"), isTrue); |
| + void test_parseFormalParameterList_positional_multiple() { |
| + FormalParameterList list = |
| + parseFormalParameterList('([A a = null, B b, C c = null])'); |
| + expect(list, isNotNull); |
| + assertNoErrors(); |
| + expect(list.leftParenthesis, isNotNull); |
| + expect(list.leftDelimiter, isNotNull); |
| + expect(list.parameters, hasLength(3)); |
| + expect(list.rightDelimiter, isNotNull); |
| + expect(list.rightParenthesis, isNotNull); |
| } |
| - void test_isFunctionExpression_noParameters_typeParameters_expression() { |
| - expect(_isFunctionExpression("<E>() => e"), isTrue); |
| + void test_parseFormalParameterList_positional_single() { |
| + FormalParameterList list = parseFormalParameterList('([A a = null])'); |
| + expect(list, isNotNull); |
| + assertNoErrors(); |
| + expect(list.leftParenthesis, isNotNull); |
| + expect(list.leftDelimiter, isNotNull); |
| + expect(list.parameters, hasLength(1)); |
| + expect(list.rightDelimiter, isNotNull); |
| + expect(list.rightParenthesis, isNotNull); |
| } |
| - void test_isFunctionExpression_parameter_final() { |
| - expect(_isFunctionExpression("(final a) {}"), isTrue); |
| - expect(_isFunctionExpression("(final a, b) {}"), isTrue); |
| - expect(_isFunctionExpression("(final a, final b) {}"), isTrue); |
| + void test_parseFormalParameterList_positional_trailing_comma() { |
| + FormalParameterList list = parseFormalParameterList('(A a, [B b,])'); |
| + expect(list, isNotNull); |
| + assertNoErrors(); |
| + expect(list.leftParenthesis, isNotNull); |
| + expect(list.leftDelimiter, isNotNull); |
| + expect(list.parameters, hasLength(2)); |
| + expect(list.rightDelimiter, isNotNull); |
| + expect(list.rightParenthesis, isNotNull); |
| } |
| - void test_isFunctionExpression_parameter_final_typed() { |
| - expect(_isFunctionExpression("(final int a) {}"), isTrue); |
| - expect(_isFunctionExpression("(final prefix.List a) {}"), isTrue); |
| - expect(_isFunctionExpression("(final List<int> a) {}"), isTrue); |
| - expect(_isFunctionExpression("(final prefix.List<int> a) {}"), isTrue); |
| + void test_parseFormalParameterList_prefixedType() { |
| + FormalParameterList list = parseFormalParameterList('(io.File f)'); |
| + expect(list, isNotNull); |
| + assertNoErrors(); |
| + expect(list.leftParenthesis, isNotNull); |
| + expect(list.leftDelimiter, isNull); |
| + expect(list.parameters, hasLength(1)); |
| + expect(list.parameters[0].toSource(), 'io.File f'); |
| + expect(list.rightDelimiter, isNull); |
| + expect(list.rightParenthesis, isNotNull); |
| } |
| - void test_isFunctionExpression_parameter_multiple() { |
| - expect(_isFunctionExpression("(a, b) {}"), isTrue); |
| + void test_parseFormalParameterList_prefixedType_partial() { |
| + FormalParameterList list = parseFormalParameterList('(io.)', errorCodes: [ |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER |
| + ]); |
| + expect(list, isNotNull); |
| + expect(list.leftParenthesis, isNotNull); |
| + expect(list.leftDelimiter, isNull); |
| + expect(list.parameters, hasLength(1)); |
| + expect(list.parameters[0].toSource(), 'io. '); |
| + expect(list.rightDelimiter, isNull); |
| + expect(list.rightParenthesis, isNotNull); |
| } |
| - void test_isFunctionExpression_parameter_named() { |
| - expect(_isFunctionExpression("({a}) {}"), isTrue); |
| + void test_parseFormalParameterList_prefixedType_partial2() { |
| + FormalParameterList list = parseFormalParameterList('(io.,a)', errorCodes: [ |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER |
| + ]); |
| + expect(list, isNotNull); |
| + expect(list.leftParenthesis, isNotNull); |
| + expect(list.leftDelimiter, isNull); |
| + expect(list.parameters, hasLength(2)); |
| + expect(list.parameters[0].toSource(), 'io. '); |
| + expect(list.parameters[1].toSource(), 'a'); |
| + expect(list.rightDelimiter, isNull); |
| + expect(list.rightParenthesis, isNotNull); |
| } |
| - void test_isFunctionExpression_parameter_optional() { |
| - expect(_isFunctionExpression("([a]) {}"), isTrue); |
| + void test_parseNormalFormalParameter_field_const_noType() { |
| + NormalFormalParameter parameter = |
| + parseNormalFormalParameter('const this.a'); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<FieldFormalParameter>()); |
| + FieldFormalParameter fieldParameter = parameter; |
| + expect(fieldParameter.keyword, isNotNull); |
| + expect(fieldParameter.type, isNull); |
| + expect(fieldParameter.identifier, isNotNull); |
| + expect(fieldParameter.parameters, isNull); |
| } |
| - void test_isFunctionExpression_parameter_single() { |
| - expect(_isFunctionExpression("(a) {}"), isTrue); |
| + void test_parseNormalFormalParameter_field_const_type() { |
| + NormalFormalParameter parameter = |
| + parseNormalFormalParameter('const A this.a'); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<FieldFormalParameter>()); |
| + FieldFormalParameter fieldParameter = parameter; |
| + expect(fieldParameter.keyword, isNotNull); |
| + expect(fieldParameter.type, isNotNull); |
| + expect(fieldParameter.identifier, isNotNull); |
| + expect(fieldParameter.parameters, isNull); |
| } |
| - void test_isFunctionExpression_parameter_typed() { |
| - expect(_isFunctionExpression("(int a, int b) {}"), isTrue); |
| + void test_parseNormalFormalParameter_field_final_noType() { |
| + NormalFormalParameter parameter = |
| + parseNormalFormalParameter('final this.a'); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<FieldFormalParameter>()); |
| + FieldFormalParameter fieldParameter = parameter; |
| + expect(fieldParameter.keyword, isNotNull); |
| + expect(fieldParameter.type, isNull); |
| + expect(fieldParameter.identifier, isNotNull); |
| + expect(fieldParameter.parameters, isNull); |
| } |
| - void test_isInitializedVariableDeclaration_assignment() { |
| - expect(_isInitializedVariableDeclaration("a = null;"), isFalse); |
| + void test_parseNormalFormalParameter_field_final_type() { |
| + NormalFormalParameter parameter = |
| + parseNormalFormalParameter('final A this.a'); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<FieldFormalParameter>()); |
| + FieldFormalParameter fieldParameter = parameter; |
| + expect(fieldParameter.keyword, isNotNull); |
| + expect(fieldParameter.type, isNotNull); |
| + expect(fieldParameter.identifier, isNotNull); |
| + expect(fieldParameter.parameters, isNull); |
| } |
| - void test_isInitializedVariableDeclaration_comparison() { |
| - expect(_isInitializedVariableDeclaration("a < 0;"), isFalse); |
| + void test_parseNormalFormalParameter_field_function_nested() { |
| + NormalFormalParameter parameter = parseNormalFormalParameter('this.a(B b)'); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<FieldFormalParameter>()); |
| + FieldFormalParameter fieldParameter = parameter; |
| + expect(fieldParameter.keyword, isNull); |
| + expect(fieldParameter.type, isNull); |
| + expect(fieldParameter.identifier, isNotNull); |
| + FormalParameterList parameterList = fieldParameter.parameters; |
| + expect(parameterList, isNotNull); |
| + expect(parameterList.parameters, hasLength(1)); |
| } |
| - void test_isInitializedVariableDeclaration_conditional() { |
| - expect(_isInitializedVariableDeclaration("a == null ? init() : update();"), |
| - isFalse); |
| + void test_parseNormalFormalParameter_field_function_noNested() { |
| + NormalFormalParameter parameter = parseNormalFormalParameter('this.a()'); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<FieldFormalParameter>()); |
| + FieldFormalParameter fieldParameter = parameter; |
| + expect(fieldParameter.keyword, isNull); |
| + expect(fieldParameter.type, isNull); |
| + expect(fieldParameter.identifier, isNotNull); |
| + FormalParameterList parameterList = fieldParameter.parameters; |
| + expect(parameterList, isNotNull); |
| + expect(parameterList.parameters, hasLength(0)); |
| } |
| - void test_isInitializedVariableDeclaration_const_noType_initialized() { |
| - expect(_isInitializedVariableDeclaration("const a = 0;"), isTrue); |
| + void test_parseNormalFormalParameter_field_noType() { |
| + NormalFormalParameter parameter = parseNormalFormalParameter('this.a'); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<FieldFormalParameter>()); |
| + FieldFormalParameter fieldParameter = parameter; |
| + expect(fieldParameter.keyword, isNull); |
| + expect(fieldParameter.type, isNull); |
| + expect(fieldParameter.identifier, isNotNull); |
| + expect(fieldParameter.parameters, isNull); |
| } |
| - void test_isInitializedVariableDeclaration_const_noType_uninitialized() { |
| - expect(_isInitializedVariableDeclaration("const a;"), isTrue); |
| + void test_parseNormalFormalParameter_field_type() { |
| + NormalFormalParameter parameter = parseNormalFormalParameter('A this.a'); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<FieldFormalParameter>()); |
| + FieldFormalParameter fieldParameter = parameter; |
| + expect(fieldParameter.keyword, isNull); |
| + expect(fieldParameter.type, isNotNull); |
| + expect(fieldParameter.identifier, isNotNull); |
| + expect(fieldParameter.parameters, isNull); |
| } |
| - void test_isInitializedVariableDeclaration_const_simpleType_uninitialized() { |
| - expect(_isInitializedVariableDeclaration("const A a;"), isTrue); |
| + void test_parseNormalFormalParameter_field_var() { |
| + NormalFormalParameter parameter = parseNormalFormalParameter('var this.a'); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<FieldFormalParameter>()); |
| + FieldFormalParameter fieldParameter = parameter; |
| + expect(fieldParameter.keyword, isNotNull); |
| + expect(fieldParameter.type, isNull); |
| + expect(fieldParameter.identifier, isNotNull); |
| + expect(fieldParameter.parameters, isNull); |
| } |
| - void test_isInitializedVariableDeclaration_final_noType_initialized() { |
| - expect(_isInitializedVariableDeclaration("final a = 0;"), isTrue); |
| + void test_parseNormalFormalParameter_function_noType() { |
| + NormalFormalParameter parameter = parseNormalFormalParameter('a()'); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| + FunctionTypedFormalParameter functionParameter = parameter; |
| + expect(functionParameter.returnType, isNull); |
| + expect(functionParameter.identifier, isNotNull); |
| + expect(functionParameter.typeParameters, isNull); |
| + expect(functionParameter.parameters, isNotNull); |
| } |
| - void test_isInitializedVariableDeclaration_final_noType_uninitialized() { |
| - expect(_isInitializedVariableDeclaration("final a;"), isTrue); |
| + void test_parseNormalFormalParameter_function_noType_nullable() { |
| + enableNnbd = true; |
| + NormalFormalParameter parameter = parseNormalFormalParameter('a()?'); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| + FunctionTypedFormalParameter functionParameter = parameter; |
| + expect(functionParameter.returnType, isNull); |
| + expect(functionParameter.identifier, isNotNull); |
| + expect(functionParameter.typeParameters, isNull); |
| + expect(functionParameter.parameters, isNotNull); |
| + expect(functionParameter.question, isNotNull); |
| } |
| - void test_isInitializedVariableDeclaration_final_simpleType_initialized() { |
| - expect(_isInitializedVariableDeclaration("final A a = 0;"), isTrue); |
| + void test_parseNormalFormalParameter_function_noType_typeParameterComments() { |
| + enableGenericMethodComments = true; |
| + NormalFormalParameter parameter = parseNormalFormalParameter('a/*<E>*/()'); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| + FunctionTypedFormalParameter functionParameter = parameter; |
| + expect(functionParameter.returnType, isNull); |
| + expect(functionParameter.identifier, isNotNull); |
| + expect(functionParameter.typeParameters, isNotNull); |
| + expect(functionParameter.parameters, isNotNull); |
| } |
| - void test_isInitializedVariableDeclaration_functionDeclaration_typed() { |
| - expect(_isInitializedVariableDeclaration("A f() {};"), isFalse); |
| + void test_parseNormalFormalParameter_function_noType_typeParameters() { |
| + NormalFormalParameter parameter = parseNormalFormalParameter('a<E>()'); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| + FunctionTypedFormalParameter functionParameter = parameter; |
| + expect(functionParameter.returnType, isNull); |
| + expect(functionParameter.identifier, isNotNull); |
| + expect(functionParameter.typeParameters, isNotNull); |
| + expect(functionParameter.parameters, isNotNull); |
| + expect(functionParameter.question, isNull); |
| + expect(functionParameter.question, isNull); |
| } |
| - void test_isInitializedVariableDeclaration_functionDeclaration_untyped() { |
| - expect(_isInitializedVariableDeclaration("f() {};"), isFalse); |
| + void |
| + test_parseNormalFormalParameter_function_noType_typeParameters_nullable() { |
| + enableNnbd = true; |
| + NormalFormalParameter parameter = parseNormalFormalParameter('a<E>()?'); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| + FunctionTypedFormalParameter functionParameter = parameter; |
| + expect(functionParameter.returnType, isNull); |
| + expect(functionParameter.identifier, isNotNull); |
| + expect(functionParameter.typeParameters, isNotNull); |
| + expect(functionParameter.parameters, isNotNull); |
| + expect(functionParameter.question, isNotNull); |
| } |
| - void test_isInitializedVariableDeclaration_noType_initialized() { |
| - expect(_isInitializedVariableDeclaration("var a = 0;"), isTrue); |
| + void test_parseNormalFormalParameter_function_type() { |
| + NormalFormalParameter parameter = parseNormalFormalParameter('A a()'); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| + FunctionTypedFormalParameter functionParameter = parameter; |
| + expect(functionParameter.returnType, isNotNull); |
| + expect(functionParameter.identifier, isNotNull); |
| + expect(functionParameter.typeParameters, isNull); |
| + expect(functionParameter.parameters, isNotNull); |
| + expect(functionParameter.question, isNull); |
| } |
| - void test_isInitializedVariableDeclaration_noType_uninitialized() { |
| - expect(_isInitializedVariableDeclaration("var a;"), isTrue); |
| + void test_parseNormalFormalParameter_function_type_nullable() { |
| + enableNnbd = true; |
| + NormalFormalParameter parameter = parseNormalFormalParameter('A a()?'); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| + FunctionTypedFormalParameter functionParameter = parameter; |
| + expect(functionParameter.returnType, isNotNull); |
| + expect(functionParameter.identifier, isNotNull); |
| + expect(functionParameter.typeParameters, isNull); |
| + expect(functionParameter.parameters, isNotNull); |
| + expect(functionParameter.question, isNotNull); |
| } |
| - void test_isInitializedVariableDeclaration_parameterizedType_initialized() { |
| - expect(_isInitializedVariableDeclaration("List<int> a = null;"), isTrue); |
| + void test_parseNormalFormalParameter_function_type_typeParameterComments() { |
| + enableGenericMethodComments = true; |
| + NormalFormalParameter parameter = |
| + parseNormalFormalParameter('A a/*<E>*/()'); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| + FunctionTypedFormalParameter functionParameter = parameter; |
| + expect(functionParameter.returnType, isNotNull); |
| + expect(functionParameter.identifier, isNotNull); |
| + expect(functionParameter.typeParameters, isNotNull); |
| + expect(functionParameter.parameters, isNotNull); |
| + expect(functionParameter.question, isNull); |
| } |
| - void test_isInitializedVariableDeclaration_parameterizedType_uninitialized() { |
| - expect(_isInitializedVariableDeclaration("List<int> a;"), isTrue); |
| + void test_parseNormalFormalParameter_function_type_typeParameters() { |
| + NormalFormalParameter parameter = parseNormalFormalParameter('A a<E>()'); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| + FunctionTypedFormalParameter functionParameter = parameter; |
| + expect(functionParameter.returnType, isNotNull); |
| + expect(functionParameter.identifier, isNotNull); |
| + expect(functionParameter.typeParameters, isNotNull); |
| + expect(functionParameter.parameters, isNotNull); |
| + expect(functionParameter.question, isNull); |
| } |
| - void test_isInitializedVariableDeclaration_simpleType_initialized() { |
| - expect(_isInitializedVariableDeclaration("A a = 0;"), isTrue); |
| + void test_parseNormalFormalParameter_function_type_typeParameters_nullable() { |
| + enableNnbd = true; |
| + NormalFormalParameter parameter = parseNormalFormalParameter('A a<E>()?'); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| + FunctionTypedFormalParameter functionParameter = parameter; |
| + expect(functionParameter.returnType, isNotNull); |
| + expect(functionParameter.identifier, isNotNull); |
| + expect(functionParameter.typeParameters, isNotNull); |
| + expect(functionParameter.parameters, isNotNull); |
| + expect(functionParameter.question, isNotNull); |
| } |
| - void test_isInitializedVariableDeclaration_simpleType_uninitialized() { |
| - expect(_isInitializedVariableDeclaration("A a;"), isTrue); |
| + void test_parseNormalFormalParameter_function_void() { |
| + NormalFormalParameter parameter = parseNormalFormalParameter('void a()'); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| + FunctionTypedFormalParameter functionParameter = parameter; |
| + expect(functionParameter.returnType, isNotNull); |
| + expect(functionParameter.identifier, isNotNull); |
| + expect(functionParameter.typeParameters, isNull); |
| + expect(functionParameter.parameters, isNotNull); |
| + expect(functionParameter.question, isNull); |
| } |
| - void test_isSwitchMember_case_labeled() { |
| - expect(_isSwitchMember("l1: l2: case"), isTrue); |
| + void test_parseNormalFormalParameter_function_void_nullable() { |
| + enableNnbd = true; |
| + NormalFormalParameter parameter = parseNormalFormalParameter('void a()?'); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| + FunctionTypedFormalParameter functionParameter = parameter; |
| + expect(functionParameter.returnType, isNotNull); |
| + expect(functionParameter.identifier, isNotNull); |
| + expect(functionParameter.typeParameters, isNull); |
| + expect(functionParameter.parameters, isNotNull); |
| + expect(functionParameter.question, isNotNull); |
| } |
| - void test_isSwitchMember_case_unlabeled() { |
| - expect(_isSwitchMember("case"), isTrue); |
| + void test_parseNormalFormalParameter_function_void_typeParameterComments() { |
| + enableGenericMethodComments = true; |
| + NormalFormalParameter parameter = |
| + parseNormalFormalParameter('void a/*<E>*/()'); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| + FunctionTypedFormalParameter functionParameter = parameter; |
| + expect(functionParameter.returnType, isNotNull); |
| + expect(functionParameter.identifier, isNotNull); |
| + expect(functionParameter.typeParameters, isNotNull); |
| + expect(functionParameter.parameters, isNotNull); |
| + expect(functionParameter.question, isNull); |
| } |
| - void test_isSwitchMember_default_labeled() { |
| - expect(_isSwitchMember("l1: l2: default"), isTrue); |
| + void test_parseNormalFormalParameter_function_void_typeParameters() { |
| + NormalFormalParameter parameter = parseNormalFormalParameter('void a<E>()'); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| + FunctionTypedFormalParameter functionParameter = parameter; |
| + expect(functionParameter.returnType, isNotNull); |
| + expect(functionParameter.identifier, isNotNull); |
| + expect(functionParameter.typeParameters, isNotNull); |
| + expect(functionParameter.parameters, isNotNull); |
| + expect(functionParameter.question, isNull); |
| } |
| - void test_isSwitchMember_default_unlabeled() { |
| - expect(_isSwitchMember("default"), isTrue); |
| + void test_parseNormalFormalParameter_function_void_typeParameters_nullable() { |
| + enableNnbd = true; |
| + NormalFormalParameter parameter = |
| + parseNormalFormalParameter('void a<E>()?'); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| + FunctionTypedFormalParameter functionParameter = parameter; |
| + expect(functionParameter.returnType, isNotNull); |
| + expect(functionParameter.identifier, isNotNull); |
| + expect(functionParameter.typeParameters, isNotNull); |
| + expect(functionParameter.parameters, isNotNull); |
| + expect(functionParameter.question, isNotNull); |
| } |
| - void test_isSwitchMember_false() { |
| - expect(_isSwitchMember("break;"), isFalse); |
| + void test_parseNormalFormalParameter_simple_const_noType() { |
| + NormalFormalParameter parameter = parseNormalFormalParameter('const a'); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| + SimpleFormalParameter simpleParameter = parameter; |
| + expect(simpleParameter.keyword, isNotNull); |
| + expect(simpleParameter.type, isNull); |
| + expect(simpleParameter.identifier, isNotNull); |
| } |
| - void test_parseAdditiveExpression_normal() { |
| - createParser('x + y'); |
| - Expression expression = parser.parseAdditiveExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<BinaryExpression>()); |
| - BinaryExpression binaryExpression = expression; |
| - expect(binaryExpression.leftOperand, isNotNull); |
| - expect(binaryExpression.operator, isNotNull); |
| - expect(binaryExpression.operator.type, TokenType.PLUS); |
| - expect(binaryExpression.rightOperand, isNotNull); |
| + void test_parseNormalFormalParameter_simple_const_type() { |
| + NormalFormalParameter parameter = parseNormalFormalParameter('const A a'); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| + SimpleFormalParameter simpleParameter = parameter; |
| + expect(simpleParameter.keyword, isNotNull); |
| + expect(simpleParameter.type, isNotNull); |
| + expect(simpleParameter.identifier, isNotNull); |
| } |
| - void test_parseAdditiveExpression_super() { |
| - createParser('super + y'); |
| - Expression expression = parser.parseAdditiveExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<BinaryExpression>()); |
| - BinaryExpression binaryExpression = expression; |
| - expect(binaryExpression.leftOperand, new isInstanceOf<SuperExpression>()); |
| - expect(binaryExpression.operator, isNotNull); |
| - expect(binaryExpression.operator.type, TokenType.PLUS); |
| - expect(binaryExpression.rightOperand, isNotNull); |
| + void test_parseNormalFormalParameter_simple_final_noType() { |
| + NormalFormalParameter parameter = parseNormalFormalParameter('final a'); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| + SimpleFormalParameter simpleParameter = parameter; |
| + expect(simpleParameter.keyword, isNotNull); |
| + expect(simpleParameter.type, isNull); |
| + expect(simpleParameter.identifier, isNotNull); |
| } |
| - void test_parseAnnotation_n1() { |
| - createParser('@A'); |
| - Annotation annotation = parser.parseAnnotation(); |
| - expectNotNullIfNoErrors(annotation); |
| - listener.assertNoErrors(); |
| - expect(annotation.atSign, isNotNull); |
| - expect(annotation.name, isNotNull); |
| - expect(annotation.period, isNull); |
| - expect(annotation.constructorName, isNull); |
| - expect(annotation.arguments, isNull); |
| + void test_parseNormalFormalParameter_simple_final_type() { |
| + NormalFormalParameter parameter = parseNormalFormalParameter('final A a'); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| + SimpleFormalParameter simpleParameter = parameter; |
| + expect(simpleParameter.keyword, isNotNull); |
| + expect(simpleParameter.type, isNotNull); |
| + expect(simpleParameter.identifier, isNotNull); |
| } |
| - void test_parseAnnotation_n1_a() { |
| - createParser('@A(x,y)'); |
| - Annotation annotation = parser.parseAnnotation(); |
| - expectNotNullIfNoErrors(annotation); |
| - listener.assertNoErrors(); |
| - expect(annotation.atSign, isNotNull); |
| - expect(annotation.name, isNotNull); |
| - expect(annotation.period, isNull); |
| - expect(annotation.constructorName, isNull); |
| - expect(annotation.arguments, isNotNull); |
| + void test_parseNormalFormalParameter_simple_noName() { |
| + NormalFormalParameter parameter = |
| + parseNormalFormalParameter('a', inFunctionType: true); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| + SimpleFormalParameter simpleParameter = parameter; |
| + expect(simpleParameter.keyword, isNull); |
| + expect(simpleParameter.type, isNotNull); |
| + expect(simpleParameter.identifier, isNull); |
| } |
| - void test_parseAnnotation_n2() { |
| - createParser('@A.B'); |
| - Annotation annotation = parser.parseAnnotation(); |
| - expectNotNullIfNoErrors(annotation); |
| - listener.assertNoErrors(); |
| - expect(annotation.atSign, isNotNull); |
| - expect(annotation.name, isNotNull); |
| - expect(annotation.period, isNull); |
| - expect(annotation.constructorName, isNull); |
| - expect(annotation.arguments, isNull); |
| + void test_parseNormalFormalParameter_simple_noType() { |
| + NormalFormalParameter parameter = parseNormalFormalParameter('a'); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| + SimpleFormalParameter simpleParameter = parameter; |
| + expect(simpleParameter.keyword, isNull); |
| + expect(simpleParameter.type, isNull); |
| + expect(simpleParameter.identifier, isNotNull); |
| } |
| - void test_parseAnnotation_n2_a() { |
| - createParser('@A.B(x,y)'); |
| - Annotation annotation = parser.parseAnnotation(); |
| - expectNotNullIfNoErrors(annotation); |
| - listener.assertNoErrors(); |
| - expect(annotation.atSign, isNotNull); |
| - expect(annotation.name, isNotNull); |
| - expect(annotation.period, isNull); |
| - expect(annotation.constructorName, isNull); |
| - expect(annotation.arguments, isNotNull); |
| + void test_parseNormalFormalParameter_simple_noType_namedCovariant() { |
| + NormalFormalParameter parameter = parseNormalFormalParameter('covariant'); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| + SimpleFormalParameter simpleParameter = parameter; |
| + expect(simpleParameter.covariantKeyword, isNull); |
| + expect(simpleParameter.keyword, isNull); |
| + expect(simpleParameter.type, isNull); |
| + expect(simpleParameter.identifier, isNotNull); |
| } |
| - void test_parseAnnotation_n3() { |
| - createParser('@A.B.C'); |
| - Annotation annotation = parser.parseAnnotation(); |
| - expectNotNullIfNoErrors(annotation); |
| - listener.assertNoErrors(); |
| - expect(annotation.atSign, isNotNull); |
| - expect(annotation.name, isNotNull); |
| - expect(annotation.period, isNotNull); |
| - expect(annotation.constructorName, isNotNull); |
| - expect(annotation.arguments, isNull); |
| + void test_parseNormalFormalParameter_simple_type() { |
| + NormalFormalParameter parameter = parseNormalFormalParameter('A a'); |
| + expect(parameter, isNotNull); |
| + assertNoErrors(); |
| + expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| + SimpleFormalParameter simpleParameter = parameter; |
| + expect(simpleParameter.keyword, isNull); |
| + expect(simpleParameter.type, isNotNull); |
| + expect(simpleParameter.identifier, isNotNull); |
| } |
| +} |
| - void test_parseAnnotation_n3_a() { |
| - createParser('@A.B.C(x,y)'); |
| - Annotation annotation = parser.parseAnnotation(); |
| - expectNotNullIfNoErrors(annotation); |
| +@reflectiveTest |
| +class NonErrorParserTest extends ParserTestCase { |
| + void test_constFactory_external() { |
| + createParser('external const factory C();'); |
| + ClassMember member = parser.parseClassMember('C'); |
| + expectNotNullIfNoErrors(member); |
| listener.assertNoErrors(); |
| - expect(annotation.atSign, isNotNull); |
| - expect(annotation.name, isNotNull); |
| - expect(annotation.period, isNotNull); |
| - expect(annotation.constructorName, isNotNull); |
| - expect(annotation.arguments, isNotNull); |
| } |
| - void test_parseArgument_named() { |
| - createParser('n: x'); |
| - Expression expression = parser.parseArgument(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<NamedExpression>()); |
| - NamedExpression namedExpression = expression; |
| - Label name = namedExpression.name; |
| - expect(name, isNotNull); |
| - expect(name.label, isNotNull); |
| - expect(name.colon, isNotNull); |
| - expect(namedExpression.expression, isNotNull); |
| + void test_staticMethod_notParsingFunctionBodies() { |
| + ParserTestCase.parseFunctionBodies = false; |
| + try { |
| + createParser('class C { static void m() {} }'); |
| + CompilationUnit unit = parser.parseCompilationUnit2(); |
| + expectNotNullIfNoErrors(unit); |
| + listener.assertNoErrors(); |
| + } finally { |
| + ParserTestCase.parseFunctionBodies = true; |
| + } |
| } |
| +} |
| - void test_parseArgument_unnamed() { |
| - String lexeme = "x"; |
| - createParser(lexeme); |
| - Expression expression = parser.parseArgument(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<SimpleIdentifier>()); |
| - SimpleIdentifier identifier = expression; |
| - expect(identifier.name, lexeme); |
| - } |
| +/** |
| + * Implementation of [AbstractParserTestCase] specialized for testing the |
| + * analyzer parser. |
| + */ |
| +class ParserTestCase extends EngineTestCase |
| + with ParserTestHelpers |
| + implements AbstractParserTestCase { |
| + /** |
| + * A flag indicating whether parser is to parse function bodies. |
| + */ |
| + static bool parseFunctionBodies = true; |
| - void test_parseArgumentList_empty() { |
| - createParser('()'); |
| - ArgumentList argumentList = parser.parseArgumentList(); |
| - expectNotNullIfNoErrors(argumentList); |
| - listener.assertNoErrors(); |
| - NodeList<Expression> arguments = argumentList.arguments; |
| - expect(arguments, hasLength(0)); |
| + /** |
| + * A flag indicating whether the parser is to parse asserts in the initializer |
| + * list of a constructor. |
| + */ |
| + bool enableAssertInitializer = false; |
| + |
| + /** |
| + * A flag indicating whether parser is to parse async. |
| + */ |
| + bool parseAsync = true; |
| + |
| + /** |
| + * Whether generic method comments should be enabled for the test. |
| + */ |
| + bool enableGenericMethodComments = false; |
| + |
| + /** |
| + * A flag indicating whether lazy assignment operators should be enabled for |
| + * the test. |
| + */ |
| + bool enableLazyAssignmentOperators = false; |
| + |
| + /** |
| + * A flag indicating whether the parser is to parse the non-nullable modifier |
| + * in type names. |
| + */ |
| + bool enableNnbd = false; |
| + |
| + /** |
| + * A flag indicating whether the parser is to parse part-of directives that |
| + * specify a URI rather than a library name. |
| + */ |
| + bool enableUriInPartOf = false; |
| + |
| + /** |
| + * The error listener to which scanner and parser errors will be reported. |
| + * |
| + * This field is typically initialized by invoking [createParser]. |
| + */ |
| + GatheringErrorListener listener; |
| + |
| + /** |
| + * The parser used by the test. |
| + * |
| + * This field is typically initialized by invoking [createParser]. |
| + */ |
| + Parser parser; |
| + |
| + @override |
| + void assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) { |
| + listener.assertErrorsWithCodes(expectedErrorCodes); |
| } |
| - void test_parseArgumentList_mixed() { |
| - createParser('(w, x, y: y, z: z)'); |
| - ArgumentList argumentList = parser.parseArgumentList(); |
| - expectNotNullIfNoErrors(argumentList); |
| + @override |
| + void assertNoErrors() { |
| listener.assertNoErrors(); |
| - NodeList<Expression> arguments = argumentList.arguments; |
| - expect(arguments, hasLength(4)); |
| } |
| - void test_parseArgumentList_noNamed() { |
| - createParser('(x, y, z)'); |
| - ArgumentList argumentList = parser.parseArgumentList(); |
| - expectNotNullIfNoErrors(argumentList); |
| - listener.assertNoErrors(); |
| - NodeList<Expression> arguments = argumentList.arguments; |
| - expect(arguments, hasLength(3)); |
| + /** |
| + * Create the [parser] and [listener] used by a test. The [parser] will be |
| + * prepared to parse the tokens scanned from the given [content]. |
| + */ |
| + void createParser(String content) { |
| + listener = new GatheringErrorListener(); |
| + // |
| + // Scan the source. |
| + // |
| + TestSource source = new TestSource(); |
| + CharacterReader reader = new CharSequenceReader(content); |
| + Scanner scanner = new Scanner(source, reader, listener); |
| + scanner.scanGenericMethodComments = enableGenericMethodComments; |
| + scanner.scanLazyAssignmentOperators = enableLazyAssignmentOperators; |
| + Token tokenStream = scanner.tokenize(); |
| + listener.setLineInfo(source, scanner.lineStarts); |
| + // |
| + // Create and initialize the parser. |
| + // |
| + parser = new Parser(source, listener); |
| + parser.enableAssertInitializer = enableAssertInitializer; |
| + parser.parseGenericMethodComments = enableGenericMethodComments; |
| + parser.parseFunctionBodies = parseFunctionBodies; |
| + parser.enableNnbd = enableNnbd; |
| + parser.enableUriInPartOf = enableUriInPartOf; |
| + parser.currentToken = tokenStream; |
| } |
| - void test_parseArgumentList_onlyNamed() { |
| - createParser('(x: x, y: y)'); |
| - ArgumentList argumentList = parser.parseArgumentList(); |
| - expectNotNullIfNoErrors(argumentList); |
| - listener.assertNoErrors(); |
| - NodeList<Expression> arguments = argumentList.arguments; |
| - expect(arguments, hasLength(2)); |
| + void expectNotNullIfNoErrors(Object result) { |
| + if (!listener.hasErrors) { |
| + expect(result, isNotNull); |
| + } |
| } |
| - void test_parseArgumentList_trailing_comma() { |
| - createParser('(x, y, z,)'); |
| - ArgumentList argumentList = parser.parseArgumentList(); |
| - expectNotNullIfNoErrors(argumentList); |
| - listener.assertNoErrors(); |
| - NodeList<Expression> arguments = argumentList.arguments; |
| - expect(arguments, hasLength(3)); |
| + /** |
| + * Parse the given source as a compilation unit. |
| + * |
| + * @param source the source to be parsed |
| + * @param errorCodes the error codes of the errors that are expected to be found |
| + * @return the compilation unit that was parsed |
| + * @throws Exception if the source could not be parsed, if the compilation errors in the source do |
| + * not match those that are expected, or if the result would have been `null` |
| + */ |
| + CompilationUnit parseCompilationUnit(String source, |
| + [List<ErrorCode> errorCodes = const <ErrorCode>[]]) { |
| + GatheringErrorListener listener = new GatheringErrorListener(); |
| + Scanner scanner = |
| + new Scanner(null, new CharSequenceReader(source), listener); |
| + listener.setLineInfo(new TestSource(), scanner.lineStarts); |
| + Token token = scanner.tokenize(); |
| + Parser parser = new Parser(null, listener); |
| + CompilationUnit unit = parser.parseCompilationUnit(token); |
| + expect(unit, isNotNull); |
| + listener.assertErrorsWithCodes(errorCodes); |
| + return unit; |
| } |
| - void test_parseAssertStatement() { |
| - createParser('assert (x);'); |
| - AssertStatement statement = parser.parseAssertStatement(); |
| - expectNotNullIfNoErrors(statement); |
| - listener.assertNoErrors(); |
| - expect(statement.assertKeyword, isNotNull); |
| - expect(statement.leftParenthesis, isNotNull); |
| - expect(statement.condition, isNotNull); |
| - expect(statement.comma, isNull); |
| - expect(statement.message, isNull); |
| - expect(statement.rightParenthesis, isNotNull); |
| - expect(statement.semicolon, isNotNull); |
| + /** |
| + * Parse the given [code] as a compilation unit. |
| + */ |
| + CompilationUnit parseCompilationUnit2(String code, |
| + {AnalysisErrorListener listener}) { |
| + listener ??= AnalysisErrorListener.NULL_LISTENER; |
| + Scanner scanner = new Scanner(null, new CharSequenceReader(code), listener); |
| + Token token = scanner.tokenize(); |
| + Parser parser = new Parser(null, listener); |
| + CompilationUnit unit = parser.parseCompilationUnit(token); |
| + unit.lineInfo = new LineInfo(scanner.lineStarts); |
| + return unit; |
| } |
| - void test_parseAssertStatement_messageLowPrecedence() { |
| - // Using a throw expression as an assert message would be silly in |
| - // practice, but it's the lowest precedence expression type, so verifying |
| - // that it works should give us high confidence that other expression types |
| - // will work as well. |
| - createParser('assert (x, throw "foo");'); |
| - AssertStatement statement = parser.parseAssertStatement(); |
| - expectNotNullIfNoErrors(statement); |
| - listener.assertNoErrors(); |
| - expect(statement.assertKeyword, isNotNull); |
| - expect(statement.leftParenthesis, isNotNull); |
| - expect(statement.condition, isNotNull); |
| - expect(statement.comma, isNotNull); |
| - expect(statement.message, isNotNull); |
| - expect(statement.rightParenthesis, isNotNull); |
| - expect(statement.semicolon, isNotNull); |
| + /** |
| + * Parse the given [source] as a compilation unit. Throw an exception if the |
| + * source could not be parsed, if the compilation errors in the source do not |
| + * match those that are expected, or if the result would have been `null`. |
| + */ |
| + CompilationUnit parseCompilationUnitWithOptions(String source, |
| + [List<ErrorCode> errorCodes = const <ErrorCode>[]]) { |
| + createParser(source); |
| + CompilationUnit unit = parser.parseCompilationUnit2(); |
| + expect(unit, isNotNull); |
| + listener.assertErrorsWithCodes(errorCodes); |
| + return unit; |
| } |
| - void test_parseAssertStatement_messageString() { |
| - createParser('assert (x, "foo");'); |
| - AssertStatement statement = parser.parseAssertStatement(); |
| - expectNotNullIfNoErrors(statement); |
| - listener.assertNoErrors(); |
| - expect(statement.assertKeyword, isNotNull); |
| - expect(statement.leftParenthesis, isNotNull); |
| - expect(statement.condition, isNotNull); |
| - expect(statement.comma, isNotNull); |
| - expect(statement.message, isNotNull); |
| - expect(statement.rightParenthesis, isNotNull); |
| - expect(statement.semicolon, isNotNull); |
| + @override |
| + CompilationUnit parseDirectives(String source, |
| + [List<ErrorCode> errorCodes = const <ErrorCode>[]]) { |
| + createParser(source); |
| + CompilationUnit unit = parser.parseDirectives2(); |
| + expect(unit, isNotNull); |
| + expect(unit.declarations, hasLength(0)); |
| + listener.assertErrorsWithCodes(errorCodes); |
| + return unit; |
| } |
| - void test_parseAssignableExpression_expression_args_dot() { |
| - createParser('(x)(y).z'); |
| - Expression expression = parser.parseAssignableExpression(false); |
| + /** |
| + * Parse the given source as an expression. |
| + * |
| + * @param source the source to be parsed |
| + * @param errorCodes the error codes of the errors that are expected to be found |
| + * @return the expression that was parsed |
| + * @throws Exception if the source could not be parsed, if the compilation errors in the source do |
| + * not match those that are expected, or if the result would have been `null` |
| + */ |
| + Expression parseExpression(String source, |
| + [List<ErrorCode> errorCodes = const <ErrorCode>[]]) { |
| + createParser(source); |
| + Expression expression = parser.parseExpression2(); |
| expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<PropertyAccess>()); |
| - PropertyAccess propertyAccess = expression; |
| - FunctionExpressionInvocation invocation = |
| - propertyAccess.target as FunctionExpressionInvocation; |
| - expect(invocation.function, isNotNull); |
| - expect(invocation.typeArguments, isNull); |
| - ArgumentList argumentList = invocation.argumentList; |
| - expect(argumentList, isNotNull); |
| - expect(argumentList.arguments, hasLength(1)); |
| - expect(propertyAccess.operator, isNotNull); |
| - expect(propertyAccess.propertyName, isNotNull); |
| + listener.assertErrorsWithCodes(errorCodes); |
| + return expression; |
| } |
| - void |
| - test_parseAssignableExpression_expression_args_dot_typeParameterComments() { |
| - enableGenericMethodComments = true; |
| - createParser('(x)/*<F>*/(y).z'); |
| - Expression expression = parser.parseAssignableExpression(false); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<PropertyAccess>()); |
| - PropertyAccess propertyAccess = expression; |
| - FunctionExpressionInvocation invocation = |
| - propertyAccess.target as FunctionExpressionInvocation; |
| - expect(invocation.function, isNotNull); |
| - expect(invocation.typeArguments, isNotNull); |
| - ArgumentList argumentList = invocation.argumentList; |
| - expect(argumentList, isNotNull); |
| - expect(argumentList.arguments, hasLength(1)); |
| - expect(propertyAccess.operator, isNotNull); |
| - expect(propertyAccess.propertyName, isNotNull); |
| + @override |
| + FormalParameter parseFormalParameter(String code, ParameterKind kind, |
| + {List<ErrorCode> errorCodes: const <ErrorCode>[]}) { |
| + createParser(code); |
| + FormalParameter parameter = parser.parseFormalParameter(kind); |
| + assertErrorsWithCodes(errorCodes); |
| + return parameter; |
| } |
| - void test_parseAssignableExpression_expression_args_dot_typeParameters() { |
| - createParser('(x)<F>(y).z'); |
| - Expression expression = parser.parseAssignableExpression(false); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<PropertyAccess>()); |
| - PropertyAccess propertyAccess = expression; |
| - FunctionExpressionInvocation invocation = |
| - propertyAccess.target as FunctionExpressionInvocation; |
| - expect(invocation.function, isNotNull); |
| - expect(invocation.typeArguments, isNotNull); |
| - ArgumentList argumentList = invocation.argumentList; |
| - expect(argumentList, isNotNull); |
| - expect(argumentList.arguments, hasLength(1)); |
| - expect(propertyAccess.operator, isNotNull); |
| - expect(propertyAccess.propertyName, isNotNull); |
| + @override |
| + FormalParameterList parseFormalParameterList(String code, |
| + {bool inFunctionType: false, |
| + List<ErrorCode> errorCodes: const <ErrorCode>[]}) { |
| + createParser(code); |
| + FormalParameterList list = |
| + parser.parseFormalParameterList(inFunctionType: inFunctionType); |
| + assertErrorsWithCodes(errorCodes); |
| + return list; |
| } |
| - void test_parseAssignableExpression_expression_dot() { |
| - createParser('(x).y'); |
| - Expression expression = parser.parseAssignableExpression(false); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<PropertyAccess>()); |
| - PropertyAccess propertyAccess = expression; |
| - expect(propertyAccess.target, isNotNull); |
| - expect(propertyAccess.operator.type, TokenType.PERIOD); |
| - expect(propertyAccess.propertyName, isNotNull); |
| + /** |
| + * Parses a single top level member of a compilation unit (other than a |
| + * directive), including any comment and/or metadata that precedes it. |
| + */ |
| + CompilationUnitMember parseFullCompilationUnitMember() => |
| + parser.parseCompilationUnitMember(parser.parseCommentAndMetadata()); |
| + |
| + @override |
| + Directive parseFullDirective() => |
| + parser.parseDirective(parser.parseCommentAndMetadata()); |
| + |
| + /** |
| + * Parses a variable declaration list (equivalent to a variable declaration |
| + * statement, but without the final comma). |
| + */ |
| + VariableDeclarationList parseFullVariableDeclarationList() => |
| + parser.parseVariableDeclarationListAfterMetadata( |
| + parser.parseCommentAndMetadata()); |
| + |
| + @override |
| + NormalFormalParameter parseNormalFormalParameter(String code, |
| + {bool inFunctionType: false, |
| + List<ErrorCode> errorCodes: const <ErrorCode>[]}) { |
| + createParser(code); |
| + FormalParameter parameter = |
| + parser.parseNormalFormalParameter(inFunctionType: inFunctionType); |
| + assertErrorsWithCodes(errorCodes); |
| + return parameter; |
| } |
| - void test_parseAssignableExpression_expression_index() { |
| - createParser('(x)[y]'); |
| - Expression expression = parser.parseAssignableExpression(false); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<IndexExpression>()); |
| - IndexExpression indexExpression = expression; |
| - expect(indexExpression.target, isNotNull); |
| - expect(indexExpression.leftBracket, isNotNull); |
| - expect(indexExpression.index, isNotNull); |
| - expect(indexExpression.rightBracket, isNotNull); |
| + /** |
| + * Parse the given [source] as a statement. The [errorCodes] are the error |
| + * codes of the errors that are expected to be found. If |
| + * [enableLazyAssignmentOperators] is `true`, then lazy assignment operators |
| + * should be enabled. |
| + */ |
| + Statement parseStatement(String source, |
| + [List<ErrorCode> errorCodes = const <ErrorCode>[], |
| + bool enableLazyAssignmentOperators]) { |
| + GatheringErrorListener listener = new GatheringErrorListener(); |
| + Scanner scanner = |
| + new Scanner(null, new CharSequenceReader(source), listener); |
| + scanner.scanLazyAssignmentOperators = enableLazyAssignmentOperators; |
| + listener.setLineInfo(new TestSource(), scanner.lineStarts); |
| + Token token = scanner.tokenize(); |
| + Parser parser = new Parser(null, listener); |
| + Statement statement = parser.parseStatement(token); |
| + expect(statement, isNotNull); |
| + listener.assertErrorsWithCodes(errorCodes); |
| + return statement; |
| } |
| - void test_parseAssignableExpression_expression_question_dot() { |
| - createParser('(x)?.y'); |
| - Expression expression = parser.parseAssignableExpression(false); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<PropertyAccess>()); |
| - PropertyAccess propertyAccess = expression; |
| - expect(propertyAccess.target, isNotNull); |
| - expect(propertyAccess.operator.type, TokenType.QUESTION_PERIOD); |
| - expect(propertyAccess.propertyName, isNotNull); |
| + /** |
| + * Parse the given source as a sequence of statements. |
| + * |
| + * @param source the source to be parsed |
| + * @param expectedCount the number of statements that are expected |
| + * @param errorCodes the error codes of the errors that are expected to be found |
| + * @return the statements that were parsed |
| + * @throws Exception if the source could not be parsed, if the number of statements does not match |
| + * the expected count, if the compilation errors in the source do not match those that |
| + * are expected, or if the result would have been `null` |
| + */ |
| + List<Statement> parseStatements(String source, int expectedCount, |
| + [List<ErrorCode> errorCodes = const <ErrorCode>[]]) { |
| + GatheringErrorListener listener = new GatheringErrorListener(); |
| + Scanner scanner = |
| + new Scanner(null, new CharSequenceReader(source), listener); |
| + listener.setLineInfo(new TestSource(), scanner.lineStarts); |
| + Token token = scanner.tokenize(); |
| + Parser parser = new Parser(null, listener); |
| + List<Statement> statements = parser.parseStatements(token); |
| + expect(statements, hasLength(expectedCount)); |
| + listener.assertErrorsWithCodes(errorCodes); |
| + return statements; |
| } |
| - void test_parseAssignableExpression_identifier() { |
| - createParser('x'); |
| - Expression expression = parser.parseAssignableExpression(false); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<SimpleIdentifier>()); |
| - SimpleIdentifier identifier = expression; |
| - expect(identifier, isNotNull); |
| + @override |
| + void setUp() { |
| + super.setUp(); |
| + parseFunctionBodies = true; |
| } |
| +} |
| - void test_parseAssignableExpression_identifier_args_dot() { |
| - createParser('x(y).z'); |
| - Expression expression = parser.parseAssignableExpression(false); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<PropertyAccess>()); |
| - PropertyAccess propertyAccess = expression; |
| - MethodInvocation invocation = propertyAccess.target as MethodInvocation; |
| - expect(invocation.methodName.name, "x"); |
| - expect(invocation.typeArguments, isNull); |
| - ArgumentList argumentList = invocation.argumentList; |
| - expect(argumentList, isNotNull); |
| - expect(argumentList.arguments, hasLength(1)); |
| - expect(propertyAccess.operator, isNotNull); |
| - expect(propertyAccess.propertyName, isNotNull); |
| +/** |
| + * Helper methods that aid in parser tests. |
| + * |
| + * Intended to be mixed in to parser test case classes. |
| + */ |
| +class ParserTestHelpers { |
| + void expectCommentText(Comment comment, String expectedText) { |
| + expect(comment.beginToken, same(comment.endToken)); |
| + expect(comment.beginToken.lexeme, expectedText); |
| + } |
| + |
| + void expectDottedName(DottedName name, List<String> expectedComponents) { |
| + int count = expectedComponents.length; |
| + NodeList<SimpleIdentifier> components = name.components; |
| + expect(components, hasLength(count)); |
| + for (int i = 0; i < count; i++) { |
| + SimpleIdentifier component = components[i]; |
| + expect(component, isNotNull); |
| + expect(component.name, expectedComponents[i]); |
| + } |
| + } |
| +} |
| + |
| +/** |
| + * The class `RecoveryParserTest` defines parser tests that test the parsing of invalid code |
| + * sequences to ensure that the correct recovery steps are taken in the parser. |
| + */ |
| +@reflectiveTest |
| +class RecoveryParserTest extends ParserTestCase { |
| + void test_additiveExpression_missing_LHS() { |
| + BinaryExpression expression = |
| + parseExpression("+ y", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.leftOperand); |
| + expect(expression.leftOperand.isSynthetic, isTrue); |
| } |
| - void |
| - test_parseAssignableExpression_identifier_args_dot_typeParameterComments() { |
| - enableGenericMethodComments = true; |
| - createParser('x/*<E>*/(y).z'); |
| - Expression expression = parser.parseAssignableExpression(false); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<PropertyAccess>()); |
| - PropertyAccess propertyAccess = expression; |
| - MethodInvocation invocation = propertyAccess.target as MethodInvocation; |
| - expect(invocation.methodName.name, "x"); |
| - expect(invocation.typeArguments, isNotNull); |
| - ArgumentList argumentList = invocation.argumentList; |
| - expect(argumentList, isNotNull); |
| - expect(argumentList.arguments, hasLength(1)); |
| - expect(propertyAccess.operator, isNotNull); |
| - expect(propertyAccess.propertyName, isNotNull); |
| + void test_additiveExpression_missing_LHS_RHS() { |
| + BinaryExpression expression = parseExpression("+", [ |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER |
| + ]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.leftOperand); |
| + expect(expression.leftOperand.isSynthetic, isTrue); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.rightOperand); |
| + expect(expression.rightOperand.isSynthetic, isTrue); |
| } |
| - void test_parseAssignableExpression_identifier_args_dot_typeParameters() { |
| - createParser('x<E>(y).z'); |
| - Expression expression = parser.parseAssignableExpression(false); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<PropertyAccess>()); |
| - PropertyAccess propertyAccess = expression; |
| - MethodInvocation invocation = propertyAccess.target as MethodInvocation; |
| - expect(invocation.methodName.name, "x"); |
| - expect(invocation.typeArguments, isNotNull); |
| - ArgumentList argumentList = invocation.argumentList; |
| - expect(argumentList, isNotNull); |
| - expect(argumentList.arguments, hasLength(1)); |
| - expect(propertyAccess.operator, isNotNull); |
| - expect(propertyAccess.propertyName, isNotNull); |
| + void test_additiveExpression_missing_RHS() { |
| + BinaryExpression expression = |
| + parseExpression("x +", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.rightOperand); |
| + expect(expression.rightOperand.isSynthetic, isTrue); |
| } |
| - void test_parseAssignableExpression_identifier_dot() { |
| - createParser('x.y'); |
| - Expression expression = parser.parseAssignableExpression(false); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<PropertyAccess>()); |
| - PropertyAccess propertyAccess = expression; |
| - expect(propertyAccess.target, isNotNull); |
| - expect(propertyAccess.operator, isNotNull); |
| - expect(propertyAccess.operator.type, TokenType.PERIOD); |
| - expect(propertyAccess.propertyName, isNotNull); |
| + void test_additiveExpression_missing_RHS_super() { |
| + BinaryExpression expression = |
| + parseExpression("super +", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.rightOperand); |
| + expect(expression.rightOperand.isSynthetic, isTrue); |
| } |
| - void test_parseAssignableExpression_identifier_index() { |
| - createParser('x[y]'); |
| - Expression expression = parser.parseAssignableExpression(false); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<IndexExpression>()); |
| - IndexExpression indexExpression = expression; |
| - expect(indexExpression.target, isNotNull); |
| - expect(indexExpression.leftBracket, isNotNull); |
| - expect(indexExpression.index, isNotNull); |
| - expect(indexExpression.rightBracket, isNotNull); |
| + void test_additiveExpression_precedence_multiplicative_left() { |
| + BinaryExpression expression = parseExpression("* +", [ |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER |
| + ]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| + BinaryExpression, expression.leftOperand); |
| } |
| - void test_parseAssignableExpression_identifier_question_dot() { |
| - createParser('x?.y'); |
| - Expression expression = parser.parseAssignableExpression(false); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<PropertyAccess>()); |
| - PropertyAccess propertyAccess = expression; |
| - expect(propertyAccess.target, isNotNull); |
| - expect(propertyAccess.operator.type, TokenType.QUESTION_PERIOD); |
| - expect(propertyAccess.propertyName, isNotNull); |
| + void test_additiveExpression_precedence_multiplicative_right() { |
| + BinaryExpression expression = parseExpression("+ *", [ |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER |
| + ]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| + BinaryExpression, expression.rightOperand); |
| } |
| - void test_parseAssignableExpression_super_dot() { |
| - createParser('super.y'); |
| - Expression expression = parser.parseAssignableExpression(false); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<PropertyAccess>()); |
| - PropertyAccess propertyAccess = expression; |
| - EngineTestCase.assertInstanceOf((obj) => obj is SuperExpression, |
| - SuperExpression, propertyAccess.target); |
| - expect(propertyAccess.operator, isNotNull); |
| - expect(propertyAccess.propertyName, isNotNull); |
| + void test_additiveExpression_super() { |
| + BinaryExpression expression = parseExpression("super + +", [ |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER |
| + ]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| + BinaryExpression, expression.leftOperand); |
| } |
| - void test_parseAssignableExpression_super_index() { |
| - createParser('super[y]'); |
| - Expression expression = parser.parseAssignableExpression(false); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<IndexExpression>()); |
| - IndexExpression indexExpression = expression; |
| - expect(indexExpression.target, new isInstanceOf<SuperExpression>()); |
| - expect(indexExpression.leftBracket, isNotNull); |
| - expect(indexExpression.index, isNotNull); |
| - expect(indexExpression.rightBracket, isNotNull); |
| + void test_assignableSelector() { |
| + IndexExpression expression = |
| + parseExpression("a.b[]", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + Expression index = expression.index; |
| + expect(index, new isInstanceOf<SimpleIdentifier>()); |
| + expect(index.isSynthetic, isTrue); |
| } |
| - void test_parseAssignableSelector_dot() { |
| - createParser('.x'); |
| - Expression expression = parser.parseAssignableSelector(null, true); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<PropertyAccess>()); |
| - PropertyAccess propertyAccess = expression; |
| - expect(propertyAccess.operator.type, TokenType.PERIOD); |
| - expect(propertyAccess.propertyName, isNotNull); |
| + void test_assignmentExpression_missing_compound1() { |
| + AssignmentExpression expression = |
| + parseExpression("= y = 0", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + Expression syntheticExpression = expression.leftHandSide; |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, syntheticExpression); |
| + expect(syntheticExpression.isSynthetic, isTrue); |
| } |
| - void test_parseAssignableSelector_index() { |
| - createParser('[x]'); |
| - Expression expression = parser.parseAssignableSelector(null, true); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<IndexExpression>()); |
| - IndexExpression indexExpression = expression; |
| - expect(indexExpression.leftBracket, isNotNull); |
| - expect(indexExpression.index, isNotNull); |
| - expect(indexExpression.rightBracket, isNotNull); |
| + void test_assignmentExpression_missing_compound2() { |
| + AssignmentExpression expression = |
| + parseExpression("x = = 0", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + Expression syntheticExpression = |
| + (expression.rightHandSide as AssignmentExpression).leftHandSide; |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, syntheticExpression); |
| + expect(syntheticExpression.isSynthetic, isTrue); |
| } |
| - void test_parseAssignableSelector_none() { |
| - createParser(';'); |
| - Expression expression = |
| - parser.parseAssignableSelector(astFactory.simpleIdentifier(null), true); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<SimpleIdentifier>()); |
| - SimpleIdentifier identifier = expression; |
| - expect(identifier, isNotNull); |
| + void test_assignmentExpression_missing_compound3() { |
| + AssignmentExpression expression = |
| + parseExpression("x = y =", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + Expression syntheticExpression = |
| + (expression.rightHandSide as AssignmentExpression).rightHandSide; |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, syntheticExpression); |
| + expect(syntheticExpression.isSynthetic, isTrue); |
| } |
| - void test_parseAssignableSelector_question_dot() { |
| - createParser('?.x'); |
| - Expression expression = parser.parseAssignableSelector(null, true); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<PropertyAccess>()); |
| - PropertyAccess propertyAccess = expression; |
| - expect(propertyAccess.operator.type, TokenType.QUESTION_PERIOD); |
| - expect(propertyAccess.propertyName, isNotNull); |
| + void test_assignmentExpression_missing_LHS() { |
| + AssignmentExpression expression = |
| + parseExpression("= 0", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.leftHandSide); |
| + expect(expression.leftHandSide.isSynthetic, isTrue); |
| } |
| - void test_parseAwaitExpression() { |
| - createParser('await x;'); |
| - AwaitExpression expression = parser.parseAwaitExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression.awaitKeyword, isNotNull); |
| - expect(expression.expression, isNotNull); |
| + void test_assignmentExpression_missing_RHS() { |
| + AssignmentExpression expression = |
| + parseExpression("x =", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.leftHandSide); |
| + expect(expression.rightHandSide.isSynthetic, isTrue); |
| } |
| - void test_parseBitwiseAndExpression_normal() { |
| - createParser('x & y'); |
| - Expression expression = parser.parseBitwiseAndExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<BinaryExpression>()); |
| - BinaryExpression binaryExpression = expression; |
| - expect(binaryExpression.leftOperand, isNotNull); |
| - expect(binaryExpression.operator, isNotNull); |
| - expect(binaryExpression.operator.type, TokenType.AMPERSAND); |
| - expect(binaryExpression.rightOperand, isNotNull); |
| + void test_bitwiseAndExpression_missing_LHS() { |
| + BinaryExpression expression = |
| + parseExpression("& y", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.leftOperand); |
| + expect(expression.leftOperand.isSynthetic, isTrue); |
| + } |
| + |
| + void test_bitwiseAndExpression_missing_LHS_RHS() { |
| + BinaryExpression expression = parseExpression("&", [ |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER |
| + ]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.leftOperand); |
| + expect(expression.leftOperand.isSynthetic, isTrue); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.rightOperand); |
| + expect(expression.rightOperand.isSynthetic, isTrue); |
| } |
| - void test_parseBitwiseAndExpression_super() { |
| - createParser('super & y'); |
| - Expression expression = parser.parseBitwiseAndExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<BinaryExpression>()); |
| - BinaryExpression binaryExpression = expression; |
| - expect(binaryExpression.leftOperand, new isInstanceOf<SuperExpression>()); |
| - expect(binaryExpression.operator, isNotNull); |
| - expect(binaryExpression.operator.type, TokenType.AMPERSAND); |
| - expect(binaryExpression.rightOperand, isNotNull); |
| + void test_bitwiseAndExpression_missing_RHS() { |
| + BinaryExpression expression = |
| + parseExpression("x &", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.rightOperand); |
| + expect(expression.rightOperand.isSynthetic, isTrue); |
| } |
| - void test_parseBitwiseOrExpression_normal() { |
| - createParser('x | y'); |
| - Expression expression = parser.parseBitwiseOrExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<BinaryExpression>()); |
| - BinaryExpression binaryExpression = expression; |
| - expect(binaryExpression.leftOperand, isNotNull); |
| - expect(binaryExpression.operator, isNotNull); |
| - expect(binaryExpression.operator.type, TokenType.BAR); |
| - expect(binaryExpression.rightOperand, isNotNull); |
| + void test_bitwiseAndExpression_missing_RHS_super() { |
| + BinaryExpression expression = |
| + parseExpression("super &", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.rightOperand); |
| + expect(expression.rightOperand.isSynthetic, isTrue); |
| } |
| - void test_parseBitwiseOrExpression_super() { |
| - createParser('super | y'); |
| - Expression expression = parser.parseBitwiseOrExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<BinaryExpression>()); |
| - BinaryExpression binaryExpression = expression; |
| - expect(binaryExpression.leftOperand, new isInstanceOf<SuperExpression>()); |
| - expect(binaryExpression.operator, isNotNull); |
| - expect(binaryExpression.operator.type, TokenType.BAR); |
| - expect(binaryExpression.rightOperand, isNotNull); |
| + void test_bitwiseAndExpression_precedence_equality_left() { |
| + BinaryExpression expression = parseExpression("== &&", [ |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER |
| + ]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| + BinaryExpression, expression.leftOperand); |
| } |
| - void test_parseBitwiseXorExpression_normal() { |
| - createParser('x ^ y'); |
| - Expression expression = parser.parseBitwiseXorExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<BinaryExpression>()); |
| - BinaryExpression binaryExpression = expression; |
| - expect(binaryExpression.leftOperand, isNotNull); |
| - expect(binaryExpression.operator, isNotNull); |
| - expect(binaryExpression.operator.type, TokenType.CARET); |
| - expect(binaryExpression.rightOperand, isNotNull); |
| + void test_bitwiseAndExpression_precedence_equality_right() { |
| + BinaryExpression expression = parseExpression("&& ==", [ |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER |
| + ]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| + BinaryExpression, expression.rightOperand); |
| } |
| - void test_parseBitwiseXorExpression_super() { |
| - createParser('super ^ y'); |
| - Expression expression = parser.parseBitwiseXorExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<BinaryExpression>()); |
| - BinaryExpression binaryExpression = expression; |
| - expect(binaryExpression.leftOperand, new isInstanceOf<SuperExpression>()); |
| - expect(binaryExpression.operator, isNotNull); |
| - expect(binaryExpression.operator.type, TokenType.CARET); |
| - expect(binaryExpression.rightOperand, isNotNull); |
| + void test_bitwiseAndExpression_super() { |
| + BinaryExpression expression = parseExpression("super & &", [ |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER |
| + ]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| + BinaryExpression, expression.leftOperand); |
| } |
| - void test_parseBlock_empty() { |
| - createParser('{}'); |
| - Block block = parser.parseBlock(); |
| - expectNotNullIfNoErrors(block); |
| - listener.assertNoErrors(); |
| - expect(block.leftBracket, isNotNull); |
| - expect(block.statements, hasLength(0)); |
| - expect(block.rightBracket, isNotNull); |
| + void test_bitwiseOrExpression_missing_LHS() { |
| + BinaryExpression expression = |
| + parseExpression("| y", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.leftOperand); |
| + expect(expression.leftOperand.isSynthetic, isTrue); |
| } |
| - void test_parseBlock_nonEmpty() { |
| - createParser('{;}'); |
| - Block block = parser.parseBlock(); |
| - expectNotNullIfNoErrors(block); |
| - listener.assertNoErrors(); |
| - expect(block.leftBracket, isNotNull); |
| - expect(block.statements, hasLength(1)); |
| - expect(block.rightBracket, isNotNull); |
| + void test_bitwiseOrExpression_missing_LHS_RHS() { |
| + BinaryExpression expression = parseExpression("|", [ |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER |
| + ]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.leftOperand); |
| + expect(expression.leftOperand.isSynthetic, isTrue); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.rightOperand); |
| + expect(expression.rightOperand.isSynthetic, isTrue); |
| } |
| - void test_parseBreakStatement_label() { |
| - createParser('break foo;'); |
| - BreakStatement statement = parser.parseBreakStatement(); |
| - expectNotNullIfNoErrors(statement); |
| - listener.assertNoErrors(); |
| - expect(statement.breakKeyword, isNotNull); |
| - expect(statement.label, isNotNull); |
| - expect(statement.semicolon, isNotNull); |
| + void test_bitwiseOrExpression_missing_RHS() { |
| + BinaryExpression expression = |
| + parseExpression("x |", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.rightOperand); |
| + expect(expression.rightOperand.isSynthetic, isTrue); |
| } |
| - void test_parseBreakStatement_noLabel() { |
| - createParser('break;'); |
| - BreakStatement statement = parser.parseBreakStatement(); |
| - expectNotNullIfNoErrors(statement); |
| - listener.assertErrorsWithCodes([ParserErrorCode.BREAK_OUTSIDE_OF_LOOP]); |
| - expect(statement.breakKeyword, isNotNull); |
| - expect(statement.label, isNull); |
| - expect(statement.semicolon, isNotNull); |
| + void test_bitwiseOrExpression_missing_RHS_super() { |
| + BinaryExpression expression = |
| + parseExpression("super |", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.rightOperand); |
| + expect(expression.rightOperand.isSynthetic, isTrue); |
| } |
| - void test_parseCascadeSection_i() { |
| - createParser('..[i]'); |
| - Expression expression = parser.parseCascadeSection(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<IndexExpression>()); |
| - IndexExpression section = expression; |
| - expect(section.target, isNull); |
| - expect(section.leftBracket, isNotNull); |
| - expect(section.index, isNotNull); |
| - expect(section.rightBracket, isNotNull); |
| + void test_bitwiseOrExpression_precedence_xor_left() { |
| + BinaryExpression expression = parseExpression("^ |", [ |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER |
| + ]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| + BinaryExpression, expression.leftOperand); |
| } |
| - void test_parseCascadeSection_ia() { |
| - createParser('..[i](b)'); |
| - Expression expression = parser.parseCascadeSection(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<FunctionExpressionInvocation>()); |
| - FunctionExpressionInvocation section = expression; |
| - expect(section.function, new isInstanceOf<IndexExpression>()); |
| - expect(section.typeArguments, isNull); |
| - expect(section.argumentList, isNotNull); |
| + void test_bitwiseOrExpression_precedence_xor_right() { |
| + BinaryExpression expression = parseExpression("| ^", [ |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER |
| + ]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| + BinaryExpression, expression.rightOperand); |
| } |
| - void test_parseCascadeSection_ia_typeArgumentComments() { |
| - enableGenericMethodComments = true; |
| - createParser('..[i]/*<E>*/(b)'); |
| - Expression expression = parser.parseCascadeSection(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<FunctionExpressionInvocation>()); |
| - FunctionExpressionInvocation section = expression; |
| - expect(section.function, new isInstanceOf<IndexExpression>()); |
| - expect(section.typeArguments, isNotNull); |
| - expect(section.argumentList, isNotNull); |
| + void test_bitwiseOrExpression_super() { |
| + BinaryExpression expression = parseExpression("super | |", [ |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER |
| + ]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| + BinaryExpression, expression.leftOperand); |
| } |
| - void test_parseCascadeSection_ia_typeArguments() { |
| - createParser('..[i]<E>(b)'); |
| - Expression expression = parser.parseCascadeSection(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<FunctionExpressionInvocation>()); |
| - FunctionExpressionInvocation section = expression; |
| - expect(section.function, new isInstanceOf<IndexExpression>()); |
| - expect(section.typeArguments, isNotNull); |
| - expect(section.argumentList, isNotNull); |
| + void test_bitwiseXorExpression_missing_LHS() { |
| + BinaryExpression expression = |
| + parseExpression("^ y", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.leftOperand); |
| + expect(expression.leftOperand.isSynthetic, isTrue); |
| } |
| - void test_parseCascadeSection_ii() { |
| - createParser('..a(b).c(d)'); |
| - Expression expression = parser.parseCascadeSection(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<MethodInvocation>()); |
| - MethodInvocation section = expression; |
| - expect(section.target, new isInstanceOf<MethodInvocation>()); |
| - expect(section.operator, isNotNull); |
| - expect(section.methodName, isNotNull); |
| - expect(section.typeArguments, isNull); |
| - expect(section.argumentList, isNotNull); |
| - expect(section.argumentList.arguments, hasLength(1)); |
| + void test_bitwiseXorExpression_missing_LHS_RHS() { |
| + BinaryExpression expression = parseExpression("^", [ |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER |
| + ]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.leftOperand); |
| + expect(expression.leftOperand.isSynthetic, isTrue); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.rightOperand); |
| + expect(expression.rightOperand.isSynthetic, isTrue); |
| + } |
| + |
| + void test_bitwiseXorExpression_missing_RHS() { |
| + BinaryExpression expression = |
| + parseExpression("x ^", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.rightOperand); |
| + expect(expression.rightOperand.isSynthetic, isTrue); |
| + } |
| + |
| + void test_bitwiseXorExpression_missing_RHS_super() { |
| + BinaryExpression expression = |
| + parseExpression("super ^", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.rightOperand); |
| + expect(expression.rightOperand.isSynthetic, isTrue); |
| } |
| - void test_parseCascadeSection_ii_typeArgumentComments() { |
| - enableGenericMethodComments = true; |
| - createParser('..a/*<E>*/(b).c/*<F>*/(d)'); |
| - Expression expression = parser.parseCascadeSection(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<MethodInvocation>()); |
| - MethodInvocation section = expression; |
| - expect(section.target, new isInstanceOf<MethodInvocation>()); |
| - expect(section.operator, isNotNull); |
| - expect(section.methodName, isNotNull); |
| - expect(section.typeArguments, isNotNull); |
| - expect(section.argumentList, isNotNull); |
| - expect(section.argumentList.arguments, hasLength(1)); |
| + void test_bitwiseXorExpression_precedence_and_left() { |
| + BinaryExpression expression = parseExpression("& ^", [ |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER |
| + ]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| + BinaryExpression, expression.leftOperand); |
| } |
| - void test_parseCascadeSection_ii_typeArguments() { |
| - createParser('..a<E>(b).c<F>(d)'); |
| - Expression expression = parser.parseCascadeSection(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<MethodInvocation>()); |
| - MethodInvocation section = expression; |
| - expect(section.target, new isInstanceOf<MethodInvocation>()); |
| - expect(section.operator, isNotNull); |
| - expect(section.methodName, isNotNull); |
| - expect(section.typeArguments, isNotNull); |
| - expect(section.argumentList, isNotNull); |
| - expect(section.argumentList.arguments, hasLength(1)); |
| + void test_bitwiseXorExpression_precedence_and_right() { |
| + BinaryExpression expression = parseExpression("^ &", [ |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER |
| + ]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| + BinaryExpression, expression.rightOperand); |
| } |
| - void test_parseCascadeSection_p() { |
| - createParser('..a'); |
| - Expression expression = parser.parseCascadeSection(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<PropertyAccess>()); |
| - PropertyAccess section = expression; |
| - expect(section.target, isNull); |
| - expect(section.operator, isNotNull); |
| - expect(section.propertyName, isNotNull); |
| + void test_bitwiseXorExpression_super() { |
| + BinaryExpression expression = parseExpression("super ^ ^", [ |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER |
| + ]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| + BinaryExpression, expression.leftOperand); |
| } |
| - void test_parseCascadeSection_p_assign() { |
| - createParser('..a = 3'); |
| - Expression expression = parser.parseCascadeSection(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<AssignmentExpression>()); |
| - AssignmentExpression section = expression; |
| - expect(section.leftHandSide, isNotNull); |
| - expect(section.operator, isNotNull); |
| - Expression rhs = section.rightHandSide; |
| - expect(rhs, isNotNull); |
| + void test_classTypeAlias_withBody() { |
| + parseCompilationUnit( |
| + r''' |
| +class A {} |
| +class B = Object with A {}''', |
| + [ParserErrorCode.EXPECTED_TOKEN]); |
| } |
| - void test_parseCascadeSection_p_assign_withCascade() { |
| - createParser('..a = 3..m()'); |
| - Expression expression = parser.parseCascadeSection(); |
| + void test_conditionalExpression_missingElse() { |
| + createParser('x ? y :'); |
| + Expression expression = parser.parseConditionalExpression(); |
| expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<AssignmentExpression>()); |
| - AssignmentExpression section = expression; |
| - expect(section.leftHandSide, isNotNull); |
| - expect(section.operator, isNotNull); |
| - Expression rhs = section.rightHandSide; |
| - EngineTestCase.assertInstanceOf( |
| - (obj) => obj is IntegerLiteral, IntegerLiteral, rhs); |
| + listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| + expect(expression, new isInstanceOf<ConditionalExpression>()); |
| + ConditionalExpression conditionalExpression = expression; |
| + expect(conditionalExpression.elseExpression, |
| + new isInstanceOf<SimpleIdentifier>()); |
| + expect(conditionalExpression.elseExpression.isSynthetic, isTrue); |
| } |
| - void test_parseCascadeSection_p_assign_withCascade_typeArgumentComments() { |
| - enableGenericMethodComments = true; |
| - createParser('..a = 3..m/*<E>*/()'); |
| - Expression expression = parser.parseCascadeSection(); |
| + void test_conditionalExpression_missingThen() { |
| + createParser('x ? : z'); |
| + Expression expression = parser.parseConditionalExpression(); |
| expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<AssignmentExpression>()); |
| - AssignmentExpression section = expression; |
| - expect(section.leftHandSide, isNotNull); |
| - expect(section.operator, isNotNull); |
| - Expression rhs = section.rightHandSide; |
| - EngineTestCase.assertInstanceOf( |
| - (obj) => obj is IntegerLiteral, IntegerLiteral, rhs); |
| + listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| + expect(expression, new isInstanceOf<ConditionalExpression>()); |
| + ConditionalExpression conditionalExpression = expression; |
| + expect(conditionalExpression.thenExpression, |
| + new isInstanceOf<SimpleIdentifier>()); |
| + expect(conditionalExpression.thenExpression.isSynthetic, isTrue); |
| } |
| - void test_parseCascadeSection_p_assign_withCascade_typeArguments() { |
| - createParser('..a = 3..m<E>()'); |
| - Expression expression = parser.parseCascadeSection(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<AssignmentExpression>()); |
| - AssignmentExpression section = expression; |
| - expect(section.leftHandSide, isNotNull); |
| - expect(section.operator, isNotNull); |
| - Expression rhs = section.rightHandSide; |
| - EngineTestCase.assertInstanceOf( |
| - (obj) => obj is IntegerLiteral, IntegerLiteral, rhs); |
| + void test_declarationBeforeDirective() { |
| + CompilationUnit unit = parseCompilationUnit( |
| + "class foo { } import 'bar.dart';", |
| + [ParserErrorCode.DIRECTIVE_AFTER_DECLARATION]); |
| + expect(unit.directives, hasLength(1)); |
| + expect(unit.declarations, hasLength(1)); |
| + ClassDeclaration classDecl = unit.childEntities.first; |
| + expect(classDecl, isNotNull); |
| + expect(classDecl.name.name, 'foo'); |
| } |
| - void test_parseCascadeSection_p_builtIn() { |
| - createParser('..as'); |
| - Expression expression = parser.parseCascadeSection(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<PropertyAccess>()); |
| - PropertyAccess section = expression; |
| - expect(section.target, isNull); |
| - expect(section.operator, isNotNull); |
| - expect(section.propertyName, isNotNull); |
| + void test_equalityExpression_missing_LHS() { |
| + BinaryExpression expression = |
| + parseExpression("== y", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.leftOperand); |
| + expect(expression.leftOperand.isSynthetic, isTrue); |
| } |
| - void test_parseCascadeSection_pa() { |
| - createParser('..a(b)'); |
| - Expression expression = parser.parseCascadeSection(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<MethodInvocation>()); |
| - MethodInvocation section = expression; |
| - expect(section.target, isNull); |
| - expect(section.operator, isNotNull); |
| - expect(section.methodName, isNotNull); |
| - expect(section.typeArguments, isNull); |
| - expect(section.argumentList, isNotNull); |
| - expect(section.argumentList.arguments, hasLength(1)); |
| + void test_equalityExpression_missing_LHS_RHS() { |
| + BinaryExpression expression = parseExpression("==", [ |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER |
| + ]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.leftOperand); |
| + expect(expression.leftOperand.isSynthetic, isTrue); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.rightOperand); |
| + expect(expression.rightOperand.isSynthetic, isTrue); |
| } |
| - void test_parseCascadeSection_pa_typeArgumentComments() { |
| - enableGenericMethodComments = true; |
| - createParser('..a/*<E>*/(b)'); |
| - Expression expression = parser.parseCascadeSection(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<MethodInvocation>()); |
| - MethodInvocation section = expression; |
| - expect(section.target, isNull); |
| - expect(section.operator, isNotNull); |
| - expect(section.methodName, isNotNull); |
| - expect(section.typeArguments, isNotNull); |
| - expect(section.argumentList, isNotNull); |
| - expect(section.argumentList.arguments, hasLength(1)); |
| + void test_equalityExpression_missing_RHS() { |
| + BinaryExpression expression = |
| + parseExpression("x ==", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.rightOperand); |
| + expect(expression.rightOperand.isSynthetic, isTrue); |
| } |
| - void test_parseCascadeSection_pa_typeArguments() { |
| - createParser('..a<E>(b)'); |
| - Expression expression = parser.parseCascadeSection(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<MethodInvocation>()); |
| - MethodInvocation section = expression; |
| - expect(section.target, isNull); |
| - expect(section.operator, isNotNull); |
| - expect(section.methodName, isNotNull); |
| - expect(section.typeArguments, isNotNull); |
| - expect(section.argumentList, isNotNull); |
| - expect(section.argumentList.arguments, hasLength(1)); |
| + void test_equalityExpression_missing_RHS_super() { |
| + BinaryExpression expression = |
| + parseExpression("super ==", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.rightOperand); |
| + expect(expression.rightOperand.isSynthetic, isTrue); |
| } |
| - void test_parseCascadeSection_paa() { |
| - createParser('..a(b)(c)'); |
| - Expression expression = parser.parseCascadeSection(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<FunctionExpressionInvocation>()); |
| - FunctionExpressionInvocation section = expression; |
| - expect(section.function, new isInstanceOf<MethodInvocation>()); |
| - expect(section.typeArguments, isNull); |
| - expect(section.argumentList, isNotNull); |
| - expect(section.argumentList.arguments, hasLength(1)); |
| + void test_equalityExpression_precedence_relational_left() { |
| + BinaryExpression expression = parseExpression("is ==", [ |
| + ParserErrorCode.EXPECTED_TYPE_NAME, |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER |
| + ]); |
| + EngineTestCase.assertInstanceOf( |
| + (obj) => obj is IsExpression, IsExpression, expression.leftOperand); |
| } |
| - void test_parseCascadeSection_paa_typeArgumentComments() { |
| - enableGenericMethodComments = true; |
| - createParser('..a/*<E>*/(b)/*<F>*/(c)'); |
| - Expression expression = parser.parseCascadeSection(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<FunctionExpressionInvocation>()); |
| - FunctionExpressionInvocation section = expression; |
| - expect(section.function, new isInstanceOf<MethodInvocation>()); |
| - expect(section.typeArguments, isNotNull); |
| - expect(section.argumentList, isNotNull); |
| - expect(section.argumentList.arguments, hasLength(1)); |
| + void test_equalityExpression_precedence_relational_right() { |
| + BinaryExpression expression = parseExpression("== is", [ |
| + ParserErrorCode.EXPECTED_TYPE_NAME, |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER |
| + ]); |
| + EngineTestCase.assertInstanceOf( |
| + (obj) => obj is IsExpression, IsExpression, expression.rightOperand); |
| } |
| - void test_parseCascadeSection_paa_typeArguments() { |
| - createParser('..a<E>(b)<F>(c)'); |
| - Expression expression = parser.parseCascadeSection(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<FunctionExpressionInvocation>()); |
| - FunctionExpressionInvocation section = expression; |
| - expect(section.function, new isInstanceOf<MethodInvocation>()); |
| - expect(section.typeArguments, isNotNull); |
| - expect(section.argumentList, isNotNull); |
| - expect(section.argumentList.arguments, hasLength(1)); |
| + void test_equalityExpression_super() { |
| + BinaryExpression expression = parseExpression("super == ==", [ |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND |
| + ]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| + BinaryExpression, expression.leftOperand); |
| } |
| - void test_parseCascadeSection_paapaa() { |
| - createParser('..a(b)(c).d(e)(f)'); |
| - Expression expression = parser.parseCascadeSection(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<FunctionExpressionInvocation>()); |
| - FunctionExpressionInvocation section = expression; |
| - expect(section.function, new isInstanceOf<MethodInvocation>()); |
| - expect(section.typeArguments, isNull); |
| - expect(section.argumentList, isNotNull); |
| - expect(section.argumentList.arguments, hasLength(1)); |
| + void test_expressionList_multiple_end() { |
| + createParser(', 2, 3, 4'); |
| + List<Expression> result = parser.parseExpressionList(); |
| + expectNotNullIfNoErrors(result); |
| + listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| + expect(result, hasLength(4)); |
| + Expression syntheticExpression = result[0]; |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, syntheticExpression); |
| + expect(syntheticExpression.isSynthetic, isTrue); |
| } |
| - void test_parseCascadeSection_paapaa_typeArgumentComments() { |
| - enableGenericMethodComments = true; |
| - createParser('..a/*<E>*/(b)/*<F>*/(c).d/*<G>*/(e)/*<H>*/(f)'); |
| - Expression expression = parser.parseCascadeSection(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<FunctionExpressionInvocation>()); |
| - FunctionExpressionInvocation section = expression; |
| - expect(section.function, new isInstanceOf<MethodInvocation>()); |
| - expect(section.typeArguments, isNotNull); |
| - expect(section.argumentList, isNotNull); |
| - expect(section.argumentList.arguments, hasLength(1)); |
| + void test_expressionList_multiple_middle() { |
| + createParser('1, 2, , 4'); |
| + List<Expression> result = parser.parseExpressionList(); |
| + expectNotNullIfNoErrors(result); |
| + listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| + expect(result, hasLength(4)); |
| + Expression syntheticExpression = result[2]; |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, syntheticExpression); |
| + expect(syntheticExpression.isSynthetic, isTrue); |
| } |
| - void test_parseCascadeSection_paapaa_typeArguments() { |
| - createParser('..a<E>(b)<F>(c).d<G>(e)<H>(f)'); |
| - Expression expression = parser.parseCascadeSection(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<FunctionExpressionInvocation>()); |
| - FunctionExpressionInvocation section = expression; |
| - expect(section.function, new isInstanceOf<MethodInvocation>()); |
| - expect(section.typeArguments, isNotNull); |
| - expect(section.argumentList, isNotNull); |
| - expect(section.argumentList.arguments, hasLength(1)); |
| + void test_expressionList_multiple_start() { |
| + createParser('1, 2, 3,'); |
| + List<Expression> result = parser.parseExpressionList(); |
| + expectNotNullIfNoErrors(result); |
| + listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| + expect(result, hasLength(4)); |
| + Expression syntheticExpression = result[3]; |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, syntheticExpression); |
| + expect(syntheticExpression.isSynthetic, isTrue); |
| } |
| - void test_parseCascadeSection_pap() { |
| - createParser('..a(b).c'); |
| - Expression expression = parser.parseCascadeSection(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<PropertyAccess>()); |
| - PropertyAccess section = expression; |
| - expect(section.target, isNotNull); |
| - expect(section.operator, isNotNull); |
| - expect(section.propertyName, isNotNull); |
| + void test_functionExpression_in_ConstructorFieldInitializer() { |
| + CompilationUnit unit = parseCompilationUnit( |
| + "class A { A() : a = (){}; var v; }", |
| + [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.UNEXPECTED_TOKEN]); |
| + // Make sure we recovered and parsed "var v" correctly |
| + ClassDeclaration declaration = unit.declarations[0] as ClassDeclaration; |
| + NodeList<ClassMember> members = declaration.members; |
| + ClassMember fieldDecl = members[1]; |
| + EngineTestCase.assertInstanceOf( |
| + (obj) => obj is FieldDeclaration, FieldDeclaration, fieldDecl); |
| + NodeList<VariableDeclaration> vars = |
| + (fieldDecl as FieldDeclaration).fields.variables; |
| + expect(vars, hasLength(1)); |
| + expect(vars[0].name.name, "v"); |
| } |
| - void test_parseCascadeSection_pap_typeArgumentComments() { |
| - enableGenericMethodComments = true; |
| - createParser('..a/*<E>*/(b).c'); |
| - Expression expression = parser.parseCascadeSection(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<PropertyAccess>()); |
| - PropertyAccess section = expression; |
| - expect(section.target, isNotNull); |
| - expect(section.operator, isNotNull); |
| - expect(section.propertyName, isNotNull); |
| + void test_functionExpression_named() { |
| + parseExpression("m(f() => 0);", [ParserErrorCode.EXPECTED_TOKEN]); |
| } |
| - void test_parseCascadeSection_pap_typeArguments() { |
| - createParser('..a<E>(b).c'); |
| - Expression expression = parser.parseCascadeSection(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<PropertyAccess>()); |
| - PropertyAccess section = expression; |
| - expect(section.target, isNotNull); |
| - expect(section.operator, isNotNull); |
| - expect(section.propertyName, isNotNull); |
| + void test_importDirectivePartial_as() { |
| + CompilationUnit unit = parseCompilationUnit( |
| + "import 'b.dart' d as b;", [ParserErrorCode.UNEXPECTED_TOKEN]); |
| + ImportDirective importDirective = unit.childEntities.first; |
| + expect(importDirective.asKeyword, isNotNull); |
| + expect(unit.directives, hasLength(1)); |
| + expect(unit.declarations, hasLength(0)); |
| } |
| - void test_parseCombinator_hide() { |
| - createParser('hide a;'); |
| - Combinator combinator = parser.parseCombinator(); |
| - expectNotNullIfNoErrors(combinator); |
| - listener.assertNoErrors(); |
| - expect(combinator, new isInstanceOf<HideCombinator>()); |
| - HideCombinator hideCombinator = combinator; |
| - expect(hideCombinator.keyword, isNotNull); |
| - expect(hideCombinator.hiddenNames, hasLength(1)); |
| + void test_importDirectivePartial_hide() { |
| + CompilationUnit unit = parseCompilationUnit( |
| + "import 'b.dart' d hide foo;", [ParserErrorCode.UNEXPECTED_TOKEN]); |
| + ImportDirective importDirective = unit.childEntities.first; |
| + expect(importDirective.combinators, hasLength(1)); |
| + expect(unit.directives, hasLength(1)); |
| + expect(unit.declarations, hasLength(0)); |
| } |
| - void test_parseCombinator_show() { |
| - createParser('show a;'); |
| - Combinator combinator = parser.parseCombinator(); |
| - expectNotNullIfNoErrors(combinator); |
| - listener.assertNoErrors(); |
| - expect(combinator, new isInstanceOf<ShowCombinator>()); |
| - ShowCombinator showCombinator = combinator; |
| - expect(showCombinator.keyword, isNotNull); |
| - expect(showCombinator.shownNames, hasLength(1)); |
| + void test_importDirectivePartial_show() { |
| + CompilationUnit unit = parseCompilationUnit( |
| + "import 'b.dart' d show foo;", [ParserErrorCode.UNEXPECTED_TOKEN]); |
| + ImportDirective importDirective = unit.childEntities.first; |
| + expect(importDirective.combinators, hasLength(1)); |
| + expect(unit.directives, hasLength(1)); |
| + expect(unit.declarations, hasLength(0)); |
| } |
| - void test_parseCombinators_h() { |
| - createParser('hide a;'); |
| - List<Combinator> combinators = parser.parseCombinators(); |
| - expectNotNullIfNoErrors(combinators); |
| - listener.assertNoErrors(); |
| - expect(combinators, hasLength(1)); |
| - HideCombinator combinator = combinators[0] as HideCombinator; |
| - expect(combinator, isNotNull); |
| - expect(combinator.keyword, isNotNull); |
| - expect(combinator.hiddenNames, hasLength(1)); |
| + void test_incomplete_conditionalExpression() { |
| + parseExpression("x ? 0", |
| + [ParserErrorCode.EXPECTED_TOKEN, ParserErrorCode.MISSING_IDENTIFIER]); |
| } |
| - void test_parseCombinators_hs() { |
| - createParser('hide a show b;'); |
| - List<Combinator> combinators = parser.parseCombinators(); |
| - expectNotNullIfNoErrors(combinators); |
| - listener.assertNoErrors(); |
| - expect(combinators, hasLength(2)); |
| - HideCombinator hideCombinator = combinators[0] as HideCombinator; |
| - expect(hideCombinator, isNotNull); |
| - expect(hideCombinator.keyword, isNotNull); |
| - expect(hideCombinator.hiddenNames, hasLength(1)); |
| - ShowCombinator showCombinator = combinators[1] as ShowCombinator; |
| - expect(showCombinator, isNotNull); |
| - expect(showCombinator.keyword, isNotNull); |
| - expect(showCombinator.shownNames, hasLength(1)); |
| + void test_incomplete_constructorInitializers_empty() { |
| + createParser('C() : {}'); |
| + ClassMember member = parser.parseClassMember('C'); |
| + expectNotNullIfNoErrors(member); |
| + listener.assertErrorsWithCodes([ParserErrorCode.MISSING_INITIALIZER]); |
| } |
| - void test_parseCombinators_hshs() { |
| - createParser('hide a show b hide c show d;'); |
| - List<Combinator> combinators = parser.parseCombinators(); |
| - expectNotNullIfNoErrors(combinators); |
| - listener.assertNoErrors(); |
| - expect(combinators, hasLength(4)); |
| + void test_incomplete_constructorInitializers_missingEquals() { |
| + createParser('C() : x(3) {}'); |
| + ClassMember member = parser.parseClassMember('C'); |
| + expectNotNullIfNoErrors(member); |
| + listener.assertErrorsWithCodes( |
| + [ParserErrorCode.MISSING_ASSIGNMENT_IN_INITIALIZER]); |
| + expect(member, new isInstanceOf<ConstructorDeclaration>()); |
| + NodeList<ConstructorInitializer> initializers = |
| + (member as ConstructorDeclaration).initializers; |
| + expect(initializers, hasLength(1)); |
| + ConstructorInitializer initializer = initializers[0]; |
| + expect(initializer, new isInstanceOf<ConstructorFieldInitializer>()); |
| + Expression expression = |
| + (initializer as ConstructorFieldInitializer).expression; |
| + expect(expression, isNotNull); |
| + expect(expression, new isInstanceOf<ParenthesizedExpression>()); |
| } |
| - void test_parseCombinators_s() { |
| - createParser('show a;'); |
| - List<Combinator> combinators = parser.parseCombinators(); |
| - expectNotNullIfNoErrors(combinators); |
| - listener.assertNoErrors(); |
| - expect(combinators, hasLength(1)); |
| - ShowCombinator combinator = combinators[0] as ShowCombinator; |
| - expect(combinator, isNotNull); |
| - expect(combinator.keyword, isNotNull); |
| - expect(combinator.shownNames, hasLength(1)); |
| + void test_incomplete_constructorInitializers_variable() { |
| + createParser('C() : x {}'); |
| + ClassMember member = parser.parseClassMember('C'); |
| + expectNotNullIfNoErrors(member); |
| + listener.assertErrorsWithCodes( |
| + [ParserErrorCode.MISSING_ASSIGNMENT_IN_INITIALIZER]); |
| } |
| - void test_parseCommentAndMetadata_c() { |
| - createParser('/** 1 */ void'); |
| - CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| - expectNotNullIfNoErrors(commentAndMetadata); |
| - listener.assertNoErrors(); |
| - expect(commentAndMetadata.comment, isNotNull); |
| - expect(commentAndMetadata.metadata, isNull); |
| + @failingTest |
| + void test_incomplete_returnType() { |
| + parseCompilationUnit(r''' |
| +Map<Symbol, convertStringToSymbolMap(Map<String, dynamic> map) { |
| + if (map == null) return null; |
| + Map<Symbol, dynamic> result = new Map<Symbol, dynamic>(); |
| + map.forEach((name, value) { |
| + result[new Symbol(name)] = value; |
| + }); |
| + return result; |
| +}'''); |
| } |
| - void test_parseCommentAndMetadata_cmc() { |
| - createParser('/** 1 */ @A /** 2 */ void'); |
| - CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| - expectNotNullIfNoErrors(commentAndMetadata); |
| - listener.assertNoErrors(); |
| - expect(commentAndMetadata.comment, isNotNull); |
| - expect(commentAndMetadata.metadata, hasLength(1)); |
| + void test_incomplete_topLevelFunction() { |
| + parseCompilationUnit("foo();", [ParserErrorCode.MISSING_FUNCTION_BODY]); |
| } |
| - void test_parseCommentAndMetadata_cmcm() { |
| - createParser('/** 1 */ @A /** 2 */ @B void'); |
| - CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| - expectNotNullIfNoErrors(commentAndMetadata); |
| - listener.assertNoErrors(); |
| - expect(commentAndMetadata.comment, isNotNull); |
| - expect(commentAndMetadata.metadata, hasLength(2)); |
| + void test_incomplete_topLevelVariable() { |
| + CompilationUnit unit = |
| + parseCompilationUnit("String", [ParserErrorCode.EXPECTED_EXECUTABLE]); |
| + NodeList<CompilationUnitMember> declarations = unit.declarations; |
| + expect(declarations, hasLength(1)); |
| + CompilationUnitMember member = declarations[0]; |
| + EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableDeclaration, |
| + TopLevelVariableDeclaration, member); |
| + NodeList<VariableDeclaration> variables = |
| + (member as TopLevelVariableDeclaration).variables.variables; |
| + expect(variables, hasLength(1)); |
| + SimpleIdentifier name = variables[0].name; |
| + expect(name.isSynthetic, isTrue); |
| } |
| - void test_parseCommentAndMetadata_cmm() { |
| - createParser('/** 1 */ @A @B void'); |
| - CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| - expectNotNullIfNoErrors(commentAndMetadata); |
| - listener.assertNoErrors(); |
| - expect(commentAndMetadata.comment, isNotNull); |
| - expect(commentAndMetadata.metadata, hasLength(2)); |
| + void test_incomplete_topLevelVariable_const() { |
| + CompilationUnit unit = parseCompilationUnit("const ", |
| + [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); |
| + NodeList<CompilationUnitMember> declarations = unit.declarations; |
| + expect(declarations, hasLength(1)); |
| + CompilationUnitMember member = declarations[0]; |
| + EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableDeclaration, |
| + TopLevelVariableDeclaration, member); |
| + NodeList<VariableDeclaration> variables = |
| + (member as TopLevelVariableDeclaration).variables.variables; |
| + expect(variables, hasLength(1)); |
| + SimpleIdentifier name = variables[0].name; |
| + expect(name.isSynthetic, isTrue); |
| } |
| - void test_parseCommentAndMetadata_m() { |
| - createParser('@A void'); |
| - CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| - expectNotNullIfNoErrors(commentAndMetadata); |
| - listener.assertNoErrors(); |
| - expect(commentAndMetadata.comment, isNull); |
| - expect(commentAndMetadata.metadata, hasLength(1)); |
| + void test_incomplete_topLevelVariable_final() { |
| + CompilationUnit unit = parseCompilationUnit("final ", |
| + [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); |
| + NodeList<CompilationUnitMember> declarations = unit.declarations; |
| + expect(declarations, hasLength(1)); |
| + CompilationUnitMember member = declarations[0]; |
| + EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableDeclaration, |
| + TopLevelVariableDeclaration, member); |
| + NodeList<VariableDeclaration> variables = |
| + (member as TopLevelVariableDeclaration).variables.variables; |
| + expect(variables, hasLength(1)); |
| + SimpleIdentifier name = variables[0].name; |
| + expect(name.isSynthetic, isTrue); |
| } |
| - void test_parseCommentAndMetadata_mcm() { |
| - createParser('@A /** 1 */ @B void'); |
| - CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| - expectNotNullIfNoErrors(commentAndMetadata); |
| - listener.assertNoErrors(); |
| - expect(commentAndMetadata.comment, isNotNull); |
| - expect(commentAndMetadata.metadata, hasLength(2)); |
| + void test_incomplete_topLevelVariable_var() { |
| + CompilationUnit unit = parseCompilationUnit("var ", |
| + [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); |
| + NodeList<CompilationUnitMember> declarations = unit.declarations; |
| + expect(declarations, hasLength(1)); |
| + CompilationUnitMember member = declarations[0]; |
| + EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableDeclaration, |
| + TopLevelVariableDeclaration, member); |
| + NodeList<VariableDeclaration> variables = |
| + (member as TopLevelVariableDeclaration).variables.variables; |
| + expect(variables, hasLength(1)); |
| + SimpleIdentifier name = variables[0].name; |
| + expect(name.isSynthetic, isTrue); |
| } |
| - void test_parseCommentAndMetadata_mcmc() { |
| - createParser('@A /** 1 */ @B /** 2 */ void'); |
| - CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| - expectNotNullIfNoErrors(commentAndMetadata); |
| - listener.assertNoErrors(); |
| - expect(commentAndMetadata.comment, isNotNull); |
| - expect(commentAndMetadata.metadata, hasLength(2)); |
| + void test_incompleteField_const() { |
| + CompilationUnit unit = parseCompilationUnit( |
| + r''' |
| +class C { |
| + const |
| +}''', |
| + [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); |
| + NodeList<CompilationUnitMember> declarations = unit.declarations; |
| + expect(declarations, hasLength(1)); |
| + CompilationUnitMember unitMember = declarations[0]; |
| + EngineTestCase.assertInstanceOf( |
| + (obj) => obj is ClassDeclaration, ClassDeclaration, unitMember); |
| + NodeList<ClassMember> members = (unitMember as ClassDeclaration).members; |
| + expect(members, hasLength(1)); |
| + ClassMember classMember = members[0]; |
| + EngineTestCase.assertInstanceOf( |
| + (obj) => obj is FieldDeclaration, FieldDeclaration, classMember); |
| + VariableDeclarationList fieldList = |
| + (classMember as FieldDeclaration).fields; |
| + expect(fieldList.keyword.keyword, Keyword.CONST); |
| + NodeList<VariableDeclaration> fields = fieldList.variables; |
| + expect(fields, hasLength(1)); |
| + VariableDeclaration field = fields[0]; |
| + expect(field.name.isSynthetic, isTrue); |
| } |
| - void test_parseCommentAndMetadata_mm() { |
| - createParser('@A @B(x) void'); |
| - CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| - expectNotNullIfNoErrors(commentAndMetadata); |
| - listener.assertNoErrors(); |
| - expect(commentAndMetadata.comment, isNull); |
| - expect(commentAndMetadata.metadata, hasLength(2)); |
| + void test_incompleteField_final() { |
| + CompilationUnit unit = parseCompilationUnit( |
| + r''' |
| +class C { |
| + final |
| +}''', |
| + [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); |
| + NodeList<CompilationUnitMember> declarations = unit.declarations; |
| + expect(declarations, hasLength(1)); |
| + CompilationUnitMember unitMember = declarations[0]; |
| + EngineTestCase.assertInstanceOf( |
| + (obj) => obj is ClassDeclaration, ClassDeclaration, unitMember); |
| + NodeList<ClassMember> members = (unitMember as ClassDeclaration).members; |
| + expect(members, hasLength(1)); |
| + ClassMember classMember = members[0]; |
| + EngineTestCase.assertInstanceOf( |
| + (obj) => obj is FieldDeclaration, FieldDeclaration, classMember); |
| + VariableDeclarationList fieldList = |
| + (classMember as FieldDeclaration).fields; |
| + expect(fieldList.keyword.keyword, Keyword.FINAL); |
| + NodeList<VariableDeclaration> fields = fieldList.variables; |
| + expect(fields, hasLength(1)); |
| + VariableDeclaration field = fields[0]; |
| + expect(field.name.isSynthetic, isTrue); |
| } |
| - void test_parseCommentAndMetadata_none() { |
| - createParser('void'); |
| - CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| - expectNotNullIfNoErrors(commentAndMetadata); |
| - listener.assertNoErrors(); |
| - expect(commentAndMetadata.comment, isNull); |
| - expect(commentAndMetadata.metadata, isNull); |
| + void test_incompleteField_var() { |
| + CompilationUnit unit = parseCompilationUnit( |
| + r''' |
| +class C { |
| + var |
| +}''', |
| + [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); |
| + NodeList<CompilationUnitMember> declarations = unit.declarations; |
| + expect(declarations, hasLength(1)); |
| + CompilationUnitMember unitMember = declarations[0]; |
| + EngineTestCase.assertInstanceOf( |
| + (obj) => obj is ClassDeclaration, ClassDeclaration, unitMember); |
| + NodeList<ClassMember> members = (unitMember as ClassDeclaration).members; |
| + expect(members, hasLength(1)); |
| + ClassMember classMember = members[0]; |
| + EngineTestCase.assertInstanceOf( |
| + (obj) => obj is FieldDeclaration, FieldDeclaration, classMember); |
| + VariableDeclarationList fieldList = |
| + (classMember as FieldDeclaration).fields; |
| + expect(fieldList.keyword.keyword, Keyword.VAR); |
| + NodeList<VariableDeclaration> fields = fieldList.variables; |
| + expect(fields, hasLength(1)); |
| + VariableDeclaration field = fields[0]; |
| + expect(field.name.isSynthetic, isTrue); |
| } |
| - void test_parseCommentAndMetadata_singleLine() { |
| - createParser(r''' |
| -/// 1 |
| -/// 2 |
| -void'''); |
| - CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| - expectNotNullIfNoErrors(commentAndMetadata); |
| - listener.assertNoErrors(); |
| - expect(commentAndMetadata.comment, isNotNull); |
| - expect(commentAndMetadata.metadata, isNull); |
| + void test_incompleteForEach() { |
| + ForStatement statement = parseStatement('for (String item i) {}', |
| + [ParserErrorCode.EXPECTED_TOKEN, ParserErrorCode.EXPECTED_TOKEN]); |
| + expect(statement, new isInstanceOf<ForStatement>()); |
| + expect(statement.toSource(), 'for (String item; i;) {}'); |
| + expect(statement.leftSeparator, isNotNull); |
| + expect(statement.leftSeparator.type, TokenType.SEMICOLON); |
| + expect(statement.rightSeparator, isNotNull); |
| + expect(statement.rightSeparator.type, TokenType.SEMICOLON); |
| } |
| - void test_parseCommentReference_new_prefixed() { |
| - createParser(''); |
| - CommentReference reference = parser.parseCommentReference('new a.b', 7); |
| - expectNotNullIfNoErrors(reference); |
| - listener.assertNoErrors(); |
| - expect(reference.identifier, new isInstanceOf<PrefixedIdentifier>()); |
| - PrefixedIdentifier prefixedIdentifier = reference.identifier; |
| - SimpleIdentifier prefix = prefixedIdentifier.prefix; |
| - expect(prefix.token, isNotNull); |
| - expect(prefix.name, "a"); |
| - expect(prefix.offset, 11); |
| - expect(prefixedIdentifier.period, isNotNull); |
| - SimpleIdentifier identifier = prefixedIdentifier.identifier; |
| - expect(identifier.token, isNotNull); |
| - expect(identifier.name, "b"); |
| - expect(identifier.offset, 13); |
| + void test_incompleteLocalVariable_atTheEndOfBlock() { |
| + Statement statement = |
| + parseStatement('String v }', [ParserErrorCode.EXPECTED_TOKEN]); |
| + expect(statement, new isInstanceOf<VariableDeclarationStatement>()); |
| + expect(statement.toSource(), 'String v;'); |
| } |
| - void test_parseCommentReference_new_simple() { |
| - createParser(''); |
| - CommentReference reference = parser.parseCommentReference('new a', 5); |
| - expectNotNullIfNoErrors(reference); |
| - listener.assertNoErrors(); |
| - expect(reference.identifier, new isInstanceOf<SimpleIdentifier>()); |
| - SimpleIdentifier identifier = reference.identifier; |
| - expect(identifier.token, isNotNull); |
| - expect(identifier.name, "a"); |
| - expect(identifier.offset, 9); |
| + void test_incompleteLocalVariable_beforeIdentifier() { |
| + Statement statement = |
| + parseStatement('String v String v2;', [ParserErrorCode.EXPECTED_TOKEN]); |
| + expect(statement, new isInstanceOf<VariableDeclarationStatement>()); |
| + expect(statement.toSource(), 'String v;'); |
| } |
| - void test_parseCommentReference_operator_withKeyword_notPrefixed() { |
| - createParser(''); |
| - CommentReference reference = parser.parseCommentReference('operator ==', 5); |
| - expectNotNullIfNoErrors(reference); |
| - listener.assertNoErrors(); |
| - expect(reference.identifier, new isInstanceOf<SimpleIdentifier>()); |
| - SimpleIdentifier identifier = reference.identifier; |
| - expect(identifier.token, isNotNull); |
| - expect(identifier.name, "=="); |
| - expect(identifier.offset, 14); |
| + void test_incompleteLocalVariable_beforeKeyword() { |
| + Statement statement = parseStatement( |
| + 'String v if (true) {}', [ParserErrorCode.EXPECTED_TOKEN]); |
| + expect(statement, new isInstanceOf<VariableDeclarationStatement>()); |
| + expect(statement.toSource(), 'String v;'); |
| } |
| - void test_parseCommentReference_operator_withKeyword_prefixed() { |
| - createParser(''); |
| - CommentReference reference = |
| - parser.parseCommentReference('Object.operator==', 7); |
| - expectNotNullIfNoErrors(reference); |
| - listener.assertNoErrors(); |
| - expect(reference.identifier, new isInstanceOf<PrefixedIdentifier>()); |
| - PrefixedIdentifier prefixedIdentifier = reference.identifier; |
| - SimpleIdentifier prefix = prefixedIdentifier.prefix; |
| - expect(prefix.token, isNotNull); |
| - expect(prefix.name, "Object"); |
| - expect(prefix.offset, 7); |
| - expect(prefixedIdentifier.period, isNotNull); |
| - SimpleIdentifier identifier = prefixedIdentifier.identifier; |
| - expect(identifier.token, isNotNull); |
| - expect(identifier.name, "=="); |
| - expect(identifier.offset, 22); |
| + void test_incompleteLocalVariable_beforeNextBlock() { |
| + Statement statement = |
| + parseStatement('String v {}', [ParserErrorCode.EXPECTED_TOKEN]); |
| + expect(statement, new isInstanceOf<VariableDeclarationStatement>()); |
| + expect(statement.toSource(), 'String v;'); |
| } |
| - void test_parseCommentReference_operator_withoutKeyword_notPrefixed() { |
| - createParser(''); |
| - CommentReference reference = parser.parseCommentReference('==', 5); |
| - expectNotNullIfNoErrors(reference); |
| - listener.assertNoErrors(); |
| - expect(reference.identifier, new isInstanceOf<SimpleIdentifier>()); |
| - SimpleIdentifier identifier = reference.identifier; |
| - expect(identifier.token, isNotNull); |
| - expect(identifier.name, "=="); |
| - expect(identifier.offset, 5); |
| + void test_incompleteLocalVariable_parameterizedType() { |
| + Statement statement = |
| + parseStatement('List<String> v {}', [ParserErrorCode.EXPECTED_TOKEN]); |
| + expect(statement, new isInstanceOf<VariableDeclarationStatement>()); |
| + expect(statement.toSource(), 'List<String> v;'); |
| } |
| - void test_parseCommentReference_operator_withoutKeyword_prefixed() { |
| - createParser(''); |
| - CommentReference reference = parser.parseCommentReference('Object.==', 7); |
| - expectNotNullIfNoErrors(reference); |
| - listener.assertNoErrors(); |
| - expect(reference.identifier, new isInstanceOf<PrefixedIdentifier>()); |
| - PrefixedIdentifier prefixedIdentifier = reference.identifier; |
| - SimpleIdentifier prefix = prefixedIdentifier.prefix; |
| - expect(prefix.token, isNotNull); |
| - expect(prefix.name, "Object"); |
| - expect(prefix.offset, 7); |
| - expect(prefixedIdentifier.period, isNotNull); |
| - SimpleIdentifier identifier = prefixedIdentifier.identifier; |
| - expect(identifier.token, isNotNull); |
| - expect(identifier.name, "=="); |
| - expect(identifier.offset, 14); |
| + void test_incompleteTypeArguments_field() { |
| + CompilationUnit unit = parseCompilationUnit( |
| + r''' |
| +class C { |
| + final List<int f; |
| +}''', |
| + [ParserErrorCode.EXPECTED_TOKEN]); |
| + // one class |
| + List<CompilationUnitMember> declarations = unit.declarations; |
| + expect(declarations, hasLength(1)); |
| + ClassDeclaration classDecl = declarations[0] as ClassDeclaration; |
| + // one field declaration |
| + List<ClassMember> members = classDecl.members; |
| + expect(members, hasLength(1)); |
| + FieldDeclaration fieldDecl = members[0] as FieldDeclaration; |
| + // one field |
| + VariableDeclarationList fieldList = fieldDecl.fields; |
| + List<VariableDeclaration> fields = fieldList.variables; |
| + expect(fields, hasLength(1)); |
| + VariableDeclaration field = fields[0]; |
| + expect(field.name.name, 'f'); |
| + // validate the type |
| + TypeArgumentList typeArguments = (fieldList.type as TypeName).typeArguments; |
| + expect(typeArguments.arguments, hasLength(1)); |
| + // synthetic '>' |
| + Token token = typeArguments.endToken; |
| + expect(token.type, TokenType.GT); |
| + expect(token.isSynthetic, isTrue); |
| } |
| - void test_parseCommentReference_prefixed() { |
| - createParser(''); |
| - CommentReference reference = parser.parseCommentReference('a.b', 7); |
| - expectNotNullIfNoErrors(reference); |
| - listener.assertNoErrors(); |
| - expect(reference.identifier, new isInstanceOf<PrefixedIdentifier>()); |
| - PrefixedIdentifier prefixedIdentifier = reference.identifier; |
| - SimpleIdentifier prefix = prefixedIdentifier.prefix; |
| - expect(prefix.token, isNotNull); |
| - expect(prefix.name, "a"); |
| - expect(prefix.offset, 7); |
| - expect(prefixedIdentifier.period, isNotNull); |
| - SimpleIdentifier identifier = prefixedIdentifier.identifier; |
| - expect(identifier.token, isNotNull); |
| - expect(identifier.name, "b"); |
| - expect(identifier.offset, 9); |
| + void test_incompleteTypeParameters() { |
| + CompilationUnit unit = parseCompilationUnit( |
| + r''' |
| +class C<K { |
| +}''', |
| + [ParserErrorCode.EXPECTED_TOKEN]); |
| + // one class |
| + List<CompilationUnitMember> declarations = unit.declarations; |
| + expect(declarations, hasLength(1)); |
| + ClassDeclaration classDecl = declarations[0] as ClassDeclaration; |
| + // validate the type parameters |
| + TypeParameterList typeParameters = classDecl.typeParameters; |
| + expect(typeParameters.typeParameters, hasLength(1)); |
| + // synthetic '>' |
| + Token token = typeParameters.endToken; |
| + expect(token.type, TokenType.GT); |
| + expect(token.isSynthetic, isTrue); |
| } |
| - void test_parseCommentReference_simple() { |
| - createParser(''); |
| - CommentReference reference = parser.parseCommentReference('a', 5); |
| - expectNotNullIfNoErrors(reference); |
| - listener.assertNoErrors(); |
| - expect(reference.identifier, new isInstanceOf<SimpleIdentifier>()); |
| - SimpleIdentifier identifier = reference.identifier; |
| - expect(identifier.token, isNotNull); |
| - expect(identifier.name, "a"); |
| - expect(identifier.offset, 5); |
| + void test_invalidFunctionBodyModifier() { |
| + parseCompilationUnit( |
| + "f() sync {}", [ParserErrorCode.MISSING_STAR_AFTER_SYNC]); |
| } |
| - void test_parseCommentReference_synthetic() { |
| - createParser(''); |
| - CommentReference reference = parser.parseCommentReference('', 5); |
| - expectNotNullIfNoErrors(reference); |
| - listener.assertNoErrors(); |
| - expect(reference.identifier, new isInstanceOf<SimpleIdentifier>()); |
| - SimpleIdentifier identifier = reference.identifier; |
| - expect(identifier, isNotNull); |
| - expect(identifier.isSynthetic, isTrue); |
| - expect(identifier.token, isNotNull); |
| - expect(identifier.name, ""); |
| - expect(identifier.offset, 5); |
| - // Should end with EOF token. |
| - Token nextToken = identifier.token.next; |
| - expect(nextToken, isNotNull); |
| - expect(nextToken.type, TokenType.EOF); |
| + void test_isExpression_noType() { |
| + CompilationUnit unit = parseCompilationUnit( |
| + "class Bar<T extends Foo> {m(x){if (x is ) return;if (x is !)}}", [ |
| + ParserErrorCode.EXPECTED_TYPE_NAME, |
| + ParserErrorCode.EXPECTED_TYPE_NAME, |
| + ParserErrorCode.MISSING_STATEMENT |
| + ]); |
| + ClassDeclaration declaration = unit.declarations[0] as ClassDeclaration; |
| + MethodDeclaration method = declaration.members[0] as MethodDeclaration; |
| + BlockFunctionBody body = method.body as BlockFunctionBody; |
| + IfStatement ifStatement = body.block.statements[1] as IfStatement; |
| + IsExpression expression = ifStatement.condition as IsExpression; |
| + expect(expression.expression, isNotNull); |
| + expect(expression.isOperator, isNotNull); |
| + expect(expression.notOperator, isNotNull); |
| + TypeAnnotation type = expression.type; |
| + expect(type, isNotNull); |
| + expect(type is TypeName && type.name.isSynthetic, isTrue); |
| + EngineTestCase.assertInstanceOf((obj) => obj is EmptyStatement, |
| + EmptyStatement, ifStatement.thenStatement); |
| } |
| - @failingTest |
| - void test_parseCommentReference_this() { |
| - // This fails because we are returning null from the method and asserting |
| - // that the return value is not null. |
| - createParser(''); |
| - CommentReference reference = parser.parseCommentReference('this', 5); |
| - expectNotNullIfNoErrors(reference); |
| - listener.assertNoErrors(); |
| - SimpleIdentifier identifier = EngineTestCase.assertInstanceOf( |
| - (obj) => obj is SimpleIdentifier, |
| - SimpleIdentifier, |
| - reference.identifier); |
| - expect(identifier.token, isNotNull); |
| - expect(identifier.name, "a"); |
| - expect(identifier.offset, 5); |
| + void test_keywordInPlaceOfIdentifier() { |
| + // TODO(brianwilkerson) We could do better with this. |
| + parseCompilationUnit("do() {}", [ |
| + ParserErrorCode.EXPECTED_EXECUTABLE, |
| + ParserErrorCode.UNEXPECTED_TOKEN |
| + ]); |
| } |
| - void test_parseCommentReferences_multiLine() { |
| - DocumentationCommentToken token = new DocumentationCommentToken( |
| - TokenType.MULTI_LINE_COMMENT, "/** xxx [a] yyy [bb] zzz */", 3); |
| - List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[token]; |
| - createParser(''); |
| - List<CommentReference> references = parser.parseCommentReferences(tokens); |
| - expectNotNullIfNoErrors(references); |
| - listener.assertNoErrors(); |
| - List<Token> tokenReferences = token.references; |
| - expect(references, hasLength(2)); |
| - expect(tokenReferences, hasLength(2)); |
| - { |
| - CommentReference reference = references[0]; |
| - expect(reference, isNotNull); |
| - expect(reference.identifier, isNotNull); |
| - expect(reference.offset, 12); |
| - // the reference is recorded in the comment token |
| - Token referenceToken = tokenReferences[0]; |
| - expect(referenceToken.offset, 12); |
| - expect(referenceToken.lexeme, 'a'); |
| - } |
| - { |
| - CommentReference reference = references[1]; |
| - expect(reference, isNotNull); |
| - expect(reference.identifier, isNotNull); |
| - expect(reference.offset, 20); |
| - // the reference is recorded in the comment token |
| - Token referenceToken = tokenReferences[1]; |
| - expect(referenceToken.offset, 20); |
| - expect(referenceToken.lexeme, 'bb'); |
| - } |
| + void test_logicalAndExpression_missing_LHS() { |
| + BinaryExpression expression = |
| + parseExpression("&& y", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.leftOperand); |
| + expect(expression.leftOperand.isSynthetic, isTrue); |
| } |
| - void test_parseCommentReferences_notClosed_noIdentifier() { |
| - DocumentationCommentToken docToken = new DocumentationCommentToken( |
| - TokenType.MULTI_LINE_COMMENT, "/** [ some text", 5); |
| - createParser(''); |
| - List<CommentReference> references = |
| - parser.parseCommentReferences(<DocumentationCommentToken>[docToken]); |
| - expectNotNullIfNoErrors(references); |
| - listener.assertNoErrors(); |
| - expect(docToken.references, hasLength(1)); |
| - expect(references, hasLength(1)); |
| - Token referenceToken = docToken.references[0]; |
| - CommentReference reference = references[0]; |
| - expect(reference, isNotNull); |
| - expect(docToken.references[0], same(reference.beginToken)); |
| - expect(reference.identifier, isNotNull); |
| - expect(reference.identifier.isSynthetic, isTrue); |
| - expect(reference.identifier.name, ""); |
| - // Should end with EOF token. |
| - Token nextToken = referenceToken.next; |
| - expect(nextToken, isNotNull); |
| - expect(nextToken.type, TokenType.EOF); |
| + void test_logicalAndExpression_missing_LHS_RHS() { |
| + BinaryExpression expression = parseExpression("&&", [ |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER |
| + ]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.leftOperand); |
| + expect(expression.leftOperand.isSynthetic, isTrue); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.rightOperand); |
| + expect(expression.rightOperand.isSynthetic, isTrue); |
| } |
| - void test_parseCommentReferences_notClosed_withIdentifier() { |
| - DocumentationCommentToken docToken = new DocumentationCommentToken( |
| - TokenType.MULTI_LINE_COMMENT, "/** [namePrefix some text", 5); |
| - createParser(''); |
| - List<CommentReference> references = |
| - parser.parseCommentReferences(<DocumentationCommentToken>[docToken]); |
| - expectNotNullIfNoErrors(references); |
| - listener.assertNoErrors(); |
| - expect(docToken.references, hasLength(1)); |
| - expect(references, hasLength(1)); |
| - Token referenceToken = docToken.references[0]; |
| - CommentReference reference = references[0]; |
| - expect(reference, isNotNull); |
| - expect(referenceToken, same(reference.beginToken)); |
| - expect(reference.identifier, isNotNull); |
| - expect(reference.identifier.isSynthetic, isFalse); |
| - expect(reference.identifier.name, "namePrefix"); |
| - // Should end with EOF token. |
| - Token nextToken = referenceToken.next; |
| - expect(nextToken, isNotNull); |
| - expect(nextToken.type, TokenType.EOF); |
| + void test_logicalAndExpression_missing_RHS() { |
| + BinaryExpression expression = |
| + parseExpression("x &&", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.rightOperand); |
| + expect(expression.rightOperand.isSynthetic, isTrue); |
| } |
| - void test_parseCommentReferences_singleLine() { |
| - List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ |
| - new DocumentationCommentToken( |
| - TokenType.SINGLE_LINE_COMMENT, "/// xxx [a] yyy [b] zzz", 3), |
| - new DocumentationCommentToken( |
| - TokenType.SINGLE_LINE_COMMENT, "/// x [c]", 28) |
| - ]; |
| - createParser(''); |
| - List<CommentReference> references = parser.parseCommentReferences(tokens); |
| - expectNotNullIfNoErrors(references); |
| - listener.assertNoErrors(); |
| - expect(references, hasLength(3)); |
| - CommentReference reference = references[0]; |
| - expect(reference, isNotNull); |
| - expect(reference.identifier, isNotNull); |
| - expect(reference.offset, 12); |
| - reference = references[1]; |
| - expect(reference, isNotNull); |
| - expect(reference.identifier, isNotNull); |
| - expect(reference.offset, 20); |
| - reference = references[2]; |
| - expect(reference, isNotNull); |
| - expect(reference.identifier, isNotNull); |
| - expect(reference.offset, 35); |
| + void test_logicalAndExpression_precedence_bitwiseOr_left() { |
| + BinaryExpression expression = parseExpression("| &&", [ |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER |
| + ]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| + BinaryExpression, expression.leftOperand); |
| } |
| - void test_parseCommentReferences_skipCodeBlock_4spaces_block() { |
| - List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ |
| - new DocumentationCommentToken(TokenType.MULTI_LINE_COMMENT, |
| - "/**\n * a[i]\n * non-code line\n */", 3) |
| - ]; |
| - createParser(''); |
| - List<CommentReference> references = parser.parseCommentReferences(tokens); |
| - expectNotNullIfNoErrors(references); |
| - listener.assertNoErrors(); |
| - expect(references, isEmpty); |
| + void test_logicalAndExpression_precedence_bitwiseOr_right() { |
| + BinaryExpression expression = parseExpression("&& |", [ |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER |
| + ]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| + BinaryExpression, expression.rightOperand); |
| } |
| - void test_parseCommentReferences_skipCodeBlock_4spaces_lines() { |
| - List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ |
| - new DocumentationCommentToken( |
| - TokenType.SINGLE_LINE_COMMENT, "/// Code block:", 0), |
| - new DocumentationCommentToken( |
| - TokenType.SINGLE_LINE_COMMENT, "/// a[i] == b[i]", 0) |
| - ]; |
| - createParser(''); |
| - List<CommentReference> references = parser.parseCommentReferences(tokens); |
| - expectNotNullIfNoErrors(references); |
| - listener.assertNoErrors(); |
| - expect(references, isEmpty); |
| + void test_logicalOrExpression_missing_LHS() { |
| + BinaryExpression expression = |
| + parseExpression("|| y", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.leftOperand); |
| + expect(expression.leftOperand.isSynthetic, isTrue); |
| } |
| - void test_parseCommentReferences_skipCodeBlock_bracketed() { |
| - List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ |
| - new DocumentationCommentToken( |
| - TokenType.MULTI_LINE_COMMENT, "/** [:xxx [a] yyy:] [b] zzz */", 3) |
| - ]; |
| - createParser(''); |
| - List<CommentReference> references = parser.parseCommentReferences(tokens); |
| - expectNotNullIfNoErrors(references); |
| - listener.assertNoErrors(); |
| - expect(references, hasLength(1)); |
| - CommentReference reference = references[0]; |
| - expect(reference, isNotNull); |
| - expect(reference.identifier, isNotNull); |
| - expect(reference.offset, 24); |
| + void test_logicalOrExpression_missing_LHS_RHS() { |
| + BinaryExpression expression = parseExpression("||", [ |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER |
| + ]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.leftOperand); |
| + expect(expression.leftOperand.isSynthetic, isTrue); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.rightOperand); |
| + expect(expression.rightOperand.isSynthetic, isTrue); |
| } |
| - void test_parseCommentReferences_skipCodeBlock_gitHub() { |
| - List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ |
| - new DocumentationCommentToken( |
| - TokenType.MULTI_LINE_COMMENT, "/** `a[i]` and [b] */", 0) |
| - ]; |
| - createParser(''); |
| - List<CommentReference> references = parser.parseCommentReferences(tokens); |
| - expectNotNullIfNoErrors(references); |
| - listener.assertNoErrors(); |
| - expect(references, hasLength(1)); |
| - CommentReference reference = references[0]; |
| - expect(reference, isNotNull); |
| - expect(reference.identifier, isNotNull); |
| - expect(reference.offset, 16); |
| + void test_logicalOrExpression_missing_RHS() { |
| + BinaryExpression expression = |
| + parseExpression("x ||", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.rightOperand); |
| + expect(expression.rightOperand.isSynthetic, isTrue); |
| } |
| - void test_parseCommentReferences_skipCodeBlock_gitHub_multiLine() { |
| - List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ |
| - new DocumentationCommentToken( |
| - TokenType.MULTI_LINE_COMMENT, |
| - r''' |
| -/** |
| - * First. |
| - * ```dart |
| - * Some [int] reference. |
| - * ``` |
| - * Last. |
| - */ |
| -''', |
| - 3) |
| - ]; |
| - createParser(''); |
| - List<CommentReference> references = parser.parseCommentReferences(tokens); |
| - expectNotNullIfNoErrors(references); |
| - listener.assertNoErrors(); |
| - expect(references, isEmpty); |
| + void test_logicalOrExpression_precedence_logicalAnd_left() { |
| + BinaryExpression expression = parseExpression("&& ||", [ |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER |
| + ]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| + BinaryExpression, expression.leftOperand); |
| } |
| - void test_parseCommentReferences_skipCodeBlock_gitHub_multiLine_lines() { |
| - String commentText = r''' |
| -/// First. |
| -/// ```dart |
| -/// Some [int] reference. |
| -/// ``` |
| -/// Last. |
| -'''; |
| - List<DocumentationCommentToken> tokens = commentText |
| - .split('\n') |
| - .map((line) => new DocumentationCommentToken( |
| - TokenType.SINGLE_LINE_COMMENT, line, 0)) |
| - .toList(); |
| - createParser(''); |
| - List<CommentReference> references = parser.parseCommentReferences(tokens); |
| - expectNotNullIfNoErrors(references); |
| - listener.assertNoErrors(); |
| - expect(references, isEmpty); |
| + void test_logicalOrExpression_precedence_logicalAnd_right() { |
| + BinaryExpression expression = parseExpression("|| &&", [ |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER |
| + ]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| + BinaryExpression, expression.rightOperand); |
| } |
| - void test_parseCommentReferences_skipCodeBlock_gitHub_notTerminated() { |
| - List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ |
| - new DocumentationCommentToken( |
| - TokenType.MULTI_LINE_COMMENT, "/** `a[i] and [b] */", 0) |
| - ]; |
| - createParser(''); |
| - List<CommentReference> references = parser.parseCommentReferences(tokens); |
| - expectNotNullIfNoErrors(references); |
| - listener.assertNoErrors(); |
| - expect(references, hasLength(2)); |
| + void test_missing_commaInArgumentList() { |
| + parseExpression("f(x: 1 y: 2)", [ParserErrorCode.EXPECTED_TOKEN]); |
| } |
| - void test_parseCommentReferences_skipCodeBlock_spaces() { |
| - List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ |
| - new DocumentationCommentToken(TokenType.MULTI_LINE_COMMENT, |
| - "/**\n * a[i]\n * xxx [i] zzz\n */", 3) |
| - ]; |
| - createParser(''); |
| - List<CommentReference> references = parser.parseCommentReferences(tokens); |
| - expectNotNullIfNoErrors(references); |
| - listener.assertNoErrors(); |
| - expect(references, hasLength(1)); |
| - CommentReference reference = references[0]; |
| - expect(reference, isNotNull); |
| - expect(reference.identifier, isNotNull); |
| - expect(reference.offset, 27); |
| + void test_missingGet() { |
| + CompilationUnit unit = parseCompilationUnit( |
| + r''' |
| +class C { |
| + int length {} |
| + void foo() {} |
| +}''', |
| + [ParserErrorCode.MISSING_GET]); |
| + expect(unit, isNotNull); |
| + ClassDeclaration classDeclaration = |
| + unit.declarations[0] as ClassDeclaration; |
| + NodeList<ClassMember> members = classDeclaration.members; |
| + expect(members, hasLength(2)); |
| + EngineTestCase.assertInstanceOf( |
| + (obj) => obj is MethodDeclaration, MethodDeclaration, members[0]); |
| + ClassMember member = members[1]; |
| + EngineTestCase.assertInstanceOf( |
| + (obj) => obj is MethodDeclaration, MethodDeclaration, member); |
| + expect((member as MethodDeclaration).name.name, "foo"); |
| } |
| - void test_parseCommentReferences_skipLinkDefinition() { |
| - List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ |
| - new DocumentationCommentToken(TokenType.MULTI_LINE_COMMENT, |
| - "/** [a]: http://www.google.com (Google) [b] zzz */", 3) |
| - ]; |
| - createParser(''); |
| - List<CommentReference> references = parser.parseCommentReferences(tokens); |
| - expectNotNullIfNoErrors(references); |
| - listener.assertNoErrors(); |
| - expect(references, hasLength(1)); |
| - CommentReference reference = references[0]; |
| - expect(reference, isNotNull); |
| - expect(reference.identifier, isNotNull); |
| - expect(reference.offset, 44); |
| + void test_missingIdentifier_afterAnnotation() { |
| + createParser('@override }'); |
| + ClassMember member = parser.parseClassMember('C'); |
| + expectNotNullIfNoErrors(member); |
| + listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_CLASS_MEMBER]); |
| + expect(member, new isInstanceOf<MethodDeclaration>()); |
| + MethodDeclaration method = member; |
| + expect(method.documentationComment, isNull); |
| + NodeList<Annotation> metadata = method.metadata; |
| + expect(metadata, hasLength(1)); |
| + expect(metadata[0].name.name, "override"); |
| } |
| - void test_parseCommentReferences_skipLinked() { |
| - List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ |
| - new DocumentationCommentToken(TokenType.MULTI_LINE_COMMENT, |
| - "/** [a](http://www.google.com) [b] zzz */", 3) |
| - ]; |
| - createParser(''); |
| - List<CommentReference> references = parser.parseCommentReferences(tokens); |
| - expectNotNullIfNoErrors(references); |
| - listener.assertNoErrors(); |
| - expect(references, hasLength(1)); |
| - CommentReference reference = references[0]; |
| - expect(reference, isNotNull); |
| - expect(reference.identifier, isNotNull); |
| - expect(reference.offset, 35); |
| - } |
| + void test_missingSemicolon_varialeDeclarationList() { |
| + void verify(CompilationUnitMember member, String expectedTypeName, |
| + String expectedName, String expectedSemicolon) { |
| + expect(member, new isInstanceOf<TopLevelVariableDeclaration>()); |
| + TopLevelVariableDeclaration declaration = member; |
| + VariableDeclarationList variableList = declaration.variables; |
| + expect(variableList, isNotNull); |
| + NodeList<VariableDeclaration> variables = variableList.variables; |
| + expect(variables, hasLength(1)); |
| + VariableDeclaration variable = variables[0]; |
| + expect(variableList.type.toString(), expectedTypeName); |
| + expect(variable.name.name, expectedName); |
| + expect(declaration.semicolon.lexeme, expectedSemicolon); |
| + } |
| - void test_parseCommentReferences_skipReferenceLink() { |
| - List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ |
| - new DocumentationCommentToken( |
| - TokenType.MULTI_LINE_COMMENT, "/** [a][c] [b] zzz */", 3) |
| - ]; |
| - createParser(''); |
| - List<CommentReference> references = parser.parseCommentReferences(tokens); |
| - expectNotNullIfNoErrors(references); |
| - listener.assertNoErrors(); |
| - expect(references, hasLength(1)); |
| - CommentReference reference = references[0]; |
| - expect(reference, isNotNull); |
| - expect(reference.identifier, isNotNull); |
| - expect(reference.offset, 15); |
| + CompilationUnit unit = parseCompilationUnit('String n x = "";', [ |
| + ParserErrorCode.EXPECTED_TOKEN, |
| + ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE |
| + ]); |
| + expect(unit, isNotNull); |
| + NodeList<CompilationUnitMember> declarations = unit.declarations; |
| + expect(declarations, hasLength(2)); |
| + verify(declarations[0], 'String', 'n', ''); |
| + verify(declarations[1], 'null', 'x', ';'); |
| } |
| - void test_parseConditionalExpression() { |
| - createParser('x ? y : z'); |
| - ConditionalExpression expression = parser.parseConditionalExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression.condition, isNotNull); |
| - expect(expression.question, isNotNull); |
| - expect(expression.thenExpression, isNotNull); |
| - expect(expression.colon, isNotNull); |
| - expect(expression.elseExpression, isNotNull); |
| + void test_multiplicativeExpression_missing_LHS() { |
| + BinaryExpression expression = |
| + parseExpression("* y", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.leftOperand); |
| + expect(expression.leftOperand.isSynthetic, isTrue); |
| } |
| - void test_parseConfiguration_noOperator_dottedIdentifier() { |
| - createParser("if (a.b) 'c.dart'"); |
| - Configuration configuration = parser.parseConfiguration(); |
| - expectNotNullIfNoErrors(configuration); |
| - listener.assertNoErrors(); |
| - expect(configuration.ifKeyword, isNotNull); |
| - expect(configuration.leftParenthesis, isNotNull); |
| - expectDottedName(configuration.name, ["a", "b"]); |
| - expect(configuration.equalToken, isNull); |
| - expect(configuration.value, isNull); |
| - expect(configuration.rightParenthesis, isNotNull); |
| - expect(configuration.uri, isNotNull); |
| + void test_multiplicativeExpression_missing_LHS_RHS() { |
| + BinaryExpression expression = parseExpression("*", [ |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER |
| + ]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.leftOperand); |
| + expect(expression.leftOperand.isSynthetic, isTrue); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.rightOperand); |
| + expect(expression.rightOperand.isSynthetic, isTrue); |
| } |
| - void test_parseConfiguration_noOperator_simpleIdentifier() { |
| - createParser("if (a) 'b.dart'"); |
| - Configuration configuration = parser.parseConfiguration(); |
| - expectNotNullIfNoErrors(configuration); |
| - listener.assertNoErrors(); |
| - expect(configuration.ifKeyword, isNotNull); |
| - expect(configuration.leftParenthesis, isNotNull); |
| - expectDottedName(configuration.name, ["a"]); |
| - expect(configuration.equalToken, isNull); |
| - expect(configuration.value, isNull); |
| - expect(configuration.rightParenthesis, isNotNull); |
| - expect(configuration.uri, isNotNull); |
| + void test_multiplicativeExpression_missing_RHS() { |
| + BinaryExpression expression = |
| + parseExpression("x *", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.rightOperand); |
| + expect(expression.rightOperand.isSynthetic, isTrue); |
| } |
| - void test_parseConfiguration_operator_dottedIdentifier() { |
| - createParser("if (a.b == 'c') 'd.dart'"); |
| - Configuration configuration = parser.parseConfiguration(); |
| - expectNotNullIfNoErrors(configuration); |
| - listener.assertNoErrors(); |
| - expect(configuration.ifKeyword, isNotNull); |
| - expect(configuration.leftParenthesis, isNotNull); |
| - expectDottedName(configuration.name, ["a", "b"]); |
| - expect(configuration.equalToken, isNotNull); |
| - expect(configuration.value, isNotNull); |
| - expect(configuration.rightParenthesis, isNotNull); |
| - expect(configuration.uri, isNotNull); |
| + void test_multiplicativeExpression_missing_RHS_super() { |
| + BinaryExpression expression = |
| + parseExpression("super *", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.rightOperand); |
| + expect(expression.rightOperand.isSynthetic, isTrue); |
| } |
| - void test_parseConfiguration_operator_simpleIdentifier() { |
| - createParser("if (a == 'b') 'c.dart'"); |
| - Configuration configuration = parser.parseConfiguration(); |
| - expectNotNullIfNoErrors(configuration); |
| - listener.assertNoErrors(); |
| - expect(configuration.ifKeyword, isNotNull); |
| - expect(configuration.leftParenthesis, isNotNull); |
| - expectDottedName(configuration.name, ["a"]); |
| - expect(configuration.equalToken, isNotNull); |
| - expect(configuration.value, isNotNull); |
| - expect(configuration.rightParenthesis, isNotNull); |
| - expect(configuration.uri, isNotNull); |
| + void test_multiplicativeExpression_precedence_unary_left() { |
| + BinaryExpression expression = |
| + parseExpression("-x *", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is PrefixExpression, |
| + PrefixExpression, expression.leftOperand); |
| } |
| - void test_parseConstExpression_instanceCreation() { |
| - createParser('const A()'); |
| - Expression expression = parser.parseConstExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<InstanceCreationExpression>()); |
| - InstanceCreationExpression instanceCreation = expression; |
| - expect(instanceCreation.keyword, isNotNull); |
| - ConstructorName name = instanceCreation.constructorName; |
| - expect(name, isNotNull); |
| - expect(name.type, isNotNull); |
| - expect(name.period, isNull); |
| - expect(name.name, isNull); |
| - expect(instanceCreation.argumentList, isNotNull); |
| + void test_multiplicativeExpression_precedence_unary_right() { |
| + BinaryExpression expression = |
| + parseExpression("* -y", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is PrefixExpression, |
| + PrefixExpression, expression.rightOperand); |
| } |
| - void test_parseConstExpression_listLiteral_typed() { |
| - createParser('const <A> []'); |
| - Expression expression = parser.parseConstExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<ListLiteral>()); |
| - ListLiteral literal = expression; |
| - expect(literal.constKeyword, isNotNull); |
| - expect(literal.typeArguments, isNotNull); |
| - expect(literal.leftBracket, isNotNull); |
| - expect(literal.elements, hasLength(0)); |
| - expect(literal.rightBracket, isNotNull); |
| + void test_multiplicativeExpression_super() { |
| + BinaryExpression expression = parseExpression("super == ==", [ |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND |
| + ]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| + BinaryExpression, expression.leftOperand); |
| } |
| - void test_parseConstExpression_listLiteral_typed_genericComment() { |
| - enableGenericMethodComments = true; |
| - createParser('const /*<A>*/ []'); |
| - Expression expression = parser.parseConstExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<ListLiteral>()); |
| - ListLiteral literal = expression; |
| - expect(literal.constKeyword, isNotNull); |
| - expect(literal.typeArguments, isNotNull); |
| - expect(literal.leftBracket, isNotNull); |
| - expect(literal.elements, hasLength(0)); |
| - expect(literal.rightBracket, isNotNull); |
| + void test_nonStringLiteralUri_import() { |
| + parseCompilationUnit("import dart:io; class C {}", |
| + [ParserErrorCode.NON_STRING_LITERAL_AS_URI]); |
| } |
| - void test_parseConstExpression_listLiteral_untyped() { |
| - createParser('const []'); |
| - Expression expression = parser.parseConstExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<ListLiteral>()); |
| - ListLiteral literal = expression; |
| - expect(literal.constKeyword, isNotNull); |
| - expect(literal.typeArguments, isNull); |
| - expect(literal.leftBracket, isNotNull); |
| - expect(literal.elements, hasLength(0)); |
| - expect(literal.rightBracket, isNotNull); |
| + void test_prefixExpression_missing_operand_minus() { |
| + PrefixExpression expression = |
| + parseExpression("-", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + EngineTestCase.assertInstanceOf( |
| + (obj) => obj is SimpleIdentifier, SimpleIdentifier, expression.operand); |
| + expect(expression.operand.isSynthetic, isTrue); |
| + expect(expression.operator.type, TokenType.MINUS); |
| } |
| - void test_parseConstExpression_mapLiteral_typed() { |
| - createParser('const <A, B> {}'); |
| - Expression expression = parser.parseConstExpression(); |
| + void test_primaryExpression_argumentDefinitionTest() { |
| + createParser('?a'); |
| + Expression expression = parser.parsePrimaryExpression(); |
| expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<MapLiteral>()); |
| - MapLiteral literal = expression; |
| - expect(literal.leftBracket, isNotNull); |
| - expect(literal.entries, hasLength(0)); |
| - expect(literal.rightBracket, isNotNull); |
| - expect(literal.typeArguments, isNotNull); |
| + listener.assertErrorsWithCodes([ParserErrorCode.UNEXPECTED_TOKEN]); |
| + expect(expression, new isInstanceOf<SimpleIdentifier>()); |
| } |
| - void test_parseConstExpression_mapLiteral_typed_genericComment() { |
| - enableGenericMethodComments = true; |
| - createParser('const /*<A, B>*/ {}'); |
| - Expression expression = parser.parseConstExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<MapLiteral>()); |
| - MapLiteral literal = expression; |
| - expect(literal.leftBracket, isNotNull); |
| - expect(literal.entries, hasLength(0)); |
| - expect(literal.rightBracket, isNotNull); |
| - expect(literal.typeArguments, isNotNull); |
| + void test_relationalExpression_missing_LHS() { |
| + IsExpression expression = |
| + parseExpression("is y", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.expression); |
| + expect(expression.expression.isSynthetic, isTrue); |
| } |
| - void test_parseConstExpression_mapLiteral_untyped() { |
| - createParser('const {}'); |
| - Expression expression = parser.parseConstExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<MapLiteral>()); |
| - MapLiteral literal = expression; |
| - expect(literal.leftBracket, isNotNull); |
| - expect(literal.entries, hasLength(0)); |
| - expect(literal.rightBracket, isNotNull); |
| - expect(literal.typeArguments, isNull); |
| + void test_relationalExpression_missing_LHS_RHS() { |
| + IsExpression expression = parseExpression("is", [ |
| + ParserErrorCode.EXPECTED_TYPE_NAME, |
| + ParserErrorCode.MISSING_IDENTIFIER |
| + ]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.expression); |
| + expect(expression.expression.isSynthetic, isTrue); |
| + EngineTestCase.assertInstanceOf( |
| + (obj) => obj is TypeName, TypeName, expression.type); |
| + expect(expression.type.isSynthetic, isTrue); |
| } |
| - void test_parseConstructor() { |
| - // TODO(brianwilkerson) Implement tests for this method. |
| + void test_relationalExpression_missing_RHS() { |
| + IsExpression expression = |
| + parseExpression("x is", [ParserErrorCode.EXPECTED_TYPE_NAME]); |
| + EngineTestCase.assertInstanceOf( |
| + (obj) => obj is TypeName, TypeName, expression.type); |
| + expect(expression.type.isSynthetic, isTrue); |
| } |
| - void test_parseConstructorName_named_noPrefix() { |
| - createParser('A.n;'); |
| - ConstructorName name = parser.parseConstructorName(); |
| - expectNotNullIfNoErrors(name); |
| - listener.assertNoErrors(); |
| - expect(name.type, isNotNull); |
| - expect(name.period, isNull); |
| - expect(name.name, isNull); |
| + void test_relationalExpression_precedence_shift_right() { |
| + IsExpression expression = parseExpression("<< is", [ |
| + ParserErrorCode.EXPECTED_TYPE_NAME, |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER |
| + ]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| + BinaryExpression, expression.expression); |
| } |
| - void test_parseConstructorName_named_prefixed() { |
| - createParser('p.A.n;'); |
| - ConstructorName name = parser.parseConstructorName(); |
| - expectNotNullIfNoErrors(name); |
| - listener.assertNoErrors(); |
| - expect(name.type, isNotNull); |
| - expect(name.period, isNotNull); |
| - expect(name.name, isNotNull); |
| + void test_shiftExpression_missing_LHS() { |
| + BinaryExpression expression = |
| + parseExpression("<< y", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.leftOperand); |
| + expect(expression.leftOperand.isSynthetic, isTrue); |
| } |
| - void test_parseConstructorName_unnamed_noPrefix() { |
| - createParser('A;'); |
| - ConstructorName name = parser.parseConstructorName(); |
| - expectNotNullIfNoErrors(name); |
| - listener.assertNoErrors(); |
| - expect(name.type, isNotNull); |
| - expect(name.period, isNull); |
| - expect(name.name, isNull); |
| + void test_shiftExpression_missing_LHS_RHS() { |
| + BinaryExpression expression = parseExpression("<<", [ |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER |
| + ]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.leftOperand); |
| + expect(expression.leftOperand.isSynthetic, isTrue); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.rightOperand); |
| + expect(expression.rightOperand.isSynthetic, isTrue); |
| } |
| - void test_parseConstructorName_unnamed_prefixed() { |
| - createParser('p.A;'); |
| - ConstructorName name = parser.parseConstructorName(); |
| - expectNotNullIfNoErrors(name); |
| - listener.assertNoErrors(); |
| - expect(name.type, isNotNull); |
| - expect(name.period, isNull); |
| - expect(name.name, isNull); |
| + void test_shiftExpression_missing_RHS() { |
| + BinaryExpression expression = |
| + parseExpression("x <<", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.rightOperand); |
| + expect(expression.rightOperand.isSynthetic, isTrue); |
| } |
| - void test_parseContinueStatement_label() { |
| - createParser('continue foo;'); |
| - ContinueStatement statement = parser.parseContinueStatement(); |
| - expectNotNullIfNoErrors(statement); |
| - listener.assertErrorsWithCodes([ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP]); |
| - expect(statement.continueKeyword, isNotNull); |
| - expect(statement.label, isNotNull); |
| - expect(statement.semicolon, isNotNull); |
| + void test_shiftExpression_missing_RHS_super() { |
| + BinaryExpression expression = |
| + parseExpression("super <<", [ParserErrorCode.MISSING_IDENTIFIER]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, expression.rightOperand); |
| + expect(expression.rightOperand.isSynthetic, isTrue); |
| } |
| - void test_parseContinueStatement_noLabel() { |
| - createParser('continue;'); |
| - ContinueStatement statement = parser.parseContinueStatement(); |
| - expectNotNullIfNoErrors(statement); |
| - listener.assertErrorsWithCodes([ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP]); |
| - expect(statement.continueKeyword, isNotNull); |
| - expect(statement.label, isNull); |
| - expect(statement.semicolon, isNotNull); |
| + void test_shiftExpression_precedence_unary_left() { |
| + BinaryExpression expression = parseExpression("+ <<", [ |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER |
| + ]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| + BinaryExpression, expression.leftOperand); |
| } |
| - void test_parseDocumentationComment_block() { |
| - createParser('/** */ class'); |
| - Comment comment = parser |
| - .parseDocumentationComment(parser.parseDocumentationCommentTokens()); |
| - expectNotNullIfNoErrors(comment); |
| - listener.assertNoErrors(); |
| - expect(comment.isBlock, isFalse); |
| - expect(comment.isDocumentation, isTrue); |
| - expect(comment.isEndOfLine, isFalse); |
| + void test_shiftExpression_precedence_unary_right() { |
| + BinaryExpression expression = parseExpression("<< +", [ |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER |
| + ]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| + BinaryExpression, expression.rightOperand); |
| } |
| - void test_parseDocumentationComment_block_withReference() { |
| - createParser('/** [a] */ class'); |
| - Comment comment = parser |
| - .parseDocumentationComment(parser.parseDocumentationCommentTokens()); |
| - expectNotNullIfNoErrors(comment); |
| - listener.assertNoErrors(); |
| - expect(comment.isBlock, isFalse); |
| - expect(comment.isDocumentation, isTrue); |
| - expect(comment.isEndOfLine, isFalse); |
| - NodeList<CommentReference> references = comment.references; |
| - expect(references, hasLength(1)); |
| - CommentReference reference = references[0]; |
| - expect(reference, isNotNull); |
| - expect(reference.offset, 5); |
| + void test_shiftExpression_super() { |
| + BinaryExpression expression = parseExpression("super << <<", [ |
| + ParserErrorCode.MISSING_IDENTIFIER, |
| + ParserErrorCode.MISSING_IDENTIFIER |
| + ]); |
| + EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| + BinaryExpression, expression.leftOperand); |
| } |
| - void test_parseDocumentationComment_endOfLine() { |
| - createParser('/// \n/// \n class'); |
| - Comment comment = parser |
| - .parseDocumentationComment(parser.parseDocumentationCommentTokens()); |
| - expectNotNullIfNoErrors(comment); |
| - listener.assertNoErrors(); |
| - expect(comment.isBlock, isFalse); |
| - expect(comment.isDocumentation, isTrue); |
| - expect(comment.isEndOfLine, isFalse); |
| + void test_typedef_eof() { |
| + CompilationUnit unit = parseCompilationUnit("typedef n", [ |
| + ParserErrorCode.EXPECTED_TOKEN, |
| + ParserErrorCode.MISSING_TYPEDEF_PARAMETERS |
| + ]); |
| + NodeList<CompilationUnitMember> declarations = unit.declarations; |
| + expect(declarations, hasLength(1)); |
| + CompilationUnitMember member = declarations[0]; |
| + EngineTestCase.assertInstanceOf( |
| + (obj) => obj is FunctionTypeAlias, FunctionTypeAlias, member); |
| } |
| - void test_parseDoStatement() { |
| - createParser('do {} while (x);'); |
| - DoStatement statement = parser.parseDoStatement(); |
| - expectNotNullIfNoErrors(statement); |
| - listener.assertNoErrors(); |
| - expect(statement.doKeyword, isNotNull); |
| - expect(statement.body, isNotNull); |
| - expect(statement.whileKeyword, isNotNull); |
| - expect(statement.leftParenthesis, isNotNull); |
| - expect(statement.condition, isNotNull); |
| - expect(statement.rightParenthesis, isNotNull); |
| - expect(statement.semicolon, isNotNull); |
| + void test_unaryPlus() { |
| + parseExpression("+2", [ParserErrorCode.MISSING_IDENTIFIER]); |
| } |
| +} |
| - void test_parseDottedName_multiple() { |
| - createParser('a.b.c'); |
| - DottedName name = parser.parseDottedName(); |
| - expectNotNullIfNoErrors(name); |
| - listener.assertNoErrors(); |
| - expectDottedName(name, ["a", "b", "c"]); |
| +/** |
| + * The class `SimpleParserTest` defines parser tests that test individual parsing method. The |
| + * code fragments should be as minimal as possible in order to test the method, but should not test |
| + * the interactions between the method under test and other methods. |
| + * |
| + * More complex tests should be defined in the class [ComplexParserTest]. |
| + */ |
| +@reflectiveTest |
| +class SimpleParserTest extends ParserTestCase { |
| + void test_computeStringValue_emptyInterpolationPrefix() { |
| + expect(_computeStringValue("'''", true, false), ""); |
| } |
| - void test_parseDottedName_single() { |
| - createParser('a'); |
| - DottedName name = parser.parseDottedName(); |
| - expectNotNullIfNoErrors(name); |
| - listener.assertNoErrors(); |
| - expectDottedName(name, ["a"]); |
| + void test_computeStringValue_escape_b() { |
| + expect(_computeStringValue("'\\b'", true, true), "\b"); |
| } |
| - void test_parseEmptyStatement() { |
| - createParser(';'); |
| - EmptyStatement statement = parser.parseEmptyStatement(); |
| - expectNotNullIfNoErrors(statement); |
| - listener.assertNoErrors(); |
| - expect(statement.semicolon, isNotNull); |
| + void test_computeStringValue_escape_f() { |
| + expect(_computeStringValue("'\\f'", true, true), "\f"); |
| } |
| - void test_parseEqualityExpression_normal() { |
| - createParser('x == y'); |
| - BinaryExpression expression = parser.parseEqualityExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression.leftOperand, isNotNull); |
| - expect(expression.operator, isNotNull); |
| - expect(expression.operator.type, TokenType.EQ_EQ); |
| - expect(expression.rightOperand, isNotNull); |
| + void test_computeStringValue_escape_n() { |
| + expect(_computeStringValue("'\\n'", true, true), "\n"); |
| } |
| - void test_parseEqualityExpression_super() { |
| - createParser('super == y'); |
| - BinaryExpression expression = parser.parseEqualityExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression.leftOperand, new isInstanceOf<SuperExpression>()); |
| - expect(expression.operator, isNotNull); |
| - expect(expression.operator.type, TokenType.EQ_EQ); |
| - expect(expression.rightOperand, isNotNull); |
| + void test_computeStringValue_escape_notSpecial() { |
| + expect(_computeStringValue("'\\:'", true, true), ":"); |
| + } |
| + |
| + void test_computeStringValue_escape_r() { |
| + expect(_computeStringValue("'\\r'", true, true), "\r"); |
| } |
| - void test_parseExpression_assign() { |
| - // TODO(brianwilkerson) Implement more tests for this method. |
| - Expression expression = parseExpression('x = y'); |
| - expect(expression, new isInstanceOf<AssignmentExpression>()); |
| - AssignmentExpression assignmentExpression = expression; |
| - expect(assignmentExpression.leftHandSide, isNotNull); |
| - expect(assignmentExpression.operator, isNotNull); |
| - expect(assignmentExpression.operator.type, TokenType.EQ); |
| - expect(assignmentExpression.rightHandSide, isNotNull); |
| + void test_computeStringValue_escape_t() { |
| + expect(_computeStringValue("'\\t'", true, true), "\t"); |
| } |
| - void test_parseExpression_assign_compound() { |
| - enableLazyAssignmentOperators = true; |
| - Expression expression = parseExpression('x ||= y'); |
| - expect(expression, new isInstanceOf<AssignmentExpression>()); |
| - AssignmentExpression assignmentExpression = expression; |
| - expect(assignmentExpression.leftHandSide, isNotNull); |
| - expect(assignmentExpression.operator, isNotNull); |
| - expect(assignmentExpression.operator.type, TokenType.BAR_BAR_EQ); |
| - expect(assignmentExpression.rightHandSide, isNotNull); |
| + void test_computeStringValue_escape_u_fixed() { |
| + expect(_computeStringValue("'\\u4321'", true, true), "\u4321"); |
| } |
| - void test_parseExpression_comparison() { |
| - Expression expression = parseExpression('--a.b == c'); |
| - expect(expression, new isInstanceOf<BinaryExpression>()); |
| - BinaryExpression binaryExpression = expression; |
| - expect(binaryExpression.leftOperand, isNotNull); |
| - expect(binaryExpression.operator, isNotNull); |
| - expect(binaryExpression.operator.type, TokenType.EQ_EQ); |
| - expect(binaryExpression.rightOperand, isNotNull); |
| + void test_computeStringValue_escape_u_variable() { |
| + expect(_computeStringValue("'\\u{123}'", true, true), "\u0123"); |
| } |
| - void test_parseExpression_function_async() { |
| - Expression expression = parseExpression('() async {}'); |
| - expect(expression, new isInstanceOf<FunctionExpression>()); |
| - FunctionExpression functionExpression = expression; |
| - expect(functionExpression.body, isNotNull); |
| - expect(functionExpression.body.isAsynchronous, isTrue); |
| - expect(functionExpression.body.isGenerator, isFalse); |
| - expect(functionExpression.parameters, isNotNull); |
| + void test_computeStringValue_escape_v() { |
| + expect(_computeStringValue("'\\v'", true, true), "\u000B"); |
| } |
| - void test_parseExpression_function_asyncStar() { |
| - Expression expression = parseExpression('() async* {}'); |
| - expect(expression, new isInstanceOf<FunctionExpression>()); |
| - FunctionExpression functionExpression = expression; |
| - expect(functionExpression.body, isNotNull); |
| - expect(functionExpression.body.isAsynchronous, isTrue); |
| - expect(functionExpression.body.isGenerator, isTrue); |
| - expect(functionExpression.parameters, isNotNull); |
| + void test_computeStringValue_escape_x() { |
| + expect(_computeStringValue("'\\xFF'", true, true), "\u00FF"); |
| } |
| - void test_parseExpression_function_sync() { |
| - Expression expression = parseExpression('() {}'); |
| - expect(expression, new isInstanceOf<FunctionExpression>()); |
| - FunctionExpression functionExpression = expression; |
| - expect(functionExpression.body, isNotNull); |
| - expect(functionExpression.body.isAsynchronous, isFalse); |
| - expect(functionExpression.body.isGenerator, isFalse); |
| - expect(functionExpression.parameters, isNotNull); |
| + void test_computeStringValue_noEscape_single() { |
| + expect(_computeStringValue("'text'", true, true), "text"); |
| } |
| - void test_parseExpression_function_syncStar() { |
| - Expression expression = parseExpression('() sync* {}'); |
| - expect(expression, new isInstanceOf<FunctionExpression>()); |
| - FunctionExpression functionExpression = expression; |
| - expect(functionExpression.body, isNotNull); |
| - expect(functionExpression.body.isAsynchronous, isFalse); |
| - expect(functionExpression.body.isGenerator, isTrue); |
| - expect(functionExpression.parameters, isNotNull); |
| + void test_computeStringValue_noEscape_triple() { |
| + expect(_computeStringValue("'''text'''", true, true), "text"); |
| } |
| - void test_parseExpression_invokeFunctionExpression() { |
| - Expression expression = parseExpression('(a) {return a + a;} (3)'); |
| - expect(expression, new isInstanceOf<FunctionExpressionInvocation>()); |
| - FunctionExpressionInvocation invocation = expression; |
| - expect(invocation.function, new isInstanceOf<FunctionExpression>()); |
| - FunctionExpression functionExpression = |
| - invocation.function as FunctionExpression; |
| - expect(functionExpression.parameters, isNotNull); |
| - expect(functionExpression.body, isNotNull); |
| - expect(invocation.typeArguments, isNull); |
| - ArgumentList list = invocation.argumentList; |
| - expect(list, isNotNull); |
| - expect(list.arguments, hasLength(1)); |
| + void test_computeStringValue_raw_single() { |
| + expect(_computeStringValue("r'text'", true, true), "text"); |
| } |
| - void test_parseExpression_nonAwait() { |
| - Expression expression = parseExpression('await()'); |
| - expect(expression, new isInstanceOf<MethodInvocation>()); |
| - MethodInvocation invocation = expression; |
| - expect(invocation.methodName.name, 'await'); |
| - expect(invocation.typeArguments, isNull); |
| - expect(invocation.argumentList, isNotNull); |
| + void test_computeStringValue_raw_triple() { |
| + expect(_computeStringValue("r'''text'''", true, true), "text"); |
| } |
| - void test_parseExpression_superMethodInvocation() { |
| - Expression expression = parseExpression('super.m()'); |
| - expect(expression, new isInstanceOf<MethodInvocation>()); |
| - MethodInvocation invocation = expression; |
| - expect(invocation.target, isNotNull); |
| - expect(invocation.methodName, isNotNull); |
| - expect(invocation.typeArguments, isNull); |
| - expect(invocation.argumentList, isNotNull); |
| + void test_computeStringValue_raw_withEscape() { |
| + expect(_computeStringValue("r'two\\nlines'", true, true), "two\\nlines"); |
| } |
| - void test_parseExpression_superMethodInvocation_typeArgumentComments() { |
| - enableGenericMethodComments = true; |
| - Expression expression = parseExpression('super.m/*<E>*/()'); |
| - expect(expression, new isInstanceOf<MethodInvocation>()); |
| - MethodInvocation invocation = expression; |
| - expect(invocation.target, isNotNull); |
| - expect(invocation.methodName, isNotNull); |
| - expect(invocation.typeArguments, isNotNull); |
| - expect(invocation.argumentList, isNotNull); |
| + void test_computeStringValue_triple_internalQuote_first_empty() { |
| + expect(_computeStringValue("''''", true, false), "'"); |
| } |
| - void test_parseExpression_superMethodInvocation_typeArguments() { |
| - Expression expression = parseExpression('super.m<E>()'); |
| - expect(expression, new isInstanceOf<MethodInvocation>()); |
| - MethodInvocation invocation = expression; |
| - expect(invocation.target, isNotNull); |
| - expect(invocation.methodName, isNotNull); |
| - expect(invocation.typeArguments, isNotNull); |
| - expect(invocation.argumentList, isNotNull); |
| + void test_computeStringValue_triple_internalQuote_first_nonEmpty() { |
| + expect(_computeStringValue("''''text", true, false), "'text"); |
| } |
| - void test_parseExpressionList_multiple() { |
| - createParser('1, 2, 3'); |
| - List<Expression> result = parser.parseExpressionList(); |
| - expectNotNullIfNoErrors(result); |
| - listener.assertNoErrors(); |
| - expect(result, hasLength(3)); |
| + void test_computeStringValue_triple_internalQuote_last_empty() { |
| + expect(_computeStringValue("'''", false, true), ""); |
| } |
| - void test_parseExpressionList_single() { |
| - createParser('1'); |
| - List<Expression> result = parser.parseExpressionList(); |
| - expectNotNullIfNoErrors(result); |
| - listener.assertNoErrors(); |
| - expect(result, hasLength(1)); |
| + void test_computeStringValue_triple_internalQuote_last_nonEmpty() { |
| + expect(_computeStringValue("text'''", false, true), "text"); |
| } |
| - void test_parseExpressionWithoutCascade_assign() { |
| - // TODO(brianwilkerson) Implement more tests for this method. |
| - createParser('x = y'); |
| - Expression expression = parser.parseExpressionWithoutCascade(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<AssignmentExpression>()); |
| - AssignmentExpression assignmentExpression = expression; |
| - expect(assignmentExpression.leftHandSide, isNotNull); |
| - expect(assignmentExpression.operator, isNotNull); |
| - expect(assignmentExpression.operator.type, TokenType.EQ); |
| - expect(assignmentExpression.rightHandSide, isNotNull); |
| + void test_createSyntheticIdentifier() { |
| + createParser(''); |
| + SimpleIdentifier identifier = parser.createSyntheticIdentifier(); |
| + expectNotNullIfNoErrors(identifier); |
| + expect(identifier.isSynthetic, isTrue); |
| } |
| - void test_parseExpressionWithoutCascade_comparison() { |
| - createParser('--a.b == c'); |
| - Expression expression = parser.parseExpressionWithoutCascade(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<BinaryExpression>()); |
| - BinaryExpression binaryExpression = expression; |
| - expect(binaryExpression.leftOperand, isNotNull); |
| - expect(binaryExpression.operator, isNotNull); |
| - expect(binaryExpression.operator.type, TokenType.EQ_EQ); |
| - expect(binaryExpression.rightOperand, isNotNull); |
| + void test_createSyntheticStringLiteral() { |
| + createParser(''); |
| + SimpleStringLiteral literal = parser.createSyntheticStringLiteral(); |
| + expectNotNullIfNoErrors(literal); |
| + expect(literal.isSynthetic, isTrue); |
| } |
| - void test_parseExpressionWithoutCascade_superMethodInvocation() { |
| - createParser('super.m()'); |
| - Expression expression = parser.parseExpressionWithoutCascade(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<MethodInvocation>()); |
| - MethodInvocation invocation = expression; |
| - expect(invocation.target, isNotNull); |
| - expect(invocation.methodName, isNotNull); |
| - expect(invocation.typeArguments, isNull); |
| - expect(invocation.argumentList, isNotNull); |
| + void test_isFunctionDeclaration_nameButNoReturn_block() { |
| + expect(_isFunctionDeclaration("f() {}"), isTrue); |
| } |
| - void |
| - test_parseExpressionWithoutCascade_superMethodInvocation_typeArgumentComments() { |
| - enableGenericMethodComments = true; |
| - createParser('super.m/*<E>*/()'); |
| - Expression expression = parser.parseExpressionWithoutCascade(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<MethodInvocation>()); |
| - MethodInvocation invocation = expression; |
| - expect(invocation.target, isNotNull); |
| - expect(invocation.methodName, isNotNull); |
| - expect(invocation.typeArguments, isNotNull); |
| - expect(invocation.argumentList, isNotNull); |
| + void test_isFunctionDeclaration_nameButNoReturn_expression() { |
| + expect(_isFunctionDeclaration("f() => e"), isTrue); |
| } |
| - void |
| - test_parseExpressionWithoutCascade_superMethodInvocation_typeArguments() { |
| - createParser('super.m<E>()'); |
| - Expression expression = parser.parseExpressionWithoutCascade(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<MethodInvocation>()); |
| - MethodInvocation invocation = expression; |
| - expect(invocation.target, isNotNull); |
| - expect(invocation.methodName, isNotNull); |
| - expect(invocation.typeArguments, isNotNull); |
| - expect(invocation.argumentList, isNotNull); |
| + void test_isFunctionDeclaration_nameButNoReturn_typeParameters_block() { |
| + expect(_isFunctionDeclaration("f<E>() {}"), isTrue); |
| } |
| - void test_parseExtendsClause() { |
| - createParser('extends B'); |
| - ExtendsClause clause = parser.parseExtendsClause(); |
| - expectNotNullIfNoErrors(clause); |
| - listener.assertNoErrors(); |
| - expect(clause.extendsKeyword, isNotNull); |
| - expect(clause.superclass, isNotNull); |
| - expect(clause.superclass, new isInstanceOf<TypeName>()); |
| + void test_isFunctionDeclaration_nameButNoReturn_typeParameters_expression() { |
| + expect(_isFunctionDeclaration("f<E>() => e"), isTrue); |
| } |
| - void test_parseFinalConstVarOrType_const_functionType() { |
| - createParser('const int Function(int) f'); |
| - FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| - expectNotNullIfNoErrors(result); |
| - listener.assertNoErrors(); |
| - Token keyword = result.keyword; |
| - expect(keyword, isNotNull); |
| - expect(keyword.type, TokenType.KEYWORD); |
| - expect(keyword.keyword, Keyword.CONST); |
| - expect(result.type, isNotNull); |
| + void test_isFunctionDeclaration_normalReturn_block() { |
| + expect(_isFunctionDeclaration("C f() {}"), isTrue); |
| } |
| - void test_parseFinalConstVarOrType_const_namedType() { |
| - createParser('const A a'); |
| - FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| - expectNotNullIfNoErrors(result); |
| - listener.assertNoErrors(); |
| - Token keyword = result.keyword; |
| - expect(keyword, isNotNull); |
| - expect(keyword.type, TokenType.KEYWORD); |
| - expect(keyword.keyword, Keyword.CONST); |
| - expect(result.type, isNotNull); |
| + void test_isFunctionDeclaration_normalReturn_expression() { |
| + expect(_isFunctionDeclaration("C f() => e"), isTrue); |
| + } |
| + |
| + void test_isFunctionDeclaration_normalReturn_typeParameters_block() { |
| + expect(_isFunctionDeclaration("C f<E>() {}"), isTrue); |
| } |
| - void test_parseFinalConstVarOrType_const_noType() { |
| - createParser('const'); |
| - FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| - expectNotNullIfNoErrors(result); |
| - listener.assertNoErrors(); |
| - Token keyword = result.keyword; |
| - expect(keyword, isNotNull); |
| - expect(keyword.type, TokenType.KEYWORD); |
| - expect(keyword.keyword, Keyword.CONST); |
| - expect(result.type, isNull); |
| + void test_isFunctionDeclaration_normalReturn_typeParameters_expression() { |
| + expect(_isFunctionDeclaration("C f<E>() => e"), isTrue); |
| } |
| - void test_parseFinalConstVarOrType_final_functionType() { |
| - createParser('final int Function(int) f'); |
| - FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| - expectNotNullIfNoErrors(result); |
| - listener.assertNoErrors(); |
| - Token keyword = result.keyword; |
| - expect(keyword, isNotNull); |
| - expect(keyword.type, TokenType.KEYWORD); |
| - expect(keyword.keyword, Keyword.FINAL); |
| - expect(result.type, isNotNull); |
| + void test_isFunctionDeclaration_voidReturn_block() { |
| + expect(_isFunctionDeclaration("void f() {}"), isTrue); |
| } |
| - void test_parseFinalConstVarOrType_final_namedType() { |
| - createParser('final A a'); |
| - FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| - expectNotNullIfNoErrors(result); |
| - listener.assertNoErrors(); |
| - Token keyword = result.keyword; |
| - expect(keyword, isNotNull); |
| - expect(keyword.type, TokenType.KEYWORD); |
| - expect(keyword.keyword, Keyword.FINAL); |
| - expect(result.type, isNotNull); |
| + void test_isFunctionDeclaration_voidReturn_expression() { |
| + expect(_isFunctionDeclaration("void f() => e"), isTrue); |
| } |
| - void test_parseFinalConstVarOrType_final_noType() { |
| - createParser('final'); |
| - FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| - expectNotNullIfNoErrors(result); |
| - listener.assertNoErrors(); |
| - Token keyword = result.keyword; |
| - expect(keyword, isNotNull); |
| - expect(keyword.type, TokenType.KEYWORD); |
| - expect(keyword.keyword, Keyword.FINAL); |
| - expect(result.type, isNull); |
| + void test_isFunctionDeclaration_voidReturn_typeParameters_block() { |
| + expect(_isFunctionDeclaration("void f<E>() {}"), isTrue); |
| } |
| - void test_parseFinalConstVarOrType_final_prefixedType() { |
| - createParser('final p.A a'); |
| - FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| - expectNotNullIfNoErrors(result); |
| - listener.assertNoErrors(); |
| - Token keyword = result.keyword; |
| - expect(keyword, isNotNull); |
| - expect(keyword.type, TokenType.KEYWORD); |
| - expect(keyword.keyword, Keyword.FINAL); |
| - expect(result.type, isNotNull); |
| + void test_isFunctionDeclaration_voidReturn_typeParameters_expression() { |
| + expect(_isFunctionDeclaration("void f<E>() => e"), isTrue); |
| } |
| - void test_parseFinalConstVarOrType_type_function() { |
| - createParser('int Function(int) f'); |
| - FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| - expectNotNullIfNoErrors(result); |
| - listener.assertNoErrors(); |
| - expect(result.keyword, isNull); |
| - expect(result.type, isNotNull); |
| + void test_isFunctionExpression_false_noBody() { |
| + expect(_isFunctionExpression("f();"), isFalse); |
| } |
| - void test_parseFinalConstVarOrType_type_parameterized() { |
| - createParser('A<B> a'); |
| - FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| - expectNotNullIfNoErrors(result); |
| - listener.assertNoErrors(); |
| - expect(result.keyword, isNull); |
| - expect(result.type, isNotNull); |
| + void test_isFunctionExpression_false_notParameters() { |
| + expect(_isFunctionExpression("(a + b) {"), isFalse); |
| } |
| - void test_parseFinalConstVarOrType_type_prefixed() { |
| - createParser('p.A a'); |
| - FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| - expectNotNullIfNoErrors(result); |
| - listener.assertNoErrors(); |
| - expect(result.keyword, isNull); |
| - expect(result.type, isNotNull); |
| + void test_isFunctionExpression_noParameters_block() { |
| + expect(_isFunctionExpression("() {}"), isTrue); |
| } |
| - void test_parseFinalConstVarOrType_type_prefixed_noIdentifier() { |
| - createParser('p.A,'); |
| - FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| - expectNotNullIfNoErrors(result); |
| - listener.assertNoErrors(); |
| - expect(result.keyword, isNull); |
| - expect(result.type, isNotNull); |
| + void test_isFunctionExpression_noParameters_expression() { |
| + expect(_isFunctionExpression("() => e"), isTrue); |
| } |
| - void test_parseFinalConstVarOrType_type_prefixedAndParameterized() { |
| - createParser('p.A<B> a'); |
| - FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| - expectNotNullIfNoErrors(result); |
| - listener.assertNoErrors(); |
| - expect(result.keyword, isNull); |
| - expect(result.type, isNotNull); |
| + void test_isFunctionExpression_noParameters_typeParameters_block() { |
| + expect(_isFunctionExpression("<E>() {}"), isTrue); |
| } |
| - void test_parseFinalConstVarOrType_type_simple() { |
| - createParser('A a'); |
| - FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| - expectNotNullIfNoErrors(result); |
| - listener.assertNoErrors(); |
| - expect(result.keyword, isNull); |
| - expect(result.type, isNotNull); |
| + void test_isFunctionExpression_noParameters_typeParameters_expression() { |
| + expect(_isFunctionExpression("<E>() => e"), isTrue); |
| } |
| - void test_parseFinalConstVarOrType_type_simple_noIdentifier_inFunctionType() { |
| - createParser('A,'); |
| - FinalConstVarOrType result = |
| - parser.parseFinalConstVarOrType(false, inFunctionType: true); |
| - expectNotNullIfNoErrors(result); |
| - listener.assertNoErrors(); |
| - expect(result.keyword, isNull); |
| - expect(result.type, isNotNull); |
| + void test_isFunctionExpression_parameter_final() { |
| + expect(_isFunctionExpression("(final a) {}"), isTrue); |
| + expect(_isFunctionExpression("(final a, b) {}"), isTrue); |
| + expect(_isFunctionExpression("(final a, final b) {}"), isTrue); |
| } |
| - void test_parseFinalConstVarOrType_var() { |
| - createParser('var'); |
| - FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| - expectNotNullIfNoErrors(result); |
| - listener.assertNoErrors(); |
| - Token keyword = result.keyword; |
| - expect(keyword, isNotNull); |
| - expect(keyword.type, TokenType.KEYWORD); |
| - expect(keyword.keyword, Keyword.VAR); |
| - expect(result.type, isNull); |
| + void test_isFunctionExpression_parameter_final_typed() { |
| + expect(_isFunctionExpression("(final int a) {}"), isTrue); |
| + expect(_isFunctionExpression("(final prefix.List a) {}"), isTrue); |
| + expect(_isFunctionExpression("(final List<int> a) {}"), isTrue); |
| + expect(_isFunctionExpression("(final prefix.List<int> a) {}"), isTrue); |
| } |
| - void test_parseFinalConstVarOrType_void() { |
| - createParser('void f()'); |
| - FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| - expectNotNullIfNoErrors(result); |
| - listener.assertNoErrors(); |
| - expect(result.keyword, isNull); |
| - expect(result.type, isNotNull); |
| + void test_isFunctionExpression_parameter_multiple() { |
| + expect(_isFunctionExpression("(a, b) {}"), isTrue); |
| } |
| - void test_parseFinalConstVarOrType_void_noIdentifier() { |
| - createParser('void,'); |
| - FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| - expectNotNullIfNoErrors(result); |
| - listener.assertNoErrors(); |
| - expect(result.keyword, isNull); |
| - expect(result.type, isNotNull); |
| + void test_isFunctionExpression_parameter_named() { |
| + expect(_isFunctionExpression("({a}) {}"), isTrue); |
| } |
| - void test_parseForStatement_each_await() { |
| - createParser('await for (element in list) {}'); |
| - Statement statement = parser.parseForStatement(); |
| - expectNotNullIfNoErrors(statement); |
| - listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<ForEachStatement>()); |
| - ForEachStatement forStatement = statement; |
| - expect(forStatement.awaitKeyword, isNotNull); |
| - expect(forStatement.forKeyword, isNotNull); |
| - expect(forStatement.leftParenthesis, isNotNull); |
| - expect(forStatement.loopVariable, isNull); |
| - expect(forStatement.identifier, isNotNull); |
| - expect(forStatement.inKeyword, isNotNull); |
| - expect(forStatement.iterable, isNotNull); |
| - expect(forStatement.rightParenthesis, isNotNull); |
| - expect(forStatement.body, isNotNull); |
| + void test_isFunctionExpression_parameter_optional() { |
| + expect(_isFunctionExpression("([a]) {}"), isTrue); |
| } |
| - void test_parseForStatement_each_identifier() { |
| - createParser('for (element in list) {}'); |
| - Statement statement = parser.parseForStatement(); |
| - expectNotNullIfNoErrors(statement); |
| - listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<ForEachStatement>()); |
| - ForEachStatement forStatement = statement; |
| - expect(forStatement.awaitKeyword, isNull); |
| - expect(forStatement.forKeyword, isNotNull); |
| - expect(forStatement.leftParenthesis, isNotNull); |
| - expect(forStatement.loopVariable, isNull); |
| - expect(forStatement.identifier, isNotNull); |
| - expect(forStatement.inKeyword, isNotNull); |
| - expect(forStatement.iterable, isNotNull); |
| - expect(forStatement.rightParenthesis, isNotNull); |
| - expect(forStatement.body, isNotNull); |
| + void test_isFunctionExpression_parameter_single() { |
| + expect(_isFunctionExpression("(a) {}"), isTrue); |
| } |
| - void test_parseForStatement_each_noType_metadata() { |
| - createParser('for (@A var element in list) {}'); |
| - Statement statement = parser.parseForStatement(); |
| - expectNotNullIfNoErrors(statement); |
| - listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<ForEachStatement>()); |
| - ForEachStatement forStatement = statement; |
| - expect(forStatement.awaitKeyword, isNull); |
| - expect(forStatement.forKeyword, isNotNull); |
| - expect(forStatement.leftParenthesis, isNotNull); |
| - expect(forStatement.loopVariable, isNotNull); |
| - expect(forStatement.loopVariable.metadata, hasLength(1)); |
| - expect(forStatement.identifier, isNull); |
| - expect(forStatement.inKeyword, isNotNull); |
| - expect(forStatement.iterable, isNotNull); |
| - expect(forStatement.rightParenthesis, isNotNull); |
| - expect(forStatement.body, isNotNull); |
| + void test_isFunctionExpression_parameter_typed() { |
| + expect(_isFunctionExpression("(int a, int b) {}"), isTrue); |
| } |
| - void test_parseForStatement_each_type() { |
| - createParser('for (A element in list) {}'); |
| - Statement statement = parser.parseForStatement(); |
| - expectNotNullIfNoErrors(statement); |
| - listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<ForEachStatement>()); |
| - ForEachStatement forStatement = statement; |
| - expect(forStatement.awaitKeyword, isNull); |
| - expect(forStatement.forKeyword, isNotNull); |
| - expect(forStatement.leftParenthesis, isNotNull); |
| - expect(forStatement.loopVariable, isNotNull); |
| - expect(forStatement.identifier, isNull); |
| - expect(forStatement.inKeyword, isNotNull); |
| - expect(forStatement.iterable, isNotNull); |
| - expect(forStatement.rightParenthesis, isNotNull); |
| - expect(forStatement.body, isNotNull); |
| + void test_isInitializedVariableDeclaration_assignment() { |
| + expect(_isInitializedVariableDeclaration("a = null;"), isFalse); |
| } |
| - void test_parseForStatement_each_var() { |
| - createParser('for (var element in list) {}'); |
| - Statement statement = parser.parseForStatement(); |
| - expectNotNullIfNoErrors(statement); |
| - listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<ForEachStatement>()); |
| - ForEachStatement forStatement = statement; |
| - expect(forStatement.awaitKeyword, isNull); |
| - expect(forStatement.forKeyword, isNotNull); |
| - expect(forStatement.leftParenthesis, isNotNull); |
| - expect(forStatement.loopVariable, isNotNull); |
| - expect(forStatement.identifier, isNull); |
| - expect(forStatement.inKeyword, isNotNull); |
| - expect(forStatement.iterable, isNotNull); |
| - expect(forStatement.rightParenthesis, isNotNull); |
| - expect(forStatement.body, isNotNull); |
| + void test_isInitializedVariableDeclaration_comparison() { |
| + expect(_isInitializedVariableDeclaration("a < 0;"), isFalse); |
| + } |
| + |
| + void test_isInitializedVariableDeclaration_conditional() { |
| + expect(_isInitializedVariableDeclaration("a == null ? init() : update();"), |
| + isFalse); |
| } |
| - void test_parseForStatement_loop_c() { |
| - createParser('for (; i < count;) {}'); |
| - Statement statement = parser.parseForStatement(); |
| - expectNotNullIfNoErrors(statement); |
| - listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<ForStatement>()); |
| - ForStatement forStatement = statement; |
| - expect(forStatement.forKeyword, isNotNull); |
| - expect(forStatement.leftParenthesis, isNotNull); |
| - expect(forStatement.variables, isNull); |
| - expect(forStatement.initialization, isNull); |
| - expect(forStatement.leftSeparator, isNotNull); |
| - expect(forStatement.condition, isNotNull); |
| - expect(forStatement.rightSeparator, isNotNull); |
| - expect(forStatement.updaters, hasLength(0)); |
| - expect(forStatement.rightParenthesis, isNotNull); |
| - expect(forStatement.body, isNotNull); |
| + void test_isInitializedVariableDeclaration_const_noType_initialized() { |
| + expect(_isInitializedVariableDeclaration("const a = 0;"), isTrue); |
| } |
| - void test_parseForStatement_loop_cu() { |
| - createParser('for (; i < count; i++) {}'); |
| - Statement statement = parser.parseForStatement(); |
| - expectNotNullIfNoErrors(statement); |
| - listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<ForStatement>()); |
| - ForStatement forStatement = statement; |
| - expect(forStatement.forKeyword, isNotNull); |
| - expect(forStatement.leftParenthesis, isNotNull); |
| - expect(forStatement.variables, isNull); |
| - expect(forStatement.initialization, isNull); |
| - expect(forStatement.leftSeparator, isNotNull); |
| - expect(forStatement.condition, isNotNull); |
| - expect(forStatement.rightSeparator, isNotNull); |
| - expect(forStatement.updaters, hasLength(1)); |
| - expect(forStatement.rightParenthesis, isNotNull); |
| - expect(forStatement.body, isNotNull); |
| + void test_isInitializedVariableDeclaration_const_noType_uninitialized() { |
| + expect(_isInitializedVariableDeclaration("const a;"), isTrue); |
| } |
| - void test_parseForStatement_loop_ecu() { |
| - createParser('for (i--; i < count; i++) {}'); |
| - Statement statement = parser.parseForStatement(); |
| - expectNotNullIfNoErrors(statement); |
| - listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<ForStatement>()); |
| - ForStatement forStatement = statement; |
| - expect(forStatement.forKeyword, isNotNull); |
| - expect(forStatement.leftParenthesis, isNotNull); |
| - expect(forStatement.variables, isNull); |
| - expect(forStatement.initialization, isNotNull); |
| - expect(forStatement.leftSeparator, isNotNull); |
| - expect(forStatement.condition, isNotNull); |
| - expect(forStatement.rightSeparator, isNotNull); |
| - expect(forStatement.updaters, hasLength(1)); |
| - expect(forStatement.rightParenthesis, isNotNull); |
| - expect(forStatement.body, isNotNull); |
| + void test_isInitializedVariableDeclaration_const_simpleType_uninitialized() { |
| + expect(_isInitializedVariableDeclaration("const A a;"), isTrue); |
| } |
| - void test_parseForStatement_loop_i() { |
| - createParser('for (var i = 0;;) {}'); |
| - Statement statement = parser.parseForStatement(); |
| - expectNotNullIfNoErrors(statement); |
| - listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<ForStatement>()); |
| - ForStatement forStatement = statement; |
| - expect(forStatement.forKeyword, isNotNull); |
| - expect(forStatement.leftParenthesis, isNotNull); |
| - VariableDeclarationList variables = forStatement.variables; |
| - expect(variables, isNotNull); |
| - expect(variables.metadata, hasLength(0)); |
| - expect(variables.variables, hasLength(1)); |
| - expect(forStatement.initialization, isNull); |
| - expect(forStatement.leftSeparator, isNotNull); |
| - expect(forStatement.condition, isNull); |
| - expect(forStatement.rightSeparator, isNotNull); |
| - expect(forStatement.updaters, hasLength(0)); |
| - expect(forStatement.rightParenthesis, isNotNull); |
| - expect(forStatement.body, isNotNull); |
| + void test_isInitializedVariableDeclaration_final_noType_initialized() { |
| + expect(_isInitializedVariableDeclaration("final a = 0;"), isTrue); |
| } |
| - void test_parseForStatement_loop_i_withMetadata() { |
| - createParser('for (@A var i = 0;;) {}'); |
| - Statement statement = parser.parseForStatement(); |
| - expectNotNullIfNoErrors(statement); |
| - listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<ForStatement>()); |
| - ForStatement forStatement = statement; |
| - expect(forStatement.forKeyword, isNotNull); |
| - expect(forStatement.leftParenthesis, isNotNull); |
| - VariableDeclarationList variables = forStatement.variables; |
| - expect(variables, isNotNull); |
| - expect(variables.metadata, hasLength(1)); |
| - expect(variables.variables, hasLength(1)); |
| - expect(forStatement.initialization, isNull); |
| - expect(forStatement.leftSeparator, isNotNull); |
| - expect(forStatement.condition, isNull); |
| - expect(forStatement.rightSeparator, isNotNull); |
| - expect(forStatement.updaters, hasLength(0)); |
| - expect(forStatement.rightParenthesis, isNotNull); |
| - expect(forStatement.body, isNotNull); |
| + void test_isInitializedVariableDeclaration_final_noType_uninitialized() { |
| + expect(_isInitializedVariableDeclaration("final a;"), isTrue); |
| } |
| - void test_parseForStatement_loop_ic() { |
| - createParser('for (var i = 0; i < count;) {}'); |
| - Statement statement = parser.parseForStatement(); |
| - expectNotNullIfNoErrors(statement); |
| - listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<ForStatement>()); |
| - ForStatement forStatement = statement; |
| - expect(forStatement.forKeyword, isNotNull); |
| - expect(forStatement.leftParenthesis, isNotNull); |
| - VariableDeclarationList variables = forStatement.variables; |
| - expect(variables, isNotNull); |
| - expect(variables.variables, hasLength(1)); |
| - expect(forStatement.initialization, isNull); |
| - expect(forStatement.leftSeparator, isNotNull); |
| - expect(forStatement.condition, isNotNull); |
| - expect(forStatement.rightSeparator, isNotNull); |
| - expect(forStatement.updaters, hasLength(0)); |
| - expect(forStatement.rightParenthesis, isNotNull); |
| - expect(forStatement.body, isNotNull); |
| + void test_isInitializedVariableDeclaration_final_simpleType_initialized() { |
| + expect(_isInitializedVariableDeclaration("final A a = 0;"), isTrue); |
| } |
| - void test_parseForStatement_loop_icu() { |
| - createParser('for (var i = 0; i < count; i++) {}'); |
| - Statement statement = parser.parseForStatement(); |
| - expectNotNullIfNoErrors(statement); |
| - listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<ForStatement>()); |
| - ForStatement forStatement = statement; |
| - expect(forStatement.forKeyword, isNotNull); |
| - expect(forStatement.leftParenthesis, isNotNull); |
| - VariableDeclarationList variables = forStatement.variables; |
| - expect(variables, isNotNull); |
| - expect(variables.variables, hasLength(1)); |
| - expect(forStatement.initialization, isNull); |
| - expect(forStatement.leftSeparator, isNotNull); |
| - expect(forStatement.condition, isNotNull); |
| - expect(forStatement.rightSeparator, isNotNull); |
| - expect(forStatement.updaters, hasLength(1)); |
| - expect(forStatement.rightParenthesis, isNotNull); |
| - expect(forStatement.body, isNotNull); |
| + void test_isInitializedVariableDeclaration_functionDeclaration_typed() { |
| + expect(_isInitializedVariableDeclaration("A f() {};"), isFalse); |
| } |
| - void test_parseForStatement_loop_iicuu() { |
| - createParser('for (int i = 0, j = count; i < j; i++, j--) {}'); |
| - Statement statement = parser.parseForStatement(); |
| - expectNotNullIfNoErrors(statement); |
| - listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<ForStatement>()); |
| - ForStatement forStatement = statement; |
| - expect(forStatement.forKeyword, isNotNull); |
| - expect(forStatement.leftParenthesis, isNotNull); |
| - VariableDeclarationList variables = forStatement.variables; |
| - expect(variables, isNotNull); |
| - expect(variables.variables, hasLength(2)); |
| - expect(forStatement.initialization, isNull); |
| - expect(forStatement.leftSeparator, isNotNull); |
| - expect(forStatement.condition, isNotNull); |
| - expect(forStatement.rightSeparator, isNotNull); |
| - expect(forStatement.updaters, hasLength(2)); |
| - expect(forStatement.rightParenthesis, isNotNull); |
| - expect(forStatement.body, isNotNull); |
| + void test_isInitializedVariableDeclaration_functionDeclaration_untyped() { |
| + expect(_isInitializedVariableDeclaration("f() {};"), isFalse); |
| } |
| - void test_parseForStatement_loop_iu() { |
| - createParser('for (var i = 0;; i++) {}'); |
| - Statement statement = parser.parseForStatement(); |
| - expectNotNullIfNoErrors(statement); |
| - listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<ForStatement>()); |
| - ForStatement forStatement = statement; |
| - expect(forStatement.forKeyword, isNotNull); |
| - expect(forStatement.leftParenthesis, isNotNull); |
| - VariableDeclarationList variables = forStatement.variables; |
| - expect(variables, isNotNull); |
| - expect(variables.variables, hasLength(1)); |
| - expect(forStatement.initialization, isNull); |
| - expect(forStatement.leftSeparator, isNotNull); |
| - expect(forStatement.condition, isNull); |
| - expect(forStatement.rightSeparator, isNotNull); |
| - expect(forStatement.updaters, hasLength(1)); |
| - expect(forStatement.rightParenthesis, isNotNull); |
| - expect(forStatement.body, isNotNull); |
| + void test_isInitializedVariableDeclaration_noType_initialized() { |
| + expect(_isInitializedVariableDeclaration("var a = 0;"), isTrue); |
| } |
| - void test_parseForStatement_loop_u() { |
| - createParser('for (;; i++) {}'); |
| - Statement statement = parser.parseForStatement(); |
| - expectNotNullIfNoErrors(statement); |
| - listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<ForStatement>()); |
| - ForStatement forStatement = statement; |
| - expect(forStatement.forKeyword, isNotNull); |
| - expect(forStatement.leftParenthesis, isNotNull); |
| - expect(forStatement.variables, isNull); |
| - expect(forStatement.initialization, isNull); |
| - expect(forStatement.leftSeparator, isNotNull); |
| - expect(forStatement.condition, isNull); |
| - expect(forStatement.rightSeparator, isNotNull); |
| - expect(forStatement.updaters, hasLength(1)); |
| - expect(forStatement.rightParenthesis, isNotNull); |
| - expect(forStatement.body, isNotNull); |
| + void test_isInitializedVariableDeclaration_noType_uninitialized() { |
| + expect(_isInitializedVariableDeclaration("var a;"), isTrue); |
| } |
| - void test_parseFunctionBody_block() { |
| - createParser('{}'); |
| - FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| - expectNotNullIfNoErrors(functionBody); |
| - listener.assertNoErrors(); |
| - expect(functionBody, new isInstanceOf<BlockFunctionBody>()); |
| - BlockFunctionBody body = functionBody; |
| - expect(body.keyword, isNull); |
| - expect(body.star, isNull); |
| - expect(body.block, isNotNull); |
| - expect(body.isAsynchronous, isFalse); |
| - expect(body.isGenerator, isFalse); |
| - expect(body.isSynchronous, isTrue); |
| + void test_isInitializedVariableDeclaration_parameterizedType_initialized() { |
| + expect(_isInitializedVariableDeclaration("List<int> a = null;"), isTrue); |
| } |
| - void test_parseFunctionBody_block_async() { |
| - createParser('async {}'); |
| - FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| - expectNotNullIfNoErrors(functionBody); |
| - listener.assertNoErrors(); |
| - expect(functionBody, new isInstanceOf<BlockFunctionBody>()); |
| - BlockFunctionBody body = functionBody; |
| - expect(body.keyword, isNotNull); |
| - expect(body.keyword.lexeme, Parser.ASYNC); |
| - expect(body.star, isNull); |
| - expect(body.block, isNotNull); |
| - expect(body.isAsynchronous, isTrue); |
| - expect(body.isGenerator, isFalse); |
| - expect(body.isSynchronous, isFalse); |
| + void test_isInitializedVariableDeclaration_parameterizedType_uninitialized() { |
| + expect(_isInitializedVariableDeclaration("List<int> a;"), isTrue); |
| } |
| - void test_parseFunctionBody_block_asyncGenerator() { |
| - createParser('async* {}'); |
| - FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| - expectNotNullIfNoErrors(functionBody); |
| - listener.assertNoErrors(); |
| - expect(functionBody, new isInstanceOf<BlockFunctionBody>()); |
| - BlockFunctionBody body = functionBody; |
| - expect(body.keyword, isNotNull); |
| - expect(body.keyword.lexeme, Parser.ASYNC); |
| - expect(body.star, isNotNull); |
| - expect(body.block, isNotNull); |
| - expect(body.isAsynchronous, isTrue); |
| - expect(body.isGenerator, isTrue); |
| - expect(body.isSynchronous, isFalse); |
| + void test_isInitializedVariableDeclaration_simpleType_initialized() { |
| + expect(_isInitializedVariableDeclaration("A a = 0;"), isTrue); |
| + } |
| + |
| + void test_isInitializedVariableDeclaration_simpleType_uninitialized() { |
| + expect(_isInitializedVariableDeclaration("A a;"), isTrue); |
| } |
| - void test_parseFunctionBody_block_syncGenerator() { |
| - createParser('sync* {}'); |
| - FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| - expectNotNullIfNoErrors(functionBody); |
| - listener.assertNoErrors(); |
| - expect(functionBody, new isInstanceOf<BlockFunctionBody>()); |
| - BlockFunctionBody body = functionBody; |
| - expect(body.keyword, isNotNull); |
| - expect(body.keyword.lexeme, Parser.SYNC); |
| - expect(body.star, isNotNull); |
| - expect(body.block, isNotNull); |
| - expect(body.isAsynchronous, isFalse); |
| - expect(body.isGenerator, isTrue); |
| - expect(body.isSynchronous, isTrue); |
| + void test_isSwitchMember_case_labeled() { |
| + expect(_isSwitchMember("l1: l2: case"), isTrue); |
| } |
| - void test_parseFunctionBody_empty() { |
| - createParser(';'); |
| - FunctionBody functionBody = parser.parseFunctionBody(true, null, false); |
| - expectNotNullIfNoErrors(functionBody); |
| - listener.assertNoErrors(); |
| - expect(functionBody, new isInstanceOf<EmptyFunctionBody>()); |
| - EmptyFunctionBody body = functionBody; |
| - expect(body.semicolon, isNotNull); |
| + void test_isSwitchMember_case_unlabeled() { |
| + expect(_isSwitchMember("case"), isTrue); |
| } |
| - void test_parseFunctionBody_expression() { |
| - createParser('=> y;'); |
| - FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| - expectNotNullIfNoErrors(functionBody); |
| - listener.assertNoErrors(); |
| - expect(functionBody, new isInstanceOf<ExpressionFunctionBody>()); |
| - ExpressionFunctionBody body = functionBody; |
| - expect(body.keyword, isNull); |
| - expect(body.functionDefinition, isNotNull); |
| - expect(body.expression, isNotNull); |
| - expect(body.semicolon, isNotNull); |
| - expect(body.isAsynchronous, isFalse); |
| - expect(body.isGenerator, isFalse); |
| - expect(body.isSynchronous, isTrue); |
| + void test_isSwitchMember_default_labeled() { |
| + expect(_isSwitchMember("l1: l2: default"), isTrue); |
| } |
| - void test_parseFunctionBody_expression_async() { |
| - createParser('async => y;'); |
| - FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| - expectNotNullIfNoErrors(functionBody); |
| - listener.assertNoErrors(); |
| - expect(functionBody, new isInstanceOf<ExpressionFunctionBody>()); |
| - ExpressionFunctionBody body = functionBody; |
| - expect(body.keyword, isNotNull); |
| - expect(body.keyword.lexeme, Parser.ASYNC); |
| - expect(body.functionDefinition, isNotNull); |
| - expect(body.expression, isNotNull); |
| - expect(body.semicolon, isNotNull); |
| - expect(body.isAsynchronous, isTrue); |
| - expect(body.isGenerator, isFalse); |
| - expect(body.isSynchronous, isFalse); |
| + void test_isSwitchMember_default_unlabeled() { |
| + expect(_isSwitchMember("default"), isTrue); |
| } |
| - void test_parseFunctionBody_nativeFunctionBody() { |
| - createParser('native "str";'); |
| - FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| - expectNotNullIfNoErrors(functionBody); |
| - listener.assertNoErrors(); |
| - expect(functionBody, new isInstanceOf<NativeFunctionBody>()); |
| - NativeFunctionBody body = functionBody; |
| - expect(body.nativeKeyword, isNotNull); |
| - expect(body.stringLiteral, isNotNull); |
| - expect(body.semicolon, isNotNull); |
| + void test_isSwitchMember_false() { |
| + expect(_isSwitchMember("break;"), isFalse); |
| } |
| - void test_parseFunctionBody_skip_block() { |
| - ParserTestCase.parseFunctionBodies = false; |
| - createParser('{}'); |
| - FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| - expectNotNullIfNoErrors(functionBody); |
| + void test_parseAnnotation_n1() { |
| + createParser('@A'); |
| + Annotation annotation = parser.parseAnnotation(); |
| + expectNotNullIfNoErrors(annotation); |
| listener.assertNoErrors(); |
| - expect(functionBody, new isInstanceOf<EmptyFunctionBody>()); |
| + expect(annotation.atSign, isNotNull); |
| + expect(annotation.name, isNotNull); |
| + expect(annotation.period, isNull); |
| + expect(annotation.constructorName, isNull); |
| + expect(annotation.arguments, isNull); |
| } |
| - void test_parseFunctionBody_skip_block_invalid() { |
| - ParserTestCase.parseFunctionBodies = false; |
| - createParser('{'); |
| - FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| - expectNotNullIfNoErrors(functionBody); |
| - listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_TOKEN]); |
| - expect(functionBody, new isInstanceOf<EmptyFunctionBody>()); |
| + void test_parseAnnotation_n1_a() { |
| + createParser('@A(x,y)'); |
| + Annotation annotation = parser.parseAnnotation(); |
| + expectNotNullIfNoErrors(annotation); |
| + listener.assertNoErrors(); |
| + expect(annotation.atSign, isNotNull); |
| + expect(annotation.name, isNotNull); |
| + expect(annotation.period, isNull); |
| + expect(annotation.constructorName, isNull); |
| + expect(annotation.arguments, isNotNull); |
| } |
| - void test_parseFunctionBody_skip_blocks() { |
| - ParserTestCase.parseFunctionBodies = false; |
| - createParser('{ {} }'); |
| - FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| - expectNotNullIfNoErrors(functionBody); |
| + void test_parseAnnotation_n2() { |
| + createParser('@A.B'); |
| + Annotation annotation = parser.parseAnnotation(); |
| + expectNotNullIfNoErrors(annotation); |
| listener.assertNoErrors(); |
| - expect(functionBody, new isInstanceOf<EmptyFunctionBody>()); |
| + expect(annotation.atSign, isNotNull); |
| + expect(annotation.name, isNotNull); |
| + expect(annotation.period, isNull); |
| + expect(annotation.constructorName, isNull); |
| + expect(annotation.arguments, isNull); |
| } |
| - void test_parseFunctionBody_skip_expression() { |
| - ParserTestCase.parseFunctionBodies = false; |
| - createParser('=> y;'); |
| - FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| - expectNotNullIfNoErrors(functionBody); |
| + void test_parseAnnotation_n2_a() { |
| + createParser('@A.B(x,y)'); |
| + Annotation annotation = parser.parseAnnotation(); |
| + expectNotNullIfNoErrors(annotation); |
| listener.assertNoErrors(); |
| - expect(functionBody, new isInstanceOf<EmptyFunctionBody>()); |
| + expect(annotation.atSign, isNotNull); |
| + expect(annotation.name, isNotNull); |
| + expect(annotation.period, isNull); |
| + expect(annotation.constructorName, isNull); |
| + expect(annotation.arguments, isNotNull); |
| } |
| - void test_parseFunctionDeclarationStatement() { |
| - createParser('void f(int p) => p * 2;'); |
| - FunctionDeclarationStatement statement = |
| - parser.parseFunctionDeclarationStatement(); |
| - expectNotNullIfNoErrors(statement); |
| + void test_parseAnnotation_n3() { |
| + createParser('@A.B.C'); |
| + Annotation annotation = parser.parseAnnotation(); |
| + expectNotNullIfNoErrors(annotation); |
| listener.assertNoErrors(); |
| - expect(statement.functionDeclaration, isNotNull); |
| + expect(annotation.atSign, isNotNull); |
| + expect(annotation.name, isNotNull); |
| + expect(annotation.period, isNotNull); |
| + expect(annotation.constructorName, isNotNull); |
| + expect(annotation.arguments, isNull); |
| } |
| - void test_parseFunctionDeclarationStatement_typeParameterComments() { |
| - enableGenericMethodComments = true; |
| - createParser('/*=E*/ f/*<E>*/(/*=E*/ p) => p * 2;'); |
| - FunctionDeclarationStatement statement = |
| - parser.parseFunctionDeclarationStatement(); |
| - expectNotNullIfNoErrors(statement); |
| + void test_parseAnnotation_n3_a() { |
| + createParser('@A.B.C(x,y)'); |
| + Annotation annotation = parser.parseAnnotation(); |
| + expectNotNullIfNoErrors(annotation); |
| listener.assertNoErrors(); |
| - FunctionDeclaration f = statement.functionDeclaration; |
| - expect(f, isNotNull); |
| - expect(f.functionExpression.typeParameters, isNotNull); |
| - expect(f.returnType, isNotNull); |
| - SimpleFormalParameter p = f.functionExpression.parameters.parameters[0]; |
| - expect(p.type, isNotNull); |
| + expect(annotation.atSign, isNotNull); |
| + expect(annotation.name, isNotNull); |
| + expect(annotation.period, isNotNull); |
| + expect(annotation.constructorName, isNotNull); |
| + expect(annotation.arguments, isNotNull); |
| } |
| - void test_parseFunctionDeclarationStatement_typeParameters() { |
| - createParser('E f<E>(E p) => p * 2;'); |
| - FunctionDeclarationStatement statement = |
| - parser.parseFunctionDeclarationStatement(); |
| - expectNotNullIfNoErrors(statement); |
| + void test_parseArgument_named() { |
| + createParser('n: x'); |
| + Expression expression = parser.parseArgument(); |
| + expectNotNullIfNoErrors(expression); |
| listener.assertNoErrors(); |
| - expect(statement.functionDeclaration, isNotNull); |
| - expect(statement.functionDeclaration.functionExpression.typeParameters, |
| - isNotNull); |
| + expect(expression, new isInstanceOf<NamedExpression>()); |
| + NamedExpression namedExpression = expression; |
| + Label name = namedExpression.name; |
| + expect(name, isNotNull); |
| + expect(name.label, isNotNull); |
| + expect(name.colon, isNotNull); |
| + expect(namedExpression.expression, isNotNull); |
| } |
| - void test_parseFunctionDeclarationStatement_typeParameters_noReturnType() { |
| - createParser('f<E>(E p) => p * 2;'); |
| - FunctionDeclarationStatement statement = |
| - parser.parseFunctionDeclarationStatement(); |
| - expectNotNullIfNoErrors(statement); |
| + void test_parseArgument_unnamed() { |
| + String lexeme = "x"; |
| + createParser(lexeme); |
| + Expression expression = parser.parseArgument(); |
| + expectNotNullIfNoErrors(expression); |
| listener.assertNoErrors(); |
| - expect(statement.functionDeclaration, isNotNull); |
| - expect(statement.functionDeclaration.functionExpression.typeParameters, |
| - isNotNull); |
| + expect(expression, new isInstanceOf<SimpleIdentifier>()); |
| + SimpleIdentifier identifier = expression; |
| + expect(identifier.name, lexeme); |
| } |
| - void test_parseFunctionExpression_body_inExpression() { |
| - createParser('(int i) => i++'); |
| - FunctionExpression expression = parser.parseFunctionExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseArgumentList_empty() { |
| + createParser('()'); |
| + ArgumentList argumentList = parser.parseArgumentList(); |
| + expectNotNullIfNoErrors(argumentList); |
| listener.assertNoErrors(); |
| - expect(expression.body, isNotNull); |
| - expect(expression.typeParameters, isNull); |
| - expect(expression.parameters, isNotNull); |
| - expect((expression.body as ExpressionFunctionBody).semicolon, isNull); |
| + NodeList<Expression> arguments = argumentList.arguments; |
| + expect(arguments, hasLength(0)); |
| } |
| - void test_parseFunctionExpression_typeParameterComments() { |
| - enableGenericMethodComments = true; |
| - createParser('/*<E>*/(/*=E*/ i) => i++'); |
| - FunctionExpression expression = parser.parseFunctionExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseArgumentList_mixed() { |
| + createParser('(w, x, y: y, z: z)'); |
| + ArgumentList argumentList = parser.parseArgumentList(); |
| + expectNotNullIfNoErrors(argumentList); |
| listener.assertNoErrors(); |
| - expect(expression.body, isNotNull); |
| - expect(expression.typeParameters, isNotNull); |
| - expect(expression.parameters, isNotNull); |
| - expect((expression.body as ExpressionFunctionBody).semicolon, isNull); |
| - SimpleFormalParameter p = expression.parameters.parameters[0]; |
| - expect(p.type, isNotNull); |
| + NodeList<Expression> arguments = argumentList.arguments; |
| + expect(arguments, hasLength(4)); |
| } |
| - void test_parseFunctionExpression_typeParameters() { |
| - createParser('<E>(E i) => i++'); |
| - FunctionExpression expression = parser.parseFunctionExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseArgumentList_noNamed() { |
| + createParser('(x, y, z)'); |
| + ArgumentList argumentList = parser.parseArgumentList(); |
| + expectNotNullIfNoErrors(argumentList); |
| listener.assertNoErrors(); |
| - expect(expression.body, isNotNull); |
| - expect(expression.typeParameters, isNotNull); |
| - expect(expression.parameters, isNotNull); |
| - expect((expression.body as ExpressionFunctionBody).semicolon, isNull); |
| + NodeList<Expression> arguments = argumentList.arguments; |
| + expect(arguments, hasLength(3)); |
| } |
| - void test_parseIdentifierList_multiple() { |
| - createParser('a, b, c'); |
| - List<SimpleIdentifier> list = parser.parseIdentifierList(); |
| - expectNotNullIfNoErrors(list); |
| + void test_parseArgumentList_onlyNamed() { |
| + createParser('(x: x, y: y)'); |
| + ArgumentList argumentList = parser.parseArgumentList(); |
| + expectNotNullIfNoErrors(argumentList); |
| listener.assertNoErrors(); |
| - expect(list, hasLength(3)); |
| + NodeList<Expression> arguments = argumentList.arguments; |
| + expect(arguments, hasLength(2)); |
| } |
| - void test_parseIdentifierList_single() { |
| - createParser('a'); |
| - List<SimpleIdentifier> list = parser.parseIdentifierList(); |
| - expectNotNullIfNoErrors(list); |
| + void test_parseArgumentList_trailing_comma() { |
| + createParser('(x, y, z,)'); |
| + ArgumentList argumentList = parser.parseArgumentList(); |
| + expectNotNullIfNoErrors(argumentList); |
| listener.assertNoErrors(); |
| - expect(list, hasLength(1)); |
| + NodeList<Expression> arguments = argumentList.arguments; |
| + expect(arguments, hasLength(3)); |
| } |
| - void test_parseIfStatement_else_block() { |
| - createParser('if (x) {} else {}'); |
| - IfStatement statement = parser.parseIfStatement(); |
| + void test_parseAssertStatement() { |
| + createParser('assert (x);'); |
| + AssertStatement statement = parser.parseAssertStatement(); |
| expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(statement.ifKeyword, isNotNull); |
| + expect(statement.assertKeyword, isNotNull); |
| expect(statement.leftParenthesis, isNotNull); |
| expect(statement.condition, isNotNull); |
| + expect(statement.comma, isNull); |
| + expect(statement.message, isNull); |
| expect(statement.rightParenthesis, isNotNull); |
| - expect(statement.thenStatement, isNotNull); |
| - expect(statement.elseKeyword, isNotNull); |
| - expect(statement.elseStatement, isNotNull); |
| + expect(statement.semicolon, isNotNull); |
| } |
| - void test_parseIfStatement_else_statement() { |
| - createParser('if (x) f(x); else f(y);'); |
| - IfStatement statement = parser.parseIfStatement(); |
| + void test_parseAssertStatement_messageLowPrecedence() { |
| + // Using a throw expression as an assert message would be silly in |
| + // practice, but it's the lowest precedence expression type, so verifying |
| + // that it works should give us high confidence that other expression types |
| + // will work as well. |
| + createParser('assert (x, throw "foo");'); |
| + AssertStatement statement = parser.parseAssertStatement(); |
| expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(statement.ifKeyword, isNotNull); |
| + expect(statement.assertKeyword, isNotNull); |
| expect(statement.leftParenthesis, isNotNull); |
| expect(statement.condition, isNotNull); |
| + expect(statement.comma, isNotNull); |
| + expect(statement.message, isNotNull); |
| expect(statement.rightParenthesis, isNotNull); |
| - expect(statement.thenStatement, isNotNull); |
| - expect(statement.elseKeyword, isNotNull); |
| - expect(statement.elseStatement, isNotNull); |
| + expect(statement.semicolon, isNotNull); |
| } |
| - void test_parseIfStatement_noElse_block() { |
| - createParser('if (x) {}'); |
| - IfStatement statement = parser.parseIfStatement(); |
| + void test_parseAssertStatement_messageString() { |
| + createParser('assert (x, "foo");'); |
| + AssertStatement statement = parser.parseAssertStatement(); |
| expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(statement.ifKeyword, isNotNull); |
| + expect(statement.assertKeyword, isNotNull); |
| expect(statement.leftParenthesis, isNotNull); |
| expect(statement.condition, isNotNull); |
| + expect(statement.comma, isNotNull); |
| + expect(statement.message, isNotNull); |
| expect(statement.rightParenthesis, isNotNull); |
| - expect(statement.thenStatement, isNotNull); |
| - expect(statement.elseKeyword, isNull); |
| - expect(statement.elseStatement, isNull); |
| + expect(statement.semicolon, isNotNull); |
| } |
| - void test_parseIfStatement_noElse_statement() { |
| - createParser('if (x) f(x);'); |
| - IfStatement statement = parser.parseIfStatement(); |
| + void test_parseBlock_empty() { |
| + createParser('{}'); |
| + Block block = parser.parseBlock(); |
| + expectNotNullIfNoErrors(block); |
| + listener.assertNoErrors(); |
| + expect(block.leftBracket, isNotNull); |
| + expect(block.statements, hasLength(0)); |
| + expect(block.rightBracket, isNotNull); |
| + } |
| + |
| + void test_parseBlock_nonEmpty() { |
| + createParser('{;}'); |
| + Block block = parser.parseBlock(); |
| + expectNotNullIfNoErrors(block); |
| + listener.assertNoErrors(); |
| + expect(block.leftBracket, isNotNull); |
| + expect(block.statements, hasLength(1)); |
| + expect(block.rightBracket, isNotNull); |
| + } |
| + |
| + void test_parseBreakStatement_label() { |
| + createParser('break foo;'); |
| + BreakStatement statement = parser.parseBreakStatement(); |
| expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(statement.ifKeyword, isNotNull); |
| - expect(statement.leftParenthesis, isNotNull); |
| - expect(statement.condition, isNotNull); |
| - expect(statement.rightParenthesis, isNotNull); |
| - expect(statement.thenStatement, isNotNull); |
| - expect(statement.elseKeyword, isNull); |
| - expect(statement.elseStatement, isNull); |
| + expect(statement.breakKeyword, isNotNull); |
| + expect(statement.label, isNotNull); |
| + expect(statement.semicolon, isNotNull); |
| } |
| - void test_parseImplementsClause_multiple() { |
| - createParser('implements A, B, C'); |
| - ImplementsClause clause = parser.parseImplementsClause(); |
| - expectNotNullIfNoErrors(clause); |
| + void test_parseBreakStatement_noLabel() { |
| + createParser('break;'); |
| + BreakStatement statement = parser.parseBreakStatement(); |
| + expectNotNullIfNoErrors(statement); |
| + listener.assertErrorsWithCodes([ParserErrorCode.BREAK_OUTSIDE_OF_LOOP]); |
| + expect(statement.breakKeyword, isNotNull); |
| + expect(statement.label, isNull); |
| + expect(statement.semicolon, isNotNull); |
| + } |
| + |
| + void test_parseCombinator_hide() { |
| + createParser('hide a;'); |
| + Combinator combinator = parser.parseCombinator(); |
| + expectNotNullIfNoErrors(combinator); |
| listener.assertNoErrors(); |
| - expect(clause.interfaces, hasLength(3)); |
| - expect(clause.implementsKeyword, isNotNull); |
| + expect(combinator, new isInstanceOf<HideCombinator>()); |
| + HideCombinator hideCombinator = combinator; |
| + expect(hideCombinator.keyword, isNotNull); |
| + expect(hideCombinator.hiddenNames, hasLength(1)); |
| } |
| - void test_parseImplementsClause_single() { |
| - createParser('implements A'); |
| - ImplementsClause clause = parser.parseImplementsClause(); |
| - expectNotNullIfNoErrors(clause); |
| + void test_parseCombinator_show() { |
| + createParser('show a;'); |
| + Combinator combinator = parser.parseCombinator(); |
| + expectNotNullIfNoErrors(combinator); |
| listener.assertNoErrors(); |
| - expect(clause.interfaces, hasLength(1)); |
| - expect(clause.implementsKeyword, isNotNull); |
| + expect(combinator, new isInstanceOf<ShowCombinator>()); |
| + ShowCombinator showCombinator = combinator; |
| + expect(showCombinator.keyword, isNotNull); |
| + expect(showCombinator.shownNames, hasLength(1)); |
| } |
| - void test_parseInstanceCreationExpression_qualifiedType() { |
| - Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| - createParser('A.B()'); |
| - InstanceCreationExpression expression = |
| - parser.parseInstanceCreationExpression(token); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseCombinators_h() { |
| + createParser('hide a;'); |
| + List<Combinator> combinators = parser.parseCombinators(); |
| + expectNotNullIfNoErrors(combinators); |
| listener.assertNoErrors(); |
| - expect(expression.keyword, token); |
| - ConstructorName name = expression.constructorName; |
| - expect(name, isNotNull); |
| - TypeName type = name.type; |
| - expect(type, isNotNull); |
| - expect(type.typeArguments, isNull); |
| - expect(name.period, isNull); |
| - expect(name.name, isNull); |
| - expect(expression.argumentList, isNotNull); |
| + expect(combinators, hasLength(1)); |
| + HideCombinator combinator = combinators[0] as HideCombinator; |
| + expect(combinator, isNotNull); |
| + expect(combinator.keyword, isNotNull); |
| + expect(combinator.hiddenNames, hasLength(1)); |
| } |
| - void test_parseInstanceCreationExpression_qualifiedType_named() { |
| - Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| - createParser('A.B.c()'); |
| - InstanceCreationExpression expression = |
| - parser.parseInstanceCreationExpression(token); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseCombinators_hs() { |
| + createParser('hide a show b;'); |
| + List<Combinator> combinators = parser.parseCombinators(); |
| + expectNotNullIfNoErrors(combinators); |
| listener.assertNoErrors(); |
| - expect(expression.keyword, token); |
| - ConstructorName name = expression.constructorName; |
| - expect(name, isNotNull); |
| - TypeName type = name.type; |
| - expect(type, isNotNull); |
| - expect(type.typeArguments, isNull); |
| - expect(name.period, isNotNull); |
| - expect(name.name, isNotNull); |
| - expect(expression.argumentList, isNotNull); |
| + expect(combinators, hasLength(2)); |
| + HideCombinator hideCombinator = combinators[0] as HideCombinator; |
| + expect(hideCombinator, isNotNull); |
| + expect(hideCombinator.keyword, isNotNull); |
| + expect(hideCombinator.hiddenNames, hasLength(1)); |
| + ShowCombinator showCombinator = combinators[1] as ShowCombinator; |
| + expect(showCombinator, isNotNull); |
| + expect(showCombinator.keyword, isNotNull); |
| + expect(showCombinator.shownNames, hasLength(1)); |
| } |
| - void |
| - test_parseInstanceCreationExpression_qualifiedType_named_typeParameterComment() { |
| - enableGenericMethodComments = true; |
| - Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| - createParser('A.B/*<E>*/.c()'); |
| - InstanceCreationExpression expression = |
| - parser.parseInstanceCreationExpression(token); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseCombinators_hshs() { |
| + createParser('hide a show b hide c show d;'); |
| + List<Combinator> combinators = parser.parseCombinators(); |
| + expectNotNullIfNoErrors(combinators); |
| listener.assertNoErrors(); |
| - expect(expression.keyword, token); |
| - ConstructorName name = expression.constructorName; |
| - expect(name, isNotNull); |
| - TypeName type = name.type; |
| - expect(type, isNotNull); |
| - expect(type.typeArguments.arguments, hasLength(1)); |
| - expect(name.period, isNotNull); |
| - expect(name.name, isNotNull); |
| - expect(expression.argumentList, isNotNull); |
| + expect(combinators, hasLength(4)); |
| } |
| - void |
| - test_parseInstanceCreationExpression_qualifiedType_named_typeParameters() { |
| - Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| - createParser('A.B<E>.c()'); |
| - InstanceCreationExpression expression = |
| - parser.parseInstanceCreationExpression(token); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseCombinators_s() { |
| + createParser('show a;'); |
| + List<Combinator> combinators = parser.parseCombinators(); |
| + expectNotNullIfNoErrors(combinators); |
| listener.assertNoErrors(); |
| - expect(expression.keyword, token); |
| - ConstructorName name = expression.constructorName; |
| - expect(name, isNotNull); |
| - TypeName type = name.type; |
| - expect(type, isNotNull); |
| - expect(type.typeArguments.arguments, hasLength(1)); |
| - expect(name.period, isNotNull); |
| - expect(name.name, isNotNull); |
| - expect(expression.argumentList, isNotNull); |
| + expect(combinators, hasLength(1)); |
| + ShowCombinator combinator = combinators[0] as ShowCombinator; |
| + expect(combinator, isNotNull); |
| + expect(combinator.keyword, isNotNull); |
| + expect(combinator.shownNames, hasLength(1)); |
| + } |
| + |
| + void test_parseCommentAndMetadata_c() { |
| + createParser('/** 1 */ void'); |
| + CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| + expectNotNullIfNoErrors(commentAndMetadata); |
| + listener.assertNoErrors(); |
| + expect(commentAndMetadata.comment, isNotNull); |
| + expect(commentAndMetadata.metadata, isNull); |
| + } |
| + |
| + void test_parseCommentAndMetadata_cmc() { |
| + createParser('/** 1 */ @A /** 2 */ void'); |
| + CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| + expectNotNullIfNoErrors(commentAndMetadata); |
| + listener.assertNoErrors(); |
| + expect(commentAndMetadata.comment, isNotNull); |
| + expect(commentAndMetadata.metadata, hasLength(1)); |
| + } |
| + |
| + void test_parseCommentAndMetadata_cmcm() { |
| + createParser('/** 1 */ @A /** 2 */ @B void'); |
| + CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| + expectNotNullIfNoErrors(commentAndMetadata); |
| + listener.assertNoErrors(); |
| + expect(commentAndMetadata.comment, isNotNull); |
| + expect(commentAndMetadata.metadata, hasLength(2)); |
| } |
| - void |
| - test_parseInstanceCreationExpression_qualifiedType_typeParameterComment() { |
| - enableGenericMethodComments = true; |
| - Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| - createParser('A.B/*<E>*/()'); |
| - InstanceCreationExpression expression = |
| - parser.parseInstanceCreationExpression(token); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseCommentAndMetadata_cmm() { |
| + createParser('/** 1 */ @A @B void'); |
| + CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| + expectNotNullIfNoErrors(commentAndMetadata); |
| listener.assertNoErrors(); |
| - expect(expression.keyword, token); |
| - ConstructorName name = expression.constructorName; |
| - expect(name, isNotNull); |
| - TypeName type = name.type; |
| - expect(type, isNotNull); |
| - expect(type.typeArguments.arguments, hasLength(1)); |
| - expect(name.period, isNull); |
| - expect(name.name, isNull); |
| - expect(expression.argumentList, isNotNull); |
| + expect(commentAndMetadata.comment, isNotNull); |
| + expect(commentAndMetadata.metadata, hasLength(2)); |
| } |
| - void test_parseInstanceCreationExpression_qualifiedType_typeParameters() { |
| - Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| - createParser('A.B<E>()'); |
| - InstanceCreationExpression expression = |
| - parser.parseInstanceCreationExpression(token); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseCommentAndMetadata_m() { |
| + createParser('@A void'); |
| + CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| + expectNotNullIfNoErrors(commentAndMetadata); |
| listener.assertNoErrors(); |
| - expect(expression.keyword, token); |
| - ConstructorName name = expression.constructorName; |
| - expect(name, isNotNull); |
| - TypeName type = name.type; |
| - expect(type, isNotNull); |
| - expect(type.typeArguments.arguments, hasLength(1)); |
| - expect(name.period, isNull); |
| - expect(name.name, isNull); |
| - expect(expression.argumentList, isNotNull); |
| + expect(commentAndMetadata.comment, isNull); |
| + expect(commentAndMetadata.metadata, hasLength(1)); |
| } |
| - void test_parseInstanceCreationExpression_type() { |
| - Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| - createParser('A()'); |
| - InstanceCreationExpression expression = |
| - parser.parseInstanceCreationExpression(token); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseCommentAndMetadata_mcm() { |
| + createParser('@A /** 1 */ @B void'); |
| + CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| + expectNotNullIfNoErrors(commentAndMetadata); |
| listener.assertNoErrors(); |
| - expect(expression.keyword, token); |
| - ConstructorName name = expression.constructorName; |
| - expect(name, isNotNull); |
| - TypeName type = name.type; |
| - expect(type, isNotNull); |
| - expect(type.typeArguments, isNull); |
| - expect(name.period, isNull); |
| - expect(name.name, isNull); |
| - expect(expression.argumentList, isNotNull); |
| + expect(commentAndMetadata.comment, isNotNull); |
| + expect(commentAndMetadata.metadata, hasLength(2)); |
| } |
| - void test_parseInstanceCreationExpression_type_named() { |
| - enableGenericMethodComments = true; |
| - Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| - createParser('A.c()'); |
| - InstanceCreationExpression expression = |
| - parser.parseInstanceCreationExpression(token); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseCommentAndMetadata_mcmc() { |
| + createParser('@A /** 1 */ @B /** 2 */ void'); |
| + CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| + expectNotNullIfNoErrors(commentAndMetadata); |
| listener.assertNoErrors(); |
| - expect(expression.keyword, token); |
| - ConstructorName name = expression.constructorName; |
| - expect(name, isNotNull); |
| - TypeName type = name.type; |
| - expect(type, isNotNull); |
| - expect(type.typeArguments, isNull); |
| - expect(name.period, isNull); |
| - expect(name.name, isNull); |
| - expect(expression.argumentList, isNotNull); |
| + expect(commentAndMetadata.comment, isNotNull); |
| + expect(commentAndMetadata.metadata, hasLength(2)); |
| } |
| - void test_parseInstanceCreationExpression_type_named_typeParameterComment() { |
| - enableGenericMethodComments = true; |
| - Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| - createParser('A/*<B>*/.c()'); |
| - InstanceCreationExpression expression = |
| - parser.parseInstanceCreationExpression(token); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseCommentAndMetadata_mm() { |
| + createParser('@A @B(x) void'); |
| + CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| + expectNotNullIfNoErrors(commentAndMetadata); |
| listener.assertNoErrors(); |
| - expect(expression.keyword, token); |
| - ConstructorName name = expression.constructorName; |
| - expect(name, isNotNull); |
| - TypeName type = name.type; |
| - expect(type, isNotNull); |
| - expect(type.typeArguments.arguments, hasLength(1)); |
| - expect(name.period, isNotNull); |
| - expect(name.name, isNotNull); |
| - expect(expression.argumentList, isNotNull); |
| + expect(commentAndMetadata.comment, isNull); |
| + expect(commentAndMetadata.metadata, hasLength(2)); |
| } |
| - void test_parseInstanceCreationExpression_type_named_typeParameters() { |
| - Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| - createParser('A<B>.c()'); |
| - InstanceCreationExpression expression = |
| - parser.parseInstanceCreationExpression(token); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseCommentAndMetadata_none() { |
| + createParser('void'); |
| + CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| + expectNotNullIfNoErrors(commentAndMetadata); |
| listener.assertNoErrors(); |
| - expect(expression.keyword, token); |
| - ConstructorName name = expression.constructorName; |
| - expect(name, isNotNull); |
| - TypeName type = name.type; |
| - expect(type, isNotNull); |
| - expect(type.typeArguments.arguments, hasLength(1)); |
| - expect(name.period, isNotNull); |
| - expect(name.name, isNotNull); |
| - expect(expression.argumentList, isNotNull); |
| + expect(commentAndMetadata.comment, isNull); |
| + expect(commentAndMetadata.metadata, isNull); |
| } |
| - void test_parseInstanceCreationExpression_type_typeParameterComment() { |
| - enableGenericMethodComments = true; |
| - Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| - createParser('A/*<B>*/()'); |
| - InstanceCreationExpression expression = |
| - parser.parseInstanceCreationExpression(token); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseCommentAndMetadata_singleLine() { |
| + createParser(r''' |
| +/// 1 |
| +/// 2 |
| +void'''); |
| + CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| + expectNotNullIfNoErrors(commentAndMetadata); |
| listener.assertNoErrors(); |
| - expect(expression.keyword, token); |
| - ConstructorName name = expression.constructorName; |
| - expect(name, isNotNull); |
| - TypeName type = name.type; |
| - expect(type, isNotNull); |
| - expect(type.typeArguments.arguments, hasLength(1)); |
| - expect(name.period, isNull); |
| - expect(name.name, isNull); |
| - expect(expression.argumentList, isNotNull); |
| + expect(commentAndMetadata.comment, isNotNull); |
| + expect(commentAndMetadata.metadata, isNull); |
| } |
| - void test_parseInstanceCreationExpression_type_typeParameters() { |
| - Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| - createParser('A<B>()'); |
| - InstanceCreationExpression expression = |
| - parser.parseInstanceCreationExpression(token); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseCommentReference_new_prefixed() { |
| + createParser(''); |
| + CommentReference reference = parser.parseCommentReference('new a.b', 7); |
| + expectNotNullIfNoErrors(reference); |
| listener.assertNoErrors(); |
| - expect(expression.keyword, token); |
| - ConstructorName name = expression.constructorName; |
| - expect(name, isNotNull); |
| - TypeName type = name.type; |
| - expect(type, isNotNull); |
| - expect(type.typeArguments.arguments, hasLength(1)); |
| - expect(name.period, isNull); |
| - expect(name.name, isNull); |
| - expect(expression.argumentList, isNotNull); |
| + expect(reference.identifier, new isInstanceOf<PrefixedIdentifier>()); |
| + PrefixedIdentifier prefixedIdentifier = reference.identifier; |
| + SimpleIdentifier prefix = prefixedIdentifier.prefix; |
| + expect(prefix.token, isNotNull); |
| + expect(prefix.name, "a"); |
| + expect(prefix.offset, 11); |
| + expect(prefixedIdentifier.period, isNotNull); |
| + SimpleIdentifier identifier = prefixedIdentifier.identifier; |
| + expect(identifier.token, isNotNull); |
| + expect(identifier.name, "b"); |
| + expect(identifier.offset, 13); |
| } |
| - void test_parseInstanceCreationExpression_type_typeParameters_nullable() { |
| - enableNnbd = true; |
| - Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| - createParser('A<B?>()'); |
| - InstanceCreationExpression expression = |
| - parser.parseInstanceCreationExpression(token); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseCommentReference_new_simple() { |
| + createParser(''); |
| + CommentReference reference = parser.parseCommentReference('new a', 5); |
| + expectNotNullIfNoErrors(reference); |
| listener.assertNoErrors(); |
| - expect(expression.keyword, token); |
| - ConstructorName name = expression.constructorName; |
| - expect(name, isNotNull); |
| - TypeName type = name.type; |
| - expect(type, isNotNull); |
| - expect(name.period, isNull); |
| - expect(name.name, isNull); |
| - expect(expression.argumentList, isNotNull); |
| - NodeList<TypeAnnotation> arguments = type.typeArguments.arguments; |
| - expect(arguments, hasLength(1)); |
| - expect((arguments[0] as TypeName).question, isNotNull); |
| + expect(reference.identifier, new isInstanceOf<SimpleIdentifier>()); |
| + SimpleIdentifier identifier = reference.identifier; |
| + expect(identifier.token, isNotNull); |
| + expect(identifier.name, "a"); |
| + expect(identifier.offset, 9); |
| } |
| - void test_parseLibraryIdentifier_multiple() { |
| - String name = "a.b.c"; |
| - createParser(name); |
| - LibraryIdentifier identifier = parser.parseLibraryIdentifier(); |
| - expectNotNullIfNoErrors(identifier); |
| + void test_parseCommentReference_operator_withKeyword_notPrefixed() { |
| + createParser(''); |
| + CommentReference reference = parser.parseCommentReference('operator ==', 5); |
| + expectNotNullIfNoErrors(reference); |
| listener.assertNoErrors(); |
| - expect(identifier.name, name); |
| + expect(reference.identifier, new isInstanceOf<SimpleIdentifier>()); |
| + SimpleIdentifier identifier = reference.identifier; |
| + expect(identifier.token, isNotNull); |
| + expect(identifier.name, "=="); |
| + expect(identifier.offset, 14); |
| } |
| - void test_parseLibraryIdentifier_single() { |
| - String name = "a"; |
| - createParser(name); |
| - LibraryIdentifier identifier = parser.parseLibraryIdentifier(); |
| - expectNotNullIfNoErrors(identifier); |
| + void test_parseCommentReference_operator_withKeyword_prefixed() { |
| + createParser(''); |
| + CommentReference reference = |
| + parser.parseCommentReference('Object.operator==', 7); |
| + expectNotNullIfNoErrors(reference); |
| + listener.assertNoErrors(); |
| + expect(reference.identifier, new isInstanceOf<PrefixedIdentifier>()); |
| + PrefixedIdentifier prefixedIdentifier = reference.identifier; |
| + SimpleIdentifier prefix = prefixedIdentifier.prefix; |
| + expect(prefix.token, isNotNull); |
| + expect(prefix.name, "Object"); |
| + expect(prefix.offset, 7); |
| + expect(prefixedIdentifier.period, isNotNull); |
| + SimpleIdentifier identifier = prefixedIdentifier.identifier; |
| + expect(identifier.token, isNotNull); |
| + expect(identifier.name, "=="); |
| + expect(identifier.offset, 22); |
| + } |
| + |
| + void test_parseCommentReference_operator_withoutKeyword_notPrefixed() { |
| + createParser(''); |
| + CommentReference reference = parser.parseCommentReference('==', 5); |
| + expectNotNullIfNoErrors(reference); |
| listener.assertNoErrors(); |
| - expect(identifier.name, name); |
| + expect(reference.identifier, new isInstanceOf<SimpleIdentifier>()); |
| + SimpleIdentifier identifier = reference.identifier; |
| + expect(identifier.token, isNotNull); |
| + expect(identifier.name, "=="); |
| + expect(identifier.offset, 5); |
| } |
| - void test_parseListLiteral_empty_oneToken() { |
| - Token token = TokenFactory.tokenFromKeyword(Keyword.CONST); |
| - TypeArgumentList typeArguments = null; |
| - createParser('[]'); |
| - ListLiteral literal = parser.parseListLiteral(token, typeArguments); |
| - expectNotNullIfNoErrors(literal); |
| + void test_parseCommentReference_operator_withoutKeyword_prefixed() { |
| + createParser(''); |
| + CommentReference reference = parser.parseCommentReference('Object.==', 7); |
| + expectNotNullIfNoErrors(reference); |
| listener.assertNoErrors(); |
| - expect(literal.constKeyword, token); |
| - expect(literal.typeArguments, typeArguments); |
| - expect(literal.leftBracket, isNotNull); |
| - expect(literal.elements, hasLength(0)); |
| - expect(literal.rightBracket, isNotNull); |
| + expect(reference.identifier, new isInstanceOf<PrefixedIdentifier>()); |
| + PrefixedIdentifier prefixedIdentifier = reference.identifier; |
| + SimpleIdentifier prefix = prefixedIdentifier.prefix; |
| + expect(prefix.token, isNotNull); |
| + expect(prefix.name, "Object"); |
| + expect(prefix.offset, 7); |
| + expect(prefixedIdentifier.period, isNotNull); |
| + SimpleIdentifier identifier = prefixedIdentifier.identifier; |
| + expect(identifier.token, isNotNull); |
| + expect(identifier.name, "=="); |
| + expect(identifier.offset, 14); |
| } |
| - void test_parseListLiteral_empty_oneToken_withComment() { |
| - Token token = null; |
| - TypeArgumentList typeArguments = null; |
| - createParser('/* 0 */ []'); |
| - ListLiteral literal = parser.parseListLiteral(token, typeArguments); |
| - expectNotNullIfNoErrors(literal); |
| + void test_parseCommentReference_prefixed() { |
| + createParser(''); |
| + CommentReference reference = parser.parseCommentReference('a.b', 7); |
| + expectNotNullIfNoErrors(reference); |
| listener.assertNoErrors(); |
| - expect(literal.constKeyword, token); |
| - expect(literal.typeArguments, typeArguments); |
| - Token leftBracket = literal.leftBracket; |
| - expect(leftBracket, isNotNull); |
| - expect(leftBracket.precedingComments, isNotNull); |
| - expect(literal.elements, hasLength(0)); |
| - expect(literal.rightBracket, isNotNull); |
| + expect(reference.identifier, new isInstanceOf<PrefixedIdentifier>()); |
| + PrefixedIdentifier prefixedIdentifier = reference.identifier; |
| + SimpleIdentifier prefix = prefixedIdentifier.prefix; |
| + expect(prefix.token, isNotNull); |
| + expect(prefix.name, "a"); |
| + expect(prefix.offset, 7); |
| + expect(prefixedIdentifier.period, isNotNull); |
| + SimpleIdentifier identifier = prefixedIdentifier.identifier; |
| + expect(identifier.token, isNotNull); |
| + expect(identifier.name, "b"); |
| + expect(identifier.offset, 9); |
| } |
| - void test_parseListLiteral_empty_twoTokens() { |
| - Token token = TokenFactory.tokenFromKeyword(Keyword.CONST); |
| - TypeArgumentList typeArguments = null; |
| - createParser('[ ]'); |
| - ListLiteral literal = parser.parseListLiteral(token, typeArguments); |
| - expectNotNullIfNoErrors(literal); |
| + void test_parseCommentReference_simple() { |
| + createParser(''); |
| + CommentReference reference = parser.parseCommentReference('a', 5); |
| + expectNotNullIfNoErrors(reference); |
| listener.assertNoErrors(); |
| - expect(literal.constKeyword, token); |
| - expect(literal.typeArguments, typeArguments); |
| - expect(literal.leftBracket, isNotNull); |
| - expect(literal.elements, hasLength(0)); |
| - expect(literal.rightBracket, isNotNull); |
| + expect(reference.identifier, new isInstanceOf<SimpleIdentifier>()); |
| + SimpleIdentifier identifier = reference.identifier; |
| + expect(identifier.token, isNotNull); |
| + expect(identifier.name, "a"); |
| + expect(identifier.offset, 5); |
| } |
| - void test_parseListLiteral_multiple() { |
| - createParser('[1, 2, 3]'); |
| - ListLiteral literal = parser.parseListLiteral(null, null); |
| - expectNotNullIfNoErrors(literal); |
| + void test_parseCommentReference_synthetic() { |
| + createParser(''); |
| + CommentReference reference = parser.parseCommentReference('', 5); |
| + expectNotNullIfNoErrors(reference); |
| listener.assertNoErrors(); |
| - expect(literal.constKeyword, isNull); |
| - expect(literal.typeArguments, isNull); |
| - expect(literal.leftBracket, isNotNull); |
| - expect(literal.elements, hasLength(3)); |
| - expect(literal.rightBracket, isNotNull); |
| + expect(reference.identifier, new isInstanceOf<SimpleIdentifier>()); |
| + SimpleIdentifier identifier = reference.identifier; |
| + expect(identifier, isNotNull); |
| + expect(identifier.isSynthetic, isTrue); |
| + expect(identifier.token, isNotNull); |
| + expect(identifier.name, ""); |
| + expect(identifier.offset, 5); |
| + // Should end with EOF token. |
| + Token nextToken = identifier.token.next; |
| + expect(nextToken, isNotNull); |
| + expect(nextToken.type, TokenType.EOF); |
| } |
| - void test_parseListLiteral_single() { |
| - createParser('[1]'); |
| - ListLiteral literal = parser.parseListLiteral(null, null); |
| - expectNotNullIfNoErrors(literal); |
| + @failingTest |
| + void test_parseCommentReference_this() { |
| + // This fails because we are returning null from the method and asserting |
| + // that the return value is not null. |
| + createParser(''); |
| + CommentReference reference = parser.parseCommentReference('this', 5); |
| + expectNotNullIfNoErrors(reference); |
| listener.assertNoErrors(); |
| - expect(literal.constKeyword, isNull); |
| - expect(literal.typeArguments, isNull); |
| - expect(literal.leftBracket, isNotNull); |
| - expect(literal.elements, hasLength(1)); |
| - expect(literal.rightBracket, isNotNull); |
| + SimpleIdentifier identifier = EngineTestCase.assertInstanceOf( |
| + (obj) => obj is SimpleIdentifier, |
| + SimpleIdentifier, |
| + reference.identifier); |
| + expect(identifier.token, isNotNull); |
| + expect(identifier.name, "a"); |
| + expect(identifier.offset, 5); |
| } |
| - void test_parseListOrMapLiteral_list_noType() { |
| - createParser('[1]'); |
| - TypedLiteral literal = parser.parseListOrMapLiteral(null); |
| - expectNotNullIfNoErrors(literal); |
| + void test_parseCommentReferences_multiLine() { |
| + DocumentationCommentToken token = new DocumentationCommentToken( |
| + TokenType.MULTI_LINE_COMMENT, "/** xxx [a] yyy [bb] zzz */", 3); |
| + List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[token]; |
| + createParser(''); |
| + List<CommentReference> references = parser.parseCommentReferences(tokens); |
| + expectNotNullIfNoErrors(references); |
| listener.assertNoErrors(); |
| - expect(literal, new isInstanceOf<ListLiteral>()); |
| - ListLiteral listLiteral = literal; |
| - expect(listLiteral.constKeyword, isNull); |
| - expect(listLiteral.typeArguments, isNull); |
| - expect(listLiteral.leftBracket, isNotNull); |
| - expect(listLiteral.elements, hasLength(1)); |
| - expect(listLiteral.rightBracket, isNotNull); |
| + List<Token> tokenReferences = token.references; |
| + expect(references, hasLength(2)); |
| + expect(tokenReferences, hasLength(2)); |
| + { |
| + CommentReference reference = references[0]; |
| + expect(reference, isNotNull); |
| + expect(reference.identifier, isNotNull); |
| + expect(reference.offset, 12); |
| + // the reference is recorded in the comment token |
| + Token referenceToken = tokenReferences[0]; |
| + expect(referenceToken.offset, 12); |
| + expect(referenceToken.lexeme, 'a'); |
| + } |
| + { |
| + CommentReference reference = references[1]; |
| + expect(reference, isNotNull); |
| + expect(reference.identifier, isNotNull); |
| + expect(reference.offset, 20); |
| + // the reference is recorded in the comment token |
| + Token referenceToken = tokenReferences[1]; |
| + expect(referenceToken.offset, 20); |
| + expect(referenceToken.lexeme, 'bb'); |
| + } |
| } |
| - void test_parseListOrMapLiteral_list_type() { |
| - createParser('<int> [1]'); |
| - TypedLiteral literal = parser.parseListOrMapLiteral(null); |
| - expectNotNullIfNoErrors(literal); |
| + void test_parseCommentReferences_notClosed_noIdentifier() { |
| + DocumentationCommentToken docToken = new DocumentationCommentToken( |
| + TokenType.MULTI_LINE_COMMENT, "/** [ some text", 5); |
| + createParser(''); |
| + List<CommentReference> references = |
| + parser.parseCommentReferences(<DocumentationCommentToken>[docToken]); |
| + expectNotNullIfNoErrors(references); |
| listener.assertNoErrors(); |
| - expect(literal, new isInstanceOf<ListLiteral>()); |
| - ListLiteral listLiteral = literal; |
| - expect(listLiteral.constKeyword, isNull); |
| - expect(listLiteral.typeArguments, isNotNull); |
| - expect(listLiteral.leftBracket, isNotNull); |
| - expect(listLiteral.elements, hasLength(1)); |
| - expect(listLiteral.rightBracket, isNotNull); |
| + expect(docToken.references, hasLength(1)); |
| + expect(references, hasLength(1)); |
| + Token referenceToken = docToken.references[0]; |
| + CommentReference reference = references[0]; |
| + expect(reference, isNotNull); |
| + expect(docToken.references[0], same(reference.beginToken)); |
| + expect(reference.identifier, isNotNull); |
| + expect(reference.identifier.isSynthetic, isTrue); |
| + expect(reference.identifier.name, ""); |
| + // Should end with EOF token. |
| + Token nextToken = referenceToken.next; |
| + expect(nextToken, isNotNull); |
| + expect(nextToken.type, TokenType.EOF); |
| } |
| - void test_parseListOrMapLiteral_map_noType() { |
| - createParser("{'1' : 1}"); |
| - TypedLiteral literal = parser.parseListOrMapLiteral(null); |
| - expectNotNullIfNoErrors(literal); |
| + void test_parseCommentReferences_notClosed_withIdentifier() { |
| + DocumentationCommentToken docToken = new DocumentationCommentToken( |
| + TokenType.MULTI_LINE_COMMENT, "/** [namePrefix some text", 5); |
| + createParser(''); |
| + List<CommentReference> references = |
| + parser.parseCommentReferences(<DocumentationCommentToken>[docToken]); |
| + expectNotNullIfNoErrors(references); |
| listener.assertNoErrors(); |
| - expect(literal, new isInstanceOf<MapLiteral>()); |
| - MapLiteral mapLiteral = literal; |
| - expect(mapLiteral.constKeyword, isNull); |
| - expect(mapLiteral.typeArguments, isNull); |
| - expect(mapLiteral.leftBracket, isNotNull); |
| - expect(mapLiteral.entries, hasLength(1)); |
| - expect(mapLiteral.rightBracket, isNotNull); |
| + expect(docToken.references, hasLength(1)); |
| + expect(references, hasLength(1)); |
| + Token referenceToken = docToken.references[0]; |
| + CommentReference reference = references[0]; |
| + expect(reference, isNotNull); |
| + expect(referenceToken, same(reference.beginToken)); |
| + expect(reference.identifier, isNotNull); |
| + expect(reference.identifier.isSynthetic, isFalse); |
| + expect(reference.identifier.name, "namePrefix"); |
| + // Should end with EOF token. |
| + Token nextToken = referenceToken.next; |
| + expect(nextToken, isNotNull); |
| + expect(nextToken.type, TokenType.EOF); |
| } |
| - void test_parseListOrMapLiteral_map_type() { |
| - createParser("<String, int> {'1' : 1}"); |
| - TypedLiteral literal = parser.parseListOrMapLiteral(null); |
| - expectNotNullIfNoErrors(literal); |
| + void test_parseCommentReferences_singleLine() { |
| + List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ |
| + new DocumentationCommentToken( |
| + TokenType.SINGLE_LINE_COMMENT, "/// xxx [a] yyy [b] zzz", 3), |
| + new DocumentationCommentToken( |
| + TokenType.SINGLE_LINE_COMMENT, "/// x [c]", 28) |
| + ]; |
| + createParser(''); |
| + List<CommentReference> references = parser.parseCommentReferences(tokens); |
| + expectNotNullIfNoErrors(references); |
| listener.assertNoErrors(); |
| - expect(literal, new isInstanceOf<MapLiteral>()); |
| - MapLiteral mapLiteral = literal; |
| - expect(mapLiteral.constKeyword, isNull); |
| - expect(mapLiteral.typeArguments, isNotNull); |
| - expect(mapLiteral.leftBracket, isNotNull); |
| - expect(mapLiteral.entries, hasLength(1)); |
| - expect(mapLiteral.rightBracket, isNotNull); |
| + expect(references, hasLength(3)); |
| + CommentReference reference = references[0]; |
| + expect(reference, isNotNull); |
| + expect(reference.identifier, isNotNull); |
| + expect(reference.offset, 12); |
| + reference = references[1]; |
| + expect(reference, isNotNull); |
| + expect(reference.identifier, isNotNull); |
| + expect(reference.offset, 20); |
| + reference = references[2]; |
| + expect(reference, isNotNull); |
| + expect(reference.identifier, isNotNull); |
| + expect(reference.offset, 35); |
| } |
| - void test_parseLogicalAndExpression() { |
| - createParser('x && y'); |
| - Expression expression = parser.parseLogicalAndExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseCommentReferences_skipCodeBlock_4spaces_block() { |
| + List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ |
| + new DocumentationCommentToken(TokenType.MULTI_LINE_COMMENT, |
| + "/**\n * a[i]\n * non-code line\n */", 3) |
| + ]; |
| + createParser(''); |
| + List<CommentReference> references = parser.parseCommentReferences(tokens); |
| + expectNotNullIfNoErrors(references); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<BinaryExpression>()); |
| - BinaryExpression binaryExpression = expression; |
| - expect(binaryExpression.leftOperand, isNotNull); |
| - expect(binaryExpression.operator, isNotNull); |
| - expect(binaryExpression.operator.type, TokenType.AMPERSAND_AMPERSAND); |
| - expect(binaryExpression.rightOperand, isNotNull); |
| + expect(references, isEmpty); |
| } |
| - void test_parseLogicalOrExpression() { |
| - createParser('x || y'); |
| - Expression expression = parser.parseLogicalOrExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseCommentReferences_skipCodeBlock_4spaces_lines() { |
| + List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ |
| + new DocumentationCommentToken( |
| + TokenType.SINGLE_LINE_COMMENT, "/// Code block:", 0), |
| + new DocumentationCommentToken( |
| + TokenType.SINGLE_LINE_COMMENT, "/// a[i] == b[i]", 0) |
| + ]; |
| + createParser(''); |
| + List<CommentReference> references = parser.parseCommentReferences(tokens); |
| + expectNotNullIfNoErrors(references); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<BinaryExpression>()); |
| - BinaryExpression binaryExpression = expression; |
| - expect(binaryExpression.leftOperand, isNotNull); |
| - expect(binaryExpression.operator, isNotNull); |
| - expect(binaryExpression.operator.type, TokenType.BAR_BAR); |
| - expect(binaryExpression.rightOperand, isNotNull); |
| + expect(references, isEmpty); |
| } |
| - void test_parseMapLiteral_empty() { |
| - Token token = TokenFactory.tokenFromKeyword(Keyword.CONST); |
| - TypeArgumentList typeArguments = AstTestFactory.typeArgumentList( |
| - [AstTestFactory.typeName4("String"), AstTestFactory.typeName4("int")]); |
| - createParser('{}'); |
| - MapLiteral literal = parser.parseMapLiteral(token, typeArguments); |
| - expectNotNullIfNoErrors(literal); |
| + void test_parseCommentReferences_skipCodeBlock_bracketed() { |
| + List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ |
| + new DocumentationCommentToken( |
| + TokenType.MULTI_LINE_COMMENT, "/** [:xxx [a] yyy:] [b] zzz */", 3) |
| + ]; |
| + createParser(''); |
| + List<CommentReference> references = parser.parseCommentReferences(tokens); |
| + expectNotNullIfNoErrors(references); |
| listener.assertNoErrors(); |
| - expect(literal.constKeyword, token); |
| - expect(literal.typeArguments, typeArguments); |
| - expect(literal.leftBracket, isNotNull); |
| - expect(literal.entries, hasLength(0)); |
| - expect(literal.rightBracket, isNotNull); |
| + expect(references, hasLength(1)); |
| + CommentReference reference = references[0]; |
| + expect(reference, isNotNull); |
| + expect(reference.identifier, isNotNull); |
| + expect(reference.offset, 24); |
| } |
| - void test_parseMapLiteral_multiple() { |
| - createParser("{'a' : b, 'x' : y}"); |
| - MapLiteral literal = parser.parseMapLiteral(null, null); |
| - expectNotNullIfNoErrors(literal); |
| + void test_parseCommentReferences_skipCodeBlock_gitHub() { |
| + List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ |
| + new DocumentationCommentToken( |
| + TokenType.MULTI_LINE_COMMENT, "/** `a[i]` and [b] */", 0) |
| + ]; |
| + createParser(''); |
| + List<CommentReference> references = parser.parseCommentReferences(tokens); |
| + expectNotNullIfNoErrors(references); |
| listener.assertNoErrors(); |
| - expect(literal.leftBracket, isNotNull); |
| - expect(literal.entries, hasLength(2)); |
| - expect(literal.rightBracket, isNotNull); |
| + expect(references, hasLength(1)); |
| + CommentReference reference = references[0]; |
| + expect(reference, isNotNull); |
| + expect(reference.identifier, isNotNull); |
| + expect(reference.offset, 16); |
| } |
| - void test_parseMapLiteral_single() { |
| - createParser("{'x' : y}"); |
| - MapLiteral literal = parser.parseMapLiteral(null, null); |
| - expectNotNullIfNoErrors(literal); |
| + void test_parseCommentReferences_skipCodeBlock_gitHub_multiLine() { |
| + List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ |
| + new DocumentationCommentToken( |
| + TokenType.MULTI_LINE_COMMENT, |
| + r''' |
| +/** |
| + * First. |
| + * ```dart |
| + * Some [int] reference. |
| + * ``` |
| + * Last. |
| + */ |
| +''', |
| + 3) |
| + ]; |
| + createParser(''); |
| + List<CommentReference> references = parser.parseCommentReferences(tokens); |
| + expectNotNullIfNoErrors(references); |
| listener.assertNoErrors(); |
| - expect(literal.leftBracket, isNotNull); |
| - expect(literal.entries, hasLength(1)); |
| - expect(literal.rightBracket, isNotNull); |
| + expect(references, isEmpty); |
| } |
| - void test_parseMapLiteralEntry_complex() { |
| - createParser('2 + 2 : y'); |
| - MapLiteralEntry entry = parser.parseMapLiteralEntry(); |
| - expectNotNullIfNoErrors(entry); |
| + void test_parseCommentReferences_skipCodeBlock_gitHub_multiLine_lines() { |
| + String commentText = r''' |
| +/// First. |
| +/// ```dart |
| +/// Some [int] reference. |
| +/// ``` |
| +/// Last. |
| +'''; |
| + List<DocumentationCommentToken> tokens = commentText |
| + .split('\n') |
| + .map((line) => new DocumentationCommentToken( |
| + TokenType.SINGLE_LINE_COMMENT, line, 0)) |
| + .toList(); |
| + createParser(''); |
| + List<CommentReference> references = parser.parseCommentReferences(tokens); |
| + expectNotNullIfNoErrors(references); |
| listener.assertNoErrors(); |
| - expect(entry.key, isNotNull); |
| - expect(entry.separator, isNotNull); |
| - expect(entry.value, isNotNull); |
| + expect(references, isEmpty); |
| } |
| - void test_parseMapLiteralEntry_int() { |
| - createParser('0 : y'); |
| - MapLiteralEntry entry = parser.parseMapLiteralEntry(); |
| - expectNotNullIfNoErrors(entry); |
| + void test_parseCommentReferences_skipCodeBlock_gitHub_notTerminated() { |
| + List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ |
| + new DocumentationCommentToken( |
| + TokenType.MULTI_LINE_COMMENT, "/** `a[i] and [b] */", 0) |
| + ]; |
| + createParser(''); |
| + List<CommentReference> references = parser.parseCommentReferences(tokens); |
| + expectNotNullIfNoErrors(references); |
| listener.assertNoErrors(); |
| - expect(entry.key, isNotNull); |
| - expect(entry.separator, isNotNull); |
| - expect(entry.value, isNotNull); |
| + expect(references, hasLength(2)); |
| } |
| - void test_parseMapLiteralEntry_string() { |
| - createParser("'x' : y"); |
| - MapLiteralEntry entry = parser.parseMapLiteralEntry(); |
| - expectNotNullIfNoErrors(entry); |
| + void test_parseCommentReferences_skipCodeBlock_spaces() { |
| + List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ |
| + new DocumentationCommentToken(TokenType.MULTI_LINE_COMMENT, |
| + "/**\n * a[i]\n * xxx [i] zzz\n */", 3) |
| + ]; |
| + createParser(''); |
| + List<CommentReference> references = parser.parseCommentReferences(tokens); |
| + expectNotNullIfNoErrors(references); |
| listener.assertNoErrors(); |
| - expect(entry.key, isNotNull); |
| - expect(entry.separator, isNotNull); |
| - expect(entry.value, isNotNull); |
| + expect(references, hasLength(1)); |
| + CommentReference reference = references[0]; |
| + expect(reference, isNotNull); |
| + expect(reference.identifier, isNotNull); |
| + expect(reference.offset, 27); |
| } |
| - void test_parseModifiers_abstract() { |
| - createParser('abstract A'); |
| - Modifiers modifiers = parser.parseModifiers(); |
| - expectNotNullIfNoErrors(modifiers); |
| + void test_parseCommentReferences_skipLinkDefinition() { |
| + List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ |
| + new DocumentationCommentToken(TokenType.MULTI_LINE_COMMENT, |
| + "/** [a]: http://www.google.com (Google) [b] zzz */", 3) |
| + ]; |
| + createParser(''); |
| + List<CommentReference> references = parser.parseCommentReferences(tokens); |
| + expectNotNullIfNoErrors(references); |
| listener.assertNoErrors(); |
| - expect(modifiers.abstractKeyword, isNotNull); |
| + expect(references, hasLength(1)); |
| + CommentReference reference = references[0]; |
| + expect(reference, isNotNull); |
| + expect(reference.identifier, isNotNull); |
| + expect(reference.offset, 44); |
| } |
| - void test_parseModifiers_const() { |
| - createParser('const A'); |
| - Modifiers modifiers = parser.parseModifiers(); |
| - expectNotNullIfNoErrors(modifiers); |
| + void test_parseCommentReferences_skipLinked() { |
| + List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ |
| + new DocumentationCommentToken(TokenType.MULTI_LINE_COMMENT, |
| + "/** [a](http://www.google.com) [b] zzz */", 3) |
| + ]; |
| + createParser(''); |
| + List<CommentReference> references = parser.parseCommentReferences(tokens); |
| + expectNotNullIfNoErrors(references); |
| listener.assertNoErrors(); |
| - expect(modifiers.constKeyword, isNotNull); |
| + expect(references, hasLength(1)); |
| + CommentReference reference = references[0]; |
| + expect(reference, isNotNull); |
| + expect(reference.identifier, isNotNull); |
| + expect(reference.offset, 35); |
| } |
| - void test_parseModifiers_covariant() { |
| - createParser('covariant A'); |
| - Modifiers modifiers = parser.parseModifiers(); |
| - expectNotNullIfNoErrors(modifiers); |
| + void test_parseCommentReferences_skipReferenceLink() { |
| + List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ |
| + new DocumentationCommentToken( |
| + TokenType.MULTI_LINE_COMMENT, "/** [a][c] [b] zzz */", 3) |
| + ]; |
| + createParser(''); |
| + List<CommentReference> references = parser.parseCommentReferences(tokens); |
| + expectNotNullIfNoErrors(references); |
| listener.assertNoErrors(); |
| - expect(modifiers.covariantKeyword, isNotNull); |
| + expect(references, hasLength(1)); |
| + CommentReference reference = references[0]; |
| + expect(reference, isNotNull); |
| + expect(reference.identifier, isNotNull); |
| + expect(reference.offset, 15); |
| } |
| - void test_parseModifiers_external() { |
| - createParser('external A'); |
| - Modifiers modifiers = parser.parseModifiers(); |
| - expectNotNullIfNoErrors(modifiers); |
| + void test_parseConfiguration_noOperator_dottedIdentifier() { |
| + createParser("if (a.b) 'c.dart'"); |
| + Configuration configuration = parser.parseConfiguration(); |
| + expectNotNullIfNoErrors(configuration); |
| listener.assertNoErrors(); |
| - expect(modifiers.externalKeyword, isNotNull); |
| + expect(configuration.ifKeyword, isNotNull); |
| + expect(configuration.leftParenthesis, isNotNull); |
| + expectDottedName(configuration.name, ["a", "b"]); |
| + expect(configuration.equalToken, isNull); |
| + expect(configuration.value, isNull); |
| + expect(configuration.rightParenthesis, isNotNull); |
| + expect(configuration.uri, isNotNull); |
| } |
| - void test_parseModifiers_factory() { |
| - createParser('factory A'); |
| - Modifiers modifiers = parser.parseModifiers(); |
| - expectNotNullIfNoErrors(modifiers); |
| + void test_parseConfiguration_noOperator_simpleIdentifier() { |
| + createParser("if (a) 'b.dart'"); |
| + Configuration configuration = parser.parseConfiguration(); |
| + expectNotNullIfNoErrors(configuration); |
| listener.assertNoErrors(); |
| - expect(modifiers.factoryKeyword, isNotNull); |
| + expect(configuration.ifKeyword, isNotNull); |
| + expect(configuration.leftParenthesis, isNotNull); |
| + expectDottedName(configuration.name, ["a"]); |
| + expect(configuration.equalToken, isNull); |
| + expect(configuration.value, isNull); |
| + expect(configuration.rightParenthesis, isNotNull); |
| + expect(configuration.uri, isNotNull); |
| } |
| - void test_parseModifiers_final() { |
| - createParser('final A'); |
| - Modifiers modifiers = parser.parseModifiers(); |
| - expectNotNullIfNoErrors(modifiers); |
| + void test_parseConfiguration_operator_dottedIdentifier() { |
| + createParser("if (a.b == 'c') 'd.dart'"); |
| + Configuration configuration = parser.parseConfiguration(); |
| + expectNotNullIfNoErrors(configuration); |
| listener.assertNoErrors(); |
| - expect(modifiers.finalKeyword, isNotNull); |
| + expect(configuration.ifKeyword, isNotNull); |
| + expect(configuration.leftParenthesis, isNotNull); |
| + expectDottedName(configuration.name, ["a", "b"]); |
| + expect(configuration.equalToken, isNotNull); |
| + expect(configuration.value, isNotNull); |
| + expect(configuration.rightParenthesis, isNotNull); |
| + expect(configuration.uri, isNotNull); |
| } |
| - void test_parseModifiers_static() { |
| - createParser('static A'); |
| - Modifiers modifiers = parser.parseModifiers(); |
| - expectNotNullIfNoErrors(modifiers); |
| + void test_parseConfiguration_operator_simpleIdentifier() { |
| + createParser("if (a == 'b') 'c.dart'"); |
| + Configuration configuration = parser.parseConfiguration(); |
| + expectNotNullIfNoErrors(configuration); |
| listener.assertNoErrors(); |
| - expect(modifiers.staticKeyword, isNotNull); |
| + expect(configuration.ifKeyword, isNotNull); |
| + expect(configuration.leftParenthesis, isNotNull); |
| + expectDottedName(configuration.name, ["a"]); |
| + expect(configuration.equalToken, isNotNull); |
| + expect(configuration.value, isNotNull); |
| + expect(configuration.rightParenthesis, isNotNull); |
| + expect(configuration.uri, isNotNull); |
| } |
| - void test_parseModifiers_var() { |
| - createParser('var A'); |
| - Modifiers modifiers = parser.parseModifiers(); |
| - expectNotNullIfNoErrors(modifiers); |
| - listener.assertNoErrors(); |
| - expect(modifiers.varKeyword, isNotNull); |
| + void test_parseConstructor() { |
| + // TODO(brianwilkerson) Implement tests for this method. |
| } |
| - void test_parseMultiplicativeExpression_normal() { |
| - createParser('x * y'); |
| - Expression expression = parser.parseMultiplicativeExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseConstructorName_named_noPrefix() { |
| + createParser('A.n;'); |
| + ConstructorName name = parser.parseConstructorName(); |
| + expectNotNullIfNoErrors(name); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<BinaryExpression>()); |
| - BinaryExpression binaryExpression = expression; |
| - expect(binaryExpression.leftOperand, isNotNull); |
| - expect(binaryExpression.operator, isNotNull); |
| - expect(binaryExpression.operator.type, TokenType.STAR); |
| - expect(binaryExpression.rightOperand, isNotNull); |
| + expect(name.type, isNotNull); |
| + expect(name.period, isNull); |
| + expect(name.name, isNull); |
| } |
| - void test_parseMultiplicativeExpression_super() { |
| - createParser('super * y'); |
| - Expression expression = parser.parseMultiplicativeExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseConstructorName_named_prefixed() { |
| + createParser('p.A.n;'); |
| + ConstructorName name = parser.parseConstructorName(); |
| + expectNotNullIfNoErrors(name); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<BinaryExpression>()); |
| - BinaryExpression binaryExpression = expression; |
| - expect(binaryExpression.leftOperand, new isInstanceOf<SuperExpression>()); |
| - expect(binaryExpression.operator, isNotNull); |
| - expect(binaryExpression.operator.type, TokenType.STAR); |
| - expect(binaryExpression.rightOperand, isNotNull); |
| + expect(name.type, isNotNull); |
| + expect(name.period, isNotNull); |
| + expect(name.name, isNotNull); |
| } |
| - void test_parseNewExpression() { |
| - createParser('new A()'); |
| - InstanceCreationExpression expression = parser.parseNewExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseConstructorName_unnamed_noPrefix() { |
| + createParser('A;'); |
| + ConstructorName name = parser.parseConstructorName(); |
| + expectNotNullIfNoErrors(name); |
| listener.assertNoErrors(); |
| - expect(expression.keyword, isNotNull); |
| - ConstructorName name = expression.constructorName; |
| - expect(name, isNotNull); |
| expect(name.type, isNotNull); |
| expect(name.period, isNull); |
| expect(name.name, isNull); |
| - expect(expression.argumentList, isNotNull); |
| } |
| - void test_parseNonLabeledStatement_const_list_empty() { |
| - createParser('const [];'); |
| - Statement statement = parser.parseNonLabeledStatement(); |
| - expectNotNullIfNoErrors(statement); |
| + void test_parseConstructorName_unnamed_prefixed() { |
| + createParser('p.A;'); |
| + ConstructorName name = parser.parseConstructorName(); |
| + expectNotNullIfNoErrors(name); |
| listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<ExpressionStatement>()); |
| - ExpressionStatement expressionStatement = statement; |
| - expect(expressionStatement.expression, isNotNull); |
| + expect(name.type, isNotNull); |
| + expect(name.period, isNull); |
| + expect(name.name, isNull); |
| } |
| - void test_parseNonLabeledStatement_const_list_nonEmpty() { |
| - createParser('const [1, 2];'); |
| - Statement statement = parser.parseNonLabeledStatement(); |
| + void test_parseContinueStatement_label() { |
| + createParser('continue foo;'); |
| + ContinueStatement statement = parser.parseContinueStatement(); |
| expectNotNullIfNoErrors(statement); |
| - listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<ExpressionStatement>()); |
| - ExpressionStatement expressionStatement = statement; |
| - expect(expressionStatement.expression, isNotNull); |
| + listener.assertErrorsWithCodes([ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP]); |
| + expect(statement.continueKeyword, isNotNull); |
| + expect(statement.label, isNotNull); |
| + expect(statement.semicolon, isNotNull); |
| } |
| - void test_parseNonLabeledStatement_const_map_empty() { |
| - createParser('const {};'); |
| - Statement statement = parser.parseNonLabeledStatement(); |
| + void test_parseContinueStatement_noLabel() { |
| + createParser('continue;'); |
| + ContinueStatement statement = parser.parseContinueStatement(); |
| expectNotNullIfNoErrors(statement); |
| - listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<ExpressionStatement>()); |
| - ExpressionStatement expressionStatement = statement; |
| - expect(expressionStatement.expression, isNotNull); |
| + listener.assertErrorsWithCodes([ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP]); |
| + expect(statement.continueKeyword, isNotNull); |
| + expect(statement.label, isNull); |
| + expect(statement.semicolon, isNotNull); |
| } |
| - void test_parseNonLabeledStatement_const_map_nonEmpty() { |
| - // TODO(brianwilkerson) Implement more tests for this method. |
| - createParser("const {'a' : 1};"); |
| - Statement statement = parser.parseNonLabeledStatement(); |
| - expectNotNullIfNoErrors(statement); |
| + void test_parseDocumentationComment_block() { |
| + createParser('/** */ class'); |
| + Comment comment = parser |
| + .parseDocumentationComment(parser.parseDocumentationCommentTokens()); |
| + expectNotNullIfNoErrors(comment); |
| listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<ExpressionStatement>()); |
| - ExpressionStatement expressionStatement = statement; |
| - expect(expressionStatement.expression, isNotNull); |
| + expect(comment.isBlock, isFalse); |
| + expect(comment.isDocumentation, isTrue); |
| + expect(comment.isEndOfLine, isFalse); |
| } |
| - void test_parseNonLabeledStatement_const_object() { |
| - createParser('const A();'); |
| - Statement statement = parser.parseNonLabeledStatement(); |
| - expectNotNullIfNoErrors(statement); |
| + void test_parseDocumentationComment_block_withReference() { |
| + createParser('/** [a] */ class'); |
| + Comment comment = parser |
| + .parseDocumentationComment(parser.parseDocumentationCommentTokens()); |
| + expectNotNullIfNoErrors(comment); |
| listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<ExpressionStatement>()); |
| - ExpressionStatement expressionStatement = statement; |
| - expect(expressionStatement.expression, isNotNull); |
| + expect(comment.isBlock, isFalse); |
| + expect(comment.isDocumentation, isTrue); |
| + expect(comment.isEndOfLine, isFalse); |
| + NodeList<CommentReference> references = comment.references; |
| + expect(references, hasLength(1)); |
| + CommentReference reference = references[0]; |
| + expect(reference, isNotNull); |
| + expect(reference.offset, 5); |
| } |
| - void test_parseNonLabeledStatement_const_object_named_typeParameters() { |
| - createParser('const A<B>.c();'); |
| - Statement statement = parser.parseNonLabeledStatement(); |
| - expectNotNullIfNoErrors(statement); |
| + void test_parseDocumentationComment_endOfLine() { |
| + createParser('/// \n/// \n class'); |
| + Comment comment = parser |
| + .parseDocumentationComment(parser.parseDocumentationCommentTokens()); |
| + expectNotNullIfNoErrors(comment); |
| listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<ExpressionStatement>()); |
| - ExpressionStatement expressionStatement = statement; |
| - expect(expressionStatement.expression, isNotNull); |
| + expect(comment.isBlock, isFalse); |
| + expect(comment.isDocumentation, isTrue); |
| + expect(comment.isEndOfLine, isFalse); |
| } |
| - void test_parseNonLabeledStatement_constructorInvocation() { |
| - createParser('new C().m();'); |
| - Statement statement = parser.parseNonLabeledStatement(); |
| + void test_parseDoStatement() { |
| + createParser('do {} while (x);'); |
| + DoStatement statement = parser.parseDoStatement(); |
| expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<ExpressionStatement>()); |
| - ExpressionStatement expressionStatement = statement; |
| - expect(expressionStatement.expression, isNotNull); |
| + expect(statement.doKeyword, isNotNull); |
| + expect(statement.body, isNotNull); |
| + expect(statement.whileKeyword, isNotNull); |
| + expect(statement.leftParenthesis, isNotNull); |
| + expect(statement.condition, isNotNull); |
| + expect(statement.rightParenthesis, isNotNull); |
| + expect(statement.semicolon, isNotNull); |
| } |
| - void test_parseNonLabeledStatement_false() { |
| - createParser('false;'); |
| - Statement statement = parser.parseNonLabeledStatement(); |
| - expectNotNullIfNoErrors(statement); |
| + void test_parseDottedName_multiple() { |
| + createParser('a.b.c'); |
| + DottedName name = parser.parseDottedName(); |
| + expectNotNullIfNoErrors(name); |
| listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<ExpressionStatement>()); |
| - ExpressionStatement expressionStatement = statement; |
| - expect(expressionStatement.expression, isNotNull); |
| + expectDottedName(name, ["a", "b", "c"]); |
| } |
| - void test_parseNonLabeledStatement_functionDeclaration() { |
| - createParser('f() {};'); |
| - Statement statement = parser.parseNonLabeledStatement(); |
| - expectNotNullIfNoErrors(statement); |
| + void test_parseDottedName_single() { |
| + createParser('a'); |
| + DottedName name = parser.parseDottedName(); |
| + expectNotNullIfNoErrors(name); |
| listener.assertNoErrors(); |
| + expectDottedName(name, ["a"]); |
| } |
| - void test_parseNonLabeledStatement_functionDeclaration_arguments() { |
| - createParser('f(void g()) {};'); |
| - Statement statement = parser.parseNonLabeledStatement(); |
| + void test_parseEmptyStatement() { |
| + createParser(';'); |
| + EmptyStatement statement = parser.parseEmptyStatement(); |
| expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| + expect(statement.semicolon, isNotNull); |
| } |
| - void test_parseNonLabeledStatement_functionExpressionIndex() { |
| - createParser('() {}[0] = null;'); |
| - Statement statement = parser.parseNonLabeledStatement(); |
| - expectNotNullIfNoErrors(statement); |
| + void test_parseExtendsClause() { |
| + createParser('extends B'); |
| + ExtendsClause clause = parser.parseExtendsClause(); |
| + expectNotNullIfNoErrors(clause); |
| listener.assertNoErrors(); |
| + expect(clause.extendsKeyword, isNotNull); |
| + expect(clause.superclass, isNotNull); |
| + expect(clause.superclass, new isInstanceOf<TypeName>()); |
| } |
| - void test_parseNonLabeledStatement_functionInvocation() { |
| - createParser('f();'); |
| - Statement statement = parser.parseNonLabeledStatement(); |
| - expectNotNullIfNoErrors(statement); |
| - listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<ExpressionStatement>()); |
| - ExpressionStatement expressionStatement = statement; |
| - expect(expressionStatement.expression, isNotNull); |
| + void test_parseFinalConstVarOrType_const_functionType() { |
| + createParser('const int Function(int) f'); |
| + FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| + expectNotNullIfNoErrors(result); |
| + listener.assertNoErrors(); |
| + Token keyword = result.keyword; |
| + expect(keyword, isNotNull); |
| + expect(keyword.type, TokenType.KEYWORD); |
| + expect(keyword.keyword, Keyword.CONST); |
| + expect(result.type, isNotNull); |
| } |
| - void test_parseNonLabeledStatement_invokeFunctionExpression() { |
| - createParser('(a) {return a + a;} (3);'); |
| - Statement statement = parser.parseNonLabeledStatement(); |
| - expectNotNullIfNoErrors(statement); |
| + void test_parseFinalConstVarOrType_const_namedType() { |
| + createParser('const A a'); |
| + FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| + expectNotNullIfNoErrors(result); |
| listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<ExpressionStatement>()); |
| - ExpressionStatement expressionStatement = statement; |
| - EngineTestCase.assertInstanceOf( |
| - (obj) => obj is FunctionExpressionInvocation, |
| - FunctionExpressionInvocation, |
| - expressionStatement.expression); |
| - FunctionExpressionInvocation invocation = |
| - expressionStatement.expression as FunctionExpressionInvocation; |
| - EngineTestCase.assertInstanceOf((obj) => obj is FunctionExpression, |
| - FunctionExpression, invocation.function); |
| - FunctionExpression expression = invocation.function as FunctionExpression; |
| - expect(expression.parameters, isNotNull); |
| - expect(expression.body, isNotNull); |
| - expect(invocation.typeArguments, isNull); |
| - ArgumentList list = invocation.argumentList; |
| - expect(list, isNotNull); |
| - expect(list.arguments, hasLength(1)); |
| + Token keyword = result.keyword; |
| + expect(keyword, isNotNull); |
| + expect(keyword.type, TokenType.KEYWORD); |
| + expect(keyword.keyword, Keyword.CONST); |
| + expect(result.type, isNotNull); |
| } |
| - void test_parseNonLabeledStatement_null() { |
| - createParser('null;'); |
| - Statement statement = parser.parseNonLabeledStatement(); |
| - expectNotNullIfNoErrors(statement); |
| + void test_parseFinalConstVarOrType_const_noType() { |
| + createParser('const'); |
| + FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| + expectNotNullIfNoErrors(result); |
| listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<ExpressionStatement>()); |
| - ExpressionStatement expressionStatement = statement; |
| - expect(expressionStatement.expression, isNotNull); |
| + Token keyword = result.keyword; |
| + expect(keyword, isNotNull); |
| + expect(keyword.type, TokenType.KEYWORD); |
| + expect(keyword.keyword, Keyword.CONST); |
| + expect(result.type, isNull); |
| } |
| - void test_parseNonLabeledStatement_startingWithBuiltInIdentifier() { |
| - createParser('library.getName();'); |
| - Statement statement = parser.parseNonLabeledStatement(); |
| - expectNotNullIfNoErrors(statement); |
| + void test_parseFinalConstVarOrType_final_functionType() { |
| + createParser('final int Function(int) f'); |
| + FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| + expectNotNullIfNoErrors(result); |
| listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<ExpressionStatement>()); |
| - ExpressionStatement expressionStatement = statement; |
| - expect(expressionStatement.expression, isNotNull); |
| + Token keyword = result.keyword; |
| + expect(keyword, isNotNull); |
| + expect(keyword.type, TokenType.KEYWORD); |
| + expect(keyword.keyword, Keyword.FINAL); |
| + expect(result.type, isNotNull); |
| } |
| - void test_parseNonLabeledStatement_true() { |
| - createParser('true;'); |
| - Statement statement = parser.parseNonLabeledStatement(); |
| - expectNotNullIfNoErrors(statement); |
| + void test_parseFinalConstVarOrType_final_namedType() { |
| + createParser('final A a'); |
| + FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| + expectNotNullIfNoErrors(result); |
| listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<ExpressionStatement>()); |
| - ExpressionStatement expressionStatement = statement; |
| - expect(expressionStatement.expression, isNotNull); |
| + Token keyword = result.keyword; |
| + expect(keyword, isNotNull); |
| + expect(keyword.type, TokenType.KEYWORD); |
| + expect(keyword.keyword, Keyword.FINAL); |
| + expect(result.type, isNotNull); |
| } |
| - void test_parseNonLabeledStatement_typeCast() { |
| - createParser('double.NAN as num;'); |
| - Statement statement = parser.parseNonLabeledStatement(); |
| - expectNotNullIfNoErrors(statement); |
| + void test_parseFinalConstVarOrType_final_noType() { |
| + createParser('final'); |
| + FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| + expectNotNullIfNoErrors(result); |
| listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<ExpressionStatement>()); |
| - ExpressionStatement expressionStatement = statement; |
| - expect(expressionStatement.expression, isNotNull); |
| + Token keyword = result.keyword; |
| + expect(keyword, isNotNull); |
| + expect(keyword.type, TokenType.KEYWORD); |
| + expect(keyword.keyword, Keyword.FINAL); |
| + expect(result.type, isNull); |
| } |
| - void test_parseNonLabeledStatement_variableDeclaration_final_namedFunction() { |
| - createParser('final int Function = 0;'); |
| - Statement statement = parser.parseNonLabeledStatement(); |
| - expectNotNullIfNoErrors(statement); |
| + void test_parseFinalConstVarOrType_final_prefixedType() { |
| + createParser('final p.A a'); |
| + FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| + expectNotNullIfNoErrors(result); |
| listener.assertNoErrors(); |
| + Token keyword = result.keyword; |
| + expect(keyword, isNotNull); |
| + expect(keyword.type, TokenType.KEYWORD); |
| + expect(keyword.keyword, Keyword.FINAL); |
| + expect(result.type, isNotNull); |
| } |
| - void test_parseOptionalReturnType() { |
| - // TODO(brianwilkerson) Implement tests for this method. |
| + void test_parseFinalConstVarOrType_type_function() { |
| + createParser('int Function(int) f'); |
| + FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| + expectNotNullIfNoErrors(result); |
| + listener.assertNoErrors(); |
| + expect(result.keyword, isNull); |
| + expect(result.type, isNotNull); |
| } |
| - void test_parsePostfixExpression_decrement() { |
| - createParser('i--'); |
| - Expression expression = parser.parsePostfixExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseFinalConstVarOrType_type_parameterized() { |
| + createParser('A<B> a'); |
| + FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| + expectNotNullIfNoErrors(result); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<PostfixExpression>()); |
| - PostfixExpression postfixExpression = expression; |
| - expect(postfixExpression.operand, isNotNull); |
| - expect(postfixExpression.operator, isNotNull); |
| - expect(postfixExpression.operator.type, TokenType.MINUS_MINUS); |
| + expect(result.keyword, isNull); |
| + expect(result.type, isNotNull); |
| } |
| - void test_parsePostfixExpression_increment() { |
| - createParser('i++'); |
| - Expression expression = parser.parsePostfixExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseFinalConstVarOrType_type_prefixed() { |
| + createParser('p.A a'); |
| + FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| + expectNotNullIfNoErrors(result); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<PostfixExpression>()); |
| - PostfixExpression postfixExpression = expression; |
| - expect(postfixExpression.operand, isNotNull); |
| - expect(postfixExpression.operator, isNotNull); |
| - expect(postfixExpression.operator.type, TokenType.PLUS_PLUS); |
| + expect(result.keyword, isNull); |
| + expect(result.type, isNotNull); |
| } |
| - void test_parsePostfixExpression_none_indexExpression() { |
| - createParser('a[0]'); |
| - Expression expression = parser.parsePostfixExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseFinalConstVarOrType_type_prefixed_noIdentifier() { |
| + createParser('p.A,'); |
| + FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| + expectNotNullIfNoErrors(result); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<IndexExpression>()); |
| - IndexExpression indexExpression = expression; |
| - expect(indexExpression.target, isNotNull); |
| - expect(indexExpression.index, isNotNull); |
| + expect(result.keyword, isNull); |
| + expect(result.type, isNotNull); |
| } |
| - void test_parsePostfixExpression_none_methodInvocation() { |
| - createParser('a.m()'); |
| - Expression expression = parser.parsePostfixExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseFinalConstVarOrType_type_prefixedAndParameterized() { |
| + createParser('p.A<B> a'); |
| + FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| + expectNotNullIfNoErrors(result); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<MethodInvocation>()); |
| - MethodInvocation methodInvocation = expression; |
| - expect(methodInvocation.target, isNotNull); |
| - expect(methodInvocation.operator.type, TokenType.PERIOD); |
| - expect(methodInvocation.methodName, isNotNull); |
| - expect(methodInvocation.typeArguments, isNull); |
| - expect(methodInvocation.argumentList, isNotNull); |
| + expect(result.keyword, isNull); |
| + expect(result.type, isNotNull); |
| } |
| - void test_parsePostfixExpression_none_methodInvocation_question_dot() { |
| - createParser('a?.m()'); |
| - Expression expression = parser.parsePostfixExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseFinalConstVarOrType_type_simple() { |
| + createParser('A a'); |
| + FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| + expectNotNullIfNoErrors(result); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<MethodInvocation>()); |
| - MethodInvocation methodInvocation = expression; |
| - expect(methodInvocation.target, isNotNull); |
| - expect(methodInvocation.operator.type, TokenType.QUESTION_PERIOD); |
| - expect(methodInvocation.methodName, isNotNull); |
| - expect(methodInvocation.typeArguments, isNull); |
| - expect(methodInvocation.argumentList, isNotNull); |
| + expect(result.keyword, isNull); |
| + expect(result.type, isNotNull); |
| } |
| - void |
| - test_parsePostfixExpression_none_methodInvocation_question_dot_typeArgumentComments() { |
| - enableGenericMethodComments = true; |
| - createParser('a?.m/*<E>*/()'); |
| - Expression expression = parser.parsePostfixExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseFinalConstVarOrType_type_simple_noIdentifier_inFunctionType() { |
| + createParser('A,'); |
| + FinalConstVarOrType result = |
| + parser.parseFinalConstVarOrType(false, inFunctionType: true); |
| + expectNotNullIfNoErrors(result); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<MethodInvocation>()); |
| - MethodInvocation methodInvocation = expression; |
| - expect(methodInvocation.target, isNotNull); |
| - expect(methodInvocation.operator.type, TokenType.QUESTION_PERIOD); |
| - expect(methodInvocation.methodName, isNotNull); |
| - expect(methodInvocation.typeArguments, isNotNull); |
| - expect(methodInvocation.argumentList, isNotNull); |
| + expect(result.keyword, isNull); |
| + expect(result.type, isNotNull); |
| } |
| - void |
| - test_parsePostfixExpression_none_methodInvocation_question_dot_typeArguments() { |
| - createParser('a?.m<E>()'); |
| - Expression expression = parser.parsePostfixExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseFinalConstVarOrType_var() { |
| + createParser('var'); |
| + FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| + expectNotNullIfNoErrors(result); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<MethodInvocation>()); |
| - MethodInvocation methodInvocation = expression; |
| - expect(methodInvocation.target, isNotNull); |
| - expect(methodInvocation.operator.type, TokenType.QUESTION_PERIOD); |
| - expect(methodInvocation.methodName, isNotNull); |
| - expect(methodInvocation.typeArguments, isNotNull); |
| - expect(methodInvocation.argumentList, isNotNull); |
| + Token keyword = result.keyword; |
| + expect(keyword, isNotNull); |
| + expect(keyword.type, TokenType.KEYWORD); |
| + expect(keyword.keyword, Keyword.VAR); |
| + expect(result.type, isNull); |
| } |
| - void |
| - test_parsePostfixExpression_none_methodInvocation_typeArgumentComments() { |
| - enableGenericMethodComments = true; |
| - createParser('a.m/*<E>*/()'); |
| - Expression expression = parser.parsePostfixExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<MethodInvocation>()); |
| - MethodInvocation methodInvocation = expression; |
| - expect(methodInvocation.target, isNotNull); |
| - expect(methodInvocation.operator.type, TokenType.PERIOD); |
| - expect(methodInvocation.methodName, isNotNull); |
| - expect(methodInvocation.typeArguments, isNotNull); |
| - expect(methodInvocation.argumentList, isNotNull); |
| + void test_parseFinalConstVarOrType_void() { |
| + createParser('void f()'); |
| + FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| + expectNotNullIfNoErrors(result); |
| + listener.assertNoErrors(); |
| + expect(result.keyword, isNull); |
| + expect(result.type, isNotNull); |
| } |
| - void test_parsePostfixExpression_none_methodInvocation_typeArguments() { |
| - createParser('a.m<E>()'); |
| - Expression expression = parser.parsePostfixExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseFinalConstVarOrType_void_noIdentifier() { |
| + createParser('void,'); |
| + FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| + expectNotNullIfNoErrors(result); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<MethodInvocation>()); |
| - MethodInvocation methodInvocation = expression; |
| - expect(methodInvocation.target, isNotNull); |
| - expect(methodInvocation.operator.type, TokenType.PERIOD); |
| - expect(methodInvocation.methodName, isNotNull); |
| - expect(methodInvocation.typeArguments, isNotNull); |
| - expect(methodInvocation.argumentList, isNotNull); |
| + expect(result.keyword, isNull); |
| + expect(result.type, isNotNull); |
| } |
| - void test_parsePostfixExpression_none_propertyAccess() { |
| - createParser('a.b'); |
| - Expression expression = parser.parsePostfixExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseForStatement_each_await() { |
| + createParser('await for (element in list) {}'); |
| + Statement statement = parser.parseForStatement(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<PrefixedIdentifier>()); |
| - PrefixedIdentifier identifier = expression; |
| - expect(identifier.prefix, isNotNull); |
| - expect(identifier.identifier, isNotNull); |
| + expect(statement, new isInstanceOf<ForEachStatement>()); |
| + ForEachStatement forStatement = statement; |
| + expect(forStatement.awaitKeyword, isNotNull); |
| + expect(forStatement.forKeyword, isNotNull); |
| + expect(forStatement.leftParenthesis, isNotNull); |
| + expect(forStatement.loopVariable, isNull); |
| + expect(forStatement.identifier, isNotNull); |
| + expect(forStatement.inKeyword, isNotNull); |
| + expect(forStatement.iterable, isNotNull); |
| + expect(forStatement.rightParenthesis, isNotNull); |
| + expect(forStatement.body, isNotNull); |
| } |
| - void test_parsePrefixedIdentifier_noPrefix() { |
| - String lexeme = "bar"; |
| - createParser(lexeme); |
| - Identifier identifier = parser.parsePrefixedIdentifier(); |
| - expectNotNullIfNoErrors(identifier); |
| + void test_parseForStatement_each_identifier() { |
| + createParser('for (element in list) {}'); |
| + Statement statement = parser.parseForStatement(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(identifier, new isInstanceOf<SimpleIdentifier>()); |
| - SimpleIdentifier simpleIdentifier = identifier; |
| - expect(simpleIdentifier.token, isNotNull); |
| - expect(simpleIdentifier.name, lexeme); |
| + expect(statement, new isInstanceOf<ForEachStatement>()); |
| + ForEachStatement forStatement = statement; |
| + expect(forStatement.awaitKeyword, isNull); |
| + expect(forStatement.forKeyword, isNotNull); |
| + expect(forStatement.leftParenthesis, isNotNull); |
| + expect(forStatement.loopVariable, isNull); |
| + expect(forStatement.identifier, isNotNull); |
| + expect(forStatement.inKeyword, isNotNull); |
| + expect(forStatement.iterable, isNotNull); |
| + expect(forStatement.rightParenthesis, isNotNull); |
| + expect(forStatement.body, isNotNull); |
| } |
| - void test_parsePrefixedIdentifier_prefix() { |
| - String lexeme = "foo.bar"; |
| - createParser(lexeme); |
| - Identifier identifier = parser.parsePrefixedIdentifier(); |
| - expectNotNullIfNoErrors(identifier); |
| + void test_parseForStatement_each_noType_metadata() { |
| + createParser('for (@A var element in list) {}'); |
| + Statement statement = parser.parseForStatement(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(identifier, new isInstanceOf<PrefixedIdentifier>()); |
| - PrefixedIdentifier prefixedIdentifier = identifier; |
| - expect(prefixedIdentifier.prefix.name, "foo"); |
| - expect(prefixedIdentifier.period, isNotNull); |
| - expect(prefixedIdentifier.identifier.name, "bar"); |
| + expect(statement, new isInstanceOf<ForEachStatement>()); |
| + ForEachStatement forStatement = statement; |
| + expect(forStatement.awaitKeyword, isNull); |
| + expect(forStatement.forKeyword, isNotNull); |
| + expect(forStatement.leftParenthesis, isNotNull); |
| + expect(forStatement.loopVariable, isNotNull); |
| + expect(forStatement.loopVariable.metadata, hasLength(1)); |
| + expect(forStatement.identifier, isNull); |
| + expect(forStatement.inKeyword, isNotNull); |
| + expect(forStatement.iterable, isNotNull); |
| + expect(forStatement.rightParenthesis, isNotNull); |
| + expect(forStatement.body, isNotNull); |
| } |
| - void test_parsePrimaryExpression_const() { |
| - createParser('const A()'); |
| - Expression expression = parser.parsePrimaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseForStatement_each_type() { |
| + createParser('for (A element in list) {}'); |
| + Statement statement = parser.parseForStatement(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(expression, isNotNull); |
| + expect(statement, new isInstanceOf<ForEachStatement>()); |
| + ForEachStatement forStatement = statement; |
| + expect(forStatement.awaitKeyword, isNull); |
| + expect(forStatement.forKeyword, isNotNull); |
| + expect(forStatement.leftParenthesis, isNotNull); |
| + expect(forStatement.loopVariable, isNotNull); |
| + expect(forStatement.identifier, isNull); |
| + expect(forStatement.inKeyword, isNotNull); |
| + expect(forStatement.iterable, isNotNull); |
| + expect(forStatement.rightParenthesis, isNotNull); |
| + expect(forStatement.body, isNotNull); |
| } |
| - void test_parsePrimaryExpression_double() { |
| - String doubleLiteral = "3.2e4"; |
| - createParser(doubleLiteral); |
| - Expression expression = parser.parsePrimaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseForStatement_each_var() { |
| + createParser('for (var element in list) {}'); |
| + Statement statement = parser.parseForStatement(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<DoubleLiteral>()); |
| - DoubleLiteral literal = expression; |
| - expect(literal.literal, isNotNull); |
| - expect(literal.value, double.parse(doubleLiteral)); |
| + expect(statement, new isInstanceOf<ForEachStatement>()); |
| + ForEachStatement forStatement = statement; |
| + expect(forStatement.awaitKeyword, isNull); |
| + expect(forStatement.forKeyword, isNotNull); |
| + expect(forStatement.leftParenthesis, isNotNull); |
| + expect(forStatement.loopVariable, isNotNull); |
| + expect(forStatement.identifier, isNull); |
| + expect(forStatement.inKeyword, isNotNull); |
| + expect(forStatement.iterable, isNotNull); |
| + expect(forStatement.rightParenthesis, isNotNull); |
| + expect(forStatement.body, isNotNull); |
| } |
| - void test_parsePrimaryExpression_false() { |
| - createParser('false'); |
| - Expression expression = parser.parsePrimaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseForStatement_loop_c() { |
| + createParser('for (; i < count;) {}'); |
| + Statement statement = parser.parseForStatement(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<BooleanLiteral>()); |
| - BooleanLiteral literal = expression; |
| - expect(literal.literal, isNotNull); |
| - expect(literal.value, isFalse); |
| + expect(statement, new isInstanceOf<ForStatement>()); |
| + ForStatement forStatement = statement; |
| + expect(forStatement.forKeyword, isNotNull); |
| + expect(forStatement.leftParenthesis, isNotNull); |
| + expect(forStatement.variables, isNull); |
| + expect(forStatement.initialization, isNull); |
| + expect(forStatement.leftSeparator, isNotNull); |
| + expect(forStatement.condition, isNotNull); |
| + expect(forStatement.rightSeparator, isNotNull); |
| + expect(forStatement.updaters, hasLength(0)); |
| + expect(forStatement.rightParenthesis, isNotNull); |
| + expect(forStatement.body, isNotNull); |
| } |
| - void test_parsePrimaryExpression_function_arguments() { |
| - createParser('(int i) => i + 1'); |
| - Expression expression = parser.parsePrimaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseForStatement_loop_cu() { |
| + createParser('for (; i < count; i++) {}'); |
| + Statement statement = parser.parseForStatement(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<FunctionExpression>()); |
| - FunctionExpression functionExpression = expression; |
| - expect(functionExpression.parameters, isNotNull); |
| - expect(functionExpression.body, isNotNull); |
| + expect(statement, new isInstanceOf<ForStatement>()); |
| + ForStatement forStatement = statement; |
| + expect(forStatement.forKeyword, isNotNull); |
| + expect(forStatement.leftParenthesis, isNotNull); |
| + expect(forStatement.variables, isNull); |
| + expect(forStatement.initialization, isNull); |
| + expect(forStatement.leftSeparator, isNotNull); |
| + expect(forStatement.condition, isNotNull); |
| + expect(forStatement.rightSeparator, isNotNull); |
| + expect(forStatement.updaters, hasLength(1)); |
| + expect(forStatement.rightParenthesis, isNotNull); |
| + expect(forStatement.body, isNotNull); |
| } |
| - void test_parsePrimaryExpression_function_noArguments() { |
| - createParser('() => 42'); |
| - Expression expression = parser.parsePrimaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseForStatement_loop_ecu() { |
| + createParser('for (i--; i < count; i++) {}'); |
| + Statement statement = parser.parseForStatement(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<FunctionExpression>()); |
| - FunctionExpression functionExpression = expression; |
| - expect(functionExpression.parameters, isNotNull); |
| - expect(functionExpression.body, isNotNull); |
| + expect(statement, new isInstanceOf<ForStatement>()); |
| + ForStatement forStatement = statement; |
| + expect(forStatement.forKeyword, isNotNull); |
| + expect(forStatement.leftParenthesis, isNotNull); |
| + expect(forStatement.variables, isNull); |
| + expect(forStatement.initialization, isNotNull); |
| + expect(forStatement.leftSeparator, isNotNull); |
| + expect(forStatement.condition, isNotNull); |
| + expect(forStatement.rightSeparator, isNotNull); |
| + expect(forStatement.updaters, hasLength(1)); |
| + expect(forStatement.rightParenthesis, isNotNull); |
| + expect(forStatement.body, isNotNull); |
| } |
| - void test_parsePrimaryExpression_genericFunctionExpression() { |
| - createParser('<X, Y>(Map<X, Y> m, X x) => m[x]'); |
| - Expression expression = parser.parsePrimaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseForStatement_loop_i() { |
| + createParser('for (var i = 0;;) {}'); |
| + Statement statement = parser.parseForStatement(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<FunctionExpression>()); |
| - FunctionExpression function = expression; |
| - expect(function.typeParameters, isNotNull); |
| + expect(statement, new isInstanceOf<ForStatement>()); |
| + ForStatement forStatement = statement; |
| + expect(forStatement.forKeyword, isNotNull); |
| + expect(forStatement.leftParenthesis, isNotNull); |
| + VariableDeclarationList variables = forStatement.variables; |
| + expect(variables, isNotNull); |
| + expect(variables.metadata, hasLength(0)); |
| + expect(variables.variables, hasLength(1)); |
| + expect(forStatement.initialization, isNull); |
| + expect(forStatement.leftSeparator, isNotNull); |
| + expect(forStatement.condition, isNull); |
| + expect(forStatement.rightSeparator, isNotNull); |
| + expect(forStatement.updaters, hasLength(0)); |
| + expect(forStatement.rightParenthesis, isNotNull); |
| + expect(forStatement.body, isNotNull); |
| } |
| - void test_parsePrimaryExpression_hex() { |
| - String hexLiteral = "3F"; |
| - createParser('0x$hexLiteral'); |
| - Expression expression = parser.parsePrimaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseForStatement_loop_i_withMetadata() { |
| + createParser('for (@A var i = 0;;) {}'); |
| + Statement statement = parser.parseForStatement(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<IntegerLiteral>()); |
| - IntegerLiteral literal = expression; |
| - expect(literal.literal, isNotNull); |
| - expect(literal.value, int.parse(hexLiteral, radix: 16)); |
| + expect(statement, new isInstanceOf<ForStatement>()); |
| + ForStatement forStatement = statement; |
| + expect(forStatement.forKeyword, isNotNull); |
| + expect(forStatement.leftParenthesis, isNotNull); |
| + VariableDeclarationList variables = forStatement.variables; |
| + expect(variables, isNotNull); |
| + expect(variables.metadata, hasLength(1)); |
| + expect(variables.variables, hasLength(1)); |
| + expect(forStatement.initialization, isNull); |
| + expect(forStatement.leftSeparator, isNotNull); |
| + expect(forStatement.condition, isNull); |
| + expect(forStatement.rightSeparator, isNotNull); |
| + expect(forStatement.updaters, hasLength(0)); |
| + expect(forStatement.rightParenthesis, isNotNull); |
| + expect(forStatement.body, isNotNull); |
| } |
| - void test_parsePrimaryExpression_identifier() { |
| - createParser('a'); |
| - Expression expression = parser.parsePrimaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseForStatement_loop_ic() { |
| + createParser('for (var i = 0; i < count;) {}'); |
| + Statement statement = parser.parseForStatement(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<SimpleIdentifier>()); |
| - SimpleIdentifier identifier = expression; |
| - expect(identifier, isNotNull); |
| + expect(statement, new isInstanceOf<ForStatement>()); |
| + ForStatement forStatement = statement; |
| + expect(forStatement.forKeyword, isNotNull); |
| + expect(forStatement.leftParenthesis, isNotNull); |
| + VariableDeclarationList variables = forStatement.variables; |
| + expect(variables, isNotNull); |
| + expect(variables.variables, hasLength(1)); |
| + expect(forStatement.initialization, isNull); |
| + expect(forStatement.leftSeparator, isNotNull); |
| + expect(forStatement.condition, isNotNull); |
| + expect(forStatement.rightSeparator, isNotNull); |
| + expect(forStatement.updaters, hasLength(0)); |
| + expect(forStatement.rightParenthesis, isNotNull); |
| + expect(forStatement.body, isNotNull); |
| } |
| - void test_parsePrimaryExpression_int() { |
| - String intLiteral = "472"; |
| - createParser(intLiteral); |
| - Expression expression = parser.parsePrimaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseForStatement_loop_icu() { |
| + createParser('for (var i = 0; i < count; i++) {}'); |
| + Statement statement = parser.parseForStatement(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<IntegerLiteral>()); |
| - IntegerLiteral literal = expression; |
| - expect(literal.literal, isNotNull); |
| - expect(literal.value, int.parse(intLiteral)); |
| + expect(statement, new isInstanceOf<ForStatement>()); |
| + ForStatement forStatement = statement; |
| + expect(forStatement.forKeyword, isNotNull); |
| + expect(forStatement.leftParenthesis, isNotNull); |
| + VariableDeclarationList variables = forStatement.variables; |
| + expect(variables, isNotNull); |
| + expect(variables.variables, hasLength(1)); |
| + expect(forStatement.initialization, isNull); |
| + expect(forStatement.leftSeparator, isNotNull); |
| + expect(forStatement.condition, isNotNull); |
| + expect(forStatement.rightSeparator, isNotNull); |
| + expect(forStatement.updaters, hasLength(1)); |
| + expect(forStatement.rightParenthesis, isNotNull); |
| + expect(forStatement.body, isNotNull); |
| } |
| - void test_parsePrimaryExpression_listLiteral() { |
| - createParser('[ ]'); |
| - Expression expression = parser.parsePrimaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseForStatement_loop_iicuu() { |
| + createParser('for (int i = 0, j = count; i < j; i++, j--) {}'); |
| + Statement statement = parser.parseForStatement(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<ListLiteral>()); |
| - ListLiteral literal = expression; |
| - expect(literal, isNotNull); |
| + expect(statement, new isInstanceOf<ForStatement>()); |
| + ForStatement forStatement = statement; |
| + expect(forStatement.forKeyword, isNotNull); |
| + expect(forStatement.leftParenthesis, isNotNull); |
| + VariableDeclarationList variables = forStatement.variables; |
| + expect(variables, isNotNull); |
| + expect(variables.variables, hasLength(2)); |
| + expect(forStatement.initialization, isNull); |
| + expect(forStatement.leftSeparator, isNotNull); |
| + expect(forStatement.condition, isNotNull); |
| + expect(forStatement.rightSeparator, isNotNull); |
| + expect(forStatement.updaters, hasLength(2)); |
| + expect(forStatement.rightParenthesis, isNotNull); |
| + expect(forStatement.body, isNotNull); |
| } |
| - void test_parsePrimaryExpression_listLiteral_index() { |
| - createParser('[]'); |
| - Expression expression = parser.parsePrimaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseForStatement_loop_iu() { |
| + createParser('for (var i = 0;; i++) {}'); |
| + Statement statement = parser.parseForStatement(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<ListLiteral>()); |
| - ListLiteral literal = expression; |
| - expect(literal, isNotNull); |
| + expect(statement, new isInstanceOf<ForStatement>()); |
| + ForStatement forStatement = statement; |
| + expect(forStatement.forKeyword, isNotNull); |
| + expect(forStatement.leftParenthesis, isNotNull); |
| + VariableDeclarationList variables = forStatement.variables; |
| + expect(variables, isNotNull); |
| + expect(variables.variables, hasLength(1)); |
| + expect(forStatement.initialization, isNull); |
| + expect(forStatement.leftSeparator, isNotNull); |
| + expect(forStatement.condition, isNull); |
| + expect(forStatement.rightSeparator, isNotNull); |
| + expect(forStatement.updaters, hasLength(1)); |
| + expect(forStatement.rightParenthesis, isNotNull); |
| + expect(forStatement.body, isNotNull); |
| } |
| - void test_parsePrimaryExpression_listLiteral_typed() { |
| - createParser('<A>[ ]'); |
| - Expression expression = parser.parsePrimaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseForStatement_loop_u() { |
| + createParser('for (;; i++) {}'); |
| + Statement statement = parser.parseForStatement(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<ListLiteral>()); |
| - ListLiteral literal = expression; |
| - expect(literal.typeArguments, isNotNull); |
| - expect(literal.typeArguments.arguments, hasLength(1)); |
| + expect(statement, new isInstanceOf<ForStatement>()); |
| + ForStatement forStatement = statement; |
| + expect(forStatement.forKeyword, isNotNull); |
| + expect(forStatement.leftParenthesis, isNotNull); |
| + expect(forStatement.variables, isNull); |
| + expect(forStatement.initialization, isNull); |
| + expect(forStatement.leftSeparator, isNotNull); |
| + expect(forStatement.condition, isNull); |
| + expect(forStatement.rightSeparator, isNotNull); |
| + expect(forStatement.updaters, hasLength(1)); |
| + expect(forStatement.rightParenthesis, isNotNull); |
| + expect(forStatement.body, isNotNull); |
| } |
| - void test_parsePrimaryExpression_listLiteral_typed_genericComment() { |
| - enableGenericMethodComments = true; |
| - createParser('/*<A>*/[ ]'); |
| - Expression expression = parser.parsePrimaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseFunctionBody_block() { |
| + createParser('{}'); |
| + FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| + expectNotNullIfNoErrors(functionBody); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<ListLiteral>()); |
| - ListLiteral literal = expression; |
| - expect(literal.typeArguments, isNotNull); |
| - expect(literal.typeArguments.arguments, hasLength(1)); |
| + expect(functionBody, new isInstanceOf<BlockFunctionBody>()); |
| + BlockFunctionBody body = functionBody; |
| + expect(body.keyword, isNull); |
| + expect(body.star, isNull); |
| + expect(body.block, isNotNull); |
| + expect(body.isAsynchronous, isFalse); |
| + expect(body.isGenerator, isFalse); |
| + expect(body.isSynchronous, isTrue); |
| } |
| - void test_parsePrimaryExpression_mapLiteral() { |
| - createParser('{}'); |
| - Expression expression = parser.parsePrimaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseFunctionBody_block_async() { |
| + createParser('async {}'); |
| + FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| + expectNotNullIfNoErrors(functionBody); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<MapLiteral>()); |
| - MapLiteral literal = expression; |
| - expect(literal.typeArguments, isNull); |
| - expect(literal, isNotNull); |
| + expect(functionBody, new isInstanceOf<BlockFunctionBody>()); |
| + BlockFunctionBody body = functionBody; |
| + expect(body.keyword, isNotNull); |
| + expect(body.keyword.lexeme, Parser.ASYNC); |
| + expect(body.star, isNull); |
| + expect(body.block, isNotNull); |
| + expect(body.isAsynchronous, isTrue); |
| + expect(body.isGenerator, isFalse); |
| + expect(body.isSynchronous, isFalse); |
| } |
| - void test_parsePrimaryExpression_mapLiteral_typed() { |
| - createParser('<A, B>{}'); |
| - Expression expression = parser.parsePrimaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseFunctionBody_block_asyncGenerator() { |
| + createParser('async* {}'); |
| + FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| + expectNotNullIfNoErrors(functionBody); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<MapLiteral>()); |
| - MapLiteral literal = expression; |
| - expect(literal.typeArguments, isNotNull); |
| - expect(literal.typeArguments.arguments, hasLength(2)); |
| + expect(functionBody, new isInstanceOf<BlockFunctionBody>()); |
| + BlockFunctionBody body = functionBody; |
| + expect(body.keyword, isNotNull); |
| + expect(body.keyword.lexeme, Parser.ASYNC); |
| + expect(body.star, isNotNull); |
| + expect(body.block, isNotNull); |
| + expect(body.isAsynchronous, isTrue); |
| + expect(body.isGenerator, isTrue); |
| + expect(body.isSynchronous, isFalse); |
| } |
| - void test_parsePrimaryExpression_mapLiteral_typed_genericComment() { |
| - enableGenericMethodComments = true; |
| - createParser('/*<A, B>*/{}'); |
| - Expression expression = parser.parsePrimaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseFunctionBody_block_syncGenerator() { |
| + createParser('sync* {}'); |
| + FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| + expectNotNullIfNoErrors(functionBody); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<MapLiteral>()); |
| - MapLiteral literal = expression; |
| - expect(literal.typeArguments, isNotNull); |
| - expect(literal.typeArguments.arguments, hasLength(2)); |
| + expect(functionBody, new isInstanceOf<BlockFunctionBody>()); |
| + BlockFunctionBody body = functionBody; |
| + expect(body.keyword, isNotNull); |
| + expect(body.keyword.lexeme, Parser.SYNC); |
| + expect(body.star, isNotNull); |
| + expect(body.block, isNotNull); |
| + expect(body.isAsynchronous, isFalse); |
| + expect(body.isGenerator, isTrue); |
| + expect(body.isSynchronous, isTrue); |
| } |
| - void test_parsePrimaryExpression_new() { |
| - createParser('new A()'); |
| - Expression expression = parser.parsePrimaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseFunctionBody_empty() { |
| + createParser(';'); |
| + FunctionBody functionBody = parser.parseFunctionBody(true, null, false); |
| + expectNotNullIfNoErrors(functionBody); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<InstanceCreationExpression>()); |
| - InstanceCreationExpression creation = expression; |
| - expect(creation, isNotNull); |
| + expect(functionBody, new isInstanceOf<EmptyFunctionBody>()); |
| + EmptyFunctionBody body = functionBody; |
| + expect(body.semicolon, isNotNull); |
| } |
| - void test_parsePrimaryExpression_null() { |
| - createParser('null'); |
| - Expression expression = parser.parsePrimaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseFunctionBody_expression() { |
| + createParser('=> y;'); |
| + FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| + expectNotNullIfNoErrors(functionBody); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<NullLiteral>()); |
| - NullLiteral literal = expression; |
| - expect(literal.literal, isNotNull); |
| + expect(functionBody, new isInstanceOf<ExpressionFunctionBody>()); |
| + ExpressionFunctionBody body = functionBody; |
| + expect(body.keyword, isNull); |
| + expect(body.functionDefinition, isNotNull); |
| + expect(body.expression, isNotNull); |
| + expect(body.semicolon, isNotNull); |
| + expect(body.isAsynchronous, isFalse); |
| + expect(body.isGenerator, isFalse); |
| + expect(body.isSynchronous, isTrue); |
| } |
| - void test_parsePrimaryExpression_parenthesized() { |
| - createParser('(x)'); |
| - Expression expression = parser.parsePrimaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseFunctionBody_expression_async() { |
| + createParser('async => y;'); |
| + FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| + expectNotNullIfNoErrors(functionBody); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<ParenthesizedExpression>()); |
| - ParenthesizedExpression parens = expression; |
| - expect(parens, isNotNull); |
| + expect(functionBody, new isInstanceOf<ExpressionFunctionBody>()); |
| + ExpressionFunctionBody body = functionBody; |
| + expect(body.keyword, isNotNull); |
| + expect(body.keyword.lexeme, Parser.ASYNC); |
| + expect(body.functionDefinition, isNotNull); |
| + expect(body.expression, isNotNull); |
| + expect(body.semicolon, isNotNull); |
| + expect(body.isAsynchronous, isTrue); |
| + expect(body.isGenerator, isFalse); |
| + expect(body.isSynchronous, isFalse); |
| } |
| - void test_parsePrimaryExpression_string() { |
| - createParser('"string"'); |
| - Expression expression = parser.parsePrimaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseFunctionBody_nativeFunctionBody() { |
| + createParser('native "str";'); |
| + FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| + expectNotNullIfNoErrors(functionBody); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| - SimpleStringLiteral literal = expression; |
| - expect(literal.isMultiline, isFalse); |
| - expect(literal.isRaw, isFalse); |
| - expect(literal.value, "string"); |
| + expect(functionBody, new isInstanceOf<NativeFunctionBody>()); |
| + NativeFunctionBody body = functionBody; |
| + expect(body.nativeKeyword, isNotNull); |
| + expect(body.stringLiteral, isNotNull); |
| + expect(body.semicolon, isNotNull); |
| } |
| - void test_parsePrimaryExpression_string_multiline() { |
| - createParser("'''string'''"); |
| - Expression expression = parser.parsePrimaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseFunctionBody_skip_block() { |
| + ParserTestCase.parseFunctionBodies = false; |
| + createParser('{}'); |
| + FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| + expectNotNullIfNoErrors(functionBody); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| - SimpleStringLiteral literal = expression; |
| - expect(literal.isMultiline, isTrue); |
| - expect(literal.isRaw, isFalse); |
| - expect(literal.value, "string"); |
| + expect(functionBody, new isInstanceOf<EmptyFunctionBody>()); |
| } |
| - void test_parsePrimaryExpression_string_raw() { |
| - createParser("r'string'"); |
| - Expression expression = parser.parsePrimaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| - SimpleStringLiteral literal = expression; |
| - expect(literal.isMultiline, isFalse); |
| - expect(literal.isRaw, isTrue); |
| - expect(literal.value, "string"); |
| + void test_parseFunctionBody_skip_block_invalid() { |
| + ParserTestCase.parseFunctionBodies = false; |
| + createParser('{'); |
| + FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| + expectNotNullIfNoErrors(functionBody); |
| + listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_TOKEN]); |
| + expect(functionBody, new isInstanceOf<EmptyFunctionBody>()); |
| } |
| - void test_parsePrimaryExpression_super() { |
| - createParser('super.x'); |
| - Expression expression = parser.parsePrimaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseFunctionBody_skip_blocks() { |
| + ParserTestCase.parseFunctionBodies = false; |
| + createParser('{ {} }'); |
| + FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| + expectNotNullIfNoErrors(functionBody); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<PropertyAccess>()); |
| - PropertyAccess propertyAccess = expression; |
| - expect(propertyAccess.target is SuperExpression, isTrue); |
| - expect(propertyAccess.operator, isNotNull); |
| - expect(propertyAccess.operator.type, TokenType.PERIOD); |
| - expect(propertyAccess.propertyName, isNotNull); |
| + expect(functionBody, new isInstanceOf<EmptyFunctionBody>()); |
| } |
| - void test_parsePrimaryExpression_this() { |
| - createParser('this'); |
| - Expression expression = parser.parsePrimaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseFunctionBody_skip_expression() { |
| + ParserTestCase.parseFunctionBodies = false; |
| + createParser('=> y;'); |
| + FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| + expectNotNullIfNoErrors(functionBody); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<ThisExpression>()); |
| - ThisExpression thisExpression = expression; |
| - expect(thisExpression.thisKeyword, isNotNull); |
| + expect(functionBody, new isInstanceOf<EmptyFunctionBody>()); |
| } |
| - void test_parsePrimaryExpression_true() { |
| - createParser('true'); |
| - Expression expression = parser.parsePrimaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseFunctionDeclarationStatement() { |
| + createParser('void f(int p) => p * 2;'); |
| + FunctionDeclarationStatement statement = |
| + parser.parseFunctionDeclarationStatement(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<BooleanLiteral>()); |
| - BooleanLiteral literal = expression; |
| - expect(literal.literal, isNotNull); |
| - expect(literal.value, isTrue); |
| - } |
| - |
| - void test_Parser() { |
| - expect(new Parser(null, null), isNotNull); |
| + expect(statement.functionDeclaration, isNotNull); |
| } |
| - void test_parseRedirectingConstructorInvocation_named() { |
| - createParser('this.a()'); |
| - RedirectingConstructorInvocation invocation = |
| - parser.parseRedirectingConstructorInvocation(true); |
| - expectNotNullIfNoErrors(invocation); |
| + void test_parseFunctionDeclarationStatement_typeParameterComments() { |
| + enableGenericMethodComments = true; |
| + createParser('/*=E*/ f/*<E>*/(/*=E*/ p) => p * 2;'); |
| + FunctionDeclarationStatement statement = |
| + parser.parseFunctionDeclarationStatement(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(invocation.argumentList, isNotNull); |
| - expect(invocation.constructorName, isNotNull); |
| - expect(invocation.thisKeyword, isNotNull); |
| - expect(invocation.period, isNotNull); |
| + FunctionDeclaration f = statement.functionDeclaration; |
| + expect(f, isNotNull); |
| + expect(f.functionExpression.typeParameters, isNotNull); |
| + expect(f.returnType, isNotNull); |
| + SimpleFormalParameter p = f.functionExpression.parameters.parameters[0]; |
| + expect(p.type, isNotNull); |
| } |
| - void test_parseRedirectingConstructorInvocation_unnamed() { |
| - createParser('this()'); |
| - RedirectingConstructorInvocation invocation = |
| - parser.parseRedirectingConstructorInvocation(false); |
| - expectNotNullIfNoErrors(invocation); |
| + void test_parseFunctionDeclarationStatement_typeParameters() { |
| + createParser('E f<E>(E p) => p * 2;'); |
| + FunctionDeclarationStatement statement = |
| + parser.parseFunctionDeclarationStatement(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(invocation.argumentList, isNotNull); |
| - expect(invocation.constructorName, isNull); |
| - expect(invocation.thisKeyword, isNotNull); |
| - expect(invocation.period, isNull); |
| + expect(statement.functionDeclaration, isNotNull); |
| + expect(statement.functionDeclaration.functionExpression.typeParameters, |
| + isNotNull); |
| } |
| - void test_parseRelationalExpression_as_functionType_noReturnType() { |
| - createParser('x as Function(int)'); |
| - Expression expression = parser.parseRelationalExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseFunctionDeclarationStatement_typeParameters_noReturnType() { |
| + createParser('f<E>(E p) => p * 2;'); |
| + FunctionDeclarationStatement statement = |
| + parser.parseFunctionDeclarationStatement(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<AsExpression>()); |
| - AsExpression asExpression = expression; |
| - expect(asExpression.expression, isNotNull); |
| - expect(asExpression.asOperator, isNotNull); |
| - expect(asExpression.type, new isInstanceOf<GenericFunctionType>()); |
| + expect(statement.functionDeclaration, isNotNull); |
| + expect(statement.functionDeclaration.functionExpression.typeParameters, |
| + isNotNull); |
| } |
| - void test_parseRelationalExpression_as_functionType_returnType() { |
| - createParser('x as String Function(int)'); |
| - Expression expression = parser.parseRelationalExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseIdentifierList_multiple() { |
| + createParser('a, b, c'); |
| + List<SimpleIdentifier> list = parser.parseIdentifierList(); |
| + expectNotNullIfNoErrors(list); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<AsExpression>()); |
| - AsExpression asExpression = expression; |
| - expect(asExpression.expression, isNotNull); |
| - expect(asExpression.asOperator, isNotNull); |
| - expect(asExpression.type, new isInstanceOf<GenericFunctionType>()); |
| + expect(list, hasLength(3)); |
| } |
| - void test_parseRelationalExpression_as_generic() { |
| - createParser('x as C<D>'); |
| - Expression expression = parser.parseRelationalExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseIdentifierList_single() { |
| + createParser('a'); |
| + List<SimpleIdentifier> list = parser.parseIdentifierList(); |
| + expectNotNullIfNoErrors(list); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<AsExpression>()); |
| - AsExpression asExpression = expression; |
| - expect(asExpression.expression, isNotNull); |
| - expect(asExpression.asOperator, isNotNull); |
| - expect(asExpression.type, new isInstanceOf<TypeName>()); |
| + expect(list, hasLength(1)); |
| } |
| - void test_parseRelationalExpression_as_nullable() { |
| - enableNnbd = true; |
| - createParser('x as Y?)'); |
| - Expression expression = parser.parseRelationalExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseIfStatement_else_block() { |
| + createParser('if (x) {} else {}'); |
| + IfStatement statement = parser.parseIfStatement(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<AsExpression>()); |
| - AsExpression asExpression = expression; |
| - expect(asExpression.expression, isNotNull); |
| - expect(asExpression.asOperator, isNotNull); |
| - expect(asExpression.type, new isInstanceOf<TypeName>()); |
| + expect(statement.ifKeyword, isNotNull); |
| + expect(statement.leftParenthesis, isNotNull); |
| + expect(statement.condition, isNotNull); |
| + expect(statement.rightParenthesis, isNotNull); |
| + expect(statement.thenStatement, isNotNull); |
| + expect(statement.elseKeyword, isNotNull); |
| + expect(statement.elseStatement, isNotNull); |
| } |
| - void test_parseRelationalExpression_as_simple() { |
| - createParser('x as Y'); |
| - Expression expression = parser.parseRelationalExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseIfStatement_else_statement() { |
| + createParser('if (x) f(x); else f(y);'); |
| + IfStatement statement = parser.parseIfStatement(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<AsExpression>()); |
| - AsExpression asExpression = expression; |
| - expect(asExpression.expression, isNotNull); |
| - expect(asExpression.asOperator, isNotNull); |
| - expect(asExpression.type, new isInstanceOf<TypeName>()); |
| + expect(statement.ifKeyword, isNotNull); |
| + expect(statement.leftParenthesis, isNotNull); |
| + expect(statement.condition, isNotNull); |
| + expect(statement.rightParenthesis, isNotNull); |
| + expect(statement.thenStatement, isNotNull); |
| + expect(statement.elseKeyword, isNotNull); |
| + expect(statement.elseStatement, isNotNull); |
| } |
| - void test_parseRelationalExpression_as_simple_function() { |
| - createParser('x as Function'); |
| - Expression expression = parser.parseRelationalExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<AsExpression>()); |
| - AsExpression asExpression = expression; |
| - expect(asExpression.expression, isNotNull); |
| - expect(asExpression.asOperator, isNotNull); |
| - expect(asExpression.type, new isInstanceOf<TypeName>()); |
| + void test_parseIfStatement_noElse_block() { |
| + createParser('if (x) {}'); |
| + IfStatement statement = parser.parseIfStatement(); |
| + expectNotNullIfNoErrors(statement); |
| + listener.assertNoErrors(); |
| + expect(statement.ifKeyword, isNotNull); |
| + expect(statement.leftParenthesis, isNotNull); |
| + expect(statement.condition, isNotNull); |
| + expect(statement.rightParenthesis, isNotNull); |
| + expect(statement.thenStatement, isNotNull); |
| + expect(statement.elseKeyword, isNull); |
| + expect(statement.elseStatement, isNull); |
| } |
| - void test_parseRelationalExpression_is() { |
| - createParser('x is y'); |
| - Expression expression = parser.parseRelationalExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseIfStatement_noElse_statement() { |
| + createParser('if (x) f(x);'); |
| + IfStatement statement = parser.parseIfStatement(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<IsExpression>()); |
| - IsExpression isExpression = expression; |
| - expect(isExpression.expression, isNotNull); |
| - expect(isExpression.isOperator, isNotNull); |
| - expect(isExpression.notOperator, isNull); |
| - expect(isExpression.type, isNotNull); |
| + expect(statement.ifKeyword, isNotNull); |
| + expect(statement.leftParenthesis, isNotNull); |
| + expect(statement.condition, isNotNull); |
| + expect(statement.rightParenthesis, isNotNull); |
| + expect(statement.thenStatement, isNotNull); |
| + expect(statement.elseKeyword, isNull); |
| + expect(statement.elseStatement, isNull); |
| } |
| - void test_parseRelationalExpression_is_nullable() { |
| - enableNnbd = true; |
| - createParser('x is y?)'); |
| - Expression expression = parser.parseRelationalExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseImplementsClause_multiple() { |
| + createParser('implements A, B, C'); |
| + ImplementsClause clause = parser.parseImplementsClause(); |
| + expectNotNullIfNoErrors(clause); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<IsExpression>()); |
| - IsExpression isExpression = expression; |
| - expect(isExpression.expression, isNotNull); |
| - expect(isExpression.isOperator, isNotNull); |
| - expect(isExpression.notOperator, isNull); |
| - expect(isExpression.type, isNotNull); |
| + expect(clause.interfaces, hasLength(3)); |
| + expect(clause.implementsKeyword, isNotNull); |
| } |
| - void test_parseRelationalExpression_isNot() { |
| - createParser('x is! y'); |
| - Expression expression = parser.parseRelationalExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseImplementsClause_single() { |
| + createParser('implements A'); |
| + ImplementsClause clause = parser.parseImplementsClause(); |
| + expectNotNullIfNoErrors(clause); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<IsExpression>()); |
| - IsExpression isExpression = expression; |
| - expect(isExpression.expression, isNotNull); |
| - expect(isExpression.isOperator, isNotNull); |
| - expect(isExpression.notOperator, isNotNull); |
| - expect(isExpression.type, isNotNull); |
| + expect(clause.interfaces, hasLength(1)); |
| + expect(clause.implementsKeyword, isNotNull); |
| } |
| - void test_parseRelationalExpression_normal() { |
| - createParser('x < y'); |
| - Expression expression = parser.parseRelationalExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseLibraryIdentifier_multiple() { |
| + String name = "a.b.c"; |
| + createParser(name); |
| + LibraryIdentifier identifier = parser.parseLibraryIdentifier(); |
| + expectNotNullIfNoErrors(identifier); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<BinaryExpression>()); |
| - BinaryExpression binaryExpression = expression; |
| - expect(binaryExpression.leftOperand, isNotNull); |
| - expect(binaryExpression.operator, isNotNull); |
| - expect(binaryExpression.operator.type, TokenType.LT); |
| - expect(binaryExpression.rightOperand, isNotNull); |
| + expect(identifier.name, name); |
| } |
| - void test_parseRelationalExpression_super() { |
| - createParser('super < y'); |
| - Expression expression = parser.parseRelationalExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseLibraryIdentifier_single() { |
| + String name = "a"; |
| + createParser(name); |
| + LibraryIdentifier identifier = parser.parseLibraryIdentifier(); |
| + expectNotNullIfNoErrors(identifier); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<BinaryExpression>()); |
| - BinaryExpression binaryExpression = expression; |
| - expect(binaryExpression.leftOperand, isNotNull); |
| - expect(binaryExpression.operator, isNotNull); |
| - expect(binaryExpression.operator.type, TokenType.LT); |
| - expect(binaryExpression.rightOperand, isNotNull); |
| + expect(identifier.name, name); |
| } |
| - void test_parseRethrowExpression() { |
| - createParser('rethrow;'); |
| - RethrowExpression expression = parser.parseRethrowExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseModifiers_abstract() { |
| + createParser('abstract A'); |
| + Modifiers modifiers = parser.parseModifiers(); |
| + expectNotNullIfNoErrors(modifiers); |
| listener.assertNoErrors(); |
| - expect(expression.rethrowKeyword, isNotNull); |
| + expect(modifiers.abstractKeyword, isNotNull); |
| } |
| - void test_parseReturnStatement_noValue() { |
| - createParser('return;'); |
| - ReturnStatement statement = parser.parseReturnStatement(); |
| - expectNotNullIfNoErrors(statement); |
| + void test_parseModifiers_const() { |
| + createParser('const A'); |
| + Modifiers modifiers = parser.parseModifiers(); |
| + expectNotNullIfNoErrors(modifiers); |
| listener.assertNoErrors(); |
| - expect(statement.returnKeyword, isNotNull); |
| - expect(statement.expression, isNull); |
| - expect(statement.semicolon, isNotNull); |
| + expect(modifiers.constKeyword, isNotNull); |
| } |
| - void test_parseReturnStatement_value() { |
| - createParser('return x;'); |
| - ReturnStatement statement = parser.parseReturnStatement(); |
| - expectNotNullIfNoErrors(statement); |
| + void test_parseModifiers_covariant() { |
| + createParser('covariant A'); |
| + Modifiers modifiers = parser.parseModifiers(); |
| + expectNotNullIfNoErrors(modifiers); |
| listener.assertNoErrors(); |
| - expect(statement.returnKeyword, isNotNull); |
| - expect(statement.expression, isNotNull); |
| - expect(statement.semicolon, isNotNull); |
| + expect(modifiers.covariantKeyword, isNotNull); |
| } |
| - void test_parseReturnType_function() { |
| - createParser('A<B> Function<B>(B)'); |
| - GenericFunctionType type = parser.parseReturnType(false); |
| - expectNotNullIfNoErrors(type); |
| + void test_parseModifiers_external() { |
| + createParser('external A'); |
| + Modifiers modifiers = parser.parseModifiers(); |
| + expectNotNullIfNoErrors(modifiers); |
| listener.assertNoErrors(); |
| - expect(type.returnType, isNotNull); |
| - expect(type.typeParameters, isNotNull); |
| - expect(type.parameters, isNotNull); |
| + expect(modifiers.externalKeyword, isNotNull); |
| } |
| - void test_parseReturnType_named() { |
| - createParser('A<B>'); |
| - TypeName typeName = parser.parseReturnType(false); |
| - expectNotNullIfNoErrors(typeName); |
| + void test_parseModifiers_factory() { |
| + createParser('factory A'); |
| + Modifiers modifiers = parser.parseModifiers(); |
| + expectNotNullIfNoErrors(modifiers); |
| listener.assertNoErrors(); |
| - expect(typeName.name, isNotNull); |
| - expect(typeName.typeArguments, isNotNull); |
| + expect(modifiers.factoryKeyword, isNotNull); |
| } |
| - void test_parseReturnType_void() { |
| - createParser('void'); |
| - TypeName typeName = parser.parseReturnType(false); |
| - expectNotNullIfNoErrors(typeName); |
| + void test_parseModifiers_final() { |
| + createParser('final A'); |
| + Modifiers modifiers = parser.parseModifiers(); |
| + expectNotNullIfNoErrors(modifiers); |
| listener.assertNoErrors(); |
| - expect(typeName.name, isNotNull); |
| - expect(typeName.typeArguments, isNull); |
| + expect(modifiers.finalKeyword, isNotNull); |
| } |
| - void test_parseShiftExpression_normal() { |
| - createParser('x << y'); |
| - BinaryExpression expression = parser.parseShiftExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseModifiers_static() { |
| + createParser('static A'); |
| + Modifiers modifiers = parser.parseModifiers(); |
| + expectNotNullIfNoErrors(modifiers); |
| listener.assertNoErrors(); |
| - expect(expression.leftOperand, isNotNull); |
| - expect(expression.operator, isNotNull); |
| - expect(expression.operator.type, TokenType.LT_LT); |
| - expect(expression.rightOperand, isNotNull); |
| + expect(modifiers.staticKeyword, isNotNull); |
| } |
| - void test_parseShiftExpression_super() { |
| - createParser('super << y'); |
| - BinaryExpression expression = parser.parseShiftExpression(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseModifiers_var() { |
| + createParser('var A'); |
| + Modifiers modifiers = parser.parseModifiers(); |
| + expectNotNullIfNoErrors(modifiers); |
| listener.assertNoErrors(); |
| - expect(expression.leftOperand, isNotNull); |
| - expect(expression.operator, isNotNull); |
| - expect(expression.operator.type, TokenType.LT_LT); |
| - expect(expression.rightOperand, isNotNull); |
| + expect(modifiers.varKeyword, isNotNull); |
| } |
| - void test_parseSimpleIdentifier1_normalIdentifier() { |
| - // TODO(brianwilkerson) Implement tests for this method. |
| + void test_parseNonLabeledStatement_const_list_empty() { |
| + createParser('const [];'); |
| + Statement statement = parser.parseNonLabeledStatement(); |
| + expectNotNullIfNoErrors(statement); |
| + listener.assertNoErrors(); |
| + expect(statement, new isInstanceOf<ExpressionStatement>()); |
| + ExpressionStatement expressionStatement = statement; |
| + expect(expressionStatement.expression, isNotNull); |
| } |
| - void test_parseSimpleIdentifier_builtInIdentifier() { |
| - String lexeme = "as"; |
| - createParser(lexeme); |
| - SimpleIdentifier identifier = parser.parseSimpleIdentifier(); |
| - expectNotNullIfNoErrors(identifier); |
| + void test_parseNonLabeledStatement_const_list_nonEmpty() { |
| + createParser('const [1, 2];'); |
| + Statement statement = parser.parseNonLabeledStatement(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(identifier.token, isNotNull); |
| - expect(identifier.name, lexeme); |
| + expect(statement, new isInstanceOf<ExpressionStatement>()); |
| + ExpressionStatement expressionStatement = statement; |
| + expect(expressionStatement.expression, isNotNull); |
| } |
| - void test_parseSimpleIdentifier_normalIdentifier() { |
| - String lexeme = "foo"; |
| - createParser(lexeme); |
| - SimpleIdentifier identifier = parser.parseSimpleIdentifier(); |
| - expectNotNullIfNoErrors(identifier); |
| + void test_parseNonLabeledStatement_const_map_empty() { |
| + createParser('const {};'); |
| + Statement statement = parser.parseNonLabeledStatement(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(identifier.token, isNotNull); |
| - expect(identifier.name, lexeme); |
| + expect(statement, new isInstanceOf<ExpressionStatement>()); |
| + ExpressionStatement expressionStatement = statement; |
| + expect(expressionStatement.expression, isNotNull); |
| } |
| - void test_parseStatement_emptyTypeArgumentList() { |
| - createParser('C<> c;'); |
| - Statement statement = parser.parseStatement2(); |
| + void test_parseNonLabeledStatement_const_map_nonEmpty() { |
| + // TODO(brianwilkerson) Implement more tests for this method. |
| + createParser("const {'a' : 1};"); |
| + Statement statement = parser.parseNonLabeledStatement(); |
| expectNotNullIfNoErrors(statement); |
| - listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_TYPE_NAME]); |
| - expect(statement, new isInstanceOf<VariableDeclarationStatement>()); |
| - VariableDeclarationStatement declaration = statement; |
| - VariableDeclarationList variables = declaration.variables; |
| - TypeName type = variables.type; |
| - TypeArgumentList argumentList = type.typeArguments; |
| - expect(argumentList.leftBracket, isNotNull); |
| - expect(argumentList.arguments, hasLength(1)); |
| - expect(argumentList.arguments[0].isSynthetic, isTrue); |
| - expect(argumentList.rightBracket, isNotNull); |
| + listener.assertNoErrors(); |
| + expect(statement, new isInstanceOf<ExpressionStatement>()); |
| + ExpressionStatement expressionStatement = statement; |
| + expect(expressionStatement.expression, isNotNull); |
| } |
| - void test_parseStatement_functionDeclaration_noReturnType() { |
| - createParser('f(a, b) {};'); |
| - Statement statement = parser.parseStatement2(); |
| + void test_parseNonLabeledStatement_const_object() { |
| + createParser('const A();'); |
| + Statement statement = parser.parseNonLabeledStatement(); |
| expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<FunctionDeclarationStatement>()); |
| - FunctionDeclarationStatement declaration = statement; |
| - expect(declaration.functionDeclaration, isNotNull); |
| + expect(statement, new isInstanceOf<ExpressionStatement>()); |
| + ExpressionStatement expressionStatement = statement; |
| + expect(expressionStatement.expression, isNotNull); |
| } |
| - void |
| - test_parseStatement_functionDeclaration_noReturnType_typeParameterComments() { |
| - enableGenericMethodComments = true; |
| - createParser('f/*<E>*/(a, b) {};'); |
| - Statement statement = parser.parseStatement2(); |
| + void test_parseNonLabeledStatement_const_object_named_typeParameters() { |
| + createParser('const A<B>.c();'); |
| + Statement statement = parser.parseNonLabeledStatement(); |
| expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<FunctionDeclarationStatement>()); |
| - FunctionDeclarationStatement declaration = statement; |
| - expect(declaration.functionDeclaration, isNotNull); |
| - expect(declaration.functionDeclaration.functionExpression.typeParameters, |
| - isNotNull); |
| + expect(statement, new isInstanceOf<ExpressionStatement>()); |
| + ExpressionStatement expressionStatement = statement; |
| + expect(expressionStatement.expression, isNotNull); |
| } |
| - void test_parseStatement_functionDeclaration_noReturnType_typeParameters() { |
| - createParser('f<E>(a, b) {};'); |
| - Statement statement = parser.parseStatement2(); |
| + void test_parseNonLabeledStatement_constructorInvocation() { |
| + createParser('new C().m();'); |
| + Statement statement = parser.parseNonLabeledStatement(); |
| expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<FunctionDeclarationStatement>()); |
| - FunctionDeclarationStatement declaration = statement; |
| - expect(declaration.functionDeclaration, isNotNull); |
| + expect(statement, new isInstanceOf<ExpressionStatement>()); |
| + ExpressionStatement expressionStatement = statement; |
| + expect(expressionStatement.expression, isNotNull); |
| } |
| - void test_parseStatement_functionDeclaration_returnType() { |
| - // TODO(brianwilkerson) Implement more tests for this method. |
| - createParser('int f(a, b) {};'); |
| - Statement statement = parser.parseStatement2(); |
| + void test_parseNonLabeledStatement_false() { |
| + createParser('false;'); |
| + Statement statement = parser.parseNonLabeledStatement(); |
| expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<FunctionDeclarationStatement>()); |
| - FunctionDeclarationStatement declaration = statement; |
| - expect(declaration.functionDeclaration, isNotNull); |
| + expect(statement, new isInstanceOf<ExpressionStatement>()); |
| + ExpressionStatement expressionStatement = statement; |
| + expect(expressionStatement.expression, isNotNull); |
| } |
| - void test_parseStatement_functionDeclaration_returnType_typeParameters() { |
| - createParser('int f<E>(a, b) {};'); |
| - Statement statement = parser.parseStatement2(); |
| + void test_parseNonLabeledStatement_functionDeclaration() { |
| + createParser('f() {};'); |
| + Statement statement = parser.parseNonLabeledStatement(); |
| expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<FunctionDeclarationStatement>()); |
| - FunctionDeclarationStatement declaration = statement; |
| - expect(declaration.functionDeclaration, isNotNull); |
| } |
| - void test_parseStatement_mulipleLabels() { |
| - createParser('l: m: return x;'); |
| - Statement statement = parser.parseStatement2(); |
| + void test_parseNonLabeledStatement_functionDeclaration_arguments() { |
| + createParser('f(void g()) {};'); |
| + Statement statement = parser.parseNonLabeledStatement(); |
| expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<LabeledStatement>()); |
| - LabeledStatement labeledStatement = statement; |
| - expect(labeledStatement.labels, hasLength(2)); |
| - expect(labeledStatement.statement, isNotNull); |
| } |
| - void test_parseStatement_noLabels() { |
| - createParser('return x;'); |
| - Statement statement = parser.parseStatement2(); |
| + void test_parseNonLabeledStatement_functionExpressionIndex() { |
| + createParser('() {}[0] = null;'); |
| + Statement statement = parser.parseNonLabeledStatement(); |
| expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| } |
| - void test_parseStatement_singleLabel() { |
| - createParser('l: return x;'); |
| - Statement statement = parser.parseStatement2(); |
| + void test_parseNonLabeledStatement_functionInvocation() { |
| + createParser('f();'); |
| + Statement statement = parser.parseNonLabeledStatement(); |
| expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(statement, new isInstanceOf<LabeledStatement>()); |
| - LabeledStatement labeledStatement = statement; |
| - expect(labeledStatement.labels, hasLength(1)); |
| - expect(labeledStatement.labels[0].label.inDeclarationContext(), isTrue); |
| - expect(labeledStatement.statement, isNotNull); |
| + expect(statement, new isInstanceOf<ExpressionStatement>()); |
| + ExpressionStatement expressionStatement = statement; |
| + expect(expressionStatement.expression, isNotNull); |
| } |
| - void test_parseStatements_multiple() { |
| - List<Statement> statements = parseStatements("return; return;", 2); |
| - expect(statements, hasLength(2)); |
| + void test_parseNonLabeledStatement_invokeFunctionExpression() { |
| + createParser('(a) {return a + a;} (3);'); |
| + Statement statement = parser.parseNonLabeledStatement(); |
| + expectNotNullIfNoErrors(statement); |
| + listener.assertNoErrors(); |
| + expect(statement, new isInstanceOf<ExpressionStatement>()); |
| + ExpressionStatement expressionStatement = statement; |
| + EngineTestCase.assertInstanceOf( |
| + (obj) => obj is FunctionExpressionInvocation, |
| + FunctionExpressionInvocation, |
| + expressionStatement.expression); |
| + FunctionExpressionInvocation invocation = |
| + expressionStatement.expression as FunctionExpressionInvocation; |
| + EngineTestCase.assertInstanceOf((obj) => obj is FunctionExpression, |
| + FunctionExpression, invocation.function); |
| + FunctionExpression expression = invocation.function as FunctionExpression; |
| + expect(expression.parameters, isNotNull); |
| + expect(expression.body, isNotNull); |
| + expect(invocation.typeArguments, isNull); |
| + ArgumentList list = invocation.argumentList; |
| + expect(list, isNotNull); |
| + expect(list.arguments, hasLength(1)); |
| } |
| - void test_parseStatements_single() { |
| - List<Statement> statements = parseStatements("return;", 1); |
| - expect(statements, hasLength(1)); |
| + void test_parseNonLabeledStatement_null() { |
| + createParser('null;'); |
| + Statement statement = parser.parseNonLabeledStatement(); |
| + expectNotNullIfNoErrors(statement); |
| + listener.assertNoErrors(); |
| + expect(statement, new isInstanceOf<ExpressionStatement>()); |
| + ExpressionStatement expressionStatement = statement; |
| + expect(expressionStatement.expression, isNotNull); |
| } |
| - void test_parseStringLiteral_adjacent() { |
| - createParser("'a' 'b'"); |
| - Expression expression = parser.parseStringLiteral(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseNonLabeledStatement_startingWithBuiltInIdentifier() { |
| + createParser('library.getName();'); |
| + Statement statement = parser.parseNonLabeledStatement(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<AdjacentStrings>()); |
| - AdjacentStrings literal = expression; |
| - NodeList<StringLiteral> strings = literal.strings; |
| - expect(strings, hasLength(2)); |
| - StringLiteral firstString = strings[0]; |
| - StringLiteral secondString = strings[1]; |
| - expect((firstString as SimpleStringLiteral).value, "a"); |
| - expect((secondString as SimpleStringLiteral).value, "b"); |
| + expect(statement, new isInstanceOf<ExpressionStatement>()); |
| + ExpressionStatement expressionStatement = statement; |
| + expect(expressionStatement.expression, isNotNull); |
| } |
| - void test_parseStringLiteral_endsWithInterpolation() { |
| - createParser(r"'x$y'"); |
| - Expression expression = parser.parseStringLiteral(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseNonLabeledStatement_true() { |
| + createParser('true;'); |
| + Statement statement = parser.parseNonLabeledStatement(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<StringInterpolation>()); |
| - StringInterpolation interpolation = expression; |
| - expect(interpolation.elements, hasLength(3)); |
| - expect(interpolation.elements[0], new isInstanceOf<InterpolationString>()); |
| - InterpolationString element0 = interpolation.elements[0]; |
| - expect(element0.value, 'x'); |
| - expect( |
| - interpolation.elements[1], new isInstanceOf<InterpolationExpression>()); |
| - InterpolationExpression element1 = interpolation.elements[1]; |
| - expect(element1.expression, new isInstanceOf<SimpleIdentifier>()); |
| - expect(interpolation.elements[2], new isInstanceOf<InterpolationString>()); |
| - InterpolationString element2 = interpolation.elements[2]; |
| - expect(element2.value, ''); |
| + expect(statement, new isInstanceOf<ExpressionStatement>()); |
| + ExpressionStatement expressionStatement = statement; |
| + expect(expressionStatement.expression, isNotNull); |
| } |
| - void test_parseStringLiteral_interpolated() { |
| - createParser("'a \${b} c \$this d'"); |
| - Expression expression = parser.parseStringLiteral(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseNonLabeledStatement_typeCast() { |
| + createParser('double.NAN as num;'); |
| + Statement statement = parser.parseNonLabeledStatement(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<StringInterpolation>()); |
| - StringInterpolation literal = expression; |
| - NodeList<InterpolationElement> elements = literal.elements; |
| - expect(elements, hasLength(5)); |
| - expect(elements[0] is InterpolationString, isTrue); |
| - expect(elements[1] is InterpolationExpression, isTrue); |
| - expect(elements[2] is InterpolationString, isTrue); |
| - expect(elements[3] is InterpolationExpression, isTrue); |
| - expect(elements[4] is InterpolationString, isTrue); |
| + expect(statement, new isInstanceOf<ExpressionStatement>()); |
| + ExpressionStatement expressionStatement = statement; |
| + expect(expressionStatement.expression, isNotNull); |
| } |
| - void test_parseStringLiteral_multiline_encodedSpace() { |
| - createParser("'''\\x20\na'''"); |
| - Expression expression = parser.parseStringLiteral(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseNonLabeledStatement_variableDeclaration_final_namedFunction() { |
| + createParser('final int Function = 0;'); |
| + Statement statement = parser.parseNonLabeledStatement(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| - SimpleStringLiteral literal = expression; |
| - expect(literal.literal, isNotNull); |
| - expect(literal.value, " \na"); |
| } |
| - void test_parseStringLiteral_multiline_endsWithInterpolation() { |
| - createParser(r"'''x$y'''"); |
| - Expression expression = parser.parseStringLiteral(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<StringInterpolation>()); |
| - StringInterpolation interpolation = expression; |
| - expect(interpolation.elements, hasLength(3)); |
| - expect(interpolation.elements[0], new isInstanceOf<InterpolationString>()); |
| - InterpolationString element0 = interpolation.elements[0]; |
| - expect(element0.value, 'x'); |
| - expect( |
| - interpolation.elements[1], new isInstanceOf<InterpolationExpression>()); |
| - InterpolationExpression element1 = interpolation.elements[1]; |
| - expect(element1.expression, new isInstanceOf<SimpleIdentifier>()); |
| - expect(interpolation.elements[2], new isInstanceOf<InterpolationString>()); |
| - InterpolationString element2 = interpolation.elements[2]; |
| - expect(element2.value, ''); |
| + void test_parseOptionalReturnType() { |
| + // TODO(brianwilkerson) Implement tests for this method. |
| } |
| - void test_parseStringLiteral_multiline_escapedBackslash() { |
| - createParser("'''\\\\\na'''"); |
| - Expression expression = parser.parseStringLiteral(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| - SimpleStringLiteral literal = expression; |
| - expect(literal.literal, isNotNull); |
| - expect(literal.value, "\\\na"); |
| + void test_Parser() { |
| + expect(new Parser(null, null), isNotNull); |
| } |
| - void test_parseStringLiteral_multiline_escapedBackslash_raw() { |
| - createParser("r'''\\\\\na'''"); |
| - Expression expression = parser.parseStringLiteral(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseRedirectingConstructorInvocation_named() { |
| + createParser('this.a()'); |
| + RedirectingConstructorInvocation invocation = |
| + parser.parseRedirectingConstructorInvocation(true); |
| + expectNotNullIfNoErrors(invocation); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| - SimpleStringLiteral literal = expression; |
| - expect(literal.literal, isNotNull); |
| - expect(literal.value, "\\\\\na"); |
| + expect(invocation.argumentList, isNotNull); |
| + expect(invocation.constructorName, isNotNull); |
| + expect(invocation.thisKeyword, isNotNull); |
| + expect(invocation.period, isNotNull); |
| } |
| - void test_parseStringLiteral_multiline_escapedEolMarker() { |
| - createParser("'''\\\na'''"); |
| - Expression expression = parser.parseStringLiteral(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseRedirectingConstructorInvocation_unnamed() { |
| + createParser('this()'); |
| + RedirectingConstructorInvocation invocation = |
| + parser.parseRedirectingConstructorInvocation(false); |
| + expectNotNullIfNoErrors(invocation); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| - SimpleStringLiteral literal = expression; |
| - expect(literal.literal, isNotNull); |
| - expect(literal.value, "a"); |
| + expect(invocation.argumentList, isNotNull); |
| + expect(invocation.constructorName, isNull); |
| + expect(invocation.thisKeyword, isNotNull); |
| + expect(invocation.period, isNull); |
| } |
| - void test_parseStringLiteral_multiline_escapedEolMarker_raw() { |
| - createParser("r'''\\\na'''"); |
| - Expression expression = parser.parseStringLiteral(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseReturnStatement_noValue() { |
| + createParser('return;'); |
| + ReturnStatement statement = parser.parseReturnStatement(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| - SimpleStringLiteral literal = expression; |
| - expect(literal.literal, isNotNull); |
| - expect(literal.value, "a"); |
| + expect(statement.returnKeyword, isNotNull); |
| + expect(statement.expression, isNull); |
| + expect(statement.semicolon, isNotNull); |
| } |
| - void test_parseStringLiteral_multiline_escapedSpaceAndEolMarker() { |
| - createParser("'''\\ \\\na'''"); |
| - Expression expression = parser.parseStringLiteral(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseReturnStatement_value() { |
| + createParser('return x;'); |
| + ReturnStatement statement = parser.parseReturnStatement(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| - SimpleStringLiteral literal = expression; |
| - expect(literal.literal, isNotNull); |
| - expect(literal.value, "a"); |
| + expect(statement.returnKeyword, isNotNull); |
| + expect(statement.expression, isNotNull); |
| + expect(statement.semicolon, isNotNull); |
| } |
| - void test_parseStringLiteral_multiline_escapedSpaceAndEolMarker_raw() { |
| - createParser("r'''\\ \\\na'''"); |
| - Expression expression = parser.parseStringLiteral(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseReturnType_function() { |
| + createParser('A<B> Function<B>(B)'); |
| + GenericFunctionType type = parser.parseReturnType(false); |
| + expectNotNullIfNoErrors(type); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| - SimpleStringLiteral literal = expression; |
| - expect(literal.literal, isNotNull); |
| - expect(literal.value, "a"); |
| + expect(type.returnType, isNotNull); |
| + expect(type.typeParameters, isNotNull); |
| + expect(type.parameters, isNotNull); |
| } |
| - void test_parseStringLiteral_multiline_escapedTab() { |
| - createParser("'''\\t\na'''"); |
| - Expression expression = parser.parseStringLiteral(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseReturnType_named() { |
| + createParser('A<B>'); |
| + TypeName typeName = parser.parseReturnType(false); |
| + expectNotNullIfNoErrors(typeName); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| - SimpleStringLiteral literal = expression; |
| - expect(literal.literal, isNotNull); |
| - expect(literal.value, "\t\na"); |
| + expect(typeName.name, isNotNull); |
| + expect(typeName.typeArguments, isNotNull); |
| } |
| - void test_parseStringLiteral_multiline_escapedTab_raw() { |
| - createParser("r'''\\t\na'''"); |
| - Expression expression = parser.parseStringLiteral(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseReturnType_void() { |
| + createParser('void'); |
| + TypeName typeName = parser.parseReturnType(false); |
| + expectNotNullIfNoErrors(typeName); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| - SimpleStringLiteral literal = expression; |
| - expect(literal.literal, isNotNull); |
| - expect(literal.value, "\\t\na"); |
| + expect(typeName.name, isNotNull); |
| + expect(typeName.typeArguments, isNull); |
| } |
| - void test_parseStringLiteral_multiline_quoteAfterInterpolation() { |
| - createParser(r"""'''$x'y'''"""); |
| - Expression expression = parser.parseStringLiteral(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<StringInterpolation>()); |
| - StringInterpolation interpolation = expression; |
| - expect(interpolation.elements, hasLength(3)); |
| - expect(interpolation.elements[0], new isInstanceOf<InterpolationString>()); |
| - InterpolationString element0 = interpolation.elements[0]; |
| - expect(element0.value, ''); |
| - expect( |
| - interpolation.elements[1], new isInstanceOf<InterpolationExpression>()); |
| - InterpolationExpression element1 = interpolation.elements[1]; |
| - expect(element1.expression, new isInstanceOf<SimpleIdentifier>()); |
| - expect(interpolation.elements[2], new isInstanceOf<InterpolationString>()); |
| - InterpolationString element2 = interpolation.elements[2]; |
| - expect(element2.value, "'y"); |
| + void test_parseStatement_emptyTypeArgumentList() { |
| + createParser('C<> c;'); |
| + Statement statement = parser.parseStatement2(); |
| + expectNotNullIfNoErrors(statement); |
| + listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_TYPE_NAME]); |
| + expect(statement, new isInstanceOf<VariableDeclarationStatement>()); |
| + VariableDeclarationStatement declaration = statement; |
| + VariableDeclarationList variables = declaration.variables; |
| + TypeName type = variables.type; |
| + TypeArgumentList argumentList = type.typeArguments; |
| + expect(argumentList.leftBracket, isNotNull); |
| + expect(argumentList.arguments, hasLength(1)); |
| + expect(argumentList.arguments[0].isSynthetic, isTrue); |
| + expect(argumentList.rightBracket, isNotNull); |
| } |
| - void test_parseStringLiteral_multiline_startsWithInterpolation() { |
| - createParser(r"'''${x}y'''"); |
| - Expression expression = parser.parseStringLiteral(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseStatement_functionDeclaration_noReturnType() { |
| + createParser('f(a, b) {};'); |
| + Statement statement = parser.parseStatement2(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<StringInterpolation>()); |
| - StringInterpolation interpolation = expression; |
| - expect(interpolation.elements, hasLength(3)); |
| - expect(interpolation.elements[0], new isInstanceOf<InterpolationString>()); |
| - InterpolationString element0 = interpolation.elements[0]; |
| - expect(element0.value, ''); |
| - expect( |
| - interpolation.elements[1], new isInstanceOf<InterpolationExpression>()); |
| - InterpolationExpression element1 = interpolation.elements[1]; |
| - expect(element1.expression, new isInstanceOf<SimpleIdentifier>()); |
| - expect(interpolation.elements[2], new isInstanceOf<InterpolationString>()); |
| - InterpolationString element2 = interpolation.elements[2]; |
| - expect(element2.value, 'y'); |
| + expect(statement, new isInstanceOf<FunctionDeclarationStatement>()); |
| + FunctionDeclarationStatement declaration = statement; |
| + expect(declaration.functionDeclaration, isNotNull); |
| } |
| - void test_parseStringLiteral_multiline_twoSpaces() { |
| - createParser("''' \na'''"); |
| - Expression expression = parser.parseStringLiteral(); |
| - expectNotNullIfNoErrors(expression); |
| + void |
| + test_parseStatement_functionDeclaration_noReturnType_typeParameterComments() { |
| + enableGenericMethodComments = true; |
| + createParser('f/*<E>*/(a, b) {};'); |
| + Statement statement = parser.parseStatement2(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| - SimpleStringLiteral literal = expression; |
| - expect(literal.literal, isNotNull); |
| - expect(literal.value, "a"); |
| + expect(statement, new isInstanceOf<FunctionDeclarationStatement>()); |
| + FunctionDeclarationStatement declaration = statement; |
| + expect(declaration.functionDeclaration, isNotNull); |
| + expect(declaration.functionDeclaration.functionExpression.typeParameters, |
| + isNotNull); |
| } |
| - void test_parseStringLiteral_multiline_twoSpaces_raw() { |
| - createParser("r''' \na'''"); |
| - Expression expression = parser.parseStringLiteral(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseStatement_functionDeclaration_noReturnType_typeParameters() { |
| + createParser('f<E>(a, b) {};'); |
| + Statement statement = parser.parseStatement2(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| - SimpleStringLiteral literal = expression; |
| - expect(literal.literal, isNotNull); |
| - expect(literal.value, "a"); |
| + expect(statement, new isInstanceOf<FunctionDeclarationStatement>()); |
| + FunctionDeclarationStatement declaration = statement; |
| + expect(declaration.functionDeclaration, isNotNull); |
| } |
| - void test_parseStringLiteral_multiline_untrimmed() { |
| - createParser("''' a\nb'''"); |
| - Expression expression = parser.parseStringLiteral(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseStatement_functionDeclaration_returnType() { |
| + // TODO(brianwilkerson) Implement more tests for this method. |
| + createParser('int f(a, b) {};'); |
| + Statement statement = parser.parseStatement2(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| - SimpleStringLiteral literal = expression; |
| - expect(literal.literal, isNotNull); |
| - expect(literal.value, " a\nb"); |
| + expect(statement, new isInstanceOf<FunctionDeclarationStatement>()); |
| + FunctionDeclarationStatement declaration = statement; |
| + expect(declaration.functionDeclaration, isNotNull); |
| } |
| - void test_parseStringLiteral_quoteAfterInterpolation() { |
| - createParser(r"""'$x"'"""); |
| - Expression expression = parser.parseStringLiteral(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseStatement_functionDeclaration_returnType_typeParameters() { |
| + createParser('int f<E>(a, b) {};'); |
| + Statement statement = parser.parseStatement2(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<StringInterpolation>()); |
| - StringInterpolation interpolation = expression; |
| - expect(interpolation.elements, hasLength(3)); |
| - expect(interpolation.elements[0], new isInstanceOf<InterpolationString>()); |
| - InterpolationString element0 = interpolation.elements[0]; |
| - expect(element0.value, ''); |
| - expect( |
| - interpolation.elements[1], new isInstanceOf<InterpolationExpression>()); |
| - InterpolationExpression element1 = interpolation.elements[1]; |
| - expect(element1.expression, new isInstanceOf<SimpleIdentifier>()); |
| - expect(interpolation.elements[2], new isInstanceOf<InterpolationString>()); |
| - InterpolationString element2 = interpolation.elements[2]; |
| - expect(element2.value, '"'); |
| + expect(statement, new isInstanceOf<FunctionDeclarationStatement>()); |
| + FunctionDeclarationStatement declaration = statement; |
| + expect(declaration.functionDeclaration, isNotNull); |
| } |
| - void test_parseStringLiteral_single() { |
| - createParser("'a'"); |
| - Expression expression = parser.parseStringLiteral(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseStatement_mulipleLabels() { |
| + createParser('l: m: return x;'); |
| + Statement statement = parser.parseStatement2(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| - SimpleStringLiteral literal = expression; |
| - expect(literal.literal, isNotNull); |
| - expect(literal.value, "a"); |
| + expect(statement, new isInstanceOf<LabeledStatement>()); |
| + LabeledStatement labeledStatement = statement; |
| + expect(labeledStatement.labels, hasLength(2)); |
| + expect(labeledStatement.statement, isNotNull); |
| } |
| - void test_parseStringLiteral_startsWithInterpolation() { |
| - createParser(r"'${x}y'"); |
| - Expression expression = parser.parseStringLiteral(); |
| - expectNotNullIfNoErrors(expression); |
| + void test_parseStatement_noLabels() { |
| + createParser('return x;'); |
| + Statement statement = parser.parseStatement2(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<StringInterpolation>()); |
| - StringInterpolation interpolation = expression; |
| - expect(interpolation.elements, hasLength(3)); |
| - expect(interpolation.elements[0], new isInstanceOf<InterpolationString>()); |
| - InterpolationString element0 = interpolation.elements[0]; |
| - expect(element0.value, ''); |
| - expect( |
| - interpolation.elements[1], new isInstanceOf<InterpolationExpression>()); |
| - InterpolationExpression element1 = interpolation.elements[1]; |
| - expect(element1.expression, new isInstanceOf<SimpleIdentifier>()); |
| - expect(interpolation.elements[2], new isInstanceOf<InterpolationString>()); |
| - InterpolationString element2 = interpolation.elements[2]; |
| - expect(element2.value, 'y'); |
| } |
| - void test_parseSuperConstructorInvocation_named() { |
| - createParser('super.a()'); |
| - SuperConstructorInvocation invocation = |
| - parser.parseSuperConstructorInvocation(); |
| - expectNotNullIfNoErrors(invocation); |
| + void test_parseStatement_singleLabel() { |
| + createParser('l: return x;'); |
| + Statement statement = parser.parseStatement2(); |
| + expectNotNullIfNoErrors(statement); |
| listener.assertNoErrors(); |
| - expect(invocation.argumentList, isNotNull); |
| - expect(invocation.constructorName, isNotNull); |
| - expect(invocation.superKeyword, isNotNull); |
| - expect(invocation.period, isNotNull); |
| + expect(statement, new isInstanceOf<LabeledStatement>()); |
| + LabeledStatement labeledStatement = statement; |
| + expect(labeledStatement.labels, hasLength(1)); |
| + expect(labeledStatement.labels[0].label.inDeclarationContext(), isTrue); |
| + expect(labeledStatement.statement, isNotNull); |
| } |
| - void test_parseSuperConstructorInvocation_unnamed() { |
| - createParser('super()'); |
| - SuperConstructorInvocation invocation = |
| - parser.parseSuperConstructorInvocation(); |
| - expectNotNullIfNoErrors(invocation); |
| - listener.assertNoErrors(); |
| - expect(invocation.argumentList, isNotNull); |
| - expect(invocation.constructorName, isNull); |
| - expect(invocation.superKeyword, isNotNull); |
| - expect(invocation.period, isNull); |
| + void test_parseStatements_multiple() { |
| + List<Statement> statements = parseStatements("return; return;", 2); |
| + expect(statements, hasLength(2)); |
| + } |
| + |
| + void test_parseStatements_single() { |
| + List<Statement> statements = parseStatements("return;", 1); |
| + expect(statements, hasLength(1)); |
| } |
| void test_parseSwitchStatement_case() { |
| @@ -11760,87 +12002,6 @@ void'''); |
| expect(statement.rightBracket, isNotNull); |
| } |
| - void test_parseSymbolLiteral_builtInIdentifier() { |
| - createParser('#dynamic.static.abstract'); |
| - SymbolLiteral literal = parser.parseSymbolLiteral(); |
| - expectNotNullIfNoErrors(literal); |
| - listener.assertNoErrors(); |
| - expect(literal.poundSign, isNotNull); |
| - List<Token> components = literal.components; |
| - expect(components, hasLength(3)); |
| - expect(components[0].lexeme, "dynamic"); |
| - expect(components[1].lexeme, "static"); |
| - expect(components[2].lexeme, "abstract"); |
| - } |
| - |
| - void test_parseSymbolLiteral_multiple() { |
| - createParser('#a.b.c'); |
| - SymbolLiteral literal = parser.parseSymbolLiteral(); |
| - expectNotNullIfNoErrors(literal); |
| - listener.assertNoErrors(); |
| - expect(literal.poundSign, isNotNull); |
| - List<Token> components = literal.components; |
| - expect(components, hasLength(3)); |
| - expect(components[0].lexeme, "a"); |
| - expect(components[1].lexeme, "b"); |
| - expect(components[2].lexeme, "c"); |
| - } |
| - |
| - void test_parseSymbolLiteral_operator() { |
| - createParser('#=='); |
| - SymbolLiteral literal = parser.parseSymbolLiteral(); |
| - expectNotNullIfNoErrors(literal); |
| - listener.assertNoErrors(); |
| - expect(literal.poundSign, isNotNull); |
| - List<Token> components = literal.components; |
| - expect(components, hasLength(1)); |
| - expect(components[0].lexeme, "=="); |
| - } |
| - |
| - void test_parseSymbolLiteral_single() { |
| - createParser('#a'); |
| - SymbolLiteral literal = parser.parseSymbolLiteral(); |
| - expectNotNullIfNoErrors(literal); |
| - listener.assertNoErrors(); |
| - expect(literal.poundSign, isNotNull); |
| - List<Token> components = literal.components; |
| - expect(components, hasLength(1)); |
| - expect(components[0].lexeme, "a"); |
| - } |
| - |
| - void test_parseSymbolLiteral_void() { |
| - createParser('#void'); |
| - SymbolLiteral literal = parser.parseSymbolLiteral(); |
| - expectNotNullIfNoErrors(literal); |
| - listener.assertNoErrors(); |
| - expect(literal.poundSign, isNotNull); |
| - List<Token> components = literal.components; |
| - expect(components, hasLength(1)); |
| - expect(components[0].lexeme, "void"); |
| - } |
| - |
| - void test_parseThrowExpression() { |
| - createParser('throw x;'); |
| - Expression expression = parser.parseThrowExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<ThrowExpression>()); |
| - ThrowExpression throwExpression = expression; |
| - expect(throwExpression.throwKeyword, isNotNull); |
| - expect(throwExpression.expression, isNotNull); |
| - } |
| - |
| - void test_parseThrowExpressionWithoutCascade() { |
| - createParser('throw x;'); |
| - Expression expression = parser.parseThrowExpressionWithoutCascade(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression, new isInstanceOf<ThrowExpression>()); |
| - ThrowExpression throwExpression = expression; |
| - expect(throwExpression.throwKeyword, isNotNull); |
| - expect(throwExpression.expression, isNotNull); |
| - } |
| - |
| void test_parseTryStatement_catch() { |
| createParser('try {} catch (e) {}'); |
| TryStatement statement = parser.parseTryStatement(); |
| @@ -12390,158 +12551,6 @@ void'''); |
| expect(parameterList.typeParameters, hasLength(1)); |
| } |
| - void test_parseUnaryExpression_decrement_normal() { |
| - createParser('--x'); |
| - PrefixExpression expression = parser.parseUnaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression.operator, isNotNull); |
| - expect(expression.operator.type, TokenType.MINUS_MINUS); |
| - expect(expression.operand, isNotNull); |
| - } |
| - |
| - void test_parseUnaryExpression_decrement_super() { |
| - createParser('--super'); |
| - PrefixExpression expression = parser.parseUnaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression.operator, isNotNull); |
| - expect(expression.operator.type, TokenType.MINUS); |
| - Expression innerExpression = expression.operand; |
| - expect(innerExpression, isNotNull); |
| - expect(innerExpression is PrefixExpression, isTrue); |
| - PrefixExpression operand = innerExpression as PrefixExpression; |
| - expect(operand.operator, isNotNull); |
| - expect(operand.operator.type, TokenType.MINUS); |
| - expect(operand.operand, isNotNull); |
| - } |
| - |
| - void test_parseUnaryExpression_decrement_super_propertyAccess() { |
| - createParser('--super.x'); |
| - PrefixExpression expression = parser.parseUnaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression.operator, isNotNull); |
| - expect(expression.operator.type, TokenType.MINUS_MINUS); |
| - expect(expression.operand, isNotNull); |
| - PropertyAccess operand = expression.operand as PropertyAccess; |
| - expect(operand.target is SuperExpression, isTrue); |
| - expect(operand.propertyName.name, "x"); |
| - } |
| - |
| - void test_parseUnaryExpression_decrement_super_withComment() { |
| - createParser('/* 0 */ --super'); |
| - PrefixExpression expression = parser.parseUnaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression.operator, isNotNull); |
| - expect(expression.operator.type, TokenType.MINUS); |
| - expect(expression.operator.precedingComments, isNotNull); |
| - Expression innerExpression = expression.operand; |
| - expect(innerExpression, isNotNull); |
| - expect(innerExpression is PrefixExpression, isTrue); |
| - PrefixExpression operand = innerExpression as PrefixExpression; |
| - expect(operand.operator, isNotNull); |
| - expect(operand.operator.type, TokenType.MINUS); |
| - expect(operand.operand, isNotNull); |
| - } |
| - |
| - void test_parseUnaryExpression_increment_normal() { |
| - createParser('++x'); |
| - PrefixExpression expression = parser.parseUnaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression.operator, isNotNull); |
| - expect(expression.operator.type, TokenType.PLUS_PLUS); |
| - expect(expression.operand, isNotNull); |
| - } |
| - |
| - void test_parseUnaryExpression_increment_super_index() { |
| - createParser('++super[0]'); |
| - PrefixExpression expression = parser.parseUnaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression.operator, isNotNull); |
| - expect(expression.operator.type, TokenType.PLUS_PLUS); |
| - expect(expression.operand, isNotNull); |
| - IndexExpression operand = expression.operand as IndexExpression; |
| - expect(operand.realTarget is SuperExpression, isTrue); |
| - expect(operand.index is IntegerLiteral, isTrue); |
| - } |
| - |
| - void test_parseUnaryExpression_increment_super_propertyAccess() { |
| - createParser('++super.x'); |
| - PrefixExpression expression = parser.parseUnaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression.operator, isNotNull); |
| - expect(expression.operator.type, TokenType.PLUS_PLUS); |
| - expect(expression.operand, isNotNull); |
| - PropertyAccess operand = expression.operand as PropertyAccess; |
| - expect(operand.target is SuperExpression, isTrue); |
| - expect(operand.propertyName.name, "x"); |
| - } |
| - |
| - void test_parseUnaryExpression_minus_normal() { |
| - createParser('-x'); |
| - PrefixExpression expression = parser.parseUnaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression.operator, isNotNull); |
| - expect(expression.operator.type, TokenType.MINUS); |
| - expect(expression.operand, isNotNull); |
| - } |
| - |
| - void test_parseUnaryExpression_minus_super() { |
| - createParser('-super'); |
| - PrefixExpression expression = parser.parseUnaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression.operator, isNotNull); |
| - expect(expression.operator.type, TokenType.MINUS); |
| - expect(expression.operand, isNotNull); |
| - } |
| - |
| - void test_parseUnaryExpression_not_normal() { |
| - createParser('!x'); |
| - PrefixExpression expression = parser.parseUnaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression.operator, isNotNull); |
| - expect(expression.operator.type, TokenType.BANG); |
| - expect(expression.operand, isNotNull); |
| - } |
| - |
| - void test_parseUnaryExpression_not_super() { |
| - createParser('!super'); |
| - PrefixExpression expression = parser.parseUnaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression.operator, isNotNull); |
| - expect(expression.operator.type, TokenType.BANG); |
| - expect(expression.operand, isNotNull); |
| - } |
| - |
| - void test_parseUnaryExpression_tilda_normal() { |
| - createParser('~x'); |
| - PrefixExpression expression = parser.parseUnaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression.operator, isNotNull); |
| - expect(expression.operator.type, TokenType.TILDE); |
| - expect(expression.operand, isNotNull); |
| - } |
| - |
| - void test_parseUnaryExpression_tilda_super() { |
| - createParser('~super'); |
| - PrefixExpression expression = parser.parseUnaryExpression(); |
| - expectNotNullIfNoErrors(expression); |
| - listener.assertNoErrors(); |
| - expect(expression.operator, isNotNull); |
| - expect(expression.operator.type, TokenType.TILDE); |
| - expect(expression.operand, isNotNull); |
| - } |
| - |
| void test_parseVariableDeclaration_equals() { |
| createParser('a = b'); |
| VariableDeclaration declaration = parser.parseVariableDeclaration(); |