auto.def: tclprefix should not be enabled by default
[jimtcl.git] / tests / lrange.test
blobe72421c39a95dac8751d550956ebebcfeade4706
1 # Commands covered:  lrange
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.
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.
11 # See the file "license.terms" for information on usage and redistribution
12 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14 source [file dirname [info script]]/testing.tcl
16 test lrange-1.1 {range of list elements} {
17     lrange {a b c d} 1 2
18 } {b c}
19 test lrange-1.2 {range of list elements} {
20     lrange {a {bcd e {f g {}}} l14 l15 d} 1 1
21 } {{bcd e {f g {}}}}
22 test lrange-1.3 {range of list elements} {
23     lrange {a {bcd e {f g {}}} l14 l15 d} 3 end
24 } {l15 d}
25 test lrange-1.4 {range of list elements} {
26     lrange {a {bcd e {f g {}}} l14 l15 d} 4 10000
27 } {d}
28 test lrange-1.5 {range of list elements} {
29     lrange {a {bcd e {f g {}}} l14 l15 d} 4 3
30 } {}
31 test lrange-1.6 {range of list elements} {
32     lrange {a {bcd e {f g {}}} l14 l15 d} 10 11
33 } {}
34 test lrange-1.7 {range of list elements} {
35     lrange {a b c d e} -1 2
36 } {a b c}
37 test lrange-1.8 {range of list elements} {
38     lrange {a b c d e} -2 -1
39 } {}
40 test lrange-1.9 {range of list elements} {
41     lrange {a b c d e} -2 end
42 } {a b c d e}
43 test lrange-1.10 {range of list elements} {
44     lrange "a b\{c d" 1 2
45 } "b\\{c d"
46 test lrange-1.11 {range of list elements} {
47     lrange "a b c d" end end
48 } d
49 test lrange-1.12 {range of list elements} {
50     lrange "a b c d" end 100000
51 } d
52 test lrange-1.13 {range of list elements} {
53     lrange "a b c d" end 3
54 } d
55 test lrange-1.14 {range of list elements} {
56     lrange "a b c d" end 2
57 } {}
58 test lrange-1.15 {range of list elements} {
59     concat \"[lrange {a b \{\           } 0 2]"
60 } {"a b \{\ "}
61 test lrange-1.16 {list element quoting} {
62     lrange {[append a .b]} 0 end    
63 } {{[append} a .b\]}
64 test lrange-2.1 {error conditions} {
65     list [catch {lrange a b} msg] $msg
66 } {1 {wrong # args: should be "lrange list first last"}}
67 test lrange-2.2 {error conditions} {
68     list [catch {lrange a b 6 7} msg] $msg
69 } {1 {wrong # args: should be "lrange list first last"}}
70 test lrange-2.3 {error conditions} {
71     list [catch {lrange a b 6} msg] $msg
72 } {1 {bad index "b": must be integer?[+-]integer? or end?[+-]integer?}}
73 test lrange-2.4 {error conditions} {
74     list [catch {lrange a 0 enigma} msg] $msg
75 } {1 {bad index "enigma": must be integer?[+-]integer? or end?[+-]integer?}}
76 test lrange-2.5 {error conditions} tcl {
77     list [catch {lrange "a \{b c" 3 4} msg] $msg
78 } {1 {unmatched open brace in list}}
79 test lrange-2.6 {error conditions} tcl {
80     list [catch {lrange "a b c \{ d e" 1 4} msg] $msg
81 } {1 {unmatched open brace in list}}
83 # cleanup
84 ::tcltest::cleanupTests
85 return