EBCDIC: the encoding pragma would need some rethinking,
[p5sagit/p5-mst-13.2.git] / lib / encoding.t
1 print "1..19\n";
2
3 BEGIN {
4     if (ord("A") == 193) {
5         print "1..0 # encoding pragma does not support EBCDIC platforms\n";
6     }
7 }
8
9 use encoding "latin1"; # ignored (overwritten by the next line)
10 use encoding "greek";  # iso 8859-7 (no "latin" alias, surprise...)
11
12 # "greek" is "ISO 8859-7", and \xDF in ISO 8859-7 is
13 # \x{3AF} in Unicode (GREEK SMALL LETTER IOTA WITH TONOS),
14 # instead of \xDF in Unicode (LATIN SMALL LETTER SHARP S)
15
16 $a = "\xDF";
17 $b = "\x{100}";
18
19 print "not " unless ord($a) == 0x3af;
20 print "ok 1\n";
21
22 print "not " unless ord($b) == 0x100;
23 print "ok 2\n";
24
25 my $c;
26
27 $c = $a . $b;
28
29 print "not " unless ord($c) == 0x3af;
30 print "ok 3\n";
31
32 print "not " unless length($c) == 2;
33 print "ok 4\n";
34
35 print "not " unless ord(substr($c, 1, 1)) == 0x100;
36 print "ok 5\n";
37
38 print "not " unless ord(chr(0xdf)) == 0x3af; # spooky
39 print "ok 6\n";
40
41 print "not " unless ord(pack("C", 0xdf)) == 0x3af;
42 print "ok 7\n";
43
44 # we didn't break pack/unpack, I hope
45
46 print "not " unless unpack("C", pack("C", 0xdf)) == 0xdf;
47 print "ok 8\n";
48
49 # the first octet of UTF-8 encoded 0x3af 
50 print "not " unless unpack("C", chr(0xdf)) == 0xce;
51 print "ok 9\n";
52
53 print "not " unless unpack("U", pack("U", 0xdf)) == 0xdf;
54 print "ok 10\n";
55
56 print "not " unless unpack("U", chr(0xdf)) == 0x3af;
57 print "ok 11\n";
58
59 # charnames must still work
60 use charnames ':full';
61 print "not " unless ord("\N{LATIN SMALL LETTER SHARP S}") == 0xdf;
62 print "ok 12\n";
63
64 # combine
65
66 $c = "\xDF\N{LATIN SMALL LETTER SHARP S}" . chr(0xdf);
67
68 print "not " unless ord($c) == 0x3af;
69 print "ok 13\n";
70
71 print "not " unless ord(substr($c, 1, 1)) == 0xdf;
72 print "ok 14\n";
73
74 print "not " unless ord(substr($c, 2, 1)) == 0x3af;
75 print "ok 15\n";
76
77 # regex literals
78
79 print "not " unless "\xDF"    =~ /\x{3AF}/;
80 print "ok 16\n";
81
82 print "not " unless "\x{3AF}" =~ /\xDF/;
83 print "ok 17\n";
84
85 print "not " unless "\xDF"    =~ /\xDF/;
86 print "ok 18\n";
87
88 print "not " unless "\x{3AF}" =~ /\x{3AF}/;
89 print "ok 19\n";
90