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