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} {
25 test lsearch-1.2 {lsearch command} {
28 test lsearch-1.3 {lsearch command} {
31 test lsearch-1.4 {lsearch command} {
35 test lsearch-2.1 {search modes} {
36 lsearch -exact {xyz bbcc *bc*} *bc*
38 test lsearch-2.2 {search modes} {
39 lsearch -exact {b.x ^bc xy bcx} ^bc
41 test lsearch-2.3 {search modes} {
42 lsearch -exact {foo bar cat} ba
44 test lsearch-2.4 {search modes} {
45 lsearch -exact {foo bar cat} bart
47 test lsearch-2.5 {search modes} {
48 lsearch -exact {foo bar cat} bar
50 test lsearch-2.6 {search modes} regexp {
51 list [catch {lsearch -regexp {xyz bbcc *bc*} *bc*} msg]
53 test lsearch-2.7 {search modes} regexp {
54 lsearch -regexp {b.x ^bc xy bcx} ^bc
56 test lsearch-2.8 {search modes} {
57 lsearch -glob {xyz bbcc *bc*} *bc*
59 test lsearch-2.9 {search modes} {
60 lsearch -glob {b.x ^bc xy bcx} ^bc
62 test lsearch-2.10 {search modes} {
63 list [catch {lsearch -glib {b.x bx xy bcx} b.x} msg]
65 test lsearch-2.7 {search modes, -nocase} regexp {
66 lsearch -nocase -regexp {b.x ^bc xy bcx} ^BC
68 test lsearch-2.8 {search modes, -nocase} {
69 lsearch -nocase -exact {b.x ^bc xy bcx} ^BC
71 test lsearch-2.9 {search modes, -nocase} {
72 lsearch -nocase -glob {b.x ^bc xy bcx} B*
75 test lsearch-3.1 {lsearch errors} {
76 list [catch lsearch msg]
78 test lsearch-3.2 {lsearch errors} {
79 list [catch {lsearch a} msg]
81 test lsearch-3.3 {lsearch errors} {
82 list [catch {lsearch a b c} msg]
84 test lsearch-3.4 {lsearch errors} {
85 list [catch {lsearch a b c d} msg]
88 test lsearch-4.1 {binary data} {
89 lsearch -exact [list foo one\000two bar] bar
91 test lsearch-4.2 {binary data} {
95 lsearch -exact [list foo one\000two bar] $x
98 test lsearch-5.1 {lsearch -all} {
99 lsearch -glob -all {a1 a2 b1 b2 a3 b3} a*
102 test lsearch-5.2 {lsearch -all no match} {
103 lsearch -glob -all {a1 a2 b1 b2 a3 b3} B*
106 test lsearch-5.3 {lsearch -all -nocase} {
107 lsearch -glob -all -nocase {a1 a2 b1 b2 a3 b3} B*
110 test lsearch-5.4 {lsearch -all -inline} {
111 lsearch -glob -all -inline -nocase {a1 a2 b1 b2 a3 b3} A*
114 test lsearch-5.5 {lsearch -inline} {
115 lsearch -glob -inline {a1 a2 b1 b2 a3 b3} b*
118 test lsearch-5.6 {lsearch -not -all} {
119 lsearch -not -glob -all {a1 a2 b1 b2 a3 b3} a*
122 test lsearch-5.7 {lsearch -not -all no match} {
123 lsearch -not -glob -all {a1 a2 b1 b2 a3 b3} B*
126 test lsearch-5.8 {lsearch -not -all -nocase} {
127 lsearch -not -glob -all -nocase {a1 a2 b1 b2 a3 b3} B*
130 test lsearch-5.9 {lsearch -not -all -inline} {
131 lsearch -not -glob -all -inline -nocase {a1 a2 b1 b2 a3 b3} A*
134 test lsearch-5.10 {lsearch -not -inline} {
135 lsearch -not -glob -inline {a1 a2 b1 b2 a3 b3} b*
138 test lsearch-5.11 {lsearch -inline, no match} {
139 lsearch -glob -inline {a1 a2 b1 b2 a3 b3} C*
142 test lsearch-6.1 {lsearch -bool, found} jim {
143 lsearch -bool {a1 a2 b1 b2 a3 b3} b1
146 test lsearch-6.2 {lsearch -bool, not found} jim {
147 lsearch -bool {a1 a2 b1 b2 a3 b3} c1
150 test lsearch-6.3 {lsearch -not -bool, found} jim {
151 lsearch -not -bool {a1 a2 b1 b2 a3 b3} b1
154 test lsearch-6.4 {lsearch -not -bool, not found} jim {
155 lsearch -not -bool {a1 a2 b1 b2 a3 b3} c1
158 test lsearch-6.5 {lsearch -bool -all} jim {
159 lsearch -bool -glob -all {a1 a2 b1 b2 a3 b3} a*
162 test lsearch-6.6 {lsearch -bool -all no match} jim {
163 lsearch -bool -glob -all {a1 a2 b1 b2 a3 b3} B*
166 test lsearch-6.7 {lsearch -bool -all -nocase} jim {
167 lsearch -bool -glob -all -nocase {a1 a2 b1 b2 a3 b3} B*
170 test lsearch-6.8 {lsearch -not -bool -all} jim {
171 lsearch -not -bool -glob -all {a1 a2 b1 b2 a3 b3} a*
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*
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*