Add more shr HTML rendering tests

This commit is contained in:
Lars Magne Ingebrigtsen 2016-03-20 13:41:59 +01:00
parent 4f9c775700
commit 21c89971c3
6 changed files with 29 additions and 5 deletions

View file

@ -0,0 +1 @@
<div>foo</div><div>Bar</div>

View file

@ -0,0 +1,2 @@
foo
Bar

View file

@ -1 +1 @@
<div>foo</div><p>Bar
<div>foo</div><p>Bar</p>

10
test/data/shr/li-div.html Normal file
View file

@ -0,0 +1,10 @@
<ul>
<li>
<div>
<p >This is the first paragraph of a list item.</div>
<p >This is the second paragraph of a list item.</li>
<li>
<div>This is the first paragraph of a list item.</div>
<div>This is the second paragraph of a list item.</div>
</li>
</ul>

6
test/data/shr/li-div.txt Normal file
View file

@ -0,0 +1,6 @@
* This is the first paragraph of a list item.
This is the second paragraph of a list item.
* This is the first paragraph of a list item.
This is the second paragraph of a list item.

View file

@ -23,10 +23,14 @@
;;; Code:
(require 'shr)
(defun shr-test (name)
(with-temp-buffer
(insert-file-contents (format "data/shr/%s.html" name))
(let ((dom (libxml-parse-html-region (point-min) (point-max))))
(let ((dom (libxml-parse-html-region (point-min) (point-max)))
(shr-width 80)
(shr-use-fonts nil))
(erase-buffer)
(shr-insert-document dom)
(cons (buffer-substring-no-properties (point-min) (point-max))
@ -37,9 +41,10 @@
(ert-deftest rendering ()
(skip-unless (fboundp 'libxml-parse-html-region))
(dolist (file (directory-files "data/shr" nil "\\.html\\'"))
(let ((result (shr-test (replace-regexp-in-string
"\\.html\\'" "" file))))
(should (equal (car result) (cdr result))))))
(let* ((name (replace-regexp-in-string "\\.html\\'" "" file))
(result (shr-test name)))
(unless (equal (car result) (cdr result))
(should (not (list name (car result) (cdr result))))))))
(require 'shr)