This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Make given() statements return the last evaluated expression
[perl5.git] / cpan / Locale-Codes / t / script.t
1 #!./perl
2 #
3 # script.t - tests for Locale::Script
4 #
5
6 use Locale::Script;
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 code2script
19         #================================================
20
21  #---- selection of examples which should all result in undef -----------
22  ['!defined code2script()', 0],                  # no argument
23  ['!defined code2script(undef)', 0],             # undef argument
24  ['!defined code2script("aa")', 0],              # illegal code
25  ['!defined code2script("aa", LOCALE_CODE_ALPHA_2)', 0],        # illegal code
26  ['!defined code2script("aa", LOCALE_CODE_ALPHA_3)', 0],        # illegal code
27  ['!defined code2script("aa", LOCALE_CODE_NUMERIC)', 0],        # illegal code
28
29  #---- some successful examples -----------------------------------------
30  ['code2script("BO") eq "Tibetan"', 0],
31  ['code2script("Bo") eq "Tibetan"', 0],
32  ['code2script("bo") eq "Tibetan"', 0],
33  ['code2script("bo", LOCALE_CODE_ALPHA_2) eq "Tibetan"', 0],
34  ['code2script("bod", LOCALE_CODE_ALPHA_3) eq "Tibetan"', 0],
35  ['code2script("330", LOCALE_CODE_NUMERIC) eq "Tibetan"', 0],
36
37  ['code2script("yi", LOCALE_CODE_ALPHA_2) eq "Yi"', 0], # last in DATA
38  ['code2script("Yii", LOCALE_CODE_ALPHA_3) eq "Yi"', 0],
39  ['code2script("460", LOCALE_CODE_NUMERIC) eq "Yi"', 0],
40
41  ['code2script("am") eq "Aramaic"', 0],          # first in DATA segment
42
43
44         #================================================
45         # TESTS FOR script2code
46         #================================================
47
48  #---- selection of examples which should all result in undef -----------
49  ['!defined code2script("BO", LOCALE_CODE_ALPHA_3)', 0],
50  ['!defined code2script("BO", LOCALE_CODE_NUMERIC)', 0],
51  ['!defined script2code()', 0],                  # no argument
52  ['!defined script2code(undef)', 0],             # undef argument
53  ['!defined script2code("Banana")', 0],          # illegal script name
54
55  #---- some successful examples -----------------------------------------
56  ['script2code("meroitic")                   eq "me"', 0],
57  ['script2code("burmese")                    eq "my"', 0],
58  ['script2code("Pahlavi")                    eq "ph"', 0],
59  ['script2code("Vai", LOCALE_CODE_ALPHA_3)   eq "vai"', 0],
60  ['script2code("Tamil", LOCALE_CODE_NUMERIC) eq "346"', 0],
61  ['script2code("Latin")                      eq "la"', 0],
62  ['script2code("Latin", LOCALE_CODE_ALPHA_3) eq "lat"', 0],
63
64         #================================================
65         # TESTS FOR script_code2code
66         #================================================
67
68  #---- selection of examples which should all result in undef -----------
69  ['!defined script_code2code("bo", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_3)', 0],
70  ['!defined script_code2code("aa", LOCALE_CODE_ALPHA_2, LOCALE_CODE_ALPHA_3)', 0],
71  ['!defined script_code2code("aa", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_3)', 0],
72  ['!defined script_code2code("aa", LOCALE_CODE_ALPHA_2)', 1],
73  ['!defined script_code2code()', 1],                  # no argument
74  ['!defined script_code2code(undef)', 1],             # undef argument
75
76  #---- some successful examples -----------------------------------------
77  ['script_code2code("BO", LOCALE_CODE_ALPHA_2, LOCALE_CODE_ALPHA_3) eq "bod"', 0],
78  ['script_code2code("bod", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_2) eq "bo"', 0],
79  ['script_code2code("Phx", LOCALE_CODE_ALPHA_3, LOCALE_CODE_ALPHA_2) eq "ph"', 0],
80  ['script_code2code("295", LOCALE_CODE_NUMERIC, LOCALE_CODE_ALPHA_3) eq "pqd"', 0],
81  ['script_code2code(170, LOCALE_CODE_NUMERIC, LOCALE_CODE_ALPHA_3) eq "tna"', 0],
82  ['script_code2code("rr", LOCALE_CODE_ALPHA_2, LOCALE_CODE_NUMERIC) eq "620"', 0],
83
84 );
85
86 print "1..", int(@TESTS), "\n";
87
88 $testid = 1;
89 foreach $test (@TESTS)
90 {
91     eval "print (($test->[0]) ? \"ok $testid\\n\" : \"not ok $testid\\n\" )";
92     if ($@)
93     {
94         if (!$test->[1])
95         {
96             print "not ok $testid\n";
97         }
98         else
99         {
100             print "ok $testid\n";
101         }
102     }
103     ++$testid;
104 }
105
106 exit 0;