diff options
Diffstat (limited to 'tests/regexpComp.test')
| -rw-r--r-- | tests/regexpComp.test | 232 | 
1 files changed, 201 insertions, 31 deletions
| diff --git a/tests/regexpComp.test b/tests/regexpComp.test index a84099e..b8e64b6 100644 --- a/tests/regexpComp.test +++ b/tests/regexpComp.test @@ -10,8 +10,6 @@  #  # See the file "license.terms" for information on usage and redistribution  # of this file, and for a DISCLAIMER OF ALL WARRANTIES. -# -# RCS: @(#) $Id$  if {[lsearch [namespace children] ::tcltest] == -1} {      package require tcltest 2 @@ -24,14 +22,15 @@ if {[lsearch [namespace children] ::tcltest] == -1} {  proc evalInProc { script } {      proc testProc {} $script      set status [catch { -	testProc  +	testProc      } result]      rename testProc {}      return $result      #return [list $status $result]  } -catch {unset foo} +unset -nocomplain foo +  test regexpComp-1.1 {basic regexp operation} {      evalInProc {  	regexp ab*c abbbc @@ -43,7 +42,7 @@ test regexpComp-1.2 {basic regexp operation} {      }  } 1  test regexpComp-1.3 {basic regexp operation} { -    evalInProc {     +    evalInProc {  	regexp ab*c ab      }  } 0 @@ -69,6 +68,64 @@ test regexpComp-1.7 {regexp utf compliance} {      }  } {0 0} +test regexpComp-1.8 {regexp ***= metasyntax} { +    evalInProc { +	regexp -- "***=o" "aeiou" +    } +} 1 +test regexpComp-1.9 {regexp ***= metasyntax} { +    evalInProc { +	set string "aeiou" +	regexp -- "***=o" $string +    } +} 1 +test regexpComp-1.10 {regexp ***= metasyntax} { +    evalInProc { +	set string "aeiou" +	set re "***=o" +	regexp -- $re $string +    } +} 1 +test regexpComp-1.11 {regexp ***= metasyntax} { +    evalInProc { +	regexp -- "***=y" "aeiou" +    } +} 0 +test regexpComp-1.12 {regexp ***= metasyntax} { +    evalInProc { +	set string "aeiou" +	regexp -- "***=y" $string +    } +} 0 +test regexpComp-1.13 {regexp ***= metasyntax} { +    evalInProc { +	set string "aeiou" +	set re "***=y" +	regexp -- $re $string +    } +} 0 +test regexpComp-1.14 {regexp ***= metasyntax} { +    evalInProc { +	set string "aeiou" +	set re "***=e*o" +	regexp -- $re $string +    } +} 0 +test regexpComp-1.15 {regexp ***= metasyntax} { +    evalInProc { +	set string "ae*ou" +	set re "***=e*o" +	regexp -- $re $string +    } +} 1 +test regexpComp-1.16 {regexp ***= metasyntax} { +    evalInProc { +	set string {ae*[o]?ua} +	set re {***=e*[o]?u} +	regexp -- $re $string +    } +} 1 +  test regexpComp-2.1 {getting substrings back from regexp} {      evalInProc {  	set foo {} @@ -202,7 +259,7 @@ test regexpComp-4.4 {case conversion in regexp} {  	list [regexp -nocase $::x $::x foo] $foo      }  } "1 $x" -catch {unset ::x} +unset -nocomplain ::x  test regexpComp-5.1 {exercise cache of compiled expressions} {      evalInProc { @@ -259,17 +316,17 @@ test regexpComp-6.1 {regexp errors} {      evalInProc {  	list [catch {regexp a} msg] $msg      } -} {1 {wrong # args: should be "regexp ?switches? exp string ?matchVar? ?subMatchVar subMatchVar ...?"}} +} {1 {wrong # args: should be "regexp ?-option ...? exp string ?matchVar? ?subMatchVar ...?"}}  test regexpComp-6.2 {regexp errors} {      evalInProc {  	list [catch {regexp -nocase a} msg] $msg      } -} {1 {wrong # args: should be "regexp ?switches? exp string ?matchVar? ?subMatchVar subMatchVar ...?"}} +} {1 {wrong # args: should be "regexp ?-option ...? exp string ?matchVar? ?subMatchVar ...?"}}  test regexpComp-6.3 {regexp errors} {      evalInProc {  	list [catch {regexp -gorp a} msg] $msg      } -} {1 {bad switch "-gorp": must be -all, -about, -indices, -inline, -expanded, -line, -linestop, -lineanchor, -nocase, -start, or --}} +} {1 {bad option "-gorp": must be -all, -about, -indices, -inline, -expanded, -line, -linestop, -lineanchor, -nocase, -start, or --}}  test regexpComp-6.4 {regexp errors} {      evalInProc {  	list [catch {regexp a( b} msg] $msg @@ -292,11 +349,11 @@ test regexpComp-6.7 {regexp errors} {  } {0 0}  test regexpComp-6.8 {regexp errors} {      evalInProc { -	catch {unset f1} +	unset -nocomplain f1  	set f1 44  	list [catch {regexp abc abc f1(f2)} msg] $msg      } -} {1 {couldn't set variable "f1(f2)"}} +} {1 {can't set "f1(f2)": variable isn't array}}  test regexpComp-6.9 {regexp errors, -start bad int check} {      evalInProc {  	list [catch {regexp -start bogus {^$} {}} msg] $msg @@ -469,6 +526,11 @@ test regexpComp-9.6 {-all option to regsub} {  	list [regsub -all ^ xxx 123 foo] $foo      }  } {1 123xxx} +test regexpComp-9.7 {Bug 84af1192f5: -all option to regsub} { +    evalInProc { +	regsub -all {\(.*} 123(qwe) "" +    } +} 123  test regexpComp-10.1 {expanded syntax in regsub} {      evalInProc { @@ -505,27 +567,27 @@ test regexpComp-11.1 {regsub errors} {      evalInProc {  	list [catch {regsub a b} msg] $msg      } -} {1 {wrong # args: should be "regsub ?switches? exp string subSpec ?varName?"}} +} {1 {wrong # args: should be "regsub ?-option ...? exp string subSpec ?varName?"}}  test regexpComp-11.2 {regsub errors} {      evalInProc {  	list [catch {regsub -nocase a b} msg] $msg      } -} {1 {wrong # args: should be "regsub ?switches? exp string subSpec ?varName?"}} +} {1 {wrong # args: should be "regsub ?-option ...? exp string subSpec ?varName?"}}  test regexpComp-11.3 {regsub errors} {      evalInProc {  	list [catch {regsub -nocase -all a b} msg] $msg      } -} {1 {wrong # args: should be "regsub ?switches? exp string subSpec ?varName?"}} +} {1 {wrong # args: should be "regsub ?-option ...? exp string subSpec ?varName?"}}  test regexpComp-11.4 {regsub errors} {      evalInProc {  	list [catch {regsub a b c d e f} msg] $msg      } -} {1 {wrong # args: should be "regsub ?switches? exp string subSpec ?varName?"}} +} {1 {wrong # args: should be "regsub ?-option ...? exp string subSpec ?varName?"}}  test regexpComp-11.5 {regsub errors} {      evalInProc {  	list [catch {regsub -gorp a b c} msg] $msg      } -} {1 {bad switch "-gorp": must be -all, -nocase, -expanded, -line, -linestop, -lineanchor, -start, or --}} +} {1 {bad option "-gorp": must be -all, -nocase, -expanded, -line, -linestop, -lineanchor, -start, or --}}  test regexpComp-11.6 {regsub errors} {      evalInProc {  	list [catch {regsub -nocase a( b c d} msg] $msg @@ -533,11 +595,11 @@ test regexpComp-11.6 {regsub errors} {  } {1 {couldn't compile regular expression pattern: parentheses () not balanced}}  test regexpComp-11.7 {regsub errors} {      evalInProc { -	catch {unset f1} +	unset -nocomplain f1  	set f1 44  	list [catch {regsub -nocase aaa aaa xxx f1(f2)} msg] $msg      } -} {1 {couldn't set variable "f1(f2)"}} +} {1 {can't set "f1(f2)": variable isn't array}}  test regexpComp-11.8 {regsub errors, -start bad int check} {      evalInProc {  	list [catch {regsub -start bogus pattern string rep var} msg] $msg @@ -545,7 +607,7 @@ test regexpComp-11.8 {regsub errors, -start bad int check} {  } {1 {bad index "bogus": must be integer?[+-]integer? or end?[+-]integer?}}  # This test crashes on the Mac unless you increase the Stack Space to about 1 -# Meg.  This is probably bigger than most users want...  +# Meg.  This is probably bigger than most users want...  # 8.2.3 regexp reduced stack space requirements, but this should be  # tested again  test regexpComp-12.1 {Tcl_RegExpExec: large number of subexpressions} {macCrash} { @@ -604,23 +666,23 @@ test regexpComp-14.3 {CompileRegexp: regexp cache, empty regexp and empty cache}  } -result 1  test regexpComp-15.1 {regexp -start} { -    catch {unset x} +    unset -nocomplain x      list [regexp -start -10 {\d} 1abc2de3 x] $x  } {1 1}  test regexpComp-15.2 {regexp -start} { -    catch {unset x} +    unset -nocomplain x      list [regexp -start 2 {\d} 1abc2de3 x] $x  } {1 2}  test regexpComp-15.3 {regexp -start} { -    catch {unset x} +    unset -nocomplain x      list [regexp -start 4 {\d} 1abc2de3 x] $x  } {1 2}  test regexpComp-15.4 {regexp -start} { -    catch {unset x} +    unset -nocomplain x      list [regexp -start 5 {\d} 1abc2de3 x] $x  } {1 3}  test regexpComp-15.5 {regexp -start, over end of string} { -    catch {unset x} +    unset -nocomplain x      list [regexp -start [string length 1abc2de3] {\d} 1abc2de3 x] [info exists x]  } {0 0}  test regexpComp-15.6 {regexp -start, loss of ^$ behavior} { @@ -628,15 +690,15 @@ test regexpComp-15.6 {regexp -start, loss of ^$ behavior} {  } {0}  test regexpComp-16.1 {regsub -start} { -    catch {unset x} +    unset -nocomplain x      list [regsub -all -start 2 {\d} a1b2c3d4e5 {/&} x] $x  } {4 a1b/2c/3d/4e/5}  test regexpComp-16.2 {regsub -start} { -    catch {unset x} +    unset -nocomplain x      list [regsub -all -start -25 {z} hello {/&} x] $x  } {0 hello}  test regexpComp-16.3 {regsub -start} { -    catch {unset x} +    unset -nocomplain x      list [regsub -all -start 3 {z} hello {/&} x] $x  } {0 hello}  test regexpComp-16.4 {regsub -start, \A behavior} { @@ -732,10 +794,10 @@ test regexpComp-19.1 {regsub null replacement} {  test regexpComp-20.1 {regsub shared object shimmering} {      evalInProc {  	# Bug #461322 -	set a abcdefghijklmnopqurstuvwxyz  -	set b $a  -	set c abcdefghijklmnopqurstuvwxyz0123456789  -	regsub $a $c $b d  +	set a abcdefghijklmnopqurstuvwxyz +	set b $a +	set c abcdefghijklmnopqurstuvwxyz0123456789 +	regsub $a $c $b d  	list $d [string length $d] [string bytelength $d]      }  } [list abcdefghijklmnopqurstuvwxyz0123456789 37 37] @@ -802,6 +864,18 @@ test regexpComp-21.11 {regexp command compiling tests} {      }  } {0 {}} +test regexpComp-22.0.1 {Bug 1810038} { +    evalInProc { +	regexp ($|^X)* {} +    } +} 1 + +test regexpComp-22.0.2 {regexp compile and backrefs, Bug 1857126} { +    evalInProc { +	regexp -- {([bc])\1} bb +    } +} 1 +  set i 0  foreach {str exp result} {      foo		^foo		1 @@ -822,6 +896,102 @@ foreach {str exp result} {  	     [subst {evalInProc {set a "$str"; regexp {$exp} \$a}}] $result  } +set i 0 +foreach {str exp result} { +    foo		^foo		1 +    foobar	^foobar$	1 +    foobar	bar$		1 +    foobar	^$		0 +    ""		^$		1 +    anything	$		1 +    anything	^.*$		1 +    anything	^.*a$		0 +    anything	^.*a.*$		1 +    anything	^.*.*$		1 +    anything	^.*..*$		1 +    anything	^.*b$		0 +    anything	^a.*$		1 +} { +    test regexpComp-23.[incr i] {regexp command compiling tests INST_REGEXP} \ +	[subst {evalInProc {set a "$str"; set re "$exp"; regexp \$re \$a}}] $result +} + +test regexpComp-24.1 {regexp command compiling tests} { +    evalInProc { +	set re foo +	regexp -nocase $re bar +    } +} 0 +test regexpComp-24.2 {regexp command compiling tests} { +    evalInProc { +	set re {^foo$} +	regexp $re dogfood +    } +} 0 +test regexpComp-24.3 {regexp command compiling tests} { +    evalInProc { +	set a foo +	set re {^foo$} +	regexp $re $a +    } +} 1 +test regexpComp-24.4 {regexp command compiling tests} { +    evalInProc { +	set re foo +	regexp $re dogfood +    } +} 1 +test regexpComp-24.5 {regexp command compiling tests} { +    evalInProc { +	set re FOO +	regexp -nocase $re dogfod +    } +} 0 +test regexpComp-24.6 {regexp command compiling tests} { +    evalInProc { +	set re foo +	regexp -n $re dogfoOd +    } +} 1 +test regexpComp-24.7 {regexp command compiling tests} { +    evalInProc { +	set re FoO +	regexp -no -- $re dogfood +    } +} 1 +test regexpComp-24.8 {regexp command compiling tests} { +    evalInProc { +	set re foo +	regexp -- $re dogfod +    } +} 0 +test regexpComp-24.9 {regexp command compiling tests} { +    evalInProc { +	set re "(" +	list [catch {regexp -- $re dogfod} msg] $msg +    } +} {1 {couldn't compile regular expression pattern: parentheses () not balanced}} +test regexpComp-24.10 {regexp command compiling tests} { +    # Bug 1902436 - last * escaped +    evalInProc { +	set text {this is *bold* !} +	set re {\*bold\*} +	regexp -- $re $text +    } +} 1 +test regexpComp-24.11 {regexp command compiling tests} { +    # Bug 1902436 - last * escaped +    evalInProc { +	set text {this is *bold* !} +	set re {\*bold\*.*!} +	regexp -- $re $text +    } +} 1 +  # cleanup  ::tcltest::cleanupTests  return + +# Local Variables: +# mode: tcl +# End: | 
