fixes
This commit is contained in:
@@ -17,6 +17,7 @@ func TestSanitizeLangPromptMap(t *testing.T) {
|
||||
m, err := SanitizeLangPromptMap(map[string]string{
|
||||
"SL": " hello {{name}} ",
|
||||
"en": "",
|
||||
"*": " shared ",
|
||||
}, 100)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -27,16 +28,37 @@ func TestSanitizeLangPromptMap(t *testing.T) {
|
||||
if _, ok := m["en"]; ok {
|
||||
t.Fatalf("empty en should be dropped: %#v", m)
|
||||
}
|
||||
if m[LangPromptAny] != "shared" {
|
||||
t.Fatalf("wildcard missing: %#v", m)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPromptForLanguage(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := LangPromptMap{"sl": "slo", "en": "eng"}
|
||||
if got := PromptForLanguage(m, "SL"); got != "slo" {
|
||||
if got := PromptForLanguage(m, "SL", ""); got != "slo" {
|
||||
t.Fatalf("got %q", got)
|
||||
}
|
||||
if got := PromptForLanguage(m, "de"); got != "" {
|
||||
t.Fatalf("expected empty, got %q", got)
|
||||
if got := PromptForLanguage(m, "de", ""); got != "" {
|
||||
t.Fatalf("expected empty without primary, got %q", got)
|
||||
}
|
||||
// sl-only map: exact hit for sl
|
||||
slOnly := LangPromptMap{"sl": "slo-only"}
|
||||
if got := PromptForLanguage(slOnly, "sl", "sl"); got != "slo-only" {
|
||||
t.Fatalf("sl exact: got %q", got)
|
||||
}
|
||||
// sl-only map: en request falls back to primary=sl
|
||||
if got := PromptForLanguage(slOnly, "en", "sl"); got != "slo-only" {
|
||||
t.Fatalf("en→primary sl: got %q", got)
|
||||
}
|
||||
// wildcard before primary
|
||||
anyMap := LangPromptMap{"*": "shared", "sl": "slo"}
|
||||
if got := PromptForLanguage(anyMap, "de", "sl"); got != "shared" {
|
||||
t.Fatalf("wildcard before primary: got %q", got)
|
||||
}
|
||||
// explicit lang beats wildcard
|
||||
if got := PromptForLanguage(anyMap, "sl", "en"); got != "slo" {
|
||||
t.Fatalf("explicit beats *: got %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user