This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
socketpair.t w/o fork
[perl5.git] / ext / Data / Dumper / t / dumper.t
CommitLineData
823edd99
GS
1#!./perl -w
2#
3# testsuite for Data::Dumper
4#
5
6BEGIN {
7 chdir 't' if -d 't';
20822f61 8 @INC = '../lib';
be3174d2
GS
9 require Config; import Config;
10 if ($Config{'extensions'} !~ /\bData\/Dumper\b/) {
11 print "1..0 # Skip: Data::Dumper was not built\n";
12 exit 0;
13 }
823edd99
GS
14}
15
16use Data::Dumper;
f70c35af
GS
17use Config;
18my $Is_ebcdic = defined($Config{'ebcdic'}) && $Config{'ebcdic'} eq 'define';
823edd99
GS
19
20$Data::Dumper::Pad = "#";
21my $TMAX;
22my $XS;
23my $TNUM = 0;
24my $WANT = '';
25
26sub TEST {
27 my $string = shift;
28 my $t = eval $string;
29 ++$TNUM;
a2126434
JN
30 $t =~ s/([A-Z]+)\(0x[0-9a-f]+\)/$1(0xdeadbeef)/g
31 if ($WANT =~ /deadbeef/);
f70c35af
GS
32 if ($Is_ebcdic) {
33 # these data need massaging with non ascii character sets
34 # because of hashing order differences
35 $WANT = join("\n",sort(split(/\n/,$WANT)));
36 $WANT =~ s/\,$//mg;
37 $t = join("\n",sort(split(/\n/,$t)));
38 $t =~ s/\,$//mg;
39 }
823edd99
GS
40 print( ($t eq $WANT and not $@) ? "ok $TNUM\n"
41 : "not ok $TNUM\n--Expected--\n$WANT\n--Got--\n$@$t\n");
42
43 ++$TNUM;
44 eval "$t";
45 print $@ ? "not ok $TNUM\n# \$@ says: $@\n" : "ok $TNUM\n";
46
47 $t = eval $string;
48 ++$TNUM;
a2126434
JN
49 $t =~ s/([A-Z]+)\(0x[0-9a-f]+\)/$1(0xdeadbeef)/g
50 if ($WANT =~ /deadbeef/);
f70c35af
GS
51 if ($Is_ebcdic) {
52 # here too there are hashing order differences
53 $WANT = join("\n",sort(split(/\n/,$WANT)));
54 $WANT =~ s/\,$//mg;
55 $t = join("\n",sort(split(/\n/,$t)));
56 $t =~ s/\,$//mg;
57 }
823edd99
GS
58 print( ($t eq $WANT and not $@) ? "ok $TNUM\n"
59 : "not ok $TNUM\n--Expected--\n$WANT\n--Got--\n$@$t\n");
60}
61
62if (defined &Data::Dumper::Dumpxs) {
63 print "### XS extension loaded, will run XS tests\n";
8e5f9a6e 64 $TMAX = 213; $XS = 1;
823edd99
GS
65}
66else {
67 print "### XS extensions not loaded, will NOT run XS tests\n";
8e5f9a6e 68 $TMAX = 108; $XS = 0;
823edd99
GS
69}
70
71print "1..$TMAX\n";
72
73#############
74#############
75
76@c = ('c');
77$c = \@c;
78$b = {};
79$a = [1, $b, $c];
80$b->{a} = $a;
81$b->{b} = $a->[1];
82$b->{c} = $a->[2];
83
84############# 1
85##
86$WANT = <<'EOT';
87#$a = [
88# 1,
89# {
823edd99
GS
90# 'c' => [
91# 'c'
a6fe520e
MLF
92# ],
93# 'a' => $a,
94# 'b' => $a->[1]
823edd99
GS
95# },
96# $a->[1]{'c'}
97# ];
98#$b = $a->[1];
99#$c = $a->[1]{'c'};
100EOT
101
102TEST q(Data::Dumper->Dump([$a,$b,$c], [qw(a b c)]));
103TEST q(Data::Dumper->Dumpxs([$a,$b,$c], [qw(a b c)])) if $XS;
104
105
106############# 7
107##
108$WANT = <<'EOT';
109#@a = (
110# 1,
111# {
823edd99
GS
112# 'c' => [
113# 'c'
a6fe520e
MLF
114# ],
115# 'a' => [],
116# 'b' => {}
823edd99
GS
117# },
118# []
119# );
120#$a[1]{'a'} = \@a;
121#$a[1]{'b'} = $a[1];
122#$a[2] = $a[1]{'c'};
123#$b = $a[1];
124EOT
125
126$Data::Dumper::Purity = 1; # fill in the holes for eval
127TEST q(Data::Dumper->Dump([$a, $b], [qw(*a b)])); # print as @a
128TEST q(Data::Dumper->Dumpxs([$a, $b], [qw(*a b)])) if $XS;
129
130############# 13
131##
132$WANT = <<'EOT';
133#%b = (
a6fe520e
MLF
134# 'c' => [
135# 'c'
136# ],
823edd99
GS
137# 'a' => [
138# 1,
139# {},
a6fe520e 140# []
823edd99 141# ],
a6fe520e 142# 'b' => {}
823edd99
GS
143# );
144#$b{'a'}[1] = \%b;
a6fe520e 145#$b{'a'}[2] = $b{'c'};
823edd99 146#$b{'b'} = \%b;
823edd99
GS
147#$a = $b{'a'};
148EOT
149
150TEST q(Data::Dumper->Dump([$b, $a], [qw(*b a)])); # print as %b
151TEST q(Data::Dumper->Dumpxs([$b, $a], [qw(*b a)])) if $XS;
152
153############# 19
154##
155$WANT = <<'EOT';
156#$a = [
157# 1,
158# {
a6fe520e 159# 'c' => [],
823edd99 160# 'a' => [],
a6fe520e 161# 'b' => {}
823edd99
GS
162# },
163# []
164#];
a6fe520e 165#$a->[1]{'c'} = \@c;
823edd99
GS
166#$a->[1]{'a'} = $a;
167#$a->[1]{'b'} = $a->[1];
823edd99
GS
168#$a->[2] = \@c;
169#$b = $a->[1];
170EOT
171
172$Data::Dumper::Indent = 1;
173TEST q(
174 $d = Data::Dumper->new([$a,$b], [qw(a b)]);
175 $d->Seen({'*c' => $c});
176 $d->Dump;
177 );
178if ($XS) {
179 TEST q(
180 $d = Data::Dumper->new([$a,$b], [qw(a b)]);
181 $d->Seen({'*c' => $c});
182 $d->Dumpxs;
183 );
184}
185
186
187############# 25
188##
189$WANT = <<'EOT';
190#$a = [
191# #0
192# 1,
193# #1
194# {
823edd99
GS
195# c => [
196# #0
197# 'c'
a6fe520e
MLF
198# ],
199# a => $a,
200# b => $a->[1]
823edd99
GS
201# },
202# #2
203# $a->[1]{c}
204# ];
205#$b = $a->[1];
206EOT
207
208$d->Indent(3);
209$d->Purity(0)->Quotekeys(0);
210TEST q( $d->Reset; $d->Dump );
211
212TEST q( $d->Reset; $d->Dumpxs ) if $XS;
213
214############# 31
215##
216$WANT = <<'EOT';
217#$VAR1 = [
218# 1,
219# {
823edd99
GS
220# 'c' => [
221# 'c'
a6fe520e
MLF
222# ],
223# 'a' => [],
224# 'b' => {}
823edd99
GS
225# },
226# []
227#];
228#$VAR1->[1]{'a'} = $VAR1;
229#$VAR1->[1]{'b'} = $VAR1->[1];
230#$VAR1->[2] = $VAR1->[1]{'c'};
231EOT
232
233TEST q(Dumper($a));
234TEST q(Data::Dumper::DumperX($a)) if $XS;
235
236############# 37
237##
238$WANT = <<'EOT';
239#[
240# 1,
241# {
823edd99
GS
242# c => [
243# 'c'
a6fe520e
MLF
244# ],
245# a => $VAR1,
246# b => $VAR1->[1]
823edd99
GS
247# },
248# $VAR1->[1]{c}
249#]
250EOT
251
252{
253 local $Data::Dumper::Purity = 0;
254 local $Data::Dumper::Quotekeys = 0;
255 local $Data::Dumper::Terse = 1;
256 TEST q(Dumper($a));
257 TEST q(Data::Dumper::DumperX($a)) if $XS;
258}
259
260
261############# 43
262##
263$WANT = <<'EOT';
264#$VAR1 = {
a6fe520e
MLF
265# "reftest" => \\1,
266# "abc\0'\efg" => "mno\0"
823edd99
GS
267#};
268EOT
269
54964f74
GA
270$foo = { "abc\000\'\efg" => "mno\000",
271 "reftest" => \\1,
272 };
823edd99
GS
273{
274 local $Data::Dumper::Useqq = 1;
275 TEST q(Dumper($foo));
276}
277
278 $WANT = <<"EOT";
279#\$VAR1 = {
a6fe520e
MLF
280# 'reftest' => \\\\1,
281# 'abc\0\\'\efg' => 'mno\0'
823edd99
GS
282#};
283EOT
284
285 {
286 local $Data::Dumper::Useqq = 1;
287 TEST q(Data::Dumper::DumperX($foo)) if $XS; # cheat
288 }
289
290
291
292#############
293#############
294
295{
296 package main;
297 use Data::Dumper;
298 $foo = 5;
f32b5c8a 299 @foo = (-10,\*foo);
823edd99
GS
300 %foo = (a=>1,b=>\$foo,c=>\@foo);
301 $foo{d} = \%foo;
302 $foo[2] = \%foo;
303
304############# 49
305##
306 $WANT = <<'EOT';
307#$foo = \*::foo;
308#*::foo = \5;
309#*::foo = [
310# #0
f32b5c8a 311# -10,
823edd99 312# #1
5df59fb6 313# do{my $o},
823edd99
GS
314# #2
315# {
a6fe520e 316# 'c' => [],
823edd99 317# 'a' => 1,
5df59fb6 318# 'b' => do{my $o},
823edd99
GS
319# 'd' => {}
320# }
321# ];
322#*::foo{ARRAY}->[1] = $foo;
823edd99 323#*::foo{ARRAY}->[2]{'c'} = *::foo{ARRAY};
a6fe520e 324#*::foo{ARRAY}->[2]{'b'} = *::foo{SCALAR};
823edd99
GS
325#*::foo{ARRAY}->[2]{'d'} = *::foo{ARRAY}->[2];
326#*::foo = *::foo{ARRAY}->[2];
327#@bar = @{*::foo{ARRAY}};
328#%baz = %{*::foo{ARRAY}->[2]};
329EOT
330
331 $Data::Dumper::Purity = 1;
332 $Data::Dumper::Indent = 3;
333 TEST q(Data::Dumper->Dump([\\*foo, \\@foo, \\%foo], ['*foo', '*bar', '*baz']));
334 TEST q(Data::Dumper->Dumpxs([\\*foo, \\@foo, \\%foo], ['*foo', '*bar', '*baz'])) if $XS;
335
336############# 55
337##
338 $WANT = <<'EOT';
339#$foo = \*::foo;
340#*::foo = \5;
341#*::foo = [
f32b5c8a 342# -10,
5df59fb6 343# do{my $o},
823edd99 344# {
a6fe520e 345# 'c' => [],
823edd99 346# 'a' => 1,
5df59fb6 347# 'b' => do{my $o},
823edd99
GS
348# 'd' => {}
349# }
350#];
351#*::foo{ARRAY}->[1] = $foo;
823edd99 352#*::foo{ARRAY}->[2]{'c'} = *::foo{ARRAY};
a6fe520e 353#*::foo{ARRAY}->[2]{'b'} = *::foo{SCALAR};
823edd99
GS
354#*::foo{ARRAY}->[2]{'d'} = *::foo{ARRAY}->[2];
355#*::foo = *::foo{ARRAY}->[2];
356#$bar = *::foo{ARRAY};
357#$baz = *::foo{ARRAY}->[2];
358EOT
359
360 $Data::Dumper::Indent = 1;
361 TEST q(Data::Dumper->Dump([\\*foo, \\@foo, \\%foo], ['foo', 'bar', 'baz']));
362 TEST q(Data::Dumper->Dumpxs([\\*foo, \\@foo, \\%foo], ['foo', 'bar', 'baz'])) if $XS;
363
364############# 61
365##
366 $WANT = <<'EOT';
367#@bar = (
f32b5c8a 368# -10,
823edd99
GS
369# \*::foo,
370# {}
371#);
372#*::foo = \5;
373#*::foo = \@bar;
374#*::foo = {
a6fe520e 375# 'c' => [],
823edd99 376# 'a' => 1,
5df59fb6 377# 'b' => do{my $o},
823edd99
GS
378# 'd' => {}
379#};
823edd99 380#*::foo{HASH}->{'c'} = \@bar;
a6fe520e 381#*::foo{HASH}->{'b'} = *::foo{SCALAR};
823edd99
GS
382#*::foo{HASH}->{'d'} = *::foo{HASH};
383#$bar[2] = *::foo{HASH};
384#%baz = %{*::foo{HASH}};
385#$foo = $bar[1];
386EOT
387
388 TEST q(Data::Dumper->Dump([\\@foo, \\%foo, \\*foo], ['*bar', '*baz', '*foo']));
389 TEST q(Data::Dumper->Dumpxs([\\@foo, \\%foo, \\*foo], ['*bar', '*baz', '*foo'])) if $XS;
390
391############# 67
392##
393 $WANT = <<'EOT';
394#$bar = [
f32b5c8a 395# -10,
823edd99
GS
396# \*::foo,
397# {}
398#];
399#*::foo = \5;
400#*::foo = $bar;
401#*::foo = {
a6fe520e 402# 'c' => [],
823edd99 403# 'a' => 1,
5df59fb6 404# 'b' => do{my $o},
823edd99
GS
405# 'd' => {}
406#};
823edd99 407#*::foo{HASH}->{'c'} = $bar;
a6fe520e 408#*::foo{HASH}->{'b'} = *::foo{SCALAR};
823edd99
GS
409#*::foo{HASH}->{'d'} = *::foo{HASH};
410#$bar->[2] = *::foo{HASH};
411#$baz = *::foo{HASH};
412#$foo = $bar->[1];
413EOT
414
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;
417
418############# 73
419##
420 $WANT = <<'EOT';
421#$foo = \*::foo;
422#@bar = (
f32b5c8a 423# -10,
823edd99
GS
424# $foo,
425# {
a6fe520e 426# c => \@bar,
823edd99
GS
427# a => 1,
428# b => \5,
823edd99
GS
429# d => $bar[2]
430# }
431#);
432#%baz = %{$bar[2]};
433EOT
434
435 $Data::Dumper::Purity = 0;
436 $Data::Dumper::Quotekeys = 0;
437 TEST q(Data::Dumper->Dump([\\*foo, \\@foo, \\%foo], ['*foo', '*bar', '*baz']));
438 TEST q(Data::Dumper->Dumpxs([\\*foo, \\@foo, \\%foo], ['*foo', '*bar', '*baz'])) if $XS;
439
440############# 79
441##
442 $WANT = <<'EOT';
443#$foo = \*::foo;
444#$bar = [
f32b5c8a 445# -10,
823edd99
GS
446# $foo,
447# {
a6fe520e 448# c => $bar,
823edd99
GS
449# a => 1,
450# b => \5,
823edd99
GS
451# d => $bar->[2]
452# }
453#];
454#$baz = $bar->[2];
455EOT
456
457 TEST q(Data::Dumper->Dump([\\*foo, \\@foo, \\%foo], ['foo', 'bar', 'baz']));
458 TEST q(Data::Dumper->Dumpxs([\\*foo, \\@foo, \\%foo], ['foo', 'bar', 'baz'])) if $XS;
459
460}
461
462#############
463#############
464{
465 package main;
466 @dogs = ( 'Fido', 'Wags' );
467 %kennel = (
468 First => \$dogs[0],
469 Second => \$dogs[1],
470 );
471 $dogs[2] = \%kennel;
472 $mutts = \%kennel;
473 $mutts = $mutts; # avoid warning
474
475############# 85
476##
477 $WANT = <<'EOT';
478#%kennels = (
a6fe520e
MLF
479# Second => \'Wags',
480# First => \'Fido'
823edd99
GS
481#);
482#@dogs = (
0f4592ef
GS
483# ${$kennels{First}},
484# ${$kennels{Second}},
823edd99
GS
485# \%kennels
486#);
487#%mutts = %kennels;
488EOT
489
490 TEST q(
491 $d = Data::Dumper->new([\\%kennel, \\@dogs, $mutts],
492 [qw(*kennels *dogs *mutts)] );
493 $d->Dump;
494 );
495 if ($XS) {
496 TEST q(
497 $d = Data::Dumper->new([\\%kennel, \\@dogs, $mutts],
498 [qw(*kennels *dogs *mutts)] );
499 $d->Dumpxs;
500 );
501 }
502
503############# 91
504##
505 $WANT = <<'EOT';
506#%kennels = %kennels;
507#@dogs = @dogs;
508#%mutts = %kennels;
509EOT
510
511 TEST q($d->Dump);
512 TEST q($d->Dumpxs) if $XS;
513
514############# 97
515##
516 $WANT = <<'EOT';
517#%kennels = (
a6fe520e
MLF
518# Second => \'Wags',
519# First => \'Fido'
823edd99
GS
520#);
521#@dogs = (
0f4592ef
GS
522# ${$kennels{First}},
523# ${$kennels{Second}},
823edd99
GS
524# \%kennels
525#);
526#%mutts = %kennels;
527EOT
528
529
530 TEST q($d->Reset; $d->Dump);
531 if ($XS) {
532 TEST q($d->Reset; $d->Dumpxs);
533 }
534
535############# 103
536##
537 $WANT = <<'EOT';
538#@dogs = (
539# 'Fido',
540# 'Wags',
541# {
a6fe520e
MLF
542# Second => \$dogs[1],
543# First => \$dogs[0]
823edd99
GS
544# }
545#);
546#%kennels = %{$dogs[2]};
547#%mutts = %{$dogs[2]};
548EOT
549
550 TEST q(
551 $d = Data::Dumper->new([\\@dogs, \\%kennel, $mutts],
552 [qw(*dogs *kennels *mutts)] );
553 $d->Dump;
554 );
555 if ($XS) {
556 TEST q(
557 $d = Data::Dumper->new([\\@dogs, \\%kennel, $mutts],
558 [qw(*dogs *kennels *mutts)] );
559 $d->Dumpxs;
560 );
561 }
562
563############# 109
564##
565 TEST q($d->Reset->Dump);
566 if ($XS) {
567 TEST q($d->Reset->Dumpxs);
568 }
569
570############# 115
571##
572 $WANT = <<'EOT';
573#@dogs = (
574# 'Fido',
575# 'Wags',
576# {
a6fe520e
MLF
577# Second => \'Wags',
578# First => \'Fido'
823edd99
GS
579# }
580#);
581#%kennels = (
a6fe520e
MLF
582# Second => \'Wags',
583# First => \'Fido'
823edd99
GS
584#);
585EOT
586
587 TEST q(
588 $d = Data::Dumper->new( [\@dogs, \%kennel], [qw(*dogs *kennels)] );
589 $d->Deepcopy(1)->Dump;
590 );
591 if ($XS) {
592 TEST q($d->Reset->Dumpxs);
593 }
594
595}
596
597{
598
0f4592ef
GS
599sub z { print "foo\n" }
600$c = [ \&z ];
823edd99
GS
601
602############# 121
603##
604 $WANT = <<'EOT';
605#$a = $b;
606#$c = [
607# $b
608#];
609EOT
610
0f4592ef
GS
611TEST q(Data::Dumper->new([\&z,$c],['a','c'])->Seen({'b' => \&z})->Dump;);
612TEST q(Data::Dumper->new([\&z,$c],['a','c'])->Seen({'b' => \&z})->Dumpxs;)
823edd99
GS
613 if $XS;
614
615############# 127
616##
617 $WANT = <<'EOT';
618#$a = \&b;
619#$c = [
620# \&b
621#];
622EOT
623
0f4592ef
GS
624TEST q(Data::Dumper->new([\&z,$c],['a','c'])->Seen({'*b' => \&z})->Dump;);
625TEST q(Data::Dumper->new([\&z,$c],['a','c'])->Seen({'*b' => \&z})->Dumpxs;)
823edd99
GS
626 if $XS;
627
628############# 133
629##
630 $WANT = <<'EOT';
631#*a = \&b;
632#@c = (
633# \&b
634#);
635EOT
636
0f4592ef
GS
637TEST q(Data::Dumper->new([\&z,$c],['*a','*c'])->Seen({'*b' => \&z})->Dump;);
638TEST q(Data::Dumper->new([\&z,$c],['*a','*c'])->Seen({'*b' => \&z})->Dumpxs;)
823edd99
GS
639 if $XS;
640
641}
0f4592ef
GS
642
643{
644 $a = [];
645 $a->[1] = \$a->[0];
646
647############# 139
648##
649 $WANT = <<'EOT';
650#@a = (
651# undef,
5df59fb6 652# do{my $o}
0f4592ef
GS
653#);
654#$a[1] = \$a[0];
655EOT
656
657TEST q(Data::Dumper->new([$a],['*a'])->Purity(1)->Dump;);
658TEST q(Data::Dumper->new([$a],['*a'])->Purity(1)->Dumpxs;)
659 if $XS;
660}
661
662{
663 $a = \\\\\'foo';
664 $b = $$$a;
665
666############# 145
667##
668 $WANT = <<'EOT';
669#$a = \\\\\'foo';
670#$b = ${${$a}};
671EOT
672
673TEST q(Data::Dumper->new([$a,$b],['a','b'])->Purity(1)->Dump;);
674TEST q(Data::Dumper->new([$a,$b],['a','b'])->Purity(1)->Dumpxs;)
675 if $XS;
676}
677
678{
679 $a = [{ a => \$b }, { b => undef }];
680 $b = [{ c => \$b }, { d => \$a }];
681
682############# 151
683##
684 $WANT = <<'EOT';
685#$a = [
686# {
687# a => \[
688# {
5df59fb6 689# c => do{my $o}
0f4592ef
GS
690# },
691# {
692# d => \[]
693# }
694# ]
695# },
696# {
697# b => undef
698# }
699#];
700#${$a->[0]{a}}->[0]->{c} = $a->[0]{a};
701#${${$a->[0]{a}}->[1]->{d}} = $a;
702#$b = ${$a->[0]{a}};
703EOT
704
705TEST q(Data::Dumper->new([$a,$b],['a','b'])->Purity(1)->Dump;);
706TEST q(Data::Dumper->new([$a,$b],['a','b'])->Purity(1)->Dumpxs;)
707 if $XS;
708}
709
710{
711 $a = [[[[\\\\\'foo']]]];
712 $b = $a->[0][0];
713 $c = $${$b->[0][0]};
714
715############# 157
716##
717 $WANT = <<'EOT';
718#$a = [
719# [
720# [
721# [
722# \\\\\'foo'
723# ]
724# ]
725# ]
726#];
727#$b = $a->[0][0];
728#$c = ${${$a->[0][0][0][0]}};
729EOT
730
731TEST q(Data::Dumper->new([$a,$b,$c],['a','b','c'])->Purity(1)->Dump;);
732TEST q(Data::Dumper->new([$a,$b,$c],['a','b','c'])->Purity(1)->Dumpxs;)
733 if $XS;
734}
a2126434
JN
735
736{
737 $f = "pearl";
738 $e = [ $f ];
739 $d = { 'e' => $e };
740 $c = [ $d ];
741 $b = { 'c' => $c };
742 $a = { 'b' => $b };
743
744############# 163
745##
746 $WANT = <<'EOT';
747#$a = {
748# b => {
749# c => [
750# {
751# e => 'ARRAY(0xdeadbeef)'
752# }
753# ]
754# }
755#};
756#$b = $a->{b};
757#$c = $a->{b}{c};
758EOT
759
760TEST q(Data::Dumper->new([$a,$b,$c],['a','b','c'])->Maxdepth(4)->Dump;);
761TEST q(Data::Dumper->new([$a,$b,$c],['a','b','c'])->Maxdepth(4)->Dumpxs;)
762 if $XS;
763
764############# 169
765##
766 $WANT = <<'EOT';
767#$a = {
768# b => 'HASH(0xdeadbeef)'
769#};
770#$b = $a->{b};
771#$c = [
772# 'HASH(0xdeadbeef)'
773#];
774EOT
775
776TEST q(Data::Dumper->new([$a,$b,$c],['a','b','c'])->Maxdepth(1)->Dump;);
777TEST q(Data::Dumper->new([$a,$b,$c],['a','b','c'])->Maxdepth(1)->Dumpxs;)
778 if $XS;
779}
5df59fb6
GS
780
781{
782 $a = \$a;
783 $b = [$a];
784
785############# 175
786##
787 $WANT = <<'EOT';
788#$b = [
789# \$b->[0]
790#];
791EOT
792
793TEST q(Data::Dumper->new([$b],['b'])->Purity(0)->Dump;);
794TEST q(Data::Dumper->new([$b],['b'])->Purity(0)->Dumpxs;)
795 if $XS;
796
797############# 181
798##
799 $WANT = <<'EOT';
800#$b = [
801# \do{my $o}
802#];
803#${$b->[0]} = $b->[0];
804EOT
805
806
807TEST q(Data::Dumper->new([$b],['b'])->Purity(1)->Dump;);
808TEST q(Data::Dumper->new([$b],['b'])->Purity(1)->Dumpxs;)
809 if $XS;
810}
f397e026
TC
811
812{
813 $a = "\x{09c10}";
814############# 187
815## XS code was adding an extra \0
816 $WANT = <<'EOT';
817#$a = "\x{9c10}";
818EOT
819
820 TEST q(Data::Dumper->Dump([$a], ['a']));
821 TEST q(Data::Dumper->Dumpxs([$a], ['a']));
822
823}
e9105f86
IN
824
825{
826 $i = 0;
827 $a = { map { ("$_$_$_", ++$i) } 'I'..'Q' };
828 local $Data::Dumper::Sortkeys = 1;
829
830############# 193
831##
832 $WANT = <<'EOT';
833#$VAR1 = {
834# III => 1,
835# JJJ => 2,
836# KKK => 3,
837# LLL => 4,
838# MMM => 5,
839# NNN => 6,
840# OOO => 7,
841# PPP => 8,
842# QQQ => 9
843#};
844EOT
845
846TEST q(Data::Dumper->new([$a])->Dump;);
847TEST q(Data::Dumper->new([$a])->Dumpxs;)
848 if $XS;
849}
850
851{
852 $i = 5;
853 $c = { map { (++$i, "$_$_$_") } 'I'..'Q' };
854 local $Data::Dumper::Sortkeys = \&sort199;
855 sub sort199 {
856 my $hash = shift;
857 return [ sort { $b <=> $a } keys %$hash ];
858 }
859
860############# 199
861##
862 $WANT = <<'EOT';
863#$VAR1 = {
864# '14' => 'QQQ',
865# '13' => 'PPP',
866# '12' => 'OOO',
867# '11' => 'NNN',
868# '10' => 'MMM',
869# '9' => 'LLL',
870# '8' => 'KKK',
871# '7' => 'JJJ',
872# '6' => 'III'
873#};
874EOT
875
876TEST q(Data::Dumper->new([$c])->Dump;);
877TEST q(Data::Dumper->new([$c])->Dumpxs;)
878 if $XS;
879}
880
881{
882 $i = 5;
883 $c = { map { (++$i, "$_$_$_") } 'I'..'Q' };
884 $d = { reverse %$c };
885 local $Data::Dumper::Sortkeys = \&sort205;
886 sub sort205 {
887 my $hash = shift;
888 return [
889 $hash eq $c ? (sort { $a <=> $b } keys %$hash)
890 : (reverse sort keys %$hash)
891 ];
892 }
893
894############# 205
895##
896 $WANT = <<'EOT';
897#$VAR1 = [
898# {
899# '6' => 'III',
900# '7' => 'JJJ',
901# '8' => 'KKK',
902# '9' => 'LLL',
903# '10' => 'MMM',
904# '11' => 'NNN',
905# '12' => 'OOO',
906# '13' => 'PPP',
907# '14' => 'QQQ'
908# },
909# {
910# QQQ => '14',
911# PPP => '13',
912# OOO => '12',
913# NNN => '11',
914# MMM => '10',
915# LLL => '9',
916# KKK => '8',
917# JJJ => '7',
918# III => '6'
919# }
920#];
921EOT
922
923TEST q(Data::Dumper->new([[$c, $d]])->Dump;);
924TEST q(Data::Dumper->new([[$c, $d]])->Dumpxs;)
925 if $XS;
926}
8e5f9a6e
RGS
927
928{
929 local $Data::Dumper::Deparse = 1;
930 local $Data::Dumper::Indent = 2;
931
932############# 211
933##
934 $WANT = <<'EOT';
935#$VAR1 = {
936# foo => sub {
937# print 'foo';
938# }
939# };
940EOT
941
942 TEST q(Data::Dumper->new([{ foo => sub { print "foo"; } }])->Dump);
943}