v2 / vlib / v / tests / fns / anon_fn_with_alias_args_test.v
36 lines · 30 sloc · 445 bytes · e2e5cf8db56f3562c7baa735061690be936bdf3e
Raw
1type MyString = string
2type MyInt = int
3
4struct S1 {
5 x fn (a int) main.MyString
6}
7
8struct S2 {
9 y fn (a int) main.MyInt
10}
11
12fn get_string(a int) MyString {
13 return '${a}'
14}
15
16fn get_int(a int) MyInt {
17 return a
18}
19
20fn test_anon_fn_with_alias_args() {
21 s1 := S1{
22 x: get_string
23 }
24 println(s1.x)
25 ret1 := s1.x(22)
26 println(ret1)
27 assert ret1 == '22'
28
29 s2 := S2{
30 y: get_int
31 }
32 println(s2.y)
33 ret2 := s2.y(22)
34 println(ret2)
35 assert ret2 == 22
36}
37