Commit | Line | Data |
fa92d705 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
a28e50e4 |
6 | use Test::More; |
fa92d705 |
7 | |
28fdde7f |
8 | use Moose::Util::TypeConstraints; |
fa92d705 |
9 | |
10 | ## First, we check that the new regex parsing works |
11 | |
8c412639 |
12 | ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint( |
13 | 'ArrayRef[Str]') => 'detected correctly'; |
fa92d705 |
14 | |
15 | is_deeply |
8c412639 |
16 | [ |
17 | Moose::Util::TypeConstraints::_parse_parameterized_type_constraint( |
18 | 'ArrayRef[Str]') |
19 | ], |
20 | [ "ArrayRef", "Str" ] => 'Correctly parsed ArrayRef[Str]'; |
21 | |
22 | ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint( |
23 | 'ArrayRef[Str ]') => 'detected correctly'; |
fa92d705 |
24 | |
fa92d705 |
25 | is_deeply |
8c412639 |
26 | [ |
27 | Moose::Util::TypeConstraints::_parse_parameterized_type_constraint( |
28 | 'ArrayRef[Str ]') |
29 | ], |
30 | [ "ArrayRef", "Str" ] => 'Correctly parsed ArrayRef[Str ]'; |
31 | |
32 | ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint( |
33 | 'ArrayRef[ Str]') => 'detected correctly'; |
fa92d705 |
34 | |
fa92d705 |
35 | is_deeply |
8c412639 |
36 | [ |
37 | Moose::Util::TypeConstraints::_parse_parameterized_type_constraint( |
38 | 'ArrayRef[ Str]') |
39 | ], |
40 | [ "ArrayRef", "Str" ] => 'Correctly parsed ArrayRef[ Str]'; |
41 | |
42 | ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint( |
43 | 'ArrayRef[ Str ]') => 'detected correctly'; |
fa92d705 |
44 | |
fa92d705 |
45 | is_deeply |
8c412639 |
46 | [ |
47 | Moose::Util::TypeConstraints::_parse_parameterized_type_constraint( |
48 | 'ArrayRef[ Str ]') |
49 | ], |
50 | [ "ArrayRef", "Str" ] => 'Correctly parsed ArrayRef[ Str ]'; |
51 | |
52 | ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint( |
53 | 'ArrayRef[ HashRef[Int] ]') => 'detected correctly'; |
fa92d705 |
54 | |
fa92d705 |
55 | is_deeply |
8c412639 |
56 | [ |
57 | Moose::Util::TypeConstraints::_parse_parameterized_type_constraint( |
58 | 'ArrayRef[ HashRef[Int] ]') |
59 | ], |
60 | [ "ArrayRef", "HashRef[Int]" ] => |
61 | 'Correctly parsed ArrayRef[ HashRef[Int] ]'; |
62 | |
63 | ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint( |
64 | 'ArrayRef[ HashRef[Int ] ]') => 'detected correctly'; |
fa92d705 |
65 | |
fa92d705 |
66 | is_deeply |
8c412639 |
67 | [ |
68 | Moose::Util::TypeConstraints::_parse_parameterized_type_constraint( |
69 | 'ArrayRef[ HashRef[Int ] ]') |
70 | ], |
71 | [ "ArrayRef", "HashRef[Int ]" ] => |
72 | 'Correctly parsed ArrayRef[ HashRef[Int ] ]'; |
73 | |
74 | ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint( |
75 | 'ArrayRef[Int|Str]') => 'detected correctly'; |
fa92d705 |
76 | |
fa92d705 |
77 | is_deeply |
8c412639 |
78 | [ |
79 | Moose::Util::TypeConstraints::_parse_parameterized_type_constraint( |
80 | 'ArrayRef[Int|Str]') |
81 | ], |
82 | [ "ArrayRef", "Int|Str" ] => 'Correctly parsed ArrayRef[Int|Str]'; |
83 | |
84 | ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint( |
85 | 'ArrayRef[ArrayRef[Int]|Str]') => 'detected correctly'; |
86 | |
fa92d705 |
87 | is_deeply |
8c412639 |
88 | [ |
89 | Moose::Util::TypeConstraints::_parse_parameterized_type_constraint( |
90 | 'ArrayRef[ArrayRef[Int]|Str]') |
91 | ], |
92 | [ "ArrayRef", "ArrayRef[Int]|Str" ] => |
93 | 'Correctly parsed ArrayRef[ArrayRef[Int]|Str]'; |
94 | |
fa92d705 |
95 | ## creating names via subtype |
96 | |
8c412639 |
97 | ok my $r = Moose::Util::TypeConstraints->get_type_constraint_registry => |
98 | 'Got registry object'; |
fa92d705 |
99 | |
8c412639 |
100 | ok my $subtype_a1 |
101 | = subtype( 'subtype_a1' => as 'HashRef[Int]' ), => 'created subtype_a1'; |
fa92d705 |
102 | |
8c412639 |
103 | ok my $subtype_a2 |
104 | = subtype( 'subtype_a2' => as 'HashRef[ Int]' ), => 'created subtype_a2'; |
fa92d705 |
105 | |
8c412639 |
106 | ok my $subtype_a3 |
107 | = subtype( 'subtype_a2' => as 'HashRef[Int ]' ), => 'created subtype_a2'; |
fa92d705 |
108 | |
8c412639 |
109 | ok my $subtype_a4 = subtype( 'subtype_a2' => as 'HashRef[ Int ]' ), => |
110 | 'created subtype_a2'; |
fa92d705 |
111 | |
8c412639 |
112 | is $subtype_a1->parent->name, $subtype_a2->parent->name => 'names match'; |
fa92d705 |
113 | |
8c412639 |
114 | is $subtype_a1->parent->name, $subtype_a3->parent->name => 'names match'; |
fa92d705 |
115 | |
8c412639 |
116 | is $subtype_a1->parent->name, $subtype_a4->parent->name => 'names match'; |
fa92d705 |
117 | |
8c412639 |
118 | ok my $subtype_b1 = subtype( 'subtype_b1' => as 'HashRef[Int|Str]' ), => |
119 | 'created subtype_b1'; |
fa92d705 |
120 | |
8c412639 |
121 | ok my $subtype_b2 = subtype( 'subtype_b2' => as 'HashRef[Int | Str]' ), => |
122 | 'created subtype_b2'; |
123 | |
25518076 |
124 | ok my $subtype_b3 = subtype( 'subtype_b3' => as 'HashRef[Str|Int]' ), => |
8c412639 |
125 | 'created subtype_b3'; |
126 | |
127 | is $subtype_b1->parent->name, $subtype_b2->parent->name => 'names match'; |
128 | |
129 | is $subtype_b1->parent->name, $subtype_b3->parent->name => 'names match'; |
130 | |
131 | is $subtype_b2->parent->name, $subtype_b3->parent->name => 'names match'; |
fa92d705 |
132 | |
133 | ## testing via add_constraint |
134 | |
135 | ok my $union1 = Moose::Util::TypeConstraints::create_type_constraint_union( |
8c412639 |
136 | 'ArrayRef[Int|Str] | ArrayRef[Int | HashRef]') => 'Created Union1'; |
fa92d705 |
137 | |
138 | ok my $union2 = Moose::Util::TypeConstraints::create_type_constraint_union( |
8c412639 |
139 | 'ArrayRef[ Int|Str] | ArrayRef[Int | HashRef]') => 'Created Union2'; |
140 | |
fa92d705 |
141 | ok my $union3 = Moose::Util::TypeConstraints::create_type_constraint_union( |
8c412639 |
142 | 'ArrayRef[Int |Str ] | ArrayRef[Int | HashRef ]') => 'Created Union3'; |
143 | |
144 | is $union1->name, $union2->name, 'names match'; |
145 | |
146 | is $union1->name, $union3->name, 'names match'; |
147 | |
148 | is $union2->name, $union3->name, 'names match'; |
a28e50e4 |
149 | |
150 | done_testing; |