-
Notifications
You must be signed in to change notification settings - Fork 6
/
string_test.go
63 lines (59 loc) · 1.44 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
package gox_test
import (
"reflect"
"testing"
"github.com/goexl/gox"
)
func TestCamel(t *testing.T) {
tests := []struct {
in string
expected string
}{
{"a b", "aB"},
{"a_b", "aB"},
{"a-b", "aB"},
{"Db", "db"},
}
for index, test := range tests {
camel := gox.String(test.in).Switch().Camel().Build()
if got := camel.Case(); test.expected != got {
t.Errorf("第%d个测试未通过,实际:%v,期望:%v", index+1, got, test.expected)
}
}
}
func TestStrike(t *testing.T) {
tests := []struct {
in string
expected string
}{
{"a b", "a-b"},
{"a_b", "a-b"},
{"a-b", "a-b"},
{"Db", "db"},
}
for index, test := range tests {
camel := gox.String(test.in).Switch().Strike().Build()
if got := camel.Case(); test.expected != got {
t.Errorf("第%d个测试未通过,实际:%v,期望:%v", index+1, got, test.expected)
}
}
}
func TestSplit(t *testing.T) {
tests := []struct {
in string
expected []string
}{
{"a b", []string{"a", "b"}},
{"你好,世界", []string{"你好,世界"}},
{"a-b", []string{"a", "b"}},
{"a_b", []string{"a", "b"}},
{"helloWorld", []string{"hello", "World"}},
{"db", []string{"db"}},
}
for index, test := range tests {
split := gox.String(test.in).Split().Naming().Build()
if got := split.Apply(); !reflect.DeepEqual(test.expected, got) {
t.Errorf("第%d个测试未通过,实际:%v,期望:%v", index+1, got, test.expected)
}
}
}