8 use Moose::Util::TypeConstraints;
10 ## First, we check that the new regex parsing works
12 ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint(
13 'ArrayRef[Str]') => 'detected correctly';
17 Moose::Util::TypeConstraints::_parse_parameterized_type_constraint(
20 [ "ArrayRef", "Str" ] => 'Correctly parsed ArrayRef[Str]';
22 ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint(
23 'ArrayRef[Str ]') => 'detected correctly';
27 Moose::Util::TypeConstraints::_parse_parameterized_type_constraint(
30 [ "ArrayRef", "Str" ] => 'Correctly parsed ArrayRef[Str ]';
32 ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint(
33 'ArrayRef[ Str]') => 'detected correctly';
37 Moose::Util::TypeConstraints::_parse_parameterized_type_constraint(
40 [ "ArrayRef", "Str" ] => 'Correctly parsed ArrayRef[ Str]';
42 ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint(
43 'ArrayRef[ Str ]') => 'detected correctly';
47 Moose::Util::TypeConstraints::_parse_parameterized_type_constraint(
50 [ "ArrayRef", "Str" ] => 'Correctly parsed ArrayRef[ Str ]';
52 ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint(
53 'ArrayRef[ HashRef[Int] ]') => 'detected correctly';
57 Moose::Util::TypeConstraints::_parse_parameterized_type_constraint(
58 'ArrayRef[ HashRef[Int] ]')
60 [ "ArrayRef", "HashRef[Int]" ] =>
61 'Correctly parsed ArrayRef[ HashRef[Int] ]';
63 ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint(
64 'ArrayRef[ HashRef[Int ] ]') => 'detected correctly';
68 Moose::Util::TypeConstraints::_parse_parameterized_type_constraint(
69 'ArrayRef[ HashRef[Int ] ]')
71 [ "ArrayRef", "HashRef[Int ]" ] =>
72 'Correctly parsed ArrayRef[ HashRef[Int ] ]';
74 ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint(
75 'ArrayRef[Int|Str]') => 'detected correctly';
79 Moose::Util::TypeConstraints::_parse_parameterized_type_constraint(
82 [ "ArrayRef", "Int|Str" ] => 'Correctly parsed ArrayRef[Int|Str]';
84 ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint(
85 'ArrayRef[ArrayRef[Int]|Str]') => 'detected correctly';
89 Moose::Util::TypeConstraints::_parse_parameterized_type_constraint(
90 'ArrayRef[ArrayRef[Int]|Str]')
92 [ "ArrayRef", "ArrayRef[Int]|Str" ] =>
93 'Correctly parsed ArrayRef[ArrayRef[Int]|Str]';
95 ## creating names via subtype
97 ok my $r = Moose::Util::TypeConstraints->get_type_constraint_registry =>
98 'Got registry object';
101 = subtype( 'subtype_a1' => as 'HashRef[Int]' ), => 'created subtype_a1';
104 = subtype( 'subtype_a2' => as 'HashRef[ Int]' ), => 'created subtype_a2';
107 = subtype( 'subtype_a2' => as 'HashRef[Int ]' ), => 'created subtype_a2';
109 ok my $subtype_a4 = subtype( 'subtype_a2' => as 'HashRef[ Int ]' ), =>
110 'created subtype_a2';
112 is $subtype_a1->parent->name, $subtype_a2->parent->name => 'names match';
114 is $subtype_a1->parent->name, $subtype_a3->parent->name => 'names match';
116 is $subtype_a1->parent->name, $subtype_a4->parent->name => 'names match';
118 ok my $subtype_b1 = subtype( 'subtype_b1' => as 'HashRef[Int|Str]' ), =>
119 'created subtype_b1';
121 ok my $subtype_b2 = subtype( 'subtype_b2' => as 'HashRef[Int | Str]' ), =>
122 'created subtype_b2';
124 ok my $subtype_b3 = subtype( 'subtype_b3' => as 'HashRef[Str|Int]' ), =>
125 'created subtype_b3';
127 is $subtype_b1->parent->name, $subtype_b2->parent->name => 'names match';
129 is $subtype_b1->parent->name, $subtype_b3->parent->name => 'names match';
131 is $subtype_b2->parent->name, $subtype_b3->parent->name => 'names match';
133 ## testing via add_constraint
135 ok my $union1 = Moose::Util::TypeConstraints::create_type_constraint_union(
136 'ArrayRef[Int|Str] | ArrayRef[Int | HashRef]') => 'Created Union1';
138 ok my $union2 = Moose::Util::TypeConstraints::create_type_constraint_union(
139 'ArrayRef[ Int|Str] | ArrayRef[Int | HashRef]') => 'Created Union2';
141 ok my $union3 = Moose::Util::TypeConstraints::create_type_constraint_union(
142 'ArrayRef[Int |Str ] | ArrayRef[Int | HashRef ]') => 'Created Union3';
144 is $union1->name, $union2->name, 'names match';
146 is $union1->name, $union3->name, 'names match';
148 is $union2->name, $union3->name, 'names match';