-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathfiles.test.ts
More file actions
43 lines (34 loc) · 1.32 KB
/
files.test.ts
File metadata and controls
43 lines (34 loc) · 1.32 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
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import assert from 'node:assert';
import {describe, it} from 'node:test';
import {ensureExtension} from '../../src/utils/files.js';
describe('ensureExtension', () => {
it('should add an extension to a filename without one', () => {
assert.strictEqual(ensureExtension('filename', '.txt'), 'filename.txt');
});
it('should replace an existing extension', () => {
assert.strictEqual(ensureExtension('filename.jpg', '.txt'), 'filename.txt');
});
it('should handle extension without a leading dot', () => {
assert.strictEqual(ensureExtension('filename', 'txt'), 'filename.txt');
});
it('should not add a second dot if already present', () => {
assert.strictEqual(ensureExtension('filename.txt', '.txt'), 'filename.txt');
});
it('should handle paths with directories', () => {
assert.strictEqual(
ensureExtension('/path/to/file.jpg', '.png'),
'/path/to/file.png',
);
});
it('should handle hidden files (starting with dot)', () => {
assert.strictEqual(ensureExtension('.bashrc', '.txt'), '.bashrc.txt');
});
it('should handle complex extensions (like .tar.gz) - path.extname only gets the last one', () => {
assert.strictEqual(ensureExtension('file.tar.gz', '.zip'), 'file.tar.zip');
});
});