mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 14:00:35 +00:00
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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user