4 print "1..0 # Skip: EBCDIC\n";
9 require Config; import Config;
10 if ($Config{'extensions'} !~ /\bStorable\b/) {
11 print "1..0 # Skip: Storable was not built; Unicode::UCD uses Storable\n";
20 use Unicode::UCD 'charinfo';
26 is(charinfo(0x110000), undef, "Verify charinfo() of non-unicode is undef");
28 $charinfo = charinfo(0); # Null is often problematic, so test it.
30 is($charinfo->{code}, '0000', '<control>');
31 is($charinfo->{name}, '<control>');
32 is($charinfo->{category}, 'Cc');
33 is($charinfo->{combining}, '0');
34 is($charinfo->{bidi}, 'BN');
35 is($charinfo->{decomposition}, '');
36 is($charinfo->{decimal}, '');
37 is($charinfo->{digit}, '');
38 is($charinfo->{numeric}, '');
39 is($charinfo->{mirrored}, 'N');
40 is($charinfo->{unicode10}, 'NULL');
41 is($charinfo->{comment}, '');
42 is($charinfo->{upper}, '');
43 is($charinfo->{lower}, '');
44 is($charinfo->{title}, '');
45 is($charinfo->{block}, 'Basic Latin');
46 is($charinfo->{script}, 'Common');
48 $charinfo = charinfo(0x41);
50 is($charinfo->{code}, '0041', 'LATIN CAPITAL LETTER A');
51 is($charinfo->{name}, 'LATIN CAPITAL LETTER A');
52 is($charinfo->{category}, 'Lu');
53 is($charinfo->{combining}, '0');
54 is($charinfo->{bidi}, 'L');
55 is($charinfo->{decomposition}, '');
56 is($charinfo->{decimal}, '');
57 is($charinfo->{digit}, '');
58 is($charinfo->{numeric}, '');
59 is($charinfo->{mirrored}, 'N');
60 is($charinfo->{unicode10}, '');
61 is($charinfo->{comment}, '');
62 is($charinfo->{upper}, '');
63 is($charinfo->{lower}, '0061');
64 is($charinfo->{title}, '');
65 is($charinfo->{block}, 'Basic Latin');
66 is($charinfo->{script}, 'Latin');
68 $charinfo = charinfo(0x100);
70 is($charinfo->{code}, '0100', 'LATIN CAPITAL LETTER A WITH MACRON');
71 is($charinfo->{name}, 'LATIN CAPITAL LETTER A WITH MACRON');
72 is($charinfo->{category}, 'Lu');
73 is($charinfo->{combining}, '0');
74 is($charinfo->{bidi}, 'L');
75 is($charinfo->{decomposition}, '0041 0304');
76 is($charinfo->{decimal}, '');
77 is($charinfo->{digit}, '');
78 is($charinfo->{numeric}, '');
79 is($charinfo->{mirrored}, 'N');
80 is($charinfo->{unicode10}, 'LATIN CAPITAL LETTER A MACRON');
81 is($charinfo->{comment}, '');
82 is($charinfo->{upper}, '');
83 is($charinfo->{lower}, '0101');
84 is($charinfo->{title}, '');
85 is($charinfo->{block}, 'Latin Extended-A');
86 is($charinfo->{script}, 'Latin');
88 # 0x0590 is in the Hebrew block but unused.
90 $charinfo = charinfo(0x590);
92 is($charinfo->{code}, undef, '0x0590 - unused Hebrew');
93 is($charinfo->{name}, undef);
94 is($charinfo->{category}, undef);
95 is($charinfo->{combining}, undef);
96 is($charinfo->{bidi}, undef);
97 is($charinfo->{decomposition}, undef);
98 is($charinfo->{decimal}, undef);
99 is($charinfo->{digit}, undef);
100 is($charinfo->{numeric}, undef);
101 is($charinfo->{mirrored}, undef);
102 is($charinfo->{unicode10}, undef);
103 is($charinfo->{comment}, undef);
104 is($charinfo->{upper}, undef);
105 is($charinfo->{lower}, undef);
106 is($charinfo->{title}, undef);
107 is($charinfo->{block}, undef);
108 is($charinfo->{script}, undef);
110 # 0x05d0 is in the Hebrew block and used.
112 $charinfo = charinfo(0x5d0);
114 is($charinfo->{code}, '05D0', '05D0 - used Hebrew');
115 is($charinfo->{name}, 'HEBREW LETTER ALEF');
116 is($charinfo->{category}, 'Lo');
117 is($charinfo->{combining}, '0');
118 is($charinfo->{bidi}, 'R');
119 is($charinfo->{decomposition}, '');
120 is($charinfo->{decimal}, '');
121 is($charinfo->{digit}, '');
122 is($charinfo->{numeric}, '');
123 is($charinfo->{mirrored}, 'N');
124 is($charinfo->{unicode10}, '');
125 is($charinfo->{comment}, '');
126 is($charinfo->{upper}, '');
127 is($charinfo->{lower}, '');
128 is($charinfo->{title}, '');
129 is($charinfo->{block}, 'Hebrew');
130 is($charinfo->{script}, 'Hebrew');
132 # An open syllable in Hangul.
134 $charinfo = charinfo(0xAC00);
136 is($charinfo->{code}, 'AC00', 'HANGUL SYLLABLE U+AC00');
137 is($charinfo->{name}, 'HANGUL SYLLABLE GA');
138 is($charinfo->{category}, 'Lo');
139 is($charinfo->{combining}, '0');
140 is($charinfo->{bidi}, 'L');
141 is($charinfo->{decomposition}, '1100 1161');
142 is($charinfo->{decimal}, '');
143 is($charinfo->{digit}, '');
144 is($charinfo->{numeric}, '');
145 is($charinfo->{mirrored}, 'N');
146 is($charinfo->{unicode10}, '');
147 is($charinfo->{comment}, '');
148 is($charinfo->{upper}, '');
149 is($charinfo->{lower}, '');
150 is($charinfo->{title}, '');
151 is($charinfo->{block}, 'Hangul Syllables');
152 is($charinfo->{script}, 'Hangul');
154 # A closed syllable in Hangul.
156 $charinfo = charinfo(0xAE00);
158 is($charinfo->{code}, 'AE00', 'HANGUL SYLLABLE U+AE00');
159 is($charinfo->{name}, 'HANGUL SYLLABLE GEUL');
160 is($charinfo->{category}, 'Lo');
161 is($charinfo->{combining}, '0');
162 is($charinfo->{bidi}, 'L');
163 is($charinfo->{decomposition}, "1100 1173 11AF");
164 is($charinfo->{decimal}, '');
165 is($charinfo->{digit}, '');
166 is($charinfo->{numeric}, '');
167 is($charinfo->{mirrored}, 'N');
168 is($charinfo->{unicode10}, '');
169 is($charinfo->{comment}, '');
170 is($charinfo->{upper}, '');
171 is($charinfo->{lower}, '');
172 is($charinfo->{title}, '');
173 is($charinfo->{block}, 'Hangul Syllables');
174 is($charinfo->{script}, 'Hangul');
176 $charinfo = charinfo(0x1D400);
178 is($charinfo->{code}, '1D400', 'MATHEMATICAL BOLD CAPITAL A');
179 is($charinfo->{name}, 'MATHEMATICAL BOLD CAPITAL A');
180 is($charinfo->{category}, 'Lu');
181 is($charinfo->{combining}, '0');
182 is($charinfo->{bidi}, 'L');
183 is($charinfo->{decomposition}, '<font> 0041');
184 is($charinfo->{decimal}, '');
185 is($charinfo->{digit}, '');
186 is($charinfo->{numeric}, '');
187 is($charinfo->{mirrored}, 'N');
188 is($charinfo->{unicode10}, '');
189 is($charinfo->{comment}, '');
190 is($charinfo->{upper}, '');
191 is($charinfo->{lower}, '');
192 is($charinfo->{title}, '');
193 is($charinfo->{block}, 'Mathematical Alphanumeric Symbols');
194 is($charinfo->{script}, 'Common');
196 $charinfo = charinfo(0x9FBA); #Bug 58428
198 is($charinfo->{code}, '9FBA', 'U+9FBA');
199 is($charinfo->{name}, 'CJK UNIFIED IDEOGRAPH-9FBA');
200 is($charinfo->{category}, 'Lo');
201 is($charinfo->{combining}, '0');
202 is($charinfo->{bidi}, 'L');
203 is($charinfo->{decomposition}, '');
204 is($charinfo->{decimal}, '');
205 is($charinfo->{digit}, '');
206 is($charinfo->{numeric}, '');
207 is($charinfo->{mirrored}, 'N');
208 is($charinfo->{unicode10}, '');
209 is($charinfo->{comment}, '');
210 is($charinfo->{upper}, '');
211 is($charinfo->{lower}, '');
212 is($charinfo->{title}, '');
213 is($charinfo->{block}, 'CJK Unified Ideographs');
214 is($charinfo->{script}, 'Han');
216 use Unicode::UCD qw(charblock charscript);
218 # 0x0590 is in the Hebrew block but unused.
220 is(charblock(0x590), 'Hebrew', '0x0590 - Hebrew unused charblock');
221 is(charscript(0x590), 'Unknown', '0x0590 - Hebrew unused charscript');
222 is(charblock(0x1FFFF), 'No_Block', '0x1FFFF - unused charblock');
224 $charinfo = charinfo(0xbe);
226 is($charinfo->{code}, '00BE', 'VULGAR FRACTION THREE QUARTERS');
227 is($charinfo->{name}, 'VULGAR FRACTION THREE QUARTERS');
228 is($charinfo->{category}, 'No');
229 is($charinfo->{combining}, '0');
230 is($charinfo->{bidi}, 'ON');
231 is($charinfo->{decomposition}, '<fraction> 0033 2044 0034');
232 is($charinfo->{decimal}, '');
233 is($charinfo->{digit}, '');
234 is($charinfo->{numeric}, '3/4');
235 is($charinfo->{mirrored}, 'N');
236 is($charinfo->{unicode10}, 'FRACTION THREE QUARTERS');
237 is($charinfo->{comment}, '');
238 is($charinfo->{upper}, '');
239 is($charinfo->{lower}, '');
240 is($charinfo->{title}, '');
241 is($charinfo->{block}, 'Latin-1 Supplement');
242 is($charinfo->{script}, 'Common');
244 # This is to test a case where both simple and full lowercases exist and
246 $charinfo = charinfo(0x130);
248 is($charinfo->{code}, '0130', 'LATIN CAPITAL LETTER I WITH DOT ABOVE');
249 is($charinfo->{name}, 'LATIN CAPITAL LETTER I WITH DOT ABOVE');
250 is($charinfo->{category}, 'Lu');
251 is($charinfo->{combining}, '0');
252 is($charinfo->{bidi}, 'L');
253 is($charinfo->{decomposition}, '0049 0307');
254 is($charinfo->{decimal}, '');
255 is($charinfo->{digit}, '');
256 is($charinfo->{numeric}, '');
257 is($charinfo->{mirrored}, 'N');
258 is($charinfo->{unicode10}, 'LATIN CAPITAL LETTER I DOT');
259 is($charinfo->{comment}, '');
260 is($charinfo->{upper}, '');
261 is($charinfo->{lower}, '0069');
262 is($charinfo->{title}, '');
263 is($charinfo->{block}, 'Latin Extended-A');
264 is($charinfo->{script}, 'Latin');
266 # This is to test a case where both simple and full uppercases exist and
268 $charinfo = charinfo(0x1F80);
270 is($charinfo->{code}, '1F80', 'GREEK SMALL LETTER ALPHA WITH PSILI AND YPOGEGRAMMENI');
271 is($charinfo->{name}, 'GREEK SMALL LETTER ALPHA WITH PSILI AND YPOGEGRAMMENI');
272 is($charinfo->{category}, 'Ll');
273 is($charinfo->{combining}, '0');
274 is($charinfo->{bidi}, 'L');
275 is($charinfo->{decomposition}, '1F00 0345');
276 is($charinfo->{decimal}, '');
277 is($charinfo->{digit}, '');
278 is($charinfo->{numeric}, '');
279 is($charinfo->{mirrored}, 'N');
280 is($charinfo->{unicode10}, '');
281 is($charinfo->{comment}, '');
282 is($charinfo->{upper}, '1F88');
283 is($charinfo->{lower}, '');
284 is($charinfo->{title}, '1F88');
285 is($charinfo->{block}, 'Greek Extended');
286 is($charinfo->{script}, 'Greek');
288 use Unicode::UCD qw(charblocks charscripts);
290 my $charblocks = charblocks();
292 ok(exists $charblocks->{Thai}, 'Thai charblock exists');
293 is($charblocks->{Thai}->[0]->[0], hex('0e00'));
294 ok(!exists $charblocks->{PigLatin}, 'PigLatin charblock does not exist');
296 my $charscripts = charscripts();
298 ok(exists $charscripts->{Armenian}, 'Armenian charscript exists');
299 is($charscripts->{Armenian}->[0]->[0], hex('0531'));
300 ok(!exists $charscripts->{PigLatin}, 'PigLatin charscript does not exist');
304 $charscript = charscript("12ab");
305 is($charscript, 'Ethiopic', 'Ethiopic charscript');
307 $charscript = charscript("0x12ab");
308 is($charscript, 'Ethiopic');
310 $charscript = charscript("U+12ab");
311 is($charscript, 'Ethiopic');
315 $ranges = charscript('Ogham');
316 is($ranges->[0]->[0], hex('1680'), 'Ogham charscript');
317 is($ranges->[0]->[1], hex('169C'));
319 use Unicode::UCD qw(charinrange);
321 $ranges = charscript('Cherokee');
322 ok(!charinrange($ranges, "139f"), 'Cherokee charscript');
323 ok( charinrange($ranges, "13a0"));
324 ok( charinrange($ranges, "13f4"));
325 ok(!charinrange($ranges, "13f5"));
327 use Unicode::UCD qw(general_categories);
329 my $gc = general_categories();
331 ok(exists $gc->{L}, 'has L');
332 is($gc->{L}, 'Letter', 'L is Letter');
333 is($gc->{Lu}, 'UppercaseLetter', 'Lu is UppercaseLetter');
335 use Unicode::UCD qw(bidi_types);
337 my $bt = bidi_types();
339 ok(exists $bt->{L}, 'has L');
340 is($bt->{L}, 'Left-to-Right', 'L is Left-to-Right');
341 is($bt->{AL}, 'Right-to-Left Arabic', 'AL is Right-to-Left Arabic');
343 # If this fails, then maybe one should look at the Unicode changes to see
344 # what else might need to be updated.
345 is(Unicode::UCD::UnicodeVersion, '6.1.0', 'UnicodeVersion');
347 use Unicode::UCD qw(compexcl);
349 ok(!compexcl(0x0100), 'compexcl');
350 ok(!compexcl(0xD801), 'compexcl of surrogate');
351 ok(!compexcl(0x110000), 'compexcl of non-Unicode code point');
352 ok( compexcl(0x0958));
354 use Unicode::UCD qw(casefold);
358 $casefold = casefold(0x41);
360 is($casefold->{code}, '0041', 'casefold 0x41 code');
361 is($casefold->{status}, 'C', 'casefold 0x41 status');
362 is($casefold->{mapping}, '0061', 'casefold 0x41 mapping');
363 is($casefold->{full}, '0061', 'casefold 0x41 full');
364 is($casefold->{simple}, '0061', 'casefold 0x41 simple');
365 is($casefold->{turkic}, "", 'casefold 0x41 turkic');
367 $casefold = casefold(0xdf);
369 is($casefold->{code}, '00DF', 'casefold 0xDF code');
370 is($casefold->{status}, 'F', 'casefold 0xDF status');
371 is($casefold->{mapping}, '0073 0073', 'casefold 0xDF mapping');
372 is($casefold->{full}, '0073 0073', 'casefold 0xDF full');
373 is($casefold->{simple}, "", 'casefold 0xDF simple');
374 is($casefold->{turkic}, "", 'casefold 0xDF turkic');
376 # Do different tests depending on if version <= 3.1, or not.
377 (my $version = Unicode::UCD::UnicodeVersion) =~ /^(\d+)\.(\d+)/;
378 if (defined $1 && ($1 <= 2 || $1 == 3 && defined $2 && $2 <= 1)) {
379 $casefold = casefold(0x130);
381 is($casefold->{code}, '0130', 'casefold 0x130 code');
382 is($casefold->{status}, 'I' , 'casefold 0x130 status');
383 is($casefold->{mapping}, '0069', 'casefold 0x130 mapping');
384 is($casefold->{full}, '0069', 'casefold 0x130 full');
385 is($casefold->{simple}, "0069", 'casefold 0x130 simple');
386 is($casefold->{turkic}, "0069", 'casefold 0x130 turkic');
388 $casefold = casefold(0x131);
390 is($casefold->{code}, '0131', 'casefold 0x131 code');
391 is($casefold->{status}, 'I' , 'casefold 0x131 status');
392 is($casefold->{mapping}, '0069', 'casefold 0x131 mapping');
393 is($casefold->{full}, '0069', 'casefold 0x131 full');
394 is($casefold->{simple}, "0069", 'casefold 0x131 simple');
395 is($casefold->{turkic}, "0069", 'casefold 0x131 turkic');
397 $casefold = casefold(0x49);
399 is($casefold->{code}, '0049', 'casefold 0x49 code');
400 is($casefold->{status}, 'C' , 'casefold 0x49 status');
401 is($casefold->{mapping}, '0069', 'casefold 0x49 mapping');
402 is($casefold->{full}, '0069', 'casefold 0x49 full');
403 is($casefold->{simple}, "0069", 'casefold 0x49 simple');
404 is($casefold->{turkic}, "0131", 'casefold 0x49 turkic');
406 $casefold = casefold(0x130);
408 is($casefold->{code}, '0130', 'casefold 0x130 code');
409 is($casefold->{status}, 'F' , 'casefold 0x130 status');
410 is($casefold->{mapping}, '0069 0307', 'casefold 0x130 mapping');
411 is($casefold->{full}, '0069 0307', 'casefold 0x130 full');
412 is($casefold->{simple}, "", 'casefold 0x130 simple');
413 is($casefold->{turkic}, "0069", 'casefold 0x130 turkic');
416 $casefold = casefold(0x1F88);
418 is($casefold->{code}, '1F88', 'casefold 0x1F88 code');
419 is($casefold->{status}, 'S' , 'casefold 0x1F88 status');
420 is($casefold->{mapping}, '1F80', 'casefold 0x1F88 mapping');
421 is($casefold->{full}, '1F00 03B9', 'casefold 0x1F88 full');
422 is($casefold->{simple}, '1F80', 'casefold 0x1F88 simple');
423 is($casefold->{turkic}, "", 'casefold 0x1F88 turkic');
427 use Unicode::UCD qw(casespec);
433 $casespec = casespec(0xdf);
435 ok($casespec->{code} eq '00DF' &&
436 $casespec->{lower} eq '00DF' &&
437 $casespec->{title} eq '0053 0073' &&
438 $casespec->{upper} eq '0053 0053' &&
439 !defined $casespec->{condition}, 'casespec 0xDF');
441 $casespec = casespec(0x307);
443 ok($casespec->{az}->{code} eq '0307' &&
444 !defined $casespec->{az}->{lower} &&
445 $casespec->{az}->{title} eq '0307' &&
446 $casespec->{az}->{upper} eq '0307' &&
447 $casespec->{az}->{condition} eq 'az After_I',
450 # perl #7305 UnicodeCD::compexcl is weird
452 for (1) {my $a=compexcl $_}
453 ok(1, 'compexcl read-only $_: perl #7305');
454 map {compexcl $_} %{{1=>2}};
455 ok(1, 'compexcl read-only hash: perl #7305');
457 is(Unicode::UCD::_getcode('123'), 123, "_getcode(123)");
458 is(Unicode::UCD::_getcode('0123'), 0x123, "_getcode(0123)");
459 is(Unicode::UCD::_getcode('0x123'), 0x123, "_getcode(0x123)");
460 is(Unicode::UCD::_getcode('0X123'), 0x123, "_getcode(0X123)");
461 is(Unicode::UCD::_getcode('U+123'), 0x123, "_getcode(U+123)");
462 is(Unicode::UCD::_getcode('u+123'), 0x123, "_getcode(u+123)");
463 is(Unicode::UCD::_getcode('U+1234'), 0x1234, "_getcode(U+1234)");
464 is(Unicode::UCD::_getcode('U+12345'), 0x12345, "_getcode(U+12345)");
465 is(Unicode::UCD::_getcode('123x'), undef, "_getcode(123x)");
466 is(Unicode::UCD::_getcode('x123'), undef, "_getcode(x123)");
467 is(Unicode::UCD::_getcode('0x123x'), undef, "_getcode(x123)");
468 is(Unicode::UCD::_getcode('U+123x'), undef, "_getcode(x123)");
471 my $r1 = charscript('Latin');
473 is($n1, 30, "number of ranges in Latin script (Unicode 6.1.0)");
474 shift @$r1 while @$r1;
475 my $r2 = charscript('Latin');
476 is(@$r2, $n1, "modifying results should not mess up internal caches");
480 is(charinfo(0xdeadbeef), undef, "[perl #23273] warnings in Unicode::UCD");
483 use Unicode::UCD qw(namedseq);
485 is(namedseq("KATAKANA LETTER AINU P"), "\x{31F7}\x{309A}", "namedseq");
486 is(namedseq("KATAKANA LETTER AINU Q"), undef);
487 is(namedseq(), undef);
488 is(namedseq(qw(foo bar)), undef);
489 my @ns = namedseq("KATAKANA LETTER AINU P");
494 is($ns{"KATAKANA LETTER AINU P"}, "\x{31F7}\x{309A}");
498 use Unicode::UCD qw(num);
499 use charnames ":full";
501 is(num("0"), 0, 'Verify num("0") == 0');
502 is(num("98765"), 98765, 'Verify num("98765") == 98765');
503 ok(! defined num("98765\N{FULLWIDTH DIGIT FOUR}"), 'Verify num("98765\N{FULLWIDTH DIGIT FOUR}") isnt defined');
504 is(num("\N{NEW TAI LUE DIGIT TWO}\N{NEW TAI LUE DIGIT ONE}"), 21, 'Verify num("\N{NEW TAI LUE DIGIT TWO}\N{NEW TAI LUE DIGIT ONE}") == 21');
505 ok(! defined num("\N{NEW TAI LUE DIGIT TWO}\N{NEW TAI LUE THAM DIGIT ONE}"), 'Verify num("\N{NEW TAI LUE DIGIT TWO}\N{NEW TAI LUE THAM DIGIT ONE}") isnt defined');
506 is(num("\N{CHAM DIGIT ZERO}\N{CHAM DIGIT THREE}"), 3, 'Verify num("\N{CHAM DIGIT ZERO}\N{CHAM DIGIT THREE}") == 3');
507 ok(! defined num("\N{CHAM DIGIT ZERO}\N{JAVANESE DIGIT NINE}"), 'Verify num("\N{CHAM DIGIT ZERO}\N{JAVANESE DIGIT NINE}") isnt defined');
508 is(num("\N{SUPERSCRIPT TWO}"), 2, 'Verify num("\N{SUPERSCRIPT TWO} == 2');
509 is(num("\N{ETHIOPIC NUMBER TEN THOUSAND}"), 10000, 'Verify num("\N{ETHIOPIC NUMBER TEN THOUSAND}") == 10000');
510 is(num("\N{NORTH INDIC FRACTION ONE HALF}"), .5, 'Verify num("\N{NORTH INDIC FRACTION ONE HALF}") == .5');
511 is(num("\N{U+12448}"), 9, 'Verify num("\N{U+12448}") == 9');
512 is(num("\N{U+5146}"), 1000000000000, 'Verify num("\N{U+5146}") == 1000000000000');
514 # Create a user-defined property
520 use Unicode::UCD qw(prop_aliases);
522 is(prop_aliases(undef), undef, "prop_aliases(undef) returns <undef>");
523 is(prop_aliases("unknown property"), undef,
524 "prop_aliases(<unknown property>) returns <undef>");
525 is(prop_aliases("InKana"), undef,
526 "prop_aliases(<user-defined property>) returns <undef>");
527 is(prop_aliases("Perl_Decomposition_Mapping"), undef, "prop_aliases('Perl_Decomposition_Mapping') returns <undef> since internal-Perl-only");
528 is(prop_aliases("Perl_Charnames"), undef,
529 "prop_aliases('Perl_Charnames') returns <undef> since internal-Perl-only");
530 is(prop_aliases("isgc"), undef,
531 "prop_aliases('isgc') returns <undef> since is not covered Perl extension");
532 is(prop_aliases("Is_Is_Any"), undef,
533 "prop_aliases('Is_Is_Any') returns <undef> since two is's");
535 require 'utf8_heavy.pl';
536 require "unicore/Heavy.pl";
538 # Keys are lists of properties. Values are defined if have been tested.
541 # To test for loose matching, add in the characters that are ignored there.
542 my $extra_chars = "-_ ";
544 # The one internal property we accept
545 $props{'Perl_Decimal_Digit'} = 1;
546 my @list = prop_aliases("perldecimaldigit");
548 [ "Perl_Decimal_Digit",
550 ], "prop_aliases('perldecimaldigit') returns Perl_Decimal_Digit as both short and full names");
552 # Get the official Unicode property name synonyms and test them.
553 open my $props, "<", "../lib/unicore/PropertyAliases.txt"
554 or die "Can't open Unicode PropertyAliases.txt";
557 s/\s*#.*//; # Remove comments
558 next if /^\s* $/x; # Ignore empty and comment lines
561 my $count = 0; # 0th field in line is short name; 1th is long name
565 foreach my $alias (split /\s*;\s*/) { # Fields are separated by
567 # Add in the characters that are supposed to be ignored, to test loose
568 # matching, which the tested function does on all inputs.
569 my $mod_name = "$extra_chars$alias";
571 my $loose = &utf8::_loose_name(lc $alias);
573 # Indicate we have tested this.
576 my @all_names = prop_aliases($mod_name);
577 if (grep { $_ eq $loose } @Unicode::UCD::suppressed_properties) {
578 is(@all_names, 0, "prop_aliases('$mod_name') returns undef since $alias is not installed");
581 elsif (! @all_names) {
582 fail("prop_aliases('$mod_name')");
583 diag("'$alias' is unknown to prop_aliases()");
587 if ($count == 0) { # Is short name
589 @names_via_short = prop_aliases($mod_name);
591 # If the 0th test fails, no sense in continuing with the others
592 last unless is($names_via_short[0], $alias,
593 "prop_aliases: '$alias' is the short name for '$mod_name'");
594 $short_name = $alias;
596 elsif ($count == 1) { # Is full name
598 # Some properties have the same short and full name; no sense
599 # repeating the test if the same.
600 if ($alias ne $short_name) {
601 my @names_via_full = prop_aliases($mod_name);
602 is_deeply(\@names_via_full, \@names_via_short, "prop_aliases() returns the same list for both '$short_name' and '$mod_name'");
605 # Tests scalar context
606 is(prop_aliases($short_name), $alias,
607 "prop_aliases: '$alias' is the long name for '$short_name'");
609 else { # Is another alias
610 is_deeply(\@all_names, \@names_via_short, "prop_aliases() returns the same list for both '$short_name' and '$mod_name'");
611 ok((grep { $_ =~ /^$alias$/i } @all_names),
612 "prop_aliases: '$alias' is listed as an alias for '$mod_name'");
619 # Now test anything we can find that wasn't covered by the tests of the
620 # official properties. We have no way of knowing if mktables omitted a Perl
621 # extension or not, but we do the best we can from its generated lists
623 foreach my $alias (keys %utf8::loose_to_file_of) {
624 next if $alias =~ /=/;
625 my $lc_name = lc $alias;
626 my $loose = &utf8::_loose_name($lc_name);
627 next if exists $props{$loose}; # Skip if already tested
629 my $mod_name = "$extra_chars$alias"; # Tests loose matching
630 my @aliases = prop_aliases($mod_name);
631 my $found_it = grep { &utf8::_loose_name(lc $_) eq $lc_name } @aliases;
633 pass("prop_aliases: '$lc_name' is listed as an alias for '$mod_name'");
635 elsif ($lc_name =~ /l[_&]$/) {
637 # These two names are special in that they don't appear in the
638 # returned list because they are discouraged from use. Verify
639 # that they return the same list as a non-discouraged version.
640 my @LC = prop_aliases('Is_LC');
641 is_deeply(\@aliases, \@LC, "prop_aliases: '$lc_name' returns the same list as 'Is_LC'");
644 my $stripped = $lc_name =~ s/^is//;
646 # Could be that the input includes a prefix 'is', which is rarely
647 # returned as an alias, so having successfully stripped it off above,
650 $found_it = grep { &utf8::_loose_name(lc $_) eq $lc_name } @aliases;
653 # If that didn't work, it could be that it's a block, which is always
654 # returned with a leading 'In_' to avoid ambiguity. Try comparing
655 # with that stripped off.
657 $found_it = grep { &utf8::_loose_name(s/^In_(.*)/\L$1/r) eq $lc_name }
659 # Could check that is a real block, but tests for invmap will
660 # likely pickup any errors, since this will be tested there.
661 $lc_name = "in$lc_name" if $found_it; # Change for message below
663 my $message = "prop_aliases: '$lc_name' is listed as an alias for '$mod_name'";
664 ($found_it) ? pass($message) : fail($message);
669 foreach my $alias (keys %utf8::stricter_to_file_of) {
670 if ($alias =~ /=/) { # Only test one case where there is an equals
671 next if $done_equals;
674 my $lc_name = lc $alias;
675 my @list = prop_aliases($alias);
676 if ($alias =~ /^_/) {
677 is(@list, 0, "prop_aliases: '$lc_name' returns an empty list since it is internal_only");
679 elsif ($alias =~ /=/) {
680 is(@list, 0, "prop_aliases: '$lc_name' returns an empty list since is illegal property name");
683 ok((grep { lc $_ eq $lc_name } @list),
684 "prop_aliases: '$lc_name' is listed as an alias for '$alias'");
688 use Unicode::UCD qw(prop_value_aliases);
690 is(prop_value_aliases("unknown property", "unknown value"), undef,
691 "prop_value_aliases(<unknown property>, <unknown value>) returns <undef>");
692 is(prop_value_aliases(undef, undef), undef,
693 "prop_value_aliases(undef, undef) returns <undef>");
694 is((prop_value_aliases("na", "A")), "A", "test that prop_value_aliases returns its input for properties that don't have synonyms");
695 is(prop_value_aliases("isgc", "C"), undef, "prop_value_aliases('isgc', 'C') returns <undef> since is not covered Perl extension");
696 is(prop_value_aliases("gc", "isC"), undef, "prop_value_aliases('gc', 'isC') returns <undef> since is not covered Perl extension");
698 # We have no way of knowing if mktables omitted a Perl extension that it
699 # shouldn't have, but we can check if it omitted an official Unicode property
700 # name synonym. And for those, we can check if the short and full names are
703 my %pva_tested; # List of things already tested.
704 open my $propvalues, "<", "../lib/unicore/PropValueAliases.txt"
705 or die "Can't open Unicode PropValueAliases.txt";
706 while (<$propvalues>) {
707 s/\s*#.*//; # Remove comments
708 next if /^\s* $/x; # Ignore empty and comment lines
711 my @fields = split /\s*;\s*/; # Fields are separated by semi-colons
712 my $prop = shift @fields; # 0th field is the property,
713 my $count = 0; # 0th field in line (after shifting off the property) is
714 # short name; 1th is long name
716 my @names_via_short; # Saves the values between iterations
718 # The property on the lhs of the = is always loosely matched. Add in
719 # characters that are ignored under loose matching to test that
720 my $mod_prop = "$extra_chars$prop";
722 if ($fields[0] eq 'n/a') { # See comments in input file, essentially
723 # means full name and short name are identical
724 $fields[0] = $fields[1];
726 elsif ($fields[0] ne $fields[1]
727 && &utf8::_loose_name(lc $fields[0])
728 eq &utf8::_loose_name(lc $fields[1])
729 && $fields[1] !~ /[[:upper:]]/)
731 # Also, there is a bug in the file in which "n/a" is omitted, and
732 # the two fields are identical except for case, and the full name
733 # is all lower case. Copy the "short" name unto the full one to
734 # give it some upper case.
736 $fields[1] = $fields[0];
739 # The ccc property in the file is special; has an extra numeric field
740 # (0th), which should go at the end, since we use the next two fields as
741 # the short and full names, respectively. See comments in input file.
742 splice (@fields, 0, 0, splice(@fields, 1, 2)) if $prop eq 'ccc';
744 my $loose_prop = &utf8::_loose_name(lc $prop);
745 my $suppressed = grep { $_ eq $loose_prop }
746 @Unicode::UCD::suppressed_properties;
747 foreach my $value (@fields) {
749 is(prop_value_aliases($prop, $value), undef, "prop_value_aliases('$prop', '$value') returns undef for suppressed property $prop");
752 elsif (grep { $_ eq ("$loose_prop=" . &utf8::_loose_name(lc $value)) } @Unicode::UCD::suppressed_properties) {
753 is(prop_value_aliases($prop, $value), undef, "prop_value_aliases('$prop', '$value') returns undef for suppressed property $prop=$value");
757 # Add in test for loose matching.
758 my $mod_value = "$extra_chars$value";
760 # If the value is a number, optionally negative, including a floating
761 # point or rational numer, it should be only strictly matched, so the
762 # loose matching should fail.
763 if ($value =~ / ^ -? \d+ (?: [\/.] \d+ )? $ /x) {
764 is(prop_value_aliases($mod_prop, $mod_value), undef, "prop_value_aliases('$mod_prop', '$mod_value') returns undef because '$mod_value' should be strictly matched");
766 # And reset so below tests just the strict matching.
772 @names_via_short = prop_value_aliases($mod_prop, $mod_value);
774 # If the 0th test fails, no sense in continuing with the others
775 last unless is($names_via_short[0], $value, "prop_value_aliases: In '$prop', '$value' is the short name for '$mod_value'");
776 $short_name = $value;
778 elsif ($count == 1) {
780 # Some properties have the same short and full name; no sense
781 # repeating the test if the same.
782 if ($value ne $short_name) {
784 prop_value_aliases($mod_prop, $mod_value);
785 is_deeply(\@names_via_full, \@names_via_short, "In '$prop', prop_value_aliases() returns the same list for both '$short_name' and '$mod_value'");
788 # Tests scalar context
789 is(prop_value_aliases($prop, $short_name), $value, "'$value' is the long name for prop_value_aliases('$prop', '$short_name')");
792 my @all_names = prop_value_aliases($mod_prop, $mod_value);
793 is_deeply(\@all_names, \@names_via_short, "In '$prop', prop_value_aliases() returns the same list for both '$short_name' and '$mod_value'");
794 ok((grep { &utf8::_loose_name(lc $_) eq &utf8::_loose_name(lc $value) } prop_value_aliases($prop, $short_name)), "'$value' is listed as an alias for prop_value_aliases('$prop', '$short_name')");
797 $pva_tested{&utf8::_loose_name(lc $prop) . "=" . &utf8::_loose_name(lc $value)} = 1;
802 # And test as best we can, the non-official pva's that mktables generates.
803 foreach my $hash (\%utf8::loose_to_file_of, \%utf8::stricter_to_file_of) {
804 foreach my $test (keys %$hash) {
805 next if exists $pva_tested{$test}; # Skip if already tested
807 my ($prop, $value) = split "=", $test;
808 next unless defined $value; # prop_value_aliases() requires an input
811 if ($hash == \%utf8::loose_to_file_of) {
813 # Add extra characters to test loose-match rhs value
814 $mod_value = "$extra_chars$value";
816 else { # Here value is strictly matched.
818 # Extra elements are added by mktables to this hash so that
819 # something like "age=6.0" has a synonym of "age=6". It's not
820 # clear to me (khw) if we should be encouraging those synonyms, so
821 # don't test for them.
822 next if $value !~ /\D/ && exists $hash->{"$prop=$value.0"};
824 # Verify that loose matching fails when only strict is called for.
825 next unless is(prop_value_aliases($prop, "$extra_chars$value"), undef,
826 "prop_value_aliases('$prop', '$extra_chars$value') returns undef since '$value' should be strictly matched"),
828 # Strict matching does allow for underscores between digits. Test
831 while ($mod_value =~ s/(\d)(\d)/$1_$2/g) {}
834 # The lhs property is always loosely matched, so add in extra
835 # characters to test that.
836 my $mod_prop = "$extra_chars$prop";
838 if ($prop eq 'gc' && $value =~ /l[_&]$/) {
839 # These two names are special in that they don't appear in the
840 # returned list because they are discouraged from use. Verify
841 # that they return the same list as a non-discouraged version.
842 my @LC = prop_value_aliases('gc', 'lc');
843 my @l_ = prop_value_aliases($mod_prop, $mod_value);
844 is_deeply(\@l_, \@LC, "prop_value_aliases('$mod_prop', '$mod_value) returns the same list as prop_value_aliases('gc', 'lc')");
847 ok((grep { &utf8::_loose_name(lc $_) eq &utf8::_loose_name(lc $value) }
848 prop_value_aliases($mod_prop, $mod_value)),
849 "'$value' is listed as an alias for prop_value_aliases('$mod_prop', '$mod_value')");
856 no warnings 'once'; # We use some values once from 'required' modules.
858 use Unicode::UCD qw(prop_invlist prop_invmap MAX_CP);
860 # There were some problems with caching interfering with prop_invlist() vs
861 # prop_invmap() on binary properties, and also between the 3 properties where
862 # Perl used the same 'To' name as another property (see utf8_heavy.pl).
863 # So, before testing all of prop_invlist(),
864 # 1) call prop_invmap() to try both orders of these name issues. This uses
865 # up two of the 3 properties; the third will be left so that invlist()
866 # on it gets called before invmap()
867 # 2) call prop_invmap() on a generic binary property, ahead of invlist().
868 # This should test that the caching works in both directions.
870 # These properties are not stable between Unicode versions, but the first few
871 # elements are; just look at the first element to see if are getting the
872 # distinction right. The general inversion map testing below will test the
875 my ($invlist_ref, $invmap_ref, $format, $missing) = prop_invmap($prop);
876 is($format, 'al', "prop_invmap() format of '$prop' is 'al'");
877 is($missing, '0', "prop_invmap() missing of '$prop' is '0'");
878 is($invlist_ref->[1], 0x61, "prop_invmap('$prop') list[1] is 0x61");
879 is($invmap_ref->[1], 0x41, "prop_invmap('$prop') map[1] is 0x41");
882 ($invlist_ref, $invmap_ref, $format, $missing) = prop_invmap($prop);
883 is($format, 's', "prop_invmap() format of '$prop' is 's");
884 is($missing, 'N', "prop_invmap() missing of '$prop' is 'N'");
885 is($invlist_ref->[1], 0x41, "prop_invmap('$prop') list[1] is 0x41");
886 is($invmap_ref->[1], 'Y', "prop_invmap('$prop') map[1] is 'Y'");
889 ($invlist_ref, $invmap_ref, $format, $missing) = prop_invmap($prop);
890 is($format, 's', "prop_invmap() format of '$prop' is 's'");
891 is($missing, 'N', "prop_invmap() missing of '$prop' is 'N'");
892 is($invlist_ref->[1], 0x61, "prop_invmap('$prop') list[1] is 0x61");
893 is($invmap_ref->[1], 'Y', "prop_invmap('$prop') map[1] is 'Y'");
896 ($invlist_ref, $invmap_ref, $format, $missing) = prop_invmap($prop);
897 is($format, 'al', "prop_invmap() format of '$prop' is 'al'");
898 is($missing, '0', "prop_invmap() missing of '$prop' is '0'");
899 is($invlist_ref->[1], 0x41, "prop_invmap('$prop') list[1] is 0x41");
900 is($invmap_ref->[1], 0x61, "prop_invmap('$prop') map[1] is 0x61");
902 # This property is stable and small, so can test all of it
903 $prop = "ASCII_Hex_Digit";
904 ($invlist_ref, $invmap_ref, $format, $missing) = prop_invmap($prop);
905 is($format, 's', "prop_invmap() format of '$prop' is 's'");
906 is($missing, 'N', "prop_invmap() missing of '$prop' is 'N'");
907 is_deeply($invlist_ref, [ 0x0000, 0x0030, 0x003A, 0x0041,
908 0x0047, 0x0061, 0x0067, 0x110000 ],
909 "prop_invmap('$prop') code point list is correct");
910 is_deeply($invmap_ref, [ 'N', 'Y', 'N', 'Y', 'N', 'Y', 'N', 'N' ] ,
911 "prop_invmap('$prop') map list is correct");
913 is(prop_invlist("Unknown property"), undef, "prop_invlist(<Unknown property>) returns undef");
914 is(prop_invlist(undef), undef, "prop_invlist(undef) returns undef");
915 is(prop_invlist("Any"), 2, "prop_invlist('Any') returns the number of elements in scalar context");
916 my @invlist = prop_invlist("Is_Any");
917 is_deeply(\@invlist, [ 0, 0x110000 ], "prop_invlist works on 'Is_' prefixes");
918 is(prop_invlist("Is_Is_Any"), undef, "prop_invlist('Is_Is_Any') returns <undef> since two is's");
920 use Storable qw(dclone);
922 is(prop_invlist("InKana"), undef, "prop_invlist(<user-defined property returns undef>)");
924 # The way both the tests for invlist and invmap work is that they take the
925 # lists returned by the functions and construct from them what the original
926 # file should look like, which are then compared with the file. If they are
927 # identical, the test passes. What this tests isn't that the results are
928 # correct, but that invlist and invmap haven't introduced errors beyond what
929 # are there in the files. As a small hedge against that, test some
930 # prop_invlist() tables fully with the known correct result. We choose
931 # ASCII_Hex_Digit again, as it is stable.
932 @invlist = prop_invlist("AHex");
933 is_deeply(\@invlist, [ 0x0030, 0x003A, 0x0041,
934 0x0047, 0x0061, 0x0067 ],
935 "prop_invlist('AHex') is exactly the expected set of points");
936 @invlist = prop_invlist("AHex=f");
937 is_deeply(\@invlist, [ 0x0000, 0x0030, 0x003A, 0x0041,
938 0x0047, 0x0061, 0x0067 ],
939 "prop_invlist('AHex=f') is exactly the expected set of points");
941 sub fail_with_diff ($$$$) {
942 # For use below to output better messages
943 my ($prop, $official, $constructed, $tested_function_name) = @_;
945 is($constructed, $official, "$tested_function_name('$prop')");
946 diag("Comment out lines " . (__LINE__ - 1) . " through " . (__LINE__ + 1) . " in '$0' on Un*x-like systems to see just the differences. Uses the 'diff' first in your \$PATH");
949 fail("$tested_function_name('$prop')");
952 my $off = File::Temp->new();
954 print $off $official, "\n";
955 close $off || die "Can't close official";
958 my $gend = File::Temp->new();
959 print $gend $constructed, "\n";
960 close $gend || die "Can't close gend";
962 my $diff = File::Temp->new();
963 system("diff $off $gend > $diff");
965 open my $fh, "<", $diff || die "Can't open $diff";
967 diag("In the diff output below '<' marks lines from the filesystem tables;\n'>' are from $tested_function_name()");
973 # Look at everything we think that mktables tells us exists, both loose and
975 foreach my $set_of_tables (\%utf8::stricter_to_file_of, \%utf8::loose_to_file_of)
977 foreach my $table (keys %$set_of_tables) {
980 my ($prop_only, $value) = split "=", $table;
981 if (defined $value) {
983 # If this is to be loose matched, add in characters to test that.
984 if ($set_of_tables == \%utf8::loose_to_file_of) {
985 $value = "$extra_chars$value";
987 else { # Strict match
989 # Verify that loose matching fails when only strict is called
991 next unless is(prop_invlist("$prop_only=$extra_chars$value"), undef, "prop_invlist('$prop_only=$extra_chars$value') returns undef since should be strictly matched");
993 # Strict matching does allow for underscores between digits.
995 while ($value =~ s/(\d)(\d)/$1_$2/g) {}
998 # The property portion in compound form specifications always
1000 $mod_table = "$extra_chars$prop_only = $value";
1002 else { # Single-form.
1004 # Like above, use looose if required, and insert underscores
1005 # between digits if strict.
1006 if ($set_of_tables == \%utf8::loose_to_file_of) {
1007 $mod_table = "$extra_chars$table";
1010 $mod_table = $table;
1011 while ($mod_table =~ s/(\d)(\d)/$1_$2/g) {}
1015 my @tested = prop_invlist($mod_table);
1016 if ($table =~ /^_/) {
1017 is(@tested, 0, "prop_invlist('$mod_table') returns an empty list since is internal-only");
1021 # If we have already tested a property that uses the same file, this
1022 # list should be identical to the one that was tested, and can bypass
1024 my $file = $set_of_tables->{$table};
1025 if (exists $tested_invlist{$file}) {
1026 is_deeply(\@tested, $tested_invlist{$file}, "prop_invlist('$mod_table') gave same results as its name synonym");
1029 $tested_invlist{$file} = dclone \@tested;
1031 # A leading '!' in the file name means that it is to be inverted.
1032 my $invert = $file =~ s/^!//;
1033 my $official = do "unicore/lib/$file.pl";
1035 # Get rid of any trailing space and comments in the file.
1036 $official =~ s/\s*(#.*)?$//mg;
1039 # If we are to test against an inverted file, it is easier to invert
1040 # our array than the file.
1041 # The file only is valid for Unicode code points, while the inversion
1042 # list is valid for all possible code points. Therefore, we must test
1043 # just the Unicode part against the file. Later we will test for
1044 # the non-Unicode part.
1046 my $before_invert; # Saves the pre-inverted table.
1048 $before_invert = dclone \@tested;
1049 if (@tested && $tested[0] == 0) {
1054 if (@tested && $tested[-1] == 0x110000) {
1058 push @tested, 0x110000;
1062 # Now construct a string from the list that should match the file.
1063 # The file gives ranges of code points with starting and ending values
1064 # in hex, like this:
1068 # Our list has even numbered elements start ranges that are in the
1069 # list, and odd ones that aren't in the list. Therefore the odd
1070 # numbered ones are one beyond the end of the previous range, but
1071 # otherwise don't get reflected in the file.
1074 for (; $i < @tested - 1; $i += 2) {
1075 my $start = $tested[$i];
1076 my $end = $tested[$i+1] - 1;
1077 if ($start == $end) {
1078 $tested .= sprintf("%04X\n", $start);
1081 $tested .= sprintf "%04X\t%04X\n", $start, $end;
1085 # As mentioned earlier, the disk files only go up through Unicode,
1086 # whereas the prop_invlist() ones go as high as necessary. The
1087 # comparison is only valid through max Unicode.
1088 if ($i == @tested - 1 && $tested[$i] <= 0x10FFFF) {
1089 $tested .= sprintf("%04X\t10FFFF\n", $tested[$i]);
1092 if ($tested ne $official) {
1093 fail_with_diff($mod_table, $official, $tested, "prop_invlist");
1097 # Here, it matched the table. Now need to check for if it is correct
1098 # for beyond Unicode. First, calculate if is the default table or
1099 # not. This is the same algorithm as used internally in
1100 # prop_invlist(), so if it is wrong there, this test won't catch it.
1101 my $prop = lc $table;
1102 ($prop_only, $table) = split /\s*[:=]\s*/, $prop;
1103 if (defined $table) {
1105 # May have optional prefixed 'is'
1106 $prop = &utf8::_loose_name($prop_only) =~ s/^is//r;
1107 $prop = $utf8::loose_property_name_of{$prop};
1108 $prop .= "=" . &utf8::_loose_name($table);
1111 $prop = &utf8::_loose_name($prop);
1113 my $is_default = exists $Unicode::UCD::loose_defaults{$prop};
1115 @tested = @$before_invert if $invert; # Use the original
1116 if (@tested % 2 == 0) {
1118 # If there are an even number of elements, the final one starts a
1119 # range (going to infinity) of code points that are not in the
1122 fail("prop_invlist('$mod_table')");
1123 diag("default table doesn't goto infinity");
1125 diag Dumper \@tested;
1130 # An odd number of elements means the final one starts a range
1131 # (going to infinity of code points that are in the list.
1132 if (! $is_default) {
1133 fail("prop_invlist('$mod_table')");
1134 diag("non-default table needs to stop in the Unicode range");
1136 diag Dumper \@tested;
1141 pass("prop_invlist('$mod_table')");
1145 # Now test prop_invmap().
1147 @list = prop_invmap("Unknown property");
1148 is (@list, 0, "prop_invmap(<Unknown property>) returns an empty list");
1149 @list = prop_invmap(undef);
1150 is (@list, 0, "prop_invmap(undef) returns an empty list");
1151 ok (! eval "prop_invmap('gc')" && $@ ne "",
1152 "prop_invmap('gc') dies in scalar context");
1153 @list = prop_invmap("_X_Begin");
1154 is (@list, 0, "prop_invmap(<internal property>) returns an empty list");
1155 @list = prop_invmap("InKana");
1156 is(@list, 0, "prop_invmap(<user-defined property returns undef>)");
1157 @list = prop_invmap("Perl_Decomposition_Mapping"), undef,
1158 is(@list, 0, "prop_invmap('Perl_Decomposition_Mapping') returns <undef> since internal-Perl-only");
1159 @list = prop_invmap("Perl_Charnames"), undef,
1160 is(@list, 0, "prop_invmap('Perl_Charnames') returns <undef> since internal-Perl-only");
1161 @list = prop_invmap("Is_Is_Any");
1162 is(@list, 0, "prop_invmap('Is_Is_Any') returns <undef> since two is's");
1164 # The set of properties to test on has already been compiled into %props by
1165 # the prop_aliases() tests.
1169 # Like prop_invlist(), prop_invmap() is tested by comparing the results
1170 # returned by the function with the tables that mktables generates. Some of
1171 # these tables are directly stored as files on disk, in either the unicore or
1172 # unicore/To directories, and most should be listed in the mktables generated
1173 # hash %utf8::loose_property_to_file_of, with a few additional ones that this
1174 # handles specially. For these, the files are read in directly, massaged, and
1175 # compared with what invmap() returns. The SPECIALS hash in some of these
1176 # files overrides values in the main part of the file.
1178 # The other properties are tested indirectly by generating all the possible
1179 # inversion lists for the property, and seeing if those match the inversion
1180 # lists returned by prop_invlist(), which has already been tested.
1183 foreach my $prop (keys %props) {
1184 my $loose_prop = &utf8::_loose_name(lc $prop);
1185 my $suppressed = grep { $_ eq $loose_prop }
1186 @Unicode::UCD::suppressed_properties;
1188 # Find the short and full names that this property goes by
1189 my ($name, $full_name) = prop_aliases($prop);
1191 if (! $suppressed) {
1192 fail("prop_invmap('$prop')");
1193 diag("is unknown to prop_aliases(), and we need it in order to test prop_invmap");
1198 # Normalize the short name, as it is stored in the hashes under the
1199 # normalized version.
1200 $name = &utf8::_loose_name(lc $name);
1202 # Add in the characters that are supposed to be ignored to test loose
1203 # matching, which the tested function applies to all properties
1204 my $mod_prop = "$extra_chars$prop";
1206 my ($invlist_ref, $invmap_ref, $format, $missing) = prop_invmap($mod_prop);
1207 my $return_ref = [ $invlist_ref, $invmap_ref, $format, $missing ];
1209 # If have already tested this property under a different name, merely
1210 # compare the return from now with the saved one from before.
1211 if (exists $tested_invmaps{$name}) {
1212 is_deeply($return_ref, $tested_invmaps{$name}, "prop_invmap('$mod_prop') gave same results as its synonym, '$name'");
1215 $tested_invmaps{$name} = dclone $return_ref;
1217 # If prop_invmap() returned nothing, is ok iff is a property whose file is
1220 if (defined $format) {
1221 fail("prop_invmap('$mod_prop')");
1222 diag("did not return undef for suppressed property $prop");
1226 elsif (!defined $format) {
1227 fail("prop_invmap('$mod_prop')");
1228 diag("'$prop' is unknown to prop_invmap()");
1232 # The two parallel arrays must have the same number of elements.
1233 if (@$invlist_ref != @$invmap_ref) {
1234 fail("prop_invmap('$mod_prop')");
1236 . scalar @$invlist_ref
1237 . " while invmap has "
1238 . scalar @$invmap_ref
1243 # The last element must be for the above-Unicode code points, and must be
1244 # for the default value.
1245 if ($invlist_ref->[-1] != 0x110000) {
1246 fail("prop_invmap('$mod_prop')");
1247 diag("The last inversion list element is not 0x110000");
1250 if ($invmap_ref->[-1] ne $missing) {
1251 fail("prop_invmap('$mod_prop')");
1252 diag("The last inversion list element is '$invmap_ref->[-1]', and should be '$missing'");
1256 if ($name eq 'bmg') { # This one has an atypical $missing
1257 if ($missing ne "") {
1258 fail("prop_invmap('$mod_prop')");
1259 diag("The missings should be \"\"; got '$missing'");
1263 elsif ($format =~ /^ a (?!r) /x) {
1264 if ($full_name eq 'Perl_Decimal_Digit') {
1265 if ($missing ne "") {
1266 fail("prop_invmap('$mod_prop')");
1267 diag("The missings should be \"\"; got '$missing'");
1271 elsif ($missing ne "0") {
1272 fail("prop_invmap('$mod_prop')");
1273 diag("The missings should be '0'; got '$missing'");
1277 elsif ($missing =~ /[<>]/) {
1278 fail("prop_invmap('$mod_prop')");
1279 diag("The missings should NOT be something with <...>'");
1282 # I don't want to hard code in what all the missings should be, so
1283 # those don't get fully tested.
1286 # Certain properties don't have their own files, but must be constructed
1288 my $proxy_prop = $name;
1289 if ($full_name eq 'Present_In') {
1290 $proxy_prop = "age"; # The maps for these two props are identical
1292 elsif ($full_name eq 'Simple_Case_Folding'
1293 || $full_name =~ /Simple_ (.) .*? case_Mapping /x)
1295 if ($full_name eq 'Simple_Case_Folding') {
1299 # We captured the U, L, or T, leading to uc, lc, or tc.
1300 $proxy_prop = lc $1 . "c";
1302 if ($format ne "a") {
1303 fail("prop_invmap('$mod_prop')");
1304 diag("The format should be 'a'; got '$format'");
1312 # Handle the properties that have full disk files for them (except the
1313 # Name property which is structurally enough different that it is handled
1314 # separately below.)
1318 ($base_file = $utf8::loose_property_to_file_of{$proxy_prop})
1319 || exists $utf8::loose_to_file_of{$proxy_prop}
1322 # In the above, blk is done unconditionally, as we need to test that
1323 # the old-style block names are returned, even if mktables has
1324 # generated a file for the new-style; the test for dm comes afterward,
1325 # so that if a file has been generated for it explicitly, we use that
1326 # file (which is valid, unlike blk) instead of the combo
1327 # Decomposition.pl files.
1330 if ($name eq 'blk') {
1332 # The blk property is special. The original file with old block
1333 # names is retained, and the default is to not write out a
1334 # new-name file. What we do is get the old names into a data
1335 # structure, and from that create what the new file would look
1336 # like. $base_file is needed to be defined, just to avoid a
1338 $base_file = "This is a dummy name";
1339 my $blocks_ref = charblocks();
1341 for my $range (sort { $a->[0][0] <=> $b->[0][0] }
1342 values %$blocks_ref)
1344 # Translate the charblocks() data structure to what the file
1346 $official .= sprintf"%04X\t%04X\t%s\n",
1353 $base_file = "Decomposition" if $format eq 'ad';
1355 # Above leaves $base_file undefined only if it came from the hash
1356 # below. This should happen only when it is a binary property
1357 # (and are accessing via a single-form name, like 'In_Latin1'),
1358 # and so it is stored in a different directory than the To ones.
1359 # XXX Currently, the only cases where it is complemented are the
1360 # ones that have no code points. And it works out for these that
1361 # 1) complementing them, and then 2) adding or subtracting the
1362 # initial 0 and final 110000 cancel each other out. But further
1363 # work would be needed in the unlikely event that an inverted
1364 # property comes along without these characteristics
1365 if (!defined $base_file) {
1366 $base_file = $utf8::loose_to_file_of{$proxy_prop};
1367 $is_binary = ($base_file =~ s/^!//) ? -1 : 1;
1368 $base_file = "lib/$base_file";
1372 $file = "unicore/$base_file.pl";
1373 $official = do $file;
1375 # Get rid of any trailing space and comments in the file.
1376 $official =~ s/\s*(#.*)?$//mg;
1378 if ($format eq 'ad') {
1379 my @official = split /\n/, $official;
1381 foreach my $line (@official) {
1382 my ($start, $end, $value)
1383 = $line =~ / ^ (.+?) \t (.*?) \t (.+?)
1384 \s* ( \# .* )? $ /x;
1385 # Decomposition.pl also has the <compatible> types in it,
1386 # which should be removed.
1387 $value =~ s/<.*?> //;
1388 $official .= "$start\t\t$value\n";
1390 # If this is a multi-char range, we turn it into as many
1391 # single character ranges as necessary. This makes things
1394 for my $i (hex($start) + 1 .. hex $end) {
1395 $official .= sprintf "%04X\t\t%s\n", $i, $value;
1403 # If there are any special elements, get a reference to them.
1404 my $swash_name = $utf8::file_to_swash_name{$base_file};
1407 $specials_ref = $utf8::SwashInfo{$swash_name}{'specials_name'};
1408 if ($specials_ref) {
1410 # Convert from the name to the actual reference.
1412 $specials_ref = \%{$specials_ref};
1416 # Certain of the proxy properties have to be adjusted to match the
1418 if ($full_name =~ /^(Case_Folding|(Lower|Title|Upper)case_Mapping)/) {
1420 # Here we have either
1421 # 1) Case_Folding; or
1422 # 2) a proxy that is a full mapping, which means that what the
1423 # real property is is the equivalent simple mapping.
1424 # In both cases, the file will have a standard list containing
1425 # simple mappings (to a single code point), and a specials hash
1426 # which contains all the mappings that are to multiple code
1427 # points. First, extract a list containing all the file's simple
1430 for (split "\n", $official) {
1431 my ($start, $end, $value) = / ^ (.+?) \t (.*?) \t (.+?)
1432 \s* ( \# .* )? $ /x;
1433 $end = $start if $end eq "";
1434 push @list, [ hex $start, hex $end, $value ];
1437 # For these mappings, the file contains all the simple mappings,
1438 # including the ones that are overridden by the specials. These
1439 # need to be removed as the list is for just the full ones.
1441 # Go through any special mappings one by one. They are packed.
1443 foreach my $utf8_cp (sort keys %$specials_ref) {
1444 my $cp = unpack("C0U", $utf8_cp);
1446 # Find the spot in the @list of simple mappings that this
1447 # special applies to; uses a linear search.
1448 while ($i < @list -1 ) {
1449 last if $cp <= $list[$i][1];
1453 # Here $i is such that it points to the first range which ends
1454 # at or above cp, and hence is the only range that could
1455 # possibly contain it.
1457 # If not in this range, no range contains it: nothing to
1459 next if $cp < $list[$i][0];
1461 # Otherwise, remove the existing entry. If it is the first
1462 # element of the range...
1463 if ($cp == $list[$i][0]) {
1465 # ... and there are other elements in the range, just shorten
1466 # the range to exclude this code point.
1467 if ($list[$i][1] > $list[$i][0]) {
1471 # ... but if it is the only element in the range, remove
1474 splice @list, $i, 1;
1477 else { # Is somewhere in the middle of the range
1478 # Split the range into two, excluding this one in the
1480 splice @list, $i, 1,
1481 [ $list[$i][0], $cp - 1, $list[$i][2] ],
1482 [ $cp + 1, $list[$i][1], $list[$i][2] ];
1486 # Here, have gone through all the specials, modifying @list as
1487 # needed. Turn it back into what the file should look like.
1489 for my $element (@list) {
1490 $official .= "\n" if $official;
1491 if ($element->[1] == $element->[0]) {
1492 $official .= sprintf "%04X\t\t%s", $element->[0], $element->[2];
1495 $official .= sprintf "%04X\t%04X\t%s", $element->[0], $element->[1], $element->[2];
1499 elsif ($full_name =~ /Simple_(Case_Folding|(Lower|Title|Upper)case_Mapping)/)
1502 # These properties have everything in the regular array, and the
1503 # specials are superfluous.
1504 undef $specials_ref;
1506 elsif ($name eq 'bmg') {
1508 # For this property, the file is output using hex notation for the
1509 # map, with all ranges equal to length 1. Convert from hex to
1511 my @lines = split "\n", $official;
1512 foreach my $line (@lines) {
1513 my ($code_point, $map) = split "\t\t", $line;
1514 $line = $code_point . "\t\t" . hex $map;
1516 $official = join "\n", @lines;
1519 # Here, in $official, we have what the file looks like, or should like
1520 # if we've had to fix it up. Now take the invmap() output and reverse
1521 # engineer from that what the file should look like. Each iteration
1522 # appends the next line to the running string.
1523 my $tested_map = "";
1525 # Create a copy of the file's specials hash. (It has been undef'd if
1526 # we know it isn't relevant to this property, so if it exists, it's an
1527 # error or is relevant). As we go along, we delete from that copy.
1528 # If a delete fails, or something is left over after we are done,
1530 my %specials = %$specials_ref if $specials_ref;
1532 # The extra -1 is because the final element has been tested above to
1533 # be for anything above Unicode. The file doesn't go that high.
1534 for (my $i = 0; $i < @$invlist_ref - 1; $i++) {
1536 # If the map element is a reference, have to stringify it (but
1537 # don't do so if the format doesn't allow references, so that an
1538 # improper format will generate an error.
1539 if (ref $invmap_ref->[$i]
1540 && ($format eq 'ad' || $format =~ /^ . l /x))
1542 # The stringification depends on the format.
1543 if ($format eq 'sl') {
1545 # At the time of this writing, there are two types of 'sl'
1546 # format One, in Name_Alias, has multiple separate entries
1547 # for each code point; the other, in Script_Extension, is space
1548 # separated. Assume the latter for non-Name_Alias.
1549 if ($full_name ne 'Name_Alias') {
1550 $invmap_ref->[$i] = join " ", @{$invmap_ref->[$i]};
1553 # For Name_Alias, we emulate the file. Entries with
1554 # just one value don't need any changes, but we
1555 # convert the list entries into a series of lines for
1556 # the file, starting with the first name. The
1557 # succeeding entries are on separate lines, with the
1558 # code point repeated for each one and then two tabs,
1559 # then the value. Code at the end of the loop will
1560 # set up the first line with its code point and two
1561 # tabs before the value, just as it does for every
1562 # other property; thus the special handling of the
1564 if (ref $invmap_ref->[$i]) {
1565 my $hex_cp = sprintf("%04X", $invlist_ref->[$i]);
1566 my $concatenated = $invmap_ref->[$i][0];
1567 for (my $j = 1; $j < @{$invmap_ref->[$i]}; $j++) {
1568 $concatenated .= "\n$hex_cp\t\t" . $invmap_ref->[$i][$j];
1570 $invmap_ref->[$i] = $concatenated;
1574 elsif ($format =~ / ^ al e? $/x) {
1576 # For a al property, the stringified result should be in
1577 # the specials hash. The key is the packed code point,
1578 # and the value is the packed map.
1580 if (! defined ($value = delete $specials{pack("C0U", $invlist_ref->[$i]) })) {
1581 fail("prop_invmap('$mod_prop')");
1582 diag(sprintf "There was no specials element for %04X", $invlist_ref->[$i]);
1585 my $packed = pack "U*", @{$invmap_ref->[$i]};
1586 if ($value ne $packed) {
1587 fail("prop_invmap('$mod_prop')");
1588 diag(sprintf "For %04X, expected the mapping to be '$packed', but got '$value'");
1592 # As this doesn't get tested when we later compare with
1593 # the actual file, it could be out of order and we
1595 if (($i > 0 && $invlist_ref->[$i] <= $invlist_ref->[$i-1])
1596 || $invlist_ref->[$i] >= $invlist_ref->[$i+1])
1598 fail("prop_invmap('$mod_prop')");
1599 diag(sprintf "Range beginning at %04X is out-of-order.", $invlist_ref->[$i]);
1604 elsif ($format eq 'ad') {
1606 # The decomposition mapping file has the code points as
1607 # a string of space-separated hex constants.
1608 $invmap_ref->[$i] = join " ", map { sprintf "%04X", $_ } @{$invmap_ref->[$i]};
1611 fail("prop_invmap('$mod_prop')");
1612 diag("Can't handle format '$format'");
1616 elsif ($format eq 'ad' || $format eq 'ale') {
1618 # The numerics in the returned map are stored as adjusted
1619 # decimal integers. The defaults are 0, and don't appear in
1620 # $official, and are excluded later, but the elements must be
1621 # converted back to their hex values before comparing with
1622 # $official, as these files, for backwards compatibility, are
1623 # not stored as adjusted. (There currently is only one ale
1624 # property, nfkccf. If that changed this would also have to.)
1625 if ($invmap_ref->[$i] =~ / ^ -? \d+ $ /x
1626 && $invmap_ref->[$i] != 0)
1628 my $next = $invmap_ref->[$i] + 1;
1629 $invmap_ref->[$i] = sprintf("%04X", $invmap_ref->[$i]);
1631 # If there are other elements in this range they need to
1632 # be adjusted; they must individually be re-mapped. Do
1633 # this by splicing in a new element into the list and the
1634 # map containing the remainder of the range. Next time
1635 # through we will look at that (possibly splicing again
1636 # until the whole range is processed).
1637 if ($invlist_ref->[$i+1] > $invlist_ref->[$i] + 1) {
1638 splice @$invlist_ref, $i+1, 0,
1639 $invlist_ref->[$i] + 1;
1640 splice @$invmap_ref, $i+1, 0, $next;
1643 if ($format eq 'ale' && $invmap_ref->[$i] eq "") {
1645 # ale properties have maps to the empty string that also
1646 # should be in the specials hash, with the key the packed
1647 # code point, and the map just empty.
1649 if (! defined ($value = delete $specials{pack("C0U", $invlist_ref->[$i]) })) {
1650 fail("prop_invmap('$mod_prop')");
1651 diag(sprintf "There was no specials element for %04X", $invlist_ref->[$i]);
1655 fail("prop_invmap('$mod_prop')");
1656 diag(sprintf "For %04X, expected the mapping to be \"\", but got '$value'", $invlist_ref->[$i]);
1660 # As this doesn't get tested when we later compare with
1661 # the actual file, it could be out of order and we
1663 if (($i > 0 && $invlist_ref->[$i] <= $invlist_ref->[$i-1])
1664 || $invlist_ref->[$i] >= $invlist_ref->[$i+1])
1666 fail("prop_invmap('$mod_prop')");
1667 diag(sprintf "Range beginning at %04X is out-of-order.", $invlist_ref->[$i]);
1673 elsif ($is_binary) { # These binary files don't have an explicit Y
1674 $invmap_ref->[$i] =~ s/Y//;
1677 # The file doesn't include entries that map to $missing, so don't
1678 # include it in the built-up string. But make sure that it is in
1679 # the correct order in the input.
1680 if ($invmap_ref->[$i] eq $missing) {
1681 if (($i > 0 && $invlist_ref->[$i] <= $invlist_ref->[$i-1])
1682 || $invlist_ref->[$i] >= $invlist_ref->[$i+1])
1684 fail("prop_invmap('$mod_prop')");
1685 diag(sprintf "Range beginning at %04X is out-of-order.", $invlist_ref->[$i]);
1691 # The ad property has one entry which isn't in the file.
1692 # Ignore it, but make sure it is in order.
1694 && $invmap_ref->[$i] eq '<hangul syllable>'
1695 && $invlist_ref->[$i] == 0xAC00)
1697 if (($i > 0 && $invlist_ref->[$i] <= $invlist_ref->[$i-1])
1698 || $invlist_ref->[$i] >= $invlist_ref->[$i+1])
1700 fail("prop_invmap('$mod_prop')");
1701 diag(sprintf "Range beginning at %04X is out-of-order.", $invlist_ref->[$i]);
1707 # Finally have figured out what the map column in the file should
1708 # be. Append the line to the running string.
1709 my $start = $invlist_ref->[$i];
1710 my $end = $invlist_ref->[$i+1] - 1;
1711 $end = ($start == $end) ? "" : sprintf("%04X", $end);
1712 if ($invmap_ref->[$i] ne "") {
1713 $tested_map .= sprintf "%04X\t%s\t%s\n", $start, $end, $invmap_ref->[$i];
1715 elsif ($end ne "") {
1716 $tested_map .= sprintf "%04X\t%s\n", $start, $end;
1719 $tested_map .= sprintf "%04X\n", $start;
1721 } # End of looping over all elements.
1723 # Here are done with generating what the file should look like
1728 if ($tested_map ne $official) {
1729 fail_with_diff($mod_prop, $official, $tested_map, "prop_invmap");
1733 # There shouldn't be any specials unaccounted for.
1734 if (keys %specials) {
1735 fail("prop_invmap('$mod_prop')");
1736 diag("Unexpected specials: " . join ", ", keys %specials);
1740 elsif ($format eq 'n') {
1742 # Handle the Name property similar to the above. But the file is
1743 # sufficiently different that it is more convenient to make a special
1744 # case for it. It is a combination of the Name, Unicode1_Name, and
1745 # Name_Alias properties, and named sequences. We need to remove all
1746 # but the Name in order to do the comparison.
1748 if ($missing ne "") {
1749 fail("prop_invmap('$mod_prop')");
1750 diag("The missings should be \"\"; got \"missing\"");
1754 $official = do "unicore/Name.pl";
1756 # Get rid of the named sequences portion of the file. These don't
1757 # have a tab before the first blank on a line.
1758 $official =~ s/ ^ [^\t]+ \ .*? \n //xmg;
1760 # And get rid of the controls. These are named in the file, but
1761 # shouldn't be in the property. This gets rid of the two ranges in
1762 # one fell swoop, and also all the Unicode1_Name values that may not
1764 $official =~ s/ 00000 \t .* 0001F .*? \n//xs;
1765 $official =~ s/ 0007F \t .* 0009F .*? \n//xs;
1767 # And remove the aliases. We read in the Name_Alias property, and go
1768 # through them one by one.
1769 my ($aliases_code_points, $aliases_maps, undef, undef)
1770 = &prop_invmap('Name_Alias');
1771 for (my $i = 0; $i < @$aliases_code_points; $i++) {
1772 my $code_point = $aliases_code_points->[$i];
1774 # Already removed these above.
1775 next if $code_point <= 0x1F
1776 || ($code_point >= 0x7F && $code_point <= 0x9F);
1778 my $hex_code_point = sprintf "%05X", $code_point;
1780 # Convert to a list if not already to make the following loop
1782 $aliases_maps->[$i] = [ $aliases_maps->[$i] ]
1783 if ! ref $aliases_maps->[$i];
1785 # Remove each alias for this code point from the file
1786 foreach my $alias (@{$aliases_maps->[$i]}) {
1788 # Remove the alias type from the entry, retaining just the name.
1791 $alias = quotemeta($alias);
1792 $official =~ s/$hex_code_point \t $alias \n //x;
1797 # Here have adjusted the file. We also have to adjust the returned
1798 # inversion map by checking and deleting all the lines in it that
1799 # won't be in the file. These are the lines that have generated
1800 # things, like <hangul syllable>.
1801 my $tested_map = ""; # Current running string
1802 my @code_point_in_names =
1803 @Unicode::UCD::code_points_ending_in_code_point;
1805 for my $i (0 .. @$invlist_ref - 1 - 1) {
1806 my $start = $invlist_ref->[$i];
1807 my $end = $invlist_ref->[$i+1] - 1;
1808 if ($invmap_ref->[$i] eq $missing) {
1809 if (($i > 0 && $invlist_ref->[$i] <= $invlist_ref->[$i-1])
1810 || $invlist_ref->[$i] >= $invlist_ref->[$i+1])
1812 fail("prop_invmap('$mod_prop')");
1813 diag(sprintf "Range beginning at %04X is out-of-order.", $invlist_ref->[$i]);
1818 if ($invmap_ref->[$i] =~ / (.*) ( < .*? > )/x) {
1821 if (($i > 0 && $invlist_ref->[$i] <= $invlist_ref->[$i-1])
1822 || $invlist_ref->[$i] >= $invlist_ref->[$i+1])
1824 fail("prop_invmap('$mod_prop')");
1825 diag(sprintf "Range beginning at %04X is out-of-order.", $invlist_ref->[$i]);
1828 if ($type eq "<hangul syllable>") {
1830 fail("prop_invmap('$mod_prop')");
1831 diag("Unexpected text in $invmap_ref->[$i]");
1834 if ($start != 0xAC00) {
1835 fail("prop_invmap('$mod_prop')");
1836 diag(sprintf("<hangul syllables> should begin at 0xAC00, got %04X", $start));
1839 if ($end != $start + 11172 - 1) {
1840 fail("prop_invmap('$mod_prop')");
1841 diag(sprintf("<hangul syllables> should end at %04X, got %04X", $start + 11172 -1, $end));
1845 elsif ($type ne "<code point>") {
1846 fail("prop_invmap('$mod_prop')");
1847 diag("Unexpected text '$type' in $invmap_ref->[$i]");
1852 # Look through the array of names that end in code points,
1853 # and look for this start and end. If not found is an
1854 # error. If found, delete it, and at the end, make sure
1855 # have deleted everything.
1856 for my $i (0 .. @code_point_in_names - 1) {
1857 my $hash = $code_point_in_names[$i];
1858 if ($hash->{'low'} == $start
1859 && $hash->{'high'} == $end
1860 && "$hash->{'name'}-" eq $name)
1862 splice @code_point_in_names, $i, 1;
1866 fail("prop_invmap('$mod_prop')");
1867 diag("Unexpected code-point-in-name line '$invmap_ref->[$i]'");
1876 # Have adjusted the map, as needed. Append to running string.
1877 $end = ($start == $end) ? "" : sprintf("%05X", $end);
1878 $tested_map .= sprintf "%05X\t%s\n", $start, $invmap_ref->[$i];
1881 # Finished creating the string from the inversion map. Can compare
1882 # with what the file is.
1884 if ($tested_map ne $official) {
1885 fail_with_diff($mod_prop, $official, $tested_map, "prop_invmap");
1888 if (@code_point_in_names) {
1889 fail("prop_invmap('$mod_prop')");
1891 diag("Missing code-point-in-name line(s)" . Dumper \@code_point_in_names);
1895 elsif ($format eq 's') {
1897 # Here the map is not more or less directly from a file stored on
1898 # disk. We try a different tack. These should all be properties that
1899 # have just a few possible values (most of them are binary). We go
1900 # through the map list, sorting each range into buckets, one for each
1901 # map value. Thus for binary properties there will be a bucket for Y
1902 # and one for N. The buckets are inversion lists. We compare each
1903 # constructed inversion list with what we would get for it using
1904 # prop_invlist(), which has already been tested. If they all match,
1905 # the whole map must have matched.
1909 # (The extra -1 is to not look at the final element in the loop, which
1910 # we know is the one that starts just beyond Unicode and goes to
1912 for my $i (0 .. @$invlist_ref - 1 - 1) {
1913 my $range_start = $invlist_ref->[$i];
1915 # Because we are sorting into buckets, things could be
1916 # out-of-order here, and still be in the correct order in the
1917 # bucket, and hence wouldn't show up as an error; so have to
1919 if (($i > 0 && $range_start <= $invlist_ref->[$i-1])
1920 || $range_start >= $invlist_ref->[$i+1])
1922 fail("prop_invmap('$mod_prop')");
1923 diag(sprintf "Range beginning at %04X is out-of-order.", $invlist_ref->[$i]);
1927 # This new range closes out the range started in the previous
1929 push @{$maps{$previous_map}}, $range_start if defined $previous_map;
1931 # And starts a range which will be closed in the next iteration.
1932 $previous_map = $invmap_ref->[$i];
1933 push @{$maps{$previous_map}}, $range_start;
1936 # The range we just started hasn't been closed, and we didn't look at
1937 # the final element of the loop. If that range is for the default
1938 # value, it shouldn't be closed, as it is to extend to infinity. But
1939 # otherwise, it should end at the final Unicode code point, and the
1940 # list that maps to the default value should have another element that
1941 # does go to infinity for every above Unicode code point.
1943 if (@$invlist_ref > 1) {
1944 my $penultimate_map = $invmap_ref->[-2];
1945 if ($penultimate_map ne $missing) {
1947 # The -1th element contains the first non-Unicode code point.
1948 push @{$maps{$penultimate_map}}, $invlist_ref->[-1];
1949 push @{$maps{$missing}}, $invlist_ref->[-1];
1953 # Here, we have the buckets (inversion lists) all constructed. Go
1954 # through each and verify that matches what prop_invlist() returns.
1955 # We could use is_deeply() for the comparison, but would get multiple
1956 # messages for each $prop.
1957 foreach my $map (keys %maps) {
1958 my @off_invlist = prop_invlist("$prop = $map");
1959 my $min = (@off_invlist >= @{$maps{$map}})
1962 for my $i (0 .. $min- 1) {
1963 if ($i > @off_invlist - 1) {
1964 fail("prop_invmap('$mod_prop')");
1965 diag("There is no element [$i] for $prop=$map from prop_invlist(), while [$i] in the implicit one constructed from prop_invmap() is '$maps{$map}[$i]'");
1968 elsif ($i > @{$maps{$map}} - 1) {
1969 fail("prop_invmap('$mod_prop')");
1970 diag("There is no element [$i] from the implicit $prop=$map constructed from prop_invmap(), while [$i] in the one from prop_invlist() is '$off_invlist[$i]'");
1973 elsif ($maps{$map}[$i] ne $off_invlist[$i]) {
1974 fail("prop_invmap('$mod_prop')");
1975 diag("Element [$i] of the implicit $prop=$map constructed from prop_invmap() is '$maps{$map}[$i]', and the one from prop_invlist() is '$off_invlist[$i]'");
1981 else { # Don't know this property nor format.
1983 fail("prop_invmap('$mod_prop')");
1984 diag("Unknown format '$format'");
1987 pass("prop_invmap('$mod_prop')");