Files
Gogs/internal/gitx/diff_test.go
ᴊᴏᴇ ᴄʜᴇɴ 36d56d5525 all: rename packages ending with "util" to end with "x" (#8182)
Co-authored-by: JSS <jss@unknwon.dev>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-16 13:25:19 -05:00

46 lines
1.1 KiB
Go

package gitx
import (
"html/template"
"testing"
dmp "github.com/sergi/go-diff/diffmatchpatch"
"github.com/stretchr/testify/assert"
"github.com/gogs/git-module"
)
func Test_diffsToHTML(t *testing.T) {
tests := []struct {
diffs []dmp.Diff
lineType git.DiffLineType
expHTML template.HTML
}{
{
diffs: []dmp.Diff{
{Type: dmp.DiffEqual, Text: "foo "},
{Type: dmp.DiffInsert, Text: "bar"},
{Type: dmp.DiffDelete, Text: " baz"},
{Type: dmp.DiffEqual, Text: " biz"},
},
lineType: git.DiffLineAdd,
expHTML: template.HTML(`+foo <span class="added-code">bar</span> biz`),
},
{
diffs: []dmp.Diff{
{Type: dmp.DiffEqual, Text: "foo "},
{Type: dmp.DiffDelete, Text: "bar"},
{Type: dmp.DiffInsert, Text: " baz"},
{Type: dmp.DiffEqual, Text: " biz"},
},
lineType: git.DiffLineDelete,
expHTML: template.HTML(`-foo <span class="removed-code">bar</span> biz`),
},
}
for _, test := range tests {
t.Run("", func(t *testing.T) {
assert.Equal(t, test.expHTML, diffsToHTML(test.diffs, test.lineType))
})
}
}