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