fix: compute first changed diff line from patch hunks
Uses hunk contents to find the first modified line instead of the hunk start Handles added, removed, and binary-only patches more accurately Adds tests for patch parsing edge cases
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { describe, expect, test } from 'bun:test';
|
||||
|
||||
import { getFirstChangedModifiedLineFromPatch } from './diffPatchUtils';
|
||||
|
||||
describe('getFirstChangedModifiedLineFromPatch', () => {
|
||||
test('returns the first added line instead of the hunk context start', () => {
|
||||
expect(getFirstChangedModifiedLineFromPatch(`diff --git a/src/file.ts b/src/file.ts
|
||||
@@ -56,10 +56,11 @@
|
||||
unchanged 58
|
||||
unchanged 59
|
||||
unchanged 60
|
||||
+changed 61
|
||||
unchanged 62`)).toBe(59);
|
||||
});
|
||||
|
||||
test('returns the following modified line for deletion-only hunks', () => {
|
||||
expect(getFirstChangedModifiedLineFromPatch(`@@ -10,4 +10,3 @@
|
||||
context
|
||||
-removed
|
||||
after`)).toBe(11);
|
||||
});
|
||||
|
||||
test('returns null when the patch has no hunk change lines', () => {
|
||||
expect(getFirstChangedModifiedLineFromPatch('Binary files a/image.png and b/image.png differ')).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user