Commit | Line | Data |
a61f836a |
1 | use strict; |
2 | use warnings; |
3 | use Test::More tests=>12; |
ff801143 |
4 | |
5 | use Moose::Util::TypeConstraints; |
c116e19a |
6 | use MooseX::Types::Structured qw(Dict Tuple slurpy); |
7 | use MooseX::Types::Moose qw(Int Str ArrayRef HashRef Object); |
3b14bb98 |
8 | |
ff801143 |
9 | my $array_tailed_tuple = |
a61f836a |
10 | Tuple[ |
ff801143 |
11 | Int, |
12 | Str, |
c116e19a |
13 | slurpy ArrayRef[Int], |
ff801143 |
14 | ]; |
a61f836a |
15 | |
16 | is($array_tailed_tuple->name, 'MooseX::Types::Structured::Tuple[Int,Str,slurpy ArrayRef[Int]]'); |
17 | |
ff801143 |
18 | ok !$array_tailed_tuple->check(['ss',1]), 'correct fail'; |
19 | ok $array_tailed_tuple->check([1,'ss']), 'correct pass'; |
20 | ok !$array_tailed_tuple->check({}), 'correct fail'; |
21 | ok $array_tailed_tuple->check([1,'hello',1,2,3,4]), 'correct pass with tail'; |
22 | ok !$array_tailed_tuple->check([1,'hello',1,2,'bad',4]), 'correct fail with tail'; |
23 | |
ff801143 |
24 | my $hash_tailed_dict = |
a61f836a |
25 | Dict[ |
ff801143 |
26 | name=>Str, |
27 | age=>Int, |
c116e19a |
28 | slurpy HashRef[Int], |
ff801143 |
29 | ]; |
a61f836a |
30 | |
31 | is($hash_tailed_dict->name, 'MooseX::Types::Structured::Dict[name,Str,age,Int,slurpy HashRef[Int]]'); |
32 | |
ff801143 |
33 | ok !$hash_tailed_dict->check({name=>'john',age=>'napiorkowski'}), 'correct fail'; |
34 | ok $hash_tailed_dict->check({name=>'Vanessa Li', age=>35}), 'correct pass'; |
35 | ok !$hash_tailed_dict->check([]), 'correct fail'; |
36 | ok $hash_tailed_dict->check({name=>'Vanessa Li', age=>35, more1=>1,more2=>2}), 'correct pass with tail'; |
37 | ok !$hash_tailed_dict->check({name=>'Vanessa Li', age=>35, more1=>1,more2=>"aa"}), 'correct fail with tail'; |
38 | |
52ffe972 |
39 | __END__ |
40 | |
41 | my $hash_tailed_tuple = |
42 | subtype 'hash_tailed_tuple', |
43 | as Tuple[ |
44 | Int, |
45 | Str, |
46 | slurpy HashRef[Int], |
47 | ]; |
48 | |
49 | ok !$hash_tailed_tuple->check(['ss',1]), 'correct fail'; |
50 | ok $hash_tailed_tuple->check([1,'ss']), 'correct pass'; |
51 | ok !$hash_tailed_tuple->check({}), 'correct fail'; |
52 | ok $hash_tailed_tuple->check([1,'hello',age=>25,zip=>10533]), 'correct pass with tail'; |
53 | ok !$hash_tailed_tuple->check([1,'hello',age=>25,name=>'john']), 'correct fail with tail'; |
54 | |
ff801143 |
55 | my $array_tailed_dict = |
56 | subtype 'hash_tailed_dict', |
57 | as Dict[ |
58 | name=>Str, |
59 | age=>Int, |
c116e19a |
60 | slurpy ArrayRef[Int], |
ff801143 |
61 | ]; |
62 | |
63 | ok !$array_tailed_dict->check({name=>'john',age=>'napiorkowski'}), 'correct fail'; |
64 | ok $array_tailed_dict->check({name=>'Vanessa Li', age=>35}), 'correct pass'; |
65 | ok !$array_tailed_dict->check([]), 'correct fail'; |
52ffe972 |
66 | ok $array_tailed_dict->check({name=>'Vanessa Li', age=>35, 1,2,3}), 'correct pass with tail'; |
ff801143 |
67 | ok !$array_tailed_dict->check({name=>'Vanessa Li', age=>35, 1, "hello"}), 'correct fail with tail'; |