OLD | NEW |
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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 [List<ErrorCode> errorCodes = const <ErrorCode>[]]); | 100 [List<ErrorCode> errorCodes = const <ErrorCode>[]]); |
101 | 101 |
102 /// TODO(paulberry): merge with [parseCompilationUnit] | 102 /// TODO(paulberry): merge with [parseCompilationUnit] |
103 CompilationUnit parseCompilationUnitWithOptions(String source, | 103 CompilationUnit parseCompilationUnitWithOptions(String source, |
104 [List<ErrorCode> errorCodes = const <ErrorCode>[]]); | 104 [List<ErrorCode> errorCodes = const <ErrorCode>[]]); |
105 | 105 |
106 ConditionalExpression parseConditionalExpression(String code); | 106 ConditionalExpression parseConditionalExpression(String code); |
107 | 107 |
108 Expression parseConstExpression(String code); | 108 Expression parseConstExpression(String code); |
109 | 109 |
| 110 ConstructorInitializer parseConstructorInitializer(String code); |
| 111 |
110 /** | 112 /** |
111 * Parse the given source as a compilation unit. | 113 * Parse the given source as a compilation unit. |
112 * | 114 * |
113 * @param source the source to be parsed | 115 * @param source the source to be parsed |
114 * @param errorCodes the error codes of the errors that are expected to be fou
nd | 116 * @param errorCodes the error codes of the errors that are expected to be fou
nd |
115 * @return the compilation unit that was parsed | 117 * @return the compilation unit that was parsed |
116 * @throws Exception if the source could not be parsed, if the compilation err
ors in the source do | 118 * @throws Exception if the source could not be parsed, if the compilation err
ors in the source do |
117 * not match those that are expected, or if the result would have be
en `null` | 119 * not match those that are expected, or if the result would have be
en `null` |
118 */ | 120 */ |
119 CompilationUnit parseDirectives(String source, | 121 CompilationUnit parseDirectives(String source, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 RethrowExpression parseRethrowExpression(String code); | 186 RethrowExpression parseRethrowExpression(String code); |
185 | 187 |
186 BinaryExpression parseShiftExpression(String code); | 188 BinaryExpression parseShiftExpression(String code); |
187 | 189 |
188 SimpleIdentifier parseSimpleIdentifier(String code); | 190 SimpleIdentifier parseSimpleIdentifier(String code); |
189 | 191 |
190 Statement parseStatement(String source, [bool enableLazyAssignmentOperators]); | 192 Statement parseStatement(String source, [bool enableLazyAssignmentOperators]); |
191 | 193 |
192 Expression parseStringLiteral(String code); | 194 Expression parseStringLiteral(String code); |
193 | 195 |
194 SuperConstructorInvocation parseSuperConstructorInvocation(String code); | |
195 | |
196 SymbolLiteral parseSymbolLiteral(String code); | 196 SymbolLiteral parseSymbolLiteral(String code); |
197 | 197 |
198 Expression parseThrowExpression(String code); | 198 Expression parseThrowExpression(String code); |
199 | 199 |
200 Expression parseThrowExpressionWithoutCascade(String code); | 200 Expression parseThrowExpressionWithoutCascade(String code); |
201 | 201 |
202 PrefixExpression parseUnaryExpression(String code); | 202 PrefixExpression parseUnaryExpression(String code); |
203 } | 203 } |
204 | 204 |
205 /** | 205 /** |
(...skipping 5741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5947 | 5947 |
5948 void test_parsePrimaryExpression_true() { | 5948 void test_parsePrimaryExpression_true() { |
5949 Expression expression = parsePrimaryExpression('true'); | 5949 Expression expression = parsePrimaryExpression('true'); |
5950 expect(expression, isNotNull); | 5950 expect(expression, isNotNull); |
5951 assertNoErrors(); | 5951 assertNoErrors(); |
5952 var literal = expression as BooleanLiteral; | 5952 var literal = expression as BooleanLiteral; |
5953 expect(literal.literal, isNotNull); | 5953 expect(literal.literal, isNotNull); |
5954 expect(literal.value, isTrue); | 5954 expect(literal.value, isTrue); |
5955 } | 5955 } |
5956 | 5956 |
| 5957 void test_parseRedirectingConstructorInvocation_named() { |
| 5958 var invocation = parseConstructorInitializer('this.a()') |
| 5959 as RedirectingConstructorInvocation; |
| 5960 assertNoErrors(); |
| 5961 expect(invocation.argumentList, isNotNull); |
| 5962 expect(invocation.constructorName, isNotNull); |
| 5963 expect(invocation.thisKeyword, isNotNull); |
| 5964 expect(invocation.period, isNotNull); |
| 5965 } |
| 5966 |
| 5967 void test_parseRedirectingConstructorInvocation_unnamed() { |
| 5968 var invocation = parseConstructorInitializer('this()') |
| 5969 as RedirectingConstructorInvocation; |
| 5970 assertNoErrors(); |
| 5971 expect(invocation.argumentList, isNotNull); |
| 5972 expect(invocation.constructorName, isNull); |
| 5973 expect(invocation.thisKeyword, isNotNull); |
| 5974 expect(invocation.period, isNull); |
| 5975 } |
| 5976 |
5957 void test_parseRelationalExpression_as_functionType_noReturnType() { | 5977 void test_parseRelationalExpression_as_functionType_noReturnType() { |
5958 Expression expression = parseRelationalExpression('x as Function(int)'); | 5978 Expression expression = parseRelationalExpression('x as Function(int)'); |
5959 expect(expression, isNotNull); | 5979 expect(expression, isNotNull); |
5960 assertNoErrors(); | 5980 assertNoErrors(); |
5961 var asExpression = expression as AsExpression; | 5981 var asExpression = expression as AsExpression; |
5962 expect(asExpression.expression, isNotNull); | 5982 expect(asExpression.expression, isNotNull); |
5963 expect(asExpression.asOperator, isNotNull); | 5983 expect(asExpression.asOperator, isNotNull); |
5964 expect(asExpression.type, new isInstanceOf<GenericFunctionType>()); | 5984 expect(asExpression.type, new isInstanceOf<GenericFunctionType>()); |
5965 } | 5985 } |
5966 | 5986 |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6368 expect( | 6388 expect( |
6369 interpolation.elements[1], new isInstanceOf<InterpolationExpression>()); | 6389 interpolation.elements[1], new isInstanceOf<InterpolationExpression>()); |
6370 InterpolationExpression element1 = interpolation.elements[1]; | 6390 InterpolationExpression element1 = interpolation.elements[1]; |
6371 expect(element1.expression, new isInstanceOf<SimpleIdentifier>()); | 6391 expect(element1.expression, new isInstanceOf<SimpleIdentifier>()); |
6372 expect(interpolation.elements[2], new isInstanceOf<InterpolationString>()); | 6392 expect(interpolation.elements[2], new isInstanceOf<InterpolationString>()); |
6373 InterpolationString element2 = interpolation.elements[2]; | 6393 InterpolationString element2 = interpolation.elements[2]; |
6374 expect(element2.value, 'y'); | 6394 expect(element2.value, 'y'); |
6375 } | 6395 } |
6376 | 6396 |
6377 void test_parseSuperConstructorInvocation_named() { | 6397 void test_parseSuperConstructorInvocation_named() { |
6378 SuperConstructorInvocation invocation = | 6398 var invocation = |
6379 parseSuperConstructorInvocation('super.a()'); | 6399 parseConstructorInitializer('super.a()') as SuperConstructorInvocation; |
6380 expect(invocation, isNotNull); | 6400 expect(invocation, isNotNull); |
6381 assertNoErrors(); | 6401 assertNoErrors(); |
6382 expect(invocation.argumentList, isNotNull); | 6402 expect(invocation.argumentList, isNotNull); |
6383 expect(invocation.constructorName, isNotNull); | 6403 expect(invocation.constructorName, isNotNull); |
6384 expect(invocation.superKeyword, isNotNull); | 6404 expect(invocation.superKeyword, isNotNull); |
6385 expect(invocation.period, isNotNull); | 6405 expect(invocation.period, isNotNull); |
6386 } | 6406 } |
6387 | 6407 |
6388 void test_parseSuperConstructorInvocation_unnamed() { | 6408 void test_parseSuperConstructorInvocation_unnamed() { |
6389 SuperConstructorInvocation invocation = | 6409 var invocation = |
6390 parseSuperConstructorInvocation('super()'); | 6410 parseConstructorInitializer('super()') as SuperConstructorInvocation; |
6391 expect(invocation, isNotNull); | |
6392 assertNoErrors(); | 6411 assertNoErrors(); |
6393 expect(invocation.argumentList, isNotNull); | 6412 expect(invocation.argumentList, isNotNull); |
6394 expect(invocation.constructorName, isNull); | 6413 expect(invocation.constructorName, isNull); |
6395 expect(invocation.superKeyword, isNotNull); | 6414 expect(invocation.superKeyword, isNotNull); |
6396 expect(invocation.period, isNull); | 6415 expect(invocation.period, isNull); |
6397 } | 6416 } |
6398 | 6417 |
6399 void test_parseSymbolLiteral_builtInIdentifier() { | 6418 void test_parseSymbolLiteral_builtInIdentifier() { |
6400 SymbolLiteral literal = parseSymbolLiteral('#dynamic.static.abstract'); | 6419 SymbolLiteral literal = parseSymbolLiteral('#dynamic.static.abstract'); |
6401 expect(literal, isNotNull); | 6420 expect(literal, isNotNull); |
(...skipping 1622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8024 return parser.parseConditionalExpression(); | 8043 return parser.parseConditionalExpression(); |
8025 } | 8044 } |
8026 | 8045 |
8027 @override | 8046 @override |
8028 Expression parseConstExpression(String code) { | 8047 Expression parseConstExpression(String code) { |
8029 createParser(code); | 8048 createParser(code); |
8030 return parser.parseConstExpression(); | 8049 return parser.parseConstExpression(); |
8031 } | 8050 } |
8032 | 8051 |
8033 @override | 8052 @override |
| 8053 ConstructorInitializer parseConstructorInitializer(String code) { |
| 8054 createParser('class __Test { __Test() : $code; }'); |
| 8055 CompilationUnit unit = parser.parseCompilationUnit2(); |
| 8056 var clazz = unit.declarations[0] as ClassDeclaration; |
| 8057 var constructor = clazz.members[0] as ConstructorDeclaration; |
| 8058 return constructor.initializers.single; |
| 8059 } |
| 8060 |
| 8061 @override |
8034 CompilationUnit parseDirectives(String source, | 8062 CompilationUnit parseDirectives(String source, |
8035 [List<ErrorCode> errorCodes = const <ErrorCode>[]]) { | 8063 [List<ErrorCode> errorCodes = const <ErrorCode>[]]) { |
8036 createParser(source); | 8064 createParser(source); |
8037 CompilationUnit unit = parser.parseDirectives2(); | 8065 CompilationUnit unit = parser.parseDirectives2(); |
8038 expect(unit, isNotNull); | 8066 expect(unit, isNotNull); |
8039 expect(unit.declarations, hasLength(0)); | 8067 expect(unit.declarations, hasLength(0)); |
8040 listener.assertErrorsWithCodes(errorCodes); | 8068 listener.assertErrorsWithCodes(errorCodes); |
8041 return unit; | 8069 return unit; |
8042 } | 8070 } |
8043 | 8071 |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8287 return statements; | 8315 return statements; |
8288 } | 8316 } |
8289 | 8317 |
8290 @override | 8318 @override |
8291 Expression parseStringLiteral(String code) { | 8319 Expression parseStringLiteral(String code) { |
8292 createParser(code); | 8320 createParser(code); |
8293 return parser.parseStringLiteral(); | 8321 return parser.parseStringLiteral(); |
8294 } | 8322 } |
8295 | 8323 |
8296 @override | 8324 @override |
8297 SuperConstructorInvocation parseSuperConstructorInvocation(String code) { | |
8298 createParser(code); | |
8299 return parser.parseSuperConstructorInvocation(); | |
8300 } | |
8301 | |
8302 @override | |
8303 SymbolLiteral parseSymbolLiteral(String code) { | 8325 SymbolLiteral parseSymbolLiteral(String code) { |
8304 createParser(code); | 8326 createParser(code); |
8305 return parser.parseSymbolLiteral(); | 8327 return parser.parseSymbolLiteral(); |
8306 } | 8328 } |
8307 | 8329 |
8308 @override | 8330 @override |
8309 Expression parseThrowExpression(String code) { | 8331 Expression parseThrowExpression(String code) { |
8310 createParser(code); | 8332 createParser(code); |
8311 return parser.parseThrowExpression(); | 8333 return parser.parseThrowExpression(); |
8312 } | 8334 } |
(...skipping 2912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11225 } | 11247 } |
11226 | 11248 |
11227 void test_parseOptionalReturnType() { | 11249 void test_parseOptionalReturnType() { |
11228 // TODO(brianwilkerson) Implement tests for this method. | 11250 // TODO(brianwilkerson) Implement tests for this method. |
11229 } | 11251 } |
11230 | 11252 |
11231 void test_Parser() { | 11253 void test_Parser() { |
11232 expect(new Parser(null, null), isNotNull); | 11254 expect(new Parser(null, null), isNotNull); |
11233 } | 11255 } |
11234 | 11256 |
11235 void test_parseRedirectingConstructorInvocation_named() { | |
11236 createParser('this.a()'); | |
11237 RedirectingConstructorInvocation invocation = | |
11238 parser.parseRedirectingConstructorInvocation(true); | |
11239 expectNotNullIfNoErrors(invocation); | |
11240 listener.assertNoErrors(); | |
11241 expect(invocation.argumentList, isNotNull); | |
11242 expect(invocation.constructorName, isNotNull); | |
11243 expect(invocation.thisKeyword, isNotNull); | |
11244 expect(invocation.period, isNotNull); | |
11245 } | |
11246 | |
11247 void test_parseRedirectingConstructorInvocation_unnamed() { | |
11248 createParser('this()'); | |
11249 RedirectingConstructorInvocation invocation = | |
11250 parser.parseRedirectingConstructorInvocation(false); | |
11251 expectNotNullIfNoErrors(invocation); | |
11252 listener.assertNoErrors(); | |
11253 expect(invocation.argumentList, isNotNull); | |
11254 expect(invocation.constructorName, isNull); | |
11255 expect(invocation.thisKeyword, isNotNull); | |
11256 expect(invocation.period, isNull); | |
11257 } | |
11258 | |
11259 void test_parseReturnStatement_noValue() { | 11257 void test_parseReturnStatement_noValue() { |
11260 createParser('return;'); | 11258 createParser('return;'); |
11261 ReturnStatement statement = parser.parseReturnStatement(); | 11259 ReturnStatement statement = parser.parseReturnStatement(); |
11262 expectNotNullIfNoErrors(statement); | 11260 expectNotNullIfNoErrors(statement); |
11263 listener.assertNoErrors(); | 11261 listener.assertNoErrors(); |
11264 expect(statement.returnKeyword, isNotNull); | 11262 expect(statement.returnKeyword, isNotNull); |
11265 expect(statement.expression, isNull); | 11263 expect(statement.expression, isNull); |
11266 expect(statement.semicolon, isNotNull); | 11264 expect(statement.semicolon, isNotNull); |
11267 } | 11265 } |
11268 | 11266 |
(...skipping 3503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14772 expectCommentText(typeVariable.documentationComment, '/// Doc'); | 14770 expectCommentText(typeVariable.documentationComment, '/// Doc'); |
14773 } | 14771 } |
14774 | 14772 |
14775 /** | 14773 /** |
14776 * Assert that the given [name] is in declaration context. | 14774 * Assert that the given [name] is in declaration context. |
14777 */ | 14775 */ |
14778 void _assertIsDeclarationName(SimpleIdentifier name) { | 14776 void _assertIsDeclarationName(SimpleIdentifier name) { |
14779 expect(name.inDeclarationContext(), isTrue); | 14777 expect(name.inDeclarationContext(), isTrue); |
14780 } | 14778 } |
14781 } | 14779 } |
OLD | NEW |