Source file
test/clear.go
1
2
3
4
5
6
7 package main
8
9 import "math"
10
11 func checkClearSlice() {
12 s := []int{1, 2, 3}
13 clear(s)
14 for i := range s {
15 if s[i] != 0 {
16 panic("clear not zeroing slice elem")
17 }
18 }
19
20 clear([]int{})
21 }
22
23 func checkClearMap() {
24 m1 := make(map[int]int)
25 m1[0] = 0
26 m1[1] = 1
27 clear(m1)
28 if len(m1) != 0 {
29 panic("m1 is not cleared")
30 }
31
32
33 m2 := make(map[float64]int)
34 m2[math.NaN()] = 1
35 m2[math.NaN()] = 1
36 clear(m2)
37 if len(m2) != 0 {
38 panic("m2 is not cleared")
39 }
40
41 clear(map[int]int{})
42 }
43
44 func main() {
45 checkClearSlice()
46 checkClearMap()
47 }
48
View as plain text