diff options
author | ringabout <43030857+ringabout@users.noreply.github.com> | 2023-05-30 19:40:09 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-30 13:40:09 +0200 |
commit | 40f88da90b0589a91f4f60b2ebf49859b79e2247 (patch) | |
tree | 4850674d0e8ce1726f7ab071693e198359d0a801 /tests/stdlib/tstrutils.nim | |
parent | 7e055413f9bbec81fc9b7e1542695f2886787566 (diff) | |
download | Nim-40f88da90b0589a91f4f60b2ebf49859b79e2247.tar.gz |
alternative to #21914; split, rsplit now forbid an empty separator (#21961)
Diffstat (limited to 'tests/stdlib/tstrutils.nim')
-rw-r--r-- | tests/stdlib/tstrutils.nim | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/stdlib/tstrutils.nim b/tests/stdlib/tstrutils.nim index 67eb5cf3a..d53e9d8b4 100644 --- a/tests/stdlib/tstrutils.nim +++ b/tests/stdlib/tstrutils.nim @@ -53,6 +53,13 @@ template main() = doAssert s.split(maxsplit = 4) == @["", "this", "is", "an", "example "] doAssert s.split(' ', maxsplit = 1) == @["", "this is an example "] doAssert s.split(" ", maxsplit = 4) == @["", "this", "is", "an", "example "] + # Empty string: + doAssert "".split() == @[""] + doAssert "".split(" ") == @[""] + doAssert "".split({' '}) == @[""] + # Empty separators: + doAssertRaises(AssertionDefect): discard s.split({}) + doAssertRaises(AssertionDefect): discard s.split("") block: # splitLines let fixture = "a\nb\rc\r\nd" @@ -69,6 +76,13 @@ template main() = doAssert rsplit(":foo:bar", sep = ':', maxsplit = 2) == @["", "foo", "bar"] doAssert rsplit(":foo:bar", sep = ':', maxsplit = 3) == @["", "foo", "bar"] doAssert rsplit("foothebar", sep = "the") == @["foo", "bar"] + # Empty string: + doAssert "".rsplit() == @[""] + doAssert "".rsplit(" ") == @[""] + doAssert "".rsplit({' '}) == @[""] + # Empty separators: + doAssertRaises(AssertionDefect): discard "".rsplit({}) + doAssertRaises(AssertionDefect): discard "".rsplit("") block: # splitWhitespace let s = " this is an example " |