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

Unified Diff: pkg/analyzer/test/generated/constant_test.dart

Issue 1623673003: Oops, move ReferenceTest to constant_test.dart as well (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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
« no previous file with comments | « pkg/analyzer/test/generated/all_the_rest_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/generated/constant_test.dart
diff --git a/pkg/analyzer/test/generated/constant_test.dart b/pkg/analyzer/test/generated/constant_test.dart
index 23d1af1d55800d5e38a805c1b526f7285a602a13..885b28681e7128c548ee2e9d21d023f041595ea4 100644
--- a/pkg/analyzer/test/generated/constant_test.dart
+++ b/pkg/analyzer/test/generated/constant_test.dart
@@ -18,6 +18,7 @@ import 'package:analyzer/src/generated/source_io.dart';
import 'package:analyzer/src/generated/testing/ast_factory.dart';
import 'package:analyzer/src/generated/testing/element_factory.dart';
import 'package:analyzer/src/generated/testing/test_type_provider.dart';
+import 'package:analyzer/src/generated/utilities_collection.dart';
import 'package:analyzer/src/task/dart.dart';
import 'package:path/path.dart';
import 'package:unittest/unittest.dart';
@@ -34,6 +35,7 @@ main() {
runReflectiveTests(ConstantFinderTest);
runReflectiveTests(ConstantValueComputerTest);
runReflectiveTests(ConstantVisitorTest);
+ runReflectiveTests(ReferenceFinderTest);
}
/**
@@ -2195,6 +2197,98 @@ const b = 3;''');
}
}
+@reflectiveTest
+class ReferenceFinderTest {
+ DirectedGraph<ConstantEvaluationTarget> _referenceGraph;
+ VariableElement _head;
+ Element _tail;
+
+ void setUp() {
+ _referenceGraph = new DirectedGraph<ConstantEvaluationTarget>();
+ _head = ElementFactory.topLevelVariableElement2("v1");
+ }
+
+ void test_visitSimpleIdentifier_const() {
+ _visitNode(_makeTailVariable("v2", true));
+ _assertOneArc(_tail);
+ }
+
+ void test_visitSimpleIdentifier_nonConst() {
+ _visitNode(_makeTailVariable("v2", false));
+ _assertOneArc(_tail);
+ }
+
+ void test_visitSuperConstructorInvocation_const() {
+ _visitNode(_makeTailSuperConstructorInvocation("A", true));
+ _assertOneArc(_tail);
+ }
+
+ void test_visitSuperConstructorInvocation_nonConst() {
+ _visitNode(_makeTailSuperConstructorInvocation("A", false));
+ _assertOneArc(_tail);
+ }
+
+ void test_visitSuperConstructorInvocation_unresolved() {
+ SuperConstructorInvocation superConstructorInvocation =
+ AstFactory.superConstructorInvocation();
+ _visitNode(superConstructorInvocation);
+ _assertNoArcs();
+ }
+
+ void _assertNoArcs() {
+ Set<ConstantEvaluationTarget> tails = _referenceGraph.getTails(_head);
+ expect(tails, hasLength(0));
+ }
+
+ void _assertOneArc(Element tail) {
+ Set<ConstantEvaluationTarget> tails = _referenceGraph.getTails(_head);
+ expect(tails, hasLength(1));
+ expect(tails.first, same(tail));
+ }
+
+ ReferenceFinder _createReferenceFinder(ConstantEvaluationTarget source) =>
+ new ReferenceFinder((ConstantEvaluationTarget dependency) {
+ _referenceGraph.addEdge(source, dependency);
+ });
+ SuperConstructorInvocation _makeTailSuperConstructorInvocation(
+ String name, bool isConst) {
+ List<ConstructorInitializer> initializers =
+ new List<ConstructorInitializer>();
+ ConstructorDeclaration constructorDeclaration =
+ AstFactory.constructorDeclaration(AstFactory.identifier3(name), null,
+ AstFactory.formalParameterList(), initializers);
+ if (isConst) {
+ constructorDeclaration.constKeyword = new KeywordToken(Keyword.CONST, 0);
+ }
+ ClassElementImpl classElement = ElementFactory.classElement2(name);
+ SuperConstructorInvocation superConstructorInvocation =
+ AstFactory.superConstructorInvocation();
+ ConstructorElementImpl constructorElement =
+ ElementFactory.constructorElement(classElement, name, isConst);
+ _tail = constructorElement;
+ superConstructorInvocation.staticElement = constructorElement;
+ return superConstructorInvocation;
+ }
+
+ SimpleIdentifier _makeTailVariable(String name, bool isConst) {
+ VariableDeclaration variableDeclaration =
+ AstFactory.variableDeclaration(name);
+ ConstLocalVariableElementImpl variableElement =
+ ElementFactory.constLocalVariableElement(name);
+ _tail = variableElement;
+ variableElement.const3 = isConst;
+ AstFactory.variableDeclarationList2(
+ isConst ? Keyword.CONST : Keyword.VAR, [variableDeclaration]);
+ SimpleIdentifier identifier = AstFactory.identifier3(name);
+ identifier.staticElement = variableElement;
+ return identifier;
+ }
+
+ void _visitNode(AstNode node) {
+ node.accept(_createReferenceFinder(_head));
+ }
+}
+
class _TestAnalysisContext extends TestAnalysisContext {
@override
InternalAnalysisContext getContextFor(Source source) => this;
« no previous file with comments | « pkg/analyzer/test/generated/all_the_rest_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698