| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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/token.dart' as analyzer; | 6 import 'package:analyzer/dart/ast/token.dart' as analyzer; |
| 7 import 'package:analyzer/dart/ast/token.dart' show TokenType; |
| 7 import 'package:analyzer/error/error.dart'; | 8 import 'package:analyzer/error/error.dart'; |
| 8 import 'package:analyzer/error/listener.dart' show ErrorReporter; | 9 import 'package:analyzer/error/listener.dart' show ErrorReporter; |
| 9 import 'package:analyzer/src/dart/scanner/scanner.dart'; | 10 import 'package:analyzer/src/dart/scanner/scanner.dart'; |
| 10 import 'package:analyzer/src/fasta/ast_builder.dart'; | 11 import 'package:analyzer/src/fasta/ast_builder.dart'; |
| 11 import 'package:analyzer/src/generated/parser.dart' as analyzer; | 12 import 'package:analyzer/src/generated/parser.dart' as analyzer; |
| 12 import 'package:analyzer/src/generated/utilities_dart.dart'; | 13 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 13 import 'package:analyzer/src/string_source.dart'; | 14 import 'package:analyzer/src/string_source.dart'; |
| 14 import 'package:front_end/src/fasta/fasta_codes.dart' show Message; | 15 import 'package:front_end/src/fasta/fasta_codes.dart' show Message; |
| 15 import 'package:front_end/src/fasta/kernel/kernel_builder.dart'; | 16 import 'package:front_end/src/fasta/kernel/kernel_builder.dart'; |
| 16 import 'package:front_end/src/fasta/kernel/kernel_library_builder.dart'; | 17 import 'package:front_end/src/fasta/kernel/kernel_library_builder.dart'; |
| (...skipping 2190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2207 * Implementation of [AbstractParserTestCase] specialized for testing the | 2208 * Implementation of [AbstractParserTestCase] specialized for testing the |
| 2208 * Fasta parser. | 2209 * Fasta parser. |
| 2209 */ | 2210 */ |
| 2210 class FastaParserTestCase extends Object | 2211 class FastaParserTestCase extends Object |
| 2211 with ParserTestHelpers | 2212 with ParserTestHelpers |
| 2212 implements AbstractParserTestCase { | 2213 implements AbstractParserTestCase { |
| 2213 ParserProxy _parserProxy; | 2214 ParserProxy _parserProxy; |
| 2214 analyzer.Token _fastaTokens; | 2215 analyzer.Token _fastaTokens; |
| 2215 | 2216 |
| 2216 @override | 2217 @override |
| 2218 bool allowNativeClause = false; |
| 2219 |
| 2220 @override |
| 2217 GatheringErrorListener get listener => _parserProxy._errorListener; | 2221 GatheringErrorListener get listener => _parserProxy._errorListener; |
| 2218 | 2222 |
| 2219 /** | 2223 /** |
| 2220 * Whether generic method comments should be enabled for the test. | 2224 * Whether generic method comments should be enabled for the test. |
| 2221 */ | 2225 */ |
| 2222 bool enableGenericMethodComments = false; | 2226 bool enableGenericMethodComments = false; |
| 2223 | 2227 |
| 2224 @override | 2228 @override |
| 2225 set enableAssertInitializer(bool value) { | 2229 set enableAssertInitializer(bool value) { |
| 2226 if (value == true) { | 2230 if (value == true) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2270 void assertNoErrors() { | 2274 void assertNoErrors() { |
| 2271 _parserProxy._errorListener.assertNoErrors(); | 2275 _parserProxy._errorListener.assertNoErrors(); |
| 2272 } | 2276 } |
| 2273 | 2277 |
| 2274 @override | 2278 @override |
| 2275 void createParser(String content) { | 2279 void createParser(String content) { |
| 2276 var scanner = new StringScanner(content, includeComments: true); | 2280 var scanner = new StringScanner(content, includeComments: true); |
| 2277 scanner.scanGenericMethodComments = enableGenericMethodComments; | 2281 scanner.scanGenericMethodComments = enableGenericMethodComments; |
| 2278 _fastaTokens = scanner.tokenize(); | 2282 _fastaTokens = scanner.tokenize(); |
| 2279 _parserProxy = new ParserProxy(_fastaTokens, | 2283 _parserProxy = new ParserProxy(_fastaTokens, |
| 2284 allowNativeClause: allowNativeClause, |
| 2280 enableGenericMethodComments: enableGenericMethodComments); | 2285 enableGenericMethodComments: enableGenericMethodComments); |
| 2281 } | 2286 } |
| 2282 | 2287 |
| 2283 @override | 2288 @override |
| 2284 void expectNotNullIfNoErrors(Object result) { | 2289 void expectNotNullIfNoErrors(Object result) { |
| 2285 if (!listener.hasErrors) { | 2290 if (!listener.hasErrors) { |
| 2286 expect(result, isNotNull); | 2291 expect(result, isNotNull); |
| 2287 } | 2292 } |
| 2288 } | 2293 } |
| 2289 | 2294 |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2766 */ | 2771 */ |
| 2767 final GatheringErrorListener _errorListener; | 2772 final GatheringErrorListener _errorListener; |
| 2768 | 2773 |
| 2769 final ForwardingTestListener _eventListener; | 2774 final ForwardingTestListener _eventListener; |
| 2770 | 2775 |
| 2771 /** | 2776 /** |
| 2772 * Creates a [ParserProxy] which is prepared to begin parsing at the given | 2777 * Creates a [ParserProxy] which is prepared to begin parsing at the given |
| 2773 * Fasta token. | 2778 * Fasta token. |
| 2774 */ | 2779 */ |
| 2775 factory ParserProxy(analyzer.Token startingToken, | 2780 factory ParserProxy(analyzer.Token startingToken, |
| 2776 {bool enableGenericMethodComments: false}) { | 2781 {bool allowNativeClause: false, |
| 2782 bool enableGenericMethodComments: false}) { |
| 2777 var library = new KernelLibraryBuilderProxy(); | 2783 var library = new KernelLibraryBuilderProxy(); |
| 2778 var member = new BuilderProxy(); | 2784 var member = new BuilderProxy(); |
| 2779 var scope = new ScopeProxy(); | 2785 var scope = new ScopeProxy(); |
| 2780 TestSource source = new TestSource(); | 2786 TestSource source = new TestSource(); |
| 2781 var errorListener = new GatheringErrorListener(); | 2787 var errorListener = new GatheringErrorListener(); |
| 2782 var errorReporter = new ErrorReporter(errorListener, source); | 2788 var errorReporter = new ErrorReporter(errorListener, source); |
| 2783 var astBuilder = | 2789 var astBuilder = |
| 2784 new AstBuilder(errorReporter, library, member, scope, true); | 2790 new AstBuilder(errorReporter, library, member, scope, true); |
| 2791 astBuilder.allowNativeClause = allowNativeClause; |
| 2785 astBuilder.parseGenericMethodComments = enableGenericMethodComments; | 2792 astBuilder.parseGenericMethodComments = enableGenericMethodComments; |
| 2786 var eventListener = new ForwardingTestListener(astBuilder); | 2793 var eventListener = new ForwardingTestListener(astBuilder); |
| 2787 var fastaParser = new fasta.Parser(eventListener); | 2794 var fastaParser = new fasta.Parser(eventListener); |
| 2788 astBuilder.parser = fastaParser; | 2795 astBuilder.parser = fastaParser; |
| 2789 return new ParserProxy._( | 2796 return new ParserProxy._( |
| 2790 startingToken, fastaParser, astBuilder, errorListener, eventListener); | 2797 startingToken, fastaParser, astBuilder, errorListener, eventListener); |
| 2791 } | 2798 } |
| 2792 | 2799 |
| 2793 ParserProxy._(this._currentFastaToken, this._fastaParser, this._astBuilder, | 2800 ParserProxy._(this._currentFastaToken, this._fastaParser, this._astBuilder, |
| 2794 this._errorListener, this._eventListener); | 2801 this._errorListener, this._eventListener); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2926 super.test_parseTryStatement_on_catch_finally(); | 2933 super.test_parseTryStatement_on_catch_finally(); |
| 2927 } | 2934 } |
| 2928 } | 2935 } |
| 2929 | 2936 |
| 2930 /** | 2937 /** |
| 2931 * Tests of the fasta parser based on [TopLevelParserTestMixin]. | 2938 * Tests of the fasta parser based on [TopLevelParserTestMixin]. |
| 2932 */ | 2939 */ |
| 2933 @reflectiveTest | 2940 @reflectiveTest |
| 2934 class TopLevelParserTest_Fasta extends FastaParserTestCase | 2941 class TopLevelParserTest_Fasta extends FastaParserTestCase |
| 2935 with TopLevelParserTestMixin { | 2942 with TopLevelParserTestMixin { |
| 2936 @override | 2943 void test_parseClassDeclaration_native_missing_literal() { |
| 2937 @failingTest | 2944 createParser('class A native {}'); |
| 2938 void test_parseClassDeclaration_native() { | 2945 CompilationUnitMember member = parseFullCompilationUnitMember(); |
| 2939 // TODO(paulberry): TODO(paulberry,ahe): Fasta parser doesn't appear to supp
ort "native" syntax yet. | 2946 expect(member, isNotNull); |
| 2940 super.test_parseClassDeclaration_native(); | 2947 if (allowNativeClause) { |
| 2948 assertNoErrors(); |
| 2949 } else { |
| 2950 assertErrorsWithCodes([ |
| 2951 ParserErrorCode.NATIVE_CLAUSE_SHOULD_BE_ANNOTATION, |
| 2952 ]); |
| 2953 } |
| 2954 expect(member, new isInstanceOf<ClassDeclaration>()); |
| 2955 ClassDeclaration declaration = member; |
| 2956 expect(declaration.nativeClause, isNotNull); |
| 2957 expect(declaration.nativeClause.nativeKeyword, isNotNull); |
| 2958 expect(declaration.nativeClause.name, isNull); |
| 2959 expect(declaration.endToken.type, TokenType.CLOSE_CURLY_BRACKET); |
| 2960 } |
| 2961 |
| 2962 void test_parseClassDeclaration_native_allowed() { |
| 2963 allowNativeClause = true; |
| 2964 test_parseClassDeclaration_native(); |
| 2965 } |
| 2966 |
| 2967 void test_parseClassDeclaration_native_missing_literal_allowed() { |
| 2968 allowNativeClause = true; |
| 2969 test_parseClassDeclaration_native_missing_literal(); |
| 2970 } |
| 2971 |
| 2972 void test_parseClassDeclaration_native_missing_literal_not_allowed() { |
| 2973 allowNativeClause = false; |
| 2974 test_parseClassDeclaration_native_missing_literal(); |
| 2975 } |
| 2976 |
| 2977 void test_parseClassDeclaration_native_not_allowed() { |
| 2978 allowNativeClause = false; |
| 2979 test_parseClassDeclaration_native(); |
| 2941 } | 2980 } |
| 2942 | 2981 |
| 2943 @override | 2982 @override |
| 2944 @failingTest | 2983 @failingTest |
| 2945 void test_parseCompilationUnit_builtIn_asFunctionName() { | 2984 void test_parseCompilationUnit_builtIn_asFunctionName() { |
| 2946 // TODO(paulberry,ahe): Fasta's parser is confused when one of the built-in | 2985 // TODO(paulberry,ahe): Fasta's parser is confused when one of the built-in |
| 2947 // identifiers `export`, `import`, `library`, `part`, or `typedef` appears | 2986 // identifiers `export`, `import`, `library`, `part`, or `typedef` appears |
| 2948 // as the name of a top level function with an implicit return type. | 2987 // as the name of a top level function with an implicit return type. |
| 2949 super.test_parseCompilationUnit_builtIn_asFunctionName(); | 2988 super.test_parseCompilationUnit_builtIn_asFunctionName(); |
| 2950 } | 2989 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2987 assertNoErrors(); | 3026 assertNoErrors(); |
| 2988 } | 3027 } |
| 2989 | 3028 |
| 2990 @failingTest | 3029 @failingTest |
| 2991 void test_parseCompilationUnitMember_abstractAsPrefix2() { | 3030 void test_parseCompilationUnitMember_abstractAsPrefix2() { |
| 2992 // TODO(danrubel): should not be generating an error | 3031 // TODO(danrubel): should not be generating an error |
| 2993 super.test_parseCompilationUnitMember_abstractAsPrefix(); | 3032 super.test_parseCompilationUnitMember_abstractAsPrefix(); |
| 2994 assertNoErrors(); | 3033 assertNoErrors(); |
| 2995 } | 3034 } |
| 2996 } | 3035 } |
| OLD | NEW |