This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Devel-PPPort: Implement av_top_index, av_tindex
[perl5.git] / dist / Devel-PPPort / t / misc.t
1 ################################################################################
2 #
3 #            !!!!!   Do NOT edit this file directly!   !!!!!
4 #
5 #            Edit mktests.PL and/or parts/inc/misc instead.
6 #
7 #  This file was automatically generated from the definition files in the
8 #  parts/inc/ subdirectory by mktests.PL. To learn more about how all this
9 #  works, please read the F<HACKERS> file that came with this distribution.
10 #
11 ################################################################################
12
13 BEGIN {
14   if ($ENV{'PERL_CORE'}) {
15     chdir 't' if -d 't';
16     @INC = ('../lib', '../ext/Devel-PPPort/t') if -d '../lib' && -d '../ext';
17     require Config; import Config;
18     use vars '%Config';
19     if (" $Config{'extensions'} " !~ m[ Devel/PPPort ]) {
20       print "1..0 # Skip -- Perl configured without Devel::PPPort module\n";
21       exit 0;
22     }
23   }
24   else {
25     unshift @INC, 't';
26   }
27
28   sub load {
29     eval "use Test";
30     require 'testutil.pl' if $@;
31   }
32
33   if (128) {
34     load();
35     plan(tests => 128);
36   }
37 }
38
39 use Devel::PPPort;
40 use strict;
41 $^W = 1;
42
43 package Devel::PPPort;
44 use vars '@ISA';
45 require DynaLoader;
46 @ISA = qw(DynaLoader);
47 bootstrap Devel::PPPort;
48
49 package main;
50
51 use vars qw($my_sv @my_av %my_hv);
52
53 ok(&Devel::PPPort::boolSV(1));
54 ok(!&Devel::PPPort::boolSV(0));
55
56 $_ = "Fred";
57 ok(&Devel::PPPort::DEFSV(), "Fred");
58 ok(&Devel::PPPort::UNDERBAR(), "Fred");
59
60 if ("$]" >= 5.009002 && "$]" < 5.023 && "$]" < 5.023004) {
61   eval q{
62     no warnings "deprecated";
63     no if $^V > v5.17.9, warnings => "experimental::lexical_topic";
64     my $_ = "Tony";
65     ok(&Devel::PPPort::DEFSV(), "Fred");
66     ok(&Devel::PPPort::UNDERBAR(), "Tony");
67   };
68 }
69 else {
70   ok(1);
71   ok(1);
72 }
73
74 my @r = &Devel::PPPort::DEFSV_modify();
75
76 ok(@r == 3);
77 ok($r[0], 'Fred');
78 ok($r[1], 'DEFSV');
79 ok($r[2], 'Fred');
80
81 ok(&Devel::PPPort::DEFSV(), "Fred");
82
83 eval { 1 };
84 ok(!&Devel::PPPort::ERRSV());
85 eval { cannot_call_this_one() };
86 ok(&Devel::PPPort::ERRSV());
87
88 ok(&Devel::PPPort::gv_stashpvn('Devel::PPPort', 0));
89 ok(!&Devel::PPPort::gv_stashpvn('does::not::exist', 0));
90 ok(&Devel::PPPort::gv_stashpvn('does::not::exist', 1));
91
92 $my_sv = 1;
93 ok(&Devel::PPPort::get_sv('my_sv', 0));
94 ok(!&Devel::PPPort::get_sv('not_my_sv', 0));
95 ok(&Devel::PPPort::get_sv('not_my_sv', 1));
96
97 @my_av = (1);
98 ok(&Devel::PPPort::get_av('my_av', 0));
99 ok(!&Devel::PPPort::get_av('not_my_av', 0));
100 ok(&Devel::PPPort::get_av('not_my_av', 1));
101
102 %my_hv = (a=>1);
103 ok(&Devel::PPPort::get_hv('my_hv', 0));
104 ok(!&Devel::PPPort::get_hv('not_my_hv', 0));
105 ok(&Devel::PPPort::get_hv('not_my_hv', 1));
106
107 sub my_cv { 1 };
108 ok(&Devel::PPPort::get_cv('my_cv', 0));
109 ok(!&Devel::PPPort::get_cv('not_my_cv', 0));
110 ok(&Devel::PPPort::get_cv('not_my_cv', 1));
111
112 ok(Devel::PPPort::dXSTARG(42), 43);
113 ok(Devel::PPPort::dAXMARK(4711), 4710);
114
115 ok(Devel::PPPort::prepush(), 42);
116
117 ok(join(':', Devel::PPPort::xsreturn(0)), 'test1');
118 ok(join(':', Devel::PPPort::xsreturn(1)), 'test1:test2');
119
120 ok(Devel::PPPort::PERL_ABS(42), 42);
121 ok(Devel::PPPort::PERL_ABS(-13), 13);
122
123 ok(Devel::PPPort::SVf(42), "$]" >= 5.004 ? '[42]' : '42');
124 ok(Devel::PPPort::SVf('abc'), "$]" >= 5.004 ? '[abc]' : 'abc');
125
126 ok(&Devel::PPPort::Perl_ppaddr_t("FOO"), "foo");
127
128 ok(&Devel::PPPort::ptrtests(), 63);
129
130 ok(&Devel::PPPort::OpSIBLING_tests(), 0);
131
132 if ("$]" >= 5.009000) {
133   eval q{
134     ok(&Devel::PPPort::check_HeUTF8("hello"), "norm");
135     ok(&Devel::PPPort::check_HeUTF8("\N{U+263a}"), "utf8");
136   };
137 } else {
138   ok(1, 1);
139   ok(1, 1);
140 }
141
142 @r = &Devel::PPPort::check_c_array();
143 ok($r[0], 4);
144 ok($r[1], "13");
145
146 ok(!Devel::PPPort::SvRXOK(""));
147 ok(!Devel::PPPort::SvRXOK(bless [], "Regexp"));
148
149 if ("$]" < 5.005) {
150         skip 'no qr// objects in this perl', 0;
151         skip 'no qr// objects in this perl', 0;
152 } else {
153         my $qr = eval 'qr/./';
154         ok(Devel::PPPort::SvRXOK($qr));
155         ok(Devel::PPPort::SvRXOK(bless $qr, "Surprise"));
156 }
157
158 ok(  Devel::PPPort::test_isBLANK(ord(" ")));
159 ok(! Devel::PPPort::test_isBLANK(ord("\n")));
160
161 ok(  Devel::PPPort::test_isBLANK_A(ord("\t")));
162 ok(! Devel::PPPort::test_isBLANK_A(ord("\r")));
163
164 ok(  Devel::PPPort::test_isUPPER(ord("A")));
165 ok(! Devel::PPPort::test_isUPPER(ord("a")));
166
167 ok(  Devel::PPPort::test_isUPPER_A(ord("Z")));
168
169 # One of these two is uppercase in EBCDIC; the other in Latin1, but neither are
170 # ASCII uppercase.
171 ok(! Devel::PPPort::test_isUPPER_A(ord(0xDC)));
172 ok(! Devel::PPPort::test_isUPPER_A(ord(0xFC)));
173
174 ok(  Devel::PPPort::test_isLOWER(ord("b")));
175 ok(! Devel::PPPort::test_isLOWER(ord("B")));
176
177 ok(  Devel::PPPort::test_isLOWER_A(ord("y")));
178
179 # One of these two is lowercase in EBCDIC; the other in Latin1, but neither are
180 # ASCII lowercase.
181 ok(! Devel::PPPort::test_isLOWER_A(ord(0xDC)));
182 ok(! Devel::PPPort::test_isLOWER_A(ord(0xFC)));
183
184 ok(  Devel::PPPort::test_isALPHA(ord("C")));
185 ok(! Devel::PPPort::test_isALPHA(ord("1")));
186
187 ok(  Devel::PPPort::test_isALPHA_A(ord("x")));
188 ok(! Devel::PPPort::test_isALPHA_A(0xDC));
189
190 ok(  Devel::PPPort::test_isWORDCHAR(ord("_")));
191 ok(! Devel::PPPort::test_isWORDCHAR(ord("@")));
192
193 ok(  Devel::PPPort::test_isWORDCHAR_A(ord("2")));
194 ok(! Devel::PPPort::test_isWORDCHAR_A(0xFC));
195
196 ok(  Devel::PPPort::test_isALPHANUMERIC(ord("4")));
197 ok(! Devel::PPPort::test_isALPHANUMERIC(ord("_")));
198
199 ok(  Devel::PPPort::test_isALPHANUMERIC_A(ord("l")));
200 ok(! Devel::PPPort::test_isALPHANUMERIC_A(0xDC));
201
202 ok(  Devel::PPPort::test_isALNUM(ord("c")));
203 ok(! Devel::PPPort::test_isALNUM(ord("}")));
204
205 ok(  Devel::PPPort::test_isALNUM_A(ord("5")));
206 ok(! Devel::PPPort::test_isALNUM_A(0xFC));
207
208 ok(  Devel::PPPort::test_isDIGIT(ord("6")));
209 ok(! Devel::PPPort::test_isDIGIT(ord("_")));
210
211 ok(  Devel::PPPort::test_isDIGIT_A(ord("7")));
212 ok(! Devel::PPPort::test_isDIGIT_A(0xDC));
213
214 ok(  Devel::PPPort::test_isOCTAL(ord("7")));
215 ok(! Devel::PPPort::test_isOCTAL(ord("8")));
216
217 ok(  Devel::PPPort::test_isOCTAL_A(ord("0")));
218 ok(! Devel::PPPort::test_isOCTAL_A(ord("9")));
219
220 ok(  Devel::PPPort::test_isIDFIRST(ord("D")));
221 ok(! Devel::PPPort::test_isIDFIRST(ord("1")));
222
223 ok(  Devel::PPPort::test_isIDFIRST_A(ord("_")));
224 ok(! Devel::PPPort::test_isIDFIRST_A(0xFC));
225
226 ok(  Devel::PPPort::test_isIDCONT(ord("e")));
227 ok(! Devel::PPPort::test_isIDCONT(ord("@")));
228
229 ok(  Devel::PPPort::test_isIDCONT_A(ord("2")));
230 ok(! Devel::PPPort::test_isIDCONT_A(0xDC));
231
232 ok(  Devel::PPPort::test_isSPACE(ord(" ")));
233 ok(! Devel::PPPort::test_isSPACE(ord("_")));
234
235 ok(  Devel::PPPort::test_isSPACE_A(ord("\cK")));
236 ok(! Devel::PPPort::test_isSPACE_A(ord("F")));
237
238 # This stresses the edge for ASCII machines, but happens to work on EBCDIC as
239 # well
240 ok(  Devel::PPPort::test_isASCII(0x7F));
241 ok(! Devel::PPPort::test_isASCII(0x80));
242
243 ok(  Devel::PPPort::test_isASCII_A(ord("9")));
244
245 # B6 is the PARAGRAPH SIGN in ASCII and EBCDIC
246 ok(! Devel::PPPort::test_isASCII_A(0xB6));
247
248 ok(  Devel::PPPort::test_isCNTRL(ord("\e")));
249 ok(! Devel::PPPort::test_isCNTRL(ord(" ")));
250
251 ok(  Devel::PPPort::test_isCNTRL_A(ord("\a")));
252 ok(! Devel::PPPort::test_isCNTRL_A(0xB6));
253
254 ok(  Devel::PPPort::test_isPRINT(ord(" ")));
255 ok(! Devel::PPPort::test_isPRINT(ord("\n")));
256
257 ok(  Devel::PPPort::test_isPRINT_A(ord("G")));
258 ok(! Devel::PPPort::test_isPRINT_A(0xB6));
259
260 ok(  Devel::PPPort::test_isGRAPH(ord("h")));
261 ok(! Devel::PPPort::test_isGRAPH(ord(" ")));
262
263 ok(  Devel::PPPort::test_isGRAPH_A(ord("i")));
264 ok(! Devel::PPPort::test_isGRAPH_A(0xB6));
265
266 ok(  Devel::PPPort::test_isPUNCT(ord("#")));
267 ok(! Devel::PPPort::test_isPUNCT(ord(" ")));
268
269 ok(  Devel::PPPort::test_isPUNCT_A(ord("*")));
270 ok(! Devel::PPPort::test_isPUNCT_A(0xB6));
271
272 ok(  Devel::PPPort::test_isXDIGIT(ord("A")));
273 ok(! Devel::PPPort::test_isXDIGIT(ord("_")));
274
275 ok(  Devel::PPPort::test_isXDIGIT_A(ord("9")));
276 ok(! Devel::PPPort::test_isXDIGIT_A(0xDC));
277
278 ok(  Devel::PPPort::test_isPSXSPC(ord(" ")));
279 ok(! Devel::PPPort::test_isPSXSPC(ord("k")));
280
281 ok(  Devel::PPPort::test_isPSXSPC_A(ord("\cK")));
282 ok(! Devel::PPPort::test_isPSXSPC_A(0xFC));
283
284 ok(&Devel::PPPort::av_top_index([1,2,3]), 2);
285 ok(&Devel::PPPort::av_tindex([1,2,3,4]), 3);
286