v2 / vlib / v / tests / options / nested_option_struct_init_test.v
30 lines · 25 sloc · 376 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1struct Data {
2 a ?int
3 b ?int = 1
4}
5
6struct Data2 {
7 d Data
8}
9
10fn test_nested_option_struct_init() {
11 d2 := Data2{}
12 println(d2)
13 assert d2.d.a == none
14 assert d2.d.b != none
15 assert d2.d.b? == 1
16}
17
18struct AA {
19 bb ?BB // defaults to none
20}
21
22struct BB {
23 x string @[required]
24}
25
26fn test_nested_option_struct_with_attr_init() {
27 aa := AA{}
28 println(aa)
29 assert aa.bb == none
30}
31