mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-20 22:35:24 +00:00
Merge pull request #3131 from zachaysan/devel
Create chomp proc and tests
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user