jsonutils: fromJson forward opt param fix (#16612)
This commit is contained in:
parent
58b9191354
commit
0d5cab77f6
2 changed files with 18 additions and 4 deletions
|
|
@ -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): """[""]"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue