create a basic type, clarified and regularized some of the naming conventions for...
[gitmo/MooseX-Dependent.git] / t / 02-depending.t
1 use Test::More tests=>8; {
2     
3     use strict;
4     use warnings;
5     
6     use Test::Exception;
7     use MooseX::Types::Dependent qw(Depending);
8         use MooseX::Types::Moose qw(Int Str Object ArrayRef HashRef Maybe);
9         use MooseX::Types -declare => [qw(
10         IntGreaterThanInt
11     )];
12     
13     subtype IntGreaterThanInt,
14       as Depending[
15         Int,
16         sub {
17                         my ($dependent_val, $constraining_val) = @_;
18                         return ($dependent_val > $constraining_val) ? 1:undef;
19         },
20         Int,
21       ];
22       
23         isa_ok IntGreaterThanInt, 'MooseX::Meta::TypeConstraint::Dependent';
24         
25         ok !IntGreaterThanInt->check(['a',10]), "Fails, 'a' is not an Int.";
26         ok !IntGreaterThanInt->check([5,'b']), "Fails, 'b' is not an Int either.";
27         ok !IntGreaterThanInt->check({4,1}), "Fails, since this isn't an arrayref";
28         ok !IntGreaterThanInt->check([5,10]), "Fails, 5 is less than 10";
29         ok IntGreaterThanInt->check([11,6]), "Success, 11 is greater than 6.";
30         ok IntGreaterThanInt->check([12,1]), "Success, 12 is greater than1.";
31         ok IntGreaterThanInt->check([0,-10]), "Success, 0 is greater than -10.";
32 }