os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/lsearch.test
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/lsearch.test	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,380 @@
     1.4 +# Commands covered:  lsearch
     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-1993 The Regents of the University of California.
    1.11 +# Copyright (c) 1994 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: lsearch.test,v 1.10.2.3 2005/12/09 14:39:25 dkf Exp $
    1.18 +
    1.19 +if {[lsearch [namespace children] ::tcltest] == -1} {
    1.20 +    package require tcltest
    1.21 +    namespace import -force ::tcltest::*
    1.22 +}
    1.23 +
    1.24 +set x {abcd bbcd 123 234 345}
    1.25 +test lsearch-1.1 {lsearch command} {
    1.26 +    lsearch $x 123
    1.27 +} 2
    1.28 +test lsearch-1.2 {lsearch command} {
    1.29 +    lsearch $x 3456
    1.30 +} -1
    1.31 +test lsearch-1.3 {lsearch command} {
    1.32 +    lsearch $x *5
    1.33 +} 4
    1.34 +test lsearch-1.4 {lsearch command} {
    1.35 +    lsearch $x *bc*
    1.36 +} 0
    1.37 +
    1.38 +test lsearch-2.1 {search modes} {
    1.39 +    lsearch -exact {xyz bbcc *bc*} *bc*
    1.40 +} 2
    1.41 +test lsearch-2.2 {search modes} {
    1.42 +    lsearch -exact {b.x ^bc xy bcx} ^bc
    1.43 +} 1
    1.44 +test lsearch-2.3 {search modes} {
    1.45 +    lsearch -exact {foo bar cat} ba
    1.46 +} -1
    1.47 +test lsearch-2.4 {search modes} {
    1.48 +    lsearch -exact {foo bar cat} bart
    1.49 +} -1
    1.50 +test lsearch-2.5 {search modes} {
    1.51 +    lsearch -exact {foo bar cat} bar
    1.52 +} 1
    1.53 +test lsearch-2.6 {search modes} {
    1.54 +    list [catch {lsearch -regexp {xyz bbcc *bc*} *bc*} msg] $msg
    1.55 +} {1 {couldn't compile regular expression pattern: quantifier operand invalid}}
    1.56 +test lsearch-2.7 {search modes} {
    1.57 +    lsearch -regexp {b.x ^bc xy bcx} ^bc
    1.58 +} 3
    1.59 +test lsearch-2.8 {search modes} {
    1.60 +    lsearch -glob {xyz bbcc *bc*} *bc*
    1.61 +} 1
    1.62 +test lsearch-2.9 {search modes} {
    1.63 +    lsearch -glob {b.x ^bc xy bcx} ^bc
    1.64 +} 1
    1.65 +test lsearch-2.10 {search modes} {
    1.66 +    list [catch {lsearch -glib {b.x bx xy bcx} b.x} msg] $msg
    1.67 +} {1 {bad option "-glib": must be -all, -ascii, -decreasing, -dictionary, -exact, -glob, -increasing, -inline, -integer, -not, -real, -regexp, -sorted, or -start}}
    1.68 +
    1.69 +test lsearch-3.1 {lsearch errors} {
    1.70 +    list [catch lsearch msg] $msg
    1.71 +} {1 {wrong # args: should be "lsearch ?options? list pattern"}}
    1.72 +test lsearch-3.2 {lsearch errors} {
    1.73 +    list [catch {lsearch a} msg] $msg
    1.74 +} {1 {wrong # args: should be "lsearch ?options? list pattern"}}
    1.75 +test lsearch-3.3 {lsearch errors} {
    1.76 +    list [catch {lsearch a b c} msg] $msg
    1.77 +} {1 {bad option "a": must be -all, -ascii, -decreasing, -dictionary, -exact, -glob, -increasing, -inline, -integer, -not, -real, -regexp, -sorted, or -start}}
    1.78 +test lsearch-3.4 {lsearch errors} {
    1.79 +    list [catch {lsearch a b c d} msg] $msg
    1.80 +} {1 {bad option "a": must be -all, -ascii, -decreasing, -dictionary, -exact, -glob, -increasing, -inline, -integer, -not, -real, -regexp, -sorted, or -start}}
    1.81 +test lsearch-3.5 {lsearch errors} {
    1.82 +    list [catch {lsearch "\{" b} msg] $msg
    1.83 +} {1 {unmatched open brace in list}}
    1.84 +
    1.85 +test lsearch-4.1 {binary data} {
    1.86 +    lsearch -exact [list foo one\000two bar] bar
    1.87 +} 2
    1.88 +test lsearch-4.2 {binary data} {
    1.89 +    set x one
    1.90 +    append x \x00
    1.91 +    append x two
    1.92 +    lsearch -exact [list foo one\000two bar] $x
    1.93 +} 1
    1.94 +
    1.95 +# Make a sorted list
    1.96 +set l {}
    1.97 +set l2 {}
    1.98 +for {set i 0} {$i < 100} {incr i} {
    1.99 +    lappend l $i
   1.100 +    lappend l2 [expr {double($i)/2}]
   1.101 +}
   1.102 +set increasingIntegers [lsort -integer $l]
   1.103 +set decreasingIntegers [lsort -decreasing -integer $l]
   1.104 +set increasingDoubles [lsort -real $l2]
   1.105 +set decreasingDoubles [lsort -decreasing -real $l2]
   1.106 +set increasingStrings [lsort {48 6a 18b 22a 21aa 35 36}]
   1.107 +set decreasingStrings [lsort -decreasing {48 6a 18b 22a 21aa 35 36}]
   1.108 +set increasingDictionary [lsort -dictionary {48 6a 18b 22a 21aa 35 36}]
   1.109 +set decreasingDictionary [lsort -dictionary -decreasing $increasingDictionary]
   1.110 +
   1.111 +set l {}
   1.112 +for {set i 0} {$i < 10} {incr i} {
   1.113 +    lappend l $i $i $i $i $i
   1.114 +}
   1.115 +set repeatingIncreasingIntegers [lsort -integer $l]
   1.116 +set repeatingDecreasingIntegers [lsort -integer -decreasing $l]
   1.117 +
   1.118 +test lsearch-5.1 {binary search} {
   1.119 +    set res {}
   1.120 +    for {set i 0} {$i < 100} {incr i} {
   1.121 +	lappend res [lsearch -integer -sorted $increasingIntegers $i]
   1.122 +    }
   1.123 +    set res
   1.124 +} $increasingIntegers
   1.125 +test lsearch-5.2 {binary search} {
   1.126 +    set res {}
   1.127 +    for {set i 0} {$i < 100} {incr i} {
   1.128 +	lappend res [lsearch -integer -decreasing -sorted \
   1.129 +		$decreasingIntegers $i]
   1.130 +    }
   1.131 +    set res
   1.132 +} $decreasingIntegers
   1.133 +test lsearch-5.3 {binary search finds leftmost occurances} {
   1.134 +    set res {}
   1.135 +    for {set i 0} {$i < 10} {incr i} {
   1.136 +	lappend res [lsearch -integer -sorted $repeatingIncreasingIntegers $i]
   1.137 +    }
   1.138 +    set res
   1.139 +} [list 0 5 10 15 20 25 30 35 40 45]
   1.140 +test lsearch-5.4 {binary search -decreasing finds leftmost occurances} {
   1.141 +    set res {}
   1.142 +    for {set i 9} {$i >= 0} {incr i -1} {
   1.143 +	lappend res [lsearch -sorted -integer -decreasing \
   1.144 +		$repeatingDecreasingIntegers $i]
   1.145 +    }
   1.146 +    set res
   1.147 +} [list 0 5 10 15 20 25 30 35 40 45]
   1.148 +
   1.149 +test lsearch-6.1 {integer search} {
   1.150 +    set res {}
   1.151 +    for {set i 0} {$i < 100} {incr i} {
   1.152 +	lappend res [lsearch -exact -integer $increasingIntegers $i]
   1.153 +    }
   1.154 +    set res
   1.155 +} [lrange $increasingIntegers 0 99]
   1.156 +test lsearch-6.2 {decreasing integer search} {
   1.157 +    set res {}
   1.158 +    for {set i 0} {$i < 100} {incr i} {
   1.159 +	lappend res [lsearch -exact -integer -decreasing \
   1.160 +		$decreasingIntegers $i]
   1.161 +    }
   1.162 +    set res
   1.163 +} [lrange $decreasingIntegers 0 99]
   1.164 +test lsearch-6.3 {sorted integer search} {
   1.165 +    set res {}
   1.166 +    for {set i 0} {$i < 100} {incr i} {
   1.167 +	lappend res [lsearch -sorted -integer $increasingIntegers $i]
   1.168 +    }
   1.169 +    set res
   1.170 +} [lrange $increasingIntegers 0 99]
   1.171 +test lsearch-6.4 {sorted decreasing integer search} {
   1.172 +    set res {}
   1.173 +    for {set i 0} {$i < 100} {incr i} {
   1.174 +	lappend res [lsearch -integer -sorted -decreasing \
   1.175 +		$decreasingIntegers $i]
   1.176 +    }
   1.177 +    set res
   1.178 +} [lrange $decreasingIntegers 0 99]
   1.179 +
   1.180 +test lsearch-7.1 {double search} {
   1.181 +    set res {}
   1.182 +    for {set i 0} {$i < 100} {incr i} {
   1.183 +	lappend res [lsearch -exact -real $increasingDoubles \
   1.184 +		[expr {double($i)/2}]]
   1.185 +    }
   1.186 +    set res
   1.187 +} [lrange $increasingIntegers 0 99]
   1.188 +test lsearch-7.2 {decreasing double search} {
   1.189 +    set res {}
   1.190 +    for {set i 0} {$i < 100} {incr i} {
   1.191 +	lappend res [lsearch -exact -real -decreasing \
   1.192 +		$decreasingDoubles [expr {double($i)/2}]]
   1.193 +    }
   1.194 +    set res
   1.195 +} [lrange $decreasingIntegers 0 99]
   1.196 +test lsearch-7.3 {sorted double search} {
   1.197 +    set res {}
   1.198 +    for {set i 0} {$i < 100} {incr i} {
   1.199 +	lappend res [lsearch -sorted -real \
   1.200 +		$increasingDoubles [expr {double($i)/2}]]
   1.201 +    }
   1.202 +    set res
   1.203 +} [lrange $increasingIntegers 0 99]
   1.204 +test lsearch-7.4 {sorted decreasing double search} {
   1.205 +    set res {}
   1.206 +    for {set i 0} {$i < 100} {incr i} {
   1.207 +	lappend res [lsearch -sorted -real -decreasing \
   1.208 +		$decreasingDoubles [expr {double($i)/2}]]
   1.209 +    }
   1.210 +    set res
   1.211 +} [lrange $decreasingIntegers 0 99]
   1.212 +
   1.213 +test lsearch-8.1 {dictionary search} {
   1.214 +    set res {}
   1.215 +    foreach val {6a 18b 21aa 22a 35 36 48} {
   1.216 +	lappend res [lsearch -exact -dictionary $increasingDictionary $val]
   1.217 +    }
   1.218 +    set res
   1.219 +} [list 0 1 2 3 4 5 6]
   1.220 +test lsearch-8.2 {decreasing dictionary search} {
   1.221 +    set res {}
   1.222 +    foreach val {6a 18b 21aa 22a 35 36 48} {
   1.223 +	lappend res [lsearch -exact -dictionary $decreasingDictionary $val]
   1.224 +    }
   1.225 +    set res
   1.226 +} [list 6 5 4 3 2 1 0]
   1.227 +test lsearch-8.3 {sorted dictionary search} {
   1.228 +    set res {}
   1.229 +    foreach val {6a 18b 21aa 22a 35 36 48} {
   1.230 +	lappend res [lsearch -sorted -dictionary $increasingDictionary $val]
   1.231 +    }
   1.232 +    set res
   1.233 +} [list 0 1 2 3 4 5 6]
   1.234 +test lsearch-8.4 {decreasing sorted dictionary search} {
   1.235 +    set res {}
   1.236 +    foreach val {6a 18b 21aa 22a 35 36 48} {
   1.237 +	lappend res [lsearch -decreasing -sorted -dictionary \
   1.238 +		$decreasingDictionary $val]
   1.239 +    }
   1.240 +    set res
   1.241 +} [list 6 5 4 3 2 1 0]
   1.242 +
   1.243 +test lsearch-9.1 {ascii search} {
   1.244 +    set res {}
   1.245 +    foreach val {18b 21aa 22a 35 36 48 6a} {
   1.246 +	lappend res [lsearch -exact -ascii $increasingStrings $val]
   1.247 +    }
   1.248 +    set res
   1.249 +} [list 0 1 2 3 4 5 6]
   1.250 +test lsearch-9.2 {decreasing ascii search} {
   1.251 +    set res {}
   1.252 +    foreach val {18b 21aa 22a 35 36 48 6a} {
   1.253 +	lappend res [lsearch -exact -ascii $decreasingStrings $val]
   1.254 +    }
   1.255 +    set res
   1.256 +} [list 6 5 4 3 2 1 0]
   1.257 +test lsearch-9.3 {sorted ascii search} {
   1.258 +    set res {}
   1.259 +    foreach val {18b 21aa 22a 35 36 48 6a} {
   1.260 +	lappend res [lsearch -sorted -ascii $increasingStrings $val]
   1.261 +    }
   1.262 +    set res
   1.263 +} [list 0 1 2 3 4 5 6]
   1.264 +test lsearch-9.4 {decreasing sorted ascii search} {
   1.265 +    set res {}
   1.266 +    foreach val {18b 21aa 22a 35 36 48 6a} {
   1.267 +	lappend res [lsearch -decreasing -sorted -ascii \
   1.268 +		$decreasingStrings $val]
   1.269 +    }
   1.270 +    set res
   1.271 +} [list 6 5 4 3 2 1 0]
   1.272 +
   1.273 +test lsearch-10.1 {offset searching} {
   1.274 +    lsearch -start 2 {a b c a b c} a
   1.275 +} 3
   1.276 +test lsearch-10.2 {offset searching} {
   1.277 +    lsearch -start 2 {a b c d e f} a
   1.278 +} -1
   1.279 +test lsearch-10.3 {offset searching} {
   1.280 +    lsearch -start end-4 {a b c a b c} a
   1.281 +} 3
   1.282 +test lsearch-10.4 {offset searching} {
   1.283 +    list [catch {lsearch -start foobar {a b c a b c} a} msg] $msg
   1.284 +} {1 {bad index "foobar": must be integer or end?-integer?}}
   1.285 +test lsearch-10.5 {offset searching} {
   1.286 +    list [catch {lsearch -start 1 2} msg] $msg
   1.287 +} {1 {missing starting index}}
   1.288 +test lsearch-10.6 {binary search with offset} {
   1.289 +    set res {}
   1.290 +    for {set i 0} {$i < 100} {incr i} {
   1.291 +	lappend res [lsearch -integer -start 2 -sorted $increasingIntegers $i]
   1.292 +    }
   1.293 +    set res
   1.294 +} [concat -1 -1 [lrange $increasingIntegers 2 end]]
   1.295 +test lsearch-10.7 {offset searching with an empty list} {
   1.296 +    # Stop bug #694232 from reocurring
   1.297 +    lsearch -start 0 {} x
   1.298 +} -1
   1.299 +test lsearch-10.8 {offset searching past the end of the list} {
   1.300 +    # Stop [Bug 1374778] from reoccurring
   1.301 +    lsearch -start 10 {a b c} c
   1.302 +} -1
   1.303 +test lsearch-10.9 {offset searching past the end of the list} {
   1.304 +    # Stop [Bug 1374778] from reoccurring
   1.305 +    lsearch -start 10 -all {a b c} c
   1.306 +} {}
   1.307 +test lsearch-10.10 {offset searching past the end of the list} {
   1.308 +    # Stop [Bug 1374778] from reoccurring
   1.309 +    lsearch -start 10 -inline {a b c} c
   1.310 +} {}
   1.311 +
   1.312 +test lsearch-11.1 {negated searches} {
   1.313 +    lsearch -not {a a a b a a a} a
   1.314 +} 3
   1.315 +test lsearch-11.2 {negated searches} {
   1.316 +    lsearch -not {a a a a a a a} a
   1.317 +} -1
   1.318 +
   1.319 +test lsearch-12.1 {return values instead of indices} {
   1.320 +    lsearch -glob -inline {a1 b2 c3 d4} c*
   1.321 +} c3
   1.322 +test lsearch-12.2 {return values instead of indices} {
   1.323 +    lsearch -glob -inline {a1 b2 c3 d4} e*
   1.324 +} {}
   1.325 +
   1.326 +test lsearch-13.1 {search for all matches} {
   1.327 +    lsearch -all {a b a c a d} 1
   1.328 +} {}
   1.329 +test lsearch-13.2 {search for all matches} {
   1.330 +    lsearch -all {a b a c a d} a
   1.331 +} {0 2 4}
   1.332 +
   1.333 +test lsearch-14.1 {combinations: -all and -inline} {
   1.334 +    lsearch -all -inline -glob {a1 b2 a3 c4 a5 d6} a*
   1.335 +} {a1 a3 a5}
   1.336 +test lsearch-14.2 {combinations: -all, -inline and -not} {
   1.337 +    lsearch -all -inline -not -glob {a1 b2 a3 c4 a5 d6} a*
   1.338 +} {b2 c4 d6}
   1.339 +test lsearch-14.3 {combinations: -all and -not} {
   1.340 +    lsearch -all -not -glob {a1 b2 a3 c4 a5 d6} a*
   1.341 +} {1 3 5}
   1.342 +test lsearch-14.4 {combinations: -inline and -not} {
   1.343 +    lsearch -inline -not -glob {a1 b2 a3 c4 a5 d6} a*
   1.344 +} {b2}
   1.345 +test lsearch-14.5 {combinations: -start, -all and -inline} {
   1.346 +    lsearch -start 2 -all -inline -glob {a1 b2 a3 c4 a5 d6} a*
   1.347 +} {a3 a5}
   1.348 +test lsearch-14.6 {combinations: -start, -all, -inline and -not} {
   1.349 +    lsearch -start 2 -all -inline -not -glob {a1 b2 a3 c4 a5 d6} a*
   1.350 +} {c4 d6}
   1.351 +test lsearch-14.7 {combinations: -start, -all and -not} {
   1.352 +    lsearch -start 2 -all -not -glob {a1 b2 a3 c4 a5 d6} a*
   1.353 +} {3 5}
   1.354 +test lsearch-14.8 {combinations: -start, -inline and -not} {
   1.355 +    lsearch -start 2 -inline -not -glob {a1 b2 a3 c4 a5 d6} a*
   1.356 +} {c4}
   1.357 +
   1.358 +test lsearch-15.1 {make sure no shimmering occurs} {
   1.359 +    set x [expr int(sin(0))]
   1.360 +    lsearch -start $x $x $x
   1.361 +} 0
   1.362 +
   1.363 +test lsearch-16.1 {lsearch -regexp shared object} {
   1.364 +    set str a
   1.365 +    lsearch -regexp $str $str
   1.366 +} 0
   1.367 +# Bug 1366683
   1.368 +test lsearch-16.2 {lsearch -regexp allows internal backrefs} {
   1.369 +    lsearch -regexp {a aa b} {(.)\1}
   1.370 +} 1
   1.371 +
   1.372 +# cleanup
   1.373 +catch {unset res}
   1.374 +catch {unset increasingIntegers}
   1.375 +catch {unset decreasingIntegers}
   1.376 +catch {unset increasingDoubles}
   1.377 +catch {unset decreasingDoubles}
   1.378 +catch {unset increasingStrings}
   1.379 +catch {unset decreasingStrings}
   1.380 +catch {unset increasingDictionary}
   1.381 +catch {unset decreasingDictionary}
   1.382 +::tcltest::cleanupTests
   1.383 +return