X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F11-overflow.t;h=8aec1b1abe71b8f81776d1bc2efaa16a4eaf9129;hb=9eb6e8c6a5da5d60eb1986db304565b8ea826aed;hp=3e8d0f41da386b0e9f91a50847eef941f239665d;hpb=797510e368ab5ee7fbc25581fa484534aa0988d3;p=gitmo%2FMooseX-Types-Structured.git diff --git a/t/11-overflow.t b/t/11-overflow.t index 3e8d0f4..8aec1b1 100644 --- a/t/11-overflow.t +++ b/t/11-overflow.t @@ -1,74 +1,38 @@ -BEGIN { - use strict; - use warnings; - use Test::More tests=>20; -} +use strict; +use warnings; +use Test::More tests=>12; use Moose::Util::TypeConstraints; -use MooseX::Types::Structured qw(Dict Tuple); -use MooseX::Types::Moose qw(Int Str ArrayRef HashRef); - - -sub merge(&$) { - my ($code, $tc) = @_; - return sub { - my @tail_args = @_; - $tc->check($code->(@tail_args)); - } -} +use MooseX::Types::Structured qw(Dict Tuple slurpy); +use MooseX::Types::Moose qw(Int Str ArrayRef HashRef Object); my $array_tailed_tuple = - subtype 'array_tailed_tuple', - as Tuple[ + Tuple[ Int, Str, - merge {[@_]} ArrayRef[Int], + slurpy ArrayRef[Int], ]; - + +is($array_tailed_tuple->name, 'MooseX::Types::Structured::Tuple[Int,Str,slurpy ArrayRef[Int]]'); + ok !$array_tailed_tuple->check(['ss',1]), 'correct fail'; ok $array_tailed_tuple->check([1,'ss']), 'correct pass'; ok !$array_tailed_tuple->check({}), 'correct fail'; ok $array_tailed_tuple->check([1,'hello',1,2,3,4]), 'correct pass with tail'; ok !$array_tailed_tuple->check([1,'hello',1,2,'bad',4]), 'correct fail with tail'; -my $hash_tailed_tuple = - subtype 'hash_tailed_tuple', - as Tuple[ - Int, - Str, - merge {+{@_}} HashRef[Int], - ]; - -ok !$hash_tailed_tuple->check(['ss',1]), 'correct fail'; -ok $hash_tailed_tuple->check([1,'ss']), 'correct pass'; -ok !$hash_tailed_tuple->check({}), 'correct fail'; -ok $hash_tailed_tuple->check([1,'hello',age=>25,zip=>10533]), 'correct pass with tail'; -ok !$hash_tailed_tuple->check([1,'hello',age=>25,name=>'john']), 'correct fail with tail'; - my $hash_tailed_dict = - subtype 'hash_tailed_dict', - as Dict[ + Dict[ name=>Str, age=>Int, - merge {+{@_}} HashRef[Int], + slurpy HashRef[Int], ]; - + +is($hash_tailed_dict->name, 'MooseX::Types::Structured::Dict[name,Str,age,Int,slurpy HashRef[Int]]'); + ok !$hash_tailed_dict->check({name=>'john',age=>'napiorkowski'}), 'correct fail'; ok $hash_tailed_dict->check({name=>'Vanessa Li', age=>35}), 'correct pass'; ok !$hash_tailed_dict->check([]), 'correct fail'; ok $hash_tailed_dict->check({name=>'Vanessa Li', age=>35, more1=>1,more2=>2}), 'correct pass with tail'; ok !$hash_tailed_dict->check({name=>'Vanessa Li', age=>35, more1=>1,more2=>"aa"}), 'correct fail with tail'; -my $array_tailed_dict = - subtype 'hash_tailed_dict', - as Dict[ - name=>Str, - age=>Int, - merge {[@_]} ArrayRef[Int], - ]; - -ok !$array_tailed_dict->check({name=>'john',age=>'napiorkowski'}), 'correct fail'; -ok $array_tailed_dict->check({name=>'Vanessa Li', age=>35}), 'correct pass'; -ok !$array_tailed_dict->check([]), 'correct fail'; -ok $array_tailed_dict->check({name=>'Vanessa Li', age=>35, 1,2}), 'correct pass with tail'; -ok !$array_tailed_dict->check({name=>'Vanessa Li', age=>35, 1, "hello"}), 'correct fail with tail';