diff options
author | Steve Bennett <steveb@workware.net.au> | 2021-01-24 10:35:50 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2021-01-30 10:00:11 +1000 |
commit | fcb7f66be6f8b7012505bfa93674aef98a26f9d6 (patch) | |
tree | dfb8bf2d418a222cd4c0e9bb757b272d2f3a6511 /tests/lsort.test | |
parent | 43e71ad476f4c96815baf973f27e4c8006ebb33f (diff) | |
download | jimtcl-fcb7f66be6f8b7012505bfa93674aef98a26f9d6.zip jimtcl-fcb7f66be6f8b7012505bfa93674aef98a26f9d6.tar.gz jimtcl-fcb7f66be6f8b7012505bfa93674aef98a26f9d6.tar.bz2 |
lsearch, lsort: support for -stride and -index
Add -stride support to both lsearch and lsort
Add -index support to lsearch
Improve -index for lsort to support multiple indices
Also harmonise some error messages with Tcl 8.7
Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'tests/lsort.test')
-rw-r--r-- | tests/lsort.test | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/tests/lsort.test b/tests/lsort.test index dd5a019..5297568 100644 --- a/tests/lsort.test +++ b/tests/lsort.test @@ -17,7 +17,7 @@ test lsort-1.1 {Tcl_LsortObjCmd procedure} jim { } {1 {wrong # args: should be "lsort ?options? list"}} test lsort-1.2 {Tcl_LsortObjCmd procedure} jim { list [catch {lsort -foo {1 3 2 5}} msg] $msg -} {1 {bad option "-foo": must be -ascii, -command, -decreasing, -increasing, -index, -integer, -nocase, -real, or -unique}} +} {1 {bad option "-foo": must be -ascii, -command, -decreasing, -increasing, -index, -integer, -nocase, -real, -stride, or -unique}} test lsort-1.3 {Tcl_LsortObjCmd procedure, default options} { lsort {d e c b a \{ d35 d300} } {a b c d d300 d35 e \{} @@ -131,12 +131,12 @@ test lsort-3.1 {SortCompare procedure, skip comparisons after error} { test lsort-3.2 {lsort -real, returning indices} { lsort -decreasing -real {1.2 34.5 34.5 5.6} } {34.5 34.5 5.6 1.2} -test lsort-3.3 {SortCompare procedure, -index option} jim { - list [catch {lsort -integer -index 2 {{20 10} {15 30 40}}} msg] $msg -} {1 {list index out of range}} -test lsort-3.5 {SortCompare procedure, -index option} jim { - list [catch {lsort -integer -index 2 {{20 10 13} {15}}} msg] $msg -} {1 {list index out of range}} +test lsort-3.3 {SortCompare procedure, -index option} -body { + lsort -integer -index 2 {{20 10} {15 30 40}} +} -returnCodes error -result {element 2 missing from sublist "20 10"} +test lsort-3.5 {SortCompare procedure, -index option} -body { + lsort -integer -index 2 {{20 10 13} {15}} +} -returnCodes error -result {index "2" out of range} test lsort-3.6 {SortCompare procedure, -index option} { lsort -integer -index 2 {{1 15 30} {2 5 25} {3 25 20}} } {{3 25 20} {2 5 25} {1 15 30}} @@ -202,12 +202,40 @@ test lsort-3.22 {lsort, unique sort with index} { set vallist } {0 4 5} -test lsort-4.26 {DefaultCompare procedure, signed characters} utf8 { - lsort [list "abc\u80" "abc"] -} [list "abc" "abc\u80"] test lsort-5.1 "Sort case insensitive" { lsort -nocase {ba aB aa ce} } {aa aB ba ce} +test cmdIL-1.30 {Tcl_LsortObjCmd procedure, -stride option} { + lsort -stride 2 {f e d c b a} +} {b a d c f e} +test cmdIL-1.31 {Tcl_LsortObjCmd procedure, -stride option} { + lsort -stride 3 {f e d c b a} +} {c b a f e d} +test cmdIL-1.32 {lsort -stride errors} -returnCodes error -body { + lsort -stride foo bar +} -result {expected integer but got "foo"} +test cmdIL-1.33 {lsort -stride errors} -returnCodes error -body { + lsort -stride 1 bar +} -result {stride length must be at least 2} +test cmdIL-1.34 {lsort -stride errors} -returnCodes error -body { + lsort -stride 2 {a b c} +} -result {list size must be a multiple of the stride length} +test cmdIL-1.35 {lsort -stride errors} -returnCodes error -body { + lsort -stride 2 -index 3 {a b c d} +} -match glob -result {*} +test cmdIL-1.36 {lsort -stride and -index: Bug 2918962} { + lsort -stride 2 -index {0 1} { + {{c o d e} 54321} {{b l a h} 94729} + {{b i g} 12345} {{d e m o} 34512} + } +} {{{b i g} 12345} {{d e m o} 34512} {{c o d e} 54321} {{b l a h} 94729}} +test cmdIL-1.41 {lsort -stride and -index} -body { + lsort -stride 2 -index -2 {a 2 b 1} +} -returnCodes error -result {index "-2" out of range} +test cmdIL-1.42 {lsort -stride and-index} -body { + lsort -stride 2 -index -1-1 {a 2 b 1} +} -returnCodes error -result {index "-1-1" out of range} + testreport |