github.com/SDLMoe/hugo@v0.47.1/tpl/lang/lang_test.go (about) 1 package lang 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/gohugoio/hugo/deps" 8 "github.com/stretchr/testify/assert" 9 "github.com/stretchr/testify/require" 10 ) 11 12 func TestNumFormat(t *testing.T) { 13 t.Parallel() 14 15 ns := New(&deps.Deps{}) 16 17 cases := []struct { 18 prec int 19 n float64 20 runes string 21 22 want string 23 }{ 24 {2, -12345.6789, "", "-12,345.68"}, 25 {2, -12345.6789, "- . ,", "-12,345.68"}, 26 {2, -12345.1234, "- . ,", "-12,345.12"}, 27 28 {2, 12345.6789, "- . ,", "12,345.68"}, 29 {0, 12345.6789, "- . ,", "12,346"}, 30 {11, -12345.6789, "- . ,", "-12,345.67890000000"}, 31 32 {3, -12345.6789, "- ,", "-12345,679"}, 33 {6, -12345.6789, "- , .", "-12.345,678900"}, 34 35 // Arabic, ar_AE 36 {6, -12345.6789, "- ٫ ٬", "-12٬345٫678900"}, 37 } 38 39 for i, c := range cases { 40 errMsg := fmt.Sprintf("[%d] %v", i, c) 41 42 var s string 43 var err error 44 45 if len(c.runes) == 0 { 46 s, err = ns.NumFmt(c.prec, c.n) 47 } else { 48 s, err = ns.NumFmt(c.prec, c.n, c.runes) 49 } 50 51 require.NoError(t, err, errMsg) 52 assert.Equal(t, c.want, s, errMsg) 53 } 54 }