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: regexp.test,v 1.22.2.3 2003/10/14 18:22:10 vincentdarley Exp $
|
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 |
catch {unset foo}
|
sl@0
|
22 |
test regexp-1.1 {basic regexp operation} {
|
sl@0
|
23 |
regexp ab*c abbbc
|
sl@0
|
24 |
} 1
|
sl@0
|
25 |
test regexp-1.2 {basic regexp operation} {
|
sl@0
|
26 |
regexp ab*c ac
|
sl@0
|
27 |
} 1
|
sl@0
|
28 |
test regexp-1.3 {basic regexp operation} {
|
sl@0
|
29 |
regexp ab*c ab
|
sl@0
|
30 |
} 0
|
sl@0
|
31 |
test regexp-1.4 {basic regexp operation} {
|
sl@0
|
32 |
regexp -- -gorp abc-gorpxxx
|
sl@0
|
33 |
} 1
|
sl@0
|
34 |
test regexp-1.5 {basic regexp operation} {
|
sl@0
|
35 |
regexp {^([^ ]*)[ ]*([^ ]*)} "" a
|
sl@0
|
36 |
} 1
|
sl@0
|
37 |
test regexp-1.6 {basic regexp operation} {
|
sl@0
|
38 |
list [catch {regexp {} abc} msg] $msg
|
sl@0
|
39 |
} {0 1}
|
sl@0
|
40 |
test regexp-1.7 {regexp utf compliance} {
|
sl@0
|
41 |
# if not UTF-8 aware, result is "0 1"
|
sl@0
|
42 |
set foo "\u4e4eb q"
|
sl@0
|
43 |
regexp "\u4e4eb q" "a\u4e4eb qw\u5e4e\x4e wq" bar
|
sl@0
|
44 |
list [string compare $foo $bar] [regexp 4 $bar]
|
sl@0
|
45 |
} {0 0}
|
sl@0
|
46 |
|
sl@0
|
47 |
test regexp-2.1 {getting substrings back from regexp} {
|
sl@0
|
48 |
set foo {}
|
sl@0
|
49 |
list [regexp ab*c abbbbc foo] $foo
|
sl@0
|
50 |
} {1 abbbbc}
|
sl@0
|
51 |
test regexp-2.2 {getting substrings back from regexp} {
|
sl@0
|
52 |
set foo {}
|
sl@0
|
53 |
set f2 {}
|
sl@0
|
54 |
list [regexp a(b*)c abbbbc foo f2] $foo $f2
|
sl@0
|
55 |
} {1 abbbbc bbbb}
|
sl@0
|
56 |
test regexp-2.3 {getting substrings back from regexp} {
|
sl@0
|
57 |
set foo {}
|
sl@0
|
58 |
set f2 {}
|
sl@0
|
59 |
list [regexp a(b*)(c) abbbbc foo f2] $foo $f2
|
sl@0
|
60 |
} {1 abbbbc bbbb}
|
sl@0
|
61 |
test regexp-2.4 {getting substrings back from regexp} {
|
sl@0
|
62 |
set foo {}
|
sl@0
|
63 |
set f2 {}
|
sl@0
|
64 |
set f3 {}
|
sl@0
|
65 |
list [regexp a(b*)(c) abbbbc foo f2 f3] $foo $f2 $f3
|
sl@0
|
66 |
} {1 abbbbc bbbb c}
|
sl@0
|
67 |
test regexp-2.5 {getting substrings back from regexp} {
|
sl@0
|
68 |
set foo {}; set f1 {}; set f2 {}; set f3 {}; set f4 {}; set f5 {};
|
sl@0
|
69 |
set f6 {}; set f7 {}; set f8 {}; set f9 {}; set fa {}; set fb {};
|
sl@0
|
70 |
list [regexp (1*)(2*)(3*)(4*)(5*)(6*)(7*)(8*)(9*)(a*)(b*) \
|
sl@0
|
71 |
12223345556789999aabbb \
|
sl@0
|
72 |
foo f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb] $foo $f1 $f2 $f3 $f4 $f5 \
|
sl@0
|
73 |
$f6 $f7 $f8 $f9 $fa $fb
|
sl@0
|
74 |
} {1 12223345556789999aabbb 1 222 33 4 555 6 7 8 9999 aa bbb}
|
sl@0
|
75 |
test regexp-2.6 {getting substrings back from regexp} {
|
sl@0
|
76 |
set foo 2; set f2 2; set f3 2; set f4 2
|
sl@0
|
77 |
list [regexp (a)(b)? xay foo f2 f3 f4] $foo $f2 $f3 $f4
|
sl@0
|
78 |
} {1 a a {} {}}
|
sl@0
|
79 |
test regexp-2.7 {getting substrings back from regexp} {
|
sl@0
|
80 |
set foo 1; set f2 1; set f3 1; set f4 1
|
sl@0
|
81 |
list [regexp (a)(b)?(c) xacy foo f2 f3 f4] $foo $f2 $f3 $f4
|
sl@0
|
82 |
} {1 ac a {} c}
|
sl@0
|
83 |
test regexp-2.8 {getting substrings back from regexp} {
|
sl@0
|
84 |
set match {}
|
sl@0
|
85 |
list [regexp {^a*b} aaaab match] $match
|
sl@0
|
86 |
} {1 aaaab}
|
sl@0
|
87 |
test regexp-2.9 {getting substrings back from regexp} {
|
sl@0
|
88 |
set foo {}
|
sl@0
|
89 |
set f2 {}
|
sl@0
|
90 |
list [regexp f\352te(b*)c f\352tebbbbc foo f2] $foo $f2
|
sl@0
|
91 |
} [list 1 f\352tebbbbc bbbb]
|
sl@0
|
92 |
test regexp-2.10 {getting substrings back from regexp} {
|
sl@0
|
93 |
set foo {}
|
sl@0
|
94 |
set f2 {}
|
sl@0
|
95 |
list [regexp f\352te(b*)c eff\352tebbbbc foo f2] $foo $f2
|
sl@0
|
96 |
} [list 1 f\352tebbbbc bbbb]
|
sl@0
|
97 |
|
sl@0
|
98 |
test regexp-3.1 {-indices option to regexp} {
|
sl@0
|
99 |
set foo {}
|
sl@0
|
100 |
list [regexp -indices ab*c abbbbc foo] $foo
|
sl@0
|
101 |
} {1 {0 5}}
|
sl@0
|
102 |
test regexp-3.2 {-indices option to regexp} {
|
sl@0
|
103 |
set foo {}
|
sl@0
|
104 |
set f2 {}
|
sl@0
|
105 |
list [regexp -indices a(b*)c abbbbc foo f2] $foo $f2
|
sl@0
|
106 |
} {1 {0 5} {1 4}}
|
sl@0
|
107 |
test regexp-3.3 {-indices option to regexp} {
|
sl@0
|
108 |
set foo {}
|
sl@0
|
109 |
set f2 {}
|
sl@0
|
110 |
list [regexp -indices a(b*)(c) abbbbc foo f2] $foo $f2
|
sl@0
|
111 |
} {1 {0 5} {1 4}}
|
sl@0
|
112 |
test regexp-3.4 {-indices option to regexp} {
|
sl@0
|
113 |
set foo {}
|
sl@0
|
114 |
set f2 {}
|
sl@0
|
115 |
set f3 {}
|
sl@0
|
116 |
list [regexp -indices a(b*)(c) abbbbc foo f2 f3] $foo $f2 $f3
|
sl@0
|
117 |
} {1 {0 5} {1 4} {5 5}}
|
sl@0
|
118 |
test regexp-3.5 {-indices option to regexp} {
|
sl@0
|
119 |
set foo {}; set f1 {}; set f2 {}; set f3 {}; set f4 {}; set f5 {};
|
sl@0
|
120 |
set f6 {}; set f7 {}; set f8 {}; set f9 {}
|
sl@0
|
121 |
list [regexp -indices (1*)(2*)(3*)(4*)(5*)(6*)(7*)(8*)(9*) \
|
sl@0
|
122 |
12223345556789999 \
|
sl@0
|
123 |
foo f1 f2 f3 f4 f5 f6 f7 f8 f9] $foo $f1 $f2 $f3 $f4 $f5 \
|
sl@0
|
124 |
$f6 $f7 $f8 $f9
|
sl@0
|
125 |
} {1 {0 16} {0 0} {1 3} {4 5} {6 6} {7 9} {10 10} {11 11} {12 12} {13 16}}
|
sl@0
|
126 |
test regexp-3.6 {getting substrings back from regexp} {
|
sl@0
|
127 |
set foo 2; set f2 2; set f3 2; set f4 2
|
sl@0
|
128 |
list [regexp -indices (a)(b)? xay foo f2 f3 f4] $foo $f2 $f3 $f4
|
sl@0
|
129 |
} {1 {1 1} {1 1} {-1 -1} {-1 -1}}
|
sl@0
|
130 |
test regexp-3.7 {getting substrings back from regexp} {
|
sl@0
|
131 |
set foo 1; set f2 1; set f3 1; set f4 1
|
sl@0
|
132 |
list [regexp -indices (a)(b)?(c) xacy foo f2 f3 f4] $foo $f2 $f3 $f4
|
sl@0
|
133 |
} {1 {1 2} {1 1} {-1 -1} {2 2}}
|
sl@0
|
134 |
|
sl@0
|
135 |
test regexp-4.1 {-nocase option to regexp} {
|
sl@0
|
136 |
regexp -nocase foo abcFOo
|
sl@0
|
137 |
} 1
|
sl@0
|
138 |
test regexp-4.2 {-nocase option to regexp} {
|
sl@0
|
139 |
set f1 22
|
sl@0
|
140 |
set f2 33
|
sl@0
|
141 |
set f3 44
|
sl@0
|
142 |
list [regexp -nocase {a(b*)([xy]*)z} aBbbxYXxxZ22 f1 f2 f3] $f1 $f2 $f3
|
sl@0
|
143 |
} {1 aBbbxYXxxZ Bbb xYXxx}
|
sl@0
|
144 |
test regexp-4.3 {-nocase option to regexp} {
|
sl@0
|
145 |
regexp -nocase FOo abcFOo
|
sl@0
|
146 |
} 1
|
sl@0
|
147 |
set x abcdefghijklmnopqrstuvwxyz1234567890
|
sl@0
|
148 |
set x $x$x$x$x$x$x$x$x$x$x$x$x
|
sl@0
|
149 |
test regexp-4.4 {case conversion in regexp} {
|
sl@0
|
150 |
list [regexp -nocase $x $x foo] $foo
|
sl@0
|
151 |
} "1 $x"
|
sl@0
|
152 |
catch {unset x}
|
sl@0
|
153 |
|
sl@0
|
154 |
test regexp-5.1 {exercise cache of compiled expressions} {
|
sl@0
|
155 |
regexp .*a b
|
sl@0
|
156 |
regexp .*b c
|
sl@0
|
157 |
regexp .*c d
|
sl@0
|
158 |
regexp .*d e
|
sl@0
|
159 |
regexp .*e f
|
sl@0
|
160 |
regexp .*a bbba
|
sl@0
|
161 |
} 1
|
sl@0
|
162 |
test regexp-5.2 {exercise cache of compiled expressions} {
|
sl@0
|
163 |
regexp .*a b
|
sl@0
|
164 |
regexp .*b c
|
sl@0
|
165 |
regexp .*c d
|
sl@0
|
166 |
regexp .*d e
|
sl@0
|
167 |
regexp .*e f
|
sl@0
|
168 |
regexp .*b xxxb
|
sl@0
|
169 |
} 1
|
sl@0
|
170 |
test regexp-5.3 {exercise cache of compiled expressions} {
|
sl@0
|
171 |
regexp .*a b
|
sl@0
|
172 |
regexp .*b c
|
sl@0
|
173 |
regexp .*c d
|
sl@0
|
174 |
regexp .*d e
|
sl@0
|
175 |
regexp .*e f
|
sl@0
|
176 |
regexp .*c yyyc
|
sl@0
|
177 |
} 1
|
sl@0
|
178 |
test regexp-5.4 {exercise cache of compiled expressions} {
|
sl@0
|
179 |
regexp .*a b
|
sl@0
|
180 |
regexp .*b c
|
sl@0
|
181 |
regexp .*c d
|
sl@0
|
182 |
regexp .*d e
|
sl@0
|
183 |
regexp .*e f
|
sl@0
|
184 |
regexp .*d 1d
|
sl@0
|
185 |
} 1
|
sl@0
|
186 |
test regexp-5.5 {exercise cache of compiled expressions} {
|
sl@0
|
187 |
regexp .*a b
|
sl@0
|
188 |
regexp .*b c
|
sl@0
|
189 |
regexp .*c d
|
sl@0
|
190 |
regexp .*d e
|
sl@0
|
191 |
regexp .*e f
|
sl@0
|
192 |
regexp .*e xe
|
sl@0
|
193 |
} 1
|
sl@0
|
194 |
|
sl@0
|
195 |
test regexp-6.1 {regexp errors} {
|
sl@0
|
196 |
list [catch {regexp a} msg] $msg
|
sl@0
|
197 |
} {1 {wrong # args: should be "regexp ?switches? exp string ?matchVar? ?subMatchVar subMatchVar ...?"}}
|
sl@0
|
198 |
test regexp-6.2 {regexp errors} {
|
sl@0
|
199 |
list [catch {regexp -nocase a} msg] $msg
|
sl@0
|
200 |
} {1 {wrong # args: should be "regexp ?switches? exp string ?matchVar? ?subMatchVar subMatchVar ...?"}}
|
sl@0
|
201 |
test regexp-6.3 {regexp errors} {
|
sl@0
|
202 |
list [catch {regexp -gorp a} msg] $msg
|
sl@0
|
203 |
} {1 {bad switch "-gorp": must be -all, -about, -indices, -inline, -expanded, -line, -linestop, -lineanchor, -nocase, -start, or --}}
|
sl@0
|
204 |
test regexp-6.4 {regexp errors} {
|
sl@0
|
205 |
list [catch {regexp a( b} msg] $msg
|
sl@0
|
206 |
} {1 {couldn't compile regular expression pattern: parentheses () not balanced}}
|
sl@0
|
207 |
test regexp-6.5 {regexp errors} {
|
sl@0
|
208 |
list [catch {regexp a( b} msg] $msg
|
sl@0
|
209 |
} {1 {couldn't compile regular expression pattern: parentheses () not balanced}}
|
sl@0
|
210 |
test regexp-6.6 {regexp errors} {
|
sl@0
|
211 |
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
|
212 |
} {0 1}
|
sl@0
|
213 |
test regexp-6.7 {regexp errors} {
|
sl@0
|
214 |
list [catch {regexp (x)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.) xyzzy} msg] $msg
|
sl@0
|
215 |
} {0 0}
|
sl@0
|
216 |
test regexp-6.8 {regexp errors} {
|
sl@0
|
217 |
catch {unset f1}
|
sl@0
|
218 |
set f1 44
|
sl@0
|
219 |
list [catch {regexp abc abc f1(f2)} msg] $msg
|
sl@0
|
220 |
} {1 {couldn't set variable "f1(f2)"}}
|
sl@0
|
221 |
test regexp-6.9 {regexp errors, -start bad int check} {
|
sl@0
|
222 |
list [catch {regexp -start bogus {^$} {}} msg] $msg
|
sl@0
|
223 |
} {1 {expected integer but got "bogus"}}
|
sl@0
|
224 |
|
sl@0
|
225 |
test regexp-7.1 {basic regsub operation} {
|
sl@0
|
226 |
list [regsub aa+ xaxaaaxaa 111&222 foo] $foo
|
sl@0
|
227 |
} {1 xax111aaa222xaa}
|
sl@0
|
228 |
test regexp-7.2 {basic regsub operation} {
|
sl@0
|
229 |
list [regsub aa+ aaaxaa &111 foo] $foo
|
sl@0
|
230 |
} {1 aaa111xaa}
|
sl@0
|
231 |
test regexp-7.3 {basic regsub operation} {
|
sl@0
|
232 |
list [regsub aa+ xaxaaa 111& foo] $foo
|
sl@0
|
233 |
} {1 xax111aaa}
|
sl@0
|
234 |
test regexp-7.4 {basic regsub operation} {
|
sl@0
|
235 |
list [regsub aa+ aaa 11&2&333 foo] $foo
|
sl@0
|
236 |
} {1 11aaa2aaa333}
|
sl@0
|
237 |
test regexp-7.5 {basic regsub operation} {
|
sl@0
|
238 |
list [regsub aa+ xaxaaaxaa &2&333 foo] $foo
|
sl@0
|
239 |
} {1 xaxaaa2aaa333xaa}
|
sl@0
|
240 |
test regexp-7.6 {basic regsub operation} {
|
sl@0
|
241 |
list [regsub aa+ xaxaaaxaa 1&22& foo] $foo
|
sl@0
|
242 |
} {1 xax1aaa22aaaxaa}
|
sl@0
|
243 |
test regexp-7.7 {basic regsub operation} {
|
sl@0
|
244 |
list [regsub a(a+) xaxaaaxaa {1\122\1} foo] $foo
|
sl@0
|
245 |
} {1 xax1aa22aaxaa}
|
sl@0
|
246 |
test regexp-7.8 {basic regsub operation} {
|
sl@0
|
247 |
list [regsub a(a+) xaxaaaxaa {1\\\122\1} foo] $foo
|
sl@0
|
248 |
} "1 {xax1\\aa22aaxaa}"
|
sl@0
|
249 |
test regexp-7.9 {basic regsub operation} {
|
sl@0
|
250 |
list [regsub a(a+) xaxaaaxaa {1\\122\1} foo] $foo
|
sl@0
|
251 |
} "1 {xax1\\122aaxaa}"
|
sl@0
|
252 |
test regexp-7.10 {basic regsub operation} {
|
sl@0
|
253 |
list [regsub a(a+) xaxaaaxaa {1\\&\1} foo] $foo
|
sl@0
|
254 |
} "1 {xax1\\aaaaaxaa}"
|
sl@0
|
255 |
test regexp-7.11 {basic regsub operation} {
|
sl@0
|
256 |
list [regsub a(a+) xaxaaaxaa {1\&\1} foo] $foo
|
sl@0
|
257 |
} {1 xax1&aaxaa}
|
sl@0
|
258 |
test regexp-7.12 {basic regsub operation} {
|
sl@0
|
259 |
list [regsub a(a+) xaxaaaxaa {\1\1\1\1&&} foo] $foo
|
sl@0
|
260 |
} {1 xaxaaaaaaaaaaaaaaxaa}
|
sl@0
|
261 |
test regexp-7.13 {basic regsub operation} {
|
sl@0
|
262 |
set foo xxx
|
sl@0
|
263 |
list [regsub abc xyz 111 foo] $foo
|
sl@0
|
264 |
} {0 xyz}
|
sl@0
|
265 |
test regexp-7.14 {basic regsub operation} {
|
sl@0
|
266 |
set foo xxx
|
sl@0
|
267 |
list [regsub ^ xyz "111 " foo] $foo
|
sl@0
|
268 |
} {1 {111 xyz}}
|
sl@0
|
269 |
test regexp-7.15 {basic regsub operation} {
|
sl@0
|
270 |
set foo xxx
|
sl@0
|
271 |
list [regsub -- -foo abc-foodef "111 " foo] $foo
|
sl@0
|
272 |
} {1 {abc111 def}}
|
sl@0
|
273 |
test regexp-7.16 {basic regsub operation} {
|
sl@0
|
274 |
set foo xxx
|
sl@0
|
275 |
list [regsub x "" y foo] $foo
|
sl@0
|
276 |
} {0 {}}
|
sl@0
|
277 |
test regexp-7.17 {regsub utf compliance} {
|
sl@0
|
278 |
# if not UTF-8 aware, result is "0 1"
|
sl@0
|
279 |
set foo "xyz555ijka\u4e4ebpqr"
|
sl@0
|
280 |
regsub a\u4e4eb xyza\u4e4ebijka\u4e4ebpqr 555 bar
|
sl@0
|
281 |
list [string compare $foo $bar] [regexp 4 $bar]
|
sl@0
|
282 |
} {0 0}
|
sl@0
|
283 |
|
sl@0
|
284 |
test regexp-8.1 {case conversion in regsub} {
|
sl@0
|
285 |
list [regsub -nocase a(a+) xaAAaAAay & foo] $foo
|
sl@0
|
286 |
} {1 xaAAaAAay}
|
sl@0
|
287 |
test regexp-8.2 {case conversion in regsub} {
|
sl@0
|
288 |
list [regsub -nocase a(a+) xaAAaAAay & foo] $foo
|
sl@0
|
289 |
} {1 xaAAaAAay}
|
sl@0
|
290 |
test regexp-8.3 {case conversion in regsub} {
|
sl@0
|
291 |
set foo 123
|
sl@0
|
292 |
list [regsub a(a+) xaAAaAAay & foo] $foo
|
sl@0
|
293 |
} {0 xaAAaAAay}
|
sl@0
|
294 |
test regexp-8.4 {case conversion in regsub} {
|
sl@0
|
295 |
set foo 123
|
sl@0
|
296 |
list [regsub -nocase a CaDE b foo] $foo
|
sl@0
|
297 |
} {1 CbDE}
|
sl@0
|
298 |
test regexp-8.5 {case conversion in regsub} {
|
sl@0
|
299 |
set foo 123
|
sl@0
|
300 |
list [regsub -nocase XYZ CxYzD b foo] $foo
|
sl@0
|
301 |
} {1 CbD}
|
sl@0
|
302 |
test regexp-8.6 {case conversion in regsub} {
|
sl@0
|
303 |
set x abcdefghijklmnopqrstuvwxyz1234567890
|
sl@0
|
304 |
set x $x$x$x$x$x$x$x$x$x$x$x$x
|
sl@0
|
305 |
set foo 123
|
sl@0
|
306 |
list [regsub -nocase $x $x b foo] $foo
|
sl@0
|
307 |
} {1 b}
|
sl@0
|
308 |
|
sl@0
|
309 |
test regexp-9.1 {-all option to regsub} {
|
sl@0
|
310 |
set foo 86
|
sl@0
|
311 |
list [regsub -all x+ axxxbxxcxdx |&| foo] $foo
|
sl@0
|
312 |
} {4 a|xxx|b|xx|c|x|d|x|}
|
sl@0
|
313 |
test regexp-9.2 {-all option to regsub} {
|
sl@0
|
314 |
set foo 86
|
sl@0
|
315 |
list [regsub -nocase -all x+ aXxXbxxcXdx |&| foo] $foo
|
sl@0
|
316 |
} {4 a|XxX|b|xx|c|X|d|x|}
|
sl@0
|
317 |
test regexp-9.3 {-all option to regsub} {
|
sl@0
|
318 |
set foo 86
|
sl@0
|
319 |
list [regsub x+ axxxbxxcxdx |&| foo] $foo
|
sl@0
|
320 |
} {1 a|xxx|bxxcxdx}
|
sl@0
|
321 |
test regexp-9.4 {-all option to regsub} {
|
sl@0
|
322 |
set foo 86
|
sl@0
|
323 |
list [regsub -all bc axxxbxxcxdx |&| foo] $foo
|
sl@0
|
324 |
} {0 axxxbxxcxdx}
|
sl@0
|
325 |
test regexp-9.5 {-all option to regsub} {
|
sl@0
|
326 |
set foo xxx
|
sl@0
|
327 |
list [regsub -all node "node node more" yy foo] $foo
|
sl@0
|
328 |
} {2 {yy yy more}}
|
sl@0
|
329 |
test regexp-9.6 {-all option to regsub} {
|
sl@0
|
330 |
set foo xxx
|
sl@0
|
331 |
list [regsub -all ^ xxx 123 foo] $foo
|
sl@0
|
332 |
} {1 123xxx}
|
sl@0
|
333 |
|
sl@0
|
334 |
test regexp-10.1 {expanded syntax in regsub} {
|
sl@0
|
335 |
set foo xxx
|
sl@0
|
336 |
list [regsub -expanded ". \#comment\n . \#comment2" abc def foo] $foo
|
sl@0
|
337 |
} {1 defc}
|
sl@0
|
338 |
test regexp-10.2 {newline sensitivity in regsub} {
|
sl@0
|
339 |
set foo xxx
|
sl@0
|
340 |
list [regsub -line {^a.*b$} "dabc\naxyb\n" 123 foo] $foo
|
sl@0
|
341 |
} "1 {dabc\n123\n}"
|
sl@0
|
342 |
test regexp-10.3 {newline sensitivity in regsub} {
|
sl@0
|
343 |
set foo xxx
|
sl@0
|
344 |
list [regsub -line {^a.*b$} "dabc\naxyb\nxb" 123 foo] $foo
|
sl@0
|
345 |
} "1 {dabc\n123\nxb}"
|
sl@0
|
346 |
test regexp-10.4 {partial newline sensitivity in regsub} {
|
sl@0
|
347 |
set foo xxx
|
sl@0
|
348 |
list [regsub -lineanchor {^a.*b$} "da\naxyb\nxb" 123 foo] $foo
|
sl@0
|
349 |
} "1 {da\n123}"
|
sl@0
|
350 |
test regexp-10.5 {inverse partial newline sensitivity in regsub} {
|
sl@0
|
351 |
set foo xxx
|
sl@0
|
352 |
list [regsub -linestop {a.*b} "da\nbaxyb\nxb" 123 foo] $foo
|
sl@0
|
353 |
} "1 {da\nb123\nxb}"
|
sl@0
|
354 |
|
sl@0
|
355 |
test regexp-11.1 {regsub errors} {
|
sl@0
|
356 |
list [catch {regsub a b} msg] $msg
|
sl@0
|
357 |
} {1 {wrong # args: should be "regsub ?switches? exp string subSpec ?varName?"}}
|
sl@0
|
358 |
test regexp-11.2 {regsub errors} {
|
sl@0
|
359 |
list [catch {regsub -nocase a b} msg] $msg
|
sl@0
|
360 |
} {1 {wrong # args: should be "regsub ?switches? exp string subSpec ?varName?"}}
|
sl@0
|
361 |
test regexp-11.3 {regsub errors} {
|
sl@0
|
362 |
list [catch {regsub -nocase -all a b} msg] $msg
|
sl@0
|
363 |
} {1 {wrong # args: should be "regsub ?switches? exp string subSpec ?varName?"}}
|
sl@0
|
364 |
test regexp-11.4 {regsub errors} {
|
sl@0
|
365 |
list [catch {regsub a b c d e f} msg] $msg
|
sl@0
|
366 |
} {1 {wrong # args: should be "regsub ?switches? exp string subSpec ?varName?"}}
|
sl@0
|
367 |
test regexp-11.5 {regsub errors} {
|
sl@0
|
368 |
list [catch {regsub -gorp a b c} msg] $msg
|
sl@0
|
369 |
} {1 {bad switch "-gorp": must be -all, -nocase, -expanded, -line, -linestop, -lineanchor, -start, or --}}
|
sl@0
|
370 |
test regexp-11.6 {regsub errors} {
|
sl@0
|
371 |
list [catch {regsub -nocase a( b c d} msg] $msg
|
sl@0
|
372 |
} {1 {couldn't compile regular expression pattern: parentheses () not balanced}}
|
sl@0
|
373 |
test regexp-11.7 {regsub errors} {
|
sl@0
|
374 |
catch {unset f1}
|
sl@0
|
375 |
set f1 44
|
sl@0
|
376 |
list [catch {regsub -nocase aaa aaa xxx f1(f2)} msg] $msg
|
sl@0
|
377 |
} {1 {couldn't set variable "f1(f2)"}}
|
sl@0
|
378 |
test regexp-11.8 {regsub errors, -start bad int check} {
|
sl@0
|
379 |
list [catch {regsub -start bogus pattern string rep var} msg] $msg
|
sl@0
|
380 |
} {1 {expected integer but got "bogus"}}
|
sl@0
|
381 |
test regexp-11.9 {regsub without final variable name returns value} {
|
sl@0
|
382 |
regsub b abaca X
|
sl@0
|
383 |
} {aXaca}
|
sl@0
|
384 |
test regexp-11.10 {regsub without final variable name returns value} {
|
sl@0
|
385 |
regsub -all a abaca X
|
sl@0
|
386 |
} {XbXcX}
|
sl@0
|
387 |
test regexp-11.11 {regsub without final variable name returns value} {
|
sl@0
|
388 |
regsub b(.*?)d abcdeabcfde {,&,\1,}
|
sl@0
|
389 |
} {a,bcd,c,eabcfde}
|
sl@0
|
390 |
test regexp-11.12 {regsub without final variable name returns value} {
|
sl@0
|
391 |
regsub -all b(.*?)d abcdeabcfde {,&,\1,}
|
sl@0
|
392 |
} {a,bcd,c,ea,bcfd,cf,e}
|
sl@0
|
393 |
|
sl@0
|
394 |
# This test crashes on the Mac unless you increase the Stack Space to about 1
|
sl@0
|
395 |
# Meg. This is probably bigger than most users want...
|
sl@0
|
396 |
# 8.2.3 regexp reduced stack space requirements, but this should be
|
sl@0
|
397 |
# tested again
|
sl@0
|
398 |
test regexp-12.1 {Tcl_RegExpExec: large number of subexpressions} {macCrash} {
|
sl@0
|
399 |
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
|
400 |
} {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
|
401 |
|
sl@0
|
402 |
test regexp-13.1 {regsub of a very large string} {
|
sl@0
|
403 |
# This test is designed to stress the memory subsystem in order
|
sl@0
|
404 |
# to catch Bug #933. It only fails if the Tcl memory allocator
|
sl@0
|
405 |
# is in use.
|
sl@0
|
406 |
|
sl@0
|
407 |
set line {BEGIN_TABLE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; END_TABLE}
|
sl@0
|
408 |
set filedata [string repeat $line 200]
|
sl@0
|
409 |
for {set i 1} {$i<10} {incr i} {
|
sl@0
|
410 |
regsub -all "BEGIN_TABLE " $filedata "" newfiledata
|
sl@0
|
411 |
}
|
sl@0
|
412 |
set x done
|
sl@0
|
413 |
} {done}
|
sl@0
|
414 |
|
sl@0
|
415 |
test regexp-14.1 {CompileRegexp: regexp cache} {
|
sl@0
|
416 |
regexp .*a b
|
sl@0
|
417 |
regexp .*b c
|
sl@0
|
418 |
regexp .*c d
|
sl@0
|
419 |
regexp .*d e
|
sl@0
|
420 |
regexp .*e f
|
sl@0
|
421 |
set x .
|
sl@0
|
422 |
append x *a
|
sl@0
|
423 |
regexp $x bbba
|
sl@0
|
424 |
} 1
|
sl@0
|
425 |
test regexp-14.2 {CompileRegexp: regexp cache, different flags} {
|
sl@0
|
426 |
regexp .*a b
|
sl@0
|
427 |
regexp .*b c
|
sl@0
|
428 |
regexp .*c d
|
sl@0
|
429 |
regexp .*d e
|
sl@0
|
430 |
regexp .*e f
|
sl@0
|
431 |
set x .
|
sl@0
|
432 |
append x *a
|
sl@0
|
433 |
regexp -nocase $x bbba
|
sl@0
|
434 |
} 1
|
sl@0
|
435 |
|
sl@0
|
436 |
testConstraint exec [llength [info commands exec]]
|
sl@0
|
437 |
test regexp-14.3 {CompileRegexp: regexp cache, empty regexp and empty cache} -constraints {
|
sl@0
|
438 |
exec
|
sl@0
|
439 |
} -setup {
|
sl@0
|
440 |
set junk [makeFile {puts [regexp {} foo]} junk.tcl]
|
sl@0
|
441 |
} -body {
|
sl@0
|
442 |
exec [interpreter] $junk
|
sl@0
|
443 |
} -cleanup {
|
sl@0
|
444 |
removeFile junk.tcl
|
sl@0
|
445 |
} -result 1
|
sl@0
|
446 |
|
sl@0
|
447 |
test regexp-15.1 {regexp -start} {
|
sl@0
|
448 |
catch {unset x}
|
sl@0
|
449 |
list [regexp -start -10 {\d} 1abc2de3 x] $x
|
sl@0
|
450 |
} {1 1}
|
sl@0
|
451 |
test regexp-15.2 {regexp -start} {
|
sl@0
|
452 |
catch {unset x}
|
sl@0
|
453 |
list [regexp -start 2 {\d} 1abc2de3 x] $x
|
sl@0
|
454 |
} {1 2}
|
sl@0
|
455 |
test regexp-15.3 {regexp -start} {
|
sl@0
|
456 |
catch {unset x}
|
sl@0
|
457 |
list [regexp -start 4 {\d} 1abc2de3 x] $x
|
sl@0
|
458 |
} {1 2}
|
sl@0
|
459 |
test regexp-15.4 {regexp -start} {
|
sl@0
|
460 |
catch {unset x}
|
sl@0
|
461 |
list [regexp -start 5 {\d} 1abc2de3 x] $x
|
sl@0
|
462 |
} {1 3}
|
sl@0
|
463 |
test regexp-15.5 {regexp -start, over end of string} {
|
sl@0
|
464 |
catch {unset x}
|
sl@0
|
465 |
list [regexp -start [string length 1abc2de3] {\d} 1abc2de3 x] [info exists x]
|
sl@0
|
466 |
} {0 0}
|
sl@0
|
467 |
test regexp-15.6 {regexp -start, loss of ^$ behavior} {
|
sl@0
|
468 |
list [regexp -start 2 {^$} {}]
|
sl@0
|
469 |
} {0}
|
sl@0
|
470 |
|
sl@0
|
471 |
test regexp-16.1 {regsub -start} {
|
sl@0
|
472 |
catch {unset x}
|
sl@0
|
473 |
list [regsub -all -start 2 {\d} a1b2c3d4e5 {/&} x] $x
|
sl@0
|
474 |
} {4 a1b/2c/3d/4e/5}
|
sl@0
|
475 |
test regexp-16.2 {regsub -start} {
|
sl@0
|
476 |
catch {unset x}
|
sl@0
|
477 |
list [regsub -all -start -25 {z} hello {/&} x] $x
|
sl@0
|
478 |
} {0 hello}
|
sl@0
|
479 |
test regexp-16.3 {regsub -start} {
|
sl@0
|
480 |
catch {unset x}
|
sl@0
|
481 |
list [regsub -all -start 3 {z} hello {/&} x] $x
|
sl@0
|
482 |
} {0 hello}
|
sl@0
|
483 |
test regexp-16.4 {regsub -start, \A behavior} {
|
sl@0
|
484 |
set out {}
|
sl@0
|
485 |
lappend out [regsub -start 0 -all {\A(\w)} {abcde} {/\1} x] $x
|
sl@0
|
486 |
lappend out [regsub -start 2 -all {\A(\w)} {abcde} {/\1} x] $x
|
sl@0
|
487 |
} {5 /a/b/c/d/e 3 ab/c/d/e}
|
sl@0
|
488 |
|
sl@0
|
489 |
test regexp-17.1 {regexp -inline} {
|
sl@0
|
490 |
regexp -inline b ababa
|
sl@0
|
491 |
} {b}
|
sl@0
|
492 |
test regexp-17.2 {regexp -inline} {
|
sl@0
|
493 |
regexp -inline (b) ababa
|
sl@0
|
494 |
} {b b}
|
sl@0
|
495 |
test regexp-17.3 {regexp -inline -indices} {
|
sl@0
|
496 |
regexp -inline -indices (b) ababa
|
sl@0
|
497 |
} {{1 1} {1 1}}
|
sl@0
|
498 |
test regexp-17.4 {regexp -inline} {
|
sl@0
|
499 |
regexp -inline {\w(\d+)\w} " hello 23 there456def "
|
sl@0
|
500 |
} {e456d 456}
|
sl@0
|
501 |
test regexp-17.5 {regexp -inline no matches} {
|
sl@0
|
502 |
regexp -inline {\w(\d+)\w} ""
|
sl@0
|
503 |
} {}
|
sl@0
|
504 |
test regexp-17.6 {regexp -inline no matches} {
|
sl@0
|
505 |
regexp -inline hello goodbye
|
sl@0
|
506 |
} {}
|
sl@0
|
507 |
test regexp-17.7 {regexp -inline, no matchvars allowed} {
|
sl@0
|
508 |
list [catch {regexp -inline b abc match} msg] $msg
|
sl@0
|
509 |
} {1 {regexp match variables not allowed when using -inline}}
|
sl@0
|
510 |
|
sl@0
|
511 |
test regexp-18.1 {regexp -all} {
|
sl@0
|
512 |
regexp -all b bbbbb
|
sl@0
|
513 |
} {5}
|
sl@0
|
514 |
test regexp-18.2 {regexp -all} {
|
sl@0
|
515 |
regexp -all b abababbabaaaaaaaaaab
|
sl@0
|
516 |
} {6}
|
sl@0
|
517 |
test regexp-18.3 {regexp -all -inline} {
|
sl@0
|
518 |
regexp -all -inline b abababbabaaaaaaaaaab
|
sl@0
|
519 |
} {b b b b b b}
|
sl@0
|
520 |
test regexp-18.4 {regexp -all -inline} {
|
sl@0
|
521 |
regexp -all -inline {\w(\w)} abcdefg
|
sl@0
|
522 |
} {ab b cd d ef f}
|
sl@0
|
523 |
test regexp-18.5 {regexp -all -inline} {
|
sl@0
|
524 |
regexp -all -inline {\w(\w)$} abcdefg
|
sl@0
|
525 |
} {fg g}
|
sl@0
|
526 |
test regexp-18.6 {regexp -all -inline} {
|
sl@0
|
527 |
regexp -all -inline {\d+} 10:20:30:40
|
sl@0
|
528 |
} {10 20 30 40}
|
sl@0
|
529 |
test regexp-18.7 {regexp -all -inline} {
|
sl@0
|
530 |
list [catch {regexp -all -inline b abc match} msg] $msg
|
sl@0
|
531 |
} {1 {regexp match variables not allowed when using -inline}}
|
sl@0
|
532 |
test regexp-18.8 {regexp -all} {
|
sl@0
|
533 |
# This should not cause an infinite loop
|
sl@0
|
534 |
regexp -all -inline {a*} a
|
sl@0
|
535 |
} {a}
|
sl@0
|
536 |
test regexp-18.9 {regexp -all} {
|
sl@0
|
537 |
# Yes, the expected result is {a {}}. Here's why:
|
sl@0
|
538 |
# Start at index 0; a* matches the "a" there then stops.
|
sl@0
|
539 |
# Go to index 1; a* matches the lambda (or {}) there then stops. Recall
|
sl@0
|
540 |
# that a* matches zero or more "a"'s; thus it matches the string "b", as
|
sl@0
|
541 |
# there are zero or more "a"'s there.
|
sl@0
|
542 |
# Go to index 2; this is past the end of the string, so stop.
|
sl@0
|
543 |
regexp -all -inline {a*} ab
|
sl@0
|
544 |
} {a {}}
|
sl@0
|
545 |
test regexp-18.10 {regexp -all} {
|
sl@0
|
546 |
# Yes, the expected result is {a {} a}. Here's why:
|
sl@0
|
547 |
# Start at index 0; a* matches the "a" there then stops.
|
sl@0
|
548 |
# Go to index 1; a* matches the lambda (or {}) there then stops. Recall
|
sl@0
|
549 |
# that a* matches zero or more "a"'s; thus it matches the string "b", as
|
sl@0
|
550 |
# there are zero or more "a"'s there.
|
sl@0
|
551 |
# Go to index 2; a* matches the "a" there then stops.
|
sl@0
|
552 |
# Go to index 3; this is past the end of the string, so stop.
|
sl@0
|
553 |
regexp -all -inline {a*} aba
|
sl@0
|
554 |
} {a {} a}
|
sl@0
|
555 |
test regexp-18.11 {regexp -all} {
|
sl@0
|
556 |
regexp -all -inline {^a} aaaa
|
sl@0
|
557 |
} {a}
|
sl@0
|
558 |
test regexp-18.12 {regexp -all -inline -indices} {
|
sl@0
|
559 |
regexp -all -inline -indices a(b(c)d|e(f)g)h abcdhaefgh
|
sl@0
|
560 |
} {{0 4} {1 3} {2 2} {-1 -1} {5 9} {6 8} {-1 -1} {7 7}}
|
sl@0
|
561 |
|
sl@0
|
562 |
test regexp-19.1 {regsub null replacement} {
|
sl@0
|
563 |
regsub -all {@} {@hel@lo@} "\0a\0" result
|
sl@0
|
564 |
list $result [string length $result]
|
sl@0
|
565 |
} "\0a\0hel\0a\0lo\0a\0 14"
|
sl@0
|
566 |
|
sl@0
|
567 |
test regexp-20.1 {regsub shared object shimmering} {
|
sl@0
|
568 |
# Bug #461322
|
sl@0
|
569 |
set a abcdefghijklmnopqurstuvwxyz
|
sl@0
|
570 |
set b $a
|
sl@0
|
571 |
set c abcdefghijklmnopqurstuvwxyz0123456789
|
sl@0
|
572 |
regsub $a $c $b d
|
sl@0
|
573 |
list $d [string length $d] [string bytelength $d]
|
sl@0
|
574 |
} [list abcdefghijklmnopqurstuvwxyz0123456789 37 37]
|
sl@0
|
575 |
test regexp-20.2 {regsub shared object shimmering with -about} {
|
sl@0
|
576 |
eval regexp -about abc
|
sl@0
|
577 |
} {0 {}}
|
sl@0
|
578 |
|
sl@0
|
579 |
test regexp-21.1 {regsub works with empty string} {
|
sl@0
|
580 |
regsub -- ^ {} foo
|
sl@0
|
581 |
} {foo}
|
sl@0
|
582 |
|
sl@0
|
583 |
test regexp-21.2 {regsub works with empty string} {
|
sl@0
|
584 |
regsub -- \$ {} foo
|
sl@0
|
585 |
} {foo}
|
sl@0
|
586 |
|
sl@0
|
587 |
test regexp-21.3 {regsub works with empty string offset} {
|
sl@0
|
588 |
regsub -start 0 -- ^ {} foo
|
sl@0
|
589 |
} {foo}
|
sl@0
|
590 |
|
sl@0
|
591 |
test regexp-21.4 {regsub works with empty string offset} {
|
sl@0
|
592 |
regsub -start 0 -- \$ {} foo
|
sl@0
|
593 |
} {foo}
|
sl@0
|
594 |
|
sl@0
|
595 |
test regexp-21.5 {regsub works with empty string offset} {
|
sl@0
|
596 |
regsub -start 3 -- \$ {123} foo
|
sl@0
|
597 |
} {123foo}
|
sl@0
|
598 |
|
sl@0
|
599 |
test regexp-21.6 {regexp works with empty string} {
|
sl@0
|
600 |
regexp -- ^ {}
|
sl@0
|
601 |
} {1}
|
sl@0
|
602 |
|
sl@0
|
603 |
test regexp-21.7 {regexp works with empty string} {
|
sl@0
|
604 |
regexp -start 0 -- ^ {}
|
sl@0
|
605 |
} {1}
|
sl@0
|
606 |
|
sl@0
|
607 |
test regexp-21.8 {regexp works with empty string offset} {
|
sl@0
|
608 |
regexp -start 3 -- ^ {123}
|
sl@0
|
609 |
} {0}
|
sl@0
|
610 |
|
sl@0
|
611 |
test regexp-21.9 {regexp works with empty string offset} {
|
sl@0
|
612 |
regexp -start 3 -- \$ {123}
|
sl@0
|
613 |
} {1}
|
sl@0
|
614 |
|
sl@0
|
615 |
test regexp-21.10 {multiple matches handle newlines} {
|
sl@0
|
616 |
regsub -all -lineanchor -- {^#[^\n]*\n} "#one\n#two\n#three\n" foo\n
|
sl@0
|
617 |
} "foo\nfoo\nfoo\n"
|
sl@0
|
618 |
|
sl@0
|
619 |
test regexp-21.11 {multiple matches handle newlines} {
|
sl@0
|
620 |
regsub -all -line -- ^ "a\nb\nc" \#
|
sl@0
|
621 |
} "\#a\n\#b\n\#c"
|
sl@0
|
622 |
|
sl@0
|
623 |
test regexp-21.12 {multiple matches handle newlines} {
|
sl@0
|
624 |
regsub -all -line -- ^ "\n\n" \#
|
sl@0
|
625 |
} "\#\n\#\n\#"
|
sl@0
|
626 |
|
sl@0
|
627 |
test regexp-21.13 {multiple matches handle newlines} {
|
sl@0
|
628 |
regexp -all -inline -indices -line -- ^ "a\nb\nc"
|
sl@0
|
629 |
} {{0 -1} {2 1} {4 3}}
|
sl@0
|
630 |
|
sl@0
|
631 |
# cleanup
|
sl@0
|
632 |
::tcltest::cleanupTests
|
sl@0
|
633 |
return
|