-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathcase_test.go
83 lines (73 loc) · 1.88 KB
/
case_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
package strutil
import (
"fmt"
"testing"
)
func TestToSnakeCase(t *testing.T) {
tests := []struct {
input string
expected string
}{
{"lorem", "lorem"},
{"lorem ipsum", "lorem_ipsum"},
{"Lorem Ipsum", "lorem_ipsum"},
{"", ""},
{" ", ""},
}
for i, test := range tests {
output := ToSnakeCase(test.input)
Assert(t, test.expected, output, "Test case %d is not successful\n", i)
}
}
func ExampleToSnakeCase() {
fmt.Println(ToSnakeCase("Lorem Ipsum"))
// Output: lorem_ipsum
}
func TestToCamelCase(t *testing.T) {
tests := []struct {
input string
expected string
}{
{"lorem", "lorem"},
{"lorem ipsum", "loremIpsum"},
{"Lorem Ipsum", "LoremIpsum"},
{"bay ğ", "bayĞ"},
{"", ""},
{" ", ""},
}
for i, test := range tests {
output := ToCamelCase(test.input)
Assert(t, test.expected, output, "Test case %d is not successful\n", i)
}
}
func ExampleToCamelCase() {
fmt.Println(ToCamelCase("long live motörhead"))
//Output: longLiveMotörhead
}
func TestSplitCamelCase(t *testing.T) {
tests := []struct {
input string
expected []string
}{
{"lorem", []string{"lorem"}},
{"loremIpsum", []string{"lorem", "Ipsum"}},
{"binaryJSONAbstractWriter", []string{"binary", "JSON", "Abstract", "Writer"}},
{"bayĞe", []string{"bay", "Ğe"}},
{"", []string{""}},
{" ", []string{""}},
{"HTML", []string{"HTML"}},
{"AClass", []string{"A", "Class"}},
{"year2000", []string{"year", "2000"}},
{"year2000OfWorld", []string{"year", "2000", "Of", "World"}},
{"year2000s", []string{"year", "2000s"}},
{"yearX2000s", []string{"year", "X", "2000s"}},
}
for i, test := range tests {
output := SplitCamelCase(test.input)
Assert(t, test.expected, output, "Test case %d is not successful\n", i)
}
}
func ExampleSplitCamelCase() {
fmt.Printf("%#v\n", SplitCamelCase("binaryJSONAbstractWriter"))
// Output: []string{"binary", "JSON", "Abstract", "Writer"}
}