1N/ABEGIN {
1N/A require Config; import Config;
1N/A if ($Config{'extensions'} !~ /\bEncode\b/) {
1N/A print "1..0 # Skip: Encode was not built\n";
1N/A exit 0;
1N/A }
1N/A unless (find PerlIO::Layer 'perlio') {
1N/A print "1..0 # Skip: PerlIO was not built\n";
1N/A exit 0;
1N/A }
1N/A if (ord("A") == 193) {
1N/A print "1..0 # encoding pragma does not support EBCDIC platforms\n";
1N/A exit(0);
1N/A }
1N/A}
1N/A
1N/Aprint "1..31\n";
1N/A
1N/Ause encoding "latin1"; # ignored (overwritten by the next line)
1N/Ause encoding "greek"; # iso 8859-7 (no "latin" alias, surprise...)
1N/A
1N/A# "greek" is "ISO 8859-7", and \xDF in ISO 8859-7 is
1N/A# \x{3AF} in Unicode (GREEK SMALL LETTER IOTA WITH TONOS),
1N/A# instead of \xDF in Unicode (LATIN SMALL LETTER SHARP S)
1N/A
1N/A$a = "\xDF";
1N/A$b = "\x{100}";
1N/A
1N/Aprint "not " unless ord($a) == 0x3af;
1N/Aprint "ok 1\n";
1N/A
1N/Aprint "not " unless ord($b) == 0x100;
1N/Aprint "ok 2\n";
1N/A
1N/Amy $c;
1N/A
1N/A$c = $a . $b;
1N/A
1N/Aprint "not " unless ord($c) == 0x3af;
1N/Aprint "ok 3\n";
1N/A
1N/Aprint "not " unless length($c) == 2;
1N/Aprint "ok 4\n";
1N/A
1N/Aprint "not " unless ord(substr($c, 1, 1)) == 0x100;
1N/Aprint "ok 5\n";
1N/A
1N/Aprint "not " unless ord(chr(0xdf)) == 0x3af; # spooky
1N/Aprint "ok 6\n";
1N/A
1N/Aprint "not " unless ord(pack("C", 0xdf)) == 0x3af;
1N/Aprint "ok 7\n";
1N/A
1N/A# we didn't break pack/unpack, I hope
1N/A
1N/Aprint "not " unless unpack("C", pack("C", 0xdf)) == 0xdf;
1N/Aprint "ok 8\n";
1N/A
1N/A# the first octet of UTF-8 encoded 0x3af
1N/Aprint "not " unless unpack("C", chr(0xdf)) == 0xce;
1N/Aprint "ok 9\n";
1N/A
1N/Aprint "not " unless unpack("U", pack("U", 0xdf)) == 0xdf;
1N/Aprint "ok 10\n";
1N/A
1N/Aprint "not " unless unpack("U", chr(0xdf)) == 0x3af;
1N/Aprint "ok 11\n";
1N/A
1N/A# charnames must still work
1N/Ause charnames ':full';
1N/Aprint "not " unless ord("\N{LATIN SMALL LETTER SHARP S}") == 0xdf;
1N/Aprint "ok 12\n";
1N/A
1N/A# combine
1N/A
1N/A$c = "\xDF\N{LATIN SMALL LETTER SHARP S}" . chr(0xdf);
1N/A
1N/Aprint "not " unless ord($c) == 0x3af;
1N/Aprint "ok 13\n";
1N/A
1N/Aprint "not " unless ord(substr($c, 1, 1)) == 0xdf;
1N/Aprint "ok 14\n";
1N/A
1N/Aprint "not " unless ord(substr($c, 2, 1)) == 0x3af;
1N/Aprint "ok 15\n";
1N/A
1N/A# regex literals
1N/A
1N/Aprint "not " unless "\xDF" =~ /\x{3AF}/;
1N/Aprint "ok 16\n";
1N/A
1N/Aprint "not " unless "\x{3AF}" =~ /\xDF/;
1N/Aprint "ok 17\n";
1N/A
1N/Aprint "not " unless "\xDF" =~ /\xDF/;
1N/Aprint "ok 18\n";
1N/A
1N/Aprint "not " unless "\x{3AF}" =~ /\x{3AF}/;
1N/Aprint "ok 19\n";
1N/A
1N/A# eq, cmp
1N/A
1N/Amy ($byte,$bytes,$U,$Ub,$g1,$g2,$l) = (
1N/A pack("C*", 0xDF ), # byte
1N/A pack("C*", 0xDF, 0x20), # ($bytes2 cmp $U) > 0
1N/A pack("U*", 0x3AF), # $U eq $byte
1N/A pack("U*", 0xDF ), # $Ub would eq $bytev w/o use encoding
1N/A pack("U*", 0x3B1), # ($g1 cmp $byte) > 0; === chr(0xe1)
1N/A pack("U*", 0x3AF, 0x20), # ($g2 cmp $byte) > 0;
1N/A pack("U*", 0x3AB), # ($l cmp $byte) < 0; === chr(0xdb)
1N/A);
1N/A
1N/A# all the tests in this section that compare a byte encoded string
1N/A# ato UTF-8 encoded are run in all possible vairants
1N/A# all of the eq, ne, cmp operations tested,
1N/A# $v z $u tested as well as $u z $v
1N/A
1N/Asub alleq($$){
1N/A my ($a,$b) = (shift, shift);
1N/A $a eq $b && $b eq $a &&
1N/A !( $a ne $b ) && !( $b ne $a ) &&
1N/A ( $a cmp $b ) == 0 && ( $b cmp $a ) == 0;
1N/A}
1N/A
1N/Asub anyeq($$){
1N/A my ($a,$b) = (shift, shift);
1N/A $a eq $b || $b eq $a ||
1N/A !( $a ne $b ) || !( $b ne $a ) ||
1N/A ( $a cmp $b ) == 0 || ( $b cmp $a ) == 0;
1N/A}
1N/A
1N/Asub allgt($$){
1N/A my ($a,$b) = (shift, shift);
1N/A ( $a cmp $b ) == 1 && ( $b cmp $a ) == -1;
1N/A}
1N/A#match the correct UTF-8 string
1N/Aprint "not " unless alleq($byte, $U);
1N/Aprint "ok 20\n";
1N/A
1N/A#do not match a wrong UTF-8 string
1N/Aprint "not " if anyeq($byte, $Ub);
1N/Aprint "ok 21\n";
1N/A
1N/A#string ordering
1N/Aprint "not " unless allgt ( $g1, $byte ) &&
1N/A allgt ( $g2, $byte ) &&
1N/A allgt ( $byte, $l ) &&
1N/A allgt ( $bytes, $U );
1N/Aprint "ok 22\n";
1N/A
1N/A# upgrade, downgrade
1N/A
1N/Amy ($u,$v,$v2);
1N/A$u = $v = $v2 = pack("C*", 0xDF);
1N/Autf8::upgrade($v); #explicit upgrade
1N/A$v2 = substr( $v2."\x{410}", 0, -1); #implicit upgrade
1N/A
1N/A# implicit upgrade === explicit upgrade
1N/Aprint "not " if do{{use bytes; $v ne $v2}} || $v ne $v2;
1N/Aprint "ok 23\n";
1N/A
1N/A# utf8::upgrade is transparent and does not break equality
1N/Aprint "not " unless alleq( $u, $v );
1N/Aprint "ok 24\n";
1N/A
1N/A$u = $v = pack("C*", 0xDF);
1N/Autf8::upgrade($v);
1N/A#test for a roundtrip, we should get back from where we left
1N/Aeval {utf8::downgrade( $v )};
1N/Aprint "not " if $@ !~ /^Wide / || do{{use bytes; $u eq $v}} || $u ne $v;
1N/Aprint "ok 25\n";
1N/A
1N/A# some more eq, cmp
1N/A
1N/A$byte=pack("C*", 0xDF);
1N/A
1N/Aprint "not " unless pack("U*", 0x3AF) eq $byte;
1N/Aprint "ok 26\n";
1N/A
1N/Aprint "not " if chr(0xDF) cmp $byte;
1N/Aprint "ok 27\n";
1N/A
1N/Aprint "not " unless ((pack("U*", 0x3B0) cmp $byte) == 1) &&
1N/A ((pack("U*", 0x3AE) cmp $byte) == -1) &&
1N/A ((pack("U*", 0x3AF, 0x20) cmp $byte) == 1) &&
1N/A ((pack("U*", 0x3AF) cmp pack("C*",0xDF,0x20))==-1);
1N/Aprint "ok 28\n";
1N/A
1N/A
1N/A{
1N/A # Used to core dump in 5.7.3
1N/A no warnings; # so test goes noiselessly
1N/A print ord(undef) == 0 ? "ok 29\n" : "not ok 29\n";
1N/A}
1N/A
1N/A{
1N/A my %h1;
1N/A my %h2;
1N/A $h1{"\xdf"} = 41;
1N/A $h2{"\x{3af}"} = 42;
1N/A print $h1{"\x{3af}"} == 41 ? "ok 30\n" : "not ok 30\n";
1N/A print $h2{"\xdf"} == 42 ? "ok 31\n" : "not ok 31\n";
1N/A}