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

Side by Side Diff: pkg/analyzer/test/src/task/dart_test.dart

Issue 1125423004: Add a task to the new task model for computing constant values. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 test.src.task.dart_test; 5 library test.src.task.dart_test;
6 6
7 import 'package:analyzer/src/context/cache.dart'; 7 import 'package:analyzer/src/context/cache.dart';
8 import 'package:analyzer/src/generated/ast.dart'; 8 import 'package:analyzer/src/generated/ast.dart';
9 import 'package:analyzer/src/generated/constant.dart';
9 import 'package:analyzer/src/generated/element.dart'; 10 import 'package:analyzer/src/generated/element.dart';
10 import 'package:analyzer/src/generated/error.dart'; 11 import 'package:analyzer/src/generated/error.dart';
11 import 'package:analyzer/src/generated/resolver.dart'; 12 import 'package:analyzer/src/generated/resolver.dart';
12 import 'package:analyzer/src/generated/source.dart'; 13 import 'package:analyzer/src/generated/source.dart';
13 import 'package:analyzer/src/task/dart.dart'; 14 import 'package:analyzer/src/task/dart.dart';
14 import 'package:analyzer/task/dart.dart'; 15 import 'package:analyzer/task/dart.dart';
15 import 'package:analyzer/task/general.dart'; 16 import 'package:analyzer/task/general.dart';
16 import 'package:analyzer/task/model.dart'; 17 import 'package:analyzer/task/model.dart';
17 import 'package:unittest/unittest.dart'; 18 import 'package:unittest/unittest.dart';
18 19
19 import '../../generated/test_support.dart'; 20 import '../../generated/test_support.dart';
20 import '../../reflective_tests.dart'; 21 import '../../reflective_tests.dart';
21 import '../context/abstract_context.dart'; 22 import '../context/abstract_context.dart';
22 23
23 main() { 24 main() {
24 groupSep = ' | '; 25 groupSep = ' | ';
25 runReflectiveTests(BuildClassConstructorsTaskTest); 26 runReflectiveTests(BuildClassConstructorsTaskTest);
26 runReflectiveTests(BuildCompilationUnitElementTaskTest); 27 runReflectiveTests(BuildCompilationUnitElementTaskTest);
27 runReflectiveTests(BuildDirectiveElementsTaskTest); 28 runReflectiveTests(BuildDirectiveElementsTaskTest);
28 runReflectiveTests(BuildEnumMemberElementsTaskTest); 29 runReflectiveTests(BuildEnumMemberElementsTaskTest);
29 runReflectiveTests(BuildSourceClosuresTaskTest); 30 runReflectiveTests(BuildSourceClosuresTaskTest);
30 runReflectiveTests(BuildExportNamespaceTaskTest); 31 runReflectiveTests(BuildExportNamespaceTaskTest);
31 runReflectiveTests(BuildFunctionTypeAliasesTaskTest); 32 runReflectiveTests(BuildFunctionTypeAliasesTaskTest);
32 runReflectiveTests(BuildLibraryConstructorsTaskTest); 33 runReflectiveTests(BuildLibraryConstructorsTaskTest);
33 runReflectiveTests(BuildLibraryElementTaskTest); 34 runReflectiveTests(BuildLibraryElementTaskTest);
34 runReflectiveTests(BuildPublicNamespaceTaskTest); 35 runReflectiveTests(BuildPublicNamespaceTaskTest);
35 runReflectiveTests(BuildTypeProviderTaskTest); 36 runReflectiveTests(BuildTypeProviderTaskTest);
36 runReflectiveTests(ComputeConstantDependenciesTaskTest); 37 runReflectiveTests(ComputeConstantDependenciesTaskTest);
38 runReflectiveTests(ComputeConstantValueTaskTest);
37 runReflectiveTests(ContainingLibrariesTaskTest); 39 runReflectiveTests(ContainingLibrariesTaskTest);
38 runReflectiveTests(DartErrorsTaskTest); 40 runReflectiveTests(DartErrorsTaskTest);
39 runReflectiveTests(GatherUsedImportedElementsTaskTest); 41 runReflectiveTests(GatherUsedImportedElementsTaskTest);
40 runReflectiveTests(GatherUsedLocalElementsTaskTest); 42 runReflectiveTests(GatherUsedLocalElementsTaskTest);
41 runReflectiveTests(GenerateHintsTaskTest); 43 runReflectiveTests(GenerateHintsTaskTest);
42 runReflectiveTests(LibraryUnitErrorsTaskTest); 44 runReflectiveTests(LibraryUnitErrorsTaskTest);
43 runReflectiveTests(ParseDartTaskTest); 45 runReflectiveTests(ParseDartTaskTest);
44 runReflectiveTests(ResolveUnitTypeNamesTaskTest); 46 runReflectiveTests(ResolveUnitTypeNamesTaskTest);
45 runReflectiveTests(ResolveLibraryTypeNamesTaskTest); 47 runReflectiveTests(ResolveLibraryTypeNamesTaskTest);
46 runReflectiveTests(ResolveReferencesTaskTest); 48 runReflectiveTests(ResolveReferencesTaskTest);
(...skipping 1129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1176 accessor.isGetter && accessor.name == 'x').variable; 1178 accessor.isGetter && accessor.name == 'x').variable;
1177 Element y = accessors.firstWhere((PropertyAccessorElement accessor) => 1179 Element y = accessors.firstWhere((PropertyAccessorElement accessor) =>
1178 accessor.isGetter && accessor.name == 'y').variable; 1180 accessor.isGetter && accessor.name == 'y').variable;
1179 // Now compute the dependencies for x, and check that it is the list [y]. 1181 // Now compute the dependencies for x, and check that it is the list [y].
1180 _computeResult(x, CONSTANT_DEPENDENCIES); 1182 _computeResult(x, CONSTANT_DEPENDENCIES);
1181 expect(outputs[CONSTANT_DEPENDENCIES], [y]); 1183 expect(outputs[CONSTANT_DEPENDENCIES], [y]);
1182 } 1184 }
1183 } 1185 }
1184 1186
1185 @reflectiveTest 1187 @reflectiveTest
1188 class ComputeConstantValueTaskTest extends _AbstractDartTaskTest {
1189 fail_circular_reference() {
1190 // TODO(paulberry): get this to work.
1191 EvaluationResultImpl evaluationResult = _computeTopLevelVariableConstValue(
1192 'x', '''
1193 const x = y + 1;
1194 const y = x + 1;
1195 ''');
1196 expect(evaluationResult, isNotNull);
1197 expect(evaluationResult.value, isNull);
1198 expect(evaluationResult.errors, hasLength(1));
1199 expect(evaluationResult.errors[0].errorCode,
1200 CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT);
1201 }
1202
1203 test_dependency() {
1204 EvaluationResultImpl evaluationResult = _computeTopLevelVariableConstValue(
1205 'x', '''
1206 const x = y + 1;
1207 const y = 1;
1208 ''');
1209 expect(evaluationResult, isNotNull);
1210 expect(evaluationResult.value, isNotNull);
1211 expect(evaluationResult.value.intValue, 2);
1212 }
1213
1214 test_simple_constant() {
1215 EvaluationResultImpl evaluationResult = _computeTopLevelVariableConstValue(
1216 'x', '''
1217 const x = 1;
1218 ''');
1219 expect(evaluationResult, isNotNull);
1220 expect(evaluationResult.value, isNotNull);
1221 expect(evaluationResult.value.intValue, 1);
1222 }
1223
1224 EvaluationResultImpl _computeTopLevelVariableConstValue(
1225 String variableName, String content) {
1226 Source source = newSource('/test.dart', content);
1227 // First compute the library element for the source.
1228 _computeResult(source, LIBRARY_ELEMENT1);
1229 LibraryElement libraryElement = outputs[LIBRARY_ELEMENT1];
1230 // Find the element for the given constant.
1231 List<PropertyAccessorElement> accessors =
1232 libraryElement.definingCompilationUnit.accessors;
1233 Element variableElement = accessors
1234 .firstWhere((PropertyAccessorElement accessor) {
1235 return accessor.isGetter && accessor.name == variableName;
1236 }).variable;
1237 // Now compute the value of the constant.
1238 _computeResult(variableElement, CONSTANT_EVALUATED_ELEMENT);
1239 expect(outputs[CONSTANT_EVALUATED_ELEMENT], same(variableElement));
1240 EvaluationResultImpl evaluationResult =
1241 (variableElement as TopLevelVariableElementImpl).evaluationResult;
1242 return evaluationResult;
1243 }
1244 }
1245
1246 @reflectiveTest
1186 class ContainingLibrariesTaskTest extends _AbstractDartTaskTest { 1247 class ContainingLibrariesTaskTest extends _AbstractDartTaskTest {
1187 test_buildInputs() { 1248 test_buildInputs() {
1188 Map<String, TaskInput> inputs = 1249 Map<String, TaskInput> inputs =
1189 ContainingLibrariesTask.buildInputs(emptySource); 1250 ContainingLibrariesTask.buildInputs(emptySource);
1190 expect(inputs, isNotNull); 1251 expect(inputs, isNotNull);
1191 expect(inputs, isEmpty); 1252 expect(inputs, isEmpty);
1192 } 1253 }
1193 1254
1194 test_constructor() { 1255 test_constructor() {
1195 ContainingLibrariesTask task = 1256 ContainingLibrariesTask task =
(...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after
2107 /** 2168 /**
2108 * Fill [errorListener] with [result] errors in the current [task]. 2169 * Fill [errorListener] with [result] errors in the current [task].
2109 */ 2170 */
2110 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { 2171 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) {
2111 List<AnalysisError> errors = task.outputs[result]; 2172 List<AnalysisError> errors = task.outputs[result];
2112 expect(errors, isNotNull, reason: result.name); 2173 expect(errors, isNotNull, reason: result.name);
2113 errorListener = new GatheringErrorListener(); 2174 errorListener = new GatheringErrorListener();
2114 errorListener.addAll(errors); 2175 errorListener.addAll(errors);
2115 } 2176 }
2116 } 2177 }
OLDNEW
« pkg/analyzer/lib/src/task/general.dart ('K') | « pkg/analyzer/lib/src/task/general.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698