Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Jun 6, 2020
1 parent 5885916 commit a38ac86
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/pure/json.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,7 @@ proc toJson*[T](a: T): JsonNode {.since: (1,3,5).} =
elif T is pointer: result = toJson(cast[int](a))
elif T is distinct: result = toJson(a.distinctBase)
elif T is bool: result = %(a)
elif T is Ordinal: result = %(cast[int](a))
elif T is Ordinal: result = %(a.ord)
else: result = %a

when isMainModule:
Expand Down
7 changes: 4 additions & 3 deletions tests/stdlib/tjsonmacro.nim
Original file line number Diff line number Diff line change
Expand Up @@ -652,12 +652,13 @@ block: # toJson, jsonTo
testRoundtrip(cast[pointer](12345)): """12345"""
testRoundtrip(Foo(1.5)): """1.5"""
testRoundtrip({"z": "Z", "y": "Y"}.toOrderedTable): """{"z":"Z","y":"Y"}"""
testRoundtrip({"z": (f1: 'f'), }.toTable): """{"z":{"f1":102}}"""
when not defined(js): # pending https://github.com/nim-lang/Nim/issues/14574
testRoundtrip({"z": (f1: 'f'), }.toTable): """{"z":{"f1":102}}"""
testRoundtrip({"name": "John", "city": "Monaco"}.newStringTable): """{"mode":"modeCaseSensitive","table":{"city":"Monaco","name":"John"}}"""
block: # complex example
let t = {"z": "Z", "y": "Y"}.newStringTable
type A = ref object
a1: string
let a = (1.1, "fo", 'x', @[10,11], [true, false], [t,newStringTable()], [0'u8,3'u8], (foo: 0.5'f32, bar: A(a1: "abc"), bar2: A.default))
let a = (1.1, "fo", 'x', @[10,11], [true, false], [t,newStringTable()], [0'i8,3'i8], -4'i16, (foo: 0.5'f32, bar: A(a1: "abc"), bar2: A.default))
testRoundtrip(a):
"""[1.1,"fo",120,[10,11],[true,false],[{"mode":"modeCaseSensitive","table":{"y":"Y","z":"Z"}},{"mode":"modeCaseSensitive","table":{}}],[0,3],{"foo":0.5,"bar":{"a1":"abc"},"bar2":null}]"""
"""[1.1,"fo",120,[10,11],[true,false],[{"mode":"modeCaseSensitive","table":{"y":"Y","z":"Z"}},{"mode":"modeCaseSensitive","table":{}}],[0,3],-4,{"foo":0.5,"bar":{"a1":"abc"},"bar2":null}]"""

0 comments on commit a38ac86

Please sign in to comment.