diff options
author | Dan Kogai <dankogai@dan.co.jp> | 2002-10-25 22:04:00 +0900 |
---|---|---|
committer | hv <hv@crypt.org> | 2002-11-07 14:01:57 +0000 |
commit | 0d55c8f7c05ceae7db13bb3863932232a57c2a7b (patch) | |
tree | 7b566936ad351672fda773b3503133ef8d430e3e /t | |
parent | c6d63c67cbd3ac9fa6ff9e314b9945f590abfc9d (diff) | |
download | perl-0d55c8f7c05ceae7db13bb3863932232a57c2a7b.tar.gz |
Re: The Inaba patch for tr/// vs. use encoding
Message-Id: <CAC896FE-E7CE-11D6-9228-0003939A104C@dan.co.jp>
p4raw-id: //depot/perl@18125
Diffstat (limited to 't')
-rw-r--r-- | t/uni/tr_7jis.t | 61 | ||||
-rw-r--r-- | t/uni/tr_eucjp.t | 59 | ||||
-rw-r--r-- | t/uni/tr_sjis.t | 59 | ||||
-rw-r--r-- | t/uni/tr_utf8.t | 62 |
4 files changed, 241 insertions, 0 deletions
diff --git a/t/uni/tr_7jis.t b/t/uni/tr_7jis.t new file mode 100644 index 0000000000..292a01a798 --- /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 0000000000..e13acab0ed --- /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 0000000000..f5ad045f0e --- /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 0000000000..54b9b4ff37 --- /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__ |