summaryrefslogtreecommitdiffstats
path: root/gnu/usr.bin/perl/cpan/Digest-MD5/t/context.t
blob: e5f79a4f04855f45e3a3bfc7b0053416ff7821a0 (plain) (blame)
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
#!/usr/bin/perl
use strict;
use warnings;

use Test::More;
use Digest::MD5;

foreach my $string ( map { 'a' x $_ }
    1..17,
    31..33,
    64..65,
    127..129,
    191..193,
    1023..1025,
    2047..2049,
) {
    my $expect = do {
        my $ctx = Digest::MD5->new;
        $ctx->add($string);
        $ctx->add($string);
        $ctx->add($string);
        $ctx->hexdigest;
    };

    my $got = do {
        my $ctx1 = Digest::MD5->new;
        $ctx1->add($string);

        my $ctx2 = Digest::MD5->new;
        $ctx2->context( $ctx1->context );
        $ctx2->add($string);

        my $ctx3 = Digest::MD5->new;
        $ctx3->context( $ctx2->context );
        $ctx3->add($string);

        $ctx3->hexdigest;
    };

    is $got, $expect, length($string) . " saved context";
}

done_testing;