Permalink
Browse files

Written test cases for Num type constraints (bug 70539)

  • Loading branch information...
1 parent fe5e5e3 commit b901ecb77f2a7733c811589c945eb02c4709d3ae Upasana Shukla committed with upasana-me May 9, 2013
Showing with 32 additions and 0 deletions.
  1. +32 −0 t/type_constraints/util_type_constraints.t
@@ -188,4 +188,36 @@ like( exception {$r->add_type_constraint(bless {}, 'SomeClass')}, qr/not a valid
like( exception { subtype 'Foo' }, qr/cannot consist solely of a name/, 'Cannot call subtype with a single string argument' );
}
+{
+ my $subtype = subtype( { as => 'Num' } );
+ isa_ok( $subtype, 'Moose::Meta::TypeConstraint', 'got a subtype' );
+
+ my @rejects = ( 'nan',
+ 'inf',
+ 'infinity',
+ 'Infinity',
+ 'NaN',
+ 'INF',
+ ' 1234 ',
+ ' 123.44 ',
+ ' 13e7 ',
+ 'hello',
+ "1e3\n",
+ "52563\n",
+ "123.4\n",
+ '0.',
+ );
+ my @accepts = ( '123',
+ '123.4367',
+ '3322',
+ '13e7',
+ '0',
+ '0.0',
+ '.0'
+ );
+
+ ok( !$subtype->check($_), "constraint rejects $_" ) for @rejects;
+ ok( $subtype->check($_), "constraint accepts $_" ) for @accepts;
+}
+
done_testing;

0 comments on commit b901ecb

Please sign in to comment.