6 use Test::More tests => 39;
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('ArrayRef[Str]')
16 => 'detected correctly';
19 [Moose::Util::TypeConstraints::_parse_parameterized_type_constraint('ArrayRef[Str]')],
21 => 'Correctly parsed ArrayRef[Str]';
23 ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint('ArrayRef[Str ]')
24 => 'detected correctly';
27 [Moose::Util::TypeConstraints::_parse_parameterized_type_constraint('ArrayRef[Str ]')],
29 => 'Correctly parsed ArrayRef[Str ]';
31 ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint('ArrayRef[ Str]')
32 => 'detected correctly';
35 [Moose::Util::TypeConstraints::_parse_parameterized_type_constraint('ArrayRef[ Str]')],
37 => 'Correctly parsed ArrayRef[ Str]';
39 ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint('ArrayRef[ Str ]')
40 => 'detected correctly';
43 [Moose::Util::TypeConstraints::_parse_parameterized_type_constraint('ArrayRef[ Str ]')],
45 => 'Correctly parsed ArrayRef[ Str ]';
47 ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint('ArrayRef[ HashRef[Int] ]')
48 => 'detected correctly';
51 [Moose::Util::TypeConstraints::_parse_parameterized_type_constraint('ArrayRef[ HashRef[Int] ]')],
52 ["ArrayRef", "HashRef[Int]"]
53 => 'Correctly parsed ArrayRef[ HashRef[Int] ]';
55 ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint('ArrayRef[ HashRef[Int ] ]')
56 => 'detected correctly';
59 [Moose::Util::TypeConstraints::_parse_parameterized_type_constraint('ArrayRef[ HashRef[Int ] ]')],
60 ["ArrayRef", "HashRef[Int ]"]
61 => 'Correctly parsed ArrayRef[ HashRef[Int ] ]';
63 ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint('ArrayRef[Int,Str]')
64 => 'detected correctly';
67 [Moose::Util::TypeConstraints::_parse_parameterized_type_constraint('ArrayRef[Int,Str]')],
68 ["ArrayRef", "Int", "Str"]
69 => 'Correctly parsed ArrayRef[Int,Str]';
71 ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint('ArrayRef[ArrayRef[Int],Str]')
72 => 'detected correctly';
75 [Moose::Util::TypeConstraints::_parse_parameterized_type_constraint('ArrayRef[ArrayRef[Int],Str]')],
76 ["ArrayRef", "ArrayRef[Int]", "Str"]
77 => 'Correctly parsed ArrayRef[ArrayRef[Int],Str]';
79 ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint('HashRef[key1 => Int, key2=>Int, key3=>ArrayRef[Int]]')
80 => 'detected correctly';
83 [Moose::Util::TypeConstraints::_parse_parameterized_type_constraint('HashRef[key1 => Int, key2=>Int, key3=>ArrayRef[Int]]')],
84 ["HashRef", "key1", "Int", "key2", "Int", "key3", "ArrayRef[Int]"]
85 => 'Correctly parsed HashRef[key1 => Int, key2=>Int, key3=>ArrayRef[Int]]';
87 ## creating names via subtype
89 ok my $r = Moose::Util::TypeConstraints->get_type_constraint_registry
90 => 'Got registry object';
92 ok my $subtype_a1 = subtype('subtype_a1' => as 'HashRef[Int]'),
93 => 'created subtype_a1';
95 ok my $subtype_a2 = subtype('subtype_a2' => as 'HashRef[ Int]'),
96 => 'created subtype_a2';
98 ok my $subtype_a3 = subtype('subtype_a2' => as 'HashRef[Int ]'),
99 => 'created subtype_a2';
101 ok my $subtype_a4 = subtype('subtype_a2' => as 'HashRef[ Int ]'),
102 => 'created subtype_a2';
104 is $subtype_a1->parent->name, $subtype_a2->parent->name
107 is $subtype_a1->parent->name, $subtype_a3->parent->name
110 is $subtype_a1->parent->name, $subtype_a4->parent->name
113 ok my $subtype_b1 = subtype('subtype_b1' => as 'HashRef[Int|Str]'),
114 => 'created subtype_b1';
116 ok my $subtype_b2 = subtype('subtype_b2' => as 'HashRef[Int | Str]'),
117 => 'created subtype_b2';
119 ok my $subtype_b3 = subtype('subtype_b2' => as 'HashRef[Str|Int]'),
120 => 'created subtype_b3';
122 is $subtype_b1->parent->name, $subtype_b2->parent->name
125 is $subtype_b1->parent->name, $subtype_b3->parent->name
128 is $subtype_b2->parent->name, $subtype_b3->parent->name
131 ## testing via add_constraint
133 ok my $union1 = Moose::Util::TypeConstraints::create_type_constraint_union(
134 'ArrayRef[Int|Str] | ArrayRef[Int | HashRef]') => 'Created Union1';
136 ok my $union2 = Moose::Util::TypeConstraints::create_type_constraint_union(
137 'ArrayRef[ Int|Str] | ArrayRef[Int | HashRef]') => 'Created Union2';
139 ok my $union3 = Moose::Util::TypeConstraints::create_type_constraint_union(
140 'ArrayRef[Int |Str ] | ArrayRef[Int | HashRef ]') => 'Created Union3';
142 is $union1->name, $union2->name,
145 is $union1->name, $union3->name,
148 is $union2->name, $union3->name,