-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstrings_test.go
165 lines (146 loc) · 3.29 KB
/
strings_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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package nautilus
import (
"testing"
"github.com/stretchr/testify/assert"
)
var strs = []string{
"ExampleString",
"exampleString",
"example_string",
"Example_String",
"EXAMPLE_STRING",
"example string",
"Example string",
"Example String",
"EXAMPLE STRING",
"ExampleString2",
"exampleString2",
"example_string2",
"example_string_2",
"Example_String2",
"Example_String_2",
"EXAMPLE_STRING2",
"EXAMPLE_STRING_2",
"example string 2",
"example string2",
"Example string 2",
"Example string2",
"Example String 2",
"Example String2",
"EXAMPLE STRING 2",
"EXAMPLE STRING2",
}
var pascalResult = "ExampleString"
var pascalResultWithNum = "ExampleString2"
var camelResult = "exampleString"
var camelResultWithNum = "exampleString2"
var snakeResult = "example_string"
var snakeResultWithNum = "example_string_2"
var screamSnakeResult = "EXAMPLE_STRING"
var screamSnakeResultWithNum = "EXAMPLE_STRING_2"
var kebabResult = "example-string"
var kebabResultWithNum = "example-string-2"
var screamKebabResult = "EXAMPLE-STRING"
var screamKebabResultWithNum = "EXAMPLE-STRING-2"
var words = map[string]string{
"star": "stars",
"bus": "buses",
"mouse": "mice",
"query": "queries",
"agency": "agencies",
"movie": "movies",
"index": "indices",
"wife": "wives",
"safe": "saves",
"half": "halves",
"salesperson": "salespeople",
"person": "people",
"spokesman": "spokesmen",
"man": "men",
"woman": "women",
"basis": "bases",
"datum": "data",
"medium": "media",
"analysis": "analyses",
"child": "children",
"news": "news",
"series": "series",
"ox": "oxen",
"photo": "photos",
"buffalo": "buffaloes",
"elf": "elves",
"information": "information",
"equipment": "equipment",
}
func TestToPascal(t *testing.T) {
for i, str := range strs {
rs := ToPascal(str)
if i < 9 {
assert.Equal(t, pascalResult, rs)
} else {
assert.Equal(t, pascalResultWithNum, rs)
}
}
}
func TestToCamel(t *testing.T) {
for i, str := range strs {
rs := ToCamel(str)
if i < 9 {
assert.Equal(t, camelResult, rs)
} else {
assert.Equal(t, camelResultWithNum, rs)
}
}
}
func TestToSnake(t *testing.T) {
for i, str := range strs {
rs := ToSnake(str)
if i < 9 {
assert.Equal(t, snakeResult, rs)
} else {
assert.Equal(t, snakeResultWithNum, rs)
}
}
}
func TestToScreamingSnake(t *testing.T) {
for i, str := range strs {
rs := ToScreamingSnake(str)
if i < 9 {
assert.Equal(t, screamSnakeResult, rs)
} else {
assert.Equal(t, screamSnakeResultWithNum, rs)
}
}
}
func TestToKebab(t *testing.T) {
for i, str := range strs {
rs := ToKebab(str)
if i < 9 {
assert.Equal(t, kebabResult, rs)
} else {
assert.Equal(t, kebabResultWithNum, rs)
}
}
}
func TestToScreamingKebab(t *testing.T) {
for i, str := range strs {
rs := ToScreamingKebab(str)
if i < 9 {
assert.Equal(t, screamKebabResult, rs)
} else {
assert.Equal(t, screamKebabResultWithNum, rs)
}
}
}
func TestPlural(t *testing.T) {
for singular, plural := range words {
res := Plural(singular)
assert.Equal(t, plural, res)
}
}
func TestSingular(t *testing.T) {
for singular, plural := range words {
res := Singular(plural)
assert.Equal(t, singular, res)
}
}