sl@0
|
1 |
# Commands covered: regexp, regsub
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# This file contains a collection of tests for one or more of the Tcl
|
sl@0
|
4 |
# built-in commands. Sourcing this file into Tcl runs the tests and
|
sl@0
|
5 |
# generates output for errors. No output means no errors were found.
|
sl@0
|
6 |
#
|
sl@0
|
7 |
# Copyright (c) 1991-1993 The Regents of the University of California.
|
sl@0
|
8 |
# Copyright (c) 1998 Sun Microsystems, Inc.
|
sl@0
|
9 |
# Copyright (c) 1998-1999 by Scriptics Corporation.
|
sl@0
|
10 |
#
|
sl@0
|
11 |
# See the file "license.terms" for information on usage and redistribution
|
sl@0
|
12 |
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
sl@0
|
13 |
#
|
sl@0
|
14 |
# RCS: @(#) $Id$
|
sl@0
|
15 |
|
sl@0
|
16 |
if {[lsearch [namespace children] ::tcltest] == -1} {
|
sl@0
|
17 |
package require tcltest 2
|
sl@0
|
18 |
namespace import -force ::tcltest::*
|
sl@0
|
19 |
}
|
sl@0
|
20 |
|
sl@0
|
21 |
# Procedure to evaluate a script within a proc, to test compilation
|
sl@0
|
22 |
# functionality
|
sl@0
|
23 |
|
sl@0
|
24 |
proc evalInProc { script } {
|
sl@0
|
25 |
proc testProc {} $script
|
sl@0
|
26 |
set status [catch {
|
sl@0
|
27 |
testProc
|
sl@0
|
28 |
} result]
|
sl@0
|
29 |
rename testProc {}
|
sl@0
|
30 |
return $result
|
sl@0
|
31 |
#return [list $status $result]
|
sl@0
|
32 |
}
|
sl@0
|
33 |
|
sl@0
|
34 |
catch {unset foo}
|
sl@0
|
35 |
test regexpComp-1.1 {basic regexp operation} {
|
sl@0
|
36 |
evalInProc {
|
sl@0
|
37 |
regexp ab*c abbbc
|
sl@0
|
38 |
}
|
sl@0
|
39 |
} 1
|
sl@0
|
40 |
test regexpComp-1.2 {basic regexp operation} {
|
sl@0
|
41 |
evalInProc {
|
sl@0
|
42 |
regexp ab*c ac
|
sl@0
|
43 |
}
|
sl@0
|
44 |
} 1
|
sl@0
|
45 |
test regexpComp-1.3 {basic regexp operation} {
|
sl@0
|
46 |
evalInProc {
|
sl@0
|
47 |
regexp ab*c ab
|
sl@0
|
48 |
}
|
sl@0
|
49 |
} 0
|
sl@0
|
50 |
test regexpComp-1.4 {basic regexp operation} {
|
sl@0
|
51 |
evalInProc {
|
sl@0
|
52 |
regexp -- -gorp abc-gorpxxx
|
sl@0
|
53 |
}
|
sl@0
|
54 |
} 1
|
sl@0
|
55 |
test regexpComp-1.5 {basic regexp operation} {
|
sl@0
|
56 |
evalInProc {
|
sl@0
|
57 |
regexp {^([^ ]*)[ ]*([^ ]*)} "" a
|
sl@0
|
58 |
}
|
sl@0
|
59 |
} 1
|
sl@0
|
60 |
test regexpComp-1.6 {basic regexp operation} {
|
sl@0
|
61 |
list [catch {regexp {} abc} msg] $msg
|
sl@0
|
62 |
} {0 1}
|
sl@0
|
63 |
test regexpComp-1.7 {regexp utf compliance} {
|
sl@0
|
64 |
# if not UTF-8 aware, result is "0 1"
|
sl@0
|
65 |
evalInProc {
|
sl@0
|
66 |
set foo "\u4e4eb q"
|
sl@0
|
67 |
regexp "\u4e4eb q" "a\u4e4eb qw\u5e4e\x4e wq" bar
|
sl@0
|
68 |
list [string compare $foo $bar] [regexp 4 $bar]
|
sl@0
|
69 |
}
|
sl@0
|
70 |
} {0 0}
|
sl@0
|
71 |
|
sl@0
|
72 |
test regexpComp-2.1 {getting substrings back from regexp} {
|
sl@0
|
73 |
evalInProc {
|
sl@0
|
74 |
set foo {}
|
sl@0
|
75 |
list [regexp ab*c abbbbc foo] $foo
|
sl@0
|
76 |
}
|
sl@0
|
77 |
} {1 abbbbc}
|
sl@0
|
78 |
test regexpComp-2.2 {getting substrings back from regexp} {
|
sl@0
|
79 |
evalInProc {
|
sl@0
|
80 |
set foo {}
|
sl@0
|
81 |
set f2 {}
|
sl@0
|
82 |
list [regexp a(b*)c abbbbc foo f2] $foo $f2
|
sl@0
|
83 |
}
|
sl@0
|
84 |
} {1 abbbbc bbbb}
|
sl@0
|
85 |
test regexpComp-2.3 {getting substrings back from regexp} {
|
sl@0
|
86 |
evalInProc {
|
sl@0
|
87 |
set foo {}
|
sl@0
|
88 |
set f2 {}
|
sl@0
|
89 |
list [regexp a(b*)(c) abbbbc foo f2] $foo $f2
|
sl@0
|
90 |
}
|
sl@0
|
91 |
} {1 abbbbc bbbb}
|
sl@0
|
92 |
test regexpComp-2.4 {getting substrings back from regexp} {
|
sl@0
|
93 |
evalInProc {
|
sl@0
|
94 |
set foo {}
|
sl@0
|
95 |
set f2 {}
|
sl@0
|
96 |
set f3 {}
|
sl@0
|
97 |
list [regexp a(b*)(c) abbbbc foo f2 f3] $foo $f2 $f3
|
sl@0
|
98 |
}
|
sl@0
|
99 |
} {1 abbbbc bbbb c}
|
sl@0
|
100 |
test regexpComp-2.5 {getting substrings back from regexp} {
|
sl@0
|
101 |
evalInProc {
|
sl@0
|
102 |
set foo {}; set f1 {}; set f2 {}; set f3 {}; set f4 {}; set f5 {};
|
sl@0
|
103 |
set f6 {}; set f7 {}; set f8 {}; set f9 {}; set fa {}; set fb {};
|
sl@0
|
104 |
list [regexp (1*)(2*)(3*)(4*)(5*)(6*)(7*)(8*)(9*)(a*)(b*) \
|
sl@0
|
105 |
12223345556789999aabbb \
|
sl@0
|
106 |
foo f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb] $foo $f1 $f2 $f3 $f4 $f5 \
|
sl@0
|
107 |
$f6 $f7 $f8 $f9 $fa $fb
|
sl@0
|
108 |
}
|
sl@0
|
109 |
} {1 12223345556789999aabbb 1 222 33 4 555 6 7 8 9999 aa bbb}
|
sl@0
|
110 |
test regexpComp-2.6 {getting substrings back from regexp} {
|
sl@0
|
111 |
evalInProc {
|
sl@0
|
112 |
set foo 2; set f2 2; set f3 2; set f4 2
|
sl@0
|
113 |
list [regexp (a)(b)? xay foo f2 f3 f4] $foo $f2 $f3 $f4
|
sl@0
|
114 |
}
|
sl@0
|
115 |
} {1 a a {} {}}
|
sl@0
|
116 |
test regexpComp-2.7 {getting substrings back from regexp} {
|
sl@0
|
117 |
evalInProc {
|
sl@0
|
118 |
set foo 1; set f2 1; set f3 1; set f4 1
|
sl@0
|
119 |
list [regexp (a)(b)?(c) xacy foo f2 f3 f4] $foo $f2 $f3 $f4
|
sl@0
|
120 |
}
|
sl@0
|
121 |
} {1 ac a {} c}
|
sl@0
|
122 |
test regexpComp-2.8 {getting substrings back from regexp} {
|
sl@0
|
123 |
evalInProc {
|
sl@0
|
124 |
set match {}
|
sl@0
|
125 |
list [regexp {^a*b} aaaab match] $match
|
sl@0
|
126 |
}
|
sl@0
|
127 |
} {1 aaaab}
|
sl@0
|
128 |
|
sl@0
|
129 |
test regexpComp-3.1 {-indices option to regexp} {
|
sl@0
|
130 |
evalInProc {
|
sl@0
|
131 |
set foo {}
|
sl@0
|
132 |
list [regexp -indices ab*c abbbbc foo] $foo
|
sl@0
|
133 |
}
|
sl@0
|
134 |
} {1 {0 5}}
|
sl@0
|
135 |
test regexpComp-3.2 {-indices option to regexp} {
|
sl@0
|
136 |
evalInProc {
|
sl@0
|
137 |
set foo {}
|
sl@0
|
138 |
set f2 {}
|
sl@0
|
139 |
list [regexp -indices a(b*)c abbbbc foo f2] $foo $f2
|
sl@0
|
140 |
}
|
sl@0
|
141 |
} {1 {0 5} {1 4}}
|
sl@0
|
142 |
test regexpComp-3.3 {-indices option to regexp} {
|
sl@0
|
143 |
evalInProc {
|
sl@0
|
144 |
set foo {}
|
sl@0
|
145 |
set f2 {}
|
sl@0
|
146 |
list [regexp -indices a(b*)(c) abbbbc foo f2] $foo $f2
|
sl@0
|
147 |
}
|
sl@0
|
148 |
} {1 {0 5} {1 4}}
|
sl@0
|
149 |
test regexpComp-3.4 {-indices option to regexp} {
|
sl@0
|
150 |
evalInProc {
|
sl@0
|
151 |
set foo {}
|
sl@0
|
152 |
set f2 {}
|
sl@0
|
153 |
set f3 {}
|
sl@0
|
154 |
list [regexp -indices a(b*)(c) abbbbc foo f2 f3] $foo $f2 $f3
|
sl@0
|
155 |
}
|
sl@0
|
156 |
} {1 {0 5} {1 4} {5 5}}
|
sl@0
|
157 |
test regexpComp-3.5 {-indices option to regexp} {
|
sl@0
|
158 |
evalInProc {
|
sl@0
|
159 |
set foo {}; set f1 {}; set f2 {}; set f3 {}; set f4 {}; set f5 {};
|
sl@0
|
160 |
set f6 {}; set f7 {}; set f8 {}; set f9 {}
|
sl@0
|
161 |
list [regexp -indices (1*)(2*)(3*)(4*)(5*)(6*)(7*)(8*)(9*) \
|
sl@0
|
162 |
12223345556789999 \
|
sl@0
|
163 |
foo f1 f2 f3 f4 f5 f6 f7 f8 f9] $foo $f1 $f2 $f3 $f4 $f5 \
|
sl@0
|
164 |
$f6 $f7 $f8 $f9
|
sl@0
|
165 |
}
|
sl@0
|
166 |
} {1 {0 16} {0 0} {1 3} {4 5} {6 6} {7 9} {10 10} {11 11} {12 12} {13 16}}
|
sl@0
|
167 |
test regexpComp-3.6 {getting substrings back from regexp} {
|
sl@0
|
168 |
evalInProc {
|
sl@0
|
169 |
set foo 2; set f2 2; set f3 2; set f4 2
|
sl@0
|
170 |
list [regexp -indices (a)(b)? xay foo f2 f3 f4] $foo $f2 $f3 $f4
|
sl@0
|
171 |
}
|
sl@0
|
172 |
} {1 {1 1} {1 1} {-1 -1} {-1 -1}}
|
sl@0
|
173 |
test regexpComp-3.7 {getting substrings back from regexp} {
|
sl@0
|
174 |
evalInProc {
|
sl@0
|
175 |
set foo 1; set f2 1; set f3 1; set f4 1
|
sl@0
|
176 |
list [regexp -indices (a)(b)?(c) xacy foo f2 f3 f4] $foo $f2 $f3 $f4
|
sl@0
|
177 |
}
|
sl@0
|
178 |
} {1 {1 2} {1 1} {-1 -1} {2 2}}
|
sl@0
|
179 |
|
sl@0
|
180 |
test regexpComp-4.1 {-nocase option to regexp} {
|
sl@0
|
181 |
evalInProc {
|
sl@0
|
182 |
regexp -nocase foo abcFOo
|
sl@0
|
183 |
}
|
sl@0
|
184 |
} 1
|
sl@0
|
185 |
test regexpComp-4.2 {-nocase option to regexp} {
|
sl@0
|
186 |
evalInProc {
|
sl@0
|
187 |
set f1 22
|
sl@0
|
188 |
set f2 33
|
sl@0
|
189 |
set f3 44
|
sl@0
|
190 |
list [regexp -nocase {a(b*)([xy]*)z} aBbbxYXxxZ22 f1 f2 f3] $f1 $f2 $f3
|
sl@0
|
191 |
}
|
sl@0
|
192 |
} {1 aBbbxYXxxZ Bbb xYXxx}
|
sl@0
|
193 |
test regexpComp-4.3 {-nocase option to regexp} {
|
sl@0
|
194 |
evalInProc {
|
sl@0
|
195 |
regexp -nocase FOo abcFOo
|
sl@0
|
196 |
}
|
sl@0
|
197 |
} 1
|
sl@0
|
198 |
set ::x abcdefghijklmnopqrstuvwxyz1234567890
|
sl@0
|
199 |
set ::x $x$x$x$x$x$x$x$x$x$x$x$x
|
sl@0
|
200 |
test regexpComp-4.4 {case conversion in regexp} {
|
sl@0
|
201 |
evalInProc {
|
sl@0
|
202 |
list [regexp -nocase $::x $::x foo] $foo
|
sl@0
|
203 |
}
|
sl@0
|
204 |
} "1 $x"
|
sl@0
|
205 |
catch {unset ::x}
|
sl@0
|
206 |
|
sl@0
|
207 |
test regexpComp-5.1 {exercise cache of compiled expressions} {
|
sl@0
|
208 |
evalInProc {
|
sl@0
|
209 |
regexp .*a b
|
sl@0
|
210 |
regexp .*b c
|
sl@0
|
211 |
regexp .*c d
|
sl@0
|
212 |
regexp .*d e
|
sl@0
|
213 |
regexp .*e f
|
sl@0
|
214 |
regexp .*a bbba
|
sl@0
|
215 |
}
|
sl@0
|
216 |
} 1
|
sl@0
|
217 |
test regexpComp-5.2 {exercise cache of compiled expressions} {
|
sl@0
|
218 |
evalInProc {
|
sl@0
|
219 |
regexp .*a b
|
sl@0
|
220 |
regexp .*b c
|
sl@0
|
221 |
regexp .*c d
|
sl@0
|
222 |
regexp .*d e
|
sl@0
|
223 |
regexp .*e f
|
sl@0
|
224 |
regexp .*b xxxb
|
sl@0
|
225 |
}
|
sl@0
|
226 |
} 1
|
sl@0
|
227 |
test regexpComp-5.3 {exercise cache of compiled expressions} {
|
sl@0
|
228 |
evalInProc {
|
sl@0
|
229 |
regexp .*a b
|
sl@0
|
230 |
regexp .*b c
|
sl@0
|
231 |
regexp .*c d
|
sl@0
|
232 |
regexp .*d e
|
sl@0
|
233 |
regexp .*e f
|
sl@0
|
234 |
regexp .*c yyyc
|
sl@0
|
235 |
}
|
sl@0
|
236 |
} 1
|
sl@0
|
237 |
test regexpComp-5.4 {exercise cache of compiled expressions} {
|
sl@0
|
238 |
evalInProc {
|
sl@0
|
239 |
regexp .*a b
|
sl@0
|
240 |
regexp .*b c
|
sl@0
|
241 |
regexp .*c d
|
sl@0
|
242 |
regexp .*d e
|
sl@0
|
243 |
regexp .*e f
|
sl@0
|
244 |
regexp .*d 1d
|
sl@0
|
245 |
}
|
sl@0
|
246 |
} 1
|
sl@0
|
247 |
test regexpComp-5.5 {exercise cache of compiled expressions} {
|
sl@0
|
248 |
evalInProc {
|
sl@0
|
249 |
regexp .*a b
|
sl@0
|
250 |
regexp .*b c
|
sl@0
|
251 |
regexp .*c d
|
sl@0
|
252 |
regexp .*d e
|
sl@0
|
253 |
regexp .*e f
|
sl@0
|
254 |
regexp .*e xe
|
sl@0
|
255 |
}
|
sl@0
|
256 |
} 1
|
sl@0
|
257 |
|
sl@0
|
258 |
test regexpComp-6.1 {regexp errors} {
|
sl@0
|
259 |
evalInProc {
|
sl@0
|
260 |
list [catch {regexp a} msg] $msg
|
sl@0
|
261 |
}
|
sl@0
|
262 |
} {1 {wrong # args: should be "regexp ?switches? exp string ?matchVar? ?subMatchVar subMatchVar ...?"}}
|
sl@0
|
263 |
test regexpComp-6.2 {regexp errors} {
|
sl@0
|
264 |
evalInProc {
|
sl@0
|
265 |
list [catch {regexp -nocase a} msg] $msg
|
sl@0
|
266 |
}
|
sl@0
|
267 |
} {1 {wrong # args: should be "regexp ?switches? exp string ?matchVar? ?subMatchVar subMatchVar ...?"}}
|
sl@0
|
268 |
test regexpComp-6.3 {regexp errors} {
|
sl@0
|
269 |
evalInProc {
|
sl@0
|
270 |
list [catch {regexp -gorp a} msg] $msg
|
sl@0
|
271 |
}
|
sl@0
|
272 |
} {1 {bad switch "-gorp": must be -all, -about, -indices, -inline, -expanded, -line, -linestop, -lineanchor, -nocase, -start, or --}}
|
sl@0
|
273 |
test regexpComp-6.4 {regexp errors} {
|
sl@0
|
274 |
evalInProc {
|
sl@0
|
275 |
list [catch {regexp a( b} msg] $msg
|
sl@0
|
276 |
}
|
sl@0
|
277 |
} {1 {couldn't compile regular expression pattern: parentheses () not balanced}}
|
sl@0
|
278 |
test regexpComp-6.5 {regexp errors} {
|
sl@0
|
279 |
evalInProc {
|
sl@0
|
280 |
list [catch {regexp a( b} msg] $msg
|
sl@0
|
281 |
}
|
sl@0
|
282 |
} {1 {couldn't compile regular expression pattern: parentheses () not balanced}}
|
sl@0
|
283 |
test regexpComp-6.6 {regexp errors} {
|
sl@0
|
284 |
evalInProc {
|
sl@0
|
285 |
list [catch {regexp a a f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1 f1} msg] $msg
|
sl@0
|
286 |
}
|
sl@0
|
287 |
} {0 1}
|
sl@0
|
288 |
test regexpComp-6.7 {regexp errors} {
|
sl@0
|
289 |
evalInProc {
|
sl@0
|
290 |
list [catch {regexp (x)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.) xyzzy} msg] $msg
|
sl@0
|
291 |
}
|
sl@0
|
292 |
} {0 0}
|
sl@0
|
293 |
test regexpComp-6.8 {regexp errors} {
|
sl@0
|
294 |
evalInProc {
|
sl@0
|
295 |
catch {unset f1}
|
sl@0
|
296 |
set f1 44
|
sl@0
|
297 |
list [catch {regexp abc abc f1(f2)} msg] $msg
|
sl@0
|
298 |
}
|
sl@0
|
299 |
} {1 {couldn't set variable "f1(f2)"}}
|
sl@0
|
300 |
test regexpComp-6.9 {regexp errors, -start bad int check} {
|
sl@0
|
301 |
evalInProc {
|
sl@0
|
302 |
list [catch {regexp -start bogus {^$} {}} msg] $msg
|
sl@0
|
303 |
}
|
sl@0
|
304 |
} {1 {expected integer but got "bogus"}}
|
sl@0
|
305 |
|
sl@0
|
306 |
test regexpComp-7.1 {basic regsub operation} {
|
sl@0
|
307 |
evalInProc {
|
sl@0
|
308 |
list [regsub aa+ xaxaaaxaa 111&222 foo] $foo
|
sl@0
|
309 |
}
|
sl@0
|
310 |
} {1 xax111aaa222xaa}
|
sl@0
|
311 |
test regexpComp-7.2 {basic regsub operation} {
|
sl@0
|
312 |
evalInProc {
|
sl@0
|
313 |
list [regsub aa+ aaaxaa &111 foo] $foo
|
sl@0
|
314 |
}
|
sl@0
|
315 |
} {1 aaa111xaa}
|
sl@0
|
316 |
test regexpComp-7.3 {basic regsub operation} {
|
sl@0
|
317 |
evalInProc {
|
sl@0
|
318 |
list [regsub aa+ xaxaaa 111& foo] $foo
|
sl@0
|
319 |
}
|
sl@0
|
320 |
} {1 xax111aaa}
|
sl@0
|
321 |
test regexpComp-7.4 {basic regsub operation} {
|
sl@0
|
322 |
evalInProc {
|
sl@0
|
323 |
list [regsub aa+ aaa 11&2&333 foo] $foo
|
sl@0
|
324 |
}
|
sl@0
|
325 |
} {1 11aaa2aaa333}
|
sl@0
|
326 |
test regexpComp-7.5 {basic regsub operation} {
|
sl@0
|
327 |
evalInProc {
|
sl@0
|
328 |
list [regsub aa+ xaxaaaxaa &2&333 foo] $foo
|
sl@0
|
329 |
}
|
sl@0
|
330 |
} {1 xaxaaa2aaa333xaa}
|
sl@0
|
331 |
test regexpComp-7.6 {basic regsub operation} {
|
sl@0
|
332 |
evalInProc {
|
sl@0
|
333 |
list [regsub aa+ xaxaaaxaa 1&22& foo] $foo
|
sl@0
|
334 |
}
|
sl@0
|
335 |
} {1 xax1aaa22aaaxaa}
|
sl@0
|
336 |
test regexpComp-7.7 {basic regsub operation} {
|
sl@0
|
337 |
evalInProc {
|
sl@0
|
338 |
list [regsub a(a+) xaxaaaxaa {1\122\1} foo] $foo
|
sl@0
|
339 |
}
|
sl@0
|
340 |
} {1 xax1aa22aaxaa}
|
sl@0
|
341 |
test regexpComp-7.8 {basic regsub operation} {
|
sl@0
|
342 |
evalInProc {
|
sl@0
|
343 |
list [regsub a(a+) xaxaaaxaa {1\\\122\1} foo] $foo
|
sl@0
|
344 |
}
|
sl@0
|
345 |
} "1 {xax1\\aa22aaxaa}"
|
sl@0
|
346 |
test regexpComp-7.9 {basic regsub operation} {
|
sl@0
|
347 |
evalInProc {
|
sl@0
|
348 |
list [regsub a(a+) xaxaaaxaa {1\\122\1} foo] $foo
|
sl@0
|
349 |
}
|
sl@0
|
350 |
} "1 {xax1\\122aaxaa}"
|
sl@0
|
351 |
test regexpComp-7.10 {basic regsub operation} {
|
sl@0
|
352 |
evalInProc {
|
sl@0
|
353 |
list [regsub a(a+) xaxaaaxaa {1\\&\1} foo] $foo
|
sl@0
|
354 |
}
|
sl@0
|
355 |
} "1 {xax1\\aaaaaxaa}"
|
sl@0
|
356 |
test regexpComp-7.11 {basic regsub operation} {
|
sl@0
|
357 |
evalInProc {
|
sl@0
|
358 |
list [regsub a(a+) xaxaaaxaa {1\&\1} foo] $foo
|
sl@0
|
359 |
}
|
sl@0
|
360 |
} {1 xax1&aaxaa}
|
sl@0
|
361 |
test regexpComp-7.12 {basic regsub operation} {
|
sl@0
|
362 |
evalInProc {
|
sl@0
|
363 |
list [regsub a(a+) xaxaaaxaa {\1\1\1\1&&} foo] $foo
|
sl@0
|
364 |
}
|
sl@0
|
365 |
} {1 xaxaaaaaaaaaaaaaaxaa}
|
sl@0
|
366 |
test regexpComp-7.13 {basic regsub operation} {
|
sl@0
|
367 |
evalInProc {
|
sl@0
|
368 |
set foo xxx
|
sl@0
|
369 |
list [regsub abc xyz 111 foo] $foo
|
sl@0
|
370 |
}
|
sl@0
|
371 |
} {0 xyz}
|
sl@0
|
372 |
test regexpComp-7.14 {basic regsub operation} {
|
sl@0
|
373 |
evalInProc {
|
sl@0
|
374 |
set foo xxx
|
sl@0
|
375 |
list [regsub ^ xyz "111 " foo] $foo
|
sl@0
|
376 |
}
|
sl@0
|
377 |
} {1 {111 xyz}}
|
sl@0
|
378 |
test regexpComp-7.15 {basic regsub operation} {
|
sl@0
|
379 |
evalInProc {
|
sl@0
|
380 |
set foo xxx
|
sl@0
|
381 |
list [regsub -- -foo abc-foodef "111 " foo] $foo
|
sl@0
|
382 |
}
|
sl@0
|
383 |
} {1 {abc111 def}}
|
sl@0
|
384 |
test regexpComp-7.16 {basic regsub operation} {
|
sl@0
|
385 |
evalInProc {
|
sl@0
|
386 |
set foo xxx
|
sl@0
|
387 |
list [regsub x "" y foo] $foo
|
sl@0
|
388 |
}
|
sl@0
|
389 |
} {0 {}}
|
sl@0
|
390 |
test regexpComp-7.17 {regsub utf compliance} {
|
sl@0
|
391 |
evalInProc {
|
sl@0
|
392 |
# if not UTF-8 aware, result is "0 1"
|
sl@0
|
393 |
set foo "xyz555ijka\u4e4ebpqr"
|
sl@0
|
394 |
regsub a\u4e4eb xyza\u4e4ebijka\u4e4ebpqr 555 bar
|
sl@0
|
395 |
list [string compare $foo $bar] [regexp 4 $bar]
|
sl@0
|
396 |
}
|
sl@0
|
397 |
} {0 0}
|
sl@0
|
398 |
|
sl@0
|
399 |
test regexpComp-8.1 {case conversion in regsub} {
|
sl@0
|
400 |
evalInProc {
|
sl@0
|
401 |
list [regsub -nocase a(a+) xaAAaAAay & foo] $foo
|
sl@0
|
402 |
}
|
sl@0
|
403 |
} {1 xaAAaAAay}
|
sl@0
|
404 |
test regexpComp-8.2 {case conversion in regsub} {
|
sl@0
|
405 |
evalInProc {
|
sl@0
|
406 |
list [regsub -nocase a(a+) xaAAaAAay & foo] $foo
|
sl@0
|
407 |
}
|
sl@0
|
408 |
} {1 xaAAaAAay}
|
sl@0
|
409 |
test regexpComp-8.3 {case conversion in regsub} {
|
sl@0
|
410 |
evalInProc {
|
sl@0
|
411 |
set foo 123
|
sl@0
|
412 |
list [regsub a(a+) xaAAaAAay & foo] $foo
|
sl@0
|
413 |
}
|
sl@0
|
414 |
} {0 xaAAaAAay}
|
sl@0
|
415 |
test regexpComp-8.4 {case conversion in regsub} {
|
sl@0
|
416 |
evalInProc {
|
sl@0
|
417 |
set foo 123
|
sl@0
|
418 |
list [regsub -nocase a CaDE b foo] $foo
|
sl@0
|
419 |
}
|
sl@0
|
420 |
} {1 CbDE}
|
sl@0
|
421 |
test regexpComp-8.5 {case conversion in regsub} {
|
sl@0
|
422 |
evalInProc {
|
sl@0
|
423 |
set foo 123
|
sl@0
|
424 |
list [regsub -nocase XYZ CxYzD b foo] $foo
|
sl@0
|
425 |
}
|
sl@0
|
426 |
} {1 CbD}
|
sl@0
|
427 |
test regexpComp-8.6 {case conversion in regsub} {
|
sl@0
|
428 |
evalInProc {
|
sl@0
|
429 |
set x abcdefghijklmnopqrstuvwxyz1234567890
|
sl@0
|
430 |
set x $x$x$x$x$x$x$x$x$x$x$x$x
|
sl@0
|
431 |
set foo 123
|
sl@0
|
432 |
list [regsub -nocase $x $x b foo] $foo
|
sl@0
|
433 |
}
|
sl@0
|
434 |
} {1 b}
|
sl@0
|
435 |
|
sl@0
|
436 |
test regexpComp-9.1 {-all option to regsub} {
|
sl@0
|
437 |
evalInProc {
|
sl@0
|
438 |
set foo 86
|
sl@0
|
439 |
list [regsub -all x+ axxxbxxcxdx |&| foo] $foo
|
sl@0
|
440 |
}
|
sl@0
|
441 |
} {4 a|xxx|b|xx|c|x|d|x|}
|
sl@0
|
442 |
test regexpComp-9.2 {-all option to regsub} {
|
sl@0
|
443 |
evalInProc {
|
sl@0
|
444 |
set foo 86
|
sl@0
|
445 |
list [regsub -nocase -all x+ aXxXbxxcXdx |&| foo] $foo
|
sl@0
|
446 |
}
|
sl@0
|
447 |
} {4 a|XxX|b|xx|c|X|d|x|}
|
sl@0
|
448 |
test regexpComp-9.3 {-all option to regsub} {
|
sl@0
|
449 |
evalInProc {
|
sl@0
|
450 |
set foo 86
|
sl@0
|
451 |
list [regsub x+ axxxbxxcxdx |&| foo] $foo
|
sl@0
|
452 |
}
|
sl@0
|
453 |
} {1 a|xxx|bxxcxdx}
|
sl@0
|
454 |
test regexpComp-9.4 {-all option to regsub} {
|
sl@0
|
455 |
evalInProc {
|
sl@0
|
456 |
set foo 86
|
sl@0
|
457 |
list [regsub -all bc axxxbxxcxdx |&| foo] $foo
|
sl@0
|
458 |
}
|
sl@0
|
459 |
} {0 axxxbxxcxdx}
|
sl@0
|
460 |
test regexpComp-9.5 {-all option to regsub} {
|
sl@0
|
461 |
evalInProc {
|
sl@0
|
462 |
set foo xxx
|
sl@0
|
463 |
list [regsub -all node "node node more" yy foo] $foo
|
sl@0
|
464 |
}
|
sl@0
|
465 |
} {2 {yy yy more}}
|
sl@0
|
466 |
test regexpComp-9.6 {-all option to regsub} {
|
sl@0
|
467 |
evalInProc {
|
sl@0
|
468 |
set foo xxx
|
sl@0
|
469 |
list [regsub -all ^ xxx 123 foo] $foo
|
sl@0
|
470 |
}
|
sl@0
|
471 |
} {1 123xxx}
|
sl@0
|
472 |
|
sl@0
|
473 |
test regexpComp-10.1 {expanded syntax in regsub} {
|
sl@0
|
474 |
evalInProc {
|
sl@0
|
475 |
set foo xxx
|
sl@0
|
476 |
list [regsub -expanded ". \#comment\n . \#comment2" abc def foo] $foo
|
sl@0
|
477 |
}
|
sl@0
|
478 |
} {1 defc}
|
sl@0
|
479 |
test regexpComp-10.2 {newline sensitivity in regsub} {
|
sl@0
|
480 |
evalInProc {
|
sl@0
|
481 |
set foo xxx
|
sl@0
|
482 |
list [regsub -line {^a.*b$} "dabc\naxyb\n" 123 foo] $foo
|
sl@0
|
483 |
}
|
sl@0
|
484 |
} "1 {dabc\n123\n}"
|
sl@0
|
485 |
test regexpComp-10.3 {newline sensitivity in regsub} {
|
sl@0
|
486 |
evalInProc {
|
sl@0
|
487 |
set foo xxx
|
sl@0
|
488 |
list [regsub -line {^a.*b$} "dabc\naxyb\nxb" 123 foo] $foo
|
sl@0
|
489 |
}
|
sl@0
|
490 |
} "1 {dabc\n123\nxb}"
|
sl@0
|
491 |
test regexpComp-10.4 {partial newline sensitivity in regsub} {
|
sl@0
|
492 |
evalInProc {
|
sl@0
|
493 |
set foo xxx
|
sl@0
|
494 |
list [regsub -lineanchor {^a.*b$} "da\naxyb\nxb" 123 foo] $foo
|
sl@0
|
495 |
}
|
sl@0
|
496 |
} "1 {da\n123}"
|
sl@0
|
497 |
test regexpComp-10.5 {inverse partial newline sensitivity in regsub} {
|
sl@0
|
498 |
evalInProc {
|
sl@0
|
499 |
set foo xxx
|
sl@0
|
500 |
list [regsub -linestop {a.*b} "da\nbaxyb\nxb" 123 foo] $foo
|
sl@0
|
501 |
}
|
sl@0
|
502 |
} "1 {da\nb123\nxb}"
|
sl@0
|
503 |
|
sl@0
|
504 |
test regexpComp-11.1 {regsub errors} {
|
sl@0
|
505 |
evalInProc {
|
sl@0
|
506 |
list [catch {regsub a b} msg] $msg
|
sl@0
|
507 |
}
|
sl@0
|
508 |
} {1 {wrong # args: should be "regsub ?switches? exp string subSpec ?varName?"}}
|
sl@0
|
509 |
test regexpComp-11.2 {regsub errors} {
|
sl@0
|
510 |
evalInProc {
|
sl@0
|
511 |
list [catch {regsub -nocase a b} msg] $msg
|
sl@0
|
512 |
}
|
sl@0
|
513 |
} {1 {wrong # args: should be "regsub ?switches? exp string subSpec ?varName?"}}
|
sl@0
|
514 |
test regexpComp-11.3 {regsub errors} {
|
sl@0
|
515 |
evalInProc {
|
sl@0
|
516 |
list [catch {regsub -nocase -all a b} msg] $msg
|
sl@0
|
517 |
}
|
sl@0
|
518 |
} {1 {wrong # args: should be "regsub ?switches? exp string subSpec ?varName?"}}
|
sl@0
|
519 |
test regexpComp-11.4 {regsub errors} {
|
sl@0
|
520 |
evalInProc {
|
sl@0
|
521 |
list [catch {regsub a b c d e f} msg] $msg
|
sl@0
|
522 |
}
|
sl@0
|
523 |
} {1 {wrong # args: should be "regsub ?switches? exp string subSpec ?varName?"}}
|
sl@0
|
524 |
test regexpComp-11.5 {regsub errors} {
|
sl@0
|
525 |
evalInProc {
|
sl@0
|
526 |
list [catch {regsub -gorp a b c} msg] $msg
|
sl@0
|
527 |
}
|
sl@0
|
528 |
} {1 {bad switch "-gorp": must be -all, -nocase, -expanded, -line, -linestop, -lineanchor, -start, or --}}
|
sl@0
|
529 |
test regexpComp-11.6 {regsub errors} {
|
sl@0
|
530 |
evalInProc {
|
sl@0
|
531 |
list [catch {regsub -nocase a( b c d} msg] $msg
|
sl@0
|
532 |
}
|
sl@0
|
533 |
} {1 {couldn't compile regular expression pattern: parentheses () not balanced}}
|
sl@0
|
534 |
test regexpComp-11.7 {regsub errors} {
|
sl@0
|
535 |
evalInProc {
|
sl@0
|
536 |
catch {unset f1}
|
sl@0
|
537 |
set f1 44
|
sl@0
|
538 |
list [catch {regsub -nocase aaa aaa xxx f1(f2)} msg] $msg
|
sl@0
|
539 |
}
|
sl@0
|
540 |
} {1 {couldn't set variable "f1(f2)"}}
|
sl@0
|
541 |
test regexpComp-11.8 {regsub errors, -start bad int check} {
|
sl@0
|
542 |
evalInProc {
|
sl@0
|
543 |
list [catch {regsub -start bogus pattern string rep var} msg] $msg
|
sl@0
|
544 |
}
|
sl@0
|
545 |
} {1 {expected integer but got "bogus"}}
|
sl@0
|
546 |
|
sl@0
|
547 |
# This test crashes on the Mac unless you increase the Stack Space to about 1
|
sl@0
|
548 |
# Meg. This is probably bigger than most users want...
|
sl@0
|
549 |
# 8.2.3 regexp reduced stack space requirements, but this should be
|
sl@0
|
550 |
# tested again
|
sl@0
|
551 |
test regexpComp-12.1 {Tcl_RegExpExec: large number of subexpressions} {macCrash} {
|
sl@0
|
552 |
evalInProc {
|
sl@0
|
553 |
list [regexp (.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.) abcdefghijklmnopqrstuvwxyz all a b c d e f g h i j k l m n o p q r s t u v w x y z] $all $a $b $c $d $e $f $g $h $i $j $k $l $m $n $o $p $q $r $s $t $u $v $w $x $y $z
|
sl@0
|
554 |
}
|
sl@0
|
555 |
} {1 abcdefghijklmnopqrstuvwxyz a b c d e f g h i j k l m n o p q r s t u v w x y z}
|
sl@0
|
556 |
|
sl@0
|
557 |
test regexpComp-13.1 {regsub of a very large string} {
|
sl@0
|
558 |
# This test is designed to stress the memory subsystem in order
|
sl@0
|
559 |
# to catch Bug #933. It only fails if the Tcl memory allocator
|
sl@0
|
560 |
# is in use.
|
sl@0
|
561 |
|
sl@0
|
562 |
set line {BEGIN_TABLE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; END_TABLE}
|
sl@0
|
563 |
set filedata [string repeat $line 200]
|
sl@0
|
564 |
for {set i 1} {$i<10} {incr i} {
|
sl@0
|
565 |
regsub -all "BEGIN_TABLE " $filedata "" newfiledata
|
sl@0
|
566 |
}
|
sl@0
|
567 |
set x done
|
sl@0
|
568 |
} {done}
|
sl@0
|
569 |
|
sl@0
|
570 |
test regexpComp-14.1 {CompileRegexp: regexp cache} {
|
sl@0
|
571 |
evalInProc {
|
sl@0
|
572 |
regexp .*a b
|
sl@0
|
573 |
regexp .*b c
|
sl@0
|
574 |
regexp .*c d
|
sl@0
|
575 |
regexp .*d e
|
sl@0
|
576 |
regexp .*e f
|
sl@0
|
577 |
set x .
|
sl@0
|
578 |
append x *a
|
sl@0
|
579 |
regexp $x bbba
|
sl@0
|
580 |
}
|
sl@0
|
581 |
} 1
|
sl@0
|
582 |
test regexpComp-14.2 {CompileRegexp: regexp cache, different flags} {
|
sl@0
|
583 |
evalInProc {
|
sl@0
|
584 |
regexp .*a b
|
sl@0
|
585 |
regexp .*b c
|
sl@0
|
586 |
regexp .*c d
|
sl@0
|
587 |
regexp .*d e
|
sl@0
|
588 |
regexp .*e f
|
sl@0
|
589 |
set x .
|
sl@0
|
590 |
append x *a
|
sl@0
|
591 |
regexp -nocase $x bbba
|
sl@0
|
592 |
}
|
sl@0
|
593 |
} 1
|
sl@0
|
594 |
|
sl@0
|
595 |
testConstraint exec [llength [info commands exec]]
|
sl@0
|
596 |
test regexpComp-14.3 {CompileRegexp: regexp cache, empty regexp and empty cache} -constraints {
|
sl@0
|
597 |
exec
|
sl@0
|
598 |
} -setup {
|
sl@0
|
599 |
set junk [makeFile {puts [regexp {} foo]} junk.tcl]
|
sl@0
|
600 |
} -body {
|
sl@0
|
601 |
exec [interpreter] $junk
|
sl@0
|
602 |
} -cleanup {
|
sl@0
|
603 |
removeFile junk.tcl
|
sl@0
|
604 |
} -result 1
|
sl@0
|
605 |
|
sl@0
|
606 |
test regexpComp-15.1 {regexp -start} {
|
sl@0
|
607 |
catch {unset x}
|
sl@0
|
608 |
list [regexp -start -10 {\d} 1abc2de3 x] $x
|
sl@0
|
609 |
} {1 1}
|
sl@0
|
610 |
test regexpComp-15.2 {regexp -start} {
|
sl@0
|
611 |
catch {unset x}
|
sl@0
|
612 |
list [regexp -start 2 {\d} 1abc2de3 x] $x
|
sl@0
|
613 |
} {1 2}
|
sl@0
|
614 |
test regexpComp-15.3 {regexp -start} {
|
sl@0
|
615 |
catch {unset x}
|
sl@0
|
616 |
list [regexp -start 4 {\d} 1abc2de3 x] $x
|
sl@0
|
617 |
} {1 2}
|
sl@0
|
618 |
test regexpComp-15.4 {regexp -start} {
|
sl@0
|
619 |
catch {unset x}
|
sl@0
|
620 |
list [regexp -start 5 {\d} 1abc2de3 x] $x
|
sl@0
|
621 |
} {1 3}
|
sl@0
|
622 |
test regexpComp-15.5 {regexp -start, over end of string} {
|
sl@0
|
623 |
catch {unset x}
|
sl@0
|
624 |
list [regexp -start [string length 1abc2de3] {\d} 1abc2de3 x] [info exists x]
|
sl@0
|
625 |
} {0 0}
|
sl@0
|
626 |
test regexpComp-15.6 {regexp -start, loss of ^$ behavior} {
|
sl@0
|
627 |
list [regexp -start 2 {^$} {}]
|
sl@0
|
628 |
} {0}
|
sl@0
|
629 |
|
sl@0
|
630 |
test regexpComp-16.1 {regsub -start} {
|
sl@0
|
631 |
catch {unset x}
|
sl@0
|
632 |
list [regsub -all -start 2 {\d} a1b2c3d4e5 {/&} x] $x
|
sl@0
|
633 |
} {4 a1b/2c/3d/4e/5}
|
sl@0
|
634 |
test regexpComp-16.2 {regsub -start} {
|
sl@0
|
635 |
catch {unset x}
|
sl@0
|
636 |
list [regsub -all -start -25 {z} hello {/&} x] $x
|
sl@0
|
637 |
} {0 hello}
|
sl@0
|
638 |
test regexpComp-16.3 {regsub -start} {
|
sl@0
|
639 |
catch {unset x}
|
sl@0
|
640 |
list [regsub -all -start 3 {z} hello {/&} x] $x
|
sl@0
|
641 |
} {0 hello}
|
sl@0
|
642 |
test regexpComp-16.4 {regsub -start, \A behavior} {
|
sl@0
|
643 |
set out {}
|
sl@0
|
644 |
lappend out [regsub -start 0 -all {\A(\w)} {abcde} {/\1} x] $x
|
sl@0
|
645 |
lappend out [regsub -start 2 -all {\A(\w)} {abcde} {/\1} x] $x
|
sl@0
|
646 |
} {5 /a/b/c/d/e 3 ab/c/d/e}
|
sl@0
|
647 |
|
sl@0
|
648 |
test regexpComp-17.1 {regexp -inline} {
|
sl@0
|
649 |
regexp -inline b ababa
|
sl@0
|
650 |
} {b}
|
sl@0
|
651 |
test regexpComp-17.2 {regexp -inline} {
|
sl@0
|
652 |
regexp -inline (b) ababa
|
sl@0
|
653 |
} {b b}
|
sl@0
|
654 |
test regexpComp-17.3 {regexp -inline -indices} {
|
sl@0
|
655 |
regexp -inline -indices (b) ababa
|
sl@0
|
656 |
} {{1 1} {1 1}}
|
sl@0
|
657 |
test regexpComp-17.4 {regexp -inline} {
|
sl@0
|
658 |
regexp -inline {\w(\d+)\w} " hello 23 there456def "
|
sl@0
|
659 |
} {e456d 456}
|
sl@0
|
660 |
test regexpComp-17.5 {regexp -inline no matches} {
|
sl@0
|
661 |
regexp -inline {\w(\d+)\w} ""
|
sl@0
|
662 |
} {}
|
sl@0
|
663 |
test regexpComp-17.6 {regexp -inline no matches} {
|
sl@0
|
664 |
regexp -inline hello goodbye
|
sl@0
|
665 |
} {}
|
sl@0
|
666 |
test regexpComp-17.7 {regexp -inline, no matchvars allowed} {
|
sl@0
|
667 |
list [catch {regexp -inline b abc match} msg] $msg
|
sl@0
|
668 |
} {1 {regexp match variables not allowed when using -inline}}
|
sl@0
|
669 |
|
sl@0
|
670 |
test regexpComp-18.1 {regexp -all} {
|
sl@0
|
671 |
regexp -all b bbbbb
|
sl@0
|
672 |
} {5}
|
sl@0
|
673 |
test regexpComp-18.2 {regexp -all} {
|
sl@0
|
674 |
regexp -all b abababbabaaaaaaaaaab
|
sl@0
|
675 |
} {6}
|
sl@0
|
676 |
test regexpComp-18.3 {regexp -all -inline} {
|
sl@0
|
677 |
regexp -all -inline b abababbabaaaaaaaaaab
|
sl@0
|
678 |
} {b b b b b b}
|
sl@0
|
679 |
test regexpComp-18.4 {regexp -all -inline} {
|
sl@0
|
680 |
regexp -all -inline {\w(\w)} abcdefg
|
sl@0
|
681 |
} {ab b cd d ef f}
|
sl@0
|
682 |
test regexpComp-18.5 {regexp -all -inline} {
|
sl@0
|
683 |
regexp -all -inline {\w(\w)$} abcdefg
|
sl@0
|
684 |
} {fg g}
|
sl@0
|
685 |
test regexpComp-18.6 {regexp -all -inline} {
|
sl@0
|
686 |
regexp -all -inline {\d+} 10:20:30:40
|
sl@0
|
687 |
} {10 20 30 40}
|
sl@0
|
688 |
test regexpComp-18.7 {regexp -all -inline} {
|
sl@0
|
689 |
list [catch {regexp -all -inline b abc match} msg] $msg
|
sl@0
|
690 |
} {1 {regexp match variables not allowed when using -inline}}
|
sl@0
|
691 |
test regexpComp-18.8 {regexp -all} {
|
sl@0
|
692 |
# This should not cause an infinite loop
|
sl@0
|
693 |
regexp -all -inline {a*} a
|
sl@0
|
694 |
} {a}
|
sl@0
|
695 |
test regexpComp-18.9 {regexp -all} {
|
sl@0
|
696 |
# Yes, the expected result is {a {}}. Here's why:
|
sl@0
|
697 |
# Start at index 0; a* matches the "a" there then stops.
|
sl@0
|
698 |
# Go to index 1; a* matches the lambda (or {}) there then stops. Recall
|
sl@0
|
699 |
# that a* matches zero or more "a"'s; thus it matches the string "b", as
|
sl@0
|
700 |
# there are zero or more "a"'s there.
|
sl@0
|
701 |
# Go to index 2; this is past the end of the string, so stop.
|
sl@0
|
702 |
regexp -all -inline {a*} ab
|
sl@0
|
703 |
} {a {}}
|
sl@0
|
704 |
test regexpComp-18.10 {regexp -all} {
|
sl@0
|
705 |
# Yes, the expected result is {a {} a}. Here's why:
|
sl@0
|
706 |
# Start at index 0; a* matches the "a" there then stops.
|
sl@0
|
707 |
# Go to index 1; a* matches the lambda (or {}) there then stops. Recall
|
sl@0
|
708 |
# that a* matches zero or more "a"'s; thus it matches the string "b", as
|
sl@0
|
709 |
# there are zero or more "a"'s there.
|
sl@0
|
710 |
# Go to index 2; a* matches the "a" there then stops.
|
sl@0
|
711 |
# Go to index 3; this is past the end of the string, so stop.
|
sl@0
|
712 |
regexp -all -inline {a*} aba
|
sl@0
|
713 |
} {a {} a}
|
sl@0
|
714 |
test regexpComp-18.11 {regexp -all} {
|
sl@0
|
715 |
evalInProc {
|
sl@0
|
716 |
regexp -all -inline {^a} aaaa
|
sl@0
|
717 |
}
|
sl@0
|
718 |
} {a}
|
sl@0
|
719 |
test regexpComp-18.12 {regexp -all -inline -indices} {
|
sl@0
|
720 |
evalInProc {
|
sl@0
|
721 |
regexp -all -inline -indices a(b(c)d|e(f)g)h abcdhaefgh
|
sl@0
|
722 |
}
|
sl@0
|
723 |
} {{0 4} {1 3} {2 2} {-1 -1} {5 9} {6 8} {-1 -1} {7 7}}
|
sl@0
|
724 |
|
sl@0
|
725 |
test regexpComp-19.1 {regsub null replacement} {
|
sl@0
|
726 |
evalInProc {
|
sl@0
|
727 |
regsub -all {@} {@hel@lo@} "\0a\0" result
|
sl@0
|
728 |
list $result [string length $result]
|
sl@0
|
729 |
}
|
sl@0
|
730 |
} "\0a\0hel\0a\0lo\0a\0 14"
|
sl@0
|
731 |
|
sl@0
|
732 |
test regexpComp-20.1 {regsub shared object shimmering} {
|
sl@0
|
733 |
evalInProc {
|
sl@0
|
734 |
# Bug #461322
|
sl@0
|
735 |
set a abcdefghijklmnopqurstuvwxyz
|
sl@0
|
736 |
set b $a
|
sl@0
|
737 |
set c abcdefghijklmnopqurstuvwxyz0123456789
|
sl@0
|
738 |
regsub $a $c $b d
|
sl@0
|
739 |
list $d [string length $d] [string bytelength $d]
|
sl@0
|
740 |
}
|
sl@0
|
741 |
} [list abcdefghijklmnopqurstuvwxyz0123456789 37 37]
|
sl@0
|
742 |
test regexpComp-20.2 {regsub shared object shimmering with -about} {
|
sl@0
|
743 |
evalInProc {
|
sl@0
|
744 |
eval regexp -about abc
|
sl@0
|
745 |
}
|
sl@0
|
746 |
} {0 {}}
|
sl@0
|
747 |
|
sl@0
|
748 |
test regexpComp-21.1 {regexp command compiling tests} {
|
sl@0
|
749 |
evalInProc {
|
sl@0
|
750 |
regexp foo bar
|
sl@0
|
751 |
}
|
sl@0
|
752 |
} 0
|
sl@0
|
753 |
test regexpComp-21.2 {regexp command compiling tests} {
|
sl@0
|
754 |
evalInProc {
|
sl@0
|
755 |
regexp {^foo$} dogfood
|
sl@0
|
756 |
}
|
sl@0
|
757 |
} 0
|
sl@0
|
758 |
test regexpComp-21.3 {regexp command compiling tests} {
|
sl@0
|
759 |
evalInProc {
|
sl@0
|
760 |
set a foo
|
sl@0
|
761 |
regexp {^foo$} $a
|
sl@0
|
762 |
}
|
sl@0
|
763 |
} 1
|
sl@0
|
764 |
test regexpComp-21.4 {regexp command compiling tests} {
|
sl@0
|
765 |
evalInProc {
|
sl@0
|
766 |
regexp foo dogfood
|
sl@0
|
767 |
}
|
sl@0
|
768 |
} 1
|
sl@0
|
769 |
test regexpComp-21.5 {regexp command compiling tests} {
|
sl@0
|
770 |
evalInProc {
|
sl@0
|
771 |
regexp -nocase FOO dogfod
|
sl@0
|
772 |
}
|
sl@0
|
773 |
} 0
|
sl@0
|
774 |
test regexpComp-21.6 {regexp command compiling tests} {
|
sl@0
|
775 |
evalInProc {
|
sl@0
|
776 |
regexp -n foo dogfoOd
|
sl@0
|
777 |
}
|
sl@0
|
778 |
} 1
|
sl@0
|
779 |
test regexpComp-21.7 {regexp command compiling tests} {
|
sl@0
|
780 |
evalInProc {
|
sl@0
|
781 |
regexp -no -- FoO dogfood
|
sl@0
|
782 |
}
|
sl@0
|
783 |
} 1
|
sl@0
|
784 |
test regexpComp-21.8 {regexp command compiling tests} {
|
sl@0
|
785 |
evalInProc {
|
sl@0
|
786 |
regexp -- foo dogfod
|
sl@0
|
787 |
}
|
sl@0
|
788 |
} 0
|
sl@0
|
789 |
test regexpComp-21.9 {regexp command compiling tests} {
|
sl@0
|
790 |
evalInProc {
|
sl@0
|
791 |
list [catch {regexp -- -nocase foo dogfod} msg] $msg
|
sl@0
|
792 |
}
|
sl@0
|
793 |
} {0 0}
|
sl@0
|
794 |
test regexpComp-21.10 {regexp command compiling tests} {
|
sl@0
|
795 |
evalInProc {
|
sl@0
|
796 |
list [regsub -all "" foo bar str] $str
|
sl@0
|
797 |
}
|
sl@0
|
798 |
} {3 barfbarobaro}
|
sl@0
|
799 |
test regexpComp-21.11 {regexp command compiling tests} {
|
sl@0
|
800 |
evalInProc {
|
sl@0
|
801 |
list [regsub -all "" "" bar str] $str
|
sl@0
|
802 |
}
|
sl@0
|
803 |
} {0 {}}
|
sl@0
|
804 |
|
sl@0
|
805 |
set i 0
|
sl@0
|
806 |
foreach {str exp result} {
|
sl@0
|
807 |
foo ^foo 1
|
sl@0
|
808 |
foobar ^foobar$ 1
|
sl@0
|
809 |
foobar bar$ 1
|
sl@0
|
810 |
foobar ^$ 0
|
sl@0
|
811 |
"" ^$ 1
|
sl@0
|
812 |
anything $ 1
|
sl@0
|
813 |
anything ^.*$ 1
|
sl@0
|
814 |
anything ^.*a$ 0
|
sl@0
|
815 |
anything ^.*a.*$ 1
|
sl@0
|
816 |
anything ^.*.*$ 1
|
sl@0
|
817 |
anything ^.*..*$ 1
|
sl@0
|
818 |
anything ^.*b$ 0
|
sl@0
|
819 |
anything ^a.*$ 1
|
sl@0
|
820 |
} {
|
sl@0
|
821 |
test regexpComp-22.[incr i] {regexp command compiling tests} \
|
sl@0
|
822 |
[subst {evalInProc {set a "$str"; regexp {$exp} \$a}}] $result
|
sl@0
|
823 |
}
|
sl@0
|
824 |
|
sl@0
|
825 |
# cleanup
|
sl@0
|
826 |
::tcltest::cleanupTests
|
sl@0
|
827 |
return
|