mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-18 21:40:32 +00:00
Fix wrong result of countLines() (#6371)
This commit is contained in:
committed by
Andreas Rumpf
parent
bca3bedc47
commit
94e336fe85
@@ -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':
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user