diff options
author | Russ Cox <rsc@golang.org> | 2010-04-20 17:02:08 -0700 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2010-04-20 17:02:08 -0700 |
commit | 25ef42d0fe2d5eabe2c043ccc864c0ffe16166f3 (patch) | |
tree | 54bb3e7ae8e432b97d1a9506ebd7a236631dcff1 /src/pkg/reflect/all_test.go | |
parent | 9bb544ef779363cddbc59be60ea4272715c36552 (diff) | |
download | golang-25ef42d0fe2d5eabe2c043ccc864c0ffe16166f3.tar.gz |
reflect: implement Set(nil), SetValue(nil) for PtrValue and MapValue
R=r
CC=golang-dev
http://codereview.appspot.com/823048
Diffstat (limited to 'src/pkg/reflect/all_test.go')
-rw-r--r-- | src/pkg/reflect/all_test.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/pkg/reflect/all_test.go b/src/pkg/reflect/all_test.go index 67bfe9eaf..552b09d89 100644 --- a/src/pkg/reflect/all_test.go +++ b/src/pkg/reflect/all_test.go @@ -350,6 +350,26 @@ func TestPtrPointTo(t *testing.T) { } } +func TestPtrSetNil(t *testing.T) { + var i int32 = 1234 + ip := &i + vip := NewValue(&ip) + vip.(*PtrValue).Elem().(*PtrValue).Set(nil) + if ip != nil { + t.Errorf("got non-nil (%d), want nil", *ip) + } +} + +func TestMapSetNil(t *testing.T) { + m := make(map[string]int) + vm := NewValue(&m) + vm.(*PtrValue).Elem().(*MapValue).Set(nil) + if m != nil { + t.Errorf("got non-nil (%p), want nil", m) + } +} + + func TestAll(t *testing.T) { testType(t, 1, Typeof((int8)(0)), "int8") testType(t, 2, Typeof((*int8)(nil)).(*PtrType).Elem(), "int8") @@ -838,6 +858,12 @@ func TestMap(t *testing.T) { if ok { t.Errorf("newm[\"a\"] = %d after delete", v) } + + mv = NewValue(&m).(*PtrValue).Elem().(*MapValue) + mv.Set(nil) + if m != nil { + t.Errorf("mv.Set(nil) failed") + } } func TestChan(t *testing.T) { |