1# Commands covered: lsearch 2# 3# This file contains a collection of tests for one or more of the Tcl built-in 4# commands. Sourcing this file into Tcl runs the tests and generates output 5# for errors. No output means no errors were found. 6# 7# Copyright © 1991-1993 The Regents of the University of California. 8# Copyright © 1994 Sun Microsystems, Inc. 9# Copyright © 1998-1999 Scriptics Corporation. 10# 11# See the file "license.terms" for information on usage and redistribution of 12# this file, and for a DISCLAIMER OF ALL WARRANTIES. 13 14if {"::tcltest" ni [namespace children]} { 15 package require tcltest 2.5 16 namespace import -force ::tcltest::* 17} 18 19set x {abcd bbcd 123 234 345} 20test lsearch-1.1 {lsearch command} { 21 lsearch $x 123 22} 2 23test lsearch-1.2 {lsearch command} { 24 lsearch $x 3456 25} -1 26test lsearch-1.3 {lsearch command} { 27 lsearch $x *5 28} 4 29test lsearch-1.4 {lsearch command} { 30 lsearch $x *bc* 31} 0 32 33test lsearch-2.1 {search modes} { 34 lsearch -exact {xyz bbcc *bc*} *bc* 35} 2 36test lsearch-2.2 {search modes} { 37 lsearch -exact {b.x ^bc xy bcx} ^bc 38} 1 39test lsearch-2.3 {search modes} { 40 lsearch -exact {foo bar cat} ba 41} -1 42test lsearch-2.4 {search modes} { 43 lsearch -exact {foo bar cat} bart 44} -1 45test lsearch-2.5 {search modes} { 46 lsearch -exact {foo bar cat} bar 47} 1 48test lsearch-2.6 {search modes} -returnCodes error -body { 49 lsearch -regexp {xyz bbcc *bc*} *bc* 50} -result {couldn't compile regular expression pattern: quantifier operand invalid} 51test lsearch-2.7 {search modes} { 52 lsearch -regexp {b.x ^bc xy bcx} ^bc 53} 3 54test lsearch-2.8 {search modes} { 55 lsearch -glob {xyz bbcc *bc*} *bc* 56} 1 57test lsearch-2.9 {search modes} { 58 lsearch -glob {b.x ^bc xy bcx} ^bc 59} 1 60test lsearch-2.10 {search modes} -returnCodes error -body { 61 lsearch -glib {b.x bx xy bcx} b.x 62} -result {bad option "-glib": must be -all, -ascii, -bisect, -decreasing, -dictionary, -exact, -glob, -increasing, -index, -inline, -integer, -nocase, -not, -real, -regexp, -sorted, -start, -stride, or -subindices} 63test lsearch-2.11 {search modes with -nocase} { 64 lsearch -exact -nocase {a b c A B C} A 65} 0 66test lsearch-2.12 {search modes with -nocase} { 67 lsearch -glob -nocase {a b c A B C} A* 68} 0 69test lsearch-2.13 {search modes with -nocase} { 70 lsearch -regexp -nocase {a b c A B C} ^A\$ 71} 0 72test lsearch-2.14 {search modes without -nocase} { 73 lsearch -exact {a b c A B C} A 74} 3 75test lsearch-2.15 {search modes without -nocase} { 76 lsearch -glob {a b c A B C} A* 77} 3 78test lsearch-2.16 {search modes without -nocase} { 79 lsearch -regexp {a b c A B C} ^A\$ 80} 3 81 82test lsearch-3.1 {lsearch errors} -returnCodes error -body { 83 lsearch 84} -result {wrong # args: should be "lsearch ?-option value ...? list pattern"} 85test lsearch-3.2 {lsearch errors} -returnCodes error -body { 86 lsearch a 87} -result {wrong # args: should be "lsearch ?-option value ...? list pattern"} 88test lsearch-3.3 {lsearch errors} -returnCodes error -body { 89 lsearch a b c 90} -result {bad option "a": must be -all, -ascii, -bisect, -decreasing, -dictionary, -exact, -glob, -increasing, -index, -inline, -integer, -nocase, -not, -real, -regexp, -sorted, -start, -stride, or -subindices} 91test lsearch-3.4 {lsearch errors} -returnCodes error -body { 92 lsearch a b c d 93} -result {bad option "a": must be -all, -ascii, -bisect, -decreasing, -dictionary, -exact, -glob, -increasing, -index, -inline, -integer, -nocase, -not, -real, -regexp, -sorted, -start, -stride, or -subindices} 94test lsearch-3.5 {lsearch errors} -returnCodes error -body { 95 lsearch "\{" b 96} -result {unmatched open brace in list} 97test lsearch-3.6 {lsearch errors} -returnCodes error -body { 98 lsearch -index a b 99} -result {"-index" option must be followed by list index} 100test lsearch-3.7 {lsearch errors} -returnCodes error -body { 101 lsearch -subindices -exact a b 102} -result {-subindices cannot be used without -index option} 103 104test lsearch-4.1 {binary data} { 105 lsearch -exact [list foo one\x00two bar] bar 106} 2 107test lsearch-4.2 {binary data} { 108 set x one 109 append x \x00 110 append x two 111 lsearch -exact [list foo one\x00two bar] $x 112} 1 113 114# Make a sorted list 115set l {} 116set l2 {} 117for {set i 0} {$i < 100} {incr i} { 118 lappend l $i 119 lappend l2 [expr {double($i)/2}] 120} 121set increasingIntegers [lsort -integer $l] 122set decreasingIntegers [lsort -decreasing -integer $l] 123set increasingDoubles [lsort -real $l2] 124set decreasingDoubles [lsort -decreasing -real $l2] 125set increasingStrings [lsort {48 6a 18b 22a 21aa 35 36}] 126set decreasingStrings [lsort -decreasing {48 6a 18b 22a 21aa 35 36}] 127set increasingDictionary [lsort -dictionary {48 6a 18b 22a 21aa 35 36}] 128set decreasingDictionary [lsort -dictionary -decreasing $increasingDictionary] 129 130set l {} 131for {set i 0} {$i < 10} {incr i} { 132 lappend l $i $i $i $i $i 133} 134set repeatingIncreasingIntegers [lsort -integer $l] 135set repeatingDecreasingIntegers [lsort -integer -decreasing $l] 136 137test lsearch-5.1 {binary search} { 138 set res {} 139 for {set i 0} {$i < 100} {incr i} { 140 lappend res [lsearch -integer -sorted $increasingIntegers $i] 141 } 142 set res 143} $increasingIntegers 144test lsearch-5.2 {binary search} { 145 set res {} 146 for {set i 0} {$i < 100} {incr i} { 147 lappend res [lsearch -integer -decreasing -sorted \ 148 $decreasingIntegers $i] 149 } 150 set res 151} $decreasingIntegers 152test lsearch-5.3 {binary search finds leftmost occurrences} { 153 set res {} 154 for {set i 0} {$i < 10} {incr i} { 155 lappend res [lsearch -integer -sorted $repeatingIncreasingIntegers $i] 156 } 157 set res 158} [list 0 5 10 15 20 25 30 35 40 45] 159test lsearch-5.4 {binary search -decreasing finds leftmost occurrences} { 160 set res {} 161 for {set i 9} {$i >= 0} {incr i -1} { 162 lappend res [lsearch -sorted -integer -decreasing \ 163 $repeatingDecreasingIntegers $i] 164 } 165 set res 166} [list 0 5 10 15 20 25 30 35 40 45] 167 168test lsearch-6.1 {integer search} { 169 set res {} 170 for {set i 0} {$i < 100} {incr i} { 171 lappend res [lsearch -exact -integer $increasingIntegers $i] 172 } 173 set res 174} [lrange $increasingIntegers 0 99] 175test lsearch-6.2 {decreasing integer search} { 176 set res {} 177 for {set i 0} {$i < 100} {incr i} { 178 lappend res [lsearch -exact -integer -decreasing \ 179 $decreasingIntegers $i] 180 } 181 set res 182} [lrange $decreasingIntegers 0 99] 183test lsearch-6.3 {sorted integer search} { 184 set res {} 185 for {set i 0} {$i < 100} {incr i} { 186 lappend res [lsearch -sorted -integer $increasingIntegers $i] 187 } 188 set res 189} [lrange $increasingIntegers 0 99] 190test lsearch-6.4 {sorted decreasing integer search} { 191 set res {} 192 for {set i 0} {$i < 100} {incr i} { 193 lappend res [lsearch -integer -sorted -decreasing \ 194 $decreasingIntegers $i] 195 } 196 set res 197} [lrange $decreasingIntegers 0 99] 198 199test lsearch-7.1 {double search} { 200 set res {} 201 for {set i 0} {$i < 100} {incr i} { 202 lappend res [lsearch -exact -real $increasingDoubles \ 203 [expr {double($i)/2}]] 204 } 205 set res 206} [lrange $increasingIntegers 0 99] 207test lsearch-7.2 {decreasing double search} { 208 set res {} 209 for {set i 0} {$i < 100} {incr i} { 210 lappend res [lsearch -exact -real -decreasing \ 211 $decreasingDoubles [expr {double($i)/2}]] 212 } 213 set res 214} [lrange $decreasingIntegers 0 99] 215test lsearch-7.3 {sorted double search} { 216 set res {} 217 for {set i 0} {$i < 100} {incr i} { 218 lappend res [lsearch -sorted -real \ 219 $increasingDoubles [expr {double($i)/2}]] 220 } 221 set res 222} [lrange $increasingIntegers 0 99] 223test lsearch-7.4 {sorted decreasing double search} { 224 set res {} 225 for {set i 0} {$i < 100} {incr i} { 226 lappend res [lsearch -sorted -real -decreasing \ 227 $decreasingDoubles [expr {double($i)/2}]] 228 } 229 set res 230} [lrange $decreasingIntegers 0 99] 231 232test lsearch-8.1 {dictionary search} { 233 set res {} 234 foreach val {6a 18b 21aa 22a 35 36 48} { 235 lappend res [lsearch -exact -dictionary $increasingDictionary $val] 236 } 237 set res 238} [list 0 1 2 3 4 5 6] 239test lsearch-8.2 {decreasing dictionary search} { 240 set res {} 241 foreach val {6a 18b 21aa 22a 35 36 48} { 242 lappend res [lsearch -exact -dictionary $decreasingDictionary $val] 243 } 244 set res 245} [list 6 5 4 3 2 1 0] 246test lsearch-8.3 {sorted dictionary search} { 247 set res {} 248 foreach val {6a 18b 21aa 22a 35 36 48} { 249 lappend res [lsearch -sorted -dictionary $increasingDictionary $val] 250 } 251 set res 252} [list 0 1 2 3 4 5 6] 253test lsearch-8.4 {decreasing sorted dictionary search} { 254 set res {} 255 foreach val {6a 18b 21aa 22a 35 36 48} { 256 lappend res [lsearch -decreasing -sorted -dictionary \ 257 $decreasingDictionary $val] 258 } 259 set res 260} [list 6 5 4 3 2 1 0] 261 262test lsearch-9.1 {ascii search} { 263 set res {} 264 foreach val {18b 21aa 22a 35 36 48 6a} { 265 lappend res [lsearch -exact -ascii $increasingStrings $val] 266 } 267 set res 268} [list 0 1 2 3 4 5 6] 269test lsearch-9.2 {decreasing ascii search} { 270 set res {} 271 foreach val {18b 21aa 22a 35 36 48 6a} { 272 lappend res [lsearch -exact -ascii $decreasingStrings $val] 273 } 274 set res 275} [list 6 5 4 3 2 1 0] 276test lsearch-9.3 {sorted ascii search} { 277 set res {} 278 foreach val {18b 21aa 22a 35 36 48 6a} { 279 lappend res [lsearch -sorted -ascii $increasingStrings $val] 280 } 281 set res 282} [list 0 1 2 3 4 5 6] 283test lsearch-9.4 {decreasing sorted ascii search} { 284 set res {} 285 foreach val {18b 21aa 22a 35 36 48 6a} { 286 lappend res [lsearch -decreasing -sorted -ascii \ 287 $decreasingStrings $val] 288 } 289 set res 290} [list 6 5 4 3 2 1 0] 291 292test lsearch-10.1 {offset searching} { 293 lsearch -start 2 {a b c a b c} a 294} 3 295test lsearch-10.2 {offset searching} { 296 lsearch -start 2 {a b c d e f} a 297} -1 298test lsearch-10.3 {offset searching} { 299 lsearch -start end-4 {a b c a b c} a 300} 3 301test lsearch-10.4 {offset searching} -returnCodes error -body { 302 lsearch -start foobar {a b c a b c} a 303} -result {bad index "foobar": must be integer?[+-]integer? or end?[+-]integer?} 304test lsearch-10.5 {offset searching} -returnCodes error -body { 305 lsearch -start 1 2 306} -result {missing starting index} 307test lsearch-10.6 {binary search with offset} { 308 set res {} 309 for {set i 0} {$i < 100} {incr i} { 310 lappend res [lsearch -integer -start 2 -sorted $increasingIntegers $i] 311 } 312 set res 313} [concat -1 -1 [lrange $increasingIntegers 2 end]] 314test lsearch-10.7 {offset searching with an empty list} { 315 # Stop bug #694232 from reocurring 316 lsearch -start 0 {} x 317} -1 318test lsearch-10.8 {offset searching past the end of the list} { 319 # Stop [Bug 1374778] from reoccurring 320 lsearch -start 10 {a b c} c 321} -1 322test lsearch-10.9 {offset searching past the end of the list} { 323 # Stop [Bug 1374778] from reoccurring 324 lsearch -start 10 -all {a b c} c 325} {} 326test lsearch-10.10 {offset searching past the end of the list} { 327 # Stop [Bug 1374778] from reoccurring 328 lsearch -start 10 -inline {a b c} c 329} {} 330 331test lsearch-11.1 {negated searches} { 332 lsearch -not {a a a b a a a} a 333} 3 334test lsearch-11.2 {negated searches} { 335 lsearch -not {a a a a a a a} a 336} -1 337 338test lsearch-12.1 {return values instead of indices} { 339 lsearch -glob -inline {a1 b2 c3 d4} c* 340} c3 341test lsearch-12.2 {return values instead of indices} { 342 lsearch -glob -inline {a1 b2 c3 d4} e* 343} {} 344 345test lsearch-13.1 {search for all matches} { 346 lsearch -all {a b a c a d} 1 347} {} 348test lsearch-13.2 {search for all matches} { 349 lsearch -all {a b a c a d} a 350} {0 2 4} 351test lsearch-13.3 {search for all matches with -nocase} { 352 lsearch -all -exact -nocase {a b c A B C} A 353} {0 3} 354test lsearch-13.4 {search for all matches with -nocase} { 355 lsearch -all -glob -nocase {a b c A B C} A* 356} {0 3} 357test lsearch-13.5 {search for all matches with -nocase} { 358 lsearch -all -regexp -nocase {a b c A B C} ^A\$ 359} {0 3} 360 361test lsearch-14.1 {combinations: -all and -inline} { 362 lsearch -all -inline -glob {a1 b2 a3 c4 a5 d6} a* 363} {a1 a3 a5} 364test lsearch-14.2 {combinations: -all, -inline and -not} { 365 lsearch -all -inline -not -glob {a1 b2 a3 c4 a5 d6} a* 366} {b2 c4 d6} 367test lsearch-14.3 {combinations: -all and -not} { 368 lsearch -all -not -glob {a1 b2 a3 c4 a5 d6} a* 369} {1 3 5} 370test lsearch-14.4 {combinations: -inline and -not} { 371 lsearch -inline -not -glob {a1 b2 a3 c4 a5 d6} a* 372} {b2} 373test lsearch-14.5 {combinations: -start, -all and -inline} { 374 lsearch -start 2 -all -inline -glob {a1 b2 a3 c4 a5 d6} a* 375} {a3 a5} 376test lsearch-14.6 {combinations: -start, -all, -inline and -not} { 377 lsearch -start 2 -all -inline -not -glob {a1 b2 a3 c4 a5 d6} a* 378} {c4 d6} 379test lsearch-14.7 {combinations: -start, -all and -not} { 380 lsearch -start 2 -all -not -glob {a1 b2 a3 c4 a5 d6} a* 381} {3 5} 382test lsearch-14.8 {combinations: -start, -inline and -not} { 383 lsearch -start 2 -inline -not -glob {a1 b2 a3 c4 a5 d6} a* 384} {c4} 385 386test lsearch-15.1 {make sure no shimmering occurs} { 387 set x [expr {int(sin(0))}] 388 lsearch -start $x $x $x 389} 0 390 391test lsearch-16.1 {lsearch -regexp shared object} { 392 set str a 393 lsearch -regexp $str $str 394} 0 395# Bug 1366683 396test lsearch-16.2 {lsearch -regexp allows internal backrefs} { 397 lsearch -regexp {a aa b} {(.)\1} 398} 1 399 400test lsearch-17.1 {lsearch -index option, basic functionality} { 401 lsearch -index 1 {{a c} {a b} {a a}} a 402} 2 403test lsearch-17.2 {lsearch -index option, basic functionality} { 404 lsearch -index 1 -exact {{a c} {a b} {a a}} a 405} 2 406test lsearch-17.3 {lsearch -index option, basic functionality} { 407 lsearch -index 1 -glob {{ab cb} {ab bb} {ab ab}} b* 408} 1 409test lsearch-17.4 {lsearch -index option, basic functionality} { 410 lsearch -index 1 -regexp {{ab cb} {ab bb} {ab ab}} {[cb]b} 411} 0 412test lsearch-17.5 {lsearch -index option, basic functionality} { 413 lsearch -all -index 0 -exact {{a c} {a b} {d a}} a 414} {0 1} 415test lsearch-17.6 {lsearch -index option, basic functionality} { 416 lsearch -all -index 1 -glob {{ab cb} {ab bb} {db bx}} b* 417} {1 2} 418test lsearch-17.7 {lsearch -index option, basic functionality} { 419 lsearch -all -index 1 -regexp {{ab cb} {ab bb} {ab ab}} {[cb]b} 420} {0 1} 421test lsearch-17.8 {lsearch -index option, empty argument} { 422 lsearch -index {} a a 423} 0 424test lsearch-17.9 {lsearch -index option, empty argument} { 425 lsearch -index {} a a 426} [lsearch a a] 427test lsearch-17.10 {lsearch -index option, empty argument} { 428 lsearch -index {} [list \{] \{ 429} 0 430test lsearch-17.11 {lsearch -index option, empty argument} { 431 lsearch -index {} [list \{] \{ 432} [lsearch [list \{] \{] 433test lsearch-17.12 {lsearch -index option, encoding aliasing} -body { 434 lsearch -index -2 a a 435} -returnCodes error -result {index "-2" out of range} 436test lsearch-17.13 {lsearch -index option, encoding aliasing} -body { 437 lsearch -index -1-1 a a 438} -returnCodes error -result {index "-1-1" out of range} 439test lsearch-17.14 {lsearch -index option, encoding aliasing} -body { 440 lsearch -index end--1 a a 441} -returnCodes error -result {index "end--1" out of range} 442test lsearch-17.15 {lsearch -index option, encoding aliasing} -body { 443 lsearch -index end+1 a a 444} -returnCodes error -result {index "end+1" out of range} 445test lsearch-17.16 {lsearch -index option, encoding aliasing} -body { 446 lsearch -index end+2 a a 447} -returnCodes error -result {index "end+2" out of range} 448 449 450test lsearch-18.1 {lsearch -index option, list as index basic functionality} { 451 lsearch -index {0 0} {{{x x} {x b} {a d}} {{a c} {a b} {a a}}} a 452} 1 453test lsearch-18.2 {lsearch -index option, list as index basic functionality} { 454 lsearch -index {2 0} -exact {{{x x} {x b} {a d}} {{a c} {a b} {a a}}} a 455} 0 456test lsearch-18.3 {lsearch -index option, list as index basic functionality} { 457 lsearch -index {1 1} -glob {{{ab cb} {ab bb} {ab ab}} {{ab cb} {ab bb} {ab ab}}} b* 458} 0 459test lsearch-18.4 {lsearch -index option, list as index basic functionality} { 460 lsearch -index {0 1} -regexp {{{ab cb} {ab bb} {ab ab}} {{ab cb} {ab bb} {ab ab}}} {[cb]b} 461} 0 462test lsearch-18.5 {lsearch -index option, list as index basic functionality} { 463 lsearch -all -index {0 0} -exact {{{a c} {a b} {d a}} {{a c} {a b} {d a}}} a 464} {0 1} 465 466test lsearch-19.1 {lsearch -subindices option} { 467 lsearch -subindices -index {0 0} {{{x x} {x b} {a d}} {{a c} {a b} {a a}}} a 468} {1 0 0} 469test lsearch-19.2 {lsearch -subindices option} { 470 lsearch -subindices -index {2 0} -exact {{{x x} {x b} {a d}} {{a c} {a b} {a a}}} a 471} {0 2 0} 472test lsearch-19.3 {lsearch -subindices option} { 473 lsearch -subindices -index {1 1} -glob {{{ab cb} {ab bb} {ab ab}} {{ab cb} {ab bb} {ab ab}}} b* 474} {0 1 1} 475test lsearch-19.4 {lsearch -subindices option} { 476 lsearch -subindices -index {0 1} -regexp {{{ab cb} {ab bb} {ab ab}} {{ab cb} {ab bb} {ab ab}}} {[cb]b} 477} {0 0 1} 478test lsearch-19.5 {lsearch -subindices option} { 479 lsearch -subindices -all -index {0 0} -exact {{{a c} {a b} {d a}} {{a c} {a b} {d a}}} a 480} {{0 0 0} {1 0 0}} 481test lsearch-19.6 {lsearch -subindices option} { 482 lsearch -subindices -all -index {1 0} -exact {{{a c} {a b} {d a}} {{a c} {a b} {d a}}} a 483} {{0 1 0} {1 1 0}} 484test lsearch-19.7 {lsearch -subindices option} { 485 lsearch -subindices -index end {{1 a}} a 486} {0 1} 487test lsearch-19.8 {lsearch -subindices option} { 488 lsearch -subindices -all -index end {{1 a}} a 489} {{0 1}} 490 491test lsearch-20.1 {lsearch -index option, index larger than sublists} -body { 492 lsearch -index 2 {{a c} {a b} {a a}} a 493} -returnCodes error -result {element 2 missing from sublist "a c"} 494test lsearch-20.2 {lsearch -index option, malformed index} -body { 495 lsearch -index foo {{a c} {a b} {a a}} a 496} -returnCodes error -result {bad index "foo": must be integer?[+-]integer? or end?[+-]integer?} 497test lsearch-20.3 {lsearch -index option, malformed index} -body { 498 lsearch -index \{ {{a c} {a b} {a a}} a 499} -returnCodes error -result {unmatched open brace in list} 500 501test lsearch-21.1 {lsearch shimmering crash} { 502 set x 0 503 lsearch -exact -integer $x $x 504} 0 505test lsearch-21.2 {lsearch shimmering crash} { 506 set x 0.5 507 lsearch -exact -real $x $x 508} 0 509 510test lsearch-22.1 {lsearch -bisect} -setup { 511 set res {} 512} -body { 513 foreach i {0 1 5 6 7 8 15 16} { 514 lappend res [lsearch -bisect -integer {1 4 5 7 9 15} $i] 515 } 516 return $res 517} -result {-1 0 2 2 3 3 5 5} 518test lsearch-22.2 {lsearch -bisect, last of equals} -setup { 519 set res {} 520} -body { 521 foreach i {0 1 2 3} { 522 lappend res [lsearch -bisect -integer {0 0 1 1 1 2 2 2 3 3 3} $i] 523 } 524 return $res 525} -result {1 4 7 10} 526test lsearch-22.3 {lsearch -bisect decreasing order} -setup { 527 set res {} 528} -body { 529 foreach i {0 1 5 6 7 8 15 16} { 530 lappend res [lsearch -bisect -integer -decreasing {15 9 7 5 4 1} $i] 531 } 532 return $res 533} -result {5 5 3 2 2 1 0 -1} 534test lsearch-22.4 {lsearch -bisect, last of equals, decreasing} -setup { 535 set res {} 536} -body { 537 foreach i {0 1 2 3} { 538 lappend res [lsearch -bisect -integer -decreasing \ 539 {3 3 3 2 2 2 1 1 1 0 0} $i] 540 } 541 return $res 542} -result {10 8 5 2} 543test lsearch-22.5 {lsearch -bisect, all equal} { 544 lsearch -bisect -integer {5 5 5 5} 5 545} {3} 546test lsearch-22.6 {lsearch -sorted, all equal} { 547 lsearch -sorted -integer {5 5 5 5} 5 548} {0} 549 550test lsearch-23.1 {lsearch -stride option, errors} -body { 551 lsearch -stride {a b} a 552} -returnCodes error -result {"-stride" option must be followed by stride length} 553test lsearch-23.2 {lsearch -stride option, errors} -body { 554 lsearch -stride 0 {a b} a 555} -returnCodes error -result {stride length must be at least 1} 556test lsearch-23.3 {lsearch -stride option, errors} -body { 557 lsearch -stride 2 {a b c} a 558} -returnCodes error -result {list size must be a multiple of the stride length} 559test lsearch-23.4 {lsearch -stride option, errors} -body { 560 lsearch -stride 5 {a b c} a 561} -returnCodes error -result {list size must be a multiple of the stride length} 562test lsearch-23.5 {lsearch -stride option, errors} -body { 563 # Stride equal to length is ok 564 lsearch -stride 3 {a b c} a 565} -result 0 566 567test lsearch-24.1 {lsearch -stride option} -body { 568 lsearch -stride 2 {a b c d e f g h} d 569} -result -1 570test lsearch-24.2 {lsearch -stride option} -body { 571 lsearch -stride 2 {a b c d e f g h} e 572} -result 4 573test lsearch-24.3 {lsearch -stride option} -body { 574 lsearch -stride 3 {a b c d e f g h i} e 575} -result -1 576test lsearch-24.4 {lsearch -stride option} -body { 577 # Result points first in group 578 lsearch -stride 3 -index 1 {a b c d e f g h i} e 579} -result 3 580test lsearch-24.5 {lsearch -stride option} -body { 581 lsearch -inline -stride 2 {a b c d e f g h} d 582} -result {} 583test lsearch-24.6 {lsearch -stride option} -body { 584 # Inline result is a "single element" strided list 585 lsearch -inline -stride 2 {a b c d e f g h} e 586} -result "e f" 587test lsearch-24.7 {lsearch -stride option} -body { 588 lsearch -inline -stride 3 {a b c d e f g h i} e 589} -result {} 590test lsearch-24.8 {lsearch -stride option} -body { 591 lsearch -inline -stride 3 -index 1 {a b c d e f g h i} e 592} -result "d e f" 593test lsearch-24.9 {lsearch -stride option} -body { 594 lsearch -all -inline -stride 3 -index 1 {a b c d e f g e i} e 595} -result "d e f g e i" 596test lsearch-24.10 {lsearch -stride option} -body { 597 lsearch -all -inline -stride 3 -index 0 {a b c d e f a e i} a 598} -result "a b c a e i" 599test lsearch-24.11 {lsearch -stride option} -body { 600 # Stride 1 is same as no stride 601 lsearch -stride 1 {a b c d e f g h} d 602} -result 3 603 604# 25* mimics 19* but with -inline added to -subindices 605test lsearch-25.1 {lsearch -subindices option} { 606 lsearch -inline -subindices -index {0 0} {{{x x} {x b} {a d}} {{a c} {a b} {a a}}} a 607} {a} 608test lsearch-25.2 {lsearch -subindices option} { 609 lsearch -inline -subindices -index {2 0} -exact {{{x x} {x b} {a d}} {{a c} {a b} {a a}}} a 610} {a} 611test lsearch-25.3 {lsearch -subindices option} { 612 lsearch -inline -subindices -index {1 1} -glob {{{ab cb} {ab bb} {ab ab}} {{ab cb} {ab bb} {ab ab}}} b* 613} {bb} 614test lsearch-25.4 {lsearch -subindices option} { 615 lsearch -inline -subindices -index {0 1} -regexp {{{ab cb} {ab bb} {ab ab}} {{ab cb} {ab bb} {ab ab}}} {[cb]b} 616} {cb} 617test lsearch-25.5 {lsearch -subindices option} { 618 lsearch -inline -subindices -all -index {0 0} -exact {{{a c} {a b} {d a}} {{a c} {a b} {d a}}} a 619} {a a} 620test lsearch-25.6 {lsearch -subindices option} { 621 lsearch -inline -subindices -all -index {1 0} -exact {{{a c} {a b} {d a}} {{a c} {a b} {d a}}} a 622} {a a} 623 624# 26* mimics 19* but with -stride added 625test lsearch-26.1 {lsearch -stride + -subindices option} { 626 lsearch -stride 3 -subindices -index {0 0} {{x x} {x b} {a d} {a c} {a b} {a a}} a 627} {3 0} 628test lsearch-26.2 {lsearch -stride + -subindices option} { 629 lsearch -stride 3 -subindices -index {2 0} -exact {{x x} {x b} {a d} {a c} {a b} {a a}} a 630} {2 0} 631test lsearch-26.3 {lsearch -stride + -subindices option} { 632 lsearch -stride 3 -subindices -index {1 1} -glob {{ab cb} {ab bb} {ab ab} {ab cb} {ab bb} {ab ab}} b* 633} {1 1} 634test lsearch-26.4 {lsearch -stride + -subindices option} { 635 lsearch -stride 3 -subindices -index {0 1} -regexp {{ab cb} {ab bb} {ab ab} {ab cb} {ab bb} {ab ab}} {[cb]b} 636} {0 1} 637test lsearch-26.5 {lsearch -stride + -subindices option} { 638 lsearch -stride 3 -subindices -all -index {0 0} -exact {{a c} {a b} {d a} {a c} {a b} {d a}} a 639} {{0 0} {3 0}} 640test lsearch-26.6 {lsearch -stride + -subindices option} { 641 lsearch -stride 3 -subindices -all -index {1 0} -exact {{a c} {a b} {d a} {x c} {a b} {d a}} a 642} {{1 0} {4 0}} 643 644# 27* mimics 25* but with -stride added 645test lsearch-27.1 {lsearch -stride + -subindices option} { 646 lsearch -inline -stride 3 -subindices -index {0 0} {{x x} {x b} {a d} {a c} {a b} {a a}} a 647} {a} 648test lsearch-27.2 {lsearch -stride + -subindices option} { 649 lsearch -inline -stride 3 -subindices -index {2 0} -exact {{x x} {x b} {a d} {a c} {a b} {a a}} a 650} {a} 651test lsearch-27.3 {lsearch -stride + -subindices option} { 652 lsearch -inline -stride 3 -subindices -index {1 1} -glob {{ab cb} {ab bb} {ab ab} {ab cb} {ab bb} {ab ab}} b* 653} {bb} 654test lsearch-27.4 {lsearch -stride + -subindices option} { 655 lsearch -inline -stride 3 -subindices -index {0 1} -regexp {{ab cb} {ab bb} {ab ab} {ab cb} {ab bb} {ab ab}} {[cb]b} 656} {cb} 657test lsearch-27.5 {lsearch -stride + -subindices option} { 658 lsearch -inline -stride 3 -subindices -all -index {0 0} -exact {{a c} {a b} {d a} {a c} {a b} {d a}} a 659} {a a} 660test lsearch-27.6 {lsearch -stride + -subindices option} { 661 lsearch -inline -stride 3 -subindices -all -index {1 0} -exact {{a c} {a b} {d a} {x c} {a b} {d a}} a 662} {a a} 663 664test lsearch-28.1 {lsearch -sorted with -stride} -body { 665 lsearch -sorted -stride 2 {5 3 7 8 9 2} 5 666} -result 0 667test lsearch-28.2 {lsearch -sorted with -stride} -body { 668 lsearch -sorted -stride 2 {5 3 7 8 9 2} 3 669} -result -1 670test lsearch-28.3 {lsearch -sorted with -stride} -body { 671 lsearch -sorted -stride 2 {5 3 7 8 9 2} 7 672} -result 2 673test lsearch-28.4 {lsearch -sorted with -stride} -body { 674 lsearch -sorted -stride 2 {5 3 7 8 9 2} 8 675} -result -1 676test lsearch-28.5 {lsearch -sorted with -stride} -body { 677 lsearch -sorted -stride 2 {5 3 7 8 9 2} 9 678} -result 4 679test lsearch-28.6 {lsearch -sorted with -stride} -body { 680 lsearch -sorted -stride 2 {5 3 7 8 9 2} 2 681} -result -1 682test lsearch-28.7 {lsearch -sorted with -stride} -body { 683 lsearch -sorted -stride 2 -index 0 -subindices {5 3 7 8 9 2} 9 684} -result 4 685test lsearch-28.8 {lsearch -sorted with -stride} -body { 686 lsearch -sorted -stride 2 -index 1 -subindices {3 5 8 7 2 9} 9 687} -result 5 688test lsearch-28.9 {lsearch -sorted with -stride} -body { 689 lsearch -sorted -stride 2 -index 1 -subindices -inline {3 5 8 7 2 9} 9 690} -result 9 691 692 693# cleanup 694catch {unset res} 695catch {unset increasingIntegers} 696catch {unset decreasingIntegers} 697catch {unset increasingDoubles} 698catch {unset decreasingDoubles} 699catch {unset increasingStrings} 700catch {unset decreasingStrings} 701catch {unset increasingDictionary} 702catch {unset decreasingDictionary} 703::tcltest::cleanupTests 704return 705 706# Local Variables: 707# mode: tcl 708# End: 709