diff --git a/gitea/position_test.go b/gitea/position_test.go index bb15042..ef89ead 100644 --- a/gitea/position_test.go +++ b/gitea/position_test.go @@ -357,3 +357,27 @@ new file mode 100644 t.Errorf("Translate(new.go, 1) = %d, want 1 (first addition line)", got) } } + +func TestTranslate_HunkHeaderAtEnd(t *testing.T) { + // A hunk-header at the last position with no subsequent new-file line should error. + // This is the hunk-header equivalent of TestBuildPositionToLineMap_DeletionAtEnd. + diff := `diff --git a/file.go b/file.go +--- a/file.go ++++ b/file.go +@@ -1,2 +1,2 @@ package main + line1 +-old ++new +@@ -10,2 +10,1 @@ func foo() { +-removed +` + pm := BuildPositionToLineMap(diff) + + // Position 5 is the second @@ hunk-header; the only line after it (pos 6) is a + // deletion (lineNum == -1), so there's no positive new-file line to resolve to. + // The hunk-header lookup should fail. + _, err := pm.Translate("file.go", 5) + if err == nil { + t.Error("expected error for hunk-header at end with no subsequent new-file line") + } +}