Fix typo in test description
[gitmo/Moose.git] / t / type_constraints / normalize_type_name.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7
8 BEGIN {
9     use_ok('Moose::Util::TypeConstraints');
10 }
11
12 ## First, we check that the new regex parsing works
13
14 ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint(
15     'ArrayRef[Str]') => 'detected correctly';
16
17 is_deeply
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';
26
27 is_deeply
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';
36
37 is_deeply
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';
46
47 is_deeply
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';
56
57 is_deeply
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';
67
68 is_deeply
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';
78
79 is_deeply
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
89 is_deeply
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
97 ## creating names via subtype
98
99 ok my $r = Moose::Util::TypeConstraints->get_type_constraint_registry =>
100     'Got registry object';
101
102 ok my $subtype_a1
103     = subtype( 'subtype_a1' => as 'HashRef[Int]' ), => 'created subtype_a1';
104
105 ok my $subtype_a2
106     = subtype( 'subtype_a2' => as 'HashRef[  Int]' ), => 'created subtype_a2';
107
108 ok my $subtype_a3
109     = subtype( 'subtype_a2' => as 'HashRef[Int  ]' ), => 'created subtype_a2';
110
111 ok my $subtype_a4 = subtype( 'subtype_a2' => as 'HashRef[  Int  ]' ), =>
112     'created subtype_a2';
113
114 is $subtype_a1->parent->name, $subtype_a2->parent->name => 'names match';
115
116 is $subtype_a1->parent->name, $subtype_a3->parent->name => 'names match';
117
118 is $subtype_a1->parent->name, $subtype_a4->parent->name => 'names match';
119
120 ok my $subtype_b1 = subtype( 'subtype_b1' => as 'HashRef[Int|Str]' ), =>
121     'created subtype_b1';
122
123 ok my $subtype_b2 = subtype( 'subtype_b2' => as 'HashRef[Int | Str]' ), =>
124     'created subtype_b2';
125
126 ok my $subtype_b3 = subtype( 'subtype_b3' => as 'HashRef[Str|Int]' ), =>
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';
134
135 ## testing via add_constraint
136
137 ok my $union1 = Moose::Util::TypeConstraints::create_type_constraint_union(
138     'ArrayRef[Int|Str] | ArrayRef[Int | HashRef]') => 'Created Union1';
139
140 ok my $union2 = Moose::Util::TypeConstraints::create_type_constraint_union(
141     'ArrayRef[  Int|Str] | ArrayRef[Int | HashRef]') => 'Created Union2';
142
143 ok my $union3 = Moose::Util::TypeConstraints::create_type_constraint_union(
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';
151
152 done_testing;