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

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

Issue 2707183002: Extract FormalParameter tests into FormalParameterParserTestMixin. (Closed)
Patch Set: Created 3 years, 10 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/test/generated/parser_fasta_test.dart ('k') | no next file » | 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 library analyzer.test.generated.parser_test; 5 library analyzer.test.generated.parser_test;
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; 8 import 'package:analyzer/dart/ast/standard_ast_factory.dart';
9 import 'package:analyzer/dart/ast/token.dart'; 9 import 'package:analyzer/dart/ast/token.dart';
10 import 'package:analyzer/dart/ast/visitor.dart'; 10 import 'package:analyzer/dart/ast/visitor.dart';
11 import 'package:analyzer/error/error.dart'; 11 import 'package:analyzer/error/error.dart';
12 import 'package:analyzer/error/listener.dart'; 12 import 'package:analyzer/error/listener.dart';
13 import 'package:analyzer/src/dart/ast/token.dart'; 13 import 'package:analyzer/src/dart/ast/token.dart';
14 import 'package:analyzer/src/dart/scanner/reader.dart'; 14 import 'package:analyzer/src/dart/scanner/reader.dart';
15 import 'package:analyzer/src/dart/scanner/scanner.dart'; 15 import 'package:analyzer/src/dart/scanner/scanner.dart';
16 import 'package:analyzer/src/generated/parser.dart'; 16 import 'package:analyzer/src/generated/parser.dart';
17 import 'package:analyzer/src/generated/source.dart'; 17 import 'package:analyzer/src/generated/source.dart';
18 import 'package:analyzer/src/generated/testing/ast_test_factory.dart'; 18 import 'package:analyzer/src/generated/testing/ast_test_factory.dart';
19 import 'package:analyzer/src/generated/testing/token_factory.dart'; 19 import 'package:analyzer/src/generated/testing/token_factory.dart';
20 import 'package:analyzer/src/generated/utilities_dart.dart'; 20 import 'package:analyzer/src/generated/utilities_dart.dart';
21 import 'package:test/test.dart'; 21 import 'package:test/test.dart';
22 import 'package:test_reflective_loader/test_reflective_loader.dart'; 22 import 'package:test_reflective_loader/test_reflective_loader.dart';
23 23
24 import 'test_support.dart'; 24 import 'test_support.dart';
25 25
26 main() { 26 main() {
27 defineReflectiveSuite(() { 27 defineReflectiveSuite(() {
28 defineReflectiveTests(ComplexParserTest); 28 defineReflectiveTests(ComplexParserTest);
29 defineReflectiveTests(ErrorParserTest); 29 defineReflectiveTests(ErrorParserTest);
30 defineReflectiveTests(FormalParameterParserTest);
30 defineReflectiveTests(NonErrorParserTest); 31 defineReflectiveTests(NonErrorParserTest);
31 defineReflectiveTests(RecoveryParserTest); 32 defineReflectiveTests(RecoveryParserTest);
32 defineReflectiveTests(SimpleParserTest); 33 defineReflectiveTests(SimpleParserTest);
33 defineReflectiveTests(TopLevelParserTest); 34 defineReflectiveTests(TopLevelParserTest);
34 }); 35 });
35 } 36 }
36 37
37 /** 38 /**
38 * Abstract base class for parser tests, which does not make assumptions about 39 * Abstract base class for parser tests, which does not make assumptions about
39 * which parser is used. 40 * which parser is used.
(...skipping 10 matching lines...) Expand all
50 void set enableUriInPartOf(bool value); 51 void set enableUriInPartOf(bool value);
51 52
52 /** 53 /**
53 * Get the parser used by the test. 54 * Get the parser used by the test.
54 * 55 *
55 * Caller must first invoke [createParser]. 56 * Caller must first invoke [createParser].
56 */ 57 */
57 Parser get parser; 58 Parser get parser;
58 59
59 /** 60 /**
61 * Assert that the number and codes of errors occurred during parsing is the
62 * same the the [expectedErrorCodes].
63 */
64 void assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes);
65
66 /**
60 * Asserts that no errors occurred during parsing. 67 * Asserts that no errors occurred during parsing.
61 */ 68 */
62 void assertNoErrors(); 69 void assertNoErrors();
63 70
64 /** 71 /**
65 * Prepares to parse using tokens scanned from the given [content] string. 72 * Prepares to parse using tokens scanned from the given [content] string.
66 */ 73 */
67 void createParser(String content); 74 void createParser(String content);
68 75
69 CompilationUnit parseCompilationUnit(String source, 76 CompilationUnit parseCompilationUnit(String source,
(...skipping 11 matching lines...) Expand all
81 * @return the compilation unit that was parsed 88 * @return the compilation unit that was parsed
82 * @throws Exception if the source could not be parsed, if the compilation err ors in the source do 89 * @throws Exception if the source could not be parsed, if the compilation err ors in the source do
83 * not match those that are expected, or if the result would have be en `null` 90 * not match those that are expected, or if the result would have be en `null`
84 */ 91 */
85 CompilationUnit parseDirectives(String source, 92 CompilationUnit parseDirectives(String source,
86 [List<ErrorCode> errorCodes = const <ErrorCode>[]]); 93 [List<ErrorCode> errorCodes = const <ErrorCode>[]]);
87 94
88 Expression parseExpression(String source, 95 Expression parseExpression(String source,
89 [List<ErrorCode> errorCodes = const <ErrorCode>[]]); 96 [List<ErrorCode> errorCodes = const <ErrorCode>[]]);
90 97
98 FormalParameter parseFormalParameter(String code, ParameterKind kind,
99 {List<ErrorCode> errorCodes: const <ErrorCode>[]});
100
101 FormalParameterList parseFormalParameterList(String code,
102 {bool inFunctionType: false,
103 List<ErrorCode> errorCodes: const <ErrorCode>[]});
104
91 /** 105 /**
92 * Parses a single top level member of a compilation unit (other than a 106 * Parses a single top level member of a compilation unit (other than a
93 * directive), including any comment and/or metadata that precedes it. 107 * directive), including any comment and/or metadata that precedes it.
94 */ 108 */
95 CompilationUnitMember parseFullCompilationUnitMember(); 109 CompilationUnitMember parseFullCompilationUnitMember();
96 110
97 /** 111 /**
98 * Parses a single top level directive, including any comment and/or metadata 112 * Parses a single top level directive, including any comment and/or metadata
99 * that precedes it. 113 * that precedes it.
100 */ 114 */
101 Directive parseFullDirective(); 115 Directive parseFullDirective();
102 116
117 NormalFormalParameter parseNormalFormalParameter(String code,
118 {bool inFunctionType: false});
119
103 Statement parseStatement(String source, 120 Statement parseStatement(String source,
104 [List<ErrorCode> errorCodes = const <ErrorCode>[], 121 [List<ErrorCode> errorCodes = const <ErrorCode>[],
105 bool enableLazyAssignmentOperators]); 122 bool enableLazyAssignmentOperators]);
106 } 123 }
107 124
108 /** 125 /**
109 * Instances of the class `AstValidator` are used to validate the correct constr uction of an 126 * Instances of the class `AstValidator` are used to validate the correct constr uction of an
110 * AST structure. 127 * AST structure.
111 */ 128 */
112 class AstValidator extends UnifyingAstVisitor<Object> { 129 class AstValidator extends UnifyingAstVisitor<Object> {
(...skipping 2851 matching lines...) Expand 10 before | Expand all | Expand 10 after
2964 2981
2965 void test_wrongTerminatorForParameterGroup_optional() { 2982 void test_wrongTerminatorForParameterGroup_optional() {
2966 createParser('(a, [b, c})'); 2983 createParser('(a, [b, c})');
2967 FormalParameterList list = parser.parseFormalParameterList(); 2984 FormalParameterList list = parser.parseFormalParameterList();
2968 expectNotNullIfNoErrors(list); 2985 expectNotNullIfNoErrors(list);
2969 listener.assertErrorsWithCodes( 2986 listener.assertErrorsWithCodes(
2970 [ParserErrorCode.WRONG_TERMINATOR_FOR_PARAMETER_GROUP]); 2987 [ParserErrorCode.WRONG_TERMINATOR_FOR_PARAMETER_GROUP]);
2971 } 2988 }
2972 } 2989 }
2973 2990
2991 /**
2992 * Tests of the analyzer parser based on [FormalParameterParserTestMixin].
2993 */
2994 @reflectiveTest
2995 class FormalParameterParserTest extends ParserTestCase
2996 with FormalParameterParserTestMixin {}
2997
2998 /**
2999 * The class [FormalParameterParserTestMixin] defines parser tests that test
3000 * the parsing of formal parameters.
3001 */
3002 abstract class FormalParameterParserTestMixin
3003 implements AbstractParserTestCase {
3004 void test_parseFormalParameter_covariant_final_named() {
3005 ParameterKind kind = ParameterKind.NAMED;
3006 FormalParameter parameter =
3007 parseFormalParameter('covariant final a : null', kind);
3008 expect(parameter, isNotNull);
3009 assertNoErrors();
3010 expect(parameter, new isInstanceOf<DefaultFormalParameter>());
3011 DefaultFormalParameter defaultParameter = parameter;
3012 SimpleFormalParameter simpleParameter =
3013 defaultParameter.parameter as SimpleFormalParameter;
3014 expect(simpleParameter.covariantKeyword, isNotNull);
3015 expect(simpleParameter.identifier, isNotNull);
3016 expect(simpleParameter.keyword, isNotNull);
3017 expect(simpleParameter.type, isNull);
3018 expect(simpleParameter.kind, kind);
3019 expect(defaultParameter.separator, isNotNull);
3020 expect(defaultParameter.defaultValue, isNotNull);
3021 expect(defaultParameter.kind, kind);
3022 }
3023
3024 void test_parseFormalParameter_covariant_final_normal() {
3025 ParameterKind kind = ParameterKind.REQUIRED;
3026 FormalParameter parameter = parseFormalParameter('covariant final a', kind);
3027 expect(parameter, isNotNull);
3028 assertNoErrors();
3029 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
3030 SimpleFormalParameter simpleParameter = parameter;
3031 expect(simpleParameter.covariantKeyword, isNotNull);
3032 expect(simpleParameter.identifier, isNotNull);
3033 expect(simpleParameter.keyword, isNotNull);
3034 expect(simpleParameter.type, isNull);
3035 expect(simpleParameter.kind, kind);
3036 }
3037
3038 void test_parseFormalParameter_covariant_final_positional() {
3039 ParameterKind kind = ParameterKind.POSITIONAL;
3040 FormalParameter parameter =
3041 parseFormalParameter('covariant final a = null', kind);
3042 expect(parameter, isNotNull);
3043 assertNoErrors();
3044 expect(parameter, new isInstanceOf<DefaultFormalParameter>());
3045 DefaultFormalParameter defaultParameter = parameter;
3046 SimpleFormalParameter simpleParameter =
3047 defaultParameter.parameter as SimpleFormalParameter;
3048 expect(simpleParameter.covariantKeyword, isNotNull);
3049 expect(simpleParameter.identifier, isNotNull);
3050 expect(simpleParameter.keyword, isNotNull);
3051 expect(simpleParameter.type, isNull);
3052 expect(simpleParameter.kind, kind);
3053 expect(defaultParameter.separator, isNotNull);
3054 expect(defaultParameter.defaultValue, isNotNull);
3055 expect(defaultParameter.kind, kind);
3056 }
3057
3058 void test_parseFormalParameter_covariant_final_type_named() {
3059 ParameterKind kind = ParameterKind.NAMED;
3060 FormalParameter parameter =
3061 parseFormalParameter('covariant final A a : null', kind);
3062 expect(parameter, isNotNull);
3063 assertNoErrors();
3064 expect(parameter, new isInstanceOf<DefaultFormalParameter>());
3065 DefaultFormalParameter defaultParameter = parameter;
3066 SimpleFormalParameter simpleParameter =
3067 defaultParameter.parameter as SimpleFormalParameter;
3068 expect(simpleParameter.covariantKeyword, isNotNull);
3069 expect(simpleParameter.identifier, isNotNull);
3070 expect(simpleParameter.keyword, isNotNull);
3071 expect(simpleParameter.type, isNotNull);
3072 expect(simpleParameter.kind, kind);
3073 expect(defaultParameter.separator, isNotNull);
3074 expect(defaultParameter.defaultValue, isNotNull);
3075 expect(defaultParameter.kind, kind);
3076 }
3077
3078 void test_parseFormalParameter_covariant_final_type_normal() {
3079 ParameterKind kind = ParameterKind.REQUIRED;
3080 FormalParameter parameter =
3081 parseFormalParameter('covariant final A a', kind);
3082 expect(parameter, isNotNull);
3083 assertNoErrors();
3084 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
3085 SimpleFormalParameter simpleParameter = parameter;
3086 expect(simpleParameter.covariantKeyword, isNotNull);
3087 expect(simpleParameter.identifier, isNotNull);
3088 expect(simpleParameter.keyword, isNotNull);
3089 expect(simpleParameter.type, isNotNull);
3090 expect(simpleParameter.kind, kind);
3091 }
3092
3093 void test_parseFormalParameter_covariant_final_type_positional() {
3094 ParameterKind kind = ParameterKind.POSITIONAL;
3095 FormalParameter parameter =
3096 parseFormalParameter('covariant final A a = null', kind);
3097 expect(parameter, isNotNull);
3098 assertNoErrors();
3099 expect(parameter, new isInstanceOf<DefaultFormalParameter>());
3100 DefaultFormalParameter defaultParameter = parameter;
3101 SimpleFormalParameter simpleParameter =
3102 defaultParameter.parameter as SimpleFormalParameter;
3103 expect(simpleParameter.covariantKeyword, isNotNull);
3104 expect(simpleParameter.identifier, isNotNull);
3105 expect(simpleParameter.keyword, isNotNull);
3106 expect(simpleParameter.type, isNotNull);
3107 expect(simpleParameter.kind, kind);
3108 expect(defaultParameter.separator, isNotNull);
3109 expect(defaultParameter.defaultValue, isNotNull);
3110 expect(defaultParameter.kind, kind);
3111 }
3112
3113 void test_parseFormalParameter_covariant_type_function() {
3114 ParameterKind kind = ParameterKind.REQUIRED;
3115 FormalParameter parameter =
3116 parseFormalParameter('covariant String Function(int) a', kind);
3117 expect(parameter, isNotNull);
3118 assertNoErrors();
3119 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
3120 SimpleFormalParameter simpleParameter = parameter;
3121 expect(simpleParameter.covariantKeyword, isNotNull);
3122 expect(simpleParameter.identifier, isNotNull);
3123 expect(simpleParameter.keyword, isNull);
3124 expect(simpleParameter.type, new isInstanceOf<GenericFunctionType>());
3125 expect(simpleParameter.kind, kind);
3126 }
3127
3128 void test_parseFormalParameter_covariant_type_named() {
3129 ParameterKind kind = ParameterKind.NAMED;
3130 FormalParameter parameter =
3131 parseFormalParameter('covariant A a : null', kind);
3132 expect(parameter, isNotNull);
3133 assertNoErrors();
3134 expect(parameter, new isInstanceOf<DefaultFormalParameter>());
3135 DefaultFormalParameter defaultParameter = parameter;
3136 SimpleFormalParameter simpleParameter =
3137 defaultParameter.parameter as SimpleFormalParameter;
3138 expect(simpleParameter.covariantKeyword, isNotNull);
3139 expect(simpleParameter.identifier, isNotNull);
3140 expect(simpleParameter.keyword, isNull);
3141 expect(simpleParameter.type, isNotNull);
3142 expect(simpleParameter.kind, kind);
3143 expect(defaultParameter.separator, isNotNull);
3144 expect(defaultParameter.defaultValue, isNotNull);
3145 expect(defaultParameter.kind, kind);
3146 }
3147
3148 void test_parseFormalParameter_covariant_type_normal() {
3149 ParameterKind kind = ParameterKind.REQUIRED;
3150 FormalParameter parameter =
3151 parseFormalParameter('covariant A<B<C>> a', kind);
3152 expect(parameter, isNotNull);
3153 assertNoErrors();
3154 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
3155 SimpleFormalParameter simpleParameter = parameter;
3156 expect(simpleParameter.covariantKeyword, isNotNull);
3157 expect(simpleParameter.identifier, isNotNull);
3158 expect(simpleParameter.keyword, isNull);
3159 expect(simpleParameter.type, isNotNull);
3160 expect(simpleParameter.kind, kind);
3161 }
3162
3163 void test_parseFormalParameter_covariant_type_positional() {
3164 ParameterKind kind = ParameterKind.POSITIONAL;
3165 FormalParameter parameter =
3166 parseFormalParameter('covariant A a = null', kind);
3167 expect(parameter, isNotNull);
3168 assertNoErrors();
3169 expect(parameter, new isInstanceOf<DefaultFormalParameter>());
3170 DefaultFormalParameter defaultParameter = parameter;
3171 SimpleFormalParameter simpleParameter =
3172 defaultParameter.parameter as SimpleFormalParameter;
3173 expect(simpleParameter.covariantKeyword, isNotNull);
3174 expect(simpleParameter.identifier, isNotNull);
3175 expect(simpleParameter.keyword, isNull);
3176 expect(simpleParameter.type, isNotNull);
3177 expect(simpleParameter.kind, kind);
3178 expect(defaultParameter.separator, isNotNull);
3179 expect(defaultParameter.defaultValue, isNotNull);
3180 expect(defaultParameter.kind, kind);
3181 }
3182
3183 void test_parseFormalParameter_covariant_var_named() {
3184 ParameterKind kind = ParameterKind.NAMED;
3185 FormalParameter parameter =
3186 parseFormalParameter('covariant var a : null', kind);
3187 expect(parameter, isNotNull);
3188 assertNoErrors();
3189 expect(parameter, new isInstanceOf<DefaultFormalParameter>());
3190 DefaultFormalParameter defaultParameter = parameter;
3191 SimpleFormalParameter simpleParameter =
3192 defaultParameter.parameter as SimpleFormalParameter;
3193 expect(simpleParameter.covariantKeyword, isNotNull);
3194 expect(simpleParameter.identifier, isNotNull);
3195 expect(simpleParameter.keyword, isNotNull);
3196 expect(simpleParameter.type, isNull);
3197 expect(simpleParameter.kind, kind);
3198 expect(defaultParameter.separator, isNotNull);
3199 expect(defaultParameter.defaultValue, isNotNull);
3200 expect(defaultParameter.kind, kind);
3201 }
3202
3203 void test_parseFormalParameter_covariant_var_normal() {
3204 ParameterKind kind = ParameterKind.REQUIRED;
3205 FormalParameter parameter = parseFormalParameter('covariant var a', kind);
3206 expect(parameter, isNotNull);
3207 assertNoErrors();
3208 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
3209 SimpleFormalParameter simpleParameter = parameter;
3210 expect(simpleParameter.covariantKeyword, isNotNull);
3211 expect(simpleParameter.identifier, isNotNull);
3212 expect(simpleParameter.keyword, isNotNull);
3213 expect(simpleParameter.type, isNull);
3214 expect(simpleParameter.kind, kind);
3215 }
3216
3217 void test_parseFormalParameter_covariant_var_positional() {
3218 ParameterKind kind = ParameterKind.POSITIONAL;
3219 FormalParameter parameter =
3220 parseFormalParameter('covariant var a = null', kind);
3221 expect(parameter, isNotNull);
3222 assertNoErrors();
3223 expect(parameter, new isInstanceOf<DefaultFormalParameter>());
3224 DefaultFormalParameter defaultParameter = parameter;
3225 SimpleFormalParameter simpleParameter =
3226 defaultParameter.parameter as SimpleFormalParameter;
3227 expect(simpleParameter.covariantKeyword, isNotNull);
3228 expect(simpleParameter.identifier, isNotNull);
3229 expect(simpleParameter.keyword, isNotNull);
3230 expect(simpleParameter.type, isNull);
3231 expect(simpleParameter.kind, kind);
3232 expect(defaultParameter.separator, isNotNull);
3233 expect(defaultParameter.defaultValue, isNotNull);
3234 expect(defaultParameter.kind, kind);
3235 }
3236
3237 void test_parseFormalParameter_final_named() {
3238 ParameterKind kind = ParameterKind.NAMED;
3239 FormalParameter parameter = parseFormalParameter('final a : null', kind);
3240 expect(parameter, isNotNull);
3241 assertNoErrors();
3242 expect(parameter, new isInstanceOf<DefaultFormalParameter>());
3243 DefaultFormalParameter defaultParameter = parameter;
3244 SimpleFormalParameter simpleParameter =
3245 defaultParameter.parameter as SimpleFormalParameter;
3246 expect(simpleParameter.covariantKeyword, isNull);
3247 expect(simpleParameter.identifier, isNotNull);
3248 expect(simpleParameter.keyword, isNotNull);
3249 expect(simpleParameter.type, isNull);
3250 expect(simpleParameter.kind, kind);
3251 expect(defaultParameter.separator, isNotNull);
3252 expect(defaultParameter.defaultValue, isNotNull);
3253 expect(defaultParameter.kind, kind);
3254 }
3255
3256 void test_parseFormalParameter_final_normal() {
3257 ParameterKind kind = ParameterKind.REQUIRED;
3258 FormalParameter parameter = parseFormalParameter('final a', kind);
3259 expect(parameter, isNotNull);
3260 assertNoErrors();
3261 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
3262 SimpleFormalParameter simpleParameter = parameter;
3263 expect(simpleParameter.covariantKeyword, isNull);
3264 expect(simpleParameter.identifier, isNotNull);
3265 expect(simpleParameter.keyword, isNotNull);
3266 expect(simpleParameter.type, isNull);
3267 expect(simpleParameter.kind, kind);
3268 }
3269
3270 void test_parseFormalParameter_final_positional() {
3271 ParameterKind kind = ParameterKind.POSITIONAL;
3272 FormalParameter parameter = parseFormalParameter('final a = null', kind);
3273 expect(parameter, isNotNull);
3274 assertNoErrors();
3275 expect(parameter, new isInstanceOf<DefaultFormalParameter>());
3276 DefaultFormalParameter defaultParameter = parameter;
3277 SimpleFormalParameter simpleParameter =
3278 defaultParameter.parameter as SimpleFormalParameter;
3279 expect(simpleParameter.covariantKeyword, isNull);
3280 expect(simpleParameter.identifier, isNotNull);
3281 expect(simpleParameter.keyword, isNotNull);
3282 expect(simpleParameter.type, isNull);
3283 expect(simpleParameter.kind, kind);
3284 expect(defaultParameter.separator, isNotNull);
3285 expect(defaultParameter.defaultValue, isNotNull);
3286 expect(defaultParameter.kind, kind);
3287 }
3288
3289 void test_parseFormalParameter_final_type_named() {
3290 ParameterKind kind = ParameterKind.NAMED;
3291 FormalParameter parameter = parseFormalParameter('final A a : null', kind);
3292 expect(parameter, isNotNull);
3293 assertNoErrors();
3294 expect(parameter, new isInstanceOf<DefaultFormalParameter>());
3295 DefaultFormalParameter defaultParameter = parameter;
3296 SimpleFormalParameter simpleParameter =
3297 defaultParameter.parameter as SimpleFormalParameter;
3298 expect(simpleParameter.covariantKeyword, isNull);
3299 expect(simpleParameter.identifier, isNotNull);
3300 expect(simpleParameter.keyword, isNotNull);
3301 expect(simpleParameter.type, isNotNull);
3302 expect(simpleParameter.kind, kind);
3303 expect(defaultParameter.separator, isNotNull);
3304 expect(defaultParameter.defaultValue, isNotNull);
3305 expect(defaultParameter.kind, kind);
3306 }
3307
3308 void test_parseFormalParameter_final_type_normal() {
3309 ParameterKind kind = ParameterKind.REQUIRED;
3310 FormalParameter parameter = parseFormalParameter('final A a', kind);
3311 expect(parameter, isNotNull);
3312 assertNoErrors();
3313 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
3314 SimpleFormalParameter simpleParameter = parameter;
3315 expect(simpleParameter.covariantKeyword, isNull);
3316 expect(simpleParameter.identifier, isNotNull);
3317 expect(simpleParameter.keyword, isNotNull);
3318 expect(simpleParameter.type, isNotNull);
3319 expect(simpleParameter.kind, kind);
3320 }
3321
3322 void test_parseFormalParameter_final_type_positional() {
3323 ParameterKind kind = ParameterKind.POSITIONAL;
3324 FormalParameter parameter = parseFormalParameter('final A a = null', kind);
3325 expect(parameter, isNotNull);
3326 assertNoErrors();
3327 expect(parameter, new isInstanceOf<DefaultFormalParameter>());
3328 DefaultFormalParameter defaultParameter = parameter;
3329 SimpleFormalParameter simpleParameter =
3330 defaultParameter.parameter as SimpleFormalParameter;
3331 expect(simpleParameter.covariantKeyword, isNull);
3332 expect(simpleParameter.identifier, isNotNull);
3333 expect(simpleParameter.keyword, isNotNull);
3334 expect(simpleParameter.type, isNotNull);
3335 expect(simpleParameter.kind, kind);
3336 expect(defaultParameter.separator, isNotNull);
3337 expect(defaultParameter.defaultValue, isNotNull);
3338 expect(defaultParameter.kind, kind);
3339 }
3340
3341 void test_parseFormalParameter_type_function() {
3342 ParameterKind kind = ParameterKind.REQUIRED;
3343 FormalParameter parameter =
3344 parseFormalParameter('String Function(int) a', kind);
3345 expect(parameter, isNotNull);
3346 assertNoErrors();
3347 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
3348 SimpleFormalParameter simpleParameter = parameter;
3349 expect(simpleParameter.covariantKeyword, isNull);
3350 expect(simpleParameter.identifier, isNotNull);
3351 expect(simpleParameter.keyword, isNull);
3352 expect(simpleParameter.type, new isInstanceOf<GenericFunctionType>());
3353 expect(simpleParameter.kind, kind);
3354 }
3355
3356 void test_parseFormalParameter_type_named() {
3357 ParameterKind kind = ParameterKind.NAMED;
3358 FormalParameter parameter = parseFormalParameter('A a : null', kind);
3359 expect(parameter, isNotNull);
3360 assertNoErrors();
3361 expect(parameter, new isInstanceOf<DefaultFormalParameter>());
3362 DefaultFormalParameter defaultParameter = parameter;
3363 SimpleFormalParameter simpleParameter =
3364 defaultParameter.parameter as SimpleFormalParameter;
3365 expect(simpleParameter.covariantKeyword, isNull);
3366 expect(simpleParameter.identifier, isNotNull);
3367 expect(simpleParameter.keyword, isNull);
3368 expect(simpleParameter.type, isNotNull);
3369 expect(simpleParameter.kind, kind);
3370 expect(defaultParameter.separator, isNotNull);
3371 expect(defaultParameter.defaultValue, isNotNull);
3372 expect(defaultParameter.kind, kind);
3373 }
3374
3375 void test_parseFormalParameter_type_normal() {
3376 ParameterKind kind = ParameterKind.REQUIRED;
3377 FormalParameter parameter = parseFormalParameter('A a', kind);
3378 expect(parameter, isNotNull);
3379 assertNoErrors();
3380 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
3381 SimpleFormalParameter simpleParameter = parameter;
3382 expect(simpleParameter.covariantKeyword, isNull);
3383 expect(simpleParameter.identifier, isNotNull);
3384 expect(simpleParameter.keyword, isNull);
3385 expect(simpleParameter.type, isNotNull);
3386 expect(simpleParameter.kind, kind);
3387 }
3388
3389 void test_parseFormalParameter_type_positional() {
3390 ParameterKind kind = ParameterKind.POSITIONAL;
3391 FormalParameter parameter = parseFormalParameter('A a = null', kind);
3392 expect(parameter, isNotNull);
3393 assertNoErrors();
3394 expect(parameter, new isInstanceOf<DefaultFormalParameter>());
3395 DefaultFormalParameter defaultParameter = parameter;
3396 SimpleFormalParameter simpleParameter =
3397 defaultParameter.parameter as SimpleFormalParameter;
3398 expect(simpleParameter.covariantKeyword, isNull);
3399 expect(simpleParameter.identifier, isNotNull);
3400 expect(simpleParameter.keyword, isNull);
3401 expect(simpleParameter.type, isNotNull);
3402 expect(simpleParameter.kind, kind);
3403 expect(defaultParameter.separator, isNotNull);
3404 expect(defaultParameter.defaultValue, isNotNull);
3405 expect(defaultParameter.kind, kind);
3406 }
3407
3408 void test_parseFormalParameter_var_named() {
3409 ParameterKind kind = ParameterKind.NAMED;
3410 FormalParameter parameter = parseFormalParameter('var a : null', kind);
3411 expect(parameter, isNotNull);
3412 assertNoErrors();
3413 expect(parameter, new isInstanceOf<DefaultFormalParameter>());
3414 DefaultFormalParameter defaultParameter = parameter;
3415 SimpleFormalParameter simpleParameter =
3416 defaultParameter.parameter as SimpleFormalParameter;
3417 expect(simpleParameter.covariantKeyword, isNull);
3418 expect(simpleParameter.identifier, isNotNull);
3419 expect(simpleParameter.keyword, isNotNull);
3420 expect(simpleParameter.type, isNull);
3421 expect(simpleParameter.kind, kind);
3422 expect(defaultParameter.separator, isNotNull);
3423 expect(defaultParameter.defaultValue, isNotNull);
3424 expect(defaultParameter.kind, kind);
3425 }
3426
3427 void test_parseFormalParameter_var_normal() {
3428 ParameterKind kind = ParameterKind.REQUIRED;
3429 FormalParameter parameter = parseFormalParameter('var a', kind);
3430 expect(parameter, isNotNull);
3431 assertNoErrors();
3432 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
3433 SimpleFormalParameter simpleParameter = parameter;
3434 expect(simpleParameter.covariantKeyword, isNull);
3435 expect(simpleParameter.identifier, isNotNull);
3436 expect(simpleParameter.keyword, isNotNull);
3437 expect(simpleParameter.type, isNull);
3438 expect(simpleParameter.kind, kind);
3439 }
3440
3441 void test_parseFormalParameter_var_positional() {
3442 ParameterKind kind = ParameterKind.POSITIONAL;
3443 FormalParameter parameter = parseFormalParameter('var a = null', kind);
3444 expect(parameter, isNotNull);
3445 assertNoErrors();
3446 expect(parameter, new isInstanceOf<DefaultFormalParameter>());
3447 DefaultFormalParameter defaultParameter = parameter;
3448 SimpleFormalParameter simpleParameter =
3449 defaultParameter.parameter as SimpleFormalParameter;
3450 expect(simpleParameter.covariantKeyword, isNull);
3451 expect(simpleParameter.identifier, isNotNull);
3452 expect(simpleParameter.keyword, isNotNull);
3453 expect(simpleParameter.type, isNull);
3454 expect(simpleParameter.kind, kind);
3455 expect(defaultParameter.separator, isNotNull);
3456 expect(defaultParameter.defaultValue, isNotNull);
3457 expect(defaultParameter.kind, kind);
3458 }
3459
3460 void test_parseFormalParameterList_empty() {
3461 FormalParameterList list = parseFormalParameterList('()');
3462 expect(list, isNotNull);
3463 assertNoErrors();
3464 expect(list.leftParenthesis, isNotNull);
3465 expect(list.leftDelimiter, isNull);
3466 expect(list.parameters, hasLength(0));
3467 expect(list.rightDelimiter, isNull);
3468 expect(list.rightParenthesis, isNotNull);
3469 }
3470
3471 void test_parseFormalParameterList_named_multiple() {
3472 FormalParameterList list =
3473 parseFormalParameterList('({A a : 1, B b, C c : 3})');
3474 expect(list, isNotNull);
3475 assertNoErrors();
3476 expect(list.leftParenthesis, isNotNull);
3477 expect(list.leftDelimiter, isNotNull);
3478 expect(list.parameters, hasLength(3));
3479 expect(list.rightDelimiter, isNotNull);
3480 expect(list.rightParenthesis, isNotNull);
3481 }
3482
3483 void test_parseFormalParameterList_named_single() {
3484 FormalParameterList list = parseFormalParameterList('({A a})');
3485 expect(list, isNotNull);
3486 assertNoErrors();
3487 expect(list.leftParenthesis, isNotNull);
3488 expect(list.leftDelimiter, isNotNull);
3489 expect(list.parameters, hasLength(1));
3490 expect(list.rightDelimiter, isNotNull);
3491 expect(list.rightParenthesis, isNotNull);
3492 }
3493
3494 void test_parseFormalParameterList_named_trailing_comma() {
3495 FormalParameterList list = parseFormalParameterList('(A a, {B b,})');
3496 expect(list, isNotNull);
3497 assertNoErrors();
3498 expect(list.leftParenthesis, isNotNull);
3499 expect(list.leftDelimiter, isNotNull);
3500 expect(list.parameters, hasLength(2));
3501 expect(list.rightDelimiter, isNotNull);
3502 expect(list.rightParenthesis, isNotNull);
3503 }
3504
3505 void test_parseFormalParameterList_normal_multiple() {
3506 FormalParameterList list = parseFormalParameterList('(A a, B b, C c)');
3507 expect(list, isNotNull);
3508 assertNoErrors();
3509 expect(list.leftParenthesis, isNotNull);
3510 expect(list.leftDelimiter, isNull);
3511 expect(list.parameters, hasLength(3));
3512 expect(list.rightDelimiter, isNull);
3513 expect(list.rightParenthesis, isNotNull);
3514 }
3515
3516 void test_parseFormalParameterList_normal_named() {
3517 FormalParameterList list = parseFormalParameterList('(A a, {B b})');
3518 expect(list, isNotNull);
3519 assertNoErrors();
3520 expect(list.leftParenthesis, isNotNull);
3521 expect(list.leftDelimiter, isNotNull);
3522 expect(list.parameters, hasLength(2));
3523 expect(list.rightDelimiter, isNotNull);
3524 expect(list.rightParenthesis, isNotNull);
3525 }
3526
3527 void test_parseFormalParameterList_normal_named_inFunctionType() {
3528 FormalParameterList list =
3529 parseFormalParameterList('(A, {B b})', inFunctionType: true);
3530 expect(list, isNotNull);
3531 assertNoErrors();
3532 expect(list.leftParenthesis, isNotNull);
3533 expect(list.leftDelimiter, isNotNull);
3534 expect(list.rightDelimiter, isNotNull);
3535 expect(list.rightParenthesis, isNotNull);
3536 NodeList<FormalParameter> parameters = list.parameters;
3537 expect(parameters, hasLength(2));
3538
3539 expect(parameters[0], new isInstanceOf<SimpleFormalParameter>());
3540 SimpleFormalParameter required = parameters[0];
3541 expect(required.identifier, isNull);
3542 expect(required.type, new isInstanceOf<TypeName>());
3543 expect((required.type as TypeName).name.name, 'A');
3544
3545 expect(parameters[1], new isInstanceOf<DefaultFormalParameter>());
3546 DefaultFormalParameter named = parameters[1];
3547 expect(named.identifier, isNotNull);
3548 expect(named.parameter, new isInstanceOf<SimpleFormalParameter>());
3549 SimpleFormalParameter simple = named.parameter;
3550 expect(simple.type, new isInstanceOf<TypeName>());
3551 expect((simple.type as TypeName).name.name, 'B');
3552 }
3553
3554 void test_parseFormalParameterList_normal_positional() {
3555 FormalParameterList list = parseFormalParameterList('(A a, [B b])');
3556 expect(list, isNotNull);
3557 assertNoErrors();
3558 expect(list.leftParenthesis, isNotNull);
3559 expect(list.leftDelimiter, isNotNull);
3560 expect(list.parameters, hasLength(2));
3561 expect(list.rightDelimiter, isNotNull);
3562 expect(list.rightParenthesis, isNotNull);
3563 }
3564
3565 void test_parseFormalParameterList_normal_single() {
3566 FormalParameterList list = parseFormalParameterList('(A a)');
3567 expect(list, isNotNull);
3568 assertNoErrors();
3569 expect(list.leftParenthesis, isNotNull);
3570 expect(list.leftDelimiter, isNull);
3571 expect(list.parameters, hasLength(1));
3572 expect(list.rightDelimiter, isNull);
3573 expect(list.rightParenthesis, isNotNull);
3574 }
3575
3576 void test_parseFormalParameterList_normal_single_Function() {
3577 FormalParameterList list = parseFormalParameterList('(Function f)');
3578 expect(list, isNotNull);
3579 assertNoErrors();
3580 expect(list.leftParenthesis, isNotNull);
3581 expect(list.leftDelimiter, isNull);
3582 expect(list.parameters, hasLength(1));
3583 expect(list.rightDelimiter, isNull);
3584 expect(list.rightParenthesis, isNotNull);
3585 }
3586
3587 void test_parseFormalParameterList_normal_single_trailing_comma() {
3588 FormalParameterList list = parseFormalParameterList('(A a,)');
3589 expect(list, isNotNull);
3590 assertNoErrors();
3591 expect(list.leftParenthesis, isNotNull);
3592 expect(list.leftDelimiter, isNull);
3593 expect(list.parameters, hasLength(1));
3594 expect(list.rightDelimiter, isNull);
3595 expect(list.rightParenthesis, isNotNull);
3596 }
3597
3598 void test_parseFormalParameterList_positional_multiple() {
3599 FormalParameterList list =
3600 parseFormalParameterList('([A a = null, B b, C c = null])');
3601 expect(list, isNotNull);
3602 assertNoErrors();
3603 expect(list.leftParenthesis, isNotNull);
3604 expect(list.leftDelimiter, isNotNull);
3605 expect(list.parameters, hasLength(3));
3606 expect(list.rightDelimiter, isNotNull);
3607 expect(list.rightParenthesis, isNotNull);
3608 }
3609
3610 void test_parseFormalParameterList_positional_single() {
3611 FormalParameterList list = parseFormalParameterList('([A a = null])');
3612 expect(list, isNotNull);
3613 assertNoErrors();
3614 expect(list.leftParenthesis, isNotNull);
3615 expect(list.leftDelimiter, isNotNull);
3616 expect(list.parameters, hasLength(1));
3617 expect(list.rightDelimiter, isNotNull);
3618 expect(list.rightParenthesis, isNotNull);
3619 }
3620
3621 void test_parseFormalParameterList_positional_trailing_comma() {
3622 FormalParameterList list = parseFormalParameterList('(A a, [B b,])');
3623 expect(list, isNotNull);
3624 assertNoErrors();
3625 expect(list.leftParenthesis, isNotNull);
3626 expect(list.leftDelimiter, isNotNull);
3627 expect(list.parameters, hasLength(2));
3628 expect(list.rightDelimiter, isNotNull);
3629 expect(list.rightParenthesis, isNotNull);
3630 }
3631
3632 void test_parseFormalParameterList_prefixedType() {
3633 FormalParameterList list = parseFormalParameterList('(io.File f)');
3634 expect(list, isNotNull);
3635 assertNoErrors();
3636 expect(list.leftParenthesis, isNotNull);
3637 expect(list.leftDelimiter, isNull);
3638 expect(list.parameters, hasLength(1));
3639 expect(list.parameters[0].toSource(), 'io.File f');
3640 expect(list.rightDelimiter, isNull);
3641 expect(list.rightParenthesis, isNotNull);
3642 }
3643
3644 void test_parseFormalParameterList_prefixedType_partial() {
3645 FormalParameterList list = parseFormalParameterList('(io.)', errorCodes: [
3646 ParserErrorCode.MISSING_IDENTIFIER,
3647 ParserErrorCode.MISSING_IDENTIFIER
3648 ]);
3649 expect(list, isNotNull);
3650 expect(list.leftParenthesis, isNotNull);
3651 expect(list.leftDelimiter, isNull);
3652 expect(list.parameters, hasLength(1));
3653 expect(list.parameters[0].toSource(), 'io. ');
3654 expect(list.rightDelimiter, isNull);
3655 expect(list.rightParenthesis, isNotNull);
3656 }
3657
3658 void test_parseFormalParameterList_prefixedType_partial2() {
3659 FormalParameterList list = parseFormalParameterList('(io.,a)', errorCodes: [
3660 ParserErrorCode.MISSING_IDENTIFIER,
3661 ParserErrorCode.MISSING_IDENTIFIER
3662 ]);
3663 expect(list, isNotNull);
3664 expect(list.leftParenthesis, isNotNull);
3665 expect(list.leftDelimiter, isNull);
3666 expect(list.parameters, hasLength(2));
3667 expect(list.parameters[0].toSource(), 'io. ');
3668 expect(list.parameters[1].toSource(), 'a');
3669 expect(list.rightDelimiter, isNull);
3670 expect(list.rightParenthesis, isNotNull);
3671 }
3672
3673 void test_parseNormalFormalParameter_field_const_noType() {
3674 NormalFormalParameter parameter =
3675 parseNormalFormalParameter('const this.a');
3676 expect(parameter, isNotNull);
3677 assertNoErrors();
3678 expect(parameter, new isInstanceOf<FieldFormalParameter>());
3679 FieldFormalParameter fieldParameter = parameter;
3680 expect(fieldParameter.keyword, isNotNull);
3681 expect(fieldParameter.type, isNull);
3682 expect(fieldParameter.identifier, isNotNull);
3683 expect(fieldParameter.parameters, isNull);
3684 }
3685
3686 void test_parseNormalFormalParameter_field_const_type() {
3687 NormalFormalParameter parameter =
3688 parseNormalFormalParameter('const A this.a');
3689 expect(parameter, isNotNull);
3690 assertNoErrors();
3691 expect(parameter, new isInstanceOf<FieldFormalParameter>());
3692 FieldFormalParameter fieldParameter = parameter;
3693 expect(fieldParameter.keyword, isNotNull);
3694 expect(fieldParameter.type, isNotNull);
3695 expect(fieldParameter.identifier, isNotNull);
3696 expect(fieldParameter.parameters, isNull);
3697 }
3698
3699 void test_parseNormalFormalParameter_field_final_noType() {
3700 NormalFormalParameter parameter =
3701 parseNormalFormalParameter('final this.a');
3702 expect(parameter, isNotNull);
3703 assertNoErrors();
3704 expect(parameter, new isInstanceOf<FieldFormalParameter>());
3705 FieldFormalParameter fieldParameter = parameter;
3706 expect(fieldParameter.keyword, isNotNull);
3707 expect(fieldParameter.type, isNull);
3708 expect(fieldParameter.identifier, isNotNull);
3709 expect(fieldParameter.parameters, isNull);
3710 }
3711
3712 void test_parseNormalFormalParameter_field_final_type() {
3713 NormalFormalParameter parameter =
3714 parseNormalFormalParameter('final A this.a');
3715 expect(parameter, isNotNull);
3716 assertNoErrors();
3717 expect(parameter, new isInstanceOf<FieldFormalParameter>());
3718 FieldFormalParameter fieldParameter = parameter;
3719 expect(fieldParameter.keyword, isNotNull);
3720 expect(fieldParameter.type, isNotNull);
3721 expect(fieldParameter.identifier, isNotNull);
3722 expect(fieldParameter.parameters, isNull);
3723 }
3724
3725 void test_parseNormalFormalParameter_field_function_nested() {
3726 NormalFormalParameter parameter = parseNormalFormalParameter('this.a(B b)');
3727 expect(parameter, isNotNull);
3728 assertNoErrors();
3729 expect(parameter, new isInstanceOf<FieldFormalParameter>());
3730 FieldFormalParameter fieldParameter = parameter;
3731 expect(fieldParameter.keyword, isNull);
3732 expect(fieldParameter.type, isNull);
3733 expect(fieldParameter.identifier, isNotNull);
3734 FormalParameterList parameterList = fieldParameter.parameters;
3735 expect(parameterList, isNotNull);
3736 expect(parameterList.parameters, hasLength(1));
3737 }
3738
3739 void test_parseNormalFormalParameter_field_function_noNested() {
3740 NormalFormalParameter parameter = parseNormalFormalParameter('this.a()');
3741 expect(parameter, isNotNull);
3742 assertNoErrors();
3743 expect(parameter, new isInstanceOf<FieldFormalParameter>());
3744 FieldFormalParameter fieldParameter = parameter;
3745 expect(fieldParameter.keyword, isNull);
3746 expect(fieldParameter.type, isNull);
3747 expect(fieldParameter.identifier, isNotNull);
3748 FormalParameterList parameterList = fieldParameter.parameters;
3749 expect(parameterList, isNotNull);
3750 expect(parameterList.parameters, hasLength(0));
3751 }
3752
3753 void test_parseNormalFormalParameter_field_noType() {
3754 NormalFormalParameter parameter = parseNormalFormalParameter('this.a');
3755 expect(parameter, isNotNull);
3756 assertNoErrors();
3757 expect(parameter, new isInstanceOf<FieldFormalParameter>());
3758 FieldFormalParameter fieldParameter = parameter;
3759 expect(fieldParameter.keyword, isNull);
3760 expect(fieldParameter.type, isNull);
3761 expect(fieldParameter.identifier, isNotNull);
3762 expect(fieldParameter.parameters, isNull);
3763 }
3764
3765 void test_parseNormalFormalParameter_field_type() {
3766 NormalFormalParameter parameter = parseNormalFormalParameter('A this.a');
3767 expect(parameter, isNotNull);
3768 assertNoErrors();
3769 expect(parameter, new isInstanceOf<FieldFormalParameter>());
3770 FieldFormalParameter fieldParameter = parameter;
3771 expect(fieldParameter.keyword, isNull);
3772 expect(fieldParameter.type, isNotNull);
3773 expect(fieldParameter.identifier, isNotNull);
3774 expect(fieldParameter.parameters, isNull);
3775 }
3776
3777 void test_parseNormalFormalParameter_field_var() {
3778 NormalFormalParameter parameter = parseNormalFormalParameter('var this.a');
3779 expect(parameter, isNotNull);
3780 assertNoErrors();
3781 expect(parameter, new isInstanceOf<FieldFormalParameter>());
3782 FieldFormalParameter fieldParameter = parameter;
3783 expect(fieldParameter.keyword, isNotNull);
3784 expect(fieldParameter.type, isNull);
3785 expect(fieldParameter.identifier, isNotNull);
3786 expect(fieldParameter.parameters, isNull);
3787 }
3788
3789 void test_parseNormalFormalParameter_function_noType() {
3790 NormalFormalParameter parameter = parseNormalFormalParameter('a()');
3791 expect(parameter, isNotNull);
3792 assertNoErrors();
3793 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
3794 FunctionTypedFormalParameter functionParameter = parameter;
3795 expect(functionParameter.returnType, isNull);
3796 expect(functionParameter.identifier, isNotNull);
3797 expect(functionParameter.typeParameters, isNull);
3798 expect(functionParameter.parameters, isNotNull);
3799 }
3800
3801 void test_parseNormalFormalParameter_function_noType_nullable() {
3802 enableNnbd = true;
3803 NormalFormalParameter parameter = parseNormalFormalParameter('a()?');
3804 expect(parameter, isNotNull);
3805 assertNoErrors();
3806 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
3807 FunctionTypedFormalParameter functionParameter = parameter;
3808 expect(functionParameter.returnType, isNull);
3809 expect(functionParameter.identifier, isNotNull);
3810 expect(functionParameter.typeParameters, isNull);
3811 expect(functionParameter.parameters, isNotNull);
3812 expect(functionParameter.question, isNotNull);
3813 }
3814
3815 void test_parseNormalFormalParameter_function_noType_typeParameterComments() {
3816 enableGenericMethodComments = true;
3817 NormalFormalParameter parameter = parseNormalFormalParameter('a/*<E>*/()');
3818 expect(parameter, isNotNull);
3819 assertNoErrors();
3820 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
3821 FunctionTypedFormalParameter functionParameter = parameter;
3822 expect(functionParameter.returnType, isNull);
3823 expect(functionParameter.identifier, isNotNull);
3824 expect(functionParameter.typeParameters, isNotNull);
3825 expect(functionParameter.parameters, isNotNull);
3826 }
3827
3828 void test_parseNormalFormalParameter_function_noType_typeParameters() {
3829 NormalFormalParameter parameter = parseNormalFormalParameter('a<E>()');
3830 expect(parameter, isNotNull);
3831 assertNoErrors();
3832 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
3833 FunctionTypedFormalParameter functionParameter = parameter;
3834 expect(functionParameter.returnType, isNull);
3835 expect(functionParameter.identifier, isNotNull);
3836 expect(functionParameter.typeParameters, isNotNull);
3837 expect(functionParameter.parameters, isNotNull);
3838 expect(functionParameter.question, isNull);
3839 expect(functionParameter.question, isNull);
3840 }
3841
3842 void
3843 test_parseNormalFormalParameter_function_noType_typeParameters_nullable() {
3844 enableNnbd = true;
3845 NormalFormalParameter parameter = parseNormalFormalParameter('a<E>()?');
3846 expect(parameter, isNotNull);
3847 assertNoErrors();
3848 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
3849 FunctionTypedFormalParameter functionParameter = parameter;
3850 expect(functionParameter.returnType, isNull);
3851 expect(functionParameter.identifier, isNotNull);
3852 expect(functionParameter.typeParameters, isNotNull);
3853 expect(functionParameter.parameters, isNotNull);
3854 expect(functionParameter.question, isNotNull);
3855 }
3856
3857 void test_parseNormalFormalParameter_function_type() {
3858 NormalFormalParameter parameter = parseNormalFormalParameter('A a()');
3859 expect(parameter, isNotNull);
3860 assertNoErrors();
3861 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
3862 FunctionTypedFormalParameter functionParameter = parameter;
3863 expect(functionParameter.returnType, isNotNull);
3864 expect(functionParameter.identifier, isNotNull);
3865 expect(functionParameter.typeParameters, isNull);
3866 expect(functionParameter.parameters, isNotNull);
3867 expect(functionParameter.question, isNull);
3868 }
3869
3870 void test_parseNormalFormalParameter_function_type_nullable() {
3871 enableNnbd = true;
3872 NormalFormalParameter parameter = parseNormalFormalParameter('A a()?');
3873 expect(parameter, isNotNull);
3874 assertNoErrors();
3875 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
3876 FunctionTypedFormalParameter functionParameter = parameter;
3877 expect(functionParameter.returnType, isNotNull);
3878 expect(functionParameter.identifier, isNotNull);
3879 expect(functionParameter.typeParameters, isNull);
3880 expect(functionParameter.parameters, isNotNull);
3881 expect(functionParameter.question, isNotNull);
3882 }
3883
3884 void test_parseNormalFormalParameter_function_type_typeParameterComments() {
3885 enableGenericMethodComments = true;
3886 NormalFormalParameter parameter =
3887 parseNormalFormalParameter('A a/*<E>*/()');
3888 expect(parameter, isNotNull);
3889 assertNoErrors();
3890 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
3891 FunctionTypedFormalParameter functionParameter = parameter;
3892 expect(functionParameter.returnType, isNotNull);
3893 expect(functionParameter.identifier, isNotNull);
3894 expect(functionParameter.typeParameters, isNotNull);
3895 expect(functionParameter.parameters, isNotNull);
3896 expect(functionParameter.question, isNull);
3897 }
3898
3899 void test_parseNormalFormalParameter_function_type_typeParameters() {
3900 NormalFormalParameter parameter = parseNormalFormalParameter('A a<E>()');
3901 expect(parameter, isNotNull);
3902 assertNoErrors();
3903 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
3904 FunctionTypedFormalParameter functionParameter = parameter;
3905 expect(functionParameter.returnType, isNotNull);
3906 expect(functionParameter.identifier, isNotNull);
3907 expect(functionParameter.typeParameters, isNotNull);
3908 expect(functionParameter.parameters, isNotNull);
3909 expect(functionParameter.question, isNull);
3910 }
3911
3912 void test_parseNormalFormalParameter_function_type_typeParameters_nullable() {
3913 enableNnbd = true;
3914 NormalFormalParameter parameter = parseNormalFormalParameter('A a<E>()?');
3915 expect(parameter, isNotNull);
3916 assertNoErrors();
3917 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
3918 FunctionTypedFormalParameter functionParameter = parameter;
3919 expect(functionParameter.returnType, isNotNull);
3920 expect(functionParameter.identifier, isNotNull);
3921 expect(functionParameter.typeParameters, isNotNull);
3922 expect(functionParameter.parameters, isNotNull);
3923 expect(functionParameter.question, isNotNull);
3924 }
3925
3926 void test_parseNormalFormalParameter_function_void() {
3927 NormalFormalParameter parameter = parseNormalFormalParameter('void a()');
3928 expect(parameter, isNotNull);
3929 assertNoErrors();
3930 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
3931 FunctionTypedFormalParameter functionParameter = parameter;
3932 expect(functionParameter.returnType, isNotNull);
3933 expect(functionParameter.identifier, isNotNull);
3934 expect(functionParameter.typeParameters, isNull);
3935 expect(functionParameter.parameters, isNotNull);
3936 expect(functionParameter.question, isNull);
3937 }
3938
3939 void test_parseNormalFormalParameter_function_void_nullable() {
3940 enableNnbd = true;
3941 NormalFormalParameter parameter = parseNormalFormalParameter('void a()?');
3942 expect(parameter, isNotNull);
3943 assertNoErrors();
3944 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
3945 FunctionTypedFormalParameter functionParameter = parameter;
3946 expect(functionParameter.returnType, isNotNull);
3947 expect(functionParameter.identifier, isNotNull);
3948 expect(functionParameter.typeParameters, isNull);
3949 expect(functionParameter.parameters, isNotNull);
3950 expect(functionParameter.question, isNotNull);
3951 }
3952
3953 void test_parseNormalFormalParameter_function_void_typeParameterComments() {
3954 enableGenericMethodComments = true;
3955 NormalFormalParameter parameter =
3956 parseNormalFormalParameter('void a/*<E>*/()');
3957 expect(parameter, isNotNull);
3958 assertNoErrors();
3959 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
3960 FunctionTypedFormalParameter functionParameter = parameter;
3961 expect(functionParameter.returnType, isNotNull);
3962 expect(functionParameter.identifier, isNotNull);
3963 expect(functionParameter.typeParameters, isNotNull);
3964 expect(functionParameter.parameters, isNotNull);
3965 expect(functionParameter.question, isNull);
3966 }
3967
3968 void test_parseNormalFormalParameter_function_void_typeParameters() {
3969 NormalFormalParameter parameter = parseNormalFormalParameter('void a<E>()');
3970 expect(parameter, isNotNull);
3971 assertNoErrors();
3972 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
3973 FunctionTypedFormalParameter functionParameter = parameter;
3974 expect(functionParameter.returnType, isNotNull);
3975 expect(functionParameter.identifier, isNotNull);
3976 expect(functionParameter.typeParameters, isNotNull);
3977 expect(functionParameter.parameters, isNotNull);
3978 expect(functionParameter.question, isNull);
3979 }
3980
3981 void test_parseNormalFormalParameter_function_void_typeParameters_nullable() {
3982 enableNnbd = true;
3983 NormalFormalParameter parameter =
3984 parseNormalFormalParameter('void a<E>()?');
3985 expect(parameter, isNotNull);
3986 assertNoErrors();
3987 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
3988 FunctionTypedFormalParameter functionParameter = parameter;
3989 expect(functionParameter.returnType, isNotNull);
3990 expect(functionParameter.identifier, isNotNull);
3991 expect(functionParameter.typeParameters, isNotNull);
3992 expect(functionParameter.parameters, isNotNull);
3993 expect(functionParameter.question, isNotNull);
3994 }
3995
3996 void test_parseNormalFormalParameter_simple_const_noType() {
3997 NormalFormalParameter parameter = parseNormalFormalParameter('const a');
3998 expect(parameter, isNotNull);
3999 assertNoErrors();
4000 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
4001 SimpleFormalParameter simpleParameter = parameter;
4002 expect(simpleParameter.keyword, isNotNull);
4003 expect(simpleParameter.type, isNull);
4004 expect(simpleParameter.identifier, isNotNull);
4005 }
4006
4007 void test_parseNormalFormalParameter_simple_const_type() {
4008 NormalFormalParameter parameter = parseNormalFormalParameter('const A a');
4009 expect(parameter, isNotNull);
4010 assertNoErrors();
4011 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
4012 SimpleFormalParameter simpleParameter = parameter;
4013 expect(simpleParameter.keyword, isNotNull);
4014 expect(simpleParameter.type, isNotNull);
4015 expect(simpleParameter.identifier, isNotNull);
4016 }
4017
4018 void test_parseNormalFormalParameter_simple_final_noType() {
4019 NormalFormalParameter parameter = parseNormalFormalParameter('final a');
4020 expect(parameter, isNotNull);
4021 assertNoErrors();
4022 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
4023 SimpleFormalParameter simpleParameter = parameter;
4024 expect(simpleParameter.keyword, isNotNull);
4025 expect(simpleParameter.type, isNull);
4026 expect(simpleParameter.identifier, isNotNull);
4027 }
4028
4029 void test_parseNormalFormalParameter_simple_final_type() {
4030 NormalFormalParameter parameter = parseNormalFormalParameter('final A a');
4031 expect(parameter, isNotNull);
4032 assertNoErrors();
4033 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
4034 SimpleFormalParameter simpleParameter = parameter;
4035 expect(simpleParameter.keyword, isNotNull);
4036 expect(simpleParameter.type, isNotNull);
4037 expect(simpleParameter.identifier, isNotNull);
4038 }
4039
4040 void test_parseNormalFormalParameter_simple_noName() {
4041 NormalFormalParameter parameter =
4042 parseNormalFormalParameter('a', inFunctionType: true);
4043 expect(parameter, isNotNull);
4044 assertNoErrors();
4045 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
4046 SimpleFormalParameter simpleParameter = parameter;
4047 expect(simpleParameter.keyword, isNull);
4048 expect(simpleParameter.type, isNotNull);
4049 expect(simpleParameter.identifier, isNull);
4050 }
4051
4052 void test_parseNormalFormalParameter_simple_noType() {
4053 NormalFormalParameter parameter = parseNormalFormalParameter('a');
4054 expect(parameter, isNotNull);
4055 assertNoErrors();
4056 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
4057 SimpleFormalParameter simpleParameter = parameter;
4058 expect(simpleParameter.keyword, isNull);
4059 expect(simpleParameter.type, isNull);
4060 expect(simpleParameter.identifier, isNotNull);
4061 }
4062
4063 void test_parseNormalFormalParameter_simple_noType_namedCovariant() {
4064 NormalFormalParameter parameter = parseNormalFormalParameter('covariant');
4065 expect(parameter, isNotNull);
4066 assertNoErrors();
4067 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
4068 SimpleFormalParameter simpleParameter = parameter;
4069 expect(simpleParameter.covariantKeyword, isNull);
4070 expect(simpleParameter.keyword, isNull);
4071 expect(simpleParameter.type, isNull);
4072 expect(simpleParameter.identifier, isNotNull);
4073 }
4074
4075 void test_parseNormalFormalParameter_simple_type() {
4076 NormalFormalParameter parameter = parseNormalFormalParameter('A a');
4077 expect(parameter, isNotNull);
4078 assertNoErrors();
4079 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
4080 SimpleFormalParameter simpleParameter = parameter;
4081 expect(simpleParameter.keyword, isNull);
4082 expect(simpleParameter.type, isNotNull);
4083 expect(simpleParameter.identifier, isNotNull);
4084 }
4085 }
4086
2974 @reflectiveTest 4087 @reflectiveTest
2975 class NonErrorParserTest extends ParserTestCase { 4088 class NonErrorParserTest extends ParserTestCase {
2976 void test_constFactory_external() { 4089 void test_constFactory_external() {
2977 createParser('external const factory C();'); 4090 createParser('external const factory C();');
2978 ClassMember member = parser.parseClassMember('C'); 4091 ClassMember member = parser.parseClassMember('C');
2979 expectNotNullIfNoErrors(member); 4092 expectNotNullIfNoErrors(member);
2980 listener.assertNoErrors(); 4093 listener.assertNoErrors();
2981 } 4094 }
2982 4095
2983 void test_staticMethod_notParsingFunctionBodies() { 4096 void test_staticMethod_notParsingFunctionBodies() {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
3047 GatheringErrorListener listener; 4160 GatheringErrorListener listener;
3048 4161
3049 /** 4162 /**
3050 * The parser used by the test. 4163 * The parser used by the test.
3051 * 4164 *
3052 * This field is typically initialized by invoking [createParser]. 4165 * This field is typically initialized by invoking [createParser].
3053 */ 4166 */
3054 Parser parser; 4167 Parser parser;
3055 4168
3056 @override 4169 @override
4170 void assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) {
4171 listener.assertErrorsWithCodes(expectedErrorCodes);
4172 }
4173
4174 @override
3057 void assertNoErrors() { 4175 void assertNoErrors() {
3058 listener.assertNoErrors(); 4176 listener.assertNoErrors();
3059 } 4177 }
3060 4178
3061 /** 4179 /**
3062 * Create the [parser] and [listener] used by a test. The [parser] will be 4180 * Create the [parser] and [listener] used by a test. The [parser] will be
3063 * prepared to parse the tokens scanned from the given [content]. 4181 * prepared to parse the tokens scanned from the given [content].
3064 */ 4182 */
3065 void createParser(String content) { 4183 void createParser(String content) {
3066 listener = new GatheringErrorListener(); 4184 listener = new GatheringErrorListener();
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
3165 */ 4283 */
3166 Expression parseExpression(String source, 4284 Expression parseExpression(String source,
3167 [List<ErrorCode> errorCodes = const <ErrorCode>[]]) { 4285 [List<ErrorCode> errorCodes = const <ErrorCode>[]]) {
3168 createParser(source); 4286 createParser(source);
3169 Expression expression = parser.parseExpression2(); 4287 Expression expression = parser.parseExpression2();
3170 expectNotNullIfNoErrors(expression); 4288 expectNotNullIfNoErrors(expression);
3171 listener.assertErrorsWithCodes(errorCodes); 4289 listener.assertErrorsWithCodes(errorCodes);
3172 return expression; 4290 return expression;
3173 } 4291 }
3174 4292
4293 @override
4294 FormalParameter parseFormalParameter(String code, ParameterKind kind,
4295 {List<ErrorCode> errorCodes: const <ErrorCode>[]}) {
4296 createParser(code);
4297 FormalParameter parameter = parser.parseFormalParameter(kind);
4298 assertErrorsWithCodes(errorCodes);
4299 return parameter;
4300 }
4301
4302 @override
4303 FormalParameterList parseFormalParameterList(String code,
4304 {bool inFunctionType: false,
4305 List<ErrorCode> errorCodes: const <ErrorCode>[]}) {
4306 createParser(code);
4307 FormalParameterList list =
4308 parser.parseFormalParameterList(inFunctionType: inFunctionType);
4309 assertErrorsWithCodes(errorCodes);
4310 return list;
4311 }
4312
3175 /** 4313 /**
3176 * Parses a single top level member of a compilation unit (other than a 4314 * Parses a single top level member of a compilation unit (other than a
3177 * directive), including any comment and/or metadata that precedes it. 4315 * directive), including any comment and/or metadata that precedes it.
3178 */ 4316 */
3179 CompilationUnitMember parseFullCompilationUnitMember() => 4317 CompilationUnitMember parseFullCompilationUnitMember() =>
3180 parser.parseCompilationUnitMember(parser.parseCommentAndMetadata()); 4318 parser.parseCompilationUnitMember(parser.parseCommentAndMetadata());
3181 4319
3182 @override 4320 @override
3183 Directive parseFullDirective() => 4321 Directive parseFullDirective() =>
3184 parser.parseDirective(parser.parseCommentAndMetadata()); 4322 parser.parseDirective(parser.parseCommentAndMetadata());
3185 4323
3186 /** 4324 /**
3187 * Parses a variable declaration list (equivalent to a variable declaration 4325 * Parses a variable declaration list (equivalent to a variable declaration
3188 * statement, but without the final comma). 4326 * statement, but without the final comma).
3189 */ 4327 */
3190 VariableDeclarationList parseFullVariableDeclarationList() => 4328 VariableDeclarationList parseFullVariableDeclarationList() =>
3191 parser.parseVariableDeclarationListAfterMetadata( 4329 parser.parseVariableDeclarationListAfterMetadata(
3192 parser.parseCommentAndMetadata()); 4330 parser.parseCommentAndMetadata());
3193 4331
4332 @override
4333 NormalFormalParameter parseNormalFormalParameter(String code,
4334 {bool inFunctionType: false,
4335 List<ErrorCode> errorCodes: const <ErrorCode>[]}) {
4336 createParser(code);
4337 FormalParameter parameter =
4338 parser.parseNormalFormalParameter(inFunctionType: inFunctionType);
4339 assertErrorsWithCodes(errorCodes);
4340 return parameter;
4341 }
4342
3194 /** 4343 /**
3195 * Parse the given [source] as a statement. The [errorCodes] are the error 4344 * Parse the given [source] as a statement. The [errorCodes] are the error
3196 * codes of the errors that are expected to be found. If 4345 * codes of the errors that are expected to be found. If
3197 * [enableLazyAssignmentOperators] is `true`, then lazy assignment operators 4346 * [enableLazyAssignmentOperators] is `true`, then lazy assignment operators
3198 * should be enabled. 4347 * should be enabled.
3199 */ 4348 */
3200 Statement parseStatement(String source, 4349 Statement parseStatement(String source,
3201 [List<ErrorCode> errorCodes = const <ErrorCode>[], 4350 [List<ErrorCode> errorCodes = const <ErrorCode>[],
3202 bool enableLazyAssignmentOperators]) { 4351 bool enableLazyAssignmentOperators]) {
3203 GatheringErrorListener listener = new GatheringErrorListener(); 4352 GatheringErrorListener listener = new GatheringErrorListener();
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
3399 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, 4548 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
3400 SimpleIdentifier, expression.leftOperand); 4549 SimpleIdentifier, expression.leftOperand);
3401 expect(expression.leftOperand.isSynthetic, isTrue); 4550 expect(expression.leftOperand.isSynthetic, isTrue);
3402 } 4551 }
3403 4552
3404 void test_bitwiseAndExpression_missing_LHS_RHS() { 4553 void test_bitwiseAndExpression_missing_LHS_RHS() {
3405 BinaryExpression expression = parseExpression("&", [ 4554 BinaryExpression expression = parseExpression("&", [
3406 ParserErrorCode.MISSING_IDENTIFIER, 4555 ParserErrorCode.MISSING_IDENTIFIER,
3407 ParserErrorCode.MISSING_IDENTIFIER 4556 ParserErrorCode.MISSING_IDENTIFIER
3408 ]); 4557 ]);
3409 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
3410 SimpleIdentifier, expression.leftOperand);
3411 expect(expression.leftOperand.isSynthetic, isTrue);
3412 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
3413 SimpleIdentifier, expression.rightOperand);
3414 expect(expression.rightOperand.isSynthetic, isTrue);
3415 }
3416
3417 void test_bitwiseAndExpression_missing_RHS() {
3418 BinaryExpression expression =
3419 parseExpression("x &", [ParserErrorCode.MISSING_IDENTIFIER]);
3420 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
3421 SimpleIdentifier, expression.rightOperand);
3422 expect(expression.rightOperand.isSynthetic, isTrue);
3423 }
3424
3425 void test_bitwiseAndExpression_missing_RHS_super() {
3426 BinaryExpression expression =
3427 parseExpression("super &", [ParserErrorCode.MISSING_IDENTIFIER]);
3428 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
3429 SimpleIdentifier, expression.rightOperand);
3430 expect(expression.rightOperand.isSynthetic, isTrue);
3431 }
3432
3433 void test_bitwiseAndExpression_precedence_equality_left() {
3434 BinaryExpression expression = parseExpression("== &&", [
3435 ParserErrorCode.MISSING_IDENTIFIER,
3436 ParserErrorCode.MISSING_IDENTIFIER,
3437 ParserErrorCode.MISSING_IDENTIFIER
3438 ]);
3439 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
3440 BinaryExpression, expression.leftOperand);
3441 }
3442
3443 void test_bitwiseAndExpression_precedence_equality_right() {
3444 BinaryExpression expression = parseExpression("&& ==", [
3445 ParserErrorCode.MISSING_IDENTIFIER,
3446 ParserErrorCode.MISSING_IDENTIFIER,
3447 ParserErrorCode.MISSING_IDENTIFIER
3448 ]);
3449 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
3450 BinaryExpression, expression.rightOperand);
3451 }
3452
3453 void test_bitwiseAndExpression_super() {
3454 BinaryExpression expression = parseExpression("super & &", [
3455 ParserErrorCode.MISSING_IDENTIFIER,
3456 ParserErrorCode.MISSING_IDENTIFIER
3457 ]);
3458 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
3459 BinaryExpression, expression.leftOperand);
3460 }
3461
3462 void test_bitwiseOrExpression_missing_LHS() {
3463 BinaryExpression expression =
3464 parseExpression("| y", [ParserErrorCode.MISSING_IDENTIFIER]);
3465 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
3466 SimpleIdentifier, expression.leftOperand);
3467 expect(expression.leftOperand.isSynthetic, isTrue);
3468 }
3469
3470 void test_bitwiseOrExpression_missing_LHS_RHS() {
3471 BinaryExpression expression = parseExpression("|", [
3472 ParserErrorCode.MISSING_IDENTIFIER,
3473 ParserErrorCode.MISSING_IDENTIFIER
3474 ]);
3475 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
3476 SimpleIdentifier, expression.leftOperand);
3477 expect(expression.leftOperand.isSynthetic, isTrue);
3478 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
3479 SimpleIdentifier, expression.rightOperand);
3480 expect(expression.rightOperand.isSynthetic, isTrue);
3481 }
3482
3483 void test_bitwiseOrExpression_missing_RHS() {
3484 BinaryExpression expression =
3485 parseExpression("x |", [ParserErrorCode.MISSING_IDENTIFIER]);
3486 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
3487 SimpleIdentifier, expression.rightOperand);
3488 expect(expression.rightOperand.isSynthetic, isTrue);
3489 }
3490
3491 void test_bitwiseOrExpression_missing_RHS_super() {
3492 BinaryExpression expression =
3493 parseExpression("super |", [ParserErrorCode.MISSING_IDENTIFIER]);
3494 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
3495 SimpleIdentifier, expression.rightOperand);
3496 expect(expression.rightOperand.isSynthetic, isTrue);
3497 }
3498
3499 void test_bitwiseOrExpression_precedence_xor_left() {
3500 BinaryExpression expression = parseExpression("^ |", [
3501 ParserErrorCode.MISSING_IDENTIFIER,
3502 ParserErrorCode.MISSING_IDENTIFIER,
3503 ParserErrorCode.MISSING_IDENTIFIER
3504 ]);
3505 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
3506 BinaryExpression, expression.leftOperand);
3507 }
3508
3509 void test_bitwiseOrExpression_precedence_xor_right() {
3510 BinaryExpression expression = parseExpression("| ^", [
3511 ParserErrorCode.MISSING_IDENTIFIER,
3512 ParserErrorCode.MISSING_IDENTIFIER,
3513 ParserErrorCode.MISSING_IDENTIFIER
3514 ]);
3515 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
3516 BinaryExpression, expression.rightOperand);
3517 }
3518
3519 void test_bitwiseOrExpression_super() {
3520 BinaryExpression expression = parseExpression("super | |", [
3521 ParserErrorCode.MISSING_IDENTIFIER,
3522 ParserErrorCode.MISSING_IDENTIFIER
3523 ]);
3524 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
3525 BinaryExpression, expression.leftOperand);
3526 }
3527
3528 void test_bitwiseXorExpression_missing_LHS() {
3529 BinaryExpression expression =
3530 parseExpression("^ y", [ParserErrorCode.MISSING_IDENTIFIER]);
3531 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
3532 SimpleIdentifier, expression.leftOperand);
3533 expect(expression.leftOperand.isSynthetic, isTrue);
3534 }
3535
3536 void test_bitwiseXorExpression_missing_LHS_RHS() {
3537 BinaryExpression expression = parseExpression("^", [
3538 ParserErrorCode.MISSING_IDENTIFIER,
3539 ParserErrorCode.MISSING_IDENTIFIER
3540 ]);
3541 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
3542 SimpleIdentifier, expression.leftOperand);
3543 expect(expression.leftOperand.isSynthetic, isTrue);
3544 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
3545 SimpleIdentifier, expression.rightOperand);
3546 expect(expression.rightOperand.isSynthetic, isTrue);
3547 }
3548
3549 void test_bitwiseXorExpression_missing_RHS() {
3550 BinaryExpression expression =
3551 parseExpression("x ^", [ParserErrorCode.MISSING_IDENTIFIER]);
3552 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
3553 SimpleIdentifier, expression.rightOperand);
3554 expect(expression.rightOperand.isSynthetic, isTrue);
3555 }
3556
3557 void test_bitwiseXorExpression_missing_RHS_super() {
3558 BinaryExpression expression =
3559 parseExpression("super ^", [ParserErrorCode.MISSING_IDENTIFIER]);
3560 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
3561 SimpleIdentifier, expression.rightOperand);
3562 expect(expression.rightOperand.isSynthetic, isTrue);
3563 }
3564
3565 void test_bitwiseXorExpression_precedence_and_left() {
3566 BinaryExpression expression = parseExpression("& ^", [
3567 ParserErrorCode.MISSING_IDENTIFIER,
3568 ParserErrorCode.MISSING_IDENTIFIER,
3569 ParserErrorCode.MISSING_IDENTIFIER
3570 ]);
3571 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
3572 BinaryExpression, expression.leftOperand);
3573 }
3574
3575 void test_bitwiseXorExpression_precedence_and_right() {
3576 BinaryExpression expression = parseExpression("^ &", [
3577 ParserErrorCode.MISSING_IDENTIFIER,
3578 ParserErrorCode.MISSING_IDENTIFIER,
3579 ParserErrorCode.MISSING_IDENTIFIER
3580 ]);
3581 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
3582 BinaryExpression, expression.rightOperand);
3583 }
3584
3585 void test_bitwiseXorExpression_super() {
3586 BinaryExpression expression = parseExpression("super ^ ^", [
3587 ParserErrorCode.MISSING_IDENTIFIER,
3588 ParserErrorCode.MISSING_IDENTIFIER
3589 ]);
3590 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
3591 BinaryExpression, expression.leftOperand);
3592 }
3593
3594 void test_classTypeAlias_withBody() {
3595 parseCompilationUnit(
3596 r'''
3597 class A {}
3598 class B = Object with A {}''',
3599 [ParserErrorCode.EXPECTED_TOKEN]);
3600 }
3601
3602 void test_conditionalExpression_missingElse() {
3603 createParser('x ? y :');
3604 Expression expression = parser.parseConditionalExpression();
3605 expectNotNullIfNoErrors(expression);
3606 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]);
3607 expect(expression, new isInstanceOf<ConditionalExpression>());
3608 ConditionalExpression conditionalExpression = expression;
3609 expect(conditionalExpression.elseExpression,
3610 new isInstanceOf<SimpleIdentifier>());
3611 expect(conditionalExpression.elseExpression.isSynthetic, isTrue);
3612 }
3613
3614 void test_conditionalExpression_missingThen() {
3615 createParser('x ? : z');
3616 Expression expression = parser.parseConditionalExpression();
3617 expectNotNullIfNoErrors(expression);
3618 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]);
3619 expect(expression, new isInstanceOf<ConditionalExpression>());
3620 ConditionalExpression conditionalExpression = expression;
3621 expect(conditionalExpression.thenExpression,
3622 new isInstanceOf<SimpleIdentifier>());
3623 expect(conditionalExpression.thenExpression.isSynthetic, isTrue);
3624 }
3625
3626 void test_declarationBeforeDirective() {
3627 CompilationUnit unit = parseCompilationUnit(
3628 "class foo { } import 'bar.dart';",
3629 [ParserErrorCode.DIRECTIVE_AFTER_DECLARATION]);
3630 expect(unit.directives, hasLength(1));
3631 expect(unit.declarations, hasLength(1));
3632 ClassDeclaration classDecl = unit.childEntities.first;
3633 expect(classDecl, isNotNull);
3634 expect(classDecl.name.name, 'foo');
3635 }
3636
3637 void test_equalityExpression_missing_LHS() {
3638 BinaryExpression expression =
3639 parseExpression("== y", [ParserErrorCode.MISSING_IDENTIFIER]);
3640 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
3641 SimpleIdentifier, expression.leftOperand);
3642 expect(expression.leftOperand.isSynthetic, isTrue);
3643 }
3644
3645 void test_equalityExpression_missing_LHS_RHS() {
3646 BinaryExpression expression = parseExpression("==", [
3647 ParserErrorCode.MISSING_IDENTIFIER,
3648 ParserErrorCode.MISSING_IDENTIFIER
3649 ]);
3650 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
3651 SimpleIdentifier, expression.leftOperand);
3652 expect(expression.leftOperand.isSynthetic, isTrue);
3653 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
3654 SimpleIdentifier, expression.rightOperand);
3655 expect(expression.rightOperand.isSynthetic, isTrue);
3656 }
3657
3658 void test_equalityExpression_missing_RHS() {
3659 BinaryExpression expression =
3660 parseExpression("x ==", [ParserErrorCode.MISSING_IDENTIFIER]);
3661 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
3662 SimpleIdentifier, expression.rightOperand);
3663 expect(expression.rightOperand.isSynthetic, isTrue);
3664 }
3665
3666 void test_equalityExpression_missing_RHS_super() {
3667 BinaryExpression expression =
3668 parseExpression("super ==", [ParserErrorCode.MISSING_IDENTIFIER]);
3669 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
3670 SimpleIdentifier, expression.rightOperand);
3671 expect(expression.rightOperand.isSynthetic, isTrue);
3672 }
3673
3674 void test_equalityExpression_precedence_relational_left() {
3675 BinaryExpression expression = parseExpression("is ==", [
3676 ParserErrorCode.EXPECTED_TYPE_NAME,
3677 ParserErrorCode.MISSING_IDENTIFIER,
3678 ParserErrorCode.MISSING_IDENTIFIER
3679 ]);
3680 EngineTestCase.assertInstanceOf(
3681 (obj) => obj is IsExpression, IsExpression, expression.leftOperand);
3682 }
3683
3684 void test_equalityExpression_precedence_relational_right() {
3685 BinaryExpression expression = parseExpression("== is", [
3686 ParserErrorCode.EXPECTED_TYPE_NAME,
3687 ParserErrorCode.MISSING_IDENTIFIER,
3688 ParserErrorCode.MISSING_IDENTIFIER
3689 ]);
3690 EngineTestCase.assertInstanceOf(
3691 (obj) => obj is IsExpression, IsExpression, expression.rightOperand);
3692 }
3693
3694 void test_equalityExpression_super() {
3695 BinaryExpression expression = parseExpression("super == ==", [
3696 ParserErrorCode.MISSING_IDENTIFIER,
3697 ParserErrorCode.MISSING_IDENTIFIER,
3698 ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND
3699 ]);
3700 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
3701 BinaryExpression, expression.leftOperand);
3702 }
3703
3704 void test_expressionList_multiple_end() {
3705 createParser(', 2, 3, 4');
3706 List<Expression> result = parser.parseExpressionList();
3707 expectNotNullIfNoErrors(result);
3708 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]);
3709 expect(result, hasLength(4));
3710 Expression syntheticExpression = result[0];
3711 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
3712 SimpleIdentifier, syntheticExpression);
3713 expect(syntheticExpression.isSynthetic, isTrue);
3714 }
3715
3716 void test_expressionList_multiple_middle() {
3717 createParser('1, 2, , 4');
3718 List<Expression> result = parser.parseExpressionList();
3719 expectNotNullIfNoErrors(result);
3720 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]);
3721 expect(result, hasLength(4));
3722 Expression syntheticExpression = result[2];
3723 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
3724 SimpleIdentifier, syntheticExpression);
3725 expect(syntheticExpression.isSynthetic, isTrue);
3726 }
3727
3728 void test_expressionList_multiple_start() {
3729 createParser('1, 2, 3,');
3730 List<Expression> result = parser.parseExpressionList();
3731 expectNotNullIfNoErrors(result);
3732 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]);
3733 expect(result, hasLength(4));
3734 Expression syntheticExpression = result[3];
3735 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
3736 SimpleIdentifier, syntheticExpression);
3737 expect(syntheticExpression.isSynthetic, isTrue);
3738 }
3739
3740 void test_functionExpression_in_ConstructorFieldInitializer() {
3741 CompilationUnit unit = parseCompilationUnit(
3742 "class A { A() : a = (){}; var v; }",
3743 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.UNEXPECTED_TOKEN]);
3744 // Make sure we recovered and parsed "var v" correctly
3745 ClassDeclaration declaration = unit.declarations[0] as ClassDeclaration;
3746 NodeList<ClassMember> members = declaration.members;
3747 ClassMember fieldDecl = members[1];
3748 EngineTestCase.assertInstanceOf(
3749 (obj) => obj is FieldDeclaration, FieldDeclaration, fieldDecl);
3750 NodeList<VariableDeclaration> vars =
3751 (fieldDecl as FieldDeclaration).fields.variables;
3752 expect(vars, hasLength(1));
3753 expect(vars[0].name.name, "v");
3754 }
3755
3756 void test_functionExpression_named() {
3757 parseExpression("m(f() => 0);", [ParserErrorCode.EXPECTED_TOKEN]);
3758 }
3759
3760 void test_importDirectivePartial_as() {
3761 CompilationUnit unit = parseCompilationUnit(
3762 "import 'b.dart' d as b;", [ParserErrorCode.UNEXPECTED_TOKEN]);
3763 ImportDirective importDirective = unit.childEntities.first;
3764 expect(importDirective.asKeyword, isNotNull);
3765 expect(unit.directives, hasLength(1));
3766 expect(unit.declarations, hasLength(0));
3767 }
3768
3769 void test_importDirectivePartial_hide() {
3770 CompilationUnit unit = parseCompilationUnit(
3771 "import 'b.dart' d hide foo;", [ParserErrorCode.UNEXPECTED_TOKEN]);
3772 ImportDirective importDirective = unit.childEntities.first;
3773 expect(importDirective.combinators, hasLength(1));
3774 expect(unit.directives, hasLength(1));
3775 expect(unit.declarations, hasLength(0));
3776 }
3777
3778 void test_importDirectivePartial_show() {
3779 CompilationUnit unit = parseCompilationUnit(
3780 "import 'b.dart' d show foo;", [ParserErrorCode.UNEXPECTED_TOKEN]);
3781 ImportDirective importDirective = unit.childEntities.first;
3782 expect(importDirective.combinators, hasLength(1));
3783 expect(unit.directives, hasLength(1));
3784 expect(unit.declarations, hasLength(0));
3785 }
3786
3787 void test_incomplete_conditionalExpression() {
3788 parseExpression("x ? 0",
3789 [ParserErrorCode.EXPECTED_TOKEN, ParserErrorCode.MISSING_IDENTIFIER]);
3790 }
3791
3792 void test_incomplete_constructorInitializers_empty() {
3793 createParser('C() : {}');
3794 ClassMember member = parser.parseClassMember('C');
3795 expectNotNullIfNoErrors(member);
3796 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_INITIALIZER]);
3797 }
3798
3799 void test_incomplete_constructorInitializers_missingEquals() {
3800 createParser('C() : x(3) {}');
3801 ClassMember member = parser.parseClassMember('C');
3802 expectNotNullIfNoErrors(member);
3803 listener.assertErrorsWithCodes(
3804 [ParserErrorCode.MISSING_ASSIGNMENT_IN_INITIALIZER]);
3805 expect(member, new isInstanceOf<ConstructorDeclaration>());
3806 NodeList<ConstructorInitializer> initializers =
3807 (member as ConstructorDeclaration).initializers;
3808 expect(initializers, hasLength(1));
3809 ConstructorInitializer initializer = initializers[0];
3810 expect(initializer, new isInstanceOf<ConstructorFieldInitializer>());
3811 Expression expression =
3812 (initializer as ConstructorFieldInitializer).expression;
3813 expect(expression, isNotNull);
3814 expect(expression, new isInstanceOf<ParenthesizedExpression>());
3815 }
3816
3817 void test_incomplete_constructorInitializers_variable() {
3818 createParser('C() : x {}');
3819 ClassMember member = parser.parseClassMember('C');
3820 expectNotNullIfNoErrors(member);
3821 listener.assertErrorsWithCodes(
3822 [ParserErrorCode.MISSING_ASSIGNMENT_IN_INITIALIZER]);
3823 }
3824
3825 @failingTest
3826 void test_incomplete_returnType() {
3827 parseCompilationUnit(r'''
3828 Map<Symbol, convertStringToSymbolMap(Map<String, dynamic> map) {
3829 if (map == null) return null;
3830 Map<Symbol, dynamic> result = new Map<Symbol, dynamic>();
3831 map.forEach((name, value) {
3832 result[new Symbol(name)] = value;
3833 });
3834 return result;
3835 }''');
3836 }
3837
3838 void test_incomplete_topLevelFunction() {
3839 parseCompilationUnit("foo();", [ParserErrorCode.MISSING_FUNCTION_BODY]);
3840 }
3841
3842 void test_incomplete_topLevelVariable() {
3843 CompilationUnit unit =
3844 parseCompilationUnit("String", [ParserErrorCode.EXPECTED_EXECUTABLE]);
3845 NodeList<CompilationUnitMember> declarations = unit.declarations;
3846 expect(declarations, hasLength(1));
3847 CompilationUnitMember member = declarations[0];
3848 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableDeclaration,
3849 TopLevelVariableDeclaration, member);
3850 NodeList<VariableDeclaration> variables =
3851 (member as TopLevelVariableDeclaration).variables.variables;
3852 expect(variables, hasLength(1));
3853 SimpleIdentifier name = variables[0].name;
3854 expect(name.isSynthetic, isTrue);
3855 }
3856
3857 void test_incomplete_topLevelVariable_const() {
3858 CompilationUnit unit = parseCompilationUnit("const ",
3859 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]);
3860 NodeList<CompilationUnitMember> declarations = unit.declarations;
3861 expect(declarations, hasLength(1));
3862 CompilationUnitMember member = declarations[0];
3863 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableDeclaration,
3864 TopLevelVariableDeclaration, member);
3865 NodeList<VariableDeclaration> variables =
3866 (member as TopLevelVariableDeclaration).variables.variables;
3867 expect(variables, hasLength(1));
3868 SimpleIdentifier name = variables[0].name;
3869 expect(name.isSynthetic, isTrue);
3870 }
3871
3872 void test_incomplete_topLevelVariable_final() {
3873 CompilationUnit unit = parseCompilationUnit("final ",
3874 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]);
3875 NodeList<CompilationUnitMember> declarations = unit.declarations;
3876 expect(declarations, hasLength(1));
3877 CompilationUnitMember member = declarations[0];
3878 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableDeclaration,
3879 TopLevelVariableDeclaration, member);
3880 NodeList<VariableDeclaration> variables =
3881 (member as TopLevelVariableDeclaration).variables.variables;
3882 expect(variables, hasLength(1));
3883 SimpleIdentifier name = variables[0].name;
3884 expect(name.isSynthetic, isTrue);
3885 }
3886
3887 void test_incomplete_topLevelVariable_var() {
3888 CompilationUnit unit = parseCompilationUnit("var ",
3889 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]);
3890 NodeList<CompilationUnitMember> declarations = unit.declarations;
3891 expect(declarations, hasLength(1));
3892 CompilationUnitMember member = declarations[0];
3893 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableDeclaration,
3894 TopLevelVariableDeclaration, member);
3895 NodeList<VariableDeclaration> variables =
3896 (member as TopLevelVariableDeclaration).variables.variables;
3897 expect(variables, hasLength(1));
3898 SimpleIdentifier name = variables[0].name;
3899 expect(name.isSynthetic, isTrue);
3900 }
3901
3902 void test_incompleteField_const() {
3903 CompilationUnit unit = parseCompilationUnit(
3904 r'''
3905 class C {
3906 const
3907 }''',
3908 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]);
3909 NodeList<CompilationUnitMember> declarations = unit.declarations;
3910 expect(declarations, hasLength(1));
3911 CompilationUnitMember unitMember = declarations[0];
3912 EngineTestCase.assertInstanceOf(
3913 (obj) => obj is ClassDeclaration, ClassDeclaration, unitMember);
3914 NodeList<ClassMember> members = (unitMember as ClassDeclaration).members;
3915 expect(members, hasLength(1));
3916 ClassMember classMember = members[0];
3917 EngineTestCase.assertInstanceOf(
3918 (obj) => obj is FieldDeclaration, FieldDeclaration, classMember);
3919 VariableDeclarationList fieldList =
3920 (classMember as FieldDeclaration).fields;
3921 expect(fieldList.keyword.keyword, Keyword.CONST);
3922 NodeList<VariableDeclaration> fields = fieldList.variables;
3923 expect(fields, hasLength(1));
3924 VariableDeclaration field = fields[0];
3925 expect(field.name.isSynthetic, isTrue);
3926 }
3927
3928 void test_incompleteField_final() {
3929 CompilationUnit unit = parseCompilationUnit(
3930 r'''
3931 class C {
3932 final
3933 }''',
3934 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]);
3935 NodeList<CompilationUnitMember> declarations = unit.declarations;
3936 expect(declarations, hasLength(1));
3937 CompilationUnitMember unitMember = declarations[0];
3938 EngineTestCase.assertInstanceOf(
3939 (obj) => obj is ClassDeclaration, ClassDeclaration, unitMember);
3940 NodeList<ClassMember> members = (unitMember as ClassDeclaration).members;
3941 expect(members, hasLength(1));
3942 ClassMember classMember = members[0];
3943 EngineTestCase.assertInstanceOf(
3944 (obj) => obj is FieldDeclaration, FieldDeclaration, classMember);
3945 VariableDeclarationList fieldList =
3946 (classMember as FieldDeclaration).fields;
3947 expect(fieldList.keyword.keyword, Keyword.FINAL);
3948 NodeList<VariableDeclaration> fields = fieldList.variables;
3949 expect(fields, hasLength(1));
3950 VariableDeclaration field = fields[0];
3951 expect(field.name.isSynthetic, isTrue);
3952 }
3953
3954 void test_incompleteField_var() {
3955 CompilationUnit unit = parseCompilationUnit(
3956 r'''
3957 class C {
3958 var
3959 }''',
3960 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]);
3961 NodeList<CompilationUnitMember> declarations = unit.declarations;
3962 expect(declarations, hasLength(1));
3963 CompilationUnitMember unitMember = declarations[0];
3964 EngineTestCase.assertInstanceOf(
3965 (obj) => obj is ClassDeclaration, ClassDeclaration, unitMember);
3966 NodeList<ClassMember> members = (unitMember as ClassDeclaration).members;
3967 expect(members, hasLength(1));
3968 ClassMember classMember = members[0];
3969 EngineTestCase.assertInstanceOf(
3970 (obj) => obj is FieldDeclaration, FieldDeclaration, classMember);
3971 VariableDeclarationList fieldList =
3972 (classMember as FieldDeclaration).fields;
3973 expect(fieldList.keyword.keyword, Keyword.VAR);
3974 NodeList<VariableDeclaration> fields = fieldList.variables;
3975 expect(fields, hasLength(1));
3976 VariableDeclaration field = fields[0];
3977 expect(field.name.isSynthetic, isTrue);
3978 }
3979
3980 void test_incompleteForEach() {
3981 ForStatement statement = parseStatement('for (String item i) {}',
3982 [ParserErrorCode.EXPECTED_TOKEN, ParserErrorCode.EXPECTED_TOKEN]);
3983 expect(statement, new isInstanceOf<ForStatement>());
3984 expect(statement.toSource(), 'for (String item; i;) {}');
3985 expect(statement.leftSeparator, isNotNull);
3986 expect(statement.leftSeparator.type, TokenType.SEMICOLON);
3987 expect(statement.rightSeparator, isNotNull);
3988 expect(statement.rightSeparator.type, TokenType.SEMICOLON);
3989 }
3990
3991 void test_incompleteLocalVariable_atTheEndOfBlock() {
3992 Statement statement =
3993 parseStatement('String v }', [ParserErrorCode.EXPECTED_TOKEN]);
3994 expect(statement, new isInstanceOf<VariableDeclarationStatement>());
3995 expect(statement.toSource(), 'String v;');
3996 }
3997
3998 void test_incompleteLocalVariable_beforeIdentifier() {
3999 Statement statement =
4000 parseStatement('String v String v2;', [ParserErrorCode.EXPECTED_TOKEN]);
4001 expect(statement, new isInstanceOf<VariableDeclarationStatement>());
4002 expect(statement.toSource(), 'String v;');
4003 }
4004
4005 void test_incompleteLocalVariable_beforeKeyword() {
4006 Statement statement = parseStatement(
4007 'String v if (true) {}', [ParserErrorCode.EXPECTED_TOKEN]);
4008 expect(statement, new isInstanceOf<VariableDeclarationStatement>());
4009 expect(statement.toSource(), 'String v;');
4010 }
4011
4012 void test_incompleteLocalVariable_beforeNextBlock() {
4013 Statement statement =
4014 parseStatement('String v {}', [ParserErrorCode.EXPECTED_TOKEN]);
4015 expect(statement, new isInstanceOf<VariableDeclarationStatement>());
4016 expect(statement.toSource(), 'String v;');
4017 }
4018
4019 void test_incompleteLocalVariable_parameterizedType() {
4020 Statement statement =
4021 parseStatement('List<String> v {}', [ParserErrorCode.EXPECTED_TOKEN]);
4022 expect(statement, new isInstanceOf<VariableDeclarationStatement>());
4023 expect(statement.toSource(), 'List<String> v;');
4024 }
4025
4026 void test_incompleteTypeArguments_field() {
4027 CompilationUnit unit = parseCompilationUnit(
4028 r'''
4029 class C {
4030 final List<int f;
4031 }''',
4032 [ParserErrorCode.EXPECTED_TOKEN]);
4033 // one class
4034 List<CompilationUnitMember> declarations = unit.declarations;
4035 expect(declarations, hasLength(1));
4036 ClassDeclaration classDecl = declarations[0] as ClassDeclaration;
4037 // one field declaration
4038 List<ClassMember> members = classDecl.members;
4039 expect(members, hasLength(1));
4040 FieldDeclaration fieldDecl = members[0] as FieldDeclaration;
4041 // one field
4042 VariableDeclarationList fieldList = fieldDecl.fields;
4043 List<VariableDeclaration> fields = fieldList.variables;
4044 expect(fields, hasLength(1));
4045 VariableDeclaration field = fields[0];
4046 expect(field.name.name, 'f');
4047 // validate the type
4048 TypeArgumentList typeArguments = (fieldList.type as TypeName).typeArguments;
4049 expect(typeArguments.arguments, hasLength(1));
4050 // synthetic '>'
4051 Token token = typeArguments.endToken;
4052 expect(token.type, TokenType.GT);
4053 expect(token.isSynthetic, isTrue);
4054 }
4055
4056 void test_incompleteTypeParameters() {
4057 CompilationUnit unit = parseCompilationUnit(
4058 r'''
4059 class C<K {
4060 }''',
4061 [ParserErrorCode.EXPECTED_TOKEN]);
4062 // one class
4063 List<CompilationUnitMember> declarations = unit.declarations;
4064 expect(declarations, hasLength(1));
4065 ClassDeclaration classDecl = declarations[0] as ClassDeclaration;
4066 // validate the type parameters
4067 TypeParameterList typeParameters = classDecl.typeParameters;
4068 expect(typeParameters.typeParameters, hasLength(1));
4069 // synthetic '>'
4070 Token token = typeParameters.endToken;
4071 expect(token.type, TokenType.GT);
4072 expect(token.isSynthetic, isTrue);
4073 }
4074
4075 void test_invalidFunctionBodyModifier() {
4076 parseCompilationUnit(
4077 "f() sync {}", [ParserErrorCode.MISSING_STAR_AFTER_SYNC]);
4078 }
4079
4080 void test_isExpression_noType() {
4081 CompilationUnit unit = parseCompilationUnit(
4082 "class Bar<T extends Foo> {m(x){if (x is ) return;if (x is !)}}", [
4083 ParserErrorCode.EXPECTED_TYPE_NAME,
4084 ParserErrorCode.EXPECTED_TYPE_NAME,
4085 ParserErrorCode.MISSING_STATEMENT
4086 ]);
4087 ClassDeclaration declaration = unit.declarations[0] as ClassDeclaration;
4088 MethodDeclaration method = declaration.members[0] as MethodDeclaration;
4089 BlockFunctionBody body = method.body as BlockFunctionBody;
4090 IfStatement ifStatement = body.block.statements[1] as IfStatement;
4091 IsExpression expression = ifStatement.condition as IsExpression;
4092 expect(expression.expression, isNotNull);
4093 expect(expression.isOperator, isNotNull);
4094 expect(expression.notOperator, isNotNull);
4095 TypeAnnotation type = expression.type;
4096 expect(type, isNotNull);
4097 expect(type is TypeName && type.name.isSynthetic, isTrue);
4098 EngineTestCase.assertInstanceOf((obj) => obj is EmptyStatement,
4099 EmptyStatement, ifStatement.thenStatement);
4100 }
4101
4102 void test_keywordInPlaceOfIdentifier() {
4103 // TODO(brianwilkerson) We could do better with this.
4104 parseCompilationUnit("do() {}", [
4105 ParserErrorCode.EXPECTED_EXECUTABLE,
4106 ParserErrorCode.UNEXPECTED_TOKEN
4107 ]);
4108 }
4109
4110 void test_logicalAndExpression_missing_LHS() {
4111 BinaryExpression expression =
4112 parseExpression("&& y", [ParserErrorCode.MISSING_IDENTIFIER]);
4113 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
4114 SimpleIdentifier, expression.leftOperand);
4115 expect(expression.leftOperand.isSynthetic, isTrue);
4116 }
4117
4118 void test_logicalAndExpression_missing_LHS_RHS() {
4119 BinaryExpression expression = parseExpression("&&", [
4120 ParserErrorCode.MISSING_IDENTIFIER,
4121 ParserErrorCode.MISSING_IDENTIFIER
4122 ]);
4123 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, 4558 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
4124 SimpleIdentifier, expression.leftOperand); 4559 SimpleIdentifier, expression.leftOperand);
4125 expect(expression.leftOperand.isSynthetic, isTrue); 4560 expect(expression.leftOperand.isSynthetic, isTrue);
4126 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, 4561 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
4127 SimpleIdentifier, expression.rightOperand); 4562 SimpleIdentifier, expression.rightOperand);
4128 expect(expression.rightOperand.isSynthetic, isTrue); 4563 expect(expression.rightOperand.isSynthetic, isTrue);
4129 } 4564 }
4130 4565
4131 void test_logicalAndExpression_missing_RHS() { 4566 void test_bitwiseAndExpression_missing_RHS() {
4132 BinaryExpression expression = 4567 BinaryExpression expression =
4133 parseExpression("x &&", [ParserErrorCode.MISSING_IDENTIFIER]); 4568 parseExpression("x &", [ParserErrorCode.MISSING_IDENTIFIER]);
4134 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, 4569 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
4135 SimpleIdentifier, expression.rightOperand); 4570 SimpleIdentifier, expression.rightOperand);
4136 expect(expression.rightOperand.isSynthetic, isTrue); 4571 expect(expression.rightOperand.isSynthetic, isTrue);
4137 } 4572 }
4138 4573
4139 void test_logicalAndExpression_precedence_bitwiseOr_left() { 4574 void test_bitwiseAndExpression_missing_RHS_super() {
4140 BinaryExpression expression = parseExpression("| &&", [ 4575 BinaryExpression expression =
4576 parseExpression("super &", [ParserErrorCode.MISSING_IDENTIFIER]);
4577 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
4578 SimpleIdentifier, expression.rightOperand);
4579 expect(expression.rightOperand.isSynthetic, isTrue);
4580 }
4581
4582 void test_bitwiseAndExpression_precedence_equality_left() {
4583 BinaryExpression expression = parseExpression("== &&", [
4141 ParserErrorCode.MISSING_IDENTIFIER, 4584 ParserErrorCode.MISSING_IDENTIFIER,
4142 ParserErrorCode.MISSING_IDENTIFIER, 4585 ParserErrorCode.MISSING_IDENTIFIER,
4143 ParserErrorCode.MISSING_IDENTIFIER 4586 ParserErrorCode.MISSING_IDENTIFIER
4144 ]); 4587 ]);
4145 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, 4588 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
4146 BinaryExpression, expression.leftOperand); 4589 BinaryExpression, expression.leftOperand);
4147 } 4590 }
4148 4591
4149 void test_logicalAndExpression_precedence_bitwiseOr_right() { 4592 void test_bitwiseAndExpression_precedence_equality_right() {
4150 BinaryExpression expression = parseExpression("&& |", [ 4593 BinaryExpression expression = parseExpression("&& ==", [
4151 ParserErrorCode.MISSING_IDENTIFIER, 4594 ParserErrorCode.MISSING_IDENTIFIER,
4152 ParserErrorCode.MISSING_IDENTIFIER, 4595 ParserErrorCode.MISSING_IDENTIFIER,
4153 ParserErrorCode.MISSING_IDENTIFIER 4596 ParserErrorCode.MISSING_IDENTIFIER
4154 ]); 4597 ]);
4155 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, 4598 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
4156 BinaryExpression, expression.rightOperand); 4599 BinaryExpression, expression.rightOperand);
4157 } 4600 }
4158 4601
4159 void test_logicalOrExpression_missing_LHS() { 4602 void test_bitwiseAndExpression_super() {
4603 BinaryExpression expression = parseExpression("super & &", [
4604 ParserErrorCode.MISSING_IDENTIFIER,
4605 ParserErrorCode.MISSING_IDENTIFIER
4606 ]);
4607 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
4608 BinaryExpression, expression.leftOperand);
4609 }
4610
4611 void test_bitwiseOrExpression_missing_LHS() {
4160 BinaryExpression expression = 4612 BinaryExpression expression =
4161 parseExpression("|| y", [ParserErrorCode.MISSING_IDENTIFIER]); 4613 parseExpression("| y", [ParserErrorCode.MISSING_IDENTIFIER]);
4162 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, 4614 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
4163 SimpleIdentifier, expression.leftOperand); 4615 SimpleIdentifier, expression.leftOperand);
4164 expect(expression.leftOperand.isSynthetic, isTrue); 4616 expect(expression.leftOperand.isSynthetic, isTrue);
4165 } 4617 }
4166 4618
4167 void test_logicalOrExpression_missing_LHS_RHS() { 4619 void test_bitwiseOrExpression_missing_LHS_RHS() {
4168 BinaryExpression expression = parseExpression("||", [ 4620 BinaryExpression expression = parseExpression("|", [
4169 ParserErrorCode.MISSING_IDENTIFIER, 4621 ParserErrorCode.MISSING_IDENTIFIER,
4170 ParserErrorCode.MISSING_IDENTIFIER 4622 ParserErrorCode.MISSING_IDENTIFIER
4171 ]); 4623 ]);
4172 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, 4624 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
4173 SimpleIdentifier, expression.leftOperand); 4625 SimpleIdentifier, expression.leftOperand);
4174 expect(expression.leftOperand.isSynthetic, isTrue); 4626 expect(expression.leftOperand.isSynthetic, isTrue);
4175 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, 4627 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
4176 SimpleIdentifier, expression.rightOperand); 4628 SimpleIdentifier, expression.rightOperand);
4177 expect(expression.rightOperand.isSynthetic, isTrue); 4629 expect(expression.rightOperand.isSynthetic, isTrue);
4178 } 4630 }
4179 4631
4180 void test_logicalOrExpression_missing_RHS() { 4632 void test_bitwiseOrExpression_missing_RHS() {
4181 BinaryExpression expression = 4633 BinaryExpression expression =
4182 parseExpression("x ||", [ParserErrorCode.MISSING_IDENTIFIER]); 4634 parseExpression("x |", [ParserErrorCode.MISSING_IDENTIFIER]);
4183 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, 4635 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
4184 SimpleIdentifier, expression.rightOperand); 4636 SimpleIdentifier, expression.rightOperand);
4185 expect(expression.rightOperand.isSynthetic, isTrue); 4637 expect(expression.rightOperand.isSynthetic, isTrue);
4186 } 4638 }
4187 4639
4188 void test_logicalOrExpression_precedence_logicalAnd_left() { 4640 void test_bitwiseOrExpression_missing_RHS_super() {
4189 BinaryExpression expression = parseExpression("&& ||", [ 4641 BinaryExpression expression =
4642 parseExpression("super |", [ParserErrorCode.MISSING_IDENTIFIER]);
4643 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
4644 SimpleIdentifier, expression.rightOperand);
4645 expect(expression.rightOperand.isSynthetic, isTrue);
4646 }
4647
4648 void test_bitwiseOrExpression_precedence_xor_left() {
4649 BinaryExpression expression = parseExpression("^ |", [
4190 ParserErrorCode.MISSING_IDENTIFIER, 4650 ParserErrorCode.MISSING_IDENTIFIER,
4191 ParserErrorCode.MISSING_IDENTIFIER, 4651 ParserErrorCode.MISSING_IDENTIFIER,
4192 ParserErrorCode.MISSING_IDENTIFIER 4652 ParserErrorCode.MISSING_IDENTIFIER
4193 ]); 4653 ]);
4194 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, 4654 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
4195 BinaryExpression, expression.leftOperand); 4655 BinaryExpression, expression.leftOperand);
4196 } 4656 }
4197 4657
4198 void test_logicalOrExpression_precedence_logicalAnd_right() { 4658 void test_bitwiseOrExpression_precedence_xor_right() {
4199 BinaryExpression expression = parseExpression("|| &&", [ 4659 BinaryExpression expression = parseExpression("| ^", [
4200 ParserErrorCode.MISSING_IDENTIFIER, 4660 ParserErrorCode.MISSING_IDENTIFIER,
4201 ParserErrorCode.MISSING_IDENTIFIER, 4661 ParserErrorCode.MISSING_IDENTIFIER,
4202 ParserErrorCode.MISSING_IDENTIFIER 4662 ParserErrorCode.MISSING_IDENTIFIER
4203 ]); 4663 ]);
4204 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, 4664 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
4205 BinaryExpression, expression.rightOperand); 4665 BinaryExpression, expression.rightOperand);
4206 } 4666 }
4207 4667
4208 void test_missing_commaInArgumentList() { 4668 void test_bitwiseOrExpression_super() {
4209 parseExpression("f(x: 1 y: 2)", [ParserErrorCode.EXPECTED_TOKEN]); 4669 BinaryExpression expression = parseExpression("super | |", [
4670 ParserErrorCode.MISSING_IDENTIFIER,
4671 ParserErrorCode.MISSING_IDENTIFIER
4672 ]);
4673 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
4674 BinaryExpression, expression.leftOperand);
4210 } 4675 }
4211 4676
4212 void test_missingGet() { 4677 void test_bitwiseXorExpression_missing_LHS() {
4213 CompilationUnit unit = parseCompilationUnit(
4214 r'''
4215 class C {
4216 int length {}
4217 void foo() {}
4218 }''',
4219 [ParserErrorCode.MISSING_GET]);
4220 expect(unit, isNotNull);
4221 ClassDeclaration classDeclaration =
4222 unit.declarations[0] as ClassDeclaration;
4223 NodeList<ClassMember> members = classDeclaration.members;
4224 expect(members, hasLength(2));
4225 EngineTestCase.assertInstanceOf(
4226 (obj) => obj is MethodDeclaration, MethodDeclaration, members[0]);
4227 ClassMember member = members[1];
4228 EngineTestCase.assertInstanceOf(
4229 (obj) => obj is MethodDeclaration, MethodDeclaration, member);
4230 expect((member as MethodDeclaration).name.name, "foo");
4231 }
4232
4233 void test_missingIdentifier_afterAnnotation() {
4234 createParser('@override }');
4235 ClassMember member = parser.parseClassMember('C');
4236 expectNotNullIfNoErrors(member);
4237 listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_CLASS_MEMBER]);
4238 expect(member, new isInstanceOf<MethodDeclaration>());
4239 MethodDeclaration method = member;
4240 expect(method.documentationComment, isNull);
4241 NodeList<Annotation> metadata = method.metadata;
4242 expect(metadata, hasLength(1));
4243 expect(metadata[0].name.name, "override");
4244 }
4245
4246 void test_missingSemicolon_varialeDeclarationList() {
4247 void verify(CompilationUnitMember member, String expectedTypeName,
4248 String expectedName, String expectedSemicolon) {
4249 expect(member, new isInstanceOf<TopLevelVariableDeclaration>());
4250 TopLevelVariableDeclaration declaration = member;
4251 VariableDeclarationList variableList = declaration.variables;
4252 expect(variableList, isNotNull);
4253 NodeList<VariableDeclaration> variables = variableList.variables;
4254 expect(variables, hasLength(1));
4255 VariableDeclaration variable = variables[0];
4256 expect(variableList.type.toString(), expectedTypeName);
4257 expect(variable.name.name, expectedName);
4258 expect(declaration.semicolon.lexeme, expectedSemicolon);
4259 }
4260
4261 CompilationUnit unit = parseCompilationUnit('String n x = "";', [
4262 ParserErrorCode.EXPECTED_TOKEN,
4263 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE
4264 ]);
4265 expect(unit, isNotNull);
4266 NodeList<CompilationUnitMember> declarations = unit.declarations;
4267 expect(declarations, hasLength(2));
4268 verify(declarations[0], 'String', 'n', '');
4269 verify(declarations[1], 'null', 'x', ';');
4270 }
4271
4272 void test_multiplicativeExpression_missing_LHS() {
4273 BinaryExpression expression = 4678 BinaryExpression expression =
4274 parseExpression("* y", [ParserErrorCode.MISSING_IDENTIFIER]); 4679 parseExpression("^ y", [ParserErrorCode.MISSING_IDENTIFIER]);
4275 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, 4680 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
4276 SimpleIdentifier, expression.leftOperand); 4681 SimpleIdentifier, expression.leftOperand);
4277 expect(expression.leftOperand.isSynthetic, isTrue); 4682 expect(expression.leftOperand.isSynthetic, isTrue);
4278 } 4683 }
4279 4684
4280 void test_multiplicativeExpression_missing_LHS_RHS() { 4685 void test_bitwiseXorExpression_missing_LHS_RHS() {
4281 BinaryExpression expression = parseExpression("*", [ 4686 BinaryExpression expression = parseExpression("^", [
4282 ParserErrorCode.MISSING_IDENTIFIER, 4687 ParserErrorCode.MISSING_IDENTIFIER,
4283 ParserErrorCode.MISSING_IDENTIFIER 4688 ParserErrorCode.MISSING_IDENTIFIER
4284 ]); 4689 ]);
4285 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, 4690 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
4286 SimpleIdentifier, expression.leftOperand); 4691 SimpleIdentifier, expression.leftOperand);
4287 expect(expression.leftOperand.isSynthetic, isTrue); 4692 expect(expression.leftOperand.isSynthetic, isTrue);
4288 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, 4693 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
4289 SimpleIdentifier, expression.rightOperand); 4694 SimpleIdentifier, expression.rightOperand);
4290 expect(expression.rightOperand.isSynthetic, isTrue); 4695 expect(expression.rightOperand.isSynthetic, isTrue);
4291 } 4696 }
4292 4697
4293 void test_multiplicativeExpression_missing_RHS() { 4698 void test_bitwiseXorExpression_missing_RHS() {
4294 BinaryExpression expression = 4699 BinaryExpression expression =
4295 parseExpression("x *", [ParserErrorCode.MISSING_IDENTIFIER]); 4700 parseExpression("x ^", [ParserErrorCode.MISSING_IDENTIFIER]);
4296 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, 4701 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
4297 SimpleIdentifier, expression.rightOperand); 4702 SimpleIdentifier, expression.rightOperand);
4298 expect(expression.rightOperand.isSynthetic, isTrue); 4703 expect(expression.rightOperand.isSynthetic, isTrue);
4299 } 4704 }
4300 4705
4301 void test_multiplicativeExpression_missing_RHS_super() { 4706 void test_bitwiseXorExpression_missing_RHS_super() {
4302 BinaryExpression expression = 4707 BinaryExpression expression =
4303 parseExpression("super *", [ParserErrorCode.MISSING_IDENTIFIER]); 4708 parseExpression("super ^", [ParserErrorCode.MISSING_IDENTIFIER]);
4304 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, 4709 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
4305 SimpleIdentifier, expression.rightOperand); 4710 SimpleIdentifier, expression.rightOperand);
4306 expect(expression.rightOperand.isSynthetic, isTrue); 4711 expect(expression.rightOperand.isSynthetic, isTrue);
4307 } 4712 }
4308 4713
4309 void test_multiplicativeExpression_precedence_unary_left() { 4714 void test_bitwiseXorExpression_precedence_and_left() {
4310 BinaryExpression expression = 4715 BinaryExpression expression = parseExpression("& ^", [
4311 parseExpression("-x *", [ParserErrorCode.MISSING_IDENTIFIER]);
4312 EngineTestCase.assertInstanceOf((obj) => obj is PrefixExpression,
4313 PrefixExpression, expression.leftOperand);
4314 }
4315
4316 void test_multiplicativeExpression_precedence_unary_right() {
4317 BinaryExpression expression =
4318 parseExpression("* -y", [ParserErrorCode.MISSING_IDENTIFIER]);
4319 EngineTestCase.assertInstanceOf((obj) => obj is PrefixExpression,
4320 PrefixExpression, expression.rightOperand);
4321 }
4322
4323 void test_multiplicativeExpression_super() {
4324 BinaryExpression expression = parseExpression("super == ==", [
4325 ParserErrorCode.MISSING_IDENTIFIER, 4716 ParserErrorCode.MISSING_IDENTIFIER,
4326 ParserErrorCode.MISSING_IDENTIFIER, 4717 ParserErrorCode.MISSING_IDENTIFIER,
4327 ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND 4718 ParserErrorCode.MISSING_IDENTIFIER
4328 ]); 4719 ]);
4329 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, 4720 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
4330 BinaryExpression, expression.leftOperand); 4721 BinaryExpression, expression.leftOperand);
4331 } 4722 }
4332 4723
4333 void test_nonStringLiteralUri_import() { 4724 void test_bitwiseXorExpression_precedence_and_right() {
4334 parseCompilationUnit("import dart:io; class C {}", 4725 BinaryExpression expression = parseExpression("^ &", [
4335 [ParserErrorCode.NON_STRING_LITERAL_AS_URI]); 4726 ParserErrorCode.MISSING_IDENTIFIER,
4336 }
4337
4338 void test_prefixExpression_missing_operand_minus() {
4339 PrefixExpression expression =
4340 parseExpression("-", [ParserErrorCode.MISSING_IDENTIFIER]);
4341 EngineTestCase.assertInstanceOf(
4342 (obj) => obj is SimpleIdentifier, SimpleIdentifier, expression.operand);
4343 expect(expression.operand.isSynthetic, isTrue);
4344 expect(expression.operator.type, TokenType.MINUS);
4345 }
4346
4347 void test_primaryExpression_argumentDefinitionTest() {
4348 createParser('?a');
4349 Expression expression = parser.parsePrimaryExpression();
4350 expectNotNullIfNoErrors(expression);
4351 listener.assertErrorsWithCodes([ParserErrorCode.UNEXPECTED_TOKEN]);
4352 expect(expression, new isInstanceOf<SimpleIdentifier>());
4353 }
4354
4355 void test_relationalExpression_missing_LHS() {
4356 IsExpression expression =
4357 parseExpression("is y", [ParserErrorCode.MISSING_IDENTIFIER]);
4358 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
4359 SimpleIdentifier, expression.expression);
4360 expect(expression.expression.isSynthetic, isTrue);
4361 }
4362
4363 void test_relationalExpression_missing_LHS_RHS() {
4364 IsExpression expression = parseExpression("is", [
4365 ParserErrorCode.EXPECTED_TYPE_NAME,
4366 ParserErrorCode.MISSING_IDENTIFIER
4367 ]);
4368 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
4369 SimpleIdentifier, expression.expression);
4370 expect(expression.expression.isSynthetic, isTrue);
4371 EngineTestCase.assertInstanceOf(
4372 (obj) => obj is TypeName, TypeName, expression.type);
4373 expect(expression.type.isSynthetic, isTrue);
4374 }
4375
4376 void test_relationalExpression_missing_RHS() {
4377 IsExpression expression =
4378 parseExpression("x is", [ParserErrorCode.EXPECTED_TYPE_NAME]);
4379 EngineTestCase.assertInstanceOf(
4380 (obj) => obj is TypeName, TypeName, expression.type);
4381 expect(expression.type.isSynthetic, isTrue);
4382 }
4383
4384 void test_relationalExpression_precedence_shift_right() {
4385 IsExpression expression = parseExpression("<< is", [
4386 ParserErrorCode.EXPECTED_TYPE_NAME,
4387 ParserErrorCode.MISSING_IDENTIFIER, 4727 ParserErrorCode.MISSING_IDENTIFIER,
4388 ParserErrorCode.MISSING_IDENTIFIER 4728 ParserErrorCode.MISSING_IDENTIFIER
4389 ]); 4729 ]);
4390 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, 4730 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
4391 BinaryExpression, expression.expression); 4731 BinaryExpression, expression.rightOperand);
4392 } 4732 }
4393 4733
4394 void test_shiftExpression_missing_LHS() { 4734 void test_bitwiseXorExpression_super() {
4735 BinaryExpression expression = parseExpression("super ^ ^", [
4736 ParserErrorCode.MISSING_IDENTIFIER,
4737 ParserErrorCode.MISSING_IDENTIFIER
4738 ]);
4739 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
4740 BinaryExpression, expression.leftOperand);
4741 }
4742
4743 void test_classTypeAlias_withBody() {
4744 parseCompilationUnit(
4745 r'''
4746 class A {}
4747 class B = Object with A {}''',
4748 [ParserErrorCode.EXPECTED_TOKEN]);
4749 }
4750
4751 void test_conditionalExpression_missingElse() {
4752 createParser('x ? y :');
4753 Expression expression = parser.parseConditionalExpression();
4754 expectNotNullIfNoErrors(expression);
4755 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]);
4756 expect(expression, new isInstanceOf<ConditionalExpression>());
4757 ConditionalExpression conditionalExpression = expression;
4758 expect(conditionalExpression.elseExpression,
4759 new isInstanceOf<SimpleIdentifier>());
4760 expect(conditionalExpression.elseExpression.isSynthetic, isTrue);
4761 }
4762
4763 void test_conditionalExpression_missingThen() {
4764 createParser('x ? : z');
4765 Expression expression = parser.parseConditionalExpression();
4766 expectNotNullIfNoErrors(expression);
4767 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]);
4768 expect(expression, new isInstanceOf<ConditionalExpression>());
4769 ConditionalExpression conditionalExpression = expression;
4770 expect(conditionalExpression.thenExpression,
4771 new isInstanceOf<SimpleIdentifier>());
4772 expect(conditionalExpression.thenExpression.isSynthetic, isTrue);
4773 }
4774
4775 void test_declarationBeforeDirective() {
4776 CompilationUnit unit = parseCompilationUnit(
4777 "class foo { } import 'bar.dart';",
4778 [ParserErrorCode.DIRECTIVE_AFTER_DECLARATION]);
4779 expect(unit.directives, hasLength(1));
4780 expect(unit.declarations, hasLength(1));
4781 ClassDeclaration classDecl = unit.childEntities.first;
4782 expect(classDecl, isNotNull);
4783 expect(classDecl.name.name, 'foo');
4784 }
4785
4786 void test_equalityExpression_missing_LHS() {
4395 BinaryExpression expression = 4787 BinaryExpression expression =
4396 parseExpression("<< y", [ParserErrorCode.MISSING_IDENTIFIER]); 4788 parseExpression("== y", [ParserErrorCode.MISSING_IDENTIFIER]);
4397 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, 4789 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
4398 SimpleIdentifier, expression.leftOperand); 4790 SimpleIdentifier, expression.leftOperand);
4399 expect(expression.leftOperand.isSynthetic, isTrue); 4791 expect(expression.leftOperand.isSynthetic, isTrue);
4400 } 4792 }
4401 4793
4402 void test_shiftExpression_missing_LHS_RHS() { 4794 void test_equalityExpression_missing_LHS_RHS() {
4403 BinaryExpression expression = parseExpression("<<", [ 4795 BinaryExpression expression = parseExpression("==", [
4404 ParserErrorCode.MISSING_IDENTIFIER, 4796 ParserErrorCode.MISSING_IDENTIFIER,
4405 ParserErrorCode.MISSING_IDENTIFIER 4797 ParserErrorCode.MISSING_IDENTIFIER
4406 ]); 4798 ]);
4407 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, 4799 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
4408 SimpleIdentifier, expression.leftOperand); 4800 SimpleIdentifier, expression.leftOperand);
4409 expect(expression.leftOperand.isSynthetic, isTrue); 4801 expect(expression.leftOperand.isSynthetic, isTrue);
4410 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, 4802 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
4411 SimpleIdentifier, expression.rightOperand); 4803 SimpleIdentifier, expression.rightOperand);
4412 expect(expression.rightOperand.isSynthetic, isTrue); 4804 expect(expression.rightOperand.isSynthetic, isTrue);
4413 } 4805 }
4414 4806
4807 void test_equalityExpression_missing_RHS() {
4808 BinaryExpression expression =
4809 parseExpression("x ==", [ParserErrorCode.MISSING_IDENTIFIER]);
4810 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
4811 SimpleIdentifier, expression.rightOperand);
4812 expect(expression.rightOperand.isSynthetic, isTrue);
4813 }
4814
4815 void test_equalityExpression_missing_RHS_super() {
4816 BinaryExpression expression =
4817 parseExpression("super ==", [ParserErrorCode.MISSING_IDENTIFIER]);
4818 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
4819 SimpleIdentifier, expression.rightOperand);
4820 expect(expression.rightOperand.isSynthetic, isTrue);
4821 }
4822
4823 void test_equalityExpression_precedence_relational_left() {
4824 BinaryExpression expression = parseExpression("is ==", [
4825 ParserErrorCode.EXPECTED_TYPE_NAME,
4826 ParserErrorCode.MISSING_IDENTIFIER,
4827 ParserErrorCode.MISSING_IDENTIFIER
4828 ]);
4829 EngineTestCase.assertInstanceOf(
4830 (obj) => obj is IsExpression, IsExpression, expression.leftOperand);
4831 }
4832
4833 void test_equalityExpression_precedence_relational_right() {
4834 BinaryExpression expression = parseExpression("== is", [
4835 ParserErrorCode.EXPECTED_TYPE_NAME,
4836 ParserErrorCode.MISSING_IDENTIFIER,
4837 ParserErrorCode.MISSING_IDENTIFIER
4838 ]);
4839 EngineTestCase.assertInstanceOf(
4840 (obj) => obj is IsExpression, IsExpression, expression.rightOperand);
4841 }
4842
4843 void test_equalityExpression_super() {
4844 BinaryExpression expression = parseExpression("super == ==", [
4845 ParserErrorCode.MISSING_IDENTIFIER,
4846 ParserErrorCode.MISSING_IDENTIFIER,
4847 ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND
4848 ]);
4849 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
4850 BinaryExpression, expression.leftOperand);
4851 }
4852
4853 void test_expressionList_multiple_end() {
4854 createParser(', 2, 3, 4');
4855 List<Expression> result = parser.parseExpressionList();
4856 expectNotNullIfNoErrors(result);
4857 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]);
4858 expect(result, hasLength(4));
4859 Expression syntheticExpression = result[0];
4860 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
4861 SimpleIdentifier, syntheticExpression);
4862 expect(syntheticExpression.isSynthetic, isTrue);
4863 }
4864
4865 void test_expressionList_multiple_middle() {
4866 createParser('1, 2, , 4');
4867 List<Expression> result = parser.parseExpressionList();
4868 expectNotNullIfNoErrors(result);
4869 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]);
4870 expect(result, hasLength(4));
4871 Expression syntheticExpression = result[2];
4872 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
4873 SimpleIdentifier, syntheticExpression);
4874 expect(syntheticExpression.isSynthetic, isTrue);
4875 }
4876
4877 void test_expressionList_multiple_start() {
4878 createParser('1, 2, 3,');
4879 List<Expression> result = parser.parseExpressionList();
4880 expectNotNullIfNoErrors(result);
4881 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]);
4882 expect(result, hasLength(4));
4883 Expression syntheticExpression = result[3];
4884 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
4885 SimpleIdentifier, syntheticExpression);
4886 expect(syntheticExpression.isSynthetic, isTrue);
4887 }
4888
4889 void test_functionExpression_in_ConstructorFieldInitializer() {
4890 CompilationUnit unit = parseCompilationUnit(
4891 "class A { A() : a = (){}; var v; }",
4892 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.UNEXPECTED_TOKEN]);
4893 // Make sure we recovered and parsed "var v" correctly
4894 ClassDeclaration declaration = unit.declarations[0] as ClassDeclaration;
4895 NodeList<ClassMember> members = declaration.members;
4896 ClassMember fieldDecl = members[1];
4897 EngineTestCase.assertInstanceOf(
4898 (obj) => obj is FieldDeclaration, FieldDeclaration, fieldDecl);
4899 NodeList<VariableDeclaration> vars =
4900 (fieldDecl as FieldDeclaration).fields.variables;
4901 expect(vars, hasLength(1));
4902 expect(vars[0].name.name, "v");
4903 }
4904
4905 void test_functionExpression_named() {
4906 parseExpression("m(f() => 0);", [ParserErrorCode.EXPECTED_TOKEN]);
4907 }
4908
4909 void test_importDirectivePartial_as() {
4910 CompilationUnit unit = parseCompilationUnit(
4911 "import 'b.dart' d as b;", [ParserErrorCode.UNEXPECTED_TOKEN]);
4912 ImportDirective importDirective = unit.childEntities.first;
4913 expect(importDirective.asKeyword, isNotNull);
4914 expect(unit.directives, hasLength(1));
4915 expect(unit.declarations, hasLength(0));
4916 }
4917
4918 void test_importDirectivePartial_hide() {
4919 CompilationUnit unit = parseCompilationUnit(
4920 "import 'b.dart' d hide foo;", [ParserErrorCode.UNEXPECTED_TOKEN]);
4921 ImportDirective importDirective = unit.childEntities.first;
4922 expect(importDirective.combinators, hasLength(1));
4923 expect(unit.directives, hasLength(1));
4924 expect(unit.declarations, hasLength(0));
4925 }
4926
4927 void test_importDirectivePartial_show() {
4928 CompilationUnit unit = parseCompilationUnit(
4929 "import 'b.dart' d show foo;", [ParserErrorCode.UNEXPECTED_TOKEN]);
4930 ImportDirective importDirective = unit.childEntities.first;
4931 expect(importDirective.combinators, hasLength(1));
4932 expect(unit.directives, hasLength(1));
4933 expect(unit.declarations, hasLength(0));
4934 }
4935
4936 void test_incomplete_conditionalExpression() {
4937 parseExpression("x ? 0",
4938 [ParserErrorCode.EXPECTED_TOKEN, ParserErrorCode.MISSING_IDENTIFIER]);
4939 }
4940
4941 void test_incomplete_constructorInitializers_empty() {
4942 createParser('C() : {}');
4943 ClassMember member = parser.parseClassMember('C');
4944 expectNotNullIfNoErrors(member);
4945 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_INITIALIZER]);
4946 }
4947
4948 void test_incomplete_constructorInitializers_missingEquals() {
4949 createParser('C() : x(3) {}');
4950 ClassMember member = parser.parseClassMember('C');
4951 expectNotNullIfNoErrors(member);
4952 listener.assertErrorsWithCodes(
4953 [ParserErrorCode.MISSING_ASSIGNMENT_IN_INITIALIZER]);
4954 expect(member, new isInstanceOf<ConstructorDeclaration>());
4955 NodeList<ConstructorInitializer> initializers =
4956 (member as ConstructorDeclaration).initializers;
4957 expect(initializers, hasLength(1));
4958 ConstructorInitializer initializer = initializers[0];
4959 expect(initializer, new isInstanceOf<ConstructorFieldInitializer>());
4960 Expression expression =
4961 (initializer as ConstructorFieldInitializer).expression;
4962 expect(expression, isNotNull);
4963 expect(expression, new isInstanceOf<ParenthesizedExpression>());
4964 }
4965
4966 void test_incomplete_constructorInitializers_variable() {
4967 createParser('C() : x {}');
4968 ClassMember member = parser.parseClassMember('C');
4969 expectNotNullIfNoErrors(member);
4970 listener.assertErrorsWithCodes(
4971 [ParserErrorCode.MISSING_ASSIGNMENT_IN_INITIALIZER]);
4972 }
4973
4974 @failingTest
4975 void test_incomplete_returnType() {
4976 parseCompilationUnit(r'''
4977 Map<Symbol, convertStringToSymbolMap(Map<String, dynamic> map) {
4978 if (map == null) return null;
4979 Map<Symbol, dynamic> result = new Map<Symbol, dynamic>();
4980 map.forEach((name, value) {
4981 result[new Symbol(name)] = value;
4982 });
4983 return result;
4984 }''');
4985 }
4986
4987 void test_incomplete_topLevelFunction() {
4988 parseCompilationUnit("foo();", [ParserErrorCode.MISSING_FUNCTION_BODY]);
4989 }
4990
4991 void test_incomplete_topLevelVariable() {
4992 CompilationUnit unit =
4993 parseCompilationUnit("String", [ParserErrorCode.EXPECTED_EXECUTABLE]);
4994 NodeList<CompilationUnitMember> declarations = unit.declarations;
4995 expect(declarations, hasLength(1));
4996 CompilationUnitMember member = declarations[0];
4997 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableDeclaration,
4998 TopLevelVariableDeclaration, member);
4999 NodeList<VariableDeclaration> variables =
5000 (member as TopLevelVariableDeclaration).variables.variables;
5001 expect(variables, hasLength(1));
5002 SimpleIdentifier name = variables[0].name;
5003 expect(name.isSynthetic, isTrue);
5004 }
5005
5006 void test_incomplete_topLevelVariable_const() {
5007 CompilationUnit unit = parseCompilationUnit("const ",
5008 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]);
5009 NodeList<CompilationUnitMember> declarations = unit.declarations;
5010 expect(declarations, hasLength(1));
5011 CompilationUnitMember member = declarations[0];
5012 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableDeclaration,
5013 TopLevelVariableDeclaration, member);
5014 NodeList<VariableDeclaration> variables =
5015 (member as TopLevelVariableDeclaration).variables.variables;
5016 expect(variables, hasLength(1));
5017 SimpleIdentifier name = variables[0].name;
5018 expect(name.isSynthetic, isTrue);
5019 }
5020
5021 void test_incomplete_topLevelVariable_final() {
5022 CompilationUnit unit = parseCompilationUnit("final ",
5023 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]);
5024 NodeList<CompilationUnitMember> declarations = unit.declarations;
5025 expect(declarations, hasLength(1));
5026 CompilationUnitMember member = declarations[0];
5027 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableDeclaration,
5028 TopLevelVariableDeclaration, member);
5029 NodeList<VariableDeclaration> variables =
5030 (member as TopLevelVariableDeclaration).variables.variables;
5031 expect(variables, hasLength(1));
5032 SimpleIdentifier name = variables[0].name;
5033 expect(name.isSynthetic, isTrue);
5034 }
5035
5036 void test_incomplete_topLevelVariable_var() {
5037 CompilationUnit unit = parseCompilationUnit("var ",
5038 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]);
5039 NodeList<CompilationUnitMember> declarations = unit.declarations;
5040 expect(declarations, hasLength(1));
5041 CompilationUnitMember member = declarations[0];
5042 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableDeclaration,
5043 TopLevelVariableDeclaration, member);
5044 NodeList<VariableDeclaration> variables =
5045 (member as TopLevelVariableDeclaration).variables.variables;
5046 expect(variables, hasLength(1));
5047 SimpleIdentifier name = variables[0].name;
5048 expect(name.isSynthetic, isTrue);
5049 }
5050
5051 void test_incompleteField_const() {
5052 CompilationUnit unit = parseCompilationUnit(
5053 r'''
5054 class C {
5055 const
5056 }''',
5057 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]);
5058 NodeList<CompilationUnitMember> declarations = unit.declarations;
5059 expect(declarations, hasLength(1));
5060 CompilationUnitMember unitMember = declarations[0];
5061 EngineTestCase.assertInstanceOf(
5062 (obj) => obj is ClassDeclaration, ClassDeclaration, unitMember);
5063 NodeList<ClassMember> members = (unitMember as ClassDeclaration).members;
5064 expect(members, hasLength(1));
5065 ClassMember classMember = members[0];
5066 EngineTestCase.assertInstanceOf(
5067 (obj) => obj is FieldDeclaration, FieldDeclaration, classMember);
5068 VariableDeclarationList fieldList =
5069 (classMember as FieldDeclaration).fields;
5070 expect(fieldList.keyword.keyword, Keyword.CONST);
5071 NodeList<VariableDeclaration> fields = fieldList.variables;
5072 expect(fields, hasLength(1));
5073 VariableDeclaration field = fields[0];
5074 expect(field.name.isSynthetic, isTrue);
5075 }
5076
5077 void test_incompleteField_final() {
5078 CompilationUnit unit = parseCompilationUnit(
5079 r'''
5080 class C {
5081 final
5082 }''',
5083 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]);
5084 NodeList<CompilationUnitMember> declarations = unit.declarations;
5085 expect(declarations, hasLength(1));
5086 CompilationUnitMember unitMember = declarations[0];
5087 EngineTestCase.assertInstanceOf(
5088 (obj) => obj is ClassDeclaration, ClassDeclaration, unitMember);
5089 NodeList<ClassMember> members = (unitMember as ClassDeclaration).members;
5090 expect(members, hasLength(1));
5091 ClassMember classMember = members[0];
5092 EngineTestCase.assertInstanceOf(
5093 (obj) => obj is FieldDeclaration, FieldDeclaration, classMember);
5094 VariableDeclarationList fieldList =
5095 (classMember as FieldDeclaration).fields;
5096 expect(fieldList.keyword.keyword, Keyword.FINAL);
5097 NodeList<VariableDeclaration> fields = fieldList.variables;
5098 expect(fields, hasLength(1));
5099 VariableDeclaration field = fields[0];
5100 expect(field.name.isSynthetic, isTrue);
5101 }
5102
5103 void test_incompleteField_var() {
5104 CompilationUnit unit = parseCompilationUnit(
5105 r'''
5106 class C {
5107 var
5108 }''',
5109 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]);
5110 NodeList<CompilationUnitMember> declarations = unit.declarations;
5111 expect(declarations, hasLength(1));
5112 CompilationUnitMember unitMember = declarations[0];
5113 EngineTestCase.assertInstanceOf(
5114 (obj) => obj is ClassDeclaration, ClassDeclaration, unitMember);
5115 NodeList<ClassMember> members = (unitMember as ClassDeclaration).members;
5116 expect(members, hasLength(1));
5117 ClassMember classMember = members[0];
5118 EngineTestCase.assertInstanceOf(
5119 (obj) => obj is FieldDeclaration, FieldDeclaration, classMember);
5120 VariableDeclarationList fieldList =
5121 (classMember as FieldDeclaration).fields;
5122 expect(fieldList.keyword.keyword, Keyword.VAR);
5123 NodeList<VariableDeclaration> fields = fieldList.variables;
5124 expect(fields, hasLength(1));
5125 VariableDeclaration field = fields[0];
5126 expect(field.name.isSynthetic, isTrue);
5127 }
5128
5129 void test_incompleteForEach() {
5130 ForStatement statement = parseStatement('for (String item i) {}',
5131 [ParserErrorCode.EXPECTED_TOKEN, ParserErrorCode.EXPECTED_TOKEN]);
5132 expect(statement, new isInstanceOf<ForStatement>());
5133 expect(statement.toSource(), 'for (String item; i;) {}');
5134 expect(statement.leftSeparator, isNotNull);
5135 expect(statement.leftSeparator.type, TokenType.SEMICOLON);
5136 expect(statement.rightSeparator, isNotNull);
5137 expect(statement.rightSeparator.type, TokenType.SEMICOLON);
5138 }
5139
5140 void test_incompleteLocalVariable_atTheEndOfBlock() {
5141 Statement statement =
5142 parseStatement('String v }', [ParserErrorCode.EXPECTED_TOKEN]);
5143 expect(statement, new isInstanceOf<VariableDeclarationStatement>());
5144 expect(statement.toSource(), 'String v;');
5145 }
5146
5147 void test_incompleteLocalVariable_beforeIdentifier() {
5148 Statement statement =
5149 parseStatement('String v String v2;', [ParserErrorCode.EXPECTED_TOKEN]);
5150 expect(statement, new isInstanceOf<VariableDeclarationStatement>());
5151 expect(statement.toSource(), 'String v;');
5152 }
5153
5154 void test_incompleteLocalVariable_beforeKeyword() {
5155 Statement statement = parseStatement(
5156 'String v if (true) {}', [ParserErrorCode.EXPECTED_TOKEN]);
5157 expect(statement, new isInstanceOf<VariableDeclarationStatement>());
5158 expect(statement.toSource(), 'String v;');
5159 }
5160
5161 void test_incompleteLocalVariable_beforeNextBlock() {
5162 Statement statement =
5163 parseStatement('String v {}', [ParserErrorCode.EXPECTED_TOKEN]);
5164 expect(statement, new isInstanceOf<VariableDeclarationStatement>());
5165 expect(statement.toSource(), 'String v;');
5166 }
5167
5168 void test_incompleteLocalVariable_parameterizedType() {
5169 Statement statement =
5170 parseStatement('List<String> v {}', [ParserErrorCode.EXPECTED_TOKEN]);
5171 expect(statement, new isInstanceOf<VariableDeclarationStatement>());
5172 expect(statement.toSource(), 'List<String> v;');
5173 }
5174
5175 void test_incompleteTypeArguments_field() {
5176 CompilationUnit unit = parseCompilationUnit(
5177 r'''
5178 class C {
5179 final List<int f;
5180 }''',
5181 [ParserErrorCode.EXPECTED_TOKEN]);
5182 // one class
5183 List<CompilationUnitMember> declarations = unit.declarations;
5184 expect(declarations, hasLength(1));
5185 ClassDeclaration classDecl = declarations[0] as ClassDeclaration;
5186 // one field declaration
5187 List<ClassMember> members = classDecl.members;
5188 expect(members, hasLength(1));
5189 FieldDeclaration fieldDecl = members[0] as FieldDeclaration;
5190 // one field
5191 VariableDeclarationList fieldList = fieldDecl.fields;
5192 List<VariableDeclaration> fields = fieldList.variables;
5193 expect(fields, hasLength(1));
5194 VariableDeclaration field = fields[0];
5195 expect(field.name.name, 'f');
5196 // validate the type
5197 TypeArgumentList typeArguments = (fieldList.type as TypeName).typeArguments;
5198 expect(typeArguments.arguments, hasLength(1));
5199 // synthetic '>'
5200 Token token = typeArguments.endToken;
5201 expect(token.type, TokenType.GT);
5202 expect(token.isSynthetic, isTrue);
5203 }
5204
5205 void test_incompleteTypeParameters() {
5206 CompilationUnit unit = parseCompilationUnit(
5207 r'''
5208 class C<K {
5209 }''',
5210 [ParserErrorCode.EXPECTED_TOKEN]);
5211 // one class
5212 List<CompilationUnitMember> declarations = unit.declarations;
5213 expect(declarations, hasLength(1));
5214 ClassDeclaration classDecl = declarations[0] as ClassDeclaration;
5215 // validate the type parameters
5216 TypeParameterList typeParameters = classDecl.typeParameters;
5217 expect(typeParameters.typeParameters, hasLength(1));
5218 // synthetic '>'
5219 Token token = typeParameters.endToken;
5220 expect(token.type, TokenType.GT);
5221 expect(token.isSynthetic, isTrue);
5222 }
5223
5224 void test_invalidFunctionBodyModifier() {
5225 parseCompilationUnit(
5226 "f() sync {}", [ParserErrorCode.MISSING_STAR_AFTER_SYNC]);
5227 }
5228
5229 void test_isExpression_noType() {
5230 CompilationUnit unit = parseCompilationUnit(
5231 "class Bar<T extends Foo> {m(x){if (x is ) return;if (x is !)}}", [
5232 ParserErrorCode.EXPECTED_TYPE_NAME,
5233 ParserErrorCode.EXPECTED_TYPE_NAME,
5234 ParserErrorCode.MISSING_STATEMENT
5235 ]);
5236 ClassDeclaration declaration = unit.declarations[0] as ClassDeclaration;
5237 MethodDeclaration method = declaration.members[0] as MethodDeclaration;
5238 BlockFunctionBody body = method.body as BlockFunctionBody;
5239 IfStatement ifStatement = body.block.statements[1] as IfStatement;
5240 IsExpression expression = ifStatement.condition as IsExpression;
5241 expect(expression.expression, isNotNull);
5242 expect(expression.isOperator, isNotNull);
5243 expect(expression.notOperator, isNotNull);
5244 TypeAnnotation type = expression.type;
5245 expect(type, isNotNull);
5246 expect(type is TypeName && type.name.isSynthetic, isTrue);
5247 EngineTestCase.assertInstanceOf((obj) => obj is EmptyStatement,
5248 EmptyStatement, ifStatement.thenStatement);
5249 }
5250
5251 void test_keywordInPlaceOfIdentifier() {
5252 // TODO(brianwilkerson) We could do better with this.
5253 parseCompilationUnit("do() {}", [
5254 ParserErrorCode.EXPECTED_EXECUTABLE,
5255 ParserErrorCode.UNEXPECTED_TOKEN
5256 ]);
5257 }
5258
5259 void test_logicalAndExpression_missing_LHS() {
5260 BinaryExpression expression =
5261 parseExpression("&& y", [ParserErrorCode.MISSING_IDENTIFIER]);
5262 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
5263 SimpleIdentifier, expression.leftOperand);
5264 expect(expression.leftOperand.isSynthetic, isTrue);
5265 }
5266
5267 void test_logicalAndExpression_missing_LHS_RHS() {
5268 BinaryExpression expression = parseExpression("&&", [
5269 ParserErrorCode.MISSING_IDENTIFIER,
5270 ParserErrorCode.MISSING_IDENTIFIER
5271 ]);
5272 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
5273 SimpleIdentifier, expression.leftOperand);
5274 expect(expression.leftOperand.isSynthetic, isTrue);
5275 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
5276 SimpleIdentifier, expression.rightOperand);
5277 expect(expression.rightOperand.isSynthetic, isTrue);
5278 }
5279
5280 void test_logicalAndExpression_missing_RHS() {
5281 BinaryExpression expression =
5282 parseExpression("x &&", [ParserErrorCode.MISSING_IDENTIFIER]);
5283 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
5284 SimpleIdentifier, expression.rightOperand);
5285 expect(expression.rightOperand.isSynthetic, isTrue);
5286 }
5287
5288 void test_logicalAndExpression_precedence_bitwiseOr_left() {
5289 BinaryExpression expression = parseExpression("| &&", [
5290 ParserErrorCode.MISSING_IDENTIFIER,
5291 ParserErrorCode.MISSING_IDENTIFIER,
5292 ParserErrorCode.MISSING_IDENTIFIER
5293 ]);
5294 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
5295 BinaryExpression, expression.leftOperand);
5296 }
5297
5298 void test_logicalAndExpression_precedence_bitwiseOr_right() {
5299 BinaryExpression expression = parseExpression("&& |", [
5300 ParserErrorCode.MISSING_IDENTIFIER,
5301 ParserErrorCode.MISSING_IDENTIFIER,
5302 ParserErrorCode.MISSING_IDENTIFIER
5303 ]);
5304 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
5305 BinaryExpression, expression.rightOperand);
5306 }
5307
5308 void test_logicalOrExpression_missing_LHS() {
5309 BinaryExpression expression =
5310 parseExpression("|| y", [ParserErrorCode.MISSING_IDENTIFIER]);
5311 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
5312 SimpleIdentifier, expression.leftOperand);
5313 expect(expression.leftOperand.isSynthetic, isTrue);
5314 }
5315
5316 void test_logicalOrExpression_missing_LHS_RHS() {
5317 BinaryExpression expression = parseExpression("||", [
5318 ParserErrorCode.MISSING_IDENTIFIER,
5319 ParserErrorCode.MISSING_IDENTIFIER
5320 ]);
5321 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
5322 SimpleIdentifier, expression.leftOperand);
5323 expect(expression.leftOperand.isSynthetic, isTrue);
5324 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
5325 SimpleIdentifier, expression.rightOperand);
5326 expect(expression.rightOperand.isSynthetic, isTrue);
5327 }
5328
5329 void test_logicalOrExpression_missing_RHS() {
5330 BinaryExpression expression =
5331 parseExpression("x ||", [ParserErrorCode.MISSING_IDENTIFIER]);
5332 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
5333 SimpleIdentifier, expression.rightOperand);
5334 expect(expression.rightOperand.isSynthetic, isTrue);
5335 }
5336
5337 void test_logicalOrExpression_precedence_logicalAnd_left() {
5338 BinaryExpression expression = parseExpression("&& ||", [
5339 ParserErrorCode.MISSING_IDENTIFIER,
5340 ParserErrorCode.MISSING_IDENTIFIER,
5341 ParserErrorCode.MISSING_IDENTIFIER
5342 ]);
5343 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
5344 BinaryExpression, expression.leftOperand);
5345 }
5346
5347 void test_logicalOrExpression_precedence_logicalAnd_right() {
5348 BinaryExpression expression = parseExpression("|| &&", [
5349 ParserErrorCode.MISSING_IDENTIFIER,
5350 ParserErrorCode.MISSING_IDENTIFIER,
5351 ParserErrorCode.MISSING_IDENTIFIER
5352 ]);
5353 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
5354 BinaryExpression, expression.rightOperand);
5355 }
5356
5357 void test_missing_commaInArgumentList() {
5358 parseExpression("f(x: 1 y: 2)", [ParserErrorCode.EXPECTED_TOKEN]);
5359 }
5360
5361 void test_missingGet() {
5362 CompilationUnit unit = parseCompilationUnit(
5363 r'''
5364 class C {
5365 int length {}
5366 void foo() {}
5367 }''',
5368 [ParserErrorCode.MISSING_GET]);
5369 expect(unit, isNotNull);
5370 ClassDeclaration classDeclaration =
5371 unit.declarations[0] as ClassDeclaration;
5372 NodeList<ClassMember> members = classDeclaration.members;
5373 expect(members, hasLength(2));
5374 EngineTestCase.assertInstanceOf(
5375 (obj) => obj is MethodDeclaration, MethodDeclaration, members[0]);
5376 ClassMember member = members[1];
5377 EngineTestCase.assertInstanceOf(
5378 (obj) => obj is MethodDeclaration, MethodDeclaration, member);
5379 expect((member as MethodDeclaration).name.name, "foo");
5380 }
5381
5382 void test_missingIdentifier_afterAnnotation() {
5383 createParser('@override }');
5384 ClassMember member = parser.parseClassMember('C');
5385 expectNotNullIfNoErrors(member);
5386 listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_CLASS_MEMBER]);
5387 expect(member, new isInstanceOf<MethodDeclaration>());
5388 MethodDeclaration method = member;
5389 expect(method.documentationComment, isNull);
5390 NodeList<Annotation> metadata = method.metadata;
5391 expect(metadata, hasLength(1));
5392 expect(metadata[0].name.name, "override");
5393 }
5394
5395 void test_missingSemicolon_varialeDeclarationList() {
5396 void verify(CompilationUnitMember member, String expectedTypeName,
5397 String expectedName, String expectedSemicolon) {
5398 expect(member, new isInstanceOf<TopLevelVariableDeclaration>());
5399 TopLevelVariableDeclaration declaration = member;
5400 VariableDeclarationList variableList = declaration.variables;
5401 expect(variableList, isNotNull);
5402 NodeList<VariableDeclaration> variables = variableList.variables;
5403 expect(variables, hasLength(1));
5404 VariableDeclaration variable = variables[0];
5405 expect(variableList.type.toString(), expectedTypeName);
5406 expect(variable.name.name, expectedName);
5407 expect(declaration.semicolon.lexeme, expectedSemicolon);
5408 }
5409
5410 CompilationUnit unit = parseCompilationUnit('String n x = "";', [
5411 ParserErrorCode.EXPECTED_TOKEN,
5412 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE
5413 ]);
5414 expect(unit, isNotNull);
5415 NodeList<CompilationUnitMember> declarations = unit.declarations;
5416 expect(declarations, hasLength(2));
5417 verify(declarations[0], 'String', 'n', '');
5418 verify(declarations[1], 'null', 'x', ';');
5419 }
5420
5421 void test_multiplicativeExpression_missing_LHS() {
5422 BinaryExpression expression =
5423 parseExpression("* y", [ParserErrorCode.MISSING_IDENTIFIER]);
5424 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
5425 SimpleIdentifier, expression.leftOperand);
5426 expect(expression.leftOperand.isSynthetic, isTrue);
5427 }
5428
5429 void test_multiplicativeExpression_missing_LHS_RHS() {
5430 BinaryExpression expression = parseExpression("*", [
5431 ParserErrorCode.MISSING_IDENTIFIER,
5432 ParserErrorCode.MISSING_IDENTIFIER
5433 ]);
5434 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
5435 SimpleIdentifier, expression.leftOperand);
5436 expect(expression.leftOperand.isSynthetic, isTrue);
5437 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
5438 SimpleIdentifier, expression.rightOperand);
5439 expect(expression.rightOperand.isSynthetic, isTrue);
5440 }
5441
5442 void test_multiplicativeExpression_missing_RHS() {
5443 BinaryExpression expression =
5444 parseExpression("x *", [ParserErrorCode.MISSING_IDENTIFIER]);
5445 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
5446 SimpleIdentifier, expression.rightOperand);
5447 expect(expression.rightOperand.isSynthetic, isTrue);
5448 }
5449
5450 void test_multiplicativeExpression_missing_RHS_super() {
5451 BinaryExpression expression =
5452 parseExpression("super *", [ParserErrorCode.MISSING_IDENTIFIER]);
5453 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
5454 SimpleIdentifier, expression.rightOperand);
5455 expect(expression.rightOperand.isSynthetic, isTrue);
5456 }
5457
5458 void test_multiplicativeExpression_precedence_unary_left() {
5459 BinaryExpression expression =
5460 parseExpression("-x *", [ParserErrorCode.MISSING_IDENTIFIER]);
5461 EngineTestCase.assertInstanceOf((obj) => obj is PrefixExpression,
5462 PrefixExpression, expression.leftOperand);
5463 }
5464
5465 void test_multiplicativeExpression_precedence_unary_right() {
5466 BinaryExpression expression =
5467 parseExpression("* -y", [ParserErrorCode.MISSING_IDENTIFIER]);
5468 EngineTestCase.assertInstanceOf((obj) => obj is PrefixExpression,
5469 PrefixExpression, expression.rightOperand);
5470 }
5471
5472 void test_multiplicativeExpression_super() {
5473 BinaryExpression expression = parseExpression("super == ==", [
5474 ParserErrorCode.MISSING_IDENTIFIER,
5475 ParserErrorCode.MISSING_IDENTIFIER,
5476 ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND
5477 ]);
5478 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
5479 BinaryExpression, expression.leftOperand);
5480 }
5481
5482 void test_nonStringLiteralUri_import() {
5483 parseCompilationUnit("import dart:io; class C {}",
5484 [ParserErrorCode.NON_STRING_LITERAL_AS_URI]);
5485 }
5486
5487 void test_prefixExpression_missing_operand_minus() {
5488 PrefixExpression expression =
5489 parseExpression("-", [ParserErrorCode.MISSING_IDENTIFIER]);
5490 EngineTestCase.assertInstanceOf(
5491 (obj) => obj is SimpleIdentifier, SimpleIdentifier, expression.operand);
5492 expect(expression.operand.isSynthetic, isTrue);
5493 expect(expression.operator.type, TokenType.MINUS);
5494 }
5495
5496 void test_primaryExpression_argumentDefinitionTest() {
5497 createParser('?a');
5498 Expression expression = parser.parsePrimaryExpression();
5499 expectNotNullIfNoErrors(expression);
5500 listener.assertErrorsWithCodes([ParserErrorCode.UNEXPECTED_TOKEN]);
5501 expect(expression, new isInstanceOf<SimpleIdentifier>());
5502 }
5503
5504 void test_relationalExpression_missing_LHS() {
5505 IsExpression expression =
5506 parseExpression("is y", [ParserErrorCode.MISSING_IDENTIFIER]);
5507 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
5508 SimpleIdentifier, expression.expression);
5509 expect(expression.expression.isSynthetic, isTrue);
5510 }
5511
5512 void test_relationalExpression_missing_LHS_RHS() {
5513 IsExpression expression = parseExpression("is", [
5514 ParserErrorCode.EXPECTED_TYPE_NAME,
5515 ParserErrorCode.MISSING_IDENTIFIER
5516 ]);
5517 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
5518 SimpleIdentifier, expression.expression);
5519 expect(expression.expression.isSynthetic, isTrue);
5520 EngineTestCase.assertInstanceOf(
5521 (obj) => obj is TypeName, TypeName, expression.type);
5522 expect(expression.type.isSynthetic, isTrue);
5523 }
5524
5525 void test_relationalExpression_missing_RHS() {
5526 IsExpression expression =
5527 parseExpression("x is", [ParserErrorCode.EXPECTED_TYPE_NAME]);
5528 EngineTestCase.assertInstanceOf(
5529 (obj) => obj is TypeName, TypeName, expression.type);
5530 expect(expression.type.isSynthetic, isTrue);
5531 }
5532
5533 void test_relationalExpression_precedence_shift_right() {
5534 IsExpression expression = parseExpression("<< is", [
5535 ParserErrorCode.EXPECTED_TYPE_NAME,
5536 ParserErrorCode.MISSING_IDENTIFIER,
5537 ParserErrorCode.MISSING_IDENTIFIER
5538 ]);
5539 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
5540 BinaryExpression, expression.expression);
5541 }
5542
5543 void test_shiftExpression_missing_LHS() {
5544 BinaryExpression expression =
5545 parseExpression("<< y", [ParserErrorCode.MISSING_IDENTIFIER]);
5546 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
5547 SimpleIdentifier, expression.leftOperand);
5548 expect(expression.leftOperand.isSynthetic, isTrue);
5549 }
5550
5551 void test_shiftExpression_missing_LHS_RHS() {
5552 BinaryExpression expression = parseExpression("<<", [
5553 ParserErrorCode.MISSING_IDENTIFIER,
5554 ParserErrorCode.MISSING_IDENTIFIER
5555 ]);
5556 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
5557 SimpleIdentifier, expression.leftOperand);
5558 expect(expression.leftOperand.isSynthetic, isTrue);
5559 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
5560 SimpleIdentifier, expression.rightOperand);
5561 expect(expression.rightOperand.isSynthetic, isTrue);
5562 }
5563
4415 void test_shiftExpression_missing_RHS() { 5564 void test_shiftExpression_missing_RHS() {
4416 BinaryExpression expression = 5565 BinaryExpression expression =
4417 parseExpression("x <<", [ParserErrorCode.MISSING_IDENTIFIER]); 5566 parseExpression("x <<", [ParserErrorCode.MISSING_IDENTIFIER]);
4418 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, 5567 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
4419 SimpleIdentifier, expression.rightOperand); 5568 SimpleIdentifier, expression.rightOperand);
4420 expect(expression.rightOperand.isSynthetic, isTrue); 5569 expect(expression.rightOperand.isSynthetic, isTrue);
4421 } 5570 }
4422 5571
4423 void test_shiftExpression_missing_RHS_super() { 5572 void test_shiftExpression_missing_RHS_super() {
4424 BinaryExpression expression = 5573 BinaryExpression expression =
(...skipping 3446 matching lines...) Expand 10 before | Expand all | Expand 10 after
7871 9020
7872 void test_parseFinalConstVarOrType_void_noIdentifier() { 9021 void test_parseFinalConstVarOrType_void_noIdentifier() {
7873 createParser('void,'); 9022 createParser('void,');
7874 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); 9023 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false);
7875 expectNotNullIfNoErrors(result); 9024 expectNotNullIfNoErrors(result);
7876 listener.assertNoErrors(); 9025 listener.assertNoErrors();
7877 expect(result.keyword, isNull); 9026 expect(result.keyword, isNull);
7878 expect(result.type, isNotNull); 9027 expect(result.type, isNotNull);
7879 } 9028 }
7880 9029
7881 void test_parseFormalParameter_covariant_final_named() {
7882 ParameterKind kind = ParameterKind.NAMED;
7883 createParser('covariant final a : null');
7884 FormalParameter parameter = parser.parseFormalParameter(kind);
7885 expectNotNullIfNoErrors(parameter);
7886 listener.assertNoErrors();
7887 expect(parameter, new isInstanceOf<DefaultFormalParameter>());
7888 DefaultFormalParameter defaultParameter = parameter;
7889 SimpleFormalParameter simpleParameter =
7890 defaultParameter.parameter as SimpleFormalParameter;
7891 expect(simpleParameter.covariantKeyword, isNotNull);
7892 expect(simpleParameter.identifier, isNotNull);
7893 expect(simpleParameter.keyword, isNotNull);
7894 expect(simpleParameter.type, isNull);
7895 expect(simpleParameter.kind, kind);
7896 expect(defaultParameter.separator, isNotNull);
7897 expect(defaultParameter.defaultValue, isNotNull);
7898 expect(defaultParameter.kind, kind);
7899 }
7900
7901 void test_parseFormalParameter_covariant_final_normal() {
7902 ParameterKind kind = ParameterKind.REQUIRED;
7903 createParser('covariant final a');
7904 FormalParameter parameter = parser.parseFormalParameter(kind);
7905 expectNotNullIfNoErrors(parameter);
7906 listener.assertNoErrors();
7907 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
7908 SimpleFormalParameter simpleParameter = parameter;
7909 expect(simpleParameter.covariantKeyword, isNotNull);
7910 expect(simpleParameter.identifier, isNotNull);
7911 expect(simpleParameter.keyword, isNotNull);
7912 expect(simpleParameter.type, isNull);
7913 expect(simpleParameter.kind, kind);
7914 }
7915
7916 void test_parseFormalParameter_covariant_final_positional() {
7917 ParameterKind kind = ParameterKind.POSITIONAL;
7918 createParser('covariant final a = null');
7919 FormalParameter parameter = parser.parseFormalParameter(kind);
7920 expectNotNullIfNoErrors(parameter);
7921 listener.assertNoErrors();
7922 expect(parameter, new isInstanceOf<DefaultFormalParameter>());
7923 DefaultFormalParameter defaultParameter = parameter;
7924 SimpleFormalParameter simpleParameter =
7925 defaultParameter.parameter as SimpleFormalParameter;
7926 expect(simpleParameter.covariantKeyword, isNotNull);
7927 expect(simpleParameter.identifier, isNotNull);
7928 expect(simpleParameter.keyword, isNotNull);
7929 expect(simpleParameter.type, isNull);
7930 expect(simpleParameter.kind, kind);
7931 expect(defaultParameter.separator, isNotNull);
7932 expect(defaultParameter.defaultValue, isNotNull);
7933 expect(defaultParameter.kind, kind);
7934 }
7935
7936 void test_parseFormalParameter_covariant_final_type_named() {
7937 ParameterKind kind = ParameterKind.NAMED;
7938 createParser('covariant final A a : null');
7939 FormalParameter parameter = parser.parseFormalParameter(kind);
7940 expectNotNullIfNoErrors(parameter);
7941 listener.assertNoErrors();
7942 expect(parameter, new isInstanceOf<DefaultFormalParameter>());
7943 DefaultFormalParameter defaultParameter = parameter;
7944 SimpleFormalParameter simpleParameter =
7945 defaultParameter.parameter as SimpleFormalParameter;
7946 expect(simpleParameter.covariantKeyword, isNotNull);
7947 expect(simpleParameter.identifier, isNotNull);
7948 expect(simpleParameter.keyword, isNotNull);
7949 expect(simpleParameter.type, isNotNull);
7950 expect(simpleParameter.kind, kind);
7951 expect(defaultParameter.separator, isNotNull);
7952 expect(defaultParameter.defaultValue, isNotNull);
7953 expect(defaultParameter.kind, kind);
7954 }
7955
7956 void test_parseFormalParameter_covariant_final_type_normal() {
7957 ParameterKind kind = ParameterKind.REQUIRED;
7958 createParser('covariant final A a');
7959 FormalParameter parameter = parser.parseFormalParameter(kind);
7960 expectNotNullIfNoErrors(parameter);
7961 listener.assertNoErrors();
7962 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
7963 SimpleFormalParameter simpleParameter = parameter;
7964 expect(simpleParameter.covariantKeyword, isNotNull);
7965 expect(simpleParameter.identifier, isNotNull);
7966 expect(simpleParameter.keyword, isNotNull);
7967 expect(simpleParameter.type, isNotNull);
7968 expect(simpleParameter.kind, kind);
7969 }
7970
7971 void test_parseFormalParameter_covariant_final_type_positional() {
7972 ParameterKind kind = ParameterKind.POSITIONAL;
7973 createParser('covariant final A a = null');
7974 FormalParameter parameter = parser.parseFormalParameter(kind);
7975 expectNotNullIfNoErrors(parameter);
7976 listener.assertNoErrors();
7977 expect(parameter, new isInstanceOf<DefaultFormalParameter>());
7978 DefaultFormalParameter defaultParameter = parameter;
7979 SimpleFormalParameter simpleParameter =
7980 defaultParameter.parameter as SimpleFormalParameter;
7981 expect(simpleParameter.covariantKeyword, isNotNull);
7982 expect(simpleParameter.identifier, isNotNull);
7983 expect(simpleParameter.keyword, isNotNull);
7984 expect(simpleParameter.type, isNotNull);
7985 expect(simpleParameter.kind, kind);
7986 expect(defaultParameter.separator, isNotNull);
7987 expect(defaultParameter.defaultValue, isNotNull);
7988 expect(defaultParameter.kind, kind);
7989 }
7990
7991 void test_parseFormalParameter_covariant_type_function() {
7992 ParameterKind kind = ParameterKind.REQUIRED;
7993 createParser('covariant String Function(int) a');
7994 FormalParameter parameter = parser.parseFormalParameter(kind);
7995 expectNotNullIfNoErrors(parameter);
7996 listener.assertNoErrors();
7997 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
7998 SimpleFormalParameter simpleParameter = parameter;
7999 expect(simpleParameter.covariantKeyword, isNotNull);
8000 expect(simpleParameter.identifier, isNotNull);
8001 expect(simpleParameter.keyword, isNull);
8002 expect(simpleParameter.type, new isInstanceOf<GenericFunctionType>());
8003 expect(simpleParameter.kind, kind);
8004 }
8005
8006 void test_parseFormalParameter_covariant_type_named() {
8007 ParameterKind kind = ParameterKind.NAMED;
8008 createParser('covariant A a : null');
8009 FormalParameter parameter = parser.parseFormalParameter(kind);
8010 expectNotNullIfNoErrors(parameter);
8011 listener.assertNoErrors();
8012 expect(parameter, new isInstanceOf<DefaultFormalParameter>());
8013 DefaultFormalParameter defaultParameter = parameter;
8014 SimpleFormalParameter simpleParameter =
8015 defaultParameter.parameter as SimpleFormalParameter;
8016 expect(simpleParameter.covariantKeyword, isNotNull);
8017 expect(simpleParameter.identifier, isNotNull);
8018 expect(simpleParameter.keyword, isNull);
8019 expect(simpleParameter.type, isNotNull);
8020 expect(simpleParameter.kind, kind);
8021 expect(defaultParameter.separator, isNotNull);
8022 expect(defaultParameter.defaultValue, isNotNull);
8023 expect(defaultParameter.kind, kind);
8024 }
8025
8026 void test_parseFormalParameter_covariant_type_normal() {
8027 ParameterKind kind = ParameterKind.REQUIRED;
8028 createParser('covariant A<B<C>> a');
8029 FormalParameter parameter = parser.parseFormalParameter(kind);
8030 expectNotNullIfNoErrors(parameter);
8031 listener.assertNoErrors();
8032 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
8033 SimpleFormalParameter simpleParameter = parameter;
8034 expect(simpleParameter.covariantKeyword, isNotNull);
8035 expect(simpleParameter.identifier, isNotNull);
8036 expect(simpleParameter.keyword, isNull);
8037 expect(simpleParameter.type, isNotNull);
8038 expect(simpleParameter.kind, kind);
8039 }
8040
8041 void test_parseFormalParameter_covariant_type_positional() {
8042 ParameterKind kind = ParameterKind.POSITIONAL;
8043 createParser('covariant A a = null');
8044 FormalParameter parameter = parser.parseFormalParameter(kind);
8045 expectNotNullIfNoErrors(parameter);
8046 listener.assertNoErrors();
8047 expect(parameter, new isInstanceOf<DefaultFormalParameter>());
8048 DefaultFormalParameter defaultParameter = parameter;
8049 SimpleFormalParameter simpleParameter =
8050 defaultParameter.parameter as SimpleFormalParameter;
8051 expect(simpleParameter.covariantKeyword, isNotNull);
8052 expect(simpleParameter.identifier, isNotNull);
8053 expect(simpleParameter.keyword, isNull);
8054 expect(simpleParameter.type, isNotNull);
8055 expect(simpleParameter.kind, kind);
8056 expect(defaultParameter.separator, isNotNull);
8057 expect(defaultParameter.defaultValue, isNotNull);
8058 expect(defaultParameter.kind, kind);
8059 }
8060
8061 void test_parseFormalParameter_covariant_var_named() {
8062 ParameterKind kind = ParameterKind.NAMED;
8063 createParser('covariant var a : null');
8064 FormalParameter parameter = parser.parseFormalParameter(kind);
8065 expectNotNullIfNoErrors(parameter);
8066 listener.assertNoErrors();
8067 expect(parameter, new isInstanceOf<DefaultFormalParameter>());
8068 DefaultFormalParameter defaultParameter = parameter;
8069 SimpleFormalParameter simpleParameter =
8070 defaultParameter.parameter as SimpleFormalParameter;
8071 expect(simpleParameter.covariantKeyword, isNotNull);
8072 expect(simpleParameter.identifier, isNotNull);
8073 expect(simpleParameter.keyword, isNotNull);
8074 expect(simpleParameter.type, isNull);
8075 expect(simpleParameter.kind, kind);
8076 expect(defaultParameter.separator, isNotNull);
8077 expect(defaultParameter.defaultValue, isNotNull);
8078 expect(defaultParameter.kind, kind);
8079 }
8080
8081 void test_parseFormalParameter_covariant_var_normal() {
8082 ParameterKind kind = ParameterKind.REQUIRED;
8083 createParser('covariant var a');
8084 FormalParameter parameter = parser.parseFormalParameter(kind);
8085 expectNotNullIfNoErrors(parameter);
8086 listener.assertNoErrors();
8087 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
8088 SimpleFormalParameter simpleParameter = parameter;
8089 expect(simpleParameter.covariantKeyword, isNotNull);
8090 expect(simpleParameter.identifier, isNotNull);
8091 expect(simpleParameter.keyword, isNotNull);
8092 expect(simpleParameter.type, isNull);
8093 expect(simpleParameter.kind, kind);
8094 }
8095
8096 void test_parseFormalParameter_covariant_var_positional() {
8097 ParameterKind kind = ParameterKind.POSITIONAL;
8098 createParser('covariant var a = null');
8099 FormalParameter parameter = parser.parseFormalParameter(kind);
8100 expectNotNullIfNoErrors(parameter);
8101 listener.assertNoErrors();
8102 expect(parameter, new isInstanceOf<DefaultFormalParameter>());
8103 DefaultFormalParameter defaultParameter = parameter;
8104 SimpleFormalParameter simpleParameter =
8105 defaultParameter.parameter as SimpleFormalParameter;
8106 expect(simpleParameter.covariantKeyword, isNotNull);
8107 expect(simpleParameter.identifier, isNotNull);
8108 expect(simpleParameter.keyword, isNotNull);
8109 expect(simpleParameter.type, isNull);
8110 expect(simpleParameter.kind, kind);
8111 expect(defaultParameter.separator, isNotNull);
8112 expect(defaultParameter.defaultValue, isNotNull);
8113 expect(defaultParameter.kind, kind);
8114 }
8115
8116 void test_parseFormalParameter_final_named() {
8117 ParameterKind kind = ParameterKind.NAMED;
8118 createParser('final a : null');
8119 FormalParameter parameter = parser.parseFormalParameter(kind);
8120 expectNotNullIfNoErrors(parameter);
8121 listener.assertNoErrors();
8122 expect(parameter, new isInstanceOf<DefaultFormalParameter>());
8123 DefaultFormalParameter defaultParameter = parameter;
8124 SimpleFormalParameter simpleParameter =
8125 defaultParameter.parameter as SimpleFormalParameter;
8126 expect(simpleParameter.covariantKeyword, isNull);
8127 expect(simpleParameter.identifier, isNotNull);
8128 expect(simpleParameter.keyword, isNotNull);
8129 expect(simpleParameter.type, isNull);
8130 expect(simpleParameter.kind, kind);
8131 expect(defaultParameter.separator, isNotNull);
8132 expect(defaultParameter.defaultValue, isNotNull);
8133 expect(defaultParameter.kind, kind);
8134 }
8135
8136 void test_parseFormalParameter_final_normal() {
8137 ParameterKind kind = ParameterKind.REQUIRED;
8138 createParser('final a');
8139 FormalParameter parameter = parser.parseFormalParameter(kind);
8140 expectNotNullIfNoErrors(parameter);
8141 listener.assertNoErrors();
8142 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
8143 SimpleFormalParameter simpleParameter = parameter;
8144 expect(simpleParameter.covariantKeyword, isNull);
8145 expect(simpleParameter.identifier, isNotNull);
8146 expect(simpleParameter.keyword, isNotNull);
8147 expect(simpleParameter.type, isNull);
8148 expect(simpleParameter.kind, kind);
8149 }
8150
8151 void test_parseFormalParameter_final_positional() {
8152 ParameterKind kind = ParameterKind.POSITIONAL;
8153 createParser('final a = null');
8154 FormalParameter parameter = parser.parseFormalParameter(kind);
8155 expectNotNullIfNoErrors(parameter);
8156 listener.assertNoErrors();
8157 expect(parameter, new isInstanceOf<DefaultFormalParameter>());
8158 DefaultFormalParameter defaultParameter = parameter;
8159 SimpleFormalParameter simpleParameter =
8160 defaultParameter.parameter as SimpleFormalParameter;
8161 expect(simpleParameter.covariantKeyword, isNull);
8162 expect(simpleParameter.identifier, isNotNull);
8163 expect(simpleParameter.keyword, isNotNull);
8164 expect(simpleParameter.type, isNull);
8165 expect(simpleParameter.kind, kind);
8166 expect(defaultParameter.separator, isNotNull);
8167 expect(defaultParameter.defaultValue, isNotNull);
8168 expect(defaultParameter.kind, kind);
8169 }
8170
8171 void test_parseFormalParameter_final_type_named() {
8172 ParameterKind kind = ParameterKind.NAMED;
8173 createParser('final A a : null');
8174 FormalParameter parameter = parser.parseFormalParameter(kind);
8175 expectNotNullIfNoErrors(parameter);
8176 listener.assertNoErrors();
8177 expect(parameter, new isInstanceOf<DefaultFormalParameter>());
8178 DefaultFormalParameter defaultParameter = parameter;
8179 SimpleFormalParameter simpleParameter =
8180 defaultParameter.parameter as SimpleFormalParameter;
8181 expect(simpleParameter.covariantKeyword, isNull);
8182 expect(simpleParameter.identifier, isNotNull);
8183 expect(simpleParameter.keyword, isNotNull);
8184 expect(simpleParameter.type, isNotNull);
8185 expect(simpleParameter.kind, kind);
8186 expect(defaultParameter.separator, isNotNull);
8187 expect(defaultParameter.defaultValue, isNotNull);
8188 expect(defaultParameter.kind, kind);
8189 }
8190
8191 void test_parseFormalParameter_final_type_normal() {
8192 ParameterKind kind = ParameterKind.REQUIRED;
8193 createParser('final A a');
8194 FormalParameter parameter = parser.parseFormalParameter(kind);
8195 expectNotNullIfNoErrors(parameter);
8196 listener.assertNoErrors();
8197 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
8198 SimpleFormalParameter simpleParameter = parameter;
8199 expect(simpleParameter.covariantKeyword, isNull);
8200 expect(simpleParameter.identifier, isNotNull);
8201 expect(simpleParameter.keyword, isNotNull);
8202 expect(simpleParameter.type, isNotNull);
8203 expect(simpleParameter.kind, kind);
8204 }
8205
8206 void test_parseFormalParameter_final_type_positional() {
8207 ParameterKind kind = ParameterKind.POSITIONAL;
8208 createParser('final A a = null');
8209 FormalParameter parameter = parser.parseFormalParameter(kind);
8210 expectNotNullIfNoErrors(parameter);
8211 listener.assertNoErrors();
8212 expect(parameter, new isInstanceOf<DefaultFormalParameter>());
8213 DefaultFormalParameter defaultParameter = parameter;
8214 SimpleFormalParameter simpleParameter =
8215 defaultParameter.parameter as SimpleFormalParameter;
8216 expect(simpleParameter.covariantKeyword, isNull);
8217 expect(simpleParameter.identifier, isNotNull);
8218 expect(simpleParameter.keyword, isNotNull);
8219 expect(simpleParameter.type, isNotNull);
8220 expect(simpleParameter.kind, kind);
8221 expect(defaultParameter.separator, isNotNull);
8222 expect(defaultParameter.defaultValue, isNotNull);
8223 expect(defaultParameter.kind, kind);
8224 }
8225
8226 void test_parseFormalParameter_type_function() {
8227 ParameterKind kind = ParameterKind.REQUIRED;
8228 createParser('String Function(int) a');
8229 FormalParameter parameter = parser.parseFormalParameter(kind);
8230 expectNotNullIfNoErrors(parameter);
8231 listener.assertNoErrors();
8232 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
8233 SimpleFormalParameter simpleParameter = parameter;
8234 expect(simpleParameter.covariantKeyword, isNull);
8235 expect(simpleParameter.identifier, isNotNull);
8236 expect(simpleParameter.keyword, isNull);
8237 expect(simpleParameter.type, new isInstanceOf<GenericFunctionType>());
8238 expect(simpleParameter.kind, kind);
8239 }
8240
8241 void test_parseFormalParameter_type_named() {
8242 ParameterKind kind = ParameterKind.NAMED;
8243 createParser('A a : null');
8244 FormalParameter parameter = parser.parseFormalParameter(kind);
8245 expectNotNullIfNoErrors(parameter);
8246 listener.assertNoErrors();
8247 expect(parameter, new isInstanceOf<DefaultFormalParameter>());
8248 DefaultFormalParameter defaultParameter = parameter;
8249 SimpleFormalParameter simpleParameter =
8250 defaultParameter.parameter as SimpleFormalParameter;
8251 expect(simpleParameter.covariantKeyword, isNull);
8252 expect(simpleParameter.identifier, isNotNull);
8253 expect(simpleParameter.keyword, isNull);
8254 expect(simpleParameter.type, isNotNull);
8255 expect(simpleParameter.kind, kind);
8256 expect(defaultParameter.separator, isNotNull);
8257 expect(defaultParameter.defaultValue, isNotNull);
8258 expect(defaultParameter.kind, kind);
8259 }
8260
8261 void test_parseFormalParameter_type_normal() {
8262 ParameterKind kind = ParameterKind.REQUIRED;
8263 createParser('A a');
8264 FormalParameter parameter = parser.parseFormalParameter(kind);
8265 expectNotNullIfNoErrors(parameter);
8266 listener.assertNoErrors();
8267 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
8268 SimpleFormalParameter simpleParameter = parameter;
8269 expect(simpleParameter.covariantKeyword, isNull);
8270 expect(simpleParameter.identifier, isNotNull);
8271 expect(simpleParameter.keyword, isNull);
8272 expect(simpleParameter.type, isNotNull);
8273 expect(simpleParameter.kind, kind);
8274 }
8275
8276 void test_parseFormalParameter_type_positional() {
8277 ParameterKind kind = ParameterKind.POSITIONAL;
8278 createParser('A a = null');
8279 FormalParameter parameter = parser.parseFormalParameter(kind);
8280 expectNotNullIfNoErrors(parameter);
8281 listener.assertNoErrors();
8282 expect(parameter, new isInstanceOf<DefaultFormalParameter>());
8283 DefaultFormalParameter defaultParameter = parameter;
8284 SimpleFormalParameter simpleParameter =
8285 defaultParameter.parameter as SimpleFormalParameter;
8286 expect(simpleParameter.covariantKeyword, isNull);
8287 expect(simpleParameter.identifier, isNotNull);
8288 expect(simpleParameter.keyword, isNull);
8289 expect(simpleParameter.type, isNotNull);
8290 expect(simpleParameter.kind, kind);
8291 expect(defaultParameter.separator, isNotNull);
8292 expect(defaultParameter.defaultValue, isNotNull);
8293 expect(defaultParameter.kind, kind);
8294 }
8295
8296 void test_parseFormalParameter_var_named() {
8297 ParameterKind kind = ParameterKind.NAMED;
8298 createParser('var a : null');
8299 FormalParameter parameter = parser.parseFormalParameter(kind);
8300 expectNotNullIfNoErrors(parameter);
8301 listener.assertNoErrors();
8302 expect(parameter, new isInstanceOf<DefaultFormalParameter>());
8303 DefaultFormalParameter defaultParameter = parameter;
8304 SimpleFormalParameter simpleParameter =
8305 defaultParameter.parameter as SimpleFormalParameter;
8306 expect(simpleParameter.covariantKeyword, isNull);
8307 expect(simpleParameter.identifier, isNotNull);
8308 expect(simpleParameter.keyword, isNotNull);
8309 expect(simpleParameter.type, isNull);
8310 expect(simpleParameter.kind, kind);
8311 expect(defaultParameter.separator, isNotNull);
8312 expect(defaultParameter.defaultValue, isNotNull);
8313 expect(defaultParameter.kind, kind);
8314 }
8315
8316 void test_parseFormalParameter_var_normal() {
8317 ParameterKind kind = ParameterKind.REQUIRED;
8318 createParser('var a');
8319 FormalParameter parameter = parser.parseFormalParameter(kind);
8320 expectNotNullIfNoErrors(parameter);
8321 listener.assertNoErrors();
8322 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
8323 SimpleFormalParameter simpleParameter = parameter;
8324 expect(simpleParameter.covariantKeyword, isNull);
8325 expect(simpleParameter.identifier, isNotNull);
8326 expect(simpleParameter.keyword, isNotNull);
8327 expect(simpleParameter.type, isNull);
8328 expect(simpleParameter.kind, kind);
8329 }
8330
8331 void test_parseFormalParameter_var_positional() {
8332 ParameterKind kind = ParameterKind.POSITIONAL;
8333 createParser('var a = null');
8334 FormalParameter parameter = parser.parseFormalParameter(kind);
8335 expectNotNullIfNoErrors(parameter);
8336 listener.assertNoErrors();
8337 expect(parameter, new isInstanceOf<DefaultFormalParameter>());
8338 DefaultFormalParameter defaultParameter = parameter;
8339 SimpleFormalParameter simpleParameter =
8340 defaultParameter.parameter as SimpleFormalParameter;
8341 expect(simpleParameter.covariantKeyword, isNull);
8342 expect(simpleParameter.identifier, isNotNull);
8343 expect(simpleParameter.keyword, isNotNull);
8344 expect(simpleParameter.type, isNull);
8345 expect(simpleParameter.kind, kind);
8346 expect(defaultParameter.separator, isNotNull);
8347 expect(defaultParameter.defaultValue, isNotNull);
8348 expect(defaultParameter.kind, kind);
8349 }
8350
8351 void test_parseFormalParameterList_empty() {
8352 createParser('()');
8353 FormalParameterList list = parser.parseFormalParameterList();
8354 expectNotNullIfNoErrors(list);
8355 listener.assertNoErrors();
8356 expect(list.leftParenthesis, isNotNull);
8357 expect(list.leftDelimiter, isNull);
8358 expect(list.parameters, hasLength(0));
8359 expect(list.rightDelimiter, isNull);
8360 expect(list.rightParenthesis, isNotNull);
8361 }
8362
8363 void test_parseFormalParameterList_named_multiple() {
8364 createParser('({A a : 1, B b, C c : 3})');
8365 FormalParameterList list = parser.parseFormalParameterList();
8366 expectNotNullIfNoErrors(list);
8367 listener.assertNoErrors();
8368 expect(list.leftParenthesis, isNotNull);
8369 expect(list.leftDelimiter, isNotNull);
8370 expect(list.parameters, hasLength(3));
8371 expect(list.rightDelimiter, isNotNull);
8372 expect(list.rightParenthesis, isNotNull);
8373 }
8374
8375 void test_parseFormalParameterList_named_single() {
8376 createParser('({A a})');
8377 FormalParameterList list = parser.parseFormalParameterList();
8378 expectNotNullIfNoErrors(list);
8379 listener.assertNoErrors();
8380 expect(list.leftParenthesis, isNotNull);
8381 expect(list.leftDelimiter, isNotNull);
8382 expect(list.parameters, hasLength(1));
8383 expect(list.rightDelimiter, isNotNull);
8384 expect(list.rightParenthesis, isNotNull);
8385 }
8386
8387 void test_parseFormalParameterList_named_trailing_comma() {
8388 createParser('(A a, {B b,})');
8389 FormalParameterList list = parser.parseFormalParameterList();
8390 expectNotNullIfNoErrors(list);
8391 listener.assertNoErrors();
8392 expect(list.leftParenthesis, isNotNull);
8393 expect(list.leftDelimiter, isNotNull);
8394 expect(list.parameters, hasLength(2));
8395 expect(list.rightDelimiter, isNotNull);
8396 expect(list.rightParenthesis, isNotNull);
8397 }
8398
8399 void test_parseFormalParameterList_normal_multiple() {
8400 createParser('(A a, B b, C c)');
8401 FormalParameterList list = parser.parseFormalParameterList();
8402 expectNotNullIfNoErrors(list);
8403 listener.assertNoErrors();
8404 expect(list.leftParenthesis, isNotNull);
8405 expect(list.leftDelimiter, isNull);
8406 expect(list.parameters, hasLength(3));
8407 expect(list.rightDelimiter, isNull);
8408 expect(list.rightParenthesis, isNotNull);
8409 }
8410
8411 void test_parseFormalParameterList_normal_named() {
8412 createParser('(A a, {B b})');
8413 FormalParameterList list = parser.parseFormalParameterList();
8414 expectNotNullIfNoErrors(list);
8415 listener.assertNoErrors();
8416 expect(list.leftParenthesis, isNotNull);
8417 expect(list.leftDelimiter, isNotNull);
8418 expect(list.parameters, hasLength(2));
8419 expect(list.rightDelimiter, isNotNull);
8420 expect(list.rightParenthesis, isNotNull);
8421 }
8422
8423 void test_parseFormalParameterList_normal_named_inFunctionType() {
8424 createParser('(A, {B b})');
8425 FormalParameterList list =
8426 parser.parseFormalParameterList(inFunctionType: true);
8427 expectNotNullIfNoErrors(list);
8428 listener.assertNoErrors();
8429 expect(list.leftParenthesis, isNotNull);
8430 expect(list.leftDelimiter, isNotNull);
8431 expect(list.rightDelimiter, isNotNull);
8432 expect(list.rightParenthesis, isNotNull);
8433 NodeList<FormalParameter> parameters = list.parameters;
8434 expect(parameters, hasLength(2));
8435
8436 expect(parameters[0], new isInstanceOf<SimpleFormalParameter>());
8437 SimpleFormalParameter required = parameters[0];
8438 expect(required.identifier, isNull);
8439 expect(required.type, new isInstanceOf<TypeName>());
8440 expect((required.type as TypeName).name.name, 'A');
8441
8442 expect(parameters[1], new isInstanceOf<DefaultFormalParameter>());
8443 DefaultFormalParameter named = parameters[1];
8444 expect(named.identifier, isNotNull);
8445 expect(named.parameter, new isInstanceOf<SimpleFormalParameter>());
8446 SimpleFormalParameter simple = named.parameter;
8447 expect(simple.type, new isInstanceOf<TypeName>());
8448 expect((simple.type as TypeName).name.name, 'B');
8449 }
8450
8451 void test_parseFormalParameterList_normal_positional() {
8452 createParser('(A a, [B b])');
8453 FormalParameterList list = parser.parseFormalParameterList();
8454 expectNotNullIfNoErrors(list);
8455 listener.assertNoErrors();
8456 expect(list.leftParenthesis, isNotNull);
8457 expect(list.leftDelimiter, isNotNull);
8458 expect(list.parameters, hasLength(2));
8459 expect(list.rightDelimiter, isNotNull);
8460 expect(list.rightParenthesis, isNotNull);
8461 }
8462
8463 void test_parseFormalParameterList_normal_single() {
8464 createParser('(A a)');
8465 FormalParameterList list = parser.parseFormalParameterList();
8466 expectNotNullIfNoErrors(list);
8467 listener.assertNoErrors();
8468 expect(list.leftParenthesis, isNotNull);
8469 expect(list.leftDelimiter, isNull);
8470 expect(list.parameters, hasLength(1));
8471 expect(list.rightDelimiter, isNull);
8472 expect(list.rightParenthesis, isNotNull);
8473 }
8474
8475 void test_parseFormalParameterList_normal_single_Function() {
8476 createParser('(Function f)');
8477 FormalParameterList list = parser.parseFormalParameterList();
8478 expectNotNullIfNoErrors(list);
8479 listener.assertNoErrors();
8480 expect(list.leftParenthesis, isNotNull);
8481 expect(list.leftDelimiter, isNull);
8482 expect(list.parameters, hasLength(1));
8483 expect(list.rightDelimiter, isNull);
8484 expect(list.rightParenthesis, isNotNull);
8485 }
8486
8487 void test_parseFormalParameterList_normal_single_trailing_comma() {
8488 createParser('(A a,)');
8489 FormalParameterList list = parser.parseFormalParameterList();
8490 expectNotNullIfNoErrors(list);
8491 listener.assertNoErrors();
8492 expect(list.leftParenthesis, isNotNull);
8493 expect(list.leftDelimiter, isNull);
8494 expect(list.parameters, hasLength(1));
8495 expect(list.rightDelimiter, isNull);
8496 expect(list.rightParenthesis, isNotNull);
8497 }
8498
8499 void test_parseFormalParameterList_positional_multiple() {
8500 createParser('([A a = null, B b, C c = null])');
8501 FormalParameterList list = parser.parseFormalParameterList();
8502 expectNotNullIfNoErrors(list);
8503 listener.assertNoErrors();
8504 expect(list.leftParenthesis, isNotNull);
8505 expect(list.leftDelimiter, isNotNull);
8506 expect(list.parameters, hasLength(3));
8507 expect(list.rightDelimiter, isNotNull);
8508 expect(list.rightParenthesis, isNotNull);
8509 }
8510
8511 void test_parseFormalParameterList_positional_single() {
8512 createParser('([A a = null])');
8513 FormalParameterList list = parser.parseFormalParameterList();
8514 expectNotNullIfNoErrors(list);
8515 listener.assertNoErrors();
8516 expect(list.leftParenthesis, isNotNull);
8517 expect(list.leftDelimiter, isNotNull);
8518 expect(list.parameters, hasLength(1));
8519 expect(list.rightDelimiter, isNotNull);
8520 expect(list.rightParenthesis, isNotNull);
8521 }
8522
8523 void test_parseFormalParameterList_positional_trailing_comma() {
8524 createParser('(A a, [B b,])');
8525 FormalParameterList list = parser.parseFormalParameterList();
8526 expectNotNullIfNoErrors(list);
8527 listener.assertNoErrors();
8528 expect(list.leftParenthesis, isNotNull);
8529 expect(list.leftDelimiter, isNotNull);
8530 expect(list.parameters, hasLength(2));
8531 expect(list.rightDelimiter, isNotNull);
8532 expect(list.rightParenthesis, isNotNull);
8533 }
8534
8535 void test_parseFormalParameterList_prefixedType() {
8536 createParser('(io.File f)');
8537 FormalParameterList list = parser.parseFormalParameterList();
8538 expectNotNullIfNoErrors(list);
8539 listener.assertNoErrors();
8540 expect(list.leftParenthesis, isNotNull);
8541 expect(list.leftDelimiter, isNull);
8542 expect(list.parameters, hasLength(1));
8543 expect(list.parameters[0].toSource(), 'io.File f');
8544 expect(list.rightDelimiter, isNull);
8545 expect(list.rightParenthesis, isNotNull);
8546 }
8547
8548 void test_parseFormalParameterList_prefixedType_partial() {
8549 createParser('(io.)');
8550 FormalParameterList list = parser.parseFormalParameterList();
8551 expectNotNullIfNoErrors(list);
8552 listener.assertErrorsWithCodes([
8553 ParserErrorCode.MISSING_IDENTIFIER,
8554 ParserErrorCode.MISSING_IDENTIFIER
8555 ]);
8556 expect(list.leftParenthesis, isNotNull);
8557 expect(list.leftDelimiter, isNull);
8558 expect(list.parameters, hasLength(1));
8559 expect(list.parameters[0].toSource(), 'io. ');
8560 expect(list.rightDelimiter, isNull);
8561 expect(list.rightParenthesis, isNotNull);
8562 }
8563
8564 void test_parseFormalParameterList_prefixedType_partial2() {
8565 createParser('(io.,a)');
8566 FormalParameterList list = parser.parseFormalParameterList();
8567 expectNotNullIfNoErrors(list);
8568 listener.assertErrorsWithCodes([
8569 ParserErrorCode.MISSING_IDENTIFIER,
8570 ParserErrorCode.MISSING_IDENTIFIER
8571 ]);
8572 expect(list.leftParenthesis, isNotNull);
8573 expect(list.leftDelimiter, isNull);
8574 expect(list.parameters, hasLength(2));
8575 expect(list.parameters[0].toSource(), 'io. ');
8576 expect(list.parameters[1].toSource(), 'a');
8577 expect(list.rightDelimiter, isNull);
8578 expect(list.rightParenthesis, isNotNull);
8579 }
8580
8581 void test_parseForStatement_each_await() { 9030 void test_parseForStatement_each_await() {
8582 createParser('await for (element in list) {}'); 9031 createParser('await for (element in list) {}');
8583 Statement statement = parser.parseForStatement(); 9032 Statement statement = parser.parseForStatement();
8584 expectNotNullIfNoErrors(statement); 9033 expectNotNullIfNoErrors(statement);
8585 listener.assertNoErrors(); 9034 listener.assertNoErrors();
8586 expect(statement, new isInstanceOf<ForEachStatement>()); 9035 expect(statement, new isInstanceOf<ForEachStatement>());
8587 ForEachStatement forStatement = statement; 9036 ForEachStatement forStatement = statement;
8588 expect(forStatement.awaitKeyword, isNotNull); 9037 expect(forStatement.awaitKeyword, isNotNull);
8589 expect(forStatement.forKeyword, isNotNull); 9038 expect(forStatement.forKeyword, isNotNull);
8590 expect(forStatement.leftParenthesis, isNotNull); 9039 expect(forStatement.leftParenthesis, isNotNull);
(...skipping 1429 matching lines...) Expand 10 before | Expand all | Expand 10 after
10020 expect(expressionStatement.expression, isNotNull); 10469 expect(expressionStatement.expression, isNotNull);
10021 } 10470 }
10022 10471
10023 void test_parseNonLabeledStatement_variableDeclaration_final_namedFunction() { 10472 void test_parseNonLabeledStatement_variableDeclaration_final_namedFunction() {
10024 createParser('final int Function = 0;'); 10473 createParser('final int Function = 0;');
10025 Statement statement = parser.parseNonLabeledStatement(); 10474 Statement statement = parser.parseNonLabeledStatement();
10026 expectNotNullIfNoErrors(statement); 10475 expectNotNullIfNoErrors(statement);
10027 listener.assertNoErrors(); 10476 listener.assertNoErrors();
10028 } 10477 }
10029 10478
10030 void test_parseNormalFormalParameter_field_const_noType() {
10031 createParser('const this.a)');
10032 NormalFormalParameter parameter = parser.parseNormalFormalParameter();
10033 expectNotNullIfNoErrors(parameter);
10034 listener.assertNoErrors();
10035 expect(parameter, new isInstanceOf<FieldFormalParameter>());
10036 FieldFormalParameter fieldParameter = parameter;
10037 expect(fieldParameter.keyword, isNotNull);
10038 expect(fieldParameter.type, isNull);
10039 expect(fieldParameter.identifier, isNotNull);
10040 expect(fieldParameter.parameters, isNull);
10041 }
10042
10043 void test_parseNormalFormalParameter_field_const_type() {
10044 createParser('const A this.a)');
10045 NormalFormalParameter parameter = parser.parseNormalFormalParameter();
10046 expectNotNullIfNoErrors(parameter);
10047 listener.assertNoErrors();
10048 expect(parameter, new isInstanceOf<FieldFormalParameter>());
10049 FieldFormalParameter fieldParameter = parameter;
10050 expect(fieldParameter.keyword, isNotNull);
10051 expect(fieldParameter.type, isNotNull);
10052 expect(fieldParameter.identifier, isNotNull);
10053 expect(fieldParameter.parameters, isNull);
10054 }
10055
10056 void test_parseNormalFormalParameter_field_final_noType() {
10057 createParser('final this.a)');
10058 NormalFormalParameter parameter = parser.parseNormalFormalParameter();
10059 expectNotNullIfNoErrors(parameter);
10060 listener.assertNoErrors();
10061 expect(parameter, new isInstanceOf<FieldFormalParameter>());
10062 FieldFormalParameter fieldParameter = parameter;
10063 expect(fieldParameter.keyword, isNotNull);
10064 expect(fieldParameter.type, isNull);
10065 expect(fieldParameter.identifier, isNotNull);
10066 expect(fieldParameter.parameters, isNull);
10067 }
10068
10069 void test_parseNormalFormalParameter_field_final_type() {
10070 createParser('final A this.a)');
10071 NormalFormalParameter parameter = parser.parseNormalFormalParameter();
10072 expectNotNullIfNoErrors(parameter);
10073 listener.assertNoErrors();
10074 expect(parameter, new isInstanceOf<FieldFormalParameter>());
10075 FieldFormalParameter fieldParameter = parameter;
10076 expect(fieldParameter.keyword, isNotNull);
10077 expect(fieldParameter.type, isNotNull);
10078 expect(fieldParameter.identifier, isNotNull);
10079 expect(fieldParameter.parameters, isNull);
10080 }
10081
10082 void test_parseNormalFormalParameter_field_function_nested() {
10083 createParser('this.a(B b))');
10084 NormalFormalParameter parameter = parser.parseNormalFormalParameter();
10085 expectNotNullIfNoErrors(parameter);
10086 listener.assertNoErrors();
10087 expect(parameter, new isInstanceOf<FieldFormalParameter>());
10088 FieldFormalParameter fieldParameter = parameter;
10089 expect(fieldParameter.keyword, isNull);
10090 expect(fieldParameter.type, isNull);
10091 expect(fieldParameter.identifier, isNotNull);
10092 FormalParameterList parameterList = fieldParameter.parameters;
10093 expect(parameterList, isNotNull);
10094 expect(parameterList.parameters, hasLength(1));
10095 }
10096
10097 void test_parseNormalFormalParameter_field_function_noNested() {
10098 createParser('this.a())');
10099 NormalFormalParameter parameter = parser.parseNormalFormalParameter();
10100 expectNotNullIfNoErrors(parameter);
10101 listener.assertNoErrors();
10102 expect(parameter, new isInstanceOf<FieldFormalParameter>());
10103 FieldFormalParameter fieldParameter = parameter;
10104 expect(fieldParameter.keyword, isNull);
10105 expect(fieldParameter.type, isNull);
10106 expect(fieldParameter.identifier, isNotNull);
10107 FormalParameterList parameterList = fieldParameter.parameters;
10108 expect(parameterList, isNotNull);
10109 expect(parameterList.parameters, hasLength(0));
10110 }
10111
10112 void test_parseNormalFormalParameter_field_noType() {
10113 createParser('this.a)');
10114 NormalFormalParameter parameter = parser.parseNormalFormalParameter();
10115 expectNotNullIfNoErrors(parameter);
10116 listener.assertNoErrors();
10117 expect(parameter, new isInstanceOf<FieldFormalParameter>());
10118 FieldFormalParameter fieldParameter = parameter;
10119 expect(fieldParameter.keyword, isNull);
10120 expect(fieldParameter.type, isNull);
10121 expect(fieldParameter.identifier, isNotNull);
10122 expect(fieldParameter.parameters, isNull);
10123 }
10124
10125 void test_parseNormalFormalParameter_field_type() {
10126 createParser('A this.a)');
10127 NormalFormalParameter parameter = parser.parseNormalFormalParameter();
10128 expectNotNullIfNoErrors(parameter);
10129 listener.assertNoErrors();
10130 expect(parameter, new isInstanceOf<FieldFormalParameter>());
10131 FieldFormalParameter fieldParameter = parameter;
10132 expect(fieldParameter.keyword, isNull);
10133 expect(fieldParameter.type, isNotNull);
10134 expect(fieldParameter.identifier, isNotNull);
10135 expect(fieldParameter.parameters, isNull);
10136 }
10137
10138 void test_parseNormalFormalParameter_field_var() {
10139 createParser('var this.a)');
10140 NormalFormalParameter parameter = parser.parseNormalFormalParameter();
10141 expectNotNullIfNoErrors(parameter);
10142 listener.assertNoErrors();
10143 expect(parameter, new isInstanceOf<FieldFormalParameter>());
10144 FieldFormalParameter fieldParameter = parameter;
10145 expect(fieldParameter.keyword, isNotNull);
10146 expect(fieldParameter.type, isNull);
10147 expect(fieldParameter.identifier, isNotNull);
10148 expect(fieldParameter.parameters, isNull);
10149 }
10150
10151 void test_parseNormalFormalParameter_function_noType() {
10152 createParser('a())');
10153 NormalFormalParameter parameter = parser.parseNormalFormalParameter();
10154 expectNotNullIfNoErrors(parameter);
10155 listener.assertNoErrors();
10156 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
10157 FunctionTypedFormalParameter functionParameter = parameter;
10158 expect(functionParameter.returnType, isNull);
10159 expect(functionParameter.identifier, isNotNull);
10160 expect(functionParameter.typeParameters, isNull);
10161 expect(functionParameter.parameters, isNotNull);
10162 }
10163
10164 void test_parseNormalFormalParameter_function_noType_nullable() {
10165 enableNnbd = true;
10166 createParser('a()?)');
10167 NormalFormalParameter parameter = parser.parseNormalFormalParameter();
10168 expectNotNullIfNoErrors(parameter);
10169 listener.assertNoErrors();
10170 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
10171 FunctionTypedFormalParameter functionParameter = parameter;
10172 expect(functionParameter.returnType, isNull);
10173 expect(functionParameter.identifier, isNotNull);
10174 expect(functionParameter.typeParameters, isNull);
10175 expect(functionParameter.parameters, isNotNull);
10176 expect(functionParameter.question, isNotNull);
10177 }
10178
10179 void test_parseNormalFormalParameter_function_noType_typeParameterComments() {
10180 enableGenericMethodComments = true;
10181 createParser('a/*<E>*/())');
10182 NormalFormalParameter parameter = parser.parseNormalFormalParameter();
10183 expectNotNullIfNoErrors(parameter);
10184 listener.assertNoErrors();
10185 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
10186 FunctionTypedFormalParameter functionParameter = parameter;
10187 expect(functionParameter.returnType, isNull);
10188 expect(functionParameter.identifier, isNotNull);
10189 expect(functionParameter.typeParameters, isNotNull);
10190 expect(functionParameter.parameters, isNotNull);
10191 }
10192
10193 void test_parseNormalFormalParameter_function_noType_typeParameters() {
10194 createParser('a<E>())');
10195 NormalFormalParameter parameter = parser.parseNormalFormalParameter();
10196 expectNotNullIfNoErrors(parameter);
10197 listener.assertNoErrors();
10198 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
10199 FunctionTypedFormalParameter functionParameter = parameter;
10200 expect(functionParameter.returnType, isNull);
10201 expect(functionParameter.identifier, isNotNull);
10202 expect(functionParameter.typeParameters, isNotNull);
10203 expect(functionParameter.parameters, isNotNull);
10204 expect(functionParameter.question, isNull);
10205 expect(functionParameter.question, isNull);
10206 }
10207
10208 void
10209 test_parseNormalFormalParameter_function_noType_typeParameters_nullable() {
10210 enableNnbd = true;
10211 createParser('a<E>()?)');
10212 NormalFormalParameter parameter = parser.parseNormalFormalParameter();
10213 expectNotNullIfNoErrors(parameter);
10214 listener.assertNoErrors();
10215 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
10216 FunctionTypedFormalParameter functionParameter = parameter;
10217 expect(functionParameter.returnType, isNull);
10218 expect(functionParameter.identifier, isNotNull);
10219 expect(functionParameter.typeParameters, isNotNull);
10220 expect(functionParameter.parameters, isNotNull);
10221 expect(functionParameter.question, isNotNull);
10222 }
10223
10224 void test_parseNormalFormalParameter_function_type() {
10225 createParser('A a())');
10226 NormalFormalParameter parameter = parser.parseNormalFormalParameter();
10227 expectNotNullIfNoErrors(parameter);
10228 listener.assertNoErrors();
10229 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
10230 FunctionTypedFormalParameter functionParameter = parameter;
10231 expect(functionParameter.returnType, isNotNull);
10232 expect(functionParameter.identifier, isNotNull);
10233 expect(functionParameter.typeParameters, isNull);
10234 expect(functionParameter.parameters, isNotNull);
10235 expect(functionParameter.question, isNull);
10236 }
10237
10238 void test_parseNormalFormalParameter_function_type_nullable() {
10239 enableNnbd = true;
10240 createParser('A a()?)');
10241 NormalFormalParameter parameter = parser.parseNormalFormalParameter();
10242 expectNotNullIfNoErrors(parameter);
10243 listener.assertNoErrors();
10244 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
10245 FunctionTypedFormalParameter functionParameter = parameter;
10246 expect(functionParameter.returnType, isNotNull);
10247 expect(functionParameter.identifier, isNotNull);
10248 expect(functionParameter.typeParameters, isNull);
10249 expect(functionParameter.parameters, isNotNull);
10250 expect(functionParameter.question, isNotNull);
10251 }
10252
10253 void test_parseNormalFormalParameter_function_type_typeParameterComments() {
10254 enableGenericMethodComments = true;
10255 createParser('A a/*<E>*/())');
10256 NormalFormalParameter parameter = parser.parseNormalFormalParameter();
10257 expectNotNullIfNoErrors(parameter);
10258 listener.assertNoErrors();
10259 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
10260 FunctionTypedFormalParameter functionParameter = parameter;
10261 expect(functionParameter.returnType, isNotNull);
10262 expect(functionParameter.identifier, isNotNull);
10263 expect(functionParameter.typeParameters, isNotNull);
10264 expect(functionParameter.parameters, isNotNull);
10265 expect(functionParameter.question, isNull);
10266 }
10267
10268 void test_parseNormalFormalParameter_function_type_typeParameters() {
10269 createParser('A a<E>())');
10270 NormalFormalParameter parameter = parser.parseNormalFormalParameter();
10271 expectNotNullIfNoErrors(parameter);
10272 listener.assertNoErrors();
10273 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
10274 FunctionTypedFormalParameter functionParameter = parameter;
10275 expect(functionParameter.returnType, isNotNull);
10276 expect(functionParameter.identifier, isNotNull);
10277 expect(functionParameter.typeParameters, isNotNull);
10278 expect(functionParameter.parameters, isNotNull);
10279 expect(functionParameter.question, isNull);
10280 }
10281
10282 void test_parseNormalFormalParameter_function_type_typeParameters_nullable() {
10283 enableNnbd = true;
10284 createParser('A a<E>()?)');
10285 NormalFormalParameter parameter = parser.parseNormalFormalParameter();
10286 expectNotNullIfNoErrors(parameter);
10287 listener.assertNoErrors();
10288 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
10289 FunctionTypedFormalParameter functionParameter = parameter;
10290 expect(functionParameter.returnType, isNotNull);
10291 expect(functionParameter.identifier, isNotNull);
10292 expect(functionParameter.typeParameters, isNotNull);
10293 expect(functionParameter.parameters, isNotNull);
10294 expect(functionParameter.question, isNotNull);
10295 }
10296
10297 void test_parseNormalFormalParameter_function_void() {
10298 createParser('void a())');
10299 NormalFormalParameter parameter = parser.parseNormalFormalParameter();
10300 expectNotNullIfNoErrors(parameter);
10301 listener.assertNoErrors();
10302 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
10303 FunctionTypedFormalParameter functionParameter = parameter;
10304 expect(functionParameter.returnType, isNotNull);
10305 expect(functionParameter.identifier, isNotNull);
10306 expect(functionParameter.typeParameters, isNull);
10307 expect(functionParameter.parameters, isNotNull);
10308 expect(functionParameter.question, isNull);
10309 }
10310
10311 void test_parseNormalFormalParameter_function_void_nullable() {
10312 enableNnbd = true;
10313 createParser('void a()?)');
10314 NormalFormalParameter parameter = parser.parseNormalFormalParameter();
10315 expectNotNullIfNoErrors(parameter);
10316 listener.assertNoErrors();
10317 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
10318 FunctionTypedFormalParameter functionParameter = parameter;
10319 expect(functionParameter.returnType, isNotNull);
10320 expect(functionParameter.identifier, isNotNull);
10321 expect(functionParameter.typeParameters, isNull);
10322 expect(functionParameter.parameters, isNotNull);
10323 expect(functionParameter.question, isNotNull);
10324 }
10325
10326 void test_parseNormalFormalParameter_function_void_typeParameterComments() {
10327 enableGenericMethodComments = true;
10328 createParser('void a/*<E>*/())');
10329 NormalFormalParameter parameter = parser.parseNormalFormalParameter();
10330 expectNotNullIfNoErrors(parameter);
10331 listener.assertNoErrors();
10332 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
10333 FunctionTypedFormalParameter functionParameter = parameter;
10334 expect(functionParameter.returnType, isNotNull);
10335 expect(functionParameter.identifier, isNotNull);
10336 expect(functionParameter.typeParameters, isNotNull);
10337 expect(functionParameter.parameters, isNotNull);
10338 expect(functionParameter.question, isNull);
10339 }
10340
10341 void test_parseNormalFormalParameter_function_void_typeParameters() {
10342 createParser('void a<E>())');
10343 NormalFormalParameter parameter = parser.parseNormalFormalParameter();
10344 expectNotNullIfNoErrors(parameter);
10345 listener.assertNoErrors();
10346 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
10347 FunctionTypedFormalParameter functionParameter = parameter;
10348 expect(functionParameter.returnType, isNotNull);
10349 expect(functionParameter.identifier, isNotNull);
10350 expect(functionParameter.typeParameters, isNotNull);
10351 expect(functionParameter.parameters, isNotNull);
10352 expect(functionParameter.question, isNull);
10353 }
10354
10355 void test_parseNormalFormalParameter_function_void_typeParameters_nullable() {
10356 enableNnbd = true;
10357 createParser('void a<E>()?)');
10358 NormalFormalParameter parameter = parser.parseNormalFormalParameter();
10359 expectNotNullIfNoErrors(parameter);
10360 listener.assertNoErrors();
10361 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
10362 FunctionTypedFormalParameter functionParameter = parameter;
10363 expect(functionParameter.returnType, isNotNull);
10364 expect(functionParameter.identifier, isNotNull);
10365 expect(functionParameter.typeParameters, isNotNull);
10366 expect(functionParameter.parameters, isNotNull);
10367 expect(functionParameter.question, isNotNull);
10368 }
10369
10370 void test_parseNormalFormalParameter_simple_const_noType() {
10371 createParser('const a)');
10372 NormalFormalParameter parameter = parser.parseNormalFormalParameter();
10373 expectNotNullIfNoErrors(parameter);
10374 listener.assertNoErrors();
10375 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
10376 SimpleFormalParameter simpleParameter = parameter;
10377 expect(simpleParameter.keyword, isNotNull);
10378 expect(simpleParameter.type, isNull);
10379 expect(simpleParameter.identifier, isNotNull);
10380 }
10381
10382 void test_parseNormalFormalParameter_simple_const_type() {
10383 createParser('const A a)');
10384 NormalFormalParameter parameter = parser.parseNormalFormalParameter();
10385 expectNotNullIfNoErrors(parameter);
10386 listener.assertNoErrors();
10387 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
10388 SimpleFormalParameter simpleParameter = parameter;
10389 expect(simpleParameter.keyword, isNotNull);
10390 expect(simpleParameter.type, isNotNull);
10391 expect(simpleParameter.identifier, isNotNull);
10392 }
10393
10394 void test_parseNormalFormalParameter_simple_final_noType() {
10395 createParser('final a)');
10396 NormalFormalParameter parameter = parser.parseNormalFormalParameter();
10397 expectNotNullIfNoErrors(parameter);
10398 listener.assertNoErrors();
10399 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
10400 SimpleFormalParameter simpleParameter = parameter;
10401 expect(simpleParameter.keyword, isNotNull);
10402 expect(simpleParameter.type, isNull);
10403 expect(simpleParameter.identifier, isNotNull);
10404 }
10405
10406 void test_parseNormalFormalParameter_simple_final_type() {
10407 createParser('final A a)');
10408 NormalFormalParameter parameter = parser.parseNormalFormalParameter();
10409 expectNotNullIfNoErrors(parameter);
10410 listener.assertNoErrors();
10411 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
10412 SimpleFormalParameter simpleParameter = parameter;
10413 expect(simpleParameter.keyword, isNotNull);
10414 expect(simpleParameter.type, isNotNull);
10415 expect(simpleParameter.identifier, isNotNull);
10416 }
10417
10418 void test_parseNormalFormalParameter_simple_noName() {
10419 createParser('a)');
10420 NormalFormalParameter parameter =
10421 parser.parseNormalFormalParameter(inFunctionType: true);
10422 expectNotNullIfNoErrors(parameter);
10423 listener.assertNoErrors();
10424 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
10425 SimpleFormalParameter simpleParameter = parameter;
10426 expect(simpleParameter.keyword, isNull);
10427 expect(simpleParameter.type, isNotNull);
10428 expect(simpleParameter.identifier, isNull);
10429 }
10430
10431 void test_parseNormalFormalParameter_simple_noType() {
10432 createParser('a)');
10433 NormalFormalParameter parameter = parser.parseNormalFormalParameter();
10434 expectNotNullIfNoErrors(parameter);
10435 listener.assertNoErrors();
10436 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
10437 SimpleFormalParameter simpleParameter = parameter;
10438 expect(simpleParameter.keyword, isNull);
10439 expect(simpleParameter.type, isNull);
10440 expect(simpleParameter.identifier, isNotNull);
10441 }
10442
10443 void test_parseNormalFormalParameter_simple_noType_namedCovariant() {
10444 createParser('covariant)');
10445 NormalFormalParameter parameter = parser.parseNormalFormalParameter();
10446 expectNotNullIfNoErrors(parameter);
10447 listener.assertNoErrors();
10448 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
10449 SimpleFormalParameter simpleParameter = parameter;
10450 expect(simpleParameter.covariantKeyword, isNull);
10451 expect(simpleParameter.keyword, isNull);
10452 expect(simpleParameter.type, isNull);
10453 expect(simpleParameter.identifier, isNotNull);
10454 }
10455
10456 void test_parseNormalFormalParameter_simple_type() {
10457 createParser('A a)');
10458 NormalFormalParameter parameter = parser.parseNormalFormalParameter();
10459 expectNotNullIfNoErrors(parameter);
10460 listener.assertNoErrors();
10461 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
10462 SimpleFormalParameter simpleParameter = parameter;
10463 expect(simpleParameter.keyword, isNull);
10464 expect(simpleParameter.type, isNotNull);
10465 expect(simpleParameter.identifier, isNotNull);
10466 }
10467
10468 void test_parseOperator() { 10479 void test_parseOperator() {
10469 createParser('/// Doc\nT operator +(A a);'); 10480 createParser('/// Doc\nT operator +(A a);');
10470 MethodDeclaration method = parser.parseClassMember('C'); 10481 MethodDeclaration method = parser.parseClassMember('C');
10471 expectNotNullIfNoErrors(method); 10482 expectNotNullIfNoErrors(method);
10472 listener.assertNoErrors(); 10483 listener.assertNoErrors();
10473 expect(method.body, isNotNull); 10484 expect(method.body, isNotNull);
10474 expectCommentText(method.documentationComment, '/// Doc'); 10485 expectCommentText(method.documentationComment, '/// Doc');
10475 expect(method.externalKeyword, isNull); 10486 expect(method.externalKeyword, isNull);
10476 expect(method.modifierKeyword, isNull); 10487 expect(method.modifierKeyword, isNull);
10477 expect(method.name, isNotNull); 10488 expect(method.name, isNotNull);
(...skipping 4084 matching lines...) Expand 10 before | Expand all | Expand 10 after
14562 expect(typeAlias.name, isNotNull); 14573 expect(typeAlias.name, isNotNull);
14563 expect(typeAlias.typeParameters, isNull); 14574 expect(typeAlias.typeParameters, isNull);
14564 expect(typeAlias.semicolon, isNotNull); 14575 expect(typeAlias.semicolon, isNotNull);
14565 GenericFunctionType functionType = typeAlias.functionType; 14576 GenericFunctionType functionType = typeAlias.functionType;
14566 expect(functionType, isNotNull); 14577 expect(functionType, isNotNull);
14567 expect(functionType.parameters, isNotNull); 14578 expect(functionType.parameters, isNotNull);
14568 expect(functionType.returnType, isNotNull); 14579 expect(functionType.returnType, isNotNull);
14569 expect(functionType.typeParameters, isNull); 14580 expect(functionType.typeParameters, isNull);
14570 } 14581 }
14571 } 14582 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/parser_fasta_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698