Add tests for chomp
This commit is contained in:
parent
a291f2c271
commit
d28862422b
1 changed files with 21 additions and 4 deletions
|
|
@ -10,12 +10,29 @@ import
|
||||||
proc testStrip() =
|
proc testStrip() =
|
||||||
write(stdout, strip(" ha "))
|
write(stdout, strip(" ha "))
|
||||||
|
|
||||||
proc main() =
|
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 main() =
|
||||||
testStrip()
|
testStrip()
|
||||||
|
testChomp()
|
||||||
for p in split("/home/a1:xyz:/usr/bin", {':'}):
|
for p in split("/home/a1:xyz:/usr/bin", {':'}):
|
||||||
write(stdout, p)
|
write(stdout, p)
|
||||||
|
|
||||||
proc testDelete =
|
proc testDelete =
|
||||||
var s = "0123456789ABCDEFGH"
|
var s = "0123456789ABCDEFGH"
|
||||||
delete(s, 4, 5)
|
delete(s, 4, 5)
|
||||||
assert s == "01236789ABCDEFGH"
|
assert s == "01236789ABCDEFGH"
|
||||||
|
|
@ -24,8 +41,8 @@ proc testDelete =
|
||||||
delete(s, 0, 0)
|
delete(s, 0, 0)
|
||||||
assert s == "1236789ABCDEFG"
|
assert s == "1236789ABCDEFG"
|
||||||
|
|
||||||
testDelete()
|
testDelete()
|
||||||
|
|
||||||
assert(insertSep($1000_000) == "1_000_000")
|
assert(insertSep($1000_000) == "1_000_000")
|
||||||
assert(insertSep($232) == "232")
|
assert(insertSep($232) == "232")
|
||||||
assert(insertSep($12345, ',') == "12,345")
|
assert(insertSep($12345, ',') == "12,345")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue