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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/test/src/task/dart_test.dart
diff --git a/pkg/analyzer/test/src/task/dart_test.dart b/pkg/analyzer/test/src/task/dart_test.dart
index e948ad818be0d3ff05a10b4c42a24a5020d7b4bb..6b64a374ae6cd4a915189fdae0efa11f9f9bd31c 100644
--- a/pkg/analyzer/test/src/task/dart_test.dart
+++ b/pkg/analyzer/test/src/task/dart_test.dart
@@ -6,6 +6,7 @@ library test.src.task.dart_test;
import 'package:analyzer/src/context/cache.dart';
import 'package:analyzer/src/generated/ast.dart';
+import 'package:analyzer/src/generated/constant.dart';
import 'package:analyzer/src/generated/element.dart';
import 'package:analyzer/src/generated/error.dart';
import 'package:analyzer/src/generated/resolver.dart';
@@ -34,6 +35,7 @@ main() {
runReflectiveTests(BuildPublicNamespaceTaskTest);
runReflectiveTests(BuildTypeProviderTaskTest);
runReflectiveTests(ComputeConstantDependenciesTaskTest);
+ runReflectiveTests(ComputeConstantValueTaskTest);
runReflectiveTests(ContainingLibrariesTaskTest);
runReflectiveTests(DartErrorsTaskTest);
runReflectiveTests(GatherUsedImportedElementsTaskTest);
@@ -1183,6 +1185,65 @@ const y = 1;
}
@reflectiveTest
+class ComputeConstantValueTaskTest extends _AbstractDartTaskTest {
+ fail_circular_reference() {
+ // TODO(paulberry): get this to work.
+ EvaluationResultImpl evaluationResult = _computeTopLevelVariableConstValue(
+ 'x', '''
+const x = y + 1;
+const y = x + 1;
+''');
+ expect(evaluationResult, isNotNull);
+ expect(evaluationResult.value, isNull);
+ expect(evaluationResult.errors, hasLength(1));
+ expect(evaluationResult.errors[0].errorCode,
+ CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT);
+ }
+
+ test_dependency() {
+ EvaluationResultImpl evaluationResult = _computeTopLevelVariableConstValue(
+ 'x', '''
+const x = y + 1;
+const y = 1;
+''');
+ expect(evaluationResult, isNotNull);
+ expect(evaluationResult.value, isNotNull);
+ expect(evaluationResult.value.intValue, 2);
+ }
+
+ test_simple_constant() {
+ EvaluationResultImpl evaluationResult = _computeTopLevelVariableConstValue(
+ 'x', '''
+const x = 1;
+''');
+ expect(evaluationResult, isNotNull);
+ expect(evaluationResult.value, isNotNull);
+ expect(evaluationResult.value.intValue, 1);
+ }
+
+ EvaluationResultImpl _computeTopLevelVariableConstValue(
+ String variableName, String content) {
+ Source source = newSource('/test.dart', content);
+ // First compute the library element for the source.
+ _computeResult(source, LIBRARY_ELEMENT1);
+ LibraryElement libraryElement = outputs[LIBRARY_ELEMENT1];
+ // Find the element for the given constant.
+ List<PropertyAccessorElement> accessors =
+ libraryElement.definingCompilationUnit.accessors;
+ Element variableElement = accessors
+ .firstWhere((PropertyAccessorElement accessor) {
+ return accessor.isGetter && accessor.name == variableName;
+ }).variable;
+ // Now compute the value of the constant.
+ _computeResult(variableElement, CONSTANT_EVALUATED_ELEMENT);
+ expect(outputs[CONSTANT_EVALUATED_ELEMENT], same(variableElement));
+ EvaluationResultImpl evaluationResult =
+ (variableElement as TopLevelVariableElementImpl).evaluationResult;
+ return evaluationResult;
+ }
+}
+
+@reflectiveTest
class ContainingLibrariesTaskTest extends _AbstractDartTaskTest {
test_buildInputs() {
Map<String, TaskInput> inputs =
« 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