mirror of
https://gitee.com/johng/gf.git
synced 2024-11-30 03:07:45 +08:00
bugfix:fix gconv map deep option not effective (#3287)
This commit is contained in:
parent
4ddc9c3909
commit
c4a51f4c2f
@ -74,6 +74,9 @@ func doMapConvert(value interface{}, recursive recursiveType, mustMapReturn bool
|
||||
usedOption = getUsedMapOption(option...)
|
||||
newTags = StructTagPriority
|
||||
)
|
||||
if usedOption.Deep {
|
||||
recursive = recursiveTypeTrue
|
||||
}
|
||||
switch len(usedOption.Tags) {
|
||||
case 0:
|
||||
// No need handling.
|
||||
|
@ -538,6 +538,60 @@ field3:
|
||||
})
|
||||
}
|
||||
|
||||
func Test_MapWithDeepOption(t *testing.T) {
|
||||
type Base struct {
|
||||
Id int `c:"id"`
|
||||
Date string `c:"date"`
|
||||
}
|
||||
type User struct {
|
||||
UserBase Base `c:"base"`
|
||||
Passport string `c:"passport"`
|
||||
Password string `c:"password"`
|
||||
Nickname string `c:"nickname"`
|
||||
}
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
user := &User{
|
||||
UserBase: Base{
|
||||
Id: 1,
|
||||
Date: "2019-10-01",
|
||||
},
|
||||
Passport: "john",
|
||||
Password: "123456",
|
||||
Nickname: "JohnGuo",
|
||||
}
|
||||
m := gconv.Map(user)
|
||||
t.Assert(m, g.Map{
|
||||
"base": user.UserBase,
|
||||
"passport": user.Passport,
|
||||
"password": user.Password,
|
||||
"nickname": user.Nickname,
|
||||
})
|
||||
})
|
||||
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
user := &User{
|
||||
UserBase: Base{
|
||||
Id: 1,
|
||||
Date: "2019-10-01",
|
||||
},
|
||||
Passport: "john",
|
||||
Password: "123456",
|
||||
Nickname: "JohnGuo",
|
||||
}
|
||||
m := gconv.Map(user, gconv.MapOption{Deep: true})
|
||||
t.Assert(m, g.Map{
|
||||
"base": g.Map{
|
||||
"id": user.UserBase.Id,
|
||||
"date": user.UserBase.Date,
|
||||
},
|
||||
"passport": user.Passport,
|
||||
"password": user.Password,
|
||||
"nickname": user.Nickname,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestMapStrStr(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
t.Assert(gconv.MapStrStr(map[string]string{"k": "v"}), map[string]string{"k": "v"})
|
||||
|
Loading…
Reference in New Issue
Block a user