OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
| 5 import 'package:analysis_testing/mock_sdk.dart'; |
5 import 'package:analyzer/src/generated/ast.dart'; | 6 import 'package:analyzer/src/generated/ast.dart'; |
6 import 'package:analyzer/src/generated/element.dart'; | 7 import 'package:analyzer/src/generated/element.dart'; |
| 8 import 'package:analyzer/src/generated/sdk.dart'; |
| 9 import 'package:analyzer/src/generated/source.dart'; |
7 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
8 | 11 |
9 import '../lib/src/closed_world.dart'; | 12 import '../lib/src/closed_world.dart'; |
10 import '../lib/src/driver.dart'; | 13 import '../lib/src/driver.dart'; |
11 | 14 |
12 main() { | 15 main() { |
13 test('Toplevel function', () { | 16 test('Toplevel function', () { |
14 var helper = new TreeShakerTestHelper(''' | 17 var helper = new TreeShakerTestHelper(''' |
15 main() { | 18 main() { |
16 foo(); | 19 foo(); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 /** | 111 /** |
109 * Classes instantiated in [world], indexed by name. | 112 * Classes instantiated in [world], indexed by name. |
110 */ | 113 */ |
111 Map<String, ClassDeclaration> instantiatedClasses = <String, | 114 Map<String, ClassDeclaration> instantiatedClasses = <String, |
112 ClassDeclaration>{}; | 115 ClassDeclaration>{}; |
113 | 116 |
114 /** | 117 /** |
115 * Create a TreeShakerTestHelper based on the given file contents. | 118 * Create a TreeShakerTestHelper based on the given file contents. |
116 */ | 119 */ |
117 TreeShakerTestHelper(String contents) { | 120 TreeShakerTestHelper(String contents) { |
118 Driver driver = new Driver(); | 121 DartSdk sdk = new MockSdk(); |
119 world = | 122 Driver driver = new Driver(sdk); |
120 driver.computeWorld(driver.resolveEntryPoint(driver.setFakeRoot(contents
))); | 123 Source rootSource = driver.setFakeRoot(contents); |
| 124 FunctionElement entryPoint = driver.resolveEntryPoint(rootSource); |
| 125 world = driver.computeWorld(entryPoint); |
121 world.executableElements.forEach( | 126 world.executableElements.forEach( |
122 (ExecutableElement element, Declaration node) { | 127 (ExecutableElement element, Declaration node) { |
123 if (element is FunctionElement) { | 128 if (element is FunctionElement) { |
124 FunctionDeclaration declaration = node as FunctionDeclaration; | 129 FunctionDeclaration declaration = node as FunctionDeclaration; |
125 expect(declaration, isNotNull); | 130 expect(declaration, isNotNull); |
126 expect(declaration.element, equals(element)); | 131 expect(declaration.element, equals(element)); |
127 functions[element.name] = declaration; | 132 functions[element.name] = declaration; |
128 } else if (element is MethodElement) { | 133 } else if (element is MethodElement) { |
129 MethodDeclaration declaration = node as MethodDeclaration; | 134 MethodDeclaration declaration = node as MethodDeclaration; |
130 expect(declaration, isNotNull); | 135 expect(declaration, isNotNull); |
131 expect(declaration.element, equals(element)); | 136 expect(declaration.element, equals(element)); |
132 methods['${element.enclosingElement.name}.${element.name}'] = | 137 methods['${element.enclosingElement.name}.${element.name}'] = |
133 declaration; | 138 declaration; |
134 } | 139 } |
135 }); | 140 }); |
136 world.instantiatedClasses.forEach( | 141 world.instantiatedClasses.forEach( |
137 (ClassElement element, ClassDeclaration declaration) { | 142 (ClassElement element, ClassDeclaration declaration) { |
138 expect(declaration, isNotNull); | 143 expect(declaration, isNotNull); |
139 expect(declaration.element, equals(element)); | 144 expect(declaration.element, equals(element)); |
140 instantiatedClasses[element.name] = declaration; | 145 instantiatedClasses[element.name] = declaration; |
141 }); | 146 }); |
142 } | 147 } |
143 } | 148 } |
OLD | NEW |