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