-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon_test.go
77 lines (71 loc) · 1.56 KB
/
common_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
package stringo
import (
"testing"
"unicode"
"github.com/stretchr/testify/require"
)
func TestSplitFunc(t *testing.T) {
t.Parallel()
type args struct {
s string
cond func(rune, int) bool
incSep bool
}
tests := []struct {
name string
args args
want []string
}{
{
name: "nil func provied",
args: args{
s: "hello world",
cond: nil,
},
want: []string{"hello world"},
},
{
name: "split by space",
args: args{
s: "hello world",
cond: func(r rune, i int) bool { return unicode.IsSpace(r) },
},
want: []string{"hello", "world"},
},
{
name: "split camelCase",
args: args{
s: "helloWorldItWorks",
cond: func(r rune, i int) bool { return unicode.IsUpper(r) },
incSep: true,
},
want: []string{"hello", "World", "It", "Works"},
},
{
name: "split camelCase in string with spaces",
args: args{
s: "helloWorld itWorks ",
cond: func(r rune, i int) bool { return unicode.IsUpper(r) || unicode.IsSpace(r) },
incSep: true,
},
want: []string{"hello", "World", " it", "Works", " "},
},
{
name: "split camelCase string but only with space and include separator",
args: args{
s: "helloWorld itWorks ",
cond: func(r rune, i int) bool { return unicode.IsSpace(r) },
incSep: true,
},
want: []string{"helloWorld", " itWorks", " "},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got := SplitFunc(tt.args.s, tt.args.cond, tt.args.incSep)
require.Equal(t, tt.want, got)
})
}
}