xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/ext/Encode/t/at-cn.t (revision 0:68f95e015346)
1*0Sstevel@tonic-gateBEGIN {
2*0Sstevel@tonic-gate    if ($ENV{'PERL_CORE'}){
3*0Sstevel@tonic-gate        chdir 't';
4*0Sstevel@tonic-gate	unshift @INC, '../lib';
5*0Sstevel@tonic-gate    }
6*0Sstevel@tonic-gate    require Config; import Config;
7*0Sstevel@tonic-gate    if ($Config{'extensions'} !~ /\bEncode\b/) {
8*0Sstevel@tonic-gate      print "1..0 # Skip: Encode was not built\n";
9*0Sstevel@tonic-gate      exit 0;
10*0Sstevel@tonic-gate    }
11*0Sstevel@tonic-gate    if (ord("A") == 193) {
12*0Sstevel@tonic-gate	print "1..0 # Skip: EBCDIC\n";
13*0Sstevel@tonic-gate	exit 0;
14*0Sstevel@tonic-gate    }
15*0Sstevel@tonic-gate    $| = 1;
16*0Sstevel@tonic-gate}
17*0Sstevel@tonic-gate
18*0Sstevel@tonic-gateuse strict;
19*0Sstevel@tonic-gateuse Test::More tests => 29;
20*0Sstevel@tonic-gateuse Encode;
21*0Sstevel@tonic-gate
22*0Sstevel@tonic-gateno utf8; # we have raw Chinese encodings here
23*0Sstevel@tonic-gate
24*0Sstevel@tonic-gateuse_ok('Encode::CN');
25*0Sstevel@tonic-gate
26*0Sstevel@tonic-gate# Since JP.t already tests basic file IO, we will just focus on
27*0Sstevel@tonic-gate# internal encode / decode test here. Unfortunately, to test
28*0Sstevel@tonic-gate# against all the UniHan characters will take a huge disk space,
29*0Sstevel@tonic-gate# not to mention the time it will take, and the fact that Perl
30*0Sstevel@tonic-gate# did not bundle UniHan.txt anyway.
31*0Sstevel@tonic-gate
32*0Sstevel@tonic-gate# So, here we just test a typical snippet spanning multiple Unicode
33*0Sstevel@tonic-gate# blocks, and hope it can point out obvious errors.
34*0Sstevel@tonic-gate
35*0Sstevel@tonic-gaterun_tests('Simplified Chinese only', {
36*0Sstevel@tonic-gate    'utf'	=> (
37*0Sstevel@tonic-gate12298.26131.32463.12299.31532.19968.21350.
38*0Sstevel@tonic-gate24406.26352.65306.
39*0Sstevel@tonic-gate22823.21705.20094.20803.65292.19975.29289.36164.22987.65292.
40*0Sstevel@tonic-gate20035.32479.22825.12290.
41*0Sstevel@tonic-gate20113.34892.38632.26045.65292.21697.29289.27969.24418.12290.
42*0Sstevel@tonic-gate22823.26126.22987.32456.65292.20845.20301.26102.25104.65292.
43*0Sstevel@tonic-gate26102.20056.20845.40857.20197.24481.22825.12290.
44*0Sstevel@tonic-gate20094.36947.21464.21270.65292.21508.27491.24615.21629.65292.
45*0Sstevel@tonic-gate20445.21512.22823.21644.65292.20035.21033.36126.12290.
46*0Sstevel@tonic-gate39318.20986.24246.29289.65292.19975.22269.21688.23425.12290
47*0Sstevel@tonic-gate    ),
48*0Sstevel@tonic-gate
49*0Sstevel@tonic-gate    'euc-cn'	=> join('',
50*0Sstevel@tonic-gate'���׾�����һ��',
51*0Sstevel@tonic-gate'��Ի��',
52*0Sstevel@tonic-gate'����ǬԪ��������ʼ��',
53*0Sstevel@tonic-gate'��ͳ�졣',
54*0Sstevel@tonic-gate'������ʩ��Ʒ�����Ρ�',
55*0Sstevel@tonic-gate'����ʼ�գ���λʱ�ɣ�',
56*0Sstevel@tonic-gate'ʱ�����������졣',
57*0Sstevel@tonic-gate'Ǭ���仯������������',
58*0Sstevel@tonic-gate'���ϴ�ͣ������ꡣ',
59*0Sstevel@tonic-gate'�׳�������������',
60*0Sstevel@tonic-gate    ),
61*0Sstevel@tonic-gate
62*0Sstevel@tonic-gate    'gb2312-raw'	=> join('',
63*0Sstevel@tonic-gate'!6RW>-!75ZR;XT',
64*0Sstevel@tonic-gate'ehT;#:',
65*0Sstevel@tonic-gate'4sTUG,T*#,MrNoWJJ<#,',
66*0Sstevel@tonic-gate'DKM3Ll!#',
67*0Sstevel@tonic-gate'TFPPSjJ)#,F7NoAwPN!#',
68*0Sstevel@tonic-gate'4sCwJ<VU#,AyN;J13I#,',
69*0Sstevel@tonic-gate'J13KAyAzRTSyLl!#',
70*0Sstevel@tonic-gate'G,5@1d;/#,8wU}PTC|#,',
71*0Sstevel@tonic-gate'1#:O4s:M#,DK@{Uj!#',
72*0Sstevel@tonic-gate'JW3vJ|No#,Mr9zOLD~!#'
73*0Sstevel@tonic-gate    ),
74*0Sstevel@tonic-gate
75*0Sstevel@tonic-gate    'iso-ir-165'=> join('',
76*0Sstevel@tonic-gate'!6RW>-!75ZR;XT',
77*0Sstevel@tonic-gate'ehT;#:',
78*0Sstevel@tonic-gate'4sTUG,T*#,MrNoWJJ<#,',
79*0Sstevel@tonic-gate'DKM3Ll!#',
80*0Sstevel@tonic-gate'TFPPSjJ)#,F7NoAwPN!#',
81*0Sstevel@tonic-gate'4sCwJ<VU#,AyN;J13I#,',
82*0Sstevel@tonic-gate'J13KAyAzRTSyLl!#',
83*0Sstevel@tonic-gate'G,5@1d;/#,8wU}PTC|#,',
84*0Sstevel@tonic-gate'1#:O4s:M#,DK@{Uj!#',
85*0Sstevel@tonic-gate'JW3vJ|No#,Mr9zOLD~!#'
86*0Sstevel@tonic-gate    ),
87*0Sstevel@tonic-gate});
88*0Sstevel@tonic-gate
89*0Sstevel@tonic-gaterun_tests('Simplified Chinese + ASCII', {
90*0Sstevel@tonic-gate    'utf'	=> (
91*0Sstevel@tonic-gate35937.26352.65306.10.
92*0Sstevel@tonic-gate22825.34892.20581.65292.21531.23376.20197.33258.24378.19981.24687.12290.10.
93*0Sstevel@tonic-gate28508.40857.21247.29992.65292.38451.22312.19979.20063.12290.32.
94*0Sstevel@tonic-gate35265.40857.22312.30000.65292.24503.26045.26222.20063.12290.32.
95*0Sstevel@tonic-gate32456.26085.20094.20094.65292.21453.22797.36947.20063.12290.10.
96*0Sstevel@tonic-gate25110.36291.22312.28170.65292.36827.26080.21646.20063.12290.39134.
97*0Sstevel@tonic-gate40857.22312.22825.65292.22823.20154.36896.20063.12290.32.
98*0Sstevel@tonic-gate20130.40857.26377.24724.65292.30408.19981.21487.20037.20063.12290.10.
99*0Sstevel@tonic-gate29992.20061.65292.22825.24503.19981.21487.20026.39318.20063.12290
100*0Sstevel@tonic-gate    ),
101*0Sstevel@tonic-gate
102*0Sstevel@tonic-gate    'cp936'	=> join(chr(10),
103*0Sstevel@tonic-gate'��Ի��',
104*0Sstevel@tonic-gate'���н�����������ǿ��Ϣ��',
105*0Sstevel@tonic-gate'DZ�����ã�������Ҳ�� ���������ʩ��Ҳ�� ����ǬǬ��������Ҳ��',
106*0Sstevel@tonic-gate'��Ծ��Ԩ�����޾�Ҳ���������죬������Ҳ�� �����лڣ�ӯ���ɾ�Ҳ��',
107*0Sstevel@tonic-gate'�þţ���²���Ϊ��Ҳ��',
108*0Sstevel@tonic-gate    ),
109*0Sstevel@tonic-gate
110*0Sstevel@tonic-gate    'hz'	=> join(chr(10),
111*0Sstevel@tonic-gate'~{OsT;#:~}',
112*0Sstevel@tonic-gate'~{LlPP=!#,>}WSRTWTG?2;O"!#~}',
113*0Sstevel@tonic-gate'~{G1AzNpSC#,QtTZOBR2!#~} ~{<{AzTZLo#,5BJ)FUR2!#~} ~{VUHUG,G,#,74845@R2!#~}',
114*0Sstevel@tonic-gate'~{;rT>TZT(#,=xN^>LR2!#7IAzTZLl#,4sHKTlR2!#~} ~{?:AzSP;Z#,S/2;?I>CR2!#~}',
115*0Sstevel@tonic-gate'~{SC>E#,Ll5B2;?IN*JWR2!#~}',
116*0Sstevel@tonic-gate    ),
117*0Sstevel@tonic-gate});
118*0Sstevel@tonic-gate
119*0Sstevel@tonic-gaterun_tests('Traditional Chinese', {
120*0Sstevel@tonic-gate    'utf',	=> 20094.65306.20803.12289.20136.12289.21033.12289.35998,
121*0Sstevel@tonic-gate    'gb12345-raw'	=> 'G,#:T*!":`!"@{!"Uj',
122*0Sstevel@tonic-gate    'gbk'	=> 'Ǭ��Ԫ���ࡢ����ؑ',
123*0Sstevel@tonic-gate});
124*0Sstevel@tonic-gate
125*0Sstevel@tonic-gatesub run_tests {
126*0Sstevel@tonic-gate    my ($title, $tests) = @_;
127*0Sstevel@tonic-gate    my $utf = delete $tests->{'utf'};
128*0Sstevel@tonic-gate
129*0Sstevel@tonic-gate    # $enc = encoding, $str = content
130*0Sstevel@tonic-gate    foreach my $enc (sort keys %{$tests}) {
131*0Sstevel@tonic-gate	my $str = $tests->{$enc};
132*0Sstevel@tonic-gate
133*0Sstevel@tonic-gate	is(Encode::decode($enc, $str), $utf, "[$enc] decode - $title");
134*0Sstevel@tonic-gate	is(Encode::encode($enc, $utf), $str, "[$enc] encode - $title");
135*0Sstevel@tonic-gate
136*0Sstevel@tonic-gate	my $str2 = $str;
137*0Sstevel@tonic-gate	my $utf8 = Encode::encode('utf-8', $utf);
138*0Sstevel@tonic-gate
139*0Sstevel@tonic-gate	Encode::from_to($str2, $enc, 'utf-8');
140*0Sstevel@tonic-gate	is($str2, $utf8, "[$enc] from_to => utf8 - $title");
141*0Sstevel@tonic-gate
142*0Sstevel@tonic-gate	Encode::from_to($utf8, 'utf-8', $enc); # convert $utf8 as $enc
143*0Sstevel@tonic-gate	is($utf8, $str,  "[$enc] utf8 => from_to - $title");
144*0Sstevel@tonic-gate    }
145*0Sstevel@tonic-gate}
146