1 use Test::More tests=>15; {
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(
14 ## The dependent value must exceed the constraining value
15 subtype IntGreaterThanInt,
19 my ($dependent_val, $constraining_val) = @_;
20 return ($dependent_val > $constraining_val) ? 1:undef;
25 isa_ok IntGreaterThanInt, 'MooseX::Meta::TypeConstraint::Dependent';
26 ok !IntGreaterThanInt->check(['a',10]), "Fails, 'a' is not an Int.";
27 ok !IntGreaterThanInt->check([5,'b']), "Fails, 'b' is not an Int either.";
28 ok !IntGreaterThanInt->check({4,1}), "Fails, since this isn't an arrayref";
29 ok !IntGreaterThanInt->check([5,10]), "Fails, 5 is less than 10";
30 ok IntGreaterThanInt->check([11,6]), "Success, 11 is greater than 6.";
31 ok IntGreaterThanInt->check([12,1]), "Success, 12 is greater than1.";
32 ok IntGreaterThanInt->check([0,-10]), "Success, 0 is greater than -10.";
34 ## The dependent value cannot exist in the constraining arrayref
39 my ($dependent_int, $constraining_arrayref) = @_;
40 (grep { $_ == $dependent_int} @$constraining_arrayref) ? 0:1
45 isa_ok UniqueInt, 'MooseX::Meta::TypeConstraint::Dependent';
46 ok !UniqueInt->check(['a',[1,2,3]]), '"a" not an Int';
47 ok !UniqueInt->check([1,['b','c']]), '"b","c" not an arrayref';
48 ok !UniqueInt->check([1,[1,2,3]]), 'not unique in set';
49 ok !UniqueInt->check([10,[1,10,15]]), 'not unique in set';
50 ok UniqueInt->check([2,[3..6]]), 'PASS unique in set';
51 ok UniqueInt->check([3,[100..110]]), 'PASS unique in set';