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.
31 #-----------------------------------------------------------------------
32 # Old API - without codeset specified, default to ALPHA_2
33 #-----------------------------------------------------------------------
35 foreach $code (all_country_codes())
37 $country = code2country($code);
38 if (!defined $country)
43 $reverse = country2code($country);
44 if (!defined $reverse)
49 if ($reverse ne $code)
55 print ($ok ? "ok 1\n" : "not ok 1\n");
57 #-----------------------------------------------------------------------
58 # code to country, back to code, for ALPHA2
59 #-----------------------------------------------------------------------
61 foreach $code (all_country_codes(LOCALE_CODE_ALPHA_2))
63 $country = code2country($code, LOCALE_CODE_ALPHA_2);
64 if (!defined $country)
69 $reverse = country2code($country, LOCALE_CODE_ALPHA_2);
70 if (!defined $reverse)
75 if ($reverse ne $code)
81 print ($ok ? "ok 2\n" : "not ok 2\n");
83 #-----------------------------------------------------------------------
84 # code to country, back to code, for ALPHA3
85 #-----------------------------------------------------------------------
87 foreach $code (all_country_codes(LOCALE_CODE_ALPHA_3))
89 $country = code2country($code, LOCALE_CODE_ALPHA_3);
90 if (!defined $country)
95 $reverse = country2code($country, LOCALE_CODE_ALPHA_3);
96 if (!defined $reverse)
101 if ($reverse ne $code)
107 print ($ok ? "ok 3\n" : "not ok 3\n");
109 #-----------------------------------------------------------------------
110 # code to country, back to code, for NUMERIC
111 #-----------------------------------------------------------------------
113 foreach $code (all_country_codes(LOCALE_CODE_NUMERIC))
115 $country = code2country($code, LOCALE_CODE_NUMERIC);
116 if (!defined $country)
121 $reverse = country2code($country, LOCALE_CODE_NUMERIC);
122 if (!defined $reverse)
127 if ($reverse ne $code)
133 print ($ok ? "ok 4\n" : "not ok 4\n");
136 #-----------------------------------------------------------------------
137 # Old API - country to code, back to country, using default of ALPHA_2
138 #-----------------------------------------------------------------------
140 foreach $country (all_country_names())
142 $code = country2code($country);
148 $reverse = code2country($code);
149 if (!defined $reverse)
154 if ($reverse ne $country)
160 print ($ok ? "ok 5\n" : "not ok 5\n");
162 #-----------------------------------------------------------------------
163 # country to code, back to country, using LOCALE_CODE_ALPHA_2
164 #-----------------------------------------------------------------------
166 foreach $country (all_country_names())
168 $code = country2code($country, LOCALE_CODE_ALPHA_2);
174 $reverse = code2country($code, LOCALE_CODE_ALPHA_2);
175 if (!defined $reverse)
180 if ($reverse ne $country)
186 print ($ok ? "ok 6\n" : "not ok 6\n");
188 #-----------------------------------------------------------------------
189 # country to code, back to country, using LOCALE_CODE_ALPHA_3
190 #-----------------------------------------------------------------------
192 foreach $country (all_country_names())
194 $code = country2code($country, LOCALE_CODE_ALPHA_3);
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');
212 $reverse = code2country($code, LOCALE_CODE_ALPHA_3);
213 if (!defined $reverse)
218 if ($reverse ne $country)
224 print ($ok ? "ok 7\n" : "not ok 7\n");
226 #-----------------------------------------------------------------------
227 # country to code, back to country, using LOCALE_CODE_NUMERIC
228 #-----------------------------------------------------------------------
230 foreach $country (all_country_names())
232 $code = country2code($country, LOCALE_CODE_NUMERIC);
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');
250 $reverse = code2country($code, LOCALE_CODE_NUMERIC);
251 if (!defined $reverse)
256 if ($reverse ne $country)
262 print ($ok ? "ok 8\n" : "not ok 8\n");
266 foreach $code (all_language_codes())
268 $language = code2language($code);
269 if (!defined $language)
274 $reverse = language2code($language);
275 if (!defined $reverse)
280 if ($reverse ne $code)
286 print ($ok ? "ok 9\n" : "not ok 9\n");
290 foreach $language (all_language_names())
292 $code = language2code($language);
298 $reverse = code2language($code);
299 if (!defined $reverse)
304 if ($reverse ne $language)
310 print ($ok ? "ok 10\n" : "not ok 10\n");
313 foreach $code (all_currency_codes())
315 $currency = code2currency($code);
316 if (!defined $currency)
321 $reverse = currency2code($currency);
322 if (!defined $reverse)
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')
341 print ($ok ? "ok 11\n" : "not ok 11\n");
344 foreach $currency (all_currency_names())
346 $code = currency2code($currency);
352 $reverse = code2currency($code);
353 if (!defined $reverse)
358 if ($reverse ne $currency)
364 print ($ok ? "ok 12\n" : "not ok 12\n");
366 #=======================================================================
368 # Locale::Script tests
370 #=======================================================================
372 #-----------------------------------------------------------------------
373 # Old API - without codeset specified, default to ALPHA_2
374 #-----------------------------------------------------------------------
376 foreach $code (all_script_codes())
378 $script = code2script($code);
379 if (!defined $script)
384 $reverse = script2code($script);
385 if (!defined $reverse)
390 if ($reverse ne $code)
396 print ($ok ? "ok 13\n" : "not ok 13\n");
398 #-----------------------------------------------------------------------
399 # code to script, back to code, for ALPHA2
400 #-----------------------------------------------------------------------
402 foreach $code (all_script_codes(LOCALE_CODE_ALPHA_2))
404 $script = code2script($code, LOCALE_CODE_ALPHA_2);
405 if (!defined $script)
410 $reverse = script2code($script, LOCALE_CODE_ALPHA_2);
411 if (!defined $reverse)
416 if ($reverse ne $code)
422 print ($ok ? "ok 14\n" : "not ok 14\n");
424 #-----------------------------------------------------------------------
425 # code to script, back to code, for ALPHA3
426 #-----------------------------------------------------------------------
428 foreach $code (all_script_codes(LOCALE_CODE_ALPHA_3))
430 $script = code2script($code, LOCALE_CODE_ALPHA_3);
431 if (!defined $script)
436 $reverse = script2code($script, LOCALE_CODE_ALPHA_3);
437 if (!defined $reverse)
442 if ($reverse ne $code)
448 print ($ok ? "ok 15\n" : "not ok 15\n");
450 #-----------------------------------------------------------------------
451 # code to script, back to code, for NUMERIC
452 #-----------------------------------------------------------------------
454 foreach $code (all_script_codes(LOCALE_CODE_NUMERIC))
456 $script = code2script($code, LOCALE_CODE_NUMERIC);
457 if (!defined $script)
462 $reverse = script2code($script, LOCALE_CODE_NUMERIC);
463 if (!defined $reverse)
468 if ($reverse ne $code)
474 print ($ok ? "ok 16\n" : "not ok 16\n");
477 #-----------------------------------------------------------------------
478 # Old API - script to code, back to script, using default of ALPHA_2
479 #-----------------------------------------------------------------------
481 foreach $script (all_script_names())
483 $code = script2code($script);
489 $reverse = code2script($code);
490 if (!defined $reverse)
495 if ($reverse ne $script)
501 print ($ok ? "ok 17\n" : "not ok 17\n");
503 #-----------------------------------------------------------------------
504 # script to code, back to script, using LOCALE_CODE_ALPHA_2
505 #-----------------------------------------------------------------------
507 foreach $script (all_script_names())
509 $code = script2code($script, LOCALE_CODE_ALPHA_2);
515 $reverse = code2script($code, LOCALE_CODE_ALPHA_2);
516 if (!defined $reverse)
521 if ($reverse ne $script)
527 print ($ok ? "ok 18\n" : "not ok 18\n");
529 #-----------------------------------------------------------------------
530 # script to code, back to script, using LOCALE_CODE_ALPHA_3
531 #-----------------------------------------------------------------------
533 foreach $script (all_script_names())
535 $code = script2code($script, LOCALE_CODE_ALPHA_3);
541 $reverse = code2script($code, LOCALE_CODE_ALPHA_3);
542 if (!defined $reverse)
547 if ($reverse ne $script)
553 print ($ok ? "ok 19\n" : "not ok 19\n");
555 #-----------------------------------------------------------------------
556 # script to code, back to script, using LOCALE_CODE_NUMERIC
557 #-----------------------------------------------------------------------
559 foreach $script (all_script_names())
561 $code = script2code($script, LOCALE_CODE_NUMERIC);
567 $reverse = code2script($code, LOCALE_CODE_NUMERIC);
568 if (!defined $reverse)
573 if ($reverse ne $script)
579 print ($ok ? "ok 20\n" : "not ok 20\n");