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