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

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

Issue 2747583003: Parse factory constructors with Fasta. (Closed)
Patch Set: Created 3 years, 9 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
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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 } 279 }
280 280
281 @reflectiveTest 281 @reflectiveTest
282 class ClassMemberParserTest extends ParserTestCase 282 class ClassMemberParserTest extends ParserTestCase
283 with ClassMemberParserTestMixin {} 283 with ClassMemberParserTestMixin {}
284 284
285 /** 285 /**
286 * Tests which exercise the parser using a class member. 286 * Tests which exercise the parser using a class member.
287 */ 287 */
288 abstract class ClassMemberParserTestMixin implements AbstractParserTestCase { 288 abstract class ClassMemberParserTestMixin implements AbstractParserTestCase {
289 void test_constFactory() {
290 createParser('const factory C() = A;');
291 ClassMember member = parser.parseClassMember('C');
292 expect(member, isNotNull);
293 assertNoErrors();
294 }
295
296 void test_parseAwaitExpression_asStatement_inAsync() { 289 void test_parseAwaitExpression_asStatement_inAsync() {
297 createParser('m() async { await x; }'); 290 createParser('m() async { await x; }');
298 ClassMember member = parser.parseClassMember('C'); 291 ClassMember member = parser.parseClassMember('C');
299 expect(member, isNotNull); 292 expect(member, isNotNull);
300 assertNoErrors(); 293 assertNoErrors();
301 expect(member, new isInstanceOf<MethodDeclaration>()); 294 expect(member, new isInstanceOf<MethodDeclaration>());
302 MethodDeclaration method = member; 295 MethodDeclaration method = member;
303 FunctionBody body = method.body; 296 FunctionBody body = method.body;
304 EngineTestCase.assertInstanceOf( 297 EngineTestCase.assertInstanceOf(
305 (obj) => obj is BlockFunctionBody, BlockFunctionBody, body); 298 (obj) => obj is BlockFunctionBody, BlockFunctionBody, body);
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 expect(method.propertyKeyword, isNull); 1007 expect(method.propertyKeyword, isNull);
1015 expect(method.returnType, isNotNull); 1008 expect(method.returnType, isNotNull);
1016 expect(method.name, isNotNull); 1009 expect(method.name, isNotNull);
1017 expect(method.operatorKeyword, isNotNull); 1010 expect(method.operatorKeyword, isNotNull);
1018 expect(method.typeParameters, isNull); 1011 expect(method.typeParameters, isNull);
1019 expect(method.parameters, isNotNull); 1012 expect(method.parameters, isNotNull);
1020 expect(method.body, isNotNull); 1013 expect(method.body, isNotNull);
1021 } 1014 }
1022 1015
1023 void test_parseClassMember_redirectingFactory_const() { 1016 void test_parseClassMember_redirectingFactory_const() {
1024 createParser('const factory C() = B;'); 1017 createParser('const factory C() = prefix.B.foo;');
1025 ClassMember member = parser.parseClassMember('C'); 1018 var constructor = parser.parseClassMember('C') as ConstructorDeclaration;
1026 expect(member, isNotNull);
1027 assertNoErrors(); 1019 assertNoErrors();
1028 expect(member, new isInstanceOf<ConstructorDeclaration>()); 1020 expect(constructor, isNotNull);
1029 ConstructorDeclaration constructor = member;
1030 expect(constructor.externalKeyword, isNull); 1021 expect(constructor.externalKeyword, isNull);
1031 expect(constructor.constKeyword, isNotNull); 1022 expect(constructor.constKeyword.keyword, Keyword.CONST);
1032 expect(constructor.factoryKeyword, isNotNull); 1023 expect(constructor.factoryKeyword.keyword, Keyword.FACTORY);
1033 expect(constructor.returnType, isNotNull); 1024 expect(constructor.returnType.name, 'C');
1034 expect(constructor.period, isNull); 1025 expect(constructor.period, isNull);
1035 expect(constructor.name, isNull); 1026 expect(constructor.name, isNull);
1036 expect(constructor.parameters, isNotNull); 1027 expect(constructor.parameters, isNotNull);
1037 expect(constructor.separator, isNotNull); 1028 expect(constructor.parameters.parameters, isEmpty);
1038 expect(constructor.initializers, hasLength(0)); 1029 expect(constructor.separator.type, TokenType.EQ);
1030 expect(constructor.initializers, isEmpty);
1039 expect(constructor.redirectedConstructor, isNotNull); 1031 expect(constructor.redirectedConstructor, isNotNull);
1040 expect(constructor.body, isNotNull); 1032 expect(constructor.redirectedConstructor.type.name.name, 'prefix.B');
1033 expect(constructor.redirectedConstructor.period.type, TokenType.PERIOD);
1034 expect(constructor.redirectedConstructor.name.name, 'foo');
1035 expect(constructor.body, new isInstanceOf<EmptyFunctionBody>());
1036 }
1037
1038 void test_parseClassMember_redirectingFactory_expressionBody() {
1039 createParser('factory C() => null;');
1040 var constructor = parser.parseClassMember('C') as ConstructorDeclaration;
1041 assertNoErrors();
1042 expect(constructor, isNotNull);
1043 expect(constructor.externalKeyword, isNull);
1044 expect(constructor.constKeyword, isNull);
1045 expect(constructor.factoryKeyword.keyword, Keyword.FACTORY);
1046 expect(constructor.returnType.name, 'C');
1047 expect(constructor.period, isNull);
1048 expect(constructor.name, isNull);
1049 expect(constructor.parameters, isNotNull);
1050 expect(constructor.parameters.parameters, isEmpty);
1051 expect(constructor.separator, isNull);
1052 expect(constructor.initializers, isEmpty);
1053 expect(constructor.redirectedConstructor, isNull);
1054
1055 var body = constructor.body as ExpressionFunctionBody;
1056 expect(body.keyword, isNull);
1057 expect(body.star, isNull);
1058 expect(body.functionDefinition.type, TokenType.FUNCTION);
1059 expect(body.expression, isNotNull);
1060 expect(body.semicolon, isNotNull);
1041 } 1061 }
1042 1062
1043 void test_parseClassMember_redirectingFactory_nonConst() { 1063 void test_parseClassMember_redirectingFactory_nonConst() {
1044 createParser('factory C() = B;'); 1064 createParser('factory C() = B;');
1045 ClassMember member = parser.parseClassMember('C'); 1065 ClassMember member = parser.parseClassMember('C');
1046 expect(member, isNotNull); 1066 expect(member, isNotNull);
1047 assertNoErrors(); 1067 assertNoErrors();
1048 expect(member, new isInstanceOf<ConstructorDeclaration>()); 1068 expect(member, new isInstanceOf<ConstructorDeclaration>());
1049 ConstructorDeclaration constructor = member; 1069 ConstructorDeclaration constructor = member;
1050 expect(constructor.externalKeyword, isNull); 1070 expect(constructor.externalKeyword, isNull);
1051 expect(constructor.constKeyword, isNull); 1071 expect(constructor.constKeyword, isNull);
1052 expect(constructor.factoryKeyword, isNotNull); 1072 expect(constructor.factoryKeyword.keyword, Keyword.FACTORY);
1053 expect(constructor.returnType, isNotNull); 1073 expect(constructor.returnType.name, 'C');
1054 expect(constructor.period, isNull); 1074 expect(constructor.period, isNull);
1055 expect(constructor.name, isNull); 1075 expect(constructor.name, isNull);
1056 expect(constructor.parameters, isNotNull); 1076 expect(constructor.parameters, isNotNull);
1057 expect(constructor.separator, isNotNull); 1077 expect(constructor.parameters.parameters, isEmpty);
1058 expect(constructor.initializers, hasLength(0)); 1078 expect(constructor.separator.type, TokenType.EQ);
1079 expect(constructor.initializers, isEmpty);
1059 expect(constructor.redirectedConstructor, isNotNull); 1080 expect(constructor.redirectedConstructor, isNotNull);
1060 expect(constructor.body, isNotNull); 1081 expect(constructor.redirectedConstructor.type.name.name, 'B');
1082 expect(constructor.redirectedConstructor.period, isNull);
1083 expect(constructor.redirectedConstructor.name, isNull);
1084 expect(constructor.body, new isInstanceOf<EmptyFunctionBody>());
1061 } 1085 }
1062 1086
1063 void test_parseConstructor_assert() { 1087 void test_parseConstructor_assert() {
1064 enableAssertInitializer = true; 1088 enableAssertInitializer = true;
1065 createParser('C(x, y) : _x = x, assert (x < y), _y = y;'); 1089 createParser('C(x, y) : _x = x, assert (x < y), _y = y;');
1066 ClassMember member = parser.parseClassMember('C'); 1090 ClassMember member = parser.parseClassMember('C');
1067 expect(member, isNotNull); 1091 expect(member, isNotNull);
1068 assertNoErrors(); 1092 assertNoErrors();
1069 expect(member, new isInstanceOf<ConstructorDeclaration>()); 1093 expect(member, new isInstanceOf<ConstructorDeclaration>());
1070 ConstructorDeclaration constructor = member as ConstructorDeclaration; 1094 ConstructorDeclaration constructor = member as ConstructorDeclaration;
(...skipping 13661 matching lines...) Expand 10 before | Expand all | Expand 10 after
14732 expect(functionType.returnType, isNotNull); 14756 expect(functionType.returnType, isNotNull);
14733 expect(functionType.typeParameters, isNull); 14757 expect(functionType.typeParameters, isNull);
14734 } 14758 }
14735 14759
14736 void test_parseTypeAlias_genericFunction_withDocComment() { 14760 void test_parseTypeAlias_genericFunction_withDocComment() {
14737 createParser('/// Doc\ntypedef F = bool Function();'); 14761 createParser('/// Doc\ntypedef F = bool Function();');
14738 var typeAlias = parseFullCompilationUnitMember() as GenericTypeAlias; 14762 var typeAlias = parseFullCompilationUnitMember() as GenericTypeAlias;
14739 expectCommentText(typeAlias.documentationComment, '/// Doc'); 14763 expectCommentText(typeAlias.documentationComment, '/// Doc');
14740 } 14764 }
14741 } 14765 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/parser_fasta_test.dart ('k') | pkg/compiler/lib/src/parser/member_listener.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698