SingleDigit now accepts [-9 .. 9] not [1 .. 9]
Karen Etheridge [Sat, 14 Sep 2013 21:33:49 +0000 (14:33 -0700)]
Changes
lib/MooseX/Types/Common/Numeric.pm
t/02-numeric.t

diff --git a/Changes b/Changes
index 1ae50ca..bd302b9 100644 (file)
--- a/Changes
+++ b/Changes
@@ -2,6 +2,7 @@ Revision history for {{$dist->name}}
 
 {{$NEXT}}
   - converted to Dist::Zilla
+  - SingleDigit now supports zero and negative numbers (RT#86738)
 
 0.001008   2012-06-14 11:29:50 PDT
   - Upper* and Lower* string types now accept non-alphabetic characters (Karen
index 5336fed..30e580b 100644 (file)
@@ -111,13 +111,13 @@ subtype NegativeOrZeroInt,
     );
 
 subtype SingleDigit,
-  as PositiveInt,
-  where { $_ <= 9 },
+  as Int,
+  where { $_ >= -9 and $_ <= 9 },
   message { "Must be a single digit" },
     ( $Moose::VERSION >= 2.0200
         ? inline_as {
             $_[0]->parent()->_inline_check( $_[1] ) . ' && '
-                . qq{ ($_[1] <= 9) };
+                . qq{ ($_[1] >= -9 and $_[1] <= 9) };
         }
         : ()
     );
index 67d1ccb..23bec41 100644 (file)
@@ -12,8 +12,15 @@ use MooseX::Types::Common::Numeric qw(
     SingleDigit
 );
 
-ok(!is_SingleDigit(100), 'SingleDigit');
-ok(is_SingleDigit(1), 'SingleDigit 2');
+ok(!is_SingleDigit(100), 'SingleDigit 100');
+ok(!is_SingleDigit(10), 'SingleDigit 10');
+ok(is_SingleDigit(9), 'SingleDigit 9');
+ok(is_SingleDigit(1), 'SingleDigit 1');
+ok(is_SingleDigit(0), 'SingleDigit 0');
+ok(is_SingleDigit(-1), 'SingleDigit -1');
+ok(is_SingleDigit(-9), 'SingleDigit -9');
+ok(!is_SingleDigit(-10), 'SingleDigit -10');
+
 
 ok(!is_PositiveInt(-100), 'PositiveInt (-100)');
 ok(!is_PositiveInt(0), 'PositiveInt (0)');