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