forked from amiri/Digest-PBKDF2
/
03_cloning.t
executable file
·52 lines (34 loc) · 1.25 KB
/
03_cloning.t
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
51
use Test::More tests => 13;
use strict;
use warnings;
use Digest::PBKDF2;
use Scalar::Util qw(refaddr);
use Test::Exception;
my $orig = Digest::PBKDF2->new;
lives_ok( sub { $orig->add('cool') }, "I can add one chunk" );
lives_ok( sub { $orig->add('jazz') }, "I can add another chunk" );
lives_ok( sub { $orig->salt('salt') }, "I can add salt" );
lives_ok( sub { $orig->iterations(1000) }, "I can add an iteration count" );
my $clone;
lives_ok( sub { $clone = $orig->clone }, "I can clone my object" );
isnt(
refaddr $orig,
refaddr $clone,
"Cloning gives me a new Digest::PBKDF2 object"
);
isnt(
refaddr \$orig->{_data},
refaddr \$clone->{_data},
"Cloning gives me a new data slot"
);
lives_ok(sub { delete $clone->{_data} }, "I can delete the data in my clone");
is($clone->{_data}, undef, "And the data is gone");
is($orig->{_data}, 'cooljazz', "And the original remains intact");
lives_ok(sub { $clone->add('cooljazz') }, "I can put back the clone data");
my ($clone_digest, $orig_digest) = ($clone->hexdigest, $orig->hexdigest);
is($clone_digest, $orig_digest, "Clone and orginal produce the same string");
is(
$orig_digest,
'ec97d051d529a3d016e17d7a71a69c1124e37f89',
"And that string is what it should be"
);