shr-tests.el 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. ;;; network-stream-tests.el --- tests for network processes -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2016-2017 Free Software Foundation, Inc.
  3. ;; Author: Lars Ingebrigtsen <larsi@gnus.org>
  4. ;; This file is part of GNU Emacs.
  5. ;; GNU Emacs is free software: you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; GNU Emacs is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;;; Code:
  17. (require 'shr)
  18. (defconst shr-tests--datadir
  19. (expand-file-name "test/data/shr" source-directory))
  20. (defun shr-test (name)
  21. (with-temp-buffer
  22. (insert-file-contents (format (concat shr-tests--datadir "/%s.html") name))
  23. (let ((dom (libxml-parse-html-region (point-min) (point-max)))
  24. (shr-width 80)
  25. (shr-use-fonts nil))
  26. (erase-buffer)
  27. (shr-insert-document dom)
  28. (cons (buffer-substring-no-properties (point-min) (point-max))
  29. (with-temp-buffer
  30. (insert-file-contents
  31. (format (concat shr-tests--datadir "/%s.txt") name))
  32. (while (re-search-forward "%\\([0-9A-F][0-9A-F]\\)" nil t)
  33. (replace-match (string (string-to-number (match-string 1) 16))
  34. t t))
  35. (buffer-string))))))
  36. (ert-deftest rendering ()
  37. (skip-unless (fboundp 'libxml-parse-html-region))
  38. (dolist (file (directory-files shr-tests--datadir nil "\\.html\\'"))
  39. (let* ((name (replace-regexp-in-string "\\.html\\'" "" file))
  40. (result (shr-test name)))
  41. (unless (equal (car result) (cdr result))
  42. (should (not (list name (car result) (cdr result))))))))
  43. (require 'shr)
  44. ;;; shr-stream-tests.el ends here