| 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. |
| 7 | interface Drawable { |
| 8 | draw() string |
| 9 | } |
| 10 | |
| 11 | struct Point { |
| 12 | x int |
| 13 | y int |
| 14 | } |
| 15 | |
| 16 | fn (p Point) draw() string { |
| 17 | return 'Point(${p.x},${p.y})' |
| 18 | } |
| 19 | |
| 20 | // Note: this helper function forced the compiler to generate an |
| 21 | // interface dispatch ast. Now, it should not be needed anymore, |
| 22 | // but it is better to test it too, to prevent future interface regressions. |
| 23 | fn (x Point) tointerface() Drawable { |
| 24 | return x |
| 25 | } |
| 26 | |
| 27 | fn to_string(d Drawable) string { |
| 28 | return d.draw() |
| 29 | } |
| 30 | |
| 31 | fn test_p_draw_can_be_called() { |
| 32 | p := Point{ |
| 33 | x: 2 |
| 34 | y: 3 |
| 35 | } |
| 36 | res := p.draw() |
| 37 | assert res == 'Point(2,3)' |
| 38 | } |
| 39 | |