reflect: convert map elements to an interface, if needed

This commit is contained in:
Damian Gryski
2023-03-11 15:49:19 -08:00
committed by Ron Evans
parent adaa7ca27a
commit c0f8f129c0
2 changed files with 27 additions and 0 deletions
+18
View File
@@ -192,6 +192,24 @@ func TestTinyMap(t *testing.T) {
}
}
func TestMapInterfaceElem(t *testing.T) {
m := make(map[string]interface{})
refm := ValueOf(m)
four := ValueOf(4)
hello := ValueOf("hello")
refm.SetMapIndex(hello, four)
if v := refm.MapIndex(hello).Interface().(int); v != 4 {
t.Errorf("failed to get value assigned to interface via MapIndex")
}
if v := m["hello"].(int); v != 4 {
t.Errorf("failed to get value assigned to interface via direct lookup")
}
}
func TestTinySlice(t *testing.T) {
s := []int{0, 10, 20}
refs := ValueOf(s)