9 use_ok('Moose::Util::TypeConstraints');
12 ## First, we check that the new regex parsing works
14 ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint(
15 'ArrayRef[Str]') => 'detected correctly';
19 Moose::Util::TypeConstraints::_parse_parameterized_type_constraint(
22 [ "ArrayRef", "Str" ] => 'Correctly parsed ArrayRef[Str]';
24 ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint(
25 'ArrayRef[Str ]') => 'detected correctly';
29 Moose::Util::TypeConstraints::_parse_parameterized_type_constraint(
32 [ "ArrayRef", "Str" ] => 'Correctly parsed ArrayRef[Str ]';
34 ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint(
35 'ArrayRef[ Str]') => 'detected correctly';
39 Moose::Util::TypeConstraints::_parse_parameterized_type_constraint(
42 [ "ArrayRef", "Str" ] => 'Correctly parsed ArrayRef[ Str]';
44 ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint(
45 'ArrayRef[ Str ]') => 'detected correctly';
49 Moose::Util::TypeConstraints::_parse_parameterized_type_constraint(
52 [ "ArrayRef", "Str" ] => 'Correctly parsed ArrayRef[ Str ]';
54 ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint(
55 'ArrayRef[ HashRef[Int] ]') => 'detected correctly';
59 Moose::Util::TypeConstraints::_parse_parameterized_type_constraint(
60 'ArrayRef[ HashRef[Int] ]')
62 [ "ArrayRef", "HashRef[Int]" ] =>
63 'Correctly parsed ArrayRef[ HashRef[Int] ]';
65 ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint(
66 'ArrayRef[ HashRef[Int ] ]') => 'detected correctly';
70 Moose::Util::TypeConstraints::_parse_parameterized_type_constraint(
71 'ArrayRef[ HashRef[Int ] ]')
73 [ "ArrayRef", "HashRef[Int ]" ] =>
74 'Correctly parsed ArrayRef[ HashRef[Int ] ]';
76 ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint(
77 'ArrayRef[Int|Str]') => 'detected correctly';
81 Moose::Util::TypeConstraints::_parse_parameterized_type_constraint(
84 [ "ArrayRef", "Int|Str" ] => 'Correctly parsed ArrayRef[Int|Str]';
86 ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint(
87 'ArrayRef[ArrayRef[Int]|Str]') => 'detected correctly';
91 Moose::Util::TypeConstraints::_parse_parameterized_type_constraint(
92 'ArrayRef[ArrayRef[Int]|Str]')
94 [ "ArrayRef", "ArrayRef[Int]|Str" ] =>
95 'Correctly parsed ArrayRef[ArrayRef[Int]|Str]';
97 ## creating names via subtype
99 ok my $r = Moose::Util::TypeConstraints->get_type_constraint_registry =>
100 'Got registry object';
103 = subtype( 'subtype_a1' => as 'HashRef[Int]' ), => 'created subtype_a1';
106 = subtype( 'subtype_a2' => as 'HashRef[ Int]' ), => 'created subtype_a2';
109 = subtype( 'subtype_a2' => as 'HashRef[Int ]' ), => 'created subtype_a2';
111 ok my $subtype_a4 = subtype( 'subtype_a2' => as 'HashRef[ Int ]' ), =>
112 'created subtype_a2';
114 is $subtype_a1->parent->name, $subtype_a2->parent->name => 'names match';
116 is $subtype_a1->parent->name, $subtype_a3->parent->name => 'names match';
118 is $subtype_a1->parent->name, $subtype_a4->parent->name => 'names match';
120 ok my $subtype_b1 = subtype( 'subtype_b1' => as 'HashRef[Int|Str]' ), =>
121 'created subtype_b1';
123 ok my $subtype_b2 = subtype( 'subtype_b2' => as 'HashRef[Int | Str]' ), =>
124 'created subtype_b2';
126 ok my $subtype_b3 = subtype( 'subtype_b3' => as 'HashRef[Str|Int]' ), =>
127 'created subtype_b3';
129 is $subtype_b1->parent->name, $subtype_b2->parent->name => 'names match';
131 is $subtype_b1->parent->name, $subtype_b3->parent->name => 'names match';
133 is $subtype_b2->parent->name, $subtype_b3->parent->name => 'names match';
135 ## testing via add_constraint
137 ok my $union1 = Moose::Util::TypeConstraints::create_type_constraint_union(
138 'ArrayRef[Int|Str] | ArrayRef[Int | HashRef]') => 'Created Union1';
140 ok my $union2 = Moose::Util::TypeConstraints::create_type_constraint_union(
141 'ArrayRef[ Int|Str] | ArrayRef[Int | HashRef]') => 'Created Union2';
143 ok my $union3 = Moose::Util::TypeConstraints::create_type_constraint_union(
144 'ArrayRef[Int |Str ] | ArrayRef[Int | HashRef ]') => 'Created Union3';
146 is $union1->name, $union2->name, 'names match';
148 is $union1->name, $union3->name, 'names match';
150 is $union2->name, $union3->name, 'names match';