vxx2 / vlib / v / tests / interfaces / interface_method_using_struct_embed_test.v
32 lines · 25 sloc · 641 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1pub interface IObject {
2mut:
3 do_stuff()
4 do_something_with_int(int)
5 do_something_with_string(string)
6}
7
8pub struct BaseObject {
9mut:
10 some_attr int
11}
12
13pub fn (mut base BaseObject) do_stuff() {}
14
15pub fn (mut base BaseObject) do_something_with_int(n int) {}
16
17pub fn (mut base BaseObject) do_something_with_string(s string) {}
18
19pub fn (mut base BaseObject) method_thats_available_to_all_object() {}
20
21pub struct GameObject {
22 BaseObject
23pub mut:
24 some_attr_for_game int
25}
26
27fn test_interface_method_using_struct_embed() {
28 mut common_object := []IObject{}
29 common_object << GameObject{}
30 println(common_object)
31 assert common_object.len == 1
32}
33