ripple 0.2.124 → 0.2.125

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,382 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import * as patterns from '../../src/utils/patterns.js';
3
+
4
+ describe('patterns utility', () => {
5
+ describe('regex_whitespace', () => {
6
+ it('should match single whitespace characters', () => {
7
+ expect(patterns.regex_whitespace.test(' ')).toBe(true);
8
+ expect(patterns.regex_whitespace.test('\t')).toBe(true);
9
+ expect(patterns.regex_whitespace.test('\n')).toBe(true);
10
+ expect(patterns.regex_whitespace.test('\r')).toBe(true);
11
+ });
12
+
13
+ it('should match whitespace character between characters', () => {
14
+ expect(patterns.regex_whitespace.test('a b')).toBe(true);
15
+ expect(patterns.regex_whitespace.test('a\tb')).toBe(true);
16
+ expect(patterns.regex_whitespace.test('a\nb')).toBe(true);
17
+ });
18
+
19
+ it('should match whitespace at start or end', () => {
20
+ expect(patterns.regex_whitespace.test(' hello')).toBe(true);
21
+ expect(patterns.regex_whitespace.test('hello ')).toBe(true);
22
+ expect(patterns.regex_whitespace.test('\thello')).toBe(true);
23
+ expect(patterns.regex_whitespace.test('hello\t')).toBe(true);
24
+ });
25
+
26
+ it('should match multiple whitespace characters', () => {
27
+ expect(patterns.regex_whitespace.test(' ')).toBe(true);
28
+ expect(patterns.regex_whitespace.test('\t\r\n ')).toBe(true);
29
+ });
30
+
31
+ it('should not match non-whitespace', () => {
32
+ expect(patterns.regex_whitespace.test('helloworld')).toBe(false);
33
+ expect(patterns.regex_whitespace.test('1')).toBe(false);
34
+ });
35
+
36
+ it('should not match empty string', () => {
37
+ expect(patterns.regex_whitespace.test('')).toBe(false);
38
+ });
39
+ });
40
+
41
+ describe('regex_whitespaces', () => {
42
+ it('should match multiple whitespace characters', () => {
43
+ expect(patterns.regex_whitespaces.test(' ')).toBe(true);
44
+ expect(patterns.regex_whitespaces.test('\t\t')).toBe(true);
45
+ expect(patterns.regex_whitespaces.test(' \t\n')).toBe(true);
46
+ });
47
+
48
+ it('should match single whitespace character', () => {
49
+ expect(patterns.regex_whitespaces.test(' ')).toBe(true);
50
+ expect(patterns.regex_whitespaces.test('\t')).toBe(true);
51
+ expect(patterns.regex_whitespaces.test('\n')).toBe(true);
52
+ });
53
+
54
+ it('should match whitespaces between characters', () => {
55
+ expect(patterns.regex_whitespaces.test('a b')).toBe(true);
56
+ expect(patterns.regex_whitespaces.test('a\t\r\nb')).toBe(true);
57
+ expect(patterns.regex_whitespaces.test('a\nb')).toBe(true);
58
+ });
59
+
60
+ it('should match whitespaces at start or end', () => {
61
+ expect(patterns.regex_whitespaces.test(' hello')).toBe(true);
62
+ expect(patterns.regex_whitespaces.test('hello \n')).toBe(true);
63
+ expect(patterns.regex_whitespaces.test('\t\rhello')).toBe(true);
64
+ expect(patterns.regex_whitespaces.test('hello\t ')).toBe(true);
65
+ });
66
+
67
+ it('should not match non-whitespace', () => {
68
+ expect(patterns.regex_whitespaces.test('helloworld')).toBe(false);
69
+ expect(patterns.regex_whitespaces.test('1')).toBe(false);
70
+ });
71
+
72
+ it('should not match empty string', () => {
73
+ expect(patterns.regex_whitespaces.test('')).toBe(false);
74
+ });
75
+ });
76
+
77
+ describe('regex_starts_with_newline', () => {
78
+ it('should match strings starting with newline', () => {
79
+ expect(patterns.regex_starts_with_newline.test('\nhello')).toBe(true);
80
+ expect(patterns.regex_starts_with_newline.test('\r\nworld')).toBe(true);
81
+ });
82
+
83
+ it('should match strings with only newline', () => {
84
+ expect(patterns.regex_starts_with_newline.test('\n')).toBe(true);
85
+ expect(patterns.regex_starts_with_newline.test('\r\n')).toBe(true);
86
+ });
87
+
88
+ it('should not match empty string', () => {
89
+ expect(patterns.regex_starts_with_newline.test('')).toBe(false);
90
+ });
91
+
92
+ it('should not match strings without leading newline', () => {
93
+ expect(patterns.regex_starts_with_newline.test('hello\n')).toBe(false);
94
+ expect(patterns.regex_starts_with_newline.test(' \nhello')).toBe(false);
95
+ });
96
+ });
97
+
98
+ describe('regex_starts_with_whitespace', () => {
99
+ it('should match strings starting with whitespace', () => {
100
+ expect(patterns.regex_starts_with_whitespace.test(' hello')).toBe(true);
101
+ expect(patterns.regex_starts_with_whitespace.test('\thello')).toBe(true);
102
+ expect(patterns.regex_starts_with_whitespace.test('\nhello')).toBe(true);
103
+ });
104
+
105
+ it('should match strings starting with multiple whitespaces', () => {
106
+ expect(patterns.regex_starts_with_whitespace.test(' hello')).toBe(true);
107
+ expect(patterns.regex_starts_with_whitespace.test('\t\nhello')).toBe(true);
108
+ });
109
+
110
+ it('should match strings with only whitespace', () => {
111
+ expect(patterns.regex_starts_with_whitespace.test(' ')).toBe(true);
112
+ expect(patterns.regex_starts_with_whitespace.test('\t\n\r')).toBe(true);
113
+ });
114
+
115
+ it('should not match empty string', () => {
116
+ expect(patterns.regex_starts_with_whitespace.test('')).toBe(false);
117
+ });
118
+
119
+ it('should not match strings without leading whitespace', () => {
120
+ expect(patterns.regex_starts_with_whitespace.test('hello ')).toBe(false);
121
+ });
122
+ });
123
+
124
+ describe('regex_starts_with_whitespaces', () => {
125
+ it('should match strings starting with a single whitespace', () => {
126
+ expect(patterns.regex_starts_with_whitespaces.test(' hello')).toBe(true);
127
+ expect(patterns.regex_starts_with_whitespaces.test('\thello')).toBe(true);
128
+ expect(patterns.regex_starts_with_whitespaces.test('\nhello')).toBe(true);
129
+ });
130
+
131
+ it('should match strings starting with multiple whitespaces', () => {
132
+ expect(patterns.regex_starts_with_whitespaces.test(' hello')).toBe(true);
133
+ expect(patterns.regex_starts_with_whitespaces.test('\t\nhello')).toBe(true);
134
+ });
135
+
136
+ it('should match strings with only whitespace', () => {
137
+ expect(patterns.regex_starts_with_whitespaces.test(' ')).toBe(true);
138
+ expect(patterns.regex_starts_with_whitespaces.test('\t\n\r')).toBe(true);
139
+ });
140
+
141
+ it('should not match empty string', () => {
142
+ expect(patterns.regex_starts_with_whitespaces.test('')).toBe(false);
143
+ });
144
+
145
+ it('should not match strings without leading whitespace', () => {
146
+ expect(patterns.regex_starts_with_whitespaces.test('hello ')).toBe(false);
147
+ expect(patterns.regex_starts_with_whitespaces.test('a b c ')).toBe(false);
148
+ });
149
+ });
150
+
151
+ describe('regex_ends_with_whitespace', () => {
152
+ it('should match strings ending with whitespace', () => {
153
+ expect(patterns.regex_ends_with_whitespace.test('hello ')).toBe(true);
154
+ expect(patterns.regex_ends_with_whitespace.test('hello\t')).toBe(true);
155
+ expect(patterns.regex_ends_with_whitespace.test('hello\n')).toBe(true);
156
+ });
157
+
158
+ it('should match strings ending with multiple whitespaces', () => {
159
+ expect(patterns.regex_ends_with_whitespace.test('hello ')).toBe(true);
160
+ expect(patterns.regex_ends_with_whitespace.test('hello\t\n')).toBe(true);
161
+ });
162
+
163
+ it('should match strings with only whitespace', () => {
164
+ expect(patterns.regex_ends_with_whitespace.test(' ')).toBe(true);
165
+ expect(patterns.regex_ends_with_whitespace.test('\t\n\r')).toBe(true);
166
+ });
167
+
168
+ it('should not match empty string', () => {
169
+ expect(patterns.regex_ends_with_whitespace.test('')).toBe(false);
170
+ });
171
+
172
+ it('should not match strings without trailing whitespace', () => {
173
+ expect(patterns.regex_ends_with_whitespace.test(' hello')).toBe(false);
174
+ expect(patterns.regex_ends_with_whitespace.test('hello')).toBe(false);
175
+ });
176
+ });
177
+
178
+ describe('regex_ends_with_whitespaces', () => {
179
+ it('should match strings ending with multiple whitespaces', () => {
180
+ expect(patterns.regex_ends_with_whitespaces.test('hello ')).toBe(true);
181
+ expect(patterns.regex_ends_with_whitespaces.test('hello\t\n')).toBe(true);
182
+ });
183
+
184
+ it('should match strings with only whitespaces', () => {
185
+ expect(patterns.regex_ends_with_whitespaces.test(' ')).toBe(true);
186
+ expect(patterns.regex_ends_with_whitespaces.test('\t\n\r')).toBe(true);
187
+ });
188
+
189
+ it('should not match empty string', () => {
190
+ expect(patterns.regex_ends_with_whitespaces.test('')).toBe(false);
191
+ });
192
+
193
+ it('should not match strings not ending with whitespaces', () => {
194
+ expect(patterns.regex_ends_with_whitespaces.test(' hello')).toBe(false);
195
+ expect(patterns.regex_ends_with_whitespaces.test('hello')).toBe(false);
196
+ expect(patterns.regex_ends_with_whitespaces.test('hello')).toBe(false);
197
+ expect(patterns.regex_ends_with_whitespaces.test('a b\nc')).toBe(false);
198
+ });
199
+ });
200
+
201
+ describe('regex_not_whitespace', () => {
202
+ it('should match non-whitespace characters', () => {
203
+ expect(patterns.regex_not_whitespace.test('a')).toBe(true);
204
+ expect(patterns.regex_not_whitespace.test('1')).toBe(true);
205
+ expect(patterns.regex_not_whitespace.test('hello world')).toBe(true);
206
+ });
207
+
208
+ it('should not match empty string', () => {
209
+ expect(patterns.regex_not_whitespace.test('')).toBe(false);
210
+ });
211
+
212
+ it('should not match only whitespace', () => {
213
+ expect(patterns.regex_not_whitespace.test(' ')).toBe(false);
214
+ expect(patterns.regex_not_whitespace.test('\t\n\r')).toBe(false);
215
+ });
216
+ });
217
+
218
+ describe('regex_only_whitespaces', () => {
219
+ it('should match strings with only whitespaces', () => {
220
+ expect(patterns.regex_only_whitespaces.test(' ')).toBe(true);
221
+ expect(patterns.regex_only_whitespaces.test('\t\n\r\f')).toBe(true);
222
+ });
223
+
224
+ it('should not match empty string', () => {
225
+ expect(patterns.regex_only_whitespaces.test('')).toBe(false);
226
+ });
227
+
228
+ it('should not match strings with content', () => {
229
+ expect(patterns.regex_only_whitespaces.test(' a ')).toBe(false);
230
+ expect(patterns.regex_only_whitespaces.test('hello')).toBe(false);
231
+ });
232
+ });
233
+
234
+ describe('regex_is_valid_identifier', () => {
235
+ it('should match valid JavaScript identifiers', () => {
236
+ expect(patterns.regex_is_valid_identifier.test('foo')).toBe(true);
237
+ expect(patterns.regex_is_valid_identifier.test('_private')).toBe(true);
238
+ expect(patterns.regex_is_valid_identifier.test('$jquery')).toBe(true);
239
+ expect(patterns.regex_is_valid_identifier.test('myVar123')).toBe(true);
240
+ expect(patterns.regex_is_valid_identifier.test('CamelCase')).toBe(true);
241
+ });
242
+
243
+ it('should not match invalid identifiers', () => {
244
+ expect(patterns.regex_is_valid_identifier.test('123abc')).toBe(false);
245
+ expect(patterns.regex_is_valid_identifier.test('my-var')).toBe(false);
246
+ expect(patterns.regex_is_valid_identifier.test('my var')).toBe(false);
247
+ expect(patterns.regex_is_valid_identifier.test('my.var')).toBe(false);
248
+ expect(patterns.regex_is_valid_identifier.test('')).toBe(false);
249
+ expect(patterns.regex_is_valid_identifier.test('\n')).toBe(false);
250
+ expect(patterns.regex_is_valid_identifier.test('my\tvar')).toBe(false);
251
+ expect(patterns.regex_is_valid_identifier.test('my\rvar')).toBe(false);
252
+ });
253
+ });
254
+
255
+ describe('regex_invalid_identifier_chars', () => {
256
+ it('should remove invalid identifier characters', () => {
257
+ expect('123abc'.replace(patterns.regex_invalid_identifier_chars, '_')).toBe('_23abc');
258
+ expect('my-var'.replace(patterns.regex_invalid_identifier_chars, '_')).toBe('my_var');
259
+ expect('hello.world'.replace(patterns.regex_invalid_identifier_chars, '_')).toBe('hello_world');
260
+ expect('\t\r\nhello.world'.replace(patterns.regex_invalid_identifier_chars, '_')).toBe('___hello_world');
261
+ expect('my\tvar'.replace(patterns.regex_invalid_identifier_chars, '_')).toBe('my_var');
262
+ expect('my\rvar'.replace(patterns.regex_invalid_identifier_chars, '_')).toBe('my_var');
263
+ expect(''.replace(patterns.regex_invalid_identifier_chars, '_')).toBe('');
264
+ });
265
+ });
266
+
267
+ describe('regex_starts_with_vowel', () => {
268
+ it('should match strings starting with vowels', () => {
269
+ expect(patterns.regex_starts_with_vowel.test('apple')).toBe(true);
270
+ expect(patterns.regex_starts_with_vowel.test('elephant')).toBe(true);
271
+ expect(patterns.regex_starts_with_vowel.test('ice')).toBe(true);
272
+ expect(patterns.regex_starts_with_vowel.test('orange')).toBe(true);
273
+ expect(patterns.regex_starts_with_vowel.test('umbrella')).toBe(true);
274
+ });
275
+
276
+ it('should not match strings starting with consonants', () => {
277
+ expect(patterns.regex_starts_with_vowel.test('banana')).toBe(false);
278
+ expect(patterns.regex_starts_with_vowel.test('cat')).toBe(false);
279
+ expect(patterns.regex_starts_with_vowel.test('d')).toBe(false);
280
+ expect(patterns.regex_starts_with_vowel.test('f')).toBe(false);
281
+ expect(patterns.regex_starts_with_vowel.test('g')).toBe(false);
282
+ expect(patterns.regex_starts_with_vowel.test('hello')).toBe(false);
283
+ expect(patterns.regex_starts_with_vowel.test('j')).toBe(false);
284
+ expect(patterns.regex_starts_with_vowel.test('k')).toBe(false);
285
+ expect(patterns.regex_starts_with_vowel.test('l')).toBe(false);
286
+ expect(patterns.regex_starts_with_vowel.test('m')).toBe(false);
287
+ expect(patterns.regex_starts_with_vowel.test('n')).toBe(false);
288
+ expect(patterns.regex_starts_with_vowel.test('p')).toBe(false);
289
+ expect(patterns.regex_starts_with_vowel.test('q')).toBe(false);
290
+ expect(patterns.regex_starts_with_vowel.test('r')).toBe(false);
291
+ expect(patterns.regex_starts_with_vowel.test('s')).toBe(false);
292
+ expect(patterns.regex_starts_with_vowel.test('t')).toBe(false);
293
+ expect(patterns.regex_starts_with_vowel.test('v')).toBe(false);
294
+ expect(patterns.regex_starts_with_vowel.test('w')).toBe(false);
295
+ expect(patterns.regex_starts_with_vowel.test('x')).toBe(false);
296
+ expect(patterns.regex_starts_with_vowel.test('y')).toBe(false);
297
+ expect(patterns.regex_starts_with_vowel.test('z')).toBe(false);
298
+ });
299
+
300
+ it('should be case-sensitive', () => {
301
+ expect(patterns.regex_starts_with_vowel.test('Apple')).toBe(false);
302
+ });
303
+ });
304
+
305
+ describe('regex_heading_tags', () => {
306
+ it('should match heading tags h1 through h6', () => {
307
+ expect(patterns.regex_heading_tags.test('h1')).toBe(true);
308
+ expect(patterns.regex_heading_tags.test('h2')).toBe(true);
309
+ expect(patterns.regex_heading_tags.test('h3')).toBe(true);
310
+ expect(patterns.regex_heading_tags.test('h4')).toBe(true);
311
+ expect(patterns.regex_heading_tags.test('h5')).toBe(true);
312
+ expect(patterns.regex_heading_tags.test('h6')).toBe(true);
313
+ });
314
+
315
+ it('should not match invalid heading tags', () => {
316
+ expect(patterns.regex_heading_tags.test('h0')).toBe(false);
317
+ expect(patterns.regex_heading_tags.test('h7')).toBe(false);
318
+ expect(patterns.regex_heading_tags.test('H1')).toBe(false);
319
+ expect(patterns.regex_heading_tags.test('header')).toBe(false);
320
+ expect(patterns.regex_heading_tags.test('h')).toBe(false);
321
+ });
322
+ });
323
+
324
+ describe('regex_illegal_attribute_character', () => {
325
+ it('should match illegal attribute characters', () => {
326
+ expect(patterns.regex_illegal_attribute_character.test('123')).toBe(true);
327
+ expect(patterns.regex_illegal_attribute_character.test('.class')).toBe(true);
328
+ expect(patterns.regex_illegal_attribute_character.test('-attr')).toBe(true);
329
+ expect(patterns.regex_illegal_attribute_character.test('attr^')).toBe(true);
330
+ expect(patterns.regex_illegal_attribute_character.test('attr$')).toBe(true);
331
+ expect(patterns.regex_illegal_attribute_character.test('attr@')).toBe(true);
332
+ expect(patterns.regex_illegal_attribute_character.test('attr%')).toBe(true);
333
+ expect(patterns.regex_illegal_attribute_character.test('attr&')).toBe(true);
334
+ expect(patterns.regex_illegal_attribute_character.test('attr#')).toBe(true);
335
+ expect(patterns.regex_illegal_attribute_character.test('attr?')).toBe(true);
336
+ expect(patterns.regex_illegal_attribute_character.test('attr!')).toBe(true);
337
+ expect(patterns.regex_illegal_attribute_character.test('attr|')).toBe(true);
338
+ expect(patterns.regex_illegal_attribute_character.test('attr[')).toBe(true);
339
+ expect(patterns.regex_illegal_attribute_character.test('attr]')).toBe(true);
340
+ expect(patterns.regex_illegal_attribute_character.test('attr{')).toBe(true);
341
+ expect(patterns.regex_illegal_attribute_character.test('attr}')).toBe(true);
342
+ expect(patterns.regex_illegal_attribute_character.test('attr*')).toBe(true);
343
+ expect(patterns.regex_illegal_attribute_character.test('attr+')).toBe(true);
344
+ expect(patterns.regex_illegal_attribute_character.test('attr~')).toBe(true);
345
+ expect(patterns.regex_illegal_attribute_character.test('attr;')).toBe(true);
346
+ });
347
+
348
+ it('should not match valid attribute names', () => {
349
+ expect(patterns.regex_illegal_attribute_character.test('id')).toBe(false);
350
+ expect(patterns.regex_illegal_attribute_character.test('class')).toBe(false);
351
+ expect(patterns.regex_illegal_attribute_character.test('className')).toBe(false);
352
+ expect(patterns.regex_illegal_attribute_character.test('className123')).toBe(false);
353
+ expect(patterns.regex_illegal_attribute_character.test('class-name-123')).toBe(false);
354
+ expect(patterns.regex_illegal_attribute_character.test('data-value')).toBe(false);
355
+ expect(patterns.regex_illegal_attribute_character.test('aria-label')).toBe(false);
356
+ });
357
+ });
358
+
359
+ describe('regex_newline_characters', () => {
360
+ it('should match newline characters globally', () => {
361
+ const text = 'line1\nline2\nline3';
362
+ const matches = text.match(patterns.regex_newline_characters);
363
+ expect(matches?.length).toBe(2);
364
+ });
365
+ });
366
+
367
+ describe('regex_not_newline_characters', () => {
368
+ it('should match non-newline characters globally', () => {
369
+ const text = 'ab\ncd';
370
+ const matches = text.match(patterns.regex_not_newline_characters);
371
+ expect(matches?.length).toBe(4);
372
+ });
373
+ });
374
+
375
+ describe('regex_whitespaces_strict', () => {
376
+ it('should match strict whitespace sequences globally', () => {
377
+ const text = 'a b\tc d';
378
+ const result = text.replace(patterns.regex_whitespaces_strict, '-');
379
+ expect(result).toBe('a-b-c-d');
380
+ });
381
+ });
382
+ });
@@ -0,0 +1,51 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { sanitize_template_string } from '../../src/utils/sanitize_template_string.js';
3
+
4
+ describe('sanitize_template_string utility', () => {
5
+ it('should escape backticks', () => {
6
+ expect(sanitize_template_string('hello `world`')).toBe('hello \\`world\\`');
7
+ });
8
+
9
+ it('should escape dollar brace sequences', () => {
10
+ expect(sanitize_template_string('hello ${world}')).toBe('hello \\${world}');
11
+ });
12
+
13
+ it('should escape backslashes', () => {
14
+ expect(sanitize_template_string('hello \\ world')).toBe('hello \\\\ world');
15
+ });
16
+
17
+ it('should escape all special characters together', () => {
18
+ expect(sanitize_template_string('`${test}\\`')).toBe('\\`\\${test}\\\\\\`');
19
+ });
20
+
21
+ it('should handle strings with no special characters', () => {
22
+ expect(sanitize_template_string('hello world')).toBe('hello world');
23
+ });
24
+
25
+ it('should handle empty strings', () => {
26
+ expect(sanitize_template_string('')).toBe('');
27
+ });
28
+
29
+ it('should escape multiple backticks', () => {
30
+ expect(sanitize_template_string('```')).toBe('\\`\\`\\`');
31
+ });
32
+
33
+ it('should escape multiple dollar braces', () => {
34
+ expect(sanitize_template_string('${a}${b}${c}')).toBe('\\${a}\\${b}\\${c}');
35
+ });
36
+
37
+ it('should escape multiple backslashes', () => {
38
+ expect(sanitize_template_string('\\\\\\')).toBe('\\\\\\\\\\\\');
39
+ });
40
+
41
+ it('should handle mixed content', () => {
42
+ expect(sanitize_template_string('Path: C:\\Users\\${name}`')).toBe('Path: C:\\\\Users\\\\\\${name}\\`');
43
+ });
44
+
45
+ it('should handle complex template literals', () => {
46
+ const input = 'const str = `Hello ${name}, path: \\${root}\\`';
47
+ const expected = 'const str = \\`Hello \\${name}, path: \\\\\\${root}\\\\\\`';
48
+ expect(sanitize_template_string(input)).toBe(expected);
49
+ });
50
+ });
51
+