| 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 =
|
|
|