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.PluralRuleOther,
67 rules := trans.PluralsOrdinal()
69 if len(rules) != expected {
70 t.Errorf("Expected '%d' Got '%d'", expected, len(rules))
73 for _, tt := range tests {
75 r := locales.PluralRuleUnknown
77 for i := 0; i < len(rules); i++ {
78 if rules[i] == tt.expected {
83 if r == locales.PluralRuleUnknown {
84 t.Errorf("Expected '%s' Got '%s'", tt.expected, r)
89 func TestPluralsCardinal(t *testing.T) {
94 expected locales.PluralRule
97 expected: locales.PluralRuleOne,
100 expected: locales.PluralRuleFew,
103 expected: locales.PluralRuleMany,
106 expected: locales.PluralRuleOther,
110 rules := trans.PluralsCardinal()
112 if len(rules) != expected {
113 t.Errorf("Expected '%d' Got '%d'", expected, len(rules))
116 for _, tt := range tests {
118 r := locales.PluralRuleUnknown
120 for i := 0; i < len(rules); i++ {
121 if rules[i] == tt.expected {
126 if r == locales.PluralRuleUnknown {
127 t.Errorf("Expected '%s' Got '%s'", tt.expected, r)
132 func TestRangePlurals(t *testing.T) {
141 expected locales.PluralRule
148 expected: locales.PluralRuleOther,
155 expected: locales.PluralRuleFew,
162 expected: locales.PluralRuleOne,
169 expected: locales.PluralRuleMany,
176 expected: locales.PluralRuleMany,
183 expected: locales.PluralRuleOther,
190 expected: locales.PluralRuleOne,
197 expected: locales.PluralRuleFew,
204 expected: locales.PluralRuleMany,
211 expected: locales.PluralRuleOther,
218 expected: locales.PluralRuleOne,
225 expected: locales.PluralRuleFew,
232 expected: locales.PluralRuleMany,
239 expected: locales.PluralRuleOther,
246 expected: locales.PluralRuleOne,
253 expected: locales.PluralRuleFew,
260 expected: locales.PluralRuleMany,
267 expected: locales.PluralRuleOther,
271 for _, tt := range tests {
272 rule := trans.RangePluralRule(tt.num1, tt.v1, tt.num2, tt.v2)
273 if rule != tt.expected {
274 t.Errorf("Expected '%s' Got '%s'", tt.expected, rule)
279 func TestOrdinalPlurals(t *testing.T) {
286 expected locales.PluralRule
291 expected: locales.PluralRuleOther,
296 expected: locales.PluralRuleOther,
301 expected: locales.PluralRuleOther,
306 expected: locales.PluralRuleOther,
310 for _, tt := range tests {
311 rule := trans.OrdinalPluralRule(tt.num, tt.v)
312 if rule != tt.expected {
313 t.Errorf("Expected '%s' Got '%s'", tt.expected, rule)
318 func TestCardinalPlurals(t *testing.T) {
325 expected locales.PluralRule
330 expected: locales.PluralRuleOne,
335 expected: locales.PluralRuleOne,
340 expected: locales.PluralRuleOne,
345 expected: locales.PluralRuleFew,
350 expected: locales.PluralRuleFew,
355 expected: locales.PluralRuleFew,
360 expected: locales.PluralRuleFew,
365 expected: locales.PluralRuleMany,
370 expected: locales.PluralRuleMany,
375 expected: locales.PluralRuleMany,
380 expected: locales.PluralRuleMany,
384 for _, tt := range tests {
385 rule := trans.CardinalPluralRule(tt.num, tt.v)
386 if rule != tt.expected {
387 t.Errorf("Expected '%s' Got '%s'", tt.expected, rule)
392 func TestDaysAbbreviated(t *testing.T) {
395 days := trans.WeekdaysAbbreviated()
397 for i, day := range days {
398 s := trans.WeekdayAbbreviated(time.Weekday(i))
400 t.Errorf("Expected '%s' Got '%s'", day, s)
438 for _, tt := range tests {
439 s := trans.WeekdayAbbreviated(time.Weekday(tt.idx))
440 if s != tt.expected {
441 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
446 func TestDaysNarrow(t *testing.T) {
449 days := trans.WeekdaysNarrow()
451 for i, day := range days {
452 s := trans.WeekdayNarrow(time.Weekday(i))
454 t.Errorf("Expected '%s' Got '%s'", string(day), s)
492 for _, tt := range tests {
493 s := trans.WeekdayNarrow(time.Weekday(tt.idx))
494 if s != tt.expected {
495 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
500 func TestDaysShort(t *testing.T) {
503 days := trans.WeekdaysShort()
505 for i, day := range days {
506 s := trans.WeekdayShort(time.Weekday(i))
508 t.Errorf("Expected '%s' Got '%s'", day, s)
546 for _, tt := range tests {
547 s := trans.WeekdayShort(time.Weekday(tt.idx))
548 if s != tt.expected {
549 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
554 func TestDaysWide(t *testing.T) {
557 days := trans.WeekdaysWide()
559 for i, day := range days {
560 s := trans.WeekdayWide(time.Weekday(i))
562 t.Errorf("Expected '%s' Got '%s'", day, s)
572 expected: "воскресенье",
576 expected: "понедельник",
600 for _, tt := range tests {
601 s := trans.WeekdayWide(time.Weekday(tt.idx))
602 if s != tt.expected {
603 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
608 func TestMonthsAbbreviated(t *testing.T) {
611 months := trans.MonthsAbbreviated()
613 for i, month := range months {
614 s := trans.MonthAbbreviated(time.Month(i + 1))
616 t.Errorf("Expected '%s' Got '%s'", month, s)
674 for _, tt := range tests {
675 s := trans.MonthAbbreviated(time.Month(tt.idx))
676 if s != tt.expected {
677 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
682 func TestMonthsNarrow(t *testing.T) {
685 months := trans.MonthsNarrow()
687 for i, month := range months {
688 s := trans.MonthNarrow(time.Month(i + 1))
690 t.Errorf("Expected '%s' Got '%s'", month, s)
748 for _, tt := range tests {
749 s := trans.MonthNarrow(time.Month(tt.idx))
750 if s != tt.expected {
751 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
756 func TestMonthsWide(t *testing.T) {
759 months := trans.MonthsWide()
761 for i, month := range months {
762 s := trans.MonthWide(time.Month(i + 1))
764 t.Errorf("Expected '%s' Got '%s'", month, s)
806 expected: "сентября",
822 for _, tt := range tests {
823 s := string(trans.MonthWide(time.Month(tt.idx)))
824 if s != tt.expected {
825 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
830 func TestFmtTimeFull(t *testing.T) {
832 loc, err := time.LoadLocation("America/Toronto")
834 t.Errorf("Expected '<nil>' Got '%s'", err)
837 fixed := time.FixedZone("OTHER", -4)
844 t: time.Date(2016, 02, 03, 9, 5, 1, 0, loc),
845 expected: "9:05:01 Восточная Америка, стандартное время",
848 t: time.Date(2016, 02, 03, 20, 5, 1, 0, fixed),
849 expected: "20:05:01 OTHER",
855 for _, tt := range tests {
856 s := trans.FmtTimeFull(tt.t)
857 if s != tt.expected {
858 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
863 func TestFmtTimeLong(t *testing.T) {
865 loc, err := time.LoadLocation("America/Toronto")
867 t.Errorf("Expected '<nil>' Got '%s'", err)
875 t: time.Date(2016, 02, 03, 9, 5, 1, 0, loc),
876 expected: "9:05:01 EST",
879 t: time.Date(2016, 02, 03, 20, 5, 1, 0, loc),
880 expected: "20:05:01 EST",
886 for _, tt := range tests {
887 s := trans.FmtTimeLong(tt.t)
888 if s != tt.expected {
889 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
894 func TestFmtTimeMedium(t *testing.T) {
901 t: time.Date(2016, 02, 03, 9, 5, 1, 0, time.UTC),
905 t: time.Date(2016, 02, 03, 20, 5, 1, 0, time.UTC),
906 expected: "20:05:01",
912 for _, tt := range tests {
913 s := trans.FmtTimeMedium(tt.t)
914 if s != tt.expected {
915 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
920 func TestFmtTimeShort(t *testing.T) {
927 t: time.Date(2016, 02, 03, 9, 5, 1, 0, time.UTC),
931 t: time.Date(2016, 02, 03, 20, 5, 1, 0, time.UTC),
938 for _, tt := range tests {
939 s := trans.FmtTimeShort(tt.t)
940 if s != tt.expected {
941 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
946 func TestFmtDateFull(t *testing.T) {
953 t: time.Date(2016, 02, 03, 9, 0, 1, 0, time.UTC),
954 expected: "среда, 3 февраля 2016 г.",
960 for _, tt := range tests {
961 s := trans.FmtDateFull(tt.t)
962 if s != tt.expected {
963 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
968 func TestFmtDateLong(t *testing.T) {
975 t: time.Date(2016, 02, 03, 9, 0, 1, 0, time.UTC),
976 expected: "3 февраля 2016 г.",
982 for _, tt := range tests {
983 s := trans.FmtDateLong(tt.t)
984 if s != tt.expected {
985 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
990 func TestFmtDateMedium(t *testing.T) {
997 t: time.Date(2016, 02, 03, 9, 0, 1, 0, time.UTC),
998 expected: "3 февр. 2016 г.",
1004 for _, tt := range tests {
1005 s := trans.FmtDateMedium(tt.t)
1006 if s != tt.expected {
1007 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
1012 func TestFmtDateShort(t *testing.T) {
1019 t: time.Date(2016, 02, 03, 9, 0, 1, 0, time.UTC),
1020 expected: "03.02.2016", // date format changed from v29 dd.MM.yy to v30 dd.MM.y so adjusted test for new CLDR data
1023 t: time.Date(-500, 02, 03, 9, 0, 1, 0, time.UTC),
1024 expected: "03.02.500",
1030 for _, tt := range tests {
1031 s := trans.FmtDateShort(tt.t)
1032 if s != tt.expected {
1033 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
1038 func TestFmtNumber(t *testing.T) {
1048 expected: "1 123 456,56",
1053 expected: "1 123 456,6",
1056 num: 221123456.5643,
1058 expected: "221 123 456,564",
1061 num: -221123456.5643,
1063 expected: "-221 123 456,564",
1066 num: -221123456.5643,
1068 expected: "-221 123 456,564",
1089 for _, tt := range tests {
1090 s := trans.FmtNumber(tt.num, tt.v)
1091 if s != tt.expected {
1092 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
1097 func TestFmtCurrency(t *testing.T) {
1102 currency currency.Type
1108 currency: currency.USD,
1109 expected: "1 123 456,56 USD",
1114 currency: currency.USD,
1115 expected: "1 123 456,60 USD",
1118 num: 221123456.5643,
1120 currency: currency.USD,
1121 expected: "221 123 456,564 USD",
1124 num: -221123456.5643,
1126 currency: currency.USD,
1127 expected: "-221 123 456,564 USD",
1130 num: -221123456.5643,
1132 currency: currency.CAD,
1133 expected: "-221 123 456,564 CAD",
1138 currency: currency.USD,
1139 expected: "0,00 USD",
1144 currency: currency.USD,
1145 expected: "0,00 USD",
1150 currency: currency.CAD,
1151 expected: "0,00 CAD",
1156 currency: currency.USD,
1157 expected: "1,00 USD",
1163 for _, tt := range tests {
1164 s := trans.FmtCurrency(tt.num, tt.v, tt.currency)
1165 if s != tt.expected {
1166 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
1171 func TestFmtAccounting(t *testing.T) {
1176 currency currency.Type
1182 currency: currency.USD,
1183 expected: "1 123 456,56 USD",
1188 currency: currency.USD,
1189 expected: "1 123 456,60 USD",
1192 num: 221123456.5643,
1194 currency: currency.USD,
1195 expected: "221 123 456,564 USD",
1198 num: -221123456.5643,
1200 currency: currency.USD,
1201 expected: "-221 123 456,564 USD",
1204 num: -221123456.5643,
1206 currency: currency.CAD,
1207 expected: "-221 123 456,564 CAD",
1212 currency: currency.USD,
1213 expected: "0,00 USD",
1218 currency: currency.CAD,
1219 expected: "0,00 CAD",
1224 currency: currency.USD,
1225 expected: "1,00 USD",
1231 for _, tt := range tests {
1232 s := trans.FmtAccounting(tt.num, tt.v, tt.currency)
1233 if s != tt.expected {
1234 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
1239 func TestFmtPercent(t *testing.T) {
1275 for _, tt := range tests {
1276 s := trans.FmtPercent(tt.num, tt.v)
1277 if s != tt.expected {
1278 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)