1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-09 15:12:26 +08:00

test: add examples for CopyProperties function

This commit is contained in:
dudaodong
2023-02-20 12:00:49 +08:00
parent 46de539e22
commit be8a0558f8

View File

@@ -295,3 +295,45 @@ func ExampleDeepClone() {
// map[a:1 b:2] false
// &{test 1 0.1 true <nil> } false
}
func ExampleCopyProperties() {
type Address struct {
Country string
ZipCode string
}
type User struct {
Name string
Age int
Role string
Addr Address
Hobbys []string
salary int
}
type Employee struct {
Name string
Age int
Role string
Addr Address
Hobbys []string
salary int
}
user := User{Name: "user001", Age: 10, Role: "Admin", Addr: Address{Country: "CN", ZipCode: "001"}, Hobbys: []string{"a", "b"}, salary: 1000}
employee1 := Employee{}
CopyProperties(&employee1, &user)
employee2 := Employee{Name: "employee001", Age: 20, Role: "User",
Addr: Address{Country: "UK", ZipCode: "002"}, salary: 500}
CopyProperties(&employee2, &user)
fmt.Println(employee1)
fmt.Println(employee2)
// Output:
// {user001 10 Admin {CN 001} [a b] 0}
// {user001 10 Admin {CN 001} [a b] 500}
}