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