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

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

Issue 2703553003: Create a new class for parser tests that test top level constructs. (Closed)
Patch Set: Created 3 years, 10 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 | « no previous file | 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 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 12 matching lines...) Expand all
23 23
24 import 'test_support.dart'; 24 import 'test_support.dart';
25 25
26 main() { 26 main() {
27 defineReflectiveSuite(() { 27 defineReflectiveSuite(() {
28 defineReflectiveTests(ComplexParserTest); 28 defineReflectiveTests(ComplexParserTest);
29 defineReflectiveTests(ErrorParserTest); 29 defineReflectiveTests(ErrorParserTest);
30 defineReflectiveTests(NonErrorParserTest); 30 defineReflectiveTests(NonErrorParserTest);
31 defineReflectiveTests(RecoveryParserTest); 31 defineReflectiveTests(RecoveryParserTest);
32 defineReflectiveTests(SimpleParserTest); 32 defineReflectiveTests(SimpleParserTest);
33 defineReflectiveTests(TopLevelParserTest);
33 }); 34 });
34 } 35 }
35 36
36 /** 37 /**
37 * Abstract base class for parser tests, which does not make assumptions about 38 * Abstract base class for parser tests, which does not make assumptions about
38 * which parser is used. 39 * which parser is used.
39 */ 40 */
40 abstract class AbstractParserTestCase { 41 abstract class AbstractParserTestCase {
41 void set enableGenericMethodComments(bool value); 42 void set enableGenericMethodComments(bool value);
42 43
(...skipping 2892 matching lines...) Expand 10 before | Expand all | Expand 10 after
2935 } finally { 2936 } finally {
2936 ParserTestCase.parseFunctionBodies = true; 2937 ParserTestCase.parseFunctionBodies = true;
2937 } 2938 }
2938 } 2939 }
2939 } 2940 }
2940 2941
2941 /** 2942 /**
2942 * Implementation of [AbstractParserTestCase] specialized for testing the 2943 * Implementation of [AbstractParserTestCase] specialized for testing the
2943 * analyzer parser. 2944 * analyzer parser.
2944 */ 2945 */
2945 class ParserTestCase extends EngineTestCase implements AbstractParserTestCase { 2946 class ParserTestCase extends EngineTestCase
2947 with ParserTestHelpers
2948 implements AbstractParserTestCase {
2946 /** 2949 /**
2947 * A flag indicating whether parser is to parse function bodies. 2950 * A flag indicating whether parser is to parse function bodies.
2948 */ 2951 */
2949 static bool parseFunctionBodies = true; 2952 static bool parseFunctionBodies = true;
2950 2953
2951 /** 2954 /**
2952 * A flag indicating whether the parser is to parse asserts in the initializer 2955 * A flag indicating whether the parser is to parse asserts in the initializer
2953 * list of a constructor. 2956 * list of a constructor.
2954 */ 2957 */
2955 bool enableAssertInitializer = false; 2958 bool enableAssertInitializer = false;
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
3169 } 3172 }
3170 3173
3171 @override 3174 @override
3172 void setUp() { 3175 void setUp() {
3173 super.setUp(); 3176 super.setUp();
3174 parseFunctionBodies = true; 3177 parseFunctionBodies = true;
3175 } 3178 }
3176 } 3179 }
3177 3180
3178 /** 3181 /**
3182 * Helper methods that aid in parser tests.
3183 *
3184 * Intended to be mixed in to parser test case classes.
3185 */
3186 class ParserTestHelpers {
3187 void expectCommentText(Comment comment, String expectedText) {
3188 expect(comment.beginToken, same(comment.endToken));
3189 expect(comment.beginToken.lexeme, expectedText);
3190 }
3191
3192 void expectDottedName(DottedName name, List<String> expectedComponents) {
3193 int count = expectedComponents.length;
3194 NodeList<SimpleIdentifier> components = name.components;
3195 expect(components, hasLength(count));
3196 for (int i = 0; i < count; i++) {
3197 SimpleIdentifier component = components[i];
3198 expect(component, isNotNull);
3199 expect(component.name, expectedComponents[i]);
3200 }
3201 }
3202 }
3203
3204 /**
3179 * The class `RecoveryParserTest` defines parser tests that test the parsing of invalid code 3205 * The class `RecoveryParserTest` defines parser tests that test the parsing of invalid code
3180 * sequences to ensure that the correct recovery steps are taken in the parser. 3206 * sequences to ensure that the correct recovery steps are taken in the parser.
3181 */ 3207 */
3182 @reflectiveTest 3208 @reflectiveTest
3183 class RecoveryParserTest extends ParserTestCase { 3209 class RecoveryParserTest extends ParserTestCase {
3184 void test_additiveExpression_missing_LHS() { 3210 void test_additiveExpression_missing_LHS() {
3185 BinaryExpression expression = 3211 BinaryExpression expression =
3186 parseExpression("+ y", [ParserErrorCode.MISSING_IDENTIFIER]); 3212 parseExpression("+ y", [ParserErrorCode.MISSING_IDENTIFIER]);
3187 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, 3213 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
3188 SimpleIdentifier, expression.leftOperand); 3214 SimpleIdentifier, expression.leftOperand);
(...skipping 1295 matching lines...) Expand 10 before | Expand all | Expand 10 after
4484 expect(identifier.isSynthetic, isTrue); 4510 expect(identifier.isSynthetic, isTrue);
4485 } 4511 }
4486 4512
4487 void test_createSyntheticStringLiteral() { 4513 void test_createSyntheticStringLiteral() {
4488 createParser(''); 4514 createParser('');
4489 SimpleStringLiteral literal = parser.createSyntheticStringLiteral(); 4515 SimpleStringLiteral literal = parser.createSyntheticStringLiteral();
4490 expectNotNullIfNoErrors(literal); 4516 expectNotNullIfNoErrors(literal);
4491 expect(literal.isSynthetic, isTrue); 4517 expect(literal.isSynthetic, isTrue);
4492 } 4518 }
4493 4519
4494 void test_function_literal_allowed_at_toplevel() {
4495 parseCompilationUnit("var x = () {};");
4496 }
4497
4498 void
4499 test_function_literal_allowed_in_ArgumentList_in_ConstructorFieldInitializ er() {
4500 parseCompilationUnit("class C { C() : a = f(() {}); }");
4501 }
4502
4503 void
4504 test_function_literal_allowed_in_IndexExpression_in_ConstructorFieldInitia lizer() {
4505 parseCompilationUnit("class C { C() : a = x[() {}]; }");
4506 }
4507
4508 void
4509 test_function_literal_allowed_in_ListLiteral_in_ConstructorFieldInitialize r() {
4510 parseCompilationUnit("class C { C() : a = [() {}]; }");
4511 }
4512
4513 void
4514 test_function_literal_allowed_in_MapLiteral_in_ConstructorFieldInitializer () {
4515 parseCompilationUnit("class C { C() : a = {'key': () {}}; }");
4516 }
4517
4518 void
4519 test_function_literal_allowed_in_ParenthesizedExpression_in_ConstructorFie ldInitializer() {
4520 parseCompilationUnit("class C { C() : a = (() {}); }");
4521 }
4522
4523 void
4524 test_function_literal_allowed_in_StringInterpolation_in_ConstructorFieldIn itializer() {
4525 parseCompilationUnit("class C { C() : a = \"\${(){}}\"; }");
4526 }
4527
4528 void test_import_as_show() {
4529 parseCompilationUnit("import 'dart:math' as M show E;");
4530 }
4531
4532 void test_import_show_hide() {
4533 parseCompilationUnit(
4534 "import 'import1_lib.dart' show hide, show hide ugly;");
4535 }
4536
4537 void test_isFunctionDeclaration_nameButNoReturn_block() { 4520 void test_isFunctionDeclaration_nameButNoReturn_block() {
4538 expect(_isFunctionDeclaration("f() {}"), isTrue); 4521 expect(_isFunctionDeclaration("f() {}"), isTrue);
4539 } 4522 }
4540 4523
4541 void test_isFunctionDeclaration_nameButNoReturn_expression() { 4524 void test_isFunctionDeclaration_nameButNoReturn_expression() {
4542 expect(_isFunctionDeclaration("f() => e"), isTrue); 4525 expect(_isFunctionDeclaration("f() => e"), isTrue);
4543 } 4526 }
4544 4527
4545 void test_isFunctionDeclaration_nameButNoReturn_typeParameters_block() { 4528 void test_isFunctionDeclaration_nameButNoReturn_typeParameters_block() {
4546 expect(_isFunctionDeclaration("f<E>() {}"), isTrue); 4529 expect(_isFunctionDeclaration("f<E>() {}"), isTrue);
(...skipping 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after
5727 Expression expression = parser.parseCascadeSection(); 5710 Expression expression = parser.parseCascadeSection();
5728 expectNotNullIfNoErrors(expression); 5711 expectNotNullIfNoErrors(expression);
5729 listener.assertNoErrors(); 5712 listener.assertNoErrors();
5730 expect(expression, new isInstanceOf<PropertyAccess>()); 5713 expect(expression, new isInstanceOf<PropertyAccess>());
5731 PropertyAccess section = expression; 5714 PropertyAccess section = expression;
5732 expect(section.target, isNotNull); 5715 expect(section.target, isNotNull);
5733 expect(section.operator, isNotNull); 5716 expect(section.operator, isNotNull);
5734 expect(section.propertyName, isNotNull); 5717 expect(section.propertyName, isNotNull);
5735 } 5718 }
5736 5719
5737 void test_parseClassDeclaration_abstract() {
5738 createParser('abstract class A {}');
5739 CompilationUnitMember member = parseFullCompilationUnitMember();
5740 expectNotNullIfNoErrors(member);
5741 listener.assertNoErrors();
5742 expect(member, new isInstanceOf<ClassDeclaration>());
5743 ClassDeclaration declaration = member;
5744 expect(declaration.documentationComment, isNull);
5745 expect(declaration.abstractKeyword, isNotNull);
5746 expect(declaration.extendsClause, isNull);
5747 expect(declaration.implementsClause, isNull);
5748 expect(declaration.classKeyword, isNotNull);
5749 expect(declaration.leftBracket, isNotNull);
5750 expect(declaration.name, isNotNull);
5751 expect(declaration.members, hasLength(0));
5752 expect(declaration.rightBracket, isNotNull);
5753 expect(declaration.typeParameters, isNull);
5754 }
5755
5756 void test_parseClassDeclaration_empty() {
5757 createParser('class A {}');
5758 CompilationUnitMember member = parseFullCompilationUnitMember();
5759 expectNotNullIfNoErrors(member);
5760 listener.assertNoErrors();
5761 expect(member, new isInstanceOf<ClassDeclaration>());
5762 ClassDeclaration declaration = member;
5763 expect(declaration.documentationComment, isNull);
5764 expect(declaration.abstractKeyword, isNull);
5765 expect(declaration.extendsClause, isNull);
5766 expect(declaration.implementsClause, isNull);
5767 expect(declaration.classKeyword, isNotNull);
5768 expect(declaration.leftBracket, isNotNull);
5769 expect(declaration.name, isNotNull);
5770 expect(declaration.members, hasLength(0));
5771 expect(declaration.rightBracket, isNotNull);
5772 expect(declaration.typeParameters, isNull);
5773 }
5774
5775 void test_parseClassDeclaration_extends() {
5776 createParser('class A extends B {}');
5777 CompilationUnitMember member = parseFullCompilationUnitMember();
5778 expectNotNullIfNoErrors(member);
5779 listener.assertNoErrors();
5780 expect(member, new isInstanceOf<ClassDeclaration>());
5781 ClassDeclaration declaration = member;
5782 expect(declaration.documentationComment, isNull);
5783 expect(declaration.abstractKeyword, isNull);
5784 expect(declaration.extendsClause, isNotNull);
5785 expect(declaration.implementsClause, isNull);
5786 expect(declaration.classKeyword, isNotNull);
5787 expect(declaration.leftBracket, isNotNull);
5788 expect(declaration.name, isNotNull);
5789 expect(declaration.members, hasLength(0));
5790 expect(declaration.rightBracket, isNotNull);
5791 expect(declaration.typeParameters, isNull);
5792 }
5793
5794 void test_parseClassDeclaration_extendsAndImplements() {
5795 createParser('class A extends B implements C {}');
5796 CompilationUnitMember member = parseFullCompilationUnitMember();
5797 expectNotNullIfNoErrors(member);
5798 listener.assertNoErrors();
5799 expect(member, new isInstanceOf<ClassDeclaration>());
5800 ClassDeclaration declaration = member;
5801 expect(declaration.documentationComment, isNull);
5802 expect(declaration.abstractKeyword, isNull);
5803 expect(declaration.extendsClause, isNotNull);
5804 expect(declaration.implementsClause, isNotNull);
5805 expect(declaration.classKeyword, isNotNull);
5806 expect(declaration.leftBracket, isNotNull);
5807 expect(declaration.name, isNotNull);
5808 expect(declaration.members, hasLength(0));
5809 expect(declaration.rightBracket, isNotNull);
5810 expect(declaration.typeParameters, isNull);
5811 }
5812
5813 void test_parseClassDeclaration_extendsAndWith() {
5814 createParser('class A extends B with C {}');
5815 CompilationUnitMember member = parseFullCompilationUnitMember();
5816 expectNotNullIfNoErrors(member);
5817 listener.assertNoErrors();
5818 expect(member, new isInstanceOf<ClassDeclaration>());
5819 ClassDeclaration declaration = member;
5820 expect(declaration.documentationComment, isNull);
5821 expect(declaration.abstractKeyword, isNull);
5822 expect(declaration.classKeyword, isNotNull);
5823 expect(declaration.name, isNotNull);
5824 expect(declaration.typeParameters, isNull);
5825 expect(declaration.extendsClause, isNotNull);
5826 expect(declaration.withClause, isNotNull);
5827 expect(declaration.implementsClause, isNull);
5828 expect(declaration.leftBracket, isNotNull);
5829 expect(declaration.members, hasLength(0));
5830 expect(declaration.rightBracket, isNotNull);
5831 }
5832
5833 void test_parseClassDeclaration_extendsAndWithAndImplements() {
5834 createParser('class A extends B with C implements D {}');
5835 CompilationUnitMember member = parseFullCompilationUnitMember();
5836 expectNotNullIfNoErrors(member);
5837 listener.assertNoErrors();
5838 expect(member, new isInstanceOf<ClassDeclaration>());
5839 ClassDeclaration declaration = member;
5840 expect(declaration.documentationComment, isNull);
5841 expect(declaration.abstractKeyword, isNull);
5842 expect(declaration.classKeyword, isNotNull);
5843 expect(declaration.name, isNotNull);
5844 expect(declaration.typeParameters, isNull);
5845 expect(declaration.extendsClause, isNotNull);
5846 expect(declaration.withClause, isNotNull);
5847 expect(declaration.implementsClause, isNotNull);
5848 expect(declaration.leftBracket, isNotNull);
5849 expect(declaration.members, hasLength(0));
5850 expect(declaration.rightBracket, isNotNull);
5851 }
5852
5853 void test_parseClassDeclaration_implements() {
5854 createParser('class A implements C {}');
5855 CompilationUnitMember member = parseFullCompilationUnitMember();
5856 expectNotNullIfNoErrors(member);
5857 listener.assertNoErrors();
5858 expect(member, new isInstanceOf<ClassDeclaration>());
5859 ClassDeclaration declaration = member;
5860 expect(declaration.documentationComment, isNull);
5861 expect(declaration.abstractKeyword, isNull);
5862 expect(declaration.extendsClause, isNull);
5863 expect(declaration.implementsClause, isNotNull);
5864 expect(declaration.classKeyword, isNotNull);
5865 expect(declaration.leftBracket, isNotNull);
5866 expect(declaration.name, isNotNull);
5867 expect(declaration.members, hasLength(0));
5868 expect(declaration.rightBracket, isNotNull);
5869 expect(declaration.typeParameters, isNull);
5870 }
5871
5872 void test_parseClassDeclaration_native() {
5873 createParser('class A native "nativeValue" {}');
5874 CompilationUnitMember member = parseFullCompilationUnitMember();
5875 expectNotNullIfNoErrors(member);
5876 listener.assertNoErrors();
5877 expect(member, new isInstanceOf<ClassDeclaration>());
5878 ClassDeclaration declaration = member;
5879 NativeClause nativeClause = declaration.nativeClause;
5880 expect(nativeClause, isNotNull);
5881 expect(nativeClause.nativeKeyword, isNotNull);
5882 expect(nativeClause.name.stringValue, "nativeValue");
5883 expect(nativeClause.beginToken, same(nativeClause.nativeKeyword));
5884 expect(nativeClause.endToken, same(nativeClause.name.endToken));
5885 }
5886
5887 void test_parseClassDeclaration_nonEmpty() {
5888 createParser('class A {var f;}');
5889 CompilationUnitMember member = parseFullCompilationUnitMember();
5890 expectNotNullIfNoErrors(member);
5891 listener.assertNoErrors();
5892 expect(member, new isInstanceOf<ClassDeclaration>());
5893 ClassDeclaration declaration = member;
5894 expect(declaration.documentationComment, isNull);
5895 expect(declaration.abstractKeyword, isNull);
5896 expect(declaration.extendsClause, isNull);
5897 expect(declaration.implementsClause, isNull);
5898 expect(declaration.classKeyword, isNotNull);
5899 expect(declaration.leftBracket, isNotNull);
5900 expect(declaration.name, isNotNull);
5901 expect(declaration.members, hasLength(1));
5902 expect(declaration.rightBracket, isNotNull);
5903 expect(declaration.typeParameters, isNull);
5904 }
5905
5906 void test_parseClassDeclaration_typeAlias_implementsC() {
5907 createParser('class A = Object with B implements C;');
5908 CompilationUnitMember member = parseFullCompilationUnitMember();
5909 expectNotNullIfNoErrors(member);
5910 listener.assertNoErrors();
5911 expect(member, new isInstanceOf<ClassTypeAlias>());
5912 ClassTypeAlias typeAlias = member;
5913 expect(typeAlias.typedefKeyword, isNotNull);
5914 expect(typeAlias.name, isNotNull);
5915 expect(typeAlias.typeParameters, isNull);
5916 expect(typeAlias.withClause, isNotNull);
5917 expect(typeAlias.implementsClause, isNotNull);
5918 expect(typeAlias.implementsClause.implementsKeyword, isNotNull);
5919 expect(typeAlias.implementsClause.interfaces.length, 1);
5920 expect(typeAlias.semicolon, isNotNull);
5921 }
5922
5923 void test_parseClassDeclaration_typeAlias_withB() {
5924 createParser('class A = Object with B;');
5925 CompilationUnitMember member = parseFullCompilationUnitMember();
5926 expectNotNullIfNoErrors(member);
5927 listener.assertNoErrors();
5928 expect(member, new isInstanceOf<ClassTypeAlias>());
5929 ClassTypeAlias typeAlias = member;
5930 expect(typeAlias.typedefKeyword, isNotNull);
5931 expect(typeAlias.name, isNotNull);
5932 expect(typeAlias.typeParameters, isNull);
5933 expect(typeAlias.withClause, isNotNull);
5934 expect(typeAlias.withClause.withKeyword, isNotNull);
5935 expect(typeAlias.withClause.mixinTypes.length, 1);
5936 expect(typeAlias.implementsClause, isNull);
5937 expect(typeAlias.semicolon, isNotNull);
5938 }
5939
5940 void test_parseClassDeclaration_typeParameters() {
5941 createParser('class A<B> {}');
5942 CompilationUnitMember member = parseFullCompilationUnitMember();
5943 expectNotNullIfNoErrors(member);
5944 listener.assertNoErrors();
5945 expect(member, new isInstanceOf<ClassDeclaration>());
5946 ClassDeclaration declaration = member;
5947 expect(declaration.documentationComment, isNull);
5948 expect(declaration.abstractKeyword, isNull);
5949 expect(declaration.extendsClause, isNull);
5950 expect(declaration.implementsClause, isNull);
5951 expect(declaration.classKeyword, isNotNull);
5952 expect(declaration.leftBracket, isNotNull);
5953 expect(declaration.name, isNotNull);
5954 expect(declaration.members, hasLength(0));
5955 expect(declaration.rightBracket, isNotNull);
5956 expect(declaration.typeParameters, isNotNull);
5957 expect(declaration.typeParameters.typeParameters, hasLength(1));
5958 }
5959
5960 void test_parseClassMember_constructor_withInitializers() { 5720 void test_parseClassMember_constructor_withInitializers() {
5961 // TODO(brianwilkerson) Test other kinds of class members: fields, getters 5721 // TODO(brianwilkerson) Test other kinds of class members: fields, getters
5962 // and setters. 5722 // and setters.
5963 createParser('C(_, _\$, this.__) : _a = _ + _\$ {}'); 5723 createParser('C(_, _\$, this.__) : _a = _ + _\$ {}');
5964 ClassMember member = parser.parseClassMember('C'); 5724 ClassMember member = parser.parseClassMember('C');
5965 expectNotNullIfNoErrors(member); 5725 expectNotNullIfNoErrors(member);
5966 listener.assertNoErrors(); 5726 listener.assertNoErrors();
5967 expect(member, new isInstanceOf<ConstructorDeclaration>()); 5727 expect(member, new isInstanceOf<ConstructorDeclaration>());
5968 ConstructorDeclaration constructor = member; 5728 ConstructorDeclaration constructor = member;
5969 expect(constructor.body, isNotNull); 5729 expect(constructor.body, isNotNull);
(...skipping 1283 matching lines...) Expand 10 before | Expand all | Expand 10 after
7253 List<CommentReference> references = parser.parseCommentReferences(tokens); 7013 List<CommentReference> references = parser.parseCommentReferences(tokens);
7254 expectNotNullIfNoErrors(references); 7014 expectNotNullIfNoErrors(references);
7255 listener.assertNoErrors(); 7015 listener.assertNoErrors();
7256 expect(references, hasLength(1)); 7016 expect(references, hasLength(1));
7257 CommentReference reference = references[0]; 7017 CommentReference reference = references[0];
7258 expect(reference, isNotNull); 7018 expect(reference, isNotNull);
7259 expect(reference.identifier, isNotNull); 7019 expect(reference.identifier, isNotNull);
7260 expect(reference.offset, 15); 7020 expect(reference.offset, 15);
7261 } 7021 }
7262 7022
7263 void test_parseCompilationUnit_abstractAsPrefix_parameterized() {
7264 createParser('abstract<dynamic> _abstract = new abstract.A();');
7265 CompilationUnit unit = parser.parseCompilationUnit2();
7266 expectNotNullIfNoErrors(unit);
7267 listener.assertNoErrors();
7268 expect(unit.scriptTag, isNull);
7269 expect(unit.directives, hasLength(0));
7270 expect(unit.declarations, hasLength(1));
7271 }
7272
7273 void test_parseCompilationUnit_builtIn_asFunctionName() {
7274 parseCompilationUnit('abstract(x) => 0;');
7275 parseCompilationUnit('as(x) => 0;');
7276 parseCompilationUnit('dynamic(x) => 0;');
7277 parseCompilationUnit('export(x) => 0;');
7278 parseCompilationUnit('external(x) => 0;');
7279 parseCompilationUnit('factory(x) => 0;');
7280 parseCompilationUnit('get(x) => 0;');
7281 parseCompilationUnit('implements(x) => 0;');
7282 parseCompilationUnit('import(x) => 0;');
7283 parseCompilationUnit('library(x) => 0;');
7284 parseCompilationUnit('operator(x) => 0;');
7285 parseCompilationUnit('part(x) => 0;');
7286 parseCompilationUnit('set(x) => 0;');
7287 parseCompilationUnit('static(x) => 0;');
7288 parseCompilationUnit('typedef(x) => 0;');
7289 }
7290
7291 void test_parseCompilationUnit_directives_multiple() {
7292 createParser("library l;\npart 'a.dart';");
7293 CompilationUnit unit = parser.parseCompilationUnit2();
7294 expectNotNullIfNoErrors(unit);
7295 listener.assertNoErrors();
7296 expect(unit.scriptTag, isNull);
7297 expect(unit.directives, hasLength(2));
7298 expect(unit.declarations, hasLength(0));
7299 }
7300
7301 void test_parseCompilationUnit_directives_single() {
7302 createParser('library l;');
7303 CompilationUnit unit = parser.parseCompilationUnit2();
7304 expectNotNullIfNoErrors(unit);
7305 listener.assertNoErrors();
7306 expect(unit.scriptTag, isNull);
7307 expect(unit.directives, hasLength(1));
7308 expect(unit.declarations, hasLength(0));
7309 }
7310
7311 void test_parseCompilationUnit_empty() {
7312 createParser('');
7313 CompilationUnit unit = parser.parseCompilationUnit2();
7314 expectNotNullIfNoErrors(unit);
7315 listener.assertNoErrors();
7316 expect(unit.scriptTag, isNull);
7317 expect(unit.directives, hasLength(0));
7318 expect(unit.declarations, hasLength(0));
7319 }
7320
7321 void test_parseCompilationUnit_exportAsPrefix() {
7322 createParser('export.A _export = new export.A();');
7323 CompilationUnit unit = parser.parseCompilationUnit2();
7324 expectNotNullIfNoErrors(unit);
7325 listener.assertNoErrors();
7326 expect(unit.scriptTag, isNull);
7327 expect(unit.directives, hasLength(0));
7328 expect(unit.declarations, hasLength(1));
7329 }
7330
7331 void test_parseCompilationUnit_exportAsPrefix_parameterized() {
7332 createParser('export<dynamic> _export = new export.A();');
7333 CompilationUnit unit = parser.parseCompilationUnit2();
7334 expectNotNullIfNoErrors(unit);
7335 listener.assertNoErrors();
7336 expect(unit.scriptTag, isNull);
7337 expect(unit.directives, hasLength(0));
7338 expect(unit.declarations, hasLength(1));
7339 }
7340
7341 void test_parseCompilationUnit_operatorAsPrefix_parameterized() {
7342 createParser('operator<dynamic> _operator = new operator.A();');
7343 CompilationUnit unit = parser.parseCompilationUnit2();
7344 expectNotNullIfNoErrors(unit);
7345 listener.assertNoErrors();
7346 expect(unit.scriptTag, isNull);
7347 expect(unit.directives, hasLength(0));
7348 expect(unit.declarations, hasLength(1));
7349 }
7350
7351 void test_parseCompilationUnit_script() {
7352 createParser('#! /bin/dart');
7353 CompilationUnit unit = parser.parseCompilationUnit2();
7354 expectNotNullIfNoErrors(unit);
7355 listener.assertNoErrors();
7356 expect(unit.scriptTag, isNotNull);
7357 expect(unit.directives, hasLength(0));
7358 expect(unit.declarations, hasLength(0));
7359 }
7360
7361 void test_parseCompilationUnit_skipFunctionBody_withInterpolation() {
7362 ParserTestCase.parseFunctionBodies = false;
7363 createParser('f() { "\${n}"; }');
7364 CompilationUnit unit = parser.parseCompilationUnit2();
7365 expectNotNullIfNoErrors(unit);
7366 listener.assertNoErrors();
7367 expect(unit.scriptTag, isNull);
7368 expect(unit.declarations, hasLength(1));
7369 }
7370
7371 void test_parseCompilationUnit_topLevelDeclaration() {
7372 createParser('class A {}');
7373 CompilationUnit unit = parser.parseCompilationUnit2();
7374 expectNotNullIfNoErrors(unit);
7375 listener.assertNoErrors();
7376 expect(unit.scriptTag, isNull);
7377 expect(unit.directives, hasLength(0));
7378 expect(unit.declarations, hasLength(1));
7379 }
7380
7381 void test_parseCompilationUnit_typedefAsPrefix() {
7382 createParser('typedef.A _typedef = new typedef.A();');
7383 CompilationUnit unit = parser.parseCompilationUnit2();
7384 expectNotNullIfNoErrors(unit);
7385 listener.assertNoErrors();
7386 expect(unit.scriptTag, isNull);
7387 expect(unit.directives, hasLength(0));
7388 expect(unit.declarations, hasLength(1));
7389 }
7390
7391 void test_parseCompilationUnitMember_abstractAsPrefix() {
7392 createParser('abstract.A _abstract = new abstract.A();');
7393 CompilationUnitMember member = parseFullCompilationUnitMember();
7394 expectNotNullIfNoErrors(member);
7395 listener.assertNoErrors();
7396 expect(member, new isInstanceOf<TopLevelVariableDeclaration>());
7397 TopLevelVariableDeclaration declaration = member;
7398 expect(declaration.semicolon, isNotNull);
7399 expect(declaration.variables, isNotNull);
7400 }
7401
7402 void test_parseCompilationUnitMember_class() {
7403 createParser('class A {}');
7404 CompilationUnitMember member = parseFullCompilationUnitMember();
7405 expectNotNullIfNoErrors(member);
7406 listener.assertNoErrors();
7407 expect(member, new isInstanceOf<ClassDeclaration>());
7408 ClassDeclaration declaration = member;
7409 expect(declaration.name.name, "A");
7410 expect(declaration.members, hasLength(0));
7411 }
7412
7413 void test_parseCompilationUnitMember_classTypeAlias() {
7414 createParser('abstract class A = B with C;');
7415 CompilationUnitMember member = parseFullCompilationUnitMember();
7416 expectNotNullIfNoErrors(member);
7417 listener.assertNoErrors();
7418 expect(member, new isInstanceOf<ClassTypeAlias>());
7419 ClassTypeAlias declaration = member;
7420 expect(declaration.name.name, "A");
7421 expect(declaration.abstractKeyword, isNotNull);
7422 }
7423
7424 void test_parseCompilationUnitMember_constVariable() {
7425 createParser('const int x = 0;');
7426 CompilationUnitMember member = parseFullCompilationUnitMember();
7427 expectNotNullIfNoErrors(member);
7428 listener.assertNoErrors();
7429 expect(member, new isInstanceOf<TopLevelVariableDeclaration>());
7430 TopLevelVariableDeclaration declaration = member;
7431 expect(declaration.semicolon, isNotNull);
7432 expect(declaration.variables, isNotNull);
7433 }
7434
7435 void test_parseCompilationUnitMember_finalVariable() {
7436 createParser('final x = 0;');
7437 CompilationUnitMember member = parseFullCompilationUnitMember();
7438 expectNotNullIfNoErrors(member);
7439 listener.assertNoErrors();
7440 expect(member, new isInstanceOf<TopLevelVariableDeclaration>());
7441 TopLevelVariableDeclaration declaration = member;
7442 expect(declaration.semicolon, isNotNull);
7443 expect(declaration.variables, isNotNull);
7444 }
7445
7446 void test_parseCompilationUnitMember_function_external_noType() {
7447 createParser('external f();');
7448 CompilationUnitMember member = parseFullCompilationUnitMember();
7449 expectNotNullIfNoErrors(member);
7450 listener.assertNoErrors();
7451 expect(member, new isInstanceOf<FunctionDeclaration>());
7452 FunctionDeclaration declaration = member;
7453 expect(declaration.externalKeyword, isNotNull);
7454 expect(declaration.functionExpression, isNotNull);
7455 expect(declaration.propertyKeyword, isNull);
7456 }
7457
7458 void test_parseCompilationUnitMember_function_external_type() {
7459 createParser('external int f();');
7460 CompilationUnitMember member = parseFullCompilationUnitMember();
7461 expectNotNullIfNoErrors(member);
7462 listener.assertNoErrors();
7463 expect(member, new isInstanceOf<FunctionDeclaration>());
7464 FunctionDeclaration declaration = member;
7465 expect(declaration.externalKeyword, isNotNull);
7466 expect(declaration.functionExpression, isNotNull);
7467 expect(declaration.propertyKeyword, isNull);
7468 }
7469
7470 void test_parseCompilationUnitMember_function_generic_noReturnType() {
7471 createParser('f<E>() {}');
7472 CompilationUnitMember member = parseFullCompilationUnitMember();
7473 expectNotNullIfNoErrors(member);
7474 listener.assertNoErrors();
7475 expect(member, new isInstanceOf<FunctionDeclaration>());
7476 FunctionDeclaration declaration = member;
7477 expect(declaration.returnType, isNull);
7478 expect(declaration.functionExpression.typeParameters, isNotNull);
7479 }
7480
7481 void
7482 test_parseCompilationUnitMember_function_generic_noReturnType_annotated() {
7483 createParser('f<@a E>() {}');
7484 CompilationUnitMember member = parseFullCompilationUnitMember();
7485 expectNotNullIfNoErrors(member);
7486 listener.assertNoErrors();
7487 expect(member, new isInstanceOf<FunctionDeclaration>());
7488 FunctionDeclaration declaration = member;
7489 expect(declaration.returnType, isNull);
7490 expect(declaration.functionExpression.typeParameters, isNotNull);
7491 }
7492
7493 void test_parseCompilationUnitMember_function_generic_returnType() {
7494 createParser('E f<E>() {}');
7495 CompilationUnitMember member = parseFullCompilationUnitMember();
7496 expectNotNullIfNoErrors(member);
7497 listener.assertNoErrors();
7498 expect(member, new isInstanceOf<FunctionDeclaration>());
7499 FunctionDeclaration declaration = member;
7500 expect(declaration.returnType, isNotNull);
7501 expect(declaration.functionExpression.typeParameters, isNotNull);
7502 }
7503
7504 void test_parseCompilationUnitMember_function_generic_void() {
7505 createParser('void f<T>(T t) {}');
7506 CompilationUnitMember member = parseFullCompilationUnitMember();
7507 expectNotNullIfNoErrors(member);
7508 listener.assertNoErrors();
7509 expect(member, new isInstanceOf<FunctionDeclaration>());
7510 FunctionDeclaration declaration = member;
7511 expect(declaration.functionExpression, isNotNull);
7512 expect(declaration.propertyKeyword, isNull);
7513 }
7514
7515 void test_parseCompilationUnitMember_function_noType() {
7516 createParser('f() {}');
7517 CompilationUnitMember member = parseFullCompilationUnitMember();
7518 expectNotNullIfNoErrors(member);
7519 listener.assertNoErrors();
7520 expect(member, new isInstanceOf<FunctionDeclaration>());
7521 FunctionDeclaration declaration = member;
7522 expect(declaration.functionExpression, isNotNull);
7523 expect(declaration.propertyKeyword, isNull);
7524 }
7525
7526 void test_parseCompilationUnitMember_function_type() {
7527 createParser('int f() {}');
7528 CompilationUnitMember member = parseFullCompilationUnitMember();
7529 expectNotNullIfNoErrors(member);
7530 listener.assertNoErrors();
7531 expect(member, new isInstanceOf<FunctionDeclaration>());
7532 FunctionDeclaration declaration = member;
7533 expect(declaration.functionExpression, isNotNull);
7534 expect(declaration.propertyKeyword, isNull);
7535 }
7536
7537 void test_parseCompilationUnitMember_function_void() {
7538 createParser('void f() {}');
7539 CompilationUnitMember member = parseFullCompilationUnitMember();
7540 expectNotNullIfNoErrors(member);
7541 listener.assertNoErrors();
7542 expect(member, new isInstanceOf<FunctionDeclaration>());
7543 FunctionDeclaration declaration = member;
7544 expect(declaration.returnType, isNotNull);
7545 }
7546
7547 void test_parseCompilationUnitMember_getter_external_noType() {
7548 createParser('external get p;');
7549 CompilationUnitMember member = parseFullCompilationUnitMember();
7550 expectNotNullIfNoErrors(member);
7551 listener.assertNoErrors();
7552 expect(member, new isInstanceOf<FunctionDeclaration>());
7553 FunctionDeclaration declaration = member;
7554 expect(declaration.externalKeyword, isNotNull);
7555 expect(declaration.functionExpression, isNotNull);
7556 expect(declaration.propertyKeyword, isNotNull);
7557 }
7558
7559 void test_parseCompilationUnitMember_getter_external_type() {
7560 createParser('external int get p;');
7561 CompilationUnitMember member = parseFullCompilationUnitMember();
7562 expectNotNullIfNoErrors(member);
7563 listener.assertNoErrors();
7564 expect(member, new isInstanceOf<FunctionDeclaration>());
7565 FunctionDeclaration declaration = member;
7566 expect(declaration.externalKeyword, isNotNull);
7567 expect(declaration.functionExpression, isNotNull);
7568 expect(declaration.propertyKeyword, isNotNull);
7569 }
7570
7571 void test_parseCompilationUnitMember_getter_noType() {
7572 createParser('get p => 0;');
7573 CompilationUnitMember member = parseFullCompilationUnitMember();
7574 expectNotNullIfNoErrors(member);
7575 listener.assertNoErrors();
7576 expect(member, new isInstanceOf<FunctionDeclaration>());
7577 FunctionDeclaration declaration = member;
7578 expect(declaration.functionExpression, isNotNull);
7579 expect(declaration.propertyKeyword, isNotNull);
7580 }
7581
7582 void test_parseCompilationUnitMember_getter_type() {
7583 createParser('int get p => 0;');
7584 CompilationUnitMember member = parseFullCompilationUnitMember();
7585 expectNotNullIfNoErrors(member);
7586 listener.assertNoErrors();
7587 expect(member, new isInstanceOf<FunctionDeclaration>());
7588 FunctionDeclaration declaration = member;
7589 expect(declaration.functionExpression, isNotNull);
7590 expect(declaration.propertyKeyword, isNotNull);
7591 }
7592
7593 void test_parseCompilationUnitMember_setter_external_noType() {
7594 createParser('external set p(v);');
7595 CompilationUnitMember member = parseFullCompilationUnitMember();
7596 expectNotNullIfNoErrors(member);
7597 listener.assertNoErrors();
7598 expect(member, new isInstanceOf<FunctionDeclaration>());
7599 FunctionDeclaration declaration = member;
7600 expect(declaration.externalKeyword, isNotNull);
7601 expect(declaration.functionExpression, isNotNull);
7602 expect(declaration.propertyKeyword, isNotNull);
7603 }
7604
7605 void test_parseCompilationUnitMember_setter_external_type() {
7606 createParser('external void set p(int v);');
7607 CompilationUnitMember member = parseFullCompilationUnitMember();
7608 expectNotNullIfNoErrors(member);
7609 listener.assertNoErrors();
7610 expect(member, new isInstanceOf<FunctionDeclaration>());
7611 FunctionDeclaration declaration = member;
7612 expect(declaration.externalKeyword, isNotNull);
7613 expect(declaration.functionExpression, isNotNull);
7614 expect(declaration.propertyKeyword, isNotNull);
7615 }
7616
7617 void test_parseCompilationUnitMember_setter_noType() {
7618 createParser('set p(v) {}');
7619 CompilationUnitMember member = parseFullCompilationUnitMember();
7620 expectNotNullIfNoErrors(member);
7621 listener.assertNoErrors();
7622 expect(member, new isInstanceOf<FunctionDeclaration>());
7623 FunctionDeclaration declaration = member;
7624 expect(declaration.functionExpression, isNotNull);
7625 expect(declaration.propertyKeyword, isNotNull);
7626 }
7627
7628 void test_parseCompilationUnitMember_setter_type() {
7629 createParser('void set p(int v) {}');
7630 CompilationUnitMember member = parseFullCompilationUnitMember();
7631 expectNotNullIfNoErrors(member);
7632 listener.assertNoErrors();
7633 expect(member, new isInstanceOf<FunctionDeclaration>());
7634 FunctionDeclaration declaration = member;
7635 expect(declaration.functionExpression, isNotNull);
7636 expect(declaration.propertyKeyword, isNotNull);
7637 expect(declaration.returnType, isNotNull);
7638 }
7639
7640 void test_parseCompilationUnitMember_typeAlias_abstract() {
7641 createParser('abstract class C = S with M;');
7642 CompilationUnitMember member = parseFullCompilationUnitMember();
7643 expectNotNullIfNoErrors(member);
7644 listener.assertNoErrors();
7645 expect(member, new isInstanceOf<ClassTypeAlias>());
7646 ClassTypeAlias typeAlias = member;
7647 expect(typeAlias.typedefKeyword, isNotNull);
7648 expect(typeAlias.name.name, "C");
7649 expect(typeAlias.typeParameters, isNull);
7650 expect(typeAlias.equals, isNotNull);
7651 expect(typeAlias.abstractKeyword, isNotNull);
7652 expect(typeAlias.superclass.name.name, "S");
7653 expect(typeAlias.withClause, isNotNull);
7654 expect(typeAlias.implementsClause, isNull);
7655 expect(typeAlias.semicolon, isNotNull);
7656 }
7657
7658 void test_parseCompilationUnitMember_typeAlias_generic() {
7659 createParser('class C<E> = S<E> with M<E> implements I<E>;');
7660 CompilationUnitMember member = parseFullCompilationUnitMember();
7661 expectNotNullIfNoErrors(member);
7662 listener.assertNoErrors();
7663 expect(member, new isInstanceOf<ClassTypeAlias>());
7664 ClassTypeAlias typeAlias = member;
7665 expect(typeAlias.typedefKeyword, isNotNull);
7666 expect(typeAlias.name.name, "C");
7667 expect(typeAlias.typeParameters.typeParameters, hasLength(1));
7668 expect(typeAlias.equals, isNotNull);
7669 expect(typeAlias.abstractKeyword, isNull);
7670 expect(typeAlias.superclass.name.name, "S");
7671 expect(typeAlias.withClause, isNotNull);
7672 expect(typeAlias.implementsClause, isNotNull);
7673 expect(typeAlias.semicolon, isNotNull);
7674 }
7675
7676 void test_parseCompilationUnitMember_typeAlias_implements() {
7677 createParser('class C = S with M implements I;');
7678 CompilationUnitMember member = parseFullCompilationUnitMember();
7679 expectNotNullIfNoErrors(member);
7680 listener.assertNoErrors();
7681 expect(member, new isInstanceOf<ClassTypeAlias>());
7682 ClassTypeAlias typeAlias = member;
7683 expect(typeAlias.typedefKeyword, isNotNull);
7684 expect(typeAlias.name.name, "C");
7685 expect(typeAlias.typeParameters, isNull);
7686 expect(typeAlias.equals, isNotNull);
7687 expect(typeAlias.abstractKeyword, isNull);
7688 expect(typeAlias.superclass.name.name, "S");
7689 expect(typeAlias.withClause, isNotNull);
7690 expect(typeAlias.implementsClause, isNotNull);
7691 expect(typeAlias.semicolon, isNotNull);
7692 }
7693
7694 void test_parseCompilationUnitMember_typeAlias_noImplements() {
7695 createParser('class C = S with M;');
7696 CompilationUnitMember member = parseFullCompilationUnitMember();
7697 expectNotNullIfNoErrors(member);
7698 listener.assertNoErrors();
7699 expect(member, new isInstanceOf<ClassTypeAlias>());
7700 ClassTypeAlias typeAlias = member;
7701 expect(typeAlias.typedefKeyword, isNotNull);
7702 expect(typeAlias.name.name, "C");
7703 expect(typeAlias.typeParameters, isNull);
7704 expect(typeAlias.equals, isNotNull);
7705 expect(typeAlias.abstractKeyword, isNull);
7706 expect(typeAlias.superclass.name.name, "S");
7707 expect(typeAlias.withClause, isNotNull);
7708 expect(typeAlias.implementsClause, isNull);
7709 expect(typeAlias.semicolon, isNotNull);
7710 }
7711
7712 void test_parseCompilationUnitMember_typedef() {
7713 createParser('typedef F();');
7714 CompilationUnitMember member = parseFullCompilationUnitMember();
7715 expectNotNullIfNoErrors(member);
7716 listener.assertNoErrors();
7717 expect(member, new isInstanceOf<FunctionTypeAlias>());
7718 FunctionTypeAlias typeAlias = member;
7719 expect(typeAlias.name.name, "F");
7720 expect(typeAlias.parameters.parameters, hasLength(0));
7721 }
7722
7723 void test_parseCompilationUnitMember_variable() {
7724 createParser('var x = 0;');
7725 CompilationUnitMember member = parseFullCompilationUnitMember();
7726 expectNotNullIfNoErrors(member);
7727 listener.assertNoErrors();
7728 expect(member, new isInstanceOf<TopLevelVariableDeclaration>());
7729 TopLevelVariableDeclaration declaration = member;
7730 expect(declaration.semicolon, isNotNull);
7731 expect(declaration.variables, isNotNull);
7732 }
7733
7734 void test_parseCompilationUnitMember_variableGet() {
7735 createParser('String get = null;');
7736 CompilationUnitMember member = parseFullCompilationUnitMember();
7737 expectNotNullIfNoErrors(member);
7738 listener.assertNoErrors();
7739 expect(member, new isInstanceOf<TopLevelVariableDeclaration>());
7740 TopLevelVariableDeclaration declaration = member;
7741 expect(declaration.semicolon, isNotNull);
7742 expect(declaration.variables, isNotNull);
7743 }
7744
7745 void test_parseCompilationUnitMember_variableSet() {
7746 createParser('String set = null;');
7747 CompilationUnitMember member = parseFullCompilationUnitMember();
7748 expectNotNullIfNoErrors(member);
7749 listener.assertNoErrors();
7750 expect(member, new isInstanceOf<TopLevelVariableDeclaration>());
7751 TopLevelVariableDeclaration declaration = member;
7752 expect(declaration.semicolon, isNotNull);
7753 expect(declaration.variables, isNotNull);
7754 }
7755
7756 void test_parseConditionalExpression() { 7023 void test_parseConditionalExpression() {
7757 createParser('x ? y : z'); 7024 createParser('x ? y : z');
7758 ConditionalExpression expression = parser.parseConditionalExpression(); 7025 ConditionalExpression expression = parser.parseConditionalExpression();
7759 expectNotNullIfNoErrors(expression); 7026 expectNotNullIfNoErrors(expression);
7760 listener.assertNoErrors(); 7027 listener.assertNoErrors();
7761 expect(expression.condition, isNotNull); 7028 expect(expression.condition, isNotNull);
7762 expect(expression.question, isNotNull); 7029 expect(expression.question, isNotNull);
7763 expect(expression.thenExpression, isNotNull); 7030 expect(expression.thenExpression, isNotNull);
7764 expect(expression.colon, isNotNull); 7031 expect(expression.colon, isNotNull);
7765 expect(expression.elseExpression, isNotNull); 7032 expect(expression.elseExpression, isNotNull);
7766 } 7033 }
7767 7034
7768 void test_parseConfiguration_noOperator_dottedIdentifier() { 7035 void test_parseConfiguration_noOperator_dottedIdentifier() {
7769 createParser("if (a.b) 'c.dart'"); 7036 createParser("if (a.b) 'c.dart'");
7770 Configuration configuration = parser.parseConfiguration(); 7037 Configuration configuration = parser.parseConfiguration();
7771 expectNotNullIfNoErrors(configuration); 7038 expectNotNullIfNoErrors(configuration);
7772 listener.assertNoErrors(); 7039 listener.assertNoErrors();
7773 expect(configuration.ifKeyword, isNotNull); 7040 expect(configuration.ifKeyword, isNotNull);
7774 expect(configuration.leftParenthesis, isNotNull); 7041 expect(configuration.leftParenthesis, isNotNull);
7775 _expectDottedName(configuration.name, ["a", "b"]); 7042 expectDottedName(configuration.name, ["a", "b"]);
7776 expect(configuration.equalToken, isNull); 7043 expect(configuration.equalToken, isNull);
7777 expect(configuration.value, isNull); 7044 expect(configuration.value, isNull);
7778 expect(configuration.rightParenthesis, isNotNull); 7045 expect(configuration.rightParenthesis, isNotNull);
7779 expect(configuration.uri, isNotNull); 7046 expect(configuration.uri, isNotNull);
7780 } 7047 }
7781 7048
7782 void test_parseConfiguration_noOperator_simpleIdentifier() { 7049 void test_parseConfiguration_noOperator_simpleIdentifier() {
7783 createParser("if (a) 'b.dart'"); 7050 createParser("if (a) 'b.dart'");
7784 Configuration configuration = parser.parseConfiguration(); 7051 Configuration configuration = parser.parseConfiguration();
7785 expectNotNullIfNoErrors(configuration); 7052 expectNotNullIfNoErrors(configuration);
7786 listener.assertNoErrors(); 7053 listener.assertNoErrors();
7787 expect(configuration.ifKeyword, isNotNull); 7054 expect(configuration.ifKeyword, isNotNull);
7788 expect(configuration.leftParenthesis, isNotNull); 7055 expect(configuration.leftParenthesis, isNotNull);
7789 _expectDottedName(configuration.name, ["a"]); 7056 expectDottedName(configuration.name, ["a"]);
7790 expect(configuration.equalToken, isNull); 7057 expect(configuration.equalToken, isNull);
7791 expect(configuration.value, isNull); 7058 expect(configuration.value, isNull);
7792 expect(configuration.rightParenthesis, isNotNull); 7059 expect(configuration.rightParenthesis, isNotNull);
7793 expect(configuration.uri, isNotNull); 7060 expect(configuration.uri, isNotNull);
7794 } 7061 }
7795 7062
7796 void test_parseConfiguration_operator_dottedIdentifier() { 7063 void test_parseConfiguration_operator_dottedIdentifier() {
7797 createParser("if (a.b == 'c') 'd.dart'"); 7064 createParser("if (a.b == 'c') 'd.dart'");
7798 Configuration configuration = parser.parseConfiguration(); 7065 Configuration configuration = parser.parseConfiguration();
7799 expectNotNullIfNoErrors(configuration); 7066 expectNotNullIfNoErrors(configuration);
7800 listener.assertNoErrors(); 7067 listener.assertNoErrors();
7801 expect(configuration.ifKeyword, isNotNull); 7068 expect(configuration.ifKeyword, isNotNull);
7802 expect(configuration.leftParenthesis, isNotNull); 7069 expect(configuration.leftParenthesis, isNotNull);
7803 _expectDottedName(configuration.name, ["a", "b"]); 7070 expectDottedName(configuration.name, ["a", "b"]);
7804 expect(configuration.equalToken, isNotNull); 7071 expect(configuration.equalToken, isNotNull);
7805 expect(configuration.value, isNotNull); 7072 expect(configuration.value, isNotNull);
7806 expect(configuration.rightParenthesis, isNotNull); 7073 expect(configuration.rightParenthesis, isNotNull);
7807 expect(configuration.uri, isNotNull); 7074 expect(configuration.uri, isNotNull);
7808 } 7075 }
7809 7076
7810 void test_parseConfiguration_operator_simpleIdentifier() { 7077 void test_parseConfiguration_operator_simpleIdentifier() {
7811 createParser("if (a == 'b') 'c.dart'"); 7078 createParser("if (a == 'b') 'c.dart'");
7812 Configuration configuration = parser.parseConfiguration(); 7079 Configuration configuration = parser.parseConfiguration();
7813 expectNotNullIfNoErrors(configuration); 7080 expectNotNullIfNoErrors(configuration);
7814 listener.assertNoErrors(); 7081 listener.assertNoErrors();
7815 expect(configuration.ifKeyword, isNotNull); 7082 expect(configuration.ifKeyword, isNotNull);
7816 expect(configuration.leftParenthesis, isNotNull); 7083 expect(configuration.leftParenthesis, isNotNull);
7817 _expectDottedName(configuration.name, ["a"]); 7084 expectDottedName(configuration.name, ["a"]);
7818 expect(configuration.equalToken, isNotNull); 7085 expect(configuration.equalToken, isNotNull);
7819 expect(configuration.value, isNotNull); 7086 expect(configuration.value, isNotNull);
7820 expect(configuration.rightParenthesis, isNotNull); 7087 expect(configuration.rightParenthesis, isNotNull);
7821 expect(configuration.uri, isNotNull); 7088 expect(configuration.uri, isNotNull);
7822 } 7089 }
7823 7090
7824 void test_parseConstExpression_instanceCreation() { 7091 void test_parseConstExpression_instanceCreation() {
7825 createParser('const A()'); 7092 createParser('const A()');
7826 Expression expression = parser.parseConstExpression(); 7093 Expression expression = parser.parseConstExpression();
7827 expectNotNullIfNoErrors(expression); 7094 expectNotNullIfNoErrors(expression);
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
8042 void test_parseContinueStatement_noLabel() { 7309 void test_parseContinueStatement_noLabel() {
8043 createParser('continue;'); 7310 createParser('continue;');
8044 ContinueStatement statement = parser.parseContinueStatement(); 7311 ContinueStatement statement = parser.parseContinueStatement();
8045 expectNotNullIfNoErrors(statement); 7312 expectNotNullIfNoErrors(statement);
8046 listener.assertErrorsWithCodes([ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP]); 7313 listener.assertErrorsWithCodes([ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP]);
8047 expect(statement.continueKeyword, isNotNull); 7314 expect(statement.continueKeyword, isNotNull);
8048 expect(statement.label, isNull); 7315 expect(statement.label, isNull);
8049 expect(statement.semicolon, isNotNull); 7316 expect(statement.semicolon, isNotNull);
8050 } 7317 }
8051 7318
8052 void test_parseDirective_export() {
8053 createParser("export 'lib/lib.dart';");
8054 Directive directive = parseFullDirective();
8055 expectNotNullIfNoErrors(directive);
8056 listener.assertNoErrors();
8057 expect(directive, new isInstanceOf<ExportDirective>());
8058 ExportDirective exportDirective = directive;
8059 expect(exportDirective.keyword, isNotNull);
8060 expect(exportDirective.uri, isNotNull);
8061 expect(exportDirective.combinators, hasLength(0));
8062 expect(exportDirective.semicolon, isNotNull);
8063 }
8064
8065 void test_parseDirective_import() {
8066 createParser("import 'lib/lib.dart';");
8067 Directive directive = parseFullDirective();
8068 expectNotNullIfNoErrors(directive);
8069 listener.assertNoErrors();
8070 expect(directive, new isInstanceOf<ImportDirective>());
8071 ImportDirective importDirective = directive;
8072 expect(importDirective.keyword, isNotNull);
8073 expect(importDirective.uri, isNotNull);
8074 expect(importDirective.asKeyword, isNull);
8075 expect(importDirective.prefix, isNull);
8076 expect(importDirective.combinators, hasLength(0));
8077 expect(importDirective.semicolon, isNotNull);
8078 }
8079
8080 void test_parseDirective_library() {
8081 createParser("library l;");
8082 Directive directive = parseFullDirective();
8083 expectNotNullIfNoErrors(directive);
8084 listener.assertNoErrors();
8085 expect(directive, new isInstanceOf<LibraryDirective>());
8086 LibraryDirective libraryDirective = directive;
8087 expect(libraryDirective.libraryKeyword, isNotNull);
8088 expect(libraryDirective.name, isNotNull);
8089 expect(libraryDirective.semicolon, isNotNull);
8090 }
8091
8092 void test_parseDirective_part() {
8093 createParser("part 'lib/lib.dart';");
8094 Directive directive = parseFullDirective();
8095 expectNotNullIfNoErrors(directive);
8096 listener.assertNoErrors();
8097 expect(directive, new isInstanceOf<PartDirective>());
8098 PartDirective partDirective = directive;
8099 expect(partDirective.partKeyword, isNotNull);
8100 expect(partDirective.uri, isNotNull);
8101 expect(partDirective.semicolon, isNotNull);
8102 }
8103
8104 void test_parseDirective_partOf() {
8105 createParser("part of l;");
8106 Directive directive = parseFullDirective();
8107 expectNotNullIfNoErrors(directive);
8108 listener.assertNoErrors();
8109 expect(directive, new isInstanceOf<PartOfDirective>());
8110 PartOfDirective partOfDirective = directive;
8111 expect(partOfDirective.partKeyword, isNotNull);
8112 expect(partOfDirective.ofKeyword, isNotNull);
8113 expect(partOfDirective.libraryName, isNotNull);
8114 expect(partOfDirective.semicolon, isNotNull);
8115 }
8116
8117 void test_parseDirectives_complete() {
8118 CompilationUnit unit =
8119 _parseDirectives("#! /bin/dart\nlibrary l;\nclass A {}");
8120 expect(unit.scriptTag, isNotNull);
8121 expect(unit.directives, hasLength(1));
8122 }
8123
8124 void test_parseDirectives_empty() {
8125 CompilationUnit unit = _parseDirectives("");
8126 expect(unit.scriptTag, isNull);
8127 expect(unit.directives, hasLength(0));
8128 }
8129
8130 void test_parseDirectives_mixed() {
8131 CompilationUnit unit =
8132 _parseDirectives("library l; class A {} part 'foo.dart';");
8133 expect(unit.scriptTag, isNull);
8134 expect(unit.directives, hasLength(1));
8135 }
8136
8137 void test_parseDirectives_multiple() {
8138 CompilationUnit unit = _parseDirectives("library l;\npart 'a.dart';");
8139 expect(unit.scriptTag, isNull);
8140 expect(unit.directives, hasLength(2));
8141 }
8142
8143 void test_parseDirectives_script() {
8144 CompilationUnit unit = _parseDirectives("#! /bin/dart");
8145 expect(unit.scriptTag, isNotNull);
8146 expect(unit.directives, hasLength(0));
8147 }
8148
8149 void test_parseDirectives_single() {
8150 CompilationUnit unit = _parseDirectives("library l;");
8151 expect(unit.scriptTag, isNull);
8152 expect(unit.directives, hasLength(1));
8153 }
8154
8155 void test_parseDirectives_topLevelDeclaration() {
8156 CompilationUnit unit = _parseDirectives("class A {}");
8157 expect(unit.scriptTag, isNull);
8158 expect(unit.directives, hasLength(0));
8159 }
8160
8161 void test_parseDocumentationComment_block() { 7319 void test_parseDocumentationComment_block() {
8162 createParser('/** */ class'); 7320 createParser('/** */ class');
8163 Comment comment = parser 7321 Comment comment = parser
8164 .parseDocumentationComment(parser.parseDocumentationCommentTokens()); 7322 .parseDocumentationComment(parser.parseDocumentationCommentTokens());
8165 expectNotNullIfNoErrors(comment); 7323 expectNotNullIfNoErrors(comment);
8166 listener.assertNoErrors(); 7324 listener.assertNoErrors();
8167 expect(comment.isBlock, isFalse); 7325 expect(comment.isBlock, isFalse);
8168 expect(comment.isDocumentation, isTrue); 7326 expect(comment.isDocumentation, isTrue);
8169 expect(comment.isEndOfLine, isFalse); 7327 expect(comment.isEndOfLine, isFalse);
8170 } 7328 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
8208 expect(statement.condition, isNotNull); 7366 expect(statement.condition, isNotNull);
8209 expect(statement.rightParenthesis, isNotNull); 7367 expect(statement.rightParenthesis, isNotNull);
8210 expect(statement.semicolon, isNotNull); 7368 expect(statement.semicolon, isNotNull);
8211 } 7369 }
8212 7370
8213 void test_parseDottedName_multiple() { 7371 void test_parseDottedName_multiple() {
8214 createParser('a.b.c'); 7372 createParser('a.b.c');
8215 DottedName name = parser.parseDottedName(); 7373 DottedName name = parser.parseDottedName();
8216 expectNotNullIfNoErrors(name); 7374 expectNotNullIfNoErrors(name);
8217 listener.assertNoErrors(); 7375 listener.assertNoErrors();
8218 _expectDottedName(name, ["a", "b", "c"]); 7376 expectDottedName(name, ["a", "b", "c"]);
8219 } 7377 }
8220 7378
8221 void test_parseDottedName_single() { 7379 void test_parseDottedName_single() {
8222 createParser('a'); 7380 createParser('a');
8223 DottedName name = parser.parseDottedName(); 7381 DottedName name = parser.parseDottedName();
8224 expectNotNullIfNoErrors(name); 7382 expectNotNullIfNoErrors(name);
8225 listener.assertNoErrors(); 7383 listener.assertNoErrors();
8226 _expectDottedName(name, ["a"]); 7384 expectDottedName(name, ["a"]);
8227 } 7385 }
8228 7386
8229 void test_parseEmptyStatement() { 7387 void test_parseEmptyStatement() {
8230 createParser(';'); 7388 createParser(';');
8231 EmptyStatement statement = parser.parseEmptyStatement(); 7389 EmptyStatement statement = parser.parseEmptyStatement();
8232 expectNotNullIfNoErrors(statement); 7390 expectNotNullIfNoErrors(statement);
8233 listener.assertNoErrors(); 7391 listener.assertNoErrors();
8234 expect(statement.semicolon, isNotNull); 7392 expect(statement.semicolon, isNotNull);
8235 } 7393 }
8236 7394
8237 void test_parseEnumDeclaration_one() {
8238 createParser("enum E {ONE}");
8239 EnumDeclaration declaration = parseFullCompilationUnitMember();
8240 expectNotNullIfNoErrors(declaration);
8241 listener.assertNoErrors();
8242 expect(declaration.documentationComment, isNull);
8243 expect(declaration.enumKeyword, isNotNull);
8244 expect(declaration.leftBracket, isNotNull);
8245 expect(declaration.name, isNotNull);
8246 expect(declaration.constants, hasLength(1));
8247 expect(declaration.rightBracket, isNotNull);
8248 }
8249
8250 void test_parseEnumDeclaration_trailingComma() {
8251 createParser("enum E {ONE,}");
8252 EnumDeclaration declaration = parseFullCompilationUnitMember();
8253 expectNotNullIfNoErrors(declaration);
8254 listener.assertNoErrors();
8255 expect(declaration.documentationComment, isNull);
8256 expect(declaration.enumKeyword, isNotNull);
8257 expect(declaration.leftBracket, isNotNull);
8258 expect(declaration.name, isNotNull);
8259 expect(declaration.constants, hasLength(1));
8260 expect(declaration.rightBracket, isNotNull);
8261 }
8262
8263 void test_parseEnumDeclaration_two() {
8264 createParser("enum E {ONE, TWO}");
8265 EnumDeclaration declaration = parseFullCompilationUnitMember();
8266 expectNotNullIfNoErrors(declaration);
8267 listener.assertNoErrors();
8268 expect(declaration.documentationComment, isNull);
8269 expect(declaration.enumKeyword, isNotNull);
8270 expect(declaration.leftBracket, isNotNull);
8271 expect(declaration.name, isNotNull);
8272 expect(declaration.constants, hasLength(2));
8273 expect(declaration.rightBracket, isNotNull);
8274 }
8275
8276 void test_parseEqualityExpression_normal() { 7395 void test_parseEqualityExpression_normal() {
8277 createParser('x == y'); 7396 createParser('x == y');
8278 BinaryExpression expression = parser.parseEqualityExpression(); 7397 BinaryExpression expression = parser.parseEqualityExpression();
8279 expectNotNullIfNoErrors(expression); 7398 expectNotNullIfNoErrors(expression);
8280 listener.assertNoErrors(); 7399 listener.assertNoErrors();
8281 expect(expression.leftOperand, isNotNull); 7400 expect(expression.leftOperand, isNotNull);
8282 expect(expression.operator, isNotNull); 7401 expect(expression.operator, isNotNull);
8283 expect(expression.operator.type, TokenType.EQ_EQ); 7402 expect(expression.operator.type, TokenType.EQ_EQ);
8284 expect(expression.rightOperand, isNotNull); 7403 expect(expression.rightOperand, isNotNull);
8285 } 7404 }
8286 7405
8287 void test_parseEqualityExpression_super() { 7406 void test_parseEqualityExpression_super() {
8288 createParser('super == y'); 7407 createParser('super == y');
8289 BinaryExpression expression = parser.parseEqualityExpression(); 7408 BinaryExpression expression = parser.parseEqualityExpression();
8290 expectNotNullIfNoErrors(expression); 7409 expectNotNullIfNoErrors(expression);
8291 listener.assertNoErrors(); 7410 listener.assertNoErrors();
8292 expect(expression.leftOperand, new isInstanceOf<SuperExpression>()); 7411 expect(expression.leftOperand, new isInstanceOf<SuperExpression>());
8293 expect(expression.operator, isNotNull); 7412 expect(expression.operator, isNotNull);
8294 expect(expression.operator.type, TokenType.EQ_EQ); 7413 expect(expression.operator.type, TokenType.EQ_EQ);
8295 expect(expression.rightOperand, isNotNull); 7414 expect(expression.rightOperand, isNotNull);
8296 } 7415 }
8297 7416
8298 void test_parseExportDirective_configuration_multiple() {
8299 createParser("export 'lib/lib.dart' if (a) 'b.dart' if (c) 'd.dart';");
8300 ExportDirective directive = parseFullDirective();
8301 expectNotNullIfNoErrors(directive);
8302 listener.assertNoErrors();
8303 expect(directive.keyword, isNotNull);
8304 expect(directive.uri, isNotNull);
8305 expect(directive.configurations, hasLength(2));
8306 _expectDottedName(directive.configurations[0].name, ['a']);
8307 _expectDottedName(directive.configurations[1].name, ['c']);
8308 expect(directive.combinators, hasLength(0));
8309 expect(directive.semicolon, isNotNull);
8310 }
8311
8312 void test_parseExportDirective_configuration_single() {
8313 createParser("export 'lib/lib.dart' if (a.b == 'c.dart') '';");
8314 ExportDirective directive = parseFullDirective();
8315 expectNotNullIfNoErrors(directive);
8316 listener.assertNoErrors();
8317 expect(directive.keyword, isNotNull);
8318 expect(directive.uri, isNotNull);
8319 expect(directive.configurations, hasLength(1));
8320 _expectDottedName(directive.configurations[0].name, ['a', 'b']);
8321 expect(directive.combinators, hasLength(0));
8322 expect(directive.semicolon, isNotNull);
8323 }
8324
8325 void test_parseExportDirective_hide() {
8326 createParser("export 'lib/lib.dart' hide A, B;");
8327 ExportDirective directive = parseFullDirective();
8328 expectNotNullIfNoErrors(directive);
8329 listener.assertNoErrors();
8330 expect(directive.keyword, isNotNull);
8331 expect(directive.uri, isNotNull);
8332 expect(directive.combinators, hasLength(1));
8333 expect(directive.semicolon, isNotNull);
8334 }
8335
8336 void test_parseExportDirective_hide_show() {
8337 createParser("export 'lib/lib.dart' hide A show B;");
8338 ExportDirective directive = parseFullDirective();
8339 expectNotNullIfNoErrors(directive);
8340 listener.assertNoErrors();
8341 expect(directive.keyword, isNotNull);
8342 expect(directive.uri, isNotNull);
8343 expect(directive.combinators, hasLength(2));
8344 expect(directive.semicolon, isNotNull);
8345 }
8346
8347 void test_parseExportDirective_noCombinator() {
8348 createParser("export 'lib/lib.dart';");
8349 ExportDirective directive = parseFullDirective();
8350 expectNotNullIfNoErrors(directive);
8351 listener.assertNoErrors();
8352 expect(directive.keyword, isNotNull);
8353 expect(directive.uri, isNotNull);
8354 expect(directive.combinators, hasLength(0));
8355 expect(directive.semicolon, isNotNull);
8356 }
8357
8358 void test_parseExportDirective_show() {
8359 createParser("export 'lib/lib.dart' show A, B;");
8360 ExportDirective directive = parseFullDirective();
8361 expectNotNullIfNoErrors(directive);
8362 listener.assertNoErrors();
8363 expect(directive.keyword, isNotNull);
8364 expect(directive.uri, isNotNull);
8365 expect(directive.combinators, hasLength(1));
8366 expect(directive.semicolon, isNotNull);
8367 }
8368
8369 void test_parseExportDirective_show_hide() {
8370 createParser("export 'lib/lib.dart' show B hide A;");
8371 ExportDirective directive = parseFullDirective();
8372 expectNotNullIfNoErrors(directive);
8373 listener.assertNoErrors();
8374 expect(directive.keyword, isNotNull);
8375 expect(directive.uri, isNotNull);
8376 expect(directive.combinators, hasLength(2));
8377 expect(directive.semicolon, isNotNull);
8378 }
8379
8380 void test_parseExpression_assign() { 7417 void test_parseExpression_assign() {
8381 // TODO(brianwilkerson) Implement more tests for this method. 7418 // TODO(brianwilkerson) Implement more tests for this method.
8382 Expression expression = parseExpression('x = y'); 7419 Expression expression = parseExpression('x = y');
8383 expect(expression, new isInstanceOf<AssignmentExpression>()); 7420 expect(expression, new isInstanceOf<AssignmentExpression>());
8384 AssignmentExpression assignmentExpression = expression; 7421 AssignmentExpression assignmentExpression = expression;
8385 expect(assignmentExpression.leftHandSide, isNotNull); 7422 expect(assignmentExpression.leftHandSide, isNotNull);
8386 expect(assignmentExpression.operator, isNotNull); 7423 expect(assignmentExpression.operator, isNotNull);
8387 expect(assignmentExpression.operator.type, TokenType.EQ); 7424 expect(assignmentExpression.operator.type, TokenType.EQ);
8388 expect(assignmentExpression.rightHandSide, isNotNull); 7425 expect(assignmentExpression.rightHandSide, isNotNull);
8389 } 7426 }
(...skipping 1531 matching lines...) Expand 10 before | Expand all | Expand 10 after
9921 8958
9922 void test_parseFunctionBody_skip_expression() { 8959 void test_parseFunctionBody_skip_expression() {
9923 ParserTestCase.parseFunctionBodies = false; 8960 ParserTestCase.parseFunctionBodies = false;
9924 createParser('=> y;'); 8961 createParser('=> y;');
9925 FunctionBody functionBody = parser.parseFunctionBody(false, null, false); 8962 FunctionBody functionBody = parser.parseFunctionBody(false, null, false);
9926 expectNotNullIfNoErrors(functionBody); 8963 expectNotNullIfNoErrors(functionBody);
9927 listener.assertNoErrors(); 8964 listener.assertNoErrors();
9928 expect(functionBody, new isInstanceOf<EmptyFunctionBody>()); 8965 expect(functionBody, new isInstanceOf<EmptyFunctionBody>());
9929 } 8966 }
9930 8967
9931 void test_parseFunctionDeclaration_function() {
9932 createParser('/// Doc\nT f() {}');
9933 FunctionDeclaration declaration = parseFullCompilationUnitMember();
9934 expectNotNullIfNoErrors(declaration);
9935 listener.assertNoErrors();
9936 _expectCommentText(declaration.documentationComment, '/// Doc');
9937 expect((declaration.returnType as TypeName).name.name, 'T');
9938 expect(declaration.name, isNotNull);
9939 FunctionExpression expression = declaration.functionExpression;
9940 expect(expression, isNotNull);
9941 expect(expression.body, isNotNull);
9942 expect(expression.typeParameters, isNull);
9943 expect(expression.parameters, isNotNull);
9944 expect(declaration.propertyKeyword, isNull);
9945 }
9946
9947 void test_parseFunctionDeclaration_functionWithTypeParameters() {
9948 createParser('/// Doc\nT f<E>() {}');
9949 FunctionDeclaration declaration = parseFullCompilationUnitMember();
9950 expectNotNullIfNoErrors(declaration);
9951 listener.assertNoErrors();
9952 _expectCommentText(declaration.documentationComment, '/// Doc');
9953 expect((declaration.returnType as TypeName).name.name, 'T');
9954 expect(declaration.name, isNotNull);
9955 FunctionExpression expression = declaration.functionExpression;
9956 expect(expression, isNotNull);
9957 expect(expression.body, isNotNull);
9958 expect(expression.typeParameters, isNotNull);
9959 expect(expression.parameters, isNotNull);
9960 expect(declaration.propertyKeyword, isNull);
9961 }
9962
9963 void test_parseFunctionDeclaration_functionWithTypeParameters_comment() {
9964 enableGenericMethodComments = true;
9965 createParser('/// Doc\nT f/*<E>*/() {}');
9966 FunctionDeclaration declaration = parseFullCompilationUnitMember();
9967 expectNotNullIfNoErrors(declaration);
9968 listener.assertNoErrors();
9969 _expectCommentText(declaration.documentationComment, '/// Doc');
9970 expect((declaration.returnType as TypeName).name.name, 'T');
9971 expect(declaration.name, isNotNull);
9972 FunctionExpression expression = declaration.functionExpression;
9973 expect(expression, isNotNull);
9974 expect(expression.body, isNotNull);
9975 expect(expression.typeParameters, isNotNull);
9976 expect(expression.parameters, isNotNull);
9977 expect(declaration.propertyKeyword, isNull);
9978 }
9979
9980 void test_parseFunctionDeclaration_getter() {
9981 createParser('/// Doc\nT get p => 0;');
9982 FunctionDeclaration declaration = parseFullCompilationUnitMember();
9983 expectNotNullIfNoErrors(declaration);
9984 listener.assertNoErrors();
9985 _expectCommentText(declaration.documentationComment, '/// Doc');
9986 expect((declaration.returnType as TypeName).name.name, 'T');
9987 expect(declaration.name, isNotNull);
9988 FunctionExpression expression = declaration.functionExpression;
9989 expect(expression, isNotNull);
9990 expect(expression.body, isNotNull);
9991 expect(expression.typeParameters, isNull);
9992 expect(expression.parameters, isNull);
9993 expect(declaration.propertyKeyword, isNotNull);
9994 }
9995
9996 void test_parseFunctionDeclaration_setter() {
9997 createParser('/// Doc\nT set p(v) {}');
9998 FunctionDeclaration declaration = parseFullCompilationUnitMember();
9999 expectNotNullIfNoErrors(declaration);
10000 listener.assertNoErrors();
10001 _expectCommentText(declaration.documentationComment, '/// Doc');
10002 expect((declaration.returnType as TypeName).name.name, 'T');
10003 expect(declaration.name, isNotNull);
10004 FunctionExpression expression = declaration.functionExpression;
10005 expect(expression, isNotNull);
10006 expect(expression.body, isNotNull);
10007 expect(expression.typeParameters, isNull);
10008 expect(expression.parameters, isNotNull);
10009 expect(declaration.propertyKeyword, isNotNull);
10010 }
10011
10012 void test_parseFunctionDeclarationStatement() { 8968 void test_parseFunctionDeclarationStatement() {
10013 createParser('void f(int p) => p * 2;'); 8969 createParser('void f(int p) => p * 2;');
10014 FunctionDeclarationStatement statement = 8970 FunctionDeclarationStatement statement =
10015 parser.parseFunctionDeclarationStatement(); 8971 parser.parseFunctionDeclarationStatement();
10016 expectNotNullIfNoErrors(statement); 8972 expectNotNullIfNoErrors(statement);
10017 listener.assertNoErrors(); 8973 listener.assertNoErrors();
10018 expect(statement.functionDeclaration, isNotNull); 8974 expect(statement.functionDeclaration, isNotNull);
10019 } 8975 }
10020 8976
10021 void test_parseFunctionDeclarationStatement_typeParameterComments() { 8977 void test_parseFunctionDeclarationStatement_typeParameterComments() {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
10084 createParser('<E>(E i) => i++'); 9040 createParser('<E>(E i) => i++');
10085 FunctionExpression expression = parser.parseFunctionExpression(); 9041 FunctionExpression expression = parser.parseFunctionExpression();
10086 expectNotNullIfNoErrors(expression); 9042 expectNotNullIfNoErrors(expression);
10087 listener.assertNoErrors(); 9043 listener.assertNoErrors();
10088 expect(expression.body, isNotNull); 9044 expect(expression.body, isNotNull);
10089 expect(expression.typeParameters, isNotNull); 9045 expect(expression.typeParameters, isNotNull);
10090 expect(expression.parameters, isNotNull); 9046 expect(expression.parameters, isNotNull);
10091 expect((expression.body as ExpressionFunctionBody).semicolon, isNull); 9047 expect((expression.body as ExpressionFunctionBody).semicolon, isNull);
10092 } 9048 }
10093 9049
10094 @failingTest
10095 void test_parseGenericTypeAlias_noTypeParameters() {
10096 createParser('F = int Function(int);');
10097 GenericTypeAlias alias = parseFullCompilationUnitMember();
10098 expectNotNullIfNoErrors(alias);
10099 listener.assertNoErrors();
10100 expect(alias.name, isNotNull);
10101 expect(alias.name.name, 'F');
10102 expect(alias.typeParameters, isNull);
10103 expect(alias.equals, isNotNull);
10104 expect(alias.functionType, isNotNull);
10105 expect(alias.semicolon, isNotNull);
10106 }
10107
10108 @failingTest
10109 void test_parseGenericTypeAlias_typeParameters() {
10110 createParser('F<T> = T Function(T);');
10111 GenericTypeAlias alias = parseFullCompilationUnitMember();
10112 expectNotNullIfNoErrors(alias);
10113 listener.assertNoErrors();
10114 expect(alias.name, isNotNull);
10115 expect(alias.name.name, 'F');
10116 expect(alias.typeParameters, isNotNull);
10117 expect(alias.equals, isNotNull);
10118 expect(alias.functionType, isNotNull);
10119 expect(alias.semicolon, isNotNull);
10120 }
10121
10122 void test_parseGetter_nonStatic() { 9050 void test_parseGetter_nonStatic() {
10123 createParser('/// Doc\nT get a;'); 9051 createParser('/// Doc\nT get a;');
10124 MethodDeclaration method = parser.parseClassMember('C'); 9052 MethodDeclaration method = parser.parseClassMember('C');
10125 expectNotNullIfNoErrors(method); 9053 expectNotNullIfNoErrors(method);
10126 listener.assertNoErrors(); 9054 listener.assertNoErrors();
10127 expect(method.body, isNotNull); 9055 expect(method.body, isNotNull);
10128 _expectCommentText(method.documentationComment, '/// Doc'); 9056 expectCommentText(method.documentationComment, '/// Doc');
10129 expect(method.externalKeyword, isNull); 9057 expect(method.externalKeyword, isNull);
10130 expect(method.modifierKeyword, isNull); 9058 expect(method.modifierKeyword, isNull);
10131 expect(method.name, isNotNull); 9059 expect(method.name, isNotNull);
10132 expect(method.operatorKeyword, isNull); 9060 expect(method.operatorKeyword, isNull);
10133 expect(method.parameters, isNull); 9061 expect(method.parameters, isNull);
10134 expect(method.propertyKeyword, isNotNull); 9062 expect(method.propertyKeyword, isNotNull);
10135 expect((method.returnType as TypeName).name.name, 'T'); 9063 expect((method.returnType as TypeName).name.name, 'T');
10136 } 9064 }
10137 9065
10138 void test_parseGetter_static() { 9066 void test_parseGetter_static() {
10139 createParser('/// Doc\nstatic T get a => 42;'); 9067 createParser('/// Doc\nstatic T get a => 42;');
10140 MethodDeclaration method = parser.parseClassMember('C'); 9068 MethodDeclaration method = parser.parseClassMember('C');
10141 expectNotNullIfNoErrors(method); 9069 expectNotNullIfNoErrors(method);
10142 listener.assertNoErrors(); 9070 listener.assertNoErrors();
10143 expect(method.body, isNotNull); 9071 expect(method.body, isNotNull);
10144 _expectCommentText(method.documentationComment, '/// Doc'); 9072 expectCommentText(method.documentationComment, '/// Doc');
10145 expect(method.externalKeyword, isNull); 9073 expect(method.externalKeyword, isNull);
10146 expect(method.modifierKeyword.lexeme, 'static'); 9074 expect(method.modifierKeyword.lexeme, 'static');
10147 expect(method.name, isNotNull); 9075 expect(method.name, isNotNull);
10148 expect(method.operatorKeyword, isNull); 9076 expect(method.operatorKeyword, isNull);
10149 expect(method.typeParameters, isNull); 9077 expect(method.typeParameters, isNull);
10150 expect(method.parameters, isNull); 9078 expect(method.parameters, isNull);
10151 expect(method.propertyKeyword, isNotNull); 9079 expect(method.propertyKeyword, isNotNull);
10152 expect((method.returnType as TypeName).name.name, 'T'); 9080 expect((method.returnType as TypeName).name.name, 'T');
10153 } 9081 }
10154 9082
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
10235 9163
10236 void test_parseImplementsClause_single() { 9164 void test_parseImplementsClause_single() {
10237 createParser('implements A'); 9165 createParser('implements A');
10238 ImplementsClause clause = parser.parseImplementsClause(); 9166 ImplementsClause clause = parser.parseImplementsClause();
10239 expectNotNullIfNoErrors(clause); 9167 expectNotNullIfNoErrors(clause);
10240 listener.assertNoErrors(); 9168 listener.assertNoErrors();
10241 expect(clause.interfaces, hasLength(1)); 9169 expect(clause.interfaces, hasLength(1));
10242 expect(clause.implementsKeyword, isNotNull); 9170 expect(clause.implementsKeyword, isNotNull);
10243 } 9171 }
10244 9172
10245 void test_parseImportDirective_configuration_multiple() {
10246 createParser("import 'lib/lib.dart' if (a) 'b.dart' if (c) 'd.dart';");
10247 ImportDirective directive = parseFullDirective();
10248 expectNotNullIfNoErrors(directive);
10249 listener.assertNoErrors();
10250 expect(directive.keyword, isNotNull);
10251 expect(directive.uri, isNotNull);
10252 expect(directive.configurations, hasLength(2));
10253 _expectDottedName(directive.configurations[0].name, ['a']);
10254 _expectDottedName(directive.configurations[1].name, ['c']);
10255 expect(directive.deferredKeyword, isNull);
10256 expect(directive.asKeyword, isNull);
10257 expect(directive.prefix, isNull);
10258 expect(directive.combinators, hasLength(0));
10259 expect(directive.semicolon, isNotNull);
10260 }
10261
10262 void test_parseImportDirective_configuration_single() {
10263 createParser("import 'lib/lib.dart' if (a.b == 'c.dart') '';");
10264 ImportDirective directive = parseFullDirective();
10265 expectNotNullIfNoErrors(directive);
10266 listener.assertNoErrors();
10267 expect(directive.keyword, isNotNull);
10268 expect(directive.uri, isNotNull);
10269 expect(directive.configurations, hasLength(1));
10270 _expectDottedName(directive.configurations[0].name, ['a', 'b']);
10271 expect(directive.deferredKeyword, isNull);
10272 expect(directive.asKeyword, isNull);
10273 expect(directive.prefix, isNull);
10274 expect(directive.combinators, hasLength(0));
10275 expect(directive.semicolon, isNotNull);
10276 }
10277
10278 void test_parseImportDirective_deferred() {
10279 createParser("import 'lib/lib.dart' deferred as a;");
10280 ImportDirective directive = parseFullDirective();
10281 expectNotNullIfNoErrors(directive);
10282 listener.assertNoErrors();
10283 expect(directive.keyword, isNotNull);
10284 expect(directive.uri, isNotNull);
10285 expect(directive.deferredKeyword, isNotNull);
10286 expect(directive.asKeyword, isNotNull);
10287 expect(directive.prefix, isNotNull);
10288 expect(directive.combinators, hasLength(0));
10289 expect(directive.semicolon, isNotNull);
10290 }
10291
10292 void test_parseImportDirective_hide() {
10293 createParser("import 'lib/lib.dart' hide A, B;");
10294 ImportDirective directive = parseFullDirective();
10295 expectNotNullIfNoErrors(directive);
10296 listener.assertNoErrors();
10297 expect(directive.keyword, isNotNull);
10298 expect(directive.uri, isNotNull);
10299 expect(directive.deferredKeyword, isNull);
10300 expect(directive.asKeyword, isNull);
10301 expect(directive.prefix, isNull);
10302 expect(directive.combinators, hasLength(1));
10303 expect(directive.semicolon, isNotNull);
10304 }
10305
10306 void test_parseImportDirective_noCombinator() {
10307 createParser("import 'lib/lib.dart';");
10308 ImportDirective directive = parseFullDirective();
10309 expectNotNullIfNoErrors(directive);
10310 listener.assertNoErrors();
10311 expect(directive.keyword, isNotNull);
10312 expect(directive.uri, isNotNull);
10313 expect(directive.deferredKeyword, isNull);
10314 expect(directive.asKeyword, isNull);
10315 expect(directive.prefix, isNull);
10316 expect(directive.combinators, hasLength(0));
10317 expect(directive.semicolon, isNotNull);
10318 }
10319
10320 void test_parseImportDirective_prefix() {
10321 createParser("import 'lib/lib.dart' as a;");
10322 ImportDirective directive = parseFullDirective();
10323 expectNotNullIfNoErrors(directive);
10324 listener.assertNoErrors();
10325 expect(directive.keyword, isNotNull);
10326 expect(directive.uri, isNotNull);
10327 expect(directive.deferredKeyword, isNull);
10328 expect(directive.asKeyword, isNotNull);
10329 expect(directive.prefix, isNotNull);
10330 expect(directive.combinators, hasLength(0));
10331 expect(directive.semicolon, isNotNull);
10332 }
10333
10334 void test_parseImportDirective_prefix_hide_show() {
10335 createParser("import 'lib/lib.dart' as a hide A show B;");
10336 ImportDirective directive = parseFullDirective();
10337 expectNotNullIfNoErrors(directive);
10338 listener.assertNoErrors();
10339 expect(directive.keyword, isNotNull);
10340 expect(directive.uri, isNotNull);
10341 expect(directive.deferredKeyword, isNull);
10342 expect(directive.asKeyword, isNotNull);
10343 expect(directive.prefix, isNotNull);
10344 expect(directive.combinators, hasLength(2));
10345 expect(directive.semicolon, isNotNull);
10346 }
10347
10348 void test_parseImportDirective_prefix_show_hide() {
10349 createParser("import 'lib/lib.dart' as a show B hide A;");
10350 ImportDirective directive = parseFullDirective();
10351 expectNotNullIfNoErrors(directive);
10352 listener.assertNoErrors();
10353 expect(directive.keyword, isNotNull);
10354 expect(directive.uri, isNotNull);
10355 expect(directive.deferredKeyword, isNull);
10356 expect(directive.asKeyword, isNotNull);
10357 expect(directive.prefix, isNotNull);
10358 expect(directive.combinators, hasLength(2));
10359 expect(directive.semicolon, isNotNull);
10360 }
10361
10362 void test_parseImportDirective_show() {
10363 createParser("import 'lib/lib.dart' show A, B;");
10364 ImportDirective directive = parseFullDirective();
10365 expectNotNullIfNoErrors(directive);
10366 listener.assertNoErrors();
10367 expect(directive.keyword, isNotNull);
10368 expect(directive.uri, isNotNull);
10369 expect(directive.deferredKeyword, isNull);
10370 expect(directive.asKeyword, isNull);
10371 expect(directive.prefix, isNull);
10372 expect(directive.combinators, hasLength(1));
10373 expect(directive.semicolon, isNotNull);
10374 }
10375
10376 void test_parseInitializedIdentifierList_type() { 9173 void test_parseInitializedIdentifierList_type() {
10377 createParser("/// Doc\nstatic T a = 1, b, c = 3;"); 9174 createParser("/// Doc\nstatic T a = 1, b, c = 3;");
10378 FieldDeclaration declaration = parser.parseClassMember('C'); 9175 FieldDeclaration declaration = parser.parseClassMember('C');
10379 expectNotNullIfNoErrors(declaration); 9176 expectNotNullIfNoErrors(declaration);
10380 listener.assertNoErrors(); 9177 listener.assertNoErrors();
10381 _expectCommentText(declaration.documentationComment, '/// Doc'); 9178 expectCommentText(declaration.documentationComment, '/// Doc');
10382 VariableDeclarationList fields = declaration.fields; 9179 VariableDeclarationList fields = declaration.fields;
10383 expect(fields, isNotNull); 9180 expect(fields, isNotNull);
10384 expect(fields.keyword, isNull); 9181 expect(fields.keyword, isNull);
10385 expect((fields.type as TypeName).name.name, 'T'); 9182 expect((fields.type as TypeName).name.name, 'T');
10386 expect(fields.variables, hasLength(3)); 9183 expect(fields.variables, hasLength(3));
10387 expect(declaration.staticKeyword.lexeme, 'static'); 9184 expect(declaration.staticKeyword.lexeme, 'static');
10388 expect(declaration.semicolon, isNotNull); 9185 expect(declaration.semicolon, isNotNull);
10389 } 9186 }
10390 9187
10391 void test_parseInitializedIdentifierList_var() { 9188 void test_parseInitializedIdentifierList_var() {
10392 createParser('/// Doc\nstatic var a = 1, b, c = 3;'); 9189 createParser('/// Doc\nstatic var a = 1, b, c = 3;');
10393 FieldDeclaration declaration = parser.parseClassMember('C'); 9190 FieldDeclaration declaration = parser.parseClassMember('C');
10394 expectNotNullIfNoErrors(declaration); 9191 expectNotNullIfNoErrors(declaration);
10395 listener.assertNoErrors(); 9192 listener.assertNoErrors();
10396 _expectCommentText(declaration.documentationComment, '/// Doc'); 9193 expectCommentText(declaration.documentationComment, '/// Doc');
10397 VariableDeclarationList fields = declaration.fields; 9194 VariableDeclarationList fields = declaration.fields;
10398 expect(fields, isNotNull); 9195 expect(fields, isNotNull);
10399 expect(fields.keyword.lexeme, 'var'); 9196 expect(fields.keyword.lexeme, 'var');
10400 expect(fields.type, isNull); 9197 expect(fields.type, isNull);
10401 expect(fields.variables, hasLength(3)); 9198 expect(fields.variables, hasLength(3));
10402 expect(declaration.staticKeyword.lexeme, 'static'); 9199 expect(declaration.staticKeyword.lexeme, 'static');
10403 expect(declaration.semicolon, isNotNull); 9200 expect(declaration.semicolon, isNotNull);
10404 } 9201 }
10405 9202
10406 void test_parseInstanceCreationExpression_qualifiedType() { 9203 void test_parseInstanceCreationExpression_qualifiedType() {
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
10641 TypeName type = name.type; 9438 TypeName type = name.type;
10642 expect(type, isNotNull); 9439 expect(type, isNotNull);
10643 expect(name.period, isNull); 9440 expect(name.period, isNull);
10644 expect(name.name, isNull); 9441 expect(name.name, isNull);
10645 expect(expression.argumentList, isNotNull); 9442 expect(expression.argumentList, isNotNull);
10646 NodeList<TypeAnnotation> arguments = type.typeArguments.arguments; 9443 NodeList<TypeAnnotation> arguments = type.typeArguments.arguments;
10647 expect(arguments, hasLength(1)); 9444 expect(arguments, hasLength(1));
10648 expect((arguments[0] as TypeName).question, isNotNull); 9445 expect((arguments[0] as TypeName).question, isNotNull);
10649 } 9446 }
10650 9447
10651 void test_parseLibraryDirective() {
10652 createParser('library l;');
10653 LibraryDirective directive = parseFullDirective();
10654 expectNotNullIfNoErrors(directive);
10655 listener.assertNoErrors();
10656 expect(directive.libraryKeyword, isNotNull);
10657 expect(directive.name, isNotNull);
10658 expect(directive.semicolon, isNotNull);
10659 }
10660
10661 void test_parseLibraryIdentifier_multiple() { 9448 void test_parseLibraryIdentifier_multiple() {
10662 String name = "a.b.c"; 9449 String name = "a.b.c";
10663 createParser(name); 9450 createParser(name);
10664 LibraryIdentifier identifier = parser.parseLibraryIdentifier(); 9451 LibraryIdentifier identifier = parser.parseLibraryIdentifier();
10665 expectNotNullIfNoErrors(identifier); 9452 expectNotNullIfNoErrors(identifier);
10666 listener.assertNoErrors(); 9453 listener.assertNoErrors();
10667 expect(identifier.name, name); 9454 expect(identifier.name, name);
10668 } 9455 }
10669 9456
10670 void test_parseLibraryIdentifier_single() { 9457 void test_parseLibraryIdentifier_single() {
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after
11608 expect(simpleParameter.type, isNotNull); 10395 expect(simpleParameter.type, isNotNull);
11609 expect(simpleParameter.identifier, isNotNull); 10396 expect(simpleParameter.identifier, isNotNull);
11610 } 10397 }
11611 10398
11612 void test_parseOperator() { 10399 void test_parseOperator() {
11613 createParser('/// Doc\nT operator +(A a);'); 10400 createParser('/// Doc\nT operator +(A a);');
11614 MethodDeclaration method = parser.parseClassMember('C'); 10401 MethodDeclaration method = parser.parseClassMember('C');
11615 expectNotNullIfNoErrors(method); 10402 expectNotNullIfNoErrors(method);
11616 listener.assertNoErrors(); 10403 listener.assertNoErrors();
11617 expect(method.body, isNotNull); 10404 expect(method.body, isNotNull);
11618 _expectCommentText(method.documentationComment, '/// Doc'); 10405 expectCommentText(method.documentationComment, '/// Doc');
11619 expect(method.externalKeyword, isNull); 10406 expect(method.externalKeyword, isNull);
11620 expect(method.modifierKeyword, isNull); 10407 expect(method.modifierKeyword, isNull);
11621 expect(method.name, isNotNull); 10408 expect(method.name, isNotNull);
11622 expect(method.operatorKeyword, isNotNull); 10409 expect(method.operatorKeyword, isNotNull);
11623 expect(method.typeParameters, isNull); 10410 expect(method.typeParameters, isNull);
11624 expect(method.parameters, isNotNull); 10411 expect(method.parameters, isNotNull);
11625 expect(method.propertyKeyword, isNull); 10412 expect(method.propertyKeyword, isNull);
11626 expect((method.returnType as TypeName).name.name, 'T'); 10413 expect((method.returnType as TypeName).name.name, 'T');
11627 } 10414 }
11628 10415
11629 void test_parseOptionalReturnType() { 10416 void test_parseOptionalReturnType() {
11630 // TODO(brianwilkerson) Implement tests for this method. 10417 // TODO(brianwilkerson) Implement tests for this method.
11631 } 10418 }
11632 10419
11633 void test_parsePartDirective() {
11634 createParser("part 'lib/lib.dart';");
11635 PartDirective directive = parseFullDirective();
11636 expectNotNullIfNoErrors(directive);
11637 listener.assertNoErrors();
11638 expect(directive.partKeyword, isNotNull);
11639 expect(directive.uri, isNotNull);
11640 expect(directive.semicolon, isNotNull);
11641 }
11642
11643 void test_parsePartOfDirective_name() {
11644 enableUriInPartOf = true;
11645 createParser("part of l;");
11646 PartOfDirective directive = parseFullDirective();
11647 expect(directive.partKeyword, isNotNull);
11648 expect(directive.ofKeyword, isNotNull);
11649 expect(directive.libraryName, isNotNull);
11650 expect(directive.uri, isNull);
11651 expect(directive.semicolon, isNotNull);
11652 }
11653
11654 void test_parsePartOfDirective_uri() {
11655 enableUriInPartOf = true;
11656 createParser("part of 'lib.dart';");
11657 PartOfDirective directive = parseFullDirective();
11658 expect(directive.partKeyword, isNotNull);
11659 expect(directive.ofKeyword, isNotNull);
11660 expect(directive.libraryName, isNull);
11661 expect(directive.uri, isNotNull);
11662 expect(directive.semicolon, isNotNull);
11663 }
11664
11665 void test_parsePostfixExpression_decrement() { 10420 void test_parsePostfixExpression_decrement() {
11666 createParser('i--'); 10421 createParser('i--');
11667 Expression expression = parser.parsePostfixExpression(); 10422 Expression expression = parser.parsePostfixExpression();
11668 expectNotNullIfNoErrors(expression); 10423 expectNotNullIfNoErrors(expression);
11669 listener.assertNoErrors(); 10424 listener.assertNoErrors();
11670 expect(expression, new isInstanceOf<PostfixExpression>()); 10425 expect(expression, new isInstanceOf<PostfixExpression>());
11671 PostfixExpression postfixExpression = expression; 10426 PostfixExpression postfixExpression = expression;
11672 expect(postfixExpression.operand, isNotNull); 10427 expect(postfixExpression.operand, isNotNull);
11673 expect(postfixExpression.operator, isNotNull); 10428 expect(postfixExpression.operator, isNotNull);
11674 expect(postfixExpression.operator.type, TokenType.MINUS_MINUS); 10429 expect(postfixExpression.operator.type, TokenType.MINUS_MINUS);
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
12321 expect(typeName.name, isNotNull); 11076 expect(typeName.name, isNotNull);
12322 expect(typeName.typeArguments, isNull); 11077 expect(typeName.typeArguments, isNull);
12323 } 11078 }
12324 11079
12325 void test_parseSetter_nonStatic() { 11080 void test_parseSetter_nonStatic() {
12326 createParser('/// Doc\nT set a(var x);'); 11081 createParser('/// Doc\nT set a(var x);');
12327 MethodDeclaration method = parser.parseClassMember('C'); 11082 MethodDeclaration method = parser.parseClassMember('C');
12328 expectNotNullIfNoErrors(method); 11083 expectNotNullIfNoErrors(method);
12329 listener.assertNoErrors(); 11084 listener.assertNoErrors();
12330 expect(method.body, isNotNull); 11085 expect(method.body, isNotNull);
12331 _expectCommentText(method.documentationComment, '/// Doc'); 11086 expectCommentText(method.documentationComment, '/// Doc');
12332 expect(method.externalKeyword, isNull); 11087 expect(method.externalKeyword, isNull);
12333 expect(method.modifierKeyword, isNull); 11088 expect(method.modifierKeyword, isNull);
12334 expect(method.name, isNotNull); 11089 expect(method.name, isNotNull);
12335 expect(method.operatorKeyword, isNull); 11090 expect(method.operatorKeyword, isNull);
12336 expect(method.typeParameters, isNull); 11091 expect(method.typeParameters, isNull);
12337 expect(method.parameters, isNotNull); 11092 expect(method.parameters, isNotNull);
12338 expect(method.propertyKeyword, isNotNull); 11093 expect(method.propertyKeyword, isNotNull);
12339 expect((method.returnType as TypeName).name.name, 'T'); 11094 expect((method.returnType as TypeName).name.name, 'T');
12340 } 11095 }
12341 11096
12342 void test_parseSetter_static() { 11097 void test_parseSetter_static() {
12343 createParser('/// Doc\nstatic T set a(var x) {}'); 11098 createParser('/// Doc\nstatic T set a(var x) {}');
12344 MethodDeclaration method = parser.parseClassMember('C'); 11099 MethodDeclaration method = parser.parseClassMember('C');
12345 expectNotNullIfNoErrors(method); 11100 expectNotNullIfNoErrors(method);
12346 listener.assertNoErrors(); 11101 listener.assertNoErrors();
12347 expect(method.body, isNotNull); 11102 expect(method.body, isNotNull);
12348 _expectCommentText(method.documentationComment, '/// Doc'); 11103 expectCommentText(method.documentationComment, '/// Doc');
12349 expect(method.externalKeyword, isNull); 11104 expect(method.externalKeyword, isNull);
12350 expect(method.modifierKeyword.lexeme, 'static'); 11105 expect(method.modifierKeyword.lexeme, 'static');
12351 expect(method.name, isNotNull); 11106 expect(method.name, isNotNull);
12352 expect(method.operatorKeyword, isNull); 11107 expect(method.operatorKeyword, isNull);
12353 expect(method.typeParameters, isNull); 11108 expect(method.typeParameters, isNull);
12354 expect(method.parameters, isNotNull); 11109 expect(method.parameters, isNotNull);
12355 expect(method.propertyKeyword, isNotNull); 11110 expect(method.propertyKeyword, isNotNull);
12356 expect((method.returnType as TypeName).name.name, 'T'); 11111 expect((method.returnType as TypeName).name.name, 'T');
12357 } 11112 }
12358 11113
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
13119 expect(clause.exceptionType, isNotNull); 11874 expect(clause.exceptionType, isNotNull);
13120 expect(clause.catchKeyword, isNotNull); 11875 expect(clause.catchKeyword, isNotNull);
13121 expect(clause.exceptionParameter, isNotNull); 11876 expect(clause.exceptionParameter, isNotNull);
13122 expect(clause.comma, isNotNull); 11877 expect(clause.comma, isNotNull);
13123 expect(clause.stackTraceParameter, isNotNull); 11878 expect(clause.stackTraceParameter, isNotNull);
13124 expect(clause.body, isNotNull); 11879 expect(clause.body, isNotNull);
13125 expect(statement.finallyKeyword, isNotNull); 11880 expect(statement.finallyKeyword, isNotNull);
13126 expect(statement.finallyBlock, isNotNull); 11881 expect(statement.finallyBlock, isNotNull);
13127 } 11882 }
13128 11883
13129 void test_parseTypeAlias_function_noParameters() {
13130 createParser('typedef bool F();');
13131 FunctionTypeAlias typeAlias = parseFullCompilationUnitMember();
13132 expectNotNullIfNoErrors(typeAlias);
13133 listener.assertNoErrors();
13134 expect(typeAlias.typedefKeyword, isNotNull);
13135 expect(typeAlias.name, isNotNull);
13136 expect(typeAlias.parameters, isNotNull);
13137 expect(typeAlias.returnType, isNotNull);
13138 expect(typeAlias.semicolon, isNotNull);
13139 expect(typeAlias.typeParameters, isNull);
13140 }
13141
13142 void test_parseTypeAlias_function_noReturnType() {
13143 createParser('typedef F();');
13144 FunctionTypeAlias typeAlias = parseFullCompilationUnitMember();
13145 expectNotNullIfNoErrors(typeAlias);
13146 listener.assertNoErrors();
13147 expect(typeAlias.typedefKeyword, isNotNull);
13148 expect(typeAlias.name, isNotNull);
13149 expect(typeAlias.parameters, isNotNull);
13150 expect(typeAlias.returnType, isNull);
13151 expect(typeAlias.semicolon, isNotNull);
13152 expect(typeAlias.typeParameters, isNull);
13153 }
13154
13155 void test_parseTypeAlias_function_parameterizedReturnType() {
13156 createParser('typedef A<B> F();');
13157 FunctionTypeAlias typeAlias = parseFullCompilationUnitMember();
13158 expectNotNullIfNoErrors(typeAlias);
13159 listener.assertNoErrors();
13160 expect(typeAlias.typedefKeyword, isNotNull);
13161 expect(typeAlias.name, isNotNull);
13162 expect(typeAlias.parameters, isNotNull);
13163 expect(typeAlias.returnType, isNotNull);
13164 expect(typeAlias.semicolon, isNotNull);
13165 expect(typeAlias.typeParameters, isNull);
13166 }
13167
13168 void test_parseTypeAlias_function_parameters() {
13169 createParser('typedef bool F(Object value);');
13170 FunctionTypeAlias typeAlias = parseFullCompilationUnitMember();
13171 expectNotNullIfNoErrors(typeAlias);
13172 listener.assertNoErrors();
13173 expect(typeAlias.typedefKeyword, isNotNull);
13174 expect(typeAlias.name, isNotNull);
13175 expect(typeAlias.parameters, isNotNull);
13176 expect(typeAlias.returnType, isNotNull);
13177 expect(typeAlias.semicolon, isNotNull);
13178 expect(typeAlias.typeParameters, isNull);
13179 }
13180
13181 void test_parseTypeAlias_function_typeParameters() {
13182 createParser('typedef bool F<E>();');
13183 FunctionTypeAlias typeAlias = parseFullCompilationUnitMember();
13184 expectNotNullIfNoErrors(typeAlias);
13185 listener.assertNoErrors();
13186 expect(typeAlias.typedefKeyword, isNotNull);
13187 expect(typeAlias.name, isNotNull);
13188 expect(typeAlias.parameters, isNotNull);
13189 expect(typeAlias.returnType, isNotNull);
13190 expect(typeAlias.semicolon, isNotNull);
13191 expect(typeAlias.typeParameters, isNotNull);
13192 }
13193
13194 void test_parseTypeAlias_function_voidReturnType() {
13195 createParser('typedef void F();');
13196 FunctionTypeAlias typeAlias = parseFullCompilationUnitMember();
13197 expectNotNullIfNoErrors(typeAlias);
13198 listener.assertNoErrors();
13199 expect(typeAlias.typedefKeyword, isNotNull);
13200 expect(typeAlias.name, isNotNull);
13201 expect(typeAlias.parameters, isNotNull);
13202 expect(typeAlias.returnType, isNotNull);
13203 expect(typeAlias.semicolon, isNotNull);
13204 expect(typeAlias.typeParameters, isNull);
13205 }
13206
13207 @failingTest
13208 void test_parseTypeAlias_genericFunction_noParameters() {
13209 createParser('typedef F = bool Function();');
13210 GenericTypeAlias typeAlias = parseFullCompilationUnitMember();
13211 expectNotNullIfNoErrors(typeAlias);
13212 listener.assertNoErrors();
13213 expect(typeAlias.typedefKeyword, isNotNull);
13214 expect(typeAlias.name, isNotNull);
13215 expect(typeAlias.typeParameters, isNull);
13216 expect(typeAlias.semicolon, isNotNull);
13217 GenericFunctionType functionType = typeAlias.functionType;
13218 expect(functionType, isNotNull);
13219 expect(functionType.parameters, isNotNull);
13220 expect(functionType.returnType, isNotNull);
13221 expect(functionType.typeParameters, isNull);
13222 }
13223
13224 @failingTest
13225 void test_parseTypeAlias_genericFunction_noReturnType() {
13226 createParser('typedef F = Function();');
13227 GenericTypeAlias typeAlias = parseFullCompilationUnitMember();
13228 expectNotNullIfNoErrors(typeAlias);
13229 listener.assertNoErrors();
13230 expect(typeAlias.typedefKeyword, isNotNull);
13231 expect(typeAlias.name, isNotNull);
13232 expect(typeAlias.typeParameters, isNull);
13233 expect(typeAlias.semicolon, isNotNull);
13234 GenericFunctionType functionType = typeAlias.functionType;
13235 expect(functionType, isNotNull);
13236 expect(functionType.parameters, isNotNull);
13237 expect(functionType.returnType, isNull);
13238 expect(functionType.typeParameters, isNull);
13239 }
13240
13241 @failingTest
13242 void test_parseTypeAlias_genericFunction_parameterizedReturnType() {
13243 createParser('typedef F = A<B> Function();');
13244 GenericTypeAlias typeAlias = parseFullCompilationUnitMember();
13245 expectNotNullIfNoErrors(typeAlias);
13246 listener.assertNoErrors();
13247 expect(typeAlias.typedefKeyword, isNotNull);
13248 expect(typeAlias.name, isNotNull);
13249 expect(typeAlias.typeParameters, isNull);
13250 expect(typeAlias.semicolon, isNotNull);
13251 GenericFunctionType functionType = typeAlias.functionType;
13252 expect(functionType, isNotNull);
13253 expect(functionType.parameters, isNotNull);
13254 expect(functionType.returnType, isNotNull);
13255 expect(functionType.typeParameters, isNull);
13256 }
13257
13258 @failingTest
13259 void test_parseTypeAlias_genericFunction_parameters() {
13260 createParser('typedef F = bool Function(Object value);');
13261 GenericTypeAlias typeAlias = parseFullCompilationUnitMember();
13262 expectNotNullIfNoErrors(typeAlias);
13263 listener.assertNoErrors();
13264 expect(typeAlias.typedefKeyword, isNotNull);
13265 expect(typeAlias.name, isNotNull);
13266 expect(typeAlias.typeParameters, isNull);
13267 expect(typeAlias.semicolon, isNotNull);
13268 GenericFunctionType functionType = typeAlias.functionType;
13269 expect(functionType, isNotNull);
13270 expect(functionType.parameters, isNotNull);
13271 expect(functionType.returnType, isNotNull);
13272 expect(functionType.typeParameters, isNull);
13273 }
13274
13275 @failingTest
13276 void test_parseTypeAlias_genericFunction_typeParameters() {
13277 createParser('typedef F = bool Function<E>();');
13278 GenericTypeAlias typeAlias = parseFullCompilationUnitMember();
13279 expectNotNullIfNoErrors(typeAlias);
13280 listener.assertNoErrors();
13281 expect(typeAlias.typedefKeyword, isNotNull);
13282 expect(typeAlias.name, isNotNull);
13283 expect(typeAlias.typeParameters, isNull);
13284 expect(typeAlias.semicolon, isNotNull);
13285 GenericFunctionType functionType = typeAlias.functionType;
13286 expect(functionType, isNotNull);
13287 expect(functionType.parameters, isNotNull);
13288 expect(functionType.returnType, isNotNull);
13289 expect(functionType.typeParameters, isNotNull);
13290 }
13291
13292 @failingTest
13293 void test_parseTypeAlias_genericFunction_typeParameters_noParameters() {
13294 createParser('typedef F<T> = bool Function();');
13295 GenericTypeAlias typeAlias = parseFullCompilationUnitMember();
13296 expectNotNullIfNoErrors(typeAlias);
13297 listener.assertNoErrors();
13298 expect(typeAlias.typedefKeyword, isNotNull);
13299 expect(typeAlias.name, isNotNull);
13300 expect(typeAlias.typeParameters, isNotNull);
13301 expect(typeAlias.semicolon, isNotNull);
13302 GenericFunctionType functionType = typeAlias.functionType;
13303 expect(functionType, isNotNull);
13304 expect(functionType.parameters, isNotNull);
13305 expect(functionType.returnType, isNotNull);
13306 expect(functionType.typeParameters, isNull);
13307 }
13308
13309 @failingTest
13310 void test_parseTypeAlias_genericFunction_typeParameters_noReturnType() {
13311 createParser('typedef F<T> = Function();');
13312 GenericTypeAlias typeAlias = parseFullCompilationUnitMember();
13313 expectNotNullIfNoErrors(typeAlias);
13314 listener.assertNoErrors();
13315 expect(typeAlias.typedefKeyword, isNotNull);
13316 expect(typeAlias.name, isNotNull);
13317 expect(typeAlias.typeParameters, isNotNull);
13318 expect(typeAlias.semicolon, isNotNull);
13319 GenericFunctionType functionType = typeAlias.functionType;
13320 expect(functionType, isNotNull);
13321 expect(functionType.parameters, isNotNull);
13322 expect(functionType.returnType, isNull);
13323 expect(functionType.typeParameters, isNull);
13324 }
13325
13326 @failingTest
13327 void
13328 test_parseTypeAlias_genericFunction_typeParameters_parameterizedReturnType () {
13329 createParser('typedef F<T> = A<B> Function();');
13330 GenericTypeAlias typeAlias = parseFullCompilationUnitMember();
13331 expectNotNullIfNoErrors(typeAlias);
13332 listener.assertNoErrors();
13333 expect(typeAlias.typedefKeyword, isNotNull);
13334 expect(typeAlias.name, isNotNull);
13335 expect(typeAlias.typeParameters, isNotNull);
13336 expect(typeAlias.semicolon, isNotNull);
13337 GenericFunctionType functionType = typeAlias.functionType;
13338 expect(functionType, isNotNull);
13339 expect(functionType.parameters, isNotNull);
13340 expect(functionType.returnType, isNotNull);
13341 expect(functionType.typeParameters, isNull);
13342 }
13343
13344 @failingTest
13345 void test_parseTypeAlias_genericFunction_typeParameters_parameters() {
13346 createParser('typedef F<T> = bool Function(Object value);');
13347 GenericTypeAlias typeAlias = parseFullCompilationUnitMember();
13348 expectNotNullIfNoErrors(typeAlias);
13349 listener.assertNoErrors();
13350 expect(typeAlias.typedefKeyword, isNotNull);
13351 expect(typeAlias.name, isNotNull);
13352 expect(typeAlias.typeParameters, isNotNull);
13353 expect(typeAlias.semicolon, isNotNull);
13354 GenericFunctionType functionType = typeAlias.functionType;
13355 expect(functionType, isNotNull);
13356 expect(functionType.parameters, isNotNull);
13357 expect(functionType.returnType, isNotNull);
13358 expect(functionType.typeParameters, isNull);
13359 }
13360
13361 @failingTest
13362 void test_parseTypeAlias_genericFunction_typeParameters_typeParameters() {
13363 createParser('typedef F<T> = bool Function<E>();');
13364 GenericTypeAlias typeAlias = parseFullCompilationUnitMember();
13365 expectNotNullIfNoErrors(typeAlias);
13366 listener.assertNoErrors();
13367 expect(typeAlias.typedefKeyword, isNotNull);
13368 expect(typeAlias.name, isNotNull);
13369 expect(typeAlias.typeParameters, isNotNull);
13370 expect(typeAlias.semicolon, isNotNull);
13371 GenericFunctionType functionType = typeAlias.functionType;
13372 expect(functionType, isNotNull);
13373 expect(functionType.parameters, isNotNull);
13374 expect(functionType.returnType, isNotNull);
13375 expect(functionType.typeParameters, isNotNull);
13376 }
13377
13378 @failingTest
13379 void test_parseTypeAlias_genericFunction_typeParameters_voidReturnType() {
13380 createParser('typedef F<T> = void Function();');
13381 GenericTypeAlias typeAlias = parseFullCompilationUnitMember();
13382 expectNotNullIfNoErrors(typeAlias);
13383 listener.assertNoErrors();
13384 expect(typeAlias.typedefKeyword, isNotNull);
13385 expect(typeAlias.name, isNotNull);
13386 expect(typeAlias.typeParameters, isNotNull);
13387 expect(typeAlias.semicolon, isNotNull);
13388 GenericFunctionType functionType = typeAlias.functionType;
13389 expect(functionType, isNotNull);
13390 expect(functionType.parameters, isNotNull);
13391 expect(functionType.returnType, isNotNull);
13392 expect(functionType.typeParameters, isNull);
13393 }
13394
13395 @failingTest
13396 void test_parseTypeAlias_genericFunction_voidReturnType() {
13397 createParser('typedef F = void Function();');
13398 GenericTypeAlias typeAlias = parseFullCompilationUnitMember();
13399 expectNotNullIfNoErrors(typeAlias);
13400 listener.assertNoErrors();
13401 expect(typeAlias.typedefKeyword, isNotNull);
13402 expect(typeAlias.name, isNotNull);
13403 expect(typeAlias.typeParameters, isNull);
13404 expect(typeAlias.semicolon, isNotNull);
13405 GenericFunctionType functionType = typeAlias.functionType;
13406 expect(functionType, isNotNull);
13407 expect(functionType.parameters, isNotNull);
13408 expect(functionType.returnType, isNotNull);
13409 expect(functionType.typeParameters, isNull);
13410 }
13411
13412 @failingTest 11884 @failingTest
13413 void test_parseTypeAnnotation_function_noReturnType_noParameters() { 11885 void test_parseTypeAnnotation_function_noReturnType_noParameters() {
13414 createParser('Function() v'); 11886 createParser('Function() v');
13415 GenericFunctionType functionType = parser.parseTypeAnnotation(false); 11887 GenericFunctionType functionType = parser.parseTypeAnnotation(false);
13416 expectNotNullIfNoErrors(functionType); 11888 expectNotNullIfNoErrors(functionType);
13417 listener.assertNoErrors(); 11889 listener.assertNoErrors();
13418 expect(functionType.returnType, isNull); 11890 expect(functionType.returnType, isNull);
13419 expect(functionType.functionKeyword, isNotNull); 11891 expect(functionType.functionKeyword, isNotNull);
13420 expect(functionType.typeParameters, isNull); 11892 expect(functionType.typeParameters, isNull);
13421 FormalParameterList parameterList = functionType.parameters; 11893 FormalParameterList parameterList = functionType.parameters;
(...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after
14356 * @return the result of invoking the method 12828 * @return the result of invoking the method
14357 * @throws Exception if the method could not be invoked or throws an exception 12829 * @throws Exception if the method could not be invoked or throws an exception
14358 */ 12830 */
14359 String _computeStringValue(String lexeme, bool first, bool last) { 12831 String _computeStringValue(String lexeme, bool first, bool last) {
14360 createParser(''); 12832 createParser('');
14361 String value = parser.computeStringValue(lexeme, first, last); 12833 String value = parser.computeStringValue(lexeme, first, last);
14362 listener.assertNoErrors(); 12834 listener.assertNoErrors();
14363 return value; 12835 return value;
14364 } 12836 }
14365 12837
14366 void _expectCommentText(Comment comment, String expectedText) {
14367 expect(comment.beginToken, same(comment.endToken));
14368 expect(comment.beginToken.lexeme, expectedText);
14369 }
14370
14371 void _expectDottedName(DottedName name, List<String> expectedComponents) {
14372 int count = expectedComponents.length;
14373 NodeList<SimpleIdentifier> components = name.components;
14374 expect(components, hasLength(count));
14375 for (int i = 0; i < count; i++) {
14376 SimpleIdentifier component = components[i];
14377 expect(component, isNotNull);
14378 expect(component.name, expectedComponents[i]);
14379 }
14380 }
14381
14382 /** 12838 /**
14383 * Invoke the method [Parser.isFunctionDeclaration] with the parser set to the token 12839 * Invoke the method [Parser.isFunctionDeclaration] with the parser set to the token
14384 * stream produced by scanning the given source. 12840 * stream produced by scanning the given source.
14385 * 12841 *
14386 * @param source the source to be scanned to produce the token stream being te sted 12842 * @param source the source to be scanned to produce the token stream being te sted
14387 * @return the result of invoking the method 12843 * @return the result of invoking the method
14388 * @throws Exception if the method could not be invoked or throws an exception 12844 * @throws Exception if the method could not be invoked or throws an exception
14389 */ 12845 */
14390 bool _isFunctionDeclaration(String source) { 12846 bool _isFunctionDeclaration(String source) {
14391 createParser(source); 12847 createParser(source);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
14429 * @param source the source to be scanned to produce the token stream being te sted 12885 * @param source the source to be scanned to produce the token stream being te sted
14430 * @return the result of invoking the method 12886 * @return the result of invoking the method
14431 * @throws Exception if the method could not be invoked or throws an exception 12887 * @throws Exception if the method could not be invoked or throws an exception
14432 */ 12888 */
14433 bool _isSwitchMember(String source) { 12889 bool _isSwitchMember(String source) {
14434 createParser(source); 12890 createParser(source);
14435 bool result = parser.isSwitchMember(); 12891 bool result = parser.isSwitchMember();
14436 expectNotNullIfNoErrors(result); 12892 expectNotNullIfNoErrors(result);
14437 return result; 12893 return result;
14438 } 12894 }
12895 }
12896
12897 /**
12898 * Tests which exercise the parser using a complete compilation unit or
12899 * compilation unit member.
12900 */
12901 @reflectiveTest
12902 class TopLevelParserTest extends ParserTestCase {
12903 void test_function_literal_allowed_at_toplevel() {
12904 parseCompilationUnit("var x = () {};");
12905 }
12906
12907 void
12908 test_function_literal_allowed_in_ArgumentList_in_ConstructorFieldInitializ er() {
12909 parseCompilationUnit("class C { C() : a = f(() {}); }");
12910 }
12911
12912 void
12913 test_function_literal_allowed_in_IndexExpression_in_ConstructorFieldInitia lizer() {
12914 parseCompilationUnit("class C { C() : a = x[() {}]; }");
12915 }
12916
12917 void
12918 test_function_literal_allowed_in_ListLiteral_in_ConstructorFieldInitialize r() {
12919 parseCompilationUnit("class C { C() : a = [() {}]; }");
12920 }
12921
12922 void
12923 test_function_literal_allowed_in_MapLiteral_in_ConstructorFieldInitializer () {
12924 parseCompilationUnit("class C { C() : a = {'key': () {}}; }");
12925 }
12926
12927 void
12928 test_function_literal_allowed_in_ParenthesizedExpression_in_ConstructorFie ldInitializer() {
12929 parseCompilationUnit("class C { C() : a = (() {}); }");
12930 }
12931
12932 void
12933 test_function_literal_allowed_in_StringInterpolation_in_ConstructorFieldIn itializer() {
12934 parseCompilationUnit("class C { C() : a = \"\${(){}}\"; }");
12935 }
12936
12937 void test_import_as_show() {
12938 parseCompilationUnit("import 'dart:math' as M show E;");
12939 }
12940
12941 void test_import_show_hide() {
12942 parseCompilationUnit(
12943 "import 'import1_lib.dart' show hide, show hide ugly;");
12944 }
12945
12946 void test_parseClassDeclaration_abstract() {
12947 createParser('abstract class A {}');
12948 CompilationUnitMember member = parseFullCompilationUnitMember();
12949 expectNotNullIfNoErrors(member);
12950 listener.assertNoErrors();
12951 expect(member, new isInstanceOf<ClassDeclaration>());
12952 ClassDeclaration declaration = member;
12953 expect(declaration.documentationComment, isNull);
12954 expect(declaration.abstractKeyword, isNotNull);
12955 expect(declaration.extendsClause, isNull);
12956 expect(declaration.implementsClause, isNull);
12957 expect(declaration.classKeyword, isNotNull);
12958 expect(declaration.leftBracket, isNotNull);
12959 expect(declaration.name, isNotNull);
12960 expect(declaration.members, hasLength(0));
12961 expect(declaration.rightBracket, isNotNull);
12962 expect(declaration.typeParameters, isNull);
12963 }
12964
12965 void test_parseClassDeclaration_empty() {
12966 createParser('class A {}');
12967 CompilationUnitMember member = parseFullCompilationUnitMember();
12968 expectNotNullIfNoErrors(member);
12969 listener.assertNoErrors();
12970 expect(member, new isInstanceOf<ClassDeclaration>());
12971 ClassDeclaration declaration = member;
12972 expect(declaration.documentationComment, isNull);
12973 expect(declaration.abstractKeyword, isNull);
12974 expect(declaration.extendsClause, isNull);
12975 expect(declaration.implementsClause, isNull);
12976 expect(declaration.classKeyword, isNotNull);
12977 expect(declaration.leftBracket, isNotNull);
12978 expect(declaration.name, isNotNull);
12979 expect(declaration.members, hasLength(0));
12980 expect(declaration.rightBracket, isNotNull);
12981 expect(declaration.typeParameters, isNull);
12982 }
12983
12984 void test_parseClassDeclaration_extends() {
12985 createParser('class A extends B {}');
12986 CompilationUnitMember member = parseFullCompilationUnitMember();
12987 expectNotNullIfNoErrors(member);
12988 listener.assertNoErrors();
12989 expect(member, new isInstanceOf<ClassDeclaration>());
12990 ClassDeclaration declaration = member;
12991 expect(declaration.documentationComment, isNull);
12992 expect(declaration.abstractKeyword, isNull);
12993 expect(declaration.extendsClause, isNotNull);
12994 expect(declaration.implementsClause, isNull);
12995 expect(declaration.classKeyword, isNotNull);
12996 expect(declaration.leftBracket, isNotNull);
12997 expect(declaration.name, isNotNull);
12998 expect(declaration.members, hasLength(0));
12999 expect(declaration.rightBracket, isNotNull);
13000 expect(declaration.typeParameters, isNull);
13001 }
13002
13003 void test_parseClassDeclaration_extendsAndImplements() {
13004 createParser('class A extends B implements C {}');
13005 CompilationUnitMember member = parseFullCompilationUnitMember();
13006 expectNotNullIfNoErrors(member);
13007 listener.assertNoErrors();
13008 expect(member, new isInstanceOf<ClassDeclaration>());
13009 ClassDeclaration declaration = member;
13010 expect(declaration.documentationComment, isNull);
13011 expect(declaration.abstractKeyword, isNull);
13012 expect(declaration.extendsClause, isNotNull);
13013 expect(declaration.implementsClause, isNotNull);
13014 expect(declaration.classKeyword, isNotNull);
13015 expect(declaration.leftBracket, isNotNull);
13016 expect(declaration.name, isNotNull);
13017 expect(declaration.members, hasLength(0));
13018 expect(declaration.rightBracket, isNotNull);
13019 expect(declaration.typeParameters, isNull);
13020 }
13021
13022 void test_parseClassDeclaration_extendsAndWith() {
13023 createParser('class A extends B with C {}');
13024 CompilationUnitMember member = parseFullCompilationUnitMember();
13025 expectNotNullIfNoErrors(member);
13026 listener.assertNoErrors();
13027 expect(member, new isInstanceOf<ClassDeclaration>());
13028 ClassDeclaration declaration = member;
13029 expect(declaration.documentationComment, isNull);
13030 expect(declaration.abstractKeyword, isNull);
13031 expect(declaration.classKeyword, isNotNull);
13032 expect(declaration.name, isNotNull);
13033 expect(declaration.typeParameters, isNull);
13034 expect(declaration.extendsClause, isNotNull);
13035 expect(declaration.withClause, isNotNull);
13036 expect(declaration.implementsClause, isNull);
13037 expect(declaration.leftBracket, isNotNull);
13038 expect(declaration.members, hasLength(0));
13039 expect(declaration.rightBracket, isNotNull);
13040 }
13041
13042 void test_parseClassDeclaration_extendsAndWithAndImplements() {
13043 createParser('class A extends B with C implements D {}');
13044 CompilationUnitMember member = parseFullCompilationUnitMember();
13045 expectNotNullIfNoErrors(member);
13046 listener.assertNoErrors();
13047 expect(member, new isInstanceOf<ClassDeclaration>());
13048 ClassDeclaration declaration = member;
13049 expect(declaration.documentationComment, isNull);
13050 expect(declaration.abstractKeyword, isNull);
13051 expect(declaration.classKeyword, isNotNull);
13052 expect(declaration.name, isNotNull);
13053 expect(declaration.typeParameters, isNull);
13054 expect(declaration.extendsClause, isNotNull);
13055 expect(declaration.withClause, isNotNull);
13056 expect(declaration.implementsClause, isNotNull);
13057 expect(declaration.leftBracket, isNotNull);
13058 expect(declaration.members, hasLength(0));
13059 expect(declaration.rightBracket, isNotNull);
13060 }
13061
13062 void test_parseClassDeclaration_implements() {
13063 createParser('class A implements C {}');
13064 CompilationUnitMember member = parseFullCompilationUnitMember();
13065 expectNotNullIfNoErrors(member);
13066 listener.assertNoErrors();
13067 expect(member, new isInstanceOf<ClassDeclaration>());
13068 ClassDeclaration declaration = member;
13069 expect(declaration.documentationComment, isNull);
13070 expect(declaration.abstractKeyword, isNull);
13071 expect(declaration.extendsClause, isNull);
13072 expect(declaration.implementsClause, isNotNull);
13073 expect(declaration.classKeyword, isNotNull);
13074 expect(declaration.leftBracket, isNotNull);
13075 expect(declaration.name, isNotNull);
13076 expect(declaration.members, hasLength(0));
13077 expect(declaration.rightBracket, isNotNull);
13078 expect(declaration.typeParameters, isNull);
13079 }
13080
13081 void test_parseClassDeclaration_native() {
13082 createParser('class A native "nativeValue" {}');
13083 CompilationUnitMember member = parseFullCompilationUnitMember();
13084 expectNotNullIfNoErrors(member);
13085 listener.assertNoErrors();
13086 expect(member, new isInstanceOf<ClassDeclaration>());
13087 ClassDeclaration declaration = member;
13088 NativeClause nativeClause = declaration.nativeClause;
13089 expect(nativeClause, isNotNull);
13090 expect(nativeClause.nativeKeyword, isNotNull);
13091 expect(nativeClause.name.stringValue, "nativeValue");
13092 expect(nativeClause.beginToken, same(nativeClause.nativeKeyword));
13093 expect(nativeClause.endToken, same(nativeClause.name.endToken));
13094 }
13095
13096 void test_parseClassDeclaration_nonEmpty() {
13097 createParser('class A {var f;}');
13098 CompilationUnitMember member = parseFullCompilationUnitMember();
13099 expectNotNullIfNoErrors(member);
13100 listener.assertNoErrors();
13101 expect(member, new isInstanceOf<ClassDeclaration>());
13102 ClassDeclaration declaration = member;
13103 expect(declaration.documentationComment, isNull);
13104 expect(declaration.abstractKeyword, isNull);
13105 expect(declaration.extendsClause, isNull);
13106 expect(declaration.implementsClause, isNull);
13107 expect(declaration.classKeyword, isNotNull);
13108 expect(declaration.leftBracket, isNotNull);
13109 expect(declaration.name, isNotNull);
13110 expect(declaration.members, hasLength(1));
13111 expect(declaration.rightBracket, isNotNull);
13112 expect(declaration.typeParameters, isNull);
13113 }
13114
13115 void test_parseClassDeclaration_typeAlias_implementsC() {
13116 createParser('class A = Object with B implements C;');
13117 CompilationUnitMember member = parseFullCompilationUnitMember();
13118 expectNotNullIfNoErrors(member);
13119 listener.assertNoErrors();
13120 expect(member, new isInstanceOf<ClassTypeAlias>());
13121 ClassTypeAlias typeAlias = member;
13122 expect(typeAlias.typedefKeyword, isNotNull);
13123 expect(typeAlias.name, isNotNull);
13124 expect(typeAlias.typeParameters, isNull);
13125 expect(typeAlias.withClause, isNotNull);
13126 expect(typeAlias.implementsClause, isNotNull);
13127 expect(typeAlias.implementsClause.implementsKeyword, isNotNull);
13128 expect(typeAlias.implementsClause.interfaces.length, 1);
13129 expect(typeAlias.semicolon, isNotNull);
13130 }
13131
13132 void test_parseClassDeclaration_typeAlias_withB() {
13133 createParser('class A = Object with B;');
13134 CompilationUnitMember member = parseFullCompilationUnitMember();
13135 expectNotNullIfNoErrors(member);
13136 listener.assertNoErrors();
13137 expect(member, new isInstanceOf<ClassTypeAlias>());
13138 ClassTypeAlias typeAlias = member;
13139 expect(typeAlias.typedefKeyword, isNotNull);
13140 expect(typeAlias.name, isNotNull);
13141 expect(typeAlias.typeParameters, isNull);
13142 expect(typeAlias.withClause, isNotNull);
13143 expect(typeAlias.withClause.withKeyword, isNotNull);
13144 expect(typeAlias.withClause.mixinTypes.length, 1);
13145 expect(typeAlias.implementsClause, isNull);
13146 expect(typeAlias.semicolon, isNotNull);
13147 }
13148
13149 void test_parseClassDeclaration_typeParameters() {
13150 createParser('class A<B> {}');
13151 CompilationUnitMember member = parseFullCompilationUnitMember();
13152 expectNotNullIfNoErrors(member);
13153 listener.assertNoErrors();
13154 expect(member, new isInstanceOf<ClassDeclaration>());
13155 ClassDeclaration declaration = member;
13156 expect(declaration.documentationComment, isNull);
13157 expect(declaration.abstractKeyword, isNull);
13158 expect(declaration.extendsClause, isNull);
13159 expect(declaration.implementsClause, isNull);
13160 expect(declaration.classKeyword, isNotNull);
13161 expect(declaration.leftBracket, isNotNull);
13162 expect(declaration.name, isNotNull);
13163 expect(declaration.members, hasLength(0));
13164 expect(declaration.rightBracket, isNotNull);
13165 expect(declaration.typeParameters, isNotNull);
13166 expect(declaration.typeParameters.typeParameters, hasLength(1));
13167 }
13168
13169 void test_parseCompilationUnit_abstractAsPrefix_parameterized() {
13170 createParser('abstract<dynamic> _abstract = new abstract.A();');
13171 CompilationUnit unit = parser.parseCompilationUnit2();
13172 expectNotNullIfNoErrors(unit);
13173 listener.assertNoErrors();
13174 expect(unit.scriptTag, isNull);
13175 expect(unit.directives, hasLength(0));
13176 expect(unit.declarations, hasLength(1));
13177 }
13178
13179 void test_parseCompilationUnit_builtIn_asFunctionName() {
13180 parseCompilationUnit('abstract(x) => 0;');
13181 parseCompilationUnit('as(x) => 0;');
13182 parseCompilationUnit('dynamic(x) => 0;');
13183 parseCompilationUnit('export(x) => 0;');
13184 parseCompilationUnit('external(x) => 0;');
13185 parseCompilationUnit('factory(x) => 0;');
13186 parseCompilationUnit('get(x) => 0;');
13187 parseCompilationUnit('implements(x) => 0;');
13188 parseCompilationUnit('import(x) => 0;');
13189 parseCompilationUnit('library(x) => 0;');
13190 parseCompilationUnit('operator(x) => 0;');
13191 parseCompilationUnit('part(x) => 0;');
13192 parseCompilationUnit('set(x) => 0;');
13193 parseCompilationUnit('static(x) => 0;');
13194 parseCompilationUnit('typedef(x) => 0;');
13195 }
13196
13197 void test_parseCompilationUnit_directives_multiple() {
13198 createParser("library l;\npart 'a.dart';");
13199 CompilationUnit unit = parser.parseCompilationUnit2();
13200 expectNotNullIfNoErrors(unit);
13201 listener.assertNoErrors();
13202 expect(unit.scriptTag, isNull);
13203 expect(unit.directives, hasLength(2));
13204 expect(unit.declarations, hasLength(0));
13205 }
13206
13207 void test_parseCompilationUnit_directives_single() {
13208 createParser('library l;');
13209 CompilationUnit unit = parser.parseCompilationUnit2();
13210 expectNotNullIfNoErrors(unit);
13211 listener.assertNoErrors();
13212 expect(unit.scriptTag, isNull);
13213 expect(unit.directives, hasLength(1));
13214 expect(unit.declarations, hasLength(0));
13215 }
13216
13217 void test_parseCompilationUnit_empty() {
13218 createParser('');
13219 CompilationUnit unit = parser.parseCompilationUnit2();
13220 expectNotNullIfNoErrors(unit);
13221 listener.assertNoErrors();
13222 expect(unit.scriptTag, isNull);
13223 expect(unit.directives, hasLength(0));
13224 expect(unit.declarations, hasLength(0));
13225 }
13226
13227 void test_parseCompilationUnit_exportAsPrefix() {
13228 createParser('export.A _export = new export.A();');
13229 CompilationUnit unit = parser.parseCompilationUnit2();
13230 expectNotNullIfNoErrors(unit);
13231 listener.assertNoErrors();
13232 expect(unit.scriptTag, isNull);
13233 expect(unit.directives, hasLength(0));
13234 expect(unit.declarations, hasLength(1));
13235 }
13236
13237 void test_parseCompilationUnit_exportAsPrefix_parameterized() {
13238 createParser('export<dynamic> _export = new export.A();');
13239 CompilationUnit unit = parser.parseCompilationUnit2();
13240 expectNotNullIfNoErrors(unit);
13241 listener.assertNoErrors();
13242 expect(unit.scriptTag, isNull);
13243 expect(unit.directives, hasLength(0));
13244 expect(unit.declarations, hasLength(1));
13245 }
13246
13247 void test_parseCompilationUnit_operatorAsPrefix_parameterized() {
13248 createParser('operator<dynamic> _operator = new operator.A();');
13249 CompilationUnit unit = parser.parseCompilationUnit2();
13250 expectNotNullIfNoErrors(unit);
13251 listener.assertNoErrors();
13252 expect(unit.scriptTag, isNull);
13253 expect(unit.directives, hasLength(0));
13254 expect(unit.declarations, hasLength(1));
13255 }
13256
13257 void test_parseCompilationUnit_script() {
13258 createParser('#! /bin/dart');
13259 CompilationUnit unit = parser.parseCompilationUnit2();
13260 expectNotNullIfNoErrors(unit);
13261 listener.assertNoErrors();
13262 expect(unit.scriptTag, isNotNull);
13263 expect(unit.directives, hasLength(0));
13264 expect(unit.declarations, hasLength(0));
13265 }
13266
13267 void test_parseCompilationUnit_skipFunctionBody_withInterpolation() {
13268 ParserTestCase.parseFunctionBodies = false;
13269 createParser('f() { "\${n}"; }');
13270 CompilationUnit unit = parser.parseCompilationUnit2();
13271 expectNotNullIfNoErrors(unit);
13272 listener.assertNoErrors();
13273 expect(unit.scriptTag, isNull);
13274 expect(unit.declarations, hasLength(1));
13275 }
13276
13277 void test_parseCompilationUnit_topLevelDeclaration() {
13278 createParser('class A {}');
13279 CompilationUnit unit = parser.parseCompilationUnit2();
13280 expectNotNullIfNoErrors(unit);
13281 listener.assertNoErrors();
13282 expect(unit.scriptTag, isNull);
13283 expect(unit.directives, hasLength(0));
13284 expect(unit.declarations, hasLength(1));
13285 }
13286
13287 void test_parseCompilationUnit_typedefAsPrefix() {
13288 createParser('typedef.A _typedef = new typedef.A();');
13289 CompilationUnit unit = parser.parseCompilationUnit2();
13290 expectNotNullIfNoErrors(unit);
13291 listener.assertNoErrors();
13292 expect(unit.scriptTag, isNull);
13293 expect(unit.directives, hasLength(0));
13294 expect(unit.declarations, hasLength(1));
13295 }
13296
13297 void test_parseCompilationUnitMember_abstractAsPrefix() {
13298 createParser('abstract.A _abstract = new abstract.A();');
13299 CompilationUnitMember member = parseFullCompilationUnitMember();
13300 expectNotNullIfNoErrors(member);
13301 listener.assertNoErrors();
13302 expect(member, new isInstanceOf<TopLevelVariableDeclaration>());
13303 TopLevelVariableDeclaration declaration = member;
13304 expect(declaration.semicolon, isNotNull);
13305 expect(declaration.variables, isNotNull);
13306 }
13307
13308 void test_parseCompilationUnitMember_class() {
13309 createParser('class A {}');
13310 CompilationUnitMember member = parseFullCompilationUnitMember();
13311 expectNotNullIfNoErrors(member);
13312 listener.assertNoErrors();
13313 expect(member, new isInstanceOf<ClassDeclaration>());
13314 ClassDeclaration declaration = member;
13315 expect(declaration.name.name, "A");
13316 expect(declaration.members, hasLength(0));
13317 }
13318
13319 void test_parseCompilationUnitMember_classTypeAlias() {
13320 createParser('abstract class A = B with C;');
13321 CompilationUnitMember member = parseFullCompilationUnitMember();
13322 expectNotNullIfNoErrors(member);
13323 listener.assertNoErrors();
13324 expect(member, new isInstanceOf<ClassTypeAlias>());
13325 ClassTypeAlias declaration = member;
13326 expect(declaration.name.name, "A");
13327 expect(declaration.abstractKeyword, isNotNull);
13328 }
13329
13330 void test_parseCompilationUnitMember_constVariable() {
13331 createParser('const int x = 0;');
13332 CompilationUnitMember member = parseFullCompilationUnitMember();
13333 expectNotNullIfNoErrors(member);
13334 listener.assertNoErrors();
13335 expect(member, new isInstanceOf<TopLevelVariableDeclaration>());
13336 TopLevelVariableDeclaration declaration = member;
13337 expect(declaration.semicolon, isNotNull);
13338 expect(declaration.variables, isNotNull);
13339 }
13340
13341 void test_parseCompilationUnitMember_finalVariable() {
13342 createParser('final x = 0;');
13343 CompilationUnitMember member = parseFullCompilationUnitMember();
13344 expectNotNullIfNoErrors(member);
13345 listener.assertNoErrors();
13346 expect(member, new isInstanceOf<TopLevelVariableDeclaration>());
13347 TopLevelVariableDeclaration declaration = member;
13348 expect(declaration.semicolon, isNotNull);
13349 expect(declaration.variables, isNotNull);
13350 }
13351
13352 void test_parseCompilationUnitMember_function_external_noType() {
13353 createParser('external f();');
13354 CompilationUnitMember member = parseFullCompilationUnitMember();
13355 expectNotNullIfNoErrors(member);
13356 listener.assertNoErrors();
13357 expect(member, new isInstanceOf<FunctionDeclaration>());
13358 FunctionDeclaration declaration = member;
13359 expect(declaration.externalKeyword, isNotNull);
13360 expect(declaration.functionExpression, isNotNull);
13361 expect(declaration.propertyKeyword, isNull);
13362 }
13363
13364 void test_parseCompilationUnitMember_function_external_type() {
13365 createParser('external int f();');
13366 CompilationUnitMember member = parseFullCompilationUnitMember();
13367 expectNotNullIfNoErrors(member);
13368 listener.assertNoErrors();
13369 expect(member, new isInstanceOf<FunctionDeclaration>());
13370 FunctionDeclaration declaration = member;
13371 expect(declaration.externalKeyword, isNotNull);
13372 expect(declaration.functionExpression, isNotNull);
13373 expect(declaration.propertyKeyword, isNull);
13374 }
13375
13376 void test_parseCompilationUnitMember_function_generic_noReturnType() {
13377 createParser('f<E>() {}');
13378 CompilationUnitMember member = parseFullCompilationUnitMember();
13379 expectNotNullIfNoErrors(member);
13380 listener.assertNoErrors();
13381 expect(member, new isInstanceOf<FunctionDeclaration>());
13382 FunctionDeclaration declaration = member;
13383 expect(declaration.returnType, isNull);
13384 expect(declaration.functionExpression.typeParameters, isNotNull);
13385 }
13386
13387 void
13388 test_parseCompilationUnitMember_function_generic_noReturnType_annotated() {
13389 createParser('f<@a E>() {}');
13390 CompilationUnitMember member = parseFullCompilationUnitMember();
13391 expectNotNullIfNoErrors(member);
13392 listener.assertNoErrors();
13393 expect(member, new isInstanceOf<FunctionDeclaration>());
13394 FunctionDeclaration declaration = member;
13395 expect(declaration.returnType, isNull);
13396 expect(declaration.functionExpression.typeParameters, isNotNull);
13397 }
13398
13399 void test_parseCompilationUnitMember_function_generic_returnType() {
13400 createParser('E f<E>() {}');
13401 CompilationUnitMember member = parseFullCompilationUnitMember();
13402 expectNotNullIfNoErrors(member);
13403 listener.assertNoErrors();
13404 expect(member, new isInstanceOf<FunctionDeclaration>());
13405 FunctionDeclaration declaration = member;
13406 expect(declaration.returnType, isNotNull);
13407 expect(declaration.functionExpression.typeParameters, isNotNull);
13408 }
13409
13410 void test_parseCompilationUnitMember_function_generic_void() {
13411 createParser('void f<T>(T t) {}');
13412 CompilationUnitMember member = parseFullCompilationUnitMember();
13413 expectNotNullIfNoErrors(member);
13414 listener.assertNoErrors();
13415 expect(member, new isInstanceOf<FunctionDeclaration>());
13416 FunctionDeclaration declaration = member;
13417 expect(declaration.functionExpression, isNotNull);
13418 expect(declaration.propertyKeyword, isNull);
13419 }
13420
13421 void test_parseCompilationUnitMember_function_noType() {
13422 createParser('f() {}');
13423 CompilationUnitMember member = parseFullCompilationUnitMember();
13424 expectNotNullIfNoErrors(member);
13425 listener.assertNoErrors();
13426 expect(member, new isInstanceOf<FunctionDeclaration>());
13427 FunctionDeclaration declaration = member;
13428 expect(declaration.functionExpression, isNotNull);
13429 expect(declaration.propertyKeyword, isNull);
13430 }
13431
13432 void test_parseCompilationUnitMember_function_type() {
13433 createParser('int f() {}');
13434 CompilationUnitMember member = parseFullCompilationUnitMember();
13435 expectNotNullIfNoErrors(member);
13436 listener.assertNoErrors();
13437 expect(member, new isInstanceOf<FunctionDeclaration>());
13438 FunctionDeclaration declaration = member;
13439 expect(declaration.functionExpression, isNotNull);
13440 expect(declaration.propertyKeyword, isNull);
13441 }
13442
13443 void test_parseCompilationUnitMember_function_void() {
13444 createParser('void f() {}');
13445 CompilationUnitMember member = parseFullCompilationUnitMember();
13446 expectNotNullIfNoErrors(member);
13447 listener.assertNoErrors();
13448 expect(member, new isInstanceOf<FunctionDeclaration>());
13449 FunctionDeclaration declaration = member;
13450 expect(declaration.returnType, isNotNull);
13451 }
13452
13453 void test_parseCompilationUnitMember_getter_external_noType() {
13454 createParser('external get p;');
13455 CompilationUnitMember member = parseFullCompilationUnitMember();
13456 expectNotNullIfNoErrors(member);
13457 listener.assertNoErrors();
13458 expect(member, new isInstanceOf<FunctionDeclaration>());
13459 FunctionDeclaration declaration = member;
13460 expect(declaration.externalKeyword, isNotNull);
13461 expect(declaration.functionExpression, isNotNull);
13462 expect(declaration.propertyKeyword, isNotNull);
13463 }
13464
13465 void test_parseCompilationUnitMember_getter_external_type() {
13466 createParser('external int get p;');
13467 CompilationUnitMember member = parseFullCompilationUnitMember();
13468 expectNotNullIfNoErrors(member);
13469 listener.assertNoErrors();
13470 expect(member, new isInstanceOf<FunctionDeclaration>());
13471 FunctionDeclaration declaration = member;
13472 expect(declaration.externalKeyword, isNotNull);
13473 expect(declaration.functionExpression, isNotNull);
13474 expect(declaration.propertyKeyword, isNotNull);
13475 }
13476
13477 void test_parseCompilationUnitMember_getter_noType() {
13478 createParser('get p => 0;');
13479 CompilationUnitMember member = parseFullCompilationUnitMember();
13480 expectNotNullIfNoErrors(member);
13481 listener.assertNoErrors();
13482 expect(member, new isInstanceOf<FunctionDeclaration>());
13483 FunctionDeclaration declaration = member;
13484 expect(declaration.functionExpression, isNotNull);
13485 expect(declaration.propertyKeyword, isNotNull);
13486 }
13487
13488 void test_parseCompilationUnitMember_getter_type() {
13489 createParser('int get p => 0;');
13490 CompilationUnitMember member = parseFullCompilationUnitMember();
13491 expectNotNullIfNoErrors(member);
13492 listener.assertNoErrors();
13493 expect(member, new isInstanceOf<FunctionDeclaration>());
13494 FunctionDeclaration declaration = member;
13495 expect(declaration.functionExpression, isNotNull);
13496 expect(declaration.propertyKeyword, isNotNull);
13497 }
13498
13499 void test_parseCompilationUnitMember_setter_external_noType() {
13500 createParser('external set p(v);');
13501 CompilationUnitMember member = parseFullCompilationUnitMember();
13502 expectNotNullIfNoErrors(member);
13503 listener.assertNoErrors();
13504 expect(member, new isInstanceOf<FunctionDeclaration>());
13505 FunctionDeclaration declaration = member;
13506 expect(declaration.externalKeyword, isNotNull);
13507 expect(declaration.functionExpression, isNotNull);
13508 expect(declaration.propertyKeyword, isNotNull);
13509 }
13510
13511 void test_parseCompilationUnitMember_setter_external_type() {
13512 createParser('external void set p(int v);');
13513 CompilationUnitMember member = parseFullCompilationUnitMember();
13514 expectNotNullIfNoErrors(member);
13515 listener.assertNoErrors();
13516 expect(member, new isInstanceOf<FunctionDeclaration>());
13517 FunctionDeclaration declaration = member;
13518 expect(declaration.externalKeyword, isNotNull);
13519 expect(declaration.functionExpression, isNotNull);
13520 expect(declaration.propertyKeyword, isNotNull);
13521 }
13522
13523 void test_parseCompilationUnitMember_setter_noType() {
13524 createParser('set p(v) {}');
13525 CompilationUnitMember member = parseFullCompilationUnitMember();
13526 expectNotNullIfNoErrors(member);
13527 listener.assertNoErrors();
13528 expect(member, new isInstanceOf<FunctionDeclaration>());
13529 FunctionDeclaration declaration = member;
13530 expect(declaration.functionExpression, isNotNull);
13531 expect(declaration.propertyKeyword, isNotNull);
13532 }
13533
13534 void test_parseCompilationUnitMember_setter_type() {
13535 createParser('void set p(int v) {}');
13536 CompilationUnitMember member = parseFullCompilationUnitMember();
13537 expectNotNullIfNoErrors(member);
13538 listener.assertNoErrors();
13539 expect(member, new isInstanceOf<FunctionDeclaration>());
13540 FunctionDeclaration declaration = member;
13541 expect(declaration.functionExpression, isNotNull);
13542 expect(declaration.propertyKeyword, isNotNull);
13543 expect(declaration.returnType, isNotNull);
13544 }
13545
13546 void test_parseCompilationUnitMember_typeAlias_abstract() {
13547 createParser('abstract class C = S with M;');
13548 CompilationUnitMember member = parseFullCompilationUnitMember();
13549 expectNotNullIfNoErrors(member);
13550 listener.assertNoErrors();
13551 expect(member, new isInstanceOf<ClassTypeAlias>());
13552 ClassTypeAlias typeAlias = member;
13553 expect(typeAlias.typedefKeyword, isNotNull);
13554 expect(typeAlias.name.name, "C");
13555 expect(typeAlias.typeParameters, isNull);
13556 expect(typeAlias.equals, isNotNull);
13557 expect(typeAlias.abstractKeyword, isNotNull);
13558 expect(typeAlias.superclass.name.name, "S");
13559 expect(typeAlias.withClause, isNotNull);
13560 expect(typeAlias.implementsClause, isNull);
13561 expect(typeAlias.semicolon, isNotNull);
13562 }
13563
13564 void test_parseCompilationUnitMember_typeAlias_generic() {
13565 createParser('class C<E> = S<E> with M<E> implements I<E>;');
13566 CompilationUnitMember member = parseFullCompilationUnitMember();
13567 expectNotNullIfNoErrors(member);
13568 listener.assertNoErrors();
13569 expect(member, new isInstanceOf<ClassTypeAlias>());
13570 ClassTypeAlias typeAlias = member;
13571 expect(typeAlias.typedefKeyword, isNotNull);
13572 expect(typeAlias.name.name, "C");
13573 expect(typeAlias.typeParameters.typeParameters, hasLength(1));
13574 expect(typeAlias.equals, isNotNull);
13575 expect(typeAlias.abstractKeyword, isNull);
13576 expect(typeAlias.superclass.name.name, "S");
13577 expect(typeAlias.withClause, isNotNull);
13578 expect(typeAlias.implementsClause, isNotNull);
13579 expect(typeAlias.semicolon, isNotNull);
13580 }
13581
13582 void test_parseCompilationUnitMember_typeAlias_implements() {
13583 createParser('class C = S with M implements I;');
13584 CompilationUnitMember member = parseFullCompilationUnitMember();
13585 expectNotNullIfNoErrors(member);
13586 listener.assertNoErrors();
13587 expect(member, new isInstanceOf<ClassTypeAlias>());
13588 ClassTypeAlias typeAlias = member;
13589 expect(typeAlias.typedefKeyword, isNotNull);
13590 expect(typeAlias.name.name, "C");
13591 expect(typeAlias.typeParameters, isNull);
13592 expect(typeAlias.equals, isNotNull);
13593 expect(typeAlias.abstractKeyword, isNull);
13594 expect(typeAlias.superclass.name.name, "S");
13595 expect(typeAlias.withClause, isNotNull);
13596 expect(typeAlias.implementsClause, isNotNull);
13597 expect(typeAlias.semicolon, isNotNull);
13598 }
13599
13600 void test_parseCompilationUnitMember_typeAlias_noImplements() {
13601 createParser('class C = S with M;');
13602 CompilationUnitMember member = parseFullCompilationUnitMember();
13603 expectNotNullIfNoErrors(member);
13604 listener.assertNoErrors();
13605 expect(member, new isInstanceOf<ClassTypeAlias>());
13606 ClassTypeAlias typeAlias = member;
13607 expect(typeAlias.typedefKeyword, isNotNull);
13608 expect(typeAlias.name.name, "C");
13609 expect(typeAlias.typeParameters, isNull);
13610 expect(typeAlias.equals, isNotNull);
13611 expect(typeAlias.abstractKeyword, isNull);
13612 expect(typeAlias.superclass.name.name, "S");
13613 expect(typeAlias.withClause, isNotNull);
13614 expect(typeAlias.implementsClause, isNull);
13615 expect(typeAlias.semicolon, isNotNull);
13616 }
13617
13618 void test_parseCompilationUnitMember_typedef() {
13619 createParser('typedef F();');
13620 CompilationUnitMember member = parseFullCompilationUnitMember();
13621 expectNotNullIfNoErrors(member);
13622 listener.assertNoErrors();
13623 expect(member, new isInstanceOf<FunctionTypeAlias>());
13624 FunctionTypeAlias typeAlias = member;
13625 expect(typeAlias.name.name, "F");
13626 expect(typeAlias.parameters.parameters, hasLength(0));
13627 }
13628
13629 void test_parseCompilationUnitMember_variable() {
13630 createParser('var x = 0;');
13631 CompilationUnitMember member = parseFullCompilationUnitMember();
13632 expectNotNullIfNoErrors(member);
13633 listener.assertNoErrors();
13634 expect(member, new isInstanceOf<TopLevelVariableDeclaration>());
13635 TopLevelVariableDeclaration declaration = member;
13636 expect(declaration.semicolon, isNotNull);
13637 expect(declaration.variables, isNotNull);
13638 }
13639
13640 void test_parseCompilationUnitMember_variableGet() {
13641 createParser('String get = null;');
13642 CompilationUnitMember member = parseFullCompilationUnitMember();
13643 expectNotNullIfNoErrors(member);
13644 listener.assertNoErrors();
13645 expect(member, new isInstanceOf<TopLevelVariableDeclaration>());
13646 TopLevelVariableDeclaration declaration = member;
13647 expect(declaration.semicolon, isNotNull);
13648 expect(declaration.variables, isNotNull);
13649 }
13650
13651 void test_parseCompilationUnitMember_variableSet() {
13652 createParser('String set = null;');
13653 CompilationUnitMember member = parseFullCompilationUnitMember();
13654 expectNotNullIfNoErrors(member);
13655 listener.assertNoErrors();
13656 expect(member, new isInstanceOf<TopLevelVariableDeclaration>());
13657 TopLevelVariableDeclaration declaration = member;
13658 expect(declaration.semicolon, isNotNull);
13659 expect(declaration.variables, isNotNull);
13660 }
13661
13662 void test_parseDirective_export() {
13663 createParser("export 'lib/lib.dart';");
13664 Directive directive = parseFullDirective();
13665 expectNotNullIfNoErrors(directive);
13666 listener.assertNoErrors();
13667 expect(directive, new isInstanceOf<ExportDirective>());
13668 ExportDirective exportDirective = directive;
13669 expect(exportDirective.keyword, isNotNull);
13670 expect(exportDirective.uri, isNotNull);
13671 expect(exportDirective.combinators, hasLength(0));
13672 expect(exportDirective.semicolon, isNotNull);
13673 }
13674
13675 void test_parseDirective_import() {
13676 createParser("import 'lib/lib.dart';");
13677 Directive directive = parseFullDirective();
13678 expectNotNullIfNoErrors(directive);
13679 listener.assertNoErrors();
13680 expect(directive, new isInstanceOf<ImportDirective>());
13681 ImportDirective importDirective = directive;
13682 expect(importDirective.keyword, isNotNull);
13683 expect(importDirective.uri, isNotNull);
13684 expect(importDirective.asKeyword, isNull);
13685 expect(importDirective.prefix, isNull);
13686 expect(importDirective.combinators, hasLength(0));
13687 expect(importDirective.semicolon, isNotNull);
13688 }
13689
13690 void test_parseDirective_library() {
13691 createParser("library l;");
13692 Directive directive = parseFullDirective();
13693 expectNotNullIfNoErrors(directive);
13694 listener.assertNoErrors();
13695 expect(directive, new isInstanceOf<LibraryDirective>());
13696 LibraryDirective libraryDirective = directive;
13697 expect(libraryDirective.libraryKeyword, isNotNull);
13698 expect(libraryDirective.name, isNotNull);
13699 expect(libraryDirective.semicolon, isNotNull);
13700 }
13701
13702 void test_parseDirective_part() {
13703 createParser("part 'lib/lib.dart';");
13704 Directive directive = parseFullDirective();
13705 expectNotNullIfNoErrors(directive);
13706 listener.assertNoErrors();
13707 expect(directive, new isInstanceOf<PartDirective>());
13708 PartDirective partDirective = directive;
13709 expect(partDirective.partKeyword, isNotNull);
13710 expect(partDirective.uri, isNotNull);
13711 expect(partDirective.semicolon, isNotNull);
13712 }
13713
13714 void test_parseDirective_partOf() {
13715 createParser("part of l;");
13716 Directive directive = parseFullDirective();
13717 expectNotNullIfNoErrors(directive);
13718 listener.assertNoErrors();
13719 expect(directive, new isInstanceOf<PartOfDirective>());
13720 PartOfDirective partOfDirective = directive;
13721 expect(partOfDirective.partKeyword, isNotNull);
13722 expect(partOfDirective.ofKeyword, isNotNull);
13723 expect(partOfDirective.libraryName, isNotNull);
13724 expect(partOfDirective.semicolon, isNotNull);
13725 }
13726
13727 void test_parseDirectives_complete() {
13728 CompilationUnit unit =
13729 _parseDirectives("#! /bin/dart\nlibrary l;\nclass A {}");
13730 expect(unit.scriptTag, isNotNull);
13731 expect(unit.directives, hasLength(1));
13732 }
13733
13734 void test_parseDirectives_empty() {
13735 CompilationUnit unit = _parseDirectives("");
13736 expect(unit.scriptTag, isNull);
13737 expect(unit.directives, hasLength(0));
13738 }
13739
13740 void test_parseDirectives_mixed() {
13741 CompilationUnit unit =
13742 _parseDirectives("library l; class A {} part 'foo.dart';");
13743 expect(unit.scriptTag, isNull);
13744 expect(unit.directives, hasLength(1));
13745 }
13746
13747 void test_parseDirectives_multiple() {
13748 CompilationUnit unit = _parseDirectives("library l;\npart 'a.dart';");
13749 expect(unit.scriptTag, isNull);
13750 expect(unit.directives, hasLength(2));
13751 }
13752
13753 void test_parseDirectives_script() {
13754 CompilationUnit unit = _parseDirectives("#! /bin/dart");
13755 expect(unit.scriptTag, isNotNull);
13756 expect(unit.directives, hasLength(0));
13757 }
13758
13759 void test_parseDirectives_single() {
13760 CompilationUnit unit = _parseDirectives("library l;");
13761 expect(unit.scriptTag, isNull);
13762 expect(unit.directives, hasLength(1));
13763 }
13764
13765 void test_parseDirectives_topLevelDeclaration() {
13766 CompilationUnit unit = _parseDirectives("class A {}");
13767 expect(unit.scriptTag, isNull);
13768 expect(unit.directives, hasLength(0));
13769 }
13770
13771 void test_parseEnumDeclaration_one() {
13772 createParser("enum E {ONE}");
13773 EnumDeclaration declaration = parseFullCompilationUnitMember();
13774 expectNotNullIfNoErrors(declaration);
13775 listener.assertNoErrors();
13776 expect(declaration.documentationComment, isNull);
13777 expect(declaration.enumKeyword, isNotNull);
13778 expect(declaration.leftBracket, isNotNull);
13779 expect(declaration.name, isNotNull);
13780 expect(declaration.constants, hasLength(1));
13781 expect(declaration.rightBracket, isNotNull);
13782 }
13783
13784 void test_parseEnumDeclaration_trailingComma() {
13785 createParser("enum E {ONE,}");
13786 EnumDeclaration declaration = parseFullCompilationUnitMember();
13787 expectNotNullIfNoErrors(declaration);
13788 listener.assertNoErrors();
13789 expect(declaration.documentationComment, isNull);
13790 expect(declaration.enumKeyword, isNotNull);
13791 expect(declaration.leftBracket, isNotNull);
13792 expect(declaration.name, isNotNull);
13793 expect(declaration.constants, hasLength(1));
13794 expect(declaration.rightBracket, isNotNull);
13795 }
13796
13797 void test_parseEnumDeclaration_two() {
13798 createParser("enum E {ONE, TWO}");
13799 EnumDeclaration declaration = parseFullCompilationUnitMember();
13800 expectNotNullIfNoErrors(declaration);
13801 listener.assertNoErrors();
13802 expect(declaration.documentationComment, isNull);
13803 expect(declaration.enumKeyword, isNotNull);
13804 expect(declaration.leftBracket, isNotNull);
13805 expect(declaration.name, isNotNull);
13806 expect(declaration.constants, hasLength(2));
13807 expect(declaration.rightBracket, isNotNull);
13808 }
13809
13810 void test_parseExportDirective_configuration_multiple() {
13811 createParser("export 'lib/lib.dart' if (a) 'b.dart' if (c) 'd.dart';");
13812 ExportDirective directive = parseFullDirective();
13813 expectNotNullIfNoErrors(directive);
13814 listener.assertNoErrors();
13815 expect(directive.keyword, isNotNull);
13816 expect(directive.uri, isNotNull);
13817 expect(directive.configurations, hasLength(2));
13818 expectDottedName(directive.configurations[0].name, ['a']);
13819 expectDottedName(directive.configurations[1].name, ['c']);
13820 expect(directive.combinators, hasLength(0));
13821 expect(directive.semicolon, isNotNull);
13822 }
13823
13824 void test_parseExportDirective_configuration_single() {
13825 createParser("export 'lib/lib.dart' if (a.b == 'c.dart') '';");
13826 ExportDirective directive = parseFullDirective();
13827 expectNotNullIfNoErrors(directive);
13828 listener.assertNoErrors();
13829 expect(directive.keyword, isNotNull);
13830 expect(directive.uri, isNotNull);
13831 expect(directive.configurations, hasLength(1));
13832 expectDottedName(directive.configurations[0].name, ['a', 'b']);
13833 expect(directive.combinators, hasLength(0));
13834 expect(directive.semicolon, isNotNull);
13835 }
13836
13837 void test_parseExportDirective_hide() {
13838 createParser("export 'lib/lib.dart' hide A, B;");
13839 ExportDirective directive = parseFullDirective();
13840 expectNotNullIfNoErrors(directive);
13841 listener.assertNoErrors();
13842 expect(directive.keyword, isNotNull);
13843 expect(directive.uri, isNotNull);
13844 expect(directive.combinators, hasLength(1));
13845 expect(directive.semicolon, isNotNull);
13846 }
13847
13848 void test_parseExportDirective_hide_show() {
13849 createParser("export 'lib/lib.dart' hide A show B;");
13850 ExportDirective directive = parseFullDirective();
13851 expectNotNullIfNoErrors(directive);
13852 listener.assertNoErrors();
13853 expect(directive.keyword, isNotNull);
13854 expect(directive.uri, isNotNull);
13855 expect(directive.combinators, hasLength(2));
13856 expect(directive.semicolon, isNotNull);
13857 }
13858
13859 void test_parseExportDirective_noCombinator() {
13860 createParser("export 'lib/lib.dart';");
13861 ExportDirective directive = parseFullDirective();
13862 expectNotNullIfNoErrors(directive);
13863 listener.assertNoErrors();
13864 expect(directive.keyword, isNotNull);
13865 expect(directive.uri, isNotNull);
13866 expect(directive.combinators, hasLength(0));
13867 expect(directive.semicolon, isNotNull);
13868 }
13869
13870 void test_parseExportDirective_show() {
13871 createParser("export 'lib/lib.dart' show A, B;");
13872 ExportDirective directive = parseFullDirective();
13873 expectNotNullIfNoErrors(directive);
13874 listener.assertNoErrors();
13875 expect(directive.keyword, isNotNull);
13876 expect(directive.uri, isNotNull);
13877 expect(directive.combinators, hasLength(1));
13878 expect(directive.semicolon, isNotNull);
13879 }
13880
13881 void test_parseExportDirective_show_hide() {
13882 createParser("export 'lib/lib.dart' show B hide A;");
13883 ExportDirective directive = parseFullDirective();
13884 expectNotNullIfNoErrors(directive);
13885 listener.assertNoErrors();
13886 expect(directive.keyword, isNotNull);
13887 expect(directive.uri, isNotNull);
13888 expect(directive.combinators, hasLength(2));
13889 expect(directive.semicolon, isNotNull);
13890 }
13891
13892 void test_parseFunctionDeclaration_function() {
13893 createParser('/// Doc\nT f() {}');
13894 FunctionDeclaration declaration = parseFullCompilationUnitMember();
13895 expectNotNullIfNoErrors(declaration);
13896 listener.assertNoErrors();
13897 expectCommentText(declaration.documentationComment, '/// Doc');
13898 expect((declaration.returnType as TypeName).name.name, 'T');
13899 expect(declaration.name, isNotNull);
13900 FunctionExpression expression = declaration.functionExpression;
13901 expect(expression, isNotNull);
13902 expect(expression.body, isNotNull);
13903 expect(expression.typeParameters, isNull);
13904 expect(expression.parameters, isNotNull);
13905 expect(declaration.propertyKeyword, isNull);
13906 }
13907
13908 void test_parseFunctionDeclaration_functionWithTypeParameters() {
13909 createParser('/// Doc\nT f<E>() {}');
13910 FunctionDeclaration declaration = parseFullCompilationUnitMember();
13911 expectNotNullIfNoErrors(declaration);
13912 listener.assertNoErrors();
13913 expectCommentText(declaration.documentationComment, '/// Doc');
13914 expect((declaration.returnType as TypeName).name.name, 'T');
13915 expect(declaration.name, isNotNull);
13916 FunctionExpression expression = declaration.functionExpression;
13917 expect(expression, isNotNull);
13918 expect(expression.body, isNotNull);
13919 expect(expression.typeParameters, isNotNull);
13920 expect(expression.parameters, isNotNull);
13921 expect(declaration.propertyKeyword, isNull);
13922 }
13923
13924 void test_parseFunctionDeclaration_functionWithTypeParameters_comment() {
13925 enableGenericMethodComments = true;
13926 createParser('/// Doc\nT f/*<E>*/() {}');
13927 FunctionDeclaration declaration = parseFullCompilationUnitMember();
13928 expectNotNullIfNoErrors(declaration);
13929 listener.assertNoErrors();
13930 expectCommentText(declaration.documentationComment, '/// Doc');
13931 expect((declaration.returnType as TypeName).name.name, 'T');
13932 expect(declaration.name, isNotNull);
13933 FunctionExpression expression = declaration.functionExpression;
13934 expect(expression, isNotNull);
13935 expect(expression.body, isNotNull);
13936 expect(expression.typeParameters, isNotNull);
13937 expect(expression.parameters, isNotNull);
13938 expect(declaration.propertyKeyword, isNull);
13939 }
13940
13941 void test_parseFunctionDeclaration_getter() {
13942 createParser('/// Doc\nT get p => 0;');
13943 FunctionDeclaration declaration = parseFullCompilationUnitMember();
13944 expectNotNullIfNoErrors(declaration);
13945 listener.assertNoErrors();
13946 expectCommentText(declaration.documentationComment, '/// Doc');
13947 expect((declaration.returnType as TypeName).name.name, 'T');
13948 expect(declaration.name, isNotNull);
13949 FunctionExpression expression = declaration.functionExpression;
13950 expect(expression, isNotNull);
13951 expect(expression.body, isNotNull);
13952 expect(expression.typeParameters, isNull);
13953 expect(expression.parameters, isNull);
13954 expect(declaration.propertyKeyword, isNotNull);
13955 }
13956
13957 void test_parseFunctionDeclaration_setter() {
13958 createParser('/// Doc\nT set p(v) {}');
13959 FunctionDeclaration declaration = parseFullCompilationUnitMember();
13960 expectNotNullIfNoErrors(declaration);
13961 listener.assertNoErrors();
13962 expectCommentText(declaration.documentationComment, '/// Doc');
13963 expect((declaration.returnType as TypeName).name.name, 'T');
13964 expect(declaration.name, isNotNull);
13965 FunctionExpression expression = declaration.functionExpression;
13966 expect(expression, isNotNull);
13967 expect(expression.body, isNotNull);
13968 expect(expression.typeParameters, isNull);
13969 expect(expression.parameters, isNotNull);
13970 expect(declaration.propertyKeyword, isNotNull);
13971 }
13972
13973 @failingTest
13974 void test_parseGenericTypeAlias_noTypeParameters() {
13975 createParser('F = int Function(int);');
13976 GenericTypeAlias alias = parseFullCompilationUnitMember();
13977 expectNotNullIfNoErrors(alias);
13978 listener.assertNoErrors();
13979 expect(alias.name, isNotNull);
13980 expect(alias.name.name, 'F');
13981 expect(alias.typeParameters, isNull);
13982 expect(alias.equals, isNotNull);
13983 expect(alias.functionType, isNotNull);
13984 expect(alias.semicolon, isNotNull);
13985 }
13986
13987 @failingTest
13988 void test_parseGenericTypeAlias_typeParameters() {
13989 createParser('F<T> = T Function(T);');
13990 GenericTypeAlias alias = parseFullCompilationUnitMember();
13991 expectNotNullIfNoErrors(alias);
13992 listener.assertNoErrors();
13993 expect(alias.name, isNotNull);
13994 expect(alias.name.name, 'F');
13995 expect(alias.typeParameters, isNotNull);
13996 expect(alias.equals, isNotNull);
13997 expect(alias.functionType, isNotNull);
13998 expect(alias.semicolon, isNotNull);
13999 }
14000
14001 void test_parseImportDirective_configuration_multiple() {
14002 createParser("import 'lib/lib.dart' if (a) 'b.dart' if (c) 'd.dart';");
14003 ImportDirective directive = parseFullDirective();
14004 expectNotNullIfNoErrors(directive);
14005 listener.assertNoErrors();
14006 expect(directive.keyword, isNotNull);
14007 expect(directive.uri, isNotNull);
14008 expect(directive.configurations, hasLength(2));
14009 expectDottedName(directive.configurations[0].name, ['a']);
14010 expectDottedName(directive.configurations[1].name, ['c']);
14011 expect(directive.deferredKeyword, isNull);
14012 expect(directive.asKeyword, isNull);
14013 expect(directive.prefix, isNull);
14014 expect(directive.combinators, hasLength(0));
14015 expect(directive.semicolon, isNotNull);
14016 }
14017
14018 void test_parseImportDirective_configuration_single() {
14019 createParser("import 'lib/lib.dart' if (a.b == 'c.dart') '';");
14020 ImportDirective directive = parseFullDirective();
14021 expectNotNullIfNoErrors(directive);
14022 listener.assertNoErrors();
14023 expect(directive.keyword, isNotNull);
14024 expect(directive.uri, isNotNull);
14025 expect(directive.configurations, hasLength(1));
14026 expectDottedName(directive.configurations[0].name, ['a', 'b']);
14027 expect(directive.deferredKeyword, isNull);
14028 expect(directive.asKeyword, isNull);
14029 expect(directive.prefix, isNull);
14030 expect(directive.combinators, hasLength(0));
14031 expect(directive.semicolon, isNotNull);
14032 }
14033
14034 void test_parseImportDirective_deferred() {
14035 createParser("import 'lib/lib.dart' deferred as a;");
14036 ImportDirective directive = parseFullDirective();
14037 expectNotNullIfNoErrors(directive);
14038 listener.assertNoErrors();
14039 expect(directive.keyword, isNotNull);
14040 expect(directive.uri, isNotNull);
14041 expect(directive.deferredKeyword, isNotNull);
14042 expect(directive.asKeyword, isNotNull);
14043 expect(directive.prefix, isNotNull);
14044 expect(directive.combinators, hasLength(0));
14045 expect(directive.semicolon, isNotNull);
14046 }
14047
14048 void test_parseImportDirective_hide() {
14049 createParser("import 'lib/lib.dart' hide A, B;");
14050 ImportDirective directive = parseFullDirective();
14051 expectNotNullIfNoErrors(directive);
14052 listener.assertNoErrors();
14053 expect(directive.keyword, isNotNull);
14054 expect(directive.uri, isNotNull);
14055 expect(directive.deferredKeyword, isNull);
14056 expect(directive.asKeyword, isNull);
14057 expect(directive.prefix, isNull);
14058 expect(directive.combinators, hasLength(1));
14059 expect(directive.semicolon, isNotNull);
14060 }
14061
14062 void test_parseImportDirective_noCombinator() {
14063 createParser("import 'lib/lib.dart';");
14064 ImportDirective directive = parseFullDirective();
14065 expectNotNullIfNoErrors(directive);
14066 listener.assertNoErrors();
14067 expect(directive.keyword, isNotNull);
14068 expect(directive.uri, isNotNull);
14069 expect(directive.deferredKeyword, isNull);
14070 expect(directive.asKeyword, isNull);
14071 expect(directive.prefix, isNull);
14072 expect(directive.combinators, hasLength(0));
14073 expect(directive.semicolon, isNotNull);
14074 }
14075
14076 void test_parseImportDirective_prefix() {
14077 createParser("import 'lib/lib.dart' as a;");
14078 ImportDirective directive = parseFullDirective();
14079 expectNotNullIfNoErrors(directive);
14080 listener.assertNoErrors();
14081 expect(directive.keyword, isNotNull);
14082 expect(directive.uri, isNotNull);
14083 expect(directive.deferredKeyword, isNull);
14084 expect(directive.asKeyword, isNotNull);
14085 expect(directive.prefix, isNotNull);
14086 expect(directive.combinators, hasLength(0));
14087 expect(directive.semicolon, isNotNull);
14088 }
14089
14090 void test_parseImportDirective_prefix_hide_show() {
14091 createParser("import 'lib/lib.dart' as a hide A show B;");
14092 ImportDirective directive = parseFullDirective();
14093 expectNotNullIfNoErrors(directive);
14094 listener.assertNoErrors();
14095 expect(directive.keyword, isNotNull);
14096 expect(directive.uri, isNotNull);
14097 expect(directive.deferredKeyword, isNull);
14098 expect(directive.asKeyword, isNotNull);
14099 expect(directive.prefix, isNotNull);
14100 expect(directive.combinators, hasLength(2));
14101 expect(directive.semicolon, isNotNull);
14102 }
14103
14104 void test_parseImportDirective_prefix_show_hide() {
14105 createParser("import 'lib/lib.dart' as a show B hide A;");
14106 ImportDirective directive = parseFullDirective();
14107 expectNotNullIfNoErrors(directive);
14108 listener.assertNoErrors();
14109 expect(directive.keyword, isNotNull);
14110 expect(directive.uri, isNotNull);
14111 expect(directive.deferredKeyword, isNull);
14112 expect(directive.asKeyword, isNotNull);
14113 expect(directive.prefix, isNotNull);
14114 expect(directive.combinators, hasLength(2));
14115 expect(directive.semicolon, isNotNull);
14116 }
14117
14118 void test_parseImportDirective_show() {
14119 createParser("import 'lib/lib.dart' show A, B;");
14120 ImportDirective directive = parseFullDirective();
14121 expectNotNullIfNoErrors(directive);
14122 listener.assertNoErrors();
14123 expect(directive.keyword, isNotNull);
14124 expect(directive.uri, isNotNull);
14125 expect(directive.deferredKeyword, isNull);
14126 expect(directive.asKeyword, isNull);
14127 expect(directive.prefix, isNull);
14128 expect(directive.combinators, hasLength(1));
14129 expect(directive.semicolon, isNotNull);
14130 }
14131
14132 void test_parseLibraryDirective() {
14133 createParser('library l;');
14134 LibraryDirective directive = parseFullDirective();
14135 expectNotNullIfNoErrors(directive);
14136 listener.assertNoErrors();
14137 expect(directive.libraryKeyword, isNotNull);
14138 expect(directive.name, isNotNull);
14139 expect(directive.semicolon, isNotNull);
14140 }
14141
14142 void test_parsePartDirective() {
14143 createParser("part 'lib/lib.dart';");
14144 PartDirective directive = parseFullDirective();
14145 expectNotNullIfNoErrors(directive);
14146 listener.assertNoErrors();
14147 expect(directive.partKeyword, isNotNull);
14148 expect(directive.uri, isNotNull);
14149 expect(directive.semicolon, isNotNull);
14150 }
14151
14152 void test_parsePartOfDirective_name() {
14153 enableUriInPartOf = true;
14154 createParser("part of l;");
14155 PartOfDirective directive = parseFullDirective();
14156 expect(directive.partKeyword, isNotNull);
14157 expect(directive.ofKeyword, isNotNull);
14158 expect(directive.libraryName, isNotNull);
14159 expect(directive.uri, isNull);
14160 expect(directive.semicolon, isNotNull);
14161 }
14162
14163 void test_parsePartOfDirective_uri() {
14164 enableUriInPartOf = true;
14165 createParser("part of 'lib.dart';");
14166 PartOfDirective directive = parseFullDirective();
14167 expect(directive.partKeyword, isNotNull);
14168 expect(directive.ofKeyword, isNotNull);
14169 expect(directive.libraryName, isNull);
14170 expect(directive.uri, isNotNull);
14171 expect(directive.semicolon, isNotNull);
14172 }
14173
14174 void test_parseTypeAlias_function_noParameters() {
14175 createParser('typedef bool F();');
14176 FunctionTypeAlias typeAlias = parseFullCompilationUnitMember();
14177 expectNotNullIfNoErrors(typeAlias);
14178 listener.assertNoErrors();
14179 expect(typeAlias.typedefKeyword, isNotNull);
14180 expect(typeAlias.name, isNotNull);
14181 expect(typeAlias.parameters, isNotNull);
14182 expect(typeAlias.returnType, isNotNull);
14183 expect(typeAlias.semicolon, isNotNull);
14184 expect(typeAlias.typeParameters, isNull);
14185 }
14186
14187 void test_parseTypeAlias_function_noReturnType() {
14188 createParser('typedef F();');
14189 FunctionTypeAlias typeAlias = parseFullCompilationUnitMember();
14190 expectNotNullIfNoErrors(typeAlias);
14191 listener.assertNoErrors();
14192 expect(typeAlias.typedefKeyword, isNotNull);
14193 expect(typeAlias.name, isNotNull);
14194 expect(typeAlias.parameters, isNotNull);
14195 expect(typeAlias.returnType, isNull);
14196 expect(typeAlias.semicolon, isNotNull);
14197 expect(typeAlias.typeParameters, isNull);
14198 }
14199
14200 void test_parseTypeAlias_function_parameterizedReturnType() {
14201 createParser('typedef A<B> F();');
14202 FunctionTypeAlias typeAlias = parseFullCompilationUnitMember();
14203 expectNotNullIfNoErrors(typeAlias);
14204 listener.assertNoErrors();
14205 expect(typeAlias.typedefKeyword, isNotNull);
14206 expect(typeAlias.name, isNotNull);
14207 expect(typeAlias.parameters, isNotNull);
14208 expect(typeAlias.returnType, isNotNull);
14209 expect(typeAlias.semicolon, isNotNull);
14210 expect(typeAlias.typeParameters, isNull);
14211 }
14212
14213 void test_parseTypeAlias_function_parameters() {
14214 createParser('typedef bool F(Object value);');
14215 FunctionTypeAlias typeAlias = parseFullCompilationUnitMember();
14216 expectNotNullIfNoErrors(typeAlias);
14217 listener.assertNoErrors();
14218 expect(typeAlias.typedefKeyword, isNotNull);
14219 expect(typeAlias.name, isNotNull);
14220 expect(typeAlias.parameters, isNotNull);
14221 expect(typeAlias.returnType, isNotNull);
14222 expect(typeAlias.semicolon, isNotNull);
14223 expect(typeAlias.typeParameters, isNull);
14224 }
14225
14226 void test_parseTypeAlias_function_typeParameters() {
14227 createParser('typedef bool F<E>();');
14228 FunctionTypeAlias typeAlias = parseFullCompilationUnitMember();
14229 expectNotNullIfNoErrors(typeAlias);
14230 listener.assertNoErrors();
14231 expect(typeAlias.typedefKeyword, isNotNull);
14232 expect(typeAlias.name, isNotNull);
14233 expect(typeAlias.parameters, isNotNull);
14234 expect(typeAlias.returnType, isNotNull);
14235 expect(typeAlias.semicolon, isNotNull);
14236 expect(typeAlias.typeParameters, isNotNull);
14237 }
14238
14239 void test_parseTypeAlias_function_voidReturnType() {
14240 createParser('typedef void F();');
14241 FunctionTypeAlias typeAlias = parseFullCompilationUnitMember();
14242 expectNotNullIfNoErrors(typeAlias);
14243 listener.assertNoErrors();
14244 expect(typeAlias.typedefKeyword, isNotNull);
14245 expect(typeAlias.name, isNotNull);
14246 expect(typeAlias.parameters, isNotNull);
14247 expect(typeAlias.returnType, isNotNull);
14248 expect(typeAlias.semicolon, isNotNull);
14249 expect(typeAlias.typeParameters, isNull);
14250 }
14251
14252 @failingTest
14253 void test_parseTypeAlias_genericFunction_noParameters() {
14254 createParser('typedef F = bool Function();');
14255 GenericTypeAlias typeAlias = parseFullCompilationUnitMember();
14256 expectNotNullIfNoErrors(typeAlias);
14257 listener.assertNoErrors();
14258 expect(typeAlias.typedefKeyword, isNotNull);
14259 expect(typeAlias.name, isNotNull);
14260 expect(typeAlias.typeParameters, isNull);
14261 expect(typeAlias.semicolon, isNotNull);
14262 GenericFunctionType functionType = typeAlias.functionType;
14263 expect(functionType, isNotNull);
14264 expect(functionType.parameters, isNotNull);
14265 expect(functionType.returnType, isNotNull);
14266 expect(functionType.typeParameters, isNull);
14267 }
14268
14269 @failingTest
14270 void test_parseTypeAlias_genericFunction_noReturnType() {
14271 createParser('typedef F = Function();');
14272 GenericTypeAlias typeAlias = parseFullCompilationUnitMember();
14273 expectNotNullIfNoErrors(typeAlias);
14274 listener.assertNoErrors();
14275 expect(typeAlias.typedefKeyword, isNotNull);
14276 expect(typeAlias.name, isNotNull);
14277 expect(typeAlias.typeParameters, isNull);
14278 expect(typeAlias.semicolon, isNotNull);
14279 GenericFunctionType functionType = typeAlias.functionType;
14280 expect(functionType, isNotNull);
14281 expect(functionType.parameters, isNotNull);
14282 expect(functionType.returnType, isNull);
14283 expect(functionType.typeParameters, isNull);
14284 }
14285
14286 @failingTest
14287 void test_parseTypeAlias_genericFunction_parameterizedReturnType() {
14288 createParser('typedef F = A<B> Function();');
14289 GenericTypeAlias typeAlias = parseFullCompilationUnitMember();
14290 expectNotNullIfNoErrors(typeAlias);
14291 listener.assertNoErrors();
14292 expect(typeAlias.typedefKeyword, isNotNull);
14293 expect(typeAlias.name, isNotNull);
14294 expect(typeAlias.typeParameters, isNull);
14295 expect(typeAlias.semicolon, isNotNull);
14296 GenericFunctionType functionType = typeAlias.functionType;
14297 expect(functionType, isNotNull);
14298 expect(functionType.parameters, isNotNull);
14299 expect(functionType.returnType, isNotNull);
14300 expect(functionType.typeParameters, isNull);
14301 }
14302
14303 @failingTest
14304 void test_parseTypeAlias_genericFunction_parameters() {
14305 createParser('typedef F = bool Function(Object value);');
14306 GenericTypeAlias typeAlias = parseFullCompilationUnitMember();
14307 expectNotNullIfNoErrors(typeAlias);
14308 listener.assertNoErrors();
14309 expect(typeAlias.typedefKeyword, isNotNull);
14310 expect(typeAlias.name, isNotNull);
14311 expect(typeAlias.typeParameters, isNull);
14312 expect(typeAlias.semicolon, isNotNull);
14313 GenericFunctionType functionType = typeAlias.functionType;
14314 expect(functionType, isNotNull);
14315 expect(functionType.parameters, isNotNull);
14316 expect(functionType.returnType, isNotNull);
14317 expect(functionType.typeParameters, isNull);
14318 }
14319
14320 @failingTest
14321 void test_parseTypeAlias_genericFunction_typeParameters() {
14322 createParser('typedef F = bool Function<E>();');
14323 GenericTypeAlias typeAlias = parseFullCompilationUnitMember();
14324 expectNotNullIfNoErrors(typeAlias);
14325 listener.assertNoErrors();
14326 expect(typeAlias.typedefKeyword, isNotNull);
14327 expect(typeAlias.name, isNotNull);
14328 expect(typeAlias.typeParameters, isNull);
14329 expect(typeAlias.semicolon, isNotNull);
14330 GenericFunctionType functionType = typeAlias.functionType;
14331 expect(functionType, isNotNull);
14332 expect(functionType.parameters, isNotNull);
14333 expect(functionType.returnType, isNotNull);
14334 expect(functionType.typeParameters, isNotNull);
14335 }
14336
14337 @failingTest
14338 void test_parseTypeAlias_genericFunction_typeParameters_noParameters() {
14339 createParser('typedef F<T> = bool Function();');
14340 GenericTypeAlias typeAlias = parseFullCompilationUnitMember();
14341 expectNotNullIfNoErrors(typeAlias);
14342 listener.assertNoErrors();
14343 expect(typeAlias.typedefKeyword, isNotNull);
14344 expect(typeAlias.name, isNotNull);
14345 expect(typeAlias.typeParameters, isNotNull);
14346 expect(typeAlias.semicolon, isNotNull);
14347 GenericFunctionType functionType = typeAlias.functionType;
14348 expect(functionType, isNotNull);
14349 expect(functionType.parameters, isNotNull);
14350 expect(functionType.returnType, isNotNull);
14351 expect(functionType.typeParameters, isNull);
14352 }
14353
14354 @failingTest
14355 void test_parseTypeAlias_genericFunction_typeParameters_noReturnType() {
14356 createParser('typedef F<T> = Function();');
14357 GenericTypeAlias typeAlias = parseFullCompilationUnitMember();
14358 expectNotNullIfNoErrors(typeAlias);
14359 listener.assertNoErrors();
14360 expect(typeAlias.typedefKeyword, isNotNull);
14361 expect(typeAlias.name, isNotNull);
14362 expect(typeAlias.typeParameters, isNotNull);
14363 expect(typeAlias.semicolon, isNotNull);
14364 GenericFunctionType functionType = typeAlias.functionType;
14365 expect(functionType, isNotNull);
14366 expect(functionType.parameters, isNotNull);
14367 expect(functionType.returnType, isNull);
14368 expect(functionType.typeParameters, isNull);
14369 }
14370
14371 @failingTest
14372 void
14373 test_parseTypeAlias_genericFunction_typeParameters_parameterizedReturnType () {
14374 createParser('typedef F<T> = A<B> Function();');
14375 GenericTypeAlias typeAlias = parseFullCompilationUnitMember();
14376 expectNotNullIfNoErrors(typeAlias);
14377 listener.assertNoErrors();
14378 expect(typeAlias.typedefKeyword, isNotNull);
14379 expect(typeAlias.name, isNotNull);
14380 expect(typeAlias.typeParameters, isNotNull);
14381 expect(typeAlias.semicolon, isNotNull);
14382 GenericFunctionType functionType = typeAlias.functionType;
14383 expect(functionType, isNotNull);
14384 expect(functionType.parameters, isNotNull);
14385 expect(functionType.returnType, isNotNull);
14386 expect(functionType.typeParameters, isNull);
14387 }
14388
14389 @failingTest
14390 void test_parseTypeAlias_genericFunction_typeParameters_parameters() {
14391 createParser('typedef F<T> = bool Function(Object value);');
14392 GenericTypeAlias typeAlias = parseFullCompilationUnitMember();
14393 expectNotNullIfNoErrors(typeAlias);
14394 listener.assertNoErrors();
14395 expect(typeAlias.typedefKeyword, isNotNull);
14396 expect(typeAlias.name, isNotNull);
14397 expect(typeAlias.typeParameters, isNotNull);
14398 expect(typeAlias.semicolon, isNotNull);
14399 GenericFunctionType functionType = typeAlias.functionType;
14400 expect(functionType, isNotNull);
14401 expect(functionType.parameters, isNotNull);
14402 expect(functionType.returnType, isNotNull);
14403 expect(functionType.typeParameters, isNull);
14404 }
14405
14406 @failingTest
14407 void test_parseTypeAlias_genericFunction_typeParameters_typeParameters() {
14408 createParser('typedef F<T> = bool Function<E>();');
14409 GenericTypeAlias typeAlias = parseFullCompilationUnitMember();
14410 expectNotNullIfNoErrors(typeAlias);
14411 listener.assertNoErrors();
14412 expect(typeAlias.typedefKeyword, isNotNull);
14413 expect(typeAlias.name, isNotNull);
14414 expect(typeAlias.typeParameters, isNotNull);
14415 expect(typeAlias.semicolon, isNotNull);
14416 GenericFunctionType functionType = typeAlias.functionType;
14417 expect(functionType, isNotNull);
14418 expect(functionType.parameters, isNotNull);
14419 expect(functionType.returnType, isNotNull);
14420 expect(functionType.typeParameters, isNotNull);
14421 }
14422
14423 @failingTest
14424 void test_parseTypeAlias_genericFunction_typeParameters_voidReturnType() {
14425 createParser('typedef F<T> = void Function();');
14426 GenericTypeAlias typeAlias = parseFullCompilationUnitMember();
14427 expectNotNullIfNoErrors(typeAlias);
14428 listener.assertNoErrors();
14429 expect(typeAlias.typedefKeyword, isNotNull);
14430 expect(typeAlias.name, isNotNull);
14431 expect(typeAlias.typeParameters, isNotNull);
14432 expect(typeAlias.semicolon, isNotNull);
14433 GenericFunctionType functionType = typeAlias.functionType;
14434 expect(functionType, isNotNull);
14435 expect(functionType.parameters, isNotNull);
14436 expect(functionType.returnType, isNotNull);
14437 expect(functionType.typeParameters, isNull);
14438 }
14439
14440 @failingTest
14441 void test_parseTypeAlias_genericFunction_voidReturnType() {
14442 createParser('typedef F = void Function();');
14443 GenericTypeAlias typeAlias = parseFullCompilationUnitMember();
14444 expectNotNullIfNoErrors(typeAlias);
14445 listener.assertNoErrors();
14446 expect(typeAlias.typedefKeyword, isNotNull);
14447 expect(typeAlias.name, isNotNull);
14448 expect(typeAlias.typeParameters, isNull);
14449 expect(typeAlias.semicolon, isNotNull);
14450 GenericFunctionType functionType = typeAlias.functionType;
14451 expect(functionType, isNotNull);
14452 expect(functionType.parameters, isNotNull);
14453 expect(functionType.returnType, isNotNull);
14454 expect(functionType.typeParameters, isNull);
14455 }
14439 14456
14440 /** 14457 /**
14441 * Parse the given source as a compilation unit. 14458 * Parse the given source as a compilation unit.
14442 * 14459 *
14443 * @param source the source to be parsed 14460 * @param source the source to be parsed
14444 * @param errorCodes the error codes of the errors that are expected to be fou nd 14461 * @param errorCodes the error codes of the errors that are expected to be fou nd
14445 * @return the compilation unit that was parsed 14462 * @return the compilation unit that was parsed
14446 * @throws Exception if the source could not be parsed, if the compilation err ors in the source do 14463 * @throws Exception if the source could not be parsed, if the compilation err ors in the source do
14447 * not match those that are expected, or if the result would have be en `null` 14464 * not match those that are expected, or if the result would have be en `null`
14448 */ 14465 */
14449 CompilationUnit _parseDirectives(String source, 14466 CompilationUnit _parseDirectives(String source,
14450 [List<ErrorCode> errorCodes = const <ErrorCode>[]]) { 14467 [List<ErrorCode> errorCodes = const <ErrorCode>[]]) {
14451 createParser(source); 14468 createParser(source);
14452 CompilationUnit unit = parser.parseDirectives2(); 14469 CompilationUnit unit = parser.parseDirectives2();
14453 expect(unit, isNotNull); 14470 expect(unit, isNotNull);
14454 expect(unit.declarations, hasLength(0)); 14471 expect(unit.declarations, hasLength(0));
14455 listener.assertErrorsWithCodes(errorCodes); 14472 listener.assertErrorsWithCodes(errorCodes);
14456 return unit; 14473 return unit;
14457 } 14474 }
14458 } 14475 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698