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('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 ## creating names via subtype
81 ok my $r = Moose::Util::TypeConstraints->get_type_constraint_registry
82 => 'Got registry object';
84 ok my $subtype_a1 = subtype('subtype_a1' => as 'HashRef[Int]'),
85 => 'created subtype_a1';
87 ok my $subtype_a2 = subtype('subtype_a2' => as 'HashRef[ Int]'),
88 => 'created subtype_a2';
90 ok my $subtype_a3 = subtype('subtype_a2' => as 'HashRef[Int ]'),
91 => 'created subtype_a2';
93 ok my $subtype_a4 = subtype('subtype_a2' => as 'HashRef[ Int ]'),
94 => 'created subtype_a2';
96 is $subtype_a1->parent->name, $subtype_a2->parent->name
99 is $subtype_a1->parent->name, $subtype_a3->parent->name
102 is $subtype_a1->parent->name, $subtype_a4->parent->name
105 ok my $subtype_b1 = subtype('subtype_b1' => as 'HashRef[Int|Str]'),
106 => 'created subtype_b1';
108 ok my $subtype_b2 = subtype('subtype_b2' => as 'HashRef[Int | Str]'),
109 => 'created subtype_b2';
111 ok my $subtype_b3 = subtype('subtype_b2' => as 'HashRef[Str|Int]'),
112 => 'created subtype_b3';
114 is $subtype_b1->parent->name, $subtype_b2->parent->name
117 is $subtype_b1->parent->name, $subtype_b3->parent->name
120 is $subtype_b2->parent->name, $subtype_b3->parent->name
123 ## testing via add_constraint
125 ok my $union1 = Moose::Util::TypeConstraints::create_type_constraint_union(
126 'ArrayRef[Int|Str] | ArrayRef[Int | HashRef]') => 'Created Union1';
128 ok my $union2 = Moose::Util::TypeConstraints::create_type_constraint_union(
129 'ArrayRef[ Int|Str] | ArrayRef[Int | HashRef]') => 'Created Union2';
131 ok my $union3 = Moose::Util::TypeConstraints::create_type_constraint_union(
132 'ArrayRef[Int |Str ] | ArrayRef[Int | HashRef ]') => 'Created Union3';
134 is $union1->name, $union2->name,
137 is $union1->name, $union3->name,
140 is $union2->name, $union3->name,