mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-23 21:53:09 +02:00
tpl: Add a delimiter parameter to lang.NumFmt
The original implementation of NumFmt did not take into account that the options delimiter (a space) could be a valid option. Adding a delim parameter seems like the simplest, safest, and most flexible way to solve this oversight in a backwards-compatible way. Fixes #5260
This commit is contained in:
committed by
Bjørn Erik Pedersen
parent
91f49c0700
commit
ce264b936c
@@ -18,22 +18,27 @@ func TestNumFormat(t *testing.T) {
|
||||
prec int
|
||||
n float64
|
||||
runes string
|
||||
delim string
|
||||
|
||||
want string
|
||||
}{
|
||||
{2, -12345.6789, "", "-12,345.68"},
|
||||
{2, -12345.6789, "- . ,", "-12,345.68"},
|
||||
{2, -12345.1234, "- . ,", "-12,345.12"},
|
||||
{2, -12345.6789, "", "", "-12,345.68"},
|
||||
{2, -12345.6789, "- . ,", "", "-12,345.68"},
|
||||
{2, -12345.1234, "- . ,", "", "-12,345.12"},
|
||||
|
||||
{2, 12345.6789, "- . ,", "12,345.68"},
|
||||
{0, 12345.6789, "- . ,", "12,346"},
|
||||
{11, -12345.6789, "- . ,", "-12,345.67890000000"},
|
||||
{2, 12345.6789, "- . ,", "", "12,345.68"},
|
||||
{0, 12345.6789, "- . ,", "", "12,346"},
|
||||
{11, -12345.6789, "- . ,", "", "-12,345.67890000000"},
|
||||
|
||||
{3, -12345.6789, "- ,", "-12345,679"},
|
||||
{6, -12345.6789, "- , .", "-12.345,678900"},
|
||||
{3, -12345.6789, "- ,", "", "-12345,679"},
|
||||
{6, -12345.6789, "- , .", "", "-12.345,678900"},
|
||||
|
||||
{3, -12345.6789, "-|,| ", "|", "-12 345,679"},
|
||||
{6, -12345.6789, "-|,| ", "|", "-12 345,678900"},
|
||||
|
||||
// Arabic, ar_AE
|
||||
{6, -12345.6789, "- ٫ ٬", "-12٬345٫678900"},
|
||||
{6, -12345.6789, "- ٫ ٬", "", "-12٬345٫678900"},
|
||||
{6, -12345.6789, "-|٫| ", "|", "-12 345٫678900"},
|
||||
}
|
||||
|
||||
for i, c := range cases {
|
||||
@@ -45,7 +50,11 @@ func TestNumFormat(t *testing.T) {
|
||||
if len(c.runes) == 0 {
|
||||
s, err = ns.NumFmt(c.prec, c.n)
|
||||
} else {
|
||||
s, err = ns.NumFmt(c.prec, c.n, c.runes)
|
||||
if c.delim == "" {
|
||||
s, err = ns.NumFmt(c.prec, c.n, c.runes)
|
||||
} else {
|
||||
s, err = ns.NumFmt(c.prec, c.n, c.runes, c.delim)
|
||||
}
|
||||
}
|
||||
|
||||
require.NoError(t, err, errMsg)
|
||||
|
Reference in New Issue
Block a user