| 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:dart_style/dart_style.dart'; | 8 import 'package:dart_style/dart_style.dart'; |
| 8 import 'package:initialize/transformer.dart'; | 9 import 'package:initialize/transformer.dart'; |
| 9 import 'package:unittest/compact_vm_config.dart'; | 10 import 'package:unittest/compact_vm_config.dart'; |
| 11 import 'package:unittest/unittest.dart'; |
| 12 |
| 13 var formatter = new DartFormatter(); |
| 10 | 14 |
| 11 main() { | 15 main() { |
| 12 useCompactVMConfiguration(); | 16 useCompactVMConfiguration(); |
| 13 | 17 |
| 14 var formatter = new DartFormatter(); | 18 group('Html entry points', htmlEntryPointTests); |
| 19 group('Dart entry points', dartEntryPointTests); |
| 20 group('InitializerPlugins', pluginTests); |
| 21 } |
| 15 | 22 |
| 16 var htmlTransformer = new InitializeTransformer(['web/*.html']); | 23 void htmlEntryPointTests() { |
| 17 var dartTransformer = new InitializeTransformer(['web/index.dart']); | 24 var phases = [[new InitializeTransformer(['web/*.html'])]]; |
| 18 | 25 |
| 19 testPhases('basic', [[htmlTransformer]], { | 26 testPhases('basic', phases, { |
| 20 'a|web/index.html': ''' | 27 'a|web/index.html': ''' |
| 21 <html><head></head><body> | 28 <html><head></head><body> |
| 22 <script type="application/dart" src="index.dart"></script> | 29 <script type="application/dart" src="index.dart"></script> |
| 23 </body></html> | 30 </body></html> |
| 24 '''.replaceAll(' ', ''), | 31 '''.replaceAll(' ', ''), |
| 25 'a|web/index.dart': ''' | 32 'a|web/index.dart': ''' |
| 26 library web_foo; | 33 library web_foo; |
| 27 | 34 |
| 28 import 'foo.dart'; | 35 import 'foo.dart'; |
| 29 ''', | 36 ''', |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 new InitEntry(const i2.DynamicInit('Bar2'), i3.Bar), | 101 new InitEntry(const i2.DynamicInit('Bar2'), i3.Bar), |
| 95 new InitEntry(i2.constInit, const LibraryIdentifier(#foo, null, 'foo
.dart')), | 102 new InitEntry(i2.constInit, const LibraryIdentifier(#foo, null, 'foo
.dart')), |
| 96 new InitEntry(i4.initMethod, i5.foo), | 103 new InitEntry(i4.initMethod, i5.foo), |
| 97 new InitEntry(i2.constInit, i5.Foo), | 104 new InitEntry(i2.constInit, i5.Foo), |
| 98 ]); | 105 ]); |
| 99 | 106 |
| 100 i0.main(); | 107 i0.main(); |
| 101 } | 108 } |
| 102 ''') | 109 ''') |
| 103 }, []); | 110 }, []); |
| 111 } |
| 104 | 112 |
| 105 testPhases('constructor arguments', [[dartTransformer]], { | 113 void dartEntryPointTests() { |
| 114 var phases = [[new InitializeTransformer(['web/index.dart'])]]; |
| 115 |
| 116 testPhases('constructor arguments', phases, { |
| 106 'a|web/index.dart': ''' | 117 'a|web/index.dart': ''' |
| 107 @DynamicInit(foo) | 118 @DynamicInit(foo) |
| 108 @DynamicInit(Foo.foo) | 119 @DynamicInit(Foo.foo) |
| 109 @DynamicInit(const [foo, Foo.foo, 'foo']) | 120 @DynamicInit(const [foo, Foo.foo, 'foo']) |
| 110 @DynamicInit(const {'foo': foo, 'Foo.foo': Foo.foo, 'bar': 'bar'}) | 121 @DynamicInit(const {'foo': foo, 'Foo.foo': Foo.foo, 'bar': 'bar'}) |
| 111 @DynamicInit('foo') | 122 @DynamicInit('foo') |
| 112 @DynamicInit(true) | 123 @DynamicInit(true) |
| 113 @DynamicInit(null) | 124 @DynamicInit(null) |
| 114 @DynamicInit(1) | 125 @DynamicInit(1) |
| 115 @DynamicInit(1.1) | 126 @DynamicInit(1.1) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 new InitEntry(const i1.DynamicInit(1), const LibraryIdentifier(#web_
foo, null, 'index.dart')), | 162 new InitEntry(const i1.DynamicInit(1), const LibraryIdentifier(#web_
foo, null, 'index.dart')), |
| 152 new InitEntry(const i1.DynamicInit(1.1), const LibraryIdentifier(#we
b_foo, null, 'index.dart')), | 163 new InitEntry(const i1.DynamicInit(1.1), const LibraryIdentifier(#we
b_foo, null, 'index.dart')), |
| 153 new InitEntry(const i1.NamedArgInit(1, name: 'Bill'), const LibraryI
dentifier(#web_foo, null, 'index.dart')), | 164 new InitEntry(const i1.NamedArgInit(1, name: 'Bill'), const LibraryI
dentifier(#web_foo, null, 'index.dart')), |
| 154 ]); | 165 ]); |
| 155 | 166 |
| 156 i0.main(); | 167 i0.main(); |
| 157 } | 168 } |
| 158 ''') | 169 ''') |
| 159 }, []); | 170 }, []); |
| 160 } | 171 } |
| 172 |
| 173 class SkipConstructorsPlugin extends InitializerPlugin { |
| 174 bool shouldApply(InitializerPluginData data) { |
| 175 return data.initializer.annotationElement.element is ConstructorElement; |
| 176 } |
| 177 |
| 178 String apply(_) => null; |
| 179 } |
| 180 |
| 181 void pluginTests() { |
| 182 var phases = [ |
| 183 [ |
| 184 new InitializeTransformer(['web/index.dart'], |
| 185 plugins: [new SkipConstructorsPlugin()]) |
| 186 ] |
| 187 ]; |
| 188 |
| 189 testPhases('can omit statements', phases, { |
| 190 'a|web/index.dart': ''' |
| 191 library index; |
| 192 |
| 193 import 'package:initialize/initialize.dart'; |
| 194 import 'package:test_initializers/common.dart'; |
| 195 import 'foo.dart'; |
| 196 |
| 197 @initMethod |
| 198 @DynamicInit('index') |
| 199 index() {} |
| 200 ''', |
| 201 'a|web/foo.dart': ''' |
| 202 library foo; |
| 203 |
| 204 import 'package:initialize/initialize.dart'; |
| 205 import 'package:test_initializers/common.dart'; |
| 206 |
| 207 @initMethod |
| 208 @DynamicInit('Foo') |
| 209 foo() {} |
| 210 ''', |
| 211 // Mock out the Initialize package plus some initializers. |
| 212 'initialize|lib/initialize.dart': mockInitialize, |
| 213 'test_initializers|lib/common.dart': commonInitializers, |
| 214 }, { |
| 215 'a|web/index.initialize.dart': formatter.format(''' |
| 216 import 'package:initialize/src/static_loader.dart'; |
| 217 import 'package:initialize/initialize.dart'; |
| 218 import 'index.dart' as i0; |
| 219 import 'foo.dart' as i1; |
| 220 import 'package:initialize/initialize.dart' as i2; |
| 221 import 'package:test_initializers/common.dart' as i3; |
| 222 |
| 223 main() { |
| 224 initializers.addAll([ |
| 225 new InitEntry(i2.initMethod, i1.foo), |
| 226 new InitEntry(i2.initMethod, i0.index), |
| 227 ]); |
| 228 |
| 229 i0.main(); |
| 230 } |
| 231 ''') |
| 232 }, []); |
| 233 } |
| OLD | NEW |