Skip to content

Commit

Permalink
fixes #23513, parseutils.nim: parseInt's doc example. (#23561)
Browse files Browse the repository at this point in the history
fixes #23513

Also, the old `runnableExample` is just a copy of `proc
parseInt(openArray[char], var int, int)` variant (in Line 1000).

---------

Co-authored-by: ringabout <[email protected]>
  • Loading branch information
litlighilit and ringabout authored Jun 12, 2024
1 parent 262ff64 commit 3915fdc
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/pure/parseutils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ proc parseBiggestInt*(s: openArray[char], number: var BiggestInt): int {.
var res: BiggestInt
doAssert parseBiggestInt("9223372036854775807", res) == 19
doAssert res == 9223372036854775807
doAssert parseBiggestInt("-2024_05_09", res) == 11
doAssert res == -20240509
var res = BiggestInt(0)
# use 'res' for exception safety (don't write to 'number' in case of an
# overflow exception):
Expand All @@ -474,10 +476,8 @@ proc parseInt*(s: openArray[char], number: var int): int {.
## `ValueError` is raised if the parsed integer is out of the valid range.
runnableExamples:
var res: int
doAssert parseInt("2019", res, 0) == 4
doAssert res == 2019
doAssert parseInt("2019", res, 2) == 2
doAssert res == 19
doAssert parseInt("-2024_05_02", res) == 11
doAssert res == -20240502
var res = BiggestInt(0)
result = parseBiggestInt(s, res)
when sizeof(int) <= 4:
Expand Down Expand Up @@ -992,6 +992,10 @@ proc parseBiggestInt*(s: string, number: var BiggestInt, start = 0): int {.noSid
var res: BiggestInt
doAssert parseBiggestInt("9223372036854775807", res, 0) == 19
doAssert res == 9223372036854775807
doAssert parseBiggestInt("-2024_05_09", res) == 11
doAssert res == -20240509
doAssert parseBiggestInt("-2024_05_02", res, 7) == 4
doAssert res == 502
parseBiggestInt(s.toOpenArray(start, s.high), number)

proc parseInt*(s: string, number: var int, start = 0): int {.noSideEffect, raises: [ValueError].} =
Expand All @@ -1000,10 +1004,10 @@ proc parseInt*(s: string, number: var int, start = 0): int {.noSideEffect, raise
## `ValueError` is raised if the parsed integer is out of the valid range.
runnableExamples:
var res: int
doAssert parseInt("2019", res, 0) == 4
doAssert res == 2019
doAssert parseInt("2019", res, 2) == 2
doAssert res == 19
doAssert parseInt("-2024_05_02", res) == 11
doAssert res == -20240502
doAssert parseInt("-2024_05_02", res, 7) == 4
doAssert res == 502
parseInt(s.toOpenArray(start, s.high), number)


Expand Down

0 comments on commit 3915fdc

Please sign in to comment.