v2 / vlib / v / tests / options / option_selector_nested_unwrapped_test.v
44 lines · 39 sloc · 732 bytes · d1d47d6b8fd3c443eb9d84c17833f6dfd74bf703
Raw
1module main
2
3interface IGameObject {
4mut:
5 name string
6 parent ?&IGameObject
7 children []&IGameObject
8 add_child(mut o IGameObject)
9 advance()
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 (mut gameobject GameObject) advance() {
26 if gameobject.parent != none {
27 eprintln('parent: ${gameobject.parent.name} ')
28 }
29 for mut child in gameobject.children {
30 child.advance()
31 }
32}
33
34fn test_main() {
35 mut v1 := &GameObject{
36 name: 'v1'
37 }
38 mut v2 := &GameObject{
39 name: 'v2'
40 }
41 v1.add_child(mut v2)
42 v1.advance()
43 assert true
44}
45