-
Notifications
You must be signed in to change notification settings - Fork 1
/
string_funcs_test.go
94 lines (84 loc) · 2.38 KB
/
string_funcs_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
package templit_test
import (
"testing"
"github.com/euforic/templit"
"github.com/google/go-cmp/cmp"
)
// TestToCamelCase tests the ToCamelCase function.
func TestToCamelCase(t *testing.T) {
tests := []struct {
input string
output string
}{
{"hello world", "helloWorld"},
{"Hello World", "helloWorld"},
{"HELLO_WORLD", "helloWorld"},
{"XML HTTP_request2_a-b", "xmlHttpRequest2AB"},
}
for _, test := range tests {
result := templit.ToCamelCase(test.input)
if diff := cmp.Diff(test.output, result); diff != "" {
t.Errorf("toCamelCase(%s) mismatch (-want +got):\n%s", test.input, diff)
}
}
}
// TestToSnakeCase tests the ToSnakeCase function.
func TestToSnakeCase(t *testing.T) {
tests := []struct {
input string
output string
}{
{"hello world", "hello_world"},
{"Hello World", "hello_world"},
{"HELLO_WORLD", "hello_world"},
{"HelloWorld", "hello_world"},
{"HelloWorld Today", "hello_world_today"},
{"HelloWorld-today", "hello_world_today"},
{"XML HTTP_request2_a-b", "xml_http_request2_a_b"},
}
for _, test := range tests {
result := templit.ToSnakeCase(test.input)
if diff := cmp.Diff(test.output, result); diff != "" {
t.Errorf("ToSnakeCase(%s) mismatch (-want +got):\n%s", test.input, diff)
}
}
}
// TestToKebabCase tests the ToKebabCase function.
func TestToKebabCase(t *testing.T) {
tests := []struct {
input string
output string
}{
{"hello world", "hello-world"},
{"Hello World", "hello-world"},
{"HELLO_WORLD", "hello-world"},
{"HelloWorld", "hello-world"},
{"HelloWorld Today", "hello-world-today"},
{"HelloWorld-today", "hello-world-today"},
{"XML HTTP_request2_a-b", "xml-http-request2-a-b"},
}
for _, test := range tests {
result := templit.ToKebabCase(test.input)
if diff := cmp.Diff(test.output, result); diff != "" {
t.Errorf("ToKebabCase(%s) mismatch (-want +got):\n%s", test.input, diff)
}
}
}
// TestToPascalCase tests the ToPascalCase function.
func TestToPascalCase(t *testing.T) {
tests := []struct {
input string
output string
}{
{"hello world", "HelloWorld"},
{"Hello World", "HelloWorld"},
{"HELLO_WORLD", "HelloWorld"},
{"XML HTTP_request2_a-b", "XmlHttpRequest2AB"},
}
for _, test := range tests {
result := templit.ToPascalCase(test.input)
if diff := cmp.Diff(test.output, result); diff != "" {
t.Errorf("ToPascalCase(%s) mismatch (-want +got):\n%s", test.input, diff)
}
}
}