OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 // TODO(jmesserly): merge into import_inliner_test.dart. | 5 // TODO(jmesserly): merge into import_inliner_test.dart. |
6 // Keeping here for now so it's easier to see the diff. | 6 // Keeping here for now so it's easier to see the diff. |
7 part of polymer.test.build.import_inliner_test; | 7 part of polymer.test.build.import_inliner_test; |
8 | 8 |
9 void codeExtractorTests() { | 9 void codeExtractorTests() { |
10 testPhases('no changes', phases, { | 10 testPhases('no changes', phases, { |
11 'a|web/test.html': '<!DOCTYPE html><html></html>', | 11 'a|web/test.html': '<!DOCTYPE html><html></html>', |
12 }, { | 12 }, { |
13 'a|web/test.html': '<!DOCTYPE html><html></html>', | 13 'a|web/test.html': '<!DOCTYPE html><html></html>', |
14 }); | 14 }); |
15 | 15 |
16 testPhases('single script, no library in script', phases, { | 16 testPhases('single script, no library in script', phases, { |
17 'a|web/test.html': | 17 'a|web/test.html': |
18 '<!DOCTYPE html><html><head>' | 18 '<!DOCTYPE html><html><head>' |
19 '<script type="application/dart">main() { }</script>', | 19 '<script type="application/dart">main() { }</script>', |
20 }, { | 20 }, { |
21 'a|web/test.html': | 21 'a|web/test.html': |
22 '<!DOCTYPE html><html><head></head><body>' | 22 '<!DOCTYPE html><html><head></head><body>' |
23 '<script type="application/dart" src="test.html.0.dart"></script>' | 23 '<script type="application/dart" src="test.html.0.dart"></script>' |
24 '</body></html>', | 24 '</body></html>', |
25 | 25 |
26 'a|web/test.html.0.dart': | 26 'a|web/test.html.0.dart': |
27 'library a.web.test_html;\nmain() { }', | 27 'library a.web.test_html_0;\nmain() { }', |
| 28 }); |
| 29 |
| 30 testPhases('component script, no library in script', phases, { |
| 31 'a|web/test.html': |
| 32 '<!DOCTYPE html><html><head>' |
| 33 '<script type="application/dart;component=1">main() { }</script>', |
| 34 }, { |
| 35 'a|web/test.html': |
| 36 '<!DOCTYPE html><html><head></head><body>' |
| 37 '</body></html>', |
| 38 |
| 39 'a|web/test.html.0.dart': |
| 40 'library a.web.test_html_0;\nmain() { }', |
28 }); | 41 }); |
29 | 42 |
30 testPhases('single script, with library', phases, { | 43 testPhases('single script, with library', phases, { |
31 'a|web/test.html': | 44 'a|web/test.html': |
32 '<!DOCTYPE html><html><head>' | 45 '<!DOCTYPE html><html><head>' |
33 '<script type="application/dart">library f;\nmain() { }</script>', | 46 '<script type="application/dart">library f;\nmain() { }</script>', |
34 }, { | 47 }, { |
35 'a|web/test.html': | 48 'a|web/test.html': |
36 '<!DOCTYPE html><html><head></head><body>' | 49 '<!DOCTYPE html><html><head></head><body>' |
37 '<script type="application/dart" src="test.html.0.dart"></script>' | 50 '<script type="application/dart" src="test.html.0.dart"></script>' |
38 '</body></html>', | 51 '</body></html>', |
39 | 52 |
40 'a|web/test.html.0.dart': | 53 'a|web/test.html.0.dart': |
41 'library f;\nmain() { }', | 54 'library f;\nmain() { }', |
42 }); | 55 }); |
43 | 56 |
44 testPhases('under lib/ directory not transformed', phases, { | 57 testPhases('under lib/ directory not transformed', phases, { |
45 'a|lib/test.html': | 58 'a|lib/test.html': |
46 '<!DOCTYPE html><html><head>' | 59 '<!DOCTYPE html><html><head>' |
47 '<script type="application/dart">library f;\nmain() { }</script>', | 60 '<script type="application/dart">library f;\nmain() { }</script>' |
| 61 '<script type="application/dart;component=1">' |
| 62 'library g;\nmain() { }</script>', |
48 }, { | 63 }, { |
49 'a|lib/test.html': | 64 'a|lib/test.html': |
50 '<!DOCTYPE html><html><head>' | 65 '<!DOCTYPE html><html><head>' |
51 '<script type="application/dart">library f;\nmain() { }</script>' | 66 '<script type="application/dart">library f;\nmain() { }</script>' |
| 67 '<script type="application/dart;component=1">' |
| 68 'library g;\nmain() { }</script>', |
52 }); | 69 }); |
53 | 70 |
54 testPhases('multiple scripts - only emit first', phases, { | 71 testPhases('multiple scripts allowed', phases, { |
55 'a|web/test.html': | 72 'a|web/test.html': |
56 '<!DOCTYPE html><html><head>' | 73 '<!DOCTYPE html><html><head>' |
57 '<script type="application/dart">library a1;\nmain1() { }</script>' | 74 '<script type="application/dart">library a1;\nmain1() { }</script>' |
58 '<script type="application/dart">library a2;\nmain2() { }</script>', | 75 '<script type="application/dart">library a2;\nmain2() { }</script>', |
59 }, { | 76 }, { |
60 'a|web/test.html': | 77 'a|web/test.html': |
61 '<!DOCTYPE html><html><head></head><body>' | 78 '<!DOCTYPE html><html><head></head><body>' |
62 '<script type="application/dart" src="test.html.0.dart"></script>' | 79 '<script type="application/dart" src="test.html.0.dart"></script>' |
| 80 '<script type="application/dart" src="test.html.1.dart"></script>' |
63 '</body></html>', | 81 '</body></html>', |
64 | 82 |
65 'a|web/test.html.0.dart': | 83 'a|web/test.html.0.dart': |
66 'library a1;\nmain1() { }', | 84 'library a1;\nmain1() { }', |
| 85 'a|web/test.html.1.dart': |
| 86 'library a2;\nmain2() { }', |
| 87 }); |
| 88 |
| 89 testPhases('component scripts removed', phases, { |
| 90 'a|web/test.html': |
| 91 '<!DOCTYPE html><html><head>' |
| 92 '<script type="application/dart;component=1">' |
| 93 'library a1;\nmain1() { }</script>' |
| 94 '<script type="application/dart;component=1">' |
| 95 'library a2;\nmain2() { }</script>', |
| 96 }, { |
| 97 'a|web/test.html': |
| 98 '<!DOCTYPE html><html><head></head><body>' |
| 99 '</body></html>', |
| 100 'a|web/test.html.scriptUrls': JSON.encode([ |
| 101 ["a", "web/test.html.0.dart"], |
| 102 ["a", "web/test.html.1.dart"]]), |
| 103 'a|web/test.html.0.dart': |
| 104 'library a1;\nmain1() { }', |
| 105 'a|web/test.html.1.dart': |
| 106 'library a2;\nmain2() { }', |
67 }); | 107 }); |
68 | 108 |
69 testPhases('multiple deeper scripts', phases, { | 109 testPhases('multiple deeper scripts', phases, { |
70 'a|web/test.html': | 110 'a|web/test.html': |
71 '<!DOCTYPE html><html><head>' | 111 '<!DOCTYPE html><html><head>' |
72 '<script type="application/dart">main1() { }</script>' | 112 '<script type="application/dart">main1() { }</script>' |
73 '</head><body><div>' | 113 '</head><body><div>' |
74 '<script type="application/dart">main2() { }</script>' | 114 '<script type="application/dart">main2() { }</script>' |
75 '</div><div><div>' | 115 '</div><div><div>' |
76 '<script type="application/dart">main3() { }</script>' | 116 '<script type="application/dart">main3() { }</script>' |
77 '</div></div>' | 117 '</div></div>' |
78 }, { | 118 }, { |
79 'a|web/test.html': | 119 'a|web/test.html': |
80 '<!DOCTYPE html><html><head>' | 120 '<!DOCTYPE html><html><head>' |
81 '</head><body>' | 121 '</head><body>' |
82 '<script type="application/dart" src="test.html.0.dart"></script>' | 122 '<script type="application/dart" src="test.html.0.dart"></script>' |
83 '<div></div><div><div>' | 123 '<div>' |
| 124 '<script type="application/dart" src="test.html.1.dart"></script>' |
| 125 '</div><div><div>' |
| 126 '<script type="application/dart" src="test.html.2.dart"></script>' |
84 '</div></div></body></html>', | 127 '</div></div></body></html>', |
85 | 128 |
86 'a|web/test.html.0.dart': | 129 'a|web/test.html.0.dart': |
87 'library a.web.test_html;\nmain1() { }', | 130 'library a.web.test_html_0;\nmain1() { }', |
| 131 'a|web/test.html.1.dart': |
| 132 'library a.web.test_html_1;\nmain2() { }', |
| 133 'a|web/test.html.2.dart': |
| 134 'library a.web.test_html_2;\nmain3() { }', |
88 }); | 135 }); |
89 | 136 |
90 testPhases('multiple imported scripts', phases, { | 137 testPhases('multiple imported scripts', phases, { |
91 'a|web/test.html': | 138 'a|web/test.html': |
92 '<link rel="import" href="test2.html">' | 139 '<link rel="import" href="test2.html">' |
93 '<link rel="import" href="bar/test.html">' | 140 '<link rel="import" href="bar/test.html">' |
94 '<link rel="import" href="packages/a/foo/test.html">' | 141 '<link rel="import" href="packages/a/foo/test.html">' |
95 '<link rel="import" href="packages/b/test.html">', | 142 '<link rel="import" href="packages/b/test.html">', |
96 'a|web/test2.html': | 143 'a|web/test2.html': |
97 '<script type="application/dart">main1() { }', | 144 '<script type="application/dart;component=1">main1() { }', |
98 'a|web/bar/test.html': | 145 'a|web/bar/test.html': |
99 '<script type="application/dart">main2() { }', | 146 '<script type="application/dart;component=1">main2() { }', |
100 'a|lib/foo/test.html': | 147 'a|lib/foo/test.html': |
101 '<script type="application/dart">main3() { }', | 148 '<script type="application/dart;component=1">main3() { }', |
102 'b|lib/test.html': | 149 'b|lib/test.html': |
103 '<script type="application/dart">main4() { }' | 150 '<script type="application/dart;component=1">main4() { }' |
104 }, { | 151 }, { |
105 'a|web/test.html': | 152 'a|web/test.html': |
106 '<html><head></head><body></body></html>', | 153 '<html><head></head><body></body></html>', |
107 'a|web/test.html.scriptUrls': JSON.encode([ | 154 'a|web/test.html.scriptUrls': JSON.encode([ |
108 ["a", "web/test.html.0.dart"], | 155 ["a", "web/test.html.0.dart"], |
109 ["a", "web/test.html.1.dart"], | 156 ["a", "web/test.html.1.dart"], |
110 ["a", "web/test.html.2.dart"], | 157 ["a", "web/test.html.2.dart"], |
111 ["a", "web/test.html.3.dart"], | 158 ["a", "web/test.html.3.dart"], |
112 ]), | 159 ]), |
113 'a|web/test.html.0.dart': 'library a.web.test2_html;\nmain1() { }', | 160 'a|web/test.html.0.dart': 'library a.web.test2_html_0;\nmain1() { }', |
114 'a|web/test.html.1.dart': 'library a.web.bar.test_html;\nmain2() { }', | 161 'a|web/test.html.1.dart': 'library a.web.bar.test_html_1;\nmain2() { }', |
115 'a|web/test.html.2.dart': 'library a.foo.test_html;\nmain3() { }', | 162 'a|web/test.html.2.dart': 'library a.foo.test_html_2;\nmain3() { }', |
116 'a|web/test.html.3.dart': 'library b.test_html;\nmain4() { }' | 163 'a|web/test.html.3.dart': 'library b.test_html_3;\nmain4() { }' |
117 }); | 164 }); |
118 | 165 |
119 group('fixes import/export/part URIs', dartUriTests); | 166 group('fixes import/export/part URIs', dartUriTests); |
120 } | 167 } |
121 | 168 |
122 dartUriTests() { | 169 dartUriTests() { |
123 | 170 |
124 testPhases('from web folder', phases, { | 171 testPhases('from web folder', phases, { |
125 'a|web/test.html': | 172 'a|web/test.html': |
126 '<!DOCTYPE html><html><head>' | 173 '<!DOCTYPE html><html><head>' |
127 '<link rel="import" href="test2/foo.html">' | 174 '<link rel="import" href="test2/foo.html">' |
128 '</head><body></body></html>', | 175 '</head><body></body></html>', |
129 'a|web/test2/foo.html': | 176 'a|web/test2/foo.html': |
130 '<!DOCTYPE html><html><head></head><body>' | 177 '<!DOCTYPE html><html><head></head><body>' |
131 '<script type="application/dart">' | 178 '<script type="application/dart">' |
132 "import 'package:qux/qux.dart';" | 179 "import 'package:qux/qux.dart';" |
133 "import 'foo.dart';" | 180 "import 'foo.dart';" |
134 "export 'bar.dart';" | 181 "export 'bar.dart';" |
135 "part 'baz.dart';" | 182 "part 'baz.dart';" |
136 '</script>' | 183 '</script>' |
137 '</body></html>', | 184 '</body></html>', |
138 }, { | 185 }, { |
139 'a|web/test.html': | 186 'a|web/test.html': |
140 '<!DOCTYPE html><html><head></head><body></body></html>', | 187 '<!DOCTYPE html><html><head></head><body>' |
141 'a|web/test.html.scriptUrls': '[["a","web/test.html.0.dart"]]', | 188 '<script type="application/dart" src="test.html.0.dart"></script>' |
| 189 '</body></html>', |
| 190 'a|web/test.html.scriptUrls': '[]', |
142 'a|web/test.html.0.dart': | 191 'a|web/test.html.0.dart': |
143 "library a.web.test2.foo_html;\n" | 192 "library a.web.test2.foo_html_0;\n" |
144 "import 'package:qux/qux.dart';" | 193 "import 'package:qux/qux.dart';" |
145 "import 'test2/foo.dart';" | 194 "import 'test2/foo.dart';" |
146 "export 'test2/bar.dart';" | 195 "export 'test2/bar.dart';" |
147 "part 'test2/baz.dart';", | 196 "part 'test2/baz.dart';", |
148 'a|web/test2/foo.html': | 197 'a|web/test2/foo.html': |
149 '<!DOCTYPE html><html><head></head><body>' | 198 '<!DOCTYPE html><html><head></head><body>' |
150 '<script type="application/dart" src="foo.html.0.dart"></script>' | 199 '<script type="application/dart" src="foo.html.0.dart"></script>' |
151 '</body></html>', | 200 '</body></html>', |
152 'a|web/test2/foo.html.scriptUrls': '[]', | 201 'a|web/test2/foo.html.scriptUrls': '[]', |
153 'a|web/test2/foo.html.0.dart': | 202 'a|web/test2/foo.html.0.dart': |
154 "library a.web.test2.foo_html;\n" | 203 "library a.web.test2.foo_html_0;\n" |
155 "import 'package:qux/qux.dart';" | 204 "import 'package:qux/qux.dart';" |
156 "import 'foo.dart';" | 205 "import 'foo.dart';" |
157 "export 'bar.dart';" | 206 "export 'bar.dart';" |
| 207 "part 'baz.dart';", |
| 208 }); |
| 209 |
| 210 testPhases('from web folder, component', phases, { |
| 211 'a|web/test.html': |
| 212 '<!DOCTYPE html><html><head>' |
| 213 '<link rel="import" href="test2/foo.html">' |
| 214 '</head><body></body></html>', |
| 215 'a|web/test2/foo.html': |
| 216 '<!DOCTYPE html><html><head></head><body>' |
| 217 '<script type="application/dart;component=1">' |
| 218 "import 'package:qux/qux.dart';" |
| 219 "import 'foo.dart';" |
| 220 "export 'bar.dart';" |
| 221 "part 'baz.dart';" |
| 222 '</script>' |
| 223 '</body></html>', |
| 224 }, { |
| 225 'a|web/test.html': |
| 226 '<!DOCTYPE html><html><head></head><body></body></html>', |
| 227 'a|web/test.html.scriptUrls': '[["a","web/test.html.0.dart"]]', |
| 228 'a|web/test.html.0.dart': |
| 229 "library a.web.test2.foo_html_0;\n" |
| 230 "import 'package:qux/qux.dart';" |
| 231 "import 'test2/foo.dart';" |
| 232 "export 'test2/bar.dart';" |
| 233 "part 'test2/baz.dart';", |
| 234 'a|web/test2/foo.html': |
| 235 '<!DOCTYPE html><html><head></head><body></body></html>', |
| 236 'a|web/test2/foo.html.scriptUrls': '[["a","web/test2/foo.html.0.dart"]]', |
| 237 'a|web/test2/foo.html.0.dart': |
| 238 "library a.web.test2.foo_html_0;\n" |
| 239 "import 'package:qux/qux.dart';" |
| 240 "import 'foo.dart';" |
| 241 "export 'bar.dart';" |
158 "part 'baz.dart';", | 242 "part 'baz.dart';", |
159 }); | 243 }); |
160 | 244 |
161 testPhases('from lib folder', phases, { | 245 testPhases('from lib folder', phases, { |
162 'a|web/test.html': | 246 'a|web/test.html': |
163 '<!DOCTYPE html><html><head>' | 247 '<!DOCTYPE html><html><head>' |
164 '<link rel="import" href="packages/a/test2/foo.html">' | 248 '<link rel="import" href="packages/a/test2/foo.html">' |
165 '</head><body></body></html>', | 249 '</head><body></body></html>', |
166 'a|lib/test2/foo.html': | 250 'a|lib/test2/foo.html': |
167 '<!DOCTYPE html><html><head></head><body>' | 251 '<!DOCTYPE html><html><head></head><body>' |
168 '<script type="application/dart">' | 252 '<script type="application/dart;component=1">' |
169 "import 'package:qux/qux.dart';" | 253 "import 'package:qux/qux.dart';" |
170 "import 'foo.dart';" | 254 "import 'foo.dart';" |
171 "export 'bar.dart';" | 255 "export 'bar.dart';" |
172 "part 'baz.dart';" | 256 "part 'baz.dart';" |
173 '</script>' | 257 '</script>' |
174 '</body></html>', | 258 '</body></html>', |
175 }, { | 259 }, { |
176 'a|web/test.html': | 260 'a|web/test.html': |
177 '<!DOCTYPE html><html><head></head><body></body></html>', | 261 '<!DOCTYPE html><html><head></head><body></body></html>', |
178 'a|web/test.html.scriptUrls': '[["a","web/test.html.0.dart"]]', | 262 'a|web/test.html.scriptUrls': '[["a","web/test.html.0.dart"]]', |
179 'a|web/test.html.0.dart': | 263 'a|web/test.html.0.dart': |
180 "library a.test2.foo_html;\n" | 264 "library a.test2.foo_html_0;\n" |
181 "import 'package:qux/qux.dart';" | 265 "import 'package:qux/qux.dart';" |
182 "import 'package:a/test2/foo.dart';" | 266 "import 'package:a/test2/foo.dart';" |
183 "export 'package:a/test2/bar.dart';" | 267 "export 'package:a/test2/bar.dart';" |
184 "part 'package:a/test2/baz.dart';", | 268 "part 'package:a/test2/baz.dart';", |
185 'a|lib/test2/foo.html': | 269 'a|lib/test2/foo.html': |
186 '<!DOCTYPE html><html><head></head><body>' | 270 '<!DOCTYPE html><html><head></head><body>' |
187 '<script type="application/dart">' | 271 '<script type="application/dart;component=1">' |
188 "import 'package:qux/qux.dart';" | 272 "import 'package:qux/qux.dart';" |
189 "import 'foo.dart';" | 273 "import 'foo.dart';" |
190 "export 'bar.dart';" | 274 "export 'bar.dart';" |
191 "part 'baz.dart';" | 275 "part 'baz.dart';" |
192 '</script>' | 276 '</script>' |
193 '</body></html>', | 277 '</body></html>', |
194 }); | 278 }); |
195 | 279 |
196 testPhases('from another pkg', phases, { | 280 testPhases('from another pkg', phases, { |
197 'a|web/test.html': | 281 'a|web/test.html': |
198 '<!DOCTYPE html><html><head>' | 282 '<!DOCTYPE html><html><head>' |
199 '<link rel="import" href="packages/b/test2/foo.html">' | 283 '<link rel="import" href="packages/b/test2/foo.html">' |
200 '</head><body></body></html>', | 284 '</head><body></body></html>', |
201 'b|lib/test2/foo.html': | 285 'b|lib/test2/foo.html': |
202 '<!DOCTYPE html><html><head></head><body>' | 286 '<!DOCTYPE html><html><head></head><body>' |
203 '<script type="application/dart">' | 287 '<script type="application/dart;component=1">' |
204 "import 'package:qux/qux.dart';" | 288 "import 'package:qux/qux.dart';" |
205 "import 'foo.dart';" | 289 "import 'foo.dart';" |
206 "export 'bar.dart';" | 290 "export 'bar.dart';" |
207 "part 'baz.dart';" | 291 "part 'baz.dart';" |
208 '</script>' | 292 '</script>' |
209 '</body></html>', | 293 '</body></html>', |
210 }, { | 294 }, { |
211 'a|web/test.html': | 295 'a|web/test.html': |
212 '<!DOCTYPE html><html><head></head><body></body></html>', | 296 '<!DOCTYPE html><html><head></head><body></body></html>', |
213 'a|web/test.html.scriptUrls': '[["a","web/test.html.0.dart"]]', | 297 'a|web/test.html.scriptUrls': '[["a","web/test.html.0.dart"]]', |
214 'a|web/test.html.0.dart': | 298 'a|web/test.html.0.dart': |
215 "library b.test2.foo_html;\n" | 299 "library b.test2.foo_html_0;\n" |
216 "import 'package:qux/qux.dart';" | 300 "import 'package:qux/qux.dart';" |
217 "import 'package:b/test2/foo.dart';" | 301 "import 'package:b/test2/foo.dart';" |
218 "export 'package:b/test2/bar.dart';" | 302 "export 'package:b/test2/bar.dart';" |
219 "part 'package:b/test2/baz.dart';", | 303 "part 'package:b/test2/baz.dart';", |
220 'b|lib/test2/foo.html': | 304 'b|lib/test2/foo.html': |
221 '<!DOCTYPE html><html><head></head><body>' | 305 '<!DOCTYPE html><html><head></head><body>' |
222 '<script type="application/dart">' | 306 '<script type="application/dart;component=1">' |
223 "import 'package:qux/qux.dart';" | 307 "import 'package:qux/qux.dart';" |
224 "import 'foo.dart';" | 308 "import 'foo.dart';" |
225 "export 'bar.dart';" | 309 "export 'bar.dart';" |
226 "part 'baz.dart';" | 310 "part 'baz.dart';" |
227 '</script>' | 311 '</script>' |
228 '</body></html>', | 312 '</body></html>', |
229 }); | 313 }); |
230 } | 314 } |
OLD | NEW |