| 1 | type Foo = int |
| 2 | |
| 3 | fn (a Foo) map(add int) string { |
| 4 | return (a + add).str() |
| 5 | } |
| 6 | |
| 7 | fn test_map_one_arg() { |
| 8 | a := Foo(0) |
| 9 | assert a.map(1) == '1' |
| 10 | assert Foo(3).map(3) == '6' |
| 11 | } |
| 12 | |
| 13 | type Bar = int |
| 14 | |
| 15 | fn (b Bar) map() int { |
| 16 | return b + 1 |
| 17 | } |
| 18 | |
| 19 | fn test_map_no_arg() { |
| 20 | b := Bar(0) |
| 21 | assert b.map() == 1 |
| 22 | assert Bar(1).map() == 2 |
| 23 | } |
| 24 | |
| 25 | type Baz = int |
| 26 | |
| 27 | fn (b Baz) map(a int, c int) int { |
| 28 | return b + (a - c) |
| 29 | } |
| 30 | |
| 31 | fn 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 | |