This commit is contained in:
@@ -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)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -70,4 +70,31 @@ describe('renderMarkdown', () => {
|
||||
expect(html).not.toContain('<table')
|
||||
expect(html).toContain('<p>a | b not a table</p>')
|
||||
})
|
||||
it('resolves a relative image against the document folder', () => {
|
||||
const html = renderMarkdown('', 'docs/how-to')
|
||||
expect(html).toContain('data-src="docs/how-to/forge-app-config.png"')
|
||||
expect(html).not.toContain(' src=')
|
||||
})
|
||||
|
||||
it('keeps the image title out of the path and walks up a parent folder', () => {
|
||||
const html = renderMarkdown('', 'docs/how-to')
|
||||
expect(html).toContain('data-src="docs/img/a b.png"')
|
||||
expect(html).toContain('title="A title"')
|
||||
})
|
||||
|
||||
it('reads a leading slash as the project root', () => {
|
||||
expect(renderMarkdown('', 'docs/how-to')).toContain('data-src="img/a.png"')
|
||||
})
|
||||
|
||||
it('leaves a remote image on src', () => {
|
||||
const html = renderMarkdown('', 'docs')
|
||||
expect(html).toContain('src="https://x.com/a.png"')
|
||||
expect(html).not.toContain('data-src')
|
||||
})
|
||||
|
||||
it('keeps a link title out of the href', () => {
|
||||
const html = renderMarkdown('[a](https://x.com "Home")')
|
||||
expect(html).toContain('href="https://x.com"')
|
||||
expect(html).toContain('title="Home"')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user