fix(edit): collapsed unchanged diff context between distant edit blocks
- Updated generateDiffString to preserve bounded context at both edges of unchanged regions between adjacent changes by adding a middle skip and ellipsis. - Added a test covering distant edit hunks to verify unchanged lines in the gap are collapsed while change lines remain visible.
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import { generateDiffString } from "../../src/edit/diff";
|
||||
|
||||
describe("generateDiffString", () => {
|
||||
it("collapses unchanged lines between distant edits", () => {
|
||||
const oldLines = Array.from({ length: 20 }, (_, index) => `line ${index + 1}`);
|
||||
const newLines = [...oldLines];
|
||||
newLines[1] = "line 2 changed";
|
||||
newLines[17] = "line 18 changed";
|
||||
|
||||
const result = generateDiffString(oldLines.join("\n"), newLines.join("\n"), 2);
|
||||
const diffLines = result.diff.split("\n");
|
||||
|
||||
expect(diffLines).toContain(" 5|...");
|
||||
expect(diffLines).toContain("-2|line 2");
|
||||
expect(diffLines).toContain("+2|line 2 changed");
|
||||
expect(diffLines).toContain("-18|line 18");
|
||||
expect(diffLines).toContain("+18|line 18 changed");
|
||||
expect(diffLines).not.toContain(" 8|line 8");
|
||||
expect(diffLines).not.toContain(" 12|line 12");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user