reflect: add MapIndex()

This commit is contained in:
Damian Gryski
2023-02-25 14:15:35 -08:00
committed by Ayke
parent c0a50e9b47
commit d0f4702f8b
3 changed files with 71 additions and 0 deletions
+9
View File
@@ -44,4 +44,13 @@ func TestMap(t *testing.T) {
if got, want := mtyp.Elem().Kind().String(), "int"; got != want {
t.Errorf("m.Elem().String()=%q, want %q", got, want)
}
m["foo"] = 2
mref := ValueOf(m)
two := mref.MapIndex(ValueOf("foo"))
if got, want := two.Interface().(int), 2; got != want {
t.Errorf("MapIndex(`foo`)=%v, want %v", got, want)
}
}