match.nim 751 B

12345678910111213141516171819
  1. include nre, unittest, optional_nonstrict
  2. suite "match":
  3. test "upper bound must be inclusive":
  4. check("abc".match(re"abc", endpos = -1) == none(RegexMatch))
  5. check("abc".match(re"abc", endpos = 1) == none(RegexMatch))
  6. check("abc".match(re"abc", endpos = 2) != none(RegexMatch))
  7. test "match examples":
  8. check("abc".match(re"(\w)").captures[0] == "a")
  9. check("abc".match(re"(?<letter>\w)").captures["letter"] == "a")
  10. check("abc".match(re"(\w)\w").captures[-1] == "ab")
  11. check("abc".match(re"(\w)").captureBounds[0] == 0 .. 0)
  12. check("abc".match(re"").captureBounds[-1] == 0 .. -1)
  13. check("abc".match(re"abc").captureBounds[-1] == 0 .. 2)
  14. test "match test cases":
  15. check("123".match(re"").matchBounds == 0 .. -1)