4 use Test::More tests=>20;
7 use Moose::Util::TypeConstraints;
8 use MooseX::Types::Structured qw(Dict Tuple slurpy);
9 use MooseX::Types::Moose qw(Int Str ArrayRef HashRef Object);
11 my $array_tailed_tuple =
12 subtype 'array_tailed_tuple',
19 ok !$array_tailed_tuple->check(['ss',1]), 'correct fail';
20 ok $array_tailed_tuple->check([1,'ss']), 'correct pass';
21 ok !$array_tailed_tuple->check({}), 'correct fail';
22 ok $array_tailed_tuple->check([1,'hello',1,2,3,4]), 'correct pass with tail';
23 ok !$array_tailed_tuple->check([1,'hello',1,2,'bad',4]), 'correct fail with tail';
25 my $hash_tailed_tuple =
26 subtype 'hash_tailed_tuple',
33 ok !$hash_tailed_tuple->check(['ss',1]), 'correct fail';
34 ok $hash_tailed_tuple->check([1,'ss']), 'correct pass';
35 ok !$hash_tailed_tuple->check({}), 'correct fail';
36 ok $hash_tailed_tuple->check([1,'hello',age=>25,zip=>10533]), 'correct pass with tail';
37 ok !$hash_tailed_tuple->check([1,'hello',age=>25,name=>'john']), 'correct fail with tail';
39 my $hash_tailed_dict =
40 subtype 'hash_tailed_dict',
47 ok !$hash_tailed_dict->check({name=>'john',age=>'napiorkowski'}), 'correct fail';
48 ok $hash_tailed_dict->check({name=>'Vanessa Li', age=>35}), 'correct pass';
49 ok !$hash_tailed_dict->check([]), 'correct fail';
50 ok $hash_tailed_dict->check({name=>'Vanessa Li', age=>35, more1=>1,more2=>2}), 'correct pass with tail';
51 ok !$hash_tailed_dict->check({name=>'Vanessa Li', age=>35, more1=>1,more2=>"aa"}), 'correct fail with tail';
53 my $array_tailed_dict =
54 subtype 'hash_tailed_dict',
61 ok !$array_tailed_dict->check({name=>'john',age=>'napiorkowski'}), 'correct fail';
62 ok $array_tailed_dict->check({name=>'Vanessa Li', age=>35}), 'correct pass';
63 ok !$array_tailed_dict->check([]), 'correct fail';
64 ok $array_tailed_dict->check({name=>'Vanessa Li', age=>35, 1,2}), 'correct pass with tail';
65 ok !$array_tailed_dict->check({name=>'Vanessa Li', age=>35, 1, "hello"}), 'correct fail with tail';
78 ok $insane_tc->check([$insane_tc, name=>"John", age=>25, 1,2,3]),
79 'validated: [$insane_tc, name=>"John", age=>25, 1,2,3]';