From: John Napiorkowski Date: Thu, 24 Jun 2010 13:09:20 +0000 (-0400) Subject: some additional tests X-Git-Tag: 0.02~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7970c9bd1c7cbc7d3fbac27bd151ce7d0552a67d;p=gitmo%2FMooseX-Dependent.git some additional tests --- diff --git a/t/04-types-parameterizable-parameterized.t b/t/04-types-parameterizable-parameterized.t new file mode 100644 index 0000000..07d2416 --- /dev/null +++ b/t/04-types-parameterizable-parameterized.t @@ -0,0 +1,40 @@ +use strict; +use warnings; + +use Test::More; +use MooseX::Types::Parameterizable qw(Parameterizable); +use MooseX::Types::Moose qw( Int ArrayRef ); +use MooseX::Types -declare=>[qw( EvenInt ArrayOfEvenIntsWithLength )]; + +ok subtype( EvenInt, + as Int, + where { + my $val = shift @_; + return $val % 2 ? 0:1; + }), + 'Created a subtype of Int'; + +ok subtype( + ArrayOfEvenIntsWithLength, + as Parameterizable[ + ArrayRef[EvenInt], + Int, + ], + where { + my ($value, $int) = @_; + my $length = scalar(@$value); + $length < ($int+1) ? 1:0; + }, +), 'Created parameterized parameterized!'; + +ok ! ArrayOfEvenIntsWithLength([5])->check([2,4,6,8,10,12,14]), + 'correctly failed too long array'; + +ok ! ArrayOfEvenIntsWithLength([5])->check([2,4,6,8,11]), + 'correctly failed with odd number in array'; + +ok ArrayOfEvenIntsWithLength([5])->check([2,4,6]), + 'correctly passed array'; + +done_testing; +