Old(er) perls (e.g. 5.8.0) do not like \my $x, more
[Data-Peek.git] / t / 50_DDual.t
blob9c5901bdd8cbcf1b3cd301264fde392692edab84
1 #!/usr/bin/perl
3 use strict;
4 use warnings;
6 use Test::More tests => 70;
7 use Test::NoWarnings;
9 use Data::Peek;
11 my %special = ( 9 => "\\t", 10 => "\\n", 13 => "\\r" );
12 sub neat
14 my $neat = $_[0];
15 defined $neat or return "undef";
16 my $ref = ref $neat ? "\\" : "" and $neat = $$neat;
17 join "", $ref, map {
18 my $cp = ord $_;
19 $cp >= 0x20 && $cp <= 0x7e
20 ? $_
21 : $special{$cp} || sprintf "\\x{%02x}", $cp
22 } split m//, $neat;
23 } # neat
25 foreach my $test (
26 [ undef, undef, undef, undef, undef, 0, undef ],
27 [ 0, undef, 0, undef, undef, 0, undef ],
28 [ 1, undef, 1, undef, undef, 0, undef ],
29 [ 0.5, undef, undef, 0.5, undef, 0, 0 ],
30 [ "", "", undef, undef, undef, 0, 0 ],
31 [ \0, undef, undef, undef, 0, 0, undef ],
32 [ \"a", undef, undef, undef, "a", 0, undef ],
33 ) {
34 (undef, my @exp) = @$test;
35 my $in = neat ($test->[0]);
36 ok (my @v = DDual ($test->[0]), "DDual ($in)");
37 is (scalar @v, 5, "5 elements");
38 is ($v[0], $exp[0], "PV $in ".DPeek ($v[0]));
39 is ($v[1], $exp[1], "IV $in ".DPeek ($v[1]));
40 is ($v[2], $exp[2], "NV $in ".DPeek ($v[2]));
41 is ($v[3], $exp[3], "RV $in ".DPeek ($v[3]));
42 is ($v[4], $exp[4], "MG $in ".DPeek ($v[4]));
44 defined $v[1] and next;
45 { no warnings;
46 my $x = 0 + $test->[0];
48 TODO: { local $TODO = "Do all perl versions upgrade?";
49 ok (@v = DDual ($test->[0]), "DDual ($in + 0)");
50 is ($v[1], $exp[5], "IV $in ".DPeek ($v[1]));
54 TODO: { local $TODO = "How magic is \$? accross perl versions?";
55 my @m = DDual ($?);
56 is ($m[4], 3, "\$? has magic");
57 is ($m[0], undef, "PV \$? w/o get");
58 is ($m[1], undef, "IV \$? w/o get");
59 is ($m[2], undef, "NV \$? w/o get");
60 is ($m[3], undef, "RV \$? w/o get");
63 TODO: { local $TODO = "How magic is \$? accross perl versions?";
64 my @m = DDual ($?, 1);
65 is ($m[4], 3, "\$? has magic");
66 is ($m[0], undef, "PV \$? w/ get");
67 is ($m[1], 0, "IV \$? w/ get");
68 is ($m[2], undef, "NV \$? w/ get");
69 is ($m[3], undef, "RV \$? w/ get");