Use Trailingcomma option when available (RT#114609)
[p5sagit/Data-Dumper-Concise.git] / t / sugar.t
CommitLineData
884bc377 1use strict;
2use warnings;
3use Data::Dumper::Concise::Sugar;
4
5use Data::Dumper::Concise ();
6
7use Test::More qw(no_plan);
884bc377 8
caf571f8 9my $warned_string;
884bc377 10
caf571f8 11BEGIN {
12 $SIG{'__WARN__'} = sub {
13 $warned_string = $_[0]
14 }
15}
884bc377 16
e6746e64 17DWARNL: {
18 my @foo = DwarnL 'warn', 'friend';
19 is $warned_string,qq{"warn"\n"friend"\n}, 'DwarnL warns';
884bc377 20
e6746e64 21 ok eq_array(\@foo, ['warn','friend']), 'DwarnL passes through correctly';
22}
23
24DWARNS: {
25 my $bar = DwarnS 'robot',2,3;
26 is $warned_string,qq{"robot"\n}, 'DwarnS warns';
27 is $bar, 'robot', 'DwarnS passes through correctly';
28}
caf571f8 29
e6746e64 30DWARN: {
31 my @foo = Dwarn 'warn', 'friend';
32 is $warned_string,qq{"warn"\n"friend"\n}, 'Dwarn warns lists';
33
34 ok eq_array(\@foo, ['warn','friend']), 'Dwarn passes lists through correctly';
35
36 my $bar = Dwarn 'robot',2,3;
0d511978 37 is $warned_string,qq{"robot"\n2\n3\n}, 'Dwarn warns scalars correctly';
e6746e64 38 is $bar, 'robot', 'Dwarn passes scalars through correctly';
39}
0deeb75f 40
7194c025 41DWARN_CODEREF: {
42 my $foo = ['warn', 'friend']->$Dwarn;
4aab3605 43 like $warned_string,qr{^\[\n "warn",\n "friend",?\n\]\n\z}, 'Dwarn warns lists';
7194c025 44
45 ok eq_array($foo, ['warn','friend']), 'Dwarn passes lists through correctly';
46}
47
92264889 48DWARNF: {
49 my @foo = DwarnF { "arr: $_[0] str: $_[1]" } [qw(wut HALP)], "gnarl";
50
4aab3605 51 like($warned_string, qr{^arr: \[\n "wut",\n "HALP",?\n\]\n str: "gnarl"\n\z}, 'DumperF works!');
92264889 52 ok eq_array($foo[0], ['wut','HALP']) && $foo[1] eq 'gnarl', 'DwarnF passes lists through correctly';
53}
54
0deeb75f 55DWARNN: {
452e7ff2 56 my $loaded = eval { require Devel::ArgNames; 1 };
57 if ($loaded) {
58 my $x = [1];
59 my $foo = DwarnN $x;
4aab3605 60 like $warned_string, qr{^\$x => \[\n 1,?\n\]\n\z}, 'DwarnN warns';
0deeb75f 61
452e7ff2 62 ok eq_array($foo, [1]), 'DwarnN passes through correctly';
0deeb75f 63
452e7ff2 64 DwarnN [1];
4aab3605 65 like $warned_string, qr{^\(anon\) => \[\n 1,?\n\]\n\z}, 'DwarnN warns';
452e7ff2 66 }
0deeb75f 67}
68
2566c738 69DDIE: {
70 eval {
71 DdieS [ 'k', 'bar' ];
72 };
4aab3605 73 like $@, qr{^\[\n "k",\n "bar",?\n\]\n\z}, 'DwarnD dies output correctly';
2566c738 74}
75