mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-15 13:45:10 +08:00
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package prompt
|
||
|
||
import (
|
||
"strings"
|
||
"testing"
|
||
)
|
||
|
||
func TestNormalizeContentNilReturnsEmpty(t *testing.T) {
|
||
if got := NormalizeContent(nil); got != "" {
|
||
t.Fatalf("expected empty string for nil content, got %q", got)
|
||
}
|
||
}
|
||
|
||
func TestMessagesPrepareNilContentNoNullLiteral(t *testing.T) {
|
||
messages := []map[string]any{
|
||
{"role": "assistant", "content": nil},
|
||
{"role": "user", "content": "ok"},
|
||
}
|
||
got := MessagesPrepare(messages)
|
||
if got == "" {
|
||
t.Fatalf("expected non-empty output")
|
||
}
|
||
if got == "null" {
|
||
t.Fatalf("expected no null literal output, got %q", got)
|
||
}
|
||
}
|
||
|
||
func TestMessagesPrepareUsesUnifiedSystemMarkerAndNoEOSTag(t *testing.T) {
|
||
messages := []map[string]any{
|
||
{"role": "system", "content": "System rule"},
|
||
{"role": "assistant", "content": "Answer"},
|
||
}
|
||
got := MessagesPrepare(messages)
|
||
if !strings.Contains(got, "<|System|>\nSystem rule") {
|
||
t.Fatalf("expected unified system marker, got %q", got)
|
||
}
|
||
if strings.Contains(got, "<|end▁of▁sentence|>") {
|
||
t.Fatalf("did not expect EOS marker, got %q", got)
|
||
}
|
||
}
|
||
|
||
func TestNormalizeContentArrayFallsBackToContentWhenTextEmpty(t *testing.T) {
|
||
got := NormalizeContent([]any{
|
||
map[string]any{"type": "text", "text": "", "content": "from-content"},
|
||
})
|
||
if got != "from-content" {
|
||
t.Fatalf("expected fallback to content when text is empty, got %q", got)
|
||
}
|
||
}
|