vxx / vlib / v / tests / interfaces / interface_str_method_test.v
35 lines · 28 sloc · 438 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1interface Str {
2 str() string
3}
4
5struct St {}
6
7fn (s St) str() string {
8 return 's'
9}
10
11fn printer(s Str) string {
12 println(s)
13 return '${s}'
14}
15
16fn test_interface_str_method() {
17 s := St{}
18 ret := printer(s)
19 assert ret == 's'
20}
21
22// for test interface gen to string
23interface Abc {}
24
25struct Xyz {}
26
27fn 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