ref: ef39ec1f6098ff0444b9ca36091204534cecedda
parent: 06d68114701f1c0007f8e4ae23190704126c6773
author: Ori Bernstein <[email protected]>
date: Mon Dec 30 18:56:22 EST 2013
Add tests for negated character classes.
--- /dev/null
+++ b/test/data/regex-negclass-expected
@@ -1,0 +1,50 @@
+Matched. 1 matches
+match 0: x
+Matched. 1 matches
+match 0: xa!#^cs
+No match
+No match
+No match
+No match
+Matched. 1 matches
+match 0: Z
+Matched. 1 matches
+match 0: gg
+No match
+No match
+Matched. 1 matches
+match 0: a
+Matched. 1 matches
+match 0: i%
+Matched. 1 matches
+match 0: alskd690!#!!
+No match
+No match
+No match
+Matched. 1 matches
+match 0: !%!^^@@!^
+No match
+Matched. 1 matches
+match 0:
+
+Matched. 1 matches
+match 0:
+
+No match
+No match
+No match
+Matched. 1 matches
+match 0: ABCD
+Matched. 1 matches
+match 0: 1234
+Matched. 1 matches
+match 0: -^^-
+Matched. 1 matches
+match 0: d6d
+Matched. 1 matches
+match 0: !^!!))#
+No match
+No match
+No match
+No match
+No match
--- /dev/null
+++ b/test/regex-negclass.myr
@@ -1,0 +1,72 @@
+use std
+
+use "testmatch.use"
+
+const main = {
+ asciiclass()
+ set()
+ /*
+ unicodeclass()
+ negasciiclass()
+ negasciirange()
+ negset()
+ */
+}
+
+const asciiclass = {
+ /* \D success */
+ testmatch("\\D", "x")
+ testmatch("\\D+", "xa!#^cs")
+
+ /* \D fail: end of ranges chars */
+ testmatch("\\D", "0")
+ testmatch("\\D", "9")
+ testmatch("\\D+", "a35x")
+ testmatch("\\D+", "13688")
+
+ /* \X success */
+ testmatch("\\X", "Z")
+ testmatch("\\X\\X", "gg")
+ /* \X fail */
+ testmatch("\\X", "a")
+ testmatch("\\X+", "zz13b8cDEf")
+
+ /* \S success */
+ testmatch("\\S", "a")
+ testmatch("\\S\\S", "i%")
+ testmatch("\\S+", "alskd690!#!!")
+
+ /* \S fail */
+ testmatch("\\S", " ")
+ testmatch("\\S\\S", "\t\n")
+ testmatch("\\S+", "\t \nkait")
+
+ /* word success */
+ testmatch("\\W+", "!%!^^@@!^")
+ /* word fail */
+ testmatch("\\W+", "a^#$bcABC0123_")
+
+ /* \H success */
+ testmatch("\\H", "\n")
+ testmatch("\\H\\H", "\n\r")
+ /* \H fail */
+ testmatch("\\H+", "\t \t.")
+ testmatch("\\H\\H", "\t ")
+ testmatch("\\H+", "\ta35 \t ")
+}
+
+const set = {
+ /* ranges: should succeed */
+ testmatch("[^a-z]*", "ABCD")
+ testmatch("[^a-zA-Z]*", "1234")
+ testmatch("[^a-zA-Z0-9_]*", "-^^-")
+ testmatch("[^abc]*", "d6d")
+ testmatch("[^a-zABC]*", "!^!!))#")
+
+ /* ranges: should fail */
+ testmatch("[^a-z]*", "abcd")
+ testmatch("[^a-zA-Z]*", "abCD")
+ testmatch("[^a-zA-Z0-9_]*", "_abCD018")
+ testmatch("[^abc]*", "abba")
+ testmatch("[^a-zABC]*", "abBa")
+}