Debian Codegraph @

t/05_is.t

raw
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 70;
7 use POSIX::2008;
8
9 my $ascii = join '', map chr, (0 .. 127);
10 my $blank = "\t ";
11 my $cntrl = substr $ascii, 0, 32;
12 my $digit = '0123456789';
13 my $lower = 'abcdefghijklmnopqrstuvwxyz';
14 my $punct = '!"#$%&\'()*+,-./:;<=>?@[\]^_`{|}~)';
15 my $space = join '', map chr, (9 .. 13), 32;
16 my $upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
17 my $xdigit = '0123456789ABCDEFabcdef';
18 my $alpha = "${upper}${lower}";
19 my $alnum = "${alpha}${digit}";
20 my $graph = "${alnum}${punct}";
21 my $print = " ${graph}";
22
23 my $inf_ok = do {
24 use bigrat;
25 sprintf('%f', inf()) =~ /^inf$/i;
26 };
27 my $nan_ok = do {
28 use bigrat;
29 sprintf('%f', NaN()) =~ /^nan$/i;
30 };
31
32 SKIP: {
33 if (!defined &POSIX::2008::isatty) {
34 skip 'isatty() UNAVAILABLE', 1;
35 }
36 ok(!(POSIX::2008::isatty(\*STDOUT) xor -t \*STDOUT), 'isatty(STDOUT)');
37 }
38
39 SKIP: {
40 if (!defined &POSIX::2008::isfinite) {
41 skip 'isfinite() UNAVAILABLE', 4;
42 }
43 else {
44 ok(POSIX::2008::isfinite(0), 'isfinite(0)');
45 if (!$inf_ok || !$nan_ok) {
46 skip 'inf() or NaN() broken', 3;
47 }
48 else {
49 use bigrat;
50 ok(!$nan_ok || !POSIX::2008::isfinite(NaN()), '!isfinite(NaN)');
51 ok(!$inf_ok || !POSIX::2008::isfinite(inf()), '!isfinite(inf)');
52 ok(!$inf_ok || !POSIX::2008::isfinite(-inf()), '!isfinite(-inf)');
53 }
54 }
55 }
56
57 SKIP: {
58 if (!defined &POSIX::2008::isinf) {
59 skip 'isinf() UNAVAILABLE', 4;
60 }
61 else {
62 ok(!POSIX::2008::isinf(0), '!isinf(0)');
63 if (!$inf_ok || !$nan_ok) {
64 skip 'inf() or NaN() broken', 3;
65 }
66 else {
67 use bigrat;
68 ok(!$nan_ok || !POSIX::2008::isinf(NaN()), '!isinf(NaN)');
69 ok(!$inf_ok || POSIX::2008::isinf(inf()), 'isinf(inf)');
70 ok(!$inf_ok || POSIX::2008::isinf(-inf()), 'isinf(-inf)');
71 }
72 }
73 }
74
75 SKIP: {
76 if (!defined &POSIX::2008::isnan) {
77 skip 'isnan() UNAVAILABLE', 4;
78 }
79 else {
80 ok(!POSIX::2008::isnan(0), '!isnan(0)');
81 if (!$inf_ok || !$nan_ok) {
82 skip 'inf() or NaN() broken', 3;
83 }
84 else {
85 use bigrat;
86 ok(!$nan_ok || POSIX::2008::isnan(NaN()), 'isnan(NaN)');
87 ok(!$inf_ok || !POSIX::2008::isnan(inf()), '!isnan(inf)');
88 ok(!$inf_ok || !POSIX::2008::isnan(-inf()), '!isnan(-inf)');
89 }
90 }
91 }
92
93 SKIP: {
94 if (!defined &POSIX::2008::isnormal) {
95 skip 'isnormal() UNAVAILABLE', 5;
96 }
97 else {
98 ok(POSIX::2008::isnormal(1), 'isnormal(1)');
99 ok(!POSIX::2008::isnormal(0), '!isnormal(0)');
100 if (!$inf_ok || !$nan_ok) {
101 skip 'inf() or NaN() broken', 3;
102 }
103 else {
104 use bigrat;
105 ok(!$nan_ok || !POSIX::2008::isnormal(NaN()), '!isnormal(NaN)');
106 ok(!$inf_ok || !POSIX::2008::isnormal(inf()), '!isnormal(inf)');
107 ok(!$inf_ok || !POSIX::2008::isnormal(-inf()), '!isnormal(-inf)');
108 }
109 }
110 }
111
112 SKIP: {
113 if (!defined &POSIX::2008::isalnum) {
114 skip 'isalnum() UNAVAILABLE', 4;
115 }
116 ok(POSIX::2008::isalnum($alnum), 'isalnum(alnum)');
117 ok(!POSIX::2008::isalnum("$alnum$space"), '!isalnum(alnum+space)');
118 ok(!POSIX::2008::isalnum(''), "!isalnum('')");
119 no warnings 'uninitialized';
120 ok(!POSIX::2008::isalnum(undef), '!isalnum(undef)');
121 }
122
123 SKIP: {
124 if (!defined &POSIX::2008::isalpha) {
125 skip 'isalpha() UNAVAILABLE', 4;
126 }
127 ok(POSIX::2008::isalpha($alpha), 'isalpha(alpha)');
128 ok(!POSIX::2008::isalpha("$alpha$space"), '!isalpha(alpha+space)');
129 ok(!POSIX::2008::isalpha(''), "!isalpha('')");
130 no warnings 'uninitialized';
131 ok(!POSIX::2008::isalpha(undef), '!isalpha(undef)');
132 }
133
134 SKIP: {
135 if (!defined &POSIX::2008::isascii) {
136 skip 'isascii() UNAVAILABLE', 4;
137 }
138 ok(POSIX::2008::isascii($ascii), 'isascii(ascii)');
139 ok(!POSIX::2008::isascii("$ascii\x80"), '!isascii(ascii+0x80)');
140 ok(!POSIX::2008::isascii(''), "!isascii('')");
141 no warnings 'uninitialized';
142 ok(!POSIX::2008::isascii(undef), '!isascii(undef)');
143 }
144
145 SKIP: {
146 if (!defined &POSIX::2008::isblank) {
147 skip 'isblank() UNAVAILABLE', 4;
148 }
149 ok(POSIX::2008::isblank($blank), 'isblank(blank)');
150 ok(!POSIX::2008::isblank("$blank$digit"), '!isblank(blank+digit)');
151 ok(!POSIX::2008::isblank(''), "!isblank('')");
152 no warnings 'uninitialized';
153 ok(!POSIX::2008::isblank(undef), '!isblank(undef)');
154 }
155
156 SKIP: {
157 if (!defined &POSIX::2008::iscntrl) {
158 skip 'iscntrl() UNAVAILABLE', 4;
159 }
160 ok(POSIX::2008::iscntrl($cntrl), 'iscntrl(cntrl)');
161 ok(!POSIX::2008::iscntrl("$cntrl$digit"), '!iscntrl(cntrl+digit)');
162 ok(!POSIX::2008::iscntrl(''), "!iscntrl('')");
163 no warnings 'uninitialized';
164 ok(!POSIX::2008::iscntrl(undef), '!iscntrl(undef)');
165 }
166
167 SKIP: {
168 if (!defined &POSIX::2008::isdigit) {
169 skip 'isdigit() UNAVAILABLE', 4;
170 }
171 ok(POSIX::2008::isdigit($digit), 'isdigit(digit)');
172 ok(!POSIX::2008::isdigit("$digit$space"), '!isdigit(digit+space)');
173 ok(!POSIX::2008::isdigit(''), "!isdigit('')");
174 no warnings 'uninitialized';
175 ok(!POSIX::2008::isdigit(undef), '!isdigit(undef)');
176 }
177
178 SKIP: {
179 if (!defined &POSIX::2008::isgraph) {
180 skip 'isgraph() UNAVAILABLE', 4;
181 }
182 ok(POSIX::2008::isgraph($graph), 'isgraph(graph)');
183 ok(!POSIX::2008::isgraph("$graph$space"), '!isgraph(graph+space)');
184 ok(!POSIX::2008::isgraph(''), "!isgraph('')");
185 no warnings 'uninitialized';
186 ok(!POSIX::2008::isgraph(undef), '!isgraph(undef)');
187 }
188
189 SKIP: {
190 if (!defined &POSIX::2008::islower) {
191 skip 'islower() UNAVAILABLE', 4;
192 }
193 ok(POSIX::2008::islower($lower), 'islower(lower)');
194 ok(!POSIX::2008::islower("$lower$upper"), '!islower(lower+upper)');
195 ok(!POSIX::2008::islower(''), "!islower('')");
196 no warnings 'uninitialized';
197 ok(!POSIX::2008::islower(undef), '!islower(undef)');
198 }
199
200 SKIP: {
201 if (!defined &POSIX::2008::isprint) {
202 skip 'isprint() UNAVAILABLE', 4;
203 }
204 ok(POSIX::2008::isprint($print), 'isprint(print)');
205 ok(!POSIX::2008::isprint("$print$space"), '!isprint(print+space)');
206 ok(!POSIX::2008::isprint(''), "!isprint('')");
207 no warnings 'uninitialized';
208 ok(!POSIX::2008::isprint(undef), '!isprint(undef)');
209 }
210
211 SKIP: {
212 if (!defined &POSIX::2008::ispunct) {
213 skip 'ispunct() UNAVAILABLE', 4;
214 }
215 ok(POSIX::2008::ispunct($punct), 'ispunct(punct)');
216 ok(!POSIX::2008::ispunct("$punct$space"), '!ispunct(punct+space)');
217 ok(!POSIX::2008::ispunct(''), "!ispunct('')");
218 no warnings 'uninitialized';
219 ok(!POSIX::2008::ispunct(undef), '!ispunct(undef)');
220 }
221
222 SKIP: {
223 if (!defined &POSIX::2008::isspace) {
224 skip 'isspace() UNAVAILABLE', 4;
225 }
226 ok(POSIX::2008::isspace($space), 'isspace(space)');
227 ok(!POSIX::2008::isspace("$space$cntrl"), '!isspace(space+cntrl)');
228 ok(!POSIX::2008::isspace(''), "!isspace('')");
229 no warnings 'uninitialized';
230 ok(!POSIX::2008::isspace(undef), '!isspace(undef)');
231 }
232
233 SKIP: {
234 if (!defined &POSIX::2008::isupper) {
235 skip 'isupper() UNAVAILABLE', 4;
236 }
237 ok(POSIX::2008::isupper($upper), 'isupper(upper)');
238 ok(!POSIX::2008::isupper("$upper$lower"), '!isupper(upper+lower)');
239 ok(!POSIX::2008::isupper(''), "!isupper('')");
240 no warnings 'uninitialized';
241 ok(!POSIX::2008::isupper(undef), '!isupper(undef)');
242 }
243
244 SKIP: {
245 if (!defined &POSIX::2008::isxdigit) {
246 skip 'isxdigit() UNAVAILABLE', 4;
247 }
248 ok(POSIX::2008::isxdigit($xdigit), 'isxdigit(xdigit)');
249 ok(!POSIX::2008::isxdigit("$xdigit$alpha"), '!isxdigit(xdigit+alpha)');
250 ok(!POSIX::2008::isxdigit(''), "!isxdigit('')");
251 no warnings 'uninitialized';
252 ok(!POSIX::2008::isxdigit(undef), '!isxdigit(undef)');
253 }