Require Dist::Zilla 4.200016+
[gitmo/Moose.git] / t / type_constraints / union_types.t
index 9e5385b..fb1f789 100644 (file)
@@ -81,9 +81,9 @@ is(
     'parent of Str|Undef is Item'
 );
 
-is(
-    $Str_or_Undef->parents,
-    find_type_constraint('Item'),
+is_deeply(
+    [$Str_or_Undef->parents],
+    [find_type_constraint('Item')],
     'parents of Str|Undef is Item'
 );
 
@@ -157,4 +157,41 @@ is(
     'parent of ArrayRef|HashRef is Ref'
 );
 
+my $double_union = Moose::Meta::TypeConstraint::Union->new(
+    type_constraints => [ $Str_or_Undef, $ArrayRef_or_HashRef ] );
+
+is(
+    $double_union->parent,
+    find_type_constraint('Item'),
+    'parent of (Str|Undef)|(ArrayRef|HashRef) is Item'
+);
+
+ok(
+    $double_union->is_subtype_of('Item'),
+    '(Str|Undef)|(ArrayRef|HashRef) is a subtype of Item'
+);
+
+ok(
+    $double_union->is_a_type_of('Item'),
+    '(Str|Undef)|(ArrayRef|HashRef) is a type of Item'
+);
+
+ok(
+    !$double_union->is_a_type_of('Str'),
+    '(Str|Undef)|(ArrayRef|HashRef) is not a type of Str'
+);
+
+type 'SomeType', where { 1 };
+type 'OtherType', where { 1 };
+
+my $parentless_union = Moose::Meta::TypeConstraint::Union->new(
+    type_constraints => [
+        find_type_constraint('SomeType'),
+        find_type_constraint('OtherType'),
+    ],
+);
+
+is($parentless_union->parent, undef, "no common ancestor gives undef parent");
+
+
 done_testing;