File: check.t

package info (click to toggle)
libparams-classify-perl 0.015-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 188 kB
  • sloc: perl: 195; makefile: 3
file content (180 lines) | stat: -r--r--r-- 5,942 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
use warnings;
use strict;

use Test::More tests => 1 + 2*28*21;

BEGIN {
	use_ok "Params::Classify", map { ("is_$_", "check_$_") } qw(
		undef string number glob regexp
		ref blessed strictly_blessed able
	);
}

format foo =
.

my $foo = "";

@B::ISA = qw(A);

sub A::flange { }

foreach(
	undef,
	"",
	"abc",
	123,
	0,
	"0 but true",
	"1ab",
	*STDOUT,
	${qr/xyz/},
	\"",
	\\"",
	\pos($foo),
	[],
	{},
	\&is,
	do {
		my $format = *foo{FORMAT};
		defined($format) ? $format : undef;
	},
	bless({}, "main"),
	bless({}, "ARRAY"),
	bless({}, "HASH"),
	bless({}, "A"),
	bless({}, "B"),
) {
	eval { check_undef($_); };
	is $@, is_undef($_) ? "" : "argument is not undefined\n";
	eval { &check_undef($_); };
	is $@, is_undef($_) ? "" : "argument is not undefined\n";
	eval { check_string($_); };
	is $@, is_string($_) ? "" : "argument is not a string\n";
	eval { &check_string($_); };
	is $@, is_string($_) ? "" : "argument is not a string\n";
	eval { check_number($_); };
	is $@, is_number($_) ? "" : "argument is not a number\n";
	eval { &check_number($_); };
	is $@, is_number($_) ? "" : "argument is not a number\n";
	eval { check_glob($_); };
	is $@, is_glob($_) ? "" : "argument is not a typeglob\n";
	eval { &check_glob($_); };
	is $@, is_glob($_) ? "" : "argument is not a typeglob\n";
	eval { check_regexp($_); };
	is $@, is_regexp($_) ? "" : "argument is not a regexp\n";
	eval { &check_regexp($_); };
	is $@, is_regexp($_) ? "" : "argument is not a regexp\n";
	eval { check_ref($_); };
	is $@, is_ref($_) ? "" :
		"argument is not a reference to plain object\n";
	eval { &check_ref($_); };
	is $@, is_ref($_) ? "" :
		"argument is not a reference to plain object\n";
	eval { check_ref($_, "SCALAR"); };
	is $@, is_ref($_, "SCALAR") ? "" :
		"argument is not a reference to plain scalar\n";
	eval { &check_ref($_, "SCALAR"); };
	is $@, is_ref($_, "SCALAR") ? "" :
		"argument is not a reference to plain scalar\n";
	eval { check_ref($_, "ARRAY"); };
	is $@, is_ref($_, "ARRAY") ? "" :
		"argument is not a reference to plain array\n";
	eval { &check_ref($_, "ARRAY"); };
	is $@, is_ref($_, "ARRAY") ? "" :
		"argument is not a reference to plain array\n";
	eval { check_ref($_, "HASH"); };
	is $@, is_ref($_, "HASH") ? "" :
		"argument is not a reference to plain hash\n";
	eval { &check_ref($_, "HASH"); };
	is $@, is_ref($_, "HASH") ? "" :
		"argument is not a reference to plain hash\n";
	eval { check_ref($_, "CODE"); };
	is $@, is_ref($_, "CODE") ? "" :
		"argument is not a reference to plain code\n";
	eval { &check_ref($_, "CODE"); };
	is $@, is_ref($_, "CODE") ? "" :
		"argument is not a reference to plain code\n";
	eval { check_ref($_, "FORMAT"); };
	is $@, is_ref($_, "FORMAT") ? "" :
		"argument is not a reference to plain format\n";
	eval { &check_ref($_, "FORMAT"); };
	is $@, is_ref($_, "FORMAT") ? "" :
		"argument is not a reference to plain format\n";
	eval { check_ref($_, "IO"); };
	is $@, is_ref($_, "IO") ? "" :
		"argument is not a reference to plain io\n";
	eval { &check_ref($_, "IO"); };
	is $@, is_ref($_, "IO") ? "" :
		"argument is not a reference to plain io\n";
	foreach my $type (qw(SCALAR ARRAY HASH CODE FORMAT IO)) {
		eval { check_ref($_, $type); };
		is $@, is_ref($_, $type) ? "" :
			"argument is not a reference to plain @{[lc($type)]}\n";
		eval { &check_ref($_, $type); };
		is $@, is_ref($_, $type) ? "" :
			"argument is not a reference to plain @{[lc($type)]}\n";
	}
	eval { check_blessed($_); };
	is $@, is_blessed($_) ? "" :
		"argument is not a reference to blessed object\n";
	eval { &check_blessed($_); };
	is $@, is_blessed($_) ? "" :
		"argument is not a reference to blessed object\n";
	eval { check_blessed($_, "A"); };
	is $@, is_blessed($_, "A") ? "" :
		"argument is not a reference to blessed A\n";
	eval { &check_blessed($_, "A"); };
	is $@, is_blessed($_, "A") ? "" :
		"argument is not a reference to blessed A\n";
	eval { check_blessed($_, "B"); };
	is $@, is_blessed($_, "B") ? "" :
		"argument is not a reference to blessed B\n";
	eval { &check_blessed($_, "B"); };
	is $@, is_blessed($_, "B") ? "" :
		"argument is not a reference to blessed B\n";
	eval { check_strictly_blessed($_); };
	is $@, is_blessed($_) ? "" :
		"argument is not a reference to blessed object\n";
	eval { &check_strictly_blessed($_); };
	is $@, is_blessed($_) ? "" :
		"argument is not a reference to blessed object\n";
	eval { check_strictly_blessed($_, "A"); };
	is $@, is_strictly_blessed($_, "A") ? "" :
		"argument is not a reference to strictly blessed A\n";
	eval { &check_strictly_blessed($_, "A"); };
	is $@, is_strictly_blessed($_, "A") ? "" :
		"argument is not a reference to strictly blessed A\n";
	eval { check_strictly_blessed($_, "B"); };
	is $@, is_strictly_blessed($_, "B") ? "" :
		"argument is not a reference to strictly blessed B\n";
	eval { &check_strictly_blessed($_, "B"); };
	is $@, is_strictly_blessed($_, "B") ? "" :
		"argument is not a reference to strictly blessed B\n";
	eval { check_able($_); };
	is $@, is_able($_) ? "" :
		"argument is not a reference to blessed object\n";
	eval { &check_able($_); };
	is $@, is_able($_) ? "" :
		"argument is not a reference to blessed object\n";
	eval { check_able($_, []); };
	is $@, is_able($_, []) ? "" :
		"argument is not able to perform at all\n";
	eval { &check_able($_, []); };
	is $@, is_able($_, []) ? "" :
		"argument is not able to perform at all\n";
	eval { check_able($_, "flange"); };
	is $@, is_able($_, "flange") ? "" :
		"argument is not able to perform method \"flange\"\n";
	eval { &check_able($_, "flange"); };
	is $@, is_able($_, "flange") ? "" :
		"argument is not able to perform method \"flange\"\n";
	eval { check_able($_, ["flange","can"]); };
	is $@, is_able($_, ["flange","can"]) ? "" :
		"argument is not able to perform method \"flange\"\n";
	eval { &check_able($_, ["flange","can"]); };
	is $@, is_able($_, ["flange","can"]) ? "" :
		"argument is not able to perform method \"flange\"\n";
}

1;