aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2013-11-10 13:53:01 +1000
committerSteve Bennett <steveb@workware.net.au>2016-02-02 12:48:14 +1000
commit8df5aa2338453ebecb561df96a7c11d356400d77 (patch)
tree8322a549424ca61a5d101eeee26dcf5f64322dd2 /tests
parenta14c13716364a835a8ab6cfcb4aa969e8c3bcc23 (diff)
downloadjimtcl-8df5aa2338453ebecb561df96a7c11d356400d77.zip
jimtcl-8df5aa2338453ebecb561df96a7c11d356400d77.tar.gz
jimtcl-8df5aa2338453ebecb561df96a7c11d356400d77.tar.bz2
regexp: Enable additional regexp/regsub tests
Many Tcl regexp tests now work correctly with Jim regexp Also update regsub/regexp wrong # args error message to match Tcl 8.6 Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'tests')
-rw-r--r--tests/regexp.test135
-rw-r--r--tests/regexp2.test50
2 files changed, 97 insertions, 88 deletions
diff --git a/tests/regexp.test b/tests/regexp.test
index 57b4dd0..50a7772 100644
--- a/tests/regexp.test
+++ b/tests/regexp.test
@@ -16,6 +16,7 @@
source [file dirname [info script]]/testing.tcl
needs cmd regexp
+testConstraint regexp_are [regexp {\d} 1]
catch {unset foo}
test regexp-1.1 {basic regexp operation} {
@@ -33,9 +34,9 @@ test regexp-1.4 {basic regexp operation} {
test regexp-1.5 {basic regexp operation} {
regexp {^([^ ]*)[ ]*([^ ]*)} "" a
} 1
-#test regexp-1.6 {basic regexp operation} {
-# list [catch {regexp {} abc} msg] $msg
-#} {0 1}
+test regexp-1.6 {basic regexp operation} regexp_are {
+ list [catch {regexp {} abc} msg] $msg
+} {0 1}
#test regexp-1.7 {regexp utf compliance} {
# # if not UTF-8 aware, result is "0 1"
# set foo "\u4e4eb q"
@@ -192,21 +193,21 @@ test regexp-5.5 {exercise cache of compiled expressions} {
regexp .*e xe
} 1
-test regexp-6.1 {regexp errors} jim {
+test regexp-6.1 {regexp errors} {
list [catch {regexp a} msg] $msg
-} {1 {wrong # args: should be "regexp ?switches? exp string ?matchVar? ?subMatchVar subMatchVar ...?"}}
-test regexp-6.2 {regexp errors} jim {
+} {1 {wrong # args: should be "regexp ?-switch ...? exp string ?matchVar? ?subMatchVar ...?"}}
+test regexp-6.2 {regexp errors} {
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 regexp-6.3 {regexp errors} jim {
list [catch {regexp -gorp a} msg] $msg
} {1 {bad switch "-gorp": must be --, -all, -indices, -inline, -line, -nocase, or -start}}
test regexp-6.4 {regexp errors} {
catch {regexp a( b} msg
} 1
-#test regexp-6.5 {regexp errors} {
-# list [catch {regexp a) b} msg] [string match *parentheses* $msg]
-#} {1 1}
+test regexp-6.5 {regexp errors} regexp_are {
+ list [catch {regexp a) b} msg] [string match *parentheses* $msg]
+} {1 1}
test regexp-6.6 {regexp errors} {
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
} {0 1}
@@ -348,18 +349,18 @@ test regexp-10.3 {newline sensitivity in regsub} {
# list [regsub -linestop {a.*b} "da\nbaxyb\nxb" 123 foo] $foo
#} "1 {da\nb123\nxb}"
-test regexp-11.1 {regsub errors} jim {
+test regexp-11.1 {regsub errors} {
list [catch {regsub a b} msg] $msg
-} {1 {wrong # args: should be "regsub ?switches? exp string subSpec ?varName?"}}
-test regexp-11.2 {regsub errors} jim {
+} {1 {wrong # args: should be "regsub ?-switch ...? exp string subSpec ?varName?"}}
+test regexp-11.2 {regsub errors} {
list [catch {regsub -nocase a b} msg] $msg
-} {1 {wrong # args: should be "regsub ?switches? exp string subSpec ?varName?"}}
-test regexp-11.3 {regsub errors} jim {
+} {1 {wrong # args: should be "regsub ?-switch ...? exp string subSpec ?varName?"}}
+test regexp-11.3 {regsub errors} {
list [catch {regsub -nocase -all a b} msg] $msg
-} {1 {wrong # args: should be "regsub ?switches? exp string subSpec ?varName?"}}
-test regexp-11.4 {regsub errors} jim {
+} {1 {wrong # args: should be "regsub ?-switch ...? exp string subSpec ?varName?"}}
+test regexp-11.4 {regsub errors} {
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 regexp-11.5 {regsub errors} jim {
list [catch {regsub -gorp a b c} msg] $msg
} {1 {bad switch "-gorp": must be --, -all, -line, -nocase, or -start}}
@@ -430,23 +431,23 @@ test regexp-14.2 {CompileRegexp: regexp cache, different flags} {
regexp -nocase $x bbba
} 1
-#test regexp-15.1 {regexp -start} {
-# catch {unset x}
-# list [regexp -start -10 {\d} 1abc2de3 x] $x
-#} {1 1}
-#test regexp-15.2 {regexp -start} {
-# catch {unset x}
-# list [regexp -start 2 {\d} 1abc2de3 x] $x
-#} {1 2}
-#test regexp-15.3 {regexp -start} {
-# catch {unset x}
-# list [regexp -start 4 {\d} 1abc2de3 x] $x
-#} {1 2}
-#test regexp-15.4 {regexp -start} {
-# catch {unset x}
-# list [regexp -start 5 {\d} 1abc2de3 x] $x
-#} {1 3}
-test regexp-15.5 {regexp -start, over end of string} {
+test regexp-15.1 {regexp -start} regexp_are {
+ catch {unset x}
+ list [regexp -start -10 {\d} 1abc2de3 x] $x
+} {1 1}
+test regexp-15.2 {regexp -start} regexp_are {
+ catch {unset x}
+ list [regexp -start 2 {\d} 1abc2de3 x] $x
+} {1 2}
+test regexp-15.3 {regexp -start} regexp_are {
+ catch {unset x}
+ list [regexp -start 4 {\d} 1abc2de3 x] $x
+} {1 2}
+test regexp-15.4 {regexp -start} regexp_are {
+ catch {unset x}
+ list [regexp -start 5 {\d} 1abc2de3 x] $x
+} {1 3}
+test regexp-15.5 {regexp -start, over end of string} regexp_are {
catch {unset x}
list [regexp -start [string length 1abc2de3] {\d} 1abc2de3 x] [info exists x]
} {0 0}
@@ -459,19 +460,19 @@ test regexp-15.7 {regexp -start, double option} {
test regexp-15.8 {regexp -start, double option} {
regexp -start 0 -start 2 a abc
} 0
-#test regexp-15.9 {regexp -start, end relative index} {
-# catch {unset x}
-# list [regexp -start end {\d} 1abc2de3 x] [info exists x]
-#} {0 0}
-#test regexp-15.10 {regexp -start, end relative index} {
-# catch {unset x}
-# list [regexp -start end-1 {\d} 1abc2de3 x] [info exists x] $x
-#} {1 1 3}
-#
-#test regexp-16.1 {regsub -start} {
-# catch {unset x}
-# list [regsub -all -start 2 {\d} a1b2c3d4e5 {/&} x] $x
-#} {4 a1b/2c/3d/4e/5}
+test regexp-15.9 {regexp -start, end relative index} {
+ catch {unset x}
+ list [regexp -start end {\d} 1abc2de3 x] [info exists x]
+} {0 0}
+test regexp-15.10 {regexp -start, end relative index} regexp_are {
+ catch {unset x}
+ list [regexp -start end-1 {\d} 1abc2de3 x] [info exists x] $x
+} {1 1 3}
+
+test regexp-16.1 {regsub -start} regexp_are {
+ catch {unset x}
+ list [regsub -all -start 2 {\d} a1b2c3d4e5 {/&} x] $x
+} {4 a1b/2c/3d/4e/5}
test regexp-16.2 {regsub -start} {
catch {unset x}
list [regsub -all -start -25 {z} hello {/&} x] $x
@@ -507,12 +508,12 @@ test regexp-17.2 {regexp -inline} {
test regexp-17.3 {regexp -inline -indices} {
regexp -inline -indices (b) ababa
} {{1 1} {1 1}}
-#test regexp-17.4 {regexp -inline} {
-# regexp -inline {\w(\d+)\w} " hello 23 there456def "
-#} {e456d 456}
-#test regexp-17.5 {regexp -inline no matches} {
-# regexp -inline {\w(\d+)\w} ""
-#} {}
+test regexp-17.4 {regexp -inline} regexp_are {
+ regexp -inline {\w(\d+)\w} " hello 23 there456def "
+} {e456d 456}
+test regexp-17.5 {regexp -inline no matches} {
+ regexp -inline {\w(\d+)\w} ""
+} {}
test regexp-17.6 {regexp -inline no matches} {
regexp -inline hello goodbye
} {}
@@ -532,15 +533,15 @@ test regexp-18.2 {regexp -all} {
test regexp-18.3 {regexp -all -inline} {
regexp -all -inline b abababbabaaaaaaaaaab
} {b b b b b b}
-#test regexp-18.4 {regexp -all -inline} {
-# regexp -all -inline {\w(\w)} abcdefg
-#} {ab b cd d ef f}
-#test regexp-18.5 {regexp -all -inline} {
-# regexp -all -inline {\w(\w)$} abcdefg
-#} {fg g}
-#test regexp-18.6 {regexp -all -inline} {
-# regexp -all -inline {\d+} 10:20:30:40
-#} {10 20 30 40}
+test regexp-18.4 {regexp -all -inline} regexp_are {
+ regexp -all -inline {\w(\w)} abcdefg
+} {ab b cd d ef f}
+test regexp-18.5 {regexp -all -inline} regexp_are {
+ regexp -all -inline {\w(\w)$} abcdefg
+} {fg g}
+test regexp-18.6 {regexp -all -inline} regexp_are {
+ regexp -all -inline {\d+} 10:20:30:40
+} {10 20 30 40}
test regexp-18.7 {regexp -all -inline} {
list [catch {regexp -all -inline b abc match} msg] $msg
} {1 {regexp match variables not allowed when using -inline}}
@@ -684,4 +685,12 @@ test regexp-22.1 {effect of caching} jim {
expr {$t2 * 1.0 / $t1 < 1.2 && $t1 * 1.0 / $t2 < 1.2}
} {0}
+# Tests resulting from bugs reported by users
+test reg-31.1 {[[:xdigit:]] behaves correctly when followed by [[:space:]]} {
+ set str {2:::DebugWin32}
+ set re {([[:xdigit:]])([[:space:]]*)}
+ list [regexp $re $str match xdigit spaces] $match $xdigit $spaces
+ # Code used to produce {1 2:::DebugWin32 2 :::DebugWin32} !!!
+} {1 2 2 {}}
+
testreport
diff --git a/tests/regexp2.test b/tests/regexp2.test
index 165c187..f7cf516 100644
--- a/tests/regexp2.test
+++ b/tests/regexp2.test
@@ -495,36 +495,36 @@ test regexpComp-10.3 {newline sensitivity in regsub} {
# }
#} "1 {da\nb123\nxb}"
-#test regexpComp-11.1 {regsub errors} {
-# evalInProc {
-# list [catch {regsub a b} msg] $msg
-# }
-#} {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 ?-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 ?-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 ?-switch ...? exp string subSpec ?varName?"}}
+test regexpComp-11.1 {regsub errors} {
+ evalInProc {
+ list [catch {regsub a b} msg] $msg
+ }
+} {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 ?-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 ?-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 ?-switch ...? 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 --}}
-#test regexpComp-11.6 {regsub errors} {
-# evalInProc {
-# list [catch {regsub -nocase a( b c d} msg] $msg
-# }
-#} {1 {couldn't compile regular expression pattern: parentheses () not balanced}}
+test regexpComp-11.6 {regsub errors} {
+ evalInProc {
+ list [catch {regsub -nocase a( b c d} msg] $msg
+ }
+} {1 {couldn't compile regular expression pattern: parentheses () not balanced}}
test regexpComp-11.7 {regsub errors} {
evalInProc {
catch {unset f1}