(t *testing.T)
| 633 | } |
| 634 | |
| 635 | func TestHumanize(t *testing.T) { |
| 636 | tplContext := getContextOrFail(t) |
| 637 | for i, test := range []struct { |
| 638 | format string |
| 639 | inputData string |
| 640 | expect string |
| 641 | errorCase bool |
| 642 | verifyErr func(actual_string, substring string) bool |
| 643 | }{ |
| 644 | { |
| 645 | format: "size", |
| 646 | inputData: "2048000", |
| 647 | expect: "2.0 MB", |
| 648 | errorCase: false, |
| 649 | verifyErr: strings.Contains, |
| 650 | }, |
| 651 | { |
| 652 | format: "time", |
| 653 | inputData: "Fri, 05 May 2022 15:04:05 +0200", |
| 654 | expect: "ago", |
| 655 | errorCase: false, |
| 656 | verifyErr: strings.HasSuffix, |
| 657 | }, |
| 658 | { |
| 659 | format: "time:2006-Jan-02", |
| 660 | inputData: "2022-May-05", |
| 661 | expect: "ago", |
| 662 | errorCase: false, |
| 663 | verifyErr: strings.HasSuffix, |
| 664 | }, |
| 665 | { |
| 666 | format: "time", |
| 667 | inputData: "Fri, 05 May 2022 15:04:05 GMT+0200", |
| 668 | expect: "error:", |
| 669 | errorCase: true, |
| 670 | verifyErr: strings.HasPrefix, |
| 671 | }, |
| 672 | } { |
| 673 | if actual, err := tplContext.funcHumanize(test.format, test.inputData); !test.verifyErr(actual, test.expect) { |
| 674 | if !test.errorCase { |
| 675 | t.Errorf("Test %d: Expected '%s' but got '%s'", i, test.expect, actual) |
| 676 | if err != nil { |
| 677 | t.Errorf("Test %d: error: %s", i, err.Error()) |
| 678 | } |
| 679 | } |
| 680 | } |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | func getContextOrFail(t *testing.T) TemplateContext { |
| 685 | tplContext, err := initTestContext() |
nothing calls this directly
no test coverage detected