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