| 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 import 'package:analyzer/dart/ast/ast.dart'; | 5 import 'package:analyzer/dart/ast/ast.dart'; |
| 6 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; | 6 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; |
| 7 import 'package:analyzer/dart/ast/token.dart'; | 7 import 'package:analyzer/dart/ast/token.dart'; |
| 8 import 'package:analyzer/dart/ast/visitor.dart'; | 8 import 'package:analyzer/dart/ast/visitor.dart'; |
| 9 import 'package:analyzer/error/error.dart'; | 9 import 'package:analyzer/error/error.dart'; |
| 10 import 'package:analyzer/error/listener.dart'; | 10 import 'package:analyzer/error/listener.dart'; |
| (...skipping 8710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8721 /** | 8721 /** |
| 8722 * Parse the given [source] as a statement. If [enableLazyAssignmentOperators] | 8722 * Parse the given [source] as a statement. If [enableLazyAssignmentOperators] |
| 8723 * is `true`, then lazy assignment operators should be enabled. | 8723 * is `true`, then lazy assignment operators should be enabled. |
| 8724 */ | 8724 */ |
| 8725 Statement parseStatement(String source, | 8725 Statement parseStatement(String source, |
| 8726 [bool enableLazyAssignmentOperators]) { | 8726 [bool enableLazyAssignmentOperators]) { |
| 8727 listener = new GatheringErrorListener(); | 8727 listener = new GatheringErrorListener(); |
| 8728 Scanner scanner = | 8728 Scanner scanner = |
| 8729 new Scanner(null, new CharSequenceReader(source), listener); | 8729 new Scanner(null, new CharSequenceReader(source), listener); |
| 8730 scanner.scanGenericMethodComments = enableGenericMethodComments; | 8730 scanner.scanGenericMethodComments = enableGenericMethodComments; |
| 8731 scanner.scanLazyAssignmentOperators = enableLazyAssignmentOperators; | 8731 if (enableLazyAssignmentOperators != null) { |
| 8732 scanner.scanLazyAssignmentOperators = enableLazyAssignmentOperators; |
| 8733 } |
| 8732 listener.setLineInfo(new TestSource(), scanner.lineStarts); | 8734 listener.setLineInfo(new TestSource(), scanner.lineStarts); |
| 8733 Token token = scanner.tokenize(); | 8735 Token token = scanner.tokenize(); |
| 8734 Parser parser = new Parser(null, listener); | 8736 Parser parser = new Parser(null, listener); |
| 8735 parser.parseGenericMethodComments = enableGenericMethodComments; | 8737 parser.parseGenericMethodComments = enableGenericMethodComments; |
| 8736 Statement statement = parser.parseStatement(token); | 8738 Statement statement = parser.parseStatement(token); |
| 8737 expect(statement, isNotNull); | 8739 expect(statement, isNotNull); |
| 8738 return statement; | 8740 return statement; |
| 8739 } | 8741 } |
| 8740 | 8742 |
| 8741 /** | 8743 /** |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8826 expect(components, hasLength(count)); | 8828 expect(components, hasLength(count)); |
| 8827 for (int i = 0; i < count; i++) { | 8829 for (int i = 0; i < count; i++) { |
| 8828 SimpleIdentifier component = components[i]; | 8830 SimpleIdentifier component = components[i]; |
| 8829 expect(component, isNotNull); | 8831 expect(component, isNotNull); |
| 8830 expect(component.name, expectedComponents[i]); | 8832 expect(component.name, expectedComponents[i]); |
| 8831 } | 8833 } |
| 8832 } | 8834 } |
| 8833 } | 8835 } |
| 8834 | 8836 |
| 8835 /** | 8837 /** |
| 8838 * Tests of the analyzer parser based on [RecoveryParserTestMixin]. |
| 8839 */ |
| 8840 @reflectiveTest |
| 8841 class RecoveryParserTest extends ParserTestCase with RecoveryParserTestMixin {} |
| 8842 |
| 8843 /** |
| 8836 * The class `RecoveryParserTest` defines parser tests that test the parsing of | 8844 * The class `RecoveryParserTest` defines parser tests that test the parsing of |
| 8837 * invalid code sequences to ensure that the correct recovery steps are taken in | 8845 * invalid code sequences to ensure that the correct recovery steps are taken in |
| 8838 * the parser. | 8846 * the parser. |
| 8839 */ | 8847 */ |
| 8840 @reflectiveTest | |
| 8841 class RecoveryParserTest extends ParserTestCase with RecoveryParserTestMixin {} | |
| 8842 | |
| 8843 abstract class RecoveryParserTestMixin implements AbstractParserTestCase { | 8848 abstract class RecoveryParserTestMixin implements AbstractParserTestCase { |
| 8844 void test_additiveExpression_missing_LHS() { | 8849 void test_additiveExpression_missing_LHS() { |
| 8845 BinaryExpression expression = | 8850 BinaryExpression expression = |
| 8846 parseExpression("+ y", [ParserErrorCode.MISSING_IDENTIFIER]); | 8851 parseExpression("+ y", [ParserErrorCode.MISSING_IDENTIFIER]); |
| 8847 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, | 8852 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| 8848 SimpleIdentifier, expression.leftOperand); | 8853 SimpleIdentifier, expression.leftOperand); |
| 8849 expect(expression.leftOperand.isSynthetic, isTrue); | 8854 expect(expression.leftOperand.isSynthetic, isTrue); |
| 8850 } | 8855 } |
| 8851 | 8856 |
| 8852 void test_additiveExpression_missing_LHS_RHS() { | 8857 void test_additiveExpression_missing_LHS_RHS() { |
| (...skipping 1176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10029 EngineTestCase.assertInstanceOf( | 10034 EngineTestCase.assertInstanceOf( |
| 10030 (obj) => obj is FunctionTypeAlias, FunctionTypeAlias, member); | 10035 (obj) => obj is FunctionTypeAlias, FunctionTypeAlias, member); |
| 10031 } | 10036 } |
| 10032 | 10037 |
| 10033 void test_unaryPlus() { | 10038 void test_unaryPlus() { |
| 10034 parseExpression("+2", [ParserErrorCode.MISSING_IDENTIFIER]); | 10039 parseExpression("+2", [ParserErrorCode.MISSING_IDENTIFIER]); |
| 10035 } | 10040 } |
| 10036 } | 10041 } |
| 10037 | 10042 |
| 10038 /** | 10043 /** |
| 10039 * The class `SimpleParserTest` defines parser tests that test individual parsin
g method. The | 10044 * Tests of the analyzer parser based on [SimpleParserTestMixin]. |
| 10040 * code fragments should be as minimal as possible in order to test the method,
but should not test | |
| 10041 * the interactions between the method under test and other methods. | |
| 10042 * | |
| 10043 * More complex tests should be defined in the class [ComplexParserTest]. | |
| 10044 */ | 10045 */ |
| 10045 @reflectiveTest | 10046 @reflectiveTest |
| 10046 class SimpleParserTest extends ParserTestCase { | 10047 class SimpleParserTest extends ParserTestCase with SimpleParserTestMixin { |
| 10047 void test_computeStringValue_emptyInterpolationPrefix() { | 10048 void test_computeStringValue_emptyInterpolationPrefix() { |
| 10048 expect(_computeStringValue("'''", true, false), ""); | 10049 expect(_computeStringValue("'''", true, false), ""); |
| 10049 } | 10050 } |
| 10050 | 10051 |
| 10051 void test_computeStringValue_escape_b() { | 10052 void test_computeStringValue_escape_b() { |
| 10052 expect(_computeStringValue("'\\b'", true, true), "\b"); | 10053 expect(_computeStringValue("'\\b'", true, true), "\b"); |
| 10053 } | 10054 } |
| 10054 | 10055 |
| 10055 void test_computeStringValue_escape_f() { | 10056 void test_computeStringValue_escape_f() { |
| 10056 expect(_computeStringValue("'\\f'", true, true), "\f"); | 10057 expect(_computeStringValue("'\\f'", true, true), "\f"); |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10325 } | 10326 } |
| 10326 | 10327 |
| 10327 void test_isSwitchMember_default_unlabeled() { | 10328 void test_isSwitchMember_default_unlabeled() { |
| 10328 expect(_isSwitchMember("default"), isTrue); | 10329 expect(_isSwitchMember("default"), isTrue); |
| 10329 } | 10330 } |
| 10330 | 10331 |
| 10331 void test_isSwitchMember_false() { | 10332 void test_isSwitchMember_false() { |
| 10332 expect(_isSwitchMember("break;"), isFalse); | 10333 expect(_isSwitchMember("break;"), isFalse); |
| 10333 } | 10334 } |
| 10334 | 10335 |
| 10335 void test_parseAnnotation_n1() { | |
| 10336 createParser('@A'); | |
| 10337 Annotation annotation = parser.parseAnnotation(); | |
| 10338 expectNotNullIfNoErrors(annotation); | |
| 10339 listener.assertNoErrors(); | |
| 10340 expect(annotation.atSign, isNotNull); | |
| 10341 expect(annotation.name, isNotNull); | |
| 10342 expect(annotation.period, isNull); | |
| 10343 expect(annotation.constructorName, isNull); | |
| 10344 expect(annotation.arguments, isNull); | |
| 10345 } | |
| 10346 | |
| 10347 void test_parseAnnotation_n1_a() { | |
| 10348 createParser('@A(x,y)'); | |
| 10349 Annotation annotation = parser.parseAnnotation(); | |
| 10350 expectNotNullIfNoErrors(annotation); | |
| 10351 listener.assertNoErrors(); | |
| 10352 expect(annotation.atSign, isNotNull); | |
| 10353 expect(annotation.name, isNotNull); | |
| 10354 expect(annotation.period, isNull); | |
| 10355 expect(annotation.constructorName, isNull); | |
| 10356 expect(annotation.arguments, isNotNull); | |
| 10357 } | |
| 10358 | |
| 10359 void test_parseAnnotation_n2() { | |
| 10360 createParser('@A.B'); | |
| 10361 Annotation annotation = parser.parseAnnotation(); | |
| 10362 expectNotNullIfNoErrors(annotation); | |
| 10363 listener.assertNoErrors(); | |
| 10364 expect(annotation.atSign, isNotNull); | |
| 10365 expect(annotation.name, isNotNull); | |
| 10366 expect(annotation.period, isNull); | |
| 10367 expect(annotation.constructorName, isNull); | |
| 10368 expect(annotation.arguments, isNull); | |
| 10369 } | |
| 10370 | |
| 10371 void test_parseAnnotation_n2_a() { | |
| 10372 createParser('@A.B(x,y)'); | |
| 10373 Annotation annotation = parser.parseAnnotation(); | |
| 10374 expectNotNullIfNoErrors(annotation); | |
| 10375 listener.assertNoErrors(); | |
| 10376 expect(annotation.atSign, isNotNull); | |
| 10377 expect(annotation.name, isNotNull); | |
| 10378 expect(annotation.period, isNull); | |
| 10379 expect(annotation.constructorName, isNull); | |
| 10380 expect(annotation.arguments, isNotNull); | |
| 10381 } | |
| 10382 | |
| 10383 void test_parseAnnotation_n3() { | |
| 10384 createParser('@A.B.C'); | |
| 10385 Annotation annotation = parser.parseAnnotation(); | |
| 10386 expectNotNullIfNoErrors(annotation); | |
| 10387 listener.assertNoErrors(); | |
| 10388 expect(annotation.atSign, isNotNull); | |
| 10389 expect(annotation.name, isNotNull); | |
| 10390 expect(annotation.period, isNotNull); | |
| 10391 expect(annotation.constructorName, isNotNull); | |
| 10392 expect(annotation.arguments, isNull); | |
| 10393 } | |
| 10394 | |
| 10395 void test_parseAnnotation_n3_a() { | |
| 10396 createParser('@A.B.C(x,y)'); | |
| 10397 Annotation annotation = parser.parseAnnotation(); | |
| 10398 expectNotNullIfNoErrors(annotation); | |
| 10399 listener.assertNoErrors(); | |
| 10400 expect(annotation.atSign, isNotNull); | |
| 10401 expect(annotation.name, isNotNull); | |
| 10402 expect(annotation.period, isNotNull); | |
| 10403 expect(annotation.constructorName, isNotNull); | |
| 10404 expect(annotation.arguments, isNotNull); | |
| 10405 } | |
| 10406 | |
| 10407 void test_parseArgument_named() { | |
| 10408 createParser('n: x'); | |
| 10409 Expression expression = parser.parseArgument(); | |
| 10410 expectNotNullIfNoErrors(expression); | |
| 10411 listener.assertNoErrors(); | |
| 10412 expect(expression, new isInstanceOf<NamedExpression>()); | |
| 10413 NamedExpression namedExpression = expression; | |
| 10414 Label name = namedExpression.name; | |
| 10415 expect(name, isNotNull); | |
| 10416 expect(name.label, isNotNull); | |
| 10417 expect(name.colon, isNotNull); | |
| 10418 expect(namedExpression.expression, isNotNull); | |
| 10419 } | |
| 10420 | |
| 10421 void test_parseArgument_unnamed() { | |
| 10422 String lexeme = "x"; | |
| 10423 createParser(lexeme); | |
| 10424 Expression expression = parser.parseArgument(); | |
| 10425 expectNotNullIfNoErrors(expression); | |
| 10426 listener.assertNoErrors(); | |
| 10427 var identifier = expression as SimpleIdentifier; | |
| 10428 expect(identifier.name, lexeme); | |
| 10429 } | |
| 10430 | |
| 10431 void test_parseArgumentList_empty() { | |
| 10432 createParser('()'); | |
| 10433 ArgumentList argumentList = parser.parseArgumentList(); | |
| 10434 expectNotNullIfNoErrors(argumentList); | |
| 10435 listener.assertNoErrors(); | |
| 10436 NodeList<Expression> arguments = argumentList.arguments; | |
| 10437 expect(arguments, hasLength(0)); | |
| 10438 } | |
| 10439 | |
| 10440 void test_parseArgumentList_mixed() { | |
| 10441 createParser('(w, x, y: y, z: z)'); | |
| 10442 ArgumentList argumentList = parser.parseArgumentList(); | |
| 10443 expectNotNullIfNoErrors(argumentList); | |
| 10444 listener.assertNoErrors(); | |
| 10445 NodeList<Expression> arguments = argumentList.arguments; | |
| 10446 expect(arguments, hasLength(4)); | |
| 10447 } | |
| 10448 | |
| 10449 void test_parseArgumentList_noNamed() { | |
| 10450 createParser('(x, y, z)'); | |
| 10451 ArgumentList argumentList = parser.parseArgumentList(); | |
| 10452 expectNotNullIfNoErrors(argumentList); | |
| 10453 listener.assertNoErrors(); | |
| 10454 NodeList<Expression> arguments = argumentList.arguments; | |
| 10455 expect(arguments, hasLength(3)); | |
| 10456 } | |
| 10457 | |
| 10458 void test_parseArgumentList_onlyNamed() { | |
| 10459 createParser('(x: x, y: y)'); | |
| 10460 ArgumentList argumentList = parser.parseArgumentList(); | |
| 10461 expectNotNullIfNoErrors(argumentList); | |
| 10462 listener.assertNoErrors(); | |
| 10463 NodeList<Expression> arguments = argumentList.arguments; | |
| 10464 expect(arguments, hasLength(2)); | |
| 10465 } | |
| 10466 | |
| 10467 void test_parseArgumentList_trailing_comma() { | |
| 10468 createParser('(x, y, z,)'); | |
| 10469 ArgumentList argumentList = parser.parseArgumentList(); | |
| 10470 expectNotNullIfNoErrors(argumentList); | |
| 10471 listener.assertNoErrors(); | |
| 10472 NodeList<Expression> arguments = argumentList.arguments; | |
| 10473 expect(arguments, hasLength(3)); | |
| 10474 } | |
| 10475 | |
| 10476 void test_parseCombinator_hide() { | |
| 10477 createParser('hide a;'); | |
| 10478 Combinator combinator = parser.parseCombinator(); | |
| 10479 expectNotNullIfNoErrors(combinator); | |
| 10480 listener.assertNoErrors(); | |
| 10481 expect(combinator, new isInstanceOf<HideCombinator>()); | |
| 10482 HideCombinator hideCombinator = combinator; | |
| 10483 expect(hideCombinator.keyword, isNotNull); | |
| 10484 expect(hideCombinator.hiddenNames, hasLength(1)); | |
| 10485 } | |
| 10486 | |
| 10487 void test_parseCombinator_show() { | |
| 10488 createParser('show a;'); | |
| 10489 Combinator combinator = parser.parseCombinator(); | |
| 10490 expectNotNullIfNoErrors(combinator); | |
| 10491 listener.assertNoErrors(); | |
| 10492 expect(combinator, new isInstanceOf<ShowCombinator>()); | |
| 10493 ShowCombinator showCombinator = combinator; | |
| 10494 expect(showCombinator.keyword, isNotNull); | |
| 10495 expect(showCombinator.shownNames, hasLength(1)); | |
| 10496 } | |
| 10497 | |
| 10498 void test_parseCombinators_h() { | |
| 10499 createParser('hide a;'); | |
| 10500 List<Combinator> combinators = parser.parseCombinators(); | |
| 10501 expectNotNullIfNoErrors(combinators); | |
| 10502 listener.assertNoErrors(); | |
| 10503 expect(combinators, hasLength(1)); | |
| 10504 HideCombinator combinator = combinators[0] as HideCombinator; | |
| 10505 expect(combinator, isNotNull); | |
| 10506 expect(combinator.keyword, isNotNull); | |
| 10507 expect(combinator.hiddenNames, hasLength(1)); | |
| 10508 } | |
| 10509 | |
| 10510 void test_parseCombinators_hs() { | |
| 10511 createParser('hide a show b;'); | |
| 10512 List<Combinator> combinators = parser.parseCombinators(); | |
| 10513 expectNotNullIfNoErrors(combinators); | |
| 10514 listener.assertNoErrors(); | |
| 10515 expect(combinators, hasLength(2)); | |
| 10516 HideCombinator hideCombinator = combinators[0] as HideCombinator; | |
| 10517 expect(hideCombinator, isNotNull); | |
| 10518 expect(hideCombinator.keyword, isNotNull); | |
| 10519 expect(hideCombinator.hiddenNames, hasLength(1)); | |
| 10520 ShowCombinator showCombinator = combinators[1] as ShowCombinator; | |
| 10521 expect(showCombinator, isNotNull); | |
| 10522 expect(showCombinator.keyword, isNotNull); | |
| 10523 expect(showCombinator.shownNames, hasLength(1)); | |
| 10524 } | |
| 10525 | |
| 10526 void test_parseCombinators_hshs() { | |
| 10527 createParser('hide a show b hide c show d;'); | |
| 10528 List<Combinator> combinators = parser.parseCombinators(); | |
| 10529 expectNotNullIfNoErrors(combinators); | |
| 10530 listener.assertNoErrors(); | |
| 10531 expect(combinators, hasLength(4)); | |
| 10532 } | |
| 10533 | |
| 10534 void test_parseCombinators_s() { | |
| 10535 createParser('show a;'); | |
| 10536 List<Combinator> combinators = parser.parseCombinators(); | |
| 10537 expectNotNullIfNoErrors(combinators); | |
| 10538 listener.assertNoErrors(); | |
| 10539 expect(combinators, hasLength(1)); | |
| 10540 ShowCombinator combinator = combinators[0] as ShowCombinator; | |
| 10541 expect(combinator, isNotNull); | |
| 10542 expect(combinator.keyword, isNotNull); | |
| 10543 expect(combinator.shownNames, hasLength(1)); | |
| 10544 } | |
| 10545 | |
| 10546 void test_parseCommentAndMetadata_c() { | |
| 10547 createParser('/** 1 */ void'); | |
| 10548 CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); | |
| 10549 expectNotNullIfNoErrors(commentAndMetadata); | |
| 10550 listener.assertNoErrors(); | |
| 10551 expect(commentAndMetadata.comment, isNotNull); | |
| 10552 expect(commentAndMetadata.metadata, isNull); | |
| 10553 } | |
| 10554 | |
| 10555 void test_parseCommentAndMetadata_cmc() { | |
| 10556 createParser('/** 1 */ @A /** 2 */ void'); | |
| 10557 CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); | |
| 10558 expectNotNullIfNoErrors(commentAndMetadata); | |
| 10559 listener.assertNoErrors(); | |
| 10560 expect(commentAndMetadata.comment, isNotNull); | |
| 10561 expect(commentAndMetadata.metadata, hasLength(1)); | |
| 10562 } | |
| 10563 | |
| 10564 void test_parseCommentAndMetadata_cmcm() { | |
| 10565 createParser('/** 1 */ @A /** 2 */ @B void'); | |
| 10566 CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); | |
| 10567 expectNotNullIfNoErrors(commentAndMetadata); | |
| 10568 listener.assertNoErrors(); | |
| 10569 expect(commentAndMetadata.comment, isNotNull); | |
| 10570 expect(commentAndMetadata.metadata, hasLength(2)); | |
| 10571 } | |
| 10572 | |
| 10573 void test_parseCommentAndMetadata_cmm() { | |
| 10574 createParser('/** 1 */ @A @B void'); | |
| 10575 CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); | |
| 10576 expectNotNullIfNoErrors(commentAndMetadata); | |
| 10577 listener.assertNoErrors(); | |
| 10578 expect(commentAndMetadata.comment, isNotNull); | |
| 10579 expect(commentAndMetadata.metadata, hasLength(2)); | |
| 10580 } | |
| 10581 | |
| 10582 void test_parseCommentAndMetadata_m() { | |
| 10583 createParser('@A void'); | |
| 10584 CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); | |
| 10585 expectNotNullIfNoErrors(commentAndMetadata); | |
| 10586 listener.assertNoErrors(); | |
| 10587 expect(commentAndMetadata.comment, isNull); | |
| 10588 expect(commentAndMetadata.metadata, hasLength(1)); | |
| 10589 } | |
| 10590 | |
| 10591 void test_parseCommentAndMetadata_mcm() { | |
| 10592 createParser('@A /** 1 */ @B void'); | |
| 10593 CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); | |
| 10594 expectNotNullIfNoErrors(commentAndMetadata); | |
| 10595 listener.assertNoErrors(); | |
| 10596 expect(commentAndMetadata.comment, isNotNull); | |
| 10597 expect(commentAndMetadata.metadata, hasLength(2)); | |
| 10598 } | |
| 10599 | |
| 10600 void test_parseCommentAndMetadata_mcmc() { | |
| 10601 createParser('@A /** 1 */ @B /** 2 */ void'); | |
| 10602 CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); | |
| 10603 expectNotNullIfNoErrors(commentAndMetadata); | |
| 10604 listener.assertNoErrors(); | |
| 10605 expect(commentAndMetadata.comment, isNotNull); | |
| 10606 expect(commentAndMetadata.metadata, hasLength(2)); | |
| 10607 } | |
| 10608 | |
| 10609 void test_parseCommentAndMetadata_mm() { | |
| 10610 createParser('@A @B(x) void'); | |
| 10611 CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); | |
| 10612 expectNotNullIfNoErrors(commentAndMetadata); | |
| 10613 listener.assertNoErrors(); | |
| 10614 expect(commentAndMetadata.comment, isNull); | |
| 10615 expect(commentAndMetadata.metadata, hasLength(2)); | |
| 10616 } | |
| 10617 | |
| 10618 void test_parseCommentAndMetadata_none() { | |
| 10619 createParser('void'); | |
| 10620 CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); | |
| 10621 expectNotNullIfNoErrors(commentAndMetadata); | |
| 10622 listener.assertNoErrors(); | |
| 10623 expect(commentAndMetadata.comment, isNull); | |
| 10624 expect(commentAndMetadata.metadata, isNull); | |
| 10625 } | |
| 10626 | |
| 10627 void test_parseCommentAndMetadata_singleLine() { | |
| 10628 createParser(r''' | |
| 10629 /// 1 | |
| 10630 /// 2 | |
| 10631 void'''); | |
| 10632 CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); | |
| 10633 expectNotNullIfNoErrors(commentAndMetadata); | |
| 10634 listener.assertNoErrors(); | |
| 10635 expect(commentAndMetadata.comment, isNotNull); | |
| 10636 expect(commentAndMetadata.metadata, isNull); | |
| 10637 } | |
| 10638 | |
| 10639 void test_parseCommentReference_new_prefixed() { | 10336 void test_parseCommentReference_new_prefixed() { |
| 10640 createParser(''); | 10337 createParser(''); |
| 10641 CommentReference reference = parser.parseCommentReference('new a.b', 7); | 10338 CommentReference reference = parser.parseCommentReference('new a.b', 7); |
| 10642 expectNotNullIfNoErrors(reference); | 10339 expectNotNullIfNoErrors(reference); |
| 10643 listener.assertNoErrors(); | 10340 listener.assertNoErrors(); |
| 10644 expect(reference.identifier, new isInstanceOf<PrefixedIdentifier>()); | 10341 expect(reference.identifier, new isInstanceOf<PrefixedIdentifier>()); |
| 10645 PrefixedIdentifier prefixedIdentifier = reference.identifier; | 10342 PrefixedIdentifier prefixedIdentifier = reference.identifier; |
| 10646 SimpleIdentifier prefix = prefixedIdentifier.prefix; | 10343 SimpleIdentifier prefix = prefixedIdentifier.prefix; |
| 10647 expect(prefix.token, isNotNull); | 10344 expect(prefix.token, isNotNull); |
| 10648 expect(prefix.name, "a"); | 10345 expect(prefix.name, "a"); |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11066 List<CommentReference> references = parser.parseCommentReferences(tokens); | 10763 List<CommentReference> references = parser.parseCommentReferences(tokens); |
| 11067 expectNotNullIfNoErrors(references); | 10764 expectNotNullIfNoErrors(references); |
| 11068 listener.assertNoErrors(); | 10765 listener.assertNoErrors(); |
| 11069 expect(references, hasLength(1)); | 10766 expect(references, hasLength(1)); |
| 11070 CommentReference reference = references[0]; | 10767 CommentReference reference = references[0]; |
| 11071 expect(reference, isNotNull); | 10768 expect(reference, isNotNull); |
| 11072 expect(reference.identifier, isNotNull); | 10769 expect(reference.identifier, isNotNull); |
| 11073 expect(reference.offset, 15); | 10770 expect(reference.offset, 15); |
| 11074 } | 10771 } |
| 11075 | 10772 |
| 10773 void test_Parser() { |
| 10774 expect(new Parser(null, null), isNotNull); |
| 10775 } |
| 10776 |
| 10777 void test_skipPrefixedIdentifier_invalid() { |
| 10778 createParser('+'); |
| 10779 Token following = parser.skipPrefixedIdentifier(parser.currentToken); |
| 10780 expect(following, isNull); |
| 10781 } |
| 10782 |
| 10783 void test_skipPrefixedIdentifier_notPrefixed() { |
| 10784 createParser('a +'); |
| 10785 Token following = parser.skipPrefixedIdentifier(parser.currentToken); |
| 10786 expect(following, isNotNull); |
| 10787 expect(following.type, TokenType.PLUS); |
| 10788 } |
| 10789 |
| 10790 void test_skipPrefixedIdentifier_prefixed() { |
| 10791 createParser('a.b +'); |
| 10792 Token following = parser.skipPrefixedIdentifier(parser.currentToken); |
| 10793 expect(following, isNotNull); |
| 10794 expect(following.type, TokenType.PLUS); |
| 10795 } |
| 10796 |
| 10797 void test_skipReturnType_invalid() { |
| 10798 // TODO(eernst): `skipReturnType` eliminated, delete this test? |
| 10799 createParser('+'); |
| 10800 Token following = parser.skipTypeAnnotation(parser.currentToken); |
| 10801 expect(following, isNull); |
| 10802 } |
| 10803 |
| 10804 void test_skipReturnType_type() { |
| 10805 // TODO(eernst): `skipReturnType` eliminated, delete this test? |
| 10806 createParser('C +'); |
| 10807 Token following = parser.skipTypeAnnotation(parser.currentToken); |
| 10808 expect(following, isNotNull); |
| 10809 expect(following.type, TokenType.PLUS); |
| 10810 } |
| 10811 |
| 10812 void test_skipReturnType_void() { |
| 10813 // TODO(eernst): `skipReturnType` eliminated, delete this test? |
| 10814 createParser('void +'); |
| 10815 Token following = parser.skipTypeAnnotation(parser.currentToken); |
| 10816 expect(following, isNotNull); |
| 10817 expect(following.type, TokenType.PLUS); |
| 10818 } |
| 10819 |
| 10820 void test_skipSimpleIdentifier_identifier() { |
| 10821 createParser('i +'); |
| 10822 Token following = parser.skipSimpleIdentifier(parser.currentToken); |
| 10823 expect(following, isNotNull); |
| 10824 expect(following.type, TokenType.PLUS); |
| 10825 } |
| 10826 |
| 10827 void test_skipSimpleIdentifier_invalid() { |
| 10828 createParser('9 +'); |
| 10829 Token following = parser.skipSimpleIdentifier(parser.currentToken); |
| 10830 expect(following, isNull); |
| 10831 } |
| 10832 |
| 10833 void test_skipSimpleIdentifier_pseudoKeyword() { |
| 10834 createParser('as +'); |
| 10835 Token following = parser.skipSimpleIdentifier(parser.currentToken); |
| 10836 expect(following, isNotNull); |
| 10837 expect(following.type, TokenType.PLUS); |
| 10838 } |
| 10839 |
| 10840 void test_skipStringLiteral_adjacent() { |
| 10841 createParser("'a' 'b' +"); |
| 10842 Token following = parser.skipStringLiteral(parser.currentToken); |
| 10843 expect(following, isNotNull); |
| 10844 expect(following.type, TokenType.PLUS); |
| 10845 } |
| 10846 |
| 10847 void test_skipStringLiteral_interpolated() { |
| 10848 createParser("'a\${b}c' +"); |
| 10849 Token following = parser.skipStringLiteral(parser.currentToken); |
| 10850 expect(following, isNotNull); |
| 10851 expect(following.type, TokenType.PLUS); |
| 10852 } |
| 10853 |
| 10854 void test_skipStringLiteral_invalid() { |
| 10855 createParser('a'); |
| 10856 Token following = parser.skipStringLiteral(parser.currentToken); |
| 10857 expect(following, isNull); |
| 10858 } |
| 10859 |
| 10860 void test_skipStringLiteral_single() { |
| 10861 createParser("'a' +"); |
| 10862 Token following = parser.skipStringLiteral(parser.currentToken); |
| 10863 expect(following, isNotNull); |
| 10864 expect(following.type, TokenType.PLUS); |
| 10865 } |
| 10866 |
| 10867 void test_skipTypeArgumentList_invalid() { |
| 10868 createParser('+'); |
| 10869 Token following = parser.skipTypeArgumentList(parser.currentToken); |
| 10870 expect(following, isNull); |
| 10871 } |
| 10872 |
| 10873 void test_skipTypeArgumentList_multiple() { |
| 10874 createParser('<E, F, G> +'); |
| 10875 Token following = parser.skipTypeArgumentList(parser.currentToken); |
| 10876 expect(following, isNotNull); |
| 10877 expect(following.type, TokenType.PLUS); |
| 10878 } |
| 10879 |
| 10880 void test_skipTypeArgumentList_single() { |
| 10881 createParser('<E> +'); |
| 10882 Token following = parser.skipTypeArgumentList(parser.currentToken); |
| 10883 expect(following, isNotNull); |
| 10884 expect(following.type, TokenType.PLUS); |
| 10885 } |
| 10886 |
| 10887 void test_skipTypeName_invalid() { |
| 10888 createParser('+'); |
| 10889 Token following = parser.skipTypeName(parser.currentToken); |
| 10890 expect(following, isNull); |
| 10891 } |
| 10892 |
| 10893 void test_skipTypeName_parameterized() { |
| 10894 createParser('C<E<F<G>>> +'); |
| 10895 Token following = parser.skipTypeName(parser.currentToken); |
| 10896 expect(following, isNotNull); |
| 10897 expect(following.type, TokenType.PLUS); |
| 10898 } |
| 10899 |
| 10900 void test_skipTypeName_simple() { |
| 10901 createParser('C +'); |
| 10902 Token following = parser.skipTypeName(parser.currentToken); |
| 10903 expect(following, isNotNull); |
| 10904 expect(following.type, TokenType.PLUS); |
| 10905 } |
| 10906 |
| 10907 /** |
| 10908 * Invoke the method [Parser.computeStringValue] with the given argument. |
| 10909 * |
| 10910 * @param lexeme the argument to the method |
| 10911 * @param first `true` if this is the first token in a string literal |
| 10912 * @param last `true` if this is the last token in a string literal |
| 10913 * @return the result of invoking the method |
| 10914 * @throws Exception if the method could not be invoked or throws an exception |
| 10915 */ |
| 10916 String _computeStringValue(String lexeme, bool first, bool last) { |
| 10917 createParser(''); |
| 10918 String value = parser.computeStringValue(lexeme, first, last); |
| 10919 listener.assertNoErrors(); |
| 10920 return value; |
| 10921 } |
| 10922 |
| 10923 /** |
| 10924 * Invoke the method [Parser.isFunctionDeclaration] with the parser set to the
token |
| 10925 * stream produced by scanning the given source. |
| 10926 * |
| 10927 * @param source the source to be scanned to produce the token stream being te
sted |
| 10928 * @return the result of invoking the method |
| 10929 * @throws Exception if the method could not be invoked or throws an exception |
| 10930 */ |
| 10931 bool _isFunctionDeclaration(String source) { |
| 10932 createParser(source); |
| 10933 bool result = parser.isFunctionDeclaration(); |
| 10934 expectNotNullIfNoErrors(result); |
| 10935 return result; |
| 10936 } |
| 10937 |
| 10938 /** |
| 10939 * Invoke the method [Parser.isFunctionExpression] with the parser set to the
token stream |
| 10940 * produced by scanning the given source. |
| 10941 * |
| 10942 * @param source the source to be scanned to produce the token stream being te
sted |
| 10943 * @return the result of invoking the method |
| 10944 * @throws Exception if the method could not be invoked or throws an exception |
| 10945 */ |
| 10946 bool _isFunctionExpression(String source) { |
| 10947 createParser(source); |
| 10948 return parser.isFunctionExpression(parser.currentToken); |
| 10949 } |
| 10950 |
| 10951 /** |
| 10952 * Invoke the method [Parser.isInitializedVariableDeclaration] with the parser
set to the |
| 10953 * token stream produced by scanning the given source. |
| 10954 * |
| 10955 * @param source the source to be scanned to produce the token stream being te
sted |
| 10956 * @return the result of invoking the method |
| 10957 * @throws Exception if the method could not be invoked or throws an exception |
| 10958 */ |
| 10959 bool _isInitializedVariableDeclaration(String source) { |
| 10960 createParser(source); |
| 10961 bool result = parser.isInitializedVariableDeclaration(); |
| 10962 expectNotNullIfNoErrors(result); |
| 10963 return result; |
| 10964 } |
| 10965 |
| 10966 /** |
| 10967 * Invoke the method [Parser.isSwitchMember] with the parser set to the token
stream |
| 10968 * produced by scanning the given source. |
| 10969 * |
| 10970 * @param source the source to be scanned to produce the token stream being te
sted |
| 10971 * @return the result of invoking the method |
| 10972 * @throws Exception if the method could not be invoked or throws an exception |
| 10973 */ |
| 10974 bool _isSwitchMember(String source) { |
| 10975 createParser(source); |
| 10976 bool result = parser.isSwitchMember(); |
| 10977 expectNotNullIfNoErrors(result); |
| 10978 return result; |
| 10979 } |
| 10980 } |
| 10981 |
| 10982 /** |
| 10983 * Parser tests that test individual parsing methods. The code fragments should |
| 10984 * be as minimal as possible in order to test the method, but should not test |
| 10985 * the interactions between the method under test and other methods. |
| 10986 * |
| 10987 * More complex tests should be defined in the class [ComplexParserTest]. |
| 10988 */ |
| 10989 abstract class SimpleParserTestMixin implements AbstractParserTestCase { |
| 10990 /** |
| 10991 * Parse the given [content] as a sequence of statements by enclosing it in a |
| 10992 * block. The [expectedCount] is the number of statements that are expected to |
| 10993 * be parsed. If [errorCodes] are provided, verify that the error codes of the |
| 10994 * errors that are expected are found. |
| 10995 */ |
| 10996 void parseStatementList(String content, int expectedCount) { |
| 10997 Statement statement = parseStatement('{$content}'); |
| 10998 expect(statement, new isInstanceOf<Block>()); |
| 10999 Block block = statement; |
| 11000 expect(block.statements, hasLength(expectedCount)); |
| 11001 } |
| 11002 |
| 11003 void test_parseAnnotation_n1() { |
| 11004 createParser('@A'); |
| 11005 Annotation annotation = parser.parseAnnotation(); |
| 11006 expectNotNullIfNoErrors(annotation); |
| 11007 listener.assertNoErrors(); |
| 11008 expect(annotation.atSign, isNotNull); |
| 11009 expect(annotation.name, isNotNull); |
| 11010 expect(annotation.period, isNull); |
| 11011 expect(annotation.constructorName, isNull); |
| 11012 expect(annotation.arguments, isNull); |
| 11013 } |
| 11014 |
| 11015 void test_parseAnnotation_n1_a() { |
| 11016 createParser('@A(x,y)'); |
| 11017 Annotation annotation = parser.parseAnnotation(); |
| 11018 expectNotNullIfNoErrors(annotation); |
| 11019 listener.assertNoErrors(); |
| 11020 expect(annotation.atSign, isNotNull); |
| 11021 expect(annotation.name, isNotNull); |
| 11022 expect(annotation.period, isNull); |
| 11023 expect(annotation.constructorName, isNull); |
| 11024 expect(annotation.arguments, isNotNull); |
| 11025 } |
| 11026 |
| 11027 void test_parseAnnotation_n2() { |
| 11028 createParser('@A.B'); |
| 11029 Annotation annotation = parser.parseAnnotation(); |
| 11030 expectNotNullIfNoErrors(annotation); |
| 11031 listener.assertNoErrors(); |
| 11032 expect(annotation.atSign, isNotNull); |
| 11033 expect(annotation.name, isNotNull); |
| 11034 expect(annotation.period, isNull); |
| 11035 expect(annotation.constructorName, isNull); |
| 11036 expect(annotation.arguments, isNull); |
| 11037 } |
| 11038 |
| 11039 void test_parseAnnotation_n2_a() { |
| 11040 createParser('@A.B(x,y)'); |
| 11041 Annotation annotation = parser.parseAnnotation(); |
| 11042 expectNotNullIfNoErrors(annotation); |
| 11043 listener.assertNoErrors(); |
| 11044 expect(annotation.atSign, isNotNull); |
| 11045 expect(annotation.name, isNotNull); |
| 11046 expect(annotation.period, isNull); |
| 11047 expect(annotation.constructorName, isNull); |
| 11048 expect(annotation.arguments, isNotNull); |
| 11049 } |
| 11050 |
| 11051 void test_parseAnnotation_n3() { |
| 11052 createParser('@A.B.C'); |
| 11053 Annotation annotation = parser.parseAnnotation(); |
| 11054 expectNotNullIfNoErrors(annotation); |
| 11055 listener.assertNoErrors(); |
| 11056 expect(annotation.atSign, isNotNull); |
| 11057 expect(annotation.name, isNotNull); |
| 11058 expect(annotation.period, isNotNull); |
| 11059 expect(annotation.constructorName, isNotNull); |
| 11060 expect(annotation.arguments, isNull); |
| 11061 } |
| 11062 |
| 11063 void test_parseAnnotation_n3_a() { |
| 11064 createParser('@A.B.C(x,y)'); |
| 11065 Annotation annotation = parser.parseAnnotation(); |
| 11066 expectNotNullIfNoErrors(annotation); |
| 11067 listener.assertNoErrors(); |
| 11068 expect(annotation.atSign, isNotNull); |
| 11069 expect(annotation.name, isNotNull); |
| 11070 expect(annotation.period, isNotNull); |
| 11071 expect(annotation.constructorName, isNotNull); |
| 11072 expect(annotation.arguments, isNotNull); |
| 11073 } |
| 11074 |
| 11075 void test_parseArgument_named() { |
| 11076 createParser('n: x'); |
| 11077 Expression expression = parser.parseArgument(); |
| 11078 expectNotNullIfNoErrors(expression); |
| 11079 listener.assertNoErrors(); |
| 11080 expect(expression, new isInstanceOf<NamedExpression>()); |
| 11081 NamedExpression namedExpression = expression; |
| 11082 Label name = namedExpression.name; |
| 11083 expect(name, isNotNull); |
| 11084 expect(name.label, isNotNull); |
| 11085 expect(name.colon, isNotNull); |
| 11086 expect(namedExpression.expression, isNotNull); |
| 11087 } |
| 11088 |
| 11089 void test_parseArgument_unnamed() { |
| 11090 String lexeme = "x"; |
| 11091 createParser(lexeme); |
| 11092 Expression expression = parser.parseArgument(); |
| 11093 expectNotNullIfNoErrors(expression); |
| 11094 listener.assertNoErrors(); |
| 11095 var identifier = expression as SimpleIdentifier; |
| 11096 expect(identifier.name, lexeme); |
| 11097 } |
| 11098 |
| 11099 void test_parseArgumentList_empty() { |
| 11100 createParser('()'); |
| 11101 ArgumentList argumentList = parser.parseArgumentList(); |
| 11102 expectNotNullIfNoErrors(argumentList); |
| 11103 listener.assertNoErrors(); |
| 11104 NodeList<Expression> arguments = argumentList.arguments; |
| 11105 expect(arguments, hasLength(0)); |
| 11106 } |
| 11107 |
| 11108 void test_parseArgumentList_mixed() { |
| 11109 createParser('(w, x, y: y, z: z)'); |
| 11110 ArgumentList argumentList = parser.parseArgumentList(); |
| 11111 expectNotNullIfNoErrors(argumentList); |
| 11112 listener.assertNoErrors(); |
| 11113 NodeList<Expression> arguments = argumentList.arguments; |
| 11114 expect(arguments, hasLength(4)); |
| 11115 } |
| 11116 |
| 11117 void test_parseArgumentList_noNamed() { |
| 11118 createParser('(x, y, z)'); |
| 11119 ArgumentList argumentList = parser.parseArgumentList(); |
| 11120 expectNotNullIfNoErrors(argumentList); |
| 11121 listener.assertNoErrors(); |
| 11122 NodeList<Expression> arguments = argumentList.arguments; |
| 11123 expect(arguments, hasLength(3)); |
| 11124 } |
| 11125 |
| 11126 void test_parseArgumentList_onlyNamed() { |
| 11127 createParser('(x: x, y: y)'); |
| 11128 ArgumentList argumentList = parser.parseArgumentList(); |
| 11129 expectNotNullIfNoErrors(argumentList); |
| 11130 listener.assertNoErrors(); |
| 11131 NodeList<Expression> arguments = argumentList.arguments; |
| 11132 expect(arguments, hasLength(2)); |
| 11133 } |
| 11134 |
| 11135 void test_parseArgumentList_trailing_comma() { |
| 11136 createParser('(x, y, z,)'); |
| 11137 ArgumentList argumentList = parser.parseArgumentList(); |
| 11138 expectNotNullIfNoErrors(argumentList); |
| 11139 listener.assertNoErrors(); |
| 11140 NodeList<Expression> arguments = argumentList.arguments; |
| 11141 expect(arguments, hasLength(3)); |
| 11142 } |
| 11143 |
| 11144 void test_parseCombinator_hide() { |
| 11145 createParser('hide a;'); |
| 11146 Combinator combinator = parser.parseCombinator(); |
| 11147 expectNotNullIfNoErrors(combinator); |
| 11148 listener.assertNoErrors(); |
| 11149 expect(combinator, new isInstanceOf<HideCombinator>()); |
| 11150 HideCombinator hideCombinator = combinator; |
| 11151 expect(hideCombinator.keyword, isNotNull); |
| 11152 expect(hideCombinator.hiddenNames, hasLength(1)); |
| 11153 } |
| 11154 |
| 11155 void test_parseCombinator_show() { |
| 11156 createParser('show a;'); |
| 11157 Combinator combinator = parser.parseCombinator(); |
| 11158 expectNotNullIfNoErrors(combinator); |
| 11159 listener.assertNoErrors(); |
| 11160 expect(combinator, new isInstanceOf<ShowCombinator>()); |
| 11161 ShowCombinator showCombinator = combinator; |
| 11162 expect(showCombinator.keyword, isNotNull); |
| 11163 expect(showCombinator.shownNames, hasLength(1)); |
| 11164 } |
| 11165 |
| 11166 void test_parseCombinators_h() { |
| 11167 createParser('hide a;'); |
| 11168 List<Combinator> combinators = parser.parseCombinators(); |
| 11169 expectNotNullIfNoErrors(combinators); |
| 11170 listener.assertNoErrors(); |
| 11171 expect(combinators, hasLength(1)); |
| 11172 HideCombinator combinator = combinators[0] as HideCombinator; |
| 11173 expect(combinator, isNotNull); |
| 11174 expect(combinator.keyword, isNotNull); |
| 11175 expect(combinator.hiddenNames, hasLength(1)); |
| 11176 } |
| 11177 |
| 11178 void test_parseCombinators_hs() { |
| 11179 createParser('hide a show b;'); |
| 11180 List<Combinator> combinators = parser.parseCombinators(); |
| 11181 expectNotNullIfNoErrors(combinators); |
| 11182 listener.assertNoErrors(); |
| 11183 expect(combinators, hasLength(2)); |
| 11184 HideCombinator hideCombinator = combinators[0] as HideCombinator; |
| 11185 expect(hideCombinator, isNotNull); |
| 11186 expect(hideCombinator.keyword, isNotNull); |
| 11187 expect(hideCombinator.hiddenNames, hasLength(1)); |
| 11188 ShowCombinator showCombinator = combinators[1] as ShowCombinator; |
| 11189 expect(showCombinator, isNotNull); |
| 11190 expect(showCombinator.keyword, isNotNull); |
| 11191 expect(showCombinator.shownNames, hasLength(1)); |
| 11192 } |
| 11193 |
| 11194 void test_parseCombinators_hshs() { |
| 11195 createParser('hide a show b hide c show d;'); |
| 11196 List<Combinator> combinators = parser.parseCombinators(); |
| 11197 expectNotNullIfNoErrors(combinators); |
| 11198 listener.assertNoErrors(); |
| 11199 expect(combinators, hasLength(4)); |
| 11200 } |
| 11201 |
| 11202 void test_parseCombinators_s() { |
| 11203 createParser('show a;'); |
| 11204 List<Combinator> combinators = parser.parseCombinators(); |
| 11205 expectNotNullIfNoErrors(combinators); |
| 11206 listener.assertNoErrors(); |
| 11207 expect(combinators, hasLength(1)); |
| 11208 ShowCombinator combinator = combinators[0] as ShowCombinator; |
| 11209 expect(combinator, isNotNull); |
| 11210 expect(combinator.keyword, isNotNull); |
| 11211 expect(combinator.shownNames, hasLength(1)); |
| 11212 } |
| 11213 |
| 11214 void test_parseCommentAndMetadata_c() { |
| 11215 createParser('/** 1 */ void'); |
| 11216 CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| 11217 expectNotNullIfNoErrors(commentAndMetadata); |
| 11218 listener.assertNoErrors(); |
| 11219 expect(commentAndMetadata.comment, isNotNull); |
| 11220 expect(commentAndMetadata.metadata, isNull); |
| 11221 } |
| 11222 |
| 11223 void test_parseCommentAndMetadata_cmc() { |
| 11224 createParser('/** 1 */ @A /** 2 */ void'); |
| 11225 CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| 11226 expectNotNullIfNoErrors(commentAndMetadata); |
| 11227 listener.assertNoErrors(); |
| 11228 expect(commentAndMetadata.comment, isNotNull); |
| 11229 expect(commentAndMetadata.metadata, hasLength(1)); |
| 11230 } |
| 11231 |
| 11232 void test_parseCommentAndMetadata_cmcm() { |
| 11233 createParser('/** 1 */ @A /** 2 */ @B void'); |
| 11234 CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| 11235 expectNotNullIfNoErrors(commentAndMetadata); |
| 11236 listener.assertNoErrors(); |
| 11237 expect(commentAndMetadata.comment, isNotNull); |
| 11238 expect(commentAndMetadata.metadata, hasLength(2)); |
| 11239 } |
| 11240 |
| 11241 void test_parseCommentAndMetadata_cmm() { |
| 11242 createParser('/** 1 */ @A @B void'); |
| 11243 CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| 11244 expectNotNullIfNoErrors(commentAndMetadata); |
| 11245 listener.assertNoErrors(); |
| 11246 expect(commentAndMetadata.comment, isNotNull); |
| 11247 expect(commentAndMetadata.metadata, hasLength(2)); |
| 11248 } |
| 11249 |
| 11250 void test_parseCommentAndMetadata_m() { |
| 11251 createParser('@A void'); |
| 11252 CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| 11253 expectNotNullIfNoErrors(commentAndMetadata); |
| 11254 listener.assertNoErrors(); |
| 11255 expect(commentAndMetadata.comment, isNull); |
| 11256 expect(commentAndMetadata.metadata, hasLength(1)); |
| 11257 } |
| 11258 |
| 11259 void test_parseCommentAndMetadata_mcm() { |
| 11260 createParser('@A /** 1 */ @B void'); |
| 11261 CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| 11262 expectNotNullIfNoErrors(commentAndMetadata); |
| 11263 listener.assertNoErrors(); |
| 11264 expect(commentAndMetadata.comment, isNotNull); |
| 11265 expect(commentAndMetadata.metadata, hasLength(2)); |
| 11266 } |
| 11267 |
| 11268 void test_parseCommentAndMetadata_mcmc() { |
| 11269 createParser('@A /** 1 */ @B /** 2 */ void'); |
| 11270 CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| 11271 expectNotNullIfNoErrors(commentAndMetadata); |
| 11272 listener.assertNoErrors(); |
| 11273 expect(commentAndMetadata.comment, isNotNull); |
| 11274 expect(commentAndMetadata.metadata, hasLength(2)); |
| 11275 } |
| 11276 |
| 11277 void test_parseCommentAndMetadata_mm() { |
| 11278 createParser('@A @B(x) void'); |
| 11279 CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| 11280 expectNotNullIfNoErrors(commentAndMetadata); |
| 11281 listener.assertNoErrors(); |
| 11282 expect(commentAndMetadata.comment, isNull); |
| 11283 expect(commentAndMetadata.metadata, hasLength(2)); |
| 11284 } |
| 11285 |
| 11286 void test_parseCommentAndMetadata_none() { |
| 11287 createParser('void'); |
| 11288 CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| 11289 expectNotNullIfNoErrors(commentAndMetadata); |
| 11290 listener.assertNoErrors(); |
| 11291 expect(commentAndMetadata.comment, isNull); |
| 11292 expect(commentAndMetadata.metadata, isNull); |
| 11293 } |
| 11294 |
| 11295 void test_parseCommentAndMetadata_singleLine() { |
| 11296 createParser(r''' |
| 11297 /// 1 |
| 11298 /// 2 |
| 11299 void'''); |
| 11300 CommentAndMetadata commentAndMetadata = parser.parseCommentAndMetadata(); |
| 11301 expectNotNullIfNoErrors(commentAndMetadata); |
| 11302 listener.assertNoErrors(); |
| 11303 expect(commentAndMetadata.comment, isNotNull); |
| 11304 expect(commentAndMetadata.metadata, isNull); |
| 11305 } |
| 11306 |
| 11076 void test_parseConfiguration_noOperator_dottedIdentifier() { | 11307 void test_parseConfiguration_noOperator_dottedIdentifier() { |
| 11077 createParser("if (a.b) 'c.dart'"); | 11308 createParser("if (a.b) 'c.dart'"); |
| 11078 Configuration configuration = parser.parseConfiguration(); | 11309 Configuration configuration = parser.parseConfiguration(); |
| 11079 expectNotNullIfNoErrors(configuration); | 11310 expectNotNullIfNoErrors(configuration); |
| 11080 listener.assertNoErrors(); | 11311 listener.assertNoErrors(); |
| 11081 expect(configuration.ifKeyword, isNotNull); | 11312 expect(configuration.ifKeyword, isNotNull); |
| 11082 expect(configuration.leftParenthesis, isNotNull); | 11313 expect(configuration.leftParenthesis, isNotNull); |
| 11083 expectDottedName(configuration.name, ["a", "b"]); | 11314 expectDottedName(configuration.name, ["a", "b"]); |
| 11084 expect(configuration.equalToken, isNull); | 11315 expect(configuration.equalToken, isNull); |
| 11085 expect(configuration.value, isNull); | 11316 expect(configuration.value, isNull); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11122 listener.assertNoErrors(); | 11353 listener.assertNoErrors(); |
| 11123 expect(configuration.ifKeyword, isNotNull); | 11354 expect(configuration.ifKeyword, isNotNull); |
| 11124 expect(configuration.leftParenthesis, isNotNull); | 11355 expect(configuration.leftParenthesis, isNotNull); |
| 11125 expectDottedName(configuration.name, ["a"]); | 11356 expectDottedName(configuration.name, ["a"]); |
| 11126 expect(configuration.equalToken, isNotNull); | 11357 expect(configuration.equalToken, isNotNull); |
| 11127 expect(configuration.value, isNotNull); | 11358 expect(configuration.value, isNotNull); |
| 11128 expect(configuration.rightParenthesis, isNotNull); | 11359 expect(configuration.rightParenthesis, isNotNull); |
| 11129 expect(configuration.uri, isNotNull); | 11360 expect(configuration.uri, isNotNull); |
| 11130 } | 11361 } |
| 11131 | 11362 |
| 11132 void test_parseConstructor() { | |
| 11133 // TODO(brianwilkerson) Implement tests for this method. | |
| 11134 } | |
| 11135 | |
| 11136 void test_parseConstructorName_named_noPrefix() { | 11363 void test_parseConstructorName_named_noPrefix() { |
| 11137 createParser('A.n;'); | 11364 createParser('A.n;'); |
| 11138 ConstructorName name = parser.parseConstructorName(); | 11365 ConstructorName name = parser.parseConstructorName(); |
| 11139 expectNotNullIfNoErrors(name); | 11366 expectNotNullIfNoErrors(name); |
| 11140 listener.assertNoErrors(); | 11367 listener.assertNoErrors(); |
| 11141 expect(name.type, isNotNull); | 11368 expect(name.type, isNotNull); |
| 11142 expect(name.period, isNull); | 11369 expect(name.period, isNull); |
| 11143 expect(name.name, isNull); | 11370 expect(name.name, isNull); |
| 11144 } | 11371 } |
| 11145 | 11372 |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11682 Modifiers modifiers = parser.parseModifiers(); | 11909 Modifiers modifiers = parser.parseModifiers(); |
| 11683 expectNotNullIfNoErrors(modifiers); | 11910 expectNotNullIfNoErrors(modifiers); |
| 11684 listener.assertNoErrors(); | 11911 listener.assertNoErrors(); |
| 11685 expect(modifiers.varKeyword, isNotNull); | 11912 expect(modifiers.varKeyword, isNotNull); |
| 11686 } | 11913 } |
| 11687 | 11914 |
| 11688 void test_parseOptionalReturnType() { | 11915 void test_parseOptionalReturnType() { |
| 11689 // TODO(brianwilkerson) Implement tests for this method. | 11916 // TODO(brianwilkerson) Implement tests for this method. |
| 11690 } | 11917 } |
| 11691 | 11918 |
| 11692 void test_Parser() { | |
| 11693 expect(new Parser(null, null), isNotNull); | |
| 11694 } | |
| 11695 | |
| 11696 void test_parseReturnStatement_noValue() { | 11919 void test_parseReturnStatement_noValue() { |
| 11697 createParser('return;'); | 11920 createParser('return;'); |
| 11698 ReturnStatement statement = parser.parseReturnStatement(); | 11921 ReturnStatement statement = parser.parseReturnStatement(); |
| 11699 expectNotNullIfNoErrors(statement); | 11922 expectNotNullIfNoErrors(statement); |
| 11700 listener.assertNoErrors(); | 11923 listener.assertNoErrors(); |
| 11701 expect(statement.returnKeyword, isNotNull); | 11924 expect(statement.returnKeyword, isNotNull); |
| 11702 expect(statement.expression, isNull); | 11925 expect(statement.expression, isNull); |
| 11703 expect(statement.semicolon, isNotNull); | 11926 expect(statement.semicolon, isNotNull); |
| 11704 } | 11927 } |
| 11705 | 11928 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11752 expect(statement, new isInstanceOf<FunctionDeclarationStatement>()); | 11975 expect(statement, new isInstanceOf<FunctionDeclarationStatement>()); |
| 11753 expect( | 11976 expect( |
| 11754 (statement as FunctionDeclarationStatement) | 11977 (statement as FunctionDeclarationStatement) |
| 11755 .functionDeclaration | 11978 .functionDeclaration |
| 11756 .functionExpression | 11979 .functionExpression |
| 11757 .body, | 11980 .body, |
| 11758 new isInstanceOf<ExpressionFunctionBody>()); | 11981 new isInstanceOf<ExpressionFunctionBody>()); |
| 11759 } | 11982 } |
| 11760 | 11983 |
| 11761 void test_parseStatements_multiple() { | 11984 void test_parseStatements_multiple() { |
| 11762 List<Statement> statements = parseStatements("return; return;", 2); | 11985 parseStatementList("return; return;", 2); |
| 11763 expect(statements, hasLength(2)); | |
| 11764 } | 11986 } |
| 11765 | 11987 |
| 11766 void test_parseStatements_single() { | 11988 void test_parseStatements_single() { |
| 11767 List<Statement> statements = parseStatements("return;", 1); | 11989 parseStatementList("return;", 1); |
| 11768 expect(statements, hasLength(1)); | |
| 11769 } | 11990 } |
| 11770 | 11991 |
| 11771 void test_parseTypeAnnotation_function_noReturnType_noParameters() { | 11992 void test_parseTypeAnnotation_function_noReturnType_noParameters() { |
| 11772 createParser('Function() v'); | 11993 createParser('Function() v'); |
| 11773 GenericFunctionType functionType = parser.parseTypeAnnotation(false); | 11994 GenericFunctionType functionType = parser.parseTypeAnnotation(false); |
| 11774 expectNotNullIfNoErrors(functionType); | 11995 expectNotNullIfNoErrors(functionType); |
| 11775 listener.assertNoErrors(); | 11996 listener.assertNoErrors(); |
| 11776 expect(functionType.returnType, isNull); | 11997 expect(functionType.returnType, isNull); |
| 11777 expect(functionType.functionKeyword, isNotNull); | 11998 expect(functionType.functionKeyword, isNotNull); |
| 11778 expect(functionType.typeParameters, isNull); | 11999 expect(functionType.typeParameters, isNull); |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12218 } | 12439 } |
| 12219 | 12440 |
| 12220 void test_parseWithClause_single() { | 12441 void test_parseWithClause_single() { |
| 12221 createParser('with M'); | 12442 createParser('with M'); |
| 12222 WithClause clause = parser.parseWithClause(); | 12443 WithClause clause = parser.parseWithClause(); |
| 12223 expectNotNullIfNoErrors(clause); | 12444 expectNotNullIfNoErrors(clause); |
| 12224 listener.assertNoErrors(); | 12445 listener.assertNoErrors(); |
| 12225 expect(clause.withKeyword, isNotNull); | 12446 expect(clause.withKeyword, isNotNull); |
| 12226 expect(clause.mixinTypes, hasLength(1)); | 12447 expect(clause.mixinTypes, hasLength(1)); |
| 12227 } | 12448 } |
| 12228 | |
| 12229 void test_skipPrefixedIdentifier_invalid() { | |
| 12230 createParser('+'); | |
| 12231 Token following = parser.skipPrefixedIdentifier(parser.currentToken); | |
| 12232 expect(following, isNull); | |
| 12233 } | |
| 12234 | |
| 12235 void test_skipPrefixedIdentifier_notPrefixed() { | |
| 12236 createParser('a +'); | |
| 12237 Token following = parser.skipPrefixedIdentifier(parser.currentToken); | |
| 12238 expect(following, isNotNull); | |
| 12239 expect(following.type, TokenType.PLUS); | |
| 12240 } | |
| 12241 | |
| 12242 void test_skipPrefixedIdentifier_prefixed() { | |
| 12243 createParser('a.b +'); | |
| 12244 Token following = parser.skipPrefixedIdentifier(parser.currentToken); | |
| 12245 expect(following, isNotNull); | |
| 12246 expect(following.type, TokenType.PLUS); | |
| 12247 } | |
| 12248 | |
| 12249 void test_skipReturnType_invalid() { | |
| 12250 // TODO(eernst): `skipReturnType` eliminated, delete this test? | |
| 12251 createParser('+'); | |
| 12252 Token following = parser.skipTypeAnnotation(parser.currentToken); | |
| 12253 expect(following, isNull); | |
| 12254 } | |
| 12255 | |
| 12256 void test_skipReturnType_type() { | |
| 12257 // TODO(eernst): `skipReturnType` eliminated, delete this test? | |
| 12258 createParser('C +'); | |
| 12259 Token following = parser.skipTypeAnnotation(parser.currentToken); | |
| 12260 expect(following, isNotNull); | |
| 12261 expect(following.type, TokenType.PLUS); | |
| 12262 } | |
| 12263 | |
| 12264 void test_skipReturnType_void() { | |
| 12265 // TODO(eernst): `skipReturnType` eliminated, delete this test? | |
| 12266 createParser('void +'); | |
| 12267 Token following = parser.skipTypeAnnotation(parser.currentToken); | |
| 12268 expect(following, isNotNull); | |
| 12269 expect(following.type, TokenType.PLUS); | |
| 12270 } | |
| 12271 | |
| 12272 void test_skipSimpleIdentifier_identifier() { | |
| 12273 createParser('i +'); | |
| 12274 Token following = parser.skipSimpleIdentifier(parser.currentToken); | |
| 12275 expect(following, isNotNull); | |
| 12276 expect(following.type, TokenType.PLUS); | |
| 12277 } | |
| 12278 | |
| 12279 void test_skipSimpleIdentifier_invalid() { | |
| 12280 createParser('9 +'); | |
| 12281 Token following = parser.skipSimpleIdentifier(parser.currentToken); | |
| 12282 expect(following, isNull); | |
| 12283 } | |
| 12284 | |
| 12285 void test_skipSimpleIdentifier_pseudoKeyword() { | |
| 12286 createParser('as +'); | |
| 12287 Token following = parser.skipSimpleIdentifier(parser.currentToken); | |
| 12288 expect(following, isNotNull); | |
| 12289 expect(following.type, TokenType.PLUS); | |
| 12290 } | |
| 12291 | |
| 12292 void test_skipStringLiteral_adjacent() { | |
| 12293 createParser("'a' 'b' +"); | |
| 12294 Token following = parser.skipStringLiteral(parser.currentToken); | |
| 12295 expect(following, isNotNull); | |
| 12296 expect(following.type, TokenType.PLUS); | |
| 12297 } | |
| 12298 | |
| 12299 void test_skipStringLiteral_interpolated() { | |
| 12300 createParser("'a\${b}c' +"); | |
| 12301 Token following = parser.skipStringLiteral(parser.currentToken); | |
| 12302 expect(following, isNotNull); | |
| 12303 expect(following.type, TokenType.PLUS); | |
| 12304 } | |
| 12305 | |
| 12306 void test_skipStringLiteral_invalid() { | |
| 12307 createParser('a'); | |
| 12308 Token following = parser.skipStringLiteral(parser.currentToken); | |
| 12309 expect(following, isNull); | |
| 12310 } | |
| 12311 | |
| 12312 void test_skipStringLiteral_single() { | |
| 12313 createParser("'a' +"); | |
| 12314 Token following = parser.skipStringLiteral(parser.currentToken); | |
| 12315 expect(following, isNotNull); | |
| 12316 expect(following.type, TokenType.PLUS); | |
| 12317 } | |
| 12318 | |
| 12319 void test_skipTypeArgumentList_invalid() { | |
| 12320 createParser('+'); | |
| 12321 Token following = parser.skipTypeArgumentList(parser.currentToken); | |
| 12322 expect(following, isNull); | |
| 12323 } | |
| 12324 | |
| 12325 void test_skipTypeArgumentList_multiple() { | |
| 12326 createParser('<E, F, G> +'); | |
| 12327 Token following = parser.skipTypeArgumentList(parser.currentToken); | |
| 12328 expect(following, isNotNull); | |
| 12329 expect(following.type, TokenType.PLUS); | |
| 12330 } | |
| 12331 | |
| 12332 void test_skipTypeArgumentList_single() { | |
| 12333 createParser('<E> +'); | |
| 12334 Token following = parser.skipTypeArgumentList(parser.currentToken); | |
| 12335 expect(following, isNotNull); | |
| 12336 expect(following.type, TokenType.PLUS); | |
| 12337 } | |
| 12338 | |
| 12339 void test_skipTypeName_invalid() { | |
| 12340 createParser('+'); | |
| 12341 Token following = parser.skipTypeName(parser.currentToken); | |
| 12342 expect(following, isNull); | |
| 12343 } | |
| 12344 | |
| 12345 void test_skipTypeName_parameterized() { | |
| 12346 createParser('C<E<F<G>>> +'); | |
| 12347 Token following = parser.skipTypeName(parser.currentToken); | |
| 12348 expect(following, isNotNull); | |
| 12349 expect(following.type, TokenType.PLUS); | |
| 12350 } | |
| 12351 | |
| 12352 void test_skipTypeName_simple() { | |
| 12353 createParser('C +'); | |
| 12354 Token following = parser.skipTypeName(parser.currentToken); | |
| 12355 expect(following, isNotNull); | |
| 12356 expect(following.type, TokenType.PLUS); | |
| 12357 } | |
| 12358 | |
| 12359 /** | |
| 12360 * Invoke the method [Parser.computeStringValue] with the given argument. | |
| 12361 * | |
| 12362 * @param lexeme the argument to the method | |
| 12363 * @param first `true` if this is the first token in a string literal | |
| 12364 * @param last `true` if this is the last token in a string literal | |
| 12365 * @return the result of invoking the method | |
| 12366 * @throws Exception if the method could not be invoked or throws an exception | |
| 12367 */ | |
| 12368 String _computeStringValue(String lexeme, bool first, bool last) { | |
| 12369 createParser(''); | |
| 12370 String value = parser.computeStringValue(lexeme, first, last); | |
| 12371 listener.assertNoErrors(); | |
| 12372 return value; | |
| 12373 } | |
| 12374 | |
| 12375 /** | |
| 12376 * Invoke the method [Parser.isFunctionDeclaration] with the parser set to the
token | |
| 12377 * stream produced by scanning the given source. | |
| 12378 * | |
| 12379 * @param source the source to be scanned to produce the token stream being te
sted | |
| 12380 * @return the result of invoking the method | |
| 12381 * @throws Exception if the method could not be invoked or throws an exception | |
| 12382 */ | |
| 12383 bool _isFunctionDeclaration(String source) { | |
| 12384 createParser(source); | |
| 12385 bool result = parser.isFunctionDeclaration(); | |
| 12386 expectNotNullIfNoErrors(result); | |
| 12387 return result; | |
| 12388 } | |
| 12389 | |
| 12390 /** | |
| 12391 * Invoke the method [Parser.isFunctionExpression] with the parser set to the
token stream | |
| 12392 * produced by scanning the given source. | |
| 12393 * | |
| 12394 * @param source the source to be scanned to produce the token stream being te
sted | |
| 12395 * @return the result of invoking the method | |
| 12396 * @throws Exception if the method could not be invoked or throws an exception | |
| 12397 */ | |
| 12398 bool _isFunctionExpression(String source) { | |
| 12399 createParser(source); | |
| 12400 return parser.isFunctionExpression(parser.currentToken); | |
| 12401 } | |
| 12402 | |
| 12403 /** | |
| 12404 * Invoke the method [Parser.isInitializedVariableDeclaration] with the parser
set to the | |
| 12405 * token stream produced by scanning the given source. | |
| 12406 * | |
| 12407 * @param source the source to be scanned to produce the token stream being te
sted | |
| 12408 * @return the result of invoking the method | |
| 12409 * @throws Exception if the method could not be invoked or throws an exception | |
| 12410 */ | |
| 12411 bool _isInitializedVariableDeclaration(String source) { | |
| 12412 createParser(source); | |
| 12413 bool result = parser.isInitializedVariableDeclaration(); | |
| 12414 expectNotNullIfNoErrors(result); | |
| 12415 return result; | |
| 12416 } | |
| 12417 | |
| 12418 /** | |
| 12419 * Invoke the method [Parser.isSwitchMember] with the parser set to the token
stream | |
| 12420 * produced by scanning the given source. | |
| 12421 * | |
| 12422 * @param source the source to be scanned to produce the token stream being te
sted | |
| 12423 * @return the result of invoking the method | |
| 12424 * @throws Exception if the method could not be invoked or throws an exception | |
| 12425 */ | |
| 12426 bool _isSwitchMember(String source) { | |
| 12427 createParser(source); | |
| 12428 bool result = parser.isSwitchMember(); | |
| 12429 expectNotNullIfNoErrors(result); | |
| 12430 return result; | |
| 12431 } | |
| 12432 } | 12449 } |
| 12433 | 12450 |
| 12434 @reflectiveTest | 12451 @reflectiveTest |
| 12435 class StatementParserTest extends ParserTestCase with StatementParserTestMixin { | 12452 class StatementParserTest extends ParserTestCase with StatementParserTestMixin { |
| 12436 } | 12453 } |
| 12437 | 12454 |
| 12438 /** | 12455 /** |
| 12439 * The class [FormalParameterParserTestMixin] defines parser tests that test | 12456 * The class [FormalParameterParserTestMixin] defines parser tests that test |
| 12440 * the parsing statements. | 12457 * the parsing statements. |
| 12441 */ | 12458 */ |
| (...skipping 3028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15470 expectCommentText(typeVariable.documentationComment, '/// Doc'); | 15487 expectCommentText(typeVariable.documentationComment, '/// Doc'); |
| 15471 } | 15488 } |
| 15472 | 15489 |
| 15473 /** | 15490 /** |
| 15474 * Assert that the given [name] is in declaration context. | 15491 * Assert that the given [name] is in declaration context. |
| 15475 */ | 15492 */ |
| 15476 void _assertIsDeclarationName(SimpleIdentifier name) { | 15493 void _assertIsDeclarationName(SimpleIdentifier name) { |
| 15477 expect(name.inDeclarationContext(), isTrue); | 15494 expect(name.inDeclarationContext(), isTrue); |
| 15478 } | 15495 } |
| 15479 } | 15496 } |
| OLD | NEW |