Old(er) perls (e.g. 5.8.0) do not like \my $x, more
[Data-Peek.git] / t / 10_DDumper.t
blobf28c09c8a9dc9ccd571ffe06182b21750ab54725
1 #!/usr/bin/perl
3 use strict;
4 use warnings;
6 use Test::More tests => 55;
7 use Test::NoWarnings;
9 BEGIN {
10 use_ok "Data::Peek";
11 die "Cannot load Data::Peek\n" if $@; # BAIL_OUT not avail in old Test::More
14 my ($dump, $var) = ("", "");
15 while (<DATA>) {
16 chomp;
17 my ($v, $exp, $re) = split m/\t+ */;
19 if ($v eq "--") {
20 ok (1, "** $exp");
21 next;
24 $v =~ s/^S:([^:]*):// and DDsort ($1), $v =~ m/^()/; # And reset $1 for below
26 unless ($v eq "") {
27 eval "\$var = $v";
28 ok ($dump = DDumper ($var), "DDumper ($v)");
29 $dump =~ s/\A\$VAR1 = //;
30 $dump =~ s/;?\n\Z//;
32 if ($re) {
33 like ($dump, qr{$exp}ms, ".. content $re");
34 $1 and diag "# '$1' (", length ($1), ")\n";
36 else {
37 is ($dump, $exp, ".. content");
43 __END__
44 -- Basic values
45 undef undef
46 1 1
47 "" ''
48 "\xa8" '¨'
49 1.24 '1.24'
50 \undef \undef
51 \1 \1
52 \"" \''
53 \"\xa8" \'¨'
54 (0, 1) 1
55 \(0, 1) \1
56 -- Structures
57 [0, 1] ^\[ 0,\n line 1
58 ^ 1\n line 2
59 ^ ]\Z line 3
60 [0,1,2] \A\[\s+0,\n\s+1,\n\s+2\n\s+]\Z line splitting
61 -- Indentation
62 [0] \A\[ 0\n ]\Z single indent
63 [[0],{foo=>1}] ^\[\n outer list
64 ^ {4}\[ 0\n {8}],\n {4} inner list
65 ^ {4}\{ foo {14}=> 1\n {8}}\n inner hash
66 ^ {4}]\Z outer list end
67 [[0],{foo=>1}] \A\[\n {4}\[ 0\n {8}],\n {4}\{ foo {14}=> 1\n {8}}\n {4}]\Z full struct
68 -- Sorting
69 S:1:{ab=>1,bc=>2,cd=>3,de=>13} ab.*bc.*cd.*de default sort
70 S:R:{ab=>1,bc=>2,cd=>3,de=>13} de.*cd.*bc.*ab reverse sort
71 S:V:{ab=>1,bc=>2,cd=>3,de=>13} 1.*13.*2.*3 sort by value
72 S:VR:{ab=>1,bc=>2,cd=>3,de=>13} 3.*2.*13.*1 reverse sort by value
73 S:VN:{ab=>1,bc=>2,cd=>3,de=>13} 1.*2.*3.*13 sort by value numeric
74 S:VNR:{ab=>1,bc=>2,cd=>3,d=>13} 13.*3.*2.*1 reverse sort by value numeric