mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
21
vlib/v/tests/generics_method_test.v
Normal file
21
vlib/v/tests/generics_method_test.v
Normal file
@@ -0,0 +1,21 @@
|
||||
struct Point {
|
||||
mut:
|
||||
x int
|
||||
y int
|
||||
}
|
||||
|
||||
fn (mut p Point) translate<T>(x T, y T) {
|
||||
p.x += x
|
||||
p.y += y
|
||||
}
|
||||
|
||||
fn test_generic_method() {
|
||||
mut pot := Point{}
|
||||
pot.translate<int>(1, 3)
|
||||
pot.translate(1, 3)
|
||||
println(pot)
|
||||
assert pot == Point{
|
||||
x: 2
|
||||
y: 6
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user