| 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 | struct Point { |
| 8 | x int |
| 9 | y int |
| 10 | z int |
| 11 | } |
| 12 | |
| 13 | fn (p Point) draw() string { |
| 14 | return 'Point(${p.x},${p.y})' |
| 15 | } |
| 16 | |
| 17 | fn to_string(d Drawer) string { |
| 18 | return d.draw() |
| 19 | } |
| 20 | |
| 21 | interface Drawer { |
| 22 | draw() string |
| 23 | } |
| 24 | |
| 25 | fn test_calling_to_string() { |
| 26 | p := Point{ |
| 27 | x: 2 |
| 28 | y: 3 |
| 29 | } |
| 30 | res := to_string(p) |
| 31 | println(res) |
| 32 | assert res == 'Point(2,3)' |
| 33 | } |
| 34 | |