feat: decode arrays into [N]T and add MarshalAppend
Test / test (push) Successful in 2m31s

Assisted-by: GLM 5.3 Flash
This commit is contained in:
2026-09-21 23:58:23 +02:00
parent 10d49fbe60
commit 2e5dfc54c9
6 changed files with 140 additions and 18 deletions
+26
View File
@@ -1998,3 +1998,29 @@ func TestMarshalNumber(t *testing.T) {
}
})
}
func TestMarshalAppend(t *testing.T) {
buf := []byte("preamble\n")
out, err := MarshalAppend(buf, map[string]any{"a": int64(1)})
if err != nil {
t.Fatal(err)
}
want := "preamble\na = 1\n"
if string(out) != want {
t.Errorf("output %q, want %q", out, want)
}
if &out[0] != &buf[0] {
t.Log("append reallocated; capacity differed")
}
out2, err := MarshalAppend(out, map[string]any{"b": true})
if err != nil {
t.Fatal(err)
}
if string(out2) != want+"b = true\n" {
t.Errorf("second append %q", out2)
}
buf = []byte("keep\n")
if out3, err := MarshalAppend(buf, Document{}); err == nil {
t.Errorf("MarshalAppend with an unencodable value = %q, want an error", out3)
}
}