Commit | Line | Data |
---|---|---|
ac70dec1 JH |
1 | #!perl -w |
2 | ||
3 | print "1..6\n"; | |
4 | ||
5 | use strict; | |
6 | use Digest::MD5 qw(md5_hex); | |
7 | ||
8 | my $a = Digest::MD5->new; | |
9 | $a->add("a"); | |
10 | my $b = $a->clone; | |
11 | ||
12 | print "not " unless $b->clone->hexdigest eq md5_hex("a"); | |
13 | print "ok 1\n"; | |
14 | ||
15 | $a->add("a"); | |
16 | print "not " unless $a->hexdigest eq md5_hex("aa"); | |
17 | print "ok 2\n"; | |
18 | ||
19 | print "not " unless $a->hexdigest eq md5_hex(""); | |
20 | print "ok 3\n"; | |
21 | ||
22 | $b->add("b"); | |
23 | print "not " unless $b->clone->hexdigest eq md5_hex("ab"); | |
24 | print "ok 4\n"; | |
25 | ||
26 | $b->add("c"); | |
27 | print "not " unless $b->clone->hexdigest eq md5_hex("abc"); | |
28 | print "ok 5\n"; | |
29 | ||
30 | # Test that cloning picks up the correct class for subclasses. | |
31 | { | |
32 | package MD5; | |
33 | @MD5::ISA = qw(Digest::MD5); | |
34 | } | |
35 | ||
36 | $a = MD5->new; | |
37 | $a->add("a"); | |
38 | $b = $a->clone; | |
39 | ||
40 | print "not " unless ref($b) eq "MD5" && $b->add("b")->hexdigest eq md5_hex("ab"); | |
41 | print "ok 6\n"; |