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