"Fossies" - the Fresh Open Source Software Archive

Member "texinfo-6.5/tp/maintain/lib/libintl-perl/tests/02atari-st-euro.t" (22 Apr 2014, 6424 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 => 'ATARI-ST-EURO',
   28                   to => 'INTERNAL');
   29 ok !$cd_int->getError;
   30 
   31 my $cd_utf8 = Locale::Recode->new (from => 'ATARI-ST-EURO',
   32                    to => 'UTF-8');
   33 ok !$cd_utf8->getError;
   34 
   35 my $cd_rev = Locale::Recode->new (from => 'INTERNAL',
   36                   to => 'ATARI-ST-EURO');
   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 => 'ATARI-ST',
   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    0x0024
  181 0x25    0x0025
  182 0x26    0x0026
  183 0x27    0x0027
  184 0x28    0x0028
  185 0x29    0x0029
  186 0x2a    0x002a
  187 0x2b    0x002b
  188 0x2c    0x002c
  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    0x003b
  204 0x3c    0x003c
  205 0x3d    0x003d
  206 0x3e    0x003e
  207 0x3f    0x003f
  208 0x40    0x0040
  209 0x41    0x0041
  210 0x42    0x0042
  211 0x43    0x0043
  212 0x44    0x0044
  213 0x45    0x0045
  214 0x46    0x0046
  215 0x47    0x0047
  216 0x48    0x0048
  217 0x49    0x0049
  218 0x4a    0x004a
  219 0x4b    0x004b
  220 0x4c    0x004c
  221 0x4d    0x004d
  222 0x4e    0x004e
  223 0x4f    0x004f
  224 0x50    0x0050
  225 0x51    0x0051
  226 0x52    0x0052
  227 0x53    0x0053
  228 0x54    0x0054
  229 0x55    0x0055
  230 0x56    0x0056
  231 0x57    0x0057
  232 0x58    0x0058
  233 0x59    0x0059
  234 0x5a    0x005a
  235 0x5b    0x005b
  236 0x5c    0x005c
  237 0x5d    0x005d
  238 0x5e    0x005e
  239 0x5f    0x005f
  240 0x60    0x0060
  241 0x61    0x0061
  242 0x62    0x0062
  243 0x63    0x0063
  244 0x64    0x0064
  245 0x65    0x0065
  246 0x66    0x0066
  247 0x67    0x0067
  248 0x68    0x0068
  249 0x69    0x0069
  250 0x6a    0x006a
  251 0x6b    0x006b
  252 0x6c    0x006c
  253 0x6d    0x006d
  254 0x6e    0x006e
  255 0x6f    0x006f
  256 0x70    0x0070
  257 0x71    0x0071
  258 0x72    0x0072
  259 0x73    0x0073
  260 0x74    0x0074
  261 0x75    0x0075
  262 0x76    0x0076
  263 0x77    0x0077
  264 0x78    0x0078
  265 0x79    0x0079
  266 0x7a    0x007a
  267 0x7b    0x007b
  268 0x7c    0x007c
  269 0x7d    0x007d
  270 0x7e    0x007e
  271 0x7f    0x007f
  272 0x80    0x00c7
  273 0x81    0x00fc
  274 0x82    0x00e9
  275 0x83    0x00e2
  276 0x84    0x00e4
  277 0x85    0x00e0
  278 0x86    0x00e5
  279 0x87    0x00e7
  280 0x88    0x00ea
  281 0x89    0x00eb
  282 0x8a    0x00e8
  283 0x8b    0x00ef
  284 0x8c    0x00ee
  285 0x8d    0x00ec
  286 0x8e    0x00c4
  287 0x8f    0x00c5
  288 0x90    0x00c9
  289 0x91    0x00e6
  290 0x92    0x00c6
  291 0x93    0x00f4
  292 0x94    0x00f6
  293 0x95    0x00f2
  294 0x96    0x00fb
  295 0x97    0x00f9
  296 0x98    0x00ff
  297 0x99    0x00d6
  298 0x9a    0x00dc
  299 0x9b    0x00a2
  300 0x9c    0x00a3
  301 0x9d    0x00a5
  302 0x9e    0x00df
  303 0x9f    0x0192
  304 0xa0    0x00e1
  305 0xa1    0x00ed
  306 0xa2    0x00f3
  307 0xa3    0x00fa
  308 0xa4    0x00f1
  309 0xa5    0x00d1
  310 0xa6    0x00aa
  311 0xa7    0x00ba
  312 0xa8    0x00bf
  313 0xa9    0x2310
  314 0xaa    0x00ac
  315 0xab    0x00bd
  316 0xac    0x00bc
  317 0xad    0x00a1
  318 0xae    0x00ab
  319 0xaf    0x00bb
  320 0xb0    0x00e3
  321 0xb1    0x00f5
  322 0xb2    0x00d8
  323 0xb3    0x00f8
  324 0xb4    0x0153
  325 0xb5    0x0152
  326 0xb6    0x00c0
  327 0xb7    0x00c3
  328 0xb8    0x00d5
  329 0xb9    0x00a8
  330 0xba    0x00b4
  331 0xbb    0x2020
  332 0xbc    0x00b6
  333 0xbd    0x00a9
  334 0xbe    0x00ae
  335 0xbf    0x2122
  336 0xc0    0x0133
  337 0xc1    0x0132
  338 0xc2    0x05d0
  339 0xc3    0x05d1
  340 0xc4    0x05d2
  341 0xc5    0x05d3
  342 0xc6    0x05d4
  343 0xc7    0x05d5
  344 0xc8    0x05d6
  345 0xc9    0x05d7
  346 0xca    0x05d8
  347 0xcb    0x05d9
  348 0xcc    0x05db
  349 0xcd    0x05dc
  350 0xce    0x05de
  351 0xcf    0x05e0
  352 0xd0    0x05e1
  353 0xd1    0x05e2
  354 0xd2    0x05e4
  355 0xd3    0x05e6
  356 0xd4    0x05e7
  357 0xd5    0x05e8
  358 0xd6    0x05e9
  359 0xd7    0x05ea
  360 0xd8    0x05df
  361 0xd9    0x05da
  362 0xda    0x05dd
  363 0xdb    0x05e3
  364 0xdc    0x05e5
  365 0xdd    0x00a7
  366 0xde    0x20ac
  367 0xdf    0x221e
  368 0xe0    0x03b1
  369 0xe1    0x03b2
  370 0xe2    0x0393
  371 0xe3    0x03c0
  372 0xe4    0x03a3
  373 0xe5    0x03c3
  374 0xe6    0x00b5
  375 0xe7    0x03c4
  376 0xe8    0x03a6
  377 0xe9    0x03b8
  378 0xea    0x03a9
  379 0xeb    0x03b4
  380 0xec    0x222e
  381 0xed    0x03c6
  382 0xee    0x2208
  383 0xef    0x220f
  384 0xf0    0x2261
  385 0xf1    0x00b1
  386 0xf2    0x2265
  387 0xf3    0x2264
  388 0xf4    0x2320
  389 0xf5    0x2321
  390 0xf6    0x00f7
  391 0xf7    0x2248
  392 0xf8    0x00b0
  393 0xf9    0x2022
  394 0xfa    0x00b7
  395 0xfb    0x221a
  396 0xfc    0x207f
  397 0xfd    0x00b2
  398 0xfe    0x00b3
  399 0xff    0x00af