mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-23 03:24:01 +09:00
Backport #39887 by @silverwind Code comments next to a diff hunk could show one line too high in the conversation view vs. in the code view that showed them on the correct line. - Treat the hunk end in `CutDiffAroundLine` as exclusive, so the line after a hunk falls back to the unchanged-line context - Don't count `\ No newline at end of file` markers as lines when cutting the hunk - Share the unchanged-line fallback with migrated review comments Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
@@ -120,10 +120,18 @@ func TestCutDiffAroundLine(t *testing.T) {
|
||||
assert.Empty(t, emptyResult)
|
||||
|
||||
// Line is out of scope
|
||||
emptyResult, err = CutDiffAroundLine(strings.NewReader(exampleDiff), 434, false, 0)
|
||||
emptyResult, err = CutDiffAroundLine(strings.NewReader(exampleDiff), 7, false, 3)
|
||||
assert.NoError(t, err)
|
||||
assert.Empty(t, emptyResult)
|
||||
|
||||
noNewlineDiff := "diff --git a/a b/a\n--- a/a\n+++ b/a\n@@ -1 +1 @@\n-a\n\\ No newline at end of file\n+a"
|
||||
result, err = CutDiffAroundLine(strings.NewReader(noNewlineDiff), 1, false, 2)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "diff --git a/a b/a\n--- a/a\n+++ b/a\n@@ -1,1 +1,1 @@\n-a\n\\ No newline at end of file\n+a", result)
|
||||
result, err = CutDiffAroundLine(strings.NewReader(noNewlineDiff), 1, true, 2)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "diff --git a/a b/a\n--- a/a\n+++ b/a\n@@ -1 +1 @@\n-a", result)
|
||||
|
||||
// Handle minus diffs properly
|
||||
minusDiff, err := CutDiffAroundLine(strings.NewReader(breakingDiff), 2, false, 4)
|
||||
assert.NoError(t, err)
|
||||
|
||||
Reference in New Issue
Block a user