Fix typos and improve layout
[Worg.git] / org-tests / ert-publish-test.el
blob7458c73f1a602203233df347ba6aeb0e93673686
1 (add-to-list 'load-path (expand-file-name "tools"))
2 (require 'ert)
4 (defun org-export-as-html-test-fixture (file body)
5 "Export the example.org buffer to html, then run the tests in
6 body passing in the org-buffer and the html-buffer as arguments"
7 (unwind-protect
8 (let* ((org-buffer (save-excursion (find-file file)
9 (buffer-name)))
10 (html-buffer "*Org HTML Export*"))
11 ;; setup
12 (set-buffer org-buffer)
13 (call-interactively 'org-export-as-html-to-buffer)
14 (save-excursion
15 ;; run the tests
16 (eval (list body org-buffer html-buffer))))
17 (progn
18 ;; clean up
19 (kill-buffer "*Org HTML Export*")
20 (kill-buffer file))))
22 (defun org-test-search-map-all-org-html-links (buffer body)
23 "for each org link in BUFFER call BODY passing the link-url and
24 link-text as arguments."
25 (save-excursion
26 (set-buffer buffer)
27 (goto-char (point-min))
28 (while (re-search-forward "\\[\\[\\([^][]+\\)\\]\\(\\[\\([^][]+\\)\\]\\)?\\]" nil t)
29 (eval (list body (match-string 1) (replace-regexp-in-string "[\r\n]" " " (match-string 3)))))))
31 ;; this actually defines the test to be run by ert
32 (ert-deftest org-test-export-as-html ()
33 (org-export-as-html-test-fixture
34 "example.org"
35 (lambda (org-buffer html-buffer)
36 (org-test-search-map-all-org-html-links
37 org-buffer
38 (lambda (link-url link-text)
39 (save-excursion
40 (message (format "%s as %s" link-url link-text))
41 (set-buffer html-buffer)
42 (goto-char (point-min))
43 (search-forward link-text)
44 (re-search-backward "<a href=\"\\(.*\\)\"" nil t)
45 (should (string= (match-string 1)
46 link-url))))))))
48 ;; this runs the ert test
49 (ert-run-tests-interactively "^org-test-export-" " *org export tests*")