Skip to content

Commit af62461

Browse files
cuonglmbradfitz
authored andcommitted
test: add test cases for index value with range array clear
Updates golang#61127 Change-Id: I5fb032c990b64bb4f455a7c0345cfb556bf263bd Reviewed-on: https://go-review.googlesource.com/c/go/+/508335 Reviewed-by: Cherry Mui <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Cuong Manh Le <[email protected]> Auto-Submit: Cuong Manh Le <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]> Auto-Submit: Keith Randall <[email protected]>
1 parent 0036904 commit af62461

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

test/for.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,33 @@ func main() {
4444
for sum < 100 {
4545
sum = sum + 9
4646
}
47-
assertequal(sum, 99 + 9, "only one")
47+
assertequal(sum, 99+9, "only one")
4848

4949
sum = 0
5050
for i := 0; i <= 10; i++ {
51-
if i % 2 == 0 {
51+
if i%2 == 0 {
5252
continue
5353
}
5454
sum = sum + i
5555
}
5656
assertequal(sum, 1+3+5+7+9, "continue")
5757

58+
i = 0
59+
for i = range [5]struct{}{} {
60+
}
61+
assertequal(i, 4, " incorrect index value after range loop")
62+
63+
i = 0
64+
var a1 [5]struct{}
65+
for i = range a1 {
66+
a1[i] = struct{}{}
67+
}
68+
assertequal(i, 4, " incorrect index value after array with zero size elem range clear")
69+
70+
i = 0
71+
var a2 [5]int
72+
for i = range a2 {
73+
a2[i] = 0
74+
}
75+
assertequal(i, 4, " incorrect index value after array range clear")
5876
}

0 commit comments

Comments
 (0)