1 | import json |
2 | |
3 | type Test = []bool | []int | []string | string |
4 | |
5 | struct Some { |
6 | t Test |
7 | } |
8 | |
9 | fn test_json_decode_with_sumtype() { |
10 | v1 := json.decode(Some, '{"t": ["string", "string2"]}')! |
11 | println(v1) |
12 | assert v1.t == Test(['string', 'string2']) |
13 | |
14 | v2 := json.decode(Some, '{"t": [11, 22]}')! |
15 | println(v2) |
16 | assert v2.t == Test([11, 22]) |
17 | |
18 | v3 := json.decode(Some, '{"t": [true, false]}')! |
19 | println(v3) |
20 | assert v3.t == Test([true, false]) |
21 | } |