Skip to content

Commit 1bc8c63

Browse files
committed
Test utils.Ellipsize()
1 parent 85dff71 commit 1bc8c63

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

utils/utils_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,28 @@ func TestIsDeadlock(t *testing.T) {
135135
}
136136
}
137137

138+
func TestEllipsize(t *testing.T) {
139+
subtests := []struct {
140+
name string
141+
s string
142+
limit int
143+
output string
144+
}{
145+
{"negative", "", -1, "..."},
146+
{"empty", "", 0, ""},
147+
{"shorter", " ", 2, " "},
148+
{"equal", " ", 1, " "},
149+
{"longer", " ", 0, "..."},
150+
{"unicode", "äöü߀", 4, "ä..."},
151+
}
152+
153+
for _, st := range subtests {
154+
t.Run(st.name, func(t *testing.T) {
155+
require.Equal(t, st.output, Ellipsize(st.s, st.limit))
156+
})
157+
}
158+
}
159+
138160
func TestChanFromSlice(t *testing.T) {
139161
t.Run("Nil", func(t *testing.T) {
140162
ch := ChanFromSlice[int](nil)

0 commit comments

Comments
 (0)