# Copyright © 2021 Nathan Coulter
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
if {"::tcltest" ni [namespace children]} {
package require tcltest 2.5
namespace import -force ::tcltest::*
}
::tcltest::loadTestedCommands
testConstraint testindexhex [expr {[namespace which testindexhex] ne {}}]
variable list
variable res
test {list lindex constant} {INST_LIST_INDEX_IMM} \
-constraints testindexhex \
-body {
set list [testindexhex]
lindex $list 731
} -cleanup {
catch {unset list}
} -result 2db
test {list lindex constant end} {INST_LIST_INDEX_IMM} \
-constraints testindexhex \
-body {
set list [testindexhex]
after 100
lindex $list end
} -cleanup {
catch {unset list}
catch {unset res}
} -returnCodes 1 -result {list length indeterminate}
test {list lindex dynamic} {INST_LIST_INDEX} \
-constraints testindexhex \
-body {
set list [testindexhex]
set val [expr {731 + 0}]
after 100
lindex $list $val
} -cleanup {
catch {unset list}
} -result 2db
test {list lindex dynamic end} {INST_LIST_INDEX} \
-constraints testindexhex \
-body {
set list [testindexhex]
append index e n d
lindex $list $index
} -cleanup {
catch {unset list}
catch {unset res}
} -returnCodes 1 -result {list length indeterminate}
test {list lindex drill} {} \
-constraints testindexhex \
-body {
set list [testindexhex]
lindex $list 731 0 0 0
} -cleanup {
catch {unset list}
} -result 2db
test {list lrange constant} {} \
-constraints testindexhex \
-body {
set list [testindexhex]
lrange $list 10 15
} -cleanup {
catch {unset list}
} -result {a b c d e f}
test {list lrange dynamic} {} \
-constraints testindexhex \
-body {
set list [testindexhex]
set first [expr {10 + 0}]
set last [expr {15 + 0}]
lrange $list $first $last
} -cleanup {
catch {unset list}
} -result {a b c d e f}
test {list lrange end constant} {} \
-constraints testindexhex \
-body {
set list [testindexhex]
lrange $list 10 end
} -cleanup {
catch {unset list}
} -returnCodes 1 -result {list length indeterminate}
test {list lrange end dynamic} {} \
-constraints testindexhex \
-body {
set list [testindexhex]
set back [expr {-5 + 0}]
lrange $list 10 end-$back
} -cleanup {
catch {unset list}
} -returnCodes 1 -result {list length indeterminate}
test {list lrange end minus constant} {} \
-constraints testindexhex \
-body {
set list [testindexhex]
lrange $list 10 end-1
} -cleanup {
catch {unset list}
} -returnCodes 1 -result {list length indeterminate}
# cleanup
::tcltest::cleanupTests
return