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

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

Issue 2672403004: Begin hooking up Fasta to analyzer parser tests. (Closed)
Patch Set: Created 3 years, 10 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 16 matching lines...) Expand all
27 defineReflectiveSuite(() { 27 defineReflectiveSuite(() {
28 defineReflectiveTests(ComplexParserTest); 28 defineReflectiveTests(ComplexParserTest);
29 defineReflectiveTests(ErrorParserTest); 29 defineReflectiveTests(ErrorParserTest);
30 defineReflectiveTests(NonErrorParserTest); 30 defineReflectiveTests(NonErrorParserTest);
31 defineReflectiveTests(RecoveryParserTest); 31 defineReflectiveTests(RecoveryParserTest);
32 defineReflectiveTests(SimpleParserTest); 32 defineReflectiveTests(SimpleParserTest);
33 }); 33 });
34 } 34 }
35 35
36 /** 36 /**
37 * Abstract base class for parser tests, which does not make assumptions about
38 * which parser is used.
39 */
40 abstract class AbstractParserTestCase {
41 void set enableGenericMethodComments(bool value);
42
43 void set enableNnbd(bool value);
44
45 CompilationUnit parseCompilationUnitWithOptions(String source,
46 [List<ErrorCode> errorCodes = const <ErrorCode>[]]);
47
48 Expression parseExpression(String source,
49 [List<ErrorCode> errorCodes = const <ErrorCode>[]]);
50 }
51
52 /**
37 * Instances of the class `AstValidator` are used to validate the correct constr uction of an 53 * Instances of the class `AstValidator` are used to validate the correct constr uction of an
38 * AST structure. 54 * AST structure.
39 */ 55 */
40 class AstValidator extends UnifyingAstVisitor<Object> { 56 class AstValidator extends UnifyingAstVisitor<Object> {
41 /** 57 /**
42 * A list containing the errors found while traversing the AST structure. 58 * A list containing the errors found while traversing the AST structure.
43 */ 59 */
44 List<String> _errors = new List<String>(); 60 List<String> _errors = new List<String>();
45 61
46 /** 62 /**
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 } 118 }
103 if (nodeEnd > parentEnd) { 119 if (nodeEnd > parentEnd) {
104 _errors.add( 120 _errors.add(
105 "Invalid source end ($nodeEnd) for ${node.runtimeType} inside ${pare nt.runtimeType} ($parentStart)"); 121 "Invalid source end ($nodeEnd) for ${node.runtimeType} inside ${pare nt.runtimeType} ($parentStart)");
106 } 122 }
107 } 123 }
108 } 124 }
109 } 125 }
110 126
111 /** 127 /**
128 * Tests of the analyzer parser based on [ComplexParserTestMixin].
129 */
130 @reflectiveTest
131 class ComplexParserTest extends ParserTestCase with ComplexParserTestMixin {}
132
133 /**
112 * The class `ComplexParserTest` defines parser tests that test the parsing of m ore complex 134 * The class `ComplexParserTest` defines parser tests that test the parsing of m ore complex
113 * code fragments or the interactions between multiple parsing methods. For exam ple, tests to ensure 135 * code fragments or the interactions between multiple parsing methods. For exam ple, tests to ensure
114 * that the precedence of operations is being handled correctly should be define d in this class. 136 * that the precedence of operations is being handled correctly should be define d in this class.
115 * 137 *
116 * Simpler tests should be defined in the class [SimpleParserTest]. 138 * Simpler tests should be defined in the class [SimpleParserTest].
117 */ 139 */
118 @reflectiveTest 140 abstract class ComplexParserTestMixin implements AbstractParserTestCase {
119 class ComplexParserTest extends ParserTestCase {
120 void test_additiveExpression_normal() { 141 void test_additiveExpression_normal() {
121 BinaryExpression expression = parseExpression("x + y - z"); 142 BinaryExpression expression = parseExpression("x + y - z");
122 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression, 143 EngineTestCase.assertInstanceOf((obj) => obj is BinaryExpression,
123 BinaryExpression, expression.leftOperand); 144 BinaryExpression, expression.leftOperand);
124 } 145 }
125 146
126 void test_additiveExpression_noSpaces() { 147 void test_additiveExpression_noSpaces() {
127 BinaryExpression expression = parseExpression("i+1"); 148 BinaryExpression expression = parseExpression("i+1");
128 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier, 149 EngineTestCase.assertInstanceOf((obj) => obj is SimpleIdentifier,
129 SimpleIdentifier, expression.leftOperand); 150 SimpleIdentifier, expression.leftOperand);
(...skipping 2816 matching lines...) Expand 10 before | Expand all | Expand 10 after
2946 createParser('class C { static void m() {} }'); 2967 createParser('class C { static void m() {} }');
2947 CompilationUnit unit = parser.parseCompilationUnit2(); 2968 CompilationUnit unit = parser.parseCompilationUnit2();
2948 expectNotNullIfNoErrors(unit); 2969 expectNotNullIfNoErrors(unit);
2949 listener.assertNoErrors(); 2970 listener.assertNoErrors();
2950 } finally { 2971 } finally {
2951 ParserTestCase.parseFunctionBodies = true; 2972 ParserTestCase.parseFunctionBodies = true;
2952 } 2973 }
2953 } 2974 }
2954 } 2975 }
2955 2976
2956 class ParserTestCase extends EngineTestCase { 2977 /**
2978 * Implementation of [AbstractParserTestCase] specialized for testing the
2979 * analyzer parser.
2980 */
2981 class ParserTestCase extends EngineTestCase implements AbstractParserTestCase {
2957 /** 2982 /**
2958 * A flag indicating whether parser is to parse function bodies. 2983 * A flag indicating whether parser is to parse function bodies.
2959 */ 2984 */
2960 static bool parseFunctionBodies = true; 2985 static bool parseFunctionBodies = true;
2961 2986
2962 /** 2987 /**
2963 * A flag indicating whether the parser is to parse asserts in the initializer 2988 * A flag indicating whether the parser is to parse asserts in the initializer
2964 * list of a constructor. 2989 * list of a constructor.
2965 */ 2990 */
2966 bool enableAssertInitializer = false; 2991 bool enableAssertInitializer = false;
(...skipping 11637 matching lines...) Expand 10 before | Expand all | Expand 10 after
14604 CompilationUnit _parseDirectives(String source, 14629 CompilationUnit _parseDirectives(String source,
14605 [List<ErrorCode> errorCodes = const <ErrorCode>[]]) { 14630 [List<ErrorCode> errorCodes = const <ErrorCode>[]]) {
14606 createParser(source); 14631 createParser(source);
14607 CompilationUnit unit = parser.parseDirectives2(); 14632 CompilationUnit unit = parser.parseDirectives2();
14608 expect(unit, isNotNull); 14633 expect(unit, isNotNull);
14609 expect(unit.declarations, hasLength(0)); 14634 expect(unit.declarations, hasLength(0));
14610 listener.assertErrorsWithCodes(errorCodes); 14635 listener.assertErrorsWithCodes(errorCodes);
14611 return unit; 14636 return unit;
14612 } 14637 }
14613 } 14638 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/parser_test_fasta.dart » ('j') | pkg/analyzer/test/generated/parser_test_fasta.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698