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

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

Issue 2930453002: update analyzer parser tests for fasta scanner (Closed)
Patch Set: add docs for the === token Created 3 years, 6 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
« no previous file with comments | « pkg/analyzer/lib/src/generated/parser.dart ('k') | pkg/front_end/lib/src/scanner/token.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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';
11 import 'package:analyzer/src/dart/ast/token.dart'; 11 import 'package:analyzer/src/dart/ast/token.dart';
12 import 'package:analyzer/src/dart/scanner/reader.dart'; 12 import 'package:analyzer/src/dart/scanner/reader.dart';
13 import 'package:analyzer/src/dart/scanner/scanner.dart'; 13 import 'package:analyzer/src/dart/scanner/scanner.dart';
14 import 'package:analyzer/src/generated/parser.dart'; 14 import 'package:analyzer/src/generated/parser.dart';
15 import 'package:analyzer/src/generated/source.dart'; 15 import 'package:analyzer/src/generated/source.dart';
16 import 'package:analyzer/src/generated/testing/token_factory.dart'; 16 import 'package:analyzer/src/generated/testing/token_factory.dart';
17 import 'package:analyzer/src/generated/utilities_dart.dart'; 17 import 'package:analyzer/src/generated/utilities_dart.dart';
18 import 'package:front_end/src/scanner/scanner.dart' as fe;
18 import 'package:test/test.dart'; 19 import 'package:test/test.dart';
19 import 'package:test_reflective_loader/test_reflective_loader.dart'; 20 import 'package:test_reflective_loader/test_reflective_loader.dart';
20 21
21 import 'test_support.dart'; 22 import 'test_support.dart';
22 23
23 main() { 24 main() {
24 defineReflectiveSuite(() { 25 defineReflectiveSuite(() {
25 defineReflectiveTests(ClassMemberParserTest); 26 defineReflectiveTests(ClassMemberParserTest);
26 defineReflectiveTests(ComplexParserTest); 27 defineReflectiveTests(ComplexParserTest);
27 defineReflectiveTests(ErrorParserTest); 28 defineReflectiveTests(ErrorParserTest);
(...skipping 2487 matching lines...) Expand 10 before | Expand all | Expand 10 after
2515 CompilationUnitMember member = parseFullCompilationUnitMember(); 2516 CompilationUnitMember member = parseFullCompilationUnitMember();
2516 expectNotNullIfNoErrors(member); 2517 expectNotNullIfNoErrors(member);
2517 listener.assertErrors( 2518 listener.assertErrors(
2518 [new AnalysisError(null, 0, 1, ParserErrorCode.EXPECTED_EXECUTABLE)]); 2519 [new AnalysisError(null, 0, 1, ParserErrorCode.EXPECTED_EXECUTABLE)]);
2519 } 2520 }
2520 2521
2521 void test_expectedInterpolationIdentifier() { 2522 void test_expectedInterpolationIdentifier() {
2522 createParser("'\$x\$'"); 2523 createParser("'\$x\$'");
2523 StringLiteral literal = parser.parseStringLiteral(); 2524 StringLiteral literal = parser.parseStringLiteral();
2524 expectNotNullIfNoErrors(literal); 2525 expectNotNullIfNoErrors(literal);
2525 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); 2526 listener.assertErrorsWithCodes([
2527 fe.Scanner.useFasta
2528 ? ScannerErrorCode.MISSING_IDENTIFIER
2529 : ParserErrorCode.MISSING_IDENTIFIER
2530 ]);
2526 } 2531 }
2527 2532
2528 void test_expectedInterpolationIdentifier_emptyString() { 2533 void test_expectedInterpolationIdentifier_emptyString() {
2529 // The scanner inserts an empty string token between the two $'s; we need to 2534 // The scanner inserts an empty string token between the two $'s; we need to
2530 // make sure that the MISSING_IDENTIFIER error that is generated has a 2535 // make sure that the MISSING_IDENTIFIER error that is generated has a
2531 // nonzero width so that it will show up in the editor UI. 2536 // nonzero width so that it will show up in the editor UI.
2532 createParser("'\$\$foo'"); 2537 createParser("'\$\$foo'");
2533 StringLiteral literal = parser.parseStringLiteral(); 2538 StringLiteral literal = parser.parseStringLiteral();
2534 expectNotNullIfNoErrors(literal); 2539 expectNotNullIfNoErrors(literal);
2535 listener.assertErrors( 2540 listener.assertErrors(fe.Scanner.useFasta
2536 [new AnalysisError(null, 2, 1, ParserErrorCode.MISSING_IDENTIFIER)]); 2541 ? [new AnalysisError(null, 2, 1, ScannerErrorCode.MISSING_IDENTIFIER)]
2542 : [new AnalysisError(null, 2, 1, ParserErrorCode.MISSING_IDENTIFIER)]);
2537 } 2543 }
2538 2544
2539 @failingTest 2545 @failingTest
2540 void test_expectedListOrMapLiteral() { 2546 void test_expectedListOrMapLiteral() {
2541 // It isn't clear that this test can ever pass. The parser is currently 2547 // It isn't clear that this test can ever pass. The parser is currently
2542 // create a synthetic list literal in this case, but isSynthetic() isn't 2548 // create a synthetic list literal in this case, but isSynthetic() isn't
2543 // overridden for ListLiteral. The problem is that the synthetic list 2549 // overridden for ListLiteral. The problem is that the synthetic list
2544 // literals that are being created are not always zero length (because they 2550 // literals that are being created are not always zero length (because they
2545 // could have type parameters), which violates the contract of 2551 // could have type parameters), which violates the contract of
2546 // isSynthetic(). 2552 // isSynthetic().
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
2854 "void f(const x()) {}", [ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR]); 2860 "void f(const x()) {}", [ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR]);
2855 } 2861 }
2856 2862
2857 void test_functionTypedParameter_final() { 2863 void test_functionTypedParameter_final() {
2858 parseCompilationUnit( 2864 parseCompilationUnit(
2859 "void f(final x()) {}", [ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR]); 2865 "void f(final x()) {}", [ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR]);
2860 } 2866 }
2861 2867
2862 void test_functionTypedParameter_incomplete1() { 2868 void test_functionTypedParameter_incomplete1() {
2863 // This caused an exception at one point. 2869 // This caused an exception at one point.
2864 parseCompilationUnit("void f(int Function(", [ 2870 parseCompilationUnit(
2865 ParserErrorCode.MISSING_FUNCTION_BODY, 2871 "void f(int Function(",
2866 ParserErrorCode.MISSING_CLOSING_PARENTHESIS, 2872 fe.Scanner.useFasta
2867 ParserErrorCode.EXPECTED_EXECUTABLE, 2873 ? [
2868 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE, 2874 ScannerErrorCode.EXPECTED_TOKEN,
2869 ParserErrorCode.EXPECTED_TOKEN, 2875 ScannerErrorCode.EXPECTED_TOKEN,
2870 ParserErrorCode.EXPECTED_TOKEN 2876 ParserErrorCode.MISSING_FUNCTION_BODY,
2871 ]); 2877 ParserErrorCode.MISSING_IDENTIFIER,
2878 ]
2879 : [
2880 ParserErrorCode.MISSING_FUNCTION_BODY,
2881 ParserErrorCode.MISSING_CLOSING_PARENTHESIS,
2882 ParserErrorCode.EXPECTED_EXECUTABLE,
2883 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE,
2884 ParserErrorCode.EXPECTED_TOKEN,
2885 ParserErrorCode.EXPECTED_TOKEN
2886 ]);
2872 } 2887 }
2873 2888
2874 void test_functionTypedParameter_var() { 2889 void test_functionTypedParameter_var() {
2875 parseCompilationUnit( 2890 parseCompilationUnit(
2876 "void f(var x()) {}", [ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR]); 2891 "void f(var x()) {}", [ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR]);
2877 } 2892 }
2878 2893
2879 void test_getterInFunction_block_noReturnType() { 2894 void test_getterInFunction_block_noReturnType() {
2880 FunctionDeclarationStatement statement = 2895 FunctionDeclarationStatement statement =
2881 parseStatement("get x { return _x; }"); 2896 parseStatement("get x { return _x; }");
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
3034 createParser("'\\x0'"); 3049 createParser("'\\x0'");
3035 StringLiteral literal = parser.parseStringLiteral(); 3050 StringLiteral literal = parser.parseStringLiteral();
3036 expectNotNullIfNoErrors(literal); 3051 expectNotNullIfNoErrors(literal);
3037 listener.assertErrorsWithCodes([ParserErrorCode.INVALID_HEX_ESCAPE]); 3052 listener.assertErrorsWithCodes([ParserErrorCode.INVALID_HEX_ESCAPE]);
3038 } 3053 }
3039 3054
3040 void test_invalidInterpolationIdentifier_startWithDigit() { 3055 void test_invalidInterpolationIdentifier_startWithDigit() {
3041 createParser("'\$1'"); 3056 createParser("'\$1'");
3042 StringLiteral literal = parser.parseStringLiteral(); 3057 StringLiteral literal = parser.parseStringLiteral();
3043 expectNotNullIfNoErrors(literal); 3058 expectNotNullIfNoErrors(literal);
3044 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); 3059 listener.assertErrorsWithCodes([
3060 fe.Scanner.useFasta
3061 ? ScannerErrorCode.MISSING_IDENTIFIER
3062 : ParserErrorCode.MISSING_IDENTIFIER
3063 ]);
3045 } 3064 }
3046 3065
3047 void test_invalidLiteralInConfiguration() { 3066 void test_invalidLiteralInConfiguration() {
3048 createParser("if (a == 'x \$y z') 'a.dart'"); 3067 createParser("if (a == 'x \$y z') 'a.dart'");
3049 Configuration configuration = parser.parseConfiguration(); 3068 Configuration configuration = parser.parseConfiguration();
3050 expectNotNullIfNoErrors(configuration); 3069 expectNotNullIfNoErrors(configuration);
3051 listener.assertErrorsWithCodes( 3070 listener.assertErrorsWithCodes(
3052 [ParserErrorCode.INVALID_LITERAL_IN_CONFIGURATION]); 3071 [ParserErrorCode.INVALID_LITERAL_IN_CONFIGURATION]);
3053 } 3072 }
3054 3073
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
3297 } 3316 }
3298 3317
3299 @failingTest 3318 @failingTest
3300 void test_missingClosingParenthesis() { 3319 void test_missingClosingParenthesis() {
3301 // It is possible that it is not possible to generate this error (that it's 3320 // It is possible that it is not possible to generate this error (that it's
3302 // being reported in code that cannot actually be reached), but that hasn't 3321 // being reported in code that cannot actually be reached), but that hasn't
3303 // been proven yet. 3322 // been proven yet.
3304 createParser('(int a, int b ;'); 3323 createParser('(int a, int b ;');
3305 FormalParameterList list = parser.parseFormalParameterList(); 3324 FormalParameterList list = parser.parseFormalParameterList();
3306 expectNotNullIfNoErrors(list); 3325 expectNotNullIfNoErrors(list);
3307 listener 3326 listener.assertErrorsWithCodes([
3308 .assertErrorsWithCodes([ParserErrorCode.MISSING_CLOSING_PARENTHESIS]); 3327 fe.Scanner.useFasta
3328 ? ScannerErrorCode.EXPECTED_TOKEN
3329 : ParserErrorCode.MISSING_CLOSING_PARENTHESIS
3330 ]);
3309 } 3331 }
3310 3332
3311 void test_missingConstFinalVarOrType_static() { 3333 void test_missingConstFinalVarOrType_static() {
3312 parseCompilationUnit("class A { static f; }", 3334 parseCompilationUnit("class A { static f; }",
3313 [ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE]); 3335 [ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE]);
3314 } 3336 }
3315 3337
3316 void test_missingConstFinalVarOrType_topLevel() { 3338 void test_missingConstFinalVarOrType_topLevel() {
3317 createParser('a;'); 3339 createParser('a;');
3318 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); 3340 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false);
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
3571 3593
3572 void test_missingStatement_afterVoid() { 3594 void test_missingStatement_afterVoid() {
3573 parseStatement("void;"); 3595 parseStatement("void;");
3574 assertErrorsWithCodes([ParserErrorCode.MISSING_STATEMENT]); 3596 assertErrorsWithCodes([ParserErrorCode.MISSING_STATEMENT]);
3575 } 3597 }
3576 3598
3577 void test_missingTerminatorForParameterGroup_named() { 3599 void test_missingTerminatorForParameterGroup_named() {
3578 createParser('(a, {b: 0)'); 3600 createParser('(a, {b: 0)');
3579 FormalParameterList list = parser.parseFormalParameterList(); 3601 FormalParameterList list = parser.parseFormalParameterList();
3580 expectNotNullIfNoErrors(list); 3602 expectNotNullIfNoErrors(list);
3581 listener.assertErrorsWithCodes( 3603 listener.assertErrorsWithCodes([
3582 [ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETER_GROUP]); 3604 fe.Scanner.useFasta
3605 ? ScannerErrorCode.EXPECTED_TOKEN
3606 : ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETER_GROUP
3607 ]);
3583 } 3608 }
3584 3609
3585 void test_missingTerminatorForParameterGroup_optional() { 3610 void test_missingTerminatorForParameterGroup_optional() {
3586 createParser('(a, [b = 0)'); 3611 createParser('(a, [b = 0)');
3587 FormalParameterList list = parser.parseFormalParameterList(); 3612 FormalParameterList list = parser.parseFormalParameterList();
3588 expectNotNullIfNoErrors(list); 3613 expectNotNullIfNoErrors(list);
3589 listener.assertErrorsWithCodes( 3614 listener.assertErrorsWithCodes([
3590 [ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETER_GROUP]); 3615 fe.Scanner.useFasta
3616 ? ScannerErrorCode.EXPECTED_TOKEN
3617 : ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETER_GROUP
3618 ]);
3591 } 3619 }
3592 3620
3593 void test_missingTypedefParameters_nonVoid() { 3621 void test_missingTypedefParameters_nonVoid() {
3594 parseCompilationUnit( 3622 parseCompilationUnit(
3595 "typedef int F;", [ParserErrorCode.MISSING_TYPEDEF_PARAMETERS]); 3623 "typedef int F;", [ParserErrorCode.MISSING_TYPEDEF_PARAMETERS]);
3596 } 3624 }
3597 3625
3598 void test_missingTypedefParameters_typeParameters() { 3626 void test_missingTypedefParameters_typeParameters() {
3599 parseCompilationUnit( 3627 parseCompilationUnit(
3600 "typedef F<E>;", [ParserErrorCode.MISSING_TYPEDEF_PARAMETERS]); 3628 "typedef F<E>;", [ParserErrorCode.MISSING_TYPEDEF_PARAMETERS]);
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
3944 "static var x;", [ParserErrorCode.STATIC_TOP_LEVEL_DECLARATION]); 3972 "static var x;", [ParserErrorCode.STATIC_TOP_LEVEL_DECLARATION]);
3945 } 3973 }
3946 3974
3947 void test_string_unterminated_interpolation_block() { 3975 void test_string_unterminated_interpolation_block() {
3948 parseCompilationUnit( 3976 parseCompilationUnit(
3949 r''' 3977 r'''
3950 m() { 3978 m() {
3951 { 3979 {
3952 '${${ 3980 '${${
3953 ''', 3981 ''',
3954 [ 3982 fe.Scanner.useFasta
3955 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 3983 ? [
3956 ParserErrorCode.EXPECTED_TOKEN, 3984 ScannerErrorCode.UNTERMINATED_STRING_LITERAL,
3957 ParserErrorCode.EXPECTED_TOKEN, 3985 ScannerErrorCode.EXPECTED_TOKEN,
3958 ParserErrorCode.EXPECTED_TOKEN, 3986 ScannerErrorCode.EXPECTED_TOKEN,
3959 ParserErrorCode.EXPECTED_TOKEN, 3987 ScannerErrorCode.EXPECTED_TOKEN,
3960 ParserErrorCode.EXPECTED_TOKEN, 3988 ScannerErrorCode.EXPECTED_TOKEN,
3961 ParserErrorCode.EXPECTED_TOKEN, 3989 ParserErrorCode.EXPECTED_TOKEN,
3962 ]); 3990 ParserErrorCode.EXPECTED_TOKEN,
3991 ParserErrorCode.EXPECTED_TOKEN,
3992 ParserErrorCode.UNEXPECTED_TOKEN,
3993 ParserErrorCode.EXPECTED_EXECUTABLE,
3994 ]
3995 : [
3996 ScannerErrorCode.UNTERMINATED_STRING_LITERAL,
3997 ParserErrorCode.EXPECTED_TOKEN,
3998 ParserErrorCode.EXPECTED_TOKEN,
3999 ParserErrorCode.EXPECTED_TOKEN,
4000 ParserErrorCode.EXPECTED_TOKEN,
4001 ParserErrorCode.EXPECTED_TOKEN,
4002 ParserErrorCode.EXPECTED_TOKEN,
4003 ]);
3963 } 4004 }
3964 4005
3965 void test_switchHasCaseAfterDefaultCase() { 4006 void test_switchHasCaseAfterDefaultCase() {
3966 createParser('switch (a) {default: return 0; case 1: return 1;}'); 4007 createParser('switch (a) {default: return 0; case 1: return 1;}');
3967 SwitchStatement statement = parser.parseSwitchStatement(); 4008 SwitchStatement statement = parser.parseSwitchStatement();
3968 expectNotNullIfNoErrors(statement); 4009 expectNotNullIfNoErrors(statement);
3969 listener.assertErrorsWithCodes( 4010 listener.assertErrorsWithCodes(
3970 [ParserErrorCode.SWITCH_HAS_CASE_AFTER_DEFAULT_CASE]); 4011 [ParserErrorCode.SWITCH_HAS_CASE_AFTER_DEFAULT_CASE]);
3971 } 4012 }
3972 4013
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
4076 4117
4077 void test_typedefInClass_withReturnType() { 4118 void test_typedefInClass_withReturnType() {
4078 parseCompilationUnit("class C { typedef int F(int x); }", 4119 parseCompilationUnit("class C { typedef int F(int x); }",
4079 [ParserErrorCode.TYPEDEF_IN_CLASS]); 4120 [ParserErrorCode.TYPEDEF_IN_CLASS]);
4080 } 4121 }
4081 4122
4082 void test_unexpectedTerminatorForParameterGroup_named() { 4123 void test_unexpectedTerminatorForParameterGroup_named() {
4083 createParser('(a, b})'); 4124 createParser('(a, b})');
4084 FormalParameterList list = parser.parseFormalParameterList(); 4125 FormalParameterList list = parser.parseFormalParameterList();
4085 expectNotNullIfNoErrors(list); 4126 expectNotNullIfNoErrors(list);
4086 listener.assertErrorsWithCodes( 4127 listener.assertErrorsWithCodes(fe.Scanner.useFasta
4087 [ParserErrorCode.UNEXPECTED_TERMINATOR_FOR_PARAMETER_GROUP]); 4128 ? [ScannerErrorCode.EXPECTED_TOKEN]
4129 : [ParserErrorCode.UNEXPECTED_TERMINATOR_FOR_PARAMETER_GROUP]);
4088 } 4130 }
4089 4131
4090 void test_unexpectedTerminatorForParameterGroup_optional() { 4132 void test_unexpectedTerminatorForParameterGroup_optional() {
4091 createParser('(a, b])'); 4133 createParser('(a, b])');
4092 FormalParameterList list = parser.parseFormalParameterList(); 4134 FormalParameterList list = parser.parseFormalParameterList();
4093 expectNotNullIfNoErrors(list); 4135 expectNotNullIfNoErrors(list);
4094 listener.assertErrorsWithCodes( 4136 listener.assertErrorsWithCodes(fe.Scanner.useFasta
4095 [ParserErrorCode.UNEXPECTED_TERMINATOR_FOR_PARAMETER_GROUP]); 4137 ? [ScannerErrorCode.EXPECTED_TOKEN]
4138 : [ParserErrorCode.UNEXPECTED_TERMINATOR_FOR_PARAMETER_GROUP]);
4096 } 4139 }
4097 4140
4098 void test_unexpectedToken_endOfFieldDeclarationStatement() { 4141 void test_unexpectedToken_endOfFieldDeclarationStatement() {
4099 parseStatement("String s = (null));"); 4142 parseStatement("String s = (null));");
4100 assertErrorsWithCodes([ParserErrorCode.UNEXPECTED_TOKEN]); 4143 assertErrorsWithCodes([ParserErrorCode.UNEXPECTED_TOKEN]);
4101 } 4144 }
4102 4145
4103 @failingTest 4146 @failingTest
4104 void test_unexpectedToken_invalidPostfixExpression() { 4147 void test_unexpectedToken_invalidPostfixExpression() {
4105 // Note: this might not be the right error to produce, but some error should 4148 // Note: this might not be the right error to produce, but some error should
(...skipping 20 matching lines...) Expand all
4126 void test_unterminatedString_at_eof() { 4169 void test_unterminatedString_at_eof() {
4127 // Although the "unterminated string" error message is produced by the 4170 // Although the "unterminated string" error message is produced by the
4128 // scanner, we need to verify that the parser can handle the tokens 4171 // scanner, we need to verify that the parser can handle the tokens
4129 // produced by the scanner when an unterminated string is encountered. 4172 // produced by the scanner when an unterminated string is encountered.
4130 parseCompilationUnit( 4173 parseCompilationUnit(
4131 r''' 4174 r'''
4132 void main() { 4175 void main() {
4133 var x = "''', 4176 var x = "''',
4134 [ 4177 [
4135 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 4178 ScannerErrorCode.UNTERMINATED_STRING_LITERAL,
4136 ParserErrorCode.EXPECTED_TOKEN, 4179 fe.Scanner.useFasta
4180 ? ScannerErrorCode.EXPECTED_TOKEN
4181 : ParserErrorCode.EXPECTED_TOKEN,
4137 ParserErrorCode.EXPECTED_TOKEN 4182 ParserErrorCode.EXPECTED_TOKEN
4138 ]); 4183 ]);
4139 } 4184 }
4140 4185
4141 void test_unterminatedString_at_eol() { 4186 void test_unterminatedString_at_eol() {
4142 // Although the "unterminated string" error message is produced by the 4187 // Although the "unterminated string" error message is produced by the
4143 // scanner, we need to verify that the parser can handle the tokens 4188 // scanner, we need to verify that the parser can handle the tokens
4144 // produced by the scanner when an unterminated string is encountered. 4189 // produced by the scanner when an unterminated string is encountered.
4145 parseCompilationUnit( 4190 parseCompilationUnit(
4146 r''' 4191 r'''
4147 void main() { 4192 void main() {
4148 var x = " 4193 var x = "
4149 ; 4194 ;
4150 } 4195 }
4151 ''', 4196 ''',
4152 [ScannerErrorCode.UNTERMINATED_STRING_LITERAL]); 4197 [ScannerErrorCode.UNTERMINATED_STRING_LITERAL]);
4153 } 4198 }
4154 4199
4155 void test_unterminatedString_multiline_at_eof_3_quotes() { 4200 void test_unterminatedString_multiline_at_eof_3_quotes() {
4156 // Although the "unterminated string" error message is produced by the 4201 // Although the "unterminated string" error message is produced by the
4157 // scanner, we need to verify that the parser can handle the tokens 4202 // scanner, we need to verify that the parser can handle the tokens
4158 // produced by the scanner when an unterminated string is encountered. 4203 // produced by the scanner when an unterminated string is encountered.
4159 parseCompilationUnit( 4204 parseCompilationUnit(
4160 r''' 4205 r'''
4161 void main() { 4206 void main() {
4162 var x = """''', 4207 var x = """''',
4163 [ 4208 [
4164 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 4209 ScannerErrorCode.UNTERMINATED_STRING_LITERAL,
4165 ParserErrorCode.EXPECTED_TOKEN, 4210 fe.Scanner.useFasta
4211 ? ScannerErrorCode.EXPECTED_TOKEN
4212 : ParserErrorCode.EXPECTED_TOKEN,
4166 ParserErrorCode.EXPECTED_TOKEN 4213 ParserErrorCode.EXPECTED_TOKEN
4167 ]); 4214 ]);
4168 } 4215 }
4169 4216
4170 void test_unterminatedString_multiline_at_eof_4_quotes() { 4217 void test_unterminatedString_multiline_at_eof_4_quotes() {
4171 // Although the "unterminated string" error message is produced by the 4218 // Although the "unterminated string" error message is produced by the
4172 // scanner, we need to verify that the parser can handle the tokens 4219 // scanner, we need to verify that the parser can handle the tokens
4173 // produced by the scanner when an unterminated string is encountered. 4220 // produced by the scanner when an unterminated string is encountered.
4174 parseCompilationUnit( 4221 parseCompilationUnit(
4175 r''' 4222 r'''
4176 void main() { 4223 void main() {
4177 var x = """"''', 4224 var x = """"''',
4178 [ 4225 [
4179 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 4226 ScannerErrorCode.UNTERMINATED_STRING_LITERAL,
4180 ParserErrorCode.EXPECTED_TOKEN, 4227 fe.Scanner.useFasta
4228 ? ScannerErrorCode.EXPECTED_TOKEN
4229 : ParserErrorCode.EXPECTED_TOKEN,
4181 ParserErrorCode.EXPECTED_TOKEN 4230 ParserErrorCode.EXPECTED_TOKEN
4182 ]); 4231 ]);
4183 } 4232 }
4184 4233
4185 void test_unterminatedString_multiline_at_eof_5_quotes() { 4234 void test_unterminatedString_multiline_at_eof_5_quotes() {
4186 // Although the "unterminated string" error message is produced by the 4235 // Although the "unterminated string" error message is produced by the
4187 // scanner, we need to verify that the parser can handle the tokens 4236 // scanner, we need to verify that the parser can handle the tokens
4188 // produced by the scanner when an unterminated string is encountered. 4237 // produced by the scanner when an unterminated string is encountered.
4189 parseCompilationUnit( 4238 parseCompilationUnit(
4190 r''' 4239 r'''
4191 void main() { 4240 void main() {
4192 var x = """""''', 4241 var x = """""''',
4193 [ 4242 [
4194 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 4243 ScannerErrorCode.UNTERMINATED_STRING_LITERAL,
4195 ParserErrorCode.EXPECTED_TOKEN, 4244 fe.Scanner.useFasta
4245 ? ScannerErrorCode.EXPECTED_TOKEN
4246 : ParserErrorCode.EXPECTED_TOKEN,
4196 ParserErrorCode.EXPECTED_TOKEN 4247 ParserErrorCode.EXPECTED_TOKEN
4197 ]); 4248 ]);
4198 } 4249 }
4199 4250
4200 void test_useOfUnaryPlusOperator() { 4251 void test_useOfUnaryPlusOperator() {
4201 createParser('+x'); 4252 createParser('+x');
4202 Expression expression = parser.parseUnaryExpression(); 4253 Expression expression = parser.parseUnaryExpression();
4203 expectNotNullIfNoErrors(expression); 4254 expectNotNullIfNoErrors(expression);
4204 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); 4255 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]);
4205 var identifier = expression as SimpleIdentifier; 4256 var identifier = expression as SimpleIdentifier;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
4326 FormalParameterList list = parser.parseFormalParameterList(); 4377 FormalParameterList list = parser.parseFormalParameterList();
4327 expectNotNullIfNoErrors(list); 4378 expectNotNullIfNoErrors(list);
4328 listener.assertErrorsWithCodes( 4379 listener.assertErrorsWithCodes(
4329 [ParserErrorCode.WRONG_SEPARATOR_FOR_POSITIONAL_PARAMETER]); 4380 [ParserErrorCode.WRONG_SEPARATOR_FOR_POSITIONAL_PARAMETER]);
4330 } 4381 }
4331 4382
4332 void test_wrongTerminatorForParameterGroup_named() { 4383 void test_wrongTerminatorForParameterGroup_named() {
4333 createParser('(a, {b, c])'); 4384 createParser('(a, {b, c])');
4334 FormalParameterList list = parser.parseFormalParameterList(); 4385 FormalParameterList list = parser.parseFormalParameterList();
4335 expectNotNullIfNoErrors(list); 4386 expectNotNullIfNoErrors(list);
4336 listener.assertErrorsWithCodes( 4387 listener.assertErrorsWithCodes(fe.Scanner.useFasta
4337 [ParserErrorCode.WRONG_TERMINATOR_FOR_PARAMETER_GROUP]); 4388 ? [ScannerErrorCode.EXPECTED_TOKEN, ScannerErrorCode.EXPECTED_TOKEN]
4389 : [ParserErrorCode.WRONG_TERMINATOR_FOR_PARAMETER_GROUP]);
4338 } 4390 }
4339 4391
4340 void test_wrongTerminatorForParameterGroup_optional() { 4392 void test_wrongTerminatorForParameterGroup_optional() {
4341 createParser('(a, [b, c})'); 4393 createParser('(a, [b, c})');
4342 FormalParameterList list = parser.parseFormalParameterList(); 4394 FormalParameterList list = parser.parseFormalParameterList();
4343 expectNotNullIfNoErrors(list); 4395 expectNotNullIfNoErrors(list);
4344 listener.assertErrorsWithCodes( 4396 listener.assertErrorsWithCodes(fe.Scanner.useFasta
4345 [ParserErrorCode.WRONG_TERMINATOR_FOR_PARAMETER_GROUP]); 4397 ? [ScannerErrorCode.EXPECTED_TOKEN, ScannerErrorCode.EXPECTED_TOKEN]
4398 : [ParserErrorCode.WRONG_TERMINATOR_FOR_PARAMETER_GROUP]);
4346 } 4399 }
4347 } 4400 }
4348 4401
4349 @reflectiveTest 4402 @reflectiveTest
4350 class ExpressionParserTest extends ParserTestCase 4403 class ExpressionParserTest extends ParserTestCase
4351 with ExpressionParserTestMixin {} 4404 with ExpressionParserTestMixin {}
4352 4405
4353 abstract class ExpressionParserTestMixin implements AbstractParserTestCase { 4406 abstract class ExpressionParserTestMixin implements AbstractParserTestCase {
4354 void test_namedArgument() { 4407 void test_namedArgument() {
4355 var invocation = parseExpression('m(a: 1, b: 2)') as MethodInvocation; 4408 var invocation = parseExpression('m(a: 1, b: 2)') as MethodInvocation;
(...skipping 6900 matching lines...) Expand 10 before | Expand all | Expand 10 after
11256 expectNotNullIfNoErrors(functionBody); 11309 expectNotNullIfNoErrors(functionBody);
11257 listener.assertNoErrors(); 11310 listener.assertNoErrors();
11258 expect(functionBody, new isInstanceOf<EmptyFunctionBody>()); 11311 expect(functionBody, new isInstanceOf<EmptyFunctionBody>());
11259 } 11312 }
11260 11313
11261 void test_parseFunctionBody_skip_block_invalid() { 11314 void test_parseFunctionBody_skip_block_invalid() {
11262 ParserTestCase.parseFunctionBodies = false; 11315 ParserTestCase.parseFunctionBodies = false;
11263 createParser('{'); 11316 createParser('{');
11264 FunctionBody functionBody = parser.parseFunctionBody(false, null, false); 11317 FunctionBody functionBody = parser.parseFunctionBody(false, null, false);
11265 expectNotNullIfNoErrors(functionBody); 11318 expectNotNullIfNoErrors(functionBody);
11266 listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_TOKEN]); 11319 listener.assertErrorsWithCodes([
11320 fe.Scanner.useFasta
11321 ? ScannerErrorCode.EXPECTED_TOKEN
11322 : ParserErrorCode.EXPECTED_TOKEN
11323 ]);
11267 expect(functionBody, new isInstanceOf<EmptyFunctionBody>()); 11324 expect(functionBody, new isInstanceOf<EmptyFunctionBody>());
11268 } 11325 }
11269 11326
11270 void test_parseFunctionBody_skip_blocks() { 11327 void test_parseFunctionBody_skip_blocks() {
11271 ParserTestCase.parseFunctionBodies = false; 11328 ParserTestCase.parseFunctionBodies = false;
11272 createParser('{ {} }'); 11329 createParser('{ {} }');
11273 FunctionBody functionBody = parser.parseFunctionBody(false, null, false); 11330 FunctionBody functionBody = parser.parseFunctionBody(false, null, false);
11274 expectNotNullIfNoErrors(functionBody); 11331 expectNotNullIfNoErrors(functionBody);
11275 listener.assertNoErrors(); 11332 listener.assertNoErrors();
11276 expect(functionBody, new isInstanceOf<EmptyFunctionBody>()); 11333 expect(functionBody, new isInstanceOf<EmptyFunctionBody>());
(...skipping 3810 matching lines...) Expand 10 before | Expand all | Expand 10 after
15087 expectCommentText(typeVariable.documentationComment, '/// Doc'); 15144 expectCommentText(typeVariable.documentationComment, '/// Doc');
15088 } 15145 }
15089 15146
15090 /** 15147 /**
15091 * Assert that the given [name] is in declaration context. 15148 * Assert that the given [name] is in declaration context.
15092 */ 15149 */
15093 void _assertIsDeclarationName(SimpleIdentifier name) { 15150 void _assertIsDeclarationName(SimpleIdentifier name) {
15094 expect(name.inDeclarationContext(), isTrue); 15151 expect(name.inDeclarationContext(), isTrue);
15095 } 15152 }
15096 } 15153 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/parser.dart ('k') | pkg/front_end/lib/src/scanner/token.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698