cwd.t (was: Cwd has no tests?)
[p5sagit/p5-mst-13.2.git] / t / lib / lc-country.t
1 #!./perl
2 #
3 # country.t - tests for Locale::Country
4 #
5
6 use Locale::Country;
7
8 #-----------------------------------------------------------------------
9 # This is an array of tests specs. Each spec is [TEST, OK_TO_DIE]
10 # Each TEST is eval'd as an expression.
11 # If it evaluates to FALSE, then "not ok N" is printed for the test,
12 # otherwise "ok N". If the eval dies, then the OK_TO_DIE flag is checked.
13 # If it is true (1), the test is treated as passing, otherwise it failed.
14 #-----------------------------------------------------------------------
15 @TESTS =
16 (
17         #================================================
18         # TESTS FOR code2country
19         #================================================
20
21  #---- selection of examples which should all result in undef -----------
22  ['!defined code2country()', 0],                  # no argument
23  ['!defined code2country(undef)', 0],             # undef argument
24  ['!defined code2country("zz")', 0],              # illegal code
25  ['!defined code2country("zz", LOCALE_CODE_ALPHA_2)', 0],        # illegal code
26  ['!defined code2country("zz", LOCALE_CODE_ALPHA_3)', 0],        # illegal code
27  ['!defined code2country("zz", LOCALE_CODE_NUMERIC)', 0],        # illegal code
28  ['!defined code2country("ja")', 0],              # should be jp for country
29  ['!defined code2country("uk")', 0],              # should be jp for country
30
31  #---- some successful examples -----------------------------------------
32  ['code2country("BO") eq "Bolivia"', 0],
33  ['code2country("BO", LOCALE_CODE_ALPHA_2) eq "Bolivia"', 0],
34  ['code2country("bol", LOCALE_CODE_ALPHA_3) eq "Bolivia"', 0],
35  ['code2country("pk") eq "Pakistan"', 0],
36  ['code2country("sn") eq "Senegal"', 0],
37  ['code2country("us") eq "United States"', 0],
38  ['code2country("ad") eq "Andorra"', 0],          # first in DATA segment
39  ['code2country("ad", LOCALE_CODE_ALPHA_2) eq "Andorra"', 0],
40  ['code2country("and", LOCALE_CODE_ALPHA_3) eq "Andorra"', 0],
41  ['code2country("020", LOCALE_CODE_NUMERIC) eq "Andorra"', 0],
42  ['code2country(48, LOCALE_CODE_NUMERIC) eq "Bahrain"', 0],
43  ['code2country("zw") eq "Zimbabwe"', 0],         # last in DATA segment
44  ['code2country("gb") eq "United Kingdom"', 0],   # United Kingdom is "gb", not "uk"
45
46         #================================================
47         # TESTS FOR country2code
48         #================================================
49
50  #---- selection of examples which should all result in undef -----------
51  ['!defined code2country("BO", LOCALE_CODE_ALPHA_3)', 0],
52  ['!defined code2country("BO", LOCALE_CODE_NUMERIC)', 0],
53  ['!defined country2code()', 0],                  # no argument
54  ['!defined country2code(undef)', 0],             # undef argument
55  ['!defined country2code("Banana")', 0],          # illegal country name
56
57  #---- some successful examples -----------------------------------------
58  ['country2code("japan")          eq "jp"', 0],
59  ['country2code("japan")          ne "ja"', 0],
60  ['country2code("Japan")          eq "jp"', 0],
61  ['country2code("United States")  eq "us"', 0],
62  ['country2code("United Kingdom") eq "gb"', 0],
63  ['country2code("Andorra")        eq "ad"', 0],    # first in DATA segment
64  ['country2code("Zimbabwe")       eq "zw"', 0],    # last in DATA segment
65
66         #================================================
67         # TESTS FOR country_code2code
68         #================================================
69
70  #---- selection of examples which should all result in undef -----------
71  ['!defined country_code2code("bo", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_3)', 0],
72  ['!defined country_code2code("zz", LOCALE_CODE_ALPHA_2, LOCALE_CODE_ALPHA_3)', 0],
73  ['!defined country_code2code("zz", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_3)', 0],
74  ['!defined country_code2code("zz", LOCALE_CODE_ALPHA_2)', 1],
75  ['!defined country_code2code("bo", LOCALE_CODE_ALPHA_2)', 1],
76  ['!defined country_code2code()', 1],                  # no argument
77  ['!defined country_code2code(undef)', 1],             # undef argument
78
79  #---- some successful examples -----------------------------------------
80  ['country_code2code("BO", LOCALE_CODE_ALPHA_2, LOCALE_CODE_ALPHA_3) eq "bol"', 0],
81  ['country_code2code("bol", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_2) eq "bo"', 0],
82  ['country_code2code("zwe", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_2) eq "zw"', 0],
83  ['country_code2code("858", LOCALE_CODE_NUMERIC, LOCALE_CODE_ALPHA_3) eq "ury"', 0],
84  ['country_code2code(858, LOCALE_CODE_NUMERIC, LOCALE_CODE_ALPHA_3) eq "ury"', 0],
85  ['country_code2code("tr", LOCALE_CODE_ALPHA_2, LOCALE_CODE_NUMERIC) eq "792"', 0],
86
87 );
88
89 print "1..", int(@TESTS), "\n";
90
91 $testid = 1;
92 foreach $test (@TESTS)
93 {
94     eval "print (($test->[0]) ? \"ok $testid\\n\" : \"not ok $testid\\n\" )";
95     if ($@)
96     {
97         if (!$test->[1])
98         {
99             print "not ok $testid\n";
100         }
101         else
102         {
103             print "ok $testid\n";
104         }
105     }
106     ++$testid;
107 }
108
109 exit 0;