| 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 library initialize.transformer_test; | 4 library initialize.transformer_test; |
| 5 | 5 |
| 6 import 'common.dart'; | 6 import 'common.dart'; |
| 7 import 'package:initialize/transformer.dart'; | 7 import 'package:initialize/transformer.dart'; |
| 8 import 'package:unittest/compact_vm_config.dart'; | 8 import 'package:unittest/compact_vm_config.dart'; |
| 9 | 9 |
| 10 main() { | 10 main() { |
| 11 useCompactVMConfiguration(); | 11 useCompactVMConfiguration(); |
| 12 | 12 |
| 13 var transformer = new InitializeTransformer( | 13 var htmlTransformer = new InitializeTransformer(['web/*.html']); |
| 14 'web/index.dart', 'web/index.bootstrap.dart', 'web/index.html'); | 14 var dartTransformer = new InitializeTransformer(['web/index.dart']); |
| 15 | 15 |
| 16 testPhases('basic', [[transformer]], { | 16 testPhases('basic', [[htmlTransformer]], { |
| 17 'a|web/index.html': ''' | 17 'a|web/index.html': ''' |
| 18 <html><head></head><body> | 18 <html><head></head><body> |
| 19 <script type="application/dart" src="index.dart"></script> | 19 <script type="application/dart" src="index.dart"></script> |
| 20 </body></html> | 20 </body></html> |
| 21 '''.replaceAll(' ', ''), | 21 '''.replaceAll(' ', ''), |
| 22 'a|web/index.dart': ''' | 22 'a|web/index.dart': ''' |
| 23 library web_foo; | 23 library web_foo; |
| 24 | 24 |
| 25 import 'foo.dart'; | 25 import 'foo.dart'; |
| 26 ''', | 26 ''', |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 library baz; | 60 library baz; |
| 61 | 61 |
| 62 import 'package:test_initializers/common.dart'; | 62 import 'package:test_initializers/common.dart'; |
| 63 ''', | 63 ''', |
| 64 // Mock out the Initialize package plus some initializers. | 64 // Mock out the Initialize package plus some initializers. |
| 65 'initialize|lib/initialize.dart': mockInitialize, | 65 'initialize|lib/initialize.dart': mockInitialize, |
| 66 'test_initializers|lib/common.dart': commonInitializers, | 66 'test_initializers|lib/common.dart': commonInitializers, |
| 67 }, { | 67 }, { |
| 68 'a|web/index.html': ''' | 68 'a|web/index.html': ''' |
| 69 <html><head></head><body> | 69 <html><head></head><body> |
| 70 <script type="application/dart" src="index.bootstrap.dart"></script> | 70 <script type="application/dart" src="index.initialize.dart"></script> |
| 71 | 71 |
| 72 </body></html>'''.replaceAll(' ', ''), | 72 </body></html>'''.replaceAll(' ', ''), |
| 73 'a|web/index.bootstrap.dart': ''' | 73 'a|web/index.initialize.dart': ''' |
| 74 import 'package:initialize/src/static_loader.dart'; | 74 import 'package:initialize/src/static_loader.dart'; |
| 75 import 'package:initialize/initialize.dart'; | 75 import 'package:initialize/initialize.dart'; |
| 76 import 'index.dart' as i0; | 76 import 'index.dart' as i0; |
| 77 import 'package:bar/baz.dart' as i1; | 77 import 'package:bar/baz.dart' as i1; |
| 78 import 'package:test_initializers/common.dart' as i2; | 78 import 'package:test_initializers/common.dart' as i2; |
| 79 import 'package:bar/bar.dart' as i3; | 79 import 'package:bar/bar.dart' as i3; |
| 80 import 'package:initialize/initialize.dart' as i4; | 80 import 'package:initialize/initialize.dart' as i4; |
| 81 import 'foo.dart' as i5; | 81 import 'foo.dart' as i5; |
| 82 | 82 |
| 83 main() { | 83 main() { |
| 84 initializers.addAll([ | 84 initializers.addAll([ |
| 85 new InitEntry(i2.constInit, const LibraryIdentifier(#baz, 'bar', 'ba
z.dart')), | 85 new InitEntry(i2.constInit, const LibraryIdentifier(#baz, 'bar', 'ba
z.dart')), |
| 86 new InitEntry(const i2.DynamicInit('bar'), const LibraryIdentifier(#
bar, 'bar', 'bar.dart')), | 86 new InitEntry(const i2.DynamicInit('bar'), const LibraryIdentifier(#
bar, 'bar', 'bar.dart')), |
| 87 new InitEntry(const i2.DynamicInit('bar2'), const LibraryIdentifier(
#bar, 'bar', 'bar.dart')), | 87 new InitEntry(const i2.DynamicInit('bar2'), const LibraryIdentifier(
#bar, 'bar', 'bar.dart')), |
| 88 new InitEntry(const i2.DynamicInit('bar()'), i3.bar), | 88 new InitEntry(const i2.DynamicInit('bar()'), i3.bar), |
| 89 new InitEntry(i4.initMethod, i3.bar), | 89 new InitEntry(i4.initMethod, i3.bar), |
| 90 new InitEntry(const i2.DynamicInit('Bar'), i3.Bar), | 90 new InitEntry(const i2.DynamicInit('Bar'), i3.Bar), |
| 91 new InitEntry(const i2.DynamicInit('Bar2'), i3.Bar), | 91 new InitEntry(const i2.DynamicInit('Bar2'), i3.Bar), |
| 92 new InitEntry(i2.constInit, const LibraryIdentifier(#foo, null, 'foo
.dart')), | 92 new InitEntry(i2.constInit, const LibraryIdentifier(#foo, null, 'foo
.dart')), |
| 93 new InitEntry(i4.initMethod, i5.foo), | 93 new InitEntry(i4.initMethod, i5.foo), |
| 94 new InitEntry(i2.constInit, i5.Foo), | 94 new InitEntry(i2.constInit, i5.Foo), |
| 95 ]); | 95 ]); |
| 96 | 96 |
| 97 i0.main(); | 97 i0.main(); |
| 98 } | 98 } |
| 99 '''.replaceAll(' ', '') | 99 '''.replaceAll(' ', '') |
| 100 }, []); | 100 }, []); |
| 101 | 101 |
| 102 testPhases('constructor arguments', [[transformer]], { | 102 testPhases('constructor arguments', [[dartTransformer]], { |
| 103 'a|web/index.dart': ''' | 103 'a|web/index.dart': ''' |
| 104 @DynamicInit(foo) | 104 @DynamicInit(foo) |
| 105 @DynamicInit(Foo.foo) | 105 @DynamicInit(Foo.foo) |
| 106 @DynamicInit(const [foo, Foo.foo, 'foo']) | 106 @DynamicInit(const [foo, Foo.foo, 'foo']) |
| 107 @DynamicInit(const {'foo': foo, 'Foo.foo': Foo.foo, 'bar': 'bar'}) | 107 @DynamicInit(const {'foo': foo, 'Foo.foo': Foo.foo, 'bar': 'bar'}) |
| 108 @DynamicInit('foo') | 108 @DynamicInit('foo') |
| 109 @DynamicInit(true) | 109 @DynamicInit(true) |
| 110 @DynamicInit(null) | 110 @DynamicInit(null) |
| 111 @DynamicInit(1) | 111 @DynamicInit(1) |
| 112 @DynamicInit(1.1) | 112 @DynamicInit(1.1) |
| 113 @NamedArgInit(1, name: 'Bill') | 113 @NamedArgInit(1, name: 'Bill') |
| 114 library web_foo; | 114 library web_foo; |
| 115 | 115 |
| 116 import 'package:test_initializers/common.dart'; | 116 import 'package:test_initializers/common.dart'; |
| 117 import 'foo.dart'; | 117 import 'foo.dart'; |
| 118 ''', | 118 ''', |
| 119 'a|web/foo.dart': ''' | 119 'a|web/foo.dart': ''' |
| 120 library foo; | 120 library foo; |
| 121 | 121 |
| 122 const String foo = 'foo'; | 122 const String foo = 'foo'; |
| 123 | 123 |
| 124 class Foo { | 124 class Foo { |
| 125 static foo = 'Foo.foo'; | 125 static foo = 'Foo.foo'; |
| 126 } | 126 } |
| 127 ''', | 127 ''', |
| 128 // Mock out the Initialize package plus some initializers. | 128 // Mock out the Initialize package plus some initializers. |
| 129 'initialize|lib/initialize.dart': mockInitialize, | 129 'initialize|lib/initialize.dart': mockInitialize, |
| 130 'test_initializers|lib/common.dart': commonInitializers, | 130 'test_initializers|lib/common.dart': commonInitializers, |
| 131 }, { | 131 }, { |
| 132 'a|web/index.bootstrap.dart': ''' | 132 'a|web/index.initialize.dart': ''' |
| 133 import 'package:initialize/src/static_loader.dart'; | 133 import 'package:initialize/src/static_loader.dart'; |
| 134 import 'package:initialize/initialize.dart'; | 134 import 'package:initialize/initialize.dart'; |
| 135 import 'index.dart' as i0; | 135 import 'index.dart' as i0; |
| 136 import 'package:test_initializers/common.dart' as i1; | 136 import 'package:test_initializers/common.dart' as i1; |
| 137 import 'foo.dart' as i2; | 137 import 'foo.dart' as i2; |
| 138 | 138 |
| 139 main() { | 139 main() { |
| 140 initializers.addAll([ | 140 initializers.addAll([ |
| 141 new InitEntry(const i1.DynamicInit(i2.foo), const LibraryIdentifier(
#web_foo, null, 'index.dart')), | 141 new InitEntry(const i1.DynamicInit(i2.foo), const LibraryIdentifier(
#web_foo, null, 'index.dart')), |
| 142 new InitEntry(const i1.DynamicInit(i2.Foo.foo), const LibraryIdentif
ier(#web_foo, null, 'index.dart')), | 142 new InitEntry(const i1.DynamicInit(i2.Foo.foo), const LibraryIdentif
ier(#web_foo, null, 'index.dart')), |
| 143 new InitEntry(const i1.DynamicInit(const [i2.foo, i2.Foo.foo, 'foo']
), const LibraryIdentifier(#web_foo, null, 'index.dart')), | 143 new InitEntry(const i1.DynamicInit(const [i2.foo, i2.Foo.foo, 'foo']
), const LibraryIdentifier(#web_foo, null, 'index.dart')), |
| 144 new InitEntry(const i1.DynamicInit(const {'foo': i2.foo, 'Foo.foo':
i2.Foo.foo, 'bar': 'bar'}), const LibraryIdentifier(#web_foo, null, 'index.dart'
)), | 144 new InitEntry(const i1.DynamicInit(const {'foo': i2.foo, 'Foo.foo':
i2.Foo.foo, 'bar': 'bar'}), const LibraryIdentifier(#web_foo, null, 'index.dart'
)), |
| 145 new InitEntry(const i1.DynamicInit('foo'), const LibraryIdentifier(#
web_foo, null, 'index.dart')), | 145 new InitEntry(const i1.DynamicInit('foo'), const LibraryIdentifier(#
web_foo, null, 'index.dart')), |
| 146 new InitEntry(const i1.DynamicInit(true), const LibraryIdentifier(#w
eb_foo, null, 'index.dart')), | 146 new InitEntry(const i1.DynamicInit(true), const LibraryIdentifier(#w
eb_foo, null, 'index.dart')), |
| 147 new InitEntry(const i1.DynamicInit(null), const LibraryIdentifier(#w
eb_foo, null, 'index.dart')), | 147 new InitEntry(const i1.DynamicInit(null), const LibraryIdentifier(#w
eb_foo, null, 'index.dart')), |
| 148 new InitEntry(const i1.DynamicInit(1), const LibraryIdentifier(#web_
foo, null, 'index.dart')), | 148 new InitEntry(const i1.DynamicInit(1), const LibraryIdentifier(#web_
foo, null, 'index.dart')), |
| 149 new InitEntry(const i1.DynamicInit(1.1), const LibraryIdentifier(#we
b_foo, null, 'index.dart')), | 149 new InitEntry(const i1.DynamicInit(1.1), const LibraryIdentifier(#we
b_foo, null, 'index.dart')), |
| 150 new InitEntry(const i1.NamedArgInit(1, name: 'Bill'), const LibraryI
dentifier(#web_foo, null, 'index.dart')), | 150 new InitEntry(const i1.NamedArgInit(1, name: 'Bill'), const LibraryI
dentifier(#web_foo, null, 'index.dart')), |
| 151 ]); | 151 ]); |
| 152 | 152 |
| 153 i0.main(); | 153 i0.main(); |
| 154 } | 154 } |
| 155 '''.replaceAll(' ', '') | 155 '''.replaceAll(' ', '') |
| 156 }, []); | 156 }, []); |
| 157 } | 157 } |
| OLD | NEW |