v2 / vlib / v / tests / interfaces / interface_edge_cases / i2_test.v
34 lines · 30 sloc · 739 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1// The series of i?_test.v files, do test different edge cases for
2// interface table generation. The differences may seem very minor
3// (placement of the interface declaration, whether or not there are
4// helper methods, etc), but PLEASE do NOT be tempted to merge them in
5// a single _test.v file. Debugging interface code generation issues
6// is *much easier* when the _test.v files are very short and focused.
7struct Point {
8 x i8
9 y i8
10 z i8
11}
12
13fn (p Point) draw() string {
14 return 'Point(${p.x},${p.y})'
15}
16
17fn to_string(d Drawer) string {
18 x := d.draw()
19 println(x)
20 return x
21}
22
23interface Drawer {
24 draw() string
25}
26
27fn test_to_string_can_be_called() {
28 p := Point{
29 x: 2
30 y: 3
31 }
32 res := to_string(p)
33 assert res == 'Point(2,3)'
34}
35