OLD | NEW |
(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.polymer_smoke_generator_test; |
| 6 |
| 7 import 'package:code_transformers/tests.dart' |
| 8 show testingDartSdkDirectory, StringFormatter; |
| 9 import 'package:polymer/src/build/common.dart'; |
| 10 import 'package:polymer/src/build/messages.dart'; |
| 11 import 'package:polymer/src/build/polymer_smoke_generator.dart'; |
| 12 import 'package:smoke/codegen/generator.dart' show DEFAULT_IMPORTS; |
| 13 import 'package:unittest/compact_vm_config.dart'; |
| 14 import 'package:unittest/unittest.dart'; |
| 15 |
| 16 import 'common.dart'; |
| 17 |
| 18 void main() { |
| 19 useCompactVMConfiguration(); |
| 20 var phases = [ |
| 21 [ |
| 22 new PolymerSmokeGeneratorTransformer(new TransformOptions(), |
| 23 sdkDir: testingDartSdkDirectory) |
| 24 ] |
| 25 ]; |
| 26 group('initializers', () => initializerTests(phases)); |
| 27 group('codegen', () => codegenTests(phases)); |
| 28 group('log element injection', logElementInjectionTests); |
| 29 } |
| 30 |
| 31 initializerTests(phases) { |
| 32 testPhases('no changes', phases, { |
| 33 'a|web/test.html': '<!DOCTYPE html><html></html>', |
| 34 }, {'a|web/test.html': '<!DOCTYPE html><html></html>',}); |
| 35 |
| 36 testPhases('no changes outside web/', phases, { |
| 37 'a|lib/test.html': '<!DOCTYPE html><html><head>' |
| 38 '<script type="application/dart" src="a.dart"></script>', |
| 39 }, { |
| 40 'a|lib/test.html': '<!DOCTYPE html><html><head>' |
| 41 '<script type="application/dart" src="a.dart"></script>', |
| 42 }); |
| 43 |
| 44 testPhases('single script', phases, { |
| 45 'a|web/test.html': '<!DOCTYPE html><html><head>' |
| 46 '<script type="application/dart" src="a.dart"></script>', |
| 47 'a|web/a.dart': 'library a;\n' |
| 48 'import "package:polymer/polymer.dart";\n' |
| 49 'main(){}', |
| 50 }, { |
| 51 'a|web/test.html': '<!DOCTYPE html><html><head>' |
| 52 '<script type="application/dart" src="test.html_bootstrap.dart">' |
| 53 '</script>' |
| 54 '</head><body></body></html>', |
| 55 'a|web/test.html_bootstrap.dart': '''$MAIN_HEADER |
| 56 import 'a.dart' as i0; |
| 57 ${DEFAULT_IMPORTS.join('\n')} |
| 58 import 'package:polymer/polymer.dart' as smoke_0; |
| 59 |
| 60 main() { |
| 61 useGeneratedCode(new StaticConfiguration( |
| 62 checkedMode: false, |
| 63 declarations: { |
| 64 smoke_0.PolymerElement: {}, |
| 65 })); |
| 66 configureForDeployment(); |
| 67 return i0.main(); |
| 68 } |
| 69 '''.replaceAll('\n ', '\n'), |
| 70 'a|web/a.dart': 'library a;\n' |
| 71 'import "package:polymer/polymer.dart";\n' |
| 72 'main(){}', |
| 73 }); |
| 74 |
| 75 testPhases('simple initialization', phases, { |
| 76 'a|web/test.html': '<!DOCTYPE html><html><head>' |
| 77 '<script type="application/dart" src="a.dart"></script>', |
| 78 'a|web/a.dart': 'library a;\n' |
| 79 'import "package:polymer/polymer.dart";\n' |
| 80 '@CustomTag("x-foo")\n' |
| 81 'class XFoo extends PolymerElement {\n' |
| 82 '}\n' |
| 83 'main(){}', |
| 84 }, { |
| 85 'a|web/test.html_bootstrap.dart': '''$MAIN_HEADER |
| 86 import 'a.dart' as i0; |
| 87 ${DEFAULT_IMPORTS.join('\n')} |
| 88 import 'package:polymer/polymer.dart' as smoke_0; |
| 89 import 'a.dart' as smoke_1; |
| 90 |
| 91 main() { |
| 92 useGeneratedCode(new StaticConfiguration( |
| 93 checkedMode: false, |
| 94 parents: { |
| 95 smoke_1.XFoo: smoke_0.PolymerElement, |
| 96 }, |
| 97 declarations: { |
| 98 smoke_1.XFoo: {}, |
| 99 smoke_0.PolymerElement: {}, |
| 100 })); |
| 101 configureForDeployment(); |
| 102 return i0.main(); |
| 103 } |
| 104 '''.replaceAll('\n ', '\n'), |
| 105 }); |
| 106 |
| 107 testPhases('simple initialization of imports and exports', phases, { |
| 108 'a|web/test.html': '<!DOCTYPE html><html><head>' |
| 109 '<script type="application/dart" src="a.dart"></script>', |
| 110 'a|web/a.dart': ''' |
| 111 library a; |
| 112 import "package:polymer/polymer.dart"; |
| 113 import 'b.dart'; |
| 114 |
| 115 @CustomTag("x-a") |
| 116 class XA extends PolymerElement {} |
| 117 main(){}'''.replaceAll('\n ', '\n'), |
| 118 'a|web/b.dart': ''' |
| 119 library b; |
| 120 import "package:polymer/polymer.dart"; |
| 121 export 'c.dart'; |
| 122 |
| 123 @CustomTag("x-b") |
| 124 class XB extends PolymerElement {} |
| 125 ''', |
| 126 'a|web/c.dart': ''' |
| 127 library c; |
| 128 import "package:polymer/polymer.dart"; |
| 129 |
| 130 @CustomTag("x-c") |
| 131 class XC extends PolymerElement {} |
| 132 ''', |
| 133 }, { |
| 134 'a|web/test.html_bootstrap.dart': '''$MAIN_HEADER |
| 135 import 'a.dart' as i0; |
| 136 ${DEFAULT_IMPORTS.join('\n')} |
| 137 import 'package:polymer/polymer.dart' as smoke_0; |
| 138 import 'c.dart' as smoke_1; |
| 139 import 'b.dart' as smoke_2; |
| 140 import 'a.dart' as smoke_3; |
| 141 |
| 142 main() { |
| 143 useGeneratedCode(new StaticConfiguration( |
| 144 checkedMode: false, |
| 145 parents: { |
| 146 smoke_3.XA: smoke_0.PolymerElement, |
| 147 smoke_2.XB: smoke_0.PolymerElement, |
| 148 smoke_1.XC: smoke_0.PolymerElement, |
| 149 }, |
| 150 declarations: { |
| 151 smoke_3.XA: {}, |
| 152 smoke_2.XB: {}, |
| 153 smoke_1.XC: {}, |
| 154 smoke_0.PolymerElement: {}, |
| 155 })); |
| 156 configureForDeployment(); |
| 157 return i0.main(); |
| 158 } |
| 159 '''.replaceAll('\n ', '\n'), |
| 160 }); |
| 161 |
| 162 testPhases('use const expressions', phases, { |
| 163 'a|web/test.html': '<!DOCTYPE html><html><head>' |
| 164 '<script type="application/dart" src="a.dart"></script>', |
| 165 'a|web/b.dart': 'library a;\n' |
| 166 'const x = "x";\n', |
| 167 'a|web/c.dart': 'part of a;\n' |
| 168 'const dash = "-";\n', |
| 169 'a|web/a.dart': 'library a;\n' |
| 170 'import "package:polymer/polymer.dart";\n' |
| 171 'import "b.dart";\n' |
| 172 'part "c.dart";\n' |
| 173 'const letterO = "o";\n' |
| 174 '@CustomTag("\$x\${dash}f\${letterO}o2")\n' |
| 175 'class XFoo extends PolymerElement {\n' |
| 176 '}\n', |
| 177 }, { |
| 178 'a|web/test.html_bootstrap.dart': '''$MAIN_HEADER |
| 179 import 'a.dart' as i0; |
| 180 ${DEFAULT_IMPORTS.join('\n')} |
| 181 import 'package:polymer/polymer.dart' as smoke_0; |
| 182 import 'a.dart' as smoke_1; |
| 183 |
| 184 main() { |
| 185 useGeneratedCode(new StaticConfiguration( |
| 186 checkedMode: false, |
| 187 parents: { |
| 188 smoke_1.XFoo: smoke_0.PolymerElement, |
| 189 }, |
| 190 declarations: { |
| 191 smoke_1.XFoo: {}, |
| 192 smoke_0.PolymerElement: {}, |
| 193 })); |
| 194 configureForDeployment(); |
| 195 return i0.main(); |
| 196 } |
| 197 '''.replaceAll('\n ', '\n'), |
| 198 }); |
| 199 |
| 200 testLogOutput((options) => new PolymerSmokeGeneratorTransformer(options, |
| 201 sdkDir: testingDartSdkDirectory), 'invalid const expression logs', { |
| 202 'a|web/test.html': '<!DOCTYPE html><html><head>' |
| 203 '<script type="application/dart" src="a.dart"></script>', |
| 204 'a|web/a.dart': 'library a;\n' |
| 205 'import "package:polymer/polymer.dart";\n' |
| 206 '@CustomTag("\${x}-foo")\n' // invalid, x is not defined |
| 207 'class XFoo extends PolymerElement {\n' |
| 208 '}\n' |
| 209 'main(){}', |
| 210 }, {}, [ |
| 211 'warning: ${INVALID_ANNOTATION_ARGUMENT.create( |
| 212 {'name': 'CustomTag'}).snippet} (web/a.dart 2 11)', |
| 213 ]); |
| 214 |
| 215 testPhases('invalid const expression', phases, { |
| 216 'a|web/test.html': '<!DOCTYPE html><html><head>' |
| 217 '<script type="application/dart" src="a.dart"></script>', |
| 218 'a|web/a.dart': 'library a;\n' |
| 219 'import "package:polymer/polymer.dart";\n' |
| 220 '@CustomTag("\${x}-foo")\n' // invalid, x is not defined |
| 221 'class XFoo extends PolymerElement {\n' |
| 222 '}\n' |
| 223 'main(){}', |
| 224 }, { |
| 225 'a|web/test.html_bootstrap.dart': '''$MAIN_HEADER |
| 226 import 'a.dart' as i0; |
| 227 ${DEFAULT_IMPORTS.join('\n')} |
| 228 import 'package:polymer/polymer.dart' as smoke_0; |
| 229 import 'a.dart' as smoke_1; |
| 230 |
| 231 main() { |
| 232 useGeneratedCode(new StaticConfiguration( |
| 233 checkedMode: false, |
| 234 parents: { |
| 235 smoke_1.XFoo: smoke_0.PolymerElement, |
| 236 }, |
| 237 declarations: { |
| 238 smoke_1.XFoo: {}, |
| 239 smoke_0.PolymerElement: {}, |
| 240 })); |
| 241 configureForDeployment(); |
| 242 return i0.main(); |
| 243 } |
| 244 '''.replaceAll('\n ', '\n'), |
| 245 }); |
| 246 |
| 247 testPhases('no polymer import (warning, but no crash)', phases, { |
| 248 'a|web/test.html': '<!DOCTYPE html><html><head>' |
| 249 '<script type="application/dart" src="a.dart"></script>', |
| 250 'a|web/a.dart': 'library a;\n' |
| 251 'import "package:polymer/polymer.broken.import.dart";\n' |
| 252 '@CustomTag("x-foo")\n' |
| 253 'class XFoo extends PolymerElement {\n' |
| 254 '}\n' |
| 255 'main(){}', |
| 256 }, { |
| 257 'a|web/test.html': '<!DOCTYPE html><html><head>' |
| 258 '<script type="application/dart" src="test.html_bootstrap.dart">' |
| 259 '</script></head><body></body></html>', |
| 260 'a|web/test.html_bootstrap.dart': '''$MAIN_HEADER |
| 261 import 'a.dart' as i0; |
| 262 ${DEFAULT_IMPORTS.join('\n')} |
| 263 |
| 264 main() { |
| 265 useGeneratedCode(new StaticConfiguration( |
| 266 checkedMode: false)); |
| 267 configureForDeployment(); |
| 268 return i0.main(); |
| 269 } |
| 270 '''.replaceAll('\n ', '\n'), |
| 271 }, ['warning: ${MISSING_POLYMER_DART.snippet}']); |
| 272 } |
| 273 |
| 274 codegenTests(phases) { |
| 275 testPhases('bindings', phases, { |
| 276 'a|web/test.html': '<!DOCTYPE html><html>' |
| 277 '<head>' |
| 278 '<link rel="import" href="foo_remote.html">' |
| 279 '</head><body>' |
| 280 '<polymer-element name="foo-bar"><template>' |
| 281 '<div>{{a.node}}</div>' |
| 282 '<div>{{ anotherNode }}</div>' // extra space inside bindings is OK |
| 283 '<div>{{a.call1(a)}}</div>' |
| 284 '<div>{{call2(a)}}</div>' |
| 285 '<div>{{}}</div>' // empty bindings are ignored |
| 286 '<div>{{ }}</div>' |
| 287 '<div class="{{an.attribute}}"></div>' |
| 288 '<a href="path/{{within.an.attribute}}/foo/bar"></a>' |
| 289 '<div data-attribute="{{anotherAttribute}}"></div>' |
| 290 // input and custom-element attributes are treated as 2-way bindings: |
| 291 '<input value="{{this.iS.twoWay}}">' |
| 292 '<input value="{{this.iS.twoWayInt | intToStringTransformer}}">' |
| 293 '<something-else my-attribute="{{here.too}}"></something-else>' |
| 294 '<div on-click="{{methodName}}"></div>' |
| 295 '<div on-click="{{ methodName2 }}"></div>' // extra space is OK |
| 296 // empty handlers are invalid, but we still produce valid output. |
| 297 '<div on-click="{{}}"></div>' |
| 298 '<div on-click="{{ }}"></div>' |
| 299 '</template></polymer-element>' |
| 300 '<script type="application/dart" src="a.dart"></script>', |
| 301 'a|web/foo_remote.html': '<polymer-element name="foo-remote"><template>' |
| 302 '<div>{{remoteValue}}</div>' |
| 303 '</template></polymer-element>', |
| 304 'a|web/a.dart': 'library a;\n' |
| 305 'import "package:polymer/polymer.dart";\n' |
| 306 'main(){}', |
| 307 }, { |
| 308 'a|web/test.html_bootstrap.dart': '''$MAIN_HEADER |
| 309 import 'a.dart' as i0; |
| 310 ${DEFAULT_IMPORTS.join('\n')} |
| 311 import 'package:polymer/polymer.dart' as smoke_0; |
| 312 |
| 313 main() { |
| 314 useGeneratedCode(new StaticConfiguration( |
| 315 checkedMode: false, |
| 316 getters: { |
| 317 #a: (o) => o.a, |
| 318 #an: (o) => o.an, |
| 319 #anotherAttribute: (o) => o.anotherAttribute, |
| 320 #anotherNode: (o) => o.anotherNode, |
| 321 #attribute: (o) => o.attribute, |
| 322 #call1: (o) => o.call1, |
| 323 #call2: (o) => o.call2, |
| 324 #here: (o) => o.here, |
| 325 #iS: (o) => o.iS, |
| 326 #intToStringTransformer: (o) => o.intToStringTransformer, |
| 327 #methodName: (o) => o.methodName, |
| 328 #methodName2: (o) => o.methodName2, |
| 329 #node: (o) => o.node, |
| 330 #remoteValue: (o) => o.remoteValue, |
| 331 #too: (o) => o.too, |
| 332 #twoWay: (o) => o.twoWay, |
| 333 #twoWayInt: (o) => o.twoWayInt, |
| 334 #within: (o) => o.within, |
| 335 }, |
| 336 setters: { |
| 337 #too: (o, v) { o.too = v; }, |
| 338 #twoWay: (o, v) { o.twoWay = v; }, |
| 339 #twoWayInt: (o, v) { o.twoWayInt = v; }, |
| 340 }, |
| 341 declarations: { |
| 342 smoke_0.PolymerElement: {}, |
| 343 }, |
| 344 names: { |
| 345 #a: r'a', |
| 346 #an: r'an', |
| 347 #anotherAttribute: r'anotherAttribute', |
| 348 #anotherNode: r'anotherNode', |
| 349 #attribute: r'attribute', |
| 350 #call1: r'call1', |
| 351 #call2: r'call2', |
| 352 #here: r'here', |
| 353 #iS: r'iS', |
| 354 #intToStringTransformer: r'intToStringTransformer', |
| 355 #methodName: r'methodName', |
| 356 #methodName2: r'methodName2', |
| 357 #node: r'node', |
| 358 #remoteValue: r'remoteValue', |
| 359 #too: r'too', |
| 360 #twoWay: r'twoWay', |
| 361 #twoWayInt: r'twoWayInt', |
| 362 #within: r'within', |
| 363 })); |
| 364 configureForDeployment(); |
| 365 return i0.main(); |
| 366 } |
| 367 '''.replaceAll('\n ', '\n'), |
| 368 }); |
| 369 |
| 370 computedDeclaration(name, expr) => |
| 371 '#$name: const Declaration(#$name, Object, kind: PROPERTY,' |
| 372 ' isFinal: true, annotations: const [const smoke_0.ComputedProperty' |
| 373 '(\'$expr\')])'; |
| 374 |
| 375 testPhases('computed properties', phases, { |
| 376 'a|web/test.html': '<!DOCTYPE html><html><body>' |
| 377 '<polymer-element name="x-foo"><template>' |
| 378 '</template></polymer-element>' |
| 379 '<script type="application/dart" src="a.dart"></script>', |
| 380 'a|web/a.dart': 'library a;\n' |
| 381 'import "package:polymer/polymer.dart";\n' |
| 382 '@CustomTag("x-foo")\n' |
| 383 'class XFoo extends PolymerElement {\n' |
| 384 ' @ComputedProperty("ta.tb")\n' |
| 385 ' get pa => readValue(#pa);\n' |
| 386 ' @ComputedProperty(" tc ")\n' // extra space inside is OK |
| 387 ' get pb => null;\n' |
| 388 ' @ComputedProperty("td.m1(te)")\n' |
| 389 ' get pc => null;\n' |
| 390 ' @ComputedProperty("m2(tf)")\n' |
| 391 ' get pd => null;\n' |
| 392 ' @ComputedProperty("")\n' // empty is ignored |
| 393 ' get pe => null;\n' |
| 394 ' @ComputedProperty(" ")\n' |
| 395 ' get pf => null;\n' |
| 396 ' @ComputedProperty("tg + th")\n' |
| 397 ' get pg => null;\n' |
| 398 ' @ComputedProperty("ti.tj | tk")\n' |
| 399 ' get ph => null;\n' |
| 400 '}\n' |
| 401 'main(){}', |
| 402 }, { |
| 403 'a|web/test.html_bootstrap.dart': '''$MAIN_HEADER |
| 404 import 'a.dart' as i0; |
| 405 ${DEFAULT_IMPORTS.join('\n')} |
| 406 import 'package:polymer/polymer.dart' as smoke_0; |
| 407 import 'a.dart' as smoke_1; |
| 408 |
| 409 main() { |
| 410 useGeneratedCode(new StaticConfiguration( |
| 411 checkedMode: false, |
| 412 getters: { |
| 413 #m1: (o) => o.m1, |
| 414 #m2: (o) => o.m2, |
| 415 #pa: (o) => o.pa, |
| 416 #pb: (o) => o.pb, |
| 417 #pc: (o) => o.pc, |
| 418 #pd: (o) => o.pd, |
| 419 #pe: (o) => o.pe, |
| 420 #pf: (o) => o.pf, |
| 421 #pg: (o) => o.pg, |
| 422 #ph: (o) => o.ph, |
| 423 #ta: (o) => o.ta, |
| 424 #tb: (o) => o.tb, |
| 425 #tc: (o) => o.tc, |
| 426 #td: (o) => o.td, |
| 427 #te: (o) => o.te, |
| 428 #tf: (o) => o.tf, |
| 429 #tg: (o) => o.tg, |
| 430 #th: (o) => o.th, |
| 431 #ti: (o) => o.ti, |
| 432 #tj: (o) => o.tj, |
| 433 #tk: (o) => o.tk, |
| 434 }, |
| 435 setters: { |
| 436 #tb: (o, v) { o.tb = v; }, |
| 437 #tc: (o, v) { o.tc = v; }, |
| 438 #tj: (o, v) { o.tj = v; }, |
| 439 }, |
| 440 parents: { |
| 441 smoke_1.XFoo: smoke_0.PolymerElement, |
| 442 }, |
| 443 declarations: { |
| 444 smoke_1.XFoo: { |
| 445 ${computedDeclaration('pa', 'ta.tb')}, |
| 446 ${computedDeclaration('pb', ' tc ')}, |
| 447 ${computedDeclaration('pc', 'td.m1(te)')}, |
| 448 ${computedDeclaration('pd', 'm2(tf)')}, |
| 449 ${computedDeclaration('pe', '')}, |
| 450 ${computedDeclaration('pf', ' ')}, |
| 451 ${computedDeclaration('pg', 'tg + th')}, |
| 452 ${computedDeclaration('ph', 'ti.tj | tk')}, |
| 453 }, |
| 454 smoke_0.PolymerElement: {}, |
| 455 }, |
| 456 names: { |
| 457 #m1: r'm1', |
| 458 #m2: r'm2', |
| 459 #pa: r'pa', |
| 460 #pb: r'pb', |
| 461 #pc: r'pc', |
| 462 #pd: r'pd', |
| 463 #pe: r'pe', |
| 464 #pf: r'pf', |
| 465 #pg: r'pg', |
| 466 #ph: r'ph', |
| 467 #ta: r'ta', |
| 468 #tb: r'tb', |
| 469 #tc: r'tc', |
| 470 #td: r'td', |
| 471 #te: r'te', |
| 472 #tf: r'tf', |
| 473 #tg: r'tg', |
| 474 #th: r'th', |
| 475 #ti: r'ti', |
| 476 #tj: r'tj', |
| 477 #tk: r'tk', |
| 478 })); |
| 479 configureForDeployment(); |
| 480 return i0.main(); |
| 481 } |
| 482 '''.replaceAll('\n ', '\n'), |
| 483 }); |
| 484 |
| 485 final field1Details = "annotations: const [smoke_0.published]"; |
| 486 final field3Details = "isFinal: true, annotations: const [smoke_0.published]"; |
| 487 final prop1Details = "kind: PROPERTY, annotations: const [smoke_0.published]"; |
| 488 final prop3Details = |
| 489 "kind: PROPERTY, isFinal: true, annotations: const [smoke_0.published]"; |
| 490 testPhases('published via annotation', phases, { |
| 491 'a|web/test.html': '<!DOCTYPE html><html><body>' |
| 492 '<script type="application/dart" src="a.dart"></script>', |
| 493 'a|web/a.dart': 'library a;\n' |
| 494 'import "package:polymer/polymer.dart";\n' |
| 495 '@CustomTag("x-foo")\n' |
| 496 'class XFoo extends PolymerElement {\n' |
| 497 ' @published int field1;\n' |
| 498 ' int field2;\n' |
| 499 ' @published final int field3;\n' |
| 500 ' final int field4;\n' |
| 501 ' @published int get prop1 => 1;\n' |
| 502 ' set prop1(int x) {};\n' |
| 503 ' int get prop2 => 2;\n' |
| 504 ' set prop2(int x) {};\n' |
| 505 ' @published int get prop3 => 3;\n' |
| 506 ' int get prop4 => 4;\n' |
| 507 ' @published int method1() => 1;\n' |
| 508 ' int method2() => 2;\n' |
| 509 '}\n', |
| 510 }, { |
| 511 'a|web/test.html_bootstrap.dart': '''$MAIN_HEADER |
| 512 import 'a.dart' as i0; |
| 513 ${DEFAULT_IMPORTS.join('\n')} |
| 514 import 'package:polymer/polymer.dart' as smoke_0; |
| 515 import 'a.dart' as smoke_1; |
| 516 |
| 517 main() { |
| 518 useGeneratedCode(new StaticConfiguration( |
| 519 checkedMode: false, |
| 520 getters: { |
| 521 #field1: (o) => o.field1, |
| 522 #field3: (o) => o.field3, |
| 523 #prop1: (o) => o.prop1, |
| 524 #prop3: (o) => o.prop3, |
| 525 }, |
| 526 setters: { |
| 527 #field1: (o, v) { o.field1 = v; }, |
| 528 #prop1: (o, v) { o.prop1 = v; }, |
| 529 }, |
| 530 parents: { |
| 531 smoke_1.XFoo: smoke_0.PolymerElement, |
| 532 }, |
| 533 declarations: { |
| 534 smoke_1.XFoo: { |
| 535 #field1: const Declaration(#field1, int, $field1Details), |
| 536 #field3: const Declaration(#field3, int, $field3Details), |
| 537 #prop1: const Declaration(#prop1, int, $prop1Details), |
| 538 #prop3: const Declaration(#prop3, int, $prop3Details), |
| 539 }, |
| 540 smoke_0.PolymerElement: {}, |
| 541 }, |
| 542 names: { |
| 543 #field1: r'field1', |
| 544 #field3: r'field3', |
| 545 #prop1: r'prop1', |
| 546 #prop3: r'prop3', |
| 547 })); |
| 548 configureForDeployment(); |
| 549 return i0.main(); |
| 550 } |
| 551 '''.replaceAll('\n ', '\n'), |
| 552 }); |
| 553 |
| 554 testPhases('published via attributes', phases, { |
| 555 'a|web/test.html': '<!DOCTYPE html><html><body>' |
| 556 '<polymer-element name="x-foo" attributes="field1,prop2">' |
| 557 '</polymer-element>' |
| 558 '<script type="application/dart" src="a.dart"></script>', |
| 559 'a|web/a.dart': 'library a;\n' |
| 560 'import "package:polymer/polymer.dart";\n' |
| 561 '@CustomTag("x-foo")\n' |
| 562 'class XFoo extends PolymerElement {\n' |
| 563 ' int field1;\n' |
| 564 ' int field2;\n' |
| 565 ' int get prop1 => 1;\n' |
| 566 ' set prop1(int x) {};\n' |
| 567 ' int get prop2 => 2;\n' |
| 568 ' set prop2(int x) {};\n' |
| 569 '}\n', |
| 570 }, { |
| 571 'a|web/test.html_bootstrap.dart': '''$MAIN_HEADER |
| 572 import 'a.dart' as i0; |
| 573 ${DEFAULT_IMPORTS.join('\n')} |
| 574 import 'package:polymer/polymer.dart' as smoke_0; |
| 575 import 'a.dart' as smoke_1; |
| 576 |
| 577 main() { |
| 578 useGeneratedCode(new StaticConfiguration( |
| 579 checkedMode: false, |
| 580 getters: { |
| 581 #field1: (o) => o.field1, |
| 582 #prop2: (o) => o.prop2, |
| 583 }, |
| 584 setters: { |
| 585 #field1: (o, v) { o.field1 = v; }, |
| 586 #prop2: (o, v) { o.prop2 = v; }, |
| 587 }, |
| 588 parents: { |
| 589 smoke_1.XFoo: smoke_0.PolymerElement, |
| 590 }, |
| 591 declarations: { |
| 592 smoke_1.XFoo: { |
| 593 #field1: const Declaration(#field1, int), |
| 594 #prop2: const Declaration(#prop2, int, kind: PROPERTY), |
| 595 }, |
| 596 smoke_0.PolymerElement: {}, |
| 597 }, |
| 598 names: { |
| 599 #field1: r'field1', |
| 600 #prop2: r'prop2', |
| 601 })); |
| 602 configureForDeployment(); |
| 603 return i0.main(); |
| 604 } |
| 605 '''.replaceAll('\n ', '\n'), |
| 606 }); |
| 607 |
| 608 final fooDetails = |
| 609 "kind: METHOD, annotations: const [const smoke_0.ObserveProperty('x')]"; |
| 610 final xChangedDetails = "Function, kind: METHOD"; |
| 611 testPhases('ObserveProperty and *Changed methods', phases, { |
| 612 'a|web/test.html': '<!DOCTYPE html><html><body>' |
| 613 '</polymer-element>' |
| 614 '<script type="application/dart" src="a.dart"></script>', |
| 615 'a|web/a.dart': 'library a;\n' |
| 616 'import "package:polymer/polymer.dart";\n' |
| 617 '@CustomTag("x-foo")\n' |
| 618 'class XFoo extends PolymerElement {\n' |
| 619 ' int x;\n' |
| 620 ' void xChanged() {}\n' |
| 621 ' void attributeChanged() {}\n' // should be excluded |
| 622 ' @ObserveProperty("x")' |
| 623 ' void foo() {}\n' |
| 624 '}\n', |
| 625 }, { |
| 626 'a|web/test.html_bootstrap.dart': '''$MAIN_HEADER |
| 627 import 'a.dart' as i0; |
| 628 ${DEFAULT_IMPORTS.join('\n')} |
| 629 import 'package:polymer/polymer.dart' as smoke_0; |
| 630 import 'a.dart' as smoke_1; |
| 631 |
| 632 main() { |
| 633 useGeneratedCode(new StaticConfiguration( |
| 634 checkedMode: false, |
| 635 getters: { |
| 636 #foo: (o) => o.foo, |
| 637 #xChanged: (o) => o.xChanged, |
| 638 }, |
| 639 parents: { |
| 640 smoke_1.XFoo: smoke_0.PolymerElement, |
| 641 }, |
| 642 declarations: { |
| 643 smoke_1.XFoo: { |
| 644 #foo: const Declaration(#foo, Function, $fooDetails), |
| 645 #xChanged: const Declaration(#xChanged, $xChangedDetails), |
| 646 }, |
| 647 smoke_0.PolymerElement: {}, |
| 648 }, |
| 649 names: { |
| 650 #foo: r'foo', |
| 651 #xChanged: r'xChanged', |
| 652 })); |
| 653 configureForDeployment(); |
| 654 return i0.main(); |
| 655 } |
| 656 '''.replaceAll('\n ', '\n'), |
| 657 }); |
| 658 |
| 659 final rcDetails = "#registerCallback, Function, kind: METHOD, isStatic: true"; |
| 660 testPhases('register callback is included', phases, { |
| 661 'a|web/test.html': '<!DOCTYPE html><html><body>' |
| 662 '</polymer-element>' |
| 663 '<script type="application/dart" src="a.dart"></script>', |
| 664 'a|web/a.dart': 'library a;\n' |
| 665 'import "package:polymer/polymer.dart";\n' |
| 666 '@CustomTag("x-foo")\n' |
| 667 'class XFoo extends PolymerElement {\n' |
| 668 ' static registerCallback() {};\n' |
| 669 ' static foo() {};\n' |
| 670 '}\n', |
| 671 }, { |
| 672 'a|web/test.html_bootstrap.dart': '''$MAIN_HEADER |
| 673 import 'a.dart' as i0; |
| 674 ${DEFAULT_IMPORTS.join('\n')} |
| 675 import 'package:polymer/polymer.dart' as smoke_0; |
| 676 import 'a.dart' as smoke_1; |
| 677 |
| 678 main() { |
| 679 useGeneratedCode(new StaticConfiguration( |
| 680 checkedMode: false, |
| 681 parents: { |
| 682 smoke_1.XFoo: smoke_0.PolymerElement, |
| 683 }, |
| 684 declarations: { |
| 685 smoke_1.XFoo: { |
| 686 #registerCallback: const Declaration($rcDetails), |
| 687 }, |
| 688 smoke_0.PolymerElement: {}, |
| 689 }, |
| 690 staticMethods: { |
| 691 smoke_1.XFoo: { |
| 692 #registerCallback: smoke_1.XFoo.registerCallback, |
| 693 }, |
| 694 }, |
| 695 names: { |
| 696 #registerCallback: r'registerCallback', |
| 697 })); |
| 698 configureForDeployment(); |
| 699 return i0.main(); |
| 700 } |
| 701 '''.replaceAll('\n ', '\n'), |
| 702 }); |
| 703 } |
| 704 |
| 705 void logElementInjectionTests() { |
| 706 final outputLogsPhases = [ |
| 707 [ |
| 708 new PolymerSmokeGeneratorTransformer(new TransformOptions( |
| 709 injectBuildLogsInOutput: true, releaseMode: false), |
| 710 sdkDir: testingDartSdkDirectory) |
| 711 ] |
| 712 ]; |
| 713 |
| 714 testPhases('Injects logging element and styles', outputLogsPhases, { |
| 715 'a|web/test.html': '<!DOCTYPE html><html><head>' |
| 716 '<script type="application/dart" src="a.dart"></script>', |
| 717 'a|web/a.dart': 'library a;\n' |
| 718 'import "package:polymer/polymer.dart";\n' |
| 719 'main(){}', |
| 720 }, { |
| 721 'a|web/test.html': '<!DOCTYPE html><html><head>' |
| 722 '<script type="application/dart" ' |
| 723 'src="test.html_bootstrap.dart"></script>' |
| 724 '<link rel="stylesheet" type="text/css" ' |
| 725 'href="packages/polymer/src/build/log_injector.css">' |
| 726 '</head><body>' |
| 727 '</body></html>', |
| 728 'a|web/test.html_bootstrap.dart': '''$MAIN_HEADER |
| 729 import 'package:polymer/src/build/log_injector.dart'; |
| 730 import 'a.dart' as i0; |
| 731 ${DEFAULT_IMPORTS.join('\n')} |
| 732 import 'package:polymer/polymer.dart' as smoke_0; |
| 733 |
| 734 main() { |
| 735 useGeneratedCode(new StaticConfiguration( |
| 736 checkedMode: false, |
| 737 declarations: { |
| 738 smoke_0.PolymerElement: {}, |
| 739 })); |
| 740 new LogInjector().injectLogsFromUrl('test.html._buildLogs'); |
| 741 configureForDeployment(); |
| 742 return i0.main(); |
| 743 } |
| 744 '''.replaceAll('\n ', '\n'), |
| 745 'a|web/a.dart': 'library a;\n' |
| 746 'import "package:polymer/polymer.dart";\n' |
| 747 'main(){}', |
| 748 }); |
| 749 } |
OLD | NEW |