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:analyzer/src/generated/element.dart'; | 7 import 'package:analyzer/src/generated/element.dart'; |
8 import 'package:dart_style/dart_style.dart'; | 8 import 'package:dart_style/dart_style.dart'; |
9 import 'package:initialize/transformer.dart'; | 9 import 'package:initialize/transformer.dart'; |
10 import 'package:unittest/compact_vm_config.dart'; | 10 import 'package:unittest/compact_vm_config.dart'; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 }, []); | 110 }, []); |
111 } | 111 } |
112 | 112 |
113 void dartEntryPointTests() { | 113 void dartEntryPointTests() { |
114 var phases = [[new InitializeTransformer(['web/index.dart'])]]; | 114 var phases = [[new InitializeTransformer(['web/index.dart'])]]; |
115 | 115 |
116 testPhases('constructor arguments', phases, { | 116 testPhases('constructor arguments', phases, { |
117 'a|web/index.dart': ''' | 117 'a|web/index.dart': ''' |
118 @DynamicInit(foo) | 118 @DynamicInit(foo) |
119 @DynamicInit(Foo.foo) | 119 @DynamicInit(Foo.foo) |
| 120 @DynamicInit(bar.Foo.bar) |
| 121 @DynamicInit(bar.Foo.foo) |
120 @DynamicInit(const [foo, Foo.foo, 'foo']) | 122 @DynamicInit(const [foo, Foo.foo, 'foo']) |
121 @DynamicInit(const {'foo': foo, 'Foo.foo': Foo.foo, 'bar': 'bar'}) | 123 @DynamicInit(const {'foo': foo, 'Foo.foo': Foo.foo, 'bar': 'bar'}) |
122 @DynamicInit('foo') | 124 @DynamicInit('foo') |
123 @DynamicInit(true) | 125 @DynamicInit(true) |
124 @DynamicInit(null) | 126 @DynamicInit(null) |
125 @DynamicInit(1) | 127 @DynamicInit(1) |
126 @DynamicInit(1.1) | 128 @DynamicInit(1.1) |
| 129 @DynamicInit('foo-\$x\${y}') |
| 130 @DynamicInit(1 + 2) |
| 131 @DynamicInit(1.0 + 0.2) |
| 132 @DynamicInit(1 == 1) |
127 @NamedArgInit(1, name: 'Bill') | 133 @NamedArgInit(1, name: 'Bill') |
128 library web_foo; | 134 library web_foo; |
129 | 135 |
130 import 'package:test_initializers/common.dart'; | 136 import 'package:test_initializers/common.dart'; |
131 import 'foo.dart'; | 137 import 'foo.dart'; |
| 138 import 'foo.dart' as bar; |
| 139 |
| 140 const x = 'x'; |
| 141 const y = 'y'; |
| 142 |
| 143 class MyConst { |
| 144 const MyConst; |
| 145 } |
132 ''', | 146 ''', |
133 'a|web/foo.dart': ''' | 147 'a|web/foo.dart': ''' |
134 library foo; | 148 library foo; |
135 | 149 |
136 const String foo = 'foo'; | 150 const String foo = 'foo'; |
137 | 151 |
| 152 class Bar { |
| 153 const Bar(); |
| 154 } |
| 155 |
138 class Foo { | 156 class Foo { |
139 static foo = 'Foo.foo'; | 157 static foo = 'Foo.foo'; |
| 158 static bar = const Bar(); |
140 } | 159 } |
141 ''', | 160 ''', |
142 // Mock out the Initialize package plus some initializers. | 161 // Mock out the Initialize package plus some initializers. |
143 'initialize|lib/initialize.dart': mockInitialize, | 162 'initialize|lib/initialize.dart': mockInitialize, |
144 'test_initializers|lib/common.dart': commonInitializers, | 163 'test_initializers|lib/common.dart': commonInitializers, |
145 }, { | 164 }, { |
146 'a|web/index.initialize.dart': formatter.format(''' | 165 'a|web/index.initialize.dart': formatter.format(''' |
147 import 'package:initialize/src/static_loader.dart'; | 166 import 'package:initialize/src/static_loader.dart'; |
148 import 'package:initialize/initialize.dart'; | 167 import 'package:initialize/initialize.dart'; |
149 import 'index.dart' as i0; | 168 import 'index.dart' as i0; |
150 import 'package:test_initializers/common.dart' as i1; | 169 import 'package:test_initializers/common.dart' as i1; |
151 import 'foo.dart' as i2; | 170 import 'foo.dart' as i2; |
152 | 171 |
153 main() { | 172 main() { |
154 initializers.addAll([ | 173 initializers.addAll([ |
155 new InitEntry(const i1.DynamicInit(i2.foo), const LibraryIdentifier(
#web_foo, null, 'index.dart')), | 174 new InitEntry(const i1.DynamicInit(i2.foo), const LibraryIdentifier(
#web_foo, null, 'index.dart')), |
156 new InitEntry(const i1.DynamicInit(i2.Foo.foo), const LibraryIdentif
ier(#web_foo, null, 'index.dart')), | 175 new InitEntry(const i1.DynamicInit(i2.Foo.foo), const LibraryIdentif
ier(#web_foo, null, 'index.dart')), |
| 176 new InitEntry(const i1.DynamicInit(i2.Foo.bar), const LibraryIdentif
ier(#web_foo, null, 'index.dart')), |
| 177 new InitEntry(const i1.DynamicInit(i2.Foo.foo), const LibraryIdentif
ier(#web_foo, null, 'index.dart')), |
157 new InitEntry(const i1.DynamicInit(const [i2.foo, i2.Foo.foo, 'foo']
), const LibraryIdentifier(#web_foo, null, 'index.dart')), | 178 new InitEntry(const i1.DynamicInit(const [i2.foo, i2.Foo.foo, 'foo']
), const LibraryIdentifier(#web_foo, null, 'index.dart')), |
158 new InitEntry(const i1.DynamicInit(const {'foo': i2.foo, 'Foo.foo':
i2.Foo.foo, 'bar': 'bar'}), const LibraryIdentifier(#web_foo, null, 'index.dart'
)), | 179 new InitEntry(const i1.DynamicInit(const {'foo': i2.foo, 'Foo.foo':
i2.Foo.foo, 'bar': 'bar'}), const LibraryIdentifier(#web_foo, null, 'index.dart'
)), |
159 new InitEntry(const i1.DynamicInit('foo'), const LibraryIdentifier(#
web_foo, null, 'index.dart')), | 180 new InitEntry(const i1.DynamicInit('foo'), const LibraryIdentifier(#
web_foo, null, 'index.dart')), |
160 new InitEntry(const i1.DynamicInit(true), const LibraryIdentifier(#w
eb_foo, null, 'index.dart')), | 181 new InitEntry(const i1.DynamicInit(true), const LibraryIdentifier(#w
eb_foo, null, 'index.dart')), |
161 new InitEntry(const i1.DynamicInit(null), const LibraryIdentifier(#w
eb_foo, null, 'index.dart')), | 182 new InitEntry(const i1.DynamicInit(null), const LibraryIdentifier(#w
eb_foo, null, 'index.dart')), |
162 new InitEntry(const i1.DynamicInit(1), const LibraryIdentifier(#web_
foo, null, 'index.dart')), | 183 new InitEntry(const i1.DynamicInit(1), const LibraryIdentifier(#web_
foo, null, 'index.dart')), |
163 new InitEntry(const i1.DynamicInit(1.1), const LibraryIdentifier(#we
b_foo, null, 'index.dart')), | 184 new InitEntry(const i1.DynamicInit(1.1), const LibraryIdentifier(#we
b_foo, null, 'index.dart')), |
| 185 new InitEntry(const i1.DynamicInit('foo-xy'), const LibraryIdentifie
r(#web_foo, null, 'index.dart')), |
| 186 new InitEntry(const i1.DynamicInit(3), const LibraryIdentifier(#web_
foo, null, 'index.dart')), |
| 187 new InitEntry(const i1.DynamicInit(1.2), const LibraryIdentifier(#we
b_foo, null, 'index.dart')), |
| 188 new InitEntry(const i1.DynamicInit(true), const LibraryIdentifier(#w
eb_foo, null, 'index.dart')), |
164 new InitEntry(const i1.NamedArgInit(1, name: 'Bill'), const LibraryI
dentifier(#web_foo, null, 'index.dart')), | 189 new InitEntry(const i1.NamedArgInit(1, name: 'Bill'), const LibraryI
dentifier(#web_foo, null, 'index.dart')), |
165 ]); | 190 ]); |
166 | 191 |
167 i0.main(); | 192 i0.main(); |
168 } | 193 } |
169 ''') | 194 ''') |
170 }, []); | 195 }, []); |
171 } | 196 } |
172 | 197 |
173 class SkipConstructorsPlugin extends InitializerPlugin { | 198 class SkipConstructorsPlugin extends InitializerPlugin { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 initializers.addAll([ | 249 initializers.addAll([ |
225 new InitEntry(i2.initMethod, i1.foo), | 250 new InitEntry(i2.initMethod, i1.foo), |
226 new InitEntry(i2.initMethod, i0.index), | 251 new InitEntry(i2.initMethod, i0.index), |
227 ]); | 252 ]); |
228 | 253 |
229 i0.main(); | 254 i0.main(); |
230 } | 255 } |
231 ''') | 256 ''') |
232 }, []); | 257 }, []); |
233 } | 258 } |
OLD | NEW |