2024-01-18 13:20:10 +02:00
|
|
|
const { friendlySafeFilename } = require('./path-utils');
|
2018-11-20 02:42:21 +02:00
|
|
|
|
2023-02-20 17:02:29 +02:00
|
|
|
describe('pathUtils', () => {
|
2018-11-20 02:42:21 +02:00
|
|
|
|
2020-12-01 20:05:24 +02:00
|
|
|
it('should create friendly safe filename', (async () => {
|
2018-11-20 02:42:21 +02:00
|
|
|
const testCases = [
|
|
|
|
['生活', '生活'],
|
|
|
|
['not/good', 'not_good'],
|
|
|
|
['really/not/good', 'really_not_good'],
|
|
|
|
['con', '___'],
|
|
|
|
['no space at the end ', 'no space at the end'],
|
|
|
|
['nor dots...', 'nor dots'],
|
2018-11-21 02:36:23 +02:00
|
|
|
[' no space before either', 'no space before either'],
|
2021-08-10 20:13:16 +02:00
|
|
|
['no\nnewline\n\rplease', 'no_newline__please'],
|
2020-09-07 23:12:51 +02:00
|
|
|
['thatsreallylongthatsreallylongthatsreallylongthatsreallylongthatsreallylongthatsreallylongthatsreallylongthatsreallylongthatsreallylongthatsreallylongthatsreallylongthatsreallylongthatsreallylongthatsreallylongthatsreallylongthatsreallylongthatsreallylongthatsreallylong', 'thatsreallylongthatsreallylongthatsreallylongthats'],
|
2018-11-20 02:42:21 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
for (let i = 0; i < testCases.length; i++) {
|
|
|
|
const t = testCases[i];
|
|
|
|
expect(friendlySafeFilename(t[0])).toBe(t[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(!!friendlySafeFilename('')).toBe(true);
|
|
|
|
expect(!!friendlySafeFilename('...')).toBe(true);
|
2021-08-10 20:13:16 +02:00
|
|
|
|
|
|
|
// Check that it optionally handles filenames with extension
|
2021-08-17 07:57:00 +02:00
|
|
|
expect(friendlySafeFilename('file', null, true)).toBe('file');
|
2021-08-10 20:13:16 +02:00
|
|
|
expect(friendlySafeFilename(' testing.md', null, true)).toBe('testing.md');
|
|
|
|
expect(friendlySafeFilename('testing.safe??ext##', null, true)).toBe('testing.safeext');
|
|
|
|
expect(friendlySafeFilename('thatsreallylongthatsreallylongthatsreallylongthatsreallylongthatsreallylongthatsreallylongthatsreallylongthatsreallylongthatsreallylongthatsreallylongthatsreallylongthatsreallylongthatsreallylongthatsreallylongthatsreallylongthatsreallylongthatsreallylongthatsreallylong.md', null, true)).toBe('thatsreallylongthatsreallylongthatsreallylongthats.md');
|
2019-09-23 23:30:25 +02:00
|
|
|
}));
|
2018-11-20 02:42:21 +02:00
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
});
|