OLD | NEW |
| (Empty) |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
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. | |
4 | |
5 import 'package:unittest/compact_vm_config.dart'; | |
6 import 'package:unittest/unittest.dart'; | |
7 import 'package:polymer/src/dart_parser.dart'; | |
8 import 'package:polymer/src/messages.dart'; | |
9 import 'package:polymer/src/observable_transform.dart'; | |
10 | |
11 main() { | |
12 useCompactVMConfiguration(); | |
13 | |
14 group('fixes contructor calls ', () { | |
15 testInitializers('this.a', '(a) : __\$a = a'); | |
16 testInitializers('{this.a}', '({a}) : __\$a = a'); | |
17 testInitializers('[this.a]', '([a]) : __\$a = a'); | |
18 testInitializers('this.a, this.b', '(a, b) : __\$a = a, __\$b = b'); | |
19 testInitializers('{this.a, this.b}', '({a, b}) : __\$a = a, __\$b = b'); | |
20 testInitializers('[this.a, this.b]', '([a, b]) : __\$a = a, __\$b = b'); | |
21 testInitializers('this.a, [this.b]', '(a, [b]) : __\$a = a, __\$b = b'); | |
22 testInitializers('this.a, {this.b}', '(a, {b}) : __\$a = a, __\$b = b'); | |
23 }); | |
24 } | |
25 | |
26 testInitializers(String args, String expected) { | |
27 test(args, () { | |
28 | |
29 var constructor = 'MyClass('; | |
30 | |
31 var code = ''' | |
32 class MyClass { | |
33 @observable var a; | |
34 @observable var b; | |
35 MyClass($args); | |
36 }'''; | |
37 | |
38 var edit = transformObservables(parseDartCode('<test>', code, null), | |
39 new Messages.silent()); | |
40 expect(edit, isNotNull); | |
41 var output = (edit.commit()..build('<test>')).text; | |
42 | |
43 var begin = output.indexOf(constructor) + constructor.length - 1; | |
44 var end = output.indexOf(';', begin); | |
45 if (end == -1) end = output.length; | |
46 var init = output.substring(begin, end).trim().replaceAll(' ', ' '); | |
47 | |
48 expect(init, expected); | |
49 }); | |
50 } | |
OLD | NEW |