Commit | Line | Data |
b2b106d7 |
1 | #!/usr/bin/perl |
5a592ad7 |
2 | # This is automatically generated by author/import-moose-test.pl. |
3 | # DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!! |
4 | use t::lib::MooseCompat; |
b2b106d7 |
5 | |
6 | use strict; |
7 | use warnings; |
8 | |
5a592ad7 |
9 | use Test::More; |
b2b106d7 |
10 | use Test::Exception; |
11 | |
12 | { |
13 | package Animal; |
14 | use Mouse; |
15 | use Mouse::Util::TypeConstraints; |
16 | |
17 | subtype 'Natural' => as 'Int' => where { $_ > 0 } => |
18 | message {"This number ($_) is not a positive integer!"}; |
19 | |
20 | subtype 'NaturalLessThanTen' => as 'Natural' => where { $_ < 10 } => |
21 | message {"This number ($_) is not less than ten!"}; |
22 | |
23 | has leg_count => ( |
24 | is => 'rw', |
25 | isa => 'NaturalLessThanTen', |
26 | lazy => 1, |
27 | default => 0, |
28 | ); |
29 | } |
30 | |
31 | lives_ok { my $goat = Animal->new( leg_count => 4 ) } |
32 | '... no errors thrown, value is good'; |
33 | lives_ok { my $spider = Animal->new( leg_count => 8 ) } |
34 | '... no errors thrown, value is good'; |
35 | |
36 | throws_ok { my $fern = Animal->new( leg_count => 0 ) } |
37 | qr/This number \(0\) is not less than ten!/, |
38 | 'gave custom supertype error message on new'; |
39 | |
40 | throws_ok { my $centipede = Animal->new( leg_count => 30 ) } |
41 | qr/This number \(30\) is not less than ten!/, |
42 | 'gave custom subtype error message on new'; |
43 | |
44 | my $chimera; |
45 | lives_ok { $chimera = Animal->new( leg_count => 4 ) } |
46 | '... no errors thrown, value is good'; |
47 | |
48 | throws_ok { $chimera->leg_count(0) } |
49 | qr/This number \(0\) is not less than ten!/, |
50 | 'gave custom supertype error message on set to 0'; |
51 | |
52 | throws_ok { $chimera->leg_count(16) } |
53 | qr/This number \(16\) is not less than ten!/, |
54 | 'gave custom subtype error message on set to 16'; |
55 | |
56 | my $gimp = eval { Animal->new() }; |
57 | is( $@, '', '... no errors thrown, value is good' ); |
58 | |
59 | throws_ok { $gimp->leg_count } |
60 | qr/This number \(0\) is not less than ten!/, |
61 | 'gave custom supertype error message on lazy set to 0'; |
62 | |
5a592ad7 |
63 | done_testing; |