Chromium Code Reviews| 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.generative(); | 13 Class.generativeConstructor(); |
| 14 Class.redirectingGenerative() : this.generative(); | 14 Class.redirectingGenerativeConstructor() : this.generativeConstructor(); |
| 15 factory Class.faktory () => new Class.generative(); | 15 factory Class.factoryConstructor() => new Class.generativeConstructor(); |
| 16 factory Class.redirectingFactory() = Class.faktory; | 16 factory Class.redirectingFactoryConstructor() = Class.factoryConstructor; |
| 17 | 17 |
| 18 const Class.constGenerative(); | 18 const Class.constGenerativeConstructor(); |
| 19 const Class.constRedirectingGenerative() : this.constGenerative(); | 19 const Class.constRedirectingGenerativeConstructor() |
| 20 : this.constGenerativeConstructor(); | |
| 20 // Not legal. | 21 // Not legal. |
| 21 // const factory Class.constFaktory () => const Class.constGenerative(); | 22 // const factory Class.constFactoryConstructor() => ... |
| 22 const factory Class.constRedirectingFactory() = Class.constGenerative; | 23 const factory Class.constRedirectingFactoryConstructor() |
| 24 = Class.constGenerativeConstructor; | |
| 23 } | 25 } |
| 24 | 26 |
| 25 main() { | 27 main() { |
| 26 ClassMirror cm; | 28 ClassMirror cm; |
| 27 MethodMirror mm; | 29 MethodMirror mm; |
| 28 | 30 |
| 29 new Class.generative(); | 31 // Multitest with and without constructor calls. On the VM, we want to check |
| 30 new Class.redirectingGenerative(); | 32 // that constructor properties are correctly set even if the constructor |
| 31 new Class.faktory(); | 33 // hasn't been fully compiled. On dart2js, we want to check that constructors |
| 32 new Class.redirectingFactory(); | 34 // are retain even if there are no base-level calls. |
|
ahe
2013/10/10 15:49:32
Great idea!
| |
| 33 const Class.constGenerative(); | 35 new ClassWithDefaultConstructor(); /// 01: ok |
| 34 const Class.constRedirectingGenerative(); | 36 new Class.generativeConstructor(); /// 01: ok |
| 35 const Class.constRedirectingFactory(); | 37 new Class.redirectingGenerativeConstructor(); /// 01: ok |
| 38 new Class.factoryConstructor(); /// 01: ok | |
| 39 new Class.redirectingFactoryConstructor(); /// 01: ok | |
| 40 const Class.constGenerativeConstructor(); /// 01: ok | |
| 41 const Class.constRedirectingGenerativeConstructor(); /// 01: ok | |
| 42 const Class.constRedirectingFactoryConstructor(); /// 01: ok | |
| 36 | 43 |
| 37 cm = reflectClass(ClassWithDefaultConstructor); | 44 cm = reflectClass(ClassWithDefaultConstructor); |
| 38 mm = cm.constructors.values.single; | 45 mm = cm.constructors.values.single; |
| 39 Expect.isTrue(mm.isConstructor); | 46 Expect.isTrue(mm.isConstructor); |
| 40 Expect.isTrue(mm.isGenerativeConstructor); | 47 Expect.isTrue(mm.isGenerativeConstructor); |
| 41 Expect.isFalse(mm.isFactoryConstructor); | 48 Expect.isFalse(mm.isFactoryConstructor); |
| 42 Expect.isFalse(mm.isRedirectingConstructor); | 49 Expect.isFalse(mm.isRedirectingConstructor); |
| 43 Expect.isFalse(mm.isConstConstructor); | 50 Expect.isFalse(mm.isConstConstructor); |
| 44 | 51 |
| 45 | |
| 46 cm = reflectClass(Class); | 52 cm = reflectClass(Class); |
| 47 | 53 |
| 48 mm = cm.constructors[#generative]; | 54 mm = cm.constructors[#Class.generativeConstructor]; |
| 49 Expect.isTrue(mm.isConstructor); | 55 Expect.isTrue(mm.isConstructor); |
| 50 Expect.isTrue(mm.isGenerativeConstructor); | 56 Expect.isTrue(mm.isGenerativeConstructor); |
| 51 Expect.isFalse(mm.isFactoryConstructor); | 57 Expect.isFalse(mm.isFactoryConstructor); |
| 52 Expect.isFalse(mm.isRedirectingConstructor); | 58 Expect.isFalse(mm.isRedirectingConstructor); |
| 53 Expect.isFalse(mm.isConstConstructor); | 59 Expect.isFalse(mm.isConstConstructor); |
| 54 | 60 |
| 55 mm = cm.constructors[#redirectingGenerative]; | 61 mm = cm.constructors[#Class.redirectingGenerativeConstructor]; |
| 56 Expect.isTrue(mm.isConstructor); | 62 Expect.isTrue(mm.isConstructor); |
| 57 Expect.isTrue(mm.isGenerativeConstructor); | 63 Expect.isTrue(mm.isGenerativeConstructor); |
| 58 Expect.isFalse(mm.isFactoryConstructor); | 64 Expect.isFalse(mm.isFactoryConstructor); |
| 59 Expect.isTrue(mm.isRedirectingConstructor); | 65 Expect.isTrue(mm.isRedirectingConstructor); |
| 60 Expect.isFalse(mm.isConstConstructor); | 66 Expect.isFalse(mm.isConstConstructor); |
| 61 | 67 |
| 62 mm = cm.constructors[#faktory]; | 68 mm = cm.constructors[#Class.factoryConstructor]; |
| 63 Expect.isTrue(mm.isConstructor); | 69 Expect.isTrue(mm.isConstructor); |
| 64 Expect.isFalse(mm.isGenerativeConstructor); | 70 Expect.isFalse(mm.isGenerativeConstructor); |
| 65 Expect.isTrue(mm.isFactoryConstructor); | 71 Expect.isTrue(mm.isFactoryConstructor); |
| 66 Expect.isFalse(mm.isRedirectingConstructor); | 72 Expect.isFalse(mm.isRedirectingConstructor); |
| 67 Expect.isFalse(mm.isConstConstructor); | 73 Expect.isFalse(mm.isConstConstructor); |
| 68 | 74 |
| 69 mm = cm.constructors[#redirectingFactory]; | 75 mm = cm.constructors[#Class.redirectingFactoryConstructor]; |
| 70 Expect.isTrue(mm.isConstructor); | 76 Expect.isTrue(mm.isConstructor); |
| 71 Expect.isFalse(mm.isGenerativeConstructor); | 77 Expect.isFalse(mm.isGenerativeConstructor); |
| 72 Expect.isTrue(mm.isFactoryConstructor); | 78 Expect.isTrue(mm.isFactoryConstructor); |
| 73 Expect.isTrue(mm.isRedirectingConstructor); | 79 Expect.isTrue(mm.isRedirectingConstructor); |
| 74 Expect.isFalse(mm.isConstConstructor); | 80 Expect.isFalse(mm.isConstConstructor); |
| 75 | 81 |
| 76 mm = cm.constructors[#constGenerative]; | 82 mm = cm.constructors[#Class.constGenerativeConstructor]; |
| 77 Expect.isTrue(mm.isConstructor); | 83 Expect.isTrue(mm.isConstructor); |
| 78 Expect.isTrue(mm.isGenerativeConstructor); | 84 Expect.isTrue(mm.isGenerativeConstructor); |
| 79 Expect.isFalse(mm.isFactoryConstructor); | 85 Expect.isFalse(mm.isFactoryConstructor); |
| 80 Expect.isFalse(mm.isRedirectingConstructor); | 86 Expect.isFalse(mm.isRedirectingConstructor); |
| 81 Expect.isTrue(mm.isConstConstructor); | 87 Expect.isTrue(mm.isConstConstructor); |
| 82 | 88 |
| 83 mm = cm.constructors[#constRedirectingGenerative]; | 89 mm = cm.constructors[#Class.constRedirectingGenerativeConstructor]; |
| 84 Expect.isTrue(mm.isConstructor); | 90 Expect.isTrue(mm.isConstructor); |
| 85 Expect.isTrue(mm.isGenerativeConstructor); | 91 Expect.isTrue(mm.isGenerativeConstructor); |
| 86 Expect.isFalse(mm.isFactoryConstructor); | 92 Expect.isFalse(mm.isFactoryConstructor); |
| 87 Expect.isTrue(mm.isRedirectingConstructor); | 93 Expect.isTrue(mm.isRedirectingConstructor); |
| 88 Expect.isTrue(mm.isConstConstructor); | 94 Expect.isTrue(mm.isConstConstructor); |
| 89 | 95 |
| 90 // Not legal. | 96 // Not legal. |
| 91 // mm = cm.constructors[#constFaktory]; | 97 // mm = cm.constructors[#Class.constFactoryConstructor]; |
| 92 // Expect.isTrue(mm.isConstructor); | 98 // Expect.isTrue(mm.isConstructor); |
| 93 // Expect.isFalse(mm.isGenerativeConstructor); | 99 // Expect.isFalse(mm.isGenerativeConstructor); |
| 94 // Expect.isTrue(mm.isFactoryConstructor); | 100 // Expect.isTrue(mm.isFactoryConstructor); |
| 95 // Expect.isFalse(mm.isRedirectingConstructor); | 101 // Expect.isFalse(mm.isRedirectingConstructor); |
| 96 // Expect.isTrue(mm.isConstConstructor); | 102 // Expect.isTrue(mm.isConstConstructor); |
| 97 | 103 |
| 98 mm = cm.constructors[#constRedirectingFactory]; | 104 mm = cm.constructors[#Class.constRedirectingFactoryConstructor]; |
| 99 Expect.isTrue(mm.isConstructor); | 105 Expect.isTrue(mm.isConstructor); |
| 100 Expect.isFalse(mm.isGenerativeConstructor); | 106 Expect.isFalse(mm.isGenerativeConstructor); |
| 101 Expect.isTrue(mm.isFactoryConstructor); | 107 Expect.isTrue(mm.isFactoryConstructor); |
| 102 Expect.isTrue(mm.isRedirectingConstructor); | 108 Expect.isTrue(mm.isRedirectingConstructor); |
| 103 Expect.isTrue(mm.isConstConstructor); | 109 Expect.isTrue(mm.isConstConstructor); |
| 104 } | 110 } |
| OLD | NEW |