svpeek.t revision 1.2
1use strict; 2use warnings; 3 4use Test::More tests => 52; 5 6BEGIN { use_ok('XS::APItest') }; 7 8$| = 1; 9 10 is (DPeek ($/), 'PVMG("\n"\0)', '$/'); 11 is (DPeek ($\), 'PVMG()', '$\\'); 12 is (DPeek ($.), 'PVMG()', '$.'); 13 is (DPeek ($,), 'UNDEF', '$,'); 14 is (DPeek ($;), 'PV("\34"\0)', '$;'); 15 is (DPeek ($"), 'PV(" "\0)', '$"'); 16 is (DPeek ($:), 'PVMG(" \n-"\0)', '$:'); 17 is (DPeek ($~), 'PVMG()', '$~'); 18 is (DPeek ($^), 'PVMG()', '$^'); 19 is (DPeek ($=), 'PVMG()', '$='); 20 is (DPeek ($-), 'PVMG()', '$-'); 21like (DPeek ($!), qr'^PVMG\("', '$!'); 22if ($^O eq 'VMS') { 23 # VMS defines COMPLEX_STATUS and upgrades $? to PVLV 24 is (DPeek ($?), 'PVLV()', '$?'); 25} else { 26 is (DPeek ($?), 'PVMG()', '$?'); 27} 28 is (DPeek ($|), 'PVMG(1)', '$|'); 29 30 "abc" =~ m/b/; # Don't know why these magic vars have this content 31 () = $1 || ''; 32 is (DPeek ($1), 'PVMG()', ' $1'); 33 is (DPeek ($`), 'PVMG()', ' $`'); 34 is (DPeek ($&), 'PVMG()', ' $&'); 35 is (DPeek ($'), 'PVMG()', " \$'"); 36 37 is (DPeek (undef), 'SV_UNDEF', 'undef'); 38 is (DPeek (1), 'IV(1)', 'constant 1'); 39 is (DPeek (""), 'PV(""\0)', 'constant ""'); 40 is (DPeek (1.), 'NV(1)', 'constant 1.'); 41 is (DPeek (\1), '\IV(1)', 'constant \1'); 42 is (DPeek (\\1), '\\\IV(1)', 'constant \\\1'); 43 44 is (DPeek (\@ARGV), '\AV()', '\@ARGV'); 45 is (DPeek (\@INC), '\AV()', '\@INC'); 46 is (DPeek (\%INC), '\HV()', '\%INC'); 47 is (DPeek (*STDOUT), 'GV()', '*STDOUT'); 48 is (DPeek (sub {}), '\CV(__ANON__)', 'sub {}'); 49 50{ our ($VAR, @VAR, %VAR); 51if ($^O eq 'vos') { 52 # VOS uses .pm as a required executable suffix 53 open VAR, "<", "$^X.pm" or die "Can't open $^X.pm: $!"; 54} else { 55 open VAR, "<", $^X or die "Can't open $^X: $!"; 56} 57 sub VAR {} 58 format VAR = 59. 60 61 is (DPeek ( $VAR), 'UNDEF', ' $VAR undef'); 62 is (DPeek (\$VAR), '\UNDEF', '\$VAR undef'); 63 $VAR = 1; 64 is (DPeek ($VAR), 'IV(1)', ' $VAR 1'); 65 is (DPeek (\$VAR), '\IV(1)', '\$VAR 1'); 66 $VAR = ""; 67 is (DPeek ($VAR), 'PVIV(""\0)', ' $VAR ""'); 68 is (DPeek (\$VAR), '\PVIV(""\0)', '\$VAR ""'); 69 $VAR = "\xdf"; # \xdf works for both ASCII and EBCDIC 70 is (DPeek ($VAR), 'PVIV("\337"\0)', ' $VAR "\xdf"'); 71 is (DPeek (\$VAR), '\PVIV("\337"\0)', '\$VAR "\xdf"'); 72 SKIP: { 73 skip("ASCII-centric tests", 1) if ord "A" == 193; 74 $VAR = "a\x0a\x{20ac}"; 75 is (DPeek ($VAR), 'PVIV("a\n\342\202\254"\0) [UTF8 "a\n\x{20ac}"]', 76 ' $VAR "a\x0a\x{20ac}"'); 77 } 78 $VAR = sub { "VAR" }; 79 is (DPeek ($VAR), '\CV(__ANON__)', ' $VAR sub { "VAR" }'); 80 is (DPeek (\$VAR), '\\\CV(__ANON__)', '\$VAR sub { "VAR" }'); 81 82 $VAR = eval qq{sub \x{30cd} { "VAR" } \\&\x{30cd}}; 83 is (DPeek ($VAR), '\CV(\x{30cd})', ' $VAR sub \x{30cd} { "VAR" }'); 84 is (DPeek (\$VAR), '\\\\CV(\x{30cd})', '\$VAR sub \x{30cd} { "VAR" }'); 85 86 $VAR = 0; 87 88 is (DPeek (\&VAR), '\CV(VAR)', '\&VAR'); 89 is (DPeek ( *VAR), 'GV()', ' *VAR'); 90 91 is (DPeek (*VAR{GLOB}), '\GV()', ' *VAR{GLOB}'); 92like (DPeek (*VAR{SCALAR}), qr'\\PV(IV|MG)\(0\)',' *VAR{SCALAR}'); 93 is (DPeek (*VAR{ARRAY}), '\AV()', ' *VAR{ARRAY}'); 94 is (DPeek (*VAR{HASH}), '\HV()', ' *VAR{HASH}'); 95 is (DPeek (*VAR{CODE}), '\CV(VAR)', ' *VAR{CODE}'); 96 is (DPeek (*VAR{IO}), '\IO()', ' *VAR{IO}'); 97 is (DPeek (*VAR{FORMAT}),$]<5.008?'SV_UNDEF':'\FM()',' *VAR{FORMAT}'); 98 } 99 1001; 101