summary refs log tree commit diff stats
path: root/tests/stdlib/tstrutil.nim
diff options
context:
space:
mode:
authorBo Lingen <lingenbw@gmail.com>2017-10-28 03:47:23 -0500
committerAndreas Rumpf <rumpf_a@web.de>2017-10-28 10:47:23 +0200
commite13513546981167e4d1ee38993b2589e14531fb9 (patch)
tree2e8fe3fe3a6c2a7ab96164bf5331ce99cd8e63b5 /tests/stdlib/tstrutil.nim
parent616db85c615d9cf00a1c3b85e59cf6401fed915b (diff)
downloadNim-e13513546981167e4d1ee38993b2589e14531fb9.tar.gz
add `strutils.removePrefix` proc (#6473)
Diffstat (limited to 'tests/stdlib/tstrutil.nim')
-rw-r--r--tests/stdlib/tstrutil.nim62
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/stdlib/tstrutil.nim b/tests/stdlib/tstrutil.nim
index 57968df13..2fb0c371f 100644
--- a/tests/stdlib/tstrutil.nim
+++ b/tests/stdlib/tstrutil.nim
@@ -49,9 +49,71 @@ proc testRemoveSuffix =
   s.removeSuffix("")
   assert s == "hello\r\n\r\n"
 
+proc testRemovePrefix =
+  var s = "\n\rhello"
+  s.removePrefix
+  assert s == "hello"
+  s.removePrefix
+  assert s == "hello"
+
+  s = "\n\nhello"
+  s.removePrefix
+  assert s == "hello"
+
+  s = "\rhello"
+  s.removePrefix
+  assert s == "hello"
+
+  s = "hello \n there"
+  s.removePrefix
+  assert s == "hello \n there"
+
+  s = "hello"
+  s.removePrefix("hel")
+  assert s == "lo"
+  s.removePrefix('l')
+  assert s == "o"
+
+  s = "hellos"
+  s.removePrefix({'h','e'})
+  assert s == "llos"
+  s.removePrefix({'l','o'})
+  assert s == "s"
+
+  s = "aeiou"
+  s.removePrefix("")
+  assert s == "aeiou"
+
+  s = ""
+  s.removePrefix("")
+  assert s == ""
+
+  s = "  "
+  s.removePrefix
+  assert s == "  "
+
+  s = "  "
+  s.removePrefix("")
+  assert s == "  "
+
+  s = "    "
+  s.removePrefix(" ")
+  assert s == "   "
+
+  s = "    "
+  s.removePrefix(' ')
+  assert s == ""
+
+  # Contrary to Chomp in other languages
+  # empty string does not change behaviour
+  s = "\r\n\r\nhello"
+  s.removePrefix("")
+  assert s == "\r\n\r\nhello"
+
 proc main() =
   testStrip()
   testRemoveSuffix()
+  testRemovePrefix()
   for p in split("/home/a1:xyz:/usr/bin", {':'}):
     write(stdout, p)