This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
07c572c90a9af4333ce8e20a2e90a682ef672b3d
[perl5.git] / lib / UnicodeCD.t
1 use UnicodeCD;
2
3 use Test;
4 use strict;
5
6 BEGIN { plan tests => 111 };
7
8 use UnicodeCD 'charinfo';
9
10 my $charinfo;
11
12 $charinfo = charinfo(0x41);
13
14 ok($charinfo->{code},           '0041');
15 ok($charinfo->{name},           'LATIN CAPITAL LETTER A');
16 ok($charinfo->{category},       'Lu');
17 ok($charinfo->{combining},      '0');
18 ok($charinfo->{bidi},           'L');
19 ok($charinfo->{decomposition},  '');
20 ok($charinfo->{decimal},        '');
21 ok($charinfo->{digit},          '');
22 ok($charinfo->{numeric},        '');
23 ok($charinfo->{mirrored},       'N');
24 ok($charinfo->{unicode10},      '');
25 ok($charinfo->{comment},        '');
26 ok($charinfo->{upper},          '');
27 ok($charinfo->{lower},          '0061');
28 ok($charinfo->{title},          '');
29 ok($charinfo->{block},          'Basic Latin');
30 ok($charinfo->{script},         'Latin');
31
32 $charinfo = charinfo(0x100);
33
34 ok($charinfo->{code},           '0100');
35 ok($charinfo->{name},           'LATIN CAPITAL LETTER A WITH MACRON');
36 ok($charinfo->{category},       'Lu');
37 ok($charinfo->{combining},      '0');
38 ok($charinfo->{bidi},           'L');
39 ok($charinfo->{decomposition},  '0041 0304');
40 ok($charinfo->{decimal},        '');
41 ok($charinfo->{digit},          '');
42 ok($charinfo->{numeric},        '');
43 ok($charinfo->{mirrored},       'N');
44 ok($charinfo->{unicode10},      'LATIN CAPITAL LETTER A MACRON');
45 ok($charinfo->{comment},        '');
46 ok($charinfo->{upper},          '');
47 ok($charinfo->{lower},          '0101');
48 ok($charinfo->{title},          '');
49 ok($charinfo->{block},          'Latin Extended-A');
50 ok($charinfo->{script},         'Latin');
51
52 # 0x0590 is in the Hebrew block but unused.
53
54 $charinfo = charinfo(0x590);
55
56 ok($charinfo->{code},          undef);
57 ok($charinfo->{name},          undef);
58 ok($charinfo->{category},      undef);
59 ok($charinfo->{combining},     undef);
60 ok($charinfo->{bidi},          undef);
61 ok($charinfo->{decomposition}, undef);
62 ok($charinfo->{decimal},       undef);
63 ok($charinfo->{digit},         undef);
64 ok($charinfo->{numeric},       undef);
65 ok($charinfo->{mirrored},      undef);
66 ok($charinfo->{unicode10},     undef);
67 ok($charinfo->{comment},       undef);
68 ok($charinfo->{upper},         undef);
69 ok($charinfo->{lower},         undef);
70 ok($charinfo->{title},         undef);
71 ok($charinfo->{block},         undef);
72 ok($charinfo->{script},        undef);
73
74 # 0x05d0 is in the Hebrew block and used.
75
76 $charinfo = charinfo(0x5d0);
77
78 ok($charinfo->{code},           '05D0');
79 ok($charinfo->{name},           'HEBREW LETTER ALEF');
80 ok($charinfo->{category},       'Lo');
81 ok($charinfo->{combining},      '0');
82 ok($charinfo->{bidi},           'R');
83 ok($charinfo->{decomposition},  '');
84 ok($charinfo->{decimal},        '');
85 ok($charinfo->{digit},          '');
86 ok($charinfo->{numeric},        '');
87 ok($charinfo->{mirrored},       'N');
88 ok($charinfo->{unicode10},      '');
89 ok($charinfo->{comment},        '');
90 ok($charinfo->{upper},          '');
91 ok($charinfo->{lower},          '');
92 ok($charinfo->{title},          '');
93 ok($charinfo->{block},          'Hebrew');
94 ok($charinfo->{script},         'Hebrew');
95
96 use UnicodeCD qw(charblock charscript);
97
98 # 0x0590 is in the Hebrew block but unused.
99
100 ok(charblock(0x590),          'Hebrew');
101 ok(charscript(0x590),         undef);
102
103 $charinfo = charinfo(0xbe);
104
105 ok($charinfo->{code},           '00BE');
106 ok($charinfo->{name},           'VULGAR FRACTION THREE QUARTERS');
107 ok($charinfo->{category},       'No');
108 ok($charinfo->{combining},      '0');
109 ok($charinfo->{bidi},           'ON');
110 ok($charinfo->{decomposition},  '<fraction> 0033 2044 0034');
111 ok($charinfo->{decimal},        '');
112 ok($charinfo->{digit},          '');
113 ok($charinfo->{numeric},        '3/4');
114 ok($charinfo->{mirrored},       'N');
115 ok($charinfo->{unicode10},      'FRACTION THREE QUARTERS');
116 ok($charinfo->{comment},        '');
117 ok($charinfo->{upper},          '');
118 ok($charinfo->{lower},          '');
119 ok($charinfo->{title},          '');
120 ok($charinfo->{block},          'Latin-1 Supplement');
121 ok($charinfo->{script},         undef);
122
123 use UnicodeCD qw(charblocks charscripts);
124
125 my $charblocks = charblocks();
126
127 ok(exists $charblocks->{Thai});
128 ok($charblocks->{Thai}->[0]->[0], hex('0e00'));
129 ok(!exists $charblocks->{PigLatin});
130
131 my $charscripts = charscripts();
132
133 ok(exists $charscripts->{Armenian});
134 ok($charscripts->{Armenian}->[0]->[0], hex('0531'));
135 ok(!exists $charscripts->{PigLatin});
136
137 my $charscript;
138
139 $charscript = charscript("12ab");
140 ok($charscript, 'Ethiopic');
141
142 $charscript = charscript("0x12ab");
143 ok($charscript, 'Ethiopic');
144
145 $charscript = charscript("U+12ab");
146 ok($charscript, 'Ethiopic');
147
148 my $ranges;
149
150 $ranges = charscript('Ogham');
151 ok($ranges->[0]->[0], hex('1681'));
152 ok($ranges->[0]->[1], hex('169a'));
153
154 use UnicodeCD qw(charinrange);
155
156 $ranges = charscript('Cherokee');
157 ok(!charinrange($ranges, "139f"));
158 ok( charinrange($ranges, "13a0"));
159 ok( charinrange($ranges, "13f4"));
160 ok(!charinrange($ranges, "13f5"));
161
162 ok(UnicodeCD::UnicodeVersion, 3.1);
163
164 use UnicodeCD qw(compexcl);
165
166 ok(!compexcl(0x0100));
167 ok( compexcl(0x0958));
168
169 use UnicodeCD qw(casefold);
170
171 my $casefold;
172
173 $casefold = casefold(0x41);
174
175 ok($casefold->{code} eq '0041' &&
176    $casefold->{status} eq 'C'  &&
177    $casefold->{mapping} eq '0061');
178
179 $casefold = casefold(0xdf);
180
181 ok($casefold->{code} eq '00DF' &&
182    $casefold->{status} eq 'F'  &&
183    $casefold->{mapping} eq '0073 0073');
184
185 ok(!casefold(0x20));
186
187 use UnicodeCD qw(casespec);
188
189 my $casespec;
190
191 ok(!casespec(0x41));
192
193 $casespec = casespec(0xdf);
194
195 ok($casespec->{code} eq '00DF' &&
196    $casespec->{lower} eq '00DF'  &&
197    $casespec->{title} eq '0053 0073'  &&
198    $casespec->{upper} eq '0053 0053' &&
199    $casespec->{condition} eq undef);
200
201 $casespec = casespec(0x307);
202
203 ok($casespec->{code} eq '0307' &&
204    $casespec->{lower} eq '0307'  &&
205    $casespec->{title} eq ''  &&
206    $casespec->{upper} eq '' &&
207    $casespec->{condition} eq 'lt AFTER_i');