Rearrange nre files
This commit is contained in:
parent
0d4aeec9be
commit
0527e1f9fe
47 changed files with 12 additions and 343 deletions
36
tests/stdlib/nre/init.nim
Normal file
36
tests/stdlib/nre/init.nim
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import unittest, private/pcre
|
||||
include nre
|
||||
|
||||
suite "Test NRE initialization":
|
||||
test "correct intialization":
|
||||
check(re("[0-9]+") != nil)
|
||||
check(re("(?i)[0-9]+") != nil)
|
||||
|
||||
test "options":
|
||||
check(extractOptions("(*NEVER_UTF)") ==
|
||||
("", pcre.NEVER_UTF, true))
|
||||
check(extractOptions("(*UTF8)(*ANCHORED)(*UCP)z") ==
|
||||
("(*UTF8)(*UCP)z", pcre.ANCHORED, true))
|
||||
check(extractOptions("(*ANCHORED)(*UTF8)(*JAVASCRIPT_COMPAT)z") ==
|
||||
("(*UTF8)z", pcre.ANCHORED or pcre.JAVASCRIPT_COMPAT, true))
|
||||
|
||||
check(extractOptions("(*NO_STUDY)(") == ("(", 0, false))
|
||||
|
||||
check(extractOptions("(*LIMIT_MATCH=6)(*ANCHORED)z") ==
|
||||
("(*LIMIT_MATCH=6)z", pcre.ANCHORED, true))
|
||||
|
||||
test "incorrect options":
|
||||
for s in ["CR", "(CR", "(*CR", "(*abc)", "(*abc)CR",
|
||||
"(?i)",
|
||||
"(*LIMIT_MATCH=5", "(*NO_AUTO_POSSESS=5)"]:
|
||||
let ss = s & "(*NEVER_UTF)"
|
||||
check(extractOptions(ss) == (ss, 0, true))
|
||||
|
||||
test "invalid regex":
|
||||
expect(SyntaxError): discard re("[0-9")
|
||||
try:
|
||||
discard re("[0-9")
|
||||
except SyntaxError:
|
||||
let ex = SyntaxError(getCurrentException())
|
||||
check(ex.pos == 4)
|
||||
check(ex.pattern == "[0-9")
|
||||
Loading…
Add table
Add a link
Reference in a new issue