Merge pull request #2137 from code-yeongyu/fix/issue-2051-diff-context-limit
fix(hashline-edit): limit diff context to 3 lines to prevent oversized hunks
This commit is contained in:
commit
5bc3a9e0db
@ -41,6 +41,23 @@ describe("generateUnifiedDiff", () => {
|
|||||||
expect(diff).toContain(" line 13")
|
expect(diff).toContain(" line 13")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("limits each hunk to three context lines", () => {
|
||||||
|
//#given
|
||||||
|
const oldContent = createNumberedLines(20)
|
||||||
|
const newLines = oldContent.split("\n")
|
||||||
|
newLines[9] = "line 10 updated"
|
||||||
|
const newContent = newLines.join("\n")
|
||||||
|
|
||||||
|
//#when
|
||||||
|
const diff = generateUnifiedDiff(oldContent, newContent, "sample.txt")
|
||||||
|
|
||||||
|
//#then
|
||||||
|
expect(diff).toContain(" line 7")
|
||||||
|
expect(diff).toContain(" line 13")
|
||||||
|
expect(diff).not.toContain(" line 6")
|
||||||
|
expect(diff).not.toContain(" line 14")
|
||||||
|
})
|
||||||
|
|
||||||
it("returns a diff string for identical content", () => {
|
it("returns a diff string for identical content", () => {
|
||||||
//#given
|
//#given
|
||||||
const oldContent = "alpha\nbeta\ngamma"
|
const oldContent = "alpha\nbeta\ngamma"
|
||||||
|
|||||||
@ -16,7 +16,7 @@ export function toHashlineContent(content: string): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function generateUnifiedDiff(oldContent: string, newContent: string, filePath: string): string {
|
export function generateUnifiedDiff(oldContent: string, newContent: string, filePath: string): string {
|
||||||
return createTwoFilesPatch(filePath, filePath, oldContent, newContent)
|
return createTwoFilesPatch(filePath, filePath, oldContent, newContent, undefined, undefined, { context: 3 })
|
||||||
}
|
}
|
||||||
|
|
||||||
export function countLineDiffs(oldContent: string, newContent: string): { additions: number; deletions: number } {
|
export function countLineDiffs(oldContent: string, newContent: string): { additions: number; deletions: number } {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user