File: utf8.t

package info (click to toggle)
perl 5.8.4-8sarge6
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 58,128 kB
  • ctags: 31,422
  • sloc: perl: 224,262; ansic: 155,398; sh: 32,253; pascal: 7,747; lisp: 6,121; makefile: 2,341; cpp: 2,035; yacc: 1,019; java: 23
file content (35 lines) | stat: -rwxr-xr-x 659 bytes parent folder | download | duplicates (5)
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
#!perl -w

BEGIN {
    if ($] < 5.006) {
	print "1..0 # Skipped: your perl don't know unicode\n";
	exit;
    }
}

print "1..3\n";

use strict;
use Digest::MD5 qw(md5_hex);

my $str;
$str = "foo\xFF\x{100}";

eval {
    print md5_hex($str);
    print "not ok 1\n";  # should not run
};
print "not " unless $@ && $@ =~ /^(Big byte|Wide character)/;
print "ok 1\n";

my $exp = ord "A" == 193 ? # EBCDIC
	   "c307ec81deba65e9a222ca81cd8f6ccd" :
	   "503debffe559537231ed24f25651ec20"; # Latin 1

chop($str);  # only bytes left
print "not " unless md5_hex($str) eq $exp;
print "ok 2\n";

# reference
print "not " unless md5_hex("foo\xFF") eq $exp;
print "ok 3\n";