From: Shawn M Moore Date: Sat, 22 Mar 2008 19:42:48 +0000 (+0000) Subject: Failing tests for Str and ArrayRef being subtypes of (Str | ArrayRef) X-Git-Tag: 0_55~259 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c12172fac6cdd220bfaf3cb84780cb6c64ca01d1;p=gitmo%2FMoose.git Failing tests for Str and ArrayRef being subtypes of (Str | ArrayRef) --- diff --git a/t/040_type_constraints/008_union_types.t b/t/040_type_constraints/008_union_types.t index 5ccf213..86f0f7c 100644 --- a/t/040_type_constraints/008_union_types.t +++ b/t/040_type_constraints/008_union_types.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 27; +use Test::More tests => 34; use Test::Exception; BEGIN { @@ -67,3 +67,17 @@ is($HashOrArray->validate(50), 'Validation failed for \'ArrayRef\' failed with value 50 and Validation failed for \'HashRef\' failed with value 50 in (ArrayRef | HashRef)', '... (ArrayRef | HashRef) cannot accept Numbers'); +my $StrOrArray = Moose::Meta::TypeConstraint::Union->new(type_constraints => [$Str, $ArrayRef]); +isa_ok($StrOrArray, 'Moose::Meta::TypeConstraint'); + +ok(!defined($StrOrArray->validate("hi"))); +ok(!defined($StrOrArray->validate([]))); +ok(!defined($StrOrArray->validate([1]))); + +like($StrOrArray->validate({}), +qr/Validation failed for \'Str\' failed with value HASH\(0x.+?\) and Validation failed for \'ArrayRef\' failed with value HASH\(0x.+?\) in \(Str \| ArrayRef\)/, +'... (Str | ArrayRef) cannot accept HashRefs'); + +ok($Str->is_subtype_of($StrOrArray), "Str is a subtype of (Str | ArrayRef)"); +ok($ArrayRef->is_subtype_of($StrOrArray), "ArrayRef is a subtype of (Str | ArrayRef)" ); +