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

Side by Side 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, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/analyzer2dart/lib/src/driver.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'package:analyzer/src/generated/element.dart';
6 import 'package:analyzer/src/generated/source.dart';
7 import 'package:unittest/unittest.dart';
8 import 'package:analyzer/src/generated/ast.dart';
9
10 import '../lib/src/closed_world.dart';
11 import '../lib/src/driver.dart';
12
13 main() {
14 test('setFakeRoot', () {
15 Driver driver = new Driver();
16 var contents = 'main() {}';
17 Source source = driver.setFakeRoot(contents);
18 expect(driver.context.getContents(source).data, equals(contents));
19 });
20
21 test('resolveEntryPoint', () {
22 Driver driver = new Driver();
23 String contents = 'main() {}';
24 FunctionElement element =
25 driver.resolveEntryPoint(driver.setFakeRoot(contents));
26 expect(element.name, equals('main'));
27 });
28
29 test('computeWorld', () {
30 Driver driver = new Driver();
31 String contents = '''
32 main() {
33 foo();
34 }
35
36 foo() {
37 }
38
39 bar() {
40 }
41 ''';
42 FunctionElement entryPoint = driver.resolveEntryPoint(driver.setFakeRoot(con tents));
Johnni Winther 2014/08/28 11:25:28 Long line.
43 ClosedWorld world =
44 driver.computeWorld(entryPoint);
Johnni Winther 2014/08/28 11:25:28 This could fit in one line.
45 expect(world.elements, hasLength(2));
46 CompilationUnitElement compilationUnit = entryPoint.getAncestor((e) => e is CompilationUnitElement);
Johnni Winther 2014/08/28 11:25:29 Ditto.
47 Map<String, FunctionElement> functions = {};
48 for (FunctionElement functionElement in compilationUnit.functions) {
49 functions[functionElement.name] = functionElement;
50 }
51 FunctionElement mainElement = functions['main'];
52 expect(world.elements.keys, contains(mainElement));
53 FunctionDeclaration mainAst = world.elements[mainElement];
54 expect(mainAst.element, equals(mainElement));
55 FunctionElement fooElement = functions['foo'];
56 expect(world.elements.keys, contains(fooElement));
57 FunctionDeclaration fooAst = world.elements[fooElement];
58 expect(fooAst.element, equals(fooElement));
59 FunctionElement barElement = functions['bar'];
60 expect(world.elements.keys, isNot(contains(functions[barElement])));
61 });
62 }
OLDNEW
« 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