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
|
# This file tests the "binary" Tcl command.
#
# This file contains a collection of tests for one or more of the Tcl built-in
# commands. Sourcing this file into Tcl runs the tests and generates output
# for errors. No output means no errors were found.
#
# Copyright (c) 1997 by Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
#
# See the file "license.terms" for information on usage and redistribution of
# this file, and for a DISCLAIMER OF ALL WARRANTIES.
source [file dirname [info script]]/testing.tcl
needs cmd binary
if {[testConstraint jim]} {
needs cmd pack
}
constraint expr bigEndian {$tcl_platform(byteOrder) eq "bigEndian"}
constraint expr littleEndian {$tcl_platform(byteOrder) eq "littleEndian"}
testConstraint maxCompatibility 0
testConstraint notImplemented 0
# ----------------------------------------------------------------------
test binary-0.1 {DupByteArrayInternalRep} {
set hdr [binary format cc 0 0316]
set buf hellomatt
set data $hdr
append data $buf
string length $data
} 11
test binary-1.1 {Tcl_BinaryObjCmd: bad args} -body {
binary
} -returnCodes error -match glob -result {wrong # args: *}
test binary-1.2 {Tcl_BinaryObjCmd: bad args} -returnCodes error -body {
binary foo
} -match glob -result {*}
test binary-1.3 {Tcl_BinaryObjCmd: format error} -returnCodes error -body {
binary f
} -match glob -result {*}
test binary-1.4 {Tcl_BinaryObjCmd: format} -body {
binary format ""
} -result {}
test binary-2.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
binary format a
} -result {not enough arguments for all format specifiers}
test binary-2.2 {Tcl_BinaryObjCmd: format} {
binary format a0 foo
} {}
test binary-2.3 {Tcl_BinaryObjCmd: format} {
binary format a f
} {f}
test binary-2.4 {Tcl_BinaryObjCmd: format} {
binary format a foo
} {f}
test binary-2.5 {Tcl_BinaryObjCmd: format} {
binary format a3 foo
} {foo}
test binary-2.6 {Tcl_BinaryObjCmd: format} {
binary format a5 foo
} foo\x00\x00
test binary-2.7 {Tcl_BinaryObjCmd: format} {
binary format a*a3 foobarbaz blat
} foobarbazbla
test binary-2.8 {Tcl_BinaryObjCmd: format} {
binary format a*X3a2 foobar x
} foox\x00r
test binary-3.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
binary format A
} -result {not enough arguments for all format specifiers}
test binary-3.2 {Tcl_BinaryObjCmd: format} {
binary format A0 f
} {}
test binary-3.3 {Tcl_BinaryObjCmd: format} {
binary format A f
} {f}
test binary-3.4 {Tcl_BinaryObjCmd: format} {
binary format A foo
} {f}
test binary-3.5 {Tcl_BinaryObjCmd: format} {
binary format A3 foo
} {foo}
test binary-3.6 {Tcl_BinaryObjCmd: format} {
binary format A5 foo
} {foo }
test binary-3.7 {Tcl_BinaryObjCmd: format} {
binary format A*A3 foobarbaz blat
} foobarbazbla
test binary-3.8 {Tcl_BinaryObjCmd: format} {
binary format A*X3A2 foobar x
} {foox r}
test binary-4.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
binary format B
} -result {not enough arguments for all format specifiers}
test binary-4.2 {Tcl_BinaryObjCmd: format} {
binary format B0 1
} {}
test binary-4.3 {Tcl_BinaryObjCmd: format} {
binary format B 1
} \x80
test binary-4.4 {Tcl_BinaryObjCmd: format} {
binary format B* 010011
} \x4c
test binary-4.5 {Tcl_BinaryObjCmd: format} {
binary format B8 01001101
} \x4d
test binary-4.6 {Tcl_BinaryObjCmd: format} {
binary format A2X2B9 oo 01001101
} \x4d\x00
test binary-4.7 {Tcl_BinaryObjCmd: format} {
binary format B9 010011011010
} \x4d\x80
test binary-4.8 {Tcl_BinaryObjCmd: format} {
binary format B2B3 10 010
} \x80\x40
test binary-4.9 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
binary format B1B5 1 foo
} -match glob -result {expected *}
test binary-5.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
binary format b
} -result {not enough arguments for all format specifiers}
test binary-5.2 {Tcl_BinaryObjCmd: format} {
binary format b0 1
} {}
test binary-5.3 {Tcl_BinaryObjCmd: format} {
binary format b 1
} \x01
test binary-5.4 {Tcl_BinaryObjCmd: format} {
binary format b* 010011
} 2
test binary-5.5 {Tcl_BinaryObjCmd: format} {
binary format b8 01001101
} \xb2
test binary-5.6 {Tcl_BinaryObjCmd: format} {
binary format A2X2b9 oo 01001101
} \xb2\x00
test binary-5.7 {Tcl_BinaryObjCmd: format} {
binary format b9 010011011010
} \xb2\x01
test binary-5.8 {Tcl_BinaryObjCmd: format} {
binary format b17 1
} \x01\00\00
test binary-5.9 {Tcl_BinaryObjCmd: format} {
binary format b2b3 10 010
} \x01\x02
test binary-5.10 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
binary format b1b5 1 foo
} -match glob -result {expected *}
test binary-6.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
binary format h
} -result {not enough arguments for all format specifiers}
test binary-6.2 {Tcl_BinaryObjCmd: format} {
binary format h0 1
} {}
test binary-6.3 {Tcl_BinaryObjCmd: format} {
binary format h 1
} \x01
test binary-6.4 {Tcl_BinaryObjCmd: format} {
binary format h c
} \x0c
test binary-6.5 {Tcl_BinaryObjCmd: format} {
binary format h* baadf00d
} \xab\xda\x0f\xd0
test binary-6.6 {Tcl_BinaryObjCmd: format} {
binary format h4 c410
} \x4c\x01
test binary-6.7 {Tcl_BinaryObjCmd: format} {
binary format h6 c4102
} \x4c\x01\x02
test binary-6.8 {Tcl_BinaryObjCmd: format} {
binary format h5 c41020304
} \x4c\x01\x02
test binary-6.9 {Tcl_BinaryObjCmd: format} {
binary format a3X3h5 foo 2
} \x02\x00\x00
test binary-6.10 {Tcl_BinaryObjCmd: format} {
binary format h2h3 23 456
} \x32\x54\x06
test binary-6.11 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
binary format h2 foo
} -match glob -result {expected *}
test binary-7.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
binary format H
} -result {not enough arguments for all format specifiers}
test binary-7.2 {Tcl_BinaryObjCmd: format} {
binary format H0 1
} {}
test binary-7.3 {Tcl_BinaryObjCmd: format} {
binary format H 1
} \x10
test binary-7.4 {Tcl_BinaryObjCmd: format} {
binary format H c
} \xc0
test binary-7.5 {Tcl_BinaryObjCmd: format} {
binary format H* baadf00d
} \xba\xad\xf0\x0d
test binary-7.6 {Tcl_BinaryObjCmd: format} {
binary format H4 c410
} \xc4\x10
test binary-7.7 {Tcl_BinaryObjCmd: format} {
binary format H6 c4102
} \xc4\x10\x20
test binary-7.8 {Tcl_BinaryObjCmd: format} {
binary format H5 c41023304
} \xc4\x10\x20
test binary-7.9 {Tcl_BinaryObjCmd: format} {
binary format a3X3H5 foo 2
} \x20\x00\x00
test binary-7.10 {Tcl_BinaryObjCmd: format} {
binary format H2H3 23 456
} \x23\x45\x60
test binary-7.11 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
binary format H2 foo
} -match glob -result {expected *}
test binary-8.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
binary format c
} -result {not enough arguments for all format specifiers}
test binary-8.2 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
binary format c blat
} -match glob -result {expected *}
test binary-8.3 {Tcl_BinaryObjCmd: format} {
binary format c0 0x50
} {}
test binary-8.4 {Tcl_BinaryObjCmd: format} {
binary format c 0x50
} P
test binary-8.5 {Tcl_BinaryObjCmd: format} {
binary format c 0x5052
} R
test binary-8.6 {Tcl_BinaryObjCmd: format} {
binary format c2 {0x50 0x52}
} PR
test binary-8.7 {Tcl_BinaryObjCmd: format} {
binary format c2 {0x50 0x52 0x53}
} PR
test binary-8.8 {Tcl_BinaryObjCmd: format} {
binary format c* {0x50 0x52}
} PR
test binary-8.9 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
binary format c2 {0x50}
} -result {number of elements in list does not match count}
test binary-8.10 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
set a {0x50 0x51}
binary format c $a
} -match glob -result "expected integer *but got \"0x50 0x51\""
test binary-8.11 {Tcl_BinaryObjCmd: format} {
set a {0x50 0x51}
binary format c1 $a
} P
test binary-9.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
binary format s
} -result {not enough arguments for all format specifiers}
test binary-9.2 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
binary format s blat
} -match glob -result {expected integer *but got "blat"}
test binary-9.3 {Tcl_BinaryObjCmd: format} {
binary format s0 0x50
} {}
test binary-9.4 {Tcl_BinaryObjCmd: format} {
binary format s 0x50
} P\x00
test binary-9.5 {Tcl_BinaryObjCmd: format} {
binary format s 0x5052
} RP
test binary-9.6 {Tcl_BinaryObjCmd: format} {
binary format s 0x505251 0x53
} QR
test binary-9.7 {Tcl_BinaryObjCmd: format} {
binary format s2 {0x50 0x52}
} P\x00R\x00
test binary-9.8 {Tcl_BinaryObjCmd: format} {
binary format s* {0x5051 0x52}
} QPR\x00
test binary-9.9 {Tcl_BinaryObjCmd: format} {
binary format s2 {0x50 0x52 0x53} 0x54
} P\x00R\x00
test binary-9.10 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
binary format s2 {0x50}
} -result {number of elements in list does not match count}
test binary-9.11 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
set a {0x50 0x51}
binary format s $a
} -match glob -result "expected integer *but got \"0x50 0x51\""
test binary-9.12 {Tcl_BinaryObjCmd: format} {
set a {0x50 0x51}
binary format s1 $a
} P\x00
test binary-10.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
binary format S
} -result {not enough arguments for all format specifiers}
test binary-10.2 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
binary format S blat
} -match glob -result {expected integer *but got "blat"}
test binary-10.3 {Tcl_BinaryObjCmd: format} {
binary format S0 0x50
} {}
test binary-10.4 {Tcl_BinaryObjCmd: format} {
binary format S 0x50
} \x00P
test binary-10.5 {Tcl_BinaryObjCmd: format} {
binary format S 0x5052
} PR
test binary-10.6 {Tcl_BinaryObjCmd: format} {
binary format S 0x505251 0x53
} RQ
test binary-10.7 {Tcl_BinaryObjCmd: format} {
binary format S2 {0x50 0x52}
} \x00P\x00R
test binary-10.8 {Tcl_BinaryObjCmd: format} {
binary format S* {0x5051 0x52}
} PQ\x00R
test binary-10.9 {Tcl_BinaryObjCmd: format} {
binary format S2 {0x50 0x52 0x53} 0x54
} \x00P\x00R
test binary-10.10 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
binary format S2 {0x50}
} -result {number of elements in list does not match count}
test binary-10.11 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
set a {0x50 0x51}
binary format S $a
} -match glob -result "expected integer *but got \"0x50 0x51\""
test binary-10.12 {Tcl_BinaryObjCmd: format} {
set a {0x50 0x51}
binary format S1 $a
} \x00P
test binary-11.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
binary format i
} -result {not enough arguments for all format specifiers}
test binary-11.2 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
binary format i blat
} -match glob -result {expected integer *but got "blat"}
test binary-11.3 {Tcl_BinaryObjCmd: format} {
binary format i0 0x50
} {}
test binary-11.4 {Tcl_BinaryObjCmd: format} {
binary format i 0x50
} P\x00\x00\x00
test binary-11.5 {Tcl_BinaryObjCmd: format} {
binary format i 0x5052
} RP\x00\x00
test binary-11.6 {Tcl_BinaryObjCmd: format} {
binary format i 0x505251 0x53
} QRP\x00
test binary-11.7 {Tcl_BinaryObjCmd: format} {
binary format i1 {0x505251 0x53}
} QRP\x00
test binary-11.8 {Tcl_BinaryObjCmd: format} {
binary format i 0x53525150
} PQRS
test binary-11.9 {Tcl_BinaryObjCmd: format} {
binary format i2 {0x50 0x52}
} P\x00\x00\x00R\x00\x00\x00
test binary-11.10 {Tcl_BinaryObjCmd: format} {
binary format i* {0x50515253 0x52}
} SRQPR\x00\x00\x00
test binary-11.11 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
binary format i2 {0x50}
} -result {number of elements in list does not match count}
test binary-11.12 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
set a {0x50 0x51}
binary format i $a
} -match glob -result "expected integer *but got \"0x50 0x51\""
test binary-11.13 {Tcl_BinaryObjCmd: format} {
set a {0x50 0x51}
binary format i1 $a
} P\x00\x00\x00
test binary-12.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
binary format I
} -result {not enough arguments for all format specifiers}
test binary-12.2 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
binary format I blat
} -match glob -result {expected integer *but got "blat"}
test binary-12.3 {Tcl_BinaryObjCmd: format} {
binary format I0 0x50
} {}
test binary-12.4 {Tcl_BinaryObjCmd: format} {
binary format I 0x50
} \x00\x00\x00P
test binary-12.5 {Tcl_BinaryObjCmd: format} {
binary format I 0x5052
} \x00\x00PR
test binary-12.6 {Tcl_BinaryObjCmd: format} {
binary format I 0x505251 0x53
} \x00PRQ
test binary-12.7 {Tcl_BinaryObjCmd: format} {
binary format I1 {0x505251 0x53}
} \x00PRQ
test binary-12.8 {Tcl_BinaryObjCmd: format} {
binary format I 0x53525150
} SRQP
test binary-12.9 {Tcl_BinaryObjCmd: format} {
binary format I2 {0x50 0x52}
} \x00\x00\x00P\x00\x00\x00R
test binary-12.10 {Tcl_BinaryObjCmd: format} {
binary format I* {0x50515253 0x52}
} PQRS\x00\x00\x00R
test binary-12.11 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
binary format i2 {0x50}
} -result {number of elements in list does not match count}
test binary-12.12 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
set a {0x50 0x51}
binary format I $a
} -match glob -result "expected integer *but got \"0x50 0x51\""
test binary-12.13 {Tcl_BinaryObjCmd: format} {
set a {0x50 0x51}
binary format I1 $a
} \x00\x00\x00P
test binary-13.1 {Tcl_BinaryObjCmd: format} {
list [catch {binary format f} msg] $msg
} {1 {not enough arguments for all format specifiers}}
test binary-13.2 {Tcl_BinaryObjCmd: format} {
list [catch {binary format f blat} msg] $msg
} {1 {expected floating-point number but got "blat"}}
test binary-13.3 {Tcl_BinaryObjCmd: format} {
binary format f0 1.6
} {}
test binary-13.4 {Tcl_BinaryObjCmd: format} bigEndian {
binary format f 1.6
} \x3f\xcc\xcc\xcd
test binary-13.5 {Tcl_BinaryObjCmd: format} littleEndian {
binary format f 1.6
} \xcd\xcc\xcc\x3f
test binary-13.6 {Tcl_BinaryObjCmd: format} bigEndian {
binary format f* {1.6 3.4}
} \x3f\xcc\xcc\xcd\x40\x59\x99\x9a
test binary-13.7 {Tcl_BinaryObjCmd: format} littleEndian {
binary format f* {1.6 3.4}
} \xcd\xcc\xcc\x3f\x9a\x99\x59\x40
test binary-13.8 {Tcl_BinaryObjCmd: format} bigEndian {
binary format f2 {1.6 3.4}
} \x3f\xcc\xcc\xcd\x40\x59\x99\x9a
test binary-13.9 {Tcl_BinaryObjCmd: format} littleEndian {
binary format f2 {1.6 3.4}
} \xcd\xcc\xcc\x3f\x9a\x99\x59\x40
test binary-13.10 {Tcl_BinaryObjCmd: format} bigEndian {
binary format f2 {1.6 3.4 5.6}
} \x3f\xcc\xcc\xcd\x40\x59\x99\x9a
test binary-13.11 {Tcl_BinaryObjCmd: format} littleEndian {
binary format f2 {1.6 3.4 5.6}
} \xcd\xcc\xcc\x3f\x9a\x99\x59\x40
test binary-13.12 {Tcl_BinaryObjCmd: float overflow} {bigEndian maxCompatibility} {
binary format f -3.402825e+38
} \xff\x7f\xff\xff
test binary-13.13 {Tcl_BinaryObjCmd: float overflow} {littleEndian maxCompatibility} {
binary format f -3.402825e+38
} \xff\xff\x7f\xff
test binary-13.14 {Tcl_BinaryObjCmd: float underflow} bigEndian {
binary format f -3.402825e-100
} \x80\x00\x00\x00
test binary-13.15 {Tcl_BinaryObjCmd: float underflow} littleEndian {
binary format f -3.402825e-100
} \x00\x00\x00\x80
test binary-13.16 {Tcl_BinaryObjCmd: format} {
list [catch {binary format f2 {1.6}} msg] $msg
} {1 {number of elements in list does not match count}}
test binary-13.17 {Tcl_BinaryObjCmd: format} {
set a {1.6 3.4}
list [catch {binary format f $a} msg] $msg
} [list 1 "expected floating-point number but got \"1.6 3.4\""]
test binary-13.18 {Tcl_BinaryObjCmd: format} bigEndian {
set a {1.6 3.4}
binary format f1 $a
} \x3f\xcc\xcc\xcd
test binary-13.19 {Tcl_BinaryObjCmd: format} littleEndian {
set a {1.6 3.4}
binary format f1 $a
} \xcd\xcc\xcc\x3f
test binary-14.1 {Tcl_BinaryObjCmd: format} {
list [catch {binary format d} msg] $msg
} {1 {not enough arguments for all format specifiers}}
test binary-14.2 {Tcl_BinaryObjCmd: format} {
list [catch {binary format d blat} msg] $msg
} {1 {expected floating-point number but got "blat"}}
test binary-14.3 {Tcl_BinaryObjCmd: format} {
binary format d0 1.6
} {}
test binary-14.4 {Tcl_BinaryObjCmd: format} bigEndian {
binary format d 1.6
} \x3f\xf9\x99\x99\x99\x99\x99\x9a
test binary-14.5 {Tcl_BinaryObjCmd: format} littleEndian {
binary format d 1.6
} \x9a\x99\x99\x99\x99\x99\xf9\x3f
test binary-14.6 {Tcl_BinaryObjCmd: format} bigEndian {
binary format d* {1.6 3.4}
} \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33
test binary-14.7 {Tcl_BinaryObjCmd: format} littleEndian {
binary format d* {1.6 3.4}
} \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40
test binary-14.8 {Tcl_BinaryObjCmd: format} bigEndian {
binary format d2 {1.6 3.4}
} \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33
test binary-14.9 {Tcl_BinaryObjCmd: format} littleEndian {
binary format d2 {1.6 3.4}
} \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40
test binary-14.10 {Tcl_BinaryObjCmd: format} bigEndian {
binary format d2 {1.6 3.4 5.6}
} \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33
test binary-14.11 {Tcl_BinaryObjCmd: format} littleEndian {
binary format d2 {1.6 3.4 5.6}
} \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40
test binary-14.14 {Tcl_BinaryObjCmd: format} {
list [catch {binary format d2 {1.6}} msg] $msg
} {1 {number of elements in list does not match count}}
test binary-14.15 {Tcl_BinaryObjCmd: format} {
set a {1.6 3.4}
list [catch {binary format d $a} msg] $msg
} [list 1 "expected floating-point number but got \"1.6 3.4\""]
test binary-14.16 {Tcl_BinaryObjCmd: format} bigEndian {
set a {1.6 3.4}
binary format d1 $a
} \x3f\xf9\x99\x99\x99\x99\x99\x9a
test binary-14.17 {Tcl_BinaryObjCmd: format} littleEndian {
set a {1.6 3.4}
binary format d1 $a
} \x9a\x99\x99\x99\x99\x99\xf9\x3f
test binary-14.18 {FormatNumber: Bug 1116542} {
binary scan [binary format d 1.25] d w
set w
} 1.25
test binary-15.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
binary format ax*a "y" "z"
} -result {cannot use "*" in format string with "x"}
test binary-15.2 {Tcl_BinaryObjCmd: format} {
binary format axa "y" "z"
} y\x00z
test binary-15.3 {Tcl_BinaryObjCmd: format} {
binary format ax3a "y" "z"
} y\x00\x00\x00z
test binary-15.4 {Tcl_BinaryObjCmd: format} {
binary format a*X3x3a* "foo" "z"
} \x00\x00\x00z
test binary-15.5 {Tcl_BinaryObjCmd: format - bug #1923966} {
binary format x0s 1
} \x01\x00
test binary-15.6 {Tcl_BinaryObjCmd: format - bug #1923966} {
binary format x0ss 1 1
} \x01\x00\x01\x00
test binary-15.7 {Tcl_BinaryObjCmd: format - bug #1923966} {
binary format x1s 1
} \x00\x01\x00
test binary-15.8 {Tcl_BinaryObjCmd: format - bug #1923966} {
binary format x1ss 1 1
} \x00\x01\x00\x01\x00
test binary-16.1 {Tcl_BinaryObjCmd: format} {
binary format a*X*a "foo" "z"
} zoo
test binary-16.2 {Tcl_BinaryObjCmd: format} {
binary format aX3a "y" "z"
} z
test binary-16.3 {Tcl_BinaryObjCmd: format} {
binary format a*Xa* "foo" "zy"
} fozy
test binary-16.4 {Tcl_BinaryObjCmd: format} {
binary format a*X3a "foobar" "z"
} foozar
test binary-16.5 {Tcl_BinaryObjCmd: format} {
binary format a*X3aX2a "foobar" "z" "b"
} fobzar
test binary-17.1 {Tcl_BinaryObjCmd: format} {
binary format @1
} \x00
test binary-17.2 {Tcl_BinaryObjCmd: format} {
binary format @5a2 "ab"
} \x00\x00\x00\x00\x00\x61\x62
test binary-17.3 {Tcl_BinaryObjCmd: format} {
binary format {a* @0 a2 @* a*} "foobar" "ab" "blat"
} abobarblat
test binary-18.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
binary format u0a3 abc abd
} -result {bad field specifier "u"}
test binary-19.1 {Tcl_BinaryObjCmd: errors} -returnCodes error -body {
binary s
} -match glob -result {*}
test binary-19.2 {Tcl_BinaryObjCmd: errors} -returnCodes error -body {
binary scan foo
} -result {wrong # args: should be "binary scan value formatString ?varName ...?"}
test binary-19.3 {Tcl_BinaryObjCmd: scan} {
binary scan {} {}
} 0
test binary-20.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
binary scan abc a
} -result {not enough arguments for all format specifiers}
test binary-20.2 {Tcl_BinaryObjCmd: scan} -setup {
unset -nocomplain arg1
} -returnCodes error -body {
set arg1 1
binary scan abc a arg1(a)
} -result {can't set "arg1(a)": variable isn't array}
test binary-20.3 {Tcl_BinaryObjCmd: scan} -setup {
unset -nocomplain arg1
} -body {
set arg1 abc
list [binary scan abc a0 arg1] $arg1
} -result {1 {}}
test binary-20.4 {Tcl_BinaryObjCmd: scan} -setup {
unset -nocomplain arg1
} -body {
list [binary scan abc a* arg1] $arg1
} -result {1 abc}
test binary-20.5 {Tcl_BinaryObjCmd: scan} -setup {
unset -nocomplain arg1
} -body {
list [binary scan abc a5 arg1] [info exists arg1]
} -result {0 0}
test binary-20.6 {Tcl_BinaryObjCmd: scan} {
set arg1 foo
list [binary scan abc a2 arg1] $arg1
} {1 ab}
test binary-20.7 {Tcl_BinaryObjCmd: scan} -setup {
unset -nocomplain arg1
unset -nocomplain arg2
} -body {
list [binary scan abcdef a2a2 arg1 arg2] $arg1 $arg2
} -result {2 ab cd}
test binary-20.8 {Tcl_BinaryObjCmd: scan} -setup {
unset -nocomplain arg1
} -body {
list [binary scan abc a2 arg1(a)] $arg1(a)
} -result {1 ab}
test binary-20.9 {Tcl_BinaryObjCmd: scan} -setup {
unset -nocomplain arg1
} -body {
list [binary scan abc a arg1(a)] $arg1(a)
} -result {1 a}
# As soon as a conversion runs out of bytes, scan should stop
test binary-20.10 {Tcl_BinaryObjCmd: scan, too few bytes} -setup {
unset -nocomplain arg1 arg2
} -body {
list [binary scan abc a5a2 arg1 arg2] [info exists arg1] [info exists arg2]
} -result {0 0 0}
test binary-21.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
binary scan abc A
} -result {not enough arguments for all format specifiers}
test binary-21.2 {Tcl_BinaryObjCmd: scan} -setup {
unset -nocomplain arg1
} -returnCodes error -body {
set arg1 1
binary scan abc A arg1(a)
} -result {can't set "arg1(a)": variable isn't array}
test binary-21.3 {Tcl_BinaryObjCmd: scan} -setup {
unset -nocomplain arg1
} -body {
set arg1 abc
list [binary scan abc A0 arg1] $arg1
} -result {1 {}}
test binary-21.4 {Tcl_BinaryObjCmd: scan} -setup {
unset -nocomplain arg1
} -body {
list [binary scan abc A* arg1] $arg1
} -result {1 abc}
test binary-21.5 {Tcl_BinaryObjCmd: scan} -setup {
unset -nocomplain arg1
} -body {
list [binary scan abc A5 arg1] [info exists arg1]
} -result {0 0}
test binary-21.6 {Tcl_BinaryObjCmd: scan} {
set arg1 foo
list [binary scan abc A2 arg1] $arg1
} {1 ab}
test binary-21.7 {Tcl_BinaryObjCmd: scan} -setup {
unset -nocomplain arg1
unset -nocomplain arg2
} -body {
list [binary scan abcdef A2A2 arg1 arg2] $arg1 $arg2
} -result {2 ab cd}
test binary-21.8 {Tcl_BinaryObjCmd: scan} -setup {
unset -nocomplain arg1
} -body {
list [binary scan abc A2 arg1(a)] $arg1(a)
} -result {1 ab}
test binary-21.9 {Tcl_BinaryObjCmd: scan} -setup {
unset -nocomplain arg1
} -body {
list [binary scan abc A2 arg1(a)] $arg1(a)
} -result {1 ab}
test binary-21.10 {Tcl_BinaryObjCmd: scan} -setup {
unset -nocomplain arg1
} -body {
list [binary scan abc A arg1(a)] $arg1(a)
} -result {1 a}
test binary-21.11 {Tcl_BinaryObjCmd: scan} -setup {
unset -nocomplain arg1
} -body {
list [binary scan "abc def \x00 " A* arg1] $arg1
} -result {1 {abc def}}
test binary-21.12 {Tcl_BinaryObjCmd: scan} -setup {
unset -nocomplain arg1
} -body {
list [binary scan "abc def \x00ghi " A* arg1] $arg1
} -result [list 1 "abc def \x00ghi"]
test binary-22.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
binary scan abc b
} -result {not enough arguments for all format specifiers}
test binary-22.2 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\x53 b* arg1] $arg1
} {1 0100101011001010}
test binary-22.3 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x82\x53 b arg1] $arg1
} {1 0}
test binary-22.4 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x82\x53 b1 arg1] $arg1
} {1 0}
test binary-22.5 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x82\x53 b0 arg1] $arg1
} {1 {}}
test binary-22.6 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\x53 b5 arg1] $arg1
} {1 01001}
test binary-22.7 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\x53 b8 arg1] $arg1
} {1 01001010}
test binary-22.8 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\x53 b14 arg1] $arg1
} {1 01001010110010}
test binary-22.9 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
set arg1 foo
list [binary scan \x52 b14 arg1] $arg1
} {0 foo}
test binary-22.10 {Tcl_BinaryObjCmd: scan} -setup {
unset -nocomplain arg1
} -returnCodes error -body {
set arg1 1
binary scan \x52\x53 b1 arg1(a)
} -result {can't set "arg1(a)": variable isn't array}
test binary-22.11 {Tcl_BinaryObjCmd: scan} -setup {
unset -nocomplain arg1 arg2
} -body {
set arg1 foo
set arg2 bar
list [binary scan \x07\x87\x05 b5b* arg1 arg2] $arg1 $arg2
} -result {2 11100 1110000110100000}
# As soon as a conversion runs out of bytes, scan should stop
test binary-20.12 {Tcl_BinaryObjCmd: scan, too few bytes} {
unset -nocomplain arg1 arg2
set arg1 foo
set arg2 bar
list [binary scan \x52 b14b8 arg1 arg2] $arg1 $arg2
} {0 foo bar}
test binary-23.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
binary scan abc B
} -result {not enough arguments for all format specifiers}
test binary-23.2 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\x53 B* arg1] $arg1
} {1 0101001001010011}
test binary-23.3 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x82\x53 B arg1] $arg1
} {1 1}
test binary-23.4 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x82\x53 B1 arg1] $arg1
} {1 1}
test binary-23.5 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\x53 B0 arg1] $arg1
} {1 {}}
test binary-23.6 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\x53 B5 arg1] $arg1
} {1 01010}
test binary-23.7 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\x53 B8 arg1] $arg1
} {1 01010010}
test binary-23.8 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\x53 B14 arg1] $arg1
} {1 01010010010100}
test binary-23.9 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
set arg1 foo
list [binary scan \x52 B14 arg1] $arg1
} {0 foo}
test binary-23.10 {Tcl_BinaryObjCmd: scan} -setup {
unset -nocomplain arg1
} -returnCodes error -body {
set arg1 1
binary scan \x52\x53 B1 arg1(a)
} -result {can't set "arg1(a)": variable isn't array}
test binary-23.11 {Tcl_BinaryObjCmd: scan} -setup {
unset -nocomplain arg1 arg2
} -body {
set arg1 foo
set arg2 bar
list [binary scan \x70\x87\x05 B5B* arg1 arg2] $arg1 $arg2
} -result {2 01110 1000011100000101}
test binary-24.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
binary scan abc h
} -result {not enough arguments for all format specifiers}
test binary-24.2 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\xa3 h* arg1] $arg1
} {1 253a}
test binary-24.3 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \xc2\xa3 h arg1] $arg1
} {1 2}
test binary-24.4 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x82\x53 h1 arg1] $arg1
} {1 2}
test binary-24.5 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\x53 h0 arg1] $arg1
} {1 {}}
test binary-24.6 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \xf2\x53 h2 arg1] $arg1
} {1 2f}
test binary-24.7 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\x53 h3 arg1] $arg1
} {1 253}
test binary-24.8 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
set arg1 foo
list [binary scan \x52 h3 arg1] $arg1
} {0 foo}
test binary-24.9 {Tcl_BinaryObjCmd: scan} -setup {
unset -nocomplain arg1
} -returnCodes error -body {
set arg1 1
binary scan \x52\x53 h1 arg1(a)
} -result {can't set "arg1(a)": variable isn't array}
test binary-24.10 {Tcl_BinaryObjCmd: scan} -setup {
unset -nocomplain arg1 arg2
} -body {
set arg1 foo
set arg2 bar
list [binary scan \x70\x87\x05 h2h* arg1 arg2] $arg1 $arg2
} -result {2 07 7850}
test binary-25.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
binary scan abc H
} -result {not enough arguments for all format specifiers}
test binary-25.2 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\xa3 H* arg1] $arg1
} {1 52a3}
test binary-25.3 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \xc2\xa3 H arg1] $arg1
} {1 c}
test binary-25.4 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x82\x53 H1 arg1] $arg1
} {1 8}
test binary-25.5 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\x53 H0 arg1] $arg1
} {1 {}}
test binary-25.6 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \xf2\x53 H2 arg1] $arg1
} {1 f2}
test binary-25.7 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\x53 H3 arg1] $arg1
} {1 525}
test binary-25.8 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
set arg1 foo
list [binary scan \x52 H3 arg1] $arg1
} {0 foo}
test binary-25.9 {Tcl_BinaryObjCmd: scan} -setup {
unset -nocomplain arg1
} -returnCodes error -body {
set arg1 1
binary scan \x52\x53 H1 arg1(a)
} -result {can't set "arg1(a)": variable isn't array}
test binary-25.10 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1 arg2
set arg1 foo
set arg2 bar
list [binary scan \x70\x87\x05 H2H* arg1 arg2] $arg1 $arg2
} {2 70 8705}
test binary-26.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
binary scan abc c
} -result {not enough arguments for all format specifiers}
test binary-26.2 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\xa3 c* arg1] $arg1
} {1 {82 -93}}
test binary-26.3 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\xa3 c arg1] $arg1
} {1 82}
test binary-26.4 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\xa3 c1 arg1] $arg1
} {1 82}
test binary-26.5 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\xa3 c0 arg1] $arg1
} {1 {}}
test binary-26.6 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\xa3 c2 arg1] $arg1
} {1 {82 -93}}
test binary-26.7 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \xff c arg1] $arg1
} {1 -1}
test binary-26.8 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
set arg1 foo
list [binary scan \x52 c3 arg1] $arg1
} {0 foo}
test binary-26.9 {Tcl_BinaryObjCmd: scan} -setup {
unset -nocomplain arg1
} -returnCodes error -body {
set arg1 1
binary scan \x52\x53 c1 arg1(a)
} -result {can't set "arg1(a)": variable isn't array}
test binary-26.10 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1 arg2
set arg1 foo
set arg2 bar
list [binary scan \x70\x87\x05 c2c* arg1 arg2] $arg1 $arg2
} {2 {112 -121} 5}
test binary-26.11 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\xa3 cu* arg1] $arg1
} {1 {82 163}}
test binary-26.12 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\xa3 cu arg1] $arg1
} {1 82}
test binary-26.13 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \xff cu arg1] $arg1
} {1 255}
test binary-26.14 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1 arg2
set arg1 foo
set arg2 bar
list [binary scan \x80\x80 cuc arg1 arg2] $arg1 $arg2
} {2 128 -128}
test binary-26.15 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1 arg2
set arg1 foo
set arg2 bar
list [binary scan \x80\x80 ccu arg1 arg2] $arg1 $arg2
} {2 -128 128}
test binary-27.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
binary scan abc s
} -result {not enough arguments for all format specifiers}
test binary-27.2 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\xa3\x53\x54 s* arg1] $arg1
} {1 {-23726 21587}}
test binary-27.3 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\xa3\x53\x54 s arg1] $arg1
} {1 -23726}
test binary-27.4 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\xa3 s1 arg1] $arg1
} {1 -23726}
test binary-27.5 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\xa3 s0 arg1] $arg1
} {1 {}}
test binary-27.6 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\xa3\x53\x54 s2 arg1] $arg1
} {1 {-23726 21587}}
test binary-27.7 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
set arg1 foo
list [binary scan \x52 s1 arg1] $arg1
} {0 foo}
test binary-27.8 {Tcl_BinaryObjCmd: scan} -setup {
unset -nocomplain arg1
} -returnCodes error -body {
set arg1 1
binary scan \x52\x53 s1 arg1(a)
} -result {can't set "arg1(a)": variable isn't array}
test binary-27.9 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1 arg2
set arg1 foo
set arg2 bar
list [binary scan \x52\xa3\x53\x54\x05 s2c* arg1 arg2] $arg1 $arg2
} {2 {-23726 21587} 5}
test binary-27.10 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\xa3\x53\x54 su* arg1] $arg1
} {1 {41810 21587}}
test binary-27.11 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1 arg2
set arg1 foo
set arg2 bar
list [binary scan \xff\xff\xff\xff sus arg1 arg2] $arg1 $arg2
} {2 65535 -1}
test binary-27.12 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1 arg2
set arg1 foo
set arg2 bar
list [binary scan \xff\xff\xff\xff ssu arg1 arg2] $arg1 $arg2
} {2 -1 65535}
test binary-28.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
binary scan abc S
} -result {not enough arguments for all format specifiers}
test binary-28.2 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\xa3\x53\x54 S* arg1] $arg1
} {1 {21155 21332}}
test binary-28.3 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\xa3\x53\x54 S arg1] $arg1
} {1 21155}
test binary-28.4 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\xa3 S1 arg1] $arg1
} {1 21155}
test binary-28.5 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\xa3 S0 arg1] $arg1
} {1 {}}
test binary-28.6 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\xa3\x53\x54 S2 arg1] $arg1
} {1 {21155 21332}}
test binary-28.7 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
set arg1 foo
list [binary scan \x52 S1 arg1] $arg1
} {0 foo}
test binary-28.8 {Tcl_BinaryObjCmd: scan} -setup {
unset -nocomplain arg1
} -returnCodes error -body {
set arg1 1
binary scan \x52\x53 S1 arg1(a)
} -result {can't set "arg1(a)": variable isn't array}
test binary-28.9 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1 arg2
set arg1 foo
set arg2 bar
list [binary scan \x52\xa3\x53\x54\x05 S2c* arg1 arg2] $arg1 $arg2
} {2 {21155 21332} 5}
test binary-28.10 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\xa3\x53\x54 Su* arg1] $arg1
} {1 {21155 21332}}
test binary-28.11 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \xa3\x52\x54\x53 Su* arg1] $arg1
} {1 {41810 21587}}
test binary-29.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
binary scan abc i
} -result {not enough arguments for all format specifiers}
test binary-29.2 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 i* arg1] $arg1
} {1 {1414767442 67305985}}
test binary-29.3 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 i arg1] $arg1
} {1 1414767442}
test binary-29.4 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\xa3\x53\x54 i1 arg1] $arg1
} {1 1414767442}
test binary-29.5 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\xa3\x53 i0 arg1] $arg1
} {1 {}}
test binary-29.6 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 i2 arg1] $arg1
} {1 {1414767442 67305985}}
test binary-29.7 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
set arg1 foo
list [binary scan \x52 i1 arg1] $arg1
} {0 foo}
test binary-29.8 {Tcl_BinaryObjCmd: scan} -setup {
unset -nocomplain arg1
} -returnCodes error -body {
set arg1 1
binary scan \x52\x53\x53\x54 i1 arg1(a)
} -result {can't set "arg1(a)": variable isn't array}
test binary-29.9 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1 arg2
set arg1 foo
set arg2 bar
list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04\x05 i2c* arg1 arg2] $arg1 $arg2
} {2 {1414767442 67305985} 5}
test binary-29.10 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1 arg2
list [binary scan \xff\xff\xff\xff\xff\xff\xff\xff iui arg1 arg2] $arg1 $arg2
} {2 4294967295 -1}
test binary-29.11 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1 arg2
list [binary scan \xff\xff\xff\xff\xff\xff\xff\xff iiu arg1 arg2] $arg1 $arg2
} {2 -1 4294967295}
test binary-29.12 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1 arg2
list [binary scan \x80\x00\x00\x00\x00\x00\x00\x80 iuiu arg1 arg2] $arg1 $arg2
} {2 128 2147483648}
test binary-30.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
binary scan abc I
} -result {not enough arguments for all format specifiers}
test binary-30.2 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 I* arg1] $arg1
} {1 {1386435412 16909060}}
test binary-30.3 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 I arg1] $arg1
} {1 1386435412}
test binary-30.4 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\xa3\x53\x54 I1 arg1] $arg1
} {1 1386435412}
test binary-30.5 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\xa3\x53 I0 arg1] $arg1
} {1 {}}
test binary-30.6 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 I2 arg1] $arg1
} {1 {1386435412 16909060}}
test binary-30.7 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
set arg1 foo
list [binary scan \x52 I1 arg1] $arg1
} {0 foo}
test binary-30.8 {Tcl_BinaryObjCmd: scan} -setup {
unset -nocomplain arg1
} -returnCodes error -body {
set arg1 1
binary scan \x52\x53\x53\x54 I1 arg1(a)
} -result {can't set "arg1(a)": variable isn't array}
test binary-30.9 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1 arg2
set arg1 foo
set arg2 bar
list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04\x05 I2c* arg1 arg2] $arg1 $arg2
} {2 {1386435412 16909060} 5}
test binary-30.10 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1 arg2
list [binary scan \xff\xff\xff\xff\xff\xff\xff\xff IuI arg1 arg2] $arg1 $arg2
} {2 4294967295 -1}
test binary-30.11 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1 arg2
list [binary scan \xff\xff\xff\xff\xff\xff\xff\xff IIu arg1 arg2] $arg1 $arg2
} {2 -1 4294967295}
test binary-30.12 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1 arg2
list [binary scan \x80\x00\x00\x00\x00\x00\x00\x80 IuIu arg1 arg2] $arg1 $arg2
} {2 2147483648 128}
test binary-31.1 {Tcl_BinaryObjCmd: scan} {
list [catch {binary scan abc f} msg] $msg
} {1 {not enough arguments for all format specifiers}}
# NB: format %.12g in Jim_DoubleToString
# tests fixed: 31.2/3, 31.4/5, 31.6/7, 31.10/11, 31.14/15, 41.5/6, 59.2-7, 59.11-15
test binary-31.2 {Tcl_BinaryObjCmd: scan} bigEndian {
catch {unset arg1}
list [binary scan \x3f\xcc\xcc\xcd\x40\x59\x99\x9a f* arg1] $arg1
} {1 {1.60000002384 3.40000009537}}
test binary-31.3 {Tcl_BinaryObjCmd: scan} littleEndian {
catch {unset arg1}
list [binary scan \xcd\xcc\xcc\x3f\x9a\x99\x59\x40 f* arg1] $arg1
} {1 {1.60000002384 3.40000009537}}
test binary-31.4 {Tcl_BinaryObjCmd: scan} bigEndian {
catch {unset arg1}
list [binary scan \x3f\xcc\xcc\xcd\x40\x59\x99\x9a f arg1] $arg1
} {1 1.60000002384}
test binary-31.5 {Tcl_BinaryObjCmd: scan} littleEndian {
catch {unset arg1}
list [binary scan \xcd\xcc\xcc\x3f\x9a\x99\x59\x40 f arg1] $arg1
} {1 1.60000002384}
test binary-31.6 {Tcl_BinaryObjCmd: scan} bigEndian {
catch {unset arg1}
list [binary scan \x3f\xcc\xcc\xcd f1 arg1] $arg1
} {1 1.60000002384}
test binary-31.7 {Tcl_BinaryObjCmd: scan} littleEndian {
catch {unset arg1}
list [binary scan \xcd\xcc\xcc\x3f f1 arg1] $arg1
} {1 1.60000002384}
test binary-31.8 {Tcl_BinaryObjCmd: scan} bigEndian {
catch {unset arg1}
list [binary scan \x3f\xcc\xcc\xcd f0 arg1] $arg1
} {1 {}}
test binary-31.9 {Tcl_BinaryObjCmd: scan} littleEndian {
catch {unset arg1}
list [binary scan \xcd\xcc\xcc\x3f f0 arg1] $arg1
} {1 {}}
test binary-31.10 {Tcl_BinaryObjCmd: scan} bigEndian {
catch {unset arg1}
list [binary scan \x3f\xcc\xcc\xcd\x40\x59\x99\x9a f2 arg1] $arg1
} {1 {1.60000002384 3.40000009537}}
test binary-31.11 {Tcl_BinaryObjCmd: scan} littleEndian {
catch {unset arg1}
list [binary scan \xcd\xcc\xcc\x3f\x9a\x99\x59\x40 f2 arg1] $arg1
} {1 {1.60000002384 3.40000009537}}
test binary-31.12 {Tcl_BinaryObjCmd: scan} {
catch {unset arg1}
set arg1 foo
list [binary scan \x52 f1 arg1] $arg1
} {0 foo}
test binary-31.13 {Tcl_BinaryObjCmd: scan} {
catch {unset arg1}
set arg1 1
list [catch {binary scan \x3f\xcc\xcc\xcd f1 arg1(a)} msg] $msg
} {1 {can't set "arg1(a)": variable isn't array}}
test binary-31.14 {Tcl_BinaryObjCmd: scan} bigEndian {
catch {unset arg1 arg2}
set arg1 foo
set arg2 bar
list [binary scan \x3f\xcc\xcc\xcd\x40\x59\x99\x9a\x05 f2c* arg1 arg2] $arg1 $arg2
} {2 {1.60000002384 3.40000009537} 5}
test binary-31.15 {Tcl_BinaryObjCmd: scan} littleEndian {
catch {unset arg1 arg2}
set arg1 foo
set arg2 bar
list [binary scan \xcd\xcc\xcc\x3f\x9a\x99\x59\x40\x05 f2c* arg1 arg2] $arg1 $arg2
} {2 {1.60000002384 3.40000009537} 5}
test binary-32.1 {Tcl_BinaryObjCmd: scan} {
list [catch {binary scan abc d} msg] $msg
} {1 {not enough arguments for all format specifiers}}
test binary-32.2 {Tcl_BinaryObjCmd: scan} bigEndian {
catch {unset arg1}
list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33 d* arg1] $arg1
} {1 {1.6 3.4}}
test binary-32.3 {Tcl_BinaryObjCmd: scan} littleEndian {
catch {unset arg1}
list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40 d* arg1] $arg1
} {1 {1.6 3.4}}
test binary-32.4 {Tcl_BinaryObjCmd: scan} bigEndian {
catch {unset arg1}
list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33 d arg1] $arg1
} {1 1.6}
test binary-32.5 {Tcl_BinaryObjCmd: scan} littleEndian {
catch {unset arg1}
list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40 d arg1] $arg1
} {1 1.6}
test binary-32.6 {Tcl_BinaryObjCmd: scan} bigEndian {
catch {unset arg1}
list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a d1 arg1] $arg1
} {1 1.6}
test binary-32.7 {Tcl_BinaryObjCmd: scan} littleEndian {
catch {unset arg1}
list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f d1 arg1] $arg1
} {1 1.6}
test binary-32.8 {Tcl_BinaryObjCmd: scan} bigEndian {
catch {unset arg1}
list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a d0 arg1] $arg1
} {1 {}}
test binary-32.9 {Tcl_BinaryObjCmd: scan} littleEndian {
catch {unset arg1}
list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f d0 arg1] $arg1
} {1 {}}
test binary-32.10 {Tcl_BinaryObjCmd: scan} bigEndian {
catch {unset arg1}
list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33 d2 arg1] $arg1
} {1 {1.6 3.4}}
test binary-32.11 {Tcl_BinaryObjCmd: scan} littleEndian {
catch {unset arg1}
list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40 d2 arg1] $arg1
} {1 {1.6 3.4}}
test binary-32.12 {Tcl_BinaryObjCmd: scan} {
catch {unset arg1}
set arg1 foo
list [binary scan \x52 d1 arg1] $arg1
} {0 foo}
test binary-32.13 {Tcl_BinaryObjCmd: scan} {
catch {unset arg1}
set arg1 1
list [catch {binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a d1 arg1(a)} msg] $msg
} {1 {can't set "arg1(a)": variable isn't array}}
test binary-32.14 {Tcl_BinaryObjCmd: scan} bigEndian {
catch {unset arg1 arg2}
set arg1 foo
set arg2 bar
list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33\x05 d2c* arg1 arg2] $arg1 $arg2
} {2 {1.6 3.4} 5}
test binary-32.15 {Tcl_BinaryObjCmd: scan} littleEndian {
catch {unset arg1 arg2}
set arg1 foo
set arg2 bar
list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40\x05 d2c* arg1 arg2] $arg1 $arg2
} {2 {1.6 3.4} 5}
test binary-33.1 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
unset -nocomplain arg2
list [binary scan abcdefg a2xa3 arg1 arg2] $arg1 $arg2
} {2 ab def}
test binary-33.2 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
unset -nocomplain arg2
set arg2 foo
list [binary scan abcdefg a3x*a3 arg1 arg2] $arg1 $arg2
} {1 abc foo}
test binary-33.3 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
unset -nocomplain arg2
set arg2 foo
list [binary scan abcdefg a3x20a3 arg1 arg2] $arg1 $arg2
} {1 abc foo}
test binary-33.4 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
unset -nocomplain arg2
set arg2 foo
list [binary scan abc a3x20a3 arg1 arg2] $arg1 $arg2
} {1 abc foo}
test binary-33.5 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan abcdef x1a1 arg1] $arg1
} {1 b}
test binary-33.6 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan abcdef x5a1 arg1] $arg1
} {1 f}
test binary-33.7 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan abcdef x0a1 arg1] $arg1
} {1 a}
test binary-34.1 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
unset -nocomplain arg2
list [binary scan abcdefg a2Xa3 arg1 arg2] $arg1 $arg2
} {2 ab bcd}
test binary-34.2 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
unset -nocomplain arg2
set arg2 foo
list [binary scan abcdefg a3X*a3 arg1 arg2] $arg1 $arg2
} {2 abc abc}
test binary-34.3 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
unset -nocomplain arg2
set arg2 foo
list [binary scan abcdefg a3X20a3 arg1 arg2] $arg1 $arg2
} {2 abc abc}
test binary-34.4 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan abc X20a3 arg1] $arg1
} {1 abc}
test binary-34.5 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan abcdef x*X1a1 arg1] $arg1
} {1 f}
test binary-34.6 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan abcdef x*X5a1 arg1] $arg1
} {1 b}
test binary-34.7 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan abcdef x3X0a1 arg1] $arg1
} {1 d}
test binary-35.1 {Tcl_BinaryObjCmd: scan} -setup {
unset -nocomplain arg1
unset -nocomplain arg2
} -returnCodes error -body {
binary scan abcdefg a2@a3 arg1 arg2
} -result {missing count for "@" field specifier}
test binary-35.2 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
unset -nocomplain arg2
set arg2 foo
list [binary scan abcdefg a3@*a3 arg1 arg2] $arg1 $arg2
} {1 abc foo}
test binary-35.3 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
unset -nocomplain arg2
set arg2 foo
list [binary scan abcdefg a3@20a3 arg1 arg2] $arg1 $arg2
} {1 abc foo}
test binary-35.4 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan abcdef @2a3 arg1] $arg1
} {1 cde}
test binary-35.5 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan abcdef x*@1a1 arg1] $arg1
} {1 b}
test binary-35.6 {Tcl_BinaryObjCmd: scan} {
unset -nocomplain arg1
list [binary scan abcdef x*@0a1 arg1] $arg1
} {1 a}
test binary-36.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
binary scan abcdef u0a3
} -result {bad field specifier "u"}
# GetFormatSpec is pretty thoroughly tested above, but there are a few cases
# we should text explicitly
test binary-37.1 {GetFormatSpec: whitespace} {
binary format "a3 a5 a3" foo barblat baz
} foobarblbaz
test binary-37.2 {GetFormatSpec: whitespace} {
binary format " " foo
} {}
test binary-37.3 {GetFormatSpec: whitespace} {
binary format " a3" foo
} foo
test binary-37.4 {GetFormatSpec: whitespace} {
binary format "" foo
} {}
test binary-37.5 {GetFormatSpec: whitespace} {
binary format "" foo
} {}
test binary-37.6 {GetFormatSpec: whitespace} {
binary format " a3 " foo
} foo
test binary-37.7 {GetFormatSpec: numbers} {
list [catch {binary scan abcdef "x-1" foo} msg] $msg
} {1 {bad field specifier "-"}}
test binary-37.8 {GetFormatSpec: numbers} {
catch {unset arg1}
set arg1 foo
list [binary scan abcdef "a0x3" arg1] $arg1
} {1 {}}
test binary-37.9 {GetFormatSpec: numbers} {
# test format of neg numbers
# bug report/fix provided by Harald Kirsch
set x [binary format f* {1 -1 2 -2 0}]
binary scan $x f* bla
set bla
} {1.0 -1.0 2.0 -2.0 0.0}
test binary-38.1 {FormatNumber: word alignment} {
set x [binary format c1s1 1 1]
} \x01\x01\x00
test binary-38.2 {FormatNumber: word alignment} {
set x [binary format c1S1 1 1]
} \x01\x00\x01
test binary-38.3 {FormatNumber: word alignment} {
set x [binary format c1i1 1 1]
} \x01\x01\x00\x00\x00
test binary-38.4 {FormatNumber: word alignment} {
set x [binary format c1I1 1 1]
} \x01\x00\x00\x00\x01
test binary-38.5 {FormatNumber: word alignment} bigEndian {
set x [binary format c1d1 1 1.6]
} \x01\x3f\xf9\x99\x99\x99\x99\x99\x9a
test binary-38.6 {FormatNumber: word alignment} littleEndian {
set x [binary format c1d1 1 1.6]
} \x01\x9a\x99\x99\x99\x99\x99\xf9\x3f
test binary-38.7 {FormatNumber: word alignment} bigEndian {
set x [binary format c1f1 1 1.6]
} \x01\x3f\xcc\xcc\xcd
test binary-38.8 {FormatNumber: word alignment} littleEndian {
set x [binary format c1f1 1 1.6]
} \x01\xcd\xcc\xcc\x3f
test binary-39.1 {ScanNumber: sign extension} {
catch {unset arg1}
list [binary scan \x52\xa3 c2 arg1] $arg1
} {1 {82 -93}}
test binary-39.2 {ScanNumber: sign extension} {
catch {unset arg1}
list [binary scan \x01\x02\x01\x81\x82\x01\x81\x82 s4 arg1] $arg1
} {1 {513 -32511 386 -32127}}
test binary-39.3 {ScanNumber: sign extension} {
catch {unset arg1}
list [binary scan \x01\x02\x01\x81\x82\x01\x81\x82 S4 arg1] $arg1
} {1 {258 385 -32255 -32382}}
test binary-39.4 {ScanNumber: sign extension} {
catch {unset arg1}
list [binary scan \x01\x01\x01\x02\x81\x01\x01\x01\x01\x82\x01\x01\x01\x01\x82\x01\x01\x01\x01\x81 i5 arg1] $arg1
} {1 {33620225 16843137 16876033 25297153 -2130640639}}
test binary-39.5 {ScanNumber: sign extension} {
catch {unset arg1}
list [binary scan \x01\x01\x01\x02\x81\x01\x01\x01\x01\x82\x01\x01\x01\x01\x82\x01\x01\x01\x01\x81 I5 arg1] $arg1
} {1 {16843010 -2130640639 25297153 16876033 16843137}}
test binary-39.6 {ScanNumber: no sign extension} {
catch {unset arg1}
list [binary scan \x52\xa3 cu2 arg1] $arg1
} {1 {82 163}}
test binary-39.7 {ScanNumber: no sign extension} {
catch {unset arg1}
list [binary scan \x01\x02\x01\x81\x82\x01\x81\x82 su4 arg1] $arg1
} {1 {513 33025 386 33409}}
test binary-39.8 {ScanNumber: no sign extension} {
catch {unset arg1}
list [binary scan \x01\x02\x01\x81\x82\x01\x81\x82 Su4 arg1] $arg1
} {1 {258 385 33281 33154}}
test binary-39.9 {ScanNumber: no sign extension} {
catch {unset arg1}
list [binary scan \x01\x01\x01\x02\x81\x01\x01\x01\x01\x82\x01\x01\x01\x01\x82\x01\x01\x01\x01\x81 iu5 arg1] $arg1
} {1 {33620225 16843137 16876033 25297153 2164326657}}
test binary-39.10 {ScanNumber: no sign extension} {
catch {unset arg1}
list [binary scan \x01\x01\x01\x02\x81\x01\x01\x01\x01\x82\x01\x01\x01\x01\x82\x01\x01\x01\x01\x81 Iu5 arg1] $arg1
} {1 {16843010 2164326657 25297153 16876033 16843137}}
test binary-40.3 {ScanNumber: NaN} -constraints {maxCompatibility} \
-body {
catch {unset arg1}
list [binary scan \xff\xff\xff\xff f1 arg1] $arg1
} \
-match glob \
-result {1 -NaN*}
test binary-40.4 {ScanNumber: NaN} -constraints {maxCompatibility} \
-body {
catch {unset arg1}
list [binary scan \xff\xff\xff\xff\xff\xff\xff\xff d arg1] $arg1
} \
-match glob \
-result {1 -NaN*}
test binary-41.1 {ScanNumber: word alignment} {
catch {unset arg1; unset arg2}
list [binary scan \x01\x01\x00 c1s1 arg1 arg2] $arg1 $arg2
} {2 1 1}
test binary-41.2 {ScanNumber: word alignment} {
catch {unset arg1; unset arg2}
list [binary scan \x01\x00\x01 c1S1 arg1 arg2] $arg1 $arg2
} {2 1 1}
test binary-41.3 {ScanNumber: word alignment} {
catch {unset arg1; unset arg2}
list [binary scan \x01\x01\x00\x00\x00 c1i1 arg1 arg2] $arg1 $arg2
} {2 1 1}
test binary-41.4 {ScanNumber: word alignment} {
catch {unset arg1; unset arg2}
list [binary scan \x01\x00\x00\x00\x01 c1I1 arg1 arg2] $arg1 $arg2
} {2 1 1}
test binary-41.5 {ScanNumber: word alignment} bigEndian {
catch {unset arg1; unset arg2}
list [binary scan \x01\x3f\xcc\xcc\xcd c1f1 arg1 arg2] $arg1 $arg2
} {2 1 1.60000002384}
test binary-41.6 {ScanNumber: word alignment} littleEndian {
catch {unset arg1; unset arg2}
list [binary scan \x01\xcd\xcc\xcc\x3f c1f1 arg1 arg2] $arg1 $arg2
} {2 1 1.60000002384}
test binary-41.7 {ScanNumber: word alignment} bigEndian {
catch {unset arg1; unset arg2}
list [binary scan \x01\x3f\xf9\x99\x99\x99\x99\x99\x9a c1d1 arg1 arg2] $arg1 $arg2
} {2 1 1.6}
test binary-41.8 {ScanNumber: word alignment} littleEndian {
catch {unset arg1; unset arg2}
list [binary scan \x01\x9a\x99\x99\x99\x99\x99\xf9\x3f c1d1 arg1 arg2] $arg1 $arg2
} {2 1 1.6}
# Test changed in Jim's fashion
test binary-42.1 {Tcl_BinaryObjCmd: bad arguments} -returnCodes error -body {
binary ?
} -match glob -result {*}
# Wide int (guaranteed at least 64-bit) handling
test binary-43.1 {Tcl_BinaryObjCmd: format wide int} {} {
binary format w 7810179016327718216
} HelloTcl
test binary-43.2 {Tcl_BinaryObjCmd: format wide int} {} {
binary format W 7810179016327718216
} lcTolleH
test binary-44.1 {Tcl_BinaryObjCmd: scan wide int} {} {
binary scan HelloTcl W x
set x
} 5216694956358656876
test binary-44.2 {Tcl_BinaryObjCmd: scan wide int} {} {
binary scan lcTolleH w x
set x
} 5216694956358656876
# Changed 44.3, 44.4 as Jim doesn't have 'wide' function
test binary-44.3 {Tcl_BinaryObjCmd: scan wide int with bit 31 set} {} {
binary scan [binary format w [expr {int(3) << 31}]] w x
set x
} 6442450944
test binary-44.4 {Tcl_BinaryObjCmd: scan wide int with bit 31 set} {} {
binary scan [binary format W [expr {int(3) << 31}]] W x
set x
} 6442450944
test binary-43.5 {Tcl_BinaryObjCmd: scan wide int} {} {
catch {unset arg1}
list [binary scan \x80[string repeat \x00 7] W arg1] $arg1
} {1 -9223372036854775808}
# Tests binary-43.6-9 excluded as they transcend Jim's integer range.
test binary-43.6 {Tcl_BinaryObjCmd: scan unsigned wide int} {notImplemented} {
catch {unset arg1}
list [binary scan \x80[string repeat \x00 7] Wu arg1] $arg1
} {1 9223372036854775808}
test binary-43.7 {Tcl_BinaryObjCmd: scan unsigned wide int} {notImplemented} {
catch {unset arg1}
list [binary scan [string repeat \x00 7]\x80 wu arg1] $arg1
} {1 9223372036854775808}
test binary-43.8 {Tcl_BinaryObjCmd: scan unsigned wide int} {notImplemented} {
catch {unset arg1 arg2}
list [binary scan \x80[string repeat \x00 7]\x80[string repeat \x00 7] WuW arg1 arg2] $arg1 $arg2
} {2 9223372036854775808 -9223372036854775808}
test binary-43.9 {Tcl_BinaryObjCmd: scan unsigned wide int} {notImplemented} {
catch {unset arg1 arg2}
list [binary scan [string repeat \x00 7]\x80[string repeat \x00 7]\x80 wuw arg1 arg2] $arg1 $arg2
} {2 9223372036854775808 -9223372036854775808}
test binary-45.1 {Tcl_BinaryObjCmd: combined wide int handling} {
binary scan [binary format sws 16450 -1 19521] c* x
set x
} {66 64 -1 -1 -1 -1 -1 -1 -1 -1 65 76}
test binary-45.2 {Tcl_BinaryObjCmd: combined wide int handling} {
binary scan [binary format sWs 16450 0x7fffffff 19521] c* x
set x
} {66 64 0 0 0 0 127 -1 -1 -1 65 76}
# NB: tests binary-46.* fail as Jim Tcl doesn't truncate Unicode chars to ISO-8859-1.
test binary-47.1 {Tcl_BinaryObjCmd: number cache reference count handling} {
# This test is only reliable when memory debugging is turned on,
# but without even memory debugging it should still generate the
# expected answers and might therefore still pick up memory corruption
# caused by [Bug 851747].
list [binary scan aba ccc x x x] $x
} {3 97}
### TIP#129: endian specifiers ----
# format t
test binary-48.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
binary format t
} -result {not enough arguments for all format specifiers}
test binary-48.2 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
binary format t blat
} -match glob -result {expected integer *but got "blat"}
test binary-48.3 {Tcl_BinaryObjCmd: format} {
binary format S0 0x50
} {}
test binary-48.4 {Tcl_BinaryObjCmd: format} bigEndian {
binary format t 0x50
} \x00P
test binary-48.5 {Tcl_BinaryObjCmd: format} littleEndian {
binary format t 0x50
} P\x00
test binary-48.6 {Tcl_BinaryObjCmd: format} bigEndian {
binary format t 0x5052
} PR
test binary-48.7 {Tcl_BinaryObjCmd: format} littleEndian {
binary format t 0x5052
} RP
test binary-48.8 {Tcl_BinaryObjCmd: format} bigEndian {
binary format t 0x505251 0x53
} RQ
test binary-48.9 {Tcl_BinaryObjCmd: format} littleEndian {
binary format t 0x505251 0x53
} QR
test binary-48.10 {Tcl_BinaryObjCmd: format} bigEndian {
binary format t2 {0x50 0x52}
} \x00P\x00R
test binary-48.11 {Tcl_BinaryObjCmd: format} littleEndian {
binary format t2 {0x50 0x52}
} P\x00R\x00
test binary-48.12 {Tcl_BinaryObjCmd: format} bigEndian {
binary format t* {0x5051 0x52}
} PQ\x00R
test binary-48.13 {Tcl_BinaryObjCmd: format} littleEndian {
binary format t* {0x5051 0x52}
} QPR\x00
test binary-48.14 {Tcl_BinaryObjCmd: format} bigEndian {
binary format t2 {0x50 0x52 0x53} 0x54
} \x00P\x00R
test binary-48.15 {Tcl_BinaryObjCmd: format} littleEndian {
binary format t2 {0x50 0x52 0x53} 0x54
} P\x00R\x00
test binary-48.16 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
binary format t2 {0x50}
} -result {number of elements in list does not match count}
test binary-48.17 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
set a {0x50 0x51}
binary format t $a
} -match glob -result "expected integer *but got \"0x50 0x51\""
test binary-48.18 {Tcl_BinaryObjCmd: format} bigEndian {
set a {0x50 0x51}
binary format t1 $a
} \x00P
test binary-48.19 {Tcl_BinaryObjCmd: format} littleEndian {
set a {0x50 0x51}
binary format t1 $a
} P\x00
# format n
test binary-49.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
binary format n
} -result {not enough arguments for all format specifiers}
test binary-49.2 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
binary format n blat
} -match glob -result {expected integer *but got "blat"}
test binary-49.3 {Tcl_BinaryObjCmd: format} {
binary format n0 0x50
} {}
test binary-49.4 {Tcl_BinaryObjCmd: format} littleEndian {
binary format n 0x50
} P\x00\x00\x00
test binary-49.5 {Tcl_BinaryObjCmd: format} littleEndian {
binary format n 0x5052
} RP\x00\x00
test binary-49.6 {Tcl_BinaryObjCmd: format} littleEndian {
binary format n 0x505251 0x53
} QRP\x00
test binary-49.7 {Tcl_BinaryObjCmd: format} littleEndian {
binary format i1 {0x505251 0x53}
} QRP\x00
test binary-49.8 {Tcl_BinaryObjCmd: format} littleEndian {
binary format n 0x53525150
} PQRS
test binary-49.9 {Tcl_BinaryObjCmd: format} littleEndian {
binary format n2 {0x50 0x52}
} P\x00\x00\x00R\x00\x00\x00
test binary-49.10 {Tcl_BinaryObjCmd: format} littleEndian {
binary format n* {0x50515253 0x52}
} SRQPR\x00\x00\x00
test binary-49.11 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
binary format n2 {0x50}
} -result {number of elements in list does not match count}
test binary-49.12 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
set a {0x50 0x51}
binary format n $a
} -match glob -result "expected integer *but got \"0x50 0x51\""
test binary-49.13 {Tcl_BinaryObjCmd: format} littleEndian {
set a {0x50 0x51}
binary format n1 $a
} P\x00\x00\x00
test binary-49.14 {Tcl_BinaryObjCmd: format} bigEndian {
binary format n 0x50
} \x00\x00\x00P
test binary-49.15 {Tcl_BinaryObjCmd: format} bigEndian {
binary format n 0x5052
} \x00\x00PR
test binary-49.16 {Tcl_BinaryObjCmd: format} bigEndian {
binary format n 0x505251 0x53
} \x00PRQ
test binary-49.17 {Tcl_BinaryObjCmd: format} bigEndian {
binary format i1 {0x505251 0x53}
} QRP\x00
test binary-49.18 {Tcl_BinaryObjCmd: format} bigEndian {
binary format n 0x53525150
} SRQP
test binary-49.19 {Tcl_BinaryObjCmd: format} bigEndian {
binary format n2 {0x50 0x52}
} \x00\x00\x00P\x00\x00\x00R
test binary-49.20 {Tcl_BinaryObjCmd: format} bigEndian {
binary format n* {0x50515253 0x52}
} PQRS\x00\x00\x00R
# format m
test binary-50.1 {Tcl_BinaryObjCmd: format wide int} littleEndian {
binary format m 7810179016327718216
} HelloTcl
test binary-50.2 {Tcl_BinaryObjCmd: format wide int} bigEndian {
binary format m 7810179016327718216
} lcTolleH
# Changed 50.3, 50.4 as Jim doesn't have 'wide' function
test binary-50.3 {Tcl_BinaryObjCmd: scan wide int with bit 31 set} littleEndian {
binary scan [binary format m [expr {int(3) << 31}]] w x
set x
} 6442450944
test binary-50.4 {Tcl_BinaryObjCmd: scan wide int with bit 31 set} bigEndian {
binary scan [binary format m [expr {int(3) << 31}]] W x
set x
} 6442450944
# format Q/q
test binary-51.1 {Tcl_BinaryObjCmd: format} {
list [catch {binary format Q} msg] $msg
} {1 {not enough arguments for all format specifiers}}
test binary-51.2 {Tcl_BinaryObjCmd: format} {
list [catch {binary format q blat} msg] $msg
} {1 {expected floating-point number but got "blat"}}
test binary-51.3 {Tcl_BinaryObjCmd: format} {
binary format q0 1.6
} {}
test binary-51.4 {Tcl_BinaryObjCmd: format} {} {
binary format Q 1.6
} \x3f\xf9\x99\x99\x99\x99\x99\x9a
test binary-51.5 {Tcl_BinaryObjCmd: format} {} {
binary format q 1.6
} \x9a\x99\x99\x99\x99\x99\xf9\x3f
test binary-51.6 {Tcl_BinaryObjCmd: format} {} {
binary format Q* {1.6 3.4}
} \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33
test binary-51.7 {Tcl_BinaryObjCmd: format} {} {
binary format q* {1.6 3.4}
} \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40
test binary-51.8 {Tcl_BinaryObjCmd: format} {} {
binary format Q2 {1.6 3.4}
} \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33
test binary-51.9 {Tcl_BinaryObjCmd: format} {} {
binary format q2 {1.6 3.4}
} \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40
test binary-51.10 {Tcl_BinaryObjCmd: format} {} {
binary format Q2 {1.6 3.4 5.6}
} \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33
test binary-51.11 {Tcl_BinaryObjCmd: format} {} {
binary format q2 {1.6 3.4 5.6}
} \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40
test binary-51.14 {Tcl_BinaryObjCmd: format} {
list [catch {binary format q2 {1.6}} msg] $msg
} {1 {number of elements in list does not match count}}
test binary-51.15 {Tcl_BinaryObjCmd: format} {
set a {1.6 3.4}
list [catch {binary format q $a} msg] $msg
} [list 1 "expected floating-point number but got \"1.6 3.4\""]
test binary-51.16 {Tcl_BinaryObjCmd: format} {} {
set a {1.6 3.4}
binary format Q1 $a
} \x3f\xf9\x99\x99\x99\x99\x99\x9a
test binary-51.17 {Tcl_BinaryObjCmd: format} {} {
set a {1.6 3.4}
binary format q1 $a
} \x9a\x99\x99\x99\x99\x99\xf9\x3f
# format R/r
test binary-53.1 {Tcl_BinaryObjCmd: format} {
list [catch {binary format r} msg] $msg
} {1 {not enough arguments for all format specifiers}}
test binary-53.2 {Tcl_BinaryObjCmd: format} {
list [catch {binary format r blat} msg] $msg
} {1 {expected floating-point number but got "blat"}}
test binary-53.3 {Tcl_BinaryObjCmd: format} {
binary format f0 1.6
} {}
test binary-53.4 {Tcl_BinaryObjCmd: format} {} {
binary format R 1.6
} \x3f\xcc\xcc\xcd
test binary-53.5 {Tcl_BinaryObjCmd: format} {} {
binary format r 1.6
} \xcd\xcc\xcc\x3f
test binary-53.6 {Tcl_BinaryObjCmd: format} {} {
binary format R* {1.6 3.4}
} \x3f\xcc\xcc\xcd\x40\x59\x99\x9a
test binary-53.7 {Tcl_BinaryObjCmd: format} {} {
binary format r* {1.6 3.4}
} \xcd\xcc\xcc\x3f\x9a\x99\x59\x40
test binary-53.8 {Tcl_BinaryObjCmd: format} {} {
binary format R2 {1.6 3.4}
} \x3f\xcc\xcc\xcd\x40\x59\x99\x9a
test binary-53.9 {Tcl_BinaryObjCmd: format} {} {
binary format r2 {1.6 3.4}
} \xcd\xcc\xcc\x3f\x9a\x99\x59\x40
test binary-53.10 {Tcl_BinaryObjCmd: format} {} {
binary format R2 {1.6 3.4 5.6}
} \x3f\xcc\xcc\xcd\x40\x59\x99\x9a
test binary-53.11 {Tcl_BinaryObjCmd: format} {} {
binary format r2 {1.6 3.4 5.6}
} \xcd\xcc\xcc\x3f\x9a\x99\x59\x40
test binary-53.12 {Tcl_BinaryObjCmd: float overflow} {maxCompatibility} {
binary format R -3.402825e+38
} \xff\x7f\xff\xff
test binary-53.13 {Tcl_BinaryObjCmd: float overflow} {maxCompatibility} {
binary format r -3.402825e+38
} \xff\xff\x7f\xff
test binary-53.14 {Tcl_BinaryObjCmd: float underflow} {} {
binary format R -3.402825e-100
} \x80\x00\x00\x00
test binary-53.15 {Tcl_BinaryObjCmd: float underflow} {} {
binary format r -3.402825e-100
} \x00\x00\x00\x80
test binary-53.16 {Tcl_BinaryObjCmd: format} {
list [catch {binary format r2 {1.6}} msg] $msg
} {1 {number of elements in list does not match count}}
test binary-53.17 {Tcl_BinaryObjCmd: format} {
set a {1.6 3.4}
list [catch {binary format r $a} msg] $msg
} [list 1 "expected floating-point number but got \"1.6 3.4\""]
test binary-53.18 {Tcl_BinaryObjCmd: format} {} {
set a {1.6 3.4}
binary format R1 $a
} \x3f\xcc\xcc\xcd
test binary-53.19 {Tcl_BinaryObjCmd: format} {} {
set a {1.6 3.4}
binary format r1 $a
} \xcd\xcc\xcc\x3f
# scan t (s)
test binary-54.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
binary scan abc t
} -result {not enough arguments for all format specifiers}
test binary-54.2 {Tcl_BinaryObjCmd: scan} littleEndian {
unset -nocomplain arg1
list [binary scan \x52\xa3\x53\x54 t* arg1] $arg1
} {1 {-23726 21587}}
test binary-54.3 {Tcl_BinaryObjCmd: scan} littleEndian {
unset -nocomplain arg1
list [binary scan \x52\xa3\x53\x54 t arg1] $arg1
} {1 -23726}
test binary-54.4 {Tcl_BinaryObjCmd: scan} littleEndian {
unset -nocomplain arg1
list [binary scan \x52\xa3 t1 arg1] $arg1
} {1 -23726}
test binary-54.5 {Tcl_BinaryObjCmd: scan} littleEndian {
unset -nocomplain arg1
list [binary scan \x52\xa3 t0 arg1] $arg1
} {1 {}}
test binary-54.6 {Tcl_BinaryObjCmd: scan} littleEndian {
unset -nocomplain arg1
list [binary scan \x52\xa3\x53\x54 t2 arg1] $arg1
} {1 {-23726 21587}}
test binary-54.7 {Tcl_BinaryObjCmd: scan} littleEndian {
unset -nocomplain arg1
set arg1 foo
list [binary scan \x52 t1 arg1] $arg1
} {0 foo}
test binary-54.8 {Tcl_BinaryObjCmd: scan} -setup {
unset -nocomplain arg1
} -returnCodes error -body {
set arg1 1
binary scan \x52\x53 t1 arg1(a)
} -result {can't set "arg1(a)": variable isn't array}
test binary-54.9 {Tcl_BinaryObjCmd: scan} littleEndian {
unset -nocomplain arg1 arg2
set arg1 foo
set arg2 bar
list [binary scan \x52\xa3\x53\x54\x05 t2c* arg1 arg2] $arg1 $arg2
} {2 {-23726 21587} 5}
test binary-54.10 {Tcl_BinaryObjCmd: scan} littleEndian {
unset -nocomplain arg1 arg2
set arg1 foo
set arg2 bar
list [binary scan \x00\x80\x00\x80 tut arg1 arg2] $arg1 $arg2
} {2 32768 -32768}
test binary-54.11 {Tcl_BinaryObjCmd: scan} littleEndian {
unset -nocomplain arg1 arg2
set arg1 foo
set arg2 bar
list [binary scan \x00\x80\x00\x80 ttu arg1 arg2] $arg1 $arg2
} {2 -32768 32768}
# scan t (b)
test binary-55.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
binary scan abc t
} -result {not enough arguments for all format specifiers}
test binary-55.2 {Tcl_BinaryObjCmd: scan} bigEndian {
unset -nocomplain arg1
list [binary scan \x52\xa3\x53\x54 t* arg1] $arg1
} {1 {21155 21332}}
test binary-55.3 {Tcl_BinaryObjCmd: scan} bigEndian {
unset -nocomplain arg1
list [binary scan \x52\xa3\x53\x54 t arg1] $arg1
} {1 21155}
test binary-55.4 {Tcl_BinaryObjCmd: scan} bigEndian {
unset -nocomplain arg1
list [binary scan \x52\xa3 t1 arg1] $arg1
} {1 21155}
test binary-55.5 {Tcl_BinaryObjCmd: scan} bigEndian {
unset -nocomplain arg1
list [binary scan \x52\xa3 t0 arg1] $arg1
} {1 {}}
test binary-55.6 {Tcl_BinaryObjCmd: scan} bigEndian {
unset -nocomplain arg1
list [binary scan \x52\xa3\x53\x54 t2 arg1] $arg1
} {1 {21155 21332}}
test binary-55.7 {Tcl_BinaryObjCmd: scan} bigEndian {
unset -nocomplain arg1
set arg1 foo
list [binary scan \x52 t1 arg1] $arg1
} {0 foo}
test binary-55.8 {Tcl_BinaryObjCmd: scan} -setup {
unset -nocomplain arg1
} -returnCodes error -body {
set arg1 1
binary scan \x52\x53 t1 arg1(a)
} -result {can't set "arg1(a)": variable isn't array}
test binary-55.9 {Tcl_BinaryObjCmd: scan} bigEndian {
unset -nocomplain arg1 arg2
set arg1 foo
set arg2 bar
list [binary scan \x52\xa3\x53\x54\x05 t2c* arg1 arg2] $arg1 $arg2
} {2 {21155 21332} 5}
test binary-55.10 {Tcl_BinaryObjCmd: scan} bigEndian {
unset -nocomplain arg1 arg2
set arg1 foo
set arg2 bar
list [binary scan \x80\x00\x80\x00 tut arg1 arg2] $arg1 $arg2
} {2 32768 -32768}
test binary-55.11 {Tcl_BinaryObjCmd: scan} bigEndian {
unset -nocomplain arg1 arg2
set arg1 foo
set arg2 bar
list [binary scan \x80\x00\x80\x00 ttu arg1 arg2] $arg1 $arg2
} {2 -32768 32768}
# scan n (s)
test binary-56.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
binary scan abc n
} -result {not enough arguments for all format specifiers}
test binary-56.2 {Tcl_BinaryObjCmd: scan} littleEndian {
unset -nocomplain arg1
list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 n* arg1] $arg1
} {1 {1414767442 67305985}}
test binary-56.3 {Tcl_BinaryObjCmd: scan} littleEndian {
unset -nocomplain arg1
list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 n arg1] $arg1
} {1 1414767442}
test binary-56.4 {Tcl_BinaryObjCmd: scan} littleEndian {
unset -nocomplain arg1
list [binary scan \x52\xa3\x53\x54 n1 arg1] $arg1
} {1 1414767442}
test binary-56.5 {Tcl_BinaryObjCmd: scan} littleEndian {
unset -nocomplain arg1
list [binary scan \x52\xa3\x53 n0 arg1] $arg1
} {1 {}}
test binary-56.6 {Tcl_BinaryObjCmd: scan} littleEndian {
unset -nocomplain arg1
list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 n2 arg1] $arg1
} {1 {1414767442 67305985}}
test binary-56.7 {Tcl_BinaryObjCmd: scan} littleEndian {
unset -nocomplain arg1
set arg1 foo
list [binary scan \x52 n1 arg1] $arg1
} {0 foo}
test binary-56.8 {Tcl_BinaryObjCmd: scan} -setup {
unset -nocomplain arg1
} -returnCodes error -body {
set arg1 1
binary scan \x52\x53\x53\x54 n1 arg1(a)
} -result {can't set "arg1(a)": variable isn't array}
test binary-56.9 {Tcl_BinaryObjCmd: scan} littleEndian {
unset -nocomplain arg1 arg2
set arg1 foo
set arg2 bar
list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04\x05 n2c* arg1 arg2] $arg1 $arg2
} {2 {1414767442 67305985} 5}
test binary-56.10 {Tcl_BinaryObjCmd: scan} littleEndian {
unset -nocomplain arg1 arg2
set arg1 foo
set arg2 bar
list [binary scan \x80\x00\x00\x00\x80\x00\x00\x00 nun arg1 arg2] $arg1 $arg2
} {2 128 128}
test binary-56.11 {Tcl_BinaryObjCmd: scan} littleEndian {
unset -nocomplain arg1 arg2
set arg1 foo
set arg2 bar
list [binary scan \x00\x00\x00\x80\x00\x00\x00\x80 nun arg1 arg2] $arg1 $arg2
} {2 2147483648 -2147483648}
# scan n (b)
test binary-57.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
binary scan abc n
} -result {not enough arguments for all format specifiers}
test binary-57.2 {Tcl_BinaryObjCmd: scan} bigEndian {
unset -nocomplain arg1
list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 n* arg1] $arg1
} {1 {1386435412 16909060}}
test binary-57.3 {Tcl_BinaryObjCmd: scan} bigEndian {
unset -nocomplain arg1
list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 n arg1] $arg1
} {1 1386435412}
test binary-57.4 {Tcl_BinaryObjCmd: scan} bigEndian {
unset -nocomplain arg1
list [binary scan \x52\xa3\x53\x54 n1 arg1] $arg1
} {1 1386435412}
test binary-57.5 {Tcl_BinaryObjCmd: scan} bigEndian {
unset -nocomplain arg1
list [binary scan \x52\xa3\x53 n0 arg1] $arg1
} {1 {}}
test binary-57.6 {Tcl_BinaryObjCmd: scan} bigEndian {
unset -nocomplain arg1
list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 n2 arg1] $arg1
} {1 {1386435412 16909060}}
test binary-57.7 {Tcl_BinaryObjCmd: scan} bigEndian {
unset -nocomplain arg1
set arg1 foo
list [binary scan \x52 n1 arg1] $arg1
} {0 foo}
test binary-57.8 {Tcl_BinaryObjCmd: scan} -setup {
unset -nocomplain arg1
} -returnCodes error -body {
set arg1 1
binary scan \x52\x53\x53\x54 n1 arg1(a)
} -result {can't set "arg1(a)": variable isn't array}
test binary-57.9 {Tcl_BinaryObjCmd: scan} bigEndian {
unset -nocomplain arg1 arg2
set arg1 foo
set arg2 bar
list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04\x05 n2c* arg1 arg2] $arg1 $arg2
} {2 {1386435412 16909060} 5}
test binary-57.10 {Tcl_BinaryObjCmd: scan} bigEndian {
unset -nocomplain arg1 arg2
set arg1 foo
set arg2 bar
list [binary scan \x80\x00\x00\x00\x80\x00\x00\x00 nun arg1 arg2] $arg1 $arg2
} {2 2147483648 -2147483648}
test binary-57.11 {Tcl_BinaryObjCmd: scan} bigEndian {
unset -nocomplain arg1 arg2
set arg1 foo
set arg2 bar
list [binary scan \x00\x00\x00\x80\x00\x00\x00\x80 nun arg1 arg2] $arg1 $arg2
} {2 128 128}
# scan Q/q
test binary-58.1 {Tcl_BinaryObjCmd: scan} {
list [catch {binary scan abc q} msg] $msg
} {1 {not enough arguments for all format specifiers}}
test binary-58.2 {Tcl_BinaryObjCmd: scan} bigEndian {
catch {unset arg1}
list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33 Q* arg1] $arg1
} {1 {1.6 3.4}}
test binary-58.3 {Tcl_BinaryObjCmd: scan} littleEndian {
catch {unset arg1}
list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40 q* arg1] $arg1
} {1 {1.6 3.4}}
test binary-58.4 {Tcl_BinaryObjCmd: scan} bigEndian {
catch {unset arg1}
list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33 Q arg1] $arg1
} {1 1.6}
test binary-58.5 {Tcl_BinaryObjCmd: scan} littleEndian {
catch {unset arg1}
list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40 q arg1] $arg1
} {1 1.6}
test binary-58.6 {Tcl_BinaryObjCmd: scan} bigEndian {
catch {unset arg1}
list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a Q1 arg1] $arg1
} {1 1.6}
test binary-58.7 {Tcl_BinaryObjCmd: scan} littleEndian {
catch {unset arg1}
list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f q1 arg1] $arg1
} {1 1.6}
test binary-58.8 {Tcl_BinaryObjCmd: scan} bigEndian {
catch {unset arg1}
list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a Q0 arg1] $arg1
} {1 {}}
test binary-58.9 {Tcl_BinaryObjCmd: scan} littleEndian {
catch {unset arg1}
list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f q0 arg1] $arg1
} {1 {}}
test binary-58.10 {Tcl_BinaryObjCmd: scan} bigEndian {
catch {unset arg1}
list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33 Q2 arg1] $arg1
} {1 {1.6 3.4}}
test binary-58.11 {Tcl_BinaryObjCmd: scan} littleEndian {
catch {unset arg1}
list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40 q2 arg1] $arg1
} {1 {1.6 3.4}}
test binary-58.12 {Tcl_BinaryObjCmd: scan} {
catch {unset arg1}
set arg1 foo
list [binary scan \x52 q1 arg1] $arg1
} {0 foo}
test binary-58.13 {Tcl_BinaryObjCmd: scan} {
catch {unset arg1}
set arg1 1
list [catch {binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a q1 arg1(a)} msg] $msg
} {1 {can't set "arg1(a)": variable isn't array}}
test binary-58.14 {Tcl_BinaryObjCmd: scan} bigEndian {
catch {unset arg1 arg2}
set arg1 foo
set arg2 bar
list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33\x05 Q2c* arg1 arg2] $arg1 $arg2
} {2 {1.6 3.4} 5}
test binary-58.15 {Tcl_BinaryObjCmd: scan} littleEndian {
catch {unset arg1 arg2}
set arg1 foo
set arg2 bar
list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40\x05 q2c* arg1 arg2] $arg1 $arg2
} {2 {1.6 3.4} 5}
# scan R/r
test binary-59.1 {Tcl_BinaryObjCmd: scan} {
list [catch {binary scan abc r} msg] $msg
} {1 {not enough arguments for all format specifiers}}
test binary-59.2 {Tcl_BinaryObjCmd: scan} bigEndian {
catch {unset arg1}
list [binary scan \x3f\xcc\xcc\xcd\x40\x59\x99\x9a R* arg1] $arg1
} {1 {1.60000002384 3.40000009537}}
test binary-59.3 {Tcl_BinaryObjCmd: scan} littleEndian {
catch {unset arg1}
list [binary scan \xcd\xcc\xcc\x3f\x9a\x99\x59\x40 r* arg1] $arg1
} {1 {1.60000002384 3.40000009537}}
test binary-59.4 {Tcl_BinaryObjCmd: scan} bigEndian {
catch {unset arg1}
list [binary scan \x3f\xcc\xcc\xcd\x40\x59\x99\x9a R arg1] $arg1
} {1 1.60000002384}
test binary-59.5 {Tcl_BinaryObjCmd: scan} littleEndian {
catch {unset arg1}
list [binary scan \xcd\xcc\xcc\x3f\x9a\x99\x59\x40 r arg1] $arg1
} {1 1.60000002384}
test binary-59.6 {Tcl_BinaryObjCmd: scan} bigEndian {
catch {unset arg1}
list [binary scan \x3f\xcc\xcc\xcd R1 arg1] $arg1
} {1 1.60000002384}
test binary-59.7 {Tcl_BinaryObjCmd: scan} littleEndian {
catch {unset arg1}
list [binary scan \xcd\xcc\xcc\x3f r1 arg1] $arg1
} {1 1.60000002384}
test binary-59.8 {Tcl_BinaryObjCmd: scan} bigEndian {
catch {unset arg1}
list [binary scan \x3f\xcc\xcc\xcd R0 arg1] $arg1
} {1 {}}
test binary-59.9 {Tcl_BinaryObjCmd: scan} littleEndian {
catch {unset arg1}
list [binary scan \xcd\xcc\xcc\x3f r0 arg1] $arg1
} {1 {}}
test binary-59.10 {Tcl_BinaryObjCmd: scan} bigEndian {
catch {unset arg1}
list [binary scan \x3f\xcc\xcc\xcd\x40\x59\x99\x9a R2 arg1] $arg1
} {1 {1.60000002384 3.40000009537}}
test binary-59.11 {Tcl_BinaryObjCmd: scan} littleEndian {
catch {unset arg1}
list [binary scan \xcd\xcc\xcc\x3f\x9a\x99\x59\x40 r2 arg1] $arg1
} {1 {1.60000002384 3.40000009537}}
test binary-59.12 {Tcl_BinaryObjCmd: scan} {
catch {unset arg1}
set arg1 foo
list [binary scan \x52 r1 arg1] $arg1
} {0 foo}
test binary-59.13 {Tcl_BinaryObjCmd: scan} {
catch {unset arg1}
set arg1 1
list [catch {binary scan \x3f\xcc\xcc\xcd r1 arg1(a)} msg] $msg
} {1 {can't set "arg1(a)": variable isn't array}}
test binary-59.14 {Tcl_BinaryObjCmd: scan} bigEndian {
catch {unset arg1 arg2}
set arg1 foo
set arg2 bar
list [binary scan \x3f\xcc\xcc\xcd\x40\x59\x99\x9a\x05 R2c* arg1 arg2] $arg1 $arg2
} {2 {1.60000002384 3.40000009537} 5}
test binary-59.15 {Tcl_BinaryObjCmd: scan} littleEndian {
catch {unset arg1 arg2}
set arg1 foo
set arg2 bar
list [binary scan \xcd\xcc\xcc\x3f\x9a\x99\x59\x40\x05 r2c* arg1 arg2] $arg1 $arg2
} {2 {1.60000002384 3.40000009537} 5}
test binary-60.1 {[binary format] with NaN} -body {
binary scan [binary format dqQfrR NaN NaN NaN NaN NaN NaN] dqQfrR \
v1 v2 v3 v4 v5 v6
list $v1 $v2 $v3 $v4 $v5 $v6
} -match regexp -result {NaN(\([[:xdigit:]]+\))? NaN(\([[:xdigit:]]+\))? NaN(\([[:xdigit:]]+\))? NaN(\([[:xdigit:]]+\))? NaN(\([[:xdigit:]]+\))? NaN(\([[:xdigit:]]+\))?}
# scan m
test binary-61.1 {Tcl_BinaryObjCmd: scan wide int} bigEndian {
binary scan HelloTcl m x
set x
} 5216694956358656876
test binary-61.2 {Tcl_BinaryObjCmd: scan wide int} littleEndian {
binary scan lcTolleH m x
set x
} 5216694956358656876
test binary-61.3 {Tcl_BinaryObjCmd: scan wide int with bit 31 set} littleEndian {
binary scan [binary format w [expr {3 << 31}]] m x
set x
} 6442450944
test binary-61.4 {Tcl_BinaryObjCmd: scan wide int with bit 31 set} bigEndian {
binary scan [binary format W [expr {3 << 31}]] m x
set x
} 6442450944
# Big test for correct ordering of data in [expr]
proc testIEEE {} {
array set ieeeValues {}
binary scan [binary format dd -1.0 1.0] c* c
switch -exact -- $c {
{0 0 0 0 0 0 -16 -65 0 0 0 0 0 0 -16 63} {
# little endian
binary scan \x00\x00\x00\x00\x00\x00\xf0\xff d \
ieeeValues(-Infinity)
binary scan \x00\x00\x00\x00\x00\x00\xf0\xbf d \
ieeeValues(-Normal)
binary scan \x00\x00\x00\x00\x00\x00\x08\x80 d \
ieeeValues(-Subnormal)
binary scan \x00\x00\x00\x00\x00\x00\x00\x80 d \
ieeeValues(-0)
binary scan \x00\x00\x00\x00\x00\x00\x00\x00 d \
ieeeValues(+0)
binary scan \x00\x00\x00\x00\x00\x00\x08\x00 d \
ieeeValues(+Subnormal)
binary scan \x00\x00\x00\x00\x00\x00\xf0\x3f d \
ieeeValues(+Normal)
binary scan \x00\x00\x00\x00\x00\x00\xf0\x7f d \
ieeeValues(+Infinity)
binary scan \x00\x00\x00\x00\x00\x00\xf8\x7f d \
ieeeValues(NaN)
set ieeeValues(littleEndian) 1
return 1
}
{-65 -16 0 0 0 0 0 0 63 -16 0 0 0 0 0 0} {
binary scan \xff\xf0\x00\x00\x00\x00\x00\x00 d \
ieeeValues(-Infinity)
binary scan \xbf\xf0\x00\x00\x00\x00\x00\x00 d \
ieeeValues(-Normal)
binary scan \x80\x08\x00\x00\x00\x00\x00\x00 d \
ieeeValues(-Subnormal)
binary scan \x80\x00\x00\x00\x00\x00\x00\x00 d \
ieeeValues(-0)
binary scan \x00\x00\x00\x00\x00\x00\x00\x00 d \
ieeeValues(+0)
binary scan \x00\x08\x00\x00\x00\x00\x00\x00 d \
ieeeValues(+Subnormal)
binary scan \x3f\xf0\x00\x00\x00\x00\x00\x00 d \
ieeeValues(+Normal)
binary scan \x7f\xf0\x00\x00\x00\x00\x00\x00 d \
ieeeValues(+Infinity)
binary scan \x7f\xf8\x00\x00\x00\x00\x00\x00 d \
ieeeValues(NaN)
set ieeeValues(littleEndian) 0
return 1
}
default {
return 0
}
}
}
testConstraint ieeeFloatingPoint [testIEEE]
# scan/format infinities
test binary-62.1 {infinity} ieeeFloatingPoint {
binary scan [binary format q Infinity] w w
format 0x%016lx $w
} 0x7ff0000000000000
test binary-62.2 {infinity} ieeeFloatingPoint {
binary scan [binary format q -Infinity] w w
format 0x%016lx $w
} 0xfff0000000000000
test binary-62.3 {infinity} ieeeFloatingPoint {
binary scan [binary format q Inf] w w
format 0x%016lx $w
} 0x7ff0000000000000
test binary-62.4 {infinity} ieeeFloatingPoint {
binary scan [binary format q -Infinity] w w
format 0x%016lx $w
} 0xfff0000000000000
test binary-62.5 {infinity} ieeeFloatingPoint {
binary scan [binary format w 0x7ff0000000000000] q d
set d
} Inf
test binary-62.6 {infinity} ieeeFloatingPoint {
binary scan [binary format w 0xfff0000000000000] q d
set d
} -Inf
# scan/format Not-a-Number
test binary-63.1 {NaN} {ieeeFloatingPoint maxCompatibility} {
binary scan [binary format q NaN] w w
format 0x%016lx [expr {$w & 0xfff3ffffffffffff}]
} 0x7ff0000000000000
# Tests binary-63.2-4, 63.5-9, 64.2 excluded.
# Apparently strtod (and Jim) don't have
# advanced NaN-handling facility as Tcl does :)
test binary-63.2 {NaN} {ieeeFloatingPoint notImplemented} {
binary scan [binary format q -NaN] w w
format 0x%016lx [expr {$w & 0xfff3ffffffffffff}]
} 0xfff0000000000000
test binary-63.3 {NaN} {ieeeFloatingPoint notImplemented} {
binary scan [binary format q NaN(3123456789aBc)] w w
format 0x%016lx [expr {$w & 0xfff3ffffffffffff}]
} 0x7ff3123456789abc
test binary-63.4 {NaN} {ieeeFloatingPoint notImplemented} {
binary scan [binary format q {NaN( 3123456789aBc)}] w w
format 0x%016lx [expr {$w & 0xfff3ffffffffffff}]
} 0x7ff3123456789abc
# Make sure TclParseNumber() rejects invalid nan-hex formats [Bug 3402540]
test binary-63.5 {NaN} -constraints {ieeeFloatingPoint} -body {
binary format q Nan(
} -returnCodes error -match glob -result {expected floating-point number*}
test binary-63.6 {NaN} -constraints {ieeeFloatingPoint notImplemented} -body {
binary format q Nan()
} -returnCodes error -match glob -result {expected floating-point number*}
test binary-63.7 {NaN} -constraints {ieeeFloatingPoint notImplemented} -body {
binary format q Nan(g)
} -returnCodes error -match glob -result {expected floating-point number*}
test binary-63.8 {NaN} -constraints {ieeeFloatingPoint notImplemented} -body {
binary format q Nan(1,2)
} -returnCodes error -match glob -result {expected floating-point number*}
test binary-63.9 {NaN} -constraints {ieeeFloatingPoint notImplemented} -body {
binary format q Nan(1234567890abcd)
} -returnCodes error -match glob -result {expected floating-point number*}
test binary-64.1 {NaN} \
-constraints ieeeFloatingPoint \
-body {
binary scan [binary format w 0x7ff8000000000000] q d
set d
} \
-match glob -result NaN*
test binary-64.2 {NaN} \
-constraints {ieeeFloatingPoint notImplemented} \
-body {
binary scan [binary format w 0x7ff0123456789aBc] q d
set d
} \
-match glob -result NaN(*123456789abc)
# NB: the problem of %.12g format in Jim_DoubleToString
# make these tests meaningless. Excluded 65.1/3/5,7-9.
test binary-65.1 {largest significand} {ieeeFloatingPoint maxCompatibility} {
binary scan [binary format w 0x3fcfffffffffffff] q d
set d
} 0.24999999999999997
test binary-65.2 {smallest significand} ieeeFloatingPoint {
binary scan [binary format w 0x3fd0000000000000] q d
set d
} 0.25
test binary-65.3 {largest significand} {ieeeFloatingPoint maxCompatibility} {
binary scan [binary format w 0x3fdfffffffffffff] q d
set d
} 0.49999999999999994
test binary-65.4 {smallest significand} ieeeFloatingPoint {
binary scan [binary format w 0x3fe0000000000000] q d
set d
} 0.5
test binary-65.5 {largest significand} {ieeeFloatingPoint maxCompatibility} {
binary scan [binary format w 0x3fffffffffffffff] q d
set d
} 1.9999999999999998
test binary-65.6 {smallest significand} ieeeFloatingPoint {
binary scan [binary format w 0x4000000000000000] q d
set d
} 2.0
test binary-65.7 {smallest significand} {ieeeFloatingPoint maxCompatibility} {
binary scan [binary format w 0x434fffffffffffff] q d
set d
} 18014398509481982.0
test binary-65.8 {largest significand} {ieeeFloatingPoint maxCompatibility} {
binary scan [binary format w 0x4350000000000000] q d
set d
} 18014398509481984.0
test binary-65.9 {largest significand} {ieeeFloatingPoint maxCompatibility} {
binary scan [binary format w 0x4350000000000001] q d
set d
} 18014398509481988.0
# Jim-specific test.
# binary scan must return immediately if there's not enough bytes left.
test binary-66.1 {binary scan: not enought bytes} {} {
unset -nocomplain arg1 arg2
binary scan ab is arg1 arg2
} 0
# cleanup
::tcltest::cleanupTests
return
# Local Variables:
# mode: tcl
# End:
|