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

v.gen.c: use unmangled variant name for encoding sumtype values in json (#11554)

This commit is contained in:
Anton Zavodchikov
2021-09-20 23:19:16 +05:00
committed by GitHub
parent 077c55d0c8
commit d51f8ed878
2 changed files with 20 additions and 15 deletions

View File

@@ -37,7 +37,7 @@ fn test_decode_top_level_array() {
assert x[1].age == 31
}
struct Usr {
struct Human {
name string
}
@@ -50,7 +50,7 @@ enum Animal {
cat
}
type Entity = Animal | Item | Usr | string | time.Time
type Entity = Animal | Human | Item | string | time.Time
struct SomeGame {
title string
@@ -61,7 +61,7 @@ struct SomeGame {
fn test_encode_decode_sumtype() ? {
game := SomeGame{
title: 'Super Mega Game'
player: Usr{'PoopLord69'}
player: Human{'Monke'}
other: [
Entity(Item{'Pen'}),
Item{'Cookie'},
@@ -70,10 +70,15 @@ fn test_encode_decode_sumtype() ? {
time.now(),
]
}
eprintln('Game: $game')
enc := json.encode(game)
eprintln('Encoded Game: $enc')
dec := json.decode(SomeGame, enc) ?
eprintln('Decoded Game: $dec')
assert game.title == dec.title
assert game.player == dec.player
assert (game.other[4] as time.Time).unix_time() == (dec.other[4] as time.Time).unix_time()