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

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

Issue 1521693002: Roll Observatory deps (charted -> ^0.3.0) (Closed) Base URL: https://chromium.googlesource.com/external/github.com/dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years 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 engine.parser_test; 5 library engine.parser_test;
6 6
7 import 'package:analyzer/src/generated/ast.dart'; 7 import 'package:analyzer/src/generated/ast.dart';
8 import 'package:analyzer/src/generated/element.dart'; 8 import 'package:analyzer/src/generated/element.dart';
9 import 'package:analyzer/src/generated/engine.dart'; 9 import 'package:analyzer/src/generated/engine.dart';
10 import 'package:analyzer/src/generated/error.dart'; 10 import 'package:analyzer/src/generated/error.dart';
(...skipping 3203 matching lines...) Expand 10 before | Expand all | Expand 10 after
3214 } 3214 }
3215 3215
3216 void test_conditionalExpression_missingThen() { 3216 void test_conditionalExpression_missingThen() {
3217 ConditionalExpression expression = parse4("parseConditionalExpression", 3217 ConditionalExpression expression = parse4("parseConditionalExpression",
3218 "x ? : z", [ParserErrorCode.MISSING_IDENTIFIER]); 3218 "x ? : z", [ParserErrorCode.MISSING_IDENTIFIER]);
3219 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, 3219 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
3220 SimpleIdentifier, expression.thenExpression); 3220 SimpleIdentifier, expression.thenExpression);
3221 expect(expression.thenExpression.isSynthetic, isTrue); 3221 expect(expression.thenExpression.isSynthetic, isTrue);
3222 } 3222 }
3223 3223
3224 void test_declarationBeforeDirective() {
3225 CompilationUnit unit = ParserTestCase.parseCompilationUnit(
3226 "class foo { } import 'bar.dart';",
3227 [ParserErrorCode.DIRECTIVE_AFTER_DECLARATION]);
3228 expect(unit.directives, hasLength(1));
3229 expect(unit.declarations, hasLength(1));
3230 ClassDeclaration classDecl = unit.childEntities.first;
3231 expect(classDecl, isNotNull);
3232 expect(classDecl.name.name, 'foo');
3233 }
3234
3224 void test_equalityExpression_missing_LHS() { 3235 void test_equalityExpression_missing_LHS() {
3225 BinaryExpression expression = 3236 BinaryExpression expression =
3226 parseExpression("== y", [ParserErrorCode.MISSING_IDENTIFIER]); 3237 parseExpression("== y", [ParserErrorCode.MISSING_IDENTIFIER]);
3227 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, 3238 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
3228 SimpleIdentifier, expression.leftOperand); 3239 SimpleIdentifier, expression.leftOperand);
3229 expect(expression.leftOperand.isSynthetic, isTrue); 3240 expect(expression.leftOperand.isSynthetic, isTrue);
3230 } 3241 }
3231 3242
3232 void test_equalityExpression_missing_LHS_RHS() { 3243 void test_equalityExpression_missing_LHS_RHS() {
3233 BinaryExpression expression = parseExpression("==", [ 3244 BinaryExpression expression = parseExpression("==", [
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
3331 NodeList<VariableDeclaration> vars = 3342 NodeList<VariableDeclaration> vars =
3332 (fieldDecl as FieldDeclaration).fields.variables; 3343 (fieldDecl as FieldDeclaration).fields.variables;
3333 expect(vars, hasLength(1)); 3344 expect(vars, hasLength(1));
3334 expect(vars[0].name.name, "v"); 3345 expect(vars[0].name.name, "v");
3335 } 3346 }
3336 3347
3337 void test_functionExpression_named() { 3348 void test_functionExpression_named() {
3338 parseExpression("m(f() => 0);", [ParserErrorCode.EXPECTED_TOKEN]); 3349 parseExpression("m(f() => 0);", [ParserErrorCode.EXPECTED_TOKEN]);
3339 } 3350 }
3340 3351
3341 void test_declarationBeforeDirective() {
3342 CompilationUnit unit = ParserTestCase.parseCompilationUnit(
3343 "class foo { } import 'bar.dart';",
3344 [ParserErrorCode.DIRECTIVE_AFTER_DECLARATION]);
3345 expect(unit.directives, hasLength(1));
3346 expect(unit.declarations, hasLength(1));
3347 ClassDeclaration classDecl = unit.childEntities.first;
3348 expect(classDecl, isNotNull);
3349 expect(classDecl.name.name, 'foo');
3350 }
3351
3352 void test_importDirectivePartial_as() { 3352 void test_importDirectivePartial_as() {
3353 CompilationUnit unit = ParserTestCase.parseCompilationUnit( 3353 CompilationUnit unit = ParserTestCase.parseCompilationUnit(
3354 "import 'b.dart' d as b;", [ParserErrorCode.UNEXPECTED_TOKEN]); 3354 "import 'b.dart' d as b;", [ParserErrorCode.UNEXPECTED_TOKEN]);
3355 ImportDirective importDirective = unit.childEntities.first; 3355 ImportDirective importDirective = unit.childEntities.first;
3356 expect(importDirective.asKeyword, isNotNull); 3356 expect(importDirective.asKeyword, isNotNull);
3357 expect(unit.directives, hasLength(1)); 3357 expect(unit.directives, hasLength(1));
3358 expect(unit.declarations, hasLength(0)); 3358 expect(unit.declarations, hasLength(0));
3359 } 3359 }
3360 3360
3361 void test_importDirectivePartial_hide() { 3361 void test_importDirectivePartial_hide() {
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
3542 (obj) => obj is FieldDeclaration, FieldDeclaration, classMember); 3542 (obj) => obj is FieldDeclaration, FieldDeclaration, classMember);
3543 VariableDeclarationList fieldList = 3543 VariableDeclarationList fieldList =
3544 (classMember as FieldDeclaration).fields; 3544 (classMember as FieldDeclaration).fields;
3545 expect((fieldList.keyword as KeywordToken).keyword, Keyword.VAR); 3545 expect((fieldList.keyword as KeywordToken).keyword, Keyword.VAR);
3546 NodeList<VariableDeclaration> fields = fieldList.variables; 3546 NodeList<VariableDeclaration> fields = fieldList.variables;
3547 expect(fields, hasLength(1)); 3547 expect(fields, hasLength(1));
3548 VariableDeclaration field = fields[0]; 3548 VariableDeclaration field = fields[0];
3549 expect(field.name.isSynthetic, isTrue); 3549 expect(field.name.isSynthetic, isTrue);
3550 } 3550 }
3551 3551
3552 void test_incompleteForEach() {
3553 ForStatement statement = ParserTestCase.parseStatement(
3554 'for (String item i) {}',
3555 [ParserErrorCode.EXPECTED_TOKEN, ParserErrorCode.EXPECTED_TOKEN]);
3556 expect(statement, new isInstanceOf<ForStatement>());
3557 expect(statement.toSource(), 'for (String item; i;) {}');
3558 expect(statement.leftSeparator, isNotNull);
3559 expect(statement.leftSeparator.type, TokenType.SEMICOLON);
3560 expect(statement.rightSeparator, isNotNull);
3561 expect(statement.rightSeparator.type, TokenType.SEMICOLON);
3562 }
3563
3564 void test_incompleteLocalVariable_atTheEndOfBlock() {
3565 Statement statement = ParserTestCase.parseStatement(
3566 'String v }', [ParserErrorCode.EXPECTED_TOKEN]);
3567 expect(statement, new isInstanceOf<VariableDeclarationStatement>());
3568 expect(statement.toSource(), 'String v;');
3569 }
3570
3571 void test_incompleteLocalVariable_beforeIdentifier() {
3572 Statement statement = ParserTestCase.parseStatement(
3573 'String v String v2;', [ParserErrorCode.EXPECTED_TOKEN]);
3574 expect(statement, new isInstanceOf<VariableDeclarationStatement>());
3575 expect(statement.toSource(), 'String v;');
3576 }
3577
3578 void test_incompleteLocalVariable_beforeKeyword() {
3579 Statement statement = ParserTestCase.parseStatement(
3580 'String v if (true) {}', [ParserErrorCode.EXPECTED_TOKEN]);
3581 expect(statement, new isInstanceOf<VariableDeclarationStatement>());
3582 expect(statement.toSource(), 'String v;');
3583 }
3584
3585 void test_incompleteLocalVariable_beforeNextBlock() {
3586 Statement statement = ParserTestCase.parseStatement(
3587 'String v {}', [ParserErrorCode.EXPECTED_TOKEN]);
3588 expect(statement, new isInstanceOf<VariableDeclarationStatement>());
3589 expect(statement.toSource(), 'String v;');
3590 }
3591
3592 void test_incompleteLocalVariable_parameterizedType() {
3593 Statement statement = ParserTestCase.parseStatement(
3594 'List<String> v {}', [ParserErrorCode.EXPECTED_TOKEN]);
3595 expect(statement, new isInstanceOf<VariableDeclarationStatement>());
3596 expect(statement.toSource(), 'List<String> v;');
3597 }
3598
3552 void test_invalidFunctionBodyModifier() { 3599 void test_invalidFunctionBodyModifier() {
3553 ParserTestCase.parseCompilationUnit( 3600 ParserTestCase.parseCompilationUnit(
3554 "f() sync {}", [ParserErrorCode.MISSING_STAR_AFTER_SYNC]); 3601 "f() sync {}", [ParserErrorCode.MISSING_STAR_AFTER_SYNC]);
3555 } 3602 }
3556 3603
3557 void test_isExpression_noType() { 3604 void test_isExpression_noType() {
3558 CompilationUnit unit = ParserTestCase.parseCompilationUnit( 3605 CompilationUnit unit = ParserTestCase.parseCompilationUnit(
3559 "class Bar<T extends Foo> {m(x){if (x is ) return;if (x is !)}}", [ 3606 "class Bar<T extends Foo> {m(x){if (x is ) return;if (x is !)}}", [
3560 ParserErrorCode.EXPECTED_TYPE_NAME, 3607 ParserErrorCode.EXPECTED_TYPE_NAME,
3561 ParserErrorCode.EXPECTED_TYPE_NAME, 3608 ParserErrorCode.EXPECTED_TYPE_NAME,
(...skipping 5854 matching lines...) Expand 10 before | Expand all | Expand 10 after
9416 expect(identifier.name, lexeme); 9463 expect(identifier.name, lexeme);
9417 } 9464 }
9418 9465
9419 void test_parseSimpleIdentifier_normalIdentifier() { 9466 void test_parseSimpleIdentifier_normalIdentifier() {
9420 String lexeme = "foo"; 9467 String lexeme = "foo";
9421 SimpleIdentifier identifier = parse4("parseSimpleIdentifier", lexeme); 9468 SimpleIdentifier identifier = parse4("parseSimpleIdentifier", lexeme);
9422 expect(identifier.token, isNotNull); 9469 expect(identifier.token, isNotNull);
9423 expect(identifier.name, lexeme); 9470 expect(identifier.name, lexeme);
9424 } 9471 }
9425 9472
9426 void test_parseStatement_emptyTypeArgumentListt() { 9473 void test_parseStatement_emptyTypeArgumentList() {
9427 VariableDeclarationStatement statement = parse4( 9474 VariableDeclarationStatement statement = parse4(
9428 "parseStatement", "C<> c;", [ParserErrorCode.EXPECTED_TYPE_NAME]); 9475 "parseStatement", "C<> c;", [ParserErrorCode.EXPECTED_TYPE_NAME]);
9429 VariableDeclarationList variables = statement.variables; 9476 VariableDeclarationList variables = statement.variables;
9430 TypeName type = variables.type; 9477 TypeName type = variables.type;
9431 TypeArgumentList argumentList = type.typeArguments; 9478 TypeArgumentList argumentList = type.typeArguments;
9432 expect(argumentList.leftBracket, isNotNull); 9479 expect(argumentList.leftBracket, isNotNull);
9433 expect(argumentList.arguments, hasLength(1)); 9480 expect(argumentList.arguments, hasLength(1));
9434 expect(argumentList.arguments[0].isSynthetic, isTrue); 9481 expect(argumentList.arguments[0].isSynthetic, isTrue);
9435 expect(argumentList.rightBracket, isNotNull); 9482 expect(argumentList.rightBracket, isNotNull);
9436 } 9483 }
(...skipping 1248 matching lines...) Expand 10 before | Expand all | Expand 10 after
10685 new Scanner(null, new CharSequenceReader(source), listener); 10732 new Scanner(null, new CharSequenceReader(source), listener);
10686 Token tokenStream = scanner.tokenize(); 10733 Token tokenStream = scanner.tokenize();
10687 // 10734 //
10688 // Parse the source. 10735 // Parse the source.
10689 // 10736 //
10690 Parser parser = new Parser(null, listener); 10737 Parser parser = new Parser(null, listener);
10691 return invokeParserMethodImpl( 10738 return invokeParserMethodImpl(
10692 parser, methodName, <Object>[tokenStream], tokenStream) as Token; 10739 parser, methodName, <Object>[tokenStream], tokenStream) as Token;
10693 } 10740 }
10694 } 10741 }
OLDNEW
« no previous file with comments | « packages/analyzer/test/generated/non_error_resolver_test.dart ('k') | packages/analyzer/test/src/context/context_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698