Skip to content

Commit

Permalink
fix stylecheck for BiggestUInt (#99)
Browse files Browse the repository at this point in the history
* fix reader_desc.nim

* fix test_serialization.nim

* workaround segfault on C++ related to unittest2

* link to nim issue as comment
  • Loading branch information
metagn authored Oct 10, 2024
1 parent ab1a061 commit 9110cc8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions json_serialization/reader_desc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type

IntOverflowError* = object of JsonReaderError
isNegative: bool
absIntVal: BiggestUint
absIntVal: BiggestUInt

Json.setReader JsonReader

Expand Down Expand Up @@ -129,15 +129,15 @@ template raiseUnexpectedValue*(r: JsonReader, msg: string) =
raiseUnexpectedValue(r.lex, msg)

func raiseIntOverflow*(
lex: JsonLexer, absIntVal: BiggestUint, isNegative: bool)
lex: JsonLexer, absIntVal: BiggestUInt, isNegative: bool)
{.noreturn, raises: [JsonReaderError].} =
var ex = new IntOverflowError
ex.assignLineNumber(lex)
ex.absIntVal = absIntVal
ex.isNegative = isNegative
raise ex

template raiseIntOverflow*(r: JsonReader, absIntVal: BiggestUint, isNegative: bool) =
template raiseIntOverflow*(r: JsonReader, absIntVal: BiggestUInt, isNegative: bool) =
raiseIntOverflow(r.lex, absIntVal, isNegative)

func raiseUnexpectedField*(
Expand Down
6 changes: 4 additions & 2 deletions tests/test_reader.nim
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ suite "JsonReader basic test":
test "readValue":
try:
var r = toReader jsonText3
var val: MasterReader
r.readValue(val)
var valOrig: MasterReader
r.readValue(valOrig)
# workaround for https://github.com/nim-lang/Nim/issues/24274
let val = valOrig
check:
val.one == JsonString("[1,true,null]")
val.two.num == 123
Expand Down
6 changes: 3 additions & 3 deletions tests/test_serialization.nim
Original file line number Diff line number Diff line change
Expand Up @@ -678,14 +678,14 @@ suite "toJson tests":
"""

test "max unsigned value":
var uintVal = not BiggestUint(0)
var uintVal = not BiggestUInt(0)
let jsonValue = Json.encode(uintVal)
check:
jsonValue == "18446744073709551615"
Json.decode(jsonValue, BiggestUint) == uintVal
Json.decode(jsonValue, BiggestUInt) == uintVal

expect JsonReaderError:
discard Json.decode(jsonValue, BiggestUint, flags = {JsonReaderFlag.portableInt})
discard Json.decode(jsonValue, BiggestUInt, flags = {JsonReaderFlag.portableInt})

test "max signed value":
let intVal = BiggestInt.high
Expand Down

0 comments on commit 9110cc8

Please sign in to comment.