"Fossies" - the Fresh Open Source Software Archive

Member "texinfo-6.5/tp/maintain/lib/libintl-perl/tests/02asmo_449.t" (22 Apr 2014, 6409 Bytes) of package /linux/misc/texinfo-6.5.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #! /usr/local/bin/perl -w
    2 
    3 # vim: tabstop=4
    4 # vim: syntax=perl
    5 
    6 use strict;
    7 
    8 use Test;
    9 
   10 BEGIN {
   11     plan tests => 7;
   12 }
   13 
   14 use Locale::Recode;
   15 
   16 sub int2utf8;
   17 
   18 my $local2ucs = {};
   19 my $ucs2local = {};
   20 
   21 while (<DATA>) {
   22     my ($code, $ucs, undef) = map { oct $_ } split /\s+/, $_;
   23     $local2ucs->{$code} = $ucs;
   24     $ucs2local->{$ucs} = $code unless $ucs == 0xfffd;
   25 }
   26 
   27 my $cd_int = Locale::Recode->new (from => 'ASMO_449',
   28                   to => 'INTERNAL');
   29 ok !$cd_int->getError;
   30 
   31 my $cd_utf8 = Locale::Recode->new (from => 'ASMO_449',
   32                    to => 'UTF-8');
   33 ok !$cd_utf8->getError;
   34 
   35 my $cd_rev = Locale::Recode->new (from => 'INTERNAL',
   36                   to => 'ASMO_449');
   37 ok !$cd_rev->getError;
   38 
   39 # Convert into internal representation.
   40 my $result_int = 1;
   41 while (my ($code, $ucs) = each %$local2ucs) {
   42     my $outbuf = chr $code;
   43     my $result = $cd_int->recode ($outbuf);
   44     unless ($result && $outbuf->[0] == $ucs) {
   45     $result_int = 0;
   46     last;
   47     }
   48 }
   49 ok $result_int;
   50 
   51 # Convert to UTF-8.
   52 my $result_utf8 = 1;
   53 while (my ($code, $ucs) = each %$local2ucs) {
   54     my $outbuf = chr $code;
   55     my $result = $cd_utf8->recode ($outbuf);
   56     unless ($result && $outbuf eq int2utf8 $ucs) {
   57         $result_utf8 = 0;
   58         last;
   59     }
   60 }
   61 ok $result_utf8;
   62 
   63 # Convert from internal representation.
   64 my $result_rev = 1;
   65 while (my ($ucs, $code) = each %$ucs2local) {
   66     my $outbuf = [ $ucs ];
   67     my $result = $cd_rev->recode ($outbuf);
   68     unless ($result && $code == ord $outbuf) {
   69         $result_int = 0;
   70         last;
   71     }
   72 }
   73 ok $result_int;
   74 
   75 # Check handling of unknown characters.
   76 my $test_string1 = [ unpack 'c*', ' Supergirl ' ];
   77 $test_string1->[0] = 0xad0be;
   78 $test_string1->[-1] = 0xbeefbabe;
   79 my $test_string2 = [ unpack 'c*', 'Supergirl' ];
   80 
   81 my $unknown = "\x3f"; # Unknown character!
   82 
   83 $cd_rev = Locale::Recode->new (from => 'INTERNAL',
   84                        to => 'ASMO_449',
   85                 )
   86 && $cd_rev->recode ($test_string1)
   87 && $cd_rev->recode ($test_string2)
   88 && ($test_string2 = $unknown . $test_string2 . $unknown);
   89 
   90 ok $test_string1 eq $test_string2;
   91 
   92 sub int2utf8
   93 {
   94     my $ucs4 = shift;
   95     
   96     if ($ucs4 <= 0x7f) {
   97     return chr $ucs4;
   98     } elsif ($ucs4 <= 0x7ff) {
   99     return pack ("C2", 
  100              (0xc0 | (($ucs4 >> 6) & 0x1f)),
  101              (0x80 | ($ucs4 & 0x3f)));
  102     } elsif ($ucs4 <= 0xffff) {
  103     return pack ("C3", 
  104              (0xe0 | (($ucs4 >> 12) & 0xf)),
  105              (0x80 | (($ucs4 >> 6) & 0x3f)),
  106              (0x80 | ($ucs4 & 0x3f)));
  107     } elsif ($ucs4 <= 0x1fffff) {
  108     return pack ("C4", 
  109              (0xf0 | (($ucs4 >> 18) & 0x7)),
  110              (0x80 | (($ucs4 >> 12) & 0x3f)),
  111              (0x80 | (($ucs4 >> 6) & 0x3f)),
  112              (0x80 | ($ucs4 & 0x3f)));
  113     } elsif ($ucs4 <= 0x3ffffff) {
  114     return pack ("C5", 
  115              (0xf0 | (($ucs4 >> 24) & 0x3)),
  116              (0x80 | (($ucs4 >> 18) & 0x3f)),
  117              (0x80 | (($ucs4 >> 12) & 0x3f)),
  118              (0x80 | (($ucs4 >> 6) & 0x3f)),
  119              (0x80 | ($ucs4 & 0x3f)));
  120     } else {
  121     return pack ("C6", 
  122              (0xf0 | (($ucs4 >> 30) & 0x3)),
  123              (0x80 | (($ucs4 >> 24) & 0x1)),
  124              (0x80 | (($ucs4 >> 18) & 0x3f)),
  125              (0x80 | (($ucs4 >> 12) & 0x3f)),
  126              (0x80 | (($ucs4 >> 6) & 0x3f)),
  127              (0x80 | ($ucs4 & 0x3f)));
  128     }
  129 }
  130 
  131 #Local Variables:
  132 #mode: perl
  133 #perl-indent-level: 4
  134 #perl-continued-statement-offset: 4
  135 #perl-continued-brace-offset: 0
  136 #perl-brace-offset: -4
  137 #perl-brace-imaginary-offset: 0
  138 #perl-label-offset: -4
  139 #tab-width: 4
  140 #End:
  141 
  142 
  143 __DATA__
  144 0x00    0x0000
  145 0x01    0x0001
  146 0x02    0x0002
  147 0x03    0x0003
  148 0x04    0x0004
  149 0x05    0x0005
  150 0x06    0x0006
  151 0x07    0x0007
  152 0x08    0x0008
  153 0x09    0x0009
  154 0x0a    0x000a
  155 0x0b    0x000b
  156 0x0c    0x000c
  157 0x0d    0x000d
  158 0x0e    0x000e
  159 0x0f    0x000f
  160 0x10    0x0010
  161 0x11    0x0011
  162 0x12    0x0012
  163 0x13    0x0013
  164 0x14    0x0014
  165 0x15    0x0015
  166 0x16    0x0016
  167 0x17    0x0017
  168 0x18    0x0018
  169 0x19    0x0019
  170 0x1a    0x001a
  171 0x1b    0x001b
  172 0x1c    0x001c
  173 0x1d    0x001d
  174 0x1e    0x001e
  175 0x1f    0x001f
  176 0x20    0x0020
  177 0x21    0x0021
  178 0x22    0x0022
  179 0x23    0x0023
  180 0x24    0x00a4
  181 0x25    0x0025
  182 0x26    0x0026
  183 0x27    0x0027
  184 0x28    0x0028
  185 0x29    0x0029
  186 0x2a    0x002a
  187 0x2b    0x002b
  188 0x2c    0x060c
  189 0x2d    0x002d
  190 0x2e    0x002e
  191 0x2f    0x002f
  192 0x30    0x0030
  193 0x31    0x0031
  194 0x32    0x0032
  195 0x33    0x0033
  196 0x34    0x0034
  197 0x35    0x0035
  198 0x36    0x0036
  199 0x37    0x0037
  200 0x38    0x0038
  201 0x39    0x0039
  202 0x3a    0x003a
  203 0x3b    0x061b
  204 0x3c    0x003c
  205 0x3d    0x003d
  206 0x3e    0x003e
  207 0x3f    0x061f
  208 0x40    0x0040
  209 0x41    0x0621
  210 0x42    0x0622
  211 0x43    0x0623
  212 0x44    0x0624
  213 0x45    0x0625
  214 0x46    0x0626
  215 0x47    0x0627
  216 0x48    0x0628
  217 0x49    0x0629
  218 0x4a    0x062a
  219 0x4b    0x062b
  220 0x4c    0x062c
  221 0x4d    0x062d
  222 0x4e    0x062e
  223 0x4f    0x062f
  224 0x50    0x0630
  225 0x51    0x0631
  226 0x52    0x0632
  227 0x53    0x0633
  228 0x54    0x0634
  229 0x55    0x0635
  230 0x56    0x0636
  231 0x57    0x0637
  232 0x58    0x0638
  233 0x59    0x0639
  234 0x5a    0x063a
  235 0x5b    0x005b
  236 0x5c    0x005c
  237 0x5d    0x005d
  238 0x5e    0x005e
  239 0x5f    0x005f
  240 0x60    0x0640
  241 0x61    0x0641
  242 0x62    0x0642
  243 0x63    0x0643
  244 0x64    0x0644
  245 0x65    0x0645
  246 0x66    0x0646
  247 0x67    0x0647
  248 0x68    0x0648
  249 0x69    0x0649
  250 0x6a    0x064a
  251 0x6b    0x064b
  252 0x6c    0x064c
  253 0x6d    0x064d
  254 0x6e    0x064e
  255 0x6f    0x064f
  256 0x70    0x0650
  257 0x71    0x0651
  258 0x72    0x0652
  259 0x7b    0xfffd
  260 0x7b    0xfffd
  261 0x7b    0xfffd
  262 0x7b    0xfffd
  263 0x7b    0xfffd
  264 0x7b    0xfffd
  265 0x7b    0xfffd
  266 0x7b    0xfffd
  267 0x7b    0x007b
  268 0x7c    0x007c
  269 0x7d    0x007d
  270 0x7e    0x203e
  271 0x7f    0x007f
  272 0x80    0xfffd
  273 0x81    0xfffd
  274 0x82    0xfffd
  275 0x83    0xfffd
  276 0x84    0xfffd
  277 0x85    0xfffd
  278 0x86    0xfffd
  279 0x87    0xfffd
  280 0x88    0xfffd
  281 0x89    0xfffd
  282 0x8a    0xfffd
  283 0x8b    0xfffd
  284 0x8c    0xfffd
  285 0x8d    0xfffd
  286 0x8e    0xfffd
  287 0x8f    0xfffd
  288 0x90    0xfffd
  289 0x91    0xfffd
  290 0x92    0xfffd
  291 0x93    0xfffd
  292 0x94    0xfffd
  293 0x95    0xfffd
  294 0x96    0xfffd
  295 0x97    0xfffd
  296 0x98    0xfffd
  297 0x99    0xfffd
  298 0x9a    0xfffd
  299 0x9b    0xfffd
  300 0x9c    0xfffd
  301 0x9d    0xfffd
  302 0x9e    0xfffd
  303 0x9f    0xfffd
  304 0xa0    0xfffd
  305 0xa1    0xfffd
  306 0xa2    0xfffd
  307 0xa3    0xfffd
  308 0xa4    0xfffd
  309 0xa5    0xfffd
  310 0xa6    0xfffd
  311 0xa7    0xfffd
  312 0xa8    0xfffd
  313 0xa9    0xfffd
  314 0xaa    0xfffd
  315 0xab    0xfffd
  316 0xac    0xfffd
  317 0xad    0xfffd
  318 0xae    0xfffd
  319 0xaf    0xfffd
  320 0xb0    0xfffd
  321 0xb1    0xfffd
  322 0xb2    0xfffd
  323 0xb3    0xfffd
  324 0xb4    0xfffd
  325 0xb5    0xfffd
  326 0xb6    0xfffd
  327 0xb7    0xfffd
  328 0xb8    0xfffd
  329 0xb9    0xfffd
  330 0xba    0xfffd
  331 0xbb    0xfffd
  332 0xbc    0xfffd
  333 0xbd    0xfffd
  334 0xbe    0xfffd
  335 0xbf    0xfffd
  336 0xc0    0xfffd
  337 0xc1    0xfffd
  338 0xc2    0xfffd
  339 0xc3    0xfffd
  340 0xc4    0xfffd
  341 0xc5    0xfffd
  342 0xc6    0xfffd
  343 0xc7    0xfffd
  344 0xc8    0xfffd
  345 0xc9    0xfffd
  346 0xca    0xfffd
  347 0xcb    0xfffd
  348 0xcc    0xfffd
  349 0xcd    0xfffd
  350 0xce    0xfffd
  351 0xcf    0xfffd
  352 0xd0    0xfffd
  353 0xd1    0xfffd
  354 0xd2    0xfffd
  355 0xd3    0xfffd
  356 0xd4    0xfffd
  357 0xd5    0xfffd
  358 0xd6    0xfffd
  359 0xd7    0xfffd
  360 0xd8    0xfffd
  361 0xd9    0xfffd
  362 0xda    0xfffd
  363 0xdb    0xfffd
  364 0xdc    0xfffd
  365 0xdd    0xfffd
  366 0xde    0xfffd
  367 0xdf    0xfffd
  368 0xe0    0xfffd
  369 0xe1    0xfffd
  370 0xe2    0xfffd
  371 0xe3    0xfffd
  372 0xe4    0xfffd
  373 0xe5    0xfffd
  374 0xe6    0xfffd
  375 0xe7    0xfffd
  376 0xe8    0xfffd
  377 0xe9    0xfffd
  378 0xea    0xfffd
  379 0xeb    0xfffd
  380 0xec    0xfffd
  381 0xed    0xfffd
  382 0xee    0xfffd
  383 0xef    0xfffd
  384 0xf0    0xfffd
  385 0xf1    0xfffd
  386 0xf2    0xfffd
  387 0xf3    0xfffd
  388 0xf4    0xfffd
  389 0xf5    0xfffd
  390 0xf6    0xfffd
  391 0xf7    0xfffd
  392 0xf8    0xfffd
  393 0xf9    0xfffd
  394 0xfa    0xfffd
  395 0xfb    0xfffd
  396 0xfc    0xfffd
  397 0xfd    0xfffd
  398 0xfe    0xfffd
  399 0xff    0xfffd