Mouse::Util::does_role() respects $thing->does() method
[gitmo/Mouse.git] / t / 040_type_constraints / 027_parameterize_from.t
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 }
15
16 # testing the parameterize method
17
18 {
19     my $parameterizable = subtype 'parameterizable_hashref', as 'HashRef';
20
21     my $parameterized = subtype 'parameterized_hashref', as 'HashRef[Int]';
22
23     my $int = Mouse::Util::TypeConstraints::find_type_constraint('Int');
24
25     my $from_parameterizable = $parameterizable->parameterize($int);
26
27     isa_ok $parameterizable,
28         'Mouse::Meta::TypeConstraint', =>
29         'Got expected type instance';
30
31     package Test::Mouse::Meta::TypeConstraint;
32     use Mouse;
33
34     has parameterizable      => ( is => 'rw', isa => $parameterizable );
35     has parameterized        => ( is => 'rw', isa => $parameterized );
36     has from_parameterizable => ( is => 'rw', isa => $from_parameterizable );
37 }
38
39 # Create and check a dummy object
40
41 ok my $params = Test::Mouse::Meta::TypeConstraint->new() =>
42     'Create Dummy object for testing';
43
44 isa_ok $params, 'Test::Mouse::Meta::TypeConstraint' =>
45     'isa correct type';
46
47 # test parameterizable
48
49 lives_ok sub {
50     $params->parameterizable( { a => 'Hello', b => 'World' } );
51 } => 'No problem setting parameterizable';
52
53 is_deeply $params->parameterizable,
54     { a => 'Hello', b => 'World' } => 'Got expected values';
55
56 # test parameterized
57
58 lives_ok sub {
59     $params->parameterized( { a => 1, b => 2 } );
60 } => 'No problem setting parameterized';
61
62 is_deeply $params->parameterized, { a => 1, b => 2 } => 'Got expected values';
63
64 throws_ok sub {
65     $params->parameterized( { a => 'Hello', b => 'World' } );
66     }, qr/Attribute \(parameterized\) does not pass the type constraint/ =>
67     'parameterized throws expected error';
68
69 # test from_parameterizable
70
71 lives_ok sub {
72     $params->from_parameterizable( { a => 1, b => 2 } );
73 } => 'No problem setting from_parameterizable';
74
75 is_deeply $params->from_parameterizable,
76     { a => 1, b => 2 } => 'Got expected values';
77
78 throws_ok sub {
79     $params->from_parameterizable( { a => 'Hello', b => 'World' } );
80     },
81     qr/Attribute \(from_parameterizable\) does not pass the type constraint/
82     => 'from_parameterizable throws expected error';
83
84 done_testing;