From 40f88da90b0589a91f4f60b2ebf49859b79e2247 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Tue, 30 May 2023 19:40:09 +0800 Subject: alternative to #21914; split, rsplit now forbid an empty separator (#21961) --- tests/stdlib/tstrutils.nim | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests/stdlib/tstrutils.nim') 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 " -- cgit 1.4.1-2-gfad0