Commit | Line | Data |
5a592ad7 |
1 | #!/usr/bin/perl |
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; |
5 | |
6 | use strict; |
7 | use warnings; |
8 | |
9 | use Test::More; |
10 | use Test::Exception; |
11 | |
12 | BEGIN { |
13 | use_ok('Mouse::Util::TypeConstraints'); |
14 | use_ok('Mouse::Meta::TypeConstraint'); |
15 | } |
16 | |
17 | # Array of Ints |
18 | |
19 | my $array_of_ints = Mouse::Meta::TypeConstraint->new( |
20 | name => 'ArrayRef[Int]', |
21 | parent => find_type_constraint('ArrayRef'), |
22 | type_parameter => find_type_constraint('Int'), |
23 | ); |
24 | isa_ok($array_of_ints, 'Mouse::Meta::TypeConstraint'); |
25 | isa_ok($array_of_ints, 'Mouse::Meta::TypeConstraint'); |
26 | |
27 | ok($array_of_ints->check([ 1, 2, 3, 4 ]), '... [ 1, 2, 3, 4 ] passed successfully'); |
28 | ok(!$array_of_ints->check([qw/foo bar baz/]), '... [qw/foo bar baz/] failed successfully'); |
29 | ok(!$array_of_ints->check([ 1, 2, 3, qw/foo bar/]), '... [ 1, 2, 3, qw/foo bar/] failed successfully'); |
30 | |
31 | ok(!$array_of_ints->check(1), '... 1 failed successfully'); |
32 | ok(!$array_of_ints->check({}), '... {} failed successfully'); |
33 | ok(!$array_of_ints->check(sub { () }), '... sub { () } failed successfully'); |
34 | |
35 | # Hash of Ints |
36 | |
37 | my $hash_of_ints = Mouse::Meta::TypeConstraint->new( |
38 | name => 'HashRef[Int]', |
39 | parent => find_type_constraint('HashRef'), |
40 | type_parameter => find_type_constraint('Int'), |
41 | ); |
42 | isa_ok($hash_of_ints, 'Mouse::Meta::TypeConstraint'); |
43 | isa_ok($hash_of_ints, 'Mouse::Meta::TypeConstraint'); |
44 | |
45 | ok($hash_of_ints->check({ one => 1, two => 2, three => 3 }), '... { one => 1, two => 2, three => 3 } passed successfully'); |
46 | ok(!$hash_of_ints->check({ 1 => 'one', 2 => 'two', 3 => 'three' }), '... { 1 => one, 2 => two, 3 => three } failed successfully'); |
47 | ok(!$hash_of_ints->check({ 1 => 'one', 2 => 'two', three => 3 }), '... { 1 => one, 2 => two, three => 3 } failed successfully'); |
48 | |
49 | ok(!$hash_of_ints->check(1), '... 1 failed successfully'); |
50 | ok(!$hash_of_ints->check([]), '... [] failed successfully'); |
51 | ok(!$hash_of_ints->check(sub { () }), '... sub { () } failed successfully'); |
52 | |
53 | # Array of Array of Ints |
54 | |
55 | my $array_of_array_of_ints = Mouse::Meta::TypeConstraint->new( |
56 | name => 'ArrayRef[ArrayRef[Int]]', |
57 | parent => find_type_constraint('ArrayRef'), |
58 | type_parameter => $array_of_ints, |
59 | ); |
60 | isa_ok($array_of_array_of_ints, 'Mouse::Meta::TypeConstraint'); |
61 | isa_ok($array_of_array_of_ints, 'Mouse::Meta::TypeConstraint'); |
62 | |
63 | ok($array_of_array_of_ints->check( |
64 | [[ 1, 2, 3 ], [ 4, 5, 6 ]] |
65 | ), '... [[ 1, 2, 3 ], [ 4, 5, 6 ]] passed successfully'); |
66 | ok(!$array_of_array_of_ints->check( |
67 | [[ 1, 2, 3 ], [ qw/foo bar/ ]] |
68 | ), '... [[ 1, 2, 3 ], [ qw/foo bar/ ]] failed successfully'); |
69 | |
70 | { |
71 | my $anon_type = Mouse::Util::TypeConstraints::find_or_parse_type_constraint('ArrayRef[Foo]'); |
72 | isa_ok( $anon_type, 'Mouse::Meta::TypeConstraint' ); |
73 | |
74 | my $param_type = $anon_type->type_parameter; |
75 | isa_ok( $param_type, 'Mouse::Meta::TypeConstraint' ); |
76 | } |
77 | |
78 | done_testing; |