v2 / vlib / v / tests / comptime / comptime_method_call_with_check_test.v
26 lines · 23 sloc · 483 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1struct TestStruct {}
2
3fn (t TestStruct) one_arg(a string) string {
4 println(a)
5 return a
6}
7
8fn (t TestStruct) two_args(a string, b int) string {
9 println('${a}:${b}')
10 return a
11}
12
13fn test_main() {
14 t := TestStruct{}
15 mut out := ''
16 $for method in TestStruct.methods {
17 $if method.name == 'one_arg' {
18 res := t.$method(method.name)
19 out += res
20 } $else $if method.name == 'two_args' {
21 res := t.$method(method.name, 42)
22 out += res
23 }
24 }
25 assert out == 'one_argtwo_args'
26}
27