v2 / vlib / x / json2 / tests / decode_option_test.v
21 lines · 18 sloc · 265 bytes · 2d33a7f2819dd5fc1f4aa3b3ca0bcc660810d7af
Raw
1import x.json2
2
3struct F1 {
4 f ?struct {
5 a int
6 }
7}
8
9fn test_main() {
10 j1 := json2.decode[F1]('{"f":{"a":1}}')!
11 assert '${j1}' == 'F1{
12 f: Option(struct {
13 a: 1
14 })
15}'
16
17 j2 := json2.decode[F1]('{}')!
18 assert '${j2}' == 'F1{
19 f: Option(none)
20}'
21}
22