From 4ffd0b3af3fa5b49c5b44071e8f4d3aa56cae92f Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Mon, 8 Apr 2019 15:29:11 +0300 Subject: [PATCH] Add a test for handling missing fields --- tests/test_serialization.nim | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/test_serialization.nim b/tests/test_serialization.nim index ead1e0d..2d70a12 100644 --- a/tests/test_serialization.nim +++ b/tests/test_serialization.nim @@ -62,6 +62,21 @@ suite "toJson tests": } """ + test "handle missing fields": + let json = dedent""" + { + "y": "test", + "distance": 20 + } + """ + + let decoded = Json.decode(json, Simple) + + check: + decoded.x == 0 + decoded.y == "test" + decoded.distance.int == 20 + test "arrays are printed correctly": var x = HoldsArray(data: @[1, 2, 3, 4])