mirror of
https://github.com/go-gitea/gitea.git
synced 2026-02-10 22:08:57 +00:00
Use full-file highlighting for diff sections (#36561)
* Fix #35252 * Fix #35999 * Improve diff rendering, don't add unnecessary "added"/"removed" tags for a full-line change * Also fix a "space trimming" bug in #36539 and add tests * Use chroma "SQL" lexer instead of "MySQL" to workaround a bug (35999)
This commit is contained in:
39
services/gitdiff/gitdiff_excerpt_test.go
Normal file
39
services/gitdiff/gitdiff_excerpt_test.go
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package gitdiff
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/modules/translation"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestBuildBlobExcerptDiffSection(t *testing.T) {
|
||||
data := &bytes.Buffer{}
|
||||
for i := range 100 {
|
||||
data.WriteString("a = " + strconv.Itoa(i+1) + "\n")
|
||||
}
|
||||
|
||||
locale := translation.MockLocale{}
|
||||
lineMiddle := 50
|
||||
diffSection, err := BuildBlobExcerptDiffSection("a.py", bytes.NewReader(data.Bytes()), BlobExcerptOptions{
|
||||
LeftIndex: lineMiddle,
|
||||
RightIndex: lineMiddle,
|
||||
LeftHunkSize: 10,
|
||||
RightHunkSize: 10,
|
||||
Direction: "up",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, diffSection.highlightedRightLines.value, BlobExcerptChunkSize)
|
||||
assert.NotEmpty(t, diffSection.highlightedRightLines.value[lineMiddle-BlobExcerptChunkSize-1])
|
||||
assert.NotEmpty(t, diffSection.highlightedRightLines.value[lineMiddle-2]) // 0-based
|
||||
|
||||
diffInline := diffSection.GetComputedInlineDiffFor(diffSection.Lines[1], locale)
|
||||
assert.Equal(t, `<span class="n">a</span> <span class="o">=</span> <span class="mi">30</span>`+"\n", string(diffInline.Content))
|
||||
}
|
||||
Reference in New Issue
Block a user