aboutsummaryrefslogtreecommitdiff
path: root/src/reflect/all_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/reflect/all_test.go')
-rw-r--r--src/reflect/all_test.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/reflect/all_test.go b/src/reflect/all_test.go
index 5a12699472..abdfe41908 100644
--- a/src/reflect/all_test.go
+++ b/src/reflect/all_test.go
@@ -6006,6 +6006,14 @@ func TestReflectMethodTraceback(t *testing.T) {
}
}
+func TestSmallZero(t *testing.T) {
+ type T [10]byte
+ typ := TypeOf(T{})
+ if allocs := testing.AllocsPerRun(100, func() { Zero(typ) }); allocs > 0 {
+ t.Errorf("Creating small zero values caused %f allocs, want 0", allocs)
+ }
+}
+
func TestBigZero(t *testing.T) {
const size = 1 << 10
var v [size]byte
@@ -6017,6 +6025,27 @@ func TestBigZero(t *testing.T) {
}
}
+func TestZeroSet(t *testing.T) {
+ type T [16]byte
+ type S struct {
+ a uint64
+ T T
+ b uint64
+ }
+ v := S{
+ a: 0xaaaaaaaaaaaaaaaa,
+ T: T{9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9},
+ b: 0xbbbbbbbbbbbbbbbb,
+ }
+ ValueOf(&v).Elem().Field(1).Set(Zero(TypeOf(T{})))
+ if v != (S{
+ a: 0xaaaaaaaaaaaaaaaa,
+ b: 0xbbbbbbbbbbbbbbbb,
+ }) {
+ t.Fatalf("Setting a field to a Zero value didn't work")
+ }
+}
+
func TestFieldByIndexNil(t *testing.T) {
type P struct {
F int