-
Notifications
You must be signed in to change notification settings - Fork 1
/
convert_test.go
173 lines (154 loc) · 4.48 KB
/
convert_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
package casec
import (
"testing"
)
func TestInvert(t *testing.T) {
testCases := []struct {
text string
expected string
}{
{text: "UPPERCASE", expected: "uppercase"},
{text: "lowercase", expected: "LOWERCASE"},
{text: "mIxEdCaSe", expected: "MiXeDcAsE"},
{text: "weird-Case", expected: "WEIRD-cASE"},
}
for i, tc := range testCases {
if s := Invert(tc.text); s != tc.expected {
t.Errorf("[%d] Expecting %v, got %v", i+1, tc.expected, s)
}
}
}
func TestToUpper(t *testing.T) {
testCases := []struct {
text string
expected string
}{
{text: "case", expected: "CASE"},
{text: "upper_case", expected: "UPPER_CASE"},
{text: "This is a sentence", expected: "THIS IS A SENTENCE"},
}
for i, tc := range testCases {
if s := ToUpper(tc.text); s != tc.expected {
t.Errorf("[%d] Expecting %v, got %v", i+1, tc.expected, s)
}
}
}
func TestToLower(t *testing.T) {
testCases := []struct {
text string
expected string
}{
{text: "Case", expected: "case"},
{text: "LOWER_CASE", expected: "lower_case"},
{text: "This is a sentence", expected: "this is a sentence"},
}
for i, tc := range testCases {
if s := ToLower(tc.text); s != tc.expected {
t.Errorf("[%d] Expecting %v, got %v", i+1, tc.expected, s)
}
}
}
func TestToTitle(t *testing.T) {
testCases := []struct {
text string
expected string
}{
{text: "case", expected: "Case"},
{text: "title_case", expected: "Title_case"},
{text: "This is a sentence", expected: "This Is A Sentence"},
}
for i, tc := range testCases {
if s := ToTitle(tc.text); s != tc.expected {
t.Errorf("[%d] Expecting %v, got %v", i+1, tc.expected, s)
}
}
}
func TestToCamel(t *testing.T) {
testCases := []struct {
text string
expected string
}{
{text: "case", expected: "case"},
{text: "snake_case", expected: "snakeCase"},
{text: "This is a sentence", expected: "thisIsASentence"},
{text: "ConsecutiveUPPERCase", expected: "consecutiveUPPERCase"},
{text: "Unknown-SpecialCase", expected: "unknownSpecialCase"},
}
for i, tc := range testCases {
if s := ToCamel(tc.text); s != tc.expected {
t.Errorf("[%d] Expecting %v, got %v", i+1, tc.expected, s)
}
}
}
func TestToPascal(t *testing.T) {
testCases := []struct {
text string
expected string
}{
{text: "case", expected: "Case"},
{text: "snake_case", expected: "SnakeCase"},
{text: "This is a sentence", expected: "ThisIsASentence"},
{text: "consecutiveUPPERCase", expected: "ConsecutiveUPPERCase"},
{text: "Unknown-SpecialCase", expected: "UnknownSpecialCase"},
}
for i, tc := range testCases {
if s := ToPascal(tc.text); s != tc.expected {
t.Errorf("[%d] Expecting %v, got %v", i+1, tc.expected, s)
}
}
}
func TestToSnake(t *testing.T) {
testCases := []struct {
text string
expected string
}{
{text: "case", expected: "case"},
{text: "camelCase", expected: "camel_case"},
{text: "This is a sentence", expected: "this_is_a_sentence"},
{text: "ConsecutiveUPPERCase", expected: "consecutive_upper_case"},
{text: "Unknown-SpecialCase", expected: "unknown_special_case"},
}
for i, tc := range testCases {
if s := ToSnake(tc.text); s != tc.expected {
t.Errorf("[%d] Expecting %v, got %v", i+1, tc.expected, s)
}
}
}
func TestToKebab(t *testing.T) {
testCases := []struct {
text string
expected string
}{
{text: "case", expected: "case"},
{text: "camelCase", expected: "camel-case"},
{text: "This is a sentence", expected: "this-is-a-sentence"},
{text: "ConsecutiveUPPERCase", expected: "consecutive-upper-case"},
{text: "Unknown-SpecialCase", expected: "unknown-special-case"},
}
for i, tc := range testCases {
if s := ToKebab(tc.text); s != tc.expected {
t.Errorf("[%d] Expecting %v, got %v", i+1, tc.expected, s)
}
}
}
func TestToCaseFor(t *testing.T) {
testCases := []struct {
kind string
text string
expected string
}{
{kind: "upper", text: "uppercase", expected: "UPPERCASE"},
{kind: "lower", text: "LOWERCASE", expected: "lowercase"},
{kind: "title", text: "titlecase", expected: "Titlecase"},
{kind: "camel", text: "camel_case", expected: "camelCase"},
{kind: "pascal", text: "pascal_case", expected: "PascalCase"},
{kind: "snake", text: "snakeCase", expected: "snake_case"},
{kind: "kebab", text: "kebabCase", expected: "kebab-case"},
{kind: "unknown", text: "unknown", expected: ""},
}
for i, tc := range testCases {
if s, _ := ToCaseFor(tc.kind, tc.text); s != tc.expected {
t.Errorf("[%d] Expecting %v, got %v", i+1, tc.expected, s)
}
}
}