A union and a bare subtype of that union should report the same results for ->is_subt...
Dave Rolsky [Fri, 16 Sep 2011 14:00:18 +0000 (09:00 -0500)]
t/type_constraints/subtyping_union_types.t

index 9b13263..3579044 100644 (file)
@@ -64,4 +64,47 @@ is( exception {
     ok(!$t->check(1), '... validated it correctly');
 }
 
+{
+    my $union = Moose::Util::TypeConstraints::find_or_create_type_constraint('Int|ArrayRef[Int]');
+    subtype 'UnionSub', as 'Int|ArrayRef[Int]';
+
+    my $subtype = find_type_constraint('UnionSub');
+
+    ok(
+        !$union->is_a_type_of('Ref'),
+        'Int|ArrayRef[Int] is not a type of Ref'
+    );
+    ok(
+        !$subtype->is_a_type_of('Ref'),
+        'subtype of Int|ArrayRef[Int] is not a type of Ref'
+    );
+
+    ok(
+        $union->is_a_type_of('Defined'),
+        'Int|ArrayRef[Int] is a type of Defined'
+    );
+    ok(
+        $subtype->is_a_type_of('Defined'),
+        'subtype of Int|ArrayRef[Int] is a type of Defined'
+    );
+
+    ok(
+        !$union->is_subtype_of('Ref'),
+        'Int|ArrayRef[Int] is not a subtype of Ref'
+    );
+    ok(
+        !$subtype->is_subtype_of('Ref'),
+        'subtype of Int|ArrayRef[Int] is not a subtype of Ref'
+    );
+
+    ok(
+        $union->is_subtype_of('Defined'),
+        'Int|ArrayRef[Int] is a subtype of Defined'
+    );
+    ok(
+        $subtype->is_subtype_of('Defined'),
+        'subtype of Int|ArrayRef[Int] is a subtype of Defined'
+    );
+}
+
 done_testing;