2 require Config; import Config;
3 if ($Config{'extensions'} !~ /\bEncode\b/) {
4 print "1..0 # Skip: Encode was not built\n";
7 unless (find PerlIO::Layer 'perlio') {
8 print "1..0 # Skip: PerlIO was not built\n";
11 if (ord("A") == 193) {
12 print "1..0 # encoding pragma does not support EBCDIC platforms\n";
19 use encoding "latin1"; # ignored (overwritten by the next line)
20 use encoding "greek"; # iso 8859-7 (no "latin" alias, surprise...)
22 # "greek" is "ISO 8859-7", and \xDF in ISO 8859-7 is
23 # \x{3AF} in Unicode (GREEK SMALL LETTER IOTA WITH TONOS),
24 # instead of \xDF in Unicode (LATIN SMALL LETTER SHARP S)
29 print "not " unless ord($a) == 0x3af;
32 print "not " unless ord($b) == 0x100;
39 print "not " unless ord($c) == 0x3af;
42 print "not " unless length($c) == 2;
45 print "not " unless ord(substr($c, 1, 1)) == 0x100;
48 print "not " unless ord(chr(0xdf)) == 0x3af; # spooky
51 print "not " unless ord(pack("C", 0xdf)) == 0x3af;
54 # we didn't break pack/unpack, I hope
56 print "not " unless unpack("C", pack("C", 0xdf)) == 0xdf;
59 # the first octet of UTF-8 encoded 0x3af
60 print "not " unless unpack("C", chr(0xdf)) == 0xce;
63 print "not " unless unpack("U", pack("U", 0xdf)) == 0xdf;
66 print "not " unless unpack("U", chr(0xdf)) == 0x3af;
69 # charnames must still work
70 use charnames ':full';
71 print "not " unless ord("\N{LATIN SMALL LETTER SHARP S}") == 0xdf;
76 $c = "\xDF\N{LATIN SMALL LETTER SHARP S}" . chr(0xdf);
78 print "not " unless ord($c) == 0x3af;
81 print "not " unless ord(substr($c, 1, 1)) == 0xdf;
84 print "not " unless ord(substr($c, 2, 1)) == 0x3af;
89 print "not " unless "\xDF" =~ /\x{3AF}/;
92 print "not " unless "\x{3AF}" =~ /\xDF/;
95 print "not " unless "\xDF" =~ /\xDF/;
98 print "not " unless "\x{3AF}" =~ /\x{3AF}/;
103 my ($byte,$bytes,$U,$Ub,$g1,$g2,$l) = (
104 pack("C*", 0xDF ), # byte
105 pack("C*", 0xDF, 0x20), # ($bytes2 cmp $U) > 0
106 pack("U*", 0x3AF), # $U eq $byte
107 pack("U*", 0xDF ), # $Ub would eq $bytev w/o use encoding
108 pack("U*", 0x3B1), # ($g1 cmp $byte) > 0; === chr(0xe1)
109 pack("U*", 0x3AF, 0x20), # ($g2 cmp $byte) > 0;
110 pack("U*", 0x3AB), # ($l cmp $byte) < 0; === chr(0xdb)
113 # all the tests in this section that compare a byte encoded string
114 # ato UTF-8 encoded are run in all possible vairants
115 # all of the eq, ne, cmp operations tested,
116 # $v z $u tested as well as $u z $v
119 my ($a,$b) = (shift, shift);
120 $a eq $b && $b eq $a &&
121 !( $a ne $b ) && !( $b ne $a ) &&
122 ( $a cmp $b ) == 0 && ( $b cmp $a ) == 0;
126 my ($a,$b) = (shift, shift);
127 $a eq $b || $b eq $a ||
128 !( $a ne $b ) || !( $b ne $a ) ||
129 ( $a cmp $b ) == 0 || ( $b cmp $a ) == 0;
133 my ($a,$b) = (shift, shift);
134 ( $a cmp $b ) == 1 && ( $b cmp $a ) == -1;
136 #match the correct UTF-8 string
137 print "not " unless alleq($byte, $U);
140 #do not match a wrong UTF-8 string
141 print "not " if anyeq($byte, $Ub);
145 print "not " unless allgt ( $g1, $byte ) &&
146 allgt ( $g2, $byte ) &&
147 allgt ( $byte, $l ) &&
148 allgt ( $bytes, $U );
154 $u = $v = $v2 = pack("C*", 0xDF);
155 utf8::upgrade($v); #explicit upgrade
156 $v2 = substr( $v2."\x{410}", 0, -1); #implicit upgrade
158 # implicit upgrade === explicit upgrade
159 print "not " if do{{use bytes; $v ne $v2}} || $v ne $v2;
162 # utf8::upgrade is transparent and does not break equality
163 print "not " unless alleq( $u, $v );
166 $u = $v = pack("C*", 0xDF);
168 #test for a roundtrip, we should get back from where we left
169 eval {utf8::downgrade( $v )};
170 print "not " if $@ !~ /^Wide / || do{{use bytes; $u eq $v}} || $u ne $v;
175 $byte=pack("C*", 0xDF);
177 print "not " unless pack("U*", 0x3AF) eq $byte;
180 print "not " if chr(0xDF) cmp $byte;
183 print "not " unless ((pack("U*", 0x3B0) cmp $byte) == 1) &&
184 ((pack("U*", 0x3AE) cmp $byte) == -1) &&
185 ((pack("U*", 0x3AF, 0x20) cmp $byte) == 1) &&
186 ((pack("U*", 0x3AF) cmp pack("C*",0xDF,0x20))==-1);
191 # Used to core dump in 5.7.3
192 no warnings; # so test goes noiselessly
193 print ord(undef) == 0 ? "ok 29\n" : "not ok 29\n";
201 print $h1{"\x{3af}"} == 41 ? "ok 30\n" : "not ok 30\n";
202 print $h2{"\xdf"} == 42 ? "ok 31\n" : "not ok 31\n";