1 package ru
2
3 import (
4 "testing"
5 "time"
6
7 "github.com/go-playground/locales"
8 "github.com/go-playground/locales/currency"
9 )
10
11 func TestLocale(t *testing.T) {
12
13 trans := New()
14 expected := "ru"
15
16 if trans.Locale() != expected {
17 t.Errorf("Expected '%s' Got '%s'", expected, trans.Locale())
18 }
19 }
20
21 func TestPluralsRange(t *testing.T) {
22
23 trans := New()
24
25 tests := []struct {
26 expected locales.PluralRule
27 }{
28
29
30
31 }
32
33 rules := trans.PluralsRange()
34
35
36
37
38
39 for _, tt := range tests {
40
41 r := locales.PluralRuleUnknown
42
43 for i := 0; i < len(rules); i++ {
44 if rules[i] == tt.expected {
45 r = rules[i]
46 break
47 }
48 }
49 if r == locales.PluralRuleUnknown {
50 t.Errorf("Expected '%s' Got '%s'", tt.expected, r)
51 }
52 }
53 }
54
55 func TestPluralsOrdinal(t *testing.T) {
56
57 trans := New()
58
59 tests := []struct {
60 expected locales.PluralRule
61 }{
62
63
64
65
66
67
68
69
70
71
72
73
74 }
75
76 rules := trans.PluralsOrdinal()
77
78
79
80
81
82 for _, tt := range tests {
83
84 r := locales.PluralRuleUnknown
85
86 for i := 0; i < len(rules); i++ {
87 if rules[i] == tt.expected {
88 r = rules[i]
89 break
90 }
91 }
92 if r == locales.PluralRuleUnknown {
93 t.Errorf("Expected '%s' Got '%s'", tt.expected, r)
94 }
95 }
96 }
97
98 func TestPluralsCardinal(t *testing.T) {
99
100 trans := New()
101
102 tests := []struct {
103 expected locales.PluralRule
104 }{
105
106
107
108
109
110
111 }
112
113 rules := trans.PluralsCardinal()
114
115
116
117
118
119 for _, tt := range tests {
120
121 r := locales.PluralRuleUnknown
122
123 for i := 0; i < len(rules); i++ {
124 if rules[i] == tt.expected {
125 r = rules[i]
126 break
127 }
128 }
129 if r == locales.PluralRuleUnknown {
130 t.Errorf("Expected '%s' Got '%s'", tt.expected, r)
131 }
132 }
133 }
134
135 func TestRangePlurals(t *testing.T) {
136
137 trans := New()
138
139 tests := []struct {
140 num1 float64
141 v1 uint64
142 num2 float64
143 v2 uint64
144 expected locales.PluralRule
145 }{
146
147
148
149
150
151
152
153 }
154
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)
159 }
160 }
161 }
162
163 func TestOrdinalPlurals(t *testing.T) {
164
165 trans := New()
166
167 tests := []struct {
168 num float64
169 v uint64
170 expected locales.PluralRule
171 }{
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192 }
193
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)
198 }
199 }
200 }
201
202 func TestCardinalPlurals(t *testing.T) {
203
204 trans := New()
205
206 tests := []struct {
207 num float64
208 v uint64
209 expected locales.PluralRule
210 }{
211
212
213
214
215
216
217
218
219
220
221 }
222
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)
227 }
228 }
229 }
230
231 func TestDaysAbbreviated(t *testing.T) {
232
233 trans := New()
234 days := trans.WeekdaysAbbreviated()
235
236 for i, day := range days {
237 s := trans.WeekdayAbbreviated(time.Weekday(i))
238 if s != day {
239 t.Errorf("Expected '%s' Got '%s'", day, s)
240 }
241 }
242
243 tests := []struct {
244 idx int
245 expected string
246 }{
247 {
248 idx: 0,
249 expected: "вс",
250 },
251 {
252 idx: 1,
253 expected: "пн",
254 },
255 {
256 idx: 2,
257 expected: "вт",
258 },
259 {
260 idx: 3,
261 expected: "ср",
262 },
263 {
264 idx: 4,
265 expected: "чт",
266 },
267 {
268 idx: 5,
269 expected: "пт",
270 },
271 {
272 idx: 6,
273 expected: "сб",
274 },
275 }
276
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)
281 }
282 }
283 }
284
285 func TestDaysNarrow(t *testing.T) {
286
287 trans := New()
288 days := trans.WeekdaysNarrow()
289
290 for i, day := range days {
291 s := trans.WeekdayNarrow(time.Weekday(i))
292 if s != day {
293 t.Errorf("Expected '%s' Got '%s'", string(day), s)
294 }
295 }
296
297 tests := []struct {
298 idx int
299 expected string
300 }{
301 {
302 idx: 0,
303 expected: "вс",
304 },
305 {
306 idx: 1,
307 expected: "пн",
308 },
309 {
310 idx: 2,
311 expected: "вт",
312 },
313 {
314 idx: 3,
315 expected: "ср",
316 },
317 {
318 idx: 4,
319 expected: "чт",
320 },
321 {
322 idx: 5,
323 expected: "пт",
324 },
325 {
326 idx: 6,
327 expected: "сб",
328 },
329 }
330
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)
335 }
336 }
337 }
338
339 func TestDaysShort(t *testing.T) {
340
341 trans := New()
342 days := trans.WeekdaysShort()
343
344 for i, day := range days {
345 s := trans.WeekdayShort(time.Weekday(i))
346 if s != day {
347 t.Errorf("Expected '%s' Got '%s'", day, s)
348 }
349 }
350
351 tests := []struct {
352 idx int
353 expected string
354 }{
355 {
356 idx: 0,
357 expected: "вс",
358 },
359 {
360 idx: 1,
361 expected: "пн",
362 },
363 {
364 idx: 2,
365 expected: "вт",
366 },
367 {
368 idx: 3,
369 expected: "ср",
370 },
371 {
372 idx: 4,
373 expected: "чт",
374 },
375 {
376 idx: 5,
377 expected: "пт",
378 },
379 {
380 idx: 6,
381 expected: "сб",
382 },
383 }
384
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)
389 }
390 }
391 }
392
393 func TestDaysWide(t *testing.T) {
394
395 trans := New()
396 days := trans.WeekdaysWide()
397
398 for i, day := range days {
399 s := trans.WeekdayWide(time.Weekday(i))
400 if s != day {
401 t.Errorf("Expected '%s' Got '%s'", day, s)
402 }
403 }
404
405 tests := []struct {
406 idx int
407 expected string
408 }{
409 {
410 idx: 0,
411 expected: "воскресенье",
412 },
413 {
414 idx: 1,
415 expected: "понедельник",
416 },
417 {
418 idx: 2,
419 expected: "вторник",
420 },
421 {
422 idx: 3,
423 expected: "среда",
424 },
425 {
426 idx: 4,
427 expected: "четверг",
428 },
429 {
430 idx: 5,
431 expected: "пятница",
432 },
433 {
434 idx: 6,
435 expected: "суббота",
436 },
437 }
438
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)
443 }
444 }
445 }
446
447 func TestMonthsAbbreviated(t *testing.T) {
448
449 trans := New()
450 months := trans.MonthsAbbreviated()
451
452 for i, month := range months {
453 s := trans.MonthAbbreviated(time.Month(i + 1))
454 if s != month {
455 t.Errorf("Expected '%s' Got '%s'", month, s)
456 }
457 }
458
459 tests := []struct {
460 idx int
461 expected string
462 }{
463 {
464 idx: 1,
465 expected: "янв.",
466 },
467 {
468 idx: 2,
469 expected: "февр.",
470 },
471 {
472 idx: 3,
473 expected: "мар.",
474 },
475 {
476 idx: 4,
477 expected: "апр.",
478 },
479 {
480 idx: 5,
481 expected: "мая",
482 },
483 {
484 idx: 6,
485 expected: "июн.",
486 },
487 {
488 idx: 7,
489 expected: "июл.",
490 },
491 {
492 idx: 8,
493 expected: "авг.",
494 },
495 {
496 idx: 9,
497 expected: "сент.",
498 },
499 {
500 idx: 10,
501 expected: "окт.",
502 },
503 {
504 idx: 11,
505 expected: "нояб.",
506 },
507 {
508 idx: 12,
509 expected: "дек.",
510 },
511 }
512
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)
517 }
518 }
519 }
520
521 func TestMonthsNarrow(t *testing.T) {
522
523 trans := New()
524 months := trans.MonthsNarrow()
525
526 for i, month := range months {
527 s := trans.MonthNarrow(time.Month(i + 1))
528 if s != month {
529 t.Errorf("Expected '%s' Got '%s'", month, s)
530 }
531 }
532
533 tests := []struct {
534 idx int
535 expected string
536 }{
537 {
538 idx: 1,
539 expected: "Я",
540 },
541 {
542 idx: 2,
543 expected: "Ф",
544 },
545 {
546 idx: 3,
547 expected: "М",
548 },
549 {
550 idx: 4,
551 expected: "А",
552 },
553 {
554 idx: 5,
555 expected: "М",
556 },
557 {
558 idx: 6,
559 expected: "И",
560 },
561 {
562 idx: 7,
563 expected: "И",
564 },
565 {
566 idx: 8,
567 expected: "А",
568 },
569 {
570 idx: 9,
571 expected: "С",
572 },
573 {
574 idx: 10,
575 expected: "О",
576 },
577 {
578 idx: 11,
579 expected: "Н",
580 },
581 {
582 idx: 12,
583 expected: "Д",
584 },
585 }
586
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)
591 }
592 }
593 }
594
595 func TestMonthsWide(t *testing.T) {
596
597 trans := New()
598 months := trans.MonthsWide()
599
600 for i, month := range months {
601 s := trans.MonthWide(time.Month(i + 1))
602 if s != month {
603 t.Errorf("Expected '%s' Got '%s'", month, s)
604 }
605 }
606
607 tests := []struct {
608 idx int
609 expected string
610 }{
611 {
612 idx: 1,
613 expected: "января",
614 },
615 {
616 idx: 2,
617 expected: "февраля",
618 },
619 {
620 idx: 3,
621 expected: "марта",
622 },
623 {
624 idx: 4,
625 expected: "апреля",
626 },
627 {
628 idx: 5,
629 expected: "мая",
630 },
631 {
632 idx: 6,
633 expected: "июня",
634 },
635 {
636 idx: 7,
637 expected: "июля",
638 },
639 {
640 idx: 8,
641 expected: "августа",
642 },
643 {
644 idx: 9,
645 expected: "сентября",
646 },
647 {
648 idx: 10,
649 expected: "октября",
650 },
651 {
652 idx: 11,
653 expected: "ноября",
654 },
655 {
656 idx: 12,
657 expected: "декабря",
658 },
659 }
660
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)
665 }
666 }
667 }
668
669 func TestFmtTimeFull(t *testing.T) {
670
671
672
673
674
675
676
677
678 tests := []struct {
679 t time.Time
680 expected string
681 }{
682
683
684
685
686
687
688
689
690 }
691
692 trans := New()
693
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)
698 }
699 }
700 }
701
702 func TestFmtTimeLong(t *testing.T) {
703
704
705
706
707
708
709 tests := []struct {
710 t time.Time
711 expected string
712 }{
713
714
715
716
717
718
719
720
721 }
722
723 trans := New()
724
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)
729 }
730 }
731 }
732
733 func TestFmtTimeMedium(t *testing.T) {
734
735 tests := []struct {
736 t time.Time
737 expected string
738 }{
739
740
741
742
743
744
745
746
747 }
748
749 trans := New()
750
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)
755 }
756 }
757 }
758
759 func TestFmtTimeShort(t *testing.T) {
760
761 tests := []struct {
762 t time.Time
763 expected string
764 }{
765
766
767
768
769
770
771
772
773 }
774
775 trans := New()
776
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)
781 }
782 }
783 }
784
785 func TestFmtDateFull(t *testing.T) {
786
787 tests := []struct {
788 t time.Time
789 expected string
790 }{
791
792
793
794
795 }
796
797 trans := New()
798
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)
803 }
804 }
805 }
806
807 func TestFmtDateLong(t *testing.T) {
808
809 tests := []struct {
810 t time.Time
811 expected string
812 }{
813
814
815
816
817 }
818
819 trans := New()
820
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)
825 }
826 }
827 }
828
829 func TestFmtDateMedium(t *testing.T) {
830
831 tests := []struct {
832 t time.Time
833 expected string
834 }{
835
836
837
838
839 }
840
841 trans := New()
842
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)
847 }
848 }
849 }
850
851 func TestFmtDateShort(t *testing.T) {
852
853 tests := []struct {
854 t time.Time
855 expected string
856 }{
857
858
859
860
861
862
863
864
865 }
866
867 trans := New()
868
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)
873 }
874 }
875 }
876
877 func TestFmtNumber(t *testing.T) {
878
879 tests := []struct {
880 num float64
881 v uint64
882 expected string
883 }{
884 {
885 num: 1123456.5643,
886 v: 2,
887 expected: "1 123 456,56",
888 },
889 {
890 num: 1123456.5643,
891 v: 1,
892 expected: "1 123 456,6",
893 },
894 {
895 num: 221123456.5643,
896 v: 3,
897 expected: "221 123 456,564",
898 },
899 {
900 num: -221123456.5643,
901 v: 3,
902 expected: "-221 123 456,564",
903 },
904 {
905 num: -221123456.5643,
906 v: 3,
907 expected: "-221 123 456,564",
908 },
909 {
910 num: 0,
911 v: 2,
912 expected: "0,00",
913 },
914 {
915 num: -0,
916 v: 2,
917 expected: "0,00",
918 },
919 {
920 num: -0,
921 v: 2,
922 expected: "0,00",
923 },
924 }
925
926 trans := New()
927
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 }
933 }
934 }
935
936 func TestFmtCurrency(t *testing.T) {
937
938 tests := []struct {
939 num float64
940 v uint64
941 currency currency.Type
942 expected string
943 }{
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998 }
999
1000 trans := New()
1001
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)
1006 }
1007 }
1008 }
1009
1010 func TestFmtAccounting(t *testing.T) {
1011
1012 tests := []struct {
1013 num float64
1014 v uint64
1015 currency currency.Type
1016 expected string
1017 }{
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066 }
1067
1068 trans := New()
1069
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)
1074 }
1075 }
1076 }
1077
1078 func TestFmtPercent(t *testing.T) {
1079
1080 tests := []struct {
1081 num float64
1082 v uint64
1083 expected string
1084 }{
1085 {
1086 num: 15,
1087 v: 0,
1088 expected: "15%",
1089 },
1090 {
1091 num: 15,
1092 v: 2,
1093 expected: "15,00%",
1094 },
1095 {
1096 num: 434.45,
1097 v: 0,
1098 expected: "434%",
1099 },
1100 {
1101 num: 34.4,
1102 v: 2,
1103 expected: "34,40%",
1104 },
1105 {
1106 num: -34,
1107 v: 0,
1108 expected: "-34%",
1109 },
1110 }
1111
1112 trans := New()
1113
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)
1118 }
1119 }
1120 }
1121
View as plain text