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

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

Issue 794473002: Delete polymer from the Dart repo (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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 library polymer.test.build.script_compactor_test;
6
7 import 'dart:convert';
8
9 import 'package:code_transformers/tests.dart' show testingDartSdkDirectory;
10 import 'package:polymer/src/build/common.dart';
11 import 'package:polymer/src/build/messages.dart';
12 import 'package:polymer/src/build/script_compactor.dart';
13 import 'package:smoke/codegen/generator.dart' show DEFAULT_IMPORTS;
14 import 'package:unittest/compact_vm_config.dart';
15 import 'package:unittest/unittest.dart';
16
17 import 'common.dart';
18
19 void main() {
20 useCompactVMConfiguration();
21 var phases = [[new ScriptCompactor(new TransformOptions(),
22 sdkDir: testingDartSdkDirectory)]];
23 group('initializers', () => initializerTests(phases));
24 group('experimental', () => initializerTestsExperimental(phases));
25 group('codegen', () => codegenTests(phases));
26 group('log element injection', logElementInjectionTests);
27 }
28
29 initializerTests(phases) {
30 testPhases('no changes', phases, {
31 'a|web/test.html': '<!DOCTYPE html><html></html>',
32 'a|web/test.html._data': EMPTY_DATA,
33 }, {
34 'a|web/test.html': '<!DOCTYPE html><html></html>',
35 });
36
37 testPhases('no changes outside web/', phases, {
38 'a|lib/test.html':
39 '<!DOCTYPE html><html><head>',
40 'a|lib/test.html._data': expectedData(['lib/a.dart']),
41 }, {
42 'a|lib/test.html':
43 '<!DOCTYPE html><html><head>',
44 'a|lib/test.html._data': expectedData(['lib/a.dart']),
45 });
46
47 testPhases('single script', phases, {
48 'a|web/test.html':
49 '<!DOCTYPE html><html><head>',
50 'a|web/test.html._data': expectedData(['web/a.dart']),
51 'a|web/a.dart':
52 'library a;\n'
53 'import "package:polymer/polymer.dart";\n'
54 'main(){}',
55 }, {
56 'a|web/test.html':
57 '<!DOCTYPE html><html><head></head><body>'
58 '<script type="application/dart" '
59 'src="test.html_bootstrap.dart"></script>'
60 '</body></html>',
61
62 'a|web/test.html_bootstrap.dart':
63 '''$MAIN_HEADER
64 import 'a.dart' as i0;
65 ${DEFAULT_IMPORTS.join('\n')}
66
67 void main() {
68 useGeneratedCode(new StaticConfiguration(
69 checkedMode: false));
70 configureForDeployment([]);
71 i0.main();
72 }
73 '''.replaceAll('\n ', '\n'),
74 'a|web/a.dart':
75 'library a;\n'
76 'import "package:polymer/polymer.dart";\n'
77 'main(){}',
78 });
79
80 testPhases('simple initialization', phases, {
81 'a|web/test.html':
82 '<!DOCTYPE html><html><head>',
83 'a|web/test.html._data': expectedData(['web/a.dart']),
84 'a|web/a.dart':
85 'library a;\n'
86 'import "package:polymer/polymer.dart";\n'
87 '@CustomTag("x-foo")\n'
88 'class XFoo extends PolymerElement {\n'
89 '}\n'
90 'main(){}',
91 }, {
92 'a|web/test.html_bootstrap.dart':
93 '''$MAIN_HEADER
94 import 'a.dart' as i0;
95 ${DEFAULT_IMPORTS.join('\n')}
96 import 'a.dart' as smoke_0;
97 import 'package:polymer/polymer.dart' as smoke_1;
98
99 void main() {
100 useGeneratedCode(new StaticConfiguration(
101 checkedMode: false,
102 parents: {
103 smoke_0.XFoo: smoke_1.PolymerElement,
104 },
105 declarations: {
106 smoke_0.XFoo: {},
107 }));
108 configureForDeployment([
109 () => Polymer.register(\'x-foo\', i0.XFoo),
110 ]);
111 i0.main();
112 }
113 '''.replaceAll('\n ', '\n'),
114 });
115
116 testPhases('use const expressions', phases, {
117 'a|web/test.html':
118 '<!DOCTYPE html><html><head>',
119 'a|web/test.html._data': expectedData(['web/a.dart']),
120 'a|web/b.dart':
121 'library a;\n'
122 'const x = "x";\n',
123 'a|web/c.dart':
124 'part of a;\n'
125 'const dash = "-";\n',
126 'a|web/a.dart':
127 'library a;\n'
128 'import "package:polymer/polymer.dart";\n'
129 'import "b.dart";\n'
130 'part "c.dart";\n'
131 'const letterO = "o";\n'
132 '@CustomTag("\$x\${dash}f\${letterO}o2")\n'
133 'class XFoo extends PolymerElement {\n'
134 '}\n',
135 }, {
136 'a|web/test.html_bootstrap.dart':
137 '''$MAIN_HEADER
138 import 'a.dart' as i0;
139 ${DEFAULT_IMPORTS.join('\n')}
140 import 'a.dart' as smoke_0;
141 import 'package:polymer/polymer.dart' as smoke_1;
142
143 void main() {
144 useGeneratedCode(new StaticConfiguration(
145 checkedMode: false,
146 parents: {
147 smoke_0.XFoo: smoke_1.PolymerElement,
148 },
149 declarations: {
150 smoke_0.XFoo: {},
151 }));
152 configureForDeployment([
153 () => Polymer.register(\'x-foo2\', i0.XFoo),
154 ]);
155 i0.main();
156 }
157 '''.replaceAll('\n ', '\n'),
158 });
159
160
161 testLogOutput(
162 (options) =>
163 new ScriptCompactor(options, sdkDir: testingDartSdkDirectory),
164 'invalid const expression logs', {
165 'a|web/test.html':
166 '<!DOCTYPE html><html><head>',
167 'a|web/test.html._data': expectedData(['web/a.dart']),
168 'a|web/a.dart':
169 'library a;\n'
170 'import "package:polymer/polymer.dart";\n'
171 '@CustomTag("\${x}-foo")\n' // invalid, x is not defined
172 'class XFoo extends PolymerElement {\n'
173 '}\n'
174 'main(){}',
175 }, {}, [
176 'warning: ${INVALID_ANNOTATION_ARGUMENT.create(
177 {'name': 'CustomTag'}).snippet} (web/a.dart 2 11)',
178 ]);
179
180 testPhases(
181 'invalid const expression', phases, {
182 'a|web/test.html':
183 '<!DOCTYPE html><html><head>',
184 'a|web/test.html._data': expectedData(['web/a.dart']),
185 'a|web/a.dart':
186 'library a;\n'
187 'import "package:polymer/polymer.dart";\n'
188 '@CustomTag("\${x}-foo")\n' // invalid, x is not defined
189 'class XFoo extends PolymerElement {\n'
190 '}\n'
191 'main(){}',
192 }, {
193 'a|web/test.html_bootstrap.dart':
194 '''$MAIN_HEADER
195 import 'a.dart' as i0;
196 ${DEFAULT_IMPORTS.join('\n')}
197 import 'a.dart' as smoke_0;
198 import 'package:polymer/polymer.dart' as smoke_1;
199
200 void main() {
201 useGeneratedCode(new StaticConfiguration(
202 checkedMode: false,
203 parents: {
204 smoke_0.XFoo: smoke_1.PolymerElement,
205 },
206 declarations: {
207 smoke_0.XFoo: {},
208 }));
209 configureForDeployment([]);
210 i0.main();
211 }
212 '''.replaceAll('\n ', '\n'),
213
214 });
215
216 testPhases('no polymer import (no warning, but no crash either)', phases, {
217 'a|web/test.html':
218 '<!DOCTYPE html><html><head>',
219 'a|web/test.html._data': expectedData(['web/a.dart']),
220 'a|web/a.dart':
221 'library a;\n'
222 'import "package:polymer/polymer.broken.import.dart";\n'
223 '@CustomTag("x-foo")\n'
224 'class XFoo extends PolymerElement {\n'
225 '}\n'
226 'main(){}',
227 }, {
228 'a|web/test.html_bootstrap.dart':
229 '''$MAIN_HEADER
230 import 'a.dart' as i0;
231 ${DEFAULT_IMPORTS.join('\n')}
232
233 void main() {
234 useGeneratedCode(new StaticConfiguration(
235 checkedMode: false));
236 configureForDeployment([]);
237 i0.main();
238 }
239 '''.replaceAll('\n ', '\n'),
240
241 }, []);
242
243 testPhases('several scripts', phases, {
244 'a|web/test.html':
245 '<!DOCTYPE html><html><head>'
246 '</head><body><div></div>',
247 'a|web/test.html._data':
248 expectedData(['web/a.dart', 'web/b.dart', 'web/c.dart',
249 'web/i.dart', 'web/j.dart', 'web/d.dart']),
250 'a|web/d.dart':
251 'library d;\n'
252 'import "package:polymer/polymer.dart";\n'
253 'main(){}\n@initMethod mD(){}',
254
255 'a|web/a.dart':
256 'import "package:polymer/polymer.dart";\n'
257 'export "i.dart" hide mI2;\n'
258 '@initMethod mA(){}\n',
259
260 'a|web/b.dart':
261 'import "package:polymer/polymer.dart";\n'
262 'export "e.dart";\n'
263 'export "f.dart" show XF1, mF1;\n'
264 'export "g.dart" hide XG1, mG1;\n'
265 'export "h.dart" show XH1, mH1 hide mH1, mH2;\n'
266 '@initMethod mB(){}\n',
267
268 'a|web/c.dart':
269 'import "package:polymer/polymer.dart";\n'
270 'part "c_part.dart";\n'
271 '@CustomTag("x-c1") class XC1 extends PolymerElement {}\n',
272
273 'a|web/c_part.dart':
274 '@CustomTag("x-c2") class XC2 extends PolymerElement {}\n',
275
276 'a|web/e.dart':
277 'import "package:polymer/polymer.dart";\n'
278 '@CustomTag("x-e") class XE extends PolymerElement {}\n'
279 '@initMethod mE(){}\n',
280
281 'a|web/f.dart':
282 'import "package:polymer/polymer.dart";\n'
283 '@CustomTag("x-f1") class XF1 extends PolymerElement {}\n'
284 '@initMethod mF1(){}\n'
285 '@CustomTag("x-f2") class XF2 extends PolymerElement {}\n'
286 '@initMethod mF2(){}\n',
287
288 'a|web/g.dart':
289 'import "package:polymer/polymer.dart";\n'
290 '@CustomTag("x-g1") class XG1 extends PolymerElement {}\n'
291 '@initMethod mG1(){}\n'
292 '@CustomTag("x-g2") class XG2 extends PolymerElement {}\n'
293 '@initMethod mG2(){}\n',
294
295 'a|web/h.dart':
296 'import "package:polymer/polymer.dart";\n'
297 '@CustomTag("x-h1") class XH1 extends PolymerElement {}\n'
298 '@initMethod mH1(){}\n'
299 '@CustomTag("x-h2") class XH2 extends PolymerElement {}\n'
300 '@initMethod mH2(){}\n',
301
302 'a|web/i.dart':
303 'import "package:polymer/polymer.dart";\n'
304 '@CustomTag("x-i") class XI extends PolymerElement {}\n'
305 '@initMethod mI1(){}\n'
306 '@initMethod mI2(){}\n',
307
308 'a|web/j.dart':
309 'export "a.dart";\n',
310 }, {
311 'a|web/test.html':
312 '<!DOCTYPE html><html><head></head><body><div></div>'
313 '<script type="application/dart" src="test.html_bootstrap.dart">'
314 '</script>'
315 '</body></html>',
316
317 'a|web/test.html_bootstrap.dart':
318 '''$MAIN_HEADER
319 import 'a.dart' as i0;
320 import 'b.dart' as i1;
321 import 'c.dart' as i2;
322 import 'i.dart' as i3;
323 import 'j.dart' as i4;
324 import 'd.dart' as i5;
325 ${DEFAULT_IMPORTS.join('\n')}
326 import 'i.dart' as smoke_0;
327 import 'package:polymer/polymer.dart' as smoke_1;
328 import 'e.dart' as smoke_2;
329 import 'f.dart' as smoke_3;
330 import 'g.dart' as smoke_4;
331 import 'h.dart' as smoke_5;
332 import 'c.dart' as smoke_6;
333
334 void main() {
335 useGeneratedCode(new StaticConfiguration(
336 checkedMode: false,
337 parents: {
338 smoke_6.XC1: smoke_1.PolymerElement,
339 smoke_6.XC2: smoke_1.PolymerElement,
340 smoke_2.XE: smoke_1.PolymerElement,
341 smoke_3.XF1: smoke_1.PolymerElement,
342 smoke_4.XG2: smoke_1.PolymerElement,
343 smoke_5.XH1: smoke_1.PolymerElement,
344 smoke_0.XI: smoke_1.PolymerElement,
345 },
346 declarations: {
347 smoke_6.XC1: {},
348 smoke_6.XC2: {},
349 smoke_2.XE: {},
350 smoke_3.XF1: {},
351 smoke_4.XG2: {},
352 smoke_5.XH1: {},
353 smoke_0.XI: {},
354 }));
355 configureForDeployment([
356 i0.mA,
357 i0.mI1,
358 () => Polymer.register('x-i', i0.XI),
359 i1.mB,
360 i1.mE,
361 i1.mF1,
362 i1.mG2,
363 () => Polymer.register('x-e', i1.XE),
364 () => Polymer.register('x-f1', i1.XF1),
365 () => Polymer.register('x-g2', i1.XG2),
366 () => Polymer.register('x-h1', i1.XH1),
367 () => Polymer.register('x-c1', i2.XC1),
368 () => Polymer.register('x-c2', i2.XC2),
369 i3.mI2,
370 i5.mD,
371 ]);
372 i5.main();
373 }
374 '''.replaceAll('\n ', '\n'),
375 }, null);
376 }
377
378 initializerTestsExperimental(phases) {
379 testPhases('no changes', phases, {
380 'a|web/test.html': '<!DOCTYPE html><html></html>',
381 'a|web/test.html._data': EMPTY_DATA,
382 }, {
383 'a|web/test.html': '<!DOCTYPE html><html></html>',
384 });
385
386 testPhases('no changes outside web/', phases, {
387 'a|lib/test.html':
388 '<!DOCTYPE html><html><head>',
389 'a|lib/test.html._data': expectedData(['lib/a.dart'], experimental: true),
390 }, {
391 'a|lib/test.html':
392 '<!DOCTYPE html><html><head>',
393 'a|lib/test.html._data': expectedData(['lib/a.dart'], experimental: true),
394 });
395
396 testPhases('single script', phases, {
397 'a|web/test.html':
398 '<!DOCTYPE html><html><head>',
399 'a|web/test.html._data': expectedData(['web/a.dart'], experimental: true),
400 'a|web/a.dart':
401 'library a;\n'
402 'import "package:polymer/polymer.dart";\n'
403 '@initMethod main(){}',
404 }, {
405 'a|web/test.html':
406 '<!DOCTYPE html><html><head></head><body>'
407 '<script type="application/dart" '
408 'src="test.html_bootstrap.dart"></script>'
409 '</body></html>',
410
411 'a|web/test.html_bootstrap.dart':
412 '''$MAIN_HEADER
413 import 'a.dart' as i0;
414 ${DEFAULT_IMPORTS.join('\n')}
415
416 void main() {
417 useGeneratedCode(new StaticConfiguration(
418 checkedMode: false));
419 startPolymer([
420 i0.main,
421 ]);
422 }
423 '''.replaceAll('\n ', '\n'),
424 'a|web/a.dart':
425 'library a;\n'
426 'import "package:polymer/polymer.dart";\n'
427 '@initMethod main(){}',
428 });
429
430 testPhases('simple initialization', phases, {
431 'a|web/test.html':
432 '<!DOCTYPE html><html><head>',
433 'a|web/test.html._data': expectedData(['web/a.dart'], experimental: true),
434 'a|web/a.dart':
435 'library a;\n'
436 'import "package:polymer/polymer.dart";\n'
437 '@CustomTag("x-foo")\n'
438 'class XFoo extends PolymerElement {\n'
439 '}\n'
440 '@initMethod main(){}',
441 }, {
442 'a|web/test.html_bootstrap.dart':
443 '''$MAIN_HEADER
444 import 'a.dart' as i0;
445 ${DEFAULT_IMPORTS.join('\n')}
446 import 'a.dart' as smoke_0;
447 import 'package:polymer/polymer.dart' as smoke_1;
448
449 void main() {
450 useGeneratedCode(new StaticConfiguration(
451 checkedMode: false,
452 parents: {
453 smoke_0.XFoo: smoke_1.PolymerElement,
454 },
455 declarations: {
456 smoke_0.XFoo: {},
457 }));
458 startPolymer([
459 i0.main,
460 () => Polymer.register(\'x-foo\', i0.XFoo),
461 ]);
462 }
463 '''.replaceAll('\n ', '\n'),
464 });
465
466 testPhases('use const expressions', phases, {
467 'a|web/test.html':
468 '<!DOCTYPE html><html><head>',
469 'a|web/test.html._data': expectedData(['web/a.dart'], experimental: true),
470 'a|web/b.dart':
471 'library a;\n'
472 'const x = "x";\n',
473 'a|web/c.dart':
474 'part of a;\n'
475 'const dash = "-";\n',
476 'a|web/a.dart':
477 'library a;\n'
478 'import "package:polymer/polymer.dart";\n'
479 'import "b.dart";\n'
480 'part "c.dart";\n'
481 'const letterO = "o";\n'
482 '@CustomTag("\$x\${dash}f\${letterO}o2")\n'
483 'class XFoo extends PolymerElement {\n'
484 '}\n',
485 }, {
486 'a|web/test.html_bootstrap.dart':
487 '''$MAIN_HEADER
488 import 'a.dart' as i0;
489 ${DEFAULT_IMPORTS.join('\n')}
490 import 'a.dart' as smoke_0;
491 import 'package:polymer/polymer.dart' as smoke_1;
492
493 void main() {
494 useGeneratedCode(new StaticConfiguration(
495 checkedMode: false,
496 parents: {
497 smoke_0.XFoo: smoke_1.PolymerElement,
498 },
499 declarations: {
500 smoke_0.XFoo: {},
501 }));
502 startPolymer([
503 () => Polymer.register(\'x-foo2\', i0.XFoo),
504 ]);
505 }
506 '''.replaceAll('\n ', '\n'),
507 });
508
509 testLogOutput(
510 (options) =>
511 new ScriptCompactor(options, sdkDir: testingDartSdkDirectory),
512 'invalid const expression logs', {
513 'a|web/test.html':
514 '<!DOCTYPE html><html><head>',
515 'a|web/test.html._data':
516 expectedData(['web/a.dart'], experimental: true),
517 'a|web/a.dart':
518 'library a;\n'
519 'import "package:polymer/polymer.dart";\n'
520 '@CustomTag("\${x}-foo")\n' // invalid, x is not defined
521 'class XFoo extends PolymerElement {\n'
522 '}\n'
523 'main(){}',
524 }, {}, [
525 'warning: ${INVALID_ANNOTATION_ARGUMENT.create(
526 {'name': 'CustomTag'}).snippet} (web/a.dart 2 11)',
527 'warning: ${NO_INITIALIZATION.snippet}',
528 ]);
529
530 testPhases(
531 'invalid const expression', phases, {
532 'a|web/test.html':
533 '<!DOCTYPE html><html><head>',
534 'a|web/test.html._data':
535 expectedData(['web/a.dart'], experimental: true),
536 'a|web/a.dart':
537 'library a;\n'
538 'import "package:polymer/polymer.dart";\n'
539 '@CustomTag("\${x}-foo")\n' // invalid, x is not defined
540 'class XFoo extends PolymerElement {\n'
541 '}\n'
542 'main(){}',
543 }, {
544 'a|web/test.html_bootstrap.dart':
545 '''$MAIN_HEADER
546 import 'a.dart' as i0;
547 ${DEFAULT_IMPORTS.join('\n')}
548 import 'a.dart' as smoke_0;
549 import 'package:polymer/polymer.dart' as smoke_1;
550
551 void main() {
552 useGeneratedCode(new StaticConfiguration(
553 checkedMode: false,
554 parents: {
555 smoke_0.XFoo: smoke_1.PolymerElement,
556 },
557 declarations: {
558 smoke_0.XFoo: {},
559 }));
560 startPolymer([]);
561 }
562 '''.replaceAll('\n ', '\n'),
563 });
564
565 testLogOutput(
566 (options) =>
567 new ScriptCompactor(options, sdkDir: testingDartSdkDirectory),
568 'no polymer import logs', {
569 'a|web/test.html':
570 '<!DOCTYPE html><html><head>',
571 'a|web/test.html._data': expectedData(['web/a.dart'], experimental: true ),
572 'a|web/a.dart':
573 'library a;\n'
574 'import "package:polymer/polymer.broken.import.dart";\n'
575 '@CustomTag("x-foo")\n'
576 'class XFoo extends PolymerElement {\n'
577 '}\n'
578 'main(){}',
579 }, {}, [
580 'warning: ${NO_INITIALIZATION.snippet}',
581 ]);
582
583 testPhases(
584 'no polymer import', phases, {
585 'a|web/test.html':
586 '<!DOCTYPE html><html><head>',
587 'a|web/test.html._data':
588 expectedData(['web/a.dart'], experimental: true),
589 'a|web/a.dart':
590 'library a;\n'
591 'import "package:polymer/polymer.broken.import.dart";\n'
592 '@CustomTag("x-foo")\n'
593 'class XFoo extends PolymerElement {\n'
594 '}\n'
595 'main(){}',
596 }, {
597 'a|web/test.html_bootstrap.dart':
598 '''$MAIN_HEADER
599 import 'a.dart' as i0;
600 ${DEFAULT_IMPORTS.join('\n')}
601
602 void main() {
603 useGeneratedCode(new StaticConfiguration(
604 checkedMode: false));
605 startPolymer([]);
606 }
607 '''.replaceAll('\n ', '\n'),
608
609 });
610
611 testPhases('several scripts', phases, {
612 'a|web/test.html':
613 '<!DOCTYPE html><html><head>'
614 '</head><body><div></div>',
615 'a|web/test.html._data':
616 expectedData(['web/a.dart', 'web/b.dart', 'web/c.dart', 'web/d.dart'], experimental: true),
617 'a|web/d.dart':
618 'library d;\n'
619 'import "package:polymer/polymer.dart";\n'
620 '@initMethod main(){}\n@initMethod mD(){}',
621
622 'a|web/a.dart':
623 'import "package:polymer/polymer.dart";\n'
624 '@initMethod mA(){}\n',
625
626 'a|web/b.dart':
627 'import "package:polymer/polymer.dart";\n'
628 'export "e.dart";\n'
629 'export "f.dart" show XF1, mF1;\n'
630 'export "g.dart" hide XG1, mG1;\n'
631 'export "h.dart" show XH1, mH1 hide mH1, mH2;\n'
632 '@initMethod mB(){}\n',
633
634 'a|web/c.dart':
635 'import "package:polymer/polymer.dart";\n'
636 'part "c_part.dart";\n'
637 '@CustomTag("x-c1") class XC1 extends PolymerElement {}\n',
638
639 'a|web/c_part.dart':
640 '@CustomTag("x-c2") class XC2 extends PolymerElement {}\n',
641
642 'a|web/e.dart':
643 'import "package:polymer/polymer.dart";\n'
644 '@CustomTag("x-e") class XE extends PolymerElement {}\n'
645 '@initMethod mE(){}\n',
646
647 'a|web/f.dart':
648 'import "package:polymer/polymer.dart";\n'
649 '@CustomTag("x-f1") class XF1 extends PolymerElement {}\n'
650 '@initMethod mF1(){}\n'
651 '@CustomTag("x-f2") class XF2 extends PolymerElement {}\n'
652 '@initMethod mF2(){}\n',
653
654 'a|web/g.dart':
655 'import "package:polymer/polymer.dart";\n'
656 '@CustomTag("x-g1") class XG1 extends PolymerElement {}\n'
657 '@initMethod mG1(){}\n'
658 '@CustomTag("x-g2") class XG2 extends PolymerElement {}\n'
659 '@initMethod mG2(){}\n',
660
661 'a|web/h.dart':
662 'import "package:polymer/polymer.dart";\n'
663 '@CustomTag("x-h1") class XH1 extends PolymerElement {}\n'
664 '@initMethod mH1(){}\n'
665 '@CustomTag("x-h2") class XH2 extends PolymerElement {}\n'
666 '@initMethod mH2(){}\n',
667 }, {
668 'a|web/test.html':
669 '<!DOCTYPE html><html><head></head><body><div></div>'
670 '<script type="application/dart" src="test.html_bootstrap.dart">'
671 '</script>'
672 '</body></html>',
673
674 'a|web/test.html_bootstrap.dart':
675 '''$MAIN_HEADER
676 import 'a.dart' as i0;
677 import 'b.dart' as i1;
678 import 'c.dart' as i2;
679 import 'd.dart' as i3;
680 ${DEFAULT_IMPORTS.join('\n')}
681 import 'e.dart' as smoke_0;
682 import 'package:polymer/polymer.dart' as smoke_1;
683 import 'f.dart' as smoke_2;
684 import 'g.dart' as smoke_3;
685 import 'h.dart' as smoke_4;
686 import 'c.dart' as smoke_5;
687
688 void main() {
689 useGeneratedCode(new StaticConfiguration(
690 checkedMode: false,
691 parents: {
692 smoke_5.XC1: smoke_1.PolymerElement,
693 smoke_5.XC2: smoke_1.PolymerElement,
694 smoke_0.XE: smoke_1.PolymerElement,
695 smoke_2.XF1: smoke_1.PolymerElement,
696 smoke_3.XG2: smoke_1.PolymerElement,
697 smoke_4.XH1: smoke_1.PolymerElement,
698 },
699 declarations: {
700 smoke_5.XC1: {},
701 smoke_5.XC2: {},
702 smoke_0.XE: {},
703 smoke_2.XF1: {},
704 smoke_3.XG2: {},
705 smoke_4.XH1: {},
706 }));
707 startPolymer([
708 i0.mA,
709 i1.mB,
710 i1.mE,
711 i1.mF1,
712 i1.mG2,
713 () => Polymer.register('x-e', i1.XE),
714 () => Polymer.register('x-f1', i1.XF1),
715 () => Polymer.register('x-g2', i1.XG2),
716 () => Polymer.register('x-h1', i1.XH1),
717 () => Polymer.register('x-c1', i2.XC1),
718 () => Polymer.register('x-c2', i2.XC2),
719 i3.main,
720 i3.mD,
721 ]);
722 }
723 '''.replaceAll('\n ', '\n'),
724 }, null);
725 }
726
727 codegenTests(phases) {
728 testPhases('bindings', phases, {
729 'a|web/test.html':
730 '<!DOCTYPE html><html><body>'
731 '<polymer-element name="foo-bar"><template>'
732 '<div>{{a.node}}</div>'
733 '<div>{{ anotherNode }}</div>' // extra space inside bindings is OK
734 '<div>{{a.call1(a)}}</div>'
735 '<div>{{call2(a)}}</div>'
736 '<div>{{}}</div>' // empty bindings are ignored
737 '<div>{{ }}</div>'
738 '<div class="{{an.attribute}}"></div>'
739 '<a href="path/{{within.an.attribute}}/foo/bar"></a>'
740 '<div data-attribute="{{anotherAttribute}}"></div>'
741 // input and custom-element attributes are treated as 2-way bindings:
742 '<input value="{{this.iS.twoWay}}">'
743 '<input value="{{this.iS.twoWayInt | intToStringTransformer}}">'
744 '<something-else my-attribute="{{here.too}}"></something-else>'
745 '<div on-click="{{methodName}}"></div>'
746 '<div on-click="{{ methodName2 }}"></div>' // extra space is OK
747 // empty handlers are invalid, but we still produce valid output.
748 '<div on-click="{{}}"></div>'
749 '<div on-click="{{ }}"></div>'
750 '</template></polymer-element>',
751 'a|web/test.html._data': expectedData(['web/a.dart']),
752 'a|web/a.dart':
753 'library a;\n'
754 'import "package:polymer/polymer.dart";\n'
755 'main(){}',
756 }, {
757 'a|web/test.html_bootstrap.dart':
758 '''$MAIN_HEADER
759 import 'a.dart' as i0;
760 ${DEFAULT_IMPORTS.join('\n')}
761
762 void main() {
763 useGeneratedCode(new StaticConfiguration(
764 checkedMode: false,
765 getters: {
766 #a: (o) => o.a,
767 #an: (o) => o.an,
768 #anotherAttribute: (o) => o.anotherAttribute,
769 #anotherNode: (o) => o.anotherNode,
770 #attribute: (o) => o.attribute,
771 #call1: (o) => o.call1,
772 #call2: (o) => o.call2,
773 #here: (o) => o.here,
774 #iS: (o) => o.iS,
775 #intToStringTransformer: (o) => o.intToStringTransformer,
776 #methodName: (o) => o.methodName,
777 #methodName2: (o) => o.methodName2,
778 #node: (o) => o.node,
779 #too: (o) => o.too,
780 #twoWay: (o) => o.twoWay,
781 #twoWayInt: (o) => o.twoWayInt,
782 #within: (o) => o.within,
783 },
784 setters: {
785 #too: (o, v) { o.too = v; },
786 #twoWay: (o, v) { o.twoWay = v; },
787 #twoWayInt: (o, v) { o.twoWayInt = v; },
788 },
789 names: {
790 #a: r'a',
791 #an: r'an',
792 #anotherAttribute: r'anotherAttribute',
793 #anotherNode: r'anotherNode',
794 #attribute: r'attribute',
795 #call1: r'call1',
796 #call2: r'call2',
797 #here: r'here',
798 #iS: r'iS',
799 #intToStringTransformer: r'intToStringTransformer',
800 #methodName: r'methodName',
801 #methodName2: r'methodName2',
802 #node: r'node',
803 #too: r'too',
804 #twoWay: r'twoWay',
805 #twoWayInt: r'twoWayInt',
806 #within: r'within',
807 }));
808 configureForDeployment([]);
809 i0.main();
810 }
811 '''.replaceAll('\n ', '\n'),
812 'a|web/a.dart':
813 'library a;\n'
814 'import "package:polymer/polymer.dart";\n'
815 'main(){}',
816 });
817
818 computedDeclaration(name, expr) =>
819 '#$name: const Declaration(#$name, dynamic, kind: PROPERTY,'
820 ' isFinal: true, annotations: const [const smoke_1.ComputedProperty'
821 '(\'$expr\')])';
822
823 testPhases('computed properties', phases, {
824 'a|web/test.html':
825 '<!DOCTYPE html><html><body>'
826 '<polymer-element name="x-foo"><template>'
827 '</template></polymer-element>',
828 'a|web/test.html._data': expectedData(['web/a.dart']),
829 'a|web/a.dart':
830 'library a;\n'
831 'import "package:polymer/polymer.dart";\n'
832 '@CustomTag("x-foo")\n'
833 'class XFoo extends PolymerElement {\n'
834 ' @ComputedProperty("ta.tb")\n'
835 ' get pa => readValue(#pa);\n'
836 ' @ComputedProperty(" tc ")\n' // extra space inside is OK
837 ' get pb => null;\n'
838 ' @ComputedProperty("td.m1(te)")\n'
839 ' get pc => null;\n'
840 ' @ComputedProperty("m2(tf)")\n'
841 ' get pd => null;\n'
842 ' @ComputedProperty("")\n' // empty is ignored
843 ' get pe => null;\n'
844 ' @ComputedProperty(" ")\n'
845 ' get pf => null;\n'
846 ' @ComputedProperty("tg + th")\n'
847 ' get pg => null;\n'
848 ' @ComputedProperty("ti.tj | tk")\n'
849 ' get ph => null;\n'
850 '}\n'
851 'main(){}',
852 }, {
853 'a|web/test.html_bootstrap.dart':
854 '''$MAIN_HEADER
855 import 'a.dart' as i0;
856 ${DEFAULT_IMPORTS.join('\n')}
857 import 'a.dart' as smoke_0;
858 import 'package:polymer/polymer.dart' as smoke_1;
859
860 void main() {
861 useGeneratedCode(new StaticConfiguration(
862 checkedMode: false,
863 getters: {
864 #m1: (o) => o.m1,
865 #m2: (o) => o.m2,
866 #pa: (o) => o.pa,
867 #pb: (o) => o.pb,
868 #pc: (o) => o.pc,
869 #pd: (o) => o.pd,
870 #pe: (o) => o.pe,
871 #pf: (o) => o.pf,
872 #pg: (o) => o.pg,
873 #ph: (o) => o.ph,
874 #ta: (o) => o.ta,
875 #tb: (o) => o.tb,
876 #tc: (o) => o.tc,
877 #td: (o) => o.td,
878 #te: (o) => o.te,
879 #tf: (o) => o.tf,
880 #tg: (o) => o.tg,
881 #th: (o) => o.th,
882 #ti: (o) => o.ti,
883 #tj: (o) => o.tj,
884 #tk: (o) => o.tk,
885 },
886 setters: {
887 #tb: (o, v) { o.tb = v; },
888 #tc: (o, v) { o.tc = v; },
889 #tj: (o, v) { o.tj = v; },
890 },
891 parents: {
892 smoke_0.XFoo: smoke_1.PolymerElement,
893 },
894 declarations: {
895 smoke_0.XFoo: {
896 ${computedDeclaration('pa', 'ta.tb')},
897 ${computedDeclaration('pb', ' tc ')},
898 ${computedDeclaration('pc', 'td.m1(te)')},
899 ${computedDeclaration('pd', 'm2(tf)')},
900 ${computedDeclaration('pe', '')},
901 ${computedDeclaration('pf', ' ')},
902 ${computedDeclaration('pg', 'tg + th')},
903 ${computedDeclaration('ph', 'ti.tj | tk')},
904 },
905 },
906 names: {
907 #m1: r'm1',
908 #m2: r'm2',
909 #pa: r'pa',
910 #pb: r'pb',
911 #pc: r'pc',
912 #pd: r'pd',
913 #pe: r'pe',
914 #pf: r'pf',
915 #pg: r'pg',
916 #ph: r'ph',
917 #ta: r'ta',
918 #tb: r'tb',
919 #tc: r'tc',
920 #td: r'td',
921 #te: r'te',
922 #tf: r'tf',
923 #tg: r'tg',
924 #th: r'th',
925 #ti: r'ti',
926 #tj: r'tj',
927 #tk: r'tk',
928 }));
929 configureForDeployment([
930 () => Polymer.register(\'x-foo\', i0.XFoo),
931 ]);
932 i0.main();
933 }
934 '''.replaceAll('\n ', '\n'),
935 });
936
937 final field1Details = "annotations: const [smoke_1.published]";
938 final field3Details = "isFinal: true, annotations: const [smoke_1.published]";
939 final prop1Details = "kind: PROPERTY, annotations: const [smoke_1.published]";
940 final prop3Details =
941 "kind: PROPERTY, isFinal: true, annotations: const [smoke_1.published]";
942 testPhases('published via annotation', phases, {
943 'a|web/test.html':
944 '<!DOCTYPE html><html><body>',
945 'a|web/test.html._data': expectedData(['web/a.dart']),
946 'a|web/a.dart':
947 'library a;\n'
948 'import "package:polymer/polymer.dart";\n'
949 '@CustomTag("x-foo")\n'
950 'class XFoo extends PolymerElement {\n'
951 ' @published int field1;\n'
952 ' int field2;\n'
953 ' @published final int field3;\n'
954 ' final int field4;\n'
955 ' @published int get prop1 => 1;\n'
956 ' set prop1(int x) {};\n'
957 ' int get prop2 => 2;\n'
958 ' set prop2(int x) {};\n'
959 ' @published int get prop3 => 3;\n'
960 ' int get prop4 => 4;\n'
961 ' @published int method1() => 1;\n'
962 ' int method2() => 2;\n'
963 '}\n',
964 }, {
965 'a|web/test.html_bootstrap.dart':
966 '''$MAIN_HEADER
967 import 'a.dart' as i0;
968 ${DEFAULT_IMPORTS.join('\n')}
969 import 'a.dart' as smoke_0;
970 import 'package:polymer/polymer.dart' as smoke_1;
971
972 void main() {
973 useGeneratedCode(new StaticConfiguration(
974 checkedMode: false,
975 getters: {
976 #field1: (o) => o.field1,
977 #field3: (o) => o.field3,
978 #prop1: (o) => o.prop1,
979 #prop3: (o) => o.prop3,
980 },
981 setters: {
982 #field1: (o, v) { o.field1 = v; },
983 #prop1: (o, v) { o.prop1 = v; },
984 },
985 parents: {
986 smoke_0.XFoo: smoke_1.PolymerElement,
987 },
988 declarations: {
989 smoke_0.XFoo: {
990 #field1: const Declaration(#field1, int, $field1Details),
991 #field3: const Declaration(#field3, int, $field3Details),
992 #prop1: const Declaration(#prop1, int, $prop1Details),
993 #prop3: const Declaration(#prop3, int, $prop3Details),
994 },
995 },
996 names: {
997 #field1: r'field1',
998 #field3: r'field3',
999 #prop1: r'prop1',
1000 #prop3: r'prop3',
1001 }));
1002 configureForDeployment([
1003 () => Polymer.register(\'x-foo\', i0.XFoo),
1004 ]);
1005 i0.main();
1006 }
1007 '''.replaceAll('\n ', '\n'),
1008 });
1009
1010 testPhases('published via attributes', phases, {
1011 'a|web/test.html':
1012 '<!DOCTYPE html><html><body>'
1013 '<polymer-element name="x-foo" attributes="field1,prop2">'
1014 '</polymer-element>',
1015 'a|web/test.html._data': expectedData(['web/a.dart']),
1016 'a|web/a.dart':
1017 'library a;\n'
1018 'import "package:polymer/polymer.dart";\n'
1019 '@CustomTag("x-foo")\n'
1020 'class XFoo extends PolymerElement {\n'
1021 ' int field1;\n'
1022 ' int field2;\n'
1023 ' int get prop1 => 1;\n'
1024 ' set prop1(int x) {};\n'
1025 ' int get prop2 => 2;\n'
1026 ' set prop2(int x) {};\n'
1027 '}\n',
1028 }, {
1029 'a|web/test.html_bootstrap.dart':
1030 '''$MAIN_HEADER
1031 import 'a.dart' as i0;
1032 ${DEFAULT_IMPORTS.join('\n')}
1033 import 'a.dart' as smoke_0;
1034 import 'package:polymer/polymer.dart' as smoke_1;
1035
1036 void main() {
1037 useGeneratedCode(new StaticConfiguration(
1038 checkedMode: false,
1039 getters: {
1040 #field1: (o) => o.field1,
1041 #prop2: (o) => o.prop2,
1042 },
1043 setters: {
1044 #field1: (o, v) { o.field1 = v; },
1045 #prop2: (o, v) { o.prop2 = v; },
1046 },
1047 parents: {
1048 smoke_0.XFoo: smoke_1.PolymerElement,
1049 },
1050 declarations: {
1051 smoke_0.XFoo: {
1052 #field1: const Declaration(#field1, int),
1053 #prop2: const Declaration(#prop2, int, kind: PROPERTY),
1054 },
1055 },
1056 names: {
1057 #field1: r'field1',
1058 #prop2: r'prop2',
1059 }));
1060 configureForDeployment([
1061 () => Polymer.register(\'x-foo\', i0.XFoo),
1062 ]);
1063 i0.main();
1064 }
1065 '''.replaceAll('\n ', '\n'),
1066 });
1067
1068 final fooDetails =
1069 "kind: METHOD, annotations: const [const smoke_1.ObserveProperty('x')]";
1070 final xChangedDetails = "Function, kind: METHOD";
1071 testPhases('ObserveProperty and *Changed methods', phases, {
1072 'a|web/test.html':
1073 '<!DOCTYPE html><html><body>'
1074 '</polymer-element>',
1075 'a|web/test.html._data': expectedData(['web/a.dart']),
1076 'a|web/a.dart':
1077 'library a;\n'
1078 'import "package:polymer/polymer.dart";\n'
1079 '@CustomTag("x-foo")\n'
1080 'class XFoo extends PolymerElement {\n'
1081 ' int x;\n'
1082 ' void xChanged() {}\n'
1083 ' void attributeChanged() {}\n' // should be excluded
1084 ' @ObserveProperty("x")'
1085 ' void foo() {}\n'
1086 '}\n',
1087 }, {
1088 'a|web/test.html_bootstrap.dart':
1089 '''$MAIN_HEADER
1090 import 'a.dart' as i0;
1091 ${DEFAULT_IMPORTS.join('\n')}
1092 import 'a.dart' as smoke_0;
1093 import 'package:polymer/polymer.dart' as smoke_1;
1094
1095 void main() {
1096 useGeneratedCode(new StaticConfiguration(
1097 checkedMode: false,
1098 getters: {
1099 #foo: (o) => o.foo,
1100 #xChanged: (o) => o.xChanged,
1101 },
1102 parents: {
1103 smoke_0.XFoo: smoke_1.PolymerElement,
1104 },
1105 declarations: {
1106 smoke_0.XFoo: {
1107 #foo: const Declaration(#foo, Function, $fooDetails),
1108 #xChanged: const Declaration(#xChanged, $xChangedDetails),
1109 },
1110 },
1111 names: {
1112 #foo: r'foo',
1113 #xChanged: r'xChanged',
1114 }));
1115 configureForDeployment([
1116 () => Polymer.register(\'x-foo\', i0.XFoo),
1117 ]);
1118 i0.main();
1119 }
1120 '''.replaceAll('\n ', '\n'),
1121 });
1122
1123 final rcDetails = "#registerCallback, Function, kind: METHOD, isStatic: true";
1124 testPhases('register callback is included', phases, {
1125 'a|web/test.html':
1126 '<!DOCTYPE html><html><body>'
1127 '</polymer-element>',
1128 'a|web/test.html._data': expectedData(['web/a.dart']),
1129 'a|web/a.dart':
1130 'library a;\n'
1131 'import "package:polymer/polymer.dart";\n'
1132 '@CustomTag("x-foo")\n'
1133 'class XFoo extends PolymerElement {\n'
1134 ' static registerCallback() {};\n'
1135 ' static foo() {};\n'
1136 '}\n',
1137 }, {
1138 'a|web/test.html_bootstrap.dart':
1139 '''$MAIN_HEADER
1140 import 'a.dart' as i0;
1141 ${DEFAULT_IMPORTS.join('\n')}
1142 import 'a.dart' as smoke_0;
1143 import 'package:polymer/polymer.dart' as smoke_1;
1144
1145 void main() {
1146 useGeneratedCode(new StaticConfiguration(
1147 checkedMode: false,
1148 parents: {
1149 smoke_0.XFoo: smoke_1.PolymerElement,
1150 },
1151 declarations: {
1152 smoke_0.XFoo: {
1153 #registerCallback: const Declaration($rcDetails),
1154 },
1155 },
1156 staticMethods: {
1157 smoke_0.XFoo: {
1158 #registerCallback: smoke_0.XFoo.registerCallback,
1159 },
1160 },
1161 names: {
1162 #registerCallback: r'registerCallback',
1163 }));
1164 configureForDeployment([
1165 () => Polymer.register(\'x-foo\', i0.XFoo),
1166 ]);
1167 i0.main();
1168 }
1169 '''.replaceAll('\n ', '\n'),
1170 });
1171 }
1172
1173 void logElementInjectionTests() {
1174 final outputLogsPhases = [[new ScriptCompactor(
1175 new TransformOptions(injectBuildLogsInOutput: true, releaseMode: false),
1176 sdkDir: testingDartSdkDirectory)]];
1177
1178 testPhases('Injects logging element and styles', outputLogsPhases, {
1179 'a|web/test.html': '<!DOCTYPE html><html><head>',
1180 'a|web/test.html._data': expectedData(['web/a.dart']),
1181 'a|web/a.dart':
1182 'library a;\n'
1183 'import "package:polymer/polymer.dart";\n'
1184 'main(){}',
1185 }, {
1186 'a|web/test.html':
1187 '<!DOCTYPE html><html><head>'
1188 '<link rel="stylesheet" type="text/css" '
1189 'href="packages/polymer/src/build/log_injector.css">'
1190 '</head><body>'
1191 '<script type="application/dart" '
1192 'src="test.html_bootstrap.dart"></script>'
1193 '</body></html>',
1194 'a|web/test.html_bootstrap.dart':
1195 '''$MAIN_HEADER
1196 import 'a.dart' as i0;
1197 import 'package:polymer/src/build/log_injector.dart';
1198 ${DEFAULT_IMPORTS.join('\n')}
1199
1200 void main() {
1201 useGeneratedCode(new StaticConfiguration(
1202 checkedMode: false));
1203 new LogInjector().injectLogsFromUrl('test.html._buildLogs');
1204 configureForDeployment([]);
1205 i0.main();
1206 }
1207 '''.replaceAll('\n ', '\n'),
1208 'a|web/a.dart':
1209 'library a;\n'
1210 'import "package:polymer/polymer.dart";\n'
1211 'main(){}',
1212 });
1213 }
OLDNEW
« no previous file with comments | « pkg/polymer/test/build/polyfill_injector_test.dart ('k') | pkg/polymer/test/build/static_clean_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698