-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathslicetostring_test.go
38 lines (35 loc) · 1.02 KB
/
slicetostring_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package stringFormatter_test
import (
"github.com/stretchr/testify/assert"
"github.com/wissance/stringFormatter"
"testing"
)
func TestSliceToString(t *testing.T) {
for name, test := range map[string]struct {
separator string
data []any
expectedResult string
}{
"comma-separated slice": {
separator: ", ",
data: []any{11, 22, 33, 44, 55, 66, 77, 88, 99},
expectedResult: "11, 22, 33, 44, 55, 66, 77, 88, 99",
},
"dash(kebab) line from slice": {
separator: "-",
data: []any{"str1", "str2", 101, "str3"},
expectedResult: "str1-str2-101-str3",
},
} {
t.Run(name, func(t *testing.T) {
actualResult := stringFormatter.SliceToString(&test.data, &test.separator)
assert.Equal(t, test.expectedResult, actualResult)
})
}
}
func TestSliceSameTypeToString(t *testing.T) {
separator := ":"
numericSlice := []int{100, 200, 400, 800}
result := stringFormatter.SliceSameTypeToString(&numericSlice, &separator)
assert.Equal(t, "100:200:400:800", result)
}