Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: test/transformer_test.dart

Issue 865293002: support basic identifiers in constructors (Closed) Base URL: git@github.com:dart-lang/static-init.git@master
Patch Set: rebase Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/common.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 transformer = new InitializeTransformer(
14 'web/index.dart', 'web/index.bootstrap.dart', 'web/index.html'); 14 'web/index.dart', 'web/index.bootstrap.dart', 'web/index.html');
15 15
16 testPhases('transformer', [[transformer]], { 16 testPhases('basic', [[transformer]], {
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 ''',
27 'a|web/foo.dart': ''' 27 'a|web/foo.dart': '''
28 @constInit 28 @constInit
29 library foo; 29 library foo;
30 30
31 import 'package:initialize/initialize.dart'; 31 import 'package:initialize/initialize.dart';
32 import 'package:bar/bar.dart'; 32 import 'package:test_initializers/common.dart';
33 import 'package:bar/bar.dart';
33 34
34 @constInit 35 @constInit
35 class Foo extends Bar {} 36 class Foo extends Bar {}
36 37
37 @initMethod 38 @initMethod
38 foo() {} 39 foo() {}
39 ''', 40 ''',
40 'bar|lib/bar.dart': ''' 41 'bar|lib/bar.dart': '''
41 @DynamicInit('bar') 42 @DynamicInit('bar')
42 @DynamicInit('bar2') 43 @DynamicInit('bar2')
43 library bar; 44 library bar;
44 45
45 import 'package:initialize/initialize.dart'; 46 import 'package:initialize/initialize.dart';
47 import 'package:test_initializers/common.dart';
46 48
47 @DynamicInit('Bar') 49 @DynamicInit('Bar')
48 @DynamicInit('Bar2') 50 @DynamicInit('Bar2')
49 class Bar {} 51 class Bar {}
50 52
51 @DynamicInit('bar()') 53 @DynamicInit('bar()')
52 @initMethod 54 @initMethod
53 bar() {} 55 bar() {}
54 ''', 56 ''',
55 // Mock out the Initialize package plus some initializers. 57 // Mock out the Initialize package plus some initializers.
56 'initialize|lib/initialize.dart': ''' 58 'initialize|lib/initialize.dart': mockInitialize,
57 library initialize; 59 'test_initializers|lib/common.dart': commonInitializers,
58
59 abstract class Initializer<T> {}
60
61 class _ConstInit extends Initializer<dynamic> {
62 const ConstInit();
63 }
64 const _ConstInit constInit = const _ConstInit();
65
66 class DynamicInit extends Initializer<dynamic> {
67 final String _name;
68 const DynamicInit(this._name);
69 }
70
71 class _InitMethod implements Initializer<Function> {
72 const _InitMethod();
73 }
74 const _InitMethod initMethod = const _InitMethod();
75 ''',
76 }, { 60 }, {
77 'a|web/index.html': ''' 61 'a|web/index.html': '''
78 <html><head></head><body> 62 <html><head></head><body>
79 <script type="application/dart" src="index.bootstrap.dart"></script> 63 <script type="application/dart" src="index.bootstrap.dart"></script>
80 64
81 </body></html>'''.replaceAll(' ', ''), 65 </body></html>'''.replaceAll(' ', ''),
82 'a|web/index.bootstrap.dart': ''' 66 'a|web/index.bootstrap.dart': '''
83 import 'package:initialize/src/static_loader.dart'; 67 import 'package:initialize/src/static_loader.dart';
84 import 'index.dart' as i0; 68 import 'index.dart' as i0;
85 import 'package:bar/bar.dart' as i1; 69 import 'package:bar/bar.dart' as i1;
86 import 'package:initialize/initialize.dart' as i2; 70 import 'package:test_initializers/common.dart' as i2;
87 import 'foo.dart' as i3; 71 import 'package:initialize/initialize.dart' as i3;
72 import 'foo.dart' as i4;
88 73
89 main() { 74 main() {
90 initializers.addAll([ 75 initializers.addAll([
91 new InitEntry(const i2.DynamicInit('bar'), #bar), 76 new InitEntry(const i2.DynamicInit('bar'), #bar),
92 new InitEntry(const i2.DynamicInit('bar2'), #bar), 77 new InitEntry(const i2.DynamicInit('bar2'), #bar),
93 new InitEntry(const i2.DynamicInit('bar()'), i1.bar), 78 new InitEntry(const i2.DynamicInit('bar()'), i1.bar),
94 new InitEntry(i2.initMethod, i1.bar), 79 new InitEntry(i3.initMethod, i1.bar),
95 new InitEntry(const i2.DynamicInit('Bar'), i1.Bar), 80 new InitEntry(const i2.DynamicInit('Bar'), i1.Bar),
96 new InitEntry(const i2.DynamicInit('Bar2'), i1.Bar), 81 new InitEntry(const i2.DynamicInit('Bar2'), i1.Bar),
97 new InitEntry(i2.constInit, #foo), 82 new InitEntry(i2.constInit, #foo),
98 new InitEntry(i2.initMethod, i3.foo), 83 new InitEntry(i3.initMethod, i4.foo),
99 new InitEntry(i2.constInit, i3.Foo), 84 new InitEntry(i2.constInit, i4.Foo),
100 ]); 85 ]);
101 86
102 i0.main(); 87 i0.main();
103 } 88 }
104 '''.replaceAll(' ', ''), 89 '''.replaceAll(' ', '')
90 });
91
92 testPhases('constructor arguments', [[transformer]], {
93 'a|web/index.dart': '''
94 @DynamicInit(foo)
95 @DynamicInit(Foo.foo)
96 @DynamicInit(const [foo, Foo.foo, 'foo'])
97 @DynamicInit(const {'foo': foo, 'Foo.foo': Foo.foo, 'bar': 'bar'})
98 @DynamicInit('foo')
99 @DynamicInit(true)
100 @DynamicInit(null)
101 @DynamicInit(1)
102 @DynamicInit(1.1)
103 @NamedArgInit(1, name: 'Bill')
104 library web_foo;
105
106 import 'package:test_initializers/common.dart';
107 import 'foo.dart';
108 ''',
109 'a|web/foo.dart': '''
110 library foo;
111
112 const String foo = 'foo';
113
114 class Foo {
115 static foo = 'Foo.foo';
116 }
117 ''',
118 // Mock out the Initialize package plus some initializers.
119 'initialize|lib/initialize.dart': mockInitialize,
120 'test_initializers|lib/common.dart': commonInitializers,
121 }, {
122 'a|web/index.bootstrap.dart': '''
123 import 'package:initialize/src/static_loader.dart';
124 import 'index.dart' as i0;
125 import 'package:test_initializers/common.dart' as i1;
126 import 'foo.dart' as i2;
127
128 main() {
129 initializers.addAll([
130 new InitEntry(const i1.DynamicInit(i2.foo), #web_foo),
131 new InitEntry(const i1.DynamicInit(i2.Foo.foo), #web_foo),
132 new InitEntry(const i1.DynamicInit(const [i2.foo, i2.Foo.foo, 'foo'] ), #web_foo),
133 new InitEntry(const i1.DynamicInit(const {'foo': i2.foo, 'Foo.foo': i2.Foo.foo, 'bar': 'bar'}), #web_foo),
134 new InitEntry(const i1.DynamicInit('foo'), #web_foo),
135 new InitEntry(const i1.DynamicInit(true), #web_foo),
136 new InitEntry(const i1.DynamicInit(null), #web_foo),
137 new InitEntry(const i1.DynamicInit(1), #web_foo),
138 new InitEntry(const i1.DynamicInit(1.1), #web_foo),
139 new InitEntry(const i1.NamedArgInit(1, name: 'Bill'), #web_foo),
140 ]);
141
142 i0.main();
143 }
144 '''.replaceAll(' ', '')
105 }); 145 });
106 } 146 }
OLDNEW
« no previous file with comments | « test/common.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698