package i18n import ( "testing" "time" ) func TestFormatDate(t *testing.T) { at := time.Date(2026, 9, 3, 10, 0, 0, 0, time.UTC) for _, c := range []struct{ lang, style, want string }{ {"en", "long", "3 September 2026"}, {"en", "short", "3 Sep 2026"}, {"en", "iso", "2026-09-03"}, {"el", "long", "3 Σεπτεμβρίου 2026"}, {"el", "short", "3 Σεπ 2026"}, {"el", "iso", "2026-09-03"}, {"xx", "long", "3 September 2026"}, // unknown language reads as English } { if got := FormatDate(c.lang, c.style, at); got != c.want { t.Errorf("%s/%s: got %q, want %q", c.lang, c.style, got, c.want) } } } func TestMonth(t *testing.T) { if got := Month("en", time.May); got != "May" { t.Errorf("en: %q", got) } if got := Month("el", time.May); got != "Μάιος" { t.Errorf("el: %q", got) } for _, tbl := range monthTables { for i := 0; i < 12; i++ { if tbl.name[i] == "" || tbl.inDate[i] == "" || tbl.short[i] == "" { t.Errorf("month %d has an empty name", i+1) } } } } func TestTranslate(t *testing.T) { if T("el", "Save") != "Αποθήκευση" || T("en", "Save") != "Save" || T("el", "no such key") != "no such key" { t.Error("T") } if got := Tf("el", "Page %d of %d", 2, 5); got != "Σελίδα 2 από 5" { t.Errorf("Tf: %q", got) } for _, l := range Languages() { if !Valid(l.Code) { t.Errorf("%s not valid", l.Code) } } if Valid("") || Valid("fr") { t.Error("Valid accepts unknown codes") } } func TestMatch(t *testing.T) { for header, want := range map[string]string{ "": "en", "fr": "en", "el": "el", "el-GR,el;q=0.9,en;q=0.8": "el", "en-US,en;q=0.9,el;q=0.8": "en", "fr-FR, EL;q=0.5": "el", "*": "en", } { if got := Match(header); got != want { t.Errorf("%q: got %q, want %q", header, got, want) } } }