1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
#!/usr/bin/perl
use strict;
use warnings;
use Test::More;
use Test::Fatal;
use MooseX::Types::LaxNum;
use Moose::Util::TypeConstraints;
{
my $subtype = subtype( { as => 'LaxNum' } );
isa_ok( $subtype, 'Moose::Meta::TypeConstraint', 'got a subtype' );
my @rejects = (
'hello',
undef
);
my @accepts = (
' 123 ',
"1\n",
"\n1",
'123',
"0 but true",
"Inf",
"Infinity",
"NaN",
'123.4367',
'3322',
'13e7',
'0',
'0.0',
'.0',
'0.',
'0.',
0.0,
123,
13e6,
123.4367,
10.5
);
for( @rejects )
{
my $printable = defined $_ ? $_ : "(undef)";
ok( !$subtype->check($_), "constraint rejects $printable" );
}
ok( $subtype->check($_), "constraint accepts $_" ) for @accepts;
}
done_testing;
|