v2 / vlib / v / tests / loops / for_in_ref_arr_test.v
31 lines · 26 sloc · 582 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1fn test_for_in_ref_val_ref_arr() {
2 arr := [1, 2, 3, 4, 5]
3 mut rets := []&int{}
4 mut expects := unsafe { []&int{len: 5, init: &arr[index]} }
5
6 for val in &arr {
7 println(val)
8 rets << val
9 }
10
11 for i, val in &arr {
12 assert voidptr(val) == voidptr(rets[i])
13 }
14 assert rets == expects
15}
16
17fn test_for_in_ref_val_ref_arr_ident() {
18 arr_ := [1, 2, 3, 4, 5]
19 arr := &arr_
20 mut rets := []&int{}
21 mut expects := unsafe { []&int{len: 5, init: &arr_[index]} }
22
23 for val in arr {
24 rets << val
25 }
26
27 for i, val in arr {
28 assert voidptr(val) == voidptr(rets[i])
29 }
30 assert rets == expects
31}
32