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