v2 / vlib / v / tests / comptime / comptime_method_call_test.v
25 lines · 21 sloc · 440 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1struct App {}
2
3fn (mut app App) method_one() string {
4 return '1'
5}
6
7fn (mut app App) method_two() string {
8 return '2'
9}
10
11fn reflect_call(method_name string) string {
12 a := App{}
13 $for method in App.methods {
14 if method.name == method_name {
15 return a.$method() + ''
16 }
17 }
18 panic('Method not supported: ${method_name}')
19}
20
21fn test_comptime_method_call() {
22 result := reflect_call('method_one')
23 println(result)
24 assert result == '1'
25}
26