fix(decode): let the later field win an equal-depth name clash
Assisted-by: GLM 5.3
This commit is contained in:
@@ -586,6 +586,22 @@ func TestUnmarshalEmbeddedNameClashShallowerWins(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshalNameClashEqualDepthLaterWins(t *testing.T) {
|
||||
// At equal depth the field declared later resolves the name, matching the
|
||||
// documented rule.
|
||||
type C struct {
|
||||
First string `toml:"v"`
|
||||
Second int `toml:"v"`
|
||||
}
|
||||
var c C
|
||||
if err := Unmarshal([]byte("v = 1\n"), &c); err != nil {
|
||||
t.Fatalf("unmarshal: %v", err)
|
||||
}
|
||||
if c.Second != 1 {
|
||||
t.Fatalf("decoded: %+v, want the later field to take the value", c)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshalUnknownKeyWithoutEmbeddedMap(t *testing.T) {
|
||||
var cfg RoundTripDerived
|
||||
if err := Unmarshal([]byte("rogue = 1\n"), &cfg); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user