From 02bdd701a56651aeb1ae7a9e35e2f20b3ed055f9 Mon Sep 17 00:00:00 2001 From: claw Date: Tue, 12 May 2026 23:32:22 -0700 Subject: [PATCH] test(gitea): add hunk-header-at-end error path test Adds TestTranslate_HunkHeaderAtEnd covering the edge case where a hunk-header is the last position in the file with no subsequent new-file line. Mirrors TestBuildPositionToLineMap_DeletionAtEnd for the hunk-header code path. Addresses NIT from sonnet-review-bot on PR #104 (comment 18412). --- gitea/position_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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") + } +}