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

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

Issue 2975253002: Format analyzer, analysis_server, analyzer_plugin, front_end and kernel with the latest dartfmt. (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'package:analyzer/dart/ast/ast.dart'; 5 import 'package:analyzer/dart/ast/ast.dart';
6 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; 6 import 'package:analyzer/dart/ast/standard_ast_factory.dart';
7 import 'package:analyzer/dart/ast/token.dart'; 7 import 'package:analyzer/dart/ast/token.dart';
8 import 'package:analyzer/dart/ast/visitor.dart'; 8 import 'package:analyzer/dart/ast/visitor.dart';
9 import 'package:analyzer/error/error.dart'; 9 import 'package:analyzer/error/error.dart';
10 import 'package:analyzer/error/listener.dart'; 10 import 'package:analyzer/error/listener.dart';
(...skipping 2423 matching lines...) Expand 10 before | Expand all | Expand 10 after
2434 } 2434 }
2435 2435
2436 void test_emptyEnumBody() { 2436 void test_emptyEnumBody() {
2437 createParser('enum E {}'); 2437 createParser('enum E {}');
2438 EnumDeclaration declaration = parseFullCompilationUnitMember(); 2438 EnumDeclaration declaration = parseFullCompilationUnitMember();
2439 expectNotNullIfNoErrors(declaration); 2439 expectNotNullIfNoErrors(declaration);
2440 listener.assertErrorsWithCodes([ParserErrorCode.EMPTY_ENUM_BODY]); 2440 listener.assertErrorsWithCodes([ParserErrorCode.EMPTY_ENUM_BODY]);
2441 } 2441 }
2442 2442
2443 void test_enumInClass() { 2443 void test_enumInClass() {
2444 parseCompilationUnit( 2444 parseCompilationUnit(r'''
2445 r'''
2446 class Foo { 2445 class Foo {
2447 enum Bar { 2446 enum Bar {
2448 Bar1, Bar2, Bar3 2447 Bar1, Bar2, Bar3
2449 } 2448 }
2450 } 2449 }
2451 ''', 2450 ''', [ParserErrorCode.ENUM_IN_CLASS]);
2452 [ParserErrorCode.ENUM_IN_CLASS]);
2453 } 2451 }
2454 2452
2455 void test_equalityCannotBeEqualityOperand_eq_eq() { 2453 void test_equalityCannotBeEqualityOperand_eq_eq() {
2456 parseExpression( 2454 parseExpression(
2457 "1 == 2 == 3", [ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND]); 2455 "1 == 2 == 3", [ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND]);
2458 } 2456 }
2459 2457
2460 void test_equalityCannotBeEqualityOperand_eq_neq() { 2458 void test_equalityCannotBeEqualityOperand_eq_neq() {
2461 parseExpression( 2459 parseExpression(
2462 "1 == 2 != 3", [ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND]); 2460 "1 == 2 != 3", [ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND]);
(...skipping 1627 matching lines...) Expand 10 before | Expand all | Expand 10 after
4090 void test_topLevelVariable_withMetadata() { 4088 void test_topLevelVariable_withMetadata() {
4091 parseCompilationUnit("String @A string;", [ 4089 parseCompilationUnit("String @A string;", [
4092 ParserErrorCode.MISSING_IDENTIFIER, 4090 ParserErrorCode.MISSING_IDENTIFIER,
4093 ParserErrorCode.EXPECTED_TOKEN, 4091 ParserErrorCode.EXPECTED_TOKEN,
4094 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE 4092 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE
4095 ]); 4093 ]);
4096 } 4094 }
4097 4095
4098 void test_typedef_incomplete() { 4096 void test_typedef_incomplete() {
4099 // TODO(brianwilkerson) Improve recovery for this case. 4097 // TODO(brianwilkerson) Improve recovery for this case.
4100 parseCompilationUnit( 4098 parseCompilationUnit('''
4101 '''
4102 class A {} 4099 class A {}
4103 class B extends A {} 4100 class B extends A {}
4104 4101
4105 typedef T 4102 typedef T
4106 4103
4107 main() { 4104 main() {
4108 Function< 4105 Function<
4109 } 4106 }
4110 ''', 4107 ''', [
4111 [ 4108 ParserErrorCode.EXPECTED_TOKEN,
4112 ParserErrorCode.EXPECTED_TOKEN, 4109 ParserErrorCode.UNEXPECTED_TOKEN,
4113 ParserErrorCode.UNEXPECTED_TOKEN, 4110 ParserErrorCode.EXPECTED_EXECUTABLE
4114 ParserErrorCode.EXPECTED_EXECUTABLE 4111 ]);
4115 ]);
4116 } 4112 }
4117 4113
4118 void test_typedef_namedFunction() { 4114 void test_typedef_namedFunction() {
4119 // TODO(brianwilkerson) Improve recovery for this case. 4115 // TODO(brianwilkerson) Improve recovery for this case.
4120 parseCompilationUnit('typedef void Function();', [ 4116 parseCompilationUnit('typedef void Function();', [
4121 ParserErrorCode.UNEXPECTED_TOKEN, 4117 ParserErrorCode.UNEXPECTED_TOKEN,
4122 ParserErrorCode.MISSING_IDENTIFIER, 4118 ParserErrorCode.MISSING_IDENTIFIER,
4123 ParserErrorCode.EXPECTED_EXECUTABLE, 4119 ParserErrorCode.EXPECTED_EXECUTABLE,
4124 ParserErrorCode.MISSING_TYPEDEF_PARAMETERS 4120 ParserErrorCode.MISSING_TYPEDEF_PARAMETERS
4125 ]); 4121 ]);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
4178 } 4174 }
4179 4175
4180 void test_unexpectedToken_semicolonBetweenCompilationUnitMembers() { 4176 void test_unexpectedToken_semicolonBetweenCompilationUnitMembers() {
4181 parseCompilationUnit("int x; ; int y;", [ParserErrorCode.UNEXPECTED_TOKEN]); 4177 parseCompilationUnit("int x; ; int y;", [ParserErrorCode.UNEXPECTED_TOKEN]);
4182 } 4178 }
4183 4179
4184 void test_unterminatedString_at_eof() { 4180 void test_unterminatedString_at_eof() {
4185 // Although the "unterminated string" error message is produced by the 4181 // Although the "unterminated string" error message is produced by the
4186 // scanner, we need to verify that the parser can handle the tokens 4182 // scanner, we need to verify that the parser can handle the tokens
4187 // produced by the scanner when an unterminated string is encountered. 4183 // produced by the scanner when an unterminated string is encountered.
4188 parseCompilationUnit( 4184 parseCompilationUnit(r'''
4189 r'''
4190 void main() { 4185 void main() {
4191 var x = "''', 4186 var x = "''', [
4192 [ 4187 ScannerErrorCode.UNTERMINATED_STRING_LITERAL,
4193 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 4188 fe.Scanner.useFasta
4194 fe.Scanner.useFasta 4189 ? ScannerErrorCode.EXPECTED_TOKEN
4195 ? ScannerErrorCode.EXPECTED_TOKEN 4190 : ParserErrorCode.EXPECTED_TOKEN,
4196 : ParserErrorCode.EXPECTED_TOKEN, 4191 ParserErrorCode.EXPECTED_TOKEN
4197 ParserErrorCode.EXPECTED_TOKEN 4192 ]);
4198 ]);
4199 } 4193 }
4200 4194
4201 void test_unterminatedString_at_eol() { 4195 void test_unterminatedString_at_eol() {
4202 // Although the "unterminated string" error message is produced by the 4196 // Although the "unterminated string" error message is produced by the
4203 // scanner, we need to verify that the parser can handle the tokens 4197 // scanner, we need to verify that the parser can handle the tokens
4204 // produced by the scanner when an unterminated string is encountered. 4198 // produced by the scanner when an unterminated string is encountered.
4205 parseCompilationUnit( 4199 parseCompilationUnit(r'''
4206 r'''
4207 void main() { 4200 void main() {
4208 var x = " 4201 var x = "
4209 ; 4202 ;
4210 } 4203 }
4211 ''', 4204 ''', [ScannerErrorCode.UNTERMINATED_STRING_LITERAL]);
4212 [ScannerErrorCode.UNTERMINATED_STRING_LITERAL]);
4213 } 4205 }
4214 4206
4215 void test_unterminatedString_multiline_at_eof_3_quotes() { 4207 void test_unterminatedString_multiline_at_eof_3_quotes() {
4216 // Although the "unterminated string" error message is produced by the 4208 // Although the "unterminated string" error message is produced by the
4217 // scanner, we need to verify that the parser can handle the tokens 4209 // scanner, we need to verify that the parser can handle the tokens
4218 // produced by the scanner when an unterminated string is encountered. 4210 // produced by the scanner when an unterminated string is encountered.
4219 parseCompilationUnit( 4211 parseCompilationUnit(r'''
4220 r'''
4221 void main() { 4212 void main() {
4222 var x = """''', 4213 var x = """''', [
4223 [ 4214 ScannerErrorCode.UNTERMINATED_STRING_LITERAL,
4224 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 4215 fe.Scanner.useFasta
4225 fe.Scanner.useFasta 4216 ? ScannerErrorCode.EXPECTED_TOKEN
4226 ? ScannerErrorCode.EXPECTED_TOKEN 4217 : ParserErrorCode.EXPECTED_TOKEN,
4227 : ParserErrorCode.EXPECTED_TOKEN, 4218 ParserErrorCode.EXPECTED_TOKEN
4228 ParserErrorCode.EXPECTED_TOKEN 4219 ]);
4229 ]);
4230 } 4220 }
4231 4221
4232 void test_unterminatedString_multiline_at_eof_4_quotes() { 4222 void test_unterminatedString_multiline_at_eof_4_quotes() {
4233 // Although the "unterminated string" error message is produced by the 4223 // Although the "unterminated string" error message is produced by the
4234 // scanner, we need to verify that the parser can handle the tokens 4224 // scanner, we need to verify that the parser can handle the tokens
4235 // produced by the scanner when an unterminated string is encountered. 4225 // produced by the scanner when an unterminated string is encountered.
4236 parseCompilationUnit( 4226 parseCompilationUnit(r'''
4237 r'''
4238 void main() { 4227 void main() {
4239 var x = """"''', 4228 var x = """"''', [
4240 [ 4229 ScannerErrorCode.UNTERMINATED_STRING_LITERAL,
4241 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 4230 fe.Scanner.useFasta
4242 fe.Scanner.useFasta 4231 ? ScannerErrorCode.EXPECTED_TOKEN
4243 ? ScannerErrorCode.EXPECTED_TOKEN 4232 : ParserErrorCode.EXPECTED_TOKEN,
4244 : ParserErrorCode.EXPECTED_TOKEN, 4233 ParserErrorCode.EXPECTED_TOKEN
4245 ParserErrorCode.EXPECTED_TOKEN 4234 ]);
4246 ]);
4247 } 4235 }
4248 4236
4249 void test_unterminatedString_multiline_at_eof_5_quotes() { 4237 void test_unterminatedString_multiline_at_eof_5_quotes() {
4250 // Although the "unterminated string" error message is produced by the 4238 // Although the "unterminated string" error message is produced by the
4251 // scanner, we need to verify that the parser can handle the tokens 4239 // scanner, we need to verify that the parser can handle the tokens
4252 // produced by the scanner when an unterminated string is encountered. 4240 // produced by the scanner when an unterminated string is encountered.
4253 parseCompilationUnit( 4241 parseCompilationUnit(r'''
4254 r'''
4255 void main() { 4242 void main() {
4256 var x = """""''', 4243 var x = """""''', [
4257 [ 4244 ScannerErrorCode.UNTERMINATED_STRING_LITERAL,
4258 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 4245 fe.Scanner.useFasta
4259 fe.Scanner.useFasta 4246 ? ScannerErrorCode.EXPECTED_TOKEN
4260 ? ScannerErrorCode.EXPECTED_TOKEN 4247 : ParserErrorCode.EXPECTED_TOKEN,
4261 : ParserErrorCode.EXPECTED_TOKEN, 4248 ParserErrorCode.EXPECTED_TOKEN
4262 ParserErrorCode.EXPECTED_TOKEN 4249 ]);
4263 ]);
4264 } 4250 }
4265 4251
4266 void test_useOfUnaryPlusOperator() { 4252 void test_useOfUnaryPlusOperator() {
4267 createParser('+x'); 4253 createParser('+x');
4268 Expression expression = parser.parseUnaryExpression(); 4254 Expression expression = parser.parseUnaryExpression();
4269 expectNotNullIfNoErrors(expression); 4255 expectNotNullIfNoErrors(expression);
4270 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); 4256 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]);
4271 var identifier = expression as SimpleIdentifier; 4257 var identifier = expression as SimpleIdentifier;
4272 expect(identifier.isSynthetic, isTrue); 4258 expect(identifier.isSynthetic, isTrue);
4273 } 4259 }
(...skipping 4663 matching lines...) Expand 10 before | Expand all | Expand 10 after
8937 void test_bitwiseXorExpression_super() { 8923 void test_bitwiseXorExpression_super() {
8938 BinaryExpression expression = parseExpression("super ^ ^", [ 8924 BinaryExpression expression = parseExpression("super ^ ^", [
8939 ParserErrorCode.MISSING_IDENTIFIER, 8925 ParserErrorCode.MISSING_IDENTIFIER,
8940 ParserErrorCode.MISSING_IDENTIFIER 8926 ParserErrorCode.MISSING_IDENTIFIER
8941 ]); 8927 ]);
8942 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, 8928 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
8943 BinaryExpression, expression.leftOperand); 8929 BinaryExpression, expression.leftOperand);
8944 } 8930 }
8945 8931
8946 void test_classTypeAlias_withBody() { 8932 void test_classTypeAlias_withBody() {
8947 parseCompilationUnit( 8933 parseCompilationUnit(r'''
8948 r'''
8949 class A {} 8934 class A {}
8950 class B = Object with A {}''', 8935 class B = Object with A {}''', [ParserErrorCode.EXPECTED_TOKEN]);
8951 [ParserErrorCode.EXPECTED_TOKEN]);
8952 } 8936 }
8953 8937
8954 void test_conditionalExpression_missingElse() { 8938 void test_conditionalExpression_missingElse() {
8955 createParser('x ? y :'); 8939 createParser('x ? y :');
8956 Expression expression = parser.parseConditionalExpression(); 8940 Expression expression = parser.parseConditionalExpression();
8957 expectNotNullIfNoErrors(expression); 8941 expectNotNullIfNoErrors(expression);
8958 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); 8942 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]);
8959 expect(expression, new isInstanceOf<ConditionalExpression>()); 8943 expect(expression, new isInstanceOf<ConditionalExpression>());
8960 ConditionalExpression conditionalExpression = expression; 8944 ConditionalExpression conditionalExpression = expression;
8961 expect(conditionalExpression.elseExpression, 8945 expect(conditionalExpression.elseExpression,
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
9245 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableDeclaration, 9229 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableDeclaration,
9246 TopLevelVariableDeclaration, member); 9230 TopLevelVariableDeclaration, member);
9247 NodeList<VariableDeclaration> variables = 9231 NodeList<VariableDeclaration> variables =
9248 (member as TopLevelVariableDeclaration).variables.variables; 9232 (member as TopLevelVariableDeclaration).variables.variables;
9249 expect(variables, hasLength(1)); 9233 expect(variables, hasLength(1));
9250 SimpleIdentifier name = variables[0].name; 9234 SimpleIdentifier name = variables[0].name;
9251 expect(name.isSynthetic, isTrue); 9235 expect(name.isSynthetic, isTrue);
9252 } 9236 }
9253 9237
9254 void test_incompleteField_const() { 9238 void test_incompleteField_const() {
9255 CompilationUnit unit = parseCompilationUnit( 9239 CompilationUnit unit = parseCompilationUnit(r'''
9256 r'''
9257 class C { 9240 class C {
9258 const 9241 const
9259 }''', 9242 }''', [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]);
9260 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]);
9261 NodeList<CompilationUnitMember> declarations = unit.declarations; 9243 NodeList<CompilationUnitMember> declarations = unit.declarations;
9262 expect(declarations, hasLength(1)); 9244 expect(declarations, hasLength(1));
9263 CompilationUnitMember unitMember = declarations[0]; 9245 CompilationUnitMember unitMember = declarations[0];
9264 EngineTestCase.assertInstanceOf( 9246 EngineTestCase.assertInstanceOf(
9265 (obj) => obj is ClassDeclaration, ClassDeclaration, unitMember); 9247 (obj) => obj is ClassDeclaration, ClassDeclaration, unitMember);
9266 NodeList<ClassMember> members = (unitMember as ClassDeclaration).members; 9248 NodeList<ClassMember> members = (unitMember as ClassDeclaration).members;
9267 expect(members, hasLength(1)); 9249 expect(members, hasLength(1));
9268 ClassMember classMember = members[0]; 9250 ClassMember classMember = members[0];
9269 EngineTestCase.assertInstanceOf( 9251 EngineTestCase.assertInstanceOf(
9270 (obj) => obj is FieldDeclaration, FieldDeclaration, classMember); 9252 (obj) => obj is FieldDeclaration, FieldDeclaration, classMember);
9271 VariableDeclarationList fieldList = 9253 VariableDeclarationList fieldList =
9272 (classMember as FieldDeclaration).fields; 9254 (classMember as FieldDeclaration).fields;
9273 expect(fieldList.keyword.keyword, Keyword.CONST); 9255 expect(fieldList.keyword.keyword, Keyword.CONST);
9274 NodeList<VariableDeclaration> fields = fieldList.variables; 9256 NodeList<VariableDeclaration> fields = fieldList.variables;
9275 expect(fields, hasLength(1)); 9257 expect(fields, hasLength(1));
9276 VariableDeclaration field = fields[0]; 9258 VariableDeclaration field = fields[0];
9277 expect(field.name.isSynthetic, isTrue); 9259 expect(field.name.isSynthetic, isTrue);
9278 } 9260 }
9279 9261
9280 void test_incompleteField_final() { 9262 void test_incompleteField_final() {
9281 CompilationUnit unit = parseCompilationUnit( 9263 CompilationUnit unit = parseCompilationUnit(r'''
9282 r'''
9283 class C { 9264 class C {
9284 final 9265 final
9285 }''', 9266 }''', [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]);
9286 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]);
9287 NodeList<CompilationUnitMember> declarations = unit.declarations; 9267 NodeList<CompilationUnitMember> declarations = unit.declarations;
9288 expect(declarations, hasLength(1)); 9268 expect(declarations, hasLength(1));
9289 CompilationUnitMember unitMember = declarations[0]; 9269 CompilationUnitMember unitMember = declarations[0];
9290 EngineTestCase.assertInstanceOf( 9270 EngineTestCase.assertInstanceOf(
9291 (obj) => obj is ClassDeclaration, ClassDeclaration, unitMember); 9271 (obj) => obj is ClassDeclaration, ClassDeclaration, unitMember);
9292 NodeList<ClassMember> members = (unitMember as ClassDeclaration).members; 9272 NodeList<ClassMember> members = (unitMember as ClassDeclaration).members;
9293 expect(members, hasLength(1)); 9273 expect(members, hasLength(1));
9294 ClassMember classMember = members[0]; 9274 ClassMember classMember = members[0];
9295 EngineTestCase.assertInstanceOf( 9275 EngineTestCase.assertInstanceOf(
9296 (obj) => obj is FieldDeclaration, FieldDeclaration, classMember); 9276 (obj) => obj is FieldDeclaration, FieldDeclaration, classMember);
9297 VariableDeclarationList fieldList = 9277 VariableDeclarationList fieldList =
9298 (classMember as FieldDeclaration).fields; 9278 (classMember as FieldDeclaration).fields;
9299 expect(fieldList.keyword.keyword, Keyword.FINAL); 9279 expect(fieldList.keyword.keyword, Keyword.FINAL);
9300 NodeList<VariableDeclaration> fields = fieldList.variables; 9280 NodeList<VariableDeclaration> fields = fieldList.variables;
9301 expect(fields, hasLength(1)); 9281 expect(fields, hasLength(1));
9302 VariableDeclaration field = fields[0]; 9282 VariableDeclaration field = fields[0];
9303 expect(field.name.isSynthetic, isTrue); 9283 expect(field.name.isSynthetic, isTrue);
9304 } 9284 }
9305 9285
9306 void test_incompleteField_var() { 9286 void test_incompleteField_var() {
9307 CompilationUnit unit = parseCompilationUnit( 9287 CompilationUnit unit = parseCompilationUnit(r'''
9308 r'''
9309 class C { 9288 class C {
9310 var 9289 var
9311 }''', 9290 }''', [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]);
9312 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]);
9313 NodeList<CompilationUnitMember> declarations = unit.declarations; 9291 NodeList<CompilationUnitMember> declarations = unit.declarations;
9314 expect(declarations, hasLength(1)); 9292 expect(declarations, hasLength(1));
9315 CompilationUnitMember unitMember = declarations[0]; 9293 CompilationUnitMember unitMember = declarations[0];
9316 EngineTestCase.assertInstanceOf( 9294 EngineTestCase.assertInstanceOf(
9317 (obj) => obj is ClassDeclaration, ClassDeclaration, unitMember); 9295 (obj) => obj is ClassDeclaration, ClassDeclaration, unitMember);
9318 NodeList<ClassMember> members = (unitMember as ClassDeclaration).members; 9296 NodeList<ClassMember> members = (unitMember as ClassDeclaration).members;
9319 expect(members, hasLength(1)); 9297 expect(members, hasLength(1));
9320 ClassMember classMember = members[0]; 9298 ClassMember classMember = members[0];
9321 EngineTestCase.assertInstanceOf( 9299 EngineTestCase.assertInstanceOf(
9322 (obj) => obj is FieldDeclaration, FieldDeclaration, classMember); 9300 (obj) => obj is FieldDeclaration, FieldDeclaration, classMember);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
9370 } 9348 }
9371 9349
9372 void test_incompleteLocalVariable_parameterizedType() { 9350 void test_incompleteLocalVariable_parameterizedType() {
9373 Statement statement = parseStatement('List<String> v {}'); 9351 Statement statement = parseStatement('List<String> v {}');
9374 assertErrorsWithCodes([ParserErrorCode.EXPECTED_TOKEN]); 9352 assertErrorsWithCodes([ParserErrorCode.EXPECTED_TOKEN]);
9375 expect(statement, new isInstanceOf<VariableDeclarationStatement>()); 9353 expect(statement, new isInstanceOf<VariableDeclarationStatement>());
9376 expect(statement.toSource(), 'List<String> v;'); 9354 expect(statement.toSource(), 'List<String> v;');
9377 } 9355 }
9378 9356
9379 void test_incompleteTypeArguments_field() { 9357 void test_incompleteTypeArguments_field() {
9380 CompilationUnit unit = parseCompilationUnit( 9358 CompilationUnit unit = parseCompilationUnit(r'''
9381 r'''
9382 class C { 9359 class C {
9383 final List<int f; 9360 final List<int f;
9384 }''', 9361 }''', [ParserErrorCode.EXPECTED_TOKEN]);
9385 [ParserErrorCode.EXPECTED_TOKEN]);
9386 // one class 9362 // one class
9387 List<CompilationUnitMember> declarations = unit.declarations; 9363 List<CompilationUnitMember> declarations = unit.declarations;
9388 expect(declarations, hasLength(1)); 9364 expect(declarations, hasLength(1));
9389 ClassDeclaration classDecl = declarations[0] as ClassDeclaration; 9365 ClassDeclaration classDecl = declarations[0] as ClassDeclaration;
9390 // one field declaration 9366 // one field declaration
9391 List<ClassMember> members = classDecl.members; 9367 List<ClassMember> members = classDecl.members;
9392 expect(members, hasLength(1)); 9368 expect(members, hasLength(1));
9393 FieldDeclaration fieldDecl = members[0] as FieldDeclaration; 9369 FieldDeclaration fieldDecl = members[0] as FieldDeclaration;
9394 // one field 9370 // one field
9395 VariableDeclarationList fieldList = fieldDecl.fields; 9371 VariableDeclarationList fieldList = fieldDecl.fields;
9396 List<VariableDeclaration> fields = fieldList.variables; 9372 List<VariableDeclaration> fields = fieldList.variables;
9397 expect(fields, hasLength(1)); 9373 expect(fields, hasLength(1));
9398 VariableDeclaration field = fields[0]; 9374 VariableDeclaration field = fields[0];
9399 expect(field.name.name, 'f'); 9375 expect(field.name.name, 'f');
9400 // validate the type 9376 // validate the type
9401 TypeArgumentList typeArguments = (fieldList.type as TypeName).typeArguments; 9377 TypeArgumentList typeArguments = (fieldList.type as TypeName).typeArguments;
9402 expect(typeArguments.arguments, hasLength(1)); 9378 expect(typeArguments.arguments, hasLength(1));
9403 // synthetic '>' 9379 // synthetic '>'
9404 Token token = typeArguments.endToken; 9380 Token token = typeArguments.endToken;
9405 expect(token.type, TokenType.GT); 9381 expect(token.type, TokenType.GT);
9406 expect(token.isSynthetic, isTrue); 9382 expect(token.isSynthetic, isTrue);
9407 } 9383 }
9408 9384
9409 void test_incompleteTypeParameters() { 9385 void test_incompleteTypeParameters() {
9410 CompilationUnit unit = parseCompilationUnit( 9386 CompilationUnit unit = parseCompilationUnit(r'''
9411 r'''
9412 class C<K { 9387 class C<K {
9413 }''', 9388 }''', [ParserErrorCode.EXPECTED_TOKEN]);
9414 [ParserErrorCode.EXPECTED_TOKEN]);
9415 // one class 9389 // one class
9416 List<CompilationUnitMember> declarations = unit.declarations; 9390 List<CompilationUnitMember> declarations = unit.declarations;
9417 expect(declarations, hasLength(1)); 9391 expect(declarations, hasLength(1));
9418 ClassDeclaration classDecl = declarations[0] as ClassDeclaration; 9392 ClassDeclaration classDecl = declarations[0] as ClassDeclaration;
9419 // validate the type parameters 9393 // validate the type parameters
9420 TypeParameterList typeParameters = classDecl.typeParameters; 9394 TypeParameterList typeParameters = classDecl.typeParameters;
9421 expect(typeParameters.typeParameters, hasLength(1)); 9395 expect(typeParameters.typeParameters, hasLength(1));
9422 // synthetic '>' 9396 // synthetic '>'
9423 Token token = typeParameters.endToken; 9397 Token token = typeParameters.endToken;
9424 expect(token.type, TokenType.GT); 9398 expect(token.type, TokenType.GT);
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
9564 9538
9565 void test_missingComma_beforeNamedArgument() { 9539 void test_missingComma_beforeNamedArgument() {
9566 createParser('(a b: c)'); 9540 createParser('(a b: c)');
9567 ArgumentList argumentList = parser.parseArgumentList(); 9541 ArgumentList argumentList = parser.parseArgumentList();
9568 expectNotNullIfNoErrors(argumentList); 9542 expectNotNullIfNoErrors(argumentList);
9569 listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_TOKEN]); 9543 listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_TOKEN]);
9570 expect(argumentList.arguments, hasLength(2)); 9544 expect(argumentList.arguments, hasLength(2));
9571 } 9545 }
9572 9546
9573 void test_missingGet() { 9547 void test_missingGet() {
9574 CompilationUnit unit = parseCompilationUnit( 9548 CompilationUnit unit = parseCompilationUnit(r'''
9575 r'''
9576 class C { 9549 class C {
9577 int length {} 9550 int length {}
9578 void foo() {} 9551 void foo() {}
9579 }''', 9552 }''', [ParserErrorCode.MISSING_GET]);
9580 [ParserErrorCode.MISSING_GET]);
9581 expect(unit, isNotNull); 9553 expect(unit, isNotNull);
9582 ClassDeclaration classDeclaration = 9554 ClassDeclaration classDeclaration =
9583 unit.declarations[0] as ClassDeclaration; 9555 unit.declarations[0] as ClassDeclaration;
9584 NodeList<ClassMember> members = classDeclaration.members; 9556 NodeList<ClassMember> members = classDeclaration.members;
9585 expect(members, hasLength(2)); 9557 expect(members, hasLength(2));
9586 EngineTestCase.assertInstanceOf( 9558 EngineTestCase.assertInstanceOf(
9587 (obj) => obj is MethodDeclaration, MethodDeclaration, members[0]); 9559 (obj) => obj is MethodDeclaration, MethodDeclaration, members[0]);
9588 ClassMember member = members[1]; 9560 ClassMember member = members[1];
9589 EngineTestCase.assertInstanceOf( 9561 EngineTestCase.assertInstanceOf(
9590 (obj) => obj is MethodDeclaration, MethodDeclaration, member); 9562 (obj) => obj is MethodDeclaration, MethodDeclaration, member);
(...skipping 5598 matching lines...) Expand 10 before | Expand all | Expand 10 after
15189 expectCommentText(typeVariable.documentationComment, '/// Doc'); 15161 expectCommentText(typeVariable.documentationComment, '/// Doc');
15190 } 15162 }
15191 15163
15192 /** 15164 /**
15193 * Assert that the given [name] is in declaration context. 15165 * Assert that the given [name] is in declaration context.
15194 */ 15166 */
15195 void _assertIsDeclarationName(SimpleIdentifier name) { 15167 void _assertIsDeclarationName(SimpleIdentifier name) {
15196 expect(name.inDeclarationContext(), isTrue); 15168 expect(name.inDeclarationContext(), isTrue);
15197 } 15169 }
15198 } 15170 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/package_test.dart ('k') | pkg/analyzer/test/generated/resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698