-
Notifications
You must be signed in to change notification settings - Fork 0
/
string-score.test.js
176 lines (170 loc) · 6.75 KB
/
string-score.test.js
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
166
167
168
169
170
171
172
173
174
175
176
const stringScore = require("./string-score");
describe("stringScore(str).lower", () => {
test.each([
["", 0], // Empty string.
["a", 1], // Single lower character.
["A", 0], // Single upper character.
["-", 0], // Single symbol.
["hello", 5], // All lower.
["world", 5], // All lower.
["Hello", 4], // Has uppercase in the beginning.
["hEllo", 4], // Has uppercase in between.
["hellO", 4], // Has uppercase in the end.
["hell-o", 5], // Has hyphen in between.
["-hello", 5], // Has hyphen in the beginning.
["hello-", 5], // Has hyphen in the end.
["hell_o", 5], // Has underscore in between.
["_hello", 5], // Has underscore in the beginning.
["hello_", 5], // Has underscore in the end.
["HELL_O", 0], // Has underscore in between.
["_HELLO", 0], // Has underscore in the beginning.
["HELLO_", 0] // Has underscore in the end.
])("stringScore(%s).lower returns %i", (str, expected) => {
expect(stringScore(str).lower).toEqual(expected);
});
});
describe("stringScore(str).upper", () => {
test.each([
["", 0], // Empty string.
["a", 0], // Single lower character.
["A", 1], // Single upper character.
["-", 0], // Single symbol.
["hello", 0], // All lower.
["world", 0], // All lower.
["Hello", 1], // Has uppercase in the beginning.
["hEllo", 1], // Has uppercase in between.
["hellO", 1], // Has uppercase in the end.
["hell-o", 0], // Has hyphen in between.
["-hello", 0], // Has hyphen in the beginning.
["hello-", 0], // Has hyphen in the end.
["HELLO", 5], // All upper.
["HELL-O", 5], // Has hyphen in between.
["-HELLO", 5], // Has hyphen in the beginning.
["HELLO-", 5], // Has hyphen in the end.
["hell_o", 0], // Has underscore in between.
["_hello", 0], // Has underscore in the beginning.
["hello_", 0], // Has underscore in the end.
["HELL_O", 5], // Has underscore in between.
["_HELLO", 5], // Has underscore in the beginning.
["HELLO_", 5] // Has underscore in the end.
])("stringScore(%s).upper returns %i", (str, expected) => {
expect(stringScore(str).upper).toEqual(expected);
});
});
describe("stringScore(str).pascal", () => {
test.each([
["", 0],
["", 0], // Empty string.
["a", 0], // Single lower character.
["A", 0], // Single upper character.
["-", 0], // Single symbol.
["hello", 0], // All lower.
["world", 0], // All lower.
["Hello", 1], // Has uppercase in the beginning.
["hEllo", 0], // Has uppercase in between.
["hellO", 0], // Has uppercase in the end.
["hell-o", 0], // Has hyphen in between.
["-hello", 0], // Has hyphen in the beginning.
["hello-", 0], // Has hyphen in the end.
["HELLO", 0], // All upper.
["HELL-O", 0], // Has hyphen in between.
["-HELLO", 0], // Has hyphen in the beginning.
["HELLO-", 0], // Has hyphen in the end.
["hell_o", 0], // Has underscore in between.
["_hello", 0], // Has underscore in the beginning.
["hello_", 0], // Has underscore in the end.
["HELL_O", 0], // Has underscore in between.
["_HELLO", 0], // Has underscore in the beginning.
["HELLO_", 0] // Has underscore in the end.
])("stringScore(%s).pascal returns %i", (str, expected) => {
expect(stringScore(str).pascal).toEqual(expected);
});
});
describe("stringScore(str).camel", () => {
test.each([
["", 0],
["", 0], // Empty string.
["a", 0], // Single lower character.
["A", 0], // Single upper character.
["-", 0], // Single symbol.
["hello", 0], // All lower.
["world", 0], // All lower.
["Hello", 0], // Has uppercase in the beginning.
["hEllo", 1], // Has uppercase in between.
["hellO", 1], // Has uppercase in the end.
["hell-o", 0], // Has hyphen in between.
["-hello", 0], // Has hyphen in the beginning.
["hello-", 0], // Has hyphen in the end.
["HELLO", 0], // All upper.
["HELL-O", 0], // Has hyphen in between.
["-HELLO", 0], // Has hyphen in the beginning.
["HELLO-", 0], // Has hyphen in the end.
["hell_o", 0], // Has underscore in between.
["_hello", 0], // Has underscore in the beginning.
["hello_", 0], // Has underscore in the end.
["HELL_O", 0], // Has underscore in between.
["_HELLO", 0], // Has underscore in the beginning.
["HELLO_", 0] // Has underscore in the end.
])("stringScore(%s).camel returns %i", (str, expected) => {
expect(stringScore(str).camel).toEqual(expected);
});
});
describe("stringScore(str).kebab", () => {
test.each([
["", 0],
["", 0], // Empty string.
["a", 0], // Single lower character.
["A", 0], // Single upper character.
["-", 1], // Single symbol.
["hello", 0], // All lower.
["world", 0], // All lower.
["Hello", 0], // Has uppercase in the beginning.
["hEllo", 0], // Has uppercase in between.
["hellO", 0], // Has uppercase in the end.
["hell-o", 1], // Has hyphen in between.
["-hello", 1], // Has hyphen in the beginning.
["hello-", 1], // Has hyphen in the end.
["HELLO", 0], // All upper.
["HELL-O", 1], // Has hyphen in between.
["-HELLO", 1], // Has hyphen in the beginning.
["HELLO-", 1], // Has hyphen in the end.
["hell_o", 0], // Has underscore in between.
["_hello", 0], // Has underscore in the beginning.
["hello_", 0], // Has underscore in the end.
["HELL_O", 0], // Has underscore in between.
["_HELLO", 0], // Has underscore in the beginning.
["HELLO_", 0] // Has underscore in the end.
])("stringScore(%s).kebab returns %i", (str, expected) => {
expect(stringScore(str).kebab).toEqual(expected);
});
});
describe("stringScore(str).snake", () => {
test.each([
["", 0],
["", 0], // Empty string.
["a", 0], // Single lower character.
["A", 0], // Single upper character.
["-", 0], // Single symbol.
["_", 1], // Single symbol.
["hello", 0], // All lower.
["world", 0], // All lower.
["Hello", 0], // Has uppercase in the beginning.
["hEllo", 0], // Has uppercase in between.
["hellO", 0], // Has uppercase in the end.
["hell-o", 0], // Has hyphen in between.
["-hello", 0], // Has hyphen in the beginning.
["hello-", 0], // Has hyphen in the end.
["HELLO", 0], // All upper.
["HELL-O", 0], // Has hyphen in between.
["-HELLO", 0], // Has hyphen in the beginning.
["HELLO-", 0], // Has hyphen in the end.
["hell_o", 1], // Has underscore in between.
["_hello", 1], // Has underscore in the beginning.
["hello_", 1], // Has underscore in the end.
["HELL_O", 1], // Has underscore in between.
["_HELLO", 1], // Has underscore in the beginning.
["HELLO_", 1] // Has underscore in the end.
])("stringScore(%s).snake returns %i", (str, expected) => {
expect(stringScore(str).snake).toEqual(expected);
});
});