[Moose-commits] r7871 - in MooseX-Types-Dependent/trunk: . t
jnapiorkowski at code2.0beta.co.uk
jnapiorkowski at code2.0beta.co.uk
Mon Mar 30 15:13:44 BST 2009
Author: jnapiorkowski
Date: 2009-03-30 07:13:44 -0700 (Mon, 30 Mar 2009)
New Revision: 7871
Modified:
MooseX-Types-Dependent/trunk/Makefile.PL
MooseX-Types-Dependent/trunk/t/02-depending.t
Log:
added possible alternative syntax and tests
Modified: MooseX-Types-Dependent/trunk/Makefile.PL
===================================================================
--- MooseX-Types-Dependent/trunk/Makefile.PL 2009-03-30 03:18:00 UTC (rev 7870)
+++ MooseX-Types-Dependent/trunk/Makefile.PL 2009-03-30 14:13:44 UTC (rev 7871)
@@ -9,7 +9,7 @@
## Module dependencies
requires 'Moose' => '0.73';
-requires 'MooseX::Types' => '.10';
+requires 'MooseX::Types' => '0.10';
requires 'Scalar::Util' => '1.19';
## Testing dependencies
Modified: MooseX-Types-Dependent/trunk/t/02-depending.t
===================================================================
--- MooseX-Types-Dependent/trunk/t/02-depending.t 2009-03-30 03:18:00 UTC (rev 7870)
+++ MooseX-Types-Dependent/trunk/t/02-depending.t 2009-03-30 14:13:44 UTC (rev 7871)
@@ -1,4 +1,4 @@
-use Test::More tests=>15; {
+use Test::More tests=>22; {
use strict;
use warnings;
@@ -9,7 +9,14 @@
use MooseX::Types -declare => [qw(
IntGreaterThanInt
UniqueInt
+ UniqueInt2
)];
+
+ ## sugar for alternative syntax: depending {} TC,TC
+ sub depending(&$$) {
+ my ($coderef, $dependent_tc, $constraining_tc) = @_;
+ return Depending[$dependent_tc,$coderef,$constraining_tc];
+ }
## The dependent value must exceed the constraining value
subtype IntGreaterThanInt,
@@ -50,5 +57,22 @@
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';
+ ok UniqueInt->check([3,[100..110]]), 'PASS unique in set';
+
+ ## Same as above, with suger
+ subtype UniqueInt2,
+ as depending {
+ my ($dependent_int, $constraining_arrayref) = @_;
+ ## Yes, this is braindead way to check for uniques in an array
+ ## but this doesn't require additional dependencies.
+ (grep { $_ == $dependent_int} @$constraining_arrayref) ? 0:1
+ } Int, ArrayRef[Int];
+
+ isa_ok UniqueInt2, 'MooseX::Meta::TypeConstraint::Dependent';
+ ok !UniqueInt2->check(['a',[1,2,3]]), '"a" not an Int';
+ ok !UniqueInt2->check([1,['b','c']]), '"b","c" not an arrayref';
+ ok !UniqueInt2->check([1,[1,2,3]]), 'not unique in set';
+ ok !UniqueInt2->check([10,[1,10,15]]), 'not unique in set';
+ ok UniqueInt2->check([2,[3..6]]), 'PASS unique in set';
+ ok UniqueInt2->check([3,[100..110]]), 'PASS unique in set';
}
More information about the Moose-commits
mailing list