7 "github.com/go-playground/locales"
8 "github.com/go-playground/locales/currency"
11 func TestLocale(t *testing.T) {
16 if trans.Locale() != expected {
17 t.Errorf("Expected '%s' Got '%s'", expected, trans.Locale())
21 func TestPluralsRange(t *testing.T) {
26 expected locales.PluralRule
29 expected: locales.PluralRuleOther,
33 rules := trans.PluralsRange()
35 if len(rules) != expected {
36 t.Errorf("Expected '%d' Got '%d'", expected, len(rules))
39 for _, tt := range tests {
41 r := locales.PluralRuleUnknown
43 for i := 0; i < len(rules); i++ {
44 if rules[i] == tt.expected {
49 if r == locales.PluralRuleUnknown {
50 t.Errorf("Expected '%s' Got '%s'", tt.expected, r)
55 func TestPluralsOrdinal(t *testing.T) {
60 expected locales.PluralRule
63 expected: locales.PluralRuleOne,
66 expected: locales.PluralRuleTwo,
69 expected: locales.PluralRuleFew,
72 expected: locales.PluralRuleOther,
76 rules := trans.PluralsOrdinal()
78 if len(rules) != expected {
79 t.Errorf("Expected '%d' Got '%d'", expected, len(rules))
82 for _, tt := range tests {
84 r := locales.PluralRuleUnknown
86 for i := 0; i < len(rules); i++ {
87 if rules[i] == tt.expected {
92 if r == locales.PluralRuleUnknown {
93 t.Errorf("Expected '%s' Got '%s'", tt.expected, r)
98 func TestPluralsCardinal(t *testing.T) {
103 expected locales.PluralRule
106 expected: locales.PluralRuleOne,
109 expected: locales.PluralRuleOther,
113 rules := trans.PluralsCardinal()
115 if len(rules) != expected {
116 t.Errorf("Expected '%d' Got '%d'", expected, len(rules))
119 for _, tt := range tests {
121 r := locales.PluralRuleUnknown
123 for i := 0; i < len(rules); i++ {
124 if rules[i] == tt.expected {
129 if r == locales.PluralRuleUnknown {
130 t.Errorf("Expected '%s' Got '%s'", tt.expected, r)
135 func TestRangePlurals(t *testing.T) {
144 expected locales.PluralRule
151 expected: locales.PluralRuleOther,
155 for _, tt := range tests {
156 rule := trans.RangePluralRule(tt.num1, tt.v1, tt.num2, tt.v2)
157 if rule != tt.expected {
158 t.Errorf("Expected '%s' Got '%s'", tt.expected, rule)
163 func TestOrdinalPlurals(t *testing.T) {
170 expected locales.PluralRule
175 expected: locales.PluralRuleOne,
180 expected: locales.PluralRuleTwo,
185 expected: locales.PluralRuleFew,
190 expected: locales.PluralRuleOther,
194 for _, tt := range tests {
195 rule := trans.OrdinalPluralRule(tt.num, tt.v)
196 if rule != tt.expected {
197 t.Errorf("Expected '%s' Got '%s'", tt.expected, rule)
202 func TestCardinalPlurals(t *testing.T) {
209 expected locales.PluralRule
214 expected: locales.PluralRuleOne,
219 expected: locales.PluralRuleOther,
223 for _, tt := range tests {
224 rule := trans.CardinalPluralRule(tt.num, tt.v)
225 if rule != tt.expected {
226 t.Errorf("Expected '%s' Got '%s'", tt.expected, rule)
231 func TestDaysAbbreviated(t *testing.T) {
234 days := trans.WeekdaysAbbreviated()
236 for i, day := range days {
237 s := trans.WeekdayAbbreviated(time.Weekday(i))
239 t.Errorf("Expected '%s' Got '%s'", day, s)
277 for _, tt := range tests {
278 s := trans.WeekdayAbbreviated(time.Weekday(tt.idx))
279 if s != tt.expected {
280 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
285 func TestDaysNarrow(t *testing.T) {
288 days := trans.WeekdaysNarrow()
290 for i, day := range days {
291 s := trans.WeekdayNarrow(time.Weekday(i))
293 t.Errorf("Expected '%s' Got '%s'", string(day), s)
331 for _, tt := range tests {
332 s := trans.WeekdayNarrow(time.Weekday(tt.idx))
333 if s != tt.expected {
334 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
339 func TestDaysShort(t *testing.T) {
342 days := trans.WeekdaysShort()
344 for i, day := range days {
345 s := trans.WeekdayShort(time.Weekday(i))
347 t.Errorf("Expected '%s' Got '%s'", day, s)
385 for _, tt := range tests {
386 s := trans.WeekdayShort(time.Weekday(tt.idx))
387 if s != tt.expected {
388 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
393 func TestDaysWide(t *testing.T) {
396 days := trans.WeekdaysWide()
398 for i, day := range days {
399 s := trans.WeekdayWide(time.Weekday(i))
401 t.Errorf("Expected '%s' Got '%s'", day, s)
423 expected: "Wednesday",
427 expected: "Thursday",
435 expected: "Saturday",
439 for _, tt := range tests {
440 s := trans.WeekdayWide(time.Weekday(tt.idx))
441 if s != tt.expected {
442 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
447 func TestMonthsAbbreviated(t *testing.T) {
450 months := trans.MonthsAbbreviated()
452 for i, month := range months {
453 s := trans.MonthAbbreviated(time.Month(i + 1))
455 t.Errorf("Expected '%s' Got '%s'", month, s)
513 for _, tt := range tests {
514 s := trans.MonthAbbreviated(time.Month(tt.idx))
515 if s != tt.expected {
516 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
521 func TestMonthsNarrow(t *testing.T) {
524 months := trans.MonthsNarrow()
526 for i, month := range months {
527 s := trans.MonthNarrow(time.Month(i + 1))
529 t.Errorf("Expected '%s' Got '%s'", month, s)
587 for _, tt := range tests {
588 s := trans.MonthNarrow(time.Month(tt.idx))
589 if s != tt.expected {
590 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
595 func TestMonthsWide(t *testing.T) {
598 months := trans.MonthsWide()
600 for i, month := range months {
601 s := trans.MonthWide(time.Month(i + 1))
603 t.Errorf("Expected '%s' Got '%s'", month, s)
617 expected: "February",
645 expected: "September",
653 expected: "November",
657 expected: "December",
661 for _, tt := range tests {
662 s := string(trans.MonthWide(time.Month(tt.idx)))
663 if s != tt.expected {
664 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
669 func TestFmtTimeFull(t *testing.T) {
671 loc, err := time.LoadLocation("America/Toronto")
673 t.Errorf("Expected '<nil>' Got '%s'", err)
676 fixed := time.FixedZone("OTHER", -4)
683 t: time.Date(2016, 02, 03, 9, 5, 1, 0, loc),
684 expected: "9:05:01 am Eastern Standard Time",
687 t: time.Date(2016, 02, 03, 20, 5, 1, 0, fixed),
688 expected: "8:05:01 pm OTHER",
694 for _, tt := range tests {
695 s := trans.FmtTimeFull(tt.t)
696 if s != tt.expected {
697 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
702 func TestFmtTimeLong(t *testing.T) {
704 loc, err := time.LoadLocation("America/Toronto")
706 t.Errorf("Expected '<nil>' Got '%s'", err)
714 t: time.Date(2016, 02, 03, 9, 5, 1, 0, loc),
715 expected: "9:05:01 am EST",
718 t: time.Date(2016, 02, 03, 20, 5, 1, 0, loc),
719 expected: "8:05:01 pm EST",
725 for _, tt := range tests {
726 s := trans.FmtTimeLong(tt.t)
727 if s != tt.expected {
728 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
733 func TestFmtTimeMedium(t *testing.T) {
740 t: time.Date(2016, 02, 03, 9, 5, 1, 0, time.UTC),
741 expected: "9:05:01 am",
744 t: time.Date(2016, 02, 03, 20, 5, 1, 0, time.UTC),
745 expected: "8:05:01 pm",
751 for _, tt := range tests {
752 s := trans.FmtTimeMedium(tt.t)
753 if s != tt.expected {
754 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
759 func TestFmtTimeShort(t *testing.T) {
766 t: time.Date(2016, 02, 03, 9, 5, 1, 0, time.UTC),
770 t: time.Date(2016, 02, 03, 20, 5, 1, 0, time.UTC),
777 for _, tt := range tests {
778 s := trans.FmtTimeShort(tt.t)
779 if s != tt.expected {
780 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
785 func TestFmtDateFull(t *testing.T) {
792 t: time.Date(2016, 02, 03, 9, 0, 1, 0, time.UTC),
793 expected: "Wednesday, February 3, 2016",
799 for _, tt := range tests {
800 s := trans.FmtDateFull(tt.t)
801 if s != tt.expected {
802 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
807 func TestFmtDateLong(t *testing.T) {
814 t: time.Date(2016, 02, 03, 9, 0, 1, 0, time.UTC),
815 expected: "February 3, 2016",
821 for _, tt := range tests {
822 s := trans.FmtDateLong(tt.t)
823 if s != tt.expected {
824 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
829 func TestFmtDateMedium(t *testing.T) {
836 t: time.Date(2016, 02, 03, 9, 0, 1, 0, time.UTC),
837 expected: "Feb 3, 2016",
843 for _, tt := range tests {
844 s := trans.FmtDateMedium(tt.t)
845 if s != tt.expected {
846 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
851 func TestFmtDateShort(t *testing.T) {
858 t: time.Date(2016, 02, 03, 9, 0, 1, 0, time.UTC),
862 t: time.Date(-500, 02, 03, 9, 0, 1, 0, time.UTC),
869 for _, tt := range tests {
870 s := trans.FmtDateShort(tt.t)
871 if s != tt.expected {
872 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
877 func TestFmtNumber(t *testing.T) {
887 expected: "1,123,456.56",
892 expected: "1,123,456.6",
897 expected: "221,123,456.564",
900 num: -221123456.5643,
902 expected: "-221,123,456.564",
905 num: -221123456.5643,
907 expected: "-221,123,456.564",
928 for _, tt := range tests {
929 s := trans.FmtNumber(tt.num, tt.v)
930 if s != tt.expected {
931 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
936 func TestFmtCurrency(t *testing.T) {
941 currency currency.Type
947 currency: currency.USD,
948 expected: "$1,123,456.56",
953 currency: currency.USD,
954 expected: "$1,123,456.60",
959 currency: currency.USD,
960 expected: "$221,123,456.564",
963 num: -221123456.5643,
965 currency: currency.USD,
966 expected: "-$221,123,456.564",
969 num: -221123456.5643,
971 currency: currency.CAD,
972 expected: "-CAD221,123,456.564",
977 currency: currency.USD,
983 currency: currency.USD,
989 currency: currency.CAD,
995 currency: currency.USD,
1002 for _, tt := range tests {
1003 s := trans.FmtCurrency(tt.num, tt.v, tt.currency)
1004 if s != tt.expected {
1005 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
1010 func TestFmtAccounting(t *testing.T) {
1015 currency currency.Type
1021 currency: currency.USD,
1022 expected: "$1,123,456.56",
1027 currency: currency.USD,
1028 expected: "$1,123,456.60",
1031 num: 221123456.5643,
1033 currency: currency.USD,
1034 expected: "$221,123,456.564",
1037 num: -221123456.5643,
1039 currency: currency.USD,
1040 expected: "($221,123,456.564)",
1043 num: -221123456.5643,
1045 currency: currency.CAD,
1046 expected: "(CAD221,123,456.564)",
1051 currency: currency.USD,
1057 currency: currency.CAD,
1058 expected: "CAD0.00",
1063 currency: currency.USD,
1070 for _, tt := range tests {
1071 s := trans.FmtAccounting(tt.num, tt.v, tt.currency)
1072 if s != tt.expected {
1073 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
1078 func TestFmtPercent(t *testing.T) {
1114 for _, tt := range tests {
1115 s := trans.FmtPercent(tt.num, tt.v)
1116 if s != tt.expected {
1117 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)