4 use Test::More tests=>20;
7 use Moose::Util::TypeConstraints;
8 use MooseX::Types::Structured qw(Dict Tuple);
9 use MooseX::Types::Moose qw(Int Str ArrayRef HashRef);
16 $tc->check($code->(@tail_args));
20 my $array_tailed_tuple =
21 subtype 'array_tailed_tuple',
25 merge {[@_]} ArrayRef[Int],
28 ok !$array_tailed_tuple->check(['ss',1]), 'correct fail';
29 ok $array_tailed_tuple->check([1,'ss']), 'correct pass';
30 ok !$array_tailed_tuple->check({}), 'correct fail';
31 ok $array_tailed_tuple->check([1,'hello',1,2,3,4]), 'correct pass with tail';
32 ok !$array_tailed_tuple->check([1,'hello',1,2,'bad',4]), 'correct fail with tail';
34 my $hash_tailed_tuple =
35 subtype 'hash_tailed_tuple',
39 merge {+{@_}} HashRef[Int],
42 ok !$hash_tailed_tuple->check(['ss',1]), 'correct fail';
43 ok $hash_tailed_tuple->check([1,'ss']), 'correct pass';
44 ok !$hash_tailed_tuple->check({}), 'correct fail';
45 ok $hash_tailed_tuple->check([1,'hello',age=>25,zip=>10533]), 'correct pass with tail';
46 ok !$hash_tailed_tuple->check([1,'hello',age=>25,name=>'john']), 'correct fail with tail';
48 my $hash_tailed_dict =
49 subtype 'hash_tailed_dict',
53 merge {+{@_}} HashRef[Int],
56 ok !$hash_tailed_dict->check({name=>'john',age=>'napiorkowski'}), 'correct fail';
57 ok $hash_tailed_dict->check({name=>'Vanessa Li', age=>35}), 'correct pass';
58 ok !$hash_tailed_dict->check([]), 'correct fail';
59 ok $hash_tailed_dict->check({name=>'Vanessa Li', age=>35, more1=>1,more2=>2}), 'correct pass with tail';
60 ok !$hash_tailed_dict->check({name=>'Vanessa Li', age=>35, more1=>1,more2=>"aa"}), 'correct fail with tail';
62 my $array_tailed_dict =
63 subtype 'hash_tailed_dict',
67 merge {[@_]} ArrayRef[Int],
70 ok !$array_tailed_dict->check({name=>'john',age=>'napiorkowski'}), 'correct fail';
71 ok $array_tailed_dict->check({name=>'Vanessa Li', age=>35}), 'correct pass';
72 ok !$array_tailed_dict->check([]), 'correct fail';
73 ok $array_tailed_dict->check({name=>'Vanessa Li', age=>35, 1,2}), 'correct pass with tail';
74 ok !$array_tailed_dict->check({name=>'Vanessa Li', age=>35, 1, "hello"}), 'correct fail with tail';