-
Notifications
You must be signed in to change notification settings - Fork 1
/
changecase_test.go
109 lines (96 loc) · 3.74 KB
/
changecase_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
package changecase
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestConstant(t *testing.T) {
assert.Equal(t, "TEST_STRING", Constant("testString"))
assert.Equal(t, "TEST_STRING", Constant("Test String"))
assert.Equal(t, "TEST_STRING", Constant("Test_String"))
assert.Equal(t, "TEST_STRING", Constant("Test-String"))
assert.Equal(t, "A_BETTER_TEST", Constant("a---better__test"))
}
func TestDot(t *testing.T) {
assert.Equal(t, "test.string", Dot("testString"))
assert.Equal(t, "test.string", Dot("Test String"))
assert.Equal(t, "test.string", Dot("Test_String"))
assert.Equal(t, "test.string", Dot("Test-String"))
assert.Equal(t, "a.better.test", Dot("a---better__test"))
}
func TestHeader(t *testing.T) {
assert.Equal(t, "A-Simple-Test", Header("a-simple-test"))
assert.Equal(t, "This-Is-A-Test", Header("this is a test"))
assert.Equal(t, "This-Is-A-Test", Header("this_is_a_test"))
assert.Equal(t, "This-Is-A-Test", Header("this-is-a-test"))
}
func TestIsLower(t *testing.T) {
assert.Equal(t, IsLower("ALLUPPERCASE"), false)
assert.Equal(t, IsLower("NotAllLowerCase"), false)
assert.Equal(t, IsLower("alllowercase"), true)
assert.Equal(t, IsLower(""), true)
}
func TestIsUpper(t *testing.T) {
assert.Equal(t, IsUpper("ALLUPPERCASE"), true)
assert.Equal(t, IsUpper("NotAllUpperCase"), false)
assert.Equal(t, IsUpper("alllowercase"), false)
assert.Equal(t, IsUpper(""), true)
}
func TestLower(t *testing.T) {
assert.Equal(t, "test", Lower("test"))
assert.Equal(t, "test", Lower("TEST"))
}
func TestLcFirst(t *testing.T) {
assert.Equal(t, "tEST", LcFirst("TEST"))
assert.Equal(t, "test", LcFirst("Test"))
}
func TestParam(t *testing.T) {
assert.Equal(t, "test-string", Param("testString"))
assert.Equal(t, "test-string", Param("Test String"))
assert.Equal(t, "test-string", Param("Test_String"))
assert.Equal(t, "test-string", Param("Test-String"))
assert.Equal(t, "a-better-test", Param("a---better__test"))
}
func TestPascal(t *testing.T) {
assert.Equal(t, "TestString", Pascal("testString"))
assert.Equal(t, "TestString", Pascal("Test String"))
assert.Equal(t, "TestString", Pascal("Test_String"))
assert.Equal(t, "TestString", Pascal("Test-String"))
assert.Equal(t, "FacebookApi", Pascal("Facebook API"))
assert.Equal(t, "ATestAgain", Pascal("a-test-again"))
assert.Equal(t, "ABetterTest", Pascal("a---better__test"))
}
func TestPath(t *testing.T) {
assert.Equal(t, "test/string", Path("testString"))
assert.Equal(t, "test/string", Path("Test String"))
assert.Equal(t, "test/string", Path("Test_String"))
assert.Equal(t, "test/string", Path("Test-String"))
assert.Equal(t, "a/better/test", Path("a---better__test"))
}
func TestSentence(t *testing.T) {
assert.Equal(t, "A simple test", Sentence("a-simple-test"))
assert.Equal(t, "This is a test", Sentence("this is a test"))
assert.Equal(t, "This is a test", Sentence("this_is_a_test"))
assert.Equal(t, "This is a test", Sentence("this-is-a-test"))
}
func TestSnake(t *testing.T) {
assert.Equal(t, "test_string", Snake("testString"))
assert.Equal(t, "test_string", Snake("Test String"))
assert.Equal(t, "test_string", Snake("Test_String"))
assert.Equal(t, "test_string", Snake("Test-String"))
assert.Equal(t, "a_better_test", Snake("a---better__test"))
}
func TestTitle(t *testing.T) {
assert.Equal(t, "A Test Sentence", Title("a test sentence"))
assert.Equal(t, "I Found A Bug", Title("i found a bug"))
assert.Equal(t, "Some Things", Title(`some things'`))
assert.Equal(t, "Quotes", Title(`"quotes"`))
assert.Equal(t, "Hyphen Ness", Title("hyphen-ness"))
}
func TestUpper(t *testing.T) {
assert.Equal(t, "TEST", Upper("TEST"))
assert.Equal(t, "TEST", Upper("test"))
}
func TestUcFirst(t *testing.T) {
assert.Equal(t, "TEST", UcFirst("TEST"))
assert.Equal(t, "Test", UcFirst("test"))
}