File: sugar.t

package info (click to toggle)
libdata-dumper-concise-perl 2.023-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 100 kB
  • sloc: perl: 56; makefile: 2
file content (75 lines) | stat: -rw-r--r-- 1,957 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use strict;
use warnings;
use Data::Dumper::Concise::Sugar;

use Data::Dumper::Concise ();

use Test::More qw(no_plan);

my $warned_string;

BEGIN {
   $SIG{'__WARN__'} = sub {
      $warned_string = $_[0]
   }
}

DWARNL: {
   my @foo = DwarnL 'warn', 'friend';
   is $warned_string,qq{"warn"\n"friend"\n}, 'DwarnL warns';

   ok eq_array(\@foo, ['warn','friend']), 'DwarnL passes through correctly';
}

DWARNS: {
   my $bar = DwarnS 'robot',2,3;
   is $warned_string,qq{"robot"\n}, 'DwarnS warns';
   is $bar, 'robot', 'DwarnS passes through correctly';
}

DWARN: {
   my @foo = Dwarn 'warn', 'friend';
   is $warned_string,qq{"warn"\n"friend"\n}, 'Dwarn warns lists';

   ok eq_array(\@foo, ['warn','friend']), 'Dwarn passes lists through correctly';

   my $bar = Dwarn 'robot',2,3;
   is $warned_string,qq{"robot"\n2\n3\n}, 'Dwarn warns scalars correctly';
   is $bar, 'robot', 'Dwarn passes scalars through correctly';
}

DWARN_CODEREF: {
   my $foo = ['warn', 'friend']->$Dwarn;
   like $warned_string,qr{^\[\n  "warn",\n  "friend",?\n\]\n\z}, 'Dwarn warns lists';

   ok eq_array($foo, ['warn','friend']), 'Dwarn passes lists through correctly';
}

DWARNF: {
   my @foo = DwarnF { "arr: $_[0] str: $_[1]" } [qw(wut HALP)], "gnarl";

   like($warned_string, qr{^arr: \[\n  "wut",\n  "HALP",?\n\]\n str: "gnarl"\n\z}, 'DumperF works!');
   ok eq_array($foo[0], ['wut','HALP']) && $foo[1] eq 'gnarl', 'DwarnF passes lists through correctly';
}

DWARNN: {
   my $loaded = eval { require Devel::ArgNames; 1 };
   if ($loaded) {
      my $x = [1];
      my $foo = DwarnN $x;
      like $warned_string, qr{^\$x => \[\n  1,?\n\]\n\z}, 'DwarnN warns';

      ok eq_array($foo, [1]), 'DwarnN passes through correctly';

      DwarnN [1];
      like $warned_string, qr{^\(anon\) => \[\n  1,?\n\]\n\z}, 'DwarnN warns';
   }
}

DDIE: {
   eval {
      DdieS [ 'k', 'bar' ];
   };
   like $@, qr{^\[\n  "k",\n  "bar",?\n\]\n\z}, 'DwarnD dies output correctly';
}