Commit | Line | Data |
7970c9bd |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use MooseX::Types::Parameterizable qw(Parameterizable); |
6 | use MooseX::Types::Moose qw( Int ArrayRef ); |
7 | use MooseX::Types -declare=>[qw( EvenInt ArrayOfEvenIntsWithLength )]; |
8 | |
9 | ok subtype( EvenInt, |
10 | as Int, |
11 | where { |
12 | my $val = shift @_; |
13 | return $val % 2 ? 0:1; |
14 | }), |
15 | 'Created a subtype of Int'; |
16 | |
17 | ok subtype( |
18 | ArrayOfEvenIntsWithLength, |
19 | as Parameterizable[ |
20 | ArrayRef[EvenInt], |
21 | Int, |
22 | ], |
23 | where { |
24 | my ($value, $int) = @_; |
25 | my $length = scalar(@$value); |
26 | $length < ($int+1) ? 1:0; |
27 | }, |
28 | ), 'Created parameterized parameterized!'; |
29 | |
30 | ok ! ArrayOfEvenIntsWithLength([5])->check([2,4,6,8,10,12,14]), |
31 | 'correctly failed too long array'; |
32 | |
33 | ok ! ArrayOfEvenIntsWithLength([5])->check([2,4,6,8,11]), |
34 | 'correctly failed with odd number in array'; |
35 | |
36 | ok ArrayOfEvenIntsWithLength([5])->check([2,4,6]), |
37 | 'correctly passed array'; |
38 | |
39 | done_testing; |
40 | |