diff options
Diffstat (limited to 'tests/regexpComp.test')
-rw-r--r-- | tests/regexpComp.test | 211 |
1 files changed, 188 insertions, 23 deletions
diff --git a/tests/regexpComp.test b/tests/regexpComp.test index a84099e..94fb90e 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 @@ -31,7 +29,8 @@ proc evalInProc { script } { #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,12 +316,12 @@ 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 ?-switch ...? 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 ?-switch ...? exp string ?matchVar? ?subMatchVar ...?"}} test regexpComp-6.3 {regexp errors} { evalInProc { list [catch {regexp -gorp a} 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 @@ -505,22 +562,22 @@ 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 ?-switch ...? 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 ?-switch ...? 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 ?-switch ...? 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 ?-switch ...? exp string subSpec ?varName?"}} test regexpComp-11.5 {regsub errors} { evalInProc { list [catch {regsub -gorp a b c} msg] $msg @@ -533,11 +590,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 @@ -604,23 +661,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 +685,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} { @@ -802,6 +859,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 +891,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: |