File: compare.t

package info (click to toggle)
libdata-hexdump-perl 0.04-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 124 kB
  • sloc: perl: 165; makefile: 2
file content (44 lines) | stat: -rw-r--r-- 708 bytes parent folder | download
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
# -*- Mode: Perl -*-

BEGIN { unshift @INC, "lib", "../lib" }
use strict;
use Data::HexDump;

local $^W = 1;
my $t = 1;
print "1..2\n";

# data
my $org = "";
for (my $i = 0; $i <= 255; $i++) {
  $org .= pack 'C', $i;
}
$org = $org x 17 . "more data";

# non-oo
print &undump(HexDump $org) eq $org ? "" : "not ", "ok $t\n";
$t++;

# data
my $f = new Data::HexDump;
$f->data($org);
print &undump($f->dump) eq $org ? "" : "not ", "ok $t\n";

# filehandle
# todo

# file
# todo

sub undump {
  my $res = shift;
  my @t = split /\n/, $res;
  $res = '';
  splice @t, 0, 2;
  for my $line (@t) {
    $line = substr $line, 10, 49;
    my @n = split / +(?:\- )?/, $line;
    map { $res .= chr hex } @n;
  }
  $res;
}