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