Extend the effect of the encoding pragma to chr() and ord().
[p5sagit/p5-mst-13.2.git] / lib / encoding.t
1 print "1..9\n";
2
3 use encoding "latin1"; # ignored (overwritten by the next line)
4 use encoding "greek";  # iso 8859-7 (no "latin" alias, surprise...)
5
6 # "greek" is "ISO 8859-7", and \xDF in ISO 8859-7 is
7 # \x{3AF} in Unicode (GREEK SMALL LETTER IOTA WITH TONOS),
8 # instead of \xDF in Unicode (LATIN SMALL LETTER SHARP S)
9
10 $a = "\xDF";
11 $b = "\x{100}";
12
13 print "not " unless ord($a) == 0x3af;
14 print "ok 1\n";
15
16 print "not " unless ord($b) == 0x100;
17 print "ok 2\n";
18
19 my $c;
20
21 $c = $a . $b;
22
23 print "not " unless ord($c) == 0x3af;
24 print "ok 3\n";
25
26 print "not " unless length($c) == 2;
27 print "ok 4\n";
28
29 print "not " unless ord(substr($c, 1, 1)) == 0x100;
30 print "ok 5\n";
31
32 print "not " unless ord(chr(0xdf)) == 0x3af; # spooky
33 print "ok 6\n";
34
35 print "not " unless ord(pack("C", 0xdf)) == 0x3af;
36 print "ok 7\n";
37
38 # we didn't break pack/unpack, I hope
39
40 print "not " unless unpack("C", pack("C", 0xdf)) == 0xdf;
41 print "ok 8\n";
42
43 # the first octet of UTF-8 encoded 0x3af 
44 print "not " unless unpack("C", chr(0xdf)) == 0xce;
45 print "ok 9\n";