-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser_test.go
129 lines (117 loc) · 3.32 KB
/
parser_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
package strcase
import (
"testing"
"github.com/stretchr/testify/suite"
)
type parseTest struct {
suite.Suite
}
func Test_parse(t *testing.T) {
suite.Run(t, &parseTest{})
}
func (s parseTest) Test_parse_basic() {
expected := []string{"hello", "world"}
testCases := []string{
"hello world",
"hello-world",
"hello--world",
"hello_world",
"hello__world",
"helloWorld",
}
for _, testCase := range testCases {
s.EqualValues(expected, parse(testCase))
}
}
func (s parseTest) Test_parse_basic_edge() {
expected := []string{"h", "w"}
testCases := []string{
"h w",
"h-w",
"h--w",
"h_w",
"h__w",
"hW",
}
for _, testCase := range testCases {
s.EqualValues(expected, parse(testCase))
}
}
func (s parseTest) Test_parse_basic_edge_extneded() {
expected := []string{"whack", "a", "mole"}
testCases := []string{
"whack a mole",
"whack-a-mole",
"whack_a_mole",
"whackAMole",
}
for _, testCase := range testCases {
s.EqualValues(expected, parse(testCase))
}
}
func (s parseTest) Test_parse_edge() {
s.EqualValues([]string{"123"}, parse("123"))
s.EqualValues([]string{"1", "2", "3"}, parse("1-2-3"))
s.EqualValues([]string{"1", "2", "3"}, parse("1--2--3"))
s.EqualValues([]string{"1", "2", "3"}, parse("1__2__3"))
s.EqualValues([]string{"1", "2", "3"}, parse("1_-2_-3"), "wtf?")
s.EqualValues([]string{"1", "a2", "b3"}, parse("1a2b3"))
s.EqualValues([]string{"1", "plate", "of", "rice"}, parse("1plateOfRice"))
s.EqualValues([]string{"1", "of3", "plates"}, parse("1of3plates"))
s.EqualValues([]string{"1", "of", "3", "plates"}, parse("1of_3plates"))
s.EqualValues([]string{"1", "for1"}, parse("1for1"))
s.EqualValues([]string{"1", "for", "1"}, parse("1-for-1"))
s.EqualValues([]string{"1", "for", "1"}, parse("1-For-1"))
s.EqualValues([]string{"1", "for", "1"}, parse("1-FOR-1"))
s.EqualValues([]string{"7", "zip", "archive"}, parse("7zipArchive"))
s.EqualValues([]string{"7", "zip", "archive"}, parse("7zipArchive"))
}
func (s parseTest) Test_parse_extended() {
expected := []string{"one", "two", "three"}
testCases := []string{
"one two three",
"one-two-three",
"one--two--three",
"one_two_three",
"one__two__three",
"oneTwoThree",
}
for _, testCase := range testCases {
s.EqualValues(expected, parse(testCase))
}
}
func (s parseTest) Test_parse_extended_edge() {
expected := []string{"a", "b", "c"}
testCases := []string{
"a b c",
"a-b-c",
"a--b--c",
"a_b_c",
"a__b__c",
}
for _, testCase := range testCases {
s.EqualValues(expected, parse(testCase))
}
}
func (s parseTest) Test_parse_extensions() {
expected := []string{"send", "api", "request"}
testCases := []string{
"send API request",
"send-API-Request",
"send_API_Request",
"sendAPIRequest",
}
for _, testCase := range testCases {
s.EqualValues(expected, parse(testCase))
}
}
func (s parseTest) Test_isDelimiter() {
s.False(isDelimiter(typeLower, typeLower, typeInvalid),
"should see somethinglikethis as one word")
s.True(isDelimiter(typeAlpha|typeLower, typeAlpha|typeUpper, typeInvalid),
"should mark the end of a word like helloWorld")
s.True(isDelimiter(typeAlpha|typeUpper, typeAlpha|typeUpper, typeAlpha|typeLower),
"something like whackAMole should be 'whack a mole'")
s.True(isDelimiter(typeNumber, typeInvalid, typeInvalid),
"should see numbers as an end since variable names cannot start with a number")
}