2022-04-13 18:06:28 +03:00
|
|
|
import json
|
|
|
|
|
2022-04-14 15:36:24 +03:00
|
|
|
type Test = []bool | []int | []string | string
|
2022-04-13 18:06:28 +03:00
|
|
|
|
|
|
|
struct Some {
|
|
|
|
t Test
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_json_decode_with_sumtype() ? {
|
2022-05-13 06:56:21 +03:00
|
|
|
v1 := json.decode(Some, '{"t": ["string", "string2"]}')?
|
2022-04-14 15:36:24 +03:00
|
|
|
println(v1)
|
|
|
|
assert v1.t == Test(['string', 'string2'])
|
|
|
|
|
2022-05-13 06:56:21 +03:00
|
|
|
v2 := json.decode(Some, '{"t": [11, 22]}')?
|
2022-04-14 15:36:24 +03:00
|
|
|
println(v2)
|
|
|
|
assert v2.t == Test([11, 22])
|
|
|
|
|
2022-05-13 06:56:21 +03:00
|
|
|
v3 := json.decode(Some, '{"t": [true, false]}')?
|
2022-04-14 15:36:24 +03:00
|
|
|
println(v3)
|
|
|
|
assert v3.t == Test([true, false])
|
2022-04-13 18:06:28 +03:00
|
|
|
}
|