reflect: add Append()

This commit is contained in:
Damian Gryski
2023-02-25 17:30:48 -08:00
committed by Ayke
parent 9b86080c80
commit 836689fdd2
2 changed files with 63 additions and 2 deletions
+17
View File
@@ -117,6 +117,23 @@ func TestMap(t *testing.T) {
}
}
func TestSlice(t *testing.T) {
s := []int{0, 10, 20}
refs := ValueOf(s)
for i := 3; i < 10; i++ {
refs = Append(refs, ValueOf(i*10))
}
s = refs.Interface().([]int)
for i := 0; i < 10; i++ {
if s[i] != i*10 {
t.Errorf("s[%d]=%d, want %d", i, s[i], i*10)
}
}
}
func equal[T comparable](a, b []T) bool {
if len(a) != len(b) {
return false