From: Dave Rolsky Date: Fri, 16 Sep 2011 14:00:18 +0000 (-0500) Subject: A union and a bare subtype of that union should report the same results for ->is_subt... X-Git-Tag: 2.0300~52 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cd34fa12b3779d4c3c60f41644afd1ba13af15c5;p=gitmo%2FMoose.git A union and a bare subtype of that union should report the same results for ->is_subtype_of and ->is_a_type_of --- diff --git a/t/type_constraints/subtyping_union_types.t b/t/type_constraints/subtyping_union_types.t index 9b13263..3579044 100644 --- a/t/type_constraints/subtyping_union_types.t +++ b/t/type_constraints/subtyping_union_types.t @@ -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;