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

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

Issue 2628973003: Add preliminary parser support for generic function types (Closed)
Patch Set: Created 3 years, 11 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/lib/src/generated/parser.dart ('k') | tests/language/language_analyzer2.status » ('j') | 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 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 848 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 listener.assertNoErrors(); 859 listener.assertNoErrors();
860 } 860 }
861 861
862 void test_continueWithoutLabelInCase_noError_switchInLoop() { 862 void test_continueWithoutLabelInCase_noError_switchInLoop() {
863 createParser('while (a) { switch (b) {default: continue;}}'); 863 createParser('while (a) { switch (b) {default: continue;}}');
864 WhileStatement statement = parser.parseWhileStatement(); 864 WhileStatement statement = parser.parseWhileStatement();
865 expectNotNullIfNoErrors(statement); 865 expectNotNullIfNoErrors(statement);
866 listener.assertNoErrors(); 866 listener.assertNoErrors();
867 } 867 }
868 868
869 void test_deprecatedClassTypeAlias() { 869 void test_defaultValueInFunctionType_named_colon() {
870 ParserTestCase.parseCompilationUnit( 870 createParser('int x : 0');
871 "typedef C = S with M;", [ParserErrorCode.DEPRECATED_CLASS_TYPE_ALIAS]); 871 FormalParameter parameter =
872 parser.parseFormalParameter(ParameterKind.NAMED, inFunctionType: true);
873 expectNotNullIfNoErrors(parameter);
874 listener.assertErrorsWithCodes(
875 [ParserErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE]);
872 } 876 }
873 877
874 void test_deprecatedClassTypeAlias_withGeneric() { 878 void test_defaultValueInFunctionType_named_equal() {
875 ParserTestCase.parseCompilationUnit("typedef C<T> = S<T> with M;", 879 createParser('int x = 0');
876 [ParserErrorCode.DEPRECATED_CLASS_TYPE_ALIAS]); 880 FormalParameter parameter =
881 parser.parseFormalParameter(ParameterKind.NAMED, inFunctionType: true);
882 expectNotNullIfNoErrors(parameter);
883 listener.assertErrorsWithCodes(
884 [ParserErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE]);
885 }
886
887 void test_defaultValueInFunctionType_positional() {
888 createParser('int x = 0');
889 FormalParameter parameter = parser
890 .parseFormalParameter(ParameterKind.POSITIONAL, inFunctionType: true);
891 expectNotNullIfNoErrors(parameter);
892 listener.assertErrorsWithCodes(
893 [ParserErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE]);
877 } 894 }
878 895
879 void test_directiveAfterDeclaration_classBeforeDirective() { 896 void test_directiveAfterDeclaration_classBeforeDirective() {
880 CompilationUnit unit = ParserTestCase.parseCompilationUnit( 897 CompilationUnit unit = ParserTestCase.parseCompilationUnit(
881 "class Foo{} library l;", 898 "class Foo{} library l;",
882 [ParserErrorCode.DIRECTIVE_AFTER_DECLARATION]); 899 [ParserErrorCode.DIRECTIVE_AFTER_DECLARATION]);
883 expect(unit, isNotNull); 900 expect(unit, isNotNull);
884 } 901 }
885 902
886 void test_directiveAfterDeclaration_classBetweenDirectives() { 903 void test_directiveAfterDeclaration_classBetweenDirectives() {
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 ArgumentList list = parser.parseArgumentList(); 1100 ArgumentList list = parser.parseArgumentList();
1084 expectNotNullIfNoErrors(list); 1101 expectNotNullIfNoErrors(list);
1085 listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_TOKEN]); 1102 listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_TOKEN]);
1086 } 1103 }
1087 1104
1088 void test_expectedToken_parseStatement_afterVoid() { 1105 void test_expectedToken_parseStatement_afterVoid() {
1089 ParserTestCase.parseStatement("void}", 1106 ParserTestCase.parseStatement("void}",
1090 [ParserErrorCode.EXPECTED_TOKEN, ParserErrorCode.MISSING_IDENTIFIER]); 1107 [ParserErrorCode.EXPECTED_TOKEN, ParserErrorCode.MISSING_IDENTIFIER]);
1091 } 1108 }
1092 1109
1093 void test_expectedToken_semicolonAfterClass() {
1094 Token token = TokenFactory.tokenFromKeyword(Keyword.CLASS);
1095 createParser('A = B with C');
1096 ClassTypeAlias declaration =
1097 parser.parseClassTypeAlias(emptyCommentAndMetadata(), null, token);
1098 expectNotNullIfNoErrors(declaration);
1099 listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_TOKEN]);
1100 }
1101
1102 void test_expectedToken_semicolonMissingAfterExport() { 1110 void test_expectedToken_semicolonMissingAfterExport() {
1103 CompilationUnit unit = ParserTestCase.parseCompilationUnit( 1111 CompilationUnit unit = ParserTestCase.parseCompilationUnit(
1104 "export '' class A {}", [ParserErrorCode.EXPECTED_TOKEN]); 1112 "export '' class A {}", [ParserErrorCode.EXPECTED_TOKEN]);
1105 ExportDirective directive = unit.directives[0] as ExportDirective; 1113 ExportDirective directive = unit.directives[0] as ExportDirective;
1106 Token semicolon = directive.semicolon; 1114 Token semicolon = directive.semicolon;
1107 expect(semicolon, isNotNull); 1115 expect(semicolon, isNotNull);
1108 expect(semicolon.isSynthetic, isTrue); 1116 expect(semicolon.isSynthetic, isTrue);
1109 } 1117 }
1110 1118
1111 void test_expectedToken_semicolonMissingAfterExpression() { 1119 void test_expectedToken_semicolonMissingAfterExpression() {
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after
1995 expect(method.parameters, hasLength(0)); 2003 expect(method.parameters, hasLength(0));
1996 } 2004 }
1997 2005
1998 void test_missingMethodParameters_void_expression() { 2006 void test_missingMethodParameters_void_expression() {
1999 createParser('void m => null; }'); 2007 createParser('void m => null; }');
2000 ClassMember member = parser.parseClassMember('C'); 2008 ClassMember member = parser.parseClassMember('C');
2001 expectNotNullIfNoErrors(member); 2009 expectNotNullIfNoErrors(member);
2002 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_METHOD_PARAMETERS]); 2010 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_METHOD_PARAMETERS]);
2003 } 2011 }
2004 2012
2013 void test_missingNameForNamedParameter_colon() {
2014 createParser('int : 0');
2015 FormalParameter parameter =
2016 parser.parseFormalParameter(ParameterKind.NAMED, inFunctionType: true);
2017 expectNotNullIfNoErrors(parameter);
2018 listener.assertErrorsWithCodes([
2019 ParserErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE,
2020 ParserErrorCode.MISSING_NAME_FOR_NAMED_PARAMETER
2021 ]);
2022 }
2023
2024 void test_missingNameForNamedParameter_equals() {
2025 createParser('int = 0');
2026 FormalParameter parameter =
2027 parser.parseFormalParameter(ParameterKind.NAMED, inFunctionType: true);
2028 expectNotNullIfNoErrors(parameter);
2029 listener.assertErrorsWithCodes([
2030 ParserErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE,
2031 ParserErrorCode.MISSING_NAME_FOR_NAMED_PARAMETER
2032 ]);
2033 }
2034
2035 void test_missingNameForNamedParameter_noDefault() {
2036 createParser('int');
2037 FormalParameter parameter =
2038 parser.parseFormalParameter(ParameterKind.NAMED, inFunctionType: true);
2039 expectNotNullIfNoErrors(parameter);
2040 listener.assertErrorsWithCodes(
2041 [ParserErrorCode.MISSING_NAME_FOR_NAMED_PARAMETER]);
2042 }
2043
2005 void test_missingNameInLibraryDirective() { 2044 void test_missingNameInLibraryDirective() {
2006 CompilationUnit unit = ParserTestCase.parseCompilationUnit( 2045 CompilationUnit unit = ParserTestCase.parseCompilationUnit(
2007 "library;", [ParserErrorCode.MISSING_NAME_IN_LIBRARY_DIRECTIVE]); 2046 "library;", [ParserErrorCode.MISSING_NAME_IN_LIBRARY_DIRECTIVE]);
2008 expect(unit, isNotNull); 2047 expect(unit, isNotNull);
2009 } 2048 }
2010 2049
2011 void test_missingNameInPartOfDirective() { 2050 void test_missingNameInPartOfDirective() {
2012 CompilationUnit unit = ParserTestCase.parseCompilationUnit( 2051 CompilationUnit unit = ParserTestCase.parseCompilationUnit(
2013 "part of;", [ParserErrorCode.MISSING_NAME_IN_PART_OF_DIRECTIVE]); 2052 "part of;", [ParserErrorCode.MISSING_NAME_IN_PART_OF_DIRECTIVE]);
2014 expect(unit, isNotNull); 2053 expect(unit, isNotNull);
(...skipping 4416 matching lines...) Expand 10 before | Expand all | Expand 10 after
6431 expect(constructor.returnType, isNotNull); 6470 expect(constructor.returnType, isNotNull);
6432 expect(constructor.period, isNull); 6471 expect(constructor.period, isNull);
6433 expect(constructor.name, isNull); 6472 expect(constructor.name, isNull);
6434 expect(constructor.parameters, isNotNull); 6473 expect(constructor.parameters, isNotNull);
6435 expect(constructor.separator, isNotNull); 6474 expect(constructor.separator, isNotNull);
6436 expect(constructor.initializers, hasLength(0)); 6475 expect(constructor.initializers, hasLength(0));
6437 expect(constructor.redirectedConstructor, isNotNull); 6476 expect(constructor.redirectedConstructor, isNotNull);
6438 expect(constructor.body, isNotNull); 6477 expect(constructor.body, isNotNull);
6439 } 6478 }
6440 6479
6441 void test_parseClassTypeAlias_abstract() {
6442 Token classToken = TokenFactory.tokenFromKeyword(Keyword.CLASS);
6443 Token abstractToken = TokenFactory.tokenFromKeyword(Keyword.ABSTRACT);
6444 createParser('A = B with C;');
6445 ClassTypeAlias classTypeAlias = parser.parseClassTypeAlias(
6446 emptyCommentAndMetadata(), abstractToken, classToken);
6447 expectNotNullIfNoErrors(classTypeAlias);
6448 listener.assertNoErrors();
6449 expect(classTypeAlias.typedefKeyword, isNotNull);
6450 expect(classTypeAlias.name.name, "A");
6451 expect(classTypeAlias.equals, isNotNull);
6452 expect(classTypeAlias.abstractKeyword, isNotNull);
6453 expect(classTypeAlias.superclass.name.name, isNotNull, reason: "B");
6454 expect(classTypeAlias.withClause, isNotNull);
6455 expect(classTypeAlias.implementsClause, isNull);
6456 expect(classTypeAlias.semicolon, isNotNull);
6457 }
6458
6459 void test_parseClassTypeAlias_implements() {
6460 Token classToken = TokenFactory.tokenFromKeyword(Keyword.CLASS);
6461 createParser('A = B with C implements D;');
6462 ClassTypeAlias classTypeAlias =
6463 parser.parseClassTypeAlias(emptyCommentAndMetadata(), null, classToken);
6464 expectNotNullIfNoErrors(classTypeAlias);
6465 listener.assertNoErrors();
6466 expect(classTypeAlias.typedefKeyword, isNotNull);
6467 expect(classTypeAlias.name.name, "A");
6468 expect(classTypeAlias.equals, isNotNull);
6469 expect(classTypeAlias.abstractKeyword, isNull);
6470 expect(classTypeAlias.superclass.name.name, isNotNull, reason: "B");
6471 expect(classTypeAlias.withClause, isNotNull);
6472 expect(classTypeAlias.implementsClause, isNotNull);
6473 expect(classTypeAlias.semicolon, isNotNull);
6474 }
6475
6476 void test_parseClassTypeAlias_with() {
6477 Token classToken = TokenFactory.tokenFromKeyword(Keyword.CLASS);
6478 createParser('A = B with C;');
6479 ClassTypeAlias classTypeAlias =
6480 parser.parseClassTypeAlias(emptyCommentAndMetadata(), null, classToken);
6481 expectNotNullIfNoErrors(classTypeAlias);
6482 listener.assertNoErrors();
6483 expect(classTypeAlias.typedefKeyword, isNotNull);
6484 expect(classTypeAlias.name.name, "A");
6485 expect(classTypeAlias.equals, isNotNull);
6486 expect(classTypeAlias.abstractKeyword, isNull);
6487 expect(classTypeAlias.superclass.name.name, isNotNull, reason: "B");
6488 expect(classTypeAlias.withClause, isNotNull);
6489 expect(classTypeAlias.implementsClause, isNull);
6490 expect(classTypeAlias.semicolon, isNotNull);
6491 }
6492
6493 void test_parseClassTypeAlias_with_implements() {
6494 Token classToken = TokenFactory.tokenFromKeyword(Keyword.CLASS);
6495 createParser('A = B with C implements D;');
6496 ClassTypeAlias classTypeAlias =
6497 parser.parseClassTypeAlias(emptyCommentAndMetadata(), null, classToken);
6498 expectNotNullIfNoErrors(classTypeAlias);
6499 listener.assertNoErrors();
6500 expect(classTypeAlias.typedefKeyword, isNotNull);
6501 expect(classTypeAlias.name.name, "A");
6502 expect(classTypeAlias.equals, isNotNull);
6503 expect(classTypeAlias.abstractKeyword, isNull);
6504 expect(classTypeAlias.superclass.name.name, isNotNull, reason: "B");
6505 expect(classTypeAlias.withClause, isNotNull);
6506 expect(classTypeAlias.implementsClause, isNotNull);
6507 expect(classTypeAlias.semicolon, isNotNull);
6508 }
6509
6510 void test_parseCombinator_hide() { 6480 void test_parseCombinator_hide() {
6511 createParser('hide a;'); 6481 createParser('hide a;');
6512 Combinator combinator = parser.parseCombinator(); 6482 Combinator combinator = parser.parseCombinator();
6513 expectNotNullIfNoErrors(combinator); 6483 expectNotNullIfNoErrors(combinator);
6514 listener.assertNoErrors(); 6484 listener.assertNoErrors();
6515 expect(combinator, new isInstanceOf<HideCombinator>()); 6485 expect(combinator, new isInstanceOf<HideCombinator>());
6516 HideCombinator hideCombinator = combinator; 6486 HideCombinator hideCombinator = combinator;
6517 expect(hideCombinator.keyword, isNotNull); 6487 expect(hideCombinator.keyword, isNotNull);
6518 expect(hideCombinator.hiddenNames, hasLength(1)); 6488 expect(hideCombinator.hiddenNames, hasLength(1));
6519 } 6489 }
(...skipping 1959 matching lines...) Expand 10 before | Expand all | Expand 10 after
8479 void test_parseExtendsClause() { 8449 void test_parseExtendsClause() {
8480 createParser('extends B'); 8450 createParser('extends B');
8481 ExtendsClause clause = parser.parseExtendsClause(); 8451 ExtendsClause clause = parser.parseExtendsClause();
8482 expectNotNullIfNoErrors(clause); 8452 expectNotNullIfNoErrors(clause);
8483 listener.assertNoErrors(); 8453 listener.assertNoErrors();
8484 expect(clause.extendsKeyword, isNotNull); 8454 expect(clause.extendsKeyword, isNotNull);
8485 expect(clause.superclass, isNotNull); 8455 expect(clause.superclass, isNotNull);
8486 expect(clause.superclass, new isInstanceOf<TypeName>()); 8456 expect(clause.superclass, new isInstanceOf<TypeName>());
8487 } 8457 }
8488 8458
8459 void test_parseFinalConstVarOrType_const_functionType() {
8460 createParser('const int Function(int) f');
8461 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false);
8462 expectNotNullIfNoErrors(result);
8463 listener.assertNoErrors();
8464 Token keyword = result.keyword;
8465 expect(keyword, isNotNull);
8466 expect(keyword.type, TokenType.KEYWORD);
8467 expect(keyword.keyword, Keyword.CONST);
8468 expect(result.type, isNotNull);
8469 }
8470
8471 void test_parseFinalConstVarOrType_const_namedType() {
8472 createParser('const A a');
8473 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false);
8474 expectNotNullIfNoErrors(result);
8475 listener.assertNoErrors();
8476 Token keyword = result.keyword;
8477 expect(keyword, isNotNull);
8478 expect(keyword.type, TokenType.KEYWORD);
8479 expect(keyword.keyword, Keyword.CONST);
8480 expect(result.type, isNotNull);
8481 }
8482
8489 void test_parseFinalConstVarOrType_const_noType() { 8483 void test_parseFinalConstVarOrType_const_noType() {
8490 createParser('const'); 8484 createParser('const');
8491 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); 8485 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false);
8492 expectNotNullIfNoErrors(result); 8486 expectNotNullIfNoErrors(result);
8493 listener.assertNoErrors(); 8487 listener.assertNoErrors();
8494 Token keyword = result.keyword; 8488 Token keyword = result.keyword;
8495 expect(keyword, isNotNull); 8489 expect(keyword, isNotNull);
8496 expect(keyword.type, TokenType.KEYWORD); 8490 expect(keyword.type, TokenType.KEYWORD);
8497 expect(keyword.keyword, Keyword.CONST); 8491 expect(keyword.keyword, Keyword.CONST);
8498 expect(result.type, isNull); 8492 expect(result.type, isNull);
8499 } 8493 }
8500 8494
8501 void test_parseFinalConstVarOrType_const_type() { 8495 void test_parseFinalConstVarOrType_final_functionType() {
8502 createParser('const A a'); 8496 createParser('final int Function(int) f');
8503 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); 8497 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false);
8504 expectNotNullIfNoErrors(result); 8498 expectNotNullIfNoErrors(result);
8505 listener.assertNoErrors(); 8499 listener.assertNoErrors();
8506 Token keyword = result.keyword; 8500 Token keyword = result.keyword;
8507 expect(keyword, isNotNull); 8501 expect(keyword, isNotNull);
8508 expect(keyword.type, TokenType.KEYWORD); 8502 expect(keyword.type, TokenType.KEYWORD);
8509 expect(keyword.keyword, Keyword.CONST); 8503 expect(keyword.keyword, Keyword.FINAL);
8510 expect(result.type, isNotNull); 8504 expect(result.type, isNotNull);
8511 } 8505 }
8512 8506
8507 void test_parseFinalConstVarOrType_final_namedType() {
8508 createParser('final A a');
8509 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false);
8510 expectNotNullIfNoErrors(result);
8511 listener.assertNoErrors();
8512 Token keyword = result.keyword;
8513 expect(keyword, isNotNull);
8514 expect(keyword.type, TokenType.KEYWORD);
8515 expect(keyword.keyword, Keyword.FINAL);
8516 expect(result.type, isNotNull);
8517 }
8518
8513 void test_parseFinalConstVarOrType_final_noType() { 8519 void test_parseFinalConstVarOrType_final_noType() {
8514 createParser('final'); 8520 createParser('final');
8515 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); 8521 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false);
8516 expectNotNullIfNoErrors(result); 8522 expectNotNullIfNoErrors(result);
8517 listener.assertNoErrors(); 8523 listener.assertNoErrors();
8518 Token keyword = result.keyword; 8524 Token keyword = result.keyword;
8519 expect(keyword, isNotNull); 8525 expect(keyword, isNotNull);
8520 expect(keyword.type, TokenType.KEYWORD); 8526 expect(keyword.type, TokenType.KEYWORD);
8521 expect(keyword.keyword, Keyword.FINAL); 8527 expect(keyword.keyword, Keyword.FINAL);
8522 expect(result.type, isNull); 8528 expect(result.type, isNull);
8523 } 8529 }
8524 8530
8525 void test_parseFinalConstVarOrType_final_prefixedType() { 8531 void test_parseFinalConstVarOrType_final_prefixedType() {
8526 createParser('final p.A a'); 8532 createParser('final p.A a');
8527 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); 8533 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false);
8528 expectNotNullIfNoErrors(result); 8534 expectNotNullIfNoErrors(result);
8529 listener.assertNoErrors(); 8535 listener.assertNoErrors();
8530 Token keyword = result.keyword; 8536 Token keyword = result.keyword;
8531 expect(keyword, isNotNull); 8537 expect(keyword, isNotNull);
8532 expect(keyword.type, TokenType.KEYWORD); 8538 expect(keyword.type, TokenType.KEYWORD);
8533 expect(keyword.keyword, Keyword.FINAL); 8539 expect(keyword.keyword, Keyword.FINAL);
8534 expect(result.type, isNotNull); 8540 expect(result.type, isNotNull);
8535 } 8541 }
8536 8542
8537 void test_parseFinalConstVarOrType_final_type() { 8543 void test_parseFinalConstVarOrType_type_function() {
8538 createParser('final A a'); 8544 createParser('int Function(int) f');
8539 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); 8545 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false);
8540 expectNotNullIfNoErrors(result); 8546 expectNotNullIfNoErrors(result);
8541 listener.assertNoErrors(); 8547 listener.assertNoErrors();
8542 Token keyword = result.keyword; 8548 expect(result.keyword, isNull);
8543 expect(keyword, isNotNull);
8544 expect(keyword.type, TokenType.KEYWORD);
8545 expect(keyword.keyword, Keyword.FINAL);
8546 expect(result.type, isNotNull); 8549 expect(result.type, isNotNull);
8547 } 8550 }
8548 8551
8549 void test_parseFinalConstVarOrType_type_parameterized() { 8552 void test_parseFinalConstVarOrType_type_parameterized() {
8550 createParser('A<B> a'); 8553 createParser('A<B> a');
8551 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); 8554 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false);
8552 expectNotNullIfNoErrors(result); 8555 expectNotNullIfNoErrors(result);
8553 listener.assertNoErrors(); 8556 listener.assertNoErrors();
8554 expect(result.keyword, isNull); 8557 expect(result.keyword, isNull);
8555 expect(result.type, isNotNull); 8558 expect(result.type, isNotNull);
(...skipping 28 matching lines...) Expand all
8584 8587
8585 void test_parseFinalConstVarOrType_type_simple() { 8588 void test_parseFinalConstVarOrType_type_simple() {
8586 createParser('A a'); 8589 createParser('A a');
8587 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); 8590 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false);
8588 expectNotNullIfNoErrors(result); 8591 expectNotNullIfNoErrors(result);
8589 listener.assertNoErrors(); 8592 listener.assertNoErrors();
8590 expect(result.keyword, isNull); 8593 expect(result.keyword, isNull);
8591 expect(result.type, isNotNull); 8594 expect(result.type, isNotNull);
8592 } 8595 }
8593 8596
8597 void test_parseFinalConstVarOrType_type_simple_noIdentifier_inFunctionType() {
8598 createParser('A,');
8599 FinalConstVarOrType result =
8600 parser.parseFinalConstVarOrType(false, inFunctionType: true);
8601 expectNotNullIfNoErrors(result);
8602 listener.assertNoErrors();
8603 expect(result.keyword, isNull);
8604 expect(result.type, isNotNull);
8605 }
8606
8594 void test_parseFinalConstVarOrType_var() { 8607 void test_parseFinalConstVarOrType_var() {
8595 createParser('var'); 8608 createParser('var');
8596 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); 8609 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false);
8597 expectNotNullIfNoErrors(result); 8610 expectNotNullIfNoErrors(result);
8598 listener.assertNoErrors(); 8611 listener.assertNoErrors();
8599 Token keyword = result.keyword; 8612 Token keyword = result.keyword;
8600 expect(keyword, isNotNull); 8613 expect(keyword, isNotNull);
8601 expect(keyword.type, TokenType.KEYWORD); 8614 expect(keyword.type, TokenType.KEYWORD);
8602 expect(keyword.keyword, Keyword.VAR); 8615 expect(keyword.keyword, Keyword.VAR);
8603 expect(result.type, isNull); 8616 expect(result.type, isNull);
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
8842 FormalParameterList list = parser.parseFormalParameterList(); 8855 FormalParameterList list = parser.parseFormalParameterList();
8843 expectNotNullIfNoErrors(list); 8856 expectNotNullIfNoErrors(list);
8844 listener.assertNoErrors(); 8857 listener.assertNoErrors();
8845 expect(list.leftParenthesis, isNotNull); 8858 expect(list.leftParenthesis, isNotNull);
8846 expect(list.leftDelimiter, isNotNull); 8859 expect(list.leftDelimiter, isNotNull);
8847 expect(list.parameters, hasLength(2)); 8860 expect(list.parameters, hasLength(2));
8848 expect(list.rightDelimiter, isNotNull); 8861 expect(list.rightDelimiter, isNotNull);
8849 expect(list.rightParenthesis, isNotNull); 8862 expect(list.rightParenthesis, isNotNull);
8850 } 8863 }
8851 8864
8865 void test_parseFormalParameterList_normal_named_inFunctionType() {
8866 createParser('(A, {B b})');
8867 FormalParameterList list =
8868 parser.parseFormalParameterList(inFunctionType: true);
8869 expectNotNullIfNoErrors(list);
8870 listener.assertNoErrors();
8871 expect(list.leftParenthesis, isNotNull);
8872 expect(list.leftDelimiter, isNotNull);
8873 expect(list.rightDelimiter, isNotNull);
8874 expect(list.rightParenthesis, isNotNull);
8875 NodeList<FormalParameter> parameters = list.parameters;
8876 expect(parameters, hasLength(2));
8877
8878 expect(parameters[0], new isInstanceOf<SimpleFormalParameter>());
8879 SimpleFormalParameter required = parameters[0];
8880 expect(required.identifier, isNull);
8881 expect(required.type, new isInstanceOf<TypeName>());
8882 expect((required.type as TypeName).name.name, 'A');
8883
8884 expect(parameters[1], new isInstanceOf<DefaultFormalParameter>());
8885 DefaultFormalParameter named = parameters[1];
8886 expect(named.identifier, isNotNull);
8887 expect(named.parameter, new isInstanceOf<SimpleFormalParameter>());
8888 SimpleFormalParameter simple = named.parameter;
8889 expect(simple.type, new isInstanceOf<TypeName>());
8890 expect((simple.type as TypeName).name.name, 'B');
8891 }
8892
8852 void test_parseFormalParameterList_normal_positional() { 8893 void test_parseFormalParameterList_normal_positional() {
8853 createParser('(A a, [B b])'); 8894 createParser('(A a, [B b])');
8854 FormalParameterList list = parser.parseFormalParameterList(); 8895 FormalParameterList list = parser.parseFormalParameterList();
8855 expectNotNullIfNoErrors(list); 8896 expectNotNullIfNoErrors(list);
8856 listener.assertNoErrors(); 8897 listener.assertNoErrors();
8857 expect(list.leftParenthesis, isNotNull); 8898 expect(list.leftParenthesis, isNotNull);
8858 expect(list.leftDelimiter, isNotNull); 8899 expect(list.leftDelimiter, isNotNull);
8859 expect(list.parameters, hasLength(2)); 8900 expect(list.parameters, hasLength(2));
8860 expect(list.rightDelimiter, isNotNull); 8901 expect(list.rightDelimiter, isNotNull);
8861 expect(list.rightParenthesis, isNotNull); 8902 expect(list.rightParenthesis, isNotNull);
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after
9592 createParser('<E>(E i) => i++'); 9633 createParser('<E>(E i) => i++');
9593 FunctionExpression expression = parser.parseFunctionExpression(); 9634 FunctionExpression expression = parser.parseFunctionExpression();
9594 expectNotNullIfNoErrors(expression); 9635 expectNotNullIfNoErrors(expression);
9595 listener.assertNoErrors(); 9636 listener.assertNoErrors();
9596 expect(expression.body, isNotNull); 9637 expect(expression.body, isNotNull);
9597 expect(expression.typeParameters, isNotNull); 9638 expect(expression.typeParameters, isNotNull);
9598 expect(expression.parameters, isNotNull); 9639 expect(expression.parameters, isNotNull);
9599 expect((expression.body as ExpressionFunctionBody).semicolon, isNull); 9640 expect((expression.body as ExpressionFunctionBody).semicolon, isNull);
9600 } 9641 }
9601 9642
9643 void test_parseGenericTypeAlias_noTypeParameters() {
9644 createParser('F = int Function(int);');
9645 GenericTypeAlias alias =
9646 parser.parseGenericTypeAlias(emptyCommentAndMetadata(), null);
9647 expectNotNullIfNoErrors(alias);
9648 listener.assertNoErrors();
9649 expect(alias.name, isNotNull);
9650 expect(alias.name.name, 'F');
9651 expect(alias.typeParameters, isNull);
9652 expect(alias.equals, isNotNull);
9653 expect(alias.functionType, isNotNull);
9654 expect(alias.semicolon, isNotNull);
9655 }
9656
9657 void test_parseGenericTypeAlias_typeParameters() {
9658 createParser('F<T> = T Function(T);');
9659 GenericTypeAlias alias =
9660 parser.parseGenericTypeAlias(emptyCommentAndMetadata(), null);
9661 expectNotNullIfNoErrors(alias);
9662 listener.assertNoErrors();
9663 expect(alias.name, isNotNull);
9664 expect(alias.name.name, 'F');
9665 expect(alias.typeParameters, isNotNull);
9666 expect(alias.equals, isNotNull);
9667 expect(alias.functionType, isNotNull);
9668 expect(alias.semicolon, isNotNull);
9669 }
9670
9602 void test_parseGetter_nonStatic() { 9671 void test_parseGetter_nonStatic() {
9603 Comment comment = astFactory.documentationComment(new List<Token>(0)); 9672 Comment comment = astFactory.documentationComment(new List<Token>(0));
9604 TypeName returnType = 9673 TypeName returnType =
9605 astFactory.typeName(astFactory.simpleIdentifier(null), null); 9674 astFactory.typeName(astFactory.simpleIdentifier(null), null);
9606 createParser('get a;'); 9675 createParser('get a;');
9607 MethodDeclaration method = 9676 MethodDeclaration method =
9608 parser.parseGetter(commentAndMetadata(comment), null, null, returnType); 9677 parser.parseGetter(commentAndMetadata(comment), null, null, returnType);
9609 expectNotNullIfNoErrors(method); 9678 expectNotNullIfNoErrors(method);
9610 listener.assertNoErrors(); 9679 listener.assertNoErrors();
9611 expect(method.body, isNotNull); 9680 expect(method.body, isNotNull);
(...skipping 1440 matching lines...) Expand 10 before | Expand all | Expand 10 after
11052 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); 11121 NormalFormalParameter parameter = parser.parseNormalFormalParameter();
11053 expectNotNullIfNoErrors(parameter); 11122 expectNotNullIfNoErrors(parameter);
11054 listener.assertNoErrors(); 11123 listener.assertNoErrors();
11055 expect(parameter, new isInstanceOf<SimpleFormalParameter>()); 11124 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
11056 SimpleFormalParameter simpleParameter = parameter; 11125 SimpleFormalParameter simpleParameter = parameter;
11057 expect(simpleParameter.keyword, isNotNull); 11126 expect(simpleParameter.keyword, isNotNull);
11058 expect(simpleParameter.type, isNotNull); 11127 expect(simpleParameter.type, isNotNull);
11059 expect(simpleParameter.identifier, isNotNull); 11128 expect(simpleParameter.identifier, isNotNull);
11060 } 11129 }
11061 11130
11131 void test_parseNormalFormalParameter_simple_noName() {
11132 createParser('a)');
11133 NormalFormalParameter parameter =
11134 parser.parseNormalFormalParameter(inFunctionType: true);
11135 expectNotNullIfNoErrors(parameter);
11136 listener.assertNoErrors();
11137 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
11138 SimpleFormalParameter simpleParameter = parameter;
11139 expect(simpleParameter.keyword, isNull);
11140 expect(simpleParameter.type, isNotNull);
11141 expect(simpleParameter.identifier, isNull);
11142 }
11143
11062 void test_parseNormalFormalParameter_simple_noType() { 11144 void test_parseNormalFormalParameter_simple_noType() {
11063 createParser('a)'); 11145 createParser('a)');
11064 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); 11146 NormalFormalParameter parameter = parser.parseNormalFormalParameter();
11065 expectNotNullIfNoErrors(parameter); 11147 expectNotNullIfNoErrors(parameter);
11066 listener.assertNoErrors(); 11148 listener.assertNoErrors();
11067 expect(parameter, new isInstanceOf<SimpleFormalParameter>()); 11149 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
11068 SimpleFormalParameter simpleParameter = parameter; 11150 SimpleFormalParameter simpleParameter = parameter;
11069 expect(simpleParameter.keyword, isNull); 11151 expect(simpleParameter.keyword, isNull);
11070 expect(simpleParameter.type, isNull); 11152 expect(simpleParameter.type, isNull);
11071 expect(simpleParameter.identifier, isNotNull); 11153 expect(simpleParameter.identifier, isNotNull);
(...skipping 1561 matching lines...) Expand 10 before | Expand all | Expand 10 after
12633 expectNotNullIfNoErrors(typeAlias); 12715 expectNotNullIfNoErrors(typeAlias);
12634 listener.assertNoErrors(); 12716 listener.assertNoErrors();
12635 expect(typeAlias.typedefKeyword, isNotNull); 12717 expect(typeAlias.typedefKeyword, isNotNull);
12636 expect(typeAlias.name, isNotNull); 12718 expect(typeAlias.name, isNotNull);
12637 expect(typeAlias.parameters, isNotNull); 12719 expect(typeAlias.parameters, isNotNull);
12638 expect(typeAlias.returnType, isNotNull); 12720 expect(typeAlias.returnType, isNotNull);
12639 expect(typeAlias.semicolon, isNotNull); 12721 expect(typeAlias.semicolon, isNotNull);
12640 expect(typeAlias.typeParameters, isNull); 12722 expect(typeAlias.typeParameters, isNull);
12641 } 12723 }
12642 12724
12725 void test_parseTypeAlias_genericFunction_noParameters() {
12726 createParser('typedef F = bool Function();');
12727 GenericTypeAlias typeAlias =
12728 parser.parseTypeAlias(emptyCommentAndMetadata());
12729 expectNotNullIfNoErrors(typeAlias);
12730 listener.assertNoErrors();
12731 expect(typeAlias.typedefKeyword, isNotNull);
12732 expect(typeAlias.name, isNotNull);
12733 expect(typeAlias.typeParameters, isNull);
12734 expect(typeAlias.semicolon, isNotNull);
12735 GenericFunctionType functionType = typeAlias.functionType;
12736 expect(functionType, isNotNull);
12737 expect(functionType.parameters, isNotNull);
12738 expect(functionType.returnType, isNotNull);
12739 expect(functionType.typeParameters, isNull);
12740 }
12741
12742 void test_parseTypeAlias_genericFunction_noReturnType() {
12743 createParser('typedef F = Function();');
12744 GenericTypeAlias typeAlias =
12745 parser.parseTypeAlias(emptyCommentAndMetadata());
12746 expectNotNullIfNoErrors(typeAlias);
12747 listener.assertNoErrors();
12748 expect(typeAlias.typedefKeyword, isNotNull);
12749 expect(typeAlias.name, isNotNull);
12750 expect(typeAlias.typeParameters, isNull);
12751 expect(typeAlias.semicolon, isNotNull);
12752 GenericFunctionType functionType = typeAlias.functionType;
12753 expect(functionType, isNotNull);
12754 expect(functionType.parameters, isNotNull);
12755 expect(functionType.returnType, isNull);
12756 expect(functionType.typeParameters, isNull);
12757 }
12758
12759 void test_parseTypeAlias_genericFunction_parameterizedReturnType() {
12760 createParser('typedef F = A<B> Function();');
12761 GenericTypeAlias typeAlias =
12762 parser.parseTypeAlias(emptyCommentAndMetadata());
12763 expectNotNullIfNoErrors(typeAlias);
12764 listener.assertNoErrors();
12765 expect(typeAlias.typedefKeyword, isNotNull);
12766 expect(typeAlias.name, isNotNull);
12767 expect(typeAlias.typeParameters, isNull);
12768 expect(typeAlias.semicolon, isNotNull);
12769 GenericFunctionType functionType = typeAlias.functionType;
12770 expect(functionType, isNotNull);
12771 expect(functionType.parameters, isNotNull);
12772 expect(functionType.returnType, isNotNull);
12773 expect(functionType.typeParameters, isNull);
12774 }
12775
12776 void test_parseTypeAlias_genericFunction_parameters() {
12777 createParser('typedef F = bool Function(Object value);');
12778 GenericTypeAlias typeAlias =
12779 parser.parseTypeAlias(emptyCommentAndMetadata());
12780 expectNotNullIfNoErrors(typeAlias);
12781 listener.assertNoErrors();
12782 expect(typeAlias.typedefKeyword, isNotNull);
12783 expect(typeAlias.name, isNotNull);
12784 expect(typeAlias.typeParameters, isNull);
12785 expect(typeAlias.semicolon, isNotNull);
12786 GenericFunctionType functionType = typeAlias.functionType;
12787 expect(functionType, isNotNull);
12788 expect(functionType.parameters, isNotNull);
12789 expect(functionType.returnType, isNotNull);
12790 expect(functionType.typeParameters, isNull);
12791 }
12792
12793 void test_parseTypeAlias_genericFunction_typeParameters() {
12794 createParser('typedef F = bool Function<E>();');
12795 GenericTypeAlias typeAlias =
12796 parser.parseTypeAlias(emptyCommentAndMetadata());
12797 expectNotNullIfNoErrors(typeAlias);
12798 listener.assertNoErrors();
12799 expect(typeAlias.typedefKeyword, isNotNull);
12800 expect(typeAlias.name, isNotNull);
12801 expect(typeAlias.typeParameters, isNull);
12802 expect(typeAlias.semicolon, isNotNull);
12803 GenericFunctionType functionType = typeAlias.functionType;
12804 expect(functionType, isNotNull);
12805 expect(functionType.parameters, isNotNull);
12806 expect(functionType.returnType, isNotNull);
12807 expect(functionType.typeParameters, isNotNull);
12808 }
12809
12810 void test_parseTypeAlias_genericFunction_typeParameters_noParameters() {
12811 createParser('typedef F<T> = bool Function();');
12812 GenericTypeAlias typeAlias =
12813 parser.parseTypeAlias(emptyCommentAndMetadata());
12814 expectNotNullIfNoErrors(typeAlias);
12815 listener.assertNoErrors();
12816 expect(typeAlias.typedefKeyword, isNotNull);
12817 expect(typeAlias.name, isNotNull);
12818 expect(typeAlias.typeParameters, isNotNull);
12819 expect(typeAlias.semicolon, isNotNull);
12820 GenericFunctionType functionType = typeAlias.functionType;
12821 expect(functionType, isNotNull);
12822 expect(functionType.parameters, isNotNull);
12823 expect(functionType.returnType, isNotNull);
12824 expect(functionType.typeParameters, isNull);
12825 }
12826
12827 void test_parseTypeAlias_genericFunction_typeParameters_noReturnType() {
12828 createParser('typedef F<T> = Function();');
12829 GenericTypeAlias typeAlias =
12830 parser.parseTypeAlias(emptyCommentAndMetadata());
12831 expectNotNullIfNoErrors(typeAlias);
12832 listener.assertNoErrors();
12833 expect(typeAlias.typedefKeyword, isNotNull);
12834 expect(typeAlias.name, isNotNull);
12835 expect(typeAlias.typeParameters, isNotNull);
12836 expect(typeAlias.semicolon, isNotNull);
12837 GenericFunctionType functionType = typeAlias.functionType;
12838 expect(functionType, isNotNull);
12839 expect(functionType.parameters, isNotNull);
12840 expect(functionType.returnType, isNull);
12841 expect(functionType.typeParameters, isNull);
12842 }
12843
12844 void
12845 test_parseTypeAlias_genericFunction_typeParameters_parameterizedReturnType () {
12846 createParser('typedef F<T> = A<B> Function();');
12847 GenericTypeAlias typeAlias =
12848 parser.parseTypeAlias(emptyCommentAndMetadata());
12849 expectNotNullIfNoErrors(typeAlias);
12850 listener.assertNoErrors();
12851 expect(typeAlias.typedefKeyword, isNotNull);
12852 expect(typeAlias.name, isNotNull);
12853 expect(typeAlias.typeParameters, isNotNull);
12854 expect(typeAlias.semicolon, isNotNull);
12855 GenericFunctionType functionType = typeAlias.functionType;
12856 expect(functionType, isNotNull);
12857 expect(functionType.parameters, isNotNull);
12858 expect(functionType.returnType, isNotNull);
12859 expect(functionType.typeParameters, isNull);
12860 }
12861
12862 void test_parseTypeAlias_genericFunction_typeParameters_parameters() {
12863 createParser('typedef F<T> = bool Function(Object value);');
12864 GenericTypeAlias typeAlias =
12865 parser.parseTypeAlias(emptyCommentAndMetadata());
12866 expectNotNullIfNoErrors(typeAlias);
12867 listener.assertNoErrors();
12868 expect(typeAlias.typedefKeyword, isNotNull);
12869 expect(typeAlias.name, isNotNull);
12870 expect(typeAlias.typeParameters, isNotNull);
12871 expect(typeAlias.semicolon, isNotNull);
12872 GenericFunctionType functionType = typeAlias.functionType;
12873 expect(functionType, isNotNull);
12874 expect(functionType.parameters, isNotNull);
12875 expect(functionType.returnType, isNotNull);
12876 expect(functionType.typeParameters, isNull);
12877 }
12878
12879 void test_parseTypeAlias_genericFunction_typeParameters_typeParameters() {
12880 createParser('typedef F<T> = bool Function<E>();');
12881 GenericTypeAlias typeAlias =
12882 parser.parseTypeAlias(emptyCommentAndMetadata());
12883 expectNotNullIfNoErrors(typeAlias);
12884 listener.assertNoErrors();
12885 expect(typeAlias.typedefKeyword, isNotNull);
12886 expect(typeAlias.name, isNotNull);
12887 expect(typeAlias.typeParameters, isNotNull);
12888 expect(typeAlias.semicolon, isNotNull);
12889 GenericFunctionType functionType = typeAlias.functionType;
12890 expect(functionType, isNotNull);
12891 expect(functionType.parameters, isNotNull);
12892 expect(functionType.returnType, isNotNull);
12893 expect(functionType.typeParameters, isNotNull);
12894 }
12895
12896 void test_parseTypeAlias_genericFunction_typeParameters_voidReturnType() {
12897 createParser('typedef F<T> = void Function();');
12898 GenericTypeAlias typeAlias =
12899 parser.parseTypeAlias(emptyCommentAndMetadata());
12900 expectNotNullIfNoErrors(typeAlias);
12901 listener.assertNoErrors();
12902 expect(typeAlias.typedefKeyword, isNotNull);
12903 expect(typeAlias.name, isNotNull);
12904 expect(typeAlias.typeParameters, isNotNull);
12905 expect(typeAlias.semicolon, isNotNull);
12906 GenericFunctionType functionType = typeAlias.functionType;
12907 expect(functionType, isNotNull);
12908 expect(functionType.parameters, isNotNull);
12909 expect(functionType.returnType, isNotNull);
12910 expect(functionType.typeParameters, isNull);
12911 }
12912
12913 void test_parseTypeAlias_genericFunction_voidReturnType() {
12914 createParser('typedef F = void Function();');
12915 GenericTypeAlias typeAlias =
12916 parser.parseTypeAlias(emptyCommentAndMetadata());
12917 expectNotNullIfNoErrors(typeAlias);
12918 listener.assertNoErrors();
12919 expect(typeAlias.typedefKeyword, isNotNull);
12920 expect(typeAlias.name, isNotNull);
12921 expect(typeAlias.typeParameters, isNull);
12922 expect(typeAlias.semicolon, isNotNull);
12923 GenericFunctionType functionType = typeAlias.functionType;
12924 expect(functionType, isNotNull);
12925 expect(functionType.parameters, isNotNull);
12926 expect(functionType.returnType, isNotNull);
12927 expect(functionType.typeParameters, isNull);
12928 }
12929
12930 void test_parseTypeAnnotation_function_noReturnType_noParameters() {
12931 createParser('Function() v');
12932 GenericFunctionType functionType = parser.parseTypeAnnotation();
12933 expectNotNullIfNoErrors(functionType);
12934 listener.assertNoErrors();
12935 expect(functionType.returnType, isNull);
12936 expect(functionType.functionKeyword, isNotNull);
12937 expect(functionType.typeParameters, isNull);
12938 FormalParameterList parameterList = functionType.parameters;
12939 expect(parameterList, isNotNull);
12940 expect(parameterList.parameters, hasLength(0));
12941 }
12942
12943 void test_parseTypeAnnotation_function_noReturnType_parameters() {
12944 createParser('Function(int, int) v');
12945 GenericFunctionType functionType = parser.parseTypeAnnotation();
12946 expectNotNullIfNoErrors(functionType);
12947 listener.assertNoErrors();
12948 expect(functionType.returnType, isNull);
12949 expect(functionType.functionKeyword, isNotNull);
12950 expect(functionType.typeParameters, isNull);
12951 FormalParameterList parameterList = functionType.parameters;
12952 expect(parameterList, isNotNull);
12953 NodeList<FormalParameter> parameters = parameterList.parameters;
12954 expect(parameters, hasLength(2));
12955
12956 expect(parameters[0], new isInstanceOf<SimpleFormalParameter>());
12957 SimpleFormalParameter parameter = parameters[0];
12958 expect(parameter.identifier, isNull);
12959 expect(parameter.type, new isInstanceOf<TypeName>());
12960 expect((parameter.type as TypeName).name.name, 'int');
12961
12962 expect(parameters[1], new isInstanceOf<SimpleFormalParameter>());
12963 parameter = parameters[1];
12964 expect(parameter.identifier, isNull);
12965 expect(parameter.type, new isInstanceOf<TypeName>());
12966 expect((parameter.type as TypeName).name.name, 'int');
12967 }
12968
12969 void test_parseTypeAnnotation_function_noReturnType_typeParameters() {
12970 createParser('Function<S, T>()');
12971 GenericFunctionType functionType = parser.parseTypeAnnotation();
12972 expectNotNullIfNoErrors(functionType);
12973 listener.assertNoErrors();
12974 expect(functionType.returnType, isNull);
12975 expect(functionType.functionKeyword, isNotNull);
12976 TypeParameterList typeParameters = functionType.typeParameters;
12977 expect(typeParameters, isNotNull);
12978 expect(typeParameters.typeParameters, hasLength(2));
12979 FormalParameterList parameterList = functionType.parameters;
12980 expect(parameterList, isNotNull);
12981 expect(parameterList.parameters, hasLength(0));
12982 }
12983
12984 void
12985 test_parseTypeAnnotation_function_noReturnType_typeParameters_parameters() {
12986 createParser('Function<T>(String, {T t})');
12987 GenericFunctionType functionType = parser.parseTypeAnnotation();
12988 expectNotNullIfNoErrors(functionType);
12989 listener.assertNoErrors();
12990 expect(functionType.returnType, isNull);
12991 expect(functionType.functionKeyword, isNotNull);
12992 TypeParameterList typeParameters = functionType.typeParameters;
12993 expect(typeParameters, isNotNull);
12994 expect(typeParameters.typeParameters, hasLength(1));
12995 FormalParameterList parameterList = functionType.parameters;
12996 expect(parameterList, isNotNull);
12997 expect(parameterList.parameters, hasLength(2));
12998 }
12999
13000 void test_parseTypeAnnotation_function_returnType_function() {
13001 createParser('A Function(B, C) Function(D) v');
13002 GenericFunctionType functionType = parser.parseTypeAnnotation();
13003 expectNotNullIfNoErrors(functionType);
13004 listener.assertNoErrors();
13005 }
13006
13007 void test_parseTypeAnnotation_function_returnType_noParameters() {
13008 createParser('List<int> Function()');
13009 GenericFunctionType functionType = parser.parseTypeAnnotation();
13010 expectNotNullIfNoErrors(functionType);
13011 listener.assertNoErrors();
13012 expect(functionType.returnType, isNotNull);
13013 expect(functionType.functionKeyword, isNotNull);
13014 expect(functionType.typeParameters, isNull);
13015 FormalParameterList parameterList = functionType.parameters;
13016 expect(parameterList, isNotNull);
13017 expect(parameterList.parameters, hasLength(0));
13018 }
13019
13020 void test_parseTypeAnnotation_function_returnType_parameters() {
13021 createParser('List<int> Function(String s, int i)');
13022 GenericFunctionType functionType = parser.parseTypeAnnotation();
13023 expectNotNullIfNoErrors(functionType);
13024 listener.assertNoErrors();
13025 expect(functionType.returnType, isNotNull);
13026 expect(functionType.functionKeyword, isNotNull);
13027 expect(functionType.typeParameters, isNull);
13028 FormalParameterList parameterList = functionType.parameters;
13029 expect(parameterList, isNotNull);
13030 NodeList<FormalParameter> parameters = parameterList.parameters;
13031 expect(parameters, hasLength(2));
13032
13033 expect(parameters[0], new isInstanceOf<SimpleFormalParameter>());
13034 SimpleFormalParameter parameter = parameters[0];
13035 expect(parameter.identifier, isNotNull);
13036 expect(parameter.identifier.name, 's');
13037 expect(parameter.type, new isInstanceOf<TypeName>());
13038 expect((parameter.type as TypeName).name.name, 'String');
13039
13040 expect(parameters[1], new isInstanceOf<SimpleFormalParameter>());
13041 parameter = parameters[1];
13042 expect(parameter.identifier, isNotNull);
13043 expect(parameter.identifier.name, 'i');
13044 expect(parameter.type, new isInstanceOf<TypeName>());
13045 expect((parameter.type as TypeName).name.name, 'int');
13046 }
13047
13048 void test_parseTypeAnnotation_function_returnType_simple() {
13049 createParser('A Function(B, C) v');
13050 GenericFunctionType functionType = parser.parseTypeAnnotation();
13051 expectNotNullIfNoErrors(functionType);
13052 listener.assertNoErrors();
13053 }
13054
13055 void test_parseTypeAnnotation_function_returnType_typeParameters() {
13056 createParser('List<T> Function<T>()');
13057 GenericFunctionType functionType = parser.parseTypeAnnotation();
13058 expectNotNullIfNoErrors(functionType);
13059 listener.assertNoErrors();
13060 expect(functionType.returnType, isNotNull);
13061 expect(functionType.functionKeyword, isNotNull);
13062 TypeParameterList typeParameters = functionType.typeParameters;
13063 expect(typeParameters, isNotNull);
13064 expect(typeParameters.typeParameters, hasLength(1));
13065 FormalParameterList parameterList = functionType.parameters;
13066 expect(parameterList, isNotNull);
13067 expect(parameterList.parameters, hasLength(0));
13068 }
13069
13070 void
13071 test_parseTypeAnnotation_function_returnType_typeParameters_parameters() {
13072 createParser('List<T> Function<T>(String s, [T])');
13073 GenericFunctionType functionType = parser.parseTypeAnnotation();
13074 expectNotNullIfNoErrors(functionType);
13075 listener.assertNoErrors();
13076 expect(functionType.returnType, isNotNull);
13077 expect(functionType.functionKeyword, isNotNull);
13078 TypeParameterList typeParameters = functionType.typeParameters;
13079 expect(typeParameters, isNotNull);
13080 expect(typeParameters.typeParameters, hasLength(1));
13081 FormalParameterList parameterList = functionType.parameters;
13082 expect(parameterList, isNotNull);
13083 expect(parameterList.parameters, hasLength(2));
13084 }
13085
13086 void test_parseTypeAnnotation_function_returnType_withArguments() {
13087 createParser('A<B> Function(C) v');
13088 GenericFunctionType functionType = parser.parseTypeAnnotation();
13089 expectNotNullIfNoErrors(functionType);
13090 listener.assertNoErrors();
13091 }
13092
13093 void test_parseTypeAnnotation_named() {
13094 createParser('A<B> v');
13095 TypeName typeName = parser.parseTypeAnnotation();
13096 expectNotNullIfNoErrors(typeName);
13097 listener.assertNoErrors();
13098 }
13099
12643 void test_parseTypeArgumentList_empty() { 13100 void test_parseTypeArgumentList_empty() {
12644 createParser('<>'); 13101 createParser('<>');
12645 TypeArgumentList argumentList = parser.parseTypeArgumentList(); 13102 TypeArgumentList argumentList = parser.parseTypeArgumentList();
12646 expectNotNullIfNoErrors(argumentList); 13103 expectNotNullIfNoErrors(argumentList);
12647 listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_TYPE_NAME]); 13104 listener.assertErrorsWithCodes([ParserErrorCode.EXPECTED_TYPE_NAME]);
12648 expect(argumentList.leftBracket, isNotNull); 13105 expect(argumentList.leftBracket, isNotNull);
12649 expect(argumentList.arguments, hasLength(1)); 13106 expect(argumentList.arguments, hasLength(1));
12650 expect(argumentList.rightBracket, isNotNull); 13107 expect(argumentList.rightBracket, isNotNull);
12651 } 13108 }
12652 13109
(...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after
13461 CompilationUnit _parseDirectives(String source, 13918 CompilationUnit _parseDirectives(String source,
13462 [List<ErrorCode> errorCodes = const <ErrorCode>[]]) { 13919 [List<ErrorCode> errorCodes = const <ErrorCode>[]]) {
13463 createParser(source); 13920 createParser(source);
13464 CompilationUnit unit = parser.parseDirectives2(); 13921 CompilationUnit unit = parser.parseDirectives2();
13465 expect(unit, isNotNull); 13922 expect(unit, isNotNull);
13466 expect(unit.declarations, hasLength(0)); 13923 expect(unit.declarations, hasLength(0));
13467 listener.assertErrorsWithCodes(errorCodes); 13924 listener.assertErrorsWithCodes(errorCodes);
13468 return unit; 13925 return unit;
13469 } 13926 }
13470 } 13927 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/parser.dart ('k') | tests/language/language_analyzer2.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698