| 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:analysis_testing/mock_sdk.dart'; |
| 6 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 6 import 'package:analyzer/src/generated/ast.dart'; | 7 import 'package:analyzer/src/generated/ast.dart'; |
| 7 import 'package:analyzer/src/generated/element.dart'; | 8 import 'package:analyzer/src/generated/element.dart'; |
| 8 import 'package:analyzer/src/generated/sdk.dart'; | 9 import 'package:analyzer/src/generated/sdk.dart'; |
| 9 import 'package:analyzer/src/generated/source.dart'; | 10 import 'package:analyzer/src/generated/source.dart'; |
| 10 import 'package:unittest/unittest.dart'; | 11 import 'package:unittest/unittest.dart'; |
| 11 | 12 |
| 12 import '../lib/src/closed_world.dart'; | 13 import '../lib/src/closed_world.dart'; |
| 13 import '../lib/src/driver.dart'; | 14 import '../lib/src/driver.dart'; |
| 14 | 15 |
| 15 main() { | 16 main() { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 foo(new A()); | 88 foo(new A()); |
| 88 } | 89 } |
| 89 '''); | 90 '''); |
| 90 helper.assertHasMethod('A.m1'); | 91 helper.assertHasMethod('A.m1'); |
| 91 helper.assertHasMethod('A.m2'); | 92 helper.assertHasMethod('A.m2'); |
| 92 }); | 93 }); |
| 93 } | 94 } |
| 94 | 95 |
| 95 class TreeShakerTestHelper { | 96 class TreeShakerTestHelper { |
| 96 /** | 97 /** |
| 98 * The name of the root file. |
| 99 */ |
| 100 String rootFile = '/root.dart'; |
| 101 |
| 102 /** |
| 97 * ClosedWorld that resulted from tree shaking. | 103 * ClosedWorld that resulted from tree shaking. |
| 98 */ | 104 */ |
| 99 ClosedWorld world; | 105 ClosedWorld world; |
| 100 | 106 |
| 101 /** | 107 /** |
| 102 * Functions contained in [world], indexed by name. | 108 * Functions contained in [world], indexed by name. |
| 103 */ | 109 */ |
| 104 Map<String, FunctionDeclaration> functions = <String, FunctionDeclaration>{}; | 110 Map<String, FunctionDeclaration> functions = <String, FunctionDeclaration>{}; |
| 105 | 111 |
| 106 /** | 112 /** |
| 107 * Methods contained in [world], indexed by className.methodName. | 113 * Methods contained in [world], indexed by className.methodName. |
| 108 */ | 114 */ |
| 109 Map<String, MethodDeclaration> methods = <String, MethodDeclaration>{}; | 115 Map<String, MethodDeclaration> methods = <String, MethodDeclaration>{}; |
| 110 | 116 |
| 111 /** | 117 /** |
| 112 * Classes instantiated in [world], indexed by name. | 118 * Classes instantiated in [world], indexed by name. |
| 113 */ | 119 */ |
| 114 Map<String, ClassDeclaration> instantiatedClasses = <String, | 120 Map<String, ClassDeclaration> instantiatedClasses = <String, |
| 115 ClassDeclaration>{}; | 121 ClassDeclaration>{}; |
| 116 | 122 |
| 117 /** | 123 /** |
| 118 * Create a TreeShakerTestHelper based on the given file contents. | 124 * Create a TreeShakerTestHelper based on the given file contents. |
| 119 */ | 125 */ |
| 120 TreeShakerTestHelper(String contents) { | 126 TreeShakerTestHelper(String contents) { |
| 127 MemoryResourceProvider provider = new MemoryResourceProvider(); |
| 121 DartSdk sdk = new MockSdk(); | 128 DartSdk sdk = new MockSdk(); |
| 122 Driver driver = new Driver(sdk); | 129 Driver driver = new Driver(provider, sdk); |
| 123 Source rootSource = driver.setFakeRoot(contents); | 130 provider.newFile(rootFile, contents); |
| 131 Source rootSource = driver.setRoot(rootFile); |
| 124 FunctionElement entryPoint = driver.resolveEntryPoint(rootSource); | 132 FunctionElement entryPoint = driver.resolveEntryPoint(rootSource); |
| 125 world = driver.computeWorld(entryPoint); | 133 world = driver.computeWorld(entryPoint); |
| 126 world.executableElements.forEach( | 134 world.executableElements.forEach( |
| 127 (ExecutableElement element, Declaration node) { | 135 (ExecutableElement element, Declaration node) { |
| 128 if (element is FunctionElement) { | 136 if (element is FunctionElement) { |
| 129 FunctionDeclaration declaration = node as FunctionDeclaration; | 137 FunctionDeclaration declaration = node as FunctionDeclaration; |
| 130 expect(declaration, isNotNull); | 138 expect(declaration, isNotNull); |
| 131 expect(declaration.element, equals(element)); | 139 expect(declaration.element, equals(element)); |
| 132 functions[element.name] = declaration; | 140 functions[element.name] = declaration; |
| 133 } else if (element is MethodElement) { | 141 } else if (element is MethodElement) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 /** | 191 /** |
| 184 * Asserts that [world] doesn't contain a method with the given qualified | 192 * Asserts that [world] doesn't contain a method with the given qualified |
| 185 * name. | 193 * name. |
| 186 * | 194 * |
| 187 * [qualifiedName] - the qualified name in form 'className.methodName'. | 195 * [qualifiedName] - the qualified name in form 'className.methodName'. |
| 188 */ | 196 */ |
| 189 void assertNoMethod(String qualifiedName) { | 197 void assertNoMethod(String qualifiedName) { |
| 190 expect(methods, isNot(contains(qualifiedName))); | 198 expect(methods, isNot(contains(qualifiedName))); |
| 191 } | 199 } |
| 192 } | 200 } |
| OLD | NEW |