created a more introspective slurpy function, moved it to the tc class, and some...
[gitmo/MooseX-Types-Structured.git] / t / 11-overflow.t
CommitLineData
ff801143 1BEGIN {
2 use strict;
3 use warnings;
4 use Test::More tests=>20;
5}
6
7use Moose::Util::TypeConstraints;
c116e19a 8use MooseX::Types::Structured qw(Dict Tuple slurpy);
9use MooseX::Types::Moose qw(Int Str ArrayRef HashRef Object);
3b14bb98 10
ff801143 11my $array_tailed_tuple =
12 subtype 'array_tailed_tuple',
13 as Tuple[
14 Int,
15 Str,
c116e19a 16 slurpy ArrayRef[Int],
ff801143 17 ];
18
19ok !$array_tailed_tuple->check(['ss',1]), 'correct fail';
20ok $array_tailed_tuple->check([1,'ss']), 'correct pass';
21ok !$array_tailed_tuple->check({}), 'correct fail';
22ok $array_tailed_tuple->check([1,'hello',1,2,3,4]), 'correct pass with tail';
23ok !$array_tailed_tuple->check([1,'hello',1,2,'bad',4]), 'correct fail with tail';
24
25my $hash_tailed_tuple =
26 subtype 'hash_tailed_tuple',
27 as Tuple[
28 Int,
29 Str,
c116e19a 30 slurpy HashRef[Int],
ff801143 31 ];
32
33ok !$hash_tailed_tuple->check(['ss',1]), 'correct fail';
34ok $hash_tailed_tuple->check([1,'ss']), 'correct pass';
35ok !$hash_tailed_tuple->check({}), 'correct fail';
36ok $hash_tailed_tuple->check([1,'hello',age=>25,zip=>10533]), 'correct pass with tail';
37ok !$hash_tailed_tuple->check([1,'hello',age=>25,name=>'john']), 'correct fail with tail';
38
39my $hash_tailed_dict =
40 subtype 'hash_tailed_dict',
41 as Dict[
42 name=>Str,
43 age=>Int,
c116e19a 44 slurpy HashRef[Int],
ff801143 45 ];
46
47ok !$hash_tailed_dict->check({name=>'john',age=>'napiorkowski'}), 'correct fail';
48ok $hash_tailed_dict->check({name=>'Vanessa Li', age=>35}), 'correct pass';
49ok !$hash_tailed_dict->check([]), 'correct fail';
50ok $hash_tailed_dict->check({name=>'Vanessa Li', age=>35, more1=>1,more2=>2}), 'correct pass with tail';
51ok !$hash_tailed_dict->check({name=>'Vanessa Li', age=>35, more1=>1,more2=>"aa"}), 'correct fail with tail';
52
53my $array_tailed_dict =
54 subtype 'hash_tailed_dict',
55 as Dict[
56 name=>Str,
57 age=>Int,
c116e19a 58 slurpy ArrayRef[Int],
ff801143 59 ];
60
61ok !$array_tailed_dict->check({name=>'john',age=>'napiorkowski'}), 'correct fail';
62ok $array_tailed_dict->check({name=>'Vanessa Li', age=>35}), 'correct pass';
63ok !$array_tailed_dict->check([]), 'correct fail';
64ok $array_tailed_dict->check({name=>'Vanessa Li', age=>35, 1,2}), 'correct pass with tail';
65ok !$array_tailed_dict->check({name=>'Vanessa Li', age=>35, 1, "hello"}), 'correct fail with tail';
c116e19a 66
67my $insane_tc =
68 subtype 'insane_tc',
69 as Tuple[
70 Object,
71 slurpy Dict[
72 name=>Str,
73 age=>Int,
74 slurpy ArrayRef[Int],
75 ]
76 ];
77
78ok $insane_tc->check([$insane_tc, name=>"John", age=>25, 1,2,3]),
79 'validated: [$insane_tc, name=>"John", age=>25, 1,2,3]';