6 use Test::More tests => 22;
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(&Num, &Num, '... the type w/out arguments just returns itself');
32 is(Num(), Num(), '... the type w/out arguments just returns itself');
34 is(String('Foo'), 'Foo', '... this is a Str');
35 ok(!defined(String(5)), '... this is not a Str');
37 is(&String, &String, '... the type w/out arguments just returns itself');
39 is(Natural(5), 5, '... this is a Natural');
40 is(Natural(-5), undef, '... this is not a Natural');
41 is(Natural('Foo'), undef, '... this is not a Natural');
43 is(&Natural, &Natural, '... the type w/out arguments just returns itself');
45 is(NaturalLessThanTen(5), 5, '... this is a NaturalLessThanTen');
46 is(NaturalLessThanTen(12), undef, '... this is not a NaturalLessThanTen');
47 is(NaturalLessThanTen(-5), undef, '... this is not a NaturalLessThanTen');
48 is(NaturalLessThanTen('Foo'), undef, '... this is not a NaturalLessThanTen');
50 is(&NaturalLessThanTen, &NaturalLessThanTen,
51 '... the type w/out arguments just returns itself');
55 my $negative = subtype Num => where { $_ < 0 };
56 ok(defined $negative, '... got a value back from negative');
57 is(ref($negative), 'CODE', '... got a type constraint back from negative');
59 is($negative->(-5), -5, '... this is a negative number');
60 ok(!defined($negative->(5)), '... this is not a negative number');
61 is($negative->('Foo'), undef, '... this is not a negative number');