-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.test.ts
More file actions
223 lines (178 loc) · 4.45 KB
/
index.test.ts
File metadata and controls
223 lines (178 loc) · 4.45 KB
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
import {
default as casify,
camelCasify,
bumpyCasify,
kebabCasify,
snakeCasify,
startCasify,
upperCasify,
lowerCasify,
} from './dist';
// Test utils
function generateObject(obj: object, fn: Function, re: RegExp) {
return {
snake_case: true,
'kebab-case': 1000,
camelCase: 'camelCase',
BumpyCase: 11.99,
'Start Case': obj,
'UPPER CASE': fn,
'lower case': re,
};
}
function generateArray() {
return [
{ cat_name: 'Max', 'dog name': 'Jellybean', 'NUM PETS': 36 },
{ cat_name: 'Leo', 'dog name': 'Archer', 'NUM PETS': 5 },
{ cat_name: 'Dalton', 'dog name': 'Skip', 'NUM PETS': 18 },
];
}
function prependBlueCase(input: string) {
return `blue_${input}`;
}
it('camelCasify - handles objects', () => {
const obj = {};
const fn = () => {};
const re = /casify/ig;
const input = generateObject(obj, fn, re);
const expected = {
snakeCase: true,
kebabCase: 1000,
camelCase: 'camelCase',
bumpyCase: 11.99,
startCase: obj,
upperCase: fn,
lowerCase: re,
};
const observed = camelCasify(input);
expect(expected).toEqual(observed);
});
it('bumpyCasify - handles objects', () => {
const obj = {};
const fn = () => {};
const re = /casify/ig;
const input = generateObject(obj, fn, re);
const expected = {
SnakeCase: true,
KebabCase: 1000,
CamelCase: 'camelCase',
BumpyCase: 11.99,
StartCase: obj,
UpperCase: fn,
LowerCase: re,
};
const observed = bumpyCasify(input);
expect(expected).toEqual(observed);
});
it('kebabCasify - handles objects', () => {
const obj = {};
const fn = () => {};
const re = /casify/ig;
const input = generateObject(obj, fn, re);
const expected = {
'snake-case': true,
'kebab-case': 1000,
'camel-case': 'camelCase',
'bumpy-case': 11.99,
'start-case': obj,
'upper-case': fn,
'lower-case': re,
};
const observed = kebabCasify(input);
expect(expected).toEqual(observed);
});
it('snakeCasify - handles objects', () => {
const obj = {};
const fn = () => {};
const re = /casify/ig;
const input = generateObject(obj, fn, re);
const expected = {
snake_case: true,
kebab_case: 1000,
camel_case: 'camelCase',
bumpy_case: 11.99,
start_case: obj,
upper_case: fn,
lower_case: re,
};
const observed = snakeCasify(input);
expect(expected).toEqual(observed);
});
it('startCasify - handles objects', () => {
const obj = {};
const fn = () => {};
const re = /casify/ig;
const input = generateObject(obj, fn, re);
const expected = {
'Snake Case': true,
'Kebab Case': 1000,
'Camel Case': 'camelCase',
'Bumpy Case': 11.99,
'Start Case': obj,
'UPPER CASE': fn,
'Lower Case': re,
};
const observed = startCasify(input);
expect(expected).toEqual(observed);
});
it('upperCasify - handles objects', () => {
const obj = {};
const fn = () => {};
const re = /casify/ig;
const input = generateObject(obj, fn, re);
const expected = {
'SNAKE CASE': true,
'KEBAB CASE': 1000,
'CAMEL CASE': 'camelCase',
'BUMPY CASE': 11.99,
'START CASE': obj,
'UPPER CASE': fn,
'LOWER CASE': re,
};
const observed = upperCasify(input);
expect(expected).toEqual(observed);
});
it('lowerCasify - handles objects', () => {
const obj = {};
const fn = () => {};
const re = /casify/ig;
const input = generateObject(obj, fn, re);
const expected = {
'snake case': true,
'kebab case': 1000,
'camel case': 'camelCase',
'bumpy case': 11.99,
'start case': obj,
'upper case': fn,
'lower case': re,
};
const observed = lowerCasify(input);
expect(expected).toEqual(observed);
});
it('casify - handles objects', () => {
const obj = {};
const fn = () => {};
const re = /casify/ig;
const input = generateObject(obj, fn, re);
const expected = {
blue_snake_case: true,
'blue_kebab-case': 1000,
blue_camelCase: 'camelCase',
blue_BumpyCase: 11.99,
'blue_Start Case': obj,
'blue_UPPER CASE': fn,
'blue_lower case': re,
};
const observed = casify(prependBlueCase, input);
expect(expected).toEqual(observed);
});
it('camelCasify - handles arrays', () => {
const input = generateArray();
const expected = [
{ catName: 'Max', dogName: 'Jellybean', numPets: 36 },
{ catName: 'Leo', dogName: 'Archer', numPets: 5 },
{ catName: 'Dalton', dogName: 'Skip', numPets: 18 },
];
const observed = camelCasify(input);
expect(expected).toEqual(observed);
});