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

Side by Side Diff: pkg/polymer/test/build/code_extractor.dart

Issue 180933002: combine script extractor and import inliner (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix multiple linked scripts Created 6 years, 9 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
OLDNEW
(Empty)
1 // Copyright (c) 2013, 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 // TODO(jmesserly): merge into import_inliner_test.dart.
6 // Keeping here for now so it's easier to see the diff.
7 part of polymer.test.build.import_inliner_test;
8
9 void codeExtractorTests() {
10 testPhases('no changes', phases, {
11 'a|web/test.html': '<!DOCTYPE html><html></html>',
12 }, {
13 'a|web/test.html': '<!DOCTYPE html><html></html>',
14 });
15
16 testPhases('single script, no library in script', phases, {
17 'a|web/test.html':
18 '<!DOCTYPE html><html><head>'
19 '<script type="application/dart">main() { }</script>',
20 }, {
21 'a|web/test.html':
22 '<!DOCTYPE html><html><head></head><body>'
23 '<script type="application/dart" src="test.html.0.dart"></script>'
24 '</body></html>',
25
26 'a|web/test.html.0.dart':
27 'library a.web.test_html;\nmain() { }',
28 });
29
30 testPhases('single script, with library', phases, {
31 'a|web/test.html':
32 '<!DOCTYPE html><html><head>'
33 '<script type="application/dart">library f;\nmain() { }</script>',
34 }, {
35 'a|web/test.html':
36 '<!DOCTYPE html><html><head></head><body>'
37 '<script type="application/dart" src="test.html.0.dart"></script>'
38 '</body></html>',
39
40 'a|web/test.html.0.dart':
41 'library f;\nmain() { }',
42 });
43
44 testPhases('under lib/ directory not transformed', phases, {
45 'a|lib/test.html':
46 '<!DOCTYPE html><html><head>'
47 '<script type="application/dart">library f;\nmain() { }</script>',
48 }, {
49 'a|lib/test.html':
50 '<!DOCTYPE html><html><head>'
51 '<script type="application/dart">library f;\nmain() { }</script>'
52 });
53
54 testPhases('multiple scripts - only emit first', phases, {
55 'a|web/test.html':
56 '<!DOCTYPE html><html><head>'
57 '<script type="application/dart">library a1;\nmain1() { }</script>'
58 '<script type="application/dart">library a2;\nmain2() { }</script>',
59 }, {
60 'a|web/test.html':
61 '<!DOCTYPE html><html><head></head><body>'
62 '<script type="application/dart" src="test.html.0.dart"></script>'
63 '</body></html>',
64
65 'a|web/test.html.0.dart':
66 'library a1;\nmain1() { }',
67 });
68
69 testPhases('multiple deeper scripts', phases, {
70 'a|web/test.html':
71 '<!DOCTYPE html><html><head>'
72 '<script type="application/dart">main1() { }</script>'
73 '</head><body><div>'
74 '<script type="application/dart">main2() { }</script>'
75 '</div><div><div>'
76 '<script type="application/dart">main3() { }</script>'
77 '</div></div>'
78 }, {
79 'a|web/test.html':
80 '<!DOCTYPE html><html><head>'
81 '</head><body>'
82 '<script type="application/dart" src="test.html.0.dart"></script>'
83 '<div></div><div><div>'
84 '</div></div></body></html>',
85
86 'a|web/test.html.0.dart':
87 'library a.web.test_html;\nmain1() { }',
88 });
89
90 testPhases('multiple imported scripts', phases, {
91 'a|web/test.html':
92 '<link rel="import" href="test2.html">'
93 '<link rel="import" href="bar/test.html">'
94 '<link rel="import" href="packages/a/foo/test.html">'
95 '<link rel="import" href="packages/b/test.html">',
96 'a|web/test2.html':
97 '<script type="application/dart">main1() { }',
98 'a|web/bar/test.html':
99 '<script type="application/dart">main2() { }',
100 'a|lib/foo/test.html':
101 '<script type="application/dart">main3() { }',
102 'b|lib/test.html':
103 '<script type="application/dart">main4() { }'
104 }, {
105 'a|web/test.html':
106 '<html><head></head><body></body></html>',
107 'a|web/test.html.scriptUrls': JSON.encode([
108 ["a", "web/test.html.0.dart"],
109 ["a", "web/test.html.1.dart"],
110 ["a", "web/test.html.2.dart"],
111 ["a", "web/test.html.3.dart"],
112 ]),
113 'a|web/test.html.0.dart': 'library a.web.test2_html;\nmain1() { }',
114 'a|web/test.html.1.dart': 'library a.web.bar.test_html;\nmain2() { }',
115 'a|web/test.html.2.dart': 'library a.foo.test_html;\nmain3() { }',
116 'a|web/test.html.3.dart': 'library b.test_html;\nmain4() { }'
117 });
118
119 group('fixes import/export/part URIs', dartUriTests);
120 }
121
122 dartUriTests() {
123
124 testPhases('from web folder', phases, {
125 'a|web/test.html':
126 '<!DOCTYPE html><html><head>'
127 '<link rel="import" href="test2/foo.html">'
128 '</head><body></body></html>',
129 'a|web/test2/foo.html':
130 '<!DOCTYPE html><html><head></head><body>'
131 '<script type="application/dart">'
132 "import 'package:qux/qux.dart';"
133 "import 'foo.dart';"
134 "export 'bar.dart';"
135 "part 'baz.dart';"
136 '</script>'
137 '</body></html>',
138 }, {
139 'a|web/test.html':
140 '<!DOCTYPE html><html><head></head><body></body></html>',
141 'a|web/test.html.scriptUrls': '[["a","web/test.html.0.dart"]]',
142 'a|web/test.html.0.dart':
143 "library a.web.test2.foo_html;\n"
144 "import 'package:qux/qux.dart';"
145 "import 'test2/foo.dart';"
146 "export 'test2/bar.dart';"
147 "part 'test2/baz.dart';",
148 'a|web/test2/foo.html':
149 '<!DOCTYPE html><html><head></head><body>'
150 '<script type="application/dart" src="foo.html.0.dart"></script>'
151 '</body></html>',
152 'a|web/test2/foo.html.scriptUrls': '[]',
153 'a|web/test2/foo.html.0.dart':
154 "library a.web.test2.foo_html;\n"
155 "import 'package:qux/qux.dart';"
156 "import 'foo.dart';"
157 "export 'bar.dart';"
158 "part 'baz.dart';",
159 });
160
161 testPhases('from lib folder', phases, {
162 'a|web/test.html':
163 '<!DOCTYPE html><html><head>'
164 '<link rel="import" href="packages/a/test2/foo.html">'
165 '</head><body></body></html>',
166 'a|lib/test2/foo.html':
167 '<!DOCTYPE html><html><head></head><body>'
168 '<script type="application/dart">'
169 "import 'package:qux/qux.dart';"
170 "import 'foo.dart';"
171 "export 'bar.dart';"
172 "part 'baz.dart';"
173 '</script>'
174 '</body></html>',
175 }, {
176 'a|web/test.html':
177 '<!DOCTYPE html><html><head></head><body></body></html>',
178 'a|web/test.html.scriptUrls': '[["a","web/test.html.0.dart"]]',
179 'a|web/test.html.0.dart':
180 "library a.test2.foo_html;\n"
181 "import 'package:qux/qux.dart';"
182 "import 'package:a/test2/foo.dart';"
183 "export 'package:a/test2/bar.dart';"
184 "part 'package:a/test2/baz.dart';",
185 'a|lib/test2/foo.html':
186 '<!DOCTYPE html><html><head></head><body>'
187 '<script type="application/dart">'
188 "import 'package:qux/qux.dart';"
189 "import 'foo.dart';"
190 "export 'bar.dart';"
191 "part 'baz.dart';"
192 '</script>'
193 '</body></html>',
194 });
195
196 testPhases('from another pkg', phases, {
197 'a|web/test.html':
198 '<!DOCTYPE html><html><head>'
199 '<link rel="import" href="packages/b/test2/foo.html">'
200 '</head><body></body></html>',
201 'b|lib/test2/foo.html':
202 '<!DOCTYPE html><html><head></head><body>'
203 '<script type="application/dart">'
204 "import 'package:qux/qux.dart';"
205 "import 'foo.dart';"
206 "export 'bar.dart';"
207 "part 'baz.dart';"
208 '</script>'
209 '</body></html>',
210 }, {
211 'a|web/test.html':
212 '<!DOCTYPE html><html><head></head><body></body></html>',
213 'a|web/test.html.scriptUrls': '[["a","web/test.html.0.dart"]]',
214 'a|web/test.html.0.dart':
215 "library b.test2.foo_html;\n"
216 "import 'package:qux/qux.dart';"
217 "import 'package:b/test2/foo.dart';"
218 "export 'package:b/test2/bar.dart';"
219 "part 'package:b/test2/baz.dart';",
220 'b|lib/test2/foo.html':
221 '<!DOCTYPE html><html><head></head><body>'
222 '<script type="application/dart">'
223 "import 'package:qux/qux.dart';"
224 "import 'foo.dart';"
225 "export 'bar.dart';"
226 "part 'baz.dart';"
227 '</script>'
228 '</body></html>',
229 });
230 }
OLDNEW
« no previous file with comments | « pkg/polymer/test/build/all_phases_test.dart ('k') | pkg/polymer/test/build/code_extractor_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698