(t *testing.T)
| 201 | } |
| 202 | |
| 203 | func 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 | } |
nothing calls this directly
no test coverage detected