UCD.t revision 1.2
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 = '8.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 822is(num("0"), 0, 'Verify num("0") == 0'); 823is(num("98765"), 98765, 'Verify num("98765") == 98765'); 824ok(! defined num("98765\N{FULLWIDTH DIGIT FOUR}"), 825 'Verify num("98765\N{FULLWIDTH DIGIT FOUR}") isnt defined'); 826my $tai_lue_2; 827if ($v_unicode_version ge v4.1.0) { 828 my $tai_lue_1 = charnames::string_vianame("NEW TAI LUE DIGIT ONE"); 829 $tai_lue_2 = charnames::string_vianame("NEW TAI LUE DIGIT TWO"); 830 is(num($tai_lue_2), 2, 'Verify num("\N{NEW TAI LUE DIGIT TWO}") == 2'); 831 is(num($tai_lue_1), 1, 'Verify num("\N{NEW TAI LUE DIGIT ONE}") == 1'); 832 is(num($tai_lue_2 . $tai_lue_1), 21, 833 'Verify num("\N{NEW TAI LUE DIGIT TWO}\N{NEW TAI LUE DIGIT ONE}") == 21'); 834} 835if ($v_unicode_version ge v5.2.0) { 836 ok(! defined num($tai_lue_2 837 . charnames::string_vianame("NEW TAI LUE THAM DIGIT ONE")), 838 'Verify num("\N{NEW TAI LUE DIGIT TWO}\N{NEW TAI LUE THAM DIGIT ONE}") isnt defined'); 839} 840if ($v_unicode_version ge v5.1.0) { 841 my $cham_0 = charnames::string_vianame("CHAM DIGIT ZERO"); 842 is(num($cham_0 . charnames::string_vianame("CHAM DIGIT THREE")), 3, 843 'Verify num("\N{CHAM DIGIT ZERO}\N{CHAM DIGIT THREE}") == 3'); 844 if ($v_unicode_version ge v5.2.0) { 845 ok(! defined num( $cham_0 846 . charnames::string_vianame("JAVANESE DIGIT NINE")), 847 'Verify num("\N{CHAM DIGIT ZERO}\N{JAVANESE DIGIT NINE}") isnt defined'); 848 } 849} 850is(num("\N{SUPERSCRIPT TWO}"), 2, 'Verify num("\N{SUPERSCRIPT TWO} == 2'); 851if ($v_unicode_version ge v3.0.0) { 852 is(num(charnames::string_vianame("ETHIOPIC NUMBER TEN THOUSAND")), 10000, 853 'Verify num("\N{ETHIOPIC NUMBER TEN THOUSAND}") == 10000'); 854} 855if ($v_unicode_version ge v5.2.0) { 856 is(num(charnames::string_vianame("NORTH INDIC FRACTION ONE HALF")), 857 .5, 858 'Verify num("\N{NORTH INDIC FRACTION ONE HALF}") == .5'); 859 is(num("\N{U+12448}"), 9, 'Verify num("\N{U+12448}") == 9'); 860} 861if ($v_unicode_version gt v3.2.0) { # Is missing from non-Unihan files before 862 # this 863 is(num("\N{U+5146}"), 1000000000000, 864 'Verify num("\N{U+5146}") == 1000000000000'); 865} 866 867# Create a user-defined property 868sub InKana {<<'END'} 8693040 309F 87030A0 30FF 871END 872 873use Unicode::UCD qw(prop_aliases); 874 875is(prop_aliases(undef), undef, "prop_aliases(undef) returns <undef>"); 876is(prop_aliases("unknown property"), undef, 877 "prop_aliases(<unknown property>) returns <undef>"); 878is(prop_aliases("InKana"), undef, 879 "prop_aliases(<user-defined property>) returns <undef>"); 880is(prop_aliases("Perl_Decomposition_Mapping"), undef, "prop_aliases('Perl_Decomposition_Mapping') returns <undef> since internal-Perl-only"); 881is(prop_aliases("Perl_Charnames"), undef, 882 "prop_aliases('Perl_Charnames') returns <undef> since internal-Perl-only"); 883is(prop_aliases("isgc"), undef, 884 "prop_aliases('isgc') returns <undef> since is not covered Perl extension"); 885is(prop_aliases("Is_Is_Any"), undef, 886 "prop_aliases('Is_Is_Any') returns <undef> since two is's"); 887is(prop_aliases("ccc=vr"), undef, 888 "prop_aliases('ccc=vr') doesn't generate a warning"); 889 890require 'utf8_heavy.pl'; 891require "unicore/Heavy.pl"; 892 893# Keys are lists of properties. Values are defined if have been tested. 894my %props; 895 896# To test for loose matching, add in the characters that are ignored there. 897my $extra_chars = "-_ "; 898 899# The one internal property we accept 900$props{'Perl_Decimal_Digit'} = 1; 901my @list = prop_aliases("perldecimaldigit"); 902is_deeply(\@list, 903 [ "Perl_Decimal_Digit", 904 "Perl_Decimal_Digit" 905 ], "prop_aliases('perldecimaldigit') returns Perl_Decimal_Digit as both short and full names"); 906 907# Get the official Unicode property name synonyms and test them. 908 909SKIP: { 910skip "PropertyAliases.txt is not in this Unicode version", 1 if $v_unicode_version lt v3.2.0; 911open my $props, "<", "../lib/unicore/PropertyAliases.txt" 912 or die "Can't open Unicode PropertyAliases.txt"; 913local $/ = "\n"; 914while (<$props>) { 915 s/\s*#.*//; # Remove comments 916 next if /^\s* $/x; # Ignore empty and comment lines 917 918 chomp; 919 local $/ = $input_record_separator; 920 my $count = 0; # 0th field in line is short name; 1th is long name 921 my $short_name; 922 my $full_name; 923 my @names_via_short; 924 foreach my $alias (split /\s*;\s*/) { # Fields are separated by 925 # semi-colons 926 # Add in the characters that are supposed to be ignored, to test loose 927 # matching, which the tested function does on all inputs. 928 my $mod_name = "$extra_chars$alias"; 929 930 my $loose = &utf8::_loose_name(lc $alias); 931 932 # Indicate we have tested this. 933 $props{$loose} = 1; 934 935 my @all_names = prop_aliases($mod_name); 936 if (grep { $_ eq $loose } @Unicode::UCD::suppressed_properties) { 937 is(@all_names, 0, "prop_aliases('$mod_name') returns undef since $alias is not installed"); 938 next; 939 } 940 elsif (! @all_names) { 941 fail("prop_aliases('$mod_name')"); 942 diag("'$alias' is unknown to prop_aliases()"); 943 next; 944 } 945 946 if ($count == 0) { # Is short name 947 948 @names_via_short = prop_aliases($mod_name); 949 950 # If the 0th test fails, no sense in continuing with the others 951 last unless is($names_via_short[0], $alias, 952 "prop_aliases: '$alias' is the short name for '$mod_name'"); 953 $short_name = $alias; 954 } 955 elsif ($count == 1) { # Is full name 956 957 # Some properties have the same short and full name; no sense 958 # repeating the test if the same. 959 if ($alias ne $short_name) { 960 my @names_via_full = prop_aliases($mod_name); 961 is_deeply(\@names_via_full, \@names_via_short, "prop_aliases() returns the same list for both '$short_name' and '$mod_name'"); 962 } 963 964 # Tests scalar context 965 is(prop_aliases($short_name), $alias, 966 "prop_aliases: '$alias' is the long name for '$short_name'"); 967 } 968 else { # Is another alias 969 is_deeply(\@all_names, \@names_via_short, "prop_aliases() returns the same list for both '$short_name' and '$mod_name'"); 970 ok((grep { $_ =~ /^$alias$/i } @all_names), 971 "prop_aliases: '$alias' is listed as an alias for '$mod_name'"); 972 } 973 974 $count++; 975 } 976} 977} # End of SKIP block 978 979# Now test anything we can find that wasn't covered by the tests of the 980# official properties. We have no way of knowing if mktables omitted a Perl 981# extension or not, but we do the best we can from its generated lists 982 983foreach my $alias (sort keys %utf8::loose_to_file_of) { 984 next if $alias =~ /=/; 985 my $lc_name = lc $alias; 986 my $loose = &utf8::_loose_name($lc_name); 987 next if exists $props{$loose}; # Skip if already tested 988 $props{$loose} = 1; 989 my $mod_name = "$extra_chars$alias"; # Tests loose matching 990 my @aliases = prop_aliases($mod_name); 991 my $found_it = grep { &utf8::_loose_name(lc $_) eq $lc_name } @aliases; 992 if ($found_it) { 993 pass("prop_aliases: '$lc_name' is listed as an alias for '$mod_name'"); 994 } 995 elsif ($lc_name =~ /l[_&]$/) { 996 997 # These two names are special in that they don't appear in the 998 # returned list because they are discouraged from use. Verify 999 # that they return the same list as a non-discouraged version. 1000 my @LC = prop_aliases('Is_LC'); 1001 is_deeply(\@aliases, \@LC, "prop_aliases: '$lc_name' returns the same list as 'Is_LC'"); 1002 } 1003 else { 1004 my $stripped = $lc_name =~ s/^is//; 1005 1006 # Could be that the input includes a prefix 'is', which is rarely 1007 # returned as an alias, so having successfully stripped it off above, 1008 # try again. 1009 if ($stripped) { 1010 $found_it = grep { &utf8::_loose_name(lc $_) eq $lc_name } @aliases; 1011 } 1012 1013 # If that didn't work, it could be that it's a block, which is always 1014 # returned with a leading 'In_' to avoid ambiguity. Try comparing 1015 # with that stripped off. 1016 if (! $found_it) { 1017 $found_it = grep { &utf8::_loose_name(s/^In_(.*)/\L$1/r) eq $lc_name } 1018 @aliases; 1019 # Could check that is a real block, but tests for invmap will 1020 # likely pickup any errors, since this will be tested there. 1021 $lc_name = "in$lc_name" if $found_it; # Change for message below 1022 } 1023 my $message = "prop_aliases: '$lc_name' is listed as an alias for '$mod_name'"; 1024 ($found_it) ? pass($message) : fail($message); 1025 } 1026} 1027 1028# Some of the Perl extensions should always be built; make sure they have the 1029# correct full name, etc. 1030for my $prop (qw(Alnum Blank Cntrl Digit Graph Print Word XDigit)) { 1031 my @expected = ( $prop, "XPosix$prop" ); 1032 my @got = prop_aliases($prop); 1033 splice @got, 2; 1034 is_deeply(\@got, \@expected, "Got expected aliases for $prop"); 1035} 1036 1037my $done_equals = 0; 1038foreach my $alias (keys %utf8::stricter_to_file_of) { 1039 if ($alias =~ /=/) { # Only test one case where there is an equals 1040 next if $done_equals; 1041 $done_equals = 1; 1042 } 1043 my $lc_name = lc $alias; 1044 my @list = prop_aliases($alias); 1045 if ($alias =~ /^_/) { 1046 is(@list, 0, "prop_aliases: '$lc_name' returns an empty list since it is internal_only"); 1047 } 1048 elsif ($alias =~ /=/) { 1049 is(@list, 0, "prop_aliases: '$lc_name' returns an empty list since is illegal property name"); 1050 } 1051 else { 1052 ok((grep { lc $_ eq $lc_name } @list), 1053 "prop_aliases: '$lc_name' is listed as an alias for '$alias'"); 1054 } 1055} 1056 1057use Unicode::UCD qw(prop_values prop_value_aliases); 1058 1059is(prop_value_aliases("unknown property", "unknown value"), undef, 1060 "prop_value_aliases(<unknown property>, <unknown value>) returns <undef>"); 1061is(prop_value_aliases(undef, undef), undef, 1062 "prop_value_aliases(undef, undef) returns <undef>"); 1063is((prop_value_aliases("na", "A")), "A", "test that prop_value_aliases returns its input for properties that don't have synonyms"); 1064is(prop_value_aliases("isgc", "C"), undef, "prop_value_aliases('isgc', 'C') returns <undef> since is not covered Perl extension"); 1065is(prop_value_aliases("gc", "isC"), undef, "prop_value_aliases('gc', 'isC') returns <undef> since is not covered Perl extension"); 1066is(prop_value_aliases("Any", "None"), undef, "prop_value_aliases('Any', 'None') returns <undef> since is Perl extension and 'None' is not valid"); 1067is(prop_value_aliases("lc", "A"), "A", "prop_value_aliases('lc', 'A') returns its input, as docs say it does"); 1068 1069# We have no way of knowing if mktables omitted a Perl extension that it 1070# shouldn't have, but we can check if it omitted an official Unicode property 1071# name synonym. And for those, we can check if the short and full names are 1072# correct. 1073 1074my %pva_tested; # List of things already tested. 1075 1076SKIP: { 1077skip "PropValueAliases.txt is not in this Unicode version", 1 if $v_unicode_version lt v3.2.0; 1078open my $propvalues, "<", "../lib/unicore/PropValueAliases.txt" 1079 or die "Can't open Unicode PropValueAliases.txt"; 1080local $/ = "\n"; 1081 1082# Each examined line in the file is for a single value for a property. We 1083# accumulate all the values for each property using these two variables. 1084my $prev_prop = ""; 1085my @this_prop_values; 1086 1087while (<$propvalues>) { 1088 s/\s*#.*//; # Remove comments 1089 next if /^\s* $/x; # Ignore empty and comment lines 1090 chomp; 1091 local $/ = $input_record_separator; 1092 1093 # Fix typo in official input file 1094 s/CCC133/CCC132/g if $v_unicode_version eq v6.1.0; 1095 1096 my @fields = split /\s*;\s*/; # Fields are separated by semi-colons 1097 my $prop = shift @fields; # 0th field is the property, 1098 1099 # 'qc' is short in early versions of the file for any of the quick check 1100 # properties. Choose one of them. 1101 if ($prop eq 'qc' && $v_unicode_version le v4.0.0) { 1102 $prop = "NFKC_QC"; 1103 } 1104 1105 # When changing properties, we examine the accumulated values for the old 1106 # one to see if our function that returns them matches. 1107 if ($prev_prop ne $prop) { 1108 if ($prev_prop ne "") { # Skip for the first time through 1109 my @ucd_function_values = prop_values($prev_prop); 1110 @ucd_function_values = () unless @ucd_function_values; 1111 1112 # The file didn't include strictly numeric values until after this 1113 if ($prev_prop eq 'ccc' && $v_unicode_version le v6.0.0) { 1114 @ucd_function_values = grep { /\D/ } @ucd_function_values; 1115 } 1116 1117 # This perl extension doesn't appear in the official file 1118 push @this_prop_values, "Non_Canon" if $prev_prop eq 'dt'; 1119 1120 my @file_values = undef; 1121 @file_values = sort { lc($a =~ s/_//gr) cmp lc($b =~ s/_//gr) } 1122 @this_prop_values if @this_prop_values; 1123 is_deeply(\@ucd_function_values, \@file_values, 1124 "prop_values('$prev_prop') returns correct list of values"); 1125 } 1126 $prev_prop = $prop; 1127 undef @this_prop_values; 1128 } 1129 1130 my $count = 0; # 0th field in line (after shifting off the property) is 1131 # short name; 1th is long name 1132 my $short_name; 1133 my @names_via_short; # Saves the values between iterations 1134 1135 # The property on the lhs of the = is always loosely matched. Add in 1136 # characters that are ignored under loose matching to test that 1137 my $mod_prop = "$extra_chars$prop"; 1138 1139 if ($prop eq 'blk' && $v_unicode_version le v5.0.0) { 1140 foreach my $element (@fields) { 1141 $element =~ s/-/_/g; 1142 } 1143 } 1144 1145 if ($fields[0] eq 'n/a') { # See comments in input file, essentially 1146 # means full name and short name are identical 1147 $fields[0] = $fields[1]; 1148 } 1149 elsif ($fields[0] ne $fields[1] 1150 && &utf8::_loose_name(lc $fields[0]) 1151 eq &utf8::_loose_name(lc $fields[1]) 1152 && $fields[1] !~ /[[:upper:]]/) 1153 { 1154 # Also, there is a bug in the file in which "n/a" is omitted, and 1155 # the two fields are identical except for case, and the full name 1156 # is all lower case. Copy the "short" name unto the full one to 1157 # give it some upper case. 1158 1159 $fields[1] = $fields[0]; 1160 } 1161 1162 # The ccc property in the file is special; has an extra numeric field 1163 # (0th), which should go at the end, since we use the next two fields as 1164 # the short and full names, respectively. See comments in input file. 1165 splice (@fields, 0, 0, splice(@fields, 1, 2)) if $prop eq 'ccc'; 1166 1167 my $loose_prop = &utf8::_loose_name(lc $prop); 1168 my $suppressed = grep { $_ eq $loose_prop } 1169 @Unicode::UCD::suppressed_properties; 1170 push @this_prop_values, $fields[0] unless $suppressed; 1171 foreach my $value (@fields) { 1172 if ($suppressed) { 1173 is(prop_value_aliases($prop, $value), undef, "prop_value_aliases('$prop', '$value') returns undef for suppressed property $prop"); 1174 next; 1175 } 1176 elsif (grep { $_ eq ("$loose_prop=" . &utf8::_loose_name(lc $value)) } @Unicode::UCD::suppressed_properties) { 1177 is(prop_value_aliases($prop, $value), undef, "prop_value_aliases('$prop', '$value') returns undef for suppressed property $prop=$value"); 1178 next; 1179 } 1180 1181 # Add in test for loose matching. 1182 my $mod_value = "$extra_chars$value"; 1183 1184 # If the value is a number, optionally negative, including a floating 1185 # point or rational numer, it should be only strictly matched, so the 1186 # loose matching should fail. 1187 if ($value =~ / ^ -? \d+ (?: [\/.] \d+ )? $ /x) { 1188 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"); 1189 1190 # And reset so below tests just the strict matching. 1191 $mod_value = $value; 1192 } 1193 1194 if ($count == 0) { 1195 1196 @names_via_short = prop_value_aliases($mod_prop, $mod_value); 1197 1198 # If the 0th test fails, no sense in continuing with the others 1199 last unless is($names_via_short[0], $value, "prop_value_aliases: In '$prop', '$value' is the short name for '$mod_value'"); 1200 $short_name = $value; 1201 } 1202 elsif ($count == 1) { 1203 1204 # Some properties have the same short and full name; no sense 1205 # repeating the test if the same. 1206 if ($value ne $short_name) { 1207 my @names_via_full = 1208 prop_value_aliases($mod_prop, $mod_value); 1209 is_deeply(\@names_via_full, \@names_via_short, "In '$prop', prop_value_aliases() returns the same list for both '$short_name' and '$mod_value'"); 1210 } 1211 1212 # Tests scalar context 1213 is(prop_value_aliases($prop, $short_name), $value, "'$value' is the long name for prop_value_aliases('$prop', '$short_name')"); 1214 } 1215 else { 1216 my @all_names = prop_value_aliases($mod_prop, $mod_value); 1217 is_deeply(\@all_names, \@names_via_short, "In '$prop', prop_value_aliases() returns the same list for both '$short_name' and '$mod_value'"); 1218 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')"); 1219 } 1220 1221 $pva_tested{&utf8::_loose_name(lc $prop) . "=" . &utf8::_loose_name(lc $value)} = 1; 1222 $count++; 1223 } 1224} 1225} # End of SKIP block 1226 1227# And test as best we can, the non-official pva's that mktables generates. 1228foreach my $hash (\%utf8::loose_to_file_of, \%utf8::stricter_to_file_of) { 1229 foreach my $test (sort keys %$hash) { 1230 next if exists $pva_tested{$test}; # Skip if already tested 1231 1232 my ($prop, $value) = split "=", $test; 1233 next unless defined $value; # prop_value_aliases() requires an input 1234 # 'value' 1235 my $mod_value; 1236 if ($hash == \%utf8::loose_to_file_of) { 1237 1238 # Add extra characters to test loose-match rhs value 1239 $mod_value = "$extra_chars$value"; 1240 } 1241 else { # Here value is strictly matched. 1242 1243 # Extra elements are added by mktables to this hash so that 1244 # something like "age=6.0" has a synonym of "age=6". It's not 1245 # clear to me (khw) if we should be encouraging those synonyms, so 1246 # don't test for them. 1247 next if $value !~ /\D/ && exists $hash->{"$prop=$value.0"}; 1248 1249 # Verify that loose matching fails when only strict is called for. 1250 next unless is(prop_value_aliases($prop, "$extra_chars$value"), undef, 1251 "prop_value_aliases('$prop', '$extra_chars$value') returns undef since '$value' should be strictly matched"), 1252 1253 # Strict matching does allow for underscores between digits. Test 1254 # for that. 1255 $mod_value = $value; 1256 while ($mod_value =~ s/(\d)(\d)/$1_$2/g) {} 1257 } 1258 1259 # The lhs property is always loosely matched, so add in extra 1260 # characters to test that. 1261 my $mod_prop = "$extra_chars$prop"; 1262 1263 if ($prop eq 'gc' && $value =~ /l[_&]$/) { 1264 # These two names are special in that they don't appear in the 1265 # returned list because they are discouraged from use. Verify 1266 # that they return the same list as a non-discouraged version. 1267 my @LC = prop_value_aliases('gc', 'lc'); 1268 my @l_ = prop_value_aliases($mod_prop, $mod_value); 1269 is_deeply(\@l_, \@LC, "prop_value_aliases('$mod_prop', '$mod_value) returns the same list as prop_value_aliases('gc', 'lc')"); 1270 } 1271 else { 1272 ok((grep { &utf8::_loose_name(lc $_) eq &utf8::_loose_name(lc $value) } 1273 prop_value_aliases($mod_prop, $mod_value)), 1274 "'$value' is listed as an alias for prop_value_aliases('$mod_prop', '$mod_value')"); 1275 } 1276 } 1277} 1278 1279undef %pva_tested; 1280 1281no warnings 'once'; # We use some values once from 'required' modules. 1282 1283use Unicode::UCD qw(prop_invlist prop_invmap MAX_CP); 1284 1285# There were some problems with caching interfering with prop_invlist() vs 1286# prop_invmap() on binary properties, and also between the 3 properties where 1287# Perl used the same 'To' name as another property (see utf8_heavy.pl). 1288# So, before testing all of prop_invlist(), 1289# 1) call prop_invmap() to try both orders of these name issues. This uses 1290# up two of the 3 properties; the third will be left so that invlist() 1291# on it gets called before invmap() 1292# 2) call prop_invmap() on a generic binary property, ahead of invlist(). 1293# This should test that the caching works in both directions. 1294 1295# These properties are not stable between Unicode versions, but the first few 1296# elements are; just look at the first element to see if are getting the 1297# distinction right. The general inversion map testing below will test the 1298# whole thing. 1299 1300my $prop; 1301my ($invlist_ref, $invmap_ref, $format, $missing); 1302if ($::IS_ASCII) { # On EBCDIC, other things will come first, and can vary 1303 # according to code page 1304 $prop = "uc"; 1305 ($invlist_ref, $invmap_ref, $format, $missing) = prop_invmap($prop); 1306 is($format, 'al', "prop_invmap() format of '$prop' is 'al'"); 1307 is($missing, '0', "prop_invmap() missing of '$prop' is '0'"); 1308 is($invlist_ref->[1], 0x61, "prop_invmap('$prop') list[1] is 0x61"); 1309 is($invmap_ref->[1], 0x41, "prop_invmap('$prop') map[1] is 0x41"); 1310 1311 $prop = "upper"; 1312 ($invlist_ref, $invmap_ref, $format, $missing) = prop_invmap($prop); 1313 is($format, 's', "prop_invmap() format of '$prop' is 's"); 1314 is($missing, 'N', "prop_invmap() missing of '$prop' is 'N'"); 1315 is($invlist_ref->[1], 0x41, "prop_invmap('$prop') list[1] is 0x41"); 1316 is($invmap_ref->[1], 'Y', "prop_invmap('$prop') map[1] is 'Y'"); 1317 1318 $prop = "lower"; 1319 ($invlist_ref, $invmap_ref, $format, $missing) = prop_invmap($prop); 1320 is($format, 's', "prop_invmap() format of '$prop' is 's'"); 1321 is($missing, 'N', "prop_invmap() missing of '$prop' is 'N'"); 1322 is($invlist_ref->[1], 0x61, "prop_invmap('$prop') list[1] is 0x61"); 1323 is($invmap_ref->[1], 'Y', "prop_invmap('$prop') map[1] is 'Y'"); 1324 1325 $prop = "lc"; 1326 ($invlist_ref, $invmap_ref, $format, $missing) = prop_invmap($prop); 1327 my $lc_format = ($v_unicode_version ge v3.2.0) ? 'al' : 'a'; 1328 is($format, $lc_format, "prop_invmap() format of '$prop' is '$lc_format"); 1329 is($missing, '0', "prop_invmap() missing of '$prop' is '0'"); 1330 is($invlist_ref->[1], 0x41, "prop_invmap('$prop') list[1] is 0x41"); 1331 is($invmap_ref->[1], 0x61, "prop_invmap('$prop') map[1] is 0x61"); 1332} 1333 1334# This property is stable and small, so can test all of it 1335if ($v_unicode_version gt v3.1.0) { 1336 $prop = "ASCII_Hex_Digit"; 1337 ($invlist_ref, $invmap_ref, $format, $missing) = prop_invmap($prop); 1338 is($format, 's', "prop_invmap() format of '$prop' is 's'"); 1339 is($missing, 'N', "prop_invmap() missing of '$prop' is 'N'"); 1340 if ($::IS_ASCII) { 1341 is_deeply($invlist_ref, [ 0x0000, 0x0030, 0x003A, 1342 0x0041, 0x0047, 1343 0x0061, 0x0067, 0x110000 1344 ], 1345 "prop_invmap('$prop') code point list is correct"); 1346 } 1347 elsif ($::IS_EBCDIC) { 1348 is_deeply($invlist_ref, [ 1349 utf8::unicode_to_native(0x0000), 1350 utf8::unicode_to_native(0x0061), utf8::unicode_to_native(0x0066) + 1, 1351 utf8::unicode_to_native(0x0041), utf8::unicode_to_native(0x0046) + 1, 1352 utf8::unicode_to_native(0x0030), utf8::unicode_to_native(0x0039) + 1, 1353 utf8::unicode_to_native(0x110000) 1354 ], 1355 "prop_invmap('$prop') code point list is correct"); 1356 } 1357 is_deeply($invmap_ref, [ 'N', 'Y', 'N', 'Y', 'N', 'Y', 'N', 'N' ] , 1358 "prop_invmap('$prop') map list is correct"); 1359} 1360 1361is(prop_invlist("Unknown property"), undef, "prop_invlist(<Unknown property>) returns undef"); 1362is(prop_invlist(undef), undef, "prop_invlist(undef) returns undef"); 1363is(prop_invlist("Any"), 2, "prop_invlist('Any') returns the number of elements in scalar context"); 1364my @invlist = prop_invlist("Is_Any"); 1365is_deeply(\@invlist, [ 0, 0x110000 ], "prop_invlist works on 'Is_' prefixes"); 1366is(prop_invlist("Is_Is_Any"), undef, "prop_invlist('Is_Is_Any') returns <undef> since two is's"); 1367 1368use Storable qw(dclone); 1369 1370is(prop_invlist("InKana"), undef, "prop_invlist(<user-defined property returns undef>)"); 1371 1372# The way both the tests for invlist and invmap work is that they take the 1373# lists returned by the functions and construct from them what the original 1374# file should look like, which are then compared with the file. If they are 1375# identical, the test passes. What this tests isn't that the results are 1376# correct, but that invlist and invmap haven't introduced errors beyond what 1377# are there in the files. As a small hedge against that, test some 1378# prop_invlist() tables fully with the known correct result. We choose 1379# ASCII_Hex_Digit again, as it is stable. 1380if ($v_unicode_version gt v3.1.0) { 1381 if ($::IS_ASCII) { 1382 @invlist = prop_invlist("AHex"); 1383 is_deeply(\@invlist, [ 0x0030, 0x003A, 0x0041, 1384 0x0047, 0x0061, 0x0067 ], 1385 "prop_invlist('AHex') is exactly the expected set of points"); 1386 @invlist = prop_invlist("AHex=f"); 1387 is_deeply(\@invlist, [ 0x0000, 0x0030, 0x003A, 0x0041, 1388 0x0047, 0x0061, 0x0067 ], 1389 "prop_invlist('AHex=f') is exactly the expected set of points"); 1390 } 1391 elsif ($::IS_EBCDIC) { # Relies on the ranges 0-9, a-f, and A-F each being 1392 # contiguous 1393 @invlist = prop_invlist("AHex"); 1394 is_deeply(\@invlist, [ 1395 utf8::unicode_to_native(0x0061), utf8::unicode_to_native(0x0066) + 1, 1396 utf8::unicode_to_native(0x0041), utf8::unicode_to_native(0x0046) + 1, 1397 utf8::unicode_to_native(0x0030), utf8::unicode_to_native(0x0039) + 1, 1398 ], 1399 "prop_invlist('AHex') is exactly the expected set of points"); 1400 @invlist = prop_invlist("AHex=f"); 1401 is_deeply(\@invlist, [ 1402 utf8::unicode_to_native(0x0000), 1403 utf8::unicode_to_native(0x0061), 1404 utf8::unicode_to_native(0x0066) + 1, 1405 utf8::unicode_to_native(0x0041), 1406 utf8::unicode_to_native(0x0046) + 1, 1407 utf8::unicode_to_native(0x0030), 1408 utf8::unicode_to_native(0x0039) + 1, 1409 ], 1410 "prop_invlist('AHex=f') is exactly the expected set of points"); 1411 } 1412} 1413 1414sub fail_with_diff ($$$$) { 1415 # For use below to output better messages 1416 my ($prop, $official, $constructed, $tested_function_name) = @_; 1417 1418 is($constructed, $official, "$tested_function_name('$prop')"); 1419 diag("Comment out lines " . (__LINE__ - 1) . " through " . (__LINE__ + 1) . " in '$0' on Un*x-like systems to see just the differences. Uses the 'diff' first in your \$PATH"); 1420 return; 1421 1422 fail("$tested_function_name('$prop')"); 1423 1424 require File::Temp; 1425 my $off = File::Temp->new(); 1426 local $/ = "\n"; 1427 chomp $official; 1428 print $off $official, "\n"; 1429 close $off || die "Can't close official"; 1430 1431 chomp $constructed; 1432 my $gend = File::Temp->new(); 1433 print $gend $constructed, "\n"; 1434 close $gend || die "Can't close gend"; 1435 1436 my $diff = File::Temp->new(); 1437 system("diff $off $gend > $diff"); 1438 1439 open my $fh, "<", $diff || die "Can't open $diff"; 1440 my @diffs = <$fh>; 1441 diag("In the diff output below '<' marks lines from the filesystem tables;\n'>' are from $tested_function_name()"); 1442 diag(@diffs); 1443} 1444 1445my %tested_invlist; 1446 1447# Look at everything we think that mktables tells us exists, both loose and 1448# strict 1449foreach my $set_of_tables (\%utf8::stricter_to_file_of, \%utf8::loose_to_file_of) 1450{ 1451 foreach my $table (sort keys %$set_of_tables) { 1452 1453 my $mod_table; 1454 my ($prop_only, $value) = split "=", $table; 1455 if (defined $value) { 1456 1457 # If this is to be loose matched, add in characters to test that. 1458 if ($set_of_tables == \%utf8::loose_to_file_of) { 1459 $value = "$extra_chars$value"; 1460 } 1461 else { # Strict match 1462 1463 # Verify that loose matching fails when only strict is called 1464 # for. 1465 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"); 1466 1467 # Strict matching does allow for underscores between digits. 1468 # Test for that. 1469 while ($value =~ s/(\d)(\d)/$1_$2/g) {} 1470 } 1471 1472 # The property portion in compound form specifications always 1473 # matches loosely 1474 $mod_table = "$extra_chars$prop_only = $value"; 1475 } 1476 else { # Single-form. 1477 1478 # Like above, use loose if required, and insert underscores 1479 # between digits if strict. 1480 if ($set_of_tables == \%utf8::loose_to_file_of) { 1481 $mod_table = "$extra_chars$table"; 1482 } 1483 else { 1484 $mod_table = $table; 1485 while ($mod_table =~ s/(\d)(\d)/$1_$2/g) {} 1486 } 1487 } 1488 1489 my @tested = prop_invlist($mod_table); 1490 if ($table =~ /^_/) { 1491 is(@tested, 0, "prop_invlist('$mod_table') returns an empty list since is internal-only"); 1492 next; 1493 } 1494 1495 # If we have already tested a property that uses the same file, this 1496 # list should be identical to the one that was tested, and can bypass 1497 # everything else. 1498 my $file = $set_of_tables->{$table}; 1499 if (exists $tested_invlist{$file}) { 1500 is_deeply(\@tested, $tested_invlist{$file}, "prop_invlist('$mod_table') gave same results as its name synonym"); 1501 next; 1502 } 1503 $tested_invlist{$file} = dclone \@tested; 1504 1505 # A '!' in the file name means that it is to be inverted. 1506 my $invert = $file =~ s/!//; 1507 my $official; 1508 1509 # If the file's directory is '#', it is a special case where the 1510 # contents are in-lined with semi-colons meaning new-lines, instead of 1511 # it being an actual file to read. The file is an index in to the 1512 # array of the definitions 1513 if ($file =~ s!^#/!!) { 1514 $official = $utf8::inline_definitions[$file]; 1515 } 1516 else { 1517 $official = do "unicore/lib/$file.pl"; 1518 } 1519 1520 # Get rid of any trailing space and comments in the file. 1521 $official =~ s/\s*(#.*)?$//mg; 1522 local $/ = "\n"; 1523 chomp $official; 1524 $/ = $input_record_separator; 1525 1526 # If we are to test against an inverted file, it is easier to invert 1527 # our array than the file. 1528 if ($invert) { 1529 if (@tested && $tested[0] == 0) { 1530 shift @tested; 1531 } else { 1532 unshift @tested, 0; 1533 } 1534 } 1535 1536 # Now construct a string from the list that should match the file. 1537 # The file is inversion list format code points, like this: 1538 # V1216 1539 # 65 # [26] 1540 # 91 1541 # 192 # [23] 1542 # ... 1543 # The V indicates it's an inversion list, and is followed immediately 1544 # by the number of elements (lines) that follow giving its contents. 1545 # The list has even numbered elements (0th, 2nd, ...) start ranges 1546 # that are in the list, and odd ones that aren't in the list. 1547 # Therefore the odd numbered ones are one beyond the end of the 1548 # previous range, but otherwise don't get reflected in the file. 1549 my $tested = join "\n", ("V" . scalar @tested), @tested; 1550 local $/ = "\n"; 1551 chomp $tested; 1552 $/ = $input_record_separator; 1553 if ($tested ne $official) { 1554 fail_with_diff($mod_table, $official, $tested, "prop_invlist"); 1555 next; 1556 } 1557 1558 pass("prop_invlist('$mod_table')"); 1559 } 1560} 1561 1562# Now test prop_invmap(). 1563 1564@list = prop_invmap("Unknown property"); 1565is (@list, 0, "prop_invmap(<Unknown property>) returns an empty list"); 1566@list = prop_invmap(undef); 1567is (@list, 0, "prop_invmap(undef) returns an empty list"); 1568ok (! eval "prop_invmap('gc')" && $@ ne "", 1569 "prop_invmap('gc') dies in scalar context"); 1570@list = prop_invmap("_X_Begin"); 1571is (@list, 0, "prop_invmap(<internal property>) returns an empty list"); 1572@list = prop_invmap("InKana"); 1573is(@list, 0, "prop_invmap(<user-defined property returns undef>)"); 1574@list = prop_invmap("Perl_Decomposition_Mapping"), undef, 1575is(@list, 0, "prop_invmap('Perl_Decomposition_Mapping') returns <undef> since internal-Perl-only"); 1576@list = prop_invmap("Perl_Charnames"), undef, 1577is(@list, 0, "prop_invmap('Perl_Charnames') returns <undef> since internal-Perl-only"); 1578@list = prop_invmap("Is_Is_Any"); 1579is(@list, 0, "prop_invmap('Is_Is_Any') returns <undef> since two is's"); 1580 1581# The files for these properties are not used by Perl, but are retained for 1582# backwards compatibility with applications that read them directly, with 1583# comments in them that their use is deprecated. Until such time as we remove 1584# them completely, we test that they exist, are correct, and that their 1585# formats haven't changed. This hash contains the info needed to test them as 1586# if they were regular properties. 'replaced_by' gives the equivalent 1587# property now used by Perl. 1588my %legacy_props = ( 1589 Legacy_Case_Folding => { replaced_by => 'cf', 1590 file => 'To/Fold', 1591 swash_name => 'ToFold' 1592 }, 1593 Legacy_Lowercase_Mapping => { replaced_by => 'lc', 1594 file => 'To/Lower', 1595 swash_name => 'ToLower' 1596 }, 1597 Legacy_Titlecase_Mapping => { replaced_by => 'tc', 1598 file => 'To/Title', 1599 swash_name => 'ToTitle' 1600 }, 1601 Legacy_Uppercase_Mapping => { replaced_by => 'uc', 1602 file => 'To/Upper', 1603 swash_name => 'ToUpper' 1604 }, 1605 Legacy_Perl_Decimal_Digit => { replaced_by => 'Perl_Decimal_Digit', 1606 file => 'To/Digit', 1607 swash_name => 'ToDigit' 1608 }, 1609 ); 1610 1611foreach my $legacy_prop (keys %legacy_props) { 1612 @list = prop_invmap($legacy_prop); 1613 is(@list, 0, "'$legacy_prop' is unknown to prop_invmap"); 1614} 1615 1616# The files for these properties shouldn't have their formats changed in case 1617# applications use them (though such use is deprecated). 1618my @legacy_file_format = (keys %legacy_props, 1619 qw( Bidi_Mirroring_Glyph 1620 NFKC_Casefold 1621 ) 1622 ); 1623 1624# The set of properties to test on has already been compiled into %props by 1625# the prop_aliases() tests. 1626 1627my %tested_invmaps; 1628 1629# Like prop_invlist(), prop_invmap() is tested by comparing the results 1630# returned by the function with the tables that mktables generates. Some of 1631# these tables are directly stored as files on disk, in either the unicore or 1632# unicore/To directories, and most should be listed in the mktables generated 1633# hash %utf8::loose_property_to_file_of, with a few additional ones that this 1634# handles specially. For these, the files are read in directly, massaged, and 1635# compared with what invmap() returns. The SPECIALS hash in some of these 1636# files overrides values in the main part of the file. 1637# 1638# The other properties are tested indirectly by generating all the possible 1639# inversion lists for the property, and seeing if those match the inversion 1640# lists returned by prop_invlist(), which has already been tested. 1641 1642PROPERTY: 1643foreach my $prop (sort(keys %props), sort keys %legacy_props) { 1644 my $is_legacy = 0; 1645 my $loose_prop = &utf8::_loose_name(lc $prop); 1646 my $suppressed = grep { $_ eq $loose_prop } 1647 @Unicode::UCD::suppressed_properties; 1648 1649 my $actual_lookup_prop; 1650 my $display_prop; # The property name that is displayed, as opposed 1651 # to the one that is actually used. 1652 1653 # Find the short and full names that this property goes by 1654 my ($name, $full_name) = prop_aliases($prop); 1655 if (! $name) { 1656 1657 # Here, Perl doesn't know about this property. It could be a 1658 # suppressed one, or a legacy one. 1659 if (grep { $prop eq $_ } keys %legacy_props) { 1660 1661 # For legacy properties, we look up the modern equivalent 1662 # property instead; later massaging the results to look like the 1663 # known format of the legacy property. We add info about the 1664 # legacy property to the data structures for the rest of the 1665 # properties; this is to avoid more special cases for the legacies 1666 # in the code below 1667 $full_name = $name = $prop; 1668 $actual_lookup_prop = $legacy_props{$prop}->{'replaced_by'}; 1669 my $base_file = $legacy_props{$prop}->{'file'}; 1670 1671 # This legacy property is otherwise unknown to Perl; so shouldn't 1672 # have any information about it already. 1673 ok(! exists $utf8::loose_property_to_file_of{$loose_prop}, 1674 "There isn't a hash entry for file lookup of $prop"); 1675 $utf8::loose_property_to_file_of{$loose_prop} = $base_file; 1676 1677 ok(! exists $utf8::file_to_swash_name{$loose_prop}, 1678 "There isn't a hash entry for swash lookup of $prop"); 1679 $utf8::file_to_swash_name{$base_file} 1680 = $legacy_props{$prop}->{'swash_name'}; 1681 $display_prop = $prop; 1682 $is_legacy = 1; 1683 } 1684 else { 1685 if (! $suppressed) { 1686 fail("prop_invmap('$prop')"); 1687 diag("is unknown to prop_aliases(), and we need it in order to test prop_invmap"); 1688 } 1689 next PROPERTY; 1690 } 1691 } 1692 1693 # Normalize the short name, as it is stored in the hashes under the 1694 # normalized version. 1695 $name = &utf8::_loose_name(lc $name); 1696 1697 # In the case of a combination property, both a map table and a match 1698 # table are generated. For all the tests except prop_invmap(), this is 1699 # irrelevant, but for prop_invmap, having an 'is' prefix forces it to 1700 # return the match table; otherwise the map. We thus need to distinguish 1701 # between the two forms. The property name is what has this information. 1702 $name = &utf8::_loose_name(lc $prop) 1703 if exists $Unicode::UCD::combination_property{$name}; 1704 1705 # Add in the characters that are supposed to be ignored to test loose 1706 # matching, which the tested function applies to all properties 1707 $display_prop = "$extra_chars$prop" unless $display_prop; 1708 $actual_lookup_prop = $display_prop unless $actual_lookup_prop; 1709 1710 my ($invlist_ref, $invmap_ref, $format, $missing) = prop_invmap($actual_lookup_prop); 1711 my $return_ref = [ $invlist_ref, $invmap_ref, $format, $missing ]; 1712 1713 1714 # The legacy property files all are expanded out so that each range is 1 1715 # element long. That isn't true of the modern equivalent we use to check 1716 # those files for correctness against. So take the output of the proxy 1717 # and expand it to match the legacy file. 1718 if ($is_legacy) { 1719 my @expanded_list; 1720 my @expanded_map; 1721 for my $i (0 .. @$invlist_ref - 1 - 1) { 1722 if (ref $invmap_ref->[$i] || $invmap_ref->[$i] eq $missing) { 1723 1724 # No adjustments should be done for the default mapping and 1725 # the multi-char ones. 1726 push @expanded_list, $invlist_ref->[$i]; 1727 push @expanded_map, $invmap_ref->[$i]; 1728 } 1729 else { 1730 1731 # Expand the range into separate elements for each item. 1732 my $offset = 0; 1733 for my $j ($invlist_ref->[$i] .. $invlist_ref->[$i+1] -1) { 1734 push @expanded_list, $j; 1735 push @expanded_map, $invmap_ref->[$i] + $offset; 1736 1737 # The 'ae' format is for Legacy_Perl_Decimal_Digit; the 1738 # other 4 are kept with leading zeros in the file, so 1739 # convert to that. 1740 $expanded_map[-1] = sprintf("%04X", $expanded_map[-1]) 1741 if $format ne 'ae'; 1742 $offset++; 1743 } 1744 } 1745 } 1746 1747 # Final element is taken as is. The map should always be to the 1748 # default value, so don't do a sprintf like we did above. 1749 push @expanded_list, $invlist_ref->[-1]; 1750 push @expanded_map, $invmap_ref->[-1]; 1751 1752 $invlist_ref = \@expanded_list; 1753 $invmap_ref = \@expanded_map; 1754 } 1755 1756 # If have already tested this property under a different name, merely 1757 # compare the return from now with the saved one from before. 1758 if (exists $tested_invmaps{$name}) { 1759 is_deeply($return_ref, $tested_invmaps{$name}, "prop_invmap('$display_prop') gave same results as its synonym, '$name'"); 1760 next PROPERTY; 1761 } 1762 $tested_invmaps{$name} = dclone $return_ref; 1763 1764 # If prop_invmap() returned nothing, is ok iff is a property whose file is 1765 # not generated. 1766 if ($suppressed) { 1767 if (defined $format) { 1768 fail("prop_invmap('$display_prop')"); 1769 diag("did not return undef for suppressed property $prop"); 1770 } 1771 next PROPERTY; 1772 } 1773 elsif (!defined $format) { 1774 fail("prop_invmap('$display_prop')"); 1775 diag("'$prop' is unknown to prop_invmap()"); 1776 next PROPERTY; 1777 } 1778 1779 # The two parallel arrays must have the same number of elements. 1780 if (@$invlist_ref != @$invmap_ref) { 1781 fail("prop_invmap('$display_prop')"); 1782 diag("invlist has " 1783 . scalar @$invlist_ref 1784 . " while invmap has " 1785 . scalar @$invmap_ref 1786 . " elements"); 1787 next PROPERTY; 1788 } 1789 1790 # The last element must be for the above-Unicode code points, and must be 1791 # for the default value. 1792 if ($invlist_ref->[-1] != 0x110000) { 1793 fail("prop_invmap('$display_prop')"); 1794 diag("The last inversion list element is not 0x110000"); 1795 next PROPERTY; 1796 } 1797 1798 my $upper_limit_subtract; 1799 1800 # prop_invmap() adds an extra element not present in the disk files for 1801 # the above-Unicode code points. For almost all properties, that will be 1802 # to $missing. In that case we don't look further at it when comparing 1803 # with the disk files. 1804 if ($invmap_ref->[-1] eq $missing) { 1805 $upper_limit_subtract = 1; 1806 } 1807 elsif ($invmap_ref->[-1] eq 'Y' && ! grep { $_ !~ /[YN]/ } @$invmap_ref) { 1808 1809 # But that's not true for a few binary properties like 'Unassigned' 1810 # that are Perl extensions (in this case for Gc=Unassigned) which 1811 # match above-Unicode code points (hence the 'Y' in the test above). 1812 # For properties where it isn't $missing, we're going to want to look 1813 # at the whole thing when comparing with the disk file. 1814 $upper_limit_subtract = 0; 1815 1816 # In those properties like 'Unassigned, the final element should be 1817 # just a repetition of the next-to-last element, and won't be in the 1818 # disk file, so remove it for the comparison. Otherwise, we will 1819 # compare the whole of the array with the whole of the disk file. 1820 if ($invlist_ref->[-2] <= 0x10FFFF && $invmap_ref->[-2] eq 'Y') { 1821 pop @$invlist_ref; 1822 pop @$invmap_ref; 1823 } 1824 } 1825 else { 1826 fail("prop_invmap('$display_prop')"); 1827 diag("The last inversion list element is '$invmap_ref->[-1]', and should be '$missing'"); 1828 next PROPERTY; 1829 } 1830 1831 if ($name eq 'bmg') { # This one has an atypical $missing 1832 if ($missing ne "") { 1833 fail("prop_invmap('$display_prop')"); 1834 diag("The missings should be \"\"; got '$missing'"); 1835 next PROPERTY; 1836 } 1837 } 1838 elsif ($format =~ /^ a (?!r) /x) { 1839 if ($full_name eq 'Perl_Decimal_Digit') { 1840 if ($missing ne "") { 1841 fail("prop_invmap('$display_prop')"); 1842 diag("The missings should be \"\"; got '$missing'"); 1843 next PROPERTY; 1844 } 1845 } 1846 elsif ($missing ne "0" && ! grep { $prop eq $_ } keys %legacy_props) { 1847 fail("prop_invmap('$display_prop')"); 1848 diag("The missings should be '0'; got '$missing'"); 1849 next PROPERTY; 1850 } 1851 } 1852 elsif ($missing =~ /[<>]/) { 1853 fail("prop_invmap('$display_prop')"); 1854 diag("The missings should NOT be something with <...>'"); 1855 next PROPERTY; 1856 1857 # I don't want to hard code in what all the missings should be, so 1858 # those don't get fully tested. 1859 } 1860 1861 # Certain properties don't have their own files, but must be constructed 1862 # using proxies. 1863 my $proxy_prop = $name; 1864 if ($full_name eq 'Present_In') { 1865 $proxy_prop = "age"; # The maps for these two props are identical 1866 } 1867 elsif ($full_name eq 'Simple_Case_Folding' 1868 || $full_name =~ /Simple_ (.) .*? case_Mapping /x) 1869 { 1870 if ($full_name eq 'Simple_Case_Folding') { 1871 $proxy_prop = 'cf'; 1872 } 1873 else { 1874 # We captured the U, L, or T, leading to uc, lc, or tc. 1875 $proxy_prop = lc $1 . "c"; 1876 } 1877 if ($format ne "a") { 1878 fail("prop_invmap('$display_prop')"); 1879 diag("The format should be 'a'; got '$format'"); 1880 next PROPERTY; 1881 } 1882 } 1883 1884 if ($format !~ / ^ (?: a [der]? | ale? | n | sl? ) $ /x) { 1885 fail("prop_invmap('$display_prop')"); 1886 diag("Unknown format '$format'"); 1887 next PROPERTY; 1888 } 1889 1890 my $base_file; 1891 my $official; 1892 1893 # Handle the properties that have full disk files for them (except the 1894 # Name property which is structurally enough different that it is handled 1895 # separately below.) 1896 if ($name ne 'na' 1897 && ($name eq 'blk' 1898 || defined 1899 ($base_file = $utf8::loose_property_to_file_of{$proxy_prop}) 1900 || exists $utf8::loose_to_file_of{$proxy_prop} 1901 || $name eq "dm")) 1902 { 1903 # In the above, blk is done unconditionally, as we need to test that 1904 # the old-style block names are returned, even if mktables has 1905 # generated a file for the new-style; the test for dm comes afterward, 1906 # so that if a file has been generated for it explicitly, we use that 1907 # file (which is valid, unlike blk) instead of the combo 1908 # Decomposition.pl files. 1909 my $file; 1910 my $is_binary = 0; 1911 if ($name eq 'blk') { 1912 1913 # The blk property is special. The original file with old block 1914 # names is retained, and the default (on ASCII platforms) is to 1915 # not write out a new-name file. What we do is get the old names 1916 # into a data structure, and from that create what the new file 1917 # would look like. $base_file is needed to be defined, just to 1918 # avoid a message below. 1919 $base_file = "This is a dummy name"; 1920 my $blocks_ref = charblocks(); 1921 1922 if ($::IS_EBCDIC) { 1923 # On EBCDIC, the first two blocks can each contain multiple 1924 # ranges. We create a new version with each of these 1925 # flattened, so have one level. ($index is used as a dummy 1926 # key.) 1927 my %new_blocks; 1928 my $index = 0; 1929 foreach my $block (values %$blocks_ref) { 1930 foreach my $range (@$block) { 1931 $new_blocks{$index++}[0] = $range; 1932 } 1933 } 1934 $blocks_ref = \%new_blocks; 1935 } 1936 $official = ""; 1937 for my $range (sort { $a->[0][0] <=> $b->[0][0] } 1938 values %$blocks_ref) 1939 { 1940 # Translate the charblocks() data structure to what the file 1941 # would look like. (The sub range is for EBCDIC platforms 1942 # where Latin1 and ASCII are intermixed.) 1943 if ($range->[0][0] == $range->[0][1]) { 1944 $official .= sprintf("%X\t\t%s\n", 1945 $range->[0][0], 1946 $range->[0][2]); 1947 } 1948 else { 1949 $official .= sprintf("%X\t%X\t%s\n", 1950 $range->[0][0], 1951 $range->[0][1], 1952 $range->[0][2]); 1953 } 1954 } 1955 } 1956 else { 1957 $base_file = "Decomposition" if $format eq 'ad'; 1958 1959 # Above leaves $base_file undefined only if it came from the hash 1960 # below. This should happen only when it is a binary property 1961 # (and are accessing via a single-form name, like 'In_Latin1'), 1962 # and so it is stored in a different directory than the To ones. 1963 # XXX Currently, the only cases where it is complemented are the 1964 # ones that have no code points. And it works out for these that 1965 # 1) complementing them, and then 2) adding or subtracting the 1966 # initial 0 and final 110000 cancel each other out. But further 1967 # work would be needed in the unlikely event that an inverted 1968 # property comes along without these characteristics 1969 if (!defined $base_file) { 1970 $base_file = $utf8::loose_to_file_of{$proxy_prop}; 1971 $is_binary = ($base_file =~ s/!//) ? -1 : 1; 1972 $base_file = "lib/$base_file" unless $base_file =~ m!^#/!; 1973 } 1974 1975 # Read in the file. If the file's directory is '#', it is a 1976 # special case where the contents are in-lined with semi-colons 1977 # meaning new-lines, instead of it being an actual file to read. 1978 if ($base_file =~ s!^#/!!) { 1979 $official = $utf8::inline_definitions[$base_file]; 1980 } 1981 else { 1982 $official = do "unicore/$base_file.pl"; 1983 } 1984 1985 # Get rid of any trailing space and comments in the file. 1986 $official =~ s/\s*(#.*)?$//mg; 1987 1988 if ($format eq 'ad') { 1989 my @official = split /\n/, $official; 1990 $official = ""; 1991 foreach my $line (@official) { 1992 my ($start, $end, $value) 1993 = $line =~ / ^ (.+?) \t (.*?) \t (.+?) 1994 \s* ( \# .* )? $ /x; 1995 # Decomposition.pl also has the <compatible> types in it, 1996 # which should be removed. 1997 $value =~ s/<.*?> //; 1998 $official .= "$start\t\t$value\n"; 1999 2000 # If this is a multi-char range, we turn it into as many 2001 # single character ranges as necessary. This makes things 2002 # easier below. 2003 if ($end ne "") { 2004 for my $i (hex($start) + 1 .. hex $end) { 2005 $official .= sprintf "%X\t\t%s\n", $i, $value; 2006 } 2007 } 2008 } 2009 } 2010 } 2011 local $/ = "\n"; 2012 chomp $official; 2013 $/ = $input_record_separator; 2014 2015 # Get the format for the file, and if there are any special elements, 2016 # get a reference to them. 2017 my $swash_name = $utf8::file_to_swash_name{$base_file}; 2018 my $specials_ref; 2019 my $file_format; # The 'format' given inside the file 2020 if ($swash_name) { 2021 $specials_ref = $utf8::SwashInfo{$swash_name}{'specials_name'}; 2022 if ($specials_ref) { 2023 2024 # Convert from the name to the actual reference. 2025 no strict 'refs'; 2026 $specials_ref = \%{$specials_ref}; 2027 } 2028 2029 $file_format = $utf8::SwashInfo{$swash_name}{'format'}; 2030 } 2031 2032 # Leading zeros used to be used with the values in the files that give, 2033 # ranges, but these have been mostly stripped off, except for some 2034 # files whose formats should not change in any way. 2035 my $file_range_format = (grep { $full_name eq $_ } @legacy_file_format) 2036 ? "%04X" 2037 : "%X"; 2038 # Currently this property still has leading zeroes in the mapped-to 2039 # values, but otherwise, those values follow the same rules as the 2040 # ranges. 2041 my $file_map_format = ($full_name eq 'Decomposition_Mapping') 2042 ? "%04X" 2043 : $file_range_format; 2044 2045 # Certain of the proxy properties have to be adjusted to match the 2046 # real ones. 2047 if ($full_name 2048 =~ /^(Legacy_)?(Case_Folding|(Lower|Title|Upper)case_Mapping)/) 2049 { 2050 2051 # Here we have either 2052 # 1) Case_Folding; or 2053 # 2) a proxy that is a full mapping, which means that what the 2054 # real property is is the equivalent simple mapping. 2055 # In both cases, the file will have a standard list containing 2056 # simple mappings (to a single code point), and a specials hash 2057 # which contains all the mappings that are to multiple code 2058 # points. First, extract a list containing all the file's simple 2059 # mappings. 2060 my @list; 2061 for (split "\n", $official) { 2062 my ($start, $end, $value) = / ^ (.+?) \t (.*?) \t (.+?) 2063 \s* ( \# .* )? $ /x; 2064 $end = $start if $end eq ""; 2065 push @list, [ hex $start, hex $end, hex $value ]; 2066 } 2067 2068 # For these mappings, the file contains all the simple mappings, 2069 # including the ones that are overridden by the specials. These 2070 # need to be removed as the list is for just the full ones. 2071 2072 # Go through any special mappings one by one. The keys are the 2073 # UTF-8 representation of code points. 2074 my $i = 0; 2075 foreach my $utf8_cp (sort keys %$specials_ref) { 2076 my $cp = $utf8_cp; 2077 utf8::decode($cp); 2078 $cp = ord $cp; 2079 2080 # Find the spot in the @list of simple mappings that this 2081 # special applies to; uses a linear search. 2082 while ($i < @list -1 ) { 2083 last if $cp <= $list[$i][1]; 2084 $i++; 2085 } 2086 2087 # Here $i is such that it points to the first range which ends 2088 # at or above cp, and hence is the only range that could 2089 # possibly contain it. 2090 2091 # If not in this range, no range contains it: nothing to 2092 # remove. 2093 next if $cp < $list[$i][0]; 2094 2095 # Otherwise, remove the existing entry. If it is the first 2096 # element of the range... 2097 if ($cp == $list[$i][0]) { 2098 2099 # ... and there are other elements in the range, just 2100 # shorten the range to exclude this code point. 2101 if ($list[$i][1] > $list[$i][0]) { 2102 $list[$i][0]++; 2103 } 2104 2105 # ... but if it is the only element in the range, remove 2106 # it entirely. 2107 else { 2108 splice @list, $i, 1; 2109 } 2110 } 2111 else { # Is somewhere in the middle of the range 2112 # Split the range into two, excluding this one in the 2113 # middle 2114 splice @list, $i, 1, 2115 [ $list[$i][0], $cp - 1, $list[$i][2] ], 2116 [ $cp + 1, $list[$i][1], $list[$i][2] ]; 2117 } 2118 } 2119 2120 # Here, have gone through all the specials, modifying @list as 2121 # needed. Turn it back into what the file should look like. 2122 $official = ""; 2123 for my $element (@list) { 2124 $official .= "\n" if $official; 2125 if ($element->[1] == $element->[0]) { 2126 $official 2127 .= sprintf "$file_range_format\t\t$file_map_format", 2128 $element->[0], $element->[2]; 2129 } 2130 else { 2131 $official .= sprintf "$file_range_format\t$file_range_format\t$file_map_format", 2132 $element->[0], 2133 $element->[1], 2134 $element->[2]; 2135 } 2136 } 2137 } 2138 elsif ($full_name 2139 =~ / ^ Simple_(Case_Folding|(Lower|Title|Upper)case_Mapping) $ /x) 2140 { 2141 2142 # These properties have everything in the regular array, and the 2143 # specials are superfluous. 2144 undef $specials_ref; 2145 } 2146 elsif ($format !~ /^a/ && defined $file_format && $file_format eq 'x') { 2147 2148 # For these properties the file is output using hex notation for the 2149 # map. Convert from hex to decimal. 2150 my @lines = split "\n", $official; 2151 foreach my $line (@lines) { 2152 my ($lower, $upper, $map) = split "\t", $line; 2153 $line = "$lower\t$upper\t" . hex $map; 2154 } 2155 $official = join "\n", @lines; 2156 } 2157 2158 # Here, in $official, we have what the file looks like, or should like 2159 # if we've had to fix it up. Now take the invmap() output and reverse 2160 # engineer from that what the file should look like. Each iteration 2161 # appends the next line to the running string. 2162 my $tested_map = ""; 2163 2164 # For use with files for binary properties only, which are stored in 2165 # inversion list format. This counts the number of data lines in the 2166 # file. 2167 my $binary_count = 0; 2168 2169 # Create a copy of the file's specials hash. (It has been undef'd if 2170 # we know it isn't relevant to this property, so if it exists, it's an 2171 # error or is relevant). As we go along, we delete from that copy. 2172 # If a delete fails, or something is left over after we are done, 2173 # it's an error 2174 my %specials = %$specials_ref if $specials_ref; 2175 2176 # The extra -$upper_limit_subtract is because the final element may 2177 # have been tested above to be for anything above Unicode, in which 2178 # case the file may not go that high. 2179 for (my $i = 0; $i < @$invlist_ref - $upper_limit_subtract; $i++) { 2180 2181 # If the map element is a reference, have to stringify it (but 2182 # don't do so if the format doesn't allow references, so that an 2183 # improper format will generate an error. 2184 if (ref $invmap_ref->[$i] 2185 && ($format eq 'ad' || $format =~ /^ . l /x)) 2186 { 2187 # The stringification depends on the format. 2188 if ($format eq 'sl') { 2189 2190 # At the time of this writing, there are two types of 'sl' 2191 # format One, in Name_Alias, has multiple separate 2192 # entries for each code point; the other, in 2193 # Script_Extension, is space separated. Assume the latter 2194 # for non-Name_Alias. 2195 if ($full_name ne 'Name_Alias') { 2196 $invmap_ref->[$i] = join " ", @{$invmap_ref->[$i]}; 2197 } 2198 else { 2199 # For Name_Alias, we emulate the file. Entries with 2200 # just one value don't need any changes, but we 2201 # convert the list entries into a series of lines for 2202 # the file, starting with the first name. The 2203 # succeeding entries are on separate lines, with the 2204 # code point repeated for each one and then two tabs, 2205 # then the value. Code at the end of the loop will 2206 # set up the first line with its code point and two 2207 # tabs before the value, just as it does for every 2208 # other property; thus the special handling of the 2209 # first line. 2210 if (ref $invmap_ref->[$i]) { 2211 my $hex_cp = sprintf("%X", $invlist_ref->[$i]); 2212 my $concatenated = $invmap_ref->[$i][0]; 2213 for (my $j = 1; $j < @{$invmap_ref->[$i]}; $j++) { 2214 $concatenated .= "\n$hex_cp\t\t" 2215 . $invmap_ref->[$i][$j]; 2216 } 2217 $invmap_ref->[$i] = $concatenated; 2218 } 2219 } 2220 } 2221 elsif ($format =~ / ^ al e? $/x) { 2222 2223 # For an al property, the stringified result should be in 2224 # the specials hash. The key is the utf8 bytes of the 2225 # code point, and the value is its map as a utf-8 string. 2226 my $value; 2227 my $key = chr $invlist_ref->[$i]; 2228 utf8::encode($key); 2229 if (! defined ($value = delete $specials{$key})) { 2230 fail("prop_invmap('$display_prop')"); 2231 diag(sprintf "There was no specials element for %04X", $invlist_ref->[$i]); 2232 next PROPERTY; 2233 } 2234 my $packed = pack "W*", @{$invmap_ref->[$i]}; 2235 utf8::upgrade($packed); 2236 if ($value ne $packed) { 2237 fail("prop_invmap('$display_prop')"); 2238 diag(sprintf "For %04X, expected the mapping to be " 2239 . "'$packed', but got '$value'", $invlist_ref->[$i]); 2240 next PROPERTY; 2241 } 2242 2243 # As this doesn't get tested when we later compare with 2244 # the actual file, it could be out of order and we 2245 # wouldn't know it. 2246 if (($i > 0 && $invlist_ref->[$i] <= $invlist_ref->[$i-1]) 2247 || $invlist_ref->[$i] >= $invlist_ref->[$i+1]) 2248 { 2249 fail("prop_invmap('$display_prop')"); 2250 diag(sprintf "Range beginning at %04X is out-of-order.", $invlist_ref->[$i]); 2251 next PROPERTY; 2252 } 2253 next; 2254 } 2255 elsif ($format eq 'ad') { 2256 2257 # The decomposition mapping file has the code points as 2258 # a string of space-separated hex constants. 2259 $invmap_ref->[$i] = join " ", map { sprintf "%04X", $_ } 2260 @{$invmap_ref->[$i]}; 2261 } 2262 else { 2263 fail("prop_invmap('$display_prop')"); 2264 diag("Can't handle format '$format'"); 2265 next PROPERTY; 2266 } 2267 } # Otherwise, the map is to a simple scalar 2268 elsif (defined $file_format && $file_format eq 'ax') { 2269 # These maps are in hex 2270 $invmap_ref->[$i] = sprintf("%X", $invmap_ref->[$i]); 2271 } 2272 elsif ($format eq 'ad' || $format eq 'ale') { 2273 2274 # The numerics in the returned map are stored as adjusted 2275 # decimal integers. The defaults are 0, and don't appear in 2276 # $official, and are excluded later, but the elements must be 2277 # converted back to their hex values before comparing with 2278 # $official, as these files, for backwards compatibility, are 2279 # not stored as adjusted. (There currently is only one ale 2280 # property, nfkccf. If that changed this would also have to.) 2281 if ($invmap_ref->[$i] =~ / ^ -? \d+ $ /x 2282 && $invmap_ref->[$i] != 0) 2283 { 2284 my $next = $invmap_ref->[$i] + 1; 2285 $invmap_ref->[$i] = sprintf($file_map_format, 2286 $invmap_ref->[$i]); 2287 2288 # If there are other elements in this range they need to 2289 # be adjusted; they must individually be re-mapped. Do 2290 # this by splicing in a new element into the list and the 2291 # map containing the remainder of the range. Next time 2292 # through we will look at that (possibly splicing again 2293 # until the whole range is processed). 2294 if ($invlist_ref->[$i+1] > $invlist_ref->[$i] + 1) { 2295 splice @$invlist_ref, $i+1, 0, 2296 $invlist_ref->[$i] + 1; 2297 splice @$invmap_ref, $i+1, 0, $next; 2298 } 2299 } 2300 if ($format eq 'ale' && $invmap_ref->[$i] eq "") { 2301 2302 # ale properties have maps to the empty string that also 2303 # should be in the specials hash, with the key the utf8 2304 # bytes representing the code point, and the map just empty. 2305 my $value; 2306 my $key = chr $invlist_ref->[$i]; 2307 utf8::encode($key); 2308 if (! defined ($value = delete $specials{$key})) { 2309 fail("prop_invmap('$display_prop')"); 2310 diag(sprintf "There was no specials element for %04X", $invlist_ref->[$i]); 2311 next PROPERTY; 2312 } 2313 if ($value ne "") { 2314 fail("prop_invmap('$display_prop')"); 2315 diag(sprintf "For %04X, expected the mapping to be \"\", but got '$value'", $invlist_ref->[$i]); 2316 next PROPERTY; 2317 } 2318 2319 # As this doesn't get tested when we later compare with 2320 # the actual file, it could be out of order and we 2321 # wouldn't know it. 2322 if (($i > 0 && $invlist_ref->[$i] <= $invlist_ref->[$i-1]) 2323 || $invlist_ref->[$i] >= $invlist_ref->[$i+1]) 2324 { 2325 fail("prop_invmap('$display_prop')"); 2326 diag(sprintf "Range beginning at %04X is out-of-order.", $invlist_ref->[$i]); 2327 next PROPERTY; 2328 } 2329 next; 2330 } 2331 } 2332 elsif ($is_binary) { # These binary files don't have an explicit Y 2333 $invmap_ref->[$i] =~ s/Y//; 2334 } 2335 2336 # The file doesn't include entries that map to $missing, so don't 2337 # include it in the built-up string. But make sure that it is in 2338 # the correct order in the input. 2339 if ($invmap_ref->[$i] eq $missing) { 2340 if (($i > 0 && $invlist_ref->[$i] <= $invlist_ref->[$i-1]) 2341 || $invlist_ref->[$i] >= $invlist_ref->[$i+1]) 2342 { 2343 fail("prop_invmap('$display_prop')"); 2344 diag(sprintf "Range beginning at %04X is out-of-order.", $invlist_ref->[$i]); 2345 next PROPERTY; 2346 } 2347 next; 2348 } 2349 2350 # The ad property has one entry which isn't in the file. 2351 # Ignore it, but make sure it is in order. 2352 if ($format eq 'ad' 2353 && $invmap_ref->[$i] eq '<hangul syllable>' 2354 && $invlist_ref->[$i] == 0xAC00) 2355 { 2356 if (($i > 0 && $invlist_ref->[$i] <= $invlist_ref->[$i-1]) 2357 || $invlist_ref->[$i] >= $invlist_ref->[$i+1]) 2358 { 2359 fail("prop_invmap('$display_prop')"); 2360 diag(sprintf "Range beginning at %04X is out-of-order.", $invlist_ref->[$i]); 2361 next PROPERTY; 2362 } 2363 next; 2364 } 2365 2366 # Finally have figured out what the map column in the file should 2367 # be. Append the line to the running string. 2368 my $start = $invlist_ref->[$i]; 2369 my $end = (defined $invlist_ref->[$i+1]) 2370 ? $invlist_ref->[$i+1] - 1 2371 : $Unicode::UCD::MAX_CP; 2372 if ($is_binary) { 2373 2374 # Files for binary properties are in inversion list format, 2375 # without ranges. 2376 $tested_map .= "$start\n"; 2377 $binary_count++; 2378 2379 # If the final value is infinity, no line for it exists. 2380 if ($end < $Unicode::UCD::MAX_CP) { 2381 $tested_map .= ($end + 1) . "\n"; 2382 $binary_count++; 2383 } 2384 } 2385 else { 2386 $end = ($start == $end) ? "" : sprintf($file_range_format, $end); 2387 if ($invmap_ref->[$i] ne "") { 2388 $tested_map .= sprintf "$file_range_format\t%s\t%s\n", 2389 $start, $end, $invmap_ref->[$i]; 2390 } 2391 elsif ($end ne "") { 2392 $tested_map .= sprintf "$file_range_format\t%s\n", 2393 $start, $end; 2394 } 2395 else { 2396 $tested_map .= sprintf "$file_range_format\n", $start; 2397 } 2398 } 2399 } # End of looping over all elements. 2400 2401 # Binary property files begin with a line count line. 2402 $tested_map = "V$binary_count\n$tested_map" if $binary_count; 2403 2404 # Here are done with generating what the file should look like 2405 2406 local $/ = "\n"; 2407 chomp $tested_map; 2408 $/ = $input_record_separator; 2409 2410 # And compare. 2411 if ($tested_map ne $official) { 2412 fail_with_diff($display_prop, $official, $tested_map, "prop_invmap"); 2413 next PROPERTY; 2414 } 2415 2416 # There shouldn't be any specials unaccounted for. 2417 if (keys %specials) { 2418 fail("prop_invmap('$display_prop')"); 2419 diag("Unexpected specials: " . join ", ", keys %specials); 2420 next PROPERTY; 2421 } 2422 } 2423 elsif ($format eq 'n') { 2424 2425 # Handle the Name property similar to the above. But the file is 2426 # sufficiently different that it is more convenient to make a special 2427 # case for it. It is a combination of the Name, Unicode1_Name, and 2428 # Name_Alias properties, and named sequences. We need to remove all 2429 # but the Name in order to do the comparison. 2430 2431 if ($missing ne "") { 2432 fail("prop_invmap('$display_prop')"); 2433 diag("The missings should be \"\"; got \"missing\""); 2434 next PROPERTY; 2435 } 2436 2437 $official = do "unicore/Name.pl"; 2438 2439 # Get rid of the named sequences portion of the file. These don't 2440 # have a tab before the first blank on a line. 2441 $official =~ s/ ^ [^\t]+ \ .*? \n //xmg; 2442 2443 # And get rid of the controls. These are named in the file, but 2444 # shouldn't be in the property. This gets rid of the two ranges in 2445 # one fell swoop, and also all the Unicode1_Name values that may not 2446 # be in Name_Alias. 2447 if ($::IS_ASCII) { 2448 $official =~ s/ 00000 \t .* 0001F .*? \n//xs; 2449 $official =~ s/ 0007F \t .* 0009F .*? \n//xs; 2450 } 2451 elsif ($::IS_EBCDIC) { # Won't work for POSIX-BC 2452 $official =~ s/ 00000 \t .* 0003F .*? \n//xs; 2453 $official =~ s/ 000FF \t .* 000FF .*? \n//xs; 2454 } 2455 2456 # And remove the aliases. We read in the Name_Alias property, and go 2457 # through them one by one. 2458 my ($aliases_code_points, $aliases_maps, undef, undef) 2459 = &prop_invmap('_Perl_Name_Alias', '_perl_core_internal_ok'); 2460 for (my $i = 0; $i < @$aliases_code_points; $i++) { 2461 my $code_point = $aliases_code_points->[$i]; 2462 2463 # Already removed these above. 2464 next if $code_point <= 0x1F 2465 || ($code_point >= 0x7F && $code_point <= 0x9F); 2466 2467 my $hex_code_point = sprintf "%05X", $code_point; 2468 2469 # Convert to a list if not already to make the following loop 2470 # control uniform. 2471 $aliases_maps->[$i] = [ $aliases_maps->[$i] ] 2472 if ! ref $aliases_maps->[$i]; 2473 2474 # Remove each alias for this code point from the file 2475 foreach my $alias (@{$aliases_maps->[$i]}) { 2476 2477 # Remove the alias type from the entry, retaining just the name. 2478 $alias =~ s/:.*//; 2479 2480 $alias = quotemeta($alias); 2481 $official =~ s/$hex_code_point \t $alias \n //x; 2482 } 2483 } 2484 local $/ = "\n"; 2485 chomp $official; 2486 $/ = $input_record_separator; 2487 2488 # Here have adjusted the file. We also have to adjust the returned 2489 # inversion map by checking and deleting all the lines in it that 2490 # won't be in the file. These are the lines that have generated 2491 # things, like <hangul syllable>. 2492 my $tested_map = ""; # Current running string 2493 my @code_point_in_names = 2494 @Unicode::UCD::code_points_ending_in_code_point; 2495 2496 for my $i (0 .. @$invlist_ref - 1 - $upper_limit_subtract) { 2497 my $start = $invlist_ref->[$i]; 2498 my $end = $invlist_ref->[$i+1] - 1; 2499 if ($invmap_ref->[$i] eq $missing) { 2500 if (($i > 0 && $invlist_ref->[$i] <= $invlist_ref->[$i-1]) 2501 || $invlist_ref->[$i] >= $invlist_ref->[$i+1]) 2502 { 2503 fail("prop_invmap('$display_prop')"); 2504 diag(sprintf "Range beginning at %04X is out-of-order.", $invlist_ref->[$i]); 2505 next PROPERTY; 2506 } 2507 next; 2508 } 2509 if ($invmap_ref->[$i] =~ / (.*) ( < .*? > )/x) { 2510 my $name = $1; 2511 my $type = $2; 2512 if (($i > 0 && $invlist_ref->[$i] <= $invlist_ref->[$i-1]) 2513 || $invlist_ref->[$i] >= $invlist_ref->[$i+1]) 2514 { 2515 fail("prop_invmap('$display_prop')"); 2516 diag(sprintf "Range beginning at %04X is out-of-order.", $invlist_ref->[$i]); 2517 next PROPERTY; 2518 } 2519 if ($type eq "<hangul syllable>") { 2520 if ($name ne "") { 2521 fail("prop_invmap('$display_prop')"); 2522 diag("Unexpected text in $invmap_ref->[$i]"); 2523 next PROPERTY; 2524 } 2525 if ($start != 0xAC00) { 2526 fail("prop_invmap('$display_prop')"); 2527 diag(sprintf("<hangul syllables> should begin at 0xAC00, got %04X", $start)); 2528 next PROPERTY; 2529 } 2530 if ($end != $start + 11172 - 1) { 2531 fail("prop_invmap('$display_prop')"); 2532 diag(sprintf("<hangul syllables> should end at %04X, got %04X", $start + 11172 -1, $end)); 2533 next PROPERTY; 2534 } 2535 } 2536 elsif ($type ne "<code point>") { 2537 fail("prop_invmap('$display_prop')"); 2538 diag("Unexpected text '$type' in $invmap_ref->[$i]"); 2539 next PROPERTY; 2540 } 2541 else { 2542 2543 # Look through the array of names that end in code points, 2544 # and look for this start and end. If not found is an 2545 # error. If found, delete it, and at the end, make sure 2546 # have deleted everything. 2547 for my $i (0 .. @code_point_in_names - 1) { 2548 my $hash = $code_point_in_names[$i]; 2549 if ($hash->{'low'} == $start 2550 && $hash->{'high'} == $end 2551 && "$hash->{'name'}-" eq $name) 2552 { 2553 splice @code_point_in_names, $i, 1; 2554 last; 2555 } 2556 else { 2557 fail("prop_invmap('$display_prop')"); 2558 diag("Unexpected code-point-in-name line '$invmap_ref->[$i]'"); 2559 next PROPERTY; 2560 } 2561 } 2562 } 2563 2564 next; 2565 } 2566 2567 # Have adjusted the map, as needed. Append to running string. 2568 $end = ($start == $end) ? "" : sprintf("%05X", $end); 2569 $tested_map .= sprintf "%05X\t%s\n", $start, $invmap_ref->[$i]; 2570 } 2571 2572 # Finished creating the string from the inversion map. Can compare 2573 # with what the file is. 2574 local $/ = "\n"; 2575 chomp $tested_map; 2576 $/ = $input_record_separator; 2577 if ($tested_map ne $official) { 2578 fail_with_diff($display_prop, $official, $tested_map, "prop_invmap"); 2579 next PROPERTY; 2580 } 2581 if (@code_point_in_names) { 2582 fail("prop_invmap('$display_prop')"); 2583 use Data::Dumper; 2584 diag("Missing code-point-in-name line(s)" . Dumper \@code_point_in_names); 2585 next PROPERTY; 2586 } 2587 } 2588 elsif ($format eq 's') { 2589 2590 # Here the map is not more or less directly from a file stored on 2591 # disk. We try a different tack. These should all be properties that 2592 # have just a few possible values (most of them are binary). We go 2593 # through the map list, sorting each range into buckets, one for each 2594 # map value. Thus for binary properties there will be a bucket for Y 2595 # and one for N. The buckets are inversion lists. We compare each 2596 # constructed inversion list with what we would get for it using 2597 # prop_invlist(), which has already been tested. If they all match, 2598 # the whole map must have matched. 2599 my %maps; 2600 my $previous_map; 2601 2602 for my $i (0 .. @$invlist_ref - 1 - $upper_limit_subtract) { 2603 my $range_start = $invlist_ref->[$i]; 2604 2605 # Because we are sorting into buckets, things could be 2606 # out-of-order here, and still be in the correct order in the 2607 # bucket, and hence wouldn't show up as an error; so have to 2608 # check. 2609 if (($i > 0 && $range_start <= $invlist_ref->[$i-1]) 2610 || $range_start >= $invlist_ref->[$i+1]) 2611 { 2612 fail("prop_invmap('$display_prop')"); 2613 diag(sprintf "Range beginning at %04X is out-of-order.", $invlist_ref->[$i]); 2614 next PROPERTY; 2615 } 2616 2617 # This new range closes out the range started in the previous 2618 # iteration. 2619 push @{$maps{$previous_map}}, $range_start if defined $previous_map; 2620 2621 # And starts a range which will be closed in the next iteration. 2622 $previous_map = $invmap_ref->[$i]; 2623 push @{$maps{$previous_map}}, $range_start; 2624 } 2625 2626 # The range we just started hasn't been closed, and we didn't look at 2627 # the final element of the loop. If that range is for the default 2628 # value, it shouldn't be closed, as it is to extend to infinity. But 2629 # otherwise, it should end at the final Unicode code point, and the 2630 # list that maps to the default value should have another element that 2631 # does go to infinity for every above Unicode code point. 2632 2633 if (@$invlist_ref > 1) { 2634 my $penultimate_map = $invmap_ref->[-2]; 2635 if ($penultimate_map ne $missing) { 2636 2637 # The -1th element contains the first non-Unicode code point. 2638 push @{$maps{$penultimate_map}}, $invlist_ref->[-1]; 2639 push @{$maps{$missing}}, $invlist_ref->[-1]; 2640 } 2641 } 2642 2643 # Here, we have the buckets (inversion lists) all constructed. Go 2644 # through each and verify that matches what prop_invlist() returns. 2645 # We could use is_deeply() for the comparison, but would get multiple 2646 # messages for each $prop. 2647 foreach my $map (sort keys %maps) { 2648 my @off_invlist = prop_invlist("$prop = $map"); 2649 my $min = (@off_invlist >= @{$maps{$map}}) 2650 ? @off_invlist 2651 : @{$maps{$map}}; 2652 for my $i (0 .. $min- 1) { 2653 if ($i > @off_invlist - 1) { 2654 fail("prop_invmap('$display_prop')"); 2655 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]'"); 2656 next PROPERTY; 2657 } 2658 elsif ($i > @{$maps{$map}} - 1) { 2659 fail("prop_invmap('$display_prop')"); 2660 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]'"); 2661 next PROPERTY; 2662 } 2663 elsif ($maps{$map}[$i] ne $off_invlist[$i]) { 2664 fail("prop_invmap('$display_prop')"); 2665 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]'"); 2666 next PROPERTY; 2667 } 2668 } 2669 } 2670 } 2671 else { # Don't know this property nor format. 2672 2673 fail("prop_invmap('$display_prop')"); 2674 diag("Unknown property '$display_prop' or format '$format'"); 2675 next PROPERTY; 2676 } 2677 2678 pass("prop_invmap('$display_prop')"); 2679} 2680 2681# A few tests of search_invlist 2682use Unicode::UCD qw(search_invlist); 2683 2684if ($v_unicode_version ge v3.1.0) { # No Script property before this 2685 my ($scripts_ranges_ref, $scripts_map_ref) = prop_invmap("Script"); 2686 my $index = search_invlist($scripts_ranges_ref, 0x390); 2687 is($scripts_map_ref->[$index], "Greek", "U+0390 is Greek"); 2688 my @alpha_invlist = prop_invlist("Alpha"); 2689 is(search_invlist(\@alpha_invlist, ord("\t")), undef, "search_invlist returns undef for code points before first one on the list"); 2690} 2691 2692ok($/ eq $input_record_separator, "The record separator didn't get overridden"); 2693 2694if (! ok(@warnings == 0, "No warnings were generated")) { 2695 diag(join "\n", "The warnings are:", @warnings); 2696} 2697 2698done_testing(); 2699