Initial commit of Descrybe v2 without local scratch artifacts.
Drop one-shot tmp/axe scripts and agent i18n scratch so the Gitea tree is deployable.
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
package company
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSanitizeLangPromptMap(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, err := SanitizeLangPromptMap(map[string]string{
|
||||
"SL": " hello {{name}} ",
|
||||
"xx": "bad",
|
||||
}, 100)
|
||||
if err == nil {
|
||||
t.Fatal("expected error for unsupported language")
|
||||
}
|
||||
m, err := SanitizeLangPromptMap(map[string]string{
|
||||
"SL": " hello {{name}} ",
|
||||
"en": "",
|
||||
}, 100)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if m["sl"] != "hello {{name}}" {
|
||||
t.Fatalf("got %#v", m)
|
||||
}
|
||||
if _, ok := m["en"]; ok {
|
||||
t.Fatalf("empty en should be dropped: %#v", m)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPromptForLanguage(t *testing.T) {
|
||||
t.Parallel()
|
||||
m := LangPromptMap{"sl": "slo", "en": "eng"}
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseContentLanguagesPrimaryFirst(t *testing.T) {
|
||||
t.Parallel()
|
||||
got, err := ParseContentLanguages([]string{"en", "de", "sl"}, "sl")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := []string{"sl", "en", "de"}
|
||||
if len(got) != len(want) {
|
||||
t.Fatalf("got %#v", got)
|
||||
}
|
||||
for i := range want {
|
||||
if got[i] != want[i] {
|
||||
t.Fatalf("got %#v want %#v", got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLocalizedContentRoundTrip(t *testing.T) {
|
||||
t.Parallel()
|
||||
c := LocalizedContent{
|
||||
"sl": {ProcessedName: "Naslov", ProcessedDescription: "Opis"},
|
||||
}
|
||||
b, err := EncodeLocalizedContent(c)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var raw any
|
||||
if err := json.Unmarshal(b, &raw); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
decoded, err := DecodeLocalizedContent(raw)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
f := FieldsForLanguage(decoded, "sl")
|
||||
if f.ProcessedName != "Naslov" || f.ProcessedDescription != "Opis" {
|
||||
t.Fatalf("got %#v", f)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user