-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathstring_test.go
102 lines (96 loc) · 2.08 KB
/
string_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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package slice_test
import (
"strings"
"testing"
"github.com/mailgun/holster/v4/slice"
"github.com/stretchr/testify/assert"
)
func TestContainsString(t *testing.T) {
tests := []struct {
name string
slice []string
str string
modifier func(string) string
want bool
}{
{
name: "Slice contains a specific string",
slice: []string{"aa", "bb", "CC"},
modifier: strings.ToLower,
str: "CC",
want: true,
},
{
name: "Slice contains a string, but it is with upper cases and modifier is nil",
slice: []string{"aa", "bb", "CC"},
str: "cc",
want: false,
},
{
name: "Slice contains a string with upper cases and modifier ToLower is provided",
slice: []string{"AA", "bb", "cc"},
modifier: strings.ToLower,
str: "aa",
want: true,
},
{
name: "Slice does not contains string",
slice: []string{"AA", "bb", "cc"},
str: "notExist",
want: false,
},
{
name: "Empty slice",
slice: []string{},
str: "notExist",
want: false,
},
}
for _, tt := range tests {
got := slice.ContainsString(tt.str, tt.slice, tt.modifier)
assert.Equal(t, tt.want, got)
}
}
func TestContainsStringIgnoreCase(t *testing.T) {
tests := []struct {
name string
slice []string
str string
want bool
}{
{
name: "Slice contains a specific string, but with different upper case",
slice: []string{"aa", "bb", "cC"},
str: "Cc",
want: true,
},
{
name: "Slice contains a string, but it is with upper case",
slice: []string{"aa", "bb", "CC"},
str: "cc",
want: true,
},
{
name: "Slice contains a string, but it is with lower cases",
slice: []string{"aa", "bb", "cc"},
str: "AA",
want: true,
},
{
name: "Slice does not contains string",
slice: []string{"AA", "bb", "cc"},
str: "notExist",
want: false,
},
{
name: "Empty slice",
slice: []string{},
str: "notExist",
want: false,
},
}
for _, tt := range tests {
got := slice.ContainsStringEqualFold(tt.str, tt.slice)
assert.Equal(t, tt.want, got)
}
}