6 use Test::More tests => 111;
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 Value(0), '... Value accepts anything which is not a Ref');
31 ok(defined Value(100), '... Value accepts anything which is not a Ref');
32 ok(defined Value(''), '... Value accepts anything which is not a Ref');
33 ok(defined Value('Foo'), '... Value accepts anything which is not a Ref');
34 ok(!defined Value([]), '... Value rejects anything which is not a Value');
35 ok(!defined Value({}), '... Value rejects anything which is not a Value');
36 ok(!defined Value(sub {}), '... Value rejects anything which is not a Value');
37 ok(!defined Value($SCALAR_REF), '... Value rejects anything which is not a Value');
38 ok(!defined Value(qr/../), '... Value rejects anything which is not a Value');
39 ok(!defined Value(bless {}, 'Foo'), '... Value rejects anything which is not a Value');
41 ok(!defined Ref(0), '... Ref accepts anything which is not a Value');
42 ok(!defined Ref(100), '... Ref accepts anything which is not a Value');
43 ok(!defined Ref(''), '... Ref accepts anything which is not a Value');
44 ok(!defined Ref('Foo'), '... Ref accepts anything which is not a Value');
45 ok(defined Ref([]), '... Ref rejects anything which is not a Ref');
46 ok(defined Ref({}), '... Ref rejects anything which is not a Ref');
47 ok(defined Ref(sub {}), '... Ref rejects anything which is not a Ref');
48 ok(defined Ref($SCALAR_REF), '... Ref rejects anything which is not a Ref');
49 ok(defined Ref(qr/../), '... Ref rejects anything which is not a Ref');
50 ok(defined Ref(bless {}, 'Foo'), '... Ref rejects anything which is not a Ref');
52 ok(defined Int(0), '... Int accepts anything which is an Int');
53 ok(defined Int(100), '... Int accepts anything which is an Int');
54 ok(!defined Int(''), '... Int rejects anything which is not a Int');
55 ok(!defined Int('Foo'), '... Int rejects anything which is not a Int');
56 ok(!defined Int([]), '... Int rejects anything which is not a Int');
57 ok(!defined Int({}), '... Int rejects anything which is not a Int');
58 ok(!defined Int(sub {}), '... Int rejects anything which is not a Int');
59 ok(!defined Int($SCALAR_REF), '... Int rejects anything which is not a Int');
60 ok(!defined Int(qr/../), '... Int rejects anything which is not a Int');
61 ok(!defined Int(bless {}, 'Foo'), '... Int rejects anything which is not a Int');
63 ok(!defined Str(0), '... Str rejects anything which is not a Str');
64 ok(!defined Str(100), '... Str rejects anything which is not a Str');
65 ok(defined Str(''), '... Str accepts anything which is a Str');
66 ok(defined Str('Foo'), '... Str accepts anything which is a Str');
67 ok(!defined Str([]), '... Str rejects anything which is not a Str');
68 ok(!defined Str({}), '... Str rejects anything which is not a Str');
69 ok(!defined Str(sub {}), '... Str rejects anything which is not a Str');
70 ok(!defined Str($SCALAR_REF), '... Str rejects anything which is not a Str');
71 ok(!defined Str(qr/../), '... Str rejects anything which is not a Str');
72 ok(!defined Str(bless {}, 'Foo'), '... Str rejects anything which is not a Str');
74 ok(!defined ScalarRef(0), '... ScalarRef rejects anything which is not a ScalarRef');
75 ok(!defined ScalarRef(100), '... ScalarRef rejects anything which is not a ScalarRef');
76 ok(!defined ScalarRef(''), '... ScalarRef rejects anything which is not a ScalarRef');
77 ok(!defined ScalarRef('Foo'), '... ScalarRef rejects anything which is not a ScalarRef');
78 ok(!defined ScalarRef([]), '... ScalarRef rejects anything which is not a ScalarRef');
79 ok(!defined ScalarRef({}), '... ScalarRef rejects anything which is not a ScalarRef');
80 ok(!defined ScalarRef(sub {}), '... ScalarRef rejects anything which is not a ScalarRef');
81 ok(defined ScalarRef($SCALAR_REF), '... ScalarRef accepts anything which is a ScalarRef');
82 ok(!defined ScalarRef(qr/../), '... ScalarRef rejects anything which is not a ScalarRef');
83 ok(!defined ScalarRef(bless {}, 'Foo'), '... ScalarRef rejects anything which is not a ScalarRef');
85 ok(!defined ArrayRef(0), '... ArrayRef rejects anything which is not a ArrayRef');
86 ok(!defined ArrayRef(100), '... ArrayRef rejects anything which is not a ArrayRef');
87 ok(!defined ArrayRef(''), '... ArrayRef rejects anything which is not a ArrayRef');
88 ok(!defined ArrayRef('Foo'), '... ArrayRef rejects anything which is not a ArrayRef');
89 ok(defined ArrayRef([]), '... ArrayRef accepts anything which is a ArrayRef');
90 ok(!defined ArrayRef({}), '... ArrayRef rejects anything which is not a ArrayRef');
91 ok(!defined ArrayRef(sub {}), '... ArrayRef rejects anything which is not a ArrayRef');
92 ok(!defined ArrayRef($SCALAR_REF), '... ArrayRef rejects anything which is not a ArrayRef');
93 ok(!defined ArrayRef(qr/../), '... ArrayRef rejects anything which is not a ArrayRef');
94 ok(!defined ArrayRef(bless {}, 'Foo'), '... ArrayRef rejects anything which is not a ArrayRef');
96 ok(!defined HashRef(0), '... HashRef rejects anything which is not a HashRef');
97 ok(!defined HashRef(100), '... HashRef rejects anything which is not a HashRef');
98 ok(!defined HashRef(''), '... HashRef rejects anything which is not a HashRef');
99 ok(!defined HashRef('Foo'), '... HashRef rejects anything which is not a HashRef');
100 ok(!defined HashRef([]), '... HashRef rejects anything which is not a HashRef');
101 ok(defined HashRef({}), '... HashRef accepts anything which is a HashRef');
102 ok(!defined HashRef(sub {}), '... HashRef rejects anything which is not a HashRef');
103 ok(!defined HashRef($SCALAR_REF), '... HashRef rejects anything which is not a HashRef');
104 ok(!defined HashRef(qr/../), '... HashRef rejects anything which is not a HashRef');
105 ok(!defined HashRef(bless {}, 'Foo'), '... HashRef rejects anything which is not a HashRef');
107 ok(!defined CodeRef(0), '... CodeRef rejects anything which is not a CodeRef');
108 ok(!defined CodeRef(100), '... CodeRef rejects anything which is not a CodeRef');
109 ok(!defined CodeRef(''), '... CodeRef rejects anything which is not a CodeRef');
110 ok(!defined CodeRef('Foo'), '... CodeRef rejects anything which is not a CodeRef');
111 ok(!defined CodeRef([]), '... CodeRef rejects anything which is not a CodeRef');
112 ok(!defined CodeRef({}), '... CodeRef rejects anything which is not a CodeRef');
113 ok(defined CodeRef(sub {}), '... CodeRef accepts anything which is a CodeRef');
114 ok(!defined CodeRef($SCALAR_REF), '... CodeRef rejects anything which is not a CodeRef');
115 ok(!defined CodeRef(qr/../), '... CodeRef rejects anything which is not a CodeRef');
116 ok(!defined CodeRef(bless {}, 'Foo'), '... CodeRef rejects anything which is not a CodeRef');
118 ok(!defined RegexpRef(0), '... RegexpRef rejects anything which is not a RegexpRef');
119 ok(!defined RegexpRef(100), '... RegexpRef rejects anything which is not a RegexpRef');
120 ok(!defined RegexpRef(''), '... RegexpRef rejects anything which is not a RegexpRef');
121 ok(!defined RegexpRef('Foo'), '... RegexpRef rejects anything which is not a RegexpRef');
122 ok(!defined RegexpRef([]), '... RegexpRef rejects anything which is not a RegexpRef');
123 ok(!defined RegexpRef({}), '... RegexpRef rejects anything which is not a RegexpRef');
124 ok(!defined RegexpRef(sub {}), '... RegexpRef rejects anything which is not a RegexpRef');
125 ok(!defined RegexpRef($SCALAR_REF), '... RegexpRef rejects anything which is not a RegexpRef');
126 ok(defined RegexpRef(qr/../), '... RegexpRef accepts anything which is a RegexpRef');
127 ok(!defined RegexpRef(bless {}, 'Foo'), '... RegexpRef rejects anything which is not a RegexpRef');
129 ok(!defined Object(0), '... Object rejects anything which is not blessed');
130 ok(!defined Object(100), '... Object rejects anything which is not blessed');
131 ok(!defined Object(''), '... Object rejects anything which is not blessed');
132 ok(!defined Object('Foo'), '... Object rejects anything which is not blessed');
133 ok(!defined Object([]), '... Object rejects anything which is not blessed');
134 ok(!defined Object({}), '... Object rejects anything which is not blessed');
135 ok(!defined Object(sub {}), '... Object rejects anything which is not blessed');
136 ok(!defined Object($SCALAR_REF), '... Object rejects anything which is not blessed');
137 ok(!defined Object(qr/../), '... Object rejects anything which is not blessed');
138 ok(defined Object(bless {}, 'Foo'), '... Object accepts anything which is blessed');