1 use Test::More tests=>22; {
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(
15 ## sugar for alternative syntax: depending {} TC,TC
17 my ($coderef, $dependent_tc, $constraining_tc) = @_;
18 return Depending[$dependent_tc,$coderef,$constraining_tc];
21 ## The dependent value must exceed the constraining value
22 subtype IntGreaterThanInt,
26 my ($dependent_val, $constraining_val) = @_;
27 return ($dependent_val > $constraining_val) ? 1:undef;
32 isa_ok IntGreaterThanInt, 'MooseX::Meta::TypeConstraint::Dependent';
33 ok !IntGreaterThanInt->check(['a',10]), "Fails, 'a' is not an Int.";
34 ok !IntGreaterThanInt->check([5,'b']), "Fails, 'b' is not an Int either.";
35 ok !IntGreaterThanInt->check({4,1}), "Fails, since this isn't an arrayref";
36 ok !IntGreaterThanInt->check([5,10]), "Fails, 5 is less than 10";
37 ok IntGreaterThanInt->check([11,6]), "Success, 11 is greater than 6.";
38 ok IntGreaterThanInt->check([12,1]), "Success, 12 is greater than1.";
39 ok IntGreaterThanInt->check([0,-10]), "Success, 0 is greater than -10.";
41 ## The dependent value cannot exist in the constraining arrayref
46 my ($dependent_int, $constraining_arrayref) = @_;
47 (grep { $_ == $dependent_int} @$constraining_arrayref) ? 0:1
52 isa_ok UniqueInt, 'MooseX::Meta::TypeConstraint::Dependent';
53 ok !UniqueInt->check(['a',[1,2,3]]), '"a" not an Int';
54 ok !UniqueInt->check([1,['b','c']]), '"b","c" not an arrayref';
55 ok !UniqueInt->check([1,[1,2,3]]), 'not unique in set';
56 ok !UniqueInt->check([10,[1,10,15]]), 'not unique in set';
57 ok UniqueInt->check([2,[3..6]]), 'PASS unique in set';
58 ok UniqueInt->check([3,[100..110]]), 'PASS unique in set';
60 ## Same as above, with suger
63 my ($dependent_int, $constraining_arrayref) = @_;
64 (grep { $_ == $dependent_int} @$constraining_arrayref) ? 0:1
67 isa_ok UniqueInt2, 'MooseX::Meta::TypeConstraint::Dependent';
68 ok !UniqueInt2->check(['a',[1,2,3]]), '"a" not an Int';
69 ok !UniqueInt2->check([1,['b','c']]), '"b","c" not an arrayref';
70 ok !UniqueInt2->check([1,[1,2,3]]), 'not unique in set';
71 ok !UniqueInt2->check([10,[1,10,15]]), 'not unique in set';
72 ok UniqueInt2->check([2,[3..6]]), 'PASS unique in set';
73 ok UniqueInt2->check([3,[100..110]]), 'PASS unique in set';