svpeek.t revision 1.3
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()', '$-'); 21 22 # This tests expects that $! will have been used as a string recently. 23 my $foo = "$!"; 24like (DPeek ($!), qr'^PVMG\("', '$!'); 25 26{ 27 local $?; # Reset anything Test::* has done to it. 28 is (DPeek ($?), 'PVMG()', '$?'); 29} 30 is (DPeek ($|), 'PVMG(1)', '$|'); 31 32 "abc" =~ m/b/; # Don't know why these magic vars have this content 33 () = $1 || ''; 34 is (DPeek ($1), 'PVMG()', ' $1'); 35 is (DPeek ($`), 'PVMG()', ' $`'); 36 is (DPeek ($&), 'PVMG()', ' $&'); 37 is (DPeek ($'), 'PVMG()', " \$'"); 38 39 is (DPeek (undef), 'SV_UNDEF', 'undef'); 40 is (DPeek (1), 'IV(1)', 'constant 1'); 41 is (DPeek (""), 'PV(""\0)', 'constant ""'); 42 is (DPeek (1.), 'NV(1)', 'constant 1.'); 43 is (DPeek (\1), '\IV(1)', 'constant \1'); 44 is (DPeek (\\1), '\\\IV(1)', 'constant \\\1'); 45 46 is (DPeek (\@ARGV), '\AV()', '\@ARGV'); 47 is (DPeek (\@INC), '\AV()', '\@INC'); 48 is (DPeek (\%INC), '\HV()', '\%INC'); 49 is (DPeek (*STDOUT), 'GV()', '*STDOUT'); 50 is (DPeek (sub {}), '\CV(__ANON__)', 'sub {}'); 51 52{ our ($VAR, @VAR, %VAR); 53if ($^O eq 'vos') { 54 # VOS uses .pm as a required executable suffix 55 open VAR, "<", "$^X.pm" or die "Can't open $^X.pm: $!"; 56} else { 57 open VAR, "<", $^X or die "Can't open $^X: $!"; 58} 59 sub VAR {} 60 format VAR = 61. 62 63 is (DPeek ( $VAR), 'UNDEF', ' $VAR undef'); 64 is (DPeek (\$VAR), '\UNDEF', '\$VAR undef'); 65 $VAR = 1; 66 is (DPeek ($VAR), 'IV(1)', ' $VAR 1'); 67 is (DPeek (\$VAR), '\IV(1)', '\$VAR 1'); 68 $VAR = ""; 69 is (DPeek ($VAR), 'PVIV(""\0)', ' $VAR ""'); 70 is (DPeek (\$VAR), '\PVIV(""\0)', '\$VAR ""'); 71 $VAR = "\xdf"; # \xdf works for both ASCII and EBCDIC 72 is (DPeek ($VAR), 'PVIV("\337"\0)', ' $VAR "\xdf"'); 73 is (DPeek (\$VAR), '\PVIV("\337"\0)', '\$VAR "\xdf"'); 74 SKIP: { 75 skip("ASCII-centric tests", 1) if ord "A" == 193; 76 $VAR = "a\x0a\x{20ac}"; 77 is (DPeek ($VAR), 'PVIV("a\n\342\202\254"\0) [UTF8 "a\n\x{20ac}"]', 78 ' $VAR "a\x0a\x{20ac}"'); 79 } 80 $VAR = sub { "VAR" }; 81 is (DPeek ($VAR), '\CV(__ANON__)', ' $VAR sub { "VAR" }'); 82 is (DPeek (\$VAR), '\\\CV(__ANON__)', '\$VAR sub { "VAR" }'); 83 84 $VAR = eval qq{sub \x{30cd} { "VAR" } \\&\x{30cd}}; 85 is (DPeek ($VAR), '\CV(\x{30cd})', ' $VAR sub \x{30cd} { "VAR" }'); 86 is (DPeek (\$VAR), '\\\\CV(\x{30cd})', '\$VAR sub \x{30cd} { "VAR" }'); 87 88 $VAR = 0; 89 90 is (DPeek (\&VAR), '\CV(VAR)', '\&VAR'); 91 is (DPeek ( *VAR), 'GV()', ' *VAR'); 92 93 is (DPeek (*VAR{GLOB}), '\GV()', ' *VAR{GLOB}'); 94like (DPeek (*VAR{SCALAR}), qr'\\PV(IV|MG)\(0\)',' *VAR{SCALAR}'); 95 is (DPeek (*VAR{ARRAY}), '\AV()', ' *VAR{ARRAY}'); 96 is (DPeek (*VAR{HASH}), '\HV()', ' *VAR{HASH}'); 97 is (DPeek (*VAR{CODE}), '\CV(VAR)', ' *VAR{CODE}'); 98 is (DPeek (*VAR{IO}), '\IO()', ' *VAR{IO}'); 99 is (DPeek (*VAR{FORMAT}),$]<5.008?'SV_UNDEF':'\FM()',' *VAR{FORMAT}'); 100 } 101 1021; 103