-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathcase-conversions.unit.test.ts
190 lines (149 loc) · 5.64 KB
/
case-conversions.unit.test.ts
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
import { describe, expect, it } from 'vitest';
import {
camelCaseToKebabCase,
capitalize,
kebabCaseToCamelCase,
toSentenceCase,
toTitleCase,
} from './case-conversions.js';
describe('capitalize', () => {
it('should transform the first string letter to upper case', () => {
expect(capitalize('code')).toBe('Code');
});
it('should lowercase all but the the first string letter', () => {
expect(capitalize('PushUp')).toBe('Pushup');
});
it('should leave the first string letter in upper case', () => {
expect(capitalize('Code')).toBe('Code');
});
it('should accept empty string', () => {
expect(capitalize('')).toBe('');
});
});
describe('kebabCaseToCamelCase', () => {
it('should convert simple kebab-case to camelCase', () => {
expect(kebabCaseToCamelCase('hello-world')).toBe('helloWorld');
});
it('should handle multiple hyphens', () => {
expect(kebabCaseToCamelCase('this-is-a-long-string')).toBe(
'thisIsALongString',
);
});
it('should preserve numbers', () => {
expect(kebabCaseToCamelCase('user-123-test')).toBe('user123Test');
});
it('should handle single word', () => {
expect(kebabCaseToCamelCase('hello')).toBe('hello');
});
it('should handle empty string', () => {
expect(kebabCaseToCamelCase('')).toBe('');
});
});
describe('camelCaseToKebabCase', () => {
it('should convert camelCase to kebab-case', () => {
expect(camelCaseToKebabCase('myTestString')).toBe('my-test-string');
});
it('should handle acronyms properly', () => {
expect(camelCaseToKebabCase('APIResponse')).toBe('api-response');
});
it('should handle consecutive uppercase letters correctly', () => {
expect(camelCaseToKebabCase('myXMLParser')).toBe('my-xml-parser');
});
it('should handle single-word camelCase', () => {
expect(camelCaseToKebabCase('singleWord')).toBe('single-word');
});
it('should not modify already kebab-case strings', () => {
expect(camelCaseToKebabCase('already-kebab')).toBe('already-kebab');
});
it('should not modify non-camelCase inputs', () => {
expect(camelCaseToKebabCase('not_camelCase')).toBe('not_camel-case');
});
});
describe('toTitleCase', () => {
it('should capitalize each word in a simple sentence', () => {
expect(toTitleCase('hello world')).toBe('Hello World');
});
it('should capitalize each word in a longer sentence', () => {
expect(toTitleCase('this is a title')).toBe('This Is a Title');
});
it('should convert PascalCase to title case', () => {
expect(toTitleCase('FormatToTitleCase')).toBe('Format to Title Case');
});
it('should convert camelCase to title case', () => {
expect(toTitleCase('thisIsTest')).toBe('This Is Test');
});
it('should convert kebab-case to title case', () => {
expect(toTitleCase('hello-world-example')).toBe('Hello World Example');
});
it('should convert snake_case to title case', () => {
expect(toTitleCase('snake_case_example')).toBe('Snake Case Example');
});
it('should capitalize a single word', () => {
expect(toTitleCase('hello')).toBe('Hello');
});
it('should handle numbers in words correctly', () => {
expect(toTitleCase('chapter1Introduction')).toBe('Chapter 1 Introduction');
});
it('should handle numbers in slugs correctly', () => {
expect(toTitleCase('version2Release')).toBe('Version 2 Release');
});
it('should handle acronyms properly', () => {
expect(toTitleCase('apiResponse')).toBe('Api Response');
});
it('should handle mixed-case inputs correctly', () => {
expect(toTitleCase('thisIs-mixed_CASE')).toBe('This Is Mixed CASE');
});
it('should not modify already formatted title case text', () => {
expect(toTitleCase('Hello World')).toBe('Hello World');
});
it('should return an empty string when given an empty input', () => {
expect(toTitleCase('')).toBe('');
});
});
describe('toSentenceCase', () => {
it('should convert a simple sentence to sentence case', () => {
expect(toSentenceCase('hello world')).toBe('Hello world');
});
it('should maintain a correctly formatted sentence', () => {
expect(toSentenceCase('This is a test')).toBe('This is a test');
});
it('should convert PascalCase to sentence case', () => {
expect(toSentenceCase('FormatToSentenceCase')).toBe(
'Format to sentence case',
);
});
it('should convert camelCase to sentence case', () => {
expect(toSentenceCase('thisIsTest')).toBe('This is test');
});
it('should convert kebab-case to sentence case', () => {
expect(toSentenceCase('hello-world-example')).toBe('Hello world example');
});
it('should convert snake_case to sentence case', () => {
expect(toSentenceCase('snake_case_example')).toBe('Snake case example');
});
it('should capitalize a single word', () => {
expect(toSentenceCase('hello')).toBe('Hello');
});
it('should handle numbers in words correctly', () => {
expect(toSentenceCase('chapter1Introduction')).toBe(
'Chapter 1 introduction',
);
});
it('should handle numbers in slugs correctly', () => {
expect(toSentenceCase('version2Release')).toBe('Version 2 release');
});
it('should handle acronyms properly', () => {
expect(toSentenceCase('apiResponse')).toBe('Api response');
});
it('should handle mixed-case inputs correctly', () => {
expect(toSentenceCase('thisIs-mixed_CASE')).toBe('This is mixed case');
});
it('should not modify already formatted sentence case text', () => {
expect(toSentenceCase('This is a normal sentence.')).toBe(
'This is a normal sentence.',
);
});
it('should return an empty string when given an empty input', () => {
expect(toSentenceCase('')).toBe('');
});
});