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