3 # all.t - tests for all_* routines in
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.
36 #-----------------------------------------------------------------------
37 # Old API - without codeset specified, default to ALPHA_2
38 #-----------------------------------------------------------------------
40 foreach $code (all_country_codes())
42 $country = code2country($code);
43 if (!defined $country)
48 $reverse = country2code($country);
49 if (!defined $reverse)
54 if ($reverse ne $code)
60 print ($ok ? "ok 1\n" : "not ok 1\n");
62 #-----------------------------------------------------------------------
63 # code to country, back to code, for ALPHA2
64 #-----------------------------------------------------------------------
66 foreach $code (all_country_codes(LOCALE_CODE_ALPHA_2))
68 $country = code2country($code, LOCALE_CODE_ALPHA_2);
69 if (!defined $country)
74 $reverse = country2code($country, LOCALE_CODE_ALPHA_2);
75 if (!defined $reverse)
80 if ($reverse ne $code)
86 print ($ok ? "ok 2\n" : "not ok 2\n");
88 #-----------------------------------------------------------------------
89 # code to country, back to code, for ALPHA3
90 #-----------------------------------------------------------------------
92 foreach $code (all_country_codes(LOCALE_CODE_ALPHA_3))
94 $country = code2country($code, LOCALE_CODE_ALPHA_3);
95 if (!defined $country)
100 $reverse = country2code($country, LOCALE_CODE_ALPHA_3);
101 if (!defined $reverse)
106 if ($reverse ne $code)
112 print ($ok ? "ok 3\n" : "not ok 3\n");
114 #-----------------------------------------------------------------------
115 # code to country, back to code, for NUMERIC
116 #-----------------------------------------------------------------------
118 foreach $code (all_country_codes(LOCALE_CODE_NUMERIC))
120 $country = code2country($code, LOCALE_CODE_NUMERIC);
121 if (!defined $country)
126 $reverse = country2code($country, LOCALE_CODE_NUMERIC);
127 if (!defined $reverse)
132 if ($reverse ne $code)
138 print ($ok ? "ok 4\n" : "not ok 4\n");
141 #-----------------------------------------------------------------------
142 # Old API - country to code, back to country, using default of ALPHA_2
143 #-----------------------------------------------------------------------
145 foreach $country (all_country_names())
147 $code = country2code($country);
153 $reverse = code2country($code);
154 if (!defined $reverse)
159 if ($reverse ne $country)
165 print ($ok ? "ok 5\n" : "not ok 5\n");
167 #-----------------------------------------------------------------------
168 # country to code, back to country, using LOCALE_CODE_ALPHA_2
169 #-----------------------------------------------------------------------
171 foreach $country (all_country_names())
173 $code = country2code($country, LOCALE_CODE_ALPHA_2);
179 $reverse = code2country($code, LOCALE_CODE_ALPHA_2);
180 if (!defined $reverse)
185 if ($reverse ne $country)
191 print ($ok ? "ok 6\n" : "not ok 6\n");
193 #-----------------------------------------------------------------------
194 # country to code, back to country, using LOCALE_CODE_ALPHA_3
195 #-----------------------------------------------------------------------
197 foreach $country (all_country_names())
199 $code = country2code($country, LOCALE_CODE_ALPHA_3);
202 next if ($country eq 'Antarctica'
203 || $country eq 'Bouvet Island'
204 || $country eq 'Cocos (Keeling) Islands'
205 || $country eq 'Christmas Island'
206 || $country eq 'France, Metropolitan'
207 || $country eq 'South Georgia and the South Sandwich Islands'
208 || $country eq 'Heard Island and McDonald Islands'
209 || $country eq 'British Indian Ocean Territory'
210 || $country eq 'French Southern Territories'
211 || $country eq 'United States Minor Outlying Islands'
212 || $country eq 'Mayotte'
213 || $country eq 'Zaire');
217 $reverse = code2country($code, LOCALE_CODE_ALPHA_3);
218 if (!defined $reverse)
223 if ($reverse ne $country)
229 print ($ok ? "ok 7\n" : "not ok 7\n");
231 #-----------------------------------------------------------------------
232 # country to code, back to country, using LOCALE_CODE_NUMERIC
233 #-----------------------------------------------------------------------
235 foreach $country (all_country_names())
237 $code = country2code($country, LOCALE_CODE_NUMERIC);
240 next if ($country eq 'Antarctica'
241 || $country eq 'Bouvet Island'
242 || $country eq 'Cocos (Keeling) Islands'
243 || $country eq 'Christmas Island'
244 || $country eq 'France, Metropolitan'
245 || $country eq 'South Georgia and the South Sandwich Islands'
246 || $country eq 'Heard Island and McDonald Islands'
247 || $country eq 'British Indian Ocean Territory'
248 || $country eq 'French Southern Territories'
249 || $country eq 'United States Minor Outlying Islands'
250 || $country eq 'Mayotte'
251 || $country eq 'Zaire');
255 $reverse = code2country($code, LOCALE_CODE_NUMERIC);
256 if (!defined $reverse)
261 if ($reverse ne $country)
267 print ($ok ? "ok 8\n" : "not ok 8\n");
271 foreach $code (all_language_codes())
273 $language = code2language($code);
274 if (!defined $language)
279 $reverse = language2code($language);
280 if (!defined $reverse)
285 if ($reverse ne $code)
291 print ($ok ? "ok 9\n" : "not ok 9\n");
295 foreach $language (all_language_names())
297 $code = language2code($language);
303 $reverse = code2language($code);
304 if (!defined $reverse)
309 if ($reverse ne $language)
315 print ($ok ? "ok 10\n" : "not ok 10\n");
318 foreach $code (all_currency_codes())
320 $currency = code2currency($code);
321 if (!defined $currency)
326 $reverse = currency2code($currency);
327 if (!defined $reverse)
333 # three special cases:
334 # The Kwacha has two codes - used in Zambia and Malawi
335 # The Russian Ruble has two codes - rub and rur
336 # The Belarussian Ruble has two codes - byb and byr
337 if ($reverse ne $code
338 && $code ne 'mwk' && $code ne 'zmk'
339 && $code ne 'byr' && $code ne 'byb'
340 && $code ne 'rub' && $code ne 'rur')
346 print ($ok ? "ok 11\n" : "not ok 11\n");
349 foreach $currency (all_currency_names())
351 $code = currency2code($currency);
357 $reverse = code2currency($code);
358 if (!defined $reverse)
363 if ($reverse ne $currency)
369 print ($ok ? "ok 12\n" : "not ok 12\n");
371 #=======================================================================
373 # Locale::Script tests
375 #=======================================================================
377 #-----------------------------------------------------------------------
378 # Old API - without codeset specified, default to ALPHA_2
379 #-----------------------------------------------------------------------
381 foreach $code (all_script_codes())
383 $script = code2script($code);
384 if (!defined $script)
389 $reverse = script2code($script);
390 if (!defined $reverse)
395 if ($reverse ne $code)
401 print ($ok ? "ok 13\n" : "not ok 13\n");
403 #-----------------------------------------------------------------------
404 # code to script, back to code, for ALPHA2
405 #-----------------------------------------------------------------------
407 foreach $code (all_script_codes(LOCALE_CODE_ALPHA_2))
409 $script = code2script($code, LOCALE_CODE_ALPHA_2);
410 if (!defined $script)
415 $reverse = script2code($script, LOCALE_CODE_ALPHA_2);
416 if (!defined $reverse)
421 if ($reverse ne $code)
427 print ($ok ? "ok 14\n" : "not ok 14\n");
429 #-----------------------------------------------------------------------
430 # code to script, back to code, for ALPHA3
431 #-----------------------------------------------------------------------
433 foreach $code (all_script_codes(LOCALE_CODE_ALPHA_3))
435 $script = code2script($code, LOCALE_CODE_ALPHA_3);
436 if (!defined $script)
441 $reverse = script2code($script, LOCALE_CODE_ALPHA_3);
442 if (!defined $reverse)
447 if ($reverse ne $code)
453 print ($ok ? "ok 15\n" : "not ok 15\n");
455 #-----------------------------------------------------------------------
456 # code to script, back to code, for NUMERIC
457 #-----------------------------------------------------------------------
459 foreach $code (all_script_codes(LOCALE_CODE_NUMERIC))
461 $script = code2script($code, LOCALE_CODE_NUMERIC);
462 if (!defined $script)
467 $reverse = script2code($script, LOCALE_CODE_NUMERIC);
468 if (!defined $reverse)
473 if ($reverse ne $code)
479 print ($ok ? "ok 16\n" : "not ok 16\n");
482 #-----------------------------------------------------------------------
483 # Old API - script to code, back to script, using default of ALPHA_2
484 #-----------------------------------------------------------------------
486 foreach $script (all_script_names())
488 $code = script2code($script);
494 $reverse = code2script($code);
495 if (!defined $reverse)
500 if ($reverse ne $script)
506 print ($ok ? "ok 17\n" : "not ok 17\n");
508 #-----------------------------------------------------------------------
509 # script to code, back to script, using LOCALE_CODE_ALPHA_2
510 #-----------------------------------------------------------------------
512 foreach $script (all_script_names())
514 $code = script2code($script, LOCALE_CODE_ALPHA_2);
520 $reverse = code2script($code, LOCALE_CODE_ALPHA_2);
521 if (!defined $reverse)
526 if ($reverse ne $script)
532 print ($ok ? "ok 18\n" : "not ok 18\n");
534 #-----------------------------------------------------------------------
535 # script to code, back to script, using LOCALE_CODE_ALPHA_3
536 #-----------------------------------------------------------------------
538 foreach $script (all_script_names())
540 $code = script2code($script, LOCALE_CODE_ALPHA_3);
546 $reverse = code2script($code, LOCALE_CODE_ALPHA_3);
547 if (!defined $reverse)
552 if ($reverse ne $script)
558 print ($ok ? "ok 19\n" : "not ok 19\n");
560 #-----------------------------------------------------------------------
561 # script to code, back to script, using LOCALE_CODE_NUMERIC
562 #-----------------------------------------------------------------------
564 foreach $script (all_script_names())
566 $code = script2code($script, LOCALE_CODE_NUMERIC);
572 $reverse = code2script($code, LOCALE_CODE_NUMERIC);
573 if (!defined $reverse)
578 if ($reverse ne $script)
584 print ($ok ? "ok 20\n" : "not ok 20\n");