Regenerate test files
[gitmo/Mouse.git] / t / 040_type_constraints / 011_container_type_constraint.t
CommitLineData
b2b106d7 1#!/usr/bin/perl
fde8e43f 2# This is automatically generated by author/import-moose-test.pl.
3# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4use t::lib::MooseCompat;
b2b106d7 5
6use strict;
7use warnings;
8
fde8e43f 9use Test::More;
10$TODO = q{Mouse is not yet completed};
b2b106d7 11use Test::Exception;
12
13BEGIN {
14 use_ok('Mouse::Util::TypeConstraints');
fde8e43f 15 use_ok('Mouse::Meta::TypeConstraint');
b2b106d7 16}
17
18# Array of Ints
19
fde8e43f 20my $array_of_ints = Mouse::Meta::TypeConstraint->new(
b2b106d7 21 name => 'ArrayRef[Int]',
22 parent => find_type_constraint('ArrayRef'),
23 type_parameter => find_type_constraint('Int'),
24);
fde8e43f 25isa_ok($array_of_ints, 'Mouse::Meta::TypeConstraint');
b2b106d7 26isa_ok($array_of_ints, 'Mouse::Meta::TypeConstraint');
27
28ok($array_of_ints->check([ 1, 2, 3, 4 ]), '... [ 1, 2, 3, 4 ] passed successfully');
29ok(!$array_of_ints->check([qw/foo bar baz/]), '... [qw/foo bar baz/] failed successfully');
30ok(!$array_of_ints->check([ 1, 2, 3, qw/foo bar/]), '... [ 1, 2, 3, qw/foo bar/] failed successfully');
31
32ok(!$array_of_ints->check(1), '... 1 failed successfully');
33ok(!$array_of_ints->check({}), '... {} failed successfully');
34ok(!$array_of_ints->check(sub { () }), '... sub { () } failed successfully');
35
36# Hash of Ints
37
fde8e43f 38my $hash_of_ints = Mouse::Meta::TypeConstraint->new(
b2b106d7 39 name => 'HashRef[Int]',
40 parent => find_type_constraint('HashRef'),
41 type_parameter => find_type_constraint('Int'),
42);
fde8e43f 43isa_ok($hash_of_ints, 'Mouse::Meta::TypeConstraint');
b2b106d7 44isa_ok($hash_of_ints, 'Mouse::Meta::TypeConstraint');
45
46ok($hash_of_ints->check({ one => 1, two => 2, three => 3 }), '... { one => 1, two => 2, three => 3 } passed successfully');
47ok(!$hash_of_ints->check({ 1 => 'one', 2 => 'two', 3 => 'three' }), '... { 1 => one, 2 => two, 3 => three } failed successfully');
48ok(!$hash_of_ints->check({ 1 => 'one', 2 => 'two', three => 3 }), '... { 1 => one, 2 => two, three => 3 } failed successfully');
49
50ok(!$hash_of_ints->check(1), '... 1 failed successfully');
51ok(!$hash_of_ints->check([]), '... [] failed successfully');
52ok(!$hash_of_ints->check(sub { () }), '... sub { () } failed successfully');
53
54# Array of Array of Ints
55
fde8e43f 56my $array_of_array_of_ints = Mouse::Meta::TypeConstraint->new(
b2b106d7 57 name => 'ArrayRef[ArrayRef[Int]]',
58 parent => find_type_constraint('ArrayRef'),
59 type_parameter => $array_of_ints,
60);
fde8e43f 61isa_ok($array_of_array_of_ints, 'Mouse::Meta::TypeConstraint');
b2b106d7 62isa_ok($array_of_array_of_ints, 'Mouse::Meta::TypeConstraint');
63
64ok($array_of_array_of_ints->check(
65 [[ 1, 2, 3 ], [ 4, 5, 6 ]]
66), '... [[ 1, 2, 3 ], [ 4, 5, 6 ]] passed successfully');
67ok(!$array_of_array_of_ints->check(
68 [[ 1, 2, 3 ], [ qw/foo bar/ ]]
69), '... [[ 1, 2, 3 ], [ qw/foo bar/ ]] failed successfully');
70
71{
72 my $anon_type = Mouse::Util::TypeConstraints::find_or_parse_type_constraint('ArrayRef[Foo]');
fde8e43f 73 isa_ok( $anon_type, 'Mouse::Meta::TypeConstraint' );
b2b106d7 74
75 my $param_type = $anon_type->type_parameter;
fde8e43f 76 isa_ok( $param_type, 'Mouse::Meta::TypeConstraint' );
b2b106d7 77}
fde8e43f 78
79done_testing;