v0.4.0 Unmapped reads any parsed value, UnknownKeys refuses what it names, decode errors name the key path
Test / test (push) Canceled after 0s

This commit is contained in:
Lixen authored and lixen committed 2026-10-26 03:33:39 -04:00
1 parent 170e71f10a
commit e5d5567beb
5 files changed
+80 -16

No files matched your search

+23
View File
@@ -303,6 +303,29 @@ func TestDecodeErrorPathIsLinear(t *testing.T) {
}
}
// A decode error names where it failed by the key path the document spells
func TestDecodeErrorNamesItsKeyPath(t *testing.T) {
type room struct {
Width int `toml:"width"`
}
var v struct {
Play struct{ Sound bool } `toml:"play"`
Rooms []room `toml:"rooms"`
ByKey map[string]room `toml:"by_key"`
}
for _, tt := range []struct {
doc, want string
}{
{"play.Sound = 1", "play.Sound: cannot convert int64 to bool"},
{"rooms = [{ width = 1 }, { width = \"x\" }]", "rooms[1].width: cannot convert string to int"},
{"by_key.\"a b\".width = true", `by_key."a b".width: cannot convert bool to int`},
} {
if err := Unmarshal([]byte(tt.doc+"\n"), &v); err == nil || err.Error() != tt.want {
t.Errorf("%s: error %v, want %s", tt.doc, err, tt.want)
}
}
}
// Header paths are bounded: deep nesting is written inline past the bound,
// so output stays linear and still round-trips
func TestMarshal_HeaderLengthBounded(t *testing.T) {