Test case for the serializedFieldName pragma

The pragma was added in https://github.com/status-im/nim-serialization/pull/25
This commit is contained in:
Zahary Karadjov 2020-05-20 13:53:21 +03:00
parent 2f5e71b25f
commit aa51f6fed1
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
1 changed files with 6 additions and 5 deletions

View File

@ -18,9 +18,10 @@ type
Invalid = object
distance: Mile
Reserved = object
HasUnusualFieldNames = object
# Using Nim reserved keyword
`type`: string
renamedField {.serializedFieldName("renamed").}: string
MyKind = enum
Apple
@ -125,11 +126,11 @@ suite "toJson tests":
expect JsonReaderError:
discard Json.decode(jsonValue, uint64, mode = Portable)
test "Using Nim reserved keyword `type`":
let r = Reserved(`type`: "uint8")
test "Unusual field names":
let r = HasUnusualFieldNames(`type`: "uint8", renamedField: "field")
check:
r.toJSON == """{"type":"uint8"}"""
r == Json.decode("""{"type":"uint8"}""", Reserved)
r.toJSON == """{"type":"uint8","renamed":"field"}"""
r == Json.decode("""{"type":"uint8", "renamed":"field"}""", HasUnusualFieldNames)
test "Option types":
let