| 1 | module main |
| 2 | |
| 3 | #include "@VMODROOT/cstruct.h" |
| 4 | |
| 5 | @[typedef] |
| 6 | struct C.Foo { |
| 7 | a int = 100 |
| 8 | } |
| 9 | |
| 10 | type Foo = C.Foo |
| 11 | |
| 12 | struct GameObject { |
| 13 | mut: |
| 14 | map_a map[string]Foo |
| 15 | map_b map[string]?Foo |
| 16 | b []Foo |
| 17 | c []?Foo |
| 18 | } |
| 19 | |
| 20 | fn 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 |