From: John Napiorkowski Date: Fri, 24 Oct 2008 20:07:54 +0000 (+0000) Subject: added tests for the subtyping parameterized constraints with new type parameters X-Git-Tag: 0.60~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=94330b084e61a283de6e79e9ebc47e096d7a9f56;p=gitmo%2FMoose.git added tests for the subtyping parameterized constraints with new type parameters --- diff --git a/t/040_type_constraints/016_subtyping_parameterized_types.t b/t/040_type_constraints/016_subtyping_parameterized_types.t index bd01271..8f1855e 100644 --- a/t/040_type_constraints/016_subtyping_parameterized_types.t +++ b/t/040_type_constraints/016_subtyping_parameterized_types.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 32; +use Test::More tests => 39; use Test::Exception; BEGIN { @@ -88,3 +88,34 @@ lives_ok { ok( !$t->check({ one => 1, two => "foo", three => [] }), "failed" ); ok( !$t->check({ one => 1 }), "failed" ); } + +{ + ## Because to throw errors in M:M:Parameterizable needs Moose loaded in + ## order to throw errors. In theory the use Moose belongs to that class + ## but when I put it there causes all sorts or trouble. In theory this is + ## never a real problem since you are likely to use Moose somewhere when you + ## are creating type constraints. + use Moose (); + + my $MyArrayRefInt = subtype 'MyArrayRefInt', + as 'ArrayRef[Int]'; + + my $BiggerInt = subtype 'BiggerInt', + as 'Int', + where {$_>10}; + + my $SubOfMyArrayRef = subtype 'SubOfMyArrayRef', + as 'MyArrayRefInt[BiggerInt]'; + + ok $MyArrayRefInt->check([1,2,3]), '[1,2,3] is okay'; + ok ! $MyArrayRefInt->check(["a","b"]), '["a","b"] is not'; + ok $BiggerInt->check(100), '100 is big enough'; + ok ! $BiggerInt->check(5), '5 is big enough'; + ok $SubOfMyArrayRef->check([15,20,25]), '[15,20,25] is a bunch of big ints'; + ok ! $SubOfMyArrayRef->check([15,5,25]), '[15,5,25] is NOT a bunch of big ints'; + + throws_ok sub { + my $SubOfMyArrayRef = subtype 'SubSubOfMyArrayRef', + as 'SubOfMyArrayRef[Str]'; + }, qr/Str is not a subtype of BiggerInt/, 'Failed to parameterize with a bad type parameter'; +}