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)
411 expected: "воскресенье",
415 expected: "понедельник",
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)
645 expected: "сентября",
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),
767 // expected: "9:05 am",
770 // t: time.Date(2016, 02, 03, 20, 5, 1, 0, time.UTC),
771 // expected: "8:05 pm",
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),
859 // expected: "2/3/16",
862 // t: time.Date(-500, 02, 03, 9, 0, 1, 0, time.UTC),
863 // expected: "2/3/500",
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)
932 t.Errorf("Expected and got bytes: ", []byte(s), []byte(tt.expected))
937 func TestFmtCurrency(t *testing.T) {
942 currency currency.Type
946 // num: 1123456.5643,
948 // currency: currency.USD,
949 // expected: "$1,123,456.56",
952 // num: 1123456.5643,
954 // currency: currency.USD,
955 // expected: "$1,123,456.60",
958 // num: 221123456.5643,
960 // currency: currency.USD,
961 // expected: "$221,123,456.564",
964 // num: -221123456.5643,
966 // currency: currency.USD,
967 // expected: "-$221,123,456.564",
970 // num: -221123456.5643,
972 // currency: currency.CAD,
973 // expected: "-CAD 221,123,456.564",
978 // currency: currency.USD,
979 // expected: "$0.00",
984 // currency: currency.USD,
985 // expected: "$0.00",
990 // currency: currency.CAD,
991 // expected: "CAD 0.00",
996 // currency: currency.USD,
997 // expected: "$1.00",
1003 for _, tt := range tests {
1004 s := trans.FmtCurrency(tt.num, tt.v, tt.currency)
1005 if s != tt.expected {
1006 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
1011 func TestFmtAccounting(t *testing.T) {
1016 currency currency.Type
1020 // num: 1123456.5643,
1022 // currency: currency.USD,
1023 // expected: "$1,123,456.56",
1026 // num: 1123456.5643,
1028 // currency: currency.USD,
1029 // expected: "$1,123,456.60",
1032 // num: 221123456.5643,
1034 // currency: currency.USD,
1035 // expected: "$221,123,456.564",
1038 // num: -221123456.5643,
1040 // currency: currency.USD,
1041 // expected: "($221,123,456.564)",
1044 // num: -221123456.5643,
1046 // currency: currency.CAD,
1047 // expected: "(CAD 221,123,456.564)",
1052 // currency: currency.USD,
1053 // expected: "$0.00",
1058 // currency: currency.CAD,
1059 // expected: "CAD 0.00",
1064 // currency: currency.USD,
1065 // expected: "$1.00",
1071 for _, tt := range tests {
1072 s := trans.FmtAccounting(tt.num, tt.v, tt.currency)
1073 if s != tt.expected {
1074 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)
1079 func TestFmtPercent(t *testing.T) {
1115 for _, tt := range tests {
1116 s := trans.FmtPercent(tt.num, tt.v)
1117 if s != tt.expected {
1118 t.Errorf("Expected '%s' Got '%s'", tt.expected, s)