File: multihash.t

package info (click to toggle)
libcrypt-util-perl 0.11-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 252 kB
  • sloc: perl: 2,438; makefile: 2
file content (50 lines) | stat: -rw-r--r-- 887 bytes parent folder | download | duplicates (6)
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
#!/usr/bin/perl

use strict;
use warnings;

use Test::More;
use Test::Exception;

use Digest::MultiHash;

BEGIN {
	plan skip_all => "No hash modules found"
		unless eval { Digest::MultiHash->new }
			and $@ !~ /^Can't find any digest module/;

	plan tests => 5;
}

my $d = Digest::MultiHash->new;

isa_ok( $d , "Digest::base" );

$d->width( 8 );

$d->add("foo bar gorch");

my $d2 = Digest::MultiHash->new( width => 8 );

$d2->add("foo bar moose");

my $hash2 = $d2->digest;

cmp_ok( $d->digest, "ne", $hash2, "digests differ" );

is( length($hash2), 8, "the hash width is 8" );

throws_ok {
	my $d = Digest::MultiHash->new(
		width => 1024, # only 20 bytes in sha1
	);

	$d->add("foo");

	$d->digest;
} qr/insufficient.*width/, "Insufficient width causes error";

throws_ok {
	Digest::MultiHash->new( hashes => [] );
} qr/No digest module specified/, "Can't construct without hashes";