Skip to content

Commit 45cb22f

Browse files
committed
tests
1 parent c51a870 commit 45cb22f

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

tests/tests_misc.nim

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ DEALINGS IN THE SOFTWARE.
5454
]#
5555

5656
from std/sequtils import map
57+
from std/strutils import splitLines
5758
import ../src/regex
5859

5960
const nonCapture = reNonCapture
@@ -724,3 +725,49 @@ test "rebar":
724725
check findAllBounds("a", re2(r"A", {regexCaseless})) == @[0 .. 0]
725726
check findAllBounds("A", re2(r"a", {regexCaseless})) == @[0 .. 0]
726727
check findAllBounds("@", re2(r"@", {regexCaseless})) == @[0 .. 0]
728+
block:
729+
var i = 0
730+
for line in "foo foo\nZ\nfoo".splitLines:
731+
i += int(re2"[a-z][a-z][a-z]" in line)
732+
check i == 2
733+
block:
734+
var i = 0
735+
for line in "foo foo\r\nZ\r\nfoo\r\nfoo".splitLines:
736+
for m in findAll(line, re2"([a-z][a-z])([a-z])([\r\n])?"):
737+
for c in m.captures:
738+
i += int(c != reNonCapture)
739+
i += 1 # bounds
740+
check i == 12
741+
742+
# These only work by chance, nim-regex expects valid utf-8
743+
when false:
744+
var i = 0
745+
for line in "./tests/lh3lh3-reb-howto.txt".lines:
746+
i += int(re2"([a-zA-Z][a-zA-Z0-9]*)://([^ /]+)(/[^ ]*)?" in line)
747+
check i == 17_549
748+
when false:
749+
var i = 0
750+
for line in "./tests/lh3lh3-reb-howto.txt".lines:
751+
i += int(re2"([^ @]+)@([^ @]+)" in line)
752+
check i == 15057
753+
when false:
754+
var i = 0
755+
for line in "./tests/lh3lh3-reb-howto.txt".lines:
756+
i += int(re2"([0-9][0-9]?)/([0-9][0-9]?)/([0-9][0-9]([0-9][0-9])?)" in line)
757+
check i == 668
758+
when false:
759+
var i = 0
760+
for line in "./tests/lh3lh3-reb-howto.txt".lines:
761+
let line = line.toValidUtf8
762+
i += int(re2"([a-zA-Z][a-zA-Z0-9]*)://([^ /]+)(/[^ ]*)?|([^ @]+)@([^ @]+)" in line)
763+
check i == 32539
764+
when false:
765+
var i = 0
766+
for line in "./tests/rust-src-tools-3b0d4813.txt".lines:
767+
i += int(re2(r"\b\w{25,}\b", {regexAscii}) in line)
768+
check i == 5073
769+
when false:
770+
var i = 0
771+
for line in "./tests/rust-src-tools-3b0d4813.txt".lines:
772+
i += int(re2"\b\w{25,}\b" in line)
773+
check i == 5075

0 commit comments

Comments
 (0)