truncate_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package sanitizer
  4. import "testing"
  5. func TestTruncateHTMWithTextLowerThanLimitL(t *testing.T) {
  6. input := `This is a <strong>bug 🐛</strong>.`
  7. expected := `This is a bug 🐛.`
  8. output := TruncateHTML(input, 50)
  9. if expected != output {
  10. t.Errorf(`Wrong output: %q != %q`, expected, output)
  11. }
  12. }
  13. func TestTruncateHTMLWithTextAboveLimit(t *testing.T) {
  14. input := `This is <strong>HTML</strong>.`
  15. expected := `This…`
  16. output := TruncateHTML(input, 4)
  17. if expected != output {
  18. t.Errorf(`Wrong output: %q != %q`, expected, output)
  19. }
  20. }
  21. func TestTruncateHTMLWithUnicodeTextAboveLimit(t *testing.T) {
  22. input := `This is a <strong>bike 🚲</strong>.`
  23. expected := `This…`
  24. output := TruncateHTML(input, 4)
  25. if expected != output {
  26. t.Errorf(`Wrong output: %q != %q`, expected, output)
  27. }
  28. }
  29. func TestTruncateHTMLWithMultilineTextAboveLimit(t *testing.T) {
  30. input := `
  31. This is a <strong>bike
  32. 🚲</strong>.
  33. `
  34. expected := `This is a bike…`
  35. output := TruncateHTML(input, 15)
  36. if expected != output {
  37. t.Errorf(`Wrong output: %q != %q`, expected, output)
  38. }
  39. }
  40. func TestTruncateHTMLWithMultilineTextLowerThanLimit(t *testing.T) {
  41. input := `
  42. This is a <strong>bike
  43. 🚲</strong>.
  44. `
  45. expected := `This is a bike 🚲.`
  46. output := TruncateHTML(input, 20)
  47. if expected != output {
  48. t.Errorf(`Wrong output: %q != %q`, expected, output)
  49. }
  50. }