'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'
);
'... (ArrayRef | HashRef) cannot accept Numbers'
);
+is(
+ $ArrayRef_or_HashRef->parent,
+ find_type_constraint('Ref'),
+ '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;