0_04
[gitmo/Moose.git] / t / 052_util_std_type_constraints.t
CommitLineData
a15dff8d 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
02a0fb52 6use Test::More tests => 122;
a15dff8d 7use Test::Exception;
8
9use Scalar::Util ();
10
11BEGIN {
12 use_ok('Moose::Util::TypeConstraints');
13}
14
15my $SCALAR_REF = \(my $var);
16
7c13858b 17Moose::Util::TypeConstraints->export_type_contstraints_as_functions();
182134e8 18
a15dff8d 19ok(defined Any(0), '... Any accepts anything');
20ok(defined Any(100), '... Any accepts anything');
21ok(defined Any(''), '... Any accepts anything');
22ok(defined Any('Foo'), '... Any accepts anything');
23ok(defined Any([]), '... Any accepts anything');
24ok(defined Any({}), '... Any accepts anything');
25ok(defined Any(sub {}), '... Any accepts anything');
26ok(defined Any($SCALAR_REF), '... Any accepts anything');
27ok(defined Any(qr/../), '... Any accepts anything');
28ok(defined Any(bless {}, 'Foo'), '... Any accepts anything');
29
30ok(defined Value(0), '... Value accepts anything which is not a Ref');
31ok(defined Value(100), '... Value accepts anything which is not a Ref');
32ok(defined Value(''), '... Value accepts anything which is not a Ref');
33ok(defined Value('Foo'), '... Value accepts anything which is not a Ref');
34ok(!defined Value([]), '... Value rejects anything which is not a Value');
35ok(!defined Value({}), '... Value rejects anything which is not a Value');
36ok(!defined Value(sub {}), '... Value rejects anything which is not a Value');
37ok(!defined Value($SCALAR_REF), '... Value rejects anything which is not a Value');
38ok(!defined Value(qr/../), '... Value rejects anything which is not a Value');
39ok(!defined Value(bless {}, 'Foo'), '... Value rejects anything which is not a Value');
40
41ok(!defined Ref(0), '... Ref accepts anything which is not a Value');
42ok(!defined Ref(100), '... Ref accepts anything which is not a Value');
43ok(!defined Ref(''), '... Ref accepts anything which is not a Value');
44ok(!defined Ref('Foo'), '... Ref accepts anything which is not a Value');
45ok(defined Ref([]), '... Ref rejects anything which is not a Ref');
46ok(defined Ref({}), '... Ref rejects anything which is not a Ref');
47ok(defined Ref(sub {}), '... Ref rejects anything which is not a Ref');
48ok(defined Ref($SCALAR_REF), '... Ref rejects anything which is not a Ref');
49ok(defined Ref(qr/../), '... Ref rejects anything which is not a Ref');
50ok(defined Ref(bless {}, 'Foo'), '... Ref rejects anything which is not a Ref');
51
52ok(defined Int(0), '... Int accepts anything which is an Int');
53ok(defined Int(100), '... Int accepts anything which is an Int');
54ok(!defined Int(''), '... Int rejects anything which is not a Int');
55ok(!defined Int('Foo'), '... Int rejects anything which is not a Int');
56ok(!defined Int([]), '... Int rejects anything which is not a Int');
57ok(!defined Int({}), '... Int rejects anything which is not a Int');
58ok(!defined Int(sub {}), '... Int rejects anything which is not a Int');
59ok(!defined Int($SCALAR_REF), '... Int rejects anything which is not a Int');
60ok(!defined Int(qr/../), '... Int rejects anything which is not a Int');
61ok(!defined Int(bless {}, 'Foo'), '... Int rejects anything which is not a Int');
62
63ok(!defined Str(0), '... Str rejects anything which is not a Str');
64ok(!defined Str(100), '... Str rejects anything which is not a Str');
65ok(defined Str(''), '... Str accepts anything which is a Str');
66ok(defined Str('Foo'), '... Str accepts anything which is a Str');
67ok(!defined Str([]), '... Str rejects anything which is not a Str');
68ok(!defined Str({}), '... Str rejects anything which is not a Str');
69ok(!defined Str(sub {}), '... Str rejects anything which is not a Str');
70ok(!defined Str($SCALAR_REF), '... Str rejects anything which is not a Str');
71ok(!defined Str(qr/../), '... Str rejects anything which is not a Str');
72ok(!defined Str(bless {}, 'Foo'), '... Str rejects anything which is not a Str');
73
74ok(!defined ScalarRef(0), '... ScalarRef rejects anything which is not a ScalarRef');
75ok(!defined ScalarRef(100), '... ScalarRef rejects anything which is not a ScalarRef');
76ok(!defined ScalarRef(''), '... ScalarRef rejects anything which is not a ScalarRef');
77ok(!defined ScalarRef('Foo'), '... ScalarRef rejects anything which is not a ScalarRef');
78ok(!defined ScalarRef([]), '... ScalarRef rejects anything which is not a ScalarRef');
79ok(!defined ScalarRef({}), '... ScalarRef rejects anything which is not a ScalarRef');
80ok(!defined ScalarRef(sub {}), '... ScalarRef rejects anything which is not a ScalarRef');
81ok(defined ScalarRef($SCALAR_REF), '... ScalarRef accepts anything which is a ScalarRef');
82ok(!defined ScalarRef(qr/../), '... ScalarRef rejects anything which is not a ScalarRef');
83ok(!defined ScalarRef(bless {}, 'Foo'), '... ScalarRef rejects anything which is not a ScalarRef');
84
85ok(!defined ArrayRef(0), '... ArrayRef rejects anything which is not a ArrayRef');
86ok(!defined ArrayRef(100), '... ArrayRef rejects anything which is not a ArrayRef');
87ok(!defined ArrayRef(''), '... ArrayRef rejects anything which is not a ArrayRef');
88ok(!defined ArrayRef('Foo'), '... ArrayRef rejects anything which is not a ArrayRef');
89ok(defined ArrayRef([]), '... ArrayRef accepts anything which is a ArrayRef');
90ok(!defined ArrayRef({}), '... ArrayRef rejects anything which is not a ArrayRef');
91ok(!defined ArrayRef(sub {}), '... ArrayRef rejects anything which is not a ArrayRef');
92ok(!defined ArrayRef($SCALAR_REF), '... ArrayRef rejects anything which is not a ArrayRef');
93ok(!defined ArrayRef(qr/../), '... ArrayRef rejects anything which is not a ArrayRef');
94ok(!defined ArrayRef(bless {}, 'Foo'), '... ArrayRef rejects anything which is not a ArrayRef');
95
96ok(!defined HashRef(0), '... HashRef rejects anything which is not a HashRef');
97ok(!defined HashRef(100), '... HashRef rejects anything which is not a HashRef');
98ok(!defined HashRef(''), '... HashRef rejects anything which is not a HashRef');
99ok(!defined HashRef('Foo'), '... HashRef rejects anything which is not a HashRef');
100ok(!defined HashRef([]), '... HashRef rejects anything which is not a HashRef');
101ok(defined HashRef({}), '... HashRef accepts anything which is a HashRef');
102ok(!defined HashRef(sub {}), '... HashRef rejects anything which is not a HashRef');
103ok(!defined HashRef($SCALAR_REF), '... HashRef rejects anything which is not a HashRef');
104ok(!defined HashRef(qr/../), '... HashRef rejects anything which is not a HashRef');
105ok(!defined HashRef(bless {}, 'Foo'), '... HashRef rejects anything which is not a HashRef');
106
107ok(!defined CodeRef(0), '... CodeRef rejects anything which is not a CodeRef');
108ok(!defined CodeRef(100), '... CodeRef rejects anything which is not a CodeRef');
109ok(!defined CodeRef(''), '... CodeRef rejects anything which is not a CodeRef');
110ok(!defined CodeRef('Foo'), '... CodeRef rejects anything which is not a CodeRef');
111ok(!defined CodeRef([]), '... CodeRef rejects anything which is not a CodeRef');
112ok(!defined CodeRef({}), '... CodeRef rejects anything which is not a CodeRef');
113ok(defined CodeRef(sub {}), '... CodeRef accepts anything which is a CodeRef');
114ok(!defined CodeRef($SCALAR_REF), '... CodeRef rejects anything which is not a CodeRef');
115ok(!defined CodeRef(qr/../), '... CodeRef rejects anything which is not a CodeRef');
116ok(!defined CodeRef(bless {}, 'Foo'), '... CodeRef rejects anything which is not a CodeRef');
117
118ok(!defined RegexpRef(0), '... RegexpRef rejects anything which is not a RegexpRef');
119ok(!defined RegexpRef(100), '... RegexpRef rejects anything which is not a RegexpRef');
120ok(!defined RegexpRef(''), '... RegexpRef rejects anything which is not a RegexpRef');
121ok(!defined RegexpRef('Foo'), '... RegexpRef rejects anything which is not a RegexpRef');
122ok(!defined RegexpRef([]), '... RegexpRef rejects anything which is not a RegexpRef');
123ok(!defined RegexpRef({}), '... RegexpRef rejects anything which is not a RegexpRef');
124ok(!defined RegexpRef(sub {}), '... RegexpRef rejects anything which is not a RegexpRef');
125ok(!defined RegexpRef($SCALAR_REF), '... RegexpRef rejects anything which is not a RegexpRef');
126ok(defined RegexpRef(qr/../), '... RegexpRef accepts anything which is a RegexpRef');
127ok(!defined RegexpRef(bless {}, 'Foo'), '... RegexpRef rejects anything which is not a RegexpRef');
128
129ok(!defined Object(0), '... Object rejects anything which is not blessed');
130ok(!defined Object(100), '... Object rejects anything which is not blessed');
131ok(!defined Object(''), '... Object rejects anything which is not blessed');
132ok(!defined Object('Foo'), '... Object rejects anything which is not blessed');
133ok(!defined Object([]), '... Object rejects anything which is not blessed');
134ok(!defined Object({}), '... Object rejects anything which is not blessed');
135ok(!defined Object(sub {}), '... Object rejects anything which is not blessed');
136ok(!defined Object($SCALAR_REF), '... Object rejects anything which is not blessed');
137ok(!defined Object(qr/../), '... Object rejects anything which is not blessed');
138ok(defined Object(bless {}, 'Foo'), '... Object accepts anything which is blessed');
02a0fb52 139
140{
141 package My::Role;
142 sub does { 'fake' }
143}
144
145ok(!defined Role(0), '... Role rejects anything which is not a Role');
146ok(!defined Role(100), '... Role rejects anything which is not a Role');
147ok(!defined Role(''), '... Role rejects anything which is not a Role');
148ok(!defined Role('Foo'), '... Role rejects anything which is not a Role');
149ok(!defined Role([]), '... Role rejects anything which is not a Role');
150ok(!defined Role({}), '... Role rejects anything which is not a Role');
151ok(!defined Role(sub {}), '... Role rejects anything which is not a Role');
152ok(!defined Role($SCALAR_REF), '... Role rejects anything which is not a Role');
153ok(!defined Role(qr/../), '... Role rejects anything which is not a Role');
154ok(!defined Role(bless {}, 'Foo'), '... Role accepts anything which is not a Role');
155ok(defined Role(bless {}, 'My::Role'), '... Role accepts anything which is not a Role');
156
157