v2 / vlib / v / tests / structs / struct_map_method_test.v
35 lines · 27 sloc · 481 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1type Foo = int
2
3fn (a Foo) map(add int) string {
4 return (a + add).str()
5}
6
7fn test_map_one_arg() {
8 a := Foo(0)
9 assert a.map(1) == '1'
10 assert Foo(3).map(3) == '6'
11}
12
13type Bar = int
14
15fn (b Bar) map() int {
16 return b + 1
17}
18
19fn test_map_no_arg() {
20 b := Bar(0)
21 assert b.map() == 1
22 assert Bar(1).map() == 2
23}
24
25type Baz = int
26
27fn (b Baz) map(a int, c int) int {
28 return b + (a - c)
29}
30
31fn test_map_more_args() {
32 b := Baz(0)
33 assert b.map(5, 2) == 3
34 assert Baz(3).map(2, 5) == 0
35}
36