jsonutils.jsonTo: support opt (#16739)

This commit is contained in:
Timothee Cour 2021-01-17 02:37:06 -08:00 • committed by GitHub
commit 6c07b0a1f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 4 deletions

View file

@ -137,6 +137,9 @@ template fn() =
var b: Bar
fromJson(b, parseJson """{"foo": {"b": "bbb"}}""", Joptions(allowExtraKeys: true, allowMissingKeys: true))
doAssert b == Bar(foo: Foo(a: 0, b: "bbb", c: 0.0))
block: # jsonTo with `opt`
let b2 = """{"foo": {"b": "bbb"}}""".parseJson.jsonTo(Bar, Joptions(allowExtraKeys: true, allowMissingKeys: true))
doAssert b2 == Bar(foo: Foo(a: 0, b: "bbb", c: 0.0))
block testHashSet:
testRoundtrip(HashSet[string]()): "[]"