| 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 import 'package:analyzer/dart/ast/ast.dart'; | 5 import 'package:analyzer/dart/ast/ast.dart'; |
| 6 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; | 6 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; |
| 7 import 'package:analyzer/dart/ast/token.dart'; | 7 import 'package:analyzer/dart/ast/token.dart'; |
| 8 import 'package:analyzer/dart/ast/visitor.dart'; | 8 import 'package:analyzer/dart/ast/visitor.dart'; |
| 9 import 'package:analyzer/error/error.dart'; | 9 import 'package:analyzer/error/error.dart'; |
| 10 import 'package:analyzer/error/listener.dart'; | 10 import 'package:analyzer/error/listener.dart'; |
| (...skipping 1279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1290 ConstructorDeclaration constructor = member as ConstructorDeclaration; | 1290 ConstructorDeclaration constructor = member as ConstructorDeclaration; |
| 1291 NodeList<ConstructorInitializer> initializers = constructor.initializers; | 1291 NodeList<ConstructorInitializer> initializers = constructor.initializers; |
| 1292 expect(initializers, hasLength(3)); | 1292 expect(initializers, hasLength(3)); |
| 1293 ConstructorInitializer initializer = initializers[1]; | 1293 ConstructorInitializer initializer = initializers[1]; |
| 1294 expect(initializer, new isInstanceOf<AssertInitializer>()); | 1294 expect(initializer, new isInstanceOf<AssertInitializer>()); |
| 1295 AssertInitializer assertInitializer = initializer; | 1295 AssertInitializer assertInitializer = initializer; |
| 1296 expect(assertInitializer.condition, isNotNull); | 1296 expect(assertInitializer.condition, isNotNull); |
| 1297 expect(assertInitializer.message, isNull); | 1297 expect(assertInitializer.message, isNull); |
| 1298 } | 1298 } |
| 1299 | 1299 |
| 1300 void test_parseConstructor_factory_const_external() { |
| 1301 createParser('external const factory C();'); |
| 1302 ClassMember member = parser.parseClassMember('C'); |
| 1303 expectNotNullIfNoErrors(member); |
| 1304 listener.assertNoErrors(); |
| 1305 } |
| 1306 |
| 1300 void test_parseConstructor_factory_named() { | 1307 void test_parseConstructor_factory_named() { |
| 1301 createParser('factory C.foo() => null;'); | 1308 createParser('factory C.foo() => null;'); |
| 1302 var constructor = parser.parseClassMember('C') as ConstructorDeclaration; | 1309 var constructor = parser.parseClassMember('C') as ConstructorDeclaration; |
| 1303 assertNoErrors(); | 1310 assertNoErrors(); |
| 1304 expect(constructor, isNotNull); | 1311 expect(constructor, isNotNull); |
| 1305 expect(constructor.externalKeyword, isNull); | 1312 expect(constructor.externalKeyword, isNull); |
| 1306 expect(constructor.constKeyword, isNull); | 1313 expect(constructor.constKeyword, isNull); |
| 1307 expect(constructor.factoryKeyword, isNotNull); | 1314 expect(constructor.factoryKeyword, isNotNull); |
| 1308 expect(constructor.returnType.name, 'C'); | 1315 expect(constructor.returnType.name, 'C'); |
| 1309 _assertIsDeclarationName(constructor.returnType, false); | 1316 _assertIsDeclarationName(constructor.returnType, false); |
| (...skipping 1341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2651 expect(directive.uri.stringValue, ''); | 2658 expect(directive.uri.stringValue, ''); |
| 2652 expect(directive.uri.beginToken.isSynthetic, false); | 2659 expect(directive.uri.beginToken.isSynthetic, false); |
| 2653 expect(directive.uri.isSynthetic, false); | 2660 expect(directive.uri.isSynthetic, false); |
| 2654 Token semicolon = directive.semicolon; | 2661 Token semicolon = directive.semicolon; |
| 2655 expect(semicolon, isNotNull); | 2662 expect(semicolon, isNotNull); |
| 2656 expect(semicolon.isSynthetic, isTrue); | 2663 expect(semicolon.isSynthetic, isTrue); |
| 2657 ClassDeclaration clazz = unit.declarations[0] as ClassDeclaration; | 2664 ClassDeclaration clazz = unit.declarations[0] as ClassDeclaration; |
| 2658 expect(clazz.name.name, 'A'); | 2665 expect(clazz.name.name, 'A'); |
| 2659 } | 2666 } |
| 2660 | 2667 |
| 2668 void test_expectedToken_semicolonMissingAfterExpression() { |
| 2669 parseStatement("x"); |
| 2670 assertErrorsWithCodes([ParserErrorCode.EXPECTED_TOKEN]); |
| 2671 } |
| 2672 |
| 2673 void test_expectedToken_semicolonMissingAfterImport() { |
| 2674 CompilationUnit unit = parseCompilationUnit( |
| 2675 "import '' class A {}", [ParserErrorCode.EXPECTED_TOKEN]); |
| 2676 ImportDirective directive = unit.directives[0] as ImportDirective; |
| 2677 Token semicolon = directive.semicolon; |
| 2678 expect(semicolon, isNotNull); |
| 2679 expect(semicolon.isSynthetic, isTrue); |
| 2680 } |
| 2681 |
| 2661 void test_expectedToken_uriAndSemicolonMissingAfterExport() { | 2682 void test_expectedToken_uriAndSemicolonMissingAfterExport() { |
| 2662 CompilationUnit unit = parseCompilationUnit("export class A {}", [ | 2683 CompilationUnit unit = parseCompilationUnit("export class A {}", [ |
| 2663 ParserErrorCode.EXPECTED_STRING_LITERAL, | 2684 ParserErrorCode.EXPECTED_STRING_LITERAL, |
| 2664 ParserErrorCode.EXPECTED_TOKEN, | 2685 ParserErrorCode.EXPECTED_TOKEN, |
| 2665 ]); | 2686 ]); |
| 2666 ExportDirective directive = unit.directives[0] as ExportDirective; | 2687 ExportDirective directive = unit.directives[0] as ExportDirective; |
| 2667 expect(directive.uri, isNotNull); | 2688 expect(directive.uri, isNotNull); |
| 2668 expect(directive.uri.stringValue, ''); | 2689 expect(directive.uri.stringValue, ''); |
| 2669 expect(directive.uri.beginToken.isSynthetic, true); | 2690 expect(directive.uri.beginToken.isSynthetic, true); |
| 2670 expect(directive.uri.isSynthetic, true); | 2691 expect(directive.uri.isSynthetic, true); |
| 2671 Token semicolon = directive.semicolon; | 2692 Token semicolon = directive.semicolon; |
| 2672 expect(semicolon, isNotNull); | 2693 expect(semicolon, isNotNull); |
| 2673 expect(semicolon.isSynthetic, isTrue); | 2694 expect(semicolon.isSynthetic, isTrue); |
| 2674 ClassDeclaration clazz = unit.declarations[0] as ClassDeclaration; | 2695 ClassDeclaration clazz = unit.declarations[0] as ClassDeclaration; |
| 2675 expect(clazz.name.name, 'A'); | 2696 expect(clazz.name.name, 'A'); |
| 2676 } | 2697 } |
| 2677 | 2698 |
| 2678 void test_expectedToken_semicolonMissingAfterExpression() { | |
| 2679 parseStatement("x"); | |
| 2680 assertErrorsWithCodes([ParserErrorCode.EXPECTED_TOKEN]); | |
| 2681 } | |
| 2682 | |
| 2683 void test_expectedToken_semicolonMissingAfterImport() { | |
| 2684 CompilationUnit unit = parseCompilationUnit( | |
| 2685 "import '' class A {}", [ParserErrorCode.EXPECTED_TOKEN]); | |
| 2686 ImportDirective directive = unit.directives[0] as ImportDirective; | |
| 2687 Token semicolon = directive.semicolon; | |
| 2688 expect(semicolon, isNotNull); | |
| 2689 expect(semicolon.isSynthetic, isTrue); | |
| 2690 } | |
| 2691 | |
| 2692 void test_expectedToken_whileMissingInDoStatement() { | 2699 void test_expectedToken_whileMissingInDoStatement() { |
| 2693 parseStatement("do {} (x);"); | 2700 parseStatement("do {} (x);"); |
| 2694 assertErrorsWithCodes([ParserErrorCode.EXPECTED_TOKEN]); | 2701 assertErrorsWithCodes([ParserErrorCode.EXPECTED_TOKEN]); |
| 2695 } | 2702 } |
| 2696 | 2703 |
| 2697 void test_expectedTypeName_as() { | 2704 void test_expectedTypeName_as() { |
| 2698 parseExpression("x as", [ParserErrorCode.EXPECTED_TYPE_NAME]); | 2705 parseExpression("x as", [ParserErrorCode.EXPECTED_TYPE_NAME]); |
| 2699 } | 2706 } |
| 2700 | 2707 |
| 2701 void test_expectedTypeName_as_void() { | 2708 void test_expectedTypeName_as_void() { |
| (...skipping 5568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8270 expect(parameter, new isInstanceOf<SimpleFormalParameter>()); | 8277 expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| 8271 SimpleFormalParameter simpleParameter = parameter; | 8278 SimpleFormalParameter simpleParameter = parameter; |
| 8272 expect(simpleParameter.keyword, isNull); | 8279 expect(simpleParameter.keyword, isNull); |
| 8273 expect(simpleParameter.type, isNotNull); | 8280 expect(simpleParameter.type, isNotNull); |
| 8274 expect(simpleParameter.identifier, isNotNull); | 8281 expect(simpleParameter.identifier, isNotNull); |
| 8275 } | 8282 } |
| 8276 } | 8283 } |
| 8277 | 8284 |
| 8278 @reflectiveTest | 8285 @reflectiveTest |
| 8279 class NonErrorParserTest extends ParserTestCase { | 8286 class NonErrorParserTest extends ParserTestCase { |
| 8280 void test_constFactory_external() { | |
| 8281 createParser('external const factory C();'); | |
| 8282 ClassMember member = parser.parseClassMember('C'); | |
| 8283 expectNotNullIfNoErrors(member); | |
| 8284 listener.assertNoErrors(); | |
| 8285 } | |
| 8286 | |
| 8287 void test_staticMethod_notParsingFunctionBodies() { | 8287 void test_staticMethod_notParsingFunctionBodies() { |
| 8288 ParserTestCase.parseFunctionBodies = false; | 8288 ParserTestCase.parseFunctionBodies = false; |
| 8289 try { | 8289 try { |
| 8290 createParser('class C { static void m() {} }'); | 8290 createParser('class C { static void m() {} }'); |
| 8291 CompilationUnit unit = parser.parseCompilationUnit2(); | 8291 CompilationUnit unit = parser.parseCompilationUnit2(); |
| 8292 expectNotNullIfNoErrors(unit); | 8292 expectNotNullIfNoErrors(unit); |
| 8293 listener.assertNoErrors(); | 8293 listener.assertNoErrors(); |
| 8294 } finally { | 8294 } finally { |
| 8295 ParserTestCase.parseFunctionBodies = true; | 8295 ParserTestCase.parseFunctionBodies = true; |
| 8296 } | 8296 } |
| (...skipping 7170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15467 expectCommentText(typeVariable.documentationComment, '/// Doc'); | 15467 expectCommentText(typeVariable.documentationComment, '/// Doc'); |
| 15468 } | 15468 } |
| 15469 | 15469 |
| 15470 /** | 15470 /** |
| 15471 * Assert that the given [name] is in declaration context. | 15471 * Assert that the given [name] is in declaration context. |
| 15472 */ | 15472 */ |
| 15473 void _assertIsDeclarationName(SimpleIdentifier name) { | 15473 void _assertIsDeclarationName(SimpleIdentifier name) { |
| 15474 expect(name.inDeclarationContext(), isTrue); | 15474 expect(name.inDeclarationContext(), isTrue); |
| 15475 } | 15475 } |
| 15476 } | 15476 } |
| OLD | NEW |