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 library test.constructor_kinds_test; |
| 6 |
| 7 import 'dart:mirrors'; |
| 8 import 'package:expect/expect.dart'; |
| 9 |
| 10 class ClassWithDefaultConstructor {} |
| 11 |
| 12 class Class { |
| 13 Class.generativeConstructor(); |
| 14 Class.redirectingGenerativeConstructor() : this.generativeConstructor(); |
| 15 factory Class.factoryConstructor() => new Class.generativeConstructor(); |
| 16 factory Class.redirectingFactoryConstructor() = Class.factoryConstructor; |
| 17 |
| 18 const Class.constGenerativeConstructor(); |
| 19 const Class.constRedirectingGenerativeConstructor() |
| 20 : this.constGenerativeConstructor(); |
| 21 // Not legal. |
| 22 // const factory Class.constFactoryConstructor() => ... |
| 23 const factory Class.constRedirectingFactoryConstructor() |
| 24 = Class.constGenerativeConstructor; |
| 25 } |
| 26 |
| 27 main() { |
| 28 ClassMirror cm; |
| 29 MethodMirror mm; |
| 30 |
| 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 |
| 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. |
| 35 new ClassWithDefaultConstructor(); /// 01: ok |
| 36 new Class.generativeConstructor(); /// 01: ok |
| 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 |
| 43 |
| 44 cm = reflectClass(ClassWithDefaultConstructor); |
| 45 mm = cm.declarations.values |
| 46 .where((d) => d is MethodMirror && d.isConstructor).single; |
| 47 Expect.isTrue(mm.isConstructor); |
| 48 Expect.isTrue(mm.isGenerativeConstructor); |
| 49 Expect.isFalse(mm.isFactoryConstructor); |
| 50 Expect.isFalse(mm.isRedirectingConstructor); |
| 51 Expect.isFalse(mm.isConstConstructor); |
| 52 |
| 53 cm = reflectClass(Class); |
| 54 |
| 55 mm = cm.declarations[#Class.generativeConstructor]; |
| 56 Expect.isTrue(mm.isConstructor); |
| 57 Expect.isTrue(mm.isGenerativeConstructor); |
| 58 Expect.isFalse(mm.isFactoryConstructor); |
| 59 Expect.isFalse(mm.isRedirectingConstructor); |
| 60 Expect.isFalse(mm.isConstConstructor); |
| 61 |
| 62 mm = cm.declarations[#Class.redirectingGenerativeConstructor]; |
| 63 Expect.isTrue(mm.isConstructor); |
| 64 Expect.isTrue(mm.isGenerativeConstructor); |
| 65 Expect.isFalse(mm.isFactoryConstructor); |
| 66 Expect.isTrue(mm.isRedirectingConstructor); |
| 67 Expect.isFalse(mm.isConstConstructor); |
| 68 |
| 69 mm = cm.declarations[#Class.factoryConstructor]; |
| 70 Expect.isTrue(mm.isConstructor); |
| 71 Expect.isFalse(mm.isGenerativeConstructor); |
| 72 Expect.isTrue(mm.isFactoryConstructor); |
| 73 Expect.isFalse(mm.isRedirectingConstructor); |
| 74 Expect.isFalse(mm.isConstConstructor); |
| 75 |
| 76 mm = cm.declarations[#Class.redirectingFactoryConstructor]; |
| 77 Expect.isTrue(mm.isConstructor); |
| 78 Expect.isFalse(mm.isGenerativeConstructor); |
| 79 Expect.isTrue(mm.isFactoryConstructor); |
| 80 Expect.isTrue(mm.isRedirectingConstructor); |
| 81 Expect.isFalse(mm.isConstConstructor); |
| 82 |
| 83 mm = cm.declarations[#Class.constGenerativeConstructor]; |
| 84 Expect.isTrue(mm.isConstructor); |
| 85 Expect.isTrue(mm.isGenerativeConstructor); |
| 86 Expect.isFalse(mm.isFactoryConstructor); |
| 87 Expect.isFalse(mm.isRedirectingConstructor); |
| 88 Expect.isTrue(mm.isConstConstructor); |
| 89 |
| 90 mm = cm.declarations[#Class.constRedirectingGenerativeConstructor]; |
| 91 Expect.isTrue(mm.isConstructor); |
| 92 Expect.isTrue(mm.isGenerativeConstructor); |
| 93 Expect.isFalse(mm.isFactoryConstructor); |
| 94 Expect.isTrue(mm.isRedirectingConstructor); |
| 95 Expect.isTrue(mm.isConstConstructor); |
| 96 |
| 97 // Not legal. |
| 98 // mm = cm.declarations[#Class.constFactoryConstructor]; |
| 99 // Expect.isTrue(mm.isConstructor); |
| 100 // Expect.isFalse(mm.isGenerativeConstructor); |
| 101 // Expect.isTrue(mm.isFactoryConstructor); |
| 102 // Expect.isFalse(mm.isRedirectingConstructor); |
| 103 // Expect.isTrue(mm.isConstConstructor); |
| 104 |
| 105 mm = cm.declarations[#Class.constRedirectingFactoryConstructor]; |
| 106 Expect.isTrue(mm.isConstructor); |
| 107 Expect.isFalse(mm.isGenerativeConstructor); |
| 108 Expect.isTrue(mm.isFactoryConstructor); |
| 109 Expect.isTrue(mm.isRedirectingConstructor); |
| 110 Expect.isTrue(mm.isConstConstructor); |
| 111 } |
OLD | NEW |