39 lines
918 B
Go
39 lines
918 B
Go
package chat
|
|
|
|
import "testing"
|
|
|
|
func TestSanitizeTitle(t *testing.T) {
|
|
if got := sanitizeTitle(` "测试标题" `); got != "测试标题" {
|
|
t.Fatalf("unexpected: %q", got)
|
|
}
|
|
long := stringsRepeat("标题", 20)
|
|
got := sanitizeTitle(long)
|
|
if len([]rune(got)) > 30 {
|
|
t.Fatalf("title too long: %d", len([]rune(got)))
|
|
}
|
|
}
|
|
|
|
func TestTitleAlreadySummarized(t *testing.T) {
|
|
if titleAlreadySummarized(map[string]any{}) {
|
|
t.Fatal("expected false")
|
|
}
|
|
if !titleAlreadySummarized(map[string]any{"title_summarized": true}) {
|
|
t.Fatal("expected true")
|
|
}
|
|
}
|
|
|
|
func stringsRepeat(s string, n int) string {
|
|
out := ""
|
|
for i := 0; i < n; i++ {
|
|
out += s
|
|
}
|
|
return out
|
|
}
|
|
|
|
func TestParseChatCompletionContent(t *testing.T) {
|
|
body := []byte(`{"choices":[{"message":{"content":" Atlas 部署方案 "}}]}`)
|
|
if got := parseChatCompletionContent(body); got != "Atlas 部署方案" {
|
|
t.Fatalf("unexpected: %q", got)
|
|
}
|
|
}
|