| 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 analyzer.test.generated.parser_test; | 5 library analyzer.test.generated.parser_test; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; | 8 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; |
| 9 import 'package:analyzer/dart/ast/token.dart'; | 9 import 'package:analyzer/dart/ast/token.dart'; |
| 10 import 'package:analyzer/dart/ast/visitor.dart'; | 10 import 'package:analyzer/dart/ast/visitor.dart'; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 /** | 36 /** |
| 37 * Abstract base class for parser tests, which does not make assumptions about | 37 * Abstract base class for parser tests, which does not make assumptions about |
| 38 * which parser is used. | 38 * which parser is used. |
| 39 */ | 39 */ |
| 40 abstract class AbstractParserTestCase { | 40 abstract class AbstractParserTestCase { |
| 41 void set enableGenericMethodComments(bool value); | 41 void set enableGenericMethodComments(bool value); |
| 42 | 42 |
| 43 void set enableNnbd(bool value); | 43 void set enableNnbd(bool value); |
| 44 | 44 |
| 45 CompilationUnit parseCompilationUnit(String source, |
| 46 [List<ErrorCode> errorCodes = const <ErrorCode>[]]); |
| 47 |
| 48 /// TODO(paulberry): merge with [parseCompilationUnit] |
| 45 CompilationUnit parseCompilationUnitWithOptions(String source, | 49 CompilationUnit parseCompilationUnitWithOptions(String source, |
| 46 [List<ErrorCode> errorCodes = const <ErrorCode>[]]); | 50 [List<ErrorCode> errorCodes = const <ErrorCode>[]]); |
| 47 | 51 |
| 48 Expression parseExpression(String source, | 52 Expression parseExpression(String source, |
| 49 [List<ErrorCode> errorCodes = const <ErrorCode>[]]); | 53 [List<ErrorCode> errorCodes = const <ErrorCode>[]]); |
| 54 |
| 55 Statement parseStatement(String source, |
| 56 [List<ErrorCode> errorCodes = const <ErrorCode>[], |
| 57 bool enableLazyAssignmentOperators]); |
| 50 } | 58 } |
| 51 | 59 |
| 52 /** | 60 /** |
| 53 * Instances of the class `AstValidator` are used to validate the correct constr
uction of an | 61 * Instances of the class `AstValidator` are used to validate the correct constr
uction of an |
| 54 * AST structure. | 62 * AST structure. |
| 55 */ | 63 */ |
| 56 class AstValidator extends UnifyingAstVisitor<Object> { | 64 class AstValidator extends UnifyingAstVisitor<Object> { |
| 57 /** | 65 /** |
| 58 * A list containing the errors found while traversing the AST structure. | 66 * A list containing the errors found while traversing the AST structure. |
| 59 */ | 67 */ |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 ConditionalExpression conditional = expression; | 389 ConditionalExpression conditional = expression; |
| 382 Expression condition = conditional.condition; | 390 Expression condition = conditional.condition; |
| 383 expect(condition, new isInstanceOf<IsExpression>()); | 391 expect(condition, new isInstanceOf<IsExpression>()); |
| 384 Expression thenExpression = conditional.thenExpression; | 392 Expression thenExpression = conditional.thenExpression; |
| 385 expect(thenExpression, new isInstanceOf<ParenthesizedExpression>()); | 393 expect(thenExpression, new isInstanceOf<ParenthesizedExpression>()); |
| 386 Expression elseExpression = conditional.elseExpression; | 394 Expression elseExpression = conditional.elseExpression; |
| 387 expect(elseExpression, new isInstanceOf<SimpleIdentifier>()); | 395 expect(elseExpression, new isInstanceOf<SimpleIdentifier>()); |
| 388 } | 396 } |
| 389 | 397 |
| 390 void test_constructor_initializer_withParenthesizedExpression() { | 398 void test_constructor_initializer_withParenthesizedExpression() { |
| 391 CompilationUnit unit = ParserTestCase.parseCompilationUnit(r''' | 399 CompilationUnit unit = parseCompilationUnit(r''' |
| 392 class C { | 400 class C { |
| 393 C() : | 401 C() : |
| 394 this.a = (b == null ? c : d) { | 402 this.a = (b == null ? c : d) { |
| 395 } | 403 } |
| 396 }'''); | 404 }'''); |
| 397 NodeList<CompilationUnitMember> declarations = unit.declarations; | 405 NodeList<CompilationUnitMember> declarations = unit.declarations; |
| 398 expect(declarations, hasLength(1)); | 406 expect(declarations, hasLength(1)); |
| 399 } | 407 } |
| 400 | 408 |
| 401 void test_equalityExpression_normal() { | 409 void test_equalityExpression_normal() { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 enableNnbd = true; | 492 enableNnbd = true; |
| 485 BinaryExpression expression = parseExpression("a is X? || (b ? c : d)"); | 493 BinaryExpression expression = parseExpression("a is X? || (b ? c : d)"); |
| 486 expect(expression.leftOperand, new isInstanceOf<IsExpression>()); | 494 expect(expression.leftOperand, new isInstanceOf<IsExpression>()); |
| 487 expect( | 495 expect( |
| 488 expression.rightOperand, new isInstanceOf<ParenthesizedExpression>()); | 496 expression.rightOperand, new isInstanceOf<ParenthesizedExpression>()); |
| 489 expect((expression.rightOperand as ParenthesizedExpression).expression, | 497 expect((expression.rightOperand as ParenthesizedExpression).expression, |
| 490 new isInstanceOf<ConditionalExpression>()); | 498 new isInstanceOf<ConditionalExpression>()); |
| 491 } | 499 } |
| 492 | 500 |
| 493 void test_multipleLabels_statement() { | 501 void test_multipleLabels_statement() { |
| 494 LabeledStatement statement = | 502 LabeledStatement statement = parseStatement("a: b: c: return x;"); |
| 495 ParserTestCase.parseStatement("a: b: c: return x;"); | |
| 496 expect(statement.labels, hasLength(3)); | 503 expect(statement.labels, hasLength(3)); |
| 497 EngineTestCase.assertInstanceOf( | 504 EngineTestCase.assertInstanceOf( |
| 498 (obj) => obj is ReturnStatement, ReturnStatement, statement.statement); | 505 (obj) => obj is ReturnStatement, ReturnStatement, statement.statement); |
| 499 } | 506 } |
| 500 | 507 |
| 501 void test_multiplicativeExpression_normal() { | 508 void test_multiplicativeExpression_normal() { |
| 502 BinaryExpression expression = parseExpression("x * y / z"); | 509 BinaryExpression expression = parseExpression("x * y / z"); |
| 503 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, | 510 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| 504 BinaryExpression, expression.leftOperand); | 511 BinaryExpression, expression.leftOperand); |
| 505 } | 512 } |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 } | 645 } |
| 639 | 646 |
| 640 void test_abstractClassMember_setter() { | 647 void test_abstractClassMember_setter() { |
| 641 createParser('abstract set m(v);'); | 648 createParser('abstract set m(v);'); |
| 642 ClassMember member = parser.parseClassMember('C'); | 649 ClassMember member = parser.parseClassMember('C'); |
| 643 expectNotNullIfNoErrors(member); | 650 expectNotNullIfNoErrors(member); |
| 644 listener.assertErrorsWithCodes([ParserErrorCode.ABSTRACT_CLASS_MEMBER]); | 651 listener.assertErrorsWithCodes([ParserErrorCode.ABSTRACT_CLASS_MEMBER]); |
| 645 } | 652 } |
| 646 | 653 |
| 647 void test_abstractEnum() { | 654 void test_abstractEnum() { |
| 648 ParserTestCase.parseCompilationUnit( | 655 parseCompilationUnit( |
| 649 "abstract enum E {ONE}", [ParserErrorCode.ABSTRACT_ENUM]); | 656 "abstract enum E {ONE}", [ParserErrorCode.ABSTRACT_ENUM]); |
| 650 } | 657 } |
| 651 | 658 |
| 652 void test_abstractTopLevelFunction_function() { | 659 void test_abstractTopLevelFunction_function() { |
| 653 ParserTestCase.parseCompilationUnit( | 660 parseCompilationUnit( |
| 654 "abstract f(v) {}", [ParserErrorCode.ABSTRACT_TOP_LEVEL_FUNCTION]); | 661 "abstract f(v) {}", [ParserErrorCode.ABSTRACT_TOP_LEVEL_FUNCTION]); |
| 655 } | 662 } |
| 656 | 663 |
| 657 void test_abstractTopLevelFunction_getter() { | 664 void test_abstractTopLevelFunction_getter() { |
| 658 ParserTestCase.parseCompilationUnit( | 665 parseCompilationUnit( |
| 659 "abstract get m {}", [ParserErrorCode.ABSTRACT_TOP_LEVEL_FUNCTION]); | 666 "abstract get m {}", [ParserErrorCode.ABSTRACT_TOP_LEVEL_FUNCTION]); |
| 660 } | 667 } |
| 661 | 668 |
| 662 void test_abstractTopLevelFunction_setter() { | 669 void test_abstractTopLevelFunction_setter() { |
| 663 ParserTestCase.parseCompilationUnit( | 670 parseCompilationUnit( |
| 664 "abstract set m(v) {}", [ParserErrorCode.ABSTRACT_TOP_LEVEL_FUNCTION]); | 671 "abstract set m(v) {}", [ParserErrorCode.ABSTRACT_TOP_LEVEL_FUNCTION]); |
| 665 } | 672 } |
| 666 | 673 |
| 667 void test_abstractTopLevelVariable() { | 674 void test_abstractTopLevelVariable() { |
| 668 ParserTestCase.parseCompilationUnit( | 675 parseCompilationUnit( |
| 669 "abstract C f;", [ParserErrorCode.ABSTRACT_TOP_LEVEL_VARIABLE]); | 676 "abstract C f;", [ParserErrorCode.ABSTRACT_TOP_LEVEL_VARIABLE]); |
| 670 } | 677 } |
| 671 | 678 |
| 672 void test_abstractTypeDef() { | 679 void test_abstractTypeDef() { |
| 673 ParserTestCase.parseCompilationUnit( | 680 parseCompilationUnit( |
| 674 "abstract typedef F();", [ParserErrorCode.ABSTRACT_TYPEDEF]); | 681 "abstract typedef F();", [ParserErrorCode.ABSTRACT_TYPEDEF]); |
| 675 } | 682 } |
| 676 | 683 |
| 677 void test_annotationOnEnumConstant_first() { | 684 void test_annotationOnEnumConstant_first() { |
| 678 ParserTestCase.parseCompilationUnit("enum E { @override C }", | 685 parseCompilationUnit("enum E { @override C }", |
| 679 [ParserErrorCode.ANNOTATION_ON_ENUM_CONSTANT]); | 686 [ParserErrorCode.ANNOTATION_ON_ENUM_CONSTANT]); |
| 680 } | 687 } |
| 681 | 688 |
| 682 void test_annotationOnEnumConstant_middle() { | 689 void test_annotationOnEnumConstant_middle() { |
| 683 ParserTestCase.parseCompilationUnit("enum E { C, @override D, E }", | 690 parseCompilationUnit("enum E { C, @override D, E }", |
| 684 [ParserErrorCode.ANNOTATION_ON_ENUM_CONSTANT]); | 691 [ParserErrorCode.ANNOTATION_ON_ENUM_CONSTANT]); |
| 685 } | 692 } |
| 686 | 693 |
| 687 void test_breakOutsideOfLoop_breakInDoStatement() { | 694 void test_breakOutsideOfLoop_breakInDoStatement() { |
| 688 createParser('do {break;} while (x);'); | 695 createParser('do {break;} while (x);'); |
| 689 DoStatement statement = parser.parseDoStatement(); | 696 DoStatement statement = parser.parseDoStatement(); |
| 690 expectNotNullIfNoErrors(statement); | 697 expectNotNullIfNoErrors(statement); |
| 691 listener.assertNoErrors(); | 698 listener.assertNoErrors(); |
| 692 } | 699 } |
| 693 | 700 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 713 } | 720 } |
| 714 | 721 |
| 715 void test_breakOutsideOfLoop_breakInWhileStatement() { | 722 void test_breakOutsideOfLoop_breakInWhileStatement() { |
| 716 createParser('while (x) {break;}'); | 723 createParser('while (x) {break;}'); |
| 717 WhileStatement statement = parser.parseWhileStatement(); | 724 WhileStatement statement = parser.parseWhileStatement(); |
| 718 expectNotNullIfNoErrors(statement); | 725 expectNotNullIfNoErrors(statement); |
| 719 listener.assertNoErrors(); | 726 listener.assertNoErrors(); |
| 720 } | 727 } |
| 721 | 728 |
| 722 void test_breakOutsideOfLoop_functionExpression_inALoop() { | 729 void test_breakOutsideOfLoop_functionExpression_inALoop() { |
| 723 ParserTestCase.parseStatement( | 730 parseStatement( |
| 724 "for(; x;) {() {break;};}", [ParserErrorCode.BREAK_OUTSIDE_OF_LOOP]); | 731 "for(; x;) {() {break;};}", [ParserErrorCode.BREAK_OUTSIDE_OF_LOOP]); |
| 725 } | 732 } |
| 726 | 733 |
| 727 void test_breakOutsideOfLoop_functionExpression_withALoop() { | 734 void test_breakOutsideOfLoop_functionExpression_withALoop() { |
| 728 ParserTestCase.parseStatement("() {for (; x;) {break;}};"); | 735 parseStatement("() {for (; x;) {break;}};"); |
| 729 } | 736 } |
| 730 | 737 |
| 731 void test_classInClass_abstract() { | 738 void test_classInClass_abstract() { |
| 732 ParserTestCase.parseCompilationUnit( | 739 parseCompilationUnit( |
| 733 "class C { abstract class B {} }", [ParserErrorCode.CLASS_IN_CLASS]); | 740 "class C { abstract class B {} }", [ParserErrorCode.CLASS_IN_CLASS]); |
| 734 } | 741 } |
| 735 | 742 |
| 736 void test_classInClass_nonAbstract() { | 743 void test_classInClass_nonAbstract() { |
| 737 ParserTestCase.parseCompilationUnit( | 744 parseCompilationUnit( |
| 738 "class C { class B {} }", [ParserErrorCode.CLASS_IN_CLASS]); | 745 "class C { class B {} }", [ParserErrorCode.CLASS_IN_CLASS]); |
| 739 } | 746 } |
| 740 | 747 |
| 741 void test_classTypeAlias_abstractAfterEq() { | 748 void test_classTypeAlias_abstractAfterEq() { |
| 742 // This syntax has been removed from the language in favor of | 749 // This syntax has been removed from the language in favor of |
| 743 // "abstract class A = B with C;" (issue 18098). | 750 // "abstract class A = B with C;" (issue 18098). |
| 744 createParser('class A = abstract B with C;'); | 751 createParser('class A = abstract B with C;'); |
| 745 CompilationUnitMember member = | 752 CompilationUnitMember member = |
| 746 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); | 753 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 747 expectNotNullIfNoErrors(member); | 754 expectNotNullIfNoErrors(member); |
| 748 listener.assertErrorsWithCodes( | 755 listener.assertErrorsWithCodes( |
| 749 [ParserErrorCode.EXPECTED_TOKEN, ParserErrorCode.EXPECTED_TOKEN]); | 756 [ParserErrorCode.EXPECTED_TOKEN, ParserErrorCode.EXPECTED_TOKEN]); |
| 750 } | 757 } |
| 751 | 758 |
| 752 void test_colonInPlaceOfIn() { | 759 void test_colonInPlaceOfIn() { |
| 753 ParserTestCase.parseStatement( | 760 parseStatement( |
| 754 "for (var x : list) {}", [ParserErrorCode.COLON_IN_PLACE_OF_IN]); | 761 "for (var x : list) {}", [ParserErrorCode.COLON_IN_PLACE_OF_IN]); |
| 755 } | 762 } |
| 756 | 763 |
| 757 void test_constAndCovariant() { | 764 void test_constAndCovariant() { |
| 758 createParser('covariant const C f;'); | 765 createParser('covariant const C f;'); |
| 759 ClassMember member = parser.parseClassMember('C'); | 766 ClassMember member = parser.parseClassMember('C'); |
| 760 expectNotNullIfNoErrors(member); | 767 expectNotNullIfNoErrors(member); |
| 761 listener.assertErrorsWithCodes([ParserErrorCode.CONST_AND_COVARIANT]); | 768 listener.assertErrorsWithCodes([ParserErrorCode.CONST_AND_COVARIANT]); |
| 762 } | 769 } |
| 763 | 770 |
| 764 void test_constAndFinal() { | 771 void test_constAndFinal() { |
| 765 createParser('const final int x;'); | 772 createParser('const final int x;'); |
| 766 ClassMember member = parser.parseClassMember('C'); | 773 ClassMember member = parser.parseClassMember('C'); |
| 767 expectNotNullIfNoErrors(member); | 774 expectNotNullIfNoErrors(member); |
| 768 listener.assertErrorsWithCodes([ParserErrorCode.CONST_AND_FINAL]); | 775 listener.assertErrorsWithCodes([ParserErrorCode.CONST_AND_FINAL]); |
| 769 } | 776 } |
| 770 | 777 |
| 771 void test_constAndVar() { | 778 void test_constAndVar() { |
| 772 createParser('const var x;'); | 779 createParser('const var x;'); |
| 773 ClassMember member = parser.parseClassMember('C'); | 780 ClassMember member = parser.parseClassMember('C'); |
| 774 expectNotNullIfNoErrors(member); | 781 expectNotNullIfNoErrors(member); |
| 775 listener.assertErrorsWithCodes([ParserErrorCode.CONST_AND_VAR]); | 782 listener.assertErrorsWithCodes([ParserErrorCode.CONST_AND_VAR]); |
| 776 } | 783 } |
| 777 | 784 |
| 778 void test_constClass() { | 785 void test_constClass() { |
| 779 ParserTestCase.parseCompilationUnit( | 786 parseCompilationUnit("const class C {}", [ParserErrorCode.CONST_CLASS]); |
| 780 "const class C {}", [ParserErrorCode.CONST_CLASS]); | |
| 781 } | 787 } |
| 782 | 788 |
| 783 void test_constConstructorWithBody() { | 789 void test_constConstructorWithBody() { |
| 784 createParser('const C() {}'); | 790 createParser('const C() {}'); |
| 785 ClassMember member = parser.parseClassMember('C'); | 791 ClassMember member = parser.parseClassMember('C'); |
| 786 expectNotNullIfNoErrors(member); | 792 expectNotNullIfNoErrors(member); |
| 787 listener | 793 listener |
| 788 .assertErrorsWithCodes([ParserErrorCode.CONST_CONSTRUCTOR_WITH_BODY]); | 794 .assertErrorsWithCodes([ParserErrorCode.CONST_CONSTRUCTOR_WITH_BODY]); |
| 789 } | 795 } |
| 790 | 796 |
| 791 void test_constEnum() { | 797 void test_constEnum() { |
| 792 ParserTestCase.parseCompilationUnit( | 798 parseCompilationUnit("const enum E {ONE}", [ParserErrorCode.CONST_ENUM]); |
| 793 "const enum E {ONE}", [ParserErrorCode.CONST_ENUM]); | |
| 794 } | 799 } |
| 795 | 800 |
| 796 void test_constFactory() { | 801 void test_constFactory() { |
| 797 createParser('const factory C() {}'); | 802 createParser('const factory C() {}'); |
| 798 ClassMember member = parser.parseClassMember('C'); | 803 ClassMember member = parser.parseClassMember('C'); |
| 799 expectNotNullIfNoErrors(member); | 804 expectNotNullIfNoErrors(member); |
| 800 listener.assertErrorsWithCodes([ParserErrorCode.CONST_FACTORY]); | 805 listener.assertErrorsWithCodes([ParserErrorCode.CONST_FACTORY]); |
| 801 } | 806 } |
| 802 | 807 |
| 803 void test_constMethod() { | 808 void test_constMethod() { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 817 | 822 |
| 818 void test_constructorWithReturnType_var() { | 823 void test_constructorWithReturnType_var() { |
| 819 createParser('var C() {}'); | 824 createParser('var C() {}'); |
| 820 ClassMember member = parser.parseClassMember('C'); | 825 ClassMember member = parser.parseClassMember('C'); |
| 821 expectNotNullIfNoErrors(member); | 826 expectNotNullIfNoErrors(member); |
| 822 listener | 827 listener |
| 823 .assertErrorsWithCodes([ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE]); | 828 .assertErrorsWithCodes([ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE]); |
| 824 } | 829 } |
| 825 | 830 |
| 826 void test_constTypedef() { | 831 void test_constTypedef() { |
| 827 ParserTestCase.parseCompilationUnit( | 832 parseCompilationUnit("const typedef F();", [ParserErrorCode.CONST_TYPEDEF]); |
| 828 "const typedef F();", [ParserErrorCode.CONST_TYPEDEF]); | |
| 829 } | 833 } |
| 830 | 834 |
| 831 void test_continueOutsideOfLoop_continueInDoStatement() { | 835 void test_continueOutsideOfLoop_continueInDoStatement() { |
| 832 createParser('do {continue;} while (x);'); | 836 createParser('do {continue;} while (x);'); |
| 833 DoStatement statement = parser.parseDoStatement(); | 837 DoStatement statement = parser.parseDoStatement(); |
| 834 expectNotNullIfNoErrors(statement); | 838 expectNotNullIfNoErrors(statement); |
| 835 listener.assertNoErrors(); | 839 listener.assertNoErrors(); |
| 836 } | 840 } |
| 837 | 841 |
| 838 void test_continueOutsideOfLoop_continueInForStatement() { | 842 void test_continueOutsideOfLoop_continueInForStatement() { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 857 } | 861 } |
| 858 | 862 |
| 859 void test_continueOutsideOfLoop_continueInWhileStatement() { | 863 void test_continueOutsideOfLoop_continueInWhileStatement() { |
| 860 createParser('while (x) {continue;}'); | 864 createParser('while (x) {continue;}'); |
| 861 WhileStatement statement = parser.parseWhileStatement(); | 865 WhileStatement statement = parser.parseWhileStatement(); |
| 862 expectNotNullIfNoErrors(statement); | 866 expectNotNullIfNoErrors(statement); |
| 863 listener.assertNoErrors(); | 867 listener.assertNoErrors(); |
| 864 } | 868 } |
| 865 | 869 |
| 866 void test_continueOutsideOfLoop_functionExpression_inALoop() { | 870 void test_continueOutsideOfLoop_functionExpression_inALoop() { |
| 867 ParserTestCase.parseStatement("for(; x;) {() {continue;};}", | 871 parseStatement("for(; x;) {() {continue;};}", |
| 868 [ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP]); | 872 [ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP]); |
| 869 } | 873 } |
| 870 | 874 |
| 871 void test_continueOutsideOfLoop_functionExpression_withALoop() { | 875 void test_continueOutsideOfLoop_functionExpression_withALoop() { |
| 872 ParserTestCase.parseStatement("() {for (; x;) {continue;}};"); | 876 parseStatement("() {for (; x;) {continue;}};"); |
| 873 } | 877 } |
| 874 | 878 |
| 875 void test_continueWithoutLabelInCase_error() { | 879 void test_continueWithoutLabelInCase_error() { |
| 876 createParser('switch (x) {case 1: continue;}'); | 880 createParser('switch (x) {case 1: continue;}'); |
| 877 SwitchStatement statement = parser.parseSwitchStatement(); | 881 SwitchStatement statement = parser.parseSwitchStatement(); |
| 878 expectNotNullIfNoErrors(statement); | 882 expectNotNullIfNoErrors(statement); |
| 879 listener.assertErrorsWithCodes( | 883 listener.assertErrorsWithCodes( |
| 880 [ParserErrorCode.CONTINUE_WITHOUT_LABEL_IN_CASE]); | 884 [ParserErrorCode.CONTINUE_WITHOUT_LABEL_IN_CASE]); |
| 881 } | 885 } |
| 882 | 886 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 949 void test_covariantTopLevelDeclaration_enum() { | 953 void test_covariantTopLevelDeclaration_enum() { |
| 950 createParser('covariant enum E { v }'); | 954 createParser('covariant enum E { v }'); |
| 951 EnumDeclaration member = | 955 EnumDeclaration member = |
| 952 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); | 956 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 953 expectNotNullIfNoErrors(member); | 957 expectNotNullIfNoErrors(member); |
| 954 listener.assertErrorsWithCodes( | 958 listener.assertErrorsWithCodes( |
| 955 [ParserErrorCode.COVARIANT_TOP_LEVEL_DECLARATION]); | 959 [ParserErrorCode.COVARIANT_TOP_LEVEL_DECLARATION]); |
| 956 } | 960 } |
| 957 | 961 |
| 958 void test_covariantTopLevelDeclaration_typedef() { | 962 void test_covariantTopLevelDeclaration_typedef() { |
| 959 ParserTestCase.parseCompilationUnit("covariant typedef F();", | 963 parseCompilationUnit("covariant typedef F();", |
| 960 [ParserErrorCode.COVARIANT_TOP_LEVEL_DECLARATION]); | 964 [ParserErrorCode.COVARIANT_TOP_LEVEL_DECLARATION]); |
| 961 } | 965 } |
| 962 | 966 |
| 963 void test_defaultValueInFunctionType_named_colon() { | 967 void test_defaultValueInFunctionType_named_colon() { |
| 964 createParser('int x : 0'); | 968 createParser('int x : 0'); |
| 965 FormalParameter parameter = | 969 FormalParameter parameter = |
| 966 parser.parseFormalParameter(ParameterKind.NAMED, inFunctionType: true); | 970 parser.parseFormalParameter(ParameterKind.NAMED, inFunctionType: true); |
| 967 expectNotNullIfNoErrors(parameter); | 971 expectNotNullIfNoErrors(parameter); |
| 968 listener.assertErrorsWithCodes( | 972 listener.assertErrorsWithCodes( |
| 969 [ParserErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE]); | 973 [ParserErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE]); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 981 void test_defaultValueInFunctionType_positional() { | 985 void test_defaultValueInFunctionType_positional() { |
| 982 createParser('int x = 0'); | 986 createParser('int x = 0'); |
| 983 FormalParameter parameter = parser | 987 FormalParameter parameter = parser |
| 984 .parseFormalParameter(ParameterKind.POSITIONAL, inFunctionType: true); | 988 .parseFormalParameter(ParameterKind.POSITIONAL, inFunctionType: true); |
| 985 expectNotNullIfNoErrors(parameter); | 989 expectNotNullIfNoErrors(parameter); |
| 986 listener.assertErrorsWithCodes( | 990 listener.assertErrorsWithCodes( |
| 987 [ParserErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE]); | 991 [ParserErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE]); |
| 988 } | 992 } |
| 989 | 993 |
| 990 void test_directiveAfterDeclaration_classBeforeDirective() { | 994 void test_directiveAfterDeclaration_classBeforeDirective() { |
| 991 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 995 CompilationUnit unit = parseCompilationUnit("class Foo{} library l;", |
| 992 "class Foo{} library l;", | |
| 993 [ParserErrorCode.DIRECTIVE_AFTER_DECLARATION]); | 996 [ParserErrorCode.DIRECTIVE_AFTER_DECLARATION]); |
| 994 expect(unit, isNotNull); | 997 expect(unit, isNotNull); |
| 995 } | 998 } |
| 996 | 999 |
| 997 void test_directiveAfterDeclaration_classBetweenDirectives() { | 1000 void test_directiveAfterDeclaration_classBetweenDirectives() { |
| 998 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 1001 CompilationUnit unit = parseCompilationUnit( |
| 999 "library l;\nclass Foo{}\npart 'a.dart';", | 1002 "library l;\nclass Foo{}\npart 'a.dart';", |
| 1000 [ParserErrorCode.DIRECTIVE_AFTER_DECLARATION]); | 1003 [ParserErrorCode.DIRECTIVE_AFTER_DECLARATION]); |
| 1001 expect(unit, isNotNull); | 1004 expect(unit, isNotNull); |
| 1002 } | 1005 } |
| 1003 | 1006 |
| 1004 void test_duplicatedModifier_const() { | 1007 void test_duplicatedModifier_const() { |
| 1005 createParser('const const m;'); | 1008 createParser('const const m;'); |
| 1006 ClassMember member = parser.parseClassMember('C'); | 1009 ClassMember member = parser.parseClassMember('C'); |
| 1007 expectNotNullIfNoErrors(member); | 1010 expectNotNullIfNoErrors(member); |
| 1008 listener.assertErrorsWithCodes([ParserErrorCode.DUPLICATED_MODIFIER]); | 1011 listener.assertErrorsWithCodes([ParserErrorCode.DUPLICATED_MODIFIER]); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1053 | 1056 |
| 1054 void test_emptyEnumBody() { | 1057 void test_emptyEnumBody() { |
| 1055 createParser('enum E {}'); | 1058 createParser('enum E {}'); |
| 1056 EnumDeclaration declaration = | 1059 EnumDeclaration declaration = |
| 1057 parser.parseEnumDeclaration(emptyCommentAndMetadata()); | 1060 parser.parseEnumDeclaration(emptyCommentAndMetadata()); |
| 1058 expectNotNullIfNoErrors(declaration); | 1061 expectNotNullIfNoErrors(declaration); |
| 1059 listener.assertErrorsWithCodes([ParserErrorCode.EMPTY_ENUM_BODY]); | 1062 listener.assertErrorsWithCodes([ParserErrorCode.EMPTY_ENUM_BODY]); |
| 1060 } | 1063 } |
| 1061 | 1064 |
| 1062 void test_enumInClass() { | 1065 void test_enumInClass() { |
| 1063 ParserTestCase.parseCompilationUnit( | 1066 parseCompilationUnit( |
| 1064 r''' | 1067 r''' |
| 1065 class Foo { | 1068 class Foo { |
| 1066 enum Bar { | 1069 enum Bar { |
| 1067 Bar1, Bar2, Bar3 | 1070 Bar1, Bar2, Bar3 |
| 1068 } | 1071 } |
| 1069 } | 1072 } |
| 1070 ''', | 1073 ''', |
| 1071 [ParserErrorCode.ENUM_IN_CLASS]); | 1074 [ParserErrorCode.ENUM_IN_CLASS]); |
| 1072 } | 1075 } |
| 1073 | 1076 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1190 } | 1193 } |
| 1191 | 1194 |
| 1192 void test_expectedToken_commaMissingInArgumentList() { | 1195 void test_expectedToken_commaMissingInArgumentList() { |
| 1193 createParser('(x, y z)'); | 1196 createParser('(x, y z)'); |
| 1194 ArgumentList list = parser.parseArgumentList(); | 1197 ArgumentList list = parser.parseArgumentList(); |
| 1195 expectNotNullIfNoErrors(list); | 1198 expectNotNullIfNoErrors(list); |
| 1196 listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_TOKEN]); | 1199 listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_TOKEN]); |
| 1197 } | 1200 } |
| 1198 | 1201 |
| 1199 void test_expectedToken_parseStatement_afterVoid() { | 1202 void test_expectedToken_parseStatement_afterVoid() { |
| 1200 ParserTestCase.parseStatement("void}", | 1203 parseStatement("void}", |
| 1201 [ParserErrorCode.EXPECTED_TOKEN, ParserErrorCode.MISSING_IDENTIFIER]); | 1204 [ParserErrorCode.EXPECTED_TOKEN, ParserErrorCode.MISSING_IDENTIFIER]); |
| 1202 } | 1205 } |
| 1203 | 1206 |
| 1204 void test_expectedToken_semicolonMissingAfterExport() { | 1207 void test_expectedToken_semicolonMissingAfterExport() { |
| 1205 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 1208 CompilationUnit unit = parseCompilationUnit( |
| 1206 "export '' class A {}", [ParserErrorCode.EXPECTED_TOKEN]); | 1209 "export '' class A {}", [ParserErrorCode.EXPECTED_TOKEN]); |
| 1207 ExportDirective directive = unit.directives[0] as ExportDirective; | 1210 ExportDirective directive = unit.directives[0] as ExportDirective; |
| 1208 Token semicolon = directive.semicolon; | 1211 Token semicolon = directive.semicolon; |
| 1209 expect(semicolon, isNotNull); | 1212 expect(semicolon, isNotNull); |
| 1210 expect(semicolon.isSynthetic, isTrue); | 1213 expect(semicolon.isSynthetic, isTrue); |
| 1211 } | 1214 } |
| 1212 | 1215 |
| 1213 void test_expectedToken_semicolonMissingAfterExpression() { | 1216 void test_expectedToken_semicolonMissingAfterExpression() { |
| 1214 ParserTestCase.parseStatement("x", [ParserErrorCode.EXPECTED_TOKEN]); | 1217 parseStatement("x", [ParserErrorCode.EXPECTED_TOKEN]); |
| 1215 } | 1218 } |
| 1216 | 1219 |
| 1217 void test_expectedToken_semicolonMissingAfterImport() { | 1220 void test_expectedToken_semicolonMissingAfterImport() { |
| 1218 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 1221 CompilationUnit unit = parseCompilationUnit( |
| 1219 "import '' class A {}", [ParserErrorCode.EXPECTED_TOKEN]); | 1222 "import '' class A {}", [ParserErrorCode.EXPECTED_TOKEN]); |
| 1220 ImportDirective directive = unit.directives[0] as ImportDirective; | 1223 ImportDirective directive = unit.directives[0] as ImportDirective; |
| 1221 Token semicolon = directive.semicolon; | 1224 Token semicolon = directive.semicolon; |
| 1222 expect(semicolon, isNotNull); | 1225 expect(semicolon, isNotNull); |
| 1223 expect(semicolon.isSynthetic, isTrue); | 1226 expect(semicolon.isSynthetic, isTrue); |
| 1224 } | 1227 } |
| 1225 | 1228 |
| 1226 void test_expectedToken_whileMissingInDoStatement() { | 1229 void test_expectedToken_whileMissingInDoStatement() { |
| 1227 ParserTestCase | 1230 parseStatement("do {} (x);", [ParserErrorCode.EXPECTED_TOKEN]); |
| 1228 .parseStatement("do {} (x);", [ParserErrorCode.EXPECTED_TOKEN]); | |
| 1229 } | 1231 } |
| 1230 | 1232 |
| 1231 void test_expectedTypeName_as() { | 1233 void test_expectedTypeName_as() { |
| 1232 parseExpression("x as", [ParserErrorCode.EXPECTED_TYPE_NAME]); | 1234 parseExpression("x as", [ParserErrorCode.EXPECTED_TYPE_NAME]); |
| 1233 } | 1235 } |
| 1234 | 1236 |
| 1235 void test_expectedTypeName_as_void() { | 1237 void test_expectedTypeName_as_void() { |
| 1236 parseExpression("x as void)", [ParserErrorCode.EXPECTED_TYPE_NAME]); | 1238 parseExpression("x as void)", [ParserErrorCode.EXPECTED_TYPE_NAME]); |
| 1237 } | 1239 } |
| 1238 | 1240 |
| 1239 void test_expectedTypeName_is() { | 1241 void test_expectedTypeName_is() { |
| 1240 parseExpression("x is", [ParserErrorCode.EXPECTED_TYPE_NAME]); | 1242 parseExpression("x is", [ParserErrorCode.EXPECTED_TYPE_NAME]); |
| 1241 } | 1243 } |
| 1242 | 1244 |
| 1243 void test_expectedTypeName_is_void() { | 1245 void test_expectedTypeName_is_void() { |
| 1244 parseExpression("x is void)", [ParserErrorCode.EXPECTED_TYPE_NAME]); | 1246 parseExpression("x is void)", [ParserErrorCode.EXPECTED_TYPE_NAME]); |
| 1245 } | 1247 } |
| 1246 | 1248 |
| 1247 void test_exportDirectiveAfterPartDirective() { | 1249 void test_exportDirectiveAfterPartDirective() { |
| 1248 ParserTestCase.parseCompilationUnit("part 'a.dart'; export 'b.dart';", | 1250 parseCompilationUnit("part 'a.dart'; export 'b.dart';", |
| 1249 [ParserErrorCode.EXPORT_DIRECTIVE_AFTER_PART_DIRECTIVE]); | 1251 [ParserErrorCode.EXPORT_DIRECTIVE_AFTER_PART_DIRECTIVE]); |
| 1250 } | 1252 } |
| 1251 | 1253 |
| 1252 void test_externalAfterConst() { | 1254 void test_externalAfterConst() { |
| 1253 createParser('const external C();'); | 1255 createParser('const external C();'); |
| 1254 ClassMember member = parser.parseClassMember('C'); | 1256 ClassMember member = parser.parseClassMember('C'); |
| 1255 expectNotNullIfNoErrors(member); | 1257 expectNotNullIfNoErrors(member); |
| 1256 listener.assertErrorsWithCodes([ParserErrorCode.EXTERNAL_AFTER_CONST]); | 1258 listener.assertErrorsWithCodes([ParserErrorCode.EXTERNAL_AFTER_CONST]); |
| 1257 } | 1259 } |
| 1258 | 1260 |
| 1259 void test_externalAfterFactory() { | 1261 void test_externalAfterFactory() { |
| 1260 createParser('factory external C();'); | 1262 createParser('factory external C();'); |
| 1261 ClassMember member = parser.parseClassMember('C'); | 1263 ClassMember member = parser.parseClassMember('C'); |
| 1262 expectNotNullIfNoErrors(member); | 1264 expectNotNullIfNoErrors(member); |
| 1263 listener.assertErrorsWithCodes([ParserErrorCode.EXTERNAL_AFTER_FACTORY]); | 1265 listener.assertErrorsWithCodes([ParserErrorCode.EXTERNAL_AFTER_FACTORY]); |
| 1264 } | 1266 } |
| 1265 | 1267 |
| 1266 void test_externalAfterStatic() { | 1268 void test_externalAfterStatic() { |
| 1267 createParser('static external int m();'); | 1269 createParser('static external int m();'); |
| 1268 ClassMember member = parser.parseClassMember('C'); | 1270 ClassMember member = parser.parseClassMember('C'); |
| 1269 expectNotNullIfNoErrors(member); | 1271 expectNotNullIfNoErrors(member); |
| 1270 listener.assertErrorsWithCodes([ParserErrorCode.EXTERNAL_AFTER_STATIC]); | 1272 listener.assertErrorsWithCodes([ParserErrorCode.EXTERNAL_AFTER_STATIC]); |
| 1271 } | 1273 } |
| 1272 | 1274 |
| 1273 void test_externalClass() { | 1275 void test_externalClass() { |
| 1274 ParserTestCase.parseCompilationUnit( | 1276 parseCompilationUnit( |
| 1275 "external class C {}", [ParserErrorCode.EXTERNAL_CLASS]); | 1277 "external class C {}", [ParserErrorCode.EXTERNAL_CLASS]); |
| 1276 } | 1278 } |
| 1277 | 1279 |
| 1278 void test_externalConstructorWithBody_factory() { | 1280 void test_externalConstructorWithBody_factory() { |
| 1279 createParser('external factory C() {}'); | 1281 createParser('external factory C() {}'); |
| 1280 ClassMember member = parser.parseClassMember('C'); | 1282 ClassMember member = parser.parseClassMember('C'); |
| 1281 expectNotNullIfNoErrors(member); | 1283 expectNotNullIfNoErrors(member); |
| 1282 listener.assertErrorsWithCodes( | 1284 listener.assertErrorsWithCodes( |
| 1283 [ParserErrorCode.EXTERNAL_CONSTRUCTOR_WITH_BODY]); | 1285 [ParserErrorCode.EXTERNAL_CONSTRUCTOR_WITH_BODY]); |
| 1284 } | 1286 } |
| 1285 | 1287 |
| 1286 void test_externalConstructorWithBody_named() { | 1288 void test_externalConstructorWithBody_named() { |
| 1287 createParser('external C.c() {}'); | 1289 createParser('external C.c() {}'); |
| 1288 ClassMember member = parser.parseClassMember('C'); | 1290 ClassMember member = parser.parseClassMember('C'); |
| 1289 expectNotNullIfNoErrors(member); | 1291 expectNotNullIfNoErrors(member); |
| 1290 listener.assertErrorsWithCodes( | 1292 listener.assertErrorsWithCodes( |
| 1291 [ParserErrorCode.EXTERNAL_CONSTRUCTOR_WITH_BODY]); | 1293 [ParserErrorCode.EXTERNAL_CONSTRUCTOR_WITH_BODY]); |
| 1292 } | 1294 } |
| 1293 | 1295 |
| 1294 void test_externalEnum() { | 1296 void test_externalEnum() { |
| 1295 ParserTestCase.parseCompilationUnit( | 1297 parseCompilationUnit( |
| 1296 "external enum E {ONE}", [ParserErrorCode.EXTERNAL_ENUM]); | 1298 "external enum E {ONE}", [ParserErrorCode.EXTERNAL_ENUM]); |
| 1297 } | 1299 } |
| 1298 | 1300 |
| 1299 void test_externalField_const() { | 1301 void test_externalField_const() { |
| 1300 createParser('external const A f;'); | 1302 createParser('external const A f;'); |
| 1301 ClassMember member = parser.parseClassMember('C'); | 1303 ClassMember member = parser.parseClassMember('C'); |
| 1302 expectNotNullIfNoErrors(member); | 1304 expectNotNullIfNoErrors(member); |
| 1303 listener.assertErrorsWithCodes([ParserErrorCode.EXTERNAL_FIELD]); | 1305 listener.assertErrorsWithCodes([ParserErrorCode.EXTERNAL_FIELD]); |
| 1304 } | 1306 } |
| 1305 | 1307 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1354 } | 1356 } |
| 1355 | 1357 |
| 1356 void test_externalSetterWithBody() { | 1358 void test_externalSetterWithBody() { |
| 1357 createParser('external set x(int value) {}'); | 1359 createParser('external set x(int value) {}'); |
| 1358 ClassMember member = parser.parseClassMember('C'); | 1360 ClassMember member = parser.parseClassMember('C'); |
| 1359 expectNotNullIfNoErrors(member); | 1361 expectNotNullIfNoErrors(member); |
| 1360 listener.assertErrorsWithCodes([ParserErrorCode.EXTERNAL_SETTER_WITH_BODY]); | 1362 listener.assertErrorsWithCodes([ParserErrorCode.EXTERNAL_SETTER_WITH_BODY]); |
| 1361 } | 1363 } |
| 1362 | 1364 |
| 1363 void test_externalTypedef() { | 1365 void test_externalTypedef() { |
| 1364 ParserTestCase.parseCompilationUnit( | 1366 parseCompilationUnit( |
| 1365 "external typedef F();", [ParserErrorCode.EXTERNAL_TYPEDEF]); | 1367 "external typedef F();", [ParserErrorCode.EXTERNAL_TYPEDEF]); |
| 1366 } | 1368 } |
| 1367 | 1369 |
| 1368 void test_extraCommaInParameterList() { | 1370 void test_extraCommaInParameterList() { |
| 1369 createParser('(int a, , int b)'); | 1371 createParser('(int a, , int b)'); |
| 1370 FormalParameterList list = parser.parseFormalParameterList(); | 1372 FormalParameterList list = parser.parseFormalParameterList(); |
| 1371 expectNotNullIfNoErrors(list); | 1373 expectNotNullIfNoErrors(list); |
| 1372 listener.assertErrorsWithCodes( | 1374 listener.assertErrorsWithCodes( |
| 1373 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); | 1375 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); |
| 1374 } | 1376 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1394 } | 1396 } |
| 1395 | 1397 |
| 1396 void test_extraTrailingCommaInParameterList() { | 1398 void test_extraTrailingCommaInParameterList() { |
| 1397 createParser('(a,,)'); | 1399 createParser('(a,,)'); |
| 1398 FormalParameterList list = parser.parseFormalParameterList(); | 1400 FormalParameterList list = parser.parseFormalParameterList(); |
| 1399 expectNotNullIfNoErrors(list); | 1401 expectNotNullIfNoErrors(list); |
| 1400 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); | 1402 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| 1401 } | 1403 } |
| 1402 | 1404 |
| 1403 void test_factoryTopLevelDeclaration_class() { | 1405 void test_factoryTopLevelDeclaration_class() { |
| 1404 ParserTestCase.parseCompilationUnit( | 1406 parseCompilationUnit( |
| 1405 "factory class C {}", [ParserErrorCode.FACTORY_TOP_LEVEL_DECLARATION]); | 1407 "factory class C {}", [ParserErrorCode.FACTORY_TOP_LEVEL_DECLARATION]); |
| 1406 } | 1408 } |
| 1407 | 1409 |
| 1408 void test_factoryTopLevelDeclaration_enum() { | 1410 void test_factoryTopLevelDeclaration_enum() { |
| 1409 ParserTestCase.parseCompilationUnit("factory enum E { v }", | 1411 parseCompilationUnit("factory enum E { v }", |
| 1410 [ParserErrorCode.FACTORY_TOP_LEVEL_DECLARATION]); | 1412 [ParserErrorCode.FACTORY_TOP_LEVEL_DECLARATION]); |
| 1411 } | 1413 } |
| 1412 | 1414 |
| 1413 void test_factoryTopLevelDeclaration_typedef() { | 1415 void test_factoryTopLevelDeclaration_typedef() { |
| 1414 ParserTestCase.parseCompilationUnit("factory typedef F();", | 1416 parseCompilationUnit("factory typedef F();", |
| 1415 [ParserErrorCode.FACTORY_TOP_LEVEL_DECLARATION]); | 1417 [ParserErrorCode.FACTORY_TOP_LEVEL_DECLARATION]); |
| 1416 } | 1418 } |
| 1417 | 1419 |
| 1418 void test_factoryWithInitializers() { | 1420 void test_factoryWithInitializers() { |
| 1419 createParser('factory C() : x = 3 {}'); | 1421 createParser('factory C() : x = 3 {}'); |
| 1420 ClassMember member = parser.parseClassMember('C'); | 1422 ClassMember member = parser.parseClassMember('C'); |
| 1421 expectNotNullIfNoErrors(member); | 1423 expectNotNullIfNoErrors(member); |
| 1422 listener.assertErrorsWithCodes([ParserErrorCode.FACTORY_WITH_INITIALIZERS]); | 1424 listener.assertErrorsWithCodes([ParserErrorCode.FACTORY_WITH_INITIALIZERS]); |
| 1423 } | 1425 } |
| 1424 | 1426 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1445 } | 1447 } |
| 1446 | 1448 |
| 1447 void test_finalAndVar() { | 1449 void test_finalAndVar() { |
| 1448 createParser('final var x;'); | 1450 createParser('final var x;'); |
| 1449 ClassMember member = parser.parseClassMember('C'); | 1451 ClassMember member = parser.parseClassMember('C'); |
| 1450 expectNotNullIfNoErrors(member); | 1452 expectNotNullIfNoErrors(member); |
| 1451 listener.assertErrorsWithCodes([ParserErrorCode.FINAL_AND_VAR]); | 1453 listener.assertErrorsWithCodes([ParserErrorCode.FINAL_AND_VAR]); |
| 1452 } | 1454 } |
| 1453 | 1455 |
| 1454 void test_finalClass() { | 1456 void test_finalClass() { |
| 1455 ParserTestCase.parseCompilationUnit( | 1457 parseCompilationUnit("final class C {}", [ParserErrorCode.FINAL_CLASS]); |
| 1456 "final class C {}", [ParserErrorCode.FINAL_CLASS]); | |
| 1457 } | 1458 } |
| 1458 | 1459 |
| 1459 void test_finalConstructor() { | 1460 void test_finalConstructor() { |
| 1460 createParser('final C() {}'); | 1461 createParser('final C() {}'); |
| 1461 ClassMember member = parser.parseClassMember('C'); | 1462 ClassMember member = parser.parseClassMember('C'); |
| 1462 expectNotNullIfNoErrors(member); | 1463 expectNotNullIfNoErrors(member); |
| 1463 listener.assertErrorsWithCodes([ParserErrorCode.FINAL_CONSTRUCTOR]); | 1464 listener.assertErrorsWithCodes([ParserErrorCode.FINAL_CONSTRUCTOR]); |
| 1464 } | 1465 } |
| 1465 | 1466 |
| 1466 void test_finalEnum() { | 1467 void test_finalEnum() { |
| 1467 ParserTestCase.parseCompilationUnit( | 1468 parseCompilationUnit("final enum E {ONE}", [ParserErrorCode.FINAL_ENUM]); |
| 1468 "final enum E {ONE}", [ParserErrorCode.FINAL_ENUM]); | |
| 1469 } | 1469 } |
| 1470 | 1470 |
| 1471 void test_finalMethod() { | 1471 void test_finalMethod() { |
| 1472 createParser('final int m() {}'); | 1472 createParser('final int m() {}'); |
| 1473 ClassMember member = parser.parseClassMember('C'); | 1473 ClassMember member = parser.parseClassMember('C'); |
| 1474 expectNotNullIfNoErrors(member); | 1474 expectNotNullIfNoErrors(member); |
| 1475 listener.assertErrorsWithCodes([ParserErrorCode.FINAL_METHOD]); | 1475 listener.assertErrorsWithCodes([ParserErrorCode.FINAL_METHOD]); |
| 1476 } | 1476 } |
| 1477 | 1477 |
| 1478 void test_finalTypedef() { | 1478 void test_finalTypedef() { |
| 1479 ParserTestCase.parseCompilationUnit( | 1479 parseCompilationUnit("final typedef F();", [ParserErrorCode.FINAL_TYPEDEF]); |
| 1480 "final typedef F();", [ParserErrorCode.FINAL_TYPEDEF]); | |
| 1481 } | 1480 } |
| 1482 | 1481 |
| 1483 void test_functionTypedParameter_const() { | 1482 void test_functionTypedParameter_const() { |
| 1484 ParserTestCase.parseCompilationUnit( | 1483 parseCompilationUnit( |
| 1485 "void f(const x()) {}", [ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR]); | 1484 "void f(const x()) {}", [ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR]); |
| 1486 } | 1485 } |
| 1487 | 1486 |
| 1488 void test_functionTypedParameter_final() { | 1487 void test_functionTypedParameter_final() { |
| 1489 ParserTestCase.parseCompilationUnit( | 1488 parseCompilationUnit( |
| 1490 "void f(final x()) {}", [ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR]); | 1489 "void f(final x()) {}", [ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR]); |
| 1491 } | 1490 } |
| 1492 | 1491 |
| 1493 void test_functionTypedParameter_var() { | 1492 void test_functionTypedParameter_var() { |
| 1494 ParserTestCase.parseCompilationUnit( | 1493 parseCompilationUnit( |
| 1495 "void f(var x()) {}", [ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR]); | 1494 "void f(var x()) {}", [ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR]); |
| 1496 } | 1495 } |
| 1497 | 1496 |
| 1498 void test_getterInFunction_block_noReturnType() { | 1497 void test_getterInFunction_block_noReturnType() { |
| 1499 FunctionDeclarationStatement statement = ParserTestCase.parseStatement( | 1498 FunctionDeclarationStatement statement = parseStatement( |
| 1500 "get x { return _x; }", [ParserErrorCode.GETTER_IN_FUNCTION]); | 1499 "get x { return _x; }", [ParserErrorCode.GETTER_IN_FUNCTION]); |
| 1501 expect(statement.functionDeclaration.functionExpression.parameters, isNull); | 1500 expect(statement.functionDeclaration.functionExpression.parameters, isNull); |
| 1502 } | 1501 } |
| 1503 | 1502 |
| 1504 void test_getterInFunction_block_returnType() { | 1503 void test_getterInFunction_block_returnType() { |
| 1505 ParserTestCase.parseStatement( | 1504 parseStatement( |
| 1506 "int get x { return _x; }", [ParserErrorCode.GETTER_IN_FUNCTION]); | 1505 "int get x { return _x; }", [ParserErrorCode.GETTER_IN_FUNCTION]); |
| 1507 } | 1506 } |
| 1508 | 1507 |
| 1509 void test_getterInFunction_expression_noReturnType() { | 1508 void test_getterInFunction_expression_noReturnType() { |
| 1510 ParserTestCase | 1509 parseStatement("get x => _x;", [ParserErrorCode.GETTER_IN_FUNCTION]); |
| 1511 .parseStatement("get x => _x;", [ParserErrorCode.GETTER_IN_FUNCTION]); | |
| 1512 } | 1510 } |
| 1513 | 1511 |
| 1514 void test_getterInFunction_expression_returnType() { | 1512 void test_getterInFunction_expression_returnType() { |
| 1515 ParserTestCase.parseStatement( | 1513 parseStatement("int get x => _x;", [ParserErrorCode.GETTER_IN_FUNCTION]); |
| 1516 "int get x => _x;", [ParserErrorCode.GETTER_IN_FUNCTION]); | |
| 1517 } | 1514 } |
| 1518 | 1515 |
| 1519 void test_getterWithParameters() { | 1516 void test_getterWithParameters() { |
| 1520 createParser('int get x() {}'); | 1517 createParser('int get x() {}'); |
| 1521 ClassMember member = parser.parseClassMember('C'); | 1518 ClassMember member = parser.parseClassMember('C'); |
| 1522 expectNotNullIfNoErrors(member); | 1519 expectNotNullIfNoErrors(member); |
| 1523 listener.assertErrorsWithCodes([ParserErrorCode.GETTER_WITH_PARAMETERS]); | 1520 listener.assertErrorsWithCodes([ParserErrorCode.GETTER_WITH_PARAMETERS]); |
| 1524 } | 1521 } |
| 1525 | 1522 |
| 1526 void test_illegalAssignmentToNonAssignable_postfix_minusMinus_literal() { | 1523 void test_illegalAssignmentToNonAssignable_postfix_minusMinus_literal() { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1557 | 1554 |
| 1558 @failingTest | 1555 @failingTest |
| 1559 void test_illegalAssignmentToNonAssignable_superAssigned_failing() { | 1556 void test_illegalAssignmentToNonAssignable_superAssigned_failing() { |
| 1560 // TODO(brianwilkerson) When this test starts to pass, remove the test | 1557 // TODO(brianwilkerson) When this test starts to pass, remove the test |
| 1561 // test_illegalAssignmentToNonAssignable_superAssigned. | 1558 // test_illegalAssignmentToNonAssignable_superAssigned. |
| 1562 parseExpression( | 1559 parseExpression( |
| 1563 "super = x;", [ParserErrorCode.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE]); | 1560 "super = x;", [ParserErrorCode.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE]); |
| 1564 } | 1561 } |
| 1565 | 1562 |
| 1566 void test_implementsBeforeExtends() { | 1563 void test_implementsBeforeExtends() { |
| 1567 ParserTestCase.parseCompilationUnit("class A implements B extends C {}", | 1564 parseCompilationUnit("class A implements B extends C {}", |
| 1568 [ParserErrorCode.IMPLEMENTS_BEFORE_EXTENDS]); | 1565 [ParserErrorCode.IMPLEMENTS_BEFORE_EXTENDS]); |
| 1569 } | 1566 } |
| 1570 | 1567 |
| 1571 void test_implementsBeforeWith() { | 1568 void test_implementsBeforeWith() { |
| 1572 ParserTestCase.parseCompilationUnit( | 1569 parseCompilationUnit("class A extends B implements C with D {}", |
| 1573 "class A extends B implements C with D {}", | |
| 1574 [ParserErrorCode.IMPLEMENTS_BEFORE_WITH]); | 1570 [ParserErrorCode.IMPLEMENTS_BEFORE_WITH]); |
| 1575 } | 1571 } |
| 1576 | 1572 |
| 1577 void test_importDirectiveAfterPartDirective() { | 1573 void test_importDirectiveAfterPartDirective() { |
| 1578 ParserTestCase.parseCompilationUnit("part 'a.dart'; import 'b.dart';", | 1574 parseCompilationUnit("part 'a.dart'; import 'b.dart';", |
| 1579 [ParserErrorCode.IMPORT_DIRECTIVE_AFTER_PART_DIRECTIVE]); | 1575 [ParserErrorCode.IMPORT_DIRECTIVE_AFTER_PART_DIRECTIVE]); |
| 1580 } | 1576 } |
| 1581 | 1577 |
| 1582 void test_initializedVariableInForEach() { | 1578 void test_initializedVariableInForEach() { |
| 1583 createParser('for (int a = 0 in foo) {}'); | 1579 createParser('for (int a = 0 in foo) {}'); |
| 1584 Statement statement = parser.parseForStatement(); | 1580 Statement statement = parser.parseForStatement(); |
| 1585 expectNotNullIfNoErrors(statement); | 1581 expectNotNullIfNoErrors(statement); |
| 1586 listener.assertErrorsWithCodes( | 1582 listener.assertErrorsWithCodes( |
| 1587 [ParserErrorCode.INITIALIZED_VARIABLE_IN_FOR_EACH]); | 1583 [ParserErrorCode.INITIALIZED_VARIABLE_IN_FOR_EACH]); |
| 1588 } | 1584 } |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1748 createParser("'\\u{12345678}'"); | 1744 createParser("'\\u{12345678}'"); |
| 1749 Expression expression = parser.parseStringLiteral(); | 1745 Expression expression = parser.parseStringLiteral(); |
| 1750 expectNotNullIfNoErrors(expression); | 1746 expectNotNullIfNoErrors(expression); |
| 1751 listener.assertErrorsWithCodes([ | 1747 listener.assertErrorsWithCodes([ |
| 1752 ParserErrorCode.INVALID_UNICODE_ESCAPE, | 1748 ParserErrorCode.INVALID_UNICODE_ESCAPE, |
| 1753 ParserErrorCode.INVALID_CODE_POINT | 1749 ParserErrorCode.INVALID_CODE_POINT |
| 1754 ]); | 1750 ]); |
| 1755 } | 1751 } |
| 1756 | 1752 |
| 1757 void test_libraryDirectiveNotFirst() { | 1753 void test_libraryDirectiveNotFirst() { |
| 1758 ParserTestCase.parseCompilationUnit("import 'x.dart'; library l;", | 1754 parseCompilationUnit("import 'x.dart'; library l;", |
| 1759 [ParserErrorCode.LIBRARY_DIRECTIVE_NOT_FIRST]); | 1755 [ParserErrorCode.LIBRARY_DIRECTIVE_NOT_FIRST]); |
| 1760 } | 1756 } |
| 1761 | 1757 |
| 1762 void test_libraryDirectiveNotFirst_afterPart() { | 1758 void test_libraryDirectiveNotFirst_afterPart() { |
| 1763 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 1759 CompilationUnit unit = parseCompilationUnit("part 'a.dart';\nlibrary l;", |
| 1764 "part 'a.dart';\nlibrary l;", | |
| 1765 [ParserErrorCode.LIBRARY_DIRECTIVE_NOT_FIRST]); | 1760 [ParserErrorCode.LIBRARY_DIRECTIVE_NOT_FIRST]); |
| 1766 expect(unit, isNotNull); | 1761 expect(unit, isNotNull); |
| 1767 } | 1762 } |
| 1768 | 1763 |
| 1769 void test_localFunctionDeclarationModifier_abstract() { | 1764 void test_localFunctionDeclarationModifier_abstract() { |
| 1770 ParserTestCase.parseStatement("abstract f() {}", | 1765 parseStatement("abstract f() {}", |
| 1771 [ParserErrorCode.LOCAL_FUNCTION_DECLARATION_MODIFIER]); | 1766 [ParserErrorCode.LOCAL_FUNCTION_DECLARATION_MODIFIER]); |
| 1772 } | 1767 } |
| 1773 | 1768 |
| 1774 void test_localFunctionDeclarationModifier_external() { | 1769 void test_localFunctionDeclarationModifier_external() { |
| 1775 ParserTestCase.parseStatement("external f() {}", | 1770 parseStatement("external f() {}", |
| 1776 [ParserErrorCode.LOCAL_FUNCTION_DECLARATION_MODIFIER]); | 1771 [ParserErrorCode.LOCAL_FUNCTION_DECLARATION_MODIFIER]); |
| 1777 } | 1772 } |
| 1778 | 1773 |
| 1779 void test_localFunctionDeclarationModifier_factory() { | 1774 void test_localFunctionDeclarationModifier_factory() { |
| 1780 ParserTestCase.parseStatement("factory f() {}", | 1775 parseStatement("factory f() {}", |
| 1781 [ParserErrorCode.LOCAL_FUNCTION_DECLARATION_MODIFIER]); | 1776 [ParserErrorCode.LOCAL_FUNCTION_DECLARATION_MODIFIER]); |
| 1782 } | 1777 } |
| 1783 | 1778 |
| 1784 void test_localFunctionDeclarationModifier_static() { | 1779 void test_localFunctionDeclarationModifier_static() { |
| 1785 ParserTestCase.parseStatement( | 1780 parseStatement( |
| 1786 "static f() {}", [ParserErrorCode.LOCAL_FUNCTION_DECLARATION_MODIFIER]); | 1781 "static f() {}", [ParserErrorCode.LOCAL_FUNCTION_DECLARATION_MODIFIER]); |
| 1787 } | 1782 } |
| 1788 | 1783 |
| 1789 void test_method_invalidTypeParameterComments() { | 1784 void test_method_invalidTypeParameterComments() { |
| 1790 enableGenericMethodComments = true; | 1785 enableGenericMethodComments = true; |
| 1791 createParser('void m/*<E, hello!>*/() {}'); | 1786 createParser('void m/*<E, hello!>*/() {}'); |
| 1792 ClassMember member = parser.parseClassMember('C'); | 1787 ClassMember member = parser.parseClassMember('C'); |
| 1793 expectNotNullIfNoErrors(member); | 1788 expectNotNullIfNoErrors(member); |
| 1794 listener.assertErrorsWithCodes([ | 1789 listener.assertErrorsWithCodes([ |
| 1795 ParserErrorCode.EXPECTED_TOKEN /*>*/, | 1790 ParserErrorCode.EXPECTED_TOKEN /*>*/, |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1902 | 1897 |
| 1903 void test_missingCatchOrFinally() { | 1898 void test_missingCatchOrFinally() { |
| 1904 createParser('try {}'); | 1899 createParser('try {}'); |
| 1905 TryStatement statement = parser.parseTryStatement(); | 1900 TryStatement statement = parser.parseTryStatement(); |
| 1906 expectNotNullIfNoErrors(statement); | 1901 expectNotNullIfNoErrors(statement); |
| 1907 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_CATCH_OR_FINALLY]); | 1902 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_CATCH_OR_FINALLY]); |
| 1908 expect(statement, isNotNull); | 1903 expect(statement, isNotNull); |
| 1909 } | 1904 } |
| 1910 | 1905 |
| 1911 void test_missingClassBody() { | 1906 void test_missingClassBody() { |
| 1912 ParserTestCase.parseCompilationUnit( | 1907 parseCompilationUnit( |
| 1913 "class A class B {}", [ParserErrorCode.MISSING_CLASS_BODY]); | 1908 "class A class B {}", [ParserErrorCode.MISSING_CLASS_BODY]); |
| 1914 } | 1909 } |
| 1915 | 1910 |
| 1916 @failingTest | 1911 @failingTest |
| 1917 void test_missingClosingParenthesis() { | 1912 void test_missingClosingParenthesis() { |
| 1918 // It is possible that it is not possible to generate this error (that it's | 1913 // It is possible that it is not possible to generate this error (that it's |
| 1919 // being reported in code that cannot actually be reached), but that hasn't | 1914 // being reported in code that cannot actually be reached), but that hasn't |
| 1920 // been proven yet. | 1915 // been proven yet. |
| 1921 createParser('(int a, int b ;'); | 1916 createParser('(int a, int b ;'); |
| 1922 FormalParameterList list = parser.parseFormalParameterList(); | 1917 FormalParameterList list = parser.parseFormalParameterList(); |
| 1923 expectNotNullIfNoErrors(list); | 1918 expectNotNullIfNoErrors(list); |
| 1924 listener | 1919 listener |
| 1925 .assertErrorsWithCodes([ParserErrorCode.MISSING_CLOSING_PARENTHESIS]); | 1920 .assertErrorsWithCodes([ParserErrorCode.MISSING_CLOSING_PARENTHESIS]); |
| 1926 } | 1921 } |
| 1927 | 1922 |
| 1928 void test_missingConstFinalVarOrType_static() { | 1923 void test_missingConstFinalVarOrType_static() { |
| 1929 ParserTestCase.parseCompilationUnit("class A { static f; }", | 1924 parseCompilationUnit("class A { static f; }", |
| 1930 [ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE]); | 1925 [ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE]); |
| 1931 } | 1926 } |
| 1932 | 1927 |
| 1933 void test_missingConstFinalVarOrType_topLevel() { | 1928 void test_missingConstFinalVarOrType_topLevel() { |
| 1934 createParser('a;'); | 1929 createParser('a;'); |
| 1935 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); | 1930 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| 1936 expectNotNullIfNoErrors(result); | 1931 expectNotNullIfNoErrors(result); |
| 1937 listener.assertErrorsWithCodes( | 1932 listener.assertErrorsWithCodes( |
| 1938 [ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE]); | 1933 [ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE]); |
| 1939 } | 1934 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1976 false, ParserErrorCode.MISSING_FUNCTION_BODY, false); | 1971 false, ParserErrorCode.MISSING_FUNCTION_BODY, false); |
| 1977 expectNotNullIfNoErrors(functionBody); | 1972 expectNotNullIfNoErrors(functionBody); |
| 1978 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_FUNCTION_BODY]); | 1973 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_FUNCTION_BODY]); |
| 1979 } | 1974 } |
| 1980 | 1975 |
| 1981 @failingTest | 1976 @failingTest |
| 1982 void test_missingFunctionParameters_local_nonVoid_block() { | 1977 void test_missingFunctionParameters_local_nonVoid_block() { |
| 1983 // The parser does not recognize this as a function declaration, so it tries | 1978 // The parser does not recognize this as a function declaration, so it tries |
| 1984 // to parse it as an expression statement. It isn't clear what the best | 1979 // to parse it as an expression statement. It isn't clear what the best |
| 1985 // error message is in this case. | 1980 // error message is in this case. |
| 1986 ParserTestCase.parseStatement( | 1981 parseStatement( |
| 1987 "int f { return x;}", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); | 1982 "int f { return x;}", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); |
| 1988 } | 1983 } |
| 1989 | 1984 |
| 1990 @failingTest | 1985 @failingTest |
| 1991 void test_missingFunctionParameters_local_nonVoid_expression() { | 1986 void test_missingFunctionParameters_local_nonVoid_expression() { |
| 1992 // The parser does not recognize this as a function declaration, so it tries | 1987 // The parser does not recognize this as a function declaration, so it tries |
| 1993 // to parse it as an expression statement. It isn't clear what the best | 1988 // to parse it as an expression statement. It isn't clear what the best |
| 1994 // error message is in this case. | 1989 // error message is in this case. |
| 1995 ParserTestCase.parseStatement( | 1990 parseStatement( |
| 1996 "int f => x;", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); | 1991 "int f => x;", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); |
| 1997 } | 1992 } |
| 1998 | 1993 |
| 1999 void test_missingFunctionParameters_local_void_block() { | 1994 void test_missingFunctionParameters_local_void_block() { |
| 2000 ParserTestCase.parseStatement( | 1995 parseStatement( |
| 2001 "void f { return x;}", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); | 1996 "void f { return x;}", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); |
| 2002 } | 1997 } |
| 2003 | 1998 |
| 2004 void test_missingFunctionParameters_local_void_expression() { | 1999 void test_missingFunctionParameters_local_void_expression() { |
| 2005 ParserTestCase.parseStatement( | 2000 parseStatement( |
| 2006 "void f => x;", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); | 2001 "void f => x;", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); |
| 2007 } | 2002 } |
| 2008 | 2003 |
| 2009 void test_missingFunctionParameters_topLevel_nonVoid_block() { | 2004 void test_missingFunctionParameters_topLevel_nonVoid_block() { |
| 2010 ParserTestCase.parseCompilationUnit( | 2005 parseCompilationUnit( |
| 2011 "int f { return x;}", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); | 2006 "int f { return x;}", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); |
| 2012 } | 2007 } |
| 2013 | 2008 |
| 2014 void test_missingFunctionParameters_topLevel_nonVoid_expression() { | 2009 void test_missingFunctionParameters_topLevel_nonVoid_expression() { |
| 2015 ParserTestCase.parseCompilationUnit( | 2010 parseCompilationUnit( |
| 2016 "int f => x;", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); | 2011 "int f => x;", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); |
| 2017 } | 2012 } |
| 2018 | 2013 |
| 2019 void test_missingFunctionParameters_topLevel_void_block() { | 2014 void test_missingFunctionParameters_topLevel_void_block() { |
| 2020 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 2015 CompilationUnit unit = parseCompilationUnit( |
| 2021 "void f { return x;}", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); | 2016 "void f { return x;}", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); |
| 2022 FunctionDeclaration funct = unit.declarations[0]; | 2017 FunctionDeclaration funct = unit.declarations[0]; |
| 2023 expect(funct.functionExpression.parameters, hasLength(0)); | 2018 expect(funct.functionExpression.parameters, hasLength(0)); |
| 2024 } | 2019 } |
| 2025 | 2020 |
| 2026 void test_missingFunctionParameters_topLevel_void_expression() { | 2021 void test_missingFunctionParameters_topLevel_void_expression() { |
| 2027 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 2022 CompilationUnit unit = parseCompilationUnit( |
| 2028 "void f => x;", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); | 2023 "void f => x;", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); |
| 2029 FunctionDeclaration funct = unit.declarations[0]; | 2024 FunctionDeclaration funct = unit.declarations[0]; |
| 2030 expect(funct.functionExpression.parameters, hasLength(0)); | 2025 expect(funct.functionExpression.parameters, hasLength(0)); |
| 2031 } | 2026 } |
| 2032 | 2027 |
| 2033 void test_missingIdentifier_afterOperator() { | 2028 void test_missingIdentifier_afterOperator() { |
| 2034 createParser('1 *'); | 2029 createParser('1 *'); |
| 2035 BinaryExpression expression = parser.parseMultiplicativeExpression(); | 2030 BinaryExpression expression = parser.parseMultiplicativeExpression(); |
| 2036 expectNotNullIfNoErrors(expression); | 2031 expectNotNullIfNoErrors(expression); |
| 2037 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); | 2032 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2153 void test_missingNameForNamedParameter_noDefault() { | 2148 void test_missingNameForNamedParameter_noDefault() { |
| 2154 createParser('int'); | 2149 createParser('int'); |
| 2155 FormalParameter parameter = | 2150 FormalParameter parameter = |
| 2156 parser.parseFormalParameter(ParameterKind.NAMED, inFunctionType: true); | 2151 parser.parseFormalParameter(ParameterKind.NAMED, inFunctionType: true); |
| 2157 expectNotNullIfNoErrors(parameter); | 2152 expectNotNullIfNoErrors(parameter); |
| 2158 listener.assertErrorsWithCodes( | 2153 listener.assertErrorsWithCodes( |
| 2159 [ParserErrorCode.MISSING_NAME_FOR_NAMED_PARAMETER]); | 2154 [ParserErrorCode.MISSING_NAME_FOR_NAMED_PARAMETER]); |
| 2160 } | 2155 } |
| 2161 | 2156 |
| 2162 void test_missingNameInLibraryDirective() { | 2157 void test_missingNameInLibraryDirective() { |
| 2163 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 2158 CompilationUnit unit = parseCompilationUnit( |
| 2164 "library;", [ParserErrorCode.MISSING_NAME_IN_LIBRARY_DIRECTIVE]); | 2159 "library;", [ParserErrorCode.MISSING_NAME_IN_LIBRARY_DIRECTIVE]); |
| 2165 expect(unit, isNotNull); | 2160 expect(unit, isNotNull); |
| 2166 } | 2161 } |
| 2167 | 2162 |
| 2168 void test_missingNameInPartOfDirective() { | 2163 void test_missingNameInPartOfDirective() { |
| 2169 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 2164 CompilationUnit unit = parseCompilationUnit( |
| 2170 "part of;", [ParserErrorCode.MISSING_NAME_IN_PART_OF_DIRECTIVE]); | 2165 "part of;", [ParserErrorCode.MISSING_NAME_IN_PART_OF_DIRECTIVE]); |
| 2171 expect(unit, isNotNull); | 2166 expect(unit, isNotNull); |
| 2172 } | 2167 } |
| 2173 | 2168 |
| 2174 void test_missingPrefixInDeferredImport() { | 2169 void test_missingPrefixInDeferredImport() { |
| 2175 ParserTestCase.parseCompilationUnit("import 'foo.dart' deferred;", | 2170 parseCompilationUnit("import 'foo.dart' deferred;", |
| 2176 [ParserErrorCode.MISSING_PREFIX_IN_DEFERRED_IMPORT]); | 2171 [ParserErrorCode.MISSING_PREFIX_IN_DEFERRED_IMPORT]); |
| 2177 } | 2172 } |
| 2178 | 2173 |
| 2179 void test_missingStartAfterSync() { | 2174 void test_missingStartAfterSync() { |
| 2180 createParser('sync {}'); | 2175 createParser('sync {}'); |
| 2181 FunctionBody functionBody = parser.parseFunctionBody(false, null, false); | 2176 FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
| 2182 expectNotNullIfNoErrors(functionBody); | 2177 expectNotNullIfNoErrors(functionBody); |
| 2183 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_STAR_AFTER_SYNC]); | 2178 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_STAR_AFTER_SYNC]); |
| 2184 } | 2179 } |
| 2185 | 2180 |
| 2186 void test_missingStatement() { | 2181 void test_missingStatement() { |
| 2187 ParserTestCase.parseStatement("is", [ParserErrorCode.MISSING_STATEMENT]); | 2182 parseStatement("is", [ParserErrorCode.MISSING_STATEMENT]); |
| 2188 } | 2183 } |
| 2189 | 2184 |
| 2190 void test_missingStatement_afterVoid() { | 2185 void test_missingStatement_afterVoid() { |
| 2191 ParserTestCase.parseStatement("void;", [ParserErrorCode.MISSING_STATEMENT]); | 2186 parseStatement("void;", [ParserErrorCode.MISSING_STATEMENT]); |
| 2192 } | 2187 } |
| 2193 | 2188 |
| 2194 void test_missingTerminatorForParameterGroup_named() { | 2189 void test_missingTerminatorForParameterGroup_named() { |
| 2195 createParser('(a, {b: 0)'); | 2190 createParser('(a, {b: 0)'); |
| 2196 FormalParameterList list = parser.parseFormalParameterList(); | 2191 FormalParameterList list = parser.parseFormalParameterList(); |
| 2197 expectNotNullIfNoErrors(list); | 2192 expectNotNullIfNoErrors(list); |
| 2198 listener.assertErrorsWithCodes( | 2193 listener.assertErrorsWithCodes( |
| 2199 [ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETER_GROUP]); | 2194 [ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETER_GROUP]); |
| 2200 } | 2195 } |
| 2201 | 2196 |
| 2202 void test_missingTerminatorForParameterGroup_optional() { | 2197 void test_missingTerminatorForParameterGroup_optional() { |
| 2203 createParser('(a, [b = 0)'); | 2198 createParser('(a, [b = 0)'); |
| 2204 FormalParameterList list = parser.parseFormalParameterList(); | 2199 FormalParameterList list = parser.parseFormalParameterList(); |
| 2205 expectNotNullIfNoErrors(list); | 2200 expectNotNullIfNoErrors(list); |
| 2206 listener.assertErrorsWithCodes( | 2201 listener.assertErrorsWithCodes( |
| 2207 [ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETER_GROUP]); | 2202 [ParserErrorCode.MISSING_TERMINATOR_FOR_PARAMETER_GROUP]); |
| 2208 } | 2203 } |
| 2209 | 2204 |
| 2210 void test_missingTypedefParameters_nonVoid() { | 2205 void test_missingTypedefParameters_nonVoid() { |
| 2211 ParserTestCase.parseCompilationUnit( | 2206 parseCompilationUnit( |
| 2212 "typedef int F;", [ParserErrorCode.MISSING_TYPEDEF_PARAMETERS]); | 2207 "typedef int F;", [ParserErrorCode.MISSING_TYPEDEF_PARAMETERS]); |
| 2213 } | 2208 } |
| 2214 | 2209 |
| 2215 void test_missingTypedefParameters_typeParameters() { | 2210 void test_missingTypedefParameters_typeParameters() { |
| 2216 ParserTestCase.parseCompilationUnit( | 2211 parseCompilationUnit( |
| 2217 "typedef F<E>;", [ParserErrorCode.MISSING_TYPEDEF_PARAMETERS]); | 2212 "typedef F<E>;", [ParserErrorCode.MISSING_TYPEDEF_PARAMETERS]); |
| 2218 } | 2213 } |
| 2219 | 2214 |
| 2220 void test_missingTypedefParameters_void() { | 2215 void test_missingTypedefParameters_void() { |
| 2221 ParserTestCase.parseCompilationUnit( | 2216 parseCompilationUnit( |
| 2222 "typedef void F;", [ParserErrorCode.MISSING_TYPEDEF_PARAMETERS]); | 2217 "typedef void F;", [ParserErrorCode.MISSING_TYPEDEF_PARAMETERS]); |
| 2223 } | 2218 } |
| 2224 | 2219 |
| 2225 void test_missingVariableInForEach() { | 2220 void test_missingVariableInForEach() { |
| 2226 createParser('for (a < b in foo) {}'); | 2221 createParser('for (a < b in foo) {}'); |
| 2227 Statement statement = parser.parseForStatement(); | 2222 Statement statement = parser.parseForStatement(); |
| 2228 expectNotNullIfNoErrors(statement); | 2223 expectNotNullIfNoErrors(statement); |
| 2229 listener | 2224 listener |
| 2230 .assertErrorsWithCodes([ParserErrorCode.MISSING_VARIABLE_IN_FOR_EACH]); | 2225 .assertErrorsWithCodes([ParserErrorCode.MISSING_VARIABLE_IN_FOR_EACH]); |
| 2231 } | 2226 } |
| 2232 | 2227 |
| 2233 void test_mixedParameterGroups_namedPositional() { | 2228 void test_mixedParameterGroups_namedPositional() { |
| 2234 createParser('(a, {b}, [c])'); | 2229 createParser('(a, {b}, [c])'); |
| 2235 FormalParameterList list = parser.parseFormalParameterList(); | 2230 FormalParameterList list = parser.parseFormalParameterList(); |
| 2236 expectNotNullIfNoErrors(list); | 2231 expectNotNullIfNoErrors(list); |
| 2237 listener.assertErrorsWithCodes([ParserErrorCode.MIXED_PARAMETER_GROUPS]); | 2232 listener.assertErrorsWithCodes([ParserErrorCode.MIXED_PARAMETER_GROUPS]); |
| 2238 } | 2233 } |
| 2239 | 2234 |
| 2240 void test_mixedParameterGroups_positionalNamed() { | 2235 void test_mixedParameterGroups_positionalNamed() { |
| 2241 createParser('(a, [b], {c})'); | 2236 createParser('(a, [b], {c})'); |
| 2242 FormalParameterList list = parser.parseFormalParameterList(); | 2237 FormalParameterList list = parser.parseFormalParameterList(); |
| 2243 expectNotNullIfNoErrors(list); | 2238 expectNotNullIfNoErrors(list); |
| 2244 listener.assertErrorsWithCodes([ParserErrorCode.MIXED_PARAMETER_GROUPS]); | 2239 listener.assertErrorsWithCodes([ParserErrorCode.MIXED_PARAMETER_GROUPS]); |
| 2245 } | 2240 } |
| 2246 | 2241 |
| 2247 void test_mixin_application_lacks_with_clause() { | 2242 void test_mixin_application_lacks_with_clause() { |
| 2248 ParserTestCase.parseCompilationUnit( | 2243 parseCompilationUnit("class Foo = Bar;", [ParserErrorCode.EXPECTED_TOKEN]); |
| 2249 "class Foo = Bar;", [ParserErrorCode.EXPECTED_TOKEN]); | |
| 2250 } | 2244 } |
| 2251 | 2245 |
| 2252 void test_multipleExtendsClauses() { | 2246 void test_multipleExtendsClauses() { |
| 2253 ParserTestCase.parseCompilationUnit("class A extends B extends C {}", | 2247 parseCompilationUnit("class A extends B extends C {}", |
| 2254 [ParserErrorCode.MULTIPLE_EXTENDS_CLAUSES]); | 2248 [ParserErrorCode.MULTIPLE_EXTENDS_CLAUSES]); |
| 2255 } | 2249 } |
| 2256 | 2250 |
| 2257 void test_multipleImplementsClauses() { | 2251 void test_multipleImplementsClauses() { |
| 2258 ParserTestCase.parseCompilationUnit("class A implements B implements C {}", | 2252 parseCompilationUnit("class A implements B implements C {}", |
| 2259 [ParserErrorCode.MULTIPLE_IMPLEMENTS_CLAUSES]); | 2253 [ParserErrorCode.MULTIPLE_IMPLEMENTS_CLAUSES]); |
| 2260 } | 2254 } |
| 2261 | 2255 |
| 2262 void test_multipleLibraryDirectives() { | 2256 void test_multipleLibraryDirectives() { |
| 2263 ParserTestCase.parseCompilationUnit( | 2257 parseCompilationUnit( |
| 2264 "library l; library m;", [ParserErrorCode.MULTIPLE_LIBRARY_DIRECTIVES]); | 2258 "library l; library m;", [ParserErrorCode.MULTIPLE_LIBRARY_DIRECTIVES]); |
| 2265 } | 2259 } |
| 2266 | 2260 |
| 2267 void test_multipleNamedParameterGroups() { | 2261 void test_multipleNamedParameterGroups() { |
| 2268 createParser('(a, {b}, {c})'); | 2262 createParser('(a, {b}, {c})'); |
| 2269 FormalParameterList list = parser.parseFormalParameterList(); | 2263 FormalParameterList list = parser.parseFormalParameterList(); |
| 2270 expectNotNullIfNoErrors(list); | 2264 expectNotNullIfNoErrors(list); |
| 2271 listener.assertErrorsWithCodes( | 2265 listener.assertErrorsWithCodes( |
| 2272 [ParserErrorCode.MULTIPLE_NAMED_PARAMETER_GROUPS]); | 2266 [ParserErrorCode.MULTIPLE_NAMED_PARAMETER_GROUPS]); |
| 2273 } | 2267 } |
| 2274 | 2268 |
| 2275 void test_multiplePartOfDirectives() { | 2269 void test_multiplePartOfDirectives() { |
| 2276 ParserTestCase.parseCompilationUnit( | 2270 parseCompilationUnit( |
| 2277 "part of l; part of m;", [ParserErrorCode.MULTIPLE_PART_OF_DIRECTIVES]); | 2271 "part of l; part of m;", [ParserErrorCode.MULTIPLE_PART_OF_DIRECTIVES]); |
| 2278 } | 2272 } |
| 2279 | 2273 |
| 2280 void test_multiplePositionalParameterGroups() { | 2274 void test_multiplePositionalParameterGroups() { |
| 2281 createParser('(a, [b], [c])'); | 2275 createParser('(a, [b], [c])'); |
| 2282 FormalParameterList list = parser.parseFormalParameterList(); | 2276 FormalParameterList list = parser.parseFormalParameterList(); |
| 2283 expectNotNullIfNoErrors(list); | 2277 expectNotNullIfNoErrors(list); |
| 2284 listener.assertErrorsWithCodes( | 2278 listener.assertErrorsWithCodes( |
| 2285 [ParserErrorCode.MULTIPLE_POSITIONAL_PARAMETER_GROUPS]); | 2279 [ParserErrorCode.MULTIPLE_POSITIONAL_PARAMETER_GROUPS]); |
| 2286 } | 2280 } |
| 2287 | 2281 |
| 2288 void test_multipleVariablesInForEach() { | 2282 void test_multipleVariablesInForEach() { |
| 2289 createParser('for (int a, b in foo) {}'); | 2283 createParser('for (int a, b in foo) {}'); |
| 2290 Statement statement = parser.parseForStatement(); | 2284 Statement statement = parser.parseForStatement(); |
| 2291 expectNotNullIfNoErrors(statement); | 2285 expectNotNullIfNoErrors(statement); |
| 2292 listener.assertErrorsWithCodes( | 2286 listener.assertErrorsWithCodes( |
| 2293 [ParserErrorCode.MULTIPLE_VARIABLES_IN_FOR_EACH]); | 2287 [ParserErrorCode.MULTIPLE_VARIABLES_IN_FOR_EACH]); |
| 2294 } | 2288 } |
| 2295 | 2289 |
| 2296 void test_multipleWithClauses() { | 2290 void test_multipleWithClauses() { |
| 2297 ParserTestCase.parseCompilationUnit("class A extends B with C with D {}", | 2291 parseCompilationUnit("class A extends B with C with D {}", |
| 2298 [ParserErrorCode.MULTIPLE_WITH_CLAUSES]); | 2292 [ParserErrorCode.MULTIPLE_WITH_CLAUSES]); |
| 2299 } | 2293 } |
| 2300 | 2294 |
| 2301 @failingTest | 2295 @failingTest |
| 2302 void test_namedFunctionExpression() { | 2296 void test_namedFunctionExpression() { |
| 2303 createParser('f() {}'); | 2297 createParser('f() {}'); |
| 2304 Expression expression = parser.parsePrimaryExpression(); | 2298 Expression expression = parser.parsePrimaryExpression(); |
| 2305 expectNotNullIfNoErrors(expression); | 2299 expectNotNullIfNoErrors(expression); |
| 2306 listener.assertErrorsWithCodes([ParserErrorCode.NAMED_FUNCTION_EXPRESSION]); | 2300 listener.assertErrorsWithCodes([ParserErrorCode.NAMED_FUNCTION_EXPRESSION]); |
| 2307 expect(expression, new isInstanceOf<FunctionExpression>()); | 2301 expect(expression, new isInstanceOf<FunctionExpression>()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2325 } | 2319 } |
| 2326 | 2320 |
| 2327 void test_nonConstructorFactory_method() { | 2321 void test_nonConstructorFactory_method() { |
| 2328 createParser('factory int m() {}'); | 2322 createParser('factory int m() {}'); |
| 2329 ClassMember member = parser.parseClassMember('C'); | 2323 ClassMember member = parser.parseClassMember('C'); |
| 2330 expectNotNullIfNoErrors(member); | 2324 expectNotNullIfNoErrors(member); |
| 2331 listener.assertErrorsWithCodes([ParserErrorCode.NON_CONSTRUCTOR_FACTORY]); | 2325 listener.assertErrorsWithCodes([ParserErrorCode.NON_CONSTRUCTOR_FACTORY]); |
| 2332 } | 2326 } |
| 2333 | 2327 |
| 2334 void test_nonIdentifierLibraryName_library() { | 2328 void test_nonIdentifierLibraryName_library() { |
| 2335 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 2329 CompilationUnit unit = parseCompilationUnit( |
| 2336 "library 'lib';", [ParserErrorCode.NON_IDENTIFIER_LIBRARY_NAME]); | 2330 "library 'lib';", [ParserErrorCode.NON_IDENTIFIER_LIBRARY_NAME]); |
| 2337 expect(unit, isNotNull); | 2331 expect(unit, isNotNull); |
| 2338 } | 2332 } |
| 2339 | 2333 |
| 2340 void test_nonIdentifierLibraryName_partOf() { | 2334 void test_nonIdentifierLibraryName_partOf() { |
| 2341 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 2335 CompilationUnit unit = parseCompilationUnit( |
| 2342 "part of 'lib';", [ParserErrorCode.NON_IDENTIFIER_LIBRARY_NAME]); | 2336 "part of 'lib';", [ParserErrorCode.NON_IDENTIFIER_LIBRARY_NAME]); |
| 2343 expect(unit, isNotNull); | 2337 expect(unit, isNotNull); |
| 2344 } | 2338 } |
| 2345 | 2339 |
| 2346 void test_nonPartOfDirectiveInPart_after() { | 2340 void test_nonPartOfDirectiveInPart_after() { |
| 2347 ParserTestCase.parseCompilationUnit("part of l; part 'f.dart';", | 2341 parseCompilationUnit("part of l; part 'f.dart';", |
| 2348 [ParserErrorCode.NON_PART_OF_DIRECTIVE_IN_PART]); | 2342 [ParserErrorCode.NON_PART_OF_DIRECTIVE_IN_PART]); |
| 2349 } | 2343 } |
| 2350 | 2344 |
| 2351 void test_nonPartOfDirectiveInPart_before() { | 2345 void test_nonPartOfDirectiveInPart_before() { |
| 2352 ParserTestCase.parseCompilationUnit("part 'f.dart'; part of m;", | 2346 parseCompilationUnit("part 'f.dart'; part of m;", |
| 2353 [ParserErrorCode.NON_PART_OF_DIRECTIVE_IN_PART]); | 2347 [ParserErrorCode.NON_PART_OF_DIRECTIVE_IN_PART]); |
| 2354 } | 2348 } |
| 2355 | 2349 |
| 2356 void test_nonUserDefinableOperator() { | 2350 void test_nonUserDefinableOperator() { |
| 2357 createParser('operator +=(int x) => x + 1;'); | 2351 createParser('operator +=(int x) => x + 1;'); |
| 2358 ClassMember member = parser.parseClassMember('C'); | 2352 ClassMember member = parser.parseClassMember('C'); |
| 2359 expectNotNullIfNoErrors(member); | 2353 expectNotNullIfNoErrors(member); |
| 2360 listener | 2354 listener |
| 2361 .assertErrorsWithCodes([ParserErrorCode.NON_USER_DEFINABLE_OPERATOR]); | 2355 .assertErrorsWithCodes([ParserErrorCode.NON_USER_DEFINABLE_OPERATOR]); |
| 2362 } | 2356 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2388 | 2382 |
| 2389 void test_nullableTypeParameter() { | 2383 void test_nullableTypeParameter() { |
| 2390 enableNnbd = true; | 2384 enableNnbd = true; |
| 2391 createParser('T?'); | 2385 createParser('T?'); |
| 2392 TypeParameter parameter = parser.parseTypeParameter(); | 2386 TypeParameter parameter = parser.parseTypeParameter(); |
| 2393 expectNotNullIfNoErrors(parameter); | 2387 expectNotNullIfNoErrors(parameter); |
| 2394 listener.assertErrorsWithCodes([ParserErrorCode.NULLABLE_TYPE_PARAMETER]); | 2388 listener.assertErrorsWithCodes([ParserErrorCode.NULLABLE_TYPE_PARAMETER]); |
| 2395 } | 2389 } |
| 2396 | 2390 |
| 2397 void test_optionalAfterNormalParameters_named() { | 2391 void test_optionalAfterNormalParameters_named() { |
| 2398 ParserTestCase.parseCompilationUnit( | 2392 parseCompilationUnit( |
| 2399 "f({a}, b) {}", [ParserErrorCode.NORMAL_BEFORE_OPTIONAL_PARAMETERS]); | 2393 "f({a}, b) {}", [ParserErrorCode.NORMAL_BEFORE_OPTIONAL_PARAMETERS]); |
| 2400 } | 2394 } |
| 2401 | 2395 |
| 2402 void test_optionalAfterNormalParameters_positional() { | 2396 void test_optionalAfterNormalParameters_positional() { |
| 2403 ParserTestCase.parseCompilationUnit( | 2397 parseCompilationUnit( |
| 2404 "f([a], b) {}", [ParserErrorCode.NORMAL_BEFORE_OPTIONAL_PARAMETERS]); | 2398 "f([a], b) {}", [ParserErrorCode.NORMAL_BEFORE_OPTIONAL_PARAMETERS]); |
| 2405 } | 2399 } |
| 2406 | 2400 |
| 2407 void test_parseCascadeSection_missingIdentifier() { | 2401 void test_parseCascadeSection_missingIdentifier() { |
| 2408 createParser('..()'); | 2402 createParser('..()'); |
| 2409 MethodInvocation methodInvocation = parser.parseCascadeSection(); | 2403 MethodInvocation methodInvocation = parser.parseCascadeSection(); |
| 2410 expectNotNullIfNoErrors(methodInvocation); | 2404 expectNotNullIfNoErrors(methodInvocation); |
| 2411 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); | 2405 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| 2412 expect(methodInvocation.target, isNull); | 2406 expect(methodInvocation.target, isNull); |
| 2413 expect(methodInvocation.methodName.name, ""); | 2407 expect(methodInvocation.methodName.name, ""); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2462 | 2456 |
| 2463 void test_redirectionInNonFactoryConstructor() { | 2457 void test_redirectionInNonFactoryConstructor() { |
| 2464 createParser('C() = D;'); | 2458 createParser('C() = D;'); |
| 2465 ClassMember member = parser.parseClassMember('C'); | 2459 ClassMember member = parser.parseClassMember('C'); |
| 2466 expectNotNullIfNoErrors(member); | 2460 expectNotNullIfNoErrors(member); |
| 2467 listener.assertErrorsWithCodes( | 2461 listener.assertErrorsWithCodes( |
| 2468 [ParserErrorCode.REDIRECTION_IN_NON_FACTORY_CONSTRUCTOR]); | 2462 [ParserErrorCode.REDIRECTION_IN_NON_FACTORY_CONSTRUCTOR]); |
| 2469 } | 2463 } |
| 2470 | 2464 |
| 2471 void test_setterInFunction_block() { | 2465 void test_setterInFunction_block() { |
| 2472 ParserTestCase.parseStatement( | 2466 parseStatement("set x(v) {_x = v;}", [ParserErrorCode.SETTER_IN_FUNCTION]); |
| 2473 "set x(v) {_x = v;}", [ParserErrorCode.SETTER_IN_FUNCTION]); | |
| 2474 } | 2467 } |
| 2475 | 2468 |
| 2476 void test_setterInFunction_expression() { | 2469 void test_setterInFunction_expression() { |
| 2477 ParserTestCase.parseStatement( | 2470 parseStatement("set x(v) => _x = v;", [ParserErrorCode.SETTER_IN_FUNCTION]); |
| 2478 "set x(v) => _x = v;", [ParserErrorCode.SETTER_IN_FUNCTION]); | |
| 2479 } | 2471 } |
| 2480 | 2472 |
| 2481 void test_staticAfterConst() { | 2473 void test_staticAfterConst() { |
| 2482 createParser('final static int f;'); | 2474 createParser('final static int f;'); |
| 2483 ClassMember member = parser.parseClassMember('C'); | 2475 ClassMember member = parser.parseClassMember('C'); |
| 2484 expectNotNullIfNoErrors(member); | 2476 expectNotNullIfNoErrors(member); |
| 2485 listener.assertErrorsWithCodes([ParserErrorCode.STATIC_AFTER_FINAL]); | 2477 listener.assertErrorsWithCodes([ParserErrorCode.STATIC_AFTER_FINAL]); |
| 2486 } | 2478 } |
| 2487 | 2479 |
| 2488 void test_staticAfterFinal() { | 2480 void test_staticAfterFinal() { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2530 | 2522 |
| 2531 void test_staticSetterWithoutBody() { | 2523 void test_staticSetterWithoutBody() { |
| 2532 createParser('static set m(x);'); | 2524 createParser('static set m(x);'); |
| 2533 ClassMember member = parser.parseClassMember('C'); | 2525 ClassMember member = parser.parseClassMember('C'); |
| 2534 expectNotNullIfNoErrors(member); | 2526 expectNotNullIfNoErrors(member); |
| 2535 listener | 2527 listener |
| 2536 .assertErrorsWithCodes([ParserErrorCode.STATIC_SETTER_WITHOUT_BODY]); | 2528 .assertErrorsWithCodes([ParserErrorCode.STATIC_SETTER_WITHOUT_BODY]); |
| 2537 } | 2529 } |
| 2538 | 2530 |
| 2539 void test_staticTopLevelDeclaration_class() { | 2531 void test_staticTopLevelDeclaration_class() { |
| 2540 ParserTestCase.parseCompilationUnit( | 2532 parseCompilationUnit( |
| 2541 "static class C {}", [ParserErrorCode.STATIC_TOP_LEVEL_DECLARATION]); | 2533 "static class C {}", [ParserErrorCode.STATIC_TOP_LEVEL_DECLARATION]); |
| 2542 } | 2534 } |
| 2543 | 2535 |
| 2544 void test_staticTopLevelDeclaration_enum() { | 2536 void test_staticTopLevelDeclaration_enum() { |
| 2545 ParserTestCase.parseCompilationUnit( | 2537 parseCompilationUnit( |
| 2546 "static enum E { v }", [ParserErrorCode.STATIC_TOP_LEVEL_DECLARATION]); | 2538 "static enum E { v }", [ParserErrorCode.STATIC_TOP_LEVEL_DECLARATION]); |
| 2547 } | 2539 } |
| 2548 | 2540 |
| 2549 void test_staticTopLevelDeclaration_function() { | 2541 void test_staticTopLevelDeclaration_function() { |
| 2550 ParserTestCase.parseCompilationUnit( | 2542 parseCompilationUnit( |
| 2551 "static f() {}", [ParserErrorCode.STATIC_TOP_LEVEL_DECLARATION]); | 2543 "static f() {}", [ParserErrorCode.STATIC_TOP_LEVEL_DECLARATION]); |
| 2552 } | 2544 } |
| 2553 | 2545 |
| 2554 void test_staticTopLevelDeclaration_typedef() { | 2546 void test_staticTopLevelDeclaration_typedef() { |
| 2555 ParserTestCase.parseCompilationUnit( | 2547 parseCompilationUnit( |
| 2556 "static typedef F();", [ParserErrorCode.STATIC_TOP_LEVEL_DECLARATION]); | 2548 "static typedef F();", [ParserErrorCode.STATIC_TOP_LEVEL_DECLARATION]); |
| 2557 } | 2549 } |
| 2558 | 2550 |
| 2559 void test_staticTopLevelDeclaration_variable() { | 2551 void test_staticTopLevelDeclaration_variable() { |
| 2560 ParserTestCase.parseCompilationUnit( | 2552 parseCompilationUnit( |
| 2561 "static var x;", [ParserErrorCode.STATIC_TOP_LEVEL_DECLARATION]); | 2553 "static var x;", [ParserErrorCode.STATIC_TOP_LEVEL_DECLARATION]); |
| 2562 } | 2554 } |
| 2563 | 2555 |
| 2564 void test_string_unterminated_interpolation_block() { | 2556 void test_string_unterminated_interpolation_block() { |
| 2565 ParserTestCase.parseCompilationUnit( | 2557 parseCompilationUnit( |
| 2566 r''' | 2558 r''' |
| 2567 m() { | 2559 m() { |
| 2568 { | 2560 { |
| 2569 '${${ | 2561 '${${ |
| 2570 ''', | 2562 ''', |
| 2571 [ | 2563 [ |
| 2572 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, | 2564 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, |
| 2573 ParserErrorCode.EXPECTED_TOKEN, | 2565 ParserErrorCode.EXPECTED_TOKEN, |
| 2574 ParserErrorCode.EXPECTED_TOKEN, | 2566 ParserErrorCode.EXPECTED_TOKEN, |
| 2575 ParserErrorCode.EXPECTED_TOKEN, | 2567 ParserErrorCode.EXPECTED_TOKEN, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2646 | 2638 |
| 2647 void test_topLevelOperator_withVoid() { | 2639 void test_topLevelOperator_withVoid() { |
| 2648 createParser('void operator +(bool x, bool y) => x | y;'); | 2640 createParser('void operator +(bool x, bool y) => x | y;'); |
| 2649 CompilationUnitMember member = | 2641 CompilationUnitMember member = |
| 2650 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); | 2642 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 2651 expectNotNullIfNoErrors(member); | 2643 expectNotNullIfNoErrors(member); |
| 2652 listener.assertErrorsWithCodes([ParserErrorCode.TOP_LEVEL_OPERATOR]); | 2644 listener.assertErrorsWithCodes([ParserErrorCode.TOP_LEVEL_OPERATOR]); |
| 2653 } | 2645 } |
| 2654 | 2646 |
| 2655 void test_topLevelVariable_withMetadata() { | 2647 void test_topLevelVariable_withMetadata() { |
| 2656 ParserTestCase.parseCompilationUnit("String @A string;", [ | 2648 parseCompilationUnit("String @A string;", [ |
| 2657 ParserErrorCode.MISSING_IDENTIFIER, | 2649 ParserErrorCode.MISSING_IDENTIFIER, |
| 2658 ParserErrorCode.EXPECTED_TOKEN, | 2650 ParserErrorCode.EXPECTED_TOKEN, |
| 2659 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE | 2651 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE |
| 2660 ]); | 2652 ]); |
| 2661 } | 2653 } |
| 2662 | 2654 |
| 2663 void test_typedefInClass_withoutReturnType() { | 2655 void test_typedefInClass_withoutReturnType() { |
| 2664 ParserTestCase.parseCompilationUnit( | 2656 parseCompilationUnit( |
| 2665 "class C { typedef F(x); }", [ParserErrorCode.TYPEDEF_IN_CLASS]); | 2657 "class C { typedef F(x); }", [ParserErrorCode.TYPEDEF_IN_CLASS]); |
| 2666 } | 2658 } |
| 2667 | 2659 |
| 2668 void test_typedefInClass_withReturnType() { | 2660 void test_typedefInClass_withReturnType() { |
| 2669 ParserTestCase.parseCompilationUnit("class C { typedef int F(int x); }", | 2661 parseCompilationUnit("class C { typedef int F(int x); }", |
| 2670 [ParserErrorCode.TYPEDEF_IN_CLASS]); | 2662 [ParserErrorCode.TYPEDEF_IN_CLASS]); |
| 2671 } | 2663 } |
| 2672 | 2664 |
| 2673 void test_unexpectedTerminatorForParameterGroup_named() { | 2665 void test_unexpectedTerminatorForParameterGroup_named() { |
| 2674 createParser('(a, b})'); | 2666 createParser('(a, b})'); |
| 2675 FormalParameterList list = parser.parseFormalParameterList(); | 2667 FormalParameterList list = parser.parseFormalParameterList(); |
| 2676 expectNotNullIfNoErrors(list); | 2668 expectNotNullIfNoErrors(list); |
| 2677 listener.assertErrorsWithCodes( | 2669 listener.assertErrorsWithCodes( |
| 2678 [ParserErrorCode.UNEXPECTED_TERMINATOR_FOR_PARAMETER_GROUP]); | 2670 [ParserErrorCode.UNEXPECTED_TERMINATOR_FOR_PARAMETER_GROUP]); |
| 2679 } | 2671 } |
| 2680 | 2672 |
| 2681 void test_unexpectedTerminatorForParameterGroup_optional() { | 2673 void test_unexpectedTerminatorForParameterGroup_optional() { |
| 2682 createParser('(a, b])'); | 2674 createParser('(a, b])'); |
| 2683 FormalParameterList list = parser.parseFormalParameterList(); | 2675 FormalParameterList list = parser.parseFormalParameterList(); |
| 2684 expectNotNullIfNoErrors(list); | 2676 expectNotNullIfNoErrors(list); |
| 2685 listener.assertErrorsWithCodes( | 2677 listener.assertErrorsWithCodes( |
| 2686 [ParserErrorCode.UNEXPECTED_TERMINATOR_FOR_PARAMETER_GROUP]); | 2678 [ParserErrorCode.UNEXPECTED_TERMINATOR_FOR_PARAMETER_GROUP]); |
| 2687 } | 2679 } |
| 2688 | 2680 |
| 2689 void test_unexpectedToken_endOfFieldDeclarationStatement() { | 2681 void test_unexpectedToken_endOfFieldDeclarationStatement() { |
| 2690 ParserTestCase.parseStatement( | 2682 parseStatement("String s = (null));", [ParserErrorCode.UNEXPECTED_TOKEN]); |
| 2691 "String s = (null));", [ParserErrorCode.UNEXPECTED_TOKEN]); | |
| 2692 } | 2683 } |
| 2693 | 2684 |
| 2694 @failingTest | 2685 @failingTest |
| 2695 void test_unexpectedToken_invalidPostfixExpression() { | 2686 void test_unexpectedToken_invalidPostfixExpression() { |
| 2696 // Note: this might not be the right error to produce, but some error should | 2687 // Note: this might not be the right error to produce, but some error should |
| 2697 // be produced | 2688 // be produced |
| 2698 parseExpression("f()++", [ParserErrorCode.UNEXPECTED_TOKEN]); | 2689 parseExpression("f()++", [ParserErrorCode.UNEXPECTED_TOKEN]); |
| 2699 } | 2690 } |
| 2700 | 2691 |
| 2701 void test_unexpectedToken_returnInExpressionFuntionBody() { | 2692 void test_unexpectedToken_returnInExpressionFuntionBody() { |
| 2702 ParserTestCase.parseCompilationUnit( | 2693 parseCompilationUnit( |
| 2703 "f() => return null;", [ParserErrorCode.UNEXPECTED_TOKEN]); | 2694 "f() => return null;", [ParserErrorCode.UNEXPECTED_TOKEN]); |
| 2704 } | 2695 } |
| 2705 | 2696 |
| 2706 void test_unexpectedToken_semicolonBetweenClassMembers() { | 2697 void test_unexpectedToken_semicolonBetweenClassMembers() { |
| 2707 createParser('class C { int x; ; int y;}'); | 2698 createParser('class C { int x; ; int y;}'); |
| 2708 ClassDeclaration declaration = | 2699 ClassDeclaration declaration = |
| 2709 parser.parseClassDeclaration(emptyCommentAndMetadata(), null); | 2700 parser.parseClassDeclaration(emptyCommentAndMetadata(), null); |
| 2710 expectNotNullIfNoErrors(declaration); | 2701 expectNotNullIfNoErrors(declaration); |
| 2711 listener.assertErrorsWithCodes([ParserErrorCode.UNEXPECTED_TOKEN]); | 2702 listener.assertErrorsWithCodes([ParserErrorCode.UNEXPECTED_TOKEN]); |
| 2712 } | 2703 } |
| 2713 | 2704 |
| 2714 void test_unexpectedToken_semicolonBetweenCompilationUnitMembers() { | 2705 void test_unexpectedToken_semicolonBetweenCompilationUnitMembers() { |
| 2715 ParserTestCase.parseCompilationUnit( | 2706 parseCompilationUnit("int x; ; int y;", [ParserErrorCode.UNEXPECTED_TOKEN]); |
| 2716 "int x; ; int y;", [ParserErrorCode.UNEXPECTED_TOKEN]); | |
| 2717 } | 2707 } |
| 2718 | 2708 |
| 2719 void test_unterminatedString_at_eof() { | 2709 void test_unterminatedString_at_eof() { |
| 2720 // Although the "unterminated string" error message is produced by the | 2710 // Although the "unterminated string" error message is produced by the |
| 2721 // scanner, we need to verify that the parser can handle the tokens | 2711 // scanner, we need to verify that the parser can handle the tokens |
| 2722 // produced by the scanner when an unterminated string is encountered. | 2712 // produced by the scanner when an unterminated string is encountered. |
| 2723 ParserTestCase.parseCompilationUnit( | 2713 parseCompilationUnit( |
| 2724 r''' | 2714 r''' |
| 2725 void main() { | 2715 void main() { |
| 2726 var x = "''', | 2716 var x = "''', |
| 2727 [ | 2717 [ |
| 2728 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, | 2718 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, |
| 2729 ParserErrorCode.EXPECTED_TOKEN, | 2719 ParserErrorCode.EXPECTED_TOKEN, |
| 2730 ParserErrorCode.EXPECTED_TOKEN | 2720 ParserErrorCode.EXPECTED_TOKEN |
| 2731 ]); | 2721 ]); |
| 2732 } | 2722 } |
| 2733 | 2723 |
| 2734 void test_unterminatedString_at_eol() { | 2724 void test_unterminatedString_at_eol() { |
| 2735 // Although the "unterminated string" error message is produced by the | 2725 // Although the "unterminated string" error message is produced by the |
| 2736 // scanner, we need to verify that the parser can handle the tokens | 2726 // scanner, we need to verify that the parser can handle the tokens |
| 2737 // produced by the scanner when an unterminated string is encountered. | 2727 // produced by the scanner when an unterminated string is encountered. |
| 2738 ParserTestCase.parseCompilationUnit( | 2728 parseCompilationUnit( |
| 2739 r''' | 2729 r''' |
| 2740 void main() { | 2730 void main() { |
| 2741 var x = " | 2731 var x = " |
| 2742 ; | 2732 ; |
| 2743 } | 2733 } |
| 2744 ''', | 2734 ''', |
| 2745 [ScannerErrorCode.UNTERMINATED_STRING_LITERAL]); | 2735 [ScannerErrorCode.UNTERMINATED_STRING_LITERAL]); |
| 2746 } | 2736 } |
| 2747 | 2737 |
| 2748 void test_unterminatedString_multiline_at_eof_3_quotes() { | 2738 void test_unterminatedString_multiline_at_eof_3_quotes() { |
| 2749 // Although the "unterminated string" error message is produced by the | 2739 // Although the "unterminated string" error message is produced by the |
| 2750 // scanner, we need to verify that the parser can handle the tokens | 2740 // scanner, we need to verify that the parser can handle the tokens |
| 2751 // produced by the scanner when an unterminated string is encountered. | 2741 // produced by the scanner when an unterminated string is encountered. |
| 2752 ParserTestCase.parseCompilationUnit( | 2742 parseCompilationUnit( |
| 2753 r''' | 2743 r''' |
| 2754 void main() { | 2744 void main() { |
| 2755 var x = """''', | 2745 var x = """''', |
| 2756 [ | 2746 [ |
| 2757 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, | 2747 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, |
| 2758 ParserErrorCode.EXPECTED_TOKEN, | 2748 ParserErrorCode.EXPECTED_TOKEN, |
| 2759 ParserErrorCode.EXPECTED_TOKEN | 2749 ParserErrorCode.EXPECTED_TOKEN |
| 2760 ]); | 2750 ]); |
| 2761 } | 2751 } |
| 2762 | 2752 |
| 2763 void test_unterminatedString_multiline_at_eof_4_quotes() { | 2753 void test_unterminatedString_multiline_at_eof_4_quotes() { |
| 2764 // Although the "unterminated string" error message is produced by the | 2754 // Although the "unterminated string" error message is produced by the |
| 2765 // scanner, we need to verify that the parser can handle the tokens | 2755 // scanner, we need to verify that the parser can handle the tokens |
| 2766 // produced by the scanner when an unterminated string is encountered. | 2756 // produced by the scanner when an unterminated string is encountered. |
| 2767 ParserTestCase.parseCompilationUnit( | 2757 parseCompilationUnit( |
| 2768 r''' | 2758 r''' |
| 2769 void main() { | 2759 void main() { |
| 2770 var x = """"''', | 2760 var x = """"''', |
| 2771 [ | 2761 [ |
| 2772 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, | 2762 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, |
| 2773 ParserErrorCode.EXPECTED_TOKEN, | 2763 ParserErrorCode.EXPECTED_TOKEN, |
| 2774 ParserErrorCode.EXPECTED_TOKEN | 2764 ParserErrorCode.EXPECTED_TOKEN |
| 2775 ]); | 2765 ]); |
| 2776 } | 2766 } |
| 2777 | 2767 |
| 2778 void test_unterminatedString_multiline_at_eof_5_quotes() { | 2768 void test_unterminatedString_multiline_at_eof_5_quotes() { |
| 2779 // Although the "unterminated string" error message is produced by the | 2769 // Although the "unterminated string" error message is produced by the |
| 2780 // scanner, we need to verify that the parser can handle the tokens | 2770 // scanner, we need to verify that the parser can handle the tokens |
| 2781 // produced by the scanner when an unterminated string is encountered. | 2771 // produced by the scanner when an unterminated string is encountered. |
| 2782 ParserTestCase.parseCompilationUnit( | 2772 parseCompilationUnit( |
| 2783 r''' | 2773 r''' |
| 2784 void main() { | 2774 void main() { |
| 2785 var x = """""''', | 2775 var x = """""''', |
| 2786 [ | 2776 [ |
| 2787 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, | 2777 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, |
| 2788 ParserErrorCode.EXPECTED_TOKEN, | 2778 ParserErrorCode.EXPECTED_TOKEN, |
| 2789 ParserErrorCode.EXPECTED_TOKEN | 2779 ParserErrorCode.EXPECTED_TOKEN |
| 2790 ]); | 2780 ]); |
| 2791 } | 2781 } |
| 2792 | 2782 |
| 2793 void test_useOfUnaryPlusOperator() { | 2783 void test_useOfUnaryPlusOperator() { |
| 2794 createParser('+x'); | 2784 createParser('+x'); |
| 2795 Expression expression = parser.parseUnaryExpression(); | 2785 Expression expression = parser.parseUnaryExpression(); |
| 2796 expectNotNullIfNoErrors(expression); | 2786 expectNotNullIfNoErrors(expression); |
| 2797 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); | 2787 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| 2798 expect(expression, new isInstanceOf<SimpleIdentifier>()); | 2788 expect(expression, new isInstanceOf<SimpleIdentifier>()); |
| 2799 SimpleIdentifier identifier = expression; | 2789 SimpleIdentifier identifier = expression; |
| 2800 expect(identifier.isSynthetic, isTrue); | 2790 expect(identifier.isSynthetic, isTrue); |
| 2801 } | 2791 } |
| 2802 | 2792 |
| 2803 void test_varAndType_field() { | 2793 void test_varAndType_field() { |
| 2804 ParserTestCase.parseCompilationUnit( | 2794 parseCompilationUnit( |
| 2805 "class C { var int x; }", [ParserErrorCode.VAR_AND_TYPE]); | 2795 "class C { var int x; }", [ParserErrorCode.VAR_AND_TYPE]); |
| 2806 } | 2796 } |
| 2807 | 2797 |
| 2808 @failingTest | 2798 @failingTest |
| 2809 void test_varAndType_local() { | 2799 void test_varAndType_local() { |
| 2810 // This is currently reporting EXPECTED_TOKEN for a missing semicolon, but | 2800 // This is currently reporting EXPECTED_TOKEN for a missing semicolon, but |
| 2811 // this would be a better error message. | 2801 // this would be a better error message. |
| 2812 ParserTestCase.parseStatement("var int x;", [ParserErrorCode.VAR_AND_TYPE]); | 2802 parseStatement("var int x;", [ParserErrorCode.VAR_AND_TYPE]); |
| 2813 } | 2803 } |
| 2814 | 2804 |
| 2815 @failingTest | 2805 @failingTest |
| 2816 void test_varAndType_parameter() { | 2806 void test_varAndType_parameter() { |
| 2817 // This is currently reporting EXPECTED_TOKEN for a missing semicolon, but | 2807 // This is currently reporting EXPECTED_TOKEN for a missing semicolon, but |
| 2818 // this would be a better error message. | 2808 // this would be a better error message. |
| 2819 createParser('(var int x)'); | 2809 createParser('(var int x)'); |
| 2820 FormalParameterList list = parser.parseFormalParameterList(); | 2810 FormalParameterList list = parser.parseFormalParameterList(); |
| 2821 expectNotNullIfNoErrors(list); | 2811 expectNotNullIfNoErrors(list); |
| 2822 listener.assertErrorsWithCodes([ParserErrorCode.VAR_AND_TYPE]); | 2812 listener.assertErrorsWithCodes([ParserErrorCode.VAR_AND_TYPE]); |
| 2823 } | 2813 } |
| 2824 | 2814 |
| 2825 void test_varAndType_topLevelVariable() { | 2815 void test_varAndType_topLevelVariable() { |
| 2826 ParserTestCase | 2816 parseCompilationUnit("var int x;", [ParserErrorCode.VAR_AND_TYPE]); |
| 2827 .parseCompilationUnit("var int x;", [ParserErrorCode.VAR_AND_TYPE]); | |
| 2828 } | 2817 } |
| 2829 | 2818 |
| 2830 void test_varAsTypeName_as() { | 2819 void test_varAsTypeName_as() { |
| 2831 parseExpression("x as var", [ParserErrorCode.VAR_AS_TYPE_NAME]); | 2820 parseExpression("x as var", [ParserErrorCode.VAR_AS_TYPE_NAME]); |
| 2832 } | 2821 } |
| 2833 | 2822 |
| 2834 void test_varClass() { | 2823 void test_varClass() { |
| 2835 ParserTestCase | 2824 parseCompilationUnit("var class C {}", [ParserErrorCode.VAR_CLASS]); |
| 2836 .parseCompilationUnit("var class C {}", [ParserErrorCode.VAR_CLASS]); | |
| 2837 } | 2825 } |
| 2838 | 2826 |
| 2839 void test_varEnum() { | 2827 void test_varEnum() { |
| 2840 ParserTestCase | 2828 parseCompilationUnit("var enum E {ONE}", [ParserErrorCode.VAR_ENUM]); |
| 2841 .parseCompilationUnit("var enum E {ONE}", [ParserErrorCode.VAR_ENUM]); | |
| 2842 } | 2829 } |
| 2843 | 2830 |
| 2844 void test_varReturnType() { | 2831 void test_varReturnType() { |
| 2845 createParser('var m() {}'); | 2832 createParser('var m() {}'); |
| 2846 ClassMember member = parser.parseClassMember('C'); | 2833 ClassMember member = parser.parseClassMember('C'); |
| 2847 expectNotNullIfNoErrors(member); | 2834 expectNotNullIfNoErrors(member); |
| 2848 listener.assertErrorsWithCodes([ParserErrorCode.VAR_RETURN_TYPE]); | 2835 listener.assertErrorsWithCodes([ParserErrorCode.VAR_RETURN_TYPE]); |
| 2849 } | 2836 } |
| 2850 | 2837 |
| 2851 void test_varTypedef() { | 2838 void test_varTypedef() { |
| 2852 ParserTestCase.parseCompilationUnit( | 2839 parseCompilationUnit("var typedef F();", [ParserErrorCode.VAR_TYPEDEF]); |
| 2853 "var typedef F();", [ParserErrorCode.VAR_TYPEDEF]); | |
| 2854 } | 2840 } |
| 2855 | 2841 |
| 2856 void test_voidParameter() { | 2842 void test_voidParameter() { |
| 2857 createParser('void a)'); | 2843 createParser('void a)'); |
| 2858 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); | 2844 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); |
| 2859 expectNotNullIfNoErrors(parameter); | 2845 expectNotNullIfNoErrors(parameter); |
| 2860 listener.assertErrorsWithCodes([ParserErrorCode.VOID_PARAMETER]); | 2846 listener.assertErrorsWithCodes([ParserErrorCode.VOID_PARAMETER]); |
| 2861 } | 2847 } |
| 2862 | 2848 |
| 2863 void test_voidVariable_parseClassMember_initializer() { | 2849 void test_voidVariable_parseClassMember_initializer() { |
| 2864 createParser('void x = 0;'); | 2850 createParser('void x = 0;'); |
| 2865 ClassMember member = parser.parseClassMember('C'); | 2851 ClassMember member = parser.parseClassMember('C'); |
| 2866 expectNotNullIfNoErrors(member); | 2852 expectNotNullIfNoErrors(member); |
| 2867 listener.assertErrorsWithCodes([ParserErrorCode.VOID_VARIABLE]); | 2853 listener.assertErrorsWithCodes([ParserErrorCode.VOID_VARIABLE]); |
| 2868 } | 2854 } |
| 2869 | 2855 |
| 2870 void test_voidVariable_parseClassMember_noInitializer() { | 2856 void test_voidVariable_parseClassMember_noInitializer() { |
| 2871 createParser('void x;'); | 2857 createParser('void x;'); |
| 2872 ClassMember member = parser.parseClassMember('C'); | 2858 ClassMember member = parser.parseClassMember('C'); |
| 2873 expectNotNullIfNoErrors(member); | 2859 expectNotNullIfNoErrors(member); |
| 2874 listener.assertErrorsWithCodes([ParserErrorCode.VOID_VARIABLE]); | 2860 listener.assertErrorsWithCodes([ParserErrorCode.VOID_VARIABLE]); |
| 2875 } | 2861 } |
| 2876 | 2862 |
| 2877 void test_voidVariable_parseCompilationUnit_initializer() { | 2863 void test_voidVariable_parseCompilationUnit_initializer() { |
| 2878 ParserTestCase | 2864 parseCompilationUnit("void x = 0;", [ParserErrorCode.VOID_VARIABLE]); |
| 2879 .parseCompilationUnit("void x = 0;", [ParserErrorCode.VOID_VARIABLE]); | |
| 2880 } | 2865 } |
| 2881 | 2866 |
| 2882 void test_voidVariable_parseCompilationUnit_noInitializer() { | 2867 void test_voidVariable_parseCompilationUnit_noInitializer() { |
| 2883 ParserTestCase | 2868 parseCompilationUnit("void x;", [ParserErrorCode.VOID_VARIABLE]); |
| 2884 .parseCompilationUnit("void x;", [ParserErrorCode.VOID_VARIABLE]); | |
| 2885 } | 2869 } |
| 2886 | 2870 |
| 2887 void test_voidVariable_parseCompilationUnitMember_initializer() { | 2871 void test_voidVariable_parseCompilationUnitMember_initializer() { |
| 2888 createParser('void a = 0;'); | 2872 createParser('void a = 0;'); |
| 2889 CompilationUnitMember member = | 2873 CompilationUnitMember member = |
| 2890 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); | 2874 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 2891 expectNotNullIfNoErrors(member); | 2875 expectNotNullIfNoErrors(member); |
| 2892 listener.assertErrorsWithCodes([ParserErrorCode.VOID_VARIABLE]); | 2876 listener.assertErrorsWithCodes([ParserErrorCode.VOID_VARIABLE]); |
| 2893 } | 2877 } |
| 2894 | 2878 |
| 2895 void test_voidVariable_parseCompilationUnitMember_noInitializer() { | 2879 void test_voidVariable_parseCompilationUnitMember_noInitializer() { |
| 2896 createParser('void a;'); | 2880 createParser('void a;'); |
| 2897 CompilationUnitMember member = | 2881 CompilationUnitMember member = |
| 2898 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); | 2882 parser.parseCompilationUnitMember(emptyCommentAndMetadata()); |
| 2899 expectNotNullIfNoErrors(member); | 2883 expectNotNullIfNoErrors(member); |
| 2900 listener.assertErrorsWithCodes([ParserErrorCode.VOID_VARIABLE]); | 2884 listener.assertErrorsWithCodes([ParserErrorCode.VOID_VARIABLE]); |
| 2901 } | 2885 } |
| 2902 | 2886 |
| 2903 void test_voidVariable_statement_initializer() { | 2887 void test_voidVariable_statement_initializer() { |
| 2904 ParserTestCase.parseStatement("void x = 0;", [ | 2888 parseStatement("void x = 0;", [ |
| 2905 ParserErrorCode.VOID_VARIABLE, | 2889 ParserErrorCode.VOID_VARIABLE, |
| 2906 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE | 2890 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE |
| 2907 ]); | 2891 ]); |
| 2908 } | 2892 } |
| 2909 | 2893 |
| 2910 void test_voidVariable_statement_noInitializer() { | 2894 void test_voidVariable_statement_noInitializer() { |
| 2911 ParserTestCase.parseStatement("void x;", [ | 2895 parseStatement("void x;", [ |
| 2912 ParserErrorCode.VOID_VARIABLE, | 2896 ParserErrorCode.VOID_VARIABLE, |
| 2913 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE | 2897 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE |
| 2914 ]); | 2898 ]); |
| 2915 } | 2899 } |
| 2916 | 2900 |
| 2917 void test_withBeforeExtends() { | 2901 void test_withBeforeExtends() { |
| 2918 ParserTestCase.parseCompilationUnit( | 2902 parseCompilationUnit( |
| 2919 "class A with B extends C {}", [ParserErrorCode.WITH_BEFORE_EXTENDS]); | 2903 "class A with B extends C {}", [ParserErrorCode.WITH_BEFORE_EXTENDS]); |
| 2920 } | 2904 } |
| 2921 | 2905 |
| 2922 void test_withWithoutExtends() { | 2906 void test_withWithoutExtends() { |
| 2923 createParser('class A with B, C {}'); | 2907 createParser('class A with B, C {}'); |
| 2924 ClassDeclaration declaration = | 2908 ClassDeclaration declaration = |
| 2925 parser.parseClassDeclaration(emptyCommentAndMetadata(), null); | 2909 parser.parseClassDeclaration(emptyCommentAndMetadata(), null); |
| 2926 expectNotNullIfNoErrors(declaration); | 2910 expectNotNullIfNoErrors(declaration); |
| 2927 listener.assertErrorsWithCodes([ParserErrorCode.WITH_WITHOUT_EXTENDS]); | 2911 listener.assertErrorsWithCodes([ParserErrorCode.WITH_WITHOUT_EXTENDS]); |
| 2928 } | 2912 } |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3080 CommentAndMetadata emptyCommentAndMetadata() => | 3064 CommentAndMetadata emptyCommentAndMetadata() => |
| 3081 new CommentAndMetadata(null, null); | 3065 new CommentAndMetadata(null, null); |
| 3082 | 3066 |
| 3083 void expectNotNullIfNoErrors(Object result) { | 3067 void expectNotNullIfNoErrors(Object result) { |
| 3084 if (!listener.hasErrors) { | 3068 if (!listener.hasErrors) { |
| 3085 expect(result, isNotNull); | 3069 expect(result, isNotNull); |
| 3086 } | 3070 } |
| 3087 } | 3071 } |
| 3088 | 3072 |
| 3089 /** | 3073 /** |
| 3090 * Parse the given [source] as a compilation unit. Throw an exception if the | |
| 3091 * source could not be parsed, if the compilation errors in the source do not | |
| 3092 * match those that are expected, or if the result would have been `null`. | |
| 3093 */ | |
| 3094 CompilationUnit parseCompilationUnitWithOptions(String source, | |
| 3095 [List<ErrorCode> errorCodes = const <ErrorCode>[]]) { | |
| 3096 createParser(source); | |
| 3097 CompilationUnit unit = parser.parseCompilationUnit2(); | |
| 3098 expect(unit, isNotNull); | |
| 3099 listener.assertErrorsWithCodes(errorCodes); | |
| 3100 return unit; | |
| 3101 } | |
| 3102 | |
| 3103 /** | |
| 3104 * Parse the given source as an expression. | |
| 3105 * | |
| 3106 * @param source the source to be parsed | |
| 3107 * @param errorCodes the error codes of the errors that are expected to be fou
nd | |
| 3108 * @return the expression that was parsed | |
| 3109 * @throws Exception if the source could not be parsed, if the compilation err
ors in the source do | |
| 3110 * not match those that are expected, or if the result would have be
en `null` | |
| 3111 */ | |
| 3112 Expression parseExpression(String source, | |
| 3113 [List<ErrorCode> errorCodes = const <ErrorCode>[]]) { | |
| 3114 createParser(source); | |
| 3115 Expression expression = parser.parseExpression2(); | |
| 3116 expectNotNullIfNoErrors(expression); | |
| 3117 listener.assertErrorsWithCodes(errorCodes); | |
| 3118 return expression; | |
| 3119 } | |
| 3120 | |
| 3121 @override | |
| 3122 void setUp() { | |
| 3123 super.setUp(); | |
| 3124 parseFunctionBodies = true; | |
| 3125 } | |
| 3126 | |
| 3127 /** | |
| 3128 * Parse the given source as a compilation unit. | 3074 * Parse the given source as a compilation unit. |
| 3129 * | 3075 * |
| 3130 * @param source the source to be parsed | 3076 * @param source the source to be parsed |
| 3131 * @param errorCodes the error codes of the errors that are expected to be fou
nd | 3077 * @param errorCodes the error codes of the errors that are expected to be fou
nd |
| 3132 * @return the compilation unit that was parsed | 3078 * @return the compilation unit that was parsed |
| 3133 * @throws Exception if the source could not be parsed, if the compilation err
ors in the source do | 3079 * @throws Exception if the source could not be parsed, if the compilation err
ors in the source do |
| 3134 * not match those that are expected, or if the result would have be
en `null` | 3080 * not match those that are expected, or if the result would have be
en `null` |
| 3135 */ | 3081 */ |
| 3136 static CompilationUnit parseCompilationUnit(String source, | 3082 CompilationUnit parseCompilationUnit(String source, |
| 3137 [List<ErrorCode> errorCodes = const <ErrorCode>[]]) { | 3083 [List<ErrorCode> errorCodes = const <ErrorCode>[]]) { |
| 3138 GatheringErrorListener listener = new GatheringErrorListener(); | 3084 GatheringErrorListener listener = new GatheringErrorListener(); |
| 3139 Scanner scanner = | 3085 Scanner scanner = |
| 3140 new Scanner(null, new CharSequenceReader(source), listener); | 3086 new Scanner(null, new CharSequenceReader(source), listener); |
| 3141 listener.setLineInfo(new TestSource(), scanner.lineStarts); | 3087 listener.setLineInfo(new TestSource(), scanner.lineStarts); |
| 3142 Token token = scanner.tokenize(); | 3088 Token token = scanner.tokenize(); |
| 3143 Parser parser = new Parser(null, listener); | 3089 Parser parser = new Parser(null, listener); |
| 3144 CompilationUnit unit = parser.parseCompilationUnit(token); | 3090 CompilationUnit unit = parser.parseCompilationUnit(token); |
| 3145 expect(unit, isNotNull); | 3091 expect(unit, isNotNull); |
| 3146 listener.assertErrorsWithCodes(errorCodes); | 3092 listener.assertErrorsWithCodes(errorCodes); |
| 3147 return unit; | 3093 return unit; |
| 3148 } | 3094 } |
| 3149 | 3095 |
| 3150 /** | 3096 /** |
| 3151 * Parse the given [code] as a compilation unit. | 3097 * Parse the given [code] as a compilation unit. |
| 3152 */ | 3098 */ |
| 3153 static CompilationUnit parseCompilationUnit2(String code, | 3099 CompilationUnit parseCompilationUnit2(String code, |
| 3154 {AnalysisErrorListener listener}) { | 3100 {AnalysisErrorListener listener}) { |
| 3155 listener ??= AnalysisErrorListener.NULL_LISTENER; | 3101 listener ??= AnalysisErrorListener.NULL_LISTENER; |
| 3156 Scanner scanner = new Scanner(null, new CharSequenceReader(code), listener); | 3102 Scanner scanner = new Scanner(null, new CharSequenceReader(code), listener); |
| 3157 Token token = scanner.tokenize(); | 3103 Token token = scanner.tokenize(); |
| 3158 Parser parser = new Parser(null, listener); | 3104 Parser parser = new Parser(null, listener); |
| 3159 CompilationUnit unit = parser.parseCompilationUnit(token); | 3105 CompilationUnit unit = parser.parseCompilationUnit(token); |
| 3160 unit.lineInfo = new LineInfo(scanner.lineStarts); | 3106 unit.lineInfo = new LineInfo(scanner.lineStarts); |
| 3161 return unit; | 3107 return unit; |
| 3162 } | 3108 } |
| 3163 | 3109 |
| 3164 /** | 3110 /** |
| 3111 * Parse the given [source] as a compilation unit. Throw an exception if the |
| 3112 * source could not be parsed, if the compilation errors in the source do not |
| 3113 * match those that are expected, or if the result would have been `null`. |
| 3114 */ |
| 3115 CompilationUnit parseCompilationUnitWithOptions(String source, |
| 3116 [List<ErrorCode> errorCodes = const <ErrorCode>[]]) { |
| 3117 createParser(source); |
| 3118 CompilationUnit unit = parser.parseCompilationUnit2(); |
| 3119 expect(unit, isNotNull); |
| 3120 listener.assertErrorsWithCodes(errorCodes); |
| 3121 return unit; |
| 3122 } |
| 3123 |
| 3124 /** |
| 3125 * Parse the given source as an expression. |
| 3126 * |
| 3127 * @param source the source to be parsed |
| 3128 * @param errorCodes the error codes of the errors that are expected to be fou
nd |
| 3129 * @return the expression that was parsed |
| 3130 * @throws Exception if the source could not be parsed, if the compilation err
ors in the source do |
| 3131 * not match those that are expected, or if the result would have be
en `null` |
| 3132 */ |
| 3133 Expression parseExpression(String source, |
| 3134 [List<ErrorCode> errorCodes = const <ErrorCode>[]]) { |
| 3135 createParser(source); |
| 3136 Expression expression = parser.parseExpression2(); |
| 3137 expectNotNullIfNoErrors(expression); |
| 3138 listener.assertErrorsWithCodes(errorCodes); |
| 3139 return expression; |
| 3140 } |
| 3141 |
| 3142 /** |
| 3165 * Parse the given [source] as a statement. The [errorCodes] are the error | 3143 * Parse the given [source] as a statement. The [errorCodes] are the error |
| 3166 * codes of the errors that are expected to be found. If | 3144 * codes of the errors that are expected to be found. If |
| 3167 * [enableLazyAssignmentOperators] is `true`, then lazy assignment operators | 3145 * [enableLazyAssignmentOperators] is `true`, then lazy assignment operators |
| 3168 * should be enabled. | 3146 * should be enabled. |
| 3169 */ | 3147 */ |
| 3170 static Statement parseStatement(String source, | 3148 Statement parseStatement(String source, |
| 3171 [List<ErrorCode> errorCodes = const <ErrorCode>[], | 3149 [List<ErrorCode> errorCodes = const <ErrorCode>[], |
| 3172 bool enableLazyAssignmentOperators]) { | 3150 bool enableLazyAssignmentOperators]) { |
| 3173 GatheringErrorListener listener = new GatheringErrorListener(); | 3151 GatheringErrorListener listener = new GatheringErrorListener(); |
| 3174 Scanner scanner = | 3152 Scanner scanner = |
| 3175 new Scanner(null, new CharSequenceReader(source), listener); | 3153 new Scanner(null, new CharSequenceReader(source), listener); |
| 3176 scanner.scanLazyAssignmentOperators = enableLazyAssignmentOperators; | 3154 scanner.scanLazyAssignmentOperators = enableLazyAssignmentOperators; |
| 3177 listener.setLineInfo(new TestSource(), scanner.lineStarts); | 3155 listener.setLineInfo(new TestSource(), scanner.lineStarts); |
| 3178 Token token = scanner.tokenize(); | 3156 Token token = scanner.tokenize(); |
| 3179 Parser parser = new Parser(null, listener); | 3157 Parser parser = new Parser(null, listener); |
| 3180 Statement statement = parser.parseStatement(token); | 3158 Statement statement = parser.parseStatement(token); |
| 3181 expect(statement, isNotNull); | 3159 expect(statement, isNotNull); |
| 3182 listener.assertErrorsWithCodes(errorCodes); | 3160 listener.assertErrorsWithCodes(errorCodes); |
| 3183 return statement; | 3161 return statement; |
| 3184 } | 3162 } |
| 3185 | 3163 |
| 3186 /** | 3164 /** |
| 3187 * Parse the given source as a sequence of statements. | 3165 * Parse the given source as a sequence of statements. |
| 3188 * | 3166 * |
| 3189 * @param source the source to be parsed | 3167 * @param source the source to be parsed |
| 3190 * @param expectedCount the number of statements that are expected | 3168 * @param expectedCount the number of statements that are expected |
| 3191 * @param errorCodes the error codes of the errors that are expected to be fou
nd | 3169 * @param errorCodes the error codes of the errors that are expected to be fou
nd |
| 3192 * @return the statements that were parsed | 3170 * @return the statements that were parsed |
| 3193 * @throws Exception if the source could not be parsed, if the number of state
ments does not match | 3171 * @throws Exception if the source could not be parsed, if the number of state
ments does not match |
| 3194 * the expected count, if the compilation errors in the source do no
t match those that | 3172 * the expected count, if the compilation errors in the source do no
t match those that |
| 3195 * are expected, or if the result would have been `null` | 3173 * are expected, or if the result would have been `null` |
| 3196 */ | 3174 */ |
| 3197 static List<Statement> parseStatements(String source, int expectedCount, | 3175 List<Statement> parseStatements(String source, int expectedCount, |
| 3198 [List<ErrorCode> errorCodes = const <ErrorCode>[]]) { | 3176 [List<ErrorCode> errorCodes = const <ErrorCode>[]]) { |
| 3199 GatheringErrorListener listener = new GatheringErrorListener(); | 3177 GatheringErrorListener listener = new GatheringErrorListener(); |
| 3200 Scanner scanner = | 3178 Scanner scanner = |
| 3201 new Scanner(null, new CharSequenceReader(source), listener); | 3179 new Scanner(null, new CharSequenceReader(source), listener); |
| 3202 listener.setLineInfo(new TestSource(), scanner.lineStarts); | 3180 listener.setLineInfo(new TestSource(), scanner.lineStarts); |
| 3203 Token token = scanner.tokenize(); | 3181 Token token = scanner.tokenize(); |
| 3204 Parser parser = new Parser(null, listener); | 3182 Parser parser = new Parser(null, listener); |
| 3205 List<Statement> statements = parser.parseStatements(token); | 3183 List<Statement> statements = parser.parseStatements(token); |
| 3206 expect(statements, hasLength(expectedCount)); | 3184 expect(statements, hasLength(expectedCount)); |
| 3207 listener.assertErrorsWithCodes(errorCodes); | 3185 listener.assertErrorsWithCodes(errorCodes); |
| 3208 return statements; | 3186 return statements; |
| 3209 } | 3187 } |
| 3188 |
| 3189 @override |
| 3190 void setUp() { |
| 3191 super.setUp(); |
| 3192 parseFunctionBodies = true; |
| 3193 } |
| 3210 } | 3194 } |
| 3211 | 3195 |
| 3212 /** | 3196 /** |
| 3213 * The class `RecoveryParserTest` defines parser tests that test the parsing of
invalid code | 3197 * The class `RecoveryParserTest` defines parser tests that test the parsing of
invalid code |
| 3214 * sequences to ensure that the correct recovery steps are taken in the parser. | 3198 * sequences to ensure that the correct recovery steps are taken in the parser. |
| 3215 */ | 3199 */ |
| 3216 @reflectiveTest | 3200 @reflectiveTest |
| 3217 class RecoveryParserTest extends ParserTestCase { | 3201 class RecoveryParserTest extends ParserTestCase { |
| 3218 void test_additiveExpression_missing_LHS() { | 3202 void test_additiveExpression_missing_LHS() { |
| 3219 BinaryExpression expression = | 3203 BinaryExpression expression = |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3526 void test_bitwiseXorExpression_super() { | 3510 void test_bitwiseXorExpression_super() { |
| 3527 BinaryExpression expression = parseExpression("super ^ ^", [ | 3511 BinaryExpression expression = parseExpression("super ^ ^", [ |
| 3528 ParserErrorCode.MISSING_IDENTIFIER, | 3512 ParserErrorCode.MISSING_IDENTIFIER, |
| 3529 ParserErrorCode.MISSING_IDENTIFIER | 3513 ParserErrorCode.MISSING_IDENTIFIER |
| 3530 ]); | 3514 ]); |
| 3531 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, | 3515 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| 3532 BinaryExpression, expression.leftOperand); | 3516 BinaryExpression, expression.leftOperand); |
| 3533 } | 3517 } |
| 3534 | 3518 |
| 3535 void test_classTypeAlias_withBody() { | 3519 void test_classTypeAlias_withBody() { |
| 3536 ParserTestCase.parseCompilationUnit( | 3520 parseCompilationUnit( |
| 3537 r''' | 3521 r''' |
| 3538 class A {} | 3522 class A {} |
| 3539 class B = Object with A {}''', | 3523 class B = Object with A {}''', |
| 3540 [ParserErrorCode.EXPECTED_TOKEN]); | 3524 [ParserErrorCode.EXPECTED_TOKEN]); |
| 3541 } | 3525 } |
| 3542 | 3526 |
| 3543 void test_conditionalExpression_missingElse() { | 3527 void test_conditionalExpression_missingElse() { |
| 3544 createParser('x ? y :'); | 3528 createParser('x ? y :'); |
| 3545 Expression expression = parser.parseConditionalExpression(); | 3529 Expression expression = parser.parseConditionalExpression(); |
| 3546 expectNotNullIfNoErrors(expression); | 3530 expectNotNullIfNoErrors(expression); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3558 expectNotNullIfNoErrors(expression); | 3542 expectNotNullIfNoErrors(expression); |
| 3559 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); | 3543 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| 3560 expect(expression, new isInstanceOf<ConditionalExpression>()); | 3544 expect(expression, new isInstanceOf<ConditionalExpression>()); |
| 3561 ConditionalExpression conditionalExpression = expression; | 3545 ConditionalExpression conditionalExpression = expression; |
| 3562 expect(conditionalExpression.thenExpression, | 3546 expect(conditionalExpression.thenExpression, |
| 3563 new isInstanceOf<SimpleIdentifier>()); | 3547 new isInstanceOf<SimpleIdentifier>()); |
| 3564 expect(conditionalExpression.thenExpression.isSynthetic, isTrue); | 3548 expect(conditionalExpression.thenExpression.isSynthetic, isTrue); |
| 3565 } | 3549 } |
| 3566 | 3550 |
| 3567 void test_declarationBeforeDirective() { | 3551 void test_declarationBeforeDirective() { |
| 3568 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 3552 CompilationUnit unit = parseCompilationUnit( |
| 3569 "class foo { } import 'bar.dart';", | 3553 "class foo { } import 'bar.dart';", |
| 3570 [ParserErrorCode.DIRECTIVE_AFTER_DECLARATION]); | 3554 [ParserErrorCode.DIRECTIVE_AFTER_DECLARATION]); |
| 3571 expect(unit.directives, hasLength(1)); | 3555 expect(unit.directives, hasLength(1)); |
| 3572 expect(unit.declarations, hasLength(1)); | 3556 expect(unit.declarations, hasLength(1)); |
| 3573 ClassDeclaration classDecl = unit.childEntities.first; | 3557 ClassDeclaration classDecl = unit.childEntities.first; |
| 3574 expect(classDecl, isNotNull); | 3558 expect(classDecl, isNotNull); |
| 3575 expect(classDecl.name.name, 'foo'); | 3559 expect(classDecl.name.name, 'foo'); |
| 3576 } | 3560 } |
| 3577 | 3561 |
| 3578 void test_equalityExpression_missing_LHS() { | 3562 void test_equalityExpression_missing_LHS() { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3672 expectNotNullIfNoErrors(result); | 3656 expectNotNullIfNoErrors(result); |
| 3673 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); | 3657 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| 3674 expect(result, hasLength(4)); | 3658 expect(result, hasLength(4)); |
| 3675 Expression syntheticExpression = result[3]; | 3659 Expression syntheticExpression = result[3]; |
| 3676 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, | 3660 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| 3677 SimpleIdentifier, syntheticExpression); | 3661 SimpleIdentifier, syntheticExpression); |
| 3678 expect(syntheticExpression.isSynthetic, isTrue); | 3662 expect(syntheticExpression.isSynthetic, isTrue); |
| 3679 } | 3663 } |
| 3680 | 3664 |
| 3681 void test_functionExpression_in_ConstructorFieldInitializer() { | 3665 void test_functionExpression_in_ConstructorFieldInitializer() { |
| 3682 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 3666 CompilationUnit unit = parseCompilationUnit( |
| 3683 "class A { A() : a = (){}; var v; }", | 3667 "class A { A() : a = (){}; var v; }", |
| 3684 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.UNEXPECTED_TOKEN]); | 3668 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.UNEXPECTED_TOKEN]); |
| 3685 // Make sure we recovered and parsed "var v" correctly | 3669 // Make sure we recovered and parsed "var v" correctly |
| 3686 ClassDeclaration declaration = unit.declarations[0] as ClassDeclaration; | 3670 ClassDeclaration declaration = unit.declarations[0] as ClassDeclaration; |
| 3687 NodeList<ClassMember> members = declaration.members; | 3671 NodeList<ClassMember> members = declaration.members; |
| 3688 ClassMember fieldDecl = members[1]; | 3672 ClassMember fieldDecl = members[1]; |
| 3689 EngineTestCase.assertInstanceOf( | 3673 EngineTestCase.assertInstanceOf( |
| 3690 (obj) => obj is FieldDeclaration, FieldDeclaration, fieldDecl); | 3674 (obj) => obj is FieldDeclaration, FieldDeclaration, fieldDecl); |
| 3691 NodeList<VariableDeclaration> vars = | 3675 NodeList<VariableDeclaration> vars = |
| 3692 (fieldDecl as FieldDeclaration).fields.variables; | 3676 (fieldDecl as FieldDeclaration).fields.variables; |
| 3693 expect(vars, hasLength(1)); | 3677 expect(vars, hasLength(1)); |
| 3694 expect(vars[0].name.name, "v"); | 3678 expect(vars[0].name.name, "v"); |
| 3695 } | 3679 } |
| 3696 | 3680 |
| 3697 void test_functionExpression_named() { | 3681 void test_functionExpression_named() { |
| 3698 parseExpression("m(f() => 0);", [ParserErrorCode.EXPECTED_TOKEN]); | 3682 parseExpression("m(f() => 0);", [ParserErrorCode.EXPECTED_TOKEN]); |
| 3699 } | 3683 } |
| 3700 | 3684 |
| 3701 void test_importDirectivePartial_as() { | 3685 void test_importDirectivePartial_as() { |
| 3702 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 3686 CompilationUnit unit = parseCompilationUnit( |
| 3703 "import 'b.dart' d as b;", [ParserErrorCode.UNEXPECTED_TOKEN]); | 3687 "import 'b.dart' d as b;", [ParserErrorCode.UNEXPECTED_TOKEN]); |
| 3704 ImportDirective importDirective = unit.childEntities.first; | 3688 ImportDirective importDirective = unit.childEntities.first; |
| 3705 expect(importDirective.asKeyword, isNotNull); | 3689 expect(importDirective.asKeyword, isNotNull); |
| 3706 expect(unit.directives, hasLength(1)); | 3690 expect(unit.directives, hasLength(1)); |
| 3707 expect(unit.declarations, hasLength(0)); | 3691 expect(unit.declarations, hasLength(0)); |
| 3708 } | 3692 } |
| 3709 | 3693 |
| 3710 void test_importDirectivePartial_hide() { | 3694 void test_importDirectivePartial_hide() { |
| 3711 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 3695 CompilationUnit unit = parseCompilationUnit( |
| 3712 "import 'b.dart' d hide foo;", [ParserErrorCode.UNEXPECTED_TOKEN]); | 3696 "import 'b.dart' d hide foo;", [ParserErrorCode.UNEXPECTED_TOKEN]); |
| 3713 ImportDirective importDirective = unit.childEntities.first; | 3697 ImportDirective importDirective = unit.childEntities.first; |
| 3714 expect(importDirective.combinators, hasLength(1)); | 3698 expect(importDirective.combinators, hasLength(1)); |
| 3715 expect(unit.directives, hasLength(1)); | 3699 expect(unit.directives, hasLength(1)); |
| 3716 expect(unit.declarations, hasLength(0)); | 3700 expect(unit.declarations, hasLength(0)); |
| 3717 } | 3701 } |
| 3718 | 3702 |
| 3719 void test_importDirectivePartial_show() { | 3703 void test_importDirectivePartial_show() { |
| 3720 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 3704 CompilationUnit unit = parseCompilationUnit( |
| 3721 "import 'b.dart' d show foo;", [ParserErrorCode.UNEXPECTED_TOKEN]); | 3705 "import 'b.dart' d show foo;", [ParserErrorCode.UNEXPECTED_TOKEN]); |
| 3722 ImportDirective importDirective = unit.childEntities.first; | 3706 ImportDirective importDirective = unit.childEntities.first; |
| 3723 expect(importDirective.combinators, hasLength(1)); | 3707 expect(importDirective.combinators, hasLength(1)); |
| 3724 expect(unit.directives, hasLength(1)); | 3708 expect(unit.directives, hasLength(1)); |
| 3725 expect(unit.declarations, hasLength(0)); | 3709 expect(unit.declarations, hasLength(0)); |
| 3726 } | 3710 } |
| 3727 | 3711 |
| 3728 void test_incomplete_conditionalExpression() { | 3712 void test_incomplete_conditionalExpression() { |
| 3729 parseExpression("x ? 0", | 3713 parseExpression("x ? 0", |
| 3730 [ParserErrorCode.EXPECTED_TOKEN, ParserErrorCode.MISSING_IDENTIFIER]); | 3714 [ParserErrorCode.EXPECTED_TOKEN, ParserErrorCode.MISSING_IDENTIFIER]); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 3758 void test_incomplete_constructorInitializers_variable() { | 3742 void test_incomplete_constructorInitializers_variable() { |
| 3759 createParser('C() : x {}'); | 3743 createParser('C() : x {}'); |
| 3760 ClassMember member = parser.parseClassMember('C'); | 3744 ClassMember member = parser.parseClassMember('C'); |
| 3761 expectNotNullIfNoErrors(member); | 3745 expectNotNullIfNoErrors(member); |
| 3762 listener.assertErrorsWithCodes( | 3746 listener.assertErrorsWithCodes( |
| 3763 [ParserErrorCode.MISSING_ASSIGNMENT_IN_INITIALIZER]); | 3747 [ParserErrorCode.MISSING_ASSIGNMENT_IN_INITIALIZER]); |
| 3764 } | 3748 } |
| 3765 | 3749 |
| 3766 @failingTest | 3750 @failingTest |
| 3767 void test_incomplete_returnType() { | 3751 void test_incomplete_returnType() { |
| 3768 ParserTestCase.parseCompilationUnit(r''' | 3752 parseCompilationUnit(r''' |
| 3769 Map<Symbol, convertStringToSymbolMap(Map<String, dynamic> map) { | 3753 Map<Symbol, convertStringToSymbolMap(Map<String, dynamic> map) { |
| 3770 if (map == null) return null; | 3754 if (map == null) return null; |
| 3771 Map<Symbol, dynamic> result = new Map<Symbol, dynamic>(); | 3755 Map<Symbol, dynamic> result = new Map<Symbol, dynamic>(); |
| 3772 map.forEach((name, value) { | 3756 map.forEach((name, value) { |
| 3773 result[new Symbol(name)] = value; | 3757 result[new Symbol(name)] = value; |
| 3774 }); | 3758 }); |
| 3775 return result; | 3759 return result; |
| 3776 }'''); | 3760 }'''); |
| 3777 } | 3761 } |
| 3778 | 3762 |
| 3779 void test_incomplete_topLevelFunction() { | 3763 void test_incomplete_topLevelFunction() { |
| 3780 ParserTestCase.parseCompilationUnit( | 3764 parseCompilationUnit("foo();", [ParserErrorCode.MISSING_FUNCTION_BODY]); |
| 3781 "foo();", [ParserErrorCode.MISSING_FUNCTION_BODY]); | |
| 3782 } | 3765 } |
| 3783 | 3766 |
| 3784 void test_incomplete_topLevelVariable() { | 3767 void test_incomplete_topLevelVariable() { |
| 3785 CompilationUnit unit = ParserTestCase | 3768 CompilationUnit unit = |
| 3786 .parseCompilationUnit("String", [ParserErrorCode.EXPECTED_EXECUTABLE]); | 3769 parseCompilationUnit("String", [ParserErrorCode.EXPECTED_EXECUTABLE]); |
| 3787 NodeList<CompilationUnitMember> declarations = unit.declarations; | 3770 NodeList<CompilationUnitMember> declarations = unit.declarations; |
| 3788 expect(declarations, hasLength(1)); | 3771 expect(declarations, hasLength(1)); |
| 3789 CompilationUnitMember member = declarations[0]; | 3772 CompilationUnitMember member = declarations[0]; |
| 3790 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableDeclaration, | 3773 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableDeclaration, |
| 3791 TopLevelVariableDeclaration, member); | 3774 TopLevelVariableDeclaration, member); |
| 3792 NodeList<VariableDeclaration> variables = | 3775 NodeList<VariableDeclaration> variables = |
| 3793 (member as TopLevelVariableDeclaration).variables.variables; | 3776 (member as TopLevelVariableDeclaration).variables.variables; |
| 3794 expect(variables, hasLength(1)); | 3777 expect(variables, hasLength(1)); |
| 3795 SimpleIdentifier name = variables[0].name; | 3778 SimpleIdentifier name = variables[0].name; |
| 3796 expect(name.isSynthetic, isTrue); | 3779 expect(name.isSynthetic, isTrue); |
| 3797 } | 3780 } |
| 3798 | 3781 |
| 3799 void test_incomplete_topLevelVariable_const() { | 3782 void test_incomplete_topLevelVariable_const() { |
| 3800 CompilationUnit unit = ParserTestCase.parseCompilationUnit("const ", | 3783 CompilationUnit unit = parseCompilationUnit("const ", |
| 3801 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); | 3784 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); |
| 3802 NodeList<CompilationUnitMember> declarations = unit.declarations; | 3785 NodeList<CompilationUnitMember> declarations = unit.declarations; |
| 3803 expect(declarations, hasLength(1)); | 3786 expect(declarations, hasLength(1)); |
| 3804 CompilationUnitMember member = declarations[0]; | 3787 CompilationUnitMember member = declarations[0]; |
| 3805 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableDeclaration, | 3788 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableDeclaration, |
| 3806 TopLevelVariableDeclaration, member); | 3789 TopLevelVariableDeclaration, member); |
| 3807 NodeList<VariableDeclaration> variables = | 3790 NodeList<VariableDeclaration> variables = |
| 3808 (member as TopLevelVariableDeclaration).variables.variables; | 3791 (member as TopLevelVariableDeclaration).variables.variables; |
| 3809 expect(variables, hasLength(1)); | 3792 expect(variables, hasLength(1)); |
| 3810 SimpleIdentifier name = variables[0].name; | 3793 SimpleIdentifier name = variables[0].name; |
| 3811 expect(name.isSynthetic, isTrue); | 3794 expect(name.isSynthetic, isTrue); |
| 3812 } | 3795 } |
| 3813 | 3796 |
| 3814 void test_incomplete_topLevelVariable_final() { | 3797 void test_incomplete_topLevelVariable_final() { |
| 3815 CompilationUnit unit = ParserTestCase.parseCompilationUnit("final ", | 3798 CompilationUnit unit = parseCompilationUnit("final ", |
| 3816 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); | 3799 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); |
| 3817 NodeList<CompilationUnitMember> declarations = unit.declarations; | 3800 NodeList<CompilationUnitMember> declarations = unit.declarations; |
| 3818 expect(declarations, hasLength(1)); | 3801 expect(declarations, hasLength(1)); |
| 3819 CompilationUnitMember member = declarations[0]; | 3802 CompilationUnitMember member = declarations[0]; |
| 3820 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableDeclaration, | 3803 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableDeclaration, |
| 3821 TopLevelVariableDeclaration, member); | 3804 TopLevelVariableDeclaration, member); |
| 3822 NodeList<VariableDeclaration> variables = | 3805 NodeList<VariableDeclaration> variables = |
| 3823 (member as TopLevelVariableDeclaration).variables.variables; | 3806 (member as TopLevelVariableDeclaration).variables.variables; |
| 3824 expect(variables, hasLength(1)); | 3807 expect(variables, hasLength(1)); |
| 3825 SimpleIdentifier name = variables[0].name; | 3808 SimpleIdentifier name = variables[0].name; |
| 3826 expect(name.isSynthetic, isTrue); | 3809 expect(name.isSynthetic, isTrue); |
| 3827 } | 3810 } |
| 3828 | 3811 |
| 3829 void test_incomplete_topLevelVariable_var() { | 3812 void test_incomplete_topLevelVariable_var() { |
| 3830 CompilationUnit unit = ParserTestCase.parseCompilationUnit("var ", | 3813 CompilationUnit unit = parseCompilationUnit("var ", |
| 3831 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); | 3814 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); |
| 3832 NodeList<CompilationUnitMember> declarations = unit.declarations; | 3815 NodeList<CompilationUnitMember> declarations = unit.declarations; |
| 3833 expect(declarations, hasLength(1)); | 3816 expect(declarations, hasLength(1)); |
| 3834 CompilationUnitMember member = declarations[0]; | 3817 CompilationUnitMember member = declarations[0]; |
| 3835 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableDeclaration, | 3818 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableDeclaration, |
| 3836 TopLevelVariableDeclaration, member); | 3819 TopLevelVariableDeclaration, member); |
| 3837 NodeList<VariableDeclaration> variables = | 3820 NodeList<VariableDeclaration> variables = |
| 3838 (member as TopLevelVariableDeclaration).variables.variables; | 3821 (member as TopLevelVariableDeclaration).variables.variables; |
| 3839 expect(variables, hasLength(1)); | 3822 expect(variables, hasLength(1)); |
| 3840 SimpleIdentifier name = variables[0].name; | 3823 SimpleIdentifier name = variables[0].name; |
| 3841 expect(name.isSynthetic, isTrue); | 3824 expect(name.isSynthetic, isTrue); |
| 3842 } | 3825 } |
| 3843 | 3826 |
| 3844 void test_incompleteField_const() { | 3827 void test_incompleteField_const() { |
| 3845 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 3828 CompilationUnit unit = parseCompilationUnit( |
| 3846 r''' | 3829 r''' |
| 3847 class C { | 3830 class C { |
| 3848 const | 3831 const |
| 3849 }''', | 3832 }''', |
| 3850 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); | 3833 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); |
| 3851 NodeList<CompilationUnitMember> declarations = unit.declarations; | 3834 NodeList<CompilationUnitMember> declarations = unit.declarations; |
| 3852 expect(declarations, hasLength(1)); | 3835 expect(declarations, hasLength(1)); |
| 3853 CompilationUnitMember unitMember = declarations[0]; | 3836 CompilationUnitMember unitMember = declarations[0]; |
| 3854 EngineTestCase.assertInstanceOf( | 3837 EngineTestCase.assertInstanceOf( |
| 3855 (obj) => obj is ClassDeclaration, ClassDeclaration, unitMember); | 3838 (obj) => obj is ClassDeclaration, ClassDeclaration, unitMember); |
| 3856 NodeList<ClassMember> members = (unitMember as ClassDeclaration).members; | 3839 NodeList<ClassMember> members = (unitMember as ClassDeclaration).members; |
| 3857 expect(members, hasLength(1)); | 3840 expect(members, hasLength(1)); |
| 3858 ClassMember classMember = members[0]; | 3841 ClassMember classMember = members[0]; |
| 3859 EngineTestCase.assertInstanceOf( | 3842 EngineTestCase.assertInstanceOf( |
| 3860 (obj) => obj is FieldDeclaration, FieldDeclaration, classMember); | 3843 (obj) => obj is FieldDeclaration, FieldDeclaration, classMember); |
| 3861 VariableDeclarationList fieldList = | 3844 VariableDeclarationList fieldList = |
| 3862 (classMember as FieldDeclaration).fields; | 3845 (classMember as FieldDeclaration).fields; |
| 3863 expect(fieldList.keyword.keyword, Keyword.CONST); | 3846 expect(fieldList.keyword.keyword, Keyword.CONST); |
| 3864 NodeList<VariableDeclaration> fields = fieldList.variables; | 3847 NodeList<VariableDeclaration> fields = fieldList.variables; |
| 3865 expect(fields, hasLength(1)); | 3848 expect(fields, hasLength(1)); |
| 3866 VariableDeclaration field = fields[0]; | 3849 VariableDeclaration field = fields[0]; |
| 3867 expect(field.name.isSynthetic, isTrue); | 3850 expect(field.name.isSynthetic, isTrue); |
| 3868 } | 3851 } |
| 3869 | 3852 |
| 3870 void test_incompleteField_final() { | 3853 void test_incompleteField_final() { |
| 3871 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 3854 CompilationUnit unit = parseCompilationUnit( |
| 3872 r''' | 3855 r''' |
| 3873 class C { | 3856 class C { |
| 3874 final | 3857 final |
| 3875 }''', | 3858 }''', |
| 3876 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); | 3859 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); |
| 3877 NodeList<CompilationUnitMember> declarations = unit.declarations; | 3860 NodeList<CompilationUnitMember> declarations = unit.declarations; |
| 3878 expect(declarations, hasLength(1)); | 3861 expect(declarations, hasLength(1)); |
| 3879 CompilationUnitMember unitMember = declarations[0]; | 3862 CompilationUnitMember unitMember = declarations[0]; |
| 3880 EngineTestCase.assertInstanceOf( | 3863 EngineTestCase.assertInstanceOf( |
| 3881 (obj) => obj is ClassDeclaration, ClassDeclaration, unitMember); | 3864 (obj) => obj is ClassDeclaration, ClassDeclaration, unitMember); |
| 3882 NodeList<ClassMember> members = (unitMember as ClassDeclaration).members; | 3865 NodeList<ClassMember> members = (unitMember as ClassDeclaration).members; |
| 3883 expect(members, hasLength(1)); | 3866 expect(members, hasLength(1)); |
| 3884 ClassMember classMember = members[0]; | 3867 ClassMember classMember = members[0]; |
| 3885 EngineTestCase.assertInstanceOf( | 3868 EngineTestCase.assertInstanceOf( |
| 3886 (obj) => obj is FieldDeclaration, FieldDeclaration, classMember); | 3869 (obj) => obj is FieldDeclaration, FieldDeclaration, classMember); |
| 3887 VariableDeclarationList fieldList = | 3870 VariableDeclarationList fieldList = |
| 3888 (classMember as FieldDeclaration).fields; | 3871 (classMember as FieldDeclaration).fields; |
| 3889 expect(fieldList.keyword.keyword, Keyword.FINAL); | 3872 expect(fieldList.keyword.keyword, Keyword.FINAL); |
| 3890 NodeList<VariableDeclaration> fields = fieldList.variables; | 3873 NodeList<VariableDeclaration> fields = fieldList.variables; |
| 3891 expect(fields, hasLength(1)); | 3874 expect(fields, hasLength(1)); |
| 3892 VariableDeclaration field = fields[0]; | 3875 VariableDeclaration field = fields[0]; |
| 3893 expect(field.name.isSynthetic, isTrue); | 3876 expect(field.name.isSynthetic, isTrue); |
| 3894 } | 3877 } |
| 3895 | 3878 |
| 3896 void test_incompleteField_var() { | 3879 void test_incompleteField_var() { |
| 3897 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 3880 CompilationUnit unit = parseCompilationUnit( |
| 3898 r''' | 3881 r''' |
| 3899 class C { | 3882 class C { |
| 3900 var | 3883 var |
| 3901 }''', | 3884 }''', |
| 3902 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); | 3885 [ParserErrorCode.MISSING_IDENTIFIER, ParserErrorCode.EXPECTED_TOKEN]); |
| 3903 NodeList<CompilationUnitMember> declarations = unit.declarations; | 3886 NodeList<CompilationUnitMember> declarations = unit.declarations; |
| 3904 expect(declarations, hasLength(1)); | 3887 expect(declarations, hasLength(1)); |
| 3905 CompilationUnitMember unitMember = declarations[0]; | 3888 CompilationUnitMember unitMember = declarations[0]; |
| 3906 EngineTestCase.assertInstanceOf( | 3889 EngineTestCase.assertInstanceOf( |
| 3907 (obj) => obj is ClassDeclaration, ClassDeclaration, unitMember); | 3890 (obj) => obj is ClassDeclaration, ClassDeclaration, unitMember); |
| 3908 NodeList<ClassMember> members = (unitMember as ClassDeclaration).members; | 3891 NodeList<ClassMember> members = (unitMember as ClassDeclaration).members; |
| 3909 expect(members, hasLength(1)); | 3892 expect(members, hasLength(1)); |
| 3910 ClassMember classMember = members[0]; | 3893 ClassMember classMember = members[0]; |
| 3911 EngineTestCase.assertInstanceOf( | 3894 EngineTestCase.assertInstanceOf( |
| 3912 (obj) => obj is FieldDeclaration, FieldDeclaration, classMember); | 3895 (obj) => obj is FieldDeclaration, FieldDeclaration, classMember); |
| 3913 VariableDeclarationList fieldList = | 3896 VariableDeclarationList fieldList = |
| 3914 (classMember as FieldDeclaration).fields; | 3897 (classMember as FieldDeclaration).fields; |
| 3915 expect(fieldList.keyword.keyword, Keyword.VAR); | 3898 expect(fieldList.keyword.keyword, Keyword.VAR); |
| 3916 NodeList<VariableDeclaration> fields = fieldList.variables; | 3899 NodeList<VariableDeclaration> fields = fieldList.variables; |
| 3917 expect(fields, hasLength(1)); | 3900 expect(fields, hasLength(1)); |
| 3918 VariableDeclaration field = fields[0]; | 3901 VariableDeclaration field = fields[0]; |
| 3919 expect(field.name.isSynthetic, isTrue); | 3902 expect(field.name.isSynthetic, isTrue); |
| 3920 } | 3903 } |
| 3921 | 3904 |
| 3922 void test_incompleteForEach() { | 3905 void test_incompleteForEach() { |
| 3923 ForStatement statement = ParserTestCase.parseStatement( | 3906 ForStatement statement = parseStatement('for (String item i) {}', |
| 3924 'for (String item i) {}', | |
| 3925 [ParserErrorCode.EXPECTED_TOKEN, ParserErrorCode.EXPECTED_TOKEN]); | 3907 [ParserErrorCode.EXPECTED_TOKEN, ParserErrorCode.EXPECTED_TOKEN]); |
| 3926 expect(statement, new isInstanceOf<ForStatement>()); | 3908 expect(statement, new isInstanceOf<ForStatement>()); |
| 3927 expect(statement.toSource(), 'for (String item; i;) {}'); | 3909 expect(statement.toSource(), 'for (String item; i;) {}'); |
| 3928 expect(statement.leftSeparator, isNotNull); | 3910 expect(statement.leftSeparator, isNotNull); |
| 3929 expect(statement.leftSeparator.type, TokenType.SEMICOLON); | 3911 expect(statement.leftSeparator.type, TokenType.SEMICOLON); |
| 3930 expect(statement.rightSeparator, isNotNull); | 3912 expect(statement.rightSeparator, isNotNull); |
| 3931 expect(statement.rightSeparator.type, TokenType.SEMICOLON); | 3913 expect(statement.rightSeparator.type, TokenType.SEMICOLON); |
| 3932 } | 3914 } |
| 3933 | 3915 |
| 3934 void test_incompleteLocalVariable_atTheEndOfBlock() { | 3916 void test_incompleteLocalVariable_atTheEndOfBlock() { |
| 3935 Statement statement = ParserTestCase | 3917 Statement statement = |
| 3936 .parseStatement('String v }', [ParserErrorCode.EXPECTED_TOKEN]); | 3918 parseStatement('String v }', [ParserErrorCode.EXPECTED_TOKEN]); |
| 3937 expect(statement, new isInstanceOf<VariableDeclarationStatement>()); | 3919 expect(statement, new isInstanceOf<VariableDeclarationStatement>()); |
| 3938 expect(statement.toSource(), 'String v;'); | 3920 expect(statement.toSource(), 'String v;'); |
| 3939 } | 3921 } |
| 3940 | 3922 |
| 3941 void test_incompleteLocalVariable_beforeIdentifier() { | 3923 void test_incompleteLocalVariable_beforeIdentifier() { |
| 3942 Statement statement = ParserTestCase.parseStatement( | 3924 Statement statement = |
| 3943 'String v String v2;', [ParserErrorCode.EXPECTED_TOKEN]); | 3925 parseStatement('String v String v2;', [ParserErrorCode.EXPECTED_TOKEN]); |
| 3944 expect(statement, new isInstanceOf<VariableDeclarationStatement>()); | 3926 expect(statement, new isInstanceOf<VariableDeclarationStatement>()); |
| 3945 expect(statement.toSource(), 'String v;'); | 3927 expect(statement.toSource(), 'String v;'); |
| 3946 } | 3928 } |
| 3947 | 3929 |
| 3948 void test_incompleteLocalVariable_beforeKeyword() { | 3930 void test_incompleteLocalVariable_beforeKeyword() { |
| 3949 Statement statement = ParserTestCase.parseStatement( | 3931 Statement statement = parseStatement( |
| 3950 'String v if (true) {}', [ParserErrorCode.EXPECTED_TOKEN]); | 3932 'String v if (true) {}', [ParserErrorCode.EXPECTED_TOKEN]); |
| 3951 expect(statement, new isInstanceOf<VariableDeclarationStatement>()); | 3933 expect(statement, new isInstanceOf<VariableDeclarationStatement>()); |
| 3952 expect(statement.toSource(), 'String v;'); | 3934 expect(statement.toSource(), 'String v;'); |
| 3953 } | 3935 } |
| 3954 | 3936 |
| 3955 void test_incompleteLocalVariable_beforeNextBlock() { | 3937 void test_incompleteLocalVariable_beforeNextBlock() { |
| 3956 Statement statement = ParserTestCase | 3938 Statement statement = |
| 3957 .parseStatement('String v {}', [ParserErrorCode.EXPECTED_TOKEN]); | 3939 parseStatement('String v {}', [ParserErrorCode.EXPECTED_TOKEN]); |
| 3958 expect(statement, new isInstanceOf<VariableDeclarationStatement>()); | 3940 expect(statement, new isInstanceOf<VariableDeclarationStatement>()); |
| 3959 expect(statement.toSource(), 'String v;'); | 3941 expect(statement.toSource(), 'String v;'); |
| 3960 } | 3942 } |
| 3961 | 3943 |
| 3962 void test_incompleteLocalVariable_parameterizedType() { | 3944 void test_incompleteLocalVariable_parameterizedType() { |
| 3963 Statement statement = ParserTestCase | 3945 Statement statement = |
| 3964 .parseStatement('List<String> v {}', [ParserErrorCode.EXPECTED_TOKEN]); | 3946 parseStatement('List<String> v {}', [ParserErrorCode.EXPECTED_TOKEN]); |
| 3965 expect(statement, new isInstanceOf<VariableDeclarationStatement>()); | 3947 expect(statement, new isInstanceOf<VariableDeclarationStatement>()); |
| 3966 expect(statement.toSource(), 'List<String> v;'); | 3948 expect(statement.toSource(), 'List<String> v;'); |
| 3967 } | 3949 } |
| 3968 | 3950 |
| 3969 void test_incompleteTypeArguments_field() { | 3951 void test_incompleteTypeArguments_field() { |
| 3970 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 3952 CompilationUnit unit = parseCompilationUnit( |
| 3971 r''' | 3953 r''' |
| 3972 class C { | 3954 class C { |
| 3973 final List<int f; | 3955 final List<int f; |
| 3974 }''', | 3956 }''', |
| 3975 [ParserErrorCode.EXPECTED_TOKEN]); | 3957 [ParserErrorCode.EXPECTED_TOKEN]); |
| 3976 // one class | 3958 // one class |
| 3977 List<CompilationUnitMember> declarations = unit.declarations; | 3959 List<CompilationUnitMember> declarations = unit.declarations; |
| 3978 expect(declarations, hasLength(1)); | 3960 expect(declarations, hasLength(1)); |
| 3979 ClassDeclaration classDecl = declarations[0] as ClassDeclaration; | 3961 ClassDeclaration classDecl = declarations[0] as ClassDeclaration; |
| 3980 // one field declaration | 3962 // one field declaration |
| 3981 List<ClassMember> members = classDecl.members; | 3963 List<ClassMember> members = classDecl.members; |
| 3982 expect(members, hasLength(1)); | 3964 expect(members, hasLength(1)); |
| 3983 FieldDeclaration fieldDecl = members[0] as FieldDeclaration; | 3965 FieldDeclaration fieldDecl = members[0] as FieldDeclaration; |
| 3984 // one field | 3966 // one field |
| 3985 VariableDeclarationList fieldList = fieldDecl.fields; | 3967 VariableDeclarationList fieldList = fieldDecl.fields; |
| 3986 List<VariableDeclaration> fields = fieldList.variables; | 3968 List<VariableDeclaration> fields = fieldList.variables; |
| 3987 expect(fields, hasLength(1)); | 3969 expect(fields, hasLength(1)); |
| 3988 VariableDeclaration field = fields[0]; | 3970 VariableDeclaration field = fields[0]; |
| 3989 expect(field.name.name, 'f'); | 3971 expect(field.name.name, 'f'); |
| 3990 // validate the type | 3972 // validate the type |
| 3991 TypeArgumentList typeArguments = (fieldList.type as TypeName).typeArguments; | 3973 TypeArgumentList typeArguments = (fieldList.type as TypeName).typeArguments; |
| 3992 expect(typeArguments.arguments, hasLength(1)); | 3974 expect(typeArguments.arguments, hasLength(1)); |
| 3993 // synthetic '>' | 3975 // synthetic '>' |
| 3994 Token token = typeArguments.endToken; | 3976 Token token = typeArguments.endToken; |
| 3995 expect(token.type, TokenType.GT); | 3977 expect(token.type, TokenType.GT); |
| 3996 expect(token.isSynthetic, isTrue); | 3978 expect(token.isSynthetic, isTrue); |
| 3997 } | 3979 } |
| 3998 | 3980 |
| 3999 void test_incompleteTypeParameters() { | 3981 void test_incompleteTypeParameters() { |
| 4000 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 3982 CompilationUnit unit = parseCompilationUnit( |
| 4001 r''' | 3983 r''' |
| 4002 class C<K { | 3984 class C<K { |
| 4003 }''', | 3985 }''', |
| 4004 [ParserErrorCode.EXPECTED_TOKEN]); | 3986 [ParserErrorCode.EXPECTED_TOKEN]); |
| 4005 // one class | 3987 // one class |
| 4006 List<CompilationUnitMember> declarations = unit.declarations; | 3988 List<CompilationUnitMember> declarations = unit.declarations; |
| 4007 expect(declarations, hasLength(1)); | 3989 expect(declarations, hasLength(1)); |
| 4008 ClassDeclaration classDecl = declarations[0] as ClassDeclaration; | 3990 ClassDeclaration classDecl = declarations[0] as ClassDeclaration; |
| 4009 // validate the type parameters | 3991 // validate the type parameters |
| 4010 TypeParameterList typeParameters = classDecl.typeParameters; | 3992 TypeParameterList typeParameters = classDecl.typeParameters; |
| 4011 expect(typeParameters.typeParameters, hasLength(1)); | 3993 expect(typeParameters.typeParameters, hasLength(1)); |
| 4012 // synthetic '>' | 3994 // synthetic '>' |
| 4013 Token token = typeParameters.endToken; | 3995 Token token = typeParameters.endToken; |
| 4014 expect(token.type, TokenType.GT); | 3996 expect(token.type, TokenType.GT); |
| 4015 expect(token.isSynthetic, isTrue); | 3997 expect(token.isSynthetic, isTrue); |
| 4016 } | 3998 } |
| 4017 | 3999 |
| 4018 void test_invalidFunctionBodyModifier() { | 4000 void test_invalidFunctionBodyModifier() { |
| 4019 ParserTestCase.parseCompilationUnit( | 4001 parseCompilationUnit( |
| 4020 "f() sync {}", [ParserErrorCode.MISSING_STAR_AFTER_SYNC]); | 4002 "f() sync {}", [ParserErrorCode.MISSING_STAR_AFTER_SYNC]); |
| 4021 } | 4003 } |
| 4022 | 4004 |
| 4023 void test_isExpression_noType() { | 4005 void test_isExpression_noType() { |
| 4024 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 4006 CompilationUnit unit = parseCompilationUnit( |
| 4025 "class Bar<T extends Foo> {m(x){if (x is ) return;if (x is !)}}", [ | 4007 "class Bar<T extends Foo> {m(x){if (x is ) return;if (x is !)}}", [ |
| 4026 ParserErrorCode.EXPECTED_TYPE_NAME, | 4008 ParserErrorCode.EXPECTED_TYPE_NAME, |
| 4027 ParserErrorCode.EXPECTED_TYPE_NAME, | 4009 ParserErrorCode.EXPECTED_TYPE_NAME, |
| 4028 ParserErrorCode.MISSING_STATEMENT | 4010 ParserErrorCode.MISSING_STATEMENT |
| 4029 ]); | 4011 ]); |
| 4030 ClassDeclaration declaration = unit.declarations[0] as ClassDeclaration; | 4012 ClassDeclaration declaration = unit.declarations[0] as ClassDeclaration; |
| 4031 MethodDeclaration method = declaration.members[0] as MethodDeclaration; | 4013 MethodDeclaration method = declaration.members[0] as MethodDeclaration; |
| 4032 BlockFunctionBody body = method.body as BlockFunctionBody; | 4014 BlockFunctionBody body = method.body as BlockFunctionBody; |
| 4033 IfStatement ifStatement = body.block.statements[1] as IfStatement; | 4015 IfStatement ifStatement = body.block.statements[1] as IfStatement; |
| 4034 IsExpression expression = ifStatement.condition as IsExpression; | 4016 IsExpression expression = ifStatement.condition as IsExpression; |
| 4035 expect(expression.expression, isNotNull); | 4017 expect(expression.expression, isNotNull); |
| 4036 expect(expression.isOperator, isNotNull); | 4018 expect(expression.isOperator, isNotNull); |
| 4037 expect(expression.notOperator, isNotNull); | 4019 expect(expression.notOperator, isNotNull); |
| 4038 TypeAnnotation type = expression.type; | 4020 TypeAnnotation type = expression.type; |
| 4039 expect(type, isNotNull); | 4021 expect(type, isNotNull); |
| 4040 expect(type is TypeName && type.name.isSynthetic, isTrue); | 4022 expect(type is TypeName && type.name.isSynthetic, isTrue); |
| 4041 EngineTestCase.assertInstanceOf((obj) => obj is EmptyStatement, | 4023 EngineTestCase.assertInstanceOf((obj) => obj is EmptyStatement, |
| 4042 EmptyStatement, ifStatement.thenStatement); | 4024 EmptyStatement, ifStatement.thenStatement); |
| 4043 } | 4025 } |
| 4044 | 4026 |
| 4045 void test_keywordInPlaceOfIdentifier() { | 4027 void test_keywordInPlaceOfIdentifier() { |
| 4046 // TODO(brianwilkerson) We could do better with this. | 4028 // TODO(brianwilkerson) We could do better with this. |
| 4047 ParserTestCase.parseCompilationUnit("do() {}", [ | 4029 parseCompilationUnit("do() {}", [ |
| 4048 ParserErrorCode.EXPECTED_EXECUTABLE, | 4030 ParserErrorCode.EXPECTED_EXECUTABLE, |
| 4049 ParserErrorCode.UNEXPECTED_TOKEN | 4031 ParserErrorCode.UNEXPECTED_TOKEN |
| 4050 ]); | 4032 ]); |
| 4051 } | 4033 } |
| 4052 | 4034 |
| 4053 void test_logicalAndExpression_missing_LHS() { | 4035 void test_logicalAndExpression_missing_LHS() { |
| 4054 BinaryExpression expression = | 4036 BinaryExpression expression = |
| 4055 parseExpression("&& y", [ParserErrorCode.MISSING_IDENTIFIER]); | 4037 parseExpression("&& y", [ParserErrorCode.MISSING_IDENTIFIER]); |
| 4056 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, | 4038 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| 4057 SimpleIdentifier, expression.leftOperand); | 4039 SimpleIdentifier, expression.leftOperand); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4146 ]); | 4128 ]); |
| 4147 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, | 4129 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| 4148 BinaryExpression, expression.rightOperand); | 4130 BinaryExpression, expression.rightOperand); |
| 4149 } | 4131 } |
| 4150 | 4132 |
| 4151 void test_missing_commaInArgumentList() { | 4133 void test_missing_commaInArgumentList() { |
| 4152 parseExpression("f(x: 1 y: 2)", [ParserErrorCode.EXPECTED_TOKEN]); | 4134 parseExpression("f(x: 1 y: 2)", [ParserErrorCode.EXPECTED_TOKEN]); |
| 4153 } | 4135 } |
| 4154 | 4136 |
| 4155 void test_missingGet() { | 4137 void test_missingGet() { |
| 4156 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 4138 CompilationUnit unit = parseCompilationUnit( |
| 4157 r''' | 4139 r''' |
| 4158 class C { | 4140 class C { |
| 4159 int length {} | 4141 int length {} |
| 4160 void foo() {} | 4142 void foo() {} |
| 4161 }''', | 4143 }''', |
| 4162 [ParserErrorCode.MISSING_GET]); | 4144 [ParserErrorCode.MISSING_GET]); |
| 4163 expect(unit, isNotNull); | 4145 expect(unit, isNotNull); |
| 4164 ClassDeclaration classDeclaration = | 4146 ClassDeclaration classDeclaration = |
| 4165 unit.declarations[0] as ClassDeclaration; | 4147 unit.declarations[0] as ClassDeclaration; |
| 4166 NodeList<ClassMember> members = classDeclaration.members; | 4148 NodeList<ClassMember> members = classDeclaration.members; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 4194 VariableDeclarationList variableList = declaration.variables; | 4176 VariableDeclarationList variableList = declaration.variables; |
| 4195 expect(variableList, isNotNull); | 4177 expect(variableList, isNotNull); |
| 4196 NodeList<VariableDeclaration> variables = variableList.variables; | 4178 NodeList<VariableDeclaration> variables = variableList.variables; |
| 4197 expect(variables, hasLength(1)); | 4179 expect(variables, hasLength(1)); |
| 4198 VariableDeclaration variable = variables[0]; | 4180 VariableDeclaration variable = variables[0]; |
| 4199 expect(variableList.type.toString(), expectedTypeName); | 4181 expect(variableList.type.toString(), expectedTypeName); |
| 4200 expect(variable.name.name, expectedName); | 4182 expect(variable.name.name, expectedName); |
| 4201 expect(declaration.semicolon.lexeme, expectedSemicolon); | 4183 expect(declaration.semicolon.lexeme, expectedSemicolon); |
| 4202 } | 4184 } |
| 4203 | 4185 |
| 4204 CompilationUnit unit = ParserTestCase.parseCompilationUnit( | 4186 CompilationUnit unit = parseCompilationUnit('String n x = "";', [ |
| 4205 'String n x = "";', [ | |
| 4206 ParserErrorCode.EXPECTED_TOKEN, | 4187 ParserErrorCode.EXPECTED_TOKEN, |
| 4207 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE | 4188 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE |
| 4208 ]); | 4189 ]); |
| 4209 expect(unit, isNotNull); | 4190 expect(unit, isNotNull); |
| 4210 NodeList<CompilationUnitMember> declarations = unit.declarations; | 4191 NodeList<CompilationUnitMember> declarations = unit.declarations; |
| 4211 expect(declarations, hasLength(2)); | 4192 expect(declarations, hasLength(2)); |
| 4212 verify(declarations[0], 'String', 'n', ''); | 4193 verify(declarations[0], 'String', 'n', ''); |
| 4213 verify(declarations[1], 'null', 'x', ';'); | 4194 verify(declarations[1], 'null', 'x', ';'); |
| 4214 } | 4195 } |
| 4215 | 4196 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4268 BinaryExpression expression = parseExpression("super == ==", [ | 4249 BinaryExpression expression = parseExpression("super == ==", [ |
| 4269 ParserErrorCode.MISSING_IDENTIFIER, | 4250 ParserErrorCode.MISSING_IDENTIFIER, |
| 4270 ParserErrorCode.MISSING_IDENTIFIER, | 4251 ParserErrorCode.MISSING_IDENTIFIER, |
| 4271 ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND | 4252 ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND |
| 4272 ]); | 4253 ]); |
| 4273 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, | 4254 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| 4274 BinaryExpression, expression.leftOperand); | 4255 BinaryExpression, expression.leftOperand); |
| 4275 } | 4256 } |
| 4276 | 4257 |
| 4277 void test_nonStringLiteralUri_import() { | 4258 void test_nonStringLiteralUri_import() { |
| 4278 ParserTestCase.parseCompilationUnit("import dart:io; class C {}", | 4259 parseCompilationUnit("import dart:io; class C {}", |
| 4279 [ParserErrorCode.NON_STRING_LITERAL_AS_URI]); | 4260 [ParserErrorCode.NON_STRING_LITERAL_AS_URI]); |
| 4280 } | 4261 } |
| 4281 | 4262 |
| 4282 void test_prefixExpression_missing_operand_minus() { | 4263 void test_prefixExpression_missing_operand_minus() { |
| 4283 PrefixExpression expression = | 4264 PrefixExpression expression = |
| 4284 parseExpression("-", [ParserErrorCode.MISSING_IDENTIFIER]); | 4265 parseExpression("-", [ParserErrorCode.MISSING_IDENTIFIER]); |
| 4285 EngineTestCase.assertInstanceOf( | 4266 EngineTestCase.assertInstanceOf( |
| 4286 (obj) => obj is SimpleIdentifier, SimpleIdentifier, expression.operand); | 4267 (obj) => obj is SimpleIdentifier, SimpleIdentifier, expression.operand); |
| 4287 expect(expression.operand.isSynthetic, isTrue); | 4268 expect(expression.operand.isSynthetic, isTrue); |
| 4288 expect(expression.operator.type, TokenType.MINUS); | 4269 expect(expression.operator.type, TokenType.MINUS); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4395 void test_shiftExpression_super() { | 4376 void test_shiftExpression_super() { |
| 4396 BinaryExpression expression = parseExpression("super << <<", [ | 4377 BinaryExpression expression = parseExpression("super << <<", [ |
| 4397 ParserErrorCode.MISSING_IDENTIFIER, | 4378 ParserErrorCode.MISSING_IDENTIFIER, |
| 4398 ParserErrorCode.MISSING_IDENTIFIER | 4379 ParserErrorCode.MISSING_IDENTIFIER |
| 4399 ]); | 4380 ]); |
| 4400 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, | 4381 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| 4401 BinaryExpression, expression.leftOperand); | 4382 BinaryExpression, expression.leftOperand); |
| 4402 } | 4383 } |
| 4403 | 4384 |
| 4404 void test_typedef_eof() { | 4385 void test_typedef_eof() { |
| 4405 CompilationUnit unit = ParserTestCase.parseCompilationUnit("typedef n", [ | 4386 CompilationUnit unit = parseCompilationUnit("typedef n", [ |
| 4406 ParserErrorCode.EXPECTED_TOKEN, | 4387 ParserErrorCode.EXPECTED_TOKEN, |
| 4407 ParserErrorCode.MISSING_TYPEDEF_PARAMETERS | 4388 ParserErrorCode.MISSING_TYPEDEF_PARAMETERS |
| 4408 ]); | 4389 ]); |
| 4409 NodeList<CompilationUnitMember> declarations = unit.declarations; | 4390 NodeList<CompilationUnitMember> declarations = unit.declarations; |
| 4410 expect(declarations, hasLength(1)); | 4391 expect(declarations, hasLength(1)); |
| 4411 CompilationUnitMember member = declarations[0]; | 4392 CompilationUnitMember member = declarations[0]; |
| 4412 EngineTestCase.assertInstanceOf( | 4393 EngineTestCase.assertInstanceOf( |
| 4413 (obj) => obj is FunctionTypeAlias, FunctionTypeAlias, member); | 4394 (obj) => obj is FunctionTypeAlias, FunctionTypeAlias, member); |
| 4414 } | 4395 } |
| 4415 | 4396 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4522 } | 4503 } |
| 4523 | 4504 |
| 4524 void test_createSyntheticStringLiteral() { | 4505 void test_createSyntheticStringLiteral() { |
| 4525 createParser(''); | 4506 createParser(''); |
| 4526 SimpleStringLiteral literal = parser.createSyntheticStringLiteral(); | 4507 SimpleStringLiteral literal = parser.createSyntheticStringLiteral(); |
| 4527 expectNotNullIfNoErrors(literal); | 4508 expectNotNullIfNoErrors(literal); |
| 4528 expect(literal.isSynthetic, isTrue); | 4509 expect(literal.isSynthetic, isTrue); |
| 4529 } | 4510 } |
| 4530 | 4511 |
| 4531 void test_function_literal_allowed_at_toplevel() { | 4512 void test_function_literal_allowed_at_toplevel() { |
| 4532 ParserTestCase.parseCompilationUnit("var x = () {};"); | 4513 parseCompilationUnit("var x = () {};"); |
| 4533 } | 4514 } |
| 4534 | 4515 |
| 4535 void | 4516 void |
| 4536 test_function_literal_allowed_in_ArgumentList_in_ConstructorFieldInitializ
er() { | 4517 test_function_literal_allowed_in_ArgumentList_in_ConstructorFieldInitializ
er() { |
| 4537 ParserTestCase.parseCompilationUnit("class C { C() : a = f(() {}); }"); | 4518 parseCompilationUnit("class C { C() : a = f(() {}); }"); |
| 4538 } | 4519 } |
| 4539 | 4520 |
| 4540 void | 4521 void |
| 4541 test_function_literal_allowed_in_IndexExpression_in_ConstructorFieldInitia
lizer() { | 4522 test_function_literal_allowed_in_IndexExpression_in_ConstructorFieldInitia
lizer() { |
| 4542 ParserTestCase.parseCompilationUnit("class C { C() : a = x[() {}]; }"); | 4523 parseCompilationUnit("class C { C() : a = x[() {}]; }"); |
| 4543 } | 4524 } |
| 4544 | 4525 |
| 4545 void | 4526 void |
| 4546 test_function_literal_allowed_in_ListLiteral_in_ConstructorFieldInitialize
r() { | 4527 test_function_literal_allowed_in_ListLiteral_in_ConstructorFieldInitialize
r() { |
| 4547 ParserTestCase.parseCompilationUnit("class C { C() : a = [() {}]; }"); | 4528 parseCompilationUnit("class C { C() : a = [() {}]; }"); |
| 4548 } | 4529 } |
| 4549 | 4530 |
| 4550 void | 4531 void |
| 4551 test_function_literal_allowed_in_MapLiteral_in_ConstructorFieldInitializer
() { | 4532 test_function_literal_allowed_in_MapLiteral_in_ConstructorFieldInitializer
() { |
| 4552 ParserTestCase | 4533 parseCompilationUnit("class C { C() : a = {'key': () {}}; }"); |
| 4553 .parseCompilationUnit("class C { C() : a = {'key': () {}}; }"); | |
| 4554 } | 4534 } |
| 4555 | 4535 |
| 4556 void | 4536 void |
| 4557 test_function_literal_allowed_in_ParenthesizedExpression_in_ConstructorFie
ldInitializer() { | 4537 test_function_literal_allowed_in_ParenthesizedExpression_in_ConstructorFie
ldInitializer() { |
| 4558 ParserTestCase.parseCompilationUnit("class C { C() : a = (() {}); }"); | 4538 parseCompilationUnit("class C { C() : a = (() {}); }"); |
| 4559 } | 4539 } |
| 4560 | 4540 |
| 4561 void | 4541 void |
| 4562 test_function_literal_allowed_in_StringInterpolation_in_ConstructorFieldIn
itializer() { | 4542 test_function_literal_allowed_in_StringInterpolation_in_ConstructorFieldIn
itializer() { |
| 4563 ParserTestCase.parseCompilationUnit("class C { C() : a = \"\${(){}}\"; }"); | 4543 parseCompilationUnit("class C { C() : a = \"\${(){}}\"; }"); |
| 4564 } | 4544 } |
| 4565 | 4545 |
| 4566 void test_import_as_show() { | 4546 void test_import_as_show() { |
| 4567 ParserTestCase.parseCompilationUnit("import 'dart:math' as M show E;"); | 4547 parseCompilationUnit("import 'dart:math' as M show E;"); |
| 4568 } | 4548 } |
| 4569 | 4549 |
| 4570 void test_import_show_hide() { | 4550 void test_import_show_hide() { |
| 4571 ParserTestCase.parseCompilationUnit( | 4551 parseCompilationUnit( |
| 4572 "import 'import1_lib.dart' show hide, show hide ugly;"); | 4552 "import 'import1_lib.dart' show hide, show hide ugly;"); |
| 4573 } | 4553 } |
| 4574 | 4554 |
| 4575 void test_isFunctionDeclaration_nameButNoReturn_block() { | 4555 void test_isFunctionDeclaration_nameButNoReturn_block() { |
| 4576 expect(_isFunctionDeclaration("f() {}"), isTrue); | 4556 expect(_isFunctionDeclaration("f() {}"), isTrue); |
| 4577 } | 4557 } |
| 4578 | 4558 |
| 4579 void test_isFunctionDeclaration_nameButNoReturn_expression() { | 4559 void test_isFunctionDeclaration_nameButNoReturn_expression() { |
| 4580 expect(_isFunctionDeclaration("f() => e"), isTrue); | 4560 expect(_isFunctionDeclaration("f() => e"), isTrue); |
| 4581 } | 4561 } |
| (...skipping 2733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7315 createParser('abstract<dynamic> _abstract = new abstract.A();'); | 7295 createParser('abstract<dynamic> _abstract = new abstract.A();'); |
| 7316 CompilationUnit unit = parser.parseCompilationUnit2(); | 7296 CompilationUnit unit = parser.parseCompilationUnit2(); |
| 7317 expectNotNullIfNoErrors(unit); | 7297 expectNotNullIfNoErrors(unit); |
| 7318 listener.assertNoErrors(); | 7298 listener.assertNoErrors(); |
| 7319 expect(unit.scriptTag, isNull); | 7299 expect(unit.scriptTag, isNull); |
| 7320 expect(unit.directives, hasLength(0)); | 7300 expect(unit.directives, hasLength(0)); |
| 7321 expect(unit.declarations, hasLength(1)); | 7301 expect(unit.declarations, hasLength(1)); |
| 7322 } | 7302 } |
| 7323 | 7303 |
| 7324 void test_parseCompilationUnit_builtIn_asFunctionName() { | 7304 void test_parseCompilationUnit_builtIn_asFunctionName() { |
| 7325 ParserTestCase.parseCompilationUnit('abstract(x) => 0;'); | 7305 parseCompilationUnit('abstract(x) => 0;'); |
| 7326 ParserTestCase.parseCompilationUnit('as(x) => 0;'); | 7306 parseCompilationUnit('as(x) => 0;'); |
| 7327 ParserTestCase.parseCompilationUnit('dynamic(x) => 0;'); | 7307 parseCompilationUnit('dynamic(x) => 0;'); |
| 7328 ParserTestCase.parseCompilationUnit('export(x) => 0;'); | 7308 parseCompilationUnit('export(x) => 0;'); |
| 7329 ParserTestCase.parseCompilationUnit('external(x) => 0;'); | 7309 parseCompilationUnit('external(x) => 0;'); |
| 7330 ParserTestCase.parseCompilationUnit('factory(x) => 0;'); | 7310 parseCompilationUnit('factory(x) => 0;'); |
| 7331 ParserTestCase.parseCompilationUnit('get(x) => 0;'); | 7311 parseCompilationUnit('get(x) => 0;'); |
| 7332 ParserTestCase.parseCompilationUnit('implements(x) => 0;'); | 7312 parseCompilationUnit('implements(x) => 0;'); |
| 7333 ParserTestCase.parseCompilationUnit('import(x) => 0;'); | 7313 parseCompilationUnit('import(x) => 0;'); |
| 7334 ParserTestCase.parseCompilationUnit('library(x) => 0;'); | 7314 parseCompilationUnit('library(x) => 0;'); |
| 7335 ParserTestCase.parseCompilationUnit('operator(x) => 0;'); | 7315 parseCompilationUnit('operator(x) => 0;'); |
| 7336 ParserTestCase.parseCompilationUnit('part(x) => 0;'); | 7316 parseCompilationUnit('part(x) => 0;'); |
| 7337 ParserTestCase.parseCompilationUnit('set(x) => 0;'); | 7317 parseCompilationUnit('set(x) => 0;'); |
| 7338 ParserTestCase.parseCompilationUnit('static(x) => 0;'); | 7318 parseCompilationUnit('static(x) => 0;'); |
| 7339 ParserTestCase.parseCompilationUnit('typedef(x) => 0;'); | 7319 parseCompilationUnit('typedef(x) => 0;'); |
| 7340 } | 7320 } |
| 7341 | 7321 |
| 7342 void test_parseCompilationUnit_directives_multiple() { | 7322 void test_parseCompilationUnit_directives_multiple() { |
| 7343 createParser("library l;\npart 'a.dart';"); | 7323 createParser("library l;\npart 'a.dart';"); |
| 7344 CompilationUnit unit = parser.parseCompilationUnit2(); | 7324 CompilationUnit unit = parser.parseCompilationUnit2(); |
| 7345 expectNotNullIfNoErrors(unit); | 7325 expectNotNullIfNoErrors(unit); |
| 7346 listener.assertNoErrors(); | 7326 listener.assertNoErrors(); |
| 7347 expect(unit.scriptTag, isNull); | 7327 expect(unit.scriptTag, isNull); |
| 7348 expect(unit.directives, hasLength(2)); | 7328 expect(unit.directives, hasLength(2)); |
| 7349 expect(unit.declarations, hasLength(0)); | 7329 expect(unit.declarations, hasLength(0)); |
| (...skipping 5304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12654 expectNotNullIfNoErrors(statement); | 12634 expectNotNullIfNoErrors(statement); |
| 12655 listener.assertNoErrors(); | 12635 listener.assertNoErrors(); |
| 12656 expect(statement, new isInstanceOf<LabeledStatement>()); | 12636 expect(statement, new isInstanceOf<LabeledStatement>()); |
| 12657 LabeledStatement labeledStatement = statement; | 12637 LabeledStatement labeledStatement = statement; |
| 12658 expect(labeledStatement.labels, hasLength(1)); | 12638 expect(labeledStatement.labels, hasLength(1)); |
| 12659 expect(labeledStatement.labels[0].label.inDeclarationContext(), isTrue); | 12639 expect(labeledStatement.labels[0].label.inDeclarationContext(), isTrue); |
| 12660 expect(labeledStatement.statement, isNotNull); | 12640 expect(labeledStatement.statement, isNotNull); |
| 12661 } | 12641 } |
| 12662 | 12642 |
| 12663 void test_parseStatements_multiple() { | 12643 void test_parseStatements_multiple() { |
| 12664 List<Statement> statements = | 12644 List<Statement> statements = parseStatements("return; return;", 2); |
| 12665 ParserTestCase.parseStatements("return; return;", 2); | |
| 12666 expect(statements, hasLength(2)); | 12645 expect(statements, hasLength(2)); |
| 12667 } | 12646 } |
| 12668 | 12647 |
| 12669 void test_parseStatements_single() { | 12648 void test_parseStatements_single() { |
| 12670 List<Statement> statements = ParserTestCase.parseStatements("return;", 1); | 12649 List<Statement> statements = parseStatements("return;", 1); |
| 12671 expect(statements, hasLength(1)); | 12650 expect(statements, hasLength(1)); |
| 12672 } | 12651 } |
| 12673 | 12652 |
| 12674 void test_parseStringLiteral_adjacent() { | 12653 void test_parseStringLiteral_adjacent() { |
| 12675 createParser("'a' 'b'"); | 12654 createParser("'a' 'b'"); |
| 12676 Expression expression = parser.parseStringLiteral(); | 12655 Expression expression = parser.parseStringLiteral(); |
| 12677 expectNotNullIfNoErrors(expression); | 12656 expectNotNullIfNoErrors(expression); |
| 12678 listener.assertNoErrors(); | 12657 listener.assertNoErrors(); |
| 12679 expect(expression, new isInstanceOf<AdjacentStrings>()); | 12658 expect(expression, new isInstanceOf<AdjacentStrings>()); |
| 12680 AdjacentStrings literal = expression; | 12659 AdjacentStrings literal = expression; |
| (...skipping 1948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14629 CompilationUnit _parseDirectives(String source, | 14608 CompilationUnit _parseDirectives(String source, |
| 14630 [List<ErrorCode> errorCodes = const <ErrorCode>[]]) { | 14609 [List<ErrorCode> errorCodes = const <ErrorCode>[]]) { |
| 14631 createParser(source); | 14610 createParser(source); |
| 14632 CompilationUnit unit = parser.parseDirectives2(); | 14611 CompilationUnit unit = parser.parseDirectives2(); |
| 14633 expect(unit, isNotNull); | 14612 expect(unit, isNotNull); |
| 14634 expect(unit.declarations, hasLength(0)); | 14613 expect(unit.declarations, hasLength(0)); |
| 14635 listener.assertErrorsWithCodes(errorCodes); | 14614 listener.assertErrorsWithCodes(errorCodes); |
| 14636 return unit; | 14615 return unit; |
| 14637 } | 14616 } |
| 14638 } | 14617 } |
| OLD | NEW |