Win32: encode/t/perlio.t needs some binmode
[p5sagit/p5-mst-13.2.git] / ext / Encode / t / CN.t
CommitLineData
00a464f7 1BEGIN {
037b88d6 2 if ($ENV{'PERL_CORE'}){
3 chdir 't';
4 unshift @INC, '../lib';
5 }
00a464f7 6 require Config; import Config;
7 if ($Config{'extensions'} !~ /\bEncode\b/) {
8 print "1..0 # Skip: Encode was not built\n";
9 exit 0;
10 }
00a464f7 11 if (ord("A") == 193) {
12 print "1..0 # Skip: EBCDIC\n";
13 exit 0;
14 }
15 $| = 1;
16}
17
18use strict;
19use Test::More tests => 29;
20use Encode;
21
22use_ok('Encode::CN');
23
24# Since JP.t already test basic file IO, we will just focus on
25# internal encode / decode test here. Unfortunately, to test
26# against all the UniHan characters will take a huge disk space,
27# not to mention the time it will take, and the fact that Perl
28# did not bundle UniHan.txt anyway.
29
30# So, here we just test a typical snippet spanning multiple Unicode
31# blocks, and hope it can point out obvious errors.
32
33run_tests('Simplified Chinese only', {
34 'utf' => (
3512298.26131.32463.12299.31532.19968.21350.
3624406.26352.65306.
3722823.21705.20094.20803.65292.19975.29289.36164.22987.65292.
3820035.32479.22825.12290.
3920113.34892.38632.26045.65292.21697.29289.27969.24418.12290.
4022823.26126.22987.32456.65292.20845.20301.26102.25104.65292.
4126102.20056.20845.40857.20197.24481.22825.12290.
4220094.36947.21464.21270.65292.21508.27491.24615.21629.65292.
4320445.21512.22823.21644.65292.20035.21033.36126.12290.
4439318.20986.24246.29289.65292.19975.22269.21688.23425.12290
45 ),
46
47 'euc-cn' => join('',
48'¡¶Ò×¾­¡·µÚÒ»ØÔ',
49'åèÔ»£º',
50'´óÔÕǬԪ£¬ÍòÎï×Êʼ£¬',
51'ÄËͳÌì¡£',
52'ÔÆÐÐÓêÊ©£¬Æ·ÎïÁ÷ÐΡ£',
53'´óÃ÷ʼÖÕ£¬Áùλʱ³É£¬',
54'ʱ³ËÁùÁúÒÔÓùÌì¡£',
55'ǬµÀ±ä»¯£¬¸÷ÕýÐÔÃü£¬',
56'±£ºÏ´óºÍ£¬ÄËÀûÕê¡£',
57'Ê׳öÊüÎÍò¹úÏÌÄþ¡£',
58 ),
59
67d7b5ef 60 'gb2312-raw' => join('',
00a464f7 61'!6RW>-!75ZR;XT',
62'ehT;#:',
63'4sTUG,T*#,MrNoWJJ<#,',
64'DKM3Ll!#',
65'TFPPSjJ)#,F7NoAwPN!#',
66'4sCwJ<VU#,AyN;J13I#,',
67'J13KAyAzRTSyLl!#',
68'G,5@1d;/#,8wU}PTC|#,',
69'1#:O4s:M#,DK@{Uj!#',
70'JW3vJ|No#,Mr9zOLD~!#'
71 ),
72
73 'iso-ir-165'=> join('',
74'!6RW>-!75ZR;XT',
75'ehT;#:',
76'4sTUG,T*#,MrNoWJJ<#,',
77'DKM3Ll!#',
78'TFPPSjJ)#,F7NoAwPN!#',
79'4sCwJ<VU#,AyN;J13I#,',
80'J13KAyAzRTSyLl!#',
81'G,5@1d;/#,8wU}PTC|#,',
82'1#:O4s:M#,DK@{Uj!#',
83'JW3vJ|No#,Mr9zOLD~!#'
84 ),
85});
86
87run_tests('Simplified Chinese + ASCII', {
88 'utf' => (
8935937.26352.65306.10.
9022825.34892.20581.65292.21531.23376.20197.33258.24378.19981.24687.12290.10.
9128508.40857.21247.29992.65292.38451.22312.19979.20063.12290.32.
9235265.40857.22312.30000.65292.24503.26045.26222.20063.12290.32.
9332456.26085.20094.20094.65292.21453.22797.36947.20063.12290.10.
9425110.36291.22312.28170.65292.36827.26080.21646.20063.12290.39134.
9540857.22312.22825.65292.22823.20154.36896.20063.12290.32.
9620130.40857.26377.24724.65292.30408.19981.21487.20037.20063.12290.10.
9729992.20061.65292.22825.24503.19981.21487.20026.39318.20063.12290
98 ),
99
100 'cp936' => join(chr(10),
101'ÏóÔ»£º',
102'ÌìÐн¡£¬¾ý×ÓÒÔ×ÔÇ¿²»Ï¢¡£',
103'DZÁúÎðÓã¬ÑôÔÚÏÂÒ²¡£ ¼ûÁúÔÚÌµÂÊ©ÆÕÒ²¡£ ÖÕÈÕǬǬ£¬·´¸´µÀÒ²¡£',
104'»òÔ¾ÔÚÔ¨£¬½øÎÞ¾ÌÒ²¡£·ÉÁúÔÚÌ죬´óÈËÔìÒ²¡£ ¿ºÁúÓлڣ¬Ó¯²»¿É¾ÃÒ²¡£',
105'Óþţ¬ÌìµÂ²»¿ÉΪÊ×Ò²¡£',
106 ),
107
108 'hz' => join(chr(10),
109'~{OsT;#:~}',
110'~{LlPP=!#,>}WSRTWTG?2;O"!#~}',
111'~{G1AzNpSC#,QtTZOBR2!#~} ~{<{AzTZLo#,5BJ)FUR2!#~} ~{VUHUG,G,#,74845@R2!#~}',
112'~{;rT>TZT(#,=xN^>LR2!#7IAzTZLl#,4sHKTlR2!#~} ~{?:AzSP;Z#,S/2;?I>CR2!#~}',
113'~{SC>E#,Ll5B2;?IN*JWR2!#~}',
114 ),
115});
116
117run_tests('Traditional Chinese', {
118 'utf', => 20094.65306.20803.12289.20136.12289.21033.12289.35998,
67d7b5ef 119 'gb12345-raw' => 'G,#:T*!":`!"@{!"Uj',
00a464f7 120 'gbk' => 'Ǭ£ºÔª¡¢ºà¡¢Àû¡¢Ø‘',
121});
122
123sub run_tests {
124 my ($title, $tests) = @_;
125 my $utf = delete $tests->{'utf'};
126
127 # $enc = encoding, $str = content
128 foreach my $enc (sort keys %{$tests}) {
129 my $str = $tests->{$enc};
130
131 is(Encode::decode($enc, $str), $utf, "[$enc] decode - $title");
132 is(Encode::encode($enc, $utf), $str, "[$enc] encode - $title");
133
134 my $str2 = $str;
135 my $utf8 = Encode::encode('utf-8', $utf);
136
137 Encode::from_to($str2, $enc, 'utf-8');
138 is($str2, $utf8, "[$enc] from_to => utf8 - $title");
139
140 Encode::from_to($utf8, 'utf-8', $enc); # convert $utf8 as $enc
141 is($utf8, $str, "[$enc] utf8 => from_to - $title");
142 }
143}