This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
$! and $1 are PVMG(), but their content is undefined when peeking
[perl5.git] / ext / XS / APItest / t / svpeek.t
CommitLineData
f9c17636
MB
1BEGIN {
2 chdir 't' if -d 't';
3 @INC = '../lib';
4 push @INC, "::lib:$MacPerl::Architecture:" if $^O eq 'MacOS';
5 require Config; import Config;
6 if ($Config{'extensions'} !~ /\bXS\/APItest\b/) {
7 print "1..0 # Skip: XS::APItest was not built\n";
8 exit 0;
9 }
10}
11
12use strict;
13use warnings;
14
a4a03afa 15use Test::More tests => 50;
f9c17636
MB
16
17BEGIN { use_ok('XS::APItest') };
18
19$| = 1;
20
21 is (DPeek ($/), 'PVMG("\n"\0)', '$/');
22 is (DPeek ($\), 'PVMG()', '$\\');
23 is (DPeek ($.), 'PVMG()', '$.');
24 is (DPeek ($,), 'PVMG()', '$,');
25 is (DPeek ($;), 'PV("\34"\0)', '$;');
26 is (DPeek ($"), 'PV(" "\0)', '$"');
27 is (DPeek ($:), 'PVMG(" \n-"\0)', '$:');
28 is (DPeek ($~), 'PVMG()', '$~');
29 is (DPeek ($^), 'PVMG()', '$^');
30 is (DPeek ($=), 'PVMG()', '$=');
31 is (DPeek ($-), 'PVMG()', '$-');
a4a03afa 32like (DPeek ($!), qr'^PVMG\("', '$!');
f9c17636
MB
33 is (DPeek ($?), 'PVMG()', '$?');
34 is (DPeek ($|), 'PVMG(1)', '$|');
35
36 "abc" =~ m/(b)/; # Don't know why these magic vars have this content
a4a03afa 37like (DPeek ($1), qr'^PVMG\("', ' $1');
f9c17636
MB
38 is (DPeek ($`), 'PVMG()', ' $`');
39 is (DPeek ($&), 'PVMG()', ' $&');
40 is (DPeek ($'), 'PVMG()', " \$'");
41
42 is (DPeek (undef), 'SV_UNDEF', 'undef');
43 is (DPeek (1), 'IV(1)', 'constant 1');
44 is (DPeek (""), 'PV(""\0)', 'constant ""');
45 is (DPeek (1.), 'NV(1)', 'constant 1.');
46 is (DPeek (\1), '\IV(1)', 'constant \1');
47 is (DPeek (\\1), '\\\IV(1)', 'constant \\\1');
48
49 is (DPeek (\@ARGV), '\AV()', '\@ARGV');
50 is (DPeek (\@INC), '\AV()', '\@INC');
51 is (DPeek (\%INC), '\HV()', '\%INC');
52 is (DPeek (*STDOUT), 'GV()', '*STDOUT');
53 is (DPeek (sub {}), '\CV(__ANON__)', 'sub {}');
54
55{ our ($VAR, @VAR, %VAR);
56 open VAR, ">VAR.txt";
57 sub VAR {}
58 format VAR =
59.
60 END { unlink "VAR.txt" };
61
62 is (DPeek ( $VAR), 'UNDEF', ' $VAR undef');
63 is (DPeek (\$VAR), '\UNDEF', '\$VAR undef');
64 $VAR = 1;
65 is (DPeek ($VAR), 'IV(1)', ' $VAR 1');
66 is (DPeek (\$VAR), '\IV(1)', '\$VAR 1');
67 $VAR = "";
68 is (DPeek ($VAR), 'PVIV(""\0)', ' $VAR ""');
69 is (DPeek (\$VAR), '\PVIV(""\0)', '\$VAR ""');
70 $VAR = "\xa8";
71 is (DPeek ($VAR), 'PVIV("\250"\0)', ' $VAR "\xa8"');
72 is (DPeek (\$VAR), '\PVIV("\250"\0)', '\$VAR "\xa8"');
73 SKIP: {
74 $] <= 5.008001 and skip "UTF8 tests useless in this ancient perl version", 1;
75 $VAR = "a\x0a\x{20ac}";
76 is (DPeek ($VAR), 'PVIV("a\n\342\202\254"\0) [UTF8 "a\n\x{20ac}"]',
77 ' $VAR "a\x0a\x{20ac}"');
78 }
79 $VAR = sub { "VAR" };
80 is (DPeek ($VAR), '\CV(__ANON__)', ' $VAR sub { "VAR" }');
81 is (DPeek (\$VAR), '\\\CV(__ANON__)', '\$VAR sub { "VAR" }');
82 $VAR = 0;
83
84 is (DPeek (\&VAR), '\CV(VAR)', '\&VAR');
85 is (DPeek ( *VAR), 'GV()', ' *VAR');
86
87 is (DPeek (*VAR{GLOB}), '\GV()', ' *VAR{GLOB}');
88like (DPeek (*VAR{SCALAR}), qr'\\PV(IV|MG)\(0\)',' *VAR{SCALAR}');
89 is (DPeek (*VAR{ARRAY}), '\AV()', ' *VAR{ARRAY}');
90 is (DPeek (*VAR{HASH}), '\HV()', ' *VAR{HASH}');
91 is (DPeek (*VAR{CODE}), '\CV(VAR)', ' *VAR{CODE}');
92 is (DPeek (*VAR{IO}), '\IO()', ' *VAR{IO}');
93 is (DPeek (*VAR{FORMAT}),$]<5.008?'SV_UNDEF':'\FM()',' *VAR{FORMAT}');
94 }
95
961;