| 1 | interface Str { |
| 2 | str() string |
| 3 | } |
| 4 | |
| 5 | struct St {} |
| 6 | |
| 7 | fn (s St) str() string { |
| 8 | return 's' |
| 9 | } |
| 10 | |
| 11 | fn printer(s Str) string { |
| 12 | println(s) |
| 13 | return '${s}' |
| 14 | } |
| 15 | |
| 16 | fn test_interface_str_method() { |
| 17 | s := St{} |
| 18 | ret := printer(s) |
| 19 | assert ret == 's' |
| 20 | } |
| 21 | |
| 22 | // for test interface gen to string |
| 23 | interface Abc {} |
| 24 | |
| 25 | struct Xyz {} |
| 26 | |
| 27 | fn test_interface_gen_to_string() { |
| 28 | d := Abc(Xyz{}) |
| 29 | mut res := '' |
| 30 | if d is Xyz { |
| 31 | println(d) |
| 32 | res = '${d}' |
| 33 | } |
| 34 | assert res == '&Xyz{}' |
| 35 | } |
| 36 |