summaryrefslogtreecommitdiffstats
path: root/tests/lsearch.test
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lsearch.test')
-rw-r--r--tests/lsearch.test218
1 files changed, 208 insertions, 10 deletions
diff --git a/tests/lsearch.test b/tests/lsearch.test
index 275a569..36bf389 100644
--- a/tests/lsearch.test
+++ b/tests/lsearch.test
@@ -10,8 +10,6 @@
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
-#
-# RCS: @(#) $Id: lsearch.test,v 1.6 2000/05/09 17:50:39 ericm Exp $
if {[lsearch [namespace children] ::tcltest] == -1} {
package require tcltest
@@ -61,7 +59,25 @@ test lsearch-2.9 {search modes} {
} 1
test lsearch-2.10 {search modes} {
list [catch {lsearch -glib {b.x bx xy bcx} b.x} msg] $msg
-} {1 {bad option "-glib": must be -ascii, -decreasing, -dictionary, -exact, -increasing, -integer, -glob, -real, -regexp, or -sorted}}
+} {1 {bad option "-glib": must be -all, -ascii, -decreasing, -dictionary, -exact, -glob, -increasing, -index, -inline, -integer, -nocase, -not, -real, -regexp, -sorted, -start, or -subindices}}
+test lsearch-2.11 {search modes with -nocase} {
+ lsearch -exact -nocase {a b c A B C} A
+} 0
+test lsearch-2.12 {search modes with -nocase} {
+ lsearch -glob -nocase {a b c A B C} A*
+} 0
+test lsearch-2.13 {search modes with -nocase} {
+ lsearch -regexp -nocase {a b c A B C} ^A\$
+} 0
+test lsearch-2.14 {search modes without -nocase} {
+ lsearch -exact {a b c A B C} A
+} 3
+test lsearch-2.15 {search modes without -nocase} {
+ lsearch -glob {a b c A B C} A*
+} 3
+test lsearch-2.16 {search modes without -nocase} {
+ lsearch -regexp {a b c A B C} ^A\$
+} 3
test lsearch-3.1 {lsearch errors} {
list [catch lsearch msg] $msg
@@ -71,13 +87,19 @@ test lsearch-3.2 {lsearch errors} {
} {1 {wrong # args: should be "lsearch ?options? list pattern"}}
test lsearch-3.3 {lsearch errors} {
list [catch {lsearch a b c} msg] $msg
-} {1 {bad option "a": must be -ascii, -decreasing, -dictionary, -exact, -increasing, -integer, -glob, -real, -regexp, or -sorted}}
+} {1 {bad option "a": must be -all, -ascii, -decreasing, -dictionary, -exact, -glob, -increasing, -index, -inline, -integer, -nocase, -not, -real, -regexp, -sorted, -start, or -subindices}}
test lsearch-3.4 {lsearch errors} {
list [catch {lsearch a b c d} msg] $msg
-} {1 {bad option "a": must be -ascii, -decreasing, -dictionary, -exact, -increasing, -integer, -glob, -real, -regexp, or -sorted}}
+} {1 {bad option "a": must be -all, -ascii, -decreasing, -dictionary, -exact, -glob, -increasing, -index, -inline, -integer, -nocase, -not, -real, -regexp, -sorted, -start, or -subindices}}
test lsearch-3.5 {lsearch errors} {
list [catch {lsearch "\{" b} msg] $msg
} {1 {unmatched open brace in list}}
+test lsearch-3.6 {lsearch errors} {
+ list [catch {lsearch -index a b} msg] $msg
+} {1 {"-index" option must be followed by list index}}
+test lsearch-3.7 {lsearch errors} {
+ list [catch {lsearch -subindices -exact a b} msg] $msg
+} {1 {-subindices cannot be used without -index option}}
test lsearch-4.1 {binary data} {
lsearch -exact [list foo one\000two bar] bar
@@ -267,20 +289,196 @@ test lsearch-9.4 {decreasing sorted ascii search} {
set res
} [list 6 5 4 3 2 1 0]
+test lsearch-10.1 {offset searching} {
+ lsearch -start 2 {a b c a b c} a
+} 3
+test lsearch-10.2 {offset searching} {
+ lsearch -start 2 {a b c d e f} a
+} -1
+test lsearch-10.3 {offset searching} {
+ lsearch -start end-4 {a b c a b c} a
+} 3
+test lsearch-10.4 {offset searching} {
+ list [catch {lsearch -start foobar {a b c a b c} a} msg] $msg
+} {1 {bad index "foobar": must be integer?[+-]integer? or end?[+-]integer?}}
+test lsearch-10.5 {offset searching} {
+ list [catch {lsearch -start 1 2} msg] $msg
+} {1 {missing starting index}}
+test lsearch-10.6 {binary search with offset} {
+ set res {}
+ for {set i 0} {$i < 100} {incr i} {
+ lappend res [lsearch -integer -start 2 -sorted $increasingIntegers $i]
+ }
+ set res
+} [concat -1 -1 [lrange $increasingIntegers 2 end]]
+test lsearch-10.7 {offset searching with an empty list} {
+ # Stop bug #694232 from reocurring
+ lsearch -start 0 {} x
+} -1
+test lsearch-10.8 {offset searching past the end of the list} {
+ # Stop [Bug 1374778] from reoccurring
+ lsearch -start 10 {a b c} c
+} -1
+test lsearch-10.9 {offset searching past the end of the list} {
+ # Stop [Bug 1374778] from reoccurring
+ lsearch -start 10 -all {a b c} c
+} {}
+test lsearch-10.10 {offset searching past the end of the list} {
+ # Stop [Bug 1374778] from reoccurring
+ lsearch -start 10 -inline {a b c} c
+} {}
+test lsearch-11.1 {negated searches} {
+ lsearch -not {a a a b a a a} a
+} 3
+test lsearch-11.2 {negated searches} {
+ lsearch -not {a a a a a a a} a
+} -1
-# cleanup
-::tcltest::cleanupTests
-return
-
-
+test lsearch-12.1 {return values instead of indices} {
+ lsearch -glob -inline {a1 b2 c3 d4} c*
+} c3
+test lsearch-12.2 {return values instead of indices} {
+ lsearch -glob -inline {a1 b2 c3 d4} e*
+} {}
+test lsearch-13.1 {search for all matches} {
+ lsearch -all {a b a c a d} 1
+} {}
+test lsearch-13.2 {search for all matches} {
+ lsearch -all {a b a c a d} a
+} {0 2 4}
+test lsearch-13.3 {search for all matches with -nocase} {
+ lsearch -all -exact -nocase {a b c A B C} A
+} {0 3}
+test lsearch-13.4 {search for all matches with -nocase} {
+ lsearch -all -glob -nocase {a b c A B C} A*
+} {0 3}
+test lsearch-13.5 {search for all matches with -nocase} {
+ lsearch -all -regexp -nocase {a b c A B C} ^A\$
+} {0 3}
+test lsearch-14.1 {combinations: -all and -inline} {
+ lsearch -all -inline -glob {a1 b2 a3 c4 a5 d6} a*
+} {a1 a3 a5}
+test lsearch-14.2 {combinations: -all, -inline and -not} {
+ lsearch -all -inline -not -glob {a1 b2 a3 c4 a5 d6} a*
+} {b2 c4 d6}
+test lsearch-14.3 {combinations: -all and -not} {
+ lsearch -all -not -glob {a1 b2 a3 c4 a5 d6} a*
+} {1 3 5}
+test lsearch-14.4 {combinations: -inline and -not} {
+ lsearch -inline -not -glob {a1 b2 a3 c4 a5 d6} a*
+} {b2}
+test lsearch-14.5 {combinations: -start, -all and -inline} {
+ lsearch -start 2 -all -inline -glob {a1 b2 a3 c4 a5 d6} a*
+} {a3 a5}
+test lsearch-14.6 {combinations: -start, -all, -inline and -not} {
+ lsearch -start 2 -all -inline -not -glob {a1 b2 a3 c4 a5 d6} a*
+} {c4 d6}
+test lsearch-14.7 {combinations: -start, -all and -not} {
+ lsearch -start 2 -all -not -glob {a1 b2 a3 c4 a5 d6} a*
+} {3 5}
+test lsearch-14.8 {combinations: -start, -inline and -not} {
+ lsearch -start 2 -inline -not -glob {a1 b2 a3 c4 a5 d6} a*
+} {c4}
+test lsearch-15.1 {make sure no shimmering occurs} {
+ set x [expr int(sin(0))]
+ lsearch -start $x $x $x
+} 0
+test lsearch-16.1 {lsearch -regexp shared object} {
+ set str a
+ lsearch -regexp $str $str
+} 0
+# Bug 1366683
+test lsearch-16.2 {lsearch -regexp allows internal backrefs} {
+ lsearch -regexp {a aa b} {(.)\1}
+} 1
+test lsearch-17.1 {lsearch -index option, basic functionality} {
+ lsearch -index 1 {{a c} {a b} {a a}} a
+} 2
+test lsearch-17.2 {lsearch -index option, basic functionality} {
+ lsearch -index 1 -exact {{a c} {a b} {a a}} a
+} 2
+test lsearch-17.3 {lsearch -index option, basic functionality} {
+ lsearch -index 1 -glob {{ab cb} {ab bb} {ab ab}} b*
+} 1
+test lsearch-17.4 {lsearch -index option, basic functionality} {
+ lsearch -index 1 -regexp {{ab cb} {ab bb} {ab ab}} {[cb]b}
+} 0
+test lsearch-17.5 {lsearch -index option, basic functionality} {
+ lsearch -all -index 0 -exact {{a c} {a b} {d a}} a
+} {0 1}
+test lsearch-17.6 {lsearch -index option, basic functionality} {
+ lsearch -all -index 1 -glob {{ab cb} {ab bb} {db bx}} b*
+} {1 2}
+test lsearch-17.7 {lsearch -index option, basic functionality} {
+ lsearch -all -index 1 -regexp {{ab cb} {ab bb} {ab ab}} {[cb]b}
+} {0 1}
+test lsearch-18.1 {lsearch -index option, list as index basic functionality} {
+ lsearch -index {0 0} {{{x x} {x b} {a d}} {{a c} {a b} {a a}}} a
+} 1
+test lsearch-18.2 {lsearch -index option, list as index basic functionality} {
+ lsearch -index {2 0} -exact {{{x x} {x b} {a d}} {{a c} {a b} {a a}}} a
+} 0
+test lsearch-18.3 {lsearch -index option, list as index basic functionality} {
+ lsearch -index {1 1} -glob {{{ab cb} {ab bb} {ab ab}} {{ab cb} {ab bb} {ab ab}}} b*
+} 0
+test lsearch-18.4 {lsearch -index option, list as index basic functionality} {
+ lsearch -index {0 1} -regexp {{{ab cb} {ab bb} {ab ab}} {{ab cb} {ab bb} {ab ab}}} {[cb]b}
+} 0
+test lsearch-18.5 {lsearch -index option, list as index basic functionality} {
+ lsearch -all -index {0 0} -exact {{{a c} {a b} {d a}} {{a c} {a b} {d a}}} a
+} {0 1}
+test lsearch-19.1 {lsearch -sunindices option} {
+ lsearch -subindices -index {0 0} {{{x x} {x b} {a d}} {{a c} {a b} {a a}}} a
+} {1 0 0}
+test lsearch-19.2 {lsearch -sunindices option} {
+ lsearch -subindices -index {2 0} -exact {{{x x} {x b} {a d}} {{a c} {a b} {a a}}} a
+} {0 2 0}
+test lsearch-19.3 {lsearch -sunindices option} {
+ lsearch -subindices -index {1 1} -glob {{{ab cb} {ab bb} {ab ab}} {{ab cb} {ab bb} {ab ab}}} b*
+} {0 1 1}
+test lsearch-19.4 {lsearch -sunindices option} {
+ lsearch -subindices -index {0 1} -regexp {{{ab cb} {ab bb} {ab ab}} {{ab cb} {ab bb} {ab ab}}} {[cb]b}
+} {0 0 1}
+test lsearch-19.5 {lsearch -sunindices option} {
+ lsearch -subindices -all -index {0 0} -exact {{{a c} {a b} {d a}} {{a c} {a b} {d a}}} a
+} {{0 0 0} {1 0 0}}
+test lsearch-20.1 {lsearch -index option, index larger than sublists} {
+ list [catch {lsearch -index 2 {{a c} {a b} {a a}} a} msg] $msg
+} {1 {element 2 missing from sublist "a c"}}
+test lsearch-20.2 {lsearch -index option, malformed index} {
+ list [catch {lsearch -index foo {{a c} {a b} {a a}} a} msg] $msg
+} {1 {bad index "foo": must be integer?[+-]integer? or end?[+-]integer?}}
+test lsearch-20.3 {lsearch -index option, malformed index} {
+ list [catch {lsearch -index \{ {{a c} {a b} {a a}} a} msg] $msg
+} {1 {unmatched open brace in list}}
+test lsearch-21.1 {lsearch shimmering crash} {
+ set x 0
+ lsearch -exact -integer $x $x
+} 0
+test lsearch-21.2 {lsearch shimmering crash} {
+ set x 0.5
+ lsearch -exact -real $x $x
+} 0
+# cleanup
+catch {unset res}
+catch {unset increasingIntegers}
+catch {unset decreasingIntegers}
+catch {unset increasingDoubles}
+catch {unset decreasingDoubles}
+catch {unset increasingStrings}
+catch {unset decreasingStrings}
+catch {unset increasingDictionary}
+catch {unset decreasingDictionary}
+::tcltest::cleanupTests
+return