mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-03-03 20:27:31 +00:00
fix: structure ignore tag not working in nest struct
This commit is contained in:
@@ -308,3 +308,27 @@ func TestStructure_Ignore(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, s.MustIgnore, "oldData")
|
||||
}
|
||||
|
||||
func TestStructure_IgnoreInNest(t *testing.T) {
|
||||
rawMap := map[string]any{
|
||||
"-": "newData",
|
||||
}
|
||||
|
||||
type TP struct {
|
||||
MustIgnore string `test:"-"`
|
||||
}
|
||||
|
||||
s := struct {
|
||||
TP
|
||||
}{TP{MustIgnore: "oldData"}}
|
||||
|
||||
err := decoder.Decode(rawMap, &s)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, s.MustIgnore, "oldData")
|
||||
|
||||
// test omitempty
|
||||
delete(rawMap, "-")
|
||||
err = decoder.Decode(rawMap, &s)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, s.MustIgnore, "oldData")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user