Debian Codegraph @

tests/regexp.test

raw
1 # Commands covered: regexp, regsub
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) 1998 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 if {"::tcltest" ni [namespace children]} {
15 package require tcltest 2.5
16 namespace import -force ::tcltest::*
17 }
18
19 unset -nocomplain foo
20
21 testConstraint exec [llength [info commands exec]]
22
23 test regexp-1.1 {basic regexp operation} {
24 regexp ab*c abbbc
25 } 1
26 test regexp-1.2 {basic regexp operation} {
27 regexp ab*c ac
28 } 1
29 test regexp-1.3 {basic regexp operation} {
30 regexp ab*c ab
31 } 0
32 test regexp-1.4 {basic regexp operation} {
33 regexp -- -gorp abc-gorpxxx
34 } 1
35 test regexp-1.5 {basic regexp operation} {
36 regexp {^([^ ]*)[ ]*([^ ]*)} "" a
37 } 1
38 test regexp-1.6 {basic regexp operation} {
39 list [catch {regexp {} abc} msg] $msg
40 } {0 1}
41 test regexp-1.7 {regexp utf compliance} {
42 # if not UTF-8 aware, result is "0 1"
43 set foo "\u4e4eb q"
44 regexp "\u4e4eb q" "a\u4e4eb qw\u5e4e\x4e wq" bar
45 list [string compare $foo $bar] [regexp 4 $bar]
46 } {0 0}
47 test regexp-1.8 {regexp ***= metasyntax} {
48 regexp -- "***=o" "aeiou"
49 } 1
50 test regexp-1.9 {regexp ***= metasyntax} {
51 set string "aeiou"
52 regexp -- "***=o" $string
53 } 1
54 test regexp-1.10 {regexp ***= metasyntax} {
55 set string "aeiou"
56 set re "***=o"
57 regexp -- $re $string
58 } 1
59 test regexp-1.11 {regexp ***= metasyntax} {
60 regexp -- "***=y" "aeiou"
61 } 0
62 test regexp-1.12 {regexp ***= metasyntax} {
63 set string "aeiou"
64 regexp -- "***=y" $string
65 } 0
66 test regexp-1.13 {regexp ***= metasyntax} {
67 set string "aeiou"
68 set re "***=y"
69 regexp -- $re $string
70 } 0
71
72 test regexp-2.1 {getting substrings back from regexp} {
73 set foo {}
74 list [regexp ab*c abbbbc foo] $foo
75 } {1 abbbbc}
76 test regexp-2.2 {getting substrings back from regexp} {
77 set foo {}
78 set f2 {}
79 list [regexp a(b*)c abbbbc foo f2] $foo $f2
80 } {1 abbbbc bbbb}
81 test regexp-2.3 {getting substrings back from regexp} {
82 set foo {}
83 set f2 {}
84 list [regexp a(b*)(c) abbbbc foo f2] $foo $f2
85 } {1 abbbbc bbbb}
86 test regexp-2.4 {getting substrings back from regexp} {
87 set foo {}
88 set f2 {}
89 set f3 {}
90 list [regexp a(b*)(c) abbbbc foo f2 f3] $foo $f2 $f3
91 } {1 abbbbc bbbb c}
92 test regexp-2.5 {getting substrings back from regexp} {
93 set foo {}; set f1 {}; set f2 {}; set f3 {}; set f4 {}; set f5 {};
94 set f6 {}; set f7 {}; set f8 {}; set f9 {}; set fa {}; set fb {};
95 list [regexp (1*)(2*)(3*)(4*)(5*)(6*)(7*)(8*)(9*)(a*)(b*) \
96 12223345556789999aabbb \
97 foo f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb] $foo $f1 $f2 $f3 $f4 $f5 \
98 $f6 $f7 $f8 $f9 $fa $fb
99 } {1 12223345556789999aabbb 1 222 33 4 555 6 7 8 9999 aa bbb}
100 test regexp-2.6 {getting substrings back from regexp} {
101 set foo 2; set f2 2; set f3 2; set f4 2
102 list [regexp (a)(b)? xay foo f2 f3 f4] $foo $f2 $f3 $f4
103 } {1 a a {} {}}
104 test regexp-2.7 {getting substrings back from regexp} {
105 set foo 1; set f2 1; set f3 1; set f4 1
106 list [regexp (a)(b)?(c) xacy foo f2 f3 f4] $foo $f2 $f3 $f4
107 } {1 ac a {} c}
108 test regexp-2.8 {getting substrings back from regexp} {
109 set match {}
110 list [regexp {^a*b} aaaab match] $match
111 } {1 aaaab}
112 test regexp-2.9 {getting substrings back from regexp} {
113 set foo {}
114 set f2 {}
115 list [regexp f\352te(b*)c f\352tebbbbc foo f2] $foo $f2
116 } [list 1 f\352tebbbbc bbbb]
117 test regexp-2.10 {getting substrings back from regexp} {
118 set foo {}
119 set f2 {}
120 list [regexp f\352te(b*)c eff\352tebbbbc foo f2] $foo $f2
121 } [list 1 f\352tebbbbc bbbb]
122 test regexp-2.11 {non-capturing subgroup} {
123 set foo {}
124 set f2 {}
125 list [regexp {str(?:a+)} straa foo f2] $foo $f2
126 } [list 1 straa {}]
127 test regexp-2.12 {non-capturing subgroup with -inline} {
128 regexp -inline {str(?:a+)} straa
129 } {straa}
130 test regexp-2.13 {non-capturing and capturing subgroups} {
131 set foo {}
132 set f2 {}
133 set f3 {}
134 list [regexp {str(?:a+)(c+)} straacc foo f2 f3] $foo $f2 $f3
135 } [list 1 straacc cc {}]
136 test regexp-2.14 {non-capturing and capturing subgroups} {
137 regexp -inline {str(?:a+)(c+)} straacc
138 } {straacc cc}
139 test regexp-2.15 {getting substrings back from regexp} {
140 set foo NA
141 set f2 NA
142 list [regexp {str(?:a+)} straa foo f2] $foo $f2
143 } [list 1 straa {}]
144
145 test regexp-3.1 {-indices option to regexp} {
146 set foo {}
147 list [regexp -indices ab*c abbbbc foo] $foo
148 } {1 {0 5}}
149 test regexp-3.2 {-indices option to regexp} {
150 set foo {}
151 set f2 {}
152 list [regexp -indices a(b*)c abbbbc foo f2] $foo $f2
153 } {1 {0 5} {1 4}}
154 test regexp-3.3 {-indices option to regexp} {
155 set foo {}
156 set f2 {}
157 list [regexp -indices a(b*)(c) abbbbc foo f2] $foo $f2
158 } {1 {0 5} {1 4}}
159 test regexp-3.4 {-indices option to regexp} {
160 set foo {}
161 set f2 {}
162 set f3 {}
163 list [regexp -indices a(b*)(c) abbbbc foo f2 f3] $foo $f2 $f3
164 } {1 {0 5} {1 4} {5 5}}
165 test regexp-3.5 {-indices option to regexp} {
166 set foo {}; set f1 {}; set f2 {}; set f3 {}; set f4 {}; set f5 {};
167 set f6 {}; set f7 {}; set f8 {}; set f9 {}
168 list [regexp -indices (1*)(2*)(3*)(4*)(5*)(6*)(7*)(8*)(9*) \
169 12223345556789999 \
170 foo f1 f2 f3 f4 f5 f6 f7 f8 f9] $foo $f1 $f2 $f3 $f4 $f5 \
171 $f6 $f7 $f8 $f9
172 } {1 {0 16} {0 0} {1 3} {4 5} {6 6} {7 9} {10 10} {11 11} {12 12} {13 16}}
173 test regexp-3.6 {getting substrings back from regexp} {
174 set foo 2; set f2 2; set f3 2; set f4 2
175 list [regexp -indices (a)(b)? xay foo f2 f3 f4] $foo $f2 $f3 $f4
176 } {1 {1 1} {1 1} {-1 -1} {-1 -1}}
177 test regexp-3.7 {getting substrings back from regexp} {
178 set foo 1; set f2 1; set f3 1; set f4 1
179 list [regexp -indices (a)(b)?(c) xacy foo f2 f3 f4] $foo $f2 $f3 $f4
180 } {1 {1 2} {1 1} {-1 -1} {2 2}}
181 test regexp-3.8a {-indices by multi-byte utf-8} {
182 regexp -inline -indices {(\w+)-(\w+)} \
183 "gr\u00FC\u00DF-\u043F\u0440\u0438\u0432\u0435\u0442"
184 } {{0 10} {0 3} {5 10}}
185 test regexp-3.8b {-indices by multi-byte utf-8, from -start position} {
186 list\
187 [regexp -inline -indices -start 3 {(\w+)-(\w+)} \
188 "gr\u00FC\u00DF-\u043F\u0440\u0438\u0432\u0435\u0442"] \
189 [regexp -inline -indices -start 4 {(\w+)-(\w+)} \
190 "gr\u00FC\u00DF-\u043F\u0440\u0438\u0432\u0435\u0442"]
191 } {{{3 10} {3 3} {5 10}} {}}
192
193 test regexp-4.1 {-nocase option to regexp} {
194 regexp -nocase foo abcFOo
195 } 1
196 test regexp-4.2 {-nocase option to regexp} {
197 set f1 22
198 set f2 33
199 set f3 44
200 list [regexp -nocase {a(b*)([xy]*)z} aBbbxYXxxZ22 f1 f2 f3] $f1 $f2 $f3
201 } {1 aBbbxYXxxZ Bbb xYXxx}
202 test regexp-4.3 {-nocase option to regexp} {
203 regexp -nocase FOo abcFOo
204 } 1
205 set x abcdefghijklmnopqrstuvwxyz1234567890
206 set x $x$x$x$x$x$x$x$x$x$x$x$x
207 test regexp-4.4 {case conversion in regexp} {
208 list [regexp -nocase $x $x foo] $foo
209 } "1 $x"
210 unset -nocomplain x
211
212 test regexp-5.1 {exercise cache of compiled expressions} {
213 regexp .*a b
214 regexp .*b c
215 regexp .*c d
216 regexp .*d e
217 regexp .*e f
218 regexp .*a bbba
219 } 1
220 test regexp-5.2 {exercise cache of compiled expressions} {
221 regexp .*a b
222 regexp .*b c
223 regexp .*c d
224 regexp .*d e
225 regexp .*e f
226 regexp .*b xxxb
227 } 1
228 test regexp-5.3 {exercise cache of compiled expressions} {
229 regexp .*a b
230 regexp .*b c
231 regexp .*c d
232 regexp .*d e
233 regexp .*e f
234 regexp .*c yyyc
235 } 1
236 test regexp-5.4 {exercise cache of compiled expressions} {
237 regexp .*a b
238 regexp .*b c
239 regexp .*c d
240 regexp .*d e
241 regexp .*e f
242 regexp .*d 1d
243 } 1
244 test regexp-5.5 {exercise cache of compiled expressions} {
245 regexp .*a b
246 regexp .*b c
247 regexp .*c d
248 regexp .*d e
249 regexp .*e f
250 regexp .*e xe
251 } 1
252
253 test regexp-6.1 {regexp errors} {
254 list [catch {regexp a} msg] $msg
255 } {1 {wrong # args: should be "regexp ?-option ...? exp string ?matchVar? ?subMatchVar ...?"}}
256 test regexp-6.2 {regexp errors} {
257 list [catch {regexp -nocase a} msg] $msg
258 } {1 {wrong # args: should be "regexp ?-option ...? exp string ?matchVar? ?subMatchVar ...?"}}
259 test regexp-6.3 {regexp errors} {
260 list [catch {regexp -gorp a} msg] $msg
261 } {1 {bad option "-gorp": must be -all, -about, -indices, -inline, -expanded, -line, -linestop, -lineanchor, -nocase, -start, or --}}
262 test regexp-6.4 {regexp errors} {
263 list [catch {regexp a( b} msg] $msg
264 } {1 {couldn't compile regular expression pattern: parentheses () not balanced}}
265 test regexp-6.5 {regexp errors} {
266 list [catch {regexp a( b} msg] $msg
267 } {1 {couldn't compile regular expression pattern: parentheses () not balanced}}
268 test regexp-6.6 {regexp errors} {
269 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
270 } {0 1}
271 test regexp-6.7 {regexp errors} {
272 list [catch {regexp (x)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.) xyzzy} msg] $msg
273 } {0 0}
274 test regexp-6.8 {regexp errors} -setup {
275 unset -nocomplain f1
276 } -body {
277 set f1 44
278 regexp abc abc f1(f2)
279 } -returnCodes error -result {can't set "f1(f2)": variable isn't array}
280 test regexp-6.9 {regexp errors, -start bad int check} {
281 list [catch {regexp -start bogus {^$} {}} msg] $msg
282 } {1 {bad index "bogus": must be integer?[+-]integer? or end?[+-]integer?}}
283 test regexp-6.10 {regexp errors} {
284 list [catch {regexp {a[} b} msg] $msg
285 } {1 {couldn't compile regular expression pattern: brackets [] not balanced}}
286
287 test regexp-7.1 {basic regsub operation} {
288 list [regsub aa+ xaxaaaxaa 111&222 foo] $foo
289 } {1 xax111aaa222xaa}
290 test regexp-7.2 {basic regsub operation} {
291 list [regsub aa+ aaaxaa &111 foo] $foo
292 } {1 aaa111xaa}
293 test regexp-7.3 {basic regsub operation} {
294 list [regsub aa+ xaxaaa 111& foo] $foo
295 } {1 xax111aaa}
296 test regexp-7.4 {basic regsub operation} {
297 list [regsub aa+ aaa 11&2&333 foo] $foo
298 } {1 11aaa2aaa333}
299 test regexp-7.5 {basic regsub operation} {
300 list [regsub aa+ xaxaaaxaa &2&333 foo] $foo
301 } {1 xaxaaa2aaa333xaa}
302 test regexp-7.6 {basic regsub operation} {
303 list [regsub aa+ xaxaaaxaa 1&22& foo] $foo
304 } {1 xax1aaa22aaaxaa}
305 test regexp-7.7 {basic regsub operation} {
306 list [regsub a(a+) xaxaaaxaa {1\122\1} foo] $foo
307 } {1 xax1aa22aaxaa}
308 test regexp-7.8 {basic regsub operation} {
309 list [regsub a(a+) xaxaaaxaa {1\\\122\1} foo] $foo
310 } "1 {xax1\\aa22aaxaa}"
311 test regexp-7.9 {basic regsub operation} {
312 list [regsub a(a+) xaxaaaxaa {1\\122\1} foo] $foo
313 } "1 {xax1\\122aaxaa}"
314 test regexp-7.10 {basic regsub operation} {
315 list [regsub a(a+) xaxaaaxaa {1\\&\1} foo] $foo
316 } "1 {xax1\\aaaaaxaa}"
317 test regexp-7.11 {basic regsub operation} {
318 list [regsub a(a+) xaxaaaxaa {1\&\1} foo] $foo
319 } {1 xax1&aaxaa}
320 test regexp-7.12 {basic regsub operation} {
321 list [regsub a(a+) xaxaaaxaa {\1\1\1\1&&} foo] $foo
322 } {1 xaxaaaaaaaaaaaaaaxaa}
323 test regexp-7.13 {basic regsub operation} {
324 set foo xxx
325 list [regsub abc xyz 111 foo] $foo
326 } {0 xyz}
327 test regexp-7.14 {basic regsub operation} {
328 set foo xxx
329 list [regsub ^ xyz "111 " foo] $foo
330 } {1 {111 xyz}}
331 test regexp-7.15 {basic regsub operation} {
332 set foo xxx
333 list [regsub -- -foo abc-foodef "111 " foo] $foo
334 } {1 {abc111 def}}
335 test regexp-7.16 {basic regsub operation} {
336 set foo xxx
337 list [regsub x "" y foo] $foo
338 } {0 {}}
339 test regexp-7.17 {regsub utf compliance} {
340 # if not UTF-8 aware, result is "0 1"
341 set foo "xyz555ijka\u4e4ebpqr"
342 regsub a\u4e4eb xyza\u4e4ebijka\u4e4ebpqr 555 bar
343 list [string compare $foo $bar] [regexp 4 $bar]
344 } {0 0}
345 test regexp-7.18 {basic regsub replacement} {
346 list [regsub a+ aaa {&} foo] $foo
347 } {1 aaa}
348 test regexp-7.19 {basic regsub replacement} {
349 list [regsub a+ aaa {\&} foo] $foo
350 } {1 &}
351 test regexp-7.20 {basic regsub replacement} {
352 list [regsub a+ aaa {\\&} foo] $foo
353 } {1 {\aaa}}
354 test regexp-7.21 {basic regsub replacement} {
355 list [regsub a+ aaa {\\\&} foo] $foo
356 } {1 {\&}}
357 test regexp-7.22 {basic regsub replacement} {
358 list [regsub a+ aaa {\0} foo] $foo
359 } {1 aaa}
360 test regexp-7.23 {basic regsub replacement} {
361 list [regsub a+ aaa {\\0} foo] $foo
362 } {1 {\0}}
363 test regexp-7.24 {basic regsub replacement} {
364 list [regsub a+ aaa {\\\0} foo] $foo
365 } {1 {\aaa}}
366 test regexp-7.25 {basic regsub replacement} {
367 list [regsub a+ aaa {\\\\0} foo] $foo
368 } {1 {\\0}}
369 test regexp-7.26 {dollar zero is not a backslash replacement} {
370 list [regsub a+ aaa {$0} foo] $foo
371 } {1 {$0}}
372 test regexp-7.27 {dollar zero is not a backslash replacement} {
373 list [regsub a+ aaa {\0$0} foo] $foo
374 } {1 {aaa$0}}
375 test regexp-7.28 {dollar zero is not a backslash replacement} {
376 list [regsub a+ aaa {\$0} foo] $foo
377 } {1 {\$0}}
378 test regexp-7.29 {dollar zero is not a backslash replacement} {
379 list [regsub a+ aaa {\\} foo] $foo
380 } {1 \\}
381
382 test regexp-8.1 {case conversion in regsub} {
383 list [regsub -nocase a(a+) xaAAaAAay & foo] $foo
384 } {1 xaAAaAAay}
385 test regexp-8.2 {case conversion in regsub} {
386 list [regsub -nocase a(a+) xaAAaAAay & foo] $foo
387 } {1 xaAAaAAay}
388 test regexp-8.3 {case conversion in regsub} {
389 set foo 123
390 list [regsub a(a+) xaAAaAAay & foo] $foo
391 } {0 xaAAaAAay}
392 test regexp-8.4 {case conversion in regsub} {
393 set foo 123
394 list [regsub -nocase a CaDE b foo] $foo
395 } {1 CbDE}
396 test regexp-8.5 {case conversion in regsub} {
397 set foo 123
398 list [regsub -nocase XYZ CxYzD b foo] $foo
399 } {1 CbD}
400 test regexp-8.6 {case conversion in regsub} {
401 set x abcdefghijklmnopqrstuvwxyz1234567890
402 set x $x$x$x$x$x$x$x$x$x$x$x$x
403 set foo 123
404 list [regsub -nocase $x $x b foo] $foo
405 } {1 b}
406
407 test regexp-9.1 {-all option to regsub} {
408 set foo 86
409 list [regsub -all x+ axxxbxxcxdx |&| foo] $foo
410 } {4 a|xxx|b|xx|c|x|d|x|}
411 test regexp-9.2 {-all option to regsub} {
412 set foo 86
413 list [regsub -nocase -all x+ aXxXbxxcXdx |&| foo] $foo
414 } {4 a|XxX|b|xx|c|X|d|x|}
415 test regexp-9.3 {-all option to regsub} {
416 set foo 86
417 list [regsub x+ axxxbxxcxdx |&| foo] $foo
418 } {1 a|xxx|bxxcxdx}
419 test regexp-9.4 {-all option to regsub} {
420 set foo 86
421 list [regsub -all bc axxxbxxcxdx |&| foo] $foo
422 } {0 axxxbxxcxdx}
423 test regexp-9.5 {-all option to regsub} {
424 set foo xxx
425 list [regsub -all node "node node more" yy foo] $foo
426 } {2 {yy yy more}}
427 test regexp-9.6 {-all option to regsub} {
428 set foo xxx
429 list [regsub -all ^ xxx 123 foo] $foo
430 } {1 123xxx}
431
432 test regexp-10.1 {expanded syntax in regsub} {
433 set foo xxx
434 list [regsub -expanded ". \#comment\n . \#comment2" abc def foo] $foo
435 } {1 defc}
436 test regexp-10.2 {newline sensitivity in regsub} {
437 set foo xxx
438 list [regsub -line {^a.*b$} "dabc\naxyb\n" 123 foo] $foo
439 } "1 {dabc\n123\n}"
440 test regexp-10.3 {newline sensitivity in regsub} {
441 set foo xxx
442 list [regsub -line {^a.*b$} "dabc\naxyb\nxb" 123 foo] $foo
443 } "1 {dabc\n123\nxb}"
444 test regexp-10.4 {partial newline sensitivity in regsub} {
445 set foo xxx
446 list [regsub -lineanchor {^a.*b$} "da\naxyb\nxb" 123 foo] $foo
447 } "1 {da\n123}"
448 test regexp-10.5 {inverse partial newline sensitivity in regsub} {
449 set foo xxx
450 list [regsub -linestop {a.*b} "da\nbaxyb\nxb" 123 foo] $foo
451 } "1 {da\nb123\nxb}"
452
453 test regexp-11.1 {regsub errors} {
454 list [catch {regsub a b} msg] $msg
455 } {1 {wrong # args: should be "regsub ?-option ...? exp string subSpec ?varName?"}}
456 test regexp-11.2 {regsub errors} {
457 list [catch {regsub -nocase a b} msg] $msg
458 } {1 {wrong # args: should be "regsub ?-option ...? exp string subSpec ?varName?"}}
459 test regexp-11.3 {regsub errors} {
460 list [catch {regsub -nocase -all a b} msg] $msg
461 } {1 {wrong # args: should be "regsub ?-option ...? exp string subSpec ?varName?"}}
462 test regexp-11.4 {regsub errors} {
463 list [catch {regsub a b c d e f} msg] $msg
464 } {1 {wrong # args: should be "regsub ?-option ...? exp string subSpec ?varName?"}}
465 test regexp-11.5 {regsub errors} {
466 list [catch {regsub -gorp a b c} msg] $msg
467 } {1 {bad option "-gorp": must be -all, -nocase, -expanded, -line, -linestop, -lineanchor, -start, or --}}
468 test regexp-11.6 {regsub errors} {
469 list [catch {regsub -nocase a( b c d} msg] $msg
470 } {1 {couldn't compile regular expression pattern: parentheses () not balanced}}
471 test regexp-11.7 {regsub errors} -setup {
472 unset -nocomplain f1
473 } -body {
474 set f1 44
475 regsub -nocase aaa aaa xxx f1(f2)
476 } -returnCodes error -result {can't set "f1(f2)": variable isn't array}
477 test regexp-11.8 {regsub errors, -start bad int check} {
478 list [catch {regsub -start bogus pattern string rep var} msg] $msg
479 } {1 {bad index "bogus": must be integer?[+-]integer? or end?[+-]integer?}}
480 test regexp-11.9 {regsub without final variable name returns value} {
481 regsub b abaca X
482 } {aXaca}
483 test regexp-11.10 {regsub without final variable name returns value} {
484 regsub -all a abaca X
485 } {XbXcX}
486 test regexp-11.11 {regsub without final variable name returns value} {
487 regsub b(.*?)d abcdeabcfde {,&,\1,}
488 } {a,bcd,c,eabcfde}
489 test regexp-11.12 {regsub without final variable name returns value} {
490 regsub -all b(.*?)d abcdeabcfde {,&,\1,}
491 } {a,bcd,c,ea,bcfd,cf,e}
492
493 # This test crashes on the Mac unless you increase the Stack Space to about 1
494 # Meg. This is probably bigger than most users want...
495 # 8.2.3 regexp reduced stack space requirements, but this should be
496 # tested again
497 test regexp-12.1 {Tcl_RegExpExec: large number of subexpressions} {macCrash} {
498 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
499 } {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}
500
501 test regexp-13.1 {regsub of a very large string} {
502 # This test is designed to stress the memory subsystem in order to catch
503 # Bug #933. It only fails if the Tcl memory allocator is in use.
504 set line {BEGIN_TABLE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; END_TABLE}
505 set filedata [string repeat $line 200]
506 for {set i 1} {$i<10} {incr i} {
507 regsub -all "BEGIN_TABLE " $filedata "" newfiledata
508 }
509 set x done
510 } {done}
511
512 test regexp-14.1 {CompileRegexp: regexp cache} {
513 regexp .*a b
514 regexp .*b c
515 regexp .*c d
516 regexp .*d e
517 regexp .*e f
518 set x .
519 append x *a
520 regexp $x bbba
521 } 1
522 test regexp-14.2 {CompileRegexp: regexp cache, different flags} {
523 regexp .*a b
524 regexp .*b c
525 regexp .*c d
526 regexp .*d e
527 regexp .*e f
528 set x .
529 append x *a
530 regexp -nocase $x bbba
531 } 1
532 test regexp-14.3 {CompileRegexp: regexp cache, empty regexp and empty cache} -constraints {
533 exec
534 } -setup {
535 set junk [makeFile {puts [regexp {} foo]} junk.tcl]
536 } -body {
537 exec [interpreter] $junk
538 } -cleanup {
539 removeFile junk.tcl
540 } -result 1
541
542 test regexp-15.1 {regexp -start} {
543 unset -nocomplain x
544 list [regexp -start -10 {\d} 1abc2de3 x] $x
545 } {1 1}
546 test regexp-15.2 {regexp -start} {
547 unset -nocomplain x
548 list [regexp -start 2 {\d} 1abc2de3 x] $x
549 } {1 2}
550 test regexp-15.3 {regexp -start} {
551 unset -nocomplain x
552 list [regexp -start 4 {\d} 1abc2de3 x] $x
553 } {1 2}
554 test regexp-15.4 {regexp -start} {
555 unset -nocomplain x
556 list [regexp -start 5 {\d} 1abc2de3 x] $x
557 } {1 3}
558 test regexp-15.5 {regexp -start, over end of string} {
559 unset -nocomplain x
560 list [regexp -start [string length 1abc2de3] {\d} 1abc2de3 x] [info exists x]
561 } {0 0}
562 test regexp-15.6 {regexp -start, loss of ^$ behavior} {
563 list [regexp -start 2 {^$} {}]
564 } {0}
565 test regexp-15.7 {regexp -start, double option} {
566 regexp -start 2 -start 0 a abc
567 } 1
568 test regexp-15.8 {regexp -start, double option} {
569 regexp -start 0 -start 2 a abc
570 } 0
571 test regexp-15.9 {regexp -start, end relative index} {
572 unset -nocomplain x
573 list [regexp -start end {\d} 1abc2de3 x] [info exists x]
574 } {0 0}
575 test regexp-15.10 {regexp -start, end relative index} {
576 unset -nocomplain x
577 list [regexp -start end-1 {\d} 1abc2de3 x] [info exists x] $x
578 } {1 1 3}
579 test regexp-15.11 {regexp -start, over end of string} {
580 set x NA
581 list [regexp -start 2 {.*} ab x] $x
582 } {1 {}}
583
584 test regexp-16.1 {regsub -start} {
585 unset -nocomplain x
586 list [regsub -all -start 2 {\d} a1b2c3d4e5 {/&} x] $x
587 } {4 a1b/2c/3d/4e/5}
588 test regexp-16.2 {regsub -start} {
589 unset -nocomplain x
590 list [regsub -all -start -25 {z} hello {/&} x] $x
591 } {0 hello}
592 test regexp-16.3 {regsub -start} {
593 unset -nocomplain x
594 list [regsub -all -start 3 {z} hello {/&} x] $x
595 } {0 hello}
596 test regexp-16.4 {regsub -start, \A behavior} {
597 set out {}
598 lappend out [regsub -start 0 -all {\A(\w)} {abcde} {/\1} x] $x
599 lappend out [regsub -start 2 -all {\A(\w)} {abcde} {/\1} x] $x
600 } {5 /a/b/c/d/e 3 ab/c/d/e}
601 test regexp-16.5 {regsub -start, double option} {
602 list [regsub -start 2 -start 0 a abc c x] $x
603 } {1 cbc}
604 test regexp-16.6 {regsub -start, double option} {
605 list [regsub -start 0 -start 2 a abc c x] $x
606 } {0 abc}
607 test regexp-16.7 {regexp -start, end relative index} {
608 list [regsub -start end a aaa b x] $x
609 } {0 aaa}
610 test regexp-16.8 {regexp -start, end relative index} {
611 list [regsub -start end-1 a aaa b x] $x
612 } {1 aab}
613 test regexp-16.9 {regsub -start and -all} {
614 set foo {}
615 list [regsub -start 0 -all x+ axxxbxx |&| foo] $foo
616 } {2 a|xxx|b|xx|}
617 test regexp-16.10 {regsub -start and -all} {
618 set foo {}
619 list [regsub -start 1 -all x+ axxxbxx |&| foo] $foo
620 } {2 a|xxx|b|xx|}
621 test regexp-16.11 {regsub -start and -all} {
622 set foo {}
623 list [regsub -start 4 -all x+ axxxbxx |&| foo] $foo
624 } {1 axxxb|xx|}
625 test regexp-16.12 {regsub -start} {
626 set foo {}
627 list [regsub -start 4 x+ axxxbxx |&| foo] $foo
628 } {1 axxxb|xx|}
629 test regexp-16.13 {regsub -start and -all} {
630 set foo {}
631 list [regsub -start 1 -all a+ "" & foo] $foo
632 } {0 {}}
633 test regexp-16.14 {regsub -start} {
634 set foo {}
635 list [regsub -start 1 a+ "" & foo] $foo
636 } {0 {}}
637 test regexp-16.15 {regsub -start and -all} {
638 set foo {}
639 list [regsub -start 2 -all a+ "xy" & foo] $foo
640 } {0 xy}
641 test regexp-16.16 {regsub -start} {
642 set foo {}
643 list [regsub -start 2 a+ "xy" & foo] $foo
644 } {0 xy}
645 test regexp-16.17 {regsub -start and -all} {
646 set foo {}
647 list [regsub -start 1 -all y+ "xy" & foo] $foo
648 } {1 xy}
649 test regexp-16.18 {regsub -start} {
650 set foo {}
651 list [regsub -start 1 y+ "xy" & foo] $foo
652 } {1 xy}
653 test regexp-16.19 {regsub -start} {
654 set foo {}
655 list [regsub -start -1 a+ "" & foo] $foo
656 } {0 {}}
657 test regexp-16.20 {regsub -start, loss of ^$ behavior} {
658 set foo NA
659 list [regsub -start 1 {^$} {} & foo] $foo
660 } {0 {}}
661 test regexp-16.21 {regsub -start, loss of ^$ behavior} {
662 set foo NA
663 list [regsub -start 1 {^.*$} abc & foo] $foo
664 } {0 abc}
665 test regexp-16.22 {regsub -start, loss of ^$ behavior} {
666 set foo NA
667 list [regsub -all -start 1 {^.*$} abc & foo] $foo
668 } {0 abc}
669
670 test regexp-17.1 {regexp -inline} {
671 regexp -inline b ababa
672 } {b}
673 test regexp-17.2 {regexp -inline} {
674 regexp -inline (b) ababa
675 } {b b}
676 test regexp-17.3 {regexp -inline -indices} {
677 regexp -inline -indices (b) ababa
678 } {{1 1} {1 1}}
679 test regexp-17.4 {regexp -inline} {
680 regexp -inline {\w(\d+)\w} " hello 23 there456def "
681 } {e456d 456}
682 test regexp-17.5 {regexp -inline no matches} {
683 regexp -inline {\w(\d+)\w} ""
684 } {}
685 test regexp-17.6 {regexp -inline no matches} {
686 regexp -inline hello goodbye
687 } {}
688 test regexp-17.7 {regexp -inline, no matchvars allowed} {
689 list [catch {regexp -inline b abc match} msg] $msg
690 } {1 {regexp match variables not allowed when using -inline}}
691
692 test regexp-18.1 {regexp -all} {
693 regexp -all b bbbbb
694 } {5}
695 test regexp-18.2 {regexp -all} {
696 regexp -all b abababbabaaaaaaaaaab
697 } {6}
698 test regexp-18.3 {regexp -all -inline} {
699 regexp -all -inline b abababbabaaaaaaaaaab
700 } {b b b b b b}
701 test regexp-18.4 {regexp -all -inline} {
702 regexp -all -inline {\w(\w)} abcdefg
703 } {ab b cd d ef f}
704 test regexp-18.5 {regexp -all -inline} {
705 regexp -all -inline {\w(\w)$} abcdefg
706 } {fg g}
707 test regexp-18.6 {regexp -all -inline} {
708 regexp -all -inline {\d+} 10:20:30:40
709 } {10 20 30 40}
710 test regexp-18.7 {regexp -all -inline} {
711 list [catch {regexp -all -inline b abc match} msg] $msg
712 } {1 {regexp match variables not allowed when using -inline}}
713 test regexp-18.8 {regexp -all} {
714 # This should not cause an infinite loop
715 regexp -all -inline {a*} a
716 } {a}
717 test regexp-18.9 {regexp -all} {
718 # Yes, the expected result is {a {}}. Here's why:
719 # Start at index 0; a* matches the "a" there then stops.
720 # Go to index 1; a* matches the lambda (or {}) there then stops. Recall
721 # that a* matches zero or more "a"'s; thus it matches the string "b", as
722 # there are zero or more "a"'s there.
723 # Go to index 2; this is past the end of the string, so stop.
724 regexp -all -inline {a*} ab
725 } {a {}}
726 test regexp-18.10 {regexp -all} {
727 # Yes, the expected result is {a {} a}. Here's why:
728 # Start at index 0; a* matches the "a" there then stops.
729 # Go to index 1; a* matches the lambda (or {}) there then stops. Recall
730 # that a* matches zero or more "a"'s; thus it matches the string "b", as
731 # there are zero or more "a"'s there.
732 # Go to index 2; a* matches the "a" there then stops.
733 # Go to index 3; this is past the end of the string, so stop.
734 regexp -all -inline {a*} aba
735 } {a {} a}
736 test regexp-18.11 {regexp -all} {
737 regexp -all -inline {^a} aaaa
738 } {a}
739 test regexp-18.12 {regexp -all -inline -indices} {
740 regexp -all -inline -indices a(b(c)d|e(f)g)h abcdhaefgh
741 } {{0 4} {1 3} {2 2} {-1 -1} {5 9} {6 8} {-1 -1} {7 7}}
742
743 test regexp-19.1 {regsub null replacement} {
744 regsub -all {@} {@hel@lo@} "\0a\0" result
745 list $result [string length $result]
746 } "\0a\0hel\0a\0lo\0a\0 14"
747
748 test regexp-19.2 {regsub null replacement} {
749 regsub -all {@} {@hel@lo@} "\0a\0" result
750 set expected "\0a\0hel\0a\0lo\0a\0"
751 string equal $result $expected
752 } 1
753
754 test regexp-20.1 {regsub shared object shimmering} {
755 # Bug #461322
756 set a abcdefghijklmnopqurstuvwxyz
757 set b $a
758 set c abcdefghijklmnopqurstuvwxyz0123456789
759 regsub $a $c $b d
760 list $d [string length $d] [string bytelength $d]
761 } [list abcdefghijklmnopqurstuvwxyz0123456789 37 37]
762 test regexp-20.2 {regsub shared object shimmering with -about} {
763 eval regexp -about abc
764 } {0 {}}
765
766 test regexp-21.1 {regsub works with empty string} {
767 regsub -- ^ {} foo
768 } {foo}
769 test regexp-21.2 {regsub works with empty string} {
770 regsub -- \$ {} foo
771 } {foo}
772 test regexp-21.3 {regsub works with empty string offset} {
773 regsub -start 0 -- ^ {} foo
774 } {foo}
775 test regexp-21.4 {regsub works with empty string offset} {
776 regsub -start 0 -- \$ {} foo
777 } {foo}
778 test regexp-21.5 {regsub works with empty string offset} {
779 regsub -start 3 -- \$ {123} foo
780 } {123foo}
781 test regexp-21.6 {regexp works with empty string} {
782 regexp -- ^ {}
783 } {1}
784 test regexp-21.7 {regexp works with empty string} {
785 regexp -start 0 -- ^ {}
786 } {1}
787 test regexp-21.8 {regexp works with empty string offset} {
788 regexp -start 3 -- ^ {123}
789 } {0}
790 test regexp-21.9 {regexp works with empty string offset} {
791 regexp -start 3 -- \$ {123}
792 } {1}
793 test regexp-21.10 {multiple matches handle newlines} {
794 regsub -all -lineanchor -- {^#[^\n]*\n} "#one\n#two\n#three\n" foo\n
795 } "foo\nfoo\nfoo\n"
796 test regexp-21.11 {multiple matches handle newlines} {
797 regsub -all -line -- ^ "a\nb\nc" \#
798 } "\#a\n\#b\n\#c"
799 test regexp-21.12 {multiple matches handle newlines} {
800 regsub -all -line -- ^ "\n\n" \#
801 } "\#\n\#\n\#"
802 test regexp-21.13 {multiple matches handle newlines} {
803 regexp -all -inline -indices -line -- ^ "a\nb\nc"
804 } {{0 -1} {2 1} {4 3}}
805 test regexp-21.14 {regsub works with empty string} {
806 regsub -- ^ {} &
807 } {}
808 test regexp-21.15 {regsub works with empty string} {
809 regsub -- ^ {} foo&
810 } {foo}
811 test regexp-21.16 {regsub works with empty string} {
812 regsub -all -- ^ {} foo&
813 } {foo}
814 test regexp-21.17 {regsub works with empty string} {
815 regsub -- ^ {} {foo\0}
816 } {foo}
817 test regexp-21.18 {regsub works with empty string} {
818 regsub -- ^.* {} {foo$0}
819 } {foo$0}
820 test regexp-21.19 {regsub works with empty string} {
821 regsub -- ^ {input} {}
822 } {input}
823 test regexp-21.20 {regsub works with empty string} {
824 regsub -- x {} {foo}
825 } {}
826
827 test regexp-22.1 {Bug 1810038} {
828 regexp ($|^X)* {}
829 } 1
830 test regexp-22.2 {regexp compile and backrefs, Bug 1857126} {
831 regexp -- {([bc])\1} bb
832 } 1
833 test regexp-22.3 {Bug 3604074} {
834 # This will hang in interps where the bug is not fixed
835 regexp ((((((((a)*)*)*)*)*)*)*)* a
836 } 1
837 test regexp-22.4 {Bug 3606139} -setup {
838 interp alias {} a {} string repeat a
839 } -body {
840 # This crashes in interps where the bug is not fixed
841 regexp [join [list [a 160]([a 55])[a 668]([a 55])[a 669]([a 55]) \
842 [a 668]([a 55])[a 649]([a 55])[a 668]([a 55])[a 668]([a 55]) \
843 [a 672]([a 55])[a 669]([a 55])[a 671]([a 55])[a 671]([a 55]) \
844 [a 672]([a 55])[a 652]([a 55])[a 672]([a 55])[a 671]([a 55]) \
845 [a 671]([a 55])[a 671]([a 55])[a 653]([a 55])[a 672]([a 55]) \
846 [a 653]([a 55])[a 672]([a 55])[a 672]([a 55])[a 652]([a 55]) \
847 [a 671]([a 55])[a 652]([a 55])[a 652]([a 55])[a 672]([a 55]) \
848 [a 672]([a 55])[a 672]([a 55])[a 653]([a 55])[a 671]([a 55]) \
849 [a 669]([a 55])[a 649]([a 55])[a 668]([a 55])[a 668]([a 55]) \
850 [a 668]([a 55])[a 650]([a 55])[a 650]([a 55])[a 672]([a 55]) \
851 [a 669]([a 55])[a 669]([a 55])[a 668]([a 55])[a 668]([a 55]) \
852 [a 668]([a 55])[a 669]([a 55])[a 672]([a 55])[a 669]([a 55]) \
853 [a 669]([a 55])[a 669]([a 55])[a 669]([a 55])[a 672]([a 55]) \
854 [a 670]([a 55])[a 671]([a 55])[a 672]([a 55])[a 672]([a 55]) \
855 [a 671]([a 55])[a 671]([a 55])[a 672]([a 55])[a 669]([a 55]) \
856 [a 668]([a 55])[a 668]([a 55])[a 669]([a 55])[a 668]([a 55]) \
857 [a 669]([a 55])[a 668]([a 55])[a 669]([a 55])[a 669]([a 55]) \
858 [a 668]([a 55])[a 668]([a 55])[a 669]([a 55])[a 668]([a 55]) \
859 [a 669]([a 55])[a 669]([a 55])[a 669]([a 55])[a 669]([a 55]) \
860 [a 668]([a 55])[a 669]([a 55])[a 672]([a 55])[a 669]([a 55]) \
861 [a 669]([a 55])[a 669]([a 55])[a 669]([a 55])[a 668]([a 55]) \
862 [a 669]([a 55])[a 669]([a 55])[a 668]([a 55])[a 668]([a 55]) \
863 [a 668]([a 55])[a 669]([a 55])[a 668]([a 55])[a 669]([a 55]) \
864 [a 672]([a 55])[a 669]([a 55])[a 669]([a 55])[a 710]([a 55]) \
865 [a 668]([a 55])[a 669]([a 55])[a 668]([a 55])[a 669]([a 55]) \
866 [a 668]([a 55])[a 669]([a 55])[a 668]([a 55])[a 668]([a 55]) \
867 [a 668]([a 55])[a 668]([a 55])[a 668]([a 55])[a 669]([a 55]) \
868 [a 672]([a 55])[a 669]([a 55])[a 669]([a 55])[a 668]([a 55]) \
869 [a 669]([a 55])[a 669]([a 55])[a 668]([a 55])[a 668]([a 55]) \
870 [a 668]([a 55])[a 668]([a 55])[a 668]([a 55])[a 668]([a 55]) \
871 [a 667]([a 55])[a 668]([a 55])[a 669]([a 55])[a 668]([a 55]) \
872 [a 671]([a 55])[a 669]([a 55])[a 668]([a 55])[a 669]([a 55]) \
873 [a 669]([a 55])[a 669]([a 55])[a 668]([a 55])[a 669]([a 55]) \
874 [a 668]([a 55])[a 710]([a 55])[a 668]([a 55])[a 668]([a 55]) \
875 [a 668]([a 55])[a 668]([a 55])[a 668]([a 55])[a 511]] {}] a
876 } -cleanup {
877 rename a {}
878 } -returnCodes 1 -match glob -result {couldn't compile regular expression pattern: *}
879 test regexp-22.5 {Bug 3610026} -setup {
880 set e {}
881 set cp 99
882 while {$cp < 32864} {
883 append e [format %c [incr cp]]
884 }
885 } -body {
886 regexp -about $e
887 } -cleanup {
888 unset -nocomplain e cp
889 } -returnCodes error -match glob -result {*too many colors*}
890 test regexp-22.6 {Bug 6585b21ca8} {
891 expr {[regexp {(\w).*?\1} Programmer m] ? $m : "<NONE>"}
892 } rogr
893
894
895 test regexp-23.1 {regexp -all and -line} {
896 set string ""
897 list \
898 [regexp -all -inline -indices -line -- {^} $string] \
899 [regexp -all -inline -indices -line -- {^$} $string] \
900 [regexp -all -inline -indices -line -- {$} $string]
901 } {{{0 -1}} {{0 -1}} {{0 -1}}}
902 test regexp-23.2 {regexp -all and -line} {
903 set string "\n"
904 list \
905 [regexp -all -inline -indices -line -- {^} $string] \
906 [regexp -all -inline -indices -line -- {^$} $string] \
907 [regexp -all -inline -indices -line -- {$} $string]
908 } {{{0 -1}} {{0 -1}} {{0 -1}}}
909 test regexp-23.3 {regexp -all and -line} {
910 set string "\n\n"
911 list \
912 [regexp -all -inline -indices -line -- {^} $string] \
913 [regexp -all -inline -indices -line -- {^$} $string] \
914 [regexp -all -inline -indices -line -- {$} $string]
915 } {{{0 -1} {1 0}} {{0 -1} {1 0}} {{0 -1} {1 0}}}
916 test regexp-23.4 {regexp -all and -line} {
917 set string "a"
918 list \
919 [regexp -all -inline -indices -line -- {^} $string] \
920 [regexp -all -inline -indices -line -- {^.*$} $string] \
921 [regexp -all -inline -indices -line -- {$} $string]
922 } {{{0 -1}} {{0 0}} {{1 0}}}
923 test regexp-23.5 {regexp -all and -line} {knownBug} {
924 set string "a\n"
925 list \
926 [regexp -all -inline -indices -line -- {^} $string] \
927 [regexp -all -inline -indices -line -- {^.*$} $string] \
928 [regexp -all -inline -indices -line -- {$} $string]
929 } {{{0 -1} {2 1}} {{0 0} {2 1}} {{1 0} {2 1}}}
930 test regexp-23.6 {regexp -all and -line} {
931 set string "\na"
932 list \
933 [regexp -all -inline -indices -line -- {^} $string] \
934 [regexp -all -inline -indices -line -- {^.*$} $string] \
935 [regexp -all -inline -indices -line -- {$} $string]
936 } {{{0 -1} {1 0}} {{0 -1} {1 1}} {{0 -1} {2 1}}}
937 test regexp-23.7 {regexp -all and -line} {knownBug} {
938 set string "ab\n"
939 list \
940 [regexp -all -inline -indices -line -- {^} $string] \
941 [regexp -all -inline -indices -line -- {^.*$} $string] \
942 [regexp -all -inline -indices -line -- {$} $string]
943 } {{{0 -1} {3 2}} {{0 1} {3 2}} {{2 1} {3 2}}}
944 test regexp-23.8 {regexp -all and -line} {
945 set string "a\nb"
946 list \
947 [regexp -all -inline -indices -line -- {^} $string] \
948 [regexp -all -inline -indices -line -- {^.*$} $string] \
949 [regexp -all -inline -indices -line -- {$} $string]
950 } {{{0 -1} {2 1}} {{0 0} {2 2}} {{1 0} {3 2}}}
951 test regexp-23.9 {regexp -all and -line} {knownBug} {
952 set string "a\nb\n"
953 list \
954 [regexp -all -inline -indices -line -- {^} $string] \
955 [regexp -all -inline -indices -line -- {^.*$} $string] \
956 [regexp -all -inline -indices -line -- {$} $string]
957 } {{{0 -1} {2 1} {4 3}} {{0 0} {2 2} {4 3}} {{1 0} {3 2} {4 3}}}
958 test regexp-23.10 {regexp -all and -line} {
959 set string "a\nb\nc"
960 list \
961 [regexp -all -inline -indices -line -- {^} $string] \
962 [regexp -all -inline -indices -line -- {^.*$} $string] \
963 [regexp -all -inline -indices -line -- {$} $string]
964 } {{{0 -1} {2 1} {4 3}} {{0 0} {2 2} {4 4}} {{1 0} {3 2} {5 4}}}
965 test regexp-23.11 {regexp -all and -line} {
966 regexp -all -inline -indices -line -- {b} "abb\nb"
967 } {{1 1} {2 2} {4 4}}
968
969 test regexp-24.1 {regsub -all and -line} {
970 foreach {v1 v2 v3} {{} {} {}} {}
971 set string ""
972 list \
973 [regsub -line -all {^} $string {<&>} v1] $v1 \
974 [regsub -line -all {^$} $string {<&>} v2] $v2 \
975 [regsub -line -all {$} $string {<&>} v3] $v3
976 } {1 <> 1 <> 1 <>}
977 test regexp-24.2 {regsub -all and -line} {
978 foreach {v1 v2 v3} {{} {} {}} {}
979 set string "\n"
980 list \
981 [regsub -line -all {^} $string {<&>} v1] $v1 \
982 [regsub -line -all {^$} $string {<&>} v2] $v2 \
983 [regsub -line -all {$} $string {<&>} v3] $v3
984 } [list 2 "<>\n<>" 2 "<>\n<>" 2 "<>\n<>"]
985 test regexp-24.3 {regsub -all and -line} {
986 foreach {v1 v2 v3} {{} {} {}} {}
987 set string "\n\n"
988 list \
989 [regsub -line -all {^} $string {<&>} v1] $v1 \
990 [regsub -line -all {^$} $string {<&>} v2] $v2 \
991 [regsub -line -all {$} $string {<&>} v3] $v3
992 } [list 3 "<>\n<>\n<>" 3 "<>\n<>\n<>" 3 "<>\n<>\n<>"]
993 test regexp-24.4 {regsub -all and -line} {
994 foreach {v1 v2 v3} {{} {} {}} {}
995 set string "a"
996 list \
997 [regsub -line -all {^} $string {<&>} v1] $v1 \
998 [regsub -line -all {^.*$} $string {<&>} v2] $v2 \
999 [regsub -line -all {$} $string {<&>} v3] $v3
1000 } [list 1 "<>a" 1 "<a>" 1 "a<>"]
1001 test regexp-24.5 {regsub -all and -line} {
1002 foreach {v1 v2 v3} {{} {} {}} {}
1003 set string "a\n"
1004 list \
1005 [regsub -line -all {^} $string {<&>} v1] $v1 \
1006 [regsub -line -all {^.*$} $string {<&>} v2] $v2 \
1007 [regsub -line -all {$} $string {<&>} v3] $v3
1008 } [list 2 "<>a\n<>" 2 "<a>\n<>" 2 "a<>\n<>"]
1009 test regexp-24.6 {regsub -all and -line} {
1010 foreach {v1 v2 v3} {{} {} {}} {}
1011 set string "\na"
1012 list \
1013 [regsub -line -all {^} $string {<&>} v1] $v1 \
1014 [regsub -line -all {^.*$} $string {<&>} v2] $v2 \
1015 [regsub -line -all {$} $string {<&>} v3] $v3
1016 } [list 2 "<>\n<>a" 2 "<>\n<a>" 2 "<>\na<>"]
1017 test regexp-24.7 {regsub -all and -line} {
1018 foreach {v1 v2 v3} {{} {} {}} {}
1019 set string "ab\n"
1020 list \
1021 [regsub -line -all {^} $string {<&>} v1] $v1 \
1022 [regsub -line -all {^.*$} $string {<&>} v2] $v2 \
1023 [regsub -line -all {$} $string {<&>} v3] $v3
1024 } [list 2 "<>ab\n<>" 2 "<ab>\n<>" 2 "ab<>\n<>"]
1025 test regexp-24.8 {regsub -all and -line} {
1026 foreach {v1 v2 v3} {{} {} {}} {}
1027 set string "a\nb"
1028 list \
1029 [regsub -line -all {^} $string {<&>} v1] $v1 \
1030 [regsub -line -all {^.*$} $string {<&>} v2] $v2 \
1031 [regsub -line -all {$} $string {<&>} v3] $v3
1032 } [list 2 "<>a\n<>b" 2 "<a>\n<b>" 2 "a<>\nb<>"]
1033 test regexp-24.9 {regsub -all and -line} {
1034 foreach {v1 v2 v3} {{} {} {}} {}
1035 set string "a\nb\n"
1036 list \
1037 [regsub -line -all {^} $string {<&>} v1] $v1 \
1038 [regsub -line -all {^.*$} $string {<&>} v2] $v2 \
1039 [regsub -line -all {$} $string {<&>} v3] $v3
1040 } [list 3 "<>a\n<>b\n<>" 3 "<a>\n<b>\n<>" 3 "a<>\nb<>\n<>"]
1041 test regexp-24.10 {regsub -all and -line} {
1042 foreach {v1 v2 v3} {{} {} {}} {}
1043 set string "a\nb\nc"
1044 list \
1045 [regsub -line -all {^} $string {<&>} v1] $v1 \
1046 [regsub -line -all {^.*$} $string {<&>} v2] $v2 \
1047 [regsub -line -all {$} $string {<&>} v3] $v3
1048 } [list 3 "<>a\n<>b\n<>c" 3 "<a>\n<b>\n<c>" 3 "a<>\nb<>\nc<>"]
1049 test regexp-24.11 {regsub -all and -line} {
1050 regsub -line -all {b} "abb\nb" {<&>}
1051 } "a<b><b>\n<b>"
1052
1053 test regexp-25.1 {regexp without -line option} {
1054 set foo ""
1055 list [regexp {a.*b} "dabc\naxyb\n" foo] $foo
1056 } [list 1 abc\naxyb]
1057 test regexp-25.2 {regexp without -line option} {
1058 set foo ""
1059 list [regexp {^a.*b$} "dabc\naxyb\n" foo] $foo
1060 } {0 {}}
1061 test regexp-25.3 {regexp with -line option} {
1062 set foo ""
1063 list [regexp -line {^a.*b$} "dabc\naxyb\n" foo] $foo
1064 } {1 axyb}
1065 test regexp-25.4 {regexp with -line option} {
1066 set foo ""
1067 list [regexp -line {^a.*b$} "dabc\naxyb\nxb" foo] $foo
1068 } {1 axyb}
1069 test regexp-25.5 {regexp without -line option} {
1070 set foo ""
1071 list [regexp {^a.*b$} "dabc\naxyb\nxb" foo] $foo
1072 } {0 {}}
1073 test regexp-25.6 {regexp without -line option} {
1074 set foo ""
1075 list [regexp {a.*b$} "dabc\naxyb\nxb" foo] $foo
1076 } "1 {abc\naxyb\nxb}"
1077 test regexp-25.7 {regexp with -lineanchor option} {
1078 set foo ""
1079 list [regexp -lineanchor {^a.*b$} "dabc\naxyb\nxb" foo] $foo
1080 } "1 {axyb\nxb}"
1081 test regexp-25.8 {regexp with -lineanchor and -linestop option} {
1082 set foo ""
1083 list [regexp -lineanchor -linestop {^a.*b$} "dabc\naxyb\nxb" foo] $foo
1084 } {1 axyb}
1085 test regexp-25.9 {regexp with -linestop option} {
1086 set foo ""
1087 list [regexp -linestop {a.*b} "ab\naxyb\nxb" foo] $foo
1088 } {1 ab}
1089
1090 test regexp-26.1 {matches start of line 1 time} {
1091 regexp -all -inline -- {^a+} "aab\naaa"
1092 } {aa}
1093 test regexp-26.2 {matches start of line(s) 2 times} {
1094 regexp -all -inline -line -- {^a+} "aab\naaa"
1095 } {aa aaa}
1096 test regexp-26.3 {effect of -line -all and -start} {
1097 list \
1098 [regexp -all -inline -line -start 0 -- {^a+} "aab\naaa"] \
1099 [regexp -all -inline -line -start 1 -- {^a+} "aab\naaa"] \
1100 [regexp -all -inline -line -start 3 -- {^a+} "aab\naaa"] \
1101 [regexp -all -inline -line -start 4 -- {^a+} "aab\naaa"] \
1102 } {{aa aaa} aaa aaa aaa}
1103 # No regexp-26.4
1104 test regexp-26.5 {match length 0, match length 1} {
1105 regexp -all -inline -line -- {^b*} "a\nb"
1106 } {{} b}
1107 test regexp-26.6 {non reporting capture group} {
1108 regexp -all -inline -line -- {^(?:a+|b)} "aab\naaa"
1109 } {aa aaa}
1110 test regexp-26.7 {Tcl bug 2826551: -line sensitive regexp and -start} {
1111 set match1 {}
1112 set match2 {}
1113 list \
1114 [regexp -start 0 -indices -line {^a} "\nab" match1] $match1 \
1115 [regexp -start 1 -indices -line {^a} "\nab" match2] $match2
1116 } {1 {1 1} 1 {1 1}}
1117 test regexp-26.8 {Tcl bug 2826551: diff regexp with -line option} {
1118 set data "@1\n2\n+3\n@4\n-5\n+6\n7\n@8\n9\n"
1119 regexp -all -inline -line {^@.*\n(?:[^@].*\n?)*} $data
1120 } [list "@1\n2\n+3\n" "@4\n-5\n+6\n7\n" "@8\n9\n"]
1121 test regexp-26.9 {Tcl bug 2826551: diff regexp with embedded -line option} {
1122 set data "@1\n2\n+3\n@4\n-5\n+6\n7\n@8\n9\n"
1123 regexp -all -inline {(?n)^@.*\n(?:[^@].*\n?)*} $data
1124 } [list "@1\n2\n+3\n" "@4\n-5\n+6\n7\n" "@8\n9\n"]
1125 test regexp-26.10 {regexp with -line option} {
1126 regexp -all -inline -line -- {a*} "a\n"
1127 } {a {}}
1128 test regexp-26.11 {regexp without -line option} {
1129 regexp -all -inline -- {a*} "a\n"
1130 } {a {}}
1131 test regexp-26.12 {regexp with -line option} {
1132 regexp -all -inline -line -- {a*} "b\n"
1133 } {{} {}}
1134 test regexp-26.13 {regexp without -line option} {
1135 regexp -all -inline -- {a*} "b\n"
1136 } {{} {}}
1137
1138 test regexp-28.1 {bug cb03e57a7b} -returnCodes error -body {
1139 regexp {} $nosuchvar
1140 } -result {can't read "nosuchvar": no such variable}
1141
1142
1143 # cleanup
1144 ::tcltest::cleanupTests
1145 return
1146
1147 # Local Variables:
1148 # mode: tcl
1149 # End: