Skip to content

Commit 632ea32

Browse files
committed
improve test
1 parent 7fffde1 commit 632ea32

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

services/gitdiff/highlightdiff_test.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,20 @@ func TestDiffWithHighlightPlaceholderExhausted(t *testing.T) {
5757
}
5858

5959
func TestDiffWithHighlightTagMatch(t *testing.T) {
60-
totalOverflow := 0
61-
for i := 0; i < 100; i++ {
62-
hcd := newHighlightCodeDiff()
63-
hcd.placeholderMaxCount = i
64-
output := string(hcd.diffLineWithHighlight(DiffLineDel, `<span class="k">&lt;</span>`, `<span class="k">&gt;</span>`))
65-
totalOverflow += hcd.placeholderOverflowCount
66-
c1 := strings.Count(output, "<span")
67-
c2 := strings.Count(output, "</span")
68-
assert.Equal(t, c1, c2)
60+
f := func(t *testing.T, lineType DiffLineType) {
61+
totalOverflow := 0
62+
for i := 0; ; i++ {
63+
hcd := newHighlightCodeDiff()
64+
hcd.placeholderMaxCount = i
65+
output := string(hcd.diffLineWithHighlight(lineType, `<span class="k">&lt;</span>`, `<span class="k">&gt;</span>`))
66+
totalOverflow += hcd.placeholderOverflowCount
67+
assert.Equal(t, strings.Count(output, "<span"), strings.Count(output, "</span"))
68+
if hcd.placeholderOverflowCount == 0 {
69+
break
70+
}
71+
}
72+
assert.NotZero(t, totalOverflow)
6973
}
70-
assert.NotZero(t, totalOverflow)
74+
t.Run("DiffLineAdd", func(t *testing.T) { f(t, DiffLineAdd) })
75+
t.Run("DiffLineDel", func(t *testing.T) { f(t, DiffLineDel) })
7176
}

0 commit comments

Comments
 (0)