Assisted-by: GLM 5.3 Flash
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user