Chromium Code Reviews| 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 = | 13 var transformer = |
| 14 new InitializeTransformer('web/index.dart', 'web/index.bootstrap.dart'); | 14 new InitializeTransformer('web/index.dart', 'web/index.bootstrap.dart'); |
| 15 | 15 |
| 16 testPhases('transformer', [[transformer]], { | 16 testPhases('basic', [[transformer]], { |
| 17 'a|web/index.dart': ''' | 17 'a|web/index.dart': ''' |
| 18 library web_foo; | 18 library web_foo; |
| 19 | 19 |
| 20 import 'foo.dart'; | 20 import 'foo.dart'; |
| 21 ''', | 21 ''', |
| 22 'a|web/foo.dart': ''' | 22 'a|web/foo.dart': ''' |
| 23 @constInit | 23 @constInit |
| 24 library foo; | 24 library foo; |
| 25 | 25 |
| 26 import 'package:initialize/initialize.dart'; | 26 import 'package:initialize/initialize.dart'; |
| 27 import 'package:bar/bar.dart'; | 27 import 'package:bar/bar.dart'; |
| 28 | 28 |
| 29 @constInit | 29 @constInit |
| 30 class Foo extends Bar {} | 30 class Foo extends Bar {} |
| 31 | 31 |
| 32 @initMethod | 32 @initMethod |
| 33 foo() {} | 33 foo() {} |
| 34 ''', | 34 ''', |
| 35 'bar|lib/bar.dart': ''' | 35 'bar|lib/bar.dart': ''' |
| 36 @DynamicInit('bar') | 36 @DynamicInit('bar') |
| 37 @DynamicInit('bar2') | 37 @DynamicInit('bar2') |
| 38 library bar; | 38 library bar; |
| 39 | 39 |
| 40 import 'package:initialize/initialize.dart'; | 40 import 'package:initialize/initialize.dart'; |
| 41 | 41 |
| 42 @DynamicInit('Bar') | 42 @DynamicInit('Bar') |
| 43 @DynamicInit('Bar2') | 43 @DynamicInit('Bar2') |
| 44 class Bar {} | 44 class Bar {} |
| 45 | 45 |
| 46 @DynamicInit('bar()') | 46 @DynamicInit('bar()') |
| 47 @initMethod | 47 @initMethod |
| 48 bar() {} | 48 bar() {} |
| 49 ''', | 49 ''', |
| 50 // Mock out the Initialize package plus some initializers. | 50 // Mock out the Initialize package plus some initializers. |
| 51 'initialize|lib/initialize.dart': ''' | 51 'initialize|lib/initialize.dart': mockInitialize |
| 52 library initialize; | |
| 53 | |
| 54 abstract class Initializer<T> {} | |
| 55 | |
| 56 class _ConstInit extends Initializer<dynamic> { | |
| 57 const ConstInit(); | |
| 58 } | |
| 59 const _ConstInit constInit = const _ConstInit(); | |
| 60 | |
| 61 class DynamicInit extends Initializer<dynamic> { | |
| 62 final String _name; | |
| 63 const DynamicInit(this._name); | |
| 64 } | |
| 65 | |
| 66 class _InitMethod implements Initializer<Function> { | |
| 67 const _InitMethod(); | |
| 68 } | |
| 69 const _InitMethod initMethod = const _InitMethod(); | |
| 70 ''' | |
| 71 }, { | 52 }, { |
| 72 'a|web/index.bootstrap.dart': ''' | 53 'a|web/index.bootstrap.dart': ''' |
| 73 import 'package:initialize/src/static_loader.dart'; | 54 import 'package:initialize/src/static_loader.dart'; |
| 74 import 'index.dart' as i0; | 55 import 'index.dart' as i0; |
| 75 import 'package:bar/bar.dart' as i1; | 56 import 'package:bar/bar.dart' as i1; |
| 76 import 'package:initialize/initialize.dart' as i2; | 57 import 'package:initialize/initialize.dart' as i2; |
| 77 import 'foo.dart' as i3; | 58 import 'foo.dart' as i3; |
| 78 | 59 |
| 79 main() { | 60 main() { |
| 80 initializers.addAll([ | 61 initializers.addAll([ |
| 81 new InitEntry(const i2.DynamicInit('bar'), #bar), | 62 new InitEntry(const i2.DynamicInit('bar'), #bar), |
| 82 new InitEntry(const i2.DynamicInit('bar2'), #bar), | 63 new InitEntry(const i2.DynamicInit('bar2'), #bar), |
| 83 new InitEntry(const i2.DynamicInit('bar()'), i1.bar), | 64 new InitEntry(const i2.DynamicInit('bar()'), i1.bar), |
| 84 new InitEntry(i2.initMethod, i1.bar), | 65 new InitEntry(i2.initMethod, i1.bar), |
| 85 new InitEntry(const i2.DynamicInit('Bar'), i1.Bar), | 66 new InitEntry(const i2.DynamicInit('Bar'), i1.Bar), |
| 86 new InitEntry(const i2.DynamicInit('Bar2'), i1.Bar), | 67 new InitEntry(const i2.DynamicInit('Bar2'), i1.Bar), |
| 87 new InitEntry(i2.constInit, #foo), | 68 new InitEntry(i2.constInit, #foo), |
| 88 new InitEntry(i2.initMethod, i3.foo), | 69 new InitEntry(i2.initMethod, i3.foo), |
| 89 new InitEntry(i2.constInit, i3.Foo), | 70 new InitEntry(i2.constInit, i3.Foo), |
| 90 ]); | 71 ]); |
| 91 | 72 |
| 92 i0.main(); | 73 i0.main(); |
| 93 } | 74 } |
| 94 '''.replaceAll(' ', '') | 75 '''.replaceAll(' ', '') |
| 76 }); | |
| 77 | |
| 78 testPhases('constructor arguments', [[transformer]], { | |
| 79 'a|web/index.dart': ''' | |
| 80 @DynamicInit(foo) | |
| 81 @DynamicInit(Foo.foo) | |
| 82 @DynamicInit([foo, Foo.foo, 'foo']) | |
|
Siggi Cherem (dart-lang)
2015/01/23 17:56:28
this would become invalid :)
jakemac
2015/01/23 21:34:39
Done.
| |
| 83 @DynamicInit(const [foo, Foo.foo, 'foo']) | |
|
Siggi Cherem (dart-lang)
2015/01/23 17:56:28
DynamicInit takes a String argument, maybe change
jakemac
2015/01/23 21:34:38
Done.
| |
| 84 @DynamicInit({'foo': foo, 'Foo.foo': Foo.foo, 'bar': 'bar'}) | |
| 85 @DynamicInit(const {'foo': foo, 'Foo.foo': Foo.foo, 'bar': 'bar'}) | |
| 86 @DynamicInit('foo') | |
| 87 @DynamicInit(true) | |
| 88 @DynamicInit(null) | |
| 89 @DynamicInit(1) | |
| 90 @DynamicInit(1.1) | |
| 91 library web_foo; | |
| 92 | |
| 93 import 'package:initialize/initialize.dart'; | |
| 94 import 'foo.dart'; | |
| 95 ''', | |
| 96 'a|web/foo.dart': ''' | |
| 97 library foo; | |
| 98 | |
| 99 const String foo = 'foo'; | |
| 100 | |
| 101 class Foo { | |
| 102 static foo = 'Foo.foo'; | |
| 103 } | |
| 104 ''', | |
| 105 // Mock out the Initialize package plus some initializers. | |
| 106 'initialize|lib/initialize.dart': mockInitialize | |
| 107 }, { | |
| 108 'a|web/index.bootstrap.dart': ''' | |
| 109 import 'package:initialize/src/static_loader.dart'; | |
| 110 import 'index.dart' as i0; | |
| 111 import 'package:initialize/initialize.dart' as i1; | |
| 112 import 'foo.dart' as i2; | |
| 113 | |
| 114 main() { | |
| 115 initializers.addAll([ | |
| 116 new InitEntry(const i1.DynamicInit(i2.foo), #web_foo), | |
| 117 new InitEntry(const i1.DynamicInit(i2.Foo.foo), #web_foo), | |
| 118 new InitEntry(const i1.DynamicInit([i2.foo, i2.Foo.foo, 'foo']), #we b_foo), | |
| 119 new InitEntry(const i1.DynamicInit(const [i2.foo, i2.Foo.foo, 'foo'] ), #web_foo), | |
| 120 new InitEntry(const i1.DynamicInit({'foo': i2.foo, 'Foo.foo': i2.Foo .foo, 'bar': 'bar'}), #web_foo), | |
| 121 new InitEntry(const i1.DynamicInit(const {'foo': i2.foo, 'Foo.foo': i2.Foo.foo, 'bar': 'bar'}), #web_foo), | |
| 122 new InitEntry(const i1.DynamicInit('foo'), #web_foo), | |
| 123 new InitEntry(const i1.DynamicInit(true), #web_foo), | |
| 124 new InitEntry(const i1.DynamicInit(null), #web_foo), | |
| 125 new InitEntry(const i1.DynamicInit(1), #web_foo), | |
| 126 new InitEntry(const i1.DynamicInit(1.1), #web_foo), | |
| 127 ]); | |
| 128 | |
| 129 i0.main(); | |
| 130 } | |
| 131 '''.replaceAll(' ', '') | |
| 95 }); | 132 }); |
| 96 } | 133 } |
| OLD | NEW |