summary refs log tree commit diff stats
path: root/tests/stdlib/tstrutil.nim
diff options
context:
space:
mode:
authorZach Aysan <zachaysan@gmail.com>2015-07-21 15:04:10 -0400
committerZach Aysan <zachaysan@gmail.com>2015-07-21 15:04:10 -0400
commit94149f7a48e1fc2730769ee181bbd09942051c9b (patch)
treea63fec06cd36e712032e508a5cb0c95eab0cdd0a /tests/stdlib/tstrutil.nim
parentd28862422be912b5f3e0cbcaf05f3712376624af (diff)
downloadNim-94149f7a48e1fc2730769ee181bbd09942051c9b.tar.gz
Update tests to proposed changes
Diffstat (limited to 'tests/stdlib/tstrutil.nim')
-rw-r--r--tests/stdlib/tstrutil.nim55
1 files 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)