init.nim 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import unittest
  2. include nre
  3. suite "Test NRE initialization":
  4. test "correct initialization":
  5. check(re("[0-9]+") != nil)
  6. check(re("(?i)[0-9]+") != nil)
  7. test "options":
  8. check(extractOptions("(*NEVER_UTF)") ==
  9. ("", pcre.NEVER_UTF, true))
  10. check(extractOptions("(*UTF8)(*ANCHORED)(*UCP)z") ==
  11. ("(*UTF8)(*UCP)z", pcre.ANCHORED, true))
  12. check(extractOptions("(*ANCHORED)(*UTF8)(*JAVASCRIPT_COMPAT)z") ==
  13. ("(*UTF8)z", pcre.ANCHORED or pcre.JAVASCRIPT_COMPAT, true))
  14. check(extractOptions("(*NO_STUDY)(") == ("(", 0, false))
  15. check(extractOptions("(*LIMIT_MATCH=6)(*ANCHORED)z") ==
  16. ("(*LIMIT_MATCH=6)z", pcre.ANCHORED, true))
  17. test "incorrect options":
  18. for s in ["CR", "(CR", "(*CR", "(*abc)", "(*abc)CR",
  19. "(?i)",
  20. "(*LIMIT_MATCH=5", "(*NO_AUTO_POSSESS=5)"]:
  21. let ss = s & "(*NEVER_UTF)"
  22. check(extractOptions(ss) == (ss, 0, true))
  23. test "invalid regex":
  24. expect(SyntaxError): discard re("[0-9")
  25. try:
  26. discard re("[0-9")
  27. except SyntaxError:
  28. let ex = SyntaxError(getCurrentException())
  29. check(ex.pos == 4)
  30. check(ex.pattern == "[0-9")