Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(322)

Side by Side Diff: pkg/analyzer/test/generated/parser_fasta_test.dart

Issue 2996163002: support class native clause (Closed)
Patch Set: add new fasta native clause error code Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 2909 matching lines...) Expand 10 before | Expand all | Expand 10 after
2926 super.test_parseTryStatement_on_catch_finally(); 2927 super.test_parseTryStatement_on_catch_finally();
2927 } 2928 }
2928 } 2929 }
2929 2930
2930 /** 2931 /**
2931 * Tests of the fasta parser based on [TopLevelParserTestMixin]. 2932 * Tests of the fasta parser based on [TopLevelParserTestMixin].
2932 */ 2933 */
2933 @reflectiveTest 2934 @reflectiveTest
2934 class TopLevelParserTest_Fasta extends FastaParserTestCase 2935 class TopLevelParserTest_Fasta extends FastaParserTestCase
2935 with TopLevelParserTestMixin { 2936 with TopLevelParserTestMixin {
2936 @override 2937 void test_parseClassDeclaration_native_missing_literal() {
2937 @failingTest 2938 createParser('class A native {}');
2938 void test_parseClassDeclaration_native() { 2939 CompilationUnitMember member = parseFullCompilationUnitMember();
2939 // TODO(paulberry): TODO(paulberry,ahe): Fasta parser doesn't appear to supp ort "native" syntax yet. 2940 expect(member, isNotNull);
2940 super.test_parseClassDeclaration_native(); 2941 if (AstBuilder.isNativeClauseAllowed) {
2942 assertNoErrors();
2943 } else {
2944 assertErrorsWithCodes([
2945 ParserErrorCode.NATIVE_CLAUSE_SHOULD_BE_ANNOTATION,
2946 ]);
2947 }
2948 expect(member, new isInstanceOf<ClassDeclaration>());
2949 ClassDeclaration declaration = member;
2950 expect(declaration.nativeClause, isNull);
2951 expect(declaration.endToken.type, TokenType.CLOSE_CURLY_BRACKET);
2952 }
2953
2954 void test_parseClassDeclaration_native_allowed() {
2955 _setNativeAllowed(true, () {
2956 test_parseClassDeclaration_native();
2957 });
2958 }
2959
2960 void test_parseClassDeclaration_native_missing_literal_allowed() {
2961 _setNativeAllowed(true, () {
2962 test_parseClassDeclaration_native_missing_literal();
2963 });
2964 }
2965
2966 void test_parseClassDeclaration_native_missing_literal_not_allowed() {
2967 _setNativeAllowed(false, () {
2968 test_parseClassDeclaration_native_missing_literal();
2969 });
2970 }
2971
2972 void test_parseClassDeclaration_native_not_allowed() {
2973 _setNativeAllowed(false, () {
2974 test_parseClassDeclaration_native();
2975 });
2941 } 2976 }
2942 2977
2943 @override 2978 @override
2944 @failingTest 2979 @failingTest
2945 void test_parseCompilationUnit_builtIn_asFunctionName() { 2980 void test_parseCompilationUnit_builtIn_asFunctionName() {
2946 // TODO(paulberry,ahe): Fasta's parser is confused when one of the built-in 2981 // TODO(paulberry,ahe): Fasta's parser is confused when one of the built-in
2947 // identifiers `export`, `import`, `library`, `part`, or `typedef` appears 2982 // identifiers `export`, `import`, `library`, `part`, or `typedef` appears
2948 // as the name of a top level function with an implicit return type. 2983 // as the name of a top level function with an implicit return type.
2949 super.test_parseCompilationUnit_builtIn_asFunctionName(); 2984 super.test_parseCompilationUnit_builtIn_asFunctionName();
2950 } 2985 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2986 super.test_parseCompilationUnit_typedefAsPrefix(); 3021 super.test_parseCompilationUnit_typedefAsPrefix();
2987 assertNoErrors(); 3022 assertNoErrors();
2988 } 3023 }
2989 3024
2990 @failingTest 3025 @failingTest
2991 void test_parseCompilationUnitMember_abstractAsPrefix2() { 3026 void test_parseCompilationUnitMember_abstractAsPrefix2() {
2992 // TODO(danrubel): should not be generating an error 3027 // TODO(danrubel): should not be generating an error
2993 super.test_parseCompilationUnitMember_abstractAsPrefix(); 3028 super.test_parseCompilationUnitMember_abstractAsPrefix();
2994 assertNoErrors(); 3029 assertNoErrors();
2995 } 3030 }
3031
3032 void _setNativeAllowed(bool isAllowed, Function f) {
3033 bool original = AstBuilder.isNativeClauseAllowed;
3034 AstBuilder.isNativeClauseAllowed = isAllowed;
ahe 2017/08/21 12:04:10 You could make this an instance field on FastaPars
danrubel 2017/08/22 01:35:28 Good point. Revised.
3035 try {
3036 f();
3037 } finally {
3038 AstBuilder.isNativeClauseAllowed = original;
3039 }
3040 }
2996 } 3041 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698