1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
#!/usr/bin/perl
#
use strict;
use Jcode;
use Test;
BEGIN { plan tests => 10 }
my $seq = 0;
sub myok{ # overloads Test::ok;
my ($a, $b, $comment) = @_;
print "not " if $a ne $b;
++$seq;
print "ok $seq # $comment\n";
}
my $file;
my $hiragana; $file = "t/hiragana.euc"; open F, $file or die "$file:$!";
read F, $hiragana, -s $file;
my $katakana; $file = "t/zenkaku.euc"; open F, $file or die "$file:$!";
read F, $katakana, -s $file;
my $stripped; $file = "t/stripped.euc"; open F, $file or die "$file:$!";
read F, $stripped, -s $file;
my %code2str =
(
'A-Za-z��-��-��' => $katakana,
'a-zA-Z��-��-��' => $hiragana,
);
# by Value
for my $icode (keys %code2str){
for my $ocode (keys %code2str){
my $ok;
my $str = $code2str{$icode};
my $out = jcode(\$str)->tr($icode, $ocode)->euc;
myok($out,$code2str{$ocode},
"H2Z: $icode -> $ocode");
}
}
# test tr($s,'','d');
myok(jcode($hiragana)->tr('��-��','','d')->euc, $stripped,
"H2Z: '��-��', '', d");
my $s = '���£á��ģţ�';
my $from = '��-�ڡ�';
myok(jcode( $s, 'euc' )->tr( $from, 'A-Z/' )->euc, 'ABC/DEF', "tr");
myok(jcode( $s, 'euc' )->tr( $from, 'A-Z\/' )->euc, 'ABC\DEF', "tr");
local($SIG{__WARN__}) = sub{}; # suppress eval error
our $T_FLAG = 0;
my $p = __PACKAGE__;
my $j = Jcode->new('a');
$j->tr("//;\$$p\:\:T_FLAG+=1;", "", "");
$j->tr("", "/;\$$p\:\:T_FLAG+=2;", "");
$j->tr("", "", ";\$$p\:\:T_FLAG+=4;");
myok($T_FLAG & 1, 0, "tr/// from escape test");
myok($T_FLAG & 2, 0, "tr/// to escape test");
myok($T_FLAG & 4, 0, "tr/// flag escape test");
__END__
|