var tot reflect.Type
if !toIsNil {
+ if tov.Kind() == reflect.Slice {
+ // Create a copy of tov, so we don't modify the original.
+ c := reflect.MakeSlice(tov.Type(), tov.Len(), tov.Len()+len(from))
+ reflect.Copy(c, tov)
+ tov = c
+ }
+
if tov.Kind() != reflect.Slice {
return nil, fmt.Errorf("expected a slice, got %T", to)
}
}
}
+
+func TestAppendShouldMakeACopyOfTheInputSlice(t *testing.T) {
+ t.Parallel()
+ c := qt.New(t)
+ slice := make([]string, 0, 100)
+ slice = append(slice, "a", "b")
+ result, err := Append(slice, "c")
+ c.Assert(err, qt.IsNil)
+ slice[0] = "d"
+ c.Assert(result, qt.DeepEquals, []string{"a", "b", "c"})
+ c.Assert(slice, qt.DeepEquals, []string{"d", "b"})
+}