jsonutils: fromJson forward opt param fix (#16612)

This commit is contained in:
inv2004 2021-01-06 20:42:49 +03:00 • committed by GitHub
commit 0d5cab77f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 4 deletions

View file

@ -118,6 +118,20 @@ template fn() =
testRoundtrip(Foo[int](t1: false, z2: 7)): """{"t1":false,"z2":7}"""
# pending https://github.com/nim-lang/Nim/issues/14698, test with `type Foo[T] = ref object`
block: # bug: pass opt params in fromJson
type Foo = object
a: int
b: string
c: float
var f: seq[Foo]
try:
fromJson(f, parseJson """[{"b": "bbb"}]""")
doAssert false
except ValueError:
doAssert true
fromJson(f, parseJson """[{"b": "bbb"}]""", Joptions(allowExtraKeys: true, allowMissingKeys: true))
doAssert f == @[Foo(a: 0, b: "bbb", c: 0.0)]
block testHashSet:
testRoundtrip(HashSet[string]()): "[]"
testRoundtrip([""].toHashSet): """[""]"""