Fix wrong result of countLines() (#6371)

This commit is contained in:
Simon Krauter
2017-09-15 10:45:22 +02:00
committed by Andreas Rumpf
parent bca3bedc47
commit 94e336fe85
2 changed files with 14 additions and 1 deletions

View File

@@ -776,7 +776,8 @@ proc countLines*(s: string): int {.noSideEffect,
##
## In this context, a line is any string seperated by a newline combination.
## A line can be an empty string.
var i = 1
result = 1
var i = 0
while i < s.len:
case s[i]
of '\c':

View File

@@ -89,9 +89,21 @@ proc testRFind =
assert "0123456789ABCDEFGAH".rfind({'A'..'C'}, 13) == 12
assert "0123456789ABCDEFGAH".rfind({'G'..'H'}, 13) == -1
proc testCountLines =
proc assertCountLines(s: string) = assert s.countLines == s.splitLines.len
assertCountLines("")
assertCountLines("\n")
assertCountLines("\n\n")
assertCountLines("abc")
assertCountLines("abc\n123")
assertCountLines("abc\n123\n")
assertCountLines("\nabc\n123")
assertCountLines("\nabc\n123\n")
testDelete()
testFind()
testRFind()
testCountLines()
assert(insertSep($1000_000) == "1_000_000")
assert(insertSep($232) == "232")