Chromium Code Reviews| 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..069d2effe5dd1982ebc7072479c03f1678ca3879 100644 |
| --- a/pkg/analyzer2dart/test/tree_shaker_test.dart |
| +++ b/pkg/analyzer2dart/test/tree_shaker_test.dart |
| @@ -27,6 +27,32 @@ 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'); |
| + }); |
|
Paul Berry
2014/09/26 16:42:39
We should probably also test that this drags a "ca
Johnni Winther
2014/09/29 13:07:25
Added with 'foo()' instead of 'return foo'.
|
| + |
| test('Class instantiation', () { |
| var helper = new TreeShakerTestHelper(''' |
| main() { |
| @@ -166,6 +192,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 +251,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 +267,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 +312,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. |
| */ |