v2 / vlib / v / tests / comptime / comptime_for_method_param_test.v
30 lines · 26 sloc · 557 bytes · 1187e1367c5b520023b1e7c1cd02523977e4af74
Raw
1module main
2
3struct Struct1 {
4 num f64
5}
6
7fn (mut s Struct1) do_thing(a f32, b voidptr) bool {
8 return false
9}
10
11fn register[T]() []string {
12 mut args := []string{}
13 $for method in T.methods {
14 $for arg in method.params {
15 $if arg.typ is f32 {
16 args << 'f32: ${arg.name} ${typeof(arg.typ).name}'
17 } $else $if arg.typ is voidptr {
18 args << '&void: ${arg.name} ${typeof(arg.typ).name}'
19 } $else {
20 }
21 }
22 }
23 return args
24}
25
26pub fn test_main() {
27 args := register[Struct1]()
28 assert args[0] == 'f32: a f32'
29 assert args[1] == '&void: b voidptr'
30}
31