Skip to content

Commit 9cf358b

Browse files
committed
demo why the tags are always balanced
1 parent 4d1d8a4 commit 9cf358b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

services/gitdiff/highlightdiff_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strings"
1010
"testing"
1111

12+
"github.com/sergi/go-diff/diffmatchpatch"
1213
"github.com/stretchr/testify/assert"
1314
)
1415

@@ -27,6 +28,23 @@ func TestDiffWithHighlight(t *testing.T) {
2728
expected = ` <span class="n">run</span><span class="o">(</span><span class="added-code"><span class="n">db</span></span><span class="o">)</span>` + "\n"
2829
output = diffToHTML(nil, diffs, DiffLineAdd)
2930
assert.Equal(t, expected, output)
31+
32+
hcd = newHighlightCodeDiff()
33+
hcd.placeholderTokenMap['O'] = "<span>"
34+
hcd.placeholderTokenMap['C'] = "</span>"
35+
diff := diffmatchpatch.Diff{}
36+
37+
diff.Text = "OC"
38+
hcd.recoverOneDiff(&diff)
39+
assert.Equal(t, "<span></span>", diff.Text)
40+
41+
diff.Text = "O"
42+
hcd.recoverOneDiff(&diff)
43+
assert.Equal(t, "<span></span>", diff.Text)
44+
45+
diff.Text = "C"
46+
hcd.recoverOneDiff(&diff)
47+
assert.Equal(t, "", diff.Text)
3048
}
3149

3250
func TestDiffWithHighlightPlaceholder(t *testing.T) {

0 commit comments

Comments
 (0)