shows relative images in markdown
Some checks failed
CI / check (push) Has been cancelled

This commit is contained in:
2026-09-14 11:27:10 +02:00
parent f6a551d7c4
commit a2d1c5df83
6 changed files with 230 additions and 29 deletions

View File

@@ -69,3 +69,33 @@ describe('makeDiff', () => {
expect(deleted.added).toBe(false)
})
})
describe('buildDiff on large files', () => {
it('diffs a 60k-line file without exhausting the heap', () => {
const base = Array.from({ length: 60_000 }, (_, i) => `line ${i}`)
const changed = base.slice()
changed[30_000] = 'line 30000 edited'
const d = buildDiff(base.join('\n'), changed.join('\n'))
expect(d.add).toBe(1)
expect(d.del).toBe(1)
expect(d.right[30_000].mark).toBe('add')
})
it('survives a full rewrite of a large file with no shared lines', () => {
const a = Array.from({ length: 40_000 }, (_, i) => `old ${i}`).join('\n')
const b = Array.from({ length: 40_000 }, (_, i) => `new ${i}`).join('\n')
const d = buildDiff(a, b)
expect(d.del).toBe(40_000)
expect(d.add).toBe(40_000)
})
it('keeps the unchanged head and tail of a large, heavily edited file', () => {
const head = Array.from({ length: 5_000 }, (_, i) => `head ${i}`)
const tail = Array.from({ length: 5_000 }, (_, i) => `tail ${i}`)
const mid = (p: string): string[] => Array.from({ length: 30_000 }, (_, i) => `${p} ${i % 7}`)
const d = buildDiff([...head, ...mid('x'), ...tail].join('\n'), [...head, ...mid('y'), ...tail].join('\n'))
expect(d.left.slice(0, 5_000).every((l) => l.mark === null)).toBe(true)
expect(d.left.slice(-5_000).every((l) => l.mark === null)).toBe(true)
expect(d.add).toBe(30_000)
})
})