This commit is contained in:
2025-09-26 18:22:17 +08:00
parent 61f7bccdf1
commit a6e0c5e740
6 changed files with 292 additions and 126 deletions
+39
View File
@@ -75,3 +75,42 @@ func TestAndSlice(t *testing.T) {
t.Errorf("Expected %v, got %v", []string{"developer", "golang", "backend"}, dst)
}
}
func TestStructAppendSlice(t *testing.T) {
type person struct {
Name string
Age int
}
src := person{Name: "Alice", Age: 20}
dst := []person{
{Name: "Charlie", Age: 40},
}
if err := Copy(&dst, src); err != nil {
t.Fatal(err)
}
if len(dst) != 2 {
t.Errorf("Expected %d elements, got %d", 2, len(dst))
}
t.Log(dst)
}
func TestAppendSlice(t *testing.T) {
src := []string{"developer", "golang", "backend"}
dst := []any{"do"}
if err := Copy(&dst, src); err != nil {
t.Fatal(err)
}
t.Log(dst)
if !slices.Equal([]any{"do", "developer", "golang", "backend"}, dst) {
t.Errorf("Expected %v, got %v", []string{"do", "developer", "golang", "backend"}, dst)
}
}