UCD.t revision 1.3
1#!perl -w
2BEGIN {
3    $::IS_ASCII = (ord("A") == 65) ? 1 : 0;
4    $::IS_EBCDIC = (ord("A") == 193) ? 1 : 0;
5    chdir 't' if -d 't';
6    @INC = '../lib';
7    require Config; import Config;
8    if ($Config{'extensions'} !~ /\bStorable\b/) {
9        print "1..0 # Skip: Storable was not built; Unicode::UCD uses Storable\n";
10        exit 0;
11    }
12}
13
14my @warnings;
15local $SIG{__WARN__} = sub { push @warnings, @_  };
16
17use strict;
18use Test::More;
19
20use Unicode::UCD qw(charinfo charprop charprops_all);
21
22my $expected_version = '10.0.0';
23my $current_version = Unicode::UCD::UnicodeVersion;
24my $v_unicode_version = pack "C*", split /\./, $current_version;
25my $unknown_script = ($v_unicode_version lt v5.0.0)
26                     ? 'Common'
27                     : 'Unknown';
28my $input_record_separator = 7; # Make sure Unicode::UCD isn't affected by
29$/ = $input_record_separator;   # setting this.
30
31my $charinfo;
32
33is(charinfo(0x110000), undef, "Verify charinfo() of non-unicode is undef");
34if ($v_unicode_version ge v3.2.0) {
35    is(lc charprop(0x110000, 'age'), lc "Unassigned", "Verify charprop(age) of non-unicode is Unassigned");
36    is(charprop(0x110000, 'in'), "Unassigned", "Verify charprop(in), a bipartite Perl extension, works");
37}
38is(charprop(0x110000, 'Any'), undef, "Verify charprop of non-bipartite Perl extension returns undef");
39
40my $cp = 0;
41$charinfo = charinfo($cp);    # Null is often problematic, so test it.
42
43is($charinfo->{code},           "0000",
44                        "Next tests are for charinfo and charprop; first NULL");
45is($charinfo->{name},           "<control>");
46is(charprop($cp, "name"),       "");
47
48if ($v_unicode_version ge v6.1.0) {
49    # This gets a sl-type property returning a flattened list
50    is(charprop($cp, "name_alias"), "NULL: control,NUL: abbreviation");
51}
52is($charinfo->{category},       "Cc");
53is(charprop($cp, "category"),   "Control");
54is($charinfo->{combining},      "0");
55is(charprop($cp, "ccc"),        "Not_Reordered");
56is($charinfo->{bidi},           "BN");
57is(charprop($cp, "bc"),         "Boundary_Neutral");
58is($charinfo->{decomposition},  "");
59is(charprop($cp, "dm"),         "\0");
60is($charinfo->{decimal},        "");
61is($charinfo->{digit},          "");
62is($charinfo->{numeric},        "");
63is(charprop($cp, "nv"),         "NaN");
64is($charinfo->{mirrored},       "N");
65is(charprop($cp, "bidim"),      "No");
66is($charinfo->{unicode10},      "NULL");
67is(charprop($cp, "na1"),        "NULL");
68is($charinfo->{comment},        "");
69is(charprop($cp, "isc"),        "");
70is($charinfo->{upper},          "");
71is(charprop($cp, "uc"),         "\0");
72is($charinfo->{lower},          "");
73is(charprop($cp, "lc"),         "\0");
74is($charinfo->{title},          "");
75is(charprop($cp, "tc"),         "\0");
76is($charinfo->{block},          "Basic Latin");
77is(charprop($cp, "block"),      "Basic_Latin");
78is($charinfo->{script},         "Common") if $v_unicode_version gt v3.0.1;
79is(charprop($cp, "script"),     "Common") if $v_unicode_version gt v3.0.1;
80
81$cp = utf8::unicode_to_native(0x41);
82my $A_code = sprintf("%04X", ord("A"));
83my $a_code = sprintf("%04X", ord("a"));
84$charinfo = charinfo($cp);
85
86is($charinfo->{code},           $A_code, "LATIN CAPITAL LETTER A");
87is($charinfo->{name},           "LATIN CAPITAL LETTER A");
88is(charprop($cp, 'name'),       "LATIN CAPITAL LETTER A");
89is($charinfo->{category},       "Lu");
90is(charprop($cp, 'gc'),         "Uppercase_Letter");
91is($charinfo->{combining},      "0");
92is(charprop($cp, 'ccc'),        "Not_Reordered");
93is($charinfo->{bidi},           "L");
94is(charprop($cp, 'bc'),         "Left_To_Right");
95is($charinfo->{decomposition},  "");
96is(charprop($cp, 'dm'),         "A");
97is($charinfo->{decimal},        "");
98is($charinfo->{digit},          "");
99is($charinfo->{numeric},        "");
100is(charprop($cp, 'nv'),        "NaN");
101is($charinfo->{mirrored},       "N");
102is(charprop($cp, 'bidim'),      "No");
103is($charinfo->{unicode10},      "");
104is(charprop($cp, 'na1'),        "");
105is($charinfo->{comment},        "");
106is(charprop($cp, 'isc'),        "");
107is($charinfo->{upper},          "");
108is(charprop($cp, 'uc'),         "A");
109is($charinfo->{lower},          $a_code);
110is(charprop($cp, 'lc'),         "a");
111is($charinfo->{title},          "");
112is(charprop($cp, 'tc'),         "A");
113is($charinfo->{block},          "Basic Latin");
114is(charprop($cp, 'block'),      "Basic_Latin");
115is($charinfo->{script},         "Latin") if $v_unicode_version gt v3.0.1;
116is(charprop($cp, 'script'),     "Latin") if $v_unicode_version gt v3.0.1;
117
118$cp = 0x100;
119$charinfo = charinfo($cp);
120
121is($charinfo->{code},           "0100", "LATIN CAPITAL LETTER A WITH MACRON");
122is($charinfo->{name},           "LATIN CAPITAL LETTER A WITH MACRON");
123is(charprop($cp, 'name'),       "LATIN CAPITAL LETTER A WITH MACRON");
124is($charinfo->{category},       "Lu");
125is(charprop($cp, 'gc'),         "Uppercase_Letter");
126is($charinfo->{combining},      "0");
127is(charprop($cp, 'ccc'),        "Not_Reordered");
128is($charinfo->{bidi},           "L");
129is(charprop($cp, 'bc'),         "Left_To_Right");
130is($charinfo->{decomposition},  "$A_code 0304");
131is(charprop($cp, 'dm'),         "A\x{0304}");
132is($charinfo->{decimal},        "");
133is($charinfo->{digit},          "");
134is($charinfo->{numeric},        "");
135is(charprop($cp, 'nv'),         "NaN");
136is($charinfo->{mirrored},       "N");
137is(charprop($cp, 'bidim'),      "No");
138is($charinfo->{unicode10},      "LATIN CAPITAL LETTER A MACRON");
139is(charprop($cp, 'na1'),        "LATIN CAPITAL LETTER A MACRON");
140is($charinfo->{comment},        "");
141is(charprop($cp, 'isc'),        "");
142is($charinfo->{upper},          "");
143is(charprop($cp, 'uc'),         "\x{100}");
144is($charinfo->{lower},          "0101");
145is(charprop($cp, 'lc'),         "\x{101}");
146is($charinfo->{title},          "");
147is(charprop($cp, 'tc'),         "\x{100}");
148is($charinfo->{block},          "Latin Extended-A");
149is(charprop($cp, 'block'),      "Latin_Extended_A");
150is($charinfo->{script},         "Latin") if $v_unicode_version gt v3.0.1;
151is(charprop($cp, 'script'),     "Latin") if $v_unicode_version gt v3.0.1;
152
153$cp = 0x590;               # 0x0590 is in the Hebrew block but unused.
154$charinfo = charinfo($cp);
155
156is($charinfo->{code},           undef,	"0x0590 - unused Hebrew");
157is($charinfo->{name},           undef);
158is(charprop($cp, 'name'),       "");
159is($charinfo->{category},       undef);
160is(charprop($cp, 'gc'),         "Unassigned");
161is($charinfo->{combining},      undef);
162is(charprop($cp, 'ccc'),        "Not_Reordered");
163is($charinfo->{bidi},           undef);
164if ($v_unicode_version gt v3.2.0) {
165    is(charprop($cp, 'bc'),         "Right_To_Left");
166}
167is($charinfo->{decomposition},  undef);
168is(charprop($cp, 'dm'),         "\x{590}");
169is($charinfo->{decimal},        undef);
170is($charinfo->{digit},          undef);
171is($charinfo->{numeric},        undef);
172is(charprop($cp, 'nv'),         "NaN");
173is($charinfo->{mirrored},       undef);
174is(charprop($cp, 'bidim'),      "No");
175is($charinfo->{unicode10},      undef);
176is(charprop($cp, 'na1'),        "");
177is($charinfo->{comment},        undef);
178is(charprop($cp, 'isc'),        "");
179is($charinfo->{upper},          undef);
180is(charprop($cp, 'uc'),         "\x{590}");
181is($charinfo->{lower},          undef);
182is(charprop($cp, 'lc'),         "\x{590}");
183is($charinfo->{title},          undef);
184is(charprop($cp, 'tc'),         "\x{590}");
185is($charinfo->{block},          undef);
186is(charprop($cp, 'block'),      "Hebrew");
187is($charinfo->{script},         undef);
188is(charprop($cp, 'script'),     $unknown_script) if $v_unicode_version gt
189v3.0.1;
190
191# 0x05d0 is in the Hebrew block and used.
192
193$cp = 0x5d0;
194$charinfo = charinfo($cp);
195
196is($charinfo->{code},           "05D0", "05D0 - used Hebrew");
197is($charinfo->{name},           "HEBREW LETTER ALEF");
198is(charprop($cp, 'name'),       "HEBREW LETTER ALEF");
199is($charinfo->{category},       "Lo");
200is(charprop($cp, 'gc'),         "Other_Letter");
201is($charinfo->{combining},      "0");
202is(charprop($cp, 'ccc'),        "Not_Reordered");
203is($charinfo->{bidi},           "R");
204is(charprop($cp, 'bc'),         "Right_To_Left");
205is($charinfo->{decomposition},  "");
206is(charprop($cp, 'dm'),         "\x{5d0}");
207is($charinfo->{decimal},        "");
208is($charinfo->{digit},          "");
209is($charinfo->{numeric},        "");
210is(charprop($cp, 'nv'),         "NaN");
211is($charinfo->{mirrored},       "N");
212is(charprop($cp, 'bidim'),      "No");
213is($charinfo->{unicode10},      "");
214is(charprop($cp, 'na1'),        "");
215is($charinfo->{comment},        "");
216is(charprop($cp, 'isc'),        "");
217is($charinfo->{upper},          "");
218is(charprop($cp, 'uc'),         "\x{5d0}");
219is($charinfo->{lower},          "");
220is(charprop($cp, 'lc'),         "\x{5d0}");
221is($charinfo->{title},          "");
222is(charprop($cp, 'tc'),         "\x{5d0}");
223is($charinfo->{block},          "Hebrew");
224is(charprop($cp, 'block'),      "Hebrew");
225is($charinfo->{script},         "Hebrew") if $v_unicode_version gt v3.0.1;
226is(charprop($cp, 'script'),     "Hebrew") if $v_unicode_version gt v3.0.1;
227
228# An open syllable in Hangul.
229
230$cp = 0xAC00;
231$charinfo = charinfo($cp);
232
233is($charinfo->{code},           "AC00", "HANGUL SYLLABLE U+AC00");
234is($charinfo->{name},           "HANGUL SYLLABLE GA");
235is(charprop($cp, 'name'),       "HANGUL SYLLABLE GA");
236is($charinfo->{category},       "Lo");
237is(charprop($cp, 'gc'),         "Other_Letter");
238is($charinfo->{combining},      "0");
239is(charprop($cp, 'ccc'),        "Not_Reordered");
240is($charinfo->{bidi},           "L");
241is(charprop($cp, 'bc'),         "Left_To_Right");
242is($charinfo->{decomposition},  "1100 1161");
243is(charprop($cp, 'dm'),         "\x{1100}\x{1161}");
244is($charinfo->{decimal},        "");
245is($charinfo->{digit},          "");
246is($charinfo->{numeric},        "");
247is(charprop($cp, 'nv'),         "NaN");
248is($charinfo->{mirrored},       "N");
249is(charprop($cp, 'bidim'),      "No");
250is($charinfo->{unicode10},      "");
251is(charprop($cp, 'na1'),        "");
252is($charinfo->{comment},        "");
253is(charprop($cp, 'isc'),        "");
254is($charinfo->{upper},          "");
255is(charprop($cp, 'uc'),         "\x{AC00}");
256is($charinfo->{lower},          "");
257is(charprop($cp, 'lc'),         "\x{AC00}");
258is($charinfo->{title},          "");
259is(charprop($cp, 'tc'),         "\x{AC00}");
260is($charinfo->{block},          "Hangul Syllables");
261is(charprop($cp, 'block'),      "Hangul_Syllables");
262is($charinfo->{script},         "Hangul") if $v_unicode_version gt v3.0.1;
263is(charprop($cp, 'script'),     "Hangul") if $v_unicode_version gt v3.0.1;
264
265# A closed syllable in Hangul.
266
267$cp = 0xAE00;
268$charinfo = charinfo($cp);
269
270is($charinfo->{code},           "AE00", "HANGUL SYLLABLE U+AE00");
271is($charinfo->{name},           "HANGUL SYLLABLE GEUL");
272is(charprop($cp, 'name'),       "HANGUL SYLLABLE GEUL");
273is($charinfo->{category},       "Lo");
274is(charprop($cp, 'gc'),         "Other_Letter");
275is($charinfo->{combining},      "0");
276is(charprop($cp, 'ccc'),        "Not_Reordered");
277is($charinfo->{bidi},           "L");
278is(charprop($cp, 'bc'),         "Left_To_Right");
279is($charinfo->{decomposition},  "1100 1173 11AF");
280is(charprop($cp, 'dm'),         "\x{1100}\x{1173}\x{11AF}");
281is($charinfo->{decimal},        "");
282is($charinfo->{digit},          "");
283is($charinfo->{numeric},        "");
284is(charprop($cp, 'nv'),         "NaN");
285is($charinfo->{mirrored},       "N");
286is(charprop($cp, 'bidim'),      "No");
287is($charinfo->{unicode10},      "");
288is(charprop($cp, 'na1'),        "");
289is($charinfo->{comment},        "");
290is(charprop($cp, 'isc'),        "");
291is($charinfo->{upper},          "");
292is(charprop($cp, 'uc'),         "\x{AE00}");
293is($charinfo->{lower},          "");
294is(charprop($cp, 'lc'),         "\x{AE00}");
295is($charinfo->{title},          "");
296is(charprop($cp, 'tc'),         "\x{AE00}");
297is($charinfo->{block},          "Hangul Syllables");
298is(charprop($cp, 'block'),      "Hangul_Syllables");
299is($charinfo->{script},         "Hangul") if $v_unicode_version gt v3.0.1;
300is(charprop($cp, 'script'),     "Hangul") if $v_unicode_version gt v3.0.1;
301
302if ($v_unicode_version gt v3.0.1) {
303    $cp = 0x1D400;
304    $charinfo = charinfo($cp);
305
306    is($charinfo->{code},           "1D400", "MATHEMATICAL BOLD CAPITAL A");
307    is($charinfo->{name},           "MATHEMATICAL BOLD CAPITAL A");
308    is(charprop($cp, 'name'),       "MATHEMATICAL BOLD CAPITAL A");
309    is($charinfo->{category},       "Lu");
310    is(charprop($cp, 'gc'),         "Uppercase_Letter");
311    is($charinfo->{combining},      "0");
312    is(charprop($cp, 'ccc'),        "Not_Reordered");
313    is($charinfo->{bidi},           "L");
314    is(charprop($cp, 'bc'),         "Left_To_Right");
315    is($charinfo->{decomposition},  "<font> $A_code");
316    is(charprop($cp, 'dm'),         "A");
317    is($charinfo->{decimal},        "");
318    is($charinfo->{digit},          "");
319    is($charinfo->{numeric},        "");
320    is(charprop($cp, 'nv'),         "NaN");
321    is($charinfo->{mirrored},       "N");
322    is(charprop($cp, 'bidim'),      "No");
323    is($charinfo->{unicode10},      "");
324    is(charprop($cp, 'na1'),        "");
325    is($charinfo->{comment},        "");
326    is(charprop($cp, 'isc'),        "");
327    is($charinfo->{upper},          "");
328    is(charprop($cp, 'uc'),         "\x{1D400}");
329    is($charinfo->{lower},          "");
330    is(charprop($cp, 'lc'),         "\x{1D400}");
331    is($charinfo->{title},          "");
332    is(charprop($cp, 'tc'),         "\x{1D400}");
333    is($charinfo->{block},          "Mathematical Alphanumeric Symbols");
334    is(charprop($cp, 'block'),      "Mathematical_Alphanumeric_Symbols");
335    is($charinfo->{script},         "Common");
336    is(charprop($cp, 'script'),     "Common");
337}
338
339if ($v_unicode_version ge v4.1.0) {
340    $cp = 0x9FBA;	                #Bug 58428
341    $charinfo = charinfo(0x9FBA);
342
343    is($charinfo->{code},           "9FBA", "U+9FBA");
344    is($charinfo->{name},           "CJK UNIFIED IDEOGRAPH-9FBA");
345    is(charprop($cp, 'name'),       "CJK UNIFIED IDEOGRAPH-9FBA");
346    is($charinfo->{category},       "Lo");
347    is(charprop($cp, 'gc'),         "Other_Letter");
348    is($charinfo->{combining},      "0");
349    is(charprop($cp, 'ccc'),        "Not_Reordered");
350    is($charinfo->{bidi},           "L");
351    is(charprop($cp, 'bc'),         "Left_To_Right");
352    is($charinfo->{decomposition},  "");
353    is(charprop($cp, 'dm'),         "\x{9FBA}");
354    is($charinfo->{decimal},        "");
355    is($charinfo->{digit},          "");
356    is($charinfo->{numeric},        "");
357    is(charprop($cp, 'nv'),         "NaN");
358    is($charinfo->{mirrored},       "N");
359    is(charprop($cp, 'bidim'),      "No");
360    is($charinfo->{unicode10},      "");
361    is(charprop($cp, 'na1'),        "");
362    is($charinfo->{comment},        "");
363    is(charprop($cp, 'isc'),        "");
364    is($charinfo->{upper},          "");
365    is(charprop($cp, 'uc'),         "\x{9FBA}");
366    is($charinfo->{lower},          "");
367    is(charprop($cp, 'lc'),         "\x{9FBA}");
368    is($charinfo->{title},          "");
369    is(charprop($cp, 'tc'),         "\x{9FBA}");
370    is($charinfo->{block},          "CJK Unified Ideographs");
371    is(charprop($cp, 'block'),      "CJK_Unified_Ideographs");
372    is($charinfo->{script},         "Han");
373    is(charprop($cp, 'script'),     "Han");
374}
375
376use Unicode::UCD qw(charblock charscript);
377
378# 0x0590 is in the Hebrew block but unused.
379
380is(charblock(0x590),          "Hebrew", "0x0590 - Hebrew unused charblock");
381is(charscript(0x590),         $unknown_script, "0x0590 - Hebrew unused charscript") if $v_unicode_version gt v3.0.1;
382is(charblock(0x1FFFF),        "No_Block", "0x1FFFF - unused charblock");
383
384{
385    my @warnings;
386    local $SIG{__WARN__} = sub { push @warnings, @_  };
387    is(charblock(chr(0x6237)), undef,
388        "Verify charblock of non-code point returns <undef>");
389    cmp_ok(scalar @warnings, '==', 1, "  ... and generates 1 warning");
390    like($warnings[0], qr/unknown code/, "  ... with the right text");
391}
392
393my $fraction_3_4_code = sprintf("%04X", utf8::unicode_to_native(0xbe));
394$cp = $fraction_3_4_code;
395$charinfo = charinfo($fraction_3_4_code);
396
397is($charinfo->{code},           $fraction_3_4_code, "VULGAR FRACTION THREE QUARTERS");
398is($charinfo->{name},           "VULGAR FRACTION THREE QUARTERS");
399is(charprop($cp, 'name'),       "VULGAR FRACTION THREE QUARTERS");
400is($charinfo->{category},       "No");
401is(charprop($cp, 'gc'),         "Other_Number");
402is($charinfo->{combining},      "0");
403is(charprop($cp, 'ccc'),        "Not_Reordered");
404is($charinfo->{bidi},           "ON");
405is(charprop($cp, 'bc'),         "Other_Neutral");
406is($charinfo->{decomposition},  "<fraction> "
407                                . sprintf("%04X", ord "3")
408                                . " 2044 "
409                                . sprintf("%04X", ord "4"));
410is(charprop($cp, 'dm'),         "3\x{2044}4");
411is($charinfo->{decimal},        "");
412is($charinfo->{digit},          "");
413is($charinfo->{numeric},        "3/4");
414is(charprop($cp, 'nv'),        "0.75");
415is($charinfo->{mirrored},       "N");
416is(charprop($cp, 'bidim'),      "No");
417is($charinfo->{unicode10},      "FRACTION THREE QUARTERS");
418is(charprop($cp, 'na1'),        "FRACTION THREE QUARTERS");
419is($charinfo->{comment},        "");
420is(charprop($cp, 'isc'),        "");
421is($charinfo->{upper},          "");
422is(charprop($cp, 'uc'),         chr hex $cp);
423is($charinfo->{lower},          "");
424is(charprop($cp, 'lc'),         chr hex $cp);
425is($charinfo->{title},          "");
426is(charprop($cp, 'tc'),         chr hex $cp);
427is($charinfo->{block},          "Latin-1 Supplement");
428is(charprop($cp, 'block'),      "Latin_1_Supplement");
429is($charinfo->{script},         "Common") if $v_unicode_version gt v3.0.1;
430is(charprop($cp, 'script'),     "Common") if $v_unicode_version gt v3.0.1;
431
432# This is to test a case where both simple and full lowercases exist and
433# differ
434$cp = 0x130;
435$charinfo = charinfo($cp);
436my $I_code = sprintf("%04X", ord("I"));
437my $i_code = sprintf("%04X", ord("i"));
438
439is($charinfo->{code},           "0130", "LATIN CAPITAL LETTER I WITH DOT ABOVE");
440is($charinfo->{name},           "LATIN CAPITAL LETTER I WITH DOT ABOVE");
441is(charprop($cp, 'name'),       "LATIN CAPITAL LETTER I WITH DOT ABOVE");
442is($charinfo->{category},       "Lu");
443is(charprop($cp, 'gc'),         "Uppercase_Letter");
444is($charinfo->{combining},      "0");
445is(charprop($cp, 'ccc'),        "Not_Reordered");
446is($charinfo->{bidi},           "L");
447is(charprop($cp, 'bc'),         "Left_To_Right");
448is($charinfo->{decomposition},  "$I_code 0307");
449is(charprop($cp, 'dm'),         "I\x{0307}");
450is($charinfo->{decimal},        "");
451is($charinfo->{digit},          "");
452is($charinfo->{numeric},        "");
453is(charprop($cp, 'nv'),         "NaN");
454is($charinfo->{mirrored},       "N");
455is(charprop($cp, 'bidim'),      "No");
456is($charinfo->{unicode10},      "LATIN CAPITAL LETTER I DOT");
457is(charprop($cp, 'na1'),        "LATIN CAPITAL LETTER I DOT");
458is($charinfo->{comment},        "");
459is(charprop($cp, 'isc'),        "");
460is($charinfo->{upper},          "");
461is(charprop($cp, 'uc'),         "\x{130}");
462is($charinfo->{lower},          $i_code);
463is(charprop($cp, 'lc'),         "i\x{307}") if $v_unicode_version ge v3.2.0;
464is($charinfo->{title},          "");
465is(charprop($cp, 'tc'),         "\x{130}");
466is($charinfo->{block},          "Latin Extended-A");
467is(charprop($cp, 'block'),      "Latin_Extended_A");
468is($charinfo->{script},         "Latin") if $v_unicode_version gt v3.0.1;
469is(charprop($cp, 'script'),     "Latin") if $v_unicode_version gt v3.0.1;
470
471# This is to test a case where both simple and full uppercases exist and
472# differ
473$cp = 0x1F80;
474$charinfo = charinfo($cp);
475
476is($charinfo->{code},           "1F80", "GREEK SMALL LETTER ALPHA WITH PSILI AND YPOGEGRAMMENI");
477is($charinfo->{name},           "GREEK SMALL LETTER ALPHA WITH PSILI AND YPOGEGRAMMENI");
478is(charprop($cp, "name"),       "GREEK SMALL LETTER ALPHA WITH PSILI AND YPOGEGRAMMENI");
479is($charinfo->{category},       "Ll");
480is(charprop($cp, "gc"),         "Lowercase_Letter");
481is($charinfo->{combining},      "0");
482is(charprop($cp, "ccc"),        "Not_Reordered");
483is($charinfo->{bidi},           "L");
484is(charprop($cp, "bc"),         "Left_To_Right");
485is($charinfo->{decomposition},  "1F00 0345");
486is(charprop($cp, "dm"),         "\x{1F00}\x{0345}");
487is($charinfo->{decimal},        "");
488is($charinfo->{digit},          "");
489is($charinfo->{numeric},        "");
490is(charprop($cp, "nv"),         "NaN");
491is($charinfo->{mirrored},       "N");
492is(charprop($cp, "bidim"),      "No");
493is($charinfo->{unicode10},      "");
494is(charprop($cp, "na1"),        "");
495is($charinfo->{comment},        "");
496is(charprop($cp, "isc"),        "");
497is($charinfo->{upper},          "1F88");
498is(charprop($cp, "uc"),         "\x{1F08}\x{0399}");
499is(charprop($cp, "suc"),        "\x{1F88}");
500is($charinfo->{lower},          "");
501is(charprop($cp, "lc"),         "\x{1F80}");
502is($charinfo->{title},          "1F88");
503is(charprop($cp, "tc"),         "\x{1F88}");
504is($charinfo->{block},          "Greek Extended");
505is(charprop($cp, "block"),      "Greek_Extended");
506is($charinfo->{script},         "Greek") if $v_unicode_version gt v3.0.1;
507is(charprop($cp, "script"),     "Greek") if $v_unicode_version gt v3.0.1;
508
509is(charprop(ord("A"), "foo"),    undef,
510                        "Verify charprop of unknown property returns <undef>");
511
512# These were created from inspection of the code to exercise the branches
513if ($v_unicode_version ge v6.3.0) {
514    is(charprop(ord("("), "bpb"),    ")",
515            "Verify charprop figures out that s-type properties can be char");
516}
517is(charprop(ord("9"), "nv"),     9,
518                            "Verify charprop can adjust an ar-type property");
519if ($v_unicode_version ge v5.2.0) {
520    is(charprop(utf8::unicode_to_native(0xAD), "NFKC_Casefold"), "",
521                    "Verify charprop can handle an \"\" in ae-type property");
522}
523
524my $mark_props_ref = charprops_all(0x300);
525is($mark_props_ref->{'Bidi_Class'}, "Nonspacing_Mark",
526                                    "Next tests are charprops_all of 0x300");
527is($mark_props_ref->{'Bidi_Mirrored'}, "No");
528is($mark_props_ref->{'Canonical_Combining_Class'}, "Above");
529is($mark_props_ref->{'Case_Folding'}, "\x{300}");
530is($mark_props_ref->{'Decomposition_Mapping'}, "\x{300}");
531is($mark_props_ref->{'Decomposition_Type'}, ($v_unicode_version le v4.0.0)
532                                             ? "none"
533                                             : "None");
534is($mark_props_ref->{'General_Category'}, "Nonspacing_Mark");
535if ($v_unicode_version gt v5.1.0) {
536    is($mark_props_ref->{'ISO_Comment'}, "");
537}
538is($mark_props_ref->{'Lowercase_Mapping'}, "\x{300}");
539is($mark_props_ref->{'Name'}, "COMBINING GRAVE ACCENT");
540is($mark_props_ref->{'Numeric_Type'}, "None");
541is($mark_props_ref->{'Numeric_Value'}, "NaN");
542is($mark_props_ref->{'Simple_Case_Folding'}, "\x{300}");
543is($mark_props_ref->{'Simple_Lowercase_Mapping'}, "\x{300}");
544is($mark_props_ref->{'Simple_Titlecase_Mapping'}, "\x{300}");
545is($mark_props_ref->{'Simple_Uppercase_Mapping'}, "\x{300}");
546is($mark_props_ref->{'Titlecase_Mapping'}, "\x{300}");
547is($mark_props_ref->{'Unicode_1_Name'}, "NON-SPACING GRAVE");
548is($mark_props_ref->{'Uppercase_Mapping'}, "\x{300}");
549
550use Unicode::UCD qw(charblocks charscripts);
551
552my $charblocks = charblocks();
553
554ok(exists $charblocks->{Thai}, 'Thai charblock exists');
555is($charblocks->{Thai}->[0]->[0], hex('0e00'));
556ok(!exists $charblocks->{PigLatin}, 'PigLatin charblock does not exist');
557
558if ($v_unicode_version gt v3.0.1) {
559    my $charscripts = charscripts();
560
561    ok(exists $charscripts->{Armenian}, 'Armenian charscript exists');
562    is($charscripts->{Armenian}->[0]->[0], hex('0531'));
563    ok(!exists $charscripts->{PigLatin}, 'PigLatin charscript does not exist');
564
565    my $charscript;
566
567    $charscript = charscript("12ab");
568    is($charscript, 'Ethiopic', 'Ethiopic charscript');
569
570    $charscript = charscript("0x12ab");
571    is($charscript, 'Ethiopic');
572
573    $charscript = charscript("U+12ab");
574    is($charscript, 'Ethiopic');
575
576    my $ranges;
577
578    if ($v_unicode_version gt v4.0.0) {
579        $ranges = charscript('Ogham');
580        is($ranges->[0]->[0], hex('1680'), 'Ogham charscript');
581        is($ranges->[0]->[1], hex('169C'));
582    }
583
584    use Unicode::UCD qw(charinrange);
585
586    $ranges = charscript('Cherokee');
587    ok(!charinrange($ranges, "139f"), 'Cherokee charscript');
588    ok( charinrange($ranges, "13a0"));
589    ok( charinrange($ranges, "13f4"));
590    ok(!charinrange($ranges, "13ff"));
591}
592
593use Unicode::UCD qw(general_categories);
594
595my $gc = general_categories();
596
597ok(exists $gc->{L}, 'has L');
598is($gc->{L}, 'Letter', 'L is Letter');
599is($gc->{Lu}, 'UppercaseLetter', 'Lu is UppercaseLetter');
600
601use Unicode::UCD qw(bidi_types);
602
603my $bt = bidi_types();
604
605ok(exists $bt->{L}, 'has L');
606is($bt->{L}, 'Left-to-Right', 'L is Left-to-Right');
607is($bt->{AL}, 'Right-to-Left Arabic', 'AL is Right-to-Left Arabic');
608
609# If this fails, then maybe one should look at the Unicode changes to see
610# what else might need to be updated.
611ok($current_version le $expected_version,
612                    "Verify there isn't a new Unicode version to upgrade to");
613
614use Unicode::UCD qw(compexcl);
615
616ok(!compexcl(0x0100), 'compexcl');
617ok(!compexcl(0xD801), 'compexcl of surrogate');
618ok(!compexcl(0x110000), 'compexcl of non-Unicode code point');
619ok( compexcl(0x0958));
620
621use Unicode::UCD qw(casefold);
622
623my $casefold;
624
625$casefold = casefold(utf8::unicode_to_native(0x41));
626
627is($casefold->{code}, $A_code, 'casefold native(0x41) code');
628is($casefold->{status}, 'C', 'casefold native(0x41) status');
629is($casefold->{mapping}, $a_code, 'casefold native(0x41) mapping');
630is($casefold->{full}, $a_code, 'casefold native(0x41) full');
631is($casefold->{simple}, $a_code, 'casefold native(0x41) simple');
632is($casefold->{turkic}, "", 'casefold native(0x41) turkic');
633
634my $sharp_s_code = sprintf("%04X", utf8::unicode_to_native(0xdf));
635my $S_code = sprintf("%04X", ord "S");
636my $s_code = sprintf("%04X", ord "s");
637
638if ($v_unicode_version gt v3.0.0) { # These special ones don't work on early
639                                    # perls
640    $casefold = casefold(utf8::unicode_to_native(0xdf));
641
642    is($casefold->{code}, $sharp_s_code, 'casefold native(0xDF) code');
643    is($casefold->{status}, 'F', 'casefold native(0xDF) status');
644    is($casefold->{mapping}, "$s_code $s_code", 'casefold native(0xDF) mapping');
645    is($casefold->{full}, "$s_code $s_code", 'casefold native(0xDF) full');
646    is($casefold->{simple}, "", 'casefold native(0xDF) simple');
647    is($casefold->{turkic}, "", 'casefold native(0xDF) turkic');
648
649    # Do different tests depending on if version < 3.2, or not.
650    if ($v_unicode_version eq v3.0.1) {
651            # In this release, there was no special Turkic values.
652            # Both 0x130 and 0x131 folded to 'i'.
653
654            $casefold = casefold(0x130);
655
656            is($casefold->{code}, '0130', 'casefold 0x130 code');
657            is($casefold->{status}, 'C' , 'casefold 0x130 status');
658            is($casefold->{mapping}, $i_code, 'casefold 0x130 mapping');
659            is($casefold->{full}, $i_code, 'casefold 0x130 full');
660            is($casefold->{simple}, $i_code, 'casefold 0x130 simple');
661            is($casefold->{turkic}, "", 'casefold 0x130 turkic');
662
663            $casefold = casefold(0x131);
664
665            is($casefold->{code}, '0131', 'casefold 0x131 code');
666            is($casefold->{status}, 'C' , 'casefold 0x131 status');
667            is($casefold->{mapping}, $i_code, 'casefold 0x131 mapping');
668            is($casefold->{full}, $i_code, 'casefold 0x131 full');
669            is($casefold->{simple}, $i_code, 'casefold 0x131 simple');
670            is($casefold->{turkic}, "", 'casefold 0x131 turkic');
671    }
672    elsif ($v_unicode_version lt v3.2.0) {
673            $casefold = casefold(0x130);
674
675            is($casefold->{code}, '0130', 'casefold 0x130 code');
676            is($casefold->{status}, 'I' , 'casefold 0x130 status');
677            is($casefold->{mapping}, $i_code, 'casefold 0x130 mapping');
678            is($casefold->{full}, $i_code, 'casefold 0x130 full');
679            is($casefold->{simple}, $i_code, 'casefold 0x130 simple');
680            is($casefold->{turkic}, $i_code, 'casefold 0x130 turkic');
681
682            $casefold = casefold(0x131);
683
684            is($casefold->{code}, '0131', 'casefold 0x131 code');
685            is($casefold->{status}, 'I' , 'casefold 0x131 status');
686            is($casefold->{mapping}, $i_code, 'casefold 0x131 mapping');
687            is($casefold->{full}, $i_code, 'casefold 0x131 full');
688            is($casefold->{simple}, $i_code, 'casefold 0x131 simple');
689            is($casefold->{turkic}, $i_code, 'casefold 0x131 turkic');
690    } else {
691            $casefold = casefold(utf8::unicode_to_native(0x49));
692
693            is($casefold->{code}, $I_code, 'casefold native(0x49) code');
694            is($casefold->{status}, 'C' , 'casefold native(0x49) status');
695            is($casefold->{mapping}, $i_code, 'casefold native(0x49) mapping');
696            is($casefold->{full}, $i_code, 'casefold native(0x49) full');
697            is($casefold->{simple}, $i_code, 'casefold native(0x49) simple');
698            is($casefold->{turkic}, "0131", 'casefold native(0x49) turkic');
699
700            $casefold = casefold(0x130);
701
702            is($casefold->{code}, '0130', 'casefold 0x130 code');
703            is($casefold->{status}, 'F' , 'casefold 0x130 status');
704            is($casefold->{mapping}, "$i_code 0307", 'casefold 0x130 mapping');
705            is($casefold->{full}, "$i_code 0307", 'casefold 0x130 full');
706            is($casefold->{simple}, "", 'casefold 0x130 simple');
707            is($casefold->{turkic}, $i_code, 'casefold 0x130 turkic');
708    }
709
710    if ($v_unicode_version gt v3.0.1) {
711        $casefold = casefold(0x1F88);
712
713        is($casefold->{code}, '1F88', 'casefold 0x1F88 code');
714        is($casefold->{status}, 'S' , 'casefold 0x1F88 status');
715        is($casefold->{mapping}, '1F80', 'casefold 0x1F88 mapping');
716        is($casefold->{full}, '1F00 03B9', 'casefold 0x1F88 full');
717        is($casefold->{simple}, '1F80', 'casefold 0x1F88 simple');
718        is($casefold->{turkic}, "", 'casefold 0x1F88 turkic');
719    }
720}
721
722ok(!casefold(utf8::unicode_to_native(0x20)));
723
724use Unicode::UCD qw(casespec);
725
726my $casespec;
727
728ok(!casespec(utf8::unicode_to_native(0x41)));
729
730$casespec = casespec(utf8::unicode_to_native(0xdf));
731
732ok($casespec->{code} eq $sharp_s_code &&
733   $casespec->{lower} eq $sharp_s_code  &&
734   $casespec->{title} eq "$S_code $s_code"  &&
735   $casespec->{upper} eq "$S_code $S_code" &&
736   !defined $casespec->{condition}, 'casespec native(0xDF)');
737
738$casespec = casespec(0x307);
739
740if ($v_unicode_version gt v3.1.0) {
741    ok($casespec->{az}->{code} eq '0307'
742    && !defined $casespec->{az}->{lower}
743    && $casespec->{az}->{title} eq '0307'
744    && $casespec->{az}->{upper} eq '0307'
745    && $casespec->{az}->{condition} eq ($v_unicode_version le v3.2)
746                                        ? 'az After_Soft_Dotted'
747                                        : 'az After_I',
748    'casespec 0x307');
749}
750
751# perl #7305 UnicodeCD::compexcl is weird
752
753for (1) {my $a=compexcl $_}
754ok(1, 'compexcl read-only $_: perl #7305');
755map {compexcl $_} %{{1=>2}};
756ok(1, 'compexcl read-only hash: perl #7305');
757
758is(Unicode::UCD::_getcode('123'),     123, "_getcode(123)");
759is(Unicode::UCD::_getcode('0123'),  0x123, "_getcode(0123)");
760is(Unicode::UCD::_getcode('0x123'), 0x123, "_getcode(0x123)");
761is(Unicode::UCD::_getcode('0X123'), 0x123, "_getcode(0X123)");
762is(Unicode::UCD::_getcode('U+123'), 0x123, "_getcode(U+123)");
763is(Unicode::UCD::_getcode('u+123'), 0x123, "_getcode(u+123)");
764is(Unicode::UCD::_getcode('U+1234'),   0x1234, "_getcode(U+1234)");
765is(Unicode::UCD::_getcode('U+12345'), 0x12345, "_getcode(U+12345)");
766is(Unicode::UCD::_getcode('123x'),    undef, "_getcode(123x)");
767is(Unicode::UCD::_getcode('x123'),    undef, "_getcode(x123)");
768is(Unicode::UCD::_getcode('0x123x'),  undef, "_getcode(x123)");
769is(Unicode::UCD::_getcode('U+123x'),  undef, "_getcode(x123)");
770
771SKIP:
772{
773    skip("Script property not in this release", 3) if $v_unicode_version lt v3.1.0;
774
775    {
776        my @warnings;
777        local $SIG{__WARN__} = sub { push @warnings, @_  };
778        is(charscript(chr(0x6237)), undef,
779           "Verify charscript of non-code point returns <undef>");
780        cmp_ok(scalar @warnings, '==', 1, "  ... and generates 1 warning");
781        like($warnings[0], qr/unknown code/, "  ... with the right text");
782    }
783
784    my $r1 = charscript('Latin');
785    if (ok(defined $r1, "Found Latin script")) {
786        skip("Latin range count will be wrong when using older Unicode release",
787             2) if $current_version lt $expected_version;
788        my $n1 = @$r1;
789        is($n1, 31, "number of ranges in Latin script (Unicode $expected_version)") if $::IS_ASCII;
790        shift @$r1 while @$r1;
791        my $r2 = charscript('Latin');
792        is(@$r2, $n1, "modifying results should not mess up internal caches");
793    }
794}
795
796{
797	is(charinfo(0xdeadbeef), undef, "[perl #23273] warnings in Unicode::UCD");
798}
799
800if ($v_unicode_version ge v4.1.0) {
801    use Unicode::UCD qw(namedseq);
802
803    is(namedseq("KATAKANA LETTER AINU P"), "\x{31F7}\x{309A}", "namedseq");
804    is(namedseq("KATAKANA LETTER AINU Q"), undef);
805    is(namedseq(), undef);
806    is(namedseq(qw(foo bar)), undef);
807    my @ns = namedseq("KATAKANA LETTER AINU P");
808    is(scalar @ns, 2);
809    is($ns[0], 0x31F7);
810    is($ns[1], 0x309A);
811    my %ns = namedseq();
812    is($ns{"KATAKANA LETTER AINU P"}, "\x{31F7}\x{309A}");
813    @ns = namedseq(42);
814    is(@ns, 0);
815}
816
817use Unicode::UCD qw(num);
818use charnames ();   # Don't use \N{} on things not in original Unicode
819                    # version; else will get a compilation error when this .t
820                    # is run on an older version.
821
822my $ret_len;
823is(num("0"), 0, 'Verify num("0") == 0');
824is(num("0", \$ret_len), 0, 'Verify num("0", \$ret_len) == 0');
825is($ret_len, 1, "... and the returned length is 1");
826ok(! defined num("", \$ret_len), 'Verify num("", \$ret_len) isnt defined');
827is($ret_len, 0, "... and the returned length is 0");
828ok(! defined num("A", \$ret_len), 'Verify num("A") isnt defined');
829is($ret_len, 0, "... and the returned length is 0");
830is(num("98765", \$ret_len), 98765, 'Verify num("98765") == 98765');
831is($ret_len, 5, "... and the returned length is 5");
832ok(! defined num("98765\N{FULLWIDTH DIGIT FOUR}", \$ret_len),
833   'Verify num("98765\N{FULLWIDTH DIGIT FOUR}") isnt defined');
834is($ret_len, 5, "... but the returned length is 5");
835my $tai_lue_2;
836if ($v_unicode_version ge v4.1.0) {
837    my $tai_lue_1 = charnames::string_vianame("NEW TAI LUE DIGIT ONE");
838    $tai_lue_2 = charnames::string_vianame("NEW TAI LUE DIGIT TWO");
839    is(num($tai_lue_2), 2, 'Verify num("\N{NEW TAI LUE DIGIT TWO}") == 2');
840    is(num($tai_lue_1), 1, 'Verify num("\N{NEW TAI LUE DIGIT ONE}") == 1');
841    is(num($tai_lue_2 . $tai_lue_1), 21,
842       'Verify num("\N{NEW TAI LUE DIGIT TWO}\N{NEW TAI LUE DIGIT ONE}") == 21');
843}
844if ($v_unicode_version ge v5.2.0) {
845    ok(! defined num($tai_lue_2
846         . charnames::string_vianame("NEW TAI LUE THAM DIGIT ONE"), \$ret_len),
847         'Verify num("\N{NEW TAI LUE DIGIT TWO}\N{NEW TAI LUE THAM DIGIT ONE}") isnt defined');
848    is($ret_len, 1, "... but the returned length is 1");
849    ok(! defined num(charnames::string_vianame("NEW TAI LUE THAM DIGIT ONE")
850                     .  $tai_lue_2, \$ret_len),
851         'Verify num("\N{NEW TAI LUE THAM DIGIT ONE}\N{NEW TAI LUE DIGIT TWO}") isnt defined');
852    is($ret_len, 1, "... but the returned length is 1");
853}
854if ($v_unicode_version ge v5.1.0) {
855    my $cham_0 = charnames::string_vianame("CHAM DIGIT ZERO");
856    is(num($cham_0 . charnames::string_vianame("CHAM DIGIT THREE")), 3,
857       'Verify num("\N{CHAM DIGIT ZERO}\N{CHAM DIGIT THREE}") == 3');
858    if ($v_unicode_version ge v5.2.0) {
859        ok(! defined num(  $cham_0
860                         . charnames::string_vianame("JAVANESE DIGIT NINE"),
861                         \$ret_len),
862        'Verify num("\N{CHAM DIGIT ZERO}\N{JAVANESE DIGIT NINE}") isnt defined');
863    is($ret_len, 1, "... but the returned length is 1");
864    }
865}
866is(num("\N{SUPERSCRIPT TWO}"), 2, 'Verify num("\N{SUPERSCRIPT TWO} == 2');
867if ($v_unicode_version ge v3.0.0) {
868    is(num(charnames::string_vianame("ETHIOPIC NUMBER TEN THOUSAND")), 10000,
869       'Verify num("\N{ETHIOPIC NUMBER TEN THOUSAND}") == 10000');
870}
871if ($v_unicode_version ge v5.2.0) {
872    is(num(charnames::string_vianame("NORTH INDIC FRACTION ONE HALF")),
873       .5,
874       'Verify num("\N{NORTH INDIC FRACTION ONE HALF}") == .5');
875    is(num("\N{U+12448}"), 9, 'Verify num("\N{U+12448}") == 9');
876}
877if ($v_unicode_version gt v3.2.0) { # Is missing from non-Unihan files before
878                                    # this
879    is(num("\N{U+5146}"), 1000000000000,
880                                'Verify num("\N{U+5146}") == 1000000000000');
881}
882
883# Create a user-defined property
884sub InKana {<<'END'}
8853040    309F
88630A0    30FF
887END
888
889use Unicode::UCD qw(prop_aliases);
890
891is(prop_aliases(undef), undef, "prop_aliases(undef) returns <undef>");
892is(prop_aliases("unknown property"), undef,
893                "prop_aliases(<unknown property>) returns <undef>");
894is(prop_aliases("InKana"), undef,
895                "prop_aliases(<user-defined property>) returns <undef>");
896is(prop_aliases("Perl_Decomposition_Mapping"), undef, "prop_aliases('Perl_Decomposition_Mapping') returns <undef> since internal-Perl-only");
897is(prop_aliases("Perl_Charnames"), undef,
898    "prop_aliases('Perl_Charnames') returns <undef> since internal-Perl-only");
899is(prop_aliases("isgc"), undef,
900    "prop_aliases('isgc') returns <undef> since is not covered Perl extension");
901is(prop_aliases("Is_Is_Any"), undef,
902                "prop_aliases('Is_Is_Any') returns <undef> since two is's");
903is(prop_aliases("ccc=vr"), undef,
904                          "prop_aliases('ccc=vr') doesn't generate a warning");
905
906require 'utf8_heavy.pl';
907require "unicore/Heavy.pl";
908
909# Keys are lists of properties. Values are defined if have been tested.
910my %props;
911
912# To test for loose matching, add in the characters that are ignored there.
913my $extra_chars = "-_ ";
914
915# The one internal property we accept
916$props{'Perl_Decimal_Digit'} = 1;
917my @list = prop_aliases("perldecimaldigit");
918is_deeply(\@list,
919          [ "Perl_Decimal_Digit",
920            "Perl_Decimal_Digit"
921          ], "prop_aliases('perldecimaldigit') returns Perl_Decimal_Digit as both short and full names");
922
923# Get the official Unicode property name synonyms and test them.
924
925SKIP: {
926skip "PropertyAliases.txt is not in this Unicode version", 1 if $v_unicode_version lt v3.2.0;
927open my $props, "<", "../lib/unicore/PropertyAliases.txt"
928                or die "Can't open Unicode PropertyAliases.txt";
929local $/ = "\n";
930while (<$props>) {
931    s/\s*#.*//;           # Remove comments
932    next if /^\s* $/x;    # Ignore empty and comment lines
933
934    chomp;
935    local $/ = $input_record_separator;
936    my $count = 0;  # 0th field in line is short name; 1th is long name
937    my $short_name;
938    my $full_name;
939    my @names_via_short;
940    foreach my $alias (split /\s*;\s*/) {    # Fields are separated by
941                                             # semi-colons
942        # Add in the characters that are supposed to be ignored, to test loose
943        # matching, which the tested function does on all inputs.
944        my $mod_name = "$extra_chars$alias";
945
946        my $loose = &utf8::_loose_name(lc $alias);
947
948        # Indicate we have tested this.
949        $props{$loose} = 1;
950
951        my @all_names = prop_aliases($mod_name);
952        if (grep { $_ eq $loose } @Unicode::UCD::suppressed_properties) {
953            is(@all_names, 0, "prop_aliases('$mod_name') returns undef since $alias is not installed");
954            next;
955        }
956        elsif (! @all_names) {
957            fail("prop_aliases('$mod_name')");
958            diag("'$alias' is unknown to prop_aliases()");
959            next;
960        }
961
962        if ($count == 0) {  # Is short name
963
964            @names_via_short = prop_aliases($mod_name);
965
966            # If the 0th test fails, no sense in continuing with the others
967            last unless is($names_via_short[0], $alias,
968                    "prop_aliases: '$alias' is the short name for '$mod_name'");
969            $short_name = $alias;
970        }
971        elsif ($count == 1) {   # Is full name
972
973            # Some properties have the same short and full name; no sense
974            # repeating the test if the same.
975            if ($alias ne $short_name) {
976                my @names_via_full = prop_aliases($mod_name);
977                is_deeply(\@names_via_full, \@names_via_short, "prop_aliases() returns the same list for both '$short_name' and '$mod_name'");
978            }
979
980            # Tests scalar context
981            is(prop_aliases($short_name), $alias,
982                "prop_aliases: '$alias' is the long name for '$short_name'");
983        }
984        else {  # Is another alias
985            is_deeply(\@all_names, \@names_via_short, "prop_aliases() returns the same list for both '$short_name' and '$mod_name'");
986            ok((grep { $_ =~ /^$alias$/i } @all_names),
987                "prop_aliases: '$alias' is listed as an alias for '$mod_name'");
988        }
989
990        $count++;
991    }
992}
993} # End of SKIP block
994
995# Now test anything we can find that wasn't covered by the tests of the
996# official properties.  We have no way of knowing if mktables omitted a Perl
997# extension or not, but we do the best we can from its generated lists
998
999foreach my $alias (sort keys %utf8::loose_to_file_of) {
1000    next if $alias =~ /=/;
1001    my $lc_name = lc $alias;
1002    my $loose = &utf8::_loose_name($lc_name);
1003    next if exists $props{$loose};  # Skip if already tested
1004    $props{$loose} = 1;
1005    my $mod_name = "$extra_chars$alias";    # Tests loose matching
1006    my @aliases = prop_aliases($mod_name);
1007    my $found_it = grep { &utf8::_loose_name(lc $_) eq $lc_name } @aliases;
1008    if ($found_it) {
1009        pass("prop_aliases: '$lc_name' is listed as an alias for '$mod_name'");
1010    }
1011    elsif ($lc_name =~ /l[_&]$/) {
1012
1013        # These two names are special in that they don't appear in the
1014        # returned list because they are discouraged from use.  Verify
1015        # that they return the same list as a non-discouraged version.
1016        my @LC = prop_aliases('Is_LC');
1017        is_deeply(\@aliases, \@LC, "prop_aliases: '$lc_name' returns the same list as 'Is_LC'");
1018    }
1019    else {
1020        my $stripped = $lc_name =~ s/^is//;
1021
1022        # Could be that the input includes a prefix 'is', which is rarely
1023        # returned as an alias, so having successfully stripped it off above,
1024        # try again.
1025        if ($stripped) {
1026            $found_it = grep { &utf8::_loose_name(lc $_) eq $lc_name } @aliases;
1027        }
1028
1029        # If that didn't work, it could be that it's a block, which is always
1030        # returned with a leading 'In_' to avoid ambiguity.  Try comparing
1031        # with that stripped off.
1032        if (! $found_it) {
1033            $found_it = grep { &utf8::_loose_name(s/^In_(.*)/\L$1/r) eq $lc_name }
1034                              @aliases;
1035            # Could check that is a real block, but tests for invmap will
1036            # likely pickup any errors, since this will be tested there.
1037            $lc_name = "in$lc_name" if $found_it;   # Change for message below
1038        }
1039        my $message = "prop_aliases: '$lc_name' is listed as an alias for '$mod_name'";
1040        ($found_it) ? pass($message) : fail($message);
1041    }
1042}
1043
1044# Some of the Perl extensions should always be built; make sure they have the
1045# correct full name, etc.
1046for my $prop (qw(Alnum Blank Cntrl Digit Graph Print Word XDigit)) {
1047    my @expected = ( $prop, "XPosix$prop" );
1048    my @got = prop_aliases($prop);
1049    splice @got, 2;
1050    is_deeply(\@got, \@expected, "Got expected aliases for $prop");
1051}
1052
1053my $done_equals = 0;
1054foreach my $alias (keys %utf8::stricter_to_file_of) {
1055    if ($alias =~ /=/) {    # Only test one case where there is an equals
1056        next if $done_equals;
1057        $done_equals = 1;
1058    }
1059    my $lc_name = lc $alias;
1060    my @list = prop_aliases($alias);
1061    if ($alias =~ /^_/) {
1062        is(@list, 0, "prop_aliases: '$lc_name' returns an empty list since it is internal_only");
1063    }
1064    elsif ($alias =~ /=/) {
1065        is(@list, 0, "prop_aliases: '$lc_name' returns an empty list since is illegal property name");
1066    }
1067    else {
1068        ok((grep { lc $_ eq $lc_name } @list),
1069                "prop_aliases: '$lc_name' is listed as an alias for '$alias'");
1070    }
1071}
1072
1073use Unicode::UCD qw(prop_values prop_value_aliases);
1074
1075is(prop_value_aliases("unknown property", "unknown value"), undef,
1076    "prop_value_aliases(<unknown property>, <unknown value>) returns <undef>");
1077is(prop_value_aliases(undef, undef), undef,
1078                           "prop_value_aliases(undef, undef) returns <undef>");
1079is((prop_value_aliases("na", "A")), "A", "test that prop_value_aliases returns its input for properties that don't have synonyms");
1080is(prop_value_aliases("isgc", "C"), undef, "prop_value_aliases('isgc', 'C') returns <undef> since is not covered Perl extension");
1081is(prop_value_aliases("gc", "isC"), undef, "prop_value_aliases('gc', 'isC') returns <undef> since is not covered Perl extension");
1082is(prop_value_aliases("Any", "None"), undef, "prop_value_aliases('Any', 'None') returns <undef> since is Perl extension and 'None' is not valid");
1083is(prop_value_aliases("lc", "A"), "A", "prop_value_aliases('lc', 'A') returns its input, as docs say it does");
1084
1085# We have no way of knowing if mktables omitted a Perl extension that it
1086# shouldn't have, but we can check if it omitted an official Unicode property
1087# name synonym.  And for those, we can check if the short and full names are
1088# correct.
1089
1090my %pva_tested;   # List of things already tested.
1091
1092SKIP: {
1093skip "PropValueAliases.txt is not in this Unicode version", 1 if $v_unicode_version lt v3.2.0;
1094open my $propvalues, "<", "../lib/unicore/PropValueAliases.txt"
1095     or die "Can't open Unicode PropValueAliases.txt";
1096local $/ = "\n";
1097
1098# Each examined line in the file is for a single value for a property.  We
1099# accumulate all the values for each property using these two variables.
1100my $prev_prop = "";
1101my @this_prop_values;
1102
1103while (<$propvalues>) {
1104    s/\s*#.*//;           # Remove comments
1105    next if /^\s* $/x;    # Ignore empty and comment lines
1106    chomp;
1107    local $/ = $input_record_separator;
1108
1109    # Fix typo in official input file
1110    s/CCC133/CCC132/g if $v_unicode_version eq v6.1.0;
1111
1112    my @fields = split /\s*;\s*/; # Fields are separated by semi-colons
1113    my $prop = shift @fields;   # 0th field is the property,
1114
1115    # 'qc' is short in early versions of the file for any of the quick check
1116    # properties.  Choose one of them.
1117    if ($prop eq 'qc' && $v_unicode_version le v4.0.0) {
1118        $prop = "NFKC_QC";
1119    }
1120
1121    # When changing properties, we examine the accumulated values for the old
1122    # one to see if our function that returns them matches.
1123    if ($prev_prop ne $prop) {
1124        if ($prev_prop ne "") { # Skip for the first time through
1125            my @ucd_function_values = prop_values($prev_prop);
1126            @ucd_function_values = () unless @ucd_function_values;
1127
1128            # The file didn't include strictly numeric values until after this
1129            if ($prev_prop eq 'ccc' && $v_unicode_version le v6.0.0) {
1130                @ucd_function_values = grep { /\D/ } @ucd_function_values;
1131            }
1132
1133            # This perl extension doesn't appear in the official file
1134            push @this_prop_values, "Non_Canon" if $prev_prop eq 'dt';
1135
1136            my @file_values = undef;
1137            @file_values = sort { lc($a =~ s/_//gr) cmp lc($b =~ s/_//gr) }
1138                                   @this_prop_values if @this_prop_values;
1139            is_deeply(\@ucd_function_values, \@file_values,
1140              "prop_values('$prev_prop') returns correct list of values");
1141        }
1142        $prev_prop = $prop;
1143        undef @this_prop_values;
1144    }
1145
1146    my $count = 0;  # 0th field in line (after shifting off the property) is
1147                    # short name; 1th is long name
1148    my $short_name;
1149    my @names_via_short;    # Saves the values between iterations
1150
1151    # The property on the lhs of the = is always loosely matched.  Add in
1152    # characters that are ignored under loose matching to test that
1153    my $mod_prop = "$extra_chars$prop";
1154
1155    if ($prop eq 'blk' && $v_unicode_version le v5.0.0) {
1156        foreach my $element (@fields) {
1157            $element =~ s/-/_/g;
1158        }
1159    }
1160
1161    if ($fields[0] eq 'n/a') {  # See comments in input file, essentially
1162                                # means full name and short name are identical
1163        $fields[0] = $fields[1];
1164    }
1165    elsif ($fields[0] ne $fields[1]
1166           && &utf8::_loose_name(lc $fields[0])
1167               eq &utf8::_loose_name(lc $fields[1])
1168           && $fields[1] !~ /[[:upper:]]/)
1169    {
1170        # Also, there is a bug in the file in which "n/a" is omitted, and
1171        # the two fields are identical except for case, and the full name
1172        # is all lower case.  Copy the "short" name unto the full one to
1173        # give it some upper case.
1174
1175        $fields[1] = $fields[0];
1176    }
1177
1178    # The ccc property in the file is special; has an extra numeric field
1179    # (0th), which should go at the end, since we use the next two fields as
1180    # the short and full names, respectively.  See comments in input file.
1181    splice (@fields, 0, 0, splice(@fields, 1, 2)) if $prop eq 'ccc';
1182
1183    my $loose_prop = &utf8::_loose_name(lc $prop);
1184    my $suppressed = grep { $_ eq $loose_prop }
1185                          @Unicode::UCD::suppressed_properties;
1186    push @this_prop_values, $fields[0] unless $suppressed;
1187    foreach my $value (@fields) {
1188        if ($suppressed) {
1189            is(prop_value_aliases($prop, $value), undef, "prop_value_aliases('$prop', '$value') returns undef for suppressed property $prop");
1190            next;
1191        }
1192        elsif (grep { $_ eq ("$loose_prop=" . &utf8::_loose_name(lc $value)) } @Unicode::UCD::suppressed_properties) {
1193            is(prop_value_aliases($prop, $value), undef, "prop_value_aliases('$prop', '$value') returns undef for suppressed property $prop=$value");
1194            next;
1195        }
1196
1197        # Add in test for loose matching.
1198        my $mod_value = "$extra_chars$value";
1199
1200        # If the value is a number, optionally negative, including a floating
1201        # point or rational numer, it should be only strictly matched, so the
1202        # loose matching should fail.
1203        if ($value =~ / ^ -? \d+ (?: [\/.] \d+ )? $ /x) {
1204            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");
1205
1206            # And reset so below tests just the strict matching.
1207            $mod_value = $value;
1208        }
1209
1210        if ($count == 0) {
1211
1212            @names_via_short = prop_value_aliases($mod_prop, $mod_value);
1213
1214            # If the 0th test fails, no sense in continuing with the others
1215            last unless is($names_via_short[0], $value, "prop_value_aliases: In '$prop', '$value' is the short name for '$mod_value'");
1216            $short_name = $value;
1217        }
1218        elsif ($count == 1) {
1219
1220            # Some properties have the same short and full name; no sense
1221            # repeating the test if the same.
1222            if ($value ne $short_name) {
1223                my @names_via_full =
1224                            prop_value_aliases($mod_prop, $mod_value);
1225                is_deeply(\@names_via_full, \@names_via_short, "In '$prop', prop_value_aliases() returns the same list for both '$short_name' and '$mod_value'");
1226            }
1227
1228            # Tests scalar context
1229            is(prop_value_aliases($prop, $short_name), $value, "'$value' is the long name for prop_value_aliases('$prop', '$short_name')");
1230        }
1231        else {
1232            my @all_names = prop_value_aliases($mod_prop, $mod_value);
1233            is_deeply(\@all_names, \@names_via_short, "In '$prop', prop_value_aliases() returns the same list for both '$short_name' and '$mod_value'");
1234            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')");
1235        }
1236
1237        $pva_tested{&utf8::_loose_name(lc $prop) . "=" . &utf8::_loose_name(lc $value)} = 1;
1238        $count++;
1239    }
1240}
1241}   # End of SKIP block
1242
1243# And test as best we can, the non-official pva's that mktables generates.
1244foreach my $hash (\%utf8::loose_to_file_of, \%utf8::stricter_to_file_of) {
1245    foreach my $test (sort keys %$hash) {
1246        next if exists $pva_tested{$test};  # Skip if already tested
1247
1248        my ($prop, $value) = split "=", $test;
1249        next unless defined $value; # prop_value_aliases() requires an input
1250                                    # 'value'
1251        my $mod_value;
1252        if ($hash == \%utf8::loose_to_file_of) {
1253
1254            # Add extra characters to test loose-match rhs value
1255            $mod_value = "$extra_chars$value";
1256        }
1257        else { # Here value is strictly matched.
1258
1259            # Extra elements are added by mktables to this hash so that
1260            # something like "age=6.0" has a synonym of "age=6".  It's not
1261            # clear to me (khw) if we should be encouraging those synonyms, so
1262            # don't test for them.
1263            next if $value !~ /\D/ && exists $hash->{"$prop=$value.0"};
1264
1265            # Verify that loose matching fails when only strict is called for.
1266            next unless is(prop_value_aliases($prop, "$extra_chars$value"), undef,
1267                        "prop_value_aliases('$prop', '$extra_chars$value') returns undef since '$value' should be strictly matched"),
1268
1269            # Strict matching does allow for underscores between digits.  Test
1270            # for that.
1271            $mod_value = $value;
1272            while ($mod_value =~ s/(\d)(\d)/$1_$2/g) {}
1273        }
1274
1275        # The lhs property is always loosely matched, so add in extra
1276        # characters to test that.
1277        my $mod_prop = "$extra_chars$prop";
1278
1279        if ($prop eq 'gc' && $value =~ /l[_&]$/) {
1280            # These two names are special in that they don't appear in the
1281            # returned list because they are discouraged from use.  Verify
1282            # that they return the same list as a non-discouraged version.
1283            my @LC = prop_value_aliases('gc', 'lc');
1284            my @l_ = prop_value_aliases($mod_prop, $mod_value);
1285            is_deeply(\@l_, \@LC, "prop_value_aliases('$mod_prop', '$mod_value) returns the same list as prop_value_aliases('gc', 'lc')");
1286        }
1287        else {
1288            ok((grep { &utf8::_loose_name(lc $_) eq &utf8::_loose_name(lc $value) }
1289                prop_value_aliases($mod_prop, $mod_value)),
1290                "'$value' is listed as an alias for prop_value_aliases('$mod_prop', '$mod_value')");
1291        }
1292    }
1293}
1294
1295undef %pva_tested;
1296
1297no warnings 'once'; # We use some values once from 'required' modules.
1298
1299use Unicode::UCD qw(prop_invlist prop_invmap MAX_CP);
1300
1301# There were some problems with caching interfering with prop_invlist() vs
1302# prop_invmap() on binary properties, and also between the 3 properties where
1303# Perl used the same 'To' name as another property (see utf8_heavy.pl).
1304# So, before testing all of prop_invlist(),
1305#   1)  call prop_invmap() to try both orders of these name issues.  This uses
1306#       up two of the 3 properties;  the third will be left so that invlist()
1307#       on it gets called before invmap()
1308#   2)  call prop_invmap() on a generic binary property, ahead of invlist().
1309# This should test that the caching works in both directions.
1310
1311# These properties are not stable between Unicode versions, but the first few
1312# elements are; just look at the first element to see if are getting the
1313# distinction right.  The general inversion map testing below will test the
1314# whole thing.
1315
1316my $prop;
1317my ($invlist_ref, $invmap_ref, $format, $missing);
1318if ($::IS_ASCII) { # On EBCDIC, other things will come first, and can vary
1319                # according to code page
1320    $prop = "uc";
1321    ($invlist_ref, $invmap_ref, $format, $missing) = prop_invmap($prop);
1322    is($format, 'al', "prop_invmap() format of '$prop' is 'al'");
1323    is($missing, '0', "prop_invmap() missing of '$prop' is '0'");
1324    is($invlist_ref->[1], 0x61, "prop_invmap('$prop') list[1] is 0x61");
1325    is($invmap_ref->[1], 0x41, "prop_invmap('$prop') map[1] is 0x41");
1326
1327    $prop = "upper";
1328    ($invlist_ref, $invmap_ref, $format, $missing) = prop_invmap($prop);
1329    is($format, 's', "prop_invmap() format of '$prop' is 's");
1330    is($missing, 'N', "prop_invmap() missing of '$prop' is 'N'");
1331    is($invlist_ref->[1], 0x41, "prop_invmap('$prop') list[1] is 0x41");
1332    is($invmap_ref->[1], 'Y', "prop_invmap('$prop') map[1] is 'Y'");
1333
1334    $prop = "lower";
1335    ($invlist_ref, $invmap_ref, $format, $missing) = prop_invmap($prop);
1336    is($format, 's', "prop_invmap() format of '$prop' is 's'");
1337    is($missing, 'N', "prop_invmap() missing of '$prop' is 'N'");
1338    is($invlist_ref->[1], 0x61, "prop_invmap('$prop') list[1] is 0x61");
1339    is($invmap_ref->[1], 'Y', "prop_invmap('$prop') map[1] is 'Y'");
1340
1341    $prop = "lc";
1342    ($invlist_ref, $invmap_ref, $format, $missing) = prop_invmap($prop);
1343    my $lc_format = ($v_unicode_version ge v3.2.0) ? 'al' : 'a';
1344    is($format, $lc_format, "prop_invmap() format of '$prop' is '$lc_format");
1345    is($missing, '0', "prop_invmap() missing of '$prop' is '0'");
1346    is($invlist_ref->[1], 0x41, "prop_invmap('$prop') list[1] is 0x41");
1347    is($invmap_ref->[1], 0x61, "prop_invmap('$prop') map[1] is 0x61");
1348}
1349
1350# This property is stable and small, so can test all of it
1351if ($v_unicode_version gt v3.1.0) {
1352    $prop = "ASCII_Hex_Digit";
1353    ($invlist_ref, $invmap_ref, $format, $missing) = prop_invmap($prop);
1354    is($format, 's', "prop_invmap() format of '$prop' is 's'");
1355    is($missing, 'N', "prop_invmap() missing of '$prop' is 'N'");
1356    if ($::IS_ASCII) {
1357        is_deeply($invlist_ref, [ 0x0000, 0x0030, 0x003A,
1358                                0x0041, 0x0047,
1359                                0x0061, 0x0067, 0x110000
1360                                ],
1361            "prop_invmap('$prop') code point list is correct");
1362    }
1363    elsif ($::IS_EBCDIC) {
1364        is_deeply($invlist_ref, [
1365                utf8::unicode_to_native(0x0000),
1366                utf8::unicode_to_native(0x0061), utf8::unicode_to_native(0x0066) + 1,
1367                utf8::unicode_to_native(0x0041), utf8::unicode_to_native(0x0046) + 1,
1368                utf8::unicode_to_native(0x0030), utf8::unicode_to_native(0x0039) + 1,
1369                utf8::unicode_to_native(0x110000)
1370            ],
1371            "prop_invmap('$prop') code point list is correct");
1372    }
1373    is_deeply($invmap_ref, [ 'N', 'Y', 'N', 'Y', 'N', 'Y', 'N', 'N' ] ,
1374            "prop_invmap('$prop') map list is correct");
1375}
1376
1377is(prop_invlist("Unknown property"), undef, "prop_invlist(<Unknown property>) returns undef");
1378is(prop_invlist(undef), undef, "prop_invlist(undef) returns undef");
1379is(prop_invlist("Any"), 2, "prop_invlist('Any') returns the number of elements in scalar context");
1380my @invlist = prop_invlist("Is_Any");
1381is_deeply(\@invlist, [ 0, 0x110000 ], "prop_invlist works on 'Is_' prefixes");
1382is(prop_invlist("Is_Is_Any"), undef, "prop_invlist('Is_Is_Any') returns <undef> since two is's");
1383
1384use Storable qw(dclone);
1385
1386is(prop_invlist("InKana"), undef, "prop_invlist(<user-defined property returns undef>)");
1387
1388# The way both the tests for invlist and invmap work is that they take the
1389# lists returned by the functions and construct from them what the original
1390# file should look like, which are then compared with the file.  If they are
1391# identical, the test passes.  What this tests isn't that the results are
1392# correct, but that invlist and invmap haven't introduced errors beyond what
1393# are there in the files.  As a small hedge against that, test some
1394# prop_invlist() tables fully with the known correct result.  We choose
1395# ASCII_Hex_Digit again, as it is stable.
1396if ($v_unicode_version gt v3.1.0) {
1397    if ($::IS_ASCII) {
1398        @invlist = prop_invlist("AHex");
1399        is_deeply(\@invlist, [ 0x0030, 0x003A, 0x0041,
1400                                    0x0047, 0x0061, 0x0067 ],
1401            "prop_invlist('AHex') is exactly the expected set of points");
1402        @invlist = prop_invlist("AHex=f");
1403        is_deeply(\@invlist, [ 0x0000, 0x0030, 0x003A, 0x0041,
1404                                    0x0047, 0x0061, 0x0067 ],
1405            "prop_invlist('AHex=f') is exactly the expected set of points");
1406    }
1407    elsif ($::IS_EBCDIC) { # Relies on the ranges 0-9, a-f, and A-F each being
1408                        # contiguous
1409        @invlist = prop_invlist("AHex");
1410        is_deeply(\@invlist, [
1411                utf8::unicode_to_native(0x0061), utf8::unicode_to_native(0x0066) + 1,
1412                utf8::unicode_to_native(0x0041), utf8::unicode_to_native(0x0046) + 1,
1413                utf8::unicode_to_native(0x0030), utf8::unicode_to_native(0x0039) + 1,
1414        ],
1415        "prop_invlist('AHex') is exactly the expected set of points");
1416        @invlist = prop_invlist("AHex=f");
1417        is_deeply(\@invlist, [
1418                utf8::unicode_to_native(0x0000),
1419                utf8::unicode_to_native(0x0061),
1420                utf8::unicode_to_native(0x0066) + 1,
1421                utf8::unicode_to_native(0x0041),
1422                utf8::unicode_to_native(0x0046) + 1,
1423                utf8::unicode_to_native(0x0030),
1424                utf8::unicode_to_native(0x0039) + 1,
1425        ],
1426        "prop_invlist('AHex=f') is exactly the expected set of points");
1427    }
1428}
1429
1430sub fail_with_diff ($$$$) {
1431    # For use below to output better messages
1432    my ($prop, $official, $constructed, $tested_function_name) = @_;
1433
1434    if (! $ENV{PERL_DIFF_TOOL}) {
1435
1436        is($constructed, $official, "$tested_function_name('$prop')");
1437
1438        diag("Set environment variable PERL_DIFF_TOOL=diff_tool to see just "
1439           . "the differences.");
1440        return;
1441    }
1442
1443    fail("$tested_function_name('$prop')");
1444
1445    require File::Temp;
1446    my $off = File::Temp->new();
1447    local $/ = "\n";
1448    chomp $official;
1449    print $off $official, "\n";
1450    close $off || die "Can't close official";
1451
1452    chomp $constructed;
1453    my $gend = File::Temp->new();
1454    print $gend $constructed, "\n";
1455    close $gend || die "Can't close gend";
1456
1457    my $diff = File::Temp->new();
1458    system("$ENV{PERL_DIFF_TOOL} $off $gend > $diff");
1459
1460    open my $fh, "<", $diff || die "Can't open $diff";
1461    my @diffs = <$fh>;
1462    diag("In the diff output below '<' marks lines from the filesystem tables;\n'>' are from $tested_function_name()");
1463    diag(@diffs);
1464}
1465
1466my %tested_invlist;
1467
1468# Look at everything we think that mktables tells us exists, both loose and
1469# strict
1470foreach my $set_of_tables (\%utf8::stricter_to_file_of, \%utf8::loose_to_file_of)
1471{
1472    foreach my $table (sort keys %$set_of_tables) {
1473
1474        my $mod_table;
1475        my ($prop_only, $value) = split "=", $table;
1476        if (defined $value) {
1477
1478            # If this is to be loose matched, add in characters to test that.
1479            if ($set_of_tables == \%utf8::loose_to_file_of) {
1480                $value = "$extra_chars$value";
1481            }
1482            else {  # Strict match
1483
1484                # Verify that loose matching fails when only strict is called
1485                # for.
1486                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");
1487
1488                # Strict matching does allow for underscores between digits.
1489                # Test for that.
1490                while ($value =~ s/(\d)(\d)/$1_$2/g) {}
1491            }
1492
1493            # The property portion in compound form specifications always
1494            # matches loosely
1495            $mod_table = "$extra_chars$prop_only = $value";
1496        }
1497        else {  # Single-form.
1498
1499            # Like above, use loose if required, and insert underscores
1500            # between digits if strict.
1501            if ($set_of_tables == \%utf8::loose_to_file_of) {
1502                $mod_table = "$extra_chars$table";
1503            }
1504            else {
1505                $mod_table = $table;
1506                while ($mod_table =~ s/(\d)(\d)/$1_$2/g) {}
1507            }
1508        }
1509
1510        my @tested = prop_invlist($mod_table);
1511        if ($table =~ /^_/) {
1512            is(@tested, 0, "prop_invlist('$mod_table') returns an empty list since is internal-only");
1513            next;
1514        }
1515
1516        # If we have already tested a property that uses the same file, this
1517        # list should be identical to the one that was tested, and can bypass
1518        # everything else.
1519        my $file = $set_of_tables->{$table};
1520        if (exists $tested_invlist{$file}) {
1521            is_deeply(\@tested, $tested_invlist{$file}, "prop_invlist('$mod_table') gave same results as its name synonym");
1522            next;
1523        }
1524        $tested_invlist{$file} = dclone \@tested;
1525
1526        # A '!' in the file name means that it is to be inverted.
1527        my $invert = $file =~ s/!//;
1528        my $official;
1529
1530        # If the file's directory is '#', it is a special case where the
1531        # contents are in-lined with semi-colons meaning new-lines, instead of
1532        # it being an actual file to read.  The file is an index in to the
1533        # array of the definitions
1534        if ($file =~ s!^#/!!) {
1535            $official = $utf8::inline_definitions[$file];
1536        }
1537        else {
1538            $official = do "unicore/lib/$file.pl";
1539        }
1540
1541        # Get rid of any trailing space and comments in the file.
1542        $official =~ s/\s*(#.*)?$//mg;
1543        local $/ = "\n";
1544        chomp $official;
1545        $/ = $input_record_separator;
1546
1547        # If we are to test against an inverted file, it is easier to invert
1548        # our array than the file.
1549        if ($invert) {
1550            if (@tested && $tested[0] == 0) {
1551                shift @tested;
1552            } else {
1553                unshift @tested, 0;
1554            }
1555        }
1556
1557        # Now construct a string from the list that should match the file.
1558        # The file is inversion list format code points, like this:
1559        # V1216
1560        # 65      # [26]
1561        # 91
1562        # 192     # [23]
1563        # ...
1564        # The V indicates it's an inversion list, and is followed immediately
1565        # by the number of elements (lines) that follow giving its contents.
1566        # The list has even numbered elements (0th, 2nd, ...) start ranges
1567        # that are in the list, and odd ones that aren't in the list.
1568        # Therefore the odd numbered ones are one beyond the end of the
1569        # previous range, but otherwise don't get reflected in the file.
1570        my $tested =  join "\n", ("V" . scalar @tested), @tested;
1571        local $/ = "\n";
1572        chomp $tested;
1573        $/ = $input_record_separator;
1574        if ($tested ne $official) {
1575            fail_with_diff($mod_table, $official, $tested, "prop_invlist");
1576            next;
1577        }
1578
1579        pass("prop_invlist('$mod_table')");
1580    }
1581}
1582
1583# Now test prop_invmap().
1584
1585@list = prop_invmap("Unknown property");
1586is (@list, 0, "prop_invmap(<Unknown property>) returns an empty list");
1587@list = prop_invmap(undef);
1588is (@list, 0, "prop_invmap(undef) returns an empty list");
1589ok (! eval "prop_invmap('gc')" && $@ ne "",
1590                                "prop_invmap('gc') dies in scalar context");
1591@list = prop_invmap("_X_Begin");
1592is (@list, 0, "prop_invmap(<internal property>) returns an empty list");
1593@list = prop_invmap("InKana");
1594is(@list, 0, "prop_invmap(<user-defined property returns undef>)");
1595@list = prop_invmap("Perl_Decomposition_Mapping"), undef,
1596is(@list, 0, "prop_invmap('Perl_Decomposition_Mapping') returns <undef> since internal-Perl-only");
1597@list = prop_invmap("Perl_Charnames"), undef,
1598is(@list, 0, "prop_invmap('Perl_Charnames') returns <undef> since internal-Perl-only");
1599@list = prop_invmap("Is_Is_Any");
1600is(@list, 0, "prop_invmap('Is_Is_Any') returns <undef> since two is's");
1601
1602# The files for these properties are not used by Perl, but are retained for
1603# backwards compatibility with applications that read them directly, with
1604# comments in them that their use is deprecated.  Until such time as we remove
1605# them completely, we test that they exist, are correct, and that their
1606# formats haven't changed.  This hash contains the info needed to test them as
1607# if they were regular properties.  'replaced_by' gives the equivalent
1608# property now used by Perl.
1609my %legacy_props = (
1610            Legacy_Case_Folding =>        { replaced_by => 'cf',
1611                                            file => 'To/Fold',
1612                                            swash_name => 'ToFold'
1613                                          },
1614            Legacy_Lowercase_Mapping =>   { replaced_by => 'lc',
1615                                            file => 'To/Lower',
1616                                            swash_name => 'ToLower'
1617                                          },
1618            Legacy_Titlecase_Mapping =>   { replaced_by => 'tc',
1619                                            file => 'To/Title',
1620                                            swash_name => 'ToTitle'
1621                                          },
1622            Legacy_Uppercase_Mapping =>   { replaced_by => 'uc',
1623                                            file => 'To/Upper',
1624                                            swash_name => 'ToUpper'
1625                                          },
1626            Legacy_Perl_Decimal_Digit =>  { replaced_by => 'Perl_Decimal_Digit',
1627                                            file => 'To/Digit',
1628                                            swash_name => 'ToDigit'
1629                                           },
1630        );
1631
1632foreach my $legacy_prop (keys %legacy_props) {
1633    @list = prop_invmap($legacy_prop);
1634    is(@list, 0, "'$legacy_prop' is unknown to prop_invmap");
1635}
1636
1637# The files for these properties shouldn't have their formats changed in case
1638# applications use them (though such use is deprecated).
1639my @legacy_file_format = (keys %legacy_props,
1640                          qw( Bidi_Mirroring_Glyph
1641                              NFKC_Casefold
1642                           )
1643                          );
1644
1645# The set of properties to test on has already been compiled into %props by
1646# the prop_aliases() tests.
1647
1648my %tested_invmaps;
1649
1650# Like prop_invlist(), prop_invmap() is tested by comparing the results
1651# returned by the function with the tables that mktables generates.  Some of
1652# these tables are directly stored as files on disk, in either the unicore or
1653# unicore/To directories, and most should be listed in the mktables generated
1654# hash %utf8::loose_property_to_file_of, with a few additional ones that this
1655# handles specially.  For these, the files are read in directly, massaged, and
1656# compared with what invmap() returns.  The SPECIALS hash in some of these
1657# files overrides values in the main part of the file.
1658#
1659# The other properties are tested indirectly by generating all the possible
1660# inversion lists for the property, and seeing if those match the inversion
1661# lists returned by prop_invlist(), which has already been tested.
1662
1663PROPERTY:
1664foreach my $prop (sort(keys %props), sort keys %legacy_props) {
1665    my $is_legacy = 0;
1666    my $loose_prop = &utf8::_loose_name(lc $prop);
1667    my $suppressed = grep { $_ eq $loose_prop }
1668                          @Unicode::UCD::suppressed_properties;
1669
1670    my $actual_lookup_prop;
1671    my $display_prop;        # The property name that is displayed, as opposed
1672                             # to the one that is actually used.
1673
1674    # Find the short and full names that this property goes by
1675    my ($name, $full_name) = prop_aliases($prop);
1676    if (! $name) {
1677
1678        # Here, Perl doesn't know about this property.  It could be a
1679        # suppressed one, or a legacy one.
1680        if (grep { $prop eq $_ } keys %legacy_props) {
1681
1682            # For legacy properties, we look up the modern equivalent
1683            # property instead; later massaging the results to look like the
1684            # known format of the legacy property.  We add info about the
1685            # legacy property to the data structures for the rest of the
1686            # properties; this is to avoid more special cases for the legacies
1687            # in the code below
1688            $full_name = $name = $prop;
1689            $actual_lookup_prop = $legacy_props{$prop}->{'replaced_by'};
1690            my $base_file = $legacy_props{$prop}->{'file'};
1691
1692            # This legacy property is otherwise unknown to Perl; so shouldn't
1693            # have any information about it already.
1694            ok(! exists $utf8::loose_property_to_file_of{$loose_prop},
1695               "There isn't a hash entry for file lookup of $prop");
1696            $utf8::loose_property_to_file_of{$loose_prop} = $base_file;
1697
1698            ok(! exists $utf8::file_to_swash_name{$loose_prop},
1699               "There isn't a hash entry for swash lookup of $prop");
1700            $utf8::file_to_swash_name{$base_file}
1701                                        = $legacy_props{$prop}->{'swash_name'};
1702            $display_prop = $prop;
1703            $is_legacy = 1;
1704        }
1705        else {
1706            if (! $suppressed) {
1707                fail("prop_invmap('$prop')");
1708                diag("is unknown to prop_aliases(), and we need it in order to test prop_invmap");
1709            }
1710            next PROPERTY;
1711        }
1712    }
1713
1714    # Normalize the short name, as it is stored in the hashes under the
1715    # normalized version.
1716    $name = &utf8::_loose_name(lc $name);
1717
1718    # In the case of a combination property, both a map table and a match
1719    # table are generated.  For all the tests except prop_invmap(), this is
1720    # irrelevant, but for prop_invmap, having an 'is' prefix forces it to
1721    # return the match table; otherwise the map.  We thus need to distinguish
1722    # between the two forms.  The property name is what has this information.
1723    $name = &utf8::_loose_name(lc $prop)
1724                         if exists $Unicode::UCD::combination_property{$name};
1725
1726    # Add in the characters that are supposed to be ignored to test loose
1727    # matching, which the tested function applies to all properties
1728    $display_prop = "$extra_chars$prop" unless $display_prop;
1729    $actual_lookup_prop = $display_prop unless $actual_lookup_prop;
1730
1731    my ($invlist_ref, $invmap_ref, $format, $missing) = prop_invmap($actual_lookup_prop);
1732    my $return_ref = [ $invlist_ref, $invmap_ref, $format, $missing ];
1733
1734
1735    # The legacy property files all are expanded out so that each range is 1
1736    # element long.  That isn't true of the modern equivalent we use to check
1737    # those files for correctness against.  So take the output of the proxy
1738    # and expand it to match the legacy file.
1739    if ($is_legacy) {
1740        my @expanded_list;
1741        my @expanded_map;
1742        for my $i (0 .. @$invlist_ref - 1 - 1) {
1743            if (ref $invmap_ref->[$i] || $invmap_ref->[$i] eq $missing) {
1744
1745                # No adjustments should be done for the default mapping and
1746                # the multi-char ones.
1747                push @expanded_list, $invlist_ref->[$i];
1748                push @expanded_map, $invmap_ref->[$i];
1749            }
1750            else {
1751
1752                # Expand the range into separate elements for each item.
1753                my $offset = 0;
1754                for my $j ($invlist_ref->[$i] .. $invlist_ref->[$i+1] -1) {
1755                    push @expanded_list, $j;
1756                    push @expanded_map, $invmap_ref->[$i] + $offset;
1757
1758                    # The 'ae' format is for Legacy_Perl_Decimal_Digit; the
1759                    # other 4 are kept with leading zeros in the file, so
1760                    # convert to that.
1761                    $expanded_map[-1] = sprintf("%04X", $expanded_map[-1])
1762                                                            if $format ne 'ae';
1763                    $offset++;
1764                }
1765            }
1766        }
1767
1768        # Final element is taken as is.  The map should always be to the
1769        # default value, so don't do a sprintf like we did above.
1770        push @expanded_list, $invlist_ref->[-1];
1771        push @expanded_map, $invmap_ref->[-1];
1772
1773        $invlist_ref = \@expanded_list;
1774        $invmap_ref = \@expanded_map;
1775    }
1776
1777    # If have already tested this property under a different name, merely
1778    # compare the return from now with the saved one from before.
1779    if (exists $tested_invmaps{$name}) {
1780        is_deeply($return_ref, $tested_invmaps{$name}, "prop_invmap('$display_prop') gave same results as its synonym, '$name'");
1781        next PROPERTY;
1782    }
1783    $tested_invmaps{$name} = dclone $return_ref;
1784
1785    # If prop_invmap() returned nothing, is ok iff is a property whose file is
1786    # not generated.
1787    if ($suppressed) {
1788        if (defined $format) {
1789            fail("prop_invmap('$display_prop')");
1790            diag("did not return undef for suppressed property $prop");
1791        }
1792        next PROPERTY;
1793    }
1794    elsif (!defined $format) {
1795        fail("prop_invmap('$display_prop')");
1796        diag("'$prop' is unknown to prop_invmap()");
1797        next PROPERTY;
1798    }
1799
1800    # The two parallel arrays must have the same number of elements.
1801    if (@$invlist_ref != @$invmap_ref) {
1802        fail("prop_invmap('$display_prop')");
1803        diag("invlist has "
1804             . scalar @$invlist_ref
1805             . " while invmap has "
1806             . scalar @$invmap_ref
1807             . " elements");
1808        next PROPERTY;
1809    }
1810
1811    # The last element must be for the above-Unicode code points, and must be
1812    # for the default value.
1813    if ($invlist_ref->[-1] != 0x110000) {
1814        fail("prop_invmap('$display_prop')");
1815        diag("The last inversion list element is not 0x110000");
1816        next PROPERTY;
1817    }
1818
1819    my $upper_limit_subtract;
1820
1821    # prop_invmap() adds an extra element not present in the disk files for
1822    # the above-Unicode code points.  For almost all properties, that will be
1823    # to $missing.  In that case we don't look further at it when comparing
1824    # with the disk files.
1825    if ($invmap_ref->[-1] eq $missing) {
1826        $upper_limit_subtract = 1;
1827    }
1828    elsif ($invmap_ref->[-1] eq 'Y' && ! grep { $_ !~ /[YN]/ } @$invmap_ref) {
1829
1830        # But that's not true for a few binary properties like 'Unassigned'
1831        # that are Perl extensions (in this case for Gc=Unassigned) which
1832        # match above-Unicode code points (hence the 'Y' in the test above).
1833        # For properties where it isn't $missing, we're going to want to look
1834        # at the whole thing when comparing with the disk file.
1835        $upper_limit_subtract = 0;
1836
1837        # In those properties like 'Unassigned, the final element should be
1838        # just a repetition of the next-to-last element, and won't be in the
1839        # disk file, so remove it for the comparison.  Otherwise, we will
1840        # compare the whole of the array with the whole of the disk file.
1841        if ($invlist_ref->[-2] <= 0x10FFFF && $invmap_ref->[-2] eq 'Y') {
1842            pop @$invlist_ref;
1843            pop @$invmap_ref;
1844        }
1845    }
1846    else {
1847        fail("prop_invmap('$display_prop')");
1848        diag("The last inversion list element is '$invmap_ref->[-1]', and should be '$missing'");
1849        next PROPERTY;
1850    }
1851
1852    if ($name eq 'bmg') {   # This one has an atypical $missing
1853        if ($missing ne "") {
1854            fail("prop_invmap('$display_prop')");
1855            diag("The missings should be \"\"; got '$missing'");
1856            next PROPERTY;
1857        }
1858    }
1859    elsif ($format =~ /^ a (?!r) /x) {
1860        if ($full_name eq 'Perl_Decimal_Digit') {
1861            if ($missing ne "") {
1862                fail("prop_invmap('$display_prop')");
1863                diag("The missings should be \"\"; got '$missing'");
1864                next PROPERTY;
1865            }
1866        }
1867        elsif ($missing ne "0" && ! grep { $prop eq $_ } keys %legacy_props) {
1868            fail("prop_invmap('$display_prop')");
1869            diag("The missings should be '0'; got '$missing'");
1870            next PROPERTY;
1871        }
1872    }
1873    elsif ($missing =~ /[<>]/) {
1874        fail("prop_invmap('$display_prop')");
1875        diag("The missings should NOT be something with <...>'");
1876        next PROPERTY;
1877
1878        # I don't want to hard code in what all the missings should be, so
1879        # those don't get fully tested.
1880    }
1881
1882    # Certain properties don't have their own files, but must be constructed
1883    # using proxies.
1884    my $proxy_prop = $name;
1885    if ($full_name eq 'Present_In') {
1886        $proxy_prop = "age";    # The maps for these two props are identical
1887    }
1888    elsif ($full_name eq 'Simple_Case_Folding'
1889           || $full_name =~ /Simple_ (.) .*? case_Mapping  /x)
1890    {
1891        if ($full_name eq 'Simple_Case_Folding') {
1892            $proxy_prop = 'cf';
1893        }
1894        else {
1895            # We captured the U, L, or T, leading to uc, lc, or tc.
1896            $proxy_prop = lc $1 . "c";
1897        }
1898        if ($format ne "a") {
1899            fail("prop_invmap('$display_prop')");
1900            diag("The format should be 'a'; got '$format'");
1901            next PROPERTY;
1902        }
1903    }
1904
1905    if ($format !~ / ^ (?: a [der]? | ale? | n | sl? ) $ /x) {
1906        fail("prop_invmap('$display_prop')");
1907        diag("Unknown format '$format'");
1908        next PROPERTY;
1909    }
1910
1911    my $base_file;
1912    my $official;
1913
1914    # Handle the properties that have full disk files for them (except the
1915    # Name property which is structurally enough different that it is handled
1916    # separately below.)
1917    if ($name ne 'na'
1918        && ($name eq 'blk'
1919            || defined
1920                    ($base_file = $utf8::loose_property_to_file_of{$proxy_prop})
1921            || exists $utf8::loose_to_file_of{$proxy_prop}
1922            || $name eq "dm"))
1923    {
1924        # In the above, blk is done unconditionally, as we need to test that
1925        # the old-style block names are returned, even if mktables has
1926        # generated a file for the new-style; the test for dm comes afterward,
1927        # so that if a file has been generated for it explicitly, we use that
1928        # file (which is valid, unlike blk) instead of the combo
1929        # Decomposition.pl files.
1930        my $file;
1931        my $is_binary = 0;
1932        if ($name eq 'blk') {
1933
1934            # The blk property is special.  The original file with old block
1935            # names is retained, and the default (on ASCII platforms) is to
1936            # not write out a new-name file.  What we do is get the old names
1937            # into a data structure, and from that create what the new file
1938            # would look like.  $base_file is needed to be defined, just to
1939            # avoid a message below.
1940            $base_file = "This is a dummy name";
1941            my $blocks_ref = charblocks();
1942
1943            if ($::IS_EBCDIC) {
1944                # On EBCDIC, the first two blocks can each contain multiple
1945                # ranges.  We create a new version with each of these
1946                # flattened, so have one level.  ($index is used as a dummy
1947                # key.)
1948                my %new_blocks;
1949                my $index = 0;
1950                foreach my $block (values %$blocks_ref) {
1951                    foreach my $range (@$block) {
1952                        $new_blocks{$index++}[0] = $range;
1953                    }
1954                }
1955                $blocks_ref = \%new_blocks;
1956            }
1957            $official = "";
1958            for my $range (sort { $a->[0][0] <=> $b->[0][0] }
1959                           values %$blocks_ref)
1960            {
1961                # Translate the charblocks() data structure to what the file
1962                # would look like.  (The sub range is for EBCDIC platforms
1963                # where Latin1 and ASCII are intermixed.)
1964                if ($range->[0][0] == $range->[0][1]) {
1965                    $official .= sprintf("%X\t\t%s\n",
1966                                         $range->[0][0],
1967                                         $range->[0][2]);
1968                }
1969                else {
1970                    $official .= sprintf("%X\t%X\t%s\n",
1971                                         $range->[0][0],
1972                                         $range->[0][1],
1973                                         $range->[0][2]);
1974                }
1975            }
1976        }
1977        else {
1978            $base_file = "Decomposition" if $format eq 'ad';
1979
1980            # Above leaves $base_file undefined only if it came from the hash
1981            # below.  This should happen only when it is a binary property
1982            # (and are accessing via a single-form name, like 'In_Latin1'),
1983            # and so it is stored in a different directory than the To ones.
1984            # XXX Currently, the only cases where it is complemented are the
1985            # ones that have no code points.  And it works out for these that
1986            # 1) complementing them, and then 2) adding or subtracting the
1987            # initial 0 and final 110000 cancel each other out.  But further
1988            # work would be needed in the unlikely event that an inverted
1989            # property comes along without these characteristics
1990            if (!defined $base_file) {
1991                $base_file = $utf8::loose_to_file_of{$proxy_prop};
1992                $is_binary = ($base_file =~ s/!//) ? -1 : 1;
1993                $base_file = "lib/$base_file" unless $base_file =~ m!^#/!;
1994            }
1995
1996            # Read in the file.  If the file's directory is '#', it is a
1997            # special case where the contents are in-lined with semi-colons
1998            # meaning new-lines, instead of it being an actual file to read.
1999            if ($base_file =~ s!^#/!!) {
2000                $official = $utf8::inline_definitions[$base_file];
2001            }
2002            else {
2003                $official = do "unicore/$base_file.pl";
2004            }
2005
2006            # Get rid of any trailing space and comments in the file.
2007            $official =~ s/\s*(#.*)?$//mg;
2008
2009            if ($format eq 'ad') {
2010                my @official = split /\n/, $official;
2011                $official = "";
2012                foreach my $line (@official) {
2013                    my ($start, $end, $value)
2014                                    = $line =~ / ^ (.+?) \t (.*?) \t (.+?)
2015                                                \s* ( \# .* )? $ /x;
2016                    # Decomposition.pl also has the <compatible> types in it,
2017                    # which should be removed.
2018                    $value =~ s/<.*?> //;
2019                    $official .= "$start\t\t$value\n";
2020
2021                    # If this is a multi-char range, we turn it into as many
2022                    # single character ranges as necessary.  This makes things
2023                    # easier below.
2024                    if ($end ne "") {
2025                        for my $i (hex($start) + 1 .. hex $end) {
2026                            $official .= sprintf "%X\t\t%s\n", $i, $value;
2027                        }
2028                    }
2029                }
2030            }
2031        }
2032        local $/ = "\n";
2033        chomp $official;
2034        $/ = $input_record_separator;
2035
2036        # Get the format for the file, and if there are any special elements,
2037        # get a reference to them.
2038        my $swash_name = $utf8::file_to_swash_name{$base_file};
2039        my $specials_ref;
2040        my $file_format;    # The 'format' given inside the file
2041        if ($swash_name) {
2042            $specials_ref = $utf8::SwashInfo{$swash_name}{'specials_name'};
2043            if ($specials_ref) {
2044
2045                # Convert from the name to the actual reference.
2046                no strict 'refs';
2047                $specials_ref = \%{$specials_ref};
2048            }
2049
2050            $file_format = $utf8::SwashInfo{$swash_name}{'format'};
2051        }
2052
2053        # Leading zeros used to be used with the values in the files that give,
2054        # ranges, but these have been mostly stripped off, except for some
2055        # files whose formats should not change in any way.
2056        my $file_range_format = (grep { $full_name eq $_ } @legacy_file_format)
2057                              ? "%04X"
2058                              : "%X";
2059        # Currently this property still has leading zeroes in the mapped-to
2060        # values, but otherwise, those values follow the same rules as the
2061        # ranges.
2062        my $file_map_format = ($full_name eq 'Decomposition_Mapping')
2063                              ? "%04X"
2064                              : $file_range_format;
2065
2066        # Certain of the proxy properties have to be adjusted to match the
2067        # real ones.
2068        if ($full_name
2069                 =~ /^(Legacy_)?(Case_Folding|(Lower|Title|Upper)case_Mapping)/)
2070        {
2071
2072            # Here we have either
2073            #   1) Case_Folding; or
2074            #   2) a proxy that is a full mapping, which means that what the
2075            #      real property is is the equivalent simple mapping.
2076            # In both cases, the file will have a standard list containing
2077            # simple mappings (to a single code point), and a specials hash
2078            # which contains all the mappings that are to multiple code
2079            # points.  First, extract a list containing all the file's simple
2080            # mappings.
2081            my @list;
2082            for (split "\n", $official) {
2083                my ($start, $end, $value) = / ^ (.+?) \t (.*?) \t (.+?)
2084                                                \s* ( \# .* )? $ /x;
2085                $end = $start if $end eq "";
2086                push @list, [ hex $start, hex $end, hex $value ];
2087            }
2088
2089            # For these mappings, the file contains all the simple mappings,
2090            # including the ones that are overridden by the specials.  These
2091            # need to be removed as the list is for just the full ones.
2092
2093            # Go through any special mappings one by one.  The keys are the
2094            # UTF-8 representation of code points.
2095            my $i = 0;
2096            foreach my $utf8_cp (sort keys %$specials_ref) {
2097                my $cp = $utf8_cp;
2098                utf8::decode($cp);
2099                $cp = ord $cp;
2100
2101                # Find the spot in the @list of simple mappings that this
2102                # special applies to; uses a linear search.
2103                while ($i < @list -1 ) {
2104                    last if  $cp <= $list[$i][1];
2105                    $i++;
2106                }
2107
2108                # Here $i is such that it points to the first range which ends
2109                # at or above cp, and hence is the only range that could
2110                # possibly contain it.
2111
2112                # If not in this range, no range contains it: nothing to
2113                # remove.
2114                next if $cp < $list[$i][0];
2115
2116                # Otherwise, remove the existing entry.  If it is the first
2117                # element of the range...
2118                if ($cp == $list[$i][0]) {
2119
2120                    # ... and there are other elements in the range, just
2121                    # shorten the range to exclude this code point.
2122                    if ($list[$i][1] > $list[$i][0]) {
2123                        $list[$i][0]++;
2124                    }
2125
2126                    # ... but if it is the only element in the range, remove
2127                    # it entirely.
2128                    else {
2129                        splice @list, $i, 1;
2130                    }
2131                }
2132                else { # Is somewhere in the middle of the range
2133                    # Split the range into two, excluding this one in the
2134                    # middle
2135                    splice @list, $i, 1,
2136                           [ $list[$i][0], $cp - 1, $list[$i][2] ],
2137                           [ $cp + 1, $list[$i][1], $list[$i][2] ];
2138                }
2139            }
2140
2141            # Here, have gone through all the specials, modifying @list as
2142            # needed.  Turn it back into what the file should look like.
2143            $official = "";
2144            for my $element (@list) {
2145                $official .= "\n" if $official;
2146                if ($element->[1] == $element->[0]) {
2147                    $official
2148                        .= sprintf "$file_range_format\t\t$file_map_format",
2149                                    $element->[0],        $element->[2];
2150                }
2151                else {
2152                    $official .= sprintf "$file_range_format\t$file_range_format\t$file_map_format",
2153                                         $element->[0],
2154                                         $element->[1],
2155                                         $element->[2];
2156                }
2157            }
2158        }
2159        elsif ($full_name
2160            =~ / ^ Simple_(Case_Folding|(Lower|Title|Upper)case_Mapping) $ /x)
2161        {
2162
2163            # These properties have everything in the regular array, and the
2164            # specials are superfluous.
2165            undef $specials_ref;
2166        }
2167        elsif ($format !~ /^a/ && defined $file_format && $file_format eq 'x') {
2168
2169            # For these properties the file is output using hex notation for the
2170            # map.  Convert from hex to decimal.
2171            my @lines = split "\n", $official;
2172            foreach my $line (@lines) {
2173                my ($lower, $upper, $map) = split "\t", $line;
2174                $line = "$lower\t$upper\t" . hex $map;
2175            }
2176            $official = join "\n", @lines;
2177        }
2178
2179        # Here, in $official, we have what the file looks like, or should like
2180        # if we've had to fix it up.  Now take the invmap() output and reverse
2181        # engineer from that what the file should look like.  Each iteration
2182        # appends the next line to the running string.
2183        my $tested_map = "";
2184
2185        # For use with files for binary properties only, which are stored in
2186        # inversion list format.  This counts the number of data lines in the
2187        # file.
2188        my $binary_count = 0;
2189
2190        # Create a copy of the file's specials hash.  (It has been undef'd if
2191        # we know it isn't relevant to this property, so if it exists, it's an
2192        # error or is relevant).  As we go along, we delete from that copy.
2193        # If a delete fails, or something is left over after we are done,
2194        # it's an error
2195        my %specials = %$specials_ref if $specials_ref;
2196
2197        # The extra -$upper_limit_subtract is because the final element may
2198        # have been tested above to be for anything above Unicode, in which
2199        # case the file may not go that high.
2200        for (my $i = 0; $i < @$invlist_ref - $upper_limit_subtract; $i++) {
2201
2202            # If the map element is a reference, have to stringify it (but
2203            # don't do so if the format doesn't allow references, so that an
2204            # improper format will generate an error.
2205            if (ref $invmap_ref->[$i]
2206                && ($format eq 'ad' || $format =~ /^ . l /x))
2207            {
2208                # The stringification depends on the format.
2209                if ($format eq 'sl') {
2210
2211                    # At the time of this writing, there are two types of 'sl'
2212                    # format  One, in Name_Alias, has multiple separate
2213                    # entries for each code point; the other, in
2214                    # Script_Extension, is space separated.  Assume the latter
2215                    # for non-Name_Alias.
2216                    if ($full_name ne 'Name_Alias') {
2217                        $invmap_ref->[$i] = join " ", @{$invmap_ref->[$i]};
2218                    }
2219                    else {
2220                        # For Name_Alias, we emulate the file.  Entries with
2221                        # just one value don't need any changes, but we
2222                        # convert the list entries into a series of lines for
2223                        # the file, starting with the first name.  The
2224                        # succeeding entries are on separate lines, with the
2225                        # code point repeated for each one and then two tabs,
2226                        # then the value.  Code at the end of the loop will
2227                        # set up the first line with its code point and two
2228                        # tabs before the value, just as it does for every
2229                        # other property; thus the special handling of the
2230                        # first line.
2231                        if (ref $invmap_ref->[$i]) {
2232                            my $hex_cp = sprintf("%X", $invlist_ref->[$i]);
2233                            my $concatenated = $invmap_ref->[$i][0];
2234                            for (my $j = 1; $j < @{$invmap_ref->[$i]}; $j++) {
2235                                $concatenated .= "\n$hex_cp\t\t"
2236                                              .  $invmap_ref->[$i][$j];
2237                            }
2238                            $invmap_ref->[$i] = $concatenated;
2239                        }
2240                    }
2241                }
2242                elsif ($format =~ / ^ al e? $/x) {
2243
2244                    # For an al property, the stringified result should be in
2245                    # the specials hash.  The key is the utf8 bytes of the
2246                    # code point, and the value is its map as a utf-8 string.
2247                    my $value;
2248                    my $key = chr $invlist_ref->[$i];
2249                    utf8::encode($key);
2250                    if (! defined ($value = delete $specials{$key})) {
2251                        fail("prop_invmap('$display_prop')");
2252                        diag(sprintf "There was no specials element for %04X", $invlist_ref->[$i]);
2253                        next PROPERTY;
2254                    }
2255                    my $packed = pack "W*", @{$invmap_ref->[$i]};
2256                    utf8::upgrade($packed);
2257                    if ($value ne $packed) {
2258                        fail("prop_invmap('$display_prop')");
2259                        diag(sprintf "For %04X, expected the mapping to be "
2260                         . "'$packed', but got '$value'", $invlist_ref->[$i]);
2261                        next PROPERTY;
2262                    }
2263
2264                    # As this doesn't get tested when we later compare with
2265                    # the actual file, it could be out of order and we
2266                    # wouldn't know it.
2267                    if (($i > 0 && $invlist_ref->[$i] <= $invlist_ref->[$i-1])
2268                        || $invlist_ref->[$i] >= $invlist_ref->[$i+1])
2269                    {
2270                        fail("prop_invmap('$display_prop')");
2271                        diag(sprintf "Range beginning at %04X is out-of-order.", $invlist_ref->[$i]);
2272                        next PROPERTY;
2273                    }
2274                    next;
2275                }
2276                elsif ($format eq 'ad') {
2277
2278                    # The decomposition mapping file has the code points as
2279                    # a string of space-separated hex constants.
2280                    $invmap_ref->[$i] = join " ", map { sprintf "%04X", $_ }
2281                                                           @{$invmap_ref->[$i]};
2282                }
2283                else {
2284                    fail("prop_invmap('$display_prop')");
2285                    diag("Can't handle format '$format'");
2286                    next PROPERTY;
2287                }
2288            } # Otherwise, the map is to a simple scalar
2289            elsif (defined $file_format && $file_format eq 'ax') {
2290                # These maps are in hex
2291                $invmap_ref->[$i] = sprintf("%X", $invmap_ref->[$i]);
2292            }
2293            elsif ($format eq 'ad' || $format eq 'ale') {
2294
2295                # The numerics in the returned map are stored as adjusted
2296                # decimal integers.  The defaults are 0, and don't appear in
2297                # $official, and are excluded later, but the elements must be
2298                # converted back to their hex values before comparing with
2299                # $official, as these files, for backwards compatibility, are
2300                # not stored as adjusted.  (There currently is only one ale
2301                # property, nfkccf.  If that changed this would also have to.)
2302                if ($invmap_ref->[$i] =~ / ^ -? \d+ $ /x
2303                    && $invmap_ref->[$i] != 0)
2304                {
2305                    my $next = $invmap_ref->[$i] + 1;
2306                    $invmap_ref->[$i] = sprintf($file_map_format,
2307                                                $invmap_ref->[$i]);
2308
2309                    # If there are other elements in this range they need to
2310                    # be adjusted; they must individually be re-mapped.  Do
2311                    # this by splicing in a new element into the list and the
2312                    # map containing the remainder of the range.  Next time
2313                    # through we will look at that (possibly splicing again
2314                    # until the whole range is processed).
2315                    if ($invlist_ref->[$i+1] > $invlist_ref->[$i] + 1) {
2316                        splice @$invlist_ref, $i+1, 0,
2317                                $invlist_ref->[$i] + 1;
2318                        splice @$invmap_ref, $i+1, 0, $next;
2319                    }
2320                }
2321                if ($format eq 'ale' && $invmap_ref->[$i] eq "") {
2322
2323                    # ale properties have maps to the empty string that also
2324                    # should be in the specials hash, with the key the utf8
2325                    # bytes representing the code point, and the map just empty.
2326                    my $value;
2327                    my $key = chr $invlist_ref->[$i];
2328                    utf8::encode($key);
2329                    if (! defined ($value = delete $specials{$key})) {
2330                        fail("prop_invmap('$display_prop')");
2331                        diag(sprintf "There was no specials element for %04X", $invlist_ref->[$i]);
2332                        next PROPERTY;
2333                    }
2334                    if ($value ne "") {
2335                        fail("prop_invmap('$display_prop')");
2336                        diag(sprintf "For %04X, expected the mapping to be \"\", but got '$value'", $invlist_ref->[$i]);
2337                        next PROPERTY;
2338                    }
2339
2340                    # As this doesn't get tested when we later compare with
2341                    # the actual file, it could be out of order and we
2342                    # wouldn't know it.
2343                    if (($i > 0 && $invlist_ref->[$i] <= $invlist_ref->[$i-1])
2344                        || $invlist_ref->[$i] >= $invlist_ref->[$i+1])
2345                    {
2346                        fail("prop_invmap('$display_prop')");
2347                        diag(sprintf "Range beginning at %04X is out-of-order.", $invlist_ref->[$i]);
2348                        next PROPERTY;
2349                    }
2350                    next;
2351                }
2352            }
2353            elsif ($is_binary) { # These binary files don't have an explicit Y
2354                $invmap_ref->[$i] =~ s/Y//;
2355            }
2356
2357            # The file doesn't include entries that map to $missing, so don't
2358            # include it in the built-up string.  But make sure that it is in
2359            # the correct order in the input.
2360            if ($invmap_ref->[$i] eq $missing) {
2361                if (($i > 0 && $invlist_ref->[$i] <= $invlist_ref->[$i-1])
2362                    || $invlist_ref->[$i] >= $invlist_ref->[$i+1])
2363                {
2364                    fail("prop_invmap('$display_prop')");
2365                    diag(sprintf "Range beginning at %04X is out-of-order.", $invlist_ref->[$i]);
2366                    next PROPERTY;
2367                }
2368                next;
2369            }
2370
2371            # The ad property has one entry which isn't in the file.
2372            # Ignore it, but make sure it is in order.
2373            if ($format eq 'ad'
2374                && $invmap_ref->[$i] eq '<hangul syllable>'
2375                && $invlist_ref->[$i] == 0xAC00)
2376            {
2377                if (($i > 0 && $invlist_ref->[$i] <= $invlist_ref->[$i-1])
2378                    || $invlist_ref->[$i] >= $invlist_ref->[$i+1])
2379                {
2380                    fail("prop_invmap('$display_prop')");
2381                    diag(sprintf "Range beginning at %04X is out-of-order.", $invlist_ref->[$i]);
2382                    next PROPERTY;
2383                }
2384                next;
2385            }
2386
2387            # Finally have figured out what the map column in the file should
2388            # be.  Append the line to the running string.
2389            my $start = $invlist_ref->[$i];
2390            my $end = (defined $invlist_ref->[$i+1])
2391                      ? $invlist_ref->[$i+1] - 1
2392                      : $Unicode::UCD::MAX_CP;
2393            if ($is_binary) {
2394
2395                # Files for binary properties are in inversion list format,
2396                # without ranges.
2397                $tested_map .= "$start\n";
2398                $binary_count++;
2399
2400                # If the final value is infinity, no line for it exists.
2401                if ($end < $Unicode::UCD::MAX_CP) {
2402                    $tested_map .= ($end + 1) . "\n";
2403                    $binary_count++;
2404                }
2405            }
2406            else {
2407                $end = ($start == $end) ? "" : sprintf($file_range_format, $end);
2408                if ($invmap_ref->[$i] ne "") {
2409                    $tested_map .= sprintf "$file_range_format\t%s\t%s\n",
2410                                            $start, $end, $invmap_ref->[$i];
2411                }
2412                elsif ($end ne "") {
2413                    $tested_map .= sprintf "$file_range_format\t%s\n",
2414                                            $start,             $end;
2415                }
2416                else {
2417                    $tested_map .= sprintf "$file_range_format\n", $start;
2418                }
2419            }
2420        } # End of looping over all elements.
2421
2422        # Binary property files begin with a line count line.
2423        $tested_map = "V$binary_count\n$tested_map" if $binary_count;
2424
2425        # Here are done with generating what the file should look like
2426
2427        local $/ = "\n";
2428        chomp $tested_map;
2429        $/ = $input_record_separator;
2430
2431        # And compare.
2432        if ($tested_map ne $official) {
2433            fail_with_diff($display_prop, $official, $tested_map, "prop_invmap");
2434            next PROPERTY;
2435        }
2436
2437        # There shouldn't be any specials unaccounted for.
2438        if (keys %specials) {
2439            fail("prop_invmap('$display_prop')");
2440            diag("Unexpected specials: " . join ", ", keys %specials);
2441            next PROPERTY;
2442        }
2443    }
2444    elsif ($format eq 'n') {
2445
2446        # Handle the Name property similar to the above.  But the file is
2447        # sufficiently different that it is more convenient to make a special
2448        # case for it.  It is a combination of the Name, Unicode1_Name, and
2449        # Name_Alias properties, and named sequences.  We need to remove all
2450        # but the Name in order to do the comparison.
2451
2452        if ($missing ne "") {
2453            fail("prop_invmap('$display_prop')");
2454            diag("The missings should be \"\"; got \"missing\"");
2455            next PROPERTY;
2456        }
2457
2458        $official = do "unicore/Name.pl";
2459
2460        # Get rid of the named sequences portion of the file.  These don't
2461        # have a tab before the first blank on a line.
2462        $official =~ s/ ^ [^\t]+ \  .*? \n //xmg;
2463
2464        # And get rid of the controls.  These are named in the file, but
2465        # shouldn't be in the property.  This gets rid of the two ranges in
2466        # one fell swoop, and also all the Unicode1_Name values that may not
2467        # be in Name_Alias.
2468        if ($::IS_ASCII) {
2469            $official =~ s/ 00000 \t .* 0001F .*? \n//xs;
2470            $official =~ s/ 0007F \t .* 0009F .*? \n//xs;
2471        }
2472        elsif ($::IS_EBCDIC) { # Won't work for POSIX-BC
2473            $official =~ s/ 00000 \t .* 0003F .*? \n//xs;
2474            $official =~ s/ 000FF \t .* 000FF .*? \n//xs;
2475        }
2476
2477        # And remove the aliases.  We read in the Name_Alias property, and go
2478        # through them one by one.
2479        my ($aliases_code_points, $aliases_maps, undef, undef)
2480                = &prop_invmap('_Perl_Name_Alias', '_perl_core_internal_ok');
2481        for (my $i = 0; $i < @$aliases_code_points; $i++) {
2482            my $code_point = $aliases_code_points->[$i];
2483
2484            # Already removed these above.
2485            next if $code_point <= 0x1F
2486                    || ($code_point >= 0x7F && $code_point <= 0x9F);
2487
2488            my $hex_code_point = sprintf "%05X", $code_point;
2489
2490            # Convert to a list if not already to make the following loop
2491            # control uniform.
2492            $aliases_maps->[$i] = [ $aliases_maps->[$i] ]
2493                                                if ! ref $aliases_maps->[$i];
2494
2495            # Remove each alias for this code point from the file
2496            foreach my $alias (@{$aliases_maps->[$i]}) {
2497
2498                # Remove the alias type from the entry, retaining just the name.
2499                $alias =~ s/:.*//;
2500
2501                $alias = quotemeta($alias);
2502                $official =~ s/$hex_code_point \t $alias \n //x;
2503            }
2504        }
2505        local $/ = "\n";
2506        chomp $official;
2507        $/ = $input_record_separator;
2508
2509        # Here have adjusted the file.  We also have to adjust the returned
2510        # inversion map by checking and deleting all the lines in it that
2511        # won't be in the file.  These are the lines that have generated
2512        # things, like <hangul syllable>.
2513        my $tested_map = "";        # Current running string
2514        my @code_point_in_names =
2515                               @Unicode::UCD::code_points_ending_in_code_point;
2516
2517        for my $i (0 .. @$invlist_ref - 1 - $upper_limit_subtract) {
2518            my $start = $invlist_ref->[$i];
2519            my $end = $invlist_ref->[$i+1] - 1;
2520            if ($invmap_ref->[$i] eq $missing) {
2521                if (($i > 0 && $invlist_ref->[$i] <= $invlist_ref->[$i-1])
2522                    || $invlist_ref->[$i] >= $invlist_ref->[$i+1])
2523                {
2524                    fail("prop_invmap('$display_prop')");
2525                    diag(sprintf "Range beginning at %04X is out-of-order.", $invlist_ref->[$i]);
2526                    next PROPERTY;
2527                }
2528                next;
2529            }
2530            if ($invmap_ref->[$i] =~ / (.*) ( < .*? > )/x) {
2531                my $name = $1;
2532                my $type = $2;
2533                if (($i > 0 && $invlist_ref->[$i] <= $invlist_ref->[$i-1])
2534                    || $invlist_ref->[$i] >= $invlist_ref->[$i+1])
2535                {
2536                    fail("prop_invmap('$display_prop')");
2537                    diag(sprintf "Range beginning at %04X is out-of-order.", $invlist_ref->[$i]);
2538                    next PROPERTY;
2539                }
2540                if ($type eq "<hangul syllable>") {
2541                    if ($name ne "") {
2542                        fail("prop_invmap('$display_prop')");
2543                        diag("Unexpected text in $invmap_ref->[$i]");
2544                        next PROPERTY;
2545                    }
2546                    if ($start != 0xAC00) {
2547                        fail("prop_invmap('$display_prop')");
2548                        diag(sprintf("<hangul syllables> should begin at 0xAC00, got %04X", $start));
2549                        next PROPERTY;
2550                    }
2551                    if ($end != $start + 11172 - 1) {
2552                        fail("prop_invmap('$display_prop')");
2553                        diag(sprintf("<hangul syllables> should end at %04X, got %04X", $start + 11172 -1, $end));
2554                        next PROPERTY;
2555                    }
2556                }
2557                elsif ($type ne "<code point>") {
2558                    fail("prop_invmap('$display_prop')");
2559                    diag("Unexpected text '$type' in $invmap_ref->[$i]");
2560                    next PROPERTY;
2561                }
2562                else {
2563
2564                    # Look through the array of names that end in code points,
2565                    # and look for this start and end.  If not found is an
2566                    # error.  If found, delete it, and at the end, make sure
2567                    # have deleted everything.
2568                    for my $i (0 .. @code_point_in_names - 1) {
2569                        my $hash = $code_point_in_names[$i];
2570                        if ($hash->{'low'} == $start
2571                            && $hash->{'high'} == $end
2572                            && "$hash->{'name'}-" eq $name)
2573                        {
2574                            splice @code_point_in_names, $i, 1;
2575                            last;
2576                        }
2577                        else {
2578                            fail("prop_invmap('$display_prop')");
2579                            diag("Unexpected code-point-in-name line '$invmap_ref->[$i]'");
2580                            next PROPERTY;
2581                        }
2582                    }
2583                }
2584
2585                next;
2586            }
2587
2588            # Have adjusted the map, as needed.  Append to running string.
2589            $end = ($start == $end) ? "" : sprintf("%05X", $end);
2590            $tested_map .= sprintf "%05X\t%s\n", $start, $invmap_ref->[$i];
2591        }
2592
2593        # Finished creating the string from the inversion map.  Can compare
2594        # with what the file is.
2595        local $/ = "\n";
2596        chomp $tested_map;
2597        $/ = $input_record_separator;
2598        if ($tested_map ne $official) {
2599            fail_with_diff($display_prop, $official, $tested_map, "prop_invmap");
2600            next PROPERTY;
2601        }
2602        if (@code_point_in_names) {
2603            fail("prop_invmap('$display_prop')");
2604            use Data::Dumper;
2605            diag("Missing code-point-in-name line(s)" . Dumper \@code_point_in_names);
2606            next PROPERTY;
2607        }
2608    }
2609    elsif ($format eq 's') {
2610
2611        # Here the map is not more or less directly from a file stored on
2612        # disk.  We try a different tack.  These should all be properties that
2613        # have just a few possible values (most of them are  binary).  We go
2614        # through the map list, sorting each range into buckets, one for each
2615        # map value.  Thus for binary properties there will be a bucket for Y
2616        # and one for N.  The buckets are inversion lists.  We compare each
2617        # constructed inversion list with what we would get for it using
2618        # prop_invlist(), which has already been tested.  If they all match,
2619        # the whole map must have matched.
2620        my %maps;
2621        my $previous_map;
2622
2623        for my $i (0 .. @$invlist_ref - 1 - $upper_limit_subtract) {
2624            my $range_start = $invlist_ref->[$i];
2625
2626            # Because we are sorting into buckets, things could be
2627            # out-of-order here, and still be in the correct order in the
2628            # bucket, and hence wouldn't show up as an error; so have to
2629            # check.
2630            if (($i > 0 && $range_start <= $invlist_ref->[$i-1])
2631                || $range_start >= $invlist_ref->[$i+1])
2632            {
2633                fail("prop_invmap('$display_prop')");
2634                diag(sprintf "Range beginning at %04X is out-of-order.", $invlist_ref->[$i]);
2635                next PROPERTY;
2636            }
2637
2638            # This new range closes out the range started in the previous
2639            # iteration.
2640            push @{$maps{$previous_map}}, $range_start if defined $previous_map;
2641
2642            # And starts a range which will be closed in the next iteration.
2643            $previous_map = $invmap_ref->[$i];
2644            push @{$maps{$previous_map}}, $range_start;
2645        }
2646
2647        # The range we just started hasn't been closed, and we didn't look at
2648        # the final element of the loop.  If that range is for the default
2649        # value, it shouldn't be closed, as it is to extend to infinity.  But
2650        # otherwise, it should end at the final Unicode code point, and the
2651        # list that maps to the default value should have another element that
2652        # does go to infinity for every above Unicode code point.
2653
2654        if (@$invlist_ref > 1) {
2655            my $penultimate_map = $invmap_ref->[-2];
2656            if ($penultimate_map ne $missing) {
2657
2658                # The -1th element contains the first non-Unicode code point.
2659                push @{$maps{$penultimate_map}}, $invlist_ref->[-1];
2660                push @{$maps{$missing}}, $invlist_ref->[-1];
2661            }
2662        }
2663
2664        # Here, we have the buckets (inversion lists) all constructed.  Go
2665        # through each and verify that matches what prop_invlist() returns.
2666        # We could use is_deeply() for the comparison, but would get multiple
2667        # messages for each $prop.
2668        foreach my $map (sort keys %maps) {
2669            my @off_invlist = prop_invlist("$prop = $map");
2670            my $min = (@off_invlist >= @{$maps{$map}})
2671                       ? @off_invlist
2672                       : @{$maps{$map}};
2673            for my $i (0 .. $min- 1) {
2674                if ($i > @off_invlist - 1) {
2675                    fail("prop_invmap('$display_prop')");
2676                    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]'");
2677                    next PROPERTY;
2678                }
2679                elsif ($i > @{$maps{$map}} - 1) {
2680                    fail("prop_invmap('$display_prop')");
2681                    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]'");
2682                    next PROPERTY;
2683                }
2684                elsif ($maps{$map}[$i] ne $off_invlist[$i]) {
2685                    fail("prop_invmap('$display_prop')");
2686                    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]'");
2687                    next PROPERTY;
2688                }
2689            }
2690        }
2691    }
2692    else {  # Don't know this property nor format.
2693
2694        fail("prop_invmap('$display_prop')");
2695        diag("Unknown property '$display_prop' or format '$format'");
2696        next PROPERTY;
2697    }
2698
2699    pass("prop_invmap('$display_prop')");
2700}
2701
2702# A few tests of search_invlist
2703use Unicode::UCD qw(search_invlist);
2704
2705if ($v_unicode_version ge v3.1.0) { # No Script property before this
2706    my ($scripts_ranges_ref, $scripts_map_ref) = prop_invmap("Script");
2707    my $index = search_invlist($scripts_ranges_ref, 0x390);
2708    is($scripts_map_ref->[$index], "Greek", "U+0390 is Greek");
2709    my @alpha_invlist = prop_invlist("Alpha");
2710    is(search_invlist(\@alpha_invlist, ord("\t")), undef, "search_invlist returns undef for code points before first one on the list");
2711}
2712
2713ok($/ eq $input_record_separator,  "The record separator didn't get overridden");
2714
2715if (! ok(@warnings == 0, "No warnings were generated")) {
2716    diag(join "\n", "The warnings are:", @warnings);
2717}
2718
2719# And make sure that the max code point returned actually fits in an IV, which
2720# currently range iterators are.
2721my $count = 0;
2722for my $i ($Unicode::UCD::MAX_CP - 1 .. $Unicode::UCD::MAX_CP) {
2723    $count++;
2724}
2725is($count, 2, "MAX_CP isn't too large");
2726
2727done_testing();
2728