v2 / vlib / v / tests / structs / embed_struct_field_default_value_test.v
37 lines · 31 sloc · 554 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1struct Papa {
2 fam_name string
3}
4
5pub struct Child {
6 Papa
7pub mut:
8 activity Activity = Fun.roll
9 age u8 = 2
10}
11
12type Activity = Fun | Other
13
14pub enum Fun {
15 run
16 roll
17 jump
18}
19
20pub struct Other {}
21
22// Same struct without embedding just works.
23pub struct Human {
24 fam_name string
25pub mut:
26 activity Activity = Fun.roll
27 age u8 = 2
28}
29
30fn test_embed_struct_field_default_value() {
31 c := Child{}
32 println(c.activity)
33 assert c.activity == Activity(Fun.roll)
34 h := Human{}
35 println(h.activity)
36 assert h.activity == Activity(Fun.roll)
37}
38