1 #!./perl -- -*- mode: cperl; cperl-indent-level: 4 -*-
7 if (($Config::Config{'extensions'} !~ m!\bList/Util\b!) ){
8 print "1..0 # Skip -- Perl configured without List::Util module\n";
20 @prgs = split "########\n", <DATA>;
26 plan tests => scalar @prgs;
30 sub unctrl { print dumpvar::unctrl($_[0]), "\n" }
31 sub uniescape { print dumpvar::uniescape($_[0]), "\n" }
32 sub stringify { print dumpvar::stringify($_[0]), "\n" }
34 # Call main::dumpValue exactly as the perl5db.pl calls it.
39 &main::dumpValue(\@params,-1);
44 sub new { my $class = shift; bless [ @_ ], $class }
48 sub new { my $class = shift; bless [ @_ ], $class }
50 use overload '""' => sub { "Bar<@{$_[0]}>" };
54 my $foo = Foo->new(1..5);
55 my $bar = Bar->new(1..5);
58 my($prog, $expected) = split(/\nEXPECT\n?/, $_);
59 # TODO: dumpvar::stringify() is controlled by a pile of package
60 # dumpvar variables: $printUndef, $unctrl, $quoteHighBit, $bareStringify,
61 # and so forth. We need to test with various settings of those.
62 my $out = tie *STDOUT, 'TieOut';
67 ok(0, "$prog - $ERR");
69 if ($expected =~ m:^/:) {
70 like($$out, $expected, $prog);
72 is($$out, $expected, $prog);
80 bless( \(my $self), $_[0] );
85 $$self .= join('', @_);
90 substr( $$self, 0, length($$self), '' );
106 uniescape("\x{100}");
128 /^'SCALAR\(0x[0-9a-f]+\)'$/i
132 /^'ARRAY\(0x[0-9a-f]+\)'$/i
136 /^'HASH\(0x[0-9a-f]+\)'$/i
140 /^'CODE\(0x[0-9a-f]+\)'$/i
144 /^'GLOB\(0x[0-9a-f]+\)'$/i
148 /^'Foo=ARRAY\(0x[0-9a-f]+\)'$/i
152 /^'Bar=ARRAY\(0x[0-9a-f]+\)'$/i
166 dumpValue("\x{100}");
170 dumpValue("1\n2\n3");
238 dumpvalue("\x{100}");
252 /0 SCALAR\(0x[0-9a-f]+\)\n -> undef\n/i
256 /0 REF\(0x[0-9a-f]+\)\n -> SCALAR\(0x[0-9a-f]+\)\n -> undef\n/i
260 /0 ARRAY\(0x[0-9a-f]+\)\n empty array/i
264 /0 HASH\(0x[0-9a-f]+\)\n\s+empty hash/i
268 /0 CODE\(0x[0-9a-f]+\)\n -> &CODE\(0x[0-9a-f]+\) in /i
272 /0 GLOB\(0x[0-9a-f]+\)\n -> \*main::a\n/i
276 /0 Foo=ARRAY\(0x[0-9a-f]+\)\n 0 1\n 1 2\n 2 3\n 3 4\n 4 5\n/i
280 /0 Bar=ARRAY\(0x[0-9a-f]+\)\n 0 1\n 1 2\n 2 3\n 3 4\n 4 5\n/i
288 /0 ARRAY\(0x[0-9a-f]+\)\n 0 1\n 1 2\n 2 3\n 3 4\n/i
292 /0 HASH\(0x[0-9a-f]+\)\n 1 => 2\n 3 => 4\n/i
294 dumpvalue({1=>2,3=>4});
296 /0 HASH\(0x[0-9a-f]+\)\n 1 => 2\n 3 => 4\n/i
298 dumpvalue({a=>1,b=>2});
300 /0 HASH\(0x[0-9a-f]+\)\n 'a' => 1\n 'b' => 2\n/i
302 dumpvalue([{a=>[1,2,3],b=>{c=>1,d=>2}},{e=>{f=>1,g=>2},h=>[qw(i j k)]}]);
304 /0 ARRAY\(0x[0-9a-f]+\)\n 0 HASH\(0x[0-9a-f]+\)\n 'a' => ARRAY\(0x[0-9a-f]+\)\n 0 1\n 1 2\n 2 3\n 'b' => HASH\(0x[0-9a-f]+\)\n 'c' => 1\n 'd' => 2\n 1 HASH\(0x[0-9a-f]+\)\n 'e' => HASH\(0x[0-9a-f]+\)\n 'f' => 1\n 'g' => 2\n 'h' => ARRAY\(0x[0-9a-f]+\)\n 0 'i'\n 1 'j'\n 2 'k'/i
306 dumpvalue({reverse map {$_=>1} sort qw(the quick brown fox)})
308 /0 HASH\(0x[0-9a-f]+\)\n 1 => 'brown'\n/i
310 my @x=qw(a b c); dumpvalue(\@x);
312 /0 ARRAY\(0x[0-9a-f]+\)\n 0 'a'\n 1 'b'\n 2 'c'\n/i
314 my %x=(a=>1, b=>2); dumpvalue(\%x);
316 /0 HASH\(0x[0-9a-f]+\)\n 'a' => 1\n 'b' => 2\n/i