mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-09 21:03:58 +00:00
fix: git diff blob excerpt (#38808)
1. refactor the legacy code and add more comments, remove the "+1/-1" tricks, clarify the BuildBlobExcerptDiffSection behavior 2. fix a line-counting bug (see screenshot below)
This commit is contained in:
@@ -7,6 +7,7 @@ package git
|
||||
import (
|
||||
"io"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -56,3 +57,20 @@ func Benchmark_Blob_Data(b *testing.B) {
|
||||
_ = r.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetBlobLineCount(t *testing.T) {
|
||||
size, count, err := getBlobLineCount(strings.NewReader(""), nil)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 0, size)
|
||||
assert.Equal(t, 0, count)
|
||||
|
||||
size, count, err = getBlobLineCount(strings.NewReader("\n"), nil)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, size)
|
||||
assert.Equal(t, 1, count)
|
||||
|
||||
size, count, err = getBlobLineCount(strings.NewReader("a\nb"), nil)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 3, size)
|
||||
assert.Equal(t, 2, count)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user