| OLD | NEW |
| 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 engine.parser_test; | 5 library analyzer.test.generated.parser_test; |
| 6 | 6 |
| 7 import 'package:analyzer/src/generated/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/src/generated/element.dart'; | 8 import 'package:analyzer/dart/ast/token.dart'; |
| 9 import 'package:analyzer/src/generated/engine.dart'; | 9 import 'package:analyzer/dart/ast/visitor.dart'; |
| 10 import 'package:analyzer/src/generated/error.dart'; | 10 import 'package:analyzer/error/error.dart'; |
| 11 import 'package:analyzer/src/generated/incremental_scanner.dart'; | 11 import 'package:analyzer/src/dart/ast/token.dart'; |
| 12 import 'package:analyzer/src/dart/scanner/reader.dart'; |
| 13 import 'package:analyzer/src/dart/scanner/scanner.dart'; |
| 12 import 'package:analyzer/src/generated/parser.dart'; | 14 import 'package:analyzer/src/generated/parser.dart'; |
| 13 import 'package:analyzer/src/generated/scanner.dart'; | |
| 14 import 'package:analyzer/src/generated/source.dart' show Source; | |
| 15 import 'package:analyzer/src/generated/testing/ast_factory.dart'; | 15 import 'package:analyzer/src/generated/testing/ast_factory.dart'; |
| 16 import 'package:analyzer/src/generated/testing/element_factory.dart'; | |
| 17 import 'package:analyzer/src/generated/testing/token_factory.dart'; | 16 import 'package:analyzer/src/generated/testing/token_factory.dart'; |
| 18 import 'package:analyzer/src/generated/utilities_dart.dart'; | 17 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 19 import 'package:unittest/unittest.dart'; | 18 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 19 import 'package:unittest/unittest.dart' hide Configuration; |
| 20 | 20 |
| 21 import '../reflective_tests.dart'; | |
| 22 import '../utils.dart'; | 21 import '../utils.dart'; |
| 23 import 'test_support.dart'; | 22 import 'test_support.dart'; |
| 24 | 23 |
| 25 main() { | 24 main() { |
| 26 initializeTestEnvironment(); | 25 initializeTestEnvironment(); |
| 27 runReflectiveTests(ComplexParserTest); | 26 defineReflectiveTests(ComplexParserTest); |
| 28 runReflectiveTests(ErrorParserTest); | 27 defineReflectiveTests(ErrorParserTest); |
| 29 runReflectiveTests(IncrementalParserTest); | 28 defineReflectiveTests(NonErrorParserTest); |
| 30 runReflectiveTests(NonErrorParserTest); | 29 defineReflectiveTests(RecoveryParserTest); |
| 31 runReflectiveTests(RecoveryParserTest); | 30 defineReflectiveTests(SimpleParserTest); |
| 32 runReflectiveTests(ResolutionCopierTest); | |
| 33 runReflectiveTests(SimpleParserTest); | |
| 34 } | |
| 35 | |
| 36 class AnalysisErrorListener_SimpleParserTest_computeStringValue | |
| 37 implements AnalysisErrorListener { | |
| 38 @override | |
| 39 void onError(AnalysisError event) { | |
| 40 fail( | |
| 41 "Unexpected compilation error: ${event.message} (${event.offset}, ${even
t.length})"); | |
| 42 } | |
| 43 } | 31 } |
| 44 | 32 |
| 45 /** | 33 /** |
| 46 * Instances of the class `AstValidator` are used to validate the correct constr
uction of an | 34 * Instances of the class `AstValidator` are used to validate the correct constr
uction of an |
| 47 * AST structure. | 35 * AST structure. |
| 48 */ | 36 */ |
| 49 class AstValidator extends UnifyingAstVisitor<Object> { | 37 class AstValidator extends UnifyingAstVisitor<Object> { |
| 50 /** | 38 /** |
| 51 * A list containing the errors found while traversing the AST structure. | 39 * A list containing the errors found while traversing the AST structure. |
| 52 */ | 40 */ |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 (obj) => obj is MethodInvocation, | 185 (obj) => obj is MethodInvocation, |
| 198 MethodInvocation, | 186 MethodInvocation, |
| 199 invocation3.function); | 187 invocation3.function); |
| 200 expect(invocation4.methodName.name, "a"); | 188 expect(invocation4.methodName.name, "a"); |
| 201 expect(invocation4.typeArguments, isNull); | 189 expect(invocation4.typeArguments, isNull); |
| 202 ArgumentList argumentList4 = invocation4.argumentList; | 190 ArgumentList argumentList4 = invocation4.argumentList; |
| 203 expect(argumentList4, isNotNull); | 191 expect(argumentList4, isNotNull); |
| 204 expect(argumentList4.arguments, hasLength(1)); | 192 expect(argumentList4.arguments, hasLength(1)); |
| 205 } | 193 } |
| 206 | 194 |
| 195 void test_assignableExpression_arguments_normal_chain_typeArgumentComments() { |
| 196 enableGenericMethodComments = true; |
| 197 _validate_assignableExpression_arguments_normal_chain_typeArguments( |
| 198 "a/*<E>*/(b)/*<F>*/(c).d/*<G>*/(e).f"); |
| 199 } |
| 200 |
| 207 void test_assignableExpression_arguments_normal_chain_typeArguments() { | 201 void test_assignableExpression_arguments_normal_chain_typeArguments() { |
| 208 enableGenericMethods = true; | 202 enableGenericMethods = true; |
| 209 PropertyAccess propertyAccess1 = parseExpression("a<E>(b)<F>(c).d<G>(e).f"); | 203 _validate_assignableExpression_arguments_normal_chain_typeArguments( |
| 210 expect(propertyAccess1.propertyName.name, "f"); | 204 "a<E>(b)<F>(c).d<G>(e).f"); |
| 211 // | |
| 212 // a<E>(b)<F>(c).d>G?(e) | |
| 213 // | |
| 214 MethodInvocation invocation2 = EngineTestCase.assertInstanceOf( | |
| 215 (obj) => obj is MethodInvocation, | |
| 216 MethodInvocation, | |
| 217 propertyAccess1.target); | |
| 218 expect(invocation2.methodName.name, "d"); | |
| 219 expect(invocation2.typeArguments, isNotNull); | |
| 220 ArgumentList argumentList2 = invocation2.argumentList; | |
| 221 expect(argumentList2, isNotNull); | |
| 222 expect(argumentList2.arguments, hasLength(1)); | |
| 223 // | |
| 224 // a<E>(b)<F>(c) | |
| 225 // | |
| 226 FunctionExpressionInvocation invocation3 = EngineTestCase.assertInstanceOf( | |
| 227 (obj) => obj is FunctionExpressionInvocation, | |
| 228 FunctionExpressionInvocation, | |
| 229 invocation2.target); | |
| 230 expect(invocation3.typeArguments, isNotNull); | |
| 231 ArgumentList argumentList3 = invocation3.argumentList; | |
| 232 expect(argumentList3, isNotNull); | |
| 233 expect(argumentList3.arguments, hasLength(1)); | |
| 234 // | |
| 235 // a(b) | |
| 236 // | |
| 237 MethodInvocation invocation4 = EngineTestCase.assertInstanceOf( | |
| 238 (obj) => obj is MethodInvocation, | |
| 239 MethodInvocation, | |
| 240 invocation3.function); | |
| 241 expect(invocation4.methodName.name, "a"); | |
| 242 expect(invocation4.typeArguments, isNotNull); | |
| 243 ArgumentList argumentList4 = invocation4.argumentList; | |
| 244 expect(argumentList4, isNotNull); | |
| 245 expect(argumentList4.arguments, hasLength(1)); | |
| 246 } | 205 } |
| 247 | 206 |
| 248 void test_assignmentExpression_compound() { | 207 void test_assignmentExpression_compound() { |
| 249 AssignmentExpression expression = parseExpression("x = y = 0"); | 208 AssignmentExpression expression = parseExpression("x = y = 0"); |
| 250 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, | 209 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| 251 SimpleIdentifier, expression.leftHandSide); | 210 SimpleIdentifier, expression.leftHandSide); |
| 252 EngineTestCase.assertInstanceOf((obj) => obj is AssignmentExpression, | 211 EngineTestCase.assertInstanceOf((obj) => obj is AssignmentExpression, |
| 253 AssignmentExpression, expression.rightHandSide); | 212 AssignmentExpression, expression.rightHandSide); |
| 254 } | 213 } |
| 255 | 214 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, | 329 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| 371 BinaryExpression, expression.condition); | 330 BinaryExpression, expression.condition); |
| 372 } | 331 } |
| 373 | 332 |
| 374 void test_conditionalExpression_precedence_logicalOrExpression() { | 333 void test_conditionalExpression_precedence_logicalOrExpression() { |
| 375 ConditionalExpression expression = parseExpression("a | b ? y : z"); | 334 ConditionalExpression expression = parseExpression("a | b ? y : z"); |
| 376 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, | 335 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| 377 BinaryExpression, expression.condition); | 336 BinaryExpression, expression.condition); |
| 378 } | 337 } |
| 379 | 338 |
| 339 void test_conditionalExpression_precedence_nullableType_as() { |
| 340 enableNnbd = true; |
| 341 Expression expression = parseExpression('x as String ? (x + y) : z'); |
| 342 expect(expression, isNotNull); |
| 343 expect(expression, new isInstanceOf<ConditionalExpression>()); |
| 344 ConditionalExpression conditional = expression; |
| 345 Expression condition = conditional.condition; |
| 346 expect(condition, new isInstanceOf<AsExpression>()); |
| 347 Expression thenExpression = conditional.thenExpression; |
| 348 expect(thenExpression, new isInstanceOf<ParenthesizedExpression>()); |
| 349 Expression elseExpression = conditional.elseExpression; |
| 350 expect(elseExpression, new isInstanceOf<SimpleIdentifier>()); |
| 351 } |
| 352 |
| 353 void test_conditionalExpression_precedence_nullableType_is() { |
| 354 enableNnbd = true; |
| 355 Expression expression = parseExpression('x is String ? (x + y) : z'); |
| 356 expect(expression, isNotNull); |
| 357 expect(expression, new isInstanceOf<ConditionalExpression>()); |
| 358 ConditionalExpression conditional = expression; |
| 359 Expression condition = conditional.condition; |
| 360 expect(condition, new isInstanceOf<IsExpression>()); |
| 361 Expression thenExpression = conditional.thenExpression; |
| 362 expect(thenExpression, new isInstanceOf<ParenthesizedExpression>()); |
| 363 Expression elseExpression = conditional.elseExpression; |
| 364 expect(elseExpression, new isInstanceOf<SimpleIdentifier>()); |
| 365 } |
| 366 |
| 380 void test_constructor_initializer_withParenthesizedExpression() { | 367 void test_constructor_initializer_withParenthesizedExpression() { |
| 381 CompilationUnit unit = ParserTestCase.parseCompilationUnit(r''' | 368 CompilationUnit unit = ParserTestCase.parseCompilationUnit(r''' |
| 382 class C { | 369 class C { |
| 383 C() : | 370 C() : |
| 384 this.a = (b == null ? c : d) { | 371 this.a = (b == null ? c : d) { |
| 385 } | 372 } |
| 386 }'''); | 373 }'''); |
| 387 NodeList<CompilationUnitMember> declarations = unit.declarations; | 374 NodeList<CompilationUnitMember> declarations = unit.declarations; |
| 388 expect(declarations, hasLength(1)); | 375 expect(declarations, hasLength(1)); |
| 389 } | 376 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 419 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, | 406 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| 420 BinaryExpression, expression.leftOperand); | 407 BinaryExpression, expression.leftOperand); |
| 421 } | 408 } |
| 422 | 409 |
| 423 void test_ifNullExpression_precedence_logicalOr_left() { | 410 void test_ifNullExpression_precedence_logicalOr_left() { |
| 424 BinaryExpression expression = parseExpression('x || y ?? z'); | 411 BinaryExpression expression = parseExpression('x || y ?? z'); |
| 425 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, | 412 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| 426 BinaryExpression, expression.leftOperand); | 413 BinaryExpression, expression.leftOperand); |
| 427 } | 414 } |
| 428 | 415 |
| 429 void test_ifNullExpression_precendce_logicalOr_right() { | 416 void test_ifNullExpression_precedence_logicalOr_right() { |
| 430 BinaryExpression expression = parseExpression('x ?? y || z'); | 417 BinaryExpression expression = parseExpression('x ?? y || z'); |
| 431 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, | 418 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| 432 BinaryExpression, expression.rightOperand); | 419 BinaryExpression, expression.rightOperand); |
| 433 } | 420 } |
| 434 | 421 |
| 435 void test_logicalAndExpression() { | 422 void test_logicalAndExpression() { |
| 436 BinaryExpression expression = parseExpression("x && y && z"); | 423 BinaryExpression expression = parseExpression("x && y && z"); |
| 437 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, | 424 expect(expression.leftOperand, new isInstanceOf<BinaryExpression>()); |
| 438 BinaryExpression, expression.leftOperand); | |
| 439 } | 425 } |
| 440 | 426 |
| 441 void test_logicalAndExpression_precedence_bitwiseOr_left() { | 427 void test_logicalAndExpression_precedence_bitwiseOr_left() { |
| 442 BinaryExpression expression = parseExpression("x | y < z"); | 428 BinaryExpression expression = parseExpression("x | y < z"); |
| 443 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, | 429 expect(expression.leftOperand, new isInstanceOf<BinaryExpression>()); |
| 444 BinaryExpression, expression.leftOperand); | |
| 445 } | 430 } |
| 446 | 431 |
| 447 void test_logicalAndExpression_precedence_bitwiseOr_right() { | 432 void test_logicalAndExpression_precedence_bitwiseOr_right() { |
| 448 BinaryExpression expression = parseExpression("x < y | z"); | 433 BinaryExpression expression = parseExpression("x < y | z"); |
| 449 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, | 434 expect(expression.rightOperand, new isInstanceOf<BinaryExpression>()); |
| 450 BinaryExpression, expression.rightOperand); | 435 } |
| 436 |
| 437 void test_logicalAndExpression_precedence_nullableType() { |
| 438 enableNnbd = true; |
| 439 BinaryExpression expression = parseExpression("x is C? && y is D"); |
| 440 expect(expression.leftOperand, new isInstanceOf<IsExpression>()); |
| 441 expect(expression.rightOperand, new isInstanceOf<IsExpression>()); |
| 451 } | 442 } |
| 452 | 443 |
| 453 void test_logicalOrExpression() { | 444 void test_logicalOrExpression() { |
| 454 BinaryExpression expression = parseExpression("x || y || z"); | 445 BinaryExpression expression = parseExpression("x || y || z"); |
| 455 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, | 446 expect(expression.leftOperand, new isInstanceOf<BinaryExpression>()); |
| 456 BinaryExpression, expression.leftOperand); | |
| 457 } | 447 } |
| 458 | 448 |
| 459 void test_logicalOrExpression_precedence_logicalAnd_left() { | 449 void test_logicalOrExpression_precedence_logicalAnd_left() { |
| 460 BinaryExpression expression = parseExpression("x && y || z"); | 450 BinaryExpression expression = parseExpression("x && y || z"); |
| 461 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, | 451 expect(expression.leftOperand, new isInstanceOf<BinaryExpression>()); |
| 462 BinaryExpression, expression.leftOperand); | |
| 463 } | 452 } |
| 464 | 453 |
| 465 void test_logicalOrExpression_precedence_logicalAnd_right() { | 454 void test_logicalOrExpression_precedence_logicalAnd_right() { |
| 466 BinaryExpression expression = parseExpression("x || y && z"); | 455 BinaryExpression expression = parseExpression("x || y && z"); |
| 467 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, | 456 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| 468 BinaryExpression, expression.rightOperand); | 457 BinaryExpression, expression.rightOperand); |
| 469 } | 458 } |
| 470 | 459 |
| 460 void test_logicalOrExpression_precedence_nullableType() { |
| 461 enableNnbd = true; |
| 462 BinaryExpression expression = parseExpression("a is X? || (b ? c : d)"); |
| 463 expect(expression.leftOperand, new isInstanceOf<IsExpression>()); |
| 464 expect( |
| 465 expression.rightOperand, new isInstanceOf<ParenthesizedExpression>()); |
| 466 expect((expression.rightOperand as ParenthesizedExpression).expression, |
| 467 new isInstanceOf<ConditionalExpression>()); |
| 468 } |
| 469 |
| 471 void test_multipleLabels_statement() { | 470 void test_multipleLabels_statement() { |
| 472 LabeledStatement statement = | 471 LabeledStatement statement = |
| 473 ParserTestCase.parseStatement("a: b: c: return x;"); | 472 ParserTestCase.parseStatement("a: b: c: return x;"); |
| 474 expect(statement.labels, hasLength(3)); | 473 expect(statement.labels, hasLength(3)); |
| 475 EngineTestCase.assertInstanceOf( | 474 EngineTestCase.assertInstanceOf( |
| 476 (obj) => obj is ReturnStatement, ReturnStatement, statement.statement); | 475 (obj) => obj is ReturnStatement, ReturnStatement, statement.statement); |
| 477 } | 476 } |
| 478 | 477 |
| 479 void test_multiplicativeExpression_normal() { | 478 void test_multiplicativeExpression_normal() { |
| 480 BinaryExpression expression = parseExpression("x * y / z"); | 479 BinaryExpression expression = parseExpression("x * y / z"); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 BinaryExpression expression = parseExpression("x << y + z"); | 521 BinaryExpression expression = parseExpression("x << y + z"); |
| 523 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, | 522 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| 524 BinaryExpression, expression.rightOperand); | 523 BinaryExpression, expression.rightOperand); |
| 525 } | 524 } |
| 526 | 525 |
| 527 void test_shiftExpression_super() { | 526 void test_shiftExpression_super() { |
| 528 BinaryExpression expression = parseExpression("super >> 4 << 3"); | 527 BinaryExpression expression = parseExpression("super >> 4 << 3"); |
| 529 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, | 528 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| 530 BinaryExpression, expression.leftOperand); | 529 BinaryExpression, expression.leftOperand); |
| 531 } | 530 } |
| 531 |
| 532 void test_topLevelFunction_nestedGenericFunction() { |
| 533 enableGenericMethods = true; |
| 534 parseCompilationUnitWithOptions(''' |
| 535 void f() { |
| 536 void g<T>() { |
| 537 } |
| 538 } |
| 539 '''); |
| 540 } |
| 541 |
| 542 void _validate_assignableExpression_arguments_normal_chain_typeArguments( |
| 543 String code) { |
| 544 PropertyAccess propertyAccess1 = parseExpression(code); |
| 545 expect(propertyAccess1.propertyName.name, "f"); |
| 546 // |
| 547 // a<E>(b)<F>(c).d<G>(e) |
| 548 // |
| 549 MethodInvocation invocation2 = EngineTestCase.assertInstanceOf( |
| 550 (obj) => obj is MethodInvocation, |
| 551 MethodInvocation, |
| 552 propertyAccess1.target); |
| 553 expect(invocation2.methodName.name, "d"); |
| 554 expect(invocation2.typeArguments, isNotNull); |
| 555 ArgumentList argumentList2 = invocation2.argumentList; |
| 556 expect(argumentList2, isNotNull); |
| 557 expect(argumentList2.arguments, hasLength(1)); |
| 558 // |
| 559 // a<E>(b)<F>(c) |
| 560 // |
| 561 FunctionExpressionInvocation invocation3 = EngineTestCase.assertInstanceOf( |
| 562 (obj) => obj is FunctionExpressionInvocation, |
| 563 FunctionExpressionInvocation, |
| 564 invocation2.target); |
| 565 expect(invocation3.typeArguments, isNotNull); |
| 566 ArgumentList argumentList3 = invocation3.argumentList; |
| 567 expect(argumentList3, isNotNull); |
| 568 expect(argumentList3.arguments, hasLength(1)); |
| 569 // |
| 570 // a(b) |
| 571 // |
| 572 MethodInvocation invocation4 = EngineTestCase.assertInstanceOf( |
| 573 (obj) => obj is MethodInvocation, |
| 574 MethodInvocation, |
| 575 invocation3.function); |
| 576 expect(invocation4.methodName.name, "a"); |
| 577 expect(invocation4.typeArguments, isNotNull); |
| 578 ArgumentList argumentList4 = invocation4.argumentList; |
| 579 expect(argumentList4, isNotNull); |
| 580 expect(argumentList4.arguments, hasLength(1)); |
| 581 } |
| 532 } | 582 } |
| 533 | 583 |
| 534 /** | 584 /** |
| 535 * The class `ErrorParserTest` defines parser tests that test the parsing of cod
e to ensure | 585 * The class `ErrorParserTest` defines parser tests that test the parsing of cod
e to ensure |
| 536 * that errors are correctly reported, and in some cases, not reported. | 586 * that errors are correctly reported, and in some cases, not reported. |
| 537 */ | 587 */ |
| 538 @reflectiveTest | 588 @reflectiveTest |
| 539 class ErrorParserTest extends ParserTestCase { | 589 class ErrorParserTest extends ParserTestCase { |
| 540 void fail_expectedListOrMapLiteral() { | |
| 541 // It isn't clear that this test can ever pass. The parser is currently | |
| 542 // create a synthetic list literal in this case, but isSynthetic() isn't | |
| 543 // overridden for ListLiteral. The problem is that the synthetic list | |
| 544 // literals that are being created are not always zero length (because they | |
| 545 // could have type parameters), which violates the contract of | |
| 546 // isSynthetic(). | |
| 547 TypedLiteral literal = parse3("parseListOrMapLiteral", <Object>[null], "1", | |
| 548 [ParserErrorCode.EXPECTED_LIST_OR_MAP_LITERAL]); | |
| 549 expect(literal.isSynthetic, isTrue); | |
| 550 } | |
| 551 | |
| 552 void fail_illegalAssignmentToNonAssignable_superAssigned() { | |
| 553 // TODO(brianwilkerson) When this test starts to pass, remove the test | |
| 554 // test_illegalAssignmentToNonAssignable_superAssigned. | |
| 555 parseExpression( | |
| 556 "super = x;", [ParserErrorCode.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE]); | |
| 557 } | |
| 558 | |
| 559 void fail_invalidCommentReference__new_nonIdentifier() { | |
| 560 // This test fails because the method parseCommentReference returns null. | |
| 561 parse3("parseCommentReference", <Object>["new 42", 0], "", | |
| 562 [ParserErrorCode.INVALID_COMMENT_REFERENCE]); | |
| 563 } | |
| 564 | |
| 565 void fail_invalidCommentReference__new_tooMuch() { | |
| 566 parse3("parseCommentReference", <Object>["new a.b.c.d", 0], "", | |
| 567 [ParserErrorCode.INVALID_COMMENT_REFERENCE]); | |
| 568 } | |
| 569 | |
| 570 void fail_invalidCommentReference__nonNew_nonIdentifier() { | |
| 571 // This test fails because the method parseCommentReference returns null. | |
| 572 parse3("parseCommentReference", <Object>["42", 0], "", | |
| 573 [ParserErrorCode.INVALID_COMMENT_REFERENCE]); | |
| 574 } | |
| 575 | |
| 576 void fail_invalidCommentReference__nonNew_tooMuch() { | |
| 577 parse3("parseCommentReference", <Object>["a.b.c.d", 0], "", | |
| 578 [ParserErrorCode.INVALID_COMMENT_REFERENCE]); | |
| 579 } | |
| 580 | |
| 581 void fail_missingClosingParenthesis() { | |
| 582 // It is possible that it is not possible to generate this error (that it's | |
| 583 // being reported in code that cannot actually be reached), but that hasn't | |
| 584 // been proven yet. | |
| 585 parse4("parseFormalParameterList", "(int a, int b ;", | |
| 586 [ParserErrorCode.MISSING_CLOSING_PARENTHESIS]); | |
| 587 } | |
| 588 | |
| 589 void fail_missingFunctionParameters_local_nonVoid_block() { | |
| 590 // The parser does not recognize this as a function declaration, so it tries | |
| 591 // to parse it as an expression statement. It isn't clear what the best | |
| 592 // error message is in this case. | |
| 593 ParserTestCase.parseStatement( | |
| 594 "int f { return x;}", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); | |
| 595 } | |
| 596 | |
| 597 void fail_missingFunctionParameters_local_nonVoid_expression() { | |
| 598 // The parser does not recognize this as a function declaration, so it tries | |
| 599 // to parse it as an expression statement. It isn't clear what the best | |
| 600 // error message is in this case. | |
| 601 ParserTestCase.parseStatement( | |
| 602 "int f => x;", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); | |
| 603 } | |
| 604 | |
| 605 void fail_namedFunctionExpression() { | |
| 606 Expression expression = parse4("parsePrimaryExpression", "f() {}", | |
| 607 [ParserErrorCode.NAMED_FUNCTION_EXPRESSION]); | |
| 608 EngineTestCase.assertInstanceOf( | |
| 609 (obj) => obj is FunctionExpression, FunctionExpression, expression); | |
| 610 } | |
| 611 | |
| 612 void fail_unexpectedToken_invalidPostfixExpression() { | |
| 613 // Note: this might not be the right error to produce, but some error should | |
| 614 // be produced | |
| 615 parseExpression("f()++", [ParserErrorCode.UNEXPECTED_TOKEN]); | |
| 616 } | |
| 617 | |
| 618 void fail_varAndType_local() { | |
| 619 // This is currently reporting EXPECTED_TOKEN for a missing semicolon, but | |
| 620 // this would be a better error message. | |
| 621 ParserTestCase.parseStatement("var int x;", [ParserErrorCode.VAR_AND_TYPE]); | |
| 622 } | |
| 623 | |
| 624 void fail_varAndType_parameter() { | |
| 625 // This is currently reporting EXPECTED_TOKEN for a missing semicolon, but | |
| 626 // this would be a better error message. | |
| 627 parse4("parseFormalParameterList", "(var int x)", | |
| 628 [ParserErrorCode.VAR_AND_TYPE]); | |
| 629 } | |
| 630 | |
| 631 void test_abstractClassMember_constructor() { | 590 void test_abstractClassMember_constructor() { |
| 632 parse3("parseClassMember", <Object>["C"], "abstract C.c();", | 591 createParser('abstract C.c();'); |
| 633 [ParserErrorCode.ABSTRACT_CLASS_MEMBER]); | 592 ClassMember member = parser.parseClassMember('C'); |
| 593 expectNotNullIfNoErrors(member); |
| 594 listener.assertErrorsWithCodes([ParserErrorCode.ABSTRACT_CLASS_MEMBER]); |
| 634 } | 595 } |
| 635 | 596 |
| 636 void test_abstractClassMember_field() { | 597 void test_abstractClassMember_field() { |
| 637 parse3("parseClassMember", <Object>["C"], "abstract C f;", | 598 createParser('abstract C f;'); |
| 638 [ParserErrorCode.ABSTRACT_CLASS_MEMBER]); | 599 ClassMember member = parser.parseClassMember('C'); |
| 600 expectNotNullIfNoErrors(member); |
| 601 listener.assertErrorsWithCodes([ParserErrorCode.ABSTRACT_CLASS_MEMBER]); |
| 639 } | 602 } |
| 640 | 603 |
| 641 void test_abstractClassMember_getter() { | 604 void test_abstractClassMember_getter() { |
| 642 parse3("parseClassMember", <Object>["C"], "abstract get m;", | 605 createParser('abstract get m;'); |
| 643 [ParserErrorCode.ABSTRACT_CLASS_MEMBER]); | 606 ClassMember member = parser.parseClassMember('C'); |
| 607 expectNotNullIfNoErrors(member); |
| 608 listener.assertErrorsWithCodes([ParserErrorCode.ABSTRACT_CLASS_MEMBER]); |
| 644 } | 609 } |
| 645 | 610 |
| 646 void test_abstractClassMember_method() { | 611 void test_abstractClassMember_method() { |
| 647 parse3("parseClassMember", <Object>["C"], "abstract m();", | 612 createParser('abstract m();'); |
| 648 [ParserErrorCode.ABSTRACT_CLASS_MEMBER]); | 613 ClassMember member = parser.parseClassMember('C'); |
| 614 expectNotNullIfNoErrors(member); |
| 615 listener.assertErrorsWithCodes([ParserErrorCode.ABSTRACT_CLASS_MEMBER]); |
| 649 } | 616 } |
| 650 | 617 |
| 651 void test_abstractClassMember_setter() { | 618 void test_abstractClassMember_setter() { |
| 652 parse3("parseClassMember", <Object>["C"], "abstract set m(v);", | 619 createParser('abstract set m(v);'); |
| 653 [ParserErrorCode.ABSTRACT_CLASS_MEMBER]); | 620 ClassMember member = parser.parseClassMember('C'); |
| 621 expectNotNullIfNoErrors(member); |
| 622 listener.assertErrorsWithCodes([ParserErrorCode.ABSTRACT_CLASS_MEMBER]); |
| 654 } | 623 } |
| 655 | 624 |
| 656 void test_abstractEnum() { | 625 void test_abstractEnum() { |
| 657 ParserTestCase.parseCompilationUnit( | 626 ParserTestCase.parseCompilationUnit( |
| 658 "abstract enum E {ONE}", [ParserErrorCode.ABSTRACT_ENUM]); | 627 "abstract enum E {ONE}", [ParserErrorCode.ABSTRACT_ENUM]); |
| 659 } | 628 } |
| 660 | 629 |
| 661 void test_abstractTopLevelFunction_function() { | 630 void test_abstractTopLevelFunction_function() { |
| 662 ParserTestCase.parseCompilationUnit( | 631 ParserTestCase.parseCompilationUnit( |
| 663 "abstract f(v) {}", [ParserErrorCode.ABSTRACT_TOP_LEVEL_FUNCTION]); | 632 "abstract f(v) {}", [ParserErrorCode.ABSTRACT_TOP_LEVEL_FUNCTION]); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 686 void test_annotationOnEnumConstant_first() { | 655 void test_annotationOnEnumConstant_first() { |
| 687 ParserTestCase.parseCompilationUnit("enum E { @override C }", | 656 ParserTestCase.parseCompilationUnit("enum E { @override C }", |
| 688 [ParserErrorCode.ANNOTATION_ON_ENUM_CONSTANT]); | 657 [ParserErrorCode.ANNOTATION_ON_ENUM_CONSTANT]); |
| 689 } | 658 } |
| 690 | 659 |
| 691 void test_annotationOnEnumConstant_middle() { | 660 void test_annotationOnEnumConstant_middle() { |
| 692 ParserTestCase.parseCompilationUnit("enum E { C, @override D, E }", | 661 ParserTestCase.parseCompilationUnit("enum E { C, @override D, E }", |
| 693 [ParserErrorCode.ANNOTATION_ON_ENUM_CONSTANT]); | 662 [ParserErrorCode.ANNOTATION_ON_ENUM_CONSTANT]); |
| 694 } | 663 } |
| 695 | 664 |
| 696 void test_assertDoesNotTakeAssignment() { | |
| 697 parse4("parseAssertStatement", "assert(b = true);", | |
| 698 [ParserErrorCode.ASSERT_DOES_NOT_TAKE_ASSIGNMENT]); | |
| 699 } | |
| 700 | |
| 701 void test_assertDoesNotTakeCascades() { | |
| 702 parse4("parseAssertStatement", "assert(new A()..m());", | |
| 703 [ParserErrorCode.ASSERT_DOES_NOT_TAKE_CASCADE]); | |
| 704 } | |
| 705 | |
| 706 void test_assertDoesNotTakeRethrow() { | |
| 707 parse4("parseAssertStatement", "assert(rethrow);", | |
| 708 [ParserErrorCode.ASSERT_DOES_NOT_TAKE_RETHROW]); | |
| 709 } | |
| 710 | |
| 711 void test_assertDoesNotTakeThrow() { | |
| 712 parse4("parseAssertStatement", "assert(throw x);", | |
| 713 [ParserErrorCode.ASSERT_DOES_NOT_TAKE_THROW]); | |
| 714 } | |
| 715 | |
| 716 void test_breakOutsideOfLoop_breakInDoStatement() { | 665 void test_breakOutsideOfLoop_breakInDoStatement() { |
| 717 parse4("parseDoStatement", "do {break;} while (x);"); | 666 createParser('do {break;} while (x);'); |
| 667 DoStatement statement = parser.parseDoStatement(); |
| 668 expectNotNullIfNoErrors(statement); |
| 669 listener.assertNoErrors(); |
| 718 } | 670 } |
| 719 | 671 |
| 720 void test_breakOutsideOfLoop_breakInForStatement() { | 672 void test_breakOutsideOfLoop_breakInForStatement() { |
| 721 parse4("parseForStatement", "for (; x;) {break;}"); | 673 createParser('for (; x;) {break;}'); |
| 674 Statement statement = parser.parseForStatement(); |
| 675 expectNotNullIfNoErrors(statement); |
| 676 listener.assertNoErrors(); |
| 722 } | 677 } |
| 723 | 678 |
| 724 void test_breakOutsideOfLoop_breakInIfStatement() { | 679 void test_breakOutsideOfLoop_breakInIfStatement() { |
| 725 parse4("parseIfStatement", "if (x) {break;}", | 680 createParser('if (x) {break;}'); |
| 726 [ParserErrorCode.BREAK_OUTSIDE_OF_LOOP]); | 681 IfStatement statement = parser.parseIfStatement(); |
| 682 expectNotNullIfNoErrors(statement); |
| 683 listener.assertErrorsWithCodes([ParserErrorCode.BREAK_OUTSIDE_OF_LOOP]); |
| 727 } | 684 } |
| 728 | 685 |
| 729 void test_breakOutsideOfLoop_breakInSwitchStatement() { | 686 void test_breakOutsideOfLoop_breakInSwitchStatement() { |
| 730 parse4("parseSwitchStatement", "switch (x) {case 1: break;}"); | 687 createParser('switch (x) {case 1: break;}'); |
| 688 SwitchStatement statement = parser.parseSwitchStatement(); |
| 689 expectNotNullIfNoErrors(statement); |
| 690 listener.assertNoErrors(); |
| 731 } | 691 } |
| 732 | 692 |
| 733 void test_breakOutsideOfLoop_breakInWhileStatement() { | 693 void test_breakOutsideOfLoop_breakInWhileStatement() { |
| 734 parse4("parseWhileStatement", "while (x) {break;}"); | 694 createParser('while (x) {break;}'); |
| 695 WhileStatement statement = parser.parseWhileStatement(); |
| 696 expectNotNullIfNoErrors(statement); |
| 697 listener.assertNoErrors(); |
| 735 } | 698 } |
| 736 | 699 |
| 737 void test_breakOutsideOfLoop_functionExpression_inALoop() { | 700 void test_breakOutsideOfLoop_functionExpression_inALoop() { |
| 738 ParserTestCase.parseStatement( | 701 ParserTestCase.parseStatement( |
| 739 "for(; x;) {() {break;};}", [ParserErrorCode.BREAK_OUTSIDE_OF_LOOP]); | 702 "for(; x;) {() {break;};}", [ParserErrorCode.BREAK_OUTSIDE_OF_LOOP]); |
| 740 } | 703 } |
| 741 | 704 |
| 742 void test_breakOutsideOfLoop_functionExpression_withALoop() { | 705 void test_breakOutsideOfLoop_functionExpression_withALoop() { |
| 743 ParserTestCase.parseStatement("() {for (; x;) {break;}};"); | 706 ParserTestCase.parseStatement("() {for (; x;) {break;}};"); |
| 744 } | 707 } |
| 745 | 708 |
| 746 void test_classInClass_abstract() { | 709 void test_classInClass_abstract() { |
| 747 ParserTestCase.parseCompilationUnit( | 710 ParserTestCase.parseCompilationUnit( |
| 748 "class C { abstract class B {} }", [ParserErrorCode.CLASS_IN_CLASS]); | 711 "class C { abstract class B {} }", [ParserErrorCode.CLASS_IN_CLASS]); |
| 749 } | 712 } |
| 750 | 713 |
| 751 void test_classInClass_nonAbstract() { | 714 void test_classInClass_nonAbstract() { |
| 752 ParserTestCase.parseCompilationUnit( | 715 ParserTestCase.parseCompilationUnit( |
| 753 "class C { class B {} }", [ParserErrorCode.CLASS_IN_CLASS]); | 716 "class C { class B {} }", [ParserErrorCode.CLASS_IN_CLASS]); |
| 754 } | 717 } |
| 755 | 718 |
| 756 void test_classTypeAlias_abstractAfterEq() { | 719 void test_classTypeAlias_abstractAfterEq() { |
| 757 // This syntax has been removed from the language in favor of | 720 // This syntax has been removed from the language in favor of |
| 758 // "abstract class A = B with C;" (issue 18098). | 721 // "abstract class A = B with C;" (issue 18098). |
| 759 parse3( | 722 createParser('class A = abstract B with C;'); |
| 760 "parseCompilationUnitMember", | 723 CompilationUnitMember member = |
| 761 <Object>[emptyCommentAndMetadata()], | 724 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 762 "class A = abstract B with C;", | 725 expectNotNullIfNoErrors(member); |
| 726 listener.assertErrorsWithCodes( |
| 763 [ParserErrorCode.EXPECTED_TOKEN, ParserErrorCode.EXPECTED_TOKEN]); | 727 [ParserErrorCode.EXPECTED_TOKEN, ParserErrorCode.EXPECTED_TOKEN]); |
| 764 } | 728 } |
| 765 | 729 |
| 766 void test_colonInPlaceOfIn() { | 730 void test_colonInPlaceOfIn() { |
| 767 ParserTestCase.parseStatement( | 731 ParserTestCase.parseStatement( |
| 768 "for (var x : list) {}", [ParserErrorCode.COLON_IN_PLACE_OF_IN]); | 732 "for (var x : list) {}", [ParserErrorCode.COLON_IN_PLACE_OF_IN]); |
| 769 } | 733 } |
| 770 | 734 |
| 771 void test_constAndFinal() { | 735 void test_constAndFinal() { |
| 772 parse3("parseClassMember", <Object>["C"], "const final int x;", | 736 createParser('const final int x;'); |
| 773 [ParserErrorCode.CONST_AND_FINAL]); | 737 ClassMember member = parser.parseClassMember('C'); |
| 738 expectNotNullIfNoErrors(member); |
| 739 listener.assertErrorsWithCodes([ParserErrorCode.CONST_AND_FINAL]); |
| 774 } | 740 } |
| 775 | 741 |
| 776 void test_constAndVar() { | 742 void test_constAndVar() { |
| 777 parse3("parseClassMember", <Object>["C"], "const var x;", | 743 createParser('const var x;'); |
| 778 [ParserErrorCode.CONST_AND_VAR]); | 744 ClassMember member = parser.parseClassMember('C'); |
| 745 expectNotNullIfNoErrors(member); |
| 746 listener.assertErrorsWithCodes([ParserErrorCode.CONST_AND_VAR]); |
| 779 } | 747 } |
| 780 | 748 |
| 781 void test_constClass() { | 749 void test_constClass() { |
| 782 ParserTestCase.parseCompilationUnit( | 750 ParserTestCase.parseCompilationUnit( |
| 783 "const class C {}", [ParserErrorCode.CONST_CLASS]); | 751 "const class C {}", [ParserErrorCode.CONST_CLASS]); |
| 784 } | 752 } |
| 785 | 753 |
| 786 void test_constConstructorWithBody() { | 754 void test_constConstructorWithBody() { |
| 787 parse3("parseClassMember", <Object>["C"], "const C() {}", | 755 createParser('const C() {}'); |
| 788 [ParserErrorCode.CONST_CONSTRUCTOR_WITH_BODY]); | 756 ClassMember member = parser.parseClassMember('C'); |
| 757 expectNotNullIfNoErrors(member); |
| 758 listener |
| 759 .assertErrorsWithCodes([ParserErrorCode.CONST_CONSTRUCTOR_WITH_BODY]); |
| 789 } | 760 } |
| 790 | 761 |
| 791 void test_constEnum() { | 762 void test_constEnum() { |
| 792 ParserTestCase.parseCompilationUnit( | 763 ParserTestCase.parseCompilationUnit( |
| 793 "const enum E {ONE}", [ParserErrorCode.CONST_ENUM]); | 764 "const enum E {ONE}", [ParserErrorCode.CONST_ENUM]); |
| 794 } | 765 } |
| 795 | 766 |
| 796 void test_constFactory() { | 767 void test_constFactory() { |
| 797 parse3("parseClassMember", <Object>["C"], "const factory C() {}", | 768 createParser('const factory C() {}'); |
| 798 [ParserErrorCode.CONST_FACTORY]); | 769 ClassMember member = parser.parseClassMember('C'); |
| 770 expectNotNullIfNoErrors(member); |
| 771 listener.assertErrorsWithCodes([ParserErrorCode.CONST_FACTORY]); |
| 799 } | 772 } |
| 800 | 773 |
| 801 void test_constMethod() { | 774 void test_constMethod() { |
| 802 parse3("parseClassMember", <Object>["C"], "const int m() {}", | 775 createParser('const int m() {}'); |
| 803 [ParserErrorCode.CONST_METHOD]); | 776 ClassMember member = parser.parseClassMember('C'); |
| 777 expectNotNullIfNoErrors(member); |
| 778 listener.assertErrorsWithCodes([ParserErrorCode.CONST_METHOD]); |
| 804 } | 779 } |
| 805 | 780 |
| 806 void test_constructorWithReturnType() { | 781 void test_constructorWithReturnType() { |
| 807 parse3("parseClassMember", <Object>["C"], "C C() {}", | 782 createParser('C C() {}'); |
| 808 [ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE]); | 783 ClassMember member = parser.parseClassMember('C'); |
| 784 expectNotNullIfNoErrors(member); |
| 785 listener |
| 786 .assertErrorsWithCodes([ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE]); |
| 809 } | 787 } |
| 810 | 788 |
| 811 void test_constructorWithReturnType_var() { | 789 void test_constructorWithReturnType_var() { |
| 812 parse3("parseClassMember", <Object>["C"], "var C() {}", | 790 createParser('var C() {}'); |
| 813 [ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE]); | 791 ClassMember member = parser.parseClassMember('C'); |
| 792 expectNotNullIfNoErrors(member); |
| 793 listener |
| 794 .assertErrorsWithCodes([ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE]); |
| 814 } | 795 } |
| 815 | 796 |
| 816 void test_constTypedef() { | 797 void test_constTypedef() { |
| 817 ParserTestCase.parseCompilationUnit( | 798 ParserTestCase.parseCompilationUnit( |
| 818 "const typedef F();", [ParserErrorCode.CONST_TYPEDEF]); | 799 "const typedef F();", [ParserErrorCode.CONST_TYPEDEF]); |
| 819 } | 800 } |
| 820 | 801 |
| 821 void test_continueOutsideOfLoop_continueInDoStatement() { | 802 void test_continueOutsideOfLoop_continueInDoStatement() { |
| 822 parse4("parseDoStatement", "do {continue;} while (x);"); | 803 createParser('do {continue;} while (x);'); |
| 804 DoStatement statement = parser.parseDoStatement(); |
| 805 expectNotNullIfNoErrors(statement); |
| 806 listener.assertNoErrors(); |
| 823 } | 807 } |
| 824 | 808 |
| 825 void test_continueOutsideOfLoop_continueInForStatement() { | 809 void test_continueOutsideOfLoop_continueInForStatement() { |
| 826 parse4("parseForStatement", "for (; x;) {continue;}"); | 810 createParser('for (; x;) {continue;}'); |
| 811 Statement statement = parser.parseForStatement(); |
| 812 expectNotNullIfNoErrors(statement); |
| 813 listener.assertNoErrors(); |
| 827 } | 814 } |
| 828 | 815 |
| 829 void test_continueOutsideOfLoop_continueInIfStatement() { | 816 void test_continueOutsideOfLoop_continueInIfStatement() { |
| 830 parse4("parseIfStatement", "if (x) {continue;}", | 817 createParser('if (x) {continue;}'); |
| 831 [ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP]); | 818 IfStatement statement = parser.parseIfStatement(); |
| 819 expectNotNullIfNoErrors(statement); |
| 820 listener.assertErrorsWithCodes([ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP]); |
| 832 } | 821 } |
| 833 | 822 |
| 834 void test_continueOutsideOfLoop_continueInSwitchStatement() { | 823 void test_continueOutsideOfLoop_continueInSwitchStatement() { |
| 835 parse4("parseSwitchStatement", "switch (x) {case 1: continue a;}"); | 824 createParser('switch (x) {case 1: continue a;}'); |
| 825 SwitchStatement statement = parser.parseSwitchStatement(); |
| 826 expectNotNullIfNoErrors(statement); |
| 827 listener.assertNoErrors(); |
| 836 } | 828 } |
| 837 | 829 |
| 838 void test_continueOutsideOfLoop_continueInWhileStatement() { | 830 void test_continueOutsideOfLoop_continueInWhileStatement() { |
| 839 parse4("parseWhileStatement", "while (x) {continue;}"); | 831 createParser('while (x) {continue;}'); |
| 832 WhileStatement statement = parser.parseWhileStatement(); |
| 833 expectNotNullIfNoErrors(statement); |
| 834 listener.assertNoErrors(); |
| 840 } | 835 } |
| 841 | 836 |
| 842 void test_continueOutsideOfLoop_functionExpression_inALoop() { | 837 void test_continueOutsideOfLoop_functionExpression_inALoop() { |
| 843 ParserTestCase.parseStatement("for(; x;) {() {continue;};}", | 838 ParserTestCase.parseStatement("for(; x;) {() {continue;};}", |
| 844 [ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP]); | 839 [ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP]); |
| 845 } | 840 } |
| 846 | 841 |
| 847 void test_continueOutsideOfLoop_functionExpression_withALoop() { | 842 void test_continueOutsideOfLoop_functionExpression_withALoop() { |
| 848 ParserTestCase.parseStatement("() {for (; x;) {continue;}};"); | 843 ParserTestCase.parseStatement("() {for (; x;) {continue;}};"); |
| 849 } | 844 } |
| 850 | 845 |
| 851 void test_continueWithoutLabelInCase_error() { | 846 void test_continueWithoutLabelInCase_error() { |
| 852 parse4("parseSwitchStatement", "switch (x) {case 1: continue;}", | 847 createParser('switch (x) {case 1: continue;}'); |
| 848 SwitchStatement statement = parser.parseSwitchStatement(); |
| 849 expectNotNullIfNoErrors(statement); |
| 850 listener.assertErrorsWithCodes( |
| 853 [ParserErrorCode.CONTINUE_WITHOUT_LABEL_IN_CASE]); | 851 [ParserErrorCode.CONTINUE_WITHOUT_LABEL_IN_CASE]); |
| 854 } | 852 } |
| 855 | 853 |
| 856 void test_continueWithoutLabelInCase_noError() { | 854 void test_continueWithoutLabelInCase_noError() { |
| 857 parse4("parseSwitchStatement", "switch (x) {case 1: continue a;}"); | 855 createParser('switch (x) {case 1: continue a;}'); |
| 856 SwitchStatement statement = parser.parseSwitchStatement(); |
| 857 expectNotNullIfNoErrors(statement); |
| 858 listener.assertNoErrors(); |
| 858 } | 859 } |
| 859 | 860 |
| 860 void test_continueWithoutLabelInCase_noError_switchInLoop() { | 861 void test_continueWithoutLabelInCase_noError_switchInLoop() { |
| 861 parse4( | 862 createParser('while (a) { switch (b) {default: continue;}}'); |
| 862 "parseWhileStatement", "while (a) { switch (b) {default: continue;}}"); | 863 WhileStatement statement = parser.parseWhileStatement(); |
| 864 expectNotNullIfNoErrors(statement); |
| 865 listener.assertNoErrors(); |
| 863 } | 866 } |
| 864 | 867 |
| 865 void test_deprecatedClassTypeAlias() { | 868 void test_deprecatedClassTypeAlias() { |
| 866 ParserTestCase.parseCompilationUnit( | 869 ParserTestCase.parseCompilationUnit( |
| 867 "typedef C = S with M;", [ParserErrorCode.DEPRECATED_CLASS_TYPE_ALIAS]); | 870 "typedef C = S with M;", [ParserErrorCode.DEPRECATED_CLASS_TYPE_ALIAS]); |
| 868 } | 871 } |
| 869 | 872 |
| 870 void test_deprecatedClassTypeAlias_withGeneric() { | 873 void test_deprecatedClassTypeAlias_withGeneric() { |
| 871 ParserTestCase.parseCompilationUnit("typedef C<T> = S<T> with M;", | 874 ParserTestCase.parseCompilationUnit("typedef C<T> = S<T> with M;", |
| 872 [ParserErrorCode.DEPRECATED_CLASS_TYPE_ALIAS]); | 875 [ParserErrorCode.DEPRECATED_CLASS_TYPE_ALIAS]); |
| 873 } | 876 } |
| 874 | 877 |
| 875 void test_directiveAfterDeclaration_classBeforeDirective() { | 878 void test_directiveAfterDeclaration_classBeforeDirective() { |
| 876 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 879 CompilationUnit unit = ParserTestCase.parseCompilationUnit( |
| 877 "class Foo{} library l;", | 880 "class Foo{} library l;", |
| 878 [ParserErrorCode.DIRECTIVE_AFTER_DECLARATION]); | 881 [ParserErrorCode.DIRECTIVE_AFTER_DECLARATION]); |
| 879 expect(unit, isNotNull); | 882 expect(unit, isNotNull); |
| 880 } | 883 } |
| 881 | 884 |
| 882 void test_directiveAfterDeclaration_classBetweenDirectives() { | 885 void test_directiveAfterDeclaration_classBetweenDirectives() { |
| 883 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 886 CompilationUnit unit = ParserTestCase.parseCompilationUnit( |
| 884 "library l;\nclass Foo{}\npart 'a.dart';", | 887 "library l;\nclass Foo{}\npart 'a.dart';", |
| 885 [ParserErrorCode.DIRECTIVE_AFTER_DECLARATION]); | 888 [ParserErrorCode.DIRECTIVE_AFTER_DECLARATION]); |
| 886 expect(unit, isNotNull); | 889 expect(unit, isNotNull); |
| 887 } | 890 } |
| 888 | 891 |
| 889 void test_duplicatedModifier_const() { | 892 void test_duplicatedModifier_const() { |
| 890 parse3("parseClassMember", <Object>["C"], "const const m;", | 893 createParser('const const m;'); |
| 891 [ParserErrorCode.DUPLICATED_MODIFIER]); | 894 ClassMember member = parser.parseClassMember('C'); |
| 895 expectNotNullIfNoErrors(member); |
| 896 listener.assertErrorsWithCodes([ParserErrorCode.DUPLICATED_MODIFIER]); |
| 892 } | 897 } |
| 893 | 898 |
| 894 void test_duplicatedModifier_external() { | 899 void test_duplicatedModifier_external() { |
| 895 parse3("parseClassMember", <Object>["C"], "external external f();", | 900 createParser('external external f();'); |
| 896 [ParserErrorCode.DUPLICATED_MODIFIER]); | 901 ClassMember member = parser.parseClassMember('C'); |
| 902 expectNotNullIfNoErrors(member); |
| 903 listener.assertErrorsWithCodes([ParserErrorCode.DUPLICATED_MODIFIER]); |
| 897 } | 904 } |
| 898 | 905 |
| 899 void test_duplicatedModifier_factory() { | 906 void test_duplicatedModifier_factory() { |
| 900 parse3("parseClassMember", <Object>["C"], "factory factory C() {}", | 907 createParser('factory factory C() {}'); |
| 901 [ParserErrorCode.DUPLICATED_MODIFIER]); | 908 ClassMember member = parser.parseClassMember('C'); |
| 909 expectNotNullIfNoErrors(member); |
| 910 listener.assertErrorsWithCodes([ParserErrorCode.DUPLICATED_MODIFIER]); |
| 902 } | 911 } |
| 903 | 912 |
| 904 void test_duplicatedModifier_final() { | 913 void test_duplicatedModifier_final() { |
| 905 parse3("parseClassMember", <Object>["C"], "final final m;", | 914 createParser('final final m;'); |
| 906 [ParserErrorCode.DUPLICATED_MODIFIER]); | 915 ClassMember member = parser.parseClassMember('C'); |
| 916 expectNotNullIfNoErrors(member); |
| 917 listener.assertErrorsWithCodes([ParserErrorCode.DUPLICATED_MODIFIER]); |
| 907 } | 918 } |
| 908 | 919 |
| 909 void test_duplicatedModifier_static() { | 920 void test_duplicatedModifier_static() { |
| 910 parse3("parseClassMember", <Object>["C"], "static static var m;", | 921 createParser('static static var m;'); |
| 911 [ParserErrorCode.DUPLICATED_MODIFIER]); | 922 ClassMember member = parser.parseClassMember('C'); |
| 923 expectNotNullIfNoErrors(member); |
| 924 listener.assertErrorsWithCodes([ParserErrorCode.DUPLICATED_MODIFIER]); |
| 912 } | 925 } |
| 913 | 926 |
| 914 void test_duplicatedModifier_var() { | 927 void test_duplicatedModifier_var() { |
| 915 parse3("parseClassMember", <Object>["C"], "var var m;", | 928 createParser('var var m;'); |
| 916 [ParserErrorCode.DUPLICATED_MODIFIER]); | 929 ClassMember member = parser.parseClassMember('C'); |
| 930 expectNotNullIfNoErrors(member); |
| 931 listener.assertErrorsWithCodes([ParserErrorCode.DUPLICATED_MODIFIER]); |
| 917 } | 932 } |
| 918 | 933 |
| 919 void test_duplicateLabelInSwitchStatement() { | 934 void test_duplicateLabelInSwitchStatement() { |
| 920 parse4( | 935 createParser('switch (e) {l1: case 0: break; l1: case 1: break;}'); |
| 921 "parseSwitchStatement", | 936 SwitchStatement statement = parser.parseSwitchStatement(); |
| 922 "switch (e) {l1: case 0: break; l1: case 1: break;}", | 937 expectNotNullIfNoErrors(statement); |
| 938 listener.assertErrorsWithCodes( |
| 923 [ParserErrorCode.DUPLICATE_LABEL_IN_SWITCH_STATEMENT]); | 939 [ParserErrorCode.DUPLICATE_LABEL_IN_SWITCH_STATEMENT]); |
| 924 } | 940 } |
| 925 | 941 |
| 926 void test_emptyEnumBody() { | 942 void test_emptyEnumBody() { |
| 927 parse3("parseEnumDeclaration", <Object>[emptyCommentAndMetadata()], | 943 createParser('enum E {}'); |
| 928 "enum E {}", [ParserErrorCode.EMPTY_ENUM_BODY]); | 944 EnumDeclaration declaration = |
| 945 parser.parseEnumDeclaration(emptyCommentAndMetadata()); |
| 946 expectNotNullIfNoErrors(declaration); |
| 947 listener.assertErrorsWithCodes([ParserErrorCode.EMPTY_ENUM_BODY]); |
| 929 } | 948 } |
| 930 | 949 |
| 931 void test_enumInClass() { | 950 void test_enumInClass() { |
| 932 ParserTestCase.parseCompilationUnit( | 951 ParserTestCase.parseCompilationUnit( |
| 933 r''' | 952 r''' |
| 934 class Foo { | 953 class Foo { |
| 935 enum Bar { | 954 enum Bar { |
| 936 Bar1, Bar2, Bar3 | 955 Bar1, Bar2, Bar3 |
| 937 } | 956 } |
| 938 } | 957 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 949 parseExpression( | 968 parseExpression( |
| 950 "1 == 2 != 3", [ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND]); | 969 "1 == 2 != 3", [ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND]); |
| 951 } | 970 } |
| 952 | 971 |
| 953 void test_equalityCannotBeEqualityOperand_neq_eq() { | 972 void test_equalityCannotBeEqualityOperand_neq_eq() { |
| 954 parseExpression( | 973 parseExpression( |
| 955 "1 != 2 == 3", [ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND]); | 974 "1 != 2 == 3", [ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND]); |
| 956 } | 975 } |
| 957 | 976 |
| 958 void test_expectedCaseOrDefault() { | 977 void test_expectedCaseOrDefault() { |
| 959 parse4("parseSwitchStatement", "switch (e) {break;}", | 978 createParser('switch (e) {break;}'); |
| 960 [ParserErrorCode.EXPECTED_CASE_OR_DEFAULT]); | 979 SwitchStatement statement = parser.parseSwitchStatement(); |
| 980 expectNotNullIfNoErrors(statement); |
| 981 listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_CASE_OR_DEFAULT]); |
| 961 } | 982 } |
| 962 | 983 |
| 963 void test_expectedClassMember_inClass_afterType() { | 984 void test_expectedClassMember_inClass_afterType() { |
| 964 parse3("parseClassMember", <Object>["C"], "heart 2 heart", | 985 createParser('heart 2 heart'); |
| 965 [ParserErrorCode.EXPECTED_CLASS_MEMBER]); | 986 ClassMember member = parser.parseClassMember('C'); |
| 987 expectNotNullIfNoErrors(member); |
| 988 listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_CLASS_MEMBER]); |
| 966 } | 989 } |
| 967 | 990 |
| 968 void test_expectedClassMember_inClass_beforeType() { | 991 void test_expectedClassMember_inClass_beforeType() { |
| 969 parse3("parseClassMember", <Object>["C"], "4 score", | 992 createParser('4 score'); |
| 970 [ParserErrorCode.EXPECTED_CLASS_MEMBER]); | 993 ClassMember member = parser.parseClassMember('C'); |
| 994 expectNotNullIfNoErrors(member); |
| 995 listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_CLASS_MEMBER]); |
| 971 } | 996 } |
| 972 | 997 |
| 973 void test_expectedExecutable_inClass_afterVoid() { | 998 void test_expectedExecutable_inClass_afterVoid() { |
| 974 parse3("parseClassMember", <Object>["C"], "void 2 void", | 999 createParser('void 2 void'); |
| 975 [ParserErrorCode.EXPECTED_EXECUTABLE]); | 1000 ClassMember member = parser.parseClassMember('C'); |
| 1001 expectNotNullIfNoErrors(member); |
| 1002 listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_EXECUTABLE]); |
| 976 } | 1003 } |
| 977 | 1004 |
| 978 void test_expectedExecutable_topLevel_afterType() { | 1005 void test_expectedExecutable_topLevel_afterType() { |
| 979 parse3("parseCompilationUnitMember", <Object>[emptyCommentAndMetadata()], | 1006 createParser('heart 2 heart'); |
| 980 "heart 2 heart", [ParserErrorCode.EXPECTED_EXECUTABLE]); | 1007 CompilationUnitMember member = |
| 1008 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 1009 expectNotNullIfNoErrors(member); |
| 1010 listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_EXECUTABLE]); |
| 981 } | 1011 } |
| 982 | 1012 |
| 983 void test_expectedExecutable_topLevel_afterVoid() { | 1013 void test_expectedExecutable_topLevel_afterVoid() { |
| 984 parse3("parseCompilationUnitMember", <Object>[emptyCommentAndMetadata()], | 1014 createParser('void 2 void'); |
| 985 "void 2 void", [ParserErrorCode.EXPECTED_EXECUTABLE]); | 1015 CompilationUnitMember member = |
| 1016 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 1017 expectNotNullIfNoErrors(member); |
| 1018 listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_EXECUTABLE]); |
| 986 } | 1019 } |
| 987 | 1020 |
| 988 void test_expectedExecutable_topLevel_beforeType() { | 1021 void test_expectedExecutable_topLevel_beforeType() { |
| 989 parse3("parseCompilationUnitMember", <Object>[emptyCommentAndMetadata()], | 1022 createParser('4 score'); |
| 990 "4 score", [ParserErrorCode.EXPECTED_EXECUTABLE]); | 1023 CompilationUnitMember member = |
| 1024 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 1025 expectNotNullIfNoErrors(member); |
| 1026 listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_EXECUTABLE]); |
| 991 } | 1027 } |
| 992 | 1028 |
| 993 void test_expectedExecutable_topLevel_eof() { | 1029 void test_expectedExecutable_topLevel_eof() { |
| 994 parse2( | 1030 createParser('x'); |
| 995 "parseCompilationUnitMember", | 1031 CompilationUnitMember member = |
| 996 <Object>[emptyCommentAndMetadata()], | 1032 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 997 "x", | 1033 expectNotNullIfNoErrors(member); |
| 1034 listener.assertErrors( |
| 998 [new AnalysisError(null, 0, 1, ParserErrorCode.EXPECTED_EXECUTABLE)]); | 1035 [new AnalysisError(null, 0, 1, ParserErrorCode.EXPECTED_EXECUTABLE)]); |
| 999 } | 1036 } |
| 1000 | 1037 |
| 1001 void test_expectedInterpolationIdentifier() { | 1038 void test_expectedInterpolationIdentifier() { |
| 1002 parse4( | 1039 createParser("'\$x\$'"); |
| 1003 "parseStringLiteral", "'\$x\$'", [ParserErrorCode.MISSING_IDENTIFIER]); | 1040 StringLiteral literal = parser.parseStringLiteral(); |
| 1041 expectNotNullIfNoErrors(literal); |
| 1042 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| 1004 } | 1043 } |
| 1005 | 1044 |
| 1006 void test_expectedInterpolationIdentifier_emptyString() { | 1045 void test_expectedInterpolationIdentifier_emptyString() { |
| 1007 // The scanner inserts an empty string token between the two $'s; we need to | 1046 // The scanner inserts an empty string token between the two $'s; we need to |
| 1008 // make sure that the MISSING_IDENTIFIER error that is generated has a | 1047 // make sure that the MISSING_IDENTIFIER error that is generated has a |
| 1009 // nonzero width so that it will show up in the editor UI. | 1048 // nonzero width so that it will show up in the editor UI. |
| 1010 parse2("parseStringLiteral", <Object>[], "'\$\$foo'", | 1049 createParser("'\$\$foo'"); |
| 1050 StringLiteral literal = parser.parseStringLiteral(); |
| 1051 expectNotNullIfNoErrors(literal); |
| 1052 listener.assertErrors( |
| 1011 [new AnalysisError(null, 2, 1, ParserErrorCode.MISSING_IDENTIFIER)]); | 1053 [new AnalysisError(null, 2, 1, ParserErrorCode.MISSING_IDENTIFIER)]); |
| 1012 } | 1054 } |
| 1013 | 1055 |
| 1056 @failingTest |
| 1057 void test_expectedListOrMapLiteral() { |
| 1058 // It isn't clear that this test can ever pass. The parser is currently |
| 1059 // create a synthetic list literal in this case, but isSynthetic() isn't |
| 1060 // overridden for ListLiteral. The problem is that the synthetic list |
| 1061 // literals that are being created are not always zero length (because they |
| 1062 // could have type parameters), which violates the contract of |
| 1063 // isSynthetic(). |
| 1064 createParser('1'); |
| 1065 TypedLiteral literal = parser.parseListOrMapLiteral(null); |
| 1066 expectNotNullIfNoErrors(literal); |
| 1067 listener |
| 1068 .assertErrorsWithCodes([ParserErrorCode.EXPECTED_LIST_OR_MAP_LITERAL]); |
| 1069 expect(literal.isSynthetic, isTrue); |
| 1070 } |
| 1071 |
| 1014 void test_expectedStringLiteral() { | 1072 void test_expectedStringLiteral() { |
| 1015 StringLiteral expression = parse4( | 1073 createParser('1'); |
| 1016 "parseStringLiteral", "1", [ParserErrorCode.EXPECTED_STRING_LITERAL]); | 1074 StringLiteral literal = parser.parseStringLiteral(); |
| 1017 expect(expression.isSynthetic, isTrue); | 1075 expectNotNullIfNoErrors(literal); |
| 1076 listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_STRING_LITERAL]); |
| 1077 expect(literal.isSynthetic, isTrue); |
| 1018 } | 1078 } |
| 1019 | 1079 |
| 1020 void test_expectedToken_commaMissingInArgumentList() { | 1080 void test_expectedToken_commaMissingInArgumentList() { |
| 1021 parse4("parseArgumentList", "(x, y z)", [ParserErrorCode.EXPECTED_TOKEN]); | 1081 createParser('(x, y z)'); |
| 1082 ArgumentList list = parser.parseArgumentList(); |
| 1083 expectNotNullIfNoErrors(list); |
| 1084 listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_TOKEN]); |
| 1022 } | 1085 } |
| 1023 | 1086 |
| 1024 void test_expectedToken_parseStatement_afterVoid() { | 1087 void test_expectedToken_parseStatement_afterVoid() { |
| 1025 ParserTestCase.parseStatement("void}", | 1088 ParserTestCase.parseStatement("void}", |
| 1026 [ParserErrorCode.EXPECTED_TOKEN, ParserErrorCode.MISSING_IDENTIFIER]); | 1089 [ParserErrorCode.EXPECTED_TOKEN, ParserErrorCode.MISSING_IDENTIFIER]); |
| 1027 } | 1090 } |
| 1028 | 1091 |
| 1029 void test_expectedToken_semicolonAfterClass() { | 1092 void test_expectedToken_semicolonAfterClass() { |
| 1030 Token token = TokenFactory.tokenFromKeyword(Keyword.CLASS); | 1093 Token token = TokenFactory.tokenFromKeyword(Keyword.CLASS); |
| 1031 parse3( | 1094 createParser('A = B with C'); |
| 1032 "parseClassTypeAlias", | 1095 ClassTypeAlias declaration = |
| 1033 <Object>[emptyCommentAndMetadata(), null, token], | 1096 parser.parseClassTypeAlias(emptyCommentAndMetadata(), null, token); |
| 1034 "A = B with C", | 1097 expectNotNullIfNoErrors(declaration); |
| 1035 [ParserErrorCode.EXPECTED_TOKEN]); | 1098 listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_TOKEN]); |
| 1036 } | 1099 } |
| 1037 | 1100 |
| 1038 void test_expectedToken_semicolonMissingAfterExport() { | 1101 void test_expectedToken_semicolonMissingAfterExport() { |
| 1039 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 1102 CompilationUnit unit = ParserTestCase.parseCompilationUnit( |
| 1040 "export '' class A {}", [ParserErrorCode.EXPECTED_TOKEN]); | 1103 "export '' class A {}", [ParserErrorCode.EXPECTED_TOKEN]); |
| 1041 ExportDirective directive = unit.directives[0] as ExportDirective; | 1104 ExportDirective directive = unit.directives[0] as ExportDirective; |
| 1042 Token semicolon = directive.semicolon; | 1105 Token semicolon = directive.semicolon; |
| 1043 expect(semicolon, isNotNull); | 1106 expect(semicolon, isNotNull); |
| 1044 expect(semicolon.isSynthetic, isTrue); | 1107 expect(semicolon.isSynthetic, isTrue); |
| 1045 } | 1108 } |
| 1046 | 1109 |
| 1047 void test_expectedToken_semicolonMissingAfterExpression() { | 1110 void test_expectedToken_semicolonMissingAfterExpression() { |
| 1048 ParserTestCase.parseStatement("x", [ParserErrorCode.EXPECTED_TOKEN]); | 1111 ParserTestCase.parseStatement("x", [ParserErrorCode.EXPECTED_TOKEN]); |
| 1049 } | 1112 } |
| 1050 | 1113 |
| 1051 void test_expectedToken_semicolonMissingAfterImport() { | 1114 void test_expectedToken_semicolonMissingAfterImport() { |
| 1052 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 1115 CompilationUnit unit = ParserTestCase.parseCompilationUnit( |
| 1053 "import '' class A {}", [ParserErrorCode.EXPECTED_TOKEN]); | 1116 "import '' class A {}", [ParserErrorCode.EXPECTED_TOKEN]); |
| 1054 ImportDirective directive = unit.directives[0] as ImportDirective; | 1117 ImportDirective directive = unit.directives[0] as ImportDirective; |
| 1055 Token semicolon = directive.semicolon; | 1118 Token semicolon = directive.semicolon; |
| 1056 expect(semicolon, isNotNull); | 1119 expect(semicolon, isNotNull); |
| 1057 expect(semicolon.isSynthetic, isTrue); | 1120 expect(semicolon.isSynthetic, isTrue); |
| 1058 } | 1121 } |
| 1059 | 1122 |
| 1060 void test_expectedToken_whileMissingInDoStatement() { | 1123 void test_expectedToken_whileMissingInDoStatement() { |
| 1061 ParserTestCase.parseStatement( | 1124 ParserTestCase |
| 1062 "do {} (x);", [ParserErrorCode.EXPECTED_TOKEN]); | 1125 .parseStatement("do {} (x);", [ParserErrorCode.EXPECTED_TOKEN]); |
| 1063 } | 1126 } |
| 1064 | 1127 |
| 1065 void test_expectedTypeName_is() { | 1128 void test_expectedTypeName_is() { |
| 1066 parseExpression("x is", [ParserErrorCode.EXPECTED_TYPE_NAME]); | 1129 parseExpression("x is", [ParserErrorCode.EXPECTED_TYPE_NAME]); |
| 1067 } | 1130 } |
| 1068 | 1131 |
| 1069 void test_exportDirectiveAfterPartDirective() { | 1132 void test_exportDirectiveAfterPartDirective() { |
| 1070 ParserTestCase.parseCompilationUnit("part 'a.dart'; export 'b.dart';", | 1133 ParserTestCase.parseCompilationUnit("part 'a.dart'; export 'b.dart';", |
| 1071 [ParserErrorCode.EXPORT_DIRECTIVE_AFTER_PART_DIRECTIVE]); | 1134 [ParserErrorCode.EXPORT_DIRECTIVE_AFTER_PART_DIRECTIVE]); |
| 1072 } | 1135 } |
| 1073 | 1136 |
| 1074 void test_externalAfterConst() { | 1137 void test_externalAfterConst() { |
| 1075 parse3("parseClassMember", <Object>["C"], "const external C();", | 1138 createParser('const external C();'); |
| 1076 [ParserErrorCode.EXTERNAL_AFTER_CONST]); | 1139 ClassMember member = parser.parseClassMember('C'); |
| 1140 expectNotNullIfNoErrors(member); |
| 1141 listener.assertErrorsWithCodes([ParserErrorCode.EXTERNAL_AFTER_CONST]); |
| 1077 } | 1142 } |
| 1078 | 1143 |
| 1079 void test_externalAfterFactory() { | 1144 void test_externalAfterFactory() { |
| 1080 parse3("parseClassMember", <Object>["C"], "factory external C();", | 1145 createParser('factory external C();'); |
| 1081 [ParserErrorCode.EXTERNAL_AFTER_FACTORY]); | 1146 ClassMember member = parser.parseClassMember('C'); |
| 1147 expectNotNullIfNoErrors(member); |
| 1148 listener.assertErrorsWithCodes([ParserErrorCode.EXTERNAL_AFTER_FACTORY]); |
| 1082 } | 1149 } |
| 1083 | 1150 |
| 1084 void test_externalAfterStatic() { | 1151 void test_externalAfterStatic() { |
| 1085 parse3("parseClassMember", <Object>["C"], "static external int m();", | 1152 createParser('static external int m();'); |
| 1086 [ParserErrorCode.EXTERNAL_AFTER_STATIC]); | 1153 ClassMember member = parser.parseClassMember('C'); |
| 1154 expectNotNullIfNoErrors(member); |
| 1155 listener.assertErrorsWithCodes([ParserErrorCode.EXTERNAL_AFTER_STATIC]); |
| 1087 } | 1156 } |
| 1088 | 1157 |
| 1089 void test_externalClass() { | 1158 void test_externalClass() { |
| 1090 ParserTestCase.parseCompilationUnit( | 1159 ParserTestCase.parseCompilationUnit( |
| 1091 "external class C {}", [ParserErrorCode.EXTERNAL_CLASS]); | 1160 "external class C {}", [ParserErrorCode.EXTERNAL_CLASS]); |
| 1092 } | 1161 } |
| 1093 | 1162 |
| 1094 void test_externalConstructorWithBody_factory() { | 1163 void test_externalConstructorWithBody_factory() { |
| 1095 parse3("parseClassMember", <Object>["C"], "external factory C() {}", | 1164 createParser('external factory C() {}'); |
| 1165 ClassMember member = parser.parseClassMember('C'); |
| 1166 expectNotNullIfNoErrors(member); |
| 1167 listener.assertErrorsWithCodes( |
| 1096 [ParserErrorCode.EXTERNAL_CONSTRUCTOR_WITH_BODY]); | 1168 [ParserErrorCode.EXTERNAL_CONSTRUCTOR_WITH_BODY]); |
| 1097 } | 1169 } |
| 1098 | 1170 |
| 1099 void test_externalConstructorWithBody_named() { | 1171 void test_externalConstructorWithBody_named() { |
| 1100 parse3("parseClassMember", <Object>["C"], "external C.c() {}", | 1172 createParser('external C.c() {}'); |
| 1173 ClassMember member = parser.parseClassMember('C'); |
| 1174 expectNotNullIfNoErrors(member); |
| 1175 listener.assertErrorsWithCodes( |
| 1101 [ParserErrorCode.EXTERNAL_CONSTRUCTOR_WITH_BODY]); | 1176 [ParserErrorCode.EXTERNAL_CONSTRUCTOR_WITH_BODY]); |
| 1102 } | 1177 } |
| 1103 | 1178 |
| 1104 void test_externalEnum() { | 1179 void test_externalEnum() { |
| 1105 ParserTestCase.parseCompilationUnit( | 1180 ParserTestCase.parseCompilationUnit( |
| 1106 "external enum E {ONE}", [ParserErrorCode.EXTERNAL_ENUM]); | 1181 "external enum E {ONE}", [ParserErrorCode.EXTERNAL_ENUM]); |
| 1107 } | 1182 } |
| 1108 | 1183 |
| 1109 void test_externalField_const() { | 1184 void test_externalField_const() { |
| 1110 parse3("parseClassMember", <Object>["C"], "external const A f;", | 1185 createParser('external const A f;'); |
| 1111 [ParserErrorCode.EXTERNAL_FIELD]); | 1186 ClassMember member = parser.parseClassMember('C'); |
| 1187 expectNotNullIfNoErrors(member); |
| 1188 listener.assertErrorsWithCodes([ParserErrorCode.EXTERNAL_FIELD]); |
| 1112 } | 1189 } |
| 1113 | 1190 |
| 1114 void test_externalField_final() { | 1191 void test_externalField_final() { |
| 1115 parse3("parseClassMember", <Object>["C"], "external final A f;", | 1192 createParser('external final A f;'); |
| 1116 [ParserErrorCode.EXTERNAL_FIELD]); | 1193 ClassMember member = parser.parseClassMember('C'); |
| 1194 expectNotNullIfNoErrors(member); |
| 1195 listener.assertErrorsWithCodes([ParserErrorCode.EXTERNAL_FIELD]); |
| 1117 } | 1196 } |
| 1118 | 1197 |
| 1119 void test_externalField_static() { | 1198 void test_externalField_static() { |
| 1120 parse3("parseClassMember", <Object>["C"], "external static A f;", | 1199 createParser('external static A f;'); |
| 1121 [ParserErrorCode.EXTERNAL_FIELD]); | 1200 ClassMember member = parser.parseClassMember('C'); |
| 1201 expectNotNullIfNoErrors(member); |
| 1202 listener.assertErrorsWithCodes([ParserErrorCode.EXTERNAL_FIELD]); |
| 1122 } | 1203 } |
| 1123 | 1204 |
| 1124 void test_externalField_typed() { | 1205 void test_externalField_typed() { |
| 1125 parse3("parseClassMember", <Object>["C"], "external A f;", | 1206 createParser('external A f;'); |
| 1126 [ParserErrorCode.EXTERNAL_FIELD]); | 1207 ClassMember member = parser.parseClassMember('C'); |
| 1208 expectNotNullIfNoErrors(member); |
| 1209 listener.assertErrorsWithCodes([ParserErrorCode.EXTERNAL_FIELD]); |
| 1127 } | 1210 } |
| 1128 | 1211 |
| 1129 void test_externalField_untyped() { | 1212 void test_externalField_untyped() { |
| 1130 parse3("parseClassMember", <Object>["C"], "external var f;", | 1213 createParser('external var f;'); |
| 1131 [ParserErrorCode.EXTERNAL_FIELD]); | 1214 ClassMember member = parser.parseClassMember('C'); |
| 1215 expectNotNullIfNoErrors(member); |
| 1216 listener.assertErrorsWithCodes([ParserErrorCode.EXTERNAL_FIELD]); |
| 1132 } | 1217 } |
| 1133 | 1218 |
| 1134 void test_externalGetterWithBody() { | 1219 void test_externalGetterWithBody() { |
| 1135 parse3("parseClassMember", <Object>["C"], "external int get x {}", | 1220 createParser('external int get x {}'); |
| 1136 [ParserErrorCode.EXTERNAL_GETTER_WITH_BODY]); | 1221 ClassMember member = parser.parseClassMember('C'); |
| 1222 expectNotNullIfNoErrors(member); |
| 1223 listener.assertErrorsWithCodes([ParserErrorCode.EXTERNAL_GETTER_WITH_BODY]); |
| 1137 } | 1224 } |
| 1138 | 1225 |
| 1139 void test_externalMethodWithBody() { | 1226 void test_externalMethodWithBody() { |
| 1140 parse3("parseClassMember", <Object>["C"], "external m() {}", | 1227 createParser('external m() {}'); |
| 1141 [ParserErrorCode.EXTERNAL_METHOD_WITH_BODY]); | 1228 ClassMember member = parser.parseClassMember('C'); |
| 1229 expectNotNullIfNoErrors(member); |
| 1230 listener.assertErrorsWithCodes([ParserErrorCode.EXTERNAL_METHOD_WITH_BODY]); |
| 1142 } | 1231 } |
| 1143 | 1232 |
| 1144 void test_externalOperatorWithBody() { | 1233 void test_externalOperatorWithBody() { |
| 1145 parse3( | 1234 createParser('external operator +(int value) {}'); |
| 1146 "parseClassMember", | 1235 ClassMember member = parser.parseClassMember('C'); |
| 1147 <Object>["C"], | 1236 expectNotNullIfNoErrors(member); |
| 1148 "external operator +(int value) {}", | 1237 listener |
| 1149 [ParserErrorCode.EXTERNAL_OPERATOR_WITH_BODY]); | 1238 .assertErrorsWithCodes([ParserErrorCode.EXTERNAL_OPERATOR_WITH_BODY]); |
| 1150 } | 1239 } |
| 1151 | 1240 |
| 1152 void test_externalSetterWithBody() { | 1241 void test_externalSetterWithBody() { |
| 1153 parse3("parseClassMember", <Object>["C"], "external set x(int value) {}", | 1242 createParser('external set x(int value) {}'); |
| 1154 [ParserErrorCode.EXTERNAL_SETTER_WITH_BODY]); | 1243 ClassMember member = parser.parseClassMember('C'); |
| 1244 expectNotNullIfNoErrors(member); |
| 1245 listener.assertErrorsWithCodes([ParserErrorCode.EXTERNAL_SETTER_WITH_BODY]); |
| 1155 } | 1246 } |
| 1156 | 1247 |
| 1157 void test_externalTypedef() { | 1248 void test_externalTypedef() { |
| 1158 ParserTestCase.parseCompilationUnit( | 1249 ParserTestCase.parseCompilationUnit( |
| 1159 "external typedef F();", [ParserErrorCode.EXTERNAL_TYPEDEF]); | 1250 "external typedef F();", [ParserErrorCode.EXTERNAL_TYPEDEF]); |
| 1160 } | 1251 } |
| 1161 | 1252 |
| 1253 void test_extraCommaInParameterList() { |
| 1254 createParser('(int a, , int b)'); |
| 1255 FormalParameterList list = parser.parseFormalParameterList(); |
| 1256 expectNotNullIfNoErrors(list); |
| 1257 listener.assertErrorsWithCodes( |
| 1258 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); |
| 1259 } |
| 1260 |
| 1261 void test_extraCommaTrailingNamedParameterGroup() { |
| 1262 createParser('({int b},)'); |
| 1263 FormalParameterList list = parser.parseFormalParameterList(); |
| 1264 expectNotNullIfNoErrors(list); |
| 1265 listener.assertErrorsWithCodes([ |
| 1266 ParserErrorCode.MISSING_IDENTIFIER, |
| 1267 ParserErrorCode.NORMAL_BEFORE_OPTIONAL_PARAMETERS |
| 1268 ]); |
| 1269 } |
| 1270 |
| 1271 void test_extraCommaTrailingPositionalParameterGroup() { |
| 1272 createParser('([int b],)'); |
| 1273 FormalParameterList list = parser.parseFormalParameterList(); |
| 1274 expectNotNullIfNoErrors(list); |
| 1275 listener.assertErrorsWithCodes([ |
| 1276 ParserErrorCode.MISSING_IDENTIFIER, |
| 1277 ParserErrorCode.NORMAL_BEFORE_OPTIONAL_PARAMETERS |
| 1278 ]); |
| 1279 } |
| 1280 |
| 1281 void test_extraTrailingCommaInParameterList() { |
| 1282 createParser('(a,,)'); |
| 1283 FormalParameterList list = parser.parseFormalParameterList(); |
| 1284 expectNotNullIfNoErrors(list); |
| 1285 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| 1286 } |
| 1287 |
| 1162 void test_factoryTopLevelDeclaration_class() { | 1288 void test_factoryTopLevelDeclaration_class() { |
| 1163 ParserTestCase.parseCompilationUnit( | 1289 ParserTestCase.parseCompilationUnit( |
| 1164 "factory class C {}", [ParserErrorCode.FACTORY_TOP_LEVEL_DECLARATION]); | 1290 "factory class C {}", [ParserErrorCode.FACTORY_TOP_LEVEL_DECLARATION]); |
| 1165 } | 1291 } |
| 1166 | 1292 |
| 1167 void test_factoryTopLevelDeclaration_typedef() { | 1293 void test_factoryTopLevelDeclaration_typedef() { |
| 1168 ParserTestCase.parseCompilationUnit("factory typedef F();", | 1294 ParserTestCase.parseCompilationUnit("factory typedef F();", |
| 1169 [ParserErrorCode.FACTORY_TOP_LEVEL_DECLARATION]); | 1295 [ParserErrorCode.FACTORY_TOP_LEVEL_DECLARATION]); |
| 1170 } | 1296 } |
| 1171 | 1297 |
| 1172 void test_factoryWithInitializers() { | 1298 void test_factoryWithInitializers() { |
| 1173 parse3("parseClassMember", <Object>["C"], "factory C() : x = 3 {}", | 1299 createParser('factory C() : x = 3 {}'); |
| 1174 [ParserErrorCode.FACTORY_WITH_INITIALIZERS]); | 1300 ClassMember member = parser.parseClassMember('C'); |
| 1301 expectNotNullIfNoErrors(member); |
| 1302 listener.assertErrorsWithCodes([ParserErrorCode.FACTORY_WITH_INITIALIZERS]); |
| 1175 } | 1303 } |
| 1176 | 1304 |
| 1177 void test_factoryWithoutBody() { | 1305 void test_factoryWithoutBody() { |
| 1178 parse3("parseClassMember", <Object>["C"], "factory C();", | 1306 createParser('factory C();'); |
| 1179 [ParserErrorCode.FACTORY_WITHOUT_BODY]); | 1307 ClassMember member = parser.parseClassMember('C'); |
| 1308 expectNotNullIfNoErrors(member); |
| 1309 listener.assertErrorsWithCodes([ParserErrorCode.FACTORY_WITHOUT_BODY]); |
| 1180 } | 1310 } |
| 1181 | 1311 |
| 1182 void test_fieldInitializerOutsideConstructor() { | 1312 void test_fieldInitializerOutsideConstructor() { |
| 1183 parse3("parseClassMember", <Object>["C"], "void m(this.x);", | 1313 createParser('void m(this.x);'); |
| 1314 ClassMember member = parser.parseClassMember('C'); |
| 1315 expectNotNullIfNoErrors(member); |
| 1316 listener.assertErrorsWithCodes( |
| 1184 [ParserErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR]); | 1317 [ParserErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR]); |
| 1185 } | 1318 } |
| 1186 | 1319 |
| 1187 void test_finalAndVar() { | 1320 void test_finalAndVar() { |
| 1188 parse3("parseClassMember", <Object>["C"], "final var x;", | 1321 createParser('final var x;'); |
| 1189 [ParserErrorCode.FINAL_AND_VAR]); | 1322 ClassMember member = parser.parseClassMember('C'); |
| 1323 expectNotNullIfNoErrors(member); |
| 1324 listener.assertErrorsWithCodes([ParserErrorCode.FINAL_AND_VAR]); |
| 1190 } | 1325 } |
| 1191 | 1326 |
| 1192 void test_finalClass() { | 1327 void test_finalClass() { |
| 1193 ParserTestCase.parseCompilationUnit( | 1328 ParserTestCase.parseCompilationUnit( |
| 1194 "final class C {}", [ParserErrorCode.FINAL_CLASS]); | 1329 "final class C {}", [ParserErrorCode.FINAL_CLASS]); |
| 1195 } | 1330 } |
| 1196 | 1331 |
| 1197 void test_finalConstructor() { | 1332 void test_finalConstructor() { |
| 1198 parse3("parseClassMember", <Object>["C"], "final C() {}", | 1333 createParser('final C() {}'); |
| 1199 [ParserErrorCode.FINAL_CONSTRUCTOR]); | 1334 ClassMember member = parser.parseClassMember('C'); |
| 1335 expectNotNullIfNoErrors(member); |
| 1336 listener.assertErrorsWithCodes([ParserErrorCode.FINAL_CONSTRUCTOR]); |
| 1200 } | 1337 } |
| 1201 | 1338 |
| 1202 void test_finalEnum() { | 1339 void test_finalEnum() { |
| 1203 ParserTestCase.parseCompilationUnit( | 1340 ParserTestCase.parseCompilationUnit( |
| 1204 "final enum E {ONE}", [ParserErrorCode.FINAL_ENUM]); | 1341 "final enum E {ONE}", [ParserErrorCode.FINAL_ENUM]); |
| 1205 } | 1342 } |
| 1206 | 1343 |
| 1207 void test_finalMethod() { | 1344 void test_finalMethod() { |
| 1208 parse3("parseClassMember", <Object>["C"], "final int m() {}", | 1345 createParser('final int m() {}'); |
| 1209 [ParserErrorCode.FINAL_METHOD]); | 1346 ClassMember member = parser.parseClassMember('C'); |
| 1347 expectNotNullIfNoErrors(member); |
| 1348 listener.assertErrorsWithCodes([ParserErrorCode.FINAL_METHOD]); |
| 1210 } | 1349 } |
| 1211 | 1350 |
| 1212 void test_finalTypedef() { | 1351 void test_finalTypedef() { |
| 1213 ParserTestCase.parseCompilationUnit( | 1352 ParserTestCase.parseCompilationUnit( |
| 1214 "final typedef F();", [ParserErrorCode.FINAL_TYPEDEF]); | 1353 "final typedef F();", [ParserErrorCode.FINAL_TYPEDEF]); |
| 1215 } | 1354 } |
| 1216 | 1355 |
| 1217 void test_functionTypedParameter_const() { | 1356 void test_functionTypedParameter_const() { |
| 1218 ParserTestCase.parseCompilationUnit( | 1357 ParserTestCase.parseCompilationUnit( |
| 1219 "void f(const x()) {}", [ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR]); | 1358 "void f(const x()) {}", [ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR]); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1234 "get x { return _x; }", [ParserErrorCode.GETTER_IN_FUNCTION]); | 1373 "get x { return _x; }", [ParserErrorCode.GETTER_IN_FUNCTION]); |
| 1235 expect(statement.functionDeclaration.functionExpression.parameters, isNull); | 1374 expect(statement.functionDeclaration.functionExpression.parameters, isNull); |
| 1236 } | 1375 } |
| 1237 | 1376 |
| 1238 void test_getterInFunction_block_returnType() { | 1377 void test_getterInFunction_block_returnType() { |
| 1239 ParserTestCase.parseStatement( | 1378 ParserTestCase.parseStatement( |
| 1240 "int get x { return _x; }", [ParserErrorCode.GETTER_IN_FUNCTION]); | 1379 "int get x { return _x; }", [ParserErrorCode.GETTER_IN_FUNCTION]); |
| 1241 } | 1380 } |
| 1242 | 1381 |
| 1243 void test_getterInFunction_expression_noReturnType() { | 1382 void test_getterInFunction_expression_noReturnType() { |
| 1244 ParserTestCase.parseStatement( | 1383 ParserTestCase |
| 1245 "get x => _x;", [ParserErrorCode.GETTER_IN_FUNCTION]); | 1384 .parseStatement("get x => _x;", [ParserErrorCode.GETTER_IN_FUNCTION]); |
| 1246 } | 1385 } |
| 1247 | 1386 |
| 1248 void test_getterInFunction_expression_returnType() { | 1387 void test_getterInFunction_expression_returnType() { |
| 1249 ParserTestCase.parseStatement( | 1388 ParserTestCase.parseStatement( |
| 1250 "int get x => _x;", [ParserErrorCode.GETTER_IN_FUNCTION]); | 1389 "int get x => _x;", [ParserErrorCode.GETTER_IN_FUNCTION]); |
| 1251 } | 1390 } |
| 1252 | 1391 |
| 1253 void test_getterWithParameters() { | 1392 void test_getterWithParameters() { |
| 1254 parse3("parseClassMember", <Object>["C"], "int get x() {}", | 1393 createParser('int get x() {}'); |
| 1255 [ParserErrorCode.GETTER_WITH_PARAMETERS]); | 1394 ClassMember member = parser.parseClassMember('C'); |
| 1395 expectNotNullIfNoErrors(member); |
| 1396 listener.assertErrorsWithCodes([ParserErrorCode.GETTER_WITH_PARAMETERS]); |
| 1256 } | 1397 } |
| 1257 | 1398 |
| 1258 void test_illegalAssignmentToNonAssignable_postfix_minusMinus_literal() { | 1399 void test_illegalAssignmentToNonAssignable_postfix_minusMinus_literal() { |
| 1259 parseExpression( | 1400 parseExpression( |
| 1260 "0--", [ParserErrorCode.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE]); | 1401 "0--", [ParserErrorCode.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE]); |
| 1261 } | 1402 } |
| 1262 | 1403 |
| 1263 void test_illegalAssignmentToNonAssignable_postfix_plusPlus_literal() { | 1404 void test_illegalAssignmentToNonAssignable_postfix_plusPlus_literal() { |
| 1264 parseExpression( | 1405 parseExpression( |
| 1265 "0++", [ParserErrorCode.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE]); | 1406 "0++", [ParserErrorCode.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE]); |
| 1266 } | 1407 } |
| 1267 | 1408 |
| 1268 void test_illegalAssignmentToNonAssignable_postfix_plusPlus_parethesized() { | 1409 void test_illegalAssignmentToNonAssignable_postfix_plusPlus_parenthesized() { |
| 1269 parseExpression( | 1410 parseExpression( |
| 1270 "(x)++", [ParserErrorCode.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE]); | 1411 "(x)++", [ParserErrorCode.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE]); |
| 1271 } | 1412 } |
| 1272 | 1413 |
| 1273 void test_illegalAssignmentToNonAssignable_primarySelectorPostfix() { | 1414 void test_illegalAssignmentToNonAssignable_primarySelectorPostfix() { |
| 1274 parseExpression( | 1415 parseExpression( |
| 1275 "x(y)(z)++", [ParserErrorCode.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE]); | 1416 "x(y)(z)++", [ParserErrorCode.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE]); |
| 1276 } | 1417 } |
| 1277 | 1418 |
| 1278 void test_illegalAssignmentToNonAssignable_superAssigned() { | 1419 void test_illegalAssignmentToNonAssignable_superAssigned() { |
| 1279 // TODO(brianwilkerson) When the test | 1420 // TODO(brianwilkerson) When the test |
| 1280 // fail_illegalAssignmentToNonAssignable_superAssigned starts to pass, | 1421 // test_illegalAssignmentToNonAssignable_superAssigned_failing starts to pas
s, |
| 1281 // remove this test (there should only be one error generated, but we're | 1422 // remove this test (there should only be one error generated, but we're |
| 1282 // keeping this test until that time so that we can catch other forms of | 1423 // keeping this test until that time so that we can catch other forms of |
| 1283 // regressions). | 1424 // regressions). |
| 1284 parseExpression("super = x;", [ | 1425 parseExpression("super = x;", [ |
| 1285 ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR, | 1426 ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR, |
| 1286 ParserErrorCode.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE | 1427 ParserErrorCode.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE |
| 1287 ]); | 1428 ]); |
| 1288 } | 1429 } |
| 1289 | 1430 |
| 1431 @failingTest |
| 1432 void test_illegalAssignmentToNonAssignable_superAssigned_failing() { |
| 1433 // TODO(brianwilkerson) When this test starts to pass, remove the test |
| 1434 // test_illegalAssignmentToNonAssignable_superAssigned. |
| 1435 parseExpression( |
| 1436 "super = x;", [ParserErrorCode.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE]); |
| 1437 } |
| 1438 |
| 1290 void test_implementsBeforeExtends() { | 1439 void test_implementsBeforeExtends() { |
| 1291 ParserTestCase.parseCompilationUnit("class A implements B extends C {}", | 1440 ParserTestCase.parseCompilationUnit("class A implements B extends C {}", |
| 1292 [ParserErrorCode.IMPLEMENTS_BEFORE_EXTENDS]); | 1441 [ParserErrorCode.IMPLEMENTS_BEFORE_EXTENDS]); |
| 1293 } | 1442 } |
| 1294 | 1443 |
| 1295 void test_implementsBeforeWith() { | 1444 void test_implementsBeforeWith() { |
| 1296 ParserTestCase.parseCompilationUnit( | 1445 ParserTestCase.parseCompilationUnit( |
| 1297 "class A extends B implements C with D {}", | 1446 "class A extends B implements C with D {}", |
| 1298 [ParserErrorCode.IMPLEMENTS_BEFORE_WITH]); | 1447 [ParserErrorCode.IMPLEMENTS_BEFORE_WITH]); |
| 1299 } | 1448 } |
| 1300 | 1449 |
| 1301 void test_importDirectiveAfterPartDirective() { | 1450 void test_importDirectiveAfterPartDirective() { |
| 1302 ParserTestCase.parseCompilationUnit("part 'a.dart'; import 'b.dart';", | 1451 ParserTestCase.parseCompilationUnit("part 'a.dart'; import 'b.dart';", |
| 1303 [ParserErrorCode.IMPORT_DIRECTIVE_AFTER_PART_DIRECTIVE]); | 1452 [ParserErrorCode.IMPORT_DIRECTIVE_AFTER_PART_DIRECTIVE]); |
| 1304 } | 1453 } |
| 1305 | 1454 |
| 1306 void test_initializedVariableInForEach() { | 1455 void test_initializedVariableInForEach() { |
| 1307 parse4("parseForStatement", "for (int a = 0 in foo) {}", | 1456 createParser('for (int a = 0 in foo) {}'); |
| 1457 Statement statement = parser.parseForStatement(); |
| 1458 expectNotNullIfNoErrors(statement); |
| 1459 listener.assertErrorsWithCodes( |
| 1308 [ParserErrorCode.INITIALIZED_VARIABLE_IN_FOR_EACH]); | 1460 [ParserErrorCode.INITIALIZED_VARIABLE_IN_FOR_EACH]); |
| 1309 } | 1461 } |
| 1310 | 1462 |
| 1311 void test_invalidAwaitInFor() { | 1463 void test_invalidAwaitInFor() { |
| 1312 parse4("parseForStatement", "await for (; ;) {}", | 1464 createParser('await for (; ;) {}'); |
| 1313 [ParserErrorCode.INVALID_AWAIT_IN_FOR]); | 1465 Statement statement = parser.parseForStatement(); |
| 1466 expectNotNullIfNoErrors(statement); |
| 1467 listener.assertErrorsWithCodes([ParserErrorCode.INVALID_AWAIT_IN_FOR]); |
| 1314 } | 1468 } |
| 1315 | 1469 |
| 1316 void test_invalidCodePoint() { | 1470 void test_invalidCodePoint() { |
| 1317 parse4("parseStringLiteral", "'\\uD900'", | 1471 createParser("'\\u{110000}'"); |
| 1318 [ParserErrorCode.INVALID_CODE_POINT]); | 1472 StringLiteral literal = parser.parseStringLiteral(); |
| 1473 expectNotNullIfNoErrors(literal); |
| 1474 listener.assertErrorsWithCodes([ParserErrorCode.INVALID_CODE_POINT]); |
| 1475 } |
| 1476 |
| 1477 @failingTest |
| 1478 void test_invalidCommentReference__new_nonIdentifier() { |
| 1479 // This test fails because the method parseCommentReference returns null. |
| 1480 createParser(''); |
| 1481 CommentReference reference = parser.parseCommentReference('new 42', 0); |
| 1482 expectNotNullIfNoErrors(reference); |
| 1483 listener.assertErrorsWithCodes([ParserErrorCode.INVALID_COMMENT_REFERENCE]); |
| 1484 } |
| 1485 |
| 1486 @failingTest |
| 1487 void test_invalidCommentReference__new_tooMuch() { |
| 1488 createParser(''); |
| 1489 CommentReference reference = parser.parseCommentReference('new a.b.c.d', 0); |
| 1490 expectNotNullIfNoErrors(reference); |
| 1491 listener.assertErrorsWithCodes([ParserErrorCode.INVALID_COMMENT_REFERENCE]); |
| 1492 } |
| 1493 |
| 1494 @failingTest |
| 1495 void test_invalidCommentReference__nonNew_nonIdentifier() { |
| 1496 // This test fails because the method parseCommentReference returns null. |
| 1497 createParser(''); |
| 1498 CommentReference reference = parser.parseCommentReference('42', 0); |
| 1499 expectNotNullIfNoErrors(reference); |
| 1500 listener.assertErrorsWithCodes([ParserErrorCode.INVALID_COMMENT_REFERENCE]); |
| 1501 } |
| 1502 |
| 1503 @failingTest |
| 1504 void test_invalidCommentReference__nonNew_tooMuch() { |
| 1505 createParser(''); |
| 1506 CommentReference reference = parser.parseCommentReference('a.b.c.d', 0); |
| 1507 expectNotNullIfNoErrors(reference); |
| 1508 listener.assertErrorsWithCodes([ParserErrorCode.INVALID_COMMENT_REFERENCE]); |
| 1319 } | 1509 } |
| 1320 | 1510 |
| 1321 void test_invalidHexEscape_invalidDigit() { | 1511 void test_invalidHexEscape_invalidDigit() { |
| 1322 parse4( | 1512 createParser("'\\x0 a'"); |
| 1323 "parseStringLiteral", "'\\x0 a'", [ParserErrorCode.INVALID_HEX_ESCAPE]); | 1513 StringLiteral literal = parser.parseStringLiteral(); |
| 1514 expectNotNullIfNoErrors(literal); |
| 1515 listener.assertErrorsWithCodes([ParserErrorCode.INVALID_HEX_ESCAPE]); |
| 1324 } | 1516 } |
| 1325 | 1517 |
| 1326 void test_invalidHexEscape_tooFewDigits() { | 1518 void test_invalidHexEscape_tooFewDigits() { |
| 1327 parse4( | 1519 createParser("'\\x0'"); |
| 1328 "parseStringLiteral", "'\\x0'", [ParserErrorCode.INVALID_HEX_ESCAPE]); | 1520 StringLiteral literal = parser.parseStringLiteral(); |
| 1521 expectNotNullIfNoErrors(literal); |
| 1522 listener.assertErrorsWithCodes([ParserErrorCode.INVALID_HEX_ESCAPE]); |
| 1329 } | 1523 } |
| 1330 | 1524 |
| 1331 void test_invalidInterpolationIdentifier_startWithDigit() { | 1525 void test_invalidInterpolationIdentifier_startWithDigit() { |
| 1332 parse4("parseStringLiteral", "'\$1'", [ParserErrorCode.MISSING_IDENTIFIER]); | 1526 createParser("'\$1'"); |
| 1527 StringLiteral literal = parser.parseStringLiteral(); |
| 1528 expectNotNullIfNoErrors(literal); |
| 1529 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| 1530 } |
| 1531 |
| 1532 void test_invalidLiteralInConfiguration() { |
| 1533 createParser("if (a == 'x \$y z') 'a.dart'"); |
| 1534 Configuration configuration = parser.parseConfiguration(); |
| 1535 expectNotNullIfNoErrors(configuration); |
| 1536 listener.assertErrorsWithCodes( |
| 1537 [ParserErrorCode.INVALID_LITERAL_IN_CONFIGURATION]); |
| 1333 } | 1538 } |
| 1334 | 1539 |
| 1335 void test_invalidOperator() { | 1540 void test_invalidOperator() { |
| 1336 parse3("parseClassMember", <Object>["C"], "void operator ===(x) {}", | 1541 createParser('void operator ===(x) {}'); |
| 1337 [ParserErrorCode.INVALID_OPERATOR]); | 1542 ClassMember member = parser.parseClassMember('C'); |
| 1543 expectNotNullIfNoErrors(member); |
| 1544 listener.assertErrorsWithCodes([ParserErrorCode.INVALID_OPERATOR]); |
| 1338 } | 1545 } |
| 1339 | 1546 |
| 1340 void test_invalidOperatorAfterSuper_assignableExpression() { | 1547 void test_invalidOperatorAfterSuper_assignableExpression() { |
| 1341 parse3('parseAssignableExpression', <Object>[false], 'super?.v', | 1548 createParser('super?.v'); |
| 1342 [ParserErrorCode.INVALID_OPERATOR_FOR_SUPER]); | 1549 Expression expression = parser.parseAssignableExpression(false); |
| 1550 expectNotNullIfNoErrors(expression); |
| 1551 listener |
| 1552 .assertErrorsWithCodes([ParserErrorCode.INVALID_OPERATOR_FOR_SUPER]); |
| 1343 } | 1553 } |
| 1344 | 1554 |
| 1345 void test_invalidOperatorAfterSuper_primaryExpression() { | 1555 void test_invalidOperatorAfterSuper_primaryExpression() { |
| 1346 parse4('parsePrimaryExpression', 'super?.v', | 1556 createParser('super?.v'); |
| 1347 [ParserErrorCode.INVALID_OPERATOR_FOR_SUPER]); | 1557 Expression expression = parser.parsePrimaryExpression(); |
| 1558 expectNotNullIfNoErrors(expression); |
| 1559 listener |
| 1560 .assertErrorsWithCodes([ParserErrorCode.INVALID_OPERATOR_FOR_SUPER]); |
| 1348 } | 1561 } |
| 1349 | 1562 |
| 1350 void test_invalidOperatorForSuper() { | 1563 void test_invalidOperatorForSuper() { |
| 1351 parse4("parseUnaryExpression", "++super", | 1564 createParser('++super'); |
| 1352 [ParserErrorCode.INVALID_OPERATOR_FOR_SUPER]); | 1565 Expression expression = parser.parseUnaryExpression(); |
| 1566 expectNotNullIfNoErrors(expression); |
| 1567 listener |
| 1568 .assertErrorsWithCodes([ParserErrorCode.INVALID_OPERATOR_FOR_SUPER]); |
| 1353 } | 1569 } |
| 1354 | 1570 |
| 1355 void test_invalidStarAfterAsync() { | 1571 void test_invalidStarAfterAsync() { |
| 1356 parse3("parseFunctionBody", <Object>[false, null, false], "async* => 0;", | 1572 createParser('async* => 0;'); |
| 1357 [ParserErrorCode.INVALID_STAR_AFTER_ASYNC]); | 1573 FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| 1574 expectNotNullIfNoErrors(functionBody); |
| 1575 listener.assertErrorsWithCodes([ParserErrorCode.INVALID_STAR_AFTER_ASYNC]); |
| 1358 } | 1576 } |
| 1359 | 1577 |
| 1360 void test_invalidSync() { | 1578 void test_invalidSync() { |
| 1361 parse3("parseFunctionBody", <Object>[false, null, false], "sync* => 0;", | 1579 createParser('sync* => 0;'); |
| 1362 [ParserErrorCode.INVALID_SYNC]); | 1580 FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| 1581 expectNotNullIfNoErrors(functionBody); |
| 1582 listener.assertErrorsWithCodes([ParserErrorCode.INVALID_SYNC]); |
| 1363 } | 1583 } |
| 1364 | 1584 |
| 1365 void test_invalidUnicodeEscape_incomplete_noDigits() { | 1585 void test_invalidUnicodeEscape_incomplete_noDigits() { |
| 1366 parse4("parseStringLiteral", "'\\u{'", | 1586 createParser("'\\u{'"); |
| 1367 [ParserErrorCode.INVALID_UNICODE_ESCAPE]); | 1587 Expression expression = parser.parseStringLiteral(); |
| 1588 expectNotNullIfNoErrors(expression); |
| 1589 listener.assertErrorsWithCodes([ParserErrorCode.INVALID_UNICODE_ESCAPE]); |
| 1368 } | 1590 } |
| 1369 | 1591 |
| 1370 void test_invalidUnicodeEscape_incomplete_someDigits() { | 1592 void test_invalidUnicodeEscape_incomplete_someDigits() { |
| 1371 parse4("parseStringLiteral", "'\\u{0A'", | 1593 createParser("'\\u{0A'"); |
| 1372 [ParserErrorCode.INVALID_UNICODE_ESCAPE]); | 1594 Expression expression = parser.parseStringLiteral(); |
| 1595 expectNotNullIfNoErrors(expression); |
| 1596 listener.assertErrorsWithCodes([ParserErrorCode.INVALID_UNICODE_ESCAPE]); |
| 1373 } | 1597 } |
| 1374 | 1598 |
| 1375 void test_invalidUnicodeEscape_invalidDigit() { | 1599 void test_invalidUnicodeEscape_invalidDigit() { |
| 1376 parse4("parseStringLiteral", "'\\u0 a'", | 1600 createParser("'\\u0 a'"); |
| 1377 [ParserErrorCode.INVALID_UNICODE_ESCAPE]); | 1601 Expression expression = parser.parseStringLiteral(); |
| 1602 expectNotNullIfNoErrors(expression); |
| 1603 listener.assertErrorsWithCodes([ParserErrorCode.INVALID_UNICODE_ESCAPE]); |
| 1378 } | 1604 } |
| 1379 | 1605 |
| 1380 void test_invalidUnicodeEscape_tooFewDigits_fixed() { | 1606 void test_invalidUnicodeEscape_tooFewDigits_fixed() { |
| 1381 parse4("parseStringLiteral", "'\\u04'", | 1607 createParser("'\\u04'"); |
| 1382 [ParserErrorCode.INVALID_UNICODE_ESCAPE]); | 1608 Expression expression = parser.parseStringLiteral(); |
| 1609 expectNotNullIfNoErrors(expression); |
| 1610 listener.assertErrorsWithCodes([ParserErrorCode.INVALID_UNICODE_ESCAPE]); |
| 1383 } | 1611 } |
| 1384 | 1612 |
| 1385 void test_invalidUnicodeEscape_tooFewDigits_variable() { | 1613 void test_invalidUnicodeEscape_tooFewDigits_variable() { |
| 1386 parse4("parseStringLiteral", "'\\u{}'", | 1614 createParser("'\\u{}'"); |
| 1387 [ParserErrorCode.INVALID_UNICODE_ESCAPE]); | 1615 Expression expression = parser.parseStringLiteral(); |
| 1616 expectNotNullIfNoErrors(expression); |
| 1617 listener.assertErrorsWithCodes([ParserErrorCode.INVALID_UNICODE_ESCAPE]); |
| 1388 } | 1618 } |
| 1389 | 1619 |
| 1390 void test_invalidUnicodeEscape_tooManyDigits_variable() { | 1620 void test_invalidUnicodeEscape_tooManyDigits_variable() { |
| 1391 parse4("parseStringLiteral", "'\\u{12345678}'", [ | 1621 createParser("'\\u{12345678}'"); |
| 1622 Expression expression = parser.parseStringLiteral(); |
| 1623 expectNotNullIfNoErrors(expression); |
| 1624 listener.assertErrorsWithCodes([ |
| 1392 ParserErrorCode.INVALID_UNICODE_ESCAPE, | 1625 ParserErrorCode.INVALID_UNICODE_ESCAPE, |
| 1393 ParserErrorCode.INVALID_CODE_POINT | 1626 ParserErrorCode.INVALID_CODE_POINT |
| 1394 ]); | 1627 ]); |
| 1395 } | 1628 } |
| 1396 | 1629 |
| 1397 void test_libraryDirectiveNotFirst() { | 1630 void test_libraryDirectiveNotFirst() { |
| 1398 ParserTestCase.parseCompilationUnit("import 'x.dart'; library l;", | 1631 ParserTestCase.parseCompilationUnit("import 'x.dart'; library l;", |
| 1399 [ParserErrorCode.LIBRARY_DIRECTIVE_NOT_FIRST]); | 1632 [ParserErrorCode.LIBRARY_DIRECTIVE_NOT_FIRST]); |
| 1400 } | 1633 } |
| 1401 | 1634 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1419 void test_localFunctionDeclarationModifier_factory() { | 1652 void test_localFunctionDeclarationModifier_factory() { |
| 1420 ParserTestCase.parseStatement("factory f() {}", | 1653 ParserTestCase.parseStatement("factory f() {}", |
| 1421 [ParserErrorCode.LOCAL_FUNCTION_DECLARATION_MODIFIER]); | 1654 [ParserErrorCode.LOCAL_FUNCTION_DECLARATION_MODIFIER]); |
| 1422 } | 1655 } |
| 1423 | 1656 |
| 1424 void test_localFunctionDeclarationModifier_static() { | 1657 void test_localFunctionDeclarationModifier_static() { |
| 1425 ParserTestCase.parseStatement( | 1658 ParserTestCase.parseStatement( |
| 1426 "static f() {}", [ParserErrorCode.LOCAL_FUNCTION_DECLARATION_MODIFIER]); | 1659 "static f() {}", [ParserErrorCode.LOCAL_FUNCTION_DECLARATION_MODIFIER]); |
| 1427 } | 1660 } |
| 1428 | 1661 |
| 1662 void test_method_invalidTypeParameterComments() { |
| 1663 enableGenericMethodComments = true; |
| 1664 createParser('void m/*<E, hello!>*/() {}'); |
| 1665 ClassMember member = parser.parseClassMember('C'); |
| 1666 expectNotNullIfNoErrors(member); |
| 1667 listener.assertErrorsWithCodes([ |
| 1668 ParserErrorCode.EXPECTED_TOKEN /*>*/, |
| 1669 ParserErrorCode.MISSING_IDENTIFIER, |
| 1670 ParserErrorCode.EXPECTED_TOKEN /*(*/, |
| 1671 ParserErrorCode.EXPECTED_TOKEN /*)*/, |
| 1672 ParserErrorCode.MISSING_FUNCTION_BODY |
| 1673 ]); |
| 1674 expect(member, new isInstanceOf<MethodDeclaration>()); |
| 1675 MethodDeclaration method = member; |
| 1676 expect(method.typeParameters.toString(), '<E, hello>', |
| 1677 reason: 'parser recovers what it can'); |
| 1678 } |
| 1679 |
| 1680 void test_method_invalidTypeParameterExtends() { |
| 1681 // Regression test for https://github.com/dart-lang/sdk/issues/25739. |
| 1682 |
| 1683 // TODO(jmesserly): ideally we'd be better at parser recovery here. |
| 1684 enableGenericMethods = true; |
| 1685 createParser('f<E>(E extends num p);'); |
| 1686 ClassMember member = parser.parseClassMember('C'); |
| 1687 expectNotNullIfNoErrors(member); |
| 1688 listener.assertErrorsWithCodes([ |
| 1689 ParserErrorCode.MISSING_IDENTIFIER, // `extends` is a keyword |
| 1690 ParserErrorCode.EXPECTED_TOKEN, // comma |
| 1691 ParserErrorCode.EXPECTED_TOKEN, // close paren |
| 1692 ParserErrorCode.MISSING_FUNCTION_BODY |
| 1693 ]); |
| 1694 expect(member, new isInstanceOf<MethodDeclaration>()); |
| 1695 MethodDeclaration method = member; |
| 1696 expect(method.parameters.toString(), '(E, extends)', |
| 1697 reason: 'parser recovers what it can'); |
| 1698 } |
| 1699 |
| 1700 void test_method_invalidTypeParameterExtendsComment() { |
| 1701 // Regression test for https://github.com/dart-lang/sdk/issues/25739. |
| 1702 |
| 1703 // TODO(jmesserly): ideally we'd be better at parser recovery here. |
| 1704 // Also, this behavior is slightly different from how we would parse a |
| 1705 // normal generic method, because we "discover" the comment at a different |
| 1706 // point in the parser. This has a slight effect on the AST that results |
| 1707 // from error recovery. |
| 1708 enableGenericMethodComments = true; |
| 1709 createParser('f/*<E>*/(dynamic/*=E extends num*/p);'); |
| 1710 ClassMember member = parser.parseClassMember('C'); |
| 1711 expectNotNullIfNoErrors(member); |
| 1712 listener.assertErrorsWithCodes([ |
| 1713 ParserErrorCode.MISSING_IDENTIFIER, // `extends` is a keyword |
| 1714 ParserErrorCode.EXPECTED_TOKEN, // comma |
| 1715 ParserErrorCode.MISSING_IDENTIFIER, // `extends` is a keyword |
| 1716 ParserErrorCode.EXPECTED_TOKEN, // close paren |
| 1717 ParserErrorCode.MISSING_FUNCTION_BODY |
| 1718 ]); |
| 1719 expect(member, new isInstanceOf<MethodDeclaration>()); |
| 1720 MethodDeclaration method = member; |
| 1721 expect(method.parameters.toString(), '(E extends, extends)', |
| 1722 reason: 'parser recovers what it can'); |
| 1723 } |
| 1724 |
| 1725 void test_method_invalidTypeParameters() { |
| 1726 // TODO(jmesserly): ideally we'd be better at parser recovery here. |
| 1727 // It doesn't try to advance past the invalid token `!` to find the |
| 1728 // valid `>`. If it did we'd get less cascading errors, at least for this |
| 1729 // particular example. |
| 1730 enableGenericMethods = true; |
| 1731 createParser('void m<E, hello!>() {}'); |
| 1732 ClassMember member = parser.parseClassMember('C'); |
| 1733 expectNotNullIfNoErrors(member); |
| 1734 listener.assertErrorsWithCodes([ |
| 1735 ParserErrorCode.EXPECTED_TOKEN /*>*/, |
| 1736 ParserErrorCode.MISSING_IDENTIFIER, |
| 1737 ParserErrorCode.EXPECTED_TOKEN /*(*/, |
| 1738 ParserErrorCode.EXPECTED_TOKEN /*)*/, |
| 1739 ParserErrorCode.MISSING_FUNCTION_BODY |
| 1740 ]); |
| 1741 expect(member, new isInstanceOf<MethodDeclaration>()); |
| 1742 MethodDeclaration method = member; |
| 1743 expect(method.typeParameters.toString(), '<E, hello>', |
| 1744 reason: 'parser recovers what it can'); |
| 1745 } |
| 1746 |
| 1429 void test_missingAssignableSelector_identifiersAssigned() { | 1747 void test_missingAssignableSelector_identifiersAssigned() { |
| 1430 parseExpression("x.y = y;"); | 1748 parseExpression("x.y = y;"); |
| 1431 } | 1749 } |
| 1432 | 1750 |
| 1433 void test_missingAssignableSelector_prefix_minusMinus_literal() { | 1751 void test_missingAssignableSelector_prefix_minusMinus_literal() { |
| 1434 parseExpression("--0", [ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR]); | 1752 parseExpression("--0", [ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR]); |
| 1435 } | 1753 } |
| 1436 | 1754 |
| 1437 void test_missingAssignableSelector_prefix_plusPlus_literal() { | 1755 void test_missingAssignableSelector_prefix_plusPlus_literal() { |
| 1438 parseExpression("++0", [ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR]); | 1756 parseExpression("++0", [ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR]); |
| 1439 } | 1757 } |
| 1440 | 1758 |
| 1441 void test_missingAssignableSelector_selector() { | 1759 void test_missingAssignableSelector_selector() { |
| 1442 parseExpression("x(y)(z).a++"); | 1760 parseExpression("x(y)(z).a++"); |
| 1443 } | 1761 } |
| 1444 | 1762 |
| 1445 void test_missingAssignableSelector_superPrimaryExpression() { | 1763 void test_missingAssignableSelector_superPrimaryExpression() { |
| 1446 SuperExpression expression = parse4("parsePrimaryExpression", "super", | 1764 createParser('super'); |
| 1447 [ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR]); | 1765 Expression expression = parser.parsePrimaryExpression(); |
| 1448 expect(expression.superKeyword, isNotNull); | 1766 expectNotNullIfNoErrors(expression); |
| 1767 listener |
| 1768 .assertErrorsWithCodes([ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR]); |
| 1769 expect(expression, new isInstanceOf<SuperExpression>()); |
| 1770 SuperExpression superExpression = expression; |
| 1771 expect(superExpression.superKeyword, isNotNull); |
| 1449 } | 1772 } |
| 1450 | 1773 |
| 1451 void test_missingAssignableSelector_superPropertyAccessAssigned() { | 1774 void test_missingAssignableSelector_superPropertyAccessAssigned() { |
| 1452 parseExpression("super.x = x;"); | 1775 parseExpression("super.x = x;"); |
| 1453 } | 1776 } |
| 1454 | 1777 |
| 1455 void test_missingCatchOrFinally() { | 1778 void test_missingCatchOrFinally() { |
| 1456 TryStatement statement = parse4("parseTryStatement", "try {}", | 1779 createParser('try {}'); |
| 1457 [ParserErrorCode.MISSING_CATCH_OR_FINALLY]); | 1780 TryStatement statement = parser.parseTryStatement(); |
| 1781 expectNotNullIfNoErrors(statement); |
| 1782 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_CATCH_OR_FINALLY]); |
| 1458 expect(statement, isNotNull); | 1783 expect(statement, isNotNull); |
| 1459 } | 1784 } |
| 1460 | 1785 |
| 1461 void test_missingClassBody() { | 1786 void test_missingClassBody() { |
| 1462 ParserTestCase.parseCompilationUnit( | 1787 ParserTestCase.parseCompilationUnit( |
| 1463 "class A class B {}", [ParserErrorCode.MISSING_CLASS_BODY]); | 1788 "class A class B {}", [ParserErrorCode.MISSING_CLASS_BODY]); |
| 1464 } | 1789 } |
| 1465 | 1790 |
| 1791 @failingTest |
| 1792 void test_missingClosingParenthesis() { |
| 1793 // It is possible that it is not possible to generate this error (that it's |
| 1794 // being reported in code that cannot actually be reached), but that hasn't |
| 1795 // been proven yet. |
| 1796 createParser('(int a, int b ;'); |
| 1797 FormalParameterList list = parser.parseFormalParameterList(); |
| 1798 expectNotNullIfNoErrors(list); |
| 1799 listener |
| 1800 .assertErrorsWithCodes([ParserErrorCode.MISSING_CLOSING_PARENTHESIS]); |
| 1801 } |
| 1802 |
| 1466 void test_missingConstFinalVarOrType_static() { | 1803 void test_missingConstFinalVarOrType_static() { |
| 1467 ParserTestCase.parseCompilationUnit("class A { static f; }", | 1804 ParserTestCase.parseCompilationUnit("class A { static f; }", |
| 1468 [ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE]); | 1805 [ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE]); |
| 1469 } | 1806 } |
| 1470 | 1807 |
| 1471 void test_missingConstFinalVarOrType_topLevel() { | 1808 void test_missingConstFinalVarOrType_topLevel() { |
| 1472 parse3("parseFinalConstVarOrType", <Object>[false], "a;", | 1809 createParser('a;'); |
| 1810 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| 1811 expectNotNullIfNoErrors(result); |
| 1812 listener.assertErrorsWithCodes( |
| 1473 [ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE]); | 1813 [ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE]); |
| 1474 } | 1814 } |
| 1475 | 1815 |
| 1476 void test_missingEnumBody() { | 1816 void test_missingEnumBody() { |
| 1477 parse3("parseEnumDeclaration", <Object>[emptyCommentAndMetadata()], | 1817 createParser('enum E;'); |
| 1478 "enum E;", [ParserErrorCode.MISSING_ENUM_BODY]); | 1818 EnumDeclaration declaration = |
| 1819 parser.parseEnumDeclaration(emptyCommentAndMetadata()); |
| 1820 expectNotNullIfNoErrors(declaration); |
| 1821 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_ENUM_BODY]); |
| 1479 } | 1822 } |
| 1480 | 1823 |
| 1481 void test_missingExpressionInThrow_withCascade() { | 1824 void test_missingExpressionInThrow_withCascade() { |
| 1482 parse4("parseThrowExpression", "throw;", | 1825 createParser('throw;'); |
| 1483 [ParserErrorCode.MISSING_EXPRESSION_IN_THROW]); | 1826 ThrowExpression expression = parser.parseThrowExpression(); |
| 1827 expectNotNullIfNoErrors(expression); |
| 1828 listener |
| 1829 .assertErrorsWithCodes([ParserErrorCode.MISSING_EXPRESSION_IN_THROW]); |
| 1484 } | 1830 } |
| 1485 | 1831 |
| 1486 void test_missingExpressionInThrow_withoutCascade() { | 1832 void test_missingExpressionInThrow_withoutCascade() { |
| 1487 parse4("parseThrowExpressionWithoutCascade", "throw;", | 1833 createParser('throw;'); |
| 1488 [ParserErrorCode.MISSING_EXPRESSION_IN_THROW]); | 1834 ThrowExpression expression = parser.parseThrowExpressionWithoutCascade(); |
| 1835 expectNotNullIfNoErrors(expression); |
| 1836 listener |
| 1837 .assertErrorsWithCodes([ParserErrorCode.MISSING_EXPRESSION_IN_THROW]); |
| 1489 } | 1838 } |
| 1490 | 1839 |
| 1491 void test_missingFunctionBody_emptyNotAllowed() { | 1840 void test_missingFunctionBody_emptyNotAllowed() { |
| 1492 parse3( | 1841 createParser(';'); |
| 1493 "parseFunctionBody", | 1842 FunctionBody functionBody = parser.parseFunctionBody( |
| 1494 <Object>[false, ParserErrorCode.MISSING_FUNCTION_BODY, false], | 1843 false, ParserErrorCode.MISSING_FUNCTION_BODY, false); |
| 1495 ";", | 1844 expectNotNullIfNoErrors(functionBody); |
| 1496 [ParserErrorCode.MISSING_FUNCTION_BODY]); | 1845 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_FUNCTION_BODY]); |
| 1497 } | 1846 } |
| 1498 | 1847 |
| 1499 void test_missingFunctionBody_invalid() { | 1848 void test_missingFunctionBody_invalid() { |
| 1500 parse3( | 1849 createParser('return 0;'); |
| 1501 "parseFunctionBody", | 1850 FunctionBody functionBody = parser.parseFunctionBody( |
| 1502 <Object>[false, ParserErrorCode.MISSING_FUNCTION_BODY, false], | 1851 false, ParserErrorCode.MISSING_FUNCTION_BODY, false); |
| 1503 "return 0;", | 1852 expectNotNullIfNoErrors(functionBody); |
| 1504 [ParserErrorCode.MISSING_FUNCTION_BODY]); | 1853 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_FUNCTION_BODY]); |
| 1854 } |
| 1855 |
| 1856 @failingTest |
| 1857 void test_missingFunctionParameters_local_nonVoid_block() { |
| 1858 // The parser does not recognize this as a function declaration, so it tries |
| 1859 // to parse it as an expression statement. It isn't clear what the best |
| 1860 // error message is in this case. |
| 1861 ParserTestCase.parseStatement( |
| 1862 "int f { return x;}", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); |
| 1863 } |
| 1864 |
| 1865 @failingTest |
| 1866 void test_missingFunctionParameters_local_nonVoid_expression() { |
| 1867 // The parser does not recognize this as a function declaration, so it tries |
| 1868 // to parse it as an expression statement. It isn't clear what the best |
| 1869 // error message is in this case. |
| 1870 ParserTestCase.parseStatement( |
| 1871 "int f => x;", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); |
| 1505 } | 1872 } |
| 1506 | 1873 |
| 1507 void test_missingFunctionParameters_local_void_block() { | 1874 void test_missingFunctionParameters_local_void_block() { |
| 1508 ParserTestCase.parseStatement( | 1875 ParserTestCase.parseStatement( |
| 1509 "void f { return x;}", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); | 1876 "void f { return x;}", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); |
| 1510 } | 1877 } |
| 1511 | 1878 |
| 1512 void test_missingFunctionParameters_local_void_expression() { | 1879 void test_missingFunctionParameters_local_void_expression() { |
| 1513 ParserTestCase.parseStatement( | 1880 ParserTestCase.parseStatement( |
| 1514 "void f => x;", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); | 1881 "void f => x;", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1532 } | 1899 } |
| 1533 | 1900 |
| 1534 void test_missingFunctionParameters_topLevel_void_expression() { | 1901 void test_missingFunctionParameters_topLevel_void_expression() { |
| 1535 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 1902 CompilationUnit unit = ParserTestCase.parseCompilationUnit( |
| 1536 "void f => x;", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); | 1903 "void f => x;", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); |
| 1537 FunctionDeclaration funct = unit.declarations[0]; | 1904 FunctionDeclaration funct = unit.declarations[0]; |
| 1538 expect(funct.functionExpression.parameters, hasLength(0)); | 1905 expect(funct.functionExpression.parameters, hasLength(0)); |
| 1539 } | 1906 } |
| 1540 | 1907 |
| 1541 void test_missingIdentifier_afterOperator() { | 1908 void test_missingIdentifier_afterOperator() { |
| 1542 parse4("parseMultiplicativeExpression", "1 *", | 1909 createParser('1 *'); |
| 1543 [ParserErrorCode.MISSING_IDENTIFIER]); | 1910 BinaryExpression expression = parser.parseMultiplicativeExpression(); |
| 1911 expectNotNullIfNoErrors(expression); |
| 1912 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| 1544 } | 1913 } |
| 1545 | 1914 |
| 1546 void test_missingIdentifier_beforeClosingCurly() { | 1915 void test_missingIdentifier_beforeClosingCurly() { |
| 1547 parse3("parseClassMember", <Object>["C"], "int}", | 1916 createParser('int}'); |
| 1917 ClassMember member = parser.parseClassMember('C'); |
| 1918 expectNotNullIfNoErrors(member); |
| 1919 listener.assertErrorsWithCodes( |
| 1548 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); | 1920 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); |
| 1549 } | 1921 } |
| 1550 | 1922 |
| 1551 void test_missingIdentifier_functionDeclaration_returnTypeWithoutName() { | 1923 void test_missingIdentifier_functionDeclaration_returnTypeWithoutName() { |
| 1552 parse4("parseFunctionDeclarationStatement", "A<T> () {}", | 1924 createParser('A<T> () {}'); |
| 1553 [ParserErrorCode.MISSING_IDENTIFIER]); | 1925 Statement statement = parser.parseFunctionDeclarationStatement(); |
| 1926 expectNotNullIfNoErrors(statement); |
| 1927 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| 1554 } | 1928 } |
| 1555 | 1929 |
| 1556 void test_missingIdentifier_inEnum() { | 1930 void test_missingIdentifier_inEnum() { |
| 1557 parse3("parseEnumDeclaration", <Object>[emptyCommentAndMetadata()], | 1931 createParser('enum E {, TWO}'); |
| 1558 "enum E {, TWO}", [ParserErrorCode.MISSING_IDENTIFIER]); | 1932 EnumDeclaration declaration = |
| 1933 parser.parseEnumDeclaration(emptyCommentAndMetadata()); |
| 1934 expectNotNullIfNoErrors(declaration); |
| 1935 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| 1559 } | 1936 } |
| 1560 | 1937 |
| 1561 void test_missingIdentifier_inSymbol_afterPeriod() { | 1938 void test_missingIdentifier_inSymbol_afterPeriod() { |
| 1562 parse4("parseSymbolLiteral", "#a.", [ParserErrorCode.MISSING_IDENTIFIER]); | 1939 createParser('#a.'); |
| 1940 SymbolLiteral literal = parser.parseSymbolLiteral(); |
| 1941 expectNotNullIfNoErrors(literal); |
| 1942 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| 1563 } | 1943 } |
| 1564 | 1944 |
| 1565 void test_missingIdentifier_inSymbol_first() { | 1945 void test_missingIdentifier_inSymbol_first() { |
| 1566 parse4("parseSymbolLiteral", "#", [ParserErrorCode.MISSING_IDENTIFIER]); | 1946 createParser('#'); |
| 1947 SymbolLiteral literal = parser.parseSymbolLiteral(); |
| 1948 expectNotNullIfNoErrors(literal); |
| 1949 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| 1567 } | 1950 } |
| 1568 | 1951 |
| 1569 void test_missingIdentifier_number() { | 1952 void test_missingIdentifier_number() { |
| 1570 SimpleIdentifier expression = parse4( | 1953 createParser('1'); |
| 1571 "parseSimpleIdentifier", "1", [ParserErrorCode.MISSING_IDENTIFIER]); | 1954 SimpleIdentifier expression = parser.parseSimpleIdentifier(); |
| 1955 expectNotNullIfNoErrors(expression); |
| 1956 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| 1572 expect(expression.isSynthetic, isTrue); | 1957 expect(expression.isSynthetic, isTrue); |
| 1573 } | 1958 } |
| 1574 | 1959 |
| 1960 void test_missingIdentifierForParameterGroup() { |
| 1961 createParser('(,)'); |
| 1962 FormalParameterList list = parser.parseFormalParameterList(); |
| 1963 expectNotNullIfNoErrors(list); |
| 1964 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| 1965 } |
| 1966 |
| 1575 void test_missingKeywordOperator() { | 1967 void test_missingKeywordOperator() { |
| 1576 parse3("parseOperator", <Object>[emptyCommentAndMetadata(), null, null], | 1968 createParser('+(x) {}'); |
| 1577 "+(x) {}", [ParserErrorCode.MISSING_KEYWORD_OPERATOR]); | 1969 MethodDeclaration method = |
| 1970 parser.parseOperator(emptyCommentAndMetadata(), null, null); |
| 1971 expectNotNullIfNoErrors(method); |
| 1972 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_KEYWORD_OPERATOR]); |
| 1578 } | 1973 } |
| 1579 | 1974 |
| 1580 void test_missingKeywordOperator_parseClassMember() { | 1975 void test_missingKeywordOperator_parseClassMember() { |
| 1581 parse3("parseClassMember", <Object>["C"], "+() {}", | 1976 createParser('+() {}'); |
| 1582 [ParserErrorCode.MISSING_KEYWORD_OPERATOR]); | 1977 ClassMember member = parser.parseClassMember('C'); |
| 1978 expectNotNullIfNoErrors(member); |
| 1979 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_KEYWORD_OPERATOR]); |
| 1583 } | 1980 } |
| 1584 | 1981 |
| 1585 void test_missingKeywordOperator_parseClassMember_afterTypeName() { | 1982 void test_missingKeywordOperator_parseClassMember_afterTypeName() { |
| 1586 parse3("parseClassMember", <Object>["C"], "int +() {}", | 1983 createParser('int +() {}'); |
| 1587 [ParserErrorCode.MISSING_KEYWORD_OPERATOR]); | 1984 ClassMember member = parser.parseClassMember('C'); |
| 1985 expectNotNullIfNoErrors(member); |
| 1986 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_KEYWORD_OPERATOR]); |
| 1588 } | 1987 } |
| 1589 | 1988 |
| 1590 void test_missingKeywordOperator_parseClassMember_afterVoid() { | 1989 void test_missingKeywordOperator_parseClassMember_afterVoid() { |
| 1591 parse3("parseClassMember", <Object>["C"], "void +() {}", | 1990 createParser('void +() {}'); |
| 1592 [ParserErrorCode.MISSING_KEYWORD_OPERATOR]); | 1991 ClassMember member = parser.parseClassMember('C'); |
| 1992 expectNotNullIfNoErrors(member); |
| 1993 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_KEYWORD_OPERATOR]); |
| 1593 } | 1994 } |
| 1594 | 1995 |
| 1595 void test_missingMethodParameters_void_block() { | 1996 void test_missingMethodParameters_void_block() { |
| 1596 MethodDeclaration method = parse3("parseClassMember", <Object>["C"], | 1997 createParser('void m {} }'); |
| 1597 "void m {} }", [ParserErrorCode.MISSING_METHOD_PARAMETERS]); | 1998 ClassMember member = parser.parseClassMember('C'); |
| 1999 expectNotNullIfNoErrors(member); |
| 2000 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_METHOD_PARAMETERS]); |
| 2001 expect(member, new isInstanceOf<MethodDeclaration>()); |
| 2002 MethodDeclaration method = member; |
| 1598 expect(method.parameters, hasLength(0)); | 2003 expect(method.parameters, hasLength(0)); |
| 1599 } | 2004 } |
| 1600 | 2005 |
| 1601 void test_missingMethodParameters_void_expression() { | 2006 void test_missingMethodParameters_void_expression() { |
| 1602 parse3("parseClassMember", <Object>["C"], "void m => null; }", | 2007 createParser('void m => null; }'); |
| 1603 [ParserErrorCode.MISSING_METHOD_PARAMETERS]); | 2008 ClassMember member = parser.parseClassMember('C'); |
| 2009 expectNotNullIfNoErrors(member); |
| 2010 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_METHOD_PARAMETERS]); |
| 1604 } | 2011 } |
| 1605 | 2012 |
| 1606 void test_missingNameInLibraryDirective() { | 2013 void test_missingNameInLibraryDirective() { |
| 1607 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 2014 CompilationUnit unit = ParserTestCase.parseCompilationUnit( |
| 1608 "library;", [ParserErrorCode.MISSING_NAME_IN_LIBRARY_DIRECTIVE]); | 2015 "library;", [ParserErrorCode.MISSING_NAME_IN_LIBRARY_DIRECTIVE]); |
| 1609 expect(unit, isNotNull); | 2016 expect(unit, isNotNull); |
| 1610 } | 2017 } |
| 1611 | 2018 |
| 1612 void test_missingNameInPartOfDirective() { | 2019 void test_missingNameInPartOfDirective() { |
| 1613 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 2020 CompilationUnit unit = ParserTestCase.parseCompilationUnit( |
| 1614 "part of;", [ParserErrorCode.MISSING_NAME_IN_PART_OF_DIRECTIVE]); | 2021 "part of;", [ParserErrorCode.MISSING_NAME_IN_PART_OF_DIRECTIVE]); |
| 1615 expect(unit, isNotNull); | 2022 expect(unit, isNotNull); |
| 1616 } | 2023 } |
| 1617 | 2024 |
| 1618 void test_missingPrefixInDeferredImport() { | 2025 void test_missingPrefixInDeferredImport() { |
| 1619 ParserTestCase.parseCompilationUnit("import 'foo.dart' deferred;", | 2026 ParserTestCase.parseCompilationUnit("import 'foo.dart' deferred;", |
| 1620 [ParserErrorCode.MISSING_PREFIX_IN_DEFERRED_IMPORT]); | 2027 [ParserErrorCode.MISSING_PREFIX_IN_DEFERRED_IMPORT]); |
| 1621 } | 2028 } |
| 1622 | 2029 |
| 1623 void test_missingStartAfterSync() { | 2030 void test_missingStartAfterSync() { |
| 1624 parse3("parseFunctionBody", <Object>[false, null, false], "sync {}", | 2031 createParser('sync {}'); |
| 1625 [ParserErrorCode.MISSING_STAR_AFTER_SYNC]); | 2032 FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| 2033 expectNotNullIfNoErrors(functionBody); |
| 2034 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_STAR_AFTER_SYNC]); |
| 1626 } | 2035 } |
| 1627 | 2036 |
| 1628 void test_missingStatement() { | 2037 void test_missingStatement() { |
| 1629 ParserTestCase.parseStatement("is", [ParserErrorCode.MISSING_STATEMENT]); | 2038 ParserTestCase.parseStatement("is", [ParserErrorCode.MISSING_STATEMENT]); |
| 1630 } | 2039 } |
| 1631 | 2040 |
| 1632 void test_missingStatement_afterVoid() { | 2041 void test_missingStatement_afterVoid() { |
| 1633 ParserTestCase.parseStatement("void;", [ParserErrorCode.MISSING_STATEMENT]); | 2042 ParserTestCase.parseStatement("void;", [ParserErrorCode.MISSING_STATEMENT]); |
| 1634 } | 2043 } |
| 1635 | 2044 |
| 1636 void test_missingTerminatorForParameterGroup_named() { | 2045 void test_missingTerminatorForParameterGroup_named() { |
| 1637 parse4("parseFormalParameterList", "(a, {b: 0)", | 2046 createParser('(a, {b: 0)'); |
| 2047 FormalParameterList list = parser.parseFormalParameterList(); |
| 2048 expectNotNullIfNoErrors(list); |
| 2049 listener.assertErrorsWithCodes( |
| 1638 [ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETER_GROUP]); | 2050 [ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETER_GROUP]); |
| 1639 } | 2051 } |
| 1640 | 2052 |
| 1641 void test_missingTerminatorForParameterGroup_optional() { | 2053 void test_missingTerminatorForParameterGroup_optional() { |
| 1642 parse4("parseFormalParameterList", "(a, [b = 0)", | 2054 createParser('(a, [b = 0)'); |
| 2055 FormalParameterList list = parser.parseFormalParameterList(); |
| 2056 expectNotNullIfNoErrors(list); |
| 2057 listener.assertErrorsWithCodes( |
| 1643 [ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETER_GROUP]); | 2058 [ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETER_GROUP]); |
| 1644 } | 2059 } |
| 1645 | 2060 |
| 1646 void test_missingTypedefParameters_nonVoid() { | 2061 void test_missingTypedefParameters_nonVoid() { |
| 1647 ParserTestCase.parseCompilationUnit( | 2062 ParserTestCase.parseCompilationUnit( |
| 1648 "typedef int F;", [ParserErrorCode.MISSING_TYPEDEF_PARAMETERS]); | 2063 "typedef int F;", [ParserErrorCode.MISSING_TYPEDEF_PARAMETERS]); |
| 1649 } | 2064 } |
| 1650 | 2065 |
| 1651 void test_missingTypedefParameters_typeParameters() { | 2066 void test_missingTypedefParameters_typeParameters() { |
| 1652 ParserTestCase.parseCompilationUnit( | 2067 ParserTestCase.parseCompilationUnit( |
| 1653 "typedef F<E>;", [ParserErrorCode.MISSING_TYPEDEF_PARAMETERS]); | 2068 "typedef F<E>;", [ParserErrorCode.MISSING_TYPEDEF_PARAMETERS]); |
| 1654 } | 2069 } |
| 1655 | 2070 |
| 1656 void test_missingTypedefParameters_void() { | 2071 void test_missingTypedefParameters_void() { |
| 1657 ParserTestCase.parseCompilationUnit( | 2072 ParserTestCase.parseCompilationUnit( |
| 1658 "typedef void F;", [ParserErrorCode.MISSING_TYPEDEF_PARAMETERS]); | 2073 "typedef void F;", [ParserErrorCode.MISSING_TYPEDEF_PARAMETERS]); |
| 1659 } | 2074 } |
| 1660 | 2075 |
| 1661 void test_missingVariableInForEach() { | 2076 void test_missingVariableInForEach() { |
| 1662 parse4("parseForStatement", "for (a < b in foo) {}", | 2077 createParser('for (a < b in foo) {}'); |
| 1663 [ParserErrorCode.MISSING_VARIABLE_IN_FOR_EACH]); | 2078 Statement statement = parser.parseForStatement(); |
| 2079 expectNotNullIfNoErrors(statement); |
| 2080 listener |
| 2081 .assertErrorsWithCodes([ParserErrorCode.MISSING_VARIABLE_IN_FOR_EACH]); |
| 1664 } | 2082 } |
| 1665 | 2083 |
| 1666 void test_mixedParameterGroups_namedPositional() { | 2084 void test_mixedParameterGroups_namedPositional() { |
| 1667 parse4("parseFormalParameterList", "(a, {b}, [c])", | 2085 createParser('(a, {b}, [c])'); |
| 1668 [ParserErrorCode.MIXED_PARAMETER_GROUPS]); | 2086 FormalParameterList list = parser.parseFormalParameterList(); |
| 2087 expectNotNullIfNoErrors(list); |
| 2088 listener.assertErrorsWithCodes([ParserErrorCode.MIXED_PARAMETER_GROUPS]); |
| 1669 } | 2089 } |
| 1670 | 2090 |
| 1671 void test_mixedParameterGroups_positionalNamed() { | 2091 void test_mixedParameterGroups_positionalNamed() { |
| 1672 parse4("parseFormalParameterList", "(a, [b], {c})", | 2092 createParser('(a, [b], {c})'); |
| 1673 [ParserErrorCode.MIXED_PARAMETER_GROUPS]); | 2093 FormalParameterList list = parser.parseFormalParameterList(); |
| 2094 expectNotNullIfNoErrors(list); |
| 2095 listener.assertErrorsWithCodes([ParserErrorCode.MIXED_PARAMETER_GROUPS]); |
| 1674 } | 2096 } |
| 1675 | 2097 |
| 1676 void test_mixin_application_lacks_with_clause() { | 2098 void test_mixin_application_lacks_with_clause() { |
| 1677 ParserTestCase.parseCompilationUnit( | 2099 ParserTestCase.parseCompilationUnit( |
| 1678 "class Foo = Bar;", [ParserErrorCode.EXPECTED_TOKEN]); | 2100 "class Foo = Bar;", [ParserErrorCode.EXPECTED_TOKEN]); |
| 1679 } | 2101 } |
| 1680 | 2102 |
| 1681 void test_multipleExtendsClauses() { | 2103 void test_multipleExtendsClauses() { |
| 1682 ParserTestCase.parseCompilationUnit("class A extends B extends C {}", | 2104 ParserTestCase.parseCompilationUnit("class A extends B extends C {}", |
| 1683 [ParserErrorCode.MULTIPLE_EXTENDS_CLAUSES]); | 2105 [ParserErrorCode.MULTIPLE_EXTENDS_CLAUSES]); |
| 1684 } | 2106 } |
| 1685 | 2107 |
| 1686 void test_multipleImplementsClauses() { | 2108 void test_multipleImplementsClauses() { |
| 1687 ParserTestCase.parseCompilationUnit("class A implements B implements C {}", | 2109 ParserTestCase.parseCompilationUnit("class A implements B implements C {}", |
| 1688 [ParserErrorCode.MULTIPLE_IMPLEMENTS_CLAUSES]); | 2110 [ParserErrorCode.MULTIPLE_IMPLEMENTS_CLAUSES]); |
| 1689 } | 2111 } |
| 1690 | 2112 |
| 1691 void test_multipleLibraryDirectives() { | 2113 void test_multipleLibraryDirectives() { |
| 1692 ParserTestCase.parseCompilationUnit( | 2114 ParserTestCase.parseCompilationUnit( |
| 1693 "library l; library m;", [ParserErrorCode.MULTIPLE_LIBRARY_DIRECTIVES]); | 2115 "library l; library m;", [ParserErrorCode.MULTIPLE_LIBRARY_DIRECTIVES]); |
| 1694 } | 2116 } |
| 1695 | 2117 |
| 1696 void test_multipleNamedParameterGroups() { | 2118 void test_multipleNamedParameterGroups() { |
| 1697 parse4("parseFormalParameterList", "(a, {b}, {c})", | 2119 createParser('(a, {b}, {c})'); |
| 2120 FormalParameterList list = parser.parseFormalParameterList(); |
| 2121 expectNotNullIfNoErrors(list); |
| 2122 listener.assertErrorsWithCodes( |
| 1698 [ParserErrorCode.MULTIPLE_NAMED_PARAMETER_GROUPS]); | 2123 [ParserErrorCode.MULTIPLE_NAMED_PARAMETER_GROUPS]); |
| 1699 } | 2124 } |
| 1700 | 2125 |
| 1701 void test_multiplePartOfDirectives() { | 2126 void test_multiplePartOfDirectives() { |
| 1702 ParserTestCase.parseCompilationUnit( | 2127 ParserTestCase.parseCompilationUnit( |
| 1703 "part of l; part of m;", [ParserErrorCode.MULTIPLE_PART_OF_DIRECTIVES]); | 2128 "part of l; part of m;", [ParserErrorCode.MULTIPLE_PART_OF_DIRECTIVES]); |
| 1704 } | 2129 } |
| 1705 | 2130 |
| 1706 void test_multiplePositionalParameterGroups() { | 2131 void test_multiplePositionalParameterGroups() { |
| 1707 parse4("parseFormalParameterList", "(a, [b], [c])", | 2132 createParser('(a, [b], [c])'); |
| 2133 FormalParameterList list = parser.parseFormalParameterList(); |
| 2134 expectNotNullIfNoErrors(list); |
| 2135 listener.assertErrorsWithCodes( |
| 1708 [ParserErrorCode.MULTIPLE_POSITIONAL_PARAMETER_GROUPS]); | 2136 [ParserErrorCode.MULTIPLE_POSITIONAL_PARAMETER_GROUPS]); |
| 1709 } | 2137 } |
| 1710 | 2138 |
| 1711 void test_multipleVariablesInForEach() { | 2139 void test_multipleVariablesInForEach() { |
| 1712 parse4("parseForStatement", "for (int a, b in foo) {}", | 2140 createParser('for (int a, b in foo) {}'); |
| 2141 Statement statement = parser.parseForStatement(); |
| 2142 expectNotNullIfNoErrors(statement); |
| 2143 listener.assertErrorsWithCodes( |
| 1713 [ParserErrorCode.MULTIPLE_VARIABLES_IN_FOR_EACH]); | 2144 [ParserErrorCode.MULTIPLE_VARIABLES_IN_FOR_EACH]); |
| 1714 } | 2145 } |
| 1715 | 2146 |
| 1716 void test_multipleWithClauses() { | 2147 void test_multipleWithClauses() { |
| 1717 ParserTestCase.parseCompilationUnit("class A extends B with C with D {}", | 2148 ParserTestCase.parseCompilationUnit("class A extends B with C with D {}", |
| 1718 [ParserErrorCode.MULTIPLE_WITH_CLAUSES]); | 2149 [ParserErrorCode.MULTIPLE_WITH_CLAUSES]); |
| 1719 } | 2150 } |
| 1720 | 2151 |
| 2152 @failingTest |
| 2153 void test_namedFunctionExpression() { |
| 2154 createParser('f() {}'); |
| 2155 Expression expression = parser.parsePrimaryExpression(); |
| 2156 expectNotNullIfNoErrors(expression); |
| 2157 listener.assertErrorsWithCodes([ParserErrorCode.NAMED_FUNCTION_EXPRESSION]); |
| 2158 expect(expression, new isInstanceOf<FunctionExpression>()); |
| 2159 } |
| 2160 |
| 1721 void test_namedParameterOutsideGroup() { | 2161 void test_namedParameterOutsideGroup() { |
| 1722 parse4("parseFormalParameterList", "(a, b : 0)", | 2162 createParser('(a, b : 0)'); |
| 1723 [ParserErrorCode.NAMED_PARAMETER_OUTSIDE_GROUP]); | 2163 FormalParameterList list = parser.parseFormalParameterList(); |
| 2164 expectNotNullIfNoErrors(list); |
| 2165 listener |
| 2166 .assertErrorsWithCodes([ParserErrorCode.NAMED_PARAMETER_OUTSIDE_GROUP]); |
| 1724 } | 2167 } |
| 1725 | 2168 |
| 1726 void test_nonConstructorFactory_field() { | 2169 void test_nonConstructorFactory_field() { |
| 1727 parse3("parseClassMember", <Object>["C"], "factory int x;", | 2170 createParser('factory int x;'); |
| 1728 [ParserErrorCode.NON_CONSTRUCTOR_FACTORY]); | 2171 ClassMember member = parser.parseClassMember('C'); |
| 2172 expectNotNullIfNoErrors(member); |
| 2173 listener.assertErrorsWithCodes([ParserErrorCode.NON_CONSTRUCTOR_FACTORY]); |
| 1729 } | 2174 } |
| 1730 | 2175 |
| 1731 void test_nonConstructorFactory_method() { | 2176 void test_nonConstructorFactory_method() { |
| 1732 parse3("parseClassMember", <Object>["C"], "factory int m() {}", | 2177 createParser('factory int m() {}'); |
| 1733 [ParserErrorCode.NON_CONSTRUCTOR_FACTORY]); | 2178 ClassMember member = parser.parseClassMember('C'); |
| 2179 expectNotNullIfNoErrors(member); |
| 2180 listener.assertErrorsWithCodes([ParserErrorCode.NON_CONSTRUCTOR_FACTORY]); |
| 1734 } | 2181 } |
| 1735 | 2182 |
| 1736 void test_nonIdentifierLibraryName_library() { | 2183 void test_nonIdentifierLibraryName_library() { |
| 1737 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 2184 CompilationUnit unit = ParserTestCase.parseCompilationUnit( |
| 1738 "library 'lib';", [ParserErrorCode.NON_IDENTIFIER_LIBRARY_NAME]); | 2185 "library 'lib';", [ParserErrorCode.NON_IDENTIFIER_LIBRARY_NAME]); |
| 1739 expect(unit, isNotNull); | 2186 expect(unit, isNotNull); |
| 1740 } | 2187 } |
| 1741 | 2188 |
| 1742 void test_nonIdentifierLibraryName_partOf() { | 2189 void test_nonIdentifierLibraryName_partOf() { |
| 1743 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 2190 CompilationUnit unit = ParserTestCase.parseCompilationUnit( |
| 1744 "part of 'lib';", [ParserErrorCode.NON_IDENTIFIER_LIBRARY_NAME]); | 2191 "part of 'lib';", [ParserErrorCode.NON_IDENTIFIER_LIBRARY_NAME]); |
| 1745 expect(unit, isNotNull); | 2192 expect(unit, isNotNull); |
| 1746 } | 2193 } |
| 1747 | 2194 |
| 1748 void test_nonPartOfDirectiveInPart_after() { | 2195 void test_nonPartOfDirectiveInPart_after() { |
| 1749 ParserTestCase.parseCompilationUnit("part of l; part 'f.dart';", | 2196 ParserTestCase.parseCompilationUnit("part of l; part 'f.dart';", |
| 1750 [ParserErrorCode.NON_PART_OF_DIRECTIVE_IN_PART]); | 2197 [ParserErrorCode.NON_PART_OF_DIRECTIVE_IN_PART]); |
| 1751 } | 2198 } |
| 1752 | 2199 |
| 1753 void test_nonPartOfDirectiveInPart_before() { | 2200 void test_nonPartOfDirectiveInPart_before() { |
| 1754 ParserTestCase.parseCompilationUnit("part 'f.dart'; part of m;", | 2201 ParserTestCase.parseCompilationUnit("part 'f.dart'; part of m;", |
| 1755 [ParserErrorCode.NON_PART_OF_DIRECTIVE_IN_PART]); | 2202 [ParserErrorCode.NON_PART_OF_DIRECTIVE_IN_PART]); |
| 1756 } | 2203 } |
| 1757 | 2204 |
| 1758 void test_nonUserDefinableOperator() { | 2205 void test_nonUserDefinableOperator() { |
| 1759 parse3("parseClassMember", <Object>["C"], "operator +=(int x) => x + 1;", | 2206 createParser('operator +=(int x) => x + 1;'); |
| 1760 [ParserErrorCode.NON_USER_DEFINABLE_OPERATOR]); | 2207 ClassMember member = parser.parseClassMember('C'); |
| 2208 expectNotNullIfNoErrors(member); |
| 2209 listener |
| 2210 .assertErrorsWithCodes([ParserErrorCode.NON_USER_DEFINABLE_OPERATOR]); |
| 2211 } |
| 2212 |
| 2213 void test_nullableTypeInExtends() { |
| 2214 enableNnbd = true; |
| 2215 createParser('extends B?'); |
| 2216 ExtendsClause clause = parser.parseExtendsClause(); |
| 2217 expectNotNullIfNoErrors(clause); |
| 2218 listener.assertErrorsWithCodes([ParserErrorCode.NULLABLE_TYPE_IN_EXTENDS]); |
| 2219 } |
| 2220 |
| 2221 void test_nullableTypeInImplements() { |
| 2222 enableNnbd = true; |
| 2223 createParser('implements I?'); |
| 2224 ImplementsClause clause = parser.parseImplementsClause(); |
| 2225 expectNotNullIfNoErrors(clause); |
| 2226 listener |
| 2227 .assertErrorsWithCodes([ParserErrorCode.NULLABLE_TYPE_IN_IMPLEMENTS]); |
| 2228 } |
| 2229 |
| 2230 void test_nullableTypeInWith() { |
| 2231 enableNnbd = true; |
| 2232 createParser('with M?'); |
| 2233 WithClause clause = parser.parseWithClause(); |
| 2234 expectNotNullIfNoErrors(clause); |
| 2235 listener.assertErrorsWithCodes([ParserErrorCode.NULLABLE_TYPE_IN_WITH]); |
| 2236 } |
| 2237 |
| 2238 void test_nullableTypeParameter() { |
| 2239 enableNnbd = true; |
| 2240 createParser('T?'); |
| 2241 TypeParameter parameter = parser.parseTypeParameter(); |
| 2242 expectNotNullIfNoErrors(parameter); |
| 2243 listener.assertErrorsWithCodes([ParserErrorCode.NULLABLE_TYPE_PARAMETER]); |
| 1761 } | 2244 } |
| 1762 | 2245 |
| 1763 void test_optionalAfterNormalParameters_named() { | 2246 void test_optionalAfterNormalParameters_named() { |
| 1764 ParserTestCase.parseCompilationUnit( | 2247 ParserTestCase.parseCompilationUnit( |
| 1765 "f({a}, b) {}", [ParserErrorCode.NORMAL_BEFORE_OPTIONAL_PARAMETERS]); | 2248 "f({a}, b) {}", [ParserErrorCode.NORMAL_BEFORE_OPTIONAL_PARAMETERS]); |
| 1766 } | 2249 } |
| 1767 | 2250 |
| 1768 void test_optionalAfterNormalParameters_positional() { | 2251 void test_optionalAfterNormalParameters_positional() { |
| 1769 ParserTestCase.parseCompilationUnit( | 2252 ParserTestCase.parseCompilationUnit( |
| 1770 "f([a], b) {}", [ParserErrorCode.NORMAL_BEFORE_OPTIONAL_PARAMETERS]); | 2253 "f([a], b) {}", [ParserErrorCode.NORMAL_BEFORE_OPTIONAL_PARAMETERS]); |
| 1771 } | 2254 } |
| 1772 | 2255 |
| 1773 void test_parseCascadeSection_missingIdentifier() { | 2256 void test_parseCascadeSection_missingIdentifier() { |
| 1774 MethodInvocation methodInvocation = parse4( | 2257 createParser('..()'); |
| 1775 "parseCascadeSection", "..()", [ParserErrorCode.MISSING_IDENTIFIER]); | 2258 MethodInvocation methodInvocation = parser.parseCascadeSection(); |
| 2259 expectNotNullIfNoErrors(methodInvocation); |
| 2260 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| 1776 expect(methodInvocation.target, isNull); | 2261 expect(methodInvocation.target, isNull); |
| 1777 expect(methodInvocation.methodName.name, ""); | 2262 expect(methodInvocation.methodName.name, ""); |
| 1778 expect(methodInvocation.typeArguments, isNull); | 2263 expect(methodInvocation.typeArguments, isNull); |
| 1779 expect(methodInvocation.argumentList.arguments, hasLength(0)); | 2264 expect(methodInvocation.argumentList.arguments, hasLength(0)); |
| 1780 } | 2265 } |
| 1781 | 2266 |
| 1782 void test_parseCascadeSection_missingIdentifier_typeArguments() { | 2267 void test_parseCascadeSection_missingIdentifier_typeArguments() { |
| 1783 enableGenericMethods = true; | 2268 enableGenericMethods = true; |
| 1784 MethodInvocation methodInvocation = parse4( | 2269 createParser('..<E>()'); |
| 1785 "parseCascadeSection", "..<E>()", [ParserErrorCode.MISSING_IDENTIFIER]); | 2270 MethodInvocation methodInvocation = parser.parseCascadeSection(); |
| 2271 expectNotNullIfNoErrors(methodInvocation); |
| 2272 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| 1786 expect(methodInvocation.target, isNull); | 2273 expect(methodInvocation.target, isNull); |
| 1787 expect(methodInvocation.methodName.name, ""); | 2274 expect(methodInvocation.methodName.name, ""); |
| 1788 expect(methodInvocation.typeArguments, isNotNull); | 2275 expect(methodInvocation.typeArguments, isNotNull); |
| 1789 expect(methodInvocation.argumentList.arguments, hasLength(0)); | 2276 expect(methodInvocation.argumentList.arguments, hasLength(0)); |
| 1790 } | 2277 } |
| 1791 | 2278 |
| 1792 void test_positionalAfterNamedArgument() { | 2279 void test_positionalAfterNamedArgument() { |
| 1793 parse4("parseArgumentList", "(x: 1, 2)", | 2280 createParser('(x: 1, 2)'); |
| 2281 ArgumentList list = parser.parseArgumentList(); |
| 2282 expectNotNullIfNoErrors(list); |
| 2283 listener.assertErrorsWithCodes( |
| 1794 [ParserErrorCode.POSITIONAL_AFTER_NAMED_ARGUMENT]); | 2284 [ParserErrorCode.POSITIONAL_AFTER_NAMED_ARGUMENT]); |
| 1795 } | 2285 } |
| 1796 | 2286 |
| 1797 void test_positionalParameterOutsideGroup() { | 2287 void test_positionalParameterOutsideGroup() { |
| 1798 parse4("parseFormalParameterList", "(a, b = 0)", | 2288 createParser('(a, b = 0)'); |
| 2289 FormalParameterList list = parser.parseFormalParameterList(); |
| 2290 expectNotNullIfNoErrors(list); |
| 2291 listener.assertErrorsWithCodes( |
| 1799 [ParserErrorCode.POSITIONAL_PARAMETER_OUTSIDE_GROUP]); | 2292 [ParserErrorCode.POSITIONAL_PARAMETER_OUTSIDE_GROUP]); |
| 1800 } | 2293 } |
| 1801 | 2294 |
| 2295 void test_redirectingConstructorWithBody_named() { |
| 2296 createParser('C.x() : this() {}'); |
| 2297 ClassMember member = parser.parseClassMember('C'); |
| 2298 expectNotNullIfNoErrors(member); |
| 2299 listener.assertErrorsWithCodes( |
| 2300 [ParserErrorCode.REDIRECTING_CONSTRUCTOR_WITH_BODY]); |
| 2301 } |
| 2302 |
| 2303 void test_redirectingConstructorWithBody_unnamed() { |
| 2304 createParser('C() : this.x() {}'); |
| 2305 ClassMember member = parser.parseClassMember('C'); |
| 2306 expectNotNullIfNoErrors(member); |
| 2307 listener.assertErrorsWithCodes( |
| 2308 [ParserErrorCode.REDIRECTING_CONSTRUCTOR_WITH_BODY]); |
| 2309 } |
| 2310 |
| 1802 void test_redirectionInNonFactoryConstructor() { | 2311 void test_redirectionInNonFactoryConstructor() { |
| 1803 parse3("parseClassMember", <Object>["C"], "C() = D;", | 2312 createParser('C() = D;'); |
| 2313 ClassMember member = parser.parseClassMember('C'); |
| 2314 expectNotNullIfNoErrors(member); |
| 2315 listener.assertErrorsWithCodes( |
| 1804 [ParserErrorCode.REDIRECTION_IN_NON_FACTORY_CONSTRUCTOR]); | 2316 [ParserErrorCode.REDIRECTION_IN_NON_FACTORY_CONSTRUCTOR]); |
| 1805 } | 2317 } |
| 1806 | 2318 |
| 1807 void test_setterInFunction_block() { | 2319 void test_setterInFunction_block() { |
| 1808 ParserTestCase.parseStatement( | 2320 ParserTestCase.parseStatement( |
| 1809 "set x(v) {_x = v;}", [ParserErrorCode.SETTER_IN_FUNCTION]); | 2321 "set x(v) {_x = v;}", [ParserErrorCode.SETTER_IN_FUNCTION]); |
| 1810 } | 2322 } |
| 1811 | 2323 |
| 1812 void test_setterInFunction_expression() { | 2324 void test_setterInFunction_expression() { |
| 1813 ParserTestCase.parseStatement( | 2325 ParserTestCase.parseStatement( |
| 1814 "set x(v) => _x = v;", [ParserErrorCode.SETTER_IN_FUNCTION]); | 2326 "set x(v) => _x = v;", [ParserErrorCode.SETTER_IN_FUNCTION]); |
| 1815 } | 2327 } |
| 1816 | 2328 |
| 1817 void test_staticAfterConst() { | 2329 void test_staticAfterConst() { |
| 1818 parse3("parseClassMember", <Object>["C"], "final static int f;", | 2330 createParser('final static int f;'); |
| 1819 [ParserErrorCode.STATIC_AFTER_FINAL]); | 2331 ClassMember member = parser.parseClassMember('C'); |
| 2332 expectNotNullIfNoErrors(member); |
| 2333 listener.assertErrorsWithCodes([ParserErrorCode.STATIC_AFTER_FINAL]); |
| 1820 } | 2334 } |
| 1821 | 2335 |
| 1822 void test_staticAfterFinal() { | 2336 void test_staticAfterFinal() { |
| 1823 parse3("parseClassMember", <Object>["C"], "const static int f;", | 2337 createParser('const static int f;'); |
| 1824 [ParserErrorCode.STATIC_AFTER_CONST]); | 2338 ClassMember member = parser.parseClassMember('C'); |
| 2339 expectNotNullIfNoErrors(member); |
| 2340 listener.assertErrorsWithCodes([ParserErrorCode.STATIC_AFTER_CONST]); |
| 1825 } | 2341 } |
| 1826 | 2342 |
| 1827 void test_staticAfterVar() { | 2343 void test_staticAfterVar() { |
| 1828 parse3("parseClassMember", <Object>["C"], "var static f;", | 2344 createParser('var static f;'); |
| 1829 [ParserErrorCode.STATIC_AFTER_VAR]); | 2345 ClassMember member = parser.parseClassMember('C'); |
| 2346 expectNotNullIfNoErrors(member); |
| 2347 listener.assertErrorsWithCodes([ParserErrorCode.STATIC_AFTER_VAR]); |
| 1830 } | 2348 } |
| 1831 | 2349 |
| 1832 void test_staticConstructor() { | 2350 void test_staticConstructor() { |
| 1833 parse3("parseClassMember", <Object>["C"], "static C.m() {}", | 2351 createParser('static C.m() {}'); |
| 1834 [ParserErrorCode.STATIC_CONSTRUCTOR]); | 2352 ClassMember member = parser.parseClassMember('C'); |
| 2353 expectNotNullIfNoErrors(member); |
| 2354 listener.assertErrorsWithCodes([ParserErrorCode.STATIC_CONSTRUCTOR]); |
| 1835 } | 2355 } |
| 1836 | 2356 |
| 1837 void test_staticGetterWithoutBody() { | 2357 void test_staticGetterWithoutBody() { |
| 1838 parse3("parseClassMember", <Object>["C"], "static get m;", | 2358 createParser('static get m;'); |
| 1839 [ParserErrorCode.STATIC_GETTER_WITHOUT_BODY]); | 2359 ClassMember member = parser.parseClassMember('C'); |
| 2360 expectNotNullIfNoErrors(member); |
| 2361 listener |
| 2362 .assertErrorsWithCodes([ParserErrorCode.STATIC_GETTER_WITHOUT_BODY]); |
| 1840 } | 2363 } |
| 1841 | 2364 |
| 1842 void test_staticOperator_noReturnType() { | 2365 void test_staticOperator_noReturnType() { |
| 1843 parse3( | 2366 createParser('static operator +(int x) => x + 1;'); |
| 1844 "parseClassMember", | 2367 ClassMember member = parser.parseClassMember('C'); |
| 1845 <Object>["C"], | 2368 expectNotNullIfNoErrors(member); |
| 1846 "static operator +(int x) => x + 1;", | 2369 listener.assertErrorsWithCodes([ParserErrorCode.STATIC_OPERATOR]); |
| 1847 [ParserErrorCode.STATIC_OPERATOR]); | |
| 1848 } | 2370 } |
| 1849 | 2371 |
| 1850 void test_staticOperator_returnType() { | 2372 void test_staticOperator_returnType() { |
| 1851 parse3( | 2373 createParser('static int operator +(int x) => x + 1;'); |
| 1852 "parseClassMember", | 2374 ClassMember member = parser.parseClassMember('C'); |
| 1853 <Object>["C"], | 2375 expectNotNullIfNoErrors(member); |
| 1854 "static int operator +(int x) => x + 1;", | 2376 listener.assertErrorsWithCodes([ParserErrorCode.STATIC_OPERATOR]); |
| 1855 [ParserErrorCode.STATIC_OPERATOR]); | |
| 1856 } | 2377 } |
| 1857 | 2378 |
| 1858 void test_staticSetterWithoutBody() { | 2379 void test_staticSetterWithoutBody() { |
| 1859 parse3("parseClassMember", <Object>["C"], "static set m(x);", | 2380 createParser('static set m(x);'); |
| 1860 [ParserErrorCode.STATIC_SETTER_WITHOUT_BODY]); | 2381 ClassMember member = parser.parseClassMember('C'); |
| 2382 expectNotNullIfNoErrors(member); |
| 2383 listener |
| 2384 .assertErrorsWithCodes([ParserErrorCode.STATIC_SETTER_WITHOUT_BODY]); |
| 1861 } | 2385 } |
| 1862 | 2386 |
| 1863 void test_staticTopLevelDeclaration_class() { | 2387 void test_staticTopLevelDeclaration_class() { |
| 1864 ParserTestCase.parseCompilationUnit( | 2388 ParserTestCase.parseCompilationUnit( |
| 1865 "static class C {}", [ParserErrorCode.STATIC_TOP_LEVEL_DECLARATION]); | 2389 "static class C {}", [ParserErrorCode.STATIC_TOP_LEVEL_DECLARATION]); |
| 1866 } | 2390 } |
| 1867 | 2391 |
| 1868 void test_staticTopLevelDeclaration_function() { | 2392 void test_staticTopLevelDeclaration_function() { |
| 1869 ParserTestCase.parseCompilationUnit( | 2393 ParserTestCase.parseCompilationUnit( |
| 1870 "static f() {}", [ParserErrorCode.STATIC_TOP_LEVEL_DECLARATION]); | 2394 "static f() {}", [ParserErrorCode.STATIC_TOP_LEVEL_DECLARATION]); |
| 1871 } | 2395 } |
| 1872 | 2396 |
| 1873 void test_staticTopLevelDeclaration_typedef() { | 2397 void test_staticTopLevelDeclaration_typedef() { |
| 1874 ParserTestCase.parseCompilationUnit( | 2398 ParserTestCase.parseCompilationUnit( |
| 1875 "static typedef F();", [ParserErrorCode.STATIC_TOP_LEVEL_DECLARATION]); | 2399 "static typedef F();", [ParserErrorCode.STATIC_TOP_LEVEL_DECLARATION]); |
| 1876 } | 2400 } |
| 1877 | 2401 |
| 1878 void test_staticTopLevelDeclaration_variable() { | 2402 void test_staticTopLevelDeclaration_variable() { |
| 1879 ParserTestCase.parseCompilationUnit( | 2403 ParserTestCase.parseCompilationUnit( |
| 1880 "static var x;", [ParserErrorCode.STATIC_TOP_LEVEL_DECLARATION]); | 2404 "static var x;", [ParserErrorCode.STATIC_TOP_LEVEL_DECLARATION]); |
| 1881 } | 2405 } |
| 1882 | 2406 |
| 2407 void test_string_unterminated_interpolation_block() { |
| 2408 ParserTestCase.parseCompilationUnit( |
| 2409 r''' |
| 2410 m() { |
| 2411 { |
| 2412 '${${ |
| 2413 ''', |
| 2414 [ |
| 2415 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, |
| 2416 ParserErrorCode.EXPECTED_TOKEN, |
| 2417 ParserErrorCode.EXPECTED_TOKEN, |
| 2418 ParserErrorCode.EXPECTED_TOKEN, |
| 2419 ParserErrorCode.EXPECTED_TOKEN, |
| 2420 ParserErrorCode.EXPECTED_TOKEN, |
| 2421 ParserErrorCode.EXPECTED_TOKEN, |
| 2422 ]); |
| 2423 } |
| 2424 |
| 1883 void test_switchHasCaseAfterDefaultCase() { | 2425 void test_switchHasCaseAfterDefaultCase() { |
| 1884 parse4( | 2426 createParser('switch (a) {default: return 0; case 1: return 1;}'); |
| 1885 "parseSwitchStatement", | 2427 SwitchStatement statement = parser.parseSwitchStatement(); |
| 1886 "switch (a) {default: return 0; case 1: return 1;}", | 2428 expectNotNullIfNoErrors(statement); |
| 2429 listener.assertErrorsWithCodes( |
| 1887 [ParserErrorCode.SWITCH_HAS_CASE_AFTER_DEFAULT_CASE]); | 2430 [ParserErrorCode.SWITCH_HAS_CASE_AFTER_DEFAULT_CASE]); |
| 1888 } | 2431 } |
| 1889 | 2432 |
| 1890 void test_switchHasCaseAfterDefaultCase_repeated() { | 2433 void test_switchHasCaseAfterDefaultCase_repeated() { |
| 1891 parse4("parseSwitchStatement", | 2434 createParser( |
| 1892 "switch (a) {default: return 0; case 1: return 1; case 2: return 2;}", [ | 2435 'switch (a) {default: return 0; case 1: return 1; case 2: return 2;}'); |
| 2436 SwitchStatement statement = parser.parseSwitchStatement(); |
| 2437 expectNotNullIfNoErrors(statement); |
| 2438 listener.assertErrorsWithCodes([ |
| 1893 ParserErrorCode.SWITCH_HAS_CASE_AFTER_DEFAULT_CASE, | 2439 ParserErrorCode.SWITCH_HAS_CASE_AFTER_DEFAULT_CASE, |
| 1894 ParserErrorCode.SWITCH_HAS_CASE_AFTER_DEFAULT_CASE | 2440 ParserErrorCode.SWITCH_HAS_CASE_AFTER_DEFAULT_CASE |
| 1895 ]); | 2441 ]); |
| 1896 } | 2442 } |
| 1897 | 2443 |
| 1898 void test_switchHasMultipleDefaultCases() { | 2444 void test_switchHasMultipleDefaultCases() { |
| 1899 parse4( | 2445 createParser('switch (a) {default: return 0; default: return 1;}'); |
| 1900 "parseSwitchStatement", | 2446 SwitchStatement statement = parser.parseSwitchStatement(); |
| 1901 "switch (a) {default: return 0; default: return 1;}", | 2447 expectNotNullIfNoErrors(statement); |
| 2448 listener.assertErrorsWithCodes( |
| 1902 [ParserErrorCode.SWITCH_HAS_MULTIPLE_DEFAULT_CASES]); | 2449 [ParserErrorCode.SWITCH_HAS_MULTIPLE_DEFAULT_CASES]); |
| 1903 } | 2450 } |
| 1904 | 2451 |
| 1905 void test_switchHasMultipleDefaultCases_repeated() { | 2452 void test_switchHasMultipleDefaultCases_repeated() { |
| 1906 parse4( | 2453 createParser( |
| 1907 "parseSwitchStatement", | 2454 'switch (a) {default: return 0; default: return 1; default: return 2;}')
; |
| 1908 "switch (a) {default: return 0; default: return 1; default: return 2;}", | 2455 SwitchStatement statement = parser.parseSwitchStatement(); |
| 1909 [ | 2456 expectNotNullIfNoErrors(statement); |
| 2457 listener.assertErrorsWithCodes([ |
| 1910 ParserErrorCode.SWITCH_HAS_MULTIPLE_DEFAULT_CASES, | 2458 ParserErrorCode.SWITCH_HAS_MULTIPLE_DEFAULT_CASES, |
| 1911 ParserErrorCode.SWITCH_HAS_MULTIPLE_DEFAULT_CASES | 2459 ParserErrorCode.SWITCH_HAS_MULTIPLE_DEFAULT_CASES |
| 1912 ]); | 2460 ]); |
| 1913 } | 2461 } |
| 1914 | 2462 |
| 1915 void test_topLevel_getter() { | 2463 void test_topLevel_getter() { |
| 1916 FunctionDeclaration funct = parse3("parseCompilationUnitMember", | 2464 createParser('get x => 7;'); |
| 1917 <Object>[emptyCommentAndMetadata()], "get x => 7;"); | 2465 CompilationUnitMember member = |
| 1918 expect(funct.functionExpression.parameters, isNull); | 2466 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 2467 expectNotNullIfNoErrors(member); |
| 2468 listener.assertNoErrors(); |
| 2469 expect(member, new isInstanceOf<FunctionDeclaration>()); |
| 2470 FunctionDeclaration function = member; |
| 2471 expect(function.functionExpression.parameters, isNull); |
| 1919 } | 2472 } |
| 1920 | 2473 |
| 1921 void test_topLevelOperator_withoutType() { | 2474 void test_topLevelOperator_withoutType() { |
| 1922 parse3( | 2475 createParser('operator +(bool x, bool y) => x | y;'); |
| 1923 "parseCompilationUnitMember", | 2476 CompilationUnitMember member = |
| 1924 <Object>[emptyCommentAndMetadata()], | 2477 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 1925 "operator +(bool x, bool y) => x | y;", | 2478 expectNotNullIfNoErrors(member); |
| 1926 [ParserErrorCode.TOP_LEVEL_OPERATOR]); | 2479 listener.assertErrorsWithCodes([ParserErrorCode.TOP_LEVEL_OPERATOR]); |
| 1927 } | 2480 } |
| 1928 | 2481 |
| 1929 void test_topLevelOperator_withType() { | 2482 void test_topLevelOperator_withType() { |
| 1930 parse3( | 2483 createParser('bool operator +(bool x, bool y) => x | y;'); |
| 1931 "parseCompilationUnitMember", | 2484 CompilationUnitMember member = |
| 1932 <Object>[emptyCommentAndMetadata()], | 2485 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 1933 "bool operator +(bool x, bool y) => x | y;", | 2486 expectNotNullIfNoErrors(member); |
| 1934 [ParserErrorCode.TOP_LEVEL_OPERATOR]); | 2487 listener.assertErrorsWithCodes([ParserErrorCode.TOP_LEVEL_OPERATOR]); |
| 1935 } | 2488 } |
| 1936 | 2489 |
| 1937 void test_topLevelOperator_withVoid() { | 2490 void test_topLevelOperator_withVoid() { |
| 1938 parse3( | 2491 createParser('void operator +(bool x, bool y) => x | y;'); |
| 1939 "parseCompilationUnitMember", | 2492 CompilationUnitMember member = |
| 1940 <Object>[emptyCommentAndMetadata()], | 2493 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 1941 "void operator +(bool x, bool y) => x | y;", | 2494 expectNotNullIfNoErrors(member); |
| 1942 [ParserErrorCode.TOP_LEVEL_OPERATOR]); | 2495 listener.assertErrorsWithCodes([ParserErrorCode.TOP_LEVEL_OPERATOR]); |
| 1943 } | 2496 } |
| 1944 | 2497 |
| 1945 void test_topLevelVariable_withMetadata() { | 2498 void test_topLevelVariable_withMetadata() { |
| 1946 ParserTestCase.parseCompilationUnit("String @A string;", [ | 2499 ParserTestCase.parseCompilationUnit("String @A string;", [ |
| 1947 ParserErrorCode.MISSING_IDENTIFIER, | 2500 ParserErrorCode.MISSING_IDENTIFIER, |
| 1948 ParserErrorCode.EXPECTED_TOKEN, | 2501 ParserErrorCode.EXPECTED_TOKEN, |
| 1949 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE | 2502 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE |
| 1950 ]); | 2503 ]); |
| 1951 } | 2504 } |
| 1952 | 2505 |
| 1953 void test_typedefInClass_withoutReturnType() { | 2506 void test_typedefInClass_withoutReturnType() { |
| 1954 ParserTestCase.parseCompilationUnit( | 2507 ParserTestCase.parseCompilationUnit( |
| 1955 "class C { typedef F(x); }", [ParserErrorCode.TYPEDEF_IN_CLASS]); | 2508 "class C { typedef F(x); }", [ParserErrorCode.TYPEDEF_IN_CLASS]); |
| 1956 } | 2509 } |
| 1957 | 2510 |
| 1958 void test_typedefInClass_withReturnType() { | 2511 void test_typedefInClass_withReturnType() { |
| 1959 ParserTestCase.parseCompilationUnit("class C { typedef int F(int x); }", | 2512 ParserTestCase.parseCompilationUnit("class C { typedef int F(int x); }", |
| 1960 [ParserErrorCode.TYPEDEF_IN_CLASS]); | 2513 [ParserErrorCode.TYPEDEF_IN_CLASS]); |
| 1961 } | 2514 } |
| 1962 | 2515 |
| 1963 void test_unexpectedTerminatorForParameterGroup_named() { | 2516 void test_unexpectedTerminatorForParameterGroup_named() { |
| 1964 parse4("parseFormalParameterList", "(a, b})", | 2517 createParser('(a, b})'); |
| 2518 FormalParameterList list = parser.parseFormalParameterList(); |
| 2519 expectNotNullIfNoErrors(list); |
| 2520 listener.assertErrorsWithCodes( |
| 1965 [ParserErrorCode.UNEXPECTED_TERMINATOR_FOR_PARAMETER_GROUP]); | 2521 [ParserErrorCode.UNEXPECTED_TERMINATOR_FOR_PARAMETER_GROUP]); |
| 1966 } | 2522 } |
| 1967 | 2523 |
| 1968 void test_unexpectedTerminatorForParameterGroup_optional() { | 2524 void test_unexpectedTerminatorForParameterGroup_optional() { |
| 1969 parse4("parseFormalParameterList", "(a, b])", | 2525 createParser('(a, b])'); |
| 2526 FormalParameterList list = parser.parseFormalParameterList(); |
| 2527 expectNotNullIfNoErrors(list); |
| 2528 listener.assertErrorsWithCodes( |
| 1970 [ParserErrorCode.UNEXPECTED_TERMINATOR_FOR_PARAMETER_GROUP]); | 2529 [ParserErrorCode.UNEXPECTED_TERMINATOR_FOR_PARAMETER_GROUP]); |
| 1971 } | 2530 } |
| 1972 | 2531 |
| 1973 void test_unexpectedToken_endOfFieldDeclarationStatement() { | 2532 void test_unexpectedToken_endOfFieldDeclarationStatement() { |
| 1974 ParserTestCase.parseStatement( | 2533 ParserTestCase.parseStatement( |
| 1975 "String s = (null));", [ParserErrorCode.UNEXPECTED_TOKEN]); | 2534 "String s = (null));", [ParserErrorCode.UNEXPECTED_TOKEN]); |
| 1976 } | 2535 } |
| 1977 | 2536 |
| 2537 @failingTest |
| 2538 void test_unexpectedToken_invalidPostfixExpression() { |
| 2539 // Note: this might not be the right error to produce, but some error should |
| 2540 // be produced |
| 2541 parseExpression("f()++", [ParserErrorCode.UNEXPECTED_TOKEN]); |
| 2542 } |
| 2543 |
| 1978 void test_unexpectedToken_returnInExpressionFuntionBody() { | 2544 void test_unexpectedToken_returnInExpressionFuntionBody() { |
| 1979 ParserTestCase.parseCompilationUnit( | 2545 ParserTestCase.parseCompilationUnit( |
| 1980 "f() => return null;", [ParserErrorCode.UNEXPECTED_TOKEN]); | 2546 "f() => return null;", [ParserErrorCode.UNEXPECTED_TOKEN]); |
| 1981 } | 2547 } |
| 1982 | 2548 |
| 1983 void test_unexpectedToken_semicolonBetweenClassMembers() { | 2549 void test_unexpectedToken_semicolonBetweenClassMembers() { |
| 1984 parse3("parseClassDeclaration", <Object>[emptyCommentAndMetadata(), null], | 2550 createParser('class C { int x; ; int y;}'); |
| 1985 "class C { int x; ; int y;}", [ParserErrorCode.UNEXPECTED_TOKEN]); | 2551 ClassDeclaration declaration = |
| 2552 parser.parseClassDeclaration(emptyCommentAndMetadata(), null); |
| 2553 expectNotNullIfNoErrors(declaration); |
| 2554 listener.assertErrorsWithCodes([ParserErrorCode.UNEXPECTED_TOKEN]); |
| 1986 } | 2555 } |
| 1987 | 2556 |
| 1988 void test_unexpectedToken_semicolonBetweenCompilationUnitMembers() { | 2557 void test_unexpectedToken_semicolonBetweenCompilationUnitMembers() { |
| 1989 ParserTestCase.parseCompilationUnit( | 2558 ParserTestCase.parseCompilationUnit( |
| 1990 "int x; ; int y;", [ParserErrorCode.UNEXPECTED_TOKEN]); | 2559 "int x; ; int y;", [ParserErrorCode.UNEXPECTED_TOKEN]); |
| 1991 } | 2560 } |
| 1992 | 2561 |
| 1993 void test_unterminatedString_at_eof() { | 2562 void test_unterminatedString_at_eof() { |
| 1994 // Although the "unterminated string" error message is produced by the | 2563 // Although the "unterminated string" error message is produced by the |
| 1995 // scanner, we need to verify that the parser can handle the tokens | 2564 // scanner, we need to verify that the parser can handle the tokens |
| 1996 // produced by the scanner when an unterminated string is encountered. | 2565 // produced by the scanner when an unterminated string is encountered. |
| 1997 ParserTestCase.parseCompilationUnit( | 2566 ParserTestCase.parseCompilationUnit( |
| 1998 r''' | 2567 r''' |
| 1999 void main() { | 2568 void main() { |
| 2000 var x = "''', | 2569 var x = "''', |
| 2001 [ | 2570 [ |
| 2002 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, | 2571 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, |
| 2003 ParserErrorCode.EXPECTED_TOKEN, | 2572 ParserErrorCode.EXPECTED_TOKEN, |
| 2004 ParserErrorCode.EXPECTED_TOKEN | 2573 ParserErrorCode.EXPECTED_TOKEN |
| 2005 ]); | 2574 ]); |
| 2006 } | 2575 } |
| 2007 | 2576 |
| 2008 void test_unterminatedString_at_eol() { | 2577 void test_unterminatedString_at_eol() { |
| 2009 // Although the "unterminated string" error message is produced by the | 2578 // Although the "unterminated string" error message is produced by the |
| 2010 // scanner, we need to verify that the parser can handle the tokens | 2579 // scanner, we need to verify that the parser can handle the tokens |
| 2011 // produced by the scanner when an unterminated string is encountered. | 2580 // produced by the scanner when an unterminated string is encountered. |
| 2012 ParserTestCase.parseCompilationUnit( | 2581 ParserTestCase.parseCompilationUnit( |
| 2013 r''' | 2582 r''' |
| 2014 void main() { | 2583 void main() { |
| 2015 var x = " | 2584 var x = " |
| 2016 ; | 2585 ; |
| 2017 } | 2586 } |
| 2018 ''', | 2587 ''', |
| 2019 [ScannerErrorCode.UNTERMINATED_STRING_LITERAL]); | 2588 [ScannerErrorCode.UNTERMINATED_STRING_LITERAL]); |
| 2020 } | 2589 } |
| 2021 | 2590 |
| 2022 void test_unterminatedString_multiline_at_eof_3_quotes() { | 2591 void test_unterminatedString_multiline_at_eof_3_quotes() { |
| 2023 // Although the "unterminated string" error message is produced by the | 2592 // Although the "unterminated string" error message is produced by the |
| 2024 // scanner, we need to verify that the parser can handle the tokens | 2593 // scanner, we need to verify that the parser can handle the tokens |
| 2025 // produced by the scanner when an unterminated string is encountered. | 2594 // produced by the scanner when an unterminated string is encountered. |
| 2026 ParserTestCase.parseCompilationUnit( | 2595 ParserTestCase.parseCompilationUnit( |
| 2027 r''' | 2596 r''' |
| 2028 void main() { | 2597 void main() { |
| 2029 var x = """''', | 2598 var x = """''', |
| 2030 [ | 2599 [ |
| 2031 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, | 2600 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, |
| 2032 ParserErrorCode.EXPECTED_TOKEN, | 2601 ParserErrorCode.EXPECTED_TOKEN, |
| 2033 ParserErrorCode.EXPECTED_TOKEN | 2602 ParserErrorCode.EXPECTED_TOKEN |
| 2034 ]); | 2603 ]); |
| 2035 } | 2604 } |
| 2036 | 2605 |
| 2037 void test_unterminatedString_multiline_at_eof_4_quotes() { | 2606 void test_unterminatedString_multiline_at_eof_4_quotes() { |
| 2038 // Although the "unterminated string" error message is produced by the | 2607 // Although the "unterminated string" error message is produced by the |
| 2039 // scanner, we need to verify that the parser can handle the tokens | 2608 // scanner, we need to verify that the parser can handle the tokens |
| 2040 // produced by the scanner when an unterminated string is encountered. | 2609 // produced by the scanner when an unterminated string is encountered. |
| 2041 ParserTestCase.parseCompilationUnit( | 2610 ParserTestCase.parseCompilationUnit( |
| 2042 r''' | 2611 r''' |
| 2043 void main() { | 2612 void main() { |
| 2044 var x = """"''', | 2613 var x = """"''', |
| 2045 [ | 2614 [ |
| 2046 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, | 2615 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, |
| 2047 ParserErrorCode.EXPECTED_TOKEN, | 2616 ParserErrorCode.EXPECTED_TOKEN, |
| 2048 ParserErrorCode.EXPECTED_TOKEN | 2617 ParserErrorCode.EXPECTED_TOKEN |
| 2049 ]); | 2618 ]); |
| 2050 } | 2619 } |
| 2051 | 2620 |
| 2052 void test_unterminatedString_multiline_at_eof_5_quotes() { | 2621 void test_unterminatedString_multiline_at_eof_5_quotes() { |
| 2053 // Although the "unterminated string" error message is produced by the | 2622 // Although the "unterminated string" error message is produced by the |
| 2054 // scanner, we need to verify that the parser can handle the tokens | 2623 // scanner, we need to verify that the parser can handle the tokens |
| 2055 // produced by the scanner when an unterminated string is encountered. | 2624 // produced by the scanner when an unterminated string is encountered. |
| 2056 ParserTestCase.parseCompilationUnit( | 2625 ParserTestCase.parseCompilationUnit( |
| 2057 r''' | 2626 r''' |
| 2058 void main() { | 2627 void main() { |
| 2059 var x = """""''', | 2628 var x = """""''', |
| 2060 [ | 2629 [ |
| 2061 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, | 2630 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, |
| 2062 ParserErrorCode.EXPECTED_TOKEN, | 2631 ParserErrorCode.EXPECTED_TOKEN, |
| 2063 ParserErrorCode.EXPECTED_TOKEN | 2632 ParserErrorCode.EXPECTED_TOKEN |
| 2064 ]); | 2633 ]); |
| 2065 } | 2634 } |
| 2066 | 2635 |
| 2067 void test_useOfUnaryPlusOperator() { | 2636 void test_useOfUnaryPlusOperator() { |
| 2068 SimpleIdentifier expression = parse4( | 2637 createParser('+x'); |
| 2069 "parseUnaryExpression", "+x", [ParserErrorCode.MISSING_IDENTIFIER]); | 2638 Expression expression = parser.parseUnaryExpression(); |
| 2070 EngineTestCase.assertInstanceOf( | 2639 expectNotNullIfNoErrors(expression); |
| 2071 (obj) => obj is SimpleIdentifier, SimpleIdentifier, expression); | 2640 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| 2072 expect(expression.isSynthetic, isTrue); | 2641 expect(expression, new isInstanceOf<SimpleIdentifier>()); |
| 2642 SimpleIdentifier identifier = expression; |
| 2643 expect(identifier.isSynthetic, isTrue); |
| 2073 } | 2644 } |
| 2074 | 2645 |
| 2075 void test_varAndType_field() { | 2646 void test_varAndType_field() { |
| 2076 ParserTestCase.parseCompilationUnit( | 2647 ParserTestCase.parseCompilationUnit( |
| 2077 "class C { var int x; }", [ParserErrorCode.VAR_AND_TYPE]); | 2648 "class C { var int x; }", [ParserErrorCode.VAR_AND_TYPE]); |
| 2078 } | 2649 } |
| 2079 | 2650 |
| 2651 @failingTest |
| 2652 void test_varAndType_local() { |
| 2653 // This is currently reporting EXPECTED_TOKEN for a missing semicolon, but |
| 2654 // this would be a better error message. |
| 2655 ParserTestCase.parseStatement("var int x;", [ParserErrorCode.VAR_AND_TYPE]); |
| 2656 } |
| 2657 |
| 2658 @failingTest |
| 2659 void test_varAndType_parameter() { |
| 2660 // This is currently reporting EXPECTED_TOKEN for a missing semicolon, but |
| 2661 // this would be a better error message. |
| 2662 createParser('(var int x)'); |
| 2663 FormalParameterList list = parser.parseFormalParameterList(); |
| 2664 expectNotNullIfNoErrors(list); |
| 2665 listener.assertErrorsWithCodes([ParserErrorCode.VAR_AND_TYPE]); |
| 2666 } |
| 2667 |
| 2080 void test_varAndType_topLevelVariable() { | 2668 void test_varAndType_topLevelVariable() { |
| 2081 ParserTestCase.parseCompilationUnit( | 2669 ParserTestCase |
| 2082 "var int x;", [ParserErrorCode.VAR_AND_TYPE]); | 2670 .parseCompilationUnit("var int x;", [ParserErrorCode.VAR_AND_TYPE]); |
| 2083 } | 2671 } |
| 2084 | 2672 |
| 2085 void test_varAsTypeName_as() { | 2673 void test_varAsTypeName_as() { |
| 2086 parseExpression("x as var", [ParserErrorCode.VAR_AS_TYPE_NAME]); | 2674 parseExpression("x as var", [ParserErrorCode.VAR_AS_TYPE_NAME]); |
| 2087 } | 2675 } |
| 2088 | 2676 |
| 2089 void test_varClass() { | 2677 void test_varClass() { |
| 2090 ParserTestCase.parseCompilationUnit( | 2678 ParserTestCase |
| 2091 "var class C {}", [ParserErrorCode.VAR_CLASS]); | 2679 .parseCompilationUnit("var class C {}", [ParserErrorCode.VAR_CLASS]); |
| 2092 } | 2680 } |
| 2093 | 2681 |
| 2094 void test_varEnum() { | 2682 void test_varEnum() { |
| 2095 ParserTestCase.parseCompilationUnit( | 2683 ParserTestCase |
| 2096 "var enum E {ONE}", [ParserErrorCode.VAR_ENUM]); | 2684 .parseCompilationUnit("var enum E {ONE}", [ParserErrorCode.VAR_ENUM]); |
| 2097 } | 2685 } |
| 2098 | 2686 |
| 2099 void test_varReturnType() { | 2687 void test_varReturnType() { |
| 2100 parse3("parseClassMember", <Object>["C"], "var m() {}", | 2688 createParser('var m() {}'); |
| 2101 [ParserErrorCode.VAR_RETURN_TYPE]); | 2689 ClassMember member = parser.parseClassMember('C'); |
| 2690 expectNotNullIfNoErrors(member); |
| 2691 listener.assertErrorsWithCodes([ParserErrorCode.VAR_RETURN_TYPE]); |
| 2102 } | 2692 } |
| 2103 | 2693 |
| 2104 void test_varTypedef() { | 2694 void test_varTypedef() { |
| 2105 ParserTestCase.parseCompilationUnit( | 2695 ParserTestCase.parseCompilationUnit( |
| 2106 "var typedef F();", [ParserErrorCode.VAR_TYPEDEF]); | 2696 "var typedef F();", [ParserErrorCode.VAR_TYPEDEF]); |
| 2107 } | 2697 } |
| 2108 | 2698 |
| 2109 void test_voidParameter() { | 2699 void test_voidParameter() { |
| 2110 parse4("parseNormalFormalParameter", "void a)", | 2700 createParser('void a)'); |
| 2111 [ParserErrorCode.VOID_PARAMETER]); | 2701 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); |
| 2702 expectNotNullIfNoErrors(parameter); |
| 2703 listener.assertErrorsWithCodes([ParserErrorCode.VOID_PARAMETER]); |
| 2112 } | 2704 } |
| 2113 | 2705 |
| 2114 void test_voidVariable_parseClassMember_initializer() { | 2706 void test_voidVariable_parseClassMember_initializer() { |
| 2115 parse3("parseClassMember", <Object>["C"], "void x = 0;", | 2707 createParser('void x = 0;'); |
| 2116 [ParserErrorCode.VOID_VARIABLE]); | 2708 ClassMember member = parser.parseClassMember('C'); |
| 2709 expectNotNullIfNoErrors(member); |
| 2710 listener.assertErrorsWithCodes([ParserErrorCode.VOID_VARIABLE]); |
| 2117 } | 2711 } |
| 2118 | 2712 |
| 2119 void test_voidVariable_parseClassMember_noInitializer() { | 2713 void test_voidVariable_parseClassMember_noInitializer() { |
| 2120 parse3("parseClassMember", <Object>["C"], "void x;", | 2714 createParser('void x;'); |
| 2121 [ParserErrorCode.VOID_VARIABLE]); | 2715 ClassMember member = parser.parseClassMember('C'); |
| 2716 expectNotNullIfNoErrors(member); |
| 2717 listener.assertErrorsWithCodes([ParserErrorCode.VOID_VARIABLE]); |
| 2122 } | 2718 } |
| 2123 | 2719 |
| 2124 void test_voidVariable_parseCompilationUnit_initializer() { | 2720 void test_voidVariable_parseCompilationUnit_initializer() { |
| 2125 ParserTestCase.parseCompilationUnit( | 2721 ParserTestCase |
| 2126 "void x = 0;", [ParserErrorCode.VOID_VARIABLE]); | 2722 .parseCompilationUnit("void x = 0;", [ParserErrorCode.VOID_VARIABLE]); |
| 2127 } | 2723 } |
| 2128 | 2724 |
| 2129 void test_voidVariable_parseCompilationUnit_noInitializer() { | 2725 void test_voidVariable_parseCompilationUnit_noInitializer() { |
| 2130 ParserTestCase.parseCompilationUnit( | 2726 ParserTestCase |
| 2131 "void x;", [ParserErrorCode.VOID_VARIABLE]); | 2727 .parseCompilationUnit("void x;", [ParserErrorCode.VOID_VARIABLE]); |
| 2132 } | 2728 } |
| 2133 | 2729 |
| 2134 void test_voidVariable_parseCompilationUnitMember_initializer() { | 2730 void test_voidVariable_parseCompilationUnitMember_initializer() { |
| 2135 parse3("parseCompilationUnitMember", <Object>[emptyCommentAndMetadata()], | 2731 createParser('void a = 0;'); |
| 2136 "void a = 0;", [ParserErrorCode.VOID_VARIABLE]); | 2732 CompilationUnitMember member = |
| 2733 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 2734 expectNotNullIfNoErrors(member); |
| 2735 listener.assertErrorsWithCodes([ParserErrorCode.VOID_VARIABLE]); |
| 2137 } | 2736 } |
| 2138 | 2737 |
| 2139 void test_voidVariable_parseCompilationUnitMember_noInitializer() { | 2738 void test_voidVariable_parseCompilationUnitMember_noInitializer() { |
| 2140 parse3("parseCompilationUnitMember", <Object>[emptyCommentAndMetadata()], | 2739 createParser('void a;'); |
| 2141 "void a;", [ParserErrorCode.VOID_VARIABLE]); | 2740 CompilationUnitMember member = |
| 2741 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 2742 expectNotNullIfNoErrors(member); |
| 2743 listener.assertErrorsWithCodes([ParserErrorCode.VOID_VARIABLE]); |
| 2142 } | 2744 } |
| 2143 | 2745 |
| 2144 void test_voidVariable_statement_initializer() { | 2746 void test_voidVariable_statement_initializer() { |
| 2145 ParserTestCase.parseStatement("void x = 0;", [ | 2747 ParserTestCase.parseStatement("void x = 0;", [ |
| 2146 ParserErrorCode.VOID_VARIABLE, | 2748 ParserErrorCode.VOID_VARIABLE, |
| 2147 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE | 2749 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE |
| 2148 ]); | 2750 ]); |
| 2149 } | 2751 } |
| 2150 | 2752 |
| 2151 void test_voidVariable_statement_noInitializer() { | 2753 void test_voidVariable_statement_noInitializer() { |
| 2152 ParserTestCase.parseStatement("void x;", [ | 2754 ParserTestCase.parseStatement("void x;", [ |
| 2153 ParserErrorCode.VOID_VARIABLE, | 2755 ParserErrorCode.VOID_VARIABLE, |
| 2154 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE | 2756 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE |
| 2155 ]); | 2757 ]); |
| 2156 } | 2758 } |
| 2157 | 2759 |
| 2158 void test_withBeforeExtends() { | 2760 void test_withBeforeExtends() { |
| 2159 ParserTestCase.parseCompilationUnit( | 2761 ParserTestCase.parseCompilationUnit( |
| 2160 "class A with B extends C {}", [ParserErrorCode.WITH_BEFORE_EXTENDS]); | 2762 "class A with B extends C {}", [ParserErrorCode.WITH_BEFORE_EXTENDS]); |
| 2161 } | 2763 } |
| 2162 | 2764 |
| 2163 void test_withWithoutExtends() { | 2765 void test_withWithoutExtends() { |
| 2164 parse3("parseClassDeclaration", <Object>[emptyCommentAndMetadata(), null], | 2766 createParser('class A with B, C {}'); |
| 2165 "class A with B, C {}", [ParserErrorCode.WITH_WITHOUT_EXTENDS]); | 2767 ClassDeclaration declaration = |
| 2768 parser.parseClassDeclaration(emptyCommentAndMetadata(), null); |
| 2769 expectNotNullIfNoErrors(declaration); |
| 2770 listener.assertErrorsWithCodes([ParserErrorCode.WITH_WITHOUT_EXTENDS]); |
| 2166 } | 2771 } |
| 2167 | 2772 |
| 2168 void test_wrongSeparatorForNamedParameter() { | 2773 void test_wrongSeparatorForNamedParameter() { |
| 2169 parse4("parseFormalParameterList", "(a, {b = 0})", | 2774 createParser('(a, {b = 0})'); |
| 2775 FormalParameterList list = parser.parseFormalParameterList(); |
| 2776 expectNotNullIfNoErrors(list); |
| 2777 listener.assertErrorsWithCodes( |
| 2170 [ParserErrorCode.WRONG_SEPARATOR_FOR_NAMED_PARAMETER]); | 2778 [ParserErrorCode.WRONG_SEPARATOR_FOR_NAMED_PARAMETER]); |
| 2171 } | 2779 } |
| 2172 | 2780 |
| 2173 void test_wrongSeparatorForPositionalParameter() { | 2781 void test_wrongSeparatorForPositionalParameter() { |
| 2174 parse4("parseFormalParameterList", "(a, [b : 0])", | 2782 createParser('(a, [b : 0])'); |
| 2783 FormalParameterList list = parser.parseFormalParameterList(); |
| 2784 expectNotNullIfNoErrors(list); |
| 2785 listener.assertErrorsWithCodes( |
| 2175 [ParserErrorCode.WRONG_SEPARATOR_FOR_POSITIONAL_PARAMETER]); | 2786 [ParserErrorCode.WRONG_SEPARATOR_FOR_POSITIONAL_PARAMETER]); |
| 2176 } | 2787 } |
| 2177 | 2788 |
| 2178 void test_wrongTerminatorForParameterGroup_named() { | 2789 void test_wrongTerminatorForParameterGroup_named() { |
| 2179 parse4("parseFormalParameterList", "(a, {b, c])", | 2790 createParser('(a, {b, c])'); |
| 2791 FormalParameterList list = parser.parseFormalParameterList(); |
| 2792 expectNotNullIfNoErrors(list); |
| 2793 listener.assertErrorsWithCodes( |
| 2180 [ParserErrorCode.WRONG_TERMINATOR_FOR_PARAMETER_GROUP]); | 2794 [ParserErrorCode.WRONG_TERMINATOR_FOR_PARAMETER_GROUP]); |
| 2181 } | 2795 } |
| 2182 | 2796 |
| 2183 void test_wrongTerminatorForParameterGroup_optional() { | 2797 void test_wrongTerminatorForParameterGroup_optional() { |
| 2184 parse4("parseFormalParameterList", "(a, [b, c})", | 2798 createParser('(a, [b, c})'); |
| 2799 FormalParameterList list = parser.parseFormalParameterList(); |
| 2800 expectNotNullIfNoErrors(list); |
| 2801 listener.assertErrorsWithCodes( |
| 2185 [ParserErrorCode.WRONG_TERMINATOR_FOR_PARAMETER_GROUP]); | 2802 [ParserErrorCode.WRONG_TERMINATOR_FOR_PARAMETER_GROUP]); |
| 2186 } | 2803 } |
| 2187 } | 2804 } |
| 2188 | 2805 |
| 2189 @reflectiveTest | 2806 @reflectiveTest |
| 2190 class IncrementalParserTest extends EngineTestCase { | |
| 2191 void fail_replace_identifier_with_functionLiteral_in_initializer_interp() { | |
| 2192 // TODO(paulberry, brianwilkerson): broken due to incremental scanning bugs | |
| 2193 | |
| 2194 // Function literals are allowed inside interpolation expressions in | |
| 2195 // initializers. | |
| 2196 // | |
| 2197 // 'class A { var a; A(b) : a = "${b}";' | |
| 2198 // 'class A { var a; A(b) : a = "${() {}}";' | |
| 2199 _assertParse(r'class A { var a; A(b) : a = "${', 'b', '() {}', '}";'); | |
| 2200 } | |
| 2201 | |
| 2202 void test_delete_everything() { | |
| 2203 // "f() => a + b;" | |
| 2204 // "" | |
| 2205 _assertParse("", "f() => a + b;", "", ""); | |
| 2206 } | |
| 2207 | |
| 2208 void test_delete_identifier_beginning() { | |
| 2209 // "f() => abs + b;" | |
| 2210 // "f() => s + b;" | |
| 2211 _assertParse("f() => ", "ab", "", "s + b;"); | |
| 2212 } | |
| 2213 | |
| 2214 void test_delete_identifier_end() { | |
| 2215 // "f() => abs + b;" | |
| 2216 // "f() => a + b;" | |
| 2217 _assertParse("f() => a", "bs", "", " + b;"); | |
| 2218 } | |
| 2219 | |
| 2220 void test_delete_identifier_middle() { | |
| 2221 // "f() => abs + b;" | |
| 2222 // "f() => as + b;" | |
| 2223 _assertParse("f() => a", "b", "", "s + b;"); | |
| 2224 } | |
| 2225 | |
| 2226 void test_delete_mergeTokens() { | |
| 2227 // "f() => a + b + c;" | |
| 2228 // "f() => ac;" | |
| 2229 _assertParse("f() => a", " + b + ", "", "c;"); | |
| 2230 } | |
| 2231 | |
| 2232 void test_insert_afterIdentifier1() { | |
| 2233 // "f() => a + b;" | |
| 2234 // "f() => abs + b;" | |
| 2235 _assertParse("f() => a", "", "bs", " + b;"); | |
| 2236 } | |
| 2237 | |
| 2238 void test_insert_afterIdentifier2() { | |
| 2239 // "f() => a + b;" | |
| 2240 // "f() => a + bar;" | |
| 2241 _assertParse("f() => a + b", "", "ar", ";"); | |
| 2242 } | |
| 2243 | |
| 2244 void test_insert_beforeIdentifier1() { | |
| 2245 // "f() => a + b;" | |
| 2246 // "f() => xa + b;" | |
| 2247 _assertParse("f() => ", "", "x", "a + b;"); | |
| 2248 } | |
| 2249 | |
| 2250 void test_insert_beforeIdentifier2() { | |
| 2251 // "f() => a + b;" | |
| 2252 // "f() => a + xb;" | |
| 2253 _assertParse("f() => a + ", "", "x", "b;"); | |
| 2254 } | |
| 2255 | |
| 2256 void test_insert_convertOneFunctionToTwo() { | |
| 2257 // "f() {}" | |
| 2258 // "f() => 0; g() {}" | |
| 2259 _assertParse("f()", "", " => 0; g()", " {}"); | |
| 2260 } | |
| 2261 | |
| 2262 void test_insert_end() { | |
| 2263 // "class A {}" | |
| 2264 // "class A {} class B {}" | |
| 2265 _assertParse("class A {}", "", " class B {}", ""); | |
| 2266 } | |
| 2267 | |
| 2268 void test_insert_final_before_field_declaration() { | |
| 2269 _assertParse('class C { ', '', 'final ', 'int x; }'); | |
| 2270 } | |
| 2271 | |
| 2272 void test_insert_function_parameter() { | |
| 2273 _assertParse('class C { void f(', '', 'arg', ') {} }'); | |
| 2274 } | |
| 2275 | |
| 2276 void test_insert_identifier_inCombinator() { | |
| 2277 _assertParse("import 'foo.dart' show x", "", ", y", ";"); | |
| 2278 } | |
| 2279 | |
| 2280 void test_insert_insideClassBody() { | |
| 2281 // "class C {C(); }" | |
| 2282 // "class C { C(); }" | |
| 2283 _assertParse("class C {", "", " ", "C(); }"); | |
| 2284 } | |
| 2285 | |
| 2286 void test_insert_insideIdentifier() { | |
| 2287 // "f() => cob;" | |
| 2288 // "f() => cow.b;" | |
| 2289 _assertParse("f() => co", "", "w.", "b;"); | |
| 2290 } | |
| 2291 | |
| 2292 void test_insert_newIdentifier1() { | |
| 2293 // "f() => a; c;" | |
| 2294 // "f() => a; b c;" | |
| 2295 _assertParse("f() => a;", "", " b", " c;"); | |
| 2296 } | |
| 2297 | |
| 2298 void test_insert_newIdentifier2() { | |
| 2299 // "f() => a; c;" | |
| 2300 // "f() => a;b c;" | |
| 2301 _assertParse("f() => a;", "", "b", " c;"); | |
| 2302 } | |
| 2303 | |
| 2304 void test_insert_newIdentifier3() { | |
| 2305 // "/** A simple function. */ f() => a; c;" | |
| 2306 // "/** A simple function. */ f() => a; b c;" | |
| 2307 _assertParse("/** A simple function. */ f() => a;", "", " b", " c;"); | |
| 2308 } | |
| 2309 | |
| 2310 void test_insert_newIdentifier4() { | |
| 2311 // "/** An [A]. */ class A {} class B { m() { return 1; } }" | |
| 2312 // "/** An [A]. */ class A {} class B { m() { return 1 + 2; } }" | |
| 2313 _assertParse("/** An [A]. */ class A {} class B { m() { return 1", "", | |
| 2314 " + 2", "; } }"); | |
| 2315 } | |
| 2316 | |
| 2317 void test_insert_period() { | |
| 2318 // "f() => a + b;" | |
| 2319 // "f() => a + b.;" | |
| 2320 _assertParse("f() => a + b", "", ".", ";"); | |
| 2321 } | |
| 2322 | |
| 2323 void test_insert_period_betweenIdentifiers1() { | |
| 2324 // "f() => a b;" | |
| 2325 // "f() => a. b;" | |
| 2326 _assertParse("f() => a", "", ".", " b;"); | |
| 2327 } | |
| 2328 | |
| 2329 void test_insert_period_betweenIdentifiers2() { | |
| 2330 // "f() => a b;" | |
| 2331 // "f() => a .b;" | |
| 2332 _assertParse("f() => a ", "", ".", "b;"); | |
| 2333 } | |
| 2334 | |
| 2335 void test_insert_period_betweenIdentifiers3() { | |
| 2336 // "f() => a b;" | |
| 2337 // "f() => a . b;" | |
| 2338 _assertParse("f() => a ", "", ".", " b;"); | |
| 2339 } | |
| 2340 | |
| 2341 void test_insert_period_insideExistingIdentifier() { | |
| 2342 // "f() => ab;" | |
| 2343 // "f() => a.b;" | |
| 2344 _assertParse("f() => a", "", ".", "b;"); | |
| 2345 } | |
| 2346 | |
| 2347 void test_insert_periodAndIdentifier() { | |
| 2348 // "f() => a + b;" | |
| 2349 // "f() => a + b.x;" | |
| 2350 _assertParse("f() => a + b", "", ".x", ";"); | |
| 2351 } | |
| 2352 | |
| 2353 void test_insert_simpleToComplexExression() { | |
| 2354 // "/** An [A]. */ class A {} class B { m() => 1; }" | |
| 2355 // "/** An [A]. */ class A {} class B { m() => 1 + 2; }" | |
| 2356 _assertParse( | |
| 2357 "/** An [A]. */ class A {} class B { m() => 1", "", " + 2", "; }"); | |
| 2358 } | |
| 2359 | |
| 2360 void test_insert_statement_in_method_with_mismatched_braces() { | |
| 2361 _assertParse( | |
| 2362 ''' | |
| 2363 class C { | |
| 2364 void f() { | |
| 2365 ''', | |
| 2366 '', | |
| 2367 'g();', | |
| 2368 ''' | |
| 2369 if (b) { | |
| 2370 | |
| 2371 | |
| 2372 } | |
| 2373 | |
| 2374 void g() { | |
| 2375 h((x) {}); | |
| 2376 } | |
| 2377 } | |
| 2378 '''); | |
| 2379 } | |
| 2380 | |
| 2381 void test_insert_whitespace_end() { | |
| 2382 // "f() => a + b;" | |
| 2383 // "f() => a + b; " | |
| 2384 _assertParse("f() => a + b;", "", " ", ""); | |
| 2385 } | |
| 2386 | |
| 2387 void test_insert_whitespace_end_multiple() { | |
| 2388 // "f() => a + b;" | |
| 2389 // "f() => a + b; " | |
| 2390 _assertParse("f() => a + b;", "", " ", ""); | |
| 2391 } | |
| 2392 | |
| 2393 void test_insert_whitespace_middle() { | |
| 2394 // "f() => a + b;" | |
| 2395 // "f() => a + b;" | |
| 2396 _assertParse("f() => a", "", " ", " + b;"); | |
| 2397 } | |
| 2398 | |
| 2399 void test_rename_class_withConstructor() { | |
| 2400 // "class C { C() {} }" | |
| 2401 // "class D { C() {} }" | |
| 2402 _assertParse('class ', 'C', 'D', ' { C() {} }'); | |
| 2403 } | |
| 2404 | |
| 2405 void test_replace_field_type_with_void() { | |
| 2406 // Note: this produces an error, but we still need the parser to produce a | |
| 2407 // consistent parse tree for it. | |
| 2408 _assertParse('class C { ', 'int', 'void', ' x; }'); | |
| 2409 } | |
| 2410 | |
| 2411 void test_replace_identifier_beginning() { | |
| 2412 // "f() => bell + b;" | |
| 2413 // "f() => fell + b;" | |
| 2414 _assertParse("f() => ", "b", "f", "ell + b;"); | |
| 2415 } | |
| 2416 | |
| 2417 void test_replace_identifier_end() { | |
| 2418 // "f() => bell + b;" | |
| 2419 // "f() => belt + b;" | |
| 2420 _assertParse("f() => bel", "l", "t", " + b;"); | |
| 2421 } | |
| 2422 | |
| 2423 void test_replace_identifier_middle() { | |
| 2424 // "f() => first + b;" | |
| 2425 // "f() => frost + b;" | |
| 2426 _assertParse("f() => f", "ir", "ro", "st + b;"); | |
| 2427 } | |
| 2428 | |
| 2429 void test_replace_identifier_with_functionLiteral_in_initializer() { | |
| 2430 // Function literals aren't allowed inside initializers; incremental parsing | |
| 2431 // needs to gather the appropriate context. | |
| 2432 // | |
| 2433 // "class A { var a; A(b) : a = b ? b : 0 { } }" | |
| 2434 // "class A { var a; A(b) : a = b ? () {} : 0 { } }" | |
| 2435 _assertParse( | |
| 2436 "class A { var a; A(b) : a = b ? ", "b", "() {}", " : 0 { } }"); | |
| 2437 } | |
| 2438 | |
| 2439 void test_replace_identifier_with_functionLiteral_in_initializer_index() { | |
| 2440 // Function literals are allowed inside index expressions in initializers. | |
| 2441 // | |
| 2442 // "class A { var a; A(b) : a = b[b];" | |
| 2443 // "class A { var a; A(b) : a = b[() {}];" | |
| 2444 _assertParse('class A { var a; A(b) : a = b[', 'b', '() {}', '];'); | |
| 2445 } | |
| 2446 | |
| 2447 void test_replace_identifier_with_functionLiteral_in_initializer_list() { | |
| 2448 // Function literals are allowed inside list literals in initializers. | |
| 2449 // | |
| 2450 // "class A { var a; A(b) : a = [b];" | |
| 2451 // "class A { var a; A(b) : a = [() {}];" | |
| 2452 _assertParse('class A { var a; A(b) : a = [', 'b', '() {}', '];'); | |
| 2453 } | |
| 2454 | |
| 2455 void test_replace_identifier_with_functionLiteral_in_initializer_map() { | |
| 2456 // Function literals are allowed inside map literals in initializers. | |
| 2457 // | |
| 2458 // "class A { var a; A(b) : a = {0: b};" | |
| 2459 // "class A { var a; A(b) : a = {0: () {}};" | |
| 2460 _assertParse('class A { var a; A(b) : a = {0: ', 'b', '() {}', '};'); | |
| 2461 } | |
| 2462 | |
| 2463 void test_replace_identifier_with_functionLiteral_in_initializer_parens() { | |
| 2464 // Function literals are allowed inside parentheses in initializers. | |
| 2465 // | |
| 2466 // "class A { var a; A(b) : a = (b);" | |
| 2467 // "class A { var a; A(b) : a = (() {});" | |
| 2468 _assertParse('class A { var a; A(b) : a = (', 'b', '() {}', ');'); | |
| 2469 } | |
| 2470 | |
| 2471 void test_replace_multiple_partialFirstAndLast() { | |
| 2472 // "f() => aa + bb;" | |
| 2473 // "f() => ab * ab;" | |
| 2474 _assertParse("f() => a", "a + b", "b * a", "b;"); | |
| 2475 } | |
| 2476 | |
| 2477 void test_replace_operator_oneForMany() { | |
| 2478 // "f() => a + b;" | |
| 2479 // "f() => a * c - b;" | |
| 2480 _assertParse("f() => a ", "+", "* c -", " b;"); | |
| 2481 } | |
| 2482 | |
| 2483 void test_replace_operator_oneForOne() { | |
| 2484 // "f() => a + b;" | |
| 2485 // "f() => a * b;" | |
| 2486 _assertParse("f() => a ", "+", "*", " b;"); | |
| 2487 } | |
| 2488 | |
| 2489 void test_split_combinator() { | |
| 2490 // "import 'foo.dart' show A;" | |
| 2491 // "import 'foo.dart' show B hide A;" | |
| 2492 _assertParse("import 'foo.dart' show ", "", "B hide ", "A;"); | |
| 2493 } | |
| 2494 | |
| 2495 /** | |
| 2496 * Given a description of the original and modified contents, perform an incre
mental scan of the | |
| 2497 * two pieces of text. | |
| 2498 * | |
| 2499 * @param prefix the unchanged text before the edit region | |
| 2500 * @param removed the text that was removed from the original contents | |
| 2501 * @param added the text that was added to the modified contents | |
| 2502 * @param suffix the unchanged text after the edit region | |
| 2503 */ | |
| 2504 void _assertParse( | |
| 2505 String prefix, String removed, String added, String suffix) { | |
| 2506 // | |
| 2507 // Compute the information needed to perform the test. | |
| 2508 // | |
| 2509 String originalContents = "$prefix$removed$suffix"; | |
| 2510 String modifiedContents = "$prefix$added$suffix"; | |
| 2511 int replaceStart = prefix.length; | |
| 2512 Source source = new TestSource(); | |
| 2513 // | |
| 2514 // Parse the original contents. | |
| 2515 // | |
| 2516 GatheringErrorListener originalListener = new GatheringErrorListener(); | |
| 2517 Scanner originalScanner = new Scanner( | |
| 2518 source, new CharSequenceReader(originalContents), originalListener); | |
| 2519 Token originalTokens = originalScanner.tokenize(); | |
| 2520 expect(originalTokens, isNotNull); | |
| 2521 Parser originalParser = new Parser(source, originalListener); | |
| 2522 CompilationUnit originalUnit = | |
| 2523 originalParser.parseCompilationUnit(originalTokens); | |
| 2524 expect(originalUnit, isNotNull); | |
| 2525 // | |
| 2526 // Parse the modified contents. | |
| 2527 // | |
| 2528 GatheringErrorListener modifiedListener = new GatheringErrorListener(); | |
| 2529 Scanner modifiedScanner = new Scanner( | |
| 2530 source, new CharSequenceReader(modifiedContents), modifiedListener); | |
| 2531 Token modifiedTokens = modifiedScanner.tokenize(); | |
| 2532 expect(modifiedTokens, isNotNull); | |
| 2533 Parser modifiedParser = new Parser(source, modifiedListener); | |
| 2534 CompilationUnit modifiedUnit = | |
| 2535 modifiedParser.parseCompilationUnit(modifiedTokens); | |
| 2536 expect(modifiedUnit, isNotNull); | |
| 2537 // | |
| 2538 // Incrementally parse the modified contents. | |
| 2539 // | |
| 2540 GatheringErrorListener incrementalListener = new GatheringErrorListener(); | |
| 2541 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | |
| 2542 IncrementalScanner incrementalScanner = new IncrementalScanner(source, | |
| 2543 new CharSequenceReader(modifiedContents), incrementalListener, options); | |
| 2544 Token incrementalTokens = incrementalScanner.rescan( | |
| 2545 originalTokens, replaceStart, removed.length, added.length); | |
| 2546 expect(incrementalTokens, isNotNull); | |
| 2547 IncrementalParser incrementalParser = new IncrementalParser( | |
| 2548 source, incrementalScanner.tokenMap, incrementalListener); | |
| 2549 CompilationUnit incrementalUnit = incrementalParser.reparse( | |
| 2550 originalUnit, | |
| 2551 incrementalScanner.leftToken, | |
| 2552 incrementalScanner.rightToken, | |
| 2553 replaceStart, | |
| 2554 prefix.length + removed.length); | |
| 2555 expect(incrementalUnit, isNotNull); | |
| 2556 // | |
| 2557 // Validate that the results of the incremental parse are the same as the | |
| 2558 // full parse of the modified source. | |
| 2559 // | |
| 2560 expect(AstComparator.equalNodes(modifiedUnit, incrementalUnit), isTrue); | |
| 2561 // TODO(brianwilkerson) Verify that the errors are correct? | |
| 2562 } | |
| 2563 } | |
| 2564 | |
| 2565 @reflectiveTest | |
| 2566 class NonErrorParserTest extends ParserTestCase { | 2807 class NonErrorParserTest extends ParserTestCase { |
| 2567 void test_constFactory_external() { | 2808 void test_constFactory_external() { |
| 2568 parse("parseClassMember", <Object>["C"], "external const factory C();"); | 2809 createParser('external const factory C();'); |
| 2810 ClassMember member = parser.parseClassMember('C'); |
| 2811 expectNotNullIfNoErrors(member); |
| 2812 listener.assertNoErrors(); |
| 2569 } | 2813 } |
| 2570 | 2814 |
| 2571 void test_staticMethod_notParsingFunctionBodies() { | 2815 void test_staticMethod_notParsingFunctionBodies() { |
| 2572 ParserTestCase.parseFunctionBodies = false; | 2816 ParserTestCase.parseFunctionBodies = false; |
| 2573 try { | 2817 try { |
| 2574 parse4("parseCompilationUnit", "class C { static void m() {} }"); | 2818 createParser('class C { static void m() {} }'); |
| 2819 CompilationUnit unit = parser.parseCompilationUnit2(); |
| 2820 expectNotNullIfNoErrors(unit); |
| 2821 listener.assertNoErrors(); |
| 2575 } finally { | 2822 } finally { |
| 2576 ParserTestCase.parseFunctionBodies = true; | 2823 ParserTestCase.parseFunctionBodies = true; |
| 2577 } | 2824 } |
| 2578 } | 2825 } |
| 2579 } | 2826 } |
| 2580 | 2827 |
| 2581 class ParserTestCase extends EngineTestCase { | 2828 class ParserTestCase extends EngineTestCase { |
| 2582 /** | 2829 /** |
| 2583 * An empty list of objects used as arguments to zero-argument methods. | |
| 2584 */ | |
| 2585 static const List<Object> _EMPTY_ARGUMENTS = const <Object>[]; | |
| 2586 | |
| 2587 /** | |
| 2588 * A flag indicating whether parser is to parse function bodies. | 2830 * A flag indicating whether parser is to parse function bodies. |
| 2589 */ | 2831 */ |
| 2590 static bool parseFunctionBodies = true; | 2832 static bool parseFunctionBodies = true; |
| 2591 | 2833 |
| 2592 /** | 2834 /** |
| 2835 * A flag indicating whether the parser is to parse asserts in the initializer |
| 2836 * list of a constructor. |
| 2837 */ |
| 2838 bool enableAssertInitializer = false; |
| 2839 |
| 2840 /** |
| 2841 * A flag indicating whether parser is to parse async. |
| 2842 */ |
| 2843 bool parseAsync = true; |
| 2844 |
| 2845 /** |
| 2593 * A flag indicating whether generic method support should be enabled for a | 2846 * A flag indicating whether generic method support should be enabled for a |
| 2594 * specific test. | 2847 * specific test. |
| 2595 */ | 2848 */ |
| 2596 bool enableGenericMethods = false; | 2849 bool enableGenericMethods = false; |
| 2597 | 2850 |
| 2598 /** | 2851 /** |
| 2852 * Whether generic method comments should be enabled for the test. |
| 2853 */ |
| 2854 bool enableGenericMethodComments = false; |
| 2855 |
| 2856 /** |
| 2857 * A flag indicating whether lazy assignment operators should be enabled for |
| 2858 * the test. |
| 2859 */ |
| 2860 bool enableLazyAssignmentOperators = false; |
| 2861 |
| 2862 /** |
| 2863 * A flag indicating whether the parser is to parse the non-nullable modifier |
| 2864 * in type names. |
| 2865 */ |
| 2866 bool enableNnbd = false; |
| 2867 |
| 2868 /** |
| 2869 * The error listener to which scanner and parser errors will be reported. |
| 2870 * |
| 2871 * This field is typically initialized by invoking [createParser]. |
| 2872 */ |
| 2873 GatheringErrorListener listener; |
| 2874 |
| 2875 /** |
| 2876 * The parser used by the test. |
| 2877 * |
| 2878 * This field is typically initialized by invoking [createParser]. |
| 2879 */ |
| 2880 Parser parser; |
| 2881 |
| 2882 /** |
| 2599 * Return a CommentAndMetadata object with the given values that can be used f
or testing. | 2883 * Return a CommentAndMetadata object with the given values that can be used f
or testing. |
| 2600 * | 2884 * |
| 2601 * @param comment the comment to be wrapped in the object | 2885 * @param comment the comment to be wrapped in the object |
| 2602 * @param annotations the annotations to be wrapped in the object | 2886 * @param annotations the annotations to be wrapped in the object |
| 2603 * @return a CommentAndMetadata object that can be used for testing | 2887 * @return a CommentAndMetadata object that can be used for testing |
| 2604 */ | 2888 */ |
| 2605 CommentAndMetadata commentAndMetadata(Comment comment, | 2889 CommentAndMetadata commentAndMetadata(Comment comment, |
| 2606 [List<Annotation> annotations]) { | 2890 [List<Annotation> annotations]) { |
| 2607 return new CommentAndMetadata(comment, annotations); | 2891 return new CommentAndMetadata(comment, annotations); |
| 2608 } | 2892 } |
| 2609 | 2893 |
| 2610 /** | 2894 /** |
| 2895 * Create the [parser] and [listener] used by a test. The [parser] will be |
| 2896 * prepared to parse the tokens scanned from the given [content]. |
| 2897 */ |
| 2898 void createParser(String content) { |
| 2899 listener = new GatheringErrorListener(); |
| 2900 // |
| 2901 // Scan the source. |
| 2902 // |
| 2903 TestSource source = new TestSource(); |
| 2904 CharacterReader reader = new CharSequenceReader(content); |
| 2905 Scanner scanner = new Scanner(source, reader, listener); |
| 2906 scanner.scanGenericMethodComments = enableGenericMethodComments; |
| 2907 scanner.scanLazyAssignmentOperators = enableLazyAssignmentOperators; |
| 2908 Token tokenStream = scanner.tokenize(); |
| 2909 listener.setLineInfo(source, scanner.lineStarts); |
| 2910 // |
| 2911 // Create and initialize the parser. |
| 2912 // |
| 2913 parser = new Parser(source, listener); |
| 2914 parser.enableAssertInitializer = enableAssertInitializer; |
| 2915 parser.parseGenericMethods = enableGenericMethods; |
| 2916 parser.parseGenericMethodComments = enableGenericMethodComments; |
| 2917 parser.parseFunctionBodies = parseFunctionBodies; |
| 2918 parser.enableNnbd = enableNnbd; |
| 2919 parser.currentToken = tokenStream; |
| 2920 } |
| 2921 |
| 2922 /** |
| 2611 * Return an empty CommentAndMetadata object that can be used for testing. | 2923 * Return an empty CommentAndMetadata object that can be used for testing. |
| 2612 * | 2924 * |
| 2613 * @return an empty CommentAndMetadata object that can be used for testing | 2925 * @return an empty CommentAndMetadata object that can be used for testing |
| 2614 */ | 2926 */ |
| 2615 CommentAndMetadata emptyCommentAndMetadata() => | 2927 CommentAndMetadata emptyCommentAndMetadata() => |
| 2616 new CommentAndMetadata(null, null); | 2928 new CommentAndMetadata(null, null); |
| 2617 | 2929 |
| 2618 /** | 2930 void expectNotNullIfNoErrors(Object result) { |
| 2619 * Invoke a method in [Parser]. The method is assumed to have the given number
and type of | |
| 2620 * parameters and will be invoked with the given arguments. | |
| 2621 * | |
| 2622 * The given source is scanned and the parser is initialized to start with the
first token in the | |
| 2623 * source before the method is invoked. | |
| 2624 * | |
| 2625 * @param methodName the name of the method that should be invoked | |
| 2626 * @param objects the values of the arguments to the method | |
| 2627 * @param source the source to be processed by the parse method | |
| 2628 * @param listener the error listener that will be used for both scanning and
parsing | |
| 2629 * @return the result of invoking the method | |
| 2630 * @throws Exception if the method could not be invoked or throws an exception | |
| 2631 * @throws AssertionFailedError if the result is `null` or the errors produced
while | |
| 2632 * scanning and parsing the source do not match the expected errors | |
| 2633 */ | |
| 2634 Object invokeParserMethod(String methodName, List<Object> objects, | |
| 2635 String source, GatheringErrorListener listener) { | |
| 2636 // | |
| 2637 // Scan the source. | |
| 2638 // | |
| 2639 Scanner scanner = | |
| 2640 new Scanner(null, new CharSequenceReader(source), listener); | |
| 2641 Token tokenStream = scanner.tokenize(); | |
| 2642 listener.setLineInfo(new TestSource(), scanner.lineStarts); | |
| 2643 // | |
| 2644 // Parse the source. | |
| 2645 // | |
| 2646 Parser parser = createParser(listener); | |
| 2647 parser.parseGenericMethods = enableGenericMethods; | |
| 2648 parser.parseFunctionBodies = parseFunctionBodies; | |
| 2649 Object result = | |
| 2650 invokeParserMethodImpl(parser, methodName, objects, tokenStream); | |
| 2651 // | |
| 2652 // Partially test the results. | |
| 2653 // | |
| 2654 if (!listener.hasErrors) { | 2931 if (!listener.hasErrors) { |
| 2655 expect(result, isNotNull); | 2932 expect(result, isNotNull); |
| 2656 } | 2933 } |
| 2657 return result; | |
| 2658 } | 2934 } |
| 2659 | 2935 |
| 2660 /** | 2936 /** |
| 2661 * Invoke a method in [Parser]. The method is assumed to have no arguments. | 2937 * Parse the given [source] as a compilation unit. Throw an exception if the |
| 2662 * | 2938 * source could not be parsed, if the compilation errors in the source do not |
| 2663 * The given source is scanned and the parser is initialized to start with the
first token in the | 2939 * match those that are expected, or if the result would have been `null`. |
| 2664 * source before the method is invoked. | |
| 2665 * | |
| 2666 * @param methodName the name of the method that should be invoked | |
| 2667 * @param source the source to be processed by the parse method | |
| 2668 * @param listener the error listener that will be used for both scanning and
parsing | |
| 2669 * @return the result of invoking the method | |
| 2670 * @throws Exception if the method could not be invoked or throws an exception | |
| 2671 * @throws AssertionFailedError if the result is `null` or the errors produced
while | |
| 2672 * scanning and parsing the source do not match the expected errors | |
| 2673 */ | 2940 */ |
| 2674 Object invokeParserMethod2( | 2941 CompilationUnit parseCompilationUnitWithOptions(String source, |
| 2675 String methodName, String source, GatheringErrorListener listener) => | 2942 [List<ErrorCode> errorCodes = ErrorCode.EMPTY_LIST]) { |
| 2676 invokeParserMethod(methodName, _EMPTY_ARGUMENTS, source, listener); | 2943 createParser(source); |
| 2677 | 2944 CompilationUnit unit = parser.parseCompilationUnit2(); |
| 2678 /** | 2945 expect(unit, isNotNull); |
| 2679 * Invoke a parse method in [Parser]. The method is assumed to have the given
number and | 2946 listener.assertErrorsWithCodes(errorCodes); |
| 2680 * type of parameters and will be invoked with the given arguments. | 2947 return unit; |
| 2681 * | |
| 2682 * The given source is scanned and the parser is initialized to start with the
first token in the | |
| 2683 * source before the parse method is invoked. | |
| 2684 * | |
| 2685 * @param methodName the name of the parse method that should be invoked to pa
rse the source | |
| 2686 * @param objects the values of the arguments to the method | |
| 2687 * @param source the source to be parsed by the parse method | |
| 2688 * @return the result of invoking the method | |
| 2689 * @throws Exception if the method could not be invoked or throws an exception | |
| 2690 * @throws AssertionFailedError if the result is `null` or if any errors are p
roduced | |
| 2691 */ | |
| 2692 Object parse(String methodName, List<Object> objects, String source) => | |
| 2693 parse2(methodName, objects, source); | |
| 2694 | |
| 2695 /** | |
| 2696 * Invoke a parse method in [Parser]. The method is assumed to have the given
number and | |
| 2697 * type of parameters and will be invoked with the given arguments. | |
| 2698 * | |
| 2699 * The given source is scanned and the parser is initialized to start with the
first token in the | |
| 2700 * source before the parse method is invoked. | |
| 2701 * | |
| 2702 * @param methodName the name of the parse method that should be invoked to pa
rse the source | |
| 2703 * @param objects the values of the arguments to the method | |
| 2704 * @param source the source to be parsed by the parse method | |
| 2705 * @param errors the errors that should be generated | |
| 2706 * @return the result of invoking the method | |
| 2707 * @throws Exception if the method could not be invoked or throws an exception | |
| 2708 * @throws AssertionFailedError if the result is `null` or the errors produced
while | |
| 2709 * scanning and parsing the source do not match the expected errors | |
| 2710 */ | |
| 2711 Object parse2(String methodName, List<Object> objects, String source, | |
| 2712 [List<AnalysisError> errors = AnalysisError.NO_ERRORS]) { | |
| 2713 GatheringErrorListener listener = new GatheringErrorListener(); | |
| 2714 Object result = invokeParserMethod(methodName, objects, source, listener); | |
| 2715 listener.assertErrors(errors); | |
| 2716 return result; | |
| 2717 } | 2948 } |
| 2718 | 2949 |
| 2719 /** | 2950 /** |
| 2720 * Invoke a parse method in [Parser]. The method is assumed to have the given
number and | |
| 2721 * type of parameters and will be invoked with the given arguments. | |
| 2722 * | |
| 2723 * The given source is scanned and the parser is initialized to start with the
first token in the | |
| 2724 * source before the parse method is invoked. | |
| 2725 * | |
| 2726 * @param methodName the name of the parse method that should be invoked to pa
rse the source | |
| 2727 * @param objects the values of the arguments to the method | |
| 2728 * @param source the source to be parsed by the parse method | |
| 2729 * @param errorCodes the error codes of the errors that should be generated | |
| 2730 * @return the result of invoking the method | |
| 2731 * @throws Exception if the method could not be invoked or throws an exception | |
| 2732 * @throws AssertionFailedError if the result is `null` or the errors produced
while | |
| 2733 * scanning and parsing the source do not match the expected errors | |
| 2734 */ | |
| 2735 Object parse3(String methodName, List<Object> objects, String source, | |
| 2736 [List<ErrorCode> errorCodes = ErrorCode.EMPTY_LIST]) { | |
| 2737 GatheringErrorListener listener = new GatheringErrorListener(); | |
| 2738 Object result = invokeParserMethod(methodName, objects, source, listener); | |
| 2739 listener.assertErrorsWithCodes(errorCodes); | |
| 2740 return result; | |
| 2741 } | |
| 2742 | |
| 2743 /** | |
| 2744 * Invoke a parse method in [Parser]. The method is assumed to have no argumen
ts. | |
| 2745 * | |
| 2746 * The given source is scanned and the parser is initialized to start with the
first token in the | |
| 2747 * source before the parse method is invoked. | |
| 2748 * | |
| 2749 * @param methodName the name of the parse method that should be invoked to pa
rse the source | |
| 2750 * @param source the source to be parsed by the parse method | |
| 2751 * @param errorCodes the error codes of the errors that should be generated | |
| 2752 * @return the result of invoking the method | |
| 2753 * @throws Exception if the method could not be invoked or throws an exception | |
| 2754 * @throws AssertionFailedError if the result is `null` or the errors produced
while | |
| 2755 * scanning and parsing the source do not match the expected errors | |
| 2756 */ | |
| 2757 Object parse4(String methodName, String source, | |
| 2758 [List<ErrorCode> errorCodes = ErrorCode.EMPTY_LIST]) => | |
| 2759 parse3(methodName, _EMPTY_ARGUMENTS, source, errorCodes); | |
| 2760 | |
| 2761 /** | |
| 2762 * Parse the given source as an expression. | 2951 * Parse the given source as an expression. |
| 2763 * | 2952 * |
| 2764 * @param source the source to be parsed | 2953 * @param source the source to be parsed |
| 2765 * @param errorCodes the error codes of the errors that are expected to be fou
nd | 2954 * @param errorCodes the error codes of the errors that are expected to be fou
nd |
| 2766 * @return the expression that was parsed | 2955 * @return the expression that was parsed |
| 2767 * @throws Exception if the source could not be parsed, if the compilation err
ors in the source do | 2956 * @throws Exception if the source could not be parsed, if the compilation err
ors in the source do |
| 2768 * not match those that are expected, or if the result would have be
en `null` | 2957 * not match those that are expected, or if the result would have be
en `null` |
| 2769 */ | 2958 */ |
| 2770 Expression parseExpression(String source, | 2959 Expression parseExpression(String source, |
| 2771 [List<ErrorCode> errorCodes = ErrorCode.EMPTY_LIST]) { | 2960 [List<ErrorCode> errorCodes = ErrorCode.EMPTY_LIST]) { |
| 2772 GatheringErrorListener listener = new GatheringErrorListener(); | 2961 createParser(source); |
| 2773 Scanner scanner = | 2962 Expression expression = parser.parseExpression2(); |
| 2774 new Scanner(null, new CharSequenceReader(source), listener); | 2963 expectNotNullIfNoErrors(expression); |
| 2775 listener.setLineInfo(new TestSource(), scanner.lineStarts); | |
| 2776 Token token = scanner.tokenize(); | |
| 2777 Parser parser = createParser(listener); | |
| 2778 parser.parseGenericMethods = enableGenericMethods; | |
| 2779 Expression expression = parser.parseExpression(token); | |
| 2780 expect(expression, isNotNull); | |
| 2781 listener.assertErrorsWithCodes(errorCodes); | 2964 listener.assertErrorsWithCodes(errorCodes); |
| 2782 return expression; | 2965 return expression; |
| 2783 } | 2966 } |
| 2784 | 2967 |
| 2785 @override | 2968 @override |
| 2786 void setUp() { | 2969 void setUp() { |
| 2787 super.setUp(); | 2970 super.setUp(); |
| 2788 parseFunctionBodies = true; | 2971 parseFunctionBodies = true; |
| 2789 } | 2972 } |
| 2790 | 2973 |
| 2791 /** | 2974 /** |
| 2792 * Create a parser. | |
| 2793 * | |
| 2794 * @param listener the listener to be passed to the parser | |
| 2795 * @return the parser that was created | |
| 2796 */ | |
| 2797 static Parser createParser(GatheringErrorListener listener) { | |
| 2798 return new Parser(null, listener); | |
| 2799 } | |
| 2800 | |
| 2801 /** | |
| 2802 * Parse the given source as a compilation unit. | 2975 * Parse the given source as a compilation unit. |
| 2803 * | 2976 * |
| 2804 * @param source the source to be parsed | 2977 * @param source the source to be parsed |
| 2805 * @param errorCodes the error codes of the errors that are expected to be fou
nd | 2978 * @param errorCodes the error codes of the errors that are expected to be fou
nd |
| 2806 * @return the compilation unit that was parsed | 2979 * @return the compilation unit that was parsed |
| 2807 * @throws Exception if the source could not be parsed, if the compilation err
ors in the source do | 2980 * @throws Exception if the source could not be parsed, if the compilation err
ors in the source do |
| 2808 * not match those that are expected, or if the result would have be
en `null` | 2981 * not match those that are expected, or if the result would have be
en `null` |
| 2809 */ | 2982 */ |
| 2810 static CompilationUnit parseCompilationUnit(String source, | 2983 static CompilationUnit parseCompilationUnit(String source, |
| 2811 [List<ErrorCode> errorCodes = ErrorCode.EMPTY_LIST]) { | 2984 [List<ErrorCode> errorCodes = ErrorCode.EMPTY_LIST]) { |
| 2812 GatheringErrorListener listener = new GatheringErrorListener(); | 2985 GatheringErrorListener listener = new GatheringErrorListener(); |
| 2813 Scanner scanner = | 2986 Scanner scanner = |
| 2814 new Scanner(null, new CharSequenceReader(source), listener); | 2987 new Scanner(null, new CharSequenceReader(source), listener); |
| 2815 listener.setLineInfo(new TestSource(), scanner.lineStarts); | 2988 listener.setLineInfo(new TestSource(), scanner.lineStarts); |
| 2816 Token token = scanner.tokenize(); | 2989 Token token = scanner.tokenize(); |
| 2817 Parser parser = createParser(listener); | 2990 Parser parser = new Parser(null, listener); |
| 2818 CompilationUnit unit = parser.parseCompilationUnit(token); | 2991 CompilationUnit unit = parser.parseCompilationUnit(token); |
| 2819 expect(unit, isNotNull); | 2992 expect(unit, isNotNull); |
| 2820 listener.assertErrorsWithCodes(errorCodes); | 2993 listener.assertErrorsWithCodes(errorCodes); |
| 2821 return unit; | 2994 return unit; |
| 2822 } | 2995 } |
| 2823 | 2996 |
| 2824 /** | 2997 /** |
| 2825 * Parse the given source as a statement. | 2998 * Parse the given [source] as a statement. The [errorCodes] are the error |
| 2826 * | 2999 * codes of the errors that are expected to be found. If |
| 2827 * @param source the source to be parsed | 3000 * [enableLazyAssignmentOperators] is `true`, then lazy assignment operators |
| 2828 * @param errorCodes the error codes of the errors that are expected to be fou
nd | 3001 * should be enabled. |
| 2829 * @return the statement that was parsed | |
| 2830 * @throws Exception if the source could not be parsed, if the compilation err
ors in the source do | |
| 2831 * not match those that are expected, or if the result would have be
en `null` | |
| 2832 */ | 3002 */ |
| 2833 static Statement parseStatement(String source, | 3003 static Statement parseStatement(String source, |
| 2834 [List<ErrorCode> errorCodes = ErrorCode.EMPTY_LIST]) { | 3004 [List<ErrorCode> errorCodes = ErrorCode.EMPTY_LIST, |
| 3005 bool enableLazyAssignmentOperators]) { |
| 2835 GatheringErrorListener listener = new GatheringErrorListener(); | 3006 GatheringErrorListener listener = new GatheringErrorListener(); |
| 2836 Scanner scanner = | 3007 Scanner scanner = |
| 2837 new Scanner(null, new CharSequenceReader(source), listener); | 3008 new Scanner(null, new CharSequenceReader(source), listener); |
| 3009 scanner.scanLazyAssignmentOperators = enableLazyAssignmentOperators; |
| 2838 listener.setLineInfo(new TestSource(), scanner.lineStarts); | 3010 listener.setLineInfo(new TestSource(), scanner.lineStarts); |
| 2839 Token token = scanner.tokenize(); | 3011 Token token = scanner.tokenize(); |
| 2840 Parser parser = createParser(listener); | 3012 Parser parser = new Parser(null, listener); |
| 2841 Statement statement = parser.parseStatement(token); | 3013 Statement statement = parser.parseStatement(token); |
| 2842 expect(statement, isNotNull); | 3014 expect(statement, isNotNull); |
| 2843 listener.assertErrorsWithCodes(errorCodes); | 3015 listener.assertErrorsWithCodes(errorCodes); |
| 2844 return statement; | 3016 return statement; |
| 2845 } | 3017 } |
| 2846 | 3018 |
| 2847 /** | 3019 /** |
| 2848 * Parse the given source as a sequence of statements. | 3020 * Parse the given source as a sequence of statements. |
| 2849 * | 3021 * |
| 2850 * @param source the source to be parsed | 3022 * @param source the source to be parsed |
| 2851 * @param expectedCount the number of statements that are expected | 3023 * @param expectedCount the number of statements that are expected |
| 2852 * @param errorCodes the error codes of the errors that are expected to be fou
nd | 3024 * @param errorCodes the error codes of the errors that are expected to be fou
nd |
| 2853 * @return the statements that were parsed | 3025 * @return the statements that were parsed |
| 2854 * @throws Exception if the source could not be parsed, if the number of state
ments does not match | 3026 * @throws Exception if the source could not be parsed, if the number of state
ments does not match |
| 2855 * the expected count, if the compilation errors in the source do no
t match those that | 3027 * the expected count, if the compilation errors in the source do no
t match those that |
| 2856 * are expected, or if the result would have been `null` | 3028 * are expected, or if the result would have been `null` |
| 2857 */ | 3029 */ |
| 2858 static List<Statement> parseStatements(String source, int expectedCount, | 3030 static List<Statement> parseStatements(String source, int expectedCount, |
| 2859 [List<ErrorCode> errorCodes = ErrorCode.EMPTY_LIST]) { | 3031 [List<ErrorCode> errorCodes = ErrorCode.EMPTY_LIST]) { |
| 2860 GatheringErrorListener listener = new GatheringErrorListener(); | 3032 GatheringErrorListener listener = new GatheringErrorListener(); |
| 2861 Scanner scanner = | 3033 Scanner scanner = |
| 2862 new Scanner(null, new CharSequenceReader(source), listener); | 3034 new Scanner(null, new CharSequenceReader(source), listener); |
| 2863 listener.setLineInfo(new TestSource(), scanner.lineStarts); | 3035 listener.setLineInfo(new TestSource(), scanner.lineStarts); |
| 2864 Token token = scanner.tokenize(); | 3036 Token token = scanner.tokenize(); |
| 2865 Parser parser = createParser(listener); | 3037 Parser parser = new Parser(null, listener); |
| 2866 List<Statement> statements = parser.parseStatements(token); | 3038 List<Statement> statements = parser.parseStatements(token); |
| 2867 expect(statements, hasLength(expectedCount)); | 3039 expect(statements, hasLength(expectedCount)); |
| 2868 listener.assertErrorsWithCodes(errorCodes); | 3040 listener.assertErrorsWithCodes(errorCodes); |
| 2869 return statements; | 3041 return statements; |
| 2870 } | 3042 } |
| 2871 } | 3043 } |
| 2872 | 3044 |
| 2873 /** | 3045 /** |
| 2874 * The class `RecoveryParserTest` defines parser tests that test the parsing of
invalid code | 3046 * The class `RecoveryParserTest` defines parser tests that test the parsing of
invalid code |
| 2875 * sequences to ensure that the correct recovery steps are taken in the parser. | 3047 * sequences to ensure that the correct recovery steps are taken in the parser. |
| 2876 */ | 3048 */ |
| 2877 @reflectiveTest | 3049 @reflectiveTest |
| 2878 class RecoveryParserTest extends ParserTestCase { | 3050 class RecoveryParserTest extends ParserTestCase { |
| 2879 void fail_incomplete_returnType() { | |
| 2880 ParserTestCase.parseCompilationUnit(r''' | |
| 2881 Map<Symbol, convertStringToSymbolMap(Map<String, dynamic> map) { | |
| 2882 if (map == null) return null; | |
| 2883 Map<Symbol, dynamic> result = new Map<Symbol, dynamic>(); | |
| 2884 map.forEach((name, value) { | |
| 2885 result[new Symbol(name)] = value; | |
| 2886 }); | |
| 2887 return result; | |
| 2888 }'''); | |
| 2889 } | |
| 2890 | |
| 2891 void test_additiveExpression_missing_LHS() { | 3051 void test_additiveExpression_missing_LHS() { |
| 2892 BinaryExpression expression = | 3052 BinaryExpression expression = |
| 2893 parseExpression("+ y", [ParserErrorCode.MISSING_IDENTIFIER]); | 3053 parseExpression("+ y", [ParserErrorCode.MISSING_IDENTIFIER]); |
| 2894 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, | 3054 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| 2895 SimpleIdentifier, expression.leftOperand); | 3055 SimpleIdentifier, expression.leftOperand); |
| 2896 expect(expression.leftOperand.isSynthetic, isTrue); | 3056 expect(expression.leftOperand.isSynthetic, isTrue); |
| 2897 } | 3057 } |
| 2898 | 3058 |
| 2899 void test_additiveExpression_missing_LHS_RHS() { | 3059 void test_additiveExpression_missing_LHS_RHS() { |
| 2900 BinaryExpression expression = parseExpression("+", [ | 3060 BinaryExpression expression = parseExpression("+", [ |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3199 | 3359 |
| 3200 void test_classTypeAlias_withBody() { | 3360 void test_classTypeAlias_withBody() { |
| 3201 ParserTestCase.parseCompilationUnit( | 3361 ParserTestCase.parseCompilationUnit( |
| 3202 r''' | 3362 r''' |
| 3203 class A {} | 3363 class A {} |
| 3204 class B = Object with A {}''', | 3364 class B = Object with A {}''', |
| 3205 [ParserErrorCode.EXPECTED_TOKEN]); | 3365 [ParserErrorCode.EXPECTED_TOKEN]); |
| 3206 } | 3366 } |
| 3207 | 3367 |
| 3208 void test_conditionalExpression_missingElse() { | 3368 void test_conditionalExpression_missingElse() { |
| 3209 ConditionalExpression expression = parse4("parseConditionalExpression", | 3369 createParser('x ? y :'); |
| 3210 "x ? y :", [ParserErrorCode.MISSING_IDENTIFIER]); | 3370 Expression expression = parser.parseConditionalExpression(); |
| 3211 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, | 3371 expectNotNullIfNoErrors(expression); |
| 3212 SimpleIdentifier, expression.elseExpression); | 3372 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| 3213 expect(expression.elseExpression.isSynthetic, isTrue); | 3373 expect(expression, new isInstanceOf<ConditionalExpression>()); |
| 3374 ConditionalExpression conditionalExpression = expression; |
| 3375 expect(conditionalExpression.elseExpression, |
| 3376 new isInstanceOf<SimpleIdentifier>()); |
| 3377 expect(conditionalExpression.elseExpression.isSynthetic, isTrue); |
| 3214 } | 3378 } |
| 3215 | 3379 |
| 3216 void test_conditionalExpression_missingThen() { | 3380 void test_conditionalExpression_missingThen() { |
| 3217 ConditionalExpression expression = parse4("parseConditionalExpression", | 3381 createParser('x ? : z'); |
| 3218 "x ? : z", [ParserErrorCode.MISSING_IDENTIFIER]); | 3382 Expression expression = parser.parseConditionalExpression(); |
| 3219 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, | 3383 expectNotNullIfNoErrors(expression); |
| 3220 SimpleIdentifier, expression.thenExpression); | 3384 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| 3221 expect(expression.thenExpression.isSynthetic, isTrue); | 3385 expect(expression, new isInstanceOf<ConditionalExpression>()); |
| 3386 ConditionalExpression conditionalExpression = expression; |
| 3387 expect(conditionalExpression.thenExpression, |
| 3388 new isInstanceOf<SimpleIdentifier>()); |
| 3389 expect(conditionalExpression.thenExpression.isSynthetic, isTrue); |
| 3222 } | 3390 } |
| 3223 | 3391 |
| 3224 void test_declarationBeforeDirective() { | 3392 void test_declarationBeforeDirective() { |
| 3225 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 3393 CompilationUnit unit = ParserTestCase.parseCompilationUnit( |
| 3226 "class foo { } import 'bar.dart';", | 3394 "class foo { } import 'bar.dart';", |
| 3227 [ParserErrorCode.DIRECTIVE_AFTER_DECLARATION]); | 3395 [ParserErrorCode.DIRECTIVE_AFTER_DECLARATION]); |
| 3228 expect(unit.directives, hasLength(1)); | 3396 expect(unit.directives, hasLength(1)); |
| 3229 expect(unit.declarations, hasLength(1)); | 3397 expect(unit.declarations, hasLength(1)); |
| 3230 ClassDeclaration classDecl = unit.childEntities.first; | 3398 ClassDeclaration classDecl = unit.childEntities.first; |
| 3231 expect(classDecl, isNotNull); | 3399 expect(classDecl, isNotNull); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3293 BinaryExpression expression = parseExpression("super == ==", [ | 3461 BinaryExpression expression = parseExpression("super == ==", [ |
| 3294 ParserErrorCode.MISSING_IDENTIFIER, | 3462 ParserErrorCode.MISSING_IDENTIFIER, |
| 3295 ParserErrorCode.MISSING_IDENTIFIER, | 3463 ParserErrorCode.MISSING_IDENTIFIER, |
| 3296 ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND | 3464 ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND |
| 3297 ]); | 3465 ]); |
| 3298 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, | 3466 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| 3299 BinaryExpression, expression.leftOperand); | 3467 BinaryExpression, expression.leftOperand); |
| 3300 } | 3468 } |
| 3301 | 3469 |
| 3302 void test_expressionList_multiple_end() { | 3470 void test_expressionList_multiple_end() { |
| 3303 List<Expression> result = parse4("parseExpressionList", ", 2, 3, 4", | 3471 createParser(', 2, 3, 4'); |
| 3304 [ParserErrorCode.MISSING_IDENTIFIER]); | 3472 List<Expression> result = parser.parseExpressionList(); |
| 3473 expectNotNullIfNoErrors(result); |
| 3474 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| 3305 expect(result, hasLength(4)); | 3475 expect(result, hasLength(4)); |
| 3306 Expression syntheticExpression = result[0]; | 3476 Expression syntheticExpression = result[0]; |
| 3307 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, | 3477 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| 3308 SimpleIdentifier, syntheticExpression); | 3478 SimpleIdentifier, syntheticExpression); |
| 3309 expect(syntheticExpression.isSynthetic, isTrue); | 3479 expect(syntheticExpression.isSynthetic, isTrue); |
| 3310 } | 3480 } |
| 3311 | 3481 |
| 3312 void test_expressionList_multiple_middle() { | 3482 void test_expressionList_multiple_middle() { |
| 3313 List<Expression> result = parse4("parseExpressionList", "1, 2, , 4", | 3483 createParser('1, 2, , 4'); |
| 3314 [ParserErrorCode.MISSING_IDENTIFIER]); | 3484 List<Expression> result = parser.parseExpressionList(); |
| 3485 expectNotNullIfNoErrors(result); |
| 3486 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| 3315 expect(result, hasLength(4)); | 3487 expect(result, hasLength(4)); |
| 3316 Expression syntheticExpression = result[2]; | 3488 Expression syntheticExpression = result[2]; |
| 3317 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, | 3489 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| 3318 SimpleIdentifier, syntheticExpression); | 3490 SimpleIdentifier, syntheticExpression); |
| 3319 expect(syntheticExpression.isSynthetic, isTrue); | 3491 expect(syntheticExpression.isSynthetic, isTrue); |
| 3320 } | 3492 } |
| 3321 | 3493 |
| 3322 void test_expressionList_multiple_start() { | 3494 void test_expressionList_multiple_start() { |
| 3323 List<Expression> result = parse4("parseExpressionList", "1, 2, 3,", | 3495 createParser('1, 2, 3,'); |
| 3324 [ParserErrorCode.MISSING_IDENTIFIER]); | 3496 List<Expression> result = parser.parseExpressionList(); |
| 3497 expectNotNullIfNoErrors(result); |
| 3498 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| 3325 expect(result, hasLength(4)); | 3499 expect(result, hasLength(4)); |
| 3326 Expression syntheticExpression = result[3]; | 3500 Expression syntheticExpression = result[3]; |
| 3327 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, | 3501 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| 3328 SimpleIdentifier, syntheticExpression); | 3502 SimpleIdentifier, syntheticExpression); |
| 3329 expect(syntheticExpression.isSynthetic, isTrue); | 3503 expect(syntheticExpression.isSynthetic, isTrue); |
| 3330 } | 3504 } |
| 3331 | 3505 |
| 3332 void test_functionExpression_in_ConstructorFieldInitializer() { | 3506 void test_functionExpression_in_ConstructorFieldInitializer() { |
| 3333 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 3507 CompilationUnit unit = ParserTestCase.parseCompilationUnit( |
| 3334 "class A { A() : a = (){}; var v; }", | 3508 "class A { A() : a = (){}; var v; }", |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3375 expect(unit.directives, hasLength(1)); | 3549 expect(unit.directives, hasLength(1)); |
| 3376 expect(unit.declarations, hasLength(0)); | 3550 expect(unit.declarations, hasLength(0)); |
| 3377 } | 3551 } |
| 3378 | 3552 |
| 3379 void test_incomplete_conditionalExpression() { | 3553 void test_incomplete_conditionalExpression() { |
| 3380 parseExpression("x ? 0", | 3554 parseExpression("x ? 0", |
| 3381 [ParserErrorCode.EXPECTED_TOKEN, ParserErrorCode.MISSING_IDENTIFIER]); | 3555 [ParserErrorCode.EXPECTED_TOKEN, ParserErrorCode.MISSING_IDENTIFIER]); |
| 3382 } | 3556 } |
| 3383 | 3557 |
| 3384 void test_incomplete_constructorInitializers_empty() { | 3558 void test_incomplete_constructorInitializers_empty() { |
| 3385 parse3("parseClassMember", ["C"], "C() : {}", | 3559 createParser('C() : {}'); |
| 3386 [ParserErrorCode.MISSING_INITIALIZER]); | 3560 ClassMember member = parser.parseClassMember('C'); |
| 3561 expectNotNullIfNoErrors(member); |
| 3562 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_INITIALIZER]); |
| 3387 } | 3563 } |
| 3388 | 3564 |
| 3389 void test_incomplete_constructorInitializers_missingEquals() { | 3565 void test_incomplete_constructorInitializers_missingEquals() { |
| 3390 ClassMember member = parse3("parseClassMember", ["C"], "C() : x(3) {}", | 3566 createParser('C() : x(3) {}'); |
| 3567 ClassMember member = parser.parseClassMember('C'); |
| 3568 expectNotNullIfNoErrors(member); |
| 3569 listener.assertErrorsWithCodes( |
| 3391 [ParserErrorCode.MISSING_ASSIGNMENT_IN_INITIALIZER]); | 3570 [ParserErrorCode.MISSING_ASSIGNMENT_IN_INITIALIZER]); |
| 3392 expect(member, new isInstanceOf<ConstructorDeclaration>()); | 3571 expect(member, new isInstanceOf<ConstructorDeclaration>()); |
| 3393 NodeList<ConstructorInitializer> initializers = | 3572 NodeList<ConstructorInitializer> initializers = |
| 3394 (member as ConstructorDeclaration).initializers; | 3573 (member as ConstructorDeclaration).initializers; |
| 3395 expect(initializers, hasLength(1)); | 3574 expect(initializers, hasLength(1)); |
| 3396 ConstructorInitializer initializer = initializers[0]; | 3575 ConstructorInitializer initializer = initializers[0]; |
| 3397 expect(initializer, new isInstanceOf<ConstructorFieldInitializer>()); | 3576 expect(initializer, new isInstanceOf<ConstructorFieldInitializer>()); |
| 3398 Expression expression = | 3577 Expression expression = |
| 3399 (initializer as ConstructorFieldInitializer).expression; | 3578 (initializer as ConstructorFieldInitializer).expression; |
| 3400 expect(expression, isNotNull); | 3579 expect(expression, isNotNull); |
| 3401 expect(expression, new isInstanceOf<ParenthesizedExpression>()); | 3580 expect(expression, new isInstanceOf<ParenthesizedExpression>()); |
| 3402 } | 3581 } |
| 3403 | 3582 |
| 3404 void test_incomplete_constructorInitializers_variable() { | 3583 void test_incomplete_constructorInitializers_variable() { |
| 3405 parse3("parseClassMember", ["C"], "C() : x {}", | 3584 createParser('C() : x {}'); |
| 3585 ClassMember member = parser.parseClassMember('C'); |
| 3586 expectNotNullIfNoErrors(member); |
| 3587 listener.assertErrorsWithCodes( |
| 3406 [ParserErrorCode.MISSING_ASSIGNMENT_IN_INITIALIZER]); | 3588 [ParserErrorCode.MISSING_ASSIGNMENT_IN_INITIALIZER]); |
| 3407 } | 3589 } |
| 3408 | 3590 |
| 3591 @failingTest |
| 3592 void test_incomplete_returnType() { |
| 3593 ParserTestCase.parseCompilationUnit(r''' |
| 3594 Map<Symbol, convertStringToSymbolMap(Map<String, dynamic> map) { |
| 3595 if (map == null) return null; |
| 3596 Map<Symbol, dynamic> result = new Map<Symbol, dynamic>(); |
| 3597 map.forEach((name, value) { |
| 3598 result[new Symbol(name)] = value; |
| 3599 }); |
| 3600 return result; |
| 3601 }'''); |
| 3602 } |
| 3603 |
| 3409 void test_incomplete_topLevelFunction() { | 3604 void test_incomplete_topLevelFunction() { |
| 3410 ParserTestCase.parseCompilationUnit( | 3605 ParserTestCase.parseCompilationUnit( |
| 3411 "foo();", [ParserErrorCode.MISSING_FUNCTION_BODY]); | 3606 "foo();", [ParserErrorCode.MISSING_FUNCTION_BODY]); |
| 3412 } | 3607 } |
| 3413 | 3608 |
| 3414 void test_incomplete_topLevelVariable() { | 3609 void test_incomplete_topLevelVariable() { |
| 3415 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 3610 CompilationUnit unit = ParserTestCase |
| 3416 "String", [ParserErrorCode.EXPECTED_EXECUTABLE]); | 3611 .parseCompilationUnit("String", [ParserErrorCode.EXPECTED_EXECUTABLE]); |
| 3417 NodeList<CompilationUnitMember> declarations = unit.declarations; | 3612 NodeList<CompilationUnitMember> declarations = unit.declarations; |
| 3418 expect(declarations, hasLength(1)); | 3613 expect(declarations, hasLength(1)); |
| 3419 CompilationUnitMember member = declarations[0]; | 3614 CompilationUnitMember member = declarations[0]; |
| 3420 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableDeclaration, | 3615 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableDeclaration, |
| 3421 TopLevelVariableDeclaration, member); | 3616 TopLevelVariableDeclaration, member); |
| 3422 NodeList<VariableDeclaration> variables = | 3617 NodeList<VariableDeclaration> variables = |
| 3423 (member as TopLevelVariableDeclaration).variables.variables; | 3618 (member as TopLevelVariableDeclaration).variables.variables; |
| 3424 expect(variables, hasLength(1)); | 3619 expect(variables, hasLength(1)); |
| 3425 SimpleIdentifier name = variables[0].name; | 3620 SimpleIdentifier name = variables[0].name; |
| 3426 expect(name.isSynthetic, isTrue); | 3621 expect(name.isSynthetic, isTrue); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3483 CompilationUnitMember unitMember = declarations[0]; | 3678 CompilationUnitMember unitMember = declarations[0]; |
| 3484 EngineTestCase.assertInstanceOf( | 3679 EngineTestCase.assertInstanceOf( |
| 3485 (obj) => obj is ClassDeclaration, ClassDeclaration, unitMember); | 3680 (obj) => obj is ClassDeclaration, ClassDeclaration, unitMember); |
| 3486 NodeList<ClassMember> members = (unitMember as ClassDeclaration).members; | 3681 NodeList<ClassMember> members = (unitMember as ClassDeclaration).members; |
| 3487 expect(members, hasLength(1)); | 3682 expect(members, hasLength(1)); |
| 3488 ClassMember classMember = members[0]; | 3683 ClassMember classMember = members[0]; |
| 3489 EngineTestCase.assertInstanceOf( | 3684 EngineTestCase.assertInstanceOf( |
| 3490 (obj) => obj is FieldDeclaration, FieldDeclaration, classMember); | 3685 (obj) => obj is FieldDeclaration, FieldDeclaration, classMember); |
| 3491 VariableDeclarationList fieldList = | 3686 VariableDeclarationList fieldList = |
| 3492 (classMember as FieldDeclaration).fields; | 3687 (classMember as FieldDeclaration).fields; |
| 3493 expect((fieldList.keyword as KeywordToken).keyword, Keyword.CONST); | 3688 expect(fieldList.keyword.keyword, Keyword.CONST); |
| 3494 NodeList<VariableDeclaration> fields = fieldList.variables; | 3689 NodeList<VariableDeclaration> fields = fieldList.variables; |
| 3495 expect(fields, hasLength(1)); | 3690 expect(fields, hasLength(1)); |
| 3496 VariableDeclaration field = fields[0]; | 3691 VariableDeclaration field = fields[0]; |
| 3497 expect(field.name.isSynthetic, isTrue); | 3692 expect(field.name.isSynthetic, isTrue); |
| 3498 } | 3693 } |
| 3499 | 3694 |
| 3500 void test_incompleteField_final() { | 3695 void test_incompleteField_final() { |
| 3501 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 3696 CompilationUnit unit = ParserTestCase.parseCompilationUnit( |
| 3502 r''' | 3697 r''' |
| 3503 class C { | 3698 class C { |
| 3504 final | 3699 final |
| 3505 }''', | 3700 }''', |
| 3506 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); | 3701 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); |
| 3507 NodeList<CompilationUnitMember> declarations = unit.declarations; | 3702 NodeList<CompilationUnitMember> declarations = unit.declarations; |
| 3508 expect(declarations, hasLength(1)); | 3703 expect(declarations, hasLength(1)); |
| 3509 CompilationUnitMember unitMember = declarations[0]; | 3704 CompilationUnitMember unitMember = declarations[0]; |
| 3510 EngineTestCase.assertInstanceOf( | 3705 EngineTestCase.assertInstanceOf( |
| 3511 (obj) => obj is ClassDeclaration, ClassDeclaration, unitMember); | 3706 (obj) => obj is ClassDeclaration, ClassDeclaration, unitMember); |
| 3512 NodeList<ClassMember> members = (unitMember as ClassDeclaration).members; | 3707 NodeList<ClassMember> members = (unitMember as ClassDeclaration).members; |
| 3513 expect(members, hasLength(1)); | 3708 expect(members, hasLength(1)); |
| 3514 ClassMember classMember = members[0]; | 3709 ClassMember classMember = members[0]; |
| 3515 EngineTestCase.assertInstanceOf( | 3710 EngineTestCase.assertInstanceOf( |
| 3516 (obj) => obj is FieldDeclaration, FieldDeclaration, classMember); | 3711 (obj) => obj is FieldDeclaration, FieldDeclaration, classMember); |
| 3517 VariableDeclarationList fieldList = | 3712 VariableDeclarationList fieldList = |
| 3518 (classMember as FieldDeclaration).fields; | 3713 (classMember as FieldDeclaration).fields; |
| 3519 expect((fieldList.keyword as KeywordToken).keyword, Keyword.FINAL); | 3714 expect(fieldList.keyword.keyword, Keyword.FINAL); |
| 3520 NodeList<VariableDeclaration> fields = fieldList.variables; | 3715 NodeList<VariableDeclaration> fields = fieldList.variables; |
| 3521 expect(fields, hasLength(1)); | 3716 expect(fields, hasLength(1)); |
| 3522 VariableDeclaration field = fields[0]; | 3717 VariableDeclaration field = fields[0]; |
| 3523 expect(field.name.isSynthetic, isTrue); | 3718 expect(field.name.isSynthetic, isTrue); |
| 3524 } | 3719 } |
| 3525 | 3720 |
| 3526 void test_incompleteField_var() { | 3721 void test_incompleteField_var() { |
| 3527 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 3722 CompilationUnit unit = ParserTestCase.parseCompilationUnit( |
| 3528 r''' | 3723 r''' |
| 3529 class C { | 3724 class C { |
| 3530 var | 3725 var |
| 3531 }''', | 3726 }''', |
| 3532 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); | 3727 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); |
| 3533 NodeList<CompilationUnitMember> declarations = unit.declarations; | 3728 NodeList<CompilationUnitMember> declarations = unit.declarations; |
| 3534 expect(declarations, hasLength(1)); | 3729 expect(declarations, hasLength(1)); |
| 3535 CompilationUnitMember unitMember = declarations[0]; | 3730 CompilationUnitMember unitMember = declarations[0]; |
| 3536 EngineTestCase.assertInstanceOf( | 3731 EngineTestCase.assertInstanceOf( |
| 3537 (obj) => obj is ClassDeclaration, ClassDeclaration, unitMember); | 3732 (obj) => obj is ClassDeclaration, ClassDeclaration, unitMember); |
| 3538 NodeList<ClassMember> members = (unitMember as ClassDeclaration).members; | 3733 NodeList<ClassMember> members = (unitMember as ClassDeclaration).members; |
| 3539 expect(members, hasLength(1)); | 3734 expect(members, hasLength(1)); |
| 3540 ClassMember classMember = members[0]; | 3735 ClassMember classMember = members[0]; |
| 3541 EngineTestCase.assertInstanceOf( | 3736 EngineTestCase.assertInstanceOf( |
| 3542 (obj) => obj is FieldDeclaration, FieldDeclaration, classMember); | 3737 (obj) => obj is FieldDeclaration, FieldDeclaration, classMember); |
| 3543 VariableDeclarationList fieldList = | 3738 VariableDeclarationList fieldList = |
| 3544 (classMember as FieldDeclaration).fields; | 3739 (classMember as FieldDeclaration).fields; |
| 3545 expect((fieldList.keyword as KeywordToken).keyword, Keyword.VAR); | 3740 expect(fieldList.keyword.keyword, Keyword.VAR); |
| 3546 NodeList<VariableDeclaration> fields = fieldList.variables; | 3741 NodeList<VariableDeclaration> fields = fieldList.variables; |
| 3547 expect(fields, hasLength(1)); | 3742 expect(fields, hasLength(1)); |
| 3548 VariableDeclaration field = fields[0]; | 3743 VariableDeclaration field = fields[0]; |
| 3549 expect(field.name.isSynthetic, isTrue); | 3744 expect(field.name.isSynthetic, isTrue); |
| 3550 } | 3745 } |
| 3551 | 3746 |
| 3552 void test_incompleteForEach() { | 3747 void test_incompleteForEach() { |
| 3553 ForStatement statement = ParserTestCase.parseStatement( | 3748 ForStatement statement = ParserTestCase.parseStatement( |
| 3554 'for (String item i) {}', | 3749 'for (String item i) {}', |
| 3555 [ParserErrorCode.EXPECTED_TOKEN, ParserErrorCode.EXPECTED_TOKEN]); | 3750 [ParserErrorCode.EXPECTED_TOKEN, ParserErrorCode.EXPECTED_TOKEN]); |
| 3556 expect(statement, new isInstanceOf<ForStatement>()); | 3751 expect(statement, new isInstanceOf<ForStatement>()); |
| 3557 expect(statement.toSource(), 'for (String item; i;) {}'); | 3752 expect(statement.toSource(), 'for (String item; i;) {}'); |
| 3558 expect(statement.leftSeparator, isNotNull); | 3753 expect(statement.leftSeparator, isNotNull); |
| 3559 expect(statement.leftSeparator.type, TokenType.SEMICOLON); | 3754 expect(statement.leftSeparator.type, TokenType.SEMICOLON); |
| 3560 expect(statement.rightSeparator, isNotNull); | 3755 expect(statement.rightSeparator, isNotNull); |
| 3561 expect(statement.rightSeparator.type, TokenType.SEMICOLON); | 3756 expect(statement.rightSeparator.type, TokenType.SEMICOLON); |
| 3562 } | 3757 } |
| 3563 | 3758 |
| 3564 void test_incompleteLocalVariable_atTheEndOfBlock() { | 3759 void test_incompleteLocalVariable_atTheEndOfBlock() { |
| 3565 Statement statement = ParserTestCase.parseStatement( | 3760 Statement statement = ParserTestCase |
| 3566 'String v }', [ParserErrorCode.EXPECTED_TOKEN]); | 3761 .parseStatement('String v }', [ParserErrorCode.EXPECTED_TOKEN]); |
| 3567 expect(statement, new isInstanceOf<VariableDeclarationStatement>()); | 3762 expect(statement, new isInstanceOf<VariableDeclarationStatement>()); |
| 3568 expect(statement.toSource(), 'String v;'); | 3763 expect(statement.toSource(), 'String v;'); |
| 3569 } | 3764 } |
| 3570 | 3765 |
| 3571 void test_incompleteLocalVariable_beforeIdentifier() { | 3766 void test_incompleteLocalVariable_beforeIdentifier() { |
| 3572 Statement statement = ParserTestCase.parseStatement( | 3767 Statement statement = ParserTestCase.parseStatement( |
| 3573 'String v String v2;', [ParserErrorCode.EXPECTED_TOKEN]); | 3768 'String v String v2;', [ParserErrorCode.EXPECTED_TOKEN]); |
| 3574 expect(statement, new isInstanceOf<VariableDeclarationStatement>()); | 3769 expect(statement, new isInstanceOf<VariableDeclarationStatement>()); |
| 3575 expect(statement.toSource(), 'String v;'); | 3770 expect(statement.toSource(), 'String v;'); |
| 3576 } | 3771 } |
| 3577 | 3772 |
| 3578 void test_incompleteLocalVariable_beforeKeyword() { | 3773 void test_incompleteLocalVariable_beforeKeyword() { |
| 3579 Statement statement = ParserTestCase.parseStatement( | 3774 Statement statement = ParserTestCase.parseStatement( |
| 3580 'String v if (true) {}', [ParserErrorCode.EXPECTED_TOKEN]); | 3775 'String v if (true) {}', [ParserErrorCode.EXPECTED_TOKEN]); |
| 3581 expect(statement, new isInstanceOf<VariableDeclarationStatement>()); | 3776 expect(statement, new isInstanceOf<VariableDeclarationStatement>()); |
| 3582 expect(statement.toSource(), 'String v;'); | 3777 expect(statement.toSource(), 'String v;'); |
| 3583 } | 3778 } |
| 3584 | 3779 |
| 3585 void test_incompleteLocalVariable_beforeNextBlock() { | 3780 void test_incompleteLocalVariable_beforeNextBlock() { |
| 3586 Statement statement = ParserTestCase.parseStatement( | 3781 Statement statement = ParserTestCase |
| 3587 'String v {}', [ParserErrorCode.EXPECTED_TOKEN]); | 3782 .parseStatement('String v {}', [ParserErrorCode.EXPECTED_TOKEN]); |
| 3588 expect(statement, new isInstanceOf<VariableDeclarationStatement>()); | 3783 expect(statement, new isInstanceOf<VariableDeclarationStatement>()); |
| 3589 expect(statement.toSource(), 'String v;'); | 3784 expect(statement.toSource(), 'String v;'); |
| 3590 } | 3785 } |
| 3591 | 3786 |
| 3592 void test_incompleteLocalVariable_parameterizedType() { | 3787 void test_incompleteLocalVariable_parameterizedType() { |
| 3593 Statement statement = ParserTestCase.parseStatement( | 3788 Statement statement = ParserTestCase |
| 3594 'List<String> v {}', [ParserErrorCode.EXPECTED_TOKEN]); | 3789 .parseStatement('List<String> v {}', [ParserErrorCode.EXPECTED_TOKEN]); |
| 3595 expect(statement, new isInstanceOf<VariableDeclarationStatement>()); | 3790 expect(statement, new isInstanceOf<VariableDeclarationStatement>()); |
| 3596 expect(statement.toSource(), 'List<String> v;'); | 3791 expect(statement.toSource(), 'List<String> v;'); |
| 3597 } | 3792 } |
| 3598 | 3793 |
| 3794 void test_incompleteTypeArguments_field() { |
| 3795 CompilationUnit unit = ParserTestCase.parseCompilationUnit( |
| 3796 r''' |
| 3797 class C { |
| 3798 final List<int f; |
| 3799 }''', |
| 3800 [ParserErrorCode.EXPECTED_TOKEN]); |
| 3801 // one class |
| 3802 List<CompilationUnitMember> declarations = unit.declarations; |
| 3803 expect(declarations, hasLength(1)); |
| 3804 ClassDeclaration classDecl = declarations[0] as ClassDeclaration; |
| 3805 // one field declaration |
| 3806 List<ClassMember> members = classDecl.members; |
| 3807 expect(members, hasLength(1)); |
| 3808 FieldDeclaration fieldDecl = members[0] as FieldDeclaration; |
| 3809 // one field |
| 3810 VariableDeclarationList fieldList = fieldDecl.fields; |
| 3811 List<VariableDeclaration> fields = fieldList.variables; |
| 3812 expect(fields, hasLength(1)); |
| 3813 VariableDeclaration field = fields[0]; |
| 3814 expect(field.name.name, 'f'); |
| 3815 // validate the type |
| 3816 TypeArgumentList typeArguments = fieldList.type.typeArguments; |
| 3817 expect(typeArguments.arguments, hasLength(1)); |
| 3818 // synthetic '>' |
| 3819 Token token = typeArguments.endToken; |
| 3820 expect(token.type, TokenType.GT); |
| 3821 expect(token.isSynthetic, isTrue); |
| 3822 } |
| 3823 |
| 3824 void test_incompleteTypeParameters() { |
| 3825 CompilationUnit unit = ParserTestCase.parseCompilationUnit( |
| 3826 r''' |
| 3827 class C<K { |
| 3828 }''', |
| 3829 [ParserErrorCode.EXPECTED_TOKEN]); |
| 3830 // one class |
| 3831 List<CompilationUnitMember> declarations = unit.declarations; |
| 3832 expect(declarations, hasLength(1)); |
| 3833 ClassDeclaration classDecl = declarations[0] as ClassDeclaration; |
| 3834 // validate the type parameters |
| 3835 TypeParameterList typeParameters = classDecl.typeParameters; |
| 3836 expect(typeParameters.typeParameters, hasLength(1)); |
| 3837 // synthetic '>' |
| 3838 Token token = typeParameters.endToken; |
| 3839 expect(token.type, TokenType.GT); |
| 3840 expect(token.isSynthetic, isTrue); |
| 3841 } |
| 3842 |
| 3599 void test_invalidFunctionBodyModifier() { | 3843 void test_invalidFunctionBodyModifier() { |
| 3600 ParserTestCase.parseCompilationUnit( | 3844 ParserTestCase.parseCompilationUnit( |
| 3601 "f() sync {}", [ParserErrorCode.MISSING_STAR_AFTER_SYNC]); | 3845 "f() sync {}", [ParserErrorCode.MISSING_STAR_AFTER_SYNC]); |
| 3602 } | 3846 } |
| 3603 | 3847 |
| 3604 void test_isExpression_noType() { | 3848 void test_isExpression_noType() { |
| 3605 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 3849 CompilationUnit unit = ParserTestCase.parseCompilationUnit( |
| 3606 "class Bar<T extends Foo> {m(x){if (x is ) return;if (x is !)}}", [ | 3850 "class Bar<T extends Foo> {m(x){if (x is ) return;if (x is !)}}", [ |
| 3607 ParserErrorCode.EXPECTED_TYPE_NAME, | 3851 ParserErrorCode.EXPECTED_TYPE_NAME, |
| 3608 ParserErrorCode.EXPECTED_TYPE_NAME, | 3852 ParserErrorCode.EXPECTED_TYPE_NAME, |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3748 expect(members, hasLength(2)); | 3992 expect(members, hasLength(2)); |
| 3749 EngineTestCase.assertInstanceOf( | 3993 EngineTestCase.assertInstanceOf( |
| 3750 (obj) => obj is MethodDeclaration, MethodDeclaration, members[0]); | 3994 (obj) => obj is MethodDeclaration, MethodDeclaration, members[0]); |
| 3751 ClassMember member = members[1]; | 3995 ClassMember member = members[1]; |
| 3752 EngineTestCase.assertInstanceOf( | 3996 EngineTestCase.assertInstanceOf( |
| 3753 (obj) => obj is MethodDeclaration, MethodDeclaration, member); | 3997 (obj) => obj is MethodDeclaration, MethodDeclaration, member); |
| 3754 expect((member as MethodDeclaration).name.name, "foo"); | 3998 expect((member as MethodDeclaration).name.name, "foo"); |
| 3755 } | 3999 } |
| 3756 | 4000 |
| 3757 void test_missingIdentifier_afterAnnotation() { | 4001 void test_missingIdentifier_afterAnnotation() { |
| 3758 MethodDeclaration method = parse3("parseClassMember", <Object>["C"], | 4002 createParser('@override }'); |
| 3759 "@override }", [ParserErrorCode.EXPECTED_CLASS_MEMBER]); | 4003 ClassMember member = parser.parseClassMember('C'); |
| 4004 expectNotNullIfNoErrors(member); |
| 4005 listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_CLASS_MEMBER]); |
| 4006 expect(member, new isInstanceOf<MethodDeclaration>()); |
| 4007 MethodDeclaration method = member; |
| 3760 expect(method.documentationComment, isNull); | 4008 expect(method.documentationComment, isNull); |
| 3761 NodeList<Annotation> metadata = method.metadata; | 4009 NodeList<Annotation> metadata = method.metadata; |
| 3762 expect(metadata, hasLength(1)); | 4010 expect(metadata, hasLength(1)); |
| 3763 expect(metadata[0].name.name, "override"); | 4011 expect(metadata[0].name.name, "override"); |
| 3764 } | 4012 } |
| 3765 | 4013 |
| 4014 void test_missingSemicolon_varialeDeclarationList() { |
| 4015 void verify(CompilationUnitMember member, String expectedTypeName, |
| 4016 String expectedName, String expectedSemicolon) { |
| 4017 expect(member, new isInstanceOf<TopLevelVariableDeclaration>()); |
| 4018 TopLevelVariableDeclaration declaration = member; |
| 4019 VariableDeclarationList variableList = declaration.variables; |
| 4020 expect(variableList, isNotNull); |
| 4021 NodeList<VariableDeclaration> variables = variableList.variables; |
| 4022 expect(variables, hasLength(1)); |
| 4023 VariableDeclaration variable = variables[0]; |
| 4024 expect(variableList.type.toString(), expectedTypeName); |
| 4025 expect(variable.name.name, expectedName); |
| 4026 expect(declaration.semicolon.lexeme, expectedSemicolon); |
| 4027 } |
| 4028 |
| 4029 CompilationUnit unit = ParserTestCase.parseCompilationUnit( |
| 4030 'String n x = "";', [ |
| 4031 ParserErrorCode.EXPECTED_TOKEN, |
| 4032 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE |
| 4033 ]); |
| 4034 expect(unit, isNotNull); |
| 4035 NodeList<CompilationUnitMember> declarations = unit.declarations; |
| 4036 expect(declarations, hasLength(2)); |
| 4037 verify(declarations[0], 'String', 'n', ''); |
| 4038 verify(declarations[1], 'null', 'x', ';'); |
| 4039 } |
| 4040 |
| 3766 void test_multiplicativeExpression_missing_LHS() { | 4041 void test_multiplicativeExpression_missing_LHS() { |
| 3767 BinaryExpression expression = | 4042 BinaryExpression expression = |
| 3768 parseExpression("* y", [ParserErrorCode.MISSING_IDENTIFIER]); | 4043 parseExpression("* y", [ParserErrorCode.MISSING_IDENTIFIER]); |
| 3769 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, | 4044 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| 3770 SimpleIdentifier, expression.leftOperand); | 4045 SimpleIdentifier, expression.leftOperand); |
| 3771 expect(expression.leftOperand.isSynthetic, isTrue); | 4046 expect(expression.leftOperand.isSynthetic, isTrue); |
| 3772 } | 4047 } |
| 3773 | 4048 |
| 3774 void test_multiplicativeExpression_missing_LHS_RHS() { | 4049 void test_multiplicativeExpression_missing_LHS_RHS() { |
| 3775 BinaryExpression expression = parseExpression("*", [ | 4050 BinaryExpression expression = parseExpression("*", [ |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3832 void test_prefixExpression_missing_operand_minus() { | 4107 void test_prefixExpression_missing_operand_minus() { |
| 3833 PrefixExpression expression = | 4108 PrefixExpression expression = |
| 3834 parseExpression("-", [ParserErrorCode.MISSING_IDENTIFIER]); | 4109 parseExpression("-", [ParserErrorCode.MISSING_IDENTIFIER]); |
| 3835 EngineTestCase.assertInstanceOf( | 4110 EngineTestCase.assertInstanceOf( |
| 3836 (obj) => obj is SimpleIdentifier, SimpleIdentifier, expression.operand); | 4111 (obj) => obj is SimpleIdentifier, SimpleIdentifier, expression.operand); |
| 3837 expect(expression.operand.isSynthetic, isTrue); | 4112 expect(expression.operand.isSynthetic, isTrue); |
| 3838 expect(expression.operator.type, TokenType.MINUS); | 4113 expect(expression.operator.type, TokenType.MINUS); |
| 3839 } | 4114 } |
| 3840 | 4115 |
| 3841 void test_primaryExpression_argumentDefinitionTest() { | 4116 void test_primaryExpression_argumentDefinitionTest() { |
| 3842 Expression expression = parse4( | 4117 createParser('?a'); |
| 3843 "parsePrimaryExpression", "?a", [ParserErrorCode.UNEXPECTED_TOKEN]); | 4118 Expression expression = parser.parsePrimaryExpression(); |
| 3844 EngineTestCase.assertInstanceOf( | 4119 expectNotNullIfNoErrors(expression); |
| 3845 (obj) => obj is SimpleIdentifier, SimpleIdentifier, expression); | 4120 listener.assertErrorsWithCodes([ParserErrorCode.UNEXPECTED_TOKEN]); |
| 4121 expect(expression, new isInstanceOf<SimpleIdentifier>()); |
| 3846 } | 4122 } |
| 3847 | 4123 |
| 3848 void test_relationalExpression_missing_LHS() { | 4124 void test_relationalExpression_missing_LHS() { |
| 3849 IsExpression expression = | 4125 IsExpression expression = |
| 3850 parseExpression("is y", [ParserErrorCode.MISSING_IDENTIFIER]); | 4126 parseExpression("is y", [ParserErrorCode.MISSING_IDENTIFIER]); |
| 3851 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, | 4127 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| 3852 SimpleIdentifier, expression.expression); | 4128 SimpleIdentifier, expression.expression); |
| 3853 expect(expression.expression.isSynthetic, isTrue); | 4129 expect(expression.expression.isSynthetic, isTrue); |
| 3854 } | 4130 } |
| 3855 | 4131 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3960 CompilationUnitMember member = declarations[0]; | 4236 CompilationUnitMember member = declarations[0]; |
| 3961 EngineTestCase.assertInstanceOf( | 4237 EngineTestCase.assertInstanceOf( |
| 3962 (obj) => obj is FunctionTypeAlias, FunctionTypeAlias, member); | 4238 (obj) => obj is FunctionTypeAlias, FunctionTypeAlias, member); |
| 3963 } | 4239 } |
| 3964 | 4240 |
| 3965 void test_unaryPlus() { | 4241 void test_unaryPlus() { |
| 3966 parseExpression("+2", [ParserErrorCode.MISSING_IDENTIFIER]); | 4242 parseExpression("+2", [ParserErrorCode.MISSING_IDENTIFIER]); |
| 3967 } | 4243 } |
| 3968 } | 4244 } |
| 3969 | 4245 |
| 3970 @reflectiveTest | |
| 3971 class ResolutionCopierTest extends EngineTestCase { | |
| 3972 void test_visitAnnotation() { | |
| 3973 String annotationName = "proxy"; | |
| 3974 Annotation fromNode = | |
| 3975 AstFactory.annotation(AstFactory.identifier3(annotationName)); | |
| 3976 Element element = ElementFactory.topLevelVariableElement2(annotationName); | |
| 3977 fromNode.element = element; | |
| 3978 Annotation toNode = | |
| 3979 AstFactory.annotation(AstFactory.identifier3(annotationName)); | |
| 3980 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 3981 expect(toNode.element, same(element)); | |
| 3982 } | |
| 3983 | |
| 3984 void test_visitAsExpression() { | |
| 3985 AsExpression fromNode = AstFactory.asExpression( | |
| 3986 AstFactory.identifier3("x"), AstFactory.typeName4("A")); | |
| 3987 DartType propagatedType = ElementFactory.classElement2("A").type; | |
| 3988 fromNode.propagatedType = propagatedType; | |
| 3989 DartType staticType = ElementFactory.classElement2("B").type; | |
| 3990 fromNode.staticType = staticType; | |
| 3991 AsExpression toNode = AstFactory.asExpression( | |
| 3992 AstFactory.identifier3("x"), AstFactory.typeName4("A")); | |
| 3993 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 3994 expect(toNode.propagatedType, same(propagatedType)); | |
| 3995 expect(toNode.staticType, same(staticType)); | |
| 3996 } | |
| 3997 | |
| 3998 void test_visitAssignmentExpression() { | |
| 3999 AssignmentExpression fromNode = AstFactory.assignmentExpression( | |
| 4000 AstFactory.identifier3("a"), | |
| 4001 TokenType.PLUS_EQ, | |
| 4002 AstFactory.identifier3("b")); | |
| 4003 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4004 MethodElement propagatedElement = | |
| 4005 ElementFactory.methodElement("+", propagatedType); | |
| 4006 fromNode.propagatedElement = propagatedElement; | |
| 4007 fromNode.propagatedType = propagatedType; | |
| 4008 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4009 MethodElement staticElement = ElementFactory.methodElement("+", staticType); | |
| 4010 fromNode.staticElement = staticElement; | |
| 4011 fromNode.staticType = staticType; | |
| 4012 AssignmentExpression toNode = AstFactory.assignmentExpression( | |
| 4013 AstFactory.identifier3("a"), | |
| 4014 TokenType.PLUS_EQ, | |
| 4015 AstFactory.identifier3("b")); | |
| 4016 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4017 expect(toNode.propagatedElement, same(propagatedElement)); | |
| 4018 expect(toNode.propagatedType, same(propagatedType)); | |
| 4019 expect(toNode.staticElement, same(staticElement)); | |
| 4020 expect(toNode.staticType, same(staticType)); | |
| 4021 } | |
| 4022 | |
| 4023 void test_visitBinaryExpression() { | |
| 4024 BinaryExpression fromNode = AstFactory.binaryExpression( | |
| 4025 AstFactory.identifier3("a"), | |
| 4026 TokenType.PLUS, | |
| 4027 AstFactory.identifier3("b")); | |
| 4028 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4029 MethodElement propagatedElement = | |
| 4030 ElementFactory.methodElement("+", propagatedType); | |
| 4031 fromNode.propagatedElement = propagatedElement; | |
| 4032 fromNode.propagatedType = propagatedType; | |
| 4033 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4034 MethodElement staticElement = ElementFactory.methodElement("+", staticType); | |
| 4035 fromNode.staticElement = staticElement; | |
| 4036 fromNode.staticType = staticType; | |
| 4037 BinaryExpression toNode = AstFactory.binaryExpression( | |
| 4038 AstFactory.identifier3("a"), | |
| 4039 TokenType.PLUS, | |
| 4040 AstFactory.identifier3("b")); | |
| 4041 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4042 expect(toNode.propagatedElement, same(propagatedElement)); | |
| 4043 expect(toNode.propagatedType, same(propagatedType)); | |
| 4044 expect(toNode.staticElement, same(staticElement)); | |
| 4045 expect(toNode.staticType, same(staticType)); | |
| 4046 } | |
| 4047 | |
| 4048 void test_visitBooleanLiteral() { | |
| 4049 BooleanLiteral fromNode = AstFactory.booleanLiteral(true); | |
| 4050 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4051 fromNode.propagatedType = propagatedType; | |
| 4052 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4053 fromNode.staticType = staticType; | |
| 4054 BooleanLiteral toNode = AstFactory.booleanLiteral(true); | |
| 4055 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4056 expect(toNode.propagatedType, same(propagatedType)); | |
| 4057 expect(toNode.staticType, same(staticType)); | |
| 4058 } | |
| 4059 | |
| 4060 void test_visitCascadeExpression() { | |
| 4061 CascadeExpression fromNode = AstFactory.cascadeExpression( | |
| 4062 AstFactory.identifier3("a"), [AstFactory.identifier3("b")]); | |
| 4063 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4064 fromNode.propagatedType = propagatedType; | |
| 4065 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4066 fromNode.staticType = staticType; | |
| 4067 CascadeExpression toNode = AstFactory.cascadeExpression( | |
| 4068 AstFactory.identifier3("a"), [AstFactory.identifier3("b")]); | |
| 4069 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4070 expect(toNode.propagatedType, same(propagatedType)); | |
| 4071 expect(toNode.staticType, same(staticType)); | |
| 4072 } | |
| 4073 | |
| 4074 void test_visitCompilationUnit() { | |
| 4075 CompilationUnit fromNode = AstFactory.compilationUnit(); | |
| 4076 CompilationUnitElement element = | |
| 4077 new CompilationUnitElementImpl("test.dart"); | |
| 4078 fromNode.element = element; | |
| 4079 CompilationUnit toNode = AstFactory.compilationUnit(); | |
| 4080 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4081 expect(toNode.element, same(element)); | |
| 4082 } | |
| 4083 | |
| 4084 void test_visitConditionalExpression() { | |
| 4085 ConditionalExpression fromNode = AstFactory.conditionalExpression( | |
| 4086 AstFactory.identifier3("c"), | |
| 4087 AstFactory.identifier3("a"), | |
| 4088 AstFactory.identifier3("b")); | |
| 4089 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4090 fromNode.propagatedType = propagatedType; | |
| 4091 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4092 fromNode.staticType = staticType; | |
| 4093 ConditionalExpression toNode = AstFactory.conditionalExpression( | |
| 4094 AstFactory.identifier3("c"), | |
| 4095 AstFactory.identifier3("a"), | |
| 4096 AstFactory.identifier3("b")); | |
| 4097 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4098 expect(toNode.propagatedType, same(propagatedType)); | |
| 4099 expect(toNode.staticType, same(staticType)); | |
| 4100 } | |
| 4101 | |
| 4102 void test_visitConstructorDeclaration() { | |
| 4103 String className = "A"; | |
| 4104 String constructorName = "c"; | |
| 4105 ConstructorDeclaration fromNode = AstFactory.constructorDeclaration( | |
| 4106 AstFactory.identifier3(className), | |
| 4107 constructorName, | |
| 4108 AstFactory.formalParameterList(), | |
| 4109 null); | |
| 4110 ConstructorElement element = ElementFactory.constructorElement2( | |
| 4111 ElementFactory.classElement2(className), constructorName); | |
| 4112 fromNode.element = element; | |
| 4113 ConstructorDeclaration toNode = AstFactory.constructorDeclaration( | |
| 4114 AstFactory.identifier3(className), | |
| 4115 constructorName, | |
| 4116 AstFactory.formalParameterList(), | |
| 4117 null); | |
| 4118 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4119 expect(toNode.element, same(element)); | |
| 4120 } | |
| 4121 | |
| 4122 void test_visitConstructorName() { | |
| 4123 ConstructorName fromNode = | |
| 4124 AstFactory.constructorName(AstFactory.typeName4("A"), "c"); | |
| 4125 ConstructorElement staticElement = ElementFactory.constructorElement2( | |
| 4126 ElementFactory.classElement2("A"), "c"); | |
| 4127 fromNode.staticElement = staticElement; | |
| 4128 ConstructorName toNode = | |
| 4129 AstFactory.constructorName(AstFactory.typeName4("A"), "c"); | |
| 4130 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4131 expect(toNode.staticElement, same(staticElement)); | |
| 4132 } | |
| 4133 | |
| 4134 void test_visitDoubleLiteral() { | |
| 4135 DoubleLiteral fromNode = AstFactory.doubleLiteral(1.0); | |
| 4136 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4137 fromNode.propagatedType = propagatedType; | |
| 4138 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4139 fromNode.staticType = staticType; | |
| 4140 DoubleLiteral toNode = AstFactory.doubleLiteral(1.0); | |
| 4141 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4142 expect(toNode.propagatedType, same(propagatedType)); | |
| 4143 expect(toNode.staticType, same(staticType)); | |
| 4144 } | |
| 4145 | |
| 4146 void test_visitExportDirective() { | |
| 4147 ExportDirective fromNode = AstFactory.exportDirective2("dart:uri"); | |
| 4148 ExportElement element = new ExportElementImpl(-1); | |
| 4149 fromNode.element = element; | |
| 4150 ExportDirective toNode = AstFactory.exportDirective2("dart:uri"); | |
| 4151 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4152 expect(toNode.element, same(element)); | |
| 4153 } | |
| 4154 | |
| 4155 void test_visitFunctionExpression() { | |
| 4156 FunctionExpression fromNode = AstFactory.functionExpression2( | |
| 4157 AstFactory.formalParameterList(), AstFactory.emptyFunctionBody()); | |
| 4158 MethodElement element = ElementFactory.methodElement( | |
| 4159 "m", ElementFactory.classElement2("C").type); | |
| 4160 fromNode.element = element; | |
| 4161 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4162 fromNode.propagatedType = propagatedType; | |
| 4163 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4164 fromNode.staticType = staticType; | |
| 4165 FunctionExpression toNode = AstFactory.functionExpression2( | |
| 4166 AstFactory.formalParameterList(), AstFactory.emptyFunctionBody()); | |
| 4167 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4168 expect(toNode.element, same(element)); | |
| 4169 expect(toNode.propagatedType, same(propagatedType)); | |
| 4170 expect(toNode.staticType, same(staticType)); | |
| 4171 } | |
| 4172 | |
| 4173 void test_visitFunctionExpressionInvocation() { | |
| 4174 FunctionExpressionInvocation fromNode = | |
| 4175 AstFactory.functionExpressionInvocation(AstFactory.identifier3("f")); | |
| 4176 MethodElement propagatedElement = ElementFactory.methodElement( | |
| 4177 "m", ElementFactory.classElement2("C").type); | |
| 4178 fromNode.propagatedElement = propagatedElement; | |
| 4179 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4180 fromNode.propagatedType = propagatedType; | |
| 4181 MethodElement staticElement = ElementFactory.methodElement( | |
| 4182 "m", ElementFactory.classElement2("C").type); | |
| 4183 fromNode.staticElement = staticElement; | |
| 4184 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4185 fromNode.staticType = staticType; | |
| 4186 FunctionExpressionInvocation toNode = | |
| 4187 AstFactory.functionExpressionInvocation(AstFactory.identifier3("f")); | |
| 4188 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4189 expect(toNode.propagatedElement, same(propagatedElement)); | |
| 4190 expect(toNode.propagatedType, same(propagatedType)); | |
| 4191 expect(toNode.staticElement, same(staticElement)); | |
| 4192 expect(toNode.staticType, same(staticType)); | |
| 4193 } | |
| 4194 | |
| 4195 void test_visitImportDirective() { | |
| 4196 ImportDirective fromNode = AstFactory.importDirective3("dart:uri", null); | |
| 4197 ImportElement element = new ImportElementImpl(0); | |
| 4198 fromNode.element = element; | |
| 4199 ImportDirective toNode = AstFactory.importDirective3("dart:uri", null); | |
| 4200 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4201 expect(toNode.element, same(element)); | |
| 4202 } | |
| 4203 | |
| 4204 void test_visitIndexExpression() { | |
| 4205 IndexExpression fromNode = AstFactory.indexExpression( | |
| 4206 AstFactory.identifier3("a"), AstFactory.integer(0)); | |
| 4207 MethodElement propagatedElement = ElementFactory.methodElement( | |
| 4208 "m", ElementFactory.classElement2("C").type); | |
| 4209 MethodElement staticElement = ElementFactory.methodElement( | |
| 4210 "m", ElementFactory.classElement2("C").type); | |
| 4211 AuxiliaryElements auxiliaryElements = | |
| 4212 new AuxiliaryElements(staticElement, propagatedElement); | |
| 4213 fromNode.auxiliaryElements = auxiliaryElements; | |
| 4214 fromNode.propagatedElement = propagatedElement; | |
| 4215 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4216 fromNode.propagatedType = propagatedType; | |
| 4217 fromNode.staticElement = staticElement; | |
| 4218 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4219 fromNode.staticType = staticType; | |
| 4220 IndexExpression toNode = AstFactory.indexExpression( | |
| 4221 AstFactory.identifier3("a"), AstFactory.integer(0)); | |
| 4222 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4223 expect(toNode.auxiliaryElements, same(auxiliaryElements)); | |
| 4224 expect(toNode.propagatedElement, same(propagatedElement)); | |
| 4225 expect(toNode.propagatedType, same(propagatedType)); | |
| 4226 expect(toNode.staticElement, same(staticElement)); | |
| 4227 expect(toNode.staticType, same(staticType)); | |
| 4228 } | |
| 4229 | |
| 4230 void test_visitInstanceCreationExpression() { | |
| 4231 InstanceCreationExpression fromNode = AstFactory | |
| 4232 .instanceCreationExpression2(Keyword.NEW, AstFactory.typeName4("C")); | |
| 4233 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4234 fromNode.propagatedType = propagatedType; | |
| 4235 ConstructorElement staticElement = ElementFactory.constructorElement2( | |
| 4236 ElementFactory.classElement2("C"), null); | |
| 4237 fromNode.staticElement = staticElement; | |
| 4238 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4239 fromNode.staticType = staticType; | |
| 4240 InstanceCreationExpression toNode = AstFactory.instanceCreationExpression2( | |
| 4241 Keyword.NEW, AstFactory.typeName4("C")); | |
| 4242 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4243 expect(toNode.propagatedType, same(propagatedType)); | |
| 4244 expect(toNode.staticElement, same(staticElement)); | |
| 4245 expect(toNode.staticType, same(staticType)); | |
| 4246 } | |
| 4247 | |
| 4248 void test_visitIntegerLiteral() { | |
| 4249 IntegerLiteral fromNode = AstFactory.integer(2); | |
| 4250 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4251 fromNode.propagatedType = propagatedType; | |
| 4252 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4253 fromNode.staticType = staticType; | |
| 4254 IntegerLiteral toNode = AstFactory.integer(2); | |
| 4255 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4256 expect(toNode.propagatedType, same(propagatedType)); | |
| 4257 expect(toNode.staticType, same(staticType)); | |
| 4258 } | |
| 4259 | |
| 4260 void test_visitIsExpression() { | |
| 4261 IsExpression fromNode = AstFactory.isExpression( | |
| 4262 AstFactory.identifier3("x"), false, AstFactory.typeName4("A")); | |
| 4263 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4264 fromNode.propagatedType = propagatedType; | |
| 4265 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4266 fromNode.staticType = staticType; | |
| 4267 IsExpression toNode = AstFactory.isExpression( | |
| 4268 AstFactory.identifier3("x"), false, AstFactory.typeName4("A")); | |
| 4269 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4270 expect(toNode.propagatedType, same(propagatedType)); | |
| 4271 expect(toNode.staticType, same(staticType)); | |
| 4272 } | |
| 4273 | |
| 4274 void test_visitLibraryIdentifier() { | |
| 4275 LibraryIdentifier fromNode = | |
| 4276 AstFactory.libraryIdentifier([AstFactory.identifier3("lib")]); | |
| 4277 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4278 fromNode.propagatedType = propagatedType; | |
| 4279 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4280 fromNode.staticType = staticType; | |
| 4281 LibraryIdentifier toNode = | |
| 4282 AstFactory.libraryIdentifier([AstFactory.identifier3("lib")]); | |
| 4283 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4284 expect(toNode.propagatedType, same(propagatedType)); | |
| 4285 expect(toNode.staticType, same(staticType)); | |
| 4286 } | |
| 4287 | |
| 4288 void test_visitListLiteral() { | |
| 4289 ListLiteral fromNode = AstFactory.listLiteral(); | |
| 4290 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4291 fromNode.propagatedType = propagatedType; | |
| 4292 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4293 fromNode.staticType = staticType; | |
| 4294 ListLiteral toNode = AstFactory.listLiteral(); | |
| 4295 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4296 expect(toNode.propagatedType, same(propagatedType)); | |
| 4297 expect(toNode.staticType, same(staticType)); | |
| 4298 } | |
| 4299 | |
| 4300 void test_visitMapLiteral() { | |
| 4301 MapLiteral fromNode = AstFactory.mapLiteral2(); | |
| 4302 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4303 fromNode.propagatedType = propagatedType; | |
| 4304 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4305 fromNode.staticType = staticType; | |
| 4306 MapLiteral toNode = AstFactory.mapLiteral2(); | |
| 4307 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4308 expect(toNode.propagatedType, same(propagatedType)); | |
| 4309 expect(toNode.staticType, same(staticType)); | |
| 4310 } | |
| 4311 | |
| 4312 void test_visitMethodInvocation() { | |
| 4313 MethodInvocation fromNode = AstFactory.methodInvocation2("m"); | |
| 4314 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4315 fromNode.propagatedType = propagatedType; | |
| 4316 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4317 fromNode.staticType = staticType; | |
| 4318 MethodInvocation toNode = AstFactory.methodInvocation2("m"); | |
| 4319 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4320 expect(toNode.propagatedType, same(propagatedType)); | |
| 4321 expect(toNode.staticType, same(staticType)); | |
| 4322 } | |
| 4323 | |
| 4324 void test_visitNamedExpression() { | |
| 4325 NamedExpression fromNode = | |
| 4326 AstFactory.namedExpression2("n", AstFactory.integer(0)); | |
| 4327 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4328 fromNode.propagatedType = propagatedType; | |
| 4329 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4330 fromNode.staticType = staticType; | |
| 4331 NamedExpression toNode = | |
| 4332 AstFactory.namedExpression2("n", AstFactory.integer(0)); | |
| 4333 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4334 expect(toNode.propagatedType, same(propagatedType)); | |
| 4335 expect(toNode.staticType, same(staticType)); | |
| 4336 } | |
| 4337 | |
| 4338 void test_visitNullLiteral() { | |
| 4339 NullLiteral fromNode = AstFactory.nullLiteral(); | |
| 4340 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4341 fromNode.propagatedType = propagatedType; | |
| 4342 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4343 fromNode.staticType = staticType; | |
| 4344 NullLiteral toNode = AstFactory.nullLiteral(); | |
| 4345 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4346 expect(toNode.propagatedType, same(propagatedType)); | |
| 4347 expect(toNode.staticType, same(staticType)); | |
| 4348 } | |
| 4349 | |
| 4350 void test_visitParenthesizedExpression() { | |
| 4351 ParenthesizedExpression fromNode = | |
| 4352 AstFactory.parenthesizedExpression(AstFactory.integer(0)); | |
| 4353 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4354 fromNode.propagatedType = propagatedType; | |
| 4355 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4356 fromNode.staticType = staticType; | |
| 4357 ParenthesizedExpression toNode = | |
| 4358 AstFactory.parenthesizedExpression(AstFactory.integer(0)); | |
| 4359 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4360 expect(toNode.propagatedType, same(propagatedType)); | |
| 4361 expect(toNode.staticType, same(staticType)); | |
| 4362 } | |
| 4363 | |
| 4364 void test_visitPartDirective() { | |
| 4365 PartDirective fromNode = AstFactory.partDirective2("part.dart"); | |
| 4366 LibraryElement element = new LibraryElementImpl.forNode( | |
| 4367 null, AstFactory.libraryIdentifier2(["lib"])); | |
| 4368 fromNode.element = element; | |
| 4369 PartDirective toNode = AstFactory.partDirective2("part.dart"); | |
| 4370 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4371 expect(toNode.element, same(element)); | |
| 4372 } | |
| 4373 | |
| 4374 void test_visitPartOfDirective() { | |
| 4375 PartOfDirective fromNode = | |
| 4376 AstFactory.partOfDirective(AstFactory.libraryIdentifier2(["lib"])); | |
| 4377 LibraryElement element = new LibraryElementImpl.forNode( | |
| 4378 null, AstFactory.libraryIdentifier2(["lib"])); | |
| 4379 fromNode.element = element; | |
| 4380 PartOfDirective toNode = | |
| 4381 AstFactory.partOfDirective(AstFactory.libraryIdentifier2(["lib"])); | |
| 4382 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4383 expect(toNode.element, same(element)); | |
| 4384 } | |
| 4385 | |
| 4386 void test_visitPostfixExpression() { | |
| 4387 String variableName = "x"; | |
| 4388 PostfixExpression fromNode = AstFactory.postfixExpression( | |
| 4389 AstFactory.identifier3(variableName), TokenType.PLUS_PLUS); | |
| 4390 MethodElement propagatedElement = ElementFactory.methodElement( | |
| 4391 "+", ElementFactory.classElement2("C").type); | |
| 4392 fromNode.propagatedElement = propagatedElement; | |
| 4393 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4394 fromNode.propagatedType = propagatedType; | |
| 4395 MethodElement staticElement = ElementFactory.methodElement( | |
| 4396 "+", ElementFactory.classElement2("C").type); | |
| 4397 fromNode.staticElement = staticElement; | |
| 4398 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4399 fromNode.staticType = staticType; | |
| 4400 PostfixExpression toNode = AstFactory.postfixExpression( | |
| 4401 AstFactory.identifier3(variableName), TokenType.PLUS_PLUS); | |
| 4402 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4403 expect(toNode.propagatedElement, same(propagatedElement)); | |
| 4404 expect(toNode.propagatedType, same(propagatedType)); | |
| 4405 expect(toNode.staticElement, same(staticElement)); | |
| 4406 expect(toNode.staticType, same(staticType)); | |
| 4407 } | |
| 4408 | |
| 4409 void test_visitPrefixedIdentifier() { | |
| 4410 PrefixedIdentifier fromNode = AstFactory.identifier5("p", "f"); | |
| 4411 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4412 fromNode.propagatedType = propagatedType; | |
| 4413 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4414 fromNode.staticType = staticType; | |
| 4415 PrefixedIdentifier toNode = AstFactory.identifier5("p", "f"); | |
| 4416 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4417 expect(toNode.propagatedType, same(propagatedType)); | |
| 4418 expect(toNode.staticType, same(staticType)); | |
| 4419 } | |
| 4420 | |
| 4421 void test_visitPrefixExpression() { | |
| 4422 PrefixExpression fromNode = AstFactory.prefixExpression( | |
| 4423 TokenType.PLUS_PLUS, AstFactory.identifier3("x")); | |
| 4424 MethodElement propagatedElement = ElementFactory.methodElement( | |
| 4425 "+", ElementFactory.classElement2("C").type); | |
| 4426 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4427 fromNode.propagatedElement = propagatedElement; | |
| 4428 fromNode.propagatedType = propagatedType; | |
| 4429 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4430 MethodElement staticElement = ElementFactory.methodElement( | |
| 4431 "+", ElementFactory.classElement2("C").type); | |
| 4432 fromNode.staticElement = staticElement; | |
| 4433 fromNode.staticType = staticType; | |
| 4434 PrefixExpression toNode = AstFactory.prefixExpression( | |
| 4435 TokenType.PLUS_PLUS, AstFactory.identifier3("x")); | |
| 4436 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4437 expect(toNode.propagatedElement, same(propagatedElement)); | |
| 4438 expect(toNode.propagatedType, same(propagatedType)); | |
| 4439 expect(toNode.staticElement, same(staticElement)); | |
| 4440 expect(toNode.staticType, same(staticType)); | |
| 4441 } | |
| 4442 | |
| 4443 void test_visitPropertyAccess() { | |
| 4444 PropertyAccess fromNode = | |
| 4445 AstFactory.propertyAccess2(AstFactory.identifier3("x"), "y"); | |
| 4446 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4447 fromNode.propagatedType = propagatedType; | |
| 4448 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4449 fromNode.staticType = staticType; | |
| 4450 PropertyAccess toNode = | |
| 4451 AstFactory.propertyAccess2(AstFactory.identifier3("x"), "y"); | |
| 4452 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4453 expect(toNode.propagatedType, same(propagatedType)); | |
| 4454 expect(toNode.staticType, same(staticType)); | |
| 4455 } | |
| 4456 | |
| 4457 void test_visitRedirectingConstructorInvocation() { | |
| 4458 RedirectingConstructorInvocation fromNode = | |
| 4459 AstFactory.redirectingConstructorInvocation(); | |
| 4460 ConstructorElement staticElement = ElementFactory.constructorElement2( | |
| 4461 ElementFactory.classElement2("C"), null); | |
| 4462 fromNode.staticElement = staticElement; | |
| 4463 RedirectingConstructorInvocation toNode = | |
| 4464 AstFactory.redirectingConstructorInvocation(); | |
| 4465 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4466 expect(toNode.staticElement, same(staticElement)); | |
| 4467 } | |
| 4468 | |
| 4469 void test_visitRethrowExpression() { | |
| 4470 RethrowExpression fromNode = AstFactory.rethrowExpression(); | |
| 4471 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4472 fromNode.propagatedType = propagatedType; | |
| 4473 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4474 fromNode.staticType = staticType; | |
| 4475 RethrowExpression toNode = AstFactory.rethrowExpression(); | |
| 4476 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4477 expect(toNode.propagatedType, same(propagatedType)); | |
| 4478 expect(toNode.staticType, same(staticType)); | |
| 4479 } | |
| 4480 | |
| 4481 void test_visitSimpleIdentifier() { | |
| 4482 SimpleIdentifier fromNode = AstFactory.identifier3("x"); | |
| 4483 MethodElement propagatedElement = ElementFactory.methodElement( | |
| 4484 "m", ElementFactory.classElement2("C").type); | |
| 4485 MethodElement staticElement = ElementFactory.methodElement( | |
| 4486 "m", ElementFactory.classElement2("C").type); | |
| 4487 AuxiliaryElements auxiliaryElements = | |
| 4488 new AuxiliaryElements(staticElement, propagatedElement); | |
| 4489 fromNode.auxiliaryElements = auxiliaryElements; | |
| 4490 fromNode.propagatedElement = propagatedElement; | |
| 4491 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4492 fromNode.propagatedType = propagatedType; | |
| 4493 fromNode.staticElement = staticElement; | |
| 4494 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4495 fromNode.staticType = staticType; | |
| 4496 SimpleIdentifier toNode = AstFactory.identifier3("x"); | |
| 4497 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4498 expect(toNode.auxiliaryElements, same(auxiliaryElements)); | |
| 4499 expect(toNode.propagatedElement, same(propagatedElement)); | |
| 4500 expect(toNode.propagatedType, same(propagatedType)); | |
| 4501 expect(toNode.staticElement, same(staticElement)); | |
| 4502 expect(toNode.staticType, same(staticType)); | |
| 4503 } | |
| 4504 | |
| 4505 void test_visitSimpleStringLiteral() { | |
| 4506 SimpleStringLiteral fromNode = AstFactory.string2("abc"); | |
| 4507 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4508 fromNode.propagatedType = propagatedType; | |
| 4509 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4510 fromNode.staticType = staticType; | |
| 4511 SimpleStringLiteral toNode = AstFactory.string2("abc"); | |
| 4512 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4513 expect(toNode.propagatedType, same(propagatedType)); | |
| 4514 expect(toNode.staticType, same(staticType)); | |
| 4515 } | |
| 4516 | |
| 4517 void test_visitStringInterpolation() { | |
| 4518 StringInterpolation fromNode = | |
| 4519 AstFactory.string([AstFactory.interpolationString("a", "'a'")]); | |
| 4520 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4521 fromNode.propagatedType = propagatedType; | |
| 4522 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4523 fromNode.staticType = staticType; | |
| 4524 StringInterpolation toNode = | |
| 4525 AstFactory.string([AstFactory.interpolationString("a", "'a'")]); | |
| 4526 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4527 expect(toNode.propagatedType, same(propagatedType)); | |
| 4528 expect(toNode.staticType, same(staticType)); | |
| 4529 } | |
| 4530 | |
| 4531 void test_visitSuperConstructorInvocation() { | |
| 4532 SuperConstructorInvocation fromNode = | |
| 4533 AstFactory.superConstructorInvocation(); | |
| 4534 ConstructorElement staticElement = ElementFactory.constructorElement2( | |
| 4535 ElementFactory.classElement2("C"), null); | |
| 4536 fromNode.staticElement = staticElement; | |
| 4537 SuperConstructorInvocation toNode = AstFactory.superConstructorInvocation(); | |
| 4538 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4539 expect(toNode.staticElement, same(staticElement)); | |
| 4540 } | |
| 4541 | |
| 4542 void test_visitSuperExpression() { | |
| 4543 SuperExpression fromNode = AstFactory.superExpression(); | |
| 4544 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4545 fromNode.propagatedType = propagatedType; | |
| 4546 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4547 fromNode.staticType = staticType; | |
| 4548 SuperExpression toNode = AstFactory.superExpression(); | |
| 4549 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4550 expect(toNode.propagatedType, same(propagatedType)); | |
| 4551 expect(toNode.staticType, same(staticType)); | |
| 4552 } | |
| 4553 | |
| 4554 void test_visitSymbolLiteral() { | |
| 4555 SymbolLiteral fromNode = AstFactory.symbolLiteral(["s"]); | |
| 4556 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4557 fromNode.propagatedType = propagatedType; | |
| 4558 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4559 fromNode.staticType = staticType; | |
| 4560 SymbolLiteral toNode = AstFactory.symbolLiteral(["s"]); | |
| 4561 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4562 expect(toNode.propagatedType, same(propagatedType)); | |
| 4563 expect(toNode.staticType, same(staticType)); | |
| 4564 } | |
| 4565 | |
| 4566 void test_visitThisExpression() { | |
| 4567 ThisExpression fromNode = AstFactory.thisExpression(); | |
| 4568 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4569 fromNode.propagatedType = propagatedType; | |
| 4570 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4571 fromNode.staticType = staticType; | |
| 4572 ThisExpression toNode = AstFactory.thisExpression(); | |
| 4573 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4574 expect(toNode.propagatedType, same(propagatedType)); | |
| 4575 expect(toNode.staticType, same(staticType)); | |
| 4576 } | |
| 4577 | |
| 4578 void test_visitThrowExpression() { | |
| 4579 ThrowExpression fromNode = AstFactory.throwExpression(); | |
| 4580 DartType propagatedType = ElementFactory.classElement2("C").type; | |
| 4581 fromNode.propagatedType = propagatedType; | |
| 4582 DartType staticType = ElementFactory.classElement2("C").type; | |
| 4583 fromNode.staticType = staticType; | |
| 4584 ThrowExpression toNode = AstFactory.throwExpression(); | |
| 4585 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4586 expect(toNode.propagatedType, same(propagatedType)); | |
| 4587 expect(toNode.staticType, same(staticType)); | |
| 4588 } | |
| 4589 | |
| 4590 void test_visitTypeName() { | |
| 4591 TypeName fromNode = AstFactory.typeName4("C"); | |
| 4592 DartType type = ElementFactory.classElement2("C").type; | |
| 4593 fromNode.type = type; | |
| 4594 TypeName toNode = AstFactory.typeName4("C"); | |
| 4595 ResolutionCopier.copyResolutionData(fromNode, toNode); | |
| 4596 expect(toNode.type, same(type)); | |
| 4597 } | |
| 4598 } | |
| 4599 | |
| 4600 /** | 4246 /** |
| 4601 * The class `SimpleParserTest` defines parser tests that test individual parsin
g method. The | 4247 * The class `SimpleParserTest` defines parser tests that test individual parsin
g method. The |
| 4602 * code fragments should be as minimal as possible in order to test the method,
but should not test | 4248 * code fragments should be as minimal as possible in order to test the method,
but should not test |
| 4603 * the interactions between the method under test and other methods. | 4249 * the interactions between the method under test and other methods. |
| 4604 * | 4250 * |
| 4605 * More complex tests should be defined in the class [ComplexParserTest]. | 4251 * More complex tests should be defined in the class [ComplexParserTest]. |
| 4606 */ | 4252 */ |
| 4607 @reflectiveTest | 4253 @reflectiveTest |
| 4608 class SimpleParserTest extends ParserTestCase { | 4254 class SimpleParserTest extends ParserTestCase { |
| 4609 void fail_parseAwaitExpression_inSync() { | |
| 4610 // This test requires better error recovery than we currently have. In | |
| 4611 // particular, we need to be able to distinguish between an await expression | |
| 4612 // in the wrong context, and the use of 'await' as an identifier. | |
| 4613 MethodDeclaration method = parse( | |
| 4614 "parseClassMember", <Object>["C"], "m() { return await x + await y; }"); | |
| 4615 FunctionBody body = method.body; | |
| 4616 EngineTestCase.assertInstanceOf( | |
| 4617 (obj) => obj is BlockFunctionBody, BlockFunctionBody, body); | |
| 4618 Statement statement = (body as BlockFunctionBody).block.statements[0]; | |
| 4619 EngineTestCase.assertInstanceOf( | |
| 4620 (obj) => obj is ReturnStatement, ReturnStatement, statement); | |
| 4621 Expression expression = (statement as ReturnStatement).expression; | |
| 4622 EngineTestCase.assertInstanceOf( | |
| 4623 (obj) => obj is BinaryExpression, BinaryExpression, expression); | |
| 4624 EngineTestCase.assertInstanceOf((obj) => obj is AwaitExpression, | |
| 4625 AwaitExpression, (expression as BinaryExpression).leftOperand); | |
| 4626 EngineTestCase.assertInstanceOf((obj) => obj is AwaitExpression, | |
| 4627 AwaitExpression, (expression as BinaryExpression).rightOperand); | |
| 4628 } | |
| 4629 | |
| 4630 void fail_parseCommentReference_this() { | |
| 4631 // This fails because we are returning null from the method and asserting | |
| 4632 // that the return value is not null. | |
| 4633 CommentReference reference = | |
| 4634 parse("parseCommentReference", <Object>["this", 5], ""); | |
| 4635 SimpleIdentifier identifier = EngineTestCase.assertInstanceOf( | |
| 4636 (obj) => obj is SimpleIdentifier, | |
| 4637 SimpleIdentifier, | |
| 4638 reference.identifier); | |
| 4639 expect(identifier.token, isNotNull); | |
| 4640 expect(identifier.name, "a"); | |
| 4641 expect(identifier.offset, 5); | |
| 4642 } | |
| 4643 | |
| 4644 void test_computeStringValue_emptyInterpolationPrefix() { | 4255 void test_computeStringValue_emptyInterpolationPrefix() { |
| 4645 expect(_computeStringValue("'''", true, false), ""); | 4256 expect(_computeStringValue("'''", true, false), ""); |
| 4646 } | 4257 } |
| 4647 | 4258 |
| 4648 void test_computeStringValue_escape_b() { | 4259 void test_computeStringValue_escape_b() { |
| 4649 expect(_computeStringValue("'\\b'", true, true), "\b"); | 4260 expect(_computeStringValue("'\\b'", true, true), "\b"); |
| 4650 } | 4261 } |
| 4651 | 4262 |
| 4652 void test_computeStringValue_escape_f() { | 4263 void test_computeStringValue_escape_f() { |
| 4653 expect(_computeStringValue("'\\f'", true, true), "\f"); | 4264 expect(_computeStringValue("'\\f'", true, true), "\f"); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4715 | 4326 |
| 4716 void test_computeStringValue_triple_internalQuote_last_empty() { | 4327 void test_computeStringValue_triple_internalQuote_last_empty() { |
| 4717 expect(_computeStringValue("'''", false, true), ""); | 4328 expect(_computeStringValue("'''", false, true), ""); |
| 4718 } | 4329 } |
| 4719 | 4330 |
| 4720 void test_computeStringValue_triple_internalQuote_last_nonEmpty() { | 4331 void test_computeStringValue_triple_internalQuote_last_nonEmpty() { |
| 4721 expect(_computeStringValue("text'''", false, true), "text"); | 4332 expect(_computeStringValue("text'''", false, true), "text"); |
| 4722 } | 4333 } |
| 4723 | 4334 |
| 4724 void test_constFactory() { | 4335 void test_constFactory() { |
| 4725 parse("parseClassMember", <Object>["C"], "const factory C() = A;"); | 4336 createParser('const factory C() = A;'); |
| 4337 ClassMember member = parser.parseClassMember('C'); |
| 4338 expectNotNullIfNoErrors(member); |
| 4339 listener.assertNoErrors(); |
| 4726 } | 4340 } |
| 4727 | 4341 |
| 4728 void test_createSyntheticIdentifier() { | 4342 void test_createSyntheticIdentifier() { |
| 4729 SimpleIdentifier identifier = _createSyntheticIdentifier(); | 4343 createParser(''); |
| 4344 SimpleIdentifier identifier = parser.createSyntheticIdentifier(); |
| 4345 expectNotNullIfNoErrors(identifier); |
| 4730 expect(identifier.isSynthetic, isTrue); | 4346 expect(identifier.isSynthetic, isTrue); |
| 4731 } | 4347 } |
| 4732 | 4348 |
| 4733 void test_createSyntheticStringLiteral() { | 4349 void test_createSyntheticStringLiteral() { |
| 4734 SimpleStringLiteral literal = _createSyntheticStringLiteral(); | 4350 createParser(''); |
| 4351 SimpleStringLiteral literal = parser.createSyntheticStringLiteral(); |
| 4352 expectNotNullIfNoErrors(literal); |
| 4735 expect(literal.isSynthetic, isTrue); | 4353 expect(literal.isSynthetic, isTrue); |
| 4736 } | 4354 } |
| 4737 | 4355 |
| 4738 void test_function_literal_allowed_at_toplevel() { | 4356 void test_function_literal_allowed_at_toplevel() { |
| 4739 ParserTestCase.parseCompilationUnit("var x = () {};"); | 4357 ParserTestCase.parseCompilationUnit("var x = () {};"); |
| 4740 } | 4358 } |
| 4741 | 4359 |
| 4742 void test_function_literal_allowed_in_ArgumentList_in_ConstructorFieldInitiali
zer() { | 4360 void |
| 4361 test_function_literal_allowed_in_ArgumentList_in_ConstructorFieldInitializ
er() { |
| 4743 ParserTestCase.parseCompilationUnit("class C { C() : a = f(() {}); }"); | 4362 ParserTestCase.parseCompilationUnit("class C { C() : a = f(() {}); }"); |
| 4744 } | 4363 } |
| 4745 | 4364 |
| 4746 void test_function_literal_allowed_in_IndexExpression_in_ConstructorFieldIniti
alizer() { | 4365 void |
| 4366 test_function_literal_allowed_in_IndexExpression_in_ConstructorFieldInitia
lizer() { |
| 4747 ParserTestCase.parseCompilationUnit("class C { C() : a = x[() {}]; }"); | 4367 ParserTestCase.parseCompilationUnit("class C { C() : a = x[() {}]; }"); |
| 4748 } | 4368 } |
| 4749 | 4369 |
| 4750 void test_function_literal_allowed_in_ListLiteral_in_ConstructorFieldInitializ
er() { | 4370 void |
| 4371 test_function_literal_allowed_in_ListLiteral_in_ConstructorFieldInitialize
r() { |
| 4751 ParserTestCase.parseCompilationUnit("class C { C() : a = [() {}]; }"); | 4372 ParserTestCase.parseCompilationUnit("class C { C() : a = [() {}]; }"); |
| 4752 } | 4373 } |
| 4753 | 4374 |
| 4754 void test_function_literal_allowed_in_MapLiteral_in_ConstructorFieldInitialize
r() { | 4375 void |
| 4376 test_function_literal_allowed_in_MapLiteral_in_ConstructorFieldInitializer
() { |
| 4755 ParserTestCase | 4377 ParserTestCase |
| 4756 .parseCompilationUnit("class C { C() : a = {'key': () {}}; }"); | 4378 .parseCompilationUnit("class C { C() : a = {'key': () {}}; }"); |
| 4757 } | 4379 } |
| 4758 | 4380 |
| 4759 void test_function_literal_allowed_in_ParenthesizedExpression_in_ConstructorFi
eldInitializer() { | 4381 void |
| 4382 test_function_literal_allowed_in_ParenthesizedExpression_in_ConstructorFie
ldInitializer() { |
| 4760 ParserTestCase.parseCompilationUnit("class C { C() : a = (() {}); }"); | 4383 ParserTestCase.parseCompilationUnit("class C { C() : a = (() {}); }"); |
| 4761 } | 4384 } |
| 4762 | 4385 |
| 4763 void test_function_literal_allowed_in_StringInterpolation_in_ConstructorFieldI
nitializer() { | 4386 void |
| 4387 test_function_literal_allowed_in_StringInterpolation_in_ConstructorFieldIn
itializer() { |
| 4764 ParserTestCase.parseCompilationUnit("class C { C() : a = \"\${(){}}\"; }"); | 4388 ParserTestCase.parseCompilationUnit("class C { C() : a = \"\${(){}}\"; }"); |
| 4765 } | 4389 } |
| 4766 | 4390 |
| 4767 void test_import_as_show() { | 4391 void test_import_as_show() { |
| 4768 ParserTestCase.parseCompilationUnit("import 'dart:math' as M show E;"); | 4392 ParserTestCase.parseCompilationUnit("import 'dart:math' as M show E;"); |
| 4769 } | 4393 } |
| 4770 | 4394 |
| 4771 void test_import_show_hide() { | 4395 void test_import_show_hide() { |
| 4772 ParserTestCase.parseCompilationUnit( | 4396 ParserTestCase.parseCompilationUnit( |
| 4773 "import 'import1_lib.dart' show hide, show hide ugly;"); | 4397 "import 'import1_lib.dart' show hide, show hide ugly;"); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4969 | 4593 |
| 4970 void test_isSwitchMember_default_unlabeled() { | 4594 void test_isSwitchMember_default_unlabeled() { |
| 4971 expect(_isSwitchMember("default"), isTrue); | 4595 expect(_isSwitchMember("default"), isTrue); |
| 4972 } | 4596 } |
| 4973 | 4597 |
| 4974 void test_isSwitchMember_false() { | 4598 void test_isSwitchMember_false() { |
| 4975 expect(_isSwitchMember("break;"), isFalse); | 4599 expect(_isSwitchMember("break;"), isFalse); |
| 4976 } | 4600 } |
| 4977 | 4601 |
| 4978 void test_parseAdditiveExpression_normal() { | 4602 void test_parseAdditiveExpression_normal() { |
| 4979 BinaryExpression expression = parse4("parseAdditiveExpression", "x + y"); | 4603 createParser('x + y'); |
| 4980 expect(expression.leftOperand, isNotNull); | 4604 Expression expression = parser.parseAdditiveExpression(); |
| 4981 expect(expression.operator, isNotNull); | 4605 expectNotNullIfNoErrors(expression); |
| 4982 expect(expression.operator.type, TokenType.PLUS); | 4606 listener.assertNoErrors(); |
| 4983 expect(expression.rightOperand, isNotNull); | 4607 expect(expression, new isInstanceOf<BinaryExpression>()); |
| 4608 BinaryExpression binaryExpression = expression; |
| 4609 expect(binaryExpression.leftOperand, isNotNull); |
| 4610 expect(binaryExpression.operator, isNotNull); |
| 4611 expect(binaryExpression.operator.type, TokenType.PLUS); |
| 4612 expect(binaryExpression.rightOperand, isNotNull); |
| 4984 } | 4613 } |
| 4985 | 4614 |
| 4986 void test_parseAdditiveExpression_super() { | 4615 void test_parseAdditiveExpression_super() { |
| 4987 BinaryExpression expression = | 4616 createParser('super + y'); |
| 4988 parse4("parseAdditiveExpression", "super + y"); | 4617 Expression expression = parser.parseAdditiveExpression(); |
| 4989 EngineTestCase.assertInstanceOf((obj) => obj is SuperExpression, | 4618 expectNotNullIfNoErrors(expression); |
| 4990 SuperExpression, expression.leftOperand); | 4619 listener.assertNoErrors(); |
| 4991 expect(expression.operator, isNotNull); | 4620 expect(expression, new isInstanceOf<BinaryExpression>()); |
| 4992 expect(expression.operator.type, TokenType.PLUS); | 4621 BinaryExpression binaryExpression = expression; |
| 4993 expect(expression.rightOperand, isNotNull); | 4622 expect(binaryExpression.leftOperand, new isInstanceOf<SuperExpression>()); |
| 4623 expect(binaryExpression.operator, isNotNull); |
| 4624 expect(binaryExpression.operator.type, TokenType.PLUS); |
| 4625 expect(binaryExpression.rightOperand, isNotNull); |
| 4994 } | 4626 } |
| 4995 | 4627 |
| 4996 void test_parseAnnotation_n1() { | 4628 void test_parseAnnotation_n1() { |
| 4997 Annotation annotation = parse4("parseAnnotation", "@A"); | 4629 createParser('@A'); |
| 4630 Annotation annotation = parser.parseAnnotation(); |
| 4631 expectNotNullIfNoErrors(annotation); |
| 4632 listener.assertNoErrors(); |
| 4998 expect(annotation.atSign, isNotNull); | 4633 expect(annotation.atSign, isNotNull); |
| 4999 expect(annotation.name, isNotNull); | 4634 expect(annotation.name, isNotNull); |
| 5000 expect(annotation.period, isNull); | 4635 expect(annotation.period, isNull); |
| 5001 expect(annotation.constructorName, isNull); | 4636 expect(annotation.constructorName, isNull); |
| 5002 expect(annotation.arguments, isNull); | 4637 expect(annotation.arguments, isNull); |
| 5003 } | 4638 } |
| 5004 | 4639 |
| 5005 void test_parseAnnotation_n1_a() { | 4640 void test_parseAnnotation_n1_a() { |
| 5006 Annotation annotation = parse4("parseAnnotation", "@A(x,y)"); | 4641 createParser('@A(x,y)'); |
| 4642 Annotation annotation = parser.parseAnnotation(); |
| 4643 expectNotNullIfNoErrors(annotation); |
| 4644 listener.assertNoErrors(); |
| 5007 expect(annotation.atSign, isNotNull); | 4645 expect(annotation.atSign, isNotNull); |
| 5008 expect(annotation.name, isNotNull); | 4646 expect(annotation.name, isNotNull); |
| 5009 expect(annotation.period, isNull); | 4647 expect(annotation.period, isNull); |
| 5010 expect(annotation.constructorName, isNull); | 4648 expect(annotation.constructorName, isNull); |
| 5011 expect(annotation.arguments, isNotNull); | 4649 expect(annotation.arguments, isNotNull); |
| 5012 } | 4650 } |
| 5013 | 4651 |
| 5014 void test_parseAnnotation_n2() { | 4652 void test_parseAnnotation_n2() { |
| 5015 Annotation annotation = parse4("parseAnnotation", "@A.B"); | 4653 createParser('@A.B'); |
| 4654 Annotation annotation = parser.parseAnnotation(); |
| 4655 expectNotNullIfNoErrors(annotation); |
| 4656 listener.assertNoErrors(); |
| 5016 expect(annotation.atSign, isNotNull); | 4657 expect(annotation.atSign, isNotNull); |
| 5017 expect(annotation.name, isNotNull); | 4658 expect(annotation.name, isNotNull); |
| 5018 expect(annotation.period, isNull); | 4659 expect(annotation.period, isNull); |
| 5019 expect(annotation.constructorName, isNull); | 4660 expect(annotation.constructorName, isNull); |
| 5020 expect(annotation.arguments, isNull); | 4661 expect(annotation.arguments, isNull); |
| 5021 } | 4662 } |
| 5022 | 4663 |
| 5023 void test_parseAnnotation_n2_a() { | 4664 void test_parseAnnotation_n2_a() { |
| 5024 Annotation annotation = parse4("parseAnnotation", "@A.B(x,y)"); | 4665 createParser('@A.B(x,y)'); |
| 4666 Annotation annotation = parser.parseAnnotation(); |
| 4667 expectNotNullIfNoErrors(annotation); |
| 4668 listener.assertNoErrors(); |
| 5025 expect(annotation.atSign, isNotNull); | 4669 expect(annotation.atSign, isNotNull); |
| 5026 expect(annotation.name, isNotNull); | 4670 expect(annotation.name, isNotNull); |
| 5027 expect(annotation.period, isNull); | 4671 expect(annotation.period, isNull); |
| 5028 expect(annotation.constructorName, isNull); | 4672 expect(annotation.constructorName, isNull); |
| 5029 expect(annotation.arguments, isNotNull); | 4673 expect(annotation.arguments, isNotNull); |
| 5030 } | 4674 } |
| 5031 | 4675 |
| 5032 void test_parseAnnotation_n3() { | 4676 void test_parseAnnotation_n3() { |
| 5033 Annotation annotation = parse4("parseAnnotation", "@A.B.C"); | 4677 createParser('@A.B.C'); |
| 4678 Annotation annotation = parser.parseAnnotation(); |
| 4679 expectNotNullIfNoErrors(annotation); |
| 4680 listener.assertNoErrors(); |
| 5034 expect(annotation.atSign, isNotNull); | 4681 expect(annotation.atSign, isNotNull); |
| 5035 expect(annotation.name, isNotNull); | 4682 expect(annotation.name, isNotNull); |
| 5036 expect(annotation.period, isNotNull); | 4683 expect(annotation.period, isNotNull); |
| 5037 expect(annotation.constructorName, isNotNull); | 4684 expect(annotation.constructorName, isNotNull); |
| 5038 expect(annotation.arguments, isNull); | 4685 expect(annotation.arguments, isNull); |
| 5039 } | 4686 } |
| 5040 | 4687 |
| 5041 void test_parseAnnotation_n3_a() { | 4688 void test_parseAnnotation_n3_a() { |
| 5042 Annotation annotation = parse4("parseAnnotation", "@A.B.C(x,y)"); | 4689 createParser('@A.B.C(x,y)'); |
| 4690 Annotation annotation = parser.parseAnnotation(); |
| 4691 expectNotNullIfNoErrors(annotation); |
| 4692 listener.assertNoErrors(); |
| 5043 expect(annotation.atSign, isNotNull); | 4693 expect(annotation.atSign, isNotNull); |
| 5044 expect(annotation.name, isNotNull); | 4694 expect(annotation.name, isNotNull); |
| 5045 expect(annotation.period, isNotNull); | 4695 expect(annotation.period, isNotNull); |
| 5046 expect(annotation.constructorName, isNotNull); | 4696 expect(annotation.constructorName, isNotNull); |
| 5047 expect(annotation.arguments, isNotNull); | 4697 expect(annotation.arguments, isNotNull); |
| 5048 } | 4698 } |
| 5049 | 4699 |
| 5050 void test_parseArgument_named() { | 4700 void test_parseArgument_named() { |
| 5051 NamedExpression expression = parse4("parseArgument", "n: x"); | 4701 createParser('n: x'); |
| 5052 Label name = expression.name; | 4702 Expression expression = parser.parseArgument(); |
| 4703 expectNotNullIfNoErrors(expression); |
| 4704 listener.assertNoErrors(); |
| 4705 expect(expression, new isInstanceOf<NamedExpression>()); |
| 4706 NamedExpression namedExpression = expression; |
| 4707 Label name = namedExpression.name; |
| 5053 expect(name, isNotNull); | 4708 expect(name, isNotNull); |
| 5054 expect(name.label, isNotNull); | 4709 expect(name.label, isNotNull); |
| 5055 expect(name.colon, isNotNull); | 4710 expect(name.colon, isNotNull); |
| 5056 expect(expression.expression, isNotNull); | 4711 expect(namedExpression.expression, isNotNull); |
| 5057 } | 4712 } |
| 5058 | 4713 |
| 5059 void test_parseArgument_unnamed() { | 4714 void test_parseArgument_unnamed() { |
| 5060 String lexeme = "x"; | 4715 String lexeme = "x"; |
| 5061 SimpleIdentifier identifier = parse4("parseArgument", lexeme); | 4716 createParser(lexeme); |
| 4717 Expression expression = parser.parseArgument(); |
| 4718 expectNotNullIfNoErrors(expression); |
| 4719 listener.assertNoErrors(); |
| 4720 expect(expression, new isInstanceOf<SimpleIdentifier>()); |
| 4721 SimpleIdentifier identifier = expression; |
| 5062 expect(identifier.name, lexeme); | 4722 expect(identifier.name, lexeme); |
| 5063 } | 4723 } |
| 5064 | 4724 |
| 5065 void test_parseArgumentList_empty() { | 4725 void test_parseArgumentList_empty() { |
| 5066 ArgumentList argumentList = parse4("parseArgumentList", "()"); | 4726 createParser('()'); |
| 4727 ArgumentList argumentList = parser.parseArgumentList(); |
| 4728 expectNotNullIfNoErrors(argumentList); |
| 4729 listener.assertNoErrors(); |
| 5067 NodeList<Expression> arguments = argumentList.arguments; | 4730 NodeList<Expression> arguments = argumentList.arguments; |
| 5068 expect(arguments, hasLength(0)); | 4731 expect(arguments, hasLength(0)); |
| 5069 } | 4732 } |
| 5070 | 4733 |
| 5071 void test_parseArgumentList_mixed() { | 4734 void test_parseArgumentList_mixed() { |
| 5072 ArgumentList argumentList = | 4735 createParser('(w, x, y: y, z: z)'); |
| 5073 parse4("parseArgumentList", "(w, x, y: y, z: z)"); | 4736 ArgumentList argumentList = parser.parseArgumentList(); |
| 4737 expectNotNullIfNoErrors(argumentList); |
| 4738 listener.assertNoErrors(); |
| 5074 NodeList<Expression> arguments = argumentList.arguments; | 4739 NodeList<Expression> arguments = argumentList.arguments; |
| 5075 expect(arguments, hasLength(4)); | 4740 expect(arguments, hasLength(4)); |
| 5076 } | 4741 } |
| 5077 | 4742 |
| 5078 void test_parseArgumentList_noNamed() { | 4743 void test_parseArgumentList_noNamed() { |
| 5079 ArgumentList argumentList = parse4("parseArgumentList", "(x, y, z)"); | 4744 createParser('(x, y, z)'); |
| 4745 ArgumentList argumentList = parser.parseArgumentList(); |
| 4746 expectNotNullIfNoErrors(argumentList); |
| 4747 listener.assertNoErrors(); |
| 5080 NodeList<Expression> arguments = argumentList.arguments; | 4748 NodeList<Expression> arguments = argumentList.arguments; |
| 5081 expect(arguments, hasLength(3)); | 4749 expect(arguments, hasLength(3)); |
| 5082 } | 4750 } |
| 5083 | 4751 |
| 5084 void test_parseArgumentList_onlyNamed() { | 4752 void test_parseArgumentList_onlyNamed() { |
| 5085 ArgumentList argumentList = parse4("parseArgumentList", "(x: x, y: y)"); | 4753 createParser('(x: x, y: y)'); |
| 4754 ArgumentList argumentList = parser.parseArgumentList(); |
| 4755 expectNotNullIfNoErrors(argumentList); |
| 4756 listener.assertNoErrors(); |
| 5086 NodeList<Expression> arguments = argumentList.arguments; | 4757 NodeList<Expression> arguments = argumentList.arguments; |
| 5087 expect(arguments, hasLength(2)); | 4758 expect(arguments, hasLength(2)); |
| 5088 } | 4759 } |
| 5089 | 4760 |
| 4761 void test_parseArgumentList_trailing_comma() { |
| 4762 createParser('(x, y, z,)'); |
| 4763 ArgumentList argumentList = parser.parseArgumentList(); |
| 4764 expectNotNullIfNoErrors(argumentList); |
| 4765 listener.assertNoErrors(); |
| 4766 NodeList<Expression> arguments = argumentList.arguments; |
| 4767 expect(arguments, hasLength(3)); |
| 4768 } |
| 4769 |
| 5090 void test_parseAssertStatement() { | 4770 void test_parseAssertStatement() { |
| 5091 AssertStatement statement = parse4("parseAssertStatement", "assert (x);"); | 4771 createParser('assert (x);'); |
| 4772 AssertStatement statement = parser.parseAssertStatement(); |
| 4773 expectNotNullIfNoErrors(statement); |
| 4774 listener.assertNoErrors(); |
| 5092 expect(statement.assertKeyword, isNotNull); | 4775 expect(statement.assertKeyword, isNotNull); |
| 5093 expect(statement.leftParenthesis, isNotNull); | 4776 expect(statement.leftParenthesis, isNotNull); |
| 5094 expect(statement.condition, isNotNull); | 4777 expect(statement.condition, isNotNull); |
| 4778 expect(statement.comma, isNull); |
| 4779 expect(statement.message, isNull); |
| 4780 expect(statement.rightParenthesis, isNotNull); |
| 4781 expect(statement.semicolon, isNotNull); |
| 4782 } |
| 4783 |
| 4784 void test_parseAssertStatement_messageLowPrecedence() { |
| 4785 // Using a throw expression as an assert message would be silly in |
| 4786 // practice, but it's the lowest precedence expression type, so verifying |
| 4787 // that it works should give us high confidence that other expression types |
| 4788 // will work as well. |
| 4789 createParser('assert (x, throw "foo");'); |
| 4790 AssertStatement statement = parser.parseAssertStatement(); |
| 4791 expectNotNullIfNoErrors(statement); |
| 4792 listener.assertNoErrors(); |
| 4793 expect(statement.assertKeyword, isNotNull); |
| 4794 expect(statement.leftParenthesis, isNotNull); |
| 4795 expect(statement.condition, isNotNull); |
| 4796 expect(statement.comma, isNotNull); |
| 4797 expect(statement.message, isNotNull); |
| 4798 expect(statement.rightParenthesis, isNotNull); |
| 4799 expect(statement.semicolon, isNotNull); |
| 4800 } |
| 4801 |
| 4802 void test_parseAssertStatement_messageString() { |
| 4803 createParser('assert (x, "foo");'); |
| 4804 AssertStatement statement = parser.parseAssertStatement(); |
| 4805 expectNotNullIfNoErrors(statement); |
| 4806 listener.assertNoErrors(); |
| 4807 expect(statement.assertKeyword, isNotNull); |
| 4808 expect(statement.leftParenthesis, isNotNull); |
| 4809 expect(statement.condition, isNotNull); |
| 4810 expect(statement.comma, isNotNull); |
| 4811 expect(statement.message, isNotNull); |
| 5095 expect(statement.rightParenthesis, isNotNull); | 4812 expect(statement.rightParenthesis, isNotNull); |
| 5096 expect(statement.semicolon, isNotNull); | 4813 expect(statement.semicolon, isNotNull); |
| 5097 } | 4814 } |
| 5098 | 4815 |
| 5099 void test_parseAssignableExpression_expression_args_dot() { | 4816 void test_parseAssignableExpression_expression_args_dot() { |
| 5100 PropertyAccess propertyAccess = | 4817 createParser('(x)(y).z'); |
| 5101 parse("parseAssignableExpression", <Object>[false], "(x)(y).z"); | 4818 Expression expression = parser.parseAssignableExpression(false); |
| 4819 expectNotNullIfNoErrors(expression); |
| 4820 listener.assertNoErrors(); |
| 4821 expect(expression, new isInstanceOf<PropertyAccess>()); |
| 4822 PropertyAccess propertyAccess = expression; |
| 5102 FunctionExpressionInvocation invocation = | 4823 FunctionExpressionInvocation invocation = |
| 5103 propertyAccess.target as FunctionExpressionInvocation; | 4824 propertyAccess.target as FunctionExpressionInvocation; |
| 5104 expect(invocation.function, isNotNull); | 4825 expect(invocation.function, isNotNull); |
| 5105 expect(invocation.typeArguments, isNull); | 4826 expect(invocation.typeArguments, isNull); |
| 5106 ArgumentList argumentList = invocation.argumentList; | 4827 ArgumentList argumentList = invocation.argumentList; |
| 5107 expect(argumentList, isNotNull); | 4828 expect(argumentList, isNotNull); |
| 5108 expect(argumentList.arguments, hasLength(1)); | 4829 expect(argumentList.arguments, hasLength(1)); |
| 5109 expect(propertyAccess.operator, isNotNull); | 4830 expect(propertyAccess.operator, isNotNull); |
| 5110 expect(propertyAccess.propertyName, isNotNull); | 4831 expect(propertyAccess.propertyName, isNotNull); |
| 5111 } | 4832 } |
| 5112 | 4833 |
| 4834 void |
| 4835 test_parseAssignableExpression_expression_args_dot_typeParameterComments()
{ |
| 4836 enableGenericMethodComments = true; |
| 4837 createParser('(x)/*<F>*/(y).z'); |
| 4838 Expression expression = parser.parseAssignableExpression(false); |
| 4839 expectNotNullIfNoErrors(expression); |
| 4840 listener.assertNoErrors(); |
| 4841 expect(expression, new isInstanceOf<PropertyAccess>()); |
| 4842 PropertyAccess propertyAccess = expression; |
| 4843 FunctionExpressionInvocation invocation = |
| 4844 propertyAccess.target as FunctionExpressionInvocation; |
| 4845 expect(invocation.function, isNotNull); |
| 4846 expect(invocation.typeArguments, isNotNull); |
| 4847 ArgumentList argumentList = invocation.argumentList; |
| 4848 expect(argumentList, isNotNull); |
| 4849 expect(argumentList.arguments, hasLength(1)); |
| 4850 expect(propertyAccess.operator, isNotNull); |
| 4851 expect(propertyAccess.propertyName, isNotNull); |
| 4852 } |
| 4853 |
| 5113 void test_parseAssignableExpression_expression_args_dot_typeParameters() { | 4854 void test_parseAssignableExpression_expression_args_dot_typeParameters() { |
| 5114 enableGenericMethods = true; | 4855 enableGenericMethods = true; |
| 5115 PropertyAccess propertyAccess = | 4856 createParser('(x)<F>(y).z'); |
| 5116 parse("parseAssignableExpression", <Object>[false], "(x)<F>(y).z"); | 4857 Expression expression = parser.parseAssignableExpression(false); |
| 4858 expectNotNullIfNoErrors(expression); |
| 4859 listener.assertNoErrors(); |
| 4860 expect(expression, new isInstanceOf<PropertyAccess>()); |
| 4861 PropertyAccess propertyAccess = expression; |
| 5117 FunctionExpressionInvocation invocation = | 4862 FunctionExpressionInvocation invocation = |
| 5118 propertyAccess.target as FunctionExpressionInvocation; | 4863 propertyAccess.target as FunctionExpressionInvocation; |
| 5119 expect(invocation.function, isNotNull); | 4864 expect(invocation.function, isNotNull); |
| 5120 expect(invocation.typeArguments, isNotNull); | 4865 expect(invocation.typeArguments, isNotNull); |
| 5121 ArgumentList argumentList = invocation.argumentList; | 4866 ArgumentList argumentList = invocation.argumentList; |
| 5122 expect(argumentList, isNotNull); | 4867 expect(argumentList, isNotNull); |
| 5123 expect(argumentList.arguments, hasLength(1)); | 4868 expect(argumentList.arguments, hasLength(1)); |
| 5124 expect(propertyAccess.operator, isNotNull); | 4869 expect(propertyAccess.operator, isNotNull); |
| 5125 expect(propertyAccess.propertyName, isNotNull); | 4870 expect(propertyAccess.propertyName, isNotNull); |
| 5126 } | 4871 } |
| 5127 | 4872 |
| 5128 void test_parseAssignableExpression_expression_dot() { | 4873 void test_parseAssignableExpression_expression_dot() { |
| 5129 PropertyAccess propertyAccess = | 4874 createParser('(x).y'); |
| 5130 parse("parseAssignableExpression", <Object>[false], "(x).y"); | 4875 Expression expression = parser.parseAssignableExpression(false); |
| 4876 expectNotNullIfNoErrors(expression); |
| 4877 listener.assertNoErrors(); |
| 4878 expect(expression, new isInstanceOf<PropertyAccess>()); |
| 4879 PropertyAccess propertyAccess = expression; |
| 5131 expect(propertyAccess.target, isNotNull); | 4880 expect(propertyAccess.target, isNotNull); |
| 5132 expect(propertyAccess.operator.type, TokenType.PERIOD); | 4881 expect(propertyAccess.operator.type, TokenType.PERIOD); |
| 5133 expect(propertyAccess.propertyName, isNotNull); | 4882 expect(propertyAccess.propertyName, isNotNull); |
| 5134 } | 4883 } |
| 5135 | 4884 |
| 5136 void test_parseAssignableExpression_expression_index() { | 4885 void test_parseAssignableExpression_expression_index() { |
| 5137 IndexExpression expression = | 4886 createParser('(x)[y]'); |
| 5138 parse("parseAssignableExpression", <Object>[false], "(x)[y]"); | 4887 Expression expression = parser.parseAssignableExpression(false); |
| 5139 expect(expression.target, isNotNull); | 4888 expectNotNullIfNoErrors(expression); |
| 5140 expect(expression.leftBracket, isNotNull); | 4889 listener.assertNoErrors(); |
| 5141 expect(expression.index, isNotNull); | 4890 expect(expression, new isInstanceOf<IndexExpression>()); |
| 5142 expect(expression.rightBracket, isNotNull); | 4891 IndexExpression indexExpression = expression; |
| 4892 expect(indexExpression.target, isNotNull); |
| 4893 expect(indexExpression.leftBracket, isNotNull); |
| 4894 expect(indexExpression.index, isNotNull); |
| 4895 expect(indexExpression.rightBracket, isNotNull); |
| 5143 } | 4896 } |
| 5144 | 4897 |
| 5145 void test_parseAssignableExpression_expression_question_dot() { | 4898 void test_parseAssignableExpression_expression_question_dot() { |
| 5146 PropertyAccess propertyAccess = | 4899 createParser('(x)?.y'); |
| 5147 parse("parseAssignableExpression", <Object>[false], "(x)?.y"); | 4900 Expression expression = parser.parseAssignableExpression(false); |
| 4901 expectNotNullIfNoErrors(expression); |
| 4902 listener.assertNoErrors(); |
| 4903 expect(expression, new isInstanceOf<PropertyAccess>()); |
| 4904 PropertyAccess propertyAccess = expression; |
| 5148 expect(propertyAccess.target, isNotNull); | 4905 expect(propertyAccess.target, isNotNull); |
| 5149 expect(propertyAccess.operator.type, TokenType.QUESTION_PERIOD); | 4906 expect(propertyAccess.operator.type, TokenType.QUESTION_PERIOD); |
| 5150 expect(propertyAccess.propertyName, isNotNull); | 4907 expect(propertyAccess.propertyName, isNotNull); |
| 5151 } | 4908 } |
| 5152 | 4909 |
| 5153 void test_parseAssignableExpression_identifier() { | 4910 void test_parseAssignableExpression_identifier() { |
| 5154 SimpleIdentifier identifier = | 4911 createParser('x'); |
| 5155 parse("parseAssignableExpression", <Object>[false], "x"); | 4912 Expression expression = parser.parseAssignableExpression(false); |
| 4913 expectNotNullIfNoErrors(expression); |
| 4914 listener.assertNoErrors(); |
| 4915 expect(expression, new isInstanceOf<SimpleIdentifier>()); |
| 4916 SimpleIdentifier identifier = expression; |
| 5156 expect(identifier, isNotNull); | 4917 expect(identifier, isNotNull); |
| 5157 } | 4918 } |
| 5158 | 4919 |
| 5159 void test_parseAssignableExpression_identifier_args_dot() { | 4920 void test_parseAssignableExpression_identifier_args_dot() { |
| 5160 PropertyAccess propertyAccess = | 4921 createParser('x(y).z'); |
| 5161 parse("parseAssignableExpression", <Object>[false], "x(y).z"); | 4922 Expression expression = parser.parseAssignableExpression(false); |
| 4923 expectNotNullIfNoErrors(expression); |
| 4924 listener.assertNoErrors(); |
| 4925 expect(expression, new isInstanceOf<PropertyAccess>()); |
| 4926 PropertyAccess propertyAccess = expression; |
| 5162 MethodInvocation invocation = propertyAccess.target as MethodInvocation; | 4927 MethodInvocation invocation = propertyAccess.target as MethodInvocation; |
| 5163 expect(invocation.methodName.name, "x"); | 4928 expect(invocation.methodName.name, "x"); |
| 5164 expect(invocation.typeArguments, isNull); | 4929 expect(invocation.typeArguments, isNull); |
| 5165 ArgumentList argumentList = invocation.argumentList; | 4930 ArgumentList argumentList = invocation.argumentList; |
| 5166 expect(argumentList, isNotNull); | 4931 expect(argumentList, isNotNull); |
| 5167 expect(argumentList.arguments, hasLength(1)); | 4932 expect(argumentList.arguments, hasLength(1)); |
| 5168 expect(propertyAccess.operator, isNotNull); | 4933 expect(propertyAccess.operator, isNotNull); |
| 5169 expect(propertyAccess.propertyName, isNotNull); | 4934 expect(propertyAccess.propertyName, isNotNull); |
| 5170 } | 4935 } |
| 5171 | 4936 |
| 4937 void |
| 4938 test_parseAssignableExpression_identifier_args_dot_typeParameterComments()
{ |
| 4939 enableGenericMethodComments = true; |
| 4940 createParser('x/*<E>*/(y).z'); |
| 4941 Expression expression = parser.parseAssignableExpression(false); |
| 4942 expectNotNullIfNoErrors(expression); |
| 4943 listener.assertNoErrors(); |
| 4944 expect(expression, new isInstanceOf<PropertyAccess>()); |
| 4945 PropertyAccess propertyAccess = expression; |
| 4946 MethodInvocation invocation = propertyAccess.target as MethodInvocation; |
| 4947 expect(invocation.methodName.name, "x"); |
| 4948 expect(invocation.typeArguments, isNotNull); |
| 4949 ArgumentList argumentList = invocation.argumentList; |
| 4950 expect(argumentList, isNotNull); |
| 4951 expect(argumentList.arguments, hasLength(1)); |
| 4952 expect(propertyAccess.operator, isNotNull); |
| 4953 expect(propertyAccess.propertyName, isNotNull); |
| 4954 } |
| 4955 |
| 5172 void test_parseAssignableExpression_identifier_args_dot_typeParameters() { | 4956 void test_parseAssignableExpression_identifier_args_dot_typeParameters() { |
| 5173 enableGenericMethods = true; | 4957 enableGenericMethods = true; |
| 5174 PropertyAccess propertyAccess = | 4958 createParser('x<E>(y).z'); |
| 5175 parse("parseAssignableExpression", <Object>[false], "x<E>(y).z"); | 4959 Expression expression = parser.parseAssignableExpression(false); |
| 4960 expectNotNullIfNoErrors(expression); |
| 4961 listener.assertNoErrors(); |
| 4962 expect(expression, new isInstanceOf<PropertyAccess>()); |
| 4963 PropertyAccess propertyAccess = expression; |
| 5176 MethodInvocation invocation = propertyAccess.target as MethodInvocation; | 4964 MethodInvocation invocation = propertyAccess.target as MethodInvocation; |
| 5177 expect(invocation.methodName.name, "x"); | 4965 expect(invocation.methodName.name, "x"); |
| 5178 expect(invocation.typeArguments, isNotNull); | 4966 expect(invocation.typeArguments, isNotNull); |
| 5179 ArgumentList argumentList = invocation.argumentList; | 4967 ArgumentList argumentList = invocation.argumentList; |
| 5180 expect(argumentList, isNotNull); | 4968 expect(argumentList, isNotNull); |
| 5181 expect(argumentList.arguments, hasLength(1)); | 4969 expect(argumentList.arguments, hasLength(1)); |
| 5182 expect(propertyAccess.operator, isNotNull); | 4970 expect(propertyAccess.operator, isNotNull); |
| 5183 expect(propertyAccess.propertyName, isNotNull); | 4971 expect(propertyAccess.propertyName, isNotNull); |
| 5184 } | 4972 } |
| 5185 | 4973 |
| 5186 void test_parseAssignableExpression_identifier_dot() { | 4974 void test_parseAssignableExpression_identifier_dot() { |
| 5187 PropertyAccess propertyAccess = | 4975 createParser('x.y'); |
| 5188 parse("parseAssignableExpression", <Object>[false], "x.y"); | 4976 Expression expression = parser.parseAssignableExpression(false); |
| 4977 expectNotNullIfNoErrors(expression); |
| 4978 listener.assertNoErrors(); |
| 4979 expect(expression, new isInstanceOf<PropertyAccess>()); |
| 4980 PropertyAccess propertyAccess = expression; |
| 5189 expect(propertyAccess.target, isNotNull); | 4981 expect(propertyAccess.target, isNotNull); |
| 5190 expect(propertyAccess.operator, isNotNull); | 4982 expect(propertyAccess.operator, isNotNull); |
| 5191 expect(propertyAccess.operator.type, TokenType.PERIOD); | 4983 expect(propertyAccess.operator.type, TokenType.PERIOD); |
| 5192 expect(propertyAccess.propertyName, isNotNull); | 4984 expect(propertyAccess.propertyName, isNotNull); |
| 5193 } | 4985 } |
| 5194 | 4986 |
| 5195 void test_parseAssignableExpression_identifier_index() { | 4987 void test_parseAssignableExpression_identifier_index() { |
| 5196 IndexExpression expression = | 4988 createParser('x[y]'); |
| 5197 parse("parseAssignableExpression", <Object>[false], "x[y]"); | 4989 Expression expression = parser.parseAssignableExpression(false); |
| 5198 expect(expression.target, isNotNull); | 4990 expectNotNullIfNoErrors(expression); |
| 5199 expect(expression.leftBracket, isNotNull); | 4991 listener.assertNoErrors(); |
| 5200 expect(expression.index, isNotNull); | 4992 expect(expression, new isInstanceOf<IndexExpression>()); |
| 5201 expect(expression.rightBracket, isNotNull); | 4993 IndexExpression indexExpression = expression; |
| 4994 expect(indexExpression.target, isNotNull); |
| 4995 expect(indexExpression.leftBracket, isNotNull); |
| 4996 expect(indexExpression.index, isNotNull); |
| 4997 expect(indexExpression.rightBracket, isNotNull); |
| 5202 } | 4998 } |
| 5203 | 4999 |
| 5204 void test_parseAssignableExpression_identifier_question_dot() { | 5000 void test_parseAssignableExpression_identifier_question_dot() { |
| 5205 PropertyAccess propertyAccess = | 5001 createParser('x?.y'); |
| 5206 parse("parseAssignableExpression", <Object>[false], "x?.y"); | 5002 Expression expression = parser.parseAssignableExpression(false); |
| 5003 expectNotNullIfNoErrors(expression); |
| 5004 listener.assertNoErrors(); |
| 5005 expect(expression, new isInstanceOf<PropertyAccess>()); |
| 5006 PropertyAccess propertyAccess = expression; |
| 5207 expect(propertyAccess.target, isNotNull); | 5007 expect(propertyAccess.target, isNotNull); |
| 5208 expect(propertyAccess.operator.type, TokenType.QUESTION_PERIOD); | 5008 expect(propertyAccess.operator.type, TokenType.QUESTION_PERIOD); |
| 5209 expect(propertyAccess.propertyName, isNotNull); | 5009 expect(propertyAccess.propertyName, isNotNull); |
| 5210 } | 5010 } |
| 5211 | 5011 |
| 5212 void test_parseAssignableExpression_super_dot() { | 5012 void test_parseAssignableExpression_super_dot() { |
| 5213 PropertyAccess propertyAccess = | 5013 createParser('super.y'); |
| 5214 parse("parseAssignableExpression", <Object>[false], "super.y"); | 5014 Expression expression = parser.parseAssignableExpression(false); |
| 5015 expectNotNullIfNoErrors(expression); |
| 5016 listener.assertNoErrors(); |
| 5017 expect(expression, new isInstanceOf<PropertyAccess>()); |
| 5018 PropertyAccess propertyAccess = expression; |
| 5215 EngineTestCase.assertInstanceOf((obj) => obj is SuperExpression, | 5019 EngineTestCase.assertInstanceOf((obj) => obj is SuperExpression, |
| 5216 SuperExpression, propertyAccess.target); | 5020 SuperExpression, propertyAccess.target); |
| 5217 expect(propertyAccess.operator, isNotNull); | 5021 expect(propertyAccess.operator, isNotNull); |
| 5218 expect(propertyAccess.propertyName, isNotNull); | 5022 expect(propertyAccess.propertyName, isNotNull); |
| 5219 } | 5023 } |
| 5220 | 5024 |
| 5221 void test_parseAssignableExpression_super_index() { | 5025 void test_parseAssignableExpression_super_index() { |
| 5222 IndexExpression expression = | 5026 createParser('super[y]'); |
| 5223 parse("parseAssignableExpression", <Object>[false], "super[y]"); | 5027 Expression expression = parser.parseAssignableExpression(false); |
| 5224 EngineTestCase.assertInstanceOf( | 5028 expectNotNullIfNoErrors(expression); |
| 5225 (obj) => obj is SuperExpression, SuperExpression, expression.target); | 5029 listener.assertNoErrors(); |
| 5226 expect(expression.leftBracket, isNotNull); | 5030 expect(expression, new isInstanceOf<IndexExpression>()); |
| 5227 expect(expression.index, isNotNull); | 5031 IndexExpression indexExpression = expression; |
| 5228 expect(expression.rightBracket, isNotNull); | 5032 expect(indexExpression.target, new isInstanceOf<SuperExpression>()); |
| 5033 expect(indexExpression.leftBracket, isNotNull); |
| 5034 expect(indexExpression.index, isNotNull); |
| 5035 expect(indexExpression.rightBracket, isNotNull); |
| 5229 } | 5036 } |
| 5230 | 5037 |
| 5231 void test_parseAssignableSelector_dot() { | 5038 void test_parseAssignableSelector_dot() { |
| 5232 PropertyAccess selector = | 5039 createParser('.x'); |
| 5233 parse("parseAssignableSelector", <Object>[null, true], ".x"); | 5040 Expression expression = parser.parseAssignableSelector(null, true); |
| 5234 expect(selector.operator.type, TokenType.PERIOD); | 5041 expectNotNullIfNoErrors(expression); |
| 5235 expect(selector.propertyName, isNotNull); | 5042 listener.assertNoErrors(); |
| 5043 expect(expression, new isInstanceOf<PropertyAccess>()); |
| 5044 PropertyAccess propertyAccess = expression; |
| 5045 expect(propertyAccess.operator.type, TokenType.PERIOD); |
| 5046 expect(propertyAccess.propertyName, isNotNull); |
| 5236 } | 5047 } |
| 5237 | 5048 |
| 5238 void test_parseAssignableSelector_index() { | 5049 void test_parseAssignableSelector_index() { |
| 5239 IndexExpression selector = | 5050 createParser('[x]'); |
| 5240 parse("parseAssignableSelector", <Object>[null, true], "[x]"); | 5051 Expression expression = parser.parseAssignableSelector(null, true); |
| 5241 expect(selector.leftBracket, isNotNull); | 5052 expectNotNullIfNoErrors(expression); |
| 5242 expect(selector.index, isNotNull); | 5053 listener.assertNoErrors(); |
| 5243 expect(selector.rightBracket, isNotNull); | 5054 expect(expression, new isInstanceOf<IndexExpression>()); |
| 5055 IndexExpression indexExpression = expression; |
| 5056 expect(indexExpression.leftBracket, isNotNull); |
| 5057 expect(indexExpression.index, isNotNull); |
| 5058 expect(indexExpression.rightBracket, isNotNull); |
| 5244 } | 5059 } |
| 5245 | 5060 |
| 5246 void test_parseAssignableSelector_none() { | 5061 void test_parseAssignableSelector_none() { |
| 5247 SimpleIdentifier selector = parse("parseAssignableSelector", | 5062 createParser(';'); |
| 5248 <Object>[new SimpleIdentifier(null), true], ";"); | 5063 Expression expression = |
| 5249 expect(selector, isNotNull); | 5064 parser.parseAssignableSelector(new SimpleIdentifier(null), true); |
| 5065 expectNotNullIfNoErrors(expression); |
| 5066 listener.assertNoErrors(); |
| 5067 expect(expression, new isInstanceOf<SimpleIdentifier>()); |
| 5068 SimpleIdentifier identifier = expression; |
| 5069 expect(identifier, isNotNull); |
| 5250 } | 5070 } |
| 5251 | 5071 |
| 5252 void test_parseAssignableSelector_question_dot() { | 5072 void test_parseAssignableSelector_question_dot() { |
| 5253 PropertyAccess selector = | 5073 createParser('?.x'); |
| 5254 parse("parseAssignableSelector", <Object>[null, true], "?.x"); | 5074 Expression expression = parser.parseAssignableSelector(null, true); |
| 5255 expect(selector.operator.type, TokenType.QUESTION_PERIOD); | 5075 expectNotNullIfNoErrors(expression); |
| 5256 expect(selector.propertyName, isNotNull); | 5076 listener.assertNoErrors(); |
| 5077 expect(expression, new isInstanceOf<PropertyAccess>()); |
| 5078 PropertyAccess propertyAccess = expression; |
| 5079 expect(propertyAccess.operator.type, TokenType.QUESTION_PERIOD); |
| 5080 expect(propertyAccess.propertyName, isNotNull); |
| 5257 } | 5081 } |
| 5258 | 5082 |
| 5259 void test_parseAwaitExpression() { | 5083 void test_parseAwaitExpression() { |
| 5260 AwaitExpression expression = parse4("parseAwaitExpression", "await x;"); | 5084 createParser('await x;'); |
| 5085 AwaitExpression expression = parser.parseAwaitExpression(); |
| 5086 expectNotNullIfNoErrors(expression); |
| 5087 listener.assertNoErrors(); |
| 5261 expect(expression.awaitKeyword, isNotNull); | 5088 expect(expression.awaitKeyword, isNotNull); |
| 5262 expect(expression.expression, isNotNull); | 5089 expect(expression.expression, isNotNull); |
| 5263 } | 5090 } |
| 5264 | 5091 |
| 5265 void test_parseAwaitExpression_asStatement_inAsync() { | 5092 void test_parseAwaitExpression_asStatement_inAsync() { |
| 5266 MethodDeclaration method = | 5093 createParser('m() async { await x; }'); |
| 5267 parse("parseClassMember", <Object>["C"], "m() async { await x; }"); | 5094 ClassMember member = parser.parseClassMember('C'); |
| 5095 expectNotNullIfNoErrors(member); |
| 5096 listener.assertNoErrors(); |
| 5097 expect(member, new isInstanceOf<MethodDeclaration>()); |
| 5098 MethodDeclaration method = member; |
| 5268 FunctionBody body = method.body; | 5099 FunctionBody body = method.body; |
| 5269 EngineTestCase.assertInstanceOf( | 5100 EngineTestCase.assertInstanceOf( |
| 5270 (obj) => obj is BlockFunctionBody, BlockFunctionBody, body); | 5101 (obj) => obj is BlockFunctionBody, BlockFunctionBody, body); |
| 5271 Statement statement = (body as BlockFunctionBody).block.statements[0]; | 5102 Statement statement = (body as BlockFunctionBody).block.statements[0]; |
| 5272 EngineTestCase.assertInstanceOf( | 5103 EngineTestCase.assertInstanceOf( |
| 5273 (obj) => obj is ExpressionStatement, ExpressionStatement, statement); | 5104 (obj) => obj is ExpressionStatement, ExpressionStatement, statement); |
| 5274 Expression expression = (statement as ExpressionStatement).expression; | 5105 Expression expression = (statement as ExpressionStatement).expression; |
| 5275 EngineTestCase.assertInstanceOf( | 5106 EngineTestCase.assertInstanceOf( |
| 5276 (obj) => obj is AwaitExpression, AwaitExpression, expression); | 5107 (obj) => obj is AwaitExpression, AwaitExpression, expression); |
| 5277 expect((expression as AwaitExpression).awaitKeyword, isNotNull); | 5108 expect((expression as AwaitExpression).awaitKeyword, isNotNull); |
| 5278 expect((expression as AwaitExpression).expression, isNotNull); | 5109 expect((expression as AwaitExpression).expression, isNotNull); |
| 5279 } | 5110 } |
| 5280 | 5111 |
| 5281 void test_parseAwaitExpression_asStatement_inSync() { | 5112 void test_parseAwaitExpression_asStatement_inSync() { |
| 5282 MethodDeclaration method = | 5113 createParser('m() { await x; }'); |
| 5283 parse("parseClassMember", <Object>["C"], "m() { await x; }"); | 5114 ClassMember member = parser.parseClassMember('C'); |
| 5115 expectNotNullIfNoErrors(member); |
| 5116 listener.assertNoErrors(); |
| 5117 expect(member, new isInstanceOf<MethodDeclaration>()); |
| 5118 MethodDeclaration method = member; |
| 5284 FunctionBody body = method.body; | 5119 FunctionBody body = method.body; |
| 5285 EngineTestCase.assertInstanceOf( | 5120 EngineTestCase.assertInstanceOf( |
| 5286 (obj) => obj is BlockFunctionBody, BlockFunctionBody, body); | 5121 (obj) => obj is BlockFunctionBody, BlockFunctionBody, body); |
| 5287 Statement statement = (body as BlockFunctionBody).block.statements[0]; | 5122 Statement statement = (body as BlockFunctionBody).block.statements[0]; |
| 5288 EngineTestCase.assertInstanceOf( | 5123 EngineTestCase.assertInstanceOf( |
| 5289 (obj) => obj is VariableDeclarationStatement, | 5124 (obj) => obj is VariableDeclarationStatement, |
| 5290 VariableDeclarationStatement, | 5125 VariableDeclarationStatement, |
| 5291 statement); | 5126 statement); |
| 5292 } | 5127 } |
| 5293 | 5128 |
| 5129 @failingTest |
| 5130 void test_parseAwaitExpression_inSync() { |
| 5131 // This test requires better error recovery than we currently have. In |
| 5132 // particular, we need to be able to distinguish between an await expression |
| 5133 // in the wrong context, and the use of 'await' as an identifier. |
| 5134 createParser('m() { return await x + await y; }'); |
| 5135 MethodDeclaration method = parser.parseClassMember('C'); |
| 5136 expectNotNullIfNoErrors(method); |
| 5137 listener.assertNoErrors(); |
| 5138 FunctionBody body = method.body; |
| 5139 EngineTestCase.assertInstanceOf( |
| 5140 (obj) => obj is BlockFunctionBody, BlockFunctionBody, body); |
| 5141 Statement statement = (body as BlockFunctionBody).block.statements[0]; |
| 5142 EngineTestCase.assertInstanceOf( |
| 5143 (obj) => obj is ReturnStatement, ReturnStatement, statement); |
| 5144 Expression expression = (statement as ReturnStatement).expression; |
| 5145 EngineTestCase.assertInstanceOf( |
| 5146 (obj) => obj is BinaryExpression, BinaryExpression, expression); |
| 5147 EngineTestCase.assertInstanceOf((obj) => obj is AwaitExpression, |
| 5148 AwaitExpression, (expression as BinaryExpression).leftOperand); |
| 5149 EngineTestCase.assertInstanceOf((obj) => obj is AwaitExpression, |
| 5150 AwaitExpression, (expression as BinaryExpression).rightOperand); |
| 5151 } |
| 5152 |
| 5294 void test_parseBitwiseAndExpression_normal() { | 5153 void test_parseBitwiseAndExpression_normal() { |
| 5295 BinaryExpression expression = parse4("parseBitwiseAndExpression", "x & y"); | 5154 createParser('x & y'); |
| 5296 expect(expression.leftOperand, isNotNull); | 5155 Expression expression = parser.parseBitwiseAndExpression(); |
| 5297 expect(expression.operator, isNotNull); | 5156 expectNotNullIfNoErrors(expression); |
| 5298 expect(expression.operator.type, TokenType.AMPERSAND); | 5157 listener.assertNoErrors(); |
| 5299 expect(expression.rightOperand, isNotNull); | 5158 expect(expression, new isInstanceOf<BinaryExpression>()); |
| 5159 BinaryExpression binaryExpression = expression; |
| 5160 expect(binaryExpression.leftOperand, isNotNull); |
| 5161 expect(binaryExpression.operator, isNotNull); |
| 5162 expect(binaryExpression.operator.type, TokenType.AMPERSAND); |
| 5163 expect(binaryExpression.rightOperand, isNotNull); |
| 5300 } | 5164 } |
| 5301 | 5165 |
| 5302 void test_parseBitwiseAndExpression_super() { | 5166 void test_parseBitwiseAndExpression_super() { |
| 5303 BinaryExpression expression = | 5167 createParser('super & y'); |
| 5304 parse4("parseBitwiseAndExpression", "super & y"); | 5168 Expression expression = parser.parseBitwiseAndExpression(); |
| 5305 EngineTestCase.assertInstanceOf((obj) => obj is SuperExpression, | 5169 expectNotNullIfNoErrors(expression); |
| 5306 SuperExpression, expression.leftOperand); | 5170 listener.assertNoErrors(); |
| 5307 expect(expression.operator, isNotNull); | 5171 expect(expression, new isInstanceOf<BinaryExpression>()); |
| 5308 expect(expression.operator.type, TokenType.AMPERSAND); | 5172 BinaryExpression binaryExpression = expression; |
| 5309 expect(expression.rightOperand, isNotNull); | 5173 expect(binaryExpression.leftOperand, new isInstanceOf<SuperExpression>()); |
| 5174 expect(binaryExpression.operator, isNotNull); |
| 5175 expect(binaryExpression.operator.type, TokenType.AMPERSAND); |
| 5176 expect(binaryExpression.rightOperand, isNotNull); |
| 5310 } | 5177 } |
| 5311 | 5178 |
| 5312 void test_parseBitwiseOrExpression_normal() { | 5179 void test_parseBitwiseOrExpression_normal() { |
| 5313 BinaryExpression expression = parse4("parseBitwiseOrExpression", "x | y"); | 5180 createParser('x | y'); |
| 5314 expect(expression.leftOperand, isNotNull); | 5181 Expression expression = parser.parseBitwiseOrExpression(); |
| 5315 expect(expression.operator, isNotNull); | 5182 expectNotNullIfNoErrors(expression); |
| 5316 expect(expression.operator.type, TokenType.BAR); | 5183 listener.assertNoErrors(); |
| 5317 expect(expression.rightOperand, isNotNull); | 5184 expect(expression, new isInstanceOf<BinaryExpression>()); |
| 5185 BinaryExpression binaryExpression = expression; |
| 5186 expect(binaryExpression.leftOperand, isNotNull); |
| 5187 expect(binaryExpression.operator, isNotNull); |
| 5188 expect(binaryExpression.operator.type, TokenType.BAR); |
| 5189 expect(binaryExpression.rightOperand, isNotNull); |
| 5318 } | 5190 } |
| 5319 | 5191 |
| 5320 void test_parseBitwiseOrExpression_super() { | 5192 void test_parseBitwiseOrExpression_super() { |
| 5321 BinaryExpression expression = | 5193 createParser('super | y'); |
| 5322 parse4("parseBitwiseOrExpression", "super | y"); | 5194 Expression expression = parser.parseBitwiseOrExpression(); |
| 5323 EngineTestCase.assertInstanceOf((obj) => obj is SuperExpression, | 5195 expectNotNullIfNoErrors(expression); |
| 5324 SuperExpression, expression.leftOperand); | 5196 listener.assertNoErrors(); |
| 5325 expect(expression.operator, isNotNull); | 5197 expect(expression, new isInstanceOf<BinaryExpression>()); |
| 5326 expect(expression.operator.type, TokenType.BAR); | 5198 BinaryExpression binaryExpression = expression; |
| 5327 expect(expression.rightOperand, isNotNull); | 5199 expect(binaryExpression.leftOperand, new isInstanceOf<SuperExpression>()); |
| 5200 expect(binaryExpression.operator, isNotNull); |
| 5201 expect(binaryExpression.operator.type, TokenType.BAR); |
| 5202 expect(binaryExpression.rightOperand, isNotNull); |
| 5328 } | 5203 } |
| 5329 | 5204 |
| 5330 void test_parseBitwiseXorExpression_normal() { | 5205 void test_parseBitwiseXorExpression_normal() { |
| 5331 BinaryExpression expression = parse4("parseBitwiseXorExpression", "x ^ y"); | 5206 createParser('x ^ y'); |
| 5332 expect(expression.leftOperand, isNotNull); | 5207 Expression expression = parser.parseBitwiseXorExpression(); |
| 5333 expect(expression.operator, isNotNull); | 5208 expectNotNullIfNoErrors(expression); |
| 5334 expect(expression.operator.type, TokenType.CARET); | 5209 listener.assertNoErrors(); |
| 5335 expect(expression.rightOperand, isNotNull); | 5210 expect(expression, new isInstanceOf<BinaryExpression>()); |
| 5211 BinaryExpression binaryExpression = expression; |
| 5212 expect(binaryExpression.leftOperand, isNotNull); |
| 5213 expect(binaryExpression.operator, isNotNull); |
| 5214 expect(binaryExpression.operator.type, TokenType.CARET); |
| 5215 expect(binaryExpression.rightOperand, isNotNull); |
| 5336 } | 5216 } |
| 5337 | 5217 |
| 5338 void test_parseBitwiseXorExpression_super() { | 5218 void test_parseBitwiseXorExpression_super() { |
| 5339 BinaryExpression expression = | 5219 createParser('super ^ y'); |
| 5340 parse4("parseBitwiseXorExpression", "super ^ y"); | 5220 Expression expression = parser.parseBitwiseXorExpression(); |
| 5341 EngineTestCase.assertInstanceOf((obj) => obj is SuperExpression, | 5221 expectNotNullIfNoErrors(expression); |
| 5342 SuperExpression, expression.leftOperand); | 5222 listener.assertNoErrors(); |
| 5343 expect(expression.operator, isNotNull); | 5223 expect(expression, new isInstanceOf<BinaryExpression>()); |
| 5344 expect(expression.operator.type, TokenType.CARET); | 5224 BinaryExpression binaryExpression = expression; |
| 5345 expect(expression.rightOperand, isNotNull); | 5225 expect(binaryExpression.leftOperand, new isInstanceOf<SuperExpression>()); |
| 5226 expect(binaryExpression.operator, isNotNull); |
| 5227 expect(binaryExpression.operator.type, TokenType.CARET); |
| 5228 expect(binaryExpression.rightOperand, isNotNull); |
| 5346 } | 5229 } |
| 5347 | 5230 |
| 5348 void test_parseBlock_empty() { | 5231 void test_parseBlock_empty() { |
| 5349 Block block = parse4("parseBlock", "{}"); | 5232 createParser('{}'); |
| 5233 Block block = parser.parseBlock(); |
| 5234 expectNotNullIfNoErrors(block); |
| 5235 listener.assertNoErrors(); |
| 5350 expect(block.leftBracket, isNotNull); | 5236 expect(block.leftBracket, isNotNull); |
| 5351 expect(block.statements, hasLength(0)); | 5237 expect(block.statements, hasLength(0)); |
| 5352 expect(block.rightBracket, isNotNull); | 5238 expect(block.rightBracket, isNotNull); |
| 5353 } | 5239 } |
| 5354 | 5240 |
| 5355 void test_parseBlock_nonEmpty() { | 5241 void test_parseBlock_nonEmpty() { |
| 5356 Block block = parse4("parseBlock", "{;}"); | 5242 createParser('{;}'); |
| 5243 Block block = parser.parseBlock(); |
| 5244 expectNotNullIfNoErrors(block); |
| 5245 listener.assertNoErrors(); |
| 5357 expect(block.leftBracket, isNotNull); | 5246 expect(block.leftBracket, isNotNull); |
| 5358 expect(block.statements, hasLength(1)); | 5247 expect(block.statements, hasLength(1)); |
| 5359 expect(block.rightBracket, isNotNull); | 5248 expect(block.rightBracket, isNotNull); |
| 5360 } | 5249 } |
| 5361 | 5250 |
| 5362 void test_parseBreakStatement_label() { | 5251 void test_parseBreakStatement_label() { |
| 5363 BreakStatement statement = parse4("parseBreakStatement", "break foo;"); | 5252 createParser('break foo;'); |
| 5253 BreakStatement statement = parser.parseBreakStatement(); |
| 5254 expectNotNullIfNoErrors(statement); |
| 5255 listener.assertNoErrors(); |
| 5364 expect(statement.breakKeyword, isNotNull); | 5256 expect(statement.breakKeyword, isNotNull); |
| 5365 expect(statement.label, isNotNull); | 5257 expect(statement.label, isNotNull); |
| 5366 expect(statement.semicolon, isNotNull); | 5258 expect(statement.semicolon, isNotNull); |
| 5367 } | 5259 } |
| 5368 | 5260 |
| 5369 void test_parseBreakStatement_noLabel() { | 5261 void test_parseBreakStatement_noLabel() { |
| 5370 BreakStatement statement = parse4("parseBreakStatement", "break;", | 5262 createParser('break;'); |
| 5371 [ParserErrorCode.BREAK_OUTSIDE_OF_LOOP]); | 5263 BreakStatement statement = parser.parseBreakStatement(); |
| 5264 expectNotNullIfNoErrors(statement); |
| 5265 listener.assertErrorsWithCodes([ParserErrorCode.BREAK_OUTSIDE_OF_LOOP]); |
| 5372 expect(statement.breakKeyword, isNotNull); | 5266 expect(statement.breakKeyword, isNotNull); |
| 5373 expect(statement.label, isNull); | 5267 expect(statement.label, isNull); |
| 5374 expect(statement.semicolon, isNotNull); | 5268 expect(statement.semicolon, isNotNull); |
| 5375 } | 5269 } |
| 5376 | 5270 |
| 5377 void test_parseCascadeSection_i() { | 5271 void test_parseCascadeSection_i() { |
| 5378 IndexExpression section = parse4("parseCascadeSection", "..[i]"); | 5272 createParser('..[i]'); |
| 5273 Expression expression = parser.parseCascadeSection(); |
| 5274 expectNotNullIfNoErrors(expression); |
| 5275 listener.assertNoErrors(); |
| 5276 expect(expression, new isInstanceOf<IndexExpression>()); |
| 5277 IndexExpression section = expression; |
| 5379 expect(section.target, isNull); | 5278 expect(section.target, isNull); |
| 5380 expect(section.leftBracket, isNotNull); | 5279 expect(section.leftBracket, isNotNull); |
| 5381 expect(section.index, isNotNull); | 5280 expect(section.index, isNotNull); |
| 5382 expect(section.rightBracket, isNotNull); | 5281 expect(section.rightBracket, isNotNull); |
| 5383 } | 5282 } |
| 5384 | 5283 |
| 5385 void test_parseCascadeSection_ia() { | 5284 void test_parseCascadeSection_ia() { |
| 5386 FunctionExpressionInvocation section = | 5285 createParser('..[i](b)'); |
| 5387 parse4("parseCascadeSection", "..[i](b)"); | 5286 Expression expression = parser.parseCascadeSection(); |
| 5388 EngineTestCase.assertInstanceOf( | 5287 expectNotNullIfNoErrors(expression); |
| 5389 (obj) => obj is IndexExpression, IndexExpression, section.function); | 5288 listener.assertNoErrors(); |
| 5289 expect(expression, new isInstanceOf<FunctionExpressionInvocation>()); |
| 5290 FunctionExpressionInvocation section = expression; |
| 5291 expect(section.function, new isInstanceOf<IndexExpression>()); |
| 5390 expect(section.typeArguments, isNull); | 5292 expect(section.typeArguments, isNull); |
| 5391 expect(section.argumentList, isNotNull); | 5293 expect(section.argumentList, isNotNull); |
| 5392 } | 5294 } |
| 5393 | 5295 |
| 5296 void test_parseCascadeSection_ia_typeArgumentComments() { |
| 5297 enableGenericMethodComments = true; |
| 5298 createParser('..[i]/*<E>*/(b)'); |
| 5299 Expression expression = parser.parseCascadeSection(); |
| 5300 expectNotNullIfNoErrors(expression); |
| 5301 listener.assertNoErrors(); |
| 5302 expect(expression, new isInstanceOf<FunctionExpressionInvocation>()); |
| 5303 FunctionExpressionInvocation section = expression; |
| 5304 expect(section.function, new isInstanceOf<IndexExpression>()); |
| 5305 expect(section.typeArguments, isNotNull); |
| 5306 expect(section.argumentList, isNotNull); |
| 5307 } |
| 5308 |
| 5394 void test_parseCascadeSection_ia_typeArguments() { | 5309 void test_parseCascadeSection_ia_typeArguments() { |
| 5395 enableGenericMethods = true; | 5310 enableGenericMethods = true; |
| 5396 FunctionExpressionInvocation section = | 5311 createParser('..[i]<E>(b)'); |
| 5397 parse4("parseCascadeSection", "..[i]<E>(b)"); | 5312 Expression expression = parser.parseCascadeSection(); |
| 5398 EngineTestCase.assertInstanceOf( | 5313 expectNotNullIfNoErrors(expression); |
| 5399 (obj) => obj is IndexExpression, IndexExpression, section.function); | 5314 listener.assertNoErrors(); |
| 5315 expect(expression, new isInstanceOf<FunctionExpressionInvocation>()); |
| 5316 FunctionExpressionInvocation section = expression; |
| 5317 expect(section.function, new isInstanceOf<IndexExpression>()); |
| 5400 expect(section.typeArguments, isNotNull); | 5318 expect(section.typeArguments, isNotNull); |
| 5401 expect(section.argumentList, isNotNull); | 5319 expect(section.argumentList, isNotNull); |
| 5402 } | 5320 } |
| 5403 | 5321 |
| 5404 void test_parseCascadeSection_ii() { | 5322 void test_parseCascadeSection_ii() { |
| 5405 MethodInvocation section = parse4("parseCascadeSection", "..a(b).c(d)"); | 5323 createParser('..a(b).c(d)'); |
| 5406 EngineTestCase.assertInstanceOf( | 5324 Expression expression = parser.parseCascadeSection(); |
| 5407 (obj) => obj is MethodInvocation, MethodInvocation, section.target); | 5325 expectNotNullIfNoErrors(expression); |
| 5326 listener.assertNoErrors(); |
| 5327 expect(expression, new isInstanceOf<MethodInvocation>()); |
| 5328 MethodInvocation section = expression; |
| 5329 expect(section.target, new isInstanceOf<MethodInvocation>()); |
| 5408 expect(section.operator, isNotNull); | 5330 expect(section.operator, isNotNull); |
| 5409 expect(section.methodName, isNotNull); | 5331 expect(section.methodName, isNotNull); |
| 5410 expect(section.typeArguments, isNull); | 5332 expect(section.typeArguments, isNull); |
| 5411 expect(section.argumentList, isNotNull); | 5333 expect(section.argumentList, isNotNull); |
| 5412 expect(section.argumentList.arguments, hasLength(1)); | 5334 expect(section.argumentList.arguments, hasLength(1)); |
| 5413 } | 5335 } |
| 5414 | 5336 |
| 5337 void test_parseCascadeSection_ii_typeArgumentComments() { |
| 5338 enableGenericMethodComments = true; |
| 5339 createParser('..a/*<E>*/(b).c/*<F>*/(d)'); |
| 5340 Expression expression = parser.parseCascadeSection(); |
| 5341 expectNotNullIfNoErrors(expression); |
| 5342 listener.assertNoErrors(); |
| 5343 expect(expression, new isInstanceOf<MethodInvocation>()); |
| 5344 MethodInvocation section = expression; |
| 5345 expect(section.target, new isInstanceOf<MethodInvocation>()); |
| 5346 expect(section.operator, isNotNull); |
| 5347 expect(section.methodName, isNotNull); |
| 5348 expect(section.typeArguments, isNotNull); |
| 5349 expect(section.argumentList, isNotNull); |
| 5350 expect(section.argumentList.arguments, hasLength(1)); |
| 5351 } |
| 5352 |
| 5415 void test_parseCascadeSection_ii_typeArguments() { | 5353 void test_parseCascadeSection_ii_typeArguments() { |
| 5416 enableGenericMethods = true; | 5354 enableGenericMethods = true; |
| 5417 MethodInvocation section = | 5355 createParser('..a<E>(b).c<F>(d)'); |
| 5418 parse4("parseCascadeSection", "..a<E>(b).c<F>(d)"); | 5356 Expression expression = parser.parseCascadeSection(); |
| 5419 EngineTestCase.assertInstanceOf( | 5357 expectNotNullIfNoErrors(expression); |
| 5420 (obj) => obj is MethodInvocation, MethodInvocation, section.target); | 5358 listener.assertNoErrors(); |
| 5359 expect(expression, new isInstanceOf<MethodInvocation>()); |
| 5360 MethodInvocation section = expression; |
| 5361 expect(section.target, new isInstanceOf<MethodInvocation>()); |
| 5421 expect(section.operator, isNotNull); | 5362 expect(section.operator, isNotNull); |
| 5422 expect(section.methodName, isNotNull); | 5363 expect(section.methodName, isNotNull); |
| 5423 expect(section.typeArguments, isNotNull); | 5364 expect(section.typeArguments, isNotNull); |
| 5424 expect(section.argumentList, isNotNull); | 5365 expect(section.argumentList, isNotNull); |
| 5425 expect(section.argumentList.arguments, hasLength(1)); | 5366 expect(section.argumentList.arguments, hasLength(1)); |
| 5426 } | 5367 } |
| 5427 | 5368 |
| 5428 void test_parseCascadeSection_p() { | 5369 void test_parseCascadeSection_p() { |
| 5429 PropertyAccess section = parse4("parseCascadeSection", "..a"); | 5370 createParser('..a'); |
| 5371 Expression expression = parser.parseCascadeSection(); |
| 5372 expectNotNullIfNoErrors(expression); |
| 5373 listener.assertNoErrors(); |
| 5374 expect(expression, new isInstanceOf<PropertyAccess>()); |
| 5375 PropertyAccess section = expression; |
| 5430 expect(section.target, isNull); | 5376 expect(section.target, isNull); |
| 5431 expect(section.operator, isNotNull); | 5377 expect(section.operator, isNotNull); |
| 5432 expect(section.propertyName, isNotNull); | 5378 expect(section.propertyName, isNotNull); |
| 5433 } | 5379 } |
| 5434 | 5380 |
| 5435 void test_parseCascadeSection_p_assign() { | 5381 void test_parseCascadeSection_p_assign() { |
| 5436 AssignmentExpression section = parse4("parseCascadeSection", "..a = 3"); | 5382 createParser('..a = 3'); |
| 5383 Expression expression = parser.parseCascadeSection(); |
| 5384 expectNotNullIfNoErrors(expression); |
| 5385 listener.assertNoErrors(); |
| 5386 expect(expression, new isInstanceOf<AssignmentExpression>()); |
| 5387 AssignmentExpression section = expression; |
| 5437 expect(section.leftHandSide, isNotNull); | 5388 expect(section.leftHandSide, isNotNull); |
| 5438 expect(section.operator, isNotNull); | 5389 expect(section.operator, isNotNull); |
| 5439 Expression rhs = section.rightHandSide; | 5390 Expression rhs = section.rightHandSide; |
| 5440 expect(rhs, isNotNull); | 5391 expect(rhs, isNotNull); |
| 5441 } | 5392 } |
| 5442 | 5393 |
| 5443 void test_parseCascadeSection_p_assign_withCascade() { | 5394 void test_parseCascadeSection_p_assign_withCascade() { |
| 5444 AssignmentExpression section = | 5395 createParser('..a = 3..m()'); |
| 5445 parse4("parseCascadeSection", "..a = 3..m()"); | 5396 Expression expression = parser.parseCascadeSection(); |
| 5397 expectNotNullIfNoErrors(expression); |
| 5398 listener.assertNoErrors(); |
| 5399 expect(expression, new isInstanceOf<AssignmentExpression>()); |
| 5400 AssignmentExpression section = expression; |
| 5446 expect(section.leftHandSide, isNotNull); | 5401 expect(section.leftHandSide, isNotNull); |
| 5447 expect(section.operator, isNotNull); | 5402 expect(section.operator, isNotNull); |
| 5448 Expression rhs = section.rightHandSide; | 5403 Expression rhs = section.rightHandSide; |
| 5404 EngineTestCase.assertInstanceOf( |
| 5405 (obj) => obj is IntegerLiteral, IntegerLiteral, rhs); |
| 5406 } |
| 5407 |
| 5408 void test_parseCascadeSection_p_assign_withCascade_typeArgumentComments() { |
| 5409 enableGenericMethodComments = true; |
| 5410 createParser('..a = 3..m/*<E>*/()'); |
| 5411 Expression expression = parser.parseCascadeSection(); |
| 5412 expectNotNullIfNoErrors(expression); |
| 5413 listener.assertNoErrors(); |
| 5414 expect(expression, new isInstanceOf<AssignmentExpression>()); |
| 5415 AssignmentExpression section = expression; |
| 5416 expect(section.leftHandSide, isNotNull); |
| 5417 expect(section.operator, isNotNull); |
| 5418 Expression rhs = section.rightHandSide; |
| 5449 EngineTestCase.assertInstanceOf( | 5419 EngineTestCase.assertInstanceOf( |
| 5450 (obj) => obj is IntegerLiteral, IntegerLiteral, rhs); | 5420 (obj) => obj is IntegerLiteral, IntegerLiteral, rhs); |
| 5451 } | 5421 } |
| 5452 | 5422 |
| 5453 void test_parseCascadeSection_p_assign_withCascade_typeArguments() { | 5423 void test_parseCascadeSection_p_assign_withCascade_typeArguments() { |
| 5454 enableGenericMethods = true; | 5424 enableGenericMethods = true; |
| 5455 AssignmentExpression section = | 5425 createParser('..a = 3..m<E>()'); |
| 5456 parse4("parseCascadeSection", "..a = 3..m<E>()"); | 5426 Expression expression = parser.parseCascadeSection(); |
| 5427 expectNotNullIfNoErrors(expression); |
| 5428 listener.assertNoErrors(); |
| 5429 expect(expression, new isInstanceOf<AssignmentExpression>()); |
| 5430 AssignmentExpression section = expression; |
| 5457 expect(section.leftHandSide, isNotNull); | 5431 expect(section.leftHandSide, isNotNull); |
| 5458 expect(section.operator, isNotNull); | 5432 expect(section.operator, isNotNull); |
| 5459 Expression rhs = section.rightHandSide; | 5433 Expression rhs = section.rightHandSide; |
| 5460 EngineTestCase.assertInstanceOf( | 5434 EngineTestCase.assertInstanceOf( |
| 5461 (obj) => obj is IntegerLiteral, IntegerLiteral, rhs); | 5435 (obj) => obj is IntegerLiteral, IntegerLiteral, rhs); |
| 5462 } | 5436 } |
| 5463 | 5437 |
| 5464 void test_parseCascadeSection_p_builtIn() { | 5438 void test_parseCascadeSection_p_builtIn() { |
| 5465 PropertyAccess section = parse4("parseCascadeSection", "..as"); | 5439 createParser('..as'); |
| 5440 Expression expression = parser.parseCascadeSection(); |
| 5441 expectNotNullIfNoErrors(expression); |
| 5442 listener.assertNoErrors(); |
| 5443 expect(expression, new isInstanceOf<PropertyAccess>()); |
| 5444 PropertyAccess section = expression; |
| 5466 expect(section.target, isNull); | 5445 expect(section.target, isNull); |
| 5467 expect(section.operator, isNotNull); | 5446 expect(section.operator, isNotNull); |
| 5468 expect(section.propertyName, isNotNull); | 5447 expect(section.propertyName, isNotNull); |
| 5469 } | 5448 } |
| 5470 | 5449 |
| 5471 void test_parseCascadeSection_pa() { | 5450 void test_parseCascadeSection_pa() { |
| 5472 MethodInvocation section = parse4("parseCascadeSection", "..a(b)"); | 5451 createParser('..a(b)'); |
| 5452 Expression expression = parser.parseCascadeSection(); |
| 5453 expectNotNullIfNoErrors(expression); |
| 5454 listener.assertNoErrors(); |
| 5455 expect(expression, new isInstanceOf<MethodInvocation>()); |
| 5456 MethodInvocation section = expression; |
| 5473 expect(section.target, isNull); | 5457 expect(section.target, isNull); |
| 5474 expect(section.operator, isNotNull); | 5458 expect(section.operator, isNotNull); |
| 5475 expect(section.methodName, isNotNull); | 5459 expect(section.methodName, isNotNull); |
| 5476 expect(section.typeArguments, isNull); | 5460 expect(section.typeArguments, isNull); |
| 5477 expect(section.argumentList, isNotNull); | 5461 expect(section.argumentList, isNotNull); |
| 5478 expect(section.argumentList.arguments, hasLength(1)); | 5462 expect(section.argumentList.arguments, hasLength(1)); |
| 5479 } | 5463 } |
| 5480 | 5464 |
| 5465 void test_parseCascadeSection_pa_typeArgumentComments() { |
| 5466 enableGenericMethodComments = true; |
| 5467 createParser('..a/*<E>*/(b)'); |
| 5468 Expression expression = parser.parseCascadeSection(); |
| 5469 expectNotNullIfNoErrors(expression); |
| 5470 listener.assertNoErrors(); |
| 5471 expect(expression, new isInstanceOf<MethodInvocation>()); |
| 5472 MethodInvocation section = expression; |
| 5473 expect(section.target, isNull); |
| 5474 expect(section.operator, isNotNull); |
| 5475 expect(section.methodName, isNotNull); |
| 5476 expect(section.typeArguments, isNotNull); |
| 5477 expect(section.argumentList, isNotNull); |
| 5478 expect(section.argumentList.arguments, hasLength(1)); |
| 5479 } |
| 5480 |
| 5481 void test_parseCascadeSection_pa_typeArguments() { | 5481 void test_parseCascadeSection_pa_typeArguments() { |
| 5482 enableGenericMethods = true; | 5482 enableGenericMethods = true; |
| 5483 MethodInvocation section = parse4("parseCascadeSection", "..a<E>(b)"); | 5483 createParser('..a<E>(b)'); |
| 5484 Expression expression = parser.parseCascadeSection(); |
| 5485 expectNotNullIfNoErrors(expression); |
| 5486 listener.assertNoErrors(); |
| 5487 expect(expression, new isInstanceOf<MethodInvocation>()); |
| 5488 MethodInvocation section = expression; |
| 5484 expect(section.target, isNull); | 5489 expect(section.target, isNull); |
| 5485 expect(section.operator, isNotNull); | 5490 expect(section.operator, isNotNull); |
| 5486 expect(section.methodName, isNotNull); | 5491 expect(section.methodName, isNotNull); |
| 5487 expect(section.typeArguments, isNotNull); | 5492 expect(section.typeArguments, isNotNull); |
| 5488 expect(section.argumentList, isNotNull); | 5493 expect(section.argumentList, isNotNull); |
| 5489 expect(section.argumentList.arguments, hasLength(1)); | 5494 expect(section.argumentList.arguments, hasLength(1)); |
| 5490 } | 5495 } |
| 5491 | 5496 |
| 5492 void test_parseCascadeSection_paa() { | 5497 void test_parseCascadeSection_paa() { |
| 5493 FunctionExpressionInvocation section = | 5498 createParser('..a(b)(c)'); |
| 5494 parse4("parseCascadeSection", "..a(b)(c)"); | 5499 Expression expression = parser.parseCascadeSection(); |
| 5495 EngineTestCase.assertInstanceOf( | 5500 expectNotNullIfNoErrors(expression); |
| 5496 (obj) => obj is MethodInvocation, MethodInvocation, section.function); | 5501 listener.assertNoErrors(); |
| 5502 expect(expression, new isInstanceOf<FunctionExpressionInvocation>()); |
| 5503 FunctionExpressionInvocation section = expression; |
| 5504 expect(section.function, new isInstanceOf<MethodInvocation>()); |
| 5497 expect(section.typeArguments, isNull); | 5505 expect(section.typeArguments, isNull); |
| 5498 expect(section.argumentList, isNotNull); | 5506 expect(section.argumentList, isNotNull); |
| 5499 expect(section.argumentList.arguments, hasLength(1)); | 5507 expect(section.argumentList.arguments, hasLength(1)); |
| 5500 } | 5508 } |
| 5501 | 5509 |
| 5510 void test_parseCascadeSection_paa_typeArgumentComments() { |
| 5511 enableGenericMethodComments = true; |
| 5512 createParser('..a/*<E>*/(b)/*<F>*/(c)'); |
| 5513 Expression expression = parser.parseCascadeSection(); |
| 5514 expectNotNullIfNoErrors(expression); |
| 5515 listener.assertNoErrors(); |
| 5516 expect(expression, new isInstanceOf<FunctionExpressionInvocation>()); |
| 5517 FunctionExpressionInvocation section = expression; |
| 5518 expect(section.function, new isInstanceOf<MethodInvocation>()); |
| 5519 expect(section.typeArguments, isNotNull); |
| 5520 expect(section.argumentList, isNotNull); |
| 5521 expect(section.argumentList.arguments, hasLength(1)); |
| 5522 } |
| 5523 |
| 5502 void test_parseCascadeSection_paa_typeArguments() { | 5524 void test_parseCascadeSection_paa_typeArguments() { |
| 5503 enableGenericMethods = true; | 5525 enableGenericMethods = true; |
| 5504 FunctionExpressionInvocation section = | 5526 createParser('..a<E>(b)<F>(c)'); |
| 5505 parse4("parseCascadeSection", "..a<E>(b)<F>(c)"); | 5527 Expression expression = parser.parseCascadeSection(); |
| 5506 EngineTestCase.assertInstanceOf( | 5528 expectNotNullIfNoErrors(expression); |
| 5507 (obj) => obj is MethodInvocation, MethodInvocation, section.function); | 5529 listener.assertNoErrors(); |
| 5530 expect(expression, new isInstanceOf<FunctionExpressionInvocation>()); |
| 5531 FunctionExpressionInvocation section = expression; |
| 5532 expect(section.function, new isInstanceOf<MethodInvocation>()); |
| 5508 expect(section.typeArguments, isNotNull); | 5533 expect(section.typeArguments, isNotNull); |
| 5509 expect(section.argumentList, isNotNull); | 5534 expect(section.argumentList, isNotNull); |
| 5510 expect(section.argumentList.arguments, hasLength(1)); | 5535 expect(section.argumentList.arguments, hasLength(1)); |
| 5511 } | 5536 } |
| 5512 | 5537 |
| 5513 void test_parseCascadeSection_paapaa() { | 5538 void test_parseCascadeSection_paapaa() { |
| 5514 FunctionExpressionInvocation section = | 5539 createParser('..a(b)(c).d(e)(f)'); |
| 5515 parse4("parseCascadeSection", "..a(b)(c).d(e)(f)"); | 5540 Expression expression = parser.parseCascadeSection(); |
| 5516 EngineTestCase.assertInstanceOf( | 5541 expectNotNullIfNoErrors(expression); |
| 5517 (obj) => obj is MethodInvocation, MethodInvocation, section.function); | 5542 listener.assertNoErrors(); |
| 5543 expect(expression, new isInstanceOf<FunctionExpressionInvocation>()); |
| 5544 FunctionExpressionInvocation section = expression; |
| 5545 expect(section.function, new isInstanceOf<MethodInvocation>()); |
| 5518 expect(section.typeArguments, isNull); | 5546 expect(section.typeArguments, isNull); |
| 5519 expect(section.argumentList, isNotNull); | 5547 expect(section.argumentList, isNotNull); |
| 5520 expect(section.argumentList.arguments, hasLength(1)); | 5548 expect(section.argumentList.arguments, hasLength(1)); |
| 5521 } | 5549 } |
| 5522 | 5550 |
| 5551 void test_parseCascadeSection_paapaa_typeArgumentComments() { |
| 5552 enableGenericMethodComments = true; |
| 5553 createParser('..a/*<E>*/(b)/*<F>*/(c).d/*<G>*/(e)/*<H>*/(f)'); |
| 5554 Expression expression = parser.parseCascadeSection(); |
| 5555 expectNotNullIfNoErrors(expression); |
| 5556 listener.assertNoErrors(); |
| 5557 expect(expression, new isInstanceOf<FunctionExpressionInvocation>()); |
| 5558 FunctionExpressionInvocation section = expression; |
| 5559 expect(section.function, new isInstanceOf<MethodInvocation>()); |
| 5560 expect(section.typeArguments, isNotNull); |
| 5561 expect(section.argumentList, isNotNull); |
| 5562 expect(section.argumentList.arguments, hasLength(1)); |
| 5563 } |
| 5564 |
| 5523 void test_parseCascadeSection_paapaa_typeArguments() { | 5565 void test_parseCascadeSection_paapaa_typeArguments() { |
| 5524 enableGenericMethods = true; | 5566 enableGenericMethods = true; |
| 5525 FunctionExpressionInvocation section = | 5567 createParser('..a<E>(b)<F>(c).d<G>(e)<H>(f)'); |
| 5526 parse4("parseCascadeSection", "..a<E>(b)<F>(c).d<G>(e)<H>(f)"); | 5568 Expression expression = parser.parseCascadeSection(); |
| 5527 EngineTestCase.assertInstanceOf( | 5569 expectNotNullIfNoErrors(expression); |
| 5528 (obj) => obj is MethodInvocation, MethodInvocation, section.function); | 5570 listener.assertNoErrors(); |
| 5571 expect(expression, new isInstanceOf<FunctionExpressionInvocation>()); |
| 5572 FunctionExpressionInvocation section = expression; |
| 5573 expect(section.function, new isInstanceOf<MethodInvocation>()); |
| 5529 expect(section.typeArguments, isNotNull); | 5574 expect(section.typeArguments, isNotNull); |
| 5530 expect(section.argumentList, isNotNull); | 5575 expect(section.argumentList, isNotNull); |
| 5531 expect(section.argumentList.arguments, hasLength(1)); | 5576 expect(section.argumentList.arguments, hasLength(1)); |
| 5532 } | 5577 } |
| 5533 | 5578 |
| 5534 void test_parseCascadeSection_pap() { | 5579 void test_parseCascadeSection_pap() { |
| 5535 PropertyAccess section = parse4("parseCascadeSection", "..a(b).c"); | 5580 createParser('..a(b).c'); |
| 5581 Expression expression = parser.parseCascadeSection(); |
| 5582 expectNotNullIfNoErrors(expression); |
| 5583 listener.assertNoErrors(); |
| 5584 expect(expression, new isInstanceOf<PropertyAccess>()); |
| 5585 PropertyAccess section = expression; |
| 5536 expect(section.target, isNotNull); | 5586 expect(section.target, isNotNull); |
| 5537 expect(section.operator, isNotNull); | 5587 expect(section.operator, isNotNull); |
| 5538 expect(section.propertyName, isNotNull); | 5588 expect(section.propertyName, isNotNull); |
| 5589 } |
| 5590 |
| 5591 void test_parseCascadeSection_pap_typeArgumentComments() { |
| 5592 enableGenericMethodComments = true; |
| 5593 createParser('..a/*<E>*/(b).c'); |
| 5594 Expression expression = parser.parseCascadeSection(); |
| 5595 expectNotNullIfNoErrors(expression); |
| 5596 listener.assertNoErrors(); |
| 5597 expect(expression, new isInstanceOf<PropertyAccess>()); |
| 5598 PropertyAccess section = expression; |
| 5599 expect(section.target, isNotNull); |
| 5600 expect(section.operator, isNotNull); |
| 5601 expect(section.propertyName, isNotNull); |
| 5539 } | 5602 } |
| 5540 | 5603 |
| 5541 void test_parseCascadeSection_pap_typeArguments() { | 5604 void test_parseCascadeSection_pap_typeArguments() { |
| 5542 enableGenericMethods = true; | 5605 enableGenericMethods = true; |
| 5543 PropertyAccess section = parse4("parseCascadeSection", "..a<E>(b).c"); | 5606 createParser('..a<E>(b).c'); |
| 5607 Expression expression = parser.parseCascadeSection(); |
| 5608 expectNotNullIfNoErrors(expression); |
| 5609 listener.assertNoErrors(); |
| 5610 expect(expression, new isInstanceOf<PropertyAccess>()); |
| 5611 PropertyAccess section = expression; |
| 5544 expect(section.target, isNotNull); | 5612 expect(section.target, isNotNull); |
| 5545 expect(section.operator, isNotNull); | 5613 expect(section.operator, isNotNull); |
| 5546 expect(section.propertyName, isNotNull); | 5614 expect(section.propertyName, isNotNull); |
| 5547 } | 5615 } |
| 5548 | 5616 |
| 5549 void test_parseClassDeclaration_abstract() { | 5617 void test_parseClassDeclaration_abstract() { |
| 5550 ClassDeclaration declaration = parse( | 5618 createParser('class A {}'); |
| 5551 "parseClassDeclaration", | 5619 CompilationUnitMember member = parser.parseClassDeclaration( |
| 5552 <Object>[ | 5620 emptyCommentAndMetadata(), |
| 5553 emptyCommentAndMetadata(), | 5621 TokenFactory.tokenFromKeyword(Keyword.ABSTRACT)); |
| 5554 TokenFactory.tokenFromKeyword(Keyword.ABSTRACT) | 5622 expectNotNullIfNoErrors(member); |
| 5555 ], | 5623 listener.assertNoErrors(); |
| 5556 "class A {}"); | 5624 expect(member, new isInstanceOf<ClassDeclaration>()); |
| 5625 ClassDeclaration declaration = member; |
| 5557 expect(declaration.documentationComment, isNull); | 5626 expect(declaration.documentationComment, isNull); |
| 5558 expect(declaration.abstractKeyword, isNotNull); | 5627 expect(declaration.abstractKeyword, isNotNull); |
| 5559 expect(declaration.extendsClause, isNull); | 5628 expect(declaration.extendsClause, isNull); |
| 5560 expect(declaration.implementsClause, isNull); | 5629 expect(declaration.implementsClause, isNull); |
| 5561 expect(declaration.classKeyword, isNotNull); | 5630 expect(declaration.classKeyword, isNotNull); |
| 5562 expect(declaration.leftBracket, isNotNull); | 5631 expect(declaration.leftBracket, isNotNull); |
| 5563 expect(declaration.name, isNotNull); | 5632 expect(declaration.name, isNotNull); |
| 5564 expect(declaration.members, hasLength(0)); | 5633 expect(declaration.members, hasLength(0)); |
| 5565 expect(declaration.rightBracket, isNotNull); | 5634 expect(declaration.rightBracket, isNotNull); |
| 5566 expect(declaration.typeParameters, isNull); | 5635 expect(declaration.typeParameters, isNull); |
| 5567 } | 5636 } |
| 5568 | 5637 |
| 5569 void test_parseClassDeclaration_empty() { | 5638 void test_parseClassDeclaration_empty() { |
| 5570 ClassDeclaration declaration = parse("parseClassDeclaration", | 5639 createParser('class A {}'); |
| 5571 <Object>[emptyCommentAndMetadata(), null], "class A {}"); | 5640 CompilationUnitMember member = |
| 5641 parser.parseClassDeclaration(emptyCommentAndMetadata(), null); |
| 5642 expectNotNullIfNoErrors(member); |
| 5643 listener.assertNoErrors(); |
| 5644 expect(member, new isInstanceOf<ClassDeclaration>()); |
| 5645 ClassDeclaration declaration = member; |
| 5572 expect(declaration.documentationComment, isNull); | 5646 expect(declaration.documentationComment, isNull); |
| 5573 expect(declaration.abstractKeyword, isNull); | 5647 expect(declaration.abstractKeyword, isNull); |
| 5574 expect(declaration.extendsClause, isNull); | 5648 expect(declaration.extendsClause, isNull); |
| 5575 expect(declaration.implementsClause, isNull); | 5649 expect(declaration.implementsClause, isNull); |
| 5576 expect(declaration.classKeyword, isNotNull); | 5650 expect(declaration.classKeyword, isNotNull); |
| 5577 expect(declaration.leftBracket, isNotNull); | 5651 expect(declaration.leftBracket, isNotNull); |
| 5578 expect(declaration.name, isNotNull); | 5652 expect(declaration.name, isNotNull); |
| 5579 expect(declaration.members, hasLength(0)); | 5653 expect(declaration.members, hasLength(0)); |
| 5580 expect(declaration.rightBracket, isNotNull); | 5654 expect(declaration.rightBracket, isNotNull); |
| 5581 expect(declaration.typeParameters, isNull); | 5655 expect(declaration.typeParameters, isNull); |
| 5582 } | 5656 } |
| 5583 | 5657 |
| 5584 void test_parseClassDeclaration_extends() { | 5658 void test_parseClassDeclaration_extends() { |
| 5585 ClassDeclaration declaration = parse("parseClassDeclaration", | 5659 createParser('class A extends B {}'); |
| 5586 <Object>[emptyCommentAndMetadata(), null], "class A extends B {}"); | 5660 CompilationUnitMember member = |
| 5661 parser.parseClassDeclaration(emptyCommentAndMetadata(), null); |
| 5662 expectNotNullIfNoErrors(member); |
| 5663 listener.assertNoErrors(); |
| 5664 expect(member, new isInstanceOf<ClassDeclaration>()); |
| 5665 ClassDeclaration declaration = member; |
| 5587 expect(declaration.documentationComment, isNull); | 5666 expect(declaration.documentationComment, isNull); |
| 5588 expect(declaration.abstractKeyword, isNull); | 5667 expect(declaration.abstractKeyword, isNull); |
| 5589 expect(declaration.extendsClause, isNotNull); | 5668 expect(declaration.extendsClause, isNotNull); |
| 5590 expect(declaration.implementsClause, isNull); | 5669 expect(declaration.implementsClause, isNull); |
| 5591 expect(declaration.classKeyword, isNotNull); | 5670 expect(declaration.classKeyword, isNotNull); |
| 5592 expect(declaration.leftBracket, isNotNull); | 5671 expect(declaration.leftBracket, isNotNull); |
| 5593 expect(declaration.name, isNotNull); | 5672 expect(declaration.name, isNotNull); |
| 5594 expect(declaration.members, hasLength(0)); | 5673 expect(declaration.members, hasLength(0)); |
| 5595 expect(declaration.rightBracket, isNotNull); | 5674 expect(declaration.rightBracket, isNotNull); |
| 5596 expect(declaration.typeParameters, isNull); | 5675 expect(declaration.typeParameters, isNull); |
| 5597 } | 5676 } |
| 5598 | 5677 |
| 5599 void test_parseClassDeclaration_extendsAndImplements() { | 5678 void test_parseClassDeclaration_extendsAndImplements() { |
| 5600 ClassDeclaration declaration = parse( | 5679 createParser('class A extends B implements C {}'); |
| 5601 "parseClassDeclaration", | 5680 CompilationUnitMember member = |
| 5602 <Object>[emptyCommentAndMetadata(), null], | 5681 parser.parseClassDeclaration(emptyCommentAndMetadata(), null); |
| 5603 "class A extends B implements C {}"); | 5682 expectNotNullIfNoErrors(member); |
| 5683 listener.assertNoErrors(); |
| 5684 expect(member, new isInstanceOf<ClassDeclaration>()); |
| 5685 ClassDeclaration declaration = member; |
| 5604 expect(declaration.documentationComment, isNull); | 5686 expect(declaration.documentationComment, isNull); |
| 5605 expect(declaration.abstractKeyword, isNull); | 5687 expect(declaration.abstractKeyword, isNull); |
| 5606 expect(declaration.extendsClause, isNotNull); | 5688 expect(declaration.extendsClause, isNotNull); |
| 5607 expect(declaration.implementsClause, isNotNull); | 5689 expect(declaration.implementsClause, isNotNull); |
| 5608 expect(declaration.classKeyword, isNotNull); | 5690 expect(declaration.classKeyword, isNotNull); |
| 5609 expect(declaration.leftBracket, isNotNull); | 5691 expect(declaration.leftBracket, isNotNull); |
| 5610 expect(declaration.name, isNotNull); | 5692 expect(declaration.name, isNotNull); |
| 5611 expect(declaration.members, hasLength(0)); | 5693 expect(declaration.members, hasLength(0)); |
| 5612 expect(declaration.rightBracket, isNotNull); | 5694 expect(declaration.rightBracket, isNotNull); |
| 5613 expect(declaration.typeParameters, isNull); | 5695 expect(declaration.typeParameters, isNull); |
| 5614 } | 5696 } |
| 5615 | 5697 |
| 5616 void test_parseClassDeclaration_extendsAndWith() { | 5698 void test_parseClassDeclaration_extendsAndWith() { |
| 5617 ClassDeclaration declaration = parse( | 5699 createParser('class A extends B with C {}'); |
| 5618 "parseClassDeclaration", | 5700 CompilationUnitMember member = |
| 5619 <Object>[emptyCommentAndMetadata(), null], | 5701 parser.parseClassDeclaration(emptyCommentAndMetadata(), null); |
| 5620 "class A extends B with C {}"); | 5702 expectNotNullIfNoErrors(member); |
| 5703 listener.assertNoErrors(); |
| 5704 expect(member, new isInstanceOf<ClassDeclaration>()); |
| 5705 ClassDeclaration declaration = member; |
| 5621 expect(declaration.documentationComment, isNull); | 5706 expect(declaration.documentationComment, isNull); |
| 5622 expect(declaration.abstractKeyword, isNull); | 5707 expect(declaration.abstractKeyword, isNull); |
| 5623 expect(declaration.classKeyword, isNotNull); | 5708 expect(declaration.classKeyword, isNotNull); |
| 5624 expect(declaration.name, isNotNull); | 5709 expect(declaration.name, isNotNull); |
| 5625 expect(declaration.typeParameters, isNull); | 5710 expect(declaration.typeParameters, isNull); |
| 5626 expect(declaration.extendsClause, isNotNull); | 5711 expect(declaration.extendsClause, isNotNull); |
| 5627 expect(declaration.withClause, isNotNull); | 5712 expect(declaration.withClause, isNotNull); |
| 5628 expect(declaration.implementsClause, isNull); | 5713 expect(declaration.implementsClause, isNull); |
| 5629 expect(declaration.leftBracket, isNotNull); | 5714 expect(declaration.leftBracket, isNotNull); |
| 5630 expect(declaration.members, hasLength(0)); | 5715 expect(declaration.members, hasLength(0)); |
| 5631 expect(declaration.rightBracket, isNotNull); | 5716 expect(declaration.rightBracket, isNotNull); |
| 5632 } | 5717 } |
| 5633 | 5718 |
| 5634 void test_parseClassDeclaration_extendsAndWithAndImplements() { | 5719 void test_parseClassDeclaration_extendsAndWithAndImplements() { |
| 5635 ClassDeclaration declaration = parse( | 5720 createParser('class A extends B with C implements D {}'); |
| 5636 "parseClassDeclaration", | 5721 CompilationUnitMember member = |
| 5637 <Object>[emptyCommentAndMetadata(), null], | 5722 parser.parseClassDeclaration(emptyCommentAndMetadata(), null); |
| 5638 "class A extends B with C implements D {}"); | 5723 expectNotNullIfNoErrors(member); |
| 5724 listener.assertNoErrors(); |
| 5725 expect(member, new isInstanceOf<ClassDeclaration>()); |
| 5726 ClassDeclaration declaration = member; |
| 5639 expect(declaration.documentationComment, isNull); | 5727 expect(declaration.documentationComment, isNull); |
| 5640 expect(declaration.abstractKeyword, isNull); | 5728 expect(declaration.abstractKeyword, isNull); |
| 5641 expect(declaration.classKeyword, isNotNull); | 5729 expect(declaration.classKeyword, isNotNull); |
| 5642 expect(declaration.name, isNotNull); | 5730 expect(declaration.name, isNotNull); |
| 5643 expect(declaration.typeParameters, isNull); | 5731 expect(declaration.typeParameters, isNull); |
| 5644 expect(declaration.extendsClause, isNotNull); | 5732 expect(declaration.extendsClause, isNotNull); |
| 5645 expect(declaration.withClause, isNotNull); | 5733 expect(declaration.withClause, isNotNull); |
| 5646 expect(declaration.implementsClause, isNotNull); | 5734 expect(declaration.implementsClause, isNotNull); |
| 5647 expect(declaration.leftBracket, isNotNull); | 5735 expect(declaration.leftBracket, isNotNull); |
| 5648 expect(declaration.members, hasLength(0)); | 5736 expect(declaration.members, hasLength(0)); |
| 5649 expect(declaration.rightBracket, isNotNull); | 5737 expect(declaration.rightBracket, isNotNull); |
| 5650 } | 5738 } |
| 5651 | 5739 |
| 5652 void test_parseClassDeclaration_implements() { | 5740 void test_parseClassDeclaration_implements() { |
| 5653 ClassDeclaration declaration = parse("parseClassDeclaration", | 5741 createParser('class A implements C {}'); |
| 5654 <Object>[emptyCommentAndMetadata(), null], "class A implements C {}"); | 5742 CompilationUnitMember member = |
| 5743 parser.parseClassDeclaration(emptyCommentAndMetadata(), null); |
| 5744 expectNotNullIfNoErrors(member); |
| 5745 listener.assertNoErrors(); |
| 5746 expect(member, new isInstanceOf<ClassDeclaration>()); |
| 5747 ClassDeclaration declaration = member; |
| 5655 expect(declaration.documentationComment, isNull); | 5748 expect(declaration.documentationComment, isNull); |
| 5656 expect(declaration.abstractKeyword, isNull); | 5749 expect(declaration.abstractKeyword, isNull); |
| 5657 expect(declaration.extendsClause, isNull); | 5750 expect(declaration.extendsClause, isNull); |
| 5658 expect(declaration.implementsClause, isNotNull); | 5751 expect(declaration.implementsClause, isNotNull); |
| 5659 expect(declaration.classKeyword, isNotNull); | 5752 expect(declaration.classKeyword, isNotNull); |
| 5660 expect(declaration.leftBracket, isNotNull); | 5753 expect(declaration.leftBracket, isNotNull); |
| 5661 expect(declaration.name, isNotNull); | 5754 expect(declaration.name, isNotNull); |
| 5662 expect(declaration.members, hasLength(0)); | 5755 expect(declaration.members, hasLength(0)); |
| 5663 expect(declaration.rightBracket, isNotNull); | 5756 expect(declaration.rightBracket, isNotNull); |
| 5664 expect(declaration.typeParameters, isNull); | 5757 expect(declaration.typeParameters, isNull); |
| 5665 } | 5758 } |
| 5666 | 5759 |
| 5667 void test_parseClassDeclaration_native() { | 5760 void test_parseClassDeclaration_native() { |
| 5668 ClassDeclaration declaration = parse( | 5761 createParser('class A native "nativeValue" {}'); |
| 5669 "parseClassDeclaration", | 5762 CompilationUnitMember member = |
| 5670 <Object>[emptyCommentAndMetadata(), null], | 5763 parser.parseClassDeclaration(emptyCommentAndMetadata(), null); |
| 5671 "class A native 'nativeValue' {}"); | 5764 expectNotNullIfNoErrors(member); |
| 5765 listener.assertNoErrors(); |
| 5766 expect(member, new isInstanceOf<ClassDeclaration>()); |
| 5767 ClassDeclaration declaration = member; |
| 5672 NativeClause nativeClause = declaration.nativeClause; | 5768 NativeClause nativeClause = declaration.nativeClause; |
| 5673 expect(nativeClause, isNotNull); | 5769 expect(nativeClause, isNotNull); |
| 5674 expect(nativeClause.nativeKeyword, isNotNull); | 5770 expect(nativeClause.nativeKeyword, isNotNull); |
| 5675 expect(nativeClause.name.stringValue, "nativeValue"); | 5771 expect(nativeClause.name.stringValue, "nativeValue"); |
| 5676 expect(nativeClause.beginToken, same(nativeClause.nativeKeyword)); | 5772 expect(nativeClause.beginToken, same(nativeClause.nativeKeyword)); |
| 5677 expect(nativeClause.endToken, same(nativeClause.name.endToken)); | 5773 expect(nativeClause.endToken, same(nativeClause.name.endToken)); |
| 5678 } | 5774 } |
| 5679 | 5775 |
| 5680 void test_parseClassDeclaration_nonEmpty() { | 5776 void test_parseClassDeclaration_nonEmpty() { |
| 5681 ClassDeclaration declaration = parse("parseClassDeclaration", | 5777 createParser('class A {var f;}'); |
| 5682 <Object>[emptyCommentAndMetadata(), null], "class A {var f;}"); | 5778 CompilationUnitMember member = |
| 5779 parser.parseClassDeclaration(emptyCommentAndMetadata(), null); |
| 5780 expectNotNullIfNoErrors(member); |
| 5781 listener.assertNoErrors(); |
| 5782 expect(member, new isInstanceOf<ClassDeclaration>()); |
| 5783 ClassDeclaration declaration = member; |
| 5683 expect(declaration.documentationComment, isNull); | 5784 expect(declaration.documentationComment, isNull); |
| 5684 expect(declaration.abstractKeyword, isNull); | 5785 expect(declaration.abstractKeyword, isNull); |
| 5685 expect(declaration.extendsClause, isNull); | 5786 expect(declaration.extendsClause, isNull); |
| 5686 expect(declaration.implementsClause, isNull); | 5787 expect(declaration.implementsClause, isNull); |
| 5687 expect(declaration.classKeyword, isNotNull); | 5788 expect(declaration.classKeyword, isNotNull); |
| 5688 expect(declaration.leftBracket, isNotNull); | 5789 expect(declaration.leftBracket, isNotNull); |
| 5689 expect(declaration.name, isNotNull); | 5790 expect(declaration.name, isNotNull); |
| 5690 expect(declaration.members, hasLength(1)); | 5791 expect(declaration.members, hasLength(1)); |
| 5691 expect(declaration.rightBracket, isNotNull); | 5792 expect(declaration.rightBracket, isNotNull); |
| 5692 expect(declaration.typeParameters, isNull); | 5793 expect(declaration.typeParameters, isNull); |
| 5693 } | 5794 } |
| 5694 | 5795 |
| 5695 void test_parseClassDeclaration_typeAlias_implementsC() { | 5796 void test_parseClassDeclaration_typeAlias_implementsC() { |
| 5696 ClassTypeAlias typeAlias = parse( | 5797 createParser('class A = Object with B implements C;'); |
| 5697 "parseClassDeclaration", | 5798 CompilationUnitMember member = |
| 5698 <Object>[emptyCommentAndMetadata(), null], | 5799 parser.parseClassDeclaration(emptyCommentAndMetadata(), null); |
| 5699 "class A = Object with B implements C;"); | 5800 expectNotNullIfNoErrors(member); |
| 5801 listener.assertNoErrors(); |
| 5802 expect(member, new isInstanceOf<ClassTypeAlias>()); |
| 5803 ClassTypeAlias typeAlias = member; |
| 5700 expect(typeAlias.typedefKeyword, isNotNull); | 5804 expect(typeAlias.typedefKeyword, isNotNull); |
| 5701 expect(typeAlias.name, isNotNull); | 5805 expect(typeAlias.name, isNotNull); |
| 5702 expect(typeAlias.typeParameters, isNull); | 5806 expect(typeAlias.typeParameters, isNull); |
| 5703 expect(typeAlias.withClause, isNotNull); | 5807 expect(typeAlias.withClause, isNotNull); |
| 5704 expect(typeAlias.implementsClause, isNotNull); | 5808 expect(typeAlias.implementsClause, isNotNull); |
| 5705 expect(typeAlias.implementsClause.implementsKeyword, isNotNull); | 5809 expect(typeAlias.implementsClause.implementsKeyword, isNotNull); |
| 5706 expect(typeAlias.implementsClause.interfaces.length, 1); | 5810 expect(typeAlias.implementsClause.interfaces.length, 1); |
| 5707 expect(typeAlias.semicolon, isNotNull); | 5811 expect(typeAlias.semicolon, isNotNull); |
| 5708 } | 5812 } |
| 5709 | 5813 |
| 5710 void test_parseClassDeclaration_typeAlias_withB() { | 5814 void test_parseClassDeclaration_typeAlias_withB() { |
| 5711 ClassTypeAlias typeAlias = parse("parseClassDeclaration", | 5815 createParser('class A = Object with B;'); |
| 5712 <Object>[emptyCommentAndMetadata(), null], "class A = Object with B;"); | 5816 CompilationUnitMember member = |
| 5817 parser.parseClassDeclaration(emptyCommentAndMetadata(), null); |
| 5818 expectNotNullIfNoErrors(member); |
| 5819 listener.assertNoErrors(); |
| 5820 expect(member, new isInstanceOf<ClassTypeAlias>()); |
| 5821 ClassTypeAlias typeAlias = member; |
| 5713 expect(typeAlias.typedefKeyword, isNotNull); | 5822 expect(typeAlias.typedefKeyword, isNotNull); |
| 5714 expect(typeAlias.name, isNotNull); | 5823 expect(typeAlias.name, isNotNull); |
| 5715 expect(typeAlias.typeParameters, isNull); | 5824 expect(typeAlias.typeParameters, isNull); |
| 5716 expect(typeAlias.withClause, isNotNull); | 5825 expect(typeAlias.withClause, isNotNull); |
| 5717 expect(typeAlias.withClause.withKeyword, isNotNull); | 5826 expect(typeAlias.withClause.withKeyword, isNotNull); |
| 5718 expect(typeAlias.withClause.mixinTypes.length, 1); | 5827 expect(typeAlias.withClause.mixinTypes.length, 1); |
| 5719 expect(typeAlias.implementsClause, isNull); | 5828 expect(typeAlias.implementsClause, isNull); |
| 5720 expect(typeAlias.semicolon, isNotNull); | 5829 expect(typeAlias.semicolon, isNotNull); |
| 5721 } | 5830 } |
| 5722 | 5831 |
| 5723 void test_parseClassDeclaration_typeParameters() { | 5832 void test_parseClassDeclaration_typeParameters() { |
| 5724 ClassDeclaration declaration = parse("parseClassDeclaration", | 5833 createParser('class A<B> {}'); |
| 5725 <Object>[emptyCommentAndMetadata(), null], "class A<B> {}"); | 5834 CompilationUnitMember member = |
| 5835 parser.parseClassDeclaration(emptyCommentAndMetadata(), null); |
| 5836 expectNotNullIfNoErrors(member); |
| 5837 listener.assertNoErrors(); |
| 5838 expect(member, new isInstanceOf<ClassDeclaration>()); |
| 5839 ClassDeclaration declaration = member; |
| 5726 expect(declaration.documentationComment, isNull); | 5840 expect(declaration.documentationComment, isNull); |
| 5727 expect(declaration.abstractKeyword, isNull); | 5841 expect(declaration.abstractKeyword, isNull); |
| 5728 expect(declaration.extendsClause, isNull); | 5842 expect(declaration.extendsClause, isNull); |
| 5729 expect(declaration.implementsClause, isNull); | 5843 expect(declaration.implementsClause, isNull); |
| 5730 expect(declaration.classKeyword, isNotNull); | 5844 expect(declaration.classKeyword, isNotNull); |
| 5731 expect(declaration.leftBracket, isNotNull); | 5845 expect(declaration.leftBracket, isNotNull); |
| 5732 expect(declaration.name, isNotNull); | 5846 expect(declaration.name, isNotNull); |
| 5733 expect(declaration.members, hasLength(0)); | 5847 expect(declaration.members, hasLength(0)); |
| 5734 expect(declaration.rightBracket, isNotNull); | 5848 expect(declaration.rightBracket, isNotNull); |
| 5735 expect(declaration.typeParameters, isNotNull); | 5849 expect(declaration.typeParameters, isNotNull); |
| 5736 expect(declaration.typeParameters.typeParameters, hasLength(1)); | 5850 expect(declaration.typeParameters.typeParameters, hasLength(1)); |
| 5737 } | 5851 } |
| 5738 | 5852 |
| 5739 void test_parseClassMember_constructor_withInitializers() { | 5853 void test_parseClassMember_constructor_withInitializers() { |
| 5740 // TODO(brianwilkerson) Test other kinds of class members: fields, getters | 5854 // TODO(brianwilkerson) Test other kinds of class members: fields, getters |
| 5741 // and setters. | 5855 // and setters. |
| 5742 ConstructorDeclaration constructor = parse("parseClassMember", | 5856 createParser('C(_, _\$, this.__) : _a = _ + _\$ {}'); |
| 5743 <Object>["C"], "C(_, _\$, this.__) : _a = _ + _\$ {}"); | 5857 ClassMember member = parser.parseClassMember('C'); |
| 5858 expectNotNullIfNoErrors(member); |
| 5859 listener.assertNoErrors(); |
| 5860 expect(member, new isInstanceOf<ConstructorDeclaration>()); |
| 5861 ConstructorDeclaration constructor = member; |
| 5744 expect(constructor.body, isNotNull); | 5862 expect(constructor.body, isNotNull); |
| 5745 expect(constructor.separator, isNotNull); | 5863 expect(constructor.separator, isNotNull); |
| 5746 expect(constructor.externalKeyword, isNull); | 5864 expect(constructor.externalKeyword, isNull); |
| 5747 expect(constructor.constKeyword, isNull); | 5865 expect(constructor.constKeyword, isNull); |
| 5748 expect(constructor.factoryKeyword, isNull); | 5866 expect(constructor.factoryKeyword, isNull); |
| 5749 expect(constructor.name, isNull); | 5867 expect(constructor.name, isNull); |
| 5750 expect(constructor.parameters, isNotNull); | 5868 expect(constructor.parameters, isNotNull); |
| 5751 expect(constructor.period, isNull); | 5869 expect(constructor.period, isNull); |
| 5752 expect(constructor.returnType, isNotNull); | 5870 expect(constructor.returnType, isNotNull); |
| 5753 expect(constructor.initializers, hasLength(1)); | 5871 expect(constructor.initializers, hasLength(1)); |
| 5754 } | 5872 } |
| 5755 | 5873 |
| 5756 void test_parseClassMember_field_instance_prefixedType() { | 5874 void test_parseClassMember_field_instance_prefixedType() { |
| 5757 FieldDeclaration field = parse("parseClassMember", <Object>["C"], "p.A f;"); | 5875 createParser('p.A f;'); |
| 5876 ClassMember member = parser.parseClassMember('C'); |
| 5877 expectNotNullIfNoErrors(member); |
| 5878 listener.assertNoErrors(); |
| 5879 expect(member, new isInstanceOf<FieldDeclaration>()); |
| 5880 FieldDeclaration field = member; |
| 5758 expect(field.documentationComment, isNull); | 5881 expect(field.documentationComment, isNull); |
| 5759 expect(field.metadata, hasLength(0)); | 5882 expect(field.metadata, hasLength(0)); |
| 5760 expect(field.staticKeyword, isNull); | 5883 expect(field.staticKeyword, isNull); |
| 5761 VariableDeclarationList list = field.fields; | 5884 VariableDeclarationList list = field.fields; |
| 5762 expect(list, isNotNull); | 5885 expect(list, isNotNull); |
| 5763 NodeList<VariableDeclaration> variables = list.variables; | 5886 NodeList<VariableDeclaration> variables = list.variables; |
| 5764 expect(variables, hasLength(1)); | 5887 expect(variables, hasLength(1)); |
| 5765 VariableDeclaration variable = variables[0]; | 5888 VariableDeclaration variable = variables[0]; |
| 5766 expect(variable.name, isNotNull); | 5889 expect(variable.name, isNotNull); |
| 5767 } | 5890 } |
| 5768 | 5891 |
| 5769 void test_parseClassMember_field_namedGet() { | 5892 void test_parseClassMember_field_namedGet() { |
| 5770 FieldDeclaration field = | 5893 createParser('var get;'); |
| 5771 parse("parseClassMember", <Object>["C"], "var get;"); | 5894 ClassMember member = parser.parseClassMember('C'); |
| 5895 expectNotNullIfNoErrors(member); |
| 5896 listener.assertNoErrors(); |
| 5897 expect(member, new isInstanceOf<FieldDeclaration>()); |
| 5898 FieldDeclaration field = member; |
| 5772 expect(field.documentationComment, isNull); | 5899 expect(field.documentationComment, isNull); |
| 5773 expect(field.metadata, hasLength(0)); | 5900 expect(field.metadata, hasLength(0)); |
| 5774 expect(field.staticKeyword, isNull); | 5901 expect(field.staticKeyword, isNull); |
| 5775 VariableDeclarationList list = field.fields; | 5902 VariableDeclarationList list = field.fields; |
| 5776 expect(list, isNotNull); | 5903 expect(list, isNotNull); |
| 5777 NodeList<VariableDeclaration> variables = list.variables; | 5904 NodeList<VariableDeclaration> variables = list.variables; |
| 5778 expect(variables, hasLength(1)); | 5905 expect(variables, hasLength(1)); |
| 5779 VariableDeclaration variable = variables[0]; | 5906 VariableDeclaration variable = variables[0]; |
| 5780 expect(variable.name, isNotNull); | 5907 expect(variable.name, isNotNull); |
| 5781 } | 5908 } |
| 5782 | 5909 |
| 5783 void test_parseClassMember_field_namedOperator() { | 5910 void test_parseClassMember_field_namedOperator() { |
| 5784 FieldDeclaration field = | 5911 createParser('var operator;'); |
| 5785 parse("parseClassMember", <Object>["C"], "var operator;"); | 5912 ClassMember member = parser.parseClassMember('C'); |
| 5913 expectNotNullIfNoErrors(member); |
| 5914 listener.assertNoErrors(); |
| 5915 expect(member, new isInstanceOf<FieldDeclaration>()); |
| 5916 FieldDeclaration field = member; |
| 5786 expect(field.documentationComment, isNull); | 5917 expect(field.documentationComment, isNull); |
| 5787 expect(field.metadata, hasLength(0)); | 5918 expect(field.metadata, hasLength(0)); |
| 5788 expect(field.staticKeyword, isNull); | 5919 expect(field.staticKeyword, isNull); |
| 5789 VariableDeclarationList list = field.fields; | 5920 VariableDeclarationList list = field.fields; |
| 5790 expect(list, isNotNull); | 5921 expect(list, isNotNull); |
| 5791 NodeList<VariableDeclaration> variables = list.variables; | 5922 NodeList<VariableDeclaration> variables = list.variables; |
| 5792 expect(variables, hasLength(1)); | 5923 expect(variables, hasLength(1)); |
| 5793 VariableDeclaration variable = variables[0]; | 5924 VariableDeclaration variable = variables[0]; |
| 5794 expect(variable.name, isNotNull); | 5925 expect(variable.name, isNotNull); |
| 5795 } | 5926 } |
| 5796 | 5927 |
| 5797 void test_parseClassMember_field_namedOperator_withAssignment() { | 5928 void test_parseClassMember_field_namedOperator_withAssignment() { |
| 5798 FieldDeclaration field = | 5929 createParser('var operator = (5);'); |
| 5799 parse("parseClassMember", <Object>["C"], "var operator = (5);"); | 5930 ClassMember member = parser.parseClassMember('C'); |
| 5931 expectNotNullIfNoErrors(member); |
| 5932 listener.assertNoErrors(); |
| 5933 expect(member, new isInstanceOf<FieldDeclaration>()); |
| 5934 FieldDeclaration field = member; |
| 5800 expect(field.documentationComment, isNull); | 5935 expect(field.documentationComment, isNull); |
| 5801 expect(field.metadata, hasLength(0)); | 5936 expect(field.metadata, hasLength(0)); |
| 5802 expect(field.staticKeyword, isNull); | 5937 expect(field.staticKeyword, isNull); |
| 5803 VariableDeclarationList list = field.fields; | 5938 VariableDeclarationList list = field.fields; |
| 5804 expect(list, isNotNull); | 5939 expect(list, isNotNull); |
| 5805 NodeList<VariableDeclaration> variables = list.variables; | 5940 NodeList<VariableDeclaration> variables = list.variables; |
| 5806 expect(variables, hasLength(1)); | 5941 expect(variables, hasLength(1)); |
| 5807 VariableDeclaration variable = variables[0]; | 5942 VariableDeclaration variable = variables[0]; |
| 5808 expect(variable.name, isNotNull); | 5943 expect(variable.name, isNotNull); |
| 5809 expect(variable.initializer, isNotNull); | 5944 expect(variable.initializer, isNotNull); |
| 5810 } | 5945 } |
| 5811 | 5946 |
| 5812 void test_parseClassMember_field_namedSet() { | 5947 void test_parseClassMember_field_namedSet() { |
| 5813 FieldDeclaration field = | 5948 createParser('var set;'); |
| 5814 parse("parseClassMember", <Object>["C"], "var set;"); | 5949 ClassMember member = parser.parseClassMember('C'); |
| 5950 expectNotNullIfNoErrors(member); |
| 5951 listener.assertNoErrors(); |
| 5952 expect(member, new isInstanceOf<FieldDeclaration>()); |
| 5953 FieldDeclaration field = member; |
| 5815 expect(field.documentationComment, isNull); | 5954 expect(field.documentationComment, isNull); |
| 5816 expect(field.metadata, hasLength(0)); | 5955 expect(field.metadata, hasLength(0)); |
| 5817 expect(field.staticKeyword, isNull); | 5956 expect(field.staticKeyword, isNull); |
| 5818 VariableDeclarationList list = field.fields; | 5957 VariableDeclarationList list = field.fields; |
| 5819 expect(list, isNotNull); | 5958 expect(list, isNotNull); |
| 5820 NodeList<VariableDeclaration> variables = list.variables; | 5959 NodeList<VariableDeclaration> variables = list.variables; |
| 5821 expect(variables, hasLength(1)); | 5960 expect(variables, hasLength(1)); |
| 5822 VariableDeclaration variable = variables[0]; | 5961 VariableDeclaration variable = variables[0]; |
| 5823 expect(variable.name, isNotNull); | 5962 expect(variable.name, isNotNull); |
| 5824 } | 5963 } |
| 5825 | 5964 |
| 5826 void test_parseClassMember_getter_void() { | 5965 void test_parseClassMember_getter_void() { |
| 5827 MethodDeclaration method = | 5966 createParser('void get g {}'); |
| 5828 parse("parseClassMember", <Object>["C"], "void get g {}"); | 5967 ClassMember member = parser.parseClassMember('C'); |
| 5968 expectNotNullIfNoErrors(member); |
| 5969 listener.assertNoErrors(); |
| 5970 expect(member, new isInstanceOf<MethodDeclaration>()); |
| 5971 MethodDeclaration method = member; |
| 5829 expect(method.documentationComment, isNull); | 5972 expect(method.documentationComment, isNull); |
| 5830 expect(method.externalKeyword, isNull); | 5973 expect(method.externalKeyword, isNull); |
| 5831 expect(method.modifierKeyword, isNull); | 5974 expect(method.modifierKeyword, isNull); |
| 5832 expect(method.propertyKeyword, isNotNull); | 5975 expect(method.propertyKeyword, isNotNull); |
| 5833 expect(method.returnType, isNotNull); | 5976 expect(method.returnType, isNotNull); |
| 5834 expect(method.name, isNotNull); | 5977 expect(method.name, isNotNull); |
| 5835 expect(method.operatorKeyword, isNull); | 5978 expect(method.operatorKeyword, isNull); |
| 5836 expect(method.body, isNotNull); | 5979 expect(method.body, isNotNull); |
| 5837 expect(method.parameters, isNull); | 5980 expect(method.parameters, isNull); |
| 5838 } | 5981 } |
| 5839 | 5982 |
| 5840 void test_parseClassMember_method_external() { | 5983 void test_parseClassMember_method_external() { |
| 5841 MethodDeclaration method = | 5984 createParser('external m();'); |
| 5842 parse("parseClassMember", <Object>["C"], "external m();"); | 5985 ClassMember member = parser.parseClassMember('C'); |
| 5986 expectNotNullIfNoErrors(member); |
| 5987 listener.assertNoErrors(); |
| 5988 expect(member, new isInstanceOf<MethodDeclaration>()); |
| 5989 MethodDeclaration method = member; |
| 5843 expect(method.body, isNotNull); | 5990 expect(method.body, isNotNull); |
| 5844 expect(method.documentationComment, isNull); | 5991 expect(method.documentationComment, isNull); |
| 5845 expect(method.externalKeyword, isNotNull); | 5992 expect(method.externalKeyword, isNotNull); |
| 5846 expect(method.modifierKeyword, isNull); | 5993 expect(method.modifierKeyword, isNull); |
| 5847 expect(method.name, isNotNull); | 5994 expect(method.name, isNotNull); |
| 5848 expect(method.operatorKeyword, isNull); | 5995 expect(method.operatorKeyword, isNull); |
| 5849 expect(method.typeParameters, isNull); | 5996 expect(method.typeParameters, isNull); |
| 5850 expect(method.parameters, isNotNull); | 5997 expect(method.parameters, isNotNull); |
| 5851 expect(method.propertyKeyword, isNull); | 5998 expect(method.propertyKeyword, isNull); |
| 5852 expect(method.returnType, isNull); | 5999 expect(method.returnType, isNull); |
| 5853 } | 6000 } |
| 5854 | 6001 |
| 5855 void test_parseClassMember_method_external_withTypeAndArgs() { | 6002 void test_parseClassMember_method_external_withTypeAndArgs() { |
| 5856 MethodDeclaration method = | 6003 createParser('external int m(int a);'); |
| 5857 parse("parseClassMember", <Object>["C"], "external int m(int a);"); | 6004 ClassMember member = parser.parseClassMember('C'); |
| 6005 expectNotNullIfNoErrors(member); |
| 6006 listener.assertNoErrors(); |
| 6007 expect(member, new isInstanceOf<MethodDeclaration>()); |
| 6008 MethodDeclaration method = member; |
| 5858 expect(method.body, isNotNull); | 6009 expect(method.body, isNotNull); |
| 5859 expect(method.documentationComment, isNull); | 6010 expect(method.documentationComment, isNull); |
| 5860 expect(method.externalKeyword, isNotNull); | 6011 expect(method.externalKeyword, isNotNull); |
| 5861 expect(method.modifierKeyword, isNull); | 6012 expect(method.modifierKeyword, isNull); |
| 5862 expect(method.name, isNotNull); | 6013 expect(method.name, isNotNull); |
| 5863 expect(method.operatorKeyword, isNull); | 6014 expect(method.operatorKeyword, isNull); |
| 5864 expect(method.typeParameters, isNull); | 6015 expect(method.typeParameters, isNull); |
| 5865 expect(method.parameters, isNotNull); | 6016 expect(method.parameters, isNotNull); |
| 5866 expect(method.propertyKeyword, isNull); | 6017 expect(method.propertyKeyword, isNull); |
| 5867 expect(method.returnType, isNotNull); | 6018 expect(method.returnType, isNotNull); |
| 5868 } | 6019 } |
| 5869 | 6020 |
| 6021 void test_parseClassMember_method_generic_comment_noReturnType() { |
| 6022 enableGenericMethodComments = true; |
| 6023 createParser('m/*<T>*/() {}'); |
| 6024 ClassMember member = parser.parseClassMember('C'); |
| 6025 expectNotNullIfNoErrors(member); |
| 6026 listener.assertNoErrors(); |
| 6027 expect(member, new isInstanceOf<MethodDeclaration>()); |
| 6028 MethodDeclaration method = member; |
| 6029 expect(method.documentationComment, isNull); |
| 6030 expect(method.externalKeyword, isNull); |
| 6031 expect(method.modifierKeyword, isNull); |
| 6032 expect(method.propertyKeyword, isNull); |
| 6033 expect(method.returnType, isNull); |
| 6034 expect(method.name, isNotNull); |
| 6035 expect(method.operatorKeyword, isNull); |
| 6036 expect(method.typeParameters, isNotNull); |
| 6037 expect(method.parameters, isNotNull); |
| 6038 expect(method.body, isNotNull); |
| 6039 } |
| 6040 |
| 6041 void test_parseClassMember_method_generic_comment_returnType() { |
| 6042 enableGenericMethodComments = true; |
| 6043 createParser('/*=T*/ m/*<T>*/() {}'); |
| 6044 ClassMember member = parser.parseClassMember('C'); |
| 6045 expectNotNullIfNoErrors(member); |
| 6046 listener.assertNoErrors(); |
| 6047 expect(member, new isInstanceOf<MethodDeclaration>()); |
| 6048 MethodDeclaration method = member; |
| 6049 expect(method.documentationComment, isNull); |
| 6050 expect(method.externalKeyword, isNull); |
| 6051 expect(method.modifierKeyword, isNull); |
| 6052 expect(method.propertyKeyword, isNull); |
| 6053 expect(method.returnType.name.name, 'T'); |
| 6054 expect(method.name, isNotNull); |
| 6055 expect(method.operatorKeyword, isNull); |
| 6056 expect(method.typeParameters, isNotNull); |
| 6057 expect(method.parameters, isNotNull); |
| 6058 expect(method.body, isNotNull); |
| 6059 } |
| 6060 |
| 6061 void test_parseClassMember_method_generic_comment_returnType_bound() { |
| 6062 enableGenericMethodComments = true; |
| 6063 createParser('num/*=T*/ m/*<T extends num>*/() {}'); |
| 6064 ClassMember member = parser.parseClassMember('C'); |
| 6065 expectNotNullIfNoErrors(member); |
| 6066 listener.assertNoErrors(); |
| 6067 expect(member, new isInstanceOf<MethodDeclaration>()); |
| 6068 MethodDeclaration method = member; |
| 6069 expect(method.documentationComment, isNull); |
| 6070 expect(method.externalKeyword, isNull); |
| 6071 expect(method.modifierKeyword, isNull); |
| 6072 expect(method.propertyKeyword, isNull); |
| 6073 expect(method.returnType.name.name, 'T'); |
| 6074 expect(method.name, isNotNull); |
| 6075 expect(method.operatorKeyword, isNull); |
| 6076 expect(method.typeParameters, isNotNull); |
| 6077 TypeParameter tp = method.typeParameters.typeParameters[0]; |
| 6078 expect(tp.name.name, 'T'); |
| 6079 expect(tp.extendsKeyword, isNotNull); |
| 6080 expect(tp.bound.name.name, 'num'); |
| 6081 expect(method.parameters, isNotNull); |
| 6082 expect(method.body, isNotNull); |
| 6083 } |
| 6084 |
| 6085 void test_parseClassMember_method_generic_comment_void() { |
| 6086 enableGenericMethodComments = true; |
| 6087 createParser('void m/*<T>*/() {}'); |
| 6088 ClassMember member = parser.parseClassMember('C'); |
| 6089 expectNotNullIfNoErrors(member); |
| 6090 listener.assertNoErrors(); |
| 6091 expect(member, new isInstanceOf<MethodDeclaration>()); |
| 6092 MethodDeclaration method = member; |
| 6093 expect(method.documentationComment, isNull); |
| 6094 expect(method.externalKeyword, isNull); |
| 6095 expect(method.modifierKeyword, isNull); |
| 6096 expect(method.propertyKeyword, isNull); |
| 6097 expect(method.returnType, isNotNull); |
| 6098 expect(method.name, isNotNull); |
| 6099 expect(method.operatorKeyword, isNull); |
| 6100 expect(method.typeParameters, isNotNull); |
| 6101 expect(method.parameters, isNotNull); |
| 6102 expect(method.body, isNotNull); |
| 6103 } |
| 6104 |
| 5870 void test_parseClassMember_method_generic_noReturnType() { | 6105 void test_parseClassMember_method_generic_noReturnType() { |
| 5871 enableGenericMethods = true; | 6106 enableGenericMethods = true; |
| 5872 MethodDeclaration method = | 6107 createParser('m<T>() {}'); |
| 5873 parse("parseClassMember", <Object>["C"], "m<T>() {}"); | 6108 ClassMember member = parser.parseClassMember('C'); |
| 6109 expectNotNullIfNoErrors(member); |
| 6110 listener.assertNoErrors(); |
| 6111 expect(member, new isInstanceOf<MethodDeclaration>()); |
| 6112 MethodDeclaration method = member; |
| 5874 expect(method.documentationComment, isNull); | 6113 expect(method.documentationComment, isNull); |
| 5875 expect(method.externalKeyword, isNull); | 6114 expect(method.externalKeyword, isNull); |
| 5876 expect(method.modifierKeyword, isNull); | 6115 expect(method.modifierKeyword, isNull); |
| 5877 expect(method.propertyKeyword, isNull); | 6116 expect(method.propertyKeyword, isNull); |
| 5878 expect(method.returnType, isNull); | 6117 expect(method.returnType, isNull); |
| 5879 expect(method.name, isNotNull); | 6118 expect(method.name, isNotNull); |
| 5880 expect(method.operatorKeyword, isNull); | 6119 expect(method.operatorKeyword, isNull); |
| 5881 expect(method.typeParameters, isNotNull); | 6120 expect(method.typeParameters, isNotNull); |
| 5882 expect(method.parameters, isNotNull); | 6121 expect(method.parameters, isNotNull); |
| 5883 expect(method.body, isNotNull); | 6122 expect(method.body, isNotNull); |
| 5884 } | 6123 } |
| 5885 | 6124 |
| 5886 void test_parseClassMember_method_generic_returnType() { | 6125 void test_parseClassMember_method_generic_returnType() { |
| 5887 enableGenericMethods = true; | 6126 enableGenericMethods = true; |
| 5888 MethodDeclaration method = | 6127 createParser('T m<T>() {}'); |
| 5889 parse("parseClassMember", <Object>["C"], "T m<T>() {}"); | 6128 ClassMember member = parser.parseClassMember('C'); |
| 6129 expectNotNullIfNoErrors(member); |
| 6130 listener.assertNoErrors(); |
| 6131 expect(member, new isInstanceOf<MethodDeclaration>()); |
| 6132 MethodDeclaration method = member; |
| 5890 expect(method.documentationComment, isNull); | 6133 expect(method.documentationComment, isNull); |
| 5891 expect(method.externalKeyword, isNull); | 6134 expect(method.externalKeyword, isNull); |
| 5892 expect(method.modifierKeyword, isNull); | 6135 expect(method.modifierKeyword, isNull); |
| 5893 expect(method.propertyKeyword, isNull); | 6136 expect(method.propertyKeyword, isNull); |
| 5894 expect(method.returnType, isNotNull); | 6137 expect(method.returnType, isNotNull); |
| 5895 expect(method.name, isNotNull); | 6138 expect(method.name, isNotNull); |
| 5896 expect(method.operatorKeyword, isNull); | 6139 expect(method.operatorKeyword, isNull); |
| 5897 expect(method.typeParameters, isNotNull); | 6140 expect(method.typeParameters, isNotNull); |
| 5898 expect(method.parameters, isNotNull); | 6141 expect(method.parameters, isNotNull); |
| 5899 expect(method.body, isNotNull); | 6142 expect(method.body, isNotNull); |
| 5900 } | 6143 } |
| 5901 | 6144 |
| 5902 void test_parseClassMember_method_generic_void() { | 6145 void test_parseClassMember_method_generic_void() { |
| 5903 enableGenericMethods = true; | 6146 enableGenericMethods = true; |
| 5904 MethodDeclaration method = | 6147 createParser('void m<T>() {}'); |
| 5905 parse("parseClassMember", <Object>["C"], "void m<T>() {}"); | 6148 ClassMember member = parser.parseClassMember('C'); |
| 6149 expectNotNullIfNoErrors(member); |
| 6150 listener.assertNoErrors(); |
| 6151 expect(member, new isInstanceOf<MethodDeclaration>()); |
| 6152 MethodDeclaration method = member; |
| 5906 expect(method.documentationComment, isNull); | 6153 expect(method.documentationComment, isNull); |
| 5907 expect(method.externalKeyword, isNull); | 6154 expect(method.externalKeyword, isNull); |
| 5908 expect(method.modifierKeyword, isNull); | 6155 expect(method.modifierKeyword, isNull); |
| 5909 expect(method.propertyKeyword, isNull); | 6156 expect(method.propertyKeyword, isNull); |
| 5910 expect(method.returnType, isNotNull); | 6157 expect(method.returnType, isNotNull); |
| 5911 expect(method.name, isNotNull); | 6158 expect(method.name, isNotNull); |
| 5912 expect(method.operatorKeyword, isNull); | 6159 expect(method.operatorKeyword, isNull); |
| 5913 expect(method.typeParameters, isNotNull); | 6160 expect(method.typeParameters, isNotNull); |
| 5914 expect(method.parameters, isNotNull); | 6161 expect(method.parameters, isNotNull); |
| 5915 expect(method.body, isNotNull); | 6162 expect(method.body, isNotNull); |
| 5916 } | 6163 } |
| 5917 | 6164 |
| 5918 void test_parseClassMember_method_get_noType() { | 6165 void test_parseClassMember_method_get_noType() { |
| 5919 MethodDeclaration method = | 6166 createParser('get() {}'); |
| 5920 parse("parseClassMember", <Object>["C"], "get() {}"); | 6167 ClassMember member = parser.parseClassMember('C'); |
| 6168 expectNotNullIfNoErrors(member); |
| 6169 listener.assertNoErrors(); |
| 6170 expect(member, new isInstanceOf<MethodDeclaration>()); |
| 6171 MethodDeclaration method = member; |
| 5921 expect(method.documentationComment, isNull); | 6172 expect(method.documentationComment, isNull); |
| 5922 expect(method.externalKeyword, isNull); | 6173 expect(method.externalKeyword, isNull); |
| 5923 expect(method.modifierKeyword, isNull); | 6174 expect(method.modifierKeyword, isNull); |
| 5924 expect(method.propertyKeyword, isNull); | 6175 expect(method.propertyKeyword, isNull); |
| 5925 expect(method.returnType, isNull); | 6176 expect(method.returnType, isNull); |
| 5926 expect(method.name, isNotNull); | 6177 expect(method.name, isNotNull); |
| 5927 expect(method.operatorKeyword, isNull); | 6178 expect(method.operatorKeyword, isNull); |
| 5928 expect(method.typeParameters, isNull); | 6179 expect(method.typeParameters, isNull); |
| 5929 expect(method.parameters, isNotNull); | 6180 expect(method.parameters, isNotNull); |
| 5930 expect(method.body, isNotNull); | 6181 expect(method.body, isNotNull); |
| 5931 } | 6182 } |
| 5932 | 6183 |
| 5933 void test_parseClassMember_method_get_type() { | 6184 void test_parseClassMember_method_get_type() { |
| 5934 MethodDeclaration method = | 6185 createParser('int get() {}'); |
| 5935 parse("parseClassMember", <Object>["C"], "int get() {}"); | 6186 ClassMember member = parser.parseClassMember('C'); |
| 6187 expectNotNullIfNoErrors(member); |
| 6188 listener.assertNoErrors(); |
| 6189 expect(member, new isInstanceOf<MethodDeclaration>()); |
| 6190 MethodDeclaration method = member; |
| 5936 expect(method.documentationComment, isNull); | 6191 expect(method.documentationComment, isNull); |
| 5937 expect(method.externalKeyword, isNull); | 6192 expect(method.externalKeyword, isNull); |
| 5938 expect(method.modifierKeyword, isNull); | 6193 expect(method.modifierKeyword, isNull); |
| 5939 expect(method.propertyKeyword, isNull); | 6194 expect(method.propertyKeyword, isNull); |
| 5940 expect(method.returnType, isNotNull); | 6195 expect(method.returnType, isNotNull); |
| 5941 expect(method.name, isNotNull); | 6196 expect(method.name, isNotNull); |
| 5942 expect(method.operatorKeyword, isNull); | 6197 expect(method.operatorKeyword, isNull); |
| 5943 expect(method.typeParameters, isNull); | 6198 expect(method.typeParameters, isNull); |
| 5944 expect(method.parameters, isNotNull); | 6199 expect(method.parameters, isNotNull); |
| 5945 expect(method.body, isNotNull); | 6200 expect(method.body, isNotNull); |
| 5946 } | 6201 } |
| 5947 | 6202 |
| 5948 void test_parseClassMember_method_get_void() { | 6203 void test_parseClassMember_method_get_void() { |
| 5949 MethodDeclaration method = | 6204 createParser('void get() {}'); |
| 5950 parse("parseClassMember", <Object>["C"], "void get() {}"); | 6205 ClassMember member = parser.parseClassMember('C'); |
| 6206 expectNotNullIfNoErrors(member); |
| 6207 listener.assertNoErrors(); |
| 6208 expect(member, new isInstanceOf<MethodDeclaration>()); |
| 6209 MethodDeclaration method = member; |
| 5951 expect(method.documentationComment, isNull); | 6210 expect(method.documentationComment, isNull); |
| 5952 expect(method.externalKeyword, isNull); | 6211 expect(method.externalKeyword, isNull); |
| 5953 expect(method.modifierKeyword, isNull); | 6212 expect(method.modifierKeyword, isNull); |
| 5954 expect(method.propertyKeyword, isNull); | 6213 expect(method.propertyKeyword, isNull); |
| 5955 expect(method.returnType, isNotNull); | 6214 expect(method.returnType, isNotNull); |
| 5956 expect(method.name, isNotNull); | 6215 expect(method.name, isNotNull); |
| 5957 expect(method.operatorKeyword, isNull); | 6216 expect(method.operatorKeyword, isNull); |
| 5958 expect(method.typeParameters, isNull); | 6217 expect(method.typeParameters, isNull); |
| 5959 expect(method.parameters, isNotNull); | 6218 expect(method.parameters, isNotNull); |
| 5960 expect(method.body, isNotNull); | 6219 expect(method.body, isNotNull); |
| 5961 } | 6220 } |
| 5962 | 6221 |
| 5963 void test_parseClassMember_method_operator_noType() { | 6222 void test_parseClassMember_method_operator_noType() { |
| 5964 MethodDeclaration method = | 6223 createParser('operator() {}'); |
| 5965 parse("parseClassMember", <Object>["C"], "operator() {}"); | 6224 ClassMember member = parser.parseClassMember('C'); |
| 6225 expectNotNullIfNoErrors(member); |
| 6226 listener.assertNoErrors(); |
| 6227 expect(member, new isInstanceOf<MethodDeclaration>()); |
| 6228 MethodDeclaration method = member; |
| 5966 expect(method.documentationComment, isNull); | 6229 expect(method.documentationComment, isNull); |
| 5967 expect(method.externalKeyword, isNull); | 6230 expect(method.externalKeyword, isNull); |
| 5968 expect(method.modifierKeyword, isNull); | 6231 expect(method.modifierKeyword, isNull); |
| 5969 expect(method.propertyKeyword, isNull); | 6232 expect(method.propertyKeyword, isNull); |
| 5970 expect(method.returnType, isNull); | 6233 expect(method.returnType, isNull); |
| 5971 expect(method.name, isNotNull); | 6234 expect(method.name, isNotNull); |
| 5972 expect(method.operatorKeyword, isNull); | 6235 expect(method.operatorKeyword, isNull); |
| 5973 expect(method.typeParameters, isNull); | 6236 expect(method.typeParameters, isNull); |
| 5974 expect(method.parameters, isNotNull); | 6237 expect(method.parameters, isNotNull); |
| 5975 expect(method.body, isNotNull); | 6238 expect(method.body, isNotNull); |
| 5976 } | 6239 } |
| 5977 | 6240 |
| 5978 void test_parseClassMember_method_operator_type() { | 6241 void test_parseClassMember_method_operator_type() { |
| 5979 MethodDeclaration method = | 6242 createParser('int operator() {}'); |
| 5980 parse("parseClassMember", <Object>["C"], "int operator() {}"); | 6243 ClassMember member = parser.parseClassMember('C'); |
| 6244 expectNotNullIfNoErrors(member); |
| 6245 listener.assertNoErrors(); |
| 6246 expect(member, new isInstanceOf<MethodDeclaration>()); |
| 6247 MethodDeclaration method = member; |
| 5981 expect(method.documentationComment, isNull); | 6248 expect(method.documentationComment, isNull); |
| 5982 expect(method.externalKeyword, isNull); | 6249 expect(method.externalKeyword, isNull); |
| 5983 expect(method.modifierKeyword, isNull); | 6250 expect(method.modifierKeyword, isNull); |
| 5984 expect(method.propertyKeyword, isNull); | 6251 expect(method.propertyKeyword, isNull); |
| 5985 expect(method.returnType, isNotNull); | 6252 expect(method.returnType, isNotNull); |
| 5986 expect(method.name, isNotNull); | 6253 expect(method.name, isNotNull); |
| 5987 expect(method.operatorKeyword, isNull); | 6254 expect(method.operatorKeyword, isNull); |
| 5988 expect(method.typeParameters, isNull); | 6255 expect(method.typeParameters, isNull); |
| 5989 expect(method.parameters, isNotNull); | 6256 expect(method.parameters, isNotNull); |
| 5990 expect(method.body, isNotNull); | 6257 expect(method.body, isNotNull); |
| 5991 } | 6258 } |
| 5992 | 6259 |
| 5993 void test_parseClassMember_method_operator_void() { | 6260 void test_parseClassMember_method_operator_void() { |
| 5994 MethodDeclaration method = | 6261 createParser('void operator() {}'); |
| 5995 parse("parseClassMember", <Object>["C"], "void operator() {}"); | 6262 ClassMember member = parser.parseClassMember('C'); |
| 6263 expectNotNullIfNoErrors(member); |
| 6264 listener.assertNoErrors(); |
| 6265 expect(member, new isInstanceOf<MethodDeclaration>()); |
| 6266 MethodDeclaration method = member; |
| 5996 expect(method.documentationComment, isNull); | 6267 expect(method.documentationComment, isNull); |
| 5997 expect(method.externalKeyword, isNull); | 6268 expect(method.externalKeyword, isNull); |
| 5998 expect(method.modifierKeyword, isNull); | 6269 expect(method.modifierKeyword, isNull); |
| 5999 expect(method.propertyKeyword, isNull); | 6270 expect(method.propertyKeyword, isNull); |
| 6000 expect(method.returnType, isNotNull); | 6271 expect(method.returnType, isNotNull); |
| 6001 expect(method.name, isNotNull); | 6272 expect(method.name, isNotNull); |
| 6002 expect(method.operatorKeyword, isNull); | 6273 expect(method.operatorKeyword, isNull); |
| 6003 expect(method.typeParameters, isNull); | 6274 expect(method.typeParameters, isNull); |
| 6004 expect(method.parameters, isNotNull); | 6275 expect(method.parameters, isNotNull); |
| 6005 expect(method.body, isNotNull); | 6276 expect(method.body, isNotNull); |
| 6006 } | 6277 } |
| 6007 | 6278 |
| 6008 void test_parseClassMember_method_returnType_parameterized() { | 6279 void test_parseClassMember_method_returnType_parameterized() { |
| 6009 MethodDeclaration method = | 6280 createParser('p.A m() {}'); |
| 6010 parse("parseClassMember", <Object>["C"], "p.A m() {}"); | 6281 ClassMember member = parser.parseClassMember('C'); |
| 6282 expectNotNullIfNoErrors(member); |
| 6283 listener.assertNoErrors(); |
| 6284 expect(member, new isInstanceOf<MethodDeclaration>()); |
| 6285 MethodDeclaration method = member; |
| 6011 expect(method.documentationComment, isNull); | 6286 expect(method.documentationComment, isNull); |
| 6012 expect(method.externalKeyword, isNull); | 6287 expect(method.externalKeyword, isNull); |
| 6013 expect(method.modifierKeyword, isNull); | 6288 expect(method.modifierKeyword, isNull); |
| 6014 expect(method.propertyKeyword, isNull); | 6289 expect(method.propertyKeyword, isNull); |
| 6015 expect(method.returnType, isNotNull); | 6290 expect(method.returnType, isNotNull); |
| 6016 expect(method.name, isNotNull); | 6291 expect(method.name, isNotNull); |
| 6017 expect(method.operatorKeyword, isNull); | 6292 expect(method.operatorKeyword, isNull); |
| 6018 expect(method.typeParameters, isNull); | 6293 expect(method.typeParameters, isNull); |
| 6019 expect(method.parameters, isNotNull); | 6294 expect(method.parameters, isNotNull); |
| 6020 expect(method.body, isNotNull); | 6295 expect(method.body, isNotNull); |
| 6021 } | 6296 } |
| 6022 | 6297 |
| 6023 void test_parseClassMember_method_set_noType() { | 6298 void test_parseClassMember_method_set_noType() { |
| 6024 MethodDeclaration method = | 6299 createParser('set() {}'); |
| 6025 parse("parseClassMember", <Object>["C"], "set() {}"); | 6300 ClassMember member = parser.parseClassMember('C'); |
| 6301 expectNotNullIfNoErrors(member); |
| 6302 listener.assertNoErrors(); |
| 6303 expect(member, new isInstanceOf<MethodDeclaration>()); |
| 6304 MethodDeclaration method = member; |
| 6026 expect(method.documentationComment, isNull); | 6305 expect(method.documentationComment, isNull); |
| 6027 expect(method.externalKeyword, isNull); | 6306 expect(method.externalKeyword, isNull); |
| 6028 expect(method.modifierKeyword, isNull); | 6307 expect(method.modifierKeyword, isNull); |
| 6029 expect(method.propertyKeyword, isNull); | 6308 expect(method.propertyKeyword, isNull); |
| 6030 expect(method.returnType, isNull); | 6309 expect(method.returnType, isNull); |
| 6031 expect(method.name, isNotNull); | 6310 expect(method.name, isNotNull); |
| 6032 expect(method.operatorKeyword, isNull); | 6311 expect(method.operatorKeyword, isNull); |
| 6033 expect(method.typeParameters, isNull); | 6312 expect(method.typeParameters, isNull); |
| 6034 expect(method.parameters, isNotNull); | 6313 expect(method.parameters, isNotNull); |
| 6035 expect(method.body, isNotNull); | 6314 expect(method.body, isNotNull); |
| 6036 } | 6315 } |
| 6037 | 6316 |
| 6038 void test_parseClassMember_method_set_type() { | 6317 void test_parseClassMember_method_set_type() { |
| 6039 MethodDeclaration method = | 6318 createParser('int set() {}'); |
| 6040 parse("parseClassMember", <Object>["C"], "int set() {}"); | 6319 ClassMember member = parser.parseClassMember('C'); |
| 6320 expectNotNullIfNoErrors(member); |
| 6321 listener.assertNoErrors(); |
| 6322 expect(member, new isInstanceOf<MethodDeclaration>()); |
| 6323 MethodDeclaration method = member; |
| 6041 expect(method.documentationComment, isNull); | 6324 expect(method.documentationComment, isNull); |
| 6042 expect(method.externalKeyword, isNull); | 6325 expect(method.externalKeyword, isNull); |
| 6043 expect(method.modifierKeyword, isNull); | 6326 expect(method.modifierKeyword, isNull); |
| 6044 expect(method.propertyKeyword, isNull); | 6327 expect(method.propertyKeyword, isNull); |
| 6045 expect(method.returnType, isNotNull); | 6328 expect(method.returnType, isNotNull); |
| 6046 expect(method.name, isNotNull); | 6329 expect(method.name, isNotNull); |
| 6047 expect(method.operatorKeyword, isNull); | 6330 expect(method.operatorKeyword, isNull); |
| 6048 expect(method.typeParameters, isNull); | 6331 expect(method.typeParameters, isNull); |
| 6049 expect(method.parameters, isNotNull); | 6332 expect(method.parameters, isNotNull); |
| 6050 expect(method.body, isNotNull); | 6333 expect(method.body, isNotNull); |
| 6051 } | 6334 } |
| 6052 | 6335 |
| 6053 void test_parseClassMember_method_set_void() { | 6336 void test_parseClassMember_method_set_void() { |
| 6054 MethodDeclaration method = | 6337 createParser('void set() {}'); |
| 6055 parse("parseClassMember", <Object>["C"], "void set() {}"); | 6338 ClassMember member = parser.parseClassMember('C'); |
| 6339 expectNotNullIfNoErrors(member); |
| 6340 listener.assertNoErrors(); |
| 6341 expect(member, new isInstanceOf<MethodDeclaration>()); |
| 6342 MethodDeclaration method = member; |
| 6056 expect(method.documentationComment, isNull); | 6343 expect(method.documentationComment, isNull); |
| 6057 expect(method.externalKeyword, isNull); | 6344 expect(method.externalKeyword, isNull); |
| 6058 expect(method.modifierKeyword, isNull); | 6345 expect(method.modifierKeyword, isNull); |
| 6346 expect(method.propertyKeyword, isNull); |
| 6347 expect(method.returnType, isNotNull); |
| 6348 expect(method.name, isNotNull); |
| 6349 expect(method.operatorKeyword, isNull); |
| 6350 expect(method.typeParameters, isNull); |
| 6351 expect(method.parameters, isNotNull); |
| 6352 expect(method.body, isNotNull); |
| 6353 } |
| 6354 |
| 6355 void test_parseClassMember_method_trailing_commas() { |
| 6356 createParser('void f(int x, int y,) {}'); |
| 6357 ClassMember member = parser.parseClassMember('C'); |
| 6358 expectNotNullIfNoErrors(member); |
| 6359 listener.assertNoErrors(); |
| 6360 expect(member, new isInstanceOf<MethodDeclaration>()); |
| 6361 MethodDeclaration method = member; |
| 6362 expect(method.documentationComment, isNull); |
| 6363 expect(method.externalKeyword, isNull); |
| 6364 expect(method.modifierKeyword, isNull); |
| 6059 expect(method.propertyKeyword, isNull); | 6365 expect(method.propertyKeyword, isNull); |
| 6060 expect(method.returnType, isNotNull); | 6366 expect(method.returnType, isNotNull); |
| 6061 expect(method.name, isNotNull); | 6367 expect(method.name, isNotNull); |
| 6062 expect(method.operatorKeyword, isNull); | 6368 expect(method.operatorKeyword, isNull); |
| 6063 expect(method.typeParameters, isNull); | 6369 expect(method.typeParameters, isNull); |
| 6064 expect(method.parameters, isNotNull); | 6370 expect(method.parameters, isNotNull); |
| 6065 expect(method.body, isNotNull); | 6371 expect(method.body, isNotNull); |
| 6066 } | 6372 } |
| 6067 | 6373 |
| 6068 void test_parseClassMember_operator_index() { | 6374 void test_parseClassMember_operator_index() { |
| 6069 MethodDeclaration method = | 6375 createParser('int operator [](int i) {}'); |
| 6070 parse("parseClassMember", <Object>["C"], "int operator [](int i) {}"); | 6376 ClassMember member = parser.parseClassMember('C'); |
| 6377 expectNotNullIfNoErrors(member); |
| 6378 listener.assertNoErrors(); |
| 6379 expect(member, new isInstanceOf<MethodDeclaration>()); |
| 6380 MethodDeclaration method = member; |
| 6071 expect(method.documentationComment, isNull); | 6381 expect(method.documentationComment, isNull); |
| 6072 expect(method.externalKeyword, isNull); | 6382 expect(method.externalKeyword, isNull); |
| 6073 expect(method.modifierKeyword, isNull); | 6383 expect(method.modifierKeyword, isNull); |
| 6074 expect(method.propertyKeyword, isNull); | 6384 expect(method.propertyKeyword, isNull); |
| 6075 expect(method.returnType, isNotNull); | 6385 expect(method.returnType, isNotNull); |
| 6076 expect(method.name, isNotNull); | 6386 expect(method.name, isNotNull); |
| 6077 expect(method.operatorKeyword, isNotNull); | 6387 expect(method.operatorKeyword, isNotNull); |
| 6078 expect(method.typeParameters, isNull); | 6388 expect(method.typeParameters, isNull); |
| 6079 expect(method.parameters, isNotNull); | 6389 expect(method.parameters, isNotNull); |
| 6080 expect(method.body, isNotNull); | 6390 expect(method.body, isNotNull); |
| 6081 } | 6391 } |
| 6082 | 6392 |
| 6083 void test_parseClassMember_operator_indexAssign() { | 6393 void test_parseClassMember_operator_indexAssign() { |
| 6084 MethodDeclaration method = | 6394 createParser('int operator []=(int i) {}'); |
| 6085 parse("parseClassMember", <Object>["C"], "int operator []=(int i) {}"); | 6395 ClassMember member = parser.parseClassMember('C'); |
| 6396 expectNotNullIfNoErrors(member); |
| 6397 listener.assertNoErrors(); |
| 6398 expect(member, new isInstanceOf<MethodDeclaration>()); |
| 6399 MethodDeclaration method = member; |
| 6086 expect(method.documentationComment, isNull); | 6400 expect(method.documentationComment, isNull); |
| 6087 expect(method.externalKeyword, isNull); | 6401 expect(method.externalKeyword, isNull); |
| 6088 expect(method.modifierKeyword, isNull); | 6402 expect(method.modifierKeyword, isNull); |
| 6089 expect(method.propertyKeyword, isNull); | 6403 expect(method.propertyKeyword, isNull); |
| 6090 expect(method.returnType, isNotNull); | 6404 expect(method.returnType, isNotNull); |
| 6091 expect(method.name, isNotNull); | 6405 expect(method.name, isNotNull); |
| 6092 expect(method.operatorKeyword, isNotNull); | 6406 expect(method.operatorKeyword, isNotNull); |
| 6093 expect(method.typeParameters, isNull); | 6407 expect(method.typeParameters, isNull); |
| 6094 expect(method.parameters, isNotNull); | 6408 expect(method.parameters, isNotNull); |
| 6095 expect(method.body, isNotNull); | 6409 expect(method.body, isNotNull); |
| 6096 } | 6410 } |
| 6097 | 6411 |
| 6098 void test_parseClassMember_redirectingFactory_const() { | 6412 void test_parseClassMember_redirectingFactory_const() { |
| 6099 ConstructorDeclaration constructor = | 6413 createParser('const factory C() = B;'); |
| 6100 parse("parseClassMember", <Object>["C"], "const factory C() = B;"); | 6414 ClassMember member = parser.parseClassMember('C'); |
| 6415 expectNotNullIfNoErrors(member); |
| 6416 listener.assertNoErrors(); |
| 6417 expect(member, new isInstanceOf<ConstructorDeclaration>()); |
| 6418 ConstructorDeclaration constructor = member; |
| 6101 expect(constructor.externalKeyword, isNull); | 6419 expect(constructor.externalKeyword, isNull); |
| 6102 expect(constructor.constKeyword, isNotNull); | 6420 expect(constructor.constKeyword, isNotNull); |
| 6103 expect(constructor.factoryKeyword, isNotNull); | 6421 expect(constructor.factoryKeyword, isNotNull); |
| 6104 expect(constructor.returnType, isNotNull); | 6422 expect(constructor.returnType, isNotNull); |
| 6105 expect(constructor.period, isNull); | 6423 expect(constructor.period, isNull); |
| 6106 expect(constructor.name, isNull); | 6424 expect(constructor.name, isNull); |
| 6107 expect(constructor.parameters, isNotNull); | 6425 expect(constructor.parameters, isNotNull); |
| 6108 expect(constructor.separator, isNotNull); | 6426 expect(constructor.separator, isNotNull); |
| 6109 expect(constructor.initializers, hasLength(0)); | 6427 expect(constructor.initializers, hasLength(0)); |
| 6110 expect(constructor.redirectedConstructor, isNotNull); | 6428 expect(constructor.redirectedConstructor, isNotNull); |
| 6111 expect(constructor.body, isNotNull); | 6429 expect(constructor.body, isNotNull); |
| 6112 } | 6430 } |
| 6113 | 6431 |
| 6114 void test_parseClassMember_redirectingFactory_nonConst() { | 6432 void test_parseClassMember_redirectingFactory_nonConst() { |
| 6115 ConstructorDeclaration constructor = | 6433 createParser('factory C() = B;'); |
| 6116 parse("parseClassMember", <Object>["C"], "factory C() = B;"); | 6434 ClassMember member = parser.parseClassMember('C'); |
| 6435 expectNotNullIfNoErrors(member); |
| 6436 listener.assertNoErrors(); |
| 6437 expect(member, new isInstanceOf<ConstructorDeclaration>()); |
| 6438 ConstructorDeclaration constructor = member; |
| 6117 expect(constructor.externalKeyword, isNull); | 6439 expect(constructor.externalKeyword, isNull); |
| 6118 expect(constructor.constKeyword, isNull); | 6440 expect(constructor.constKeyword, isNull); |
| 6119 expect(constructor.factoryKeyword, isNotNull); | 6441 expect(constructor.factoryKeyword, isNotNull); |
| 6120 expect(constructor.returnType, isNotNull); | 6442 expect(constructor.returnType, isNotNull); |
| 6121 expect(constructor.period, isNull); | 6443 expect(constructor.period, isNull); |
| 6122 expect(constructor.name, isNull); | 6444 expect(constructor.name, isNull); |
| 6123 expect(constructor.parameters, isNotNull); | 6445 expect(constructor.parameters, isNotNull); |
| 6124 expect(constructor.separator, isNotNull); | 6446 expect(constructor.separator, isNotNull); |
| 6125 expect(constructor.initializers, hasLength(0)); | 6447 expect(constructor.initializers, hasLength(0)); |
| 6126 expect(constructor.redirectedConstructor, isNotNull); | 6448 expect(constructor.redirectedConstructor, isNotNull); |
| 6127 expect(constructor.body, isNotNull); | 6449 expect(constructor.body, isNotNull); |
| 6128 } | 6450 } |
| 6129 | 6451 |
| 6130 void test_parseClassTypeAlias_abstract() { | 6452 void test_parseClassTypeAlias_abstract() { |
| 6131 Token classToken = TokenFactory.tokenFromKeyword(Keyword.CLASS); | 6453 Token classToken = TokenFactory.tokenFromKeyword(Keyword.CLASS); |
| 6132 Token abstractToken = TokenFactory.tokenFromKeyword(Keyword.ABSTRACT); | 6454 Token abstractToken = TokenFactory.tokenFromKeyword(Keyword.ABSTRACT); |
| 6133 ClassTypeAlias classTypeAlias = parse( | 6455 createParser('A = B with C;'); |
| 6134 "parseClassTypeAlias", | 6456 ClassTypeAlias classTypeAlias = parser.parseClassTypeAlias( |
| 6135 <Object>[emptyCommentAndMetadata(), abstractToken, classToken], | 6457 emptyCommentAndMetadata(), abstractToken, classToken); |
| 6136 "A = B with C;"); | 6458 expectNotNullIfNoErrors(classTypeAlias); |
| 6459 listener.assertNoErrors(); |
| 6137 expect(classTypeAlias.typedefKeyword, isNotNull); | 6460 expect(classTypeAlias.typedefKeyword, isNotNull); |
| 6138 expect(classTypeAlias.name.name, "A"); | 6461 expect(classTypeAlias.name.name, "A"); |
| 6139 expect(classTypeAlias.equals, isNotNull); | 6462 expect(classTypeAlias.equals, isNotNull); |
| 6140 expect(classTypeAlias.abstractKeyword, isNotNull); | 6463 expect(classTypeAlias.abstractKeyword, isNotNull); |
| 6141 expect(classTypeAlias.superclass.name.name, isNotNull, reason: "B"); | 6464 expect(classTypeAlias.superclass.name.name, isNotNull, reason: "B"); |
| 6142 expect(classTypeAlias.withClause, isNotNull); | 6465 expect(classTypeAlias.withClause, isNotNull); |
| 6143 expect(classTypeAlias.implementsClause, isNull); | 6466 expect(classTypeAlias.implementsClause, isNull); |
| 6144 expect(classTypeAlias.semicolon, isNotNull); | 6467 expect(classTypeAlias.semicolon, isNotNull); |
| 6145 } | 6468 } |
| 6146 | 6469 |
| 6147 void test_parseClassTypeAlias_implements() { | 6470 void test_parseClassTypeAlias_implements() { |
| 6148 Token token = TokenFactory.tokenFromKeyword(Keyword.CLASS); | 6471 Token classToken = TokenFactory.tokenFromKeyword(Keyword.CLASS); |
| 6149 ClassTypeAlias classTypeAlias = parse( | 6472 createParser('A = B with C implements D;'); |
| 6150 "parseClassTypeAlias", | 6473 ClassTypeAlias classTypeAlias = |
| 6151 <Object>[emptyCommentAndMetadata(), null, token], | 6474 parser.parseClassTypeAlias(emptyCommentAndMetadata(), null, classToken); |
| 6152 "A = B with C implements D;"); | 6475 expectNotNullIfNoErrors(classTypeAlias); |
| 6476 listener.assertNoErrors(); |
| 6153 expect(classTypeAlias.typedefKeyword, isNotNull); | 6477 expect(classTypeAlias.typedefKeyword, isNotNull); |
| 6154 expect(classTypeAlias.name.name, "A"); | 6478 expect(classTypeAlias.name.name, "A"); |
| 6155 expect(classTypeAlias.equals, isNotNull); | 6479 expect(classTypeAlias.equals, isNotNull); |
| 6156 expect(classTypeAlias.abstractKeyword, isNull); | 6480 expect(classTypeAlias.abstractKeyword, isNull); |
| 6157 expect(classTypeAlias.superclass.name.name, isNotNull, reason: "B"); | 6481 expect(classTypeAlias.superclass.name.name, isNotNull, reason: "B"); |
| 6158 expect(classTypeAlias.withClause, isNotNull); | 6482 expect(classTypeAlias.withClause, isNotNull); |
| 6159 expect(classTypeAlias.implementsClause, isNotNull); | 6483 expect(classTypeAlias.implementsClause, isNotNull); |
| 6160 expect(classTypeAlias.semicolon, isNotNull); | 6484 expect(classTypeAlias.semicolon, isNotNull); |
| 6161 } | 6485 } |
| 6162 | 6486 |
| 6163 void test_parseClassTypeAlias_with() { | 6487 void test_parseClassTypeAlias_with() { |
| 6164 Token token = TokenFactory.tokenFromKeyword(Keyword.CLASS); | 6488 Token classToken = TokenFactory.tokenFromKeyword(Keyword.CLASS); |
| 6165 ClassTypeAlias classTypeAlias = parse("parseClassTypeAlias", | 6489 createParser('A = B with C;'); |
| 6166 <Object>[emptyCommentAndMetadata(), null, token], "A = B with C;"); | 6490 ClassTypeAlias classTypeAlias = |
| 6491 parser.parseClassTypeAlias(emptyCommentAndMetadata(), null, classToken); |
| 6492 expectNotNullIfNoErrors(classTypeAlias); |
| 6493 listener.assertNoErrors(); |
| 6167 expect(classTypeAlias.typedefKeyword, isNotNull); | 6494 expect(classTypeAlias.typedefKeyword, isNotNull); |
| 6168 expect(classTypeAlias.name.name, "A"); | 6495 expect(classTypeAlias.name.name, "A"); |
| 6169 expect(classTypeAlias.equals, isNotNull); | 6496 expect(classTypeAlias.equals, isNotNull); |
| 6170 expect(classTypeAlias.abstractKeyword, isNull); | 6497 expect(classTypeAlias.abstractKeyword, isNull); |
| 6171 expect(classTypeAlias.superclass.name.name, isNotNull, reason: "B"); | 6498 expect(classTypeAlias.superclass.name.name, isNotNull, reason: "B"); |
| 6172 expect(classTypeAlias.withClause, isNotNull); | 6499 expect(classTypeAlias.withClause, isNotNull); |
| 6173 expect(classTypeAlias.implementsClause, isNull); | 6500 expect(classTypeAlias.implementsClause, isNull); |
| 6174 expect(classTypeAlias.semicolon, isNotNull); | 6501 expect(classTypeAlias.semicolon, isNotNull); |
| 6175 } | 6502 } |
| 6176 | 6503 |
| 6177 void test_parseClassTypeAlias_with_implements() { | 6504 void test_parseClassTypeAlias_with_implements() { |
| 6178 Token token = TokenFactory.tokenFromKeyword(Keyword.CLASS); | 6505 Token classToken = TokenFactory.tokenFromKeyword(Keyword.CLASS); |
| 6179 ClassTypeAlias classTypeAlias = parse( | 6506 createParser('A = B with C implements D;'); |
| 6180 "parseClassTypeAlias", | 6507 ClassTypeAlias classTypeAlias = |
| 6181 <Object>[emptyCommentAndMetadata(), null, token], | 6508 parser.parseClassTypeAlias(emptyCommentAndMetadata(), null, classToken); |
| 6182 "A = B with C implements D;"); | 6509 expectNotNullIfNoErrors(classTypeAlias); |
| 6510 listener.assertNoErrors(); |
| 6183 expect(classTypeAlias.typedefKeyword, isNotNull); | 6511 expect(classTypeAlias.typedefKeyword, isNotNull); |
| 6184 expect(classTypeAlias.name.name, "A"); | 6512 expect(classTypeAlias.name.name, "A"); |
| 6185 expect(classTypeAlias.equals, isNotNull); | 6513 expect(classTypeAlias.equals, isNotNull); |
| 6186 expect(classTypeAlias.abstractKeyword, isNull); | 6514 expect(classTypeAlias.abstractKeyword, isNull); |
| 6187 expect(classTypeAlias.superclass.name.name, isNotNull, reason: "B"); | 6515 expect(classTypeAlias.superclass.name.name, isNotNull, reason: "B"); |
| 6188 expect(classTypeAlias.withClause, isNotNull); | 6516 expect(classTypeAlias.withClause, isNotNull); |
| 6189 expect(classTypeAlias.implementsClause, isNotNull); | 6517 expect(classTypeAlias.implementsClause, isNotNull); |
| 6190 expect(classTypeAlias.semicolon, isNotNull); | 6518 expect(classTypeAlias.semicolon, isNotNull); |
| 6191 } | 6519 } |
| 6192 | 6520 |
| 6193 void test_parseCombinator_hide() { | 6521 void test_parseCombinator_hide() { |
| 6194 HideCombinator combinator = parse4('parseCombinator', 'hide a;'); | 6522 createParser('hide a;'); |
| 6523 Combinator combinator = parser.parseCombinator(); |
| 6524 expectNotNullIfNoErrors(combinator); |
| 6525 listener.assertNoErrors(); |
| 6195 expect(combinator, new isInstanceOf<HideCombinator>()); | 6526 expect(combinator, new isInstanceOf<HideCombinator>()); |
| 6196 expect(combinator.keyword, isNotNull); | 6527 HideCombinator hideCombinator = combinator; |
| 6197 expect(combinator.hiddenNames, hasLength(1)); | 6528 expect(hideCombinator.keyword, isNotNull); |
| 6529 expect(hideCombinator.hiddenNames, hasLength(1)); |
| 6198 } | 6530 } |
| 6199 | 6531 |
| 6200 void test_parseCombinator_show() { | 6532 void test_parseCombinator_show() { |
| 6201 ShowCombinator combinator = parse4('parseCombinator', 'show a;'); | 6533 createParser('show a;'); |
| 6534 Combinator combinator = parser.parseCombinator(); |
| 6535 expectNotNullIfNoErrors(combinator); |
| 6536 listener.assertNoErrors(); |
| 6202 expect(combinator, new isInstanceOf<ShowCombinator>()); | 6537 expect(combinator, new isInstanceOf<ShowCombinator>()); |
| 6203 expect(combinator.keyword, isNotNull); | 6538 ShowCombinator showCombinator = combinator; |
| 6204 expect(combinator.shownNames, hasLength(1)); | 6539 expect(showCombinator.keyword, isNotNull); |
| 6540 expect(showCombinator.shownNames, hasLength(1)); |
| 6205 } | 6541 } |
| 6206 | 6542 |
| 6207 void test_parseCombinators_h() { | 6543 void test_parseCombinators_h() { |
| 6208 List<Combinator> combinators = parse4("parseCombinators", "hide a;"); | 6544 createParser('hide a;'); |
| 6545 List<Combinator> combinators = parser.parseCombinators(); |
| 6546 expectNotNullIfNoErrors(combinators); |
| 6547 listener.assertNoErrors(); |
| 6209 expect(combinators, hasLength(1)); | 6548 expect(combinators, hasLength(1)); |
| 6210 HideCombinator combinator = combinators[0] as HideCombinator; | 6549 HideCombinator combinator = combinators[0] as HideCombinator; |
| 6211 expect(combinator, isNotNull); | 6550 expect(combinator, isNotNull); |
| 6212 expect(combinator.keyword, isNotNull); | 6551 expect(combinator.keyword, isNotNull); |
| 6213 expect(combinator.hiddenNames, hasLength(1)); | 6552 expect(combinator.hiddenNames, hasLength(1)); |
| 6214 } | 6553 } |
| 6215 | 6554 |
| 6216 void test_parseCombinators_hs() { | 6555 void test_parseCombinators_hs() { |
| 6217 List<Combinator> combinators = parse4("parseCombinators", "hide a show b;"); | 6556 createParser('hide a show b;'); |
| 6557 List<Combinator> combinators = parser.parseCombinators(); |
| 6558 expectNotNullIfNoErrors(combinators); |
| 6559 listener.assertNoErrors(); |
| 6218 expect(combinators, hasLength(2)); | 6560 expect(combinators, hasLength(2)); |
| 6219 HideCombinator hideCombinator = combinators[0] as HideCombinator; | 6561 HideCombinator hideCombinator = combinators[0] as HideCombinator; |
| 6220 expect(hideCombinator, isNotNull); | 6562 expect(hideCombinator, isNotNull); |
| 6221 expect(hideCombinator.keyword, isNotNull); | 6563 expect(hideCombinator.keyword, isNotNull); |
| 6222 expect(hideCombinator.hiddenNames, hasLength(1)); | 6564 expect(hideCombinator.hiddenNames, hasLength(1)); |
| 6223 ShowCombinator showCombinator = combinators[1] as ShowCombinator; | 6565 ShowCombinator showCombinator = combinators[1] as ShowCombinator; |
| 6224 expect(showCombinator, isNotNull); | 6566 expect(showCombinator, isNotNull); |
| 6225 expect(showCombinator.keyword, isNotNull); | 6567 expect(showCombinator.keyword, isNotNull); |
| 6226 expect(showCombinator.shownNames, hasLength(1)); | 6568 expect(showCombinator.shownNames, hasLength(1)); |
| 6227 } | 6569 } |
| 6228 | 6570 |
| 6229 void test_parseCombinators_hshs() { | 6571 void test_parseCombinators_hshs() { |
| 6230 List<Combinator> combinators = | 6572 createParser('hide a show b hide c show d;'); |
| 6231 parse4("parseCombinators", "hide a show b hide c show d;"); | 6573 List<Combinator> combinators = parser.parseCombinators(); |
| 6574 expectNotNullIfNoErrors(combinators); |
| 6575 listener.assertNoErrors(); |
| 6232 expect(combinators, hasLength(4)); | 6576 expect(combinators, hasLength(4)); |
| 6233 } | 6577 } |
| 6234 | 6578 |
| 6235 void test_parseCombinators_s() { | 6579 void test_parseCombinators_s() { |
| 6236 List<Combinator> combinators = parse4("parseCombinators", "show a;"); | 6580 createParser('show a;'); |
| 6581 List<Combinator> combinators = parser.parseCombinators(); |
| 6582 expectNotNullIfNoErrors(combinators); |
| 6583 listener.assertNoErrors(); |
| 6237 expect(combinators, hasLength(1)); | 6584 expect(combinators, hasLength(1)); |
| 6238 ShowCombinator combinator = combinators[0] as ShowCombinator; | 6585 ShowCombinator combinator = combinators[0] as ShowCombinator; |
| 6239 expect(combinator, isNotNull); | 6586 expect(combinator, isNotNull); |
| 6240 expect(combinator.keyword, isNotNull); | 6587 expect(combinator.keyword, isNotNull); |
| 6241 expect(combinator.shownNames, hasLength(1)); | 6588 expect(combinator.shownNames, hasLength(1)); |
| 6242 } | 6589 } |
| 6243 | 6590 |
| 6244 void test_parseCommentAndMetadata_c() { | 6591 void test_parseCommentAndMetadata_c() { |
| 6245 CommentAndMetadata commentAndMetadata = | 6592 createParser('/** 1 */ void'); |
| 6246 parse4("parseCommentAndMetadata", "/** 1 */ void"); | 6593 CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| 6594 expectNotNullIfNoErrors(commentAndMetadata); |
| 6595 listener.assertNoErrors(); |
| 6247 expect(commentAndMetadata.comment, isNotNull); | 6596 expect(commentAndMetadata.comment, isNotNull); |
| 6248 expect(commentAndMetadata.metadata, hasLength(0)); | 6597 expect(commentAndMetadata.metadata, isNull); |
| 6249 } | 6598 } |
| 6250 | 6599 |
| 6251 void test_parseCommentAndMetadata_cmc() { | 6600 void test_parseCommentAndMetadata_cmc() { |
| 6252 CommentAndMetadata commentAndMetadata = | 6601 createParser('/** 1 */ @A /** 2 */ void'); |
| 6253 parse4("parseCommentAndMetadata", "/** 1 */ @A /** 2 */ void"); | 6602 CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| 6603 expectNotNullIfNoErrors(commentAndMetadata); |
| 6604 listener.assertNoErrors(); |
| 6254 expect(commentAndMetadata.comment, isNotNull); | 6605 expect(commentAndMetadata.comment, isNotNull); |
| 6255 expect(commentAndMetadata.metadata, hasLength(1)); | 6606 expect(commentAndMetadata.metadata, hasLength(1)); |
| 6256 } | 6607 } |
| 6257 | 6608 |
| 6258 void test_parseCommentAndMetadata_cmcm() { | 6609 void test_parseCommentAndMetadata_cmcm() { |
| 6259 CommentAndMetadata commentAndMetadata = | 6610 createParser('/** 1 */ @A /** 2 */ @B void'); |
| 6260 parse4("parseCommentAndMetadata", "/** 1 */ @A /** 2 */ @B void"); | 6611 CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| 6612 expectNotNullIfNoErrors(commentAndMetadata); |
| 6613 listener.assertNoErrors(); |
| 6261 expect(commentAndMetadata.comment, isNotNull); | 6614 expect(commentAndMetadata.comment, isNotNull); |
| 6262 expect(commentAndMetadata.metadata, hasLength(2)); | 6615 expect(commentAndMetadata.metadata, hasLength(2)); |
| 6263 } | 6616 } |
| 6264 | 6617 |
| 6265 void test_parseCommentAndMetadata_cmm() { | 6618 void test_parseCommentAndMetadata_cmm() { |
| 6266 CommentAndMetadata commentAndMetadata = | 6619 createParser('/** 1 */ @A @B void'); |
| 6267 parse4("parseCommentAndMetadata", "/** 1 */ @A @B void"); | 6620 CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| 6621 expectNotNullIfNoErrors(commentAndMetadata); |
| 6622 listener.assertNoErrors(); |
| 6268 expect(commentAndMetadata.comment, isNotNull); | 6623 expect(commentAndMetadata.comment, isNotNull); |
| 6269 expect(commentAndMetadata.metadata, hasLength(2)); | 6624 expect(commentAndMetadata.metadata, hasLength(2)); |
| 6270 } | 6625 } |
| 6271 | 6626 |
| 6272 void test_parseCommentAndMetadata_m() { | 6627 void test_parseCommentAndMetadata_m() { |
| 6273 CommentAndMetadata commentAndMetadata = | 6628 createParser('@A void'); |
| 6274 parse4("parseCommentAndMetadata", "@A void"); | 6629 CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| 6630 expectNotNullIfNoErrors(commentAndMetadata); |
| 6631 listener.assertNoErrors(); |
| 6275 expect(commentAndMetadata.comment, isNull); | 6632 expect(commentAndMetadata.comment, isNull); |
| 6276 expect(commentAndMetadata.metadata, hasLength(1)); | 6633 expect(commentAndMetadata.metadata, hasLength(1)); |
| 6277 } | 6634 } |
| 6278 | 6635 |
| 6279 void test_parseCommentAndMetadata_mcm() { | 6636 void test_parseCommentAndMetadata_mcm() { |
| 6280 CommentAndMetadata commentAndMetadata = | 6637 createParser('@A /** 1 */ @B void'); |
| 6281 parse4("parseCommentAndMetadata", "@A /** 1 */ @B void"); | 6638 CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| 6639 expectNotNullIfNoErrors(commentAndMetadata); |
| 6640 listener.assertNoErrors(); |
| 6282 expect(commentAndMetadata.comment, isNotNull); | 6641 expect(commentAndMetadata.comment, isNotNull); |
| 6283 expect(commentAndMetadata.metadata, hasLength(2)); | 6642 expect(commentAndMetadata.metadata, hasLength(2)); |
| 6284 } | 6643 } |
| 6285 | 6644 |
| 6286 void test_parseCommentAndMetadata_mcmc() { | 6645 void test_parseCommentAndMetadata_mcmc() { |
| 6287 CommentAndMetadata commentAndMetadata = | 6646 createParser('@A /** 1 */ @B /** 2 */ void'); |
| 6288 parse4("parseCommentAndMetadata", "@A /** 1 */ @B /** 2 */ void"); | 6647 CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| 6648 expectNotNullIfNoErrors(commentAndMetadata); |
| 6649 listener.assertNoErrors(); |
| 6289 expect(commentAndMetadata.comment, isNotNull); | 6650 expect(commentAndMetadata.comment, isNotNull); |
| 6290 expect(commentAndMetadata.metadata, hasLength(2)); | 6651 expect(commentAndMetadata.metadata, hasLength(2)); |
| 6291 } | 6652 } |
| 6292 | 6653 |
| 6293 void test_parseCommentAndMetadata_mm() { | 6654 void test_parseCommentAndMetadata_mm() { |
| 6294 CommentAndMetadata commentAndMetadata = | 6655 createParser('@A @B(x) void'); |
| 6295 parse4("parseCommentAndMetadata", "@A @B(x) void"); | 6656 CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| 6657 expectNotNullIfNoErrors(commentAndMetadata); |
| 6658 listener.assertNoErrors(); |
| 6296 expect(commentAndMetadata.comment, isNull); | 6659 expect(commentAndMetadata.comment, isNull); |
| 6297 expect(commentAndMetadata.metadata, hasLength(2)); | 6660 expect(commentAndMetadata.metadata, hasLength(2)); |
| 6298 } | 6661 } |
| 6299 | 6662 |
| 6300 void test_parseCommentAndMetadata_none() { | 6663 void test_parseCommentAndMetadata_none() { |
| 6301 CommentAndMetadata commentAndMetadata = | 6664 createParser('void'); |
| 6302 parse4("parseCommentAndMetadata", "void"); | 6665 CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| 6666 expectNotNullIfNoErrors(commentAndMetadata); |
| 6667 listener.assertNoErrors(); |
| 6303 expect(commentAndMetadata.comment, isNull); | 6668 expect(commentAndMetadata.comment, isNull); |
| 6304 expect(commentAndMetadata.metadata, hasLength(0)); | 6669 expect(commentAndMetadata.metadata, isNull); |
| 6305 } | 6670 } |
| 6306 | 6671 |
| 6307 void test_parseCommentAndMetadata_singleLine() { | 6672 void test_parseCommentAndMetadata_singleLine() { |
| 6308 CommentAndMetadata commentAndMetadata = parse4( | 6673 createParser(r''' |
| 6309 "parseCommentAndMetadata", | |
| 6310 r''' | |
| 6311 /// 1 | 6674 /// 1 |
| 6312 /// 2 | 6675 /// 2 |
| 6313 void'''); | 6676 void'''); |
| 6677 CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| 6678 expectNotNullIfNoErrors(commentAndMetadata); |
| 6679 listener.assertNoErrors(); |
| 6314 expect(commentAndMetadata.comment, isNotNull); | 6680 expect(commentAndMetadata.comment, isNotNull); |
| 6315 expect(commentAndMetadata.metadata, hasLength(0)); | 6681 expect(commentAndMetadata.metadata, isNull); |
| 6316 } | 6682 } |
| 6317 | 6683 |
| 6318 void test_parseCommentReference_new_prefixed() { | 6684 void test_parseCommentReference_new_prefixed() { |
| 6319 CommentReference reference = | 6685 createParser(''); |
| 6320 parse("parseCommentReference", <Object>["new a.b", 7], ""); | 6686 CommentReference reference = parser.parseCommentReference('new a.b', 7); |
| 6321 PrefixedIdentifier prefixedIdentifier = EngineTestCase.assertInstanceOf( | 6687 expectNotNullIfNoErrors(reference); |
| 6322 (obj) => obj is PrefixedIdentifier, | 6688 listener.assertNoErrors(); |
| 6323 PrefixedIdentifier, | 6689 expect(reference.identifier, new isInstanceOf<PrefixedIdentifier>()); |
| 6324 reference.identifier); | 6690 PrefixedIdentifier prefixedIdentifier = reference.identifier; |
| 6325 SimpleIdentifier prefix = prefixedIdentifier.prefix; | 6691 SimpleIdentifier prefix = prefixedIdentifier.prefix; |
| 6326 expect(prefix.token, isNotNull); | 6692 expect(prefix.token, isNotNull); |
| 6327 expect(prefix.name, "a"); | 6693 expect(prefix.name, "a"); |
| 6328 expect(prefix.offset, 11); | 6694 expect(prefix.offset, 11); |
| 6329 expect(prefixedIdentifier.period, isNotNull); | 6695 expect(prefixedIdentifier.period, isNotNull); |
| 6330 SimpleIdentifier identifier = prefixedIdentifier.identifier; | 6696 SimpleIdentifier identifier = prefixedIdentifier.identifier; |
| 6331 expect(identifier.token, isNotNull); | 6697 expect(identifier.token, isNotNull); |
| 6332 expect(identifier.name, "b"); | 6698 expect(identifier.name, "b"); |
| 6333 expect(identifier.offset, 13); | 6699 expect(identifier.offset, 13); |
| 6334 } | 6700 } |
| 6335 | 6701 |
| 6336 void test_parseCommentReference_new_simple() { | 6702 void test_parseCommentReference_new_simple() { |
| 6337 CommentReference reference = | 6703 createParser(''); |
| 6338 parse("parseCommentReference", <Object>["new a", 5], ""); | 6704 CommentReference reference = parser.parseCommentReference('new a', 5); |
| 6339 SimpleIdentifier identifier = EngineTestCase.assertInstanceOf( | 6705 expectNotNullIfNoErrors(reference); |
| 6340 (obj) => obj is SimpleIdentifier, | 6706 listener.assertNoErrors(); |
| 6341 SimpleIdentifier, | 6707 expect(reference.identifier, new isInstanceOf<SimpleIdentifier>()); |
| 6342 reference.identifier); | 6708 SimpleIdentifier identifier = reference.identifier; |
| 6343 expect(identifier.token, isNotNull); | 6709 expect(identifier.token, isNotNull); |
| 6344 expect(identifier.name, "a"); | 6710 expect(identifier.name, "a"); |
| 6345 expect(identifier.offset, 9); | 6711 expect(identifier.offset, 9); |
| 6346 } | 6712 } |
| 6347 | 6713 |
| 6714 void test_parseCommentReference_operator_withKeyword_notPrefixed() { |
| 6715 createParser(''); |
| 6716 CommentReference reference = parser.parseCommentReference('operator ==', 5); |
| 6717 expectNotNullIfNoErrors(reference); |
| 6718 listener.assertNoErrors(); |
| 6719 expect(reference.identifier, new isInstanceOf<SimpleIdentifier>()); |
| 6720 SimpleIdentifier identifier = reference.identifier; |
| 6721 expect(identifier.token, isNotNull); |
| 6722 expect(identifier.name, "=="); |
| 6723 expect(identifier.offset, 14); |
| 6724 } |
| 6725 |
| 6726 void test_parseCommentReference_operator_withKeyword_prefixed() { |
| 6727 createParser(''); |
| 6728 CommentReference reference = |
| 6729 parser.parseCommentReference('Object.operator==', 7); |
| 6730 expectNotNullIfNoErrors(reference); |
| 6731 listener.assertNoErrors(); |
| 6732 expect(reference.identifier, new isInstanceOf<PrefixedIdentifier>()); |
| 6733 PrefixedIdentifier prefixedIdentifier = reference.identifier; |
| 6734 SimpleIdentifier prefix = prefixedIdentifier.prefix; |
| 6735 expect(prefix.token, isNotNull); |
| 6736 expect(prefix.name, "Object"); |
| 6737 expect(prefix.offset, 7); |
| 6738 expect(prefixedIdentifier.period, isNotNull); |
| 6739 SimpleIdentifier identifier = prefixedIdentifier.identifier; |
| 6740 expect(identifier.token, isNotNull); |
| 6741 expect(identifier.name, "=="); |
| 6742 expect(identifier.offset, 22); |
| 6743 } |
| 6744 |
| 6745 void test_parseCommentReference_operator_withoutKeyword_notPrefixed() { |
| 6746 createParser(''); |
| 6747 CommentReference reference = parser.parseCommentReference('==', 5); |
| 6748 expectNotNullIfNoErrors(reference); |
| 6749 listener.assertNoErrors(); |
| 6750 expect(reference.identifier, new isInstanceOf<SimpleIdentifier>()); |
| 6751 SimpleIdentifier identifier = reference.identifier; |
| 6752 expect(identifier.token, isNotNull); |
| 6753 expect(identifier.name, "=="); |
| 6754 expect(identifier.offset, 5); |
| 6755 } |
| 6756 |
| 6757 void test_parseCommentReference_operator_withoutKeyword_prefixed() { |
| 6758 createParser(''); |
| 6759 CommentReference reference = parser.parseCommentReference('Object.==', 7); |
| 6760 expectNotNullIfNoErrors(reference); |
| 6761 listener.assertNoErrors(); |
| 6762 expect(reference.identifier, new isInstanceOf<PrefixedIdentifier>()); |
| 6763 PrefixedIdentifier prefixedIdentifier = reference.identifier; |
| 6764 SimpleIdentifier prefix = prefixedIdentifier.prefix; |
| 6765 expect(prefix.token, isNotNull); |
| 6766 expect(prefix.name, "Object"); |
| 6767 expect(prefix.offset, 7); |
| 6768 expect(prefixedIdentifier.period, isNotNull); |
| 6769 SimpleIdentifier identifier = prefixedIdentifier.identifier; |
| 6770 expect(identifier.token, isNotNull); |
| 6771 expect(identifier.name, "=="); |
| 6772 expect(identifier.offset, 14); |
| 6773 } |
| 6774 |
| 6348 void test_parseCommentReference_prefixed() { | 6775 void test_parseCommentReference_prefixed() { |
| 6349 CommentReference reference = | 6776 createParser(''); |
| 6350 parse("parseCommentReference", <Object>["a.b", 7], ""); | 6777 CommentReference reference = parser.parseCommentReference('a.b', 7); |
| 6351 PrefixedIdentifier prefixedIdentifier = EngineTestCase.assertInstanceOf( | 6778 expectNotNullIfNoErrors(reference); |
| 6352 (obj) => obj is PrefixedIdentifier, | 6779 listener.assertNoErrors(); |
| 6353 PrefixedIdentifier, | 6780 expect(reference.identifier, new isInstanceOf<PrefixedIdentifier>()); |
| 6354 reference.identifier); | 6781 PrefixedIdentifier prefixedIdentifier = reference.identifier; |
| 6355 SimpleIdentifier prefix = prefixedIdentifier.prefix; | 6782 SimpleIdentifier prefix = prefixedIdentifier.prefix; |
| 6356 expect(prefix.token, isNotNull); | 6783 expect(prefix.token, isNotNull); |
| 6357 expect(prefix.name, "a"); | 6784 expect(prefix.name, "a"); |
| 6358 expect(prefix.offset, 7); | 6785 expect(prefix.offset, 7); |
| 6359 expect(prefixedIdentifier.period, isNotNull); | 6786 expect(prefixedIdentifier.period, isNotNull); |
| 6360 SimpleIdentifier identifier = prefixedIdentifier.identifier; | 6787 SimpleIdentifier identifier = prefixedIdentifier.identifier; |
| 6361 expect(identifier.token, isNotNull); | 6788 expect(identifier.token, isNotNull); |
| 6362 expect(identifier.name, "b"); | 6789 expect(identifier.name, "b"); |
| 6363 expect(identifier.offset, 9); | 6790 expect(identifier.offset, 9); |
| 6364 } | 6791 } |
| 6365 | 6792 |
| 6366 void test_parseCommentReference_simple() { | 6793 void test_parseCommentReference_simple() { |
| 6367 CommentReference reference = | 6794 createParser(''); |
| 6368 parse("parseCommentReference", <Object>["a", 5], ""); | 6795 CommentReference reference = parser.parseCommentReference('a', 5); |
| 6796 expectNotNullIfNoErrors(reference); |
| 6797 listener.assertNoErrors(); |
| 6798 expect(reference.identifier, new isInstanceOf<SimpleIdentifier>()); |
| 6799 SimpleIdentifier identifier = reference.identifier; |
| 6800 expect(identifier.token, isNotNull); |
| 6801 expect(identifier.name, "a"); |
| 6802 expect(identifier.offset, 5); |
| 6803 } |
| 6804 |
| 6805 void test_parseCommentReference_synthetic() { |
| 6806 createParser(''); |
| 6807 CommentReference reference = parser.parseCommentReference('', 5); |
| 6808 expectNotNullIfNoErrors(reference); |
| 6809 listener.assertNoErrors(); |
| 6810 expect(reference.identifier, new isInstanceOf<SimpleIdentifier>()); |
| 6811 SimpleIdentifier identifier = reference.identifier; |
| 6812 expect(identifier, isNotNull); |
| 6813 expect(identifier.isSynthetic, isTrue); |
| 6814 expect(identifier.token, isNotNull); |
| 6815 expect(identifier.name, ""); |
| 6816 expect(identifier.offset, 5); |
| 6817 // Should end with EOF token. |
| 6818 Token nextToken = identifier.token.next; |
| 6819 expect(nextToken, isNotNull); |
| 6820 expect(nextToken.type, TokenType.EOF); |
| 6821 } |
| 6822 |
| 6823 @failingTest |
| 6824 void test_parseCommentReference_this() { |
| 6825 // This fails because we are returning null from the method and asserting |
| 6826 // that the return value is not null. |
| 6827 createParser(''); |
| 6828 CommentReference reference = parser.parseCommentReference('this', 5); |
| 6829 expectNotNullIfNoErrors(reference); |
| 6830 listener.assertNoErrors(); |
| 6369 SimpleIdentifier identifier = EngineTestCase.assertInstanceOf( | 6831 SimpleIdentifier identifier = EngineTestCase.assertInstanceOf( |
| 6370 (obj) => obj is SimpleIdentifier, | 6832 (obj) => obj is SimpleIdentifier, |
| 6371 SimpleIdentifier, | 6833 SimpleIdentifier, |
| 6372 reference.identifier); | 6834 reference.identifier); |
| 6373 expect(identifier.token, isNotNull); | 6835 expect(identifier.token, isNotNull); |
| 6374 expect(identifier.name, "a"); | 6836 expect(identifier.name, "a"); |
| 6375 expect(identifier.offset, 5); | 6837 expect(identifier.offset, 5); |
| 6376 } | 6838 } |
| 6377 | 6839 |
| 6378 void test_parseCommentReference_synthetic() { | |
| 6379 CommentReference reference = | |
| 6380 parse("parseCommentReference", <Object>["", 5], ""); | |
| 6381 SimpleIdentifier identifier = EngineTestCase.assertInstanceOf( | |
| 6382 (obj) => obj is SimpleIdentifier, | |
| 6383 SimpleIdentifier, | |
| 6384 reference.identifier); | |
| 6385 expect(identifier, isNotNull); | |
| 6386 expect(identifier.isSynthetic, isTrue); | |
| 6387 expect(identifier.token, isNotNull); | |
| 6388 expect(identifier.name, ""); | |
| 6389 expect(identifier.offset, 5); | |
| 6390 } | |
| 6391 | |
| 6392 void test_parseCommentReferences_multiLine() { | 6840 void test_parseCommentReferences_multiLine() { |
| 6393 DocumentationCommentToken token = new DocumentationCommentToken( | 6841 DocumentationCommentToken token = new DocumentationCommentToken( |
| 6394 TokenType.MULTI_LINE_COMMENT, "/** xxx [a] yyy [bb] zzz */", 3); | 6842 TokenType.MULTI_LINE_COMMENT, "/** xxx [a] yyy [bb] zzz */", 3); |
| 6395 List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[token]; | 6843 List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[token]; |
| 6396 List<CommentReference> references = | 6844 createParser(''); |
| 6397 parse("parseCommentReferences", <Object>[tokens], ""); | 6845 List<CommentReference> references = parser.parseCommentReferences(tokens); |
| 6846 expectNotNullIfNoErrors(references); |
| 6847 listener.assertNoErrors(); |
| 6398 List<Token> tokenReferences = token.references; | 6848 List<Token> tokenReferences = token.references; |
| 6399 expect(references, hasLength(2)); | 6849 expect(references, hasLength(2)); |
| 6400 expect(tokenReferences, hasLength(2)); | 6850 expect(tokenReferences, hasLength(2)); |
| 6401 { | 6851 { |
| 6402 CommentReference reference = references[0]; | 6852 CommentReference reference = references[0]; |
| 6403 expect(reference, isNotNull); | 6853 expect(reference, isNotNull); |
| 6404 expect(reference.identifier, isNotNull); | 6854 expect(reference.identifier, isNotNull); |
| 6405 expect(reference.offset, 12); | 6855 expect(reference.offset, 12); |
| 6406 // the reference is recorded in the comment token | 6856 // the reference is recorded in the comment token |
| 6407 Token referenceToken = tokenReferences[0]; | 6857 Token referenceToken = tokenReferences[0]; |
| 6408 expect(referenceToken.offset, 12); | 6858 expect(referenceToken.offset, 12); |
| 6409 expect(referenceToken.lexeme, 'a'); | 6859 expect(referenceToken.lexeme, 'a'); |
| 6410 } | 6860 } |
| 6411 { | 6861 { |
| 6412 CommentReference reference = references[1]; | 6862 CommentReference reference = references[1]; |
| 6413 expect(reference, isNotNull); | 6863 expect(reference, isNotNull); |
| 6414 expect(reference.identifier, isNotNull); | 6864 expect(reference.identifier, isNotNull); |
| 6415 expect(reference.offset, 20); | 6865 expect(reference.offset, 20); |
| 6416 // the reference is recorded in the comment token | 6866 // the reference is recorded in the comment token |
| 6417 Token referenceToken = tokenReferences[1]; | 6867 Token referenceToken = tokenReferences[1]; |
| 6418 expect(referenceToken.offset, 20); | 6868 expect(referenceToken.offset, 20); |
| 6419 expect(referenceToken.lexeme, 'bb'); | 6869 expect(referenceToken.lexeme, 'bb'); |
| 6420 } | 6870 } |
| 6421 } | 6871 } |
| 6422 | 6872 |
| 6423 void test_parseCommentReferences_notClosed_noIdentifier() { | 6873 void test_parseCommentReferences_notClosed_noIdentifier() { |
| 6424 List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ | 6874 DocumentationCommentToken docToken = new DocumentationCommentToken( |
| 6425 new DocumentationCommentToken( | 6875 TokenType.MULTI_LINE_COMMENT, "/** [ some text", 5); |
| 6426 TokenType.MULTI_LINE_COMMENT, "/** [ some text", 5) | 6876 createParser(''); |
| 6427 ]; | |
| 6428 List<CommentReference> references = | 6877 List<CommentReference> references = |
| 6429 parse("parseCommentReferences", <Object>[tokens], ""); | 6878 parser.parseCommentReferences(<DocumentationCommentToken>[docToken]); |
| 6879 expectNotNullIfNoErrors(references); |
| 6880 listener.assertNoErrors(); |
| 6881 expect(docToken.references, hasLength(1)); |
| 6430 expect(references, hasLength(1)); | 6882 expect(references, hasLength(1)); |
| 6883 Token referenceToken = docToken.references[0]; |
| 6431 CommentReference reference = references[0]; | 6884 CommentReference reference = references[0]; |
| 6432 expect(reference, isNotNull); | 6885 expect(reference, isNotNull); |
| 6886 expect(docToken.references[0], same(reference.beginToken)); |
| 6433 expect(reference.identifier, isNotNull); | 6887 expect(reference.identifier, isNotNull); |
| 6434 expect(reference.identifier.isSynthetic, isTrue); | 6888 expect(reference.identifier.isSynthetic, isTrue); |
| 6435 expect(reference.identifier.name, ""); | 6889 expect(reference.identifier.name, ""); |
| 6890 // Should end with EOF token. |
| 6891 Token nextToken = referenceToken.next; |
| 6892 expect(nextToken, isNotNull); |
| 6893 expect(nextToken.type, TokenType.EOF); |
| 6436 } | 6894 } |
| 6437 | 6895 |
| 6438 void test_parseCommentReferences_notClosed_withIdentifier() { | 6896 void test_parseCommentReferences_notClosed_withIdentifier() { |
| 6439 List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ | 6897 DocumentationCommentToken docToken = new DocumentationCommentToken( |
| 6440 new DocumentationCommentToken( | 6898 TokenType.MULTI_LINE_COMMENT, "/** [namePrefix some text", 5); |
| 6441 TokenType.MULTI_LINE_COMMENT, "/** [namePrefix some text", 5) | 6899 createParser(''); |
| 6442 ]; | |
| 6443 List<CommentReference> references = | 6900 List<CommentReference> references = |
| 6444 parse("parseCommentReferences", <Object>[tokens], ""); | 6901 parser.parseCommentReferences(<DocumentationCommentToken>[docToken]); |
| 6902 expectNotNullIfNoErrors(references); |
| 6903 listener.assertNoErrors(); |
| 6904 expect(docToken.references, hasLength(1)); |
| 6445 expect(references, hasLength(1)); | 6905 expect(references, hasLength(1)); |
| 6906 Token referenceToken = docToken.references[0]; |
| 6446 CommentReference reference = references[0]; | 6907 CommentReference reference = references[0]; |
| 6447 expect(reference, isNotNull); | 6908 expect(reference, isNotNull); |
| 6909 expect(referenceToken, same(reference.beginToken)); |
| 6448 expect(reference.identifier, isNotNull); | 6910 expect(reference.identifier, isNotNull); |
| 6449 expect(reference.identifier.isSynthetic, isFalse); | 6911 expect(reference.identifier.isSynthetic, isFalse); |
| 6450 expect(reference.identifier.name, "namePrefix"); | 6912 expect(reference.identifier.name, "namePrefix"); |
| 6913 // Should end with EOF token. |
| 6914 Token nextToken = referenceToken.next; |
| 6915 expect(nextToken, isNotNull); |
| 6916 expect(nextToken.type, TokenType.EOF); |
| 6451 } | 6917 } |
| 6452 | 6918 |
| 6453 void test_parseCommentReferences_singleLine() { | 6919 void test_parseCommentReferences_singleLine() { |
| 6454 List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ | 6920 List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ |
| 6455 new DocumentationCommentToken( | 6921 new DocumentationCommentToken( |
| 6456 TokenType.SINGLE_LINE_COMMENT, "/// xxx [a] yyy [b] zzz", 3), | 6922 TokenType.SINGLE_LINE_COMMENT, "/// xxx [a] yyy [b] zzz", 3), |
| 6457 new DocumentationCommentToken( | 6923 new DocumentationCommentToken( |
| 6458 TokenType.SINGLE_LINE_COMMENT, "/// x [c]", 28) | 6924 TokenType.SINGLE_LINE_COMMENT, "/// x [c]", 28) |
| 6459 ]; | 6925 ]; |
| 6460 List<CommentReference> references = | 6926 createParser(''); |
| 6461 parse("parseCommentReferences", <Object>[tokens], ""); | 6927 List<CommentReference> references = parser.parseCommentReferences(tokens); |
| 6928 expectNotNullIfNoErrors(references); |
| 6929 listener.assertNoErrors(); |
| 6462 expect(references, hasLength(3)); | 6930 expect(references, hasLength(3)); |
| 6463 CommentReference reference = references[0]; | 6931 CommentReference reference = references[0]; |
| 6464 expect(reference, isNotNull); | 6932 expect(reference, isNotNull); |
| 6465 expect(reference.identifier, isNotNull); | 6933 expect(reference.identifier, isNotNull); |
| 6466 expect(reference.offset, 12); | 6934 expect(reference.offset, 12); |
| 6467 reference = references[1]; | 6935 reference = references[1]; |
| 6468 expect(reference, isNotNull); | 6936 expect(reference, isNotNull); |
| 6469 expect(reference.identifier, isNotNull); | 6937 expect(reference.identifier, isNotNull); |
| 6470 expect(reference.offset, 20); | 6938 expect(reference.offset, 20); |
| 6471 reference = references[2]; | 6939 reference = references[2]; |
| 6472 expect(reference, isNotNull); | 6940 expect(reference, isNotNull); |
| 6473 expect(reference.identifier, isNotNull); | 6941 expect(reference.identifier, isNotNull); |
| 6474 expect(reference.offset, 35); | 6942 expect(reference.offset, 35); |
| 6475 } | 6943 } |
| 6476 | 6944 |
| 6945 void test_parseCommentReferences_skipCodeBlock_4spaces_block() { |
| 6946 List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ |
| 6947 new DocumentationCommentToken(TokenType.MULTI_LINE_COMMENT, |
| 6948 "/**\n * a[i]\n * non-code line\n */", 3) |
| 6949 ]; |
| 6950 createParser(''); |
| 6951 List<CommentReference> references = parser.parseCommentReferences(tokens); |
| 6952 expectNotNullIfNoErrors(references); |
| 6953 listener.assertNoErrors(); |
| 6954 expect(references, isEmpty); |
| 6955 } |
| 6956 |
| 6957 void test_parseCommentReferences_skipCodeBlock_4spaces_lines() { |
| 6958 List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ |
| 6959 new DocumentationCommentToken( |
| 6960 TokenType.SINGLE_LINE_COMMENT, "/// Code block:", 0), |
| 6961 new DocumentationCommentToken( |
| 6962 TokenType.SINGLE_LINE_COMMENT, "/// a[i] == b[i]", 0) |
| 6963 ]; |
| 6964 createParser(''); |
| 6965 List<CommentReference> references = parser.parseCommentReferences(tokens); |
| 6966 expectNotNullIfNoErrors(references); |
| 6967 listener.assertNoErrors(); |
| 6968 expect(references, isEmpty); |
| 6969 } |
| 6970 |
| 6477 void test_parseCommentReferences_skipCodeBlock_bracketed() { | 6971 void test_parseCommentReferences_skipCodeBlock_bracketed() { |
| 6478 List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ | 6972 List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ |
| 6479 new DocumentationCommentToken( | 6973 new DocumentationCommentToken( |
| 6480 TokenType.MULTI_LINE_COMMENT, "/** [:xxx [a] yyy:] [b] zzz */", 3) | 6974 TokenType.MULTI_LINE_COMMENT, "/** [:xxx [a] yyy:] [b] zzz */", 3) |
| 6481 ]; | 6975 ]; |
| 6482 List<CommentReference> references = | 6976 createParser(''); |
| 6483 parse("parseCommentReferences", <Object>[tokens], ""); | 6977 List<CommentReference> references = parser.parseCommentReferences(tokens); |
| 6978 expectNotNullIfNoErrors(references); |
| 6979 listener.assertNoErrors(); |
| 6484 expect(references, hasLength(1)); | 6980 expect(references, hasLength(1)); |
| 6485 CommentReference reference = references[0]; | 6981 CommentReference reference = references[0]; |
| 6486 expect(reference, isNotNull); | 6982 expect(reference, isNotNull); |
| 6487 expect(reference.identifier, isNotNull); | 6983 expect(reference.identifier, isNotNull); |
| 6488 expect(reference.offset, 24); | 6984 expect(reference.offset, 24); |
| 6489 } | 6985 } |
| 6490 | 6986 |
| 6987 void test_parseCommentReferences_skipCodeBlock_gitHub() { |
| 6988 List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ |
| 6989 new DocumentationCommentToken( |
| 6990 TokenType.MULTI_LINE_COMMENT, "/** `a[i]` and [b] */", 0) |
| 6991 ]; |
| 6992 createParser(''); |
| 6993 List<CommentReference> references = parser.parseCommentReferences(tokens); |
| 6994 expectNotNullIfNoErrors(references); |
| 6995 listener.assertNoErrors(); |
| 6996 expect(references, hasLength(1)); |
| 6997 CommentReference reference = references[0]; |
| 6998 expect(reference, isNotNull); |
| 6999 expect(reference.identifier, isNotNull); |
| 7000 expect(reference.offset, 16); |
| 7001 } |
| 7002 |
| 7003 void test_parseCommentReferences_skipCodeBlock_gitHub_multiLine() { |
| 7004 List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ |
| 7005 new DocumentationCommentToken( |
| 7006 TokenType.MULTI_LINE_COMMENT, |
| 7007 r''' |
| 7008 /** |
| 7009 * First. |
| 7010 * ```dart |
| 7011 * Some [int] reference. |
| 7012 * ``` |
| 7013 * Last. |
| 7014 */ |
| 7015 ''', |
| 7016 3) |
| 7017 ]; |
| 7018 createParser(''); |
| 7019 List<CommentReference> references = parser.parseCommentReferences(tokens); |
| 7020 expectNotNullIfNoErrors(references); |
| 7021 listener.assertNoErrors(); |
| 7022 expect(references, isEmpty); |
| 7023 } |
| 7024 |
| 7025 void test_parseCommentReferences_skipCodeBlock_gitHub_multiLine_lines() { |
| 7026 String commentText = r''' |
| 7027 /// First. |
| 7028 /// ```dart |
| 7029 /// Some [int] reference. |
| 7030 /// ``` |
| 7031 /// Last. |
| 7032 '''; |
| 7033 List<DocumentationCommentToken> tokens = commentText |
| 7034 .split('\n') |
| 7035 .map((line) => new DocumentationCommentToken( |
| 7036 TokenType.SINGLE_LINE_COMMENT, line, 0)) |
| 7037 .toList(); |
| 7038 createParser(''); |
| 7039 List<CommentReference> references = parser.parseCommentReferences(tokens); |
| 7040 expectNotNullIfNoErrors(references); |
| 7041 listener.assertNoErrors(); |
| 7042 expect(references, isEmpty); |
| 7043 } |
| 7044 |
| 7045 void test_parseCommentReferences_skipCodeBlock_gitHub_notTerminated() { |
| 7046 List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ |
| 7047 new DocumentationCommentToken( |
| 7048 TokenType.MULTI_LINE_COMMENT, "/** `a[i] and [b] */", 0) |
| 7049 ]; |
| 7050 createParser(''); |
| 7051 List<CommentReference> references = parser.parseCommentReferences(tokens); |
| 7052 expectNotNullIfNoErrors(references); |
| 7053 listener.assertNoErrors(); |
| 7054 expect(references, hasLength(2)); |
| 7055 } |
| 7056 |
| 6491 void test_parseCommentReferences_skipCodeBlock_spaces() { | 7057 void test_parseCommentReferences_skipCodeBlock_spaces() { |
| 6492 List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ | 7058 List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ |
| 6493 new DocumentationCommentToken(TokenType.MULTI_LINE_COMMENT, | 7059 new DocumentationCommentToken(TokenType.MULTI_LINE_COMMENT, |
| 6494 "/**\n * a[i]\n * xxx [i] zzz\n */", 3) | 7060 "/**\n * a[i]\n * xxx [i] zzz\n */", 3) |
| 6495 ]; | 7061 ]; |
| 6496 List<CommentReference> references = | 7062 createParser(''); |
| 6497 parse("parseCommentReferences", <Object>[tokens], ""); | 7063 List<CommentReference> references = parser.parseCommentReferences(tokens); |
| 7064 expectNotNullIfNoErrors(references); |
| 7065 listener.assertNoErrors(); |
| 6498 expect(references, hasLength(1)); | 7066 expect(references, hasLength(1)); |
| 6499 CommentReference reference = references[0]; | 7067 CommentReference reference = references[0]; |
| 6500 expect(reference, isNotNull); | 7068 expect(reference, isNotNull); |
| 6501 expect(reference.identifier, isNotNull); | 7069 expect(reference.identifier, isNotNull); |
| 6502 expect(reference.offset, 27); | 7070 expect(reference.offset, 27); |
| 6503 } | 7071 } |
| 6504 | 7072 |
| 6505 void test_parseCommentReferences_skipLinkDefinition() { | 7073 void test_parseCommentReferences_skipLinkDefinition() { |
| 6506 List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ | 7074 List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ |
| 6507 new DocumentationCommentToken(TokenType.MULTI_LINE_COMMENT, | 7075 new DocumentationCommentToken(TokenType.MULTI_LINE_COMMENT, |
| 6508 "/** [a]: http://www.google.com (Google) [b] zzz */", 3) | 7076 "/** [a]: http://www.google.com (Google) [b] zzz */", 3) |
| 6509 ]; | 7077 ]; |
| 6510 List<CommentReference> references = | 7078 createParser(''); |
| 6511 parse("parseCommentReferences", <Object>[tokens], ""); | 7079 List<CommentReference> references = parser.parseCommentReferences(tokens); |
| 7080 expectNotNullIfNoErrors(references); |
| 7081 listener.assertNoErrors(); |
| 6512 expect(references, hasLength(1)); | 7082 expect(references, hasLength(1)); |
| 6513 CommentReference reference = references[0]; | 7083 CommentReference reference = references[0]; |
| 6514 expect(reference, isNotNull); | 7084 expect(reference, isNotNull); |
| 6515 expect(reference.identifier, isNotNull); | 7085 expect(reference.identifier, isNotNull); |
| 6516 expect(reference.offset, 44); | 7086 expect(reference.offset, 44); |
| 6517 } | 7087 } |
| 6518 | 7088 |
| 6519 void test_parseCommentReferences_skipLinked() { | 7089 void test_parseCommentReferences_skipLinked() { |
| 6520 List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ | 7090 List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ |
| 6521 new DocumentationCommentToken(TokenType.MULTI_LINE_COMMENT, | 7091 new DocumentationCommentToken(TokenType.MULTI_LINE_COMMENT, |
| 6522 "/** [a](http://www.google.com) [b] zzz */", 3) | 7092 "/** [a](http://www.google.com) [b] zzz */", 3) |
| 6523 ]; | 7093 ]; |
| 6524 List<CommentReference> references = | 7094 createParser(''); |
| 6525 parse("parseCommentReferences", <Object>[tokens], ""); | 7095 List<CommentReference> references = parser.parseCommentReferences(tokens); |
| 7096 expectNotNullIfNoErrors(references); |
| 7097 listener.assertNoErrors(); |
| 6526 expect(references, hasLength(1)); | 7098 expect(references, hasLength(1)); |
| 6527 CommentReference reference = references[0]; | 7099 CommentReference reference = references[0]; |
| 6528 expect(reference, isNotNull); | 7100 expect(reference, isNotNull); |
| 6529 expect(reference.identifier, isNotNull); | 7101 expect(reference.identifier, isNotNull); |
| 6530 expect(reference.offset, 35); | 7102 expect(reference.offset, 35); |
| 6531 } | 7103 } |
| 6532 | 7104 |
| 6533 void test_parseCommentReferences_skipReferenceLink() { | 7105 void test_parseCommentReferences_skipReferenceLink() { |
| 6534 List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ | 7106 List<DocumentationCommentToken> tokens = <DocumentationCommentToken>[ |
| 6535 new DocumentationCommentToken( | 7107 new DocumentationCommentToken( |
| 6536 TokenType.MULTI_LINE_COMMENT, "/** [a][c] [b] zzz */", 3) | 7108 TokenType.MULTI_LINE_COMMENT, "/** [a][c] [b] zzz */", 3) |
| 6537 ]; | 7109 ]; |
| 6538 List<CommentReference> references = | 7110 createParser(''); |
| 6539 parse("parseCommentReferences", <Object>[tokens], ""); | 7111 List<CommentReference> references = parser.parseCommentReferences(tokens); |
| 7112 expectNotNullIfNoErrors(references); |
| 7113 listener.assertNoErrors(); |
| 6540 expect(references, hasLength(1)); | 7114 expect(references, hasLength(1)); |
| 6541 CommentReference reference = references[0]; | 7115 CommentReference reference = references[0]; |
| 6542 expect(reference, isNotNull); | 7116 expect(reference, isNotNull); |
| 6543 expect(reference.identifier, isNotNull); | 7117 expect(reference.identifier, isNotNull); |
| 6544 expect(reference.offset, 15); | 7118 expect(reference.offset, 15); |
| 6545 } | 7119 } |
| 6546 | 7120 |
| 6547 void test_parseCompilationUnit_abstractAsPrefix_parameterized() { | 7121 void test_parseCompilationUnit_abstractAsPrefix_parameterized() { |
| 6548 CompilationUnit unit = parse4("parseCompilationUnit", | 7122 createParser('abstract<dynamic> _abstract = new abstract.A();'); |
| 6549 "abstract<dynamic> _abstract = new abstract.A();"); | 7123 CompilationUnit unit = parser.parseCompilationUnit2(); |
| 7124 expectNotNullIfNoErrors(unit); |
| 7125 listener.assertNoErrors(); |
| 6550 expect(unit.scriptTag, isNull); | 7126 expect(unit.scriptTag, isNull); |
| 6551 expect(unit.directives, hasLength(0)); | 7127 expect(unit.directives, hasLength(0)); |
| 6552 expect(unit.declarations, hasLength(1)); | 7128 expect(unit.declarations, hasLength(1)); |
| 6553 } | 7129 } |
| 6554 | 7130 |
| 6555 void test_parseCompilationUnit_builtIn_asFunctionName() { | 7131 void test_parseCompilationUnit_builtIn_asFunctionName() { |
| 6556 parse4("parseCompilationUnit", "abstract(x) => 0;"); | 7132 ParserTestCase.parseCompilationUnit('abstract(x) => 0;'); |
| 6557 parse4("parseCompilationUnit", "as(x) => 0;"); | 7133 ParserTestCase.parseCompilationUnit('as(x) => 0;'); |
| 6558 parse4("parseCompilationUnit", "dynamic(x) => 0;"); | 7134 ParserTestCase.parseCompilationUnit('dynamic(x) => 0;'); |
| 6559 parse4("parseCompilationUnit", "export(x) => 0;"); | 7135 ParserTestCase.parseCompilationUnit('export(x) => 0;'); |
| 6560 parse4("parseCompilationUnit", "external(x) => 0;"); | 7136 ParserTestCase.parseCompilationUnit('external(x) => 0;'); |
| 6561 parse4("parseCompilationUnit", "factory(x) => 0;"); | 7137 ParserTestCase.parseCompilationUnit('factory(x) => 0;'); |
| 6562 parse4("parseCompilationUnit", "get(x) => 0;"); | 7138 ParserTestCase.parseCompilationUnit('get(x) => 0;'); |
| 6563 parse4("parseCompilationUnit", "implements(x) => 0;"); | 7139 ParserTestCase.parseCompilationUnit('implements(x) => 0;'); |
| 6564 parse4("parseCompilationUnit", "import(x) => 0;"); | 7140 ParserTestCase.parseCompilationUnit('import(x) => 0;'); |
| 6565 parse4("parseCompilationUnit", "library(x) => 0;"); | 7141 ParserTestCase.parseCompilationUnit('library(x) => 0;'); |
| 6566 parse4("parseCompilationUnit", "operator(x) => 0;"); | 7142 ParserTestCase.parseCompilationUnit('operator(x) => 0;'); |
| 6567 parse4("parseCompilationUnit", "part(x) => 0;"); | 7143 ParserTestCase.parseCompilationUnit('part(x) => 0;'); |
| 6568 parse4("parseCompilationUnit", "set(x) => 0;"); | 7144 ParserTestCase.parseCompilationUnit('set(x) => 0;'); |
| 6569 parse4("parseCompilationUnit", "static(x) => 0;"); | 7145 ParserTestCase.parseCompilationUnit('static(x) => 0;'); |
| 6570 parse4("parseCompilationUnit", "typedef(x) => 0;"); | 7146 ParserTestCase.parseCompilationUnit('typedef(x) => 0;'); |
| 6571 } | 7147 } |
| 6572 | 7148 |
| 6573 void test_parseCompilationUnit_directives_multiple() { | 7149 void test_parseCompilationUnit_directives_multiple() { |
| 6574 CompilationUnit unit = | 7150 createParser("library l;\npart 'a.dart';"); |
| 6575 parse4("parseCompilationUnit", "library l;\npart 'a.dart';"); | 7151 CompilationUnit unit = parser.parseCompilationUnit2(); |
| 7152 expectNotNullIfNoErrors(unit); |
| 7153 listener.assertNoErrors(); |
| 6576 expect(unit.scriptTag, isNull); | 7154 expect(unit.scriptTag, isNull); |
| 6577 expect(unit.directives, hasLength(2)); | 7155 expect(unit.directives, hasLength(2)); |
| 6578 expect(unit.declarations, hasLength(0)); | 7156 expect(unit.declarations, hasLength(0)); |
| 6579 } | 7157 } |
| 6580 | 7158 |
| 6581 void test_parseCompilationUnit_directives_single() { | 7159 void test_parseCompilationUnit_directives_single() { |
| 6582 CompilationUnit unit = parse4("parseCompilationUnit", "library l;"); | 7160 createParser('library l;'); |
| 7161 CompilationUnit unit = parser.parseCompilationUnit2(); |
| 7162 expectNotNullIfNoErrors(unit); |
| 7163 listener.assertNoErrors(); |
| 6583 expect(unit.scriptTag, isNull); | 7164 expect(unit.scriptTag, isNull); |
| 6584 expect(unit.directives, hasLength(1)); | 7165 expect(unit.directives, hasLength(1)); |
| 6585 expect(unit.declarations, hasLength(0)); | 7166 expect(unit.declarations, hasLength(0)); |
| 6586 } | 7167 } |
| 6587 | 7168 |
| 6588 void test_parseCompilationUnit_empty() { | 7169 void test_parseCompilationUnit_empty() { |
| 6589 CompilationUnit unit = parse4("parseCompilationUnit", ""); | 7170 createParser(''); |
| 7171 CompilationUnit unit = parser.parseCompilationUnit2(); |
| 7172 expectNotNullIfNoErrors(unit); |
| 7173 listener.assertNoErrors(); |
| 6590 expect(unit.scriptTag, isNull); | 7174 expect(unit.scriptTag, isNull); |
| 6591 expect(unit.directives, hasLength(0)); | 7175 expect(unit.directives, hasLength(0)); |
| 6592 expect(unit.declarations, hasLength(0)); | 7176 expect(unit.declarations, hasLength(0)); |
| 6593 } | 7177 } |
| 6594 | 7178 |
| 6595 void test_parseCompilationUnit_exportAsPrefix() { | 7179 void test_parseCompilationUnit_exportAsPrefix() { |
| 6596 CompilationUnit unit = | 7180 createParser('export.A _export = new export.A();'); |
| 6597 parse4("parseCompilationUnit", "export.A _export = new export.A();"); | 7181 CompilationUnit unit = parser.parseCompilationUnit2(); |
| 7182 expectNotNullIfNoErrors(unit); |
| 7183 listener.assertNoErrors(); |
| 6598 expect(unit.scriptTag, isNull); | 7184 expect(unit.scriptTag, isNull); |
| 6599 expect(unit.directives, hasLength(0)); | 7185 expect(unit.directives, hasLength(0)); |
| 6600 expect(unit.declarations, hasLength(1)); | 7186 expect(unit.declarations, hasLength(1)); |
| 6601 } | 7187 } |
| 6602 | 7188 |
| 6603 void test_parseCompilationUnit_exportAsPrefix_parameterized() { | 7189 void test_parseCompilationUnit_exportAsPrefix_parameterized() { |
| 6604 CompilationUnit unit = parse4( | 7190 createParser('export<dynamic> _export = new export.A();'); |
| 6605 "parseCompilationUnit", "export<dynamic> _export = new export.A();"); | 7191 CompilationUnit unit = parser.parseCompilationUnit2(); |
| 7192 expectNotNullIfNoErrors(unit); |
| 7193 listener.assertNoErrors(); |
| 6606 expect(unit.scriptTag, isNull); | 7194 expect(unit.scriptTag, isNull); |
| 6607 expect(unit.directives, hasLength(0)); | 7195 expect(unit.directives, hasLength(0)); |
| 6608 expect(unit.declarations, hasLength(1)); | 7196 expect(unit.declarations, hasLength(1)); |
| 6609 } | 7197 } |
| 6610 | 7198 |
| 6611 void test_parseCompilationUnit_operatorAsPrefix_parameterized() { | 7199 void test_parseCompilationUnit_operatorAsPrefix_parameterized() { |
| 6612 CompilationUnit unit = parse4("parseCompilationUnit", | 7200 createParser('operator<dynamic> _operator = new operator.A();'); |
| 6613 "operator<dynamic> _operator = new operator.A();"); | 7201 CompilationUnit unit = parser.parseCompilationUnit2(); |
| 7202 expectNotNullIfNoErrors(unit); |
| 7203 listener.assertNoErrors(); |
| 6614 expect(unit.scriptTag, isNull); | 7204 expect(unit.scriptTag, isNull); |
| 6615 expect(unit.directives, hasLength(0)); | 7205 expect(unit.directives, hasLength(0)); |
| 6616 expect(unit.declarations, hasLength(1)); | 7206 expect(unit.declarations, hasLength(1)); |
| 6617 } | 7207 } |
| 6618 | 7208 |
| 6619 void test_parseCompilationUnit_script() { | 7209 void test_parseCompilationUnit_script() { |
| 6620 CompilationUnit unit = parse4("parseCompilationUnit", "#! /bin/dart"); | 7210 createParser('#! /bin/dart'); |
| 7211 CompilationUnit unit = parser.parseCompilationUnit2(); |
| 7212 expectNotNullIfNoErrors(unit); |
| 7213 listener.assertNoErrors(); |
| 6621 expect(unit.scriptTag, isNotNull); | 7214 expect(unit.scriptTag, isNotNull); |
| 6622 expect(unit.directives, hasLength(0)); | 7215 expect(unit.directives, hasLength(0)); |
| 6623 expect(unit.declarations, hasLength(0)); | 7216 expect(unit.declarations, hasLength(0)); |
| 6624 } | 7217 } |
| 6625 | 7218 |
| 6626 void test_parseCompilationUnit_skipFunctionBody_withInterpolation() { | 7219 void test_parseCompilationUnit_skipFunctionBody_withInterpolation() { |
| 6627 ParserTestCase.parseFunctionBodies = false; | 7220 ParserTestCase.parseFunctionBodies = false; |
| 6628 CompilationUnit unit = parse4("parseCompilationUnit", "f() { '\${n}'; }"); | 7221 createParser('f() { "\${n}"; }'); |
| 7222 CompilationUnit unit = parser.parseCompilationUnit2(); |
| 7223 expectNotNullIfNoErrors(unit); |
| 7224 listener.assertNoErrors(); |
| 6629 expect(unit.scriptTag, isNull); | 7225 expect(unit.scriptTag, isNull); |
| 6630 expect(unit.declarations, hasLength(1)); | 7226 expect(unit.declarations, hasLength(1)); |
| 6631 } | 7227 } |
| 6632 | 7228 |
| 6633 void test_parseCompilationUnit_topLevelDeclaration() { | 7229 void test_parseCompilationUnit_topLevelDeclaration() { |
| 6634 CompilationUnit unit = parse4("parseCompilationUnit", "class A {}"); | 7230 createParser('class A {}'); |
| 7231 CompilationUnit unit = parser.parseCompilationUnit2(); |
| 7232 expectNotNullIfNoErrors(unit); |
| 7233 listener.assertNoErrors(); |
| 6635 expect(unit.scriptTag, isNull); | 7234 expect(unit.scriptTag, isNull); |
| 6636 expect(unit.directives, hasLength(0)); | 7235 expect(unit.directives, hasLength(0)); |
| 6637 expect(unit.declarations, hasLength(1)); | 7236 expect(unit.declarations, hasLength(1)); |
| 6638 } | 7237 } |
| 6639 | 7238 |
| 6640 void test_parseCompilationUnit_typedefAsPrefix() { | 7239 void test_parseCompilationUnit_typedefAsPrefix() { |
| 6641 CompilationUnit unit = | 7240 createParser('typedef.A _typedef = new typedef.A();'); |
| 6642 parse4("parseCompilationUnit", "typedef.A _typedef = new typedef.A();"); | 7241 CompilationUnit unit = parser.parseCompilationUnit2(); |
| 7242 expectNotNullIfNoErrors(unit); |
| 7243 listener.assertNoErrors(); |
| 6643 expect(unit.scriptTag, isNull); | 7244 expect(unit.scriptTag, isNull); |
| 6644 expect(unit.directives, hasLength(0)); | 7245 expect(unit.directives, hasLength(0)); |
| 6645 expect(unit.declarations, hasLength(1)); | 7246 expect(unit.declarations, hasLength(1)); |
| 6646 } | 7247 } |
| 6647 | 7248 |
| 6648 void test_parseCompilationUnitMember_abstractAsPrefix() { | 7249 void test_parseCompilationUnitMember_abstractAsPrefix() { |
| 6649 TopLevelVariableDeclaration declaration = parse( | 7250 createParser('abstract.A _abstract = new abstract.A();'); |
| 6650 "parseCompilationUnitMember", | 7251 CompilationUnitMember member = |
| 6651 <Object>[emptyCommentAndMetadata()], | 7252 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 6652 "abstract.A _abstract = new abstract.A();"); | 7253 expectNotNullIfNoErrors(member); |
| 7254 listener.assertNoErrors(); |
| 7255 expect(member, new isInstanceOf<TopLevelVariableDeclaration>()); |
| 7256 TopLevelVariableDeclaration declaration = member; |
| 6653 expect(declaration.semicolon, isNotNull); | 7257 expect(declaration.semicolon, isNotNull); |
| 6654 expect(declaration.variables, isNotNull); | 7258 expect(declaration.variables, isNotNull); |
| 6655 } | 7259 } |
| 6656 | 7260 |
| 6657 void test_parseCompilationUnitMember_class() { | 7261 void test_parseCompilationUnitMember_class() { |
| 6658 ClassDeclaration declaration = parse("parseCompilationUnitMember", | 7262 createParser('class A {}'); |
| 6659 <Object>[emptyCommentAndMetadata()], "class A {}"); | 7263 CompilationUnitMember member = |
| 7264 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 7265 expectNotNullIfNoErrors(member); |
| 7266 listener.assertNoErrors(); |
| 7267 expect(member, new isInstanceOf<ClassDeclaration>()); |
| 7268 ClassDeclaration declaration = member; |
| 6660 expect(declaration.name.name, "A"); | 7269 expect(declaration.name.name, "A"); |
| 6661 expect(declaration.members, hasLength(0)); | 7270 expect(declaration.members, hasLength(0)); |
| 6662 } | 7271 } |
| 6663 | 7272 |
| 6664 void test_parseCompilationUnitMember_classTypeAlias() { | 7273 void test_parseCompilationUnitMember_classTypeAlias() { |
| 6665 ClassTypeAlias alias = parse("parseCompilationUnitMember", | 7274 createParser('abstract class A = B with C;'); |
| 6666 <Object>[emptyCommentAndMetadata()], "abstract class A = B with C;"); | 7275 CompilationUnitMember member = |
| 6667 expect(alias.name.name, "A"); | 7276 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 6668 expect(alias.abstractKeyword, isNotNull); | 7277 expectNotNullIfNoErrors(member); |
| 7278 listener.assertNoErrors(); |
| 7279 expect(member, new isInstanceOf<ClassTypeAlias>()); |
| 7280 ClassTypeAlias declaration = member; |
| 7281 expect(declaration.name.name, "A"); |
| 7282 expect(declaration.abstractKeyword, isNotNull); |
| 6669 } | 7283 } |
| 6670 | 7284 |
| 6671 void test_parseCompilationUnitMember_constVariable() { | 7285 void test_parseCompilationUnitMember_constVariable() { |
| 6672 TopLevelVariableDeclaration declaration = parse( | 7286 createParser('const int x = 0;'); |
| 6673 "parseCompilationUnitMember", | 7287 CompilationUnitMember member = |
| 6674 <Object>[emptyCommentAndMetadata()], | 7288 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 6675 "const int x = 0;"); | 7289 expectNotNullIfNoErrors(member); |
| 7290 listener.assertNoErrors(); |
| 7291 expect(member, new isInstanceOf<TopLevelVariableDeclaration>()); |
| 7292 TopLevelVariableDeclaration declaration = member; |
| 6676 expect(declaration.semicolon, isNotNull); | 7293 expect(declaration.semicolon, isNotNull); |
| 6677 expect(declaration.variables, isNotNull); | 7294 expect(declaration.variables, isNotNull); |
| 6678 } | 7295 } |
| 6679 | 7296 |
| 6680 void test_parseCompilationUnitMember_finalVariable() { | 7297 void test_parseCompilationUnitMember_finalVariable() { |
| 6681 TopLevelVariableDeclaration declaration = parse( | 7298 createParser('final x = 0;'); |
| 6682 "parseCompilationUnitMember", | 7299 CompilationUnitMember member = |
| 6683 <Object>[emptyCommentAndMetadata()], | 7300 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 6684 "final x = 0;"); | 7301 expectNotNullIfNoErrors(member); |
| 7302 listener.assertNoErrors(); |
| 7303 expect(member, new isInstanceOf<TopLevelVariableDeclaration>()); |
| 7304 TopLevelVariableDeclaration declaration = member; |
| 6685 expect(declaration.semicolon, isNotNull); | 7305 expect(declaration.semicolon, isNotNull); |
| 6686 expect(declaration.variables, isNotNull); | 7306 expect(declaration.variables, isNotNull); |
| 6687 } | 7307 } |
| 6688 | 7308 |
| 6689 void test_parseCompilationUnitMember_function_external_noType() { | 7309 void test_parseCompilationUnitMember_function_external_noType() { |
| 6690 FunctionDeclaration declaration = parse("parseCompilationUnitMember", | 7310 createParser('external f();'); |
| 6691 <Object>[emptyCommentAndMetadata()], "external f();"); | 7311 CompilationUnitMember member = |
| 7312 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 7313 expectNotNullIfNoErrors(member); |
| 7314 listener.assertNoErrors(); |
| 7315 expect(member, new isInstanceOf<FunctionDeclaration>()); |
| 7316 FunctionDeclaration declaration = member; |
| 6692 expect(declaration.externalKeyword, isNotNull); | 7317 expect(declaration.externalKeyword, isNotNull); |
| 6693 expect(declaration.functionExpression, isNotNull); | 7318 expect(declaration.functionExpression, isNotNull); |
| 6694 expect(declaration.propertyKeyword, isNull); | 7319 expect(declaration.propertyKeyword, isNull); |
| 6695 } | 7320 } |
| 6696 | 7321 |
| 6697 void test_parseCompilationUnitMember_function_external_type() { | 7322 void test_parseCompilationUnitMember_function_external_type() { |
| 6698 FunctionDeclaration declaration = parse("parseCompilationUnitMember", | 7323 createParser('external int f();'); |
| 6699 <Object>[emptyCommentAndMetadata()], "external int f();"); | 7324 CompilationUnitMember member = |
| 6700 expect(declaration.externalKeyword, isNotNull); | 7325 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 7326 expectNotNullIfNoErrors(member); |
| 7327 listener.assertNoErrors(); |
| 7328 expect(member, new isInstanceOf<FunctionDeclaration>()); |
| 7329 FunctionDeclaration declaration = member; |
| 7330 expect(declaration.externalKeyword, isNotNull); |
| 7331 expect(declaration.functionExpression, isNotNull); |
| 7332 expect(declaration.propertyKeyword, isNull); |
| 7333 } |
| 7334 |
| 7335 void test_parseCompilationUnitMember_function_generic_noReturnType() { |
| 7336 enableGenericMethods = true; |
| 7337 createParser('f<E>() {}'); |
| 7338 CompilationUnitMember member = |
| 7339 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 7340 expectNotNullIfNoErrors(member); |
| 7341 listener.assertNoErrors(); |
| 7342 expect(member, new isInstanceOf<FunctionDeclaration>()); |
| 7343 FunctionDeclaration declaration = member; |
| 7344 expect(declaration.returnType, isNull); |
| 7345 expect(declaration.functionExpression.typeParameters, isNotNull); |
| 7346 } |
| 7347 |
| 7348 void |
| 7349 test_parseCompilationUnitMember_function_generic_noReturnType_annotated()
{ |
| 7350 enableGenericMethods = true; |
| 7351 createParser('f<@a E>() {}'); |
| 7352 CompilationUnitMember member = |
| 7353 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 7354 expectNotNullIfNoErrors(member); |
| 7355 listener.assertNoErrors(); |
| 7356 expect(member, new isInstanceOf<FunctionDeclaration>()); |
| 7357 FunctionDeclaration declaration = member; |
| 7358 expect(declaration.returnType, isNull); |
| 7359 expect(declaration.functionExpression.typeParameters, isNotNull); |
| 7360 } |
| 7361 |
| 7362 void test_parseCompilationUnitMember_function_generic_returnType() { |
| 7363 enableGenericMethods = true; |
| 7364 createParser('E f<E>() {}'); |
| 7365 CompilationUnitMember member = |
| 7366 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 7367 expectNotNullIfNoErrors(member); |
| 7368 listener.assertNoErrors(); |
| 7369 expect(member, new isInstanceOf<FunctionDeclaration>()); |
| 7370 FunctionDeclaration declaration = member; |
| 7371 expect(declaration.returnType, isNotNull); |
| 7372 expect(declaration.functionExpression.typeParameters, isNotNull); |
| 7373 } |
| 7374 |
| 7375 void test_parseCompilationUnitMember_function_generic_void() { |
| 7376 enableGenericMethods = true; |
| 7377 createParser('void f<T>(T t) {}'); |
| 7378 CompilationUnitMember member = |
| 7379 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 7380 expectNotNullIfNoErrors(member); |
| 7381 listener.assertNoErrors(); |
| 7382 expect(member, new isInstanceOf<FunctionDeclaration>()); |
| 7383 FunctionDeclaration declaration = member; |
| 6701 expect(declaration.functionExpression, isNotNull); | 7384 expect(declaration.functionExpression, isNotNull); |
| 6702 expect(declaration.propertyKeyword, isNull); | 7385 expect(declaration.propertyKeyword, isNull); |
| 6703 } | 7386 } |
| 6704 | 7387 |
| 6705 void test_parseCompilationUnitMember_function_noType() { | 7388 void test_parseCompilationUnitMember_function_noType() { |
| 6706 FunctionDeclaration declaration = parse("parseCompilationUnitMember", | 7389 createParser('f() {}'); |
| 6707 <Object>[emptyCommentAndMetadata()], "f() {}"); | 7390 CompilationUnitMember member = |
| 7391 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 7392 expectNotNullIfNoErrors(member); |
| 7393 listener.assertNoErrors(); |
| 7394 expect(member, new isInstanceOf<FunctionDeclaration>()); |
| 7395 FunctionDeclaration declaration = member; |
| 6708 expect(declaration.functionExpression, isNotNull); | 7396 expect(declaration.functionExpression, isNotNull); |
| 6709 expect(declaration.propertyKeyword, isNull); | 7397 expect(declaration.propertyKeyword, isNull); |
| 6710 } | 7398 } |
| 6711 | 7399 |
| 6712 void test_parseCompilationUnitMember_function_type() { | 7400 void test_parseCompilationUnitMember_function_type() { |
| 6713 FunctionDeclaration declaration = parse("parseCompilationUnitMember", | 7401 createParser('int f() {}'); |
| 6714 <Object>[emptyCommentAndMetadata()], "int f() {}"); | 7402 CompilationUnitMember member = |
| 7403 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 7404 expectNotNullIfNoErrors(member); |
| 7405 listener.assertNoErrors(); |
| 7406 expect(member, new isInstanceOf<FunctionDeclaration>()); |
| 7407 FunctionDeclaration declaration = member; |
| 6715 expect(declaration.functionExpression, isNotNull); | 7408 expect(declaration.functionExpression, isNotNull); |
| 6716 expect(declaration.propertyKeyword, isNull); | 7409 expect(declaration.propertyKeyword, isNull); |
| 6717 } | 7410 } |
| 6718 | 7411 |
| 6719 void test_parseCompilationUnitMember_function_void() { | 7412 void test_parseCompilationUnitMember_function_void() { |
| 6720 FunctionDeclaration declaration = parse("parseCompilationUnitMember", | 7413 createParser('void f() {}'); |
| 6721 <Object>[emptyCommentAndMetadata()], "void f() {}"); | 7414 CompilationUnitMember member = |
| 7415 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 7416 expectNotNullIfNoErrors(member); |
| 7417 listener.assertNoErrors(); |
| 7418 expect(member, new isInstanceOf<FunctionDeclaration>()); |
| 7419 FunctionDeclaration declaration = member; |
| 6722 expect(declaration.returnType, isNotNull); | 7420 expect(declaration.returnType, isNotNull); |
| 6723 } | 7421 } |
| 6724 | 7422 |
| 6725 void test_parseCompilationUnitMember_getter_external_noType() { | 7423 void test_parseCompilationUnitMember_getter_external_noType() { |
| 6726 FunctionDeclaration declaration = parse("parseCompilationUnitMember", | 7424 createParser('external get p;'); |
| 6727 <Object>[emptyCommentAndMetadata()], "external get p;"); | 7425 CompilationUnitMember member = |
| 7426 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 7427 expectNotNullIfNoErrors(member); |
| 7428 listener.assertNoErrors(); |
| 7429 expect(member, new isInstanceOf<FunctionDeclaration>()); |
| 7430 FunctionDeclaration declaration = member; |
| 6728 expect(declaration.externalKeyword, isNotNull); | 7431 expect(declaration.externalKeyword, isNotNull); |
| 6729 expect(declaration.functionExpression, isNotNull); | 7432 expect(declaration.functionExpression, isNotNull); |
| 6730 expect(declaration.propertyKeyword, isNotNull); | 7433 expect(declaration.propertyKeyword, isNotNull); |
| 6731 } | 7434 } |
| 6732 | 7435 |
| 6733 void test_parseCompilationUnitMember_getter_external_type() { | 7436 void test_parseCompilationUnitMember_getter_external_type() { |
| 6734 FunctionDeclaration declaration = parse("parseCompilationUnitMember", | 7437 createParser('external int get p;'); |
| 6735 <Object>[emptyCommentAndMetadata()], "external int get p;"); | 7438 CompilationUnitMember member = |
| 7439 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 7440 expectNotNullIfNoErrors(member); |
| 7441 listener.assertNoErrors(); |
| 7442 expect(member, new isInstanceOf<FunctionDeclaration>()); |
| 7443 FunctionDeclaration declaration = member; |
| 6736 expect(declaration.externalKeyword, isNotNull); | 7444 expect(declaration.externalKeyword, isNotNull); |
| 6737 expect(declaration.functionExpression, isNotNull); | 7445 expect(declaration.functionExpression, isNotNull); |
| 6738 expect(declaration.propertyKeyword, isNotNull); | 7446 expect(declaration.propertyKeyword, isNotNull); |
| 6739 } | 7447 } |
| 6740 | 7448 |
| 6741 void test_parseCompilationUnitMember_getter_noType() { | 7449 void test_parseCompilationUnitMember_getter_noType() { |
| 6742 FunctionDeclaration declaration = parse("parseCompilationUnitMember", | 7450 createParser('get p => 0;'); |
| 6743 <Object>[emptyCommentAndMetadata()], "get p => 0;"); | 7451 CompilationUnitMember member = |
| 7452 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 7453 expectNotNullIfNoErrors(member); |
| 7454 listener.assertNoErrors(); |
| 7455 expect(member, new isInstanceOf<FunctionDeclaration>()); |
| 7456 FunctionDeclaration declaration = member; |
| 6744 expect(declaration.functionExpression, isNotNull); | 7457 expect(declaration.functionExpression, isNotNull); |
| 6745 expect(declaration.propertyKeyword, isNotNull); | 7458 expect(declaration.propertyKeyword, isNotNull); |
| 6746 } | 7459 } |
| 6747 | 7460 |
| 6748 void test_parseCompilationUnitMember_getter_type() { | 7461 void test_parseCompilationUnitMember_getter_type() { |
| 6749 FunctionDeclaration declaration = parse("parseCompilationUnitMember", | 7462 createParser('int get p => 0;'); |
| 6750 <Object>[emptyCommentAndMetadata()], "int get p => 0;"); | 7463 CompilationUnitMember member = |
| 7464 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 7465 expectNotNullIfNoErrors(member); |
| 7466 listener.assertNoErrors(); |
| 7467 expect(member, new isInstanceOf<FunctionDeclaration>()); |
| 7468 FunctionDeclaration declaration = member; |
| 6751 expect(declaration.functionExpression, isNotNull); | 7469 expect(declaration.functionExpression, isNotNull); |
| 6752 expect(declaration.propertyKeyword, isNotNull); | 7470 expect(declaration.propertyKeyword, isNotNull); |
| 6753 } | 7471 } |
| 6754 | 7472 |
| 6755 void test_parseCompilationUnitMember_setter_external_noType() { | 7473 void test_parseCompilationUnitMember_setter_external_noType() { |
| 6756 FunctionDeclaration declaration = parse("parseCompilationUnitMember", | 7474 createParser('external set p(v);'); |
| 6757 <Object>[emptyCommentAndMetadata()], "external set p(v);"); | 7475 CompilationUnitMember member = |
| 7476 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 7477 expectNotNullIfNoErrors(member); |
| 7478 listener.assertNoErrors(); |
| 7479 expect(member, new isInstanceOf<FunctionDeclaration>()); |
| 7480 FunctionDeclaration declaration = member; |
| 6758 expect(declaration.externalKeyword, isNotNull); | 7481 expect(declaration.externalKeyword, isNotNull); |
| 6759 expect(declaration.functionExpression, isNotNull); | 7482 expect(declaration.functionExpression, isNotNull); |
| 6760 expect(declaration.propertyKeyword, isNotNull); | 7483 expect(declaration.propertyKeyword, isNotNull); |
| 6761 } | 7484 } |
| 6762 | 7485 |
| 6763 void test_parseCompilationUnitMember_setter_external_type() { | 7486 void test_parseCompilationUnitMember_setter_external_type() { |
| 6764 FunctionDeclaration declaration = parse("parseCompilationUnitMember", | 7487 createParser('external void set p(int v);'); |
| 6765 <Object>[emptyCommentAndMetadata()], "external void set p(int v);"); | 7488 CompilationUnitMember member = |
| 7489 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 7490 expectNotNullIfNoErrors(member); |
| 7491 listener.assertNoErrors(); |
| 7492 expect(member, new isInstanceOf<FunctionDeclaration>()); |
| 7493 FunctionDeclaration declaration = member; |
| 6766 expect(declaration.externalKeyword, isNotNull); | 7494 expect(declaration.externalKeyword, isNotNull); |
| 6767 expect(declaration.functionExpression, isNotNull); | 7495 expect(declaration.functionExpression, isNotNull); |
| 6768 expect(declaration.propertyKeyword, isNotNull); | 7496 expect(declaration.propertyKeyword, isNotNull); |
| 6769 } | 7497 } |
| 6770 | 7498 |
| 6771 void test_parseCompilationUnitMember_setter_noType() { | 7499 void test_parseCompilationUnitMember_setter_noType() { |
| 6772 FunctionDeclaration declaration = parse("parseCompilationUnitMember", | 7500 createParser('set p(v) {}'); |
| 6773 <Object>[emptyCommentAndMetadata()], "set p(v) {}"); | 7501 CompilationUnitMember member = |
| 7502 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 7503 expectNotNullIfNoErrors(member); |
| 7504 listener.assertNoErrors(); |
| 7505 expect(member, new isInstanceOf<FunctionDeclaration>()); |
| 7506 FunctionDeclaration declaration = member; |
| 6774 expect(declaration.functionExpression, isNotNull); | 7507 expect(declaration.functionExpression, isNotNull); |
| 6775 expect(declaration.propertyKeyword, isNotNull); | 7508 expect(declaration.propertyKeyword, isNotNull); |
| 6776 } | 7509 } |
| 6777 | 7510 |
| 6778 void test_parseCompilationUnitMember_setter_type() { | 7511 void test_parseCompilationUnitMember_setter_type() { |
| 6779 FunctionDeclaration declaration = parse("parseCompilationUnitMember", | 7512 createParser('void set p(int v) {}'); |
| 6780 <Object>[emptyCommentAndMetadata()], "void set p(int v) {}"); | 7513 CompilationUnitMember member = |
| 7514 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 7515 expectNotNullIfNoErrors(member); |
| 7516 listener.assertNoErrors(); |
| 7517 expect(member, new isInstanceOf<FunctionDeclaration>()); |
| 7518 FunctionDeclaration declaration = member; |
| 6781 expect(declaration.functionExpression, isNotNull); | 7519 expect(declaration.functionExpression, isNotNull); |
| 6782 expect(declaration.propertyKeyword, isNotNull); | 7520 expect(declaration.propertyKeyword, isNotNull); |
| 6783 expect(declaration.returnType, isNotNull); | 7521 expect(declaration.returnType, isNotNull); |
| 6784 } | 7522 } |
| 6785 | 7523 |
| 6786 void test_parseCompilationUnitMember_typeAlias_abstract() { | 7524 void test_parseCompilationUnitMember_typeAlias_abstract() { |
| 6787 ClassTypeAlias typeAlias = parse("parseCompilationUnitMember", | 7525 createParser('abstract class C = S with M;'); |
| 6788 <Object>[emptyCommentAndMetadata()], "abstract class C = S with M;"); | 7526 CompilationUnitMember member = |
| 7527 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 7528 expectNotNullIfNoErrors(member); |
| 7529 listener.assertNoErrors(); |
| 7530 expect(member, new isInstanceOf<ClassTypeAlias>()); |
| 7531 ClassTypeAlias typeAlias = member; |
| 6789 expect(typeAlias.typedefKeyword, isNotNull); | 7532 expect(typeAlias.typedefKeyword, isNotNull); |
| 6790 expect(typeAlias.name.name, "C"); | 7533 expect(typeAlias.name.name, "C"); |
| 6791 expect(typeAlias.typeParameters, isNull); | 7534 expect(typeAlias.typeParameters, isNull); |
| 6792 expect(typeAlias.equals, isNotNull); | 7535 expect(typeAlias.equals, isNotNull); |
| 6793 expect(typeAlias.abstractKeyword, isNotNull); | 7536 expect(typeAlias.abstractKeyword, isNotNull); |
| 6794 expect(typeAlias.superclass.name.name, "S"); | 7537 expect(typeAlias.superclass.name.name, "S"); |
| 6795 expect(typeAlias.withClause, isNotNull); | 7538 expect(typeAlias.withClause, isNotNull); |
| 6796 expect(typeAlias.implementsClause, isNull); | 7539 expect(typeAlias.implementsClause, isNull); |
| 6797 expect(typeAlias.semicolon, isNotNull); | 7540 expect(typeAlias.semicolon, isNotNull); |
| 6798 } | 7541 } |
| 6799 | 7542 |
| 6800 void test_parseCompilationUnitMember_typeAlias_generic() { | 7543 void test_parseCompilationUnitMember_typeAlias_generic() { |
| 6801 ClassTypeAlias typeAlias = parse( | 7544 createParser('class C<E> = S<E> with M<E> implements I<E>;'); |
| 6802 "parseCompilationUnitMember", | 7545 CompilationUnitMember member = |
| 6803 <Object>[emptyCommentAndMetadata()], | 7546 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 6804 "class C<E> = S<E> with M<E> implements I<E>;"); | 7547 expectNotNullIfNoErrors(member); |
| 7548 listener.assertNoErrors(); |
| 7549 expect(member, new isInstanceOf<ClassTypeAlias>()); |
| 7550 ClassTypeAlias typeAlias = member; |
| 6805 expect(typeAlias.typedefKeyword, isNotNull); | 7551 expect(typeAlias.typedefKeyword, isNotNull); |
| 6806 expect(typeAlias.name.name, "C"); | 7552 expect(typeAlias.name.name, "C"); |
| 6807 expect(typeAlias.typeParameters.typeParameters, hasLength(1)); | 7553 expect(typeAlias.typeParameters.typeParameters, hasLength(1)); |
| 6808 expect(typeAlias.equals, isNotNull); | 7554 expect(typeAlias.equals, isNotNull); |
| 6809 expect(typeAlias.abstractKeyword, isNull); | 7555 expect(typeAlias.abstractKeyword, isNull); |
| 6810 expect(typeAlias.superclass.name.name, "S"); | 7556 expect(typeAlias.superclass.name.name, "S"); |
| 6811 expect(typeAlias.withClause, isNotNull); | 7557 expect(typeAlias.withClause, isNotNull); |
| 6812 expect(typeAlias.implementsClause, isNotNull); | 7558 expect(typeAlias.implementsClause, isNotNull); |
| 6813 expect(typeAlias.semicolon, isNotNull); | 7559 expect(typeAlias.semicolon, isNotNull); |
| 6814 } | 7560 } |
| 6815 | 7561 |
| 6816 void test_parseCompilationUnitMember_typeAlias_implements() { | 7562 void test_parseCompilationUnitMember_typeAlias_implements() { |
| 6817 ClassTypeAlias typeAlias = parse( | 7563 createParser('class C = S with M implements I;'); |
| 6818 "parseCompilationUnitMember", | 7564 CompilationUnitMember member = |
| 6819 <Object>[emptyCommentAndMetadata()], | 7565 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 6820 "class C = S with M implements I;"); | 7566 expectNotNullIfNoErrors(member); |
| 7567 listener.assertNoErrors(); |
| 7568 expect(member, new isInstanceOf<ClassTypeAlias>()); |
| 7569 ClassTypeAlias typeAlias = member; |
| 6821 expect(typeAlias.typedefKeyword, isNotNull); | 7570 expect(typeAlias.typedefKeyword, isNotNull); |
| 6822 expect(typeAlias.name.name, "C"); | 7571 expect(typeAlias.name.name, "C"); |
| 6823 expect(typeAlias.typeParameters, isNull); | 7572 expect(typeAlias.typeParameters, isNull); |
| 6824 expect(typeAlias.equals, isNotNull); | 7573 expect(typeAlias.equals, isNotNull); |
| 6825 expect(typeAlias.abstractKeyword, isNull); | 7574 expect(typeAlias.abstractKeyword, isNull); |
| 6826 expect(typeAlias.superclass.name.name, "S"); | 7575 expect(typeAlias.superclass.name.name, "S"); |
| 6827 expect(typeAlias.withClause, isNotNull); | 7576 expect(typeAlias.withClause, isNotNull); |
| 6828 expect(typeAlias.implementsClause, isNotNull); | 7577 expect(typeAlias.implementsClause, isNotNull); |
| 6829 expect(typeAlias.semicolon, isNotNull); | 7578 expect(typeAlias.semicolon, isNotNull); |
| 6830 } | 7579 } |
| 6831 | 7580 |
| 6832 void test_parseCompilationUnitMember_typeAlias_noImplements() { | 7581 void test_parseCompilationUnitMember_typeAlias_noImplements() { |
| 6833 ClassTypeAlias typeAlias = parse("parseCompilationUnitMember", | 7582 createParser('class C = S with M;'); |
| 6834 <Object>[emptyCommentAndMetadata()], "class C = S with M;"); | 7583 CompilationUnitMember member = |
| 7584 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 7585 expectNotNullIfNoErrors(member); |
| 7586 listener.assertNoErrors(); |
| 7587 expect(member, new isInstanceOf<ClassTypeAlias>()); |
| 7588 ClassTypeAlias typeAlias = member; |
| 6835 expect(typeAlias.typedefKeyword, isNotNull); | 7589 expect(typeAlias.typedefKeyword, isNotNull); |
| 6836 expect(typeAlias.name.name, "C"); | 7590 expect(typeAlias.name.name, "C"); |
| 6837 expect(typeAlias.typeParameters, isNull); | 7591 expect(typeAlias.typeParameters, isNull); |
| 6838 expect(typeAlias.equals, isNotNull); | 7592 expect(typeAlias.equals, isNotNull); |
| 6839 expect(typeAlias.abstractKeyword, isNull); | 7593 expect(typeAlias.abstractKeyword, isNull); |
| 6840 expect(typeAlias.superclass.name.name, "S"); | 7594 expect(typeAlias.superclass.name.name, "S"); |
| 6841 expect(typeAlias.withClause, isNotNull); | 7595 expect(typeAlias.withClause, isNotNull); |
| 6842 expect(typeAlias.implementsClause, isNull); | 7596 expect(typeAlias.implementsClause, isNull); |
| 6843 expect(typeAlias.semicolon, isNotNull); | 7597 expect(typeAlias.semicolon, isNotNull); |
| 6844 } | 7598 } |
| 6845 | 7599 |
| 6846 void test_parseCompilationUnitMember_typedef() { | 7600 void test_parseCompilationUnitMember_typedef() { |
| 6847 FunctionTypeAlias typeAlias = parse("parseCompilationUnitMember", | 7601 createParser('typedef F();'); |
| 6848 <Object>[emptyCommentAndMetadata()], "typedef F();"); | 7602 CompilationUnitMember member = |
| 7603 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 7604 expectNotNullIfNoErrors(member); |
| 7605 listener.assertNoErrors(); |
| 7606 expect(member, new isInstanceOf<FunctionTypeAlias>()); |
| 7607 FunctionTypeAlias typeAlias = member; |
| 6849 expect(typeAlias.name.name, "F"); | 7608 expect(typeAlias.name.name, "F"); |
| 6850 expect(typeAlias.parameters.parameters, hasLength(0)); | 7609 expect(typeAlias.parameters.parameters, hasLength(0)); |
| 6851 } | 7610 } |
| 6852 | 7611 |
| 6853 void test_parseCompilationUnitMember_variable() { | 7612 void test_parseCompilationUnitMember_variable() { |
| 6854 TopLevelVariableDeclaration declaration = parse( | 7613 createParser('var x = 0;'); |
| 6855 "parseCompilationUnitMember", | 7614 CompilationUnitMember member = |
| 6856 <Object>[emptyCommentAndMetadata()], | 7615 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 6857 "var x = 0;"); | 7616 expectNotNullIfNoErrors(member); |
| 7617 listener.assertNoErrors(); |
| 7618 expect(member, new isInstanceOf<TopLevelVariableDeclaration>()); |
| 7619 TopLevelVariableDeclaration declaration = member; |
| 6858 expect(declaration.semicolon, isNotNull); | 7620 expect(declaration.semicolon, isNotNull); |
| 6859 expect(declaration.variables, isNotNull); | 7621 expect(declaration.variables, isNotNull); |
| 6860 } | 7622 } |
| 6861 | 7623 |
| 6862 void test_parseCompilationUnitMember_variableGet() { | 7624 void test_parseCompilationUnitMember_variableGet() { |
| 6863 TopLevelVariableDeclaration declaration = parse( | 7625 createParser('String get = null;'); |
| 6864 "parseCompilationUnitMember", | 7626 CompilationUnitMember member = |
| 6865 <Object>[emptyCommentAndMetadata()], | 7627 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 6866 "String get = null;"); | 7628 expectNotNullIfNoErrors(member); |
| 7629 listener.assertNoErrors(); |
| 7630 expect(member, new isInstanceOf<TopLevelVariableDeclaration>()); |
| 7631 TopLevelVariableDeclaration declaration = member; |
| 6867 expect(declaration.semicolon, isNotNull); | 7632 expect(declaration.semicolon, isNotNull); |
| 6868 expect(declaration.variables, isNotNull); | 7633 expect(declaration.variables, isNotNull); |
| 6869 } | 7634 } |
| 6870 | 7635 |
| 6871 void test_parseCompilationUnitMember_variableSet() { | 7636 void test_parseCompilationUnitMember_variableSet() { |
| 6872 TopLevelVariableDeclaration declaration = parse( | 7637 createParser('String set = null;'); |
| 6873 "parseCompilationUnitMember", | 7638 CompilationUnitMember member = |
| 6874 <Object>[emptyCommentAndMetadata()], | 7639 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 6875 "String set = null;"); | 7640 expectNotNullIfNoErrors(member); |
| 7641 listener.assertNoErrors(); |
| 7642 expect(member, new isInstanceOf<TopLevelVariableDeclaration>()); |
| 7643 TopLevelVariableDeclaration declaration = member; |
| 6876 expect(declaration.semicolon, isNotNull); | 7644 expect(declaration.semicolon, isNotNull); |
| 6877 expect(declaration.variables, isNotNull); | 7645 expect(declaration.variables, isNotNull); |
| 6878 } | 7646 } |
| 6879 | 7647 |
| 6880 void test_parseConditionalExpression() { | 7648 void test_parseConditionalExpression() { |
| 6881 ConditionalExpression expression = | 7649 createParser('x ? y : z'); |
| 6882 parse4("parseConditionalExpression", "x ? y : z"); | 7650 ConditionalExpression expression = parser.parseConditionalExpression(); |
| 7651 expectNotNullIfNoErrors(expression); |
| 7652 listener.assertNoErrors(); |
| 6883 expect(expression.condition, isNotNull); | 7653 expect(expression.condition, isNotNull); |
| 6884 expect(expression.question, isNotNull); | 7654 expect(expression.question, isNotNull); |
| 6885 expect(expression.thenExpression, isNotNull); | 7655 expect(expression.thenExpression, isNotNull); |
| 6886 expect(expression.colon, isNotNull); | 7656 expect(expression.colon, isNotNull); |
| 6887 expect(expression.elseExpression, isNotNull); | 7657 expect(expression.elseExpression, isNotNull); |
| 6888 } | 7658 } |
| 6889 | 7659 |
| 7660 void test_parseConfiguration_noOperator_dottedIdentifier() { |
| 7661 createParser("if (a.b) 'c.dart'"); |
| 7662 Configuration configuration = parser.parseConfiguration(); |
| 7663 expectNotNullIfNoErrors(configuration); |
| 7664 listener.assertNoErrors(); |
| 7665 expect(configuration.ifKeyword, isNotNull); |
| 7666 expect(configuration.leftParenthesis, isNotNull); |
| 7667 _expectDottedName(configuration.name, ["a", "b"]); |
| 7668 expect(configuration.equalToken, isNull); |
| 7669 expect(configuration.value, isNull); |
| 7670 expect(configuration.rightParenthesis, isNotNull); |
| 7671 expect(configuration.uri, isNotNull); |
| 7672 } |
| 7673 |
| 7674 void test_parseConfiguration_noOperator_simpleIdentifier() { |
| 7675 createParser("if (a) 'b.dart'"); |
| 7676 Configuration configuration = parser.parseConfiguration(); |
| 7677 expectNotNullIfNoErrors(configuration); |
| 7678 listener.assertNoErrors(); |
| 7679 expect(configuration.ifKeyword, isNotNull); |
| 7680 expect(configuration.leftParenthesis, isNotNull); |
| 7681 _expectDottedName(configuration.name, ["a"]); |
| 7682 expect(configuration.equalToken, isNull); |
| 7683 expect(configuration.value, isNull); |
| 7684 expect(configuration.rightParenthesis, isNotNull); |
| 7685 expect(configuration.uri, isNotNull); |
| 7686 } |
| 7687 |
| 7688 void test_parseConfiguration_operator_dottedIdentifier() { |
| 7689 createParser("if (a.b == 'c') 'd.dart'"); |
| 7690 Configuration configuration = parser.parseConfiguration(); |
| 7691 expectNotNullIfNoErrors(configuration); |
| 7692 listener.assertNoErrors(); |
| 7693 expect(configuration.ifKeyword, isNotNull); |
| 7694 expect(configuration.leftParenthesis, isNotNull); |
| 7695 _expectDottedName(configuration.name, ["a", "b"]); |
| 7696 expect(configuration.equalToken, isNotNull); |
| 7697 expect(configuration.value, isNotNull); |
| 7698 expect(configuration.rightParenthesis, isNotNull); |
| 7699 expect(configuration.uri, isNotNull); |
| 7700 } |
| 7701 |
| 7702 void test_parseConfiguration_operator_simpleIdentifier() { |
| 7703 createParser("if (a == 'b') 'c.dart'"); |
| 7704 Configuration configuration = parser.parseConfiguration(); |
| 7705 expectNotNullIfNoErrors(configuration); |
| 7706 listener.assertNoErrors(); |
| 7707 expect(configuration.ifKeyword, isNotNull); |
| 7708 expect(configuration.leftParenthesis, isNotNull); |
| 7709 _expectDottedName(configuration.name, ["a"]); |
| 7710 expect(configuration.equalToken, isNotNull); |
| 7711 expect(configuration.value, isNotNull); |
| 7712 expect(configuration.rightParenthesis, isNotNull); |
| 7713 expect(configuration.uri, isNotNull); |
| 7714 } |
| 7715 |
| 6890 void test_parseConstExpression_instanceCreation() { | 7716 void test_parseConstExpression_instanceCreation() { |
| 6891 InstanceCreationExpression expression = | 7717 createParser('const A()'); |
| 6892 parse4("parseConstExpression", "const A()"); | 7718 Expression expression = parser.parseConstExpression(); |
| 6893 expect(expression.keyword, isNotNull); | 7719 expectNotNullIfNoErrors(expression); |
| 6894 ConstructorName name = expression.constructorName; | 7720 listener.assertNoErrors(); |
| 7721 expect(expression, new isInstanceOf<InstanceCreationExpression>()); |
| 7722 InstanceCreationExpression instanceCreation = expression; |
| 7723 expect(instanceCreation.keyword, isNotNull); |
| 7724 ConstructorName name = instanceCreation.constructorName; |
| 6895 expect(name, isNotNull); | 7725 expect(name, isNotNull); |
| 6896 expect(name.type, isNotNull); | 7726 expect(name.type, isNotNull); |
| 6897 expect(name.period, isNull); | 7727 expect(name.period, isNull); |
| 6898 expect(name.name, isNull); | 7728 expect(name.name, isNull); |
| 6899 expect(expression.argumentList, isNotNull); | 7729 expect(instanceCreation.argumentList, isNotNull); |
| 6900 } | 7730 } |
| 6901 | 7731 |
| 6902 void test_parseConstExpression_listLiteral_typed() { | 7732 void test_parseConstExpression_listLiteral_typed() { |
| 6903 ListLiteral literal = parse4("parseConstExpression", "const <A> []"); | 7733 createParser('const <A> []'); |
| 7734 Expression expression = parser.parseConstExpression(); |
| 7735 expectNotNullIfNoErrors(expression); |
| 7736 listener.assertNoErrors(); |
| 7737 expect(expression, new isInstanceOf<ListLiteral>()); |
| 7738 ListLiteral literal = expression; |
| 6904 expect(literal.constKeyword, isNotNull); | 7739 expect(literal.constKeyword, isNotNull); |
| 6905 expect(literal.typeArguments, isNotNull); | 7740 expect(literal.typeArguments, isNotNull); |
| 6906 expect(literal.leftBracket, isNotNull); | 7741 expect(literal.leftBracket, isNotNull); |
| 7742 expect(literal.elements, hasLength(0)); |
| 7743 expect(literal.rightBracket, isNotNull); |
| 7744 } |
| 7745 |
| 7746 void test_parseConstExpression_listLiteral_typed_genericComment() { |
| 7747 enableGenericMethodComments = true; |
| 7748 createParser('const /*<A>*/ []'); |
| 7749 Expression expression = parser.parseConstExpression(); |
| 7750 expectNotNullIfNoErrors(expression); |
| 7751 listener.assertNoErrors(); |
| 7752 expect(expression, new isInstanceOf<ListLiteral>()); |
| 7753 ListLiteral literal = expression; |
| 7754 expect(literal.constKeyword, isNotNull); |
| 7755 expect(literal.typeArguments, isNotNull); |
| 7756 expect(literal.leftBracket, isNotNull); |
| 6907 expect(literal.elements, hasLength(0)); | 7757 expect(literal.elements, hasLength(0)); |
| 6908 expect(literal.rightBracket, isNotNull); | 7758 expect(literal.rightBracket, isNotNull); |
| 6909 } | 7759 } |
| 6910 | 7760 |
| 6911 void test_parseConstExpression_listLiteral_untyped() { | 7761 void test_parseConstExpression_listLiteral_untyped() { |
| 6912 ListLiteral literal = parse4("parseConstExpression", "const []"); | 7762 createParser('const []'); |
| 7763 Expression expression = parser.parseConstExpression(); |
| 7764 expectNotNullIfNoErrors(expression); |
| 7765 listener.assertNoErrors(); |
| 7766 expect(expression, new isInstanceOf<ListLiteral>()); |
| 7767 ListLiteral literal = expression; |
| 6913 expect(literal.constKeyword, isNotNull); | 7768 expect(literal.constKeyword, isNotNull); |
| 6914 expect(literal.typeArguments, isNull); | 7769 expect(literal.typeArguments, isNull); |
| 6915 expect(literal.leftBracket, isNotNull); | 7770 expect(literal.leftBracket, isNotNull); |
| 6916 expect(literal.elements, hasLength(0)); | 7771 expect(literal.elements, hasLength(0)); |
| 6917 expect(literal.rightBracket, isNotNull); | 7772 expect(literal.rightBracket, isNotNull); |
| 6918 } | 7773 } |
| 6919 | 7774 |
| 6920 void test_parseConstExpression_mapLiteral_typed() { | 7775 void test_parseConstExpression_mapLiteral_typed() { |
| 6921 MapLiteral literal = parse4("parseConstExpression", "const <A, B> {}"); | 7776 createParser('const <A, B> {}'); |
| 7777 Expression expression = parser.parseConstExpression(); |
| 7778 expectNotNullIfNoErrors(expression); |
| 7779 listener.assertNoErrors(); |
| 7780 expect(expression, new isInstanceOf<MapLiteral>()); |
| 7781 MapLiteral literal = expression; |
| 6922 expect(literal.leftBracket, isNotNull); | 7782 expect(literal.leftBracket, isNotNull); |
| 6923 expect(literal.entries, hasLength(0)); | 7783 expect(literal.entries, hasLength(0)); |
| 6924 expect(literal.rightBracket, isNotNull); | 7784 expect(literal.rightBracket, isNotNull); |
| 7785 expect(literal.typeArguments, isNotNull); |
| 7786 } |
| 7787 |
| 7788 void test_parseConstExpression_mapLiteral_typed_genericComment() { |
| 7789 enableGenericMethodComments = true; |
| 7790 createParser('const /*<A, B>*/ {}'); |
| 7791 Expression expression = parser.parseConstExpression(); |
| 7792 expectNotNullIfNoErrors(expression); |
| 7793 listener.assertNoErrors(); |
| 7794 expect(expression, new isInstanceOf<MapLiteral>()); |
| 7795 MapLiteral literal = expression; |
| 7796 expect(literal.leftBracket, isNotNull); |
| 7797 expect(literal.entries, hasLength(0)); |
| 7798 expect(literal.rightBracket, isNotNull); |
| 6925 expect(literal.typeArguments, isNotNull); | 7799 expect(literal.typeArguments, isNotNull); |
| 6926 } | 7800 } |
| 6927 | 7801 |
| 6928 void test_parseConstExpression_mapLiteral_untyped() { | 7802 void test_parseConstExpression_mapLiteral_untyped() { |
| 6929 MapLiteral literal = parse4("parseConstExpression", "const {}"); | 7803 createParser('const {}'); |
| 7804 Expression expression = parser.parseConstExpression(); |
| 7805 expectNotNullIfNoErrors(expression); |
| 7806 listener.assertNoErrors(); |
| 7807 expect(expression, new isInstanceOf<MapLiteral>()); |
| 7808 MapLiteral literal = expression; |
| 6930 expect(literal.leftBracket, isNotNull); | 7809 expect(literal.leftBracket, isNotNull); |
| 6931 expect(literal.entries, hasLength(0)); | 7810 expect(literal.entries, hasLength(0)); |
| 6932 expect(literal.rightBracket, isNotNull); | 7811 expect(literal.rightBracket, isNotNull); |
| 6933 expect(literal.typeArguments, isNull); | 7812 expect(literal.typeArguments, isNull); |
| 6934 } | 7813 } |
| 6935 | 7814 |
| 6936 void test_parseConstructor() { | 7815 void test_parseConstructor() { |
| 6937 // TODO(brianwilkerson) Implement tests for this method. | 7816 // TODO(brianwilkerson) Implement tests for this method. |
| 6938 // parse("parseConstructor", new Class[] {Parser.CommentAndMetadata.class, | 7817 } |
| 6939 // Token.class, Token.class, SimpleIdentifier.class, Token.class, | 7818 |
| 6940 // SimpleIdentifier.class, FormalParameterList.class}, new Object[] {empt
yCommentAndMetadata(), | 7819 void test_parseConstructor_assert() { |
| 6941 // null, null, null, null, null, null}, ""); | 7820 enableAssertInitializer = true; |
| 7821 createParser('C(x, y) : _x = x, assert (x < y), _y = y;'); |
| 7822 ClassMember member = parser.parseClassMember('C'); |
| 7823 expectNotNullIfNoErrors(member); |
| 7824 listener.assertNoErrors(); |
| 7825 expect(member, new isInstanceOf<ConstructorDeclaration>()); |
| 7826 ConstructorDeclaration constructor = member as ConstructorDeclaration; |
| 7827 NodeList<ConstructorInitializer> initializers = constructor.initializers; |
| 7828 expect(initializers, hasLength(2)); |
| 6942 } | 7829 } |
| 6943 | 7830 |
| 6944 void test_parseConstructor_with_pseudo_function_literal() { | 7831 void test_parseConstructor_with_pseudo_function_literal() { |
| 6945 // "(b) {}" should not be misinterpreted as a function literal even though | 7832 // "(b) {}" should not be misinterpreted as a function literal even though |
| 6946 // it looks like one. | 7833 // it looks like one. |
| 6947 ClassMember classMember = | 7834 createParser('C() : a = (b) {}'); |
| 6948 parse("parseClassMember", <Object>["C"], "C() : a = (b) {}"); | 7835 ClassMember member = parser.parseClassMember('C'); |
| 6949 EngineTestCase.assertInstanceOf((obj) => obj is ConstructorDeclaration, | 7836 expectNotNullIfNoErrors(member); |
| 6950 ConstructorDeclaration, classMember); | 7837 listener.assertNoErrors(); |
| 6951 ConstructorDeclaration constructor = classMember as ConstructorDeclaration; | 7838 expect(member, new isInstanceOf<ConstructorDeclaration>()); |
| 7839 ConstructorDeclaration constructor = member as ConstructorDeclaration; |
| 6952 NodeList<ConstructorInitializer> initializers = constructor.initializers; | 7840 NodeList<ConstructorInitializer> initializers = constructor.initializers; |
| 6953 expect(initializers, hasLength(1)); | 7841 expect(initializers, hasLength(1)); |
| 6954 ConstructorInitializer initializer = initializers[0]; | 7842 ConstructorInitializer initializer = initializers[0]; |
| 6955 EngineTestCase.assertInstanceOf((obj) => obj is ConstructorFieldInitializer, | 7843 EngineTestCase.assertInstanceOf((obj) => obj is ConstructorFieldInitializer, |
| 6956 ConstructorFieldInitializer, initializer); | 7844 ConstructorFieldInitializer, initializer); |
| 6957 EngineTestCase.assertInstanceOf( | 7845 EngineTestCase.assertInstanceOf( |
| 6958 (obj) => obj is ParenthesizedExpression, | 7846 (obj) => obj is ParenthesizedExpression, |
| 6959 ParenthesizedExpression, | 7847 ParenthesizedExpression, |
| 6960 (initializer as ConstructorFieldInitializer).expression); | 7848 (initializer as ConstructorFieldInitializer).expression); |
| 6961 EngineTestCase.assertInstanceOf( | 7849 EngineTestCase.assertInstanceOf( |
| 6962 (obj) => obj is BlockFunctionBody, BlockFunctionBody, constructor.body); | 7850 (obj) => obj is BlockFunctionBody, BlockFunctionBody, constructor.body); |
| 6963 } | 7851 } |
| 6964 | 7852 |
| 6965 void test_parseConstructorFieldInitializer_qualified() { | 7853 void test_parseConstructorFieldInitializer_qualified() { |
| 6966 ConstructorFieldInitializer invocation = | 7854 createParser('this.a = b'); |
| 6967 parse4("parseConstructorFieldInitializer", "this.a = b"); | 7855 ConstructorFieldInitializer initializer = |
| 6968 expect(invocation.equals, isNotNull); | 7856 parser.parseConstructorFieldInitializer(true); |
| 6969 expect(invocation.expression, isNotNull); | 7857 expectNotNullIfNoErrors(initializer); |
| 6970 expect(invocation.fieldName, isNotNull); | 7858 listener.assertNoErrors(); |
| 6971 expect(invocation.thisKeyword, isNotNull); | 7859 expect(initializer.equals, isNotNull); |
| 6972 expect(invocation.period, isNotNull); | 7860 expect(initializer.expression, isNotNull); |
| 7861 expect(initializer.fieldName, isNotNull); |
| 7862 expect(initializer.thisKeyword, isNotNull); |
| 7863 expect(initializer.period, isNotNull); |
| 6973 } | 7864 } |
| 6974 | 7865 |
| 6975 void test_parseConstructorFieldInitializer_unqualified() { | 7866 void test_parseConstructorFieldInitializer_unqualified() { |
| 6976 ConstructorFieldInitializer invocation = | 7867 createParser('a = b'); |
| 6977 parse4("parseConstructorFieldInitializer", "a = b"); | 7868 ConstructorFieldInitializer initializer = |
| 6978 expect(invocation.equals, isNotNull); | 7869 parser.parseConstructorFieldInitializer(false); |
| 6979 expect(invocation.expression, isNotNull); | 7870 expectNotNullIfNoErrors(initializer); |
| 6980 expect(invocation.fieldName, isNotNull); | 7871 listener.assertNoErrors(); |
| 6981 expect(invocation.thisKeyword, isNull); | 7872 expect(initializer.equals, isNotNull); |
| 6982 expect(invocation.period, isNull); | 7873 expect(initializer.expression, isNotNull); |
| 7874 expect(initializer.fieldName, isNotNull); |
| 7875 expect(initializer.thisKeyword, isNull); |
| 7876 expect(initializer.period, isNull); |
| 6983 } | 7877 } |
| 6984 | 7878 |
| 6985 void test_parseConstructorName_named_noPrefix() { | 7879 void test_parseConstructorName_named_noPrefix() { |
| 6986 ConstructorName name = parse4("parseConstructorName", "A.n;"); | 7880 createParser('A.n;'); |
| 7881 ConstructorName name = parser.parseConstructorName(); |
| 7882 expectNotNullIfNoErrors(name); |
| 7883 listener.assertNoErrors(); |
| 6987 expect(name.type, isNotNull); | 7884 expect(name.type, isNotNull); |
| 6988 expect(name.period, isNull); | 7885 expect(name.period, isNull); |
| 6989 expect(name.name, isNull); | 7886 expect(name.name, isNull); |
| 6990 } | 7887 } |
| 6991 | 7888 |
| 6992 void test_parseConstructorName_named_prefixed() { | 7889 void test_parseConstructorName_named_prefixed() { |
| 6993 ConstructorName name = parse4("parseConstructorName", "p.A.n;"); | 7890 createParser('p.A.n;'); |
| 7891 ConstructorName name = parser.parseConstructorName(); |
| 7892 expectNotNullIfNoErrors(name); |
| 7893 listener.assertNoErrors(); |
| 6994 expect(name.type, isNotNull); | 7894 expect(name.type, isNotNull); |
| 6995 expect(name.period, isNotNull); | 7895 expect(name.period, isNotNull); |
| 6996 expect(name.name, isNotNull); | 7896 expect(name.name, isNotNull); |
| 6997 } | 7897 } |
| 6998 | 7898 |
| 6999 void test_parseConstructorName_unnamed_noPrefix() { | 7899 void test_parseConstructorName_unnamed_noPrefix() { |
| 7000 ConstructorName name = parse4("parseConstructorName", "A;"); | 7900 createParser('A;'); |
| 7901 ConstructorName name = parser.parseConstructorName(); |
| 7902 expectNotNullIfNoErrors(name); |
| 7903 listener.assertNoErrors(); |
| 7001 expect(name.type, isNotNull); | 7904 expect(name.type, isNotNull); |
| 7002 expect(name.period, isNull); | 7905 expect(name.period, isNull); |
| 7003 expect(name.name, isNull); | 7906 expect(name.name, isNull); |
| 7004 } | 7907 } |
| 7005 | 7908 |
| 7006 void test_parseConstructorName_unnamed_prefixed() { | 7909 void test_parseConstructorName_unnamed_prefixed() { |
| 7007 ConstructorName name = parse4("parseConstructorName", "p.A;"); | 7910 createParser('p.A;'); |
| 7911 ConstructorName name = parser.parseConstructorName(); |
| 7912 expectNotNullIfNoErrors(name); |
| 7913 listener.assertNoErrors(); |
| 7008 expect(name.type, isNotNull); | 7914 expect(name.type, isNotNull); |
| 7009 expect(name.period, isNull); | 7915 expect(name.period, isNull); |
| 7010 expect(name.name, isNull); | 7916 expect(name.name, isNull); |
| 7011 } | 7917 } |
| 7012 | 7918 |
| 7013 void test_parseContinueStatement_label() { | 7919 void test_parseContinueStatement_label() { |
| 7014 ContinueStatement statement = parse4("parseContinueStatement", | 7920 createParser('continue foo;'); |
| 7015 "continue foo;", [ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP]); | 7921 ContinueStatement statement = parser.parseContinueStatement(); |
| 7922 expectNotNullIfNoErrors(statement); |
| 7923 listener.assertErrorsWithCodes([ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP]); |
| 7016 expect(statement.continueKeyword, isNotNull); | 7924 expect(statement.continueKeyword, isNotNull); |
| 7017 expect(statement.label, isNotNull); | 7925 expect(statement.label, isNotNull); |
| 7018 expect(statement.semicolon, isNotNull); | 7926 expect(statement.semicolon, isNotNull); |
| 7019 } | 7927 } |
| 7020 | 7928 |
| 7021 void test_parseContinueStatement_noLabel() { | 7929 void test_parseContinueStatement_noLabel() { |
| 7022 ContinueStatement statement = parse4("parseContinueStatement", "continue;", | 7930 createParser('continue;'); |
| 7023 [ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP]); | 7931 ContinueStatement statement = parser.parseContinueStatement(); |
| 7932 expectNotNullIfNoErrors(statement); |
| 7933 listener.assertErrorsWithCodes([ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP]); |
| 7024 expect(statement.continueKeyword, isNotNull); | 7934 expect(statement.continueKeyword, isNotNull); |
| 7025 expect(statement.label, isNull); | 7935 expect(statement.label, isNull); |
| 7026 expect(statement.semicolon, isNotNull); | 7936 expect(statement.semicolon, isNotNull); |
| 7027 } | 7937 } |
| 7028 | 7938 |
| 7029 void test_parseDirective_export() { | 7939 void test_parseDirective_export() { |
| 7030 ExportDirective directive = parse("parseDirective", | 7940 createParser("export 'lib/lib.dart';"); |
| 7031 <Object>[emptyCommentAndMetadata()], "export 'lib/lib.dart';"); | 7941 Directive directive = parser.parseDirective(emptyCommentAndMetadata()); |
| 7032 expect(directive.keyword, isNotNull); | 7942 expectNotNullIfNoErrors(directive); |
| 7033 expect(directive.uri, isNotNull); | 7943 listener.assertNoErrors(); |
| 7034 expect(directive.combinators, hasLength(0)); | 7944 expect(directive, new isInstanceOf<ExportDirective>()); |
| 7035 expect(directive.semicolon, isNotNull); | 7945 ExportDirective exportDirective = directive; |
| 7946 expect(exportDirective.keyword, isNotNull); |
| 7947 expect(exportDirective.uri, isNotNull); |
| 7948 expect(exportDirective.combinators, hasLength(0)); |
| 7949 expect(exportDirective.semicolon, isNotNull); |
| 7036 } | 7950 } |
| 7037 | 7951 |
| 7038 void test_parseDirective_import() { | 7952 void test_parseDirective_import() { |
| 7039 ImportDirective directive = parse("parseDirective", | 7953 createParser("import 'lib/lib.dart';"); |
| 7040 <Object>[emptyCommentAndMetadata()], "import 'lib/lib.dart';"); | 7954 Directive directive = parser.parseDirective(emptyCommentAndMetadata()); |
| 7041 expect(directive.keyword, isNotNull); | 7955 expectNotNullIfNoErrors(directive); |
| 7042 expect(directive.uri, isNotNull); | 7956 listener.assertNoErrors(); |
| 7043 expect(directive.asKeyword, isNull); | 7957 expect(directive, new isInstanceOf<ImportDirective>()); |
| 7044 expect(directive.prefix, isNull); | 7958 ImportDirective importDirective = directive; |
| 7045 expect(directive.combinators, hasLength(0)); | 7959 expect(importDirective.keyword, isNotNull); |
| 7046 expect(directive.semicolon, isNotNull); | 7960 expect(importDirective.uri, isNotNull); |
| 7961 expect(importDirective.asKeyword, isNull); |
| 7962 expect(importDirective.prefix, isNull); |
| 7963 expect(importDirective.combinators, hasLength(0)); |
| 7964 expect(importDirective.semicolon, isNotNull); |
| 7047 } | 7965 } |
| 7048 | 7966 |
| 7049 void test_parseDirective_library() { | 7967 void test_parseDirective_library() { |
| 7050 LibraryDirective directive = parse( | 7968 createParser("library l;"); |
| 7051 "parseDirective", <Object>[emptyCommentAndMetadata()], "library l;"); | 7969 Directive directive = parser.parseDirective(emptyCommentAndMetadata()); |
| 7052 expect(directive.libraryKeyword, isNotNull); | 7970 expectNotNullIfNoErrors(directive); |
| 7053 expect(directive.name, isNotNull); | 7971 listener.assertNoErrors(); |
| 7054 expect(directive.semicolon, isNotNull); | 7972 expect(directive, new isInstanceOf<LibraryDirective>()); |
| 7973 LibraryDirective libraryDirective = directive; |
| 7974 expect(libraryDirective.libraryKeyword, isNotNull); |
| 7975 expect(libraryDirective.name, isNotNull); |
| 7976 expect(libraryDirective.semicolon, isNotNull); |
| 7055 } | 7977 } |
| 7056 | 7978 |
| 7057 void test_parseDirective_part() { | 7979 void test_parseDirective_part() { |
| 7058 PartDirective directive = parse("parseDirective", | 7980 createParser("part 'lib/lib.dart';"); |
| 7059 <Object>[emptyCommentAndMetadata()], "part 'lib/lib.dart';"); | 7981 Directive directive = parser.parseDirective(emptyCommentAndMetadata()); |
| 7060 expect(directive.partKeyword, isNotNull); | 7982 expectNotNullIfNoErrors(directive); |
| 7061 expect(directive.uri, isNotNull); | 7983 listener.assertNoErrors(); |
| 7062 expect(directive.semicolon, isNotNull); | 7984 expect(directive, new isInstanceOf<PartDirective>()); |
| 7985 PartDirective partDirective = directive; |
| 7986 expect(partDirective.partKeyword, isNotNull); |
| 7987 expect(partDirective.uri, isNotNull); |
| 7988 expect(partDirective.semicolon, isNotNull); |
| 7063 } | 7989 } |
| 7064 | 7990 |
| 7065 void test_parseDirective_partOf() { | 7991 void test_parseDirective_partOf() { |
| 7066 PartOfDirective directive = parse( | 7992 createParser("part of l;"); |
| 7067 "parseDirective", <Object>[emptyCommentAndMetadata()], "part of l;"); | 7993 Directive directive = parser.parseDirective(emptyCommentAndMetadata()); |
| 7068 expect(directive.partKeyword, isNotNull); | 7994 expectNotNullIfNoErrors(directive); |
| 7069 expect(directive.ofKeyword, isNotNull); | 7995 listener.assertNoErrors(); |
| 7070 expect(directive.libraryName, isNotNull); | 7996 expect(directive, new isInstanceOf<PartOfDirective>()); |
| 7071 expect(directive.semicolon, isNotNull); | 7997 PartOfDirective partOfDirective = directive; |
| 7998 expect(partOfDirective.partKeyword, isNotNull); |
| 7999 expect(partOfDirective.ofKeyword, isNotNull); |
| 8000 expect(partOfDirective.libraryName, isNotNull); |
| 8001 expect(partOfDirective.semicolon, isNotNull); |
| 7072 } | 8002 } |
| 7073 | 8003 |
| 7074 void test_parseDirectives_complete() { | 8004 void test_parseDirectives_complete() { |
| 7075 CompilationUnit unit = | 8005 CompilationUnit unit = |
| 7076 _parseDirectives("#! /bin/dart\nlibrary l;\nclass A {}"); | 8006 _parseDirectives("#! /bin/dart\nlibrary l;\nclass A {}"); |
| 7077 expect(unit.scriptTag, isNotNull); | 8007 expect(unit.scriptTag, isNotNull); |
| 7078 expect(unit.directives, hasLength(1)); | 8008 expect(unit.directives, hasLength(1)); |
| 7079 } | 8009 } |
| 7080 | 8010 |
| 7081 void test_parseDirectives_empty() { | 8011 void test_parseDirectives_empty() { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 7109 expect(unit.directives, hasLength(1)); | 8039 expect(unit.directives, hasLength(1)); |
| 7110 } | 8040 } |
| 7111 | 8041 |
| 7112 void test_parseDirectives_topLevelDeclaration() { | 8042 void test_parseDirectives_topLevelDeclaration() { |
| 7113 CompilationUnit unit = _parseDirectives("class A {}"); | 8043 CompilationUnit unit = _parseDirectives("class A {}"); |
| 7114 expect(unit.scriptTag, isNull); | 8044 expect(unit.scriptTag, isNull); |
| 7115 expect(unit.directives, hasLength(0)); | 8045 expect(unit.directives, hasLength(0)); |
| 7116 } | 8046 } |
| 7117 | 8047 |
| 7118 void test_parseDocumentationComment_block() { | 8048 void test_parseDocumentationComment_block() { |
| 7119 Comment comment = parse4("parseDocumentationComment", "/** */ class"); | 8049 createParser('/** */ class'); |
| 8050 Comment comment = parser |
| 8051 .parseDocumentationComment(parser.parseDocumentationCommentTokens()); |
| 8052 expectNotNullIfNoErrors(comment); |
| 8053 listener.assertNoErrors(); |
| 7120 expect(comment.isBlock, isFalse); | 8054 expect(comment.isBlock, isFalse); |
| 7121 expect(comment.isDocumentation, isTrue); | 8055 expect(comment.isDocumentation, isTrue); |
| 7122 expect(comment.isEndOfLine, isFalse); | 8056 expect(comment.isEndOfLine, isFalse); |
| 7123 } | 8057 } |
| 7124 | 8058 |
| 7125 void test_parseDocumentationComment_block_withReference() { | 8059 void test_parseDocumentationComment_block_withReference() { |
| 7126 Comment comment = parse4("parseDocumentationComment", "/** [a] */ class"); | 8060 createParser('/** [a] */ class'); |
| 8061 Comment comment = parser |
| 8062 .parseDocumentationComment(parser.parseDocumentationCommentTokens()); |
| 8063 expectNotNullIfNoErrors(comment); |
| 8064 listener.assertNoErrors(); |
| 7127 expect(comment.isBlock, isFalse); | 8065 expect(comment.isBlock, isFalse); |
| 7128 expect(comment.isDocumentation, isTrue); | 8066 expect(comment.isDocumentation, isTrue); |
| 7129 expect(comment.isEndOfLine, isFalse); | 8067 expect(comment.isEndOfLine, isFalse); |
| 7130 NodeList<CommentReference> references = comment.references; | 8068 NodeList<CommentReference> references = comment.references; |
| 7131 expect(references, hasLength(1)); | 8069 expect(references, hasLength(1)); |
| 7132 CommentReference reference = references[0]; | 8070 CommentReference reference = references[0]; |
| 7133 expect(reference, isNotNull); | 8071 expect(reference, isNotNull); |
| 7134 expect(reference.offset, 5); | 8072 expect(reference.offset, 5); |
| 7135 } | 8073 } |
| 7136 | 8074 |
| 7137 void test_parseDocumentationComment_endOfLine() { | 8075 void test_parseDocumentationComment_endOfLine() { |
| 7138 Comment comment = parse4("parseDocumentationComment", "/// \n/// \n class"); | 8076 createParser('/// \n/// \n class'); |
| 8077 Comment comment = parser |
| 8078 .parseDocumentationComment(parser.parseDocumentationCommentTokens()); |
| 8079 expectNotNullIfNoErrors(comment); |
| 8080 listener.assertNoErrors(); |
| 7139 expect(comment.isBlock, isFalse); | 8081 expect(comment.isBlock, isFalse); |
| 7140 expect(comment.isDocumentation, isTrue); | 8082 expect(comment.isDocumentation, isTrue); |
| 7141 expect(comment.isEndOfLine, isFalse); | 8083 expect(comment.isEndOfLine, isFalse); |
| 7142 } | 8084 } |
| 7143 | 8085 |
| 7144 void test_parseDoStatement() { | 8086 void test_parseDoStatement() { |
| 7145 DoStatement statement = parse4("parseDoStatement", "do {} while (x);"); | 8087 createParser('do {} while (x);'); |
| 8088 DoStatement statement = parser.parseDoStatement(); |
| 8089 expectNotNullIfNoErrors(statement); |
| 8090 listener.assertNoErrors(); |
| 7146 expect(statement.doKeyword, isNotNull); | 8091 expect(statement.doKeyword, isNotNull); |
| 7147 expect(statement.body, isNotNull); | 8092 expect(statement.body, isNotNull); |
| 7148 expect(statement.whileKeyword, isNotNull); | 8093 expect(statement.whileKeyword, isNotNull); |
| 7149 expect(statement.leftParenthesis, isNotNull); | 8094 expect(statement.leftParenthesis, isNotNull); |
| 7150 expect(statement.condition, isNotNull); | 8095 expect(statement.condition, isNotNull); |
| 7151 expect(statement.rightParenthesis, isNotNull); | 8096 expect(statement.rightParenthesis, isNotNull); |
| 7152 expect(statement.semicolon, isNotNull); | 8097 expect(statement.semicolon, isNotNull); |
| 7153 } | 8098 } |
| 7154 | 8099 |
| 8100 void test_parseDottedName_multiple() { |
| 8101 createParser('a.b.c'); |
| 8102 DottedName name = parser.parseDottedName(); |
| 8103 expectNotNullIfNoErrors(name); |
| 8104 listener.assertNoErrors(); |
| 8105 _expectDottedName(name, ["a", "b", "c"]); |
| 8106 } |
| 8107 |
| 8108 void test_parseDottedName_single() { |
| 8109 createParser('a'); |
| 8110 DottedName name = parser.parseDottedName(); |
| 8111 expectNotNullIfNoErrors(name); |
| 8112 listener.assertNoErrors(); |
| 8113 _expectDottedName(name, ["a"]); |
| 8114 } |
| 8115 |
| 7155 void test_parseEmptyStatement() { | 8116 void test_parseEmptyStatement() { |
| 7156 EmptyStatement statement = parse4("parseEmptyStatement", ";"); | 8117 createParser(';'); |
| 8118 EmptyStatement statement = parser.parseEmptyStatement(); |
| 8119 expectNotNullIfNoErrors(statement); |
| 8120 listener.assertNoErrors(); |
| 7157 expect(statement.semicolon, isNotNull); | 8121 expect(statement.semicolon, isNotNull); |
| 7158 } | 8122 } |
| 7159 | 8123 |
| 7160 void test_parseEnumDeclaration_one() { | 8124 void test_parseEnumDeclaration_one() { |
| 7161 EnumDeclaration declaration = parse("parseEnumDeclaration", | 8125 createParser("enum E {ONE}"); |
| 7162 <Object>[emptyCommentAndMetadata()], "enum E {ONE}"); | 8126 EnumDeclaration declaration = |
| 8127 parser.parseEnumDeclaration(emptyCommentAndMetadata()); |
| 8128 expectNotNullIfNoErrors(declaration); |
| 8129 listener.assertNoErrors(); |
| 7163 expect(declaration.documentationComment, isNull); | 8130 expect(declaration.documentationComment, isNull); |
| 7164 expect(declaration.enumKeyword, isNotNull); | 8131 expect(declaration.enumKeyword, isNotNull); |
| 7165 expect(declaration.leftBracket, isNotNull); | 8132 expect(declaration.leftBracket, isNotNull); |
| 7166 expect(declaration.name, isNotNull); | 8133 expect(declaration.name, isNotNull); |
| 7167 expect(declaration.constants, hasLength(1)); | 8134 expect(declaration.constants, hasLength(1)); |
| 7168 expect(declaration.rightBracket, isNotNull); | 8135 expect(declaration.rightBracket, isNotNull); |
| 7169 } | 8136 } |
| 7170 | 8137 |
| 7171 void test_parseEnumDeclaration_trailingComma() { | 8138 void test_parseEnumDeclaration_trailingComma() { |
| 7172 EnumDeclaration declaration = parse("parseEnumDeclaration", | 8139 createParser("enum E {ONE,}"); |
| 7173 <Object>[emptyCommentAndMetadata()], "enum E {ONE,}"); | 8140 EnumDeclaration declaration = |
| 8141 parser.parseEnumDeclaration(emptyCommentAndMetadata()); |
| 8142 expectNotNullIfNoErrors(declaration); |
| 8143 listener.assertNoErrors(); |
| 7174 expect(declaration.documentationComment, isNull); | 8144 expect(declaration.documentationComment, isNull); |
| 7175 expect(declaration.enumKeyword, isNotNull); | 8145 expect(declaration.enumKeyword, isNotNull); |
| 7176 expect(declaration.leftBracket, isNotNull); | 8146 expect(declaration.leftBracket, isNotNull); |
| 7177 expect(declaration.name, isNotNull); | 8147 expect(declaration.name, isNotNull); |
| 7178 expect(declaration.constants, hasLength(1)); | 8148 expect(declaration.constants, hasLength(1)); |
| 7179 expect(declaration.rightBracket, isNotNull); | 8149 expect(declaration.rightBracket, isNotNull); |
| 7180 } | 8150 } |
| 7181 | 8151 |
| 7182 void test_parseEnumDeclaration_two() { | 8152 void test_parseEnumDeclaration_two() { |
| 7183 EnumDeclaration declaration = parse("parseEnumDeclaration", | 8153 createParser("enum E {ONE, TWO}"); |
| 7184 <Object>[emptyCommentAndMetadata()], "enum E {ONE, TWO}"); | 8154 EnumDeclaration declaration = |
| 8155 parser.parseEnumDeclaration(emptyCommentAndMetadata()); |
| 8156 expectNotNullIfNoErrors(declaration); |
| 8157 listener.assertNoErrors(); |
| 7185 expect(declaration.documentationComment, isNull); | 8158 expect(declaration.documentationComment, isNull); |
| 7186 expect(declaration.enumKeyword, isNotNull); | 8159 expect(declaration.enumKeyword, isNotNull); |
| 7187 expect(declaration.leftBracket, isNotNull); | 8160 expect(declaration.leftBracket, isNotNull); |
| 7188 expect(declaration.name, isNotNull); | 8161 expect(declaration.name, isNotNull); |
| 7189 expect(declaration.constants, hasLength(2)); | 8162 expect(declaration.constants, hasLength(2)); |
| 7190 expect(declaration.rightBracket, isNotNull); | 8163 expect(declaration.rightBracket, isNotNull); |
| 7191 } | 8164 } |
| 7192 | 8165 |
| 7193 void test_parseEqualityExpression_normal() { | 8166 void test_parseEqualityExpression_normal() { |
| 7194 BinaryExpression expression = parse4("parseEqualityExpression", "x == y"); | 8167 createParser('x == y'); |
| 8168 BinaryExpression expression = parser.parseEqualityExpression(); |
| 8169 expectNotNullIfNoErrors(expression); |
| 8170 listener.assertNoErrors(); |
| 7195 expect(expression.leftOperand, isNotNull); | 8171 expect(expression.leftOperand, isNotNull); |
| 7196 expect(expression.operator, isNotNull); | 8172 expect(expression.operator, isNotNull); |
| 7197 expect(expression.operator.type, TokenType.EQ_EQ); | 8173 expect(expression.operator.type, TokenType.EQ_EQ); |
| 7198 expect(expression.rightOperand, isNotNull); | 8174 expect(expression.rightOperand, isNotNull); |
| 7199 } | 8175 } |
| 7200 | 8176 |
| 7201 void test_parseEqualityExpression_super() { | 8177 void test_parseEqualityExpression_super() { |
| 7202 BinaryExpression expression = | 8178 createParser('super == y'); |
| 7203 parse4("parseEqualityExpression", "super == y"); | 8179 BinaryExpression expression = parser.parseEqualityExpression(); |
| 7204 EngineTestCase.assertInstanceOf((obj) => obj is SuperExpression, | 8180 expectNotNullIfNoErrors(expression); |
| 7205 SuperExpression, expression.leftOperand); | 8181 listener.assertNoErrors(); |
| 8182 expect(expression.leftOperand, new isInstanceOf<SuperExpression>()); |
| 7206 expect(expression.operator, isNotNull); | 8183 expect(expression.operator, isNotNull); |
| 7207 expect(expression.operator.type, TokenType.EQ_EQ); | 8184 expect(expression.operator.type, TokenType.EQ_EQ); |
| 7208 expect(expression.rightOperand, isNotNull); | 8185 expect(expression.rightOperand, isNotNull); |
| 7209 } | 8186 } |
| 7210 | 8187 |
| 8188 void test_parseExportDirective_configuration_multiple() { |
| 8189 createParser("export 'lib/lib.dart' if (a) 'b.dart' if (c) 'd.dart';"); |
| 8190 ExportDirective directive = |
| 8191 parser.parseExportDirective(emptyCommentAndMetadata()); |
| 8192 expectNotNullIfNoErrors(directive); |
| 8193 listener.assertNoErrors(); |
| 8194 expect(directive.keyword, isNotNull); |
| 8195 expect(directive.uri, isNotNull); |
| 8196 expect(directive.configurations, hasLength(2)); |
| 8197 _expectDottedName(directive.configurations[0].name, ['a']); |
| 8198 _expectDottedName(directive.configurations[1].name, ['c']); |
| 8199 expect(directive.combinators, hasLength(0)); |
| 8200 expect(directive.semicolon, isNotNull); |
| 8201 } |
| 8202 |
| 8203 void test_parseExportDirective_configuration_single() { |
| 8204 createParser("export 'lib/lib.dart' if (a.b == 'c.dart') '';"); |
| 8205 ExportDirective directive = |
| 8206 parser.parseExportDirective(emptyCommentAndMetadata()); |
| 8207 expectNotNullIfNoErrors(directive); |
| 8208 listener.assertNoErrors(); |
| 8209 expect(directive.keyword, isNotNull); |
| 8210 expect(directive.uri, isNotNull); |
| 8211 expect(directive.configurations, hasLength(1)); |
| 8212 _expectDottedName(directive.configurations[0].name, ['a', 'b']); |
| 8213 expect(directive.combinators, hasLength(0)); |
| 8214 expect(directive.semicolon, isNotNull); |
| 8215 } |
| 8216 |
| 7211 void test_parseExportDirective_hide() { | 8217 void test_parseExportDirective_hide() { |
| 7212 ExportDirective directive = parse( | 8218 createParser("export 'lib/lib.dart' hide A, B;"); |
| 7213 "parseExportDirective", | 8219 ExportDirective directive = |
| 7214 <Object>[emptyCommentAndMetadata()], | 8220 parser.parseExportDirective(emptyCommentAndMetadata()); |
| 7215 "export 'lib/lib.dart' hide A, B;"); | 8221 expectNotNullIfNoErrors(directive); |
| 8222 listener.assertNoErrors(); |
| 7216 expect(directive.keyword, isNotNull); | 8223 expect(directive.keyword, isNotNull); |
| 7217 expect(directive.uri, isNotNull); | 8224 expect(directive.uri, isNotNull); |
| 7218 expect(directive.combinators, hasLength(1)); | 8225 expect(directive.combinators, hasLength(1)); |
| 7219 expect(directive.semicolon, isNotNull); | 8226 expect(directive.semicolon, isNotNull); |
| 7220 } | 8227 } |
| 7221 | 8228 |
| 7222 void test_parseExportDirective_hide_show() { | 8229 void test_parseExportDirective_hide_show() { |
| 7223 ExportDirective directive = parse( | 8230 createParser("export 'lib/lib.dart' hide A show B;"); |
| 7224 "parseExportDirective", | 8231 ExportDirective directive = |
| 7225 <Object>[emptyCommentAndMetadata()], | 8232 parser.parseExportDirective(emptyCommentAndMetadata()); |
| 7226 "export 'lib/lib.dart' hide A show B;"); | 8233 expectNotNullIfNoErrors(directive); |
| 8234 listener.assertNoErrors(); |
| 7227 expect(directive.keyword, isNotNull); | 8235 expect(directive.keyword, isNotNull); |
| 7228 expect(directive.uri, isNotNull); | 8236 expect(directive.uri, isNotNull); |
| 7229 expect(directive.combinators, hasLength(2)); | 8237 expect(directive.combinators, hasLength(2)); |
| 7230 expect(directive.semicolon, isNotNull); | 8238 expect(directive.semicolon, isNotNull); |
| 7231 } | 8239 } |
| 7232 | 8240 |
| 7233 void test_parseExportDirective_noCombinator() { | 8241 void test_parseExportDirective_noCombinator() { |
| 7234 ExportDirective directive = parse("parseExportDirective", | 8242 createParser("export 'lib/lib.dart';"); |
| 7235 <Object>[emptyCommentAndMetadata()], "export 'lib/lib.dart';"); | 8243 ExportDirective directive = |
| 8244 parser.parseExportDirective(emptyCommentAndMetadata()); |
| 8245 expectNotNullIfNoErrors(directive); |
| 8246 listener.assertNoErrors(); |
| 7236 expect(directive.keyword, isNotNull); | 8247 expect(directive.keyword, isNotNull); |
| 7237 expect(directive.uri, isNotNull); | 8248 expect(directive.uri, isNotNull); |
| 7238 expect(directive.combinators, hasLength(0)); | 8249 expect(directive.combinators, hasLength(0)); |
| 7239 expect(directive.semicolon, isNotNull); | 8250 expect(directive.semicolon, isNotNull); |
| 7240 } | 8251 } |
| 7241 | 8252 |
| 7242 void test_parseExportDirective_show() { | 8253 void test_parseExportDirective_show() { |
| 7243 ExportDirective directive = parse( | 8254 createParser("export 'lib/lib.dart' show A, B;"); |
| 7244 "parseExportDirective", | 8255 ExportDirective directive = |
| 7245 <Object>[emptyCommentAndMetadata()], | 8256 parser.parseExportDirective(emptyCommentAndMetadata()); |
| 7246 "export 'lib/lib.dart' show A, B;"); | 8257 expectNotNullIfNoErrors(directive); |
| 8258 listener.assertNoErrors(); |
| 7247 expect(directive.keyword, isNotNull); | 8259 expect(directive.keyword, isNotNull); |
| 7248 expect(directive.uri, isNotNull); | 8260 expect(directive.uri, isNotNull); |
| 7249 expect(directive.combinators, hasLength(1)); | 8261 expect(directive.combinators, hasLength(1)); |
| 7250 expect(directive.semicolon, isNotNull); | 8262 expect(directive.semicolon, isNotNull); |
| 7251 } | 8263 } |
| 7252 | 8264 |
| 7253 void test_parseExportDirective_show_hide() { | 8265 void test_parseExportDirective_show_hide() { |
| 7254 ExportDirective directive = parse( | 8266 createParser("export 'lib/lib.dart' show B hide A;"); |
| 7255 "parseExportDirective", | 8267 ExportDirective directive = |
| 7256 <Object>[emptyCommentAndMetadata()], | 8268 parser.parseExportDirective(emptyCommentAndMetadata()); |
| 7257 "export 'lib/lib.dart' show B hide A;"); | 8269 expectNotNullIfNoErrors(directive); |
| 8270 listener.assertNoErrors(); |
| 7258 expect(directive.keyword, isNotNull); | 8271 expect(directive.keyword, isNotNull); |
| 7259 expect(directive.uri, isNotNull); | 8272 expect(directive.uri, isNotNull); |
| 7260 expect(directive.combinators, hasLength(2)); | 8273 expect(directive.combinators, hasLength(2)); |
| 7261 expect(directive.semicolon, isNotNull); | 8274 expect(directive.semicolon, isNotNull); |
| 7262 } | 8275 } |
| 7263 | 8276 |
| 7264 void test_parseExpression_assign() { | 8277 void test_parseExpression_assign() { |
| 7265 // TODO(brianwilkerson) Implement more tests for this method. | 8278 // TODO(brianwilkerson) Implement more tests for this method. |
| 7266 AssignmentExpression expression = parse4("parseExpression", "x = y"); | 8279 Expression expression = parseExpression('x = y'); |
| 7267 expect(expression.leftHandSide, isNotNull); | 8280 expect(expression, new isInstanceOf<AssignmentExpression>()); |
| 7268 expect(expression.operator, isNotNull); | 8281 AssignmentExpression assignmentExpression = expression; |
| 7269 expect(expression.operator.type, TokenType.EQ); | 8282 expect(assignmentExpression.leftHandSide, isNotNull); |
| 7270 expect(expression.rightHandSide, isNotNull); | 8283 expect(assignmentExpression.operator, isNotNull); |
| 8284 expect(assignmentExpression.operator.type, TokenType.EQ); |
| 8285 expect(assignmentExpression.rightHandSide, isNotNull); |
| 8286 } |
| 8287 |
| 8288 void test_parseExpression_assign_compound() { |
| 8289 enableLazyAssignmentOperators = true; |
| 8290 Expression expression = parseExpression('x ||= y'); |
| 8291 expect(expression, new isInstanceOf<AssignmentExpression>()); |
| 8292 AssignmentExpression assignmentExpression = expression; |
| 8293 expect(assignmentExpression.leftHandSide, isNotNull); |
| 8294 expect(assignmentExpression.operator, isNotNull); |
| 8295 expect(assignmentExpression.operator.type, TokenType.BAR_BAR_EQ); |
| 8296 expect(assignmentExpression.rightHandSide, isNotNull); |
| 7271 } | 8297 } |
| 7272 | 8298 |
| 7273 void test_parseExpression_comparison() { | 8299 void test_parseExpression_comparison() { |
| 7274 BinaryExpression expression = parse4("parseExpression", "--a.b == c"); | 8300 Expression expression = parseExpression('--a.b == c'); |
| 7275 expect(expression.leftOperand, isNotNull); | 8301 expect(expression, new isInstanceOf<BinaryExpression>()); |
| 7276 expect(expression.operator, isNotNull); | 8302 BinaryExpression binaryExpression = expression; |
| 7277 expect(expression.operator.type, TokenType.EQ_EQ); | 8303 expect(binaryExpression.leftOperand, isNotNull); |
| 7278 expect(expression.rightOperand, isNotNull); | 8304 expect(binaryExpression.operator, isNotNull); |
| 8305 expect(binaryExpression.operator.type, TokenType.EQ_EQ); |
| 8306 expect(binaryExpression.rightOperand, isNotNull); |
| 7279 } | 8307 } |
| 7280 | 8308 |
| 7281 void test_parseExpression_function_async() { | 8309 void test_parseExpression_function_async() { |
| 7282 FunctionExpression expression = parseExpression("() async {}"); | 8310 Expression expression = parseExpression('() async {}'); |
| 7283 expect(expression.body, isNotNull); | 8311 expect(expression, new isInstanceOf<FunctionExpression>()); |
| 7284 expect(expression.body.isAsynchronous, isTrue); | 8312 FunctionExpression functionExpression = expression; |
| 7285 expect(expression.body.isGenerator, isFalse); | 8313 expect(functionExpression.body, isNotNull); |
| 7286 expect(expression.parameters, isNotNull); | 8314 expect(functionExpression.body.isAsynchronous, isTrue); |
| 8315 expect(functionExpression.body.isGenerator, isFalse); |
| 8316 expect(functionExpression.parameters, isNotNull); |
| 7287 } | 8317 } |
| 7288 | 8318 |
| 7289 void test_parseExpression_function_asyncStar() { | 8319 void test_parseExpression_function_asyncStar() { |
| 7290 FunctionExpression expression = parseExpression("() async* {}"); | 8320 Expression expression = parseExpression('() async* {}'); |
| 7291 expect(expression.body, isNotNull); | 8321 expect(expression, new isInstanceOf<FunctionExpression>()); |
| 7292 expect(expression.body.isAsynchronous, isTrue); | 8322 FunctionExpression functionExpression = expression; |
| 7293 expect(expression.body.isGenerator, isTrue); | 8323 expect(functionExpression.body, isNotNull); |
| 7294 expect(expression.parameters, isNotNull); | 8324 expect(functionExpression.body.isAsynchronous, isTrue); |
| 8325 expect(functionExpression.body.isGenerator, isTrue); |
| 8326 expect(functionExpression.parameters, isNotNull); |
| 7295 } | 8327 } |
| 7296 | 8328 |
| 7297 void test_parseExpression_function_sync() { | 8329 void test_parseExpression_function_sync() { |
| 7298 FunctionExpression expression = parseExpression("() {}"); | 8330 Expression expression = parseExpression('() {}'); |
| 7299 expect(expression.body, isNotNull); | 8331 expect(expression, new isInstanceOf<FunctionExpression>()); |
| 7300 expect(expression.body.isAsynchronous, isFalse); | 8332 FunctionExpression functionExpression = expression; |
| 7301 expect(expression.body.isGenerator, isFalse); | 8333 expect(functionExpression.body, isNotNull); |
| 7302 expect(expression.parameters, isNotNull); | 8334 expect(functionExpression.body.isAsynchronous, isFalse); |
| 8335 expect(functionExpression.body.isGenerator, isFalse); |
| 8336 expect(functionExpression.parameters, isNotNull); |
| 7303 } | 8337 } |
| 7304 | 8338 |
| 7305 void test_parseExpression_function_syncStar() { | 8339 void test_parseExpression_function_syncStar() { |
| 7306 FunctionExpression expression = parseExpression("() sync* {}"); | 8340 Expression expression = parseExpression('() sync* {}'); |
| 7307 expect(expression.body, isNotNull); | 8341 expect(expression, new isInstanceOf<FunctionExpression>()); |
| 7308 expect(expression.body.isAsynchronous, isFalse); | 8342 FunctionExpression functionExpression = expression; |
| 7309 expect(expression.body.isGenerator, isTrue); | 8343 expect(functionExpression.body, isNotNull); |
| 7310 expect(expression.parameters, isNotNull); | 8344 expect(functionExpression.body.isAsynchronous, isFalse); |
| 8345 expect(functionExpression.body.isGenerator, isTrue); |
| 8346 expect(functionExpression.parameters, isNotNull); |
| 7311 } | 8347 } |
| 7312 | 8348 |
| 7313 void test_parseExpression_invokeFunctionExpression() { | 8349 void test_parseExpression_invokeFunctionExpression() { |
| 7314 FunctionExpressionInvocation invocation = | 8350 Expression expression = parseExpression('(a) {return a + a;} (3)'); |
| 7315 parse4("parseExpression", "(a) {return a + a;} (3)"); | 8351 expect(expression, new isInstanceOf<FunctionExpressionInvocation>()); |
| 7316 EngineTestCase.assertInstanceOf((obj) => obj is FunctionExpression, | 8352 FunctionExpressionInvocation invocation = expression; |
| 7317 FunctionExpression, invocation.function); | 8353 expect(invocation.function, new isInstanceOf<FunctionExpression>()); |
| 7318 FunctionExpression expression = invocation.function as FunctionExpression; | 8354 FunctionExpression functionExpression = |
| 7319 expect(expression.parameters, isNotNull); | 8355 invocation.function as FunctionExpression; |
| 7320 expect(expression.body, isNotNull); | 8356 expect(functionExpression.parameters, isNotNull); |
| 8357 expect(functionExpression.body, isNotNull); |
| 7321 expect(invocation.typeArguments, isNull); | 8358 expect(invocation.typeArguments, isNull); |
| 7322 ArgumentList list = invocation.argumentList; | 8359 ArgumentList list = invocation.argumentList; |
| 7323 expect(list, isNotNull); | 8360 expect(list, isNotNull); |
| 7324 expect(list.arguments, hasLength(1)); | 8361 expect(list.arguments, hasLength(1)); |
| 7325 } | 8362 } |
| 7326 | 8363 |
| 7327 void test_parseExpression_nonAwait() { | 8364 void test_parseExpression_nonAwait() { |
| 7328 MethodInvocation expression = parseExpression("await()"); | 8365 Expression expression = parseExpression('await()'); |
| 7329 expect(expression.methodName.name, 'await'); | 8366 expect(expression, new isInstanceOf<MethodInvocation>()); |
| 7330 expect(expression.typeArguments, isNull); | 8367 MethodInvocation invocation = expression; |
| 7331 expect(expression.argumentList, isNotNull); | 8368 expect(invocation.methodName.name, 'await'); |
| 8369 expect(invocation.typeArguments, isNull); |
| 8370 expect(invocation.argumentList, isNotNull); |
| 7332 } | 8371 } |
| 7333 | 8372 |
| 7334 void test_parseExpression_superMethodInvocation() { | 8373 void test_parseExpression_superMethodInvocation() { |
| 7335 MethodInvocation invocation = parse4("parseExpression", "super.m()"); | 8374 Expression expression = parseExpression('super.m()'); |
| 8375 expect(expression, new isInstanceOf<MethodInvocation>()); |
| 8376 MethodInvocation invocation = expression; |
| 7336 expect(invocation.target, isNotNull); | 8377 expect(invocation.target, isNotNull); |
| 7337 expect(invocation.methodName, isNotNull); | 8378 expect(invocation.methodName, isNotNull); |
| 7338 expect(invocation.typeArguments, isNull); | 8379 expect(invocation.typeArguments, isNull); |
| 7339 expect(invocation.argumentList, isNotNull); | 8380 expect(invocation.argumentList, isNotNull); |
| 7340 } | 8381 } |
| 7341 | 8382 |
| 7342 void test_parseExpression_superMethodInvocation_typeArguments() { | 8383 void test_parseExpression_superMethodInvocation_typeArgumentComments() { |
| 7343 enableGenericMethods = true; | 8384 enableGenericMethodComments = true; |
| 7344 MethodInvocation invocation = parse4("parseExpression", "super.m<E>()"); | 8385 Expression expression = parseExpression('super.m/*<E>*/()'); |
| 8386 expect(expression, new isInstanceOf<MethodInvocation>()); |
| 8387 MethodInvocation invocation = expression; |
| 7345 expect(invocation.target, isNotNull); | 8388 expect(invocation.target, isNotNull); |
| 7346 expect(invocation.methodName, isNotNull); | 8389 expect(invocation.methodName, isNotNull); |
| 7347 expect(invocation.typeArguments, isNotNull); | 8390 expect(invocation.typeArguments, isNotNull); |
| 8391 expect(invocation.argumentList, isNotNull); |
| 8392 } |
| 8393 |
| 8394 void test_parseExpression_superMethodInvocation_typeArguments() { |
| 8395 enableGenericMethods = true; |
| 8396 Expression expression = parseExpression('super.m<E>()'); |
| 8397 expect(expression, new isInstanceOf<MethodInvocation>()); |
| 8398 MethodInvocation invocation = expression; |
| 8399 expect(invocation.target, isNotNull); |
| 8400 expect(invocation.methodName, isNotNull); |
| 8401 expect(invocation.typeArguments, isNotNull); |
| 7348 expect(invocation.argumentList, isNotNull); | 8402 expect(invocation.argumentList, isNotNull); |
| 7349 } | 8403 } |
| 7350 | 8404 |
| 7351 void test_parseExpressionList_multiple() { | 8405 void test_parseExpressionList_multiple() { |
| 7352 List<Expression> result = parse4("parseExpressionList", "1, 2, 3"); | 8406 createParser('1, 2, 3'); |
| 8407 List<Expression> result = parser.parseExpressionList(); |
| 8408 expectNotNullIfNoErrors(result); |
| 8409 listener.assertNoErrors(); |
| 7353 expect(result, hasLength(3)); | 8410 expect(result, hasLength(3)); |
| 7354 } | 8411 } |
| 7355 | 8412 |
| 7356 void test_parseExpressionList_single() { | 8413 void test_parseExpressionList_single() { |
| 7357 List<Expression> result = parse4("parseExpressionList", "1"); | 8414 createParser('1'); |
| 8415 List<Expression> result = parser.parseExpressionList(); |
| 8416 expectNotNullIfNoErrors(result); |
| 8417 listener.assertNoErrors(); |
| 7358 expect(result, hasLength(1)); | 8418 expect(result, hasLength(1)); |
| 7359 } | 8419 } |
| 7360 | 8420 |
| 7361 void test_parseExpressionWithoutCascade_assign() { | 8421 void test_parseExpressionWithoutCascade_assign() { |
| 7362 // TODO(brianwilkerson) Implement more tests for this method. | 8422 // TODO(brianwilkerson) Implement more tests for this method. |
| 7363 AssignmentExpression expression = | 8423 createParser('x = y'); |
| 7364 parse4("parseExpressionWithoutCascade", "x = y"); | 8424 Expression expression = parser.parseExpressionWithoutCascade(); |
| 7365 expect(expression.leftHandSide, isNotNull); | 8425 expectNotNullIfNoErrors(expression); |
| 7366 expect(expression.operator, isNotNull); | 8426 listener.assertNoErrors(); |
| 7367 expect(expression.operator.type, TokenType.EQ); | 8427 expect(expression, new isInstanceOf<AssignmentExpression>()); |
| 7368 expect(expression.rightHandSide, isNotNull); | 8428 AssignmentExpression assignmentExpression = expression; |
| 8429 expect(assignmentExpression.leftHandSide, isNotNull); |
| 8430 expect(assignmentExpression.operator, isNotNull); |
| 8431 expect(assignmentExpression.operator.type, TokenType.EQ); |
| 8432 expect(assignmentExpression.rightHandSide, isNotNull); |
| 7369 } | 8433 } |
| 7370 | 8434 |
| 7371 void test_parseExpressionWithoutCascade_comparison() { | 8435 void test_parseExpressionWithoutCascade_comparison() { |
| 7372 BinaryExpression expression = | 8436 createParser('--a.b == c'); |
| 7373 parse4("parseExpressionWithoutCascade", "--a.b == c"); | 8437 Expression expression = parser.parseExpressionWithoutCascade(); |
| 7374 expect(expression.leftOperand, isNotNull); | 8438 expectNotNullIfNoErrors(expression); |
| 7375 expect(expression.operator, isNotNull); | 8439 listener.assertNoErrors(); |
| 7376 expect(expression.operator.type, TokenType.EQ_EQ); | 8440 expect(expression, new isInstanceOf<BinaryExpression>()); |
| 7377 expect(expression.rightOperand, isNotNull); | 8441 BinaryExpression binaryExpression = expression; |
| 8442 expect(binaryExpression.leftOperand, isNotNull); |
| 8443 expect(binaryExpression.operator, isNotNull); |
| 8444 expect(binaryExpression.operator.type, TokenType.EQ_EQ); |
| 8445 expect(binaryExpression.rightOperand, isNotNull); |
| 7378 } | 8446 } |
| 7379 | 8447 |
| 7380 void test_parseExpressionWithoutCascade_superMethodInvocation() { | 8448 void test_parseExpressionWithoutCascade_superMethodInvocation() { |
| 7381 MethodInvocation invocation = | 8449 createParser('super.m()'); |
| 7382 parse4("parseExpressionWithoutCascade", "super.m()"); | 8450 Expression expression = parser.parseExpressionWithoutCascade(); |
| 8451 expectNotNullIfNoErrors(expression); |
| 8452 listener.assertNoErrors(); |
| 8453 expect(expression, new isInstanceOf<MethodInvocation>()); |
| 8454 MethodInvocation invocation = expression; |
| 7383 expect(invocation.target, isNotNull); | 8455 expect(invocation.target, isNotNull); |
| 7384 expect(invocation.methodName, isNotNull); | 8456 expect(invocation.methodName, isNotNull); |
| 7385 expect(invocation.typeArguments, isNull); | 8457 expect(invocation.typeArguments, isNull); |
| 7386 expect(invocation.argumentList, isNotNull); | 8458 expect(invocation.argumentList, isNotNull); |
| 7387 } | 8459 } |
| 7388 | 8460 |
| 7389 void test_parseExpressionWithoutCascade_superMethodInvocation_typeArguments()
{ | 8461 void |
| 7390 enableGenericMethods = true; | 8462 test_parseExpressionWithoutCascade_superMethodInvocation_typeArgumentComme
nts() { |
| 7391 MethodInvocation invocation = | 8463 enableGenericMethodComments = true; |
| 7392 parse4("parseExpressionWithoutCascade", "super.m<E>()"); | 8464 createParser('super.m/*<E>*/()'); |
| 8465 Expression expression = parser.parseExpressionWithoutCascade(); |
| 8466 expectNotNullIfNoErrors(expression); |
| 8467 listener.assertNoErrors(); |
| 8468 expect(expression, new isInstanceOf<MethodInvocation>()); |
| 8469 MethodInvocation invocation = expression; |
| 7393 expect(invocation.target, isNotNull); | 8470 expect(invocation.target, isNotNull); |
| 7394 expect(invocation.methodName, isNotNull); | 8471 expect(invocation.methodName, isNotNull); |
| 7395 expect(invocation.typeArguments, isNotNull); | 8472 expect(invocation.typeArguments, isNotNull); |
| 8473 expect(invocation.argumentList, isNotNull); |
| 8474 } |
| 8475 |
| 8476 void |
| 8477 test_parseExpressionWithoutCascade_superMethodInvocation_typeArguments() { |
| 8478 enableGenericMethods = true; |
| 8479 createParser('super.m<E>()'); |
| 8480 Expression expression = parser.parseExpressionWithoutCascade(); |
| 8481 expectNotNullIfNoErrors(expression); |
| 8482 listener.assertNoErrors(); |
| 8483 expect(expression, new isInstanceOf<MethodInvocation>()); |
| 8484 MethodInvocation invocation = expression; |
| 8485 expect(invocation.target, isNotNull); |
| 8486 expect(invocation.methodName, isNotNull); |
| 8487 expect(invocation.typeArguments, isNotNull); |
| 7396 expect(invocation.argumentList, isNotNull); | 8488 expect(invocation.argumentList, isNotNull); |
| 7397 } | 8489 } |
| 7398 | 8490 |
| 7399 void test_parseExtendsClause() { | 8491 void test_parseExtendsClause() { |
| 7400 ExtendsClause clause = parse4("parseExtendsClause", "extends B"); | 8492 createParser('extends B'); |
| 8493 ExtendsClause clause = parser.parseExtendsClause(); |
| 8494 expectNotNullIfNoErrors(clause); |
| 8495 listener.assertNoErrors(); |
| 7401 expect(clause.extendsKeyword, isNotNull); | 8496 expect(clause.extendsKeyword, isNotNull); |
| 7402 expect(clause.superclass, isNotNull); | 8497 expect(clause.superclass, isNotNull); |
| 7403 EngineTestCase.assertInstanceOf( | 8498 expect(clause.superclass, new isInstanceOf<TypeName>()); |
| 7404 (obj) => obj is TypeName, TypeName, clause.superclass); | |
| 7405 } | 8499 } |
| 7406 | 8500 |
| 7407 void test_parseFinalConstVarOrType_const_noType() { | 8501 void test_parseFinalConstVarOrType_const_noType() { |
| 7408 FinalConstVarOrType result = | 8502 createParser('const'); |
| 7409 parse("parseFinalConstVarOrType", <Object>[false], "const"); | 8503 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| 8504 expectNotNullIfNoErrors(result); |
| 8505 listener.assertNoErrors(); |
| 7410 Token keyword = result.keyword; | 8506 Token keyword = result.keyword; |
| 7411 expect(keyword, isNotNull); | 8507 expect(keyword, isNotNull); |
| 7412 expect(keyword.type, TokenType.KEYWORD); | 8508 expect(keyword.type, TokenType.KEYWORD); |
| 7413 expect((keyword as KeywordToken).keyword, Keyword.CONST); | 8509 expect(keyword.keyword, Keyword.CONST); |
| 7414 expect(result.type, isNull); | 8510 expect(result.type, isNull); |
| 7415 } | 8511 } |
| 7416 | 8512 |
| 7417 void test_parseFinalConstVarOrType_const_type() { | 8513 void test_parseFinalConstVarOrType_const_type() { |
| 7418 FinalConstVarOrType result = | 8514 createParser('const A a'); |
| 7419 parse("parseFinalConstVarOrType", <Object>[false], "const A a"); | 8515 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| 8516 expectNotNullIfNoErrors(result); |
| 8517 listener.assertNoErrors(); |
| 7420 Token keyword = result.keyword; | 8518 Token keyword = result.keyword; |
| 7421 expect(keyword, isNotNull); | 8519 expect(keyword, isNotNull); |
| 7422 expect(keyword.type, TokenType.KEYWORD); | 8520 expect(keyword.type, TokenType.KEYWORD); |
| 7423 expect((keyword as KeywordToken).keyword, Keyword.CONST); | 8521 expect(keyword.keyword, Keyword.CONST); |
| 7424 expect(result.type, isNotNull); | 8522 expect(result.type, isNotNull); |
| 7425 } | 8523 } |
| 7426 | 8524 |
| 7427 void test_parseFinalConstVarOrType_final_noType() { | 8525 void test_parseFinalConstVarOrType_final_noType() { |
| 7428 FinalConstVarOrType result = | 8526 createParser('final'); |
| 7429 parse("parseFinalConstVarOrType", <Object>[false], "final"); | 8527 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| 8528 expectNotNullIfNoErrors(result); |
| 8529 listener.assertNoErrors(); |
| 7430 Token keyword = result.keyword; | 8530 Token keyword = result.keyword; |
| 7431 expect(keyword, isNotNull); | 8531 expect(keyword, isNotNull); |
| 7432 expect(keyword.type, TokenType.KEYWORD); | 8532 expect(keyword.type, TokenType.KEYWORD); |
| 7433 expect((keyword as KeywordToken).keyword, Keyword.FINAL); | 8533 expect(keyword.keyword, Keyword.FINAL); |
| 7434 expect(result.type, isNull); | 8534 expect(result.type, isNull); |
| 7435 } | 8535 } |
| 7436 | 8536 |
| 7437 void test_parseFinalConstVarOrType_final_prefixedType() { | 8537 void test_parseFinalConstVarOrType_final_prefixedType() { |
| 7438 FinalConstVarOrType result = | 8538 createParser('final p.A a'); |
| 7439 parse("parseFinalConstVarOrType", <Object>[false], "final p.A a"); | 8539 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| 8540 expectNotNullIfNoErrors(result); |
| 8541 listener.assertNoErrors(); |
| 7440 Token keyword = result.keyword; | 8542 Token keyword = result.keyword; |
| 7441 expect(keyword, isNotNull); | 8543 expect(keyword, isNotNull); |
| 7442 expect(keyword.type, TokenType.KEYWORD); | 8544 expect(keyword.type, TokenType.KEYWORD); |
| 7443 expect((keyword as KeywordToken).keyword, Keyword.FINAL); | 8545 expect(keyword.keyword, Keyword.FINAL); |
| 7444 expect(result.type, isNotNull); | 8546 expect(result.type, isNotNull); |
| 7445 } | 8547 } |
| 7446 | 8548 |
| 7447 void test_parseFinalConstVarOrType_final_type() { | 8549 void test_parseFinalConstVarOrType_final_type() { |
| 7448 FinalConstVarOrType result = | 8550 createParser('final A a'); |
| 7449 parse("parseFinalConstVarOrType", <Object>[false], "final A a"); | 8551 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| 8552 expectNotNullIfNoErrors(result); |
| 8553 listener.assertNoErrors(); |
| 7450 Token keyword = result.keyword; | 8554 Token keyword = result.keyword; |
| 7451 expect(keyword, isNotNull); | 8555 expect(keyword, isNotNull); |
| 7452 expect(keyword.type, TokenType.KEYWORD); | 8556 expect(keyword.type, TokenType.KEYWORD); |
| 7453 expect((keyword as KeywordToken).keyword, Keyword.FINAL); | 8557 expect(keyword.keyword, Keyword.FINAL); |
| 7454 expect(result.type, isNotNull); | 8558 expect(result.type, isNotNull); |
| 7455 } | 8559 } |
| 7456 | 8560 |
| 7457 void test_parseFinalConstVarOrType_type_parameterized() { | 8561 void test_parseFinalConstVarOrType_type_parameterized() { |
| 7458 FinalConstVarOrType result = | 8562 createParser('A<B> a'); |
| 7459 parse("parseFinalConstVarOrType", <Object>[false], "A<B> a"); | 8563 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| 8564 expectNotNullIfNoErrors(result); |
| 8565 listener.assertNoErrors(); |
| 7460 expect(result.keyword, isNull); | 8566 expect(result.keyword, isNull); |
| 7461 expect(result.type, isNotNull); | 8567 expect(result.type, isNotNull); |
| 7462 } | 8568 } |
| 7463 | 8569 |
| 7464 void test_parseFinalConstVarOrType_type_prefixed() { | 8570 void test_parseFinalConstVarOrType_type_prefixed() { |
| 7465 FinalConstVarOrType result = | 8571 createParser('p.A a'); |
| 7466 parse("parseFinalConstVarOrType", <Object>[false], "p.A a"); | 8572 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| 8573 expectNotNullIfNoErrors(result); |
| 8574 listener.assertNoErrors(); |
| 7467 expect(result.keyword, isNull); | 8575 expect(result.keyword, isNull); |
| 7468 expect(result.type, isNotNull); | 8576 expect(result.type, isNotNull); |
| 7469 } | 8577 } |
| 7470 | 8578 |
| 7471 void test_parseFinalConstVarOrType_type_prefixed_noIdentifier() { | 8579 void test_parseFinalConstVarOrType_type_prefixed_noIdentifier() { |
| 7472 FinalConstVarOrType result = | 8580 createParser('p.A,'); |
| 7473 parse("parseFinalConstVarOrType", <Object>[false], "p.A,"); | 8581 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| 8582 expectNotNullIfNoErrors(result); |
| 8583 listener.assertNoErrors(); |
| 7474 expect(result.keyword, isNull); | 8584 expect(result.keyword, isNull); |
| 7475 expect(result.type, isNotNull); | 8585 expect(result.type, isNotNull); |
| 7476 } | 8586 } |
| 7477 | 8587 |
| 7478 void test_parseFinalConstVarOrType_type_prefixedAndParameterized() { | 8588 void test_parseFinalConstVarOrType_type_prefixedAndParameterized() { |
| 7479 FinalConstVarOrType result = | 8589 createParser('p.A<B> a'); |
| 7480 parse("parseFinalConstVarOrType", <Object>[false], "p.A<B> a"); | 8590 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| 8591 expectNotNullIfNoErrors(result); |
| 8592 listener.assertNoErrors(); |
| 7481 expect(result.keyword, isNull); | 8593 expect(result.keyword, isNull); |
| 7482 expect(result.type, isNotNull); | 8594 expect(result.type, isNotNull); |
| 7483 } | 8595 } |
| 7484 | 8596 |
| 7485 void test_parseFinalConstVarOrType_type_simple() { | 8597 void test_parseFinalConstVarOrType_type_simple() { |
| 7486 FinalConstVarOrType result = | 8598 createParser('A a'); |
| 7487 parse("parseFinalConstVarOrType", <Object>[false], "A a"); | 8599 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| 8600 expectNotNullIfNoErrors(result); |
| 8601 listener.assertNoErrors(); |
| 7488 expect(result.keyword, isNull); | 8602 expect(result.keyword, isNull); |
| 7489 expect(result.type, isNotNull); | 8603 expect(result.type, isNotNull); |
| 7490 } | 8604 } |
| 7491 | 8605 |
| 7492 void test_parseFinalConstVarOrType_var() { | 8606 void test_parseFinalConstVarOrType_var() { |
| 7493 FinalConstVarOrType result = | 8607 createParser('var'); |
| 7494 parse("parseFinalConstVarOrType", <Object>[false], "var"); | 8608 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| 8609 expectNotNullIfNoErrors(result); |
| 8610 listener.assertNoErrors(); |
| 7495 Token keyword = result.keyword; | 8611 Token keyword = result.keyword; |
| 7496 expect(keyword, isNotNull); | 8612 expect(keyword, isNotNull); |
| 7497 expect(keyword.type, TokenType.KEYWORD); | 8613 expect(keyword.type, TokenType.KEYWORD); |
| 7498 expect((keyword as KeywordToken).keyword, Keyword.VAR); | 8614 expect(keyword.keyword, Keyword.VAR); |
| 7499 expect(result.type, isNull); | 8615 expect(result.type, isNull); |
| 7500 } | 8616 } |
| 7501 | 8617 |
| 7502 void test_parseFinalConstVarOrType_void() { | 8618 void test_parseFinalConstVarOrType_void() { |
| 7503 FinalConstVarOrType result = | 8619 createParser('void f()'); |
| 7504 parse("parseFinalConstVarOrType", <Object>[false], "void f()"); | 8620 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| 8621 expectNotNullIfNoErrors(result); |
| 8622 listener.assertNoErrors(); |
| 7505 expect(result.keyword, isNull); | 8623 expect(result.keyword, isNull); |
| 7506 expect(result.type, isNotNull); | 8624 expect(result.type, isNotNull); |
| 7507 } | 8625 } |
| 7508 | 8626 |
| 7509 void test_parseFinalConstVarOrType_void_noIdentifier() { | 8627 void test_parseFinalConstVarOrType_void_noIdentifier() { |
| 7510 FinalConstVarOrType result = | 8628 createParser('void,'); |
| 7511 parse("parseFinalConstVarOrType", <Object>[false], "void,"); | 8629 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| 8630 expectNotNullIfNoErrors(result); |
| 8631 listener.assertNoErrors(); |
| 7512 expect(result.keyword, isNull); | 8632 expect(result.keyword, isNull); |
| 7513 expect(result.type, isNotNull); | 8633 expect(result.type, isNotNull); |
| 7514 } | 8634 } |
| 7515 | 8635 |
| 7516 void test_parseFormalParameter_final_withType_named() { | 8636 void test_parseFormalParameter_final_withType_named() { |
| 7517 ParameterKind kind = ParameterKind.NAMED; | 8637 ParameterKind kind = ParameterKind.NAMED; |
| 7518 DefaultFormalParameter parameter = | 8638 createParser('final A a : null'); |
| 7519 parse("parseFormalParameter", <Object>[kind], "final A a : null"); | 8639 FormalParameter parameter = parser.parseFormalParameter(kind); |
| 8640 expectNotNullIfNoErrors(parameter); |
| 8641 listener.assertNoErrors(); |
| 8642 expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| 8643 DefaultFormalParameter defaultParameter = parameter; |
| 7520 SimpleFormalParameter simpleParameter = | 8644 SimpleFormalParameter simpleParameter = |
| 7521 parameter.parameter as SimpleFormalParameter; | 8645 defaultParameter.parameter as SimpleFormalParameter; |
| 7522 expect(simpleParameter.identifier, isNotNull); | 8646 expect(simpleParameter.identifier, isNotNull); |
| 7523 expect(simpleParameter.keyword, isNotNull); | 8647 expect(simpleParameter.keyword, isNotNull); |
| 7524 expect(simpleParameter.type, isNotNull); | 8648 expect(simpleParameter.type, isNotNull); |
| 7525 expect(simpleParameter.kind, kind); | 8649 expect(simpleParameter.kind, kind); |
| 7526 expect(parameter.separator, isNotNull); | 8650 expect(defaultParameter.separator, isNotNull); |
| 7527 expect(parameter.defaultValue, isNotNull); | 8651 expect(defaultParameter.defaultValue, isNotNull); |
| 7528 expect(parameter.kind, kind); | 8652 expect(defaultParameter.kind, kind); |
| 7529 } | 8653 } |
| 7530 | 8654 |
| 7531 void test_parseFormalParameter_final_withType_normal() { | 8655 void test_parseFormalParameter_final_withType_normal() { |
| 7532 ParameterKind kind = ParameterKind.REQUIRED; | 8656 ParameterKind kind = ParameterKind.REQUIRED; |
| 7533 SimpleFormalParameter parameter = | 8657 createParser('final A a'); |
| 7534 parse("parseFormalParameter", <Object>[kind], "final A a"); | 8658 FormalParameter parameter = parser.parseFormalParameter(kind); |
| 7535 expect(parameter.identifier, isNotNull); | 8659 expectNotNullIfNoErrors(parameter); |
| 7536 expect(parameter.keyword, isNotNull); | 8660 listener.assertNoErrors(); |
| 7537 expect(parameter.type, isNotNull); | 8661 expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| 7538 expect(parameter.kind, kind); | 8662 SimpleFormalParameter simpleParameter = parameter; |
| 7539 } | |
| 7540 | |
| 7541 void test_parseFormalParameter_final_withType_positional() { | |
| 7542 ParameterKind kind = ParameterKind.POSITIONAL; | |
| 7543 DefaultFormalParameter parameter = | |
| 7544 parse("parseFormalParameter", <Object>[kind], "final A a = null"); | |
| 7545 SimpleFormalParameter simpleParameter = | |
| 7546 parameter.parameter as SimpleFormalParameter; | |
| 7547 expect(simpleParameter.identifier, isNotNull); | 8663 expect(simpleParameter.identifier, isNotNull); |
| 7548 expect(simpleParameter.keyword, isNotNull); | 8664 expect(simpleParameter.keyword, isNotNull); |
| 7549 expect(simpleParameter.type, isNotNull); | 8665 expect(simpleParameter.type, isNotNull); |
| 7550 expect(simpleParameter.kind, kind); | 8666 expect(simpleParameter.kind, kind); |
| 7551 expect(parameter.separator, isNotNull); | 8667 } |
| 7552 expect(parameter.defaultValue, isNotNull); | 8668 |
| 7553 expect(parameter.kind, kind); | 8669 void test_parseFormalParameter_final_withType_positional() { |
| 8670 ParameterKind kind = ParameterKind.POSITIONAL; |
| 8671 createParser('final A a = null'); |
| 8672 FormalParameter parameter = parser.parseFormalParameter(kind); |
| 8673 expectNotNullIfNoErrors(parameter); |
| 8674 listener.assertNoErrors(); |
| 8675 expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| 8676 DefaultFormalParameter defaultParameter = parameter; |
| 8677 SimpleFormalParameter simpleParameter = |
| 8678 defaultParameter.parameter as SimpleFormalParameter; |
| 8679 expect(simpleParameter.identifier, isNotNull); |
| 8680 expect(simpleParameter.keyword, isNotNull); |
| 8681 expect(simpleParameter.type, isNotNull); |
| 8682 expect(simpleParameter.kind, kind); |
| 8683 expect(defaultParameter.separator, isNotNull); |
| 8684 expect(defaultParameter.defaultValue, isNotNull); |
| 8685 expect(defaultParameter.kind, kind); |
| 7554 } | 8686 } |
| 7555 | 8687 |
| 7556 void test_parseFormalParameter_nonFinal_withType_named() { | 8688 void test_parseFormalParameter_nonFinal_withType_named() { |
| 7557 ParameterKind kind = ParameterKind.NAMED; | 8689 ParameterKind kind = ParameterKind.NAMED; |
| 7558 DefaultFormalParameter parameter = | 8690 createParser('A a : null'); |
| 7559 parse("parseFormalParameter", <Object>[kind], "A a : null"); | 8691 FormalParameter parameter = parser.parseFormalParameter(kind); |
| 8692 expectNotNullIfNoErrors(parameter); |
| 8693 listener.assertNoErrors(); |
| 8694 expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| 8695 DefaultFormalParameter defaultParameter = parameter; |
| 7560 SimpleFormalParameter simpleParameter = | 8696 SimpleFormalParameter simpleParameter = |
| 7561 parameter.parameter as SimpleFormalParameter; | 8697 defaultParameter.parameter as SimpleFormalParameter; |
| 7562 expect(simpleParameter.identifier, isNotNull); | 8698 expect(simpleParameter.identifier, isNotNull); |
| 7563 expect(simpleParameter.keyword, isNull); | 8699 expect(simpleParameter.keyword, isNull); |
| 7564 expect(simpleParameter.type, isNotNull); | 8700 expect(simpleParameter.type, isNotNull); |
| 7565 expect(simpleParameter.kind, kind); | 8701 expect(simpleParameter.kind, kind); |
| 7566 expect(parameter.separator, isNotNull); | 8702 expect(defaultParameter.separator, isNotNull); |
| 7567 expect(parameter.defaultValue, isNotNull); | 8703 expect(defaultParameter.defaultValue, isNotNull); |
| 7568 expect(parameter.kind, kind); | 8704 expect(defaultParameter.kind, kind); |
| 7569 } | 8705 } |
| 7570 | 8706 |
| 7571 void test_parseFormalParameter_nonFinal_withType_normal() { | 8707 void test_parseFormalParameter_nonFinal_withType_normal() { |
| 7572 ParameterKind kind = ParameterKind.REQUIRED; | 8708 ParameterKind kind = ParameterKind.REQUIRED; |
| 7573 SimpleFormalParameter parameter = | 8709 createParser('A a'); |
| 7574 parse("parseFormalParameter", <Object>[kind], "A a"); | 8710 FormalParameter parameter = parser.parseFormalParameter(kind); |
| 7575 expect(parameter.identifier, isNotNull); | 8711 expectNotNullIfNoErrors(parameter); |
| 7576 expect(parameter.keyword, isNull); | 8712 listener.assertNoErrors(); |
| 7577 expect(parameter.type, isNotNull); | 8713 expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| 7578 expect(parameter.kind, kind); | 8714 SimpleFormalParameter simpleParameter = parameter; |
| 7579 } | |
| 7580 | |
| 7581 void test_parseFormalParameter_nonFinal_withType_positional() { | |
| 7582 ParameterKind kind = ParameterKind.POSITIONAL; | |
| 7583 DefaultFormalParameter parameter = | |
| 7584 parse("parseFormalParameter", <Object>[kind], "A a = null"); | |
| 7585 SimpleFormalParameter simpleParameter = | |
| 7586 parameter.parameter as SimpleFormalParameter; | |
| 7587 expect(simpleParameter.identifier, isNotNull); | 8715 expect(simpleParameter.identifier, isNotNull); |
| 7588 expect(simpleParameter.keyword, isNull); | 8716 expect(simpleParameter.keyword, isNull); |
| 7589 expect(simpleParameter.type, isNotNull); | 8717 expect(simpleParameter.type, isNotNull); |
| 7590 expect(simpleParameter.kind, kind); | 8718 expect(simpleParameter.kind, kind); |
| 7591 expect(parameter.separator, isNotNull); | 8719 } |
| 7592 expect(parameter.defaultValue, isNotNull); | 8720 |
| 7593 expect(parameter.kind, kind); | 8721 void test_parseFormalParameter_nonFinal_withType_positional() { |
| 8722 ParameterKind kind = ParameterKind.POSITIONAL; |
| 8723 createParser('A a = null'); |
| 8724 FormalParameter parameter = parser.parseFormalParameter(kind); |
| 8725 expectNotNullIfNoErrors(parameter); |
| 8726 listener.assertNoErrors(); |
| 8727 expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| 8728 DefaultFormalParameter defaultParameter = parameter; |
| 8729 SimpleFormalParameter simpleParameter = |
| 8730 defaultParameter.parameter as SimpleFormalParameter; |
| 8731 expect(simpleParameter.identifier, isNotNull); |
| 8732 expect(simpleParameter.keyword, isNull); |
| 8733 expect(simpleParameter.type, isNotNull); |
| 8734 expect(simpleParameter.kind, kind); |
| 8735 expect(defaultParameter.separator, isNotNull); |
| 8736 expect(defaultParameter.defaultValue, isNotNull); |
| 8737 expect(defaultParameter.kind, kind); |
| 7594 } | 8738 } |
| 7595 | 8739 |
| 7596 void test_parseFormalParameter_var() { | 8740 void test_parseFormalParameter_var() { |
| 7597 ParameterKind kind = ParameterKind.REQUIRED; | 8741 ParameterKind kind = ParameterKind.REQUIRED; |
| 7598 SimpleFormalParameter parameter = | 8742 createParser('var a'); |
| 7599 parse("parseFormalParameter", <Object>[kind], "var a"); | 8743 FormalParameter parameter = parser.parseFormalParameter(kind); |
| 7600 expect(parameter.identifier, isNotNull); | 8744 expectNotNullIfNoErrors(parameter); |
| 7601 expect(parameter.keyword, isNotNull); | 8745 listener.assertNoErrors(); |
| 7602 expect(parameter.type, isNull); | 8746 expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| 7603 expect(parameter.kind, kind); | 8747 SimpleFormalParameter simpleParameter = parameter; |
| 7604 } | |
| 7605 | |
| 7606 void test_parseFormalParameter_var_named() { | |
| 7607 ParameterKind kind = ParameterKind.NAMED; | |
| 7608 DefaultFormalParameter parameter = | |
| 7609 parse("parseFormalParameter", <Object>[kind], "var a : null"); | |
| 7610 SimpleFormalParameter simpleParameter = | |
| 7611 parameter.parameter as SimpleFormalParameter; | |
| 7612 expect(simpleParameter.identifier, isNotNull); | 8748 expect(simpleParameter.identifier, isNotNull); |
| 7613 expect(simpleParameter.keyword, isNotNull); | 8749 expect(simpleParameter.keyword, isNotNull); |
| 7614 expect(simpleParameter.type, isNull); | 8750 expect(simpleParameter.type, isNull); |
| 7615 expect(simpleParameter.kind, kind); | 8751 expect(simpleParameter.kind, kind); |
| 7616 expect(parameter.separator, isNotNull); | 8752 } |
| 7617 expect(parameter.defaultValue, isNotNull); | 8753 |
| 7618 expect(parameter.kind, kind); | 8754 void test_parseFormalParameter_var_named() { |
| 7619 } | 8755 ParameterKind kind = ParameterKind.NAMED; |
| 7620 | 8756 createParser('var a : null'); |
| 7621 void test_parseFormalParameter_var_positional() { | 8757 FormalParameter parameter = parser.parseFormalParameter(kind); |
| 7622 ParameterKind kind = ParameterKind.POSITIONAL; | 8758 expectNotNullIfNoErrors(parameter); |
| 7623 DefaultFormalParameter parameter = | 8759 listener.assertNoErrors(); |
| 7624 parse("parseFormalParameter", <Object>[kind], "var a = null"); | 8760 expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| 8761 DefaultFormalParameter defaultParameter = parameter; |
| 7625 SimpleFormalParameter simpleParameter = | 8762 SimpleFormalParameter simpleParameter = |
| 7626 parameter.parameter as SimpleFormalParameter; | 8763 defaultParameter.parameter as SimpleFormalParameter; |
| 7627 expect(simpleParameter.identifier, isNotNull); | 8764 expect(simpleParameter.identifier, isNotNull); |
| 7628 expect(simpleParameter.keyword, isNotNull); | 8765 expect(simpleParameter.keyword, isNotNull); |
| 7629 expect(simpleParameter.type, isNull); | 8766 expect(simpleParameter.type, isNull); |
| 7630 expect(simpleParameter.kind, kind); | 8767 expect(simpleParameter.kind, kind); |
| 7631 expect(parameter.separator, isNotNull); | 8768 expect(defaultParameter.separator, isNotNull); |
| 7632 expect(parameter.defaultValue, isNotNull); | 8769 expect(defaultParameter.defaultValue, isNotNull); |
| 7633 expect(parameter.kind, kind); | 8770 expect(defaultParameter.kind, kind); |
| 8771 } |
| 8772 |
| 8773 void test_parseFormalParameter_var_positional() { |
| 8774 ParameterKind kind = ParameterKind.POSITIONAL; |
| 8775 createParser('var a = null'); |
| 8776 FormalParameter parameter = parser.parseFormalParameter(kind); |
| 8777 expectNotNullIfNoErrors(parameter); |
| 8778 listener.assertNoErrors(); |
| 8779 expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| 8780 DefaultFormalParameter defaultParameter = parameter; |
| 8781 SimpleFormalParameter simpleParameter = |
| 8782 defaultParameter.parameter as SimpleFormalParameter; |
| 8783 expect(simpleParameter.identifier, isNotNull); |
| 8784 expect(simpleParameter.keyword, isNotNull); |
| 8785 expect(simpleParameter.type, isNull); |
| 8786 expect(simpleParameter.kind, kind); |
| 8787 expect(defaultParameter.separator, isNotNull); |
| 8788 expect(defaultParameter.defaultValue, isNotNull); |
| 8789 expect(defaultParameter.kind, kind); |
| 7634 } | 8790 } |
| 7635 | 8791 |
| 7636 void test_parseFormalParameterList_empty() { | 8792 void test_parseFormalParameterList_empty() { |
| 7637 FormalParameterList parameterList = | 8793 createParser('()'); |
| 7638 parse4("parseFormalParameterList", "()"); | 8794 FormalParameterList list = parser.parseFormalParameterList(); |
| 7639 expect(parameterList.leftParenthesis, isNotNull); | 8795 expectNotNullIfNoErrors(list); |
| 7640 expect(parameterList.leftDelimiter, isNull); | 8796 listener.assertNoErrors(); |
| 7641 expect(parameterList.parameters, hasLength(0)); | 8797 expect(list.leftParenthesis, isNotNull); |
| 7642 expect(parameterList.rightDelimiter, isNull); | 8798 expect(list.leftDelimiter, isNull); |
| 7643 expect(parameterList.rightParenthesis, isNotNull); | 8799 expect(list.parameters, hasLength(0)); |
| 8800 expect(list.rightDelimiter, isNull); |
| 8801 expect(list.rightParenthesis, isNotNull); |
| 7644 } | 8802 } |
| 7645 | 8803 |
| 7646 void test_parseFormalParameterList_named_multiple() { | 8804 void test_parseFormalParameterList_named_multiple() { |
| 7647 FormalParameterList parameterList = | 8805 createParser('({A a : 1, B b, C c : 3})'); |
| 7648 parse4("parseFormalParameterList", "({A a : 1, B b, C c : 3})"); | 8806 FormalParameterList list = parser.parseFormalParameterList(); |
| 7649 expect(parameterList.leftParenthesis, isNotNull); | 8807 expectNotNullIfNoErrors(list); |
| 7650 expect(parameterList.leftDelimiter, isNotNull); | 8808 listener.assertNoErrors(); |
| 7651 expect(parameterList.parameters, hasLength(3)); | 8809 expect(list.leftParenthesis, isNotNull); |
| 7652 expect(parameterList.rightDelimiter, isNotNull); | 8810 expect(list.leftDelimiter, isNotNull); |
| 7653 expect(parameterList.rightParenthesis, isNotNull); | 8811 expect(list.parameters, hasLength(3)); |
| 8812 expect(list.rightDelimiter, isNotNull); |
| 8813 expect(list.rightParenthesis, isNotNull); |
| 7654 } | 8814 } |
| 7655 | 8815 |
| 7656 void test_parseFormalParameterList_named_single() { | 8816 void test_parseFormalParameterList_named_single() { |
| 7657 FormalParameterList parameterList = | 8817 createParser('({A a})'); |
| 7658 parse4("parseFormalParameterList", "({A a})"); | 8818 FormalParameterList list = parser.parseFormalParameterList(); |
| 7659 expect(parameterList.leftParenthesis, isNotNull); | 8819 expectNotNullIfNoErrors(list); |
| 7660 expect(parameterList.leftDelimiter, isNotNull); | 8820 listener.assertNoErrors(); |
| 7661 expect(parameterList.parameters, hasLength(1)); | 8821 expect(list.leftParenthesis, isNotNull); |
| 7662 expect(parameterList.rightDelimiter, isNotNull); | 8822 expect(list.leftDelimiter, isNotNull); |
| 7663 expect(parameterList.rightParenthesis, isNotNull); | 8823 expect(list.parameters, hasLength(1)); |
| 8824 expect(list.rightDelimiter, isNotNull); |
| 8825 expect(list.rightParenthesis, isNotNull); |
| 8826 } |
| 8827 |
| 8828 void test_parseFormalParameterList_named_trailing_comma() { |
| 8829 createParser('(A a, {B b,})'); |
| 8830 FormalParameterList list = parser.parseFormalParameterList(); |
| 8831 expectNotNullIfNoErrors(list); |
| 8832 listener.assertNoErrors(); |
| 8833 expect(list.leftParenthesis, isNotNull); |
| 8834 expect(list.leftDelimiter, isNotNull); |
| 8835 expect(list.parameters, hasLength(2)); |
| 8836 expect(list.rightDelimiter, isNotNull); |
| 8837 expect(list.rightParenthesis, isNotNull); |
| 7664 } | 8838 } |
| 7665 | 8839 |
| 7666 void test_parseFormalParameterList_normal_multiple() { | 8840 void test_parseFormalParameterList_normal_multiple() { |
| 7667 FormalParameterList parameterList = | 8841 createParser('(A a, B b, C c)'); |
| 7668 parse4("parseFormalParameterList", "(A a, B b, C c)"); | 8842 FormalParameterList list = parser.parseFormalParameterList(); |
| 7669 expect(parameterList.leftParenthesis, isNotNull); | 8843 expectNotNullIfNoErrors(list); |
| 7670 expect(parameterList.leftDelimiter, isNull); | 8844 listener.assertNoErrors(); |
| 7671 expect(parameterList.parameters, hasLength(3)); | 8845 expect(list.leftParenthesis, isNotNull); |
| 7672 expect(parameterList.rightDelimiter, isNull); | 8846 expect(list.leftDelimiter, isNull); |
| 7673 expect(parameterList.rightParenthesis, isNotNull); | 8847 expect(list.parameters, hasLength(3)); |
| 8848 expect(list.rightDelimiter, isNull); |
| 8849 expect(list.rightParenthesis, isNotNull); |
| 7674 } | 8850 } |
| 7675 | 8851 |
| 7676 void test_parseFormalParameterList_normal_named() { | 8852 void test_parseFormalParameterList_normal_named() { |
| 7677 FormalParameterList parameterList = | 8853 createParser('(A a, {B b})'); |
| 7678 parse4("parseFormalParameterList", "(A a, {B b})"); | 8854 FormalParameterList list = parser.parseFormalParameterList(); |
| 7679 expect(parameterList.leftParenthesis, isNotNull); | 8855 expectNotNullIfNoErrors(list); |
| 7680 expect(parameterList.leftDelimiter, isNotNull); | 8856 listener.assertNoErrors(); |
| 7681 expect(parameterList.parameters, hasLength(2)); | 8857 expect(list.leftParenthesis, isNotNull); |
| 7682 expect(parameterList.rightDelimiter, isNotNull); | 8858 expect(list.leftDelimiter, isNotNull); |
| 7683 expect(parameterList.rightParenthesis, isNotNull); | 8859 expect(list.parameters, hasLength(2)); |
| 8860 expect(list.rightDelimiter, isNotNull); |
| 8861 expect(list.rightParenthesis, isNotNull); |
| 7684 } | 8862 } |
| 7685 | 8863 |
| 7686 void test_parseFormalParameterList_normal_positional() { | 8864 void test_parseFormalParameterList_normal_positional() { |
| 7687 FormalParameterList parameterList = | 8865 createParser('(A a, [B b])'); |
| 7688 parse4("parseFormalParameterList", "(A a, [B b])"); | 8866 FormalParameterList list = parser.parseFormalParameterList(); |
| 7689 expect(parameterList.leftParenthesis, isNotNull); | 8867 expectNotNullIfNoErrors(list); |
| 7690 expect(parameterList.leftDelimiter, isNotNull); | 8868 listener.assertNoErrors(); |
| 7691 expect(parameterList.parameters, hasLength(2)); | 8869 expect(list.leftParenthesis, isNotNull); |
| 7692 expect(parameterList.rightDelimiter, isNotNull); | 8870 expect(list.leftDelimiter, isNotNull); |
| 7693 expect(parameterList.rightParenthesis, isNotNull); | 8871 expect(list.parameters, hasLength(2)); |
| 8872 expect(list.rightDelimiter, isNotNull); |
| 8873 expect(list.rightParenthesis, isNotNull); |
| 7694 } | 8874 } |
| 7695 | 8875 |
| 7696 void test_parseFormalParameterList_normal_single() { | 8876 void test_parseFormalParameterList_normal_single() { |
| 7697 FormalParameterList parameterList = | 8877 createParser('(A a)'); |
| 7698 parse4("parseFormalParameterList", "(A a)"); | 8878 FormalParameterList list = parser.parseFormalParameterList(); |
| 7699 expect(parameterList.leftParenthesis, isNotNull); | 8879 expectNotNullIfNoErrors(list); |
| 7700 expect(parameterList.leftDelimiter, isNull); | 8880 listener.assertNoErrors(); |
| 7701 expect(parameterList.parameters, hasLength(1)); | 8881 expect(list.leftParenthesis, isNotNull); |
| 7702 expect(parameterList.rightDelimiter, isNull); | 8882 expect(list.leftDelimiter, isNull); |
| 7703 expect(parameterList.rightParenthesis, isNotNull); | 8883 expect(list.parameters, hasLength(1)); |
| 8884 expect(list.rightDelimiter, isNull); |
| 8885 expect(list.rightParenthesis, isNotNull); |
| 8886 } |
| 8887 |
| 8888 void test_parseFormalParameterList_normal_single_trailing_comma() { |
| 8889 createParser('(A a,)'); |
| 8890 FormalParameterList list = parser.parseFormalParameterList(); |
| 8891 expectNotNullIfNoErrors(list); |
| 8892 listener.assertNoErrors(); |
| 8893 expect(list.leftParenthesis, isNotNull); |
| 8894 expect(list.leftDelimiter, isNull); |
| 8895 expect(list.parameters, hasLength(1)); |
| 8896 expect(list.rightDelimiter, isNull); |
| 8897 expect(list.rightParenthesis, isNotNull); |
| 7704 } | 8898 } |
| 7705 | 8899 |
| 7706 void test_parseFormalParameterList_positional_multiple() { | 8900 void test_parseFormalParameterList_positional_multiple() { |
| 7707 FormalParameterList parameterList = | 8901 createParser('([A a = null, B b, C c = null])'); |
| 7708 parse4("parseFormalParameterList", "([A a = null, B b, C c = null])"); | 8902 FormalParameterList list = parser.parseFormalParameterList(); |
| 7709 expect(parameterList.leftParenthesis, isNotNull); | 8903 expectNotNullIfNoErrors(list); |
| 7710 expect(parameterList.leftDelimiter, isNotNull); | 8904 listener.assertNoErrors(); |
| 7711 expect(parameterList.parameters, hasLength(3)); | 8905 expect(list.leftParenthesis, isNotNull); |
| 7712 expect(parameterList.rightDelimiter, isNotNull); | 8906 expect(list.leftDelimiter, isNotNull); |
| 7713 expect(parameterList.rightParenthesis, isNotNull); | 8907 expect(list.parameters, hasLength(3)); |
| 8908 expect(list.rightDelimiter, isNotNull); |
| 8909 expect(list.rightParenthesis, isNotNull); |
| 7714 } | 8910 } |
| 7715 | 8911 |
| 7716 void test_parseFormalParameterList_positional_single() { | 8912 void test_parseFormalParameterList_positional_single() { |
| 7717 FormalParameterList parameterList = | 8913 createParser('([A a = null])'); |
| 7718 parse4("parseFormalParameterList", "([A a = null])"); | 8914 FormalParameterList list = parser.parseFormalParameterList(); |
| 7719 expect(parameterList.leftParenthesis, isNotNull); | 8915 expectNotNullIfNoErrors(list); |
| 7720 expect(parameterList.leftDelimiter, isNotNull); | 8916 listener.assertNoErrors(); |
| 7721 expect(parameterList.parameters, hasLength(1)); | 8917 expect(list.leftParenthesis, isNotNull); |
| 7722 expect(parameterList.rightDelimiter, isNotNull); | 8918 expect(list.leftDelimiter, isNotNull); |
| 7723 expect(parameterList.rightParenthesis, isNotNull); | 8919 expect(list.parameters, hasLength(1)); |
| 8920 expect(list.rightDelimiter, isNotNull); |
| 8921 expect(list.rightParenthesis, isNotNull); |
| 8922 } |
| 8923 |
| 8924 void test_parseFormalParameterList_positional_trailing_comma() { |
| 8925 createParser('(A a, [B b,])'); |
| 8926 FormalParameterList list = parser.parseFormalParameterList(); |
| 8927 expectNotNullIfNoErrors(list); |
| 8928 listener.assertNoErrors(); |
| 8929 expect(list.leftParenthesis, isNotNull); |
| 8930 expect(list.leftDelimiter, isNotNull); |
| 8931 expect(list.parameters, hasLength(2)); |
| 8932 expect(list.rightDelimiter, isNotNull); |
| 8933 expect(list.rightParenthesis, isNotNull); |
| 7724 } | 8934 } |
| 7725 | 8935 |
| 7726 void test_parseFormalParameterList_prefixedType() { | 8936 void test_parseFormalParameterList_prefixedType() { |
| 7727 FormalParameterList parameterList = | 8937 createParser('(io.File f)'); |
| 7728 parse4("parseFormalParameterList", "(io.File f)"); | 8938 FormalParameterList list = parser.parseFormalParameterList(); |
| 7729 expect(parameterList.leftParenthesis, isNotNull); | 8939 expectNotNullIfNoErrors(list); |
| 7730 expect(parameterList.leftDelimiter, isNull); | 8940 listener.assertNoErrors(); |
| 7731 expect(parameterList.parameters, hasLength(1)); | 8941 expect(list.leftParenthesis, isNotNull); |
| 7732 expect(parameterList.parameters[0].toSource(), 'io.File f'); | 8942 expect(list.leftDelimiter, isNull); |
| 7733 expect(parameterList.rightDelimiter, isNull); | 8943 expect(list.parameters, hasLength(1)); |
| 7734 expect(parameterList.rightParenthesis, isNotNull); | 8944 expect(list.parameters[0].toSource(), 'io.File f'); |
| 8945 expect(list.rightDelimiter, isNull); |
| 8946 expect(list.rightParenthesis, isNotNull); |
| 7735 } | 8947 } |
| 7736 | 8948 |
| 7737 void test_parseFormalParameterList_prefixedType_partial() { | 8949 void test_parseFormalParameterList_prefixedType_partial() { |
| 7738 FormalParameterList parameterList = parse4( | 8950 createParser('(io.)'); |
| 7739 "parseFormalParameterList", "(io.)", [ | 8951 FormalParameterList list = parser.parseFormalParameterList(); |
| 8952 expectNotNullIfNoErrors(list); |
| 8953 listener.assertErrorsWithCodes([ |
| 7740 ParserErrorCode.MISSING_IDENTIFIER, | 8954 ParserErrorCode.MISSING_IDENTIFIER, |
| 7741 ParserErrorCode.MISSING_IDENTIFIER | 8955 ParserErrorCode.MISSING_IDENTIFIER |
| 7742 ]); | 8956 ]); |
| 7743 expect(parameterList.leftParenthesis, isNotNull); | 8957 expect(list.leftParenthesis, isNotNull); |
| 7744 expect(parameterList.leftDelimiter, isNull); | 8958 expect(list.leftDelimiter, isNull); |
| 7745 expect(parameterList.parameters, hasLength(1)); | 8959 expect(list.parameters, hasLength(1)); |
| 7746 expect(parameterList.parameters[0].toSource(), 'io. '); | 8960 expect(list.parameters[0].toSource(), 'io. '); |
| 7747 expect(parameterList.rightDelimiter, isNull); | 8961 expect(list.rightDelimiter, isNull); |
| 7748 expect(parameterList.rightParenthesis, isNotNull); | 8962 expect(list.rightParenthesis, isNotNull); |
| 7749 } | 8963 } |
| 7750 | 8964 |
| 7751 void test_parseFormalParameterList_prefixedType_partial2() { | 8965 void test_parseFormalParameterList_prefixedType_partial2() { |
| 7752 FormalParameterList parameterList = parse4( | 8966 createParser('(io.,a)'); |
| 7753 "parseFormalParameterList", "(io.,a)", [ | 8967 FormalParameterList list = parser.parseFormalParameterList(); |
| 8968 expectNotNullIfNoErrors(list); |
| 8969 listener.assertErrorsWithCodes([ |
| 7754 ParserErrorCode.MISSING_IDENTIFIER, | 8970 ParserErrorCode.MISSING_IDENTIFIER, |
| 7755 ParserErrorCode.MISSING_IDENTIFIER | 8971 ParserErrorCode.MISSING_IDENTIFIER |
| 7756 ]); | 8972 ]); |
| 7757 expect(parameterList.leftParenthesis, isNotNull); | 8973 expect(list.leftParenthesis, isNotNull); |
| 7758 expect(parameterList.leftDelimiter, isNull); | 8974 expect(list.leftDelimiter, isNull); |
| 7759 expect(parameterList.parameters, hasLength(2)); | 8975 expect(list.parameters, hasLength(2)); |
| 7760 expect(parameterList.parameters[0].toSource(), 'io. '); | 8976 expect(list.parameters[0].toSource(), 'io. '); |
| 7761 expect(parameterList.parameters[1].toSource(), 'a'); | 8977 expect(list.parameters[1].toSource(), 'a'); |
| 7762 expect(parameterList.rightDelimiter, isNull); | 8978 expect(list.rightDelimiter, isNull); |
| 7763 expect(parameterList.rightParenthesis, isNotNull); | 8979 expect(list.rightParenthesis, isNotNull); |
| 7764 } | 8980 } |
| 7765 | 8981 |
| 7766 void test_parseForStatement_each_await() { | 8982 void test_parseForStatement_each_await() { |
| 7767 ForEachStatement statement = | 8983 createParser('await for (element in list) {}'); |
| 7768 parse4("parseForStatement", "await for (element in list) {}"); | 8984 Statement statement = parser.parseForStatement(); |
| 7769 expect(statement.awaitKeyword, isNotNull); | 8985 expectNotNullIfNoErrors(statement); |
| 7770 expect(statement.forKeyword, isNotNull); | 8986 listener.assertNoErrors(); |
| 7771 expect(statement.leftParenthesis, isNotNull); | 8987 expect(statement, new isInstanceOf<ForEachStatement>()); |
| 7772 expect(statement.loopVariable, isNull); | 8988 ForEachStatement forStatement = statement; |
| 7773 expect(statement.identifier, isNotNull); | 8989 expect(forStatement.awaitKeyword, isNotNull); |
| 7774 expect(statement.inKeyword, isNotNull); | 8990 expect(forStatement.forKeyword, isNotNull); |
| 7775 expect(statement.iterable, isNotNull); | 8991 expect(forStatement.leftParenthesis, isNotNull); |
| 7776 expect(statement.rightParenthesis, isNotNull); | 8992 expect(forStatement.loopVariable, isNull); |
| 7777 expect(statement.body, isNotNull); | 8993 expect(forStatement.identifier, isNotNull); |
| 8994 expect(forStatement.inKeyword, isNotNull); |
| 8995 expect(forStatement.iterable, isNotNull); |
| 8996 expect(forStatement.rightParenthesis, isNotNull); |
| 8997 expect(forStatement.body, isNotNull); |
| 7778 } | 8998 } |
| 7779 | 8999 |
| 7780 void test_parseForStatement_each_identifier() { | 9000 void test_parseForStatement_each_identifier() { |
| 7781 ForEachStatement statement = | 9001 createParser('for (element in list) {}'); |
| 7782 parse4("parseForStatement", "for (element in list) {}"); | 9002 Statement statement = parser.parseForStatement(); |
| 7783 expect(statement.awaitKeyword, isNull); | 9003 expectNotNullIfNoErrors(statement); |
| 7784 expect(statement.forKeyword, isNotNull); | 9004 listener.assertNoErrors(); |
| 7785 expect(statement.leftParenthesis, isNotNull); | 9005 expect(statement, new isInstanceOf<ForEachStatement>()); |
| 7786 expect(statement.loopVariable, isNull); | 9006 ForEachStatement forStatement = statement; |
| 7787 expect(statement.identifier, isNotNull); | 9007 expect(forStatement.awaitKeyword, isNull); |
| 7788 expect(statement.inKeyword, isNotNull); | 9008 expect(forStatement.forKeyword, isNotNull); |
| 7789 expect(statement.iterable, isNotNull); | 9009 expect(forStatement.leftParenthesis, isNotNull); |
| 7790 expect(statement.rightParenthesis, isNotNull); | 9010 expect(forStatement.loopVariable, isNull); |
| 7791 expect(statement.body, isNotNull); | 9011 expect(forStatement.identifier, isNotNull); |
| 9012 expect(forStatement.inKeyword, isNotNull); |
| 9013 expect(forStatement.iterable, isNotNull); |
| 9014 expect(forStatement.rightParenthesis, isNotNull); |
| 9015 expect(forStatement.body, isNotNull); |
| 7792 } | 9016 } |
| 7793 | 9017 |
| 7794 void test_parseForStatement_each_noType_metadata() { | 9018 void test_parseForStatement_each_noType_metadata() { |
| 7795 ForEachStatement statement = | 9019 createParser('for (@A var element in list) {}'); |
| 7796 parse4("parseForStatement", "for (@A var element in list) {}"); | 9020 Statement statement = parser.parseForStatement(); |
| 7797 expect(statement.awaitKeyword, isNull); | 9021 expectNotNullIfNoErrors(statement); |
| 7798 expect(statement.forKeyword, isNotNull); | 9022 listener.assertNoErrors(); |
| 7799 expect(statement.leftParenthesis, isNotNull); | 9023 expect(statement, new isInstanceOf<ForEachStatement>()); |
| 7800 expect(statement.loopVariable, isNotNull); | 9024 ForEachStatement forStatement = statement; |
| 7801 expect(statement.loopVariable.metadata, hasLength(1)); | 9025 expect(forStatement.awaitKeyword, isNull); |
| 7802 expect(statement.identifier, isNull); | 9026 expect(forStatement.forKeyword, isNotNull); |
| 7803 expect(statement.inKeyword, isNotNull); | 9027 expect(forStatement.leftParenthesis, isNotNull); |
| 7804 expect(statement.iterable, isNotNull); | 9028 expect(forStatement.loopVariable, isNotNull); |
| 7805 expect(statement.rightParenthesis, isNotNull); | 9029 expect(forStatement.loopVariable.metadata, hasLength(1)); |
| 7806 expect(statement.body, isNotNull); | 9030 expect(forStatement.identifier, isNull); |
| 9031 expect(forStatement.inKeyword, isNotNull); |
| 9032 expect(forStatement.iterable, isNotNull); |
| 9033 expect(forStatement.rightParenthesis, isNotNull); |
| 9034 expect(forStatement.body, isNotNull); |
| 7807 } | 9035 } |
| 7808 | 9036 |
| 7809 void test_parseForStatement_each_type() { | 9037 void test_parseForStatement_each_type() { |
| 7810 ForEachStatement statement = | 9038 createParser('for (A element in list) {}'); |
| 7811 parse4("parseForStatement", "for (A element in list) {}"); | 9039 Statement statement = parser.parseForStatement(); |
| 7812 expect(statement.awaitKeyword, isNull); | 9040 expectNotNullIfNoErrors(statement); |
| 7813 expect(statement.forKeyword, isNotNull); | 9041 listener.assertNoErrors(); |
| 7814 expect(statement.leftParenthesis, isNotNull); | 9042 expect(statement, new isInstanceOf<ForEachStatement>()); |
| 7815 expect(statement.loopVariable, isNotNull); | 9043 ForEachStatement forStatement = statement; |
| 7816 expect(statement.identifier, isNull); | 9044 expect(forStatement.awaitKeyword, isNull); |
| 7817 expect(statement.inKeyword, isNotNull); | 9045 expect(forStatement.forKeyword, isNotNull); |
| 7818 expect(statement.iterable, isNotNull); | 9046 expect(forStatement.leftParenthesis, isNotNull); |
| 7819 expect(statement.rightParenthesis, isNotNull); | 9047 expect(forStatement.loopVariable, isNotNull); |
| 7820 expect(statement.body, isNotNull); | 9048 expect(forStatement.identifier, isNull); |
| 9049 expect(forStatement.inKeyword, isNotNull); |
| 9050 expect(forStatement.iterable, isNotNull); |
| 9051 expect(forStatement.rightParenthesis, isNotNull); |
| 9052 expect(forStatement.body, isNotNull); |
| 7821 } | 9053 } |
| 7822 | 9054 |
| 7823 void test_parseForStatement_each_var() { | 9055 void test_parseForStatement_each_var() { |
| 7824 ForEachStatement statement = | 9056 createParser('for (var element in list) {}'); |
| 7825 parse4("parseForStatement", "for (var element in list) {}"); | 9057 Statement statement = parser.parseForStatement(); |
| 7826 expect(statement.awaitKeyword, isNull); | 9058 expectNotNullIfNoErrors(statement); |
| 7827 expect(statement.forKeyword, isNotNull); | 9059 listener.assertNoErrors(); |
| 7828 expect(statement.leftParenthesis, isNotNull); | 9060 expect(statement, new isInstanceOf<ForEachStatement>()); |
| 7829 expect(statement.loopVariable, isNotNull); | 9061 ForEachStatement forStatement = statement; |
| 7830 expect(statement.identifier, isNull); | 9062 expect(forStatement.awaitKeyword, isNull); |
| 7831 expect(statement.inKeyword, isNotNull); | 9063 expect(forStatement.forKeyword, isNotNull); |
| 7832 expect(statement.iterable, isNotNull); | 9064 expect(forStatement.leftParenthesis, isNotNull); |
| 7833 expect(statement.rightParenthesis, isNotNull); | 9065 expect(forStatement.loopVariable, isNotNull); |
| 7834 expect(statement.body, isNotNull); | 9066 expect(forStatement.identifier, isNull); |
| 9067 expect(forStatement.inKeyword, isNotNull); |
| 9068 expect(forStatement.iterable, isNotNull); |
| 9069 expect(forStatement.rightParenthesis, isNotNull); |
| 9070 expect(forStatement.body, isNotNull); |
| 7835 } | 9071 } |
| 7836 | 9072 |
| 7837 void test_parseForStatement_loop_c() { | 9073 void test_parseForStatement_loop_c() { |
| 7838 ForStatement statement = | 9074 createParser('for (; i < count;) {}'); |
| 7839 parse4("parseForStatement", "for (; i < count;) {}"); | 9075 Statement statement = parser.parseForStatement(); |
| 7840 expect(statement.forKeyword, isNotNull); | 9076 expectNotNullIfNoErrors(statement); |
| 7841 expect(statement.leftParenthesis, isNotNull); | 9077 listener.assertNoErrors(); |
| 7842 expect(statement.variables, isNull); | 9078 expect(statement, new isInstanceOf<ForStatement>()); |
| 7843 expect(statement.initialization, isNull); | 9079 ForStatement forStatement = statement; |
| 7844 expect(statement.leftSeparator, isNotNull); | 9080 expect(forStatement.forKeyword, isNotNull); |
| 7845 expect(statement.condition, isNotNull); | 9081 expect(forStatement.leftParenthesis, isNotNull); |
| 7846 expect(statement.rightSeparator, isNotNull); | 9082 expect(forStatement.variables, isNull); |
| 7847 expect(statement.updaters, hasLength(0)); | 9083 expect(forStatement.initialization, isNull); |
| 7848 expect(statement.rightParenthesis, isNotNull); | 9084 expect(forStatement.leftSeparator, isNotNull); |
| 7849 expect(statement.body, isNotNull); | 9085 expect(forStatement.condition, isNotNull); |
| 9086 expect(forStatement.rightSeparator, isNotNull); |
| 9087 expect(forStatement.updaters, hasLength(0)); |
| 9088 expect(forStatement.rightParenthesis, isNotNull); |
| 9089 expect(forStatement.body, isNotNull); |
| 7850 } | 9090 } |
| 7851 | 9091 |
| 7852 void test_parseForStatement_loop_cu() { | 9092 void test_parseForStatement_loop_cu() { |
| 7853 ForStatement statement = | 9093 createParser('for (; i < count; i++) {}'); |
| 7854 parse4("parseForStatement", "for (; i < count; i++) {}"); | 9094 Statement statement = parser.parseForStatement(); |
| 7855 expect(statement.forKeyword, isNotNull); | 9095 expectNotNullIfNoErrors(statement); |
| 7856 expect(statement.leftParenthesis, isNotNull); | 9096 listener.assertNoErrors(); |
| 7857 expect(statement.variables, isNull); | 9097 expect(statement, new isInstanceOf<ForStatement>()); |
| 7858 expect(statement.initialization, isNull); | 9098 ForStatement forStatement = statement; |
| 7859 expect(statement.leftSeparator, isNotNull); | 9099 expect(forStatement.forKeyword, isNotNull); |
| 7860 expect(statement.condition, isNotNull); | 9100 expect(forStatement.leftParenthesis, isNotNull); |
| 7861 expect(statement.rightSeparator, isNotNull); | 9101 expect(forStatement.variables, isNull); |
| 7862 expect(statement.updaters, hasLength(1)); | 9102 expect(forStatement.initialization, isNull); |
| 7863 expect(statement.rightParenthesis, isNotNull); | 9103 expect(forStatement.leftSeparator, isNotNull); |
| 7864 expect(statement.body, isNotNull); | 9104 expect(forStatement.condition, isNotNull); |
| 9105 expect(forStatement.rightSeparator, isNotNull); |
| 9106 expect(forStatement.updaters, hasLength(1)); |
| 9107 expect(forStatement.rightParenthesis, isNotNull); |
| 9108 expect(forStatement.body, isNotNull); |
| 7865 } | 9109 } |
| 7866 | 9110 |
| 7867 void test_parseForStatement_loop_ecu() { | 9111 void test_parseForStatement_loop_ecu() { |
| 7868 ForStatement statement = | 9112 createParser('for (i--; i < count; i++) {}'); |
| 7869 parse4("parseForStatement", "for (i--; i < count; i++) {}"); | 9113 Statement statement = parser.parseForStatement(); |
| 7870 expect(statement.forKeyword, isNotNull); | 9114 expectNotNullIfNoErrors(statement); |
| 7871 expect(statement.leftParenthesis, isNotNull); | 9115 listener.assertNoErrors(); |
| 7872 expect(statement.variables, isNull); | 9116 expect(statement, new isInstanceOf<ForStatement>()); |
| 7873 expect(statement.initialization, isNotNull); | 9117 ForStatement forStatement = statement; |
| 7874 expect(statement.leftSeparator, isNotNull); | 9118 expect(forStatement.forKeyword, isNotNull); |
| 7875 expect(statement.condition, isNotNull); | 9119 expect(forStatement.leftParenthesis, isNotNull); |
| 7876 expect(statement.rightSeparator, isNotNull); | 9120 expect(forStatement.variables, isNull); |
| 7877 expect(statement.updaters, hasLength(1)); | 9121 expect(forStatement.initialization, isNotNull); |
| 7878 expect(statement.rightParenthesis, isNotNull); | 9122 expect(forStatement.leftSeparator, isNotNull); |
| 7879 expect(statement.body, isNotNull); | 9123 expect(forStatement.condition, isNotNull); |
| 9124 expect(forStatement.rightSeparator, isNotNull); |
| 9125 expect(forStatement.updaters, hasLength(1)); |
| 9126 expect(forStatement.rightParenthesis, isNotNull); |
| 9127 expect(forStatement.body, isNotNull); |
| 7880 } | 9128 } |
| 7881 | 9129 |
| 7882 void test_parseForStatement_loop_i() { | 9130 void test_parseForStatement_loop_i() { |
| 7883 ForStatement statement = | 9131 createParser('for (var i = 0;;) {}'); |
| 7884 parse4("parseForStatement", "for (var i = 0;;) {}"); | 9132 Statement statement = parser.parseForStatement(); |
| 7885 expect(statement.forKeyword, isNotNull); | 9133 expectNotNullIfNoErrors(statement); |
| 7886 expect(statement.leftParenthesis, isNotNull); | 9134 listener.assertNoErrors(); |
| 7887 VariableDeclarationList variables = statement.variables; | 9135 expect(statement, new isInstanceOf<ForStatement>()); |
| 9136 ForStatement forStatement = statement; |
| 9137 expect(forStatement.forKeyword, isNotNull); |
| 9138 expect(forStatement.leftParenthesis, isNotNull); |
| 9139 VariableDeclarationList variables = forStatement.variables; |
| 7888 expect(variables, isNotNull); | 9140 expect(variables, isNotNull); |
| 7889 expect(variables.metadata, hasLength(0)); | 9141 expect(variables.metadata, hasLength(0)); |
| 7890 expect(variables.variables, hasLength(1)); | 9142 expect(variables.variables, hasLength(1)); |
| 7891 expect(statement.initialization, isNull); | 9143 expect(forStatement.initialization, isNull); |
| 7892 expect(statement.leftSeparator, isNotNull); | 9144 expect(forStatement.leftSeparator, isNotNull); |
| 7893 expect(statement.condition, isNull); | 9145 expect(forStatement.condition, isNull); |
| 7894 expect(statement.rightSeparator, isNotNull); | 9146 expect(forStatement.rightSeparator, isNotNull); |
| 7895 expect(statement.updaters, hasLength(0)); | 9147 expect(forStatement.updaters, hasLength(0)); |
| 7896 expect(statement.rightParenthesis, isNotNull); | 9148 expect(forStatement.rightParenthesis, isNotNull); |
| 7897 expect(statement.body, isNotNull); | 9149 expect(forStatement.body, isNotNull); |
| 7898 } | 9150 } |
| 7899 | 9151 |
| 7900 void test_parseForStatement_loop_i_withMetadata() { | 9152 void test_parseForStatement_loop_i_withMetadata() { |
| 7901 ForStatement statement = | 9153 createParser('for (@A var i = 0;;) {}'); |
| 7902 parse4("parseForStatement", "for (@A var i = 0;;) {}"); | 9154 Statement statement = parser.parseForStatement(); |
| 7903 expect(statement.forKeyword, isNotNull); | 9155 expectNotNullIfNoErrors(statement); |
| 7904 expect(statement.leftParenthesis, isNotNull); | 9156 listener.assertNoErrors(); |
| 7905 VariableDeclarationList variables = statement.variables; | 9157 expect(statement, new isInstanceOf<ForStatement>()); |
| 9158 ForStatement forStatement = statement; |
| 9159 expect(forStatement.forKeyword, isNotNull); |
| 9160 expect(forStatement.leftParenthesis, isNotNull); |
| 9161 VariableDeclarationList variables = forStatement.variables; |
| 7906 expect(variables, isNotNull); | 9162 expect(variables, isNotNull); |
| 7907 expect(variables.metadata, hasLength(1)); | 9163 expect(variables.metadata, hasLength(1)); |
| 7908 expect(variables.variables, hasLength(1)); | 9164 expect(variables.variables, hasLength(1)); |
| 7909 expect(statement.initialization, isNull); | 9165 expect(forStatement.initialization, isNull); |
| 7910 expect(statement.leftSeparator, isNotNull); | 9166 expect(forStatement.leftSeparator, isNotNull); |
| 7911 expect(statement.condition, isNull); | 9167 expect(forStatement.condition, isNull); |
| 7912 expect(statement.rightSeparator, isNotNull); | 9168 expect(forStatement.rightSeparator, isNotNull); |
| 7913 expect(statement.updaters, hasLength(0)); | 9169 expect(forStatement.updaters, hasLength(0)); |
| 7914 expect(statement.rightParenthesis, isNotNull); | 9170 expect(forStatement.rightParenthesis, isNotNull); |
| 7915 expect(statement.body, isNotNull); | 9171 expect(forStatement.body, isNotNull); |
| 7916 } | 9172 } |
| 7917 | 9173 |
| 7918 void test_parseForStatement_loop_ic() { | 9174 void test_parseForStatement_loop_ic() { |
| 7919 ForStatement statement = | 9175 createParser('for (var i = 0; i < count;) {}'); |
| 7920 parse4("parseForStatement", "for (var i = 0; i < count;) {}"); | 9176 Statement statement = parser.parseForStatement(); |
| 7921 expect(statement.forKeyword, isNotNull); | 9177 expectNotNullIfNoErrors(statement); |
| 7922 expect(statement.leftParenthesis, isNotNull); | 9178 listener.assertNoErrors(); |
| 7923 VariableDeclarationList variables = statement.variables; | 9179 expect(statement, new isInstanceOf<ForStatement>()); |
| 9180 ForStatement forStatement = statement; |
| 9181 expect(forStatement.forKeyword, isNotNull); |
| 9182 expect(forStatement.leftParenthesis, isNotNull); |
| 9183 VariableDeclarationList variables = forStatement.variables; |
| 7924 expect(variables, isNotNull); | 9184 expect(variables, isNotNull); |
| 7925 expect(variables.variables, hasLength(1)); | 9185 expect(variables.variables, hasLength(1)); |
| 7926 expect(statement.initialization, isNull); | 9186 expect(forStatement.initialization, isNull); |
| 7927 expect(statement.leftSeparator, isNotNull); | 9187 expect(forStatement.leftSeparator, isNotNull); |
| 7928 expect(statement.condition, isNotNull); | 9188 expect(forStatement.condition, isNotNull); |
| 7929 expect(statement.rightSeparator, isNotNull); | 9189 expect(forStatement.rightSeparator, isNotNull); |
| 7930 expect(statement.updaters, hasLength(0)); | 9190 expect(forStatement.updaters, hasLength(0)); |
| 7931 expect(statement.rightParenthesis, isNotNull); | 9191 expect(forStatement.rightParenthesis, isNotNull); |
| 7932 expect(statement.body, isNotNull); | 9192 expect(forStatement.body, isNotNull); |
| 7933 } | 9193 } |
| 7934 | 9194 |
| 7935 void test_parseForStatement_loop_icu() { | 9195 void test_parseForStatement_loop_icu() { |
| 7936 ForStatement statement = | 9196 createParser('for (var i = 0; i < count; i++) {}'); |
| 7937 parse4("parseForStatement", "for (var i = 0; i < count; i++) {}"); | 9197 Statement statement = parser.parseForStatement(); |
| 7938 expect(statement.forKeyword, isNotNull); | 9198 expectNotNullIfNoErrors(statement); |
| 7939 expect(statement.leftParenthesis, isNotNull); | 9199 listener.assertNoErrors(); |
| 7940 VariableDeclarationList variables = statement.variables; | 9200 expect(statement, new isInstanceOf<ForStatement>()); |
| 9201 ForStatement forStatement = statement; |
| 9202 expect(forStatement.forKeyword, isNotNull); |
| 9203 expect(forStatement.leftParenthesis, isNotNull); |
| 9204 VariableDeclarationList variables = forStatement.variables; |
| 7941 expect(variables, isNotNull); | 9205 expect(variables, isNotNull); |
| 7942 expect(variables.variables, hasLength(1)); | 9206 expect(variables.variables, hasLength(1)); |
| 7943 expect(statement.initialization, isNull); | 9207 expect(forStatement.initialization, isNull); |
| 7944 expect(statement.leftSeparator, isNotNull); | 9208 expect(forStatement.leftSeparator, isNotNull); |
| 7945 expect(statement.condition, isNotNull); | 9209 expect(forStatement.condition, isNotNull); |
| 7946 expect(statement.rightSeparator, isNotNull); | 9210 expect(forStatement.rightSeparator, isNotNull); |
| 7947 expect(statement.updaters, hasLength(1)); | 9211 expect(forStatement.updaters, hasLength(1)); |
| 7948 expect(statement.rightParenthesis, isNotNull); | 9212 expect(forStatement.rightParenthesis, isNotNull); |
| 7949 expect(statement.body, isNotNull); | 9213 expect(forStatement.body, isNotNull); |
| 7950 } | 9214 } |
| 7951 | 9215 |
| 7952 void test_parseForStatement_loop_iicuu() { | 9216 void test_parseForStatement_loop_iicuu() { |
| 7953 ForStatement statement = parse4( | 9217 createParser('for (int i = 0, j = count; i < j; i++, j--) {}'); |
| 7954 "parseForStatement", "for (int i = 0, j = count; i < j; i++, j--) {}"); | 9218 Statement statement = parser.parseForStatement(); |
| 7955 expect(statement.forKeyword, isNotNull); | 9219 expectNotNullIfNoErrors(statement); |
| 7956 expect(statement.leftParenthesis, isNotNull); | 9220 listener.assertNoErrors(); |
| 7957 VariableDeclarationList variables = statement.variables; | 9221 expect(statement, new isInstanceOf<ForStatement>()); |
| 9222 ForStatement forStatement = statement; |
| 9223 expect(forStatement.forKeyword, isNotNull); |
| 9224 expect(forStatement.leftParenthesis, isNotNull); |
| 9225 VariableDeclarationList variables = forStatement.variables; |
| 7958 expect(variables, isNotNull); | 9226 expect(variables, isNotNull); |
| 7959 expect(variables.variables, hasLength(2)); | 9227 expect(variables.variables, hasLength(2)); |
| 7960 expect(statement.initialization, isNull); | 9228 expect(forStatement.initialization, isNull); |
| 7961 expect(statement.leftSeparator, isNotNull); | 9229 expect(forStatement.leftSeparator, isNotNull); |
| 7962 expect(statement.condition, isNotNull); | 9230 expect(forStatement.condition, isNotNull); |
| 7963 expect(statement.rightSeparator, isNotNull); | 9231 expect(forStatement.rightSeparator, isNotNull); |
| 7964 expect(statement.updaters, hasLength(2)); | 9232 expect(forStatement.updaters, hasLength(2)); |
| 7965 expect(statement.rightParenthesis, isNotNull); | 9233 expect(forStatement.rightParenthesis, isNotNull); |
| 7966 expect(statement.body, isNotNull); | 9234 expect(forStatement.body, isNotNull); |
| 7967 } | 9235 } |
| 7968 | 9236 |
| 7969 void test_parseForStatement_loop_iu() { | 9237 void test_parseForStatement_loop_iu() { |
| 7970 ForStatement statement = | 9238 createParser('for (var i = 0;; i++) {}'); |
| 7971 parse4("parseForStatement", "for (var i = 0;; i++) {}"); | 9239 Statement statement = parser.parseForStatement(); |
| 7972 expect(statement.forKeyword, isNotNull); | 9240 expectNotNullIfNoErrors(statement); |
| 7973 expect(statement.leftParenthesis, isNotNull); | 9241 listener.assertNoErrors(); |
| 7974 VariableDeclarationList variables = statement.variables; | 9242 expect(statement, new isInstanceOf<ForStatement>()); |
| 9243 ForStatement forStatement = statement; |
| 9244 expect(forStatement.forKeyword, isNotNull); |
| 9245 expect(forStatement.leftParenthesis, isNotNull); |
| 9246 VariableDeclarationList variables = forStatement.variables; |
| 7975 expect(variables, isNotNull); | 9247 expect(variables, isNotNull); |
| 7976 expect(variables.variables, hasLength(1)); | 9248 expect(variables.variables, hasLength(1)); |
| 7977 expect(statement.initialization, isNull); | 9249 expect(forStatement.initialization, isNull); |
| 7978 expect(statement.leftSeparator, isNotNull); | 9250 expect(forStatement.leftSeparator, isNotNull); |
| 7979 expect(statement.condition, isNull); | 9251 expect(forStatement.condition, isNull); |
| 7980 expect(statement.rightSeparator, isNotNull); | 9252 expect(forStatement.rightSeparator, isNotNull); |
| 7981 expect(statement.updaters, hasLength(1)); | 9253 expect(forStatement.updaters, hasLength(1)); |
| 7982 expect(statement.rightParenthesis, isNotNull); | 9254 expect(forStatement.rightParenthesis, isNotNull); |
| 7983 expect(statement.body, isNotNull); | 9255 expect(forStatement.body, isNotNull); |
| 7984 } | 9256 } |
| 7985 | 9257 |
| 7986 void test_parseForStatement_loop_u() { | 9258 void test_parseForStatement_loop_u() { |
| 7987 ForStatement statement = parse4("parseForStatement", "for (;; i++) {}"); | 9259 createParser('for (;; i++) {}'); |
| 7988 expect(statement.forKeyword, isNotNull); | 9260 Statement statement = parser.parseForStatement(); |
| 7989 expect(statement.leftParenthesis, isNotNull); | 9261 expectNotNullIfNoErrors(statement); |
| 7990 expect(statement.variables, isNull); | 9262 listener.assertNoErrors(); |
| 7991 expect(statement.initialization, isNull); | 9263 expect(statement, new isInstanceOf<ForStatement>()); |
| 7992 expect(statement.leftSeparator, isNotNull); | 9264 ForStatement forStatement = statement; |
| 7993 expect(statement.condition, isNull); | 9265 expect(forStatement.forKeyword, isNotNull); |
| 7994 expect(statement.rightSeparator, isNotNull); | 9266 expect(forStatement.leftParenthesis, isNotNull); |
| 7995 expect(statement.updaters, hasLength(1)); | 9267 expect(forStatement.variables, isNull); |
| 7996 expect(statement.rightParenthesis, isNotNull); | 9268 expect(forStatement.initialization, isNull); |
| 7997 expect(statement.body, isNotNull); | 9269 expect(forStatement.leftSeparator, isNotNull); |
| 9270 expect(forStatement.condition, isNull); |
| 9271 expect(forStatement.rightSeparator, isNotNull); |
| 9272 expect(forStatement.updaters, hasLength(1)); |
| 9273 expect(forStatement.rightParenthesis, isNotNull); |
| 9274 expect(forStatement.body, isNotNull); |
| 7998 } | 9275 } |
| 7999 | 9276 |
| 8000 void test_parseFunctionBody_block() { | 9277 void test_parseFunctionBody_block() { |
| 8001 BlockFunctionBody functionBody = | 9278 createParser('{}'); |
| 8002 parse("parseFunctionBody", <Object>[false, null, false], "{}"); | 9279 FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| 8003 expect(functionBody.keyword, isNull); | 9280 expectNotNullIfNoErrors(functionBody); |
| 8004 expect(functionBody.star, isNull); | 9281 listener.assertNoErrors(); |
| 8005 expect(functionBody.block, isNotNull); | 9282 expect(functionBody, new isInstanceOf<BlockFunctionBody>()); |
| 8006 expect(functionBody.isAsynchronous, isFalse); | 9283 BlockFunctionBody body = functionBody; |
| 8007 expect(functionBody.isGenerator, isFalse); | 9284 expect(body.keyword, isNull); |
| 8008 expect(functionBody.isSynchronous, isTrue); | 9285 expect(body.star, isNull); |
| 9286 expect(body.block, isNotNull); |
| 9287 expect(body.isAsynchronous, isFalse); |
| 9288 expect(body.isGenerator, isFalse); |
| 9289 expect(body.isSynchronous, isTrue); |
| 8009 } | 9290 } |
| 8010 | 9291 |
| 8011 void test_parseFunctionBody_block_async() { | 9292 void test_parseFunctionBody_block_async() { |
| 8012 BlockFunctionBody functionBody = | 9293 createParser('async {}'); |
| 8013 parse("parseFunctionBody", <Object>[false, null, false], "async {}"); | 9294 FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| 8014 expect(functionBody.keyword, isNotNull); | 9295 expectNotNullIfNoErrors(functionBody); |
| 8015 expect(functionBody.keyword.lexeme, Parser.ASYNC); | 9296 listener.assertNoErrors(); |
| 8016 expect(functionBody.star, isNull); | 9297 expect(functionBody, new isInstanceOf<BlockFunctionBody>()); |
| 8017 expect(functionBody.block, isNotNull); | 9298 BlockFunctionBody body = functionBody; |
| 8018 expect(functionBody.isAsynchronous, isTrue); | 9299 expect(body.keyword, isNotNull); |
| 8019 expect(functionBody.isGenerator, isFalse); | 9300 expect(body.keyword.lexeme, Parser.ASYNC); |
| 8020 expect(functionBody.isSynchronous, isFalse); | 9301 expect(body.star, isNull); |
| 9302 expect(body.block, isNotNull); |
| 9303 expect(body.isAsynchronous, isTrue); |
| 9304 expect(body.isGenerator, isFalse); |
| 9305 expect(body.isSynchronous, isFalse); |
| 8021 } | 9306 } |
| 8022 | 9307 |
| 8023 void test_parseFunctionBody_block_asyncGenerator() { | 9308 void test_parseFunctionBody_block_asyncGenerator() { |
| 8024 BlockFunctionBody functionBody = | 9309 createParser('async* {}'); |
| 8025 parse("parseFunctionBody", <Object>[false, null, false], "async* {}"); | 9310 FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| 8026 expect(functionBody.keyword, isNotNull); | 9311 expectNotNullIfNoErrors(functionBody); |
| 8027 expect(functionBody.keyword.lexeme, Parser.ASYNC); | 9312 listener.assertNoErrors(); |
| 8028 expect(functionBody.star, isNotNull); | 9313 expect(functionBody, new isInstanceOf<BlockFunctionBody>()); |
| 8029 expect(functionBody.block, isNotNull); | 9314 BlockFunctionBody body = functionBody; |
| 8030 expect(functionBody.isAsynchronous, isTrue); | 9315 expect(body.keyword, isNotNull); |
| 8031 expect(functionBody.isGenerator, isTrue); | 9316 expect(body.keyword.lexeme, Parser.ASYNC); |
| 8032 expect(functionBody.isSynchronous, isFalse); | 9317 expect(body.star, isNotNull); |
| 9318 expect(body.block, isNotNull); |
| 9319 expect(body.isAsynchronous, isTrue); |
| 9320 expect(body.isGenerator, isTrue); |
| 9321 expect(body.isSynchronous, isFalse); |
| 8033 } | 9322 } |
| 8034 | 9323 |
| 8035 void test_parseFunctionBody_block_syncGenerator() { | 9324 void test_parseFunctionBody_block_syncGenerator() { |
| 8036 BlockFunctionBody functionBody = | 9325 createParser('sync* {}'); |
| 8037 parse("parseFunctionBody", <Object>[false, null, false], "sync* {}"); | 9326 FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| 8038 expect(functionBody.keyword, isNotNull); | 9327 expectNotNullIfNoErrors(functionBody); |
| 8039 expect(functionBody.keyword.lexeme, Parser.SYNC); | 9328 listener.assertNoErrors(); |
| 8040 expect(functionBody.star, isNotNull); | 9329 expect(functionBody, new isInstanceOf<BlockFunctionBody>()); |
| 8041 expect(functionBody.block, isNotNull); | 9330 BlockFunctionBody body = functionBody; |
| 8042 expect(functionBody.isAsynchronous, isFalse); | 9331 expect(body.keyword, isNotNull); |
| 8043 expect(functionBody.isGenerator, isTrue); | 9332 expect(body.keyword.lexeme, Parser.SYNC); |
| 8044 expect(functionBody.isSynchronous, isTrue); | 9333 expect(body.star, isNotNull); |
| 9334 expect(body.block, isNotNull); |
| 9335 expect(body.isAsynchronous, isFalse); |
| 9336 expect(body.isGenerator, isTrue); |
| 9337 expect(body.isSynchronous, isTrue); |
| 8045 } | 9338 } |
| 8046 | 9339 |
| 8047 void test_parseFunctionBody_empty() { | 9340 void test_parseFunctionBody_empty() { |
| 8048 EmptyFunctionBody functionBody = | 9341 createParser(';'); |
| 8049 parse("parseFunctionBody", <Object>[true, null, false], ";"); | 9342 FunctionBody functionBody = parser.parseFunctionBody(true, null, false); |
| 8050 expect(functionBody.semicolon, isNotNull); | 9343 expectNotNullIfNoErrors(functionBody); |
| 9344 listener.assertNoErrors(); |
| 9345 expect(functionBody, new isInstanceOf<EmptyFunctionBody>()); |
| 9346 EmptyFunctionBody body = functionBody; |
| 9347 expect(body.semicolon, isNotNull); |
| 8051 } | 9348 } |
| 8052 | 9349 |
| 8053 void test_parseFunctionBody_expression() { | 9350 void test_parseFunctionBody_expression() { |
| 8054 ExpressionFunctionBody functionBody = | 9351 createParser('=> y;'); |
| 8055 parse("parseFunctionBody", <Object>[false, null, false], "=> y;"); | 9352 FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| 8056 expect(functionBody.keyword, isNull); | 9353 expectNotNullIfNoErrors(functionBody); |
| 8057 expect(functionBody.functionDefinition, isNotNull); | 9354 listener.assertNoErrors(); |
| 8058 expect(functionBody.expression, isNotNull); | 9355 expect(functionBody, new isInstanceOf<ExpressionFunctionBody>()); |
| 8059 expect(functionBody.semicolon, isNotNull); | 9356 ExpressionFunctionBody body = functionBody; |
| 8060 expect(functionBody.isAsynchronous, isFalse); | 9357 expect(body.keyword, isNull); |
| 8061 expect(functionBody.isGenerator, isFalse); | 9358 expect(body.functionDefinition, isNotNull); |
| 8062 expect(functionBody.isSynchronous, isTrue); | 9359 expect(body.expression, isNotNull); |
| 9360 expect(body.semicolon, isNotNull); |
| 9361 expect(body.isAsynchronous, isFalse); |
| 9362 expect(body.isGenerator, isFalse); |
| 9363 expect(body.isSynchronous, isTrue); |
| 8063 } | 9364 } |
| 8064 | 9365 |
| 8065 void test_parseFunctionBody_expression_async() { | 9366 void test_parseFunctionBody_expression_async() { |
| 8066 ExpressionFunctionBody functionBody = | 9367 createParser('async => y;'); |
| 8067 parse("parseFunctionBody", <Object>[false, null, false], "async => y;"); | 9368 FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| 8068 expect(functionBody.keyword, isNotNull); | 9369 expectNotNullIfNoErrors(functionBody); |
| 8069 expect(functionBody.keyword.lexeme, Parser.ASYNC); | 9370 listener.assertNoErrors(); |
| 8070 expect(functionBody.functionDefinition, isNotNull); | 9371 expect(functionBody, new isInstanceOf<ExpressionFunctionBody>()); |
| 8071 expect(functionBody.expression, isNotNull); | 9372 ExpressionFunctionBody body = functionBody; |
| 8072 expect(functionBody.semicolon, isNotNull); | 9373 expect(body.keyword, isNotNull); |
| 8073 expect(functionBody.isAsynchronous, isTrue); | 9374 expect(body.keyword.lexeme, Parser.ASYNC); |
| 8074 expect(functionBody.isGenerator, isFalse); | 9375 expect(body.functionDefinition, isNotNull); |
| 8075 expect(functionBody.isSynchronous, isFalse); | 9376 expect(body.expression, isNotNull); |
| 9377 expect(body.semicolon, isNotNull); |
| 9378 expect(body.isAsynchronous, isTrue); |
| 9379 expect(body.isGenerator, isFalse); |
| 9380 expect(body.isSynchronous, isFalse); |
| 8076 } | 9381 } |
| 8077 | 9382 |
| 8078 void test_parseFunctionBody_nativeFunctionBody() { | 9383 void test_parseFunctionBody_nativeFunctionBody() { |
| 8079 NativeFunctionBody functionBody = parse( | 9384 createParser('native "str";'); |
| 8080 "parseFunctionBody", <Object>[false, null, false], "native 'str';"); | 9385 FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| 8081 expect(functionBody.nativeKeyword, isNotNull); | 9386 expectNotNullIfNoErrors(functionBody); |
| 8082 expect(functionBody.stringLiteral, isNotNull); | 9387 listener.assertNoErrors(); |
| 8083 expect(functionBody.semicolon, isNotNull); | 9388 expect(functionBody, new isInstanceOf<NativeFunctionBody>()); |
| 9389 NativeFunctionBody body = functionBody; |
| 9390 expect(body.nativeKeyword, isNotNull); |
| 9391 expect(body.stringLiteral, isNotNull); |
| 9392 expect(body.semicolon, isNotNull); |
| 8084 } | 9393 } |
| 8085 | 9394 |
| 8086 void test_parseFunctionBody_skip_block() { | 9395 void test_parseFunctionBody_skip_block() { |
| 8087 ParserTestCase.parseFunctionBodies = false; | 9396 ParserTestCase.parseFunctionBodies = false; |
| 8088 FunctionBody functionBody = | 9397 createParser('{}'); |
| 8089 parse("parseFunctionBody", <Object>[false, null, false], "{}"); | 9398 FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| 8090 EngineTestCase.assertInstanceOf( | 9399 expectNotNullIfNoErrors(functionBody); |
| 8091 (obj) => obj is EmptyFunctionBody, EmptyFunctionBody, functionBody); | 9400 listener.assertNoErrors(); |
| 9401 expect(functionBody, new isInstanceOf<EmptyFunctionBody>()); |
| 8092 } | 9402 } |
| 8093 | 9403 |
| 8094 void test_parseFunctionBody_skip_block_invalid() { | 9404 void test_parseFunctionBody_skip_block_invalid() { |
| 8095 ParserTestCase.parseFunctionBodies = false; | 9405 ParserTestCase.parseFunctionBodies = false; |
| 8096 FunctionBody functionBody = parse3("parseFunctionBody", | 9406 createParser('{'); |
| 8097 <Object>[false, null, false], "{", [ParserErrorCode.EXPECTED_TOKEN]); | 9407 FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| 8098 EngineTestCase.assertInstanceOf( | 9408 expectNotNullIfNoErrors(functionBody); |
| 8099 (obj) => obj is EmptyFunctionBody, EmptyFunctionBody, functionBody); | 9409 listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_TOKEN]); |
| 9410 expect(functionBody, new isInstanceOf<EmptyFunctionBody>()); |
| 8100 } | 9411 } |
| 8101 | 9412 |
| 8102 void test_parseFunctionBody_skip_blocks() { | 9413 void test_parseFunctionBody_skip_blocks() { |
| 8103 ParserTestCase.parseFunctionBodies = false; | 9414 ParserTestCase.parseFunctionBodies = false; |
| 8104 FunctionBody functionBody = | 9415 createParser('{ {} }'); |
| 8105 parse("parseFunctionBody", <Object>[false, null, false], "{ {} }"); | 9416 FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| 8106 EngineTestCase.assertInstanceOf( | 9417 expectNotNullIfNoErrors(functionBody); |
| 8107 (obj) => obj is EmptyFunctionBody, EmptyFunctionBody, functionBody); | 9418 listener.assertNoErrors(); |
| 9419 expect(functionBody, new isInstanceOf<EmptyFunctionBody>()); |
| 8108 } | 9420 } |
| 8109 | 9421 |
| 8110 void test_parseFunctionBody_skip_expression() { | 9422 void test_parseFunctionBody_skip_expression() { |
| 8111 ParserTestCase.parseFunctionBodies = false; | 9423 ParserTestCase.parseFunctionBodies = false; |
| 8112 FunctionBody functionBody = | 9424 createParser('=> y;'); |
| 8113 parse("parseFunctionBody", <Object>[false, null, false], "=> y;"); | 9425 FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| 8114 EngineTestCase.assertInstanceOf( | 9426 expectNotNullIfNoErrors(functionBody); |
| 8115 (obj) => obj is EmptyFunctionBody, EmptyFunctionBody, functionBody); | 9427 listener.assertNoErrors(); |
| 9428 expect(functionBody, new isInstanceOf<EmptyFunctionBody>()); |
| 8116 } | 9429 } |
| 8117 | 9430 |
| 8118 void test_parseFunctionDeclaration_function() { | 9431 void test_parseFunctionDeclaration_function() { |
| 8119 Comment comment = Comment.createDocumentationComment(new List<Token>(0)); | 9432 Comment comment = Comment.createDocumentationComment(new List<Token>(0)); |
| 8120 TypeName returnType = new TypeName(new SimpleIdentifier(null), null); | 9433 TypeName returnType = new TypeName(new SimpleIdentifier(null), null); |
| 8121 FunctionDeclaration declaration = parse("parseFunctionDeclaration", | 9434 createParser('f() {}'); |
| 8122 <Object>[commentAndMetadata(comment), null, returnType], "f() {}"); | 9435 FunctionDeclaration declaration = parser.parseFunctionDeclaration( |
| 9436 commentAndMetadata(comment), null, returnType); |
| 9437 expectNotNullIfNoErrors(declaration); |
| 9438 listener.assertNoErrors(); |
| 8123 expect(declaration.documentationComment, comment); | 9439 expect(declaration.documentationComment, comment); |
| 8124 expect(declaration.returnType, returnType); | 9440 expect(declaration.returnType, returnType); |
| 8125 expect(declaration.name, isNotNull); | 9441 expect(declaration.name, isNotNull); |
| 8126 FunctionExpression expression = declaration.functionExpression; | 9442 FunctionExpression expression = declaration.functionExpression; |
| 8127 expect(expression, isNotNull); | 9443 expect(expression, isNotNull); |
| 8128 expect(expression.body, isNotNull); | 9444 expect(expression.body, isNotNull); |
| 8129 expect(expression.typeParameters, isNull); | 9445 expect(expression.typeParameters, isNull); |
| 8130 expect(expression.parameters, isNotNull); | 9446 expect(expression.parameters, isNotNull); |
| 8131 expect(declaration.propertyKeyword, isNull); | 9447 expect(declaration.propertyKeyword, isNull); |
| 8132 } | 9448 } |
| 8133 | 9449 |
| 8134 void test_parseFunctionDeclaration_functionWithTypeParameters() { | 9450 void test_parseFunctionDeclaration_functionWithTypeParameters() { |
| 8135 enableGenericMethods = true; | 9451 enableGenericMethods = true; |
| 8136 Comment comment = Comment.createDocumentationComment(new List<Token>(0)); | 9452 Comment comment = Comment.createDocumentationComment(new List<Token>(0)); |
| 8137 TypeName returnType = new TypeName(new SimpleIdentifier(null), null); | 9453 TypeName returnType = new TypeName(new SimpleIdentifier(null), null); |
| 8138 FunctionDeclaration declaration = parse("parseFunctionDeclaration", | 9454 createParser('f<E>() {}'); |
| 8139 <Object>[commentAndMetadata(comment), null, returnType], "f<E>() {}"); | 9455 FunctionDeclaration declaration = parser.parseFunctionDeclaration( |
| 9456 commentAndMetadata(comment), null, returnType); |
| 9457 expectNotNullIfNoErrors(declaration); |
| 9458 listener.assertNoErrors(); |
| 8140 expect(declaration.documentationComment, comment); | 9459 expect(declaration.documentationComment, comment); |
| 8141 expect(declaration.returnType, returnType); | 9460 expect(declaration.returnType, returnType); |
| 8142 expect(declaration.name, isNotNull); | 9461 expect(declaration.name, isNotNull); |
| 9462 FunctionExpression expression = declaration.functionExpression; |
| 9463 expect(expression, isNotNull); |
| 9464 expect(expression.body, isNotNull); |
| 9465 expect(expression.typeParameters, isNotNull); |
| 9466 expect(expression.parameters, isNotNull); |
| 9467 expect(declaration.propertyKeyword, isNull); |
| 9468 } |
| 9469 |
| 9470 void test_parseFunctionDeclaration_functionWithTypeParameters_comment() { |
| 9471 enableGenericMethodComments = true; |
| 9472 Comment comment = Comment.createDocumentationComment(new List<Token>(0)); |
| 9473 TypeName returnType = new TypeName(new SimpleIdentifier(null), null); |
| 9474 createParser('f/*<E>*/() {}'); |
| 9475 FunctionDeclaration declaration = parser.parseFunctionDeclaration( |
| 9476 commentAndMetadata(comment), null, returnType); |
| 9477 expectNotNullIfNoErrors(declaration); |
| 9478 listener.assertNoErrors(); |
| 9479 expect(declaration.documentationComment, comment); |
| 9480 expect(declaration.returnType, returnType); |
| 9481 expect(declaration.name, isNotNull); |
| 8143 FunctionExpression expression = declaration.functionExpression; | 9482 FunctionExpression expression = declaration.functionExpression; |
| 8144 expect(expression, isNotNull); | 9483 expect(expression, isNotNull); |
| 8145 expect(expression.body, isNotNull); | 9484 expect(expression.body, isNotNull); |
| 8146 expect(expression.typeParameters, isNotNull); | 9485 expect(expression.typeParameters, isNotNull); |
| 8147 expect(expression.parameters, isNotNull); | 9486 expect(expression.parameters, isNotNull); |
| 8148 expect(declaration.propertyKeyword, isNull); | 9487 expect(declaration.propertyKeyword, isNull); |
| 8149 } | 9488 } |
| 8150 | 9489 |
| 8151 void test_parseFunctionDeclaration_getter() { | 9490 void test_parseFunctionDeclaration_getter() { |
| 8152 Comment comment = Comment.createDocumentationComment(new List<Token>(0)); | 9491 Comment comment = Comment.createDocumentationComment(new List<Token>(0)); |
| 8153 TypeName returnType = new TypeName(new SimpleIdentifier(null), null); | 9492 TypeName returnType = new TypeName(new SimpleIdentifier(null), null); |
| 8154 FunctionDeclaration declaration = parse("parseFunctionDeclaration", | 9493 createParser('get p => 0;'); |
| 8155 <Object>[commentAndMetadata(comment), null, returnType], "get p => 0;"); | 9494 FunctionDeclaration declaration = parser.parseFunctionDeclaration( |
| 9495 commentAndMetadata(comment), null, returnType); |
| 9496 expectNotNullIfNoErrors(declaration); |
| 9497 listener.assertNoErrors(); |
| 8156 expect(declaration.documentationComment, comment); | 9498 expect(declaration.documentationComment, comment); |
| 8157 expect(declaration.returnType, returnType); | 9499 expect(declaration.returnType, returnType); |
| 8158 expect(declaration.name, isNotNull); | 9500 expect(declaration.name, isNotNull); |
| 8159 FunctionExpression expression = declaration.functionExpression; | 9501 FunctionExpression expression = declaration.functionExpression; |
| 8160 expect(expression, isNotNull); | 9502 expect(expression, isNotNull); |
| 8161 expect(expression.body, isNotNull); | 9503 expect(expression.body, isNotNull); |
| 8162 expect(expression.typeParameters, isNull); | 9504 expect(expression.typeParameters, isNull); |
| 8163 expect(expression.parameters, isNull); | 9505 expect(expression.parameters, isNull); |
| 8164 expect(declaration.propertyKeyword, isNotNull); | 9506 expect(declaration.propertyKeyword, isNotNull); |
| 8165 } | 9507 } |
| 8166 | 9508 |
| 8167 void test_parseFunctionDeclaration_setter() { | 9509 void test_parseFunctionDeclaration_setter() { |
| 8168 Comment comment = Comment.createDocumentationComment(new List<Token>(0)); | 9510 Comment comment = Comment.createDocumentationComment(new List<Token>(0)); |
| 8169 TypeName returnType = new TypeName(new SimpleIdentifier(null), null); | 9511 TypeName returnType = new TypeName(new SimpleIdentifier(null), null); |
| 8170 FunctionDeclaration declaration = parse("parseFunctionDeclaration", | 9512 createParser('set p(v) {}'); |
| 8171 <Object>[commentAndMetadata(comment), null, returnType], "set p(v) {}"); | 9513 FunctionDeclaration declaration = parser.parseFunctionDeclaration( |
| 9514 commentAndMetadata(comment), null, returnType); |
| 9515 expectNotNullIfNoErrors(declaration); |
| 9516 listener.assertNoErrors(); |
| 8172 expect(declaration.documentationComment, comment); | 9517 expect(declaration.documentationComment, comment); |
| 8173 expect(declaration.returnType, returnType); | 9518 expect(declaration.returnType, returnType); |
| 8174 expect(declaration.name, isNotNull); | 9519 expect(declaration.name, isNotNull); |
| 8175 FunctionExpression expression = declaration.functionExpression; | 9520 FunctionExpression expression = declaration.functionExpression; |
| 8176 expect(expression, isNotNull); | 9521 expect(expression, isNotNull); |
| 8177 expect(expression.body, isNotNull); | 9522 expect(expression.body, isNotNull); |
| 8178 expect(expression.typeParameters, isNull); | 9523 expect(expression.typeParameters, isNull); |
| 8179 expect(expression.parameters, isNotNull); | 9524 expect(expression.parameters, isNotNull); |
| 8180 expect(declaration.propertyKeyword, isNotNull); | 9525 expect(declaration.propertyKeyword, isNotNull); |
| 8181 } | 9526 } |
| 8182 | 9527 |
| 8183 void test_parseFunctionDeclarationStatement() { | 9528 void test_parseFunctionDeclarationStatement() { |
| 9529 createParser('void f(int p) => p * 2;'); |
| 8184 FunctionDeclarationStatement statement = | 9530 FunctionDeclarationStatement statement = |
| 8185 parse4("parseFunctionDeclarationStatement", "void f(int p) => p * 2;"); | 9531 parser.parseFunctionDeclarationStatement(); |
| 9532 expectNotNullIfNoErrors(statement); |
| 9533 listener.assertNoErrors(); |
| 8186 expect(statement.functionDeclaration, isNotNull); | 9534 expect(statement.functionDeclaration, isNotNull); |
| 8187 } | 9535 } |
| 8188 | 9536 |
| 9537 void test_parseFunctionDeclarationStatement_typeParameterComments() { |
| 9538 enableGenericMethodComments = true; |
| 9539 createParser('/*=E*/ f/*<E>*/(/*=E*/ p) => p * 2;'); |
| 9540 FunctionDeclarationStatement statement = |
| 9541 parser.parseFunctionDeclarationStatement(); |
| 9542 expectNotNullIfNoErrors(statement); |
| 9543 listener.assertNoErrors(); |
| 9544 FunctionDeclaration f = statement.functionDeclaration; |
| 9545 expect(f, isNotNull); |
| 9546 expect(f.functionExpression.typeParameters, isNotNull); |
| 9547 expect(f.returnType, isNotNull); |
| 9548 SimpleFormalParameter p = f.functionExpression.parameters.parameters[0]; |
| 9549 expect(p.type, isNotNull); |
| 9550 } |
| 9551 |
| 8189 void test_parseFunctionDeclarationStatement_typeParameters() { | 9552 void test_parseFunctionDeclarationStatement_typeParameters() { |
| 8190 enableGenericMethods = true; | 9553 enableGenericMethods = true; |
| 9554 createParser('E f<E>(E p) => p * 2;'); |
| 8191 FunctionDeclarationStatement statement = | 9555 FunctionDeclarationStatement statement = |
| 8192 parse4("parseFunctionDeclarationStatement", "E f<E>(E p) => p * 2;"); | 9556 parser.parseFunctionDeclarationStatement(); |
| 9557 expectNotNullIfNoErrors(statement); |
| 9558 listener.assertNoErrors(); |
| 8193 expect(statement.functionDeclaration, isNotNull); | 9559 expect(statement.functionDeclaration, isNotNull); |
| 9560 expect(statement.functionDeclaration.functionExpression.typeParameters, |
| 9561 isNotNull); |
| 8194 } | 9562 } |
| 8195 | 9563 |
| 8196 void test_parseFunctionExpression_body_inExpression() { | 9564 void test_parseFunctionExpression_body_inExpression() { |
| 8197 FunctionExpression expression = | 9565 createParser('(int i) => i++'); |
| 8198 parse4("parseFunctionExpression", "(int i) => i++"); | 9566 FunctionExpression expression = parser.parseFunctionExpression(); |
| 9567 expectNotNullIfNoErrors(expression); |
| 9568 listener.assertNoErrors(); |
| 8199 expect(expression.body, isNotNull); | 9569 expect(expression.body, isNotNull); |
| 8200 expect(expression.typeParameters, isNull); | 9570 expect(expression.typeParameters, isNull); |
| 8201 expect(expression.parameters, isNotNull); | 9571 expect(expression.parameters, isNotNull); |
| 8202 expect((expression.body as ExpressionFunctionBody).semicolon, isNull); | 9572 expect((expression.body as ExpressionFunctionBody).semicolon, isNull); |
| 8203 } | 9573 } |
| 8204 | 9574 |
| 8205 void test_parseFunctionExpression_typeParameters() { | 9575 void test_parseFunctionExpression_typeParameterComments() { |
| 8206 enableGenericMethods = true; | 9576 enableGenericMethodComments = true; |
| 8207 FunctionExpression expression = | 9577 createParser('/*<E>*/(/*=E*/ i) => i++'); |
| 8208 parse4("parseFunctionExpression", "<E>(E i) => i++"); | 9578 FunctionExpression expression = parser.parseFunctionExpression(); |
| 9579 expectNotNullIfNoErrors(expression); |
| 9580 listener.assertNoErrors(); |
| 8209 expect(expression.body, isNotNull); | 9581 expect(expression.body, isNotNull); |
| 8210 expect(expression.typeParameters, isNotNull); | 9582 expect(expression.typeParameters, isNotNull); |
| 8211 expect(expression.parameters, isNotNull); | 9583 expect(expression.parameters, isNotNull); |
| 9584 expect((expression.body as ExpressionFunctionBody).semicolon, isNull); |
| 9585 SimpleFormalParameter p = expression.parameters.parameters[0]; |
| 9586 expect(p.type, isNotNull); |
| 9587 } |
| 9588 |
| 9589 void test_parseFunctionExpression_typeParameters() { |
| 9590 enableGenericMethods = true; |
| 9591 createParser('<E>(E i) => i++'); |
| 9592 FunctionExpression expression = parser.parseFunctionExpression(); |
| 9593 expectNotNullIfNoErrors(expression); |
| 9594 listener.assertNoErrors(); |
| 9595 expect(expression.body, isNotNull); |
| 9596 expect(expression.typeParameters, isNotNull); |
| 9597 expect(expression.parameters, isNotNull); |
| 8212 expect((expression.body as ExpressionFunctionBody).semicolon, isNull); | 9598 expect((expression.body as ExpressionFunctionBody).semicolon, isNull); |
| 8213 } | 9599 } |
| 8214 | 9600 |
| 8215 void test_parseGetter_nonStatic() { | 9601 void test_parseGetter_nonStatic() { |
| 8216 Comment comment = Comment.createDocumentationComment(new List<Token>(0)); | 9602 Comment comment = Comment.createDocumentationComment(new List<Token>(0)); |
| 8217 TypeName returnType = new TypeName(new SimpleIdentifier(null), null); | 9603 TypeName returnType = new TypeName(new SimpleIdentifier(null), null); |
| 8218 MethodDeclaration method = parse( | 9604 createParser('get a;'); |
| 8219 "parseGetter", | 9605 MethodDeclaration method = |
| 8220 <Object>[commentAndMetadata(comment), null, null, returnType], | 9606 parser.parseGetter(commentAndMetadata(comment), null, null, returnType); |
| 8221 "get a;"); | 9607 expectNotNullIfNoErrors(method); |
| 9608 listener.assertNoErrors(); |
| 8222 expect(method.body, isNotNull); | 9609 expect(method.body, isNotNull); |
| 8223 expect(method.documentationComment, comment); | 9610 expect(method.documentationComment, comment); |
| 8224 expect(method.externalKeyword, isNull); | 9611 expect(method.externalKeyword, isNull); |
| 8225 expect(method.modifierKeyword, isNull); | 9612 expect(method.modifierKeyword, isNull); |
| 8226 expect(method.name, isNotNull); | 9613 expect(method.name, isNotNull); |
| 8227 expect(method.operatorKeyword, isNull); | 9614 expect(method.operatorKeyword, isNull); |
| 8228 expect(method.parameters, isNull); | 9615 expect(method.parameters, isNull); |
| 8229 expect(method.propertyKeyword, isNotNull); | 9616 expect(method.propertyKeyword, isNotNull); |
| 8230 expect(method.returnType, returnType); | 9617 expect(method.returnType, returnType); |
| 8231 } | 9618 } |
| 8232 | 9619 |
| 8233 void test_parseGetter_static() { | 9620 void test_parseGetter_static() { |
| 8234 Comment comment = Comment.createDocumentationComment(new List<Token>(0)); | 9621 Comment comment = Comment.createDocumentationComment(new List<Token>(0)); |
| 8235 Token staticKeyword = TokenFactory.tokenFromKeyword(Keyword.STATIC); | 9622 Token staticKeyword = TokenFactory.tokenFromKeyword(Keyword.STATIC); |
| 8236 TypeName returnType = new TypeName(new SimpleIdentifier(null), null); | 9623 TypeName returnType = new TypeName(new SimpleIdentifier(null), null); |
| 8237 MethodDeclaration method = parse( | 9624 createParser('get a => 42;'); |
| 8238 "parseGetter", | 9625 MethodDeclaration method = parser.parseGetter( |
| 8239 <Object>[commentAndMetadata(comment), null, staticKeyword, returnType], | 9626 commentAndMetadata(comment), null, staticKeyword, returnType); |
| 8240 "get a => 42;"); | 9627 expectNotNullIfNoErrors(method); |
| 9628 listener.assertNoErrors(); |
| 8241 expect(method.body, isNotNull); | 9629 expect(method.body, isNotNull); |
| 8242 expect(method.documentationComment, comment); | 9630 expect(method.documentationComment, comment); |
| 8243 expect(method.externalKeyword, isNull); | 9631 expect(method.externalKeyword, isNull); |
| 8244 expect(method.modifierKeyword, staticKeyword); | 9632 expect(method.modifierKeyword, staticKeyword); |
| 8245 expect(method.name, isNotNull); | 9633 expect(method.name, isNotNull); |
| 8246 expect(method.operatorKeyword, isNull); | 9634 expect(method.operatorKeyword, isNull); |
| 8247 expect(method.typeParameters, isNull); | 9635 expect(method.typeParameters, isNull); |
| 8248 expect(method.parameters, isNull); | 9636 expect(method.parameters, isNull); |
| 8249 expect(method.propertyKeyword, isNotNull); | 9637 expect(method.propertyKeyword, isNotNull); |
| 8250 expect(method.returnType, returnType); | 9638 expect(method.returnType, returnType); |
| 8251 } | 9639 } |
| 8252 | 9640 |
| 8253 void test_parseIdentifierList_multiple() { | 9641 void test_parseIdentifierList_multiple() { |
| 8254 List<SimpleIdentifier> list = parse4("parseIdentifierList", "a, b, c"); | 9642 createParser('a, b, c'); |
| 9643 List<SimpleIdentifier> list = parser.parseIdentifierList(); |
| 9644 expectNotNullIfNoErrors(list); |
| 9645 listener.assertNoErrors(); |
| 8255 expect(list, hasLength(3)); | 9646 expect(list, hasLength(3)); |
| 8256 } | 9647 } |
| 8257 | 9648 |
| 8258 void test_parseIdentifierList_single() { | 9649 void test_parseIdentifierList_single() { |
| 8259 List<SimpleIdentifier> list = parse4("parseIdentifierList", "a"); | 9650 createParser('a'); |
| 9651 List<SimpleIdentifier> list = parser.parseIdentifierList(); |
| 9652 expectNotNullIfNoErrors(list); |
| 9653 listener.assertNoErrors(); |
| 8260 expect(list, hasLength(1)); | 9654 expect(list, hasLength(1)); |
| 8261 } | 9655 } |
| 8262 | 9656 |
| 8263 void test_parseIfStatement_else_block() { | 9657 void test_parseIfStatement_else_block() { |
| 8264 IfStatement statement = parse4("parseIfStatement", "if (x) {} else {}"); | 9658 createParser('if (x) {} else {}'); |
| 9659 IfStatement statement = parser.parseIfStatement(); |
| 9660 expectNotNullIfNoErrors(statement); |
| 9661 listener.assertNoErrors(); |
| 8265 expect(statement.ifKeyword, isNotNull); | 9662 expect(statement.ifKeyword, isNotNull); |
| 8266 expect(statement.leftParenthesis, isNotNull); | 9663 expect(statement.leftParenthesis, isNotNull); |
| 8267 expect(statement.condition, isNotNull); | 9664 expect(statement.condition, isNotNull); |
| 8268 expect(statement.rightParenthesis, isNotNull); | 9665 expect(statement.rightParenthesis, isNotNull); |
| 8269 expect(statement.thenStatement, isNotNull); | 9666 expect(statement.thenStatement, isNotNull); |
| 8270 expect(statement.elseKeyword, isNotNull); | 9667 expect(statement.elseKeyword, isNotNull); |
| 8271 expect(statement.elseStatement, isNotNull); | 9668 expect(statement.elseStatement, isNotNull); |
| 8272 } | 9669 } |
| 8273 | 9670 |
| 8274 void test_parseIfStatement_else_statement() { | 9671 void test_parseIfStatement_else_statement() { |
| 8275 IfStatement statement = | 9672 createParser('if (x) f(x); else f(y);'); |
| 8276 parse4("parseIfStatement", "if (x) f(x); else f(y);"); | 9673 IfStatement statement = parser.parseIfStatement(); |
| 9674 expectNotNullIfNoErrors(statement); |
| 9675 listener.assertNoErrors(); |
| 8277 expect(statement.ifKeyword, isNotNull); | 9676 expect(statement.ifKeyword, isNotNull); |
| 8278 expect(statement.leftParenthesis, isNotNull); | 9677 expect(statement.leftParenthesis, isNotNull); |
| 8279 expect(statement.condition, isNotNull); | 9678 expect(statement.condition, isNotNull); |
| 8280 expect(statement.rightParenthesis, isNotNull); | 9679 expect(statement.rightParenthesis, isNotNull); |
| 8281 expect(statement.thenStatement, isNotNull); | 9680 expect(statement.thenStatement, isNotNull); |
| 8282 expect(statement.elseKeyword, isNotNull); | 9681 expect(statement.elseKeyword, isNotNull); |
| 8283 expect(statement.elseStatement, isNotNull); | 9682 expect(statement.elseStatement, isNotNull); |
| 8284 } | 9683 } |
| 8285 | 9684 |
| 8286 void test_parseIfStatement_noElse_block() { | 9685 void test_parseIfStatement_noElse_block() { |
| 8287 IfStatement statement = parse4("parseIfStatement", "if (x) {}"); | 9686 createParser('if (x) {}'); |
| 9687 IfStatement statement = parser.parseIfStatement(); |
| 9688 expectNotNullIfNoErrors(statement); |
| 9689 listener.assertNoErrors(); |
| 8288 expect(statement.ifKeyword, isNotNull); | 9690 expect(statement.ifKeyword, isNotNull); |
| 8289 expect(statement.leftParenthesis, isNotNull); | 9691 expect(statement.leftParenthesis, isNotNull); |
| 8290 expect(statement.condition, isNotNull); | 9692 expect(statement.condition, isNotNull); |
| 8291 expect(statement.rightParenthesis, isNotNull); | 9693 expect(statement.rightParenthesis, isNotNull); |
| 8292 expect(statement.thenStatement, isNotNull); | 9694 expect(statement.thenStatement, isNotNull); |
| 8293 expect(statement.elseKeyword, isNull); | 9695 expect(statement.elseKeyword, isNull); |
| 8294 expect(statement.elseStatement, isNull); | 9696 expect(statement.elseStatement, isNull); |
| 8295 } | 9697 } |
| 8296 | 9698 |
| 8297 void test_parseIfStatement_noElse_statement() { | 9699 void test_parseIfStatement_noElse_statement() { |
| 8298 IfStatement statement = parse4("parseIfStatement", "if (x) f(x);"); | 9700 createParser('if (x) f(x);'); |
| 9701 IfStatement statement = parser.parseIfStatement(); |
| 9702 expectNotNullIfNoErrors(statement); |
| 9703 listener.assertNoErrors(); |
| 8299 expect(statement.ifKeyword, isNotNull); | 9704 expect(statement.ifKeyword, isNotNull); |
| 8300 expect(statement.leftParenthesis, isNotNull); | 9705 expect(statement.leftParenthesis, isNotNull); |
| 8301 expect(statement.condition, isNotNull); | 9706 expect(statement.condition, isNotNull); |
| 8302 expect(statement.rightParenthesis, isNotNull); | 9707 expect(statement.rightParenthesis, isNotNull); |
| 8303 expect(statement.thenStatement, isNotNull); | 9708 expect(statement.thenStatement, isNotNull); |
| 8304 expect(statement.elseKeyword, isNull); | 9709 expect(statement.elseKeyword, isNull); |
| 8305 expect(statement.elseStatement, isNull); | 9710 expect(statement.elseStatement, isNull); |
| 8306 } | 9711 } |
| 8307 | 9712 |
| 8308 void test_parseImplementsClause_multiple() { | 9713 void test_parseImplementsClause_multiple() { |
| 8309 ImplementsClause clause = | 9714 createParser('implements A, B, C'); |
| 8310 parse4("parseImplementsClause", "implements A, B, C"); | 9715 ImplementsClause clause = parser.parseImplementsClause(); |
| 9716 expectNotNullIfNoErrors(clause); |
| 9717 listener.assertNoErrors(); |
| 8311 expect(clause.interfaces, hasLength(3)); | 9718 expect(clause.interfaces, hasLength(3)); |
| 8312 expect(clause.implementsKeyword, isNotNull); | 9719 expect(clause.implementsKeyword, isNotNull); |
| 8313 } | 9720 } |
| 8314 | 9721 |
| 8315 void test_parseImplementsClause_single() { | 9722 void test_parseImplementsClause_single() { |
| 8316 ImplementsClause clause = parse4("parseImplementsClause", "implements A"); | 9723 createParser('implements A'); |
| 9724 ImplementsClause clause = parser.parseImplementsClause(); |
| 9725 expectNotNullIfNoErrors(clause); |
| 9726 listener.assertNoErrors(); |
| 8317 expect(clause.interfaces, hasLength(1)); | 9727 expect(clause.interfaces, hasLength(1)); |
| 8318 expect(clause.implementsKeyword, isNotNull); | 9728 expect(clause.implementsKeyword, isNotNull); |
| 8319 } | 9729 } |
| 8320 | 9730 |
| 9731 void test_parseImportDirective_configuration_multiple() { |
| 9732 createParser("import 'lib/lib.dart' if (a) 'b.dart' if (c) 'd.dart';"); |
| 9733 ImportDirective directive = |
| 9734 parser.parseImportDirective(emptyCommentAndMetadata()); |
| 9735 expectNotNullIfNoErrors(directive); |
| 9736 listener.assertNoErrors(); |
| 9737 expect(directive.keyword, isNotNull); |
| 9738 expect(directive.uri, isNotNull); |
| 9739 expect(directive.configurations, hasLength(2)); |
| 9740 _expectDottedName(directive.configurations[0].name, ['a']); |
| 9741 _expectDottedName(directive.configurations[1].name, ['c']); |
| 9742 expect(directive.deferredKeyword, isNull); |
| 9743 expect(directive.asKeyword, isNull); |
| 9744 expect(directive.prefix, isNull); |
| 9745 expect(directive.combinators, hasLength(0)); |
| 9746 expect(directive.semicolon, isNotNull); |
| 9747 } |
| 9748 |
| 9749 void test_parseImportDirective_configuration_single() { |
| 9750 createParser("import 'lib/lib.dart' if (a.b == 'c.dart') '';"); |
| 9751 ImportDirective directive = |
| 9752 parser.parseImportDirective(emptyCommentAndMetadata()); |
| 9753 expectNotNullIfNoErrors(directive); |
| 9754 listener.assertNoErrors(); |
| 9755 expect(directive.keyword, isNotNull); |
| 9756 expect(directive.uri, isNotNull); |
| 9757 expect(directive.configurations, hasLength(1)); |
| 9758 _expectDottedName(directive.configurations[0].name, ['a', 'b']); |
| 9759 expect(directive.deferredKeyword, isNull); |
| 9760 expect(directive.asKeyword, isNull); |
| 9761 expect(directive.prefix, isNull); |
| 9762 expect(directive.combinators, hasLength(0)); |
| 9763 expect(directive.semicolon, isNotNull); |
| 9764 } |
| 9765 |
| 8321 void test_parseImportDirective_deferred() { | 9766 void test_parseImportDirective_deferred() { |
| 8322 ImportDirective directive = parse( | 9767 createParser("import 'lib/lib.dart' deferred as a;"); |
| 8323 "parseImportDirective", | 9768 ImportDirective directive = |
| 8324 <Object>[emptyCommentAndMetadata()], | 9769 parser.parseImportDirective(emptyCommentAndMetadata()); |
| 8325 "import 'lib/lib.dart' deferred as a;"); | 9770 expectNotNullIfNoErrors(directive); |
| 9771 listener.assertNoErrors(); |
| 8326 expect(directive.keyword, isNotNull); | 9772 expect(directive.keyword, isNotNull); |
| 8327 expect(directive.uri, isNotNull); | 9773 expect(directive.uri, isNotNull); |
| 8328 expect(directive.deferredKeyword, isNotNull); | 9774 expect(directive.deferredKeyword, isNotNull); |
| 8329 expect(directive.asKeyword, isNotNull); | 9775 expect(directive.asKeyword, isNotNull); |
| 8330 expect(directive.prefix, isNotNull); | 9776 expect(directive.prefix, isNotNull); |
| 8331 expect(directive.combinators, hasLength(0)); | 9777 expect(directive.combinators, hasLength(0)); |
| 8332 expect(directive.semicolon, isNotNull); | 9778 expect(directive.semicolon, isNotNull); |
| 8333 } | 9779 } |
| 8334 | 9780 |
| 8335 void test_parseImportDirective_hide() { | 9781 void test_parseImportDirective_hide() { |
| 8336 ImportDirective directive = parse( | 9782 createParser("import 'lib/lib.dart' hide A, B;"); |
| 8337 "parseImportDirective", | 9783 ImportDirective directive = |
| 8338 <Object>[emptyCommentAndMetadata()], | 9784 parser.parseImportDirective(emptyCommentAndMetadata()); |
| 8339 "import 'lib/lib.dart' hide A, B;"); | 9785 expectNotNullIfNoErrors(directive); |
| 9786 listener.assertNoErrors(); |
| 8340 expect(directive.keyword, isNotNull); | 9787 expect(directive.keyword, isNotNull); |
| 8341 expect(directive.uri, isNotNull); | 9788 expect(directive.uri, isNotNull); |
| 8342 expect(directive.deferredKeyword, isNull); | 9789 expect(directive.deferredKeyword, isNull); |
| 8343 expect(directive.asKeyword, isNull); | 9790 expect(directive.asKeyword, isNull); |
| 8344 expect(directive.prefix, isNull); | 9791 expect(directive.prefix, isNull); |
| 8345 expect(directive.combinators, hasLength(1)); | 9792 expect(directive.combinators, hasLength(1)); |
| 8346 expect(directive.semicolon, isNotNull); | 9793 expect(directive.semicolon, isNotNull); |
| 8347 } | 9794 } |
| 8348 | 9795 |
| 8349 void test_parseImportDirective_noCombinator() { | 9796 void test_parseImportDirective_noCombinator() { |
| 8350 ImportDirective directive = parse("parseImportDirective", | 9797 createParser("import 'lib/lib.dart';"); |
| 8351 <Object>[emptyCommentAndMetadata()], "import 'lib/lib.dart';"); | 9798 ImportDirective directive = |
| 9799 parser.parseImportDirective(emptyCommentAndMetadata()); |
| 9800 expectNotNullIfNoErrors(directive); |
| 9801 listener.assertNoErrors(); |
| 8352 expect(directive.keyword, isNotNull); | 9802 expect(directive.keyword, isNotNull); |
| 8353 expect(directive.uri, isNotNull); | 9803 expect(directive.uri, isNotNull); |
| 8354 expect(directive.deferredKeyword, isNull); | 9804 expect(directive.deferredKeyword, isNull); |
| 8355 expect(directive.asKeyword, isNull); | 9805 expect(directive.asKeyword, isNull); |
| 8356 expect(directive.prefix, isNull); | 9806 expect(directive.prefix, isNull); |
| 8357 expect(directive.combinators, hasLength(0)); | 9807 expect(directive.combinators, hasLength(0)); |
| 8358 expect(directive.semicolon, isNotNull); | 9808 expect(directive.semicolon, isNotNull); |
| 8359 } | 9809 } |
| 8360 | 9810 |
| 8361 void test_parseImportDirective_prefix() { | 9811 void test_parseImportDirective_prefix() { |
| 8362 ImportDirective directive = parse("parseImportDirective", | 9812 createParser("import 'lib/lib.dart' as a;"); |
| 8363 <Object>[emptyCommentAndMetadata()], "import 'lib/lib.dart' as a;"); | 9813 ImportDirective directive = |
| 9814 parser.parseImportDirective(emptyCommentAndMetadata()); |
| 9815 expectNotNullIfNoErrors(directive); |
| 9816 listener.assertNoErrors(); |
| 8364 expect(directive.keyword, isNotNull); | 9817 expect(directive.keyword, isNotNull); |
| 8365 expect(directive.uri, isNotNull); | 9818 expect(directive.uri, isNotNull); |
| 8366 expect(directive.deferredKeyword, isNull); | 9819 expect(directive.deferredKeyword, isNull); |
| 8367 expect(directive.asKeyword, isNotNull); | 9820 expect(directive.asKeyword, isNotNull); |
| 8368 expect(directive.prefix, isNotNull); | 9821 expect(directive.prefix, isNotNull); |
| 8369 expect(directive.combinators, hasLength(0)); | 9822 expect(directive.combinators, hasLength(0)); |
| 8370 expect(directive.semicolon, isNotNull); | 9823 expect(directive.semicolon, isNotNull); |
| 8371 } | 9824 } |
| 8372 | 9825 |
| 8373 void test_parseImportDirective_prefix_hide_show() { | 9826 void test_parseImportDirective_prefix_hide_show() { |
| 8374 ImportDirective directive = parse( | 9827 createParser("import 'lib/lib.dart' as a hide A show B;"); |
| 8375 "parseImportDirective", | 9828 ImportDirective directive = |
| 8376 <Object>[emptyCommentAndMetadata()], | 9829 parser.parseImportDirective(emptyCommentAndMetadata()); |
| 8377 "import 'lib/lib.dart' as a hide A show B;"); | 9830 expectNotNullIfNoErrors(directive); |
| 9831 listener.assertNoErrors(); |
| 8378 expect(directive.keyword, isNotNull); | 9832 expect(directive.keyword, isNotNull); |
| 8379 expect(directive.uri, isNotNull); | 9833 expect(directive.uri, isNotNull); |
| 8380 expect(directive.deferredKeyword, isNull); | 9834 expect(directive.deferredKeyword, isNull); |
| 8381 expect(directive.asKeyword, isNotNull); | 9835 expect(directive.asKeyword, isNotNull); |
| 8382 expect(directive.prefix, isNotNull); | 9836 expect(directive.prefix, isNotNull); |
| 8383 expect(directive.combinators, hasLength(2)); | 9837 expect(directive.combinators, hasLength(2)); |
| 8384 expect(directive.semicolon, isNotNull); | 9838 expect(directive.semicolon, isNotNull); |
| 8385 } | 9839 } |
| 8386 | 9840 |
| 8387 void test_parseImportDirective_prefix_show_hide() { | 9841 void test_parseImportDirective_prefix_show_hide() { |
| 8388 ImportDirective directive = parse( | 9842 createParser("import 'lib/lib.dart' as a show B hide A;"); |
| 8389 "parseImportDirective", | 9843 ImportDirective directive = |
| 8390 <Object>[emptyCommentAndMetadata()], | 9844 parser.parseImportDirective(emptyCommentAndMetadata()); |
| 8391 "import 'lib/lib.dart' as a show B hide A;"); | 9845 expectNotNullIfNoErrors(directive); |
| 9846 listener.assertNoErrors(); |
| 8392 expect(directive.keyword, isNotNull); | 9847 expect(directive.keyword, isNotNull); |
| 8393 expect(directive.uri, isNotNull); | 9848 expect(directive.uri, isNotNull); |
| 8394 expect(directive.deferredKeyword, isNull); | 9849 expect(directive.deferredKeyword, isNull); |
| 8395 expect(directive.asKeyword, isNotNull); | 9850 expect(directive.asKeyword, isNotNull); |
| 8396 expect(directive.prefix, isNotNull); | 9851 expect(directive.prefix, isNotNull); |
| 8397 expect(directive.combinators, hasLength(2)); | 9852 expect(directive.combinators, hasLength(2)); |
| 8398 expect(directive.semicolon, isNotNull); | 9853 expect(directive.semicolon, isNotNull); |
| 8399 } | 9854 } |
| 8400 | 9855 |
| 8401 void test_parseImportDirective_show() { | 9856 void test_parseImportDirective_show() { |
| 8402 ImportDirective directive = parse( | 9857 createParser("import 'lib/lib.dart' show A, B;"); |
| 8403 "parseImportDirective", | 9858 ImportDirective directive = |
| 8404 <Object>[emptyCommentAndMetadata()], | 9859 parser.parseImportDirective(emptyCommentAndMetadata()); |
| 8405 "import 'lib/lib.dart' show A, B;"); | 9860 expectNotNullIfNoErrors(directive); |
| 9861 listener.assertNoErrors(); |
| 8406 expect(directive.keyword, isNotNull); | 9862 expect(directive.keyword, isNotNull); |
| 8407 expect(directive.uri, isNotNull); | 9863 expect(directive.uri, isNotNull); |
| 8408 expect(directive.deferredKeyword, isNull); | 9864 expect(directive.deferredKeyword, isNull); |
| 8409 expect(directive.asKeyword, isNull); | 9865 expect(directive.asKeyword, isNull); |
| 8410 expect(directive.prefix, isNull); | 9866 expect(directive.prefix, isNull); |
| 8411 expect(directive.combinators, hasLength(1)); | 9867 expect(directive.combinators, hasLength(1)); |
| 8412 expect(directive.semicolon, isNotNull); | 9868 expect(directive.semicolon, isNotNull); |
| 8413 } | 9869 } |
| 8414 | 9870 |
| 8415 void test_parseInitializedIdentifierList_type() { | 9871 void test_parseInitializedIdentifierList_type() { |
| 8416 Comment comment = Comment.createDocumentationComment(new List<Token>(0)); | 9872 Comment comment = Comment.createDocumentationComment(new List<Token>(0)); |
| 8417 Token staticKeyword = TokenFactory.tokenFromKeyword(Keyword.STATIC); | 9873 Token staticKeyword = TokenFactory.tokenFromKeyword(Keyword.STATIC); |
| 8418 TypeName type = new TypeName(new SimpleIdentifier(null), null); | 9874 TypeName type = new TypeName(new SimpleIdentifier(null), null); |
| 8419 FieldDeclaration declaration = parse( | 9875 createParser("a = 1, b, c = 3;"); |
| 8420 "parseInitializedIdentifierList", | 9876 FieldDeclaration declaration = parser.parseInitializedIdentifierList( |
| 8421 <Object>[commentAndMetadata(comment), staticKeyword, null, type], | 9877 commentAndMetadata(comment), staticKeyword, null, type); |
| 8422 "a = 1, b, c = 3;"); | 9878 expectNotNullIfNoErrors(declaration); |
| 9879 listener.assertNoErrors(); |
| 8423 expect(declaration.documentationComment, comment); | 9880 expect(declaration.documentationComment, comment); |
| 8424 VariableDeclarationList fields = declaration.fields; | 9881 VariableDeclarationList fields = declaration.fields; |
| 8425 expect(fields, isNotNull); | 9882 expect(fields, isNotNull); |
| 8426 expect(fields.keyword, isNull); | 9883 expect(fields.keyword, isNull); |
| 8427 expect(fields.type, type); | 9884 expect(fields.type, type); |
| 8428 expect(fields.variables, hasLength(3)); | 9885 expect(fields.variables, hasLength(3)); |
| 8429 expect(declaration.staticKeyword, staticKeyword); | 9886 expect(declaration.staticKeyword, staticKeyword); |
| 8430 expect(declaration.semicolon, isNotNull); | 9887 expect(declaration.semicolon, isNotNull); |
| 8431 } | 9888 } |
| 8432 | 9889 |
| 8433 void test_parseInitializedIdentifierList_var() { | 9890 void test_parseInitializedIdentifierList_var() { |
| 8434 Comment comment = Comment.createDocumentationComment(new List<Token>(0)); | 9891 Comment comment = Comment.createDocumentationComment(new List<Token>(0)); |
| 8435 Token staticKeyword = TokenFactory.tokenFromKeyword(Keyword.STATIC); | 9892 Token staticKeyword = TokenFactory.tokenFromKeyword(Keyword.STATIC); |
| 8436 Token varKeyword = TokenFactory.tokenFromKeyword(Keyword.VAR); | 9893 Token varKeyword = TokenFactory.tokenFromKeyword(Keyword.VAR); |
| 8437 FieldDeclaration declaration = parse( | 9894 createParser('a = 1, b, c = 3;'); |
| 8438 "parseInitializedIdentifierList", | 9895 FieldDeclaration declaration = parser.parseInitializedIdentifierList( |
| 8439 <Object>[commentAndMetadata(comment), staticKeyword, varKeyword, null], | 9896 commentAndMetadata(comment), staticKeyword, varKeyword, null); |
| 8440 "a = 1, b, c = 3;"); | 9897 expectNotNullIfNoErrors(declaration); |
| 9898 listener.assertNoErrors(); |
| 8441 expect(declaration.documentationComment, comment); | 9899 expect(declaration.documentationComment, comment); |
| 8442 VariableDeclarationList fields = declaration.fields; | 9900 VariableDeclarationList fields = declaration.fields; |
| 8443 expect(fields, isNotNull); | 9901 expect(fields, isNotNull); |
| 8444 expect(fields.keyword, varKeyword); | 9902 expect(fields.keyword, varKeyword); |
| 8445 expect(fields.type, isNull); | 9903 expect(fields.type, isNull); |
| 8446 expect(fields.variables, hasLength(3)); | 9904 expect(fields.variables, hasLength(3)); |
| 8447 expect(declaration.staticKeyword, staticKeyword); | 9905 expect(declaration.staticKeyword, staticKeyword); |
| 8448 expect(declaration.semicolon, isNotNull); | 9906 expect(declaration.semicolon, isNotNull); |
| 8449 } | 9907 } |
| 8450 | 9908 |
| 8451 void test_parseInstanceCreationExpression_qualifiedType() { | 9909 void test_parseInstanceCreationExpression_qualifiedType() { |
| 8452 Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); | 9910 Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| 8453 InstanceCreationExpression expression = | 9911 createParser('A.B()'); |
| 8454 parse("parseInstanceCreationExpression", <Object>[token], "A.B()"); | 9912 InstanceCreationExpression expression = |
| 8455 expect(expression.keyword, token); | 9913 parser.parseInstanceCreationExpression(token); |
| 8456 ConstructorName name = expression.constructorName; | 9914 expectNotNullIfNoErrors(expression); |
| 8457 expect(name, isNotNull); | 9915 listener.assertNoErrors(); |
| 8458 expect(name.type, isNotNull); | 9916 expect(expression.keyword, token); |
| 9917 ConstructorName name = expression.constructorName; |
| 9918 expect(name, isNotNull); |
| 9919 TypeName type = name.type; |
| 9920 expect(type, isNotNull); |
| 9921 expect(type.typeArguments, isNull); |
| 8459 expect(name.period, isNull); | 9922 expect(name.period, isNull); |
| 8460 expect(name.name, isNull); | 9923 expect(name.name, isNull); |
| 8461 expect(expression.argumentList, isNotNull); | 9924 expect(expression.argumentList, isNotNull); |
| 8462 } | 9925 } |
| 8463 | 9926 |
| 8464 void test_parseInstanceCreationExpression_qualifiedType_named() { | 9927 void test_parseInstanceCreationExpression_qualifiedType_named() { |
| 8465 Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); | 9928 Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| 8466 InstanceCreationExpression expression = | 9929 createParser('A.B.c()'); |
| 8467 parse("parseInstanceCreationExpression", <Object>[token], "A.B.c()"); | 9930 InstanceCreationExpression expression = |
| 8468 expect(expression.keyword, token); | 9931 parser.parseInstanceCreationExpression(token); |
| 8469 ConstructorName name = expression.constructorName; | 9932 expectNotNullIfNoErrors(expression); |
| 8470 expect(name, isNotNull); | 9933 listener.assertNoErrors(); |
| 8471 expect(name.type, isNotNull); | 9934 expect(expression.keyword, token); |
| 8472 expect(name.period, isNotNull); | 9935 ConstructorName name = expression.constructorName; |
| 8473 expect(name.name, isNotNull); | 9936 expect(name, isNotNull); |
| 9937 TypeName type = name.type; |
| 9938 expect(type, isNotNull); |
| 9939 expect(type.typeArguments, isNull); |
| 9940 expect(name.period, isNotNull); |
| 9941 expect(name.name, isNotNull); |
| 9942 expect(expression.argumentList, isNotNull); |
| 9943 } |
| 9944 |
| 9945 void |
| 9946 test_parseInstanceCreationExpression_qualifiedType_named_typeParameterComm
ent() { |
| 9947 enableGenericMethodComments = true; |
| 9948 Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| 9949 createParser('A.B/*<E>*/.c()'); |
| 9950 InstanceCreationExpression expression = |
| 9951 parser.parseInstanceCreationExpression(token); |
| 9952 expectNotNullIfNoErrors(expression); |
| 9953 listener.assertNoErrors(); |
| 9954 expect(expression.keyword, token); |
| 9955 ConstructorName name = expression.constructorName; |
| 9956 expect(name, isNotNull); |
| 9957 TypeName type = name.type; |
| 9958 expect(type, isNotNull); |
| 9959 expect(type.typeArguments.arguments, hasLength(1)); |
| 9960 expect(name.period, isNotNull); |
| 9961 expect(name.name, isNotNull); |
| 9962 expect(expression.argumentList, isNotNull); |
| 9963 } |
| 9964 |
| 9965 void |
| 9966 test_parseInstanceCreationExpression_qualifiedType_named_typeParameters()
{ |
| 9967 Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| 9968 createParser('A.B<E>.c()'); |
| 9969 InstanceCreationExpression expression = |
| 9970 parser.parseInstanceCreationExpression(token); |
| 9971 expectNotNullIfNoErrors(expression); |
| 9972 listener.assertNoErrors(); |
| 9973 expect(expression.keyword, token); |
| 9974 ConstructorName name = expression.constructorName; |
| 9975 expect(name, isNotNull); |
| 9976 TypeName type = name.type; |
| 9977 expect(type, isNotNull); |
| 9978 expect(type.typeArguments.arguments, hasLength(1)); |
| 9979 expect(name.period, isNotNull); |
| 9980 expect(name.name, isNotNull); |
| 9981 expect(expression.argumentList, isNotNull); |
| 9982 } |
| 9983 |
| 9984 void |
| 9985 test_parseInstanceCreationExpression_qualifiedType_typeParameterComment()
{ |
| 9986 enableGenericMethodComments = true; |
| 9987 Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| 9988 createParser('A.B/*<E>*/()'); |
| 9989 InstanceCreationExpression expression = |
| 9990 parser.parseInstanceCreationExpression(token); |
| 9991 expectNotNullIfNoErrors(expression); |
| 9992 listener.assertNoErrors(); |
| 9993 expect(expression.keyword, token); |
| 9994 ConstructorName name = expression.constructorName; |
| 9995 expect(name, isNotNull); |
| 9996 TypeName type = name.type; |
| 9997 expect(type, isNotNull); |
| 9998 expect(type.typeArguments.arguments, hasLength(1)); |
| 9999 expect(name.period, isNull); |
| 10000 expect(name.name, isNull); |
| 10001 expect(expression.argumentList, isNotNull); |
| 10002 } |
| 10003 |
| 10004 void test_parseInstanceCreationExpression_qualifiedType_typeParameters() { |
| 10005 Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| 10006 createParser('A.B<E>()'); |
| 10007 InstanceCreationExpression expression = |
| 10008 parser.parseInstanceCreationExpression(token); |
| 10009 expectNotNullIfNoErrors(expression); |
| 10010 listener.assertNoErrors(); |
| 10011 expect(expression.keyword, token); |
| 10012 ConstructorName name = expression.constructorName; |
| 10013 expect(name, isNotNull); |
| 10014 TypeName type = name.type; |
| 10015 expect(type, isNotNull); |
| 10016 expect(type.typeArguments.arguments, hasLength(1)); |
| 10017 expect(name.period, isNull); |
| 10018 expect(name.name, isNull); |
| 8474 expect(expression.argumentList, isNotNull); | 10019 expect(expression.argumentList, isNotNull); |
| 8475 } | 10020 } |
| 8476 | 10021 |
| 8477 void test_parseInstanceCreationExpression_type() { | 10022 void test_parseInstanceCreationExpression_type() { |
| 8478 Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); | 10023 Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| 8479 InstanceCreationExpression expression = | 10024 createParser('A()'); |
| 8480 parse("parseInstanceCreationExpression", <Object>[token], "A()"); | 10025 InstanceCreationExpression expression = |
| 8481 expect(expression.keyword, token); | 10026 parser.parseInstanceCreationExpression(token); |
| 8482 ConstructorName name = expression.constructorName; | 10027 expectNotNullIfNoErrors(expression); |
| 8483 expect(name, isNotNull); | 10028 listener.assertNoErrors(); |
| 8484 expect(name.type, isNotNull); | 10029 expect(expression.keyword, token); |
| 10030 ConstructorName name = expression.constructorName; |
| 10031 expect(name, isNotNull); |
| 10032 TypeName type = name.type; |
| 10033 expect(type, isNotNull); |
| 10034 expect(type.typeArguments, isNull); |
| 8485 expect(name.period, isNull); | 10035 expect(name.period, isNull); |
| 8486 expect(name.name, isNull); | 10036 expect(name.name, isNull); |
| 8487 expect(expression.argumentList, isNotNull); | 10037 expect(expression.argumentList, isNotNull); |
| 8488 } | 10038 } |
| 8489 | 10039 |
| 8490 void test_parseInstanceCreationExpression_type_named() { | 10040 void test_parseInstanceCreationExpression_type_named() { |
| 8491 Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); | 10041 enableGenericMethodComments = true; |
| 8492 InstanceCreationExpression expression = | 10042 Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| 8493 parse("parseInstanceCreationExpression", <Object>[token], "A<B>.c()"); | 10043 createParser('A.c()'); |
| 8494 expect(expression.keyword, token); | 10044 InstanceCreationExpression expression = |
| 8495 ConstructorName name = expression.constructorName; | 10045 parser.parseInstanceCreationExpression(token); |
| 8496 expect(name, isNotNull); | 10046 expectNotNullIfNoErrors(expression); |
| 8497 expect(name.type, isNotNull); | 10047 listener.assertNoErrors(); |
| 8498 expect(name.period, isNotNull); | 10048 expect(expression.keyword, token); |
| 8499 expect(name.name, isNotNull); | 10049 ConstructorName name = expression.constructorName; |
| 8500 expect(expression.argumentList, isNotNull); | 10050 expect(name, isNotNull); |
| 10051 TypeName type = name.type; |
| 10052 expect(type, isNotNull); |
| 10053 expect(type.typeArguments, isNull); |
| 10054 expect(name.period, isNull); |
| 10055 expect(name.name, isNull); |
| 10056 expect(expression.argumentList, isNotNull); |
| 10057 } |
| 10058 |
| 10059 void test_parseInstanceCreationExpression_type_named_typeParameterComment() { |
| 10060 enableGenericMethodComments = true; |
| 10061 Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| 10062 createParser('A/*<B>*/.c()'); |
| 10063 InstanceCreationExpression expression = |
| 10064 parser.parseInstanceCreationExpression(token); |
| 10065 expectNotNullIfNoErrors(expression); |
| 10066 listener.assertNoErrors(); |
| 10067 expect(expression.keyword, token); |
| 10068 ConstructorName name = expression.constructorName; |
| 10069 expect(name, isNotNull); |
| 10070 TypeName type = name.type; |
| 10071 expect(type, isNotNull); |
| 10072 expect(type.typeArguments.arguments, hasLength(1)); |
| 10073 expect(name.period, isNotNull); |
| 10074 expect(name.name, isNotNull); |
| 10075 expect(expression.argumentList, isNotNull); |
| 10076 } |
| 10077 |
| 10078 void test_parseInstanceCreationExpression_type_named_typeParameters() { |
| 10079 Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| 10080 createParser('A<B>.c()'); |
| 10081 InstanceCreationExpression expression = |
| 10082 parser.parseInstanceCreationExpression(token); |
| 10083 expectNotNullIfNoErrors(expression); |
| 10084 listener.assertNoErrors(); |
| 10085 expect(expression.keyword, token); |
| 10086 ConstructorName name = expression.constructorName; |
| 10087 expect(name, isNotNull); |
| 10088 TypeName type = name.type; |
| 10089 expect(type, isNotNull); |
| 10090 expect(type.typeArguments.arguments, hasLength(1)); |
| 10091 expect(name.period, isNotNull); |
| 10092 expect(name.name, isNotNull); |
| 10093 expect(expression.argumentList, isNotNull); |
| 10094 } |
| 10095 |
| 10096 void test_parseInstanceCreationExpression_type_typeParameterComment() { |
| 10097 enableGenericMethodComments = true; |
| 10098 Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| 10099 createParser('A/*<B>*/()'); |
| 10100 InstanceCreationExpression expression = |
| 10101 parser.parseInstanceCreationExpression(token); |
| 10102 expectNotNullIfNoErrors(expression); |
| 10103 listener.assertNoErrors(); |
| 10104 expect(expression.keyword, token); |
| 10105 ConstructorName name = expression.constructorName; |
| 10106 expect(name, isNotNull); |
| 10107 TypeName type = name.type; |
| 10108 expect(type, isNotNull); |
| 10109 expect(type.typeArguments.arguments, hasLength(1)); |
| 10110 expect(name.period, isNull); |
| 10111 expect(name.name, isNull); |
| 10112 expect(expression.argumentList, isNotNull); |
| 10113 } |
| 10114 |
| 10115 void test_parseInstanceCreationExpression_type_typeParameters() { |
| 10116 Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| 10117 createParser('A<B>()'); |
| 10118 InstanceCreationExpression expression = |
| 10119 parser.parseInstanceCreationExpression(token); |
| 10120 expectNotNullIfNoErrors(expression); |
| 10121 listener.assertNoErrors(); |
| 10122 expect(expression.keyword, token); |
| 10123 ConstructorName name = expression.constructorName; |
| 10124 expect(name, isNotNull); |
| 10125 TypeName type = name.type; |
| 10126 expect(type, isNotNull); |
| 10127 expect(type.typeArguments.arguments, hasLength(1)); |
| 10128 expect(name.period, isNull); |
| 10129 expect(name.name, isNull); |
| 10130 expect(expression.argumentList, isNotNull); |
| 10131 } |
| 10132 |
| 10133 void test_parseInstanceCreationExpression_type_typeParameters_nullable() { |
| 10134 enableNnbd = true; |
| 10135 Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
| 10136 createParser('A<B?>()'); |
| 10137 InstanceCreationExpression expression = |
| 10138 parser.parseInstanceCreationExpression(token); |
| 10139 expectNotNullIfNoErrors(expression); |
| 10140 listener.assertNoErrors(); |
| 10141 expect(expression.keyword, token); |
| 10142 ConstructorName name = expression.constructorName; |
| 10143 expect(name, isNotNull); |
| 10144 TypeName type = name.type; |
| 10145 expect(type, isNotNull); |
| 10146 expect(name.period, isNull); |
| 10147 expect(name.name, isNull); |
| 10148 expect(expression.argumentList, isNotNull); |
| 10149 NodeList<TypeName> arguments = type.typeArguments.arguments; |
| 10150 expect(arguments, hasLength(1)); |
| 10151 expect(arguments[0].question, isNotNull); |
| 8501 } | 10152 } |
| 8502 | 10153 |
| 8503 void test_parseLibraryDirective() { | 10154 void test_parseLibraryDirective() { |
| 8504 LibraryDirective directive = parse("parseLibraryDirective", | 10155 createParser('library l;'); |
| 8505 <Object>[emptyCommentAndMetadata()], "library l;"); | 10156 LibraryDirective directive = |
| 10157 parser.parseLibraryDirective(emptyCommentAndMetadata()); |
| 10158 expectNotNullIfNoErrors(directive); |
| 10159 listener.assertNoErrors(); |
| 8506 expect(directive.libraryKeyword, isNotNull); | 10160 expect(directive.libraryKeyword, isNotNull); |
| 8507 expect(directive.name, isNotNull); | 10161 expect(directive.name, isNotNull); |
| 8508 expect(directive.semicolon, isNotNull); | 10162 expect(directive.semicolon, isNotNull); |
| 8509 } | 10163 } |
| 8510 | 10164 |
| 8511 void test_parseLibraryIdentifier_multiple() { | 10165 void test_parseLibraryIdentifier_multiple() { |
| 8512 String name = "a.b.c"; | 10166 String name = "a.b.c"; |
| 8513 LibraryIdentifier identifier = parse4("parseLibraryIdentifier", name); | 10167 createParser(name); |
| 10168 LibraryIdentifier identifier = parser.parseLibraryIdentifier(); |
| 10169 expectNotNullIfNoErrors(identifier); |
| 10170 listener.assertNoErrors(); |
| 8514 expect(identifier.name, name); | 10171 expect(identifier.name, name); |
| 8515 } | 10172 } |
| 8516 | 10173 |
| 8517 void test_parseLibraryIdentifier_single() { | 10174 void test_parseLibraryIdentifier_single() { |
| 8518 String name = "a"; | 10175 String name = "a"; |
| 8519 LibraryIdentifier identifier = parse4("parseLibraryIdentifier", name); | 10176 createParser(name); |
| 10177 LibraryIdentifier identifier = parser.parseLibraryIdentifier(); |
| 10178 expectNotNullIfNoErrors(identifier); |
| 10179 listener.assertNoErrors(); |
| 8520 expect(identifier.name, name); | 10180 expect(identifier.name, name); |
| 8521 } | 10181 } |
| 8522 | 10182 |
| 8523 void test_parseListLiteral_empty_oneToken() { | 10183 void test_parseListLiteral_empty_oneToken() { |
| 8524 Token token = TokenFactory.tokenFromKeyword(Keyword.CONST); | 10184 Token token = TokenFactory.tokenFromKeyword(Keyword.CONST); |
| 8525 TypeArgumentList typeArguments = null; | 10185 TypeArgumentList typeArguments = null; |
| 8526 ListLiteral literal = | 10186 createParser('[]'); |
| 8527 parse("parseListLiteral", <Object>[token, typeArguments], "[]"); | 10187 ListLiteral literal = parser.parseListLiteral(token, typeArguments); |
| 10188 expectNotNullIfNoErrors(literal); |
| 10189 listener.assertNoErrors(); |
| 8528 expect(literal.constKeyword, token); | 10190 expect(literal.constKeyword, token); |
| 8529 expect(literal.typeArguments, typeArguments); | 10191 expect(literal.typeArguments, typeArguments); |
| 8530 expect(literal.leftBracket, isNotNull); | 10192 expect(literal.leftBracket, isNotNull); |
| 8531 expect(literal.elements, hasLength(0)); | 10193 expect(literal.elements, hasLength(0)); |
| 8532 expect(literal.rightBracket, isNotNull); | 10194 expect(literal.rightBracket, isNotNull); |
| 8533 } | 10195 } |
| 8534 | 10196 |
| 8535 void test_parseListLiteral_empty_oneToken_withComment() { | 10197 void test_parseListLiteral_empty_oneToken_withComment() { |
| 8536 Token constToken = null; | 10198 Token token = null; |
| 8537 TypeArgumentList typeArguments = null; | 10199 TypeArgumentList typeArguments = null; |
| 8538 ListLiteral literal = parse( | 10200 createParser('/* 0 */ []'); |
| 8539 "parseListLiteral", <Object>[constToken, typeArguments], "/* 0 */ []"); | 10201 ListLiteral literal = parser.parseListLiteral(token, typeArguments); |
| 8540 expect(literal.constKeyword, constToken); | 10202 expectNotNullIfNoErrors(literal); |
| 10203 listener.assertNoErrors(); |
| 10204 expect(literal.constKeyword, token); |
| 8541 expect(literal.typeArguments, typeArguments); | 10205 expect(literal.typeArguments, typeArguments); |
| 8542 Token leftBracket = literal.leftBracket; | 10206 Token leftBracket = literal.leftBracket; |
| 8543 expect(leftBracket, isNotNull); | 10207 expect(leftBracket, isNotNull); |
| 8544 expect(leftBracket.precedingComments, isNotNull); | 10208 expect(leftBracket.precedingComments, isNotNull); |
| 8545 expect(literal.elements, hasLength(0)); | 10209 expect(literal.elements, hasLength(0)); |
| 8546 expect(literal.rightBracket, isNotNull); | 10210 expect(literal.rightBracket, isNotNull); |
| 8547 } | 10211 } |
| 8548 | 10212 |
| 8549 void test_parseListLiteral_empty_twoTokens() { | 10213 void test_parseListLiteral_empty_twoTokens() { |
| 8550 Token token = TokenFactory.tokenFromKeyword(Keyword.CONST); | 10214 Token token = TokenFactory.tokenFromKeyword(Keyword.CONST); |
| 8551 TypeArgumentList typeArguments = null; | 10215 TypeArgumentList typeArguments = null; |
| 8552 ListLiteral literal = | 10216 createParser('[ ]'); |
| 8553 parse("parseListLiteral", <Object>[token, typeArguments], "[ ]"); | 10217 ListLiteral literal = parser.parseListLiteral(token, typeArguments); |
| 10218 expectNotNullIfNoErrors(literal); |
| 10219 listener.assertNoErrors(); |
| 8554 expect(literal.constKeyword, token); | 10220 expect(literal.constKeyword, token); |
| 8555 expect(literal.typeArguments, typeArguments); | 10221 expect(literal.typeArguments, typeArguments); |
| 8556 expect(literal.leftBracket, isNotNull); | 10222 expect(literal.leftBracket, isNotNull); |
| 8557 expect(literal.elements, hasLength(0)); | 10223 expect(literal.elements, hasLength(0)); |
| 8558 expect(literal.rightBracket, isNotNull); | 10224 expect(literal.rightBracket, isNotNull); |
| 8559 } | 10225 } |
| 8560 | 10226 |
| 8561 void test_parseListLiteral_multiple() { | 10227 void test_parseListLiteral_multiple() { |
| 8562 ListLiteral literal = | 10228 createParser('[1, 2, 3]'); |
| 8563 parse("parseListLiteral", <Object>[null, null], "[1, 2, 3]"); | 10229 ListLiteral literal = parser.parseListLiteral(null, null); |
| 10230 expectNotNullIfNoErrors(literal); |
| 10231 listener.assertNoErrors(); |
| 8564 expect(literal.constKeyword, isNull); | 10232 expect(literal.constKeyword, isNull); |
| 8565 expect(literal.typeArguments, isNull); | 10233 expect(literal.typeArguments, isNull); |
| 8566 expect(literal.leftBracket, isNotNull); | 10234 expect(literal.leftBracket, isNotNull); |
| 8567 expect(literal.elements, hasLength(3)); | 10235 expect(literal.elements, hasLength(3)); |
| 8568 expect(literal.rightBracket, isNotNull); | 10236 expect(literal.rightBracket, isNotNull); |
| 8569 } | 10237 } |
| 8570 | 10238 |
| 8571 void test_parseListLiteral_single() { | 10239 void test_parseListLiteral_single() { |
| 8572 ListLiteral literal = | 10240 createParser('[1]'); |
| 8573 parse("parseListLiteral", <Object>[null, null], "[1]"); | 10241 ListLiteral literal = parser.parseListLiteral(null, null); |
| 10242 expectNotNullIfNoErrors(literal); |
| 10243 listener.assertNoErrors(); |
| 8574 expect(literal.constKeyword, isNull); | 10244 expect(literal.constKeyword, isNull); |
| 8575 expect(literal.typeArguments, isNull); | 10245 expect(literal.typeArguments, isNull); |
| 8576 expect(literal.leftBracket, isNotNull); | 10246 expect(literal.leftBracket, isNotNull); |
| 8577 expect(literal.elements, hasLength(1)); | 10247 expect(literal.elements, hasLength(1)); |
| 8578 expect(literal.rightBracket, isNotNull); | 10248 expect(literal.rightBracket, isNotNull); |
| 8579 } | 10249 } |
| 8580 | 10250 |
| 8581 void test_parseListOrMapLiteral_list_noType() { | 10251 void test_parseListOrMapLiteral_list_noType() { |
| 8582 ListLiteral literal = parse("parseListOrMapLiteral", <Object>[null], "[1]"); | 10252 createParser('[1]'); |
| 8583 expect(literal.constKeyword, isNull); | 10253 TypedLiteral literal = parser.parseListOrMapLiteral(null); |
| 8584 expect(literal.typeArguments, isNull); | 10254 expectNotNullIfNoErrors(literal); |
| 8585 expect(literal.leftBracket, isNotNull); | 10255 listener.assertNoErrors(); |
| 8586 expect(literal.elements, hasLength(1)); | 10256 expect(literal, new isInstanceOf<ListLiteral>()); |
| 8587 expect(literal.rightBracket, isNotNull); | 10257 ListLiteral listLiteral = literal; |
| 10258 expect(listLiteral.constKeyword, isNull); |
| 10259 expect(listLiteral.typeArguments, isNull); |
| 10260 expect(listLiteral.leftBracket, isNotNull); |
| 10261 expect(listLiteral.elements, hasLength(1)); |
| 10262 expect(listLiteral.rightBracket, isNotNull); |
| 8588 } | 10263 } |
| 8589 | 10264 |
| 8590 void test_parseListOrMapLiteral_list_type() { | 10265 void test_parseListOrMapLiteral_list_type() { |
| 8591 ListLiteral literal = | 10266 createParser('<int> [1]'); |
| 8592 parse("parseListOrMapLiteral", <Object>[null], "<int> [1]"); | 10267 TypedLiteral literal = parser.parseListOrMapLiteral(null); |
| 8593 expect(literal.constKeyword, isNull); | 10268 expectNotNullIfNoErrors(literal); |
| 8594 expect(literal.typeArguments, isNotNull); | 10269 listener.assertNoErrors(); |
| 8595 expect(literal.leftBracket, isNotNull); | 10270 expect(literal, new isInstanceOf<ListLiteral>()); |
| 8596 expect(literal.elements, hasLength(1)); | 10271 ListLiteral listLiteral = literal; |
| 8597 expect(literal.rightBracket, isNotNull); | 10272 expect(listLiteral.constKeyword, isNull); |
| 10273 expect(listLiteral.typeArguments, isNotNull); |
| 10274 expect(listLiteral.leftBracket, isNotNull); |
| 10275 expect(listLiteral.elements, hasLength(1)); |
| 10276 expect(listLiteral.rightBracket, isNotNull); |
| 8598 } | 10277 } |
| 8599 | 10278 |
| 8600 void test_parseListOrMapLiteral_map_noType() { | 10279 void test_parseListOrMapLiteral_map_noType() { |
| 8601 MapLiteral literal = | 10280 createParser("{'1' : 1}"); |
| 8602 parse("parseListOrMapLiteral", <Object>[null], "{'1' : 1}"); | 10281 TypedLiteral literal = parser.parseListOrMapLiteral(null); |
| 8603 expect(literal.constKeyword, isNull); | 10282 expectNotNullIfNoErrors(literal); |
| 8604 expect(literal.typeArguments, isNull); | 10283 listener.assertNoErrors(); |
| 8605 expect(literal.leftBracket, isNotNull); | 10284 expect(literal, new isInstanceOf<MapLiteral>()); |
| 8606 expect(literal.entries, hasLength(1)); | 10285 MapLiteral mapLiteral = literal; |
| 8607 expect(literal.rightBracket, isNotNull); | 10286 expect(mapLiteral.constKeyword, isNull); |
| 10287 expect(mapLiteral.typeArguments, isNull); |
| 10288 expect(mapLiteral.leftBracket, isNotNull); |
| 10289 expect(mapLiteral.entries, hasLength(1)); |
| 10290 expect(mapLiteral.rightBracket, isNotNull); |
| 8608 } | 10291 } |
| 8609 | 10292 |
| 8610 void test_parseListOrMapLiteral_map_type() { | 10293 void test_parseListOrMapLiteral_map_type() { |
| 8611 MapLiteral literal = parse( | 10294 createParser("<String, int> {'1' : 1}"); |
| 8612 "parseListOrMapLiteral", <Object>[null], "<String, int> {'1' : 1}"); | 10295 TypedLiteral literal = parser.parseListOrMapLiteral(null); |
| 8613 expect(literal.constKeyword, isNull); | 10296 expectNotNullIfNoErrors(literal); |
| 8614 expect(literal.typeArguments, isNotNull); | 10297 listener.assertNoErrors(); |
| 8615 expect(literal.leftBracket, isNotNull); | 10298 expect(literal, new isInstanceOf<MapLiteral>()); |
| 8616 expect(literal.entries, hasLength(1)); | 10299 MapLiteral mapLiteral = literal; |
| 8617 expect(literal.rightBracket, isNotNull); | 10300 expect(mapLiteral.constKeyword, isNull); |
| 10301 expect(mapLiteral.typeArguments, isNotNull); |
| 10302 expect(mapLiteral.leftBracket, isNotNull); |
| 10303 expect(mapLiteral.entries, hasLength(1)); |
| 10304 expect(mapLiteral.rightBracket, isNotNull); |
| 8618 } | 10305 } |
| 8619 | 10306 |
| 8620 void test_parseLogicalAndExpression() { | 10307 void test_parseLogicalAndExpression() { |
| 8621 BinaryExpression expression = parse4("parseLogicalAndExpression", "x && y"); | 10308 createParser('x && y'); |
| 8622 expect(expression.leftOperand, isNotNull); | 10309 Expression expression = parser.parseLogicalAndExpression(); |
| 8623 expect(expression.operator, isNotNull); | 10310 expectNotNullIfNoErrors(expression); |
| 8624 expect(expression.operator.type, TokenType.AMPERSAND_AMPERSAND); | 10311 listener.assertNoErrors(); |
| 8625 expect(expression.rightOperand, isNotNull); | 10312 expect(expression, new isInstanceOf<BinaryExpression>()); |
| 10313 BinaryExpression binaryExpression = expression; |
| 10314 expect(binaryExpression.leftOperand, isNotNull); |
| 10315 expect(binaryExpression.operator, isNotNull); |
| 10316 expect(binaryExpression.operator.type, TokenType.AMPERSAND_AMPERSAND); |
| 10317 expect(binaryExpression.rightOperand, isNotNull); |
| 8626 } | 10318 } |
| 8627 | 10319 |
| 8628 void test_parseLogicalOrExpression() { | 10320 void test_parseLogicalOrExpression() { |
| 8629 BinaryExpression expression = parse4("parseLogicalOrExpression", "x || y"); | 10321 createParser('x || y'); |
| 8630 expect(expression.leftOperand, isNotNull); | 10322 Expression expression = parser.parseLogicalOrExpression(); |
| 8631 expect(expression.operator, isNotNull); | 10323 expectNotNullIfNoErrors(expression); |
| 8632 expect(expression.operator.type, TokenType.BAR_BAR); | 10324 listener.assertNoErrors(); |
| 8633 expect(expression.rightOperand, isNotNull); | 10325 expect(expression, new isInstanceOf<BinaryExpression>()); |
| 10326 BinaryExpression binaryExpression = expression; |
| 10327 expect(binaryExpression.leftOperand, isNotNull); |
| 10328 expect(binaryExpression.operator, isNotNull); |
| 10329 expect(binaryExpression.operator.type, TokenType.BAR_BAR); |
| 10330 expect(binaryExpression.rightOperand, isNotNull); |
| 8634 } | 10331 } |
| 8635 | 10332 |
| 8636 void test_parseMapLiteral_empty() { | 10333 void test_parseMapLiteral_empty() { |
| 8637 Token token = TokenFactory.tokenFromKeyword(Keyword.CONST); | 10334 Token token = TokenFactory.tokenFromKeyword(Keyword.CONST); |
| 8638 TypeArgumentList typeArguments = AstFactory.typeArgumentList( | 10335 TypeArgumentList typeArguments = AstFactory.typeArgumentList( |
| 8639 [AstFactory.typeName4("String"), AstFactory.typeName4("int")]); | 10336 [AstFactory.typeName4("String"), AstFactory.typeName4("int")]); |
| 8640 MapLiteral literal = | 10337 createParser('{}'); |
| 8641 parse("parseMapLiteral", <Object>[token, typeArguments], "{}"); | 10338 MapLiteral literal = parser.parseMapLiteral(token, typeArguments); |
| 10339 expectNotNullIfNoErrors(literal); |
| 10340 listener.assertNoErrors(); |
| 8642 expect(literal.constKeyword, token); | 10341 expect(literal.constKeyword, token); |
| 8643 expect(literal.typeArguments, typeArguments); | 10342 expect(literal.typeArguments, typeArguments); |
| 8644 expect(literal.leftBracket, isNotNull); | 10343 expect(literal.leftBracket, isNotNull); |
| 8645 expect(literal.entries, hasLength(0)); | 10344 expect(literal.entries, hasLength(0)); |
| 8646 expect(literal.rightBracket, isNotNull); | 10345 expect(literal.rightBracket, isNotNull); |
| 8647 } | 10346 } |
| 8648 | 10347 |
| 8649 void test_parseMapLiteral_multiple() { | 10348 void test_parseMapLiteral_multiple() { |
| 8650 MapLiteral literal = | 10349 createParser("{'a' : b, 'x' : y}"); |
| 8651 parse("parseMapLiteral", <Object>[null, null], "{'a' : b, 'x' : y}"); | 10350 MapLiteral literal = parser.parseMapLiteral(null, null); |
| 10351 expectNotNullIfNoErrors(literal); |
| 10352 listener.assertNoErrors(); |
| 8652 expect(literal.leftBracket, isNotNull); | 10353 expect(literal.leftBracket, isNotNull); |
| 8653 expect(literal.entries, hasLength(2)); | 10354 expect(literal.entries, hasLength(2)); |
| 8654 expect(literal.rightBracket, isNotNull); | 10355 expect(literal.rightBracket, isNotNull); |
| 8655 } | 10356 } |
| 8656 | 10357 |
| 8657 void test_parseMapLiteral_single() { | 10358 void test_parseMapLiteral_single() { |
| 8658 MapLiteral literal = | 10359 createParser("{'x' : y}"); |
| 8659 parse("parseMapLiteral", <Object>[null, null], "{'x' : y}"); | 10360 MapLiteral literal = parser.parseMapLiteral(null, null); |
| 10361 expectNotNullIfNoErrors(literal); |
| 10362 listener.assertNoErrors(); |
| 8660 expect(literal.leftBracket, isNotNull); | 10363 expect(literal.leftBracket, isNotNull); |
| 8661 expect(literal.entries, hasLength(1)); | 10364 expect(literal.entries, hasLength(1)); |
| 8662 expect(literal.rightBracket, isNotNull); | 10365 expect(literal.rightBracket, isNotNull); |
| 8663 } | 10366 } |
| 8664 | 10367 |
| 8665 void test_parseMapLiteralEntry_complex() { | 10368 void test_parseMapLiteralEntry_complex() { |
| 8666 MapLiteralEntry entry = parse4("parseMapLiteralEntry", "2 + 2 : y"); | 10369 createParser('2 + 2 : y'); |
| 10370 MapLiteralEntry entry = parser.parseMapLiteralEntry(); |
| 10371 expectNotNullIfNoErrors(entry); |
| 10372 listener.assertNoErrors(); |
| 8667 expect(entry.key, isNotNull); | 10373 expect(entry.key, isNotNull); |
| 8668 expect(entry.separator, isNotNull); | 10374 expect(entry.separator, isNotNull); |
| 8669 expect(entry.value, isNotNull); | 10375 expect(entry.value, isNotNull); |
| 8670 } | 10376 } |
| 8671 | 10377 |
| 8672 void test_parseMapLiteralEntry_int() { | 10378 void test_parseMapLiteralEntry_int() { |
| 8673 MapLiteralEntry entry = parse4("parseMapLiteralEntry", "0 : y"); | 10379 createParser('0 : y'); |
| 10380 MapLiteralEntry entry = parser.parseMapLiteralEntry(); |
| 10381 expectNotNullIfNoErrors(entry); |
| 10382 listener.assertNoErrors(); |
| 8674 expect(entry.key, isNotNull); | 10383 expect(entry.key, isNotNull); |
| 8675 expect(entry.separator, isNotNull); | 10384 expect(entry.separator, isNotNull); |
| 8676 expect(entry.value, isNotNull); | 10385 expect(entry.value, isNotNull); |
| 8677 } | 10386 } |
| 8678 | 10387 |
| 8679 void test_parseMapLiteralEntry_string() { | 10388 void test_parseMapLiteralEntry_string() { |
| 8680 MapLiteralEntry entry = parse4("parseMapLiteralEntry", "'x' : y"); | 10389 createParser("'x' : y"); |
| 10390 MapLiteralEntry entry = parser.parseMapLiteralEntry(); |
| 10391 expectNotNullIfNoErrors(entry); |
| 10392 listener.assertNoErrors(); |
| 8681 expect(entry.key, isNotNull); | 10393 expect(entry.key, isNotNull); |
| 8682 expect(entry.separator, isNotNull); | 10394 expect(entry.separator, isNotNull); |
| 8683 expect(entry.value, isNotNull); | 10395 expect(entry.value, isNotNull); |
| 8684 } | 10396 } |
| 8685 | 10397 |
| 8686 void test_parseModifiers_abstract() { | 10398 void test_parseModifiers_abstract() { |
| 8687 Modifiers modifiers = parse4("parseModifiers", "abstract A"); | 10399 createParser('abstract A'); |
| 10400 Modifiers modifiers = parser.parseModifiers(); |
| 10401 expectNotNullIfNoErrors(modifiers); |
| 10402 listener.assertNoErrors(); |
| 8688 expect(modifiers.abstractKeyword, isNotNull); | 10403 expect(modifiers.abstractKeyword, isNotNull); |
| 8689 } | 10404 } |
| 8690 | 10405 |
| 8691 void test_parseModifiers_const() { | 10406 void test_parseModifiers_const() { |
| 8692 Modifiers modifiers = parse4("parseModifiers", "const A"); | 10407 createParser('const A'); |
| 10408 Modifiers modifiers = parser.parseModifiers(); |
| 10409 expectNotNullIfNoErrors(modifiers); |
| 10410 listener.assertNoErrors(); |
| 8693 expect(modifiers.constKeyword, isNotNull); | 10411 expect(modifiers.constKeyword, isNotNull); |
| 8694 } | 10412 } |
| 8695 | 10413 |
| 8696 void test_parseModifiers_external() { | 10414 void test_parseModifiers_external() { |
| 8697 Modifiers modifiers = parse4("parseModifiers", "external A"); | 10415 createParser('external A'); |
| 10416 Modifiers modifiers = parser.parseModifiers(); |
| 10417 expectNotNullIfNoErrors(modifiers); |
| 10418 listener.assertNoErrors(); |
| 8698 expect(modifiers.externalKeyword, isNotNull); | 10419 expect(modifiers.externalKeyword, isNotNull); |
| 8699 } | 10420 } |
| 8700 | 10421 |
| 8701 void test_parseModifiers_factory() { | 10422 void test_parseModifiers_factory() { |
| 8702 Modifiers modifiers = parse4("parseModifiers", "factory A"); | 10423 createParser('factory A'); |
| 10424 Modifiers modifiers = parser.parseModifiers(); |
| 10425 expectNotNullIfNoErrors(modifiers); |
| 10426 listener.assertNoErrors(); |
| 8703 expect(modifiers.factoryKeyword, isNotNull); | 10427 expect(modifiers.factoryKeyword, isNotNull); |
| 8704 } | 10428 } |
| 8705 | 10429 |
| 8706 void test_parseModifiers_final() { | 10430 void test_parseModifiers_final() { |
| 8707 Modifiers modifiers = parse4("parseModifiers", "final A"); | 10431 createParser('final A'); |
| 10432 Modifiers modifiers = parser.parseModifiers(); |
| 10433 expectNotNullIfNoErrors(modifiers); |
| 10434 listener.assertNoErrors(); |
| 8708 expect(modifiers.finalKeyword, isNotNull); | 10435 expect(modifiers.finalKeyword, isNotNull); |
| 8709 } | 10436 } |
| 8710 | 10437 |
| 8711 void test_parseModifiers_static() { | 10438 void test_parseModifiers_static() { |
| 8712 Modifiers modifiers = parse4("parseModifiers", "static A"); | 10439 createParser('static A'); |
| 10440 Modifiers modifiers = parser.parseModifiers(); |
| 10441 expectNotNullIfNoErrors(modifiers); |
| 10442 listener.assertNoErrors(); |
| 8713 expect(modifiers.staticKeyword, isNotNull); | 10443 expect(modifiers.staticKeyword, isNotNull); |
| 8714 } | 10444 } |
| 8715 | 10445 |
| 8716 void test_parseModifiers_var() { | 10446 void test_parseModifiers_var() { |
| 8717 Modifiers modifiers = parse4("parseModifiers", "var A"); | 10447 createParser('var A'); |
| 10448 Modifiers modifiers = parser.parseModifiers(); |
| 10449 expectNotNullIfNoErrors(modifiers); |
| 10450 listener.assertNoErrors(); |
| 8718 expect(modifiers.varKeyword, isNotNull); | 10451 expect(modifiers.varKeyword, isNotNull); |
| 8719 } | 10452 } |
| 8720 | 10453 |
| 8721 void test_parseMultiplicativeExpression_normal() { | 10454 void test_parseMultiplicativeExpression_normal() { |
| 8722 BinaryExpression expression = | 10455 createParser('x * y'); |
| 8723 parse4("parseMultiplicativeExpression", "x * y"); | 10456 Expression expression = parser.parseMultiplicativeExpression(); |
| 8724 expect(expression.leftOperand, isNotNull); | 10457 expectNotNullIfNoErrors(expression); |
| 8725 expect(expression.operator, isNotNull); | 10458 listener.assertNoErrors(); |
| 8726 expect(expression.operator.type, TokenType.STAR); | 10459 expect(expression, new isInstanceOf<BinaryExpression>()); |
| 8727 expect(expression.rightOperand, isNotNull); | 10460 BinaryExpression binaryExpression = expression; |
| 10461 expect(binaryExpression.leftOperand, isNotNull); |
| 10462 expect(binaryExpression.operator, isNotNull); |
| 10463 expect(binaryExpression.operator.type, TokenType.STAR); |
| 10464 expect(binaryExpression.rightOperand, isNotNull); |
| 8728 } | 10465 } |
| 8729 | 10466 |
| 8730 void test_parseMultiplicativeExpression_super() { | 10467 void test_parseMultiplicativeExpression_super() { |
| 8731 BinaryExpression expression = | 10468 createParser('super * y'); |
| 8732 parse4("parseMultiplicativeExpression", "super * y"); | 10469 Expression expression = parser.parseMultiplicativeExpression(); |
| 8733 EngineTestCase.assertInstanceOf((obj) => obj is SuperExpression, | 10470 expectNotNullIfNoErrors(expression); |
| 8734 SuperExpression, expression.leftOperand); | 10471 listener.assertNoErrors(); |
| 8735 expect(expression.operator, isNotNull); | 10472 expect(expression, new isInstanceOf<BinaryExpression>()); |
| 8736 expect(expression.operator.type, TokenType.STAR); | 10473 BinaryExpression binaryExpression = expression; |
| 8737 expect(expression.rightOperand, isNotNull); | 10474 expect(binaryExpression.leftOperand, new isInstanceOf<SuperExpression>()); |
| 10475 expect(binaryExpression.operator, isNotNull); |
| 10476 expect(binaryExpression.operator.type, TokenType.STAR); |
| 10477 expect(binaryExpression.rightOperand, isNotNull); |
| 8738 } | 10478 } |
| 8739 | 10479 |
| 8740 void test_parseNewExpression() { | 10480 void test_parseNewExpression() { |
| 8741 InstanceCreationExpression expression = | 10481 createParser('new A()'); |
| 8742 parse4("parseNewExpression", "new A()"); | 10482 InstanceCreationExpression expression = parser.parseNewExpression(); |
| 10483 expectNotNullIfNoErrors(expression); |
| 10484 listener.assertNoErrors(); |
| 8743 expect(expression.keyword, isNotNull); | 10485 expect(expression.keyword, isNotNull); |
| 8744 ConstructorName name = expression.constructorName; | 10486 ConstructorName name = expression.constructorName; |
| 8745 expect(name, isNotNull); | 10487 expect(name, isNotNull); |
| 8746 expect(name.type, isNotNull); | 10488 expect(name.type, isNotNull); |
| 8747 expect(name.period, isNull); | 10489 expect(name.period, isNull); |
| 8748 expect(name.name, isNull); | 10490 expect(name.name, isNull); |
| 8749 expect(expression.argumentList, isNotNull); | 10491 expect(expression.argumentList, isNotNull); |
| 8750 } | 10492 } |
| 8751 | 10493 |
| 8752 void test_parseNonLabeledStatement_const_list_empty() { | 10494 void test_parseNonLabeledStatement_const_list_empty() { |
| 8753 ExpressionStatement statement = | 10495 createParser('const [];'); |
| 8754 parse4("parseNonLabeledStatement", "const [];"); | 10496 Statement statement = parser.parseNonLabeledStatement(); |
| 8755 expect(statement.expression, isNotNull); | 10497 expectNotNullIfNoErrors(statement); |
| 10498 listener.assertNoErrors(); |
| 10499 expect(statement, new isInstanceOf<ExpressionStatement>()); |
| 10500 ExpressionStatement expressionStatement = statement; |
| 10501 expect(expressionStatement.expression, isNotNull); |
| 8756 } | 10502 } |
| 8757 | 10503 |
| 8758 void test_parseNonLabeledStatement_const_list_nonEmpty() { | 10504 void test_parseNonLabeledStatement_const_list_nonEmpty() { |
| 8759 ExpressionStatement statement = | 10505 createParser('const [1, 2];'); |
| 8760 parse4("parseNonLabeledStatement", "const [1, 2];"); | 10506 Statement statement = parser.parseNonLabeledStatement(); |
| 8761 expect(statement.expression, isNotNull); | 10507 expectNotNullIfNoErrors(statement); |
| 10508 listener.assertNoErrors(); |
| 10509 expect(statement, new isInstanceOf<ExpressionStatement>()); |
| 10510 ExpressionStatement expressionStatement = statement; |
| 10511 expect(expressionStatement.expression, isNotNull); |
| 8762 } | 10512 } |
| 8763 | 10513 |
| 8764 void test_parseNonLabeledStatement_const_map_empty() { | 10514 void test_parseNonLabeledStatement_const_map_empty() { |
| 8765 ExpressionStatement statement = | 10515 createParser('const {};'); |
| 8766 parse4("parseNonLabeledStatement", "const {};"); | 10516 Statement statement = parser.parseNonLabeledStatement(); |
| 8767 expect(statement.expression, isNotNull); | 10517 expectNotNullIfNoErrors(statement); |
| 10518 listener.assertNoErrors(); |
| 10519 expect(statement, new isInstanceOf<ExpressionStatement>()); |
| 10520 ExpressionStatement expressionStatement = statement; |
| 10521 expect(expressionStatement.expression, isNotNull); |
| 8768 } | 10522 } |
| 8769 | 10523 |
| 8770 void test_parseNonLabeledStatement_const_map_nonEmpty() { | 10524 void test_parseNonLabeledStatement_const_map_nonEmpty() { |
| 8771 // TODO(brianwilkerson) Implement more tests for this method. | 10525 // TODO(brianwilkerson) Implement more tests for this method. |
| 8772 ExpressionStatement statement = | 10526 createParser("const {'a' : 1};"); |
| 8773 parse4("parseNonLabeledStatement", "const {'a' : 1};"); | 10527 Statement statement = parser.parseNonLabeledStatement(); |
| 8774 expect(statement.expression, isNotNull); | 10528 expectNotNullIfNoErrors(statement); |
| 10529 listener.assertNoErrors(); |
| 10530 expect(statement, new isInstanceOf<ExpressionStatement>()); |
| 10531 ExpressionStatement expressionStatement = statement; |
| 10532 expect(expressionStatement.expression, isNotNull); |
| 8775 } | 10533 } |
| 8776 | 10534 |
| 8777 void test_parseNonLabeledStatement_const_object() { | 10535 void test_parseNonLabeledStatement_const_object() { |
| 8778 ExpressionStatement statement = | 10536 createParser('const A();'); |
| 8779 parse4("parseNonLabeledStatement", "const A();"); | 10537 Statement statement = parser.parseNonLabeledStatement(); |
| 8780 expect(statement.expression, isNotNull); | 10538 expectNotNullIfNoErrors(statement); |
| 10539 listener.assertNoErrors(); |
| 10540 expect(statement, new isInstanceOf<ExpressionStatement>()); |
| 10541 ExpressionStatement expressionStatement = statement; |
| 10542 expect(expressionStatement.expression, isNotNull); |
| 8781 } | 10543 } |
| 8782 | 10544 |
| 8783 void test_parseNonLabeledStatement_const_object_named_typeParameters() { | 10545 void test_parseNonLabeledStatement_const_object_named_typeParameters() { |
| 8784 ExpressionStatement statement = | 10546 createParser('const A<B>.c();'); |
| 8785 parse4("parseNonLabeledStatement", "const A<B>.c();"); | 10547 Statement statement = parser.parseNonLabeledStatement(); |
| 8786 expect(statement.expression, isNotNull); | 10548 expectNotNullIfNoErrors(statement); |
| 10549 listener.assertNoErrors(); |
| 10550 expect(statement, new isInstanceOf<ExpressionStatement>()); |
| 10551 ExpressionStatement expressionStatement = statement; |
| 10552 expect(expressionStatement.expression, isNotNull); |
| 8787 } | 10553 } |
| 8788 | 10554 |
| 8789 void test_parseNonLabeledStatement_constructorInvocation() { | 10555 void test_parseNonLabeledStatement_constructorInvocation() { |
| 8790 ExpressionStatement statement = | 10556 createParser('new C().m();'); |
| 8791 parse4("parseNonLabeledStatement", "new C().m();"); | 10557 Statement statement = parser.parseNonLabeledStatement(); |
| 8792 expect(statement.expression, isNotNull); | 10558 expectNotNullIfNoErrors(statement); |
| 10559 listener.assertNoErrors(); |
| 10560 expect(statement, new isInstanceOf<ExpressionStatement>()); |
| 10561 ExpressionStatement expressionStatement = statement; |
| 10562 expect(expressionStatement.expression, isNotNull); |
| 8793 } | 10563 } |
| 8794 | 10564 |
| 8795 void test_parseNonLabeledStatement_false() { | 10565 void test_parseNonLabeledStatement_false() { |
| 8796 ExpressionStatement statement = | 10566 createParser('false;'); |
| 8797 parse4("parseNonLabeledStatement", "false;"); | 10567 Statement statement = parser.parseNonLabeledStatement(); |
| 8798 expect(statement.expression, isNotNull); | 10568 expectNotNullIfNoErrors(statement); |
| 10569 listener.assertNoErrors(); |
| 10570 expect(statement, new isInstanceOf<ExpressionStatement>()); |
| 10571 ExpressionStatement expressionStatement = statement; |
| 10572 expect(expressionStatement.expression, isNotNull); |
| 8799 } | 10573 } |
| 8800 | 10574 |
| 8801 void test_parseNonLabeledStatement_functionDeclaration() { | 10575 void test_parseNonLabeledStatement_functionDeclaration() { |
| 8802 parse4("parseNonLabeledStatement", "f() {};"); | 10576 createParser('f() {};'); |
| 10577 Statement statement = parser.parseNonLabeledStatement(); |
| 10578 expectNotNullIfNoErrors(statement); |
| 10579 listener.assertNoErrors(); |
| 8803 } | 10580 } |
| 8804 | 10581 |
| 8805 void test_parseNonLabeledStatement_functionDeclaration_arguments() { | 10582 void test_parseNonLabeledStatement_functionDeclaration_arguments() { |
| 8806 parse4("parseNonLabeledStatement", "f(void g()) {};"); | 10583 createParser('f(void g()) {};'); |
| 10584 Statement statement = parser.parseNonLabeledStatement(); |
| 10585 expectNotNullIfNoErrors(statement); |
| 10586 listener.assertNoErrors(); |
| 8807 } | 10587 } |
| 8808 | 10588 |
| 8809 void test_parseNonLabeledStatement_functionExpressionIndex() { | 10589 void test_parseNonLabeledStatement_functionExpressionIndex() { |
| 8810 parse4("parseNonLabeledStatement", "() {}[0] = null;"); | 10590 createParser('() {}[0] = null;'); |
| 10591 Statement statement = parser.parseNonLabeledStatement(); |
| 10592 expectNotNullIfNoErrors(statement); |
| 10593 listener.assertNoErrors(); |
| 8811 } | 10594 } |
| 8812 | 10595 |
| 8813 void test_parseNonLabeledStatement_functionInvocation() { | 10596 void test_parseNonLabeledStatement_functionInvocation() { |
| 8814 ExpressionStatement statement = parse4("parseNonLabeledStatement", "f();"); | 10597 createParser('f();'); |
| 8815 expect(statement.expression, isNotNull); | 10598 Statement statement = parser.parseNonLabeledStatement(); |
| 10599 expectNotNullIfNoErrors(statement); |
| 10600 listener.assertNoErrors(); |
| 10601 expect(statement, new isInstanceOf<ExpressionStatement>()); |
| 10602 ExpressionStatement expressionStatement = statement; |
| 10603 expect(expressionStatement.expression, isNotNull); |
| 8816 } | 10604 } |
| 8817 | 10605 |
| 8818 void test_parseNonLabeledStatement_invokeFunctionExpression() { | 10606 void test_parseNonLabeledStatement_invokeFunctionExpression() { |
| 8819 ExpressionStatement statement = | 10607 createParser('(a) {return a + a;} (3);'); |
| 8820 parse4("parseNonLabeledStatement", "(a) {return a + a;} (3);"); | 10608 Statement statement = parser.parseNonLabeledStatement(); |
| 10609 expectNotNullIfNoErrors(statement); |
| 10610 listener.assertNoErrors(); |
| 10611 expect(statement, new isInstanceOf<ExpressionStatement>()); |
| 10612 ExpressionStatement expressionStatement = statement; |
| 8821 EngineTestCase.assertInstanceOf( | 10613 EngineTestCase.assertInstanceOf( |
| 8822 (obj) => obj is FunctionExpressionInvocation, | 10614 (obj) => obj is FunctionExpressionInvocation, |
| 8823 FunctionExpressionInvocation, | 10615 FunctionExpressionInvocation, |
| 8824 statement.expression); | 10616 expressionStatement.expression); |
| 8825 FunctionExpressionInvocation invocation = | 10617 FunctionExpressionInvocation invocation = |
| 8826 statement.expression as FunctionExpressionInvocation; | 10618 expressionStatement.expression as FunctionExpressionInvocation; |
| 8827 EngineTestCase.assertInstanceOf((obj) => obj is FunctionExpression, | 10619 EngineTestCase.assertInstanceOf((obj) => obj is FunctionExpression, |
| 8828 FunctionExpression, invocation.function); | 10620 FunctionExpression, invocation.function); |
| 8829 FunctionExpression expression = invocation.function as FunctionExpression; | 10621 FunctionExpression expression = invocation.function as FunctionExpression; |
| 8830 expect(expression.parameters, isNotNull); | 10622 expect(expression.parameters, isNotNull); |
| 8831 expect(expression.body, isNotNull); | 10623 expect(expression.body, isNotNull); |
| 8832 expect(invocation.typeArguments, isNull); | 10624 expect(invocation.typeArguments, isNull); |
| 8833 ArgumentList list = invocation.argumentList; | 10625 ArgumentList list = invocation.argumentList; |
| 8834 expect(list, isNotNull); | 10626 expect(list, isNotNull); |
| 8835 expect(list.arguments, hasLength(1)); | 10627 expect(list.arguments, hasLength(1)); |
| 8836 } | 10628 } |
| 8837 | 10629 |
| 8838 void test_parseNonLabeledStatement_null() { | 10630 void test_parseNonLabeledStatement_null() { |
| 8839 ExpressionStatement statement = parse4("parseNonLabeledStatement", "null;"); | 10631 createParser('null;'); |
| 8840 expect(statement.expression, isNotNull); | 10632 Statement statement = parser.parseNonLabeledStatement(); |
| 10633 expectNotNullIfNoErrors(statement); |
| 10634 listener.assertNoErrors(); |
| 10635 expect(statement, new isInstanceOf<ExpressionStatement>()); |
| 10636 ExpressionStatement expressionStatement = statement; |
| 10637 expect(expressionStatement.expression, isNotNull); |
| 8841 } | 10638 } |
| 8842 | 10639 |
| 8843 void test_parseNonLabeledStatement_startingWithBuiltInIdentifier() { | 10640 void test_parseNonLabeledStatement_startingWithBuiltInIdentifier() { |
| 8844 ExpressionStatement statement = | 10641 createParser('library.getName();'); |
| 8845 parse4("parseNonLabeledStatement", "library.getName();"); | 10642 Statement statement = parser.parseNonLabeledStatement(); |
| 8846 expect(statement.expression, isNotNull); | 10643 expectNotNullIfNoErrors(statement); |
| 10644 listener.assertNoErrors(); |
| 10645 expect(statement, new isInstanceOf<ExpressionStatement>()); |
| 10646 ExpressionStatement expressionStatement = statement; |
| 10647 expect(expressionStatement.expression, isNotNull); |
| 8847 } | 10648 } |
| 8848 | 10649 |
| 8849 void test_parseNonLabeledStatement_true() { | 10650 void test_parseNonLabeledStatement_true() { |
| 8850 ExpressionStatement statement = parse4("parseNonLabeledStatement", "true;"); | 10651 createParser('true;'); |
| 8851 expect(statement.expression, isNotNull); | 10652 Statement statement = parser.parseNonLabeledStatement(); |
| 10653 expectNotNullIfNoErrors(statement); |
| 10654 listener.assertNoErrors(); |
| 10655 expect(statement, new isInstanceOf<ExpressionStatement>()); |
| 10656 ExpressionStatement expressionStatement = statement; |
| 10657 expect(expressionStatement.expression, isNotNull); |
| 8852 } | 10658 } |
| 8853 | 10659 |
| 8854 void test_parseNonLabeledStatement_typeCast() { | 10660 void test_parseNonLabeledStatement_typeCast() { |
| 8855 ExpressionStatement statement = | 10661 createParser('double.NAN as num;'); |
| 8856 parse4("parseNonLabeledStatement", "double.NAN as num;"); | 10662 Statement statement = parser.parseNonLabeledStatement(); |
| 8857 expect(statement.expression, isNotNull); | 10663 expectNotNullIfNoErrors(statement); |
| 10664 listener.assertNoErrors(); |
| 10665 expect(statement, new isInstanceOf<ExpressionStatement>()); |
| 10666 ExpressionStatement expressionStatement = statement; |
| 10667 expect(expressionStatement.expression, isNotNull); |
| 8858 } | 10668 } |
| 8859 | 10669 |
| 8860 void test_parseNormalFormalParameter_field_const_noType() { | 10670 void test_parseNormalFormalParameter_field_const_noType() { |
| 8861 FieldFormalParameter parameter = | 10671 createParser('const this.a)'); |
| 8862 parse4("parseNormalFormalParameter", "const this.a)"); | 10672 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); |
| 8863 expect(parameter.keyword, isNotNull); | 10673 expectNotNullIfNoErrors(parameter); |
| 8864 expect(parameter.type, isNull); | 10674 listener.assertNoErrors(); |
| 8865 expect(parameter.identifier, isNotNull); | 10675 expect(parameter, new isInstanceOf<FieldFormalParameter>()); |
| 8866 expect(parameter.parameters, isNull); | 10676 FieldFormalParameter fieldParameter = parameter; |
| 10677 expect(fieldParameter.keyword, isNotNull); |
| 10678 expect(fieldParameter.type, isNull); |
| 10679 expect(fieldParameter.identifier, isNotNull); |
| 10680 expect(fieldParameter.parameters, isNull); |
| 8867 } | 10681 } |
| 8868 | 10682 |
| 8869 void test_parseNormalFormalParameter_field_const_type() { | 10683 void test_parseNormalFormalParameter_field_const_type() { |
| 8870 FieldFormalParameter parameter = | 10684 createParser('const A this.a)'); |
| 8871 parse4("parseNormalFormalParameter", "const A this.a)"); | 10685 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); |
| 8872 expect(parameter.keyword, isNotNull); | 10686 expectNotNullIfNoErrors(parameter); |
| 8873 expect(parameter.type, isNotNull); | 10687 listener.assertNoErrors(); |
| 8874 expect(parameter.identifier, isNotNull); | 10688 expect(parameter, new isInstanceOf<FieldFormalParameter>()); |
| 8875 expect(parameter.parameters, isNull); | 10689 FieldFormalParameter fieldParameter = parameter; |
| 10690 expect(fieldParameter.keyword, isNotNull); |
| 10691 expect(fieldParameter.type, isNotNull); |
| 10692 expect(fieldParameter.identifier, isNotNull); |
| 10693 expect(fieldParameter.parameters, isNull); |
| 8876 } | 10694 } |
| 8877 | 10695 |
| 8878 void test_parseNormalFormalParameter_field_final_noType() { | 10696 void test_parseNormalFormalParameter_field_final_noType() { |
| 8879 FieldFormalParameter parameter = | 10697 createParser('final this.a)'); |
| 8880 parse4("parseNormalFormalParameter", "final this.a)"); | 10698 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); |
| 8881 expect(parameter.keyword, isNotNull); | 10699 expectNotNullIfNoErrors(parameter); |
| 8882 expect(parameter.type, isNull); | 10700 listener.assertNoErrors(); |
| 8883 expect(parameter.identifier, isNotNull); | 10701 expect(parameter, new isInstanceOf<FieldFormalParameter>()); |
| 8884 expect(parameter.parameters, isNull); | 10702 FieldFormalParameter fieldParameter = parameter; |
| 10703 expect(fieldParameter.keyword, isNotNull); |
| 10704 expect(fieldParameter.type, isNull); |
| 10705 expect(fieldParameter.identifier, isNotNull); |
| 10706 expect(fieldParameter.parameters, isNull); |
| 8885 } | 10707 } |
| 8886 | 10708 |
| 8887 void test_parseNormalFormalParameter_field_final_type() { | 10709 void test_parseNormalFormalParameter_field_final_type() { |
| 8888 FieldFormalParameter parameter = | 10710 createParser('final A this.a)'); |
| 8889 parse4("parseNormalFormalParameter", "final A this.a)"); | 10711 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); |
| 8890 expect(parameter.keyword, isNotNull); | 10712 expectNotNullIfNoErrors(parameter); |
| 8891 expect(parameter.type, isNotNull); | 10713 listener.assertNoErrors(); |
| 8892 expect(parameter.identifier, isNotNull); | 10714 expect(parameter, new isInstanceOf<FieldFormalParameter>()); |
| 8893 expect(parameter.parameters, isNull); | 10715 FieldFormalParameter fieldParameter = parameter; |
| 10716 expect(fieldParameter.keyword, isNotNull); |
| 10717 expect(fieldParameter.type, isNotNull); |
| 10718 expect(fieldParameter.identifier, isNotNull); |
| 10719 expect(fieldParameter.parameters, isNull); |
| 8894 } | 10720 } |
| 8895 | 10721 |
| 8896 void test_parseNormalFormalParameter_field_function_nested() { | 10722 void test_parseNormalFormalParameter_field_function_nested() { |
| 8897 FieldFormalParameter parameter = | 10723 createParser('this.a(B b))'); |
| 8898 parse4("parseNormalFormalParameter", "this.a(B b))"); | 10724 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); |
| 8899 expect(parameter.keyword, isNull); | 10725 expectNotNullIfNoErrors(parameter); |
| 8900 expect(parameter.type, isNull); | 10726 listener.assertNoErrors(); |
| 8901 expect(parameter.identifier, isNotNull); | 10727 expect(parameter, new isInstanceOf<FieldFormalParameter>()); |
| 8902 FormalParameterList parameterList = parameter.parameters; | 10728 FieldFormalParameter fieldParameter = parameter; |
| 10729 expect(fieldParameter.keyword, isNull); |
| 10730 expect(fieldParameter.type, isNull); |
| 10731 expect(fieldParameter.identifier, isNotNull); |
| 10732 FormalParameterList parameterList = fieldParameter.parameters; |
| 8903 expect(parameterList, isNotNull); | 10733 expect(parameterList, isNotNull); |
| 8904 expect(parameterList.parameters, hasLength(1)); | 10734 expect(parameterList.parameters, hasLength(1)); |
| 8905 } | 10735 } |
| 8906 | 10736 |
| 8907 void test_parseNormalFormalParameter_field_function_noNested() { | 10737 void test_parseNormalFormalParameter_field_function_noNested() { |
| 8908 FieldFormalParameter parameter = | 10738 createParser('this.a())'); |
| 8909 parse4("parseNormalFormalParameter", "this.a())"); | 10739 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); |
| 8910 expect(parameter.keyword, isNull); | 10740 expectNotNullIfNoErrors(parameter); |
| 8911 expect(parameter.type, isNull); | 10741 listener.assertNoErrors(); |
| 8912 expect(parameter.identifier, isNotNull); | 10742 expect(parameter, new isInstanceOf<FieldFormalParameter>()); |
| 8913 FormalParameterList parameterList = parameter.parameters; | 10743 FieldFormalParameter fieldParameter = parameter; |
| 10744 expect(fieldParameter.keyword, isNull); |
| 10745 expect(fieldParameter.type, isNull); |
| 10746 expect(fieldParameter.identifier, isNotNull); |
| 10747 FormalParameterList parameterList = fieldParameter.parameters; |
| 8914 expect(parameterList, isNotNull); | 10748 expect(parameterList, isNotNull); |
| 8915 expect(parameterList.parameters, hasLength(0)); | 10749 expect(parameterList.parameters, hasLength(0)); |
| 8916 } | 10750 } |
| 8917 | 10751 |
| 8918 void test_parseNormalFormalParameter_field_noType() { | 10752 void test_parseNormalFormalParameter_field_noType() { |
| 8919 FieldFormalParameter parameter = | 10753 createParser('this.a)'); |
| 8920 parse4("parseNormalFormalParameter", "this.a)"); | 10754 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); |
| 8921 expect(parameter.keyword, isNull); | 10755 expectNotNullIfNoErrors(parameter); |
| 8922 expect(parameter.type, isNull); | 10756 listener.assertNoErrors(); |
| 8923 expect(parameter.identifier, isNotNull); | 10757 expect(parameter, new isInstanceOf<FieldFormalParameter>()); |
| 8924 expect(parameter.parameters, isNull); | 10758 FieldFormalParameter fieldParameter = parameter; |
| 10759 expect(fieldParameter.keyword, isNull); |
| 10760 expect(fieldParameter.type, isNull); |
| 10761 expect(fieldParameter.identifier, isNotNull); |
| 10762 expect(fieldParameter.parameters, isNull); |
| 8925 } | 10763 } |
| 8926 | 10764 |
| 8927 void test_parseNormalFormalParameter_field_type() { | 10765 void test_parseNormalFormalParameter_field_type() { |
| 8928 FieldFormalParameter parameter = | 10766 createParser('A this.a)'); |
| 8929 parse4("parseNormalFormalParameter", "A this.a)"); | 10767 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); |
| 8930 expect(parameter.keyword, isNull); | 10768 expectNotNullIfNoErrors(parameter); |
| 8931 expect(parameter.type, isNotNull); | 10769 listener.assertNoErrors(); |
| 8932 expect(parameter.identifier, isNotNull); | 10770 expect(parameter, new isInstanceOf<FieldFormalParameter>()); |
| 8933 expect(parameter.parameters, isNull); | 10771 FieldFormalParameter fieldParameter = parameter; |
| 10772 expect(fieldParameter.keyword, isNull); |
| 10773 expect(fieldParameter.type, isNotNull); |
| 10774 expect(fieldParameter.identifier, isNotNull); |
| 10775 expect(fieldParameter.parameters, isNull); |
| 8934 } | 10776 } |
| 8935 | 10777 |
| 8936 void test_parseNormalFormalParameter_field_var() { | 10778 void test_parseNormalFormalParameter_field_var() { |
| 8937 FieldFormalParameter parameter = | 10779 createParser('var this.a)'); |
| 8938 parse4("parseNormalFormalParameter", "var this.a)"); | 10780 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); |
| 8939 expect(parameter.keyword, isNotNull); | 10781 expectNotNullIfNoErrors(parameter); |
| 8940 expect(parameter.type, isNull); | 10782 listener.assertNoErrors(); |
| 8941 expect(parameter.identifier, isNotNull); | 10783 expect(parameter, new isInstanceOf<FieldFormalParameter>()); |
| 8942 expect(parameter.parameters, isNull); | 10784 FieldFormalParameter fieldParameter = parameter; |
| 10785 expect(fieldParameter.keyword, isNotNull); |
| 10786 expect(fieldParameter.type, isNull); |
| 10787 expect(fieldParameter.identifier, isNotNull); |
| 10788 expect(fieldParameter.parameters, isNull); |
| 8943 } | 10789 } |
| 8944 | 10790 |
| 8945 void test_parseNormalFormalParameter_function_noType() { | 10791 void test_parseNormalFormalParameter_function_noType() { |
| 8946 FunctionTypedFormalParameter parameter = | 10792 createParser('a())'); |
| 8947 parse4("parseNormalFormalParameter", "a())"); | 10793 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); |
| 8948 expect(parameter.returnType, isNull); | 10794 expectNotNullIfNoErrors(parameter); |
| 8949 expect(parameter.identifier, isNotNull); | 10795 listener.assertNoErrors(); |
| 8950 expect(parameter.typeParameters, isNull); | 10796 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| 8951 expect(parameter.parameters, isNotNull); | 10797 FunctionTypedFormalParameter functionParameter = parameter; |
| 10798 expect(functionParameter.returnType, isNull); |
| 10799 expect(functionParameter.identifier, isNotNull); |
| 10800 expect(functionParameter.typeParameters, isNull); |
| 10801 expect(functionParameter.parameters, isNotNull); |
| 10802 } |
| 10803 |
| 10804 void test_parseNormalFormalParameter_function_noType_nullable() { |
| 10805 enableNnbd = true; |
| 10806 createParser('a()?)'); |
| 10807 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); |
| 10808 expectNotNullIfNoErrors(parameter); |
| 10809 listener.assertNoErrors(); |
| 10810 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| 10811 FunctionTypedFormalParameter functionParameter = parameter; |
| 10812 expect(functionParameter.returnType, isNull); |
| 10813 expect(functionParameter.identifier, isNotNull); |
| 10814 expect(functionParameter.typeParameters, isNull); |
| 10815 expect(functionParameter.parameters, isNotNull); |
| 10816 expect(functionParameter.question, isNotNull); |
| 10817 } |
| 10818 |
| 10819 void test_parseNormalFormalParameter_function_noType_typeParameterComments() { |
| 10820 enableGenericMethodComments = true; |
| 10821 createParser('a/*<E>*/())'); |
| 10822 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); |
| 10823 expectNotNullIfNoErrors(parameter); |
| 10824 listener.assertNoErrors(); |
| 10825 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| 10826 FunctionTypedFormalParameter functionParameter = parameter; |
| 10827 expect(functionParameter.returnType, isNull); |
| 10828 expect(functionParameter.identifier, isNotNull); |
| 10829 expect(functionParameter.typeParameters, isNotNull); |
| 10830 expect(functionParameter.parameters, isNotNull); |
| 8952 } | 10831 } |
| 8953 | 10832 |
| 8954 void test_parseNormalFormalParameter_function_noType_typeParameters() { | 10833 void test_parseNormalFormalParameter_function_noType_typeParameters() { |
| 8955 enableGenericMethods = true; | 10834 enableGenericMethods = true; |
| 8956 FunctionTypedFormalParameter parameter = | 10835 createParser('a<E>())'); |
| 8957 parse4("parseNormalFormalParameter", "a<E>())"); | 10836 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); |
| 8958 expect(parameter.returnType, isNull); | 10837 expectNotNullIfNoErrors(parameter); |
| 8959 expect(parameter.identifier, isNotNull); | 10838 listener.assertNoErrors(); |
| 8960 expect(parameter.typeParameters, isNotNull); | 10839 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| 8961 expect(parameter.parameters, isNotNull); | 10840 FunctionTypedFormalParameter functionParameter = parameter; |
| 10841 expect(functionParameter.returnType, isNull); |
| 10842 expect(functionParameter.identifier, isNotNull); |
| 10843 expect(functionParameter.typeParameters, isNotNull); |
| 10844 expect(functionParameter.parameters, isNotNull); |
| 10845 expect(functionParameter.question, isNull); |
| 10846 expect(functionParameter.question, isNull); |
| 10847 } |
| 10848 |
| 10849 void |
| 10850 test_parseNormalFormalParameter_function_noType_typeParameters_nullable()
{ |
| 10851 enableGenericMethods = true; |
| 10852 enableNnbd = true; |
| 10853 createParser('a<E>()?)'); |
| 10854 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); |
| 10855 expectNotNullIfNoErrors(parameter); |
| 10856 listener.assertNoErrors(); |
| 10857 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| 10858 FunctionTypedFormalParameter functionParameter = parameter; |
| 10859 expect(functionParameter.returnType, isNull); |
| 10860 expect(functionParameter.identifier, isNotNull); |
| 10861 expect(functionParameter.typeParameters, isNotNull); |
| 10862 expect(functionParameter.parameters, isNotNull); |
| 10863 expect(functionParameter.question, isNotNull); |
| 8962 } | 10864 } |
| 8963 | 10865 |
| 8964 void test_parseNormalFormalParameter_function_type() { | 10866 void test_parseNormalFormalParameter_function_type() { |
| 8965 FunctionTypedFormalParameter parameter = | 10867 createParser('A a())'); |
| 8966 parse4("parseNormalFormalParameter", "A a())"); | 10868 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); |
| 8967 expect(parameter.returnType, isNotNull); | 10869 expectNotNullIfNoErrors(parameter); |
| 8968 expect(parameter.identifier, isNotNull); | 10870 listener.assertNoErrors(); |
| 8969 expect(parameter.typeParameters, isNull); | 10871 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| 8970 expect(parameter.parameters, isNotNull); | 10872 FunctionTypedFormalParameter functionParameter = parameter; |
| 10873 expect(functionParameter.returnType, isNotNull); |
| 10874 expect(functionParameter.identifier, isNotNull); |
| 10875 expect(functionParameter.typeParameters, isNull); |
| 10876 expect(functionParameter.parameters, isNotNull); |
| 10877 expect(functionParameter.question, isNull); |
| 10878 } |
| 10879 |
| 10880 void test_parseNormalFormalParameter_function_type_nullable() { |
| 10881 enableNnbd = true; |
| 10882 createParser('A a()?)'); |
| 10883 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); |
| 10884 expectNotNullIfNoErrors(parameter); |
| 10885 listener.assertNoErrors(); |
| 10886 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| 10887 FunctionTypedFormalParameter functionParameter = parameter; |
| 10888 expect(functionParameter.returnType, isNotNull); |
| 10889 expect(functionParameter.identifier, isNotNull); |
| 10890 expect(functionParameter.typeParameters, isNull); |
| 10891 expect(functionParameter.parameters, isNotNull); |
| 10892 expect(functionParameter.question, isNotNull); |
| 10893 } |
| 10894 |
| 10895 void test_parseNormalFormalParameter_function_type_typeParameterComments() { |
| 10896 enableGenericMethodComments = true; |
| 10897 createParser('A a/*<E>*/())'); |
| 10898 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); |
| 10899 expectNotNullIfNoErrors(parameter); |
| 10900 listener.assertNoErrors(); |
| 10901 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| 10902 FunctionTypedFormalParameter functionParameter = parameter; |
| 10903 expect(functionParameter.returnType, isNotNull); |
| 10904 expect(functionParameter.identifier, isNotNull); |
| 10905 expect(functionParameter.typeParameters, isNotNull); |
| 10906 expect(functionParameter.parameters, isNotNull); |
| 10907 expect(functionParameter.question, isNull); |
| 8971 } | 10908 } |
| 8972 | 10909 |
| 8973 void test_parseNormalFormalParameter_function_type_typeParameters() { | 10910 void test_parseNormalFormalParameter_function_type_typeParameters() { |
| 8974 enableGenericMethods = true; | 10911 enableGenericMethods = true; |
| 8975 FunctionTypedFormalParameter parameter = | 10912 createParser('A a<E>())'); |
| 8976 parse4("parseNormalFormalParameter", "A a<E>())"); | 10913 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); |
| 8977 expect(parameter.returnType, isNotNull); | 10914 expectNotNullIfNoErrors(parameter); |
| 8978 expect(parameter.identifier, isNotNull); | 10915 listener.assertNoErrors(); |
| 8979 expect(parameter.typeParameters, isNotNull); | 10916 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| 8980 expect(parameter.parameters, isNotNull); | 10917 FunctionTypedFormalParameter functionParameter = parameter; |
| 10918 expect(functionParameter.returnType, isNotNull); |
| 10919 expect(functionParameter.identifier, isNotNull); |
| 10920 expect(functionParameter.typeParameters, isNotNull); |
| 10921 expect(functionParameter.parameters, isNotNull); |
| 10922 expect(functionParameter.question, isNull); |
| 10923 } |
| 10924 |
| 10925 void test_parseNormalFormalParameter_function_type_typeParameters_nullable() { |
| 10926 enableGenericMethods = true; |
| 10927 enableNnbd = true; |
| 10928 createParser('A a<E>()?)'); |
| 10929 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); |
| 10930 expectNotNullIfNoErrors(parameter); |
| 10931 listener.assertNoErrors(); |
| 10932 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| 10933 FunctionTypedFormalParameter functionParameter = parameter; |
| 10934 expect(functionParameter.returnType, isNotNull); |
| 10935 expect(functionParameter.identifier, isNotNull); |
| 10936 expect(functionParameter.typeParameters, isNotNull); |
| 10937 expect(functionParameter.parameters, isNotNull); |
| 10938 expect(functionParameter.question, isNotNull); |
| 8981 } | 10939 } |
| 8982 | 10940 |
| 8983 void test_parseNormalFormalParameter_function_void() { | 10941 void test_parseNormalFormalParameter_function_void() { |
| 8984 FunctionTypedFormalParameter parameter = | 10942 createParser('void a())'); |
| 8985 parse4("parseNormalFormalParameter", "void a())"); | 10943 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); |
| 8986 expect(parameter.returnType, isNotNull); | 10944 expectNotNullIfNoErrors(parameter); |
| 8987 expect(parameter.identifier, isNotNull); | 10945 listener.assertNoErrors(); |
| 8988 expect(parameter.typeParameters, isNull); | 10946 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| 8989 expect(parameter.parameters, isNotNull); | 10947 FunctionTypedFormalParameter functionParameter = parameter; |
| 10948 expect(functionParameter.returnType, isNotNull); |
| 10949 expect(functionParameter.identifier, isNotNull); |
| 10950 expect(functionParameter.typeParameters, isNull); |
| 10951 expect(functionParameter.parameters, isNotNull); |
| 10952 expect(functionParameter.question, isNull); |
| 10953 } |
| 10954 |
| 10955 void test_parseNormalFormalParameter_function_void_nullable() { |
| 10956 enableNnbd = true; |
| 10957 createParser('void a()?)'); |
| 10958 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); |
| 10959 expectNotNullIfNoErrors(parameter); |
| 10960 listener.assertNoErrors(); |
| 10961 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| 10962 FunctionTypedFormalParameter functionParameter = parameter; |
| 10963 expect(functionParameter.returnType, isNotNull); |
| 10964 expect(functionParameter.identifier, isNotNull); |
| 10965 expect(functionParameter.typeParameters, isNull); |
| 10966 expect(functionParameter.parameters, isNotNull); |
| 10967 expect(functionParameter.question, isNotNull); |
| 10968 } |
| 10969 |
| 10970 void test_parseNormalFormalParameter_function_void_typeParameterComments() { |
| 10971 enableGenericMethodComments = true; |
| 10972 createParser('void a/*<E>*/())'); |
| 10973 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); |
| 10974 expectNotNullIfNoErrors(parameter); |
| 10975 listener.assertNoErrors(); |
| 10976 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| 10977 FunctionTypedFormalParameter functionParameter = parameter; |
| 10978 expect(functionParameter.returnType, isNotNull); |
| 10979 expect(functionParameter.identifier, isNotNull); |
| 10980 expect(functionParameter.typeParameters, isNotNull); |
| 10981 expect(functionParameter.parameters, isNotNull); |
| 10982 expect(functionParameter.question, isNull); |
| 8990 } | 10983 } |
| 8991 | 10984 |
| 8992 void test_parseNormalFormalParameter_function_void_typeParameters() { | 10985 void test_parseNormalFormalParameter_function_void_typeParameters() { |
| 8993 enableGenericMethods = true; | 10986 enableGenericMethods = true; |
| 8994 FunctionTypedFormalParameter parameter = | 10987 createParser('void a<E>())'); |
| 8995 parse4("parseNormalFormalParameter", "void a<E>())"); | 10988 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); |
| 8996 expect(parameter.returnType, isNotNull); | 10989 expectNotNullIfNoErrors(parameter); |
| 8997 expect(parameter.identifier, isNotNull); | 10990 listener.assertNoErrors(); |
| 8998 expect(parameter.typeParameters, isNotNull); | 10991 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| 8999 expect(parameter.parameters, isNotNull); | 10992 FunctionTypedFormalParameter functionParameter = parameter; |
| 10993 expect(functionParameter.returnType, isNotNull); |
| 10994 expect(functionParameter.identifier, isNotNull); |
| 10995 expect(functionParameter.typeParameters, isNotNull); |
| 10996 expect(functionParameter.parameters, isNotNull); |
| 10997 expect(functionParameter.question, isNull); |
| 10998 } |
| 10999 |
| 11000 void test_parseNormalFormalParameter_function_void_typeParameters_nullable() { |
| 11001 enableGenericMethods = true; |
| 11002 enableNnbd = true; |
| 11003 createParser('void a<E>()?)'); |
| 11004 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); |
| 11005 expectNotNullIfNoErrors(parameter); |
| 11006 listener.assertNoErrors(); |
| 11007 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); |
| 11008 FunctionTypedFormalParameter functionParameter = parameter; |
| 11009 expect(functionParameter.returnType, isNotNull); |
| 11010 expect(functionParameter.identifier, isNotNull); |
| 11011 expect(functionParameter.typeParameters, isNotNull); |
| 11012 expect(functionParameter.parameters, isNotNull); |
| 11013 expect(functionParameter.question, isNotNull); |
| 9000 } | 11014 } |
| 9001 | 11015 |
| 9002 void test_parseNormalFormalParameter_simple_const_noType() { | 11016 void test_parseNormalFormalParameter_simple_const_noType() { |
| 9003 SimpleFormalParameter parameter = | 11017 createParser('const a)'); |
| 9004 parse4("parseNormalFormalParameter", "const a)"); | 11018 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); |
| 9005 expect(parameter.keyword, isNotNull); | 11019 expectNotNullIfNoErrors(parameter); |
| 9006 expect(parameter.type, isNull); | 11020 listener.assertNoErrors(); |
| 9007 expect(parameter.identifier, isNotNull); | 11021 expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| 11022 SimpleFormalParameter simpleParameter = parameter; |
| 11023 expect(simpleParameter.keyword, isNotNull); |
| 11024 expect(simpleParameter.type, isNull); |
| 11025 expect(simpleParameter.identifier, isNotNull); |
| 9008 } | 11026 } |
| 9009 | 11027 |
| 9010 void test_parseNormalFormalParameter_simple_const_type() { | 11028 void test_parseNormalFormalParameter_simple_const_type() { |
| 9011 SimpleFormalParameter parameter = | 11029 createParser('const A a)'); |
| 9012 parse4("parseNormalFormalParameter", "const A a)"); | 11030 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); |
| 9013 expect(parameter.keyword, isNotNull); | 11031 expectNotNullIfNoErrors(parameter); |
| 9014 expect(parameter.type, isNotNull); | 11032 listener.assertNoErrors(); |
| 9015 expect(parameter.identifier, isNotNull); | 11033 expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| 11034 SimpleFormalParameter simpleParameter = parameter; |
| 11035 expect(simpleParameter.keyword, isNotNull); |
| 11036 expect(simpleParameter.type, isNotNull); |
| 11037 expect(simpleParameter.identifier, isNotNull); |
| 9016 } | 11038 } |
| 9017 | 11039 |
| 9018 void test_parseNormalFormalParameter_simple_final_noType() { | 11040 void test_parseNormalFormalParameter_simple_final_noType() { |
| 9019 SimpleFormalParameter parameter = | 11041 createParser('final a)'); |
| 9020 parse4("parseNormalFormalParameter", "final a)"); | 11042 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); |
| 9021 expect(parameter.keyword, isNotNull); | 11043 expectNotNullIfNoErrors(parameter); |
| 9022 expect(parameter.type, isNull); | 11044 listener.assertNoErrors(); |
| 9023 expect(parameter.identifier, isNotNull); | 11045 expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| 11046 SimpleFormalParameter simpleParameter = parameter; |
| 11047 expect(simpleParameter.keyword, isNotNull); |
| 11048 expect(simpleParameter.type, isNull); |
| 11049 expect(simpleParameter.identifier, isNotNull); |
| 9024 } | 11050 } |
| 9025 | 11051 |
| 9026 void test_parseNormalFormalParameter_simple_final_type() { | 11052 void test_parseNormalFormalParameter_simple_final_type() { |
| 9027 SimpleFormalParameter parameter = | 11053 createParser('final A a)'); |
| 9028 parse4("parseNormalFormalParameter", "final A a)"); | 11054 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); |
| 9029 expect(parameter.keyword, isNotNull); | 11055 expectNotNullIfNoErrors(parameter); |
| 9030 expect(parameter.type, isNotNull); | 11056 listener.assertNoErrors(); |
| 9031 expect(parameter.identifier, isNotNull); | 11057 expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| 11058 SimpleFormalParameter simpleParameter = parameter; |
| 11059 expect(simpleParameter.keyword, isNotNull); |
| 11060 expect(simpleParameter.type, isNotNull); |
| 11061 expect(simpleParameter.identifier, isNotNull); |
| 9032 } | 11062 } |
| 9033 | 11063 |
| 9034 void test_parseNormalFormalParameter_simple_noType() { | 11064 void test_parseNormalFormalParameter_simple_noType() { |
| 9035 SimpleFormalParameter parameter = | 11065 createParser('a)'); |
| 9036 parse4("parseNormalFormalParameter", "a)"); | 11066 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); |
| 9037 expect(parameter.keyword, isNull); | 11067 expectNotNullIfNoErrors(parameter); |
| 9038 expect(parameter.type, isNull); | 11068 listener.assertNoErrors(); |
| 9039 expect(parameter.identifier, isNotNull); | 11069 expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| 11070 SimpleFormalParameter simpleParameter = parameter; |
| 11071 expect(simpleParameter.keyword, isNull); |
| 11072 expect(simpleParameter.type, isNull); |
| 11073 expect(simpleParameter.identifier, isNotNull); |
| 9040 } | 11074 } |
| 9041 | 11075 |
| 9042 void test_parseNormalFormalParameter_simple_type() { | 11076 void test_parseNormalFormalParameter_simple_type() { |
| 9043 SimpleFormalParameter parameter = | 11077 createParser('A a)'); |
| 9044 parse4("parseNormalFormalParameter", "A a)"); | 11078 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); |
| 9045 expect(parameter.keyword, isNull); | 11079 expectNotNullIfNoErrors(parameter); |
| 9046 expect(parameter.type, isNotNull); | 11080 listener.assertNoErrors(); |
| 9047 expect(parameter.identifier, isNotNull); | 11081 expect(parameter, new isInstanceOf<SimpleFormalParameter>()); |
| 11082 SimpleFormalParameter simpleParameter = parameter; |
| 11083 expect(simpleParameter.keyword, isNull); |
| 11084 expect(simpleParameter.type, isNotNull); |
| 11085 expect(simpleParameter.identifier, isNotNull); |
| 9048 } | 11086 } |
| 9049 | 11087 |
| 9050 void test_parseOperator() { | 11088 void test_parseOperator() { |
| 9051 Comment comment = Comment.createDocumentationComment(new List<Token>(0)); | 11089 Comment comment = Comment.createDocumentationComment(new List<Token>(0)); |
| 9052 TypeName returnType = new TypeName(new SimpleIdentifier(null), null); | 11090 TypeName returnType = new TypeName(new SimpleIdentifier(null), null); |
| 9053 MethodDeclaration method = parse( | 11091 createParser('operator +(A a);'); |
| 9054 "parseOperator", | 11092 MethodDeclaration method = |
| 9055 <Object>[commentAndMetadata(comment), null, returnType], | 11093 parser.parseOperator(commentAndMetadata(comment), null, returnType); |
| 9056 "operator +(A a);"); | 11094 expectNotNullIfNoErrors(method); |
| 11095 listener.assertNoErrors(); |
| 9057 expect(method.body, isNotNull); | 11096 expect(method.body, isNotNull); |
| 9058 expect(method.documentationComment, comment); | 11097 expect(method.documentationComment, comment); |
| 9059 expect(method.externalKeyword, isNull); | 11098 expect(method.externalKeyword, isNull); |
| 9060 expect(method.modifierKeyword, isNull); | 11099 expect(method.modifierKeyword, isNull); |
| 9061 expect(method.name, isNotNull); | 11100 expect(method.name, isNotNull); |
| 9062 expect(method.operatorKeyword, isNotNull); | 11101 expect(method.operatorKeyword, isNotNull); |
| 9063 expect(method.typeParameters, isNull); | 11102 expect(method.typeParameters, isNull); |
| 9064 expect(method.parameters, isNotNull); | 11103 expect(method.parameters, isNotNull); |
| 9065 expect(method.propertyKeyword, isNull); | 11104 expect(method.propertyKeyword, isNull); |
| 9066 expect(method.returnType, returnType); | 11105 expect(method.returnType, returnType); |
| 9067 } | 11106 } |
| 9068 | 11107 |
| 9069 void test_parseOptionalReturnType() { | 11108 void test_parseOptionalReturnType() { |
| 9070 // TODO(brianwilkerson) Implement tests for this method. | 11109 // TODO(brianwilkerson) Implement tests for this method. |
| 9071 } | 11110 } |
| 9072 | 11111 |
| 9073 void test_parsePartDirective_part() { | 11112 void test_parsePartDirective_part() { |
| 9074 PartDirective directive = parse("parsePartDirective", | 11113 createParser("part 'lib/lib.dart';"); |
| 9075 <Object>[emptyCommentAndMetadata()], "part 'lib/lib.dart';"); | 11114 PartDirective directive = |
| 11115 parser.parsePartOrPartOfDirective(emptyCommentAndMetadata()); |
| 11116 expectNotNullIfNoErrors(directive); |
| 11117 listener.assertNoErrors(); |
| 9076 expect(directive.partKeyword, isNotNull); | 11118 expect(directive.partKeyword, isNotNull); |
| 9077 expect(directive.uri, isNotNull); | 11119 expect(directive.uri, isNotNull); |
| 9078 expect(directive.semicolon, isNotNull); | 11120 expect(directive.semicolon, isNotNull); |
| 9079 } | 11121 } |
| 9080 | 11122 |
| 9081 void test_parsePartDirective_partOf() { | 11123 void test_parsePartDirective_partOf() { |
| 9082 PartOfDirective directive = parse("parsePartDirective", | 11124 createParser('part of l;'); |
| 9083 <Object>[emptyCommentAndMetadata()], "part of l;"); | 11125 PartOfDirective directive = |
| 11126 parser.parsePartOrPartOfDirective(emptyCommentAndMetadata()); |
| 11127 expectNotNullIfNoErrors(directive); |
| 11128 listener.assertNoErrors(); |
| 9084 expect(directive.partKeyword, isNotNull); | 11129 expect(directive.partKeyword, isNotNull); |
| 9085 expect(directive.ofKeyword, isNotNull); | 11130 expect(directive.ofKeyword, isNotNull); |
| 9086 expect(directive.libraryName, isNotNull); | 11131 expect(directive.libraryName, isNotNull); |
| 9087 expect(directive.semicolon, isNotNull); | 11132 expect(directive.semicolon, isNotNull); |
| 9088 } | 11133 } |
| 9089 | 11134 |
| 9090 void test_parsePostfixExpression_decrement() { | 11135 void test_parsePostfixExpression_decrement() { |
| 9091 PostfixExpression expression = parse4("parsePostfixExpression", "i--"); | 11136 createParser('i--'); |
| 9092 expect(expression.operand, isNotNull); | 11137 Expression expression = parser.parsePostfixExpression(); |
| 9093 expect(expression.operator, isNotNull); | 11138 expectNotNullIfNoErrors(expression); |
| 9094 expect(expression.operator.type, TokenType.MINUS_MINUS); | 11139 listener.assertNoErrors(); |
| 11140 expect(expression, new isInstanceOf<PostfixExpression>()); |
| 11141 PostfixExpression postfixExpression = expression; |
| 11142 expect(postfixExpression.operand, isNotNull); |
| 11143 expect(postfixExpression.operator, isNotNull); |
| 11144 expect(postfixExpression.operator.type, TokenType.MINUS_MINUS); |
| 9095 } | 11145 } |
| 9096 | 11146 |
| 9097 void test_parsePostfixExpression_increment() { | 11147 void test_parsePostfixExpression_increment() { |
| 9098 PostfixExpression expression = parse4("parsePostfixExpression", "i++"); | 11148 createParser('i++'); |
| 9099 expect(expression.operand, isNotNull); | 11149 Expression expression = parser.parsePostfixExpression(); |
| 9100 expect(expression.operator, isNotNull); | 11150 expectNotNullIfNoErrors(expression); |
| 9101 expect(expression.operator.type, TokenType.PLUS_PLUS); | 11151 listener.assertNoErrors(); |
| 11152 expect(expression, new isInstanceOf<PostfixExpression>()); |
| 11153 PostfixExpression postfixExpression = expression; |
| 11154 expect(postfixExpression.operand, isNotNull); |
| 11155 expect(postfixExpression.operator, isNotNull); |
| 11156 expect(postfixExpression.operator.type, TokenType.PLUS_PLUS); |
| 9102 } | 11157 } |
| 9103 | 11158 |
| 9104 void test_parsePostfixExpression_none_indexExpression() { | 11159 void test_parsePostfixExpression_none_indexExpression() { |
| 9105 IndexExpression expression = parse4("parsePostfixExpression", "a[0]"); | 11160 createParser('a[0]'); |
| 9106 expect(expression.target, isNotNull); | 11161 Expression expression = parser.parsePostfixExpression(); |
| 9107 expect(expression.index, isNotNull); | 11162 expectNotNullIfNoErrors(expression); |
| 11163 listener.assertNoErrors(); |
| 11164 expect(expression, new isInstanceOf<IndexExpression>()); |
| 11165 IndexExpression indexExpression = expression; |
| 11166 expect(indexExpression.target, isNotNull); |
| 11167 expect(indexExpression.index, isNotNull); |
| 9108 } | 11168 } |
| 9109 | 11169 |
| 9110 void test_parsePostfixExpression_none_methodInvocation() { | 11170 void test_parsePostfixExpression_none_methodInvocation() { |
| 9111 MethodInvocation expression = parse4("parsePostfixExpression", "a.m()"); | 11171 createParser('a.m()'); |
| 9112 expect(expression.target, isNotNull); | 11172 Expression expression = parser.parsePostfixExpression(); |
| 9113 expect(expression.operator.type, TokenType.PERIOD); | 11173 expectNotNullIfNoErrors(expression); |
| 9114 expect(expression.methodName, isNotNull); | 11174 listener.assertNoErrors(); |
| 9115 expect(expression.typeArguments, isNull); | 11175 expect(expression, new isInstanceOf<MethodInvocation>()); |
| 9116 expect(expression.argumentList, isNotNull); | 11176 MethodInvocation methodInvocation = expression; |
| 11177 expect(methodInvocation.target, isNotNull); |
| 11178 expect(methodInvocation.operator.type, TokenType.PERIOD); |
| 11179 expect(methodInvocation.methodName, isNotNull); |
| 11180 expect(methodInvocation.typeArguments, isNull); |
| 11181 expect(methodInvocation.argumentList, isNotNull); |
| 9117 } | 11182 } |
| 9118 | 11183 |
| 9119 void test_parsePostfixExpression_none_methodInvocation_question_dot() { | 11184 void test_parsePostfixExpression_none_methodInvocation_question_dot() { |
| 9120 MethodInvocation expression = parse4('parsePostfixExpression', 'a?.m()'); | 11185 createParser('a?.m()'); |
| 9121 expect(expression.target, isNotNull); | 11186 Expression expression = parser.parsePostfixExpression(); |
| 9122 expect(expression.operator.type, TokenType.QUESTION_PERIOD); | 11187 expectNotNullIfNoErrors(expression); |
| 9123 expect(expression.methodName, isNotNull); | 11188 listener.assertNoErrors(); |
| 9124 expect(expression.typeArguments, isNull); | 11189 expect(expression, new isInstanceOf<MethodInvocation>()); |
| 9125 expect(expression.argumentList, isNotNull); | 11190 MethodInvocation methodInvocation = expression; |
| 9126 } | 11191 expect(methodInvocation.target, isNotNull); |
| 9127 | 11192 expect(methodInvocation.operator.type, TokenType.QUESTION_PERIOD); |
| 9128 void test_parsePostfixExpression_none_methodInvocation_question_dot_typeArgume
nts() { | 11193 expect(methodInvocation.methodName, isNotNull); |
| 11194 expect(methodInvocation.typeArguments, isNull); |
| 11195 expect(methodInvocation.argumentList, isNotNull); |
| 11196 } |
| 11197 |
| 11198 void |
| 11199 test_parsePostfixExpression_none_methodInvocation_question_dot_typeArgumen
tComments() { |
| 11200 enableGenericMethodComments = true; |
| 11201 createParser('a?.m/*<E>*/()'); |
| 11202 Expression expression = parser.parsePostfixExpression(); |
| 11203 expectNotNullIfNoErrors(expression); |
| 11204 listener.assertNoErrors(); |
| 11205 expect(expression, new isInstanceOf<MethodInvocation>()); |
| 11206 MethodInvocation methodInvocation = expression; |
| 11207 expect(methodInvocation.target, isNotNull); |
| 11208 expect(methodInvocation.operator.type, TokenType.QUESTION_PERIOD); |
| 11209 expect(methodInvocation.methodName, isNotNull); |
| 11210 expect(methodInvocation.typeArguments, isNotNull); |
| 11211 expect(methodInvocation.argumentList, isNotNull); |
| 11212 } |
| 11213 |
| 11214 void |
| 11215 test_parsePostfixExpression_none_methodInvocation_question_dot_typeArgumen
ts() { |
| 9129 enableGenericMethods = true; | 11216 enableGenericMethods = true; |
| 9130 MethodInvocation expression = parse4('parsePostfixExpression', 'a?.m<E>()'); | 11217 createParser('a?.m<E>()'); |
| 9131 expect(expression.target, isNotNull); | 11218 Expression expression = parser.parsePostfixExpression(); |
| 9132 expect(expression.operator.type, TokenType.QUESTION_PERIOD); | 11219 expectNotNullIfNoErrors(expression); |
| 9133 expect(expression.methodName, isNotNull); | 11220 listener.assertNoErrors(); |
| 9134 expect(expression.typeArguments, isNotNull); | 11221 expect(expression, new isInstanceOf<MethodInvocation>()); |
| 9135 expect(expression.argumentList, isNotNull); | 11222 MethodInvocation methodInvocation = expression; |
| 11223 expect(methodInvocation.target, isNotNull); |
| 11224 expect(methodInvocation.operator.type, TokenType.QUESTION_PERIOD); |
| 11225 expect(methodInvocation.methodName, isNotNull); |
| 11226 expect(methodInvocation.typeArguments, isNotNull); |
| 11227 expect(methodInvocation.argumentList, isNotNull); |
| 11228 } |
| 11229 |
| 11230 void |
| 11231 test_parsePostfixExpression_none_methodInvocation_typeArgumentComments() { |
| 11232 enableGenericMethodComments = true; |
| 11233 createParser('a.m/*<E>*/()'); |
| 11234 Expression expression = parser.parsePostfixExpression(); |
| 11235 expectNotNullIfNoErrors(expression); |
| 11236 listener.assertNoErrors(); |
| 11237 expect(expression, new isInstanceOf<MethodInvocation>()); |
| 11238 MethodInvocation methodInvocation = expression; |
| 11239 expect(methodInvocation.target, isNotNull); |
| 11240 expect(methodInvocation.operator.type, TokenType.PERIOD); |
| 11241 expect(methodInvocation.methodName, isNotNull); |
| 11242 expect(methodInvocation.typeArguments, isNotNull); |
| 11243 expect(methodInvocation.argumentList, isNotNull); |
| 9136 } | 11244 } |
| 9137 | 11245 |
| 9138 void test_parsePostfixExpression_none_methodInvocation_typeArguments() { | 11246 void test_parsePostfixExpression_none_methodInvocation_typeArguments() { |
| 9139 enableGenericMethods = true; | 11247 enableGenericMethods = true; |
| 9140 MethodInvocation expression = parse4("parsePostfixExpression", "a.m<E>()"); | 11248 createParser('a.m<E>()'); |
| 9141 expect(expression.target, isNotNull); | 11249 Expression expression = parser.parsePostfixExpression(); |
| 9142 expect(expression.operator.type, TokenType.PERIOD); | 11250 expectNotNullIfNoErrors(expression); |
| 9143 expect(expression.methodName, isNotNull); | 11251 listener.assertNoErrors(); |
| 9144 expect(expression.typeArguments, isNotNull); | 11252 expect(expression, new isInstanceOf<MethodInvocation>()); |
| 9145 expect(expression.argumentList, isNotNull); | 11253 MethodInvocation methodInvocation = expression; |
| 11254 expect(methodInvocation.target, isNotNull); |
| 11255 expect(methodInvocation.operator.type, TokenType.PERIOD); |
| 11256 expect(methodInvocation.methodName, isNotNull); |
| 11257 expect(methodInvocation.typeArguments, isNotNull); |
| 11258 expect(methodInvocation.argumentList, isNotNull); |
| 9146 } | 11259 } |
| 9147 | 11260 |
| 9148 void test_parsePostfixExpression_none_propertyAccess() { | 11261 void test_parsePostfixExpression_none_propertyAccess() { |
| 9149 PrefixedIdentifier expression = parse4("parsePostfixExpression", "a.b"); | 11262 createParser('a.b'); |
| 9150 expect(expression.prefix, isNotNull); | 11263 Expression expression = parser.parsePostfixExpression(); |
| 9151 expect(expression.identifier, isNotNull); | 11264 expectNotNullIfNoErrors(expression); |
| 11265 listener.assertNoErrors(); |
| 11266 expect(expression, new isInstanceOf<PrefixedIdentifier>()); |
| 11267 PrefixedIdentifier identifier = expression; |
| 11268 expect(identifier.prefix, isNotNull); |
| 11269 expect(identifier.identifier, isNotNull); |
| 9152 } | 11270 } |
| 9153 | 11271 |
| 9154 void test_parsePrefixedIdentifier_noPrefix() { | 11272 void test_parsePrefixedIdentifier_noPrefix() { |
| 9155 String lexeme = "bar"; | 11273 String lexeme = "bar"; |
| 9156 SimpleIdentifier identifier = parse4("parsePrefixedIdentifier", lexeme); | 11274 createParser(lexeme); |
| 9157 expect(identifier.token, isNotNull); | 11275 Identifier identifier = parser.parsePrefixedIdentifier(); |
| 9158 expect(identifier.name, lexeme); | 11276 expectNotNullIfNoErrors(identifier); |
| 11277 listener.assertNoErrors(); |
| 11278 expect(identifier, new isInstanceOf<SimpleIdentifier>()); |
| 11279 SimpleIdentifier simpleIdentifier = identifier; |
| 11280 expect(simpleIdentifier.token, isNotNull); |
| 11281 expect(simpleIdentifier.name, lexeme); |
| 9159 } | 11282 } |
| 9160 | 11283 |
| 9161 void test_parsePrefixedIdentifier_prefix() { | 11284 void test_parsePrefixedIdentifier_prefix() { |
| 9162 String lexeme = "foo.bar"; | 11285 String lexeme = "foo.bar"; |
| 9163 PrefixedIdentifier identifier = parse4("parsePrefixedIdentifier", lexeme); | 11286 createParser(lexeme); |
| 9164 expect(identifier.prefix.name, "foo"); | 11287 Identifier identifier = parser.parsePrefixedIdentifier(); |
| 9165 expect(identifier.period, isNotNull); | 11288 expectNotNullIfNoErrors(identifier); |
| 9166 expect(identifier.identifier.name, "bar"); | 11289 listener.assertNoErrors(); |
| 11290 expect(identifier, new isInstanceOf<PrefixedIdentifier>()); |
| 11291 PrefixedIdentifier prefixedIdentifier = identifier; |
| 11292 expect(prefixedIdentifier.prefix.name, "foo"); |
| 11293 expect(prefixedIdentifier.period, isNotNull); |
| 11294 expect(prefixedIdentifier.identifier.name, "bar"); |
| 9167 } | 11295 } |
| 9168 | 11296 |
| 9169 void test_parsePrimaryExpression_const() { | 11297 void test_parsePrimaryExpression_const() { |
| 9170 InstanceCreationExpression expression = | 11298 createParser('const A()'); |
| 9171 parse4("parsePrimaryExpression", "const A()"); | 11299 Expression expression = parser.parsePrimaryExpression(); |
| 11300 expectNotNullIfNoErrors(expression); |
| 11301 listener.assertNoErrors(); |
| 9172 expect(expression, isNotNull); | 11302 expect(expression, isNotNull); |
| 9173 } | 11303 } |
| 9174 | 11304 |
| 9175 void test_parsePrimaryExpression_double() { | 11305 void test_parsePrimaryExpression_double() { |
| 9176 String doubleLiteral = "3.2e4"; | 11306 String doubleLiteral = "3.2e4"; |
| 9177 DoubleLiteral literal = parse4("parsePrimaryExpression", doubleLiteral); | 11307 createParser(doubleLiteral); |
| 11308 Expression expression = parser.parsePrimaryExpression(); |
| 11309 expectNotNullIfNoErrors(expression); |
| 11310 listener.assertNoErrors(); |
| 11311 expect(expression, new isInstanceOf<DoubleLiteral>()); |
| 11312 DoubleLiteral literal = expression; |
| 9178 expect(literal.literal, isNotNull); | 11313 expect(literal.literal, isNotNull); |
| 9179 expect(literal.value, double.parse(doubleLiteral)); | 11314 expect(literal.value, double.parse(doubleLiteral)); |
| 9180 } | 11315 } |
| 9181 | 11316 |
| 9182 void test_parsePrimaryExpression_false() { | 11317 void test_parsePrimaryExpression_false() { |
| 9183 BooleanLiteral literal = parse4("parsePrimaryExpression", "false"); | 11318 createParser('false'); |
| 11319 Expression expression = parser.parsePrimaryExpression(); |
| 11320 expectNotNullIfNoErrors(expression); |
| 11321 listener.assertNoErrors(); |
| 11322 expect(expression, new isInstanceOf<BooleanLiteral>()); |
| 11323 BooleanLiteral literal = expression; |
| 9184 expect(literal.literal, isNotNull); | 11324 expect(literal.literal, isNotNull); |
| 9185 expect(literal.value, isFalse); | 11325 expect(literal.value, isFalse); |
| 9186 } | 11326 } |
| 9187 | 11327 |
| 9188 void test_parsePrimaryExpression_function_arguments() { | 11328 void test_parsePrimaryExpression_function_arguments() { |
| 9189 FunctionExpression expression = | 11329 createParser('(int i) => i + 1'); |
| 9190 parse4("parsePrimaryExpression", "(int i) => i + 1"); | 11330 Expression expression = parser.parsePrimaryExpression(); |
| 9191 expect(expression.parameters, isNotNull); | 11331 expectNotNullIfNoErrors(expression); |
| 9192 expect(expression.body, isNotNull); | 11332 listener.assertNoErrors(); |
| 11333 expect(expression, new isInstanceOf<FunctionExpression>()); |
| 11334 FunctionExpression functionExpression = expression; |
| 11335 expect(functionExpression.parameters, isNotNull); |
| 11336 expect(functionExpression.body, isNotNull); |
| 9193 } | 11337 } |
| 9194 | 11338 |
| 9195 void test_parsePrimaryExpression_function_noArguments() { | 11339 void test_parsePrimaryExpression_function_noArguments() { |
| 9196 FunctionExpression expression = | 11340 createParser('() => 42'); |
| 9197 parse4("parsePrimaryExpression", "() => 42"); | 11341 Expression expression = parser.parsePrimaryExpression(); |
| 9198 expect(expression.parameters, isNotNull); | 11342 expectNotNullIfNoErrors(expression); |
| 9199 expect(expression.body, isNotNull); | 11343 listener.assertNoErrors(); |
| 11344 expect(expression, new isInstanceOf<FunctionExpression>()); |
| 11345 FunctionExpression functionExpression = expression; |
| 11346 expect(functionExpression.parameters, isNotNull); |
| 11347 expect(functionExpression.body, isNotNull); |
| 9200 } | 11348 } |
| 9201 | 11349 |
| 9202 void test_parsePrimaryExpression_hex() { | 11350 void test_parsePrimaryExpression_hex() { |
| 9203 String hexLiteral = "3F"; | 11351 String hexLiteral = "3F"; |
| 9204 IntegerLiteral literal = parse4("parsePrimaryExpression", "0x$hexLiteral"); | 11352 createParser('0x$hexLiteral'); |
| 11353 Expression expression = parser.parsePrimaryExpression(); |
| 11354 expectNotNullIfNoErrors(expression); |
| 11355 listener.assertNoErrors(); |
| 11356 expect(expression, new isInstanceOf<IntegerLiteral>()); |
| 11357 IntegerLiteral literal = expression; |
| 9205 expect(literal.literal, isNotNull); | 11358 expect(literal.literal, isNotNull); |
| 9206 expect(literal.value, int.parse(hexLiteral, radix: 16)); | 11359 expect(literal.value, int.parse(hexLiteral, radix: 16)); |
| 9207 } | 11360 } |
| 9208 | 11361 |
| 9209 void test_parsePrimaryExpression_identifier() { | 11362 void test_parsePrimaryExpression_identifier() { |
| 9210 SimpleIdentifier identifier = parse4("parsePrimaryExpression", "a"); | 11363 createParser('a'); |
| 11364 Expression expression = parser.parsePrimaryExpression(); |
| 11365 expectNotNullIfNoErrors(expression); |
| 11366 listener.assertNoErrors(); |
| 11367 expect(expression, new isInstanceOf<SimpleIdentifier>()); |
| 11368 SimpleIdentifier identifier = expression; |
| 9211 expect(identifier, isNotNull); | 11369 expect(identifier, isNotNull); |
| 9212 } | 11370 } |
| 9213 | 11371 |
| 9214 void test_parsePrimaryExpression_int() { | 11372 void test_parsePrimaryExpression_int() { |
| 9215 String intLiteral = "472"; | 11373 String intLiteral = "472"; |
| 9216 IntegerLiteral literal = parse4("parsePrimaryExpression", intLiteral); | 11374 createParser(intLiteral); |
| 11375 Expression expression = parser.parsePrimaryExpression(); |
| 11376 expectNotNullIfNoErrors(expression); |
| 11377 listener.assertNoErrors(); |
| 11378 expect(expression, new isInstanceOf<IntegerLiteral>()); |
| 11379 IntegerLiteral literal = expression; |
| 9217 expect(literal.literal, isNotNull); | 11380 expect(literal.literal, isNotNull); |
| 9218 expect(literal.value, int.parse(intLiteral)); | 11381 expect(literal.value, int.parse(intLiteral)); |
| 9219 } | 11382 } |
| 9220 | 11383 |
| 9221 void test_parsePrimaryExpression_listLiteral() { | 11384 void test_parsePrimaryExpression_listLiteral() { |
| 9222 ListLiteral literal = parse4("parsePrimaryExpression", "[ ]"); | 11385 createParser('[ ]'); |
| 11386 Expression expression = parser.parsePrimaryExpression(); |
| 11387 expectNotNullIfNoErrors(expression); |
| 11388 listener.assertNoErrors(); |
| 11389 expect(expression, new isInstanceOf<ListLiteral>()); |
| 11390 ListLiteral literal = expression; |
| 9223 expect(literal, isNotNull); | 11391 expect(literal, isNotNull); |
| 9224 } | 11392 } |
| 9225 | 11393 |
| 9226 void test_parsePrimaryExpression_listLiteral_index() { | 11394 void test_parsePrimaryExpression_listLiteral_index() { |
| 9227 ListLiteral literal = parse4("parsePrimaryExpression", "[]"); | 11395 createParser('[]'); |
| 11396 Expression expression = parser.parsePrimaryExpression(); |
| 11397 expectNotNullIfNoErrors(expression); |
| 11398 listener.assertNoErrors(); |
| 11399 expect(expression, new isInstanceOf<ListLiteral>()); |
| 11400 ListLiteral literal = expression; |
| 9228 expect(literal, isNotNull); | 11401 expect(literal, isNotNull); |
| 9229 } | 11402 } |
| 9230 | 11403 |
| 9231 void test_parsePrimaryExpression_listLiteral_typed() { | 11404 void test_parsePrimaryExpression_listLiteral_typed() { |
| 9232 ListLiteral literal = parse4("parsePrimaryExpression", "<A>[ ]"); | 11405 createParser('<A>[ ]'); |
| 11406 Expression expression = parser.parsePrimaryExpression(); |
| 11407 expectNotNullIfNoErrors(expression); |
| 11408 listener.assertNoErrors(); |
| 11409 expect(expression, new isInstanceOf<ListLiteral>()); |
| 11410 ListLiteral literal = expression; |
| 9233 expect(literal.typeArguments, isNotNull); | 11411 expect(literal.typeArguments, isNotNull); |
| 9234 expect(literal.typeArguments.arguments, hasLength(1)); | 11412 expect(literal.typeArguments.arguments, hasLength(1)); |
| 9235 } | 11413 } |
| 9236 | 11414 |
| 11415 void test_parsePrimaryExpression_listLiteral_typed_genericComment() { |
| 11416 enableGenericMethodComments = true; |
| 11417 createParser('/*<A>*/[ ]'); |
| 11418 Expression expression = parser.parsePrimaryExpression(); |
| 11419 expectNotNullIfNoErrors(expression); |
| 11420 listener.assertNoErrors(); |
| 11421 expect(expression, new isInstanceOf<ListLiteral>()); |
| 11422 ListLiteral literal = expression; |
| 11423 expect(literal.typeArguments, isNotNull); |
| 11424 expect(literal.typeArguments.arguments, hasLength(1)); |
| 11425 } |
| 11426 |
| 9237 void test_parsePrimaryExpression_mapLiteral() { | 11427 void test_parsePrimaryExpression_mapLiteral() { |
| 9238 MapLiteral literal = parse4("parsePrimaryExpression", "{}"); | 11428 createParser('{}'); |
| 11429 Expression expression = parser.parsePrimaryExpression(); |
| 11430 expectNotNullIfNoErrors(expression); |
| 11431 listener.assertNoErrors(); |
| 11432 expect(expression, new isInstanceOf<MapLiteral>()); |
| 11433 MapLiteral literal = expression; |
| 11434 expect(literal.typeArguments, isNull); |
| 9239 expect(literal, isNotNull); | 11435 expect(literal, isNotNull); |
| 9240 } | 11436 } |
| 9241 | 11437 |
| 9242 void test_parsePrimaryExpression_mapLiteral_typed() { | 11438 void test_parsePrimaryExpression_mapLiteral_typed() { |
| 9243 MapLiteral literal = parse4("parsePrimaryExpression", "<A, B>{}"); | 11439 createParser('<A, B>{}'); |
| 11440 Expression expression = parser.parsePrimaryExpression(); |
| 11441 expectNotNullIfNoErrors(expression); |
| 11442 listener.assertNoErrors(); |
| 11443 expect(expression, new isInstanceOf<MapLiteral>()); |
| 11444 MapLiteral literal = expression; |
| 9244 expect(literal.typeArguments, isNotNull); | 11445 expect(literal.typeArguments, isNotNull); |
| 9245 expect(literal.typeArguments.arguments, hasLength(2)); | 11446 expect(literal.typeArguments.arguments, hasLength(2)); |
| 9246 } | 11447 } |
| 9247 | 11448 |
| 11449 void test_parsePrimaryExpression_mapLiteral_typed_genericComment() { |
| 11450 enableGenericMethodComments = true; |
| 11451 createParser('/*<A, B>*/{}'); |
| 11452 Expression expression = parser.parsePrimaryExpression(); |
| 11453 expectNotNullIfNoErrors(expression); |
| 11454 listener.assertNoErrors(); |
| 11455 expect(expression, new isInstanceOf<MapLiteral>()); |
| 11456 MapLiteral literal = expression; |
| 11457 expect(literal.typeArguments, isNotNull); |
| 11458 expect(literal.typeArguments.arguments, hasLength(2)); |
| 11459 } |
| 11460 |
| 9248 void test_parsePrimaryExpression_new() { | 11461 void test_parsePrimaryExpression_new() { |
| 9249 InstanceCreationExpression expression = | 11462 createParser('new A()'); |
| 9250 parse4("parsePrimaryExpression", "new A()"); | 11463 Expression expression = parser.parsePrimaryExpression(); |
| 9251 expect(expression, isNotNull); | 11464 expectNotNullIfNoErrors(expression); |
| 11465 listener.assertNoErrors(); |
| 11466 expect(expression, new isInstanceOf<InstanceCreationExpression>()); |
| 11467 InstanceCreationExpression creation = expression; |
| 11468 expect(creation, isNotNull); |
| 9252 } | 11469 } |
| 9253 | 11470 |
| 9254 void test_parsePrimaryExpression_null() { | 11471 void test_parsePrimaryExpression_null() { |
| 9255 NullLiteral literal = parse4("parsePrimaryExpression", "null"); | 11472 createParser('null'); |
| 11473 Expression expression = parser.parsePrimaryExpression(); |
| 11474 expectNotNullIfNoErrors(expression); |
| 11475 listener.assertNoErrors(); |
| 11476 expect(expression, new isInstanceOf<NullLiteral>()); |
| 11477 NullLiteral literal = expression; |
| 9256 expect(literal.literal, isNotNull); | 11478 expect(literal.literal, isNotNull); |
| 9257 } | 11479 } |
| 9258 | 11480 |
| 9259 void test_parsePrimaryExpression_parenthesized() { | 11481 void test_parsePrimaryExpression_parenthesized() { |
| 9260 ParenthesizedExpression expression = | 11482 createParser('(x)'); |
| 9261 parse4("parsePrimaryExpression", "(x)"); | 11483 Expression expression = parser.parsePrimaryExpression(); |
| 9262 expect(expression, isNotNull); | 11484 expectNotNullIfNoErrors(expression); |
| 11485 listener.assertNoErrors(); |
| 11486 expect(expression, new isInstanceOf<ParenthesizedExpression>()); |
| 11487 ParenthesizedExpression parens = expression; |
| 11488 expect(parens, isNotNull); |
| 9263 } | 11489 } |
| 9264 | 11490 |
| 9265 void test_parsePrimaryExpression_string() { | 11491 void test_parsePrimaryExpression_string() { |
| 9266 SimpleStringLiteral literal = | 11492 createParser('"string"'); |
| 9267 parse4("parsePrimaryExpression", "\"string\""); | 11493 Expression expression = parser.parsePrimaryExpression(); |
| 11494 expectNotNullIfNoErrors(expression); |
| 11495 listener.assertNoErrors(); |
| 11496 expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| 11497 SimpleStringLiteral literal = expression; |
| 9268 expect(literal.isMultiline, isFalse); | 11498 expect(literal.isMultiline, isFalse); |
| 9269 expect(literal.isRaw, isFalse); | 11499 expect(literal.isRaw, isFalse); |
| 9270 expect(literal.value, "string"); | 11500 expect(literal.value, "string"); |
| 9271 } | 11501 } |
| 9272 | 11502 |
| 9273 void test_parsePrimaryExpression_string_multiline() { | 11503 void test_parsePrimaryExpression_string_multiline() { |
| 9274 SimpleStringLiteral literal = | 11504 createParser("'''string'''"); |
| 9275 parse4("parsePrimaryExpression", "'''string'''"); | 11505 Expression expression = parser.parsePrimaryExpression(); |
| 11506 expectNotNullIfNoErrors(expression); |
| 11507 listener.assertNoErrors(); |
| 11508 expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| 11509 SimpleStringLiteral literal = expression; |
| 9276 expect(literal.isMultiline, isTrue); | 11510 expect(literal.isMultiline, isTrue); |
| 9277 expect(literal.isRaw, isFalse); | 11511 expect(literal.isRaw, isFalse); |
| 9278 expect(literal.value, "string"); | 11512 expect(literal.value, "string"); |
| 9279 } | 11513 } |
| 9280 | 11514 |
| 9281 void test_parsePrimaryExpression_string_raw() { | 11515 void test_parsePrimaryExpression_string_raw() { |
| 9282 SimpleStringLiteral literal = parse4("parsePrimaryExpression", "r'string'"); | 11516 createParser("r'string'"); |
| 11517 Expression expression = parser.parsePrimaryExpression(); |
| 11518 expectNotNullIfNoErrors(expression); |
| 11519 listener.assertNoErrors(); |
| 11520 expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| 11521 SimpleStringLiteral literal = expression; |
| 9283 expect(literal.isMultiline, isFalse); | 11522 expect(literal.isMultiline, isFalse); |
| 9284 expect(literal.isRaw, isTrue); | 11523 expect(literal.isRaw, isTrue); |
| 9285 expect(literal.value, "string"); | 11524 expect(literal.value, "string"); |
| 9286 } | 11525 } |
| 9287 | 11526 |
| 9288 void test_parsePrimaryExpression_super() { | 11527 void test_parsePrimaryExpression_super() { |
| 9289 PropertyAccess propertyAccess = parse4("parsePrimaryExpression", "super.x"); | 11528 createParser('super.x'); |
| 11529 Expression expression = parser.parsePrimaryExpression(); |
| 11530 expectNotNullIfNoErrors(expression); |
| 11531 listener.assertNoErrors(); |
| 11532 expect(expression, new isInstanceOf<PropertyAccess>()); |
| 11533 PropertyAccess propertyAccess = expression; |
| 9290 expect(propertyAccess.target is SuperExpression, isTrue); | 11534 expect(propertyAccess.target is SuperExpression, isTrue); |
| 9291 expect(propertyAccess.operator, isNotNull); | 11535 expect(propertyAccess.operator, isNotNull); |
| 9292 expect(propertyAccess.operator.type, TokenType.PERIOD); | 11536 expect(propertyAccess.operator.type, TokenType.PERIOD); |
| 9293 expect(propertyAccess.propertyName, isNotNull); | 11537 expect(propertyAccess.propertyName, isNotNull); |
| 9294 } | 11538 } |
| 9295 | 11539 |
| 9296 void test_parsePrimaryExpression_this() { | 11540 void test_parsePrimaryExpression_this() { |
| 9297 ThisExpression expression = parse4("parsePrimaryExpression", "this"); | 11541 createParser('this'); |
| 9298 expect(expression.thisKeyword, isNotNull); | 11542 Expression expression = parser.parsePrimaryExpression(); |
| 11543 expectNotNullIfNoErrors(expression); |
| 11544 listener.assertNoErrors(); |
| 11545 expect(expression, new isInstanceOf<ThisExpression>()); |
| 11546 ThisExpression thisExpression = expression; |
| 11547 expect(thisExpression.thisKeyword, isNotNull); |
| 9299 } | 11548 } |
| 9300 | 11549 |
| 9301 void test_parsePrimaryExpression_true() { | 11550 void test_parsePrimaryExpression_true() { |
| 9302 BooleanLiteral literal = parse4("parsePrimaryExpression", "true"); | 11551 createParser('true'); |
| 11552 Expression expression = parser.parsePrimaryExpression(); |
| 11553 expectNotNullIfNoErrors(expression); |
| 11554 listener.assertNoErrors(); |
| 11555 expect(expression, new isInstanceOf<BooleanLiteral>()); |
| 11556 BooleanLiteral literal = expression; |
| 9303 expect(literal.literal, isNotNull); | 11557 expect(literal.literal, isNotNull); |
| 9304 expect(literal.value, isTrue); | 11558 expect(literal.value, isTrue); |
| 9305 } | 11559 } |
| 9306 | 11560 |
| 9307 void test_Parser() { | 11561 void test_Parser() { |
| 9308 expect(new Parser(null, null), isNotNull); | 11562 expect(new Parser(null, null), isNotNull); |
| 9309 } | 11563 } |
| 9310 | 11564 |
| 9311 void test_parseRedirectingConstructorInvocation_named() { | 11565 void test_parseRedirectingConstructorInvocation_named() { |
| 11566 createParser('this.a()'); |
| 9312 RedirectingConstructorInvocation invocation = | 11567 RedirectingConstructorInvocation invocation = |
| 9313 parse4("parseRedirectingConstructorInvocation", "this.a()"); | 11568 parser.parseRedirectingConstructorInvocation(true); |
| 11569 expectNotNullIfNoErrors(invocation); |
| 11570 listener.assertNoErrors(); |
| 9314 expect(invocation.argumentList, isNotNull); | 11571 expect(invocation.argumentList, isNotNull); |
| 9315 expect(invocation.constructorName, isNotNull); | 11572 expect(invocation.constructorName, isNotNull); |
| 9316 expect(invocation.thisKeyword, isNotNull); | 11573 expect(invocation.thisKeyword, isNotNull); |
| 9317 expect(invocation.period, isNotNull); | 11574 expect(invocation.period, isNotNull); |
| 9318 } | 11575 } |
| 9319 | 11576 |
| 9320 void test_parseRedirectingConstructorInvocation_unnamed() { | 11577 void test_parseRedirectingConstructorInvocation_unnamed() { |
| 11578 createParser('this()'); |
| 9321 RedirectingConstructorInvocation invocation = | 11579 RedirectingConstructorInvocation invocation = |
| 9322 parse4("parseRedirectingConstructorInvocation", "this()"); | 11580 parser.parseRedirectingConstructorInvocation(false); |
| 11581 expectNotNullIfNoErrors(invocation); |
| 11582 listener.assertNoErrors(); |
| 9323 expect(invocation.argumentList, isNotNull); | 11583 expect(invocation.argumentList, isNotNull); |
| 9324 expect(invocation.constructorName, isNull); | 11584 expect(invocation.constructorName, isNull); |
| 9325 expect(invocation.thisKeyword, isNotNull); | 11585 expect(invocation.thisKeyword, isNotNull); |
| 9326 expect(invocation.period, isNull); | 11586 expect(invocation.period, isNull); |
| 9327 } | 11587 } |
| 9328 | 11588 |
| 9329 void test_parseRelationalExpression_as() { | 11589 void test_parseRelationalExpression_as() { |
| 9330 AsExpression expression = parse4("parseRelationalExpression", "x as Y"); | 11590 createParser('x as Y'); |
| 9331 expect(expression.expression, isNotNull); | 11591 Expression expression = parser.parseRelationalExpression(); |
| 9332 expect(expression.asOperator, isNotNull); | 11592 expectNotNullIfNoErrors(expression); |
| 9333 expect(expression.type, isNotNull); | 11593 listener.assertNoErrors(); |
| 11594 expect(expression, new isInstanceOf<AsExpression>()); |
| 11595 AsExpression asExpression = expression; |
| 11596 expect(asExpression.expression, isNotNull); |
| 11597 expect(asExpression.asOperator, isNotNull); |
| 11598 expect(asExpression.type, isNotNull); |
| 11599 } |
| 11600 |
| 11601 void test_parseRelationalExpression_as_nullable() { |
| 11602 enableNnbd = true; |
| 11603 createParser('x as Y?)'); |
| 11604 Expression expression = parser.parseRelationalExpression(); |
| 11605 expectNotNullIfNoErrors(expression); |
| 11606 listener.assertNoErrors(); |
| 11607 expect(expression, new isInstanceOf<AsExpression>()); |
| 11608 AsExpression asExpression = expression; |
| 11609 expect(asExpression.expression, isNotNull); |
| 11610 expect(asExpression.asOperator, isNotNull); |
| 11611 expect(asExpression.type, isNotNull); |
| 9334 } | 11612 } |
| 9335 | 11613 |
| 9336 void test_parseRelationalExpression_is() { | 11614 void test_parseRelationalExpression_is() { |
| 9337 IsExpression expression = parse4("parseRelationalExpression", "x is y"); | 11615 createParser('x is y'); |
| 9338 expect(expression.expression, isNotNull); | 11616 Expression expression = parser.parseRelationalExpression(); |
| 9339 expect(expression.isOperator, isNotNull); | 11617 expectNotNullIfNoErrors(expression); |
| 9340 expect(expression.notOperator, isNull); | 11618 listener.assertNoErrors(); |
| 9341 expect(expression.type, isNotNull); | 11619 expect(expression, new isInstanceOf<IsExpression>()); |
| 11620 IsExpression isExpression = expression; |
| 11621 expect(isExpression.expression, isNotNull); |
| 11622 expect(isExpression.isOperator, isNotNull); |
| 11623 expect(isExpression.notOperator, isNull); |
| 11624 expect(isExpression.type, isNotNull); |
| 11625 } |
| 11626 |
| 11627 void test_parseRelationalExpression_is_nullable() { |
| 11628 enableNnbd = true; |
| 11629 createParser('x is y?)'); |
| 11630 Expression expression = parser.parseRelationalExpression(); |
| 11631 expectNotNullIfNoErrors(expression); |
| 11632 listener.assertNoErrors(); |
| 11633 expect(expression, new isInstanceOf<IsExpression>()); |
| 11634 IsExpression isExpression = expression; |
| 11635 expect(isExpression.expression, isNotNull); |
| 11636 expect(isExpression.isOperator, isNotNull); |
| 11637 expect(isExpression.notOperator, isNull); |
| 11638 expect(isExpression.type, isNotNull); |
| 9342 } | 11639 } |
| 9343 | 11640 |
| 9344 void test_parseRelationalExpression_isNot() { | 11641 void test_parseRelationalExpression_isNot() { |
| 9345 IsExpression expression = parse4("parseRelationalExpression", "x is! y"); | 11642 createParser('x is! y'); |
| 9346 expect(expression.expression, isNotNull); | 11643 Expression expression = parser.parseRelationalExpression(); |
| 9347 expect(expression.isOperator, isNotNull); | 11644 expectNotNullIfNoErrors(expression); |
| 9348 expect(expression.notOperator, isNotNull); | 11645 listener.assertNoErrors(); |
| 9349 expect(expression.type, isNotNull); | 11646 expect(expression, new isInstanceOf<IsExpression>()); |
| 11647 IsExpression isExpression = expression; |
| 11648 expect(isExpression.expression, isNotNull); |
| 11649 expect(isExpression.isOperator, isNotNull); |
| 11650 expect(isExpression.notOperator, isNotNull); |
| 11651 expect(isExpression.type, isNotNull); |
| 9350 } | 11652 } |
| 9351 | 11653 |
| 9352 void test_parseRelationalExpression_normal() { | 11654 void test_parseRelationalExpression_normal() { |
| 9353 BinaryExpression expression = parse4("parseRelationalExpression", "x < y"); | 11655 createParser('x < y'); |
| 9354 expect(expression.leftOperand, isNotNull); | 11656 Expression expression = parser.parseRelationalExpression(); |
| 9355 expect(expression.operator, isNotNull); | 11657 expectNotNullIfNoErrors(expression); |
| 9356 expect(expression.operator.type, TokenType.LT); | 11658 listener.assertNoErrors(); |
| 9357 expect(expression.rightOperand, isNotNull); | 11659 expect(expression, new isInstanceOf<BinaryExpression>()); |
| 11660 BinaryExpression binaryExpression = expression; |
| 11661 expect(binaryExpression.leftOperand, isNotNull); |
| 11662 expect(binaryExpression.operator, isNotNull); |
| 11663 expect(binaryExpression.operator.type, TokenType.LT); |
| 11664 expect(binaryExpression.rightOperand, isNotNull); |
| 9358 } | 11665 } |
| 9359 | 11666 |
| 9360 void test_parseRelationalExpression_super() { | 11667 void test_parseRelationalExpression_super() { |
| 9361 BinaryExpression expression = | 11668 createParser('super < y'); |
| 9362 parse4("parseRelationalExpression", "super < y"); | 11669 Expression expression = parser.parseRelationalExpression(); |
| 9363 expect(expression.leftOperand, isNotNull); | 11670 expectNotNullIfNoErrors(expression); |
| 9364 expect(expression.operator, isNotNull); | 11671 listener.assertNoErrors(); |
| 9365 expect(expression.operator.type, TokenType.LT); | 11672 expect(expression, new isInstanceOf<BinaryExpression>()); |
| 9366 expect(expression.rightOperand, isNotNull); | 11673 BinaryExpression binaryExpression = expression; |
| 11674 expect(binaryExpression.leftOperand, isNotNull); |
| 11675 expect(binaryExpression.operator, isNotNull); |
| 11676 expect(binaryExpression.operator.type, TokenType.LT); |
| 11677 expect(binaryExpression.rightOperand, isNotNull); |
| 9367 } | 11678 } |
| 9368 | 11679 |
| 9369 void test_parseRethrowExpression() { | 11680 void test_parseRethrowExpression() { |
| 9370 RethrowExpression expression = parse4("parseRethrowExpression", "rethrow;"); | 11681 createParser('rethrow;'); |
| 11682 RethrowExpression expression = parser.parseRethrowExpression(); |
| 11683 expectNotNullIfNoErrors(expression); |
| 11684 listener.assertNoErrors(); |
| 9371 expect(expression.rethrowKeyword, isNotNull); | 11685 expect(expression.rethrowKeyword, isNotNull); |
| 9372 } | 11686 } |
| 9373 | 11687 |
| 9374 void test_parseReturnStatement_noValue() { | 11688 void test_parseReturnStatement_noValue() { |
| 9375 ReturnStatement statement = parse4("parseReturnStatement", "return;"); | 11689 createParser('return;'); |
| 11690 ReturnStatement statement = parser.parseReturnStatement(); |
| 11691 expectNotNullIfNoErrors(statement); |
| 11692 listener.assertNoErrors(); |
| 9376 expect(statement.returnKeyword, isNotNull); | 11693 expect(statement.returnKeyword, isNotNull); |
| 9377 expect(statement.expression, isNull); | 11694 expect(statement.expression, isNull); |
| 9378 expect(statement.semicolon, isNotNull); | 11695 expect(statement.semicolon, isNotNull); |
| 9379 } | 11696 } |
| 9380 | 11697 |
| 9381 void test_parseReturnStatement_value() { | 11698 void test_parseReturnStatement_value() { |
| 9382 ReturnStatement statement = parse4("parseReturnStatement", "return x;"); | 11699 createParser('return x;'); |
| 11700 ReturnStatement statement = parser.parseReturnStatement(); |
| 11701 expectNotNullIfNoErrors(statement); |
| 11702 listener.assertNoErrors(); |
| 9383 expect(statement.returnKeyword, isNotNull); | 11703 expect(statement.returnKeyword, isNotNull); |
| 9384 expect(statement.expression, isNotNull); | 11704 expect(statement.expression, isNotNull); |
| 9385 expect(statement.semicolon, isNotNull); | 11705 expect(statement.semicolon, isNotNull); |
| 9386 } | 11706 } |
| 9387 | 11707 |
| 9388 void test_parseReturnType_nonVoid() { | 11708 void test_parseReturnType_nonVoid() { |
| 9389 TypeName typeName = parse4("parseReturnType", "A<B>"); | 11709 createParser('A<B>'); |
| 11710 TypeName typeName = parser.parseReturnType(); |
| 11711 expectNotNullIfNoErrors(typeName); |
| 11712 listener.assertNoErrors(); |
| 9390 expect(typeName.name, isNotNull); | 11713 expect(typeName.name, isNotNull); |
| 9391 expect(typeName.typeArguments, isNotNull); | 11714 expect(typeName.typeArguments, isNotNull); |
| 9392 } | 11715 } |
| 9393 | 11716 |
| 9394 void test_parseReturnType_void() { | 11717 void test_parseReturnType_void() { |
| 9395 TypeName typeName = parse4("parseReturnType", "void"); | 11718 createParser('void'); |
| 11719 TypeName typeName = parser.parseReturnType(); |
| 11720 expectNotNullIfNoErrors(typeName); |
| 11721 listener.assertNoErrors(); |
| 9396 expect(typeName.name, isNotNull); | 11722 expect(typeName.name, isNotNull); |
| 9397 expect(typeName.typeArguments, isNull); | 11723 expect(typeName.typeArguments, isNull); |
| 9398 } | 11724 } |
| 9399 | 11725 |
| 9400 void test_parseSetter_nonStatic() { | 11726 void test_parseSetter_nonStatic() { |
| 9401 Comment comment = Comment.createDocumentationComment(new List<Token>(0)); | 11727 Comment comment = Comment.createDocumentationComment(new List<Token>(0)); |
| 9402 TypeName returnType = new TypeName(new SimpleIdentifier(null), null); | 11728 TypeName returnType = new TypeName(new SimpleIdentifier(null), null); |
| 9403 MethodDeclaration method = parse( | 11729 createParser('set a(var x);'); |
| 9404 "parseSetter", | 11730 MethodDeclaration method = |
| 9405 <Object>[commentAndMetadata(comment), null, null, returnType], | 11731 parser.parseSetter(commentAndMetadata(comment), null, null, returnType); |
| 9406 "set a(var x);"); | 11732 expectNotNullIfNoErrors(method); |
| 11733 listener.assertNoErrors(); |
| 9407 expect(method.body, isNotNull); | 11734 expect(method.body, isNotNull); |
| 9408 expect(method.documentationComment, comment); | 11735 expect(method.documentationComment, comment); |
| 9409 expect(method.externalKeyword, isNull); | 11736 expect(method.externalKeyword, isNull); |
| 9410 expect(method.modifierKeyword, isNull); | 11737 expect(method.modifierKeyword, isNull); |
| 9411 expect(method.name, isNotNull); | 11738 expect(method.name, isNotNull); |
| 9412 expect(method.operatorKeyword, isNull); | 11739 expect(method.operatorKeyword, isNull); |
| 9413 expect(method.typeParameters, isNull); | 11740 expect(method.typeParameters, isNull); |
| 9414 expect(method.parameters, isNotNull); | 11741 expect(method.parameters, isNotNull); |
| 9415 expect(method.propertyKeyword, isNotNull); | 11742 expect(method.propertyKeyword, isNotNull); |
| 9416 expect(method.returnType, returnType); | 11743 expect(method.returnType, returnType); |
| 9417 } | 11744 } |
| 9418 | 11745 |
| 9419 void test_parseSetter_static() { | 11746 void test_parseSetter_static() { |
| 9420 Comment comment = Comment.createDocumentationComment(new List<Token>(0)); | 11747 Comment comment = Comment.createDocumentationComment(new List<Token>(0)); |
| 9421 Token staticKeyword = TokenFactory.tokenFromKeyword(Keyword.STATIC); | 11748 Token staticKeyword = TokenFactory.tokenFromKeyword(Keyword.STATIC); |
| 9422 TypeName returnType = new TypeName(new SimpleIdentifier(null), null); | 11749 TypeName returnType = new TypeName(new SimpleIdentifier(null), null); |
| 9423 MethodDeclaration method = parse( | 11750 createParser('set a(var x) {}'); |
| 9424 "parseSetter", | 11751 MethodDeclaration method = parser.parseSetter( |
| 9425 <Object>[commentAndMetadata(comment), null, staticKeyword, returnType], | 11752 commentAndMetadata(comment), null, staticKeyword, returnType); |
| 9426 "set a(var x) {}"); | 11753 expectNotNullIfNoErrors(method); |
| 11754 listener.assertNoErrors(); |
| 9427 expect(method.body, isNotNull); | 11755 expect(method.body, isNotNull); |
| 9428 expect(method.documentationComment, comment); | 11756 expect(method.documentationComment, comment); |
| 9429 expect(method.externalKeyword, isNull); | 11757 expect(method.externalKeyword, isNull); |
| 9430 expect(method.modifierKeyword, staticKeyword); | 11758 expect(method.modifierKeyword, staticKeyword); |
| 9431 expect(method.name, isNotNull); | 11759 expect(method.name, isNotNull); |
| 9432 expect(method.operatorKeyword, isNull); | 11760 expect(method.operatorKeyword, isNull); |
| 9433 expect(method.typeParameters, isNull); | 11761 expect(method.typeParameters, isNull); |
| 9434 expect(method.parameters, isNotNull); | 11762 expect(method.parameters, isNotNull); |
| 9435 expect(method.propertyKeyword, isNotNull); | 11763 expect(method.propertyKeyword, isNotNull); |
| 9436 expect(method.returnType, returnType); | 11764 expect(method.returnType, returnType); |
| 9437 } | 11765 } |
| 9438 | 11766 |
| 9439 void test_parseShiftExpression_normal() { | 11767 void test_parseShiftExpression_normal() { |
| 9440 BinaryExpression expression = parse4("parseShiftExpression", "x << y"); | 11768 createParser('x << y'); |
| 11769 BinaryExpression expression = parser.parseShiftExpression(); |
| 11770 expectNotNullIfNoErrors(expression); |
| 11771 listener.assertNoErrors(); |
| 9441 expect(expression.leftOperand, isNotNull); | 11772 expect(expression.leftOperand, isNotNull); |
| 9442 expect(expression.operator, isNotNull); | 11773 expect(expression.operator, isNotNull); |
| 9443 expect(expression.operator.type, TokenType.LT_LT); | 11774 expect(expression.operator.type, TokenType.LT_LT); |
| 9444 expect(expression.rightOperand, isNotNull); | 11775 expect(expression.rightOperand, isNotNull); |
| 9445 } | 11776 } |
| 9446 | 11777 |
| 9447 void test_parseShiftExpression_super() { | 11778 void test_parseShiftExpression_super() { |
| 9448 BinaryExpression expression = parse4("parseShiftExpression", "super << y"); | 11779 createParser('super << y'); |
| 11780 BinaryExpression expression = parser.parseShiftExpression(); |
| 11781 expectNotNullIfNoErrors(expression); |
| 11782 listener.assertNoErrors(); |
| 9449 expect(expression.leftOperand, isNotNull); | 11783 expect(expression.leftOperand, isNotNull); |
| 9450 expect(expression.operator, isNotNull); | 11784 expect(expression.operator, isNotNull); |
| 9451 expect(expression.operator.type, TokenType.LT_LT); | 11785 expect(expression.operator.type, TokenType.LT_LT); |
| 9452 expect(expression.rightOperand, isNotNull); | 11786 expect(expression.rightOperand, isNotNull); |
| 9453 } | 11787 } |
| 9454 | 11788 |
| 9455 void test_parseSimpleIdentifier1_normalIdentifier() { | 11789 void test_parseSimpleIdentifier1_normalIdentifier() { |
| 9456 // TODO(brianwilkerson) Implement tests for this method. | 11790 // TODO(brianwilkerson) Implement tests for this method. |
| 9457 } | 11791 } |
| 9458 | 11792 |
| 9459 void test_parseSimpleIdentifier_builtInIdentifier() { | 11793 void test_parseSimpleIdentifier_builtInIdentifier() { |
| 9460 String lexeme = "as"; | 11794 String lexeme = "as"; |
| 9461 SimpleIdentifier identifier = parse4("parseSimpleIdentifier", lexeme); | 11795 createParser(lexeme); |
| 11796 SimpleIdentifier identifier = parser.parseSimpleIdentifier(); |
| 11797 expectNotNullIfNoErrors(identifier); |
| 11798 listener.assertNoErrors(); |
| 9462 expect(identifier.token, isNotNull); | 11799 expect(identifier.token, isNotNull); |
| 9463 expect(identifier.name, lexeme); | 11800 expect(identifier.name, lexeme); |
| 9464 } | 11801 } |
| 9465 | 11802 |
| 9466 void test_parseSimpleIdentifier_normalIdentifier() { | 11803 void test_parseSimpleIdentifier_normalIdentifier() { |
| 9467 String lexeme = "foo"; | 11804 String lexeme = "foo"; |
| 9468 SimpleIdentifier identifier = parse4("parseSimpleIdentifier", lexeme); | 11805 createParser(lexeme); |
| 11806 SimpleIdentifier identifier = parser.parseSimpleIdentifier(); |
| 11807 expectNotNullIfNoErrors(identifier); |
| 11808 listener.assertNoErrors(); |
| 9469 expect(identifier.token, isNotNull); | 11809 expect(identifier.token, isNotNull); |
| 9470 expect(identifier.name, lexeme); | 11810 expect(identifier.name, lexeme); |
| 9471 } | 11811 } |
| 9472 | 11812 |
| 9473 void test_parseStatement_emptyTypeArgumentList() { | 11813 void test_parseStatement_emptyTypeArgumentList() { |
| 9474 VariableDeclarationStatement statement = parse4( | 11814 createParser('C<> c;'); |
| 9475 "parseStatement", "C<> c;", [ParserErrorCode.EXPECTED_TYPE_NAME]); | 11815 Statement statement = parser.parseStatement2(); |
| 9476 VariableDeclarationList variables = statement.variables; | 11816 expectNotNullIfNoErrors(statement); |
| 11817 listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_TYPE_NAME]); |
| 11818 expect(statement, new isInstanceOf<VariableDeclarationStatement>()); |
| 11819 VariableDeclarationStatement declaration = statement; |
| 11820 VariableDeclarationList variables = declaration.variables; |
| 9477 TypeName type = variables.type; | 11821 TypeName type = variables.type; |
| 9478 TypeArgumentList argumentList = type.typeArguments; | 11822 TypeArgumentList argumentList = type.typeArguments; |
| 9479 expect(argumentList.leftBracket, isNotNull); | 11823 expect(argumentList.leftBracket, isNotNull); |
| 9480 expect(argumentList.arguments, hasLength(1)); | 11824 expect(argumentList.arguments, hasLength(1)); |
| 9481 expect(argumentList.arguments[0].isSynthetic, isTrue); | 11825 expect(argumentList.arguments[0].isSynthetic, isTrue); |
| 9482 expect(argumentList.rightBracket, isNotNull); | 11826 expect(argumentList.rightBracket, isNotNull); |
| 9483 } | 11827 } |
| 9484 | 11828 |
| 9485 void test_parseStatement_functionDeclaration_noReturnType() { | 11829 void test_parseStatement_functionDeclaration_noReturnType() { |
| 9486 FunctionDeclarationStatement statement = | 11830 createParser('f(a, b) {};'); |
| 9487 parse4("parseStatement", "f(a, b) {};"); | 11831 Statement statement = parser.parseStatement2(); |
| 9488 expect(statement.functionDeclaration, isNotNull); | 11832 expectNotNullIfNoErrors(statement); |
| 11833 listener.assertNoErrors(); |
| 11834 expect(statement, new isInstanceOf<FunctionDeclarationStatement>()); |
| 11835 FunctionDeclarationStatement declaration = statement; |
| 11836 expect(declaration.functionDeclaration, isNotNull); |
| 9489 } | 11837 } |
| 9490 | 11838 |
| 11839 void |
| 11840 test_parseStatement_functionDeclaration_noReturnType_typeParameterComments
() { |
| 11841 enableGenericMethodComments = true; |
| 11842 createParser('f/*<E>*/(a, b) {};'); |
| 11843 Statement statement = parser.parseStatement2(); |
| 11844 expectNotNullIfNoErrors(statement); |
| 11845 listener.assertNoErrors(); |
| 11846 expect(statement, new isInstanceOf<FunctionDeclarationStatement>()); |
| 11847 FunctionDeclarationStatement declaration = statement; |
| 11848 expect(declaration.functionDeclaration, isNotNull); |
| 11849 expect(declaration.functionDeclaration.functionExpression.typeParameters, |
| 11850 isNotNull); |
| 11851 } |
| 11852 |
| 11853 @failingTest |
| 9491 void test_parseStatement_functionDeclaration_noReturnType_typeParameters() { | 11854 void test_parseStatement_functionDeclaration_noReturnType_typeParameters() { |
| 9492 enableGenericMethods = true; | 11855 enableGenericMethods = true; |
| 9493 FunctionDeclarationStatement statement = | 11856 createParser('f<E>(a, b) {};'); |
| 9494 parse4("parseStatement", "f(a, b) {};"); | 11857 Statement statement = parser.parseStatement2(); |
| 9495 expect(statement.functionDeclaration, isNotNull); | 11858 expectNotNullIfNoErrors(statement); |
| 11859 listener.assertNoErrors(); |
| 11860 expect(statement, new isInstanceOf<FunctionDeclarationStatement>()); |
| 11861 FunctionDeclarationStatement declaration = statement; |
| 11862 expect(declaration.functionDeclaration, isNotNull); |
| 9496 } | 11863 } |
| 9497 | 11864 |
| 9498 void test_parseStatement_functionDeclaration_returnType() { | 11865 void test_parseStatement_functionDeclaration_returnType() { |
| 9499 // TODO(brianwilkerson) Implement more tests for this method. | 11866 // TODO(brianwilkerson) Implement more tests for this method. |
| 9500 FunctionDeclarationStatement statement = | 11867 createParser('int f(a, b) {};'); |
| 9501 parse4("parseStatement", "int f(a, b) {};"); | 11868 Statement statement = parser.parseStatement2(); |
| 9502 expect(statement.functionDeclaration, isNotNull); | 11869 expectNotNullIfNoErrors(statement); |
| 11870 listener.assertNoErrors(); |
| 11871 expect(statement, new isInstanceOf<FunctionDeclarationStatement>()); |
| 11872 FunctionDeclarationStatement declaration = statement; |
| 11873 expect(declaration.functionDeclaration, isNotNull); |
| 9503 } | 11874 } |
| 9504 | 11875 |
| 9505 void test_parseStatement_functionDeclaration_returnType_typeParameters() { | 11876 void test_parseStatement_functionDeclaration_returnType_typeParameters() { |
| 9506 enableGenericMethods = true; | 11877 enableGenericMethods = true; |
| 9507 FunctionDeclarationStatement statement = | 11878 createParser('int f<E>(a, b) {};'); |
| 9508 parse4("parseStatement", "int f<E>(a, b) {};"); | 11879 Statement statement = parser.parseStatement2(); |
| 9509 expect(statement.functionDeclaration, isNotNull); | 11880 expectNotNullIfNoErrors(statement); |
| 11881 listener.assertNoErrors(); |
| 11882 expect(statement, new isInstanceOf<FunctionDeclarationStatement>()); |
| 11883 FunctionDeclarationStatement declaration = statement; |
| 11884 expect(declaration.functionDeclaration, isNotNull); |
| 9510 } | 11885 } |
| 9511 | 11886 |
| 9512 void test_parseStatement_mulipleLabels() { | 11887 void test_parseStatement_mulipleLabels() { |
| 9513 LabeledStatement statement = parse4("parseStatement", "l: m: return x;"); | 11888 createParser('l: m: return x;'); |
| 9514 expect(statement.labels, hasLength(2)); | 11889 Statement statement = parser.parseStatement2(); |
| 9515 expect(statement.statement, isNotNull); | 11890 expectNotNullIfNoErrors(statement); |
| 11891 listener.assertNoErrors(); |
| 11892 expect(statement, new isInstanceOf<LabeledStatement>()); |
| 11893 LabeledStatement labeledStatement = statement; |
| 11894 expect(labeledStatement.labels, hasLength(2)); |
| 11895 expect(labeledStatement.statement, isNotNull); |
| 9516 } | 11896 } |
| 9517 | 11897 |
| 9518 void test_parseStatement_noLabels() { | 11898 void test_parseStatement_noLabels() { |
| 9519 parse4("parseStatement", "return x;"); | 11899 createParser('return x;'); |
| 11900 Statement statement = parser.parseStatement2(); |
| 11901 expectNotNullIfNoErrors(statement); |
| 11902 listener.assertNoErrors(); |
| 9520 } | 11903 } |
| 9521 | 11904 |
| 9522 void test_parseStatement_singleLabel() { | 11905 void test_parseStatement_singleLabel() { |
| 9523 LabeledStatement statement = parse4("parseStatement", "l: return x;"); | 11906 createParser('l: return x;'); |
| 9524 expect(statement.labels, hasLength(1)); | 11907 Statement statement = parser.parseStatement2(); |
| 9525 expect(statement.statement, isNotNull); | 11908 expectNotNullIfNoErrors(statement); |
| 11909 listener.assertNoErrors(); |
| 11910 expect(statement, new isInstanceOf<LabeledStatement>()); |
| 11911 LabeledStatement labeledStatement = statement; |
| 11912 expect(labeledStatement.labels, hasLength(1)); |
| 11913 expect(labeledStatement.labels[0].label.inDeclarationContext(), isTrue); |
| 11914 expect(labeledStatement.statement, isNotNull); |
| 9526 } | 11915 } |
| 9527 | 11916 |
| 9528 void test_parseStatements_multiple() { | 11917 void test_parseStatements_multiple() { |
| 9529 List<Statement> statements = | 11918 List<Statement> statements = |
| 9530 ParserTestCase.parseStatements("return; return;", 2); | 11919 ParserTestCase.parseStatements("return; return;", 2); |
| 9531 expect(statements, hasLength(2)); | 11920 expect(statements, hasLength(2)); |
| 9532 } | 11921 } |
| 9533 | 11922 |
| 9534 void test_parseStatements_single() { | 11923 void test_parseStatements_single() { |
| 9535 List<Statement> statements = ParserTestCase.parseStatements("return;", 1); | 11924 List<Statement> statements = ParserTestCase.parseStatements("return;", 1); |
| 9536 expect(statements, hasLength(1)); | 11925 expect(statements, hasLength(1)); |
| 9537 } | 11926 } |
| 9538 | 11927 |
| 9539 void test_parseStringLiteral_adjacent() { | 11928 void test_parseStringLiteral_adjacent() { |
| 9540 AdjacentStrings literal = parse4("parseStringLiteral", "'a' 'b'"); | 11929 createParser("'a' 'b'"); |
| 11930 Expression expression = parser.parseStringLiteral(); |
| 11931 expectNotNullIfNoErrors(expression); |
| 11932 listener.assertNoErrors(); |
| 11933 expect(expression, new isInstanceOf<AdjacentStrings>()); |
| 11934 AdjacentStrings literal = expression; |
| 9541 NodeList<StringLiteral> strings = literal.strings; | 11935 NodeList<StringLiteral> strings = literal.strings; |
| 9542 expect(strings, hasLength(2)); | 11936 expect(strings, hasLength(2)); |
| 9543 StringLiteral firstString = strings[0]; | 11937 StringLiteral firstString = strings[0]; |
| 9544 StringLiteral secondString = strings[1]; | 11938 StringLiteral secondString = strings[1]; |
| 9545 expect((firstString as SimpleStringLiteral).value, "a"); | 11939 expect((firstString as SimpleStringLiteral).value, "a"); |
| 9546 expect((secondString as SimpleStringLiteral).value, "b"); | 11940 expect((secondString as SimpleStringLiteral).value, "b"); |
| 9547 } | 11941 } |
| 9548 | 11942 |
| 9549 void test_parseStringLiteral_endsWithInterpolation() { | 11943 void test_parseStringLiteral_endsWithInterpolation() { |
| 9550 StringLiteral literal = parse4('parseStringLiteral', r"'x$y'"); | 11944 createParser(r"'x$y'"); |
| 9551 expect(literal, new isInstanceOf<StringInterpolation>()); | 11945 Expression expression = parser.parseStringLiteral(); |
| 9552 StringInterpolation interpolation = literal; | 11946 expectNotNullIfNoErrors(expression); |
| 11947 listener.assertNoErrors(); |
| 11948 expect(expression, new isInstanceOf<StringInterpolation>()); |
| 11949 StringInterpolation interpolation = expression; |
| 9553 expect(interpolation.elements, hasLength(3)); | 11950 expect(interpolation.elements, hasLength(3)); |
| 9554 expect(interpolation.elements[0], new isInstanceOf<InterpolationString>()); | 11951 expect(interpolation.elements[0], new isInstanceOf<InterpolationString>()); |
| 9555 InterpolationString element0 = interpolation.elements[0]; | 11952 InterpolationString element0 = interpolation.elements[0]; |
| 9556 expect(element0.value, 'x'); | 11953 expect(element0.value, 'x'); |
| 9557 expect( | 11954 expect( |
| 9558 interpolation.elements[1], new isInstanceOf<InterpolationExpression>()); | 11955 interpolation.elements[1], new isInstanceOf<InterpolationExpression>()); |
| 9559 InterpolationExpression element1 = interpolation.elements[1]; | 11956 InterpolationExpression element1 = interpolation.elements[1]; |
| 9560 expect(element1.expression, new isInstanceOf<SimpleIdentifier>()); | 11957 expect(element1.expression, new isInstanceOf<SimpleIdentifier>()); |
| 9561 expect(interpolation.elements[2], new isInstanceOf<InterpolationString>()); | 11958 expect(interpolation.elements[2], new isInstanceOf<InterpolationString>()); |
| 9562 InterpolationString element2 = interpolation.elements[2]; | 11959 InterpolationString element2 = interpolation.elements[2]; |
| 9563 expect(element2.value, ''); | 11960 expect(element2.value, ''); |
| 9564 } | 11961 } |
| 9565 | 11962 |
| 9566 void test_parseStringLiteral_interpolated() { | 11963 void test_parseStringLiteral_interpolated() { |
| 9567 StringInterpolation literal = | 11964 createParser("'a \${b} c \$this d'"); |
| 9568 parse4("parseStringLiteral", "'a \${b} c \$this d'"); | 11965 Expression expression = parser.parseStringLiteral(); |
| 11966 expectNotNullIfNoErrors(expression); |
| 11967 listener.assertNoErrors(); |
| 11968 expect(expression, new isInstanceOf<StringInterpolation>()); |
| 11969 StringInterpolation literal = expression; |
| 9569 NodeList<InterpolationElement> elements = literal.elements; | 11970 NodeList<InterpolationElement> elements = literal.elements; |
| 9570 expect(elements, hasLength(5)); | 11971 expect(elements, hasLength(5)); |
| 9571 expect(elements[0] is InterpolationString, isTrue); | 11972 expect(elements[0] is InterpolationString, isTrue); |
| 9572 expect(elements[1] is InterpolationExpression, isTrue); | 11973 expect(elements[1] is InterpolationExpression, isTrue); |
| 9573 expect(elements[2] is InterpolationString, isTrue); | 11974 expect(elements[2] is InterpolationString, isTrue); |
| 9574 expect(elements[3] is InterpolationExpression, isTrue); | 11975 expect(elements[3] is InterpolationExpression, isTrue); |
| 9575 expect(elements[4] is InterpolationString, isTrue); | 11976 expect(elements[4] is InterpolationString, isTrue); |
| 9576 } | 11977 } |
| 9577 | 11978 |
| 9578 void test_parseStringLiteral_multiline_encodedSpace() { | 11979 void test_parseStringLiteral_multiline_encodedSpace() { |
| 9579 SimpleStringLiteral literal = | 11980 createParser("'''\\x20\na'''"); |
| 9580 parse4("parseStringLiteral", "'''\\x20\na'''"); | 11981 Expression expression = parser.parseStringLiteral(); |
| 11982 expectNotNullIfNoErrors(expression); |
| 11983 listener.assertNoErrors(); |
| 11984 expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| 11985 SimpleStringLiteral literal = expression; |
| 9581 expect(literal.literal, isNotNull); | 11986 expect(literal.literal, isNotNull); |
| 9582 expect(literal.value, " \na"); | 11987 expect(literal.value, " \na"); |
| 9583 } | 11988 } |
| 9584 | 11989 |
| 9585 void test_parseStringLiteral_multiline_endsWithInterpolation() { | 11990 void test_parseStringLiteral_multiline_endsWithInterpolation() { |
| 9586 StringLiteral literal = parse4('parseStringLiteral', r"'''x$y'''"); | 11991 createParser(r"'''x$y'''"); |
| 9587 expect(literal, new isInstanceOf<StringInterpolation>()); | 11992 Expression expression = parser.parseStringLiteral(); |
| 9588 StringInterpolation interpolation = literal; | 11993 expectNotNullIfNoErrors(expression); |
| 11994 listener.assertNoErrors(); |
| 11995 expect(expression, new isInstanceOf<StringInterpolation>()); |
| 11996 StringInterpolation interpolation = expression; |
| 9589 expect(interpolation.elements, hasLength(3)); | 11997 expect(interpolation.elements, hasLength(3)); |
| 9590 expect(interpolation.elements[0], new isInstanceOf<InterpolationString>()); | 11998 expect(interpolation.elements[0], new isInstanceOf<InterpolationString>()); |
| 9591 InterpolationString element0 = interpolation.elements[0]; | 11999 InterpolationString element0 = interpolation.elements[0]; |
| 9592 expect(element0.value, 'x'); | 12000 expect(element0.value, 'x'); |
| 9593 expect( | 12001 expect( |
| 9594 interpolation.elements[1], new isInstanceOf<InterpolationExpression>()); | 12002 interpolation.elements[1], new isInstanceOf<InterpolationExpression>()); |
| 9595 InterpolationExpression element1 = interpolation.elements[1]; | 12003 InterpolationExpression element1 = interpolation.elements[1]; |
| 9596 expect(element1.expression, new isInstanceOf<SimpleIdentifier>()); | 12004 expect(element1.expression, new isInstanceOf<SimpleIdentifier>()); |
| 9597 expect(interpolation.elements[2], new isInstanceOf<InterpolationString>()); | 12005 expect(interpolation.elements[2], new isInstanceOf<InterpolationString>()); |
| 9598 InterpolationString element2 = interpolation.elements[2]; | 12006 InterpolationString element2 = interpolation.elements[2]; |
| 9599 expect(element2.value, ''); | 12007 expect(element2.value, ''); |
| 9600 } | 12008 } |
| 9601 | 12009 |
| 9602 void test_parseStringLiteral_multiline_escapedBackslash() { | 12010 void test_parseStringLiteral_multiline_escapedBackslash() { |
| 9603 SimpleStringLiteral literal = parse4("parseStringLiteral", "'''\\\\\na'''"); | 12011 createParser("'''\\\\\na'''"); |
| 12012 Expression expression = parser.parseStringLiteral(); |
| 12013 expectNotNullIfNoErrors(expression); |
| 12014 listener.assertNoErrors(); |
| 12015 expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| 12016 SimpleStringLiteral literal = expression; |
| 9604 expect(literal.literal, isNotNull); | 12017 expect(literal.literal, isNotNull); |
| 9605 expect(literal.value, "\\\na"); | 12018 expect(literal.value, "\\\na"); |
| 9606 } | 12019 } |
| 9607 | 12020 |
| 9608 void test_parseStringLiteral_multiline_escapedBackslash_raw() { | 12021 void test_parseStringLiteral_multiline_escapedBackslash_raw() { |
| 9609 SimpleStringLiteral literal = | 12022 createParser("r'''\\\\\na'''"); |
| 9610 parse4("parseStringLiteral", "r'''\\\\\na'''"); | 12023 Expression expression = parser.parseStringLiteral(); |
| 12024 expectNotNullIfNoErrors(expression); |
| 12025 listener.assertNoErrors(); |
| 12026 expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| 12027 SimpleStringLiteral literal = expression; |
| 9611 expect(literal.literal, isNotNull); | 12028 expect(literal.literal, isNotNull); |
| 9612 expect(literal.value, "\\\\\na"); | 12029 expect(literal.value, "\\\\\na"); |
| 9613 } | 12030 } |
| 9614 | 12031 |
| 9615 void test_parseStringLiteral_multiline_escapedEolMarker() { | 12032 void test_parseStringLiteral_multiline_escapedEolMarker() { |
| 9616 SimpleStringLiteral literal = parse4("parseStringLiteral", "'''\\\na'''"); | 12033 createParser("'''\\\na'''"); |
| 12034 Expression expression = parser.parseStringLiteral(); |
| 12035 expectNotNullIfNoErrors(expression); |
| 12036 listener.assertNoErrors(); |
| 12037 expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| 12038 SimpleStringLiteral literal = expression; |
| 9617 expect(literal.literal, isNotNull); | 12039 expect(literal.literal, isNotNull); |
| 9618 expect(literal.value, "a"); | 12040 expect(literal.value, "a"); |
| 9619 } | 12041 } |
| 9620 | 12042 |
| 9621 void test_parseStringLiteral_multiline_escapedEolMarker_raw() { | 12043 void test_parseStringLiteral_multiline_escapedEolMarker_raw() { |
| 9622 SimpleStringLiteral literal = parse4("parseStringLiteral", "r'''\\\na'''"); | 12044 createParser("r'''\\\na'''"); |
| 12045 Expression expression = parser.parseStringLiteral(); |
| 12046 expectNotNullIfNoErrors(expression); |
| 12047 listener.assertNoErrors(); |
| 12048 expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| 12049 SimpleStringLiteral literal = expression; |
| 9623 expect(literal.literal, isNotNull); | 12050 expect(literal.literal, isNotNull); |
| 9624 expect(literal.value, "a"); | 12051 expect(literal.value, "a"); |
| 9625 } | 12052 } |
| 9626 | 12053 |
| 9627 void test_parseStringLiteral_multiline_escapedSpaceAndEolMarker() { | 12054 void test_parseStringLiteral_multiline_escapedSpaceAndEolMarker() { |
| 9628 SimpleStringLiteral literal = | 12055 createParser("'''\\ \\\na'''"); |
| 9629 parse4("parseStringLiteral", "'''\\ \\\na'''"); | 12056 Expression expression = parser.parseStringLiteral(); |
| 12057 expectNotNullIfNoErrors(expression); |
| 12058 listener.assertNoErrors(); |
| 12059 expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| 12060 SimpleStringLiteral literal = expression; |
| 9630 expect(literal.literal, isNotNull); | 12061 expect(literal.literal, isNotNull); |
| 9631 expect(literal.value, "a"); | 12062 expect(literal.value, "a"); |
| 9632 } | 12063 } |
| 9633 | 12064 |
| 9634 void test_parseStringLiteral_multiline_escapedSpaceAndEolMarker_raw() { | 12065 void test_parseStringLiteral_multiline_escapedSpaceAndEolMarker_raw() { |
| 9635 SimpleStringLiteral literal = | 12066 createParser("r'''\\ \\\na'''"); |
| 9636 parse4("parseStringLiteral", "r'''\\ \\\na'''"); | 12067 Expression expression = parser.parseStringLiteral(); |
| 12068 expectNotNullIfNoErrors(expression); |
| 12069 listener.assertNoErrors(); |
| 12070 expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| 12071 SimpleStringLiteral literal = expression; |
| 9637 expect(literal.literal, isNotNull); | 12072 expect(literal.literal, isNotNull); |
| 9638 expect(literal.value, "a"); | 12073 expect(literal.value, "a"); |
| 9639 } | 12074 } |
| 9640 | 12075 |
| 9641 void test_parseStringLiteral_multiline_escapedTab() { | 12076 void test_parseStringLiteral_multiline_escapedTab() { |
| 9642 SimpleStringLiteral literal = parse4("parseStringLiteral", "'''\\t\na'''"); | 12077 createParser("'''\\t\na'''"); |
| 12078 Expression expression = parser.parseStringLiteral(); |
| 12079 expectNotNullIfNoErrors(expression); |
| 12080 listener.assertNoErrors(); |
| 12081 expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| 12082 SimpleStringLiteral literal = expression; |
| 9643 expect(literal.literal, isNotNull); | 12083 expect(literal.literal, isNotNull); |
| 9644 expect(literal.value, "\t\na"); | 12084 expect(literal.value, "\t\na"); |
| 9645 } | 12085 } |
| 9646 | 12086 |
| 9647 void test_parseStringLiteral_multiline_escapedTab_raw() { | 12087 void test_parseStringLiteral_multiline_escapedTab_raw() { |
| 9648 SimpleStringLiteral literal = parse4("parseStringLiteral", "r'''\\t\na'''"); | 12088 createParser("r'''\\t\na'''"); |
| 12089 Expression expression = parser.parseStringLiteral(); |
| 12090 expectNotNullIfNoErrors(expression); |
| 12091 listener.assertNoErrors(); |
| 12092 expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| 12093 SimpleStringLiteral literal = expression; |
| 9649 expect(literal.literal, isNotNull); | 12094 expect(literal.literal, isNotNull); |
| 9650 expect(literal.value, "\\t\na"); | 12095 expect(literal.value, "\\t\na"); |
| 9651 } | 12096 } |
| 9652 | 12097 |
| 9653 void test_parseStringLiteral_multiline_quoteAfterInterpolation() { | 12098 void test_parseStringLiteral_multiline_quoteAfterInterpolation() { |
| 9654 StringLiteral literal = parse4('parseStringLiteral', r"""'''$x'y'''"""); | 12099 createParser(r"""'''$x'y'''"""); |
| 9655 expect(literal, new isInstanceOf<StringInterpolation>()); | 12100 Expression expression = parser.parseStringLiteral(); |
| 9656 StringInterpolation interpolation = literal; | 12101 expectNotNullIfNoErrors(expression); |
| 12102 listener.assertNoErrors(); |
| 12103 expect(expression, new isInstanceOf<StringInterpolation>()); |
| 12104 StringInterpolation interpolation = expression; |
| 9657 expect(interpolation.elements, hasLength(3)); | 12105 expect(interpolation.elements, hasLength(3)); |
| 9658 expect(interpolation.elements[0], new isInstanceOf<InterpolationString>()); | 12106 expect(interpolation.elements[0], new isInstanceOf<InterpolationString>()); |
| 9659 InterpolationString element0 = interpolation.elements[0]; | 12107 InterpolationString element0 = interpolation.elements[0]; |
| 9660 expect(element0.value, ''); | 12108 expect(element0.value, ''); |
| 9661 expect( | 12109 expect( |
| 9662 interpolation.elements[1], new isInstanceOf<InterpolationExpression>()); | 12110 interpolation.elements[1], new isInstanceOf<InterpolationExpression>()); |
| 9663 InterpolationExpression element1 = interpolation.elements[1]; | 12111 InterpolationExpression element1 = interpolation.elements[1]; |
| 9664 expect(element1.expression, new isInstanceOf<SimpleIdentifier>()); | 12112 expect(element1.expression, new isInstanceOf<SimpleIdentifier>()); |
| 9665 expect(interpolation.elements[2], new isInstanceOf<InterpolationString>()); | 12113 expect(interpolation.elements[2], new isInstanceOf<InterpolationString>()); |
| 9666 InterpolationString element2 = interpolation.elements[2]; | 12114 InterpolationString element2 = interpolation.elements[2]; |
| 9667 expect(element2.value, "'y"); | 12115 expect(element2.value, "'y"); |
| 9668 } | 12116 } |
| 9669 | 12117 |
| 9670 void test_parseStringLiteral_multiline_startsWithInterpolation() { | 12118 void test_parseStringLiteral_multiline_startsWithInterpolation() { |
| 9671 StringLiteral literal = parse4('parseStringLiteral', r"'''${x}y'''"); | 12119 createParser(r"'''${x}y'''"); |
| 9672 expect(literal, new isInstanceOf<StringInterpolation>()); | 12120 Expression expression = parser.parseStringLiteral(); |
| 9673 StringInterpolation interpolation = literal; | 12121 expectNotNullIfNoErrors(expression); |
| 12122 listener.assertNoErrors(); |
| 12123 expect(expression, new isInstanceOf<StringInterpolation>()); |
| 12124 StringInterpolation interpolation = expression; |
| 9674 expect(interpolation.elements, hasLength(3)); | 12125 expect(interpolation.elements, hasLength(3)); |
| 9675 expect(interpolation.elements[0], new isInstanceOf<InterpolationString>()); | 12126 expect(interpolation.elements[0], new isInstanceOf<InterpolationString>()); |
| 9676 InterpolationString element0 = interpolation.elements[0]; | 12127 InterpolationString element0 = interpolation.elements[0]; |
| 9677 expect(element0.value, ''); | 12128 expect(element0.value, ''); |
| 9678 expect( | 12129 expect( |
| 9679 interpolation.elements[1], new isInstanceOf<InterpolationExpression>()); | 12130 interpolation.elements[1], new isInstanceOf<InterpolationExpression>()); |
| 9680 InterpolationExpression element1 = interpolation.elements[1]; | 12131 InterpolationExpression element1 = interpolation.elements[1]; |
| 9681 expect(element1.expression, new isInstanceOf<SimpleIdentifier>()); | 12132 expect(element1.expression, new isInstanceOf<SimpleIdentifier>()); |
| 9682 expect(interpolation.elements[2], new isInstanceOf<InterpolationString>()); | 12133 expect(interpolation.elements[2], new isInstanceOf<InterpolationString>()); |
| 9683 InterpolationString element2 = interpolation.elements[2]; | 12134 InterpolationString element2 = interpolation.elements[2]; |
| 9684 expect(element2.value, 'y'); | 12135 expect(element2.value, 'y'); |
| 9685 } | 12136 } |
| 9686 | 12137 |
| 9687 void test_parseStringLiteral_multiline_twoSpaces() { | 12138 void test_parseStringLiteral_multiline_twoSpaces() { |
| 9688 SimpleStringLiteral literal = parse4("parseStringLiteral", "''' \na'''"); | 12139 createParser("''' \na'''"); |
| 12140 Expression expression = parser.parseStringLiteral(); |
| 12141 expectNotNullIfNoErrors(expression); |
| 12142 listener.assertNoErrors(); |
| 12143 expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| 12144 SimpleStringLiteral literal = expression; |
| 9689 expect(literal.literal, isNotNull); | 12145 expect(literal.literal, isNotNull); |
| 9690 expect(literal.value, "a"); | 12146 expect(literal.value, "a"); |
| 9691 } | 12147 } |
| 9692 | 12148 |
| 9693 void test_parseStringLiteral_multiline_twoSpaces_raw() { | 12149 void test_parseStringLiteral_multiline_twoSpaces_raw() { |
| 9694 SimpleStringLiteral literal = parse4("parseStringLiteral", "r''' \na'''"); | 12150 createParser("r''' \na'''"); |
| 12151 Expression expression = parser.parseStringLiteral(); |
| 12152 expectNotNullIfNoErrors(expression); |
| 12153 listener.assertNoErrors(); |
| 12154 expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| 12155 SimpleStringLiteral literal = expression; |
| 9695 expect(literal.literal, isNotNull); | 12156 expect(literal.literal, isNotNull); |
| 9696 expect(literal.value, "a"); | 12157 expect(literal.value, "a"); |
| 9697 } | 12158 } |
| 9698 | 12159 |
| 9699 void test_parseStringLiteral_multiline_untrimmed() { | 12160 void test_parseStringLiteral_multiline_untrimmed() { |
| 9700 SimpleStringLiteral literal = parse4("parseStringLiteral", "''' a\nb'''"); | 12161 createParser("''' a\nb'''"); |
| 12162 Expression expression = parser.parseStringLiteral(); |
| 12163 expectNotNullIfNoErrors(expression); |
| 12164 listener.assertNoErrors(); |
| 12165 expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| 12166 SimpleStringLiteral literal = expression; |
| 9701 expect(literal.literal, isNotNull); | 12167 expect(literal.literal, isNotNull); |
| 9702 expect(literal.value, " a\nb"); | 12168 expect(literal.value, " a\nb"); |
| 9703 } | 12169 } |
| 9704 | 12170 |
| 9705 void test_parseStringLiteral_quoteAfterInterpolation() { | 12171 void test_parseStringLiteral_quoteAfterInterpolation() { |
| 9706 StringLiteral literal = parse4('parseStringLiteral', r"""'$x"'"""); | 12172 createParser(r"""'$x"'"""); |
| 9707 expect(literal, new isInstanceOf<StringInterpolation>()); | 12173 Expression expression = parser.parseStringLiteral(); |
| 9708 StringInterpolation interpolation = literal; | 12174 expectNotNullIfNoErrors(expression); |
| 12175 listener.assertNoErrors(); |
| 12176 expect(expression, new isInstanceOf<StringInterpolation>()); |
| 12177 StringInterpolation interpolation = expression; |
| 9709 expect(interpolation.elements, hasLength(3)); | 12178 expect(interpolation.elements, hasLength(3)); |
| 9710 expect(interpolation.elements[0], new isInstanceOf<InterpolationString>()); | 12179 expect(interpolation.elements[0], new isInstanceOf<InterpolationString>()); |
| 9711 InterpolationString element0 = interpolation.elements[0]; | 12180 InterpolationString element0 = interpolation.elements[0]; |
| 9712 expect(element0.value, ''); | 12181 expect(element0.value, ''); |
| 9713 expect( | 12182 expect( |
| 9714 interpolation.elements[1], new isInstanceOf<InterpolationExpression>()); | 12183 interpolation.elements[1], new isInstanceOf<InterpolationExpression>()); |
| 9715 InterpolationExpression element1 = interpolation.elements[1]; | 12184 InterpolationExpression element1 = interpolation.elements[1]; |
| 9716 expect(element1.expression, new isInstanceOf<SimpleIdentifier>()); | 12185 expect(element1.expression, new isInstanceOf<SimpleIdentifier>()); |
| 9717 expect(interpolation.elements[2], new isInstanceOf<InterpolationString>()); | 12186 expect(interpolation.elements[2], new isInstanceOf<InterpolationString>()); |
| 9718 InterpolationString element2 = interpolation.elements[2]; | 12187 InterpolationString element2 = interpolation.elements[2]; |
| 9719 expect(element2.value, '"'); | 12188 expect(element2.value, '"'); |
| 9720 } | 12189 } |
| 9721 | 12190 |
| 9722 void test_parseStringLiteral_single() { | 12191 void test_parseStringLiteral_single() { |
| 9723 SimpleStringLiteral literal = parse4("parseStringLiteral", "'a'"); | 12192 createParser("'a'"); |
| 12193 Expression expression = parser.parseStringLiteral(); |
| 12194 expectNotNullIfNoErrors(expression); |
| 12195 listener.assertNoErrors(); |
| 12196 expect(expression, new isInstanceOf<SimpleStringLiteral>()); |
| 12197 SimpleStringLiteral literal = expression; |
| 9724 expect(literal.literal, isNotNull); | 12198 expect(literal.literal, isNotNull); |
| 9725 expect(literal.value, "a"); | 12199 expect(literal.value, "a"); |
| 9726 } | 12200 } |
| 9727 | 12201 |
| 9728 void test_parseStringLiteral_startsWithInterpolation() { | 12202 void test_parseStringLiteral_startsWithInterpolation() { |
| 9729 StringLiteral literal = parse4('parseStringLiteral', r"'${x}y'"); | 12203 createParser(r"'${x}y'"); |
| 9730 expect(literal, new isInstanceOf<StringInterpolation>()); | 12204 Expression expression = parser.parseStringLiteral(); |
| 9731 StringInterpolation interpolation = literal; | 12205 expectNotNullIfNoErrors(expression); |
| 12206 listener.assertNoErrors(); |
| 12207 expect(expression, new isInstanceOf<StringInterpolation>()); |
| 12208 StringInterpolation interpolation = expression; |
| 9732 expect(interpolation.elements, hasLength(3)); | 12209 expect(interpolation.elements, hasLength(3)); |
| 9733 expect(interpolation.elements[0], new isInstanceOf<InterpolationString>()); | 12210 expect(interpolation.elements[0], new isInstanceOf<InterpolationString>()); |
| 9734 InterpolationString element0 = interpolation.elements[0]; | 12211 InterpolationString element0 = interpolation.elements[0]; |
| 9735 expect(element0.value, ''); | 12212 expect(element0.value, ''); |
| 9736 expect( | 12213 expect( |
| 9737 interpolation.elements[1], new isInstanceOf<InterpolationExpression>()); | 12214 interpolation.elements[1], new isInstanceOf<InterpolationExpression>()); |
| 9738 InterpolationExpression element1 = interpolation.elements[1]; | 12215 InterpolationExpression element1 = interpolation.elements[1]; |
| 9739 expect(element1.expression, new isInstanceOf<SimpleIdentifier>()); | 12216 expect(element1.expression, new isInstanceOf<SimpleIdentifier>()); |
| 9740 expect(interpolation.elements[2], new isInstanceOf<InterpolationString>()); | 12217 expect(interpolation.elements[2], new isInstanceOf<InterpolationString>()); |
| 9741 InterpolationString element2 = interpolation.elements[2]; | 12218 InterpolationString element2 = interpolation.elements[2]; |
| 9742 expect(element2.value, 'y'); | 12219 expect(element2.value, 'y'); |
| 9743 } | 12220 } |
| 9744 | 12221 |
| 9745 void test_parseSuperConstructorInvocation_named() { | 12222 void test_parseSuperConstructorInvocation_named() { |
| 12223 createParser('super.a()'); |
| 9746 SuperConstructorInvocation invocation = | 12224 SuperConstructorInvocation invocation = |
| 9747 parse4("parseSuperConstructorInvocation", "super.a()"); | 12225 parser.parseSuperConstructorInvocation(); |
| 12226 expectNotNullIfNoErrors(invocation); |
| 12227 listener.assertNoErrors(); |
| 9748 expect(invocation.argumentList, isNotNull); | 12228 expect(invocation.argumentList, isNotNull); |
| 9749 expect(invocation.constructorName, isNotNull); | 12229 expect(invocation.constructorName, isNotNull); |
| 9750 expect(invocation.superKeyword, isNotNull); | 12230 expect(invocation.superKeyword, isNotNull); |
| 9751 expect(invocation.period, isNotNull); | 12231 expect(invocation.period, isNotNull); |
| 9752 } | 12232 } |
| 9753 | 12233 |
| 9754 void test_parseSuperConstructorInvocation_unnamed() { | 12234 void test_parseSuperConstructorInvocation_unnamed() { |
| 12235 createParser('super()'); |
| 9755 SuperConstructorInvocation invocation = | 12236 SuperConstructorInvocation invocation = |
| 9756 parse4("parseSuperConstructorInvocation", "super()"); | 12237 parser.parseSuperConstructorInvocation(); |
| 12238 expectNotNullIfNoErrors(invocation); |
| 12239 listener.assertNoErrors(); |
| 9757 expect(invocation.argumentList, isNotNull); | 12240 expect(invocation.argumentList, isNotNull); |
| 9758 expect(invocation.constructorName, isNull); | 12241 expect(invocation.constructorName, isNull); |
| 9759 expect(invocation.superKeyword, isNotNull); | 12242 expect(invocation.superKeyword, isNotNull); |
| 9760 expect(invocation.period, isNull); | 12243 expect(invocation.period, isNull); |
| 9761 } | 12244 } |
| 9762 | 12245 |
| 9763 void test_parseSwitchStatement_case() { | 12246 void test_parseSwitchStatement_case() { |
| 9764 SwitchStatement statement = | 12247 createParser('switch (a) {case 1: return "I";}'); |
| 9765 parse4("parseSwitchStatement", "switch (a) {case 1: return 'I';}"); | 12248 SwitchStatement statement = parser.parseSwitchStatement(); |
| 12249 expectNotNullIfNoErrors(statement); |
| 12250 listener.assertNoErrors(); |
| 9766 expect(statement.switchKeyword, isNotNull); | 12251 expect(statement.switchKeyword, isNotNull); |
| 9767 expect(statement.leftParenthesis, isNotNull); | 12252 expect(statement.leftParenthesis, isNotNull); |
| 9768 expect(statement.expression, isNotNull); | 12253 expect(statement.expression, isNotNull); |
| 9769 expect(statement.rightParenthesis, isNotNull); | 12254 expect(statement.rightParenthesis, isNotNull); |
| 9770 expect(statement.leftBracket, isNotNull); | 12255 expect(statement.leftBracket, isNotNull); |
| 9771 expect(statement.members, hasLength(1)); | 12256 expect(statement.members, hasLength(1)); |
| 9772 expect(statement.rightBracket, isNotNull); | 12257 expect(statement.rightBracket, isNotNull); |
| 9773 } | 12258 } |
| 9774 | 12259 |
| 9775 void test_parseSwitchStatement_empty() { | 12260 void test_parseSwitchStatement_empty() { |
| 9776 SwitchStatement statement = parse4("parseSwitchStatement", "switch (a) {}"); | 12261 createParser('switch (a) {}'); |
| 12262 SwitchStatement statement = parser.parseSwitchStatement(); |
| 12263 expectNotNullIfNoErrors(statement); |
| 12264 listener.assertNoErrors(); |
| 9777 expect(statement.switchKeyword, isNotNull); | 12265 expect(statement.switchKeyword, isNotNull); |
| 9778 expect(statement.leftParenthesis, isNotNull); | 12266 expect(statement.leftParenthesis, isNotNull); |
| 9779 expect(statement.expression, isNotNull); | 12267 expect(statement.expression, isNotNull); |
| 9780 expect(statement.rightParenthesis, isNotNull); | 12268 expect(statement.rightParenthesis, isNotNull); |
| 9781 expect(statement.leftBracket, isNotNull); | 12269 expect(statement.leftBracket, isNotNull); |
| 9782 expect(statement.members, hasLength(0)); | 12270 expect(statement.members, hasLength(0)); |
| 9783 expect(statement.rightBracket, isNotNull); | 12271 expect(statement.rightBracket, isNotNull); |
| 9784 } | 12272 } |
| 9785 | 12273 |
| 9786 void test_parseSwitchStatement_labeledCase() { | 12274 void test_parseSwitchStatement_labeledCase() { |
| 9787 SwitchStatement statement = | 12275 createParser('switch (a) {l1: l2: l3: case(1):}'); |
| 9788 parse4("parseSwitchStatement", "switch (a) {l1: l2: l3: case(1):}"); | 12276 SwitchStatement statement = parser.parseSwitchStatement(); |
| 12277 expectNotNullIfNoErrors(statement); |
| 12278 listener.assertNoErrors(); |
| 9789 expect(statement.switchKeyword, isNotNull); | 12279 expect(statement.switchKeyword, isNotNull); |
| 9790 expect(statement.leftParenthesis, isNotNull); | 12280 expect(statement.leftParenthesis, isNotNull); |
| 9791 expect(statement.expression, isNotNull); | 12281 expect(statement.expression, isNotNull); |
| 9792 expect(statement.rightParenthesis, isNotNull); | 12282 expect(statement.rightParenthesis, isNotNull); |
| 9793 expect(statement.leftBracket, isNotNull); | 12283 expect(statement.leftBracket, isNotNull); |
| 9794 expect(statement.members, hasLength(1)); | 12284 expect(statement.members, hasLength(1)); |
| 9795 expect(statement.members[0].labels, hasLength(3)); | 12285 { |
| 12286 List<Label> labels = statement.members[0].labels; |
| 12287 expect(labels, hasLength(3)); |
| 12288 expect(labels[0].label.inDeclarationContext(), isTrue); |
| 12289 expect(labels[1].label.inDeclarationContext(), isTrue); |
| 12290 expect(labels[2].label.inDeclarationContext(), isTrue); |
| 12291 } |
| 12292 expect(statement.rightBracket, isNotNull); |
| 12293 } |
| 12294 |
| 12295 void test_parseSwitchStatement_labeledDefault() { |
| 12296 createParser('switch (a) {l1: l2: l3: default:}'); |
| 12297 SwitchStatement statement = parser.parseSwitchStatement(); |
| 12298 expectNotNullIfNoErrors(statement); |
| 12299 listener.assertNoErrors(); |
| 12300 expect(statement.switchKeyword, isNotNull); |
| 12301 expect(statement.leftParenthesis, isNotNull); |
| 12302 expect(statement.expression, isNotNull); |
| 12303 expect(statement.rightParenthesis, isNotNull); |
| 12304 expect(statement.leftBracket, isNotNull); |
| 12305 expect(statement.members, hasLength(1)); |
| 12306 { |
| 12307 List<Label> labels = statement.members[0].labels; |
| 12308 expect(labels, hasLength(3)); |
| 12309 expect(labels[0].label.inDeclarationContext(), isTrue); |
| 12310 expect(labels[1].label.inDeclarationContext(), isTrue); |
| 12311 expect(labels[2].label.inDeclarationContext(), isTrue); |
| 12312 } |
| 9796 expect(statement.rightBracket, isNotNull); | 12313 expect(statement.rightBracket, isNotNull); |
| 9797 } | 12314 } |
| 9798 | 12315 |
| 9799 void test_parseSwitchStatement_labeledStatementInCase() { | 12316 void test_parseSwitchStatement_labeledStatementInCase() { |
| 9800 SwitchStatement statement = parse4( | 12317 createParser('switch (a) {case 0: f(); l1: g(); break;}'); |
| 9801 "parseSwitchStatement", "switch (a) {case 0: f(); l1: g(); break;}"); | 12318 SwitchStatement statement = parser.parseSwitchStatement(); |
| 12319 expectNotNullIfNoErrors(statement); |
| 12320 listener.assertNoErrors(); |
| 9802 expect(statement.switchKeyword, isNotNull); | 12321 expect(statement.switchKeyword, isNotNull); |
| 9803 expect(statement.leftParenthesis, isNotNull); | 12322 expect(statement.leftParenthesis, isNotNull); |
| 9804 expect(statement.expression, isNotNull); | 12323 expect(statement.expression, isNotNull); |
| 9805 expect(statement.rightParenthesis, isNotNull); | 12324 expect(statement.rightParenthesis, isNotNull); |
| 9806 expect(statement.leftBracket, isNotNull); | 12325 expect(statement.leftBracket, isNotNull); |
| 9807 expect(statement.members, hasLength(1)); | 12326 expect(statement.members, hasLength(1)); |
| 9808 expect(statement.members[0].statements, hasLength(3)); | 12327 expect(statement.members[0].statements, hasLength(3)); |
| 9809 expect(statement.rightBracket, isNotNull); | 12328 expect(statement.rightBracket, isNotNull); |
| 9810 } | 12329 } |
| 9811 | 12330 |
| 9812 void test_parseSymbolLiteral_builtInIdentifier() { | 12331 void test_parseSymbolLiteral_builtInIdentifier() { |
| 9813 SymbolLiteral literal = | 12332 createParser('#dynamic.static.abstract'); |
| 9814 parse4("parseSymbolLiteral", "#dynamic.static.abstract"); | 12333 SymbolLiteral literal = parser.parseSymbolLiteral(); |
| 12334 expectNotNullIfNoErrors(literal); |
| 12335 listener.assertNoErrors(); |
| 9815 expect(literal.poundSign, isNotNull); | 12336 expect(literal.poundSign, isNotNull); |
| 9816 List<Token> components = literal.components; | 12337 List<Token> components = literal.components; |
| 9817 expect(components, hasLength(3)); | 12338 expect(components, hasLength(3)); |
| 9818 expect(components[0].lexeme, "dynamic"); | 12339 expect(components[0].lexeme, "dynamic"); |
| 9819 expect(components[1].lexeme, "static"); | 12340 expect(components[1].lexeme, "static"); |
| 9820 expect(components[2].lexeme, "abstract"); | 12341 expect(components[2].lexeme, "abstract"); |
| 9821 } | 12342 } |
| 9822 | 12343 |
| 9823 void test_parseSymbolLiteral_multiple() { | 12344 void test_parseSymbolLiteral_multiple() { |
| 9824 SymbolLiteral literal = parse4("parseSymbolLiteral", "#a.b.c"); | 12345 createParser('#a.b.c'); |
| 12346 SymbolLiteral literal = parser.parseSymbolLiteral(); |
| 12347 expectNotNullIfNoErrors(literal); |
| 12348 listener.assertNoErrors(); |
| 9825 expect(literal.poundSign, isNotNull); | 12349 expect(literal.poundSign, isNotNull); |
| 9826 List<Token> components = literal.components; | 12350 List<Token> components = literal.components; |
| 9827 expect(components, hasLength(3)); | 12351 expect(components, hasLength(3)); |
| 9828 expect(components[0].lexeme, "a"); | 12352 expect(components[0].lexeme, "a"); |
| 9829 expect(components[1].lexeme, "b"); | 12353 expect(components[1].lexeme, "b"); |
| 9830 expect(components[2].lexeme, "c"); | 12354 expect(components[2].lexeme, "c"); |
| 9831 } | 12355 } |
| 9832 | 12356 |
| 9833 void test_parseSymbolLiteral_operator() { | 12357 void test_parseSymbolLiteral_operator() { |
| 9834 SymbolLiteral literal = parse4("parseSymbolLiteral", "#=="); | 12358 createParser('#=='); |
| 12359 SymbolLiteral literal = parser.parseSymbolLiteral(); |
| 12360 expectNotNullIfNoErrors(literal); |
| 12361 listener.assertNoErrors(); |
| 9835 expect(literal.poundSign, isNotNull); | 12362 expect(literal.poundSign, isNotNull); |
| 9836 List<Token> components = literal.components; | 12363 List<Token> components = literal.components; |
| 9837 expect(components, hasLength(1)); | 12364 expect(components, hasLength(1)); |
| 9838 expect(components[0].lexeme, "=="); | 12365 expect(components[0].lexeme, "=="); |
| 9839 } | 12366 } |
| 9840 | 12367 |
| 9841 void test_parseSymbolLiteral_single() { | 12368 void test_parseSymbolLiteral_single() { |
| 9842 SymbolLiteral literal = parse4("parseSymbolLiteral", "#a"); | 12369 createParser('#a'); |
| 12370 SymbolLiteral literal = parser.parseSymbolLiteral(); |
| 12371 expectNotNullIfNoErrors(literal); |
| 12372 listener.assertNoErrors(); |
| 9843 expect(literal.poundSign, isNotNull); | 12373 expect(literal.poundSign, isNotNull); |
| 9844 List<Token> components = literal.components; | 12374 List<Token> components = literal.components; |
| 9845 expect(components, hasLength(1)); | 12375 expect(components, hasLength(1)); |
| 9846 expect(components[0].lexeme, "a"); | 12376 expect(components[0].lexeme, "a"); |
| 9847 } | 12377 } |
| 9848 | 12378 |
| 9849 void test_parseSymbolLiteral_void() { | 12379 void test_parseSymbolLiteral_void() { |
| 9850 SymbolLiteral literal = parse4("parseSymbolLiteral", "#void"); | 12380 createParser('#void'); |
| 12381 SymbolLiteral literal = parser.parseSymbolLiteral(); |
| 12382 expectNotNullIfNoErrors(literal); |
| 12383 listener.assertNoErrors(); |
| 9851 expect(literal.poundSign, isNotNull); | 12384 expect(literal.poundSign, isNotNull); |
| 9852 List<Token> components = literal.components; | 12385 List<Token> components = literal.components; |
| 9853 expect(components, hasLength(1)); | 12386 expect(components, hasLength(1)); |
| 9854 expect(components[0].lexeme, "void"); | 12387 expect(components[0].lexeme, "void"); |
| 9855 } | 12388 } |
| 9856 | 12389 |
| 9857 void test_parseThrowExpression() { | 12390 void test_parseThrowExpression() { |
| 9858 ThrowExpression expression = parse4("parseThrowExpression", "throw x;"); | 12391 createParser('throw x;'); |
| 9859 expect(expression.throwKeyword, isNotNull); | 12392 Expression expression = parser.parseThrowExpression(); |
| 9860 expect(expression.expression, isNotNull); | 12393 expectNotNullIfNoErrors(expression); |
| 12394 listener.assertNoErrors(); |
| 12395 expect(expression, new isInstanceOf<ThrowExpression>()); |
| 12396 ThrowExpression throwExpression = expression; |
| 12397 expect(throwExpression.throwKeyword, isNotNull); |
| 12398 expect(throwExpression.expression, isNotNull); |
| 9861 } | 12399 } |
| 9862 | 12400 |
| 9863 void test_parseThrowExpressionWithoutCascade() { | 12401 void test_parseThrowExpressionWithoutCascade() { |
| 9864 ThrowExpression expression = | 12402 createParser('throw x;'); |
| 9865 parse4("parseThrowExpressionWithoutCascade", "throw x;"); | 12403 Expression expression = parser.parseThrowExpressionWithoutCascade(); |
| 9866 expect(expression.throwKeyword, isNotNull); | 12404 expectNotNullIfNoErrors(expression); |
| 9867 expect(expression.expression, isNotNull); | 12405 listener.assertNoErrors(); |
| 12406 expect(expression, new isInstanceOf<ThrowExpression>()); |
| 12407 ThrowExpression throwExpression = expression; |
| 12408 expect(throwExpression.throwKeyword, isNotNull); |
| 12409 expect(throwExpression.expression, isNotNull); |
| 9868 } | 12410 } |
| 9869 | 12411 |
| 9870 void test_parseTryStatement_catch() { | 12412 void test_parseTryStatement_catch() { |
| 9871 TryStatement statement = parse4("parseTryStatement", "try {} catch (e) {}"); | 12413 createParser('try {} catch (e) {}'); |
| 12414 TryStatement statement = parser.parseTryStatement(); |
| 12415 expectNotNullIfNoErrors(statement); |
| 12416 listener.assertNoErrors(); |
| 9872 expect(statement.tryKeyword, isNotNull); | 12417 expect(statement.tryKeyword, isNotNull); |
| 9873 expect(statement.body, isNotNull); | 12418 expect(statement.body, isNotNull); |
| 9874 NodeList<CatchClause> catchClauses = statement.catchClauses; | 12419 NodeList<CatchClause> catchClauses = statement.catchClauses; |
| 9875 expect(catchClauses, hasLength(1)); | 12420 expect(catchClauses, hasLength(1)); |
| 9876 CatchClause clause = catchClauses[0]; | 12421 CatchClause clause = catchClauses[0]; |
| 9877 expect(clause.onKeyword, isNull); | 12422 expect(clause.onKeyword, isNull); |
| 9878 expect(clause.exceptionType, isNull); | 12423 expect(clause.exceptionType, isNull); |
| 9879 expect(clause.catchKeyword, isNotNull); | 12424 expect(clause.catchKeyword, isNotNull); |
| 9880 expect(clause.exceptionParameter, isNotNull); | 12425 expect(clause.exceptionParameter, isNotNull); |
| 9881 expect(clause.comma, isNull); | 12426 expect(clause.comma, isNull); |
| 9882 expect(clause.stackTraceParameter, isNull); | 12427 expect(clause.stackTraceParameter, isNull); |
| 9883 expect(clause.body, isNotNull); | 12428 expect(clause.body, isNotNull); |
| 9884 expect(statement.finallyKeyword, isNull); | 12429 expect(statement.finallyKeyword, isNull); |
| 9885 expect(statement.finallyBlock, isNull); | 12430 expect(statement.finallyBlock, isNull); |
| 9886 } | 12431 } |
| 9887 | 12432 |
| 9888 void test_parseTryStatement_catch_finally() { | 12433 void test_parseTryStatement_catch_finally() { |
| 9889 TryStatement statement = | 12434 createParser('try {} catch (e, s) {} finally {}'); |
| 9890 parse4("parseTryStatement", "try {} catch (e, s) {} finally {}"); | 12435 TryStatement statement = parser.parseTryStatement(); |
| 12436 expectNotNullIfNoErrors(statement); |
| 12437 listener.assertNoErrors(); |
| 9891 expect(statement.tryKeyword, isNotNull); | 12438 expect(statement.tryKeyword, isNotNull); |
| 9892 expect(statement.body, isNotNull); | 12439 expect(statement.body, isNotNull); |
| 9893 NodeList<CatchClause> catchClauses = statement.catchClauses; | 12440 NodeList<CatchClause> catchClauses = statement.catchClauses; |
| 9894 expect(catchClauses, hasLength(1)); | 12441 expect(catchClauses, hasLength(1)); |
| 9895 CatchClause clause = catchClauses[0]; | 12442 CatchClause clause = catchClauses[0]; |
| 9896 expect(clause.onKeyword, isNull); | 12443 expect(clause.onKeyword, isNull); |
| 9897 expect(clause.exceptionType, isNull); | 12444 expect(clause.exceptionType, isNull); |
| 9898 expect(clause.catchKeyword, isNotNull); | 12445 expect(clause.catchKeyword, isNotNull); |
| 9899 expect(clause.exceptionParameter, isNotNull); | 12446 expect(clause.exceptionParameter, isNotNull); |
| 9900 expect(clause.comma, isNotNull); | 12447 expect(clause.comma, isNotNull); |
| 9901 expect(clause.stackTraceParameter, isNotNull); | 12448 expect(clause.stackTraceParameter, isNotNull); |
| 9902 expect(clause.body, isNotNull); | 12449 expect(clause.body, isNotNull); |
| 9903 expect(statement.finallyKeyword, isNotNull); | 12450 expect(statement.finallyKeyword, isNotNull); |
| 9904 expect(statement.finallyBlock, isNotNull); | 12451 expect(statement.finallyBlock, isNotNull); |
| 9905 } | 12452 } |
| 9906 | 12453 |
| 9907 void test_parseTryStatement_finally() { | 12454 void test_parseTryStatement_finally() { |
| 9908 TryStatement statement = parse4("parseTryStatement", "try {} finally {}"); | 12455 createParser('try {} finally {}'); |
| 12456 TryStatement statement = parser.parseTryStatement(); |
| 12457 expectNotNullIfNoErrors(statement); |
| 12458 listener.assertNoErrors(); |
| 9909 expect(statement.tryKeyword, isNotNull); | 12459 expect(statement.tryKeyword, isNotNull); |
| 9910 expect(statement.body, isNotNull); | 12460 expect(statement.body, isNotNull); |
| 9911 expect(statement.catchClauses, hasLength(0)); | 12461 expect(statement.catchClauses, hasLength(0)); |
| 9912 expect(statement.finallyKeyword, isNotNull); | 12462 expect(statement.finallyKeyword, isNotNull); |
| 9913 expect(statement.finallyBlock, isNotNull); | 12463 expect(statement.finallyBlock, isNotNull); |
| 9914 } | 12464 } |
| 9915 | 12465 |
| 9916 void test_parseTryStatement_multiple() { | 12466 void test_parseTryStatement_multiple() { |
| 9917 TryStatement statement = parse4("parseTryStatement", | 12467 createParser('try {} on NPE catch (e) {} on Error {} catch (e) {}'); |
| 9918 "try {} on NPE catch (e) {} on Error {} catch (e) {}"); | 12468 TryStatement statement = parser.parseTryStatement(); |
| 12469 expectNotNullIfNoErrors(statement); |
| 12470 listener.assertNoErrors(); |
| 9919 expect(statement.tryKeyword, isNotNull); | 12471 expect(statement.tryKeyword, isNotNull); |
| 9920 expect(statement.body, isNotNull); | 12472 expect(statement.body, isNotNull); |
| 9921 expect(statement.catchClauses, hasLength(3)); | 12473 expect(statement.catchClauses, hasLength(3)); |
| 9922 expect(statement.finallyKeyword, isNull); | 12474 expect(statement.finallyKeyword, isNull); |
| 9923 expect(statement.finallyBlock, isNull); | 12475 expect(statement.finallyBlock, isNull); |
| 9924 } | 12476 } |
| 9925 | 12477 |
| 9926 void test_parseTryStatement_on() { | 12478 void test_parseTryStatement_on() { |
| 9927 TryStatement statement = parse4("parseTryStatement", "try {} on Error {}"); | 12479 createParser('try {} on Error {}'); |
| 12480 TryStatement statement = parser.parseTryStatement(); |
| 12481 expectNotNullIfNoErrors(statement); |
| 12482 listener.assertNoErrors(); |
| 9928 expect(statement.tryKeyword, isNotNull); | 12483 expect(statement.tryKeyword, isNotNull); |
| 9929 expect(statement.body, isNotNull); | 12484 expect(statement.body, isNotNull); |
| 9930 NodeList<CatchClause> catchClauses = statement.catchClauses; | 12485 NodeList<CatchClause> catchClauses = statement.catchClauses; |
| 9931 expect(catchClauses, hasLength(1)); | 12486 expect(catchClauses, hasLength(1)); |
| 9932 CatchClause clause = catchClauses[0]; | 12487 CatchClause clause = catchClauses[0]; |
| 9933 expect(clause.onKeyword, isNotNull); | 12488 expect(clause.onKeyword, isNotNull); |
| 9934 expect(clause.exceptionType, isNotNull); | 12489 expect(clause.exceptionType, isNotNull); |
| 9935 expect(clause.catchKeyword, isNull); | 12490 expect(clause.catchKeyword, isNull); |
| 9936 expect(clause.exceptionParameter, isNull); | 12491 expect(clause.exceptionParameter, isNull); |
| 9937 expect(clause.comma, isNull); | 12492 expect(clause.comma, isNull); |
| 9938 expect(clause.stackTraceParameter, isNull); | 12493 expect(clause.stackTraceParameter, isNull); |
| 9939 expect(clause.body, isNotNull); | 12494 expect(clause.body, isNotNull); |
| 9940 expect(statement.finallyKeyword, isNull); | 12495 expect(statement.finallyKeyword, isNull); |
| 9941 expect(statement.finallyBlock, isNull); | 12496 expect(statement.finallyBlock, isNull); |
| 9942 } | 12497 } |
| 9943 | 12498 |
| 9944 void test_parseTryStatement_on_catch() { | 12499 void test_parseTryStatement_on_catch() { |
| 9945 TryStatement statement = | 12500 createParser('try {} on Error catch (e, s) {}'); |
| 9946 parse4("parseTryStatement", "try {} on Error catch (e, s) {}"); | 12501 TryStatement statement = parser.parseTryStatement(); |
| 12502 expectNotNullIfNoErrors(statement); |
| 12503 listener.assertNoErrors(); |
| 9947 expect(statement.tryKeyword, isNotNull); | 12504 expect(statement.tryKeyword, isNotNull); |
| 9948 expect(statement.body, isNotNull); | 12505 expect(statement.body, isNotNull); |
| 9949 NodeList<CatchClause> catchClauses = statement.catchClauses; | 12506 NodeList<CatchClause> catchClauses = statement.catchClauses; |
| 9950 expect(catchClauses, hasLength(1)); | 12507 expect(catchClauses, hasLength(1)); |
| 9951 CatchClause clause = catchClauses[0]; | 12508 CatchClause clause = catchClauses[0]; |
| 9952 expect(clause.onKeyword, isNotNull); | 12509 expect(clause.onKeyword, isNotNull); |
| 9953 expect(clause.exceptionType, isNotNull); | 12510 expect(clause.exceptionType, isNotNull); |
| 9954 expect(clause.catchKeyword, isNotNull); | 12511 expect(clause.catchKeyword, isNotNull); |
| 9955 expect(clause.exceptionParameter, isNotNull); | 12512 expect(clause.exceptionParameter, isNotNull); |
| 9956 expect(clause.comma, isNotNull); | 12513 expect(clause.comma, isNotNull); |
| 9957 expect(clause.stackTraceParameter, isNotNull); | 12514 expect(clause.stackTraceParameter, isNotNull); |
| 9958 expect(clause.body, isNotNull); | 12515 expect(clause.body, isNotNull); |
| 9959 expect(statement.finallyKeyword, isNull); | 12516 expect(statement.finallyKeyword, isNull); |
| 9960 expect(statement.finallyBlock, isNull); | 12517 expect(statement.finallyBlock, isNull); |
| 9961 } | 12518 } |
| 9962 | 12519 |
| 9963 void test_parseTryStatement_on_catch_finally() { | 12520 void test_parseTryStatement_on_catch_finally() { |
| 9964 TryStatement statement = parse4( | 12521 createParser('try {} on Error catch (e, s) {} finally {}'); |
| 9965 "parseTryStatement", "try {} on Error catch (e, s) {} finally {}"); | 12522 TryStatement statement = parser.parseTryStatement(); |
| 12523 expectNotNullIfNoErrors(statement); |
| 12524 listener.assertNoErrors(); |
| 9966 expect(statement.tryKeyword, isNotNull); | 12525 expect(statement.tryKeyword, isNotNull); |
| 9967 expect(statement.body, isNotNull); | 12526 expect(statement.body, isNotNull); |
| 9968 NodeList<CatchClause> catchClauses = statement.catchClauses; | 12527 NodeList<CatchClause> catchClauses = statement.catchClauses; |
| 9969 expect(catchClauses, hasLength(1)); | 12528 expect(catchClauses, hasLength(1)); |
| 9970 CatchClause clause = catchClauses[0]; | 12529 CatchClause clause = catchClauses[0]; |
| 9971 expect(clause.onKeyword, isNotNull); | 12530 expect(clause.onKeyword, isNotNull); |
| 9972 expect(clause.exceptionType, isNotNull); | 12531 expect(clause.exceptionType, isNotNull); |
| 9973 expect(clause.catchKeyword, isNotNull); | 12532 expect(clause.catchKeyword, isNotNull); |
| 9974 expect(clause.exceptionParameter, isNotNull); | 12533 expect(clause.exceptionParameter, isNotNull); |
| 9975 expect(clause.comma, isNotNull); | 12534 expect(clause.comma, isNotNull); |
| 9976 expect(clause.stackTraceParameter, isNotNull); | 12535 expect(clause.stackTraceParameter, isNotNull); |
| 9977 expect(clause.body, isNotNull); | 12536 expect(clause.body, isNotNull); |
| 9978 expect(statement.finallyKeyword, isNotNull); | 12537 expect(statement.finallyKeyword, isNotNull); |
| 9979 expect(statement.finallyBlock, isNotNull); | 12538 expect(statement.finallyBlock, isNotNull); |
| 9980 } | 12539 } |
| 9981 | 12540 |
| 9982 void test_parseTypeAlias_function_noParameters() { | 12541 void test_parseTypeAlias_function_noParameters() { |
| 9983 FunctionTypeAlias typeAlias = parse("parseTypeAlias", | 12542 createParser('typedef bool F();'); |
| 9984 <Object>[emptyCommentAndMetadata()], "typedef bool F();"); | 12543 FunctionTypeAlias typeAlias = |
| 12544 parser.parseTypeAlias(emptyCommentAndMetadata()); |
| 12545 expectNotNullIfNoErrors(typeAlias); |
| 12546 listener.assertNoErrors(); |
| 9985 expect(typeAlias.typedefKeyword, isNotNull); | 12547 expect(typeAlias.typedefKeyword, isNotNull); |
| 9986 expect(typeAlias.name, isNotNull); | 12548 expect(typeAlias.name, isNotNull); |
| 9987 expect(typeAlias.parameters, isNotNull); | 12549 expect(typeAlias.parameters, isNotNull); |
| 9988 expect(typeAlias.returnType, isNotNull); | 12550 expect(typeAlias.returnType, isNotNull); |
| 9989 expect(typeAlias.semicolon, isNotNull); | 12551 expect(typeAlias.semicolon, isNotNull); |
| 9990 expect(typeAlias.typeParameters, isNull); | 12552 expect(typeAlias.typeParameters, isNull); |
| 9991 } | 12553 } |
| 9992 | 12554 |
| 9993 void test_parseTypeAlias_function_noReturnType() { | 12555 void test_parseTypeAlias_function_noReturnType() { |
| 9994 FunctionTypeAlias typeAlias = parse( | 12556 createParser('typedef F();'); |
| 9995 "parseTypeAlias", <Object>[emptyCommentAndMetadata()], "typedef F();"); | 12557 FunctionTypeAlias typeAlias = |
| 12558 parser.parseTypeAlias(emptyCommentAndMetadata()); |
| 12559 expectNotNullIfNoErrors(typeAlias); |
| 12560 listener.assertNoErrors(); |
| 9996 expect(typeAlias.typedefKeyword, isNotNull); | 12561 expect(typeAlias.typedefKeyword, isNotNull); |
| 9997 expect(typeAlias.name, isNotNull); | 12562 expect(typeAlias.name, isNotNull); |
| 9998 expect(typeAlias.parameters, isNotNull); | 12563 expect(typeAlias.parameters, isNotNull); |
| 9999 expect(typeAlias.returnType, isNull); | 12564 expect(typeAlias.returnType, isNull); |
| 10000 expect(typeAlias.semicolon, isNotNull); | 12565 expect(typeAlias.semicolon, isNotNull); |
| 10001 expect(typeAlias.typeParameters, isNull); | 12566 expect(typeAlias.typeParameters, isNull); |
| 10002 } | 12567 } |
| 10003 | 12568 |
| 10004 void test_parseTypeAlias_function_parameterizedReturnType() { | 12569 void test_parseTypeAlias_function_parameterizedReturnType() { |
| 10005 FunctionTypeAlias typeAlias = parse("parseTypeAlias", | 12570 createParser('typedef A<B> F();'); |
| 10006 <Object>[emptyCommentAndMetadata()], "typedef A<B> F();"); | 12571 FunctionTypeAlias typeAlias = |
| 12572 parser.parseTypeAlias(emptyCommentAndMetadata()); |
| 12573 expectNotNullIfNoErrors(typeAlias); |
| 12574 listener.assertNoErrors(); |
| 10007 expect(typeAlias.typedefKeyword, isNotNull); | 12575 expect(typeAlias.typedefKeyword, isNotNull); |
| 10008 expect(typeAlias.name, isNotNull); | 12576 expect(typeAlias.name, isNotNull); |
| 10009 expect(typeAlias.parameters, isNotNull); | 12577 expect(typeAlias.parameters, isNotNull); |
| 10010 expect(typeAlias.returnType, isNotNull); | 12578 expect(typeAlias.returnType, isNotNull); |
| 10011 expect(typeAlias.semicolon, isNotNull); | 12579 expect(typeAlias.semicolon, isNotNull); |
| 10012 expect(typeAlias.typeParameters, isNull); | 12580 expect(typeAlias.typeParameters, isNull); |
| 10013 } | 12581 } |
| 10014 | 12582 |
| 10015 void test_parseTypeAlias_function_parameters() { | 12583 void test_parseTypeAlias_function_parameters() { |
| 10016 FunctionTypeAlias typeAlias = parse("parseTypeAlias", | 12584 createParser('typedef bool F(Object value);'); |
| 10017 <Object>[emptyCommentAndMetadata()], "typedef bool F(Object value);"); | 12585 FunctionTypeAlias typeAlias = |
| 12586 parser.parseTypeAlias(emptyCommentAndMetadata()); |
| 12587 expectNotNullIfNoErrors(typeAlias); |
| 12588 listener.assertNoErrors(); |
| 10018 expect(typeAlias.typedefKeyword, isNotNull); | 12589 expect(typeAlias.typedefKeyword, isNotNull); |
| 10019 expect(typeAlias.name, isNotNull); | 12590 expect(typeAlias.name, isNotNull); |
| 10020 expect(typeAlias.parameters, isNotNull); | 12591 expect(typeAlias.parameters, isNotNull); |
| 10021 expect(typeAlias.returnType, isNotNull); | 12592 expect(typeAlias.returnType, isNotNull); |
| 10022 expect(typeAlias.semicolon, isNotNull); | 12593 expect(typeAlias.semicolon, isNotNull); |
| 10023 expect(typeAlias.typeParameters, isNull); | 12594 expect(typeAlias.typeParameters, isNull); |
| 10024 } | 12595 } |
| 10025 | 12596 |
| 10026 void test_parseTypeAlias_function_typeParameters() { | 12597 void test_parseTypeAlias_function_typeParameters() { |
| 10027 FunctionTypeAlias typeAlias = parse("parseTypeAlias", | 12598 createParser('typedef bool F<E>();'); |
| 10028 <Object>[emptyCommentAndMetadata()], "typedef bool F<E>();"); | 12599 FunctionTypeAlias typeAlias = |
| 12600 parser.parseTypeAlias(emptyCommentAndMetadata()); |
| 12601 expectNotNullIfNoErrors(typeAlias); |
| 12602 listener.assertNoErrors(); |
| 10029 expect(typeAlias.typedefKeyword, isNotNull); | 12603 expect(typeAlias.typedefKeyword, isNotNull); |
| 10030 expect(typeAlias.name, isNotNull); | 12604 expect(typeAlias.name, isNotNull); |
| 10031 expect(typeAlias.parameters, isNotNull); | 12605 expect(typeAlias.parameters, isNotNull); |
| 10032 expect(typeAlias.returnType, isNotNull); | 12606 expect(typeAlias.returnType, isNotNull); |
| 10033 expect(typeAlias.semicolon, isNotNull); | 12607 expect(typeAlias.semicolon, isNotNull); |
| 10034 expect(typeAlias.typeParameters, isNotNull); | 12608 expect(typeAlias.typeParameters, isNotNull); |
| 10035 } | 12609 } |
| 10036 | 12610 |
| 10037 void test_parseTypeAlias_function_voidReturnType() { | 12611 void test_parseTypeAlias_function_voidReturnType() { |
| 10038 FunctionTypeAlias typeAlias = parse("parseTypeAlias", | 12612 createParser('typedef void F();'); |
| 10039 <Object>[emptyCommentAndMetadata()], "typedef void F();"); | 12613 FunctionTypeAlias typeAlias = |
| 12614 parser.parseTypeAlias(emptyCommentAndMetadata()); |
| 12615 expectNotNullIfNoErrors(typeAlias); |
| 12616 listener.assertNoErrors(); |
| 10040 expect(typeAlias.typedefKeyword, isNotNull); | 12617 expect(typeAlias.typedefKeyword, isNotNull); |
| 10041 expect(typeAlias.name, isNotNull); | 12618 expect(typeAlias.name, isNotNull); |
| 10042 expect(typeAlias.parameters, isNotNull); | 12619 expect(typeAlias.parameters, isNotNull); |
| 10043 expect(typeAlias.returnType, isNotNull); | 12620 expect(typeAlias.returnType, isNotNull); |
| 10044 expect(typeAlias.semicolon, isNotNull); | 12621 expect(typeAlias.semicolon, isNotNull); |
| 10045 expect(typeAlias.typeParameters, isNull); | 12622 expect(typeAlias.typeParameters, isNull); |
| 10046 } | 12623 } |
| 10047 | 12624 |
| 10048 void test_parseTypeArgumentList_empty() { | 12625 void test_parseTypeArgumentList_empty() { |
| 10049 TypeArgumentList argumentList = parse4( | 12626 createParser('<>'); |
| 10050 "parseTypeArgumentList", "<>", [ParserErrorCode.EXPECTED_TYPE_NAME]); | 12627 TypeArgumentList argumentList = parser.parseTypeArgumentList(); |
| 12628 expectNotNullIfNoErrors(argumentList); |
| 12629 listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_TYPE_NAME]); |
| 10051 expect(argumentList.leftBracket, isNotNull); | 12630 expect(argumentList.leftBracket, isNotNull); |
| 10052 expect(argumentList.arguments, hasLength(1)); | 12631 expect(argumentList.arguments, hasLength(1)); |
| 10053 expect(argumentList.rightBracket, isNotNull); | 12632 expect(argumentList.rightBracket, isNotNull); |
| 10054 } | 12633 } |
| 10055 | 12634 |
| 10056 void test_parseTypeArgumentList_multiple() { | 12635 void test_parseTypeArgumentList_multiple() { |
| 10057 TypeArgumentList argumentList = | 12636 createParser('<int, int, int>'); |
| 10058 parse4("parseTypeArgumentList", "<int, int, int>"); | 12637 TypeArgumentList argumentList = parser.parseTypeArgumentList(); |
| 12638 expectNotNullIfNoErrors(argumentList); |
| 12639 listener.assertNoErrors(); |
| 10059 expect(argumentList.leftBracket, isNotNull); | 12640 expect(argumentList.leftBracket, isNotNull); |
| 10060 expect(argumentList.arguments, hasLength(3)); | 12641 expect(argumentList.arguments, hasLength(3)); |
| 10061 expect(argumentList.rightBracket, isNotNull); | 12642 expect(argumentList.rightBracket, isNotNull); |
| 10062 } | 12643 } |
| 10063 | 12644 |
| 10064 void test_parseTypeArgumentList_nested() { | 12645 void test_parseTypeArgumentList_nested() { |
| 10065 TypeArgumentList argumentList = parse4("parseTypeArgumentList", "<A<B>>"); | 12646 createParser('<A<B>>'); |
| 12647 TypeArgumentList argumentList = parser.parseTypeArgumentList(); |
| 12648 expectNotNullIfNoErrors(argumentList); |
| 12649 listener.assertNoErrors(); |
| 10066 expect(argumentList.leftBracket, isNotNull); | 12650 expect(argumentList.leftBracket, isNotNull); |
| 10067 expect(argumentList.arguments, hasLength(1)); | 12651 expect(argumentList.arguments, hasLength(1)); |
| 10068 TypeName argument = argumentList.arguments[0]; | 12652 TypeName argument = argumentList.arguments[0]; |
| 10069 expect(argument, isNotNull); | 12653 expect(argument, isNotNull); |
| 10070 TypeArgumentList innerList = argument.typeArguments; | 12654 TypeArgumentList innerList = argument.typeArguments; |
| 10071 expect(innerList, isNotNull); | 12655 expect(innerList, isNotNull); |
| 10072 expect(innerList.arguments, hasLength(1)); | 12656 expect(innerList.arguments, hasLength(1)); |
| 10073 expect(argumentList.rightBracket, isNotNull); | 12657 expect(argumentList.rightBracket, isNotNull); |
| 10074 } | 12658 } |
| 10075 | 12659 |
| 10076 void test_parseTypeArgumentList_nested_withComment_double() { | 12660 void test_parseTypeArgumentList_nested_withComment_double() { |
| 10077 TypeArgumentList argumentList = | 12661 createParser('<A<B /* 0 */ >>'); |
| 10078 parse4("parseTypeArgumentList", "<A<B /* 0 */ >>"); | 12662 TypeArgumentList argumentList = parser.parseTypeArgumentList(); |
| 12663 expectNotNullIfNoErrors(argumentList); |
| 12664 listener.assertNoErrors(); |
| 10079 expect(argumentList.leftBracket, isNotNull); | 12665 expect(argumentList.leftBracket, isNotNull); |
| 10080 expect(argumentList.rightBracket, isNotNull); | 12666 expect(argumentList.rightBracket, isNotNull); |
| 10081 expect(argumentList.arguments, hasLength(1)); | 12667 expect(argumentList.arguments, hasLength(1)); |
| 10082 | 12668 |
| 10083 TypeName argument = argumentList.arguments[0]; | 12669 TypeName argument = argumentList.arguments[0]; |
| 10084 expect(argument, isNotNull); | 12670 expect(argument, isNotNull); |
| 10085 | 12671 |
| 10086 TypeArgumentList innerList = argument.typeArguments; | 12672 TypeArgumentList innerList = argument.typeArguments; |
| 10087 expect(innerList, isNotNull); | 12673 expect(innerList, isNotNull); |
| 10088 expect(innerList.leftBracket, isNotNull); | 12674 expect(innerList.leftBracket, isNotNull); |
| 10089 expect(innerList.arguments, hasLength(1)); | 12675 expect(innerList.arguments, hasLength(1)); |
| 10090 expect(innerList.rightBracket, isNotNull); | 12676 expect(innerList.rightBracket, isNotNull); |
| 10091 expect(innerList.rightBracket.precedingComments, isNotNull); | 12677 expect(innerList.rightBracket.precedingComments, isNotNull); |
| 10092 } | 12678 } |
| 10093 | 12679 |
| 10094 void test_parseTypeArgumentList_nested_withComment_tripple() { | 12680 void test_parseTypeArgumentList_nested_withComment_tripple() { |
| 10095 TypeArgumentList argumentList = | 12681 createParser('<A<B<C /* 0 */ >>>'); |
| 10096 parse4("parseTypeArgumentList", "<A<B<C /* 0 */ >>>"); | 12682 TypeArgumentList argumentList = parser.parseTypeArgumentList(); |
| 12683 expectNotNullIfNoErrors(argumentList); |
| 12684 listener.assertNoErrors(); |
| 10097 expect(argumentList.leftBracket, isNotNull); | 12685 expect(argumentList.leftBracket, isNotNull); |
| 10098 expect(argumentList.rightBracket, isNotNull); | 12686 expect(argumentList.rightBracket, isNotNull); |
| 10099 expect(argumentList.arguments, hasLength(1)); | 12687 expect(argumentList.arguments, hasLength(1)); |
| 10100 | 12688 |
| 10101 TypeName argument = argumentList.arguments[0]; | 12689 TypeName argument = argumentList.arguments[0]; |
| 10102 expect(argument, isNotNull); | 12690 expect(argument, isNotNull); |
| 10103 | 12691 |
| 10104 TypeArgumentList innerList = argument.typeArguments; | 12692 TypeArgumentList innerList = argument.typeArguments; |
| 10105 expect(innerList, isNotNull); | 12693 expect(innerList, isNotNull); |
| 10106 expect(innerList.leftBracket, isNotNull); | 12694 expect(innerList.leftBracket, isNotNull); |
| 10107 expect(innerList.arguments, hasLength(1)); | 12695 expect(innerList.arguments, hasLength(1)); |
| 10108 expect(innerList.rightBracket, isNotNull); | 12696 expect(innerList.rightBracket, isNotNull); |
| 10109 | 12697 |
| 10110 TypeName innerArgument = innerList.arguments[0]; | 12698 TypeName innerArgument = innerList.arguments[0]; |
| 10111 expect(innerArgument, isNotNull); | 12699 expect(innerArgument, isNotNull); |
| 10112 | 12700 |
| 10113 TypeArgumentList innerInnerList = innerArgument.typeArguments; | 12701 TypeArgumentList innerInnerList = innerArgument.typeArguments; |
| 10114 expect(innerInnerList, isNotNull); | 12702 expect(innerInnerList, isNotNull); |
| 10115 expect(innerInnerList.leftBracket, isNotNull); | 12703 expect(innerInnerList.leftBracket, isNotNull); |
| 10116 expect(innerInnerList.arguments, hasLength(1)); | 12704 expect(innerInnerList.arguments, hasLength(1)); |
| 10117 expect(innerInnerList.rightBracket, isNotNull); | 12705 expect(innerInnerList.rightBracket, isNotNull); |
| 10118 expect(innerInnerList.rightBracket.precedingComments, isNotNull); | 12706 expect(innerInnerList.rightBracket.precedingComments, isNotNull); |
| 10119 } | 12707 } |
| 10120 | 12708 |
| 10121 void test_parseTypeArgumentList_single() { | 12709 void test_parseTypeArgumentList_single() { |
| 10122 TypeArgumentList argumentList = parse4("parseTypeArgumentList", "<int>"); | 12710 createParser('<int>'); |
| 12711 TypeArgumentList argumentList = parser.parseTypeArgumentList(); |
| 12712 expectNotNullIfNoErrors(argumentList); |
| 12713 listener.assertNoErrors(); |
| 10123 expect(argumentList.leftBracket, isNotNull); | 12714 expect(argumentList.leftBracket, isNotNull); |
| 10124 expect(argumentList.arguments, hasLength(1)); | 12715 expect(argumentList.arguments, hasLength(1)); |
| 10125 expect(argumentList.rightBracket, isNotNull); | 12716 expect(argumentList.rightBracket, isNotNull); |
| 10126 } | 12717 } |
| 10127 | 12718 |
| 10128 void test_parseTypeName_parameterized() { | 12719 void test_parseTypeName_parameterized() { |
| 10129 TypeName typeName = parse4("parseTypeName", "List<int>"); | 12720 createParser('List<int>'); |
| 12721 TypeName typeName = parser.parseTypeName(false); |
| 12722 expectNotNullIfNoErrors(typeName); |
| 12723 listener.assertNoErrors(); |
| 10130 expect(typeName.name, isNotNull); | 12724 expect(typeName.name, isNotNull); |
| 10131 expect(typeName.typeArguments, isNotNull); | 12725 expect(typeName.typeArguments, isNotNull); |
| 12726 expect(typeName.question, isNull); |
| 12727 } |
| 12728 |
| 12729 void test_parseTypeName_parameterized_nullable() { |
| 12730 enableNnbd = true; |
| 12731 createParser('List<int>?'); |
| 12732 TypeName typeName = parser.parseTypeName(false); |
| 12733 expectNotNullIfNoErrors(typeName); |
| 12734 listener.assertNoErrors(); |
| 12735 expect(typeName.name, isNotNull); |
| 12736 expect(typeName.typeArguments, isNotNull); |
| 12737 expect(typeName.question, isNotNull); |
| 10132 } | 12738 } |
| 10133 | 12739 |
| 10134 void test_parseTypeName_simple() { | 12740 void test_parseTypeName_simple() { |
| 10135 TypeName typeName = parse4("parseTypeName", "int"); | 12741 createParser('int'); |
| 12742 TypeName typeName = parser.parseTypeName(false); |
| 12743 expectNotNullIfNoErrors(typeName); |
| 12744 listener.assertNoErrors(); |
| 10136 expect(typeName.name, isNotNull); | 12745 expect(typeName.name, isNotNull); |
| 10137 expect(typeName.typeArguments, isNull); | 12746 expect(typeName.typeArguments, isNull); |
| 12747 expect(typeName.question, isNull); |
| 12748 } |
| 12749 |
| 12750 void test_parseTypeName_simple_nullable() { |
| 12751 enableNnbd = true; |
| 12752 createParser('String?'); |
| 12753 TypeName typeName = parser.parseTypeName(false); |
| 12754 expectNotNullIfNoErrors(typeName); |
| 12755 listener.assertNoErrors(); |
| 12756 expect(typeName.name, isNotNull); |
| 12757 expect(typeName.typeArguments, isNull); |
| 12758 expect(typeName.question, isNotNull); |
| 10138 } | 12759 } |
| 10139 | 12760 |
| 10140 void test_parseTypeParameter_bounded() { | 12761 void test_parseTypeParameter_bounded() { |
| 10141 TypeParameter parameter = parse4("parseTypeParameter", "A extends B"); | 12762 createParser('A extends B'); |
| 12763 TypeParameter parameter = parser.parseTypeParameter(); |
| 12764 expectNotNullIfNoErrors(parameter); |
| 12765 listener.assertNoErrors(); |
| 10142 expect(parameter.bound, isNotNull); | 12766 expect(parameter.bound, isNotNull); |
| 10143 expect(parameter.extendsKeyword, isNotNull); | 12767 expect(parameter.extendsKeyword, isNotNull); |
| 10144 expect(parameter.name, isNotNull); | 12768 expect(parameter.name, isNotNull); |
| 10145 } | 12769 } |
| 10146 | 12770 |
| 12771 void test_parseTypeParameter_bounded_nullable() { |
| 12772 enableNnbd = true; |
| 12773 createParser('A extends B?'); |
| 12774 TypeParameter parameter = parser.parseTypeParameter(); |
| 12775 expectNotNullIfNoErrors(parameter); |
| 12776 listener.assertNoErrors(); |
| 12777 expect(parameter.bound, isNotNull); |
| 12778 expect(parameter.extendsKeyword, isNotNull); |
| 12779 expect(parameter.name, isNotNull); |
| 12780 TypeName bound = parameter.bound; |
| 12781 expect(bound, isNotNull); |
| 12782 expect(bound.question, isNotNull); |
| 12783 } |
| 12784 |
| 10147 void test_parseTypeParameter_simple() { | 12785 void test_parseTypeParameter_simple() { |
| 10148 TypeParameter parameter = parse4("parseTypeParameter", "A"); | 12786 createParser('A'); |
| 12787 TypeParameter parameter = parser.parseTypeParameter(); |
| 12788 expectNotNullIfNoErrors(parameter); |
| 12789 listener.assertNoErrors(); |
| 10149 expect(parameter.bound, isNull); | 12790 expect(parameter.bound, isNull); |
| 10150 expect(parameter.extendsKeyword, isNull); | 12791 expect(parameter.extendsKeyword, isNull); |
| 10151 expect(parameter.name, isNotNull); | 12792 expect(parameter.name, isNotNull); |
| 10152 } | 12793 } |
| 10153 | 12794 |
| 10154 void test_parseTypeParameterList_multiple() { | 12795 void test_parseTypeParameterList_multiple() { |
| 10155 TypeParameterList parameterList = | 12796 createParser('<A, B extends C, D>'); |
| 10156 parse4("parseTypeParameterList", "<A, B extends C, D>"); | 12797 TypeParameterList parameterList = parser.parseTypeParameterList(); |
| 12798 expectNotNullIfNoErrors(parameterList); |
| 12799 listener.assertNoErrors(); |
| 10157 expect(parameterList.leftBracket, isNotNull); | 12800 expect(parameterList.leftBracket, isNotNull); |
| 10158 expect(parameterList.rightBracket, isNotNull); | 12801 expect(parameterList.rightBracket, isNotNull); |
| 10159 expect(parameterList.typeParameters, hasLength(3)); | 12802 expect(parameterList.typeParameters, hasLength(3)); |
| 10160 } | 12803 } |
| 10161 | 12804 |
| 10162 void test_parseTypeParameterList_parameterizedWithTrailingEquals() { | 12805 void test_parseTypeParameterList_parameterizedWithTrailingEquals() { |
| 10163 TypeParameterList parameterList = | 12806 createParser('<A extends B<E>>='); |
| 10164 parse4("parseTypeParameterList", "<A extends B<E>>="); | 12807 TypeParameterList parameterList = parser.parseTypeParameterList(); |
| 12808 expectNotNullIfNoErrors(parameterList); |
| 12809 listener.assertNoErrors(); |
| 10165 expect(parameterList.leftBracket, isNotNull); | 12810 expect(parameterList.leftBracket, isNotNull); |
| 10166 expect(parameterList.rightBracket, isNotNull); | 12811 expect(parameterList.rightBracket, isNotNull); |
| 10167 expect(parameterList.typeParameters, hasLength(1)); | 12812 expect(parameterList.typeParameters, hasLength(1)); |
| 10168 } | 12813 } |
| 10169 | 12814 |
| 10170 void test_parseTypeParameterList_single() { | 12815 void test_parseTypeParameterList_single() { |
| 10171 TypeParameterList parameterList = parse4("parseTypeParameterList", "<A>"); | 12816 createParser('<<A>'); |
| 12817 TypeParameterList parameterList = parser.parseTypeParameterList(); |
| 12818 expectNotNullIfNoErrors(parameterList); |
| 12819 listener.assertNoErrors(); |
| 10172 expect(parameterList.leftBracket, isNotNull); | 12820 expect(parameterList.leftBracket, isNotNull); |
| 10173 expect(parameterList.rightBracket, isNotNull); | 12821 expect(parameterList.rightBracket, isNotNull); |
| 10174 expect(parameterList.typeParameters, hasLength(1)); | 12822 expect(parameterList.typeParameters, hasLength(1)); |
| 10175 } | 12823 } |
| 10176 | 12824 |
| 10177 void test_parseTypeParameterList_withTrailingEquals() { | 12825 void test_parseTypeParameterList_withTrailingEquals() { |
| 10178 TypeParameterList parameterList = parse4("parseTypeParameterList", "<A>="); | 12826 createParser('<A>='); |
| 12827 TypeParameterList parameterList = parser.parseTypeParameterList(); |
| 12828 expectNotNullIfNoErrors(parameterList); |
| 12829 listener.assertNoErrors(); |
| 10179 expect(parameterList.leftBracket, isNotNull); | 12830 expect(parameterList.leftBracket, isNotNull); |
| 10180 expect(parameterList.rightBracket, isNotNull); | 12831 expect(parameterList.rightBracket, isNotNull); |
| 10181 expect(parameterList.typeParameters, hasLength(1)); | 12832 expect(parameterList.typeParameters, hasLength(1)); |
| 10182 } | 12833 } |
| 10183 | 12834 |
| 10184 void test_parseUnaryExpression_decrement_normal() { | 12835 void test_parseUnaryExpression_decrement_normal() { |
| 10185 PrefixExpression expression = parse4("parseUnaryExpression", "--x"); | 12836 createParser('--x'); |
| 12837 PrefixExpression expression = parser.parseUnaryExpression(); |
| 12838 expectNotNullIfNoErrors(expression); |
| 12839 listener.assertNoErrors(); |
| 10186 expect(expression.operator, isNotNull); | 12840 expect(expression.operator, isNotNull); |
| 10187 expect(expression.operator.type, TokenType.MINUS_MINUS); | 12841 expect(expression.operator.type, TokenType.MINUS_MINUS); |
| 10188 expect(expression.operand, isNotNull); | 12842 expect(expression.operand, isNotNull); |
| 10189 } | 12843 } |
| 10190 | 12844 |
| 10191 void test_parseUnaryExpression_decrement_super() { | 12845 void test_parseUnaryExpression_decrement_super() { |
| 10192 PrefixExpression expression = parse4("parseUnaryExpression", "--super"); | 12846 createParser('--super'); |
| 12847 PrefixExpression expression = parser.parseUnaryExpression(); |
| 12848 expectNotNullIfNoErrors(expression); |
| 12849 listener.assertNoErrors(); |
| 10193 expect(expression.operator, isNotNull); | 12850 expect(expression.operator, isNotNull); |
| 10194 expect(expression.operator.type, TokenType.MINUS); | 12851 expect(expression.operator.type, TokenType.MINUS); |
| 10195 Expression innerExpression = expression.operand; | 12852 Expression innerExpression = expression.operand; |
| 10196 expect(innerExpression, isNotNull); | 12853 expect(innerExpression, isNotNull); |
| 10197 expect(innerExpression is PrefixExpression, isTrue); | 12854 expect(innerExpression is PrefixExpression, isTrue); |
| 10198 PrefixExpression operand = innerExpression as PrefixExpression; | 12855 PrefixExpression operand = innerExpression as PrefixExpression; |
| 10199 expect(operand.operator, isNotNull); | 12856 expect(operand.operator, isNotNull); |
| 10200 expect(operand.operator.type, TokenType.MINUS); | 12857 expect(operand.operator.type, TokenType.MINUS); |
| 10201 expect(operand.operand, isNotNull); | 12858 expect(operand.operand, isNotNull); |
| 10202 } | 12859 } |
| 10203 | 12860 |
| 10204 void test_parseUnaryExpression_decrement_super_propertyAccess() { | 12861 void test_parseUnaryExpression_decrement_super_propertyAccess() { |
| 10205 PrefixExpression expression = parse4("parseUnaryExpression", "--super.x"); | 12862 createParser('--super.x'); |
| 12863 PrefixExpression expression = parser.parseUnaryExpression(); |
| 12864 expectNotNullIfNoErrors(expression); |
| 12865 listener.assertNoErrors(); |
| 10206 expect(expression.operator, isNotNull); | 12866 expect(expression.operator, isNotNull); |
| 10207 expect(expression.operator.type, TokenType.MINUS_MINUS); | 12867 expect(expression.operator.type, TokenType.MINUS_MINUS); |
| 10208 expect(expression.operand, isNotNull); | 12868 expect(expression.operand, isNotNull); |
| 10209 PropertyAccess operand = expression.operand as PropertyAccess; | 12869 PropertyAccess operand = expression.operand as PropertyAccess; |
| 10210 expect(operand.target is SuperExpression, isTrue); | 12870 expect(operand.target is SuperExpression, isTrue); |
| 10211 expect(operand.propertyName.name, "x"); | 12871 expect(operand.propertyName.name, "x"); |
| 10212 } | 12872 } |
| 10213 | 12873 |
| 10214 void test_parseUnaryExpression_decrement_super_withComment() { | 12874 void test_parseUnaryExpression_decrement_super_withComment() { |
| 10215 PrefixExpression expression = | 12875 createParser('/* 0 */ --super'); |
| 10216 parse4("parseUnaryExpression", "/* 0 */ --super"); | 12876 PrefixExpression expression = parser.parseUnaryExpression(); |
| 12877 expectNotNullIfNoErrors(expression); |
| 12878 listener.assertNoErrors(); |
| 10217 expect(expression.operator, isNotNull); | 12879 expect(expression.operator, isNotNull); |
| 10218 expect(expression.operator.type, TokenType.MINUS); | 12880 expect(expression.operator.type, TokenType.MINUS); |
| 10219 expect(expression.operator.precedingComments, isNotNull); | 12881 expect(expression.operator.precedingComments, isNotNull); |
| 10220 Expression innerExpression = expression.operand; | 12882 Expression innerExpression = expression.operand; |
| 10221 expect(innerExpression, isNotNull); | 12883 expect(innerExpression, isNotNull); |
| 10222 expect(innerExpression is PrefixExpression, isTrue); | 12884 expect(innerExpression is PrefixExpression, isTrue); |
| 10223 PrefixExpression operand = innerExpression as PrefixExpression; | 12885 PrefixExpression operand = innerExpression as PrefixExpression; |
| 10224 expect(operand.operator, isNotNull); | 12886 expect(operand.operator, isNotNull); |
| 10225 expect(operand.operator.type, TokenType.MINUS); | 12887 expect(operand.operator.type, TokenType.MINUS); |
| 10226 expect(operand.operand, isNotNull); | 12888 expect(operand.operand, isNotNull); |
| 10227 } | 12889 } |
| 10228 | 12890 |
| 10229 void test_parseUnaryExpression_increment_normal() { | 12891 void test_parseUnaryExpression_increment_normal() { |
| 10230 PrefixExpression expression = parse4("parseUnaryExpression", "++x"); | 12892 createParser('++x'); |
| 12893 PrefixExpression expression = parser.parseUnaryExpression(); |
| 12894 expectNotNullIfNoErrors(expression); |
| 12895 listener.assertNoErrors(); |
| 10231 expect(expression.operator, isNotNull); | 12896 expect(expression.operator, isNotNull); |
| 10232 expect(expression.operator.type, TokenType.PLUS_PLUS); | 12897 expect(expression.operator.type, TokenType.PLUS_PLUS); |
| 10233 expect(expression.operand, isNotNull); | 12898 expect(expression.operand, isNotNull); |
| 10234 } | 12899 } |
| 10235 | 12900 |
| 10236 void test_parseUnaryExpression_increment_super_index() { | 12901 void test_parseUnaryExpression_increment_super_index() { |
| 10237 PrefixExpression expression = parse4("parseUnaryExpression", "++super[0]"); | 12902 createParser('++super[0]'); |
| 12903 PrefixExpression expression = parser.parseUnaryExpression(); |
| 12904 expectNotNullIfNoErrors(expression); |
| 12905 listener.assertNoErrors(); |
| 10238 expect(expression.operator, isNotNull); | 12906 expect(expression.operator, isNotNull); |
| 10239 expect(expression.operator.type, TokenType.PLUS_PLUS); | 12907 expect(expression.operator.type, TokenType.PLUS_PLUS); |
| 10240 expect(expression.operand, isNotNull); | 12908 expect(expression.operand, isNotNull); |
| 10241 IndexExpression operand = expression.operand as IndexExpression; | 12909 IndexExpression operand = expression.operand as IndexExpression; |
| 10242 expect(operand.realTarget is SuperExpression, isTrue); | 12910 expect(operand.realTarget is SuperExpression, isTrue); |
| 10243 expect(operand.index is IntegerLiteral, isTrue); | 12911 expect(operand.index is IntegerLiteral, isTrue); |
| 10244 } | 12912 } |
| 10245 | 12913 |
| 10246 void test_parseUnaryExpression_increment_super_propertyAccess() { | 12914 void test_parseUnaryExpression_increment_super_propertyAccess() { |
| 10247 PrefixExpression expression = parse4("parseUnaryExpression", "++super.x"); | 12915 createParser('++super.x'); |
| 12916 PrefixExpression expression = parser.parseUnaryExpression(); |
| 12917 expectNotNullIfNoErrors(expression); |
| 12918 listener.assertNoErrors(); |
| 10248 expect(expression.operator, isNotNull); | 12919 expect(expression.operator, isNotNull); |
| 10249 expect(expression.operator.type, TokenType.PLUS_PLUS); | 12920 expect(expression.operator.type, TokenType.PLUS_PLUS); |
| 10250 expect(expression.operand, isNotNull); | 12921 expect(expression.operand, isNotNull); |
| 10251 PropertyAccess operand = expression.operand as PropertyAccess; | 12922 PropertyAccess operand = expression.operand as PropertyAccess; |
| 10252 expect(operand.target is SuperExpression, isTrue); | 12923 expect(operand.target is SuperExpression, isTrue); |
| 10253 expect(operand.propertyName.name, "x"); | 12924 expect(operand.propertyName.name, "x"); |
| 10254 } | 12925 } |
| 10255 | 12926 |
| 10256 void test_parseUnaryExpression_minus_normal() { | 12927 void test_parseUnaryExpression_minus_normal() { |
| 10257 PrefixExpression expression = parse4("parseUnaryExpression", "-x"); | 12928 createParser('-x'); |
| 12929 PrefixExpression expression = parser.parseUnaryExpression(); |
| 12930 expectNotNullIfNoErrors(expression); |
| 12931 listener.assertNoErrors(); |
| 10258 expect(expression.operator, isNotNull); | 12932 expect(expression.operator, isNotNull); |
| 10259 expect(expression.operator.type, TokenType.MINUS); | 12933 expect(expression.operator.type, TokenType.MINUS); |
| 10260 expect(expression.operand, isNotNull); | 12934 expect(expression.operand, isNotNull); |
| 10261 } | 12935 } |
| 10262 | 12936 |
| 10263 void test_parseUnaryExpression_minus_super() { | 12937 void test_parseUnaryExpression_minus_super() { |
| 10264 PrefixExpression expression = parse4("parseUnaryExpression", "-super"); | 12938 createParser('-super'); |
| 12939 PrefixExpression expression = parser.parseUnaryExpression(); |
| 12940 expectNotNullIfNoErrors(expression); |
| 12941 listener.assertNoErrors(); |
| 10265 expect(expression.operator, isNotNull); | 12942 expect(expression.operator, isNotNull); |
| 10266 expect(expression.operator.type, TokenType.MINUS); | 12943 expect(expression.operator.type, TokenType.MINUS); |
| 10267 expect(expression.operand, isNotNull); | 12944 expect(expression.operand, isNotNull); |
| 10268 } | 12945 } |
| 10269 | 12946 |
| 10270 void test_parseUnaryExpression_not_normal() { | 12947 void test_parseUnaryExpression_not_normal() { |
| 10271 PrefixExpression expression = parse4("parseUnaryExpression", "!x"); | 12948 createParser('!x'); |
| 12949 PrefixExpression expression = parser.parseUnaryExpression(); |
| 12950 expectNotNullIfNoErrors(expression); |
| 12951 listener.assertNoErrors(); |
| 10272 expect(expression.operator, isNotNull); | 12952 expect(expression.operator, isNotNull); |
| 10273 expect(expression.operator.type, TokenType.BANG); | 12953 expect(expression.operator.type, TokenType.BANG); |
| 10274 expect(expression.operand, isNotNull); | 12954 expect(expression.operand, isNotNull); |
| 10275 } | 12955 } |
| 10276 | 12956 |
| 10277 void test_parseUnaryExpression_not_super() { | 12957 void test_parseUnaryExpression_not_super() { |
| 10278 PrefixExpression expression = parse4("parseUnaryExpression", "!super"); | 12958 createParser('!super'); |
| 12959 PrefixExpression expression = parser.parseUnaryExpression(); |
| 12960 expectNotNullIfNoErrors(expression); |
| 12961 listener.assertNoErrors(); |
| 10279 expect(expression.operator, isNotNull); | 12962 expect(expression.operator, isNotNull); |
| 10280 expect(expression.operator.type, TokenType.BANG); | 12963 expect(expression.operator.type, TokenType.BANG); |
| 10281 expect(expression.operand, isNotNull); | 12964 expect(expression.operand, isNotNull); |
| 10282 } | 12965 } |
| 10283 | 12966 |
| 10284 void test_parseUnaryExpression_tilda_normal() { | 12967 void test_parseUnaryExpression_tilda_normal() { |
| 10285 PrefixExpression expression = parse4("parseUnaryExpression", "~x"); | 12968 createParser('~x'); |
| 12969 PrefixExpression expression = parser.parseUnaryExpression(); |
| 12970 expectNotNullIfNoErrors(expression); |
| 12971 listener.assertNoErrors(); |
| 10286 expect(expression.operator, isNotNull); | 12972 expect(expression.operator, isNotNull); |
| 10287 expect(expression.operator.type, TokenType.TILDE); | 12973 expect(expression.operator.type, TokenType.TILDE); |
| 10288 expect(expression.operand, isNotNull); | 12974 expect(expression.operand, isNotNull); |
| 10289 } | 12975 } |
| 10290 | 12976 |
| 10291 void test_parseUnaryExpression_tilda_super() { | 12977 void test_parseUnaryExpression_tilda_super() { |
| 10292 PrefixExpression expression = parse4("parseUnaryExpression", "~super"); | 12978 createParser('~super'); |
| 12979 PrefixExpression expression = parser.parseUnaryExpression(); |
| 12980 expectNotNullIfNoErrors(expression); |
| 12981 listener.assertNoErrors(); |
| 10293 expect(expression.operator, isNotNull); | 12982 expect(expression.operator, isNotNull); |
| 10294 expect(expression.operator.type, TokenType.TILDE); | 12983 expect(expression.operator.type, TokenType.TILDE); |
| 10295 expect(expression.operand, isNotNull); | 12984 expect(expression.operand, isNotNull); |
| 10296 } | 12985 } |
| 10297 | 12986 |
| 10298 void test_parseVariableDeclaration_equals() { | 12987 void test_parseVariableDeclaration_equals() { |
| 10299 VariableDeclaration declaration = | 12988 createParser('a = b'); |
| 10300 parse4("parseVariableDeclaration", "a = b"); | 12989 VariableDeclaration declaration = parser.parseVariableDeclaration(); |
| 12990 expectNotNullIfNoErrors(declaration); |
| 12991 listener.assertNoErrors(); |
| 10301 expect(declaration.name, isNotNull); | 12992 expect(declaration.name, isNotNull); |
| 10302 expect(declaration.equals, isNotNull); | 12993 expect(declaration.equals, isNotNull); |
| 10303 expect(declaration.initializer, isNotNull); | 12994 expect(declaration.initializer, isNotNull); |
| 10304 } | 12995 } |
| 10305 | 12996 |
| 10306 void test_parseVariableDeclaration_noEquals() { | 12997 void test_parseVariableDeclaration_noEquals() { |
| 10307 VariableDeclaration declaration = parse4("parseVariableDeclaration", "a"); | 12998 createParser('a'); |
| 12999 VariableDeclaration declaration = parser.parseVariableDeclaration(); |
| 13000 expectNotNullIfNoErrors(declaration); |
| 13001 listener.assertNoErrors(); |
| 10308 expect(declaration.name, isNotNull); | 13002 expect(declaration.name, isNotNull); |
| 10309 expect(declaration.equals, isNull); | 13003 expect(declaration.equals, isNull); |
| 10310 expect(declaration.initializer, isNull); | 13004 expect(declaration.initializer, isNull); |
| 10311 } | 13005 } |
| 10312 | 13006 |
| 10313 void test_parseVariableDeclarationListAfterMetadata_const_noType() { | 13007 void test_parseVariableDeclarationListAfterMetadata_const_noType() { |
| 10314 VariableDeclarationList declarationList = parse( | 13008 createParser('const a'); |
| 10315 "parseVariableDeclarationListAfterMetadata", | 13009 VariableDeclarationList declarationList = parser |
| 10316 <Object>[emptyCommentAndMetadata()], | 13010 .parseVariableDeclarationListAfterMetadata(emptyCommentAndMetadata()); |
| 10317 "const a"); | 13011 expectNotNullIfNoErrors(declarationList); |
| 13012 listener.assertNoErrors(); |
| 10318 expect(declarationList.keyword, isNotNull); | 13013 expect(declarationList.keyword, isNotNull); |
| 10319 expect(declarationList.type, isNull); | 13014 expect(declarationList.type, isNull); |
| 10320 expect(declarationList.variables, hasLength(1)); | 13015 expect(declarationList.variables, hasLength(1)); |
| 10321 } | 13016 } |
| 10322 | 13017 |
| 10323 void test_parseVariableDeclarationListAfterMetadata_const_type() { | 13018 void test_parseVariableDeclarationListAfterMetadata_const_type() { |
| 10324 VariableDeclarationList declarationList = parse( | 13019 createParser('const A a'); |
| 10325 "parseVariableDeclarationListAfterMetadata", | 13020 VariableDeclarationList declarationList = parser |
| 10326 <Object>[emptyCommentAndMetadata()], | 13021 .parseVariableDeclarationListAfterMetadata(emptyCommentAndMetadata()); |
| 10327 "const A a"); | 13022 expectNotNullIfNoErrors(declarationList); |
| 13023 listener.assertNoErrors(); |
| 10328 expect(declarationList.keyword, isNotNull); | 13024 expect(declarationList.keyword, isNotNull); |
| 10329 expect(declarationList.type, isNotNull); | 13025 expect(declarationList.type, isNotNull); |
| 10330 expect(declarationList.variables, hasLength(1)); | 13026 expect(declarationList.variables, hasLength(1)); |
| 10331 } | 13027 } |
| 10332 | 13028 |
| 10333 void test_parseVariableDeclarationListAfterMetadata_final_noType() { | 13029 void test_parseVariableDeclarationListAfterMetadata_final_noType() { |
| 10334 VariableDeclarationList declarationList = parse( | 13030 createParser('final a'); |
| 10335 "parseVariableDeclarationListAfterMetadata", | 13031 VariableDeclarationList declarationList = parser |
| 10336 <Object>[emptyCommentAndMetadata()], | 13032 .parseVariableDeclarationListAfterMetadata(emptyCommentAndMetadata()); |
| 10337 "final a"); | 13033 expectNotNullIfNoErrors(declarationList); |
| 13034 listener.assertNoErrors(); |
| 10338 expect(declarationList.keyword, isNotNull); | 13035 expect(declarationList.keyword, isNotNull); |
| 10339 expect(declarationList.type, isNull); | 13036 expect(declarationList.type, isNull); |
| 10340 expect(declarationList.variables, hasLength(1)); | 13037 expect(declarationList.variables, hasLength(1)); |
| 10341 } | 13038 } |
| 10342 | 13039 |
| 10343 void test_parseVariableDeclarationListAfterMetadata_final_type() { | 13040 void test_parseVariableDeclarationListAfterMetadata_final_type() { |
| 10344 VariableDeclarationList declarationList = parse( | 13041 createParser('final A a'); |
| 10345 "parseVariableDeclarationListAfterMetadata", | 13042 VariableDeclarationList declarationList = parser |
| 10346 <Object>[emptyCommentAndMetadata()], | 13043 .parseVariableDeclarationListAfterMetadata(emptyCommentAndMetadata()); |
| 10347 "final A a"); | 13044 expectNotNullIfNoErrors(declarationList); |
| 10348 expect(declarationList.keyword, isNotNull); | 13045 listener.assertNoErrors(); |
| 10349 expect(declarationList.type, isNotNull); | 13046 expect(declarationList.keyword, isNotNull); |
| 10350 expect(declarationList.variables, hasLength(1)); | 13047 expect(declarationList.type, isNotNull); |
| 13048 expect(declarationList.variables, hasLength(1)); |
| 13049 } |
| 13050 |
| 13051 void test_parseVariableDeclarationListAfterMetadata_final_typeComment() { |
| 13052 enableGenericMethodComments = true; |
| 13053 createParser('final/*=T*/ x'); |
| 13054 VariableDeclarationList declarationList = parser |
| 13055 .parseVariableDeclarationListAfterMetadata(emptyCommentAndMetadata()); |
| 13056 expectNotNullIfNoErrors(declarationList); |
| 13057 listener.assertNoErrors(); |
| 13058 expect(declarationList.type.name.name, 'T'); |
| 13059 expect(declarationList.isFinal, true); |
| 10351 } | 13060 } |
| 10352 | 13061 |
| 10353 void test_parseVariableDeclarationListAfterMetadata_type_multiple() { | 13062 void test_parseVariableDeclarationListAfterMetadata_type_multiple() { |
| 10354 VariableDeclarationList declarationList = parse( | 13063 createParser('A a, b, c'); |
| 10355 "parseVariableDeclarationListAfterMetadata", | 13064 VariableDeclarationList declarationList = parser |
| 10356 <Object>[emptyCommentAndMetadata()], | 13065 .parseVariableDeclarationListAfterMetadata(emptyCommentAndMetadata()); |
| 10357 "A a, b, c"); | 13066 expectNotNullIfNoErrors(declarationList); |
| 13067 listener.assertNoErrors(); |
| 10358 expect(declarationList.keyword, isNull); | 13068 expect(declarationList.keyword, isNull); |
| 10359 expect(declarationList.type, isNotNull); | 13069 expect(declarationList.type, isNotNull); |
| 10360 expect(declarationList.variables, hasLength(3)); | 13070 expect(declarationList.variables, hasLength(3)); |
| 10361 } | 13071 } |
| 10362 | 13072 |
| 10363 void test_parseVariableDeclarationListAfterMetadata_type_single() { | 13073 void test_parseVariableDeclarationListAfterMetadata_type_single() { |
| 10364 VariableDeclarationList declarationList = parse( | 13074 createParser('A a'); |
| 10365 "parseVariableDeclarationListAfterMetadata", | 13075 VariableDeclarationList declarationList = parser |
| 10366 <Object>[emptyCommentAndMetadata()], | 13076 .parseVariableDeclarationListAfterMetadata(emptyCommentAndMetadata()); |
| 10367 "A a"); | 13077 expectNotNullIfNoErrors(declarationList); |
| 13078 listener.assertNoErrors(); |
| 10368 expect(declarationList.keyword, isNull); | 13079 expect(declarationList.keyword, isNull); |
| 10369 expect(declarationList.type, isNotNull); | 13080 expect(declarationList.type, isNotNull); |
| 10370 expect(declarationList.variables, hasLength(1)); | 13081 expect(declarationList.variables, hasLength(1)); |
| 10371 } | 13082 } |
| 10372 | 13083 |
| 10373 void test_parseVariableDeclarationListAfterMetadata_var_multiple() { | 13084 void test_parseVariableDeclarationListAfterMetadata_var_multiple() { |
| 10374 VariableDeclarationList declarationList = parse( | 13085 createParser('var a, b, c'); |
| 10375 "parseVariableDeclarationListAfterMetadata", | 13086 VariableDeclarationList declarationList = parser |
| 10376 <Object>[emptyCommentAndMetadata()], | 13087 .parseVariableDeclarationListAfterMetadata(emptyCommentAndMetadata()); |
| 10377 "var a, b, c"); | 13088 expectNotNullIfNoErrors(declarationList); |
| 13089 listener.assertNoErrors(); |
| 10378 expect(declarationList.keyword, isNotNull); | 13090 expect(declarationList.keyword, isNotNull); |
| 10379 expect(declarationList.type, isNull); | 13091 expect(declarationList.type, isNull); |
| 10380 expect(declarationList.variables, hasLength(3)); | 13092 expect(declarationList.variables, hasLength(3)); |
| 10381 } | 13093 } |
| 10382 | 13094 |
| 10383 void test_parseVariableDeclarationListAfterMetadata_var_single() { | 13095 void test_parseVariableDeclarationListAfterMetadata_var_single() { |
| 10384 VariableDeclarationList declarationList = parse( | 13096 createParser('var a'); |
| 10385 "parseVariableDeclarationListAfterMetadata", | 13097 VariableDeclarationList declarationList = parser |
| 10386 <Object>[emptyCommentAndMetadata()], | 13098 .parseVariableDeclarationListAfterMetadata(emptyCommentAndMetadata()); |
| 10387 "var a"); | 13099 expectNotNullIfNoErrors(declarationList); |
| 10388 expect(declarationList.keyword, isNotNull); | 13100 listener.assertNoErrors(); |
| 10389 expect(declarationList.type, isNull); | 13101 expect(declarationList.keyword, isNotNull); |
| 10390 expect(declarationList.variables, hasLength(1)); | 13102 expect(declarationList.type, isNull); |
| 13103 expect(declarationList.variables, hasLength(1)); |
| 13104 } |
| 13105 |
| 13106 void test_parseVariableDeclarationListAfterMetadata_var_typeComment() { |
| 13107 enableGenericMethodComments = true; |
| 13108 createParser('var/*=T*/ x'); |
| 13109 VariableDeclarationList declarationList = parser |
| 13110 .parseVariableDeclarationListAfterMetadata(emptyCommentAndMetadata()); |
| 13111 expectNotNullIfNoErrors(declarationList); |
| 13112 listener.assertNoErrors(); |
| 13113 expect(declarationList.type.name.name, 'T'); |
| 13114 expect(declarationList.keyword, isNull); |
| 10391 } | 13115 } |
| 10392 | 13116 |
| 10393 void test_parseVariableDeclarationListAfterType_type() { | 13117 void test_parseVariableDeclarationListAfterType_type() { |
| 10394 TypeName type = new TypeName(new SimpleIdentifier(null), null); | 13118 TypeName type = new TypeName(new SimpleIdentifier(null), null); |
| 10395 VariableDeclarationList declarationList = parse( | 13119 createParser('a'); |
| 10396 "parseVariableDeclarationListAfterType", | 13120 VariableDeclarationList declarationList = |
| 10397 <Object>[emptyCommentAndMetadata(), null, type], | 13121 parser.parseVariableDeclarationListAfterType( |
| 10398 "a"); | 13122 emptyCommentAndMetadata(), null, type); |
| 13123 expectNotNullIfNoErrors(declarationList); |
| 13124 listener.assertNoErrors(); |
| 10399 expect(declarationList.keyword, isNull); | 13125 expect(declarationList.keyword, isNull); |
| 10400 expect(declarationList.type, type); | 13126 expect(declarationList.type, type); |
| 10401 expect(declarationList.variables, hasLength(1)); | 13127 expect(declarationList.variables, hasLength(1)); |
| 10402 } | 13128 } |
| 10403 | 13129 |
| 10404 void test_parseVariableDeclarationListAfterType_var() { | 13130 void test_parseVariableDeclarationListAfterType_var() { |
| 10405 Token keyword = TokenFactory.tokenFromKeyword(Keyword.VAR); | 13131 Token keyword = TokenFactory.tokenFromKeyword(Keyword.VAR); |
| 10406 VariableDeclarationList declarationList = parse( | 13132 createParser('a, b, c'); |
| 10407 "parseVariableDeclarationListAfterType", | 13133 VariableDeclarationList declarationList = |
| 10408 <Object>[emptyCommentAndMetadata(), keyword, null], | 13134 parser.parseVariableDeclarationListAfterType( |
| 10409 "a, b, c"); | 13135 emptyCommentAndMetadata(), keyword, null); |
| 13136 expectNotNullIfNoErrors(declarationList); |
| 13137 listener.assertNoErrors(); |
| 10410 expect(declarationList.keyword, keyword); | 13138 expect(declarationList.keyword, keyword); |
| 10411 expect(declarationList.type, isNull); | 13139 expect(declarationList.type, isNull); |
| 10412 expect(declarationList.variables, hasLength(3)); | 13140 expect(declarationList.variables, hasLength(3)); |
| 10413 } | 13141 } |
| 10414 | 13142 |
| 10415 void test_parseVariableDeclarationStatementAfterMetadata_multiple() { | 13143 void test_parseVariableDeclarationStatementAfterMetadata_multiple() { |
| 10416 VariableDeclarationStatement statement = parse( | 13144 createParser('var x, y, z;'); |
| 10417 "parseVariableDeclarationStatementAfterMetadata", | 13145 VariableDeclarationStatement statement = |
| 10418 <Object>[emptyCommentAndMetadata()], | 13146 parser.parseVariableDeclarationStatementAfterMetadata( |
| 10419 "var x, y, z;"); | 13147 emptyCommentAndMetadata()); |
| 13148 expectNotNullIfNoErrors(statement); |
| 13149 listener.assertNoErrors(); |
| 10420 expect(statement.semicolon, isNotNull); | 13150 expect(statement.semicolon, isNotNull); |
| 10421 VariableDeclarationList variableList = statement.variables; | 13151 VariableDeclarationList variableList = statement.variables; |
| 10422 expect(variableList, isNotNull); | 13152 expect(variableList, isNotNull); |
| 10423 expect(variableList.variables, hasLength(3)); | 13153 expect(variableList.variables, hasLength(3)); |
| 10424 } | 13154 } |
| 10425 | 13155 |
| 10426 void test_parseVariableDeclarationStatementAfterMetadata_single() { | 13156 void test_parseVariableDeclarationStatementAfterMetadata_single() { |
| 10427 VariableDeclarationStatement statement = parse( | 13157 createParser('var x;'); |
| 10428 "parseVariableDeclarationStatementAfterMetadata", | 13158 VariableDeclarationStatement statement = |
| 10429 <Object>[emptyCommentAndMetadata()], | 13159 parser.parseVariableDeclarationStatementAfterMetadata( |
| 10430 "var x;"); | 13160 emptyCommentAndMetadata()); |
| 13161 expectNotNullIfNoErrors(statement); |
| 13162 listener.assertNoErrors(); |
| 10431 expect(statement.semicolon, isNotNull); | 13163 expect(statement.semicolon, isNotNull); |
| 10432 VariableDeclarationList variableList = statement.variables; | 13164 VariableDeclarationList variableList = statement.variables; |
| 10433 expect(variableList, isNotNull); | 13165 expect(variableList, isNotNull); |
| 10434 expect(variableList.variables, hasLength(1)); | 13166 expect(variableList.variables, hasLength(1)); |
| 10435 } | 13167 } |
| 10436 | 13168 |
| 10437 void test_parseWhileStatement() { | 13169 void test_parseWhileStatement() { |
| 10438 WhileStatement statement = parse4("parseWhileStatement", "while (x) {}"); | 13170 createParser('while (x) {}'); |
| 13171 WhileStatement statement = parser.parseWhileStatement(); |
| 13172 expectNotNullIfNoErrors(statement); |
| 13173 listener.assertNoErrors(); |
| 10439 expect(statement.whileKeyword, isNotNull); | 13174 expect(statement.whileKeyword, isNotNull); |
| 10440 expect(statement.leftParenthesis, isNotNull); | 13175 expect(statement.leftParenthesis, isNotNull); |
| 10441 expect(statement.condition, isNotNull); | 13176 expect(statement.condition, isNotNull); |
| 10442 expect(statement.rightParenthesis, isNotNull); | 13177 expect(statement.rightParenthesis, isNotNull); |
| 10443 expect(statement.body, isNotNull); | 13178 expect(statement.body, isNotNull); |
| 10444 } | 13179 } |
| 10445 | 13180 |
| 10446 void test_parseWithClause_multiple() { | 13181 void test_parseWithClause_multiple() { |
| 10447 WithClause clause = parse4("parseWithClause", "with A, B, C"); | 13182 createParser('with A, B, C'); |
| 13183 WithClause clause = parser.parseWithClause(); |
| 13184 expectNotNullIfNoErrors(clause); |
| 13185 listener.assertNoErrors(); |
| 10448 expect(clause.withKeyword, isNotNull); | 13186 expect(clause.withKeyword, isNotNull); |
| 10449 expect(clause.mixinTypes, hasLength(3)); | 13187 expect(clause.mixinTypes, hasLength(3)); |
| 10450 } | 13188 } |
| 10451 | 13189 |
| 10452 void test_parseWithClause_single() { | 13190 void test_parseWithClause_single() { |
| 10453 WithClause clause = parse4("parseWithClause", "with M"); | 13191 createParser('with M'); |
| 13192 WithClause clause = parser.parseWithClause(); |
| 13193 expectNotNullIfNoErrors(clause); |
| 13194 listener.assertNoErrors(); |
| 10454 expect(clause.withKeyword, isNotNull); | 13195 expect(clause.withKeyword, isNotNull); |
| 10455 expect(clause.mixinTypes, hasLength(1)); | 13196 expect(clause.mixinTypes, hasLength(1)); |
| 10456 } | 13197 } |
| 10457 | 13198 |
| 10458 void test_parseYieldStatement_each() { | 13199 void test_parseYieldStatement_each() { |
| 10459 YieldStatement statement = parse4("parseYieldStatement", "yield* x;"); | 13200 createParser('yield* x;'); |
| 13201 YieldStatement statement = parser.parseYieldStatement(); |
| 13202 expectNotNullIfNoErrors(statement); |
| 13203 listener.assertNoErrors(); |
| 10460 expect(statement.yieldKeyword, isNotNull); | 13204 expect(statement.yieldKeyword, isNotNull); |
| 10461 expect(statement.star, isNotNull); | 13205 expect(statement.star, isNotNull); |
| 10462 expect(statement.expression, isNotNull); | 13206 expect(statement.expression, isNotNull); |
| 10463 expect(statement.semicolon, isNotNull); | 13207 expect(statement.semicolon, isNotNull); |
| 10464 } | 13208 } |
| 10465 | 13209 |
| 10466 void test_parseYieldStatement_normal() { | 13210 void test_parseYieldStatement_normal() { |
| 10467 YieldStatement statement = parse4("parseYieldStatement", "yield x;"); | 13211 createParser('yield x;'); |
| 13212 YieldStatement statement = parser.parseYieldStatement(); |
| 13213 expectNotNullIfNoErrors(statement); |
| 13214 listener.assertNoErrors(); |
| 10468 expect(statement.yieldKeyword, isNotNull); | 13215 expect(statement.yieldKeyword, isNotNull); |
| 10469 expect(statement.star, isNull); | 13216 expect(statement.star, isNull); |
| 10470 expect(statement.expression, isNotNull); | 13217 expect(statement.expression, isNotNull); |
| 10471 expect(statement.semicolon, isNotNull); | 13218 expect(statement.semicolon, isNotNull); |
| 10472 } | 13219 } |
| 10473 | 13220 |
| 10474 void test_skipPrefixedIdentifier_invalid() { | 13221 void test_skipPrefixedIdentifier_invalid() { |
| 10475 Token following = _skip("skipPrefixedIdentifier", "+"); | 13222 createParser('+'); |
| 13223 Token following = parser.skipPrefixedIdentifier(parser.currentToken); |
| 10476 expect(following, isNull); | 13224 expect(following, isNull); |
| 10477 } | 13225 } |
| 10478 | 13226 |
| 10479 void test_skipPrefixedIdentifier_notPrefixed() { | 13227 void test_skipPrefixedIdentifier_notPrefixed() { |
| 10480 Token following = _skip("skipPrefixedIdentifier", "a +"); | 13228 createParser('a +'); |
| 13229 Token following = parser.skipPrefixedIdentifier(parser.currentToken); |
| 10481 expect(following, isNotNull); | 13230 expect(following, isNotNull); |
| 10482 expect(following.type, TokenType.PLUS); | 13231 expect(following.type, TokenType.PLUS); |
| 10483 } | 13232 } |
| 10484 | 13233 |
| 10485 void test_skipPrefixedIdentifier_prefixed() { | 13234 void test_skipPrefixedIdentifier_prefixed() { |
| 10486 Token following = _skip("skipPrefixedIdentifier", "a.b +"); | 13235 createParser('a.b +'); |
| 13236 Token following = parser.skipPrefixedIdentifier(parser.currentToken); |
| 10487 expect(following, isNotNull); | 13237 expect(following, isNotNull); |
| 10488 expect(following.type, TokenType.PLUS); | 13238 expect(following.type, TokenType.PLUS); |
| 10489 } | 13239 } |
| 10490 | 13240 |
| 10491 void test_skipReturnType_invalid() { | 13241 void test_skipReturnType_invalid() { |
| 10492 Token following = _skip("skipReturnType", "+"); | 13242 createParser('+'); |
| 13243 Token following = parser.skipReturnType(parser.currentToken); |
| 10493 expect(following, isNull); | 13244 expect(following, isNull); |
| 10494 } | 13245 } |
| 10495 | 13246 |
| 10496 void test_skipReturnType_type() { | 13247 void test_skipReturnType_type() { |
| 10497 Token following = _skip("skipReturnType", "C +"); | 13248 createParser('C +'); |
| 13249 Token following = parser.skipReturnType(parser.currentToken); |
| 10498 expect(following, isNotNull); | 13250 expect(following, isNotNull); |
| 10499 expect(following.type, TokenType.PLUS); | 13251 expect(following.type, TokenType.PLUS); |
| 10500 } | 13252 } |
| 10501 | 13253 |
| 10502 void test_skipReturnType_void() { | 13254 void test_skipReturnType_void() { |
| 10503 Token following = _skip("skipReturnType", "void +"); | 13255 createParser('void +'); |
| 13256 Token following = parser.skipReturnType(parser.currentToken); |
| 10504 expect(following, isNotNull); | 13257 expect(following, isNotNull); |
| 10505 expect(following.type, TokenType.PLUS); | 13258 expect(following.type, TokenType.PLUS); |
| 10506 } | 13259 } |
| 10507 | 13260 |
| 10508 void test_skipSimpleIdentifier_identifier() { | 13261 void test_skipSimpleIdentifier_identifier() { |
| 10509 Token following = _skip("skipSimpleIdentifier", "i +"); | 13262 createParser('i +'); |
| 13263 Token following = parser.skipSimpleIdentifier(parser.currentToken); |
| 10510 expect(following, isNotNull); | 13264 expect(following, isNotNull); |
| 10511 expect(following.type, TokenType.PLUS); | 13265 expect(following.type, TokenType.PLUS); |
| 10512 } | 13266 } |
| 10513 | 13267 |
| 10514 void test_skipSimpleIdentifier_invalid() { | 13268 void test_skipSimpleIdentifier_invalid() { |
| 10515 Token following = _skip("skipSimpleIdentifier", "9 +"); | 13269 createParser('9 +'); |
| 13270 Token following = parser.skipSimpleIdentifier(parser.currentToken); |
| 10516 expect(following, isNull); | 13271 expect(following, isNull); |
| 10517 } | 13272 } |
| 10518 | 13273 |
| 10519 void test_skipSimpleIdentifier_pseudoKeyword() { | 13274 void test_skipSimpleIdentifier_pseudoKeyword() { |
| 10520 Token following = _skip("skipSimpleIdentifier", "as +"); | 13275 createParser('as +'); |
| 13276 Token following = parser.skipSimpleIdentifier(parser.currentToken); |
| 10521 expect(following, isNotNull); | 13277 expect(following, isNotNull); |
| 10522 expect(following.type, TokenType.PLUS); | 13278 expect(following.type, TokenType.PLUS); |
| 10523 } | 13279 } |
| 10524 | 13280 |
| 10525 void test_skipStringLiteral_adjacent() { | 13281 void test_skipStringLiteral_adjacent() { |
| 10526 Token following = _skip("skipStringLiteral", "'a' 'b' +"); | 13282 createParser("'a' 'b' +"); |
| 13283 Token following = parser.skipStringLiteral(parser.currentToken); |
| 10527 expect(following, isNotNull); | 13284 expect(following, isNotNull); |
| 10528 expect(following.type, TokenType.PLUS); | 13285 expect(following.type, TokenType.PLUS); |
| 10529 } | 13286 } |
| 10530 | 13287 |
| 10531 void test_skipStringLiteral_interpolated() { | 13288 void test_skipStringLiteral_interpolated() { |
| 10532 Token following = _skip("skipStringLiteral", "'a\${b}c' +"); | 13289 createParser("'a\${b}c' +"); |
| 13290 Token following = parser.skipStringLiteral(parser.currentToken); |
| 10533 expect(following, isNotNull); | 13291 expect(following, isNotNull); |
| 10534 expect(following.type, TokenType.PLUS); | 13292 expect(following.type, TokenType.PLUS); |
| 10535 } | 13293 } |
| 10536 | 13294 |
| 10537 void test_skipStringLiteral_invalid() { | 13295 void test_skipStringLiteral_invalid() { |
| 10538 Token following = _skip("skipStringLiteral", "a"); | 13296 createParser('a'); |
| 13297 Token following = parser.skipStringLiteral(parser.currentToken); |
| 10539 expect(following, isNull); | 13298 expect(following, isNull); |
| 10540 } | 13299 } |
| 10541 | 13300 |
| 10542 void test_skipStringLiteral_single() { | 13301 void test_skipStringLiteral_single() { |
| 10543 Token following = _skip("skipStringLiteral", "'a' +"); | 13302 createParser("'a' +"); |
| 13303 Token following = parser.skipStringLiteral(parser.currentToken); |
| 10544 expect(following, isNotNull); | 13304 expect(following, isNotNull); |
| 10545 expect(following.type, TokenType.PLUS); | 13305 expect(following.type, TokenType.PLUS); |
| 10546 } | 13306 } |
| 10547 | 13307 |
| 10548 void test_skipTypeArgumentList_invalid() { | 13308 void test_skipTypeArgumentList_invalid() { |
| 10549 Token following = _skip("skipTypeArgumentList", "+"); | 13309 createParser('+'); |
| 13310 Token following = parser.skipTypeArgumentList(parser.currentToken); |
| 10550 expect(following, isNull); | 13311 expect(following, isNull); |
| 10551 } | 13312 } |
| 10552 | 13313 |
| 10553 void test_skipTypeArgumentList_multiple() { | 13314 void test_skipTypeArgumentList_multiple() { |
| 10554 Token following = _skip("skipTypeArgumentList", "<E, F, G> +"); | 13315 createParser('<E, F, G> +'); |
| 13316 Token following = parser.skipTypeArgumentList(parser.currentToken); |
| 10555 expect(following, isNotNull); | 13317 expect(following, isNotNull); |
| 10556 expect(following.type, TokenType.PLUS); | 13318 expect(following.type, TokenType.PLUS); |
| 10557 } | 13319 } |
| 10558 | 13320 |
| 10559 void test_skipTypeArgumentList_single() { | 13321 void test_skipTypeArgumentList_single() { |
| 10560 Token following = _skip("skipTypeArgumentList", "<E> +"); | 13322 createParser('<E> +'); |
| 13323 Token following = parser.skipTypeArgumentList(parser.currentToken); |
| 10561 expect(following, isNotNull); | 13324 expect(following, isNotNull); |
| 10562 expect(following.type, TokenType.PLUS); | 13325 expect(following.type, TokenType.PLUS); |
| 10563 } | 13326 } |
| 10564 | 13327 |
| 10565 void test_skipTypeName_invalid() { | 13328 void test_skipTypeName_invalid() { |
| 10566 Token following = _skip("skipTypeName", "+"); | 13329 createParser('+'); |
| 13330 Token following = parser.skipTypeName(parser.currentToken); |
| 10567 expect(following, isNull); | 13331 expect(following, isNull); |
| 10568 } | 13332 } |
| 10569 | 13333 |
| 10570 void test_skipTypeName_parameterized() { | 13334 void test_skipTypeName_parameterized() { |
| 10571 Token following = _skip("skipTypeName", "C<E<F<G>>> +"); | 13335 createParser('C<E<F<G>>> +'); |
| 13336 Token following = parser.skipTypeName(parser.currentToken); |
| 10572 expect(following, isNotNull); | 13337 expect(following, isNotNull); |
| 10573 expect(following.type, TokenType.PLUS); | 13338 expect(following.type, TokenType.PLUS); |
| 10574 } | 13339 } |
| 10575 | 13340 |
| 10576 void test_skipTypeName_simple() { | 13341 void test_skipTypeName_simple() { |
| 10577 Token following = _skip("skipTypeName", "C +"); | 13342 createParser('C +'); |
| 13343 Token following = parser.skipTypeName(parser.currentToken); |
| 10578 expect(following, isNotNull); | 13344 expect(following, isNotNull); |
| 10579 expect(following.type, TokenType.PLUS); | 13345 expect(following.type, TokenType.PLUS); |
| 10580 } | 13346 } |
| 10581 | 13347 |
| 10582 /** | 13348 /** |
| 10583 * Invoke the method [Parser.computeStringValue] with the given argument. | 13349 * Invoke the method [Parser.computeStringValue] with the given argument. |
| 10584 * | 13350 * |
| 10585 * @param lexeme the argument to the method | 13351 * @param lexeme the argument to the method |
| 10586 * @param first `true` if this is the first token in a string literal | 13352 * @param first `true` if this is the first token in a string literal |
| 10587 * @param last `true` if this is the last token in a string literal | 13353 * @param last `true` if this is the last token in a string literal |
| 10588 * @return the result of invoking the method | 13354 * @return the result of invoking the method |
| 10589 * @throws Exception if the method could not be invoked or throws an exception | 13355 * @throws Exception if the method could not be invoked or throws an exception |
| 10590 */ | 13356 */ |
| 10591 String _computeStringValue(String lexeme, bool first, bool last) { | 13357 String _computeStringValue(String lexeme, bool first, bool last) { |
| 10592 AnalysisErrorListener listener = | 13358 createParser(''); |
| 10593 new AnalysisErrorListener_SimpleParserTest_computeStringValue(); | 13359 String value = parser.computeStringValue(lexeme, first, last); |
| 10594 Parser parser = new Parser(null, listener); | 13360 listener.assertNoErrors(); |
| 10595 return invokeParserMethodImpl( | 13361 return value; |
| 10596 parser, "computeStringValue", <Object>[lexeme, first, last], null) | 13362 } |
| 10597 as String; | 13363 |
| 13364 void _expectDottedName(DottedName name, List<String> expectedComponents) { |
| 13365 int count = expectedComponents.length; |
| 13366 NodeList<SimpleIdentifier> components = name.components; |
| 13367 expect(components, hasLength(count)); |
| 13368 for (int i = 0; i < count; i++) { |
| 13369 SimpleIdentifier component = components[i]; |
| 13370 expect(component, isNotNull); |
| 13371 expect(component.name, expectedComponents[i]); |
| 13372 } |
| 10598 } | 13373 } |
| 10599 | 13374 |
| 10600 /** | 13375 /** |
| 10601 * Invoke the method [Parser.createSyntheticIdentifier] with the parser set to
the token | |
| 10602 * stream produced by scanning the given source. | |
| 10603 * | |
| 10604 * @param source the source to be scanned to produce the token stream being te
sted | |
| 10605 * @return the result of invoking the method | |
| 10606 * @throws Exception if the method could not be invoked or throws an exception | |
| 10607 */ | |
| 10608 SimpleIdentifier _createSyntheticIdentifier() { | |
| 10609 GatheringErrorListener listener = new GatheringErrorListener(); | |
| 10610 return invokeParserMethod2("createSyntheticIdentifier", "", listener); | |
| 10611 } | |
| 10612 | |
| 10613 /** | |
| 10614 * Invoke the method [Parser.createSyntheticIdentifier] with the parser set to
the token | |
| 10615 * stream produced by scanning the given source. | |
| 10616 * | |
| 10617 * @param source the source to be scanned to produce the token stream being te
sted | |
| 10618 * @return the result of invoking the method | |
| 10619 * @throws Exception if the method could not be invoked or throws an exception | |
| 10620 */ | |
| 10621 SimpleStringLiteral _createSyntheticStringLiteral() { | |
| 10622 GatheringErrorListener listener = new GatheringErrorListener(); | |
| 10623 return invokeParserMethod2("createSyntheticStringLiteral", "", listener); | |
| 10624 } | |
| 10625 | |
| 10626 /** | |
| 10627 * Invoke the method [Parser.isFunctionDeclaration] with the parser set to the
token | 13376 * Invoke the method [Parser.isFunctionDeclaration] with the parser set to the
token |
| 10628 * stream produced by scanning the given source. | 13377 * stream produced by scanning the given source. |
| 10629 * | 13378 * |
| 10630 * @param source the source to be scanned to produce the token stream being te
sted | 13379 * @param source the source to be scanned to produce the token stream being te
sted |
| 10631 * @return the result of invoking the method | 13380 * @return the result of invoking the method |
| 10632 * @throws Exception if the method could not be invoked or throws an exception | 13381 * @throws Exception if the method could not be invoked or throws an exception |
| 10633 */ | 13382 */ |
| 10634 bool _isFunctionDeclaration(String source) { | 13383 bool _isFunctionDeclaration(String source) { |
| 10635 GatheringErrorListener listener = new GatheringErrorListener(); | 13384 createParser(source); |
| 10636 return invokeParserMethod2("isFunctionDeclaration", source, listener) | 13385 bool result = parser.isFunctionDeclaration(); |
| 10637 as bool; | 13386 expectNotNullIfNoErrors(result); |
| 13387 return result; |
| 10638 } | 13388 } |
| 10639 | 13389 |
| 10640 /** | 13390 /** |
| 10641 * Invoke the method [Parser.isFunctionExpression] with the parser set to the
token stream | 13391 * Invoke the method [Parser.isFunctionExpression] with the parser set to the
token stream |
| 10642 * produced by scanning the given source. | 13392 * produced by scanning the given source. |
| 10643 * | 13393 * |
| 10644 * @param source the source to be scanned to produce the token stream being te
sted | 13394 * @param source the source to be scanned to produce the token stream being te
sted |
| 10645 * @return the result of invoking the method | 13395 * @return the result of invoking the method |
| 10646 * @throws Exception if the method could not be invoked or throws an exception | 13396 * @throws Exception if the method could not be invoked or throws an exception |
| 10647 */ | 13397 */ |
| 10648 bool _isFunctionExpression(String source) { | 13398 bool _isFunctionExpression(String source) { |
| 10649 GatheringErrorListener listener = new GatheringErrorListener(); | 13399 createParser(source); |
| 10650 // | 13400 return parser.isFunctionExpression(parser.currentToken); |
| 10651 // Scan the source. | |
| 10652 // | |
| 10653 Scanner scanner = | |
| 10654 new Scanner(null, new CharSequenceReader(source), listener); | |
| 10655 Token tokenStream = scanner.tokenize(); | |
| 10656 // | |
| 10657 // Parse the source. | |
| 10658 // | |
| 10659 Parser parser = new Parser(null, listener); | |
| 10660 return invokeParserMethodImpl( | |
| 10661 parser, "isFunctionExpression", <Object>[tokenStream], tokenStream) | |
| 10662 as bool; | |
| 10663 } | 13401 } |
| 10664 | 13402 |
| 10665 /** | 13403 /** |
| 10666 * Invoke the method [Parser.isInitializedVariableDeclaration] with the parser
set to the | 13404 * Invoke the method [Parser.isInitializedVariableDeclaration] with the parser
set to the |
| 10667 * token stream produced by scanning the given source. | 13405 * token stream produced by scanning the given source. |
| 10668 * | 13406 * |
| 10669 * @param source the source to be scanned to produce the token stream being te
sted | 13407 * @param source the source to be scanned to produce the token stream being te
sted |
| 10670 * @return the result of invoking the method | 13408 * @return the result of invoking the method |
| 10671 * @throws Exception if the method could not be invoked or throws an exception | 13409 * @throws Exception if the method could not be invoked or throws an exception |
| 10672 */ | 13410 */ |
| 10673 bool _isInitializedVariableDeclaration(String source) { | 13411 bool _isInitializedVariableDeclaration(String source) { |
| 10674 GatheringErrorListener listener = new GatheringErrorListener(); | 13412 createParser(source); |
| 10675 return invokeParserMethod2( | 13413 bool result = parser.isInitializedVariableDeclaration(); |
| 10676 "isInitializedVariableDeclaration", source, listener) as bool; | 13414 expectNotNullIfNoErrors(result); |
| 13415 return result; |
| 10677 } | 13416 } |
| 10678 | 13417 |
| 10679 /** | 13418 /** |
| 10680 * Invoke the method [Parser.isSwitchMember] with the parser set to the token
stream | 13419 * Invoke the method [Parser.isSwitchMember] with the parser set to the token
stream |
| 10681 * produced by scanning the given source. | 13420 * produced by scanning the given source. |
| 10682 * | 13421 * |
| 10683 * @param source the source to be scanned to produce the token stream being te
sted | 13422 * @param source the source to be scanned to produce the token stream being te
sted |
| 10684 * @return the result of invoking the method | 13423 * @return the result of invoking the method |
| 10685 * @throws Exception if the method could not be invoked or throws an exception | 13424 * @throws Exception if the method could not be invoked or throws an exception |
| 10686 */ | 13425 */ |
| 10687 bool _isSwitchMember(String source) { | 13426 bool _isSwitchMember(String source) { |
| 10688 GatheringErrorListener listener = new GatheringErrorListener(); | 13427 createParser(source); |
| 10689 return invokeParserMethod2("isSwitchMember", source, listener) as bool; | 13428 bool result = parser.isSwitchMember(); |
| 13429 expectNotNullIfNoErrors(result); |
| 13430 return result; |
| 10690 } | 13431 } |
| 10691 | 13432 |
| 10692 /** | 13433 /** |
| 10693 * Parse the given source as a compilation unit. | 13434 * Parse the given source as a compilation unit. |
| 10694 * | 13435 * |
| 10695 * @param source the source to be parsed | 13436 * @param source the source to be parsed |
| 10696 * @param errorCodes the error codes of the errors that are expected to be fou
nd | 13437 * @param errorCodes the error codes of the errors that are expected to be fou
nd |
| 10697 * @return the compilation unit that was parsed | 13438 * @return the compilation unit that was parsed |
| 10698 * @throws Exception if the source could not be parsed, if the compilation err
ors in the source do | 13439 * @throws Exception if the source could not be parsed, if the compilation err
ors in the source do |
| 10699 * not match those that are expected, or if the result would have be
en `null` | 13440 * not match those that are expected, or if the result would have be
en `null` |
| 10700 */ | 13441 */ |
| 10701 CompilationUnit _parseDirectives(String source, | 13442 CompilationUnit _parseDirectives(String source, |
| 10702 [List<ErrorCode> errorCodes = ErrorCode.EMPTY_LIST]) { | 13443 [List<ErrorCode> errorCodes = ErrorCode.EMPTY_LIST]) { |
| 10703 GatheringErrorListener listener = new GatheringErrorListener(); | 13444 createParser(source); |
| 10704 Scanner scanner = | 13445 CompilationUnit unit = parser.parseDirectives2(); |
| 10705 new Scanner(null, new CharSequenceReader(source), listener); | |
| 10706 listener.setLineInfo(new TestSource(), scanner.lineStarts); | |
| 10707 Token token = scanner.tokenize(); | |
| 10708 Parser parser = new Parser(null, listener); | |
| 10709 CompilationUnit unit = parser.parseDirectives(token); | |
| 10710 expect(unit, isNotNull); | 13446 expect(unit, isNotNull); |
| 10711 expect(unit.declarations, hasLength(0)); | 13447 expect(unit.declarations, hasLength(0)); |
| 10712 listener.assertErrorsWithCodes(errorCodes); | 13448 listener.assertErrorsWithCodes(errorCodes); |
| 10713 return unit; | 13449 return unit; |
| 10714 } | 13450 } |
| 10715 | |
| 10716 /** | |
| 10717 * Invoke a "skip" method in [Parser]. The method is assumed to take a token a
s it's | |
| 10718 * parameter and is given the first token in the scanned source. | |
| 10719 * | |
| 10720 * @param methodName the name of the method that should be invoked | |
| 10721 * @param source the source to be processed by the method | |
| 10722 * @return the result of invoking the method | |
| 10723 * @throws Exception if the method could not be invoked or throws an exception | |
| 10724 * @throws AssertionFailedError if the result is `null` | |
| 10725 */ | |
| 10726 Token _skip(String methodName, String source) { | |
| 10727 GatheringErrorListener listener = new GatheringErrorListener(); | |
| 10728 // | |
| 10729 // Scan the source. | |
| 10730 // | |
| 10731 Scanner scanner = | |
| 10732 new Scanner(null, new CharSequenceReader(source), listener); | |
| 10733 Token tokenStream = scanner.tokenize(); | |
| 10734 // | |
| 10735 // Parse the source. | |
| 10736 // | |
| 10737 Parser parser = new Parser(null, listener); | |
| 10738 return invokeParserMethodImpl( | |
| 10739 parser, methodName, <Object>[tokenStream], tokenStream) as Token; | |
| 10740 } | |
| 10741 } | 13451 } |
| OLD | NEW |