This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
e70e104874697396ccc18fb97bbc9a88449e74fd
[perl5.git] / lib / Unicode / UCD.t
1 use Unicode::UCD;
2
3 use strict;
4
5 BEGIN {
6     if (ord("A") == 193) {
7         print "1..0 # Skip: EBCDIC\n";
8         exit 0;
9     }
10 }
11
12 use Test;
13
14 BEGIN { plan tests => 162 };
15
16 use Unicode::UCD 'charinfo';
17
18 my $charinfo;
19
20 $charinfo = charinfo(0x41);
21
22 ok($charinfo->{code},           '0041');
23 ok($charinfo->{name},           'LATIN CAPITAL LETTER A');
24 ok($charinfo->{category},       'Lu');
25 ok($charinfo->{combining},      '0');
26 ok($charinfo->{bidi},           'L');
27 ok($charinfo->{decomposition},  '');
28 ok($charinfo->{decimal},        '');
29 ok($charinfo->{digit},          '');
30 ok($charinfo->{numeric},        '');
31 ok($charinfo->{mirrored},       'N');
32 ok($charinfo->{unicode10},      '');
33 ok($charinfo->{comment},        '');
34 ok($charinfo->{upper},          '');
35 ok($charinfo->{lower},          '0061');
36 ok($charinfo->{title},          '');
37 ok($charinfo->{block},          'Basic Latin');
38 ok($charinfo->{script},         'Latin');
39
40 $charinfo = charinfo(0x100);
41
42 ok($charinfo->{code},           '0100');
43 ok($charinfo->{name},           'LATIN CAPITAL LETTER A WITH MACRON');
44 ok($charinfo->{category},       'Lu');
45 ok($charinfo->{combining},      '0');
46 ok($charinfo->{bidi},           'L');
47 ok($charinfo->{decomposition},  '0041 0304');
48 ok($charinfo->{decimal},        '');
49 ok($charinfo->{digit},          '');
50 ok($charinfo->{numeric},        '');
51 ok($charinfo->{mirrored},       'N');
52 ok($charinfo->{unicode10},      'LATIN CAPITAL LETTER A MACRON');
53 ok($charinfo->{comment},        '');
54 ok($charinfo->{upper},          '');
55 ok($charinfo->{lower},          '0101');
56 ok($charinfo->{title},          '');
57 ok($charinfo->{block},          'Latin Extended-A');
58 ok($charinfo->{script},         'Latin');
59
60 # 0x0590 is in the Hebrew block but unused.
61
62 $charinfo = charinfo(0x590);
63
64 ok($charinfo->{code},          undef);
65 ok($charinfo->{name},          undef);
66 ok($charinfo->{category},      undef);
67 ok($charinfo->{combining},     undef);
68 ok($charinfo->{bidi},          undef);
69 ok($charinfo->{decomposition}, undef);
70 ok($charinfo->{decimal},       undef);
71 ok($charinfo->{digit},         undef);
72 ok($charinfo->{numeric},       undef);
73 ok($charinfo->{mirrored},      undef);
74 ok($charinfo->{unicode10},     undef);
75 ok($charinfo->{comment},       undef);
76 ok($charinfo->{upper},         undef);
77 ok($charinfo->{lower},         undef);
78 ok($charinfo->{title},         undef);
79 ok($charinfo->{block},         undef);
80 ok($charinfo->{script},        undef);
81
82 # 0x05d0 is in the Hebrew block and used.
83
84 $charinfo = charinfo(0x5d0);
85
86 ok($charinfo->{code},           '05D0');
87 ok($charinfo->{name},           'HEBREW LETTER ALEF');
88 ok($charinfo->{category},       'Lo');
89 ok($charinfo->{combining},      '0');
90 ok($charinfo->{bidi},           'R');
91 ok($charinfo->{decomposition},  '');
92 ok($charinfo->{decimal},        '');
93 ok($charinfo->{digit},          '');
94 ok($charinfo->{numeric},        '');
95 ok($charinfo->{mirrored},       'N');
96 ok($charinfo->{unicode10},      '');
97 ok($charinfo->{comment},        '');
98 ok($charinfo->{upper},          '');
99 ok($charinfo->{lower},          '');
100 ok($charinfo->{title},          '');
101 ok($charinfo->{block},          'Hebrew');
102 ok($charinfo->{script},         'Hebrew');
103
104 # An open syllable in Hangul.
105
106 $charinfo = charinfo(0xAC00);
107
108 ok($charinfo->{code},           'AC00');
109 ok($charinfo->{name},           'HANGUL SYLLABLE-AC00');
110 ok($charinfo->{category},       'Lo');
111 ok($charinfo->{combining},      '0');
112 ok($charinfo->{bidi},           'L');
113 ok($charinfo->{decomposition},  undef);
114 ok($charinfo->{decimal},        '');
115 ok($charinfo->{digit},          '');
116 ok($charinfo->{numeric},        '');
117 ok($charinfo->{mirrored},       'N');
118 ok($charinfo->{unicode10},      '');
119 ok($charinfo->{comment},        '');
120 ok($charinfo->{upper},          '');
121 ok($charinfo->{lower},          '');
122 ok($charinfo->{title},          '');
123 ok($charinfo->{block},          'Hangul Syllables');
124 ok($charinfo->{script},         'Hangul');
125
126 # A closed syllable in Hangul.
127
128 $charinfo = charinfo(0xAE00);
129
130 ok($charinfo->{code},           'AE00');
131 ok($charinfo->{name},           'HANGUL SYLLABLE-AE00');
132 ok($charinfo->{category},       'Lo');
133 ok($charinfo->{combining},      '0');
134 ok($charinfo->{bidi},           'L');
135 ok($charinfo->{decomposition},  undef);
136 ok($charinfo->{decimal},        '');
137 ok($charinfo->{digit},          '');
138 ok($charinfo->{numeric},        '');
139 ok($charinfo->{mirrored},       'N');
140 ok($charinfo->{unicode10},      '');
141 ok($charinfo->{comment},        '');
142 ok($charinfo->{upper},          '');
143 ok($charinfo->{lower},          '');
144 ok($charinfo->{title},          '');
145 ok($charinfo->{block},          'Hangul Syllables');
146 ok($charinfo->{script},         'Hangul');
147
148 $charinfo = charinfo(0x1D400);
149
150 ok($charinfo->{code},           '1D400');
151 ok($charinfo->{name},           'MATHEMATICAL BOLD CAPITAL A');
152 ok($charinfo->{category},       'Lu');
153 ok($charinfo->{combining},      '0');
154 ok($charinfo->{bidi},           'L');
155 ok($charinfo->{decomposition},  '<font> 0041');
156 ok($charinfo->{decimal},        '');
157 ok($charinfo->{digit},          '');
158 ok($charinfo->{numeric},        '');
159 ok($charinfo->{mirrored},       'N');
160 ok($charinfo->{unicode10},      '');
161 ok($charinfo->{comment},        '');
162 ok($charinfo->{upper},          '');
163 ok($charinfo->{lower},          '');
164 ok($charinfo->{title},          '');
165 ok($charinfo->{block},          'Mathematical Alphanumeric Symbols');
166 ok($charinfo->{script},         undef);
167
168 use Unicode::UCD qw(charblock charscript);
169
170 # 0x0590 is in the Hebrew block but unused.
171
172 ok(charblock(0x590),          'Hebrew');
173 ok(charscript(0x590),         undef);
174
175 $charinfo = charinfo(0xbe);
176
177 ok($charinfo->{code},           '00BE');
178 ok($charinfo->{name},           'VULGAR FRACTION THREE QUARTERS');
179 ok($charinfo->{category},       'No');
180 ok($charinfo->{combining},      '0');
181 ok($charinfo->{bidi},           'ON');
182 ok($charinfo->{decomposition},  '<fraction> 0033 2044 0034');
183 ok($charinfo->{decimal},        '');
184 ok($charinfo->{digit},          '');
185 ok($charinfo->{numeric},        '3/4');
186 ok($charinfo->{mirrored},       'N');
187 ok($charinfo->{unicode10},      'FRACTION THREE QUARTERS');
188 ok($charinfo->{comment},        '');
189 ok($charinfo->{upper},          '');
190 ok($charinfo->{lower},          '');
191 ok($charinfo->{title},          '');
192 ok($charinfo->{block},          'Latin-1 Supplement');
193 ok($charinfo->{script},         undef);
194
195 use Unicode::UCD qw(charblocks charscripts);
196
197 my $charblocks = charblocks();
198
199 ok(exists $charblocks->{Thai});
200 ok($charblocks->{Thai}->[0]->[0], hex('0e00'));
201 ok(!exists $charblocks->{PigLatin});
202
203 my $charscripts = charscripts();
204
205 ok(exists $charscripts->{Armenian});
206 ok($charscripts->{Armenian}->[0]->[0], hex('0531'));
207 ok(!exists $charscripts->{PigLatin});
208
209 my $charscript;
210
211 $charscript = charscript("12ab");
212 ok($charscript, 'Ethiopic');
213
214 $charscript = charscript("0x12ab");
215 ok($charscript, 'Ethiopic');
216
217 $charscript = charscript("U+12ab");
218 ok($charscript, 'Ethiopic');
219
220 my $ranges;
221
222 $ranges = charscript('Ogham');
223 ok($ranges->[0]->[0], hex('1681'));
224 ok($ranges->[0]->[1], hex('169a'));
225
226 use Unicode::UCD qw(charinrange);
227
228 $ranges = charscript('Cherokee');
229 ok(!charinrange($ranges, "139f"));
230 ok( charinrange($ranges, "13a0"));
231 ok( charinrange($ranges, "13f4"));
232 ok(!charinrange($ranges, "13f5"));
233
234 ok(Unicode::UCD::UnicodeVersion, '3.1.1');
235
236 use Unicode::UCD qw(compexcl);
237
238 ok(!compexcl(0x0100));
239 ok( compexcl(0x0958));
240
241 use Unicode::UCD qw(casefold);
242
243 my $casefold;
244
245 $casefold = casefold(0x41);
246
247 ok($casefold->{code} eq '0041' &&
248    $casefold->{status} eq 'C'  &&
249    $casefold->{mapping} eq '0061');
250
251 $casefold = casefold(0xdf);
252
253 ok($casefold->{code} eq '00DF' &&
254    $casefold->{status} eq 'F'  &&
255    $casefold->{mapping} eq '0073 0073');
256
257 ok(!casefold(0x20));
258
259 use Unicode::UCD qw(casespec);
260
261 my $casespec;
262
263 ok(!casespec(0x41));
264
265 $casespec = casespec(0xdf);
266
267 ok($casespec->{code} eq '00DF' &&
268    $casespec->{lower} eq '00DF'  &&
269    $casespec->{title} eq '0053 0073'  &&
270    $casespec->{upper} eq '0053 0053' &&
271    $casespec->{condition} eq undef);
272
273 $casespec = casespec(0x307);
274
275 ok($casespec->{az}->{code} eq '0307' &&
276    $casespec->{az}->{lower} eq ''  &&
277    $casespec->{az}->{title} eq '0307'  &&
278    $casespec->{az}->{upper} eq '0307' &&
279    $casespec->{az}->{condition} eq 'az AFTER_i NOT_MORE_ABOVE');