1 # Commands covered: scan
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.
7 # Copyright (c) 1991-1994 The Regents of the University of California.
8 # Copyright (c) 1994-1997 Sun Microsystems, Inc.
9 # Copyright (c) 1998-1999 by Scriptics Corporation.
11 # See the file "license.terms" for information on usage and redistribution
12 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14 # RCS: @(#) $Id: scan.test,v 1.10.2.2 2002/02/07 01:54:04 hobbs Exp $
16 source [file dirname [info script]]/testing.tcl
20 test scan-1.1 {BuildCharSet, CharInSet} {
21 list [scan foo {%[^o]} x] $x
23 test scan-1.2 {BuildCharSet, CharInSet} {
24 list [scan \]foo {%[]f]} x] $x
26 test scan-1.3 {BuildCharSet, CharInSet} {
27 list [scan abc-def {%[a-c]} x] $x
29 test scan-1.4 {BuildCharSet, CharInSet} {
30 list [scan abc-def {%[a-c]} x] $x
32 test scan-1.5 {BuildCharSet, CharInSet} {
33 list [scan -abc-def {%[-ac]} x] $x
35 test scan-1.6 {BuildCharSet, CharInSet} {
36 list [scan -abc-def {%[ac-]} x] $x
38 test scan-1.7 {BuildCharSet, CharInSet} {
39 list [scan abc-def {%[c-a]} x] $x
41 test scan-1.8 {BuildCharSet, CharInSet} {
42 list [scan def-abc {%[^c-a]} x] $x
44 test scan-1.9 {BuildCharSet, CharInSet no match} {
46 list [scan {= f} {= %[TF]} x] [info exists x]
49 test scan-2.1 {ReleaseCharSet} {
50 list [scan abcde {%[abc]} x] $x
52 test scan-2.2 {ReleaseCharSet} {
53 list [scan abcde {%[a-c]} x] $x
56 test scan-3.1 {ValidateFormat} {
57 list [catch {scan {} {%d%1$d} x} msg] $msg
58 } {1 {cannot mix "%" and "%n$" conversion specifiers}}
59 test scan-3.2 {ValidateFormat} {
60 list [catch {scan {} {%d%1$d} x} msg] $msg
61 } {1 {cannot mix "%" and "%n$" conversion specifiers}}
62 test scan-3.3 {ValidateFormat} {
63 list [catch {scan {} {%2$d%d} x} msg] $msg
64 } {1 {"%n$" argument index out of range}}
65 test scan-3.4 {ValidateFormat} {
66 # degenerate case, before changed from 8.2 to 8.3
67 list [catch {scan {} %d} msg] $msg
69 test scan-3.5 {ValidateFormat} {
70 list [catch {scan {} {%10c} a} msg] $msg
71 } {1 {field width may not be specified in %c conversion}}
72 test scan-3.6 {ValidateFormat} jim {
73 list [catch {scan {} {%*1$d} a} msg] $msg
74 } {1 {bad scan conversion character}}
75 test scan-3.7 {ValidateFormat} {
76 list [catch {scan {} {%1$d%1$d} a} msg] $msg
77 } {1 {variable is assigned by multiple "%n$" conversion specifiers}}
78 test scan-3.8 {ValidateFormat} {
79 list [catch {scan {} a x} msg] $msg
80 } {1 {variable is not assigned by any conversion specifiers}}
81 test scan-3.9 {ValidateFormat} {
82 list [catch {scan {} {%2$s} x y} msg] $msg
83 } {1 {variable is not assigned by any conversion specifiers}}
84 test scan-3.10 {ValidateFormat} {
85 list [catch {scan {} {%[a} x} msg] $msg
86 } {1 {unmatched [ in format string}}
87 test scan-3.11 {ValidateFormat} {
88 list [catch {scan {} {%[^a} x} msg] $msg
89 } {1 {unmatched [ in format string}}
90 test scan-3.12 {ValidateFormat} {
91 list [catch {scan {} {%[]a} x} msg] $msg
92 } {1 {unmatched [ in format string}}
93 test scan-3.13 {ValidateFormat} {
94 list [catch {scan {} {%[^]a} x} msg] $msg
95 } {1 {unmatched [ in format string}}
97 test scan-4.1 {Tcl_ScanObjCmd, argument checks} jim {
98 list [catch {scan} msg] $msg
99 } {1 {wrong # args: should be "scan string format ?varName varName ...?"}}
100 test scan-4.2 {Tcl_ScanObjCmd, argument checks} jim {
101 list [catch {scan string} msg] $msg
102 } {1 {wrong # args: should be "scan string format ?varName varName ...?"}}
103 test scan-4.3 {Tcl_ScanObjCmd, argument checks} {
104 # degenerate case, before changed from 8.2 to 8.3
105 list [catch {scan string format} msg] $msg
107 test scan-4.4 {Tcl_ScanObjCmd, whitespace} {
108 list [scan { abc def } {%s%s} x y] $x $y
110 test scan-4.5 {Tcl_ScanObjCmd, whitespace} {
111 list [scan { abc def } { %s %s } x y] $x $y
113 test scan-4.6 {Tcl_ScanObjCmd, whitespace} {
114 list [scan { abc def } { %s %s } x y] $x $y
116 test scan-4.7 {Tcl_ScanObjCmd, literals} {
117 # degenerate case, before changed from 8.2 to 8.3
118 scan { abc def } { abc def }
120 test scan-4.8 {Tcl_ScanObjCmd, literals} {
122 list [scan { abcg} { abc def %1s} x] $x
124 test scan-4.9 {Tcl_ScanObjCmd, literals} {
125 list [scan { abc%defghi} { abc %% def%n } x] $x
127 test scan-4.10 {Tcl_ScanObjCmd, assignment suppression} {
128 list [scan { abc def } { %*c%s def } x] $x
130 test scan-4.11 {Tcl_ScanObjCmd, XPG3-style} {
131 list [scan { abc def } {%2$s %1$s} x y] $x $y
133 test scan-4.12 {Tcl_ScanObjCmd, width specifiers} {
134 list [scan {abc123456789012} {%3s%3d%3f%3[0-9]%s} a b c d e] $a $b $c $d $e
135 } {5 abc 123 456.0 789 012}
136 test scan-4.13 {Tcl_ScanObjCmd, width specifiers} {
137 list [scan {abc123456789012} {%3s%3d%3f%3[0-9]%s} a b c d e] $a $b $c $d $e
138 } {5 abc 123 456.0 789 012}
139 test scan-4.14 {Tcl_ScanObjCmd, underflow} {
141 list [scan {a} {a%d} x] $x
143 test scan-4.15 {Tcl_ScanObjCmd, underflow} {
145 list [scan {} {a%d} x] $x
147 test scan-4.16 {Tcl_ScanObjCmd, underflow} {
149 list [scan {ab} {a%d} x] $x
151 test scan-4.17 {Tcl_ScanObjCmd, underflow} {
153 list [scan {a } {a%d} x] $x
155 test scan-4.18 {Tcl_ScanObjCmd, skipping whitespace} {
156 list [scan { b} {%c%s} x y] $x $y
158 test scan-4.19 {Tcl_ScanObjCmd, skipping whitespace} {
159 list [scan { b} {%[^b]%s} x y] $x $y
161 test scan-4.20 {Tcl_ScanObjCmd, string scanning} {
162 list [scan {abc def} {%s} x] $x
164 test scan-4.21 {Tcl_ScanObjCmd, string scanning} {
165 list [scan {abc def} {%0s} x] $x
167 test scan-4.22 {Tcl_ScanObjCmd, string scanning} {
168 list [scan {abc def} {%2s} x] $x
170 test scan-4.23 {Tcl_ScanObjCmd, string scanning} {
171 list [scan {abc def} {%*s%n} x] $x
173 test scan-4.24 {Tcl_ScanObjCmd, charset scanning} {
174 list [scan {abcdef} {%[a-c]} x] $x
176 test scan-4.25 {Tcl_ScanObjCmd, charset scanning} {
177 list [scan {abcdef} {%0[a-c]} x] $x
179 test scan-4.26 {Tcl_ScanObjCmd, charset scanning} {
180 list [scan {abcdef} {%2[a-c]} x] $x
182 test scan-4.27 {Tcl_ScanObjCmd, charset scanning} {
183 list [scan {abcdef} {%*[a-c]%n} x] $x
185 test scan-4.28 {Tcl_ScanObjCmd, character scanning} {
186 list [scan {abcdef} {%c} x] $x
188 test scan-4.29 {Tcl_ScanObjCmd, character scanning} {
189 list [scan {abcdef} {%*c%n} x] $x
192 test scan-4.30 {Tcl_ScanObjCmd, base-10 integer scanning} {
194 list [scan {1234567890a} {%3d} x] $x
196 test scan-4.31 {Tcl_ScanObjCmd, base-10 integer scanning} {
198 list [scan {1234567890a} {%d} x] $x
200 test scan-4.32 {Tcl_ScanObjCmd, base-10 integer scanning} {
202 list [scan {01234567890a} {%d} x] $x
204 test scan-4.33 {Tcl_ScanObjCmd, base-10 integer scanning} {
206 list [scan {+01234} {%d} x] $x
208 test scan-4.34 {Tcl_ScanObjCmd, base-10 integer scanning} {
210 list [scan {-01234} {%d} x] $x
212 test scan-4.35 {Tcl_ScanObjCmd, base-10 integer scanning} {
214 list [scan {a01234} {%d} x] $x
216 test scan-4.36 {Tcl_ScanObjCmd, base-10 integer scanning} {
218 list [scan {0x10} {%d} x] $x
220 test scan-4.37 {Tcl_ScanObjCmd, base-8 integer scanning} {
222 list [scan {012345678} {%o} x] $x
224 test scan-4.38 {Tcl_ScanObjCmd, base-8 integer scanning} {
226 list [scan {+1238 -1239 123a} {%o%*s%o%*s%o} x y z] $x $y $z
228 test scan-4.39 {Tcl_ScanObjCmd, base-16 integer scanning} {
230 list [scan {+1238 -123a 0123} {%x%x%x} x y z] $x $y $z
232 test scan-4.40 {Tcl_ScanObjCmd, base-16 integer scanning} {
233 # The behavior changed in 8.4a4/8.3.4cvs (6 Feb) to correctly
234 # return '1' for 0x1 scanned via %x, to comply with 8.0 and C scanf.
237 list [scan {aBcDeF AbCdEf 0x1} {%x%x%x} x y z] $x $y $z
238 } {3 11259375 11259375 1}
239 test scan-4.40.1 {Tcl_ScanObjCmd, base-16 integer scanning} {
241 list [scan {0xF 0x00A0B 0X0XF} {%x %x %x} x y z] $x $y $z
243 test scan-4.40.2 {Tcl_ScanObjCmd, base-16 integer scanning} {
245 list [scan {xF} {%x} x] [info exists x]
247 test scan-4.41 {Tcl_ScanObjCmd, base-unknown integer scanning} {
249 list [scan {10 010 0x10} {%i%i%i} x y z] $x $y $z
251 test scan-4.42 {Tcl_ScanObjCmd, base-unknown integer scanning} {
253 list [scan {10 010 0X10} {%i%i%i} x y z] $x $y $z
255 test scan-4.43 {Tcl_ScanObjCmd, integer scanning, odd cases} {
257 list [scan {+ } {%i} x] $x
259 #test scan-4.44 {Tcl_ScanObjCmd, integer scanning, odd cases} {
261 # list [scan {+} {%i} x] $x
263 test scan-4.45 {Tcl_ScanObjCmd, integer scanning, odd cases} {
265 list [scan {0x} {%i%s} x y] $x $y
267 test scan-4.46 {Tcl_ScanObjCmd, integer scanning, odd cases} {
269 list [scan {0X} {%i%s} x y] $x $y
271 test scan-4.47 {Tcl_ScanObjCmd, integer scanning, suppressed} {
273 list [scan {123def} {%*i%s} x] $x
275 test scan-4.48 {Tcl_ScanObjCmd, float scanning} {
276 list [scan {1 2 3} {%e %f %g} x y z] $x $y $z
278 test scan-4.49 {Tcl_ScanObjCmd, float scanning} {
279 list [scan {.1 0.2 3.} {%e %f %g} x y z] $x $y $z
281 test scan-4.50 {Tcl_ScanObjCmd, float scanning} {
282 list [scan {1234567890a} %f x] $x
284 test scan-4.51 {Tcl_ScanObjCmd, float scanning} {
285 list [scan {+123+45} %f x] $x
287 test scan-4.52 {Tcl_ScanObjCmd, float scanning} {
288 list [scan {-123+45} %f x] $x
290 test scan-4.53 {Tcl_ScanObjCmd, float scanning} {
291 list [scan {1.0e1} %f x] $x
293 test scan-4.54 {Tcl_ScanObjCmd, float scanning} {
294 list [scan {1.0e-1} %f x] $x
296 #test scan-4.55 {Tcl_ScanObjCmd, odd cases} {
298 # list [scan {+} %f x] $x
300 test scan-4.56 {Tcl_ScanObjCmd, odd cases} {
302 list [scan {1.0e} %f%s x y] $x $y
304 test scan-4.57 {Tcl_ScanObjCmd, odd cases} {
306 list [scan {1.0e+} %f%s x y] $x $y
308 test scan-4.58 {Tcl_ScanObjCmd, odd cases} {
311 list [scan {e1} %f%s x y] $x $y
313 test scan-4.59 {Tcl_ScanObjCmd, float scanning} {
314 list [scan {1.0e-1x} %*f%n x] $x
317 test scan-4.60 {Tcl_ScanObjCmd, set errors} {
321 set result [list [catch {scan {abc def ghi} {%s%s%s} x z(z) y} msg] \
325 test scan-4.61 {Tcl_ScanObjCmd, set errors} {
329 set result [list [catch {scan {abc def ghi} {%s%s%s} x y(y) z(z)} msg] \
334 # procedure that returns the range of integers
336 # On Tcl with bignum, these won't produce a result!
338 for { set MIN_INT 1 } { $MIN_INT > 0 } {} {
339 set MIN_INT [expr { $MIN_INT << 1 }]
341 set MAX_INT [expr { ~ $MIN_INT }]
342 return [list $MIN_INT $MAX_INT]
345 test scan-4.62 {scanning of large and negative octal integers} jim {
346 foreach { MIN_INT MAX_INT } [int_range] {}
347 set scanstring [format {%o %o %o} -1 $MIN_INT $MAX_INT]
348 list [scan $scanstring {%o %o %o} a b c] \
349 [expr { $a == -1 }] [expr { $b == $MIN_INT }] [expr { $c == $MAX_INT }]
351 test scan-4.63 {scanning of large and negative hex integers} jim {
352 foreach { MIN_INT MAX_INT } [int_range] {}
353 set scanstring [format {%x %x %x} -1 $MIN_INT $MAX_INT]
354 list [scan $scanstring {%x %x %x} a b c] \
355 [expr { $a == -1 }] [expr { $b == $MIN_INT }] [expr { $c == $MAX_INT }]
358 # clean up from last two tests
364 test scan-5.1 {integer scanning} {
365 set a {}; set b {}; set c {}; set d {}
366 list [scan "-20 1476 \n33 0" "%d %d %d %d" a b c d] $a $b $c $d
368 test scan-5.2 {integer scanning} {
369 set a {}; set b {}; set c {}
370 list [scan "-45 16 7890 +10" "%2d %*d %10d %d" a b c] $a $b $c
372 test scan-5.3 {integer scanning} {
373 set a {}; set b {}; set c {}; set d {}
374 list [scan "-45 16 +10 987" "%ld %d %ld %d" a b c d] $a $b $c $d
376 test scan-5.4 {integer scanning} {
377 set a {}; set b {}; set c {}; set d {}
378 list [scan "14 1ab 62 10" "%d %x %lo %x" a b c d] $a $b $c $d
380 test scan-5.5 {integer scanning} {
381 set a {}; set b {}; set c {}; set d {}
382 list [scan "12345670 1234567890ab cdefg" "%o %o %x %lx" a b c d] \
384 } {4 2739128 342391 561323 52719}
385 test scan-5.6 {integer scanning} {
386 set a {}; set b {}; set c {}; set d {}
387 list [scan "ab123-24642" "%2x %3x %3o %2o" a b c d] $a $b $c $d
389 test scan-5.7 {integer scanning} {
391 list [scan "1234567 234 567 " "%*3x %x %*o %4o" a b] $a $b
393 test scan-5.8 {integer scanning} {
395 list [scan "a 1234" "%d %d" a b] $a $b
397 test scan-5.9 {integer scanning} {
398 set a {}; set b {}; set c {}; set d {};
399 list [scan "12345678" "%2d %2d %2ld %2d" a b c d] $a $b $c $d
401 test scan-5.10 {integer scanning} {
402 set a {}; set b {}; set c {}; set d {}
403 list [scan "1 2 " "%hd %d %d %d" a b c d] $a $b $c $d
406 # The behavior for scaning intergers larger than MAX_INT is
407 # not defined by the ANSI spec. Some implementations wrap the
408 # input (-16) some return MAX_INT.
410 test scan-5.11 {integer scanning} {
412 list [scan "4294967280 4294967280" "%u %d" a b] $a \
413 [expr {$b == -16 || $b == 0x7fffffff || $b == $a}]
416 test scan-6.1 {floating-point scanning} {
417 set a {}; set b {}; set c {}; set d {}
418 list [scan "2.1 -3.0e8 .99962 a" "%f%g%e%f" a b c d] $a $b $c $d
419 } {3 2.1 -300000000.0 0.99962 {}}
420 test scan-6.2 {floating-point scanning} {
421 set a {}; set b {}; set c {}; set d {}
422 list [scan "-1.2345 +8.2 9" "%3e %3lf %f %f" a b c d] $a $b $c $d
423 } {4 -1.0 234.0 5.0 8.2}
424 test scan-6.3 {floating-point scanning} {
425 set a {}; set b {}; set c {}
426 list [scan "1e00004 332E-4 3e+4" "%Lf %*2e %f %f" a b c] $a $c
427 } {3 10000.0 30000.0}
429 # Some libc implementations consider 3.e- bad input. The ANSI
430 # spec states that digits must follow the - sign.
432 test scan-6.4 {floating-point scanning} {
433 set a {}; set b {}; set c {}
434 list [scan "1. 47.6 2.e2 3.e-" "%f %*f %f %f" a b c] $a $b $c
436 test scan-6.5 {floating-point scanning} {
437 set a {}; set b {}; set c {}; set d {}
438 list [scan "4.6 99999.7 876.43e-1 118" "%f %f %f %e" a b c d] $a $b $c $d
439 } {4 4.6 99999.7 87.643 118.0}
440 test scan-6.6 {floating-point scanning} jim {
441 set a {}; set b {}; set c {}; set d {}
442 list [scan "1.2345 697.0e-3 124 .00005" "%f %e %f %e" a b c d] $a $b $c $d
443 } {4 1.2345 0.697 124.0 5e-05}
444 test scan-6.7 {floating-point scanning} {
445 set a {}; set b {}; set c {}; set d {}
446 list [scan "4.6abc" "%f %f %f %f" a b c d] $a $b $c $d
448 test scan-6.8 {floating-point scanning} {
449 set a {}; set b {}; set c {}; set d {}
450 list [scan "4.6 5.2" "%f %f %f %f" a b c d] $a $b $c $d
453 test scan-7.1 {string and character scanning} {
454 set a {}; set b {}; set c {}; set d {}
455 list [scan "abc defghijk dum " "%s %3s %20s %s" a b c d] $a $b $c $d
456 } {4 abc def ghijk dum}
457 test scan-7.2 {string and character scanning} {
458 set a {}; set b {}; set c {}; set d {}
459 list [scan "a bcdef" "%c%c%1s %s" a b c d] $a $b $c $d
461 test scan-7.3 {string and character scanning} {
462 set a {}; set b {}; set c {}
463 list [scan "123456 test " "%*c%*s %s %s %s" a b c] $a $b $c
465 test scan-7.4 {string and character scanning} {
466 set a {}; set b {}; set c {}; set d
467 list [scan "ababcd01234 f 123450" {%4[abcd] %4[abcd] %[^abcdef] %[^0]} a b c d] $a $b $c $d
468 } {4 abab cd {01234 } {f 12345}}
469 test scan-7.5 {string and character scanning} {
470 set a {}; set b {}; set c {}
471 list [scan "aaaaaabc aaabcdefg + + XYZQR" {%*4[a] %s %*4[a]%s%*4[ +]%c} a b c] $a $b $c
473 test scan-7.6 {string and character scanning, unicode} utf8 {
474 set a {}; set b {}; set c {}; set d {}
475 list [scan "abc d\u00c7fghijk dum " "%s %3s %20s %s" a b c d] $a $b $c $d
476 } "4 abc d\u00c7f ghijk dum"
477 test scan-7.7 {string and character scanning, unicode} utf8 {
479 list [scan "ab\u00c7cdef" "ab%c%c" a b] $a $b
481 test scan-7.8 {string and character scanning, unicode} utf8 {
483 list [scan "ab\ufeffdef" "%\[ab\ufeff\]" a] $a
485 test scan-8.1 {error conditions} {
488 test scan-8.2 {error conditions} jim {
491 } {wrong # args: should be "scan string format ?varName varName ...?"}
492 test scan-8.3 {error conditions} jim {
493 list [catch {scan a %D x} msg] $msg
494 } {1 {bad scan conversion character}}
495 test scan-8.4 {error conditions} jim {
496 list [catch {scan a %O x} msg] $msg
497 } {1 {bad scan conversion character}}
498 test scan-8.5 {error conditions} jim {
499 list [catch {scan a %X x} msg] $msg
500 } {1 {bad scan conversion character}}
501 test scan-8.6 {error conditions} jim {
502 list [catch {scan a %F x} msg] $msg
503 } {1 {bad scan conversion character}}
504 test scan-8.7 {error conditions} jim {
505 list [catch {scan a %E x} msg] $msg
506 } {1 {bad scan conversion character}}
507 test scan-8.8 {error conditions} {
508 list [catch {scan a "%d %d" a} msg] $msg
509 } {1 {different numbers of variable names and field specifiers}}
510 test scan-8.9 {error conditions} {
511 list [catch {scan a "%d %d" a b c} msg] $msg
512 } {1 {variable is not assigned by any conversion specifiers}}
513 test scan-8.10 {error conditions} {
514 set a {}; set b {}; set c {}; set d {}
515 list [expr {[scan " a" " a %d %d %d %d" a b c d] <= 0}] $a $b $c $d
517 test scan-8.11 {error conditions} {
518 set a {}; set b {}; set c {}; set d {}
519 list [scan "1 2" "%d %d %d %d" a b c d] $a $b $c $d
521 test scan-8.12 {error conditions} {
523 list [catch {scan 44 %d a(0)} msg]
525 test scan-8.13 {error conditions} {
527 list [catch {scan 44 %c a(0)} msg]
529 test scan-8.14 {error conditions} {
531 list [catch {scan 44 %s a(0)} msg]
533 test scan-8.15 {error conditions} {
535 list [catch {scan 44 %f a(0)} msg]
542 test scan-8.17 {error conditions} {
543 list [catch {scan 44 %2c a} msg] $msg
544 } {1 {field width may not be specified in %c conversion}}
545 test scan-8.18 {error conditions} {
546 list [catch {scan abc {%[} x} msg] $msg
547 } {1 {unmatched [ in format string}}
548 test scan-8.19 {error conditions} {
549 list [catch {scan abc {%[^a} x} msg] $msg
550 } {1 {unmatched [ in format string}}
551 test scan-8.20 {error conditions} {
552 list [catch {scan abc {%[^]a} x} msg] $msg
553 } {1 {unmatched [ in format string}}
554 test scan-8.21 {error conditions} {
555 list [catch {scan abc {%[]a} x} msg] $msg
556 } {1 {unmatched [ in format string}}
558 test scan-9.1 {lots of arguments} {
559 scan "10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200" "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d" a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20
561 test scan-9.2 {lots of arguments} {
562 scan "10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200" "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d" a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20
566 test scan-10.1 {miscellaneous tests} {
568 list [scan ab16c ab%dc a] $a
570 test scan-10.2 {miscellaneous tests} {
572 list [scan ax16c ab%dc a] $a
574 test scan-10.3 {miscellaneous tests} {
576 list [catch {scan ab%c114 ab%%c%d a} msg] $msg $a
578 test scan-10.4 {miscellaneous tests} {
580 list [catch {scan ab%c14 ab%%c%d a} msg] $msg $a
582 test scan-10.5 {miscellaneous tests} {
585 list [catch {scan ab%c14 ab%%c%d arr(2)} msg] $msg $arr(2)
588 test scan-11.1 {alignment in results array (TCL_ALIGN)} {
589 scan "123 13.6" "%s %f" a b
592 test scan-11.2 {alignment in results array (TCL_ALIGN)} {
593 scan "1234567 13.6" "%s %f" a b
596 test scan-11.3 {alignment in results array (TCL_ALIGN)} {
597 scan "12345678901 13.6" "%s %f" a b
600 test scan-11.4 {alignment in results array (TCL_ALIGN)} {
601 scan "123456789012345 13.6" "%s %f" a b
604 test scan-11.5 {alignment in results array (TCL_ALIGN)} {
605 scan "1234567890123456789 13.6" "%s %f" a b
609 test scan-12.1 {Tcl_ScanObjCmd, inline case} {
612 test scan-12.2 {Tcl_ScanObjCmd, inline case} {
615 test scan-12.3 {Tcl_ScanObjCmd, inline case} {
618 test scan-12.4 {Tcl_ScanObjCmd, inline case, underflow} {
621 test scan-12.5 {Tcl_ScanObjCmd, inline case} {
624 test scan-12.6 {Tcl_ScanObjCmd, inline case} {
625 # degenerate case, behavior changed from 8.2 to 8.3
626 list [catch {scan foo foobar} msg] $msg
628 test scan-12.7 {Tcl_ScanObjCmd, inline case lots of arguments} {
629 scan "10 20 30 40 50 60 70 80 90 100 110 120 130 140\
630 150 160 170 180 190 200" \
631 "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d"
632 } {10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 {}}
634 test scan-13.1 {Tcl_ScanObjCmd, inline XPG case} {
637 test scan-13.2 {Tcl_ScanObjCmd, inline XPG case} {
638 scan abc {%1$c%2$c%3$c%4$c}
640 test scan-13.3 {Tcl_ScanObjCmd, inline XPG case} {
641 list [catch {scan abc {%1$c%1$c}} msg] $msg
642 } {1 {variable is assigned by multiple "%n$" conversion specifiers}}
643 test scan-13.4 {Tcl_ScanObjCmd, inline XPG case} {
646 test scan-13.5 {Tcl_ScanObjCmd, inline XPG case, underflow} {
649 test scan-13.6 {Tcl_ScanObjCmd, inline XPG case} {
650 catch {scan abc {bogus%1$c%5$c%10$c}} msg
651 list [llength $msg] $msg
652 } {10 {{} {} {} {} {} {} {} {} {} {}}}
653 test scan-13.7 {Tcl_ScanObjCmd, inline XPG case lots of arguments} {
654 scan "10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200" {%20$d %18$d %17$d %16$d %15$d %14$d %13$d %12$d %11$d %10$d %9$d %8$d %7$d %6$d %5$d %4$d %3$d %2$d %1$d}
655 } {190 180 170 160 150 140 130 120 110 100 90 80 70 60 50 40 30 20 {} 10}
656 test scan-13.8 {Tcl_ScanObjCmd, inline XPG case lots of arguments} {
657 set msg [scan "10 20 30" {%100$d %5$d %200$d}]
658 list [llength $msg] [lindex $msg 99] [lindex $msg 4] [lindex $msg 199]
661 test scan-14.1 {scan with null chars} {
665 test scan-14.2 {scan with null chars} {
669 test scan-14.3 {scan with null chars} {
670 scan ab12x\0 %cb%dx%c