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

Side by Side Diff: pkg/analyzer/test/dart/element/builder_test.dart

Issue 2683543006: Make some parser test helper methods non-static. (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.dart.element.builder_test; 5 library analyzer.test.dart.element.builder_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/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
(...skipping 1012 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 } 1023 }
1024 1024
1025 @reflectiveTest 1025 @reflectiveTest
1026 class LocalElementBuilderTest extends _BaseTest { 1026 class LocalElementBuilderTest extends _BaseTest {
1027 @override 1027 @override
1028 AstVisitor createElementBuilder(ElementHolder holder) { 1028 AstVisitor createElementBuilder(ElementHolder holder) {
1029 return new LocalElementBuilder(holder, compilationUnitElement); 1029 return new LocalElementBuilder(holder, compilationUnitElement);
1030 } 1030 }
1031 1031
1032 void test_buildLocalElements() { 1032 void test_buildLocalElements() {
1033 CompilationUnit unit = ParserTestCase.parseCompilationUnit(r''' 1033 CompilationUnit unit = parseCompilationUnit(r'''
1034 main() { 1034 main() {
1035 int v1; 1035 int v1;
1036 f1() { 1036 f1() {
1037 int v2; 1037 int v2;
1038 f2() { 1038 f2() {
1039 int v3; 1039 int v3;
1040 } 1040 }
1041 } 1041 }
1042 } 1042 }
1043 '''); 1043 ''');
(...skipping 23 matching lines...) Expand all
1067 { 1067 {
1068 FunctionElement f2 = f1.functions[0]; 1068 FunctionElement f2 = f1.functions[0];
1069 expect(f2.name, 'f2'); 1069 expect(f2.name, 'f2');
1070 expect(f2.localVariables.map((v) => v.name), ['v3']); 1070 expect(f2.localVariables.map((v) => v.name), ['v3']);
1071 expect(f2.functions, isEmpty); 1071 expect(f2.functions, isEmpty);
1072 } 1072 }
1073 } 1073 }
1074 } 1074 }
1075 1075
1076 void test_buildParameterInitializer() { 1076 void test_buildParameterInitializer() {
1077 CompilationUnit unit = ParserTestCase.parseCompilationUnit('f({p: 42}) {}'); 1077 CompilationUnit unit = parseCompilationUnit('f({p: 42}) {}');
1078 var function = unit.declarations.single as FunctionDeclaration; 1078 var function = unit.declarations.single as FunctionDeclaration;
1079 var parameter = function.functionExpression.parameters.parameters.single 1079 var parameter = function.functionExpression.parameters.parameters.single
1080 as DefaultFormalParameter; 1080 as DefaultFormalParameter;
1081 // Build API elements. 1081 // Build API elements.
1082 { 1082 {
1083 ElementHolder holder = new ElementHolder(); 1083 ElementHolder holder = new ElementHolder();
1084 unit.accept(new ApiElementBuilder(holder, compilationUnitElement)); 1084 unit.accept(new ApiElementBuilder(holder, compilationUnitElement));
1085 } 1085 }
1086 // Validate the parameter element. 1086 // Validate the parameter element.
1087 var parameterElement = parameter.element as ParameterElementImpl; 1087 var parameterElement = parameter.element as ParameterElementImpl;
1088 expect(parameterElement, isNotNull); 1088 expect(parameterElement, isNotNull);
1089 expect(parameterElement.initializer, isNull); 1089 expect(parameterElement.initializer, isNull);
1090 // Build the initializer element. 1090 // Build the initializer element.
1091 new LocalElementBuilder(new ElementHolder(), compilationUnitElement) 1091 new LocalElementBuilder(new ElementHolder(), compilationUnitElement)
1092 .buildParameterInitializer(parameterElement, parameter.defaultValue); 1092 .buildParameterInitializer(parameterElement, parameter.defaultValue);
1093 expect(parameterElement.initializer, isNotNull); 1093 expect(parameterElement.initializer, isNotNull);
1094 } 1094 }
1095 1095
1096 void test_buildVariableInitializer() { 1096 void test_buildVariableInitializer() {
1097 CompilationUnit unit = ParserTestCase.parseCompilationUnit('var V = 42;'); 1097 CompilationUnit unit = parseCompilationUnit('var V = 42;');
1098 TopLevelVariableDeclaration topLevelDecl = 1098 TopLevelVariableDeclaration topLevelDecl =
1099 unit.declarations[0] as TopLevelVariableDeclaration; 1099 unit.declarations[0] as TopLevelVariableDeclaration;
1100 VariableDeclaration variable = topLevelDecl.variables.variables.single; 1100 VariableDeclaration variable = topLevelDecl.variables.variables.single;
1101 // Build the variable element. 1101 // Build the variable element.
1102 { 1102 {
1103 ElementHolder holder = new ElementHolder(); 1103 ElementHolder holder = new ElementHolder();
1104 unit.accept(new ApiElementBuilder(holder, compilationUnitElement)); 1104 unit.accept(new ApiElementBuilder(holder, compilationUnitElement));
1105 } 1105 }
1106 // Validate the variable element. 1106 // Validate the variable element.
1107 var variableElement = variable.element as VariableElementImpl; 1107 var variableElement = variable.element as VariableElementImpl;
1108 expect(variableElement, isNotNull); 1108 expect(variableElement, isNotNull);
1109 expect(variableElement.initializer, isNull); 1109 expect(variableElement.initializer, isNull);
1110 // Build the initializer element. 1110 // Build the initializer element.
1111 new LocalElementBuilder(new ElementHolder(), compilationUnitElement) 1111 new LocalElementBuilder(new ElementHolder(), compilationUnitElement)
1112 .buildVariableInitializer(variableElement, variable.initializer); 1112 .buildVariableInitializer(variableElement, variable.initializer);
1113 expect(variableElement.initializer, isNotNull); 1113 expect(variableElement.initializer, isNotNull);
1114 } 1114 }
1115 1115
1116 void test_visitDefaultFormalParameter_local() { 1116 void test_visitDefaultFormalParameter_local() {
1117 CompilationUnit unit = ParserTestCase.parseCompilationUnit(''' 1117 CompilationUnit unit = parseCompilationUnit('''
1118 main() { 1118 main() {
1119 f({bool b: false}) {} 1119 f({bool b: false}) {}
1120 } 1120 }
1121 '''); 1121 ''');
1122 var mainAst = unit.declarations.single as FunctionDeclaration; 1122 var mainAst = unit.declarations.single as FunctionDeclaration;
1123 // Build API elements. 1123 // Build API elements.
1124 FunctionElementImpl main; 1124 FunctionElementImpl main;
1125 { 1125 {
1126 ElementHolder holder = new ElementHolder(); 1126 ElementHolder holder = new ElementHolder();
1127 unit.accept(new ApiElementBuilder(holder, compilationUnitElement)); 1127 unit.accept(new ApiElementBuilder(holder, compilationUnitElement));
(...skipping 1403 matching lines...) Expand 10 before | Expand all | Expand 10 after
2531 expect(typeParameters, hasLength(1)); 2531 expect(typeParameters, hasLength(1));
2532 TypeParameterElement typeParameterElement = typeParameters[0]; 2532 TypeParameterElement typeParameterElement = typeParameters[0];
2533 expect(typeParameterElement, isNotNull); 2533 expect(typeParameterElement, isNotNull);
2534 assertHasCodeRange(typeParameterElement, 50, 1); 2534 assertHasCodeRange(typeParameterElement, 50, 1);
2535 expect(typeParameterElement.name, parameterName); 2535 expect(typeParameterElement.name, parameterName);
2536 expect(typeParameterElement.bound, isNull); 2536 expect(typeParameterElement.bound, isNull);
2537 expect(typeParameterElement.isSynthetic, isFalse); 2537 expect(typeParameterElement.isSynthetic, isFalse);
2538 } 2538 }
2539 } 2539 }
2540 2540
2541 abstract class _BaseTest { 2541 abstract class _BaseTest extends ParserTestCase {
2542 CompilationUnitElement compilationUnitElement; 2542 CompilationUnitElement compilationUnitElement;
2543 CompilationUnit _compilationUnit; 2543 CompilationUnit _compilationUnit;
2544 2544
2545 CompilationUnit get compilationUnit => _compilationUnit; 2545 CompilationUnit get compilationUnit => _compilationUnit;
2546 2546
2547 void assertHasCodeRange(Element element, int offset, int length) { 2547 void assertHasCodeRange(Element element, int offset, int length) {
2548 ElementImpl elementImpl = element; 2548 ElementImpl elementImpl = element;
2549 expect(elementImpl.codeOffset, offset); 2549 expect(elementImpl.codeOffset, offset);
2550 expect(elementImpl.codeLength, length); 2550 expect(elementImpl.codeLength, length);
2551 } 2551 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
2612 } 2612 }
2613 2613
2614 /** 2614 /**
2615 * Parse the given [code], and visit it with the given [visitor]. 2615 * Parse the given [code], and visit it with the given [visitor].
2616 * Fail if any error is logged. 2616 * Fail if any error is logged.
2617 */ 2617 */
2618 void _visitAstOfCode(String code, AstVisitor visitor) { 2618 void _visitAstOfCode(String code, AstVisitor visitor) {
2619 TestLogger logger = new TestLogger(); 2619 TestLogger logger = new TestLogger();
2620 AnalysisEngine.instance.logger = logger; 2620 AnalysisEngine.instance.logger = logger;
2621 try { 2621 try {
2622 _compilationUnit = ParserTestCase.parseCompilationUnit(code); 2622 _compilationUnit = parseCompilationUnit(code);
2623 compilationUnit.accept(visitor); 2623 compilationUnit.accept(visitor);
2624 } finally { 2624 } finally {
2625 expect(logger.log, hasLength(0)); 2625 expect(logger.log, hasLength(0));
2626 AnalysisEngine.instance.logger = Logger.NULL; 2626 AnalysisEngine.instance.logger = Logger.NULL;
2627 } 2627 }
2628 } 2628 }
2629 } 2629 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/dart/ast/visitor_test.dart ('k') | pkg/analyzer/test/generated/all_the_rest_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698