reflect: add SetBytes()

This commit is contained in:
Damian Gryski
2023-03-14 17:37:05 -07:00
committed by Damian Gryski
parent 0da97e2427
commit 91d6ca057c
2 changed files with 21 additions and 1 deletions
+14
View File
@@ -321,6 +321,20 @@ func TestNilType(t *testing.T) {
}
}
func TestSetBytes(t *testing.T) {
var b []byte
refb := ValueOf(&b).Elem()
s := []byte("hello")
refb.SetBytes(s)
s[0] = 'b'
refbSlice := refb.Interface().([]byte)
if len(refbSlice) != len(s) || b[0] != s[0] || refbSlice[0] != s[0] {
t.Errorf("SetBytes(): reflection slice mismatch")
}
}
func equal[T comparable](a, b []T) bool {
if len(a) != len(b) {
return false