Skip to content

Commit 8cf68aa

Browse files
author
Ben Krieger
committed
reflect: add TestClearMap
1 parent ba79b94 commit 8cf68aa

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/reflect/value_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,32 @@ func TestClearSlice(t *testing.T) {
765765
}
766766
}
767767

768+
func TestClearMap(t *testing.T) {
769+
for _, test := range []struct {
770+
m any
771+
expect any
772+
}{
773+
{
774+
m: map[int]bool{1: true, 2: false, 3: true},
775+
expect: map[int]bool{},
776+
},
777+
{
778+
m: map[string][]byte{"hello": []byte("world")},
779+
expect: map[string][]byte{},
780+
},
781+
} {
782+
v := ValueOf(test.m)
783+
784+
v.Clear()
785+
if len := v.Len(); len != 0 {
786+
t.Errorf("Clear(map) should set len to 0, got %d", len)
787+
}
788+
if !DeepEqual(test.m, test.expect) {
789+
t.Errorf("Clear(map) got %v, expected %v", test.m, test.expect)
790+
}
791+
}
792+
}
793+
768794
func TestIssue4040(t *testing.T) {
769795
var value interface{} = uint16(0)
770796

0 commit comments

Comments
 (0)