created a more introspective slurpy function, moved it to the tc class, and some...
[gitmo/MooseX-Types-Structured.git] / t / 11-overflow.t
index 949061d..94328eb 100644 (file)
@@ -5,17 +5,15 @@ BEGIN {
 }
 
 use Moose::Util::TypeConstraints;
-use MooseX::Types::Structured qw(Dict Tuple);
-use MooseX::Types::Moose qw(Int Str ArrayRef HashRef);
+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[
         Int,
         Str,
-        sub {
-            (ArrayRef[Int])->check([@_]);
-        },
+        slurpy ArrayRef[Int],
      ];
   
 ok !$array_tailed_tuple->check(['ss',1]), 'correct fail';
@@ -29,9 +27,7 @@ my $hash_tailed_tuple =
      as Tuple[
        Int,
        Str,
-       sub {
-        (HashRef[Int])->check({@_});
-       },
+       slurpy HashRef[Int],
      ];
 
 ok !$hash_tailed_tuple->check(['ss',1]), 'correct fail';
@@ -45,9 +41,7 @@ my $hash_tailed_dict =
     as Dict[
       name=>Str,
       age=>Int,
-      sub {
-        (HashRef[Int])->check({@_});        
-      }
+      slurpy HashRef[Int],
     ];
     
 ok !$hash_tailed_dict->check({name=>'john',age=>'napiorkowski'}), 'correct fail';
@@ -61,9 +55,7 @@ my $array_tailed_dict =
     as Dict[
       name=>Str,
       age=>Int,
-      sub {
-        (ArrayRef[Int])->check([@_]);       
-      }
+      slurpy ArrayRef[Int],
     ];
     
 ok !$array_tailed_dict->check({name=>'john',age=>'napiorkowski'}), 'correct fail';
@@ -72,3 +64,16 @@ 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';
 
+my $insane_tc =
+       subtype 'insane_tc',
+       as Tuple[
+               Object,
+               slurpy Dict[
+                       name=>Str,
+                       age=>Int,
+                       slurpy ArrayRef[Int],
+               ]
+       ];
+       
+ok $insane_tc->check([$insane_tc, name=>"John", age=>25, 1,2,3]),
+  'validated: [$insane_tc, name=>"John", age=>25, 1,2,3]';
\ No newline at end of file