v2 / vlib / v / tests / comptime / comptime_for_method_call_test.v
30 lines · 24 sloc · 412 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1struct Foo {}
2
3fn (f Foo) a() int {
4 return 1
5}
6
7fn (f Foo) b() int {
8 return 2
9}
10
11fn test_comptime_for_method_call() {
12 f := Foo{}
13 mut rets := []string{}
14
15 $for method in Foo.methods {
16 x := f.$method()
17
18 println(x)
19 println(x.str())
20 println('${x}')
21
22 rets << x.str()
23 rets << '${x}'
24 }
25 assert rets.len == 4
26 assert rets[0] == '1'
27 assert rets[1] == '1'
28 assert rets[2] == '2'
29 assert rets[3] == '2'
30}
31