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