diff options
author | mrsdizzie <info@mrsdizzie.com> | 2020-08-11 00:29:25 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-11 00:29:25 -0400 |
commit | 73b155d5f21813abc788a54aee0ee72459e7c7c9 (patch) | |
tree | d3b1dce6b8699dd3bebec6bc797e3008ffe23d2d /services/gitdiff | |
parent | a4ba1ad5ed6415ffecd2a6d1234741b4c2532e35 (diff) | |
download | gitea-73b155d5f21813abc788a54aee0ee72459e7c7c9.tar.gz gitea-73b155d5f21813abc788a54aee0ee72459e7c7c9.zip |
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>
Diffstat (limited to 'services/gitdiff')
-rw-r--r-- | services/gitdiff/gitdiff.go | 2 | ||||
-rw-r--r-- | services/gitdiff/gitdiff_test.go | 15 |
2 files changed, 16 insertions, 1 deletions
diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go index fca210bb10..d50ae6ae27 100644 --- a/services/gitdiff/gitdiff.go +++ b/services/gitdiff/gitdiff.go @@ -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) diff --git a/services/gitdiff/gitdiff_test.go b/services/gitdiff/gitdiff_test.go index b927abf07b..597c9d394e 100644 --- a/services/gitdiff/gitdiff_test.go +++ b/services/gitdiff/gitdiff_test.go @@ -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) { |