Files
MokoGitea/services/gitdiff/gitdiff_excerpt_test.go
T
Jonathan Miller 9a5720e8ad
Universal: PR Check / Branch Policy (pull_request) Successful in 1s
Branch Policy Check / Verify merge target (pull_request) Successful in 1s
PR RC Release / Build RC Release (pull_request) Successful in 3s
Universal: PR Check / Validate PR (pull_request) Failing after 6s
Branch Cleanup / Delete merged branch (pull_request) Successful in 1s
Universal: PR Check / Build RC Package (pull_request) Has been cancelled
chore: rename Go module from git. to code.mokoconsulting.tech (#336)
Full namespace migration: update the Go module path and all import
statements from git.mokoconsulting.tech to code.mokoconsulting.tech.
Also updates all URL references in templates, workflows, configs,
tests, and documentation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-31 10:28:25 -05:00

40 lines
1.2 KiB
Go

// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package gitdiff
import (
"bytes"
"strconv"
"testing"
"code.mokoconsulting.tech/MokoConsulting/MokoGitea/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))
}