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

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

Issue 703773004: Add parser recovery tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Improved test Created 6 years, 1 month 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 | Annotate | Revision Log
« 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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.parser_test; 8 library engine.parser_test;
9 9
10 import 'package:analyzer/src/generated/error.dart'; 10 import 'package:analyzer/src/generated/error.dart';
(...skipping 2453 matching lines...) Expand 10 before | Expand all | Expand 10 after
2464 // Make sure we recovered and parsed "var v" correctly 2464 // Make sure we recovered and parsed "var v" correctly
2465 ClassDeclaration declaration = unit.declarations[0] as ClassDeclaration; 2465 ClassDeclaration declaration = unit.declarations[0] as ClassDeclaration;
2466 NodeList<ClassMember> members = declaration.members; 2466 NodeList<ClassMember> members = declaration.members;
2467 ClassMember fieldDecl = members[1]; 2467 ClassMember fieldDecl = members[1];
2468 EngineTestCase.assertInstanceOf((obj) => obj is FieldDeclaration, FieldDecla ration, fieldDecl); 2468 EngineTestCase.assertInstanceOf((obj) => obj is FieldDeclaration, FieldDecla ration, fieldDecl);
2469 NodeList<VariableDeclaration> vars = (fieldDecl as FieldDeclaration).fields. variables; 2469 NodeList<VariableDeclaration> vars = (fieldDecl as FieldDeclaration).fields. variables;
2470 expect(vars, hasLength(1)); 2470 expect(vars, hasLength(1));
2471 expect(vars[0].name.name, "v"); 2471 expect(vars[0].name.name, "v");
2472 } 2472 }
2473 2473
2474 void test_functionExpression_named() {
2475 ParserTestCase.parseExpression("m(f() => 0);", [
2476 ParserErrorCode.EXPECTED_TOKEN]);
2477 }
2478
2479 void test_incomplete_conditionalExpression() {
2480 ParserTestCase.parseExpression("x ? 0", [
2481 ParserErrorCode.EXPECTED_TOKEN,
2482 ParserErrorCode.MISSING_IDENTIFIER]);
2483 }
2484
2474 void test_incomplete_constructorInitializers_empty() { 2485 void test_incomplete_constructorInitializers_empty() {
2475 ParserTestCase.parse3( 2486 ParserTestCase.parse3(
2476 "parseClassMember", 2487 "parseClassMember",
2477 ["C"], 2488 ["C"],
2478 "C() : {}", 2489 "C() : {}",
2479 [ParserErrorCode.MISSING_INITIALIZER]); 2490 [ParserErrorCode.MISSING_INITIALIZER]);
2480 } 2491 }
2481 2492
2482 void test_incomplete_constructorInitializers_missingEquals() { 2493 void test_incomplete_constructorInitializers_missingEquals() {
2483 ClassMember member = ParserTestCase.parse3( 2494 ClassMember member = ParserTestCase.parse3(
(...skipping 12 matching lines...) Expand all
2496 } 2507 }
2497 2508
2498 void test_incomplete_constructorInitializers_variable() { 2509 void test_incomplete_constructorInitializers_variable() {
2499 ParserTestCase.parse3( 2510 ParserTestCase.parse3(
2500 "parseClassMember", 2511 "parseClassMember",
2501 ["C"], 2512 ["C"],
2502 "C() : x {}", 2513 "C() : x {}",
2503 [ParserErrorCode.MISSING_ASSIGNMENT_IN_INITIALIZER]); 2514 [ParserErrorCode.MISSING_ASSIGNMENT_IN_INITIALIZER]);
2504 } 2515 }
2505 2516
2517 void test_incomplete_topLevelFunction() {
2518 ParserTestCase.parseCompilationUnit("foo();", [
2519 ParserErrorCode.MISSING_FUNCTION_BODY]);
2520 }
2521
2506 void test_incomplete_topLevelVariable() { 2522 void test_incomplete_topLevelVariable() {
2507 CompilationUnit unit = ParserTestCase.parseCompilationUnit("String", [Parser ErrorCode.EXPECTED_EXECUTABLE]); 2523 CompilationUnit unit = ParserTestCase.parseCompilationUnit("String", [Parser ErrorCode.EXPECTED_EXECUTABLE]);
2508 NodeList<CompilationUnitMember> declarations = unit.declarations; 2524 NodeList<CompilationUnitMember> declarations = unit.declarations;
2509 expect(declarations, hasLength(1)); 2525 expect(declarations, hasLength(1));
2510 CompilationUnitMember member = declarations[0]; 2526 CompilationUnitMember member = declarations[0];
2511 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableDeclaration, TopLevelVariableDeclaration, member); 2527 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableDeclaration, TopLevelVariableDeclaration, member);
2512 NodeList<VariableDeclaration> variables = (member as TopLevelVariableDeclara tion).variables.variables; 2528 NodeList<VariableDeclaration> variables = (member as TopLevelVariableDeclara tion).variables.variables;
2513 expect(variables, hasLength(1)); 2529 expect(variables, hasLength(1));
2514 SimpleIdentifier name = variables[0].name; 2530 SimpleIdentifier name = variables[0].name;
2515 expect(name.isSynthetic, isTrue); 2531 expect(name.isSynthetic, isTrue);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
2619 ClassMember classMember = members[0]; 2635 ClassMember classMember = members[0];
2620 EngineTestCase.assertInstanceOf((obj) => obj is FieldDeclaration, FieldDecla ration, classMember); 2636 EngineTestCase.assertInstanceOf((obj) => obj is FieldDeclaration, FieldDecla ration, classMember);
2621 VariableDeclarationList fieldList = (classMember as FieldDeclaration).fields ; 2637 VariableDeclarationList fieldList = (classMember as FieldDeclaration).fields ;
2622 expect((fieldList.keyword as KeywordToken).keyword, Keyword.VAR); 2638 expect((fieldList.keyword as KeywordToken).keyword, Keyword.VAR);
2623 NodeList<VariableDeclaration> fields = fieldList.variables; 2639 NodeList<VariableDeclaration> fields = fieldList.variables;
2624 expect(fields, hasLength(1)); 2640 expect(fields, hasLength(1));
2625 VariableDeclaration field = fields[0]; 2641 VariableDeclaration field = fields[0];
2626 expect(field.name.isSynthetic, isTrue); 2642 expect(field.name.isSynthetic, isTrue);
2627 } 2643 }
2628 2644
2645 void test_invalidFunctionBodyModifier() {
2646 ParserTestCase.parseCompilationUnit("f() sync {}", [
2647 ParserErrorCode.MISSING_STAR_AFTER_SYNC]);
2648 }
2649
2629 void test_isExpression_noType() { 2650 void test_isExpression_noType() {
2630 CompilationUnit unit = ParserTestCase.parseCompilationUnit("class Bar<T exte nds Foo> {m(x){if (x is ) return;if (x is !)}}", [ 2651 CompilationUnit unit = ParserTestCase.parseCompilationUnit("class Bar<T exte nds Foo> {m(x){if (x is ) return;if (x is !)}}", [
2631 ParserErrorCode.EXPECTED_TYPE_NAME, 2652 ParserErrorCode.EXPECTED_TYPE_NAME,
2632 ParserErrorCode.EXPECTED_TYPE_NAME, 2653 ParserErrorCode.EXPECTED_TYPE_NAME,
2633 ParserErrorCode.MISSING_STATEMENT]); 2654 ParserErrorCode.MISSING_STATEMENT]);
2634 ClassDeclaration declaration = unit.declarations[0] as ClassDeclaration; 2655 ClassDeclaration declaration = unit.declarations[0] as ClassDeclaration;
2635 MethodDeclaration method = declaration.members[0] as MethodDeclaration; 2656 MethodDeclaration method = declaration.members[0] as MethodDeclaration;
2636 BlockFunctionBody body = method.body as BlockFunctionBody; 2657 BlockFunctionBody body = method.body as BlockFunctionBody;
2637 IfStatement ifStatement = body.block.statements[1] as IfStatement; 2658 IfStatement ifStatement = body.block.statements[1] as IfStatement;
2638 IsExpression expression = ifStatement.condition as IsExpression; 2659 IsExpression expression = ifStatement.condition as IsExpression;
2639 expect(expression.expression, isNotNull); 2660 expect(expression.expression, isNotNull);
2640 expect(expression.isOperator, isNotNull); 2661 expect(expression.isOperator, isNotNull);
2641 expect(expression.notOperator, isNotNull); 2662 expect(expression.notOperator, isNotNull);
2642 TypeName type = expression.type; 2663 TypeName type = expression.type;
2643 expect(type, isNotNull); 2664 expect(type, isNotNull);
2644 expect(type.name.isSynthetic, isTrue); 2665 expect(type.name.isSynthetic, isTrue);
2645 EngineTestCase.assertInstanceOf((obj) => obj is EmptyStatement, EmptyStateme nt, ifStatement.thenStatement); 2666 EngineTestCase.assertInstanceOf((obj) => obj is EmptyStatement, EmptyStateme nt, ifStatement.thenStatement);
2646 } 2667 }
2647 2668
2669 void test_keywordInPlaceOfIdentifier() {
2670 // TODO(brianwilkerson) We could do better with this.
2671 ParserTestCase.parseCompilationUnit("do() {}", [
2672 ParserErrorCode.EXPECTED_EXECUTABLE,
2673 ParserErrorCode.UNEXPECTED_TOKEN]);
2674 }
2675
2648 void test_logicalAndExpression_missing_LHS() { 2676 void test_logicalAndExpression_missing_LHS() {
2649 BinaryExpression expression = ParserTestCase.parseExpression("&& y", [Parser ErrorCode.MISSING_IDENTIFIER]); 2677 BinaryExpression expression = ParserTestCase.parseExpression("&& y", [Parser ErrorCode.MISSING_IDENTIFIER]);
2650 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, SimpleIden tifier, expression.leftOperand); 2678 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, SimpleIden tifier, expression.leftOperand);
2651 expect(expression.leftOperand.isSynthetic, isTrue); 2679 expect(expression.leftOperand.isSynthetic, isTrue);
2652 } 2680 }
2653 2681
2654 void test_logicalAndExpression_missing_LHS_RHS() { 2682 void test_logicalAndExpression_missing_LHS_RHS() {
2655 BinaryExpression expression = ParserTestCase.parseExpression("&&", [ 2683 BinaryExpression expression = ParserTestCase.parseExpression("&&", [
2656 ParserErrorCode.MISSING_IDENTIFIER, 2684 ParserErrorCode.MISSING_IDENTIFIER,
2657 ParserErrorCode.MISSING_IDENTIFIER]); 2685 ParserErrorCode.MISSING_IDENTIFIER]);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2714 } 2742 }
2715 2743
2716 void test_logicalOrExpression_precedence_logicalAnd_right() { 2744 void test_logicalOrExpression_precedence_logicalAnd_right() {
2717 BinaryExpression expression = ParserTestCase.parseExpression("|| &&", [ 2745 BinaryExpression expression = ParserTestCase.parseExpression("|| &&", [
2718 ParserErrorCode.MISSING_IDENTIFIER, 2746 ParserErrorCode.MISSING_IDENTIFIER,
2719 ParserErrorCode.MISSING_IDENTIFIER, 2747 ParserErrorCode.MISSING_IDENTIFIER,
2720 ParserErrorCode.MISSING_IDENTIFIER]); 2748 ParserErrorCode.MISSING_IDENTIFIER]);
2721 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, BinaryExpr ession, expression.rightOperand); 2749 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, BinaryExpr ession, expression.rightOperand);
2722 } 2750 }
2723 2751
2752 void test_missing_commaInArgumentList() {
2753 ParserTestCase.parseExpression("f(x: 1 y: 2)", [
2754 ParserErrorCode.EXPECTED_TOKEN]);
2755 }
2756
2724 void test_missingGet() { 2757 void test_missingGet() {
2725 CompilationUnit unit = ParserTestCase.parseCompilationUnit(r''' 2758 CompilationUnit unit = ParserTestCase.parseCompilationUnit(r'''
2726 class C { 2759 class C {
2727 int length {} 2760 int length {}
2728 void foo() {} 2761 void foo() {}
2729 }''', [ParserErrorCode.MISSING_GET]); 2762 }''', [ParserErrorCode.MISSING_GET]);
2730 expect(unit, isNotNull); 2763 expect(unit, isNotNull);
2731 ClassDeclaration classDeclaration = unit.declarations[0] as ClassDeclaration ; 2764 ClassDeclaration classDeclaration = unit.declarations[0] as ClassDeclaration ;
2732 NodeList<ClassMember> members = classDeclaration.members; 2765 NodeList<ClassMember> members = classDeclaration.members;
2733 expect(members, hasLength(2)); 2766 expect(members, hasLength(2));
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
2886 2919
2887 void test_typedef_eof() { 2920 void test_typedef_eof() {
2888 CompilationUnit unit = ParserTestCase.parseCompilationUnit("typedef n", [ 2921 CompilationUnit unit = ParserTestCase.parseCompilationUnit("typedef n", [
2889 ParserErrorCode.EXPECTED_TOKEN, 2922 ParserErrorCode.EXPECTED_TOKEN,
2890 ParserErrorCode.MISSING_TYPEDEF_PARAMETERS]); 2923 ParserErrorCode.MISSING_TYPEDEF_PARAMETERS]);
2891 NodeList<CompilationUnitMember> declarations = unit.declarations; 2924 NodeList<CompilationUnitMember> declarations = unit.declarations;
2892 expect(declarations, hasLength(1)); 2925 expect(declarations, hasLength(1));
2893 CompilationUnitMember member = declarations[0]; 2926 CompilationUnitMember member = declarations[0];
2894 EngineTestCase.assertInstanceOf((obj) => obj is FunctionTypeAlias, FunctionT ypeAlias, member); 2927 EngineTestCase.assertInstanceOf((obj) => obj is FunctionTypeAlias, FunctionT ypeAlias, member);
2895 } 2928 }
2929
2930 void test_unaryPlus() {
2931 ParserTestCase.parseExpression("+2", [
2932 ParserErrorCode.MISSING_IDENTIFIER]);
2933 }
2896 } 2934 }
2897 2935
2898 class ResolutionCopierTest extends EngineTestCase { 2936 class ResolutionCopierTest extends EngineTestCase {
2899 void test_visitAnnotation() { 2937 void test_visitAnnotation() {
2900 String annotationName = "proxy"; 2938 String annotationName = "proxy";
2901 Annotation fromNode = AstFactory.annotation(AstFactory.identifier3(annotatio nName)); 2939 Annotation fromNode = AstFactory.annotation(AstFactory.identifier3(annotatio nName));
2902 Element element = ElementFactory.topLevelVariableElement2(annotationName); 2940 Element element = ElementFactory.topLevelVariableElement2(annotationName);
2903 fromNode.element = element; 2941 fromNode.element = element;
2904 Annotation toNode = AstFactory.annotation(AstFactory.identifier3(annotationN ame)); 2942 Annotation toNode = AstFactory.annotation(AstFactory.identifier3(annotationN ame));
2905 ResolutionCopier.copyResolutionData(fromNode, toNode); 2943 ResolutionCopier.copyResolutionData(fromNode, toNode);
(...skipping 5425 matching lines...) Expand 10 before | Expand all | Expand 10 after
8331 8369
8332 main() { 8370 main() {
8333 groupSep = ' | '; 8371 groupSep = ' | ';
8334 runReflectiveTests(ComplexParserTest); 8372 runReflectiveTests(ComplexParserTest);
8335 runReflectiveTests(ErrorParserTest); 8373 runReflectiveTests(ErrorParserTest);
8336 runReflectiveTests(IncrementalParserTest); 8374 runReflectiveTests(IncrementalParserTest);
8337 runReflectiveTests(NonErrorParserTest); 8375 runReflectiveTests(NonErrorParserTest);
8338 runReflectiveTests(RecoveryParserTest); 8376 runReflectiveTests(RecoveryParserTest);
8339 runReflectiveTests(ResolutionCopierTest); 8377 runReflectiveTests(ResolutionCopierTest);
8340 runReflectiveTests(SimpleParserTest); 8378 runReflectiveTests(SimpleParserTest);
8341 } 8379 }
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