v / vlib / json / tests / json_decode_option_alias_test.v
20 lines · 16 sloc · 363 bytes · af87a302faf517d41176e84ce8d7adc2817c3ac2
Raw
1import json
2
3struct Empty {}
4
5struct SomeStruct {
6 random_field_a ?string
7 random_field_b ?string
8 empty_field ?Empty
9}
10
11type Alias = SomeStruct
12
13fn test_main() {
14 data := json.decode(Alias, '{"empty_field":{}}')!
15 assert data.str() == 'Alias(SomeStruct{
16 random_field_a: Option(none)
17 random_field_b: Option(none)
18 empty_field: Option(Empty{})
19})'
20}
21