Update Locale::Codes to 3.12
[p5sagit/p5-mst-13.2.git] / cpan / Locale-Codes / t / country.t
old mode 100644 (file)
new mode 100755 (executable)
index 0c9fda8..830fa55
-#!./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: