1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

json: assert encoded struct with a sumtype (#11970)

This commit is contained in:
Anton Zavodchikov 2021-09-25 22:29:52 +05:00 committed by GitHub
parent 970768288d
commit 80c15607da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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