| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 @TestOn('vm') |
| 4 library web_components.test.build.script_compactor_test; | 5 library web_components.test.build.script_compactor_test; |
| 5 | 6 |
| 6 import 'package:code_transformers/tests.dart'; | 7 import 'package:transformer_test/utils.dart'; |
| 7 import 'package:web_components/build/messages.dart'; | 8 import 'package:web_components/build/messages.dart'; |
| 8 import 'package:web_components/build/script_compactor.dart'; | 9 import 'package:web_components/build/script_compactor.dart'; |
| 9 import 'package:unittest/compact_vm_config.dart'; | 10 import 'package:test/test.dart'; |
| 10 import 'package:unittest/unittest.dart'; | |
| 11 | 11 |
| 12 var transformer = new ScriptCompactorTransformer(); | 12 var transformer = new ScriptCompactorTransformer(); |
| 13 var phases = [[transformer]]; | 13 var phases = [ |
| 14 [transformer] |
| 15 ]; |
| 14 | 16 |
| 15 main() { | 17 main() { |
| 16 useCompactVMConfiguration(); | |
| 17 | |
| 18 group('basic', basicTests); | 18 group('basic', basicTests); |
| 19 group('code extraction tests', codeExtractorTests); | 19 group('code extraction tests', codeExtractorTests); |
| 20 group('fixes import/export/part URIs', dartUriTests); | 20 group('fixes import/export/part URIs', dartUriTests); |
| 21 group('validates script-tag URIs', validateUriTests); | 21 group('validates script-tag URIs', validateUriTests); |
| 22 } | 22 } |
| 23 | 23 |
| 24 void basicTests() { | 24 void basicTests() { |
| 25 testPhases('single script', phases, { | 25 testPhases( |
| 26 'a|web/index.html': ''' | 26 'single script', |
| 27 phases, |
| 28 { |
| 29 'a|web/index.html': ''' |
| 27 <!DOCTYPE html><html><head></head><body> | 30 <!DOCTYPE html><html><head></head><body> |
| 28 <script type="application/dart" src="index.dart"></script> | 31 <script type="application/dart" src="index.dart"></script> |
| 29 </body></html>''', | 32 </body></html>''', |
| 30 'a|web/index.dart': ''' | 33 'a|web/index.dart': ''' |
| 31 library a.index; | 34 library a.index; |
| 32 main(){}''', | 35 main(){}''', |
| 33 }, { | 36 }, |
| 34 'a|web/index.html': ''' | 37 { |
| 38 'a|web/index.html': ''' |
| 35 <!DOCTYPE html><html><head></head><body> | 39 <!DOCTYPE html><html><head></head><body> |
| 36 <script type="application/dart" src="index.bootstrap.dart"></script> | 40 <script type="application/dart" src="index.bootstrap.dart"></script> |
| 37 </body></html>''', | 41 </body></html>''', |
| 38 'a|web/index.bootstrap.dart': ''' | 42 'a|web/index.bootstrap.dart': ''' |
| 39 library a.web.index_bootstrap_dart; | 43 library a.web.index_bootstrap_dart; |
| 40 | 44 |
| 41 import 'index.dart' as i0; | 45 import 'index.dart' as i0; |
| 42 | 46 |
| 43 main() => i0.main();''', | 47 main() => i0.main();''', |
| 44 'a|web/index.dart': ''' | 48 'a|web/index.dart': ''' |
| 45 library a.index; | 49 library a.index; |
| 46 main(){}''', | 50 main(){}''', |
| 47 }, [], StringFormatter.noNewlinesOrSurroundingWhitespace); | 51 }, |
| 52 messages: [], |
| 53 formatter: StringFormatter.noNewlinesOrSurroundingWhitespace); |
| 48 | 54 |
| 49 testPhases('multiple scripts from nested html import', phases, { | 55 testPhases( |
| 50 'a|web/index.html': ''' | 56 'multiple scripts from nested html import', |
| 57 phases, |
| 58 { |
| 59 'a|web/index.html': ''' |
| 51 <!DOCTYPE html><html> | 60 <!DOCTYPE html><html> |
| 52 <head> | 61 <head> |
| 53 <link rel="import" href="packages/b/a.html"> | 62 <link rel="import" href="packages/b/a.html"> |
| 54 </head> | 63 </head> |
| 55 <body> | 64 <body> |
| 56 <script type="application/dart" src="index.dart"></script> | 65 <script type="application/dart" src="index.dart"></script> |
| 57 </body> | 66 </body> |
| 58 </body></html>''', | 67 </body></html>''', |
| 59 'a|web/index.dart': ''' | 68 'a|web/index.dart': ''' |
| 60 library a.index; | 69 library a.index; |
| 61 main(){}''', | 70 main(){}''', |
| 62 'b|lib/a.html': ''' | 71 'b|lib/a.html': ''' |
| 63 <link rel="import" href="b/b.html"> | 72 <link rel="import" href="b/b.html"> |
| 64 <link rel="import" href="../../packages/c/c.html"> | 73 <link rel="import" href="../../packages/c/c.html"> |
| 65 <script type="application/dart" src="a.dart"></script>''', | 74 <script type="application/dart" src="a.dart"></script>''', |
| 66 'b|lib/b/b.html': '<script type="application/dart" src="b.dart"></script>', | 75 'b|lib/b/b.html': |
| 67 'b|lib/a.dart': 'library b.a;', | 76 '<script type="application/dart" src="b.dart"></script>', |
| 68 'b|lib/b/b.dart': 'library b.b.b;', | 77 'b|lib/a.dart': 'library b.a;', |
| 69 'c|lib/c.html': '<script type="application/dart" src="c.dart"></script>', | 78 'b|lib/b/b.dart': 'library b.b.b;', |
| 70 'c|lib/c.dart': 'library c.c;', | 79 'c|lib/c.html': |
| 71 }, { | 80 '<script type="application/dart" src="c.dart"></script>', |
| 72 'a|web/index.html': ''' | 81 'c|lib/c.dart': 'library c.c;', |
| 82 }, |
| 83 { |
| 84 'a|web/index.html': ''' |
| 73 <!DOCTYPE html><html> | 85 <!DOCTYPE html><html> |
| 74 <head> | 86 <head> |
| 75 <link rel="import" href="packages/b/a.html"> | 87 <link rel="import" href="packages/b/a.html"> |
| 76 </head> | 88 </head> |
| 77 <body> | 89 <body> |
| 78 <script type="application/dart" src="index.bootstrap.dart"></script> | 90 <script type="application/dart" src="index.bootstrap.dart"></script> |
| 79 </body></html>''', | 91 </body></html>''', |
| 80 'a|web/index.bootstrap.dart': ''' | 92 'a|web/index.bootstrap.dart': ''' |
| 81 library a.web.index_bootstrap_dart; | 93 library a.web.index_bootstrap_dart; |
| 82 | 94 |
| 83 import 'package:b/b/b.dart' as i0; | 95 import 'package:b/b/b.dart' as i0; |
| 84 import 'package:c/c.dart' as i1; | 96 import 'package:c/c.dart' as i1; |
| 85 import 'package:b/a.dart' as i2; | 97 import 'package:b/a.dart' as i2; |
| 86 import 'index.dart' as i3; | 98 import 'index.dart' as i3; |
| 87 | 99 |
| 88 main() => i3.main();''', | 100 main() => i3.main();''', |
| 89 'b|lib/a.html': ''' | 101 'b|lib/a.html': ''' |
| 90 <link rel="import" href="b/b.html"> | 102 <link rel="import" href="b/b.html"> |
| 91 <link rel="import" href="../../packages/c/c.html"> | 103 <link rel="import" href="../../packages/c/c.html"> |
| 92 <script type="application/dart" src="a.dart"></script>''', | 104 <script type="application/dart" src="a.dart"></script>''', |
| 93 }, [], StringFormatter.noNewlinesOrSurroundingWhitespace); | 105 }, |
| 106 messages: [], |
| 107 formatter: StringFormatter.noNewlinesOrSurroundingWhitespace); |
| 94 | 108 |
| 95 testPhases('inline scripts', phases, { | 109 testPhases( |
| 96 'a|web/index.html': ''' | 110 'inline scripts', |
| 111 phases, |
| 112 { |
| 113 'a|web/index.html': ''' |
| 97 <!DOCTYPE html> | 114 <!DOCTYPE html> |
| 98 <html> | 115 <html> |
| 99 <head> | 116 <head> |
| 100 <link rel="import" href="packages/a/foo.html"> | 117 <link rel="import" href="packages/a/foo.html"> |
| 101 </head> | 118 </head> |
| 102 <body> | 119 <body> |
| 103 <script type="application/dart"> | 120 <script type="application/dart"> |
| 104 library a.index; | 121 library a.index; |
| 105 main(){} | 122 main(){} |
| 106 </script> | 123 </script> |
| 107 </body> | 124 </body> |
| 108 </html>''', | 125 </html>''', |
| 109 'a|lib/foo.html': ''' | 126 'a|lib/foo.html': ''' |
| 110 <script type="application/dart"> | 127 <script type="application/dart"> |
| 111 library a.foo; | 128 library a.foo; |
| 112 | 129 |
| 113 import 'bar.dart'; | 130 import 'bar.dart'; |
| 114 </script>''', | 131 </script>''', |
| 115 }, { | 132 }, |
| 116 'a|web/index.html': ''' | 133 { |
| 134 'a|web/index.html': ''' |
| 117 <!DOCTYPE html> | 135 <!DOCTYPE html> |
| 118 <html> | 136 <html> |
| 119 <head> | 137 <head> |
| 120 <link rel="import" href="packages/a/foo.html"> | 138 <link rel="import" href="packages/a/foo.html"> |
| 121 </head> | 139 </head> |
| 122 <body> | 140 <body> |
| 123 <script type="application/dart" src="index.bootstrap.dart"></script> | 141 <script type="application/dart" src="index.bootstrap.dart"></script> |
| 124 </body> | 142 </body> |
| 125 </html>''', | 143 </html>''', |
| 126 'a|web/index.html.1.dart': ''' | 144 'a|web/index.html.1.dart': ''' |
| 127 library a.index; | 145 library a.index; |
| 128 main(){}''', | 146 main(){}''', |
| 129 'a|web/index.html.0.dart': ''' | 147 'a|web/index.html.0.dart': ''' |
| 130 library a.foo; | 148 library a.foo; |
| 131 | 149 |
| 132 import 'package:a/bar.dart';''', | 150 import 'package:a/bar.dart';''', |
| 133 'a|web/index.bootstrap.dart': ''' | 151 'a|web/index.bootstrap.dart': ''' |
| 134 library a.web.index_bootstrap_dart; | 152 library a.web.index_bootstrap_dart; |
| 135 | 153 |
| 136 import 'index.html.0.dart' as i0; | 154 import 'index.html.0.dart' as i0; |
| 137 import 'index.html.1.dart' as i1; | 155 import 'index.html.1.dart' as i1; |
| 138 | 156 |
| 139 main() => i1.main();''', | 157 main() => i1.main();''', |
| 140 }, [], StringFormatter.noNewlinesOrSurroundingWhitespace); | 158 }, |
| 141 | 159 messages: [], |
| 142 testPhases('Cleans library names generated from file paths.', phases, { | 160 formatter: StringFormatter.noNewlinesOrSurroundingWhitespace); |
| 143 'a|web/01_test.html': ''' | 161 |
| 162 testPhases( |
| 163 'Cleans library names generated from file paths.', |
| 164 phases, |
| 165 { |
| 166 'a|web/01_test.html': ''' |
| 144 <!DOCTYPE html><html><head> | 167 <!DOCTYPE html><html><head> |
| 145 <script type="application/dart">/*1*/</script> | 168 <script type="application/dart">/*1*/</script> |
| 146 </head></html>''', | 169 </head></html>''', |
| 147 'a|web/foo_02_test.html': ''' | 170 'a|web/foo_02_test.html': ''' |
| 148 <!DOCTYPE html><html><head> | 171 <!DOCTYPE html><html><head> |
| 149 <script type="application/dart">/*2*/</script> | 172 <script type="application/dart">/*2*/</script> |
| 150 </head></html>''', | 173 </head></html>''', |
| 151 'a|web/test_03.html': ''' | 174 'a|web/test_03.html': ''' |
| 152 <!DOCTYPE html><html><head> | 175 <!DOCTYPE html><html><head> |
| 153 <script type="application/dart">/*3*/</script> | 176 <script type="application/dart">/*3*/</script> |
| 154 </head></html>''', | 177 </head></html>''', |
| 155 'a|web/*test_%foo_04!.html': ''' | 178 'a|web/*test_%foo_04!.html': ''' |
| 156 <!DOCTYPE html><html><head> | 179 <!DOCTYPE html><html><head> |
| 157 <script type="application/dart">/*4*/</script> | 180 <script type="application/dart">/*4*/</script> |
| 158 </head></html>''', | 181 </head></html>''', |
| 159 'a|web/%05_test.html': ''' | 182 'a|web/%05_test.html': ''' |
| 160 <!DOCTYPE html><html><head> | 183 <!DOCTYPE html><html><head> |
| 161 <script type="application/dart">/*5*/</script> | 184 <script type="application/dart">/*5*/</script> |
| 162 </head></html>''', | 185 </head></html>''', |
| 163 }, { | 186 }, |
| 164 // Appends an _ if it starts with a number. | 187 { |
| 165 'a|web/01_test.html.0.dart': 'library a.web._01_test_html_0;\n/*1*/', | 188 // Appends an _ if it starts with a number. |
| 166 // Allows numbers in the middle. | 189 'a|web/01_test.html.0.dart': 'library a.web._01_test_html_0;\n/*1*/', |
| 167 'a|web/foo_02_test.html.0.dart': 'library a.web.foo_02_test_html_0;\n/*2*/', | 190 // Allows numbers in the middle. |
| 168 // Allows numbers at the end. | 191 'a|web/foo_02_test.html.0.dart': |
| 169 'a|web/test_03.html.0.dart': 'library a.web.test_03_html_0;\n/*3*/', | 192 'library a.web.foo_02_test_html_0;\n/*2*/', |
| 170 // Replaces invalid characters with _. | 193 // Allows numbers at the end. |
| 171 'a|web/*test_%foo_04!.html.0.dart': | 194 'a|web/test_03.html.0.dart': 'library a.web.test_03_html_0;\n/*3*/', |
| 172 'library a.web._test__foo_04__html_0;\n/*4*/', | 195 // Replaces invalid characters with _. |
| 173 // Replace invalid character followed by number. | 196 'a|web/*test_%foo_04!.html.0.dart': |
| 174 'a|web/%05_test.html.0.dart': 'library a.web._05_test_html_0;\n/*5*/', | 197 'library a.web._test__foo_04__html_0;\n/*4*/', |
| 175 }, [], StringFormatter.noNewlinesOrSurroundingWhitespace); | 198 // Replace invalid character followed by number. |
| 199 'a|web/%05_test.html.0.dart': 'library a.web._05_test_html_0;\n/*5*/', |
| 200 }, |
| 201 messages: [], |
| 202 formatter: StringFormatter.noNewlinesOrSurroundingWhitespace); |
| 203 |
| 204 testPhases( |
| 205 'file names with hyphens are ok', |
| 206 phases, |
| 207 { |
| 208 'a|web/a-b.html': ''' |
| 209 <!DOCTYPE html><html><head></head><body> |
| 210 <script type="application/dart" src="a-b.dart"></script> |
| 211 </body></html>''', |
| 212 'a|web/a-b.dart': ''' |
| 213 library a.a_b; |
| 214 main(){}''', |
| 215 }, |
| 216 { |
| 217 'a|web/a-b.html': ''' |
| 218 <!DOCTYPE html><html><head></head><body> |
| 219 <script type="application/dart" src="a-b.bootstrap.dart"></script> |
| 220 </body></html>''', |
| 221 'a|web/a-b.bootstrap.dart': ''' |
| 222 library a.web.a_b_bootstrap_dart; |
| 223 |
| 224 import 'a-b.dart' as i0; |
| 225 |
| 226 main() => i0.main();''', |
| 227 'a|web/a-b.dart': ''' |
| 228 library a.a_b; |
| 229 main(){}''', |
| 230 }, |
| 231 messages: [], |
| 232 formatter: StringFormatter.noNewlinesOrSurroundingWhitespace); |
| 233 |
| 234 testPhases( |
| 235 'package names with hyphens give an error', |
| 236 phases, |
| 237 { |
| 238 'a-b|web/a.html': ''' |
| 239 <!DOCTYPE html><html><head></head><body> |
| 240 <script type="application/dart" src="a.dart"></script> |
| 241 </body></html>''', |
| 242 'a-b|web/a.dart': ''' |
| 243 library a.a; |
| 244 main(){}''', |
| 245 }, |
| 246 {}, |
| 247 messages: [ |
| 248 'error: Invalid package name `a-b`. Package names should be ' |
| 249 'valid dart identifiers, as indicated at ' |
| 250 'https://www.dartlang.org/tools/pub/pubspec.html#name.' |
| 251 ], |
| 252 formatter: StringFormatter.noNewlinesOrSurroundingWhitespace); |
| 253 |
| 254 testPhases( |
| 255 'package names that start with a period are not allowed', |
| 256 phases, |
| 257 { |
| 258 '.a|web/a.html': ''' |
| 259 <!DOCTYPE html><html><head></head><body> |
| 260 <script type="application/dart" src="a.dart"></script> |
| 261 </body></html>''', |
| 262 '.a|web/a.dart': ''' |
| 263 library a.a; |
| 264 main(){}''', |
| 265 }, |
| 266 {}, |
| 267 messages: [ |
| 268 'error: Invalid package name `.a`. Package names should be ' |
| 269 'valid dart identifiers, as indicated at ' |
| 270 'https://www.dartlang.org/tools/pub/pubspec.html#name.' |
| 271 ], |
| 272 formatter: StringFormatter.noNewlinesOrSurroundingWhitespace); |
| 273 |
| 274 testPhases( |
| 275 'package names that end with a period are not allowed', |
| 276 phases, |
| 277 { |
| 278 'a.|web/a.html': ''' |
| 279 <!DOCTYPE html><html><head></head><body> |
| 280 <script type="application/dart" src="a.dart"></script> |
| 281 </body></html>''', |
| 282 'a.|web/a.dart': ''' |
| 283 library a.a; |
| 284 main(){}''', |
| 285 }, |
| 286 {}, |
| 287 messages: [ |
| 288 'error: Invalid package name `a.`. Package names should be ' |
| 289 'valid dart identifiers, as indicated at ' |
| 290 'https://www.dartlang.org/tools/pub/pubspec.html#name.' |
| 291 ], |
| 292 formatter: StringFormatter.noNewlinesOrSurroundingWhitespace); |
| 293 |
| 294 testPhases( |
| 295 'package names with double periods are not allowed', |
| 296 phases, |
| 297 { |
| 298 'a..b|web/a.html': ''' |
| 299 <!DOCTYPE html><html><head></head><body> |
| 300 <script type="application/dart" src="a.dart"></script> |
| 301 </body></html>''', |
| 302 'a..b|web/a.dart': ''' |
| 303 library a.a; |
| 304 main(){}''', |
| 305 }, |
| 306 {}, |
| 307 messages: [ |
| 308 'error: Invalid package name `a..b`. Package names should be ' |
| 309 'valid dart identifiers, as indicated at ' |
| 310 'https://www.dartlang.org/tools/pub/pubspec.html#name.' |
| 311 ], |
| 312 formatter: StringFormatter.noNewlinesOrSurroundingWhitespace); |
| 313 |
| 314 testPhases( |
| 315 'package names with internal periods are allowed', |
| 316 phases, |
| 317 { |
| 318 'a.b|web/a.html': ''' |
| 319 <!DOCTYPE html><html><head></head><body> |
| 320 <script type="application/dart" src="a.dart"></script> |
| 321 </body></html>''', |
| 322 'a.b|web/a.dart': ''' |
| 323 library a.b.a; |
| 324 main(){}''', |
| 325 }, |
| 326 { |
| 327 'a.b|web/a.bootstrap.dart': ''' |
| 328 library a.b.web.a_bootstrap_dart; |
| 329 |
| 330 import 'a.dart' as i0; |
| 331 |
| 332 main() => i0.main();''', |
| 333 }, |
| 334 messages: [], |
| 335 formatter: StringFormatter.noNewlinesOrSurroundingWhitespace); |
| 176 } | 336 } |
| 177 | 337 |
| 178 void codeExtractorTests() { | 338 void codeExtractorTests() { |
| 179 testPhases('no dart script', phases, { | 339 testPhases('no dart script', phases, |
| 180 'a|web/test.html': '<!DOCTYPE html><html></html>', | 340 {'a|web/test.html': '<!DOCTYPE html><html></html>',}, {}, |
| 181 }, {}, [ | 341 messages: [ |
| 182 'error: Found either zero or multiple dart scripts in the entry point ' | 342 'error: Found either zero or multiple dart scripts in the entry point ' |
| 183 '`web/test.html`. Exactly one was expected.', | 343 '`web/test.html`. Exactly one was expected.', |
| 184 ], StringFormatter.noNewlinesOrSurroundingWhitespace); | 344 ], |
| 185 | 345 formatter: StringFormatter.noNewlinesOrSurroundingWhitespace); |
| 186 testPhases('single script, no library in script', phases, { | 346 |
| 187 'a|web/test.html': ''' | 347 testPhases( |
| 348 'single script, no library in script', |
| 349 phases, |
| 350 { |
| 351 'a|web/test.html': ''' |
| 188 <!DOCTYPE html><html><head> | 352 <!DOCTYPE html><html><head> |
| 189 <script type="application/dart">main() { }</script>''', | 353 <script type="application/dart">main() { }</script>''', |
| 190 }, { | 354 }, |
| 191 'a|web/test.html': ''' | 355 { |
| 356 'a|web/test.html': ''' |
| 192 <!DOCTYPE html><html><head> | 357 <!DOCTYPE html><html><head> |
| 193 <script type="application/dart" src="test.bootstrap.dart"> | 358 <script type="application/dart" src="test.bootstrap.dart"> |
| 194 </script> | 359 </script> |
| 195 </head><body></body></html>''', | 360 </head><body></body></html>''', |
| 196 'a|web/test.html.0.dart': ''' | 361 'a|web/test.html.0.dart': ''' |
| 197 library a.web.test_html_0; | 362 library a.web.test_html_0; |
| 198 main() { }''', | 363 main() { }''', |
| 199 'a|web/test.bootstrap.dart': ''' | 364 'a|web/test.bootstrap.dart': ''' |
| 200 library a.web.test_bootstrap_dart; | 365 library a.web.test_bootstrap_dart; |
| 201 | 366 |
| 202 import 'test.html.0.dart' as i0; | 367 import 'test.html.0.dart' as i0; |
| 203 | 368 |
| 204 main() => i0.main();''', | 369 main() => i0.main();''', |
| 205 }, [], StringFormatter.noNewlinesOrSurroundingWhitespace); | 370 }, |
| 206 | 371 messages: [], |
| 207 testPhases('single script, with library', phases, { | 372 formatter: StringFormatter.noNewlinesOrSurroundingWhitespace); |
| 208 'a|web/test.html': ''' | 373 |
| 374 testPhases( |
| 375 'single script, with library', |
| 376 phases, |
| 377 { |
| 378 'a|web/test.html': ''' |
| 209 <!DOCTYPE html><html><head> | 379 <!DOCTYPE html><html><head> |
| 210 <script type="application/dart"> | 380 <script type="application/dart"> |
| 211 library f; | 381 library f; |
| 212 main() { } | 382 main() { } |
| 213 </script>''', | 383 </script>''', |
| 214 }, { | 384 }, |
| 215 'a|web/test.html': ''' | 385 { |
| 386 'a|web/test.html': ''' |
| 216 <!DOCTYPE html><html><head> | 387 <!DOCTYPE html><html><head> |
| 217 <script type="application/dart" src="test.bootstrap.dart"> | 388 <script type="application/dart" src="test.bootstrap.dart"> |
| 218 </script> | 389 </script> |
| 219 </head><body></body></html>''', | 390 </head><body></body></html>''', |
| 220 'a|web/test.html.0.dart': ''' | 391 'a|web/test.html.0.dart': ''' |
| 221 library f; | 392 library f; |
| 222 main() { }''', | 393 main() { }''', |
| 223 'a|web/test.bootstrap.dart': ''' | 394 'a|web/test.bootstrap.dart': ''' |
| 224 library a.web.test_bootstrap_dart; | 395 library a.web.test_bootstrap_dart; |
| 225 | 396 |
| 226 import 'test.html.0.dart' as i0; | 397 import 'test.html.0.dart' as i0; |
| 227 | 398 |
| 228 main() => i0.main();''', | 399 main() => i0.main();''', |
| 229 }, [], StringFormatter.noNewlinesOrSurroundingWhitespace); | 400 }, |
| 230 | 401 messages: [], |
| 231 testPhases('under lib/ directory not transformed', phases, { | 402 formatter: StringFormatter.noNewlinesOrSurroundingWhitespace); |
| 232 'a|lib/test.html': ''' | 403 |
| 404 testPhases( |
| 405 'under lib/ directory not transformed', |
| 406 phases, |
| 407 { |
| 408 'a|lib/test.html': ''' |
| 233 <!DOCTYPE html><html><head> | 409 <!DOCTYPE html><html><head> |
| 234 <script type="application/dart"> | 410 <script type="application/dart"> |
| 235 library f; | 411 library f; |
| 236 main() { } | 412 main() { } |
| 237 </script>''', | 413 </script>''', |
| 238 }, { | 414 }, |
| 239 'a|lib/test.html': ''' | 415 { |
| 416 'a|lib/test.html': ''' |
| 240 <!DOCTYPE html><html><head> | 417 <!DOCTYPE html><html><head> |
| 241 <script type="application/dart"> | 418 <script type="application/dart"> |
| 242 library f; | 419 library f; |
| 243 main() { } | 420 main() { } |
| 244 </script>''', | 421 </script>''', |
| 245 }, [], StringFormatter.noNewlinesOrSurroundingWhitespace); | 422 }, |
| 246 | 423 messages: [], |
| 247 testPhases('multiple scripts - error', phases, { | 424 formatter: StringFormatter.noNewlinesOrSurroundingWhitespace); |
| 248 'a|web/test.html': ''' | 425 |
| 426 testPhases( |
| 427 'multiple scripts - error', |
| 428 phases, |
| 429 { |
| 430 'a|web/test.html': ''' |
| 249 <!DOCTYPE html><html><head> | 431 <!DOCTYPE html><html><head> |
| 250 <script type="application/dart"> | 432 <script type="application/dart"> |
| 251 library a1; | 433 library a1; |
| 252 main1() { } | 434 main1() { } |
| 253 </script> | 435 </script> |
| 254 <script type="application/dart">library a2;\nmain2() { }</script>''', | 436 <script type="application/dart">library a2;\nmain2() { }</script>''', |
| 255 }, {}, [ | 437 }, |
| 256 'error: Found either zero or multiple dart scripts in the entry point ' | 438 {}, |
| 257 '`web/test.html`. Exactly one was expected.', | 439 messages: [ |
| 258 ], StringFormatter.noNewlinesOrSurroundingWhitespace); | 440 'error: Found either zero or multiple dart scripts in the entry point ' |
| 259 | 441 '`web/test.html`. Exactly one was expected.', |
| 260 testPhases('multiple imported scripts', phases, { | 442 ], |
| 261 'a|web/test.html': ''' | 443 formatter: StringFormatter.noNewlinesOrSurroundingWhitespace); |
| 444 |
| 445 testPhases( |
| 446 'multiple imported scripts', |
| 447 phases, |
| 448 { |
| 449 'a|web/test.html': ''' |
| 262 <link rel="import" href="test2.html"> | 450 <link rel="import" href="test2.html"> |
| 263 <link rel="import" href="bar/test.html"> | 451 <link rel="import" href="bar/test.html"> |
| 264 <link rel="import" href="packages/a/foo/test.html"> | 452 <link rel="import" href="packages/a/foo/test.html"> |
| 265 <link rel="import" href="packages/b/test.html"> | 453 <link rel="import" href="packages/b/test.html"> |
| 266 <script type="application/dart" src="test.dart"></script>''', | 454 <script type="application/dart" src="test.dart"></script>''', |
| 267 'a|web/test.dart': 'library a.test;', | 455 'a|web/test.dart': 'library a.test;', |
| 268 'a|web/test2.html': '<script type="application/dart">main1() { }', | 456 'a|web/test2.html': '<script type="application/dart">main1() { }', |
| 269 'a|web/bar/test.html': '<script type="application/dart">main2() { }', | 457 'a|web/bar/test.html': '<script type="application/dart">main2() { }', |
| 270 'a|lib/foo/test.html': '<script type="application/dart">main3() { }', | 458 'a|lib/foo/test.html': '<script type="application/dart">main3() { }', |
| 271 'b|lib/test.html': '<script type="application/dart">main4() { }', | 459 'b|lib/test.html': '<script type="application/dart">main4() { }', |
| 272 }, { | 460 }, |
| 273 'a|web/test.html': ''' | 461 { |
| 462 'a|web/test.html': ''' |
| 274 <html> | 463 <html> |
| 275 <head> | 464 <head> |
| 276 <link rel="import" href="test2.html"> | 465 <link rel="import" href="test2.html"> |
| 277 <link rel="import" href="bar/test.html"> | 466 <link rel="import" href="bar/test.html"> |
| 278 <link rel="import" href="packages/a/foo/test.html"> | 467 <link rel="import" href="packages/a/foo/test.html"> |
| 279 <link rel="import" href="packages/b/test.html"> | 468 <link rel="import" href="packages/b/test.html"> |
| 280 <script type="application/dart" src="test.bootstrap.dart"></script> | 469 <script type="application/dart" src="test.bootstrap.dart"></script> |
| 281 </head><body></body></html>''', | 470 </head><body></body></html>''', |
| 282 'a|web/test.bootstrap.dart': ''' | 471 'a|web/test.bootstrap.dart': ''' |
| 283 library a.web.test_bootstrap_dart; | 472 library a.web.test_bootstrap_dart; |
| 284 import 'test.html.0.dart' as i0; | 473 import 'test.html.0.dart' as i0; |
| 285 import 'test.html.1.dart' as i1; | 474 import 'test.html.1.dart' as i1; |
| 286 import 'test.html.2.dart' as i2; | 475 import 'test.html.2.dart' as i2; |
| 287 import 'test.html.3.dart' as i3; | 476 import 'test.html.3.dart' as i3; |
| 288 import 'test.dart' as i4; | 477 import 'test.dart' as i4; |
| 289 | 478 |
| 290 main() => i4.main(); | 479 main() => i4.main(); |
| 291 ''', | 480 ''', |
| 292 'a|web/test.html.0.dart': ''' | 481 'a|web/test.html.0.dart': ''' |
| 293 library a.web.test_html_0; | 482 library a.web.test_html_0; |
| 294 main1() { }''', | 483 main1() { }''', |
| 295 'a|web/test.html.1.dart': ''' | 484 'a|web/test.html.1.dart': ''' |
| 296 library a.web.test_html_1; | 485 library a.web.test_html_1; |
| 297 main2() { }''', | 486 main2() { }''', |
| 298 'a|web/test.html.2.dart': ''' | 487 'a|web/test.html.2.dart': ''' |
| 299 library a.web.test_html_2; | 488 library a.web.test_html_2; |
| 300 main3() { }''', | 489 main3() { }''', |
| 301 'a|web/test.html.3.dart': ''' | 490 'a|web/test.html.3.dart': ''' |
| 302 library a.web.test_html_3; | 491 library a.web.test_html_3; |
| 303 main4() { }''', | 492 main4() { }''', |
| 304 }, [], StringFormatter.noNewlinesOrSurroundingWhitespace); | 493 }, |
| 494 messages: [], |
| 495 formatter: StringFormatter.noNewlinesOrSurroundingWhitespace); |
| 305 } | 496 } |
| 306 | 497 |
| 307 dartUriTests() { | 498 dartUriTests() { |
| 308 testPhases('from web folder', phases, { | 499 testPhases( |
| 309 'a|web/test.html': ''' | 500 'from web folder', |
| 501 phases, |
| 502 { |
| 503 'a|web/test.html': ''' |
| 310 <!DOCTYPE html><html><head> | 504 <!DOCTYPE html><html><head> |
| 311 <link rel="import" href="test2/foo.html"> | 505 <link rel="import" href="test2/foo.html"> |
| 312 <script type="application/dart" src="test.dart"></script> | 506 <script type="application/dart" src="test.dart"></script> |
| 313 </head><body></body></html>''', | 507 </head><body></body></html>''', |
| 314 'a|web/test.dart': 'library a.test;', | 508 'a|web/test.dart': 'library a.test;', |
| 315 'a|web/test2/foo.html': ''' | 509 'a|web/test2/foo.html': ''' |
| 316 <!DOCTYPE html><html><head></head><body> | 510 <!DOCTYPE html><html><head></head><body> |
| 317 <script type="application/dart"> | 511 <script type="application/dart"> |
| 318 import 'package:qux/qux.dart'; | 512 import 'package:qux/qux.dart'; |
| 319 import 'foo.dart'; | 513 import 'foo.dart'; |
| 320 export 'bar.dart'; | 514 export 'bar.dart'; |
| 321 part 'baz.dart'; | 515 part 'baz.dart'; |
| 322 </script> | 516 </script> |
| 323 </body></html>''', | 517 </body></html>''', |
| 324 }, { | 518 }, |
| 325 'a|web/test.html': ''' | 519 { |
| 520 'a|web/test.html': ''' |
| 326 <!DOCTYPE html><html><head> | 521 <!DOCTYPE html><html><head> |
| 327 <link rel="import" href="test2/foo.html"> | 522 <link rel="import" href="test2/foo.html"> |
| 328 <script type="application/dart" src="test.bootstrap.dart"></script> | 523 <script type="application/dart" src="test.bootstrap.dart"></script> |
| 329 </head><body></body></html>''', | 524 </head><body></body></html>''', |
| 330 'a|web/test.html.0.dart': ''' | 525 'a|web/test.html.0.dart': ''' |
| 331 library a.web.test_html_0; | 526 library a.web.test_html_0; |
| 332 | 527 |
| 333 import 'package:qux/qux.dart'; | 528 import 'package:qux/qux.dart'; |
| 334 import 'test2/foo.dart'; | 529 import 'test2/foo.dart'; |
| 335 export 'test2/bar.dart'; | 530 export 'test2/bar.dart'; |
| 336 part 'test2/baz.dart';''', | 531 part 'test2/baz.dart';''', |
| 337 'a|web/test2/foo.html': ''' | 532 'a|web/test2/foo.html': ''' |
| 338 <!DOCTYPE html><html><head></head><body> | 533 <!DOCTYPE html><html><head></head><body> |
| 339 <script type="application/dart" src="foo.bootstrap.dart"> | 534 <script type="application/dart" src="foo.bootstrap.dart"> |
| 340 </script> | 535 </script> |
| 341 </body></html>''', | 536 </body></html>''', |
| 342 'a|web/test2/foo.html.0.dart': ''' | 537 'a|web/test2/foo.html.0.dart': ''' |
| 343 library a.web.test2.foo_html_0; | 538 library a.web.test2.foo_html_0; |
| 344 | 539 |
| 345 import 'package:qux/qux.dart'; | 540 import 'package:qux/qux.dart'; |
| 346 import 'foo.dart'; | 541 import 'foo.dart'; |
| 347 export 'bar.dart'; | 542 export 'bar.dart'; |
| 348 part 'baz.dart';''', | 543 part 'baz.dart';''', |
| 349 }, [], StringFormatter.noNewlinesOrSurroundingWhitespace); | 544 }, |
| 545 messages: [], |
| 546 formatter: StringFormatter.noNewlinesOrSurroundingWhitespace); |
| 350 | 547 |
| 351 testPhases('from lib folder', phases, { | 548 testPhases( |
| 352 'a|web/test.html': ''' | 549 'from lib folder', |
| 550 phases, |
| 551 { |
| 552 'a|web/test.html': ''' |
| 353 <!DOCTYPE html><html><head> | 553 <!DOCTYPE html><html><head> |
| 354 <link rel="import" href="packages/a/test2/foo.html"> | 554 <link rel="import" href="packages/a/test2/foo.html"> |
| 355 <script type="application/dart" src="test.dart"></script> | 555 <script type="application/dart" src="test.dart"></script> |
| 356 </head><body></body></html>''', | 556 </head><body></body></html>''', |
| 357 'a|web/test.dart': 'library a.test;', | 557 'a|web/test.dart': 'library a.test;', |
| 358 'a|lib/test2/foo.html': ''' | 558 'a|lib/test2/foo.html': ''' |
| 359 <!DOCTYPE html><html><head></head><body> | 559 <!DOCTYPE html><html><head></head><body> |
| 360 <script type="application/dart"> | 560 <script type="application/dart"> |
| 361 import 'package:qux/qux.dart'; | 561 import 'package:qux/qux.dart'; |
| 362 import 'foo.dart'; | 562 import 'foo.dart'; |
| 363 export 'bar.dart'; | 563 export 'bar.dart'; |
| 364 part 'baz.dart'; | 564 part 'baz.dart'; |
| 365 </script> | 565 </script> |
| 366 </body></html>''', | 566 </body></html>''', |
| 367 }, { | 567 }, |
| 368 'a|web/test.html': ''' | 568 { |
| 569 'a|web/test.html': ''' |
| 369 <!DOCTYPE html><html><head> | 570 <!DOCTYPE html><html><head> |
| 370 <link rel="import" href="packages/a/test2/foo.html"> | 571 <link rel="import" href="packages/a/test2/foo.html"> |
| 371 <script type="application/dart" src="test.bootstrap.dart"></script> | 572 <script type="application/dart" src="test.bootstrap.dart"></script> |
| 372 </head><body></body></html>''', | 573 </head><body></body></html>''', |
| 373 'a|web/test.html.0.dart': ''' | 574 'a|web/test.html.0.dart': ''' |
| 374 library a.web.test_html_0; | 575 library a.web.test_html_0; |
| 375 | 576 |
| 376 import 'package:qux/qux.dart'; | 577 import 'package:qux/qux.dart'; |
| 377 import 'package:a/test2/foo.dart'; | 578 import 'package:a/test2/foo.dart'; |
| 378 export 'package:a/test2/bar.dart'; | 579 export 'package:a/test2/bar.dart'; |
| 379 part 'package:a/test2/baz.dart';''', | 580 part 'package:a/test2/baz.dart';''', |
| 380 'a|lib/test2/foo.html': ''' | 581 'a|lib/test2/foo.html': ''' |
| 381 <!DOCTYPE html><html><head></head><body> | 582 <!DOCTYPE html><html><head></head><body> |
| 382 <script type="application/dart"> | 583 <script type="application/dart"> |
| 383 import 'package:qux/qux.dart'; | 584 import 'package:qux/qux.dart'; |
| 384 import 'foo.dart'; | 585 import 'foo.dart'; |
| 385 export 'bar.dart'; | 586 export 'bar.dart'; |
| 386 part 'baz.dart'; | 587 part 'baz.dart'; |
| 387 </script> | 588 </script> |
| 388 </body></html>''', | 589 </body></html>''', |
| 389 }, [], StringFormatter.noNewlinesOrSurroundingWhitespace); | 590 }, |
| 591 messages: [], |
| 592 formatter: StringFormatter.noNewlinesOrSurroundingWhitespace); |
| 390 | 593 |
| 391 testPhases('from another pkg', phases, { | 594 testPhases( |
| 392 'a|web/test.html': ''' | 595 'from another pkg', |
| 596 phases, |
| 597 { |
| 598 'a|web/test.html': ''' |
| 393 <!DOCTYPE html><html><head> | 599 <!DOCTYPE html><html><head> |
| 394 <link rel="import" href="packages/b/test2/foo.html"> | 600 <link rel="import" href="packages/b/test2/foo.html"> |
| 395 <script type="application/dart" src="test.dart"></script> | 601 <script type="application/dart" src="test.dart"></script> |
| 396 </head><body></body></html>''', | 602 </head><body></body></html>''', |
| 397 'a|web/test.dart': 'library a.test;', | 603 'a|web/test.dart': 'library a.test;', |
| 398 'b|lib/test2/foo.html': ''' | 604 'b|lib/test2/foo.html': ''' |
| 399 <!DOCTYPE html><html><head></head><body> | 605 <!DOCTYPE html><html><head></head><body> |
| 400 <script type="application/dart"> | 606 <script type="application/dart"> |
| 401 import 'package:qux/qux.dart'; | 607 import 'package:qux/qux.dart'; |
| 402 import 'foo.dart'; | 608 import 'foo.dart'; |
| 403 export 'bar.dart'; | 609 export 'bar.dart'; |
| 404 part 'baz.dart'; | 610 part 'baz.dart'; |
| 405 </script> | 611 </script> |
| 406 </body></html>''', | 612 </body></html>''', |
| 407 }, { | 613 }, |
| 408 'a|web/test.html': ''' | 614 { |
| 615 'a|web/test.html': ''' |
| 409 <!DOCTYPE html><html><head> | 616 <!DOCTYPE html><html><head> |
| 410 <link rel="import" href="packages/b/test2/foo.html"> | 617 <link rel="import" href="packages/b/test2/foo.html"> |
| 411 <script type="application/dart" src="test.bootstrap.dart"></script> | 618 <script type="application/dart" src="test.bootstrap.dart"></script> |
| 412 </head><body></body></html>''', | 619 </head><body></body></html>''', |
| 413 'a|web/test.html.0.dart': ''' | 620 'a|web/test.html.0.dart': ''' |
| 414 library a.web.test_html_0; | 621 library a.web.test_html_0; |
| 415 | 622 |
| 416 import 'package:qux/qux.dart'; | 623 import 'package:qux/qux.dart'; |
| 417 import 'package:b/test2/foo.dart'; | 624 import 'package:b/test2/foo.dart'; |
| 418 export 'package:b/test2/bar.dart'; | 625 export 'package:b/test2/bar.dart'; |
| 419 part 'package:b/test2/baz.dart';''', | 626 part 'package:b/test2/baz.dart';''', |
| 420 }, [], StringFormatter.noNewlinesOrSurroundingWhitespace); | 627 }, |
| 628 messages: [], |
| 629 formatter: StringFormatter.noNewlinesOrSurroundingWhitespace); |
| 421 } | 630 } |
| 422 | 631 |
| 423 validateUriTests() { | 632 validateUriTests() { |
| 424 testPhases('script src is invalid', phases, { | 633 testPhases('script src is invalid', phases, { |
| 425 'a|web/test.html': ''' | 634 'a|web/test.html': ''' |
| 426 <!DOCTYPE html><html><body> | 635 <!DOCTYPE html><html><body> |
| 427 <script type="application/dart" src="a.dart"></script> | 636 <script type="application/dart" src="a.dart"></script> |
| 428 </body></html>''', | 637 </body></html>''', |
| 429 }, {}, [ | 638 }, {}, messages: [ |
| 430 'warning: ${scriptFileNotFound.create({'url': 'a|web/a.dart'}).snippet} ' | 639 'warning: ${scriptFileNotFound.create({'url': 'a|web/a.dart'}).snippet} ' |
| 431 '(web/test.html 1 8)', | 640 '(web/test.html 1 8)', |
| 432 ]); | 641 ]); |
| 433 } | 642 } |
| OLD | NEW |