From: Dan Kogai Date: Fri, 25 Oct 2002 13:04:00 +0000 (+0900) Subject: Re: The Inaba patch for tr/// vs. use encoding X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0d55c8f7c05ceae7db13bb3863932232a57c2a7b;p=p5sagit%2Fp5-mst-13.2.git Re: The Inaba patch for tr/// vs. use encoding Message-Id: p4raw-id: //depot/perl@18125 --- diff --git a/MANIFEST b/MANIFEST index e5e5c90..69dbb07 100644 --- a/MANIFEST +++ b/MANIFEST @@ -2674,6 +2674,10 @@ t/uni/fold.t See if Unicode folding works t/uni/lower.t See if Unicode casing works t/uni/sprintf.t See if Unicode sprintf works t/uni/title.t See if Unicode casing works +t/uni/tr_7jis.t See if Unicode tr/// works +t/uni/tr_eucjp.t See if Unicode tr/// works +t/uni/tr_sjis.t See if Unicode tr/// works +t/uni/tr_utf8.t See if Unicode tr/// works t/uni/upper.t See if Unicode casing works t/win32/longpath.t Test if Win32::GetLongPathName() works t/win32/system.t See if system works in Win* diff --git a/t/uni/tr_7jis.t b/t/uni/tr_7jis.t new file mode 100644 index 0000000..292a01a --- /dev/null +++ b/t/uni/tr_7jis.t @@ -0,0 +1,61 @@ +# +# $Id$ +# +# This script is written intentionally in EUC-JP +# -- dankogai + +BEGIN { + if ($ENV{'PERL_CORE'}){ + chdir 't'; + unshift @INC, '../lib'; + } + require Config; import Config; + if ($Config{'extensions'} !~ /\bEncode\b/) { + print "1..0 # Skip: Encode was not built\n"; + exit 0; + } + if (ord("A") == 193) { + print "1..0 # Skip: EBCDIC\n"; + exit 0; + } + unless (PerlIO::Layer->find('perlio')){ + print "1..0 # Skip: PerlIO required\n"; + exit 0; + } + $| = 1; + print "1..0 # does not work with iso-2022-jp yet\n"; + exit 0; +} + +use strict; +#use Test::More qw(no_plan); +use Test::More tests => 6; +use Encode; +use encoding 'iso-2022-jp'; + +my @hiragana = map {chr} ord("$B$!(B")..ord("$B$s(B"); +my @katakana = map {chr} ord("$B%!(B")..ord("$B%s(B"); +my $hiragana = join('' => @hiragana); +my $katakana = join('' => @katakana); +my %h2k; @h2k{@hiragana} = @katakana; +my %k2h; @k2h{@katakana} = @hiragana; + +# print @hiragana, "\n"; + +my $str; + +$str = $hiragana; $str =~ tr/$B$!(B-$B$s(B/$B%!(B-$B%s(B/; +is($str, $katakana, "tr// # hiragana -> katakana"); +$str = $katakana; $str =~ tr/$B%!(B-$B%s(B/$B$!(B-$B$s(B/; +is($str, $hiragana, "tr// # hiragana -> katakana"); + +$str = $hiragana; eval qq(\$str =~ tr/$B$!(B-$B$s(B/$B%!(B-$B%s(B/); +is($str, $katakana, "eval qq(tr//) # hiragana -> katakana"); +$str = $katakana; eval qq(\$str =~ tr/$B%!(B-$B%s(B/$B$!(B-$B$s(B/); +is($str, $hiragana, "eval qq(tr//) # hiragana -> katakana"); + +$str = $hiragana; $str =~ s/([$B$!(B-$B$s(B])/$h2k{$1}/go; +is($str, $katakana, "s/// # hiragana -> katakana"); +$str = $katakana; $str =~ s/([$B%!(B-$B%s(B])/$k2h{$1}/go; +is($str, $hiragana, "s/// # hiragana -> katakana"); +__END__ diff --git a/t/uni/tr_eucjp.t b/t/uni/tr_eucjp.t new file mode 100644 index 0000000..e13acab --- /dev/null +++ b/t/uni/tr_eucjp.t @@ -0,0 +1,59 @@ +# +# $Id$ +# +# This script is written intentionally in EUC-JP +# -- dankogai + +BEGIN { + if ($ENV{'PERL_CORE'}){ + chdir 't'; + unshift @INC, '../lib'; + } + require Config; import Config; + if ($Config{'extensions'} !~ /\bEncode\b/) { + print "1..0 # Skip: Encode was not built\n"; + exit 0; + } + if (ord("A") == 193) { + print "1..0 # Skip: EBCDIC\n"; + exit 0; + } + unless (PerlIO::Layer->find('perlio')){ + print "1..0 # Skip: PerlIO required\n"; + exit 0; + } + $| = 1; +} + +use strict; +#use Test::More qw(no_plan); +use Test::More tests => 6; +use Encode; +use encoding 'euc-jp'; + +my @hiragana = map {chr} ord("¤¡")..ord("¤ó"); +my @katakana = map {chr} ord("¥¡")..ord("¥ó"); +my $hiragana = join('' => @hiragana); +my $katakana = join('' => @katakana); +my %h2k; @h2k{@hiragana} = @katakana; +my %k2h; @k2h{@katakana} = @hiragana; + +# print @hiragana, "\n"; + +my $str; + +$str = $hiragana; $str =~ tr/¤¡-¤ó/¥¡-¥ó/; +is($str, $katakana, "tr// # hiragana -> katakana"); +$str = $katakana; $str =~ tr/¥¡-¥ó/¤¡-¤ó/; +is($str, $hiragana, "tr// # hiragana -> katakana"); + +$str = $hiragana; eval qq(\$str =~ tr/¤¡-¤ó/¥¡-¥ó/); +is($str, $katakana, "eval qq(tr//) # hiragana -> katakana"); +$str = $katakana; eval qq(\$str =~ tr/¥¡-¥ó/¤¡-¤ó/); +is($str, $hiragana, "eval qq(tr//) # hiragana -> katakana"); + +$str = $hiragana; $str =~ s/([¤¡-¤ó])/$h2k{$1}/go; +is($str, $katakana, "s/// # hiragana -> katakana"); +$str = $katakana; $str =~ s/([¥¡-¥ó])/$k2h{$1}/go; +is($str, $hiragana, "s/// # hiragana -> katakana"); +__END__ diff --git a/t/uni/tr_sjis.t b/t/uni/tr_sjis.t new file mode 100644 index 0000000..f5ad045 --- /dev/null +++ b/t/uni/tr_sjis.t @@ -0,0 +1,59 @@ +# +# $Id$ +# +# This script is written intentionally in EUC-JP +# -- dankogai + +BEGIN { + if ($ENV{'PERL_CORE'}){ + chdir 't'; + unshift @INC, '../lib'; + } + require Config; import Config; + if ($Config{'extensions'} !~ /\bEncode\b/) { + print "1..0 # Skip: Encode was not built\n"; + exit 0; + } + if (ord("A") == 193) { + print "1..0 # Skip: EBCDIC\n"; + exit 0; + } + unless (PerlIO::Layer->find('perlio')){ + print "1..0 # Skip: PerlIO required\n"; + exit 0; + } + $| = 1; +} + +use strict; +#use Test::More qw(no_plan); +use Test::More tests => 6; +use Encode; +use encoding 'shiftjis'; + +my @hiragana = map {chr} ord("‚Ÿ")..ord("‚ñ"); +my @katakana = map {chr} ord("ƒ@")..ord("ƒ“"); +my $hiragana = join('' => @hiragana); +my $katakana = join('' => @katakana); +my %h2k; @h2k{@hiragana} = @katakana; +my %k2h; @k2h{@katakana} = @hiragana; + +# print @hiragana, "\n"; + +my $str; + +$str = $hiragana; $str =~ tr/‚Ÿ-‚ñ/ƒ@-ƒ“/; +is($str, $katakana, "tr// # hiragana -> katakana"); +$str = $katakana; $str =~ tr/ƒ@-ƒ“/‚Ÿ-‚ñ/; +is($str, $hiragana, "tr// # hiragana -> katakana"); + +$str = $hiragana; eval qq(\$str =~ tr/‚Ÿ-‚ñ/ƒ@-ƒ“/); +is($str, $katakana, "eval qq(tr//) # hiragana -> katakana"); +$str = $katakana; eval qq(\$str =~ tr/ƒ@-ƒ“/‚Ÿ-‚ñ/); +is($str, $hiragana, "eval qq(tr//) # hiragana -> katakana"); + +$str = $hiragana; $str =~ s/([‚Ÿ-‚ñ])/$h2k{$1}/go; +is($str, $katakana, "s/// # hiragana -> katakana"); +$str = $katakana; $str =~ s/([ƒ@-ƒ“])/$k2h{$1}/go; +is($str, $hiragana, "s/// # hiragana -> katakana"); +__END__ diff --git a/t/uni/tr_utf8.t b/t/uni/tr_utf8.t new file mode 100644 index 0000000..54b9b4f --- /dev/null +++ b/t/uni/tr_utf8.t @@ -0,0 +1,62 @@ +# +# $Id$ +# +# This script is written intentionally in EUC-JP +# -- dankogai + +BEGIN { + if ($ENV{'PERL_CORE'}){ + chdir 't'; + unshift @INC, '../lib'; + } + require Config; import Config; + if ($Config{'extensions'} !~ /\bEncode\b/) { + print "1..0 # Skip: Encode was not built\n"; + exit 0; + } + if (ord("A") == 193) { + print "1..0 # Skip: EBCDIC\n"; + exit 0; + } + unless (PerlIO::Layer->find('perlio')){ + print "1..0 # Skip: PerlIO required\n"; + exit 0; + } + $| = 1; +} + +use strict; +#use Test::More qw(no_plan); +use Test::More tests => 6; + +# use encoding 'utf8'; # you can't uncomment this! +# if you uncomment above, you'll get the following (as of Encode 1.80) +# Assertion ((dst)->sv_flags & 0xff) >= SVt_PV failed: +# file "Encode.xs", line 255 at t/uni/tr_utf8.t line 35. + +my @hiragana = map {chr} ord("ぁ")..ord("ん"); +my @katakana = map {chr} ord("ァ")..ord("ン"); +my $hiragana = join('' => @hiragana); +my $katakana = join('' => @katakana); +my %h2k; @h2k{@hiragana} = @katakana; +my %k2h; @k2h{@katakana} = @hiragana; + +# print @hiragana, "\n"; + +my $str; + +$str = $hiragana; $str =~ tr/ぁ-ん/ァ-ン/; +is($str, $katakana, "tr// # hiragana -> katakana"); +$str = $katakana; $str =~ tr/ァ-ン/ぁ-ん/; +is($str, $hiragana, "tr// # hiragana -> katakana"); + +$str = $hiragana; eval qq(\$str =~ tr/ぁ-ん/ァ-ン/); +is($str, $katakana, "eval qq(tr//) # hiragana -> katakana"); +$str = $katakana; eval qq(\$str =~ tr/ァ-ン/ぁ-ん/); +is($str, $hiragana, "eval qq(tr//) # hiragana -> katakana"); + +$str = $hiragana; $str =~ s/([ぁ-ん])/$h2k{$1}/go; +is($str, $katakana, "s/// # hiragana -> katakana"); +$str = $katakana; $str =~ s/([ァ-ン])/$k2h{$1}/go; +is($str, $hiragana, "s/// # hiragana -> katakana"); +__END__