From: Karen Etheridge Date: Sat, 14 Sep 2013 21:33:49 +0000 (-0700) Subject: SingleDigit now accepts [-9 .. 9] not [1 .. 9] X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMooseX-Types-Common.git;a=commitdiff_plain;h=966ead6bcb0ac6386052f2aa64920858afa170f4 SingleDigit now accepts [-9 .. 9] not [1 .. 9] --- diff --git a/Changes b/Changes index 1ae50ca..bd302b9 100644 --- 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 diff --git a/lib/MooseX/Types/Common/Numeric.pm b/lib/MooseX/Types/Common/Numeric.pm index 5336fed..30e580b 100644 --- a/lib/MooseX/Types/Common/Numeric.pm +++ b/lib/MooseX/Types/Common/Numeric.pm @@ -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) }; } : () ); diff --git a/t/02-numeric.t b/t/02-numeric.t index 67d1ccb..23bec41 100644 --- a/t/02-numeric.t +++ b/t/02-numeric.t @@ -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)');