v2 / vlib / v / tests / options / option_ptr_unwrap_selector_test.v
39 lines · 35 sloc · 629 bytes · 23c3af8b4dcb6d444aa8013dd16daa548f541fa8
Raw
1module main
2
3@[heap]
4interface IGameObject {
5mut:
6 name string
7 parent ?&IGameObject
8 children []&IGameObject
9 add_child(mut o IGameObject)
10}
11
12@[heap]
13struct GameObject implements IGameObject {
14mut:
15 name string
16 parent ?&IGameObject
17 children []&IGameObject
18}
19
20fn (mut gameobject GameObject) add_child(mut o IGameObject) {
21 o.parent = gameobject
22 gameobject.children << o
23}
24
25fn test_main() {
26 mut v1 := &GameObject{
27 name: 'v1'
28 }
29 mut v2 := &GameObject{
30 name: 'v2'
31 }
32 v1.add_child(mut v2)
33 for child in v1.children {
34 if child.parent != none {
35 eprintln('parent: ${child.parent.name}')
36 }
37 }
38 assert true
39}
40