Tests for DDsort
[Data-Peek.git] / t / 10_DDumper.t
blob3afccf155f6655f306baad94fd6641dae0536c07
1 #!/usr/bin/perl
3 use strict;
4 use warnings;
6 use Test::More tests => 56;
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 print STDERR "# '$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] ^\[\n line 1
58 ^ 0,\n line 2
59 ^ 1\n line 3
60 ^ ]\Z line 4
61 [0,1,2] \A\[\n\s+0,\n\s+1,\n\s+2\n\s+]\Z line splitting
62 -- Indentation
63 [0] \A\[\n 0\n ]\Z single indent
64 [[0],{foo=>1}] ^\[\n outer list
65 ^ {4}\[\n {8}0\n {8}],\n {4} inner list
66 ^ {4}\{\n {8}foo {14}=> 1\n {8}}\n inner hash
67 ^ {4}]\Z outer list end
68 [[0],{foo=>1}] \A\[\n {4}\[\n {8}0\n {8}],\n {4}\{\n {8}foo {14}=> 1\n {8}}\n {4}]\Z full struct
69 -- Sorting
70 S:1:{ab=>1,bc=>2,cd=>3,de=>13} ab.*bc.*cd.*de default sort
71 S:R:{ab=>1,bc=>2,cd=>3,de=>13} de.*cd.*bc.*ab reverse sort
72 S:V:{ab=>1,bc=>2,cd=>3,de=>13} 1.*13.*2.*3 sort by value
73 S:VR:{ab=>1,bc=>2,cd=>3,de=>13} 3.*2.*13.*1 reverse sort by value
74 S:VN:{ab=>1,bc=>2,cd=>3,de=>13} 1.*2.*3.*13 sort by value numeric
75 S:VNR:{ab=>1,bc=>2,cd=>3,d=>13} 13.*3.*2.*1 reverse sort by value numeric