xref: /openbsd-src/gnu/usr.bin/perl/cpan/Digest-MD5/t/utf8.t (revision 5486feefcc8cb79b19e014ab332cc5dfd05b3b33)
1#!perl -w
2
3use strict;
4use warnings;
5
6use Digest::MD5 qw(md5_hex);
7
8print "1..5\n";
9
10my $str;
11$str = "foo\xFF\x{100}";
12
13eval {
14    print md5_hex($str);
15    print "not ok 1\n";  # should not run
16};
17print "not " unless $@ && $@ =~ /^(Big byte|Wide character)/;
18print "ok 1\n";
19
20my $exp = ord "A" == 193 ? # EBCDIC
21    "c307ec81deba65e9a222ca81cd8f6ccd" :
22    "503debffe559537231ed24f25651ec20"; # Latin 1
23
24chop($str);  # only bytes left
25print "not " unless md5_hex($str) eq $exp;
26print "ok 2\n";
27
28# reference
29print "not " unless md5_hex("foo\xFF") eq $exp;
30print "ok 3\n";
31
32# autopromotion
33if ($] >= 5.007003) {
34
35my $unistring = "Oslo.pm har sosialt medlemsmøte onsdag 1. April 2008, klokken 18:30. Vi treffes på Marhaba Café, Keysersgate 1.";
36
37require Encode;
38$unistring = Encode::decode_utf8($unistring);
39print "not " if ( not utf8::is_utf8($unistring));
40print "ok 4\n";
41
42md5_hex($unistring, "");
43print "not " if ( not utf8::is_utf8($unistring));
44print "ok 5\n"
45
46} else {
47    print "ok 4 # SKIP Your perl is too old to properly test unicode semantics\nok 5 # SKIP No, really\n";
48}
49