os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/scan.test
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/scan.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,683 @@
1.4 +# Commands covered: scan
1.5 +#
1.6 +# This file contains a collection of tests for one or more of the Tcl
1.7 +# built-in commands. Sourcing this file into Tcl runs the tests and
1.8 +# generates output for errors. No output means no errors were found.
1.9 +#
1.10 +# Copyright (c) 1991-1994 The Regents of the University of California.
1.11 +# Copyright (c) 1994-1997 Sun Microsystems, Inc.
1.12 +# Copyright (c) 1998-1999 by Scriptics Corporation.
1.13 +#
1.14 +# See the file "license.terms" for information on usage and redistribution
1.15 +# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
1.16 +#
1.17 +# RCS: @(#) $Id: scan.test,v 1.14.2.1 2004/08/19 21:12:04 dkf Exp $
1.18 +
1.19 +if {[lsearch [namespace children] ::tcltest] == -1} {
1.20 + package require tcltest 2
1.21 + namespace import -force ::tcltest::*
1.22 +}
1.23 +
1.24 +::tcltest::testConstraint 64bitInts [expr {0x80000000 > 0}]
1.25 +
1.26 +test scan-1.1 {BuildCharSet, CharInSet} {
1.27 + list [scan foo {%[^o]} x] $x
1.28 +} {1 f}
1.29 +test scan-1.2 {BuildCharSet, CharInSet} {
1.30 + list [scan \]foo {%[]f]} x] $x
1.31 +} {1 \]f}
1.32 +test scan-1.3 {BuildCharSet, CharInSet} {
1.33 + list [scan abc-def {%[a-c]} x] $x
1.34 +} {1 abc}
1.35 +test scan-1.4 {BuildCharSet, CharInSet} {
1.36 + list [scan abc-def {%[a-c]} x] $x
1.37 +} {1 abc}
1.38 +test scan-1.5 {BuildCharSet, CharInSet} {
1.39 + list [scan -abc-def {%[-ac]} x] $x
1.40 +} {1 -a}
1.41 +test scan-1.6 {BuildCharSet, CharInSet} {
1.42 + list [scan -abc-def {%[ac-]} x] $x
1.43 +} {1 -a}
1.44 +test scan-1.7 {BuildCharSet, CharInSet} {
1.45 + list [scan abc-def {%[c-a]} x] $x
1.46 +} {1 abc}
1.47 +test scan-1.8 {BuildCharSet, CharInSet} {
1.48 + list [scan def-abc {%[^c-a]} x] $x
1.49 +} {1 def-}
1.50 +test scan-1.9 {BuildCharSet, CharInSet no match} {
1.51 + catch {unset x}
1.52 + list [scan {= f} {= %[TF]} x] [info exists x]
1.53 +} {0 0}
1.54 +
1.55 +test scan-2.1 {ReleaseCharSet} {
1.56 + list [scan abcde {%[abc]} x] $x
1.57 +} {1 abc}
1.58 +test scan-2.2 {ReleaseCharSet} {
1.59 + list [scan abcde {%[a-c]} x] $x
1.60 +} {1 abc}
1.61 +
1.62 +test scan-3.1 {ValidateFormat} {
1.63 + list [catch {scan {} {%d%1$d} x} msg] $msg
1.64 +} {1 {cannot mix "%" and "%n$" conversion specifiers}}
1.65 +test scan-3.2 {ValidateFormat} {
1.66 + list [catch {scan {} {%d%1$d} x} msg] $msg
1.67 +} {1 {cannot mix "%" and "%n$" conversion specifiers}}
1.68 +test scan-3.3 {ValidateFormat} {
1.69 + list [catch {scan {} {%2$d%d} x} msg] $msg
1.70 +} {1 {"%n$" argument index out of range}}
1.71 +test scan-3.4 {ValidateFormat} {
1.72 + # degenerate case, before changed from 8.2 to 8.3
1.73 + list [catch {scan {} %d} msg] $msg
1.74 +} {0 {}}
1.75 +test scan-3.5 {ValidateFormat} {
1.76 + list [catch {scan {} {%10c} a} msg] $msg
1.77 +} {1 {field width may not be specified in %c conversion}}
1.78 +test scan-3.6 {ValidateFormat} {
1.79 + list [catch {scan {} {%*1$d} a} msg] $msg
1.80 +} {1 {bad scan conversion character "$"}}
1.81 +test scan-3.7 {ValidateFormat} {
1.82 + list [catch {scan {} {%1$d%1$d} a} msg] $msg
1.83 +} {1 {variable is assigned by multiple "%n$" conversion specifiers}}
1.84 +test scan-3.8 {ValidateFormat} {
1.85 + list [catch {scan {} a x} msg] $msg
1.86 +} {1 {variable is not assigned by any conversion specifiers}}
1.87 +test scan-3.9 {ValidateFormat} {
1.88 + list [catch {scan {} {%2$s} x y} msg] $msg
1.89 +} {1 {variable is not assigned by any conversion specifiers}}
1.90 +test scan-3.10 {ValidateFormat} {
1.91 + list [catch {scan {} {%[a} x} msg] $msg
1.92 +} {1 {unmatched [ in format string}}
1.93 +test scan-3.11 {ValidateFormat} {
1.94 + list [catch {scan {} {%[^a} x} msg] $msg
1.95 +} {1 {unmatched [ in format string}}
1.96 +test scan-3.12 {ValidateFormat} {
1.97 + list [catch {scan {} {%[]a} x} msg] $msg
1.98 +} {1 {unmatched [ in format string}}
1.99 +test scan-3.13 {ValidateFormat} {
1.100 + list [catch {scan {} {%[^]a} x} msg] $msg
1.101 +} {1 {unmatched [ in format string}}
1.102 +
1.103 +test scan-4.1 {Tcl_ScanObjCmd, argument checks} {
1.104 + list [catch {scan} msg] $msg
1.105 +} {1 {wrong # args: should be "scan string format ?varName varName ...?"}}
1.106 +test scan-4.2 {Tcl_ScanObjCmd, argument checks} {
1.107 + list [catch {scan string} msg] $msg
1.108 +} {1 {wrong # args: should be "scan string format ?varName varName ...?"}}
1.109 +test scan-4.3 {Tcl_ScanObjCmd, argument checks} {
1.110 + # degenerate case, before changed from 8.2 to 8.3
1.111 + list [catch {scan string format} msg] $msg
1.112 +} {0 {}}
1.113 +test scan-4.4 {Tcl_ScanObjCmd, whitespace} {
1.114 + list [scan { abc def } {%s%s} x y] $x $y
1.115 +} {2 abc def}
1.116 +test scan-4.5 {Tcl_ScanObjCmd, whitespace} {
1.117 + list [scan { abc def } { %s %s } x y] $x $y
1.118 +} {2 abc def}
1.119 +test scan-4.6 {Tcl_ScanObjCmd, whitespace} {
1.120 + list [scan { abc def } { %s %s } x y] $x $y
1.121 +} {2 abc def}
1.122 +test scan-4.7 {Tcl_ScanObjCmd, literals} {
1.123 + # degenerate case, before changed from 8.2 to 8.3
1.124 + scan { abc def } { abc def }
1.125 +} {}
1.126 +test scan-4.8 {Tcl_ScanObjCmd, literals} {
1.127 + set x {}
1.128 + list [scan { abcg} { abc def %1s} x] $x
1.129 +} {0 {}}
1.130 +test scan-4.9 {Tcl_ScanObjCmd, literals} {
1.131 + list [scan { abc%defghi} { abc %% def%n } x] $x
1.132 +} {1 10}
1.133 +test scan-4.10 {Tcl_ScanObjCmd, assignment suppression} {
1.134 + list [scan { abc def } { %*c%s def } x] $x
1.135 +} {1 bc}
1.136 +test scan-4.11 {Tcl_ScanObjCmd, XPG3-style} {
1.137 + list [scan { abc def } {%2$s %1$s} x y] $x $y
1.138 +} {2 def abc}
1.139 +test scan-4.12 {Tcl_ScanObjCmd, width specifiers} {
1.140 + list [scan {abc123456789012} {%3s%3d%3f%3[0-9]%s} a b c d e] $a $b $c $d $e
1.141 +} {5 abc 123 456.0 789 012}
1.142 +test scan-4.13 {Tcl_ScanObjCmd, width specifiers} {
1.143 + list [scan {abc123456789012} {%3s%3d%3f%3[0-9]%s} a b c d e] $a $b $c $d $e
1.144 +} {5 abc 123 456.0 789 012}
1.145 +test scan-4.14 {Tcl_ScanObjCmd, underflow} {
1.146 + set x {}
1.147 + list [scan {a} {a%d} x] $x
1.148 +} {-1 {}}
1.149 +test scan-4.15 {Tcl_ScanObjCmd, underflow} {
1.150 + set x {}
1.151 + list [scan {} {a%d} x] $x
1.152 +} {-1 {}}
1.153 +test scan-4.16 {Tcl_ScanObjCmd, underflow} {
1.154 + set x {}
1.155 + list [scan {ab} {a%d} x] $x
1.156 +} {0 {}}
1.157 +test scan-4.17 {Tcl_ScanObjCmd, underflow} {
1.158 + set x {}
1.159 + list [scan {a } {a%d} x] $x
1.160 +} {-1 {}}
1.161 +test scan-4.18 {Tcl_ScanObjCmd, skipping whitespace} {
1.162 + list [scan { b} {%c%s} x y] $x $y
1.163 +} {2 32 b}
1.164 +test scan-4.19 {Tcl_ScanObjCmd, skipping whitespace} {
1.165 + list [scan { b} {%[^b]%s} x y] $x $y
1.166 +} {2 { } b}
1.167 +test scan-4.20 {Tcl_ScanObjCmd, string scanning} {
1.168 + list [scan {abc def} {%s} x] $x
1.169 +} {1 abc}
1.170 +test scan-4.21 {Tcl_ScanObjCmd, string scanning} {
1.171 + list [scan {abc def} {%0s} x] $x
1.172 +} {1 abc}
1.173 +test scan-4.22 {Tcl_ScanObjCmd, string scanning} {
1.174 + list [scan {abc def} {%2s} x] $x
1.175 +} {1 ab}
1.176 +test scan-4.23 {Tcl_ScanObjCmd, string scanning} {
1.177 + list [scan {abc def} {%*s%n} x] $x
1.178 +} {1 3}
1.179 +test scan-4.24 {Tcl_ScanObjCmd, charset scanning} {
1.180 + list [scan {abcdef} {%[a-c]} x] $x
1.181 +} {1 abc}
1.182 +test scan-4.25 {Tcl_ScanObjCmd, charset scanning} {
1.183 + list [scan {abcdef} {%0[a-c]} x] $x
1.184 +} {1 abc}
1.185 +test scan-4.26 {Tcl_ScanObjCmd, charset scanning} {
1.186 + list [scan {abcdef} {%2[a-c]} x] $x
1.187 +} {1 ab}
1.188 +test scan-4.27 {Tcl_ScanObjCmd, charset scanning} {
1.189 + list [scan {abcdef} {%*[a-c]%n} x] $x
1.190 +} {1 3}
1.191 +test scan-4.28 {Tcl_ScanObjCmd, character scanning} {
1.192 + list [scan {abcdef} {%c} x] $x
1.193 +} {1 97}
1.194 +test scan-4.29 {Tcl_ScanObjCmd, character scanning} {
1.195 + list [scan {abcdef} {%*c%n} x] $x
1.196 +} {1 1}
1.197 +
1.198 +test scan-4.30 {Tcl_ScanObjCmd, base-10 integer scanning} {
1.199 + set x {}
1.200 + list [scan {1234567890a} {%3d} x] $x
1.201 +} {1 123}
1.202 +test scan-4.31 {Tcl_ScanObjCmd, base-10 integer scanning} {
1.203 + set x {}
1.204 + list [scan {1234567890a} {%d} x] $x
1.205 +} {1 1234567890}
1.206 +test scan-4.32 {Tcl_ScanObjCmd, base-10 integer scanning} {
1.207 + set x {}
1.208 + list [scan {01234567890a} {%d} x] $x
1.209 +} {1 1234567890}
1.210 +test scan-4.33 {Tcl_ScanObjCmd, base-10 integer scanning} {
1.211 + set x {}
1.212 + list [scan {+01234} {%d} x] $x
1.213 +} {1 1234}
1.214 +test scan-4.34 {Tcl_ScanObjCmd, base-10 integer scanning} {
1.215 + set x {}
1.216 + list [scan {-01234} {%d} x] $x
1.217 +} {1 -1234}
1.218 +test scan-4.35 {Tcl_ScanObjCmd, base-10 integer scanning} {
1.219 + set x {}
1.220 + list [scan {a01234} {%d} x] $x
1.221 +} {0 {}}
1.222 +test scan-4.36 {Tcl_ScanObjCmd, base-10 integer scanning} {
1.223 + set x {}
1.224 + list [scan {0x10} {%d} x] $x
1.225 +} {1 0}
1.226 +test scan-4.37 {Tcl_ScanObjCmd, base-8 integer scanning} {
1.227 + set x {}
1.228 + list [scan {012345678} {%o} x] $x
1.229 +} {1 342391}
1.230 +test scan-4.38 {Tcl_ScanObjCmd, base-8 integer scanning} {
1.231 + set x {}
1.232 + list [scan {+1238 -1239 123a} {%o%*s%o%*s%o} x y z] $x $y $z
1.233 +} {3 83 -83 83}
1.234 +test scan-4.39 {Tcl_ScanObjCmd, base-16 integer scanning} {
1.235 + set x {}
1.236 + list [scan {+1238 -123a 0123} {%x%x%x} x y z] $x $y $z
1.237 +} {3 4664 -4666 291}
1.238 +test scan-4.40 {Tcl_ScanObjCmd, base-16 integer scanning} {
1.239 + # The behavior changed in 8.4a4/8.3.4cvs (6 Feb) to correctly
1.240 + # return '1' for 0x1 scanned via %x, to comply with 8.0 and C scanf.
1.241 + # Bug #495213
1.242 + set x {}
1.243 + list [scan {aBcDeF AbCdEf 0x1} {%x%x%x} x y z] $x $y $z
1.244 +} {3 11259375 11259375 1}
1.245 +test scan-4.40.1 {Tcl_ScanObjCmd, base-16 integer scanning} {
1.246 + set x {}
1.247 + list [scan {0xF 0x00A0B 0X0XF} {%x %x %x} x y z] $x $y $z
1.248 +} {3 15 2571 0}
1.249 +test scan-4.40.2 {Tcl_ScanObjCmd, base-16 integer scanning} {
1.250 + catch {unset x}
1.251 + list [scan {xF} {%x} x] [info exists x]
1.252 +} {0 0}
1.253 +test scan-4.41 {Tcl_ScanObjCmd, base-unknown integer scanning} {
1.254 + set x {}
1.255 + list [scan {10 010 0x10} {%i%i%i} x y z] $x $y $z
1.256 +} {3 10 8 16}
1.257 +test scan-4.42 {Tcl_ScanObjCmd, base-unknown integer scanning} {
1.258 + set x {}
1.259 + list [scan {10 010 0X10} {%i%i%i} x y z] $x $y $z
1.260 +} {3 10 8 16}
1.261 +test scan-4.43 {Tcl_ScanObjCmd, integer scanning, odd cases} {
1.262 + set x {}
1.263 + list [scan {+ } {%i} x] $x
1.264 +} {0 {}}
1.265 +test scan-4.44 {Tcl_ScanObjCmd, integer scanning, odd cases} {
1.266 + set x {}
1.267 + list [scan {+} {%i} x] $x
1.268 +} {-1 {}}
1.269 +test scan-4.45 {Tcl_ScanObjCmd, integer scanning, odd cases} {
1.270 + set x {}
1.271 + list [scan {0x} {%i%s} x y] $x $y
1.272 +} {2 0 x}
1.273 +test scan-4.46 {Tcl_ScanObjCmd, integer scanning, odd cases} {
1.274 + set x {}
1.275 + list [scan {0X} {%i%s} x y] $x $y
1.276 +} {2 0 X}
1.277 +test scan-4.47 {Tcl_ScanObjCmd, integer scanning, suppressed} {
1.278 + set x {}
1.279 + list [scan {123def} {%*i%s} x] $x
1.280 +} {1 def}
1.281 +test scan-4.48 {Tcl_ScanObjCmd, float scanning} {
1.282 + list [scan {1 2 3} {%e %f %g} x y z] $x $y $z
1.283 +} {3 1.0 2.0 3.0}
1.284 +test scan-4.49 {Tcl_ScanObjCmd, float scanning} {
1.285 + list [scan {.1 0.2 3.} {%e %f %g} x y z] $x $y $z
1.286 +} {3 0.1 0.2 3.0}
1.287 +test scan-4.50 {Tcl_ScanObjCmd, float scanning} {
1.288 + list [scan {1234567890a} %f x] $x
1.289 +} {1 1234567890.0}
1.290 +test scan-4.51 {Tcl_ScanObjCmd, float scanning} {
1.291 + list [scan {+123+45} %f x] $x
1.292 +} {1 123.0}
1.293 +test scan-4.52 {Tcl_ScanObjCmd, float scanning} {
1.294 + list [scan {-123+45} %f x] $x
1.295 +} {1 -123.0}
1.296 +test scan-4.53 {Tcl_ScanObjCmd, float scanning} {
1.297 + list [scan {1.0e1} %f x] $x
1.298 +} {1 10.0}
1.299 +test scan-4.54 {Tcl_ScanObjCmd, float scanning} {
1.300 + list [scan {1.0e-1} %f x] $x
1.301 +} {1 0.1}
1.302 +test scan-4.55 {Tcl_ScanObjCmd, odd cases} {
1.303 + set x {}
1.304 + list [scan {+} %f x] $x
1.305 +} {-1 {}}
1.306 +test scan-4.56 {Tcl_ScanObjCmd, odd cases} {
1.307 + set x {}
1.308 + list [scan {1.0e} %f%s x y] $x $y
1.309 +} {2 1.0 e}
1.310 +test scan-4.57 {Tcl_ScanObjCmd, odd cases} {
1.311 + set x {}
1.312 + list [scan {1.0e+} %f%s x y] $x $y
1.313 +} {2 1.0 e+}
1.314 +test scan-4.58 {Tcl_ScanObjCmd, odd cases} {
1.315 + set x {}
1.316 + set y {}
1.317 + list [scan {e1} %f%s x y] $x $y
1.318 +} {0 {} {}}
1.319 +test scan-4.59 {Tcl_ScanObjCmd, float scanning} {
1.320 + list [scan {1.0e-1x} %*f%n x] $x
1.321 +} {1 6}
1.322 +
1.323 +test scan-4.60 {Tcl_ScanObjCmd, set errors} {
1.324 + set x {}
1.325 + set y {}
1.326 + catch {unset z}; array set z {}
1.327 + set result [list [catch {scan {abc def ghi} {%s%s%s} x z y} msg] \
1.328 + $msg $x $y]
1.329 + unset z
1.330 + set result
1.331 +} {1 {couldn't set variable "z"} abc ghi}
1.332 +test scan-4.61 {Tcl_ScanObjCmd, set errors} {
1.333 + set x {}
1.334 + catch {unset y}; array set y {}
1.335 + catch {unset z}; array set z {}
1.336 + set result [list [catch {scan {abc def ghi} {%s%s%s} x z y} msg] \
1.337 + $msg $x]
1.338 + unset y
1.339 + unset z
1.340 + set result
1.341 +} {1 {couldn't set variable "z"couldn't set variable "y"} abc}
1.342 +
1.343 +# procedure that returns the range of integers
1.344 +
1.345 +proc int_range {} {
1.346 + for { set MIN_INT 1 } { $MIN_INT > 0 } {} {
1.347 + set MIN_INT [expr { $MIN_INT << 1 }]
1.348 + }
1.349 + set MAX_INT [expr { ~ $MIN_INT }]
1.350 + return [list $MIN_INT $MAX_INT]
1.351 +}
1.352 +
1.353 +test scan-4.62 {scanning of large and negative octal integers} {
1.354 + foreach { MIN_INT MAX_INT } [int_range] {}
1.355 + set scanstring [format {%o %o %o} -1 $MIN_INT $MAX_INT]
1.356 + list [scan $scanstring {%o %o %o} a b c] \
1.357 + [expr { $a == -1 }] [expr { $b == $MIN_INT }] [expr { $c == $MAX_INT }]
1.358 +} {3 1 1 1}
1.359 +test scan-4.63 {scanning of large and negative hex integers} {
1.360 + foreach { MIN_INT MAX_INT } [int_range] {}
1.361 + set scanstring [format {%x %x %x} -1 $MIN_INT $MAX_INT]
1.362 + list [scan $scanstring {%x %x %x} a b c] \
1.363 + [expr { $a == -1 }] [expr { $b == $MIN_INT }] [expr { $c == $MAX_INT }]
1.364 +} {3 1 1 1}
1.365 +
1.366 +# clean up from last two tests
1.367 +
1.368 +catch {
1.369 + rename int_range {}
1.370 +}
1.371 +
1.372 +test scan-5.1 {integer scanning} {
1.373 + set a {}; set b {}; set c {}; set d {}
1.374 + list [scan "-20 1476 \n33 0" "%d %d %d %d" a b c d] $a $b $c $d
1.375 +} {4 -20 1476 33 0}
1.376 +test scan-5.2 {integer scanning} {
1.377 + set a {}; set b {}; set c {}
1.378 + list [scan "-45 16 7890 +10" "%2d %*d %10d %d" a b c] $a $b $c
1.379 +} {3 -4 16 7890}
1.380 +test scan-5.3 {integer scanning} {
1.381 + set a {}; set b {}; set c {}; set d {}
1.382 + list [scan "-45 16 +10 987" "%ld %d %ld %d" a b c d] $a $b $c $d
1.383 +} {4 -45 16 10 987}
1.384 +test scan-5.4 {integer scanning} {
1.385 + set a {}; set b {}; set c {}; set d {}
1.386 + list [scan "14 1ab 62 10" "%d %x %lo %x" a b c d] $a $b $c $d
1.387 +} {4 14 427 50 16}
1.388 +test scan-5.5 {integer scanning} {
1.389 + set a {}; set b {}; set c {}; set d {}
1.390 + list [scan "12345670 1234567890ab cdefg" "%o %o %x %lx" a b c d] \
1.391 + $a $b $c $d
1.392 +} {4 2739128 342391 561323 52719}
1.393 +test scan-5.6 {integer scanning} {
1.394 + set a {}; set b {}; set c {}; set d {}
1.395 + list [scan "ab123-24642" "%2x %3x %3o %2o" a b c d] $a $b $c $d
1.396 +} {4 171 291 -20 52}
1.397 +test scan-5.7 {integer scanning} {
1.398 + set a {}; set b {}
1.399 + list [scan "1234567 234 567 " "%*3x %x %*o %4o" a b] $a $b
1.400 +} {2 17767 375}
1.401 +test scan-5.8 {integer scanning} {
1.402 + set a {}; set b {}
1.403 + list [scan "a 1234" "%d %d" a b] $a $b
1.404 +} {0 {} {}}
1.405 +test scan-5.9 {integer scanning} {
1.406 + set a {}; set b {}; set c {}; set d {};
1.407 + list [scan "12345678" "%2d %2d %2ld %2d" a b c d] $a $b $c $d
1.408 +} {4 12 34 56 78}
1.409 +test scan-5.10 {integer scanning} {
1.410 + set a {}; set b {}; set c {}; set d {}
1.411 + list [scan "1 2 " "%hd %d %d %d" a b c d] $a $b $c $d
1.412 +} {2 1 2 {} {}}
1.413 +#
1.414 +# The behavior for scaning intergers larger than MAX_INT is
1.415 +# not defined by the ANSI spec. Some implementations wrap the
1.416 +# input (-16) some return MAX_INT.
1.417 +#
1.418 +test scan-5.11 {integer scanning} {nonPortable} {
1.419 + set a {}; set b {};
1.420 + list [scan "4294967280 4294967280" "%u %d" a b] $a \
1.421 + [expr {$b == -16 || $b == 0x7fffffff}]
1.422 +} {2 4294967280 1}
1.423 +test scan-5.12 {integer scanning} {64bitInts} {
1.424 + set a {}; set b {}; set c {}
1.425 + list [scan "7810179016327718216,6c63546f6c6c6548,661432506755433062510" \
1.426 + %ld,%lx,%lo a b c] $a $b $c
1.427 +} {3 7810179016327718216 7810179016327718216 7810179016327718216}
1.428 +test scan-5.13 {integer scanning and overflow} {
1.429 + # This test used to fail on some 64-bit systems. [Bug 1011860]
1.430 + scan {300000000 3000000000 30000000000} {%ld %ld %ld}
1.431 +} {300000000 3000000000 30000000000}
1.432 +
1.433 +test scan-6.1 {floating-point scanning} {
1.434 + set a {}; set b {}; set c {}; set d {}
1.435 + list [scan "2.1 -3.0e8 .99962 a" "%f%g%e%f" a b c d] $a $b $c $d
1.436 +} {3 2.1 -300000000.0 0.99962 {}}
1.437 +test scan-6.2 {floating-point scanning} {
1.438 + set a {}; set b {}; set c {}; set d {}
1.439 + list [scan "-1.2345 +8.2 9" "%3e %3lf %f %f" a b c d] $a $b $c $d
1.440 +} {4 -1.0 234.0 5.0 8.2}
1.441 +test scan-6.3 {floating-point scanning} {
1.442 + set a {}; set b {}; set c {}
1.443 + list [scan "1e00004 332E-4 3e+4" "%Lf %*2e %f %f" a b c] $a $c
1.444 +} {3 10000.0 30000.0}
1.445 +#
1.446 +# Some libc implementations consider 3.e- bad input. The ANSI
1.447 +# spec states that digits must follow the - sign.
1.448 +#
1.449 +test scan-6.4 {floating-point scanning} {
1.450 + set a {}; set b {}; set c {}
1.451 + list [scan "1. 47.6 2.e2 3.e-" "%f %*f %f %f" a b c] $a $b $c
1.452 +} {3 1.0 200.0 3.0}
1.453 +test scan-6.5 {floating-point scanning} {
1.454 + set a {}; set b {}; set c {}; set d {}
1.455 + list [scan "4.6 99999.7 876.43e-1 118" "%f %f %f %e" a b c d] $a $b $c $d
1.456 +} {4 4.6 99999.7 87.643 118.0}
1.457 +test scan-6.6 {floating-point scanning} {eformat} {
1.458 + set a {}; set b {}; set c {}; set d {}
1.459 + list [scan "1.2345 697.0e-3 124 .00005" "%f %e %f %e" a b c d] $a $b $c $d
1.460 +} {4 1.2345 0.697 124.0 5e-05}
1.461 +test scan-6.7 {floating-point scanning} {
1.462 + set a {}; set b {}; set c {}; set d {}
1.463 + list [scan "4.6abc" "%f %f %f %f" a b c d] $a $b $c $d
1.464 +} {1 4.6 {} {} {}}
1.465 +test scan-6.8 {floating-point scanning} {
1.466 + set a {}; set b {}; set c {}; set d {}
1.467 + list [scan "4.6 5.2" "%f %f %f %f" a b c d] $a $b $c $d
1.468 +} {2 4.6 5.2 {} {}}
1.469 +
1.470 +test scan-7.1 {string and character scanning} {
1.471 + set a {}; set b {}; set c {}; set d {}
1.472 + list [scan "abc defghijk dum " "%s %3s %20s %s" a b c d] $a $b $c $d
1.473 +} {4 abc def ghijk dum}
1.474 +test scan-7.2 {string and character scanning} {
1.475 + set a {}; set b {}; set c {}; set d {}
1.476 + list [scan "a bcdef" "%c%c%1s %s" a b c d] $a $b $c $d
1.477 +} {4 97 32 b cdef}
1.478 +test scan-7.3 {string and character scanning} {
1.479 + set a {}; set b {}; set c {}
1.480 + list [scan "123456 test " "%*c%*s %s %s %s" a b c] $a $b $c
1.481 +} {1 test {} {}}
1.482 +test scan-7.4 {string and character scanning} {
1.483 + set a {}; set b {}; set c {}; set d
1.484 + list [scan "ababcd01234 f 123450" {%4[abcd] %4[abcd] %[^abcdef] %[^0]} a b c d] $a $b $c $d
1.485 +} {4 abab cd {01234 } {f 12345}}
1.486 +test scan-7.5 {string and character scanning} {
1.487 + set a {}; set b {}; set c {}
1.488 + list [scan "aaaaaabc aaabcdefg + + XYZQR" {%*4[a] %s %*4[a]%s%*4[ +]%c} a b c] $a $b $c
1.489 +} {3 aabc bcdefg 43}
1.490 +test scan-7.6 {string and character scanning, unicode} {
1.491 + set a {}; set b {}; set c {}; set d {}
1.492 + list [scan "abc d\u00c7fghijk dum " "%s %3s %20s %s" a b c d] $a $b $c $d
1.493 +} "4 abc d\u00c7f ghijk dum"
1.494 +test scan-7.7 {string and character scanning, unicode} {
1.495 + set a {}; set b {}
1.496 + list [scan "ab\u00c7cdef" "ab%c%c" a b] $a $b
1.497 +} "2 199 99"
1.498 +test scan-7.8 {string and character scanning, unicode} {
1.499 + set a {}; set b {}
1.500 + list [scan "ab\ufeffdef" "%\[ab\ufeff\]" a] $a
1.501 +} "1 ab\ufeff"
1.502 +
1.503 +test scan-8.1 {error conditions} {
1.504 + catch {scan a}
1.505 +} 1
1.506 +test scan-8.2 {error conditions} {
1.507 + catch {scan a} msg
1.508 + set msg
1.509 +} {wrong # args: should be "scan string format ?varName varName ...?"}
1.510 +test scan-8.3 {error conditions} {
1.511 + list [catch {scan a %D x} msg] $msg
1.512 +} {1 {bad scan conversion character "D"}}
1.513 +test scan-8.4 {error conditions} {
1.514 + list [catch {scan a %O x} msg] $msg
1.515 +} {1 {bad scan conversion character "O"}}
1.516 +test scan-8.5 {error conditions} {
1.517 + list [catch {scan a %X x} msg] $msg
1.518 +} {1 {bad scan conversion character "X"}}
1.519 +test scan-8.6 {error conditions} {
1.520 + list [catch {scan a %F x} msg] $msg
1.521 +} {1 {bad scan conversion character "F"}}
1.522 +test scan-8.7 {error conditions} {
1.523 + list [catch {scan a %E x} msg] $msg
1.524 +} {1 {bad scan conversion character "E"}}
1.525 +test scan-8.8 {error conditions} {
1.526 + list [catch {scan a "%d %d" a} msg] $msg
1.527 +} {1 {different numbers of variable names and field specifiers}}
1.528 +test scan-8.9 {error conditions} {
1.529 + list [catch {scan a "%d %d" a b c} msg] $msg
1.530 +} {1 {variable is not assigned by any conversion specifiers}}
1.531 +test scan-8.10 {error conditions} {
1.532 + set a {}; set b {}; set c {}; set d {}
1.533 + list [expr {[scan " a" " a %d %d %d %d" a b c d] <= 0}] $a $b $c $d
1.534 +} {1 {} {} {} {}}
1.535 +test scan-8.11 {error conditions} {
1.536 + set a {}; set b {}; set c {}; set d {}
1.537 + list [scan "1 2" "%d %d %d %d" a b c d] $a $b $c $d
1.538 +} {2 1 2 {} {}}
1.539 +test scan-8.12 {error conditions} {
1.540 + catch {unset a}
1.541 + set a(0) 44
1.542 + list [catch {scan 44 %d a} msg] $msg
1.543 +} {1 {couldn't set variable "a"}}
1.544 +test scan-8.13 {error conditions} {
1.545 + catch {unset a}
1.546 + set a(0) 44
1.547 + list [catch {scan 44 %c a} msg] $msg
1.548 +} {1 {couldn't set variable "a"}}
1.549 +test scan-8.14 {error conditions} {
1.550 + catch {unset a}
1.551 + set a(0) 44
1.552 + list [catch {scan 44 %s a} msg] $msg
1.553 +} {1 {couldn't set variable "a"}}
1.554 +test scan-8.15 {error conditions} {
1.555 + catch {unset a}
1.556 + set a(0) 44
1.557 + list [catch {scan 44 %f a} msg] $msg
1.558 +} {1 {couldn't set variable "a"}}
1.559 +test scan-8.16 {error conditions} {
1.560 + catch {unset a}
1.561 + set a(0) 44
1.562 + list [catch {scan 44 %f a} msg] $msg
1.563 +} {1 {couldn't set variable "a"}}
1.564 +catch {unset a}
1.565 +test scan-8.17 {error conditions} {
1.566 + list [catch {scan 44 %2c a} msg] $msg
1.567 +} {1 {field width may not be specified in %c conversion}}
1.568 +test scan-8.18 {error conditions} {
1.569 + list [catch {scan abc {%[} x} msg] $msg
1.570 +} {1 {unmatched [ in format string}}
1.571 +test scan-8.19 {error conditions} {
1.572 + list [catch {scan abc {%[^a} x} msg] $msg
1.573 +} {1 {unmatched [ in format string}}
1.574 +test scan-8.20 {error conditions} {
1.575 + list [catch {scan abc {%[^]a} x} msg] $msg
1.576 +} {1 {unmatched [ in format string}}
1.577 +test scan-8.21 {error conditions} {
1.578 + list [catch {scan abc {%[]a} x} msg] $msg
1.579 +} {1 {unmatched [ in format string}}
1.580 +
1.581 +test scan-9.1 {lots of arguments} {
1.582 + 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
1.583 +} 20
1.584 +test scan-9.2 {lots of arguments} {
1.585 + 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
1.586 + set a20
1.587 +} 200
1.588 +
1.589 +test scan-10.1 {miscellaneous tests} {
1.590 + set a {}
1.591 + list [scan ab16c ab%dc a] $a
1.592 +} {1 16}
1.593 +test scan-10.2 {miscellaneous tests} {
1.594 + set a {}
1.595 + list [scan ax16c ab%dc a] $a
1.596 +} {0 {}}
1.597 +test scan-10.3 {miscellaneous tests} {
1.598 + set a {}
1.599 + list [catch {scan ab%c114 ab%%c%d a} msg] $msg $a
1.600 +} {0 1 114}
1.601 +test scan-10.4 {miscellaneous tests} {
1.602 + set a {}
1.603 + list [catch {scan ab%c14 ab%%c%d a} msg] $msg $a
1.604 +} {0 1 14}
1.605 +test scan-10.5 {miscellaneous tests} {
1.606 + catch {unset arr}
1.607 + set arr(2) {}
1.608 + list [catch {scan ab%c14 ab%%c%d arr(2)} msg] $msg $arr(2)
1.609 +} {0 1 14}
1.610 +
1.611 +test scan-11.1 {alignment in results array (TCL_ALIGN)} {
1.612 + scan "123 13.6" "%s %f" a b
1.613 + set b
1.614 +} 13.6
1.615 +test scan-11.2 {alignment in results array (TCL_ALIGN)} {
1.616 + scan "1234567 13.6" "%s %f" a b
1.617 + set b
1.618 +} 13.6
1.619 +test scan-11.3 {alignment in results array (TCL_ALIGN)} {
1.620 + scan "12345678901 13.6" "%s %f" a b
1.621 + set b
1.622 +} 13.6
1.623 +test scan-11.4 {alignment in results array (TCL_ALIGN)} {
1.624 + scan "123456789012345 13.6" "%s %f" a b
1.625 + set b
1.626 +} 13.6
1.627 +test scan-11.5 {alignment in results array (TCL_ALIGN)} {
1.628 + scan "1234567890123456789 13.6" "%s %f" a b
1.629 + set b
1.630 +} 13.6
1.631 +
1.632 +test scan-12.1 {Tcl_ScanObjCmd, inline case} {
1.633 + scan a %c
1.634 +} 97
1.635 +test scan-12.2 {Tcl_ScanObjCmd, inline case} {
1.636 + scan abc %c%c%c%c
1.637 +} {97 98 99 {}}
1.638 +test scan-12.3 {Tcl_ScanObjCmd, inline case} {
1.639 + scan abc %s%c
1.640 +} {abc {}}
1.641 +test scan-12.4 {Tcl_ScanObjCmd, inline case, underflow} {
1.642 + scan abc abc%c
1.643 +} {}
1.644 +test scan-12.5 {Tcl_ScanObjCmd, inline case} {
1.645 + scan abc bogus%c%c%c
1.646 +} {{} {} {}}
1.647 +test scan-12.6 {Tcl_ScanObjCmd, inline case} {
1.648 + # degenerate case, behavior changed from 8.2 to 8.3
1.649 + list [catch {scan foo foobar} msg] $msg
1.650 +} {0 {}}
1.651 +test scan-12.7 {Tcl_ScanObjCmd, inline case lots of arguments} {
1.652 + scan "10 20 30 40 50 60 70 80 90 100 110 120 130 140\
1.653 + 150 160 170 180 190 200" \
1.654 + "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d"
1.655 +} {10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 {}}
1.656 +
1.657 +test scan-13.1 {Tcl_ScanObjCmd, inline XPG case} {
1.658 + scan a {%1$c}
1.659 +} 97
1.660 +test scan-13.2 {Tcl_ScanObjCmd, inline XPG case} {
1.661 + scan abc {%1$c%2$c%3$c%4$c}
1.662 +} {97 98 99 {}}
1.663 +test scan-13.3 {Tcl_ScanObjCmd, inline XPG case} {
1.664 + list [catch {scan abc {%1$c%1$c}} msg] $msg
1.665 +} {1 {variable is assigned by multiple "%n$" conversion specifiers}}
1.666 +test scan-13.4 {Tcl_ScanObjCmd, inline XPG case} {
1.667 + scan abc {%2$s%1$c}
1.668 +} {{} abc}
1.669 +test scan-13.5 {Tcl_ScanObjCmd, inline XPG case, underflow} {
1.670 + scan abc {abc%5$c}
1.671 +} {}
1.672 +test scan-13.6 {Tcl_ScanObjCmd, inline XPG case} {
1.673 + catch {scan abc {bogus%1$c%5$c%10$c}} msg
1.674 + list [llength $msg] $msg
1.675 +} {10 {{} {} {} {} {} {} {} {} {} {}}}
1.676 +test scan-13.7 {Tcl_ScanObjCmd, inline XPG case lots of arguments} {
1.677 + 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}
1.678 +} {190 180 170 160 150 140 130 120 110 100 90 80 70 60 50 40 30 20 {} 10}
1.679 +test scan-13.8 {Tcl_ScanObjCmd, inline XPG case lots of arguments} {
1.680 + set msg [scan "10 20 30" {%100$d %5$d %200$d}]
1.681 + list [llength $msg] [lindex $msg 99] [lindex $msg 4] [lindex $msg 199]
1.682 +} {200 10 20 30}
1.683 +
1.684 +# cleanup
1.685 +::tcltest::cleanupTests
1.686 +return