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