6 use Test::More tests => 37;
10 use_ok('Moose::Util::TypeConstraints');
13 ## First, we check that the new regex parsing works
15 ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint(
16 'ArrayRef[Str]') => 'detected correctly';
20 Moose::Util::TypeConstraints::_parse_parameterized_type_constraint(
23 [ "ArrayRef", "Str" ] => 'Correctly parsed ArrayRef[Str]';
25 ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint(
26 'ArrayRef[Str ]') => 'detected correctly';
30 Moose::Util::TypeConstraints::_parse_parameterized_type_constraint(
33 [ "ArrayRef", "Str" ] => 'Correctly parsed ArrayRef[Str ]';
35 ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint(
36 'ArrayRef[ Str]') => 'detected correctly';
40 Moose::Util::TypeConstraints::_parse_parameterized_type_constraint(
43 [ "ArrayRef", "Str" ] => 'Correctly parsed ArrayRef[ Str]';
45 ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint(
46 'ArrayRef[ Str ]') => 'detected correctly';
50 Moose::Util::TypeConstraints::_parse_parameterized_type_constraint(
53 [ "ArrayRef", "Str" ] => 'Correctly parsed ArrayRef[ Str ]';
55 ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint(
56 'ArrayRef[ HashRef[Int] ]') => 'detected correctly';
60 Moose::Util::TypeConstraints::_parse_parameterized_type_constraint(
61 'ArrayRef[ HashRef[Int] ]')
63 [ "ArrayRef", "HashRef[Int]" ] =>
64 'Correctly parsed ArrayRef[ HashRef[Int] ]';
66 ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint(
67 'ArrayRef[ HashRef[Int ] ]') => 'detected correctly';
71 Moose::Util::TypeConstraints::_parse_parameterized_type_constraint(
72 'ArrayRef[ HashRef[Int ] ]')
74 [ "ArrayRef", "HashRef[Int ]" ] =>
75 'Correctly parsed ArrayRef[ HashRef[Int ] ]';
77 ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint(
78 'ArrayRef[Int|Str]') => 'detected correctly';
82 Moose::Util::TypeConstraints::_parse_parameterized_type_constraint(
85 [ "ArrayRef", "Int|Str" ] => 'Correctly parsed ArrayRef[Int|Str]';
87 ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint(
88 'ArrayRef[ArrayRef[Int]|Str]') => 'detected correctly';
92 Moose::Util::TypeConstraints::_parse_parameterized_type_constraint(
93 'ArrayRef[ArrayRef[Int]|Str]')
95 [ "ArrayRef", "ArrayRef[Int]|Str" ] =>
96 'Correctly parsed ArrayRef[ArrayRef[Int]|Str]';
98 ## creating names via subtype
100 ok my $r = Moose::Util::TypeConstraints->get_type_constraint_registry =>
101 'Got registry object';
104 = subtype( 'subtype_a1' => as 'HashRef[Int]' ), => 'created subtype_a1';
107 = subtype( 'subtype_a2' => as 'HashRef[ Int]' ), => 'created subtype_a2';
110 = subtype( 'subtype_a2' => as 'HashRef[Int ]' ), => 'created subtype_a2';
112 ok my $subtype_a4 = subtype( 'subtype_a2' => as 'HashRef[ Int ]' ), =>
113 'created subtype_a2';
115 is $subtype_a1->parent->name, $subtype_a2->parent->name => 'names match';
117 is $subtype_a1->parent->name, $subtype_a3->parent->name => 'names match';
119 is $subtype_a1->parent->name, $subtype_a4->parent->name => 'names match';
121 ok my $subtype_b1 = subtype( 'subtype_b1' => as 'HashRef[Int|Str]' ), =>
122 'created subtype_b1';
124 ok my $subtype_b2 = subtype( 'subtype_b2' => as 'HashRef[Int | Str]' ), =>
125 'created subtype_b2';
127 ok my $subtype_b3 = subtype( 'subtype_b2' => as 'HashRef[Str|Int]' ), =>
128 'created subtype_b3';
130 is $subtype_b1->parent->name, $subtype_b2->parent->name => 'names match';
132 is $subtype_b1->parent->name, $subtype_b3->parent->name => 'names match';
134 is $subtype_b2->parent->name, $subtype_b3->parent->name => 'names match';
136 ## testing via add_constraint
138 ok my $union1 = Moose::Util::TypeConstraints::create_type_constraint_union(
139 'ArrayRef[Int|Str] | ArrayRef[Int | HashRef]') => 'Created Union1';
141 ok my $union2 = Moose::Util::TypeConstraints::create_type_constraint_union(
142 'ArrayRef[ Int|Str] | ArrayRef[Int | HashRef]') => 'Created Union2';
144 ok my $union3 = Moose::Util::TypeConstraints::create_type_constraint_union(
145 'ArrayRef[Int |Str ] | ArrayRef[Int | HashRef ]') => 'Created Union3';
147 is $union1->name, $union2->name, 'names match';
149 is $union1->name, $union3->name, 'names match';
151 is $union2->name, $union3->name, 'names match';