Skip to content

Commit 04a4140

Browse files
committed
works as expected
1 parent 40a9d8b commit 04a4140

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

formatter.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ func FormatComplex(template string, args map[string]any) string {
218218
if !ok {
219219
formatOptionIndex := strings.Index(argNumberStr, argumentFormatSeparator)
220220
if formatOptionIndex >= 0 {
221-
argFormatOptions = strings.Trim(argNumberStr[formatOptionIndex+1:], " ")
221+
// argFormatOptions = strings.Trim(argNumberStr[formatOptionIndex+1:], " ")
222+
argFormatOptions = argNumberStr[formatOptionIndex+1:]
222223
argNumberStr = strings.Trim(argNumberStr[:formatOptionIndex], " ")
223224
}
224225

formatter_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,21 @@ func TestFormatComplexWithArgFormatting(t *testing.T) {
299299
args: map[string]any{"float": 10.5467890},
300300
expected: "This is the text with an only number formatting: decimal - 10.546789 / 10.5468 / 10.54678900",
301301
},
302+
"list_with_default_sep": {
303+
template: "This is a list(slice) test: {list:L}",
304+
args: map[string]any{"list": []any{"s1", "s2", "s3"}},
305+
expected: "This is a list(slice) test: s1,s2,s3",
306+
},
307+
"list_with_dash_sep": {
308+
template: "This is a list(slice) test: {list:L-}",
309+
args: map[string]any{"list": []any{"s1", "s2", "s3"}},
310+
expected: "This is a list(slice) test: s1-s2-s3",
311+
},
312+
"list_with_space_sep": {
313+
template: "This is a list(slice) test: {list:L }",
314+
args: map[string]any{"list": []any{"s1", "s2", "s3"}},
315+
expected: "This is a list(slice) test: s1 s2 s3",
316+
},
302317
} {
303318
t.Run(name, func(t *testing.T) {
304319
assert.Equal(t, test.expected, stringFormatter.FormatComplex(test.template, test.args))

0 commit comments

Comments
 (0)