MCPcopy Index your code
hub / github.com/apache/answer / TestFetchMatchedExcerpt

Function TestFetchMatchedExcerpt

pkg/htmltext/htmltext_test.go:203–228  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

201}
202
203func TestFetchMatchedExcerpt(t *testing.T) {
204 var (
205 expected,
206 actual string
207 )
208
209 html := "<p>Hello, I have 中文 and 😂 and I am supposed to work fine</p>"
210
211 // test find nothing
212 // it should return from the begin with double trimLength text
213 expected = "Hello, I h..."
214 actual = FetchMatchedExcerpt(html, []string{"youcantfindme"}, "...", 5)
215 assert.Equal(t, expected, actual)
216
217 // test find the word at the end
218 // it should return the word beginning with double trimLenth plus len(word)
219 expected = "... work fine"
220 actual = FetchMatchedExcerpt(html, []string{"youcant", "fine"}, "...", 3)
221 assert.Equal(t, expected, actual)
222
223 // test find multiple words
224 // it should return the first matched word with trimmedText
225 expected = "... have 中文 and 😂..."
226 actual = FetchMatchedExcerpt(html, []string{"中文", "😂"}, "...", 6)
227 assert.Equal(t, expected, actual)
228}

Callers

nothing calls this directly

Calls 1

FetchMatchedExcerptFunction · 0.85

Tested by

no test coverage detected