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;
10 $TODO = q{Mouse is not yet completed};
14 use_ok('Mouse::Util::TypeConstraints');
17 ## First, we check that the new regex parsing works
19 ok Mouse::Util::TypeConstraints::_detect_parameterized_type_constraint(
20 'ArrayRef[Str]') => 'detected correctly';
24 Mouse::Util::TypeConstraints::_parse_parameterized_type_constraint(
27 [ "ArrayRef", "Str" ] => 'Correctly parsed ArrayRef[Str]';
29 ok Mouse::Util::TypeConstraints::_detect_parameterized_type_constraint(
30 'ArrayRef[Str ]') => 'detected correctly';
34 Mouse::Util::TypeConstraints::_parse_parameterized_type_constraint(
37 [ "ArrayRef", "Str" ] => 'Correctly parsed ArrayRef[Str ]';
39 ok Mouse::Util::TypeConstraints::_detect_parameterized_type_constraint(
40 'ArrayRef[ Str]') => 'detected correctly';
44 Mouse::Util::TypeConstraints::_parse_parameterized_type_constraint(
47 [ "ArrayRef", "Str" ] => 'Correctly parsed ArrayRef[ Str]';
49 ok Mouse::Util::TypeConstraints::_detect_parameterized_type_constraint(
50 'ArrayRef[ Str ]') => 'detected correctly';
54 Mouse::Util::TypeConstraints::_parse_parameterized_type_constraint(
57 [ "ArrayRef", "Str" ] => 'Correctly parsed ArrayRef[ Str ]';
59 ok Mouse::Util::TypeConstraints::_detect_parameterized_type_constraint(
60 'ArrayRef[ HashRef[Int] ]') => 'detected correctly';
64 Mouse::Util::TypeConstraints::_parse_parameterized_type_constraint(
65 'ArrayRef[ HashRef[Int] ]')
67 [ "ArrayRef", "HashRef[Int]" ] =>
68 'Correctly parsed ArrayRef[ HashRef[Int] ]';
70 ok Mouse::Util::TypeConstraints::_detect_parameterized_type_constraint(
71 'ArrayRef[ HashRef[Int ] ]') => 'detected correctly';
75 Mouse::Util::TypeConstraints::_parse_parameterized_type_constraint(
76 'ArrayRef[ HashRef[Int ] ]')
78 [ "ArrayRef", "HashRef[Int ]" ] =>
79 'Correctly parsed ArrayRef[ HashRef[Int ] ]';
81 ok Mouse::Util::TypeConstraints::_detect_parameterized_type_constraint(
82 'ArrayRef[Int|Str]') => 'detected correctly';
86 Mouse::Util::TypeConstraints::_parse_parameterized_type_constraint(
89 [ "ArrayRef", "Int|Str" ] => 'Correctly parsed ArrayRef[Int|Str]';
91 ok Mouse::Util::TypeConstraints::_detect_parameterized_type_constraint(
92 'ArrayRef[ArrayRef[Int]|Str]') => 'detected correctly';
96 Mouse::Util::TypeConstraints::_parse_parameterized_type_constraint(
97 'ArrayRef[ArrayRef[Int]|Str]')
99 [ "ArrayRef", "ArrayRef[Int]|Str" ] =>
100 'Correctly parsed ArrayRef[ArrayRef[Int]|Str]';
102 ## creating names via subtype
104 ok my $r = Mouse::Util::TypeConstraints->get_type_constraint_registry =>
105 'Got registry object';
108 = subtype( 'subtype_a1' => as 'HashRef[Int]' ), => 'created subtype_a1';
111 = subtype( 'subtype_a2' => as 'HashRef[ Int]' ), => 'created subtype_a2';
114 = subtype( 'subtype_a2' => as 'HashRef[Int ]' ), => 'created subtype_a2';
116 ok my $subtype_a4 = subtype( 'subtype_a2' => as 'HashRef[ Int ]' ), =>
117 'created subtype_a2';
119 is $subtype_a1->parent->name, $subtype_a2->parent->name => 'names match';
121 is $subtype_a1->parent->name, $subtype_a3->parent->name => 'names match';
123 is $subtype_a1->parent->name, $subtype_a4->parent->name => 'names match';
125 ok my $subtype_b1 = subtype( 'subtype_b1' => as 'HashRef[Int|Str]' ), =>
126 'created subtype_b1';
128 ok my $subtype_b2 = subtype( 'subtype_b2' => as 'HashRef[Int | Str]' ), =>
129 'created subtype_b2';
131 ok my $subtype_b3 = subtype( 'subtype_b3' => as 'HashRef[Str|Int]' ), =>
132 'created subtype_b3';
134 is $subtype_b1->parent->name, $subtype_b2->parent->name => 'names match';
136 is $subtype_b1->parent->name, $subtype_b3->parent->name => 'names match';
138 is $subtype_b2->parent->name, $subtype_b3->parent->name => 'names match';
140 ## testing via add_constraint
142 ok my $union1 = Mouse::Util::TypeConstraints::create_type_constraint_union(
143 'ArrayRef[Int|Str] | ArrayRef[Int | HashRef]') => 'Created Union1';
145 ok my $union2 = Mouse::Util::TypeConstraints::create_type_constraint_union(
146 'ArrayRef[ Int|Str] | ArrayRef[Int | HashRef]') => 'Created Union2';
148 ok my $union3 = Mouse::Util::TypeConstraints::create_type_constraint_union(
149 'ArrayRef[Int |Str ] | ArrayRef[Int | HashRef ]') => 'Created Union3';
151 is $union1->name, $union2->name, 'names match';
153 is $union1->name, $union3->name, 'names match';
155 is $union2->name, $union3->name, 'names match';