mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-10-21 05:57:53 +00:00
perf(stream): append text deltas as JSON without an intermediate Marshal
This commit is contained in:
@@ -1150,3 +1150,20 @@ func TestContentChunkerMatchesChunk(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppendJSONStringMatchesMarshal(t *testing.T) {
|
||||
var cases []string
|
||||
for r := rune(0); r < 0x250; r++ {
|
||||
cases = append(cases, string(r), "a"+string(r)+"b")
|
||||
}
|
||||
cases = append(cases, "\u2028", "\u2029", "x\u2028y\u2029z", "bad\xffutf8", "\xc3", "\xe2\x80", "\U0001F600 emoji", "", "<script>alert('&')</script>")
|
||||
for _, s := range cases {
|
||||
want, err := json.Marshal(s)
|
||||
if err != nil {
|
||||
t.Fatalf("Marshal(%q): %v", s, err)
|
||||
}
|
||||
if got := appendJSONString(nil, s); !bytes.Equal(got, want) {
|
||||
t.Errorf("appendJSONString(%q) = %s, want %s", s, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user