v2 / vlib / v / tests / assign / cross_assign_aliased_array_test.v
13 lines · 11 sloc · 240 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1pub type IntSlice = []int
2
3pub fn (mut x IntSlice) swap(i int, j int) {
4 x[i], x[j] = x[j], x[i]
5}
6
7fn test_cross_assign_aliased_array() {
8 mut x := IntSlice([11, 22])
9 println(x)
10 x.swap(0, 1)
11 println(x)
12 assert x == IntSlice([22, 11])
13}
14