Newer
Older
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
package utils
import (
"testing"
)
func failSlice(t *testing.T, a, exp []string) {
t.Errorf("Expected '%+v', but got '%+v'", exp, a)
}
func checkSlice(t *testing.T, a, exp []string) {
if len(a) != len(exp) {
failSlice(t, a, exp)
return
}
for i, e := range exp {
if e != a[i] {
failSlice(t, a, exp)
return
}
}
}
func TestSplitIgnoreEmpty(t *testing.T) {
tests := []struct {
name string
str string
expected []string
}{
{
name: "Empty",
str: "",
expected: []string{},
},
{
name: "Normal",
str: "a b c d",
expected: []string{
"a",
"b",
"c",
"d",
},
},
{
name: "Multiple Empty",
str: "a b c d",
expected: []string{
"a",
"b",
"c",
"d",
},
},
}
for _, test := range tests {
t.Run(
test.name, func(t *testing.T) {
split := SplitIgnoreEmpty(test.str, " ")
checkSlice(t, split, test.expected)
},
)
}
}