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;
13 use_ok('Mouse::Util::TypeConstraints');
16 # testing the parameterize method
19 my $parameterizable = subtype 'parameterizable_hashref', as 'HashRef';
21 my $parameterized = subtype 'parameterized_hashref', as 'HashRef[Int]';
23 my $int = Mouse::Util::TypeConstraints::find_type_constraint('Int');
25 my $from_parameterizable = $parameterizable->parameterize($int);
27 isa_ok $parameterizable,
28 'Mouse::Meta::TypeConstraint', =>
29 'Got expected type instance';
31 package Test::Mouse::Meta::TypeConstraint;
34 has parameterizable => ( is => 'rw', isa => $parameterizable );
35 has parameterized => ( is => 'rw', isa => $parameterized );
36 has from_parameterizable => ( is => 'rw', isa => $from_parameterizable );
39 # Create and check a dummy object
41 ok my $params = Test::Mouse::Meta::TypeConstraint->new() =>
42 'Create Dummy object for testing';
44 isa_ok $params, 'Test::Mouse::Meta::TypeConstraint' =>
47 # test parameterizable
50 $params->parameterizable( { a => 'Hello', b => 'World' } );
51 } => 'No problem setting parameterizable';
53 is_deeply $params->parameterizable,
54 { a => 'Hello', b => 'World' } => 'Got expected values';
59 $params->parameterized( { a => 1, b => 2 } );
60 } => 'No problem setting parameterized';
62 is_deeply $params->parameterized, { a => 1, b => 2 } => 'Got expected values';
65 $params->parameterized( { a => 'Hello', b => 'World' } );
66 }, qr/Attribute \(parameterized\) does not pass the type constraint/ =>
67 'parameterized throws expected error';
69 # test from_parameterizable
72 $params->from_parameterizable( { a => 1, b => 2 } );
73 } => 'No problem setting from_parameterizable';
75 is_deeply $params->from_parameterizable,
76 { a => 1, b => 2 } => 'Got expected values';
79 $params->from_parameterizable( { a => 'Hello', b => 'World' } );
81 qr/Attribute \(from_parameterizable\) does not pass the type constraint/
82 => 'from_parameterizable throws expected error';