v2 / vlib / v / tests / options / option_ptr_field_test.v
40 lines · 36 sloc · 592 bytes · 9ae8cc357f55ffe21bc856847d9fdb8f202ac5bb
Raw
1module main
2
3@[heap]
4interface IGameObject {
5mut:
6 name string
7 parent ?&IGameObject
8}
9
10@[heap]
11struct GameObject implements IGameObject {
12mut:
13 name string
14 parent ?&IGameObject
15}
16
17struct Ship implements IGameObject {
18 GameObject
19 speed f32
20}
21
22fn test_main() {
23 mut world := &GameObject{
24 name: 'world'
25 }
26 mut ship := &Ship{
27 name: 'ship'
28 parent: world
29 }
30 assert '${ship}' == "&Ship{
31 GameObject: GameObject{
32 name: 'ship'
33 parent: &Option(IGameObject(GameObject{
34 name: 'world'
35 parent: &Option(none)
36 }))
37 }
38 speed: 0.0
39}"
40}
41