| 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() { |
| 17 MemoryResourceProvider provider; |
| 16 Driver driver; | 18 Driver driver; |
| 17 setUp(() { | 19 setUp(() { |
| 20 provider = new MemoryResourceProvider(); |
| 18 DartSdk sdk = new MockSdk(); | 21 DartSdk sdk = new MockSdk(); |
| 19 driver = new Driver(sdk); | 22 driver = new Driver(provider, sdk); |
| 20 }); | 23 }); |
| 21 | 24 |
| 22 test('setFakeRoot', () { | 25 Source setFakeRoot(String contents) { |
| 23 var contents = 'main() {}'; | 26 String path = '/root.dart'; |
| 24 Source source = driver.setFakeRoot(contents); | 27 provider.newFile(path, contents); |
| 25 expect(driver.context.getContents(source).data, equals(contents)); | 28 return driver.setRoot(path); |
| 26 }); | 29 } |
| 27 | 30 |
| 28 test('resolveEntryPoint', () { | 31 test('resolveEntryPoint', () { |
| 29 String contents = 'main() {}'; | 32 String contents = 'main() {}'; |
| 30 FunctionElement element = | 33 Source source = setFakeRoot(contents); |
| 31 driver.resolveEntryPoint(driver.setFakeRoot(contents)); | 34 FunctionElement element = driver.resolveEntryPoint(source); |
| 32 expect(element.name, equals('main')); | 35 expect(element.name, equals('main')); |
| 33 }); | 36 }); |
| 34 | 37 |
| 35 test('computeWorld', () { | 38 test('computeWorld', () { |
| 36 String contents = ''' | 39 String contents = ''' |
| 37 main() { | 40 main() { |
| 38 foo(); | 41 foo(); |
| 39 } | 42 } |
| 40 | 43 |
| 41 foo() { | 44 foo() { |
| 42 } | 45 } |
| 43 | 46 |
| 44 bar() { | 47 bar() { |
| 45 } | 48 } |
| 46 '''; | 49 '''; |
| 47 FunctionElement entryPoint = | 50 Source source = setFakeRoot(contents); |
| 48 driver.resolveEntryPoint(driver.setFakeRoot(contents)); | 51 FunctionElement entryPoint = driver.resolveEntryPoint(source); |
| 49 ClosedWorld world = driver.computeWorld(entryPoint); | 52 ClosedWorld world = driver.computeWorld(entryPoint); |
| 50 expect(world.executableElements, hasLength(2)); | 53 expect(world.executableElements, hasLength(2)); |
| 51 CompilationUnitElement compilationUnit = | 54 CompilationUnitElement compilationUnit = |
| 52 entryPoint.getAncestor((e) => e is CompilationUnitElement); | 55 entryPoint.getAncestor((e) => e is CompilationUnitElement); |
| 53 Map<String, FunctionElement> functions = {}; | 56 Map<String, FunctionElement> functions = {}; |
| 54 for (FunctionElement functionElement in compilationUnit.functions) { | 57 for (FunctionElement functionElement in compilationUnit.functions) { |
| 55 functions[functionElement.name] = functionElement; | 58 functions[functionElement.name] = functionElement; |
| 56 } | 59 } |
| 57 FunctionElement mainElement = functions['main']; | 60 FunctionElement mainElement = functions['main']; |
| 58 expect(world.executableElements.keys, contains(mainElement)); | 61 expect(world.executableElements.keys, contains(mainElement)); |
| 59 FunctionDeclaration mainAst = world.executableElements[mainElement]; | 62 FunctionDeclaration mainAst = world.executableElements[mainElement]; |
| 60 expect(mainAst.element, equals(mainElement)); | 63 expect(mainAst.element, equals(mainElement)); |
| 61 FunctionElement fooElement = functions['foo']; | 64 FunctionElement fooElement = functions['foo']; |
| 62 expect(world.executableElements.keys, contains(fooElement)); | 65 expect(world.executableElements.keys, contains(fooElement)); |
| 63 FunctionDeclaration fooAst = world.executableElements[fooElement]; | 66 FunctionDeclaration fooAst = world.executableElements[fooElement]; |
| 64 expect(fooAst.element, equals(fooElement)); | 67 expect(fooAst.element, equals(fooElement)); |
| 65 FunctionElement barElement = functions['bar']; | 68 FunctionElement barElement = functions['bar']; |
| 66 expect( | 69 expect( |
| 67 world.executableElements.keys, | 70 world.executableElements.keys, |
| 68 isNot(contains(functions[barElement]))); | 71 isNot(contains(functions[barElement]))); |
| 69 }); | 72 }); |
| 70 } | 73 } |
| OLD | NEW |