6 use Test::More tests => 143;
12 use_ok('Moose::Util::TypeConstraints');
15 my $SCALAR_REF = \(my $var);
17 Moose::Util::TypeConstraints->export_type_contstraints_as_functions();
19 ok(defined Any(0), '... Any accepts anything');
20 ok(defined Any(100), '... Any accepts anything');
21 ok(defined Any(''), '... Any accepts anything');
22 ok(defined Any('Foo'), '... Any accepts anything');
23 ok(defined Any([]), '... Any accepts anything');
24 ok(defined Any({}), '... Any accepts anything');
25 ok(defined Any(sub {}), '... Any accepts anything');
26 ok(defined Any($SCALAR_REF), '... Any accepts anything');
27 ok(defined Any(qr/../), '... Any accepts anything');
28 ok(defined Any(bless {}, 'Foo'), '... Any accepts anything');
30 ok(defined Bool(0), '... Bool rejects anything which is not a 1 or 0');
31 ok(defined Bool(1), '... Bool rejects anything which is not a 1 or 0');
32 ok(!defined Bool(100), '... Bool rejects anything which is not a 1 or 0');
33 ok(!defined Bool(''), '... Bool rejects anything which is not a 1 or 0');
34 ok(!defined Bool('Foo'), '... Bool rejects anything which is not a 1 or 0');
35 ok(!defined Bool([]), '... Bool rejects anything which is not a 1 or 0');
36 ok(!defined Bool({}), '... Bool rejects anything which is not a 1 or 0');
37 ok(!defined Bool(sub {}), '... Bool rejects anything which is not a 1 or 0');
38 ok(!defined Bool($SCALAR_REF), '... Bool rejects anything which is not a 1 or 0');
39 ok(!defined Bool(qr/../), '... Bool rejects anything which is not a 1 or 0');
40 ok(!defined Bool(bless {}, 'Foo'), '... Bool rejects anything which is not a 1 or 0');
42 ok(defined Value(0), '... Value accepts anything which is not a Ref');
43 ok(defined Value(100), '... Value accepts anything which is not a Ref');
44 ok(defined Value(''), '... Value accepts anything which is not a Ref');
45 ok(defined Value('Foo'), '... Value accepts anything which is not a Ref');
46 ok(!defined Value([]), '... Value rejects anything which is not a Value');
47 ok(!defined Value({}), '... Value rejects anything which is not a Value');
48 ok(!defined Value(sub {}), '... Value rejects anything which is not a Value');
49 ok(!defined Value($SCALAR_REF), '... Value rejects anything which is not a Value');
50 ok(!defined Value(qr/../), '... Value rejects anything which is not a Value');
51 ok(!defined Value(bless {}, 'Foo'), '... Value rejects anything which is not a Value');
53 ok(!defined Ref(0), '... Ref accepts anything which is not a Value');
54 ok(!defined Ref(100), '... Ref accepts anything which is not a Value');
55 ok(!defined Ref(''), '... Ref accepts anything which is not a Value');
56 ok(!defined Ref('Foo'), '... Ref accepts anything which is not a Value');
57 ok(defined Ref([]), '... Ref rejects anything which is not a Ref');
58 ok(defined Ref({}), '... Ref rejects anything which is not a Ref');
59 ok(defined Ref(sub {}), '... Ref rejects anything which is not a Ref');
60 ok(defined Ref($SCALAR_REF), '... Ref rejects anything which is not a Ref');
61 ok(defined Ref(qr/../), '... Ref rejects anything which is not a Ref');
62 ok(defined Ref(bless {}, 'Foo'), '... Ref rejects anything which is not a Ref');
64 ok(defined Int(0), '... Int accepts anything which is an Int');
65 ok(defined Int(100), '... Int accepts anything which is an Int');
66 ok(!defined Int(''), '... Int rejects anything which is not a Int');
67 ok(!defined Int('Foo'), '... Int rejects anything which is not a Int');
68 ok(!defined Int([]), '... Int rejects anything which is not a Int');
69 ok(!defined Int({}), '... Int rejects anything which is not a Int');
70 ok(!defined Int(sub {}), '... Int rejects anything which is not a Int');
71 ok(!defined Int($SCALAR_REF), '... Int rejects anything which is not a Int');
72 ok(!defined Int(qr/../), '... Int rejects anything which is not a Int');
73 ok(!defined Int(bless {}, 'Foo'), '... Int rejects anything which is not a Int');
75 ok(!defined Str(0), '... Str rejects anything which is not a Str');
76 ok(!defined Str(100), '... Str rejects anything which is not a Str');
77 ok(defined Str(''), '... Str accepts anything which is a Str');
78 ok(defined Str('Foo'), '... Str accepts anything which is a Str');
79 ok(!defined Str([]), '... Str rejects anything which is not a Str');
80 ok(!defined Str({}), '... Str rejects anything which is not a Str');
81 ok(!defined Str(sub {}), '... Str rejects anything which is not a Str');
82 ok(!defined Str($SCALAR_REF), '... Str rejects anything which is not a Str');
83 ok(!defined Str(qr/../), '... Str rejects anything which is not a Str');
84 ok(!defined Str(bless {}, 'Foo'), '... Str rejects anything which is not a Str');
86 ok(!defined ScalarRef(0), '... ScalarRef rejects anything which is not a ScalarRef');
87 ok(!defined ScalarRef(100), '... ScalarRef rejects anything which is not a ScalarRef');
88 ok(!defined ScalarRef(''), '... ScalarRef rejects anything which is not a ScalarRef');
89 ok(!defined ScalarRef('Foo'), '... ScalarRef rejects anything which is not a ScalarRef');
90 ok(!defined ScalarRef([]), '... ScalarRef rejects anything which is not a ScalarRef');
91 ok(!defined ScalarRef({}), '... ScalarRef rejects anything which is not a ScalarRef');
92 ok(!defined ScalarRef(sub {}), '... ScalarRef rejects anything which is not a ScalarRef');
93 ok(defined ScalarRef($SCALAR_REF), '... ScalarRef accepts anything which is a ScalarRef');
94 ok(!defined ScalarRef(qr/../), '... ScalarRef rejects anything which is not a ScalarRef');
95 ok(!defined ScalarRef(bless {}, 'Foo'), '... ScalarRef rejects anything which is not a ScalarRef');
97 ok(!defined CollectionRef(0), '... CollectionRef rejects anything which is not a HASH or ARRAY');
98 ok(!defined CollectionRef(100), '... CollectionRef rejects anything which is not a HASH or ARRAY');
99 ok(!defined CollectionRef(''), '... CollectionRef rejects anything which is not a HASH or ARRAY');
100 ok(!defined CollectionRef('Foo'), '... CollectionRef rejects anything which is not a HASH or ARRAY');
101 ok(defined CollectionRef([]), '... CollectionRef accepts anything which is not a HASH or ARRAY');
102 ok(defined CollectionRef({}), '... CollectionRef rejects anything which is not a HASH or ARRAY');
103 ok(!defined CollectionRef(sub {}), '... CollectionRef rejects anything which is not a HASH or ARRAY');
104 ok(!defined CollectionRef($SCALAR_REF), '... CollectionRef rejects anything which is not a HASH or ARRAY');
105 ok(!defined CollectionRef(qr/../), '... CollectionRef rejects anything which is not a HASH or ARRAY');
106 ok(!defined CollectionRef(bless {}, 'Foo'), '... CollectionRef rejects anything which is not a HASH or ARRAY');
108 ok(!defined ArrayRef(0), '... ArrayRef rejects anything which is not a ArrayRef');
109 ok(!defined ArrayRef(100), '... ArrayRef rejects anything which is not a ArrayRef');
110 ok(!defined ArrayRef(''), '... ArrayRef rejects anything which is not a ArrayRef');
111 ok(!defined ArrayRef('Foo'), '... ArrayRef rejects anything which is not a ArrayRef');
112 ok(defined ArrayRef([]), '... ArrayRef accepts anything which is a ArrayRef');
113 ok(!defined ArrayRef({}), '... ArrayRef rejects anything which is not a ArrayRef');
114 ok(!defined ArrayRef(sub {}), '... ArrayRef rejects anything which is not a ArrayRef');
115 ok(!defined ArrayRef($SCALAR_REF), '... ArrayRef rejects anything which is not a ArrayRef');
116 ok(!defined ArrayRef(qr/../), '... ArrayRef rejects anything which is not a ArrayRef');
117 ok(!defined ArrayRef(bless {}, 'Foo'), '... ArrayRef rejects anything which is not a ArrayRef');
119 ok(!defined HashRef(0), '... HashRef rejects anything which is not a HashRef');
120 ok(!defined HashRef(100), '... HashRef rejects anything which is not a HashRef');
121 ok(!defined HashRef(''), '... HashRef rejects anything which is not a HashRef');
122 ok(!defined HashRef('Foo'), '... HashRef rejects anything which is not a HashRef');
123 ok(!defined HashRef([]), '... HashRef rejects anything which is not a HashRef');
124 ok(defined HashRef({}), '... HashRef accepts anything which is a HashRef');
125 ok(!defined HashRef(sub {}), '... HashRef rejects anything which is not a HashRef');
126 ok(!defined HashRef($SCALAR_REF), '... HashRef rejects anything which is not a HashRef');
127 ok(!defined HashRef(qr/../), '... HashRef rejects anything which is not a HashRef');
128 ok(!defined HashRef(bless {}, 'Foo'), '... HashRef rejects anything which is not a HashRef');
130 ok(!defined CodeRef(0), '... CodeRef rejects anything which is not a CodeRef');
131 ok(!defined CodeRef(100), '... CodeRef rejects anything which is not a CodeRef');
132 ok(!defined CodeRef(''), '... CodeRef rejects anything which is not a CodeRef');
133 ok(!defined CodeRef('Foo'), '... CodeRef rejects anything which is not a CodeRef');
134 ok(!defined CodeRef([]), '... CodeRef rejects anything which is not a CodeRef');
135 ok(!defined CodeRef({}), '... CodeRef rejects anything which is not a CodeRef');
136 ok(defined CodeRef(sub {}), '... CodeRef accepts anything which is a CodeRef');
137 ok(!defined CodeRef($SCALAR_REF), '... CodeRef rejects anything which is not a CodeRef');
138 ok(!defined CodeRef(qr/../), '... CodeRef rejects anything which is not a CodeRef');
139 ok(!defined CodeRef(bless {}, 'Foo'), '... CodeRef rejects anything which is not a CodeRef');
141 ok(!defined RegexpRef(0), '... RegexpRef rejects anything which is not a RegexpRef');
142 ok(!defined RegexpRef(100), '... RegexpRef rejects anything which is not a RegexpRef');
143 ok(!defined RegexpRef(''), '... RegexpRef rejects anything which is not a RegexpRef');
144 ok(!defined RegexpRef('Foo'), '... RegexpRef rejects anything which is not a RegexpRef');
145 ok(!defined RegexpRef([]), '... RegexpRef rejects anything which is not a RegexpRef');
146 ok(!defined RegexpRef({}), '... RegexpRef rejects anything which is not a RegexpRef');
147 ok(!defined RegexpRef(sub {}), '... RegexpRef rejects anything which is not a RegexpRef');
148 ok(!defined RegexpRef($SCALAR_REF), '... RegexpRef rejects anything which is not a RegexpRef');
149 ok(defined RegexpRef(qr/../), '... RegexpRef accepts anything which is a RegexpRef');
150 ok(!defined RegexpRef(bless {}, 'Foo'), '... RegexpRef rejects anything which is not a RegexpRef');
152 ok(!defined Object(0), '... Object rejects anything which is not blessed');
153 ok(!defined Object(100), '... Object rejects anything which is not blessed');
154 ok(!defined Object(''), '... Object rejects anything which is not blessed');
155 ok(!defined Object('Foo'), '... Object rejects anything which is not blessed');
156 ok(!defined Object([]), '... Object rejects anything which is not blessed');
157 ok(!defined Object({}), '... Object rejects anything which is not blessed');
158 ok(!defined Object(sub {}), '... Object rejects anything which is not blessed');
159 ok(!defined Object($SCALAR_REF), '... Object rejects anything which is not blessed');
160 ok(!defined Object(qr/../), '... Object rejects anything which is not blessed');
161 ok(defined Object(bless {}, 'Foo'), '... Object accepts anything which is blessed');
168 ok(!defined Role(0), '... Role rejects anything which is not a Role');
169 ok(!defined Role(100), '... Role rejects anything which is not a Role');
170 ok(!defined Role(''), '... Role rejects anything which is not a Role');
171 ok(!defined Role('Foo'), '... Role rejects anything which is not a Role');
172 ok(!defined Role([]), '... Role rejects anything which is not a Role');
173 ok(!defined Role({}), '... Role rejects anything which is not a Role');
174 ok(!defined Role(sub {}), '... Role rejects anything which is not a Role');
175 ok(!defined Role($SCALAR_REF), '... Role rejects anything which is not a Role');
176 ok(!defined Role(qr/../), '... Role rejects anything which is not a Role');
177 ok(!defined Role(bless {}, 'Foo'), '... Role accepts anything which is not a Role');
178 ok(defined Role(bless {}, 'My::Role'), '... Role accepts anything which is not a Role');