Index: tests/lib/mirrors/relation_subclass_test.dart |
diff --git a/tests/lib/mirrors/relation_subclass_test.dart b/tests/lib/mirrors/relation_subclass_test.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..dc9c6019ceb7fd7029bbe52992f642ecca673066 |
--- /dev/null |
+++ b/tests/lib/mirrors/relation_subclass_test.dart |
@@ -0,0 +1,100 @@ |
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
+import "dart:mirrors"; |
+ |
+import "package:expect/expect.dart"; |
+ |
+class Superclass {} |
+class Subclass1 extends Superclass {} |
+class Subclass2 extends Superclass {} |
+ |
+typedef bool NumberPredicate(num x); |
+typedef bool IntegerPredicate(int x); |
+typedef bool DoublePredicate(double x); |
+ |
+typedef num NumberGenerator(); |
+typedef int IntegerGenerator(); |
+typedef double DoubleGenerator(); |
+ |
+main() { |
+ ClassMirror Super = reflectType(Superclass); |
+ ClassMirror Sub1 = reflectType(Subclass1); |
+ ClassMirror Sub2 = reflectType(Subclass2); |
+ ClassMirror Obj = reflectType(Object); |
+ |
+ Expect.isTrue(Obj.isSubclassOf(Obj)); |
+ Expect.isTrue(Super.isSubclassOf(Super)); |
+ Expect.isTrue(Sub1.isSubclassOf(Sub1)); |
+ Expect.isTrue(Sub2.isSubclassOf(Sub2)); |
+ |
+ Expect.isTrue(Sub1.isSubclassOf(Super)); |
+ Expect.isFalse(Super.isSubclassOf(Sub1)); |
+ |
+ Expect.isTrue(Sub2.isSubclassOf(Super)); |
+ Expect.isFalse(Super.isSubclassOf(Sub2)); |
+ |
+ Expect.isFalse(Sub2.isSubclassOf(Sub1)); |
+ Expect.isFalse(Sub1.isSubclassOf(Sub2)); |
+ |
+ Expect.isTrue(Sub1.isSubclassOf(Obj)); |
+ Expect.isFalse(Obj.isSubclassOf(Sub1)); |
+ |
+ Expect.isTrue(Sub2.isSubclassOf(Obj)); |
+ Expect.isFalse(Obj.isSubclassOf(Sub2)); |
+ |
+ Expect.isTrue(Super.isSubclassOf(Obj)); |
+ Expect.isFalse(Obj.isSubclassOf(Super)); |
+ |
+ return; /// 01: ok |
+ |
+ TypeMirror Func = reflectType(Function); |
+ Expect.isTrue(Func.isSubclassOf(Obj)); |
+ Expect.isFalse(Obj.isSubclassOf(Func)); |
+ |
+ // Function typedef. |
+ TypeMirror NumPred = reflectType(NumberPredicate); |
+ TypeMirror IntPred = reflectType(IntegerPredicate); |
+ TypeMirror DubPred = reflectType(DoublePredicate); |
+ TypeMirror NumGen = reflectType(NumberGenerator); |
+ TypeMirror IntGen = reflectType(IntegerGenerator); |
+ TypeMirror DubGen = reflectType(DoubleGenerator); |
+ |
+ Expect.throws(() => Func.isSubclassOf(NumPred), (e) => e is ArgumentError || e is TypeError); |
+ Expect.throws(() => Func.isSubclassOf(IntPred), (e) => e is ArgumentError || e is TypeError); |
+ Expect.throws(() => Func.isSubclassOf(DubPred), (e) => e is ArgumentError || e is TypeError); |
+ Expect.throws(() => Func.isSubclassOf(NumGen), (e) => e is ArgumentError || e is TypeError); |
+ Expect.throws(() => Func.isSubclassOf(IntGen), (e) => e is ArgumentError || e is TypeError); |
+ Expect.throws(() => Func.isSubclassOf(DubGen), (e) => e is ArgumentError || e is TypeError); |
+ |
+ Expect.throws(() => NumPred.isSubclassOf(Func), (e) => e is NoSuchMethodError); |
+ Expect.throws(() => IntPred.isSubclassOf(Func), (e) => e is NoSuchMethodError); |
+ Expect.throws(() => DubPred.isSubclassOf(Func), (e) => e is NoSuchMethodError); |
+ Expect.throws(() => NumGen.isSubclassOf(Func), (e) => e is NoSuchMethodError); |
+ Expect.throws(() => IntGen.isSubclassOf(Func), (e) => e is NoSuchMethodError); |
+ Expect.throws(() => DubGen.isSubclassOf(Func), (e) => e is NoSuchMethodError); |
+ |
+ // Function type. |
+ TypeMirror NumPredRef = reflectType(NumberPredicate).referent; |
+ TypeMirror IntPredRef = reflectType(IntegerPredicate).referent; |
+ TypeMirror DubPredRef = reflectType(DoublePredicate).referent; |
+ TypeMirror NumGenRef = reflectType(NumberGenerator).referent; |
+ TypeMirror IntGenRef = reflectType(IntegerGenerator).referent; |
+ TypeMirror DubGenRef = reflectType(DoubleGenerator).referent; |
+ |
+ Expect.isFalse(Func.isSubclassOf(NumPredRef)); |
+ Expect.isFalse(Func.isSubclassOf(IntPredRef)); |
+ Expect.isFalse(Func.isSubclassOf(DubPredRef)); |
+ Expect.isFalse(Func.isSubclassOf(NumGenRef)); |
+ Expect.isFalse(Func.isSubclassOf(IntGenRef)); |
+ Expect.isFalse(Func.isSubclassOf(DubGenRef)); |
+ |
+ // The spec doesn't require these to be either value. |
+ // NumPredRef.isSubclassOf(Func); |
+ // IntPredRef.isSubclassOf(Func); |
+ // DubPredRef.isSubclassOf(Func); |
+ // NumGenRef.isSubclassOf(Func); |
+ // IntGenRef.isSubclassOf(Func); |
+ // DubGenRef.isSubclassOf(Func); |
+} |