test-ein-output-area.el 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. (eval-when-compile (require 'cl))
  2. (require 'ert)
  3. (require 'ein-output-area)
  4. (defun ein:testing-insert-html--fix-urls-do-test (source desired)
  5. (setq source (ein:xml-parse-html-string source))
  6. (setq desired (ein:xml-parse-html-string desired))
  7. (ein:insert-html--fix-urls source 8888)
  8. (should (equal source desired)))
  9. (defmacro ein:testing-insert-html--fix-urls-deftests (args-list)
  10. `(progn
  11. ,@(loop for i from 0
  12. for args in args-list
  13. for test = (intern (format "ein:insert-html--fix-urls/%s" i))
  14. collect
  15. `(ert-deftest ,test ()
  16. (ein:testing-insert-html--fix-urls-do-test ,@args)))))
  17. (when (require 'shr nil t)
  18. (ein:testing-insert-html--fix-urls-deftests
  19. (;; Simple replaces
  20. ("<a href=files/spam>text</a>"
  21. "<a href=http://127.0.0.1:8888/files/spam>text</a>")
  22. ("<a href=/files/spam>text</a>"
  23. "<a href=http://127.0.0.1:8888/files/spam>text</a>")
  24. ("<img src=files/sample.png />"
  25. "<img src=http://127.0.0.1:8888/files/sample.png />")
  26. ("<img src=/files/sample.png />"
  27. "<img src=http://127.0.0.1:8888/files/sample.png />")
  28. ;; Do not modify dom in these cases:
  29. ("<a>text</a>"
  30. "<a>text</a>")
  31. ("<a href=http://example>text</a>"
  32. "<a href=http://example>text</a>")
  33. ("<img src=http://example />"
  34. "<img src=http://example />")
  35. ;; Bit more complicated cases:
  36. ("<p><a href=files/spam>link</a> normal</p>"
  37. "<p><a href=http://127.0.0.1:8888/files/spam>link</a> normal</p>")
  38. ("<img><img src=files/sample.png /> normal</p>"
  39. "<img><img src=http://127.0.0.1:8888/files/sample.png /> normal</p>")
  40. )))