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\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\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";
80 # Force Data::Dumper::Dump to use perl. We test Dumpxs explicitly by calling
81 # it direct. Out here it lets us knobble the next if to test that the perl
82 # only tests do work (and count correctly)
83 $Data::Dumper::Useperl = 1;
84 if (defined &Data::Dumper::Dumpxs) {
85 print "### XS extension loaded, will run XS tests\n";
89 print "### XS extensions not loaded, will NOT run XS tests\n";
125 TEST (q(Data::Dumper->Dump([$a,$b,$c], [qw(a b), 6])),
126 'basic test with names: Dump()');
127 TEST (q(Data::Dumper->Dumpxs([$a,$b,$c], [qw(a b), 6])),
128 'basic test with names: Dumpxs()')
132 local $Data::Dumper::Sparseseen = 1;
133 TEST (q(Data::Dumper->Dump([$a,$b,$c], [qw(a b), 6])),
134 'Sparseseen with names: Dump()');
135 TEST (q(Data::Dumper->Dumpxs([$a,$b,$c], [qw(a b), 6])),
136 'Sparseseen with names: Dumpxs()')
161 $Data::Dumper::Purity = 1; # fill in the holes for eval
162 TEST (q(Data::Dumper->Dump([$a, $b], [qw(*a b)])),
163 'Purity: basic test with dereferenced array: Dump()'); # print as @a
164 TEST (q(Data::Dumper->Dumpxs([$a, $b], [qw(*a b)])),
165 'Purity: basic test with dereferenced array: Dumpxs()')
169 local $Data::Dumper::Sparseseen = 1;
170 TEST (q(Data::Dumper->Dump([$a, $b], [qw(*a b)])),
171 'Purity: Sparseseen with dereferenced array: Dump()'); # print as @a
172 TEST (q(Data::Dumper->Dumpxs([$a, $b], [qw(*a b)])),
173 'Purity: Sparseseen with dereferenced array: Dumpxs()')
193 #$b{'c'} = $b{'a'}[2];
197 TEST (q(Data::Dumper->Dump([$b, $a], [qw(*b a)])),
198 'basic test with dereferenced hash: Dump()'); # print as %b
199 TEST (q(Data::Dumper->Dumpxs([$b, $a], [qw(*b a)])),
200 'basic test with dereferenced hash: Dumpxs()')
216 #$a->[1]{'b'} = $a->[1];
222 $Data::Dumper::Indent = 1;
224 $d = Data::Dumper->new([$a,$b], [qw(a b)]);
225 $d->Seen({'*c' => $c});
228 'Indent: Seen: Dump()');
231 $d = Data::Dumper->new([$a,$b], [qw(a b)]);
232 $d->Seen({'*c' => $c});
235 'Indent: Seen: Dumpxs()');
261 $d->Purity(0)->Quotekeys(0);
262 TEST (q( $d->Reset; $d->Dump ),
263 'Indent(3): Purity(0)->Quotekeys(0): Dump()');
265 TEST (q( $d->Reset; $d->Dumpxs ),
266 'Indent(3): Purity(0)->Quotekeys(0): Dumpxs()')
283 #$VAR1->[1]{'a'} = $VAR1;
284 #$VAR1->[1]{'b'} = $VAR1->[1];
285 #$VAR1->[2] = $VAR1->[1]{'c'};
288 TEST (q(Dumper($a)), 'Dumper');
289 TEST (q(Data::Dumper::DumperX($a)), 'DumperX') if $XS;
308 local $Data::Dumper::Purity = 0;
309 local $Data::Dumper::Quotekeys = 0;
310 local $Data::Dumper::Terse = 1;
312 'Purity 0: Quotekeys 0: Terse 1: Dumper');
313 TEST (q(Data::Dumper::DumperX($a)),
314 'Purity 0: Quotekeys 0: Terse 1: DumperX')
323 # "abc\0'\efg" => "mno\0",
328 $foo = { "abc\000\'\efg" => "mno\000",
332 local $Data::Dumper::Useqq = 1;
333 TEST (q(Dumper($foo)), 'Useqq: Dumper');
334 TEST (q(Data::Dumper::DumperX($foo)), 'Useqq: DumperX') if $XS;
347 %foo = (a=>1,b=>\$foo,c=>\@foo);
369 #*::foo{ARRAY}->[1] = $foo;
370 #*::foo{ARRAY}->[2]{'b'} = *::foo{SCALAR};
371 #*::foo{ARRAY}->[2]{'c'} = *::foo{ARRAY};
372 #*::foo{ARRAY}->[2]{'d'} = *::foo{ARRAY}->[2];
373 #*::foo = *::foo{ARRAY}->[2];
374 #@bar = @{*::foo{ARRAY}};
375 #%baz = %{*::foo{ARRAY}->[2]};
378 $Data::Dumper::Purity = 1;
379 $Data::Dumper::Indent = 3;
380 TEST (q(Data::Dumper->Dump([\\*foo, \\@foo, \\%foo], ['*foo', '*bar', '*baz'])),
381 'Purity 1: Indent 3: Dump()');
382 TEST (q(Data::Dumper->Dumpxs([\\*foo, \\@foo, \\%foo], ['*foo', '*bar', '*baz'])),
383 'Purity 1: Indent 3: Dumpxs()')
401 #*::foo{ARRAY}->[1] = $foo;
402 #*::foo{ARRAY}->[2]{'b'} = *::foo{SCALAR};
403 #*::foo{ARRAY}->[2]{'c'} = *::foo{ARRAY};
404 #*::foo{ARRAY}->[2]{'d'} = *::foo{ARRAY}->[2];
405 #*::foo = *::foo{ARRAY}->[2];
406 #$bar = *::foo{ARRAY};
407 #$baz = *::foo{ARRAY}->[2];
410 $Data::Dumper::Indent = 1;
411 TEST (q(Data::Dumper->Dump([\\*foo, \\@foo, \\%foo], ['foo', 'bar', 'baz'])),
412 'Purity 1: Indent 1: Dump()');
413 TEST (q(Data::Dumper->Dumpxs([\\*foo, \\@foo, \\%foo], ['foo', 'bar', 'baz'])),
414 'Purity 1: Indent 1: Dumpxs()')
433 #*::foo{HASH}->{'b'} = *::foo{SCALAR};
434 #*::foo{HASH}->{'c'} = \@bar;
435 #*::foo{HASH}->{'d'} = *::foo{HASH};
436 #$bar[2] = *::foo{HASH};
437 #%baz = %{*::foo{HASH}};
441 TEST (q(Data::Dumper->Dump([\\@foo, \\%foo, \\*foo], ['*bar', '*baz', '*foo'])),
442 'array|hash|glob dereferenced: Dump()');
443 TEST (q(Data::Dumper->Dumpxs([\\@foo, \\%foo, \\*foo], ['*bar', '*baz', '*foo'])),
444 'array|hash|glob dereferenced: Dumpxs()')
463 #*::foo{HASH}->{'b'} = *::foo{SCALAR};
464 #*::foo{HASH}->{'c'} = $bar;
465 #*::foo{HASH}->{'d'} = *::foo{HASH};
466 #$bar->[2] = *::foo{HASH};
467 #$baz = *::foo{HASH};
471 TEST (q(Data::Dumper->Dump([\\@foo, \\%foo, \\*foo], ['bar', 'baz', 'foo'])),
472 'array|hash|glob: not dereferenced: Dump()');
473 TEST (q(Data::Dumper->Dumpxs([\\@foo, \\%foo, \\*foo], ['bar', 'baz', 'foo'])),
474 'array|hash|glob: not dereferenced: Dumpxs()')
494 $Data::Dumper::Purity = 0;
495 $Data::Dumper::Quotekeys = 0;
496 TEST (q(Data::Dumper->Dump([\\*foo, \\@foo, \\%foo], ['*foo', '*bar', '*baz'])),
497 'Purity 0: Quotekeys 0: dereferenced: Dump()');
498 TEST (q(Data::Dumper->Dumpxs([\\*foo, \\@foo, \\%foo], ['*foo', '*bar', '*baz'])),
499 'Purity 0: Quotekeys 0: dereferenced: Dumpxs')
519 TEST (q(Data::Dumper->Dump([\\*foo, \\@foo, \\%foo], ['foo', 'bar', 'baz'])),
520 'Purity 0: Quotekeys 0: not dereferenced: Dump()');
521 TEST (q(Data::Dumper->Dumpxs([\\*foo, \\@foo, \\%foo], ['foo', 'bar', 'baz'])),
522 'Purity 0: Quotekeys 0: not dereferenced: Dumpxs()')
531 @dogs = ( 'Fido', 'Wags' );
538 $mutts = $mutts; # avoid warning
548 # ${$kennels{First}},
549 # ${$kennels{Second}},
556 $d = Data::Dumper->new([\\%kennel, \\@dogs, $mutts],
557 [qw(*kennels *dogs *mutts)] );
560 'constructor: hash|array|scalar: Dump()');
563 $d = Data::Dumper->new([\\%kennel, \\@dogs, $mutts],
564 [qw(*kennels *dogs *mutts)] );
567 'constructor: hash|array|scalar: Dumpxs()');
573 #%kennels = %kennels;
578 TEST q($d->Dump), 'object call: Dump';
579 TEST q($d->Dumpxs), 'object call: Dumpxs' if $XS;
589 # ${$kennels{First}},
590 # ${$kennels{Second}},
596 TEST q($d->Reset; $d->Dump), 'Reset and Dump separate calls';
598 TEST (q($d->Reset; $d->Dumpxs), 'Reset and Dumpxs separate calls');
608 # First => \$dogs[0],
609 # Second => \$dogs[1]
612 #%kennels = %{$dogs[2]};
613 #%mutts = %{$dogs[2]};
617 $d = Data::Dumper->new([\\@dogs, \\%kennel, $mutts],
618 [qw(*dogs *kennels *mutts)] );
621 'constructor: array|hash|scalar: Dump()');
624 $d = Data::Dumper->new([\\@dogs, \\%kennel, $mutts],
625 [qw(*dogs *kennels *mutts)] );
628 'constructor: array|hash|scalar: Dumpxs()');
633 TEST q($d->Reset->Dump), 'Reset Dump chained';
635 TEST q($d->Reset->Dumpxs), 'Reset Dumpxs chained';
656 $d = Data::Dumper->new( [\@dogs, \%kennel], [qw(*dogs *kennels)] );
657 $d->Deepcopy(1)->Dump;
659 'Deepcopy(1): Dump');
661 # TEST 'q($d->Reset->Dumpxs);
663 $d = Data::Dumper->new( [\@dogs, \%kennel], [qw(*dogs *kennels)] );
664 $d->Deepcopy(1)->Dumpxs;
666 'Deepcopy(1): Dumpxs');
673 sub z { print "foo\n" }
685 TEST (q(Data::Dumper->new([\&z,$c],['a','c'])->Seen({'b' => \&z})->Dump;),
686 'Seen: scalar: Dump');
687 TEST (q(Data::Dumper->new([\&z,$c],['a','c'])->Seen({'b' => \&z})->Dumpxs;),
688 'Seen: scalar: Dumpxs')
700 TEST (q(Data::Dumper->new([\&z,$c],['a','c'])->Seen({'*b' => \&z})->Dump;),
702 TEST (q(Data::Dumper->new([\&z,$c],['a','c'])->Seen({'*b' => \&z})->Dumpxs;),
703 'Seen: glob: Dumpxs')
715 TEST (q(Data::Dumper->new([\&z,$c],['*a','*c'])->Seen({'*b' => \&z})->Dump;),
716 'Seen: glob: dereference: Dump');
717 TEST (q(Data::Dumper->new([\&z,$c],['*a','*c'])->Seen({'*b' =>
719 'Seen: glob: derference: Dumpxs')
738 TEST (q(Data::Dumper->new([$a],['*a'])->Purity(1)->Dump;),
739 'Purity(1): dereference: Dump');
740 TEST (q(Data::Dumper->new([$a],['*a'])->Purity(1)->Dumpxs;),
741 'Purity(1): dereference: Dumpxs')
756 TEST (q(Data::Dumper->new([$a,$b],['a','b'])->Purity(1)->Dump;),
757 'Purity(1): not dereferenced: Dump');
758 TEST (q(Data::Dumper->new([$a,$b],['a','b'])->Purity(1)->Dumpxs;),
759 'Purity(1): not dereferenced: Dumpxs')
764 $a = [{ a => \$b }, { b => undef }];
765 $b = [{ c => \$b }, { d => \$a }];
785 #${$a->[0]{a}}->[0]->{c} = $a->[0]{a};
786 #${${$a->[0]{a}}->[1]->{d}} = $a;
790 TEST (q(Data::Dumper->new([$a,$b],['a','b'])->Purity(1)->Dump;),
791 'Purity(1): Dump again');
792 TEST (q(Data::Dumper->new([$a,$b],['a','b'])->Purity(1)->Dumpxs;),
793 'Purity(1); Dumpxs again')
798 $a = [[[[\\\\\'foo']]]];
815 #$c = ${${$a->[0][0][0][0]}};
818 TEST (q(Data::Dumper->new([$a,$b,$c],['a','b','c'])->Purity(1)->Dump;),
819 'Purity(1): Dump: 3 elements');
820 TEST (q(Data::Dumper->new([$a,$b,$c],['a','b','c'])->Purity(1)->Dumpxs;),
821 'Purity(1): Dumpxs: 3 elements')
840 # e => 'ARRAY(0xdeadbeef)'
849 TEST (q(Data::Dumper->new([$a,$b,$c],['a','b','c'])->Maxdepth(4)->Dump;),
850 'Maxdepth(4): Dump()');
851 TEST (q(Data::Dumper->new([$a,$b,$c],['a','b','c'])->Maxdepth(4)->Dumpxs;),
852 'Maxdepth(4): Dumpxs()')
859 # b => 'HASH(0xdeadbeef)'
867 TEST (q(Data::Dumper->new([$a,$b,$c],['a','b','c'])->Maxdepth(1)->Dump;),
868 'Maxdepth(1): Dump()');
869 TEST (q(Data::Dumper->new([$a,$b,$c],['a','b','c'])->Maxdepth(1)->Dumpxs;),
870 'Maxdepth(1): Dumpxs()')
886 TEST (q(Data::Dumper->new([$b],['b'])->Purity(0)->Dump;),
887 'Purity(0): Dump()');
888 TEST (q(Data::Dumper->new([$b],['b'])->Purity(0)->Dumpxs;),
889 'Purity(0): Dumpxs()')
898 #${$b->[0]} = $b->[0];
902 TEST (q(Data::Dumper->new([$b],['b'])->Purity(1)->Dump;),
903 'Purity(1): Dump()');
904 TEST (q(Data::Dumper->new([$b],['b'])->Purity(1)->Dumpxs;),
912 ## XS code was adding an extra \0
918 TEST q(Data::Dumper->Dump([$a], ['a'])), "\\x{9c10}";
920 SKIP_TEST "Incomplete support for UTF-8 in old perls";
922 TEST q(Data::Dumper->Dumpxs([$a], ['a'])), "XS \\x{9c10}"
928 $a = { map { ("$_$_$_", ++$i) } 'I'..'Q' };
946 TEST (q(Data::Dumper->new([$a])->Dump;),
947 'basic test without names: Dump()');
948 TEST (q(Data::Dumper->new([$a])->Dumpxs;),
949 'basic test without names: Dumpxs()')
955 $c = { map { (++$i, "$_$_$_") } 'I'..'Q' };
956 local $Data::Dumper::Sortkeys = \&sort199;
959 return [ sort { $b <=> $a } keys %$hash ];
978 TEST q(Data::Dumper->new([$c])->Dump;), "sortkeys sub";
979 TEST q(Data::Dumper->new([$c])->Dumpxs;), "sortkeys sub (XS)"
985 $c = { map { (++$i, "$_$_$_") } 'I'..'Q' };
986 $d = { reverse %$c };
987 local $Data::Dumper::Sortkeys = \&sort205;
991 $hash eq $c ? (sort { $a <=> $b } keys %$hash)
992 : (reverse sort keys %$hash)
1025 TEST q(Data::Dumper->new([[$c, $d]])->Dump;), "more sortkeys sub";
1026 # the XS code does number values as strings
1027 $WANT =~ s/ (\d+)(,?)$/ '$1'$2/gm;
1028 TEST q(Data::Dumper->new([[$c, $d]])->Dumpxs;), "more sortkeys sub (XS)"
1033 local $Data::Dumper::Deparse = 1;
1034 local $Data::Dumper::Indent = 2;
1046 if(" $Config{'extensions'} " !~ m[ B ]) {
1047 SKIP_TEST "Perl configured without B module";
1049 TEST (q(Data::Dumper->new([{ foo => sub { print "foo"; } }])->Dump),
1050 'Deparse 1: Indent 2; Dump()');
1058 # The controls (bare numbers) are stored either as integers or floating point.
1059 # [depending on whether the tokeniser sees things like ".".
1060 # The peephole optimiser only runs for constant folding, not single constants,
1061 # so I already have some NVs, some IVs
1062 # The string versions are not. They are all PV
1064 # This is arguably all far too chummy with the implementation, but I really
1065 # want to ensure that we don't go wrong when flags on scalars get as side
1066 # effects of reading them.
1068 # These tests are actually testing the precise output of the current
1069 # implementation, so will most likely fail if the implementation changes,
1070 # even if the new implementation produces different but correct results.
1071 # It would be nice to test for wrong answers, but I can't see how to do that,
1072 # so instead I'm checking for unexpected answers. (ie -2 becoming "-2" is not
1073 # wrong, but I can't see an easy, reliable way to code that knowledge)
1075 # Numbers (seen by the tokeniser as numbers, stored as numbers.
1078 0, +1, -2, 3.0, +4.0, -5.0, 6.5, +7.5, -8.5,
1079 9, +10, -11, 12.0, +13.0, -14.0, 15.5, +16.25, -17.75,
1084 "0", "+1", "-2", "3.0", "+4.0", "-5.0", "6.5", "+7.5", "-8.5", " 9",
1085 " +10", " -11", " 12.0", " +13.0", " -14.0", " 15.5", " +16.25", " -17.75",
1088 # The perl code always does things the same way for numbers.
1089 $WANT_PL_N = <<'EOT';
1109 # The perl code knows that 0 and -2 stringify exactly back to the strings,
1110 # so it dumps them as numbers, not strings.
1111 $WANT_PL_S = <<'EOT';
1128 #$VAR17 = ' +16.25';
1129 #$VAR18 = ' -17.75';
1132 # The XS code differs.
1133 # These are the numbers as seen by the tokeniser. Constants aren't folded
1134 # (which makes IVs where possible) so values the tokeniser thought were
1135 # floating point are stored as NVs. The XS code outputs these as strings,
1136 # but as it has converted them from NVs, leading + signs will not be there.
1137 $WANT_XS_N = <<'EOT';
1158 # These are the strings as seen by the tokeniser. The XS code will output
1159 # these for all cases except where the scalar has been used in integer context
1160 $WANT_XS_S = <<'EOT';
1177 #$VAR17 = ' +16.25';
1178 #$VAR18 = ' -17.75';
1181 # These are the numbers as IV-ized by &
1182 # These will differ from WANT_XS_N because now IV flags will be set on all
1183 # values that were actually integer, and the XS code will then output these
1184 # as numbers not strings.
1185 $WANT_XS_I = <<'EOT';
1206 # Some of these tests will be redundant.
1207 @numbers_s = @numbers_i = @numbers_is = @numbers_n = @numbers_ns = @numbers_ni
1208 = @numbers_nis = @numbers;
1209 @strings_s = @strings_i = @strings_is = @strings_n = @strings_ns = @strings_ni
1210 = @strings_nis = @strings;
1211 # Use them in an integer context
1212 foreach (@numbers_i, @numbers_ni, @numbers_nis, @numbers_is,
1213 @strings_i, @strings_ni, @strings_nis, @strings_is) {
1214 my $b = sprintf "%d", $_;
1216 # Use them in a floating point context
1217 foreach (@numbers_n, @numbers_ni, @numbers_nis, @numbers_ns,
1218 @strings_n, @strings_ni, @strings_nis, @strings_ns) {
1219 my $b = sprintf "%e", $_;
1221 # Use them in a string context
1222 foreach (@numbers_s, @numbers_is, @numbers_nis, @numbers_ns,
1223 @strings_s, @strings_is, @strings_nis, @strings_ns) {
1224 my $b = sprintf "%s", $_;
1227 # use Devel::Peek; Dump ($_) foreach @vanilla_c;
1230 TEST q(Data::Dumper->new(\@numbers)->Dump), 'Numbers';
1231 TEST q(Data::Dumper->new(\@numbers_s)->Dump), 'Numbers PV';
1232 TEST q(Data::Dumper->new(\@numbers_i)->Dump), 'Numbers IV';
1233 TEST q(Data::Dumper->new(\@numbers_is)->Dump), 'Numbers IV,PV';
1234 TEST q(Data::Dumper->new(\@numbers_n)->Dump), 'Numbers NV';
1235 TEST q(Data::Dumper->new(\@numbers_ns)->Dump), 'Numbers NV,PV';
1236 TEST q(Data::Dumper->new(\@numbers_ni)->Dump), 'Numbers NV,IV';
1237 TEST q(Data::Dumper->new(\@numbers_nis)->Dump), 'Numbers NV,IV,PV';
1239 TEST q(Data::Dumper->new(\@strings)->Dump), 'Strings';
1240 TEST q(Data::Dumper->new(\@strings_s)->Dump), 'Strings PV';
1241 TEST q(Data::Dumper->new(\@strings_i)->Dump), 'Strings IV';
1242 TEST q(Data::Dumper->new(\@strings_is)->Dump), 'Strings IV,PV';
1243 TEST q(Data::Dumper->new(\@strings_n)->Dump), 'Strings NV';
1244 TEST q(Data::Dumper->new(\@strings_ns)->Dump), 'Strings NV,PV';
1245 TEST q(Data::Dumper->new(\@strings_ni)->Dump), 'Strings NV,IV';
1246 TEST q(Data::Dumper->new(\@strings_nis)->Dump), 'Strings NV,IV,PV';
1248 my $nv_preserves_uv = defined $Config{d_nv_preserves_uv};
1249 my $nv_preserves_uv_4bits = exists($Config{nv_preserves_uv_bits}) && $Config{nv_preserves_uv_bits} >= 4;
1251 TEST q(Data::Dumper->new(\@numbers)->Dumpxs), 'XS Numbers';
1252 TEST q(Data::Dumper->new(\@numbers_s)->Dumpxs), 'XS Numbers PV';
1253 if ($nv_preserves_uv || $nv_preserves_uv_4bits) {
1255 TEST q(Data::Dumper->new(\@numbers_i)->Dumpxs), 'XS Numbers IV';
1256 TEST q(Data::Dumper->new(\@numbers_is)->Dumpxs), 'XS Numbers IV,PV';
1258 SKIP_TEST "NV does not preserve 4bits";
1259 SKIP_TEST "NV does not preserve 4bits";
1262 TEST q(Data::Dumper->new(\@numbers_n)->Dumpxs), 'XS Numbers NV';
1263 TEST q(Data::Dumper->new(\@numbers_ns)->Dumpxs), 'XS Numbers NV,PV';
1264 if ($nv_preserves_uv || $nv_preserves_uv_4bits) {
1266 TEST q(Data::Dumper->new(\@numbers_ni)->Dumpxs), 'XS Numbers NV,IV';
1267 TEST q(Data::Dumper->new(\@numbers_nis)->Dumpxs), 'XS Numbers NV,IV,PV';
1269 SKIP_TEST "NV does not preserve 4bits";
1270 SKIP_TEST "NV does not preserve 4bits";
1274 TEST q(Data::Dumper->new(\@strings)->Dumpxs), 'XS Strings';
1275 TEST q(Data::Dumper->new(\@strings_s)->Dumpxs), 'XS Strings PV';
1276 # This one used to really mess up. New code actually emulates the .pm code
1278 TEST q(Data::Dumper->new(\@strings_i)->Dumpxs), 'XS Strings IV';
1279 TEST q(Data::Dumper->new(\@strings_is)->Dumpxs), 'XS Strings IV,PV';
1280 if ($nv_preserves_uv || $nv_preserves_uv_4bits) {
1282 TEST q(Data::Dumper->new(\@strings_n)->Dumpxs), 'XS Strings NV';
1283 TEST q(Data::Dumper->new(\@strings_ns)->Dumpxs), 'XS Strings NV,PV';
1285 SKIP_TEST "NV does not preserve 4bits";
1286 SKIP_TEST "NV does not preserve 4bits";
1288 # This one used to really mess up. New code actually emulates the .pm code
1290 TEST q(Data::Dumper->new(\@strings_ni)->Dumpxs), 'XS Strings NV,IV';
1291 TEST q(Data::Dumper->new(\@strings_nis)->Dumpxs), 'XS Strings NV,IV,PV';
1297 ## Perl code was using /...$/ and hence missing the \n.
1303 # Can't pad with # as the output has an embedded newline.
1304 local $Data::Dumper::Pad = "my ";
1305 TEST q(Data::Dumper->Dump(["42\n"])), "number with trailing newline";
1306 TEST q(Data::Dumper->Dumpxs(["42\n"])), "XS number with trailing newline"
1326 ## Perl code flips over at 10 digits.
1329 #$VAR2 = '1000000000';
1330 #$VAR3 = '9999999999';
1331 #$VAR4 = '10000000000';
1332 #$VAR5 = -999999999;
1333 #$VAR6 = '-1000000000';
1334 #$VAR7 = '-9999999999';
1335 #$VAR8 = '-10000000000';
1336 #$VAR9 = '4294967295';
1337 #$VAR10 = '4294967296';
1338 #$VAR11 = '-2147483648';
1339 #$VAR12 = '-2147483649';
1342 TEST q(Data::Dumper->Dump(\@a)), "long integers";
1345 ## XS code flips over at 11 characters ("-" is a char) or larger than int.
1346 if (~0 == 0xFFFFFFFF) {
1350 #$VAR2 = 1000000000;
1351 #$VAR3 = '9999999999';
1352 #$VAR4 = '10000000000';
1353 #$VAR5 = -999999999;
1354 #$VAR6 = '-1000000000';
1355 #$VAR7 = '-9999999999';
1356 #$VAR8 = '-10000000000';
1357 #$VAR9 = 4294967295;
1358 #$VAR10 = '4294967296';
1359 #$VAR11 = '-2147483648';
1360 #$VAR12 = '-2147483649';
1365 #$VAR2 = 1000000000;
1366 #$VAR3 = 9999999999;
1367 #$VAR4 = '10000000000';
1368 #$VAR5 = -999999999;
1369 #$VAR6 = '-1000000000';
1370 #$VAR7 = '-9999999999';
1371 #$VAR8 = '-10000000000';
1372 #$VAR9 = 4294967295;
1373 #$VAR10 = 4294967296;
1374 #$VAR11 = '-2147483648';
1375 #$VAR12 = '-2147483649';
1378 TEST q(Data::Dumper->Dumpxs(\@a)), "XS long integers";
1385 $b = "Bad. XS didn't escape dollar sign";
1387 $WANT = <<"EOT"; # Careful. This is '' string written inside "" here doc
1388 #\$VAR1 = '\$b\"\@\\\\\xB1';
1390 $a = "\$b\"\@\\\xB1\x{100}";
1392 TEST q(Data::Dumper->Dump([$a])), "utf8 flag with \" and \$";
1394 $WANT = <<'EOT'; # While this is "" string written inside "" here doc
1395 #$VAR1 = "\$b\"\@\\\x{b1}";
1397 TEST q(Data::Dumper->Dumpxs([$a])), "XS utf8 flag with \" and \$";
1400 $b = "Bad. XS didn't escape dollar sign";
1402 $WANT = <<"EOT"; # Careful. This is '' string written inside "" here doc
1403 #\$VAR1 = '\$b\"\@\\\\\xA3';
1406 $a = "\$b\"\@\\\xA3\x{100}";
1408 TEST q(Data::Dumper->Dump([$a])), "utf8 flag with \" and \$";
1410 $WANT = <<'EOT'; # While this is "" string written inside "" here doc
1411 #$VAR1 = "\$b\"\@\\\x{a3}";
1413 TEST q(Data::Dumper->Dumpxs([$a])), "XS utf8 flag with \" and \$";
1416 # XS used to produce "$b\"' which is 4 chars, not 3. [ie wrongly qq(\$b\\\")]
1422 $a = "\$b\"\x{100}";
1424 TEST q(Data::Dumper->Dump([$a])), "utf8 flag with \" and \$";
1426 TEST q(Data::Dumper->Dumpxs([$a])), "XS utf8 flag with \" and \$";
1430 # XS used to produce 'D'oh!' which is well, D'oh!
1431 # Andreas found this one, which in turn discovered the previous two.
1437 $a = "D'oh!\x{100}";
1439 TEST q(Data::Dumper->Dump([$a])), "utf8 flag with '";
1441 TEST q(Data::Dumper->Dumpxs([$a])), "XS utf8 flag with '";
1445 # Jarkko found that -Mutf8 caused some tests to fail. Turns out that there
1446 # was an otherwise untested code path in the XS for utf8 hash keys with purity
1454 # "\x{decaf}\x{decaf}\x{decaf}\x{decaf}" => do{my $o}
1456 #*::ping{HASH}->{"\x{decaf}\x{decaf}\x{decaf}\x{decaf}"} = *::ping{SCALAR};
1457 #%pong = %{*::ping{HASH}};
1459 local $Data::Dumper::Purity = 1;
1460 local $Data::Dumper::Sortkeys;
1462 %ping = (chr (0xDECAF) x 4 =>\$ping);
1463 for $Data::Dumper::Sortkeys (0, 1) {
1465 TEST (q(Data::Dumper->Dump([\\*ping, \\%ping], ['*ping', '*pong'])),
1466 "utf8: Purity 1: Sortkeys: Dump()");
1467 TEST (q(Data::Dumper->Dumpxs([\\*ping, \\%ping], ['*ping', '*pong'])),
1468 "utf8: Purity 1: Sortkeys: Dumpxs()")
1471 SKIP_TEST "Incomplete support for UTF-8 in old perls";
1472 SKIP_TEST "Incomplete support for UTF-8 in old perls";
1477 # XS for quotekeys==0 was not being defensive enough against utf8 flagged
1486 local $Data::Dumper::Quotekeys = 0;
1487 my $k = 'perl' . chr 256;
1489 %foo = ($k => 'rocks');
1491 TEST q(Data::Dumper->Dump([\\%foo])), "quotekeys == 0 for utf8 flagged ASCII";
1492 TEST q(Data::Dumper->Dumpxs([\\%foo])),
1493 "XS quotekeys == 0 for utf8 flagged ASCII" if $XS;
1506 TEST q(Data::Dumper->Dump([\@foo])), 'Richard Clamp, Message-Id: <20030104005247.GA27685@mirth.demon.co.uk>: Dump()';
1507 TEST q(Data::Dumper->Dumpxs([\@foo])), 'Richard Clamp, Message-Id: <20030104005247.GA27685@mirth.demon.co.uk>: Dumpxs()'if $XS;
1511 # Make sure $obj->Dumpxs returns the right thing in list context. This was
1512 # broken by the initial attempt to fix [perl #74170].
1516 TEST q(join " ", new Data::Dumper [[]],[] =>->Dumpxs),
1517 '$obj->Dumpxs in list context'
1524 # "\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"
1528 $foo = [ join "", map chr, 0..255 ];
1529 local $Data::Dumper::Useqq = 1;
1530 TEST (q(Dumper($foo)), 'All latin1 characters: Dumper');
1531 TEST (q(Data::Dumper::DumperX($foo)), 'All latin1 characters: DumperX') if $XS;
1538 # "\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}"
1542 $foo = [ join "", map chr, 0..255, 0x20ac ];
1543 local $Data::Dumper::Useqq = 1;
1545 print "not ok " . (++$TNUM) . " # TODO - fails under 5.6\n" for 1..3;
1548 TEST q(Dumper($foo)),
1549 'All latin1 characters with utf8 flag including a wide character: Dumper';
1551 TEST (q(Data::Dumper::DumperX($foo)),
1552 'All latin1 characters with utf8 flag including a wide character: DumperX')
1558 # If XS cannot load, the pure-Perl version cannot deparse vstrings with
1559 # underscores properly. In 5.8.0, vstrings are just strings.
1560 my $no_vstrings = <<'NOVSTRINGS';
1566 my $vstrings_corr = <<'VSTRINGS_CORRECT';
1572 $WANT = $] <= 5.0080001
1578 \($] < 5.007 ? v65.66.67 : eval 'v65.66.067'),
1583 TEST q(Data::Dumper->Dump(\@::_v, [qw(a b c d)])), 'vstrings';
1584 TEST q(Data::Dumper->Dumpxs(\@::_v, [qw(a b c d)])), 'xs vstrings'
1587 else { # Skip tests before 5.10. vstrings considered funny before
1588 SKIP_TEST "vstrings considered funny before 5.10.0";
1589 SKIP_TEST "vstrings considered funny before 5.10.0 (XS)"
1596 # [perl #107372] blessed overloaded globs
1598 #$VAR1 = bless( \*::finkle, 'overtest' );
1602 use overload fallback=>1, q\""\=>sub{"oaoaa"};
1604 TEST q(Data::Dumper->Dump([bless \*finkle, "overtest"])),
1605 'blessed overloaded globs';
1606 TEST q(Data::Dumper->Dumpxs([\*finkle])), 'blessed overloaded globs (xs)'
1611 # [perl #74798] uncovered behaviour
1615 local $Data::Dumper::Useqq = 1;
1616 TEST q(Data::Dumper->Dump(["\x000"])),
1617 "\\ octal followed by digit";
1618 TEST q(Data::Dumper->Dumpxs(["\x000"])), '\\ octal followed by digit (xs)'
1622 #$VAR1 = "\x{100}\0000";
1624 local $Data::Dumper::Useqq = 1;
1625 TEST q(Data::Dumper->Dump(["\x{100}\x000"])),
1626 "\\ octal followed by digit unicode";
1627 TEST q(Data::Dumper->Dumpxs(["\x{100}\x000"])), '\\ octal followed by digit unicode (xs)'
1632 #$VAR1 = "\0\x{660}";
1634 TEST q(Data::Dumper->Dump(["\\x00\\x{0660}"])),
1635 "\\ octal followed by unicode digit";
1636 TEST q(Data::Dumper->Dumpxs(["\\x00\\x{0660}"])), '\\ octal followed by unicode digit (xs)'
1639 # [perl #118933 - handling of digits
1647 #$VAR7 = "1234567890";
1649 TEST q(Data::Dumper->Dump([0, 1, 90, -10, "010", "112345678", "1234567890" ])),
1650 "numbers and number-like scalars";
1652 TEST q(Data::Dumper->Dumpxs([0, 1, 90, -10, "010", "112345678", "1234567890" ])),
1653 "numbers and number-like scalars"
1659 # re::regexp_pattern was moved to universal.c in v5.10.0-252-g192c1e2
1660 # and apparently backported to maint-5.10
1661 $WANT = $] > 5.010 ? <<'NEW' : <<'OLD';
1665 #$VAR1 = qr/(?-xism:abc)/;
1666 #$VAR2 = qr/(?i-xsm:abc)/;
1668 TEST q(Data::Dumper->Dump([ qr/abc/, qr/abc/i ])), "qr//";
1669 TEST q(Data::Dumper->Dumpxs([ qr/abc/, qr/abc/i ])), "qr// xs"
1677 #*a = sub { "DUMMY" };
1681 TEST q(Data::Dumper->new([ \&foo, \\&foo ], [ "*a", "b" ])->Dump), "name of code in *foo";
1682 TEST q(Data::Dumper->new([ \&foo, \\&foo ], [ "*a", "b" ])->Dumpxs), "name of code in *foo xs"