summaryrefslogtreecommitdiff
path: root/cpan/Digest-SHA/t/unicode.t
blob: 1e7bd13d53182a4e97cec9a67df31c93ea3c1485 (plain)
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
use strict;

my $MODULE;

BEGIN {
	$MODULE = (-d "src") ? "Digest::SHA" : "Digest::SHA::PurePerl";
	eval "require $MODULE" || die $@;
	$MODULE->import(qw(sha1_hex));
}

BEGIN {
	if ($ENV{PERL_CORE}) {
		chdir 't' if -d 't';
		@INC = '../lib';
	}
}

my $skip = $] < 5.006 ? 1 : 0;

my $TEMPLATE = $] >= 5.006 ? 'U*' : 'C*';
my $empty_unicode = pack($TEMPLATE, ());
my $ok_unicode    = pack($TEMPLATE, (0..255));
my $wide_unicode  = pack($TEMPLATE, (0..256));

print "1..3\n";

unless ($skip) {
	print "not " unless sha1_hex($empty_unicode."abc") eq
		"a9993e364706816aba3e25717850c26c9cd0d89d";
}
print "ok 1", $skip ? " # skip: no Unicode" : "", "\n";

unless ($skip) {
	print "not " unless sha1_hex($ok_unicode) eq
		"4916d6bdb7f78e6803698cab32d1586ea457dfc8";
}
print "ok 2", $skip ? " # skip: no Unicode" : "", "\n";

unless ($skip) {
	eval { sha1_hex($wide_unicode) };
	print "not " unless $@ =~ /Wide character/;
}
print "ok 3", $skip ? " # skip: no Unicode" : "", "\n";