-
Notifications
You must be signed in to change notification settings - Fork 0
/
camel_test.go
175 lines (168 loc) · 2.9 KB
/
camel_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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// Copyright (c) 2021 startdusk. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package strnaming
import (
"testing"
"github.com/startdusk/strnaming/style"
)
func TestCamel(t *testing.T) {
testCamel(t)
}
func BenchmarkCamel(b *testing.B) {
for n := 0; n < b.N; n++ {
testCamel(b)
}
}
func testCamel(tb testing.TB) {
cases := []struct {
test string
expect string
upperFirst bool
style Style
delimiters []byte
prefix string
cacheKV struct {
key, val string
}
}{
{
test: "_abc_def",
expect: "abcDef",
},
{
test: " _abc_def",
expect: "abcDef",
},
{
test: " _abc_DB_",
expect: "abcDB",
},
{
test: "DNV.abc",
expect: "dNVAbc",
delimiters: []byte{'.'},
},
{
test: "test_case",
expect: "testCase",
delimiters: []byte{'_', '_'},
},
{
test: "many2many",
expect: "many2Many",
},
{
test: "department_id",
expect: "departmentId",
},
{
test: "department_id",
expect: "DepartmentId",
upperFirst: true,
},
{
test: "_Department_id",
expect: "DepartmentId",
upperFirst: true,
},
{
test: "_Department_id",
expect: "departmentId",
},
{
test: "__prod__",
expect: "Prod",
upperFirst: true,
},
{
test: "",
expect: "",
},
{
test: "Golang",
expect: "Golang",
upperFirst: true,
},
{
test: "__foo_Fzz",
expect: "fooFzz",
},
{
test: "__foo_Fzz",
expect: "FooFzz",
upperFirst: true,
},
{
test: "account_id",
expect: "AccountId",
upperFirst: true,
},
{
test: "account_id",
expect: "accountID",
cacheKV: struct {
key string
val string
}{
key: "account_id",
val: "accountID",
},
},
{
test: "account_id",
expect: "myAccountId",
upperFirst: true,
prefix: "my",
},
{
test: "account_id",
expect: "myaccountId",
prefix: "my",
},
{
test: "AccountID",
expect: "accountID",
},
{
test: "http_test",
expect: "httpTest",
},
{
test: "http_test",
expect: "HttpTest",
upperFirst: true,
},
{
test: "http_test",
expect: "HTTPTest",
style: style.NewGolang(),
},
{
test: "oauth",
expect: "OAuth",
style: style.NewGolang(),
},
{
test: "oi_Auth",
expect: "oiAuth",
},
{
test: "json_data",
expect: "JSONData",
style: style.NewGolang(),
},
}
for _, cc := range cases {
actual := NewCamel().
WithUpperFirst(cc.upperFirst).
WithCache(cc.cacheKV.key, cc.cacheKV.val).
WithPrefix(cc.prefix).
WithDelimiter(cc.delimiters...).
WithStyle(cc.style).
Convert(cc.test)
if actual != cc.expect {
tb.Errorf("test camel case %s expect %s, but got %s\n", cc.test, cc.expect, actual)
}
}
}