-
Notifications
You must be signed in to change notification settings - Fork 0
/
camel_test.go
190 lines (165 loc) · 4.13 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package scs
import "testing"
// TestStrIsCamel tests StrIsCamel function.
func TestStrIsCamel(t *testing.T) {
tests := []struct {
value string
result bool
}{
// Simple examples
{"One", false},
{"oneTwoThree", true},
{"OneTwoThree", false},
{"ice9", true},
{"Ice9", false},
// Examples with abbreviations
{"isWWWConnection", true},
{"httpToHTTPS", true},
{"isHTTPOrHTTPS", true},
{"IsHTTPOrHTTPS", false},
{"HTTPToHTTPS", false},
{"http_To_HTTPS", false},
{"http-To-HTTPS", false},
}
for i, s := range tests {
if r := StrIsCamel(s.value); s.result != r {
t.Errorf("test for %d is failed, "+
"expected %t but %t", i, s.result, r)
}
}
}
// TestStrToCamel tests StrToCamel function.
func TestStrToCamel(t *testing.T) {
tests := []struct {
value string
result string
}{
// Simple examples
{"One", "one"},
{" One two Three ", "oneTwoThree"},
{"Ice 9", "ice9"},
// Examples with abbreviations
{"is www Connection", "isWWWConnection"},
{"http to https", "httpToHTTPS"},
{"is http or https", "isHTTPOrHTTPS"},
}
for i, s := range tests {
if r := StrToCamel(s.value); s.result != r {
t.Errorf("test for %d is failed, "+
"expected %s but %s", i, s.result, r)
}
}
}
// TestToCamel tests ToCamel function.
func TestToCamel(t *testing.T) {
tests := []struct {
value string
result string
}{
// Simple examples
{"One", "one"},
{" One two Three ", "oneTwoThree"},
{"Ice 9", "ice9"},
// Examples with abbreviations
{"IsWWWConnection", "isWWWConnection"},
{"http-to-https", "httpToHTTPS"},
{"is_http_or_https", "isHTTPOrHTTPS"},
{"httpToHTTPS", "httpToHTTPS"},
}
for i, s := range tests {
if r := ToCamel(s.value); s.result != r {
t.Errorf("test for %d is failed, "+
"expected %s but %s", i, s.result, r)
}
}
}
// TestCamelToKebab tests CamelToKebab function.
func TestCamelToKebab(t *testing.T) {
tests := []struct {
value string
result string
}{
// Simple examples
{"one", "one"},
{"oneTwoThree", "one-two-three"},
{"ice9", "ice-9"},
// Examples with abbreviations
{"isWWWConnection", "is-www-connection"},
{"httpToHTTPS", "http-to-https"},
{"isHTTPOrHTTPS", "is-http-or-https"},
}
for i, s := range tests {
if r, _ := CamelToKebab(s.value); s.result != r {
t.Errorf("test for %d is failed, "+
"expected %s but %s", i, s.result, r)
}
}
}
// TestCamelToKebabError tests CamelToKebab function with wrong value.
func TestCamelToKebabError(t *testing.T) {
notCamel := "one-two-three"
_, err := CamelToKebab(notCamel)
if err == nil {
t.Error("not camel to kebab")
}
}
// TestCamelToPascal tests CamelToPascal function.
func TestCamelToPascal(t *testing.T) {
tests := []struct {
value string
result string
}{
// Simple examples
{"one", "One"},
{"oneTwoThree", "OneTwoThree"},
{"ice9", "Ice9"},
// Examples with abbreviations
{"isWWWConnection", "IsWWWConnection"},
{"httpToHTTPS", "HTTPToHTTPS"},
{"isHTTPOrHTTPS", "IsHTTPOrHTTPS"},
}
for i, s := range tests {
if r, _ := CamelToPascal(s.value); s.result != r {
t.Errorf("test for %d is failed, "+
"expected %s but %s", i, s.result, r)
}
}
}
// TestCamelToPascalError tests CamelToPascal function with wrong value.
func TestCamelToPascalError(t *testing.T) {
notCamel := "one-two-three"
_, err := CamelToPascal(notCamel)
if err == nil {
t.Error("not camel to pascal")
}
}
// TestCamelToSnake tests CamelToSnake function.
func TestCamelToSnake(t *testing.T) {
tests := []struct {
value string
result string
}{
// Simple examples
{"one", "one"},
{"oneTwoThree", "one_two_three"},
{"ice9", "ice_9"},
// Examples with abbreviations
{"isWWWConnection", "is_www_connection"},
{"httpToHTTPS", "http_to_https"},
{"isHTTPOrHTTPS", "is_http_or_https"},
}
for i, s := range tests {
if r, _ := CamelToSnake(s.value); s.result != r {
t.Errorf("test for %d is failed, "+
"expected %s but %s", i, s.result, r)
}
}
}
// TestCamelToSnakeError tests CamelToSnake function with wrong value.
func TestCamelToSnakeError(t *testing.T) {
notCamel := "one-two-three"
_, err := CamelToSnake(notCamel)
if err == nil {
t.Error("not camel to snake")
}
}