v2 / vlib / v / tests / interfaces / interface_embedding_recursive_test.v
78 lines · 67 sloc · 1.09 KB · 6488041a749df9762348d019c4223908c476f2e2
Raw
1// This test orders the interface definitions intentionally
2// in such a way that interface `Re` is first, and `Fe` is
3// last. The goal is testing that the embedding expansion
4// works independently from the source order, and that both
5// can be checked/compiled/used at the same time.
6interface Re {
7 I1
8 I2
9 m_ie() int
10}
11
12interface I1 {
13 I0
14 m1() int
15}
16
17interface I2 {
18 I0
19 m2() int
20}
21
22interface I0 {
23 m0() int
24}
25
26interface Fe {
27 I1
28 I2
29 m_ie() int
30}
31
32struct StructIE {
33 x int = 456
34}
35
36fn (s StructIE) m0() int {
37 println(@METHOD)
38 return 0
39}
40
41fn (s StructIE) m1() int {
42 println(@METHOD)
43 return 1
44}
45
46fn (s StructIE) m2() int {
47 println(@METHOD)
48 return 2
49}
50
51fn (s StructIE) m_ie() int {
52 println(@METHOD)
53 return 3
54}
55
56fn test_ie_recursive_forward() {
57 i := Fe(StructIE{})
58 eprintln(i)
59 assert 0 == i.m0()
60 assert 1 == i.m1()
61 assert 2 == i.m2()
62 assert 3 == i.m_ie()
63 if i is StructIE {
64 assert i.x == 456
65 }
66}
67
68fn test_ie_recursive_backward() {
69 i := Re(StructIE{})
70 eprintln(i)
71 assert 0 == i.m0()
72 assert 1 == i.m1()
73 assert 2 == i.m2()
74 assert 3 == i.m_ie()
75 if i is StructIE {
76 assert i.x == 456
77 }
78}
79