auto.def: tclprefix should not be enabled by default
[jimtcl.git] / tests / lsearch.test
blob1eb6607bccbbac38d48811c4bc9a9d260803bf26
1 # Commands covered:  lsearch
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 # RCS: @(#) $Id: lsearch.test,v 1.5 2000/04/10 17:19:01 ericm Exp $
16 source [file dirname [info script]]/testing.tcl
18 catch {package require regexp}
19 testConstraint regexp [expr {[info commands regexp] ne {}}]
21 set x {abcd bbcd 123 234 345}
22 test lsearch-1.1 {lsearch command} {
23     lsearch $x 123
24 } 2
25 test lsearch-1.2 {lsearch command} {
26     lsearch $x 3456
27 } -1
28 test lsearch-1.3 {lsearch command} {
29     lsearch -glob $x *5
30 } 4
31 test lsearch-1.4 {lsearch command} {
32     lsearch -glob $x *bc*
33 } 0
35 test lsearch-2.1 {search modes} {
36     lsearch -exact {xyz bbcc *bc*} *bc*
37 } 2
38 test lsearch-2.2 {search modes} {
39     lsearch -exact {b.x ^bc xy bcx} ^bc
40 } 1
41 test lsearch-2.3 {search modes} {
42     lsearch -exact {foo bar cat} ba
43 } -1
44 test lsearch-2.4 {search modes} {
45     lsearch -exact {foo bar cat} bart
46 } -1
47 test lsearch-2.5 {search modes} {
48     lsearch -exact {foo bar cat} bar
49 } 1
50 test lsearch-2.6 {search modes} regexp {
51     list [catch {lsearch -regexp {xyz bbcc *bc*} *bc*} msg]
52 } {1}
53 test lsearch-2.7 {search modes} regexp {
54     lsearch -regexp {b.x ^bc xy bcx} ^bc
55 } 3
56 test lsearch-2.8 {search modes} {
57     lsearch -glob {xyz bbcc *bc*} *bc*
58 } 1
59 test lsearch-2.9 {search modes} {
60     lsearch -glob {b.x ^bc xy bcx} ^bc
61 } 1
62 test lsearch-2.10 {search modes} {
63     list [catch {lsearch -glib {b.x bx xy bcx} b.x} msg]
64 } {1}
65 test lsearch-2.7 {search modes, -nocase} regexp {
66     lsearch -nocase -regexp {b.x ^bc xy bcx} ^BC
67 } 3
68 test lsearch-2.8 {search modes, -nocase} {
69     lsearch -nocase -exact {b.x ^bc xy bcx} ^BC
70 } 1
71 test lsearch-2.9 {search modes, -nocase} {
72     lsearch -nocase -glob {b.x ^bc xy bcx} B*
73 } 0
75 test lsearch-3.1 {lsearch errors} {
76     list [catch lsearch msg]
77 } {1}
78 test lsearch-3.2 {lsearch errors} {
79     list [catch {lsearch a} msg]
80 } {1}
81 test lsearch-3.3 {lsearch errors} {
82     list [catch {lsearch a b c} msg]
83 } {1}
84 test lsearch-3.4 {lsearch errors} {
85     list [catch {lsearch a b c d} msg]
86 } {1}
88 test lsearch-4.1 {binary data} {
89     lsearch -exact [list foo one\000two bar] bar
90 } 2
91 test lsearch-4.2 {binary data} {
92     set x one
93     append x \x00
94     append x two
95     lsearch -exact [list foo one\000two bar] $x
96 } 1
98 test lsearch-5.1 {lsearch -all} {
99     lsearch -glob -all {a1 a2 b1 b2 a3 b3} a*
100 } {0 1 4}
102 test lsearch-5.2 {lsearch -all no match} {
103     lsearch -glob -all {a1 a2 b1 b2 a3 b3} B*
104 } {}
106 test lsearch-5.3 {lsearch -all -nocase} {
107     lsearch -glob -all -nocase {a1 a2 b1 b2 a3 b3} B*
108 } {2 3 5}
110 test lsearch-5.4 {lsearch -all -inline} {
111     lsearch -glob -all -inline -nocase {a1 a2 b1 b2 a3 b3} A*
112 } {a1 a2 a3}
114 test lsearch-5.5 {lsearch -inline} {
115     lsearch -glob -inline {a1 a2 b1 b2 a3 b3} b*
116 } {b1}
118 test lsearch-5.6 {lsearch -not -all} {
119     lsearch -not -glob -all {a1 a2 b1 b2 a3 b3} a*
120 } {2 3 5}
122 test lsearch-5.7 {lsearch -not -all no match} {
123     lsearch -not -glob -all {a1 a2 b1 b2 a3 b3} B*
124 } {0 1 2 3 4 5}
126 test lsearch-5.8 {lsearch -not -all -nocase} {
127     lsearch -not -glob -all -nocase {a1 a2 b1 b2 a3 b3} B*
128 } {0 1 4}
130 test lsearch-5.9 {lsearch -not -all -inline} {
131     lsearch -not -glob -all -inline -nocase {a1 a2 b1 b2 a3 b3} A*
132 } {b1 b2 b3}
134 test lsearch-5.10 {lsearch -not -inline} {
135     lsearch -not -glob -inline {a1 a2 b1 b2 a3 b3} b*
136 } {a1}
138 test lsearch-5.11 {lsearch -inline, no match} {
139     lsearch -glob -inline {a1 a2 b1 b2 a3 b3} C*
140 } {}
142 test lsearch-6.1 {lsearch -bool, found} jim {
143     lsearch -bool {a1 a2 b1 b2 a3 b3} b1
144 } {1}
146 test lsearch-6.2 {lsearch -bool, not found} jim {
147     lsearch -bool {a1 a2 b1 b2 a3 b3} c1
148 } {0}
150 test lsearch-6.3 {lsearch -not -bool, found} jim {
151     lsearch -not -bool {a1 a2 b1 b2 a3 b3} b1
152 } {0}
154 test lsearch-6.4 {lsearch -not -bool, not found} jim {
155     lsearch -not -bool {a1 a2 b1 b2 a3 b3} c1
156 } {1}
158 test lsearch-6.5 {lsearch -bool -all} jim {
159     lsearch -bool -glob -all {a1 a2 b1 b2 a3 b3} a*
160 } {1 1 0 0 1 0}
162 test lsearch-6.6 {lsearch -bool -all no match} jim {
163     lsearch -bool -glob -all {a1 a2 b1 b2 a3 b3} B*
164 } {0 0 0 0 0 0}
166 test lsearch-6.7 {lsearch -bool -all -nocase} jim {
167     lsearch -bool -glob -all -nocase {a1 a2 b1 b2 a3 b3} B*
168 } {0 0 1 1 0 1}
170 test lsearch-6.8 {lsearch -not -bool -all} jim {
171     lsearch -not -bool -glob -all {a1 a2 b1 b2 a3 b3} a*
172 } {0 0 1 1 0 1}
174 test lsearch-6.9 {lsearch -not -bool -all no match} jim {
175     lsearch -not -bool -glob -all {a1 a2 b1 b2 a3 b3} B*
176 } {1 1 1 1 1 1}
178 test lsearch-6.10 {lsearch -not -bool -all -nocase} jim {
179     lsearch -not -bool -glob -all -nocase {a1 a2 b1 b2 a3 b3} B*
180 } {1 1 0 0 1 0}
182 testreport