summary refs log tree commit diff stats
path: root/tests/stdlib/tjsonutils.nim
diff options
context:
space:
mode:
Diffstat (limited to 'tests/stdlib/tjsonutils.nim')
-rw-r--r--tests/stdlib/tjsonutils.nim22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/stdlib/tjsonutils.nim b/tests/stdlib/tjsonutils.nim
index 54cb69560..12a4b20eb 100644
--- a/tests/stdlib/tjsonutils.nim
+++ b/tests/stdlib/tjsonutils.nim
@@ -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.