tcltest: do a better job of cleanup up after tests
[jimtcl.git] / tests / binary.test
blob3ba19707f3bf28dad8d6ea70a07032223a6deb66
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
15 needs cmd binary
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]
25     set buf hellomatt
26     set data $hdr
27     append data $buf
28     string length $data
29 } 11
31 test binary-1.1 {Tcl_BinaryObjCmd: bad args} -body {
32     binary
33 } -returnCodes error -match glob -result {wrong # args: *}
34 test binary-1.2 {Tcl_BinaryObjCmd: bad args} -returnCodes error -body {
35     binary foo
36 } -match glob -result {*}
37 test binary-1.3 {Tcl_BinaryObjCmd: format error} -returnCodes error -body {
38     binary f
39 } -match glob -result {*}
40 test binary-1.4 {Tcl_BinaryObjCmd: format} -body {
41     binary format ""
42 } -result {}
44 test binary-2.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
45     binary format a
46 } -result {not enough arguments for all format specifiers}
47 test binary-2.2 {Tcl_BinaryObjCmd: format} {
48     binary format a0 foo
49 } {}
50 test binary-2.3 {Tcl_BinaryObjCmd: format} {
51     binary format a f
52 } {f}
53 test binary-2.4 {Tcl_BinaryObjCmd: format} {
54     binary format a foo
55 } {f}
56 test binary-2.5 {Tcl_BinaryObjCmd: format} {
57     binary format a3 foo
58 } {foo}
59 test binary-2.6 {Tcl_BinaryObjCmd: format} {
60     binary format a5 foo
61 } foo\x00\x00
62 test binary-2.7 {Tcl_BinaryObjCmd: format} {
63     binary format a*a3 foobarbaz blat
64 } foobarbazbla
65 test binary-2.8 {Tcl_BinaryObjCmd: format} {
66     binary format a*X3a2 foobar x
67 } foox\x00r
69 test binary-3.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
70     binary format A
71 } -result {not enough arguments for all format specifiers}
72 test binary-3.2 {Tcl_BinaryObjCmd: format} {
73     binary format A0 f
74 } {}
75 test binary-3.3 {Tcl_BinaryObjCmd: format} {
76     binary format A f
77 } {f}
78 test binary-3.4 {Tcl_BinaryObjCmd: format} {
79     binary format A foo
80 } {f}
81 test binary-3.5 {Tcl_BinaryObjCmd: format} {
82     binary format A3 foo
83 } {foo}
84 test binary-3.6 {Tcl_BinaryObjCmd: format} {
85     binary format A5 foo
86 } {foo  }
87 test binary-3.7 {Tcl_BinaryObjCmd: format} {
88     binary format A*A3 foobarbaz blat
89 } foobarbazbla
90 test binary-3.8 {Tcl_BinaryObjCmd: format} {
91     binary format A*X3A2 foobar x
92 } {foox r}
94 test binary-4.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
95     binary format B
96 } -result {not enough arguments for all format specifiers}
97 test binary-4.2 {Tcl_BinaryObjCmd: format} {
98     binary format B0 1
99 } {}
100 test binary-4.3 {Tcl_BinaryObjCmd: format} {
101     binary format B 1
102 } \x80
103 test binary-4.4 {Tcl_BinaryObjCmd: format} {
104     binary format B* 010011
105 } \x4c
106 test binary-4.5 {Tcl_BinaryObjCmd: format} {
107     binary format B8 01001101
108 } \x4d
109 test binary-4.6 {Tcl_BinaryObjCmd: format} {
110     binary format A2X2B9 oo 01001101
111 } \x4d\x00
112 test binary-4.7 {Tcl_BinaryObjCmd: format} {
113     binary format B9 010011011010
114 } \x4d\x80
115 test binary-4.8 {Tcl_BinaryObjCmd: format} {
116     binary format B2B3 10 010
117 } \x80\x40
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 {
123     binary format b
124 } -result {not enough arguments for all format specifiers}
125 test binary-5.2 {Tcl_BinaryObjCmd: format} {
126     binary format b0 1
127 } {}
128 test binary-5.3 {Tcl_BinaryObjCmd: format} {
129     binary format b 1
130 } \x01
131 test binary-5.4 {Tcl_BinaryObjCmd: format} {
132     binary format b* 010011
133 } 2
134 test binary-5.5 {Tcl_BinaryObjCmd: format} {
135     binary format b8 01001101
136 } \xb2
137 test binary-5.6 {Tcl_BinaryObjCmd: format} {
138     binary format A2X2b9 oo 01001101
139 } \xb2\x00
140 test binary-5.7 {Tcl_BinaryObjCmd: format} {
141     binary format b9 010011011010
142 } \xb2\x01
143 test binary-5.8 {Tcl_BinaryObjCmd: format} {
144     binary format b17 1
145 } \x01\00\00
146 test binary-5.9 {Tcl_BinaryObjCmd: format} {
147     binary format b2b3 10 010
148 } \x01\x02
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 {
154     binary format h
155 } -result {not enough arguments for all format specifiers}
156 test binary-6.2 {Tcl_BinaryObjCmd: format} {
157     binary format h0 1
158 } {}
159 test binary-6.3 {Tcl_BinaryObjCmd: format} {
160     binary format h 1
161 } \x01
162 test binary-6.4 {Tcl_BinaryObjCmd: format} {
163     binary format h c
164 } \x0c
165 test binary-6.5 {Tcl_BinaryObjCmd: format} {
166     binary format h* baadf00d
167 } \xab\xda\x0f\xd0
168 test binary-6.6 {Tcl_BinaryObjCmd: format} {
169     binary format h4 c410
170 } \x4c\x01
171 test binary-6.7 {Tcl_BinaryObjCmd: format} {
172     binary format h6 c4102
173 } \x4c\x01\x02
174 test binary-6.8 {Tcl_BinaryObjCmd: format} {
175     binary format h5 c41020304
176 } \x4c\x01\x02
177 test binary-6.9 {Tcl_BinaryObjCmd: format} {
178     binary format a3X3h5 foo 2
179 } \x02\x00\x00
180 test binary-6.10 {Tcl_BinaryObjCmd: format} {
181     binary format h2h3 23 456
182 } \x32\x54\x06
183 test binary-6.11 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
184     binary format h2 foo
185 } -match glob -result {expected *}
187 test binary-7.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
188     binary format H
189 } -result {not enough arguments for all format specifiers}
190 test binary-7.2 {Tcl_BinaryObjCmd: format} {
191     binary format H0 1
192 } {}
193 test binary-7.3 {Tcl_BinaryObjCmd: format} {
194     binary format H 1
195 } \x10
196 test binary-7.4 {Tcl_BinaryObjCmd: format} {
197     binary format H c
198 } \xc0
199 test binary-7.5 {Tcl_BinaryObjCmd: format} {
200     binary format H* baadf00d
201 } \xba\xad\xf0\x0d
202 test binary-7.6 {Tcl_BinaryObjCmd: format} {
203     binary format H4 c410
204 } \xc4\x10
205 test binary-7.7 {Tcl_BinaryObjCmd: format} {
206     binary format H6 c4102
207 } \xc4\x10\x20
208 test binary-7.8 {Tcl_BinaryObjCmd: format} {
209     binary format H5 c41023304
210 } \xc4\x10\x20
211 test binary-7.9 {Tcl_BinaryObjCmd: format} {
212     binary format a3X3H5 foo 2
213 } \x20\x00\x00
214 test binary-7.10 {Tcl_BinaryObjCmd: format} {
215     binary format H2H3 23 456
216 } \x23\x45\x60
217 test binary-7.11 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
218     binary format H2 foo
219 } -match glob -result {expected *}
221 test binary-8.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
222     binary format c
223 } -result {not enough arguments for all format specifiers}
224 test binary-8.2 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
225     binary format c blat
226 } -match glob -result {expected *}
227 test binary-8.3 {Tcl_BinaryObjCmd: format} {
228     binary format c0 0x50
229 } {}
230 test binary-8.4 {Tcl_BinaryObjCmd: format} {
231     binary format c 0x50
232 } P
233 test binary-8.5 {Tcl_BinaryObjCmd: format} {
234     binary format c 0x5052
235 } R
236 test binary-8.6 {Tcl_BinaryObjCmd: format} {
237     binary format c2 {0x50 0x52}
238 } PR
239 test binary-8.7 {Tcl_BinaryObjCmd: format} {
240     binary format c2 {0x50 0x52 0x53}
241 } PR
242 test binary-8.8 {Tcl_BinaryObjCmd: format} {
243     binary format c* {0x50 0x52}
244 } PR
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 {
249     set a {0x50 0x51}
250     binary format c $a
251 } -result "expected integer but got \"0x50 0x51\""
252 test binary-8.11 {Tcl_BinaryObjCmd: format} {
253     set a {0x50 0x51}
254     binary format c1 $a
255 } P
257 test binary-9.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
258     binary format s
259 } -result {not enough arguments for all format specifiers}
260 test binary-9.2 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
261     binary format s blat
262 } -result {expected integer but got "blat"}
263 test binary-9.3 {Tcl_BinaryObjCmd: format} {
264     binary format s0 0x50
265 } {}
266 test binary-9.4 {Tcl_BinaryObjCmd: format} {
267     binary format s 0x50
268 } P\x00
269 test binary-9.5 {Tcl_BinaryObjCmd: format} {
270     binary format s 0x5052
271 } RP
272 test binary-9.6 {Tcl_BinaryObjCmd: format} {
273     binary format s 0x505251 0x53
274 } QR
275 test binary-9.7 {Tcl_BinaryObjCmd: format} {
276     binary format s2 {0x50 0x52}
277 } P\x00R\x00
278 test binary-9.8 {Tcl_BinaryObjCmd: format} {
279     binary format s* {0x5051 0x52}
280 } QPR\x00
281 test binary-9.9 {Tcl_BinaryObjCmd: format} {
282     binary format s2 {0x50 0x52 0x53} 0x54
283 } P\x00R\x00
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 {
288     set a {0x50 0x51}
289     binary format s $a
290 } -result "expected integer but got \"0x50 0x51\""
291 test binary-9.12 {Tcl_BinaryObjCmd: format} {
292     set a {0x50 0x51}
293     binary format s1 $a
294 } P\x00
296 test binary-10.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
297     binary format S
298 } -result {not enough arguments for all format specifiers}
299 test binary-10.2 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
300     binary format S blat
301 } -result {expected integer but got "blat"}
302 test binary-10.3 {Tcl_BinaryObjCmd: format} {
303     binary format S0 0x50
304 } {}
305 test binary-10.4 {Tcl_BinaryObjCmd: format} {
306     binary format S 0x50
307 } \x00P
308 test binary-10.5 {Tcl_BinaryObjCmd: format} {
309     binary format S 0x5052
310 } PR
311 test binary-10.6 {Tcl_BinaryObjCmd: format} {
312     binary format S 0x505251 0x53
313 } RQ
314 test binary-10.7 {Tcl_BinaryObjCmd: format} {
315     binary format S2 {0x50 0x52}
316 } \x00P\x00R
317 test binary-10.8 {Tcl_BinaryObjCmd: format} {
318     binary format S* {0x5051 0x52}
319 } PQ\x00R
320 test binary-10.9 {Tcl_BinaryObjCmd: format} {
321     binary format S2 {0x50 0x52 0x53} 0x54
322 } \x00P\x00R
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 {
327     set a {0x50 0x51}
328     binary format S $a
329 } -result "expected integer but got \"0x50 0x51\""
330 test binary-10.12 {Tcl_BinaryObjCmd: format} {
331     set a {0x50 0x51}
332     binary format S1 $a
333 } \x00P
335 test binary-11.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
336     binary format i
337 } -result {not enough arguments for all format specifiers}
338 test binary-11.2 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
339     binary format i blat
340 } -result {expected integer but got "blat"}
341 test binary-11.3 {Tcl_BinaryObjCmd: format} {
342     binary format i0 0x50
343 } {}
344 test binary-11.4 {Tcl_BinaryObjCmd: format} {
345     binary format i 0x50
346 } P\x00\x00\x00
347 test binary-11.5 {Tcl_BinaryObjCmd: format} {
348     binary format i 0x5052
349 } RP\x00\x00
350 test binary-11.6 {Tcl_BinaryObjCmd: format} {
351     binary format i 0x505251 0x53
352 } QRP\x00
353 test binary-11.7 {Tcl_BinaryObjCmd: format} {
354     binary format i1 {0x505251 0x53}
355 } QRP\x00
356 test binary-11.8 {Tcl_BinaryObjCmd: format} {
357     binary format i 0x53525150
358 } PQRS
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}
364 } SRQPR\x00\x00\x00
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 {
369     set a {0x50 0x51}
370     binary format i $a
371 } -result "expected integer but got \"0x50 0x51\""
372 test binary-11.13 {Tcl_BinaryObjCmd: format} {
373     set a {0x50 0x51}
374     binary format i1 $a
375 } P\x00\x00\x00
377 test binary-12.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
378     binary format I
379 } -result {not enough arguments for all format specifiers}
380 test binary-12.2 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
381     binary format I blat
382 } -result {expected integer but got "blat"}
383 test binary-12.3 {Tcl_BinaryObjCmd: format} {
384     binary format I0 0x50
385 } {}
386 test binary-12.4 {Tcl_BinaryObjCmd: format} {
387     binary format I 0x50
388 } \x00\x00\x00P
389 test binary-12.5 {Tcl_BinaryObjCmd: format} {
390     binary format I 0x5052
391 } \x00\x00PR
392 test binary-12.6 {Tcl_BinaryObjCmd: format} {
393     binary format I 0x505251 0x53
394 } \x00PRQ
395 test binary-12.7 {Tcl_BinaryObjCmd: format} {
396     binary format I1 {0x505251 0x53}
397 } \x00PRQ
398 test binary-12.8 {Tcl_BinaryObjCmd: format} {
399     binary format I 0x53525150
400 } SRQP
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}
406 } PQRS\x00\x00\x00R
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 {
411     set a {0x50 0x51}
412     binary format I $a
413 } -result "expected integer but got \"0x50 0x51\""
414 test binary-12.13 {Tcl_BinaryObjCmd: format} {
415     set a {0x50 0x51}
416     binary format I1 $a
417 } \x00\x00\x00P
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} {
426     binary format f0 1.6
427 } {}
428 test binary-13.4 {Tcl_BinaryObjCmd: format} bigEndian {
429     binary format f 1.6
430 } \x3f\xcc\xcc\xcd
431 test binary-13.5 {Tcl_BinaryObjCmd: format} littleEndian {
432     binary format f 1.6
433 } \xcd\xcc\xcc\x3f
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
454 } \xff\x7f\xff\xff
455 test binary-13.13 {Tcl_BinaryObjCmd: float overflow} {littleEndian maxCompatibility} {
456     binary format f -3.402825e+38
457 } \xff\xff\x7f\xff
458 test binary-13.14 {Tcl_BinaryObjCmd: float underflow} bigEndian {
459     binary format f -3.402825e-100
460 } \x80\x00\x00\x00
461 test binary-13.15 {Tcl_BinaryObjCmd: float underflow} littleEndian {
462     binary format f -3.402825e-100
463 } \x00\x00\x00\x80
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} {
468     set a {1.6 3.4}
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 {
472     set a {1.6 3.4}
473     binary format f1 $a
474 } \x3f\xcc\xcc\xcd
475 test binary-13.19 {Tcl_BinaryObjCmd: format} littleEndian {
476     set a {1.6 3.4}
477     binary format f1 $a
478 } \xcd\xcc\xcc\x3f
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} {
487     binary format d0 1.6
488 } {}
489 test binary-14.4 {Tcl_BinaryObjCmd: format} bigEndian {
490     binary format d 1.6
491 } \x3f\xf9\x99\x99\x99\x99\x99\x9a
492 test binary-14.5 {Tcl_BinaryObjCmd: format} littleEndian {
493     binary format d 1.6
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} {
517     set a {1.6 3.4}
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 {
521     set a {1.6 3.4}
522     binary format d1 $a
523 } \x3f\xf9\x99\x99\x99\x99\x99\x9a
524 test binary-14.17 {Tcl_BinaryObjCmd: format} littleEndian {
525     set a {1.6 3.4}
526     binary format d1 $a
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
530     set w
531 } 1.25
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"
538 } y\x00z
539 test binary-15.3 {Tcl_BinaryObjCmd: format} {
540     binary format ax3a "y" "z"
541 } y\x00\x00\x00z
542 test binary-15.4 {Tcl_BinaryObjCmd: format} {
543     binary format a*X3x3a* "foo" "z"
544 } \x00\x00\x00z
545 test binary-15.5 {Tcl_BinaryObjCmd: format - bug #1923966} {
546     binary format x0s 1
547 } \x01\x00
548 test binary-15.6 {Tcl_BinaryObjCmd: format - bug #1923966} {
549     binary format x0ss 1 1
550 } \x01\x00\x01\x00
551 test binary-15.7 {Tcl_BinaryObjCmd: format - bug #1923966} {
552     binary format x1s 1
553 } \x00\x01\x00
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"
560 } zoo
561 test binary-16.2 {Tcl_BinaryObjCmd: format} {
562     binary format aX3a "y" "z"
563 } z
564 test binary-16.3 {Tcl_BinaryObjCmd: format} {
565     binary format a*Xa* "foo" "zy"
566 } fozy
567 test binary-16.4 {Tcl_BinaryObjCmd: format} {
568     binary format a*X3a "foobar" "z"
569 } foozar
570 test binary-16.5 {Tcl_BinaryObjCmd: format} {
571     binary format a*X3aX2a "foobar" "z" "b"
572 } fobzar
574 test binary-17.1 {Tcl_BinaryObjCmd: format} {
575     binary format @1
576 } \x00
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"
582 } abobarblat
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 {
589     binary s
590 } -match glob -result {*}
591 test binary-19.2 {Tcl_BinaryObjCmd: errors} -returnCodes error -body {
592     binary scan foo
593 } -result {wrong # args: should be "binary scan value formatString ?varName ...?"}
594 test binary-19.3 {Tcl_BinaryObjCmd: scan} {
595     binary scan {} {}
596 } 0
598 test binary-20.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
599     binary scan abc a
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 {
604     set arg1 1
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
609 } -body {
610     set arg1 abc
611     list [binary scan abc a0 arg1] $arg1
612 } -result {1 {}}
613 test binary-20.4 {Tcl_BinaryObjCmd: scan} -setup {
614     unset -nocomplain arg1
615 } -body {
616     list [binary scan abc a* arg1] $arg1
617 } -result {1 abc}
618 test binary-20.5 {Tcl_BinaryObjCmd: scan} -setup {
619     unset -nocomplain arg1
620 } -body {
621     list [binary scan abc a5 arg1] [info exists arg1]
622 } -result {0 0}
623 test binary-20.6 {Tcl_BinaryObjCmd: scan} {
624     set arg1 foo
625     list [binary scan abc a2 arg1] $arg1
626 } {1 ab}
627 test binary-20.7 {Tcl_BinaryObjCmd: scan} -setup {
628     unset -nocomplain arg1
629     unset -nocomplain arg2
630 } -body {
631     list [binary scan abcdef a2a2 arg1 arg2] $arg1 $arg2
632 } -result {2 ab cd}
633 test binary-20.8 {Tcl_BinaryObjCmd: scan} -setup {
634     unset -nocomplain arg1
635 } -body {
636     list [binary scan abc a2 arg1(a)] $arg1(a)
637 } -result {1 ab}
638 test binary-20.9 {Tcl_BinaryObjCmd: scan} -setup {
639     unset -nocomplain arg1
640 } -body {
641     list [binary scan abc a arg1(a)] $arg1(a)
642 } -result {1 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
647 } -body {
648     list [binary scan abc a5a2 arg1 arg2] [info exists arg1] [info exists arg2]
649 } -result {0 0 0}
651 test binary-21.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
652     binary scan abc A
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 {
657     set arg1 1
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
662 } -body {
663     set arg1 abc
664     list [binary scan abc A0 arg1] $arg1
665 } -result {1 {}}
666 test binary-21.4 {Tcl_BinaryObjCmd: scan} -setup {
667     unset -nocomplain arg1
668 } -body {
669     list [binary scan abc A* arg1] $arg1
670 } -result {1 abc}
671 test binary-21.5 {Tcl_BinaryObjCmd: scan} -setup {
672     unset -nocomplain arg1
673 } -body {
674     list [binary scan abc A5 arg1] [info exists arg1]
675 } -result {0 0}
676 test binary-21.6 {Tcl_BinaryObjCmd: scan} {
677     set arg1 foo
678     list [binary scan abc A2 arg1] $arg1
679 } {1 ab}
680 test binary-21.7 {Tcl_BinaryObjCmd: scan} -setup {
681     unset -nocomplain arg1
682     unset -nocomplain arg2
683 } -body {
684     list [binary scan abcdef A2A2 arg1 arg2] $arg1 $arg2
685 } -result {2 ab cd}
686 test binary-21.8 {Tcl_BinaryObjCmd: scan} -setup {
687     unset -nocomplain arg1
688 } -body {
689     list [binary scan abc A2 arg1(a)] $arg1(a)
690 } -result {1 ab}
691 test binary-21.9 {Tcl_BinaryObjCmd: scan} -setup {
692     unset -nocomplain arg1
693 } -body {
694     list [binary scan abc A2 arg1(a)] $arg1(a)
695 } -result {1 ab}
696 test binary-21.10 {Tcl_BinaryObjCmd: scan} -setup {
697     unset -nocomplain arg1
698 } -body {
699     list [binary scan abc A arg1(a)] $arg1(a)
700 } -result {1 a}
701 test binary-21.11 {Tcl_BinaryObjCmd: scan} -setup {
702     unset -nocomplain arg1
703 } -body {
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
708 } -body {
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 {
713     binary scan abc b
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
722 } {1 0}
723 test binary-22.4 {Tcl_BinaryObjCmd: scan} {
724     unset -nocomplain arg1
725     list [binary scan \x82\x53 b1 arg1] $arg1
726 } {1 0}
727 test binary-22.5 {Tcl_BinaryObjCmd: scan} {
728     unset -nocomplain arg1
729     list [binary scan \x82\x53 b0 arg1] $arg1
730 } {1 {}}
731 test binary-22.6 {Tcl_BinaryObjCmd: scan} {
732     unset -nocomplain arg1
733     list [binary scan \x52\x53 b5 arg1] $arg1
734 } {1 01001}
735 test binary-22.7 {Tcl_BinaryObjCmd: scan} {
736     unset -nocomplain arg1
737     list [binary scan \x52\x53 b8 arg1] $arg1
738 } {1 01001010}
739 test binary-22.8 {Tcl_BinaryObjCmd: scan} {
740     unset -nocomplain arg1
741     list [binary scan \x52\x53 b14 arg1] $arg1
742 } {1 01001010110010}
743 test binary-22.9 {Tcl_BinaryObjCmd: scan} {
744     unset -nocomplain arg1
745     set arg1 foo
746     list [binary scan \x52 b14 arg1] $arg1
747 } {0 foo}
748 test binary-22.10 {Tcl_BinaryObjCmd: scan} -setup {
749     unset -nocomplain arg1
750 } -returnCodes error -body {
751     set arg1 1
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
756 } -body {
757     set arg1 foo
758     set arg2 bar
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
765     set arg1 foo
766     set arg2 bar
767     list [binary scan \x52 b14b8 arg1 arg2] $arg1 $arg2
768 } {0 foo bar}
770 test binary-23.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
771     binary scan abc B
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
780 } {1 1}
781 test binary-23.4 {Tcl_BinaryObjCmd: scan} {
782     unset -nocomplain arg1
783     list [binary scan \x82\x53 B1 arg1] $arg1
784 } {1 1}
785 test binary-23.5 {Tcl_BinaryObjCmd: scan} {
786     unset -nocomplain arg1
787     list [binary scan \x52\x53 B0 arg1] $arg1
788 } {1 {}}
789 test binary-23.6 {Tcl_BinaryObjCmd: scan} {
790     unset -nocomplain arg1
791     list [binary scan \x52\x53 B5 arg1] $arg1
792 } {1 01010}
793 test binary-23.7 {Tcl_BinaryObjCmd: scan} {
794     unset -nocomplain arg1
795     list [binary scan \x52\x53 B8 arg1] $arg1
796 } {1 01010010}
797 test binary-23.8 {Tcl_BinaryObjCmd: scan} {
798     unset -nocomplain arg1
799     list [binary scan \x52\x53 B14 arg1] $arg1
800 } {1 01010010010100}
801 test binary-23.9 {Tcl_BinaryObjCmd: scan} {
802     unset -nocomplain arg1
803     set arg1 foo
804     list [binary scan \x52 B14 arg1] $arg1
805 } {0 foo}
806 test binary-23.10 {Tcl_BinaryObjCmd: scan} -setup {
807     unset -nocomplain arg1
808 } -returnCodes error -body {
809     set arg1 1
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
814 } -body {
815     set arg1 foo
816     set arg2 bar
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 {
821     binary scan abc h
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
826 } {1 253a}
827 test binary-24.3 {Tcl_BinaryObjCmd: scan} {
828     unset -nocomplain arg1
829     list [binary scan \xc2\xa3 h arg1] $arg1
830 } {1 2}
831 test binary-24.4 {Tcl_BinaryObjCmd: scan} {
832     unset -nocomplain arg1
833     list [binary scan \x82\x53 h1 arg1] $arg1
834 } {1 2}
835 test binary-24.5 {Tcl_BinaryObjCmd: scan} {
836     unset -nocomplain arg1
837     list [binary scan \x52\x53 h0 arg1] $arg1
838 } {1 {}}
839 test binary-24.6 {Tcl_BinaryObjCmd: scan} {
840     unset -nocomplain arg1
841     list [binary scan \xf2\x53 h2 arg1] $arg1
842 } {1 2f}
843 test binary-24.7 {Tcl_BinaryObjCmd: scan} {
844     unset -nocomplain arg1
845     list [binary scan \x52\x53 h3 arg1] $arg1
846 } {1 253}
847 test binary-24.8 {Tcl_BinaryObjCmd: scan} {
848     unset -nocomplain arg1
849     set arg1 foo
850     list [binary scan \x52 h3 arg1] $arg1
851 } {0 foo}
852 test binary-24.9 {Tcl_BinaryObjCmd: scan} -setup {
853     unset -nocomplain arg1
854 } -returnCodes error -body {
855     set arg1 1
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
860 } -body {
861     set arg1 foo
862     set arg2 bar
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 {
867     binary scan abc H
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
872 } {1 52a3}
873 test binary-25.3 {Tcl_BinaryObjCmd: scan} {
874     unset -nocomplain arg1
875     list [binary scan \xc2\xa3 H arg1] $arg1
876 } {1 c}
877 test binary-25.4 {Tcl_BinaryObjCmd: scan} {
878     unset -nocomplain arg1
879     list [binary scan \x82\x53 H1 arg1] $arg1
880 } {1 8}
881 test binary-25.5 {Tcl_BinaryObjCmd: scan} {
882     unset -nocomplain arg1
883     list [binary scan \x52\x53 H0 arg1] $arg1
884 } {1 {}}
885 test binary-25.6 {Tcl_BinaryObjCmd: scan} {
886     unset -nocomplain arg1
887     list [binary scan \xf2\x53 H2 arg1] $arg1
888 } {1 f2}
889 test binary-25.7 {Tcl_BinaryObjCmd: scan} {
890     unset -nocomplain arg1
891     list [binary scan \x52\x53 H3 arg1] $arg1
892 } {1 525}
893 test binary-25.8 {Tcl_BinaryObjCmd: scan} {
894     unset -nocomplain arg1
895     set arg1 foo
896     list [binary scan \x52 H3 arg1] $arg1
897 } {0 foo}
898 test binary-25.9 {Tcl_BinaryObjCmd: scan} -setup {
899     unset -nocomplain arg1
900 } -returnCodes error -body {
901     set arg1 1
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
906     set arg1 foo
907     set arg2 bar
908     list [binary scan \x70\x87\x05 H2H* arg1 arg2] $arg1 $arg2
909 } {2 70 8705}
911 test binary-26.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
912     binary scan abc c
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
917 } {1 {82 -93}}
918 test binary-26.3 {Tcl_BinaryObjCmd: scan} {
919     unset -nocomplain arg1
920     list [binary scan \x52\xa3 c arg1] $arg1
921 } {1 82}
922 test binary-26.4 {Tcl_BinaryObjCmd: scan} {
923     unset -nocomplain arg1
924     list [binary scan \x52\xa3 c1 arg1] $arg1
925 } {1 82}
926 test binary-26.5 {Tcl_BinaryObjCmd: scan} {
927     unset -nocomplain arg1
928     list [binary scan \x52\xa3 c0 arg1] $arg1
929 } {1 {}}
930 test binary-26.6 {Tcl_BinaryObjCmd: scan} {
931     unset -nocomplain arg1
932     list [binary scan \x52\xa3 c2 arg1] $arg1
933 } {1 {82 -93}}
934 test binary-26.7 {Tcl_BinaryObjCmd: scan} {
935     unset -nocomplain arg1
936     list [binary scan \xff c arg1] $arg1
937 } {1 -1}
938 test binary-26.8 {Tcl_BinaryObjCmd: scan} {
939     unset -nocomplain arg1
940     set arg1 foo
941     list [binary scan \x52 c3 arg1] $arg1
942 } {0 foo}
943 test binary-26.9 {Tcl_BinaryObjCmd: scan} -setup {
944     unset -nocomplain arg1
945 } -returnCodes error -body {
946     set arg1 1
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
951     set arg1 foo
952     set arg2 bar
953     list [binary scan \x70\x87\x05 c2c* arg1 arg2] $arg1 $arg2
954 } {2 {112 -121} 5}
955 test binary-26.11 {Tcl_BinaryObjCmd: scan} {
956     unset -nocomplain arg1
957     list [binary scan \x52\xa3 cu* arg1] $arg1
958 } {1 {82 163}}
959 test binary-26.12 {Tcl_BinaryObjCmd: scan} {
960     unset -nocomplain arg1
961     list [binary scan \x52\xa3 cu arg1] $arg1
962 } {1 82}
963 test binary-26.13 {Tcl_BinaryObjCmd: scan} {
964     unset -nocomplain arg1
965     list [binary scan \xff cu arg1] $arg1
966 } {1 255}
967 test binary-26.14 {Tcl_BinaryObjCmd: scan} {
968     unset -nocomplain arg1 arg2
969     set arg1 foo
970     set arg2 bar
971     list [binary scan \x80\x80 cuc arg1 arg2] $arg1 $arg2
972 } {2 128 -128}
973 test binary-26.15 {Tcl_BinaryObjCmd: scan} {
974     unset -nocomplain arg1 arg2
975     set arg1 foo
976     set arg2 bar
977     list [binary scan \x80\x80 ccu arg1 arg2] $arg1 $arg2
978 } {2 -128 128}
980 test binary-27.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
981     binary scan abc s
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
986 } {1 {-23726 21587}}
987 test binary-27.3 {Tcl_BinaryObjCmd: scan} {
988     unset -nocomplain arg1
989     list [binary scan \x52\xa3\x53\x54 s arg1] $arg1
990 } {1 -23726}
991 test binary-27.4 {Tcl_BinaryObjCmd: scan} {
992     unset -nocomplain arg1
993     list [binary scan \x52\xa3 s1 arg1] $arg1
994 } {1 -23726}
995 test binary-27.5 {Tcl_BinaryObjCmd: scan} {
996     unset -nocomplain arg1
997     list [binary scan \x52\xa3 s0 arg1] $arg1
998 } {1 {}}
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
1005     set arg1 foo
1006     list [binary scan \x52 s1 arg1] $arg1
1007 } {0 foo}
1008 test binary-27.8 {Tcl_BinaryObjCmd: scan} -setup {
1009     unset -nocomplain arg1
1010 } -returnCodes error -body {
1011     set arg1 1
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
1016     set arg1 foo
1017     set arg2 bar
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
1023 } {1 {41810 21587}}
1024 test binary-27.11 {Tcl_BinaryObjCmd: scan} {
1025     unset -nocomplain arg1 arg2
1026     set arg1 foo
1027     set arg2 bar
1028     list [binary scan \xff\xff\xff\xff sus arg1 arg2] $arg1 $arg2
1029 } {2 65535 -1}
1030 test binary-27.12 {Tcl_BinaryObjCmd: scan} {
1031     unset -nocomplain arg1 arg2
1032     set arg1 foo
1033     set arg2 bar
1034     list [binary scan \xff\xff\xff\xff ssu arg1 arg2] $arg1 $arg2
1035 } {2 -1 65535}
1037 test binary-28.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
1038     binary scan abc S
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
1043 } {1 {21155 21332}}
1044 test binary-28.3 {Tcl_BinaryObjCmd: scan} {
1045     unset -nocomplain arg1
1046     list [binary scan \x52\xa3\x53\x54 S arg1] $arg1
1047 } {1 21155}
1048 test binary-28.4 {Tcl_BinaryObjCmd: scan} {
1049     unset -nocomplain arg1
1050     list [binary scan \x52\xa3 S1 arg1] $arg1
1051 } {1 21155}
1052 test binary-28.5 {Tcl_BinaryObjCmd: scan} {
1053     unset -nocomplain arg1
1054     list [binary scan \x52\xa3 S0 arg1] $arg1
1055 } {1 {}}
1056 test binary-28.6 {Tcl_BinaryObjCmd: scan} {
1057     unset -nocomplain arg1
1058     list [binary scan \x52\xa3\x53\x54 S2 arg1] $arg1
1059 } {1 {21155 21332}}
1060 test binary-28.7 {Tcl_BinaryObjCmd: scan} {
1061     unset -nocomplain arg1
1062     set arg1 foo
1063     list [binary scan \x52 S1 arg1] $arg1
1064 } {0 foo}
1065 test binary-28.8 {Tcl_BinaryObjCmd: scan} -setup {
1066     unset -nocomplain arg1
1067 } -returnCodes error -body {
1068     set arg1 1
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
1073     set arg1 foo
1074     set arg2 bar
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
1080 } {1 {21155 21332}}
1081 test binary-28.11 {Tcl_BinaryObjCmd: scan} {
1082     unset -nocomplain arg1
1083     list [binary scan \xa3\x52\x54\x53 Su* arg1] $arg1
1084 } {1 {41810 21587}}
1086 test binary-29.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
1087     binary scan abc i
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
1096 } {1 1414767442}
1097 test binary-29.4 {Tcl_BinaryObjCmd: scan} {
1098     unset -nocomplain arg1
1099     list [binary scan \x52\xa3\x53\x54 i1 arg1] $arg1
1100 } {1 1414767442}
1101 test binary-29.5 {Tcl_BinaryObjCmd: scan} {
1102     unset -nocomplain arg1
1103     list [binary scan \x52\xa3\x53 i0 arg1] $arg1
1104 } {1 {}}
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
1111     set arg1 foo
1112     list [binary scan \x52 i1 arg1] $arg1
1113 } {0 foo}
1114 test binary-29.8 {Tcl_BinaryObjCmd: scan} -setup {
1115     unset -nocomplain arg1
1116 } -returnCodes error -body {
1117     set arg1 1
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
1122     set arg1 foo
1123     set arg2 bar
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
1129 } {2 4294967295 -1}
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
1133 } {2 -1 4294967295}
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 {
1140     binary scan abc I
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
1149 } {1 1386435412}
1150 test binary-30.4 {Tcl_BinaryObjCmd: scan} {
1151     unset -nocomplain arg1
1152     list [binary scan \x52\xa3\x53\x54 I1 arg1] $arg1
1153 } {1 1386435412}
1154 test binary-30.5 {Tcl_BinaryObjCmd: scan} {
1155     unset -nocomplain arg1
1156     list [binary scan \x52\xa3\x53 I0 arg1] $arg1
1157 } {1 {}}
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
1164     set arg1 foo
1165     list [binary scan \x52 I1 arg1] $arg1
1166 } {0 foo}
1167 test binary-30.8 {Tcl_BinaryObjCmd: scan} -setup {
1168     unset -nocomplain arg1
1169 } -returnCodes error -body {
1170     set arg1 1
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
1175     set arg1 foo
1176     set arg2 bar
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
1182 } {2 4294967295 -1}
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
1186 } {2 -1 4294967295}
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 {
1198     catch {unset arg1}
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 {
1202     catch {unset arg1}
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 {
1206     catch {unset arg1}
1207     list [binary scan \x3f\xcc\xcc\xcd\x40\x59\x99\x9a f arg1] $arg1
1208 } {1 1.60000002384}
1209 test binary-31.5 {Tcl_BinaryObjCmd: scan} littleEndian {
1210     catch {unset arg1}
1211     list [binary scan \xcd\xcc\xcc\x3f\x9a\x99\x59\x40 f arg1] $arg1
1212 } {1 1.60000002384}
1213 test binary-31.6 {Tcl_BinaryObjCmd: scan} bigEndian {
1214     catch {unset arg1}
1215     list [binary scan \x3f\xcc\xcc\xcd f1 arg1] $arg1
1216 } {1 1.60000002384}
1217 test binary-31.7 {Tcl_BinaryObjCmd: scan} littleEndian {
1218     catch {unset arg1}
1219     list [binary scan \xcd\xcc\xcc\x3f f1 arg1] $arg1
1220 } {1 1.60000002384}
1221 test binary-31.8 {Tcl_BinaryObjCmd: scan} bigEndian {
1222     catch {unset arg1}
1223     list [binary scan \x3f\xcc\xcc\xcd f0 arg1] $arg1
1224 } {1 {}}
1225 test binary-31.9 {Tcl_BinaryObjCmd: scan} littleEndian {
1226     catch {unset arg1}
1227     list [binary scan \xcd\xcc\xcc\x3f f0 arg1] $arg1
1228 } {1 {}}
1229 test binary-31.10 {Tcl_BinaryObjCmd: scan} bigEndian {
1230     catch {unset arg1}
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 {
1234     catch {unset arg1}
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} {
1238     catch {unset arg1}
1239     set arg1 foo
1240     list [binary scan \x52 f1 arg1] $arg1
1241 } {0 foo}
1242 test binary-31.13 {Tcl_BinaryObjCmd: scan} {
1243     catch {unset arg1}
1244     set arg1 1
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}
1249     set arg1 foo
1250     set arg2 bar
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}
1255     set arg1 foo
1256     set arg2 bar
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 {
1264     catch {unset arg1}
1265     list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33 d* arg1] $arg1
1266 } {1 {1.6 3.4}}
1267 test binary-32.3 {Tcl_BinaryObjCmd: scan} littleEndian {
1268     catch {unset arg1}
1269     list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40 d* arg1] $arg1
1270 } {1 {1.6 3.4}}
1271 test binary-32.4 {Tcl_BinaryObjCmd: scan} bigEndian {
1272     catch {unset arg1}
1273     list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33 d arg1] $arg1
1274 } {1 1.6}
1275 test binary-32.5 {Tcl_BinaryObjCmd: scan} littleEndian {
1276     catch {unset arg1}
1277     list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40 d arg1] $arg1
1278 } {1 1.6}
1279 test binary-32.6 {Tcl_BinaryObjCmd: scan} bigEndian {
1280     catch {unset arg1}
1281     list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a d1 arg1] $arg1
1282 } {1 1.6}
1283 test binary-32.7 {Tcl_BinaryObjCmd: scan} littleEndian {
1284     catch {unset arg1}
1285     list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f d1 arg1] $arg1
1286 } {1 1.6}
1287 test binary-32.8 {Tcl_BinaryObjCmd: scan} bigEndian {
1288     catch {unset arg1}
1289     list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a d0 arg1] $arg1
1290 } {1 {}}
1291 test binary-32.9 {Tcl_BinaryObjCmd: scan} littleEndian {
1292     catch {unset arg1}
1293     list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f d0 arg1] $arg1
1294 } {1 {}}
1295 test binary-32.10 {Tcl_BinaryObjCmd: scan} bigEndian {
1296     catch {unset arg1}
1297     list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33 d2 arg1] $arg1
1298 } {1 {1.6 3.4}}
1299 test binary-32.11 {Tcl_BinaryObjCmd: scan} littleEndian {
1300     catch {unset arg1}
1301     list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40 d2 arg1] $arg1
1302 } {1 {1.6 3.4}}
1303 test binary-32.12 {Tcl_BinaryObjCmd: scan} {
1304     catch {unset arg1}
1305     set arg1 foo
1306     list [binary scan \x52 d1 arg1] $arg1
1307 } {0 foo}
1308 test binary-32.13 {Tcl_BinaryObjCmd: scan} {
1309     catch {unset arg1}
1310     set arg1 1
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}
1315     set arg1 foo
1316     set arg2 bar
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
1318 } {2 {1.6 3.4} 5}
1319 test binary-32.15 {Tcl_BinaryObjCmd: scan} littleEndian {
1320     catch {unset arg1 arg2}
1321     set arg1 foo
1322     set arg2 bar
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
1324 } {2 {1.6 3.4} 5}
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
1330 } {2 ab def}
1331 test binary-33.2 {Tcl_BinaryObjCmd: scan} {
1332     unset -nocomplain arg1
1333     unset -nocomplain arg2
1334     set arg2 foo
1335     list [binary scan abcdefg a3x*a3 arg1 arg2] $arg1 $arg2
1336 } {1 abc foo}
1337 test binary-33.3 {Tcl_BinaryObjCmd: scan} {
1338     unset -nocomplain arg1
1339     unset -nocomplain arg2
1340     set arg2 foo
1341     list [binary scan abcdefg a3x20a3 arg1 arg2] $arg1 $arg2
1342 } {1 abc foo}
1343 test binary-33.4 {Tcl_BinaryObjCmd: scan} {
1344     unset -nocomplain arg1
1345     unset -nocomplain arg2
1346     set arg2 foo
1347     list [binary scan abc a3x20a3 arg1 arg2] $arg1 $arg2
1348 } {1 abc foo}
1349 test binary-33.5 {Tcl_BinaryObjCmd: scan} {
1350     unset -nocomplain arg1
1351     list [binary scan abcdef x1a1 arg1] $arg1
1352 } {1 b}
1353 test binary-33.6 {Tcl_BinaryObjCmd: scan} {
1354     unset -nocomplain arg1
1355     list [binary scan abcdef x5a1 arg1] $arg1
1356 } {1 f}
1357 test binary-33.7 {Tcl_BinaryObjCmd: scan} {
1358     unset -nocomplain arg1
1359     list [binary scan abcdef x0a1 arg1] $arg1
1360 } {1 a}
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
1366 } {2 ab bcd}
1367 test binary-34.2 {Tcl_BinaryObjCmd: scan} {
1368     unset -nocomplain arg1
1369     unset -nocomplain arg2
1370     set arg2 foo
1371     list [binary scan abcdefg a3X*a3 arg1 arg2] $arg1 $arg2
1372 } {2 abc abc}
1373 test binary-34.3 {Tcl_BinaryObjCmd: scan} {
1374     unset -nocomplain arg1
1375     unset -nocomplain arg2
1376     set arg2 foo
1377     list [binary scan abcdefg a3X20a3 arg1 arg2] $arg1 $arg2
1378 } {2 abc abc}
1379 test binary-34.4 {Tcl_BinaryObjCmd: scan} {
1380     unset -nocomplain arg1
1381     list [binary scan abc X20a3 arg1] $arg1
1382 } {1 abc}
1383 test binary-34.5 {Tcl_BinaryObjCmd: scan} {
1384     unset -nocomplain arg1
1385     list [binary scan abcdef x*X1a1 arg1] $arg1
1386 } {1 f}
1387 test binary-34.6 {Tcl_BinaryObjCmd: scan} {
1388     unset -nocomplain arg1
1389     list [binary scan abcdef x*X5a1 arg1] $arg1
1390 } {1 b}
1391 test binary-34.7 {Tcl_BinaryObjCmd: scan} {
1392     unset -nocomplain arg1
1393     list [binary scan abcdef x3X0a1 arg1] $arg1
1394 } {1 d}
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
1405     set arg2 foo
1406     list [binary scan abcdefg a3@*a3 arg1 arg2] $arg1 $arg2
1407 } {1 abc foo}
1408 test binary-35.3 {Tcl_BinaryObjCmd: scan} {
1409     unset -nocomplain arg1
1410     unset -nocomplain arg2
1411     set arg2 foo
1412     list [binary scan abcdefg a3@20a3 arg1 arg2] $arg1 $arg2
1413 } {1 abc foo}
1414 test binary-35.4 {Tcl_BinaryObjCmd: scan} {
1415     unset -nocomplain arg1
1416     list [binary scan abcdef @2a3 arg1] $arg1
1417 } {1 cde}
1418 test binary-35.5 {Tcl_BinaryObjCmd: scan} {
1419     unset -nocomplain arg1
1420     list [binary scan abcdef x*@1a1 arg1] $arg1
1421 } {1 b}
1422 test binary-35.6 {Tcl_BinaryObjCmd: scan} {
1423     unset -nocomplain arg1
1424     list [binary scan abcdef x*@0a1 arg1] $arg1
1425 } {1 a}
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
1437 } foobarblbaz
1438 test binary-37.2 {GetFormatSpec: whitespace} {
1439     binary format "      " foo
1440 } {}
1441 test binary-37.3 {GetFormatSpec: whitespace} {
1442     binary format "     a3" foo
1443 } foo
1444 test binary-37.4 {GetFormatSpec: whitespace} {
1445     binary format "" foo
1446 } {}
1447 test binary-37.5 {GetFormatSpec: whitespace} {
1448     binary format "" foo
1449 } {}
1450 test binary-37.6 {GetFormatSpec: whitespace} {
1451     binary format "     a3   " foo
1452 } 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} {
1457     catch {unset arg1}
1458     set arg1 foo
1459     list [binary scan abcdef "a0x3" arg1] $arg1
1460 } {1 {}}
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
1466     set 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]
1471 } \x01\x01\x00
1472 test binary-38.2 {FormatNumber: word alignment} {
1473     set x [binary format c1S1 1 1]
1474 } \x01\x00\x01
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} {
1495     catch {unset arg1}
1496     list [binary scan \x52\xa3 c2 arg1] $arg1
1497 } {1 {82 -93}}
1498 test binary-39.2 {ScanNumber: sign extension} {
1499     catch {unset arg1}
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} {
1503     catch {unset arg1}
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} {
1507     catch {unset arg1}
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} {
1511     catch {unset arg1}
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} {
1515     catch {unset arg1}
1516     list [binary scan \x52\xa3 cu2 arg1] $arg1
1517 } {1 {82 163}}
1518 test binary-39.7 {ScanNumber: no sign extension} {
1519     catch {unset arg1}
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} {
1523     catch {unset arg1}
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} {
1527     catch {unset arg1}
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} {
1531     catch {unset arg1}
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} \
1536     -body {
1537         catch {unset arg1}
1538         list [binary scan \xff\xff\xff\xff f1 arg1] $arg1
1539     } \
1540     -match glob \
1541     -result {1 -NaN*}
1543 test binary-40.4 {ScanNumber: NaN} -constraints {maxCompatibility} \
1544     -body {
1545         catch {unset arg1}
1546         list [binary scan \xff\xff\xff\xff\xff\xff\xff\xff d arg1] $arg1
1547     } \
1548     -match glob \
1549     -result {1 -NaN*}
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
1554 } {2 1 1}
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
1558 } {2 1 1}
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
1562 } {2 1 1}
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
1566 } {2 1 1}
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
1578 } {2 1 1.6}
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
1582 } {2 1 1.6}
1584 # Test changed in Jim's fashion
1585 test binary-42.1 {Tcl_BinaryObjCmd: bad arguments} -returnCodes error -body {
1586     binary ?
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
1592 } HelloTcl
1593 test binary-43.2 {Tcl_BinaryObjCmd: format wide int} {} {
1594     binary format W 7810179016327718216
1595 } lcTolleH
1597 test binary-44.1 {Tcl_BinaryObjCmd: scan wide int} {} {
1598     binary scan HelloTcl W x
1599     set x
1600 } 5216694956358656876
1601 test binary-44.2 {Tcl_BinaryObjCmd: scan wide int} {} {
1602     binary scan lcTolleH w x
1603     set 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
1608     set x
1609 } 6442450944
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
1612     set x
1613 } 6442450944
1614 test binary-43.5 {Tcl_BinaryObjCmd: scan wide int} {} {
1615     catch {unset arg1}
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} {
1620     catch {unset arg1}
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} {
1624     catch {unset arg1}
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
1638     set 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
1642     set 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
1653 } {3 97}
1656 ### TIP#129: endian specifiers ----
1658 # format t
1659 test binary-48.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
1660     binary format t
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
1667 } {}
1668 test binary-48.4 {Tcl_BinaryObjCmd: format} bigEndian {
1669     binary format t 0x50
1670 } \x00P
1671 test binary-48.5 {Tcl_BinaryObjCmd: format} littleEndian {
1672     binary format t 0x50
1673 } P\x00
1674 test binary-48.6 {Tcl_BinaryObjCmd: format} bigEndian {
1675     binary format t 0x5052
1676 } PR
1677 test binary-48.7 {Tcl_BinaryObjCmd: format} littleEndian {
1678     binary format t 0x5052
1679 } RP
1680 test binary-48.8 {Tcl_BinaryObjCmd: format} bigEndian {
1681     binary format t 0x505251 0x53
1682 } RQ
1683 test binary-48.9 {Tcl_BinaryObjCmd: format} littleEndian {
1684     binary format t 0x505251 0x53
1685 } QR
1686 test binary-48.10 {Tcl_BinaryObjCmd: format} bigEndian {
1687     binary format t2 {0x50 0x52}
1688 } \x00P\x00R
1689 test binary-48.11 {Tcl_BinaryObjCmd: format} littleEndian {
1690     binary format t2 {0x50 0x52}
1691 } P\x00R\x00
1692 test binary-48.12 {Tcl_BinaryObjCmd: format} bigEndian {
1693     binary format t* {0x5051 0x52}
1694 } PQ\x00R
1695 test binary-48.13 {Tcl_BinaryObjCmd: format} littleEndian {
1696     binary format t* {0x5051 0x52}
1697 } QPR\x00
1698 test binary-48.14 {Tcl_BinaryObjCmd: format} bigEndian {
1699     binary format t2 {0x50 0x52 0x53} 0x54
1700 } \x00P\x00R
1701 test binary-48.15 {Tcl_BinaryObjCmd: format} littleEndian {
1702     binary format t2 {0x50 0x52 0x53} 0x54
1703 } P\x00R\x00
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 {
1708     set a {0x50 0x51}
1709     binary format t $a
1710 } -result "expected integer but got \"0x50 0x51\""
1711 test binary-48.18 {Tcl_BinaryObjCmd: format} bigEndian {
1712     set a {0x50 0x51}
1713     binary format t1 $a
1714 } \x00P
1715 test binary-48.19 {Tcl_BinaryObjCmd: format} littleEndian {
1716     set a {0x50 0x51}
1717     binary format t1 $a
1718 } P\x00
1720 # format n
1721 test binary-49.1 {Tcl_BinaryObjCmd: format} -returnCodes error -body {
1722     binary format n
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
1729 } {}
1730 test binary-49.4 {Tcl_BinaryObjCmd: format} littleEndian {
1731     binary format n 0x50
1732 } P\x00\x00\x00
1733 test binary-49.5 {Tcl_BinaryObjCmd: format} littleEndian {
1734     binary format n 0x5052
1735 } RP\x00\x00
1736 test binary-49.6 {Tcl_BinaryObjCmd: format} littleEndian {
1737     binary format n 0x505251 0x53
1738 } QRP\x00
1739 test binary-49.7 {Tcl_BinaryObjCmd: format} littleEndian {
1740     binary format i1 {0x505251 0x53}
1741 } QRP\x00
1742 test binary-49.8 {Tcl_BinaryObjCmd: format} littleEndian {
1743     binary format n 0x53525150
1744 } PQRS
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}
1750 } SRQPR\x00\x00\x00
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 {
1755     set a {0x50 0x51}
1756     binary format n $a
1757 } -result "expected integer but got \"0x50 0x51\""
1758 test binary-49.13 {Tcl_BinaryObjCmd: format} littleEndian {
1759     set a {0x50 0x51}
1760     binary format n1 $a
1761 } P\x00\x00\x00
1762 test binary-49.14 {Tcl_BinaryObjCmd: format} bigEndian {
1763     binary format n 0x50
1764 } \x00\x00\x00P
1765 test binary-49.15 {Tcl_BinaryObjCmd: format} bigEndian {
1766     binary format n 0x5052
1767 } \x00\x00PR
1768 test binary-49.16 {Tcl_BinaryObjCmd: format} bigEndian {
1769     binary format n 0x505251 0x53
1770 } \x00PRQ
1771 test binary-49.17 {Tcl_BinaryObjCmd: format} bigEndian {
1772     binary format i1 {0x505251 0x53}
1773 } QRP\x00
1774 test binary-49.18 {Tcl_BinaryObjCmd: format} bigEndian {
1775     binary format n 0x53525150
1776 } SRQP
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}
1782 } PQRS\x00\x00\x00R
1784 # format m
1785 test binary-50.1 {Tcl_BinaryObjCmd: format wide int} littleEndian {
1786     binary format m 7810179016327718216
1787 } HelloTcl
1788 test binary-50.2 {Tcl_BinaryObjCmd: format wide int} bigEndian {
1789     binary format m 7810179016327718216
1790 } lcTolleH
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
1795     set x
1796 } 6442450944
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
1799     set x
1800 } 6442450944
1803 # format Q/q
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
1812 } {}
1813 test binary-51.4 {Tcl_BinaryObjCmd: format} {} {
1814     binary format Q 1.6
1815 } \x3f\xf9\x99\x99\x99\x99\x99\x9a
1816 test binary-51.5 {Tcl_BinaryObjCmd: format} {} {
1817     binary format q 1.6
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} {
1841     set a {1.6 3.4}
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} {} {
1845     set a {1.6 3.4}
1846     binary format Q1 $a
1847 } \x3f\xf9\x99\x99\x99\x99\x99\x9a
1848 test binary-51.17 {Tcl_BinaryObjCmd: format} {} {
1849     set a {1.6 3.4}
1850     binary format q1 $a
1851 } \x9a\x99\x99\x99\x99\x99\xf9\x3f
1853 # format R/r
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
1862 } {}
1863 test binary-53.4 {Tcl_BinaryObjCmd: format} {} {
1864     binary format R 1.6
1865 } \x3f\xcc\xcc\xcd
1866 test binary-53.5 {Tcl_BinaryObjCmd: format} {} {
1867     binary format r 1.6
1868 } \xcd\xcc\xcc\x3f
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
1889 } \xff\x7f\xff\xff
1890 test binary-53.13 {Tcl_BinaryObjCmd: float overflow} {maxCompatibility} {
1891     binary format r -3.402825e+38
1892 } \xff\xff\x7f\xff
1893 test binary-53.14 {Tcl_BinaryObjCmd: float underflow} {} {
1894     binary format R -3.402825e-100
1895 } \x80\x00\x00\x00
1896 test binary-53.15 {Tcl_BinaryObjCmd: float underflow} {} {
1897     binary format r -3.402825e-100
1898 } \x00\x00\x00\x80
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} {
1903     set a {1.6 3.4}
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} {} {
1907     set a {1.6 3.4}
1908     binary format R1 $a
1909 } \x3f\xcc\xcc\xcd
1910 test binary-53.19 {Tcl_BinaryObjCmd: format} {} {
1911     set a {1.6 3.4}
1912     binary format r1 $a
1913 } \xcd\xcc\xcc\x3f
1915 # scan t (s)
1916 test binary-54.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
1917     binary scan abc t
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
1926 } {1 -23726}
1927 test binary-54.4 {Tcl_BinaryObjCmd: scan} littleEndian {
1928     unset -nocomplain arg1
1929     list [binary scan \x52\xa3 t1 arg1] $arg1
1930 } {1 -23726}
1931 test binary-54.5 {Tcl_BinaryObjCmd: scan} littleEndian {
1932     unset -nocomplain arg1
1933     list [binary scan \x52\xa3 t0 arg1] $arg1
1934 } {1 {}}
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
1941     set arg1 foo
1942     list [binary scan \x52 t1 arg1] $arg1
1943 } {0 foo}
1944 test binary-54.8 {Tcl_BinaryObjCmd: scan} -setup {
1945     unset -nocomplain arg1
1946 } -returnCodes error -body {
1947     set arg1 1
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
1952     set arg1 foo
1953     set arg2 bar
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
1958     set arg1 foo
1959     set arg2 bar
1960     list [binary scan \x00\x80\x00\x80 tut arg1 arg2] $arg1 $arg2
1961 } {2 32768 -32768}
1962 test binary-54.11 {Tcl_BinaryObjCmd: scan} littleEndian {
1963     unset -nocomplain arg1 arg2
1964     set arg1 foo
1965     set arg2 bar
1966     list [binary scan \x00\x80\x00\x80 ttu arg1 arg2] $arg1 $arg2
1967 } {2 -32768 32768}
1969 # scan t (b)
1970 test binary-55.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
1971     binary scan abc t
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
1976 } {1 {21155 21332}}
1977 test binary-55.3 {Tcl_BinaryObjCmd: scan} bigEndian {
1978     unset -nocomplain arg1
1979     list [binary scan \x52\xa3\x53\x54 t arg1] $arg1
1980 } {1 21155}
1981 test binary-55.4 {Tcl_BinaryObjCmd: scan} bigEndian {
1982     unset -nocomplain arg1
1983     list [binary scan \x52\xa3 t1 arg1] $arg1
1984 } {1 21155}
1985 test binary-55.5 {Tcl_BinaryObjCmd: scan} bigEndian {
1986     unset -nocomplain arg1
1987     list [binary scan \x52\xa3 t0 arg1] $arg1
1988 } {1 {}}
1989 test binary-55.6 {Tcl_BinaryObjCmd: scan} bigEndian {
1990     unset -nocomplain arg1
1991     list [binary scan \x52\xa3\x53\x54 t2 arg1] $arg1
1992 } {1 {21155 21332}}
1993 test binary-55.7 {Tcl_BinaryObjCmd: scan} bigEndian {
1994     unset -nocomplain arg1
1995     set arg1 foo
1996     list [binary scan \x52 t1 arg1] $arg1
1997 } {0 foo}
1998 test binary-55.8 {Tcl_BinaryObjCmd: scan} -setup {
1999     unset -nocomplain arg1
2000 } -returnCodes error -body {
2001     set arg1 1
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
2006     set arg1 foo
2007     set arg2 bar
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
2012     set arg1 foo
2013     set arg2 bar
2014     list [binary scan \x80\x00\x80\x00 tut arg1 arg2] $arg1 $arg2
2015 } {2 32768 -32768}
2016 test binary-55.11 {Tcl_BinaryObjCmd: scan} bigEndian {
2017     unset -nocomplain arg1 arg2
2018     set arg1 foo
2019     set arg2 bar
2020     list [binary scan \x80\x00\x80\x00 ttu arg1 arg2] $arg1 $arg2
2021 } {2 -32768 32768}
2023 # scan n (s)
2024 test binary-56.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
2025     binary scan abc n
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
2034 } {1 1414767442}
2035 test binary-56.4 {Tcl_BinaryObjCmd: scan} littleEndian {
2036     unset -nocomplain arg1
2037     list [binary scan \x52\xa3\x53\x54 n1 arg1] $arg1
2038 } {1 1414767442}
2039 test binary-56.5 {Tcl_BinaryObjCmd: scan} littleEndian {
2040     unset -nocomplain arg1
2041     list [binary scan \x52\xa3\x53 n0 arg1] $arg1
2042 } {1 {}}
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
2049     set arg1 foo
2050     list [binary scan \x52 n1 arg1] $arg1
2051 } {0 foo}
2052 test binary-56.8 {Tcl_BinaryObjCmd: scan} -setup {
2053     unset -nocomplain arg1
2054 } -returnCodes error -body {
2055     set arg1 1
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
2060     set arg1 foo
2061     set arg2 bar
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
2066     set arg1 foo
2067     set arg2 bar
2068     list [binary scan \x80\x00\x00\x00\x80\x00\x00\x00 nun arg1 arg2] $arg1 $arg2
2069 } {2 128 128}
2070 test binary-56.11 {Tcl_BinaryObjCmd: scan} littleEndian {
2071     unset -nocomplain arg1 arg2
2072     set arg1 foo
2073     set arg2 bar
2074     list [binary scan \x00\x00\x00\x80\x00\x00\x00\x80 nun arg1 arg2] $arg1 $arg2
2075 } {2 2147483648 -2147483648}
2077 # scan n (b)
2078 test binary-57.1 {Tcl_BinaryObjCmd: scan} -returnCodes error -body {
2079     binary scan abc n
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
2088 } {1 1386435412}
2089 test binary-57.4 {Tcl_BinaryObjCmd: scan} bigEndian {
2090     unset -nocomplain arg1
2091     list [binary scan \x52\xa3\x53\x54 n1 arg1] $arg1
2092 } {1 1386435412}
2093 test binary-57.5 {Tcl_BinaryObjCmd: scan} bigEndian {
2094     unset -nocomplain arg1
2095     list [binary scan \x52\xa3\x53 n0 arg1] $arg1
2096 } {1 {}}
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
2103     set arg1 foo
2104     list [binary scan \x52 n1 arg1] $arg1
2105 } {0 foo}
2106 test binary-57.8 {Tcl_BinaryObjCmd: scan} -setup {
2107     unset -nocomplain arg1
2108 } -returnCodes error -body {
2109     set arg1 1
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
2114     set arg1 foo
2115     set arg2 bar
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
2120     set arg1 foo
2121     set arg2 bar
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
2126     set arg1 foo
2127     set arg2 bar
2128     list [binary scan \x00\x00\x00\x80\x00\x00\x00\x80 nun arg1 arg2] $arg1 $arg2
2129 } {2 128 128}
2131 # scan Q/q
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 {
2136     catch {unset arg1}
2137     list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33 Q* arg1] $arg1
2138 } {1 {1.6 3.4}}
2139 test binary-58.3 {Tcl_BinaryObjCmd: scan} littleEndian {
2140     catch {unset arg1}
2141     list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40 q* arg1] $arg1
2142 } {1 {1.6 3.4}}
2143 test binary-58.4 {Tcl_BinaryObjCmd: scan} bigEndian {
2144     catch {unset arg1}
2145     list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33 Q arg1] $arg1
2146 } {1 1.6}
2147 test binary-58.5 {Tcl_BinaryObjCmd: scan} littleEndian {
2148     catch {unset arg1}
2149     list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40 q arg1] $arg1
2150 } {1 1.6}
2151 test binary-58.6 {Tcl_BinaryObjCmd: scan} bigEndian {
2152     catch {unset arg1}
2153     list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a Q1 arg1] $arg1
2154 } {1 1.6}
2155 test binary-58.7 {Tcl_BinaryObjCmd: scan} littleEndian {
2156     catch {unset arg1}
2157     list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f q1 arg1] $arg1
2158 } {1 1.6}
2159 test binary-58.8 {Tcl_BinaryObjCmd: scan} bigEndian {
2160     catch {unset arg1}
2161     list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a Q0 arg1] $arg1
2162 } {1 {}}
2163 test binary-58.9 {Tcl_BinaryObjCmd: scan} littleEndian {
2164     catch {unset arg1}
2165     list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f q0 arg1] $arg1
2166 } {1 {}}
2167 test binary-58.10 {Tcl_BinaryObjCmd: scan} bigEndian {
2168     catch {unset arg1}
2169     list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33 Q2 arg1] $arg1
2170 } {1 {1.6 3.4}}
2171 test binary-58.11 {Tcl_BinaryObjCmd: scan} littleEndian {
2172     catch {unset arg1}
2173     list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40 q2 arg1] $arg1
2174 } {1 {1.6 3.4}}
2175 test binary-58.12 {Tcl_BinaryObjCmd: scan} {
2176     catch {unset arg1}
2177     set arg1 foo
2178     list [binary scan \x52 q1 arg1] $arg1
2179 } {0 foo}
2180 test binary-58.13 {Tcl_BinaryObjCmd: scan} {
2181     catch {unset arg1}
2182     set arg1 1
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}
2187     set arg1 foo
2188     set arg2 bar
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
2190 } {2 {1.6 3.4} 5}
2191 test binary-58.15 {Tcl_BinaryObjCmd: scan} littleEndian {
2192     catch {unset arg1 arg2}
2193     set arg1 foo
2194     set arg2 bar
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
2196 } {2 {1.6 3.4} 5}
2198 # scan R/r
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 {
2203     catch {unset arg1}
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 {
2207     catch {unset arg1}
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 {
2211     catch {unset arg1}
2212     list [binary scan \x3f\xcc\xcc\xcd\x40\x59\x99\x9a R arg1] $arg1
2213 } {1 1.60000002384}
2214 test binary-59.5 {Tcl_BinaryObjCmd: scan} littleEndian {
2215     catch {unset arg1}
2216     list [binary scan \xcd\xcc\xcc\x3f\x9a\x99\x59\x40 r arg1] $arg1
2217 } {1 1.60000002384}
2218 test binary-59.6 {Tcl_BinaryObjCmd: scan} bigEndian {
2219     catch {unset arg1}
2220     list [binary scan \x3f\xcc\xcc\xcd R1 arg1] $arg1
2221 } {1 1.60000002384}
2222 test binary-59.7 {Tcl_BinaryObjCmd: scan} littleEndian {
2223     catch {unset arg1}
2224     list [binary scan \xcd\xcc\xcc\x3f r1 arg1] $arg1
2225 } {1 1.60000002384}
2226 test binary-59.8 {Tcl_BinaryObjCmd: scan} bigEndian {
2227     catch {unset arg1}
2228     list [binary scan \x3f\xcc\xcc\xcd R0 arg1] $arg1
2229 } {1 {}}
2230 test binary-59.9 {Tcl_BinaryObjCmd: scan} littleEndian {
2231     catch {unset arg1}
2232     list [binary scan \xcd\xcc\xcc\x3f r0 arg1] $arg1
2233 } {1 {}}
2234 test binary-59.10 {Tcl_BinaryObjCmd: scan} bigEndian {
2235     catch {unset arg1}
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 {
2239     catch {unset arg1}
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} {
2243     catch {unset arg1}
2244     set arg1 foo
2245     list [binary scan \x52 r1 arg1] $arg1
2246 } {0 foo}
2247 test binary-59.13 {Tcl_BinaryObjCmd: scan} {
2248     catch {unset arg1}
2249     set arg1 1
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}
2254     set arg1 foo
2255     set arg2 bar
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}
2260     set arg1 foo
2261     set arg2 bar
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 \
2267         v1 v2 v3 v4 v5 v6
2268     list $v1 $v2 $v3 $v4 $v5 $v6
2269 } -match regexp -result {NaN(\([[:xdigit:]]+\))? NaN(\([[:xdigit:]]+\))? NaN(\([[:xdigit:]]+\))? NaN(\([[:xdigit:]]+\))? NaN(\([[:xdigit:]]+\))? NaN(\([[:xdigit:]]+\))?}
2271 # scan m
2272 test binary-61.1 {Tcl_BinaryObjCmd: scan wide int} bigEndian {
2273     binary scan HelloTcl m x
2274     set x
2275 } 5216694956358656876
2276 test binary-61.2 {Tcl_BinaryObjCmd: scan wide int} littleEndian {
2277     binary scan lcTolleH m x
2278     set 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
2282     set x
2283 } 6442450944
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
2286     set x
2287 } 6442450944
2289 # Big test for correct ordering of data in [expr]
2291 proc testIEEE {} {
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} {
2296             # little endian
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 \
2300                 ieeeValues(-Normal)
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 \
2304                 ieeeValues(-0)
2305             binary scan \x00\x00\x00\x00\x00\x00\x00\x00 d \
2306                 ieeeValues(+0)
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 \
2310                 ieeeValues(+Normal)
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 \
2314                 ieeeValues(NaN)
2315             set ieeeValues(littleEndian) 1
2316             return 1
2317         }
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 \
2322                 ieeeValues(-Normal)
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 \
2326                 ieeeValues(-0)
2327             binary scan \x00\x00\x00\x00\x00\x00\x00\x00 d \
2328                 ieeeValues(+0)
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 \
2332                 ieeeValues(+Normal)
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 \
2336                 ieeeValues(NaN)
2337             set ieeeValues(littleEndian) 0
2338             return 1
2339         }
2340         default {
2341             return 0
2342         }
2343     }
2346 testConstraint ieeeFloatingPoint [testIEEE]
2348 # scan/format infinities
2350 test binary-62.1 {infinity} ieeeFloatingPoint {
2351     binary scan [binary format q Infinity] w w
2352     format 0x%016lx $w
2353 } 0x7ff0000000000000
2354 test binary-62.2 {infinity} ieeeFloatingPoint {
2355     binary scan [binary format q -Infinity] w w
2356     format 0x%016lx $w
2357 } 0xfff0000000000000
2358 test binary-62.3 {infinity} ieeeFloatingPoint {
2359     binary scan [binary format q Inf] w w
2360     format 0x%016lx $w
2361 } 0x7ff0000000000000
2362 test binary-62.4 {infinity} ieeeFloatingPoint {
2363     binary scan [binary format q -Infinity] w w
2364     format 0x%016lx $w
2365 } 0xfff0000000000000
2366 test binary-62.5 {infinity} ieeeFloatingPoint {
2367     binary scan [binary format w 0x7ff0000000000000] q d
2368     set d
2369 } Inf
2370 test binary-62.6 {infinity} ieeeFloatingPoint {
2371     binary scan [binary format w 0xfff0000000000000] q d
2372     set d
2373 } -Inf
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 \
2416     -body {
2417         binary scan [binary format w 0x7ff8000000000000] q d
2418         set d
2419     } \
2420     -match glob -result NaN*
2421 test binary-64.2 {NaN} \
2422     -constraints {ieeeFloatingPoint notImplemented} \
2423     -body {
2424         binary scan [binary format w 0x7ff0123456789aBc] q d
2425         set d
2426     } \
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
2434     set d
2435 } 0.24999999999999997
2436 test binary-65.2 {smallest significand} ieeeFloatingPoint {
2437     binary scan [binary format w 0x3fd0000000000000] q d
2438     set d
2439 } 0.25
2440 test binary-65.3 {largest significand} {ieeeFloatingPoint maxCompatibility} {
2441     binary scan [binary format w 0x3fdfffffffffffff] q d
2442     set d
2443 } 0.49999999999999994
2444 test binary-65.4 {smallest significand} ieeeFloatingPoint {
2445     binary scan [binary format w 0x3fe0000000000000] q d
2446     set d
2447 } 0.5
2448 test binary-65.5 {largest significand} {ieeeFloatingPoint maxCompatibility} {
2449     binary scan [binary format w 0x3fffffffffffffff] q d
2450     set d
2451 } 1.9999999999999998
2452 test binary-65.6 {smallest significand} ieeeFloatingPoint {
2453     binary scan [binary format w 0x4000000000000000] q d
2454     set d
2455 } 2.0
2456 test binary-65.7 {smallest significand} {ieeeFloatingPoint maxCompatibility} {
2457     binary scan [binary format w 0x434fffffffffffff] q d
2458     set d
2459 } 18014398509481982.0
2460 test binary-65.8 {largest significand} {ieeeFloatingPoint maxCompatibility} {
2461     binary scan [binary format w 0x4350000000000000] q d
2462     set d
2463 } 18014398509481984.0
2464 test binary-65.9 {largest significand} {ieeeFloatingPoint maxCompatibility} {
2465     binary scan [binary format w 0x4350000000000001] q d
2466     set 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
2474 } 0
2476 # cleanup
2477 ::tcltest::cleanupTests
2478 return
2480 # Local Variables:
2481 # mode: tcl
2482 # End: