Re: the remaining bugs in \x escapes (was Re: [PATCH] oct and hex in glorious 64...
[p5sagit/p5-mst-13.2.git] / t / op / tr.t
index b10f4f2..6390f6a 100755 (executable)
--- a/t/op/tr.t
+++ b/t/op/tr.t
@@ -5,7 +5,7 @@ BEGIN {
     @INC = '../lib';
 }
 
-print "1..55\n";
+print "1..70\n";
 
 $_ = "abcdefghijklmnopqrstuvwxyz";
 
@@ -80,9 +80,6 @@ else {
 print "ok 10\n";
 
 {
-if (ord("\t") == 9) { # ASCII
-    use utf8;
-}
 # 11 - changing UTF8 characters in a UTF8 string, same length.
 my $l = chr(300); my $r = chr(400);
 $x = 200.300.400;
@@ -315,3 +312,79 @@ print "ok 54\n";
 print "not " unless $a eq "X";
 print "ok 55\n"; 
 
+# UTF8 range tests from Inaba Hiroto
+
+($a = "\x{200}") =~ tr/\x00-\x{100}/X/c;
+print "not " unless $a eq "X";
+print "ok 56\n";
+
+($a = "\x{200}") =~ tr/\x00-\x{100}/X/cs;
+print "not " unless $a eq "X";
+print "ok 57\n";
+
+# Tricky on EBCDIC: while [a-z] [A-Z] must not match the gap characters,
+# (i-j, r-s, I-J, R-S), [\x89-\x91] [\xc9-\xd1] has to match them,
+# from Karsten Sperling.
+
+$c = ($a = "\x89\x8a\x8b\x8c\x8d\x8f\x90\x91") =~ tr/\x89-\x91/X/;
+print "not " unless $c == 8 and $a eq "XXXXXXXX";
+print "ok 58\n";
+   
+$c = ($a = "\xc9\xca\xcb\xcc\xcd\xcf\xd0\xd1") =~ tr/\xc9-\xd1/X/;
+print "not " unless $c == 8 and $a eq "XXXXXXXX";
+print "ok 59\n";
+   
+if (ord('i') == 0x89 & ord('J') == 0xd1) {
+
+$c = ($a = "\x89\x8a\x8b\x8c\x8d\x8f\x90\x91") =~ tr/i-j/X/;
+print "not " unless $c == 2 and $a eq "X\x8a\x8b\x8c\x8d\x8f\x90X";
+print "ok 60\n";
+   
+$c = ($a = "\xc9\xca\xcb\xcc\xcd\xcf\xd0\xd1") =~ tr/I-J/X/;
+print "not " unless $c == 2 and $a eq "X\xca\xcb\xcc\xcd\xcf\xd0X";
+print "ok 61\n";
+
+} else {
+  for (60..61) { print "ok $_ # Skip: not EBCDIC\n" }
+}
+
+($a = "\x{100}") =~ tr/\x00-\xff/X/c;
+print "not " unless ord($a) == ord("X");
+print "ok 62\n";
+
+($a = "\x{100}") =~ tr/\x00-\xff/X/cs;
+print "not " unless ord($a) == ord("X");
+print "ok 63\n";
+
+($a = "\x{100}\x{100}") =~ tr/\x{101}-\x{200}//c;
+print "not " unless $a eq "\x{100}\x{100}";
+print "ok 64\n";
+
+($a = "\x{100}\x{100}") =~ tr/\x{101}-\x{200}//cs;
+print "not " unless $a eq "\x{100}";
+print "ok 65\n";
+
+$a = "\xfe\xff"; $a =~ tr/\xfe\xff/\x{1ff}\x{1fe}/;
+print "not " unless $a eq "\x{1ff}\x{1fe}";
+print "ok 66\n";
+
+# From David Dyck
+($a = "R0_001") =~ tr/R_//d;
+print "not " if hex($a) != 1;
+print "ok 67\n";
+
+# From Inaba Hiroto
+@a = (1,2); map { y/1/./ for $_ } @a;
+print "not " if "@a" ne ". 2";
+print "ok 68\n";
+
+@a = (1,2); map { y/1/./ for $_.'' } @a;
+print "not " if "@a" ne "1 2";
+print "ok 69\n";
+
+# Additional test for Inaba Hiroto patch (robin@kitsite.com)
+($a = "\x{100}\x{102}\x{101}") =~ tr/\x00-\377/XYZ/c;
+print "not " unless $a eq "XZY";
+print "ok 70\n";
+
+