v2 / vlib / v / tests / interfaces / interface_edge_cases / i8_test.v
31 lines · 27 sloc · 712 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.
7interface Drawable {
8 draw() string
9}
10
11struct Point {
12 x int
13 y int
14}
15
16fn (p Point) draw() string {
17 return 'Point(${p.x},${p.y})'
18}
19
20fn to_string(d Drawable) string {
21 return d.draw()
22}
23
24fn test_p_draw_can_be_called() {
25 p := Point{
26 x: 2
27 y: 3
28 }
29 res := p.draw()
30 assert res == 'Point(2,3)'
31}
32