properly supporting a where clause in the suger example and proof you can customize...
[gitmo/MooseX-Dependent.git] / t / 01-basic.t
index 136928b..86b12e0 100644 (file)
@@ -1,5 +1,5 @@
 
-use Test::More tests=>8; {
+use Test::More tests=>9; {
        
        use strict;
        use warnings;
@@ -7,8 +7,9 @@ use Test::More tests=>8; {
        use_ok 'MooseX::Meta::TypeConstraint::Dependent';
        use_ok 'Moose::Util::TypeConstraints';
 
-       ## A sample dependent type constraint the requires two ints and see which
-       ## is the greater.
+       ## A sample dependent type constraint the requires two ints and sees if
+       ## the dependent value (the first) is greater than the constraining value
+       ## (the second).
        
        ok my $int = find_type_constraint('Int') => 'Got Int';
        
@@ -16,23 +17,22 @@ use Test::More tests=>8; {
                name => "MooseX::Types::Dependent::Depending" ,
                parent => find_type_constraint('ArrayRef'),
                dependent_type_constraint=>$int,
-               comparision_callback=>sub {
-                       my ($constraining_value, $check_value) = @_;
-                       return $constraining_value > $check_value ? 0:1;
+               comparison_callback=>sub {
+                       my ($dependent_val, $constraining_val) = @_;
+                       return ($dependent_val > $constraining_val) ? 1:undef;
                },
-               constraint_generator =>$int,
-               constraint_generator=> sub { 
-                       my ($callback, $constraining_value, $check_value) = @_;
-                       return $callback->($constraining_value, $check_value) ? 1:0;
+               constraining_type_constraint =>$int,
+               constraint_generator=> sub {
+                       my ($dependent_val, $callback, $constraining_val) = @_;
+                       return $callback->($dependent_val, $constraining_val);
                },
        );
-       
-       ## Does this work at all?
 
        isa_ok $dep_tc, 'MooseX::Meta::TypeConstraint::Dependent';
-
-       ok !$dep_tc->check([5,10]), "Fails, 5 is less than 10";
+       
        ok !$dep_tc->check(['a',10]), "Fails, 'a' is not an Int.";
        ok !$dep_tc->check([5,'b']), "Fails, 'b' is not an Int either.";
-       ok $dep_tc->check([10,5]), "Success, 10 is greater than 5.";
+       ok !$dep_tc->check({4,1}), "Fails, since this isn't an arrayref";
+       ok !$dep_tc->check([5,10]), "Fails, 5 is less than 10";
+       ok $dep_tc->check([11,6]), "Success, 11 is greater than 6.";
 }