Debian Codegraph @

t/multihash.t

raw symbols SCIP
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use Test::Exception;
8
9 use Digest::MultiHash;
10
11 BEGIN {
12 plan skip_all => "No hash modules found"
13 unless eval { Digest::MultiHash->new }
14 and $@ !~ /^Can't find any digest module/;
15
16 plan tests => 5;
17 }
18
19 my $d = Digest::MultiHash->new;
20
21 isa_ok( $d , "Digest::base" );
22
23 $d->width( 8 );
24
25 $d->add("foo bar gorch");
26
27 my $d2 = Digest::MultiHash->new( width => 8 );
28
29 $d2->add("foo bar moose");
30
31 my $hash2 = $d2->digest;
32
33 cmp_ok( $d->digest, "ne", $hash2, "digests differ" );
34
35 is( length($hash2), 8, "the hash width is 8" );
36
37 throws_ok {
38 my $d = Digest::MultiHash->new(
39 width => 1024, # only 20 bytes in sha1
40 );
41
42 $d->add("foo");
43
44 $d->digest;
45 } qr/insufficient.*width/, "Insufficient width causes error";
46
47 throws_ok {
48 Digest::MultiHash->new( hashes => [] );
49 } qr/No digest module specified/, "Can't construct without hashes";
50