forked from Gitlink/gitea-1156
Add more tests for diff highlighting (#12467)
Adding some more tests for different cases to make sure they keep working Co-authored-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
parent
a4ba1ad5ed
commit
73b155d5f2
|
@ -181,7 +181,7 @@ var (
|
|||
removedCodePrefix = []byte(`<span class="removed-code">`)
|
||||
codeTagSuffix = []byte(`</span>`)
|
||||
)
|
||||
var addSpanRegex = regexp.MustCompile(`<span class="[a-z]*$`)
|
||||
var addSpanRegex = regexp.MustCompile(`<span [class="[a-z]*]*$`)
|
||||
|
||||
func diffToHTML(fileName string, diffs []diffmatchpatch.Diff, lineType DiffLineType) template.HTML {
|
||||
buf := bytes.NewBuffer(nil)
|
||||
|
|
|
@ -60,6 +60,21 @@ func TestDiffToHTML(t *testing.T) {
|
|||
{Type: dmp.DiffInsert, Text: "ge</span><span class=\"p\">.</span><span class=\"nx\">Milestone</span><span class=\"p\">,</span> <span class=\"nx\">from</span><span class=\"p\">,</span> <span class=\"nx\">milestoneID"},
|
||||
{Type: dmp.DiffEqual, Text: "</span><span class=\"p\">)</span>"},
|
||||
}, DiffLineDel))
|
||||
|
||||
assertEqual(t, "<span class=\"nx\">r</span><span class=\"p\">.</span><span class=\"nf\">WrapperRenderer</span><span class=\"p\">(</span><span class=\"nx\">w</span><span class=\"p\">,</span> <span class=\"nx\"><span class=\"removed-code\">language</span></span><span class=\"removed-code\"><span class=\"p\">,</span> <span class=\"kc\">true</span><span class=\"p\">,</span> <span class=\"nx\">attrs</span></span><span class=\"p\">,</span> <span class=\"kc\">false</span><span class=\"p\">)</span>", diffToHTML("", []dmp.Diff{
|
||||
{Type: dmp.DiffEqual, Text: "<span class=\"nx\">r</span><span class=\"p\">.</span><span class=\"nf\">WrapperRenderer</span><span class=\"p\">(</span><span class=\"nx\">w</span><span class=\"p\">,</span> <span class=\"nx\">"},
|
||||
{Type: dmp.DiffDelete, Text: "language</span><span "},
|
||||
{Type: dmp.DiffEqual, Text: "c"},
|
||||
{Type: dmp.DiffDelete, Text: "lass=\"p\">,</span> <span class=\"kc\">true</span><span class=\"p\">,</span> <span class=\"nx\">attrs"},
|
||||
{Type: dmp.DiffEqual, Text: "</span><span class=\"p\">,</span> <span class=\"kc\">false</span><span class=\"p\">)</span>"},
|
||||
}, DiffLineDel))
|
||||
|
||||
assertEqual(t, "<span class=\"added-code\">language</span></span><span class=\"added-code\"><span class=\"p\">,</span> <span class=\"kc\">true</span><span class=\"p\">,</span> <span class=\"nx\">attrs</span></span><span class=\"p\">,</span> <span class=\"kc\">false</span><span class=\"p\">)</span>", diffToHTML("", []dmp.Diff{
|
||||
{Type: dmp.DiffInsert, Text: "language</span><span "},
|
||||
{Type: dmp.DiffEqual, Text: "c"},
|
||||
{Type: dmp.DiffInsert, Text: "lass=\"p\">,</span> <span class=\"kc\">true</span><span class=\"p\">,</span> <span class=\"nx\">attrs"},
|
||||
{Type: dmp.DiffEqual, Text: "</span><span class=\"p\">,</span> <span class=\"kc\">false</span><span class=\"p\">)</span>"},
|
||||
}, DiffLineAdd))
|
||||
}
|
||||
|
||||
func TestParsePatch(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue