Move Archive::Tar from lib/ to ext/
[p5sagit/p5-mst-13.2.git] / lib / Locale / Codes / t / all.t
1 #!./perl
2 #
3 # all.t - tests for all_* routines in
4 #       Locale::Country
5 #       Locale::Language
6 #       Locale::Currency
7 #       Locale::Script
8 #
9 # There are four tests. We get a list of all codes, convert to
10 # language/country/currency, # convert back to code,
11 # and check that they're the same. Then we do the same,
12 # starting with list of languages/countries/currencies.
13 #
14
15 use Locale::Country;
16 use Locale::Language;
17 use Locale::Currency;
18 use Locale::Script;
19
20 print "1..20\n";
21
22 my $code;
23 my $language;
24 my $country;
25 my $ok;
26 my $reverse;
27 my $currency;
28 my $script;
29
30
31 #-----------------------------------------------------------------------
32 # Old API - without codeset specified, default to ALPHA_2
33 #-----------------------------------------------------------------------
34 $ok = 1;
35 foreach $code (all_country_codes())
36 {
37     $country = code2country($code);
38     if (!defined $country)
39     {
40         $ok = 0;
41         last;
42     }
43     $reverse = country2code($country);
44     if (!defined $reverse)
45     {
46         $ok = 0;
47         last;
48     }
49     if ($reverse ne $code)
50     {
51         $ok = 0;
52         last;
53     }
54 }
55 print ($ok ? "ok 1\n" : "not ok 1\n");
56
57 #-----------------------------------------------------------------------
58 # code to country, back to code, for ALPHA2
59 #-----------------------------------------------------------------------
60 $ok = 1;
61 foreach $code (all_country_codes(LOCALE_CODE_ALPHA_2))
62 {
63     $country = code2country($code, LOCALE_CODE_ALPHA_2);
64     if (!defined $country)
65     {
66         $ok = 0;
67         last;
68     }
69     $reverse = country2code($country, LOCALE_CODE_ALPHA_2);
70     if (!defined $reverse)
71     {
72         $ok = 0;
73         last;
74     }
75     if ($reverse ne $code)
76     {
77         $ok = 0;
78         last;
79     }
80 }
81 print ($ok ? "ok 2\n" : "not ok 2\n");
82
83 #-----------------------------------------------------------------------
84 # code to country, back to code, for ALPHA3
85 #-----------------------------------------------------------------------
86 $ok = 1;
87 foreach $code (all_country_codes(LOCALE_CODE_ALPHA_3))
88 {
89     $country = code2country($code, LOCALE_CODE_ALPHA_3);
90     if (!defined $country)
91     {
92         $ok = 0;
93         last;
94     }
95     $reverse = country2code($country, LOCALE_CODE_ALPHA_3);
96     if (!defined $reverse)
97     {
98         $ok = 0;
99         last;
100     }
101     if ($reverse ne $code)
102     {
103         $ok = 0;
104         last;
105     }
106 }
107 print ($ok ? "ok 3\n" : "not ok 3\n");
108
109 #-----------------------------------------------------------------------
110 # code to country, back to code, for NUMERIC
111 #-----------------------------------------------------------------------
112 $ok = 1;
113 foreach $code (all_country_codes(LOCALE_CODE_NUMERIC))
114 {
115     $country = code2country($code, LOCALE_CODE_NUMERIC);
116     if (!defined $country)
117     {
118         $ok = 0;
119         last;
120     }
121     $reverse = country2code($country, LOCALE_CODE_NUMERIC);
122     if (!defined $reverse)
123     {
124         $ok = 0;
125         last;
126     }
127     if ($reverse ne $code)
128     {
129         $ok = 0;
130         last;
131     }
132 }
133 print ($ok ? "ok 4\n" : "not ok 4\n");
134
135
136 #-----------------------------------------------------------------------
137 # Old API - country to code, back to country, using default of ALPHA_2
138 #-----------------------------------------------------------------------
139 $ok = 1;
140 foreach $country (all_country_names())
141 {
142     $code = country2code($country);
143     if (!defined $code)
144     {
145         $ok = 0;
146         last;
147     }
148     $reverse = code2country($code);
149     if (!defined $reverse)
150     {
151         $ok = 0;
152         last;
153     }
154     if ($reverse ne $country)
155     {
156         $ok = 0;
157         last;
158     }
159 }
160 print ($ok ? "ok 5\n" : "not ok 5\n");
161
162 #-----------------------------------------------------------------------
163 # country to code, back to country, using LOCALE_CODE_ALPHA_2
164 #-----------------------------------------------------------------------
165 $ok = 1;
166 foreach $country (all_country_names())
167 {
168     $code = country2code($country, LOCALE_CODE_ALPHA_2);
169     if (!defined $code)
170     {
171         $ok = 0;
172         last;
173     }
174     $reverse = code2country($code, LOCALE_CODE_ALPHA_2);
175     if (!defined $reverse)
176     {
177         $ok = 0;
178         last;
179     }
180     if ($reverse ne $country)
181     {
182         $ok = 0;
183         last;
184     }
185 }
186 print ($ok ? "ok 6\n" : "not ok 6\n");
187
188 #-----------------------------------------------------------------------
189 # country to code, back to country, using LOCALE_CODE_ALPHA_3
190 #-----------------------------------------------------------------------
191 $ok = 1;
192 foreach $country (all_country_names())
193 {
194     $code = country2code($country, LOCALE_CODE_ALPHA_3);
195     if (!defined $code)
196     {
197         next if ($country eq 'Antarctica'
198                  || $country eq 'Bouvet Island'
199                  || $country eq 'Cocos (Keeling) Islands'
200                  || $country eq 'Christmas Island'
201                  || $country eq 'France, Metropolitan'
202                  || $country eq 'South Georgia and the South Sandwich Islands'
203                  || $country eq 'Heard Island and McDonald Islands'
204                  || $country eq 'British Indian Ocean Territory'
205                  || $country eq 'French Southern Territories'
206                  || $country eq 'United States Minor Outlying Islands'
207                  || $country eq 'Mayotte'
208                  || $country eq 'Zaire');
209         $ok = 0;
210         last;
211     }
212     $reverse = code2country($code, LOCALE_CODE_ALPHA_3);
213     if (!defined $reverse)
214     {
215         $ok = 0;
216         last;
217     }
218     if ($reverse ne $country)
219     {
220         $ok = 0;
221         last;
222     }
223 }
224 print ($ok ? "ok 7\n" : "not ok 7\n");
225
226 #-----------------------------------------------------------------------
227 # country to code, back to country, using LOCALE_CODE_NUMERIC
228 #-----------------------------------------------------------------------
229 $ok = 1;
230 foreach $country (all_country_names())
231 {
232     $code = country2code($country, LOCALE_CODE_NUMERIC);
233     if (!defined $code)
234     {
235         next if ($country eq 'Antarctica'
236                  || $country eq 'Bouvet Island'
237                  || $country eq 'Cocos (Keeling) Islands'
238                  || $country eq 'Christmas Island'
239                  || $country eq 'France, Metropolitan'
240                  || $country eq 'South Georgia and the South Sandwich Islands'
241                  || $country eq 'Heard Island and McDonald Islands'
242                  || $country eq 'British Indian Ocean Territory'
243                  || $country eq 'French Southern Territories'
244                  || $country eq 'United States Minor Outlying Islands'
245                  || $country eq 'Mayotte'
246                  || $country eq 'Zaire');
247         $ok = 0;
248         last;
249     }
250     $reverse = code2country($code, LOCALE_CODE_NUMERIC);
251     if (!defined $reverse)
252     {
253         $ok = 0;
254         last;
255     }
256     if ($reverse ne $country)
257     {
258         $ok = 0;
259         last;
260     }
261 }
262 print ($ok ? "ok 8\n" : "not ok 8\n");
263
264
265 $ok = 1;
266 foreach $code (all_language_codes())
267 {
268     $language = code2language($code);
269     if (!defined $language)
270     {
271         $ok = 0;
272         last;
273     }
274     $reverse = language2code($language);
275     if (!defined $reverse)
276     {
277         $ok = 0;
278         last;
279     }
280     if ($reverse ne $code)
281     {
282         $ok = 0;
283         last;
284     }
285 }
286 print ($ok ? "ok 9\n" : "not ok 9\n");
287
288
289 $ok = 1;
290 foreach $language (all_language_names())
291 {
292     $code = language2code($language);
293     if (!defined $code)
294     {
295         $ok = 0;
296         last;
297     }
298     $reverse = code2language($code);
299     if (!defined $reverse)
300     {
301         $ok = 0;
302         last;
303     }
304     if ($reverse ne $language)
305     {
306         $ok = 0;
307         last;
308     }
309 }
310 print ($ok ? "ok 10\n" : "not ok 10\n");
311
312 $ok = 1;
313 foreach $code (all_currency_codes())
314 {
315     $currency = code2currency($code);
316     if (!defined $currency)
317     {
318         $ok = 0;
319         last;
320     }
321     $reverse = currency2code($currency);
322     if (!defined $reverse)
323     {
324         $ok = 0;
325         last;
326     }
327     #
328     # three special cases:
329     #   The Kwacha has two codes - used in Zambia and Malawi
330     #   The Russian Ruble has two codes - rub and rur
331     #   The Belarussian Ruble has two codes - byb and byr
332     if ($reverse ne $code
333         && $code ne 'mwk' && $code ne 'zmk'
334         && $code ne 'byr' && $code ne 'byb'
335         && $code ne 'rub' && $code ne 'rur')
336     {
337         $ok = 0;
338         last;
339     }
340 }
341 print ($ok ? "ok 11\n" : "not ok 11\n");
342
343 $ok = 1;
344 foreach $currency (all_currency_names())
345 {
346     $code = currency2code($currency);
347     if (!defined $code)
348     {
349         $ok = 0;
350         last;
351     }
352     $reverse = code2currency($code);
353     if (!defined $reverse)
354     {
355         $ok = 0;
356         last;
357     }
358     if ($reverse ne $currency)
359     {
360         $ok = 0;
361         last;
362     }
363 }
364 print ($ok ? "ok 12\n" : "not ok 12\n");
365
366 #=======================================================================
367 #
368 #       Locale::Script tests
369 #
370 #=======================================================================
371
372 #-----------------------------------------------------------------------
373 # Old API - without codeset specified, default to ALPHA_2
374 #-----------------------------------------------------------------------
375 $ok = 1;
376 foreach $code (all_script_codes())
377 {
378     $script = code2script($code);
379     if (!defined $script)
380     {
381         $ok = 0;
382         last;
383     }
384     $reverse = script2code($script);
385     if (!defined $reverse)
386     {
387         $ok = 0;
388         last;
389     }
390     if ($reverse ne $code)
391     {
392         $ok = 0;
393         last;
394     }
395 }
396 print ($ok ? "ok 13\n" : "not ok 13\n");
397
398 #-----------------------------------------------------------------------
399 # code to script, back to code, for ALPHA2
400 #-----------------------------------------------------------------------
401 $ok = 1;
402 foreach $code (all_script_codes(LOCALE_CODE_ALPHA_2))
403 {
404     $script = code2script($code, LOCALE_CODE_ALPHA_2);
405     if (!defined $script)
406     {
407         $ok = 0;
408         last;
409     }
410     $reverse = script2code($script, LOCALE_CODE_ALPHA_2);
411     if (!defined $reverse)
412     {
413         $ok = 0;
414         last;
415     }
416     if ($reverse ne $code)
417     {
418         $ok = 0;
419         last;
420     }
421 }
422 print ($ok ? "ok 14\n" : "not ok 14\n");
423
424 #-----------------------------------------------------------------------
425 # code to script, back to code, for ALPHA3
426 #-----------------------------------------------------------------------
427 $ok = 1;
428 foreach $code (all_script_codes(LOCALE_CODE_ALPHA_3))
429 {
430     $script = code2script($code, LOCALE_CODE_ALPHA_3);
431     if (!defined $script)
432     {
433         $ok = 0;
434         last;
435     }
436     $reverse = script2code($script, LOCALE_CODE_ALPHA_3);
437     if (!defined $reverse)
438     {
439         $ok = 0;
440         last;
441     }
442     if ($reverse ne $code)
443     {
444         $ok = 0;
445         last;
446     }
447 }
448 print ($ok ? "ok 15\n" : "not ok 15\n");
449
450 #-----------------------------------------------------------------------
451 # code to script, back to code, for NUMERIC
452 #-----------------------------------------------------------------------
453 $ok = 1;
454 foreach $code (all_script_codes(LOCALE_CODE_NUMERIC))
455 {
456     $script = code2script($code, LOCALE_CODE_NUMERIC);
457     if (!defined $script)
458     {
459         $ok = 0;
460         last;
461     }
462     $reverse = script2code($script, LOCALE_CODE_NUMERIC);
463     if (!defined $reverse)
464     {
465         $ok = 0;
466         last;
467     }
468     if ($reverse ne $code)
469     {
470         $ok = 0;
471         last;
472     }
473 }
474 print ($ok ? "ok 16\n" : "not ok 16\n");
475
476
477 #-----------------------------------------------------------------------
478 # Old API - script to code, back to script, using default of ALPHA_2
479 #-----------------------------------------------------------------------
480 $ok = 1;
481 foreach $script (all_script_names())
482 {
483     $code = script2code($script);
484     if (!defined $code)
485     {
486         $ok = 0;
487         last;
488     }
489     $reverse = code2script($code);
490     if (!defined $reverse)
491     {
492         $ok = 0;
493         last;
494     }
495     if ($reverse ne $script)
496     {
497         $ok = 0;
498         last;
499     }
500 }
501 print ($ok ? "ok 17\n" : "not ok 17\n");
502
503 #-----------------------------------------------------------------------
504 # script to code, back to script, using LOCALE_CODE_ALPHA_2
505 #-----------------------------------------------------------------------
506 $ok = 1;
507 foreach $script (all_script_names())
508 {
509     $code = script2code($script, LOCALE_CODE_ALPHA_2);
510     if (!defined $code)
511     {
512         $ok = 0;
513         last;
514     }
515     $reverse = code2script($code, LOCALE_CODE_ALPHA_2);
516     if (!defined $reverse)
517     {
518         $ok = 0;
519         last;
520     }
521     if ($reverse ne $script)
522     {
523         $ok = 0;
524         last;
525     }
526 }
527 print ($ok ? "ok 18\n" : "not ok 18\n");
528
529 #-----------------------------------------------------------------------
530 # script to code, back to script, using LOCALE_CODE_ALPHA_3
531 #-----------------------------------------------------------------------
532 $ok = 1;
533 foreach $script (all_script_names())
534 {
535     $code = script2code($script, LOCALE_CODE_ALPHA_3);
536     if (!defined $code)
537     {
538         $ok = 0;
539         last;
540     }
541     $reverse = code2script($code, LOCALE_CODE_ALPHA_3);
542     if (!defined $reverse)
543     {
544         $ok = 0;
545         last;
546     }
547     if ($reverse ne $script)
548     {
549         $ok = 0;
550         last;
551     }
552 }
553 print ($ok ? "ok 19\n" : "not ok 19\n");
554
555 #-----------------------------------------------------------------------
556 # script to code, back to script, using LOCALE_CODE_NUMERIC
557 #-----------------------------------------------------------------------
558 $ok = 1;
559 foreach $script (all_script_names())
560 {
561     $code = script2code($script, LOCALE_CODE_NUMERIC);
562     if (!defined $code)
563     {
564         $ok = 0;
565         last;
566     }
567     $reverse = code2script($code, LOCALE_CODE_NUMERIC);
568     if (!defined $reverse)
569     {
570         $ok = 0;
571         last;
572     }
573     if ($reverse ne $script)
574     {
575         $ok = 0;
576         last;
577     }
578 }
579 print ($ok ? "ok 20\n" : "not ok 20\n");
580