2 # t/indent.t - Test Indent()
5 require Config; import Config;
7 if ($Config{'extensions'} !~ /\bData\/Dumper\b/) {
8 print "1..0 # Skip: Data::Dumper was not built\n";
17 use Test::More tests => 9;
18 use lib qw( ./t/lib );
19 use Testing qw( _dumptostr );
22 my $hash = { foo => 42 };
27 $dumper = Data::Dumper->new([$hash]);
28 $dumpstr{noindent} = _dumptostr($dumper);
33 $dumper = Data::Dumper->new([$hash]);
35 $dumpstr{indent_no_arg} = _dumptostr($dumper);
37 $dumper = Data::Dumper->new([$hash]);
39 $dumpstr{indent_0} = _dumptostr($dumper);
40 # $VAR1 = {'foo' => 42}; # no newline
42 $dumper = Data::Dumper->new([$hash]);
44 $dumpstr{indent_1} = _dumptostr($dumper);
49 $dumper = Data::Dumper->new([$hash]);
51 $dumpstr{indent_2} = _dumptostr($dumper);
56 is($dumpstr{noindent}, $dumpstr{indent_no_arg},
57 "absence of Indent is same as Indent()");
58 isnt($dumpstr{noindent}, $dumpstr{indent_0},
59 "absence of Indent is different from Indent(0)");
60 isnt($dumpstr{indent_0}, $dumpstr{indent_1},
61 "Indent(0) is different from Indent(1)");
62 cmp_ok(length($dumpstr{indent_0}), '<=', length($dumpstr{indent_1}),
63 "Indent(0) is more compact than Indent(1)");
64 is($dumpstr{noindent}, $dumpstr{indent_2},
65 "absence of Indent is same as Indent(2), i.e., 2 is default");
66 cmp_ok(length($dumpstr{indent_1}), '<=', length($dumpstr{indent_2}),
67 "Indent(1) is more compact than Indent(2)");
69 my $array = [ qw| foo 42 | ];
70 $dumper = Data::Dumper->new([$array]);
72 $dumpstr{ar_indent_2} = _dumptostr($dumper);
78 $dumper = Data::Dumper->new([$array]);
80 $dumpstr{ar_indent_3} = _dumptostr($dumper);
88 isnt($dumpstr{ar_indent_2}, $dumpstr{ar_indent_3},
89 "On arrays, Indent(2) is different from Indent(3)");
90 like($dumpstr{ar_indent_3},
91 qr/\#0.+'foo'.+\#1.+42/s,
92 "Indent(3) annotates array elements with their indices"
95 no if $] < 5.011, warnings => 'deprecated';
96 is(scalar(split("\n" => $dumpstr{ar_indent_2})) + 2,
97 scalar(split("\n" => $dumpstr{ar_indent_3})),
98 "Indent(3) runs 2 lines longer than Indent(2)");
102 is($dumpstr{noindent}, $dumpstr{indent_0},
103 "absence of Indent is same as Indent(0)");
104 isnt($dumpstr{noindent}, $dumpstr{indent_1},
105 "absence of Indent is different from Indent(1)");
106 print STDERR $dumpstr{indent_0};
107 print STDERR $dumpstr{ar_indent_3};