os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/regexpComp.test
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/regexpComp.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,827 @@
1.4 +# Commands covered: regexp, regsub
1.5 +#
1.6 +# This file contains a collection of tests for one or more of the Tcl
1.7 +# built-in commands. Sourcing this file into Tcl runs the tests and
1.8 +# generates output for errors. No output means no errors were found.
1.9 +#
1.10 +# Copyright (c) 1991-1993 The Regents of the University of California.
1.11 +# Copyright (c) 1998 Sun Microsystems, Inc.
1.12 +# Copyright (c) 1998-1999 by Scriptics Corporation.
1.13 +#
1.14 +# See the file "license.terms" for information on usage and redistribution
1.15 +# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
1.16 +#
1.17 +# RCS: @(#) $Id$
1.18 +
1.19 +if {[lsearch [namespace children] ::tcltest] == -1} {
1.20 + package require tcltest 2
1.21 + namespace import -force ::tcltest::*
1.22 +}
1.23 +
1.24 +# Procedure to evaluate a script within a proc, to test compilation
1.25 +# functionality
1.26 +
1.27 +proc evalInProc { script } {
1.28 + proc testProc {} $script
1.29 + set status [catch {
1.30 + testProc
1.31 + } result]
1.32 + rename testProc {}
1.33 + return $result
1.34 + #return [list $status $result]
1.35 +}
1.36 +
1.37 +catch {unset foo}
1.38 +test regexpComp-1.1 {basic regexp operation} {
1.39 + evalInProc {
1.40 + regexp ab*c abbbc
1.41 + }
1.42 +} 1
1.43 +test regexpComp-1.2 {basic regexp operation} {
1.44 + evalInProc {
1.45 + regexp ab*c ac
1.46 + }
1.47 +} 1
1.48 +test regexpComp-1.3 {basic regexp operation} {
1.49 + evalInProc {
1.50 + regexp ab*c ab
1.51 + }
1.52 +} 0
1.53 +test regexpComp-1.4 {basic regexp operation} {
1.54 + evalInProc {
1.55 + regexp -- -gorp abc-gorpxxx
1.56 + }
1.57 +} 1
1.58 +test regexpComp-1.5 {basic regexp operation} {
1.59 + evalInProc {
1.60 + regexp {^([^ ]*)[ ]*([^ ]*)} "" a
1.61 + }
1.62 +} 1
1.63 +test regexpComp-1.6 {basic regexp operation} {
1.64 + list [catch {regexp {} abc} msg] $msg
1.65 +} {0 1}
1.66 +test regexpComp-1.7 {regexp utf compliance} {
1.67 + # if not UTF-8 aware, result is "0 1"
1.68 + evalInProc {
1.69 + set foo "\u4e4eb q"
1.70 + regexp "\u4e4eb q" "a\u4e4eb qw\u5e4e\x4e wq" bar
1.71 + list [string compare $foo $bar] [regexp 4 $bar]
1.72 + }
1.73 +} {0 0}
1.74 +
1.75 +test regexpComp-2.1 {getting substrings back from regexp} {
1.76 + evalInProc {
1.77 + set foo {}
1.78 + list [regexp ab*c abbbbc foo] $foo
1.79 + }
1.80 +} {1 abbbbc}
1.81 +test regexpComp-2.2 {getting substrings back from regexp} {
1.82 + evalInProc {
1.83 + set foo {}
1.84 + set f2 {}
1.85 + list [regexp a(b*)c abbbbc foo f2] $foo $f2
1.86 + }
1.87 +} {1 abbbbc bbbb}
1.88 +test regexpComp-2.3 {getting substrings back from regexp} {
1.89 + evalInProc {
1.90 + set foo {}
1.91 + set f2 {}
1.92 + list [regexp a(b*)(c) abbbbc foo f2] $foo $f2
1.93 + }
1.94 +} {1 abbbbc bbbb}
1.95 +test regexpComp-2.4 {getting substrings back from regexp} {
1.96 + evalInProc {
1.97 + set foo {}
1.98 + set f2 {}
1.99 + set f3 {}
1.100 + list [regexp a(b*)(c) abbbbc foo f2 f3] $foo $f2 $f3
1.101 + }
1.102 +} {1 abbbbc bbbb c}
1.103 +test regexpComp-2.5 {getting substrings back from regexp} {
1.104 + evalInProc {
1.105 + set foo {}; set f1 {}; set f2 {}; set f3 {}; set f4 {}; set f5 {};
1.106 + set f6 {}; set f7 {}; set f8 {}; set f9 {}; set fa {}; set fb {};
1.107 + list [regexp (1*)(2*)(3*)(4*)(5*)(6*)(7*)(8*)(9*)(a*)(b*) \
1.108 + 12223345556789999aabbb \
1.109 + foo f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb] $foo $f1 $f2 $f3 $f4 $f5 \
1.110 + $f6 $f7 $f8 $f9 $fa $fb
1.111 + }
1.112 +} {1 12223345556789999aabbb 1 222 33 4 555 6 7 8 9999 aa bbb}
1.113 +test regexpComp-2.6 {getting substrings back from regexp} {
1.114 + evalInProc {
1.115 + set foo 2; set f2 2; set f3 2; set f4 2
1.116 + list [regexp (a)(b)? xay foo f2 f3 f4] $foo $f2 $f3 $f4
1.117 + }
1.118 +} {1 a a {} {}}
1.119 +test regexpComp-2.7 {getting substrings back from regexp} {
1.120 + evalInProc {
1.121 + set foo 1; set f2 1; set f3 1; set f4 1
1.122 + list [regexp (a)(b)?(c) xacy foo f2 f3 f4] $foo $f2 $f3 $f4
1.123 + }
1.124 +} {1 ac a {} c}
1.125 +test regexpComp-2.8 {getting substrings back from regexp} {
1.126 + evalInProc {
1.127 + set match {}
1.128 + list [regexp {^a*b} aaaab match] $match
1.129 + }
1.130 +} {1 aaaab}
1.131 +
1.132 +test regexpComp-3.1 {-indices option to regexp} {
1.133 + evalInProc {
1.134 + set foo {}
1.135 + list [regexp -indices ab*c abbbbc foo] $foo
1.136 + }
1.137 +} {1 {0 5}}
1.138 +test regexpComp-3.2 {-indices option to regexp} {
1.139 + evalInProc {
1.140 + set foo {}
1.141 + set f2 {}
1.142 + list [regexp -indices a(b*)c abbbbc foo f2] $foo $f2
1.143 + }
1.144 +} {1 {0 5} {1 4}}
1.145 +test regexpComp-3.3 {-indices option to regexp} {
1.146 + evalInProc {
1.147 + set foo {}
1.148 + set f2 {}
1.149 + list [regexp -indices a(b*)(c) abbbbc foo f2] $foo $f2
1.150 + }
1.151 +} {1 {0 5} {1 4}}
1.152 +test regexpComp-3.4 {-indices option to regexp} {
1.153 + evalInProc {
1.154 + set foo {}
1.155 + set f2 {}
1.156 + set f3 {}
1.157 + list [regexp -indices a(b*)(c) abbbbc foo f2 f3] $foo $f2 $f3
1.158 + }
1.159 +} {1 {0 5} {1 4} {5 5}}
1.160 +test regexpComp-3.5 {-indices option to regexp} {
1.161 + evalInProc {
1.162 + set foo {}; set f1 {}; set f2 {}; set f3 {}; set f4 {}; set f5 {};
1.163 + set f6 {}; set f7 {}; set f8 {}; set f9 {}
1.164 + list [regexp -indices (1*)(2*)(3*)(4*)(5*)(6*)(7*)(8*)(9*) \
1.165 + 12223345556789999 \
1.166 + foo f1 f2 f3 f4 f5 f6 f7 f8 f9] $foo $f1 $f2 $f3 $f4 $f5 \
1.167 + $f6 $f7 $f8 $f9
1.168 + }
1.169 +} {1 {0 16} {0 0} {1 3} {4 5} {6 6} {7 9} {10 10} {11 11} {12 12} {13 16}}
1.170 +test regexpComp-3.6 {getting substrings back from regexp} {
1.171 + evalInProc {
1.172 + set foo 2; set f2 2; set f3 2; set f4 2
1.173 + list [regexp -indices (a)(b)? xay foo f2 f3 f4] $foo $f2 $f3 $f4
1.174 + }
1.175 +} {1 {1 1} {1 1} {-1 -1} {-1 -1}}
1.176 +test regexpComp-3.7 {getting substrings back from regexp} {
1.177 + evalInProc {
1.178 + set foo 1; set f2 1; set f3 1; set f4 1
1.179 + list [regexp -indices (a)(b)?(c) xacy foo f2 f3 f4] $foo $f2 $f3 $f4
1.180 + }
1.181 +} {1 {1 2} {1 1} {-1 -1} {2 2}}
1.182 +
1.183 +test regexpComp-4.1 {-nocase option to regexp} {
1.184 + evalInProc {
1.185 + regexp -nocase foo abcFOo
1.186 + }
1.187 +} 1
1.188 +test regexpComp-4.2 {-nocase option to regexp} {
1.189 + evalInProc {
1.190 + set f1 22
1.191 + set f2 33
1.192 + set f3 44
1.193 + list [regexp -nocase {a(b*)([xy]*)z} aBbbxYXxxZ22 f1 f2 f3] $f1 $f2 $f3
1.194 + }
1.195 +} {1 aBbbxYXxxZ Bbb xYXxx}
1.196 +test regexpComp-4.3 {-nocase option to regexp} {
1.197 + evalInProc {
1.198 + regexp -nocase FOo abcFOo
1.199 + }
1.200 +} 1
1.201 +set ::x abcdefghijklmnopqrstuvwxyz1234567890
1.202 +set ::x $x$x$x$x$x$x$x$x$x$x$x$x
1.203 +test regexpComp-4.4 {case conversion in regexp} {
1.204 + evalInProc {
1.205 + list [regexp -nocase $::x $::x foo] $foo
1.206 + }
1.207 +} "1 $x"
1.208 +catch {unset ::x}
1.209 +
1.210 +test regexpComp-5.1 {exercise cache of compiled expressions} {
1.211 + evalInProc {
1.212 + regexp .*a b
1.213 + regexp .*b c
1.214 + regexp .*c d
1.215 + regexp .*d e
1.216 + regexp .*e f
1.217 + regexp .*a bbba
1.218 + }
1.219 +} 1
1.220 +test regexpComp-5.2 {exercise cache of compiled expressions} {
1.221 + evalInProc {
1.222 + regexp .*a b
1.223 + regexp .*b c
1.224 + regexp .*c d
1.225 + regexp .*d e
1.226 + regexp .*e f
1.227 + regexp .*b xxxb
1.228 + }
1.229 +} 1
1.230 +test regexpComp-5.3 {exercise cache of compiled expressions} {
1.231 + evalInProc {
1.232 + regexp .*a b
1.233 + regexp .*b c
1.234 + regexp .*c d
1.235 + regexp .*d e
1.236 + regexp .*e f
1.237 + regexp .*c yyyc
1.238 + }
1.239 +} 1
1.240 +test regexpComp-5.4 {exercise cache of compiled expressions} {
1.241 + evalInProc {
1.242 + regexp .*a b
1.243 + regexp .*b c
1.244 + regexp .*c d
1.245 + regexp .*d e
1.246 + regexp .*e f
1.247 + regexp .*d 1d
1.248 + }
1.249 +} 1
1.250 +test regexpComp-5.5 {exercise cache of compiled expressions} {
1.251 + evalInProc {
1.252 + regexp .*a b
1.253 + regexp .*b c
1.254 + regexp .*c d
1.255 + regexp .*d e
1.256 + regexp .*e f
1.257 + regexp .*e xe
1.258 + }
1.259 +} 1
1.260 +
1.261 +test regexpComp-6.1 {regexp errors} {
1.262 + evalInProc {
1.263 + list [catch {regexp a} msg] $msg
1.264 + }
1.265 +} {1 {wrong # args: should be "regexp ?switches? exp string ?matchVar? ?subMatchVar subMatchVar ...?"}}
1.266 +test regexpComp-6.2 {regexp errors} {
1.267 + evalInProc {
1.268 + list [catch {regexp -nocase a} msg] $msg
1.269 + }
1.270 +} {1 {wrong # args: should be "regexp ?switches? exp string ?matchVar? ?subMatchVar subMatchVar ...?"}}
1.271 +test regexpComp-6.3 {regexp errors} {
1.272 + evalInProc {
1.273 + list [catch {regexp -gorp a} msg] $msg
1.274 + }
1.275 +} {1 {bad switch "-gorp": must be -all, -about, -indices, -inline, -expanded, -line, -linestop, -lineanchor, -nocase, -start, or --}}
1.276 +test regexpComp-6.4 {regexp errors} {
1.277 + evalInProc {
1.278 + list [catch {regexp a( b} msg] $msg
1.279 + }
1.280 +} {1 {couldn't compile regular expression pattern: parentheses () not balanced}}
1.281 +test regexpComp-6.5 {regexp errors} {
1.282 + evalInProc {
1.283 + list [catch {regexp a( b} msg] $msg
1.284 + }
1.285 +} {1 {couldn't compile regular expression pattern: parentheses () not balanced}}
1.286 +test regexpComp-6.6 {regexp errors} {
1.287 + evalInProc {
1.288 + 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
1.289 + }
1.290 +} {0 1}
1.291 +test regexpComp-6.7 {regexp errors} {
1.292 + evalInProc {
1.293 + list [catch {regexp (x)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.) xyzzy} msg] $msg
1.294 + }
1.295 +} {0 0}
1.296 +test regexpComp-6.8 {regexp errors} {
1.297 + evalInProc {
1.298 + catch {unset f1}
1.299 + set f1 44
1.300 + list [catch {regexp abc abc f1(f2)} msg] $msg
1.301 + }
1.302 +} {1 {couldn't set variable "f1(f2)"}}
1.303 +test regexpComp-6.9 {regexp errors, -start bad int check} {
1.304 + evalInProc {
1.305 + list [catch {regexp -start bogus {^$} {}} msg] $msg
1.306 + }
1.307 +} {1 {expected integer but got "bogus"}}
1.308 +
1.309 +test regexpComp-7.1 {basic regsub operation} {
1.310 + evalInProc {
1.311 + list [regsub aa+ xaxaaaxaa 111&222 foo] $foo
1.312 + }
1.313 +} {1 xax111aaa222xaa}
1.314 +test regexpComp-7.2 {basic regsub operation} {
1.315 + evalInProc {
1.316 + list [regsub aa+ aaaxaa &111 foo] $foo
1.317 + }
1.318 +} {1 aaa111xaa}
1.319 +test regexpComp-7.3 {basic regsub operation} {
1.320 + evalInProc {
1.321 + list [regsub aa+ xaxaaa 111& foo] $foo
1.322 + }
1.323 +} {1 xax111aaa}
1.324 +test regexpComp-7.4 {basic regsub operation} {
1.325 + evalInProc {
1.326 + list [regsub aa+ aaa 11&2&333 foo] $foo
1.327 + }
1.328 +} {1 11aaa2aaa333}
1.329 +test regexpComp-7.5 {basic regsub operation} {
1.330 + evalInProc {
1.331 + list [regsub aa+ xaxaaaxaa &2&333 foo] $foo
1.332 + }
1.333 +} {1 xaxaaa2aaa333xaa}
1.334 +test regexpComp-7.6 {basic regsub operation} {
1.335 + evalInProc {
1.336 + list [regsub aa+ xaxaaaxaa 1&22& foo] $foo
1.337 + }
1.338 +} {1 xax1aaa22aaaxaa}
1.339 +test regexpComp-7.7 {basic regsub operation} {
1.340 + evalInProc {
1.341 + list [regsub a(a+) xaxaaaxaa {1\122\1} foo] $foo
1.342 + }
1.343 +} {1 xax1aa22aaxaa}
1.344 +test regexpComp-7.8 {basic regsub operation} {
1.345 + evalInProc {
1.346 + list [regsub a(a+) xaxaaaxaa {1\\\122\1} foo] $foo
1.347 + }
1.348 +} "1 {xax1\\aa22aaxaa}"
1.349 +test regexpComp-7.9 {basic regsub operation} {
1.350 + evalInProc {
1.351 + list [regsub a(a+) xaxaaaxaa {1\\122\1} foo] $foo
1.352 + }
1.353 +} "1 {xax1\\122aaxaa}"
1.354 +test regexpComp-7.10 {basic regsub operation} {
1.355 + evalInProc {
1.356 + list [regsub a(a+) xaxaaaxaa {1\\&\1} foo] $foo
1.357 + }
1.358 +} "1 {xax1\\aaaaaxaa}"
1.359 +test regexpComp-7.11 {basic regsub operation} {
1.360 + evalInProc {
1.361 + list [regsub a(a+) xaxaaaxaa {1\&\1} foo] $foo
1.362 + }
1.363 +} {1 xax1&aaxaa}
1.364 +test regexpComp-7.12 {basic regsub operation} {
1.365 + evalInProc {
1.366 + list [regsub a(a+) xaxaaaxaa {\1\1\1\1&&} foo] $foo
1.367 + }
1.368 +} {1 xaxaaaaaaaaaaaaaaxaa}
1.369 +test regexpComp-7.13 {basic regsub operation} {
1.370 + evalInProc {
1.371 + set foo xxx
1.372 + list [regsub abc xyz 111 foo] $foo
1.373 + }
1.374 +} {0 xyz}
1.375 +test regexpComp-7.14 {basic regsub operation} {
1.376 + evalInProc {
1.377 + set foo xxx
1.378 + list [regsub ^ xyz "111 " foo] $foo
1.379 + }
1.380 +} {1 {111 xyz}}
1.381 +test regexpComp-7.15 {basic regsub operation} {
1.382 + evalInProc {
1.383 + set foo xxx
1.384 + list [regsub -- -foo abc-foodef "111 " foo] $foo
1.385 + }
1.386 +} {1 {abc111 def}}
1.387 +test regexpComp-7.16 {basic regsub operation} {
1.388 + evalInProc {
1.389 + set foo xxx
1.390 + list [regsub x "" y foo] $foo
1.391 + }
1.392 +} {0 {}}
1.393 +test regexpComp-7.17 {regsub utf compliance} {
1.394 + evalInProc {
1.395 + # if not UTF-8 aware, result is "0 1"
1.396 + set foo "xyz555ijka\u4e4ebpqr"
1.397 + regsub a\u4e4eb xyza\u4e4ebijka\u4e4ebpqr 555 bar
1.398 + list [string compare $foo $bar] [regexp 4 $bar]
1.399 + }
1.400 +} {0 0}
1.401 +
1.402 +test regexpComp-8.1 {case conversion in regsub} {
1.403 + evalInProc {
1.404 + list [regsub -nocase a(a+) xaAAaAAay & foo] $foo
1.405 + }
1.406 +} {1 xaAAaAAay}
1.407 +test regexpComp-8.2 {case conversion in regsub} {
1.408 + evalInProc {
1.409 + list [regsub -nocase a(a+) xaAAaAAay & foo] $foo
1.410 + }
1.411 +} {1 xaAAaAAay}
1.412 +test regexpComp-8.3 {case conversion in regsub} {
1.413 + evalInProc {
1.414 + set foo 123
1.415 + list [regsub a(a+) xaAAaAAay & foo] $foo
1.416 + }
1.417 +} {0 xaAAaAAay}
1.418 +test regexpComp-8.4 {case conversion in regsub} {
1.419 + evalInProc {
1.420 + set foo 123
1.421 + list [regsub -nocase a CaDE b foo] $foo
1.422 + }
1.423 +} {1 CbDE}
1.424 +test regexpComp-8.5 {case conversion in regsub} {
1.425 + evalInProc {
1.426 + set foo 123
1.427 + list [regsub -nocase XYZ CxYzD b foo] $foo
1.428 + }
1.429 +} {1 CbD}
1.430 +test regexpComp-8.6 {case conversion in regsub} {
1.431 + evalInProc {
1.432 + set x abcdefghijklmnopqrstuvwxyz1234567890
1.433 + set x $x$x$x$x$x$x$x$x$x$x$x$x
1.434 + set foo 123
1.435 + list [regsub -nocase $x $x b foo] $foo
1.436 + }
1.437 +} {1 b}
1.438 +
1.439 +test regexpComp-9.1 {-all option to regsub} {
1.440 + evalInProc {
1.441 + set foo 86
1.442 + list [regsub -all x+ axxxbxxcxdx |&| foo] $foo
1.443 + }
1.444 +} {4 a|xxx|b|xx|c|x|d|x|}
1.445 +test regexpComp-9.2 {-all option to regsub} {
1.446 + evalInProc {
1.447 + set foo 86
1.448 + list [regsub -nocase -all x+ aXxXbxxcXdx |&| foo] $foo
1.449 + }
1.450 +} {4 a|XxX|b|xx|c|X|d|x|}
1.451 +test regexpComp-9.3 {-all option to regsub} {
1.452 + evalInProc {
1.453 + set foo 86
1.454 + list [regsub x+ axxxbxxcxdx |&| foo] $foo
1.455 + }
1.456 +} {1 a|xxx|bxxcxdx}
1.457 +test regexpComp-9.4 {-all option to regsub} {
1.458 + evalInProc {
1.459 + set foo 86
1.460 + list [regsub -all bc axxxbxxcxdx |&| foo] $foo
1.461 + }
1.462 +} {0 axxxbxxcxdx}
1.463 +test regexpComp-9.5 {-all option to regsub} {
1.464 + evalInProc {
1.465 + set foo xxx
1.466 + list [regsub -all node "node node more" yy foo] $foo
1.467 + }
1.468 +} {2 {yy yy more}}
1.469 +test regexpComp-9.6 {-all option to regsub} {
1.470 + evalInProc {
1.471 + set foo xxx
1.472 + list [regsub -all ^ xxx 123 foo] $foo
1.473 + }
1.474 +} {1 123xxx}
1.475 +
1.476 +test regexpComp-10.1 {expanded syntax in regsub} {
1.477 + evalInProc {
1.478 + set foo xxx
1.479 + list [regsub -expanded ". \#comment\n . \#comment2" abc def foo] $foo
1.480 + }
1.481 +} {1 defc}
1.482 +test regexpComp-10.2 {newline sensitivity in regsub} {
1.483 + evalInProc {
1.484 + set foo xxx
1.485 + list [regsub -line {^a.*b$} "dabc\naxyb\n" 123 foo] $foo
1.486 + }
1.487 +} "1 {dabc\n123\n}"
1.488 +test regexpComp-10.3 {newline sensitivity in regsub} {
1.489 + evalInProc {
1.490 + set foo xxx
1.491 + list [regsub -line {^a.*b$} "dabc\naxyb\nxb" 123 foo] $foo
1.492 + }
1.493 +} "1 {dabc\n123\nxb}"
1.494 +test regexpComp-10.4 {partial newline sensitivity in regsub} {
1.495 + evalInProc {
1.496 + set foo xxx
1.497 + list [regsub -lineanchor {^a.*b$} "da\naxyb\nxb" 123 foo] $foo
1.498 + }
1.499 +} "1 {da\n123}"
1.500 +test regexpComp-10.5 {inverse partial newline sensitivity in regsub} {
1.501 + evalInProc {
1.502 + set foo xxx
1.503 + list [regsub -linestop {a.*b} "da\nbaxyb\nxb" 123 foo] $foo
1.504 + }
1.505 +} "1 {da\nb123\nxb}"
1.506 +
1.507 +test regexpComp-11.1 {regsub errors} {
1.508 + evalInProc {
1.509 + list [catch {regsub a b} msg] $msg
1.510 + }
1.511 +} {1 {wrong # args: should be "regsub ?switches? exp string subSpec ?varName?"}}
1.512 +test regexpComp-11.2 {regsub errors} {
1.513 + evalInProc {
1.514 + list [catch {regsub -nocase a b} msg] $msg
1.515 + }
1.516 +} {1 {wrong # args: should be "regsub ?switches? exp string subSpec ?varName?"}}
1.517 +test regexpComp-11.3 {regsub errors} {
1.518 + evalInProc {
1.519 + list [catch {regsub -nocase -all a b} msg] $msg
1.520 + }
1.521 +} {1 {wrong # args: should be "regsub ?switches? exp string subSpec ?varName?"}}
1.522 +test regexpComp-11.4 {regsub errors} {
1.523 + evalInProc {
1.524 + list [catch {regsub a b c d e f} msg] $msg
1.525 + }
1.526 +} {1 {wrong # args: should be "regsub ?switches? exp string subSpec ?varName?"}}
1.527 +test regexpComp-11.5 {regsub errors} {
1.528 + evalInProc {
1.529 + list [catch {regsub -gorp a b c} msg] $msg
1.530 + }
1.531 +} {1 {bad switch "-gorp": must be -all, -nocase, -expanded, -line, -linestop, -lineanchor, -start, or --}}
1.532 +test regexpComp-11.6 {regsub errors} {
1.533 + evalInProc {
1.534 + list [catch {regsub -nocase a( b c d} msg] $msg
1.535 + }
1.536 +} {1 {couldn't compile regular expression pattern: parentheses () not balanced}}
1.537 +test regexpComp-11.7 {regsub errors} {
1.538 + evalInProc {
1.539 + catch {unset f1}
1.540 + set f1 44
1.541 + list [catch {regsub -nocase aaa aaa xxx f1(f2)} msg] $msg
1.542 + }
1.543 +} {1 {couldn't set variable "f1(f2)"}}
1.544 +test regexpComp-11.8 {regsub errors, -start bad int check} {
1.545 + evalInProc {
1.546 + list [catch {regsub -start bogus pattern string rep var} msg] $msg
1.547 + }
1.548 +} {1 {expected integer but got "bogus"}}
1.549 +
1.550 +# This test crashes on the Mac unless you increase the Stack Space to about 1
1.551 +# Meg. This is probably bigger than most users want...
1.552 +# 8.2.3 regexp reduced stack space requirements, but this should be
1.553 +# tested again
1.554 +test regexpComp-12.1 {Tcl_RegExpExec: large number of subexpressions} {macCrash} {
1.555 + evalInProc {
1.556 + 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
1.557 + }
1.558 +} {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}
1.559 +
1.560 +test regexpComp-13.1 {regsub of a very large string} {
1.561 + # This test is designed to stress the memory subsystem in order
1.562 + # to catch Bug #933. It only fails if the Tcl memory allocator
1.563 + # is in use.
1.564 +
1.565 + set line {BEGIN_TABLE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; END_TABLE}
1.566 + set filedata [string repeat $line 200]
1.567 + for {set i 1} {$i<10} {incr i} {
1.568 + regsub -all "BEGIN_TABLE " $filedata "" newfiledata
1.569 + }
1.570 + set x done
1.571 +} {done}
1.572 +
1.573 +test regexpComp-14.1 {CompileRegexp: regexp cache} {
1.574 + evalInProc {
1.575 + regexp .*a b
1.576 + regexp .*b c
1.577 + regexp .*c d
1.578 + regexp .*d e
1.579 + regexp .*e f
1.580 + set x .
1.581 + append x *a
1.582 + regexp $x bbba
1.583 + }
1.584 +} 1
1.585 +test regexpComp-14.2 {CompileRegexp: regexp cache, different flags} {
1.586 + evalInProc {
1.587 + regexp .*a b
1.588 + regexp .*b c
1.589 + regexp .*c d
1.590 + regexp .*d e
1.591 + regexp .*e f
1.592 + set x .
1.593 + append x *a
1.594 + regexp -nocase $x bbba
1.595 + }
1.596 +} 1
1.597 +
1.598 +testConstraint exec [llength [info commands exec]]
1.599 +test regexpComp-14.3 {CompileRegexp: regexp cache, empty regexp and empty cache} -constraints {
1.600 + exec
1.601 +} -setup {
1.602 + set junk [makeFile {puts [regexp {} foo]} junk.tcl]
1.603 +} -body {
1.604 + exec [interpreter] $junk
1.605 +} -cleanup {
1.606 + removeFile junk.tcl
1.607 +} -result 1
1.608 +
1.609 +test regexpComp-15.1 {regexp -start} {
1.610 + catch {unset x}
1.611 + list [regexp -start -10 {\d} 1abc2de3 x] $x
1.612 +} {1 1}
1.613 +test regexpComp-15.2 {regexp -start} {
1.614 + catch {unset x}
1.615 + list [regexp -start 2 {\d} 1abc2de3 x] $x
1.616 +} {1 2}
1.617 +test regexpComp-15.3 {regexp -start} {
1.618 + catch {unset x}
1.619 + list [regexp -start 4 {\d} 1abc2de3 x] $x
1.620 +} {1 2}
1.621 +test regexpComp-15.4 {regexp -start} {
1.622 + catch {unset x}
1.623 + list [regexp -start 5 {\d} 1abc2de3 x] $x
1.624 +} {1 3}
1.625 +test regexpComp-15.5 {regexp -start, over end of string} {
1.626 + catch {unset x}
1.627 + list [regexp -start [string length 1abc2de3] {\d} 1abc2de3 x] [info exists x]
1.628 +} {0 0}
1.629 +test regexpComp-15.6 {regexp -start, loss of ^$ behavior} {
1.630 + list [regexp -start 2 {^$} {}]
1.631 +} {0}
1.632 +
1.633 +test regexpComp-16.1 {regsub -start} {
1.634 + catch {unset x}
1.635 + list [regsub -all -start 2 {\d} a1b2c3d4e5 {/&} x] $x
1.636 +} {4 a1b/2c/3d/4e/5}
1.637 +test regexpComp-16.2 {regsub -start} {
1.638 + catch {unset x}
1.639 + list [regsub -all -start -25 {z} hello {/&} x] $x
1.640 +} {0 hello}
1.641 +test regexpComp-16.3 {regsub -start} {
1.642 + catch {unset x}
1.643 + list [regsub -all -start 3 {z} hello {/&} x] $x
1.644 +} {0 hello}
1.645 +test regexpComp-16.4 {regsub -start, \A behavior} {
1.646 + set out {}
1.647 + lappend out [regsub -start 0 -all {\A(\w)} {abcde} {/\1} x] $x
1.648 + lappend out [regsub -start 2 -all {\A(\w)} {abcde} {/\1} x] $x
1.649 +} {5 /a/b/c/d/e 3 ab/c/d/e}
1.650 +
1.651 +test regexpComp-17.1 {regexp -inline} {
1.652 + regexp -inline b ababa
1.653 +} {b}
1.654 +test regexpComp-17.2 {regexp -inline} {
1.655 + regexp -inline (b) ababa
1.656 +} {b b}
1.657 +test regexpComp-17.3 {regexp -inline -indices} {
1.658 + regexp -inline -indices (b) ababa
1.659 +} {{1 1} {1 1}}
1.660 +test regexpComp-17.4 {regexp -inline} {
1.661 + regexp -inline {\w(\d+)\w} " hello 23 there456def "
1.662 +} {e456d 456}
1.663 +test regexpComp-17.5 {regexp -inline no matches} {
1.664 + regexp -inline {\w(\d+)\w} ""
1.665 +} {}
1.666 +test regexpComp-17.6 {regexp -inline no matches} {
1.667 + regexp -inline hello goodbye
1.668 +} {}
1.669 +test regexpComp-17.7 {regexp -inline, no matchvars allowed} {
1.670 + list [catch {regexp -inline b abc match} msg] $msg
1.671 +} {1 {regexp match variables not allowed when using -inline}}
1.672 +
1.673 +test regexpComp-18.1 {regexp -all} {
1.674 + regexp -all b bbbbb
1.675 +} {5}
1.676 +test regexpComp-18.2 {regexp -all} {
1.677 + regexp -all b abababbabaaaaaaaaaab
1.678 +} {6}
1.679 +test regexpComp-18.3 {regexp -all -inline} {
1.680 + regexp -all -inline b abababbabaaaaaaaaaab
1.681 +} {b b b b b b}
1.682 +test regexpComp-18.4 {regexp -all -inline} {
1.683 + regexp -all -inline {\w(\w)} abcdefg
1.684 +} {ab b cd d ef f}
1.685 +test regexpComp-18.5 {regexp -all -inline} {
1.686 + regexp -all -inline {\w(\w)$} abcdefg
1.687 +} {fg g}
1.688 +test regexpComp-18.6 {regexp -all -inline} {
1.689 + regexp -all -inline {\d+} 10:20:30:40
1.690 +} {10 20 30 40}
1.691 +test regexpComp-18.7 {regexp -all -inline} {
1.692 + list [catch {regexp -all -inline b abc match} msg] $msg
1.693 +} {1 {regexp match variables not allowed when using -inline}}
1.694 +test regexpComp-18.8 {regexp -all} {
1.695 + # This should not cause an infinite loop
1.696 + regexp -all -inline {a*} a
1.697 +} {a}
1.698 +test regexpComp-18.9 {regexp -all} {
1.699 + # Yes, the expected result is {a {}}. Here's why:
1.700 + # Start at index 0; a* matches the "a" there then stops.
1.701 + # Go to index 1; a* matches the lambda (or {}) there then stops. Recall
1.702 + # that a* matches zero or more "a"'s; thus it matches the string "b", as
1.703 + # there are zero or more "a"'s there.
1.704 + # Go to index 2; this is past the end of the string, so stop.
1.705 + regexp -all -inline {a*} ab
1.706 +} {a {}}
1.707 +test regexpComp-18.10 {regexp -all} {
1.708 + # Yes, the expected result is {a {} a}. Here's why:
1.709 + # Start at index 0; a* matches the "a" there then stops.
1.710 + # Go to index 1; a* matches the lambda (or {}) there then stops. Recall
1.711 + # that a* matches zero or more "a"'s; thus it matches the string "b", as
1.712 + # there are zero or more "a"'s there.
1.713 + # Go to index 2; a* matches the "a" there then stops.
1.714 + # Go to index 3; this is past the end of the string, so stop.
1.715 + regexp -all -inline {a*} aba
1.716 +} {a {} a}
1.717 +test regexpComp-18.11 {regexp -all} {
1.718 + evalInProc {
1.719 + regexp -all -inline {^a} aaaa
1.720 + }
1.721 +} {a}
1.722 +test regexpComp-18.12 {regexp -all -inline -indices} {
1.723 + evalInProc {
1.724 + regexp -all -inline -indices a(b(c)d|e(f)g)h abcdhaefgh
1.725 + }
1.726 +} {{0 4} {1 3} {2 2} {-1 -1} {5 9} {6 8} {-1 -1} {7 7}}
1.727 +
1.728 +test regexpComp-19.1 {regsub null replacement} {
1.729 + evalInProc {
1.730 + regsub -all {@} {@hel@lo@} "\0a\0" result
1.731 + list $result [string length $result]
1.732 + }
1.733 +} "\0a\0hel\0a\0lo\0a\0 14"
1.734 +
1.735 +test regexpComp-20.1 {regsub shared object shimmering} {
1.736 + evalInProc {
1.737 + # Bug #461322
1.738 + set a abcdefghijklmnopqurstuvwxyz
1.739 + set b $a
1.740 + set c abcdefghijklmnopqurstuvwxyz0123456789
1.741 + regsub $a $c $b d
1.742 + list $d [string length $d] [string bytelength $d]
1.743 + }
1.744 +} [list abcdefghijklmnopqurstuvwxyz0123456789 37 37]
1.745 +test regexpComp-20.2 {regsub shared object shimmering with -about} {
1.746 + evalInProc {
1.747 + eval regexp -about abc
1.748 + }
1.749 +} {0 {}}
1.750 +
1.751 +test regexpComp-21.1 {regexp command compiling tests} {
1.752 + evalInProc {
1.753 + regexp foo bar
1.754 + }
1.755 +} 0
1.756 +test regexpComp-21.2 {regexp command compiling tests} {
1.757 + evalInProc {
1.758 + regexp {^foo$} dogfood
1.759 + }
1.760 +} 0
1.761 +test regexpComp-21.3 {regexp command compiling tests} {
1.762 + evalInProc {
1.763 + set a foo
1.764 + regexp {^foo$} $a
1.765 + }
1.766 +} 1
1.767 +test regexpComp-21.4 {regexp command compiling tests} {
1.768 + evalInProc {
1.769 + regexp foo dogfood
1.770 + }
1.771 +} 1
1.772 +test regexpComp-21.5 {regexp command compiling tests} {
1.773 + evalInProc {
1.774 + regexp -nocase FOO dogfod
1.775 + }
1.776 +} 0
1.777 +test regexpComp-21.6 {regexp command compiling tests} {
1.778 + evalInProc {
1.779 + regexp -n foo dogfoOd
1.780 + }
1.781 +} 1
1.782 +test regexpComp-21.7 {regexp command compiling tests} {
1.783 + evalInProc {
1.784 + regexp -no -- FoO dogfood
1.785 + }
1.786 +} 1
1.787 +test regexpComp-21.8 {regexp command compiling tests} {
1.788 + evalInProc {
1.789 + regexp -- foo dogfod
1.790 + }
1.791 +} 0
1.792 +test regexpComp-21.9 {regexp command compiling tests} {
1.793 + evalInProc {
1.794 + list [catch {regexp -- -nocase foo dogfod} msg] $msg
1.795 + }
1.796 +} {0 0}
1.797 +test regexpComp-21.10 {regexp command compiling tests} {
1.798 + evalInProc {
1.799 + list [regsub -all "" foo bar str] $str
1.800 + }
1.801 +} {3 barfbarobaro}
1.802 +test regexpComp-21.11 {regexp command compiling tests} {
1.803 + evalInProc {
1.804 + list [regsub -all "" "" bar str] $str
1.805 + }
1.806 +} {0 {}}
1.807 +
1.808 +set i 0
1.809 +foreach {str exp result} {
1.810 + foo ^foo 1
1.811 + foobar ^foobar$ 1
1.812 + foobar bar$ 1
1.813 + foobar ^$ 0
1.814 + "" ^$ 1
1.815 + anything $ 1
1.816 + anything ^.*$ 1
1.817 + anything ^.*a$ 0
1.818 + anything ^.*a.*$ 1
1.819 + anything ^.*.*$ 1
1.820 + anything ^.*..*$ 1
1.821 + anything ^.*b$ 0
1.822 + anything ^a.*$ 1
1.823 +} {
1.824 + test regexpComp-22.[incr i] {regexp command compiling tests} \
1.825 + [subst {evalInProc {set a "$str"; regexp {$exp} \$a}}] $result
1.826 +}
1.827 +
1.828 +# cleanup
1.829 +::tcltest::cleanupTests
1.830 +return