[Moose-commits] r7868 - MooseX-Types-Dependent/trunk/t

jnapiorkowski at code2.0beta.co.uk jnapiorkowski at code2.0beta.co.uk
Mon Mar 30 00:28:09 BST 2009


Author: jnapiorkowski
Date: 2009-03-29 16:28:09 -0700 (Sun, 29 Mar 2009)
New Revision: 7868

Modified:
   MooseX-Types-Dependent/trunk/t/02-depending.t
Log:
added another example test to show more useful functionality

Modified: MooseX-Types-Dependent/trunk/t/02-depending.t
===================================================================
--- MooseX-Types-Dependent/trunk/t/02-depending.t	2009-03-29 23:13:13 UTC (rev 7867)
+++ MooseX-Types-Dependent/trunk/t/02-depending.t	2009-03-29 23:28:09 UTC (rev 7868)
@@ -1,4 +1,4 @@
-use Test::More tests=>8; {
+use Test::More tests=>15; {
     
     use strict;
     use warnings;
@@ -8,8 +8,10 @@
  	use MooseX::Types::Moose qw(Int Str Object ArrayRef HashRef Maybe);
 	use MooseX::Types -declare => [qw(
         IntGreaterThanInt
+        UniqueInt
     )];
     
+    ## The dependent value must exceed the constraining value
     subtype IntGreaterThanInt,
       as Depending[
         Int,
@@ -19,9 +21,8 @@
         },
         Int,
       ];
-      
+
 	isa_ok IntGreaterThanInt, 'MooseX::Meta::TypeConstraint::Dependent';
-	
 	ok !IntGreaterThanInt->check(['a',10]), "Fails, 'a' is not an Int.";
 	ok !IntGreaterThanInt->check([5,'b']), "Fails, 'b' is not an Int either.";
 	ok !IntGreaterThanInt->check({4,1}), "Fails, since this isn't an arrayref";
@@ -29,4 +30,23 @@
 	ok IntGreaterThanInt->check([11,6]), "Success, 11 is greater than 6.";
 	ok IntGreaterThanInt->check([12,1]), "Success, 12 is greater than1.";
 	ok IntGreaterThanInt->check([0,-10]), "Success, 0 is greater than -10.";
+    
+    ## The dependent value cannot exist in the constraining arrayref
+    subtype UniqueInt,
+      as Depending[
+        Int,
+        sub {
+            my ($dependent_int, $constraining_arrayref) = @_;
+            (grep { $_ == $dependent_int} @$constraining_arrayref) ? 0:1
+        },
+        ArrayRef[Int],
+      ];
+      
+    isa_ok UniqueInt, 'MooseX::Meta::TypeConstraint::Dependent';
+    ok !UniqueInt->check(['a',[1,2,3]]), '"a" not an Int';
+    ok !UniqueInt->check([1,['b','c']]), '"b","c" not an arrayref';    
+    ok !UniqueInt->check([1,[1,2,3]]), 'not unique in set';
+    ok !UniqueInt->check([10,[1,10,15]]), 'not unique in set';
+    ok UniqueInt->check([2,[3..6]]), 'PASS unique in set';
+    ok UniqueInt->check([3,[100..110]]), 'PASS unique in set';    
 }




More information about the Moose-commits mailing list