add strutils.removePrefix proc (#6473)
This commit is contained in:
parent
616db85c61
commit
e135135469
2 changed files with 100 additions and 2 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue