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