update
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user