Commit | Line | Data |
b2b106d7 |
1 | #!/usr/bin/perl |
c47cf415 |
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 | |
c47cf415 |
9 | use Test::More; |
10 | $TODO = q{Mouse is not yet completed}; |
b2b106d7 |
11 | use Test::Exception; |
12 | |
13 | BEGIN { |
14 | use_ok('Mouse::Util::TypeConstraints'); |
c47cf415 |
15 | use_ok('Mouse::Meta::TypeConstraint'); |
b2b106d7 |
16 | } |
17 | |
18 | my $r = Mouse::Util::TypeConstraints->get_type_constraint_registry; |
19 | |
20 | # Array of Ints |
21 | |
c47cf415 |
22 | my $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 | ); |
c47cf415 |
27 | isa_ok($array_of_ints, 'Mouse::Meta::TypeConstraint'); |
b2b106d7 |
28 | isa_ok($array_of_ints, 'Mouse::Meta::TypeConstraint'); |
29 | |
30 | $r->add_type_constraint($array_of_ints); |
31 | |
32 | is(find_type_constraint('ArrayRef[Int]'), $array_of_ints, '... found the type we just added'); |
33 | |
34 | # Hash of Ints |
35 | |
c47cf415 |
36 | my $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 | ); |
c47cf415 |
41 | isa_ok($hash_of_ints, 'Mouse::Meta::TypeConstraint'); |
b2b106d7 |
42 | isa_ok($hash_of_ints, 'Mouse::Meta::TypeConstraint'); |
43 | |
44 | $r->add_type_constraint($hash_of_ints); |
45 | |
46 | is(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 | |
67 | my $foo = Foo->new(bar => { one => 1, two => 2, three => 3 }); |
68 | isa_ok($foo, 'Foo'); |
69 | |
70 | is_deeply([ sort @{$foo->bar} ], [ 1, 2, 3 ], '... our coercion worked!'); |
71 | |
c47cf415 |
72 | done_testing; |