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

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

Issue 2684833004: Eliminate commentAndMetadata() from parser tests. (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 2979 matching lines...) Expand 10 before | Expand all | Expand 10 after
2990 GatheringErrorListener listener; 2990 GatheringErrorListener listener;
2991 2991
2992 /** 2992 /**
2993 * The parser used by the test. 2993 * The parser used by the test.
2994 * 2994 *
2995 * This field is typically initialized by invoking [createParser]. 2995 * This field is typically initialized by invoking [createParser].
2996 */ 2996 */
2997 Parser parser; 2997 Parser parser;
2998 2998
2999 /** 2999 /**
3000 * Return a CommentAndMetadata object with the given values that can be used f or testing.
3001 *
3002 * @param comment the comment to be wrapped in the object
3003 * @param annotations the annotations to be wrapped in the object
3004 * @return a CommentAndMetadata object that can be used for testing
3005 */
3006 CommentAndMetadata commentAndMetadata(Comment comment,
3007 [List<Annotation> annotations]) {
3008 return new CommentAndMetadata(comment, annotations);
3009 }
3010
3011 /**
3012 * Create the [parser] and [listener] used by a test. The [parser] will be 3000 * Create the [parser] and [listener] used by a test. The [parser] will be
3013 * prepared to parse the tokens scanned from the given [content]. 3001 * prepared to parse the tokens scanned from the given [content].
3014 */ 3002 */
3015 void createParser(String content) { 3003 void createParser(String content) {
3016 listener = new GatheringErrorListener(); 3004 listener = new GatheringErrorListener();
3017 // 3005 //
3018 // Scan the source. 3006 // Scan the source.
3019 // 3007 //
3020 TestSource source = new TestSource(); 3008 TestSource source = new TestSource();
3021 CharacterReader reader = new CharSequenceReader(content); 3009 CharacterReader reader = new CharSequenceReader(content);
(...skipping 6912 matching lines...) Expand 10 before | Expand all | Expand 10 after
9934 void test_parseFunctionBody_skip_expression() { 9922 void test_parseFunctionBody_skip_expression() {
9935 ParserTestCase.parseFunctionBodies = false; 9923 ParserTestCase.parseFunctionBodies = false;
9936 createParser('=> y;'); 9924 createParser('=> y;');
9937 FunctionBody functionBody = parser.parseFunctionBody(false, null, false); 9925 FunctionBody functionBody = parser.parseFunctionBody(false, null, false);
9938 expectNotNullIfNoErrors(functionBody); 9926 expectNotNullIfNoErrors(functionBody);
9939 listener.assertNoErrors(); 9927 listener.assertNoErrors();
9940 expect(functionBody, new isInstanceOf<EmptyFunctionBody>()); 9928 expect(functionBody, new isInstanceOf<EmptyFunctionBody>());
9941 } 9929 }
9942 9930
9943 void test_parseFunctionDeclaration_function() { 9931 void test_parseFunctionDeclaration_function() {
9944 Comment comment = astFactory.documentationComment(new List<Token>(0)); 9932 createParser('/// Doc\nT f() {}');
9945 TypeName returnType = 9933 FunctionDeclaration declaration = parseFullCompilationUnitMember();
9946 astFactory.typeName(astFactory.simpleIdentifier(null), null);
9947 createParser('f() {}');
9948 FunctionDeclaration declaration = parser.parseFunctionDeclaration(
9949 commentAndMetadata(comment), null, returnType);
9950 expectNotNullIfNoErrors(declaration); 9934 expectNotNullIfNoErrors(declaration);
9951 listener.assertNoErrors(); 9935 listener.assertNoErrors();
9952 expect(declaration.documentationComment, comment); 9936 _expectCommentText(declaration.documentationComment, '/// Doc');
9953 expect(declaration.returnType, returnType); 9937 expect((declaration.returnType as TypeName).name.name, 'T');
9954 expect(declaration.name, isNotNull); 9938 expect(declaration.name, isNotNull);
9955 FunctionExpression expression = declaration.functionExpression; 9939 FunctionExpression expression = declaration.functionExpression;
9956 expect(expression, isNotNull); 9940 expect(expression, isNotNull);
9957 expect(expression.body, isNotNull); 9941 expect(expression.body, isNotNull);
9958 expect(expression.typeParameters, isNull); 9942 expect(expression.typeParameters, isNull);
9959 expect(expression.parameters, isNotNull); 9943 expect(expression.parameters, isNotNull);
9960 expect(declaration.propertyKeyword, isNull); 9944 expect(declaration.propertyKeyword, isNull);
9961 } 9945 }
9962 9946
9963 void test_parseFunctionDeclaration_functionWithTypeParameters() { 9947 void test_parseFunctionDeclaration_functionWithTypeParameters() {
9964 Comment comment = astFactory.documentationComment(new List<Token>(0)); 9948 createParser('/// Doc\nT f<E>() {}');
9965 TypeName returnType = 9949 FunctionDeclaration declaration = parseFullCompilationUnitMember();
9966 astFactory.typeName(astFactory.simpleIdentifier(null), null);
9967 createParser('f<E>() {}');
9968 FunctionDeclaration declaration = parser.parseFunctionDeclaration(
9969 commentAndMetadata(comment), null, returnType);
9970 expectNotNullIfNoErrors(declaration); 9950 expectNotNullIfNoErrors(declaration);
9971 listener.assertNoErrors(); 9951 listener.assertNoErrors();
9972 expect(declaration.documentationComment, comment); 9952 _expectCommentText(declaration.documentationComment, '/// Doc');
9973 expect(declaration.returnType, returnType); 9953 expect((declaration.returnType as TypeName).name.name, 'T');
9974 expect(declaration.name, isNotNull); 9954 expect(declaration.name, isNotNull);
9975 FunctionExpression expression = declaration.functionExpression; 9955 FunctionExpression expression = declaration.functionExpression;
9976 expect(expression, isNotNull); 9956 expect(expression, isNotNull);
9977 expect(expression.body, isNotNull); 9957 expect(expression.body, isNotNull);
9978 expect(expression.typeParameters, isNotNull); 9958 expect(expression.typeParameters, isNotNull);
9979 expect(expression.parameters, isNotNull); 9959 expect(expression.parameters, isNotNull);
9980 expect(declaration.propertyKeyword, isNull); 9960 expect(declaration.propertyKeyword, isNull);
9981 } 9961 }
9982 9962
9983 void test_parseFunctionDeclaration_functionWithTypeParameters_comment() { 9963 void test_parseFunctionDeclaration_functionWithTypeParameters_comment() {
9984 enableGenericMethodComments = true; 9964 enableGenericMethodComments = true;
9985 Comment comment = astFactory.documentationComment(new List<Token>(0)); 9965 createParser('/// Doc\nT f/*<E>*/() {}');
9986 TypeName returnType = 9966 FunctionDeclaration declaration = parseFullCompilationUnitMember();
9987 astFactory.typeName(astFactory.simpleIdentifier(null), null);
9988 createParser('f/*<E>*/() {}');
9989 FunctionDeclaration declaration = parser.parseFunctionDeclaration(
9990 commentAndMetadata(comment), null, returnType);
9991 expectNotNullIfNoErrors(declaration); 9967 expectNotNullIfNoErrors(declaration);
9992 listener.assertNoErrors(); 9968 listener.assertNoErrors();
9993 expect(declaration.documentationComment, comment); 9969 _expectCommentText(declaration.documentationComment, '/// Doc');
9994 expect(declaration.returnType, returnType); 9970 expect((declaration.returnType as TypeName).name.name, 'T');
9995 expect(declaration.name, isNotNull); 9971 expect(declaration.name, isNotNull);
9996 FunctionExpression expression = declaration.functionExpression; 9972 FunctionExpression expression = declaration.functionExpression;
9997 expect(expression, isNotNull); 9973 expect(expression, isNotNull);
9998 expect(expression.body, isNotNull); 9974 expect(expression.body, isNotNull);
9999 expect(expression.typeParameters, isNotNull); 9975 expect(expression.typeParameters, isNotNull);
10000 expect(expression.parameters, isNotNull); 9976 expect(expression.parameters, isNotNull);
10001 expect(declaration.propertyKeyword, isNull); 9977 expect(declaration.propertyKeyword, isNull);
10002 } 9978 }
10003 9979
10004 void test_parseFunctionDeclaration_getter() { 9980 void test_parseFunctionDeclaration_getter() {
10005 Comment comment = astFactory.documentationComment(new List<Token>(0)); 9981 createParser('/// Doc\nT get p => 0;');
10006 TypeName returnType = 9982 FunctionDeclaration declaration = parseFullCompilationUnitMember();
10007 astFactory.typeName(astFactory.simpleIdentifier(null), null);
10008 createParser('get p => 0;');
10009 FunctionDeclaration declaration = parser.parseFunctionDeclaration(
10010 commentAndMetadata(comment), null, returnType);
10011 expectNotNullIfNoErrors(declaration); 9983 expectNotNullIfNoErrors(declaration);
10012 listener.assertNoErrors(); 9984 listener.assertNoErrors();
10013 expect(declaration.documentationComment, comment); 9985 _expectCommentText(declaration.documentationComment, '/// Doc');
10014 expect(declaration.returnType, returnType); 9986 expect((declaration.returnType as TypeName).name.name, 'T');
10015 expect(declaration.name, isNotNull); 9987 expect(declaration.name, isNotNull);
10016 FunctionExpression expression = declaration.functionExpression; 9988 FunctionExpression expression = declaration.functionExpression;
10017 expect(expression, isNotNull); 9989 expect(expression, isNotNull);
10018 expect(expression.body, isNotNull); 9990 expect(expression.body, isNotNull);
10019 expect(expression.typeParameters, isNull); 9991 expect(expression.typeParameters, isNull);
10020 expect(expression.parameters, isNull); 9992 expect(expression.parameters, isNull);
10021 expect(declaration.propertyKeyword, isNotNull); 9993 expect(declaration.propertyKeyword, isNotNull);
10022 } 9994 }
10023 9995
10024 void test_parseFunctionDeclaration_setter() { 9996 void test_parseFunctionDeclaration_setter() {
10025 Comment comment = astFactory.documentationComment(new List<Token>(0)); 9997 createParser('/// Doc\nT set p(v) {}');
10026 TypeName returnType = 9998 FunctionDeclaration declaration = parseFullCompilationUnitMember();
10027 astFactory.typeName(astFactory.simpleIdentifier(null), null);
10028 createParser('set p(v) {}');
10029 FunctionDeclaration declaration = parser.parseFunctionDeclaration(
10030 commentAndMetadata(comment), null, returnType);
10031 expectNotNullIfNoErrors(declaration); 9999 expectNotNullIfNoErrors(declaration);
10032 listener.assertNoErrors(); 10000 listener.assertNoErrors();
10033 expect(declaration.documentationComment, comment); 10001 _expectCommentText(declaration.documentationComment, '/// Doc');
10034 expect(declaration.returnType, returnType); 10002 expect((declaration.returnType as TypeName).name.name, 'T');
10035 expect(declaration.name, isNotNull); 10003 expect(declaration.name, isNotNull);
10036 FunctionExpression expression = declaration.functionExpression; 10004 FunctionExpression expression = declaration.functionExpression;
10037 expect(expression, isNotNull); 10005 expect(expression, isNotNull);
10038 expect(expression.body, isNotNull); 10006 expect(expression.body, isNotNull);
10039 expect(expression.typeParameters, isNull); 10007 expect(expression.typeParameters, isNull);
10040 expect(expression.parameters, isNotNull); 10008 expect(expression.parameters, isNotNull);
10041 expect(declaration.propertyKeyword, isNotNull); 10009 expect(declaration.propertyKeyword, isNotNull);
10042 } 10010 }
10043 10011
10044 void test_parseFunctionDeclarationStatement() { 10012 void test_parseFunctionDeclarationStatement() {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
10145 listener.assertNoErrors(); 10113 listener.assertNoErrors();
10146 expect(alias.name, isNotNull); 10114 expect(alias.name, isNotNull);
10147 expect(alias.name.name, 'F'); 10115 expect(alias.name.name, 'F');
10148 expect(alias.typeParameters, isNotNull); 10116 expect(alias.typeParameters, isNotNull);
10149 expect(alias.equals, isNotNull); 10117 expect(alias.equals, isNotNull);
10150 expect(alias.functionType, isNotNull); 10118 expect(alias.functionType, isNotNull);
10151 expect(alias.semicolon, isNotNull); 10119 expect(alias.semicolon, isNotNull);
10152 } 10120 }
10153 10121
10154 void test_parseGetter_nonStatic() { 10122 void test_parseGetter_nonStatic() {
10155 Comment comment = astFactory.documentationComment(new List<Token>(0)); 10123 createParser('/// Doc\nT get a;');
10156 TypeName returnType = 10124 MethodDeclaration method = parser.parseClassMember('C');
10157 astFactory.typeName(astFactory.simpleIdentifier(null), null);
10158 createParser('get a;');
10159 MethodDeclaration method =
10160 parser.parseGetter(commentAndMetadata(comment), null, null, returnType);
10161 expectNotNullIfNoErrors(method); 10125 expectNotNullIfNoErrors(method);
10162 listener.assertNoErrors(); 10126 listener.assertNoErrors();
10163 expect(method.body, isNotNull); 10127 expect(method.body, isNotNull);
10164 expect(method.documentationComment, comment); 10128 _expectCommentText(method.documentationComment, '/// Doc');
10165 expect(method.externalKeyword, isNull); 10129 expect(method.externalKeyword, isNull);
10166 expect(method.modifierKeyword, isNull); 10130 expect(method.modifierKeyword, isNull);
10167 expect(method.name, isNotNull); 10131 expect(method.name, isNotNull);
10168 expect(method.operatorKeyword, isNull); 10132 expect(method.operatorKeyword, isNull);
10169 expect(method.parameters, isNull); 10133 expect(method.parameters, isNull);
10170 expect(method.propertyKeyword, isNotNull); 10134 expect(method.propertyKeyword, isNotNull);
10171 expect(method.returnType, returnType); 10135 expect((method.returnType as TypeName).name.name, 'T');
10172 } 10136 }
10173 10137
10174 void test_parseGetter_static() { 10138 void test_parseGetter_static() {
10175 Comment comment = astFactory.documentationComment(new List<Token>(0)); 10139 createParser('/// Doc\nstatic T get a => 42;');
10176 Token staticKeyword = TokenFactory.tokenFromKeyword(Keyword.STATIC); 10140 MethodDeclaration method = parser.parseClassMember('C');
10177 TypeName returnType =
10178 astFactory.typeName(astFactory.simpleIdentifier(null), null);
10179 createParser('get a => 42;');
10180 MethodDeclaration method = parser.parseGetter(
10181 commentAndMetadata(comment), null, staticKeyword, returnType);
10182 expectNotNullIfNoErrors(method); 10141 expectNotNullIfNoErrors(method);
10183 listener.assertNoErrors(); 10142 listener.assertNoErrors();
10184 expect(method.body, isNotNull); 10143 expect(method.body, isNotNull);
10185 expect(method.documentationComment, comment); 10144 _expectCommentText(method.documentationComment, '/// Doc');
10186 expect(method.externalKeyword, isNull); 10145 expect(method.externalKeyword, isNull);
10187 expect(method.modifierKeyword, staticKeyword); 10146 expect(method.modifierKeyword.lexeme, 'static');
10188 expect(method.name, isNotNull); 10147 expect(method.name, isNotNull);
10189 expect(method.operatorKeyword, isNull); 10148 expect(method.operatorKeyword, isNull);
10190 expect(method.typeParameters, isNull); 10149 expect(method.typeParameters, isNull);
10191 expect(method.parameters, isNull); 10150 expect(method.parameters, isNull);
10192 expect(method.propertyKeyword, isNotNull); 10151 expect(method.propertyKeyword, isNotNull);
10193 expect(method.returnType, returnType); 10152 expect((method.returnType as TypeName).name.name, 'T');
10194 } 10153 }
10195 10154
10196 void test_parseIdentifierList_multiple() { 10155 void test_parseIdentifierList_multiple() {
10197 createParser('a, b, c'); 10156 createParser('a, b, c');
10198 List<SimpleIdentifier> list = parser.parseIdentifierList(); 10157 List<SimpleIdentifier> list = parser.parseIdentifierList();
10199 expectNotNullIfNoErrors(list); 10158 expectNotNullIfNoErrors(list);
10200 listener.assertNoErrors(); 10159 listener.assertNoErrors();
10201 expect(list, hasLength(3)); 10160 expect(list, hasLength(3));
10202 } 10161 }
10203 10162
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
10408 expect(directive.keyword, isNotNull); 10367 expect(directive.keyword, isNotNull);
10409 expect(directive.uri, isNotNull); 10368 expect(directive.uri, isNotNull);
10410 expect(directive.deferredKeyword, isNull); 10369 expect(directive.deferredKeyword, isNull);
10411 expect(directive.asKeyword, isNull); 10370 expect(directive.asKeyword, isNull);
10412 expect(directive.prefix, isNull); 10371 expect(directive.prefix, isNull);
10413 expect(directive.combinators, hasLength(1)); 10372 expect(directive.combinators, hasLength(1));
10414 expect(directive.semicolon, isNotNull); 10373 expect(directive.semicolon, isNotNull);
10415 } 10374 }
10416 10375
10417 void test_parseInitializedIdentifierList_type() { 10376 void test_parseInitializedIdentifierList_type() {
10418 Comment comment = astFactory.documentationComment(new List<Token>(0)); 10377 createParser("/// Doc\nstatic T a = 1, b, c = 3;");
10419 Token staticKeyword = TokenFactory.tokenFromKeyword(Keyword.STATIC); 10378 FieldDeclaration declaration = parser.parseClassMember('C');
10420 TypeName type =
10421 astFactory.typeName(astFactory.simpleIdentifier(null), null);
10422 createParser("a = 1, b, c = 3;");
10423 FieldDeclaration declaration = parser.parseInitializedIdentifierList(
10424 commentAndMetadata(comment), staticKeyword, null, null, type);
10425 expectNotNullIfNoErrors(declaration); 10379 expectNotNullIfNoErrors(declaration);
10426 listener.assertNoErrors(); 10380 listener.assertNoErrors();
10427 expect(declaration.documentationComment, comment); 10381 _expectCommentText(declaration.documentationComment, '/// Doc');
10428 VariableDeclarationList fields = declaration.fields; 10382 VariableDeclarationList fields = declaration.fields;
10429 expect(fields, isNotNull); 10383 expect(fields, isNotNull);
10430 expect(fields.keyword, isNull); 10384 expect(fields.keyword, isNull);
10431 expect(fields.type, type); 10385 expect((fields.type as TypeName).name.name, 'T');
10432 expect(fields.variables, hasLength(3)); 10386 expect(fields.variables, hasLength(3));
10433 expect(declaration.staticKeyword, staticKeyword); 10387 expect(declaration.staticKeyword.lexeme, 'static');
10434 expect(declaration.semicolon, isNotNull); 10388 expect(declaration.semicolon, isNotNull);
10435 } 10389 }
10436 10390
10437 void test_parseInitializedIdentifierList_var() { 10391 void test_parseInitializedIdentifierList_var() {
10438 Comment comment = astFactory.documentationComment(new List<Token>(0)); 10392 createParser('/// Doc\nstatic var a = 1, b, c = 3;');
10439 Token staticKeyword = TokenFactory.tokenFromKeyword(Keyword.STATIC); 10393 FieldDeclaration declaration = parser.parseClassMember('C');
10440 Token varKeyword = TokenFactory.tokenFromKeyword(Keyword.VAR);
10441 createParser('a = 1, b, c = 3;');
10442 FieldDeclaration declaration = parser.parseInitializedIdentifierList(
10443 commentAndMetadata(comment), staticKeyword, null, varKeyword, null);
10444 expectNotNullIfNoErrors(declaration); 10394 expectNotNullIfNoErrors(declaration);
10445 listener.assertNoErrors(); 10395 listener.assertNoErrors();
10446 expect(declaration.documentationComment, comment); 10396 _expectCommentText(declaration.documentationComment, '/// Doc');
10447 VariableDeclarationList fields = declaration.fields; 10397 VariableDeclarationList fields = declaration.fields;
10448 expect(fields, isNotNull); 10398 expect(fields, isNotNull);
10449 expect(fields.keyword, varKeyword); 10399 expect(fields.keyword.lexeme, 'var');
10450 expect(fields.type, isNull); 10400 expect(fields.type, isNull);
10451 expect(fields.variables, hasLength(3)); 10401 expect(fields.variables, hasLength(3));
10452 expect(declaration.staticKeyword, staticKeyword); 10402 expect(declaration.staticKeyword.lexeme, 'static');
10453 expect(declaration.semicolon, isNotNull); 10403 expect(declaration.semicolon, isNotNull);
10454 } 10404 }
10455 10405
10456 void test_parseInstanceCreationExpression_qualifiedType() { 10406 void test_parseInstanceCreationExpression_qualifiedType() {
10457 Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); 10407 Token token = TokenFactory.tokenFromKeyword(Keyword.NEW);
10458 createParser('A.B()'); 10408 createParser('A.B()');
10459 InstanceCreationExpression expression = 10409 InstanceCreationExpression expression =
10460 parser.parseInstanceCreationExpression(token); 10410 parser.parseInstanceCreationExpression(token);
10461 expectNotNullIfNoErrors(expression); 10411 expectNotNullIfNoErrors(expression);
10462 listener.assertNoErrors(); 10412 listener.assertNoErrors();
(...skipping 1190 matching lines...) Expand 10 before | Expand all | Expand 10 after
11653 expectNotNullIfNoErrors(parameter); 11603 expectNotNullIfNoErrors(parameter);
11654 listener.assertNoErrors(); 11604 listener.assertNoErrors();
11655 expect(parameter, new isInstanceOf<SimpleFormalParameter>()); 11605 expect(parameter, new isInstanceOf<SimpleFormalParameter>());
11656 SimpleFormalParameter simpleParameter = parameter; 11606 SimpleFormalParameter simpleParameter = parameter;
11657 expect(simpleParameter.keyword, isNull); 11607 expect(simpleParameter.keyword, isNull);
11658 expect(simpleParameter.type, isNotNull); 11608 expect(simpleParameter.type, isNotNull);
11659 expect(simpleParameter.identifier, isNotNull); 11609 expect(simpleParameter.identifier, isNotNull);
11660 } 11610 }
11661 11611
11662 void test_parseOperator() { 11612 void test_parseOperator() {
11663 Comment comment = astFactory.documentationComment(new List<Token>(0)); 11613 createParser('/// Doc\nT operator +(A a);');
11664 TypeName returnType = 11614 MethodDeclaration method = parser.parseClassMember('C');
11665 astFactory.typeName(astFactory.simpleIdentifier(null), null);
11666 createParser('operator +(A a);');
11667 MethodDeclaration method =
11668 parser.parseOperator(commentAndMetadata(comment), null, returnType);
11669 expectNotNullIfNoErrors(method); 11615 expectNotNullIfNoErrors(method);
11670 listener.assertNoErrors(); 11616 listener.assertNoErrors();
11671 expect(method.body, isNotNull); 11617 expect(method.body, isNotNull);
11672 expect(method.documentationComment, comment); 11618 _expectCommentText(method.documentationComment, '/// Doc');
11673 expect(method.externalKeyword, isNull); 11619 expect(method.externalKeyword, isNull);
11674 expect(method.modifierKeyword, isNull); 11620 expect(method.modifierKeyword, isNull);
11675 expect(method.name, isNotNull); 11621 expect(method.name, isNotNull);
11676 expect(method.operatorKeyword, isNotNull); 11622 expect(method.operatorKeyword, isNotNull);
11677 expect(method.typeParameters, isNull); 11623 expect(method.typeParameters, isNull);
11678 expect(method.parameters, isNotNull); 11624 expect(method.parameters, isNotNull);
11679 expect(method.propertyKeyword, isNull); 11625 expect(method.propertyKeyword, isNull);
11680 expect(method.returnType, returnType); 11626 expect((method.returnType as TypeName).name.name, 'T');
11681 } 11627 }
11682 11628
11683 void test_parseOptionalReturnType() { 11629 void test_parseOptionalReturnType() {
11684 // TODO(brianwilkerson) Implement tests for this method. 11630 // TODO(brianwilkerson) Implement tests for this method.
11685 } 11631 }
11686 11632
11687 void test_parsePartDirective() { 11633 void test_parsePartDirective() {
11688 createParser("part 'lib/lib.dart';"); 11634 createParser("part 'lib/lib.dart';");
11689 PartDirective directive = parseFullDirective(); 11635 PartDirective directive = parseFullDirective();
11690 expectNotNullIfNoErrors(directive); 11636 expectNotNullIfNoErrors(directive);
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
12370 void test_parseReturnType_void() { 12316 void test_parseReturnType_void() {
12371 createParser('void'); 12317 createParser('void');
12372 TypeName typeName = parser.parseReturnType(false); 12318 TypeName typeName = parser.parseReturnType(false);
12373 expectNotNullIfNoErrors(typeName); 12319 expectNotNullIfNoErrors(typeName);
12374 listener.assertNoErrors(); 12320 listener.assertNoErrors();
12375 expect(typeName.name, isNotNull); 12321 expect(typeName.name, isNotNull);
12376 expect(typeName.typeArguments, isNull); 12322 expect(typeName.typeArguments, isNull);
12377 } 12323 }
12378 12324
12379 void test_parseSetter_nonStatic() { 12325 void test_parseSetter_nonStatic() {
12380 Comment comment = astFactory.documentationComment(new List<Token>(0)); 12326 createParser('/// Doc\nT set a(var x);');
12381 TypeName returnType = 12327 MethodDeclaration method = parser.parseClassMember('C');
12382 astFactory.typeName(astFactory.simpleIdentifier(null), null);
12383 createParser('set a(var x);');
12384 MethodDeclaration method =
12385 parser.parseSetter(commentAndMetadata(comment), null, null, returnType);
12386 expectNotNullIfNoErrors(method); 12328 expectNotNullIfNoErrors(method);
12387 listener.assertNoErrors(); 12329 listener.assertNoErrors();
12388 expect(method.body, isNotNull); 12330 expect(method.body, isNotNull);
12389 expect(method.documentationComment, comment); 12331 _expectCommentText(method.documentationComment, '/// Doc');
12390 expect(method.externalKeyword, isNull); 12332 expect(method.externalKeyword, isNull);
12391 expect(method.modifierKeyword, isNull); 12333 expect(method.modifierKeyword, isNull);
12392 expect(method.name, isNotNull); 12334 expect(method.name, isNotNull);
12393 expect(method.operatorKeyword, isNull); 12335 expect(method.operatorKeyword, isNull);
12394 expect(method.typeParameters, isNull); 12336 expect(method.typeParameters, isNull);
12395 expect(method.parameters, isNotNull); 12337 expect(method.parameters, isNotNull);
12396 expect(method.propertyKeyword, isNotNull); 12338 expect(method.propertyKeyword, isNotNull);
12397 expect(method.returnType, returnType); 12339 expect((method.returnType as TypeName).name.name, 'T');
12398 } 12340 }
12399 12341
12400 void test_parseSetter_static() { 12342 void test_parseSetter_static() {
12401 Comment comment = astFactory.documentationComment(new List<Token>(0)); 12343 createParser('/// Doc\nstatic T set a(var x) {}');
12402 Token staticKeyword = TokenFactory.tokenFromKeyword(Keyword.STATIC); 12344 MethodDeclaration method = parser.parseClassMember('C');
12403 TypeName returnType =
12404 astFactory.typeName(astFactory.simpleIdentifier(null), null);
12405 createParser('set a(var x) {}');
12406 MethodDeclaration method = parser.parseSetter(
12407 commentAndMetadata(comment), null, staticKeyword, returnType);
12408 expectNotNullIfNoErrors(method); 12345 expectNotNullIfNoErrors(method);
12409 listener.assertNoErrors(); 12346 listener.assertNoErrors();
12410 expect(method.body, isNotNull); 12347 expect(method.body, isNotNull);
12411 expect(method.documentationComment, comment); 12348 _expectCommentText(method.documentationComment, '/// Doc');
12412 expect(method.externalKeyword, isNull); 12349 expect(method.externalKeyword, isNull);
12413 expect(method.modifierKeyword, staticKeyword); 12350 expect(method.modifierKeyword.lexeme, 'static');
12414 expect(method.name, isNotNull); 12351 expect(method.name, isNotNull);
12415 expect(method.operatorKeyword, isNull); 12352 expect(method.operatorKeyword, isNull);
12416 expect(method.typeParameters, isNull); 12353 expect(method.typeParameters, isNull);
12417 expect(method.parameters, isNotNull); 12354 expect(method.parameters, isNotNull);
12418 expect(method.propertyKeyword, isNotNull); 12355 expect(method.propertyKeyword, isNotNull);
12419 expect(method.returnType, returnType); 12356 expect((method.returnType as TypeName).name.name, 'T');
12420 } 12357 }
12421 12358
12422 void test_parseShiftExpression_normal() { 12359 void test_parseShiftExpression_normal() {
12423 createParser('x << y'); 12360 createParser('x << y');
12424 BinaryExpression expression = parser.parseShiftExpression(); 12361 BinaryExpression expression = parser.parseShiftExpression();
12425 expectNotNullIfNoErrors(expression); 12362 expectNotNullIfNoErrors(expression);
12426 listener.assertNoErrors(); 12363 listener.assertNoErrors();
12427 expect(expression.leftOperand, isNotNull); 12364 expect(expression.leftOperand, isNotNull);
12428 expect(expression.operator, isNotNull); 12365 expect(expression.operator, isNotNull);
12429 expect(expression.operator.type, TokenType.LT_LT); 12366 expect(expression.operator.type, TokenType.LT_LT);
(...skipping 1989 matching lines...) Expand 10 before | Expand all | Expand 10 after
14419 * @return the result of invoking the method 14356 * @return the result of invoking the method
14420 * @throws Exception if the method could not be invoked or throws an exception 14357 * @throws Exception if the method could not be invoked or throws an exception
14421 */ 14358 */
14422 String _computeStringValue(String lexeme, bool first, bool last) { 14359 String _computeStringValue(String lexeme, bool first, bool last) {
14423 createParser(''); 14360 createParser('');
14424 String value = parser.computeStringValue(lexeme, first, last); 14361 String value = parser.computeStringValue(lexeme, first, last);
14425 listener.assertNoErrors(); 14362 listener.assertNoErrors();
14426 return value; 14363 return value;
14427 } 14364 }
14428 14365
14366 void _expectCommentText(Comment comment, String expectedText) {
14367 expect(comment.beginToken, same(comment.endToken));
14368 expect(comment.beginToken.lexeme, expectedText);
14369 }
14370
14429 void _expectDottedName(DottedName name, List<String> expectedComponents) { 14371 void _expectDottedName(DottedName name, List<String> expectedComponents) {
14430 int count = expectedComponents.length; 14372 int count = expectedComponents.length;
14431 NodeList<SimpleIdentifier> components = name.components; 14373 NodeList<SimpleIdentifier> components = name.components;
14432 expect(components, hasLength(count)); 14374 expect(components, hasLength(count));
14433 for (int i = 0; i < count; i++) { 14375 for (int i = 0; i < count; i++) {
14434 SimpleIdentifier component = components[i]; 14376 SimpleIdentifier component = components[i];
14435 expect(component, isNotNull); 14377 expect(component, isNotNull);
14436 expect(component.name, expectedComponents[i]); 14378 expect(component.name, expectedComponents[i]);
14437 } 14379 }
14438 } 14380 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
14507 CompilationUnit _parseDirectives(String source, 14449 CompilationUnit _parseDirectives(String source,
14508 [List<ErrorCode> errorCodes = const <ErrorCode>[]]) { 14450 [List<ErrorCode> errorCodes = const <ErrorCode>[]]) {
14509 createParser(source); 14451 createParser(source);
14510 CompilationUnit unit = parser.parseDirectives2(); 14452 CompilationUnit unit = parser.parseDirectives2();
14511 expect(unit, isNotNull); 14453 expect(unit, isNotNull);
14512 expect(unit.declarations, hasLength(0)); 14454 expect(unit.declarations, hasLength(0));
14513 listener.assertErrorsWithCodes(errorCodes); 14455 listener.assertErrorsWithCodes(errorCodes);
14514 return unit; 14456 return unit;
14515 } 14457 }
14516 } 14458 }
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