summaryrefslogtreecommitdiff
path: root/lib/regex/test/boundaries.myr
diff options
context:
space:
mode:
Diffstat (limited to 'lib/regex/test/boundaries.myr')
-rw-r--r--lib/regex/test/boundaries.myr36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/regex/test/boundaries.myr b/lib/regex/test/boundaries.myr
new file mode 100644
index 0000000..196d197
--- /dev/null
+++ b/lib/regex/test/boundaries.myr
@@ -0,0 +1,36 @@
+use std
+use "testmatch.use"
+
+const main = {
+ /* expected matches */
+ testmatch("\\<([a-z]*)\\>", "abcdef", `std.Some [
+ "abcdef",
+ ][:])
+ testmatch(".*(\\<.*\\>).*", "!m!", `std.Some [ /* single char word in midstring */
+ "m",
+ ][:])
+ testmatch(".*(\\<.*\\>).*", "!m", `std.Some [ /* single char word at end of string */
+ "m",
+ ][:])
+ testmatch(".*(\\<.*\\>).*", "m!", `std.Some [ /* single char word at start of string */
+ "m",
+ ][:])
+ testmatch(".*(\\<.*\\>).*", "!@#!!matches!!%!", `std.Some [ /* word in midstring */
+ "matches",
+ ][:])
+ testmatch(".*(\\<.*\\>).*", "matches!!%!", `std.Some [ /* word at start of string */
+ "matches",
+ ][:])
+ testmatch(".*(\\<.*\\>).*", "!@#!!matches", `std.Some [ /* word at end of string */
+ "matches",
+ ][:])
+ testmatch(".*(\\<.*\\>).*", "!@#!!matches!!%!foo", `std.Some [ /* matches last word in string */
+ "foo",
+ ][:])
+ testmatch(".*(\\<.*\\>).*", "123", `std.Some [ /* numbers are also word bounds */
+ "123",
+ ][:])
+
+ /* nonmatches */
+ testmatch("\\<([a-z]*)\\>foo", "abcdefoo", `std.None) /* word boundary needed in midstring */
+}