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

Unified Diff: pkg/analyzer2dart/test/tree_shaker_test.dart

Issue 609783002: Support static field access in analyzer2dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 6 years, 3 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/analyzer2dart/test/tree_shaker_test.dart
diff --git a/pkg/analyzer2dart/test/tree_shaker_test.dart b/pkg/analyzer2dart/test/tree_shaker_test.dart
index 31064368b3861b62c6d782c5915c639910a70b44..938b334e3dfc6d424797e2ba99f56b61dd1d16dc 100644
--- a/pkg/analyzer2dart/test/tree_shaker_test.dart
+++ b/pkg/analyzer2dart/test/tree_shaker_test.dart
@@ -27,6 +27,53 @@ foo() {
helper.assertHasFunction('foo');
});
+ test('Toplevel field access', () {
+ var helper = new TreeShakerTestHelper('''
+main() {
+ return foo;
+}
+var foo;
+var bar;
+''');
+ helper.assertHasFunction('main');
+ helper.assertHasVariable('foo');
+ helper.assertNoVariable('bar');
+ });
+
+ test('Toplevel field invocation', () {
+ var helper = new TreeShakerTestHelper('''
+main() {
+ return foo();
+}
+var foo;
+var bar;
+''');
+ helper.assertHasFunction('main');
+ helper.assertHasVariable('foo');
+ helper.assertNoVariable('bar');
+ });
+
+ test('Member field invocation', () {
+ var helper = new TreeShakerTestHelper('''
+class A {
+ void call() {}
+ void baz() {}
+}
+main() {
+ new A();
+ foo();
+}
+var foo;
+var bar;
+''');
+ helper.assertHasFunction('main');
+ helper.assertHasVariable('foo');
+ helper.assertNoVariable('bar');
+ helper.assertHasInstantiatedClass('A');
+ helper.assertHasMethod('A.call');
+ helper.assertNoMethod('A.baz');
+ });
+
test('Class instantiation', () {
var helper = new TreeShakerTestHelper('''
main() {
@@ -166,6 +213,11 @@ class TreeShakerTestHelper {
Map<String, VariableDeclaration> fields = <String, VariableDeclaration>{};
/**
+ * Top level variables contained in [world], indexed by name.
+ */
+ Map<String, VariableDeclaration> variables = <String, VariableDeclaration>{};
+
+ /**
* Classes instantiated in [world], indexed by name.
*/
Map<String, ClassDeclaration> instantiatedClasses = <String,
@@ -220,6 +272,12 @@ class TreeShakerTestHelper {
expect(declaration.element, equals(element));
fields['${element.enclosingElement.name}.${element.name}'] = declaration;
});
+ world.variables.forEach(
+ (TopLevelVariableElement element, VariableDeclaration declaration) {
+ expect(declaration, isNotNull);
+ expect(declaration.element, equals(element));
+ variables['${element.name}'] = declaration;
+ });
}
/**
@@ -230,6 +288,13 @@ class TreeShakerTestHelper {
}
/**
+ * Asserts that [world] contains a top level variable with the given name.
+ */
+ void assertHasVariable(String name) {
+ expect(variables, contains(name));
+ }
+
+ /**
* Asserts that [world] contains a top-level function with the given name.
*/
void assertHasFunction(String name) {
@@ -268,6 +333,14 @@ class TreeShakerTestHelper {
}
/**
+ * Asserts that [world] doesn't contain a top level variable with the given
+ * name.
+ */
+ void assertNoVariable(String name) {
+ expect(variables, isNot(contains(name)));
+ }
+
+ /**
* Asserts that [world] doesn't contain a top-level function with the given
* name.
*/
« no previous file with comments | « pkg/analyzer2dart/test/end2end_test.dart ('k') | sdk/lib/_internal/compiler/implementation/cps_ir/cps_ir_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698