3 # testsuite for Data::Dumper
10 require Config; import Config;
11 if ($Config{'extensions'} !~ /\bData\/Dumper\b/) {
12 print "1..0 # Skip: Data::Dumper was not built\n";
18 # Since Perl 5.8.1 because otherwise hash ordering is really random.
19 local $Data::Dumper::Sortkeys = 1;
23 my $Is_ebcdic = defined($Config{'ebcdic'}) && $Config{'ebcdic'} eq 'define';
25 $Data::Dumper::Pad = "#";
36 $t =~ s/([A-Z]+)\(0x[0-9a-f]+\)/$1(0xdeadbeef)/g
37 if ($WANT =~ /deadbeef/);
39 # these data need massaging with non ascii character sets
40 # because of hashing order differences
41 $WANT = join("\n",sort(split(/\n/,$WANT)));
43 $t = join("\n",sort(split(/\n/,$t)));
46 $name = $name ? " - $name" : '';
47 print( ($t eq $WANT and not $@) ? "ok $TNUM$name\n"
48 : "not ok $TNUM$name\n--Expected--\n$WANT\n--Got--\n$@$t\n");
51 if ($Is_ebcdic) { # EBCDIC.
52 if ($TNUM == 311 || $TNUM == 314) {
60 print $@ ? "not ok $TNUM\n# \$@ says: $@\n" : "ok $TNUM\n";
64 $t =~ s/([A-Z]+)\(0x[0-9a-f]+\)/$1(0xdeadbeef)/g
65 if ($WANT =~ /deadbeef/);
67 # here too there are hashing order differences
68 $WANT = join("\n",sort(split(/\n/,$WANT)));
70 $t = join("\n",sort(split(/\n/,$t)));
73 print( ($t eq $WANT and not $@) ? "ok $TNUM\n"
74 : "not ok $TNUM\n--Expected--\n$WANT\n--Got--\n$@$t\n");
79 ++$TNUM; print "ok $TNUM # skip $reason\n";
80 ++$TNUM; print "ok $TNUM # skip $reason\n";
81 ++$TNUM; print "ok $TNUM # skip $reason\n";
84 # Force Data::Dumper::Dump to use perl. We test Dumpxs explicitly by calling
85 # it direct. Out here it lets us knobble the next if to test that the perl
86 # only tests do work (and count correctly)
87 $Data::Dumper::Useperl = 1;
88 if (defined &Data::Dumper::Dumpxs) {
89 print "### XS extension loaded, will run XS tests\n";
93 print "### XS extensions not loaded, will NOT run XS tests\n";
129 TEST q(Data::Dumper->Dump([$a,$b,$c], [qw(a b), 6]));
130 TEST q(Data::Dumper->Dumpxs([$a,$b,$c], [qw(a b), 6])) if $XS;
153 $Data::Dumper::Purity = 1; # fill in the holes for eval
154 TEST q(Data::Dumper->Dump([$a, $b], [qw(*a b)])); # print as @a
155 TEST q(Data::Dumper->Dumpxs([$a, $b], [qw(*a b)])) if $XS;
173 #$b{'c'} = $b{'a'}[2];
177 TEST q(Data::Dumper->Dump([$b, $a], [qw(*b a)])); # print as %b
178 TEST q(Data::Dumper->Dumpxs([$b, $a], [qw(*b a)])) if $XS;
193 #$a->[1]{'b'} = $a->[1];
199 $Data::Dumper::Indent = 1;
201 $d = Data::Dumper->new([$a,$b], [qw(a b)]);
202 $d->Seen({'*c' => $c});
207 $d = Data::Dumper->new([$a,$b], [qw(a b)]);
208 $d->Seen({'*c' => $c});
236 $d->Purity(0)->Quotekeys(0);
237 TEST q( $d->Reset; $d->Dump );
239 TEST q( $d->Reset; $d->Dumpxs ) if $XS;
255 #$VAR1->[1]{'a'} = $VAR1;
256 #$VAR1->[1]{'b'} = $VAR1->[1];
257 #$VAR1->[2] = $VAR1->[1]{'c'};
261 TEST q(Data::Dumper::DumperX($a)) if $XS;
280 local $Data::Dumper::Purity = 0;
281 local $Data::Dumper::Quotekeys = 0;
282 local $Data::Dumper::Terse = 1;
284 TEST q(Data::Dumper::DumperX($a)) if $XS;
292 # "abc\0'\efg" => "mno\0",
297 $foo = { "abc\000\'\efg" => "mno\000",
301 local $Data::Dumper::Useqq = 1;
302 TEST q(Dumper($foo));
307 # 'abc\0\\'\efg' => 'mno\0',
313 local $Data::Dumper::Useqq = 1;
314 TEST q(Data::Dumper::DumperX($foo)) if $XS; # cheat
327 %foo = (a=>1,b=>\$foo,c=>\@foo);
349 #*::foo{ARRAY}->[1] = $foo;
350 #*::foo{ARRAY}->[2]{'b'} = *::foo{SCALAR};
351 #*::foo{ARRAY}->[2]{'c'} = *::foo{ARRAY};
352 #*::foo{ARRAY}->[2]{'d'} = *::foo{ARRAY}->[2];
353 #*::foo = *::foo{ARRAY}->[2];
354 #@bar = @{*::foo{ARRAY}};
355 #%baz = %{*::foo{ARRAY}->[2]};
358 $Data::Dumper::Purity = 1;
359 $Data::Dumper::Indent = 3;
360 TEST q(Data::Dumper->Dump([\\*foo, \\@foo, \\%foo], ['*foo', '*bar', '*baz']));
361 TEST q(Data::Dumper->Dumpxs([\\*foo, \\@foo, \\%foo], ['*foo', '*bar', '*baz'])) if $XS;
378 #*::foo{ARRAY}->[1] = $foo;
379 #*::foo{ARRAY}->[2]{'b'} = *::foo{SCALAR};
380 #*::foo{ARRAY}->[2]{'c'} = *::foo{ARRAY};
381 #*::foo{ARRAY}->[2]{'d'} = *::foo{ARRAY}->[2];
382 #*::foo = *::foo{ARRAY}->[2];
383 #$bar = *::foo{ARRAY};
384 #$baz = *::foo{ARRAY}->[2];
387 $Data::Dumper::Indent = 1;
388 TEST q(Data::Dumper->Dump([\\*foo, \\@foo, \\%foo], ['foo', 'bar', 'baz']));
389 TEST q(Data::Dumper->Dumpxs([\\*foo, \\@foo, \\%foo], ['foo', 'bar', 'baz'])) if $XS;
407 #*::foo{HASH}->{'b'} = *::foo{SCALAR};
408 #*::foo{HASH}->{'c'} = \@bar;
409 #*::foo{HASH}->{'d'} = *::foo{HASH};
410 #$bar[2] = *::foo{HASH};
411 #%baz = %{*::foo{HASH}};
415 TEST q(Data::Dumper->Dump([\\@foo, \\%foo, \\*foo], ['*bar', '*baz', '*foo']));
416 TEST q(Data::Dumper->Dumpxs([\\@foo, \\%foo, \\*foo], ['*bar', '*baz', '*foo'])) if $XS;
434 #*::foo{HASH}->{'b'} = *::foo{SCALAR};
435 #*::foo{HASH}->{'c'} = $bar;
436 #*::foo{HASH}->{'d'} = *::foo{HASH};
437 #$bar->[2] = *::foo{HASH};
438 #$baz = *::foo{HASH};
442 TEST q(Data::Dumper->Dump([\\@foo, \\%foo, \\*foo], ['bar', 'baz', 'foo']));
443 TEST q(Data::Dumper->Dumpxs([\\@foo, \\%foo, \\*foo], ['bar', 'baz', 'foo'])) if $XS;
462 $Data::Dumper::Purity = 0;
463 $Data::Dumper::Quotekeys = 0;
464 TEST q(Data::Dumper->Dump([\\*foo, \\@foo, \\%foo], ['*foo', '*bar', '*baz']));
465 TEST q(Data::Dumper->Dumpxs([\\*foo, \\@foo, \\%foo], ['*foo', '*bar', '*baz'])) if $XS;
484 TEST q(Data::Dumper->Dump([\\*foo, \\@foo, \\%foo], ['foo', 'bar', 'baz']));
485 TEST q(Data::Dumper->Dumpxs([\\*foo, \\@foo, \\%foo], ['foo', 'bar', 'baz'])) if $XS;
493 @dogs = ( 'Fido', 'Wags' );
500 $mutts = $mutts; # avoid warning
510 # ${$kennels{First}},
511 # ${$kennels{Second}},
518 $d = Data::Dumper->new([\\%kennel, \\@dogs, $mutts],
519 [qw(*kennels *dogs *mutts)] );
524 $d = Data::Dumper->new([\\%kennel, \\@dogs, $mutts],
525 [qw(*kennels *dogs *mutts)] );
533 #%kennels = %kennels;
539 TEST q($d->Dumpxs) if $XS;
549 # ${$kennels{First}},
550 # ${$kennels{Second}},
557 TEST q($d->Reset; $d->Dump);
559 TEST q($d->Reset; $d->Dumpxs);
569 # First => \$dogs[0],
570 # Second => \$dogs[1]
573 #%kennels = %{$dogs[2]};
574 #%mutts = %{$dogs[2]};
578 $d = Data::Dumper->new([\\@dogs, \\%kennel, $mutts],
579 [qw(*dogs *kennels *mutts)] );
584 $d = Data::Dumper->new([\\@dogs, \\%kennel, $mutts],
585 [qw(*dogs *kennels *mutts)] );
592 TEST q($d->Reset->Dump);
594 TEST q($d->Reset->Dumpxs);
615 $d = Data::Dumper->new( [\@dogs, \%kennel], [qw(*dogs *kennels)] );
616 $d->Deepcopy(1)->Dump;
619 TEST q($d->Reset->Dumpxs);
626 sub z { print "foo\n" }
638 TEST q(Data::Dumper->new([\&z,$c],['a','c'])->Seen({'b' => \&z})->Dump;);
639 TEST q(Data::Dumper->new([\&z,$c],['a','c'])->Seen({'b' => \&z})->Dumpxs;)
651 TEST q(Data::Dumper->new([\&z,$c],['a','c'])->Seen({'*b' => \&z})->Dump;);
652 TEST q(Data::Dumper->new([\&z,$c],['a','c'])->Seen({'*b' => \&z})->Dumpxs;)
664 TEST q(Data::Dumper->new([\&z,$c],['*a','*c'])->Seen({'*b' => \&z})->Dump;);
665 TEST q(Data::Dumper->new([\&z,$c],['*a','*c'])->Seen({'*b' => \&z})->Dumpxs;)
684 TEST q(Data::Dumper->new([$a],['*a'])->Purity(1)->Dump;);
685 TEST q(Data::Dumper->new([$a],['*a'])->Purity(1)->Dumpxs;)
700 TEST q(Data::Dumper->new([$a,$b],['a','b'])->Purity(1)->Dump;);
701 TEST q(Data::Dumper->new([$a,$b],['a','b'])->Purity(1)->Dumpxs;)
706 $a = [{ a => \$b }, { b => undef }];
707 $b = [{ c => \$b }, { d => \$a }];
727 #${$a->[0]{a}}->[0]->{c} = $a->[0]{a};
728 #${${$a->[0]{a}}->[1]->{d}} = $a;
732 TEST q(Data::Dumper->new([$a,$b],['a','b'])->Purity(1)->Dump;);
733 TEST q(Data::Dumper->new([$a,$b],['a','b'])->Purity(1)->Dumpxs;)
738 $a = [[[[\\\\\'foo']]]];
755 #$c = ${${$a->[0][0][0][0]}};
758 TEST q(Data::Dumper->new([$a,$b,$c],['a','b','c'])->Purity(1)->Dump;);
759 TEST q(Data::Dumper->new([$a,$b,$c],['a','b','c'])->Purity(1)->Dumpxs;)
778 # e => 'ARRAY(0xdeadbeef)'
787 TEST q(Data::Dumper->new([$a,$b,$c],['a','b','c'])->Maxdepth(4)->Dump;);
788 TEST q(Data::Dumper->new([$a,$b,$c],['a','b','c'])->Maxdepth(4)->Dumpxs;)
795 # b => 'HASH(0xdeadbeef)'
803 TEST q(Data::Dumper->new([$a,$b,$c],['a','b','c'])->Maxdepth(1)->Dump;);
804 TEST q(Data::Dumper->new([$a,$b,$c],['a','b','c'])->Maxdepth(1)->Dumpxs;)
820 TEST q(Data::Dumper->new([$b],['b'])->Purity(0)->Dump;);
821 TEST q(Data::Dumper->new([$b],['b'])->Purity(0)->Dumpxs;)
830 #${$b->[0]} = $b->[0];
834 TEST q(Data::Dumper->new([$b],['b'])->Purity(1)->Dump;);
835 TEST q(Data::Dumper->new([$b],['b'])->Purity(1)->Dumpxs;)
842 ## XS code was adding an extra \0
848 TEST q(Data::Dumper->Dump([$a], ['a'])), "\\x{9c10}";
850 SKIP_TEST "Incomplete support for UTF-8 in old perls";
852 TEST q(Data::Dumper->Dumpxs([$a], ['a'])), "XS \\x{9c10}"
858 $a = { map { ("$_$_$_", ++$i) } 'I'..'Q' };
876 TEST q(Data::Dumper->new([$a])->Dump;);
877 TEST q(Data::Dumper->new([$a])->Dumpxs;)
883 $c = { map { (++$i, "$_$_$_") } 'I'..'Q' };
884 local $Data::Dumper::Sortkeys = \&sort199;
887 return [ sort { $b <=> $a } keys %$hash ];
906 # perl code does keys and values as numbers if possible
907 TEST q(Data::Dumper->new([$c])->Dump;);
908 # XS code always does them as strings
909 $WANT =~ s/ (\d+)/ '$1'/gs;
910 TEST q(Data::Dumper->new([$c])->Dumpxs;)
916 $c = { map { (++$i, "$_$_$_") } 'I'..'Q' };
917 $d = { reverse %$c };
918 local $Data::Dumper::Sortkeys = \&sort205;
922 $hash eq $c ? (sort { $a <=> $b } keys %$hash)
923 : (reverse sort keys %$hash)
956 TEST q(Data::Dumper->new([[$c, $d]])->Dump;);
957 $WANT =~ s/ (\d+)/ '$1'/gs;
958 TEST q(Data::Dumper->new([[$c, $d]])->Dumpxs;)
963 local $Data::Dumper::Deparse = 1;
964 local $Data::Dumper::Indent = 2;
976 if(" $Config{'extensions'} " !~ m[ B ]) {
977 SKIP_TEST "Perl configured without B module";
979 TEST q(Data::Dumper->new([{ foo => sub { print "foo"; } }])->Dump);
987 # The controls (bare numbers) are stored either as integers or floating point.
988 # [depending on whether the tokeniser sees things like ".".
989 # The peephole optimiser only runs for constant folding, not single constants,
990 # so I already have some NVs, some IVs
991 # The string versions are not. They are all PV
993 # This is arguably all far too chummy with the implementation, but I really
994 # want to ensure that we don't go wrong when flags on scalars get as side
995 # effects of reading them.
997 # These tests are actually testing the precise output of the current
998 # implementation, so will most likely fail if the implementation changes,
999 # even if the new implementation produces different but correct results.
1000 # It would be nice to test for wrong answers, but I can't see how to do that,
1001 # so instead I'm checking for unexpected answers. (ie -2 becoming "-2" is not
1002 # wrong, but I can't see an easy, reliable way to code that knowledge)
1004 # Numbers (seen by the tokeniser as numbers, stored as numbers.
1007 0, +1, -2, 3.0, +4.0, -5.0, 6.5, +7.5, -8.5,
1008 9, +10, -11, 12.0, +13.0, -14.0, 15.5, +16.25, -17.75,
1013 "0", "+1", "-2", "3.0", "+4.0", "-5.0", "6.5", "+7.5", "-8.5", " 9",
1014 " +10", " -11", " 12.0", " +13.0", " -14.0", " 15.5", " +16.25", " -17.75",
1017 # The perl code always does things the same way for numbers.
1018 $WANT_PL_N = <<'EOT';
1038 # The perl code knows that 0 and -2 stringify exactly back to the strings,
1039 # so it dumps them as numbers, not strings.
1040 $WANT_PL_S = <<'EOT';
1057 #$VAR17 = ' +16.25';
1058 #$VAR18 = ' -17.75';
1061 # The XS code differs.
1062 # These are the numbers as seen by the tokeniser. Constants aren't folded
1063 # (which makes IVs where possible) so values the tokeniser thought were
1064 # floating point are stored as NVs. The XS code outputs these as strings,
1065 # but as it has converted them from NVs, leading + signs will not be there.
1066 $WANT_XS_N = <<'EOT';
1087 # These are the strings as seen by the tokeniser. The XS code will output
1088 # these for all cases except where the scalar has been used in integer context
1089 $WANT_XS_S = <<'EOT';
1106 #$VAR17 = ' +16.25';
1107 #$VAR18 = ' -17.75';
1110 # These are the numbers as IV-ized by &
1111 # These will differ from WANT_XS_N because now IV flags will be set on all
1112 # values that were actually integer, and the XS code will then output these
1113 # as numbers not strings.
1114 $WANT_XS_I = <<'EOT';
1135 # Some of these tests will be redundant.
1136 @numbers_s = @numbers_i = @numbers_is = @numbers_n = @numbers_ns = @numbers_ni
1137 = @numbers_nis = @numbers;
1138 @strings_s = @strings_i = @strings_is = @strings_n = @strings_ns = @strings_ni
1139 = @strings_nis = @strings;
1140 # Use them in an integer context
1141 foreach (@numbers_i, @numbers_ni, @numbers_nis, @numbers_is,
1142 @strings_i, @strings_ni, @strings_nis, @strings_is) {
1143 my $b = sprintf "%d", $_;
1145 # Use them in a floating point context
1146 foreach (@numbers_n, @numbers_ni, @numbers_nis, @numbers_ns,
1147 @strings_n, @strings_ni, @strings_nis, @strings_ns) {
1148 my $b = sprintf "%e", $_;
1150 # Use them in a string context
1151 foreach (@numbers_s, @numbers_is, @numbers_nis, @numbers_ns,
1152 @strings_s, @strings_is, @strings_nis, @strings_ns) {
1153 my $b = sprintf "%s", $_;
1156 # use Devel::Peek; Dump ($_) foreach @vanilla_c;
1159 TEST q(Data::Dumper->new(\@numbers)->Dump), 'Numbers';
1160 TEST q(Data::Dumper->new(\@numbers_s)->Dump), 'Numbers PV';
1161 TEST q(Data::Dumper->new(\@numbers_i)->Dump), 'Numbers IV';
1162 TEST q(Data::Dumper->new(\@numbers_is)->Dump), 'Numbers IV,PV';
1163 TEST q(Data::Dumper->new(\@numbers_n)->Dump), 'Numbers NV';
1164 TEST q(Data::Dumper->new(\@numbers_ns)->Dump), 'Numbers NV,PV';
1165 TEST q(Data::Dumper->new(\@numbers_ni)->Dump), 'Numbers NV,IV';
1166 TEST q(Data::Dumper->new(\@numbers_nis)->Dump), 'Numbers NV,IV,PV';
1168 TEST q(Data::Dumper->new(\@strings)->Dump), 'Strings';
1169 TEST q(Data::Dumper->new(\@strings_s)->Dump), 'Strings PV';
1170 TEST q(Data::Dumper->new(\@strings_i)->Dump), 'Strings IV';
1171 TEST q(Data::Dumper->new(\@strings_is)->Dump), 'Strings IV,PV';
1172 TEST q(Data::Dumper->new(\@strings_n)->Dump), 'Strings NV';
1173 TEST q(Data::Dumper->new(\@strings_ns)->Dump), 'Strings NV,PV';
1174 TEST q(Data::Dumper->new(\@strings_ni)->Dump), 'Strings NV,IV';
1175 TEST q(Data::Dumper->new(\@strings_nis)->Dump), 'Strings NV,IV,PV';
1177 my $nv_preserves_uv = defined $Config{d_nv_preserves_uv};
1178 my $nv_preserves_uv_4bits = $Config{nv_preserves_uv_bits} >= 4;
1180 TEST q(Data::Dumper->new(\@numbers)->Dumpxs), 'XS Numbers';
1181 TEST q(Data::Dumper->new(\@numbers_s)->Dumpxs), 'XS Numbers PV';
1182 if ($nv_preserves_uv || $nv_preserves_uv_4bits) {
1184 TEST q(Data::Dumper->new(\@numbers_i)->Dumpxs), 'XS Numbers IV';
1185 TEST q(Data::Dumper->new(\@numbers_is)->Dumpxs), 'XS Numbers IV,PV';
1187 SKIP_TEST "NV does not preserve 4bits";
1188 SKIP_TEST "NV does not preserve 4bits";
1191 TEST q(Data::Dumper->new(\@numbers_n)->Dumpxs), 'XS Numbers NV';
1192 TEST q(Data::Dumper->new(\@numbers_ns)->Dumpxs), 'XS Numbers NV,PV';
1193 if ($nv_preserves_uv || $nv_preserves_uv_4bits) {
1195 TEST q(Data::Dumper->new(\@numbers_ni)->Dumpxs), 'XS Numbers NV,IV';
1196 TEST q(Data::Dumper->new(\@numbers_nis)->Dumpxs), 'XS Numbers NV,IV,PV';
1198 SKIP_TEST "NV does not preserve 4bits";
1199 SKIP_TEST "NV does not preserve 4bits";
1203 TEST q(Data::Dumper->new(\@strings)->Dumpxs), 'XS Strings';
1204 TEST q(Data::Dumper->new(\@strings_s)->Dumpxs), 'XS Strings PV';
1205 # This one used to really mess up. New code actually emulates the .pm code
1207 TEST q(Data::Dumper->new(\@strings_i)->Dumpxs), 'XS Strings IV';
1208 TEST q(Data::Dumper->new(\@strings_is)->Dumpxs), 'XS Strings IV,PV';
1209 if ($nv_preserves_uv || $nv_preserves_uv_4bits) {
1211 TEST q(Data::Dumper->new(\@strings_n)->Dumpxs), 'XS Strings NV';
1212 TEST q(Data::Dumper->new(\@strings_ns)->Dumpxs), 'XS Strings NV,PV';
1214 SKIP_TEST "NV does not preserve 4bits";
1215 SKIP_TEST "NV does not preserve 4bits";
1217 # This one used to really mess up. New code actually emulates the .pm code
1219 TEST q(Data::Dumper->new(\@strings_ni)->Dumpxs), 'XS Strings NV,IV';
1220 TEST q(Data::Dumper->new(\@strings_nis)->Dumpxs), 'XS Strings NV,IV,PV';
1226 ## Perl code was using /...$/ and hence missing the \n.
1232 # Can't pad with # as the output has an embedded newline.
1233 local $Data::Dumper::Pad = "my ";
1234 TEST q(Data::Dumper->Dump(["42\n"])), "number with trailing newline";
1235 TEST q(Data::Dumper->Dumpxs(["42\n"])), "XS number with trailing newline"
1255 ## Perl code flips over at 10 digits.
1258 #$VAR2 = '1000000000';
1259 #$VAR3 = '9999999999';
1260 #$VAR4 = '10000000000';
1261 #$VAR5 = -999999999;
1262 #$VAR6 = '-1000000000';
1263 #$VAR7 = '-9999999999';
1264 #$VAR8 = '-10000000000';
1265 #$VAR9 = '4294967295';
1266 #$VAR10 = '4294967296';
1267 #$VAR11 = '-2147483648';
1268 #$VAR12 = '-2147483649';
1271 TEST q(Data::Dumper->Dump(\@a)), "long integers";
1274 ## XS code flips over at 11 characters ("-" is a char) or larger than int.
1275 if (~0 == 0xFFFFFFFF) {
1279 #$VAR2 = 1000000000;
1280 #$VAR3 = '9999999999';
1281 #$VAR4 = '10000000000';
1282 #$VAR5 = -999999999;
1283 #$VAR6 = '-1000000000';
1284 #$VAR7 = '-9999999999';
1285 #$VAR8 = '-10000000000';
1286 #$VAR9 = 4294967295;
1287 #$VAR10 = '4294967296';
1288 #$VAR11 = '-2147483648';
1289 #$VAR12 = '-2147483649';
1294 #$VAR2 = 1000000000;
1295 #$VAR3 = 9999999999;
1296 #$VAR4 = '10000000000';
1297 #$VAR5 = -999999999;
1298 #$VAR6 = '-1000000000';
1299 #$VAR7 = '-9999999999';
1300 #$VAR8 = '-10000000000';
1301 #$VAR9 = 4294967295;
1302 #$VAR10 = 4294967296;
1303 #$VAR11 = '-2147483648';
1304 #$VAR12 = '-2147483649';
1307 TEST q(Data::Dumper->Dumpxs(\@a)), "XS long integers";
1314 $b = "Bad. XS didn't escape dollar sign";
1316 $WANT = <<"EOT"; # Careful. This is '' string written inside '' here doc
1317 #\$VAR1 = '\$b\"\@\\\\\xB1';
1319 $a = "\$b\"\@\\\xB1\x{100}";
1321 TEST q(Data::Dumper->Dump([$a])), "utf8 flag with \" and \$";
1323 $WANT = <<'EOT'; # While this is "" string written inside "" here doc
1324 #$VAR1 = "\$b\"\@\\\x{b1}";
1326 TEST q(Data::Dumper->Dumpxs([$a])), "XS utf8 flag with \" and \$";
1329 $b = "Bad. XS didn't escape dollar sign";
1331 $WANT = <<"EOT"; # Careful. This is '' string written inside '' here doc
1332 #\$VAR1 = '\$b\"\@\\\\\xA3';
1335 $a = "\$b\"\@\\\xA3\x{100}";
1337 TEST q(Data::Dumper->Dump([$a])), "utf8 flag with \" and \$";
1339 $WANT = <<'EOT'; # While this is "" string written inside "" here doc
1340 #$VAR1 = "\$b\"\@\\\x{a3}";
1342 TEST q(Data::Dumper->Dumpxs([$a])), "XS utf8 flag with \" and \$";
1345 # XS used to produce "$b\"' which is 4 chars, not 3. [ie wrongly qq(\$b\\\")]
1351 $a = "\$b\"\x{100}";
1353 TEST q(Data::Dumper->Dump([$a])), "utf8 flag with \" and \$";
1355 TEST q(Data::Dumper->Dumpxs([$a])), "XS utf8 flag with \" and \$";
1359 # XS used to produce 'D'oh!' which is well, D'oh!
1360 # Andreas found this one, which in turn discovered the previous two.
1366 $a = "D'oh!\x{100}";
1368 TEST q(Data::Dumper->Dump([$a])), "utf8 flag with '";
1370 TEST q(Data::Dumper->Dumpxs([$a])), "XS utf8 flag with '";
1374 # Jarkko found that -Mutf8 caused some tests to fail. Turns out that there
1375 # was an otherwise untested code path in the XS for utf8 hash keys with purity
1383 # "\x{decaf}\x{decaf}\x{decaf}\x{decaf}" => do{my $o}
1385 #*::ping{HASH}->{"\x{decaf}\x{decaf}\x{decaf}\x{decaf}"} = *::ping{SCALAR};
1386 #%pong = %{*::ping{HASH}};
1388 local $Data::Dumper::Purity = 1;
1389 local $Data::Dumper::Sortkeys;
1391 %ping = (chr (0xDECAF) x 4 =>\$ping);
1392 for $Data::Dumper::Sortkeys (0, 1) {
1394 TEST q(Data::Dumper->Dump([\\*ping, \\%ping], ['*ping', '*pong']));
1395 TEST q(Data::Dumper->Dumpxs([\\*ping, \\%ping], ['*ping', '*pong'])) if $XS;
1397 SKIP_TEST "Incomplete support for UTF-8 in old perls";
1398 SKIP_TEST "Incomplete support for UTF-8 in old perls";
1403 # XS for quotekeys==0 was not being defensive enough against utf8 flagged
1412 local $Data::Dumper::Quotekeys = 0;
1413 my $k = 'perl' . chr 256;
1415 %foo = ($k => 'rocks');
1417 TEST q(Data::Dumper->Dump([\\%foo])), "quotekeys == 0 for utf8 flagged ASCII";
1418 TEST q(Data::Dumper->Dumpxs([\\%foo])),
1419 "XS quotekeys == 0 for utf8 flagged ASCII" if $XS;
1432 TEST q(Data::Dumper->Dump([\@foo])), 'Richard Clamp, Message-Id: <20030104005247.GA27685@mirth.demon.co.uk>';
1433 TEST q(Data::Dumper->Dumpxs([\@foo])) if $XS;