1 | # Commands covered: lrange |
---|
2 | # |
---|
3 | # This file contains a collection of tests for one or more of the Tcl |
---|
4 | # built-in commands. Sourcing this file into Tcl runs the tests and |
---|
5 | # generates output for errors. No output means no errors were found. |
---|
6 | # |
---|
7 | # Copyright (c) 1991-1993 The Regents of the University of California. |
---|
8 | # Copyright (c) 1994 Sun Microsystems, Inc. |
---|
9 | # Copyright (c) 1998-1999 by Scriptics Corporation. |
---|
10 | # |
---|
11 | # See the file "license.terms" for information on usage and redistribution |
---|
12 | # of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
13 | # |
---|
14 | # RCS: @(#) $Id: lrange.test,v 1.9 2005/05/10 18:35:22 kennykb Exp $ |
---|
15 | |
---|
16 | if {[lsearch [namespace children] ::tcltest] == -1} { |
---|
17 | package require tcltest |
---|
18 | namespace import -force ::tcltest::* |
---|
19 | } |
---|
20 | |
---|
21 | test lrange-1.1 {range of list elements} { |
---|
22 | lrange {a b c d} 1 2 |
---|
23 | } {b c} |
---|
24 | test lrange-1.2 {range of list elements} { |
---|
25 | lrange {a {bcd e {f g {}}} l14 l15 d} 1 1 |
---|
26 | } {{bcd e {f g {}}}} |
---|
27 | test lrange-1.3 {range of list elements} { |
---|
28 | lrange {a {bcd e {f g {}}} l14 l15 d} 3 end |
---|
29 | } {l15 d} |
---|
30 | test lrange-1.4 {range of list elements} { |
---|
31 | lrange {a {bcd e {f g {}}} l14 l15 d} 4 10000 |
---|
32 | } {d} |
---|
33 | test lrange-1.5 {range of list elements} { |
---|
34 | lrange {a {bcd e {f g {}}} l14 l15 d} 4 3 |
---|
35 | } {} |
---|
36 | test lrange-1.6 {range of list elements} { |
---|
37 | lrange {a {bcd e {f g {}}} l14 l15 d} 10 11 |
---|
38 | } {} |
---|
39 | test lrange-1.7 {range of list elements} { |
---|
40 | lrange {a b c d e} -1 2 |
---|
41 | } {a b c} |
---|
42 | test lrange-1.8 {range of list elements} { |
---|
43 | lrange {a b c d e} -2 -1 |
---|
44 | } {} |
---|
45 | test lrange-1.9 {range of list elements} { |
---|
46 | lrange {a b c d e} -2 end |
---|
47 | } {a b c d e} |
---|
48 | test lrange-1.10 {range of list elements} { |
---|
49 | lrange "a b\{c d" 1 2 |
---|
50 | } "b\\{c d" |
---|
51 | test lrange-1.11 {range of list elements} { |
---|
52 | lrange "a b c d" end end |
---|
53 | } d |
---|
54 | test lrange-1.12 {range of list elements} { |
---|
55 | lrange "a b c d" end 100000 |
---|
56 | } d |
---|
57 | test lrange-1.13 {range of list elements} { |
---|
58 | lrange "a b c d" end 3 |
---|
59 | } d |
---|
60 | test lrange-1.14 {range of list elements} { |
---|
61 | lrange "a b c d" end 2 |
---|
62 | } {} |
---|
63 | test lrange-1.15 {range of list elements} { |
---|
64 | concat \"[lrange {a b \{\ } 0 2]" |
---|
65 | } {"a b \{\ "} |
---|
66 | test lrange-1.16 {list element quoting} { |
---|
67 | lrange {[append a .b]} 0 end |
---|
68 | } {{[append} a .b\]} |
---|
69 | |
---|
70 | test lrange-2.1 {error conditions} { |
---|
71 | list [catch {lrange a b} msg] $msg |
---|
72 | } {1 {wrong # args: should be "lrange list first last"}} |
---|
73 | test lrange-2.2 {error conditions} { |
---|
74 | list [catch {lrange a b 6 7} msg] $msg |
---|
75 | } {1 {wrong # args: should be "lrange list first last"}} |
---|
76 | test lrange-2.3 {error conditions} { |
---|
77 | list [catch {lrange a b 6} msg] $msg |
---|
78 | } {1 {bad index "b": must be integer?[+-]integer? or end?[+-]integer?}} |
---|
79 | test lrange-2.4 {error conditions} { |
---|
80 | list [catch {lrange a 0 enigma} msg] $msg |
---|
81 | } {1 {bad index "enigma": must be integer?[+-]integer? or end?[+-]integer?}} |
---|
82 | test lrange-2.5 {error conditions} { |
---|
83 | list [catch {lrange "a \{b c" 3 4} msg] $msg |
---|
84 | } {1 {unmatched open brace in list}} |
---|
85 | test lrange-2.6 {error conditions} { |
---|
86 | list [catch {lrange "a b c \{ d e" 1 4} msg] $msg |
---|
87 | } {1 {unmatched open brace in list}} |
---|
88 | |
---|
89 | # cleanup |
---|
90 | ::tcltest::cleanupTests |
---|
91 | return |
---|