xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/lib/Locale/Codes/t/country.t (revision 0:68f95e015346)
1#!./perl
2#
3# country.t - tests for Locale::Country
4#
5
6BEGIN {
7        chdir 't' if -d 't';
8        @INC = '../lib';
9}
10
11use Locale::Country;
12
13#-----------------------------------------------------------------------
14# This is an array of tests specs. Each spec is [TEST, OK_TO_DIE]
15# Each TEST is eval'd as an expression.
16# If it evaluates to FALSE, then "not ok N" is printed for the test,
17# otherwise "ok N". If the eval dies, then the OK_TO_DIE flag is checked.
18# If it is true (1), the test is treated as passing, otherwise it failed.
19#-----------------------------------------------------------------------
20@TESTS =
21(
22	#================================================
23	# TESTS FOR code2country
24	#================================================
25
26 #---- selection of examples which should all result in undef -----------
27 ['!defined code2country()', 0],                  # no argument
28 ['!defined code2country(undef)', 0],             # undef argument
29 ['!defined code2country("zz")', 0],              # illegal code
30 ['!defined code2country("zz", LOCALE_CODE_ALPHA_2)', 0],        # illegal code
31 ['!defined code2country("zz", LOCALE_CODE_ALPHA_3)', 0],        # illegal code
32 ['!defined code2country("zz", LOCALE_CODE_NUMERIC)', 0],        # illegal code
33 ['!defined code2country("ja")', 0],              # should be jp for country
34 ['!defined code2country("uk")', 0],              # should be jp for country
35
36 #---- some successful examples -----------------------------------------
37 ['code2country("BO") eq "Bolivia"', 0],
38 ['code2country("BO", LOCALE_CODE_ALPHA_2) eq "Bolivia"', 0],
39 ['code2country("bol", LOCALE_CODE_ALPHA_3) eq "Bolivia"', 0],
40 ['code2country("pk") eq "Pakistan"', 0],
41 ['code2country("sn") eq "Senegal"', 0],
42 ['code2country("us") eq "United States"', 0],
43 ['code2country("ad") eq "Andorra"', 0],          # first in DATA segment
44 ['code2country("ad", LOCALE_CODE_ALPHA_2) eq "Andorra"', 0],
45 ['code2country("and", LOCALE_CODE_ALPHA_3) eq "Andorra"', 0],
46 ['code2country("020", LOCALE_CODE_NUMERIC) eq "Andorra"', 0],
47 ['code2country(48, LOCALE_CODE_NUMERIC) eq "Bahrain"', 0],
48 ['code2country("zw") eq "Zimbabwe"', 0],         # last in DATA segment
49 ['code2country("gb") eq "United Kingdom"', 0],   # United Kingdom is "gb", not "uk"
50
51 #-- tests added after changes in the standard 2002-05-20 ------
52 ['code2country("kz") eq "Kazakhstan"', 0],
53 ['country2code("kazakhstan")               eq "kz"', 0],
54 ['country2code("kazakstan")                eq "kz"', 0],
55
56 ['code2country("mo") eq "Macao"', 0],
57 ['country2code("macao")                    eq "mo"', 0],
58 ['country2code("macau")                    eq "mo"', 0],
59
60 ['code2country("tl", LOCALE_CODE_ALPHA_2) eq "East Timor"', 0],
61 ['code2country("tls", LOCALE_CODE_ALPHA_3) eq "East Timor"', 0],
62 ['code2country("626", LOCALE_CODE_NUMERIC) eq "East Timor"', 0],
63
64	#================================================
65	# TESTS FOR country2code
66	#================================================
67
68 #---- selection of examples which should all result in undef -----------
69 ['!defined code2country("BO", LOCALE_CODE_ALPHA_3)', 0],
70 ['!defined code2country("BO", LOCALE_CODE_NUMERIC)', 0],
71 ['!defined country2code()', 0],                  # no argument
72 ['!defined country2code(undef)', 0],             # undef argument
73 ['!defined country2code("Banana")', 0],          # illegal country name
74
75 #---- some successful examples -----------------------------------------
76 ['country2code("japan")                    eq "jp"', 0],
77 ['country2code("japan")                    ne "ja"', 0],
78 ['country2code("Japan")                    eq "jp"', 0],
79 ['country2code("United States")            eq "us"', 0],
80 ['country2code("United Kingdom")           eq "gb"', 0],
81 ['country2code("Andorra")                  eq "ad"', 0],    # first in DATA
82 ['country2code("Zimbabwe")                 eq "zw"', 0],    # last in DATA
83 ['country2code("Iran")                     eq "ir"', 0],    # alias
84 ['country2code("North Korea")              eq "kp"', 0],    # alias
85 ['country2code("South Korea")              eq "kr"', 0],    # alias
86 ['country2code("Libya")                    eq "ly"', 0],    # alias
87 ['country2code("Syria")                    eq "sy"', 0],    # alias
88 ['country2code("Svalbard")                 eq "sj"', 0],    # alias
89 ['country2code("Jan Mayen")                eq "sj"', 0],    # alias
90 ['country2code("USA")                      eq "us"', 0],    # alias
91 ['country2code("United States of America") eq "us"', 0],    # alias
92 ['country2code("Great Britain")            eq "gb"', 0],    # alias
93
94	#================================================
95	# TESTS FOR country_code2code
96	#================================================
97
98 #---- selection of examples which should all result in undef -----------
99 ['!defined country_code2code("bo", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_3)', 0],
100 ['!defined country_code2code("zz", LOCALE_CODE_ALPHA_2, LOCALE_CODE_ALPHA_3)', 0],
101 ['!defined country_code2code("zz", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_3)', 0],
102 ['!defined country_code2code("zz", LOCALE_CODE_ALPHA_2)', 1],
103 ['!defined country_code2code("bo", LOCALE_CODE_ALPHA_2)', 1],
104 ['!defined country_code2code()', 1],                  # no argument
105 ['!defined country_code2code(undef)', 1],             # undef argument
106
107 #---- some successful examples -----------------------------------------
108 ['country_code2code("BO", LOCALE_CODE_ALPHA_2, LOCALE_CODE_ALPHA_3) eq "bol"', 0],
109 ['country_code2code("bol", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_2) eq "bo"', 0],
110 ['country_code2code("zwe", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_2) eq "zw"', 0],
111 ['country_code2code("858", LOCALE_CODE_NUMERIC, LOCALE_CODE_ALPHA_3) eq "ury"', 0],
112 ['country_code2code(858, LOCALE_CODE_NUMERIC, LOCALE_CODE_ALPHA_3) eq "ury"', 0],
113 ['country_code2code("tr", LOCALE_CODE_ALPHA_2, LOCALE_CODE_NUMERIC) eq "792"', 0],
114
115);
116
117print "1..", int(@TESTS), "\n";
118
119$testid = 1;
120foreach $test (@TESTS)
121{
122    eval "print (($test->[0]) ? \"ok $testid\\n\" : \"not ok $testid\\n\" )";
123    if ($@)
124    {
125	if (!$test->[1])
126	{
127	    print "not ok $testid\n";
128	}
129	else
130	{
131	    print "ok $testid\n";
132	}
133    }
134    ++$testid;
135}
136
137exit 0;
138