os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/regexp.test
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/regexp.test	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,633 @@
     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: regexp.test,v 1.22.2.3 2003/10/14 18:22:10 vincentdarley Exp $
    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 +catch {unset foo}
    1.25 +test regexp-1.1 {basic regexp operation} {
    1.26 +    regexp ab*c abbbc
    1.27 +} 1
    1.28 +test regexp-1.2 {basic regexp operation} {
    1.29 +    regexp ab*c ac
    1.30 +} 1
    1.31 +test regexp-1.3 {basic regexp operation} {
    1.32 +    regexp ab*c ab
    1.33 +} 0
    1.34 +test regexp-1.4 {basic regexp operation} {
    1.35 +    regexp -- -gorp abc-gorpxxx
    1.36 +} 1
    1.37 +test regexp-1.5 {basic regexp operation} {
    1.38 +    regexp {^([^ ]*)[ ]*([^ ]*)} "" a
    1.39 +} 1
    1.40 +test regexp-1.6 {basic regexp operation} {
    1.41 +    list [catch {regexp {} abc} msg] $msg
    1.42 +} {0 1}
    1.43 +test regexp-1.7 {regexp utf compliance} {
    1.44 +    # if not UTF-8 aware, result is "0 1"
    1.45 +    set foo "\u4e4eb q"
    1.46 +    regexp "\u4e4eb q" "a\u4e4eb qw\u5e4e\x4e wq" bar
    1.47 +    list [string compare $foo $bar] [regexp 4 $bar]
    1.48 +} {0 0}
    1.49 +
    1.50 +test regexp-2.1 {getting substrings back from regexp} {
    1.51 +    set foo {}
    1.52 +    list [regexp ab*c abbbbc foo] $foo
    1.53 +} {1 abbbbc}
    1.54 +test regexp-2.2 {getting substrings back from regexp} {
    1.55 +    set foo {}
    1.56 +    set f2 {}
    1.57 +    list [regexp a(b*)c abbbbc foo f2] $foo $f2
    1.58 +} {1 abbbbc bbbb}
    1.59 +test regexp-2.3 {getting substrings back from regexp} {
    1.60 +    set foo {}
    1.61 +    set f2 {}
    1.62 +    list [regexp a(b*)(c) abbbbc foo f2] $foo $f2
    1.63 +} {1 abbbbc bbbb}
    1.64 +test regexp-2.4 {getting substrings back from regexp} {
    1.65 +    set foo {}
    1.66 +    set f2 {}
    1.67 +    set f3 {}
    1.68 +    list [regexp a(b*)(c) abbbbc foo f2 f3] $foo $f2 $f3
    1.69 +} {1 abbbbc bbbb c}
    1.70 +test regexp-2.5 {getting substrings back from regexp} {
    1.71 +    set foo {}; set f1 {}; set f2 {}; set f3 {}; set f4 {}; set f5 {};
    1.72 +    set f6 {}; set f7 {}; set f8 {}; set f9 {}; set fa {}; set fb {};
    1.73 +    list [regexp (1*)(2*)(3*)(4*)(5*)(6*)(7*)(8*)(9*)(a*)(b*) \
    1.74 +	      12223345556789999aabbb \
    1.75 +	    foo f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb] $foo $f1 $f2 $f3 $f4 $f5 \
    1.76 +	    $f6 $f7 $f8 $f9 $fa $fb
    1.77 +} {1 12223345556789999aabbb 1 222 33 4 555 6 7 8 9999 aa bbb}
    1.78 +test regexp-2.6 {getting substrings back from regexp} {
    1.79 +    set foo 2; set f2 2; set f3 2; set f4 2
    1.80 +    list [regexp (a)(b)? xay foo f2 f3 f4] $foo $f2 $f3 $f4
    1.81 +} {1 a a {} {}}
    1.82 +test regexp-2.7 {getting substrings back from regexp} {
    1.83 +    set foo 1; set f2 1; set f3 1; set f4 1
    1.84 +    list [regexp (a)(b)?(c) xacy foo f2 f3 f4] $foo $f2 $f3 $f4
    1.85 +} {1 ac a {} c}
    1.86 +test regexp-2.8 {getting substrings back from regexp} {
    1.87 +    set match {}
    1.88 +    list [regexp {^a*b} aaaab match] $match
    1.89 +} {1 aaaab}
    1.90 +test regexp-2.9 {getting substrings back from regexp} {
    1.91 +    set foo {}
    1.92 +    set f2 {}
    1.93 +    list [regexp f\352te(b*)c f\352tebbbbc foo f2] $foo $f2
    1.94 +} [list 1 f\352tebbbbc bbbb]
    1.95 +test regexp-2.10 {getting substrings back from regexp} {
    1.96 +    set foo {}
    1.97 +    set f2 {}
    1.98 +    list [regexp f\352te(b*)c eff\352tebbbbc foo f2] $foo $f2
    1.99 +} [list 1 f\352tebbbbc bbbb]
   1.100 +
   1.101 +test regexp-3.1 {-indices option to regexp} {
   1.102 +    set foo {}
   1.103 +    list [regexp -indices ab*c abbbbc foo] $foo
   1.104 +} {1 {0 5}}
   1.105 +test regexp-3.2 {-indices option to regexp} {
   1.106 +    set foo {}
   1.107 +    set f2 {}
   1.108 +    list [regexp -indices a(b*)c abbbbc foo f2] $foo $f2
   1.109 +} {1 {0 5} {1 4}}
   1.110 +test regexp-3.3 {-indices option to regexp} {
   1.111 +    set foo {}
   1.112 +    set f2 {}
   1.113 +    list [regexp -indices a(b*)(c) abbbbc foo f2] $foo $f2
   1.114 +} {1 {0 5} {1 4}}
   1.115 +test regexp-3.4 {-indices option to regexp} {
   1.116 +    set foo {}
   1.117 +    set f2 {}
   1.118 +    set f3 {}
   1.119 +    list [regexp -indices a(b*)(c) abbbbc foo f2 f3] $foo $f2 $f3
   1.120 +} {1 {0 5} {1 4} {5 5}}
   1.121 +test regexp-3.5 {-indices option to regexp} {
   1.122 +    set foo {}; set f1 {}; set f2 {}; set f3 {}; set f4 {}; set f5 {};
   1.123 +    set f6 {}; set f7 {}; set f8 {}; set f9 {}
   1.124 +    list [regexp -indices (1*)(2*)(3*)(4*)(5*)(6*)(7*)(8*)(9*) \
   1.125 +	    12223345556789999 \
   1.126 +	    foo f1 f2 f3 f4 f5 f6 f7 f8 f9] $foo $f1 $f2 $f3 $f4 $f5 \
   1.127 +	    $f6 $f7 $f8 $f9
   1.128 +} {1 {0 16} {0 0} {1 3} {4 5} {6 6} {7 9} {10 10} {11 11} {12 12} {13 16}}
   1.129 +test regexp-3.6 {getting substrings back from regexp} {
   1.130 +    set foo 2; set f2 2; set f3 2; set f4 2
   1.131 +    list [regexp -indices (a)(b)? xay foo f2 f3 f4] $foo $f2 $f3 $f4
   1.132 +} {1 {1 1} {1 1} {-1 -1} {-1 -1}}
   1.133 +test regexp-3.7 {getting substrings back from regexp} {
   1.134 +    set foo 1; set f2 1; set f3 1; set f4 1
   1.135 +    list [regexp -indices (a)(b)?(c) xacy foo f2 f3 f4] $foo $f2 $f3 $f4
   1.136 +} {1 {1 2} {1 1} {-1 -1} {2 2}}
   1.137 +
   1.138 +test regexp-4.1 {-nocase option to regexp} {
   1.139 +    regexp -nocase foo abcFOo
   1.140 +} 1
   1.141 +test regexp-4.2 {-nocase option to regexp} {
   1.142 +    set f1 22
   1.143 +    set f2 33
   1.144 +    set f3 44
   1.145 +    list [regexp -nocase {a(b*)([xy]*)z} aBbbxYXxxZ22 f1 f2 f3] $f1 $f2 $f3
   1.146 +} {1 aBbbxYXxxZ Bbb xYXxx}
   1.147 +test regexp-4.3 {-nocase option to regexp} {
   1.148 +    regexp -nocase FOo abcFOo
   1.149 +} 1
   1.150 +set x abcdefghijklmnopqrstuvwxyz1234567890
   1.151 +set x $x$x$x$x$x$x$x$x$x$x$x$x
   1.152 +test regexp-4.4 {case conversion in regexp} {
   1.153 +    list [regexp -nocase $x $x foo] $foo
   1.154 +} "1 $x"
   1.155 +catch {unset x}
   1.156 +
   1.157 +test regexp-5.1 {exercise cache of compiled expressions} {
   1.158 +    regexp .*a b
   1.159 +    regexp .*b c
   1.160 +    regexp .*c d
   1.161 +    regexp .*d e
   1.162 +    regexp .*e f
   1.163 +    regexp .*a bbba
   1.164 +} 1
   1.165 +test regexp-5.2 {exercise cache of compiled expressions} {
   1.166 +    regexp .*a b
   1.167 +    regexp .*b c
   1.168 +    regexp .*c d
   1.169 +    regexp .*d e
   1.170 +    regexp .*e f
   1.171 +    regexp .*b xxxb
   1.172 +} 1
   1.173 +test regexp-5.3 {exercise cache of compiled expressions} {
   1.174 +    regexp .*a b
   1.175 +    regexp .*b c
   1.176 +    regexp .*c d
   1.177 +    regexp .*d e
   1.178 +    regexp .*e f
   1.179 +    regexp .*c yyyc
   1.180 +} 1
   1.181 +test regexp-5.4 {exercise cache of compiled expressions} {
   1.182 +    regexp .*a b
   1.183 +    regexp .*b c
   1.184 +    regexp .*c d
   1.185 +    regexp .*d e
   1.186 +    regexp .*e f
   1.187 +    regexp .*d 1d
   1.188 +} 1
   1.189 +test regexp-5.5 {exercise cache of compiled expressions} {
   1.190 +    regexp .*a b
   1.191 +    regexp .*b c
   1.192 +    regexp .*c d
   1.193 +    regexp .*d e
   1.194 +    regexp .*e f
   1.195 +    regexp .*e xe
   1.196 +} 1
   1.197 +
   1.198 +test regexp-6.1 {regexp errors} {
   1.199 +    list [catch {regexp a} msg] $msg
   1.200 +} {1 {wrong # args: should be "regexp ?switches? exp string ?matchVar? ?subMatchVar subMatchVar ...?"}}
   1.201 +test regexp-6.2 {regexp errors} {
   1.202 +    list [catch {regexp -nocase a} msg] $msg
   1.203 +} {1 {wrong # args: should be "regexp ?switches? exp string ?matchVar? ?subMatchVar subMatchVar ...?"}}
   1.204 +test regexp-6.3 {regexp errors} {
   1.205 +    list [catch {regexp -gorp a} msg] $msg
   1.206 +} {1 {bad switch "-gorp": must be -all, -about, -indices, -inline, -expanded, -line, -linestop, -lineanchor, -nocase, -start, or --}}
   1.207 +test regexp-6.4 {regexp errors} {
   1.208 +    list [catch {regexp a( b} msg] $msg
   1.209 +} {1 {couldn't compile regular expression pattern: parentheses () not balanced}}
   1.210 +test regexp-6.5 {regexp errors} {
   1.211 +    list [catch {regexp a( b} msg] $msg
   1.212 +} {1 {couldn't compile regular expression pattern: parentheses () not balanced}}
   1.213 +test regexp-6.6 {regexp errors} {
   1.214 +    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.215 +} {0 1}
   1.216 +test regexp-6.7 {regexp errors} {
   1.217 +    list [catch {regexp (x)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.) xyzzy} msg] $msg
   1.218 +} {0 0}
   1.219 +test regexp-6.8 {regexp errors} {
   1.220 +    catch {unset f1}
   1.221 +    set f1 44
   1.222 +    list [catch {regexp abc abc f1(f2)} msg] $msg
   1.223 +} {1 {couldn't set variable "f1(f2)"}}
   1.224 +test regexp-6.9 {regexp errors, -start bad int check} {
   1.225 +    list [catch {regexp -start bogus {^$} {}} msg] $msg
   1.226 +} {1 {expected integer but got "bogus"}}
   1.227 +
   1.228 +test regexp-7.1 {basic regsub operation} {
   1.229 +    list [regsub aa+ xaxaaaxaa 111&222 foo] $foo
   1.230 +} {1 xax111aaa222xaa}
   1.231 +test regexp-7.2 {basic regsub operation} {
   1.232 +    list [regsub aa+ aaaxaa &111 foo] $foo
   1.233 +} {1 aaa111xaa}
   1.234 +test regexp-7.3 {basic regsub operation} {
   1.235 +    list [regsub aa+ xaxaaa 111& foo] $foo
   1.236 +} {1 xax111aaa}
   1.237 +test regexp-7.4 {basic regsub operation} {
   1.238 +    list [regsub aa+ aaa 11&2&333 foo] $foo
   1.239 +} {1 11aaa2aaa333}
   1.240 +test regexp-7.5 {basic regsub operation} {
   1.241 +    list [regsub aa+ xaxaaaxaa &2&333 foo] $foo
   1.242 +} {1 xaxaaa2aaa333xaa}
   1.243 +test regexp-7.6 {basic regsub operation} {
   1.244 +    list [regsub aa+ xaxaaaxaa 1&22& foo] $foo
   1.245 +} {1 xax1aaa22aaaxaa}
   1.246 +test regexp-7.7 {basic regsub operation} {
   1.247 +    list [regsub a(a+) xaxaaaxaa {1\122\1} foo] $foo
   1.248 +} {1 xax1aa22aaxaa}
   1.249 +test regexp-7.8 {basic regsub operation} {
   1.250 +    list [regsub a(a+) xaxaaaxaa {1\\\122\1} foo] $foo
   1.251 +} "1 {xax1\\aa22aaxaa}"
   1.252 +test regexp-7.9 {basic regsub operation} {
   1.253 +    list [regsub a(a+) xaxaaaxaa {1\\122\1} foo] $foo
   1.254 +} "1 {xax1\\122aaxaa}"
   1.255 +test regexp-7.10 {basic regsub operation} {
   1.256 +    list [regsub a(a+) xaxaaaxaa {1\\&\1} foo] $foo
   1.257 +} "1 {xax1\\aaaaaxaa}"
   1.258 +test regexp-7.11 {basic regsub operation} {
   1.259 +    list [regsub a(a+) xaxaaaxaa {1\&\1} foo] $foo
   1.260 +} {1 xax1&aaxaa}
   1.261 +test regexp-7.12 {basic regsub operation} {
   1.262 +    list [regsub a(a+) xaxaaaxaa {\1\1\1\1&&} foo] $foo
   1.263 +} {1 xaxaaaaaaaaaaaaaaxaa}
   1.264 +test regexp-7.13 {basic regsub operation} {
   1.265 +    set foo xxx
   1.266 +    list [regsub abc xyz 111 foo] $foo
   1.267 +} {0 xyz}
   1.268 +test regexp-7.14 {basic regsub operation} {
   1.269 +    set foo xxx
   1.270 +    list [regsub ^ xyz "111 " foo] $foo
   1.271 +} {1 {111 xyz}}
   1.272 +test regexp-7.15 {basic regsub operation} {
   1.273 +    set foo xxx
   1.274 +    list [regsub -- -foo abc-foodef "111 " foo] $foo
   1.275 +} {1 {abc111 def}}
   1.276 +test regexp-7.16 {basic regsub operation} {
   1.277 +    set foo xxx
   1.278 +    list [regsub x "" y foo] $foo
   1.279 +} {0 {}}
   1.280 +test regexp-7.17 {regsub utf compliance} {
   1.281 +    # if not UTF-8 aware, result is "0 1"
   1.282 +    set foo "xyz555ijka\u4e4ebpqr"
   1.283 +    regsub a\u4e4eb xyza\u4e4ebijka\u4e4ebpqr 555 bar
   1.284 +    list [string compare $foo $bar] [regexp 4 $bar]
   1.285 +} {0 0}
   1.286 +
   1.287 +test regexp-8.1 {case conversion in regsub} {
   1.288 +    list [regsub -nocase a(a+) xaAAaAAay & foo] $foo
   1.289 +} {1 xaAAaAAay}
   1.290 +test regexp-8.2 {case conversion in regsub} {
   1.291 +    list [regsub -nocase a(a+) xaAAaAAay & foo] $foo
   1.292 +} {1 xaAAaAAay}
   1.293 +test regexp-8.3 {case conversion in regsub} {
   1.294 +    set foo 123
   1.295 +    list [regsub a(a+) xaAAaAAay & foo] $foo
   1.296 +} {0 xaAAaAAay}
   1.297 +test regexp-8.4 {case conversion in regsub} {
   1.298 +    set foo 123
   1.299 +    list [regsub -nocase a CaDE b foo] $foo
   1.300 +} {1 CbDE}
   1.301 +test regexp-8.5 {case conversion in regsub} {
   1.302 +    set foo 123
   1.303 +    list [regsub -nocase XYZ CxYzD b foo] $foo
   1.304 +} {1 CbD}
   1.305 +test regexp-8.6 {case conversion in regsub} {
   1.306 +    set x abcdefghijklmnopqrstuvwxyz1234567890
   1.307 +    set x $x$x$x$x$x$x$x$x$x$x$x$x
   1.308 +    set foo 123
   1.309 +    list [regsub -nocase $x $x b foo] $foo
   1.310 +} {1 b}
   1.311 +
   1.312 +test regexp-9.1 {-all option to regsub} {
   1.313 +    set foo 86
   1.314 +    list [regsub -all x+ axxxbxxcxdx |&| foo] $foo
   1.315 +} {4 a|xxx|b|xx|c|x|d|x|}
   1.316 +test regexp-9.2 {-all option to regsub} {
   1.317 +    set foo 86
   1.318 +    list [regsub -nocase -all x+ aXxXbxxcXdx |&| foo] $foo
   1.319 +} {4 a|XxX|b|xx|c|X|d|x|}
   1.320 +test regexp-9.3 {-all option to regsub} {
   1.321 +    set foo 86
   1.322 +    list [regsub x+ axxxbxxcxdx |&| foo] $foo
   1.323 +} {1 a|xxx|bxxcxdx}
   1.324 +test regexp-9.4 {-all option to regsub} {
   1.325 +    set foo 86
   1.326 +    list [regsub -all bc axxxbxxcxdx |&| foo] $foo
   1.327 +} {0 axxxbxxcxdx}
   1.328 +test regexp-9.5 {-all option to regsub} {
   1.329 +    set foo xxx
   1.330 +    list [regsub -all node "node node more" yy foo] $foo
   1.331 +} {2 {yy yy more}}
   1.332 +test regexp-9.6 {-all option to regsub} {
   1.333 +    set foo xxx
   1.334 +    list [regsub -all ^ xxx 123 foo] $foo
   1.335 +} {1 123xxx}
   1.336 +
   1.337 +test regexp-10.1 {expanded syntax in regsub} {
   1.338 +    set foo xxx
   1.339 +    list [regsub -expanded ". \#comment\n  . \#comment2" abc def foo] $foo
   1.340 +} {1 defc}
   1.341 +test regexp-10.2 {newline sensitivity in regsub} {
   1.342 +    set foo xxx
   1.343 +    list [regsub -line {^a.*b$} "dabc\naxyb\n" 123 foo] $foo
   1.344 +} "1 {dabc\n123\n}"
   1.345 +test regexp-10.3 {newline sensitivity in regsub} {
   1.346 +    set foo xxx
   1.347 +    list [regsub -line {^a.*b$} "dabc\naxyb\nxb" 123 foo] $foo
   1.348 +} "1 {dabc\n123\nxb}"
   1.349 +test regexp-10.4 {partial newline sensitivity in regsub} {
   1.350 +    set foo xxx
   1.351 +    list [regsub -lineanchor {^a.*b$} "da\naxyb\nxb" 123 foo] $foo
   1.352 +} "1 {da\n123}"
   1.353 +test regexp-10.5 {inverse partial newline sensitivity in regsub} {
   1.354 +    set foo xxx
   1.355 +    list [regsub -linestop {a.*b} "da\nbaxyb\nxb" 123 foo] $foo
   1.356 +} "1 {da\nb123\nxb}"
   1.357 +
   1.358 +test regexp-11.1 {regsub errors} {
   1.359 +    list [catch {regsub a b} msg] $msg
   1.360 +} {1 {wrong # args: should be "regsub ?switches? exp string subSpec ?varName?"}}
   1.361 +test regexp-11.2 {regsub errors} {
   1.362 +    list [catch {regsub -nocase a b} msg] $msg
   1.363 +} {1 {wrong # args: should be "regsub ?switches? exp string subSpec ?varName?"}}
   1.364 +test regexp-11.3 {regsub errors} {
   1.365 +    list [catch {regsub -nocase -all a b} msg] $msg
   1.366 +} {1 {wrong # args: should be "regsub ?switches? exp string subSpec ?varName?"}}
   1.367 +test regexp-11.4 {regsub errors} {
   1.368 +    list [catch {regsub a b c d e f} msg] $msg
   1.369 +} {1 {wrong # args: should be "regsub ?switches? exp string subSpec ?varName?"}}
   1.370 +test regexp-11.5 {regsub errors} {
   1.371 +    list [catch {regsub -gorp a b c} msg] $msg
   1.372 +} {1 {bad switch "-gorp": must be -all, -nocase, -expanded, -line, -linestop, -lineanchor, -start, or --}}
   1.373 +test regexp-11.6 {regsub errors} {
   1.374 +    list [catch {regsub -nocase a( b c d} msg] $msg
   1.375 +} {1 {couldn't compile regular expression pattern: parentheses () not balanced}}
   1.376 +test regexp-11.7 {regsub errors} {
   1.377 +    catch {unset f1}
   1.378 +    set f1 44
   1.379 +    list [catch {regsub -nocase aaa aaa xxx f1(f2)} msg] $msg
   1.380 +} {1 {couldn't set variable "f1(f2)"}}
   1.381 +test regexp-11.8 {regsub errors, -start bad int check} {
   1.382 +    list [catch {regsub -start bogus pattern string rep var} msg] $msg
   1.383 +} {1 {expected integer but got "bogus"}}
   1.384 +test regexp-11.9 {regsub without final variable name returns value} {
   1.385 +    regsub b abaca X
   1.386 +} {aXaca}
   1.387 +test regexp-11.10 {regsub without final variable name returns value} {
   1.388 +    regsub -all a abaca X
   1.389 +} {XbXcX}
   1.390 +test regexp-11.11 {regsub without final variable name returns value} {
   1.391 +    regsub b(.*?)d abcdeabcfde {,&,\1,}
   1.392 +} {a,bcd,c,eabcfde}
   1.393 +test regexp-11.12 {regsub without final variable name returns value} {
   1.394 +    regsub -all b(.*?)d abcdeabcfde {,&,\1,}
   1.395 +} {a,bcd,c,ea,bcfd,cf,e}
   1.396 +
   1.397 +# This test crashes on the Mac unless you increase the Stack Space to about 1
   1.398 +# Meg.  This is probably bigger than most users want... 
   1.399 +# 8.2.3 regexp reduced stack space requirements, but this should be
   1.400 +# tested again
   1.401 +test regexp-12.1 {Tcl_RegExpExec: large number of subexpressions} {macCrash} {
   1.402 +    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.403 +} {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.404 +
   1.405 +test regexp-13.1 {regsub of a very large string} {
   1.406 +    # This test is designed to stress the memory subsystem in order
   1.407 +    # to catch Bug #933.  It only fails if the Tcl memory allocator
   1.408 +    # is in use.
   1.409 +
   1.410 +    set line {BEGIN_TABLE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; END_TABLE}
   1.411 +    set filedata [string repeat $line 200]
   1.412 +    for {set i 1} {$i<10} {incr i} {
   1.413 +	regsub -all "BEGIN_TABLE " $filedata "" newfiledata
   1.414 +    }
   1.415 +    set x done
   1.416 +} {done}
   1.417 +
   1.418 +test regexp-14.1 {CompileRegexp: regexp cache} {
   1.419 +    regexp .*a b
   1.420 +    regexp .*b c
   1.421 +    regexp .*c d
   1.422 +    regexp .*d e
   1.423 +    regexp .*e f
   1.424 +    set x .
   1.425 +    append x *a
   1.426 +    regexp $x bbba
   1.427 +} 1
   1.428 +test regexp-14.2 {CompileRegexp: regexp cache, different flags} {
   1.429 +    regexp .*a b
   1.430 +    regexp .*b c
   1.431 +    regexp .*c d
   1.432 +    regexp .*d e
   1.433 +    regexp .*e f
   1.434 +    set x .
   1.435 +    append x *a
   1.436 +    regexp -nocase $x bbba
   1.437 +} 1
   1.438 +
   1.439 +testConstraint exec [llength [info commands exec]]
   1.440 +test regexp-14.3 {CompileRegexp: regexp cache, empty regexp and empty cache} -constraints {
   1.441 +	exec
   1.442 +} -setup {
   1.443 +    set junk [makeFile {puts [regexp {} foo]} junk.tcl]
   1.444 +} -body {
   1.445 +    exec [interpreter] $junk
   1.446 +} -cleanup {
   1.447 +    removeFile junk.tcl
   1.448 +} -result 1
   1.449 +
   1.450 +test regexp-15.1 {regexp -start} {
   1.451 +    catch {unset x}
   1.452 +    list [regexp -start -10 {\d} 1abc2de3 x] $x
   1.453 +} {1 1}
   1.454 +test regexp-15.2 {regexp -start} {
   1.455 +    catch {unset x}
   1.456 +    list [regexp -start 2 {\d} 1abc2de3 x] $x
   1.457 +} {1 2}
   1.458 +test regexp-15.3 {regexp -start} {
   1.459 +    catch {unset x}
   1.460 +    list [regexp -start 4 {\d} 1abc2de3 x] $x
   1.461 +} {1 2}
   1.462 +test regexp-15.4 {regexp -start} {
   1.463 +    catch {unset x}
   1.464 +    list [regexp -start 5 {\d} 1abc2de3 x] $x
   1.465 +} {1 3}
   1.466 +test regexp-15.5 {regexp -start, over end of string} {
   1.467 +    catch {unset x}
   1.468 +    list [regexp -start [string length 1abc2de3] {\d} 1abc2de3 x] [info exists x]
   1.469 +} {0 0}
   1.470 +test regexp-15.6 {regexp -start, loss of ^$ behavior} {
   1.471 +    list [regexp -start 2 {^$} {}]
   1.472 +} {0}
   1.473 +
   1.474 +test regexp-16.1 {regsub -start} {
   1.475 +    catch {unset x}
   1.476 +    list [regsub -all -start 2 {\d} a1b2c3d4e5 {/&} x] $x
   1.477 +} {4 a1b/2c/3d/4e/5}
   1.478 +test regexp-16.2 {regsub -start} {
   1.479 +    catch {unset x}
   1.480 +    list [regsub -all -start -25 {z} hello {/&} x] $x
   1.481 +} {0 hello}
   1.482 +test regexp-16.3 {regsub -start} {
   1.483 +    catch {unset x}
   1.484 +    list [regsub -all -start 3 {z} hello {/&} x] $x
   1.485 +} {0 hello}
   1.486 +test regexp-16.4 {regsub -start, \A behavior} {
   1.487 +    set out {}
   1.488 +    lappend out [regsub -start 0 -all {\A(\w)} {abcde} {/\1} x] $x
   1.489 +    lappend out [regsub -start 2 -all {\A(\w)} {abcde} {/\1} x] $x
   1.490 +} {5 /a/b/c/d/e 3 ab/c/d/e}
   1.491 +
   1.492 +test regexp-17.1 {regexp -inline} {
   1.493 +    regexp -inline b ababa
   1.494 +} {b}
   1.495 +test regexp-17.2 {regexp -inline} {
   1.496 +    regexp -inline (b) ababa
   1.497 +} {b b}
   1.498 +test regexp-17.3 {regexp -inline -indices} {
   1.499 +    regexp -inline -indices (b) ababa
   1.500 +} {{1 1} {1 1}}
   1.501 +test regexp-17.4 {regexp -inline} {
   1.502 +    regexp -inline {\w(\d+)\w} "   hello 23 there456def "
   1.503 +} {e456d 456}
   1.504 +test regexp-17.5 {regexp -inline no matches} {
   1.505 +    regexp -inline {\w(\d+)\w} ""
   1.506 +} {}
   1.507 +test regexp-17.6 {regexp -inline no matches} {
   1.508 +    regexp -inline hello goodbye
   1.509 +} {}
   1.510 +test regexp-17.7 {regexp -inline, no matchvars allowed} {
   1.511 +    list [catch {regexp -inline b abc match} msg] $msg
   1.512 +} {1 {regexp match variables not allowed when using -inline}}
   1.513 +
   1.514 +test regexp-18.1 {regexp -all} {
   1.515 +    regexp -all b bbbbb
   1.516 +} {5}
   1.517 +test regexp-18.2 {regexp -all} {
   1.518 +    regexp -all b abababbabaaaaaaaaaab
   1.519 +} {6}
   1.520 +test regexp-18.3 {regexp -all -inline} {
   1.521 +    regexp -all -inline b abababbabaaaaaaaaaab
   1.522 +} {b b b b b b}
   1.523 +test regexp-18.4 {regexp -all -inline} {
   1.524 +    regexp -all -inline {\w(\w)} abcdefg
   1.525 +} {ab b cd d ef f}
   1.526 +test regexp-18.5 {regexp -all -inline} {
   1.527 +    regexp -all -inline {\w(\w)$} abcdefg
   1.528 +} {fg g}
   1.529 +test regexp-18.6 {regexp -all -inline} {
   1.530 +    regexp -all -inline {\d+} 10:20:30:40
   1.531 +} {10 20 30 40}
   1.532 +test regexp-18.7 {regexp -all -inline} {
   1.533 +    list [catch {regexp -all -inline b abc match} msg] $msg
   1.534 +} {1 {regexp match variables not allowed when using -inline}}
   1.535 +test regexp-18.8 {regexp -all} {
   1.536 +    # This should not cause an infinite loop
   1.537 +    regexp -all -inline {a*} a
   1.538 +} {a}
   1.539 +test regexp-18.9 {regexp -all} {
   1.540 +    # Yes, the expected result is {a {}}.  Here's why:
   1.541 +    # Start at index 0; a* matches the "a" there then stops.
   1.542 +    # Go to index 1; a* matches the lambda (or {}) there then stops.  Recall
   1.543 +    #   that a* matches zero or more "a"'s; thus it matches the string "b", as
   1.544 +    #   there are zero or more "a"'s there.
   1.545 +    # Go to index 2; this is past the end of the string, so stop.
   1.546 +    regexp -all -inline {a*} ab
   1.547 +} {a {}}
   1.548 +test regexp-18.10 {regexp -all} {
   1.549 +    # Yes, the expected result is {a {} a}.  Here's why:
   1.550 +    # Start at index 0; a* matches the "a" there then stops.
   1.551 +    # Go to index 1; a* matches the lambda (or {}) there then stops.   Recall
   1.552 +    #   that a* matches zero or more "a"'s; thus it matches the string "b", as
   1.553 +    #   there are zero or more "a"'s there.
   1.554 +    # Go to index 2; a* matches the "a" there then stops.
   1.555 +    # Go to index 3; this is past the end of the string, so stop.
   1.556 +    regexp -all -inline {a*} aba
   1.557 +} {a {} a}
   1.558 +test regexp-18.11 {regexp -all} {
   1.559 +    regexp -all -inline {^a} aaaa
   1.560 +} {a}
   1.561 +test regexp-18.12 {regexp -all -inline -indices} {
   1.562 +    regexp -all -inline -indices a(b(c)d|e(f)g)h abcdhaefgh
   1.563 +} {{0 4} {1 3} {2 2} {-1 -1} {5 9} {6 8} {-1 -1} {7 7}}
   1.564 +
   1.565 +test regexp-19.1 {regsub null replacement} {
   1.566 +    regsub -all {@} {@hel@lo@} "\0a\0" result
   1.567 +    list $result [string length $result]
   1.568 +} "\0a\0hel\0a\0lo\0a\0 14"
   1.569 +
   1.570 +test regexp-20.1 {regsub shared object shimmering} {
   1.571 +    # Bug #461322
   1.572 +    set a abcdefghijklmnopqurstuvwxyz 
   1.573 +    set b $a 
   1.574 +    set c abcdefghijklmnopqurstuvwxyz0123456789 
   1.575 +    regsub $a $c $b d 
   1.576 +    list $d [string length $d] [string bytelength $d]
   1.577 +} [list abcdefghijklmnopqurstuvwxyz0123456789 37 37]
   1.578 +test regexp-20.2 {regsub shared object shimmering with -about} {
   1.579 +    eval regexp -about abc
   1.580 +} {0 {}}
   1.581 +
   1.582 +test regexp-21.1 {regsub works with empty string} {
   1.583 +    regsub -- ^ {} foo
   1.584 +} {foo}
   1.585 +
   1.586 +test regexp-21.2 {regsub works with empty string} {
   1.587 +    regsub -- \$ {} foo
   1.588 +} {foo}
   1.589 +
   1.590 +test regexp-21.3 {regsub works with empty string offset} {
   1.591 +    regsub -start 0 -- ^ {} foo
   1.592 +} {foo}
   1.593 +
   1.594 +test regexp-21.4 {regsub works with empty string offset} {
   1.595 +    regsub -start 0 -- \$ {} foo
   1.596 +} {foo}
   1.597 +
   1.598 +test regexp-21.5 {regsub works with empty string offset} {
   1.599 +    regsub -start 3 -- \$ {123} foo
   1.600 +} {123foo}
   1.601 +
   1.602 +test regexp-21.6 {regexp works with empty string} {
   1.603 +    regexp -- ^ {}
   1.604 +} {1}
   1.605 +
   1.606 +test regexp-21.7 {regexp works with empty string} {
   1.607 +    regexp -start 0 -- ^ {}
   1.608 +} {1}
   1.609 +
   1.610 +test regexp-21.8 {regexp works with empty string offset} {
   1.611 +    regexp -start 3 -- ^ {123}
   1.612 +} {0}
   1.613 +
   1.614 +test regexp-21.9 {regexp works with empty string offset} {
   1.615 +    regexp -start 3 -- \$ {123}
   1.616 +} {1}
   1.617 +
   1.618 +test regexp-21.10 {multiple matches handle newlines} {
   1.619 +    regsub -all -lineanchor -- {^#[^\n]*\n} "#one\n#two\n#three\n" foo\n
   1.620 +} "foo\nfoo\nfoo\n"
   1.621 +
   1.622 +test regexp-21.11 {multiple matches handle newlines} {
   1.623 +    regsub -all -line -- ^ "a\nb\nc" \#
   1.624 +} "\#a\n\#b\n\#c"
   1.625 +
   1.626 +test regexp-21.12 {multiple matches handle newlines} {
   1.627 +    regsub -all -line -- ^ "\n\n" \#
   1.628 +} "\#\n\#\n\#"
   1.629 +
   1.630 +test regexp-21.13 {multiple matches handle newlines} {
   1.631 +    regexp -all -inline -indices -line -- ^ "a\nb\nc"
   1.632 +} {{0 -1} {2 1} {4 3}}
   1.633 +
   1.634 +# cleanup
   1.635 +::tcltest::cleanupTests
   1.636 +return