dslinux/user/perl/lib/Locale/Codes/t all.t constants.t country.t currency.t languages.t rename.t script.t uk.t

cayenne dslinux_cayenne at user.in-berlin.de
Tue Dec 5 05:27:11 CET 2006


Update of /cvsroot/dslinux/dslinux/user/perl/lib/Locale/Codes/t
In directory antilope:/tmp/cvs-serv7729/lib/Locale/Codes/t

Added Files:
	all.t constants.t country.t currency.t languages.t rename.t 
	script.t uk.t 
Log Message:
Adding fresh perl source to HEAD to branch from

--- NEW FILE: uk.t ---
#!./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;

--- NEW FILE: currency.t ---
#!./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;

--- NEW FILE: rename.t ---
#!./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;

--- NEW FILE: languages.t ---
#!./perl
#
# language.t - tests for Locale::Language
#

BEGIN {
	chdir 't' if -d 't';
	@INC = '../lib';
}

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;
}

exit 0;

--- NEW FILE: country.t ---
#!./perl
#
# country.t - tests for Locale::Country
#

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;
}

exit 0;

--- NEW FILE: all.t ---
#!./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");


--- NEW FILE: script.t ---
#!./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;

--- NEW FILE: constants.t ---
#!./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;




More information about the dslinux-commit mailing list