-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcases_test.go
More file actions
139 lines (130 loc) · 4.57 KB
/
cases_test.go
File metadata and controls
139 lines (130 loc) · 4.57 KB
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
package stringx
import "testing"
func TestCamelCase(t *testing.T) {
tests := []struct {
name string
input string
expected string
}{
{"empty string", "", ""},
{"single word lowercase", "hello", "hello"},
{"snake_case", "hello_world", "helloWorld"},
{"kebab-case", "hello-world", "helloWorld"},
{"space separated", "hello world", "helloWorld"},
{"mixed separators", "hello_world-foo bar", "helloWorldFooBar"},
{"PascalCase input", "HelloWorld", "helloWorld"},
{"already camelCase", "helloWorld", "helloWorld"},
{"multiple underscores", "hello__world", "helloWorld"},
{"leading separator", "_hello_world", "helloWorld"},
{"trailing separator", "hello_world_", "helloWorld"},
{"unicode characters", "hello_世界", "hello世界"},
{"with numbers", "hello_2_world", "hello2World"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := CamelCase(tt.input)
if result != tt.expected {
t.Errorf("CamelCase(%q) = %q, want %q", tt.input, result, tt.expected)
}
})
}
}
func TestPascalCase(t *testing.T) {
tests := []struct {
name string
input string
expected string
}{
{"empty string", "", ""},
{"single word lowercase", "hello", "Hello"},
{"snake_case", "hello_world", "HelloWorld"},
{"kebab-case", "hello-world", "HelloWorld"},
{"space separated", "hello world", "HelloWorld"},
{"mixed separators", "hello_world-foo bar", "HelloWorldFooBar"},
{"already PascalCase", "HelloWorld", "HelloWorld"},
{"camelCase input", "helloWorld", "HelloWorld"},
{"multiple underscores", "hello__world", "HelloWorld"},
{"leading separator", "_hello_world", "HelloWorld"},
{"trailing separator", "hello_world_", "HelloWorld"},
{"unicode characters", "hello_世界", "Hello世界"},
{"with numbers", "hello_2_world", "Hello2World"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := PascalCase(tt.input)
if result != tt.expected {
t.Errorf("PascalCase(%q) = %q, want %q", tt.input, result, tt.expected)
}
})
}
}
func TestSnakeCase(t *testing.T) {
tests := []struct {
name string
input string
expected string
}{
{"empty string", "", ""},
{"single word lowercase", "hello", "hello"},
{"single word uppercase", "HELLO", "hello"},
{"camelCase", "helloWorld", "hello_world"},
{"PascalCase", "HelloWorld", "hello_world"},
{"snake_case already", "hello_world", "hello_world"},
{"kebab-case", "hello-world", "hello_world"},
{"space separated", "hello world", "hello_world"},
{"mixed separators", "hello_worldU-foo bar", "hello_world_u_foo_bar"},
{"multiple underscores", "hello__world", "hello_world"},
{"leading separator", "_hello_world", "hello_world"},
{"trailing separator", "hello_world_", "hello_world"},
{"unicode characters", "hello世界", "hello世界"},
{"with numbers", "hello2World", "hello2_world"},
{"uppercase acronym", "XMLParser", "xml_parser"},
{"mixed case complex", "myHTTPServer", "my_http_server"},
{"acronym at end", "parseXML", "parse_xml"},
{"multiple acronyms", "XMLToJSON", "xml_to_json"},
{"single letter words", "aBC", "a_bc"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := SnakeCase(tt.input)
if result != tt.expected {
t.Errorf("SnakeCase(%q) = %q, want %q", tt.input, result, tt.expected)
}
})
}
}
func TestKebabCase(t *testing.T) {
tests := []struct {
name string
input string
expected string
}{
{"empty string", "", ""},
{"single word lowercase", "hello", "hello"},
{"single word uppercase", "HELLO", "hello"},
{"camelCase", "helloWorld", "hello-world"},
{"PascalCase", "HelloWorld", "hello-world"},
{"snake_case", "hello_world", "hello-world"},
{"kebab-case already", "hello-world", "hello-world"},
{"space separated", "hello world", "hello-world"},
{"mixed separators", "hello_worldU-foo bar", "hello-world-u-foo-bar"},
{"multiple dashes", "hello--world", "hello-world"},
{"leading separator", "-hello-world", "hello-world"},
{"trailing separator", "hello-world-", "hello-world"},
{"unicode characters", "hello世界", "hello世界"},
{"with numbers", "hello2World", "hello2-world"},
{"uppercase acronym", "XMLParser", "xml-parser"},
{"mixed case complex", "myHTTPServer", "my-http-server"},
{"acronym at end", "parseXML", "parse-xml"},
{"multiple acronyms", "XMLToJSON", "xml-to-json"},
{"single letter words", "aBC", "a-bc"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := KebabCase(tt.input)
if result != tt.expected {
t.Errorf("KebabCase(%q) = %q, want %q", tt.input, result, tt.expected)
}
})
}
}