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