Fix wrong result of countLines() (#6371)
This commit is contained in:
parent
bca3bedc47
commit
94e336fe85
2 changed files with 14 additions and 1 deletions
|
|
@ -776,7 +776,8 @@ proc countLines*(s: string): int {.noSideEffect,
|
||||||
##
|
##
|
||||||
## In this context, a line is any string seperated by a newline combination.
|
## In this context, a line is any string seperated by a newline combination.
|
||||||
## A line can be an empty string.
|
## A line can be an empty string.
|
||||||
var i = 1
|
result = 1
|
||||||
|
var i = 0
|
||||||
while i < s.len:
|
while i < s.len:
|
||||||
case s[i]
|
case s[i]
|
||||||
of '\c':
|
of '\c':
|
||||||
|
|
|
||||||
|
|
@ -89,9 +89,21 @@ proc testRFind =
|
||||||
assert "0123456789ABCDEFGAH".rfind({'A'..'C'}, 13) == 12
|
assert "0123456789ABCDEFGAH".rfind({'A'..'C'}, 13) == 12
|
||||||
assert "0123456789ABCDEFGAH".rfind({'G'..'H'}, 13) == -1
|
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()
|
testDelete()
|
||||||
testFind()
|
testFind()
|
||||||
testRFind()
|
testRFind()
|
||||||
|
testCountLines()
|
||||||
|
|
||||||
assert(insertSep($1000_000) == "1_000_000")
|
assert(insertSep($1000_000) == "1_000_000")
|
||||||
assert(insertSep($232) == "232")
|
assert(insertSep($232) == "232")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue