fix: allocate export names in linear time
This commit is contained in:
@@ -436,6 +436,28 @@ describe('OneNote export filenames', () => {
|
||||
expect(allocator.allocate('Report.txt')).toBe('Report.txt');
|
||||
expect(allocator.allocate('report.TXT')).toBe('report-2.txt');
|
||||
});
|
||||
|
||||
it('keeps collision suffixes within the filename cap', () => {
|
||||
const allocator = new SafeExportNameAllocator();
|
||||
const filename = `${'x'.repeat(116)}.txt`;
|
||||
expect(filename).toHaveLength(120);
|
||||
expect(allocator.allocate(filename)).toBe(filename);
|
||||
|
||||
const duplicate = allocator.allocate(filename);
|
||||
expect(duplicate).toBe(`${'x'.repeat(114)}-2.txt`);
|
||||
expect([...duplicate]).toHaveLength(120);
|
||||
});
|
||||
|
||||
it('allocates many duplicate names without rescanning prior suffixes', () => {
|
||||
const allocator = new SafeExportNameAllocator();
|
||||
const names = Array.from({ length: 10_000 }, () =>
|
||||
allocator.allocate('Report.txt')
|
||||
);
|
||||
|
||||
expect(names[0]).toBe('Report.txt');
|
||||
expect(names.at(-1)).toBe('Report-10000.txt');
|
||||
expect(new Set(names)).toHaveLength(names.length);
|
||||
});
|
||||
});
|
||||
|
||||
function fixtureSnapshot(): OneNoteExportSnapshot {
|
||||
|
||||
Reference in New Issue
Block a user