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;
10 $TODO = q{Mouse is not yet completed};
14 use_ok('Mouse::Util::TypeConstraints');
15 use_ok('Mouse::Meta::TypeConstraint');
20 my $array_of_ints = Mouse::Meta::TypeConstraint->new(
21 name => 'ArrayRef[Int]',
22 parent => find_type_constraint('ArrayRef'),
23 type_parameter => find_type_constraint('Int'),
25 isa_ok($array_of_ints, 'Mouse::Meta::TypeConstraint');
26 isa_ok($array_of_ints, 'Mouse::Meta::TypeConstraint');
28 ok($array_of_ints->check([ 1, 2, 3, 4 ]), '... [ 1, 2, 3, 4 ] passed successfully');
29 ok(!$array_of_ints->check([qw/foo bar baz/]), '... [qw/foo bar baz/] failed successfully');
30 ok(!$array_of_ints->check([ 1, 2, 3, qw/foo bar/]), '... [ 1, 2, 3, qw/foo bar/] failed successfully');
32 ok(!$array_of_ints->check(1), '... 1 failed successfully');
33 ok(!$array_of_ints->check({}), '... {} failed successfully');
34 ok(!$array_of_ints->check(sub { () }), '... sub { () } failed successfully');
38 my $hash_of_ints = Mouse::Meta::TypeConstraint->new(
39 name => 'HashRef[Int]',
40 parent => find_type_constraint('HashRef'),
41 type_parameter => find_type_constraint('Int'),
43 isa_ok($hash_of_ints, 'Mouse::Meta::TypeConstraint');
44 isa_ok($hash_of_ints, 'Mouse::Meta::TypeConstraint');
46 ok($hash_of_ints->check({ one => 1, two => 2, three => 3 }), '... { one => 1, two => 2, three => 3 } passed successfully');
47 ok(!$hash_of_ints->check({ 1 => 'one', 2 => 'two', 3 => 'three' }), '... { 1 => one, 2 => two, 3 => three } failed successfully');
48 ok(!$hash_of_ints->check({ 1 => 'one', 2 => 'two', three => 3 }), '... { 1 => one, 2 => two, three => 3 } failed successfully');
50 ok(!$hash_of_ints->check(1), '... 1 failed successfully');
51 ok(!$hash_of_ints->check([]), '... [] failed successfully');
52 ok(!$hash_of_ints->check(sub { () }), '... sub { () } failed successfully');
54 # Array of Array of Ints
56 my $array_of_array_of_ints = Mouse::Meta::TypeConstraint->new(
57 name => 'ArrayRef[ArrayRef[Int]]',
58 parent => find_type_constraint('ArrayRef'),
59 type_parameter => $array_of_ints,
61 isa_ok($array_of_array_of_ints, 'Mouse::Meta::TypeConstraint');
62 isa_ok($array_of_array_of_ints, 'Mouse::Meta::TypeConstraint');
64 ok($array_of_array_of_ints->check(
65 [[ 1, 2, 3 ], [ 4, 5, 6 ]]
66 ), '... [[ 1, 2, 3 ], [ 4, 5, 6 ]] passed successfully');
67 ok(!$array_of_array_of_ints->check(
68 [[ 1, 2, 3 ], [ qw/foo bar/ ]]
69 ), '... [[ 1, 2, 3 ], [ qw/foo bar/ ]] failed successfully');
72 my $anon_type = Mouse::Util::TypeConstraints::find_or_parse_type_constraint('ArrayRef[Foo]');
73 isa_ok( $anon_type, 'Mouse::Meta::TypeConstraint' );
75 my $param_type = $anon_type->type_parameter;
76 isa_ok( $param_type, 'Mouse::Meta::TypeConstraint' );