Skip to content

Commit 279dab7

Browse files
committed
tests
1 parent 512cb17 commit 279dab7

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/regex/litopt.nim

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ func update(
8181
ends[ni].setLen 0
8282
for n in next:
8383
if n == eoe:
84-
ends[ni].add ni
84+
ends[ni].add ni
8585
else:
86-
ends[ni].add ends[n]
86+
ends[ni].add ends[n]
8787

8888
# Keep lits,
8989
# replace (...)+, (...)*, (...)?,
@@ -341,6 +341,12 @@ when isMainModule:
341341
doAssert lit"(?m)^" == "" # XXX \n
342342
doAssert lit"(?m)$" == "" # XXX \n
343343
doAssert lit"弢" == "" # XXX support unicode
344+
doAssert lit"(?<=\d)ab" == "b"
345+
doAssert lit"(?<=\w)ab" == "b"
346+
doAssert lit"(?<=\w+)ab" == "b"
347+
doAssert lit"\dab2" == "b"
348+
doAssert lit"\d+ab2" == "b"
349+
doAssert lit"\wab2" == ""
344350

345351
doAssert r"abc".prefix.toString == r"ba".toNfa.toString
346352
doAssert r"abcab".prefix.toString == r"ba".toNfa.toString

tests/tests2.nim

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2753,6 +2753,24 @@ test "tmisc3":
27532753
"He was carefully disguised but captured quickly by police.",
27542754
re2"\w+ly") == @["carefully", "quickly"]
27552755

2756+
test "misc4":
2757+
check findAllBounds(r"1abab", re2"(?<=\d)ab") == @[1 .. 2]
2758+
check findAllBounds(r"abab", re2"(?<=\d)ab").len == 0
2759+
check findAllBounds(r"abab1", re2"ab(?=\d)") == @[2 .. 3]
2760+
check findAllBounds(r"abab", re2"ab(?=\d)").len == 0
2761+
check findAllBounds(r"1ab1ab", re2"(?<=\d)ab") == @[1 .. 2, 4 .. 5]
2762+
check findAllBounds(r"ab1ab1", re2"ab(?=\d)") == @[0 .. 1, 3 .. 4]
2763+
check findAllBounds(r"1abab", re2"(\d)+ab") == @[0 .. 2]
2764+
check findAllBounds(r"abab", re2"(\d)+ab").len == 0
2765+
check findAllBounds(r"abab1", re2"ab(\d)+") == @[2 .. 4]
2766+
check findAllBounds(r"abab", re2"ab(\d)+").len == 0
2767+
check findAllBounds(r"1abab", re2"(?<=\d)a") == @[1 .. 1]
2768+
check findAllBounds(r"abab1", re2"b(?=\d)") == @[3 .. 3]
2769+
check findAllBounds(r"bb1", re2"b(?=\d)") == @[1 .. 1]
2770+
check findAllBounds(r"b1b1", re2"b(?=\d)") == @[0 .. 0, 2 .. 2]
2771+
check findAllBounds(r"1a1a1", re2"(?<=\d)a\d") == @[1 .. 2, 3 .. 4]
2772+
check findAllBounds(r"a1a1", re2"(?<=\d)a\d") == @[2 .. 3]
2773+
27562774
test "fix#83":
27572775
block:
27582776
let pattern = "^src/(?:[^\\/]*(?:\\/|$))*[^/]*\\.nim$"

0 commit comments

Comments
 (0)