reflect: unpack interfaces in MapKeys() if needed

This commit is contained in:
Damian Gryski
2023-03-16 21:23:17 -07:00
committed by Ron Evans
parent f7880e73d8
commit a5ddc68845
2 changed files with 24 additions and 1 deletions
+14
View File
@@ -134,6 +134,20 @@ func TestTinyMap(t *testing.T) {
t.Errorf("m[hello, 4]=%v, want 6", six)
}
keys := refsimap.MapKeys()
if len(keys) != 1 {
t.Errorf("refsimap: MapKeys()=%v, want 1", len(keys))
}
if keys[0].Type() != TypeOf(stringint{}) {
t.Errorf("keys[0] has wrong type: %v", keys[0].Type().String())
}
sikey := keys[0].Interface().(stringint)
if sikey != (stringint{"hello", 4}) {
t.Errorf("sikey has unexpected value: %#v", sikey)
}
// make sure we can look up interface keys with reflection
type unmarshalerText struct {
A, B string