1 # This file tests the "binary" Tcl command.
3 # This file contains a collection of tests for one or more of the Tcl built-in
4 # commands. Sourcing this file into Tcl runs the tests and generates output
5 # for errors. No output means no errors were found.
7 # Copyright (c) 1997 by Sun Microsystems, Inc.
8 # Copyright (c) 1998-1999 by Scriptics Corporation.
10 # See the file "license.terms" for information on usage and redistribution of
11 # this file, and for a DISCLAIMER OF ALL WARRANTIES.
13 source [file dirname [info script]]/testing.tcl
16 testConstraint bigEndian [expr {$tcl_platform(byteOrder) eq "bigEndian"}]
17 testConstraint littleEndian [expr {$tcl_platform(byteOrder) eq "littleEndian"}]
18 testConstraint maxCompatibility 0
19 testConstraint notImplemented 0
21 # ----------------------------------------------------------------------
23 test binary-0.1 {DupByteArrayInternalRep} {
24 set hdr [binary format cc 0 0316]
31 test binary-1.1 {Tcl_BinaryObjCmd: bad args} -body {
33 } -returnCodes error -match glob -result {wrong # args: *}
34 test binary-1.2 {Tcl_BinaryObjCmd: bad args} -returnCodes error -body {
36 } -match glob -result {*}
37 test binary-1.3 {Tcl_BinaryObjCmd: format error} -returnCodes error -body {
39 } -match glob -result {*}
40 test binary-1.4 {Tcl_BinaryObjCmd: format} -body {
44 test binary-2.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
46 } -result {not enough arguments for all format specifiers}
47 test binary-2.2 {Tcl_BinaryObjCmd: format} {
50 test binary-2.3 {Tcl_BinaryObjCmd: format} {
53 test binary-2.4 {Tcl_BinaryObjCmd: format} {
56 test binary-2.5 {Tcl_BinaryObjCmd: format} {
59 test binary-2.6 {Tcl_BinaryObjCmd: format} {
62 test binary-2.7 {Tcl_BinaryObjCmd: format} {
63 binary format a*a3 foobarbaz blat
65 test binary-2.8 {Tcl_BinaryObjCmd: format} {
66 binary format a*X3a2 foobar x
69 test binary-3.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
71 } -result {not enough arguments for all format specifiers}
72 test binary-3.2 {Tcl_BinaryObjCmd: format} {
75 test binary-3.3 {Tcl_BinaryObjCmd: format} {
78 test binary-3.4 {Tcl_BinaryObjCmd: format} {
81 test binary-3.5 {Tcl_BinaryObjCmd: format} {
84 test binary-3.6 {Tcl_BinaryObjCmd: format} {
87 test binary-3.7 {Tcl_BinaryObjCmd: format} {
88 binary format A*A3 foobarbaz blat
90 test binary-3.8 {Tcl_BinaryObjCmd: format} {
91 binary format A*X3A2 foobar x
94 test binary-4.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
96 } -result {not enough arguments for all format specifiers}
97 test binary-4.2 {Tcl_BinaryObjCmd: format} {
100 test binary-4.3 {Tcl_BinaryObjCmd: format} {
103 test binary-4.4 {Tcl_BinaryObjCmd: format} {
104 binary format B* 010011
106 test binary-4.5 {Tcl_BinaryObjCmd: format} {
107 binary format B8 01001101
109 test binary-4.6 {Tcl_BinaryObjCmd: format} {
110 binary format A2X2B9 oo 01001101
112 test binary-4.7 {Tcl_BinaryObjCmd: format} {
113 binary format B9 010011011010
115 test binary-4.8 {Tcl_BinaryObjCmd: format} {
116 binary format B2B3 10 010
118 test binary-4.9 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
119 binary format B1B5 1 foo
120 } -match glob -result {expected *}
122 test binary-5.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
124 } -result {not enough arguments for all format specifiers}
125 test binary-5.2 {Tcl_BinaryObjCmd: format} {
128 test binary-5.3 {Tcl_BinaryObjCmd: format} {
131 test binary-5.4 {Tcl_BinaryObjCmd: format} {
132 binary format b* 010011
134 test binary-5.5 {Tcl_BinaryObjCmd: format} {
135 binary format b8 01001101
137 test binary-5.6 {Tcl_BinaryObjCmd: format} {
138 binary format A2X2b9 oo 01001101
140 test binary-5.7 {Tcl_BinaryObjCmd: format} {
141 binary format b9 010011011010
143 test binary-5.8 {Tcl_BinaryObjCmd: format} {
146 test binary-5.9 {Tcl_BinaryObjCmd: format} {
147 binary format b2b3 10 010
149 test binary-5.10 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
150 binary format b1b5 1 foo
151 } -match glob -result {expected *}
153 test binary-6.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
155 } -result {not enough arguments for all format specifiers}
156 test binary-6.2 {Tcl_BinaryObjCmd: format} {
159 test binary-6.3 {Tcl_BinaryObjCmd: format} {
162 test binary-6.4 {Tcl_BinaryObjCmd: format} {
165 test binary-6.5 {Tcl_BinaryObjCmd: format} {
166 binary format h* baadf00d
168 test binary-6.6 {Tcl_BinaryObjCmd: format} {
169 binary format h4 c410
171 test binary-6.7 {Tcl_BinaryObjCmd: format} {
172 binary format h6 c4102
174 test binary-6.8 {Tcl_BinaryObjCmd: format} {
175 binary format h5 c41020304
177 test binary-6.9 {Tcl_BinaryObjCmd: format} {
178 binary format a3X3h5 foo 2
180 test binary-6.10 {Tcl_BinaryObjCmd: format} {
181 binary format h2h3 23 456
183 test binary-6.11 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
185 } -match glob -result {expected *}
187 test binary-7.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
189 } -result {not enough arguments for all format specifiers}
190 test binary-7.2 {Tcl_BinaryObjCmd: format} {
193 test binary-7.3 {Tcl_BinaryObjCmd: format} {
196 test binary-7.4 {Tcl_BinaryObjCmd: format} {
199 test binary-7.5 {Tcl_BinaryObjCmd: format} {
200 binary format H* baadf00d
202 test binary-7.6 {Tcl_BinaryObjCmd: format} {
203 binary format H4 c410
205 test binary-7.7 {Tcl_BinaryObjCmd: format} {
206 binary format H6 c4102
208 test binary-7.8 {Tcl_BinaryObjCmd: format} {
209 binary format H5 c41023304
211 test binary-7.9 {Tcl_BinaryObjCmd: format} {
212 binary format a3X3H5 foo 2
214 test binary-7.10 {Tcl_BinaryObjCmd: format} {
215 binary format H2H3 23 456
217 test binary-7.11 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
219 } -match glob -result {expected *}
221 test binary-8.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
223 } -result {not enough arguments for all format specifiers}
224 test binary-8.2 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
226 } -match glob -result {expected *}
227 test binary-8.3 {Tcl_BinaryObjCmd: format} {
228 binary format c0 0x50
230 test binary-8.4 {Tcl_BinaryObjCmd: format} {
233 test binary-8.5 {Tcl_BinaryObjCmd: format} {
234 binary format c 0x5052
236 test binary-8.6 {Tcl_BinaryObjCmd: format} {
237 binary format c2 {0x50 0x52}
239 test binary-8.7 {Tcl_BinaryObjCmd: format} {
240 binary format c2 {0x50 0x52 0x53}
242 test binary-8.8 {Tcl_BinaryObjCmd: format} {
243 binary format c* {0x50 0x52}
245 test binary-8.9 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
246 binary format c2 {0x50}
247 } -result {number of elements in list does not match count}
248 test binary-8.10 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
251 } -result "expected integer but got \"0x50 0x51\""
252 test binary-8.11 {Tcl_BinaryObjCmd: format} {
257 test binary-9.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
259 } -result {not enough arguments for all format specifiers}
260 test binary-9.2 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
262 } -result {expected integer but got "blat"}
263 test binary-9.3 {Tcl_BinaryObjCmd: format} {
264 binary format s0 0x50
266 test binary-9.4 {Tcl_BinaryObjCmd: format} {
269 test binary-9.5 {Tcl_BinaryObjCmd: format} {
270 binary format s 0x5052
272 test binary-9.6 {Tcl_BinaryObjCmd: format} {
273 binary format s 0x505251 0x53
275 test binary-9.7 {Tcl_BinaryObjCmd: format} {
276 binary format s2 {0x50 0x52}
278 test binary-9.8 {Tcl_BinaryObjCmd: format} {
279 binary format s* {0x5051 0x52}
281 test binary-9.9 {Tcl_BinaryObjCmd: format} {
282 binary format s2 {0x50 0x52 0x53} 0x54
284 test binary-9.10 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
285 binary format s2 {0x50}
286 } -result {number of elements in list does not match count}
287 test binary-9.11 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
290 } -result "expected integer but got \"0x50 0x51\""
291 test binary-9.12 {Tcl_BinaryObjCmd: format} {
296 test binary-10.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
298 } -result {not enough arguments for all format specifiers}
299 test binary-10.2 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
301 } -result {expected integer but got "blat"}
302 test binary-10.3 {Tcl_BinaryObjCmd: format} {
303 binary format S0 0x50
305 test binary-10.4 {Tcl_BinaryObjCmd: format} {
308 test binary-10.5 {Tcl_BinaryObjCmd: format} {
309 binary format S 0x5052
311 test binary-10.6 {Tcl_BinaryObjCmd: format} {
312 binary format S 0x505251 0x53
314 test binary-10.7 {Tcl_BinaryObjCmd: format} {
315 binary format S2 {0x50 0x52}
317 test binary-10.8 {Tcl_BinaryObjCmd: format} {
318 binary format S* {0x5051 0x52}
320 test binary-10.9 {Tcl_BinaryObjCmd: format} {
321 binary format S2 {0x50 0x52 0x53} 0x54
323 test binary-10.10 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
324 binary format S2 {0x50}
325 } -result {number of elements in list does not match count}
326 test binary-10.11 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
329 } -result "expected integer but got \"0x50 0x51\""
330 test binary-10.12 {Tcl_BinaryObjCmd: format} {
335 test binary-11.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
337 } -result {not enough arguments for all format specifiers}
338 test binary-11.2 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
340 } -result {expected integer but got "blat"}
341 test binary-11.3 {Tcl_BinaryObjCmd: format} {
342 binary format i0 0x50
344 test binary-11.4 {Tcl_BinaryObjCmd: format} {
347 test binary-11.5 {Tcl_BinaryObjCmd: format} {
348 binary format i 0x5052
350 test binary-11.6 {Tcl_BinaryObjCmd: format} {
351 binary format i 0x505251 0x53
353 test binary-11.7 {Tcl_BinaryObjCmd: format} {
354 binary format i1 {0x505251 0x53}
356 test binary-11.8 {Tcl_BinaryObjCmd: format} {
357 binary format i 0x53525150
359 test binary-11.9 {Tcl_BinaryObjCmd: format} {
360 binary format i2 {0x50 0x52}
361 } P\x00\x00\x00R\x00\x00\x00
362 test binary-11.10 {Tcl_BinaryObjCmd: format} {
363 binary format i* {0x50515253 0x52}
365 test binary-11.11 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
366 binary format i2 {0x50}
367 } -result {number of elements in list does not match count}
368 test binary-11.12 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
371 } -result "expected integer but got \"0x50 0x51\""
372 test binary-11.13 {Tcl_BinaryObjCmd: format} {
377 test binary-12.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
379 } -result {not enough arguments for all format specifiers}
380 test binary-12.2 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
382 } -result {expected integer but got "blat"}
383 test binary-12.3 {Tcl_BinaryObjCmd: format} {
384 binary format I0 0x50
386 test binary-12.4 {Tcl_BinaryObjCmd: format} {
389 test binary-12.5 {Tcl_BinaryObjCmd: format} {
390 binary format I 0x5052
392 test binary-12.6 {Tcl_BinaryObjCmd: format} {
393 binary format I 0x505251 0x53
395 test binary-12.7 {Tcl_BinaryObjCmd: format} {
396 binary format I1 {0x505251 0x53}
398 test binary-12.8 {Tcl_BinaryObjCmd: format} {
399 binary format I 0x53525150
401 test binary-12.9 {Tcl_BinaryObjCmd: format} {
402 binary format I2 {0x50 0x52}
403 } \x00\x00\x00P\x00\x00\x00R
404 test binary-12.10 {Tcl_BinaryObjCmd: format} {
405 binary format I* {0x50515253 0x52}
407 test binary-12.11 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
408 binary format i2 {0x50}
409 } -result {number of elements in list does not match count}
410 test binary-12.12 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
413 } -result "expected integer but got \"0x50 0x51\""
414 test binary-12.13 {Tcl_BinaryObjCmd: format} {
419 test binary-13.1 {Tcl_BinaryObjCmd: format} {
420 list [catch {binary format f} msg] $msg
421 } {1 {not enough arguments for all format specifiers}}
422 test binary-13.2 {Tcl_BinaryObjCmd: format} {
423 list [catch {binary format f blat} msg] $msg
424 } {1 {expected floating-point number but got "blat"}}
425 test binary-13.3 {Tcl_BinaryObjCmd: format} {
428 test binary-13.4 {Tcl_BinaryObjCmd: format} bigEndian {
431 test binary-13.5 {Tcl_BinaryObjCmd: format} littleEndian {
434 test binary-13.6 {Tcl_BinaryObjCmd: format} bigEndian {
435 binary format f* {1.6 3.4}
436 } \x3f\xcc\xcc\xcd\x40\x59\x99\x9a
437 test binary-13.7 {Tcl_BinaryObjCmd: format} littleEndian {
438 binary format f* {1.6 3.4}
439 } \xcd\xcc\xcc\x3f\x9a\x99\x59\x40
440 test binary-13.8 {Tcl_BinaryObjCmd: format} bigEndian {
441 binary format f2 {1.6 3.4}
442 } \x3f\xcc\xcc\xcd\x40\x59\x99\x9a
443 test binary-13.9 {Tcl_BinaryObjCmd: format} littleEndian {
444 binary format f2 {1.6 3.4}
445 } \xcd\xcc\xcc\x3f\x9a\x99\x59\x40
446 test binary-13.10 {Tcl_BinaryObjCmd: format} bigEndian {
447 binary format f2 {1.6 3.4 5.6}
448 } \x3f\xcc\xcc\xcd\x40\x59\x99\x9a
449 test binary-13.11 {Tcl_BinaryObjCmd: format} littleEndian {
450 binary format f2 {1.6 3.4 5.6}
451 } \xcd\xcc\xcc\x3f\x9a\x99\x59\x40
452 test binary-13.12 {Tcl_BinaryObjCmd: float overflow} {bigEndian maxCompatibility} {
453 binary format f -3.402825e+38
455 test binary-13.13 {Tcl_BinaryObjCmd: float overflow} {littleEndian maxCompatibility} {
456 binary format f -3.402825e+38
458 test binary-13.14 {Tcl_BinaryObjCmd: float underflow} bigEndian {
459 binary format f -3.402825e-100
461 test binary-13.15 {Tcl_BinaryObjCmd: float underflow} littleEndian {
462 binary format f -3.402825e-100
464 test binary-13.16 {Tcl_BinaryObjCmd: format} {
465 list [catch {binary format f2 {1.6}} msg] $msg
466 } {1 {number of elements in list does not match count}}
467 test binary-13.17 {Tcl_BinaryObjCmd: format} {
469 list [catch {binary format f $a} msg] $msg
470 } [list 1 "expected floating-point number but got \"1.6 3.4\""]
471 test binary-13.18 {Tcl_BinaryObjCmd: format} bigEndian {
475 test binary-13.19 {Tcl_BinaryObjCmd: format} littleEndian {
480 test binary-14.1 {Tcl_BinaryObjCmd: format} {
481 list [catch {binary format d} msg] $msg
482 } {1 {not enough arguments for all format specifiers}}
483 test binary-14.2 {Tcl_BinaryObjCmd: format} {
484 list [catch {binary format d blat} msg] $msg
485 } {1 {expected floating-point number but got "blat"}}
486 test binary-14.3 {Tcl_BinaryObjCmd: format} {
489 test binary-14.4 {Tcl_BinaryObjCmd: format} bigEndian {
491 } \x3f\xf9\x99\x99\x99\x99\x99\x9a
492 test binary-14.5 {Tcl_BinaryObjCmd: format} littleEndian {
494 } \x9a\x99\x99\x99\x99\x99\xf9\x3f
495 test binary-14.6 {Tcl_BinaryObjCmd: format} bigEndian {
496 binary format d* {1.6 3.4}
497 } \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33
498 test binary-14.7 {Tcl_BinaryObjCmd: format} littleEndian {
499 binary format d* {1.6 3.4}
500 } \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40
501 test binary-14.8 {Tcl_BinaryObjCmd: format} bigEndian {
502 binary format d2 {1.6 3.4}
503 } \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33
504 test binary-14.9 {Tcl_BinaryObjCmd: format} littleEndian {
505 binary format d2 {1.6 3.4}
506 } \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40
507 test binary-14.10 {Tcl_BinaryObjCmd: format} bigEndian {
508 binary format d2 {1.6 3.4 5.6}
509 } \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33
510 test binary-14.11 {Tcl_BinaryObjCmd: format} littleEndian {
511 binary format d2 {1.6 3.4 5.6}
512 } \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40
513 test binary-14.14 {Tcl_BinaryObjCmd: format} {
514 list [catch {binary format d2 {1.6}} msg] $msg
515 } {1 {number of elements in list does not match count}}
516 test binary-14.15 {Tcl_BinaryObjCmd: format} {
518 list [catch {binary format d $a} msg] $msg
519 } [list 1 "expected floating-point number but got \"1.6 3.4\""]
520 test binary-14.16 {Tcl_BinaryObjCmd: format} bigEndian {
523 } \x3f\xf9\x99\x99\x99\x99\x99\x9a
524 test binary-14.17 {Tcl_BinaryObjCmd: format} littleEndian {
527 } \x9a\x99\x99\x99\x99\x99\xf9\x3f
528 test binary-14.18 {FormatNumber: Bug 1116542} {
529 binary scan [binary format d 1.25] d w
533 test binary-15.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
534 binary format ax*a "y" "z"
535 } -result {cannot use "*" in format string with "x"}
536 test binary-15.2 {Tcl_BinaryObjCmd: format} {
537 binary format axa "y" "z"
539 test binary-15.3 {Tcl_BinaryObjCmd: format} {
540 binary format ax3a "y" "z"
542 test binary-15.4 {Tcl_BinaryObjCmd: format} {
543 binary format a*X3x3a* "foo" "z"
545 test binary-15.5 {Tcl_BinaryObjCmd: format - bug #1923966} {
548 test binary-15.6 {Tcl_BinaryObjCmd: format - bug #1923966} {
549 binary format x0ss 1 1
551 test binary-15.7 {Tcl_BinaryObjCmd: format - bug #1923966} {
554 test binary-15.8 {Tcl_BinaryObjCmd: format - bug #1923966} {
555 binary format x1ss 1 1
556 } \x00\x01\x00\x01\x00
558 test binary-16.1 {Tcl_BinaryObjCmd: format} {
559 binary format a*X*a "foo" "z"
561 test binary-16.2 {Tcl_BinaryObjCmd: format} {
562 binary format aX3a "y" "z"
564 test binary-16.3 {Tcl_BinaryObjCmd: format} {
565 binary format a*Xa* "foo" "zy"
567 test binary-16.4 {Tcl_BinaryObjCmd: format} {
568 binary format a*X3a "foobar" "z"
570 test binary-16.5 {Tcl_BinaryObjCmd: format} {
571 binary format a*X3aX2a "foobar" "z" "b"
574 test binary-17.1 {Tcl_BinaryObjCmd: format} {
577 test binary-17.2 {Tcl_BinaryObjCmd: format} {
578 binary format @5a2 "ab"
579 } \x00\x00\x00\x00\x00\x61\x62
580 test binary-17.3 {Tcl_BinaryObjCmd: format} {
581 binary format {a* @0 a2 @* a*} "foobar" "ab" "blat"
584 test binary-18.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
585 binary format u0a3 abc abd
586 } -result {bad field specifier "u"}
588 test binary-19.1 {Tcl_BinaryObjCmd: errors} -returnCodes error -body {
590 } -match glob -result {*}
591 test binary-19.2 {Tcl_BinaryObjCmd: errors} -returnCodes error -body {
593 } -result {wrong # args: should be "binary scan value formatString ?varName ...?"}
594 test binary-19.3 {Tcl_BinaryObjCmd: scan} {
598 test binary-20.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
600 } -result {not enough arguments for all format specifiers}
601 test binary-20.2 {Tcl_BinaryObjCmd: scan} -setup {
602 unset -nocomplain arg1
603 } -returnCodes error -body {
605 binary scan abc a arg1(a)
606 } -result {can't set "arg1(a)": variable isn't array}
607 test binary-20.3 {Tcl_BinaryObjCmd: scan} -setup {
608 unset -nocomplain arg1
611 list [binary scan abc a0 arg1] $arg1
613 test binary-20.4 {Tcl_BinaryObjCmd: scan} -setup {
614 unset -nocomplain arg1
616 list [binary scan abc a* arg1] $arg1
618 test binary-20.5 {Tcl_BinaryObjCmd: scan} -setup {
619 unset -nocomplain arg1
621 list [binary scan abc a5 arg1] [info exists arg1]
623 test binary-20.6 {Tcl_BinaryObjCmd: scan} {
625 list [binary scan abc a2 arg1] $arg1
627 test binary-20.7 {Tcl_BinaryObjCmd: scan} -setup {
628 unset -nocomplain arg1
629 unset -nocomplain arg2
631 list [binary scan abcdef a2a2 arg1 arg2] $arg1 $arg2
633 test binary-20.8 {Tcl_BinaryObjCmd: scan} -setup {
634 unset -nocomplain arg1
636 list [binary scan abc a2 arg1(a)] $arg1(a)
638 test binary-20.9 {Tcl_BinaryObjCmd: scan} -setup {
639 unset -nocomplain arg1
641 list [binary scan abc a arg1(a)] $arg1(a)
644 # As soon as a conversion runs out of bytes, scan should stop
645 test binary-20.10 {Tcl_BinaryObjCmd: scan, too few bytes} -setup {
646 unset -nocomplain arg1 arg2
648 list [binary scan abc a5a2 arg1 arg2] [info exists arg1] [info exists arg2]
651 test binary-21.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
653 } -result {not enough arguments for all format specifiers}
654 test binary-21.2 {Tcl_BinaryObjCmd: scan} -setup {
655 unset -nocomplain arg1
656 } -returnCodes error -body {
658 binary scan abc A arg1(a)
659 } -result {can't set "arg1(a)": variable isn't array}
660 test binary-21.3 {Tcl_BinaryObjCmd: scan} -setup {
661 unset -nocomplain arg1
664 list [binary scan abc A0 arg1] $arg1
666 test binary-21.4 {Tcl_BinaryObjCmd: scan} -setup {
667 unset -nocomplain arg1
669 list [binary scan abc A* arg1] $arg1
671 test binary-21.5 {Tcl_BinaryObjCmd: scan} -setup {
672 unset -nocomplain arg1
674 list [binary scan abc A5 arg1] [info exists arg1]
676 test binary-21.6 {Tcl_BinaryObjCmd: scan} {
678 list [binary scan abc A2 arg1] $arg1
680 test binary-21.7 {Tcl_BinaryObjCmd: scan} -setup {
681 unset -nocomplain arg1
682 unset -nocomplain arg2
684 list [binary scan abcdef A2A2 arg1 arg2] $arg1 $arg2
686 test binary-21.8 {Tcl_BinaryObjCmd: scan} -setup {
687 unset -nocomplain arg1
689 list [binary scan abc A2 arg1(a)] $arg1(a)
691 test binary-21.9 {Tcl_BinaryObjCmd: scan} -setup {
692 unset -nocomplain arg1
694 list [binary scan abc A2 arg1(a)] $arg1(a)
696 test binary-21.10 {Tcl_BinaryObjCmd: scan} -setup {
697 unset -nocomplain arg1
699 list [binary scan abc A arg1(a)] $arg1(a)
701 test binary-21.11 {Tcl_BinaryObjCmd: scan} -setup {
702 unset -nocomplain arg1
704 list [binary scan "abc def \x00 " A* arg1] $arg1
705 } -result {1 {abc def}}
706 test binary-21.12 {Tcl_BinaryObjCmd: scan} -setup {
707 unset -nocomplain arg1
709 list [binary scan "abc def \x00ghi " A* arg1] $arg1
710 } -result [list 1 "abc def \x00ghi"]
712 test binary-22.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
714 } -result {not enough arguments for all format specifiers}
715 test binary-22.2 {Tcl_BinaryObjCmd: scan} {
716 unset -nocomplain arg1
717 list [binary scan \x52\x53 b* arg1] $arg1
718 } {1 0100101011001010}
719 test binary-22.3 {Tcl_BinaryObjCmd: scan} {
720 unset -nocomplain arg1
721 list [binary scan \x82\x53 b arg1] $arg1
723 test binary-22.4 {Tcl_BinaryObjCmd: scan} {
724 unset -nocomplain arg1
725 list [binary scan \x82\x53 b1 arg1] $arg1
727 test binary-22.5 {Tcl_BinaryObjCmd: scan} {
728 unset -nocomplain arg1
729 list [binary scan \x82\x53 b0 arg1] $arg1
731 test binary-22.6 {Tcl_BinaryObjCmd: scan} {
732 unset -nocomplain arg1
733 list [binary scan \x52\x53 b5 arg1] $arg1
735 test binary-22.7 {Tcl_BinaryObjCmd: scan} {
736 unset -nocomplain arg1
737 list [binary scan \x52\x53 b8 arg1] $arg1
739 test binary-22.8 {Tcl_BinaryObjCmd: scan} {
740 unset -nocomplain arg1
741 list [binary scan \x52\x53 b14 arg1] $arg1
743 test binary-22.9 {Tcl_BinaryObjCmd: scan} {
744 unset -nocomplain arg1
746 list [binary scan \x52 b14 arg1] $arg1
748 test binary-22.10 {Tcl_BinaryObjCmd: scan} -setup {
749 unset -nocomplain arg1
750 } -returnCodes error -body {
752 binary scan \x52\x53 b1 arg1(a)
753 } -result {can't set "arg1(a)": variable isn't array}
754 test binary-22.11 {Tcl_BinaryObjCmd: scan} -setup {
755 unset -nocomplain arg1 arg2
759 list [binary scan \x07\x87\x05 b5b* arg1 arg2] $arg1 $arg2
760 } -result {2 11100 1110000110100000}
762 # As soon as a conversion runs out of bytes, scan should stop
763 test binary-20.12 {Tcl_BinaryObjCmd: scan, too few bytes} {
764 unset -nocomplain arg1 arg2
767 list [binary scan \x52 b14b8 arg1 arg2] $arg1 $arg2
770 test binary-23.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
772 } -result {not enough arguments for all format specifiers}
773 test binary-23.2 {Tcl_BinaryObjCmd: scan} {
774 unset -nocomplain arg1
775 list [binary scan \x52\x53 B* arg1] $arg1
776 } {1 0101001001010011}
777 test binary-23.3 {Tcl_BinaryObjCmd: scan} {
778 unset -nocomplain arg1
779 list [binary scan \x82\x53 B arg1] $arg1
781 test binary-23.4 {Tcl_BinaryObjCmd: scan} {
782 unset -nocomplain arg1
783 list [binary scan \x82\x53 B1 arg1] $arg1
785 test binary-23.5 {Tcl_BinaryObjCmd: scan} {
786 unset -nocomplain arg1
787 list [binary scan \x52\x53 B0 arg1] $arg1
789 test binary-23.6 {Tcl_BinaryObjCmd: scan} {
790 unset -nocomplain arg1
791 list [binary scan \x52\x53 B5 arg1] $arg1
793 test binary-23.7 {Tcl_BinaryObjCmd: scan} {
794 unset -nocomplain arg1
795 list [binary scan \x52\x53 B8 arg1] $arg1
797 test binary-23.8 {Tcl_BinaryObjCmd: scan} {
798 unset -nocomplain arg1
799 list [binary scan \x52\x53 B14 arg1] $arg1
801 test binary-23.9 {Tcl_BinaryObjCmd: scan} {
802 unset -nocomplain arg1
804 list [binary scan \x52 B14 arg1] $arg1
806 test binary-23.10 {Tcl_BinaryObjCmd: scan} -setup {
807 unset -nocomplain arg1
808 } -returnCodes error -body {
810 binary scan \x52\x53 B1 arg1(a)
811 } -result {can't set "arg1(a)": variable isn't array}
812 test binary-23.11 {Tcl_BinaryObjCmd: scan} -setup {
813 unset -nocomplain arg1 arg2
817 list [binary scan \x70\x87\x05 B5B* arg1 arg2] $arg1 $arg2
818 } -result {2 01110 1000011100000101}
820 test binary-24.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
822 } -result {not enough arguments for all format specifiers}
823 test binary-24.2 {Tcl_BinaryObjCmd: scan} {
824 unset -nocomplain arg1
825 list [binary scan \x52\xa3 h* arg1] $arg1
827 test binary-24.3 {Tcl_BinaryObjCmd: scan} {
828 unset -nocomplain arg1
829 list [binary scan \xc2\xa3 h arg1] $arg1
831 test binary-24.4 {Tcl_BinaryObjCmd: scan} {
832 unset -nocomplain arg1
833 list [binary scan \x82\x53 h1 arg1] $arg1
835 test binary-24.5 {Tcl_BinaryObjCmd: scan} {
836 unset -nocomplain arg1
837 list [binary scan \x52\x53 h0 arg1] $arg1
839 test binary-24.6 {Tcl_BinaryObjCmd: scan} {
840 unset -nocomplain arg1
841 list [binary scan \xf2\x53 h2 arg1] $arg1
843 test binary-24.7 {Tcl_BinaryObjCmd: scan} {
844 unset -nocomplain arg1
845 list [binary scan \x52\x53 h3 arg1] $arg1
847 test binary-24.8 {Tcl_BinaryObjCmd: scan} {
848 unset -nocomplain arg1
850 list [binary scan \x52 h3 arg1] $arg1
852 test binary-24.9 {Tcl_BinaryObjCmd: scan} -setup {
853 unset -nocomplain arg1
854 } -returnCodes error -body {
856 binary scan \x52\x53 h1 arg1(a)
857 } -result {can't set "arg1(a)": variable isn't array}
858 test binary-24.10 {Tcl_BinaryObjCmd: scan} -setup {
859 unset -nocomplain arg1 arg2
863 list [binary scan \x70\x87\x05 h2h* arg1 arg2] $arg1 $arg2
864 } -result {2 07 7850}
866 test binary-25.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
868 } -result {not enough arguments for all format specifiers}
869 test binary-25.2 {Tcl_BinaryObjCmd: scan} {
870 unset -nocomplain arg1
871 list [binary scan \x52\xa3 H* arg1] $arg1
873 test binary-25.3 {Tcl_BinaryObjCmd: scan} {
874 unset -nocomplain arg1
875 list [binary scan \xc2\xa3 H arg1] $arg1
877 test binary-25.4 {Tcl_BinaryObjCmd: scan} {
878 unset -nocomplain arg1
879 list [binary scan \x82\x53 H1 arg1] $arg1
881 test binary-25.5 {Tcl_BinaryObjCmd: scan} {
882 unset -nocomplain arg1
883 list [binary scan \x52\x53 H0 arg1] $arg1
885 test binary-25.6 {Tcl_BinaryObjCmd: scan} {
886 unset -nocomplain arg1
887 list [binary scan \xf2\x53 H2 arg1] $arg1
889 test binary-25.7 {Tcl_BinaryObjCmd: scan} {
890 unset -nocomplain arg1
891 list [binary scan \x52\x53 H3 arg1] $arg1
893 test binary-25.8 {Tcl_BinaryObjCmd: scan} {
894 unset -nocomplain arg1
896 list [binary scan \x52 H3 arg1] $arg1
898 test binary-25.9 {Tcl_BinaryObjCmd: scan} -setup {
899 unset -nocomplain arg1
900 } -returnCodes error -body {
902 binary scan \x52\x53 H1 arg1(a)
903 } -result {can't set "arg1(a)": variable isn't array}
904 test binary-25.10 {Tcl_BinaryObjCmd: scan} {
905 unset -nocomplain arg1 arg2
908 list [binary scan \x70\x87\x05 H2H* arg1 arg2] $arg1 $arg2
911 test binary-26.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
913 } -result {not enough arguments for all format specifiers}
914 test binary-26.2 {Tcl_BinaryObjCmd: scan} {
915 unset -nocomplain arg1
916 list [binary scan \x52\xa3 c* arg1] $arg1
918 test binary-26.3 {Tcl_BinaryObjCmd: scan} {
919 unset -nocomplain arg1
920 list [binary scan \x52\xa3 c arg1] $arg1
922 test binary-26.4 {Tcl_BinaryObjCmd: scan} {
923 unset -nocomplain arg1
924 list [binary scan \x52\xa3 c1 arg1] $arg1
926 test binary-26.5 {Tcl_BinaryObjCmd: scan} {
927 unset -nocomplain arg1
928 list [binary scan \x52\xa3 c0 arg1] $arg1
930 test binary-26.6 {Tcl_BinaryObjCmd: scan} {
931 unset -nocomplain arg1
932 list [binary scan \x52\xa3 c2 arg1] $arg1
934 test binary-26.7 {Tcl_BinaryObjCmd: scan} {
935 unset -nocomplain arg1
936 list [binary scan \xff c arg1] $arg1
938 test binary-26.8 {Tcl_BinaryObjCmd: scan} {
939 unset -nocomplain arg1
941 list [binary scan \x52 c3 arg1] $arg1
943 test binary-26.9 {Tcl_BinaryObjCmd: scan} -setup {
944 unset -nocomplain arg1
945 } -returnCodes error -body {
947 binary scan \x52\x53 c1 arg1(a)
948 } -result {can't set "arg1(a)": variable isn't array}
949 test binary-26.10 {Tcl_BinaryObjCmd: scan} {
950 unset -nocomplain arg1 arg2
953 list [binary scan \x70\x87\x05 c2c* arg1 arg2] $arg1 $arg2
955 test binary-26.11 {Tcl_BinaryObjCmd: scan} {
956 unset -nocomplain arg1
957 list [binary scan \x52\xa3 cu* arg1] $arg1
959 test binary-26.12 {Tcl_BinaryObjCmd: scan} {
960 unset -nocomplain arg1
961 list [binary scan \x52\xa3 cu arg1] $arg1
963 test binary-26.13 {Tcl_BinaryObjCmd: scan} {
964 unset -nocomplain arg1
965 list [binary scan \xff cu arg1] $arg1
967 test binary-26.14 {Tcl_BinaryObjCmd: scan} {
968 unset -nocomplain arg1 arg2
971 list [binary scan \x80\x80 cuc arg1 arg2] $arg1 $arg2
973 test binary-26.15 {Tcl_BinaryObjCmd: scan} {
974 unset -nocomplain arg1 arg2
977 list [binary scan \x80\x80 ccu arg1 arg2] $arg1 $arg2
980 test binary-27.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
982 } -result {not enough arguments for all format specifiers}
983 test binary-27.2 {Tcl_BinaryObjCmd: scan} {
984 unset -nocomplain arg1
985 list [binary scan \x52\xa3\x53\x54 s* arg1] $arg1
987 test binary-27.3 {Tcl_BinaryObjCmd: scan} {
988 unset -nocomplain arg1
989 list [binary scan \x52\xa3\x53\x54 s arg1] $arg1
991 test binary-27.4 {Tcl_BinaryObjCmd: scan} {
992 unset -nocomplain arg1
993 list [binary scan \x52\xa3 s1 arg1] $arg1
995 test binary-27.5 {Tcl_BinaryObjCmd: scan} {
996 unset -nocomplain arg1
997 list [binary scan \x52\xa3 s0 arg1] $arg1
999 test binary-27.6 {Tcl_BinaryObjCmd: scan} {
1000 unset -nocomplain arg1
1001 list [binary scan \x52\xa3\x53\x54 s2 arg1] $arg1
1002 } {1 {-23726 21587}}
1003 test binary-27.7 {Tcl_BinaryObjCmd: scan} {
1004 unset -nocomplain arg1
1006 list [binary scan \x52 s1 arg1] $arg1
1008 test binary-27.8 {Tcl_BinaryObjCmd: scan} -setup {
1009 unset -nocomplain arg1
1010 } -returnCodes error -body {
1012 binary scan \x52\x53 s1 arg1(a)
1013 } -result {can't set "arg1(a)": variable isn't array}
1014 test binary-27.9 {Tcl_BinaryObjCmd: scan} {
1015 unset -nocomplain arg1 arg2
1018 list [binary scan \x52\xa3\x53\x54\x05 s2c* arg1 arg2] $arg1 $arg2
1019 } {2 {-23726 21587} 5}
1020 test binary-27.10 {Tcl_BinaryObjCmd: scan} {
1021 unset -nocomplain arg1
1022 list [binary scan \x52\xa3\x53\x54 su* arg1] $arg1
1024 test binary-27.11 {Tcl_BinaryObjCmd: scan} {
1025 unset -nocomplain arg1 arg2
1028 list [binary scan \xff\xff\xff\xff sus arg1 arg2] $arg1 $arg2
1030 test binary-27.12 {Tcl_BinaryObjCmd: scan} {
1031 unset -nocomplain arg1 arg2
1034 list [binary scan \xff\xff\xff\xff ssu arg1 arg2] $arg1 $arg2
1037 test binary-28.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
1039 } -result {not enough arguments for all format specifiers}
1040 test binary-28.2 {Tcl_BinaryObjCmd: scan} {
1041 unset -nocomplain arg1
1042 list [binary scan \x52\xa3\x53\x54 S* arg1] $arg1
1044 test binary-28.3 {Tcl_BinaryObjCmd: scan} {
1045 unset -nocomplain arg1
1046 list [binary scan \x52\xa3\x53\x54 S arg1] $arg1
1048 test binary-28.4 {Tcl_BinaryObjCmd: scan} {
1049 unset -nocomplain arg1
1050 list [binary scan \x52\xa3 S1 arg1] $arg1
1052 test binary-28.5 {Tcl_BinaryObjCmd: scan} {
1053 unset -nocomplain arg1
1054 list [binary scan \x52\xa3 S0 arg1] $arg1
1056 test binary-28.6 {Tcl_BinaryObjCmd: scan} {
1057 unset -nocomplain arg1
1058 list [binary scan \x52\xa3\x53\x54 S2 arg1] $arg1
1060 test binary-28.7 {Tcl_BinaryObjCmd: scan} {
1061 unset -nocomplain arg1
1063 list [binary scan \x52 S1 arg1] $arg1
1065 test binary-28.8 {Tcl_BinaryObjCmd: scan} -setup {
1066 unset -nocomplain arg1
1067 } -returnCodes error -body {
1069 binary scan \x52\x53 S1 arg1(a)
1070 } -result {can't set "arg1(a)": variable isn't array}
1071 test binary-28.9 {Tcl_BinaryObjCmd: scan} {
1072 unset -nocomplain arg1 arg2
1075 list [binary scan \x52\xa3\x53\x54\x05 S2c* arg1 arg2] $arg1 $arg2
1076 } {2 {21155 21332} 5}
1077 test binary-28.10 {Tcl_BinaryObjCmd: scan} {
1078 unset -nocomplain arg1
1079 list [binary scan \x52\xa3\x53\x54 Su* arg1] $arg1
1081 test binary-28.11 {Tcl_BinaryObjCmd: scan} {
1082 unset -nocomplain arg1
1083 list [binary scan \xa3\x52\x54\x53 Su* arg1] $arg1
1086 test binary-29.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
1088 } -result {not enough arguments for all format specifiers}
1089 test binary-29.2 {Tcl_BinaryObjCmd: scan} {
1090 unset -nocomplain arg1
1091 list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 i* arg1] $arg1
1092 } {1 {1414767442 67305985}}
1093 test binary-29.3 {Tcl_BinaryObjCmd: scan} {
1094 unset -nocomplain arg1
1095 list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 i arg1] $arg1
1097 test binary-29.4 {Tcl_BinaryObjCmd: scan} {
1098 unset -nocomplain arg1
1099 list [binary scan \x52\xa3\x53\x54 i1 arg1] $arg1
1101 test binary-29.5 {Tcl_BinaryObjCmd: scan} {
1102 unset -nocomplain arg1
1103 list [binary scan \x52\xa3\x53 i0 arg1] $arg1
1105 test binary-29.6 {Tcl_BinaryObjCmd: scan} {
1106 unset -nocomplain arg1
1107 list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 i2 arg1] $arg1
1108 } {1 {1414767442 67305985}}
1109 test binary-29.7 {Tcl_BinaryObjCmd: scan} {
1110 unset -nocomplain arg1
1112 list [binary scan \x52 i1 arg1] $arg1
1114 test binary-29.8 {Tcl_BinaryObjCmd: scan} -setup {
1115 unset -nocomplain arg1
1116 } -returnCodes error -body {
1118 binary scan \x52\x53\x53\x54 i1 arg1(a)
1119 } -result {can't set "arg1(a)": variable isn't array}
1120 test binary-29.9 {Tcl_BinaryObjCmd: scan} {
1121 unset -nocomplain arg1 arg2
1124 list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04\x05 i2c* arg1 arg2] $arg1 $arg2
1125 } {2 {1414767442 67305985} 5}
1126 test binary-29.10 {Tcl_BinaryObjCmd: scan} {
1127 unset -nocomplain arg1 arg2
1128 list [binary scan \xff\xff\xff\xff\xff\xff\xff\xff iui arg1 arg2] $arg1 $arg2
1130 test binary-29.11 {Tcl_BinaryObjCmd: scan} {
1131 unset -nocomplain arg1 arg2
1132 list [binary scan \xff\xff\xff\xff\xff\xff\xff\xff iiu arg1 arg2] $arg1 $arg2
1134 test binary-29.12 {Tcl_BinaryObjCmd: scan} {
1135 unset -nocomplain arg1 arg2
1136 list [binary scan \x80\x00\x00\x00\x00\x00\x00\x80 iuiu arg1 arg2] $arg1 $arg2
1137 } {2 128 2147483648}
1139 test binary-30.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
1141 } -result {not enough arguments for all format specifiers}
1142 test binary-30.2 {Tcl_BinaryObjCmd: scan} {
1143 unset -nocomplain arg1
1144 list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 I* arg1] $arg1
1145 } {1 {1386435412 16909060}}
1146 test binary-30.3 {Tcl_BinaryObjCmd: scan} {
1147 unset -nocomplain arg1
1148 list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 I arg1] $arg1
1150 test binary-30.4 {Tcl_BinaryObjCmd: scan} {
1151 unset -nocomplain arg1
1152 list [binary scan \x52\xa3\x53\x54 I1 arg1] $arg1
1154 test binary-30.5 {Tcl_BinaryObjCmd: scan} {
1155 unset -nocomplain arg1
1156 list [binary scan \x52\xa3\x53 I0 arg1] $arg1
1158 test binary-30.6 {Tcl_BinaryObjCmd: scan} {
1159 unset -nocomplain arg1
1160 list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 I2 arg1] $arg1
1161 } {1 {1386435412 16909060}}
1162 test binary-30.7 {Tcl_BinaryObjCmd: scan} {
1163 unset -nocomplain arg1
1165 list [binary scan \x52 I1 arg1] $arg1
1167 test binary-30.8 {Tcl_BinaryObjCmd: scan} -setup {
1168 unset -nocomplain arg1
1169 } -returnCodes error -body {
1171 binary scan \x52\x53\x53\x54 I1 arg1(a)
1172 } -result {can't set "arg1(a)": variable isn't array}
1173 test binary-30.9 {Tcl_BinaryObjCmd: scan} {
1174 unset -nocomplain arg1 arg2
1177 list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04\x05 I2c* arg1 arg2] $arg1 $arg2
1178 } {2 {1386435412 16909060} 5}
1179 test binary-30.10 {Tcl_BinaryObjCmd: scan} {
1180 unset -nocomplain arg1 arg2
1181 list [binary scan \xff\xff\xff\xff\xff\xff\xff\xff IuI arg1 arg2] $arg1 $arg2
1183 test binary-30.11 {Tcl_BinaryObjCmd: scan} {
1184 unset -nocomplain arg1 arg2
1185 list [binary scan \xff\xff\xff\xff\xff\xff\xff\xff IIu arg1 arg2] $arg1 $arg2
1187 test binary-30.12 {Tcl_BinaryObjCmd: scan} {
1188 unset -nocomplain arg1 arg2
1189 list [binary scan \x80\x00\x00\x00\x00\x00\x00\x80 IuIu arg1 arg2] $arg1 $arg2
1190 } {2 2147483648 128}
1192 test binary-31.1 {Tcl_BinaryObjCmd: scan} {
1193 list [catch {binary scan abc f} msg] $msg
1194 } {1 {not enough arguments for all format specifiers}}
1195 # NB: format %.12g in Jim_DoubleToString
1196 # 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
1197 test binary-31.2 {Tcl_BinaryObjCmd: scan} bigEndian {
1199 list [binary scan \x3f\xcc\xcc\xcd\x40\x59\x99\x9a f* arg1] $arg1
1200 } {1 {1.60000002384 3.40000009537}}
1201 test binary-31.3 {Tcl_BinaryObjCmd: scan} littleEndian {
1203 list [binary scan \xcd\xcc\xcc\x3f\x9a\x99\x59\x40 f* arg1] $arg1
1204 } {1 {1.60000002384 3.40000009537}}
1205 test binary-31.4 {Tcl_BinaryObjCmd: scan} bigEndian {
1207 list [binary scan \x3f\xcc\xcc\xcd\x40\x59\x99\x9a f arg1] $arg1
1209 test binary-31.5 {Tcl_BinaryObjCmd: scan} littleEndian {
1211 list [binary scan \xcd\xcc\xcc\x3f\x9a\x99\x59\x40 f arg1] $arg1
1213 test binary-31.6 {Tcl_BinaryObjCmd: scan} bigEndian {
1215 list [binary scan \x3f\xcc\xcc\xcd f1 arg1] $arg1
1217 test binary-31.7 {Tcl_BinaryObjCmd: scan} littleEndian {
1219 list [binary scan \xcd\xcc\xcc\x3f f1 arg1] $arg1
1221 test binary-31.8 {Tcl_BinaryObjCmd: scan} bigEndian {
1223 list [binary scan \x3f\xcc\xcc\xcd f0 arg1] $arg1
1225 test binary-31.9 {Tcl_BinaryObjCmd: scan} littleEndian {
1227 list [binary scan \xcd\xcc\xcc\x3f f0 arg1] $arg1
1229 test binary-31.10 {Tcl_BinaryObjCmd: scan} bigEndian {
1231 list [binary scan \x3f\xcc\xcc\xcd\x40\x59\x99\x9a f2 arg1] $arg1
1232 } {1 {1.60000002384 3.40000009537}}
1233 test binary-31.11 {Tcl_BinaryObjCmd: scan} littleEndian {
1235 list [binary scan \xcd\xcc\xcc\x3f\x9a\x99\x59\x40 f2 arg1] $arg1
1236 } {1 {1.60000002384 3.40000009537}}
1237 test binary-31.12 {Tcl_BinaryObjCmd: scan} {
1240 list [binary scan \x52 f1 arg1] $arg1
1242 test binary-31.13 {Tcl_BinaryObjCmd: scan} {
1245 list [catch {binary scan \x3f\xcc\xcc\xcd f1 arg1(a)} msg] $msg
1246 } {1 {can't set "arg1(a)": variable isn't array}}
1247 test binary-31.14 {Tcl_BinaryObjCmd: scan} bigEndian {
1248 catch {unset arg1 arg2}
1251 list [binary scan \x3f\xcc\xcc\xcd\x40\x59\x99\x9a\x05 f2c* arg1 arg2] $arg1 $arg2
1252 } {2 {1.60000002384 3.40000009537} 5}
1253 test binary-31.15 {Tcl_BinaryObjCmd: scan} littleEndian {
1254 catch {unset arg1 arg2}
1257 list [binary scan \xcd\xcc\xcc\x3f\x9a\x99\x59\x40\x05 f2c* arg1 arg2] $arg1 $arg2
1258 } {2 {1.60000002384 3.40000009537} 5}
1260 test binary-32.1 {Tcl_BinaryObjCmd: scan} {
1261 list [catch {binary scan abc d} msg] $msg
1262 } {1 {not enough arguments for all format specifiers}}
1263 test binary-32.2 {Tcl_BinaryObjCmd: scan} bigEndian {
1265 list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33 d* arg1] $arg1
1267 test binary-32.3 {Tcl_BinaryObjCmd: scan} littleEndian {
1269 list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40 d* arg1] $arg1
1271 test binary-32.4 {Tcl_BinaryObjCmd: scan} bigEndian {
1273 list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33 d arg1] $arg1
1275 test binary-32.5 {Tcl_BinaryObjCmd: scan} littleEndian {
1277 list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40 d arg1] $arg1
1279 test binary-32.6 {Tcl_BinaryObjCmd: scan} bigEndian {
1281 list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a d1 arg1] $arg1
1283 test binary-32.7 {Tcl_BinaryObjCmd: scan} littleEndian {
1285 list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f d1 arg1] $arg1
1287 test binary-32.8 {Tcl_BinaryObjCmd: scan} bigEndian {
1289 list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a d0 arg1] $arg1
1291 test binary-32.9 {Tcl_BinaryObjCmd: scan} littleEndian {
1293 list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f d0 arg1] $arg1
1295 test binary-32.10 {Tcl_BinaryObjCmd: scan} bigEndian {
1297 list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33 d2 arg1] $arg1
1299 test binary-32.11 {Tcl_BinaryObjCmd: scan} littleEndian {
1301 list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40 d2 arg1] $arg1
1303 test binary-32.12 {Tcl_BinaryObjCmd: scan} {
1306 list [binary scan \x52 d1 arg1] $arg1
1308 test binary-32.13 {Tcl_BinaryObjCmd: scan} {
1311 list [catch {binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a d1 arg1(a)} msg] $msg
1312 } {1 {can't set "arg1(a)": variable isn't array}}
1313 test binary-32.14 {Tcl_BinaryObjCmd: scan} bigEndian {
1314 catch {unset arg1 arg2}
1317 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
1319 test binary-32.15 {Tcl_BinaryObjCmd: scan} littleEndian {
1320 catch {unset arg1 arg2}
1323 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
1326 test binary-33.1 {Tcl_BinaryObjCmd: scan} {
1327 unset -nocomplain arg1
1328 unset -nocomplain arg2
1329 list [binary scan abcdefg a2xa3 arg1 arg2] $arg1 $arg2
1331 test binary-33.2 {Tcl_BinaryObjCmd: scan} {
1332 unset -nocomplain arg1
1333 unset -nocomplain arg2
1335 list [binary scan abcdefg a3x*a3 arg1 arg2] $arg1 $arg2
1337 test binary-33.3 {Tcl_BinaryObjCmd: scan} {
1338 unset -nocomplain arg1
1339 unset -nocomplain arg2
1341 list [binary scan abcdefg a3x20a3 arg1 arg2] $arg1 $arg2
1343 test binary-33.4 {Tcl_BinaryObjCmd: scan} {
1344 unset -nocomplain arg1
1345 unset -nocomplain arg2
1347 list [binary scan abc a3x20a3 arg1 arg2] $arg1 $arg2
1349 test binary-33.5 {Tcl_BinaryObjCmd: scan} {
1350 unset -nocomplain arg1
1351 list [binary scan abcdef x1a1 arg1] $arg1
1353 test binary-33.6 {Tcl_BinaryObjCmd: scan} {
1354 unset -nocomplain arg1
1355 list [binary scan abcdef x5a1 arg1] $arg1
1357 test binary-33.7 {Tcl_BinaryObjCmd: scan} {
1358 unset -nocomplain arg1
1359 list [binary scan abcdef x0a1 arg1] $arg1
1362 test binary-34.1 {Tcl_BinaryObjCmd: scan} {
1363 unset -nocomplain arg1
1364 unset -nocomplain arg2
1365 list [binary scan abcdefg a2Xa3 arg1 arg2] $arg1 $arg2
1367 test binary-34.2 {Tcl_BinaryObjCmd: scan} {
1368 unset -nocomplain arg1
1369 unset -nocomplain arg2
1371 list [binary scan abcdefg a3X*a3 arg1 arg2] $arg1 $arg2
1373 test binary-34.3 {Tcl_BinaryObjCmd: scan} {
1374 unset -nocomplain arg1
1375 unset -nocomplain arg2
1377 list [binary scan abcdefg a3X20a3 arg1 arg2] $arg1 $arg2
1379 test binary-34.4 {Tcl_BinaryObjCmd: scan} {
1380 unset -nocomplain arg1
1381 list [binary scan abc X20a3 arg1] $arg1
1383 test binary-34.5 {Tcl_BinaryObjCmd: scan} {
1384 unset -nocomplain arg1
1385 list [binary scan abcdef x*X1a1 arg1] $arg1
1387 test binary-34.6 {Tcl_BinaryObjCmd: scan} {
1388 unset -nocomplain arg1
1389 list [binary scan abcdef x*X5a1 arg1] $arg1
1391 test binary-34.7 {Tcl_BinaryObjCmd: scan} {
1392 unset -nocomplain arg1
1393 list [binary scan abcdef x3X0a1 arg1] $arg1
1396 test binary-35.1 {Tcl_BinaryObjCmd: scan} -setup {
1397 unset -nocomplain arg1
1398 unset -nocomplain arg2
1399 } -returnCodes error -body {
1400 binary scan abcdefg a2@a3 arg1 arg2
1401 } -result {missing count for "@" field specifier}
1402 test binary-35.2 {Tcl_BinaryObjCmd: scan} {
1403 unset -nocomplain arg1
1404 unset -nocomplain arg2
1406 list [binary scan abcdefg a3@*a3 arg1 arg2] $arg1 $arg2
1408 test binary-35.3 {Tcl_BinaryObjCmd: scan} {
1409 unset -nocomplain arg1
1410 unset -nocomplain arg2
1412 list [binary scan abcdefg a3@20a3 arg1 arg2] $arg1 $arg2
1414 test binary-35.4 {Tcl_BinaryObjCmd: scan} {
1415 unset -nocomplain arg1
1416 list [binary scan abcdef @2a3 arg1] $arg1
1418 test binary-35.5 {Tcl_BinaryObjCmd: scan} {
1419 unset -nocomplain arg1
1420 list [binary scan abcdef x*@1a1 arg1] $arg1
1422 test binary-35.6 {Tcl_BinaryObjCmd: scan} {
1423 unset -nocomplain arg1
1424 list [binary scan abcdef x*@0a1 arg1] $arg1
1427 test binary-36.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
1428 binary scan abcdef u0a3
1429 } -result {bad field specifier "u"}
1432 # GetFormatSpec is pretty thoroughly tested above, but there are a few cases
1433 # we should text explicitly
1435 test binary-37.1 {GetFormatSpec: whitespace} {
1436 binary format "a3 a5 a3" foo barblat baz
1438 test binary-37.2 {GetFormatSpec: whitespace} {
1439 binary format " " foo
1441 test binary-37.3 {GetFormatSpec: whitespace} {
1442 binary format " a3" foo
1444 test binary-37.4 {GetFormatSpec: whitespace} {
1445 binary format "" foo
1447 test binary-37.5 {GetFormatSpec: whitespace} {
1448 binary format "" foo
1450 test binary-37.6 {GetFormatSpec: whitespace} {
1451 binary format " a3 " foo
1453 test binary-37.7 {GetFormatSpec: numbers} {
1454 list [catch {binary scan abcdef "x-1" foo} msg] $msg
1455 } {1 {bad field specifier "-"}}
1456 test binary-37.8 {GetFormatSpec: numbers} {
1459 list [binary scan abcdef "a0x3" arg1] $arg1
1461 test binary-37.9 {GetFormatSpec: numbers} {
1462 # test format of neg numbers
1463 # bug report/fix provided by Harald Kirsch
1464 set x [binary format f* {1 -1 2 -2 0}]
1465 binary scan $x f* bla
1467 } {1.0 -1.0 2.0 -2.0 0.0}
1469 test binary-38.1 {FormatNumber: word alignment} {
1470 set x [binary format c1s1 1 1]
1472 test binary-38.2 {FormatNumber: word alignment} {
1473 set x [binary format c1S1 1 1]
1475 test binary-38.3 {FormatNumber: word alignment} {
1476 set x [binary format c1i1 1 1]
1477 } \x01\x01\x00\x00\x00
1478 test binary-38.4 {FormatNumber: word alignment} {
1479 set x [binary format c1I1 1 1]
1480 } \x01\x00\x00\x00\x01
1481 test binary-38.5 {FormatNumber: word alignment} bigEndian {
1482 set x [binary format c1d1 1 1.6]
1483 } \x01\x3f\xf9\x99\x99\x99\x99\x99\x9a
1484 test binary-38.6 {FormatNumber: word alignment} littleEndian {
1485 set x [binary format c1d1 1 1.6]
1486 } \x01\x9a\x99\x99\x99\x99\x99\xf9\x3f
1487 test binary-38.7 {FormatNumber: word alignment} bigEndian {
1488 set x [binary format c1f1 1 1.6]
1489 } \x01\x3f\xcc\xcc\xcd
1490 test binary-38.8 {FormatNumber: word alignment} littleEndian {
1491 set x [binary format c1f1 1 1.6]
1492 } \x01\xcd\xcc\xcc\x3f
1494 test binary-39.1 {ScanNumber: sign extension} {
1496 list [binary scan \x52\xa3 c2 arg1] $arg1
1498 test binary-39.2 {ScanNumber: sign extension} {
1500 list [binary scan \x01\x02\x01\x81\x82\x01\x81\x82 s4 arg1] $arg1
1501 } {1 {513 -32511 386 -32127}}
1502 test binary-39.3 {ScanNumber: sign extension} {
1504 list [binary scan \x01\x02\x01\x81\x82\x01\x81\x82 S4 arg1] $arg1
1505 } {1 {258 385 -32255 -32382}}
1506 test binary-39.4 {ScanNumber: sign extension} {
1508 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
1509 } {1 {33620225 16843137 16876033 25297153 -2130640639}}
1510 test binary-39.5 {ScanNumber: sign extension} {
1512 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
1513 } {1 {16843010 -2130640639 25297153 16876033 16843137}}
1514 test binary-39.6 {ScanNumber: no sign extension} {
1516 list [binary scan \x52\xa3 cu2 arg1] $arg1
1518 test binary-39.7 {ScanNumber: no sign extension} {
1520 list [binary scan \x01\x02\x01\x81\x82\x01\x81\x82 su4 arg1] $arg1
1521 } {1 {513 33025 386 33409}}
1522 test binary-39.8 {ScanNumber: no sign extension} {
1524 list [binary scan \x01\x02\x01\x81\x82\x01\x81\x82 Su4 arg1] $arg1
1525 } {1 {258 385 33281 33154}}
1526 test binary-39.9 {ScanNumber: no sign extension} {
1528 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
1529 } {1 {33620225 16843137 16876033 25297153 2164326657}}
1530 test binary-39.10 {ScanNumber: no sign extension} {
1532 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
1533 } {1 {16843010 2164326657 25297153 16876033 16843137}}
1535 test binary-40.3 {ScanNumber: NaN} -constraints {maxCompatibility} \
1538 list [binary scan \xff\xff\xff\xff f1 arg1] $arg1
1543 test binary-40.4 {ScanNumber: NaN} -constraints {maxCompatibility} \
1546 list [binary scan \xff\xff\xff\xff\xff\xff\xff\xff d arg1] $arg1
1551 test binary-41.1 {ScanNumber: word alignment} {
1552 catch {unset arg1; unset arg2}
1553 list [binary scan \x01\x01\x00 c1s1 arg1 arg2] $arg1 $arg2
1555 test binary-41.2 {ScanNumber: word alignment} {
1556 catch {unset arg1; unset arg2}
1557 list [binary scan \x01\x00\x01 c1S1 arg1 arg2] $arg1 $arg2
1559 test binary-41.3 {ScanNumber: word alignment} {
1560 catch {unset arg1; unset arg2}
1561 list [binary scan \x01\x01\x00\x00\x00 c1i1 arg1 arg2] $arg1 $arg2
1563 test binary-41.4 {ScanNumber: word alignment} {
1564 catch {unset arg1; unset arg2}
1565 list [binary scan \x01\x00\x00\x00\x01 c1I1 arg1 arg2] $arg1 $arg2
1567 test binary-41.5 {ScanNumber: word alignment} bigEndian {
1568 catch {unset arg1; unset arg2}
1569 list [binary scan \x01\x3f\xcc\xcc\xcd c1f1 arg1 arg2] $arg1 $arg2
1570 } {2 1 1.60000002384}
1571 test binary-41.6 {ScanNumber: word alignment} littleEndian {
1572 catch {unset arg1; unset arg2}
1573 list [binary scan \x01\xcd\xcc\xcc\x3f c1f1 arg1 arg2] $arg1 $arg2
1574 } {2 1 1.60000002384}
1575 test binary-41.7 {ScanNumber: word alignment} bigEndian {
1576 catch {unset arg1; unset arg2}
1577 list [binary scan \x01\x3f\xf9\x99\x99\x99\x99\x99\x9a c1d1 arg1 arg2] $arg1 $arg2
1579 test binary-41.8 {ScanNumber: word alignment} littleEndian {
1580 catch {unset arg1; unset arg2}
1581 list [binary scan \x01\x9a\x99\x99\x99\x99\x99\xf9\x3f c1d1 arg1 arg2] $arg1 $arg2
1584 # Test changed in Jim's fashion
1585 test binary-42.1 {Tcl_BinaryObjCmd: bad arguments} -returnCodes error -body {
1587 } -match glob -result {*}
1589 # Wide int (guaranteed at least 64-bit) handling
1590 test binary-43.1 {Tcl_BinaryObjCmd: format wide int} {} {
1591 binary format w 7810179016327718216
1593 test binary-43.2 {Tcl_BinaryObjCmd: format wide int} {} {
1594 binary format W 7810179016327718216
1597 test binary-44.1 {Tcl_BinaryObjCmd: scan wide int} {} {
1598 binary scan HelloTcl W x
1600 } 5216694956358656876
1601 test binary-44.2 {Tcl_BinaryObjCmd: scan wide int} {} {
1602 binary scan lcTolleH w x
1604 } 5216694956358656876
1605 # Changed 44.3, 44.4 as Jim doesn't have 'wide' function
1606 test binary-44.3 {Tcl_BinaryObjCmd: scan wide int with bit 31 set} {} {
1607 binary scan [binary format w [expr {int(3) << 31}]] w x
1610 test binary-44.4 {Tcl_BinaryObjCmd: scan wide int with bit 31 set} {} {
1611 binary scan [binary format W [expr {int(3) << 31}]] W x
1614 test binary-43.5 {Tcl_BinaryObjCmd: scan wide int} {} {
1616 list [binary scan \x80[string repeat \x00 7] W arg1] $arg1
1617 } {1 -9223372036854775808}
1618 # Tests binary-43.6-9 excluded as they transcend Jim's integer range.
1619 test binary-43.6 {Tcl_BinaryObjCmd: scan unsigned wide int} {notImplemented} {
1621 list [binary scan \x80[string repeat \x00 7] Wu arg1] $arg1
1622 } {1 9223372036854775808}
1623 test binary-43.7 {Tcl_BinaryObjCmd: scan unsigned wide int} {notImplemented} {
1625 list [binary scan [string repeat \x00 7]\x80 wu arg1] $arg1
1626 } {1 9223372036854775808}
1627 test binary-43.8 {Tcl_BinaryObjCmd: scan unsigned wide int} {notImplemented} {
1628 catch {unset arg1 arg2}
1629 list [binary scan \x80[string repeat \x00 7]\x80[string repeat \x00 7] WuW arg1 arg2] $arg1 $arg2
1630 } {2 9223372036854775808 -9223372036854775808}
1631 test binary-43.9 {Tcl_BinaryObjCmd: scan unsigned wide int} {notImplemented} {
1632 catch {unset arg1 arg2}
1633 list [binary scan [string repeat \x00 7]\x80[string repeat \x00 7]\x80 wuw arg1 arg2] $arg1 $arg2
1634 } {2 9223372036854775808 -9223372036854775808}
1636 test binary-45.1 {Tcl_BinaryObjCmd: combined wide int handling} {
1637 binary scan [binary format sws 16450 -1 19521] c* x
1639 } {66 64 -1 -1 -1 -1 -1 -1 -1 -1 65 76}
1640 test binary-45.2 {Tcl_BinaryObjCmd: combined wide int handling} {
1641 binary scan [binary format sWs 16450 0x7fffffff 19521] c* x
1643 } {66 64 0 0 0 0 127 -1 -1 -1 65 76}
1645 # NB: tests binary-46.* fail as Jim Tcl doesn't truncate Unicode chars to ISO-8859-1.
1647 test binary-47.1 {Tcl_BinaryObjCmd: number cache reference count handling} {
1648 # This test is only reliable when memory debugging is turned on,
1649 # but without even memory debugging it should still generate the
1650 # expected answers and might therefore still pick up memory corruption
1651 # caused by [Bug 851747].
1652 list [binary scan aba ccc x x x] $x
1656 ### TIP#129: endian specifiers ----
1659 test binary-48.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
1661 } -result {not enough arguments for all format specifiers}
1662 test binary-48.2 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
1663 binary format t blat
1664 } -result {expected integer but got "blat"}
1665 test binary-48.3 {Tcl_BinaryObjCmd: format} {
1666 binary format S0 0x50
1668 test binary-48.4 {Tcl_BinaryObjCmd: format} bigEndian {
1669 binary format t 0x50
1671 test binary-48.5 {Tcl_BinaryObjCmd: format} littleEndian {
1672 binary format t 0x50
1674 test binary-48.6 {Tcl_BinaryObjCmd: format} bigEndian {
1675 binary format t 0x5052
1677 test binary-48.7 {Tcl_BinaryObjCmd: format} littleEndian {
1678 binary format t 0x5052
1680 test binary-48.8 {Tcl_BinaryObjCmd: format} bigEndian {
1681 binary format t 0x505251 0x53
1683 test binary-48.9 {Tcl_BinaryObjCmd: format} littleEndian {
1684 binary format t 0x505251 0x53
1686 test binary-48.10 {Tcl_BinaryObjCmd: format} bigEndian {
1687 binary format t2 {0x50 0x52}
1689 test binary-48.11 {Tcl_BinaryObjCmd: format} littleEndian {
1690 binary format t2 {0x50 0x52}
1692 test binary-48.12 {Tcl_BinaryObjCmd: format} bigEndian {
1693 binary format t* {0x5051 0x52}
1695 test binary-48.13 {Tcl_BinaryObjCmd: format} littleEndian {
1696 binary format t* {0x5051 0x52}
1698 test binary-48.14 {Tcl_BinaryObjCmd: format} bigEndian {
1699 binary format t2 {0x50 0x52 0x53} 0x54
1701 test binary-48.15 {Tcl_BinaryObjCmd: format} littleEndian {
1702 binary format t2 {0x50 0x52 0x53} 0x54
1704 test binary-48.16 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
1705 binary format t2 {0x50}
1706 } -result {number of elements in list does not match count}
1707 test binary-48.17 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
1710 } -result "expected integer but got \"0x50 0x51\""
1711 test binary-48.18 {Tcl_BinaryObjCmd: format} bigEndian {
1715 test binary-48.19 {Tcl_BinaryObjCmd: format} littleEndian {
1721 test binary-49.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
1723 } -result {not enough arguments for all format specifiers}
1724 test binary-49.2 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
1725 binary format n blat
1726 } -result {expected integer but got "blat"}
1727 test binary-49.3 {Tcl_BinaryObjCmd: format} {
1728 binary format n0 0x50
1730 test binary-49.4 {Tcl_BinaryObjCmd: format} littleEndian {
1731 binary format n 0x50
1733 test binary-49.5 {Tcl_BinaryObjCmd: format} littleEndian {
1734 binary format n 0x5052
1736 test binary-49.6 {Tcl_BinaryObjCmd: format} littleEndian {
1737 binary format n 0x505251 0x53
1739 test binary-49.7 {Tcl_BinaryObjCmd: format} littleEndian {
1740 binary format i1 {0x505251 0x53}
1742 test binary-49.8 {Tcl_BinaryObjCmd: format} littleEndian {
1743 binary format n 0x53525150
1745 test binary-49.9 {Tcl_BinaryObjCmd: format} littleEndian {
1746 binary format n2 {0x50 0x52}
1747 } P\x00\x00\x00R\x00\x00\x00
1748 test binary-49.10 {Tcl_BinaryObjCmd: format} littleEndian {
1749 binary format n* {0x50515253 0x52}
1751 test binary-49.11 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
1752 binary format n2 {0x50}
1753 } -result {number of elements in list does not match count}
1754 test binary-49.12 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
1757 } -result "expected integer but got \"0x50 0x51\""
1758 test binary-49.13 {Tcl_BinaryObjCmd: format} littleEndian {
1762 test binary-49.14 {Tcl_BinaryObjCmd: format} bigEndian {
1763 binary format n 0x50
1765 test binary-49.15 {Tcl_BinaryObjCmd: format} bigEndian {
1766 binary format n 0x5052
1768 test binary-49.16 {Tcl_BinaryObjCmd: format} bigEndian {
1769 binary format n 0x505251 0x53
1771 test binary-49.17 {Tcl_BinaryObjCmd: format} bigEndian {
1772 binary format i1 {0x505251 0x53}
1774 test binary-49.18 {Tcl_BinaryObjCmd: format} bigEndian {
1775 binary format n 0x53525150
1777 test binary-49.19 {Tcl_BinaryObjCmd: format} bigEndian {
1778 binary format n2 {0x50 0x52}
1779 } \x00\x00\x00P\x00\x00\x00R
1780 test binary-49.20 {Tcl_BinaryObjCmd: format} bigEndian {
1781 binary format n* {0x50515253 0x52}
1785 test binary-50.1 {Tcl_BinaryObjCmd: format wide int} littleEndian {
1786 binary format m 7810179016327718216
1788 test binary-50.2 {Tcl_BinaryObjCmd: format wide int} bigEndian {
1789 binary format m 7810179016327718216
1792 # Changed 50.3, 50.4 as Jim doesn't have 'wide' function
1793 test binary-50.3 {Tcl_BinaryObjCmd: scan wide int with bit 31 set} littleEndian {
1794 binary scan [binary format m [expr {int(3) << 31}]] w x
1797 test binary-50.4 {Tcl_BinaryObjCmd: scan wide int with bit 31 set} bigEndian {
1798 binary scan [binary format m [expr {int(3) << 31}]] W x
1804 test binary-51.1 {Tcl_BinaryObjCmd: format} {
1805 list [catch {binary format Q} msg] $msg
1806 } {1 {not enough arguments for all format specifiers}}
1807 test binary-51.2 {Tcl_BinaryObjCmd: format} {
1808 list [catch {binary format q blat} msg] $msg
1809 } {1 {expected floating-point number but got "blat"}}
1810 test binary-51.3 {Tcl_BinaryObjCmd: format} {
1811 binary format q0 1.6
1813 test binary-51.4 {Tcl_BinaryObjCmd: format} {} {
1815 } \x3f\xf9\x99\x99\x99\x99\x99\x9a
1816 test binary-51.5 {Tcl_BinaryObjCmd: format} {} {
1818 } \x9a\x99\x99\x99\x99\x99\xf9\x3f
1819 test binary-51.6 {Tcl_BinaryObjCmd: format} {} {
1820 binary format Q* {1.6 3.4}
1821 } \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33
1822 test binary-51.7 {Tcl_BinaryObjCmd: format} {} {
1823 binary format q* {1.6 3.4}
1824 } \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40
1825 test binary-51.8 {Tcl_BinaryObjCmd: format} {} {
1826 binary format Q2 {1.6 3.4}
1827 } \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33
1828 test binary-51.9 {Tcl_BinaryObjCmd: format} {} {
1829 binary format q2 {1.6 3.4}
1830 } \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40
1831 test binary-51.10 {Tcl_BinaryObjCmd: format} {} {
1832 binary format Q2 {1.6 3.4 5.6}
1833 } \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33
1834 test binary-51.11 {Tcl_BinaryObjCmd: format} {} {
1835 binary format q2 {1.6 3.4 5.6}
1836 } \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40
1837 test binary-51.14 {Tcl_BinaryObjCmd: format} {
1838 list [catch {binary format q2 {1.6}} msg] $msg
1839 } {1 {number of elements in list does not match count}}
1840 test binary-51.15 {Tcl_BinaryObjCmd: format} {
1842 list [catch {binary format q $a} msg] $msg
1843 } [list 1 "expected floating-point number but got \"1.6 3.4\""]
1844 test binary-51.16 {Tcl_BinaryObjCmd: format} {} {
1847 } \x3f\xf9\x99\x99\x99\x99\x99\x9a
1848 test binary-51.17 {Tcl_BinaryObjCmd: format} {} {
1851 } \x9a\x99\x99\x99\x99\x99\xf9\x3f
1854 test binary-53.1 {Tcl_BinaryObjCmd: format} {
1855 list [catch {binary format r} msg] $msg
1856 } {1 {not enough arguments for all format specifiers}}
1857 test binary-53.2 {Tcl_BinaryObjCmd: format} {
1858 list [catch {binary format r blat} msg] $msg
1859 } {1 {expected floating-point number but got "blat"}}
1860 test binary-53.3 {Tcl_BinaryObjCmd: format} {
1861 binary format f0 1.6
1863 test binary-53.4 {Tcl_BinaryObjCmd: format} {} {
1866 test binary-53.5 {Tcl_BinaryObjCmd: format} {} {
1869 test binary-53.6 {Tcl_BinaryObjCmd: format} {} {
1870 binary format R* {1.6 3.4}
1871 } \x3f\xcc\xcc\xcd\x40\x59\x99\x9a
1872 test binary-53.7 {Tcl_BinaryObjCmd: format} {} {
1873 binary format r* {1.6 3.4}
1874 } \xcd\xcc\xcc\x3f\x9a\x99\x59\x40
1875 test binary-53.8 {Tcl_BinaryObjCmd: format} {} {
1876 binary format R2 {1.6 3.4}
1877 } \x3f\xcc\xcc\xcd\x40\x59\x99\x9a
1878 test binary-53.9 {Tcl_BinaryObjCmd: format} {} {
1879 binary format r2 {1.6 3.4}
1880 } \xcd\xcc\xcc\x3f\x9a\x99\x59\x40
1881 test binary-53.10 {Tcl_BinaryObjCmd: format} {} {
1882 binary format R2 {1.6 3.4 5.6}
1883 } \x3f\xcc\xcc\xcd\x40\x59\x99\x9a
1884 test binary-53.11 {Tcl_BinaryObjCmd: format} {} {
1885 binary format r2 {1.6 3.4 5.6}
1886 } \xcd\xcc\xcc\x3f\x9a\x99\x59\x40
1887 test binary-53.12 {Tcl_BinaryObjCmd: float overflow} {maxCompatibility} {
1888 binary format R -3.402825e+38
1890 test binary-53.13 {Tcl_BinaryObjCmd: float overflow} {maxCompatibility} {
1891 binary format r -3.402825e+38
1893 test binary-53.14 {Tcl_BinaryObjCmd: float underflow} {} {
1894 binary format R -3.402825e-100
1896 test binary-53.15 {Tcl_BinaryObjCmd: float underflow} {} {
1897 binary format r -3.402825e-100
1899 test binary-53.16 {Tcl_BinaryObjCmd: format} {
1900 list [catch {binary format r2 {1.6}} msg] $msg
1901 } {1 {number of elements in list does not match count}}
1902 test binary-53.17 {Tcl_BinaryObjCmd: format} {
1904 list [catch {binary format r $a} msg] $msg
1905 } [list 1 "expected floating-point number but got \"1.6 3.4\""]
1906 test binary-53.18 {Tcl_BinaryObjCmd: format} {} {
1910 test binary-53.19 {Tcl_BinaryObjCmd: format} {} {
1916 test binary-54.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
1918 } -result {not enough arguments for all format specifiers}
1919 test binary-54.2 {Tcl_BinaryObjCmd: scan} littleEndian {
1920 unset -nocomplain arg1
1921 list [binary scan \x52\xa3\x53\x54 t* arg1] $arg1
1922 } {1 {-23726 21587}}
1923 test binary-54.3 {Tcl_BinaryObjCmd: scan} littleEndian {
1924 unset -nocomplain arg1
1925 list [binary scan \x52\xa3\x53\x54 t arg1] $arg1
1927 test binary-54.4 {Tcl_BinaryObjCmd: scan} littleEndian {
1928 unset -nocomplain arg1
1929 list [binary scan \x52\xa3 t1 arg1] $arg1
1931 test binary-54.5 {Tcl_BinaryObjCmd: scan} littleEndian {
1932 unset -nocomplain arg1
1933 list [binary scan \x52\xa3 t0 arg1] $arg1
1935 test binary-54.6 {Tcl_BinaryObjCmd: scan} littleEndian {
1936 unset -nocomplain arg1
1937 list [binary scan \x52\xa3\x53\x54 t2 arg1] $arg1
1938 } {1 {-23726 21587}}
1939 test binary-54.7 {Tcl_BinaryObjCmd: scan} littleEndian {
1940 unset -nocomplain arg1
1942 list [binary scan \x52 t1 arg1] $arg1
1944 test binary-54.8 {Tcl_BinaryObjCmd: scan} -setup {
1945 unset -nocomplain arg1
1946 } -returnCodes error -body {
1948 binary scan \x52\x53 t1 arg1(a)
1949 } -result {can't set "arg1(a)": variable isn't array}
1950 test binary-54.9 {Tcl_BinaryObjCmd: scan} littleEndian {
1951 unset -nocomplain arg1 arg2
1954 list [binary scan \x52\xa3\x53\x54\x05 t2c* arg1 arg2] $arg1 $arg2
1955 } {2 {-23726 21587} 5}
1956 test binary-54.10 {Tcl_BinaryObjCmd: scan} littleEndian {
1957 unset -nocomplain arg1 arg2
1960 list [binary scan \x00\x80\x00\x80 tut arg1 arg2] $arg1 $arg2
1962 test binary-54.11 {Tcl_BinaryObjCmd: scan} littleEndian {
1963 unset -nocomplain arg1 arg2
1966 list [binary scan \x00\x80\x00\x80 ttu arg1 arg2] $arg1 $arg2
1970 test binary-55.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
1972 } -result {not enough arguments for all format specifiers}
1973 test binary-55.2 {Tcl_BinaryObjCmd: scan} bigEndian {
1974 unset -nocomplain arg1
1975 list [binary scan \x52\xa3\x53\x54 t* arg1] $arg1
1977 test binary-55.3 {Tcl_BinaryObjCmd: scan} bigEndian {
1978 unset -nocomplain arg1
1979 list [binary scan \x52\xa3\x53\x54 t arg1] $arg1
1981 test binary-55.4 {Tcl_BinaryObjCmd: scan} bigEndian {
1982 unset -nocomplain arg1
1983 list [binary scan \x52\xa3 t1 arg1] $arg1
1985 test binary-55.5 {Tcl_BinaryObjCmd: scan} bigEndian {
1986 unset -nocomplain arg1
1987 list [binary scan \x52\xa3 t0 arg1] $arg1
1989 test binary-55.6 {Tcl_BinaryObjCmd: scan} bigEndian {
1990 unset -nocomplain arg1
1991 list [binary scan \x52\xa3\x53\x54 t2 arg1] $arg1
1993 test binary-55.7 {Tcl_BinaryObjCmd: scan} bigEndian {
1994 unset -nocomplain arg1
1996 list [binary scan \x52 t1 arg1] $arg1
1998 test binary-55.8 {Tcl_BinaryObjCmd: scan} -setup {
1999 unset -nocomplain arg1
2000 } -returnCodes error -body {
2002 binary scan \x52\x53 t1 arg1(a)
2003 } -result {can't set "arg1(a)": variable isn't array}
2004 test binary-55.9 {Tcl_BinaryObjCmd: scan} bigEndian {
2005 unset -nocomplain arg1 arg2
2008 list [binary scan \x52\xa3\x53\x54\x05 t2c* arg1 arg2] $arg1 $arg2
2009 } {2 {21155 21332} 5}
2010 test binary-55.10 {Tcl_BinaryObjCmd: scan} bigEndian {
2011 unset -nocomplain arg1 arg2
2014 list [binary scan \x80\x00\x80\x00 tut arg1 arg2] $arg1 $arg2
2016 test binary-55.11 {Tcl_BinaryObjCmd: scan} bigEndian {
2017 unset -nocomplain arg1 arg2
2020 list [binary scan \x80\x00\x80\x00 ttu arg1 arg2] $arg1 $arg2
2024 test binary-56.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
2026 } -result {not enough arguments for all format specifiers}
2027 test binary-56.2 {Tcl_BinaryObjCmd: scan} littleEndian {
2028 unset -nocomplain arg1
2029 list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 n* arg1] $arg1
2030 } {1 {1414767442 67305985}}
2031 test binary-56.3 {Tcl_BinaryObjCmd: scan} littleEndian {
2032 unset -nocomplain arg1
2033 list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 n arg1] $arg1
2035 test binary-56.4 {Tcl_BinaryObjCmd: scan} littleEndian {
2036 unset -nocomplain arg1
2037 list [binary scan \x52\xa3\x53\x54 n1 arg1] $arg1
2039 test binary-56.5 {Tcl_BinaryObjCmd: scan} littleEndian {
2040 unset -nocomplain arg1
2041 list [binary scan \x52\xa3\x53 n0 arg1] $arg1
2043 test binary-56.6 {Tcl_BinaryObjCmd: scan} littleEndian {
2044 unset -nocomplain arg1
2045 list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 n2 arg1] $arg1
2046 } {1 {1414767442 67305985}}
2047 test binary-56.7 {Tcl_BinaryObjCmd: scan} littleEndian {
2048 unset -nocomplain arg1
2050 list [binary scan \x52 n1 arg1] $arg1
2052 test binary-56.8 {Tcl_BinaryObjCmd: scan} -setup {
2053 unset -nocomplain arg1
2054 } -returnCodes error -body {
2056 binary scan \x52\x53\x53\x54 n1 arg1(a)
2057 } -result {can't set "arg1(a)": variable isn't array}
2058 test binary-56.9 {Tcl_BinaryObjCmd: scan} littleEndian {
2059 unset -nocomplain arg1 arg2
2062 list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04\x05 n2c* arg1 arg2] $arg1 $arg2
2063 } {2 {1414767442 67305985} 5}
2064 test binary-56.10 {Tcl_BinaryObjCmd: scan} littleEndian {
2065 unset -nocomplain arg1 arg2
2068 list [binary scan \x80\x00\x00\x00\x80\x00\x00\x00 nun arg1 arg2] $arg1 $arg2
2070 test binary-56.11 {Tcl_BinaryObjCmd: scan} littleEndian {
2071 unset -nocomplain arg1 arg2
2074 list [binary scan \x00\x00\x00\x80\x00\x00\x00\x80 nun arg1 arg2] $arg1 $arg2
2075 } {2 2147483648 -2147483648}
2078 test binary-57.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
2080 } -result {not enough arguments for all format specifiers}
2081 test binary-57.2 {Tcl_BinaryObjCmd: scan} bigEndian {
2082 unset -nocomplain arg1
2083 list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 n* arg1] $arg1
2084 } {1 {1386435412 16909060}}
2085 test binary-57.3 {Tcl_BinaryObjCmd: scan} bigEndian {
2086 unset -nocomplain arg1
2087 list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 n arg1] $arg1
2089 test binary-57.4 {Tcl_BinaryObjCmd: scan} bigEndian {
2090 unset -nocomplain arg1
2091 list [binary scan \x52\xa3\x53\x54 n1 arg1] $arg1
2093 test binary-57.5 {Tcl_BinaryObjCmd: scan} bigEndian {
2094 unset -nocomplain arg1
2095 list [binary scan \x52\xa3\x53 n0 arg1] $arg1
2097 test binary-57.6 {Tcl_BinaryObjCmd: scan} bigEndian {
2098 unset -nocomplain arg1
2099 list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 n2 arg1] $arg1
2100 } {1 {1386435412 16909060}}
2101 test binary-57.7 {Tcl_BinaryObjCmd: scan} bigEndian {
2102 unset -nocomplain arg1
2104 list [binary scan \x52 n1 arg1] $arg1
2106 test binary-57.8 {Tcl_BinaryObjCmd: scan} -setup {
2107 unset -nocomplain arg1
2108 } -returnCodes error -body {
2110 binary scan \x52\x53\x53\x54 n1 arg1(a)
2111 } -result {can't set "arg1(a)": variable isn't array}
2112 test binary-57.9 {Tcl_BinaryObjCmd: scan} bigEndian {
2113 unset -nocomplain arg1 arg2
2116 list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04\x05 n2c* arg1 arg2] $arg1 $arg2
2117 } {2 {1386435412 16909060} 5}
2118 test binary-57.10 {Tcl_BinaryObjCmd: scan} bigEndian {
2119 unset -nocomplain arg1 arg2
2122 list [binary scan \x80\x00\x00\x00\x80\x00\x00\x00 nun arg1 arg2] $arg1 $arg2
2123 } {2 2147483648 -2147483648}
2124 test binary-57.11 {Tcl_BinaryObjCmd: scan} bigEndian {
2125 unset -nocomplain arg1 arg2
2128 list [binary scan \x00\x00\x00\x80\x00\x00\x00\x80 nun arg1 arg2] $arg1 $arg2
2132 test binary-58.1 {Tcl_BinaryObjCmd: scan} {
2133 list [catch {binary scan abc q} msg] $msg
2134 } {1 {not enough arguments for all format specifiers}}
2135 test binary-58.2 {Tcl_BinaryObjCmd: scan} bigEndian {
2137 list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33 Q* arg1] $arg1
2139 test binary-58.3 {Tcl_BinaryObjCmd: scan} littleEndian {
2141 list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40 q* arg1] $arg1
2143 test binary-58.4 {Tcl_BinaryObjCmd: scan} bigEndian {
2145 list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33 Q arg1] $arg1
2147 test binary-58.5 {Tcl_BinaryObjCmd: scan} littleEndian {
2149 list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40 q arg1] $arg1
2151 test binary-58.6 {Tcl_BinaryObjCmd: scan} bigEndian {
2153 list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a Q1 arg1] $arg1
2155 test binary-58.7 {Tcl_BinaryObjCmd: scan} littleEndian {
2157 list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f q1 arg1] $arg1
2159 test binary-58.8 {Tcl_BinaryObjCmd: scan} bigEndian {
2161 list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a Q0 arg1] $arg1
2163 test binary-58.9 {Tcl_BinaryObjCmd: scan} littleEndian {
2165 list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f q0 arg1] $arg1
2167 test binary-58.10 {Tcl_BinaryObjCmd: scan} bigEndian {
2169 list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33 Q2 arg1] $arg1
2171 test binary-58.11 {Tcl_BinaryObjCmd: scan} littleEndian {
2173 list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40 q2 arg1] $arg1
2175 test binary-58.12 {Tcl_BinaryObjCmd: scan} {
2178 list [binary scan \x52 q1 arg1] $arg1
2180 test binary-58.13 {Tcl_BinaryObjCmd: scan} {
2183 list [catch {binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a q1 arg1(a)} msg] $msg
2184 } {1 {can't set "arg1(a)": variable isn't array}}
2185 test binary-58.14 {Tcl_BinaryObjCmd: scan} bigEndian {
2186 catch {unset arg1 arg2}
2189 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
2191 test binary-58.15 {Tcl_BinaryObjCmd: scan} littleEndian {
2192 catch {unset arg1 arg2}
2195 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
2199 test binary-59.1 {Tcl_BinaryObjCmd: scan} {
2200 list [catch {binary scan abc r} msg] $msg
2201 } {1 {not enough arguments for all format specifiers}}
2202 test binary-59.2 {Tcl_BinaryObjCmd: scan} bigEndian {
2204 list [binary scan \x3f\xcc\xcc\xcd\x40\x59\x99\x9a R* arg1] $arg1
2205 } {1 {1.60000002384 3.40000009537}}
2206 test binary-59.3 {Tcl_BinaryObjCmd: scan} littleEndian {
2208 list [binary scan \xcd\xcc\xcc\x3f\x9a\x99\x59\x40 r* arg1] $arg1
2209 } {1 {1.60000002384 3.40000009537}}
2210 test binary-59.4 {Tcl_BinaryObjCmd: scan} bigEndian {
2212 list [binary scan \x3f\xcc\xcc\xcd\x40\x59\x99\x9a R arg1] $arg1
2214 test binary-59.5 {Tcl_BinaryObjCmd: scan} littleEndian {
2216 list [binary scan \xcd\xcc\xcc\x3f\x9a\x99\x59\x40 r arg1] $arg1
2218 test binary-59.6 {Tcl_BinaryObjCmd: scan} bigEndian {
2220 list [binary scan \x3f\xcc\xcc\xcd R1 arg1] $arg1
2222 test binary-59.7 {Tcl_BinaryObjCmd: scan} littleEndian {
2224 list [binary scan \xcd\xcc\xcc\x3f r1 arg1] $arg1
2226 test binary-59.8 {Tcl_BinaryObjCmd: scan} bigEndian {
2228 list [binary scan \x3f\xcc\xcc\xcd R0 arg1] $arg1
2230 test binary-59.9 {Tcl_BinaryObjCmd: scan} littleEndian {
2232 list [binary scan \xcd\xcc\xcc\x3f r0 arg1] $arg1
2234 test binary-59.10 {Tcl_BinaryObjCmd: scan} bigEndian {
2236 list [binary scan \x3f\xcc\xcc\xcd\x40\x59\x99\x9a R2 arg1] $arg1
2237 } {1 {1.60000002384 3.40000009537}}
2238 test binary-59.11 {Tcl_BinaryObjCmd: scan} littleEndian {
2240 list [binary scan \xcd\xcc\xcc\x3f\x9a\x99\x59\x40 r2 arg1] $arg1
2241 } {1 {1.60000002384 3.40000009537}}
2242 test binary-59.12 {Tcl_BinaryObjCmd: scan} {
2245 list [binary scan \x52 r1 arg1] $arg1
2247 test binary-59.13 {Tcl_BinaryObjCmd: scan} {
2250 list [catch {binary scan \x3f\xcc\xcc\xcd r1 arg1(a)} msg] $msg
2251 } {1 {can't set "arg1(a)": variable isn't array}}
2252 test binary-59.14 {Tcl_BinaryObjCmd: scan} bigEndian {
2253 catch {unset arg1 arg2}
2256 list [binary scan \x3f\xcc\xcc\xcd\x40\x59\x99\x9a\x05 R2c* arg1 arg2] $arg1 $arg2
2257 } {2 {1.60000002384 3.40000009537} 5}
2258 test binary-59.15 {Tcl_BinaryObjCmd: scan} littleEndian {
2259 catch {unset arg1 arg2}
2262 list [binary scan \xcd\xcc\xcc\x3f\x9a\x99\x59\x40\x05 r2c* arg1 arg2] $arg1 $arg2
2263 } {2 {1.60000002384 3.40000009537} 5}
2265 test binary-60.1 {[binary format] with NaN} -body {
2266 binary scan [binary format dqQfrR NaN NaN NaN NaN NaN NaN] dqQfrR \
2268 list $v1 $v2 $v3 $v4 $v5 $v6
2269 } -match regexp -result {NaN(\([[:xdigit:]]+\))? NaN(\([[:xdigit:]]+\))? NaN(\([[:xdigit:]]+\))? NaN(\([[:xdigit:]]+\))? NaN(\([[:xdigit:]]+\))? NaN(\([[:xdigit:]]+\))?}
2272 test binary-61.1 {Tcl_BinaryObjCmd: scan wide int} bigEndian {
2273 binary scan HelloTcl m x
2275 } 5216694956358656876
2276 test binary-61.2 {Tcl_BinaryObjCmd: scan wide int} littleEndian {
2277 binary scan lcTolleH m x
2279 } 5216694956358656876
2280 test binary-61.3 {Tcl_BinaryObjCmd: scan wide int with bit 31 set} littleEndian {
2281 binary scan [binary format w [expr {3 << 31}]] m x
2284 test binary-61.4 {Tcl_BinaryObjCmd: scan wide int with bit 31 set} bigEndian {
2285 binary scan [binary format W [expr {3 << 31}]] m x
2289 # Big test for correct ordering of data in [expr]
2292 array set ieeeValues {}
2293 binary scan [binary format dd -1.0 1.0] c* c
2294 switch -exact -- $c {
2295 {0 0 0 0 0 0 -16 -65 0 0 0 0 0 0 -16 63} {
2297 binary scan \x00\x00\x00\x00\x00\x00\xf0\xff d \
2298 ieeeValues(-Infinity)
2299 binary scan \x00\x00\x00\x00\x00\x00\xf0\xbf d \
2301 binary scan \x00\x00\x00\x00\x00\x00\x08\x80 d \
2302 ieeeValues(-Subnormal)
2303 binary scan \x00\x00\x00\x00\x00\x00\x00\x80 d \
2305 binary scan \x00\x00\x00\x00\x00\x00\x00\x00 d \
2307 binary scan \x00\x00\x00\x00\x00\x00\x08\x00 d \
2308 ieeeValues(+Subnormal)
2309 binary scan \x00\x00\x00\x00\x00\x00\xf0\x3f d \
2311 binary scan \x00\x00\x00\x00\x00\x00\xf0\x7f d \
2312 ieeeValues(+Infinity)
2313 binary scan \x00\x00\x00\x00\x00\x00\xf8\x7f d \
2315 set ieeeValues(littleEndian) 1
2318 {-65 -16 0 0 0 0 0 0 63 -16 0 0 0 0 0 0} {
2319 binary scan \xff\xf0\x00\x00\x00\x00\x00\x00 d \
2320 ieeeValues(-Infinity)
2321 binary scan \xbf\xf0\x00\x00\x00\x00\x00\x00 d \
2323 binary scan \x80\x08\x00\x00\x00\x00\x00\x00 d \
2324 ieeeValues(-Subnormal)
2325 binary scan \x80\x00\x00\x00\x00\x00\x00\x00 d \
2327 binary scan \x00\x00\x00\x00\x00\x00\x00\x00 d \
2329 binary scan \x00\x08\x00\x00\x00\x00\x00\x00 d \
2330 ieeeValues(+Subnormal)
2331 binary scan \x3f\xf0\x00\x00\x00\x00\x00\x00 d \
2333 binary scan \x7f\xf0\x00\x00\x00\x00\x00\x00 d \
2334 ieeeValues(+Infinity)
2335 binary scan \x7f\xf8\x00\x00\x00\x00\x00\x00 d \
2337 set ieeeValues(littleEndian) 0
2346 testConstraint ieeeFloatingPoint [testIEEE]
2348 # scan/format infinities
2350 test binary-62.1 {infinity} ieeeFloatingPoint {
2351 binary scan [binary format q Infinity] w w
2353 } 0x7ff0000000000000
2354 test binary-62.2 {infinity} ieeeFloatingPoint {
2355 binary scan [binary format q -Infinity] w w
2357 } 0xfff0000000000000
2358 test binary-62.3 {infinity} ieeeFloatingPoint {
2359 binary scan [binary format q Inf] w w
2361 } 0x7ff0000000000000
2362 test binary-62.4 {infinity} ieeeFloatingPoint {
2363 binary scan [binary format q -Infinity] w w
2365 } 0xfff0000000000000
2366 test binary-62.5 {infinity} ieeeFloatingPoint {
2367 binary scan [binary format w 0x7ff0000000000000] q d
2370 test binary-62.6 {infinity} ieeeFloatingPoint {
2371 binary scan [binary format w 0xfff0000000000000] q d
2375 # scan/format Not-a-Number
2377 test binary-63.1 {NaN} {ieeeFloatingPoint maxCompatibility} {
2378 binary scan [binary format q NaN] w w
2379 format 0x%016lx [expr {$w & 0xfff3ffffffffffff}]
2380 } 0x7ff0000000000000
2381 # Tests binary-63.2-4, 63.5-9, 64.2 excluded.
2382 # Apparently strtod (and Jim) don't have
2383 # advanced NaN-handling facility as Tcl does :)
2384 test binary-63.2 {NaN} {ieeeFloatingPoint notImplemented} {
2385 binary scan [binary format q -NaN] w w
2386 format 0x%016lx [expr {$w & 0xfff3ffffffffffff}]
2387 } 0xfff0000000000000
2388 test binary-63.3 {NaN} {ieeeFloatingPoint notImplemented} {
2389 binary scan [binary format q NaN(3123456789aBc)] w w
2390 format 0x%016lx [expr {$w & 0xfff3ffffffffffff}]
2391 } 0x7ff3123456789abc
2392 test binary-63.4 {NaN} {ieeeFloatingPoint notImplemented} {
2393 binary scan [binary format q {NaN( 3123456789aBc)}] w w
2394 format 0x%016lx [expr {$w & 0xfff3ffffffffffff}]
2395 } 0x7ff3123456789abc
2397 # Make sure TclParseNumber() rejects invalid nan-hex formats [Bug 3402540]
2398 test binary-63.5 {NaN} -constraints {ieeeFloatingPoint} -body {
2399 binary format q Nan(
2400 } -returnCodes error -match glob -result {expected floating-point number*}
2401 test binary-63.6 {NaN} -constraints {ieeeFloatingPoint notImplemented} -body {
2402 binary format q Nan()
2403 } -returnCodes error -match glob -result {expected floating-point number*}
2404 test binary-63.7 {NaN} -constraints {ieeeFloatingPoint notImplemented} -body {
2405 binary format q Nan(g)
2406 } -returnCodes error -match glob -result {expected floating-point number*}
2407 test binary-63.8 {NaN} -constraints {ieeeFloatingPoint notImplemented} -body {
2408 binary format q Nan(1,2)
2409 } -returnCodes error -match glob -result {expected floating-point number*}
2410 test binary-63.9 {NaN} -constraints {ieeeFloatingPoint notImplemented} -body {
2411 binary format q Nan(1234567890abcd)
2412 } -returnCodes error -match glob -result {expected floating-point number*}
2414 test binary-64.1 {NaN} \
2415 -constraints ieeeFloatingPoint \
2417 binary scan [binary format w 0x7ff8000000000000] q d
2420 -match glob -result NaN*
2421 test binary-64.2 {NaN} \
2422 -constraints {ieeeFloatingPoint notImplemented} \
2424 binary scan [binary format w 0x7ff0123456789aBc] q d
2427 -match glob -result NaN(*123456789abc)
2429 # NB: the problem of %.12g format in Jim_DoubleToString
2430 # make these tests meaningless. Excluded 65.1/3/5,7-9.
2432 test binary-65.1 {largest significand} {ieeeFloatingPoint maxCompatibility} {
2433 binary scan [binary format w 0x3fcfffffffffffff] q d
2435 } 0.24999999999999997
2436 test binary-65.2 {smallest significand} ieeeFloatingPoint {
2437 binary scan [binary format w 0x3fd0000000000000] q d
2440 test binary-65.3 {largest significand} {ieeeFloatingPoint maxCompatibility} {
2441 binary scan [binary format w 0x3fdfffffffffffff] q d
2443 } 0.49999999999999994
2444 test binary-65.4 {smallest significand} ieeeFloatingPoint {
2445 binary scan [binary format w 0x3fe0000000000000] q d
2448 test binary-65.5 {largest significand} {ieeeFloatingPoint maxCompatibility} {
2449 binary scan [binary format w 0x3fffffffffffffff] q d
2451 } 1.9999999999999998
2452 test binary-65.6 {smallest significand} ieeeFloatingPoint {
2453 binary scan [binary format w 0x4000000000000000] q d
2456 test binary-65.7 {smallest significand} {ieeeFloatingPoint maxCompatibility} {
2457 binary scan [binary format w 0x434fffffffffffff] q d
2459 } 18014398509481982.0
2460 test binary-65.8 {largest significand} {ieeeFloatingPoint maxCompatibility} {
2461 binary scan [binary format w 0x4350000000000000] q d
2463 } 18014398509481984.0
2464 test binary-65.9 {largest significand} {ieeeFloatingPoint maxCompatibility} {
2465 binary scan [binary format w 0x4350000000000001] q d
2467 } 18014398509481988.0
2469 # Jim-specific test.
2470 # binary scan must return immediately if there's not enough bytes left.
2471 test binary-66.1 {binary scan: not enought bytes} {} {
2472 unset -nocomplain arg1 arg2
2473 binary scan ab is arg1 arg2
2477 ::tcltest::cleanupTests