| 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 import 'package:analyzer/dart/ast/ast.dart'; | 5 import 'package:analyzer/dart/ast/ast.dart'; |
| 6 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; | 6 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; |
| 7 import 'package:analyzer/dart/ast/token.dart'; | 7 import 'package:analyzer/dart/ast/token.dart'; |
| 8 import 'package:analyzer/dart/ast/visitor.dart'; | 8 import 'package:analyzer/dart/ast/visitor.dart'; |
| 9 import 'package:analyzer/error/error.dart'; | 9 import 'package:analyzer/error/error.dart'; |
| 10 import 'package:analyzer/error/listener.dart'; | 10 import 'package:analyzer/error/listener.dart'; |
| (...skipping 9152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9163 BinaryExpression, expression.leftOperand); | 9163 BinaryExpression, expression.leftOperand); |
| 9164 } | 9164 } |
| 9165 | 9165 |
| 9166 void test_classTypeAlias_withBody() { | 9166 void test_classTypeAlias_withBody() { |
| 9167 parseCompilationUnit(r''' | 9167 parseCompilationUnit(r''' |
| 9168 class A {} | 9168 class A {} |
| 9169 class B = Object with A {}''', [ParserErrorCode.EXPECTED_TOKEN]); | 9169 class B = Object with A {}''', [ParserErrorCode.EXPECTED_TOKEN]); |
| 9170 } | 9170 } |
| 9171 | 9171 |
| 9172 void test_conditionalExpression_missingElse() { | 9172 void test_conditionalExpression_missingElse() { |
| 9173 createParser('x ? y :'); | 9173 Expression expression = |
| 9174 Expression expression = parser.parseConditionalExpression(); | 9174 parseExpression('x ? y :', [ParserErrorCode.MISSING_IDENTIFIER]); |
| 9175 expectNotNullIfNoErrors(expression); | 9175 expectNotNullIfNoErrors(expression); |
| 9176 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); | |
| 9177 expect(expression, new isInstanceOf<ConditionalExpression>()); | 9176 expect(expression, new isInstanceOf<ConditionalExpression>()); |
| 9178 ConditionalExpression conditionalExpression = expression; | 9177 ConditionalExpression conditionalExpression = expression; |
| 9179 expect(conditionalExpression.elseExpression, | 9178 expect(conditionalExpression.elseExpression, |
| 9180 new isInstanceOf<SimpleIdentifier>()); | 9179 new isInstanceOf<SimpleIdentifier>()); |
| 9181 expect(conditionalExpression.elseExpression.isSynthetic, isTrue); | 9180 expect(conditionalExpression.elseExpression.isSynthetic, isTrue); |
| 9182 } | 9181 } |
| 9183 | 9182 |
| 9184 void test_conditionalExpression_missingThen() { | 9183 void test_conditionalExpression_missingThen() { |
| 9185 createParser('x ? : z'); | 9184 Expression expression = |
| 9186 Expression expression = parser.parseConditionalExpression(); | 9185 parseExpression('x ? : z', [ParserErrorCode.MISSING_IDENTIFIER]); |
| 9187 expectNotNullIfNoErrors(expression); | 9186 expectNotNullIfNoErrors(expression); |
| 9188 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); | |
| 9189 expect(expression, new isInstanceOf<ConditionalExpression>()); | 9187 expect(expression, new isInstanceOf<ConditionalExpression>()); |
| 9190 ConditionalExpression conditionalExpression = expression; | 9188 ConditionalExpression conditionalExpression = expression; |
| 9191 expect(conditionalExpression.thenExpression, | 9189 expect(conditionalExpression.thenExpression, |
| 9192 new isInstanceOf<SimpleIdentifier>()); | 9190 new isInstanceOf<SimpleIdentifier>()); |
| 9193 expect(conditionalExpression.thenExpression.isSynthetic, isTrue); | 9191 expect(conditionalExpression.thenExpression.isSynthetic, isTrue); |
| 9194 } | 9192 } |
| 9195 | 9193 |
| 9196 void test_declarationBeforeDirective() { | 9194 void test_declarationBeforeDirective() { |
| 9197 CompilationUnit unit = parseCompilationUnit( | 9195 CompilationUnit unit = parseCompilationUnit( |
| 9198 "class foo { } import 'bar.dart';", | 9196 "class foo { } import 'bar.dart';", |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9265 BinaryExpression expression = parseExpression("super == ==", [ | 9263 BinaryExpression expression = parseExpression("super == ==", [ |
| 9266 ParserErrorCode.MISSING_IDENTIFIER, | 9264 ParserErrorCode.MISSING_IDENTIFIER, |
| 9267 ParserErrorCode.MISSING_IDENTIFIER, | 9265 ParserErrorCode.MISSING_IDENTIFIER, |
| 9268 ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND | 9266 ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND |
| 9269 ]); | 9267 ]); |
| 9270 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, | 9268 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, |
| 9271 BinaryExpression, expression.leftOperand); | 9269 BinaryExpression, expression.leftOperand); |
| 9272 } | 9270 } |
| 9273 | 9271 |
| 9274 void test_expressionList_multiple_end() { | 9272 void test_expressionList_multiple_end() { |
| 9275 createParser(', 2, 3, 4'); | 9273 List<Expression> result = parseExpressionList(', 2, 3, 4'); |
| 9276 List<Expression> result = parser.parseExpressionList(); | |
| 9277 expectNotNullIfNoErrors(result); | 9274 expectNotNullIfNoErrors(result); |
| 9278 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); | 9275 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| 9279 expect(result, hasLength(4)); | 9276 expect(result, hasLength(4)); |
| 9280 Expression syntheticExpression = result[0]; | 9277 Expression syntheticExpression = result[0]; |
| 9281 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, | 9278 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| 9282 SimpleIdentifier, syntheticExpression); | 9279 SimpleIdentifier, syntheticExpression); |
| 9283 expect(syntheticExpression.isSynthetic, isTrue); | 9280 expect(syntheticExpression.isSynthetic, isTrue); |
| 9284 } | 9281 } |
| 9285 | 9282 |
| 9286 void test_expressionList_multiple_middle() { | 9283 void test_expressionList_multiple_middle() { |
| 9287 createParser('1, 2, , 4'); | 9284 List<Expression> result = parseExpressionList('1, 2, , 4'); |
| 9288 List<Expression> result = parser.parseExpressionList(); | |
| 9289 expectNotNullIfNoErrors(result); | 9285 expectNotNullIfNoErrors(result); |
| 9290 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); | 9286 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| 9291 expect(result, hasLength(4)); | 9287 expect(result, hasLength(4)); |
| 9292 Expression syntheticExpression = result[2]; | 9288 Expression syntheticExpression = result[2]; |
| 9293 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, | 9289 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| 9294 SimpleIdentifier, syntheticExpression); | 9290 SimpleIdentifier, syntheticExpression); |
| 9295 expect(syntheticExpression.isSynthetic, isTrue); | 9291 expect(syntheticExpression.isSynthetic, isTrue); |
| 9296 } | 9292 } |
| 9297 | 9293 |
| 9298 void test_expressionList_multiple_start() { | 9294 void test_expressionList_multiple_start() { |
| 9299 createParser('1, 2, 3,'); | 9295 List<Expression> result = parseExpressionList('1, 2, 3,'); |
| 9300 List<Expression> result = parser.parseExpressionList(); | |
| 9301 expectNotNullIfNoErrors(result); | 9296 expectNotNullIfNoErrors(result); |
| 9302 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); | 9297 listener.assertErrorsWithCodes([ParserErrorCode.MISSING_IDENTIFIER]); |
| 9303 expect(result, hasLength(4)); | 9298 expect(result, hasLength(4)); |
| 9304 Expression syntheticExpression = result[3]; | 9299 Expression syntheticExpression = result[3]; |
| 9305 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, | 9300 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, |
| 9306 SimpleIdentifier, syntheticExpression); | 9301 SimpleIdentifier, syntheticExpression); |
| 9307 expect(syntheticExpression.isSynthetic, isTrue); | 9302 expect(syntheticExpression.isSynthetic, isTrue); |
| 9308 } | 9303 } |
| 9309 | 9304 |
| 9310 void test_functionExpression_in_ConstructorFieldInitializer() { | 9305 void test_functionExpression_in_ConstructorFieldInitializer() { |
| (...skipping 2599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11910 expectNotNullIfNoErrors(modifiers); | 11905 expectNotNullIfNoErrors(modifiers); |
| 11911 listener.assertNoErrors(); | 11906 listener.assertNoErrors(); |
| 11912 expect(modifiers.varKeyword, isNotNull); | 11907 expect(modifiers.varKeyword, isNotNull); |
| 11913 } | 11908 } |
| 11914 | 11909 |
| 11915 void test_parseOptionalReturnType() { | 11910 void test_parseOptionalReturnType() { |
| 11916 // TODO(brianwilkerson) Implement tests for this method. | 11911 // TODO(brianwilkerson) Implement tests for this method. |
| 11917 } | 11912 } |
| 11918 | 11913 |
| 11919 void test_parseReturnStatement_noValue() { | 11914 void test_parseReturnStatement_noValue() { |
| 11920 createParser('return;'); | 11915 ReturnStatement statement = parseStatement('return;'); |
| 11921 ReturnStatement statement = parser.parseReturnStatement(); | |
| 11922 expectNotNullIfNoErrors(statement); | 11916 expectNotNullIfNoErrors(statement); |
| 11923 listener.assertNoErrors(); | 11917 listener.assertNoErrors(); |
| 11924 expect(statement.returnKeyword, isNotNull); | 11918 expect(statement.returnKeyword, isNotNull); |
| 11925 expect(statement.expression, isNull); | 11919 expect(statement.expression, isNull); |
| 11926 expect(statement.semicolon, isNotNull); | 11920 expect(statement.semicolon, isNotNull); |
| 11927 } | 11921 } |
| 11928 | 11922 |
| 11929 void test_parseReturnStatement_value() { | 11923 void test_parseReturnStatement_value() { |
| 11930 createParser('return x;'); | 11924 ReturnStatement statement = parseStatement('return x;'); |
| 11931 ReturnStatement statement = parser.parseReturnStatement(); | |
| 11932 expectNotNullIfNoErrors(statement); | 11925 expectNotNullIfNoErrors(statement); |
| 11933 listener.assertNoErrors(); | 11926 listener.assertNoErrors(); |
| 11934 expect(statement.returnKeyword, isNotNull); | 11927 expect(statement.returnKeyword, isNotNull); |
| 11935 expect(statement.expression, isNotNull); | 11928 expect(statement.expression, isNotNull); |
| 11936 expect(statement.semicolon, isNotNull); | 11929 expect(statement.semicolon, isNotNull); |
| 11937 } | 11930 } |
| 11938 | 11931 |
| 11939 void test_parseReturnType_function() { | 11932 void test_parseReturnType_function() { |
| 11940 // TODO(eernst): `parseReturnType` eliminated, delete this test? | 11933 // TODO(eernst): `parseReturnType` eliminated, delete this test? |
| 11941 createParser('A<B> Function<B>(B)'); | 11934 createParser('A<B> Function<B>(B)'); |
| (...skipping 3545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15487 expectCommentText(typeVariable.documentationComment, '/// Doc'); | 15480 expectCommentText(typeVariable.documentationComment, '/// Doc'); |
| 15488 } | 15481 } |
| 15489 | 15482 |
| 15490 /** | 15483 /** |
| 15491 * Assert that the given [name] is in declaration context. | 15484 * Assert that the given [name] is in declaration context. |
| 15492 */ | 15485 */ |
| 15493 void _assertIsDeclarationName(SimpleIdentifier name) { | 15486 void _assertIsDeclarationName(SimpleIdentifier name) { |
| 15494 expect(name.inDeclarationContext(), isTrue); | 15487 expect(name.inDeclarationContext(), isTrue); |
| 15495 } | 15488 } |
| 15496 } | 15489 } |
| OLD | NEW |