first go at supporting callbacks in the type parameter list, added test for it
[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;
8use MooseX::Types::Structured qw(Dict Tuple);
9use MooseX::Types::Moose qw(Int Str ArrayRef HashRef);
10
11my $array_tailed_tuple =
12 subtype 'array_tailed_tuple',
13 as Tuple[
14 Int,
15 Str,
16 sub {
17 (ArrayRef[Int])->check([@_]);
18 },
19 ];
20
21ok !$array_tailed_tuple->check(['ss',1]), 'correct fail';
22ok $array_tailed_tuple->check([1,'ss']), 'correct pass';
23ok !$array_tailed_tuple->check({}), 'correct fail';
24ok $array_tailed_tuple->check([1,'hello',1,2,3,4]), 'correct pass with tail';
25ok !$array_tailed_tuple->check([1,'hello',1,2,'bad',4]), 'correct fail with tail';
26
27my $hash_tailed_tuple =
28 subtype 'hash_tailed_tuple',
29 as Tuple[
30 Int,
31 Str,
32 sub {
33 (HashRef[Int])->check({@_});
34 },
35 ];
36
37ok !$hash_tailed_tuple->check(['ss',1]), 'correct fail';
38ok $hash_tailed_tuple->check([1,'ss']), 'correct pass';
39ok !$hash_tailed_tuple->check({}), 'correct fail';
40ok $hash_tailed_tuple->check([1,'hello',age=>25,zip=>10533]), 'correct pass with tail';
41ok !$hash_tailed_tuple->check([1,'hello',age=>25,name=>'john']), 'correct fail with tail';
42
43my $hash_tailed_dict =
44 subtype 'hash_tailed_dict',
45 as Dict[
46 name=>Str,
47 age=>Int,
48 sub {
49 (HashRef[Int])->check({@_});
50 }
51 ];
52
53ok !$hash_tailed_dict->check({name=>'john',age=>'napiorkowski'}), 'correct fail';
54ok $hash_tailed_dict->check({name=>'Vanessa Li', age=>35}), 'correct pass';
55ok !$hash_tailed_dict->check([]), 'correct fail';
56ok $hash_tailed_dict->check({name=>'Vanessa Li', age=>35, more1=>1,more2=>2}), 'correct pass with tail';
57ok !$hash_tailed_dict->check({name=>'Vanessa Li', age=>35, more1=>1,more2=>"aa"}), 'correct fail with tail';
58
59my $array_tailed_dict =
60 subtype 'hash_tailed_dict',
61 as Dict[
62 name=>Str,
63 age=>Int,
64 sub {
65 (ArrayRef[Int])->check([@_]);
66 }
67 ];
68
69ok !$array_tailed_dict->check({name=>'john',age=>'napiorkowski'}), 'correct fail';
70ok $array_tailed_dict->check({name=>'Vanessa Li', age=>35}), 'correct pass';
71ok !$array_tailed_dict->check([]), 'correct fail';
72ok $array_tailed_dict->check({name=>'Vanessa Li', age=>35, 1,2}), 'correct pass with tail';
73ok !$array_tailed_dict->check({name=>'Vanessa Li', age=>35, 1, "hello"}), 'correct fail with tail';
74