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