diff --git a/src/reflect/value_test.go b/src/reflect/value_test.go index 9cc1f53c48..add40b3f82 100644 --- a/src/reflect/value_test.go +++ b/src/reflect/value_test.go @@ -765,6 +765,32 @@ func TestClearSlice(t *testing.T) { } } +func TestClearMap(t *testing.T) { + for _, test := range []struct { + m any + expect any + }{ + { + m: map[int]bool{1: true, 2: false, 3: true}, + expect: map[int]bool{}, + }, + { + m: map[string][]byte{"hello": []byte("world")}, + expect: map[string][]byte{}, + }, + } { + v := ValueOf(test.m) + + v.Clear() + if len := v.Len(); len != 0 { + t.Errorf("Clear(map) should set len to 0, got %d", len) + } + if !DeepEqual(test.m, test.expect) { + t.Errorf("Clear(map) got %v, expected %v", test.m, test.expect) + } + } +} + func TestIssue4040(t *testing.T) { var value interface{} = uint16(0)