A web blog and personal homepage engine written in Go.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

45 lignes
1.0 KiB

  1. package mogrify_test
  2. import (
  3. "testing"
  4. "git.kirsle.net/apps/gophertype/pkg/mogrify"
  5. )
  6. func TestLazyLoadImages(t *testing.T) {
  7. var tests = []struct {
  8. In string
  9. Expect string
  10. }{
  11. {
  12. In: `<img src="logo.jpg">`,
  13. Expect: `<img src="logo.jpg" loading="lazy">`,
  14. },
  15. {
  16. In: `<img src="https://example.com/image.png" loading="eager">`,
  17. Expect: `<img src="https://example.com/image.png" loading="eager">`,
  18. },
  19. {
  20. In: `Hello world`,
  21. Expect: `Hello world`,
  22. },
  23. {
  24. In: `<img src="a"><img src="b"><img src="a">`,
  25. Expect: `<img src="a" loading="lazy"><img src="b" loading="lazy"><img src="a" loading="lazy">`,
  26. },
  27. {
  28. In: `<img src="a"><img src="b" loading="eager"><img src="a">`,
  29. Expect: `<img src="a" loading="lazy"><img src="b" loading="eager"><img src="a" loading="lazy">`,
  30. },
  31. }
  32. for _, test := range tests {
  33. actual := mogrify.LazyLoadImages(test.In)
  34. if actual != test.Expect {
  35. t.Errorf("for input {%s} I expected {%s} but got: {%s}",
  36. test.In, test.Expect, actual,
  37. )
  38. }
  39. }
  40. }