fix #17383: json.%,to and jsonutils.formJson,toJson now works with uint|uint64 (#17389) [backport:1.2]
* fix #17383: json.%,to and jsonutils.formJson,toJson now works with uint|uint64 * fixup * fix for js
This commit is contained in:
parent
cfe2f126e5
commit
895a40d1ac
4 changed files with 56 additions and 6 deletions
|
|
@ -7,7 +7,14 @@ discard """
|
|||
Note: Macro tests are in tests/stdlib/tjsonmacro.nim
|
||||
]#
|
||||
|
||||
import std/[json,parsejson,strutils,streams]
|
||||
import std/[json,parsejson,strutils]
|
||||
when not defined(js):
|
||||
import std/streams
|
||||
|
||||
proc testRoundtrip[T](t: T, expected: string) =
|
||||
let j = %t
|
||||
doAssert $j == expected, $j
|
||||
doAssert %(j.to(T)) == j
|
||||
|
||||
let testJson = parseJson"""{ "a": [1, 2, 3, 4], "b": "asd", "c": "\ud83c\udf83", "d": "\u00E6"}"""
|
||||
# nil passthrough
|
||||
|
|
@ -281,3 +288,15 @@ let jsonNode = %*mynode
|
|||
doAssert $jsonNode == """{"kind":"P","pChildren":[{"kind":"Text","textStr":"mychild"},{"kind":"Br"}]}"""
|
||||
doAssert $jsonNode.to(ContentNode) == """(kind: P, pChildren: @[(kind: Text, textStr: "mychild"), (kind: Br)])"""
|
||||
|
||||
block: # bug #17383
|
||||
testRoundtrip(int32.high): "2147483647"
|
||||
testRoundtrip(uint32.high): "4294967295"
|
||||
when int.sizeof == 4:
|
||||
testRoundtrip(int.high): "2147483647"
|
||||
testRoundtrip(uint.high): "4294967295"
|
||||
else:
|
||||
testRoundtrip(int.high): "9223372036854775807"
|
||||
testRoundtrip(uint.high): "18446744073709551615"
|
||||
when not defined(js):
|
||||
testRoundtrip(int64.high): "9223372036854775807"
|
||||
testRoundtrip(uint64.high): "18446744073709551615"
|
||||
|
|
|
|||
|
|
@ -67,6 +67,21 @@ template fn() =
|
|||
doAssert b2.ord == 1 # explains the `1`
|
||||
testRoundtrip(a): """[1,2,3]"""
|
||||
|
||||
block: # bug #17383
|
||||
block:
|
||||
let a = (int32.high, uint32.high)
|
||||
testRoundtrip(a): "[2147483647,4294967295]"
|
||||
when not defined(js):
|
||||
block:
|
||||
let a = (int64.high, uint64.high)
|
||||
testRoundtrip(a): "[9223372036854775807,18446744073709551615]"
|
||||
block:
|
||||
let a = (int.high, uint.high)
|
||||
when int.sizeof == 4:
|
||||
testRoundtrip(a): "[2147483647,4294967295]"
|
||||
else:
|
||||
testRoundtrip(a): "[9223372036854775807,18446744073709551615]"
|
||||
|
||||
block: # case object
|
||||
type Foo = object
|
||||
x0: float
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue