3 # testsuite for Data::Dumper
7 require Config; import Config;
8 if ($Config{'extensions'} !~ /\bData\/Dumper\b/) {
9 print "1..0 # Skip: Data::Dumper was not built\n";
14 # Since Perl 5.8.1 because otherwise hash ordering is really random.
15 local $Data::Dumper::Sortkeys = 1;
19 my $Is_ebcdic = defined($Config{'ebcdic'}) && $Config{'ebcdic'} eq 'define';
21 $Data::Dumper::Pad = "#";
32 $t =~ s/([A-Z]+)\(0x[0-9a-f]+\)/$1(0xdeadbeef)/g
33 if ($WANT =~ /deadbeef/);
35 # these data need massaging with non ascii character sets
36 # because of hashing order differences
37 $WANT = join("\n",sort(split(/\n/,$WANT)));
39 $t = join("\n",sort(split(/\n/,$t)));
42 $name = $name ? " - $name" : '';
43 print( ($t eq $WANT and not $@) ? "ok $TNUM$name\n"
44 : "not ok $TNUM$name\n--Expected--\n$WANT\n--Got--\n$@$t\n");
47 if ($Is_ebcdic) { # EBCDIC.
48 if ($TNUM == 311 || $TNUM == 314) {
56 print $@ ? "not ok $TNUM\n# \$@ says: $@\n" : "ok $TNUM - no eval error\n";
60 $t =~ s/([A-Z]+)\(0x[0-9a-f]+\)/$1(0xdeadbeef)/g
61 if ($WANT =~ /deadbeef/);
63 # here too there are hashing order differences
64 $WANT = join("\n",sort(split(/\n/,$WANT)));
66 $t = join("\n",sort(split(/\n/,$t)));
69 print( ($t eq $WANT and not $@) ? "ok $TNUM - works a 2nd time after intervening eval\n"
70 : "not ok $TNUM\n--Expected--\n$WANT\n--Got--\n$@$t\n");
75 ++$TNUM; print "ok $TNUM # skip $reason\n";
76 ++$TNUM; print "ok $TNUM # skip $reason\n";
77 ++$TNUM; print "ok $TNUM # skip $reason\n";
82 # Force Data::Dumper::Dump to use perl. We test Dumpxs explicitly by calling
83 # it direct. Out here it lets us knobble the next if to test that the perl
84 # only tests do work (and count correctly)
85 $Data::Dumper::Useperl = 1;
86 if (defined &Data::Dumper::Dumpxs) {
87 print "### XS extension loaded, will run XS tests\n";
91 print "### XS extensions not loaded, will NOT run XS tests\n";
128 TEST (q(Data::Dumper->Dump([$a,$b,$c], [qw(a b), 6])),
129 'basic test with names: Dump()');
130 TEST (q(Data::Dumper->Dumpxs([$a,$b,$c], [qw(a b), 6])),
131 'basic test with names: Dumpxs()')
135 local $Data::Dumper::Sparseseen = 1;
136 TEST (q(Data::Dumper->Dump([$a,$b,$c], [qw(a b), 6])),
137 'Sparseseen with names: Dump()');
138 TEST (q(Data::Dumper->Dumpxs([$a,$b,$c], [qw(a b), 6])),
139 'Sparseseen with names: Dumpxs()')
164 $Data::Dumper::Purity = 1; # fill in the holes for eval
165 TEST (q(Data::Dumper->Dump([$a, $b], [qw(*a b)])),
166 'Purity: basic test with dereferenced array: Dump()'); # print as @a
167 TEST (q(Data::Dumper->Dumpxs([$a, $b], [qw(*a b)])),
168 'Purity: basic test with dereferenced array: Dumpxs()')
172 local $Data::Dumper::Sparseseen = 1;
173 TEST (q(Data::Dumper->Dump([$a, $b], [qw(*a b)])),
174 'Purity: Sparseseen with dereferenced array: Dump()'); # print as @a
175 TEST (q(Data::Dumper->Dumpxs([$a, $b], [qw(*a b)])),
176 'Purity: Sparseseen with dereferenced array: Dumpxs()')
196 #$b{'c'} = $b{'a'}[2];
200 TEST (q(Data::Dumper->Dump([$b, $a], [qw(*b a)])),
201 'basic test with dereferenced hash: Dump()'); # print as %b
202 TEST (q(Data::Dumper->Dumpxs([$b, $a], [qw(*b a)])),
203 'basic test with dereferenced hash: Dumpxs()')
219 #$a->[1]{'b'} = $a->[1];
225 $Data::Dumper::Indent = 1;
227 $d = Data::Dumper->new([$a,$b], [qw(a b)]);
228 $d->Seen({'*c' => $c});
231 'Indent: Seen: Dump()');
234 $d = Data::Dumper->new([$a,$b], [qw(a b)]);
235 $d->Seen({'*c' => $c});
238 'Indent: Seen: Dumpxs()');
264 $d->Purity(0)->Quotekeys(0);
265 TEST (q( $d->Reset; $d->Dump ),
266 'Indent(3): Purity(0)->Quotekeys(0): Dump()');
268 TEST (q( $d->Reset; $d->Dumpxs ),
269 'Indent(3): Purity(0)->Quotekeys(0): Dumpxs()')
286 #$VAR1->[1]{'a'} = $VAR1;
287 #$VAR1->[1]{'b'} = $VAR1->[1];
288 #$VAR1->[2] = $VAR1->[1]{'c'};
291 TEST (q(Dumper($a)), 'Dumper');
292 TEST (q(Data::Dumper::DumperX($a)), 'DumperX') if $XS;
311 local $Data::Dumper::Purity = 0;
312 local $Data::Dumper::Quotekeys = 0;
313 local $Data::Dumper::Terse = 1;
315 'Purity 0: Quotekeys 0: Terse 1: Dumper');
316 TEST (q(Data::Dumper::DumperX($a)),
317 'Purity 0: Quotekeys 0: Terse 1: DumperX')
326 # "abc\0'\efg" => "mno\0",
331 $foo = { "abc\000\'\efg" => "mno\000",
335 local $Data::Dumper::Useqq = 1;
336 TEST (q(Dumper($foo)), 'Useqq: Dumper');
337 TEST (q(Data::Dumper::DumperX($foo)), 'Useqq: DumperX') if $XS;
350 %foo = (a=>1,b=>\$foo,c=>\@foo);
372 #*::foo{ARRAY}->[1] = $foo;
373 #*::foo{ARRAY}->[2]{'b'} = *::foo{SCALAR};
374 #*::foo{ARRAY}->[2]{'c'} = *::foo{ARRAY};
375 #*::foo{ARRAY}->[2]{'d'} = *::foo{ARRAY}->[2];
376 #*::foo = *::foo{ARRAY}->[2];
377 #@bar = @{*::foo{ARRAY}};
378 #%baz = %{*::foo{ARRAY}->[2]};
381 $Data::Dumper::Purity = 1;
382 $Data::Dumper::Indent = 3;
383 TEST (q(Data::Dumper->Dump([\\*foo, \\@foo, \\%foo], ['*foo', '*bar', '*baz'])),
384 'Purity 1: Indent 3: Dump()');
385 TEST (q(Data::Dumper->Dumpxs([\\*foo, \\@foo, \\%foo], ['*foo', '*bar', '*baz'])),
386 'Purity 1: Indent 3: Dumpxs()')
404 #*::foo{ARRAY}->[1] = $foo;
405 #*::foo{ARRAY}->[2]{'b'} = *::foo{SCALAR};
406 #*::foo{ARRAY}->[2]{'c'} = *::foo{ARRAY};
407 #*::foo{ARRAY}->[2]{'d'} = *::foo{ARRAY}->[2];
408 #*::foo = *::foo{ARRAY}->[2];
409 #$bar = *::foo{ARRAY};
410 #$baz = *::foo{ARRAY}->[2];
413 $Data::Dumper::Indent = 1;
414 TEST (q(Data::Dumper->Dump([\\*foo, \\@foo, \\%foo], ['foo', 'bar', 'baz'])),
415 'Purity 1: Indent 1: Dump()');
416 TEST (q(Data::Dumper->Dumpxs([\\*foo, \\@foo, \\%foo], ['foo', 'bar', 'baz'])),
417 'Purity 1: Indent 1: Dumpxs()')
436 #*::foo{HASH}->{'b'} = *::foo{SCALAR};
437 #*::foo{HASH}->{'c'} = \@bar;
438 #*::foo{HASH}->{'d'} = *::foo{HASH};
439 #$bar[2] = *::foo{HASH};
440 #%baz = %{*::foo{HASH}};
444 TEST (q(Data::Dumper->Dump([\\@foo, \\%foo, \\*foo], ['*bar', '*baz', '*foo'])),
445 'array|hash|glob dereferenced: Dump()');
446 TEST (q(Data::Dumper->Dumpxs([\\@foo, \\%foo, \\*foo], ['*bar', '*baz', '*foo'])),
447 'array|hash|glob dereferenced: Dumpxs()')
466 #*::foo{HASH}->{'b'} = *::foo{SCALAR};
467 #*::foo{HASH}->{'c'} = $bar;
468 #*::foo{HASH}->{'d'} = *::foo{HASH};
469 #$bar->[2] = *::foo{HASH};
470 #$baz = *::foo{HASH};
474 TEST (q(Data::Dumper->Dump([\\@foo, \\%foo, \\*foo], ['bar', 'baz', 'foo'])),
475 'array|hash|glob: not dereferenced: Dump()');
476 TEST (q(Data::Dumper->Dumpxs([\\@foo, \\%foo, \\*foo], ['bar', 'baz', 'foo'])),
477 'array|hash|glob: not dereferenced: Dumpxs()')
497 $Data::Dumper::Purity = 0;
498 $Data::Dumper::Quotekeys = 0;
499 TEST (q(Data::Dumper->Dump([\\*foo, \\@foo, \\%foo], ['*foo', '*bar', '*baz'])),
500 'Purity 0: Quotekeys 0: dereferenced: Dump()');
501 TEST (q(Data::Dumper->Dumpxs([\\*foo, \\@foo, \\%foo], ['*foo', '*bar', '*baz'])),
502 'Purity 0: Quotekeys 0: dereferenced: Dumpxs')
522 TEST (q(Data::Dumper->Dump([\\*foo, \\@foo, \\%foo], ['foo', 'bar', 'baz'])),
523 'Purity 0: Quotekeys 0: not dereferenced: Dump()');
524 TEST (q(Data::Dumper->Dumpxs([\\*foo, \\@foo, \\%foo], ['foo', 'bar', 'baz'])),
525 'Purity 0: Quotekeys 0: not dereferenced: Dumpxs()')
534 @dogs = ( 'Fido', 'Wags' );
541 $mutts = $mutts; # avoid warning
551 # ${$kennels{First}},
552 # ${$kennels{Second}},
559 $d = Data::Dumper->new([\\%kennel, \\@dogs, $mutts],
560 [qw(*kennels *dogs *mutts)] );
563 'constructor: hash|array|scalar: Dump()');
566 $d = Data::Dumper->new([\\%kennel, \\@dogs, $mutts],
567 [qw(*kennels *dogs *mutts)] );
570 'constructor: hash|array|scalar: Dumpxs()');
576 #%kennels = %kennels;
581 TEST q($d->Dump), 'object call: Dump';
582 TEST q($d->Dumpxs), 'object call: Dumpxs' if $XS;
592 # ${$kennels{First}},
593 # ${$kennels{Second}},
599 TEST q($d->Reset; $d->Dump), 'Reset and Dump separate calls';
601 TEST (q($d->Reset; $d->Dumpxs), 'Reset and Dumpxs separate calls');
611 # First => \$dogs[0],
612 # Second => \$dogs[1]
615 #%kennels = %{$dogs[2]};
616 #%mutts = %{$dogs[2]};
620 $d = Data::Dumper->new([\\@dogs, \\%kennel, $mutts],
621 [qw(*dogs *kennels *mutts)] );
624 'constructor: array|hash|scalar: Dump()');
627 $d = Data::Dumper->new([\\@dogs, \\%kennel, $mutts],
628 [qw(*dogs *kennels *mutts)] );
631 'constructor: array|hash|scalar: Dumpxs()');
636 TEST q($d->Reset->Dump), 'Reset Dump chained';
638 TEST q($d->Reset->Dumpxs), 'Reset Dumpxs chained';
659 $d = Data::Dumper->new( [\@dogs, \%kennel], [qw(*dogs *kennels)] );
660 $d->Deepcopy(1)->Dump;
662 'Deepcopy(1): Dump');
664 # TEST 'q($d->Reset->Dumpxs);
666 $d = Data::Dumper->new( [\@dogs, \%kennel], [qw(*dogs *kennels)] );
667 $d->Deepcopy(1)->Dumpxs;
669 'Deepcopy(1): Dumpxs');
676 sub z { print "foo\n" }
688 TEST (q(Data::Dumper->new([\&z,$c],['a','c'])->Seen({'b' => \&z})->Dump;),
689 'Seen: scalar: Dump');
690 TEST (q(Data::Dumper->new([\&z,$c],['a','c'])->Seen({'b' => \&z})->Dumpxs;),
691 'Seen: scalar: Dumpxs')
703 TEST (q(Data::Dumper->new([\&z,$c],['a','c'])->Seen({'*b' => \&z})->Dump;),
705 TEST (q(Data::Dumper->new([\&z,$c],['a','c'])->Seen({'*b' => \&z})->Dumpxs;),
706 'Seen: glob: Dumpxs')
718 TEST (q(Data::Dumper->new([\&z,$c],['*a','*c'])->Seen({'*b' => \&z})->Dump;),
719 'Seen: glob: dereference: Dump');
720 TEST (q(Data::Dumper->new([\&z,$c],['*a','*c'])->Seen({'*b' =>
722 'Seen: glob: derference: Dumpxs')
741 TEST (q(Data::Dumper->new([$a],['*a'])->Purity(1)->Dump;),
742 'Purity(1): dereference: Dump');
743 TEST (q(Data::Dumper->new([$a],['*a'])->Purity(1)->Dumpxs;),
744 'Purity(1): dereference: Dumpxs')
759 TEST (q(Data::Dumper->new([$a,$b],['a','b'])->Purity(1)->Dump;),
760 'Purity(1): not dereferenced: Dump');
761 TEST (q(Data::Dumper->new([$a,$b],['a','b'])->Purity(1)->Dumpxs;),
762 'Purity(1): not dereferenced: Dumpxs')
767 $a = [{ a => \$b }, { b => undef }];
768 $b = [{ c => \$b }, { d => \$a }];
788 #${$a->[0]{a}}->[0]->{c} = $a->[0]{a};
789 #${${$a->[0]{a}}->[1]->{d}} = $a;
793 TEST (q(Data::Dumper->new([$a,$b],['a','b'])->Purity(1)->Dump;),
794 'Purity(1): Dump again');
795 TEST (q(Data::Dumper->new([$a,$b],['a','b'])->Purity(1)->Dumpxs;),
796 'Purity(1); Dumpxs again')
801 $a = [[[[\\\\\'foo']]]];
818 #$c = ${${$a->[0][0][0][0]}};
821 TEST (q(Data::Dumper->new([$a,$b,$c],['a','b','c'])->Purity(1)->Dump;),
822 'Purity(1): Dump: 3 elements');
823 TEST (q(Data::Dumper->new([$a,$b,$c],['a','b','c'])->Purity(1)->Dumpxs;),
824 'Purity(1): Dumpxs: 3 elements')
843 # e => 'ARRAY(0xdeadbeef)'
852 TEST (q(Data::Dumper->new([$a,$b,$c],['a','b','c'])->Maxdepth(4)->Dump;),
853 'Maxdepth(4): Dump()');
854 TEST (q(Data::Dumper->new([$a,$b,$c],['a','b','c'])->Maxdepth(4)->Dumpxs;),
855 'Maxdepth(4): Dumpxs()')
862 # b => 'HASH(0xdeadbeef)'
870 TEST (q(Data::Dumper->new([$a,$b,$c],['a','b','c'])->Maxdepth(1)->Dump;),
871 'Maxdepth(1): Dump()');
872 TEST (q(Data::Dumper->new([$a,$b,$c],['a','b','c'])->Maxdepth(1)->Dumpxs;),
873 'Maxdepth(1): Dumpxs()')
889 TEST (q(Data::Dumper->new([$b],['b'])->Purity(0)->Dump;),
890 'Purity(0): Dump()');
891 TEST (q(Data::Dumper->new([$b],['b'])->Purity(0)->Dumpxs;),
892 'Purity(0): Dumpxs()')
901 #${$b->[0]} = $b->[0];
905 TEST (q(Data::Dumper->new([$b],['b'])->Purity(1)->Dump;),
906 'Purity(1): Dump()');
907 TEST (q(Data::Dumper->new([$b],['b'])->Purity(1)->Dumpxs;),
915 ## XS code was adding an extra \0
921 TEST q(Data::Dumper->Dump([$a], ['a'])), "\\x{9c10}";
923 SKIP_TEST "Incomplete support for UTF-8 in old perls";
925 TEST q(Data::Dumper->Dumpxs([$a], ['a'])), "XS \\x{9c10}"
931 $a = { map { ("$_$_$_", ++$i) } 'I'..'Q' };
949 TEST (q(Data::Dumper->new([$a])->Dump;),
950 'basic test without names: Dump()');
951 TEST (q(Data::Dumper->new([$a])->Dumpxs;),
952 'basic test without names: Dumpxs()')
958 $c = { map { (++$i, "$_$_$_") } 'I'..'Q' };
959 local $Data::Dumper::Sortkeys = \&sort199;
962 return [ sort { $b <=> $a } keys %$hash ];
981 TEST q(Data::Dumper->new([$c])->Dump;), "sortkeys sub";
982 TEST q(Data::Dumper->new([$c])->Dumpxs;), "sortkeys sub (XS)"
988 $c = { map { (++$i, "$_$_$_") } 'I'..'Q' };
989 $d = { reverse %$c };
990 local $Data::Dumper::Sortkeys = \&sort205;
994 $hash eq $c ? (sort { $a <=> $b } keys %$hash)
995 : (reverse sort keys %$hash)
1028 TEST q(Data::Dumper->new([[$c, $d]])->Dump;), "more sortkeys sub";
1029 # the XS code does number values as strings
1030 $WANT =~ s/ (\d+)(,?)$/ '$1'$2/gm;
1031 TEST q(Data::Dumper->new([[$c, $d]])->Dumpxs;), "more sortkeys sub (XS)"
1036 local $Data::Dumper::Deparse = 1;
1037 local $Data::Dumper::Indent = 2;
1049 if(" $Config{'extensions'} " !~ m[ B ]) {
1050 SKIP_TEST "Perl configured without B module";
1052 TEST (q(Data::Dumper->new([{ foo => sub { print "foo"; } }])->Dump),
1053 'Deparse 1: Indent 2; Dump()');
1061 # The controls (bare numbers) are stored either as integers or floating point.
1062 # [depending on whether the tokeniser sees things like ".".
1063 # The peephole optimiser only runs for constant folding, not single constants,
1064 # so I already have some NVs, some IVs
1065 # The string versions are not. They are all PV
1067 # This is arguably all far too chummy with the implementation, but I really
1068 # want to ensure that we don't go wrong when flags on scalars get as side
1069 # effects of reading them.
1071 # These tests are actually testing the precise output of the current
1072 # implementation, so will most likely fail if the implementation changes,
1073 # even if the new implementation produces different but correct results.
1074 # It would be nice to test for wrong answers, but I can't see how to do that,
1075 # so instead I'm checking for unexpected answers. (ie -2 becoming "-2" is not
1076 # wrong, but I can't see an easy, reliable way to code that knowledge)
1078 # Numbers (seen by the tokeniser as numbers, stored as numbers.
1081 0, +1, -2, 3.0, +4.0, -5.0, 6.5, +7.5, -8.5,
1082 9, +10, -11, 12.0, +13.0, -14.0, 15.5, +16.25, -17.75,
1087 "0", "+1", "-2", "3.0", "+4.0", "-5.0", "6.5", "+7.5", "-8.5", " 9",
1088 " +10", " -11", " 12.0", " +13.0", " -14.0", " 15.5", " +16.25", " -17.75",
1091 # The perl code always does things the same way for numbers.
1092 $WANT_PL_N = <<'EOT';
1112 # The perl code knows that 0 and -2 stringify exactly back to the strings,
1113 # so it dumps them as numbers, not strings.
1114 $WANT_PL_S = <<'EOT';
1131 #$VAR17 = ' +16.25';
1132 #$VAR18 = ' -17.75';
1135 # The XS code differs.
1136 # These are the numbers as seen by the tokeniser. Constants aren't folded
1137 # (which makes IVs where possible) so values the tokeniser thought were
1138 # floating point are stored as NVs. The XS code outputs these as strings,
1139 # but as it has converted them from NVs, leading + signs will not be there.
1140 $WANT_XS_N = <<'EOT';
1161 # These are the strings as seen by the tokeniser. The XS code will output
1162 # these for all cases except where the scalar has been used in integer context
1163 $WANT_XS_S = <<'EOT';
1180 #$VAR17 = ' +16.25';
1181 #$VAR18 = ' -17.75';
1184 # These are the numbers as IV-ized by &
1185 # These will differ from WANT_XS_N because now IV flags will be set on all
1186 # values that were actually integer, and the XS code will then output these
1187 # as numbers not strings.
1188 $WANT_XS_I = <<'EOT';
1209 # Some of these tests will be redundant.
1210 @numbers_s = @numbers_i = @numbers_is = @numbers_n = @numbers_ns = @numbers_ni
1211 = @numbers_nis = @numbers;
1212 @strings_s = @strings_i = @strings_is = @strings_n = @strings_ns = @strings_ni
1213 = @strings_nis = @strings;
1214 # Use them in an integer context
1215 foreach (@numbers_i, @numbers_ni, @numbers_nis, @numbers_is,
1216 @strings_i, @strings_ni, @strings_nis, @strings_is) {
1217 my $b = sprintf "%d", $_;
1219 # Use them in a floating point context
1220 foreach (@numbers_n, @numbers_ni, @numbers_nis, @numbers_ns,
1221 @strings_n, @strings_ni, @strings_nis, @strings_ns) {
1222 my $b = sprintf "%e", $_;
1224 # Use them in a string context
1225 foreach (@numbers_s, @numbers_is, @numbers_nis, @numbers_ns,
1226 @strings_s, @strings_is, @strings_nis, @strings_ns) {
1227 my $b = sprintf "%s", $_;
1230 # use Devel::Peek; Dump ($_) foreach @vanilla_c;
1233 TEST q(Data::Dumper->new(\@numbers)->Dump), 'Numbers';
1234 TEST q(Data::Dumper->new(\@numbers_s)->Dump), 'Numbers PV';
1235 TEST q(Data::Dumper->new(\@numbers_i)->Dump), 'Numbers IV';
1236 TEST q(Data::Dumper->new(\@numbers_is)->Dump), 'Numbers IV,PV';
1237 TEST q(Data::Dumper->new(\@numbers_n)->Dump), 'Numbers NV';
1238 TEST q(Data::Dumper->new(\@numbers_ns)->Dump), 'Numbers NV,PV';
1239 TEST q(Data::Dumper->new(\@numbers_ni)->Dump), 'Numbers NV,IV';
1240 TEST q(Data::Dumper->new(\@numbers_nis)->Dump), 'Numbers NV,IV,PV';
1242 TEST q(Data::Dumper->new(\@strings)->Dump), 'Strings';
1243 TEST q(Data::Dumper->new(\@strings_s)->Dump), 'Strings PV';
1244 TEST q(Data::Dumper->new(\@strings_i)->Dump), 'Strings IV';
1245 TEST q(Data::Dumper->new(\@strings_is)->Dump), 'Strings IV,PV';
1246 TEST q(Data::Dumper->new(\@strings_n)->Dump), 'Strings NV';
1247 TEST q(Data::Dumper->new(\@strings_ns)->Dump), 'Strings NV,PV';
1248 TEST q(Data::Dumper->new(\@strings_ni)->Dump), 'Strings NV,IV';
1249 TEST q(Data::Dumper->new(\@strings_nis)->Dump), 'Strings NV,IV,PV';
1251 my $nv_preserves_uv = defined $Config{d_nv_preserves_uv};
1252 my $nv_preserves_uv_4bits = exists($Config{nv_preserves_uv_bits}) && $Config{nv_preserves_uv_bits} >= 4;
1254 TEST q(Data::Dumper->new(\@numbers)->Dumpxs), 'XS Numbers';
1255 TEST q(Data::Dumper->new(\@numbers_s)->Dumpxs), 'XS Numbers PV';
1256 if ($nv_preserves_uv || $nv_preserves_uv_4bits) {
1258 TEST q(Data::Dumper->new(\@numbers_i)->Dumpxs), 'XS Numbers IV';
1259 TEST q(Data::Dumper->new(\@numbers_is)->Dumpxs), 'XS Numbers IV,PV';
1261 SKIP_TEST "NV does not preserve 4bits";
1262 SKIP_TEST "NV does not preserve 4bits";
1265 TEST q(Data::Dumper->new(\@numbers_n)->Dumpxs), 'XS Numbers NV';
1266 TEST q(Data::Dumper->new(\@numbers_ns)->Dumpxs), 'XS Numbers NV,PV';
1267 if ($nv_preserves_uv || $nv_preserves_uv_4bits) {
1269 TEST q(Data::Dumper->new(\@numbers_ni)->Dumpxs), 'XS Numbers NV,IV';
1270 TEST q(Data::Dumper->new(\@numbers_nis)->Dumpxs), 'XS Numbers NV,IV,PV';
1272 SKIP_TEST "NV does not preserve 4bits";
1273 SKIP_TEST "NV does not preserve 4bits";
1277 TEST q(Data::Dumper->new(\@strings)->Dumpxs), 'XS Strings';
1278 TEST q(Data::Dumper->new(\@strings_s)->Dumpxs), 'XS Strings PV';
1279 # This one used to really mess up. New code actually emulates the .pm code
1281 TEST q(Data::Dumper->new(\@strings_i)->Dumpxs), 'XS Strings IV';
1282 TEST q(Data::Dumper->new(\@strings_is)->Dumpxs), 'XS Strings IV,PV';
1283 if ($nv_preserves_uv || $nv_preserves_uv_4bits) {
1285 TEST q(Data::Dumper->new(\@strings_n)->Dumpxs), 'XS Strings NV';
1286 TEST q(Data::Dumper->new(\@strings_ns)->Dumpxs), 'XS Strings NV,PV';
1288 SKIP_TEST "NV does not preserve 4bits";
1289 SKIP_TEST "NV does not preserve 4bits";
1291 # This one used to really mess up. New code actually emulates the .pm code
1293 TEST q(Data::Dumper->new(\@strings_ni)->Dumpxs), 'XS Strings NV,IV';
1294 TEST q(Data::Dumper->new(\@strings_nis)->Dumpxs), 'XS Strings NV,IV,PV';
1300 ## Perl code was using /...$/ and hence missing the \n.
1306 # Can't pad with # as the output has an embedded newline.
1307 local $Data::Dumper::Pad = "my ";
1308 TEST q(Data::Dumper->Dump(["42\n"])), "number with trailing newline";
1309 TEST q(Data::Dumper->Dumpxs(["42\n"])), "XS number with trailing newline"
1329 ## Perl code flips over at 10 digits.
1332 #$VAR2 = '1000000000';
1333 #$VAR3 = '9999999999';
1334 #$VAR4 = '10000000000';
1335 #$VAR5 = -999999999;
1336 #$VAR6 = '-1000000000';
1337 #$VAR7 = '-9999999999';
1338 #$VAR8 = '-10000000000';
1339 #$VAR9 = '4294967295';
1340 #$VAR10 = '4294967296';
1341 #$VAR11 = '-2147483648';
1342 #$VAR12 = '-2147483649';
1345 TEST q(Data::Dumper->Dump(\@a)), "long integers";
1348 ## XS code flips over at 11 characters ("-" is a char) or larger than int.
1349 if (~0 == 0xFFFFFFFF) {
1353 #$VAR2 = 1000000000;
1354 #$VAR3 = '9999999999';
1355 #$VAR4 = '10000000000';
1356 #$VAR5 = -999999999;
1357 #$VAR6 = '-1000000000';
1358 #$VAR7 = '-9999999999';
1359 #$VAR8 = '-10000000000';
1360 #$VAR9 = 4294967295;
1361 #$VAR10 = '4294967296';
1362 #$VAR11 = '-2147483648';
1363 #$VAR12 = '-2147483649';
1368 #$VAR2 = 1000000000;
1369 #$VAR3 = 9999999999;
1370 #$VAR4 = '10000000000';
1371 #$VAR5 = -999999999;
1372 #$VAR6 = '-1000000000';
1373 #$VAR7 = '-9999999999';
1374 #$VAR8 = '-10000000000';
1375 #$VAR9 = 4294967295;
1376 #$VAR10 = 4294967296;
1377 #$VAR11 = '-2147483648';
1378 #$VAR12 = '-2147483649';
1381 TEST q(Data::Dumper->Dumpxs(\@a)), "XS long integers";
1388 $b = "Bad. XS didn't escape dollar sign";
1390 $WANT = <<"EOT"; # Careful. This is '' string written inside "" here doc
1391 #\$VAR1 = '\$b\"\@\\\\\xB1';
1393 $a = "\$b\"\@\\\xB1\x{100}";
1395 TEST q(Data::Dumper->Dump([$a])), "utf8 flag with \" and \$";
1397 $WANT = <<'EOT'; # While this is "" string written inside "" here doc
1398 #$VAR1 = "\$b\"\@\\\x{b1}";
1400 TEST q(Data::Dumper->Dumpxs([$a])), "XS utf8 flag with \" and \$";
1403 $b = "Bad. XS didn't escape dollar sign";
1405 $WANT = <<"EOT"; # Careful. This is '' string written inside "" here doc
1406 #\$VAR1 = '\$b\"\@\\\\\xA3';
1409 $a = "\$b\"\@\\\xA3\x{100}";
1411 TEST q(Data::Dumper->Dump([$a])), "utf8 flag with \" and \$";
1413 $WANT = <<'EOT'; # While this is "" string written inside "" here doc
1414 #$VAR1 = "\$b\"\@\\\x{a3}";
1416 TEST q(Data::Dumper->Dumpxs([$a])), "XS utf8 flag with \" and \$";
1419 # XS used to produce "$b\"' which is 4 chars, not 3. [ie wrongly qq(\$b\\\")]
1425 $a = "\$b\"\x{100}";
1427 TEST q(Data::Dumper->Dump([$a])), "utf8 flag with \" and \$";
1429 TEST q(Data::Dumper->Dumpxs([$a])), "XS utf8 flag with \" and \$";
1433 # XS used to produce 'D'oh!' which is well, D'oh!
1434 # Andreas found this one, which in turn discovered the previous two.
1440 $a = "D'oh!\x{100}";
1442 TEST q(Data::Dumper->Dump([$a])), "utf8 flag with '";
1444 TEST q(Data::Dumper->Dumpxs([$a])), "XS utf8 flag with '";
1448 # Jarkko found that -Mutf8 caused some tests to fail. Turns out that there
1449 # was an otherwise untested code path in the XS for utf8 hash keys with purity
1457 # "\x{decaf}\x{decaf}\x{decaf}\x{decaf}" => do{my $o}
1459 #*::ping{HASH}->{"\x{decaf}\x{decaf}\x{decaf}\x{decaf}"} = *::ping{SCALAR};
1460 #%pong = %{*::ping{HASH}};
1462 local $Data::Dumper::Purity = 1;
1463 local $Data::Dumper::Sortkeys;
1465 %ping = (chr (0xDECAF) x 4 =>\$ping);
1466 for $Data::Dumper::Sortkeys (0, 1) {
1468 TEST (q(Data::Dumper->Dump([\\*ping, \\%ping], ['*ping', '*pong'])),
1469 "utf8: Purity 1: Sortkeys: Dump()");
1470 TEST (q(Data::Dumper->Dumpxs([\\*ping, \\%ping], ['*ping', '*pong'])),
1471 "utf8: Purity 1: Sortkeys: Dumpxs()")
1474 SKIP_TEST "Incomplete support for UTF-8 in old perls";
1475 SKIP_TEST "Incomplete support for UTF-8 in old perls";
1480 # XS for quotekeys==0 was not being defensive enough against utf8 flagged
1489 local $Data::Dumper::Quotekeys = 0;
1490 my $k = 'perl' . chr 256;
1492 %foo = ($k => 'rocks');
1494 TEST q(Data::Dumper->Dump([\\%foo])), "quotekeys == 0 for utf8 flagged ASCII";
1495 TEST q(Data::Dumper->Dumpxs([\\%foo])),
1496 "XS quotekeys == 0 for utf8 flagged ASCII" if $XS;
1509 TEST q(Data::Dumper->Dump([\@foo])), 'Richard Clamp, Message-Id: <20030104005247.GA27685@mirth.demon.co.uk>: Dump()';
1510 TEST q(Data::Dumper->Dumpxs([\@foo])), 'Richard Clamp, Message-Id: <20030104005247.GA27685@mirth.demon.co.uk>: Dumpxs()'if $XS;
1514 # Make sure $obj->Dumpxs returns the right thing in list context. This was
1515 # broken by the initial attempt to fix [perl #74170].
1519 TEST q(join " ", new Data::Dumper [[]],[] =>->Dumpxs),
1520 '$obj->Dumpxs in list context'
1527 # "\0\1\2\3\4\5\6\a\b\t\n\13\f\r\16\17\20\21\22\23\24\25\26\27\30\31\32\e\34\35\36\37 !\"#\$%&'()*+,-./0123456789:;<=>?\@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377"
1531 $foo = [ join "", map chr, 0..255 ];
1532 local $Data::Dumper::Useqq = 1;
1533 TEST (q(Dumper($foo)), 'All latin1 characters: Dumper');
1534 TEST (q(Data::Dumper::DumperX($foo)), 'All latin1 characters: DumperX') if $XS;
1541 # "\0\1\2\3\4\5\6\a\b\t\n\13\f\r\16\17\20\21\22\23\24\25\26\27\30\31\32\e\34\35\36\37 !\"#\$%&'()*+,-./0123456789:;<=>?\@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177\x{80}\x{81}\x{82}\x{83}\x{84}\x{85}\x{86}\x{87}\x{88}\x{89}\x{8a}\x{8b}\x{8c}\x{8d}\x{8e}\x{8f}\x{90}\x{91}\x{92}\x{93}\x{94}\x{95}\x{96}\x{97}\x{98}\x{99}\x{9a}\x{9b}\x{9c}\x{9d}\x{9e}\x{9f}\x{a0}\x{a1}\x{a2}\x{a3}\x{a4}\x{a5}\x{a6}\x{a7}\x{a8}\x{a9}\x{aa}\x{ab}\x{ac}\x{ad}\x{ae}\x{af}\x{b0}\x{b1}\x{b2}\x{b3}\x{b4}\x{b5}\x{b6}\x{b7}\x{b8}\x{b9}\x{ba}\x{bb}\x{bc}\x{bd}\x{be}\x{bf}\x{c0}\x{c1}\x{c2}\x{c3}\x{c4}\x{c5}\x{c6}\x{c7}\x{c8}\x{c9}\x{ca}\x{cb}\x{cc}\x{cd}\x{ce}\x{cf}\x{d0}\x{d1}\x{d2}\x{d3}\x{d4}\x{d5}\x{d6}\x{d7}\x{d8}\x{d9}\x{da}\x{db}\x{dc}\x{dd}\x{de}\x{df}\x{e0}\x{e1}\x{e2}\x{e3}\x{e4}\x{e5}\x{e6}\x{e7}\x{e8}\x{e9}\x{ea}\x{eb}\x{ec}\x{ed}\x{ee}\x{ef}\x{f0}\x{f1}\x{f2}\x{f3}\x{f4}\x{f5}\x{f6}\x{f7}\x{f8}\x{f9}\x{fa}\x{fb}\x{fc}\x{fd}\x{fe}\x{ff}\x{20ac}"
1545 $foo = [ join "", map chr, 0..255, 0x20ac ];
1546 local $Data::Dumper::Useqq = 1;
1548 print "not ok " . (++$TNUM) . " # TODO - fails under 5.6\n" for 1..3;
1551 TEST q(Dumper($foo)),
1552 'All latin1 characters with utf8 flag including a wide character: Dumper';
1554 TEST (q(Data::Dumper::DumperX($foo)),
1555 'All latin1 characters with utf8 flag including a wide character: DumperX')
1561 # If XS cannot load, the pure-Perl version cannot deparse vstrings with
1562 # underscores properly. In 5.8.0, vstrings are just strings.
1563 my $no_vstrings = <<'NOVSTRINGS';
1569 my $vstrings_corr = <<'VSTRINGS_CORRECT';
1575 $WANT = $] <= 5.0080001
1581 \($] < 5.007 ? v65.66.67 : eval 'v65.66.067'),
1586 TEST q(Data::Dumper->Dump(\@::_v, [qw(a b c d)])), 'vstrings';
1587 TEST q(Data::Dumper->Dumpxs(\@::_v, [qw(a b c d)])), 'xs vstrings'
1590 else { # Skip tests before 5.10. vstrings considered funny before
1591 SKIP_TEST "vstrings considered funny before 5.10.0";
1592 SKIP_TEST "vstrings considered funny before 5.10.0 (XS)"
1599 # [perl #107372] blessed overloaded globs
1601 #$VAR1 = bless( \*::finkle, 'overtest' );
1605 use overload fallback=>1, q\""\=>sub{"oaoaa"};
1607 TEST q(Data::Dumper->Dump([bless \*finkle, "overtest"])),
1608 'blessed overloaded globs';
1609 TEST q(Data::Dumper->Dumpxs([\*finkle])), 'blessed overloaded globs (xs)'
1614 # [perl #74798] uncovered behaviour
1618 local $Data::Dumper::Useqq = 1;
1619 TEST q(Data::Dumper->Dump(["\x000"])),
1620 "\\ octal followed by digit";
1621 TEST q(Data::Dumper->Dumpxs(["\x000"])), '\\ octal followed by digit (xs)'
1625 #$VAR1 = "\x{100}\0000";
1627 local $Data::Dumper::Useqq = 1;
1628 TEST q(Data::Dumper->Dump(["\x{100}\x000"])),
1629 "\\ octal followed by digit unicode";
1630 TEST q(Data::Dumper->Dumpxs(["\x{100}\x000"])), '\\ octal followed by digit unicode (xs)'
1635 #$VAR1 = "\0\x{660}";
1637 TEST q(Data::Dumper->Dump(["\\x00\\x{0660}"])),
1638 "\\ octal followed by unicode digit";
1639 TEST q(Data::Dumper->Dumpxs(["\\x00\\x{0660}"])), '\\ octal followed by unicode digit (xs)'
1642 # [perl #118933 - handling of digits
1650 #$VAR7 = "1234567890";
1652 TEST q(Data::Dumper->Dump([0, 1, 90, -10, "010", "112345678", "1234567890" ])),
1653 "numbers and number-like scalars";
1655 TEST q(Data::Dumper->Dumpxs([0, 1, 90, -10, "010", "112345678", "1234567890" ])),
1656 "numbers and number-like scalars"
1662 # re::regexp_pattern was moved to universal.c in v5.10.0-252-g192c1e2
1663 # and apparently backported to maint-5.10
1664 $WANT = $] > 5.010 ? <<'NEW' : <<'OLD';
1668 #$VAR1 = qr/(?-xism:abc)/;
1669 #$VAR2 = qr/(?i-xsm:abc)/;
1671 TEST q(Data::Dumper->Dump([ qr/abc/, qr/abc/i ])), "qr//";
1672 TEST q(Data::Dumper->Dumpxs([ qr/abc/, qr/abc/i ])), "qr// xs"
1680 #*a = sub { "DUMMY" };
1684 TEST q(Data::Dumper->new([ \&foo, \\&foo ], [ "*a", "b" ])->Dump), "name of code in *foo";
1685 TEST q(Data::Dumper->new([ \&foo, \\&foo ], [ "*a", "b" ])->Dumpxs), "name of code in *foo xs"