1package locale_test23import (4 "testing"56 "src.rest/cat/012/internal/locale"7)89func TestLookup(t *testing.T) {10 for in, want := range map[string]string{11 "de-DE": "de-DE", "de_de": "de-DE", "DE-de": "de-DE", " en-GB ": "en-GB",12 "de": "de-DE", "fr": "fr-FR", "xx-YY": "", "": "", "de-AT": "",13 } {14 l, ok := locale.Lookup(in)15 if got := ""; ok {16 got = l.Tag17 if got != want {18 t.Errorf("Lookup(%q) = %s, want %q", in, got, want)19 }20 } else if want != "" {21 t.Errorf("Lookup(%q) found nothing, want %s", in, want)22 }23 }24}2526func TestFromPOSIX(t *testing.T) {27 for in, want := range map[string]string{28 "de_DE.UTF-8": "de-DE", "fr_FR@euro": "fr-FR", "en_US.UTF-8": "en-US", "C": "", "POSIX": "",29 "C.UTF-8": "", "": "", "xx_YY.UTF-8": "", "pt_BR": "pt-BR",30 } {31 if got := locale.FromPOSIX(in); got != want {32 t.Errorf("FromPOSIX(%q) = %q, want %q", in, got, want)33 }34 }35}3637// TestTable checks every locale is whole: a separator a formula can tell38// from its arguments, a date pattern in its own order, and tags that39// look themselves up.40func TestTable(t *testing.T) {41 seen := map[string]bool{}42 for _, l := range locale.All() {43 if seen[l.Tag] {44 t.Errorf("%s twice", l.Tag)45 }46 seen[l.Tag] = true47 if got, ok := locale.Lookup(l.Tag); !ok || got != l {48 t.Errorf("%s doesn't look itself up", l.Tag)49 }50 if l.Decimal != '.' && l.Decimal != ',' {51 t.Errorf("%s: decimal %q", l.Tag, l.Decimal)52 }53 if l.ArgSep() == l.Decimal || l.ColSep() == l.Decimal || l.Group == string(l.Decimal) {54 t.Errorf("%s: separators clash with the decimal %q", l.Tag, l.Decimal)55 }56 if l.Name == "" || l.Currency == "" || l.Date == "" || l.Time == "" {57 t.Errorf("%s is missing a field", l.Tag)58 }59 }60 if !locale.Canonical.IsCanonical() || locale.Canonical.Tag != "en-US" {61 t.Error("en-US isn't canonical")62 }63 if got := locale.Canonical.DateTime(); got != "m/d/yyyy h:mm:ss" {64 t.Errorf("en-US date time %q", got)65 }66}6768// TestNames checks every locale has a whole set of names, abbreviations69// no longer than the names, and both or neither of AM and PM.70func TestNames(t *testing.T) {71 for _, l := range locale.All() {72 n := l.Names()73 for m := range 12 {74 if n.Months[m] == "" || n.Short[m] == "" {75 t.Errorf("%s: month %d unnamed", l.Tag, m+1)76 }77 }78 for d := range 7 {79 if n.Days[d] == "" || n.DaysShort[d] == "" || len(n.DaysShort[d]) > len(n.Days[d]) {80 t.Errorf("%s: day %d is %q, %q", l.Tag, d, n.Days[d], n.DaysShort[d])81 }82 }83 if (n.AM == "") != (n.PM == "") {84 t.Errorf("%s: AM %q PM %q", l.Tag, n.AM, n.PM)85 }86 if got, ok := locale.ByLCID(l.LCID); !ok || got != l {87 t.Errorf("%s: LCID %X finds %v", l.Tag, l.LCID, got)88 }89 }90 if de, _ := locale.Lookup("de-DE"); de.Names().Months[2] != "März" {91 t.Errorf("de-DE March is %q", de.Names().Months[2])92 }93}