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,59 @@
|
||||
package i18n
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestResolveAcceptLanguage(t *testing.T) {
|
||||
t.Parallel()
|
||||
cases := []struct {
|
||||
in string
|
||||
want string
|
||||
}{
|
||||
{"", Default},
|
||||
{"en", "en"},
|
||||
{"nl-NL,nl;q=0.9,en;q=0.8", "nl"},
|
||||
{"fr-CA,en;q=0.5", "fr"},
|
||||
{"xx-YY,en;q=0.1", "en"},
|
||||
{"de;q=0.2,pl;q=0.9", "pl"},
|
||||
{"*;q=0.1", "en"},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
if got := Resolve(tc.in); got != tc.want {
|
||||
t.Fatalf("Resolve(%q)=%q want %q", tc.in, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestTFallsBackAndSkipsStableCodes(t *testing.T) {
|
||||
t.Parallel()
|
||||
if got := T("nl", "unauthorized"); got != "niet geautoriseerd" {
|
||||
t.Fatalf("nl unauthorized=%q", got)
|
||||
}
|
||||
if got := T("nl", "password_not_set"); got != "password_not_set" {
|
||||
t.Fatalf("stable code translated: %q", got)
|
||||
}
|
||||
if got := T("nl", "some unknown message"); got != "some unknown message" {
|
||||
t.Fatalf("missing key should stay English: %q", got)
|
||||
}
|
||||
if got := T("en", "unauthorized"); got != "unauthorized" {
|
||||
t.Fatalf("en identity=%q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSupportedMatchesUILocales(t *testing.T) {
|
||||
t.Parallel()
|
||||
want := []string{"en", "es", "fr", "de", "it", "pt", "nl", "pl", "ja"}
|
||||
if len(Supported) != len(want) {
|
||||
t.Fatalf("Supported len=%d want %d", len(Supported), len(want))
|
||||
}
|
||||
for i, code := range want {
|
||||
if Supported[i] != code {
|
||||
t.Fatalf("Supported[%d]=%q want %q", i, Supported[i], code)
|
||||
}
|
||||
if !IsSupported(code) {
|
||||
t.Fatalf("IsSupported(%q)=false", code)
|
||||
}
|
||||
}
|
||||
if IsSupported("xx") {
|
||||
t.Fatal("xx must not be supported")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user