test: add filename collision detection unit tests
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
a4ca410641
commit
3537d28eb2
@ -105,6 +105,21 @@ function run() {
|
||||
const iIndex = args.indexOf('-i');
|
||||
assert(ssIndex < iIndex, `FFmpeg args: -ss (${ssIndex}) must be before -i (${iIndex})`);
|
||||
|
||||
// ---- Test 9: ensureUniqueFilename pattern ----
|
||||
function ensureUnique(base, ext, existingFiles) {
|
||||
let candidate = base + ext;
|
||||
if (!existingFiles.includes(candidate)) return candidate;
|
||||
let counter = 1;
|
||||
while (existingFiles.includes(candidate)) {
|
||||
candidate = `${base}_${counter}${ext}`;
|
||||
counter++;
|
||||
}
|
||||
return candidate;
|
||||
}
|
||||
assert(ensureUnique('video', '.mp4', []) === 'video.mp4', 'Unique: no conflict');
|
||||
assert(ensureUnique('video', '.mp4', ['video.mp4']) === 'video_1.mp4', 'Unique: one conflict');
|
||||
assert(ensureUnique('video', '.mp4', ['video.mp4', 'video_1.mp4']) === 'video_2.mp4', 'Unique: two conflicts');
|
||||
|
||||
// ---- Results ----
|
||||
if (failures.length > 0) {
|
||||
console.error(`FAIL: ${failures.length} test(s) failed:`);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user