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

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

Issue 3011693002: Fasta test cleanup (Closed)
Patch Set: Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analyzer/test/generated/parser_fasta_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'package:analyzer/dart/ast/ast.dart'; 5 import 'package:analyzer/dart/ast/ast.dart';
6 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; 6 import 'package:analyzer/dart/ast/standard_ast_factory.dart';
7 import 'package:analyzer/dart/ast/token.dart'; 7 import 'package:analyzer/dart/ast/token.dart';
8 import 'package:analyzer/dart/ast/visitor.dart'; 8 import 'package:analyzer/dart/ast/visitor.dart';
9 import 'package:analyzer/error/error.dart'; 9 import 'package:analyzer/error/error.dart';
10 import 'package:analyzer/error/listener.dart'; 10 import 'package:analyzer/error/listener.dart';
(...skipping 1559 matching lines...) Expand 10 before | Expand all | Expand 10 after
1570 */ 1570 */
1571 void _assertIsDeclarationName(SimpleIdentifier name, [bool expected = true]) { 1571 void _assertIsDeclarationName(SimpleIdentifier name, [bool expected = true]) {
1572 expect(name.inDeclarationContext(), expected); 1572 expect(name.inDeclarationContext(), expected);
1573 } 1573 }
1574 } 1574 }
1575 1575
1576 /** 1576 /**
1577 * Tests of the analyzer parser based on [ComplexParserTestMixin]. 1577 * Tests of the analyzer parser based on [ComplexParserTestMixin].
1578 */ 1578 */
1579 @reflectiveTest 1579 @reflectiveTest
1580 class ComplexParserTest extends ParserTestCase with ComplexParserTestMixin {} 1580 class ComplexParserTest extends ParserTestCase with ComplexParserTestMixin {
1581 void test_logicalAndExpression_precedence_nullableType() {
1582 enableNnbd = true;
1583 BinaryExpression expression = parseExpression("x is C? && y is D");
1584 expect(expression.leftOperand, new isInstanceOf<IsExpression>());
1585 expect(expression.rightOperand, new isInstanceOf<IsExpression>());
1586 }
1587
1588 void test_logicalOrExpression_precedence_nullableType() {
1589 enableNnbd = true;
1590 BinaryExpression expression = parseExpression("a is X? || (b ? c : d)");
1591 expect(expression.leftOperand, new isInstanceOf<IsExpression>());
1592 expect(
1593 expression.rightOperand, new isInstanceOf<ParenthesizedExpression>());
1594 expect((expression.rightOperand as ParenthesizedExpression).expression,
1595 new isInstanceOf<ConditionalExpression>());
1596 }
1597 }
1581 1598
1582 /** 1599 /**
1583 * The class `ComplexParserTest` defines parser tests that test the parsing of m ore complex 1600 * The class `ComplexParserTest` defines parser tests that test the parsing of m ore complex
1584 * code fragments or the interactions between multiple parsing methods. For exam ple, tests to ensure 1601 * code fragments or the interactions between multiple parsing methods. For exam ple, tests to ensure
1585 * that the precedence of operations is being handled correctly should be define d in this class. 1602 * that the precedence of operations is being handled correctly should be define d in this class.
1586 * 1603 *
1587 * Simpler tests should be defined in the class [SimpleParserTest]. 1604 * Simpler tests should be defined in the class [SimpleParserTest].
1588 */ 1605 */
1589 abstract class ComplexParserTestMixin implements AbstractParserTestCase { 1606 abstract class ComplexParserTestMixin implements AbstractParserTestCase {
1590 void test_additiveExpression_normal() { 1607 void test_additiveExpression_normal() {
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
1809 BinaryExpression, expression.condition); 1826 BinaryExpression, expression.condition);
1810 } 1827 }
1811 1828
1812 void test_conditionalExpression_precedence_logicalOrExpression() { 1829 void test_conditionalExpression_precedence_logicalOrExpression() {
1813 ConditionalExpression expression = parseExpression("a | b ? y : z"); 1830 ConditionalExpression expression = parseExpression("a | b ? y : z");
1814 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, 1831 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
1815 BinaryExpression, expression.condition); 1832 BinaryExpression, expression.condition);
1816 } 1833 }
1817 1834
1818 void test_conditionalExpression_precedence_nullableType_as() { 1835 void test_conditionalExpression_precedence_nullableType_as() {
1819 enableNnbd = true;
1820 Expression expression = parseExpression('x as String ? (x + y) : z'); 1836 Expression expression = parseExpression('x as String ? (x + y) : z');
1821 expect(expression, isNotNull); 1837 expect(expression, isNotNull);
1822 expect(expression, new isInstanceOf<ConditionalExpression>()); 1838 expect(expression, new isInstanceOf<ConditionalExpression>());
1823 ConditionalExpression conditional = expression; 1839 ConditionalExpression conditional = expression;
1824 Expression condition = conditional.condition; 1840 Expression condition = conditional.condition;
1825 expect(condition, new isInstanceOf<AsExpression>()); 1841 expect(condition, new isInstanceOf<AsExpression>());
1826 Expression thenExpression = conditional.thenExpression; 1842 Expression thenExpression = conditional.thenExpression;
1827 expect(thenExpression, new isInstanceOf<ParenthesizedExpression>()); 1843 expect(thenExpression, new isInstanceOf<ParenthesizedExpression>());
1828 Expression elseExpression = conditional.elseExpression; 1844 Expression elseExpression = conditional.elseExpression;
1829 expect(elseExpression, new isInstanceOf<SimpleIdentifier>()); 1845 expect(elseExpression, new isInstanceOf<SimpleIdentifier>());
1830 } 1846 }
1831 1847
1832 void test_conditionalExpression_precedence_nullableType_is() { 1848 void test_conditionalExpression_precedence_nullableType_is() {
1833 enableNnbd = true;
1834 Expression expression = parseExpression('x is String ? (x + y) : z'); 1849 Expression expression = parseExpression('x is String ? (x + y) : z');
1835 expect(expression, isNotNull); 1850 expect(expression, isNotNull);
1836 expect(expression, new isInstanceOf<ConditionalExpression>()); 1851 expect(expression, new isInstanceOf<ConditionalExpression>());
1837 ConditionalExpression conditional = expression; 1852 ConditionalExpression conditional = expression;
1838 Expression condition = conditional.condition; 1853 Expression condition = conditional.condition;
1839 expect(condition, new isInstanceOf<IsExpression>()); 1854 expect(condition, new isInstanceOf<IsExpression>());
1840 Expression thenExpression = conditional.thenExpression; 1855 Expression thenExpression = conditional.thenExpression;
1841 expect(thenExpression, new isInstanceOf<ParenthesizedExpression>()); 1856 expect(thenExpression, new isInstanceOf<ParenthesizedExpression>());
1842 Expression elseExpression = conditional.elseExpression; 1857 Expression elseExpression = conditional.elseExpression;
1843 expect(elseExpression, new isInstanceOf<SimpleIdentifier>()); 1858 expect(elseExpression, new isInstanceOf<SimpleIdentifier>());
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1906 void test_logicalAndExpression_precedence_bitwiseOr_left() { 1921 void test_logicalAndExpression_precedence_bitwiseOr_left() {
1907 BinaryExpression expression = parseExpression("x | y < z"); 1922 BinaryExpression expression = parseExpression("x | y < z");
1908 expect(expression.leftOperand, new isInstanceOf<BinaryExpression>()); 1923 expect(expression.leftOperand, new isInstanceOf<BinaryExpression>());
1909 } 1924 }
1910 1925
1911 void test_logicalAndExpression_precedence_bitwiseOr_right() { 1926 void test_logicalAndExpression_precedence_bitwiseOr_right() {
1912 BinaryExpression expression = parseExpression("x < y | z"); 1927 BinaryExpression expression = parseExpression("x < y | z");
1913 expect(expression.rightOperand, new isInstanceOf<BinaryExpression>()); 1928 expect(expression.rightOperand, new isInstanceOf<BinaryExpression>());
1914 } 1929 }
1915 1930
1916 void test_logicalAndExpression_precedence_nullableType() {
1917 enableNnbd = true;
1918 BinaryExpression expression = parseExpression("x is C? && y is D");
1919 expect(expression.leftOperand, new isInstanceOf<IsExpression>());
1920 expect(expression.rightOperand, new isInstanceOf<IsExpression>());
1921 }
1922
1923 void test_logicalOrExpression() { 1931 void test_logicalOrExpression() {
1924 BinaryExpression expression = parseExpression("x || y || z"); 1932 BinaryExpression expression = parseExpression("x || y || z");
1925 expect(expression.leftOperand, new isInstanceOf<BinaryExpression>()); 1933 expect(expression.leftOperand, new isInstanceOf<BinaryExpression>());
1926 } 1934 }
1927 1935
1928 void test_logicalOrExpression_precedence_logicalAnd_left() { 1936 void test_logicalOrExpression_precedence_logicalAnd_left() {
1929 BinaryExpression expression = parseExpression("x && y || z"); 1937 BinaryExpression expression = parseExpression("x && y || z");
1930 expect(expression.leftOperand, new isInstanceOf<BinaryExpression>()); 1938 expect(expression.leftOperand, new isInstanceOf<BinaryExpression>());
1931 } 1939 }
1932 1940
1933 void test_logicalOrExpression_precedence_logicalAnd_right() { 1941 void test_logicalOrExpression_precedence_logicalAnd_right() {
1934 BinaryExpression expression = parseExpression("x || y && z"); 1942 BinaryExpression expression = parseExpression("x || y && z");
1935 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, 1943 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
1936 BinaryExpression, expression.rightOperand); 1944 BinaryExpression, expression.rightOperand);
1937 } 1945 }
1938 1946
1939 void test_logicalOrExpression_precedence_nullableType() {
1940 enableNnbd = true;
1941 BinaryExpression expression = parseExpression("a is X? || (b ? c : d)");
1942 expect(expression.leftOperand, new isInstanceOf<IsExpression>());
1943 expect(
1944 expression.rightOperand, new isInstanceOf<ParenthesizedExpression>());
1945 expect((expression.rightOperand as ParenthesizedExpression).expression,
1946 new isInstanceOf<ConditionalExpression>());
1947 }
1948
1949 void test_multipleLabels_statement() { 1947 void test_multipleLabels_statement() {
1950 LabeledStatement statement = parseStatement("a: b: c: return x;"); 1948 LabeledStatement statement = parseStatement("a: b: c: return x;");
1951 expect(statement.labels, hasLength(3)); 1949 expect(statement.labels, hasLength(3));
1952 EngineTestCase.assertInstanceOf( 1950 EngineTestCase.assertInstanceOf(
1953 (obj) => obj is ReturnStatement, ReturnStatement, statement.statement); 1951 (obj) => obj is ReturnStatement, ReturnStatement, statement.statement);
1954 } 1952 }
1955 1953
1956 void test_multiplicativeExpression_normal() { 1954 void test_multiplicativeExpression_normal() {
1957 BinaryExpression expression = parseExpression("x * y / z"); 1955 BinaryExpression expression = parseExpression("x * y / z");
1958 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, 1956 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
2058 expect(argumentList4.arguments, hasLength(1)); 2056 expect(argumentList4.arguments, hasLength(1));
2059 } 2057 }
2060 } 2058 }
2061 2059
2062 /** 2060 /**
2063 * The class `ErrorParserTest` defines parser tests that test the parsing 2061 * The class `ErrorParserTest` defines parser tests that test the parsing
2064 * of code to ensure that errors are correctly reported, 2062 * of code to ensure that errors are correctly reported,
2065 * and in some cases, not reported. 2063 * and in some cases, not reported.
2066 */ 2064 */
2067 @reflectiveTest 2065 @reflectiveTest
2068 class ErrorParserTest extends ParserTestCase with ErrorParserTestMixin {} 2066 class ErrorParserTest extends ParserTestCase with ErrorParserTestMixin {
2067 void test_nullableTypeInExtends() {
2068 enableNnbd = true;
2069 createParser('extends B?');
2070 ExtendsClause clause = parser.parseExtendsClause();
2071 expectNotNullIfNoErrors(clause);
2072 listener.assertErrorsWithCodes([ParserErrorCode.NULLABLE_TYPE_IN_EXTENDS]);
2073 }
2074
2075 void test_nullableTypeInImplements() {
2076 enableNnbd = true;
2077 createParser('implements I?');
2078 ImplementsClause clause = parser.parseImplementsClause();
2079 expectNotNullIfNoErrors(clause);
2080 listener
2081 .assertErrorsWithCodes([ParserErrorCode.NULLABLE_TYPE_IN_IMPLEMENTS]);
2082 }
2083
2084 void test_nullableTypeInWith() {
2085 enableNnbd = true;
2086 createParser('with M?');
2087 WithClause clause = parser.parseWithClause();
2088 expectNotNullIfNoErrors(clause);
2089 listener.assertErrorsWithCodes([ParserErrorCode.NULLABLE_TYPE_IN_WITH]);
2090 }
2091
2092 void test_nullableTypeParameter() {
2093 enableNnbd = true;
2094 createParser('T?');
2095 TypeParameter parameter = parser.parseTypeParameter();
2096 expectNotNullIfNoErrors(parameter);
2097 listener.assertErrorsWithCodes([ParserErrorCode.NULLABLE_TYPE_PARAMETER]);
2098 }
2099 }
2069 2100
2070 abstract class ErrorParserTestMixin implements AbstractParserTestCase { 2101 abstract class ErrorParserTestMixin implements AbstractParserTestCase {
2071 void test_abstractClassMember_constructor() { 2102 void test_abstractClassMember_constructor() {
2072 createParser('abstract C.c();'); 2103 createParser('abstract C.c();');
2073 ClassMember member = parser.parseClassMember('C'); 2104 ClassMember member = parser.parseClassMember('C');
2074 expectNotNullIfNoErrors(member); 2105 expectNotNullIfNoErrors(member);
2075 assertErrorsWithCodes([ParserErrorCode.ABSTRACT_CLASS_MEMBER]); 2106 assertErrorsWithCodes([ParserErrorCode.ABSTRACT_CLASS_MEMBER]);
2076 } 2107 }
2077 2108
2078 void test_abstractClassMember_field() { 2109 void test_abstractClassMember_field() {
(...skipping 1814 matching lines...) Expand 10 before | Expand all | Expand 10 after
3893 } 3924 }
3894 3925
3895 void test_nonUserDefinableOperator() { 3926 void test_nonUserDefinableOperator() {
3896 createParser('operator +=(int x) => x + 1;'); 3927 createParser('operator +=(int x) => x + 1;');
3897 ClassMember member = parser.parseClassMember('C'); 3928 ClassMember member = parser.parseClassMember('C');
3898 expectNotNullIfNoErrors(member); 3929 expectNotNullIfNoErrors(member);
3899 listener 3930 listener
3900 .assertErrorsWithCodes([ParserErrorCode.NON_USER_DEFINABLE_OPERATOR]); 3931 .assertErrorsWithCodes([ParserErrorCode.NON_USER_DEFINABLE_OPERATOR]);
3901 } 3932 }
3902 3933
3903 void test_nullableTypeInExtends() {
3904 enableNnbd = true;
3905 createParser('extends B?');
3906 ExtendsClause clause = parser.parseExtendsClause();
3907 expectNotNullIfNoErrors(clause);
3908 listener.assertErrorsWithCodes([ParserErrorCode.NULLABLE_TYPE_IN_EXTENDS]);
3909 }
3910
3911 void test_nullableTypeInImplements() {
3912 enableNnbd = true;
3913 createParser('implements I?');
3914 ImplementsClause clause = parser.parseImplementsClause();
3915 expectNotNullIfNoErrors(clause);
3916 listener
3917 .assertErrorsWithCodes([ParserErrorCode.NULLABLE_TYPE_IN_IMPLEMENTS]);
3918 }
3919
3920 void test_nullableTypeInWith() {
3921 enableNnbd = true;
3922 createParser('with M?');
3923 WithClause clause = parser.parseWithClause();
3924 expectNotNullIfNoErrors(clause);
3925 listener.assertErrorsWithCodes([ParserErrorCode.NULLABLE_TYPE_IN_WITH]);
3926 }
3927
3928 void test_nullableTypeParameter() {
3929 enableNnbd = true;
3930 createParser('T?');
3931 TypeParameter parameter = parser.parseTypeParameter();
3932 expectNotNullIfNoErrors(parameter);
3933 listener.assertErrorsWithCodes([ParserErrorCode.NULLABLE_TYPE_PARAMETER]);
3934 }
3935
3936 void test_optionalAfterNormalParameters_named() { 3934 void test_optionalAfterNormalParameters_named() {
3937 parseCompilationUnit( 3935 parseCompilationUnit(
3938 "f({a}, b) {}", [ParserErrorCode.NORMAL_BEFORE_OPTIONAL_PARAMETERS]); 3936 "f({a}, b) {}", [ParserErrorCode.NORMAL_BEFORE_OPTIONAL_PARAMETERS]);
3939 } 3937 }
3940 3938
3941 void test_optionalAfterNormalParameters_positional() { 3939 void test_optionalAfterNormalParameters_positional() {
3942 parseCompilationUnit( 3940 parseCompilationUnit(
3943 "f([a], b) {}", [ParserErrorCode.NORMAL_BEFORE_OPTIONAL_PARAMETERS]); 3941 "f([a], b) {}", [ParserErrorCode.NORMAL_BEFORE_OPTIONAL_PARAMETERS]);
3944 } 3942 }
3945 3943
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
4516 // fasta scanner generates '(a, [b, c}])' where ']' is synthetic 4514 // fasta scanner generates '(a, [b, c}])' where ']' is synthetic
4517 ParserErrorCode.WRONG_TERMINATOR_FOR_PARAMETER_GROUP, 4515 ParserErrorCode.WRONG_TERMINATOR_FOR_PARAMETER_GROUP,
4518 ScannerErrorCode.EXPECTED_TOKEN, 4516 ScannerErrorCode.EXPECTED_TOKEN,
4519 ] 4517 ]
4520 : [ParserErrorCode.WRONG_TERMINATOR_FOR_PARAMETER_GROUP]); 4518 : [ParserErrorCode.WRONG_TERMINATOR_FOR_PARAMETER_GROUP]);
4521 } 4519 }
4522 } 4520 }
4523 4521
4524 @reflectiveTest 4522 @reflectiveTest
4525 class ExpressionParserTest extends ParserTestCase 4523 class ExpressionParserTest extends ParserTestCase
4526 with ExpressionParserTestMixin {} 4524 with ExpressionParserTestMixin {
4525 void test_parseInstanceCreationExpression_type_typeArguments_nullable() {
4526 enableNnbd = true;
4527 Token token = TokenFactory.tokenFromKeyword(Keyword.NEW);
4528 InstanceCreationExpression expression =
4529 parseInstanceCreationExpression('A<B?>()', token);
4530 expect(expression, isNotNull);
4531 assertNoErrors();
4532 expect(expression.keyword.keyword, Keyword.NEW);
4533 ConstructorName name = expression.constructorName;
4534 expect(name, isNotNull);
4535 TypeName type = name.type;
4536 expect(type, isNotNull);
4537 expect(name.period, isNull);
4538 expect(name.name, isNull);
4539 expect(expression.argumentList, isNotNull);
4540 NodeList<TypeAnnotation> arguments = type.typeArguments.arguments;
4541 expect(arguments, hasLength(1));
4542 expect((arguments[0] as TypeName).question, isNotNull);
4543 }
4544
4545 void test_parseRelationalExpression_as_nullable() {
4546 enableNnbd = true;
4547 Expression expression = parseRelationalExpression('x as Y?)');
4548 expect(expression, isNotNull);
4549 assertNoErrors();
4550 var asExpression = expression as AsExpression;
4551 expect(asExpression.expression, isNotNull);
4552 expect(asExpression.asOperator, isNotNull);
4553 expect(asExpression.type, new isInstanceOf<TypeName>());
4554 }
4555
4556 void test_parseRelationalExpression_is_nullable() {
4557 enableNnbd = true;
4558 Expression expression = parseRelationalExpression('x is y?)');
4559 expect(expression, isNotNull);
4560 assertNoErrors();
4561 var isExpression = expression as IsExpression;
4562 expect(isExpression.expression, isNotNull);
4563 expect(isExpression.isOperator, isNotNull);
4564 expect(isExpression.notOperator, isNull);
4565 expect(isExpression.type, isNotNull);
4566 }
4567 }
4527 4568
4528 abstract class ExpressionParserTestMixin implements AbstractParserTestCase { 4569 abstract class ExpressionParserTestMixin implements AbstractParserTestCase {
4529 void test_namedArgument() { 4570 void test_namedArgument() {
4530 var invocation = parseExpression('m(a: 1, b: 2)') as MethodInvocation; 4571 var invocation = parseExpression('m(a: 1, b: 2)') as MethodInvocation;
4531 List<Expression> arguments = invocation.argumentList.arguments; 4572 List<Expression> arguments = invocation.argumentList.arguments;
4532 4573
4533 var a = arguments[0] as NamedExpression; 4574 var a = arguments[0] as NamedExpression;
4534 expect(a.name.label.name, 'a'); 4575 expect(a.name.label.name, 'a');
4535 expect(a.expression, isNotNull); 4576 expect(a.expression, isNotNull);
4536 4577
(...skipping 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after
5770 ConstructorName name = expression.constructorName; 5811 ConstructorName name = expression.constructorName;
5771 expect(name, isNotNull); 5812 expect(name, isNotNull);
5772 TypeName type = name.type; 5813 TypeName type = name.type;
5773 expect(type, isNotNull); 5814 expect(type, isNotNull);
5774 expect(type.typeArguments.arguments, hasLength(1)); 5815 expect(type.typeArguments.arguments, hasLength(1));
5775 expect(name.period, isNull); 5816 expect(name.period, isNull);
5776 expect(name.name, isNull); 5817 expect(name.name, isNull);
5777 expect(expression.argumentList, isNotNull); 5818 expect(expression.argumentList, isNotNull);
5778 } 5819 }
5779 5820
5780 void test_parseInstanceCreationExpression_type_typeArguments_nullable() {
5781 enableNnbd = true;
5782 Token token = TokenFactory.tokenFromKeyword(Keyword.NEW);
5783 InstanceCreationExpression expression =
5784 parseInstanceCreationExpression('A<B?>()', token);
5785 expect(expression, isNotNull);
5786 assertNoErrors();
5787 expect(expression.keyword.keyword, Keyword.NEW);
5788 ConstructorName name = expression.constructorName;
5789 expect(name, isNotNull);
5790 TypeName type = name.type;
5791 expect(type, isNotNull);
5792 expect(name.period, isNull);
5793 expect(name.name, isNull);
5794 expect(expression.argumentList, isNotNull);
5795 NodeList<TypeAnnotation> arguments = type.typeArguments.arguments;
5796 expect(arguments, hasLength(1));
5797 expect((arguments[0] as TypeName).question, isNotNull);
5798 }
5799
5800 void test_parseListLiteral_empty_oneToken() { 5821 void test_parseListLiteral_empty_oneToken() {
5801 Token token = TokenFactory.tokenFromKeyword(Keyword.CONST); 5822 Token token = TokenFactory.tokenFromKeyword(Keyword.CONST);
5802 ListLiteral literal = parseListLiteral(token, null, '[]'); 5823 ListLiteral literal = parseListLiteral(token, null, '[]');
5803 expect(literal, isNotNull); 5824 expect(literal, isNotNull);
5804 assertNoErrors(); 5825 assertNoErrors();
5805 expect(literal.constKeyword.keyword, Keyword.CONST); 5826 expect(literal.constKeyword.keyword, Keyword.CONST);
5806 expect(literal.typeArguments, isNull); 5827 expect(literal.typeArguments, isNull);
5807 expect(literal.leftBracket, isNotNull); 5828 expect(literal.leftBracket, isNotNull);
5808 expect(literal.elements, hasLength(0)); 5829 expect(literal.elements, hasLength(0));
5809 expect(literal.rightBracket, isNotNull); 5830 expect(literal.rightBracket, isNotNull);
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after
6453 void test_parseRelationalExpression_as_generic() { 6474 void test_parseRelationalExpression_as_generic() {
6454 Expression expression = parseRelationalExpression('x as C<D>'); 6475 Expression expression = parseRelationalExpression('x as C<D>');
6455 expect(expression, isNotNull); 6476 expect(expression, isNotNull);
6456 assertNoErrors(); 6477 assertNoErrors();
6457 var asExpression = expression as AsExpression; 6478 var asExpression = expression as AsExpression;
6458 expect(asExpression.expression, isNotNull); 6479 expect(asExpression.expression, isNotNull);
6459 expect(asExpression.asOperator, isNotNull); 6480 expect(asExpression.asOperator, isNotNull);
6460 expect(asExpression.type, new isInstanceOf<TypeName>()); 6481 expect(asExpression.type, new isInstanceOf<TypeName>());
6461 } 6482 }
6462 6483
6463 void test_parseRelationalExpression_as_nullable() {
6464 enableNnbd = true;
6465 Expression expression = parseRelationalExpression('x as Y?)');
6466 expect(expression, isNotNull);
6467 assertNoErrors();
6468 var asExpression = expression as AsExpression;
6469 expect(asExpression.expression, isNotNull);
6470 expect(asExpression.asOperator, isNotNull);
6471 expect(asExpression.type, new isInstanceOf<TypeName>());
6472 }
6473
6474 void test_parseRelationalExpression_as_simple() { 6484 void test_parseRelationalExpression_as_simple() {
6475 Expression expression = parseRelationalExpression('x as Y'); 6485 Expression expression = parseRelationalExpression('x as Y');
6476 expect(expression, isNotNull); 6486 expect(expression, isNotNull);
6477 assertNoErrors(); 6487 assertNoErrors();
6478 var asExpression = expression as AsExpression; 6488 var asExpression = expression as AsExpression;
6479 expect(asExpression.expression, isNotNull); 6489 expect(asExpression.expression, isNotNull);
6480 expect(asExpression.asOperator, isNotNull); 6490 expect(asExpression.asOperator, isNotNull);
6481 expect(asExpression.type, new isInstanceOf<TypeName>()); 6491 expect(asExpression.type, new isInstanceOf<TypeName>());
6482 } 6492 }
6483 6493
(...skipping 11 matching lines...) Expand all
6495 Expression expression = parseRelationalExpression('x is y'); 6505 Expression expression = parseRelationalExpression('x is y');
6496 expect(expression, isNotNull); 6506 expect(expression, isNotNull);
6497 assertNoErrors(); 6507 assertNoErrors();
6498 var isExpression = expression as IsExpression; 6508 var isExpression = expression as IsExpression;
6499 expect(isExpression.expression, isNotNull); 6509 expect(isExpression.expression, isNotNull);
6500 expect(isExpression.isOperator, isNotNull); 6510 expect(isExpression.isOperator, isNotNull);
6501 expect(isExpression.notOperator, isNull); 6511 expect(isExpression.notOperator, isNull);
6502 expect(isExpression.type, isNotNull); 6512 expect(isExpression.type, isNotNull);
6503 } 6513 }
6504 6514
6505 void test_parseRelationalExpression_is_nullable() {
6506 enableNnbd = true;
6507 Expression expression = parseRelationalExpression('x is y?)');
6508 expect(expression, isNotNull);
6509 assertNoErrors();
6510 var isExpression = expression as IsExpression;
6511 expect(isExpression.expression, isNotNull);
6512 expect(isExpression.isOperator, isNotNull);
6513 expect(isExpression.notOperator, isNull);
6514 expect(isExpression.type, isNotNull);
6515 }
6516
6517 void test_parseRelationalExpression_isNot() { 6515 void test_parseRelationalExpression_isNot() {
6518 Expression expression = parseRelationalExpression('x is! y'); 6516 Expression expression = parseRelationalExpression('x is! y');
6519 expect(expression, isNotNull); 6517 expect(expression, isNotNull);
6520 assertNoErrors(); 6518 assertNoErrors();
6521 var isExpression = expression as IsExpression; 6519 var isExpression = expression as IsExpression;
6522 expect(isExpression.expression, isNotNull); 6520 expect(isExpression.expression, isNotNull);
6523 expect(isExpression.isOperator, isNotNull); 6521 expect(isExpression.isOperator, isNotNull);
6524 expect(isExpression.notOperator, isNotNull); 6522 expect(isExpression.notOperator, isNotNull);
6525 expect(isExpression.type, isNotNull); 6523 expect(isExpression.type, isNotNull);
6526 } 6524 }
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
7080 expect(expression.operator.type, TokenType.TILDE); 7078 expect(expression.operator.type, TokenType.TILDE);
7081 expect(expression.operand, isNotNull); 7079 expect(expression.operand, isNotNull);
7082 } 7080 }
7083 } 7081 }
7084 7082
7085 /** 7083 /**
7086 * Tests of the analyzer parser based on [FormalParameterParserTestMixin]. 7084 * Tests of the analyzer parser based on [FormalParameterParserTestMixin].
7087 */ 7085 */
7088 @reflectiveTest 7086 @reflectiveTest
7089 class FormalParameterParserTest extends ParserTestCase 7087 class FormalParameterParserTest extends ParserTestCase
7090 with FormalParameterParserTestMixin {} 7088 with FormalParameterParserTestMixin {
7089 void test_parseNormalFormalParameter_function_noType_nullable() {
7090 enableNnbd = true;
7091 NormalFormalParameter parameter = parseNormalFormalParameter('a()?');
7092 expect(parameter, isNotNull);
7093 assertNoErrors();
7094 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
7095 FunctionTypedFormalParameter functionParameter = parameter;
7096 expect(functionParameter.returnType, isNull);
7097 expect(functionParameter.identifier, isNotNull);
7098 expect(functionParameter.typeParameters, isNull);
7099 expect(functionParameter.parameters, isNotNull);
7100 expect(functionParameter.question, isNotNull);
7101 }
7102
7103 void
7104 test_parseNormalFormalParameter_function_noType_typeParameters_nullable() {
7105 enableNnbd = true;
7106 NormalFormalParameter parameter = parseNormalFormalParameter('a<E>()?');
7107 expect(parameter, isNotNull);
7108 assertNoErrors();
7109 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
7110 FunctionTypedFormalParameter functionParameter = parameter;
7111 expect(functionParameter.returnType, isNull);
7112 expect(functionParameter.identifier, isNotNull);
7113 expect(functionParameter.typeParameters, isNotNull);
7114 expect(functionParameter.parameters, isNotNull);
7115 expect(functionParameter.question, isNotNull);
7116 }
7117
7118 void test_parseNormalFormalParameter_function_type_nullable() {
7119 enableNnbd = true;
7120 NormalFormalParameter parameter = parseNormalFormalParameter('A a()?');
7121 expect(parameter, isNotNull);
7122 assertNoErrors();
7123 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
7124 FunctionTypedFormalParameter functionParameter = parameter;
7125 expect(functionParameter.returnType, isNotNull);
7126 expect(functionParameter.identifier, isNotNull);
7127 expect(functionParameter.typeParameters, isNull);
7128 expect(functionParameter.parameters, isNotNull);
7129 expect(functionParameter.question, isNotNull);
7130 }
7131
7132 void test_parseNormalFormalParameter_function_type_typeParameters_nullable() {
7133 enableNnbd = true;
7134 NormalFormalParameter parameter = parseNormalFormalParameter('A a<E>()?');
7135 expect(parameter, isNotNull);
7136 assertNoErrors();
7137 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
7138 FunctionTypedFormalParameter functionParameter = parameter;
7139 expect(functionParameter.returnType, isNotNull);
7140 expect(functionParameter.identifier, isNotNull);
7141 expect(functionParameter.typeParameters, isNotNull);
7142 expect(functionParameter.parameters, isNotNull);
7143 expect(functionParameter.question, isNotNull);
7144 }
7145
7146 void test_parseNormalFormalParameter_function_void_nullable() {
7147 enableNnbd = true;
7148 NormalFormalParameter parameter = parseNormalFormalParameter('void a()?');
7149 expect(parameter, isNotNull);
7150 assertNoErrors();
7151 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
7152 FunctionTypedFormalParameter functionParameter = parameter;
7153 expect(functionParameter.returnType, isNotNull);
7154 expect(functionParameter.identifier, isNotNull);
7155 expect(functionParameter.typeParameters, isNull);
7156 expect(functionParameter.parameters, isNotNull);
7157 expect(functionParameter.question, isNotNull);
7158 }
7159
7160 void test_parseNormalFormalParameter_function_void_typeParameters_nullable() {
7161 enableNnbd = true;
7162 NormalFormalParameter parameter =
7163 parseNormalFormalParameter('void a<E>()?');
7164 expect(parameter, isNotNull);
7165 assertNoErrors();
7166 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
7167 FunctionTypedFormalParameter functionParameter = parameter;
7168 expect(functionParameter.returnType, isNotNull);
7169 expect(functionParameter.identifier, isNotNull);
7170 expect(functionParameter.typeParameters, isNotNull);
7171 expect(functionParameter.parameters, isNotNull);
7172 expect(functionParameter.question, isNotNull);
7173 }
7174 }
7091 7175
7092 /** 7176 /**
7093 * The class [FormalParameterParserTestMixin] defines parser tests that test 7177 * The class [FormalParameterParserTestMixin] defines parser tests that test
7094 * the parsing of formal parameters. 7178 * the parsing of formal parameters.
7095 */ 7179 */
7096 abstract class FormalParameterParserTestMixin 7180 abstract class FormalParameterParserTestMixin
7097 implements AbstractParserTestCase { 7181 implements AbstractParserTestCase {
7098 void test_parseFormalParameter_covariant_final_named() { 7182 void test_parseFormalParameter_covariant_final_named() {
7099 ParameterKind kind = ParameterKind.NAMED; 7183 ParameterKind kind = ParameterKind.NAMED;
7100 FormalParameter parameter = 7184 FormalParameter parameter =
(...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after
7974 assertNoErrors(); 8058 assertNoErrors();
7975 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); 8059 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
7976 FunctionTypedFormalParameter functionParameter = parameter; 8060 FunctionTypedFormalParameter functionParameter = parameter;
7977 expect(functionParameter.covariantKeyword, isNotNull); 8061 expect(functionParameter.covariantKeyword, isNotNull);
7978 expect(functionParameter.returnType, isNull); 8062 expect(functionParameter.returnType, isNull);
7979 expect(functionParameter.identifier, isNotNull); 8063 expect(functionParameter.identifier, isNotNull);
7980 expect(functionParameter.typeParameters, isNull); 8064 expect(functionParameter.typeParameters, isNull);
7981 expect(functionParameter.parameters, isNotNull); 8065 expect(functionParameter.parameters, isNotNull);
7982 } 8066 }
7983 8067
7984 void test_parseNormalFormalParameter_function_noType_nullable() {
7985 enableNnbd = true;
7986 NormalFormalParameter parameter = parseNormalFormalParameter('a()?');
7987 expect(parameter, isNotNull);
7988 assertNoErrors();
7989 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
7990 FunctionTypedFormalParameter functionParameter = parameter;
7991 expect(functionParameter.returnType, isNull);
7992 expect(functionParameter.identifier, isNotNull);
7993 expect(functionParameter.typeParameters, isNull);
7994 expect(functionParameter.parameters, isNotNull);
7995 expect(functionParameter.question, isNotNull);
7996 }
7997
7998 void test_parseNormalFormalParameter_function_noType_typeParameterComments() { 8068 void test_parseNormalFormalParameter_function_noType_typeParameterComments() {
7999 enableGenericMethodComments = true; 8069 enableGenericMethodComments = true;
8000 NormalFormalParameter parameter = parseNormalFormalParameter('a/*<E>*/()', 8070 NormalFormalParameter parameter = parseNormalFormalParameter('a/*<E>*/()',
8001 errorCodes: usingFastaParser ? [] : [HintCode.GENERIC_METHOD_COMMENT]); 8071 errorCodes: usingFastaParser ? [] : [HintCode.GENERIC_METHOD_COMMENT]);
8002 expect(parameter, isNotNull); 8072 expect(parameter, isNotNull);
8003 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); 8073 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
8004 FunctionTypedFormalParameter functionParameter = parameter; 8074 FunctionTypedFormalParameter functionParameter = parameter;
8005 expect(functionParameter.returnType, isNull); 8075 expect(functionParameter.returnType, isNull);
8006 expect(functionParameter.identifier, isNotNull); 8076 expect(functionParameter.identifier, isNotNull);
8007 expect(functionParameter.typeParameters, isNotNull); 8077 expect(functionParameter.typeParameters, isNotNull);
8008 expect(functionParameter.parameters, isNotNull); 8078 expect(functionParameter.parameters, isNotNull);
8009 } 8079 }
8010 8080
8011 void test_parseNormalFormalParameter_function_noType_typeParameters() { 8081 void test_parseNormalFormalParameter_function_noType_typeParameters() {
8012 NormalFormalParameter parameter = parseNormalFormalParameter('a<E>()'); 8082 NormalFormalParameter parameter = parseNormalFormalParameter('a<E>()');
8013 expect(parameter, isNotNull); 8083 expect(parameter, isNotNull);
8014 assertNoErrors(); 8084 assertNoErrors();
8015 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); 8085 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
8016 FunctionTypedFormalParameter functionParameter = parameter; 8086 FunctionTypedFormalParameter functionParameter = parameter;
8017 expect(functionParameter.returnType, isNull); 8087 expect(functionParameter.returnType, isNull);
8018 expect(functionParameter.identifier, isNotNull); 8088 expect(functionParameter.identifier, isNotNull);
8019 expect(functionParameter.typeParameters, isNotNull); 8089 expect(functionParameter.typeParameters, isNotNull);
8020 expect(functionParameter.parameters, isNotNull); 8090 expect(functionParameter.parameters, isNotNull);
8021 expect(functionParameter.question, isNull); 8091 expect(functionParameter.question, isNull);
8022 expect(functionParameter.question, isNull); 8092 expect(functionParameter.question, isNull);
8023 } 8093 }
8024 8094
8025 void
8026 test_parseNormalFormalParameter_function_noType_typeParameters_nullable() {
8027 enableNnbd = true;
8028 NormalFormalParameter parameter = parseNormalFormalParameter('a<E>()?');
8029 expect(parameter, isNotNull);
8030 assertNoErrors();
8031 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
8032 FunctionTypedFormalParameter functionParameter = parameter;
8033 expect(functionParameter.returnType, isNull);
8034 expect(functionParameter.identifier, isNotNull);
8035 expect(functionParameter.typeParameters, isNotNull);
8036 expect(functionParameter.parameters, isNotNull);
8037 expect(functionParameter.question, isNotNull);
8038 }
8039
8040 void test_parseNormalFormalParameter_function_type() { 8095 void test_parseNormalFormalParameter_function_type() {
8041 NormalFormalParameter parameter = parseNormalFormalParameter('A a()'); 8096 NormalFormalParameter parameter = parseNormalFormalParameter('A a()');
8042 expect(parameter, isNotNull); 8097 expect(parameter, isNotNull);
8043 assertNoErrors(); 8098 assertNoErrors();
8044 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); 8099 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
8045 FunctionTypedFormalParameter functionParameter = parameter; 8100 FunctionTypedFormalParameter functionParameter = parameter;
8046 expect(functionParameter.returnType, isNotNull); 8101 expect(functionParameter.returnType, isNotNull);
8047 expect(functionParameter.identifier, isNotNull); 8102 expect(functionParameter.identifier, isNotNull);
8048 expect(functionParameter.typeParameters, isNull); 8103 expect(functionParameter.typeParameters, isNull);
8049 expect(functionParameter.parameters, isNotNull); 8104 expect(functionParameter.parameters, isNotNull);
8050 expect(functionParameter.question, isNull); 8105 expect(functionParameter.question, isNull);
8051 } 8106 }
8052 8107
8053 void test_parseNormalFormalParameter_function_type_nullable() {
8054 enableNnbd = true;
8055 NormalFormalParameter parameter = parseNormalFormalParameter('A a()?');
8056 expect(parameter, isNotNull);
8057 assertNoErrors();
8058 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
8059 FunctionTypedFormalParameter functionParameter = parameter;
8060 expect(functionParameter.returnType, isNotNull);
8061 expect(functionParameter.identifier, isNotNull);
8062 expect(functionParameter.typeParameters, isNull);
8063 expect(functionParameter.parameters, isNotNull);
8064 expect(functionParameter.question, isNotNull);
8065 }
8066
8067 void test_parseNormalFormalParameter_function_type_typeParameterComments() { 8108 void test_parseNormalFormalParameter_function_type_typeParameterComments() {
8068 enableGenericMethodComments = true; 8109 enableGenericMethodComments = true;
8069 NormalFormalParameter parameter = parseNormalFormalParameter('A a/*<E>*/()', 8110 NormalFormalParameter parameter = parseNormalFormalParameter('A a/*<E>*/()',
8070 errorCodes: usingFastaParser ? [] : [HintCode.GENERIC_METHOD_COMMENT]); 8111 errorCodes: usingFastaParser ? [] : [HintCode.GENERIC_METHOD_COMMENT]);
8071 expect(parameter, isNotNull); 8112 expect(parameter, isNotNull);
8072 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); 8113 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
8073 FunctionTypedFormalParameter functionParameter = parameter; 8114 FunctionTypedFormalParameter functionParameter = parameter;
8074 expect(functionParameter.returnType, isNotNull); 8115 expect(functionParameter.returnType, isNotNull);
8075 expect(functionParameter.identifier, isNotNull); 8116 expect(functionParameter.identifier, isNotNull);
8076 expect(functionParameter.typeParameters, isNotNull); 8117 expect(functionParameter.typeParameters, isNotNull);
8077 expect(functionParameter.parameters, isNotNull); 8118 expect(functionParameter.parameters, isNotNull);
8078 expect(functionParameter.question, isNull); 8119 expect(functionParameter.question, isNull);
8079 } 8120 }
8080 8121
8081 void test_parseNormalFormalParameter_function_type_typeParameters() { 8122 void test_parseNormalFormalParameter_function_type_typeParameters() {
8082 NormalFormalParameter parameter = parseNormalFormalParameter('A a<E>()'); 8123 NormalFormalParameter parameter = parseNormalFormalParameter('A a<E>()');
8083 expect(parameter, isNotNull); 8124 expect(parameter, isNotNull);
8084 assertNoErrors(); 8125 assertNoErrors();
8085 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); 8126 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
8086 FunctionTypedFormalParameter functionParameter = parameter; 8127 FunctionTypedFormalParameter functionParameter = parameter;
8087 expect(functionParameter.returnType, isNotNull); 8128 expect(functionParameter.returnType, isNotNull);
8088 expect(functionParameter.identifier, isNotNull); 8129 expect(functionParameter.identifier, isNotNull);
8089 expect(functionParameter.typeParameters, isNotNull); 8130 expect(functionParameter.typeParameters, isNotNull);
8090 expect(functionParameter.parameters, isNotNull); 8131 expect(functionParameter.parameters, isNotNull);
8091 expect(functionParameter.question, isNull); 8132 expect(functionParameter.question, isNull);
8092 } 8133 }
8093 8134
8094 void test_parseNormalFormalParameter_function_type_typeParameters_nullable() {
8095 enableNnbd = true;
8096 NormalFormalParameter parameter = parseNormalFormalParameter('A a<E>()?');
8097 expect(parameter, isNotNull);
8098 assertNoErrors();
8099 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
8100 FunctionTypedFormalParameter functionParameter = parameter;
8101 expect(functionParameter.returnType, isNotNull);
8102 expect(functionParameter.identifier, isNotNull);
8103 expect(functionParameter.typeParameters, isNotNull);
8104 expect(functionParameter.parameters, isNotNull);
8105 expect(functionParameter.question, isNotNull);
8106 }
8107
8108 void test_parseNormalFormalParameter_function_void() { 8135 void test_parseNormalFormalParameter_function_void() {
8109 NormalFormalParameter parameter = parseNormalFormalParameter('void a()'); 8136 NormalFormalParameter parameter = parseNormalFormalParameter('void a()');
8110 expect(parameter, isNotNull); 8137 expect(parameter, isNotNull);
8111 assertNoErrors(); 8138 assertNoErrors();
8112 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); 8139 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
8113 FunctionTypedFormalParameter functionParameter = parameter; 8140 FunctionTypedFormalParameter functionParameter = parameter;
8114 expect(functionParameter.returnType, isNotNull); 8141 expect(functionParameter.returnType, isNotNull);
8115 expect(functionParameter.identifier, isNotNull); 8142 expect(functionParameter.identifier, isNotNull);
8116 expect(functionParameter.typeParameters, isNull); 8143 expect(functionParameter.typeParameters, isNull);
8117 expect(functionParameter.parameters, isNotNull); 8144 expect(functionParameter.parameters, isNotNull);
8118 expect(functionParameter.question, isNull); 8145 expect(functionParameter.question, isNull);
8119 } 8146 }
8120 8147
8121 void test_parseNormalFormalParameter_function_void_nullable() {
8122 enableNnbd = true;
8123 NormalFormalParameter parameter = parseNormalFormalParameter('void a()?');
8124 expect(parameter, isNotNull);
8125 assertNoErrors();
8126 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
8127 FunctionTypedFormalParameter functionParameter = parameter;
8128 expect(functionParameter.returnType, isNotNull);
8129 expect(functionParameter.identifier, isNotNull);
8130 expect(functionParameter.typeParameters, isNull);
8131 expect(functionParameter.parameters, isNotNull);
8132 expect(functionParameter.question, isNotNull);
8133 }
8134
8135 void test_parseNormalFormalParameter_function_void_typeParameterComments() { 8148 void test_parseNormalFormalParameter_function_void_typeParameterComments() {
8136 enableGenericMethodComments = true; 8149 enableGenericMethodComments = true;
8137 NormalFormalParameter parameter = parseNormalFormalParameter( 8150 NormalFormalParameter parameter = parseNormalFormalParameter(
8138 'void a/*<E>*/()', 8151 'void a/*<E>*/()',
8139 errorCodes: usingFastaParser ? [] : [HintCode.GENERIC_METHOD_COMMENT]); 8152 errorCodes: usingFastaParser ? [] : [HintCode.GENERIC_METHOD_COMMENT]);
8140 expect(parameter, isNotNull); 8153 expect(parameter, isNotNull);
8141 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); 8154 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
8142 FunctionTypedFormalParameter functionParameter = parameter; 8155 FunctionTypedFormalParameter functionParameter = parameter;
8143 expect(functionParameter.returnType, isNotNull); 8156 expect(functionParameter.returnType, isNotNull);
8144 expect(functionParameter.identifier, isNotNull); 8157 expect(functionParameter.identifier, isNotNull);
8145 expect(functionParameter.typeParameters, isNotNull); 8158 expect(functionParameter.typeParameters, isNotNull);
8146 expect(functionParameter.parameters, isNotNull); 8159 expect(functionParameter.parameters, isNotNull);
8147 expect(functionParameter.question, isNull); 8160 expect(functionParameter.question, isNull);
8148 } 8161 }
8149 8162
8150 void test_parseNormalFormalParameter_function_void_typeParameters() { 8163 void test_parseNormalFormalParameter_function_void_typeParameters() {
8151 NormalFormalParameter parameter = parseNormalFormalParameter('void a<E>()'); 8164 NormalFormalParameter parameter = parseNormalFormalParameter('void a<E>()');
8152 expect(parameter, isNotNull); 8165 expect(parameter, isNotNull);
8153 assertNoErrors(); 8166 assertNoErrors();
8154 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>()); 8167 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
8155 FunctionTypedFormalParameter functionParameter = parameter; 8168 FunctionTypedFormalParameter functionParameter = parameter;
8156 expect(functionParameter.returnType, isNotNull); 8169 expect(functionParameter.returnType, isNotNull);
8157 expect(functionParameter.identifier, isNotNull); 8170 expect(functionParameter.identifier, isNotNull);
8158 expect(functionParameter.typeParameters, isNotNull); 8171 expect(functionParameter.typeParameters, isNotNull);
8159 expect(functionParameter.parameters, isNotNull); 8172 expect(functionParameter.parameters, isNotNull);
8160 expect(functionParameter.question, isNull); 8173 expect(functionParameter.question, isNull);
8161 } 8174 }
8162 8175
8163 void test_parseNormalFormalParameter_function_void_typeParameters_nullable() {
8164 enableNnbd = true;
8165 NormalFormalParameter parameter =
8166 parseNormalFormalParameter('void a<E>()?');
8167 expect(parameter, isNotNull);
8168 assertNoErrors();
8169 expect(parameter, new isInstanceOf<FunctionTypedFormalParameter>());
8170 FunctionTypedFormalParameter functionParameter = parameter;
8171 expect(functionParameter.returnType, isNotNull);
8172 expect(functionParameter.identifier, isNotNull);
8173 expect(functionParameter.typeParameters, isNotNull);
8174 expect(functionParameter.parameters, isNotNull);
8175 expect(functionParameter.question, isNotNull);
8176 }
8177
8178 void test_parseNormalFormalParameter_function_withDocComment() { 8176 void test_parseNormalFormalParameter_function_withDocComment() {
8179 var parameter = parseFormalParameter('/// Doc\nf()', ParameterKind.REQUIRED) 8177 var parameter = parseFormalParameter('/// Doc\nf()', ParameterKind.REQUIRED)
8180 as FunctionTypedFormalParameter; 8178 as FunctionTypedFormalParameter;
8181 expectCommentText(parameter.documentationComment, '/// Doc'); 8179 expectCommentText(parameter.documentationComment, '/// Doc');
8182 } 8180 }
8183 8181
8184 void test_parseNormalFormalParameter_simple_const_noType() { 8182 void test_parseNormalFormalParameter_simple_const_noType() {
8185 NormalFormalParameter parameter = parseNormalFormalParameter('const a'); 8183 NormalFormalParameter parameter = parseNormalFormalParameter('const a');
8186 expect(parameter, isNotNull); 8184 expect(parameter, isNotNull);
8187 if (usingFastaParser) { 8185 if (usingFastaParser) {
(...skipping 2614 matching lines...) Expand 10 before | Expand all | Expand 10 after
10802 FunctionBody functionBody = parser.parseFunctionBody(false, null, false); 10800 FunctionBody functionBody = parser.parseFunctionBody(false, null, false);
10803 expectNotNullIfNoErrors(functionBody); 10801 expectNotNullIfNoErrors(functionBody);
10804 listener.assertNoErrors(); 10802 listener.assertNoErrors();
10805 expect(functionBody, new isInstanceOf<EmptyFunctionBody>()); 10803 expect(functionBody, new isInstanceOf<EmptyFunctionBody>());
10806 } 10804 }
10807 10805
10808 void test_Parser() { 10806 void test_Parser() {
10809 expect(new Parser(null, null), isNotNull); 10807 expect(new Parser(null, null), isNotNull);
10810 } 10808 }
10811 10809
10810 void test_parseTypeName_parameterized_nullable() {
10811 enableNnbd = true;
10812 createParser('List<int>?');
10813 TypeName typeName = parser.parseTypeName(false);
10814 expectNotNullIfNoErrors(typeName);
10815 listener.assertNoErrors();
10816 expect(typeName.name, isNotNull);
10817 expect(typeName.typeArguments, isNotNull);
10818 expect(typeName.question, isNotNull);
10819 }
10820
10821 void test_parseTypeName_simple_nullable() {
10822 enableNnbd = true;
10823 createParser('String?');
10824 TypeName typeName = parser.parseTypeName(false);
10825 expectNotNullIfNoErrors(typeName);
10826 listener.assertNoErrors();
10827 expect(typeName.name, isNotNull);
10828 expect(typeName.typeArguments, isNull);
10829 expect(typeName.question, isNotNull);
10830 }
10831
10832 void test_parseTypeParameter_bounded_nullable() {
10833 enableNnbd = true;
10834 createParser('A extends B?');
10835 TypeParameter parameter = parser.parseTypeParameter();
10836 expectNotNullIfNoErrors(parameter);
10837 listener.assertNoErrors();
10838 expect(parameter.bound, new isInstanceOf<TypeName>());
10839 expect(parameter.extendsKeyword, isNotNull);
10840 expect(parameter.name, isNotNull);
10841 TypeName bound = parameter.bound;
10842 expect(bound, isNotNull);
10843 expect(bound.question, isNotNull);
10844 }
10845
10812 void test_skipPrefixedIdentifier_invalid() { 10846 void test_skipPrefixedIdentifier_invalid() {
10813 createParser('+'); 10847 createParser('+');
10814 Token following = parser.skipPrefixedIdentifier(parser.currentToken); 10848 Token following = parser.skipPrefixedIdentifier(parser.currentToken);
10815 expect(following, isNull); 10849 expect(following, isNull);
10816 } 10850 }
10817 10851
10818 void test_skipPrefixedIdentifier_notPrefixed() { 10852 void test_skipPrefixedIdentifier_notPrefixed() {
10819 createParser('a +'); 10853 createParser('a +');
10820 Token following = parser.skipPrefixedIdentifier(parser.currentToken); 10854 Token following = parser.skipPrefixedIdentifier(parser.currentToken);
10821 expect(following, isNotNull); 10855 expect(following, isNotNull);
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
11100 Annotation annotation = parser.parseAnnotation(); 11134 Annotation annotation = parser.parseAnnotation();
11101 expectNotNullIfNoErrors(annotation); 11135 expectNotNullIfNoErrors(annotation);
11102 listener.assertNoErrors(); 11136 listener.assertNoErrors();
11103 expect(annotation.atSign, isNotNull); 11137 expect(annotation.atSign, isNotNull);
11104 expect(annotation.name, isNotNull); 11138 expect(annotation.name, isNotNull);
11105 expect(annotation.period, isNotNull); 11139 expect(annotation.period, isNotNull);
11106 expect(annotation.constructorName, isNotNull); 11140 expect(annotation.constructorName, isNotNull);
11107 expect(annotation.arguments, isNotNull); 11141 expect(annotation.arguments, isNotNull);
11108 } 11142 }
11109 11143
11110 void test_parseArgument_named() {
11111 createParser('n: x');
11112 Expression expression = parser.parseArgument();
11113 expectNotNullIfNoErrors(expression);
11114 listener.assertNoErrors();
11115 expect(expression, new isInstanceOf<NamedExpression>());
11116 NamedExpression namedExpression = expression;
11117 Label name = namedExpression.name;
11118 expect(name, isNotNull);
11119 expect(name.label, isNotNull);
11120 expect(name.colon, isNotNull);
11121 expect(namedExpression.expression, isNotNull);
11122 }
11123
11124 void test_parseArgument_unnamed() {
11125 String lexeme = "x";
11126 createParser(lexeme);
11127 Expression expression = parser.parseArgument();
11128 expectNotNullIfNoErrors(expression);
11129 listener.assertNoErrors();
11130 var identifier = expression as SimpleIdentifier;
11131 expect(identifier.name, lexeme);
11132 }
11133
11134 void test_parseArgumentList_empty() { 11144 void test_parseArgumentList_empty() {
11135 createParser('()'); 11145 createParser('()');
11136 ArgumentList argumentList = parser.parseArgumentList(); 11146 ArgumentList argumentList = parser.parseArgumentList();
11137 expectNotNullIfNoErrors(argumentList); 11147 expectNotNullIfNoErrors(argumentList);
11138 listener.assertNoErrors(); 11148 listener.assertNoErrors();
11139 NodeList<Expression> arguments = argumentList.arguments; 11149 NodeList<Expression> arguments = argumentList.arguments;
11140 expect(arguments, hasLength(0)); 11150 expect(arguments, hasLength(0));
11141 } 11151 }
11142 11152
11143 void test_parseArgumentList_mixed() { 11153 void test_parseArgumentList_mixed() {
(...skipping 25 matching lines...) Expand all
11169 11179
11170 void test_parseArgumentList_trailing_comma() { 11180 void test_parseArgumentList_trailing_comma() {
11171 createParser('(x, y, z,)'); 11181 createParser('(x, y, z,)');
11172 ArgumentList argumentList = parser.parseArgumentList(); 11182 ArgumentList argumentList = parser.parseArgumentList();
11173 expectNotNullIfNoErrors(argumentList); 11183 expectNotNullIfNoErrors(argumentList);
11174 listener.assertNoErrors(); 11184 listener.assertNoErrors();
11175 NodeList<Expression> arguments = argumentList.arguments; 11185 NodeList<Expression> arguments = argumentList.arguments;
11176 expect(arguments, hasLength(3)); 11186 expect(arguments, hasLength(3));
11177 } 11187 }
11178 11188
11179 void test_parseCombinator_hide() {
11180 createParser('hide a');
11181 Combinator combinator = parser.parseCombinator();
11182 expectNotNullIfNoErrors(combinator);
11183 listener.assertNoErrors();
11184 expect(combinator, new isInstanceOf<HideCombinator>());
11185 HideCombinator hideCombinator = combinator;
11186 expect(hideCombinator.keyword, isNotNull);
11187 expect(hideCombinator.hiddenNames, hasLength(1));
11188 }
11189
11190 void test_parseCombinator_show() {
11191 createParser('show a');
11192 Combinator combinator = parser.parseCombinator();
11193 expectNotNullIfNoErrors(combinator);
11194 listener.assertNoErrors();
11195 expect(combinator, new isInstanceOf<ShowCombinator>());
11196 ShowCombinator showCombinator = combinator;
11197 expect(showCombinator.keyword, isNotNull);
11198 expect(showCombinator.shownNames, hasLength(1));
11199 }
11200
11201 void test_parseCombinators_h() { 11189 void test_parseCombinators_h() {
11202 createParser('hide a'); 11190 createParser('hide a');
11203 List<Combinator> combinators = parser.parseCombinators(); 11191 List<Combinator> combinators = parser.parseCombinators();
11204 expectNotNullIfNoErrors(combinators); 11192 expectNotNullIfNoErrors(combinators);
11205 listener.assertNoErrors(); 11193 listener.assertNoErrors();
11206 expect(combinators, hasLength(1)); 11194 expect(combinators, hasLength(1));
11207 HideCombinator combinator = combinators[0] as HideCombinator; 11195 HideCombinator combinator = combinators[0] as HideCombinator;
11208 expect(combinator, isNotNull); 11196 expect(combinator, isNotNull);
11209 expect(combinator.keyword, isNotNull); 11197 expect(combinator.keyword, isNotNull);
11210 expect(combinator.hiddenNames, hasLength(1)); 11198 expect(combinator.hiddenNames, hasLength(1));
(...skipping 1048 matching lines...) Expand 10 before | Expand all | Expand 10 after
12259 void test_parseTypeName_parameterized() { 12247 void test_parseTypeName_parameterized() {
12260 createParser('List<int>'); 12248 createParser('List<int>');
12261 TypeName typeName = parser.parseTypeName(false); 12249 TypeName typeName = parser.parseTypeName(false);
12262 expectNotNullIfNoErrors(typeName); 12250 expectNotNullIfNoErrors(typeName);
12263 listener.assertNoErrors(); 12251 listener.assertNoErrors();
12264 expect(typeName.name, isNotNull); 12252 expect(typeName.name, isNotNull);
12265 expect(typeName.typeArguments, isNotNull); 12253 expect(typeName.typeArguments, isNotNull);
12266 expect(typeName.question, isNull); 12254 expect(typeName.question, isNull);
12267 } 12255 }
12268 12256
12269 void test_parseTypeName_parameterized_nullable() {
12270 enableNnbd = true;
12271 createParser('List<int>?');
12272 TypeName typeName = parser.parseTypeName(false);
12273 expectNotNullIfNoErrors(typeName);
12274 listener.assertNoErrors();
12275 expect(typeName.name, isNotNull);
12276 expect(typeName.typeArguments, isNotNull);
12277 expect(typeName.question, isNotNull);
12278 }
12279
12280 void test_parseTypeName_simple() { 12257 void test_parseTypeName_simple() {
12281 createParser('int'); 12258 createParser('int');
12282 TypeName typeName = parser.parseTypeName(false); 12259 TypeName typeName = parser.parseTypeName(false);
12283 expectNotNullIfNoErrors(typeName); 12260 expectNotNullIfNoErrors(typeName);
12284 listener.assertNoErrors(); 12261 listener.assertNoErrors();
12285 expect(typeName.name, isNotNull); 12262 expect(typeName.name, isNotNull);
12286 expect(typeName.typeArguments, isNull); 12263 expect(typeName.typeArguments, isNull);
12287 expect(typeName.question, isNull); 12264 expect(typeName.question, isNull);
12288 } 12265 }
12289 12266
12290 void test_parseTypeName_simple_nullable() {
12291 enableNnbd = true;
12292 createParser('String?');
12293 TypeName typeName = parser.parseTypeName(false);
12294 expectNotNullIfNoErrors(typeName);
12295 listener.assertNoErrors();
12296 expect(typeName.name, isNotNull);
12297 expect(typeName.typeArguments, isNull);
12298 expect(typeName.question, isNotNull);
12299 }
12300
12301 void test_parseTypeParameter_bounded_functionType_noReturn() { 12267 void test_parseTypeParameter_bounded_functionType_noReturn() {
12302 createParser('A extends Function(int)'); 12268 createParser('A extends Function(int)');
12303 TypeParameter parameter = parser.parseTypeParameter(); 12269 TypeParameter parameter = parser.parseTypeParameter();
12304 expectNotNullIfNoErrors(parameter); 12270 expectNotNullIfNoErrors(parameter);
12305 listener.assertNoErrors(); 12271 listener.assertNoErrors();
12306 expect(parameter.bound, new isInstanceOf<GenericFunctionType>()); 12272 expect(parameter.bound, new isInstanceOf<GenericFunctionType>());
12307 expect(parameter.extendsKeyword, isNotNull); 12273 expect(parameter.extendsKeyword, isNotNull);
12308 expect(parameter.name, isNotNull); 12274 expect(parameter.name, isNotNull);
12309 } 12275 }
12310 12276
(...skipping 10 matching lines...) Expand all
12321 void test_parseTypeParameter_bounded_generic() { 12287 void test_parseTypeParameter_bounded_generic() {
12322 createParser('A extends B<C>'); 12288 createParser('A extends B<C>');
12323 TypeParameter parameter = parser.parseTypeParameter(); 12289 TypeParameter parameter = parser.parseTypeParameter();
12324 expectNotNullIfNoErrors(parameter); 12290 expectNotNullIfNoErrors(parameter);
12325 listener.assertNoErrors(); 12291 listener.assertNoErrors();
12326 expect(parameter.bound, new isInstanceOf<TypeName>()); 12292 expect(parameter.bound, new isInstanceOf<TypeName>());
12327 expect(parameter.extendsKeyword, isNotNull); 12293 expect(parameter.extendsKeyword, isNotNull);
12328 expect(parameter.name, isNotNull); 12294 expect(parameter.name, isNotNull);
12329 } 12295 }
12330 12296
12331 void test_parseTypeParameter_bounded_nullable() {
12332 enableNnbd = true;
12333 createParser('A extends B?');
12334 TypeParameter parameter = parser.parseTypeParameter();
12335 expectNotNullIfNoErrors(parameter);
12336 listener.assertNoErrors();
12337 expect(parameter.bound, new isInstanceOf<TypeName>());
12338 expect(parameter.extendsKeyword, isNotNull);
12339 expect(parameter.name, isNotNull);
12340 TypeName bound = parameter.bound;
12341 expect(bound, isNotNull);
12342 expect(bound.question, isNotNull);
12343 }
12344
12345 void test_parseTypeParameter_bounded_simple() { 12297 void test_parseTypeParameter_bounded_simple() {
12346 createParser('A extends B'); 12298 createParser('A extends B');
12347 TypeParameter parameter = parser.parseTypeParameter(); 12299 TypeParameter parameter = parser.parseTypeParameter();
12348 expectNotNullIfNoErrors(parameter); 12300 expectNotNullIfNoErrors(parameter);
12349 listener.assertNoErrors(); 12301 listener.assertNoErrors();
12350 expect(parameter.bound, new isInstanceOf<TypeName>()); 12302 expect(parameter.bound, new isInstanceOf<TypeName>());
12351 expect(parameter.extendsKeyword, isNotNull); 12303 expect(parameter.extendsKeyword, isNotNull);
12352 expect(parameter.name, isNotNull); 12304 expect(parameter.name, isNotNull);
12353 } 12305 }
12354 12306
(...skipping 3120 matching lines...) Expand 10 before | Expand all | Expand 10 after
15475 expectCommentText(typeVariable.documentationComment, '/// Doc'); 15427 expectCommentText(typeVariable.documentationComment, '/// Doc');
15476 } 15428 }
15477 15429
15478 /** 15430 /**
15479 * Assert that the given [name] is in declaration context. 15431 * Assert that the given [name] is in declaration context.
15480 */ 15432 */
15481 void _assertIsDeclarationName(SimpleIdentifier name) { 15433 void _assertIsDeclarationName(SimpleIdentifier name) {
15482 expect(name.inDeclarationContext(), isTrue); 15434 expect(name.inDeclarationContext(), isTrue);
15483 } 15435 }
15484 } 15436 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/parser_fasta_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698