6 use Test::More tests => 17;
12 use_ok('Moose::Util::TypeConstraints');
15 type Num => where { Scalar::Util::looks_like_number($_) };
16 type String => where { !ref($_) && !Num($_) };
22 subtype NaturalLessThanTen
26 Moose::Util::TypeConstraints->export_type_contstraints_as_functions();
28 is(Num(5), 5, '... this is a Num');
29 ok(!defined(Num('Foo')), '... this is not a Num');
31 is(String('Foo'), 'Foo', '... this is a Str');
32 ok(!defined(String(5)), '... this is not a Str');
34 is(Natural(5), 5, '... this is a Natural');
35 is(Natural(-5), undef, '... this is not a Natural');
36 is(Natural('Foo'), undef, '... this is not a Natural');
38 is(NaturalLessThanTen(5), 5, '... this is a NaturalLessThanTen');
39 is(NaturalLessThanTen(12), undef, '... this is not a NaturalLessThanTen');
40 is(NaturalLessThanTen(-5), undef, '... this is not a NaturalLessThanTen');
41 is(NaturalLessThanTen('Foo'), undef, '... this is not a NaturalLessThanTen');
45 my $negative = subtype Num => where { $_ < 0 };
46 ok(defined $negative, '... got a value back from negative');
47 isa_ok($negative, 'Moose::Meta::TypeConstraint');
49 is($negative->check(-5), -5, '... this is a negative number');
50 ok(!defined($negative->check(5)), '... this is not a negative number');
51 is($negative->check('Foo'), undef, '... this is not a negative number');