Skip to content

Commit

Permalink
demo why the tags are always balanced
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang committed Jul 9, 2022
1 parent 4d1d8a4 commit 9cf358b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions services/gitdiff/highlightdiff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"
"testing"

"github.com/sergi/go-diff/diffmatchpatch"
"github.com/stretchr/testify/assert"
)

Expand All @@ -27,6 +28,23 @@ func TestDiffWithHighlight(t *testing.T) {
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"
output = diffToHTML(nil, diffs, DiffLineAdd)
assert.Equal(t, expected, output)

hcd = newHighlightCodeDiff()
hcd.placeholderTokenMap['O'] = "<span>"
hcd.placeholderTokenMap['C'] = "</span>"
diff := diffmatchpatch.Diff{}

diff.Text = "OC"
hcd.recoverOneDiff(&diff)
assert.Equal(t, "<span></span>", diff.Text)

diff.Text = "O"
hcd.recoverOneDiff(&diff)
assert.Equal(t, "<span></span>", diff.Text)

diff.Text = "C"
hcd.recoverOneDiff(&diff)
assert.Equal(t, "", diff.Text)
}

func TestDiffWithHighlightPlaceholder(t *testing.T) {
Expand Down

0 comments on commit 9cf358b

Please sign in to comment.