Implement match, find, split
This commit is contained in:
parent
6fe0de0639
commit
2474758ed5
3 changed files with 145 additions and 8 deletions
14
test/find.nim
Normal file
14
test/find.nim
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import unittest
|
||||
include nre
|
||||
|
||||
suite "find":
|
||||
test "find text":
|
||||
check(initRegex(r"[a-z]").find("3213a").get.match == "a")
|
||||
check(initRegex(r" ", "S").findAll("1 2 3 4 5 6 7 8 ").map(
|
||||
proc (a: RegexMatch): string = a.match
|
||||
) == @[" ", " ", " ", " ", " ", " ", " ", " "])
|
||||
|
||||
test "find bounds":
|
||||
check(initRegex(r" ", "S").findAll("1 2 3 4 5 ").map(
|
||||
proc (a: RegexMatch): Slice[int] = a.matchBounds
|
||||
) == @[1..2, 3..4, 5..6, 7..8, 9..10])
|
||||
9
test/split.nim
Normal file
9
test/split.nim
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import unittest
|
||||
include nre
|
||||
|
||||
suite "string splitting":
|
||||
test "splitting strings":
|
||||
check(initRegex("").split("12345") == @["1", "2", "3", "4", "5"])
|
||||
check(initRegex(" ", "S").split("1 2 3 4 5 6 ") == @["1", "2", "3", "4", "5", "6", ""])
|
||||
check(initRegex(" ", "S").split("1 2 ") == @["1", "", "2", "", ""])
|
||||
check(initRegex(" ", "S").split("1 2") == @["1", "2"])
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
import nre
|
||||
import init
|
||||
import captures
|
||||
import find
|
||||
import split
|
||||
|
|
|
|||
Loading…
Reference in a new issue