Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Unified Diff: pkg/analyzer2dart/test/driver_test.dart

Issue 516463007: Create unit tests for analyzer2dart/driver. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer2dart/lib/src/driver.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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])));
+ });
+}
« no previous file with comments | « pkg/analyzer2dart/lib/src/driver.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698