| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analyzer.test.generated.parser_test; | 5 library analyzer.test.generated.parser_test; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; | 8 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; |
| 9 import 'package:analyzer/dart/ast/token.dart'; | 9 import 'package:analyzer/dart/ast/token.dart'; |
| 10 import 'package:analyzer/dart/ast/visitor.dart'; | 10 import 'package:analyzer/dart/ast/visitor.dart'; |
| (...skipping 3804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3815 List<ClassMember> members = classDecl.members; | 3815 List<ClassMember> members = classDecl.members; |
| 3816 expect(members, hasLength(1)); | 3816 expect(members, hasLength(1)); |
| 3817 FieldDeclaration fieldDecl = members[0] as FieldDeclaration; | 3817 FieldDeclaration fieldDecl = members[0] as FieldDeclaration; |
| 3818 // one field | 3818 // one field |
| 3819 VariableDeclarationList fieldList = fieldDecl.fields; | 3819 VariableDeclarationList fieldList = fieldDecl.fields; |
| 3820 List<VariableDeclaration> fields = fieldList.variables; | 3820 List<VariableDeclaration> fields = fieldList.variables; |
| 3821 expect(fields, hasLength(1)); | 3821 expect(fields, hasLength(1)); |
| 3822 VariableDeclaration field = fields[0]; | 3822 VariableDeclaration field = fields[0]; |
| 3823 expect(field.name.name, 'f'); | 3823 expect(field.name.name, 'f'); |
| 3824 // validate the type | 3824 // validate the type |
| 3825 TypeArgumentList typeArguments = (fieldList.type as TypeName).typeArguments; | 3825 TypeArgumentList typeArguments = fieldList.type.typeArguments; |
| 3826 expect(typeArguments.arguments, hasLength(1)); | 3826 expect(typeArguments.arguments, hasLength(1)); |
| 3827 // synthetic '>' | 3827 // synthetic '>' |
| 3828 Token token = typeArguments.endToken; | 3828 Token token = typeArguments.endToken; |
| 3829 expect(token.type, TokenType.GT); | 3829 expect(token.type, TokenType.GT); |
| 3830 expect(token.isSynthetic, isTrue); | 3830 expect(token.isSynthetic, isTrue); |
| 3831 } | 3831 } |
| 3832 | 3832 |
| 3833 void test_incompleteTypeParameters() { | 3833 void test_incompleteTypeParameters() { |
| 3834 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 3834 CompilationUnit unit = ParserTestCase.parseCompilationUnit( |
| 3835 r''' | 3835 r''' |
| (...skipping 26 matching lines...) Expand all Loading... |
| 3862 ParserErrorCode.MISSING_STATEMENT | 3862 ParserErrorCode.MISSING_STATEMENT |
| 3863 ]); | 3863 ]); |
| 3864 ClassDeclaration declaration = unit.declarations[0] as ClassDeclaration; | 3864 ClassDeclaration declaration = unit.declarations[0] as ClassDeclaration; |
| 3865 MethodDeclaration method = declaration.members[0] as MethodDeclaration; | 3865 MethodDeclaration method = declaration.members[0] as MethodDeclaration; |
| 3866 BlockFunctionBody body = method.body as BlockFunctionBody; | 3866 BlockFunctionBody body = method.body as BlockFunctionBody; |
| 3867 IfStatement ifStatement = body.block.statements[1] as IfStatement; | 3867 IfStatement ifStatement = body.block.statements[1] as IfStatement; |
| 3868 IsExpression expression = ifStatement.condition as IsExpression; | 3868 IsExpression expression = ifStatement.condition as IsExpression; |
| 3869 expect(expression.expression, isNotNull); | 3869 expect(expression.expression, isNotNull); |
| 3870 expect(expression.isOperator, isNotNull); | 3870 expect(expression.isOperator, isNotNull); |
| 3871 expect(expression.notOperator, isNotNull); | 3871 expect(expression.notOperator, isNotNull); |
| 3872 TypeAnnotation type = expression.type; | 3872 TypeName type = expression.type; |
| 3873 expect(type, isNotNull); | 3873 expect(type, isNotNull); |
| 3874 expect(type is TypeName && type.name.isSynthetic, isTrue); | 3874 expect(type.name.isSynthetic, isTrue); |
| 3875 EngineTestCase.assertInstanceOf((obj) => obj is EmptyStatement, | 3875 EngineTestCase.assertInstanceOf((obj) => obj is EmptyStatement, |
| 3876 EmptyStatement, ifStatement.thenStatement); | 3876 EmptyStatement, ifStatement.thenStatement); |
| 3877 } | 3877 } |
| 3878 | 3878 |
| 3879 void test_keywordInPlaceOfIdentifier() { | 3879 void test_keywordInPlaceOfIdentifier() { |
| 3880 // TODO(brianwilkerson) We could do better with this. | 3880 // TODO(brianwilkerson) We could do better with this. |
| 3881 ParserTestCase.parseCompilationUnit("do() {}", [ | 3881 ParserTestCase.parseCompilationUnit("do() {}", [ |
| 3882 ParserErrorCode.EXPECTED_EXECUTABLE, | 3882 ParserErrorCode.EXPECTED_EXECUTABLE, |
| 3883 ParserErrorCode.UNEXPECTED_TOKEN | 3883 ParserErrorCode.UNEXPECTED_TOKEN |
| 3884 ]); | 3884 ]); |
| (...skipping 2150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6035 createParser('/*=T*/ m/*<T>*/() {}'); | 6035 createParser('/*=T*/ m/*<T>*/() {}'); |
| 6036 ClassMember member = parser.parseClassMember('C'); | 6036 ClassMember member = parser.parseClassMember('C'); |
| 6037 expectNotNullIfNoErrors(member); | 6037 expectNotNullIfNoErrors(member); |
| 6038 listener.assertNoErrors(); | 6038 listener.assertNoErrors(); |
| 6039 expect(member, new isInstanceOf<MethodDeclaration>()); | 6039 expect(member, new isInstanceOf<MethodDeclaration>()); |
| 6040 MethodDeclaration method = member; | 6040 MethodDeclaration method = member; |
| 6041 expect(method.documentationComment, isNull); | 6041 expect(method.documentationComment, isNull); |
| 6042 expect(method.externalKeyword, isNull); | 6042 expect(method.externalKeyword, isNull); |
| 6043 expect(method.modifierKeyword, isNull); | 6043 expect(method.modifierKeyword, isNull); |
| 6044 expect(method.propertyKeyword, isNull); | 6044 expect(method.propertyKeyword, isNull); |
| 6045 expect((method.returnType as TypeName).name.name, 'T'); | 6045 expect(method.returnType.name.name, 'T'); |
| 6046 expect(method.name, isNotNull); | 6046 expect(method.name, isNotNull); |
| 6047 expect(method.operatorKeyword, isNull); | 6047 expect(method.operatorKeyword, isNull); |
| 6048 expect(method.typeParameters, isNotNull); | 6048 expect(method.typeParameters, isNotNull); |
| 6049 expect(method.parameters, isNotNull); | 6049 expect(method.parameters, isNotNull); |
| 6050 expect(method.body, isNotNull); | 6050 expect(method.body, isNotNull); |
| 6051 } | 6051 } |
| 6052 | 6052 |
| 6053 void test_parseClassMember_method_generic_comment_returnType_bound() { | 6053 void test_parseClassMember_method_generic_comment_returnType_bound() { |
| 6054 enableGenericMethodComments = true; | 6054 enableGenericMethodComments = true; |
| 6055 createParser('num/*=T*/ m/*<T extends num>*/() {}'); | 6055 createParser('num/*=T*/ m/*<T extends num>*/() {}'); |
| 6056 ClassMember member = parser.parseClassMember('C'); | 6056 ClassMember member = parser.parseClassMember('C'); |
| 6057 expectNotNullIfNoErrors(member); | 6057 expectNotNullIfNoErrors(member); |
| 6058 listener.assertNoErrors(); | 6058 listener.assertNoErrors(); |
| 6059 expect(member, new isInstanceOf<MethodDeclaration>()); | 6059 expect(member, new isInstanceOf<MethodDeclaration>()); |
| 6060 MethodDeclaration method = member; | 6060 MethodDeclaration method = member; |
| 6061 expect(method.documentationComment, isNull); | 6061 expect(method.documentationComment, isNull); |
| 6062 expect(method.externalKeyword, isNull); | 6062 expect(method.externalKeyword, isNull); |
| 6063 expect(method.modifierKeyword, isNull); | 6063 expect(method.modifierKeyword, isNull); |
| 6064 expect(method.propertyKeyword, isNull); | 6064 expect(method.propertyKeyword, isNull); |
| 6065 expect((method.returnType as TypeName).name.name, 'T'); | 6065 expect(method.returnType.name.name, 'T'); |
| 6066 expect(method.name, isNotNull); | 6066 expect(method.name, isNotNull); |
| 6067 expect(method.operatorKeyword, isNull); | 6067 expect(method.operatorKeyword, isNull); |
| 6068 expect(method.typeParameters, isNotNull); | 6068 expect(method.typeParameters, isNotNull); |
| 6069 TypeParameter tp = method.typeParameters.typeParameters[0]; | 6069 TypeParameter tp = method.typeParameters.typeParameters[0]; |
| 6070 expect(tp.name.name, 'T'); | 6070 expect(tp.name.name, 'T'); |
| 6071 expect(tp.extendsKeyword, isNotNull); | 6071 expect(tp.extendsKeyword, isNotNull); |
| 6072 expect((tp.bound as TypeName).name.name, 'num'); | 6072 expect(tp.bound.name.name, 'num'); |
| 6073 expect(method.parameters, isNotNull); | 6073 expect(method.parameters, isNotNull); |
| 6074 expect(method.body, isNotNull); | 6074 expect(method.body, isNotNull); |
| 6075 } | 6075 } |
| 6076 | 6076 |
| 6077 void test_parseClassMember_method_generic_comment_void() { | 6077 void test_parseClassMember_method_generic_comment_void() { |
| 6078 enableGenericMethodComments = true; | 6078 enableGenericMethodComments = true; |
| 6079 createParser('void m/*<T>*/() {}'); | 6079 createParser('void m/*<T>*/() {}'); |
| 6080 ClassMember member = parser.parseClassMember('C'); | 6080 ClassMember member = parser.parseClassMember('C'); |
| 6081 expectNotNullIfNoErrors(member); | 6081 expectNotNullIfNoErrors(member); |
| 6082 listener.assertNoErrors(); | 6082 listener.assertNoErrors(); |
| (...skipping 4060 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10143 expectNotNullIfNoErrors(expression); | 10143 expectNotNullIfNoErrors(expression); |
| 10144 listener.assertNoErrors(); | 10144 listener.assertNoErrors(); |
| 10145 expect(expression.keyword, token); | 10145 expect(expression.keyword, token); |
| 10146 ConstructorName name = expression.constructorName; | 10146 ConstructorName name = expression.constructorName; |
| 10147 expect(name, isNotNull); | 10147 expect(name, isNotNull); |
| 10148 TypeName type = name.type; | 10148 TypeName type = name.type; |
| 10149 expect(type, isNotNull); | 10149 expect(type, isNotNull); |
| 10150 expect(name.period, isNull); | 10150 expect(name.period, isNull); |
| 10151 expect(name.name, isNull); | 10151 expect(name.name, isNull); |
| 10152 expect(expression.argumentList, isNotNull); | 10152 expect(expression.argumentList, isNotNull); |
| 10153 NodeList<TypeAnnotation> arguments = type.typeArguments.arguments; | 10153 NodeList<TypeName> arguments = type.typeArguments.arguments; |
| 10154 expect(arguments, hasLength(1)); | 10154 expect(arguments, hasLength(1)); |
| 10155 expect((arguments[0] as TypeName).question, isNotNull); | 10155 expect(arguments[0].question, isNotNull); |
| 10156 } | 10156 } |
| 10157 | 10157 |
| 10158 void test_parseLibraryDirective() { | 10158 void test_parseLibraryDirective() { |
| 10159 createParser('library l;'); | 10159 createParser('library l;'); |
| 10160 LibraryDirective directive = | 10160 LibraryDirective directive = |
| 10161 parser.parseLibraryDirective(emptyCommentAndMetadata()); | 10161 parser.parseLibraryDirective(emptyCommentAndMetadata()); |
| 10162 expectNotNullIfNoErrors(directive); | 10162 expectNotNullIfNoErrors(directive); |
| 10163 listener.assertNoErrors(); | 10163 listener.assertNoErrors(); |
| 10164 expect(directive.libraryKeyword, isNotNull); | 10164 expect(directive.libraryKeyword, isNotNull); |
| 10165 expect(directive.name, isNotNull); | 10165 expect(directive.name, isNotNull); |
| (...skipping 2900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13066 expect(declarationList.variables, hasLength(1)); | 13066 expect(declarationList.variables, hasLength(1)); |
| 13067 } | 13067 } |
| 13068 | 13068 |
| 13069 void test_parseVariableDeclarationListAfterMetadata_final_typeComment() { | 13069 void test_parseVariableDeclarationListAfterMetadata_final_typeComment() { |
| 13070 enableGenericMethodComments = true; | 13070 enableGenericMethodComments = true; |
| 13071 createParser('final/*=T*/ x'); | 13071 createParser('final/*=T*/ x'); |
| 13072 VariableDeclarationList declarationList = parser | 13072 VariableDeclarationList declarationList = parser |
| 13073 .parseVariableDeclarationListAfterMetadata(emptyCommentAndMetadata()); | 13073 .parseVariableDeclarationListAfterMetadata(emptyCommentAndMetadata()); |
| 13074 expectNotNullIfNoErrors(declarationList); | 13074 expectNotNullIfNoErrors(declarationList); |
| 13075 listener.assertNoErrors(); | 13075 listener.assertNoErrors(); |
| 13076 expect((declarationList.type as TypeName).name.name, 'T'); | 13076 expect(declarationList.type.name.name, 'T'); |
| 13077 expect(declarationList.isFinal, true); | 13077 expect(declarationList.isFinal, true); |
| 13078 } | 13078 } |
| 13079 | 13079 |
| 13080 void test_parseVariableDeclarationListAfterMetadata_type_multiple() { | 13080 void test_parseVariableDeclarationListAfterMetadata_type_multiple() { |
| 13081 createParser('A a, b, c'); | 13081 createParser('A a, b, c'); |
| 13082 VariableDeclarationList declarationList = parser | 13082 VariableDeclarationList declarationList = parser |
| 13083 .parseVariableDeclarationListAfterMetadata(emptyCommentAndMetadata()); | 13083 .parseVariableDeclarationListAfterMetadata(emptyCommentAndMetadata()); |
| 13084 expectNotNullIfNoErrors(declarationList); | 13084 expectNotNullIfNoErrors(declarationList); |
| 13085 listener.assertNoErrors(); | 13085 listener.assertNoErrors(); |
| 13086 expect(declarationList.keyword, isNull); | 13086 expect(declarationList.keyword, isNull); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13121 expect(declarationList.variables, hasLength(1)); | 13121 expect(declarationList.variables, hasLength(1)); |
| 13122 } | 13122 } |
| 13123 | 13123 |
| 13124 void test_parseVariableDeclarationListAfterMetadata_var_typeComment() { | 13124 void test_parseVariableDeclarationListAfterMetadata_var_typeComment() { |
| 13125 enableGenericMethodComments = true; | 13125 enableGenericMethodComments = true; |
| 13126 createParser('var/*=T*/ x'); | 13126 createParser('var/*=T*/ x'); |
| 13127 VariableDeclarationList declarationList = parser | 13127 VariableDeclarationList declarationList = parser |
| 13128 .parseVariableDeclarationListAfterMetadata(emptyCommentAndMetadata()); | 13128 .parseVariableDeclarationListAfterMetadata(emptyCommentAndMetadata()); |
| 13129 expectNotNullIfNoErrors(declarationList); | 13129 expectNotNullIfNoErrors(declarationList); |
| 13130 listener.assertNoErrors(); | 13130 listener.assertNoErrors(); |
| 13131 expect((declarationList.type as TypeName).name.name, 'T'); | 13131 expect(declarationList.type.name.name, 'T'); |
| 13132 expect(declarationList.keyword, isNull); | 13132 expect(declarationList.keyword, isNull); |
| 13133 } | 13133 } |
| 13134 | 13134 |
| 13135 void test_parseVariableDeclarationListAfterType_type() { | 13135 void test_parseVariableDeclarationListAfterType_type() { |
| 13136 TypeName type = | 13136 TypeName type = |
| 13137 astFactory.typeName(astFactory.simpleIdentifier(null), null); | 13137 astFactory.typeName(astFactory.simpleIdentifier(null), null); |
| 13138 createParser('a'); | 13138 createParser('a'); |
| 13139 VariableDeclarationList declarationList = | 13139 VariableDeclarationList declarationList = |
| 13140 parser.parseVariableDeclarationListAfterType( | 13140 parser.parseVariableDeclarationListAfterType( |
| 13141 emptyCommentAndMetadata(), null, type); | 13141 emptyCommentAndMetadata(), null, type); |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13461 CompilationUnit _parseDirectives(String source, | 13461 CompilationUnit _parseDirectives(String source, |
| 13462 [List<ErrorCode> errorCodes = const <ErrorCode>[]]) { | 13462 [List<ErrorCode> errorCodes = const <ErrorCode>[]]) { |
| 13463 createParser(source); | 13463 createParser(source); |
| 13464 CompilationUnit unit = parser.parseDirectives2(); | 13464 CompilationUnit unit = parser.parseDirectives2(); |
| 13465 expect(unit, isNotNull); | 13465 expect(unit, isNotNull); |
| 13466 expect(unit.declarations, hasLength(0)); | 13466 expect(unit.declarations, hasLength(0)); |
| 13467 listener.assertErrorsWithCodes(errorCodes); | 13467 listener.assertErrorsWithCodes(errorCodes); |
| 13468 return unit; | 13468 return unit; |
| 13469 } | 13469 } |
| 13470 } | 13470 } |
| OLD | NEW |