json: assert encoded struct with a sumtype (#11970)
parent
970768288d
commit
80c15607da
|
@ -59,6 +59,7 @@ struct SomeGame {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_encode_decode_sumtype() ? {
|
fn test_encode_decode_sumtype() ? {
|
||||||
|
t := time.now()
|
||||||
game := SomeGame{
|
game := SomeGame{
|
||||||
title: 'Super Mega Game'
|
title: 'Super Mega Game'
|
||||||
player: Human{'Monke'}
|
player: Human{'Monke'}
|
||||||
|
@ -67,7 +68,7 @@ fn test_encode_decode_sumtype() ? {
|
||||||
Item{'Cookie'},
|
Item{'Cookie'},
|
||||||
Animal.cat,
|
Animal.cat,
|
||||||
'Stool',
|
'Stool',
|
||||||
time.now(),
|
t,
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
eprintln('Game: $game')
|
eprintln('Game: $game')
|
||||||
|
@ -75,8 +76,9 @@ fn test_encode_decode_sumtype() ? {
|
||||||
enc := json.encode(game)
|
enc := json.encode(game)
|
||||||
eprintln('Encoded Game: $enc')
|
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')
|
eprintln('Decoded Game: $dec')
|
||||||
|
|
||||||
assert game.title == dec.title
|
assert game.title == dec.title
|
||||||
|
|
Loading…
Reference in New Issue