2023-08-16 09:57:42 +08:00
|
|
|
package reflection
|
|
|
|
|
2023-09-12 14:14:09 +08:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
)
|
2023-08-16 09:57:42 +08:00
|
|
|
|
2023-09-12 14:14:09 +08:00
|
|
|
type Fakeb struct {
|
|
|
|
In int `json:"in"`
|
|
|
|
}
|
2023-08-16 09:57:42 +08:00
|
|
|
type fake struct {
|
2023-09-12 14:14:09 +08:00
|
|
|
Name string `json:"name"`
|
|
|
|
Age int `json:"age"`
|
|
|
|
Usage *Fakeb `json:"usage"`
|
2023-08-16 09:57:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSetter(t *testing.T) {
|
|
|
|
dst := &fake{}
|
2023-09-12 14:14:09 +08:00
|
|
|
ms := map[string]any{"name": "aa", "age": "5", "usage": map[string]any{"in": 15}}
|
|
|
|
err := Setter(dst, ms)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
return
|
|
|
|
}
|
2023-08-16 09:57:42 +08:00
|
|
|
if dst.Age != 5 {
|
|
|
|
t.Errorf("setter failed")
|
2023-09-12 14:14:09 +08:00
|
|
|
} else {
|
|
|
|
fmt.Println(dst.Usage.In)
|
|
|
|
fmt.Printf("%+v", dst)
|
2023-08-16 09:57:42 +08:00
|
|
|
}
|
|
|
|
}
|