Regenerate test files
[gitmo/Mouse.git] / t-failing / 040_type_constraints / 012_container_type_coercion.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
18my $r = Mouse::Util::TypeConstraints->get_type_constraint_registry;
19
20# Array of Ints
21
fde8e43f 22my $array_of_ints = Mouse::Meta::TypeConstraint->new(
b2b106d7 23 name => 'ArrayRef[Int]',
24 parent => find_type_constraint('ArrayRef'),
25 type_parameter => find_type_constraint('Int'),
26);
fde8e43f 27isa_ok($array_of_ints, 'Mouse::Meta::TypeConstraint');
b2b106d7 28isa_ok($array_of_ints, 'Mouse::Meta::TypeConstraint');
29
30$r->add_type_constraint($array_of_ints);
31
32is(find_type_constraint('ArrayRef[Int]'), $array_of_ints, '... found the type we just added');
33
34# Hash of Ints
35
fde8e43f 36my $hash_of_ints = Mouse::Meta::TypeConstraint->new(
b2b106d7 37 name => 'HashRef[Int]',
38 parent => find_type_constraint('HashRef'),
39 type_parameter => find_type_constraint('Int'),
40);
fde8e43f 41isa_ok($hash_of_ints, 'Mouse::Meta::TypeConstraint');
b2b106d7 42isa_ok($hash_of_ints, 'Mouse::Meta::TypeConstraint');
43
44$r->add_type_constraint($hash_of_ints);
45
46is(find_type_constraint('HashRef[Int]'), $hash_of_ints, '... found the type we just added');
47
48## now attempt a coercion
49
50{
51 package Foo;
52 use Mouse;
53 use Mouse::Util::TypeConstraints;
54
55 coerce 'ArrayRef[Int]'
56 => from 'HashRef[Int]'
57 => via { [ values %$_ ] };
58
59 has 'bar' => (
60 is => 'ro',
61 isa => 'ArrayRef[Int]',
62 coerce => 1,
63 );
64
65}
66
67my $foo = Foo->new(bar => { one => 1, two => 2, three => 3 });
68isa_ok($foo, 'Foo');
69
70is_deeply([ sort @{$foo->bar} ], [ 1, 2, 3 ], '... our coercion worked!');
71
fde8e43f 72done_testing;