-
Notifications
You must be signed in to change notification settings - Fork 3
/
maptostring_test.go
75 lines (70 loc) · 1.35 KB
/
maptostring_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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package stringFormatter_test
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/wissance/stringFormatter"
)
const _separator = ", "
func TestMapToString(t *testing.T) {
for name, test := range map[string]struct {
str string
expectedParts []string
}{
"semicolon sep": {
str: stringFormatter.MapToString(
map[string]any{
"connectTimeout": 1000,
"useSsl": true,
"login": "sa",
"password": "sa",
},
"{key} : {value}",
_separator,
),
expectedParts: []string{
"connectTimeout : 1000",
"useSsl : true",
"login : sa",
"password : sa",
},
},
"arrow sep": {
str: stringFormatter.MapToString(
map[int]any{
1: "value 1",
2: "value 2",
-5: "value -5",
},
"{key} => {value}",
_separator,
),
expectedParts: []string{
"1 => value 1",
"2 => value 2",
"-5 => value -5",
},
},
"only value": {
str: stringFormatter.MapToString(
map[uint64]any{
1: "value 1",
2: "value 2",
5: "value 5",
},
"{value}",
_separator,
),
expectedParts: []string{
"value 1",
"value 2",
"value 5",
},
},
} {
t.Run(name, func(t *testing.T) {
actualParts := strings.Split(test.str, _separator)
assert.ElementsMatch(t, test.expectedParts, actualParts)
})
}
}