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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 /** | 58 /** |
59 * Get the parser used by the test. | 59 * Get the parser used by the test. |
60 * | 60 * |
61 * Caller must first invoke [createParser]. | 61 * Caller must first invoke [createParser]. |
62 */ | 62 */ |
63 Parser get parser; | 63 Parser get parser; |
64 | 64 |
65 /** | 65 /** |
66 * Flag indicating whether the fasta parser is being used. | 66 * Flag indicating whether the fasta parser is being used. |
67 */ | 67 */ |
68 bool get usingFasta; | 68 bool get usingFastaParser; |
| 69 |
| 70 /** |
| 71 * Flag indicating whether the fasta scanner is being used. |
| 72 */ |
| 73 bool get usingFastaScanner; |
69 | 74 |
70 /** | 75 /** |
71 * Assert that the number and codes of errors occurred during parsing is the | 76 * Assert that the number and codes of errors occurred during parsing is the |
72 * same as the [expectedErrorCodes]. | 77 * same as the [expectedErrorCodes]. |
73 */ | 78 */ |
74 void assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes); | 79 void assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes); |
75 | 80 |
76 /** | 81 /** |
77 * Asserts that no errors occurred during parsing. | 82 * Asserts that no errors occurred during parsing. |
78 */ | 83 */ |
(...skipping 8048 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8127 GatheringErrorListener listener; | 8132 GatheringErrorListener listener; |
8128 | 8133 |
8129 /** | 8134 /** |
8130 * The parser used by the test. | 8135 * The parser used by the test. |
8131 * | 8136 * |
8132 * This field is typically initialized by invoking [createParser]. | 8137 * This field is typically initialized by invoking [createParser]. |
8133 */ | 8138 */ |
8134 Parser parser; | 8139 Parser parser; |
8135 | 8140 |
8136 @override | 8141 @override |
8137 bool get usingFasta => Parser.useFasta; | 8142 bool get usingFastaParser => Parser.useFasta; |
8138 | 8143 |
8139 @override | 8144 @override |
8140 void assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) { | 8145 void assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) { |
8141 listener.assertErrorsWithCodes(expectedErrorCodes); | 8146 listener.assertErrorsWithCodes(expectedErrorCodes); |
8142 } | 8147 } |
8143 | 8148 |
8144 @override | 8149 @override |
8145 void assertNoErrors() { | 8150 void assertNoErrors() { |
8146 listener.assertNoErrors(); | 8151 listener.assertNoErrors(); |
8147 } | 8152 } |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8582 parseFunctionBodies = true; | 8587 parseFunctionBodies = true; |
8583 } | 8588 } |
8584 } | 8589 } |
8585 | 8590 |
8586 /** | 8591 /** |
8587 * Helper methods that aid in parser tests. | 8592 * Helper methods that aid in parser tests. |
8588 * | 8593 * |
8589 * Intended to be mixed in to parser test case classes. | 8594 * Intended to be mixed in to parser test case classes. |
8590 */ | 8595 */ |
8591 class ParserTestHelpers { | 8596 class ParserTestHelpers { |
| 8597 bool get usingFastaScanner => fe.Scanner.useFasta; |
| 8598 |
8592 void expectCommentText(Comment comment, String expectedText) { | 8599 void expectCommentText(Comment comment, String expectedText) { |
8593 expect(comment.beginToken, same(comment.endToken)); | 8600 expect(comment.beginToken, same(comment.endToken)); |
8594 expect(comment.beginToken.lexeme, expectedText); | 8601 expect(comment.beginToken.lexeme, expectedText); |
8595 } | 8602 } |
8596 | 8603 |
8597 void expectDottedName(DottedName name, List<String> expectedComponents) { | 8604 void expectDottedName(DottedName name, List<String> expectedComponents) { |
8598 int count = expectedComponents.length; | 8605 int count = expectedComponents.length; |
8599 NodeList<SimpleIdentifier> components = name.components; | 8606 NodeList<SimpleIdentifier> components = name.components; |
8600 expect(components, hasLength(count)); | 8607 expect(components, hasLength(count)); |
8601 for (int i = 0; i < count; i++) { | 8608 for (int i = 0; i < count; i++) { |
(...skipping 5057 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13659 } | 13666 } |
13660 | 13667 |
13661 void test_parseClassTypeAlias_withDocumentationComment() { | 13668 void test_parseClassTypeAlias_withDocumentationComment() { |
13662 createParser('/// Doc\nclass C = D with E;'); | 13669 createParser('/// Doc\nclass C = D with E;'); |
13663 var classTypeAlias = parseFullCompilationUnitMember() as ClassTypeAlias; | 13670 var classTypeAlias = parseFullCompilationUnitMember() as ClassTypeAlias; |
13664 expectCommentText(classTypeAlias.documentationComment, '/// Doc'); | 13671 expectCommentText(classTypeAlias.documentationComment, '/// Doc'); |
13665 } | 13672 } |
13666 | 13673 |
13667 void test_parseCompilationUnit_abstractAsPrefix_parameterized() { | 13674 void test_parseCompilationUnit_abstractAsPrefix_parameterized() { |
13668 var errorCodes = <ErrorCode>[]; | 13675 var errorCodes = <ErrorCode>[]; |
13669 if (usingFasta) { | 13676 if (usingFastaParser) { |
13670 // built-in "abstract" cannot be used as a type | 13677 // built-in "abstract" cannot be used as a type |
13671 errorCodes.add(ParserErrorCode.EXPECTED_TYPE_NAME); | 13678 errorCodes.add(ParserErrorCode.EXPECTED_TYPE_NAME); |
13672 } | 13679 } |
13673 CompilationUnit unit = parseCompilationUnit( | 13680 CompilationUnit unit = parseCompilationUnit( |
13674 'abstract<dynamic> _abstract = new abstract.A();', errorCodes); | 13681 'abstract<dynamic> _abstract = new abstract.A();', errorCodes); |
13675 expect(unit.scriptTag, isNull); | 13682 expect(unit.scriptTag, isNull); |
13676 expect(unit.directives, hasLength(0)); | 13683 expect(unit.directives, hasLength(0)); |
13677 expect(unit.declarations, hasLength(1)); | 13684 expect(unit.declarations, hasLength(1)); |
13678 } | 13685 } |
13679 | 13686 |
(...skipping 1481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15161 expectCommentText(typeVariable.documentationComment, '/// Doc'); | 15168 expectCommentText(typeVariable.documentationComment, '/// Doc'); |
15162 } | 15169 } |
15163 | 15170 |
15164 /** | 15171 /** |
15165 * Assert that the given [name] is in declaration context. | 15172 * Assert that the given [name] is in declaration context. |
15166 */ | 15173 */ |
15167 void _assertIsDeclarationName(SimpleIdentifier name) { | 15174 void _assertIsDeclarationName(SimpleIdentifier name) { |
15168 expect(name.inDeclarationContext(), isTrue); | 15175 expect(name.inDeclarationContext(), isTrue); |
15169 } | 15176 } |
15170 } | 15177 } |
OLD | NEW |