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

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

Issue 211393006: Enables codegen support in polymer (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/polymer/test/build/common.dart ('k') | pkg/polymer/test/prop_attr_reflection_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 library polymer.test.build.script_compactor_test; 5 library polymer.test.build.script_compactor_test;
6 6
7 import 'package:code_transformers/tests.dart' show testingDartSdkDirectory;
7 import 'package:polymer/src/build/common.dart'; 8 import 'package:polymer/src/build/common.dart';
8 import 'package:polymer/src/build/script_compactor.dart'; 9 import 'package:polymer/src/build/script_compactor.dart';
10 import 'package:smoke/codegen/generator.dart' show DEFAULT_IMPORTS;
9 import 'package:unittest/compact_vm_config.dart'; 11 import 'package:unittest/compact_vm_config.dart';
12 import 'package:unittest/unittest.dart';
10 13
11 import 'common.dart'; 14 import 'common.dart';
12 15
13 void main() { 16 void main() {
14 useCompactVMConfiguration(); 17 useCompactVMConfiguration();
15 var phases = [[new ScriptCompactor(new TransformOptions())]]; 18 var phases = [[new ScriptCompactor(new TransformOptions(),
19 sdkDir: testingDartSdkDirectory)]];
20 group('initializers', () => initializerTests(phases));
21 group('codegen', () => codegenTests(phases));
22 }
16 23
24 initializerTests(phases) {
17 testPhases('no changes', phases, { 25 testPhases('no changes', phases, {
18 'a|web/test.html': '<!DOCTYPE html><html></html>', 26 'a|web/test.html': '<!DOCTYPE html><html></html>',
19 'a|web/test.html.scriptUrls': '[]', 27 'a|web/test.html.scriptUrls': '[]',
20 }, { 28 }, {
21 'a|web/test.html': '<!DOCTYPE html><html></html>', 29 'a|web/test.html': '<!DOCTYPE html><html></html>',
22 }); 30 });
23 31
24 testPhases('no changes outside web/', phases, { 32 testPhases('no changes outside web/', phases, {
25 'a|lib/test.html': 33 'a|lib/test.html':
26 '<!DOCTYPE html><html><head>' 34 '<!DOCTYPE html><html><head>'
27 '<script type="application/dart" src="a.dart"></script>', 35 '<script type="application/dart" src="a.dart"></script>',
28 }, { 36 }, {
29 'a|lib/test.html': 37 'a|lib/test.html':
30 '<!DOCTYPE html><html><head>' 38 '<!DOCTYPE html><html><head>'
31 '<script type="application/dart" src="a.dart"></script>', 39 '<script type="application/dart" src="a.dart"></script>',
32 }); 40 });
33 41
34 testPhases('single script', phases, { 42 testPhases('single script', phases, {
35 'a|web/test.html': 43 'a|web/test.html':
36 '<!DOCTYPE html><html><head>' 44 '<!DOCTYPE html><html><head>'
37 '<script type="application/dart" src="a.dart"></script>', 45 '<script type="application/dart" src="a.dart"></script>',
38 'a|web/test.html.scriptUrls': '[]', 46 'a|web/test.html.scriptUrls': '[]',
39 'a|web/a.dart': 'library a;\nmain(){}', 47 'a|web/a.dart':
48 'library a;\n'
49 'import "package:polymer/polymer.dart";\n'
50 'main(){}',
40 }, { 51 }, {
41 'a|web/test.html': 52 'a|web/test.html':
42 '<!DOCTYPE html><html><head>' 53 '<!DOCTYPE html><html><head>'
43 '<script type="application/dart" ' 54 '<script type="application/dart" '
44 'src="test.html_bootstrap.dart"></script>' 55 'src="test.html_bootstrap.dart"></script>'
45 '</head><body></body></html>', 56 '</head><body></body></html>',
46 57
47 'a|web/test.html_bootstrap.dart': 58 'a|web/test.html_bootstrap.dart':
48 '''$MAIN_HEADER 59 '''$MAIN_HEADER
49 import 'a.dart' as i0; 60 import 'a.dart' as i0;
61 ${DEFAULT_IMPORTS.join('\n')}
50 62
51 void main() { 63 void main() {
64 useGeneratedCode(new StaticConfiguration(
65 checkedMode: false));
52 configureForDeployment([ 66 configureForDeployment([
53 ]); 67 ]);
54 i0.main(); 68 i0.main();
55 } 69 }
56 '''.replaceAll('\n ', '\n'), 70 '''.replaceAll('\n ', '\n'),
57 'a|web/a.dart': 'library a;\nmain(){}', 71 'a|web/a.dart':
72 'library a;\n'
73 'import "package:polymer/polymer.dart";\n'
74 'main(){}',
58 }); 75 });
59 76
77 testPhases('simple initialization', phases, {
78 'a|web/test.html':
79 '<!DOCTYPE html><html><head>'
80 '<script type="application/dart" src="a.dart"></script>',
81 'a|web/test.html.scriptUrls': '[]',
82 'a|web/a.dart':
83 'library a;\n'
84 'import "package:polymer/polymer.dart";\n'
85 '@CustomTag("x-foo")\n'
86 'class XFoo extends PolymerElement {\n'
87 '}\n'
88 'main(){}',
89 }, {
90 'a|web/test.html_bootstrap.dart':
91 '''$MAIN_HEADER
92 import 'a.dart' as i0;
93 ${DEFAULT_IMPORTS.join('\n')}
94 import 'a.dart' as smoke_0;
95 import 'package:polymer/polymer.dart' as smoke_1;
96
97 void main() {
98 useGeneratedCode(new StaticConfiguration(
99 checkedMode: false,
100 parents: {
101 smoke_0.XFoo: smoke_1.PolymerElement,
102 },
103 declarations: {
104 smoke_0.XFoo: const {},
105 }));
106 configureForDeployment([
107 () => Polymer.register(\'x-foo\', i0.XFoo),
108 ]);
109 i0.main();
110 }
111 '''.replaceAll('\n ', '\n'),
112 });
113
114 testPhases('use const expressions', phases, {
115 'a|web/test.html':
116 '<!DOCTYPE html><html><head>'
117 '<script type="application/dart" src="a.dart"></script>',
118 'a|web/test.html.scriptUrls': '[]',
119 'a|web/b.dart':
120 'library a;\n'
121 'const x = "x";\n',
122 'a|web/c.dart':
123 'part of a;\n'
124 'const dash = "-";\n',
125 'a|web/a.dart':
126 'library a;\n'
127 'import "package:polymer/polymer.dart";\n'
128 'import "b.dart";\n'
129 'part "c.dart";\n'
130 'const letterO = "o";\n'
131 '@CustomTag("\$x\${dash}f\${letterO}o2")\n'
132 'class XFoo extends PolymerElement {\n'
133 '}\n'
134 'main(){}',
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: const {},
151 }));
152 configureForDeployment([
153 () => Polymer.register(\'x-foo2\', i0.XFoo),
154 ]);
155 i0.main();
156 }
157 '''.replaceAll('\n ', '\n'),
158 });
159
160 testPhases('invalid const expression', phases, {
161 'a|web/test.html':
162 '<!DOCTYPE html><html><head>'
163 '<script type="application/dart" src="a.dart"></script>',
164 'a|web/test.html.scriptUrls': '[]',
165 'a|web/a.dart':
166 'library a;\n'
167 'import "package:polymer/polymer.dart";\n'
168 '@CustomTag("\${x}-foo")\n' // invalid, x is not defined
169 'class XFoo extends PolymerElement {\n'
170 '}\n'
171 'main(){}',
172 }, {}, [
173 'warning: The parameter to @CustomTag seems to be invalid. '
174 '(web/a.dart 2 11)',
175 ]);
176
60 testPhases('several scripts', phases, { 177 testPhases('several scripts', phases, {
61 'a|web/test.html': 178 'a|web/test.html':
62 '<!DOCTYPE html><html><head>' 179 '<!DOCTYPE html><html><head>'
63 '</head><body><div>' 180 '</head><body><div>'
64 '<script type="application/dart" src="d.dart"></script>' 181 '<script type="application/dart" src="d.dart"></script>'
65 '</div>', 182 '</div>',
66 'a|web/test.html.scriptUrls': 183 'a|web/test.html.scriptUrls':
67 '[["a", "web/a.dart"],["a", "web/b.dart"],["a", "web/c.dart"]]', 184 '[["a", "web/a.dart"],["a", "web/b.dart"],["a", "web/c.dart"]]',
68 'a|web/d.dart': 'library d;\nmain(){}\n@initMethod mD(){}', 185 'a|web/d.dart':
186 'library d;\n'
187 'import "package:polymer/polymer.dart";\n'
188 'main(){}\n@initMethod mD(){}',
69 189
70 'a|web/a.dart': 190 'a|web/a.dart':
71 'import "package:polymer/polymer.dart";\n' 191 'import "package:polymer/polymer.dart";\n'
72 '@initMethod mA(){}\n', 192 '@initMethod mA(){}\n',
73 193
74 'a|web/b.dart': 194 'a|web/b.dart':
195 'import "package:polymer/polymer.dart";\n'
75 'export "e.dart";\n' 196 'export "e.dart";\n'
76 'export "f.dart" show XF1, mF1;\n' 197 'export "f.dart" show XF1, mF1;\n'
77 'export "g.dart" hide XG1, mG1;\n' 198 'export "g.dart" hide XG1, mG1;\n'
78 'export "h.dart" show XH1, mH1 hide mH1, mH2;\n' 199 'export "h.dart" show XH1, mH1 hide mH1, mH2;\n'
79 '@initMethod mB(){}\n', 200 '@initMethod mB(){}\n',
80 201
81 'a|web/c.dart': 202 'a|web/c.dart':
82 'import "package:polymer/polymer.dart";\n' 203 'import "package:polymer/polymer.dart";\n'
83 'part "c_part.dart"\n' 204 'part "c_part.dart";\n'
84 '@CustomTag("x-c2") class XC2 {}\n', 205 '@CustomTag("x-c1") class XC1 extends PolymerElement {}\n',
85 206
86 'a|web/c_part.dart': 207 'a|web/c_part.dart':
87 '@CustomTag("x-c1") class XC1 {}\n', 208 '@CustomTag("x-c2") class XC2 extends PolymerElement {}\n',
88 209
89 'a|web/e.dart': 210 'a|web/e.dart':
90 'import "package:polymer/polymer.dart";\n' 211 'import "package:polymer/polymer.dart";\n'
91 '@CustomTag("x-e") class XE {}\n' 212 '@CustomTag("x-e") class XE extends PolymerElement {}\n'
92 '@initMethod mE(){}\n', 213 '@initMethod mE(){}\n',
93 214
94 'a|web/f.dart': 215 'a|web/f.dart':
95 'import "package:polymer/polymer.dart";\n' 216 'import "package:polymer/polymer.dart";\n'
96 '@CustomTag("x-f1") class XF1 {}\n' 217 '@CustomTag("x-f1") class XF1 extends PolymerElement {}\n'
97 '@initMethod mF1(){}\n' 218 '@initMethod mF1(){}\n'
98 '@CustomTag("x-f2") class XF2 {}\n' 219 '@CustomTag("x-f2") class XF2 extends PolymerElement {}\n'
99 '@initMethod mF2(){}\n', 220 '@initMethod mF2(){}\n',
100 221
101 'a|web/g.dart': 222 'a|web/g.dart':
102 'import "package:polymer/polymer.dart";\n' 223 'import "package:polymer/polymer.dart";\n'
103 '@CustomTag("x-g1") class XG1 {}\n' 224 '@CustomTag("x-g1") class XG1 extends PolymerElement {}\n'
104 '@initMethod mG1(){}\n' 225 '@initMethod mG1(){}\n'
105 '@CustomTag("x-g2") class XG2 {}\n' 226 '@CustomTag("x-g2") class XG2 extends PolymerElement {}\n'
106 '@initMethod mG2(){}\n', 227 '@initMethod mG2(){}\n',
107 228
108 'a|web/h.dart': 229 'a|web/h.dart':
109 'import "package:polymer/polymer.dart";\n' 230 'import "package:polymer/polymer.dart";\n'
110 '@CustomTag("x-h1") class XH1 {}\n' 231 '@CustomTag("x-h1") class XH1 extends PolymerElement {}\n'
111 '@initMethod mH1(){}\n' 232 '@initMethod mH1(){}\n'
112 '@CustomTag("x-h2") class XH2 {}\n' 233 '@CustomTag("x-h2") class XH2 extends PolymerElement {}\n'
113 '@initMethod mH2(){}\n', 234 '@initMethod mH2(){}\n',
114 }, { 235 }, {
115 'a|web/test.html': 236 'a|web/test.html':
116 '<!DOCTYPE html><html><head></head><body><div>' 237 '<!DOCTYPE html><html><head></head><body><div>'
117 '<script type="application/dart" src="test.html_bootstrap.dart">' 238 '<script type="application/dart" src="test.html_bootstrap.dart">'
118 '</script>' 239 '</script>'
119 '</div>' 240 '</div>'
120 '</body></html>', 241 '</body></html>',
121 242
122 'a|web/test.html_bootstrap.dart': 243 'a|web/test.html_bootstrap.dart':
123 '''$MAIN_HEADER 244 '''$MAIN_HEADER
124 import 'a.dart' as i0; 245 import 'a.dart' as i0;
125 import 'b.dart' as i1; 246 import 'b.dart' as i1;
126 import 'c.dart' as i2; 247 import 'c.dart' as i2;
127 import 'd.dart' as i3; 248 import 'd.dart' as i3;
249 ${DEFAULT_IMPORTS.join('\n')}
250 import 'e.dart' as smoke_0;
251 import 'package:polymer/polymer.dart' as smoke_1;
252 import 'f.dart' as smoke_2;
253 import 'g.dart' as smoke_3;
254 import 'h.dart' as smoke_4;
255 import 'c.dart' as smoke_5;
128 256
129 void main() { 257 void main() {
258 useGeneratedCode(new StaticConfiguration(
259 checkedMode: false,
260 parents: {
261 smoke_5.XC1: smoke_1.PolymerElement,
262 smoke_5.XC2: smoke_1.PolymerElement,
263 smoke_0.XE: smoke_1.PolymerElement,
264 smoke_2.XF1: smoke_1.PolymerElement,
265 smoke_3.XG2: smoke_1.PolymerElement,
266 smoke_4.XH1: smoke_1.PolymerElement,
267 },
268 declarations: {
269 smoke_5.XC1: const {},
270 smoke_5.XC2: const {},
271 smoke_0.XE: const {},
272 smoke_2.XF1: const {},
273 smoke_3.XG2: const {},
274 smoke_4.XH1: const {},
275 }));
130 configureForDeployment([ 276 configureForDeployment([
131 i0.mA, 277 i0.mA,
278 i1.mB,
279 i1.mE,
280 i1.mF1,
281 i1.mG2,
132 () => Polymer.register('x-e', i1.XE), 282 () => Polymer.register('x-e', i1.XE),
133 i1.mE,
134 () => Polymer.register('x-f1', i1.XF1), 283 () => Polymer.register('x-f1', i1.XF1),
135 i1.mF1,
136 () => Polymer.register('x-g2', i1.XG2), 284 () => Polymer.register('x-g2', i1.XG2),
137 i1.mG2,
138 () => Polymer.register('x-h1', i1.XH1), 285 () => Polymer.register('x-h1', i1.XH1),
139 i1.mB,
140 () => Polymer.register('x-c1', i2.XC1), 286 () => Polymer.register('x-c1', i2.XC1),
141 () => Polymer.register('x-c2', i2.XC2), 287 () => Polymer.register('x-c2', i2.XC2),
142 i3.mD, 288 i3.mD,
143 ]); 289 ]);
144 i3.main(); 290 i3.main();
145 } 291 }
146 '''.replaceAll('\n ', '\n'), 292 '''.replaceAll('\n ', '\n'),
147 }); 293 }, null);
148 } 294 }
295
296 codegenTests(phases) {
297 testPhases('bindings', phases, {
298 'a|web/test.html':
299 '<!DOCTYPE html><html><body>'
300 '<polymer-element name="foo-bar"><template>'
301 '<div>{{a.node}}</div>'
302 '<div>{{anotherNode}}</div>'
303 '<div class="{{an.attribute}}"></div>'
304 '<a href="path/{{within.an.attribute}}/foo/bar"></a>'
305 '<div data-attribute="{{anotherAttribute}}"></div>'
306 // input and custom-element attributes are treated as 2-way bindings:
307 '<input value="{{this.is.twoWay}}">'
308 '<something-else my-attribute="{{here.too}}"></something-else>'
309 '<div on-click="{{methodName}}"></div>'
310 '<div on-click="{{@read.method}}"></div>'
311 '</template></polymer-element>'
312 '<script type="application/dart" src="a.dart"></script>',
313 'a|web/test.html.scriptUrls': '[]',
314 'a|web/a.dart':
315 'library a;\n'
316 'import "package:polymer/polymer.dart";\n'
317 'main(){}',
318 }, {
319 'a|web/test.html_bootstrap.dart':
320 '''$MAIN_HEADER
321 import 'a.dart' as i0;
322 ${DEFAULT_IMPORTS.join('\n')}
323
324 void main() {
325 useGeneratedCode(new StaticConfiguration(
326 checkedMode: false,
327 getters: {
328 #a: (o) => o.a,
329 #an: (o) => o.an,
330 #anotherAttribute: (o) => o.anotherAttribute,
331 #anotherNode: (o) => o.anotherNode,
332 #attribute: (o) => o.attribute,
333 #here: (o) => o.here,
334 #is: (o) => o.is,
335 #method: (o) => o.method,
336 #methodName: (o) => o.methodName,
337 #node: (o) => o.node,
338 #read: (o) => o.read,
339 #too: (o) => o.too,
340 #twoWay: (o) => o.twoWay,
341 #within: (o) => o.within,
342 },
343 setters: {
344 #too: (o, v) { o.too = v; },
345 #twoWay: (o, v) { o.twoWay = v; },
346 },
347 names: {
348 #a: r'a',
349 #an: r'an',
350 #anotherAttribute: r'anotherAttribute',
351 #anotherNode: r'anotherNode',
352 #attribute: r'attribute',
353 #here: r'here',
354 #is: r'is',
355 #method: r'method',
356 #methodName: r'methodName',
357 #node: r'node',
358 #read: r'read',
359 #too: r'too',
360 #twoWay: r'twoWay',
361 #within: r'within',
362 }));
363 configureForDeployment([
364 ]);
365 i0.main();
366 }
367 '''.replaceAll('\n ', '\n'),
368 'a|web/a.dart':
369 'library a;\n'
370 'import "package:polymer/polymer.dart";\n'
371 'main(){}',
372 });
373
374 final field1Details = "annotations: const [smoke_1.published]";
375 final field3Details = "isFinal: true, annotations: const [smoke_1.published]";
376 final prop1Details = "kind: PROPERTY, annotations: const [smoke_1.published]";
377 final prop3Details =
378 "kind: PROPERTY, isFinal: true, annotations: const [smoke_1.published]";
379 testPhases('published via annotation', phases, {
380 'a|web/test.html':
381 '<!DOCTYPE html><html><body>'
382 '<script type="application/dart" src="a.dart"></script>',
383 'a|web/test.html.scriptUrls': '[]',
384 'a|web/a.dart':
385 'library a;\n'
386 'import "package:polymer/polymer.dart";\n'
387 '@CustomTag("x-foo")\n'
388 'class XFoo extends PolymerElement {\n'
389 ' @published int field1;\n'
390 ' int field2;\n'
391 ' @published final int field3;\n'
392 ' final int field4;\n'
393 ' @published int get prop1 => 1;\n'
394 ' set prop1(int x) {};\n'
395 ' int get prop2 => 2;\n'
396 ' set prop2(int x) {};\n'
397 ' @published int get prop3 => 3;\n'
398 ' int get prop4 => 4;\n'
399 ' @published int method1() => 1;\n'
400 ' int method2() => 2;\n'
401 '}\n'
402 'main(){}',
403 }, {
404 'a|web/test.html_bootstrap.dart':
405 '''$MAIN_HEADER
406 import 'a.dart' as i0;
407 ${DEFAULT_IMPORTS.join('\n')}
408 import 'a.dart' as smoke_0;
409 import 'package:polymer/polymer.dart' as smoke_1;
410
411 void main() {
412 useGeneratedCode(new StaticConfiguration(
413 checkedMode: false,
414 getters: {
415 #field1: (o) => o.field1,
416 #field3: (o) => o.field3,
417 #prop1: (o) => o.prop1,
418 #prop3: (o) => o.prop3,
419 },
420 setters: {
421 #field1: (o, v) { o.field1 = v; },
422 #prop1: (o, v) { o.prop1 = v; },
423 },
424 parents: {
425 smoke_0.XFoo: smoke_1.PolymerElement,
426 },
427 declarations: {
428 smoke_0.XFoo: {
429 #field1: const Declaration(#field1, int, $field1Details),
430 #field3: const Declaration(#field3, int, $field3Details),
431 #prop1: const Declaration(#prop1, int, $prop1Details),
432 #prop3: const Declaration(#prop3, int, $prop3Details),
433 },
434 },
435 names: {
436 #field1: r'field1',
437 #field3: r'field3',
438 #prop1: r'prop1',
439 #prop3: r'prop3',
440 }));
441 configureForDeployment([
442 () => Polymer.register(\'x-foo\', i0.XFoo),
443 ]);
444 i0.main();
445 }
446 '''.replaceAll('\n ', '\n'),
447 });
448
449 testPhases('published via attributes', phases, {
450 'a|web/test.html':
451 '<!DOCTYPE html><html><body>'
452 '<polymer-element name="x-foo" attributes="field1,prop2">'
453 '</polymer-element>'
454 '<script type="application/dart" src="a.dart"></script>',
455 'a|web/test.html.scriptUrls': '[]',
456 'a|web/a.dart':
457 'library a;\n'
458 'import "package:polymer/polymer.dart";\n'
459 '@CustomTag("x-foo")\n'
460 'class XFoo extends PolymerElement {\n'
461 ' int field1;\n'
462 ' int field2;\n'
463 ' int get prop1 => 1;\n'
464 ' set prop1(int x) {};\n'
465 ' int get prop2 => 2;\n'
466 ' set prop2(int x) {};\n'
467 '}\n'
468 'main(){}',
469 }, {
470 'a|web/test.html_bootstrap.dart':
471 '''$MAIN_HEADER
472 import 'a.dart' as i0;
473 ${DEFAULT_IMPORTS.join('\n')}
474 import 'a.dart' as smoke_0;
475 import 'package:polymer/polymer.dart' as smoke_1;
476
477 void main() {
478 useGeneratedCode(new StaticConfiguration(
479 checkedMode: false,
480 getters: {
481 #field1: (o) => o.field1,
482 #prop2: (o) => o.prop2,
483 },
484 setters: {
485 #field1: (o, v) { o.field1 = v; },
486 #prop2: (o, v) { o.prop2 = v; },
487 },
488 parents: {
489 smoke_0.XFoo: smoke_1.PolymerElement,
490 },
491 declarations: {
492 smoke_0.XFoo: {
493 #field1: const Declaration(#field1, int),
494 #prop2: const Declaration(#prop2, int, kind: PROPERTY),
495 },
496 },
497 names: {
498 #field1: r'field1',
499 #prop2: r'prop2',
500 }));
501 configureForDeployment([
502 () => Polymer.register(\'x-foo\', i0.XFoo),
503 ]);
504 i0.main();
505 }
506 '''.replaceAll('\n ', '\n'),
507 });
508
509 final fooDetails =
510 "kind: METHOD, annotations: const [const smoke_1.ObserveProperty('x')]";
511 final xChangedDetails = "Function, kind: METHOD";
512 testPhases('ObserveProperty and *Changed methods', phases, {
513 'a|web/test.html':
514 '<!DOCTYPE html><html><body>'
515 '</polymer-element>'
516 '<script type="application/dart" src="a.dart"></script>',
517 'a|web/test.html.scriptUrls': '[]',
518 'a|web/a.dart':
519 'library a;\n'
520 'import "package:polymer/polymer.dart";\n'
521 '@CustomTag("x-foo")\n'
522 'class XFoo extends PolymerElement {\n'
523 ' int x;\n'
524 ' void xChanged() {}\n'
525 ' void attributeChanged() {}\n' // should be excluded
526 ' @ObserveProperty("x")'
527 ' void foo() {}\n'
528 '}\n'
529 'main(){}',
530 }, {
531 'a|web/test.html_bootstrap.dart':
532 '''$MAIN_HEADER
533 import 'a.dart' as i0;
534 ${DEFAULT_IMPORTS.join('\n')}
535 import 'a.dart' as smoke_0;
536 import 'package:polymer/polymer.dart' as smoke_1;
537
538 void main() {
539 useGeneratedCode(new StaticConfiguration(
540 checkedMode: false,
541 getters: {
542 #foo: (o) => o.foo,
543 #xChanged: (o) => o.xChanged,
544 },
545 parents: {
546 smoke_0.XFoo: smoke_1.PolymerElement,
547 },
548 declarations: {
549 smoke_0.XFoo: {
550 #foo: const Declaration(#foo, Function, $fooDetails),
551 #xChanged: const Declaration(#xChanged, $xChangedDetails),
552 },
553 },
554 names: {
555 #foo: r'foo',
556 #xChanged: r'xChanged',
557 }));
558 configureForDeployment([
559 () => Polymer.register(\'x-foo\', i0.XFoo),
560 ]);
561 i0.main();
562 }
563 '''.replaceAll('\n ', '\n'),
564 });
565
566 final rcDetails = "#registerCallback, Function, kind: METHOD, isStatic: true";
567 testPhases('register callback is included', phases, {
568 'a|web/test.html':
569 '<!DOCTYPE html><html><body>'
570 '</polymer-element>'
571 '<script type="application/dart" src="a.dart"></script>',
572 'a|web/test.html.scriptUrls': '[]',
573 'a|web/a.dart':
574 'library a;\n'
575 'import "package:polymer/polymer.dart";\n'
576 '@CustomTag("x-foo")\n'
577 'class XFoo extends PolymerElement {\n'
578 ' static registerCallback() {};\n'
579 ' static foo() {};\n'
580 '}\n'
581 'main(){}',
582 }, {
583 'a|web/test.html_bootstrap.dart':
584 '''$MAIN_HEADER
585 import 'a.dart' as i0;
586 ${DEFAULT_IMPORTS.join('\n')}
587 import 'a.dart' as smoke_0;
588 import 'package:polymer/polymer.dart' as smoke_1;
589
590 void main() {
591 useGeneratedCode(new StaticConfiguration(
592 checkedMode: false,
593 parents: {
594 smoke_0.XFoo: smoke_1.PolymerElement,
595 },
596 declarations: {
597 smoke_0.XFoo: {
598 #registerCallback: const Declaration($rcDetails),
599 },
600 },
601 staticMethods: {
602 smoke_0.XFoo: {
603 #registerCallback: smoke_0.XFoo.registerCallback,
604 },
605 },
606 names: {
607 #registerCallback: r'registerCallback',
608 }));
609 configureForDeployment([
610 () => Polymer.register(\'x-foo\', i0.XFoo),
611 ]);
612 i0.main();
613 }
614 '''.replaceAll('\n ', '\n'),
615 });
616 }
OLDNEW
« no previous file with comments | « pkg/polymer/test/build/common.dart ('k') | pkg/polymer/test/prop_attr_reflection_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698