v2 / vlib / v / tests / interfaces / interface_embedding_test.v
58 lines · 52 sloc · 821 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1interface WalkerTalker {
2 // Abc
3 Walker // adsas
4 // zxczxc
5 Talker // xyzdef
6 // asdasdas
7 nspeeches int
8}
9
10interface Talker {
11 nspeeches int
12mut:
13 talk(msg string)
14}
15
16interface Walker {
17 nsteps int
18mut:
19 walk(newx int, newy int)
20}
21
22struct Abc {
23mut:
24 x int
25 y int
26 phrases []string
27 nsteps int = 1000
28 nspeeches int = 1000
29}
30
31fn (mut s Abc) talk(msg string) {
32 s.phrases << msg
33 s.nspeeches++
34}
35
36fn (mut s Abc) walk(x int, y int) {
37 s.x = x
38 s.y = y
39 s.nsteps++
40}
41
42fn test_walker_talker() {
43 mut wt := WalkerTalker(Abc{
44 x: 1
45 y: 1
46 phrases: ['hi']
47 })
48 wt.talk('my name is Wally')
49 wt.walk(100, 100)
50 if mut wt is Abc {
51 dump(wt)
52 assert wt.x == 100
53 assert wt.y == 100
54 assert wt.phrases.last().ends_with('Wally')
55 assert wt.nspeeches == 1001
56 assert wt.nsteps == 1001
57 }
58}
59