reflection for interface set

rename map access methods to Elem, SetElem.

R=r
DELTA=95  (66 added, 7 deleted, 22 changed)
OCL=31456
CL=31469
This commit is contained in:
Russ Cox 2009-07-10 16:32:26 -07:00
parent 0dadc4fe4f
commit 92e925778e
7 changed files with 86 additions and 27 deletions

View file

@ -626,15 +626,15 @@ func TestMap(t *testing.T) {
i++;
// Check that value lookup is correct.
vv := mv.Get(NewValue(k));
vv := mv.Elem(NewValue(k));
if vi := vv.(*IntValue).Get(); vi != v {
t.Errorf("Key %q: have value %d, want %d", vi, v);
}
// Copy into new map.
newmap.Put(NewValue(k), NewValue(v));
newmap.SetElem(NewValue(k), NewValue(v));
}
vv := mv.Get(NewValue("not-present"));
vv := mv.Elem(NewValue("not-present"));
if vv != nil {
t.Errorf("Invalid key: got non-nil value %s", valueToString(vv));
}
@ -651,7 +651,7 @@ func TestMap(t *testing.T) {
}
}
newmap.Put(NewValue("a"), nil);
newmap.SetElem(NewValue("a"), nil);
v, ok := newm["a"];
if ok {
t.Errorf("newm[\"a\"] = %d after delete", v);
@ -784,3 +784,28 @@ func TestMethod(t *testing.T) {
t.Errorf("Interface Method returned %d; want 250", i);
}
}
func TestInterfaceSet(t *testing.T) {
p := &Point{3, 4};
var s struct {
I interface {};
P interface { Dist(int)int };
}
sv := NewValue(&s).(*PtrValue).Elem().(*StructValue);
sv.Field(0).(*InterfaceValue).Set(NewValue(p));
if q := s.I.(*Point); q != p {
t.Errorf("i: have %p want %p", q, p);
}
pv := sv.Field(1).(*InterfaceValue);
pv.Set(NewValue(p));
if q := s.P.(*Point); q != p {
t.Errorf("i: have %p want %p", q, p);
}
i := pv.Method(0).Call([]Value{NewValue(10)})[0].(*IntValue).Get();
if i != 250 {
t.Errorf("Interface Method returned %d; want 250", i);
}
}