diff options
author | Steffen Mueller <smueller@cpan.org> | 2010-04-21 12:18:49 +0200 |
---|---|---|
committer | Steffen Mueller <smueller@cpan.org> | 2010-04-21 12:20:47 +0200 |
commit | f768f60b565004f735138c26b9a0823b95e9f470 (patch) | |
tree | d77fb75823d5915b8e1dec8f1a84df48cd3c4761 /cpan/Locale-Codes/t | |
parent | b7e0327c3017c44f609566d81cb412798a1dad56 (diff) | |
download | perl-f768f60b565004f735138c26b9a0823b95e9f470.tar.gz |
Update Locale::Codes to 3.12
We're skipping inclusion of some files such as the unused Build.PL,
INSTALL, etc. cpan/Locale-Codes/internal/* should probably also not be
included in perl core.
Diffstat (limited to 'cpan/Locale-Codes/t')
-rwxr-xr-x | cpan/Locale-Codes/t/alias_code.t | 113 | ||||
-rw-r--r-- | cpan/Locale-Codes/t/all.t | 580 | ||||
-rwxr-xr-x | cpan/Locale-Codes/t/code2country.t | 144 | ||||
-rwxr-xr-x | cpan/Locale-Codes/t/code2currency.t | 125 | ||||
-rwxr-xr-x | cpan/Locale-Codes/t/code2language.t | 222 | ||||
-rwxr-xr-x | cpan/Locale-Codes/t/code2script.t | 57 | ||||
-rw-r--r-- | cpan/Locale-Codes/t/constants.t | 44 | ||||
-rwxr-xr-x[-rw-r--r--] | cpan/Locale-Codes/t/country.t | 390 | ||||
-rwxr-xr-x | cpan/Locale-Codes/t/country2code.t | 183 | ||||
-rwxr-xr-x | cpan/Locale-Codes/t/country_code2code.t | 78 | ||||
-rw-r--r-- | cpan/Locale-Codes/t/currency.t | 80 | ||||
-rwxr-xr-x | cpan/Locale-Codes/t/currency2code.t | 78 | ||||
-rwxr-xr-x[-rw-r--r--] | cpan/Locale-Codes/t/language.t | 197 | ||||
-rwxr-xr-x | cpan/Locale-Codes/t/language2code.t | 88 | ||||
-rw-r--r-- | cpan/Locale-Codes/t/rename.t | 79 | ||||
-rw-r--r-- | cpan/Locale-Codes/t/script.t | 106 | ||||
-rwxr-xr-x | cpan/Locale-Codes/t/script2code.t | 55 | ||||
-rw-r--r-- | cpan/Locale-Codes/t/testfunc.pl | 480 | ||||
-rw-r--r-- | cpan/Locale-Codes/t/uk.t | 65 |
19 files changed, 1958 insertions, 1206 deletions
diff --git a/cpan/Locale-Codes/t/alias_code.t b/cpan/Locale-Codes/t/alias_code.t new file mode 100755 index 0000000000..b763372100 --- /dev/null +++ b/cpan/Locale-Codes/t/alias_code.t @@ -0,0 +1,113 @@ +#!/usr/bin/perl -w + +require 5.002; + +$runtests=shift(@ARGV); +if ( -f "t/testfunc.pl" ) { + require "t/testfunc.pl"; + $dir="./lib"; + $tdir="t"; +} elsif ( -f "testfunc.pl" ) { + require "testfunc.pl"; + $dir="../lib"; + $tdir="."; +} else { + die "ERROR: cannot find testfunc.pl\n"; +} + +unshift(@INC,$dir); +use Locale::Country; + +%type = ( "LOCALE_CODE_ALPHA_2" => LOCALE_CODE_ALPHA_2, + "LOCALE_CODE_ALPHA_3" => LOCALE_CODE_ALPHA_3, + "LOCALE_CODE_NUMERIC" => LOCALE_CODE_NUMERIC, + ); + +sub test { + my(@test) = @_; + + if ($test[0] eq "alias_code") { + shift(@test); + $test[2] = $type{$test[2]} + if (@test == 3 && $test[2] && exists $type{$test[2]}); + return Locale::Country::alias_code(@test,"nowarn"); + + } elsif ($test[0] eq "country2code") { + shift(@test); + $test[1] = $type{$test[1]} if (@test == 2 && $test[1] && exists $type{$test[1]}); + return country2code(@test); + + } else { + $test[1] = $type{$test[1]} + if (@test == 2 && $test[1] && exists $type{$test[1]}); + return code2country(@test); + } +} + +$tests = " + +gb + ~ + United Kingdom + +uk + ~ + _undef_ + +country2code +United Kingdom + ~ + gb + +alias_code uk gb LOCALE_CODE_FOO ~ 0 + +alias_code uk x1 ~ 0 + +alias_code us gb ~ 0 + +alias_code uk gb LOCALE_CODE_ALPHA_3 ~ 0 + +gb + ~ + United Kingdom + +uk + ~ + _undef_ + +country2code +United Kingdom + ~ + gb + +alias_code uk gb ~ uk + +gb + ~ + United Kingdom + +uk + ~ + United Kingdom + +country2code +United Kingdom + ~ + uk + +"; + +print "alias_code...\n"; +test_Func(\&test,$tests,$runtests); + +1; +# Local Variables: +# mode: cperl +# indent-tabs-mode: nil +# cperl-indent-level: 3 +# cperl-continued-statement-offset: 2 +# cperl-continued-brace-offset: 0 +# cperl-brace-offset: 0 +# cperl-brace-imaginary-offset: 0 +# cperl-label-offset: -2 +# End: diff --git a/cpan/Locale-Codes/t/all.t b/cpan/Locale-Codes/t/all.t deleted file mode 100644 index f70727c1c5..0000000000 --- a/cpan/Locale-Codes/t/all.t +++ /dev/null @@ -1,580 +0,0 @@ -#!./perl -# -# all.t - tests for all_* routines in -# Locale::Country -# Locale::Language -# Locale::Currency -# Locale::Script -# -# 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. -# - -use Locale::Country; -use Locale::Language; -use Locale::Currency; -use Locale::Script; - -print "1..20\n"; - -my $code; -my $language; -my $country; -my $ok; -my $reverse; -my $currency; -my $script; - - -#----------------------------------------------------------------------- -# 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"); - -#======================================================================= -# -# Locale::Script tests -# -#======================================================================= - -#----------------------------------------------------------------------- -# Old API - without codeset specified, default to ALPHA_2 -#----------------------------------------------------------------------- -$ok = 1; -foreach $code (all_script_codes()) -{ - $script = code2script($code); - if (!defined $script) - { - $ok = 0; - last; - } - $reverse = script2code($script); - if (!defined $reverse) - { - $ok = 0; - last; - } - if ($reverse ne $code) - { - $ok = 0; - last; - } -} -print ($ok ? "ok 13\n" : "not ok 13\n"); - -#----------------------------------------------------------------------- -# code to script, back to code, for ALPHA2 -#----------------------------------------------------------------------- -$ok = 1; -foreach $code (all_script_codes(LOCALE_CODE_ALPHA_2)) -{ - $script = code2script($code, LOCALE_CODE_ALPHA_2); - if (!defined $script) - { - $ok = 0; - last; - } - $reverse = script2code($script, LOCALE_CODE_ALPHA_2); - if (!defined $reverse) - { - $ok = 0; - last; - } - if ($reverse ne $code) - { - $ok = 0; - last; - } -} -print ($ok ? "ok 14\n" : "not ok 14\n"); - -#----------------------------------------------------------------------- -# code to script, back to code, for ALPHA3 -#----------------------------------------------------------------------- -$ok = 1; -foreach $code (all_script_codes(LOCALE_CODE_ALPHA_3)) -{ - $script = code2script($code, LOCALE_CODE_ALPHA_3); - if (!defined $script) - { - $ok = 0; - last; - } - $reverse = script2code($script, LOCALE_CODE_ALPHA_3); - if (!defined $reverse) - { - $ok = 0; - last; - } - if ($reverse ne $code) - { - $ok = 0; - last; - } -} -print ($ok ? "ok 15\n" : "not ok 15\n"); - -#----------------------------------------------------------------------- -# code to script, back to code, for NUMERIC -#----------------------------------------------------------------------- -$ok = 1; -foreach $code (all_script_codes(LOCALE_CODE_NUMERIC)) -{ - $script = code2script($code, LOCALE_CODE_NUMERIC); - if (!defined $script) - { - $ok = 0; - last; - } - $reverse = script2code($script, LOCALE_CODE_NUMERIC); - if (!defined $reverse) - { - $ok = 0; - last; - } - if ($reverse ne $code) - { - $ok = 0; - last; - } -} -print ($ok ? "ok 16\n" : "not ok 16\n"); - - -#----------------------------------------------------------------------- -# Old API - script to code, back to script, using default of ALPHA_2 -#----------------------------------------------------------------------- -$ok = 1; -foreach $script (all_script_names()) -{ - $code = script2code($script); - if (!defined $code) - { - $ok = 0; - last; - } - $reverse = code2script($code); - if (!defined $reverse) - { - $ok = 0; - last; - } - if ($reverse ne $script) - { - $ok = 0; - last; - } -} -print ($ok ? "ok 17\n" : "not ok 17\n"); - -#----------------------------------------------------------------------- -# script to code, back to script, using LOCALE_CODE_ALPHA_2 -#----------------------------------------------------------------------- -$ok = 1; -foreach $script (all_script_names()) -{ - $code = script2code($script, LOCALE_CODE_ALPHA_2); - if (!defined $code) - { - $ok = 0; - last; - } - $reverse = code2script($code, LOCALE_CODE_ALPHA_2); - if (!defined $reverse) - { - $ok = 0; - last; - } - if ($reverse ne $script) - { - $ok = 0; - last; - } -} -print ($ok ? "ok 18\n" : "not ok 18\n"); - -#----------------------------------------------------------------------- -# script to code, back to script, using LOCALE_CODE_ALPHA_3 -#----------------------------------------------------------------------- -$ok = 1; -foreach $script (all_script_names()) -{ - $code = script2code($script, LOCALE_CODE_ALPHA_3); - if (!defined $code) - { - $ok = 0; - last; - } - $reverse = code2script($code, LOCALE_CODE_ALPHA_3); - if (!defined $reverse) - { - $ok = 0; - last; - } - if ($reverse ne $script) - { - $ok = 0; - last; - } -} -print ($ok ? "ok 19\n" : "not ok 19\n"); - -#----------------------------------------------------------------------- -# script to code, back to script, using LOCALE_CODE_NUMERIC -#----------------------------------------------------------------------- -$ok = 1; -foreach $script (all_script_names()) -{ - $code = script2code($script, LOCALE_CODE_NUMERIC); - if (!defined $code) - { - $ok = 0; - last; - } - $reverse = code2script($code, LOCALE_CODE_NUMERIC); - if (!defined $reverse) - { - $ok = 0; - last; - } - if ($reverse ne $script) - { - $ok = 0; - last; - } -} -print ($ok ? "ok 20\n" : "not ok 20\n"); - diff --git a/cpan/Locale-Codes/t/code2country.t b/cpan/Locale-Codes/t/code2country.t new file mode 100755 index 0000000000..43c06a03a5 --- /dev/null +++ b/cpan/Locale-Codes/t/code2country.t @@ -0,0 +1,144 @@ +#!/usr/bin/perl -w + +require 5.002; + +$runtests=shift(@ARGV); +if ( -f "t/testfunc.pl" ) { + require "t/testfunc.pl"; + $dir="./lib"; + $tdir="t"; +} elsif ( -f "testfunc.pl" ) { + require "testfunc.pl"; + $dir="../lib"; + $tdir="."; +} else { + die "ERROR: cannot find testfunc.pl\n"; +} + +unshift(@INC,$dir); +use Locale::Country; + +%type = ( "LOCALE_CODE_ALPHA_2" => LOCALE_CODE_ALPHA_2, + "LOCALE_CODE_ALPHA_3" => LOCALE_CODE_ALPHA_3, + "LOCALE_CODE_NUMERIC" => LOCALE_CODE_NUMERIC, + ); + +sub test { + my(@test) = @_; + $test[1] = $type{$test[1]} if (@test == 2 && $test[1] && exists $type{$test[1]}); + return code2country(@test); +} + +$tests = " + +~ _undef_ + +_undef_ ~ _undef_ + +zz ~ _undef_ + +zz LOCALE_CODE_ALPHA_2 ~ _undef_ + +zz LOCALE_CODE_ALPHA_3 ~ _undef_ + +zz LOCALE_CODE_NUMERIC ~ _undef_ + +ja ~ _undef_ + +uk ~ _undef_ + +BO + ~ + Bolivia, Plurinational State of + +BO +LOCALE_CODE_ALPHA_2 + ~ + Bolivia, Plurinational State of + +bol +LOCALE_CODE_ALPHA_3 + ~ + Bolivia (Plurinational State of) + +pk ~ Pakistan + +sn ~ Senegal + +us + ~ + United States + +ad ~ Andorra + +ad LOCALE_CODE_ALPHA_2 ~ Andorra + +and LOCALE_CODE_ALPHA_3 ~ Andorra + +020 LOCALE_CODE_NUMERIC ~ Andorra + +48 LOCALE_CODE_NUMERIC ~ Bahrain + +zw ~ Zimbabwe + +gb + ~ + United Kingdom + +kz ~ Kazakhstan + +mo ~ Macao + +tl LOCALE_CODE_ALPHA_2 ~ Timor-Leste + +tls LOCALE_CODE_ALPHA_3 ~ Timor-Leste + +626 LOCALE_CODE_NUMERIC ~ Timor-Leste + +BO LOCALE_CODE_ALPHA_3 ~ _undef_ + +BO LOCALE_CODE_NUMERIC ~ _undef_ + +ax + ~ + Aland Islands + +ala +LOCALE_CODE_ALPHA_3 + ~ + Aland Islands + +248 +LOCALE_CODE_NUMERIC + ~ + Aland Islands + +scg +LOCALE_CODE_ALPHA_3 + ~ + _undef_ + +891 +LOCALE_CODE_NUMERIC + ~ + _undef_ + +rou LOCALE_CODE_ALPHA_3 ~ Romania + +"; + +print "code2country...\n"; +test_Func(\&test,$tests,$runtests); + +1; +# Local Variables: +# mode: cperl +# indent-tabs-mode: nil +# cperl-indent-level: 3 +# cperl-continued-statement-offset: 2 +# cperl-continued-brace-offset: 0 +# cperl-brace-offset: 0 +# cperl-brace-imaginary-offset: 0 +# cperl-label-offset: -2 +# End: + diff --git a/cpan/Locale-Codes/t/code2currency.t b/cpan/Locale-Codes/t/code2currency.t new file mode 100755 index 0000000000..6b32b311e7 --- /dev/null +++ b/cpan/Locale-Codes/t/code2currency.t @@ -0,0 +1,125 @@ +#!/usr/bin/perl -w + +require 5.002; + +$runtests=shift(@ARGV); +if ( -f "t/testfunc.pl" ) { + require "t/testfunc.pl"; + $dir="./lib"; + $tdir="t"; +} elsif ( -f "testfunc.pl" ) { + require "testfunc.pl"; + $dir="../lib"; + $tdir="."; +} else { + die "ERROR: cannot find testfunc.pl\n"; +} + +unshift(@INC,$dir); +use Locale::Currency; + +%type = ( "LOCALE_CODE_ALPHA" => LOCALE_CODE_ALPHA, + "LOCALE_CODE_NUMERIC" => LOCALE_CODE_NUMERIC, + ); + +sub test { + my(@test) = @_; + $test[1] = $type{$test[1]} + if (@test == 2 && $test[1] && exists $type{$test[1]}); + return code2currency(@test); +} + +$tests = " + +ukp ~ _undef_ + +zz ~ _undef_ + +zzz ~ _undef_ + +zzzz ~ _undef_ + +~ _undef_ + +_undef_ ~ _undef_ + +BOB + ~ + Boliviano + +all + ~ + Lek + +bnd + ~ + Brunei Dollar + +bob + ~ + Boliviano + +byr + ~ + Belarussian Ruble + +chf + ~ + Swiss Franc + +cop + ~ + Colombian Peso + +dkk + ~ + Danish Krone + +fjd + ~ + Fiji Dollar + +idr + ~ + Rupiah + +mmk + ~ + Kyat + +mvr + ~ + Rufiyaa + +mwk + ~ + Kwacha + +rub + ~ + Russian Ruble + +zmk + ~ + Zambian Kwacha + +zwl + ~ + Zimbabwe Dollar + +"; + +print "code2currency...\n"; +test_Func(\&test,$tests,$runtests); + +1; +# Local Variables: +# mode: cperl +# indent-tabs-mode: nil +# cperl-indent-level: 3 +# cperl-continued-statement-offset: 2 +# cperl-continued-brace-offset: 0 +# cperl-brace-offset: 0 +# cperl-brace-imaginary-offset: 0 +# cperl-label-offset: -2 +# End: diff --git a/cpan/Locale-Codes/t/code2language.t b/cpan/Locale-Codes/t/code2language.t new file mode 100755 index 0000000000..a0308d4e5b --- /dev/null +++ b/cpan/Locale-Codes/t/code2language.t @@ -0,0 +1,222 @@ +#!/usr/bin/perl -w + +require 5.002; + +$runtests=shift(@ARGV); +if ( -f "t/testfunc.pl" ) { + require "t/testfunc.pl"; + $dir="./lib"; + $tdir="t"; +} elsif ( -f "testfunc.pl" ) { + require "testfunc.pl"; + $dir="../lib"; + $tdir="."; +} else { + die "ERROR: cannot find testfunc.pl\n"; +} + +unshift(@INC,$dir); +use Locale::Language; + +%type = ( "LOCALE_CODE_ALPHA_2" => LOCALE_CODE_ALPHA_2, + "LOCALE_CODE_ALPHA_3" => LOCALE_CODE_ALPHA_3, + "LOCALE_CODE_TERM" => LOCALE_CODE_TERM, + ); + +sub test { + my(@test) = @_; + $test[1] = $type{$test[1]} + if (@test == 2 && $test[1] && exists $type{$test[1]}); + return code2language(@test); +} + +$tests = " + +in ~ _undef_ + +iw ~ _undef_ + +ji ~ _undef_ + +jp ~ _undef_ + +sh ~ _undef_ + +zz ~ _undef_ + +~ _undef_ + +_undef_ ~ _undef_ + +DA + ~ + Danish + +aa + ~ + Afar + +ae + ~ + Avestan + +bs + ~ + Bosnian + +ce + ~ + Chechen + +ch + ~ + Chamorro + +cu + ~ + Church Slavic + +cv + ~ + Chuvash + +en + ~ + English + +eo + ~ + Esperanto + +fi + ~ + Finnish + +gv + ~ + Manx + +he + ~ + Hebrew + +ho + ~ + Hiri Motu + +hz + ~ + Herero + +id + ~ + Indonesian + +iu + ~ + Inuktitut + +ki + ~ + Kikuyu + +kj + ~ + Kuanyama + +kv + ~ + Komi + +kw + ~ + Cornish + +lb + ~ + Luxembourgish + +mh + ~ + Marshallese + +nb + ~ + Bokmal, Norwegian + +nd + ~ + Ndebele, North + +ng + ~ + Ndonga + +nn + ~ + Norwegian Nynorsk + +nr + ~ + Ndebele, South + +nv + ~ + Navajo + +ny + ~ + Chichewa + +oc + ~ + Occitan (post 1500) + +os + ~ + Ossetian + +pi + ~ + Pali + +sc + ~ + Sardinian + +se + ~ + Northern Sami + +ug + ~ + Uighur + +yi + ~ + Yiddish + +za + ~ + Zhuang + +zu + ~ + Zulu + +"; + +print "code2language...\n"; +test_Func(\&test,$tests,$runtests); + +1; +# Local Variables: +# mode: cperl +# indent-tabs-mode: nil +# cperl-indent-level: 3 +# cperl-continued-statement-offset: 2 +# cperl-continued-brace-offset: 0 +# cperl-brace-offset: 0 +# cperl-brace-imaginary-offset: 0 +# cperl-label-offset: -2 +# End: diff --git a/cpan/Locale-Codes/t/code2script.t b/cpan/Locale-Codes/t/code2script.t new file mode 100755 index 0000000000..ba700f956f --- /dev/null +++ b/cpan/Locale-Codes/t/code2script.t @@ -0,0 +1,57 @@ +#!/usr/bin/perl -w + +require 5.002; + +$runtests=shift(@ARGV); +if ( -f "t/testfunc.pl" ) { + require "t/testfunc.pl"; + $dir="./lib"; + $tdir="t"; +} elsif ( -f "testfunc.pl" ) { + require "testfunc.pl"; + $dir="../lib"; + $tdir="."; +} else { + die "ERROR: cannot find testfunc.pl\n"; +} + +unshift(@INC,$dir); +use Locale::Script; + +%type = ( "LOCALE_SCRIPT_ALPHA" => LOCALE_SCRIPT_ALPHA, + "LOCALE_SCRIPT_NUMERIC" => LOCALE_SCRIPT_NUMERIC, + ); + +sub test { + my(@test) = @_; + $test[1] = $type{$test[1]} + if (@test == 2 && $test[1] && exists $type{$test[1]}); + return code2script(@test); +} + +$tests = " + +~ _undef_ + +Phnx ~ Phoenician + +phnx ~ Phoenician + +115 LOCALE_SCRIPT_NUMERIC ~ Phoenician + +"; + +print "code2script...\n"; +test_Func(\&test,$tests,$runtests); + +1; +# Local Variables: +# mode: cperl +# indent-tabs-mode: nil +# cperl-indent-level: 3 +# cperl-continued-statement-offset: 2 +# cperl-continued-brace-offset: 0 +# cperl-brace-offset: 0 +# cperl-brace-imaginary-offset: 0 +# cperl-label-offset: -2 +# End: diff --git a/cpan/Locale-Codes/t/constants.t b/cpan/Locale-Codes/t/constants.t deleted file mode 100644 index e71103d0f0..0000000000 --- a/cpan/Locale-Codes/t/constants.t +++ /dev/null @@ -1,44 +0,0 @@ -#!./perl -# -# constants.t - tests for Locale::Constants -# - -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/cpan/Locale-Codes/t/country.t b/cpan/Locale-Codes/t/country.t index 0c9fda83f7..830fa55392 100644..100755 --- a/cpan/Locale-Codes/t/country.t +++ b/cpan/Locale-Codes/t/country.t @@ -1,153 +1,247 @@ -#!./perl -# -# country.t - tests for Locale::Country -# +#!/usr/bin/perl -w + +require 5.002; + +$runtests=shift(@ARGV); +if ( -f "t/testfunc.pl" ) { + require "t/testfunc.pl"; + $dir="./lib"; + $tdir="t"; +} elsif ( -f "testfunc.pl" ) { + require "testfunc.pl"; + $dir="../lib"; + $tdir="."; +} else { + die "ERROR: cannot find testfunc.pl\n"; +} +unshift(@INC,$dir); 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 added after changes in the standard 2002-05-20 ------ - ['code2country("kz") eq "Kazakhstan"', 0], - ['country2code("kazakhstan") eq "kz"', 0], - ['country2code("kazakstan") eq "kz"', 0], - - ['code2country("mo") eq "Macao"', 0], - ['country2code("macao") eq "mo"', 0], - ['country2code("macau") eq "mo"', 0], - - ['code2country("tl", LOCALE_CODE_ALPHA_2) eq "Timor-Leste"', 0], - ['code2country("tls", LOCALE_CODE_ALPHA_3) eq "Timor-Leste"', 0], - ['code2country("626", LOCALE_CODE_NUMERIC) eq "Timor-Leste"', 0], - - #================================================ - # 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 - ['country2code("Zimbabwe") eq "zw"', 0], # last in DATA - ['country2code("Iran") eq "ir"', 0], # alias - ['country2code("North Korea") eq "kp"', 0], # alias - ['country2code("South Korea") eq "kr"', 0], # alias - ['country2code("Libya") eq "ly"', 0], # alias - ['country2code("Syria") eq "sy"', 0], # alias - ['country2code("Svalbard") eq "sj"', 0], # alias - ['country2code("Jan Mayen") eq "sj"', 0], # alias - ['country2code("USA") eq "us"', 0], # alias - ['country2code("United States of America") eq "us"', 0], # alias - ['country2code("Great Britain") eq "gb"', 0], # alias - - #================================================ - # 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], - - #-- tests added for 2.07 release - ['country2code("Burma") eq "mm"', 0], # alias - ['country2code("French Southern and Antarctic Lands") eq "tf"', 0], # alias - ['code2country("ax") eq "Aland Islands"', 0], - ['country2code("Aland Islands") eq "ax"', 0], - ['code2country("ala", LOCALE_CODE_ALPHA_3) eq "Aland Islands"', 0], - ['code2country("248", LOCALE_CODE_NUMERIC) eq "Aland Islands"', 0], - - ['country2code("Yugoslavia") eq "cs"', 0], # alias (old name) - ['country2code("Serbia and Montenegro") eq "cs"', 0], # new name - ['code2country("scg", LOCALE_CODE_ALPHA_3) eq "Serbia and Montenegro"', 0], - ['code2country("891", LOCALE_CODE_NUMERIC) eq "Serbia and Montenegro"', 0], - - ['country2code("East Timor") eq "tl"', 0], # alias (provisional name) - ['code2country("rou", LOCALE_CODE_ALPHA_3) eq "Romania"', 0], - - ['country2code("Zaire") eq "cd"', 0], # alias (old name) - ['country2code("Congo, The Democratic Republic of the") eq "cd"', 0], # new name - ['country2code("Congo, The Democratic Republic of the", LOCALE_CODE_ALPHA_3) eq "cod"', 0], # new name - ['country2code("Congo, The Democratic Republic of the", LOCALE_CODE_NUMERIC) eq "180"', 0], # new name - -); - -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; +%type = ( "LOCALE_CODE_ALPHA_2" => LOCALE_CODE_ALPHA_2, + "LOCALE_CODE_ALPHA_3" => LOCALE_CODE_ALPHA_3, + "LOCALE_CODE_NUMERIC" => LOCALE_CODE_NUMERIC, + "LOCALE_CODE_FIPS" => LOCALE_CODE_FIPS, + ); + +sub test { + my(@test) = @_; + + if ($test[0] eq "rename_country") { + shift(@test); + $test[2] = $type{$test[2]} + if (@test == 3 && $test[2] && exists $type{$test[2]}); + return Locale::Country::rename_country(@test,"nowarn"); + + } elsif ($test[0] eq "add_country") { + shift(@test); + $test[2] = $type{$test[2]} + if (@test == 3 && $test[2] && exists $type{$test[2]}); + return Locale::Country::add_country(@test,"nowarn"); + + } elsif ($test[0] eq "delete_country") { + shift(@test); + $test[1] = $type{$test[1]} + if (@test == 2 && $test[1] && exists $type{$test[1]}); + return Locale::Country::delete_country(@test,"nowarn"); + + } elsif ($test[0] eq "add_country_alias") { + shift(@test); + return Locale::Country::add_country_alias(@test,"nowarn"); + + } elsif ($test[0] eq "delete_country_alias") { + shift(@test); + return Locale::Country::delete_country_alias(@test,"nowarn"); + + } elsif ($test[0] eq "rename_country_code") { + shift(@test); + $test[2] = $type{$test[2]} + if (@test == 3 && $test[2] && exists $type{$test[2]}); + return Locale::Country::rename_country_code(@test,"nowarn"); + + } elsif ($test[0] eq "add_country_code_alias") { + shift(@test); + $test[2] = $type{$test[2]} + if (@test == 3 && $test[2] && exists $type{$test[2]}); + return Locale::Country::add_country_code_alias(@test,"nowarn"); + + } elsif ($test[0] eq "delete_country_code_alias") { + shift(@test); + $test[1] = $type{$test[1]} + if (@test == 2 && $test[1] && exists $type{$test[1]}); + return Locale::Country::delete_country_code_alias(@test,"nowarn"); + + } elsif ($test[0] eq "country2code") { + shift(@test); + $test[1] = $type{$test[1]} + if (@test == 2 && $test[1] && exists $type{$test[1]}); + return country2code(@test); + + } else { + shift(@test) if ($test[0] eq "code2country"); + $test[1] = $type{$test[1]} + if (@test == 2 && $test[1] && exists $type{$test[1]}); + return code2country(@test); + } } -exit 0; +$tests = " + +################################### +# Test rename_country + +gb + ~ + United Kingdom + +rename_country x1 NewName ~ 0 + +rename_country gb NewName LOCALE_CODE_FOO ~ 0 + +rename_country gb Macao ~ 0 + +rename_country gb NewName LOCALE_CODE_ALPHA_3 ~ 0 + +gb + ~ + United Kingdom + +rename_country gb NewName ~ 1 + +gb + ~ + NewName + +################################### +# Test add_country + +xx ~ _undef_ + +add_country xx Bolivia ~ 0 + +add_country fi Xxxxx ~ 0 + +add_country xx Xxxxx ~ 1 + +xx ~ Xxxxx + +################################### +# Test add_country_alias + +add_country_alias FooBar NewName ~ 0 + +add_country_alias Australia Angola ~ 0 + +country2code Australia ~ au + +country2code DownUnder ~ _undef_ + +add_country_alias Australia DownUnder ~ 1 + +country2code DownUnder ~ au + +################################### +# Test delete_country_alias + +country2code uk ~ gb + +delete_country_alias Foobar ~ 0 + +delete_country_alias UK ~ 1 + +country2code uk ~ _undef_ + +delete_country_alias Angola ~ 0 + +################################### +# Test delete_country + +country2code Angola ~ ao + +country2code Angola LOCALE_CODE_ALPHA_3 ~ ago + +delete_country ao ~ 1 + +country2code Angola ~ _undef_ + +country2code Angola LOCALE_CODE_ALPHA_3 ~ ago + +################################### +# Test rename_country_code + +code2country zz ~ _undef_ + +code2country ar ~ Argentina + +country2code Argentina ~ ar + +rename_country_code ar us ~ 0 + +rename_country_code ar zz ~ 1 + +rename_country_code us ar ~ 0 + +code2country zz ~ Argentina + +code2country ar ~ Argentina + +country2code Argentina ~ zz + +rename_country_code zz ar ~ 1 + +code2country zz ~ Argentina + +code2country ar ~ Argentina + +country2code Argentina ~ ar + +################################### +# Test add_country_code_alias and +# delete_country_code_alias + +code2country bm ~ Bermuda + +code2country yy ~ _undef_ + +country2code Bermuda ~ bm + +add_country_code_alias bm us ~ 0 + +add_country_code_alias bm zz ~ 0 + +add_country_code_alias bm yy ~ 1 + +code2country bm ~ Bermuda + +code2country yy ~ Bermuda + +country2code Bermuda ~ bm + +delete_country_code_alias us ~ 0 + +delete_country_code_alias ww ~ 0 + +delete_country_code_alias yy ~ 1 + +code2country bm ~ Bermuda + +code2country yy ~ _undef_ + +country2code Bermuda ~ bm + +"; + +print "country (semi-private)...\n"; +test_Func(\&test,$tests,$runtests); + +1; +# Local Variables: +# mode: cperl +# indent-tabs-mode: nil +# cperl-indent-level: 3 +# cperl-continued-statement-offset: 2 +# cperl-continued-brace-offset: 0 +# cperl-brace-offset: 0 +# cperl-brace-imaginary-offset: 0 +# cperl-label-offset: -2 +# End: diff --git a/cpan/Locale-Codes/t/country2code.t b/cpan/Locale-Codes/t/country2code.t new file mode 100755 index 0000000000..1eacf466ee --- /dev/null +++ b/cpan/Locale-Codes/t/country2code.t @@ -0,0 +1,183 @@ +#!/usr/bin/perl -w + +require 5.002; + +$runtests=shift(@ARGV); +if ( -f "t/testfunc.pl" ) { + require "t/testfunc.pl"; + $dir="./lib"; + $tdir="t"; +} elsif ( -f "testfunc.pl" ) { + require "testfunc.pl"; + $dir="../lib"; + $tdir="."; +} else { + die "ERROR: cannot find testfunc.pl\n"; +} + +unshift(@INC,$dir); +use Locale::Country; + +%type = ( "LOCALE_CODE_ALPHA_2" => LOCALE_CODE_ALPHA_2, + "LOCALE_CODE_ALPHA_3" => LOCALE_CODE_ALPHA_3, + "LOCALE_CODE_NUMERIC" => LOCALE_CODE_NUMERIC, + ); + +sub test { + my(@test) = @_; + $test[1] = $type{$test[1]} if (@test == 2 && $test[1] && exists $type{$test[1]}); + return country2code(@test); +} + +$tests = " + +kazakhstan + ~ + kz + +kazakstan + ~ + kz + +macao + ~ + mo + +macau + ~ + mo + + +~ _undef_ + +_undef_ + ~ + _undef_ + +Banana + ~ + _undef_ + +japan + ~ + jp + +Japan + ~ + jp + +United States + ~ + us + +United Kingdom + ~ + gb + +Andorra + ~ + ad + +Zimbabwe + ~ + zw + +Iran + ~ + ir + +North Korea + ~ + kp + +South Korea + ~ + kr + +Libya + ~ + ly + +Syria + ~ + sy + +Svalbard + ~ + _undef_ + +Jan Mayen + ~ + _undef_ + +USA + ~ + us + +United States of America + ~ + us + +Great Britain + ~ + gb + +Burma + ~ + mm + +French Southern and Antarctic Lands + ~ + tf + +Aland Islands + ~ + ax + +Yugoslavia + ~ + _undef_ + +Serbia and Montenegro + ~ + _undef_ + +East Timor + ~ + tl + +Zaire + ~ + _undef_ + +Congo, The Democratic Republic of the + ~ + cd + +Congo, The Democratic Republic of the +LOCALE_CODE_ALPHA_3 + ~ + cod + +Congo, The Democratic Republic of the +LOCALE_CODE_NUMERIC + ~ + 180 + +"; + +print "country2code...\n"; +test_Func(\&test,$tests,$runtests); + +1; +# Local Variables: +# mode: cperl +# indent-tabs-mode: nil +# cperl-indent-level: 3 +# cperl-continued-statement-offset: 2 +# cperl-continued-brace-offset: 0 +# cperl-brace-offset: 0 +# cperl-brace-imaginary-offset: 0 +# cperl-label-offset: -2 +# End: + diff --git a/cpan/Locale-Codes/t/country_code2code.t b/cpan/Locale-Codes/t/country_code2code.t new file mode 100755 index 0000000000..5ec8117fe4 --- /dev/null +++ b/cpan/Locale-Codes/t/country_code2code.t @@ -0,0 +1,78 @@ +#!/usr/bin/perl -w + +require 5.002; + +$runtests=shift(@ARGV); +if ( -f "t/testfunc.pl" ) { + require "t/testfunc.pl"; + $dir="./lib"; + $tdir="t"; +} elsif ( -f "testfunc.pl" ) { + require "testfunc.pl"; + $dir="../lib"; + $tdir="."; +} else { + die "ERROR: cannot find testfunc.pl\n"; +} + +unshift(@INC,$dir); +use Locale::Country; +use Locale::Constants; + +%type = ( "LOCALE_CODE_ALPHA_2" => LOCALE_CODE_ALPHA_2, + "LOCALE_CODE_ALPHA_3" => LOCALE_CODE_ALPHA_3, + "LOCALE_CODE_NUMERIC" => LOCALE_CODE_NUMERIC, + ); + +sub test { + my($code,$type_in,$type_out) = @_; + $type_in = $type{$type_in} if ($type_in && exists $type{$type_in}); + $type_out = $type{$type_out} if ($type_out && exists $type{$type_out}); + + return country_code2code($code,$type_in,$type_out); +} + +$tests = " + +bo LOCALE_CODE_ALPHA_2 LOCALE_CODE_ALPHA_2 ~ bo + +bo LOCALE_CODE_ALPHA_3 LOCALE_CODE_ALPHA_3 ~ _undef_ + +zz LOCALE_CODE_ALPHA_2 LOCALE_CODE_ALPHA_3 ~ _undef_ + +zz LOCALE_CODE_ALPHA_3 LOCALE_CODE_ALPHA_3 ~ _undef_ + +zz LOCALE_CODE_ALPHA_2 0 ~ _undef_ + +bo LOCALE_CODE_ALPHA_2 0 ~ _undef_ + +_blank_ 0 0 ~ _undef_ + +BO LOCALE_CODE_ALPHA_2 LOCALE_CODE_ALPHA_3 ~ bol + +bol LOCALE_CODE_ALPHA_3 LOCALE_CODE_ALPHA_2 ~ bo + +zwe LOCALE_CODE_ALPHA_3 LOCALE_CODE_ALPHA_2 ~ zw + +858 LOCALE_CODE_NUMERIC LOCALE_CODE_ALPHA_3 ~ ury + +858 LOCALE_CODE_NUMERIC LOCALE_CODE_ALPHA_3 ~ ury + +tr LOCALE_CODE_ALPHA_2 LOCALE_CODE_NUMERIC ~ 792 + +"; + +print "country_code2code...\n"; +test_Func(\&test,$tests,$runtests); + +1; +# Local Variables: +# mode: cperl +# indent-tabs-mode: nil +# cperl-indent-level: 3 +# cperl-continued-statement-offset: 2 +# cperl-continued-brace-offset: 0 +# cperl-brace-offset: 0 +# cperl-brace-imaginary-offset: 0 +# cperl-label-offset: -2 +# End: diff --git a/cpan/Locale-Codes/t/currency.t b/cpan/Locale-Codes/t/currency.t deleted file mode 100644 index adb844e4d4..0000000000 --- a/cpan/Locale-Codes/t/currency.t +++ /dev/null @@ -1,80 +0,0 @@ -#!./perl -# -# currency.t - tests for Locale::Currency -# -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 - 'currency2code("Canadian Dollar") eq "cad"', # 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/cpan/Locale-Codes/t/currency2code.t b/cpan/Locale-Codes/t/currency2code.t new file mode 100755 index 0000000000..6df23cd7c3 --- /dev/null +++ b/cpan/Locale-Codes/t/currency2code.t @@ -0,0 +1,78 @@ +#!/usr/bin/perl -w + +require 5.002; + +$runtests=shift(@ARGV); +if ( -f "t/testfunc.pl" ) { + require "t/testfunc.pl"; + $dir="./lib"; + $tdir="t"; +} elsif ( -f "testfunc.pl" ) { + require "testfunc.pl"; + $dir="../lib"; + $tdir="."; +} else { + die "ERROR: cannot find testfunc.pl\n"; +} + +unshift(@INC,$dir); +use Locale::Currency; + +%type = ( "LOCALE_CODE_ALPHA" => LOCALE_CODE_ALPHA, + "LOCALE_CODE_NUMERIC" => LOCALE_CODE_NUMERIC, + ); + +sub test { + my(@test) = @_; + $test[1] = $type{$test[1]} + if (@test == 2 && $test[1] && exists $type{$test[1]}); + return currency2code(@test); +} + +$tests = " + +_blank_ ~ _undef_ + +Banana ~ _undef_ + +~ _undef_ + +_undef_ ~ _undef_ + + +Canadian Dollar + ~ + CAD + +Kroon + ~ + EEK + +PULA + ~ + BWP + +Riel + ~ + KHR + +Zimbabwe Dollar + ~ + ZWL + +"; + +print "currency2code...\n"; +test_Func(\&test,$tests,$runtests); + +1; +# Local Variables: +# mode: cperl +# indent-tabs-mode: nil +# cperl-indent-level: 3 +# cperl-continued-statement-offset: 2 +# cperl-continued-brace-offset: 0 +# cperl-brace-offset: 0 +# cperl-brace-imaginary-offset: 0 +# cperl-label-offset: -2 +# End: diff --git a/cpan/Locale-Codes/t/language.t b/cpan/Locale-Codes/t/language.t index 88edcee816..14364e7245 100644..100755 --- a/cpan/Locale-Codes/t/language.t +++ b/cpan/Locale-Codes/t/language.t @@ -1,110 +1,99 @@ -#!./perl -# -# language.t - tests for Locale::Language -# - -BEGIN { - chdir 't' if -d 't'; - #@INC = '../lib'; +#!/usr/bin/perl -w + +require 5.002; + +$runtests=shift(@ARGV); +if ( -f "t/testfunc.pl" ) { + require "t/testfunc.pl"; + $dir="./lib"; + $tdir="t"; +} elsif ( -f "testfunc.pl" ) { + require "testfunc.pl"; + $dir="../lib"; + $tdir="."; +} else { + die "ERROR: cannot find testfunc.pl\n"; } +unshift(@INC,$dir); use Locale::Language; -no utf8; # we contain Latin-1 - -#----------------------------------------------------------------------- -# 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 Bokmal"', - '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; +%type = ( "LOCALE_LANG_ALPHA_2" => LOCALE_LANG_ALPHA_2, + "LOCALE_LANG_ALPHA_3" => LOCALE_LANG_ALPHA_3, + "LOCALE_LANG_TERM" => LOCALE_LANG_TERM, + ); + +sub test { + my(@test) = @_; + + if ($test[0] eq "rename_language") { + shift(@test); + $test[2] = $type{$test[2]} + if (@test == 3 && $test[2] && exists $type{$test[2]}); + return Locale::Language::rename_language(@test,"nowarn"); + + } elsif ($test[0] eq "add_language") { + shift(@test); + $test[2] = $type{$test[2]} + if (@test == 3 && $test[2] && exists $type{$test[2]}); + return Locale::Language::add_language(@test,"nowarn"); + + } elsif ($test[0] eq "delete_language") { + shift(@test); + $test[1] = $type{$test[1]} + if (@test == 2 && $test[1] && exists $type{$test[1]}); + return Locale::Language::delete_language(@test,"nowarn"); + + } elsif ($test[0] eq "add_language_alias") { + shift(@test); + return Locale::Language::add_language_alias(@test,"nowarn"); + + } elsif ($test[0] eq "delete_language_alias") { + shift(@test); + return Locale::Language::delete_language_alias(@test,"nowarn"); + + } elsif ($test[0] eq "language2code") { + shift(@test); + $test[1] = $type{$test[1]} + if (@test == 2 && $test[1] && exists $type{$test[1]}); + return language2code(@test); + + } else { + $test[1] = $type{$test[1]} + if (@test == 2 && $test[1] && exists $type{$test[1]}); + return code2language(@test); + } } -exit 0; +$tests = " + +zu ~ Zulu + +rename_language zu NewName LOCALE_LANG_FOO ~ 0 + +rename_language zu English LOCALE_LANG_ALPHA_2 ~ 0 + +rename_language zu NewName LOCALE_LANG_ALPHA_3 ~ 0 + +zu ~ Zulu + +rename_language zu NewName LOCALE_LANG_ALPHA_2 ~ 1 + +zu ~ NewName + +"; + +print "language (semi-private)...\n"; +test_Func(\&test,$tests,$runtests); + +1; +# Local Variables: +# mode: cperl +# indent-tabs-mode: nil +# cperl-indent-level: 3 +# cperl-continued-statement-offset: 2 +# cperl-continued-brace-offset: 0 +# cperl-brace-offset: 0 +# cperl-brace-imaginary-offset: 0 +# cperl-label-offset: -2 +# End: diff --git a/cpan/Locale-Codes/t/language2code.t b/cpan/Locale-Codes/t/language2code.t new file mode 100755 index 0000000000..2e5bb23dc1 --- /dev/null +++ b/cpan/Locale-Codes/t/language2code.t @@ -0,0 +1,88 @@ +#!/usr/bin/perl -w + +require 5.002; + +$runtests=shift(@ARGV); +if ( -f "t/testfunc.pl" ) { + require "t/testfunc.pl"; + $dir="./lib"; + $tdir="t"; +} elsif ( -f "testfunc.pl" ) { + require "testfunc.pl"; + $dir="../lib"; + $tdir="."; +} else { + die "ERROR: cannot find testfunc.pl\n"; +} + +unshift(@INC,$dir); +use Locale::Language; + +%type = ( "LOCALE_CODE_ALPHA_2" => LOCALE_CODE_ALPHA_2, + "LOCALE_CODE_ALPHA_3" => LOCALE_CODE_ALPHA_3, + "LOCALE_CODE_TERM" => LOCALE_CODE_TERM, + ); + +sub test { + my(@test) = @_; + $test[1] = $type{$test[1]} + if (@test == 2 && $test[1] && exists $type{$test[1]}); + return language2code(@test); +} + +$tests = " + +Banana ~ _undef_ + +~ _undef_ + +_undef_ ~ _undef_ + +Afar + ~ + aa + +ESTONIAN + ~ + et + +French + ~ + fr + +Greek + ~ + el + +Japanese + ~ + ja + +Zulu + ~ + zu + +english + ~ + en + +japanese + ~ + ja + +"; + +print "language2code...\n"; +test_Func(\&test,$tests,$runtests); + +1; +# Local Variables: +# mode: cperl +# indent-tabs-mode: nil +# cperl-indent-level: 3 +# cperl-continued-statement-offset: 2 +# cperl-continued-brace-offset: 0 +# cperl-brace-offset: 0 +# cperl-brace-imaginary-offset: 0 +# cperl-label-offset: -2 +# End: diff --git a/cpan/Locale-Codes/t/rename.t b/cpan/Locale-Codes/t/rename.t deleted file mode 100644 index 27f506c84b..0000000000 --- a/cpan/Locale-Codes/t/rename.t +++ /dev/null @@ -1,79 +0,0 @@ -#!./perl -# -# rename.t - tests for Locale::Country with "uk" aliases to "gb" -# - -use Locale::Country; - -local $SIG{__WARN__} = sub { }; # muffle warnings from carp - -Locale::Country::rename_country('gb' => 'Great Britain'); - -#----------------------------------------------------------------------- -# 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 - '!defined code2country("uk")', # code for United Kingdom is 'gb' - - #---- this call should return 0, since code doesn't exist -------------- - '!Locale::Country::rename_country("ukz", "United Karz")', - - #---- 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("gb") eq "Great Britain"', # normally "United Kingdom" - - #================================================ - # 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("Great Britain") eq "gb"', - 'country2code("Great Britain", LOCALE_CODE_ALPHA_3) eq "gbr"', - 'country2code("Great Britain", LOCALE_CODE_NUMERIC) eq "826"', - - 'country2code("United Kingdom") eq "gb"', - 'country2code("United Kingdom", LOCALE_CODE_ALPHA_3) eq "gbr"', - 'country2code("United Kingdom", LOCALE_CODE_NUMERIC) eq "826"', - - '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; diff --git a/cpan/Locale-Codes/t/script.t b/cpan/Locale-Codes/t/script.t deleted file mode 100644 index 989b778f82..0000000000 --- a/cpan/Locale-Codes/t/script.t +++ /dev/null @@ -1,106 +0,0 @@ -#!./perl -# -# script.t - tests for Locale::Script -# - -use Locale::Script; - -#----------------------------------------------------------------------- -# 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 code2script - #================================================ - - #---- selection of examples which should all result in undef ----------- - ['!defined code2script()', 0], # no argument - ['!defined code2script(undef)', 0], # undef argument - ['!defined code2script("aa")', 0], # illegal code - ['!defined code2script("aa", LOCALE_CODE_ALPHA_2)', 0], # illegal code - ['!defined code2script("aa", LOCALE_CODE_ALPHA_3)', 0], # illegal code - ['!defined code2script("aa", LOCALE_CODE_NUMERIC)', 0], # illegal code - - #---- some successful examples ----------------------------------------- - ['code2script("BO") eq "Tibetan"', 0], - ['code2script("Bo") eq "Tibetan"', 0], - ['code2script("bo") eq "Tibetan"', 0], - ['code2script("bo", LOCALE_CODE_ALPHA_2) eq "Tibetan"', 0], - ['code2script("bod", LOCALE_CODE_ALPHA_3) eq "Tibetan"', 0], - ['code2script("330", LOCALE_CODE_NUMERIC) eq "Tibetan"', 0], - - ['code2script("yi", LOCALE_CODE_ALPHA_2) eq "Yi"', 0], # last in DATA - ['code2script("Yii", LOCALE_CODE_ALPHA_3) eq "Yi"', 0], - ['code2script("460", LOCALE_CODE_NUMERIC) eq "Yi"', 0], - - ['code2script("am") eq "Aramaic"', 0], # first in DATA segment - - - #================================================ - # TESTS FOR script2code - #================================================ - - #---- selection of examples which should all result in undef ----------- - ['!defined code2script("BO", LOCALE_CODE_ALPHA_3)', 0], - ['!defined code2script("BO", LOCALE_CODE_NUMERIC)', 0], - ['!defined script2code()', 0], # no argument - ['!defined script2code(undef)', 0], # undef argument - ['!defined script2code("Banana")', 0], # illegal script name - - #---- some successful examples ----------------------------------------- - ['script2code("meroitic") eq "me"', 0], - ['script2code("burmese") eq "my"', 0], - ['script2code("Pahlavi") eq "ph"', 0], - ['script2code("Vai", LOCALE_CODE_ALPHA_3) eq "vai"', 0], - ['script2code("Tamil", LOCALE_CODE_NUMERIC) eq "346"', 0], - ['script2code("Latin") eq "la"', 0], - ['script2code("Latin", LOCALE_CODE_ALPHA_3) eq "lat"', 0], - - #================================================ - # TESTS FOR script_code2code - #================================================ - - #---- selection of examples which should all result in undef ----------- - ['!defined script_code2code("bo", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_3)', 0], - ['!defined script_code2code("aa", LOCALE_CODE_ALPHA_2, LOCALE_CODE_ALPHA_3)', 0], - ['!defined script_code2code("aa", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_3)', 0], - ['!defined script_code2code("aa", LOCALE_CODE_ALPHA_2)', 1], - ['!defined script_code2code()', 1], # no argument - ['!defined script_code2code(undef)', 1], # undef argument - - #---- some successful examples ----------------------------------------- - ['script_code2code("BO", LOCALE_CODE_ALPHA_2, LOCALE_CODE_ALPHA_3) eq "bod"', 0], - ['script_code2code("bod", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_2) eq "bo"', 0], - ['script_code2code("Phx", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_2) eq "ph"', 0], - ['script_code2code("295", LOCALE_CODE_NUMERIC, LOCALE_CODE_ALPHA_3) eq "pqd"', 0], - ['script_code2code(170, LOCALE_CODE_NUMERIC, LOCALE_CODE_ALPHA_3) eq "tna"', 0], - ['script_code2code("rr", LOCALE_CODE_ALPHA_2, LOCALE_CODE_NUMERIC) eq "620"', 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/cpan/Locale-Codes/t/script2code.t b/cpan/Locale-Codes/t/script2code.t new file mode 100755 index 0000000000..415e1a6c53 --- /dev/null +++ b/cpan/Locale-Codes/t/script2code.t @@ -0,0 +1,55 @@ +#!/usr/bin/perl -w + +require 5.002; + +$runtests=shift(@ARGV); +if ( -f "t/testfunc.pl" ) { + require "t/testfunc.pl"; + $dir="./lib"; + $tdir="t"; +} elsif ( -f "testfunc.pl" ) { + require "testfunc.pl"; + $dir="../lib"; + $tdir="."; +} else { + die "ERROR: cannot find testfunc.pl\n"; +} + +unshift(@INC,$dir); +use Locale::Script; + +%type = ( "LOCALE_SCRIPT_ALPHA" => LOCALE_SCRIPT_ALPHA, + "LOCALE_SCRIPT_NUMERIC" => LOCALE_SCRIPT_NUMERIC, + ); + +sub test { + my(@test) = @_; + $test[1] = $type{$test[1]} + if (@test == 2 && $test[1] && exists $type{$test[1]}); + return script2code(@test); +} + +$tests = " + +~ _undef_ + +Phoenician ~ Phnx + +Phoenician LOCALE_SCRIPT_NUMERIC ~ 115 + +"; + +print "script2code...\n"; +test_Func(\&test,$tests,$runtests); + +1; +# Local Variables: +# mode: cperl +# indent-tabs-mode: nil +# cperl-indent-level: 3 +# cperl-continued-statement-offset: 2 +# cperl-continued-brace-offset: 0 +# cperl-brace-offset: 0 +# cperl-brace-imaginary-offset: 0 +# cperl-label-offset: -2 +# End: diff --git a/cpan/Locale-Codes/t/testfunc.pl b/cpan/Locale-Codes/t/testfunc.pl new file mode 100644 index 0000000000..affbf9505d --- /dev/null +++ b/cpan/Locale-Codes/t/testfunc.pl @@ -0,0 +1,480 @@ +#!/usr/bin/perl -w +# Copyright (c) 1996-2010 Sullivan Beck. All rights reserved. +# This program is free software; you can redistribute it and/or modify it +# under the same terms as Perl itself. + +# SB_TEST.PL +############################################################################### +# HISTORY +# +# 1996-??-?? Wrote initial version for Date::Manip module +# +# 1996-2001 Numerous changes +# +# 2001-03-29 Rewrote to make it easier to drop in for any module. +# +# 2001-06-19 Modifications to make space delimited stuff work better. +# +# 2001-08-23 Added support for undef args. +# +# 2007-08-14 Better support for undef/blank args. +# +# 2008-01-02 Better handling of $runtests. +# +# 2008-01-24 Better handling of undef/blank args when arguements are +# entered as lists instead of strings. +# +# 2008-01-25 Created a global $testnum variable to store the test number +# in. +# +# 2008-11-05 Slightly better handling of blank/undef in returned values. +# +# 2009-09-01 Added "-l" value to $runtests. +# +# 2009-09-30 Much better support for references. +# +# 2010-02-05 Fixed bug in passing tests as lists +# +# 2010-04-05 Renamed to testfunc.pl to avoid being called in a core module + +############################################################################### + +use Storable qw(dclone); + +# Usage: test_Func($funcref,$tests,$runtests,@extra)=@_; +# +# This takes a series of tests, runs them, compares the output of the tests +# with expected output, and reports any differences. Each test consists of +# several parts: +# a function passed in as a reference ($funcref) +# a series of arguments to be passed to the function +# the expected output from the function call +# +# Tests may be passed in in two methods: as a string, or as a reference. +# +# Using the string case, $tests is a newline delimited string. Each test +# takes one or more lines of the string. Tests are separated from each +# other by a blank line. +# +# Arguments and return value(s) may be written as a single line: +# ARG1 ARG2 ... ARGn ~ VAL1 VAL2 ... VALm +# or as multiple lines: +# ARG1 +# ARG2 +# ... +# ARGn +# ~ +# VAL1 +# VAL2 +# ... +# VALm +# +# If any of the arguments OR values have spaces in them, only the multiline +# form may be used. +# +# If there is exactly one return value, the separating tilde is +# optional: +# ARG1 ARG2 ... ARGn VAL1 +# or: +# ARG1 +# ARG2 +# ... +# ARGn +# VAL +# +# It is valid to have a function with no arguments or with no return +# value (or both). The "~" must be used: +# +# ARG1 ARG2 ... ARGn ~ +# +# ~ VAL1 VAL2 ... VALm +# +# ~ +# +# Leading and trailing space is ignored in the multi-line format. +# +# If desired, any of the ARGs or VALs may be the word "_undef_" which +# will be strictly interpreted as the perl undef value. The word "_blank_" +# may also be used to designate a defined but empty string. +# +# They may also be (in the multiline format) of the form: +# +# \ STRING : a string reference +# +# [] LIST : a list reference (where LIST is a +# comma separated list) +# +# [SEP] LIST : a list reference (where SEP is a +# single character separator) +# +# {} HASH : a hash reference (where HASH is +# a comma separated list) +# +# {SEP} HASH : a hash reference (where SEP is a +# single character separator) +# +# Alternately, the tests can be passed in as a list reference: +# $tests = [ +# [ +# [ @ARGS1 ], +# [ @VALS1 ] +# ], +# [ +# [ @ARGS2 ], +# [ @VALS2 ] +# ], ... +# ] +# +# @extra are extra arguments which are added to the function call. +# +# There are several ways to run the tests, depending on the value of +# $runtests. +# +# If $runtests is 0, the tests are run in a non-interactive way suitable +# for running as part of a "make test". +# +# If $runtests is a positive number, it runs runs all tests starting at +# that value in a way suitable for running interactively. +# +# If $runtests is a negative number, it runs all tests starting at that +# value, but providing feedback at each test. +# +# If $runtests is a string "=N" (where N is a number), it runs only +# that test. +# +# If $runtests is the string "-l", it lists the tests and the expected +# output without running any. + +sub test_Func { + my($funcref,$tests,$runtests,@extra)=@_; + my(@tests); + + $runtests = 0 if (! $runtests); + my($starttest,$feedback,$endtest,$runtest); + if ($runtests eq "0" or $runtests eq "-0") { + $starttest = 1; + $feedback = 1; + $endtest = 0; + $runtest = 1; + } elsif ($runtests =~ /^\d+$/){ + $starttest = $runtests; + $feedback = 0; + $endtest = 0; + $runtest = 1; + } elsif ($runtests =~ /^-(\d+)$/) { + $starttest = $1; + $feedback = 1; + $endtest = 0; + $runtest = 1; + } elsif ($runtests =~ /^=(\d+)$/) { + $starttest = $1; + $feedback = 1; + $endtest = $1; + $runtest = 1; + } elsif ($runtests eq "-l") { + $starttest = 1; + $feedback = 1; + $endtest = 0; + $runtest = 0; + } else { + die "ERROR: unknown argument(s): $runtests"; + } + + my($tests_as_list) = 0; + if (ref($tests) eq "ARRAY") { + @tests = @$tests; + $tests_as_list = 1; + + } else { + # Separate tests. + + my($comment)="#"; + my(@lines)=split(/\n/,$tests); + my(@test); + while (@lines) { + my $line = shift(@lines); + $line =~ s/^\s*//; + $line =~ s/\s*$//; + next if ($line =~ /^$comment/); + + if ($line ne "") { + push(@test,$line); + next; + } + + if (@test) { + push(@tests,[ @test ]); + @test=(); + } + } + if (@test) { + push(@tests,[ @test ]); + } + + # Get arg/val lists for each test. + + foreach my $test (@tests) { + my(@tmp)=@$test; + my(@arg,@val); + + # single line test + @tmp = split(/\s+/,$tmp[0]) if ($#tmp == 0); + + my($sep)=-1; + my($i); + for ($i=0; $i<=$#tmp; $i++) { + if ($tmp[$i] eq "~") { + $sep=$i; + last; + } + } + + if ($sep<0) { + @val=pop(@tmp); + @arg=@tmp; + } else { + @arg=@tmp[0..($sep-1)]; + @val=@tmp[($sep+1)..$#tmp]; + } + $test = [ [@arg],[@val] ]; + } + } + + my($ntest)=$#tests + 1; + print "1..$ntest\n" if ($feedback && $runtest); + + my(@t); + if ($endtest) { + @t = ($starttest..$endtest); + } else { + @t = ($starttest..$ntest); + } + + foreach my $t (@t) { + $::testnum = $t; + + my (@arg); + if ($tests_as_list) { + @arg = @{ $tests[$t-1][0] }; + } else { + my $arg = dclone($tests[$t-1][0]); + @arg = @$arg; + print_to_vals(\@arg); + } + + my $argprt = dclone(\@arg); + my @argprt = @$argprt; + vals_to_print(\@argprt); + + my $exp = dclone($tests[$t-1][1]); + my @exp = @$exp; + print_to_vals(\@exp); + vals_to_print(\@exp); + + # Run the test + + my ($ans,@ans); + if ($runtest) { + @ans = &$funcref(@arg,@extra); + } + vals_to_print(\@ans); + + # Compare the results + + foreach my $arg (@arg) { + $arg = "_undef_" if (! defined $arg); + $arg = "_blank_" if ($arg eq ""); + } + $arg = join("\n ",@argprt,@extra); + $ans = join("\n ",@ans); + $exp = join("\n ",@exp); + + if (! $runtest) { + print "########################\n"; + print "Test = $t\n"; + print "Args = $arg\n"; + print "Expected = $exp\n"; + } elsif ($ans ne $exp) { + print "not ok $t\n"; + warn "########################\n"; + warn "Args = $arg\n"; + warn "Expected = $exp\n"; + warn "Got = $ans\n"; + warn "########################\n"; + } else { + print "ok $t\n" if ($feedback); + } + } +} + +# The following is similar but it takes input from an input file and +# sends output to an output file. +# +# $files is a reference to a list of tests. If one of the tests is named +# "foobar", the input is from "foobar.in", output is to "foobar.out", and +# the expected output is in "foobar.exp". +# +# The function stored in $funcref is called as: +# &$funcref($in,$out,@extra) +# where $in is the name of the input file, $out is the name of the output +# file, and @extra are any additional arguments that are required. +# +# The function should return 0 on success, or an error message. + +sub test_File { + my($funcref,$files,$runtests,@extra)=@_; + my(@files)=@$files; + + $runtests=0 if (! $runtests); + + my($ntest)=$#files + 1; + print "1..$ntest\n" if (! $runtests); + + my(@t); + if ($runtests > 0) { + @t = ($runtests..$ntest); + } elsif ($runtests < 0) { + @t = (-$runtests); + } else { + @t = (1..$ntest); + } + + foreach my $t (@t) { + $::testnum = $t; + my $test = $files[$t-1]; + my $expf = "$test.exp"; + my $outf = "$test.out"; + + if (! -f $test || ! -f $expf) { + print "not ok $t\n"; + warn "Test: $test: missing input/outpuf information\n"; + next; + } + + my $err = &$funcref($test,$outf,@extra); + if ($err) { + print "not ok $t\n"; + warn "Test: $test: $err\n"; + next; + } + + local *FH; + open(FH,$expf) || do { + print "not ok $t\n"; + warn "Test: $test: $!\n"; + next; + }; + my @exp = <FH>; + close(FH); + my $exp = join("",@exp); + open(FH,$outf) || do { + print "not ok $t\n"; + warn "Test: $test: $!\n"; + next; + }; + my @out = <FH>; + close(FH); + my $out = join("",@out); + + if ($out ne $exp) { + print "not ok $t\n"; + warn "Test: $test: output differs from expected value\n"; + next; + } + + print "ok $t\n" if (! $runtests); + } +} + +# Converts a printable version of arguments to actual arguments +sub print_to_vals { + my($listref) = @_; + + foreach my $arg (@$listref) { + next if (! defined($arg)); + if ($arg eq "_undef_") { + $arg = undef; + + } elsif ($arg eq "_blank_") { + $arg = ""; + + } elsif ($arg =~ /^\\\s*(.*)/) { + $str = $1; + $arg = \$str; + + } elsif ($arg =~ /^\[(.?)\]\s*(.*)/) { + my($sep,$str) = ($1,$2); + $sep = "," if (! $sep); + my @list = split(/\Q$sep\E/,$str); + foreach my $e (@list) { + $e = "" if ($e eq "_blank_"); + $e = undef if ($e eq "_undef_"); + } + $arg = \@list; + + } elsif ($arg =~ /^\{(.?)\}\s*(.*)/) { + my($sep,$str) = ($1,$2); + $sep = "," if (! $sep); + my %hash = split(/\Q$sep\E/,$str); + foreach my $key (keys %hash) { + my $val = $hash{$key}; + $hash{$key} = undef if ($val eq "_undef_"); + $hash{$key} = "" if ($val eq "_blank_"); + } + $arg = \%hash; + } + } +} + +# Converts arguments to a printable version. +sub vals_to_print { + my($listref) = @_; + + foreach my $arg (@$listref) { + if (! defined $arg) { + $arg = "_undef_"; + + } elsif (! ref($arg)) { + $arg = "_blank_" if ($arg eq ""); + + } else { + my $ref = ref($arg); + if ($ref eq "SCALAR") { + $arg = "\\ $$arg"; + + } elsif ($ref eq "ARRAY") { + my @list = @$arg; + foreach my $e (@list) { + $e = "_undef_", next if (! defined($e)); + $e = "_blank_" if ($e eq ""); + } + $arg = join(" ","[",join(", ",@list),"]"); + + } elsif ($ref eq "HASH") { + %hash = %$arg; + foreach my $key (keys %hash) { + my $val = $hash{$key}; + $hash{$key} = "_undef_", next if (! defined($val)); + $hash{$key} = "_blank_" if ($val eq "_blank_"); + } + $arg = join(" ","{", + join(", ",map { "$_ => $hash{$_}" } + (sort keys %hash)), "}"); + $arg =~ s/ +/ /g; + } + } + } +} + +1; +# Local Variables: +# mode: cperl +# indent-tabs-mode: nil +# cperl-indent-level: 3 +# cperl-continued-statement-offset: 2 +# cperl-continued-brace-offset: 0 +# cperl-brace-offset: 0 +# cperl-brace-imaginary-offset: 0 +# cperl-label-offset: -2 +# End: + diff --git a/cpan/Locale-Codes/t/uk.t b/cpan/Locale-Codes/t/uk.t deleted file mode 100644 index 95c2118fe9..0000000000 --- a/cpan/Locale-Codes/t/uk.t +++ /dev/null @@ -1,65 +0,0 @@ -#!./perl -# -# uk.t - tests for Locale::Country with "uk" aliases to "gb" -# - -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; |