Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/tests/binary.test @ 47

Last change on this file since 47 was 25, checked in by landauf, 17 years ago

added tcl to libs

File size: 83.3 KB
Line 
1# This file tests the tclBinary.c file and the "binary" Tcl command.
2#
3# This file contains a collection of tests for one or more of the Tcl
4# built-in commands.  Sourcing this file into Tcl runs the tests and
5# generates output for errors.  No output means no errors were found.
6#
7# Copyright (c) 1997 by Sun Microsystems, Inc.
8# Copyright (c) 1998-1999 by Scriptics Corporation.
9#
10# See the file "license.terms" for information on usage and redistribution
11# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12#
13# RCS: @(#) $Id: binary.test,v 1.32 2008/03/24 03:10:46 patthoyts Exp $
14
15if {[lsearch [namespace children] ::tcltest] == -1} {
16    package require tcltest
17    namespace import -force ::tcltest::*
18}
19testConstraint bigEndian [expr {$tcl_platform(byteOrder) eq "bigEndian"}]
20testConstraint littleEndian [expr {$tcl_platform(byteOrder) eq "littleEndian"}]
21
22test binary-0.1 {DupByteArrayInternalRep} {
23    set hdr [binary format cc 0 0316]
24    set buf hellomatt
25   
26    set data $hdr
27    append data $buf
28   
29    string length $data
30} 11
31
32test binary-1.1 {Tcl_BinaryObjCmd: bad args} {
33    list [catch {binary} msg] $msg
34} {1 {wrong # args: should be "binary option ?arg arg ...?"}}
35test binary-1.2 {Tcl_BinaryObjCmd: bad args} {
36    list [catch {binary foo} msg] $msg
37} {1 {bad option "foo": must be format or scan}}
38
39test binary-1.3 {Tcl_BinaryObjCmd: format error} {
40    list [catch {binary f} msg] $msg
41} {1 {wrong # args: should be "binary format formatString ?arg arg ...?"}}
42test binary-1.4 {Tcl_BinaryObjCmd: format} {
43    binary format ""
44} {}
45
46
47test binary-2.1 {Tcl_BinaryObjCmd: format} {
48    list [catch {binary format a } msg] $msg
49} {1 {not enough arguments for all format specifiers}}
50test binary-2.2 {Tcl_BinaryObjCmd: format} {
51    binary format a0 foo
52} {}
53test binary-2.3 {Tcl_BinaryObjCmd: format} {
54    binary format a f
55} {f}
56test binary-2.4 {Tcl_BinaryObjCmd: format} {
57    binary format a foo
58} {f}
59test binary-2.5 {Tcl_BinaryObjCmd: format} {
60    binary format a3 foo
61} {foo}
62test binary-2.6 {Tcl_BinaryObjCmd: format} {
63    binary format a5 foo
64} foo\x00\x00
65test binary-2.7 {Tcl_BinaryObjCmd: format} {
66    binary format a*a3 foobarbaz blat
67} foobarbazbla
68test binary-2.8 {Tcl_BinaryObjCmd: format} {
69    binary format a*X3a2 foobar x
70} foox\x00r
71
72test binary-3.1 {Tcl_BinaryObjCmd: format} {
73    list [catch {binary format A} msg] $msg
74} {1 {not enough arguments for all format specifiers}}
75test binary-3.2 {Tcl_BinaryObjCmd: format} {
76    binary format A0 f
77} {}
78test binary-3.3 {Tcl_BinaryObjCmd: format} {
79    binary format A f
80} {f}
81test binary-3.4 {Tcl_BinaryObjCmd: format} {
82    binary format A foo
83} {f}
84test binary-3.5 {Tcl_BinaryObjCmd: format} {
85    binary format A3 foo
86} {foo}
87test binary-3.6 {Tcl_BinaryObjCmd: format} {
88    binary format A5 foo
89} {foo  }
90test binary-3.7 {Tcl_BinaryObjCmd: format} {
91    binary format A*A3 foobarbaz blat
92} foobarbazbla
93test binary-3.8 {Tcl_BinaryObjCmd: format} {
94    binary format A*X3A2 foobar x
95} {foox r}
96
97test binary-4.1 {Tcl_BinaryObjCmd: format} {
98    list [catch {binary format B} msg] $msg
99} {1 {not enough arguments for all format specifiers}}
100test binary-4.2 {Tcl_BinaryObjCmd: format} {
101    binary format B0 1
102} {}
103test binary-4.3 {Tcl_BinaryObjCmd: format} {
104    binary format B 1
105} \x80
106test binary-4.4 {Tcl_BinaryObjCmd: format} {
107    binary format B* 010011
108} \x4c
109test binary-4.5 {Tcl_BinaryObjCmd: format} {
110    binary format B8 01001101
111} \x4d
112test binary-4.6 {Tcl_BinaryObjCmd: format} {
113    binary format A2X2B9 oo 01001101
114} \x4d\x00
115test binary-4.7 {Tcl_BinaryObjCmd: format} {
116    binary format B9 010011011010
117} \x4d\x80
118test binary-4.8 {Tcl_BinaryObjCmd: format} {
119    binary format B2B3 10 010
120} \x80\x40
121test binary-4.9 {Tcl_BinaryObjCmd: format} {
122    list [catch {binary format B1B5 1 foo} msg] $msg
123} {1 {expected binary string but got "foo" instead}}
124
125test binary-5.1 {Tcl_BinaryObjCmd: format} {
126    list [catch {binary format b} msg] $msg
127} {1 {not enough arguments for all format specifiers}}
128test binary-5.2 {Tcl_BinaryObjCmd: format} {
129    binary format b0 1
130} {}
131test binary-5.3 {Tcl_BinaryObjCmd: format} {
132    binary format b 1
133} \x01
134test binary-5.4 {Tcl_BinaryObjCmd: format} {
135    binary format b* 010011
136} 2
137test binary-5.5 {Tcl_BinaryObjCmd: format} {
138    binary format b8 01001101
139} \xb2
140test binary-5.6 {Tcl_BinaryObjCmd: format} {
141    binary format A2X2b9 oo 01001101
142} \xb2\x00
143test binary-5.7 {Tcl_BinaryObjCmd: format} {
144    binary format b9 010011011010
145} \xb2\x01
146test binary-5.8 {Tcl_BinaryObjCmd: format} {
147    binary format b17 1
148} \x01\00\00
149test binary-5.9 {Tcl_BinaryObjCmd: format} {
150    binary format b2b3 10 010
151} \x01\x02
152test binary-5.10 {Tcl_BinaryObjCmd: format} {
153    list [catch {binary format b1b5 1 foo} msg] $msg
154} {1 {expected binary string but got "foo" instead}}
155
156test binary-6.1 {Tcl_BinaryObjCmd: format} {
157    list [catch {binary format h} msg] $msg
158} {1 {not enough arguments for all format specifiers}}
159test binary-6.2 {Tcl_BinaryObjCmd: format} {
160    binary format h0 1
161} {}
162test binary-6.3 {Tcl_BinaryObjCmd: format} {
163    binary format h 1
164} \x01
165test binary-6.4 {Tcl_BinaryObjCmd: format} {
166    binary format h c
167} \x0c
168test binary-6.5 {Tcl_BinaryObjCmd: format} {
169    binary format h* baadf00d
170} \xab\xda\x0f\xd0
171test binary-6.6 {Tcl_BinaryObjCmd: format} {
172    binary format h4 c410
173} \x4c\x01
174test binary-6.7 {Tcl_BinaryObjCmd: format} {
175    binary format h6 c4102
176} \x4c\x01\x02
177test binary-6.8 {Tcl_BinaryObjCmd: format} {
178    binary format h5 c41020304
179} \x4c\x01\x02
180test binary-6.9 {Tcl_BinaryObjCmd: format} {
181    binary format a3X3h5 foo 2
182} \x02\x00\x00
183test binary-6.10 {Tcl_BinaryObjCmd: format} {
184    binary format h2h3 23 456
185} \x32\x54\x06
186test binary-6.11 {Tcl_BinaryObjCmd: format} {
187    list [catch {binary format h2 foo} msg] $msg
188} {1 {expected hexadecimal string but got "foo" instead}}
189
190test binary-7.1 {Tcl_BinaryObjCmd: format} {
191    list [catch {binary format H} msg] $msg
192} {1 {not enough arguments for all format specifiers}}
193test binary-7.2 {Tcl_BinaryObjCmd: format} {
194    binary format H0 1
195} {}
196test binary-7.3 {Tcl_BinaryObjCmd: format} {
197    binary format H 1
198} \x10
199test binary-7.4 {Tcl_BinaryObjCmd: format} {
200    binary format H c
201} \xc0
202test binary-7.5 {Tcl_BinaryObjCmd: format} {
203    binary format H* baadf00d
204} \xba\xad\xf0\x0d
205test binary-7.6 {Tcl_BinaryObjCmd: format} {
206    binary format H4 c410
207} \xc4\x10
208test binary-7.7 {Tcl_BinaryObjCmd: format} {
209    binary format H6 c4102
210} \xc4\x10\x20
211test binary-7.8 {Tcl_BinaryObjCmd: format} {
212    binary format H5 c41023304
213} \xc4\x10\x20
214test binary-7.9 {Tcl_BinaryObjCmd: format} {
215    binary format a3X3H5 foo 2
216} \x20\x00\x00
217test binary-7.10 {Tcl_BinaryObjCmd: format} {
218    binary format H2H3 23 456
219} \x23\x45\x60
220test binary-7.11 {Tcl_BinaryObjCmd: format} {
221    list [catch {binary format H2 foo} msg] $msg
222} {1 {expected hexadecimal string but got "foo" instead}}
223
224test binary-8.1 {Tcl_BinaryObjCmd: format} {
225    list [catch {binary format c} msg] $msg
226} {1 {not enough arguments for all format specifiers}}
227test binary-8.2 {Tcl_BinaryObjCmd: format} {
228    list [catch {binary format c blat} msg] $msg
229} {1 {expected integer but got "blat"}}
230test binary-8.3 {Tcl_BinaryObjCmd: format} {
231    binary format c0 0x50
232} {}
233test binary-8.4 {Tcl_BinaryObjCmd: format} {
234    binary format c 0x50
235} P
236test binary-8.5 {Tcl_BinaryObjCmd: format} {
237    binary format c 0x5052
238} R
239test binary-8.6 {Tcl_BinaryObjCmd: format} {
240    binary format c2 {0x50 0x52}
241} PR
242test binary-8.7 {Tcl_BinaryObjCmd: format} {
243    binary format c2 {0x50 0x52 0x53}
244} PR
245test binary-8.8 {Tcl_BinaryObjCmd: format} {
246    binary format c* {0x50 0x52}
247} PR
248test binary-8.9 {Tcl_BinaryObjCmd: format} {
249    list [catch {binary format c2 {0x50}} msg] $msg
250} {1 {number of elements in list does not match count}}
251test binary-8.10 {Tcl_BinaryObjCmd: format} {
252    set a {0x50 0x51}
253    list [catch {binary format c $a} msg] $msg
254} [list 1 "expected integer but got \"0x50 0x51\""]
255test binary-8.11 {Tcl_BinaryObjCmd: format} {
256    set a {0x50 0x51}
257    binary format c1 $a
258} P
259
260test binary-9.1 {Tcl_BinaryObjCmd: format} {
261    list [catch {binary format s} msg] $msg
262} {1 {not enough arguments for all format specifiers}}
263test binary-9.2 {Tcl_BinaryObjCmd: format} {
264    list [catch {binary format s blat} msg] $msg
265} {1 {expected integer but got "blat"}}
266test binary-9.3 {Tcl_BinaryObjCmd: format} {
267    binary format s0 0x50
268} {}
269test binary-9.4 {Tcl_BinaryObjCmd: format} {
270    binary format s 0x50
271} P\x00
272test binary-9.5 {Tcl_BinaryObjCmd: format} {
273    binary format s 0x5052
274} RP
275test binary-9.6 {Tcl_BinaryObjCmd: format} {
276    binary format s 0x505251 0x53
277} QR
278test binary-9.7 {Tcl_BinaryObjCmd: format} {
279    binary format s2 {0x50 0x52}
280} P\x00R\x00
281test binary-9.8 {Tcl_BinaryObjCmd: format} {
282    binary format s* {0x5051 0x52}
283} QPR\x00
284test binary-9.9 {Tcl_BinaryObjCmd: format} {
285    binary format s2 {0x50 0x52 0x53} 0x54
286} P\x00R\x00
287test binary-9.10 {Tcl_BinaryObjCmd: format} {
288    list [catch {binary format s2 {0x50}} msg] $msg
289} {1 {number of elements in list does not match count}}
290test binary-9.11 {Tcl_BinaryObjCmd: format} {
291    set a {0x50 0x51}
292    list [catch {binary format s $a} msg] $msg
293} [list 1 "expected integer but got \"0x50 0x51\""]
294test binary-9.12 {Tcl_BinaryObjCmd: format} {
295    set a {0x50 0x51}
296    binary format s1 $a
297} P\x00
298
299test binary-10.1 {Tcl_BinaryObjCmd: format} {
300    list [catch {binary format S} msg] $msg
301} {1 {not enough arguments for all format specifiers}}
302test binary-10.2 {Tcl_BinaryObjCmd: format} {
303    list [catch {binary format S blat} msg] $msg
304} {1 {expected integer but got "blat"}}
305test binary-10.3 {Tcl_BinaryObjCmd: format} {
306    binary format S0 0x50
307} {}
308test binary-10.4 {Tcl_BinaryObjCmd: format} {
309    binary format S 0x50
310} \x00P
311test binary-10.5 {Tcl_BinaryObjCmd: format} {
312    binary format S 0x5052
313} PR
314test binary-10.6 {Tcl_BinaryObjCmd: format} {
315    binary format S 0x505251 0x53
316} RQ
317test binary-10.7 {Tcl_BinaryObjCmd: format} {
318    binary format S2 {0x50 0x52}
319} \x00P\x00R
320test binary-10.8 {Tcl_BinaryObjCmd: format} {
321    binary format S* {0x5051 0x52}
322} PQ\x00R
323test binary-10.9 {Tcl_BinaryObjCmd: format} {
324    binary format S2 {0x50 0x52 0x53} 0x54
325} \x00P\x00R
326test binary-10.10 {Tcl_BinaryObjCmd: format} {
327    list [catch {binary format S2 {0x50}} msg] $msg
328} {1 {number of elements in list does not match count}}
329test binary-10.11 {Tcl_BinaryObjCmd: format} {
330    set a {0x50 0x51}
331    list [catch {binary format S $a} msg] $msg
332} [list 1 "expected integer but got \"0x50 0x51\""]
333test binary-10.12 {Tcl_BinaryObjCmd: format} {
334    set a {0x50 0x51}
335    binary format S1 $a
336} \x00P
337
338test binary-11.1 {Tcl_BinaryObjCmd: format} {
339    list [catch {binary format i} msg] $msg
340} {1 {not enough arguments for all format specifiers}}
341test binary-11.2 {Tcl_BinaryObjCmd: format} {
342    list [catch {binary format i blat} msg] $msg
343} {1 {expected integer but got "blat"}}
344test binary-11.3 {Tcl_BinaryObjCmd: format} {
345    binary format i0 0x50
346} {}
347test binary-11.4 {Tcl_BinaryObjCmd: format} {
348    binary format i 0x50
349} P\x00\x00\x00
350test binary-11.5 {Tcl_BinaryObjCmd: format} {
351    binary format i 0x5052
352} RP\x00\x00
353test binary-11.6 {Tcl_BinaryObjCmd: format} {
354    binary format i 0x505251 0x53
355} QRP\x00
356test binary-11.7 {Tcl_BinaryObjCmd: format} {
357    binary format i1 {0x505251 0x53}
358} QRP\x00
359test binary-11.8 {Tcl_BinaryObjCmd: format} {
360    binary format i 0x53525150
361} PQRS
362test binary-11.9 {Tcl_BinaryObjCmd: format} {
363    binary format i2 {0x50 0x52}
364} P\x00\x00\x00R\x00\x00\x00
365test binary-11.10 {Tcl_BinaryObjCmd: format} {
366    binary format i* {0x50515253 0x52}
367} SRQPR\x00\x00\x00
368test binary-11.11 {Tcl_BinaryObjCmd: format} {
369    list [catch {binary format i2 {0x50}} msg] $msg
370} {1 {number of elements in list does not match count}}
371test binary-11.12 {Tcl_BinaryObjCmd: format} {
372    set a {0x50 0x51}
373    list [catch {binary format i $a} msg] $msg
374} [list 1 "expected integer but got \"0x50 0x51\""]
375test binary-11.13 {Tcl_BinaryObjCmd: format} {
376    set a {0x50 0x51}
377    binary format i1 $a
378} P\x00\x00\x00
379
380test binary-12.1 {Tcl_BinaryObjCmd: format} {
381    list [catch {binary format I} msg] $msg
382} {1 {not enough arguments for all format specifiers}}
383test binary-12.2 {Tcl_BinaryObjCmd: format} {
384    list [catch {binary format I blat} msg] $msg
385} {1 {expected integer but got "blat"}}
386test binary-12.3 {Tcl_BinaryObjCmd: format} {
387    binary format I0 0x50
388} {}
389test binary-12.4 {Tcl_BinaryObjCmd: format} {
390    binary format I 0x50
391} \x00\x00\x00P
392test binary-12.5 {Tcl_BinaryObjCmd: format} {
393    binary format I 0x5052
394} \x00\x00PR
395test binary-12.6 {Tcl_BinaryObjCmd: format} {
396    binary format I 0x505251 0x53
397} \x00PRQ
398test binary-12.7 {Tcl_BinaryObjCmd: format} {
399    binary format I1 {0x505251 0x53}
400} \x00PRQ
401test binary-12.8 {Tcl_BinaryObjCmd: format} {
402    binary format I 0x53525150
403} SRQP
404test binary-12.9 {Tcl_BinaryObjCmd: format} {
405    binary format I2 {0x50 0x52}
406} \x00\x00\x00P\x00\x00\x00R
407test binary-12.10 {Tcl_BinaryObjCmd: format} {
408    binary format I* {0x50515253 0x52}
409} PQRS\x00\x00\x00R
410test binary-12.11 {Tcl_BinaryObjCmd: format} {
411    list [catch {binary format i2 {0x50}} msg] $msg
412} {1 {number of elements in list does not match count}}
413test binary-12.12 {Tcl_BinaryObjCmd: format} {
414    set a {0x50 0x51}
415    list [catch {binary format I $a} msg] $msg
416} [list 1 "expected integer but got \"0x50 0x51\""]
417test binary-12.13 {Tcl_BinaryObjCmd: format} {
418    set a {0x50 0x51}
419    binary format I1 $a
420} \x00\x00\x00P
421
422test binary-13.1 {Tcl_BinaryObjCmd: format} {
423    list [catch {binary format f} msg] $msg
424} {1 {not enough arguments for all format specifiers}}
425test binary-13.2 {Tcl_BinaryObjCmd: format} {
426    list [catch {binary format f blat} msg] $msg
427} {1 {expected floating-point number but got "blat"}}
428test binary-13.3 {Tcl_BinaryObjCmd: format} {
429    binary format f0 1.6
430} {}
431test binary-13.4 {Tcl_BinaryObjCmd: format} bigEndian {
432    binary format f 1.6
433} \x3f\xcc\xcc\xcd
434test binary-13.5 {Tcl_BinaryObjCmd: format} littleEndian {
435    binary format f 1.6
436} \xcd\xcc\xcc\x3f
437test binary-13.6 {Tcl_BinaryObjCmd: format} bigEndian {
438    binary format f* {1.6 3.4}
439} \x3f\xcc\xcc\xcd\x40\x59\x99\x9a
440test binary-13.7 {Tcl_BinaryObjCmd: format} littleEndian {
441    binary format f* {1.6 3.4}
442} \xcd\xcc\xcc\x3f\x9a\x99\x59\x40
443test binary-13.8 {Tcl_BinaryObjCmd: format} bigEndian {
444    binary format f2 {1.6 3.4}
445} \x3f\xcc\xcc\xcd\x40\x59\x99\x9a
446test binary-13.9 {Tcl_BinaryObjCmd: format} littleEndian {
447    binary format f2 {1.6 3.4}
448} \xcd\xcc\xcc\x3f\x9a\x99\x59\x40
449test binary-13.10 {Tcl_BinaryObjCmd: format} bigEndian {
450    binary format f2 {1.6 3.4 5.6}
451} \x3f\xcc\xcc\xcd\x40\x59\x99\x9a
452test binary-13.11 {Tcl_BinaryObjCmd: format} littleEndian {
453    binary format f2 {1.6 3.4 5.6}
454} \xcd\xcc\xcc\x3f\x9a\x99\x59\x40
455test binary-13.12 {Tcl_BinaryObjCmd: float overflow} bigEndian {
456    binary format f -3.402825e+38
457} \xff\x7f\xff\xff
458test binary-13.13 {Tcl_BinaryObjCmd: float overflow} littleEndian {
459    binary format f -3.402825e+38
460} \xff\xff\x7f\xff
461test binary-13.14 {Tcl_BinaryObjCmd: float underflow} bigEndian {
462    binary format f -3.402825e-100
463} \x80\x00\x00\x00
464test binary-13.15 {Tcl_BinaryObjCmd: float underflow} littleEndian {
465    binary format f -3.402825e-100
466} \x00\x00\x00\x80
467test binary-13.16 {Tcl_BinaryObjCmd: format} {
468    list [catch {binary format f2 {1.6}} msg] $msg
469} {1 {number of elements in list does not match count}}
470test binary-13.17 {Tcl_BinaryObjCmd: format} {
471    set a {1.6 3.4}
472    list [catch {binary format f $a} msg] $msg
473} [list 1 "expected floating-point number but got \"1.6 3.4\""]
474test binary-13.18 {Tcl_BinaryObjCmd: format} bigEndian {
475    set a {1.6 3.4}
476    binary format f1 $a
477} \x3f\xcc\xcc\xcd
478test binary-13.19 {Tcl_BinaryObjCmd: format} littleEndian {
479    set a {1.6 3.4}
480    binary format f1 $a
481} \xcd\xcc\xcc\x3f
482
483test binary-14.1 {Tcl_BinaryObjCmd: format} {
484    list [catch {binary format d} msg] $msg
485} {1 {not enough arguments for all format specifiers}}
486test binary-14.2 {Tcl_BinaryObjCmd: format} {
487    list [catch {binary format d blat} msg] $msg
488} {1 {expected floating-point number but got "blat"}}
489test binary-14.3 {Tcl_BinaryObjCmd: format} {
490    binary format d0 1.6
491} {}
492test binary-14.4 {Tcl_BinaryObjCmd: format} bigEndian {
493    binary format d 1.6
494} \x3f\xf9\x99\x99\x99\x99\x99\x9a
495test binary-14.5 {Tcl_BinaryObjCmd: format} littleEndian {
496    binary format d 1.6
497} \x9a\x99\x99\x99\x99\x99\xf9\x3f
498test binary-14.6 {Tcl_BinaryObjCmd: format} bigEndian {
499    binary format d* {1.6 3.4}
500} \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33
501test binary-14.7 {Tcl_BinaryObjCmd: format} littleEndian {
502    binary format d* {1.6 3.4}
503} \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40
504test binary-14.8 {Tcl_BinaryObjCmd: format} bigEndian {
505    binary format d2 {1.6 3.4}
506} \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33
507test binary-14.9 {Tcl_BinaryObjCmd: format} littleEndian {
508    binary format d2 {1.6 3.4}
509} \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40
510test binary-14.10 {Tcl_BinaryObjCmd: format} bigEndian {
511    binary format d2 {1.6 3.4 5.6}
512} \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33
513test binary-14.11 {Tcl_BinaryObjCmd: format} littleEndian {
514    binary format d2 {1.6 3.4 5.6}
515} \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40
516test binary-14.14 {Tcl_BinaryObjCmd: format} {
517    list [catch {binary format d2 {1.6}} msg] $msg
518} {1 {number of elements in list does not match count}}
519test binary-14.15 {Tcl_BinaryObjCmd: format} {
520    set a {1.6 3.4}
521    list [catch {binary format d $a} msg] $msg
522} [list 1 "expected floating-point number but got \"1.6 3.4\""]
523test binary-14.16 {Tcl_BinaryObjCmd: format} bigEndian {
524    set a {1.6 3.4}
525    binary format d1 $a
526} \x3f\xf9\x99\x99\x99\x99\x99\x9a
527test binary-14.17 {Tcl_BinaryObjCmd: format} littleEndian {
528    set a {1.6 3.4}
529    binary format d1 $a
530} \x9a\x99\x99\x99\x99\x99\xf9\x3f
531test binary-14.18 {FormatNumber: Bug 1116542} {
532    binary scan [binary format d 1.25] d w
533    set w
534} 1.25
535
536test binary-15.1 {Tcl_BinaryObjCmd: format} {
537    list [catch {binary format ax*a "y" "z"} msg] $msg
538} {1 {cannot use "*" in format string with "x"}}
539test binary-15.2 {Tcl_BinaryObjCmd: format} {
540    binary format axa "y" "z"
541} y\x00z
542test binary-15.3 {Tcl_BinaryObjCmd: format} {
543    binary format ax3a "y" "z"
544} y\x00\x00\x00z
545test binary-15.4 {Tcl_BinaryObjCmd: format} {
546    binary format a*X3x3a* "foo" "z"
547} \x00\x00\x00z
548test binary-15.5 {Tcl_BinaryObjCmd: format - bug #1923966} {
549    binary format x0s 1
550} \x01\x00
551test binary-15.6 {Tcl_BinaryObjCmd: format - bug #1923966} {
552    binary format x0ss 1 1
553} \x01\x00\x01\x00
554test binary-15.7 {Tcl_BinaryObjCmd: format - bug #1923966} {
555    binary format x1s 1
556} \x00\x01\x00
557test binary-15.8 {Tcl_BinaryObjCmd: format - bug #1923966} {
558    binary format x1ss 1 1
559} \x00\x01\x00\x01\x00
560
561test binary-16.1 {Tcl_BinaryObjCmd: format} {
562    binary format a*X*a "foo" "z"
563} zoo
564test binary-16.2 {Tcl_BinaryObjCmd: format} {
565    binary format aX3a "y" "z"
566} z
567test binary-16.3 {Tcl_BinaryObjCmd: format} {
568    binary format a*Xa* "foo" "zy"
569} fozy
570test binary-16.4 {Tcl_BinaryObjCmd: format} {
571    binary format a*X3a "foobar" "z"
572} foozar
573test binary-16.5 {Tcl_BinaryObjCmd: format} {
574    binary format a*X3aX2a "foobar" "z" "b"
575} fobzar
576
577test binary-17.1 {Tcl_BinaryObjCmd: format} {
578    binary format @1
579} \x00
580test binary-17.2 {Tcl_BinaryObjCmd: format} {
581    binary format @5a2 "ab"
582} \x00\x00\x00\x00\x00\x61\x62
583test binary-17.3 {Tcl_BinaryObjCmd: format} {
584    binary format {a*  @0  a2 @* a*} "foobar" "ab" "blat"
585} abobarblat
586
587test binary-18.1 {Tcl_BinaryObjCmd: format} {
588    list [catch {binary format u0a3 abc abd} msg] $msg
589} {1 {bad field specifier "u"}}
590
591
592test binary-19.1 {Tcl_BinaryObjCmd: errors} {
593    list [catch {binary s} msg] $msg
594} {1 {wrong # args: should be "binary scan value formatString ?varName varName ...?"}}
595test binary-19.2 {Tcl_BinaryObjCmd: errors} {
596    list [catch {binary scan foo} msg] $msg
597} {1 {wrong # args: should be "binary scan value formatString ?varName varName ...?"}}
598test binary-19.3 {Tcl_BinaryObjCmd: scan} {
599    binary scan {} {}
600} 0
601
602test binary-20.1 {Tcl_BinaryObjCmd: scan} {
603    list [catch {binary scan abc a} msg] $msg
604} {1 {not enough arguments for all format specifiers}}
605test binary-20.2 {Tcl_BinaryObjCmd: scan} {
606    catch {unset arg1}
607    set arg1 1
608    list [catch {binary scan abc a arg1(a)} msg] $msg
609} {1 {can't set "arg1(a)": variable isn't array}}
610test binary-20.3 {Tcl_BinaryObjCmd: scan} {
611    catch {unset arg1}
612    set arg1 abc
613    list [binary scan abc a0 arg1] $arg1
614} {1 {}}
615test binary-20.4 {Tcl_BinaryObjCmd: scan} {
616    catch {unset arg1}
617    list [binary scan abc a* arg1] $arg1
618} {1 abc}
619test binary-20.5 {Tcl_BinaryObjCmd: scan} {
620    catch {unset arg1}
621    list [binary scan abc a5 arg1] [info exists arg1]
622} {0 0}
623test binary-20.6 {Tcl_BinaryObjCmd: scan} {
624    set arg1 foo
625    list [binary scan abc a2 arg1] $arg1
626} {1 ab}
627test binary-20.7 {Tcl_BinaryObjCmd: scan} {
628    catch {unset arg1}
629    catch {unset arg2}
630    list [binary scan abcdef a2a2 arg1 arg2] $arg1 $arg2
631} {2 ab cd}
632test binary-20.8 {Tcl_BinaryObjCmd: scan} {
633    catch {unset arg1}
634    list [binary scan abc a2 arg1(a)] $arg1(a)
635} {1 ab}
636test binary-20.9 {Tcl_BinaryObjCmd: scan} {
637    catch {unset arg1}
638    list [binary scan abc a arg1(a)] $arg1(a)
639} {1 a}
640
641test binary-21.1 {Tcl_BinaryObjCmd: scan} {
642    list [catch {binary scan abc A} msg] $msg
643} {1 {not enough arguments for all format specifiers}}
644test binary-21.2 {Tcl_BinaryObjCmd: scan} {
645    catch {unset arg1}
646    set arg1 1
647    list [catch {binary scan abc A arg1(a)} msg] $msg
648} {1 {can't set "arg1(a)": variable isn't array}}
649test binary-21.3 {Tcl_BinaryObjCmd: scan} {
650    catch {unset arg1}
651    set arg1 abc
652    list [binary scan abc A0 arg1] $arg1
653} {1 {}}
654test binary-21.4 {Tcl_BinaryObjCmd: scan} {
655    catch {unset arg1}
656    list [binary scan abc A* arg1] $arg1
657} {1 abc}
658test binary-21.5 {Tcl_BinaryObjCmd: scan} {
659    catch {unset arg1}
660    list [binary scan abc A5 arg1] [info exists arg1]
661} {0 0}
662test binary-21.6 {Tcl_BinaryObjCmd: scan} {
663    set arg1 foo
664    list [binary scan abc A2 arg1] $arg1
665} {1 ab}
666test binary-21.7 {Tcl_BinaryObjCmd: scan} {
667    catch {unset arg1}
668    catch {unset arg2}
669    list [binary scan abcdef A2A2 arg1 arg2] $arg1 $arg2
670} {2 ab cd}
671test binary-21.8 {Tcl_BinaryObjCmd: scan} {
672    catch {unset arg1}
673    list [binary scan abc A2 arg1(a)] $arg1(a)
674} {1 ab}
675test binary-21.9 {Tcl_BinaryObjCmd: scan} {
676    catch {unset arg1}
677    list [binary scan abc A2 arg1(a)] $arg1(a)
678} {1 ab}
679test binary-21.10 {Tcl_BinaryObjCmd: scan} {
680    catch {unset arg1}
681    list [binary scan abc A arg1(a)] $arg1(a)
682} {1 a}
683test binary-21.11 {Tcl_BinaryObjCmd: scan} {
684    catch {unset arg1}
685    list [binary scan "abc def \x00  " A* arg1] $arg1
686} {1 {abc def}}
687test binary-21.12 {Tcl_BinaryObjCmd: scan} {
688    catch {unset arg1}
689    list [binary scan "abc def \x00ghi  " A* arg1] $arg1
690} [list 1 "abc def \x00ghi"]
691
692test binary-22.1 {Tcl_BinaryObjCmd: scan} {
693    list [catch {binary scan abc b} msg] $msg
694} {1 {not enough arguments for all format specifiers}}
695test binary-22.2 {Tcl_BinaryObjCmd: scan} {
696    catch {unset arg1}
697    list [binary scan \x52\x53 b* arg1] $arg1
698} {1 0100101011001010}
699test binary-22.3 {Tcl_BinaryObjCmd: scan} {
700    catch {unset arg1}
701    list [binary scan \x82\x53 b arg1] $arg1
702} {1 0}
703test binary-22.4 {Tcl_BinaryObjCmd: scan} {
704    catch {unset arg1}
705    list [binary scan \x82\x53 b1 arg1] $arg1
706} {1 0}
707test binary-22.5 {Tcl_BinaryObjCmd: scan} {
708    catch {unset arg1}
709    list [binary scan \x82\x53 b0 arg1] $arg1
710} {1 {}}
711test binary-22.6 {Tcl_BinaryObjCmd: scan} {
712    catch {unset arg1}
713    list [binary scan \x52\x53 b5 arg1] $arg1
714} {1 01001}
715test binary-22.7 {Tcl_BinaryObjCmd: scan} {
716    catch {unset arg1}
717    list [binary scan \x52\x53 b8 arg1] $arg1
718} {1 01001010}
719test binary-22.8 {Tcl_BinaryObjCmd: scan} {
720    catch {unset arg1}
721    list [binary scan \x52\x53 b14 arg1] $arg1
722} {1 01001010110010}
723test binary-22.9 {Tcl_BinaryObjCmd: scan} {
724    catch {unset arg1}
725    set arg1 foo
726    list [binary scan \x52 b14 arg1] $arg1
727} {0 foo}
728test binary-22.10 {Tcl_BinaryObjCmd: scan} {
729    catch {unset arg1}
730    set arg1 1
731    list [catch {binary scan \x52\x53 b1 arg1(a)} msg] $msg
732} {1 {can't set "arg1(a)": variable isn't array}}
733test binary-22.11 {Tcl_BinaryObjCmd: scan} {
734    catch {unset arg1 arg2}
735    set arg1 foo
736    set arg2 bar
737    list [binary scan \x07\x87\x05 b5b* arg1 arg2] $arg1 $arg2
738} {2 11100 1110000110100000}
739
740
741test binary-23.1 {Tcl_BinaryObjCmd: scan} {
742    list [catch {binary scan abc B} msg] $msg
743} {1 {not enough arguments for all format specifiers}}
744test binary-23.2 {Tcl_BinaryObjCmd: scan} {
745    catch {unset arg1}
746    list [binary scan \x52\x53 B* arg1] $arg1
747} {1 0101001001010011}
748test binary-23.3 {Tcl_BinaryObjCmd: scan} {
749    catch {unset arg1}
750    list [binary scan \x82\x53 B arg1] $arg1
751} {1 1}
752test binary-23.4 {Tcl_BinaryObjCmd: scan} {
753    catch {unset arg1}
754    list [binary scan \x82\x53 B1 arg1] $arg1
755} {1 1}
756test binary-23.5 {Tcl_BinaryObjCmd: scan} {
757    catch {unset arg1}
758    list [binary scan \x52\x53 B0 arg1] $arg1
759} {1 {}}
760test binary-23.6 {Tcl_BinaryObjCmd: scan} {
761    catch {unset arg1}
762    list [binary scan \x52\x53 B5 arg1] $arg1
763} {1 01010}
764test binary-23.7 {Tcl_BinaryObjCmd: scan} {
765    catch {unset arg1}
766    list [binary scan \x52\x53 B8 arg1] $arg1
767} {1 01010010}
768test binary-23.8 {Tcl_BinaryObjCmd: scan} {
769    catch {unset arg1}
770    list [binary scan \x52\x53 B14 arg1] $arg1
771} {1 01010010010100}
772test binary-23.9 {Tcl_BinaryObjCmd: scan} {
773    catch {unset arg1}
774    set arg1 foo
775    list [binary scan \x52 B14 arg1] $arg1
776} {0 foo}
777test binary-23.10 {Tcl_BinaryObjCmd: scan} {
778    catch {unset arg1}
779    set arg1 1
780    list [catch {binary scan \x52\x53 B1 arg1(a)} msg] $msg
781} {1 {can't set "arg1(a)": variable isn't array}}
782test binary-23.11 {Tcl_BinaryObjCmd: scan} {
783    catch {unset arg1 arg2}
784    set arg1 foo
785    set arg2 bar
786    list [binary scan \x70\x87\x05 B5B* arg1 arg2] $arg1 $arg2
787} {2 01110 1000011100000101}
788
789test binary-24.1 {Tcl_BinaryObjCmd: scan} {
790    list [catch {binary scan abc h} msg] $msg
791} {1 {not enough arguments for all format specifiers}}
792test binary-24.2 {Tcl_BinaryObjCmd: scan} {
793    catch {unset arg1}
794    list [binary scan \x52\xa3 h* arg1] $arg1
795} {1 253a}
796test binary-24.3 {Tcl_BinaryObjCmd: scan} {
797    catch {unset arg1}
798    list [binary scan \xc2\xa3 h arg1] $arg1
799} {1 2}
800test binary-24.4 {Tcl_BinaryObjCmd: scan} {
801    catch {unset arg1}
802    list [binary scan \x82\x53 h1 arg1] $arg1
803} {1 2}
804test binary-24.5 {Tcl_BinaryObjCmd: scan} {
805    catch {unset arg1}
806    list [binary scan \x52\x53 h0 arg1] $arg1
807} {1 {}}
808test binary-24.6 {Tcl_BinaryObjCmd: scan} {
809    catch {unset arg1}
810    list [binary scan \xf2\x53 h2 arg1] $arg1
811} {1 2f}
812test binary-24.7 {Tcl_BinaryObjCmd: scan} {
813    catch {unset arg1}
814    list [binary scan \x52\x53 h3 arg1] $arg1
815} {1 253}
816test binary-24.8 {Tcl_BinaryObjCmd: scan} {
817    catch {unset arg1}
818    set arg1 foo
819    list [binary scan \x52 h3 arg1] $arg1
820} {0 foo}
821test binary-24.9 {Tcl_BinaryObjCmd: scan} {
822    catch {unset arg1}
823    set arg1 1
824    list [catch {binary scan \x52\x53 h1 arg1(a)} msg] $msg
825} {1 {can't set "arg1(a)": variable isn't array}}
826test binary-24.10 {Tcl_BinaryObjCmd: scan} {
827    catch {unset arg1 arg2}
828    set arg1 foo
829    set arg2 bar
830    list [binary scan \x70\x87\x05 h2h* arg1 arg2] $arg1 $arg2
831} {2 07 7850}
832
833test binary-25.1 {Tcl_BinaryObjCmd: scan} {
834    list [catch {binary scan abc H} msg] $msg
835} {1 {not enough arguments for all format specifiers}}
836test binary-25.2 {Tcl_BinaryObjCmd: scan} {
837    catch {unset arg1}
838    list [binary scan \x52\xa3 H* arg1] $arg1
839} {1 52a3}
840test binary-25.3 {Tcl_BinaryObjCmd: scan} {
841    catch {unset arg1}
842    list [binary scan \xc2\xa3 H arg1] $arg1
843} {1 c}
844test binary-25.4 {Tcl_BinaryObjCmd: scan} {
845    catch {unset arg1}
846    list [binary scan \x82\x53 H1 arg1] $arg1
847} {1 8}
848test binary-25.5 {Tcl_BinaryObjCmd: scan} {
849    catch {unset arg1}
850    list [binary scan \x52\x53 H0 arg1] $arg1
851} {1 {}}
852test binary-25.6 {Tcl_BinaryObjCmd: scan} {
853    catch {unset arg1}
854    list [binary scan \xf2\x53 H2 arg1] $arg1
855} {1 f2}
856test binary-25.7 {Tcl_BinaryObjCmd: scan} {
857    catch {unset arg1}
858    list [binary scan \x52\x53 H3 arg1] $arg1
859} {1 525}
860test binary-25.8 {Tcl_BinaryObjCmd: scan} {
861    catch {unset arg1}
862    set arg1 foo
863    list [binary scan \x52 H3 arg1] $arg1
864} {0 foo}
865test binary-25.9 {Tcl_BinaryObjCmd: scan} {
866    catch {unset arg1}
867    set arg1 1
868    list [catch {binary scan \x52\x53 H1 arg1(a)} msg] $msg
869} {1 {can't set "arg1(a)": variable isn't array}}
870test binary-25.10 {Tcl_BinaryObjCmd: scan} {
871    catch {unset arg1 arg2}
872    set arg1 foo
873    set arg2 bar
874    list [binary scan \x70\x87\x05 H2H* arg1 arg2] $arg1 $arg2
875} {2 70 8705}
876
877test binary-26.1 {Tcl_BinaryObjCmd: scan} {
878    list [catch {binary scan abc c} msg] $msg
879} {1 {not enough arguments for all format specifiers}}
880test binary-26.2 {Tcl_BinaryObjCmd: scan} {
881    catch {unset arg1}
882    list [binary scan \x52\xa3 c* arg1] $arg1
883} {1 {82 -93}}
884test binary-26.3 {Tcl_BinaryObjCmd: scan} {
885    catch {unset arg1}
886    list [binary scan \x52\xa3 c arg1] $arg1
887} {1 82}
888test binary-26.4 {Tcl_BinaryObjCmd: scan} {
889    catch {unset arg1}
890    list [binary scan \x52\xa3 c1 arg1] $arg1
891} {1 82}
892test binary-26.5 {Tcl_BinaryObjCmd: scan} {
893    catch {unset arg1}
894    list [binary scan \x52\xa3 c0 arg1] $arg1
895} {1 {}}
896test binary-26.6 {Tcl_BinaryObjCmd: scan} {
897    catch {unset arg1}
898    list [binary scan \x52\xa3 c2 arg1] $arg1
899} {1 {82 -93}}
900test binary-26.7 {Tcl_BinaryObjCmd: scan} {
901    catch {unset arg1}
902    list [binary scan \xff c arg1] $arg1
903} {1 -1}
904test binary-26.8 {Tcl_BinaryObjCmd: scan} {
905    catch {unset arg1}
906    set arg1 foo
907    list [binary scan \x52 c3 arg1] $arg1
908} {0 foo}
909test binary-26.9 {Tcl_BinaryObjCmd: scan} {
910    catch {unset arg1}
911    set arg1 1
912    list [catch {binary scan \x52\x53 c1 arg1(a)} msg] $msg
913} {1 {can't set "arg1(a)": variable isn't array}}
914test binary-26.10 {Tcl_BinaryObjCmd: scan} {
915    catch {unset arg1 arg2}
916    set arg1 foo
917    set arg2 bar
918    list [binary scan \x70\x87\x05 c2c* arg1 arg2] $arg1 $arg2
919} {2 {112 -121} 5}
920test binary-26.11 {Tcl_BinaryObjCmd: scan} {
921    catch {unset arg1}
922    list [binary scan \x52\xa3 cu* arg1] $arg1
923} {1 {82 163}}
924test binary-26.12 {Tcl_BinaryObjCmd: scan} {
925    catch {unset arg1}
926    list [binary scan \x52\xa3 cu arg1] $arg1
927} {1 82}
928test binary-26.13 {Tcl_BinaryObjCmd: scan} {
929    catch {unset arg1}
930    list [binary scan \xff cu arg1] $arg1
931} {1 255}
932test binary-26.14 {Tcl_BinaryObjCmd: scan} {
933    catch {unset arg1 arg2}
934    set arg1 foo
935    set arg2 bar
936    list [binary scan \x80\x80 cuc arg1 arg2] $arg1 $arg2
937} {2 128 -128}
938test binary-26.15 {Tcl_BinaryObjCmd: scan} {
939    catch {unset arg1 arg2}
940    set arg1 foo
941    set arg2 bar
942    list [binary scan \x80\x80 ccu arg1 arg2] $arg1 $arg2
943} {2 -128 128}
944
945test binary-27.1 {Tcl_BinaryObjCmd: scan} {
946    list [catch {binary scan abc s} msg] $msg
947} {1 {not enough arguments for all format specifiers}}
948test binary-27.2 {Tcl_BinaryObjCmd: scan} {
949    catch {unset arg1}
950    list [binary scan \x52\xa3\x53\x54 s* arg1] $arg1
951} {1 {-23726 21587}}
952test binary-27.3 {Tcl_BinaryObjCmd: scan} {
953    catch {unset arg1}
954    list [binary scan \x52\xa3\x53\x54 s arg1] $arg1
955} {1 -23726}
956test binary-27.4 {Tcl_BinaryObjCmd: scan} {
957    catch {unset arg1}
958    list [binary scan \x52\xa3 s1 arg1] $arg1
959} {1 -23726}
960test binary-27.5 {Tcl_BinaryObjCmd: scan} {
961    catch {unset arg1}
962    list [binary scan \x52\xa3 s0 arg1] $arg1
963} {1 {}}
964test binary-27.6 {Tcl_BinaryObjCmd: scan} {
965    catch {unset arg1}
966    list [binary scan \x52\xa3\x53\x54 s2 arg1] $arg1
967} {1 {-23726 21587}}
968test binary-27.7 {Tcl_BinaryObjCmd: scan} {
969    catch {unset arg1}
970    set arg1 foo
971    list [binary scan \x52 s1 arg1] $arg1
972} {0 foo}
973test binary-27.8 {Tcl_BinaryObjCmd: scan} {
974    catch {unset arg1}
975    set arg1 1
976    list [catch {binary scan \x52\x53 s1 arg1(a)} msg] $msg
977} {1 {can't set "arg1(a)": variable isn't array}}
978test binary-27.9 {Tcl_BinaryObjCmd: scan} {
979    catch {unset arg1 arg2}
980    set arg1 foo
981    set arg2 bar
982    list [binary scan \x52\xa3\x53\x54\x05 s2c* arg1 arg2] $arg1 $arg2
983} {2 {-23726 21587} 5}
984test binary-27.10 {Tcl_BinaryObjCmd: scan} {
985    catch {unset arg1}
986    list [binary scan \x52\xa3\x53\x54 su* arg1] $arg1
987} {1 {41810 21587}}
988test binary-27.11 {Tcl_BinaryObjCmd: scan} {
989    catch {unset arg1 arg2}
990    set arg1 foo
991    set arg2 bar
992    list [binary scan \xff\xff\xff\xff sus arg1 arg2] $arg1 $arg2
993} {2 65535 -1}
994test binary-27.12 {Tcl_BinaryObjCmd: scan} {
995    catch {unset arg1 arg2}
996    set arg1 foo
997    set arg2 bar
998    list [binary scan \xff\xff\xff\xff ssu arg1 arg2] $arg1 $arg2
999} {2 -1 65535}
1000
1001test binary-28.1 {Tcl_BinaryObjCmd: scan} {
1002    list [catch {binary scan abc S} msg] $msg
1003} {1 {not enough arguments for all format specifiers}}
1004test binary-28.2 {Tcl_BinaryObjCmd: scan} {
1005    catch {unset arg1}
1006    list [binary scan \x52\xa3\x53\x54 S* arg1] $arg1
1007} {1 {21155 21332}}
1008test binary-28.3 {Tcl_BinaryObjCmd: scan} {
1009    catch {unset arg1}
1010    list [binary scan \x52\xa3\x53\x54 S arg1] $arg1
1011} {1 21155}
1012test binary-28.4 {Tcl_BinaryObjCmd: scan} {
1013    catch {unset arg1}
1014    list [binary scan \x52\xa3 S1 arg1] $arg1
1015} {1 21155}
1016test binary-28.5 {Tcl_BinaryObjCmd: scan} {
1017    catch {unset arg1}
1018    list [binary scan \x52\xa3 S0 arg1] $arg1
1019} {1 {}}
1020test binary-28.6 {Tcl_BinaryObjCmd: scan} {
1021    catch {unset arg1}
1022    list [binary scan \x52\xa3\x53\x54 S2 arg1] $arg1
1023} {1 {21155 21332}}
1024test binary-28.7 {Tcl_BinaryObjCmd: scan} {
1025    catch {unset arg1}
1026    set arg1 foo
1027    list [binary scan \x52 S1 arg1] $arg1
1028} {0 foo}
1029test binary-28.8 {Tcl_BinaryObjCmd: scan} {
1030    catch {unset arg1}
1031    set arg1 1
1032    list [catch {binary scan \x52\x53 S1 arg1(a)} msg] $msg
1033} {1 {can't set "arg1(a)": variable isn't array}}
1034test binary-28.9 {Tcl_BinaryObjCmd: scan} {
1035    catch {unset arg1 arg2}
1036    set arg1 foo
1037    set arg2 bar
1038    list [binary scan \x52\xa3\x53\x54\x05 S2c* arg1 arg2] $arg1 $arg2
1039} {2 {21155 21332} 5}
1040test binary-28.10 {Tcl_BinaryObjCmd: scan} {
1041    catch {unset arg1}
1042    list [binary scan \x52\xa3\x53\x54 Su* arg1] $arg1
1043} {1 {21155 21332}}
1044test binary-28.11 {Tcl_BinaryObjCmd: scan} {
1045    catch {unset arg1}
1046    list [binary scan \xa3\x52\x54\x53 Su* arg1] $arg1
1047} {1 {41810 21587}}
1048
1049test binary-29.1 {Tcl_BinaryObjCmd: scan} {
1050    list [catch {binary scan abc i} msg] $msg
1051} {1 {not enough arguments for all format specifiers}}
1052test binary-29.2 {Tcl_BinaryObjCmd: scan} {
1053    catch {unset arg1}
1054    list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 i* arg1] $arg1
1055} {1 {1414767442 67305985}}
1056test binary-29.3 {Tcl_BinaryObjCmd: scan} {
1057    catch {unset arg1}
1058    list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 i arg1] $arg1
1059} {1 1414767442}
1060test binary-29.4 {Tcl_BinaryObjCmd: scan} {
1061    catch {unset arg1}
1062    list [binary scan \x52\xa3\x53\x54 i1 arg1] $arg1
1063} {1 1414767442}
1064test binary-29.5 {Tcl_BinaryObjCmd: scan} {
1065    catch {unset arg1}
1066    list [binary scan \x52\xa3\x53 i0 arg1] $arg1
1067} {1 {}}
1068test binary-29.6 {Tcl_BinaryObjCmd: scan} {
1069    catch {unset arg1}
1070    list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 i2 arg1] $arg1
1071} {1 {1414767442 67305985}}
1072test binary-29.7 {Tcl_BinaryObjCmd: scan} {
1073    catch {unset arg1}
1074    set arg1 foo
1075    list [binary scan \x52 i1 arg1] $arg1
1076} {0 foo}
1077test binary-29.8 {Tcl_BinaryObjCmd: scan} {
1078    catch {unset arg1}
1079    set arg1 1
1080    list [catch {binary scan \x52\x53\x53\x54 i1 arg1(a)} msg] $msg
1081} {1 {can't set "arg1(a)": variable isn't array}}
1082test binary-29.9 {Tcl_BinaryObjCmd: scan} {
1083    catch {unset arg1 arg2}
1084    set arg1 foo
1085    set arg2 bar
1086    list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04\x05 i2c* arg1 arg2] $arg1 $arg2
1087} {2 {1414767442 67305985} 5}
1088test binary-29.10 {Tcl_BinaryObjCmd: scan} {
1089    catch {unset arg1 arg2}
1090    list [binary scan \xff\xff\xff\xff\xff\xff\xff\xff iui arg1 arg2] $arg1 $arg2
1091} {2 4294967295 -1}
1092test binary-29.11 {Tcl_BinaryObjCmd: scan} {
1093    catch {unset arg1 arg2}
1094    list [binary scan \xff\xff\xff\xff\xff\xff\xff\xff iiu arg1 arg2] $arg1 $arg2
1095} {2 -1 4294967295}
1096test binary-29.12 {Tcl_BinaryObjCmd: scan} {
1097    catch {unset arg1 arg2}
1098    list [binary scan \x80\x00\x00\x00\x00\x00\x00\x80 iuiu arg1 arg2] $arg1 $arg2
1099} {2 128 2147483648}
1100
1101test binary-30.1 {Tcl_BinaryObjCmd: scan} {
1102    list [catch {binary scan abc I} msg] $msg
1103} {1 {not enough arguments for all format specifiers}}
1104test binary-30.2 {Tcl_BinaryObjCmd: scan} {
1105    catch {unset arg1}
1106    list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 I* arg1] $arg1
1107} {1 {1386435412 16909060}}
1108test binary-30.3 {Tcl_BinaryObjCmd: scan} {
1109    catch {unset arg1}
1110    list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 I arg1] $arg1
1111} {1 1386435412}
1112test binary-30.4 {Tcl_BinaryObjCmd: scan} {
1113    catch {unset arg1}
1114    list [binary scan \x52\xa3\x53\x54 I1 arg1] $arg1
1115} {1 1386435412}
1116test binary-30.5 {Tcl_BinaryObjCmd: scan} {
1117    catch {unset arg1}
1118    list [binary scan \x52\xa3\x53 I0 arg1] $arg1
1119} {1 {}}
1120test binary-30.6 {Tcl_BinaryObjCmd: scan} {
1121    catch {unset arg1}
1122    list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 I2 arg1] $arg1
1123} {1 {1386435412 16909060}}
1124test binary-30.7 {Tcl_BinaryObjCmd: scan} {
1125    catch {unset arg1}
1126    set arg1 foo
1127    list [binary scan \x52 I1 arg1] $arg1
1128} {0 foo}
1129test binary-30.8 {Tcl_BinaryObjCmd: scan} {
1130    catch {unset arg1}
1131    set arg1 1
1132    list [catch {binary scan \x52\x53\x53\x54 I1 arg1(a)} msg] $msg
1133} {1 {can't set "arg1(a)": variable isn't array}}
1134test binary-30.9 {Tcl_BinaryObjCmd: scan} {
1135    catch {unset arg1 arg2}
1136    set arg1 foo
1137    set arg2 bar
1138    list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04\x05 I2c* arg1 arg2] $arg1 $arg2
1139} {2 {1386435412 16909060} 5}
1140test binary-30.10 {Tcl_BinaryObjCmd: scan} {
1141    catch {unset arg1 arg2}
1142    list [binary scan \xff\xff\xff\xff\xff\xff\xff\xff IuI arg1 arg2] $arg1 $arg2
1143} {2 4294967295 -1}
1144test binary-30.11 {Tcl_BinaryObjCmd: scan} {
1145    catch {unset arg1 arg2}
1146    list [binary scan \xff\xff\xff\xff\xff\xff\xff\xff IIu arg1 arg2] $arg1 $arg2
1147} {2 -1 4294967295}
1148test binary-30.12 {Tcl_BinaryObjCmd: scan} {
1149    catch {unset arg1 arg2}
1150    list [binary scan \x80\x00\x00\x00\x00\x00\x00\x80 IuIu arg1 arg2] $arg1 $arg2
1151} {2 2147483648 128}
1152
1153test binary-31.1 {Tcl_BinaryObjCmd: scan} {
1154    list [catch {binary scan abc f} msg] $msg
1155} {1 {not enough arguments for all format specifiers}}
1156test binary-31.2 {Tcl_BinaryObjCmd: scan} bigEndian {
1157    catch {unset arg1}
1158    list [binary scan \x3f\xcc\xcc\xcd\x40\x59\x99\x9a f* arg1] $arg1
1159} {1 {1.600000023841858 3.4000000953674316}}
1160test binary-31.3 {Tcl_BinaryObjCmd: scan} littleEndian {
1161    catch {unset arg1}
1162    list [binary scan \xcd\xcc\xcc\x3f\x9a\x99\x59\x40 f* arg1] $arg1
1163} {1 {1.600000023841858 3.4000000953674316}}
1164test binary-31.4 {Tcl_BinaryObjCmd: scan} bigEndian {
1165    catch {unset arg1}
1166    list [binary scan \x3f\xcc\xcc\xcd\x40\x59\x99\x9a f arg1] $arg1
1167} {1 1.600000023841858}
1168test binary-31.5 {Tcl_BinaryObjCmd: scan} littleEndian {
1169    catch {unset arg1}
1170    list [binary scan \xcd\xcc\xcc\x3f\x9a\x99\x59\x40 f arg1] $arg1
1171} {1 1.600000023841858}
1172test binary-31.6 {Tcl_BinaryObjCmd: scan} bigEndian {
1173    catch {unset arg1}
1174    list [binary scan \x3f\xcc\xcc\xcd f1 arg1] $arg1
1175} {1 1.600000023841858}
1176test binary-31.7 {Tcl_BinaryObjCmd: scan} littleEndian {
1177    catch {unset arg1}
1178    list [binary scan \xcd\xcc\xcc\x3f f1 arg1] $arg1
1179} {1 1.600000023841858}
1180test binary-31.8 {Tcl_BinaryObjCmd: scan} bigEndian {
1181    catch {unset arg1}
1182    list [binary scan \x3f\xcc\xcc\xcd f0 arg1] $arg1
1183} {1 {}}
1184test binary-31.9 {Tcl_BinaryObjCmd: scan} littleEndian {
1185    catch {unset arg1}
1186    list [binary scan \xcd\xcc\xcc\x3f f0 arg1] $arg1
1187} {1 {}}
1188test binary-31.10 {Tcl_BinaryObjCmd: scan} bigEndian {
1189    catch {unset arg1}
1190    list [binary scan \x3f\xcc\xcc\xcd\x40\x59\x99\x9a f2 arg1] $arg1
1191} {1 {1.600000023841858 3.4000000953674316}}
1192test binary-31.11 {Tcl_BinaryObjCmd: scan} littleEndian {
1193    catch {unset arg1}
1194    list [binary scan \xcd\xcc\xcc\x3f\x9a\x99\x59\x40 f2 arg1] $arg1
1195} {1 {1.600000023841858 3.4000000953674316}}
1196test binary-31.12 {Tcl_BinaryObjCmd: scan} {
1197    catch {unset arg1}
1198    set arg1 foo
1199    list [binary scan \x52 f1 arg1] $arg1
1200} {0 foo}
1201test binary-31.13 {Tcl_BinaryObjCmd: scan} {
1202    catch {unset arg1}
1203    set arg1 1
1204    list [catch {binary scan \x3f\xcc\xcc\xcd f1 arg1(a)} msg] $msg
1205} {1 {can't set "arg1(a)": variable isn't array}}
1206test binary-31.14 {Tcl_BinaryObjCmd: scan} bigEndian {
1207    catch {unset arg1 arg2}
1208    set arg1 foo
1209    set arg2 bar
1210    list [binary scan \x3f\xcc\xcc\xcd\x40\x59\x99\x9a\x05 f2c* arg1 arg2] $arg1 $arg2
1211} {2 {1.600000023841858 3.4000000953674316} 5}
1212test binary-31.15 {Tcl_BinaryObjCmd: scan} littleEndian {
1213    catch {unset arg1 arg2}
1214    set arg1 foo
1215    set arg2 bar
1216    list [binary scan \xcd\xcc\xcc\x3f\x9a\x99\x59\x40\x05 f2c* arg1 arg2] $arg1 $arg2
1217} {2 {1.600000023841858 3.4000000953674316} 5}
1218
1219test binary-32.1 {Tcl_BinaryObjCmd: scan} {
1220    list [catch {binary scan abc d} msg] $msg
1221} {1 {not enough arguments for all format specifiers}}
1222test binary-32.2 {Tcl_BinaryObjCmd: scan} bigEndian {
1223    catch {unset arg1}
1224    list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33 d* arg1] $arg1
1225} {1 {1.6 3.4}}
1226test binary-32.3 {Tcl_BinaryObjCmd: scan} littleEndian {
1227    catch {unset arg1}
1228    list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40 d* arg1] $arg1
1229} {1 {1.6 3.4}}
1230test binary-32.4 {Tcl_BinaryObjCmd: scan} bigEndian {
1231    catch {unset arg1}
1232    list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33 d arg1] $arg1
1233} {1 1.6}
1234test binary-32.5 {Tcl_BinaryObjCmd: scan} littleEndian {
1235    catch {unset arg1}
1236    list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40 d arg1] $arg1
1237} {1 1.6}
1238test binary-32.6 {Tcl_BinaryObjCmd: scan} bigEndian {
1239    catch {unset arg1}
1240    list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a d1 arg1] $arg1
1241} {1 1.6}
1242test binary-32.7 {Tcl_BinaryObjCmd: scan} littleEndian {
1243    catch {unset arg1}
1244    list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f d1 arg1] $arg1
1245} {1 1.6}
1246test binary-32.8 {Tcl_BinaryObjCmd: scan} bigEndian {
1247    catch {unset arg1}
1248    list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a d0 arg1] $arg1
1249} {1 {}}
1250test binary-32.9 {Tcl_BinaryObjCmd: scan} littleEndian {
1251    catch {unset arg1}
1252    list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f d0 arg1] $arg1
1253} {1 {}}
1254test binary-32.10 {Tcl_BinaryObjCmd: scan} bigEndian {
1255    catch {unset arg1}
1256    list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33 d2 arg1] $arg1
1257} {1 {1.6 3.4}}
1258test binary-32.11 {Tcl_BinaryObjCmd: scan} littleEndian {
1259    catch {unset arg1}
1260    list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40 d2 arg1] $arg1
1261} {1 {1.6 3.4}}
1262test binary-32.12 {Tcl_BinaryObjCmd: scan} {
1263    catch {unset arg1}
1264    set arg1 foo
1265    list [binary scan \x52 d1 arg1] $arg1
1266} {0 foo}
1267test binary-32.13 {Tcl_BinaryObjCmd: scan} {
1268    catch {unset arg1}
1269    set arg1 1
1270    list [catch {binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a d1 arg1(a)} msg] $msg
1271} {1 {can't set "arg1(a)": variable isn't array}}
1272test binary-32.14 {Tcl_BinaryObjCmd: scan} bigEndian {
1273    catch {unset arg1 arg2}
1274    set arg1 foo
1275    set arg2 bar
1276    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
1277} {2 {1.6 3.4} 5}
1278test binary-32.15 {Tcl_BinaryObjCmd: scan} littleEndian {
1279    catch {unset arg1 arg2}
1280    set arg1 foo
1281    set arg2 bar
1282    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
1283} {2 {1.6 3.4} 5}
1284
1285test binary-33.1 {Tcl_BinaryObjCmd: scan} {
1286    catch {unset arg1}
1287    catch {unset arg2}
1288    list [binary scan abcdefg a2xa3 arg1 arg2] $arg1 $arg2
1289} {2 ab def}
1290test binary-33.2 {Tcl_BinaryObjCmd: scan} {
1291    catch {unset arg1}
1292    catch {unset arg2}
1293    set arg2 foo
1294    list [binary scan abcdefg a3x*a3 arg1 arg2] $arg1 $arg2
1295} {1 abc foo}
1296test binary-33.3 {Tcl_BinaryObjCmd: scan} {
1297    catch {unset arg1}
1298    catch {unset arg2}
1299    set arg2 foo
1300    list [binary scan abcdefg a3x20a3 arg1 arg2] $arg1 $arg2
1301} {1 abc foo}
1302test binary-33.4 {Tcl_BinaryObjCmd: scan} {
1303    catch {unset arg1}
1304    catch {unset arg2}
1305    set arg2 foo
1306    list [binary scan abc a3x20a3 arg1 arg2] $arg1 $arg2
1307} {1 abc foo}
1308test binary-33.5 {Tcl_BinaryObjCmd: scan} {
1309    catch {unset arg1}
1310    list [binary scan abcdef x1a1 arg1] $arg1
1311} {1 b}
1312test binary-33.6 {Tcl_BinaryObjCmd: scan} {
1313    catch {unset arg1}
1314    list [binary scan abcdef x5a1 arg1] $arg1
1315} {1 f}
1316test binary-33.7 {Tcl_BinaryObjCmd: scan} {
1317    catch {unset arg1}
1318    list [binary scan abcdef x0a1 arg1] $arg1
1319} {1 a}
1320
1321test binary-34.1 {Tcl_BinaryObjCmd: scan} {
1322    catch {unset arg1}
1323    catch {unset arg2}
1324    list [binary scan abcdefg a2Xa3 arg1 arg2] $arg1 $arg2
1325} {2 ab bcd}
1326test binary-34.2 {Tcl_BinaryObjCmd: scan} {
1327    catch {unset arg1}
1328    catch {unset arg2}
1329    set arg2 foo
1330    list [binary scan abcdefg a3X*a3 arg1 arg2] $arg1 $arg2
1331} {2 abc abc}
1332test binary-34.3 {Tcl_BinaryObjCmd: scan} {
1333    catch {unset arg1}
1334    catch {unset arg2}
1335    set arg2 foo
1336    list [binary scan abcdefg a3X20a3 arg1 arg2] $arg1 $arg2
1337} {2 abc abc}
1338test binary-34.4 {Tcl_BinaryObjCmd: scan} {
1339    catch {unset arg1}
1340    list [binary scan abc X20a3 arg1] $arg1
1341} {1 abc}
1342test binary-34.5 {Tcl_BinaryObjCmd: scan} {
1343    catch {unset arg1}
1344    list [binary scan abcdef x*X1a1 arg1] $arg1
1345} {1 f}
1346test binary-34.6 {Tcl_BinaryObjCmd: scan} {
1347    catch {unset arg1}
1348    list [binary scan abcdef x*X5a1 arg1] $arg1
1349} {1 b}
1350test binary-34.7 {Tcl_BinaryObjCmd: scan} {
1351    catch {unset arg1}
1352    list [binary scan abcdef x3X0a1 arg1] $arg1
1353} {1 d}
1354
1355test binary-35.1 {Tcl_BinaryObjCmd: scan} {
1356    catch {unset arg1}
1357    catch {unset arg2}
1358    list [catch {binary scan abcdefg a2@a3 arg1 arg2} msg] $msg
1359} {1 {missing count for "@" field specifier}}
1360test binary-35.2 {Tcl_BinaryObjCmd: scan} {
1361    catch {unset arg1}
1362    catch {unset arg2}
1363    set arg2 foo
1364    list [binary scan abcdefg a3@*a3 arg1 arg2] $arg1 $arg2
1365} {1 abc foo}
1366test binary-35.3 {Tcl_BinaryObjCmd: scan} {
1367    catch {unset arg1}
1368    catch {unset arg2}
1369    set arg2 foo
1370    list [binary scan abcdefg a3@20a3 arg1 arg2] $arg1 $arg2
1371} {1 abc foo}
1372test binary-35.4 {Tcl_BinaryObjCmd: scan} {
1373    catch {unset arg1}
1374    list [binary scan abcdef @2a3 arg1] $arg1
1375} {1 cde}
1376test binary-35.5 {Tcl_BinaryObjCmd: scan} {
1377    catch {unset arg1}
1378    list [binary scan abcdef x*@1a1 arg1] $arg1
1379} {1 b}
1380test binary-35.6 {Tcl_BinaryObjCmd: scan} {
1381    catch {unset arg1}
1382    list [binary scan abcdef x*@0a1 arg1] $arg1
1383} {1 a}
1384
1385test binary-36.1 {Tcl_BinaryObjCmd: scan} {
1386    list [catch {binary scan abcdef u0a3} msg] $msg
1387} {1 {bad field specifier "u"}}
1388
1389# GetFormatSpec is pretty thoroughly tested above, but there are a few
1390# cases we should text explicitly
1391
1392test binary-37.1 {GetFormatSpec: whitespace} {
1393    binary format "a3 a5     a3" foo barblat baz
1394} foobarblbaz
1395test binary-37.2 {GetFormatSpec: whitespace} {
1396    binary format "      " foo
1397} {}
1398test binary-37.3 {GetFormatSpec: whitespace} {
1399    binary format "     a3" foo
1400} foo
1401test binary-37.4 {GetFormatSpec: whitespace} {
1402    binary format "" foo
1403} {}
1404test binary-37.5 {GetFormatSpec: whitespace} {
1405    binary format "" foo
1406} {}
1407test binary-37.6 {GetFormatSpec: whitespace} {
1408    binary format "     a3   " foo
1409} foo
1410test binary-37.7 {GetFormatSpec: numbers} {
1411    list [catch {binary scan abcdef "x-1" foo} msg] $msg
1412} {1 {bad field specifier "-"}}
1413test binary-37.8 {GetFormatSpec: numbers} {
1414    catch {unset arg1}
1415    set arg1 foo
1416    list [binary scan abcdef "a0x3" arg1] $arg1
1417} {1 {}}
1418test binary-37.9 {GetFormatSpec: numbers} {
1419    # test format of neg numbers
1420    # bug report/fix provided by Harald Kirsch
1421    set x [binary format f* {1 -1 2 -2 0}]
1422    binary scan $x f* bla
1423    set bla
1424} {1.0 -1.0 2.0 -2.0 0.0}
1425
1426test binary-38.1 {FormatNumber: word alignment} {
1427    set x [binary format c1s1 1 1]
1428} \x01\x01\x00
1429test binary-38.2 {FormatNumber: word alignment} {
1430    set x [binary format c1S1 1 1]
1431} \x01\x00\x01
1432test binary-38.3 {FormatNumber: word alignment} {
1433    set x [binary format c1i1 1 1]
1434} \x01\x01\x00\x00\x00
1435test binary-38.4 {FormatNumber: word alignment} {
1436    set x [binary format c1I1 1 1]
1437} \x01\x00\x00\x00\x01
1438test binary-38.5 {FormatNumber: word alignment} bigEndian {
1439    set x [binary format c1d1 1 1.6]
1440} \x01\x3f\xf9\x99\x99\x99\x99\x99\x9a
1441test binary-38.6 {FormatNumber: word alignment} littleEndian {
1442    set x [binary format c1d1 1 1.6]
1443} \x01\x9a\x99\x99\x99\x99\x99\xf9\x3f
1444test binary-38.7 {FormatNumber: word alignment} bigEndian {
1445    set x [binary format c1f1 1 1.6]
1446} \x01\x3f\xcc\xcc\xcd
1447test binary-38.8 {FormatNumber: word alignment} littleEndian {
1448    set x [binary format c1f1 1 1.6]
1449} \x01\xcd\xcc\xcc\x3f
1450
1451test binary-39.1 {ScanNumber: sign extension} {
1452    catch {unset arg1}
1453    list [binary scan \x52\xa3 c2 arg1] $arg1
1454} {1 {82 -93}}
1455test binary-39.2 {ScanNumber: sign extension} {
1456    catch {unset arg1}
1457    list [binary scan \x01\x02\x01\x81\x82\x01\x81\x82 s4 arg1] $arg1
1458} {1 {513 -32511 386 -32127}}
1459test binary-39.3 {ScanNumber: sign extension} {
1460    catch {unset arg1}
1461    list [binary scan \x01\x02\x01\x81\x82\x01\x81\x82 S4 arg1] $arg1
1462} {1 {258 385 -32255 -32382}}
1463test binary-39.4 {ScanNumber: sign extension} {
1464    catch {unset arg1}
1465    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
1466} {1 {33620225 16843137 16876033 25297153 -2130640639}}
1467test binary-39.5 {ScanNumber: sign extension} {
1468    catch {unset arg1}
1469    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
1470} {1 {16843010 -2130640639 25297153 16876033 16843137}}
1471test binary-39.6 {ScanNumber: no sign extension} {
1472    catch {unset arg1}
1473    list [binary scan \x52\xa3 cu2 arg1] $arg1
1474} {1 {82 163}}
1475test binary-39.7 {ScanNumber: no sign extension} {
1476    catch {unset arg1}
1477    list [binary scan \x01\x02\x01\x81\x82\x01\x81\x82 su4 arg1] $arg1
1478} {1 {513 33025 386 33409}}
1479test binary-39.8 {ScanNumber: no sign extension} {
1480    catch {unset arg1}
1481    list [binary scan \x01\x02\x01\x81\x82\x01\x81\x82 Su4 arg1] $arg1
1482} {1 {258 385 33281 33154}}
1483test binary-39.9 {ScanNumber: no sign extension} {
1484    catch {unset arg1}
1485    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
1486} {1 {33620225 16843137 16876033 25297153 2164326657}}
1487test binary-39.10 {ScanNumber: no sign extension} {
1488    catch {unset arg1}
1489    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
1490} {1 {16843010 2164326657 25297153 16876033 16843137}}
1491
1492test binary-40.3 {ScanNumber: NaN} \
1493    -body {
1494        catch {unset arg1}
1495        list [binary scan \xff\xff\xff\xff f1 arg1] $arg1
1496    } \
1497    -match glob \
1498    -result {1 -NaN*}
1499
1500test binary-40.4 {ScanNumber: NaN} \
1501    -body {
1502        catch {unset arg1}
1503        list [binary scan \xff\xff\xff\xff\xff\xff\xff\xff d arg1] $arg1
1504    } \
1505    -match glob \
1506    -result {1 -NaN*}
1507
1508test binary-41.1 {ScanNumber: word alignment} {
1509    catch {unset arg1; unset arg2}
1510    list [binary scan \x01\x01\x00 c1s1 arg1 arg2] $arg1 $arg2
1511} {2 1 1}
1512test binary-41.2 {ScanNumber: word alignment} {
1513    catch {unset arg1; unset arg2}
1514    list [binary scan \x01\x00\x01 c1S1 arg1 arg2] $arg1 $arg2
1515} {2 1 1}
1516test binary-41.3 {ScanNumber: word alignment} {
1517    catch {unset arg1; unset arg2}
1518    list [binary scan \x01\x01\x00\x00\x00 c1i1 arg1 arg2] $arg1 $arg2
1519} {2 1 1}
1520test binary-41.4 {ScanNumber: word alignment} {
1521    catch {unset arg1; unset arg2}
1522    list [binary scan \x01\x00\x00\x00\x01 c1I1 arg1 arg2] $arg1 $arg2
1523} {2 1 1}
1524test binary-41.5 {ScanNumber: word alignment} bigEndian {
1525    catch {unset arg1; unset arg2}
1526    list [binary scan \x01\x3f\xcc\xcc\xcd c1f1 arg1 arg2] $arg1 $arg2
1527} {2 1 1.600000023841858}
1528test binary-41.6 {ScanNumber: word alignment} littleEndian {
1529    catch {unset arg1; unset arg2}
1530    list [binary scan \x01\xcd\xcc\xcc\x3f c1f1 arg1 arg2] $arg1 $arg2
1531} {2 1 1.600000023841858}
1532test binary-41.7 {ScanNumber: word alignment} bigEndian {
1533    catch {unset arg1; unset arg2}
1534    list [binary scan \x01\x3f\xf9\x99\x99\x99\x99\x99\x9a c1d1 arg1 arg2] $arg1 $arg2
1535} {2 1 1.6}
1536test binary-41.8 {ScanNumber: word alignment} littleEndian {
1537    catch {unset arg1; unset arg2}
1538    list [binary scan \x01\x9a\x99\x99\x99\x99\x99\xf9\x3f c1d1 arg1 arg2] $arg1 $arg2
1539} {2 1 1.6}
1540
1541test binary-42.1 {Tcl_BinaryObjCmd: bad arguments} {} {
1542    catch {binary ?} result
1543    set result
1544} {bad option "?": must be format or scan}
1545
1546# Wide int (guaranteed at least 64-bit) handling
1547test binary-43.1 {Tcl_BinaryObjCmd: format wide int} {} {
1548    binary format w 7810179016327718216
1549} HelloTcl
1550test binary-43.2 {Tcl_BinaryObjCmd: format wide int} {} {
1551    binary format W 7810179016327718216
1552} lcTolleH
1553
1554test binary-44.1 {Tcl_BinaryObjCmd: scan wide int} {} {
1555    binary scan HelloTcl W x
1556    set x
1557} 5216694956358656876
1558test binary-44.2 {Tcl_BinaryObjCmd: scan wide int} {} {
1559    binary scan lcTolleH w x
1560    set x
1561} 5216694956358656876
1562test binary-44.3 {Tcl_BinaryObjCmd: scan wide int with bit 31 set} {} {
1563    binary scan [binary format w [expr {wide(3) << 31}]] w x
1564    set x
1565} 6442450944
1566test binary-44.4 {Tcl_BinaryObjCmd: scan wide int with bit 31 set} {} {
1567    binary scan [binary format W [expr {wide(3) << 31}]] W x
1568    set x
1569} 6442450944
1570test binary-43.5 {Tcl_BinaryObjCmd: scan wide int} {} {
1571    catch {unset arg1}
1572    list [binary scan \x80[string repeat \x00 7] W arg1] $arg1
1573} {1 -9223372036854775808}
1574test binary-43.6 {Tcl_BinaryObjCmd: scan unsigned wide int} {} {
1575    catch {unset arg1}
1576    list [binary scan \x80[string repeat \x00 7] Wu arg1] $arg1
1577} {1 9223372036854775808}
1578test binary-43.7 {Tcl_BinaryObjCmd: scan unsigned wide int} {} {
1579    catch {unset arg1}
1580    list [binary scan [string repeat \x00 7]\x80 wu arg1] $arg1
1581} {1 9223372036854775808}
1582test binary-43.8 {Tcl_BinaryObjCmd: scan unsigned wide int} {} {
1583    catch {unset arg1 arg2}
1584    list [binary scan \x80[string repeat \x00 7]\x80[string repeat \x00 7] WuW arg1 arg2] $arg1 $arg2
1585} {2 9223372036854775808 -9223372036854775808}
1586test binary-43.9 {Tcl_BinaryObjCmd: scan unsigned wide int} {} {
1587    catch {unset arg1 arg2}
1588    list [binary scan [string repeat \x00 7]\x80[string repeat \x00 7]\x80 wuw arg1 arg2] $arg1 $arg2
1589} {2 9223372036854775808 -9223372036854775808}
1590
1591test binary-45.1 {Tcl_BinaryObjCmd: combined wide int handling} {
1592    binary scan [binary format sws 16450 -1 19521] c* x
1593    set x
1594} {66 64 -1 -1 -1 -1 -1 -1 -1 -1 65 76}
1595test binary-45.2 {Tcl_BinaryObjCmd: combined wide int handling} {
1596    binary scan [binary format sWs 16450 0x7fffffff 19521] c* x
1597    set x
1598} {66 64 0 0 0 0 127 -1 -1 -1 65 76}
1599
1600test binary-46.1 {Tcl_BinaryObjCmd: handling of non-ISO8859-1 chars} {
1601    binary format a* \u20ac
1602} \u00ac
1603test binary-46.2 {Tcl_BinaryObjCmd: handling of non-ISO8859-1 chars} {
1604    list [binary scan [binary format a* \u20ac\u20bd] s x] $x
1605} {1 -16980}
1606test binary-46.3 {Tcl_BinaryObjCmd: handling of non-ISO8859-1 chars} {
1607    set x {}
1608    set y {}
1609    set z {}
1610    list [binary scan [binary format a* \u20ac\u20bd] aaa x y z] $x $y $z
1611} "2 \u00ac \u00bd {}"
1612test binary-46.4 {Tcl_BinaryObjCmd: handling of non-ISO8859-1 chars} {
1613    set x [encoding convertto iso8859-15 \u20ac]
1614    set y [binary format a* $x]
1615    list $x $y
1616} "\u00a4 \u00a4"
1617test binary-46.5 {Tcl_BinaryObjCmd: handling of non-ISO8859-1 chars} {
1618    set x [binary scan \u00a4 a* y]
1619    list $x $y [encoding convertfrom iso8859-15 $y]
1620} "1 \u00a4 \u20ac"
1621
1622test binary-47.1 {Tcl_BinaryObjCmd: number cache reference count handling} {
1623    # This test is only reliable when memory debugging is turned on,
1624    # but without even memory debugging it should still generate the
1625    # expected answers and might therefore still pick up memory corruption
1626    # caused by [Bug 851747].
1627    list [binary scan aba ccc x x x] $x
1628} {3 97}
1629
1630### TIP#129: endian specifiers ----
1631
1632# format t
1633test binary-48.1 {Tcl_BinaryObjCmd: format} {
1634    list [catch {binary format t} msg] $msg
1635} {1 {not enough arguments for all format specifiers}}
1636test binary-48.2 {Tcl_BinaryObjCmd: format} {
1637    list [catch {binary format t blat} msg] $msg
1638} {1 {expected integer but got "blat"}}
1639test binary-48.3 {Tcl_BinaryObjCmd: format} {
1640    binary format S0 0x50
1641} {}
1642test binary-48.4 {Tcl_BinaryObjCmd: format} bigEndian {
1643    binary format t 0x50
1644} \x00P
1645test binary-48.5 {Tcl_BinaryObjCmd: format} littleEndian {
1646    binary format t 0x50
1647} P\x00
1648test binary-48.6 {Tcl_BinaryObjCmd: format} bigEndian {
1649    binary format t 0x5052
1650} PR
1651test binary-48.7 {Tcl_BinaryObjCmd: format} littleEndian {
1652    binary format t 0x5052
1653} RP
1654test binary-48.8 {Tcl_BinaryObjCmd: format} bigEndian {
1655    binary format t 0x505251 0x53
1656} RQ
1657test binary-48.9 {Tcl_BinaryObjCmd: format} littleEndian {
1658    binary format t 0x505251 0x53
1659} QR
1660test binary-48.10 {Tcl_BinaryObjCmd: format} bigEndian {
1661    binary format t2 {0x50 0x52}
1662} \x00P\x00R
1663test binary-48.11 {Tcl_BinaryObjCmd: format} littleEndian {
1664    binary format t2 {0x50 0x52}
1665} P\x00R\x00
1666test binary-48.12 {Tcl_BinaryObjCmd: format}  bigEndian {
1667    binary format t* {0x5051 0x52}
1668} PQ\x00R
1669test binary-48.13 {Tcl_BinaryObjCmd: format}  littleEndian {
1670    binary format t* {0x5051 0x52}
1671} QPR\x00
1672test binary-48.14 {Tcl_BinaryObjCmd: format} bigEndian {
1673    binary format t2 {0x50 0x52 0x53} 0x54
1674} \x00P\x00R
1675test binary-48.15 {Tcl_BinaryObjCmd: format} littleEndian {
1676    binary format t2 {0x50 0x52 0x53} 0x54
1677} P\x00R\x00
1678test binary-48.16 {Tcl_BinaryObjCmd: format} {
1679    list [catch {binary format t2 {0x50}} msg] $msg
1680} {1 {number of elements in list does not match count}}
1681test binary-48.17 {Tcl_BinaryObjCmd: format} {
1682    set a {0x50 0x51}
1683    list [catch {binary format t $a} msg] $msg
1684} [list 1 "expected integer but got \"0x50 0x51\""]
1685test binary-48.18 {Tcl_BinaryObjCmd: format} bigEndian {
1686    set a {0x50 0x51}
1687    binary format t1 $a
1688} \x00P
1689test binary-48.19 {Tcl_BinaryObjCmd: format} littleEndian {
1690    set a {0x50 0x51}
1691    binary format t1 $a
1692} P\x00
1693
1694# format n
1695test binary-49.1 {Tcl_BinaryObjCmd: format} {
1696    list [catch {binary format n} msg] $msg
1697} {1 {not enough arguments for all format specifiers}}
1698test binary-49.2 {Tcl_BinaryObjCmd: format} {
1699    list [catch {binary format n blat} msg] $msg
1700} {1 {expected integer but got "blat"}}
1701test binary-49.3 {Tcl_BinaryObjCmd: format} {
1702    binary format n0 0x50
1703} {}
1704test binary-49.4 {Tcl_BinaryObjCmd: format} littleEndian {
1705    binary format n 0x50
1706} P\x00\x00\x00
1707test binary-49.5 {Tcl_BinaryObjCmd: format} littleEndian {
1708    binary format n 0x5052
1709} RP\x00\x00
1710test binary-49.6 {Tcl_BinaryObjCmd: format} littleEndian {
1711    binary format n 0x505251 0x53
1712} QRP\x00
1713test binary-49.7 {Tcl_BinaryObjCmd: format} littleEndian {
1714    binary format i1 {0x505251 0x53}
1715} QRP\x00
1716test binary-49.8 {Tcl_BinaryObjCmd: format} littleEndian {
1717    binary format n 0x53525150
1718} PQRS
1719test binary-49.9 {Tcl_BinaryObjCmd: format} littleEndian {
1720    binary format n2 {0x50 0x52}
1721} P\x00\x00\x00R\x00\x00\x00
1722test binary-49.10 {Tcl_BinaryObjCmd: format} littleEndian {
1723    binary format n* {0x50515253 0x52}
1724} SRQPR\x00\x00\x00
1725test binary-49.11 {Tcl_BinaryObjCmd: format} {
1726    list [catch {binary format n2 {0x50}} msg] $msg
1727} {1 {number of elements in list does not match count}}
1728test binary-49.12 {Tcl_BinaryObjCmd: format} {
1729    set a {0x50 0x51}
1730    list [catch {binary format n $a} msg] $msg
1731} [list 1 "expected integer but got \"0x50 0x51\""]
1732test binary-49.13 {Tcl_BinaryObjCmd: format} littleEndian {
1733    set a {0x50 0x51}
1734    binary format n1 $a
1735} P\x00\x00\x00
1736test binary-49.14 {Tcl_BinaryObjCmd: format} bigEndian {
1737    binary format n 0x50
1738} \x00\x00\x00P
1739test binary-49.15 {Tcl_BinaryObjCmd: format} bigEndian {
1740    binary format n 0x5052
1741} \x00\x00PR
1742test binary-49.16 {Tcl_BinaryObjCmd: format} bigEndian {
1743    binary format n 0x505251 0x53
1744} \x00PRQ
1745test binary-49.17 {Tcl_BinaryObjCmd: format} bigEndian {
1746    binary format i1 {0x505251 0x53}
1747} QRP\x00
1748test binary-49.18 {Tcl_BinaryObjCmd: format} bigEndian {
1749    binary format n 0x53525150
1750} SRQP
1751test binary-49.19 {Tcl_BinaryObjCmd: format} bigEndian {
1752    binary format n2 {0x50 0x52}
1753} \x00\x00\x00P\x00\x00\x00R
1754test binary-49.20 {Tcl_BinaryObjCmd: format} bigEndian {
1755    binary format n* {0x50515253 0x52}
1756} PQRS\x00\x00\x00R
1757
1758# format m
1759test binary-50.1 {Tcl_BinaryObjCmd: format wide int} littleEndian {
1760    binary format m 7810179016327718216
1761} HelloTcl
1762test binary-50.2 {Tcl_BinaryObjCmd: format wide int} bigEndian {
1763    binary format m 7810179016327718216
1764} lcTolleH
1765test binary-50.3 {Tcl_BinaryObjCmd: scan wide int with bit 31 set} littleEndian {
1766    binary scan [binary format m [expr {wide(3) << 31}]] w x
1767    set x
1768} 6442450944
1769test binary-50.4 {Tcl_BinaryObjCmd: scan wide int with bit 31 set} bigEndian {
1770    binary scan [binary format m [expr {wide(3) << 31}]] W x
1771    set x
1772} 6442450944
1773
1774
1775# format Q/q
1776test binary-51.1 {Tcl_BinaryObjCmd: format} {
1777    list [catch {binary format Q} msg] $msg
1778} {1 {not enough arguments for all format specifiers}}
1779test binary-51.2 {Tcl_BinaryObjCmd: format} {
1780    list [catch {binary format q blat} msg] $msg
1781} {1 {expected floating-point number but got "blat"}}
1782test binary-51.3 {Tcl_BinaryObjCmd: format} {
1783    binary format q0 1.6
1784} {}
1785test binary-51.4 {Tcl_BinaryObjCmd: format} {} {
1786    binary format Q 1.6
1787} \x3f\xf9\x99\x99\x99\x99\x99\x9a
1788test binary-51.5 {Tcl_BinaryObjCmd: format} {} {
1789    binary format q 1.6
1790} \x9a\x99\x99\x99\x99\x99\xf9\x3f
1791test binary-51.6 {Tcl_BinaryObjCmd: format} {} {
1792    binary format Q* {1.6 3.4}
1793} \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33
1794test binary-51.7 {Tcl_BinaryObjCmd: format} {} {
1795    binary format q* {1.6 3.4}
1796} \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40
1797test binary-51.8 {Tcl_BinaryObjCmd: format} {} {
1798    binary format Q2 {1.6 3.4}
1799} \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33
1800test binary-51.9 {Tcl_BinaryObjCmd: format} {} {
1801    binary format q2 {1.6 3.4}
1802} \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40
1803test binary-51.10 {Tcl_BinaryObjCmd: format} {} {
1804    binary format Q2 {1.6 3.4 5.6}
1805} \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33
1806test binary-51.11 {Tcl_BinaryObjCmd: format} {} {
1807    binary format q2 {1.6 3.4 5.6}
1808} \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40
1809test binary-51.14 {Tcl_BinaryObjCmd: format} {
1810    list [catch {binary format q2 {1.6}} msg] $msg
1811} {1 {number of elements in list does not match count}}
1812test binary-51.15 {Tcl_BinaryObjCmd: format} {
1813    set a {1.6 3.4}
1814    list [catch {binary format q $a} msg] $msg
1815} [list 1 "expected floating-point number but got \"1.6 3.4\""]
1816test binary-51.16 {Tcl_BinaryObjCmd: format} {} {
1817    set a {1.6 3.4}
1818    binary format Q1 $a
1819} \x3f\xf9\x99\x99\x99\x99\x99\x9a
1820test binary-51.17 {Tcl_BinaryObjCmd: format} {} {
1821    set a {1.6 3.4}
1822    binary format q1 $a
1823} \x9a\x99\x99\x99\x99\x99\xf9\x3f
1824
1825# format R/r
1826test binary-53.1 {Tcl_BinaryObjCmd: format} {
1827    list [catch {binary format r} msg] $msg
1828} {1 {not enough arguments for all format specifiers}}
1829test binary-53.2 {Tcl_BinaryObjCmd: format} {
1830    list [catch {binary format r blat} msg] $msg
1831} {1 {expected floating-point number but got "blat"}}
1832test binary-53.3 {Tcl_BinaryObjCmd: format} {
1833    binary format f0 1.6
1834} {}
1835test binary-53.4 {Tcl_BinaryObjCmd: format} {} {
1836    binary format R 1.6
1837} \x3f\xcc\xcc\xcd
1838test binary-53.5 {Tcl_BinaryObjCmd: format} {} {
1839    binary format r 1.6
1840} \xcd\xcc\xcc\x3f
1841test binary-53.6 {Tcl_BinaryObjCmd: format} {} {
1842    binary format R* {1.6 3.4}
1843} \x3f\xcc\xcc\xcd\x40\x59\x99\x9a
1844test binary-53.7 {Tcl_BinaryObjCmd: format} {} {
1845    binary format r* {1.6 3.4}
1846} \xcd\xcc\xcc\x3f\x9a\x99\x59\x40
1847test binary-53.8 {Tcl_BinaryObjCmd: format} {} {
1848    binary format R2 {1.6 3.4}
1849} \x3f\xcc\xcc\xcd\x40\x59\x99\x9a
1850test binary-53.9 {Tcl_BinaryObjCmd: format} {} {
1851    binary format r2 {1.6 3.4}
1852} \xcd\xcc\xcc\x3f\x9a\x99\x59\x40
1853test binary-53.10 {Tcl_BinaryObjCmd: format} {} {
1854    binary format R2 {1.6 3.4 5.6}
1855} \x3f\xcc\xcc\xcd\x40\x59\x99\x9a
1856test binary-53.11 {Tcl_BinaryObjCmd: format} {} {
1857    binary format r2 {1.6 3.4 5.6}
1858} \xcd\xcc\xcc\x3f\x9a\x99\x59\x40
1859test binary-53.12 {Tcl_BinaryObjCmd: float overflow} {} {
1860    binary format R -3.402825e+38
1861} \xff\x7f\xff\xff
1862test binary-53.13 {Tcl_BinaryObjCmd: float overflow} {} {
1863    binary format r -3.402825e+38
1864} \xff\xff\x7f\xff
1865test binary-53.14 {Tcl_BinaryObjCmd: float underflow} {} {
1866    binary format R -3.402825e-100
1867} \x80\x00\x00\x00
1868test binary-53.15 {Tcl_BinaryObjCmd: float underflow} {} {
1869    binary format r -3.402825e-100
1870} \x00\x00\x00\x80
1871test binary-53.16 {Tcl_BinaryObjCmd: format} {
1872    list [catch {binary format r2 {1.6}} msg] $msg
1873} {1 {number of elements in list does not match count}}
1874test binary-53.17 {Tcl_BinaryObjCmd: format} {
1875    set a {1.6 3.4}
1876    list [catch {binary format r $a} msg] $msg
1877} [list 1 "expected floating-point number but got \"1.6 3.4\""]
1878test binary-53.18 {Tcl_BinaryObjCmd: format} {} {
1879    set a {1.6 3.4}
1880    binary format R1 $a
1881} \x3f\xcc\xcc\xcd
1882test binary-53.19 {Tcl_BinaryObjCmd: format} {} {
1883    set a {1.6 3.4}
1884    binary format r1 $a
1885} \xcd\xcc\xcc\x3f
1886
1887# scan t (s)
1888test binary-54.1 {Tcl_BinaryObjCmd: scan} {
1889    list [catch {binary scan abc t} msg] $msg
1890} {1 {not enough arguments for all format specifiers}}
1891test binary-54.2 {Tcl_BinaryObjCmd: scan} littleEndian {
1892    catch {unset arg1}
1893    list [binary scan \x52\xa3\x53\x54 t* arg1] $arg1
1894} {1 {-23726 21587}}
1895test binary-54.3 {Tcl_BinaryObjCmd: scan} littleEndian {
1896    catch {unset arg1}
1897    list [binary scan \x52\xa3\x53\x54 t arg1] $arg1
1898} {1 -23726}
1899test binary-54.4 {Tcl_BinaryObjCmd: scan} littleEndian {
1900    catch {unset arg1}
1901    list [binary scan \x52\xa3 t1 arg1] $arg1
1902} {1 -23726}
1903test binary-54.5 {Tcl_BinaryObjCmd: scan} littleEndian {
1904    catch {unset arg1}
1905    list [binary scan \x52\xa3 t0 arg1] $arg1
1906} {1 {}}
1907test binary-54.6 {Tcl_BinaryObjCmd: scan} littleEndian {
1908    catch {unset arg1}
1909    list [binary scan \x52\xa3\x53\x54 t2 arg1] $arg1
1910} {1 {-23726 21587}}
1911test binary-54.7 {Tcl_BinaryObjCmd: scan} littleEndian {
1912    catch {unset arg1}
1913    set arg1 foo
1914    list [binary scan \x52 t1 arg1] $arg1
1915} {0 foo}
1916test binary-54.8 {Tcl_BinaryObjCmd: scan} {} {
1917    catch {unset arg1}
1918    set arg1 1
1919    list [catch {binary scan \x52\x53 t1 arg1(a)} msg] $msg
1920} {1 {can't set "arg1(a)": variable isn't array}}
1921test binary-54.9 {Tcl_BinaryObjCmd: scan} littleEndian {
1922    catch {unset arg1 arg2}
1923    set arg1 foo
1924    set arg2 bar
1925    list [binary scan \x52\xa3\x53\x54\x05 t2c* arg1 arg2] $arg1 $arg2
1926} {2 {-23726 21587} 5}
1927test binary-54.10 {Tcl_BinaryObjCmd: scan} littleEndian  {
1928    catch {unset arg1 arg2}
1929    set arg1 foo
1930    set arg2 bar
1931    list [binary scan \x00\x80\x00\x80 tut arg1 arg2] $arg1 $arg2
1932} {2 32768 -32768}
1933test binary-54.11 {Tcl_BinaryObjCmd: scan} littleEndian  {
1934    catch {unset arg1 arg2}
1935    set arg1 foo
1936    set arg2 bar
1937    list [binary scan \x00\x80\x00\x80 ttu arg1 arg2] $arg1 $arg2
1938} {2 -32768 32768}
1939
1940# scan t (b)
1941test binary-55.1 {Tcl_BinaryObjCmd: scan} {
1942    list [catch {binary scan abc t} msg] $msg
1943} {1 {not enough arguments for all format specifiers}}
1944test binary-55.2 {Tcl_BinaryObjCmd: scan} bigEndian  {
1945    catch {unset arg1}
1946    list [binary scan \x52\xa3\x53\x54 t* arg1] $arg1
1947} {1 {21155 21332}}
1948test binary-55.3 {Tcl_BinaryObjCmd: scan} bigEndian  {
1949    catch {unset arg1}
1950    list [binary scan \x52\xa3\x53\x54 t arg1] $arg1
1951} {1 21155}
1952test binary-55.4 {Tcl_BinaryObjCmd: scan} bigEndian  {
1953    catch {unset arg1}
1954    list [binary scan \x52\xa3 t1 arg1] $arg1
1955} {1 21155}
1956test binary-55.5 {Tcl_BinaryObjCmd: scan} bigEndian  {
1957    catch {unset arg1}
1958    list [binary scan \x52\xa3 t0 arg1] $arg1
1959} {1 {}}
1960test binary-55.6 {Tcl_BinaryObjCmd: scan} bigEndian  {
1961    catch {unset arg1}
1962    list [binary scan \x52\xa3\x53\x54 t2 arg1] $arg1
1963} {1 {21155 21332}}
1964test binary-55.7 {Tcl_BinaryObjCmd: scan} bigEndian  {
1965    catch {unset arg1}
1966    set arg1 foo
1967    list [binary scan \x52 t1 arg1] $arg1
1968} {0 foo}
1969test binary-55.8 {Tcl_BinaryObjCmd: scan} {
1970    catch {unset arg1}
1971    set arg1 1
1972    list [catch {binary scan \x52\x53 t1 arg1(a)} msg] $msg
1973} {1 {can't set "arg1(a)": variable isn't array}}
1974test binary-55.9 {Tcl_BinaryObjCmd: scan} bigEndian  {
1975    catch {unset arg1 arg2}
1976    set arg1 foo
1977    set arg2 bar
1978    list [binary scan \x52\xa3\x53\x54\x05 t2c* arg1 arg2] $arg1 $arg2
1979} {2 {21155 21332} 5}
1980test binary-55.10 {Tcl_BinaryObjCmd: scan} bigEndian  {
1981    catch {unset arg1 arg2}
1982    set arg1 foo
1983    set arg2 bar
1984    list [binary scan \x80\x00\x80\x00 tut arg1 arg2] $arg1 $arg2
1985} {2 32768 -32768}
1986test binary-55.11 {Tcl_BinaryObjCmd: scan} bigEndian  {
1987    catch {unset arg1 arg2}
1988    set arg1 foo
1989    set arg2 bar
1990    list [binary scan \x80\x00\x80\x00 ttu arg1 arg2] $arg1 $arg2
1991} {2 -32768 32768}
1992
1993# scan n (s)
1994test binary-56.1 {Tcl_BinaryObjCmd: scan} {
1995    list [catch {binary scan abc n} msg] $msg
1996} {1 {not enough arguments for all format specifiers}}
1997test binary-56.2 {Tcl_BinaryObjCmd: scan} littleEndian {
1998    catch {unset arg1}
1999    list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 n* arg1] $arg1
2000} {1 {1414767442 67305985}}
2001test binary-56.3 {Tcl_BinaryObjCmd: scan} littleEndian  {
2002    catch {unset arg1}
2003    list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 n arg1] $arg1
2004} {1 1414767442}
2005test binary-56.4 {Tcl_BinaryObjCmd: scan} littleEndian  {
2006    catch {unset arg1}
2007    list [binary scan \x52\xa3\x53\x54 n1 arg1] $arg1
2008} {1 1414767442}
2009test binary-56.5 {Tcl_BinaryObjCmd: scan} littleEndian  {
2010    catch {unset arg1}
2011    list [binary scan \x52\xa3\x53 n0 arg1] $arg1
2012} {1 {}}
2013test binary-56.6 {Tcl_BinaryObjCmd: scan} littleEndian  {
2014    catch {unset arg1}
2015    list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 n2 arg1] $arg1
2016} {1 {1414767442 67305985}}
2017test binary-56.7 {Tcl_BinaryObjCmd: scan} littleEndian  {
2018    catch {unset arg1}
2019    set arg1 foo
2020    list [binary scan \x52 n1 arg1] $arg1
2021} {0 foo}
2022test binary-56.8 {Tcl_BinaryObjCmd: scan} {
2023    catch {unset arg1}
2024    set arg1 1
2025    list [catch {binary scan \x52\x53\x53\x54 n1 arg1(a)} msg] $msg
2026} {1 {can't set "arg1(a)": variable isn't array}}
2027test binary-56.9 {Tcl_BinaryObjCmd: scan} littleEndian  {
2028    catch {unset arg1 arg2}
2029    set arg1 foo
2030    set arg2 bar
2031    list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04\x05 n2c* arg1 arg2] $arg1 $arg2
2032} {2 {1414767442 67305985} 5}
2033test binary-56.10 {Tcl_BinaryObjCmd: scan} littleEndian  {
2034    catch {unset arg1 arg2}
2035    set arg1 foo
2036    set arg2 bar
2037    list [binary scan \x80\x00\x00\x00\x80\x00\x00\x00 nun arg1 arg2] $arg1 $arg2
2038} {2 128 128}
2039test binary-56.11 {Tcl_BinaryObjCmd: scan} littleEndian  {
2040    catch {unset arg1 arg2}
2041    set arg1 foo
2042    set arg2 bar
2043    list [binary scan \x00\x00\x00\x80\x00\x00\x00\x80 nun arg1 arg2] $arg1 $arg2
2044} {2 2147483648 -2147483648}
2045
2046# scan n (b)
2047test binary-57.1 {Tcl_BinaryObjCmd: scan} {
2048    list [catch {binary scan abc n} msg] $msg
2049} {1 {not enough arguments for all format specifiers}}
2050test binary-57.2 {Tcl_BinaryObjCmd: scan} bigEndian  {
2051    catch {unset arg1}
2052    list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 n* arg1] $arg1
2053} {1 {1386435412 16909060}}
2054test binary-57.3 {Tcl_BinaryObjCmd: scan} bigEndian  {
2055    catch {unset arg1}
2056    list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 n arg1] $arg1
2057} {1 1386435412}
2058test binary-57.4 {Tcl_BinaryObjCmd: scan} bigEndian  {
2059    catch {unset arg1}
2060    list [binary scan \x52\xa3\x53\x54 n1 arg1] $arg1
2061} {1 1386435412}
2062test binary-57.5 {Tcl_BinaryObjCmd: scan} bigEndian  {
2063    catch {unset arg1}
2064    list [binary scan \x52\xa3\x53 n0 arg1] $arg1
2065} {1 {}}
2066test binary-57.6 {Tcl_BinaryObjCmd: scan} bigEndian  {
2067    catch {unset arg1}
2068    list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04 n2 arg1] $arg1
2069} {1 {1386435412 16909060}}
2070test binary-57.7 {Tcl_BinaryObjCmd: scan} bigEndian  {
2071    catch {unset arg1}
2072    set arg1 foo
2073    list [binary scan \x52 n1 arg1] $arg1
2074} {0 foo}
2075test binary-57.8 {Tcl_BinaryObjCmd: scan} {
2076    catch {unset arg1}
2077    set arg1 1
2078    list [catch {binary scan \x52\x53\x53\x54 n1 arg1(a)} msg] $msg
2079} {1 {can't set "arg1(a)": variable isn't array}}
2080test binary-57.9 {Tcl_BinaryObjCmd: scan} bigEndian  {
2081    catch {unset arg1 arg2}
2082    set arg1 foo
2083    set arg2 bar
2084    list [binary scan \x52\xa3\x53\x54\x01\x02\x03\x04\x05 n2c* arg1 arg2] $arg1 $arg2
2085} {2 {1386435412 16909060} 5}
2086test binary-57.10 {Tcl_BinaryObjCmd: scan} bigEndian  {
2087    catch {unset arg1 arg2}
2088    set arg1 foo
2089    set arg2 bar
2090    list [binary scan \x80\x00\x00\x00\x80\x00\x00\x00 nun arg1 arg2] $arg1 $arg2
2091} {2 2147483648 -2147483648}
2092test binary-57.11 {Tcl_BinaryObjCmd: scan} bigEndian  {
2093    catch {unset arg1 arg2}
2094    set arg1 foo
2095    set arg2 bar
2096    list [binary scan \x00\x00\x00\x80\x00\x00\x00\x80 nun arg1 arg2] $arg1 $arg2
2097} {2 128 128}
2098
2099# scan Q/q
2100test binary-58.1 {Tcl_BinaryObjCmd: scan} {
2101    list [catch {binary scan abc q} msg] $msg
2102} {1 {not enough arguments for all format specifiers}}
2103test binary-58.2 {Tcl_BinaryObjCmd: scan} bigEndian {
2104    catch {unset arg1}
2105    list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33 Q* arg1] $arg1
2106} {1 {1.6 3.4}}
2107test binary-58.3 {Tcl_BinaryObjCmd: scan} littleEndian {
2108    catch {unset arg1}
2109    list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40 q* arg1] $arg1
2110} {1 {1.6 3.4}}
2111test binary-58.4 {Tcl_BinaryObjCmd: scan} bigEndian {
2112    catch {unset arg1}
2113    list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a\x40\x0b\x33\x33\x33\x33\x33\x33 Q arg1] $arg1
2114} {1 1.6}
2115test binary-58.5 {Tcl_BinaryObjCmd: scan} littleEndian {
2116    catch {unset arg1}
2117    list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f\x33\x33\x33\x33\x33\x33\x0b\x40 q arg1] $arg1
2118} {1 1.6}
2119test binary-58.6 {Tcl_BinaryObjCmd: scan} bigEndian {
2120    catch {unset arg1}
2121    list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a Q1 arg1] $arg1
2122} {1 1.6}
2123test binary-58.7 {Tcl_BinaryObjCmd: scan} littleEndian {
2124    catch {unset arg1}
2125    list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f q1 arg1] $arg1
2126} {1 1.6}
2127test binary-58.8 {Tcl_BinaryObjCmd: scan} bigEndian {
2128    catch {unset arg1}
2129    list [binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a Q0 arg1] $arg1
2130} {1 {}}
2131test binary-58.9 {Tcl_BinaryObjCmd: scan} littleEndian {
2132    catch {unset arg1}
2133    list [binary scan \x9a\x99\x99\x99\x99\x99\xf9\x3f q0 arg1] $arg1
2134} {1 {}}
2135test binary-58.10 {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 Q2 arg1] $arg1
2138} {1 {1.6 3.4}}
2139test binary-58.11 {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 q2 arg1] $arg1
2142} {1 {1.6 3.4}}
2143test binary-58.12 {Tcl_BinaryObjCmd: scan} {
2144    catch {unset arg1}
2145    set arg1 foo
2146    list [binary scan \x52 q1 arg1] $arg1
2147} {0 foo}
2148test binary-58.13 {Tcl_BinaryObjCmd: scan} {
2149    catch {unset arg1}
2150    set arg1 1
2151    list [catch {binary scan \x3f\xf9\x99\x99\x99\x99\x99\x9a q1 arg1(a)} msg] $msg
2152} {1 {can't set "arg1(a)": variable isn't array}}
2153test binary-58.14 {Tcl_BinaryObjCmd: scan} bigEndian {
2154    catch {unset arg1 arg2}
2155    set arg1 foo
2156    set arg2 bar
2157    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
2158} {2 {1.6 3.4} 5}
2159test binary-58.15 {Tcl_BinaryObjCmd: scan} littleEndian {
2160    catch {unset arg1 arg2}
2161    set arg1 foo
2162    set arg2 bar
2163    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
2164} {2 {1.6 3.4} 5}
2165
2166# scan R/r
2167test binary-59.1 {Tcl_BinaryObjCmd: scan} {
2168    list [catch {binary scan abc r} msg] $msg
2169} {1 {not enough arguments for all format specifiers}}
2170test binary-59.2 {Tcl_BinaryObjCmd: scan} bigEndian {
2171    catch {unset arg1}
2172    list [binary scan \x3f\xcc\xcc\xcd\x40\x59\x99\x9a R* arg1] $arg1
2173} {1 {1.600000023841858 3.4000000953674316}}
2174test binary-59.3 {Tcl_BinaryObjCmd: scan} littleEndian {
2175    catch {unset arg1}
2176    list [binary scan \xcd\xcc\xcc\x3f\x9a\x99\x59\x40 r* arg1] $arg1
2177} {1 {1.600000023841858 3.4000000953674316}}
2178test binary-59.4 {Tcl_BinaryObjCmd: scan} bigEndian {
2179    catch {unset arg1}
2180    list [binary scan \x3f\xcc\xcc\xcd\x40\x59\x99\x9a R arg1] $arg1
2181} {1 1.600000023841858}
2182test binary-59.5 {Tcl_BinaryObjCmd: scan} littleEndian {
2183    catch {unset arg1}
2184    list [binary scan \xcd\xcc\xcc\x3f\x9a\x99\x59\x40 r arg1] $arg1
2185} {1 1.600000023841858}
2186test binary-59.6 {Tcl_BinaryObjCmd: scan} bigEndian {
2187    catch {unset arg1}
2188    list [binary scan \x3f\xcc\xcc\xcd R1 arg1] $arg1
2189} {1 1.600000023841858}
2190test binary-59.7 {Tcl_BinaryObjCmd: scan} littleEndian {
2191    catch {unset arg1}
2192    list [binary scan \xcd\xcc\xcc\x3f r1 arg1] $arg1
2193} {1 1.600000023841858}
2194test binary-59.8 {Tcl_BinaryObjCmd: scan} bigEndian {
2195    catch {unset arg1}
2196    list [binary scan \x3f\xcc\xcc\xcd R0 arg1] $arg1
2197} {1 {}}
2198test binary-59.9 {Tcl_BinaryObjCmd: scan} littleEndian {
2199    catch {unset arg1}
2200    list [binary scan \xcd\xcc\xcc\x3f r0 arg1] $arg1
2201} {1 {}}
2202test binary-59.10 {Tcl_BinaryObjCmd: scan} bigEndian {
2203    catch {unset arg1}
2204    list [binary scan \x3f\xcc\xcc\xcd\x40\x59\x99\x9a R2 arg1] $arg1
2205} {1 {1.600000023841858 3.4000000953674316}}
2206test binary-59.11 {Tcl_BinaryObjCmd: scan} littleEndian {
2207    catch {unset arg1}
2208    list [binary scan \xcd\xcc\xcc\x3f\x9a\x99\x59\x40 r2 arg1] $arg1
2209} {1 {1.600000023841858 3.4000000953674316}}
2210test binary-59.12 {Tcl_BinaryObjCmd: scan} {
2211    catch {unset arg1}
2212    set arg1 foo
2213    list [binary scan \x52 r1 arg1] $arg1
2214} {0 foo}
2215test binary-59.13 {Tcl_BinaryObjCmd: scan} {
2216    catch {unset arg1}
2217    set arg1 1
2218    list [catch {binary scan \x3f\xcc\xcc\xcd r1 arg1(a)} msg] $msg
2219} {1 {can't set "arg1(a)": variable isn't array}}
2220test binary-59.14 {Tcl_BinaryObjCmd: scan} bigEndian {
2221    catch {unset arg1 arg2}
2222    set arg1 foo
2223    set arg2 bar
2224    list [binary scan \x3f\xcc\xcc\xcd\x40\x59\x99\x9a\x05 R2c* arg1 arg2] $arg1 $arg2
2225} {2 {1.600000023841858 3.4000000953674316} 5}
2226test binary-59.15 {Tcl_BinaryObjCmd: scan} littleEndian {
2227    catch {unset arg1 arg2}
2228    set arg1 foo
2229    set arg2 bar
2230    list [binary scan \xcd\xcc\xcc\x3f\x9a\x99\x59\x40\x05 r2c* arg1 arg2] $arg1 $arg2
2231} {2 {1.600000023841858 3.4000000953674316} 5}
2232
2233test binary-60.1 {[binary format] with NaN} -body {
2234    binary scan [binary format dqQfrR NaN NaN NaN NaN NaN NaN] dqQfrR \
2235        v1 v2 v3 v4 v5 v6
2236    list $v1 $v2 $v3 $v4 $v5 $v6
2237} -match regexp -result {NaN(\([[:xdigit:]]+\))? NaN(\([[:xdigit:]]+\))? NaN(\([[:xdigit:]]+\))? NaN(\([[:xdigit:]]+\))? NaN(\([[:xdigit:]]+\))? NaN(\([[:xdigit:]]+\))?}
2238
2239# scan m
2240test binary-61.1 {Tcl_BinaryObjCmd: scan wide int} bigEndian {
2241    binary scan HelloTcl m x
2242    set x
2243} 5216694956358656876
2244test binary-61.2 {Tcl_BinaryObjCmd: scan wide int} littleEndian {
2245    binary scan lcTolleH m x
2246    set x
2247} 5216694956358656876
2248test binary-61.3 {Tcl_BinaryObjCmd: scan wide int with bit 31 set}  littleEndian {
2249    binary scan [binary format w [expr {wide(3) << 31}]] m x
2250    set x
2251} 6442450944
2252test binary-61.4 {Tcl_BinaryObjCmd: scan wide int with bit 31 set} bigEndian {
2253    binary scan [binary format W [expr {wide(3) << 31}]] m x
2254    set x
2255} 6442450944
2256
2257# Big test for correct ordering of data in [expr]
2258
2259proc testIEEE {} {
2260    variable ieeeValues
2261    binary scan [binary format dd -1.0 1.0] c* c
2262    switch -exact -- $c {
2263        {0 0 0 0 0 0 -16 -65 0 0 0 0 0 0 -16 63} {
2264            # little endian
2265            binary scan \x00\x00\x00\x00\x00\x00\xf0\xff d \
2266                ieeeValues(-Infinity)
2267            binary scan \x00\x00\x00\x00\x00\x00\xf0\xbf d \
2268                ieeeValues(-Normal)
2269            binary scan \x00\x00\x00\x00\x00\x00\x08\x80 d \
2270                ieeeValues(-Subnormal)
2271            binary scan \x00\x00\x00\x00\x00\x00\x00\x80 d \
2272                ieeeValues(-0)
2273            binary scan \x00\x00\x00\x00\x00\x00\x00\x00 d \
2274                ieeeValues(+0)
2275            binary scan \x00\x00\x00\x00\x00\x00\x08\x00 d \
2276                ieeeValues(+Subnormal)
2277            binary scan \x00\x00\x00\x00\x00\x00\xf0\x3f d \
2278                ieeeValues(+Normal)
2279            binary scan \x00\x00\x00\x00\x00\x00\xf0\x7f d \
2280                ieeeValues(+Infinity)
2281            binary scan \x00\x00\x00\x00\x00\x00\xf8\x7f d \
2282                ieeeValues(NaN)
2283            set ieeeValues(littleEndian) 1
2284            return 1
2285        }
2286        {-65 -16 0 0 0 0 0 0 63 -16 0 0 0 0 0 0} {
2287            binary scan \xff\xf0\x00\x00\x00\x00\x00\x00 d \
2288                ieeeValues(-Infinity)
2289            binary scan \xbf\xf0\x00\x00\x00\x00\x00\x00 d \
2290                ieeeValues(-Normal)
2291            binary scan \x80\x08\x00\x00\x00\x00\x00\x00 d \
2292                ieeeValues(-Subnormal)
2293            binary scan \x80\x00\x00\x00\x00\x00\x00\x00 d \
2294                ieeeValues(-0)
2295            binary scan \x00\x00\x00\x00\x00\x00\x00\x00 d \
2296                ieeeValues(+0)
2297            binary scan \x00\x08\x00\x00\x00\x00\x00\x00 d \
2298                ieeeValues(+Subnormal)
2299            binary scan \x3f\xf0\x00\x00\x00\x00\x00\x00 d \
2300                ieeeValues(+Normal)
2301            binary scan \x7f\xf0\x00\x00\x00\x00\x00\x00 d \
2302                ieeeValues(+Infinity)
2303            binary scan \x7f\xf8\x00\x00\x00\x00\x00\x00 d \
2304                ieeeValues(NaN)
2305            set ieeeValues(littleEndian) 0
2306            return 1
2307        }
2308        default {
2309            return 0
2310        }
2311    }
2312}
2313
2314testConstraint ieeeFloatingPoint [testIEEE]
2315
2316# scan/format infinities
2317
2318test binary-62.1 {infinity} ieeeFloatingPoint {
2319    binary scan [binary format q Infinity] w w
2320    format 0x%016lx $w
2321} 0x7ff0000000000000
2322test binary-62.2 {infinity} ieeeFloatingPoint {
2323    binary scan [binary format q -Infinity] w w
2324    format 0x%016lx $w
2325} 0xfff0000000000000
2326test binary-62.3 {infinity} ieeeFloatingPoint {
2327    binary scan [binary format q Inf] w w
2328    format 0x%016lx $w
2329} 0x7ff0000000000000
2330test binary-62.4 {infinity} ieeeFloatingPoint {
2331    binary scan [binary format q -Infinity] w w
2332    format 0x%016lx $w
2333} 0xfff0000000000000
2334test binary-62.5 {infinity} ieeeFloatingPoint {
2335    binary scan [binary format w 0x7ff0000000000000] q d
2336    set d
2337} Inf
2338test binary-62.6 {infinity} ieeeFloatingPoint {
2339    binary scan [binary format w 0xfff0000000000000] q d
2340    set d
2341} -Inf
2342
2343# scan/format Not-a-Number
2344
2345test binary-63.1 {NaN} ieeeFloatingPoint {
2346    binary scan [binary format q NaN] w w
2347    format 0x%016lx [expr {$w & 0xfff3ffffffffffff}]
2348} 0x7ff0000000000000
2349test binary-63.2 {NaN} ieeeFloatingPoint {
2350    binary scan [binary format q -NaN] w w
2351    format 0x%016lx [expr {$w & 0xfff3ffffffffffff}]
2352} 0xfff0000000000000
2353test binary-63.3 {NaN} ieeeFloatingPoint {
2354    binary scan [binary format q NaN(3123456789aBc)] w w
2355    format 0x%016lx [expr {$w & 0xfff3ffffffffffff}]
2356} 0x7ff3123456789abc
2357test binary-63.4 {NaN} ieeeFloatingPoint {
2358    binary scan [binary format q {NaN( 3123456789aBc)}] w w
2359    format 0x%016lx [expr {$w & 0xfff3ffffffffffff}]
2360} 0x7ff3123456789abc
2361test binary-64.1 {NaN} \
2362    -constraints ieeeFloatingPoint \
2363    -body {
2364        binary scan [binary format w 0x7ff8000000000000] q d
2365        set d
2366    } \
2367    -match glob -result NaN*
2368test binary-64.2 {NaN} \
2369    -constraints ieeeFloatingPoint \
2370    -body {
2371        binary scan [binary format w 0x7ff0123456789aBc] q d
2372        set d
2373    } \
2374    -match glob -result NaN(*123456789abc)
2375
2376test binary-65.1 {largest significand} ieeeFloatingPoint {
2377    binary scan [binary format w 0x3fcfffffffffffff] q d
2378    set d
2379} 0.24999999999999997
2380test binary-65.2 {smallest significand} ieeeFloatingPoint {
2381    binary scan [binary format w 0x3fd0000000000000] q d
2382    set d
2383} 0.25
2384test binary-65.3 {largest significand} ieeeFloatingPoint {
2385    binary scan [binary format w 0x3fdfffffffffffff] q d
2386    set d
2387} 0.49999999999999994
2388test binary-65.4 {smallest significand} ieeeFloatingPoint {
2389    binary scan [binary format w 0x3fe0000000000000] q d
2390    set d
2391} 0.5
2392test binary-65.5 {largest significand} ieeeFloatingPoint {
2393    binary scan [binary format w 0x3fffffffffffffff] q d
2394    set d
2395} 1.9999999999999998
2396test binary-65.6 {smallest significand} ieeeFloatingPoint {
2397    binary scan [binary format w 0x4000000000000000] q d
2398    set d
2399} 2.0
2400test binary-65.7 {smallest significand} ieeeFloatingPoint {
2401    binary scan [binary format w 0x434fffffffffffff] q d
2402    set d
2403} 18014398509481982.0
2404test binary-65.8 {largest significand} ieeeFloatingPoint {
2405    binary scan [binary format w 0x4350000000000000] q d
2406    set d
2407} 18014398509481984.0
2408test binary-65.9 {largest significand} ieeeFloatingPoint {
2409    binary scan [binary format w 0x4350000000000001] q d
2410    set d
2411} 18014398509481988.0
2412
2413# cleanup
2414::tcltest::cleanupTests
2415return
2416
2417# Local Variables:
2418# mode: tcl
2419# End:
Note: See TracBrowser for help on using the repository browser.