diff options
Diffstat (limited to 'lib/Locale/Codes')
-rw-r--r-- | lib/Locale/Codes/t/all.t | 366 | ||||
-rw-r--r-- | lib/Locale/Codes/t/constants.t | 49 | ||||
-rw-r--r-- | lib/Locale/Codes/t/country.t | 114 | ||||
-rw-r--r-- | lib/Locale/Codes/t/currency.t | 85 | ||||
-rw-r--r-- | lib/Locale/Codes/t/languages.t | 110 | ||||
-rw-r--r-- | lib/Locale/Codes/t/uk.t | 70 |
6 files changed, 794 insertions, 0 deletions
diff --git a/lib/Locale/Codes/t/all.t b/lib/Locale/Codes/t/all.t new file mode 100644 index 0000000000..ed93c5a856 --- /dev/null +++ b/lib/Locale/Codes/t/all.t @@ -0,0 +1,366 @@ +#!./perl +# +# all.t - tests for all_* routines in +# Locale::Country +# Locale::Language +# Locale::Currency +# +# There are four tests. We get a list of all codes, convert to +# language/country/currency, # convert back to code, +# and check that they're the same. Then we do the same, +# starting with list of languages/countries/currencies. +# + +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; +} + +use Locale::Country; +use Locale::Language; +use Locale::Currency; + +print "1..12\n"; + +my $code; +my $language; +my $country; +my $ok; +my $reverse; +my $currency; + + +#----------------------------------------------------------------------- +# Old API - without codeset specified, default to ALPHA_2 +#----------------------------------------------------------------------- +$ok = 1; +foreach $code (all_country_codes()) +{ + $country = code2country($code); + if (!defined $country) + { + $ok = 0; + last; + } + $reverse = country2code($country); + if (!defined $reverse) + { + $ok = 0; + last; + } + if ($reverse ne $code) + { + $ok = 0; + last; + } +} +print ($ok ? "ok 1\n" : "not ok 1\n"); + +#----------------------------------------------------------------------- +# code to country, back to code, for ALPHA2 +#----------------------------------------------------------------------- +$ok = 1; +foreach $code (all_country_codes(LOCALE_CODE_ALPHA_2)) +{ + $country = code2country($code, LOCALE_CODE_ALPHA_2); + if (!defined $country) + { + $ok = 0; + last; + } + $reverse = country2code($country, LOCALE_CODE_ALPHA_2); + if (!defined $reverse) + { + $ok = 0; + last; + } + if ($reverse ne $code) + { + $ok = 0; + last; + } +} +print ($ok ? "ok 2\n" : "not ok 2\n"); + +#----------------------------------------------------------------------- +# code to country, back to code, for ALPHA3 +#----------------------------------------------------------------------- +$ok = 1; +foreach $code (all_country_codes(LOCALE_CODE_ALPHA_3)) +{ + $country = code2country($code, LOCALE_CODE_ALPHA_3); + if (!defined $country) + { + $ok = 0; + last; + } + $reverse = country2code($country, LOCALE_CODE_ALPHA_3); + if (!defined $reverse) + { + $ok = 0; + last; + } + if ($reverse ne $code) + { + $ok = 0; + last; + } +} +print ($ok ? "ok 3\n" : "not ok 3\n"); + +#----------------------------------------------------------------------- +# code to country, back to code, for NUMERIC +#----------------------------------------------------------------------- +$ok = 1; +foreach $code (all_country_codes(LOCALE_CODE_NUMERIC)) +{ + $country = code2country($code, LOCALE_CODE_NUMERIC); + if (!defined $country) + { + $ok = 0; + last; + } + $reverse = country2code($country, LOCALE_CODE_NUMERIC); + if (!defined $reverse) + { + $ok = 0; + last; + } + if ($reverse ne $code) + { + $ok = 0; + last; + } +} +print ($ok ? "ok 4\n" : "not ok 4\n"); + + +#----------------------------------------------------------------------- +# Old API - country to code, back to country, using default of ALPHA_2 +#----------------------------------------------------------------------- +$ok = 1; +foreach $country (all_country_names()) +{ + $code = country2code($country); + if (!defined $code) + { + $ok = 0; + last; + } + $reverse = code2country($code); + if (!defined $reverse) + { + $ok = 0; + last; + } + if ($reverse ne $country) + { + $ok = 0; + last; + } +} +print ($ok ? "ok 5\n" : "not ok 5\n"); + +#----------------------------------------------------------------------- +# country to code, back to country, using LOCALE_CODE_ALPHA_2 +#----------------------------------------------------------------------- +$ok = 1; +foreach $country (all_country_names()) +{ + $code = country2code($country, LOCALE_CODE_ALPHA_2); + if (!defined $code) + { + $ok = 0; + last; + } + $reverse = code2country($code, LOCALE_CODE_ALPHA_2); + if (!defined $reverse) + { + $ok = 0; + last; + } + if ($reverse ne $country) + { + $ok = 0; + last; + } +} +print ($ok ? "ok 6\n" : "not ok 6\n"); + +#----------------------------------------------------------------------- +# country to code, back to country, using LOCALE_CODE_ALPHA_3 +#----------------------------------------------------------------------- +$ok = 1; +foreach $country (all_country_names()) +{ + $code = country2code($country, LOCALE_CODE_ALPHA_3); + if (!defined $code) + { + next if ($country eq 'Antarctica' + || $country eq 'Bouvet Island' + || $country eq 'Cocos (Keeling) Islands' + || $country eq 'Christmas Island' + || $country eq 'France, Metropolitan' + || $country eq 'South Georgia and the South Sandwich Islands' + || $country eq 'Heard Island and McDonald Islands' + || $country eq 'British Indian Ocean Territory' + || $country eq 'French Southern Territories' + || $country eq 'United States Minor Outlying Islands' + || $country eq 'Mayotte' + || $country eq 'Zaire'); + $ok = 0; + last; + } + $reverse = code2country($code, LOCALE_CODE_ALPHA_3); + if (!defined $reverse) + { + $ok = 0; + last; + } + if ($reverse ne $country) + { + $ok = 0; + last; + } +} +print ($ok ? "ok 7\n" : "not ok 7\n"); + +#----------------------------------------------------------------------- +# country to code, back to country, using LOCALE_CODE_NUMERIC +#----------------------------------------------------------------------- +$ok = 1; +foreach $country (all_country_names()) +{ + $code = country2code($country, LOCALE_CODE_NUMERIC); + if (!defined $code) + { + next if ($country eq 'Antarctica' + || $country eq 'Bouvet Island' + || $country eq 'Cocos (Keeling) Islands' + || $country eq 'Christmas Island' + || $country eq 'France, Metropolitan' + || $country eq 'South Georgia and the South Sandwich Islands' + || $country eq 'Heard Island and McDonald Islands' + || $country eq 'British Indian Ocean Territory' + || $country eq 'French Southern Territories' + || $country eq 'United States Minor Outlying Islands' + || $country eq 'Mayotte' + || $country eq 'Zaire'); + $ok = 0; + last; + } + $reverse = code2country($code, LOCALE_CODE_NUMERIC); + if (!defined $reverse) + { + $ok = 0; + last; + } + if ($reverse ne $country) + { + $ok = 0; + last; + } +} +print ($ok ? "ok 8\n" : "not ok 8\n"); + + +$ok = 1; +foreach $code (all_language_codes()) +{ + $language = code2language($code); + if (!defined $language) + { + $ok = 0; + last; + } + $reverse = language2code($language); + if (!defined $reverse) + { + $ok = 0; + last; + } + if ($reverse ne $code) + { + $ok = 0; + last; + } +} +print ($ok ? "ok 9\n" : "not ok 9\n"); + + +$ok = 1; +foreach $language (all_language_names()) +{ + $code = language2code($language); + if (!defined $code) + { + $ok = 0; + last; + } + $reverse = code2language($code); + if (!defined $reverse) + { + $ok = 0; + last; + } + if ($reverse ne $language) + { + $ok = 0; + last; + } +} +print ($ok ? "ok 10\n" : "not ok 10\n"); + +$ok = 1; +foreach $code (all_currency_codes()) +{ + $currency = code2currency($code); + if (!defined $currency) + { + $ok = 0; + last; + } + $reverse = currency2code($currency); + if (!defined $reverse) + { + $ok = 0; + last; + } + # + # three special cases: + # The Kwacha has two codes - used in Zambia and Malawi + # The Russian Ruble has two codes - rub and rur + # The Belarussian Ruble has two codes - byb and byr + if ($reverse ne $code + && $code ne 'mwk' && $code ne 'zmk' + && $code ne 'byr' && $code ne 'byb' + && $code ne 'rub' && $code ne 'rur') + { + $ok = 0; + last; + } +} +print ($ok ? "ok 11\n" : "not ok 11\n"); + +$ok = 1; +foreach $currency (all_currency_names()) +{ + $code = currency2code($currency); + if (!defined $code) + { + $ok = 0; + last; + } + $reverse = code2currency($code); + if (!defined $reverse) + { + $ok = 0; + last; + } + if ($reverse ne $currency) + { + $ok = 0; + last; + } +} +print ($ok ? "ok 12\n" : "not ok 12\n"); diff --git a/lib/Locale/Codes/t/constants.t b/lib/Locale/Codes/t/constants.t new file mode 100644 index 0000000000..359cdfc7a5 --- /dev/null +++ b/lib/Locale/Codes/t/constants.t @@ -0,0 +1,49 @@ +#!./perl +# +# constants.t - tests for Locale::Constants +# + +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; +} + +use Locale::Constants; + +print "1..3\n"; + +if (defined LOCALE_CODE_ALPHA_2 + && defined LOCALE_CODE_ALPHA_3 + && defined LOCALE_CODE_NUMERIC) +{ + print "ok 1\n"; +} +else +{ + print "not ok 1\n"; +} + +if (LOCALE_CODE_ALPHA_2 != LOCALE_CODE_ALPHA_3 + && LOCALE_CODE_ALPHA_2 != LOCALE_CODE_NUMERIC + && LOCALE_CODE_ALPHA_3 != LOCALE_CODE_NUMERIC) +{ + print "ok 2\n"; +} +else +{ + print "not ok 2\n"; +} + +if (defined LOCALE_CODE_DEFAULT + && (LOCALE_CODE_DEFAULT == LOCALE_CODE_ALPHA_2 + || LOCALE_CODE_DEFAULT == LOCALE_CODE_ALPHA_3 + || LOCALE_CODE_DEFAULT == LOCALE_CODE_NUMERIC)) +{ + print "ok 3\n"; +} +else +{ + print "not ok 3\n"; +} + +exit 0; diff --git a/lib/Locale/Codes/t/country.t b/lib/Locale/Codes/t/country.t new file mode 100644 index 0000000000..4234d1e6a7 --- /dev/null +++ b/lib/Locale/Codes/t/country.t @@ -0,0 +1,114 @@ +#!./perl +# +# country.t - tests for Locale::Country +# + +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; +} + +use Locale::Country; + +#----------------------------------------------------------------------- +# This is an array of tests specs. Each spec is [TEST, OK_TO_DIE] +# Each TEST is eval'd as an expression. +# If it evaluates to FALSE, then "not ok N" is printed for the test, +# otherwise "ok N". If the eval dies, then the OK_TO_DIE flag is checked. +# If it is true (1), the test is treated as passing, otherwise it failed. +#----------------------------------------------------------------------- +@TESTS = +( + #================================================ + # TESTS FOR code2country + #================================================ + + #---- selection of examples which should all result in undef ----------- + ['!defined code2country()', 0], # no argument + ['!defined code2country(undef)', 0], # undef argument + ['!defined code2country("zz")', 0], # illegal code + ['!defined code2country("zz", LOCALE_CODE_ALPHA_2)', 0], # illegal code + ['!defined code2country("zz", LOCALE_CODE_ALPHA_3)', 0], # illegal code + ['!defined code2country("zz", LOCALE_CODE_NUMERIC)', 0], # illegal code + ['!defined code2country("ja")', 0], # should be jp for country + ['!defined code2country("uk")', 0], # should be jp for country + + #---- some successful examples ----------------------------------------- + ['code2country("BO") eq "Bolivia"', 0], + ['code2country("BO", LOCALE_CODE_ALPHA_2) eq "Bolivia"', 0], + ['code2country("bol", LOCALE_CODE_ALPHA_3) eq "Bolivia"', 0], + ['code2country("pk") eq "Pakistan"', 0], + ['code2country("sn") eq "Senegal"', 0], + ['code2country("us") eq "United States"', 0], + ['code2country("ad") eq "Andorra"', 0], # first in DATA segment + ['code2country("ad", LOCALE_CODE_ALPHA_2) eq "Andorra"', 0], + ['code2country("and", LOCALE_CODE_ALPHA_3) eq "Andorra"', 0], + ['code2country("020", LOCALE_CODE_NUMERIC) eq "Andorra"', 0], + ['code2country(48, LOCALE_CODE_NUMERIC) eq "Bahrain"', 0], + ['code2country("zw") eq "Zimbabwe"', 0], # last in DATA segment + ['code2country("gb") eq "United Kingdom"', 0], # United Kingdom is "gb", not "uk" + + #================================================ + # TESTS FOR country2code + #================================================ + + #---- selection of examples which should all result in undef ----------- + ['!defined code2country("BO", LOCALE_CODE_ALPHA_3)', 0], + ['!defined code2country("BO", LOCALE_CODE_NUMERIC)', 0], + ['!defined country2code()', 0], # no argument + ['!defined country2code(undef)', 0], # undef argument + ['!defined country2code("Banana")', 0], # illegal country name + + #---- some successful examples ----------------------------------------- + ['country2code("japan") eq "jp"', 0], + ['country2code("japan") ne "ja"', 0], + ['country2code("Japan") eq "jp"', 0], + ['country2code("United States") eq "us"', 0], + ['country2code("United Kingdom") eq "gb"', 0], + ['country2code("Andorra") eq "ad"', 0], # first in DATA segment + ['country2code("Zimbabwe") eq "zw"', 0], # last in DATA segment + + #================================================ + # TESTS FOR country_code2code + #================================================ + + #---- selection of examples which should all result in undef ----------- + ['!defined country_code2code("bo", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_3)', 0], + ['!defined country_code2code("zz", LOCALE_CODE_ALPHA_2, LOCALE_CODE_ALPHA_3)', 0], + ['!defined country_code2code("zz", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_3)', 0], + ['!defined country_code2code("zz", LOCALE_CODE_ALPHA_2)', 1], + ['!defined country_code2code("bo", LOCALE_CODE_ALPHA_2)', 1], + ['!defined country_code2code()', 1], # no argument + ['!defined country_code2code(undef)', 1], # undef argument + + #---- some successful examples ----------------------------------------- + ['country_code2code("BO", LOCALE_CODE_ALPHA_2, LOCALE_CODE_ALPHA_3) eq "bol"', 0], + ['country_code2code("bol", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_2) eq "bo"', 0], + ['country_code2code("zwe", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_2) eq "zw"', 0], + ['country_code2code("858", LOCALE_CODE_NUMERIC, LOCALE_CODE_ALPHA_3) eq "ury"', 0], + ['country_code2code(858, LOCALE_CODE_NUMERIC, LOCALE_CODE_ALPHA_3) eq "ury"', 0], + ['country_code2code("tr", LOCALE_CODE_ALPHA_2, LOCALE_CODE_NUMERIC) eq "792"', 0], + +); + +print "1..", int(@TESTS), "\n"; + +$testid = 1; +foreach $test (@TESTS) +{ + eval "print (($test->[0]) ? \"ok $testid\\n\" : \"not ok $testid\\n\" )"; + if ($@) + { + if (!$test->[1]) + { + print "not ok $testid\n"; + } + else + { + print "ok $testid\n"; + } + } + ++$testid; +} + +exit 0; diff --git a/lib/Locale/Codes/t/currency.t b/lib/Locale/Codes/t/currency.t new file mode 100644 index 0000000000..55a04db9fb --- /dev/null +++ b/lib/Locale/Codes/t/currency.t @@ -0,0 +1,85 @@ +#!./perl +# +# currency.t - tests for Locale::Currency +# + +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; +} + +use Locale::Currency; + +#----------------------------------------------------------------------- +# This is an array of tests. Each test is eval'd as an expression. +# If it evaluates to FALSE, then "not ok N" is printed for the test, +# otherwise "ok N". +#----------------------------------------------------------------------- +@TESTS = +( + #================================================ + # TESTS FOR code2currency + #================================================ + + #---- selection of examples which should all result in undef ----------- + '!defined code2currency()', # no argument => undef returned + '!defined code2currency(undef)', # undef arg => undef returned + '!defined code2currency("zz")', # illegal code => undef + '!defined code2currency("zzzz")', # illegal code => undef + '!defined code2currency("zzz")', # illegal code => undef + '!defined code2currency("ukp")', # gbp for sterling, not ukp + + #---- misc tests ------------------------------------------------------- + 'code2currency("all") eq "Lek"', + 'code2currency("ats") eq "Schilling"', + 'code2currency("bob") eq "Boliviano"', + 'code2currency("bnd") eq "Brunei Dollar"', + 'code2currency("cop") eq "Colombian Peso"', + 'code2currency("dkk") eq "Danish Krone"', + 'code2currency("fjd") eq "Fiji Dollar"', + 'code2currency("idr") eq "Rupiah"', + 'code2currency("chf") eq "Swiss Franc"', + 'code2currency("mvr") eq "Rufiyaa"', + 'code2currency("mmk") eq "Kyat"', + 'code2currency("mwk") eq "Kwacha"', # two different codes for Kwacha + 'code2currency("zmk") eq "Kwacha"', # used in Zambia and Malawi + 'code2currency("byr") eq "Belarussian Ruble"', # 2 codes for belarussian ruble + 'code2currency("byb") eq "Belarussian Ruble"', # + 'code2currency("rub") eq "Russian Ruble"', # 2 codes for russian ruble + 'code2currency("rur") eq "Russian Ruble"', # + + #---- some successful examples ----------------------------------------- + 'code2currency("BOB") eq "Boliviano"', + 'code2currency("adp") eq "Andorran Peseta"', # first in DATA segment + 'code2currency("zwd") eq "Zimbabwe Dollar"', # last in DATA segment + + #================================================ + # TESTS FOR currency2code + #================================================ + + #---- selection of examples which should all result in undef ----------- + '!defined currency2code()', # no argument => undef returned + '!defined currency2code(undef)', # undef arg => undef returned + '!defined currency2code("")', # empty string => undef returned + '!defined currency2code("Banana")', # illegal curr name => undef + + #---- some successful examples ----------------------------------------- + 'currency2code("Kroon") eq "eek"', + 'currency2code("Markka") eq "fim"', + 'currency2code("Riel") eq "khr"', + 'currency2code("PULA") eq "bwp"', + 'currency2code("Andorran Peseta") eq "adp"', # first in DATA segment + 'currency2code("Zimbabwe Dollar") eq "zwd"', # last in DATA segment +); + +print "1..", int(@TESTS), "\n"; + +$testid = 1; +foreach $test (@TESTS) +{ + eval "print (($test) ? \"ok $testid\\n\" : \"not ok $testid\\n\" )"; + print "not ok $testid\n" if $@; + ++$testid; +} + +exit 0; diff --git a/lib/Locale/Codes/t/languages.t b/lib/Locale/Codes/t/languages.t new file mode 100644 index 0000000000..9facd3509d --- /dev/null +++ b/lib/Locale/Codes/t/languages.t @@ -0,0 +1,110 @@ +#!./perl +# +# language.t - tests for Locale::Language +# + +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; +} + +use Locale::Language; + +no utf8; # so that the naked 8-bit characters won't gripe under use utf8 + +#----------------------------------------------------------------------- +# This is an array of tests. Each test is eval'd as an expression. +# If it evaluates to FALSE, then "not ok N" is printed for the test, +# otherwise "ok N". +#----------------------------------------------------------------------- +@TESTS = +( + #================================================ + # TESTS FOR code2language + #================================================ + + #---- selection of examples which should all result in undef ----------- + '!defined code2language()', # no argument => undef returned + '!defined code2language(undef)', # undef arg => undef returned + '!defined code2language("zz")', # illegal code => undef + '!defined code2language("jp")', # ja for lang, jp for country + + #---- test recent changes ---------------------------------------------- + 'code2language("ae") eq "Avestan"', + 'code2language("bs") eq "Bosnian"', + 'code2language("ch") eq "Chamorro"', + 'code2language("ce") eq "Chechen"', + 'code2language("cu") eq "Church Slavic"', + 'code2language("cv") eq "Chuvash"', + 'code2language("hz") eq "Herero"', + 'code2language("ho") eq "Hiri Motu"', + 'code2language("ki") eq "Kikuyu"', + 'code2language("kj") eq "Kuanyama"', + 'code2language("kv") eq "Komi"', + 'code2language("mh") eq "Marshall"', + 'code2language("nv") eq "Navajo"', + 'code2language("nr") eq "Ndebele, South"', + 'code2language("nd") eq "Ndebele, North"', + 'code2language("ng") eq "Ndonga"', + 'code2language("nn") eq "Norwegian Nynorsk"', + 'code2language("nb") eq "Norwegian Bokmål"', + 'code2language("ny") eq "Chichewa; Nyanja"', + 'code2language("oc") eq "Occitan (post 1500)"', + 'code2language("os") eq "Ossetian; Ossetic"', + 'code2language("pi") eq "Pali"', + '!defined code2language("sh")', # Serbo-Croatian withdrawn + 'code2language("se") eq "Sami"', + 'code2language("sc") eq "Sardinian"', + 'code2language("kw") eq "Cornish"', + 'code2language("gv") eq "Manx"', + 'code2language("lb") eq "Letzeburgesch"', + 'code2language("he") eq "Hebrew"', + '!defined code2language("iw")', # Hebrew withdrawn + 'code2language("id") eq "Indonesian"', + '!defined code2language("in")', # Indonesian withdrawn + 'code2language("iu") eq "Inuktitut"', + 'code2language("ug") eq "Uighur"', + '!defined code2language("ji")', # Yiddish withdrawn + 'code2language("yi") eq "Yiddish"', + 'code2language("za") eq "Zhuang"', + + #---- some successful examples ----------------------------------------- + 'code2language("DA") eq "Danish"', + 'code2language("eo") eq "Esperanto"', + 'code2language("fi") eq "Finnish"', + 'code2language("en") eq "English"', + 'code2language("aa") eq "Afar"', # first in DATA segment + 'code2language("zu") eq "Zulu"', # last in DATA segment + + #================================================ + # TESTS FOR language2code + #================================================ + + #---- selection of examples which should all result in undef ----------- + '!defined language2code()', # no argument => undef returned + '!defined language2code(undef)', # undef arg => undef returned + '!defined language2code("Banana")', # illegal lang name => undef + + #---- some successful examples ----------------------------------------- + 'language2code("Japanese") eq "ja"', + 'language2code("japanese") eq "ja"', + 'language2code("japanese") ne "jp"', + 'language2code("French") eq "fr"', + 'language2code("Greek") eq "el"', + 'language2code("english") eq "en"', + 'language2code("ESTONIAN") eq "et"', + 'language2code("Afar") eq "aa"', # first in DATA segment + 'language2code("Zulu") eq "zu"', # last in DATA segment +); + +print "1..", int(@TESTS), "\n"; + +$testid = 1; +foreach $test (@TESTS) +{ + eval "print (($test) ? \"ok $testid\\n\" : \"not ok $testid\\n\" )"; + print "not ok $testid\n" if $@; + ++$testid; +} + +exit 0; diff --git a/lib/Locale/Codes/t/uk.t b/lib/Locale/Codes/t/uk.t new file mode 100644 index 0000000000..948e2d1af2 --- /dev/null +++ b/lib/Locale/Codes/t/uk.t @@ -0,0 +1,70 @@ +#!./perl +# +# uk.t - tests for Locale::Country with "uk" aliases to "gb" +# + +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; +} + +use Locale::Country; + +Locale::Country::_alias_code('uk' => 'gb'); + +#----------------------------------------------------------------------- +# This is an array of tests. Each test is eval'd as an expression. +# If it evaluates to FALSE, then "not ok N" is printed for the test, +# otherwise "ok N". +#----------------------------------------------------------------------- +@TESTS = +( + #================================================ + # TESTS FOR code2country + #================================================ + + #---- selection of examples which should all result in undef ----------- + '!defined code2country()', # no argument + '!defined code2country(undef)', # undef argument + '!defined code2country("zz")', # illegal code + '!defined code2country("ja")', # should be jp for country + + #---- some successful examples ----------------------------------------- + 'code2country("BO") eq "Bolivia"', + 'code2country("pk") eq "Pakistan"', + 'code2country("sn") eq "Senegal"', + 'code2country("us") eq "United States"', + 'code2country("ad") eq "Andorra"', # first in DATA segment + 'code2country("zw") eq "Zimbabwe"', # last in DATA segment + 'code2country("uk") eq "United Kingdom"', # normally "gb" + + #================================================ + # TESTS FOR country2code + #================================================ + + #---- selection of examples which should all result in undef ----------- + '!defined country2code()', # no argument + '!defined country2code(undef)', # undef argument + '!defined country2code("Banana")', # illegal country name + + #---- some successful examples ----------------------------------------- + 'country2code("japan") eq "jp"', + 'country2code("japan") ne "ja"', + 'country2code("Japan") eq "jp"', + 'country2code("United States") eq "us"', + 'country2code("United Kingdom") eq "uk"', + 'country2code("Andorra") eq "ad"', # first in DATA segment + 'country2code("Zimbabwe") eq "zw"', # last in DATA segment +); + +print "1..", int(@TESTS), "\n"; + +$testid = 1; +foreach $test (@TESTS) +{ + eval "print (($test) ? \"ok $testid\\n\" : \"not ok $testid\\n\" )"; + print "not ok $testid\n" if $@; + ++$testid; +} + +exit 0; |