From 94149f7a48e1fc2730769ee181bbd09942051c9b Mon Sep 17 00:00:00 2001 From: Zach Aysan Date: Tue, 21 Jul 2015 15:04:10 -0400 Subject: [PATCH] Update tests to proposed changes --- tests/stdlib/tstrutil.nim | 55 +++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/tests/stdlib/tstrutil.nim b/tests/stdlib/tstrutil.nim index d807cd11c..b15bf0e68 100644 --- a/tests/stdlib/tstrutil.nim +++ b/tests/stdlib/tstrutil.nim @@ -10,25 +10,48 @@ import proc testStrip() = write(stdout, strip(" ha ")) -proc testChomp = - assert "hello".chomp == "hello" - assert "hello\n".chomp == "hello" - assert "hello\r\n".chomp == "hello" - assert "hello\n\r".chomp == "hello\n" - assert "hello\n\n".chomp == "hello\n" - assert "hello\r".chomp == "hello" - assert "hello \n there".chomp == "hello \n there" - assert "hello".chomp("llo") == "he" - assert "hellos".chomp('s') == "hello" - assert "hellos".chomp({'s','z'}) == "hello" - assert "hellos".chomp({'o','s'}) == "hello" - assert "hello\r\n\r\n".chomp("") == "hello" - assert "hello\r\n\r\r\n".chomp("") == "hello\r\n\r" - assert "hello\n\n\n\n\n".chomp("") == "hello" +proc testRemoveSuffix = + var s = "hello\n\r" + s.removeSuffix + assert s == "hello\n" + s.removeSuffix + assert s == "hello" + s.removeSuffix + assert s == "hello" + + s = "hello\n\n" + s.removeSuffix + assert s == "hello\n" + + s = "hello\r" + s.removeSuffix + assert s == "hello" + + s = "hello \n there" + s.removeSuffix + assert s == "hello \n there" + + s = "hello" + s.removeSuffix("llo") + assert s == "he" + s.removeSuffix('e') + assert s == "h" + + s = "hellos" + s.removeSuffix({'s','z'}) + assert s == "hello" + s.removeSuffix({'l','o'}) + assert s == "hell" + + # Contrary to Chomp in other languages + # empty string does not change behaviour + s = "hello\r\n\r\n" + s.removeSuffix("") + assert s == "hello\r\n\r\n" proc main() = testStrip() - testChomp() + testRemoveSuffix() for p in split("/home/a1:xyz:/usr/bin", {':'}): write(stdout, p)