"Fossies" - the Fresh Open Source Software Archive

Member "texinfo-6.5/tp/maintain/lib/libintl-perl/tests/02ebcdic-dk-no.t" (22 Apr 2014, 6425 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 => 'EBCDIC-DK-NO',
   28                   to => 'INTERNAL');
   29 ok !$cd_int->getError;
   30 
   31 my $cd_utf8 = Locale::Recode->new (from => 'EBCDIC-DK-NO',
   32                    to => 'UTF-8');
   33 ok !$cd_utf8->getError;
   34 
   35 my $cd_rev = Locale::Recode->new (from => 'INTERNAL',
   36                   to => 'EBCDIC-DK-NO');
   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 => 'EBCDIC-DK-NO',
   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    0x009c
  149 0x05    0x0009
  150 0x06    0x0086
  151 0x07    0x007f
  152 0x08    0x0097
  153 0x09    0x008d
  154 0x0a    0x008e
  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    0x009d
  165 0x15    0x0085
  166 0x16    0x0008
  167 0x17    0x0087
  168 0x18    0x0018
  169 0x19    0x0019
  170 0x1a    0x0092
  171 0x1b    0x008f
  172 0x1c    0x001c
  173 0x1d    0x001d
  174 0x1e    0x001e
  175 0x1f    0x001f
  176 0x20    0x0080
  177 0x21    0x0081
  178 0x22    0x0082
  179 0x23    0x0083
  180 0x24    0x0084
  181 0x25    0x000a
  182 0x26    0x0017
  183 0x27    0x001b
  184 0x28    0x0088
  185 0x29    0x0089
  186 0x2a    0x008a
  187 0x2b    0x008b
  188 0x2c    0x008c
  189 0x2d    0x0005
  190 0x2e    0x0006
  191 0x2f    0x0007
  192 0x30    0x0090
  193 0x31    0x0091
  194 0x32    0x0016
  195 0x33    0x0093
  196 0x34    0x0094
  197 0x35    0x0095
  198 0x36    0x0096
  199 0x37    0x0004
  200 0x38    0x0098
  201 0x39    0x0099
  202 0x3a    0x009a
  203 0x3b    0x009b
  204 0x3c    0x0014
  205 0x3d    0x0015
  206 0x3e    0x009e
  207 0x3f    0x001a
  208 0x40    0x0020
  209 0x4a    0xfffd
  210 0x4a    0xfffd
  211 0x4a    0xfffd
  212 0x4a    0xfffd
  213 0x4a    0xfffd
  214 0x4a    0xfffd
  215 0x4a    0xfffd
  216 0x4a    0xfffd
  217 0x4a    0xfffd
  218 0x4a    0x0023
  219 0x4b    0x002e
  220 0x4c    0x003c
  221 0x4d    0x0028
  222 0x4e    0x002b
  223 0x4f    0x0021
  224 0x50    0x0026
  225 0x5a    0xfffd
  226 0x5a    0xfffd
  227 0x5a    0xfffd
  228 0x5a    0xfffd
  229 0x5a    0xfffd
  230 0x5a    0xfffd
  231 0x5a    0xfffd
  232 0x5a    0xfffd
  233 0x5a    0xfffd
  234 0x5a    0x00a4
  235 0x5b    0x00c5
  236 0x5c    0x002a
  237 0x5d    0x0029
  238 0x5e    0x003b
  239 0x5f    0x005e
  240 0x60    0x002d
  241 0x61    0x002f
  242 0x6a    0xfffd
  243 0x6a    0xfffd
  244 0x6a    0xfffd
  245 0x6a    0xfffd
  246 0x6a    0xfffd
  247 0x6a    0xfffd
  248 0x6a    0xfffd
  249 0x6a    0xfffd
  250 0x6a    0x00f8
  251 0x6b    0x002c
  252 0x6c    0x0025
  253 0x6d    0x005f
  254 0x6e    0x003e
  255 0x6f    0x003f
  256 0x79    0xfffd
  257 0x79    0xfffd
  258 0x79    0xfffd
  259 0x79    0xfffd
  260 0x79    0xfffd
  261 0x79    0xfffd
  262 0x79    0xfffd
  263 0x79    0xfffd
  264 0x79    0xfffd
  265 0x79    0x0060
  266 0x7a    0x003a
  267 0x7b    0x00c6
  268 0x7c    0x00d8
  269 0x7d    0x0027
  270 0x7e    0x003d
  271 0x7f    0x0022
  272 0x81    0xfffd
  273 0x81    0x0061
  274 0x82    0x0062
  275 0x83    0x0063
  276 0x84    0x0064
  277 0x85    0x0065
  278 0x86    0x0066
  279 0x87    0x0067
  280 0x88    0x0068
  281 0x89    0x0069
  282 0x91    0xfffd
  283 0x91    0xfffd
  284 0x91    0xfffd
  285 0x91    0xfffd
  286 0x91    0xfffd
  287 0x91    0xfffd
  288 0x91    0xfffd
  289 0x91    0x006a
  290 0x92    0x006b
  291 0x93    0x006c
  292 0x94    0x006d
  293 0x95    0x006e
  294 0x96    0x006f
  295 0x97    0x0070
  296 0x98    0x0071
  297 0x99    0x0072
  298 0xa1    0xfffd
  299 0xa1    0xfffd
  300 0xa1    0xfffd
  301 0xa1    0xfffd
  302 0xa1    0xfffd
  303 0xa1    0xfffd
  304 0xa1    0xfffd
  305 0xa1    0x00fc
  306 0xa2    0x0073
  307 0xa3    0x0074
  308 0xa4    0x0075
  309 0xa5    0x0076
  310 0xa6    0x0077
  311 0xa7    0x0078
  312 0xa8    0x0079
  313 0xa9    0x007a
  314 0xc0    0xfffd
  315 0xc0    0xfffd
  316 0xc0    0xfffd
  317 0xc0    0xfffd
  318 0xc0    0xfffd
  319 0xc0    0xfffd
  320 0xc0    0xfffd
  321 0xc0    0xfffd
  322 0xc0    0xfffd
  323 0xc0    0xfffd
  324 0xc0    0xfffd
  325 0xc0    0xfffd
  326 0xc0    0xfffd
  327 0xc0    0xfffd
  328 0xc0    0xfffd
  329 0xc0    0xfffd
  330 0xc0    0xfffd
  331 0xc0    0xfffd
  332 0xc0    0xfffd
  333 0xc0    0xfffd
  334 0xc0    0xfffd
  335 0xc0    0xfffd
  336 0xc0    0x00e6
  337 0xc1    0x0041
  338 0xc2    0x0042
  339 0xc3    0x0043
  340 0xc4    0x0044
  341 0xc5    0x0045
  342 0xc6    0x0046
  343 0xc7    0x0047
  344 0xc8    0x0048
  345 0xc9    0x0049
  346 0xd0    0xfffd
  347 0xd0    0xfffd
  348 0xd0    0xfffd
  349 0xd0    0xfffd
  350 0xd0    0xfffd
  351 0xd0    0xfffd
  352 0xd0    0x00e5
  353 0xd1    0x004a
  354 0xd2    0x004b
  355 0xd3    0x004c
  356 0xd4    0x004d
  357 0xd5    0x004e
  358 0xd6    0x004f
  359 0xd7    0x0050
  360 0xd8    0x0051
  361 0xd9    0x0052
  362 0xe0    0xfffd
  363 0xe0    0xfffd
  364 0xe0    0xfffd
  365 0xe0    0xfffd
  366 0xe0    0xfffd
  367 0xe0    0xfffd
  368 0xe0    0x005c
  369 0xe2    0xfffd
  370 0xe2    0x0053
  371 0xe3    0x0054
  372 0xe4    0x0055
  373 0xe5    0x0056
  374 0xe6    0x0057
  375 0xe7    0x0058
  376 0xe8    0x0059
  377 0xe9    0x005a
  378 0xf0    0xfffd
  379 0xf0    0xfffd
  380 0xf0    0xfffd
  381 0xf0    0xfffd
  382 0xf0    0xfffd
  383 0xf0    0xfffd
  384 0xf0    0x0030
  385 0xf1    0x0031
  386 0xf2    0x0032
  387 0xf3    0x0033
  388 0xf4    0x0034
  389 0xf5    0x0035
  390 0xf6    0x0036
  391 0xf7    0x0037
  392 0xf8    0x0038
  393 0xf9    0x0039
  394 0xff    0xfffd
  395 0xff    0xfffd
  396 0xff    0xfffd
  397 0xff    0xfffd
  398 0xff    0xfffd
  399 0xff    0x009f