dateparse_tag/parse_test.go

79 lines
1.4 KiB
Go
Raw Permalink Normal View History

2022-01-12 14:11:27 +08:00
package dateparse_tag
import (
"testing"
"time"
)
type User struct {
Name string `json:"name"`
BirthDay string `json:"birth_day" format_date:"default"`
2022-01-13 16:38:46 +08:00
DateS DateS `json:"date_s"`
}
type DateS struct {
OldData string `json:"old_data" format_date:"default"`
NewDates *NewDates `json:"new_dates"`
}
type NewDates struct {
NewDates string `json:"new_dates" format_date:"default"`
2022-01-12 14:11:27 +08:00
}
func TestNewDateParseTag(t *testing.T) {
u := new(User)
u.Name = "张三"
u.BirthDay = time.Now().String()
2022-01-12 14:38:39 +08:00
t.Logf("user : %v", u)
2022-01-12 14:11:27 +08:00
dp := NewDateParseTag(WithTagName("format_date"))
dp.Parse(u, u)
2022-01-12 14:38:39 +08:00
t.Logf("user new %v", u)
2022-01-12 14:11:27 +08:00
}
2022-01-13 16:38:46 +08:00
func TestDateParseTag_Format(t *testing.T) {
u := new(User)
u.Name = "张三"
u.BirthDay = time.Now().String()
u.DateS = DateS{
OldData: time.Now().String(),
NewDates: &NewDates{
NewDates: time.Now().String(),
},
}
t.Logf("user : %v", u)
dp := NewDateParseTag(WithTagName("format_date"))
dp.Format(u)
t.Logf("user new %v %v %v", u, u.DateS, u.DateS.NewDates)
}
func TestDateParseTag_Format2(t *testing.T) {
u := new(User)
u.Name = "张三"
u.BirthDay = time.Now().String()
u.DateS = DateS{
OldData: time.Now().String(),
NewDates: &NewDates{
NewDates: time.Now().String(),
},
}
t.Logf("user : %v", u)
dp := NewDateParseTag(WithTagName("format_date"))
dp.Format(u)
t.Logf("user new %v %v %v", u, u.DateS, u.DateS.NewDates)
}