v2 / vlib / v / tests / c_structs / cstruct_arr_map_test.c.v
46 lines · 40 sloc · 595 bytes · cf2ccbc22d205d898de76ed3fea7aa188571f770
Raw
1module main
2
3#include "@VMODROOT/cstruct.h"
4
5@[typedef]
6struct C.Foo {
7 a int = 100
8}
9
10type Foo = C.Foo
11
12struct GameObject {
13mut:
14 map_a map[string]Foo
15 map_b map[string]?Foo
16 b []Foo
17 c []?Foo
18}
19
20fn test_main() {
21 mut g := GameObject{}
22 g.map_a['a'] = Foo{}
23 g.map_b['a'] = ?Foo{
24 a: 123
25 }
26 g.map_b['aa'] = ?Foo{}
27 g.b << Foo{}
28 g.c << ?Foo{
29 a: 123
30 }
31 g.c << ?Foo{}
32 println(g)
33 dump(g)
34 assert g.map_a.len == 1
35 assert g.map_b.len == 2
36 assert g.b.len == 1
37 assert g.c.len == 2
38 assert g.c[0] != none
39 assert g.c[1] == none
40
41 t := ?Foo{
42 a: 123
43 }
44 dump(t)
45 assert t?.a == 123
46}
47