diff options
Diffstat (limited to 'tests/lsearch.test')
-rw-r--r-- | tests/lsearch.test | 105 |
1 files changed, 101 insertions, 4 deletions
diff --git a/tests/lsearch.test b/tests/lsearch.test index a0899c4..36bf389 100644 --- a/tests/lsearch.test +++ b/tests/lsearch.test @@ -59,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 -all, -ascii, -decreasing, -dictionary, -exact, -glob, -increasing, -inline, -integer, -not, -real, -regexp, -sorted, or -start}} +} {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 @@ -69,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 -all, -ascii, -decreasing, -dictionary, -exact, -glob, -increasing, -inline, -integer, -not, -real, -regexp, -sorted, or -start}} +} {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 -all, -ascii, -decreasing, -dictionary, -exact, -glob, -increasing, -inline, -integer, -not, -real, -regexp, -sorted, or -start}} +} {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 @@ -276,7 +300,7 @@ test lsearch-10.3 {offset searching} { } 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 or end?-integer?}} +} {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}} @@ -324,6 +348,15 @@ test lsearch-13.1 {search for all matches} { 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* @@ -364,6 +397,70 @@ 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 |