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

Side by Side Diff: pkg/analyzer2dart/test/end2end_test.dart

Issue 548253003: First end-to-end capability in analyzer2dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. 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/test/driver_test.dart ('k') | pkg/analyzer2dart/test/tree_shaker_test.dart » ('j') | 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 /// End-to-end test of the analyzer2dart compiler.
6
7 import 'dart:async';
8
9 import 'mock_sdk.dart';
10 import 'package:analyzer/file_system/memory_file_system.dart';
11 import 'package:analyzer/src/generated/element.dart';
12 import 'package:analyzer/src/generated/sdk.dart';
13 import 'package:analyzer/src/generated/source.dart';
14 import 'package:compiler/implementation/dart_backend/backend_ast_to_frontend_ast .dart';
15 import 'package:unittest/unittest.dart';
16
17 import '../lib/src/closed_world.dart';
18 import '../lib/src/driver.dart';
19 import '../lib/src/converted_world.dart';
20 import '../lib/src/dart_backend.dart';
21
22 main() {
23 test('Empty main', () {
24 String expectedResult = '''
25 main() $NEW_BACKEND_COMMENT
26 {}
27
28 ''';
29 checkResult('''
30 main() {}''',
31 expectedResult);
32
33 checkResult('''
34 main() {}
35 foo() {}''',
36 expectedResult);
37 });
38
39 test('Simple call-chains', () {
40 checkResult('''
41 foo() {}
42 main() {
43 foo();
44 }
45 ''', '''
46 foo() $NEW_BACKEND_COMMENT
47 {}
48
49 main() $NEW_BACKEND_COMMENT
50 {
51 foo();
52 }
53
54 ''');
55
56 checkResult('''
57 bar() {}
58 foo() {
59 bar();
60 }
61 main() {
62 foo();
63 }
64 ''', '''
65 bar() $NEW_BACKEND_COMMENT
66 {}
67
68 foo() $NEW_BACKEND_COMMENT
69 {
70 bar();
71 }
72
73 main() $NEW_BACKEND_COMMENT
74 {
75 foo();
76 }
77
78 ''');
79
80 checkResult('''
81 bar() {
82 main();
83 }
84 foo() {
85 bar();
86 }
87 main() {
88 foo();
89 }
90 ''', '''
91 bar() $NEW_BACKEND_COMMENT
92 {
93 main();
94 }
95
96 foo() $NEW_BACKEND_COMMENT
97 {
98 bar();
99 }
100
101 main() $NEW_BACKEND_COMMENT
102 {
103 foo();
104 }
105
106 ''');
107 });
108 }
109
110 checkResult(String input, String expectedOutput) {
111 CollectingOutputProvider outputProvider = new CollectingOutputProvider();
112 MemoryResourceProvider provider = new MemoryResourceProvider();
113 DartSdk sdk = new MockSdk();
114 Driver driver = new Driver(provider, sdk, outputProvider);
115 String rootFile = '/root.dart';
116 provider.newFile(rootFile, input);
117 Source rootSource = driver.setRoot(rootFile);
118 FunctionElement entryPoint = driver.resolveEntryPoint(rootSource);
119 ClosedWorld world = driver.computeWorld(entryPoint);
120 ConvertedWorld convertedWorld = convertWorld(world);
121 compileToDart(driver, convertedWorld);
122 String output = outputProvider.output.text;
123 expect(output, equals(expectedOutput));
124 }
125
126 class CollectingOutputProvider {
127 StringBufferSink output;
128
129 EventSink<String> call(String name, String extension) {
130 print('outputProvider($name,$extension)');
131 return output = new StringBufferSink();
132 }
133 }
134
135 class StringBufferSink implements EventSink<String> {
136 StringBuffer sb = new StringBuffer();
137
138 void add(String text) {
139 sb.write(text);
140 }
141
142 void addError(errorEvent, [StackTrace stackTrace]) {}
143
144 void close() {}
145
146 String get text => sb.toString();
147 }
148
OLDNEW
« no previous file with comments | « pkg/analyzer2dart/test/driver_test.dart ('k') | pkg/analyzer2dart/test/tree_shaker_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698