OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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 | 4 |
5 library test.constructor_kinds_test; | 5 library test.constructor_kinds_test; |
6 | 6 |
7 import 'dart:mirrors'; | 7 import 'dart:mirrors'; |
8 import 'package:expect/expect.dart'; | 8 import 'package:expect/expect.dart'; |
9 | 9 |
10 class ClassWithDefaultConstructor {} | 10 class ClassWithDefaultConstructor {} |
11 | 11 |
12 class Class { | 12 class Class { |
13 Class.generativeConstructor(); | 13 Class.generativeConstructor(); |
14 Class.redirectingGenerativeConstructor() : this.generativeConstructor(); | 14 Class.redirectingGenerativeConstructor() : this.generativeConstructor(); |
15 factory Class.factoryConstructor() => new Class.generativeConstructor(); | 15 factory Class.factoryConstructor() => new Class.generativeConstructor(); |
16 factory Class.redirectingFactoryConstructor() = Class.factoryConstructor; | 16 factory Class.redirectingFactoryConstructor() = Class.factoryConstructor; |
17 | 17 |
18 const Class.constGenerativeConstructor(); | 18 const Class.constGenerativeConstructor(); |
19 const Class.constRedirectingGenerativeConstructor() | 19 const Class.constRedirectingGenerativeConstructor() |
20 : this.constGenerativeConstructor(); | 20 : this.constGenerativeConstructor(); |
21 // Not legal. | 21 // Not legal. |
22 // const factory Class.constFactoryConstructor() => ... | 22 // const factory Class.constFactoryConstructor() => ... |
23 const factory Class.constRedirectingFactoryConstructor() | 23 const factory Class.constRedirectingFactoryConstructor() = |
24 = Class.constGenerativeConstructor; | 24 Class.constGenerativeConstructor; |
25 } | 25 } |
26 | 26 |
27 main() { | 27 main() { |
28 ClassMirror cm; | 28 ClassMirror cm; |
29 MethodMirror mm; | 29 MethodMirror mm; |
30 | 30 |
31 // Multitest with and without constructor calls. On the VM, we want to check | 31 // Multitest with and without constructor calls. On the VM, we want to check |
32 // that constructor properties are correctly set even if the constructor | 32 // that constructor properties are correctly set even if the constructor |
33 // hasn't been fully compiled. On dart2js, we want to check that constructors | 33 // hasn't been fully compiled. On dart2js, we want to check that constructors |
34 // are retain even if there are no base-level calls. | 34 // are retain even if there are no base-level calls. |
35 new ClassWithDefaultConstructor(); // //# 01: ok | 35 new ClassWithDefaultConstructor(); // //# 01: ok |
36 new Class.generativeConstructor(); // //# 01: ok | 36 new Class.generativeConstructor(); // //# 01: ok |
37 new Class.redirectingGenerativeConstructor(); // //# 01: ok | 37 new Class.redirectingGenerativeConstructor(); // //# 01: ok |
38 new Class.factoryConstructor(); // //# 01: ok | 38 new Class.factoryConstructor(); // //# 01: ok |
39 new Class.redirectingFactoryConstructor(); // //# 01: ok | 39 new Class.redirectingFactoryConstructor(); // //# 01: ok |
40 const Class.constGenerativeConstructor(); // //# 01: ok | 40 const Class.constGenerativeConstructor(); // //# 01: ok |
41 const Class.constRedirectingGenerativeConstructor(); // //# 01: ok | 41 const Class.constRedirectingGenerativeConstructor(); // //# 01: ok |
42 const Class.constRedirectingFactoryConstructor(); // //# 01: ok | 42 const Class.constRedirectingFactoryConstructor(); // //# 01: ok |
43 | 43 |
44 cm = reflectClass(ClassWithDefaultConstructor); | 44 cm = reflectClass(ClassWithDefaultConstructor); |
45 mm = cm.declarations.values | 45 mm = cm.declarations.values |
46 .where((d) => d is MethodMirror && d.isConstructor).single; | 46 .where((d) => d is MethodMirror && d.isConstructor) |
| 47 .single; |
47 Expect.isTrue(mm.isConstructor); | 48 Expect.isTrue(mm.isConstructor); |
48 Expect.isTrue(mm.isGenerativeConstructor); | 49 Expect.isTrue(mm.isGenerativeConstructor); |
49 Expect.isFalse(mm.isFactoryConstructor); | 50 Expect.isFalse(mm.isFactoryConstructor); |
50 Expect.isFalse(mm.isRedirectingConstructor); | 51 Expect.isFalse(mm.isRedirectingConstructor); |
51 Expect.isFalse(mm.isConstConstructor); | 52 Expect.isFalse(mm.isConstConstructor); |
52 | 53 |
53 cm = reflectClass(Class); | 54 cm = reflectClass(Class); |
54 | 55 |
55 mm = cm.declarations[#Class.generativeConstructor]; | 56 mm = cm.declarations[#Class.generativeConstructor]; |
56 Expect.isTrue(mm.isConstructor); | 57 Expect.isTrue(mm.isConstructor); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 // Expect.isFalse(mm.isRedirectingConstructor); | 103 // Expect.isFalse(mm.isRedirectingConstructor); |
103 // Expect.isTrue(mm.isConstConstructor); | 104 // Expect.isTrue(mm.isConstConstructor); |
104 | 105 |
105 mm = cm.declarations[#Class.constRedirectingFactoryConstructor]; | 106 mm = cm.declarations[#Class.constRedirectingFactoryConstructor]; |
106 Expect.isTrue(mm.isConstructor); | 107 Expect.isTrue(mm.isConstructor); |
107 Expect.isFalse(mm.isGenerativeConstructor); | 108 Expect.isFalse(mm.isGenerativeConstructor); |
108 Expect.isTrue(mm.isFactoryConstructor); | 109 Expect.isTrue(mm.isFactoryConstructor); |
109 Expect.isTrue(mm.isRedirectingConstructor); | 110 Expect.isTrue(mm.isRedirectingConstructor); |
110 Expect.isTrue(mm.isConstConstructor); | 111 Expect.isTrue(mm.isConstConstructor); |
111 } | 112 } |
OLD | NEW |