sl@0: # Commands covered: regexp, regsub sl@0: # sl@0: # This file contains a collection of tests for one or more of the Tcl sl@0: # built-in commands. Sourcing this file into Tcl runs the tests and sl@0: # generates output for errors. No output means no errors were found. sl@0: # sl@0: # Copyright (c) 1991-1993 The Regents of the University of California. sl@0: # Copyright (c) 1998 Sun Microsystems, Inc. sl@0: # Copyright (c) 1998-1999 by Scriptics Corporation. sl@0: # sl@0: # See the file "license.terms" for information on usage and redistribution sl@0: # of this file, and for a DISCLAIMER OF ALL WARRANTIES. sl@0: # sl@0: # RCS: @(#) $Id: regexp.test,v 1.22.2.3 2003/10/14 18:22:10 vincentdarley Exp $ sl@0: sl@0: if {[lsearch [namespace children] ::tcltest] == -1} { sl@0: package require tcltest 2 sl@0: namespace import -force ::tcltest::* sl@0: } sl@0: sl@0: catch {unset foo} sl@0: test regexp-1.1 {basic regexp operation} { sl@0: regexp ab*c abbbc sl@0: } 1 sl@0: test regexp-1.2 {basic regexp operation} { sl@0: regexp ab*c ac sl@0: } 1 sl@0: test regexp-1.3 {basic regexp operation} { sl@0: regexp ab*c ab sl@0: } 0 sl@0: test regexp-1.4 {basic regexp operation} { sl@0: regexp -- -gorp abc-gorpxxx sl@0: } 1 sl@0: test regexp-1.5 {basic regexp operation} { sl@0: regexp {^([^ ]*)[ ]*([^ ]*)} "" a sl@0: } 1 sl@0: test regexp-1.6 {basic regexp operation} { sl@0: list [catch {regexp {} abc} msg] $msg sl@0: } {0 1} sl@0: test regexp-1.7 {regexp utf compliance} { sl@0: # if not UTF-8 aware, result is "0 1" sl@0: set foo "\u4e4eb q" sl@0: regexp "\u4e4eb q" "a\u4e4eb qw\u5e4e\x4e wq" bar sl@0: list [string compare $foo $bar] [regexp 4 $bar] sl@0: } {0 0} sl@0: sl@0: test regexp-2.1 {getting substrings back from regexp} { sl@0: set foo {} sl@0: list [regexp ab*c abbbbc foo] $foo sl@0: } {1 abbbbc} sl@0: test regexp-2.2 {getting substrings back from regexp} { sl@0: set foo {} sl@0: set f2 {} sl@0: list [regexp a(b*)c abbbbc foo f2] $foo $f2 sl@0: } {1 abbbbc bbbb} sl@0: test regexp-2.3 {getting substrings back from regexp} { sl@0: set foo {} sl@0: set f2 {} sl@0: list [regexp a(b*)(c) abbbbc foo f2] $foo $f2 sl@0: } {1 abbbbc bbbb} sl@0: test regexp-2.4 {getting substrings back from regexp} { sl@0: set foo {} sl@0: set f2 {} sl@0: set f3 {} sl@0: list [regexp a(b*)(c) abbbbc foo f2 f3] $foo $f2 $f3 sl@0: } {1 abbbbc bbbb c} sl@0: test regexp-2.5 {getting substrings back from regexp} { sl@0: set foo {}; set f1 {}; set f2 {}; set f3 {}; set f4 {}; set f5 {}; sl@0: set f6 {}; set f7 {}; set f8 {}; set f9 {}; set fa {}; set fb {}; sl@0: list [regexp (1*)(2*)(3*)(4*)(5*)(6*)(7*)(8*)(9*)(a*)(b*) \ sl@0: 12223345556789999aabbb \ sl@0: foo f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb] $foo $f1 $f2 $f3 $f4 $f5 \ sl@0: $f6 $f7 $f8 $f9 $fa $fb sl@0: } {1 12223345556789999aabbb 1 222 33 4 555 6 7 8 9999 aa bbb} sl@0: test regexp-2.6 {getting substrings back from regexp} { sl@0: set foo 2; set f2 2; set f3 2; set f4 2 sl@0: list [regexp (a)(b)? xay foo f2 f3 f4] $foo $f2 $f3 $f4 sl@0: } {1 a a {} {}} sl@0: test regexp-2.7 {getting substrings back from regexp} { sl@0: set foo 1; set f2 1; set f3 1; set f4 1 sl@0: list [regexp (a)(b)?(c) xacy foo f2 f3 f4] $foo $f2 $f3 $f4 sl@0: } {1 ac a {} c} sl@0: test regexp-2.8 {getting substrings back from regexp} { sl@0: set match {} sl@0: list [regexp {^a*b} aaaab match] $match sl@0: } {1 aaaab} sl@0: test regexp-2.9 {getting substrings back from regexp} { sl@0: set foo {} sl@0: set f2 {} sl@0: list [regexp f\352te(b*)c f\352tebbbbc foo f2] $foo $f2 sl@0: } [list 1 f\352tebbbbc bbbb] sl@0: test regexp-2.10 {getting substrings back from regexp} { sl@0: set foo {} sl@0: set f2 {} sl@0: list [regexp f\352te(b*)c eff\352tebbbbc foo f2] $foo $f2 sl@0: } [list 1 f\352tebbbbc bbbb] sl@0: sl@0: test regexp-3.1 {-indices option to regexp} { sl@0: set foo {} sl@0: list [regexp -indices ab*c abbbbc foo] $foo sl@0: } {1 {0 5}} sl@0: test regexp-3.2 {-indices option to regexp} { sl@0: set foo {} sl@0: set f2 {} sl@0: list [regexp -indices a(b*)c abbbbc foo f2] $foo $f2 sl@0: } {1 {0 5} {1 4}} sl@0: test regexp-3.3 {-indices option to regexp} { sl@0: set foo {} sl@0: set f2 {} sl@0: list [regexp -indices a(b*)(c) abbbbc foo f2] $foo $f2 sl@0: } {1 {0 5} {1 4}} sl@0: test regexp-3.4 {-indices option to regexp} { sl@0: set foo {} sl@0: set f2 {} sl@0: set f3 {} sl@0: list [regexp -indices a(b*)(c) abbbbc foo f2 f3] $foo $f2 $f3 sl@0: } {1 {0 5} {1 4} {5 5}} sl@0: test regexp-3.5 {-indices option to regexp} { sl@0: set foo {}; set f1 {}; set f2 {}; set f3 {}; set f4 {}; set f5 {}; sl@0: set f6 {}; set f7 {}; set f8 {}; set f9 {} sl@0: list [regexp -indices (1*)(2*)(3*)(4*)(5*)(6*)(7*)(8*)(9*) \ sl@0: 12223345556789999 \ sl@0: foo f1 f2 f3 f4 f5 f6 f7 f8 f9] $foo $f1 $f2 $f3 $f4 $f5 \ sl@0: $f6 $f7 $f8 $f9 sl@0: } {1 {0 16} {0 0} {1 3} {4 5} {6 6} {7 9} {10 10} {11 11} {12 12} {13 16}} sl@0: test regexp-3.6 {getting substrings back from regexp} { sl@0: set foo 2; set f2 2; set f3 2; set f4 2 sl@0: list [regexp -indices (a)(b)? xay foo f2 f3 f4] $foo $f2 $f3 $f4 sl@0: } {1 {1 1} {1 1} {-1 -1} {-1 -1}} sl@0: test regexp-3.7 {getting substrings back from regexp} { sl@0: set foo 1; set f2 1; set f3 1; set f4 1 sl@0: list [regexp -indices (a)(b)?(c) xacy foo f2 f3 f4] $foo $f2 $f3 $f4 sl@0: } {1 {1 2} {1 1} {-1 -1} {2 2}} sl@0: sl@0: test regexp-4.1 {-nocase option to regexp} { sl@0: regexp -nocase foo abcFOo sl@0: } 1 sl@0: test regexp-4.2 {-nocase option to regexp} { sl@0: set f1 22 sl@0: set f2 33 sl@0: set f3 44 sl@0: list [regexp -nocase {a(b*)([xy]*)z} aBbbxYXxxZ22 f1 f2 f3] $f1 $f2 $f3 sl@0: } {1 aBbbxYXxxZ Bbb xYXxx} sl@0: test regexp-4.3 {-nocase option to regexp} { sl@0: regexp -nocase FOo abcFOo sl@0: } 1 sl@0: set x abcdefghijklmnopqrstuvwxyz1234567890 sl@0: set x $x$x$x$x$x$x$x$x$x$x$x$x sl@0: test regexp-4.4 {case conversion in regexp} { sl@0: list [regexp -nocase $x $x foo] $foo sl@0: } "1 $x" sl@0: catch {unset x} sl@0: sl@0: test regexp-5.1 {exercise cache of compiled expressions} { sl@0: regexp .*a b sl@0: regexp .*b c sl@0: regexp .*c d sl@0: regexp .*d e sl@0: regexp .*e f sl@0: regexp .*a bbba sl@0: } 1 sl@0: test regexp-5.2 {exercise cache of compiled expressions} { sl@0: regexp .*a b sl@0: regexp .*b c sl@0: regexp .*c d sl@0: regexp .*d e sl@0: regexp .*e f sl@0: regexp .*b xxxb sl@0: } 1 sl@0: test regexp-5.3 {exercise cache of compiled expressions} { sl@0: regexp .*a b sl@0: regexp .*b c sl@0: regexp .*c d sl@0: regexp .*d e sl@0: regexp .*e f sl@0: regexp .*c yyyc sl@0: } 1 sl@0: test regexp-5.4 {exercise cache of compiled expressions} { sl@0: regexp .*a b sl@0: regexp .*b c sl@0: regexp .*c d sl@0: regexp .*d e sl@0: regexp .*e f sl@0: regexp .*d 1d sl@0: } 1 sl@0: test regexp-5.5 {exercise cache of compiled expressions} { sl@0: regexp .*a b sl@0: regexp .*b c sl@0: regexp .*c d sl@0: regexp .*d e sl@0: regexp .*e f sl@0: regexp .*e xe sl@0: } 1 sl@0: sl@0: test regexp-6.1 {regexp errors} { sl@0: list [catch {regexp a} msg] $msg sl@0: } {1 {wrong # args: should be "regexp ?switches? exp string ?matchVar? ?subMatchVar subMatchVar ...?"}} sl@0: test regexp-6.2 {regexp errors} { sl@0: list [catch {regexp -nocase a} msg] $msg sl@0: } {1 {wrong # args: should be "regexp ?switches? exp string ?matchVar? ?subMatchVar subMatchVar ...?"}} sl@0: test regexp-6.3 {regexp errors} { sl@0: list [catch {regexp -gorp a} msg] $msg sl@0: } {1 {bad switch "-gorp": must be -all, -about, -indices, -inline, -expanded, -line, -linestop, -lineanchor, -nocase, -start, or --}} sl@0: test regexp-6.4 {regexp errors} { sl@0: list [catch {regexp a( b} msg] $msg sl@0: } {1 {couldn't compile regular expression pattern: parentheses () not balanced}} sl@0: test regexp-6.5 {regexp errors} { sl@0: list [catch {regexp a( b} msg] $msg sl@0: } {1 {couldn't compile regular expression pattern: parentheses () not balanced}} sl@0: test regexp-6.6 {regexp errors} { sl@0: 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: } {0 1} sl@0: test regexp-6.7 {regexp errors} { sl@0: list [catch {regexp (x)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.) xyzzy} msg] $msg sl@0: } {0 0} sl@0: test regexp-6.8 {regexp errors} { sl@0: catch {unset f1} sl@0: set f1 44 sl@0: list [catch {regexp abc abc f1(f2)} msg] $msg sl@0: } {1 {couldn't set variable "f1(f2)"}} sl@0: test regexp-6.9 {regexp errors, -start bad int check} { sl@0: list [catch {regexp -start bogus {^$} {}} msg] $msg sl@0: } {1 {expected integer but got "bogus"}} sl@0: sl@0: test regexp-7.1 {basic regsub operation} { sl@0: list [regsub aa+ xaxaaaxaa 111&222 foo] $foo sl@0: } {1 xax111aaa222xaa} sl@0: test regexp-7.2 {basic regsub operation} { sl@0: list [regsub aa+ aaaxaa &111 foo] $foo sl@0: } {1 aaa111xaa} sl@0: test regexp-7.3 {basic regsub operation} { sl@0: list [regsub aa+ xaxaaa 111& foo] $foo sl@0: } {1 xax111aaa} sl@0: test regexp-7.4 {basic regsub operation} { sl@0: list [regsub aa+ aaa 11&2&333 foo] $foo sl@0: } {1 11aaa2aaa333} sl@0: test regexp-7.5 {basic regsub operation} { sl@0: list [regsub aa+ xaxaaaxaa &2&333 foo] $foo sl@0: } {1 xaxaaa2aaa333xaa} sl@0: test regexp-7.6 {basic regsub operation} { sl@0: list [regsub aa+ xaxaaaxaa 1&22& foo] $foo sl@0: } {1 xax1aaa22aaaxaa} sl@0: test regexp-7.7 {basic regsub operation} { sl@0: list [regsub a(a+) xaxaaaxaa {1\122\1} foo] $foo sl@0: } {1 xax1aa22aaxaa} sl@0: test regexp-7.8 {basic regsub operation} { sl@0: list [regsub a(a+) xaxaaaxaa {1\\\122\1} foo] $foo sl@0: } "1 {xax1\\aa22aaxaa}" sl@0: test regexp-7.9 {basic regsub operation} { sl@0: list [regsub a(a+) xaxaaaxaa {1\\122\1} foo] $foo sl@0: } "1 {xax1\\122aaxaa}" sl@0: test regexp-7.10 {basic regsub operation} { sl@0: list [regsub a(a+) xaxaaaxaa {1\\&\1} foo] $foo sl@0: } "1 {xax1\\aaaaaxaa}" sl@0: test regexp-7.11 {basic regsub operation} { sl@0: list [regsub a(a+) xaxaaaxaa {1\&\1} foo] $foo sl@0: } {1 xax1&aaxaa} sl@0: test regexp-7.12 {basic regsub operation} { sl@0: list [regsub a(a+) xaxaaaxaa {\1\1\1\1&&} foo] $foo sl@0: } {1 xaxaaaaaaaaaaaaaaxaa} sl@0: test regexp-7.13 {basic regsub operation} { sl@0: set foo xxx sl@0: list [regsub abc xyz 111 foo] $foo sl@0: } {0 xyz} sl@0: test regexp-7.14 {basic regsub operation} { sl@0: set foo xxx sl@0: list [regsub ^ xyz "111 " foo] $foo sl@0: } {1 {111 xyz}} sl@0: test regexp-7.15 {basic regsub operation} { sl@0: set foo xxx sl@0: list [regsub -- -foo abc-foodef "111 " foo] $foo sl@0: } {1 {abc111 def}} sl@0: test regexp-7.16 {basic regsub operation} { sl@0: set foo xxx sl@0: list [regsub x "" y foo] $foo sl@0: } {0 {}} sl@0: test regexp-7.17 {regsub utf compliance} { sl@0: # if not UTF-8 aware, result is "0 1" sl@0: set foo "xyz555ijka\u4e4ebpqr" sl@0: regsub a\u4e4eb xyza\u4e4ebijka\u4e4ebpqr 555 bar sl@0: list [string compare $foo $bar] [regexp 4 $bar] sl@0: } {0 0} sl@0: sl@0: test regexp-8.1 {case conversion in regsub} { sl@0: list [regsub -nocase a(a+) xaAAaAAay & foo] $foo sl@0: } {1 xaAAaAAay} sl@0: test regexp-8.2 {case conversion in regsub} { sl@0: list [regsub -nocase a(a+) xaAAaAAay & foo] $foo sl@0: } {1 xaAAaAAay} sl@0: test regexp-8.3 {case conversion in regsub} { sl@0: set foo 123 sl@0: list [regsub a(a+) xaAAaAAay & foo] $foo sl@0: } {0 xaAAaAAay} sl@0: test regexp-8.4 {case conversion in regsub} { sl@0: set foo 123 sl@0: list [regsub -nocase a CaDE b foo] $foo sl@0: } {1 CbDE} sl@0: test regexp-8.5 {case conversion in regsub} { sl@0: set foo 123 sl@0: list [regsub -nocase XYZ CxYzD b foo] $foo sl@0: } {1 CbD} sl@0: test regexp-8.6 {case conversion in regsub} { sl@0: set x abcdefghijklmnopqrstuvwxyz1234567890 sl@0: set x $x$x$x$x$x$x$x$x$x$x$x$x sl@0: set foo 123 sl@0: list [regsub -nocase $x $x b foo] $foo sl@0: } {1 b} sl@0: sl@0: test regexp-9.1 {-all option to regsub} { sl@0: set foo 86 sl@0: list [regsub -all x+ axxxbxxcxdx |&| foo] $foo sl@0: } {4 a|xxx|b|xx|c|x|d|x|} sl@0: test regexp-9.2 {-all option to regsub} { sl@0: set foo 86 sl@0: list [regsub -nocase -all x+ aXxXbxxcXdx |&| foo] $foo sl@0: } {4 a|XxX|b|xx|c|X|d|x|} sl@0: test regexp-9.3 {-all option to regsub} { sl@0: set foo 86 sl@0: list [regsub x+ axxxbxxcxdx |&| foo] $foo sl@0: } {1 a|xxx|bxxcxdx} sl@0: test regexp-9.4 {-all option to regsub} { sl@0: set foo 86 sl@0: list [regsub -all bc axxxbxxcxdx |&| foo] $foo sl@0: } {0 axxxbxxcxdx} sl@0: test regexp-9.5 {-all option to regsub} { sl@0: set foo xxx sl@0: list [regsub -all node "node node more" yy foo] $foo sl@0: } {2 {yy yy more}} sl@0: test regexp-9.6 {-all option to regsub} { sl@0: set foo xxx sl@0: list [regsub -all ^ xxx 123 foo] $foo sl@0: } {1 123xxx} sl@0: sl@0: test regexp-10.1 {expanded syntax in regsub} { sl@0: set foo xxx sl@0: list [regsub -expanded ". \#comment\n . \#comment2" abc def foo] $foo sl@0: } {1 defc} sl@0: test regexp-10.2 {newline sensitivity in regsub} { sl@0: set foo xxx sl@0: list [regsub -line {^a.*b$} "dabc\naxyb\n" 123 foo] $foo sl@0: } "1 {dabc\n123\n}" sl@0: test regexp-10.3 {newline sensitivity in regsub} { sl@0: set foo xxx sl@0: list [regsub -line {^a.*b$} "dabc\naxyb\nxb" 123 foo] $foo sl@0: } "1 {dabc\n123\nxb}" sl@0: test regexp-10.4 {partial newline sensitivity in regsub} { sl@0: set foo xxx sl@0: list [regsub -lineanchor {^a.*b$} "da\naxyb\nxb" 123 foo] $foo sl@0: } "1 {da\n123}" sl@0: test regexp-10.5 {inverse partial newline sensitivity in regsub} { sl@0: set foo xxx sl@0: list [regsub -linestop {a.*b} "da\nbaxyb\nxb" 123 foo] $foo sl@0: } "1 {da\nb123\nxb}" sl@0: sl@0: test regexp-11.1 {regsub errors} { sl@0: list [catch {regsub a b} msg] $msg sl@0: } {1 {wrong # args: should be "regsub ?switches? exp string subSpec ?varName?"}} sl@0: test regexp-11.2 {regsub errors} { sl@0: list [catch {regsub -nocase a b} msg] $msg sl@0: } {1 {wrong # args: should be "regsub ?switches? exp string subSpec ?varName?"}} sl@0: test regexp-11.3 {regsub errors} { sl@0: list [catch {regsub -nocase -all a b} msg] $msg sl@0: } {1 {wrong # args: should be "regsub ?switches? exp string subSpec ?varName?"}} sl@0: test regexp-11.4 {regsub errors} { sl@0: list [catch {regsub a b c d e f} msg] $msg sl@0: } {1 {wrong # args: should be "regsub ?switches? exp string subSpec ?varName?"}} sl@0: test regexp-11.5 {regsub errors} { sl@0: list [catch {regsub -gorp a b c} msg] $msg sl@0: } {1 {bad switch "-gorp": must be -all, -nocase, -expanded, -line, -linestop, -lineanchor, -start, or --}} sl@0: test regexp-11.6 {regsub errors} { sl@0: list [catch {regsub -nocase a( b c d} msg] $msg sl@0: } {1 {couldn't compile regular expression pattern: parentheses () not balanced}} sl@0: test regexp-11.7 {regsub errors} { sl@0: catch {unset f1} sl@0: set f1 44 sl@0: list [catch {regsub -nocase aaa aaa xxx f1(f2)} msg] $msg sl@0: } {1 {couldn't set variable "f1(f2)"}} sl@0: test regexp-11.8 {regsub errors, -start bad int check} { sl@0: list [catch {regsub -start bogus pattern string rep var} msg] $msg sl@0: } {1 {expected integer but got "bogus"}} sl@0: test regexp-11.9 {regsub without final variable name returns value} { sl@0: regsub b abaca X sl@0: } {aXaca} sl@0: test regexp-11.10 {regsub without final variable name returns value} { sl@0: regsub -all a abaca X sl@0: } {XbXcX} sl@0: test regexp-11.11 {regsub without final variable name returns value} { sl@0: regsub b(.*?)d abcdeabcfde {,&,\1,} sl@0: } {a,bcd,c,eabcfde} sl@0: test regexp-11.12 {regsub without final variable name returns value} { sl@0: regsub -all b(.*?)d abcdeabcfde {,&,\1,} sl@0: } {a,bcd,c,ea,bcfd,cf,e} sl@0: sl@0: # This test crashes on the Mac unless you increase the Stack Space to about 1 sl@0: # Meg. This is probably bigger than most users want... sl@0: # 8.2.3 regexp reduced stack space requirements, but this should be sl@0: # tested again sl@0: test regexp-12.1 {Tcl_RegExpExec: large number of subexpressions} {macCrash} { sl@0: 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: } {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: sl@0: test regexp-13.1 {regsub of a very large string} { sl@0: # This test is designed to stress the memory subsystem in order sl@0: # to catch Bug #933. It only fails if the Tcl memory allocator sl@0: # is in use. sl@0: sl@0: set line {BEGIN_TABLE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; END_TABLE} sl@0: set filedata [string repeat $line 200] sl@0: for {set i 1} {$i<10} {incr i} { sl@0: regsub -all "BEGIN_TABLE " $filedata "" newfiledata sl@0: } sl@0: set x done sl@0: } {done} sl@0: sl@0: test regexp-14.1 {CompileRegexp: regexp cache} { sl@0: regexp .*a b sl@0: regexp .*b c sl@0: regexp .*c d sl@0: regexp .*d e sl@0: regexp .*e f sl@0: set x . sl@0: append x *a sl@0: regexp $x bbba sl@0: } 1 sl@0: test regexp-14.2 {CompileRegexp: regexp cache, different flags} { sl@0: regexp .*a b sl@0: regexp .*b c sl@0: regexp .*c d sl@0: regexp .*d e sl@0: regexp .*e f sl@0: set x . sl@0: append x *a sl@0: regexp -nocase $x bbba sl@0: } 1 sl@0: sl@0: testConstraint exec [llength [info commands exec]] sl@0: test regexp-14.3 {CompileRegexp: regexp cache, empty regexp and empty cache} -constraints { sl@0: exec sl@0: } -setup { sl@0: set junk [makeFile {puts [regexp {} foo]} junk.tcl] sl@0: } -body { sl@0: exec [interpreter] $junk sl@0: } -cleanup { sl@0: removeFile junk.tcl sl@0: } -result 1 sl@0: sl@0: test regexp-15.1 {regexp -start} { sl@0: catch {unset x} sl@0: list [regexp -start -10 {\d} 1abc2de3 x] $x sl@0: } {1 1} sl@0: test regexp-15.2 {regexp -start} { sl@0: catch {unset x} sl@0: list [regexp -start 2 {\d} 1abc2de3 x] $x sl@0: } {1 2} sl@0: test regexp-15.3 {regexp -start} { sl@0: catch {unset x} sl@0: list [regexp -start 4 {\d} 1abc2de3 x] $x sl@0: } {1 2} sl@0: test regexp-15.4 {regexp -start} { sl@0: catch {unset x} sl@0: list [regexp -start 5 {\d} 1abc2de3 x] $x sl@0: } {1 3} sl@0: test regexp-15.5 {regexp -start, over end of string} { sl@0: catch {unset x} sl@0: list [regexp -start [string length 1abc2de3] {\d} 1abc2de3 x] [info exists x] sl@0: } {0 0} sl@0: test regexp-15.6 {regexp -start, loss of ^$ behavior} { sl@0: list [regexp -start 2 {^$} {}] sl@0: } {0} sl@0: sl@0: test regexp-16.1 {regsub -start} { sl@0: catch {unset x} sl@0: list [regsub -all -start 2 {\d} a1b2c3d4e5 {/&} x] $x sl@0: } {4 a1b/2c/3d/4e/5} sl@0: test regexp-16.2 {regsub -start} { sl@0: catch {unset x} sl@0: list [regsub -all -start -25 {z} hello {/&} x] $x sl@0: } {0 hello} sl@0: test regexp-16.3 {regsub -start} { sl@0: catch {unset x} sl@0: list [regsub -all -start 3 {z} hello {/&} x] $x sl@0: } {0 hello} sl@0: test regexp-16.4 {regsub -start, \A behavior} { sl@0: set out {} sl@0: lappend out [regsub -start 0 -all {\A(\w)} {abcde} {/\1} x] $x sl@0: lappend out [regsub -start 2 -all {\A(\w)} {abcde} {/\1} x] $x sl@0: } {5 /a/b/c/d/e 3 ab/c/d/e} sl@0: sl@0: test regexp-17.1 {regexp -inline} { sl@0: regexp -inline b ababa sl@0: } {b} sl@0: test regexp-17.2 {regexp -inline} { sl@0: regexp -inline (b) ababa sl@0: } {b b} sl@0: test regexp-17.3 {regexp -inline -indices} { sl@0: regexp -inline -indices (b) ababa sl@0: } {{1 1} {1 1}} sl@0: test regexp-17.4 {regexp -inline} { sl@0: regexp -inline {\w(\d+)\w} " hello 23 there456def " sl@0: } {e456d 456} sl@0: test regexp-17.5 {regexp -inline no matches} { sl@0: regexp -inline {\w(\d+)\w} "" sl@0: } {} sl@0: test regexp-17.6 {regexp -inline no matches} { sl@0: regexp -inline hello goodbye sl@0: } {} sl@0: test regexp-17.7 {regexp -inline, no matchvars allowed} { sl@0: list [catch {regexp -inline b abc match} msg] $msg sl@0: } {1 {regexp match variables not allowed when using -inline}} sl@0: sl@0: test regexp-18.1 {regexp -all} { sl@0: regexp -all b bbbbb sl@0: } {5} sl@0: test regexp-18.2 {regexp -all} { sl@0: regexp -all b abababbabaaaaaaaaaab sl@0: } {6} sl@0: test regexp-18.3 {regexp -all -inline} { sl@0: regexp -all -inline b abababbabaaaaaaaaaab sl@0: } {b b b b b b} sl@0: test regexp-18.4 {regexp -all -inline} { sl@0: regexp -all -inline {\w(\w)} abcdefg sl@0: } {ab b cd d ef f} sl@0: test regexp-18.5 {regexp -all -inline} { sl@0: regexp -all -inline {\w(\w)$} abcdefg sl@0: } {fg g} sl@0: test regexp-18.6 {regexp -all -inline} { sl@0: regexp -all -inline {\d+} 10:20:30:40 sl@0: } {10 20 30 40} sl@0: test regexp-18.7 {regexp -all -inline} { sl@0: list [catch {regexp -all -inline b abc match} msg] $msg sl@0: } {1 {regexp match variables not allowed when using -inline}} sl@0: test regexp-18.8 {regexp -all} { sl@0: # This should not cause an infinite loop sl@0: regexp -all -inline {a*} a sl@0: } {a} sl@0: test regexp-18.9 {regexp -all} { sl@0: # Yes, the expected result is {a {}}. Here's why: sl@0: # Start at index 0; a* matches the "a" there then stops. sl@0: # Go to index 1; a* matches the lambda (or {}) there then stops. Recall sl@0: # that a* matches zero or more "a"'s; thus it matches the string "b", as sl@0: # there are zero or more "a"'s there. sl@0: # Go to index 2; this is past the end of the string, so stop. sl@0: regexp -all -inline {a*} ab sl@0: } {a {}} sl@0: test regexp-18.10 {regexp -all} { sl@0: # Yes, the expected result is {a {} a}. Here's why: sl@0: # Start at index 0; a* matches the "a" there then stops. sl@0: # Go to index 1; a* matches the lambda (or {}) there then stops. Recall sl@0: # that a* matches zero or more "a"'s; thus it matches the string "b", as sl@0: # there are zero or more "a"'s there. sl@0: # Go to index 2; a* matches the "a" there then stops. sl@0: # Go to index 3; this is past the end of the string, so stop. sl@0: regexp -all -inline {a*} aba sl@0: } {a {} a} sl@0: test regexp-18.11 {regexp -all} { sl@0: regexp -all -inline {^a} aaaa sl@0: } {a} sl@0: test regexp-18.12 {regexp -all -inline -indices} { sl@0: regexp -all -inline -indices a(b(c)d|e(f)g)h abcdhaefgh sl@0: } {{0 4} {1 3} {2 2} {-1 -1} {5 9} {6 8} {-1 -1} {7 7}} sl@0: sl@0: test regexp-19.1 {regsub null replacement} { sl@0: regsub -all {@} {@hel@lo@} "\0a\0" result sl@0: list $result [string length $result] sl@0: } "\0a\0hel\0a\0lo\0a\0 14" sl@0: sl@0: test regexp-20.1 {regsub shared object shimmering} { sl@0: # Bug #461322 sl@0: set a abcdefghijklmnopqurstuvwxyz sl@0: set b $a sl@0: set c abcdefghijklmnopqurstuvwxyz0123456789 sl@0: regsub $a $c $b d sl@0: list $d [string length $d] [string bytelength $d] sl@0: } [list abcdefghijklmnopqurstuvwxyz0123456789 37 37] sl@0: test regexp-20.2 {regsub shared object shimmering with -about} { sl@0: eval regexp -about abc sl@0: } {0 {}} sl@0: sl@0: test regexp-21.1 {regsub works with empty string} { sl@0: regsub -- ^ {} foo sl@0: } {foo} sl@0: sl@0: test regexp-21.2 {regsub works with empty string} { sl@0: regsub -- \$ {} foo sl@0: } {foo} sl@0: sl@0: test regexp-21.3 {regsub works with empty string offset} { sl@0: regsub -start 0 -- ^ {} foo sl@0: } {foo} sl@0: sl@0: test regexp-21.4 {regsub works with empty string offset} { sl@0: regsub -start 0 -- \$ {} foo sl@0: } {foo} sl@0: sl@0: test regexp-21.5 {regsub works with empty string offset} { sl@0: regsub -start 3 -- \$ {123} foo sl@0: } {123foo} sl@0: sl@0: test regexp-21.6 {regexp works with empty string} { sl@0: regexp -- ^ {} sl@0: } {1} sl@0: sl@0: test regexp-21.7 {regexp works with empty string} { sl@0: regexp -start 0 -- ^ {} sl@0: } {1} sl@0: sl@0: test regexp-21.8 {regexp works with empty string offset} { sl@0: regexp -start 3 -- ^ {123} sl@0: } {0} sl@0: sl@0: test regexp-21.9 {regexp works with empty string offset} { sl@0: regexp -start 3 -- \$ {123} sl@0: } {1} sl@0: sl@0: test regexp-21.10 {multiple matches handle newlines} { sl@0: regsub -all -lineanchor -- {^#[^\n]*\n} "#one\n#two\n#three\n" foo\n sl@0: } "foo\nfoo\nfoo\n" sl@0: sl@0: test regexp-21.11 {multiple matches handle newlines} { sl@0: regsub -all -line -- ^ "a\nb\nc" \# sl@0: } "\#a\n\#b\n\#c" sl@0: sl@0: test regexp-21.12 {multiple matches handle newlines} { sl@0: regsub -all -line -- ^ "\n\n" \# sl@0: } "\#\n\#\n\#" sl@0: sl@0: test regexp-21.13 {multiple matches handle newlines} { sl@0: regexp -all -inline -indices -line -- ^ "a\nb\nc" sl@0: } {{0 -1} {2 1} {4 3}} sl@0: sl@0: # cleanup sl@0: ::tcltest::cleanupTests sl@0: return