1{{ define "tests" }}
2package {{ .Locale }}
3
4import (
5 "testing"
6 "time"
7
8 "github.com/go-playground/locales"
9 "github.com/go-playground/locales/currency"
10)
11
12func TestLocale(t *testing.T) {
13
14 trans := New()
15 expected := "{{ .Locale }}"
16
17 if trans.Locale() != expected {
18 t.Errorf("Expected '%s' Got '%s'", expected, trans.Locale())
19 }
20}
21
22func TestPluralsRange(t *testing.T) {
23
24 trans := New()
25
26 tests := []struct {
27 expected locales.PluralRule
28 }{
29 // {
30 // expected: locales.PluralRuleOther,
31 // },
32 }
33
34 rules := trans.PluralsRange()
35 // expected := 1
36 // if len(rules) != expected {
37 // t.Errorf("Expected '%d' Got '%d'", expected, len(rules))
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
56func TestPluralsOrdinal(t *testing.T) {
57
58 trans := New()
59
60 tests := []struct {
61 expected locales.PluralRule
62 }{
63 // {
64 // expected: locales.PluralRuleOne,
65 // },
66 // {
67 // expected: locales.PluralRuleTwo,
68 // },
69 // {
70 // expected: locales.PluralRuleFew,
71 // },
72 // {
73 // expected: locales.PluralRuleOther,
74 // },
75 }
76
77 rules := trans.PluralsOrdinal()
78 // expected := 4
79 // if len(rules) != expected {
80 // t.Errorf("Expected '%d' Got '%d'", expected, len(rules))
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
99func TestPluralsCardinal(t *testing.T) {
100
101 trans := New()
102
103 tests := []struct {
104 expected locales.PluralRule
105 }{
106 // {
107 // expected: locales.PluralRuleOne,
108 // },
109 // {
110 // expected: locales.PluralRuleOther,
111 // },
112 }
113
114 rules := trans.PluralsCardinal()
115 // expected := 2
116 // if len(rules) != expected {
117 // t.Errorf("Expected '%d' Got '%d'", expected, len(rules))
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
136func 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 // num1: 1,
149 // v1: 1,
150 // num2: 2,
151 // v2: 2,
152 // expected: locales.PluralRuleOther,
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
164func 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 // num: 1,
175 // v: 0,
176 // expected: locales.PluralRuleOne,
177 // },
178 // {
179 // num: 2,
180 // v: 0,
181 // expected: locales.PluralRuleTwo,
182 // },
183 // {
184 // num: 3,
185 // v: 0,
186 // expected: locales.PluralRuleFew,
187 // },
188 // {
189 // num: 4,
190 // v: 0,
191 // expected: locales.PluralRuleOther,
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
203func 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 // num: 1,
214 // v: 0,
215 // expected: locales.PluralRuleOne,
216 // },
217 // {
218 // num: 4,
219 // v: 0,
220 // expected: locales.PluralRuleOther,
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
232func 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 // idx: 0,
250 // expected: "Sun",
251 // },
252 // {
253 // idx: 1,
254 // expected: "Mon",
255 // },
256 // {
257 // idx: 2,
258 // expected: "Tue",
259 // },
260 // {
261 // idx: 3,
262 // expected: "Wed",
263 // },
264 // {
265 // idx: 4,
266 // expected: "Thu",
267 // },
268 // {
269 // idx: 5,
270 // expected: "Fri",
271 // },
272 // {
273 // idx: 6,
274 // expected: "Sat",
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
286func 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 // idx: 0,
304 // expected: "S",
305 // },
306 // {
307 // idx: 1,
308 // expected: "M",
309 // },
310 // {
311 // idx: 2,
312 // expected: "T",
313 // },
314 // {
315 // idx: 3,
316 // expected: "W",
317 // },
318 // {
319 // idx: 4,
320 // expected: "T",
321 // },
322 // {
323 // idx: 5,
324 // expected: "F",
325 // },
326 // {
327 // idx: 6,
328 // expected: "S",
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
340func 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 // idx: 0,
358 // expected: "Su",
359 // },
360 // {
361 // idx: 1,
362 // expected: "Mo",
363 // },
364 // {
365 // idx: 2,
366 // expected: "Tu",
367 // },
368 // {
369 // idx: 3,
370 // expected: "We",
371 // },
372 // {
373 // idx: 4,
374 // expected: "Th",
375 // },
376 // {
377 // idx: 5,
378 // expected: "Fr",
379 // },
380 // {
381 // idx: 6,
382 // expected: "Sa",
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
394func 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 // idx: 0,
412 // expected: "Sunday",
413 // },
414 // {
415 // idx: 1,
416 // expected: "Monday",
417 // },
418 // {
419 // idx: 2,
420 // expected: "Tuesday",
421 // },
422 // {
423 // idx: 3,
424 // expected: "Wednesday",
425 // },
426 // {
427 // idx: 4,
428 // expected: "Thursday",
429 // },
430 // {
431 // idx: 5,
432 // expected: "Friday",
433 // },
434 // {
435 // idx: 6,
436 // expected: "Saturday",
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
448func 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 // idx: 1,
466 // expected: "Jan",
467 // },
468 // {
469 // idx: 2,
470 // expected: "Feb",
471 // },
472 // {
473 // idx: 3,
474 // expected: "Mar",
475 // },
476 // {
477 // idx: 4,
478 // expected: "Apr",
479 // },
480 // {
481 // idx: 5,
482 // expected: "May",
483 // },
484 // {
485 // idx: 6,
486 // expected: "Jun",
487 // },
488 // {
489 // idx: 7,
490 // expected: "Jul",
491 // },
492 // {
493 // idx: 8,
494 // expected: "Aug",
495 // },
496 // {
497 // idx: 9,
498 // expected: "Sep",
499 // },
500 // {
501 // idx: 10,
502 // expected: "Oct",
503 // },
504 // {
505 // idx: 11,
506 // expected: "Nov",
507 // },
508 // {
509 // idx: 12,
510 // expected: "Dec",
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
522func 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 // idx: 1,
540 // expected: "J",
541 // },
542 // {
543 // idx: 2,
544 // expected: "F",
545 // },
546 // {
547 // idx: 3,
548 // expected: "M",
549 // },
550 // {
551 // idx: 4,
552 // expected: "A",
553 // },
554 // {
555 // idx: 5,
556 // expected: "M",
557 // },
558 // {
559 // idx: 6,
560 // expected: "J",
561 // },
562 // {
563 // idx: 7,
564 // expected: "J",
565 // },
566 // {
567 // idx: 8,
568 // expected: "A",
569 // },
570 // {
571 // idx: 9,
572 // expected: "S",
573 // },
574 // {
575 // idx: 10,
576 // expected: "O",
577 // },
578 // {
579 // idx: 11,
580 // expected: "N",
581 // },
582 // {
583 // idx: 12,
584 // expected: "D",
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
596func 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 // idx: 1,
614 // expected: "January",
615 // },
616 // {
617 // idx: 2,
618 // expected: "February",
619 // },
620 // {
621 // idx: 3,
622 // expected: "March",
623 // },
624 // {
625 // idx: 4,
626 // expected: "April",
627 // },
628 // {
629 // idx: 5,
630 // expected: "May",
631 // },
632 // {
633 // idx: 6,
634 // expected: "June",
635 // },
636 // {
637 // idx: 7,
638 // expected: "July",
639 // },
640 // {
641 // idx: 8,
642 // expected: "August",
643 // },
644 // {
645 // idx: 9,
646 // expected: "September",
647 // },
648 // {
649 // idx: 10,
650 // expected: "October",
651 // },
652 // {
653 // idx: 11,
654 // expected: "November",
655 // },
656 // {
657 // idx: 12,
658 // expected: "December",
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
670func TestFmtTimeFull(t *testing.T) {
671
672 // loc, err := time.LoadLocation("America/Toronto")
673 // if err != nil {
674 // t.Errorf("Expected '<nil>' Got '%s'", err)
675 // }
676
677 // fixed := time.FixedZone("OTHER", -4)
678
679 tests := []struct {
680 t time.Time
681 expected string
682 }{
683 // {
684 // t: time.Date(2016, 02, 03, 9, 5, 1, 0, loc),
685 // expected: "9:05:01 am Eastern Standard Time",
686 // },
687 // {
688 // t: time.Date(2016, 02, 03, 20, 5, 1, 0, fixed),
689 // expected: "8:05:01 pm OTHER",
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
703func TestFmtTimeLong(t *testing.T) {
704
705 // loc, err := time.LoadLocation("America/Toronto")
706 // if err != nil {
707 // t.Errorf("Expected '<nil>' Got '%s'", err)
708 // }
709
710 tests := []struct {
711 t time.Time
712 expected string
713 }{
714 // {
715 // t: time.Date(2016, 02, 03, 9, 5, 1, 0, loc),
716 // expected: "9:05:01 am EST",
717 // },
718 // {
719 // t: time.Date(2016, 02, 03, 20, 5, 1, 0, loc),
720 // expected: "8:05:01 pm EST",
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
734func TestFmtTimeMedium(t *testing.T) {
735
736 tests := []struct {
737 t time.Time
738 expected string
739 }{
740 // {
741 // t: time.Date(2016, 02, 03, 9, 5, 1, 0, time.UTC),
742 // expected: "9:05:01 am",
743 // },
744 // {
745 // t: time.Date(2016, 02, 03, 20, 5, 1, 0, time.UTC),
746 // expected: "8:05:01 pm",
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
760func TestFmtTimeShort(t *testing.T) {
761
762 tests := []struct {
763 t time.Time
764 expected string
765 }{
766 // {
767 // t: time.Date(2016, 02, 03, 9, 5, 1, 0, time.UTC),
768 // expected: "9:05 am",
769 // },
770 // {
771 // t: time.Date(2016, 02, 03, 20, 5, 1, 0, time.UTC),
772 // expected: "8:05 pm",
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
786func TestFmtDateFull(t *testing.T) {
787
788 tests := []struct {
789 t time.Time
790 expected string
791 }{
792 // {
793 // t: time.Date(2016, 02, 03, 9, 0, 1, 0, time.UTC),
794 // expected: "Wednesday, February 3, 2016",
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
808func TestFmtDateLong(t *testing.T) {
809
810 tests := []struct {
811 t time.Time
812 expected string
813 }{
814 // {
815 // t: time.Date(2016, 02, 03, 9, 0, 1, 0, time.UTC),
816 // expected: "February 3, 2016",
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
830func TestFmtDateMedium(t *testing.T) {
831
832 tests := []struct {
833 t time.Time
834 expected string
835 }{
836 // {
837 // t: time.Date(2016, 02, 03, 9, 0, 1, 0, time.UTC),
838 // expected: "Feb 3, 2016",
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
852func TestFmtDateShort(t *testing.T) {
853
854 tests := []struct {
855 t time.Time
856 expected string
857 }{
858 // {
859 // t: time.Date(2016, 02, 03, 9, 0, 1, 0, time.UTC),
860 // expected: "2/3/16",
861 // },
862 // {
863 // t: time.Date(-500, 02, 03, 9, 0, 1, 0, time.UTC),
864 // expected: "2/3/500",
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
878func TestFmtNumber(t *testing.T) {
879
880 tests := []struct {
881 num float64
882 v uint64
883 expected string
884 }{
885 // {
886 // num: 1123456.5643,
887 // v: 2,
888 // expected: "1,123,456.56",
889 // },
890 // {
891 // num: 1123456.5643,
892 // v: 1,
893 // expected: "1,123,456.6",
894 // },
895 // {
896 // num: 221123456.5643,
897 // v: 3,
898 // expected: "221,123,456.564",
899 // },
900 // {
901 // num: -221123456.5643,
902 // v: 3,
903 // expected: "-221,123,456.564",
904 // },
905 // {
906 // num: -221123456.5643,
907 // v: 3,
908 // expected: "-221,123,456.564",
909 // },
910 // {
911 // num: 0,
912 // v: 2,
913 // expected: "0.00",
914 // },
915 // {
916 // num: -0,
917 // v: 2,
918 // expected: "0.00",
919 // },
920 // {
921 // num: -0,
922 // v: 2,
923 // expected: "0.00",
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
937func TestFmtCurrency(t *testing.T) {
938
939 tests := []struct {
940 num float64
941 v uint64
942 currency currency.Type
943 expected string
944 }{
945 // {
946 // num: 1123456.5643,
947 // v: 2,
948 // currency: currency.USD,
949 // expected: "$1,123,456.56",
950 // },
951 // {
952 // num: 1123456.5643,
953 // v: 1,
954 // currency: currency.USD,
955 // expected: "$1,123,456.60",
956 // },
957 // {
958 // num: 221123456.5643,
959 // v: 3,
960 // currency: currency.USD,
961 // expected: "$221,123,456.564",
962 // },
963 // {
964 // num: -221123456.5643,
965 // v: 3,
966 // currency: currency.USD,
967 // expected: "-$221,123,456.564",
968 // },
969 // {
970 // num: -221123456.5643,
971 // v: 3,
972 // currency: currency.CAD,
973 // expected: "-CAD 221,123,456.564",
974 // },
975 // {
976 // num: 0,
977 // v: 2,
978 // currency: currency.USD,
979 // expected: "$0.00",
980 // },
981 // {
982 // num: -0,
983 // v: 2,
984 // currency: currency.USD,
985 // expected: "$0.00",
986 // },
987 // {
988 // num: -0,
989 // v: 2,
990 // currency: currency.CAD,
991 // expected: "CAD 0.00",
992 // },
993 // {
994 // num: 1.23,
995 // v: 0,
996 // currency: currency.USD,
997 // expected: "$1.00",
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
1011func TestFmtAccounting(t *testing.T) {
1012
1013 tests := []struct {
1014 num float64
1015 v uint64
1016 currency currency.Type
1017 expected string
1018 }{
1019 // {
1020 // num: 1123456.5643,
1021 // v: 2,
1022 // currency: currency.USD,
1023 // expected: "$1,123,456.56",
1024 // },
1025 // {
1026 // num: 1123456.5643,
1027 // v: 1,
1028 // currency: currency.USD,
1029 // expected: "$1,123,456.60",
1030 // },
1031 // {
1032 // num: 221123456.5643,
1033 // v: 3,
1034 // currency: currency.USD,
1035 // expected: "$221,123,456.564",
1036 // },
1037 // {
1038 // num: -221123456.5643,
1039 // v: 3,
1040 // currency: currency.USD,
1041 // expected: "($221,123,456.564)",
1042 // },
1043 // {
1044 // num: -221123456.5643,
1045 // v: 3,
1046 // currency: currency.CAD,
1047 // expected: "(CAD 221,123,456.564)",
1048 // },
1049 // {
1050 // num: -0,
1051 // v: 2,
1052 // currency: currency.USD,
1053 // expected: "$0.00",
1054 // },
1055 // {
1056 // num: -0,
1057 // v: 2,
1058 // currency: currency.CAD,
1059 // expected: "CAD 0.00",
1060 // },
1061 // {
1062 // num: 1.23,
1063 // v: 0,
1064 // currency: currency.USD,
1065 // expected: "$1.00",
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
1079func TestFmtPercent(t *testing.T) {
1080
1081 tests := []struct {
1082 num float64
1083 v uint64
1084 expected string
1085 }{
1086 // {
1087 // num: 15,
1088 // v: 0,
1089 // expected: "15%",
1090 // },
1091 // {
1092 // num: 15,
1093 // v: 2,
1094 // expected: "15.00%",
1095 // },
1096 // {
1097 // num: 434.45,
1098 // v: 0,
1099 // expected: "434%",
1100 // },
1101 // {
1102 // num: 34.4,
1103 // v: 2,
1104 // expected: "34.40%",
1105 // },
1106 // {
1107 // num: -34,
1108 // v: 0,
1109 // expected: "-34%",
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{{ end }}
View as plain text