Pass json options to hooks (#20638)
* Added tests * Fix expected string * Allow hooks to take an optional parameter that is the current options * Add options to hooks for other generic types * Fix doc links
This commit is contained in:
parent
4578e773ce
commit
69cb671d8d
2 changed files with 38 additions and 14 deletions
|
|
@ -410,6 +410,28 @@ template fn() =
|
|||
doAssert foo.c == 0
|
||||
doAssert foo.c0 == 42
|
||||
|
||||
type
|
||||
InnerEnum = enum
|
||||
A
|
||||
B
|
||||
C
|
||||
InnerObject = object
|
||||
x: string
|
||||
y: InnerEnum
|
||||
|
||||
block testOptionsArePassedWhenDeserialising:
|
||||
let json = parseJson("""{"x": "hello"}""")
|
||||
let inner = json.jsonTo(Option[InnerObject], Joptions(allowMissingKeys: true))
|
||||
doAssert inner.isSome()
|
||||
doAssert inner.get().x == "hello"
|
||||
doAssert inner.get().y == A
|
||||
|
||||
block testOptionsArePassedWhenSerialising:
|
||||
let inner = some InnerObject(x: "hello", y: A)
|
||||
let json = inner.toJson(ToJsonOptions(enumMode: joptEnumSymbol))
|
||||
doAssert $json == """{"x":"hello","y":"A"}"""
|
||||
|
||||
|
||||
when false:
|
||||
## TODO: Implement support for nested variant objects allowing the tests
|
||||
## bellow to pass.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue