Merge pull request #3131 from zachaysan/devel

Create chomp proc and tests
This commit is contained in:
Dominik Picheta
2015-08-13 22:31:30 +01:00
2 changed files with 101 additions and 6 deletions

View File

@@ -10,12 +10,52 @@ import
proc testStrip() =
write(stdout, strip(" ha "))
proc main() =
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()
testRemoveSuffix()
for p in split("/home/a1:xyz:/usr/bin", {':'}):
write(stdout, p)
proc testDelete =
proc testDelete =
var s = "0123456789ABCDEFGH"
delete(s, 4, 5)
assert s == "01236789ABCDEFGH"
@@ -24,8 +64,8 @@ proc testDelete =
delete(s, 0, 0)
assert s == "1236789ABCDEFG"
testDelete()
testDelete()
assert(insertSep($1000_000) == "1_000_000")
assert(insertSep($232) == "232")
assert(insertSep($12345, ',') == "12,345")