Files
Nim/test/split.nim
2015-01-18 13:04:56 -05:00

19 lines
666 B
Nim

import unittest
include nre
suite "string splitting":
test "splitting strings":
check("12345".split(re("")) == @["1", "2", "3", "4", "5"])
check("1 2 3 4 5 6 ".split(re" ") == @["1", "2", "3", "4", "5", "6", ""])
check("1 2 ".split(re(" ")) == @["1", "", "2", "", ""])
check("1 2".split(re(" ")) == @["1", "2"])
check("foo".split(re("foo")) == @["", ""])
test "captured patterns":
check("12".split(re"(\d)") == @["", "1", "", "2", ""])
test "maxsplit":
check("123".split(re"", maxsplit = 1) == @["1", "23"])
check("123".split(re"", maxsplit = 0) == @["123"])
check("123".split(re"", maxsplit = -1) == @["1", "2", "3"])