|
|
1.1 root 1: # This file contains contains a collection of tests for the "index"
2: # command in Tcl. If everything is OK then it finishes silently.
3: # If a problem is detected then it generates a Tcl error with a
4: # cryptic message. To trace the error you'll have to read through
5: # the commands in this file.
6: #
7: # $Header: /sprite/src/lib/tcl/tests/RCS/index.test,v 1.1 90/03/21 14:05:41 ouster Exp $ (Berkeley)
8:
9: proc check {a b num} {
10: if {[string compare $a $b] != 0} {
11: error [format {Index error %s: wanted "%s", got "%s"} $num $b $a]}
12: }
13:
14: check [index {a b c} 0] a 1.1
15: check [index {a {b c d} x} 1] {b c d} 1.2
16: check [index {a b\ c\ d x} 1] {b c d} 1.3
17: check [index {a b c} 3] {} 1.4
18: check [catch {index {a b c} -1} msg] 1 1.5
19: check $msg {bad index "-1"} 1.6
20:
21: check [index abcde 0 chars] a 2.1
22: check [index abcde 4 c] e 2.2
23: check [index abcde 5 chars] {} 2.3
24: check [catch {index abcde -10 chars} msg] 1 2.4
25: check $msg {bad index "-10"} 2.5
26:
27: check [catch index msg] 1 3.1
28: check $msg {wrong # args: should be "index value index [chars]"} 3.2
29: check [catch {index 1 2 3 4} msg] 1 3.3
30: check $msg {wrong # args: should be "index value index [chars]"} 3.4
31: check [catch {index 1 2 foo} msg] 1 3.5
32: check $msg {bad argument "foo": must be "chars"} 3.6
33: check [catch "index \"a b {c\" 2" msg] 1 3.7
34: check $msg {unmatched open brace in list} 3.8
35: check [catch "index \"a b {c}d e\" 2" msg] 1 3.9
36: check $msg {list element in braces followed by "d" instead of space} 3.10
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.