Index: pkg/analyzer2dart/test/driver_test.dart |
diff --git a/pkg/analyzer2dart/test/driver_test.dart b/pkg/analyzer2dart/test/driver_test.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3942907137da93af8e8d638a55b71337d38ce17b |
--- /dev/null |
+++ b/pkg/analyzer2dart/test/driver_test.dart |
@@ -0,0 +1,62 @@ |
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
+import 'package:analyzer/src/generated/element.dart'; |
+import 'package:analyzer/src/generated/source.dart'; |
+import 'package:unittest/unittest.dart'; |
+import 'package:analyzer/src/generated/ast.dart'; |
+ |
+import '../lib/src/closed_world.dart'; |
+import '../lib/src/driver.dart'; |
+ |
+main() { |
+ test('setFakeRoot', () { |
+ Driver driver = new Driver(); |
+ var contents = 'main() {}'; |
+ Source source = driver.setFakeRoot(contents); |
+ expect(driver.context.getContents(source).data, equals(contents)); |
+ }); |
+ |
+ test('resolveEntryPoint', () { |
+ Driver driver = new Driver(); |
+ String contents = 'main() {}'; |
+ FunctionElement element = |
+ driver.resolveEntryPoint(driver.setFakeRoot(contents)); |
+ expect(element.name, equals('main')); |
+ }); |
+ |
+ test('computeWorld', () { |
+ Driver driver = new Driver(); |
+ String contents = ''' |
+main() { |
+ foo(); |
+} |
+ |
+foo() { |
+} |
+ |
+bar() { |
+} |
+'''; |
+ FunctionElement entryPoint = driver.resolveEntryPoint(driver.setFakeRoot(contents)); |
Johnni Winther
2014/08/28 11:25:28
Long line.
|
+ ClosedWorld world = |
+ driver.computeWorld(entryPoint); |
Johnni Winther
2014/08/28 11:25:28
This could fit in one line.
|
+ expect(world.elements, hasLength(2)); |
+ CompilationUnitElement compilationUnit = entryPoint.getAncestor((e) => e is CompilationUnitElement); |
Johnni Winther
2014/08/28 11:25:29
Ditto.
|
+ Map<String, FunctionElement> functions = {}; |
+ for (FunctionElement functionElement in compilationUnit.functions) { |
+ functions[functionElement.name] = functionElement; |
+ } |
+ FunctionElement mainElement = functions['main']; |
+ expect(world.elements.keys, contains(mainElement)); |
+ FunctionDeclaration mainAst = world.elements[mainElement]; |
+ expect(mainAst.element, equals(mainElement)); |
+ FunctionElement fooElement = functions['foo']; |
+ expect(world.elements.keys, contains(fooElement)); |
+ FunctionDeclaration fooAst = world.elements[fooElement]; |
+ expect(fooAst.element, equals(fooElement)); |
+ FunctionElement barElement = functions['bar']; |
+ expect(world.elements.keys, isNot(contains(functions[barElement]))); |
+ }); |
+} |