Allow length for DHexDump ()
[Data-Peek.git] / t / 22_DHexDump.t
blob0846908f1958ba3d947ebea4156842b5ac60a46a
1 #!/usr/bin/perl
3 use strict;
4 use warnings;
6 use Test::More;
7 #use Test::NoWarnings;
9 use Data::Peek;
11 is (DHexDump (undef), undef, 'undef');
12 is (DHexDump (""), "", '""');
14 for (split m/##\n/ => test_data ()) {
15 my ($desc, $in, $out) = split m/\n-\n/, $_, 3;
17 if ($in =~ s/\t(\d+)$//) {
18 is (scalar DHexDump ($in, $1), $out, "HexDump $desc");
20 else {
21 is (scalar DHexDump ($in), $out, "HexDump $desc");
25 done_testing;
27 sub test_data
29 return <<"EOTD";
30 Single 0
34 0000 30 0
36 Documentation example
38 abc\x{0a}de\x{20ac}fg
40 0000 61 62 63 0a 64 65 e2 82 ac 66 67 abc.de...fg
42 Documentation example with length
44 abc\x{0a}de\x{20ac}fg 6
46 0000 61 62 63 0a 64 65 abc.de
48 Binary data
50 \x01Great wide open space\x02\x{20ac}\n
52 0000 01 47 72 65 61 74 20 77 69 64 65 20 6f 70 65 6e .Great wide open
53 0010 20 73 70 61 63 65 02 e2 82 ac 0a space.....
55 EOTD
56 } # test_data