From 80c15607da14e8d77299d17c4d9f1212f1c30737 Mon Sep 17 00:00:00 2001 From: Anton Zavodchikov Date: Sat, 25 Sep 2021 22:29:52 +0500 Subject: [PATCH] json: assert encoded struct with a sumtype (#11970) --- vlib/json/json_test.v | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/vlib/json/json_test.v b/vlib/json/json_test.v index 39444c0d67..75407d8b04 100644 --- a/vlib/json/json_test.v +++ b/vlib/json/json_test.v @@ -59,6 +59,7 @@ struct SomeGame { } fn test_encode_decode_sumtype() ? { + t := time.now() game := SomeGame{ title: 'Super Mega Game' player: Human{'Monke'} @@ -67,7 +68,7 @@ fn test_encode_decode_sumtype() ? { Item{'Cookie'}, Animal.cat, 'Stool', - time.now(), + t, ] } eprintln('Game: $game') @@ -75,8 +76,9 @@ fn test_encode_decode_sumtype() ? { enc := json.encode(game) eprintln('Encoded Game: $enc') - dec := json.decode(SomeGame, enc) ? + assert enc == '{"title":"Super Mega Game","player":{"name":"Monke","_type":"Human"},"other":[{"tag":"Pen","_type":"Item"},{"tag":"Cookie","_type":"Item"},1,"Stool",{"_type":"Time","value":$t.unix_time()}]}' + dec := json.decode(SomeGame, enc) ? eprintln('Decoded Game: $dec') assert game.title == dec.title