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