ox: Add test for included files.

* testing/lisp/test-ox.el (test-org/expand-include/links): New test.
This commit is contained in:
Nicolas Goaziou 2018-03-18 16:08:37 +01:00
parent d81a1d088c
commit a23be068f6
1 changed files with 113 additions and 0 deletions

View File

@ -1363,6 +1363,119 @@ Footnotes[fn:2], foot[fn:test] and [fn:inline:inline footnote]
(org-export-expand-include-keyword) (org-export-expand-include-keyword)
(eq 3 (org-current-level))))) (eq 3 (org-current-level)))))
(ert-deftest test-org/expand-include/links ()
"Test links modifications when including files."
;; Preserve relative plain links.
(should
(string-prefix-p
"file:org-includee-"
(let* ((subdir (make-temp-file "org-includee-" t))
(includee (expand-file-name "includee.org" subdir))
(includer (make-temp-file "org-includer-")))
(write-region "file:foo.org" nil includee)
(write-region (format "#+INCLUDE: %S"
(file-relative-name includee
temporary-file-directory))
nil includer)
(let ((buffer (find-file-noselect includer t)))
(unwind-protect
(with-current-buffer buffer
(org-export-expand-include-keyword)
(org-trim (buffer-string)))
(when (buffer-live-p buffer)
(with-current-buffer buffer (set-buffer-modified-p nil))
(kill-buffer buffer))
(when (file-exists-p subdir) (delete-directory subdir t))
(when (file-exists-p includer) (delete-file includer)))))))
;; Preserve relative angular links.
(should
(string-prefix-p
"<file:org-includee-"
(let* ((subdir (make-temp-file "org-includee-" t))
(includee (expand-file-name "includee.org" subdir))
(includer (make-temp-file "org-includer-")))
(write-region "<file:foo.org>" nil includee)
(write-region (format "#+INCLUDE: %S"
(file-relative-name includee
temporary-file-directory))
nil includer)
(let ((buffer (find-file-noselect includer t)))
(unwind-protect
(with-current-buffer buffer
(org-export-expand-include-keyword)
(org-trim (buffer-string)))
(when (buffer-live-p buffer)
(with-current-buffer buffer (set-buffer-modified-p nil))
(kill-buffer buffer))
(when (file-exists-p subdir) (delete-directory subdir t))
(when (file-exists-p includer) (delete-file includer)))))))
;; Preserve relative bracket links without description.
(should
(string-prefix-p
"[[file:org-includee-"
(let* ((subdir (make-temp-file "org-includee-" t))
(includee (expand-file-name "includee.org" subdir))
(includer (make-temp-file "org-includer-")))
(write-region "[[file:foo.org]]" nil includee)
(write-region (format "#+INCLUDE: %S"
(file-relative-name includee
temporary-file-directory))
nil includer)
(let ((buffer (find-file-noselect includer t)))
(unwind-protect
(with-current-buffer buffer
(org-export-expand-include-keyword)
(org-trim (buffer-string)))
(when (buffer-live-p buffer)
(with-current-buffer buffer (set-buffer-modified-p nil))
(kill-buffer buffer))
(when (file-exists-p subdir) (delete-directory subdir t))
(when (file-exists-p includer) (delete-file includer)))))))
;; Preserve relative bracket links with description.
(should
(string-prefix-p
"[[file:org-includee-"
(let* ((subdir (make-temp-file "org-includee-" t))
(includee (expand-file-name "includee.org" subdir))
(includer (make-temp-file "org-includer-")))
(write-region "[[file:foo.org][description]]" nil includee)
(write-region (format "#+INCLUDE: %S"
(file-relative-name includee
temporary-file-directory))
nil includer)
(let ((buffer (find-file-noselect includer t)))
(unwind-protect
(with-current-buffer buffer
(org-export-expand-include-keyword)
(org-trim (buffer-string)))
(when (buffer-live-p buffer)
(with-current-buffer buffer (set-buffer-modified-p nil))
(kill-buffer buffer))
(when (file-exists-p subdir) (delete-directory subdir t))
(when (file-exists-p includer) (delete-file includer)))))))
;; Preserve absolute links.
(should
(string=
"[[file:/foo/bar.org]]"
(let* ((subdir (make-temp-file "org-includee-" t))
(includee (expand-file-name "includee.org" subdir))
(includer (make-temp-file "org-includer-")))
(write-region "[[file:/foo/bar.org]]" nil includee)
(write-region (format "#+INCLUDE: %S"
(file-relative-name includee
temporary-file-directory))
nil includer)
(let ((buffer (find-file-noselect includer t)))
(unwind-protect
(with-current-buffer buffer
(org-export-expand-include-keyword)
(org-trim (buffer-string)))
(when (buffer-live-p buffer)
(with-current-buffer buffer (set-buffer-modified-p nil))
(kill-buffer buffer))
(when (file-exists-p subdir) (delete-directory subdir t))
(when (file-exists-p includer) (delete-file includer))))))))
(ert-deftest test-org-export/expand-macro () (ert-deftest test-org-export/expand-macro ()
"Test macro expansion in an Org buffer." "Test macro expansion in an Org buffer."
(require 'ox-org) (require 'ox-org)