1 ;;; test-org-export.el --- Tests for org-export.el
3 ;; Copyright (C) 2012, 2013 Nicolas Goaziou
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
7 ;; This file is not part of GNU Emacs.
9 ;; This program is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
24 (unless (featurep 'org-export
)
25 (signal 'missing-test-dependency
"org-export"))
27 (defmacro org-test-with-backend
(backend &rest body
)
28 "Execute body with an export back-end defined.
30 BACKEND is the name of the back-end. BODY is the body to
31 execute. The defined back-end simply returns parsed data as Org
33 (declare (debug (form body
)) (indent 1))
34 `(let ((org-export-registered-backends
38 (let (transcode-table)
39 (dolist (type (append org-element-all-elements
40 org-element-all-objects
)
44 (lambda (obj contents info
)
46 (intern (format "org-element-%s-interpreter"
49 transcode-table
)))))))
52 (defmacro org-test-with-parsed-data
(data &rest body
)
53 "Execute body with parsed data available.
55 DATA is a string containing the data to be parsed. BODY is the
56 body to execute. Parse tree is available under the `tree'
57 variable, and communication channel under `info'.
59 This function calls `org-export-collect-tree-properties'. As
60 such, `:ignore-list' (for `org-element-map') and
61 `:parse-tree' (for `org-export-get-genealogy') properties are
62 already filled in `info'."
63 (declare (debug (form body
)) (indent 1))
64 `(org-test-with-temp-text ,data
65 (let* ((tree (org-element-parse-buffer))
66 (info (org-export-collect-tree-properties
67 tree
(org-export-get-environment))))
74 (ert-deftest test-org-export
/bind-keyword
()
75 "Test reading #+BIND: keywords."
76 ;; Test with `org-export-all-BIND' set to t.
78 (org-test-with-temp-text "#+BIND: variable value"
79 (let ((org-export-allow-BIND t
))
80 (org-export--install-letbind-maybe)
81 (eq variable
'value
))))
82 ;; Test with `org-export-all-BIND' set to nil.
84 (org-test-with-temp-text "#+BIND: variable value"
85 (let ((org-export-allow-BIND nil
))
86 (org-export--install-letbind-maybe)
88 ;; Test with `org-export-all-BIND' set to 'confirm and
89 ;; `org-export--allow-BIND-local' to t .
91 (org-test-with-temp-text "#+BIND: variable value"
92 (let ((org-export-allow-BIND 'confirm
))
93 (org-set-local 'org-export--allow-BIND-local t
)
94 (org-export--install-letbind-maybe)
95 (eq variable
'value
))))
96 ;; Test with `org-export-all-BIND' set to 'confirm and
97 ;; `org-export--allow-BIND-local' to nil.
99 (org-test-with-temp-text "#+BIND: variable value"
100 (let ((org-export-allow-BIND 'confirm
))
101 (org-set-local 'org-export--allow-BIND-local nil
)
102 (org-export--install-letbind-maybe)
103 (boundp 'variable
))))
104 ;; BIND keywords are case-insensitive.
106 (org-test-with-temp-text "#+bind: variable value"
107 (let ((org-export-allow-BIND t
))
108 (org-export--install-letbind-maybe)
109 (eq variable
'value
)))))
111 (ert-deftest test-org-export
/parse-option-keyword
()
112 "Test reading all standard #+OPTIONS: items."
115 (org-export--parse-option-keyword
116 "H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t
117 *:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t inline:nil
120 1 :preserve-breaks t
:section-numbers t
:time-stamp-file t
121 :with-archived-trees t
:with-author t
:with-creator t
:with-drawers t
122 :with-email t
:with-emphasize t
:with-entities t
:with-fixed-width t
123 :with-footnotes t
:with-inlinetasks nil
:with-priority t
124 :with-special-strings t
:with-statistics-cookies t
:with-sub-superscript t
125 :with-toc t
:with-tables t
:with-tags t
:with-tasks t
:with-timestamps t
126 :with-todo-keywords t
)))
127 ;; Test some special values.
130 (org-export--parse-option-keyword
131 "arch:headline creator:comment d:(\"TEST\")
132 ^:{} toc:1 tags:not-in-toc tasks:todo num:2 <:active")
135 :with-archived-trees headline
:with-creator comment
136 :with-drawers
("TEST") :with-sub-superscript
{} :with-toc
1
137 :with-tags not-in-toc
:with-tasks todo
:with-timestamps active
))))
139 (ert-deftest test-org-export
/get-inbuffer-options
()
140 "Test reading all standard export keywords."
143 (org-test-with-temp-text "#+AUTHOR: Me, Myself and I
146 #+DESCRIPTION: Testing
147 #+DESCRIPTION: with two lines
148 #+EMAIL: some@email.org
149 #+EXCLUDE_TAGS: noexport invisible
152 #+SELECT_TAGS: export
154 #+TITLE: with spaces"
155 (org-export--get-inbuffer-options))
157 ("Me, Myself and I") :creator
"Idem" :date
("Today")
158 :description
"Testing\nwith two lines" :email
"some@email.org"
159 :exclude-tags
("noexport" "invisible") :keywords
"test" :language
"en"
160 :select-tags
("export") :title
("Some title with spaces")))))
162 (ert-deftest test-org-export
/get-subtree-options
()
163 "Test setting options from headline's properties."
165 (org-test-with-temp-text "#+TITLE: Title
168 :EXPORT_TITLE: Subtree Title
172 (should (equal (plist-get (org-export-get-environment nil t
) :title
)
173 '("Subtree Title"))))
177 (org-test-with-temp-text "#+OPTIONS: H:1
185 (= 2 (plist-get (org-export-get-environment nil t
) :headline-levels
))))
187 (org-test-with-temp-text "#+DATE: today
190 :EXPORT_DATE: 29-03-2012
194 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
196 ;; Properties with `split' behaviour are stored as a list of
200 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
203 :EXPORT_EXCLUDE_TAGS: a b
208 (plist-get (org-export-get-environment nil t
) :exclude-tags
)))))
209 ;; Handle :PROPERTY+: syntax.
212 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
215 :EXPORT_EXCLUDE_TAGS: a
216 :EXPORT_EXCLUDE_TAGS+: b
221 (plist-get (org-export-get-environment nil t
) :exclude-tags
)))))
222 ;; Export properties are case-insensitive.
223 (org-test-with-temp-text "* Headline
225 :EXPORT_Date: 29-03-2012
228 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
230 ;; Still grab correct options when section above is empty.
233 (org-test-with-temp-text "* H1\n** H11\n** H12"
234 (progn (forward-line 2)
235 (plist-get (org-export-get-environment nil t
) :title
))))))
237 (ert-deftest test-org-export
/handle-options
()
238 "Test if export options have an impact on output."
239 ;; Test exclude tags.
240 (org-test-with-temp-text "* Head1 :noexport:"
241 (org-test-with-backend test
243 (equal (org-export-as 'test nil nil nil
'(:exclude-tags
("noexport")))
245 ;; Test include tags.
246 (org-test-with-temp-text "
249 ** Sub-Head2.1 :export:
252 (org-test-with-backend test
255 "* Head2\n** Sub-Head2.1 :export:\n*** Sub-Head2.1.1\n"
256 (let ((org-tags-column 0))
257 (org-export-as 'test nil nil nil
'(:select-tags
("export"))))))))
258 ;; Test mixing include tags and exclude tags.
259 (org-test-with-temp-text "
261 ** Sub-Head1 :noexport:
264 ** Sub-Head1 :export:"
265 (org-test-with-backend test
268 "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
271 '(:select-tags
("export") :exclude-tags
("noexport")))))))
273 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
274 (org-test-with-temp-text "* TODO Head1"
275 (org-test-with-backend test
276 (should (equal (org-export-as 'test nil nil nil
'(:with-tasks nil
))
278 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
279 (org-test-with-temp-text "* TODO Head1"
280 (org-test-with-backend test
281 (should (equal (org-export-as 'test nil nil nil
'(:with-tasks t
))
282 "* TODO Head1\n")))))
284 (org-test-with-temp-text "* Head1 :archive:"
285 (let ((org-archive-tag "archive"))
286 (org-test-with-backend test
288 (equal (org-export-as 'test nil nil nil
'(:with-archived-trees nil
))
290 (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
291 (let ((org-archive-tag "archive"))
292 (org-test-with-backend test
295 "\\* Head1[ \t]+:archive:"
296 (org-export-as 'test nil nil nil
297 '(:with-archived-trees headline
)))))))
298 (org-test-with-temp-text "* Head1 :archive:"
299 (let ((org-archive-tag "archive"))
300 (org-test-with-backend test
303 "\\`\\* Head1[ \t]+:archive:\n\\'"
304 (org-export-as 'test nil nil nil
'(:with-archived-trees t
)))))))
306 (let ((org-drawers '("TEST")))
307 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
308 (org-test-with-backend test
309 (should (equal (org-export-as 'test nil nil nil
'(:with-drawers nil
))
311 (should (equal (org-export-as 'test nil nil nil
'(:with-drawers t
))
312 ":TEST:\ncontents\n:END:\n")))))
313 (let ((org-drawers '("FOO" "BAR")))
314 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
315 (org-test-with-backend test
317 (equal (org-export-as 'test nil nil nil
'(:with-drawers
("FOO")))
318 ":FOO:\nkeep\n:END:\n")))))
320 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
321 (org-test-with-backend test
323 (equal (org-export-as 'test nil nil nil
'(:with-timestamps t
))
324 "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>\n"))
326 (equal (org-export-as 'test nil nil nil
'(:with-timestamps nil
)) ""))
328 (equal (org-export-as 'test nil nil nil
'(:with-timestamps active
))
329 "<2012-04-29 sun. 10:45>\n"))
331 (equal (org-export-as 'test nil nil nil
'(:with-timestamps inactive
))
332 "[2012-04-29 sun. 10:45]\n"))))
334 (let ((org-clock-string "CLOCK:"))
335 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
336 (org-test-with-backend test
338 (equal (org-export-as 'test nil nil nil
'(:with-clocks t
))
339 "CLOCK: [2012-04-29 sun. 10:45]\n"))
341 (equal (org-export-as 'test nil nil nil
'(:with-clocks nil
)) "")))))
343 (let ((org-closed-string "CLOSED:"))
344 (org-test-with-temp-text "CLOSED: [2012-04-29 sun. 10:45]"
345 (org-test-with-backend test
347 (equal (org-export-as 'test nil nil nil
'(:with-plannings t
))
348 "CLOSED: [2012-04-29 sun. 10:45]\n"))
350 (equal (org-export-as 'test nil nil nil
'(:with-plannings nil
))
353 (when (featurep 'org-inlinetask
)
356 (let ((org-inlinetask-min-level 15))
357 (org-test-with-temp-text "*************** Task"
358 (org-test-with-backend test
359 (org-export-as 'test nil nil nil
'(:with-inlinetasks nil
)))))
363 (let ((org-inlinetask-min-level 15))
364 (org-test-with-temp-text
365 "*************** Task\nContents\n*************** END"
366 (org-test-with-backend test
367 (org-export-as 'test nil nil nil
'(:with-inlinetasks nil
)))))
369 ;; Statistics cookies.
372 (org-test-with-temp-text "[0/0]"
373 (org-test-with-backend test
375 'test nil nil nil
'(:with-statistics-cookies nil
)))))))
377 (ert-deftest test-org-export
/comment-tree
()
378 "Test if export process ignores commented trees."
379 (let ((org-comment-string "COMMENT"))
380 (org-test-with-temp-text "* COMMENT Head1"
381 (org-test-with-backend test
382 (should (equal (org-export-as 'test
) ""))))))
384 (ert-deftest test-org-export
/export-scope
()
385 "Test all export scopes."
386 (org-test-with-temp-text "
391 (org-test-with-backend test
394 (should (equal (org-export-as 'test
'subtree
) "text\n*** Head3\n"))
396 (goto-char (point-min))
399 (should (equal (org-export-as 'test nil
'visible
) "* Head1\n"))
401 (goto-char (point-min))
403 (transient-mark-mode 1)
404 (push-mark (point) t t
)
405 (goto-char (point-at-eol))
406 (should (equal (org-export-as 'test
) "text\n"))))
407 ;; Subtree with a code block calling another block outside.
410 (org-test-with-temp-text "
412 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
417 #+BEGIN_SRC emacs-lisp
420 (org-test-with-backend test
422 (org-export-as 'test
'subtree
)))))
424 (org-test-with-temp-text "Text"
425 (org-test-with-backend test
427 (cdr (assq 'test org-export-registered-backends
))
429 (cons (cons 'template
(lambda (body info
) (format "BEGIN\n%sEND" body
)))
430 (org-export-backend-translate-table 'test
)))
431 (should (equal (org-export-as 'test nil nil
'body-only
) "Text\n"))
432 (should (equal (org-export-as 'test
) "BEGIN\nText\nEND")))))
434 (ert-deftest test-org-export
/expand-include
()
435 "Test file inclusion in an Org buffer."
436 ;; Error when file isn't specified.
438 (org-test-with-temp-text "#+INCLUDE: dummy.org"
439 (org-export-expand-include-keyword)))
440 ;; Full insertion with recursive inclusion.
441 (org-test-with-temp-text
442 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir
)
443 (org-export-expand-include-keyword)
444 (should (equal (buffer-string)
445 "Small Org file with an include keyword.
447 #+BEGIN_SRC emacs-lisp :exports results\n(+ 2 1)\n#+END_SRC
453 ;; Localized insertion.
454 (org-test-with-temp-text
455 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
457 (org-export-expand-include-keyword)
458 (should (equal (buffer-string)
459 "Small Org file with an include keyword.\n")))
460 ;; Insertion with constraints on headlines level.
461 (org-test-with-temp-text
463 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\""
465 (org-export-expand-include-keyword)
466 (should (equal (buffer-string) "* Top heading\n** Heading\nbody\n")))
467 ;; Inclusion within an example block.
468 (org-test-with-temp-text
469 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" example"
471 (org-export-expand-include-keyword)
475 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n")))
476 ;; Inclusion within a src-block.
477 (org-test-with-temp-text
479 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" src emacs-lisp"
481 (org-export-expand-include-keyword)
482 (should (equal (buffer-string)
483 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"))))
485 (ert-deftest test-org-export
/expand-macro
()
486 "Test macro expansion in an Org buffer."
487 ;; Standard macro expansion.
489 (equal "#+MACRO: macro1 value\nvalue\n"
490 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
491 (org-test-with-backend test
(org-export-as 'test
)))))
492 ;; Expand specific macros.
494 (equal "me 2012-03-29 me@here Title\n"
495 (org-test-with-temp-text
501 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
502 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
503 (substring output
(string-match ".*\n\\'" output
))))))
504 ;; Expand specific macros when property contained a regular macro
508 (org-test-with-temp-text "
509 #+MACRO: macro1 value
510 #+TITLE: {{{macro1}}}
512 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
513 (substring output
(string-match ".*\n\\'" output
))))))
514 ;; Expand macros with templates in included files.
517 (org-test-with-temp-text
518 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
519 {{{included-macro}}}" org-test-dir
)
520 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
521 (substring output
(string-match ".*\n\\'" output
)))))))
523 (ert-deftest test-org-export
/user-ignore-list
()
524 "Test if `:ignore-list' accepts user input."
525 (org-test-with-backend test
526 (flet ((skip-note-head
528 ;; Ignore headlines with the word "note" in their title.
532 (when (string-match "\\<note\\>"
533 (org-element-property :raw-value headline
))
534 (org-export-ignore-element headline info
)))
537 ;; Install function in parse tree filters.
538 (let ((org-export-filter-parse-tree-functions '(skip-note-head)))
539 (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
540 (should (equal (org-export-as 'test
) "* Head1\n")))))))
542 (ert-deftest test-org-export
/before-processing-hook
()
543 "Test `org-export-before-processing-hook'."
546 "#+MACRO: mac val\nTest\n"
547 (org-test-with-backend test
548 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
549 (let ((org-export-before-processing-hook
551 (while (re-search-forward "{{{" nil t
)
552 (let ((object (org-element-context)))
553 (when (eq (org-element-type object
) 'macro
)
555 (org-element-property :begin object
)
556 (org-element-property :end object
)))))))))
557 (org-export-as 'test
)))))))
559 (ert-deftest test-org-export
/before-parsing-hook
()
560 "Test `org-export-before-parsing-hook'."
562 (equal "Body 1\nBody 2\n"
563 (org-test-with-backend test
564 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
565 (let ((org-export-before-parsing-hook
569 (delete-region (point) (progn (forward-line) (point)))))))))
570 (org-export-as 'test
)))))))
574 ;;; Affiliated Keywords
576 (ert-deftest test-org-export
/read-attribute
()
577 "Test `org-export-read-attribute' specifications."
581 (org-export-read-attribute
583 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
584 (org-element-at-point)))
586 ;; Return nil on empty attribute.
588 (org-export-read-attribute
590 (org-test-with-temp-text "Paragraph" (org-element-at-point)))))
592 (ert-deftest test-org-export
/get-caption
()
593 "Test `org-export-get-caption' specifications."
594 ;; Without optional argument, return long caption
598 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
599 (org-export-get-caption (org-element-at-point)))))
600 ;; With optional argument, return short caption.
604 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
605 (org-export-get-caption (org-element-at-point) t
))))
606 ;; Multiple lines are separated by white spaces.
610 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
611 (org-export-get-caption (org-element-at-point))))))
617 (ert-deftest test-org-export
/define-backend
()
618 "Test back-end definition and accessors."
621 (equal '((headline . my-headline-test
))
622 (let (org-export-registered-backends)
623 (org-export-define-backend test
((headline . my-headline-test
)))
624 (org-export-backend-translate-table 'test
))))
627 (equal '((:filter-headline . my-filter
))
628 (let (org-export-registered-backends)
629 (org-export-define-backend test
630 ((headline . my-headline-test
))
631 :filters-alist
((:filter-headline . my-filter
)))
632 (org-export-backend-filters 'test
))))
635 (equal '((:prop value
))
636 (let (org-export-registered-backends)
637 (org-export-define-backend test
638 ((headline . my-headline-test
))
639 :options-alist
((:prop value
)))
640 (org-export-backend-options 'test
))))
643 (equal '(?k
"Test Export" test
)
644 (let (org-export-registered-backends)
645 (org-export-define-backend test
646 ((headline . my-headline-test
))
647 :menu-entry
(?k
"Test Export" test
))
648 (org-export-backend-menu 'test
))))
651 (equal '(("TEST" . org-element-export-block-parser
))
652 (let (org-export-registered-backends org-element-block-name-alist
)
653 (org-export-define-backend test
654 ((headline . my-headline-test
))
655 :export-block
("test"))
656 org-element-block-name-alist
))))
658 (ert-deftest test-org-export
/define-derived-backend
()
659 "Test `org-export-define-derived-backend' specifications."
660 ;; Error when parent back-end is not defined.
662 (let (org-export-registered-backends)
663 (org-export-define-derived-backend test parent
)))
664 ;; Append translation table to parent's.
666 (equal '((:headline . test
) (:headline . parent
))
667 (let (org-export-registered-backends)
668 (org-export-define-backend parent
((:headline . parent
)))
669 (org-export-define-derived-backend test parent
670 :translate-alist
((:headline . test
)))
671 (org-export-backend-translate-table 'test
)))))
673 (ert-deftest test-org-export
/derived-backend-p
()
674 "Test `org-export-derived-backend-p' specifications."
675 ;; Non-nil with direct match.
677 (let (org-export-registered-backends)
678 (org-export-define-backend test
((headline . test
)))
679 (org-export-derived-backend-p 'test
'test
)))
681 (let (org-export-registered-backends)
682 (org-export-define-backend test
((headline . test
)))
683 (org-export-define-derived-backend test2 test
)
684 (org-export-derived-backend-p 'test2
'test2
)))
685 ;; Non-nil with a direct parent.
687 (let (org-export-registered-backends)
688 (org-export-define-backend test
((headline . test
)))
689 (org-export-define-derived-backend test2 test
)
690 (org-export-derived-backend-p 'test2
'test
)))
691 ;; Non-nil with an indirect parent.
693 (let (org-export-registered-backends)
694 (org-export-define-backend test
((headline . test
)))
695 (org-export-define-derived-backend test2 test
)
696 (org-export-define-derived-backend test3 test2
)
697 (org-export-derived-backend-p 'test3
'test
)))
700 (let (org-export-registered-backends)
701 (org-export-define-backend test
((headline . test
)))
702 (org-export-define-backend test2
((headline . test2
)))
703 (org-export-derived-backend-p 'test2
'test
)))
705 (let (org-export-registered-backends)
706 (org-export-define-backend test
((headline . test
)))
707 (org-export-define-backend test2
((headline . test2
)))
708 (org-export-define-derived-backend test3 test2
)
709 (org-export-derived-backend-p 'test3
'test
))))
711 (ert-deftest test-org-export
/with-backend
()
712 "Test `org-export-with-backend' definition."
713 ;; Error when calling an undefined back-end
715 (let (org-export-registered-backends)
716 (org-export-with-backend 'test
"Test")))
717 ;; Error when called back-end doesn't have an appropriate
720 (let (org-export-registered-backends)
721 (org-export-define-backend test
((headline . ignore
)))
722 (org-export-with-backend 'test
"Test")))
723 ;; Otherwise, export using correct transcoder
726 (let (org-export-registered-backends)
727 (org-export-define-backend test
728 ((plain-text .
(lambda (text contents info
) "Failure"))))
729 (org-export-define-backend test2
730 ((plain-text .
(lambda (text contents info
) "Success"))))
731 (org-export-with-backend 'test2
"Test")))))
733 (ert-deftest test-org-export
/data-with-translations
()
734 "Test `org-export-data-with-translations' specifications."
738 (org-export-data-with-translations
740 '((plain-text .
(lambda (text info
) "Success"))
741 (bold .
(lambda (bold contents info
) (concat contents
"!"))))
742 '(:with-emphasize t
)))))
744 (ert-deftest test-org-export
/data-with-backend
()
745 "Test `org-export-data-with-backend' specifications."
746 ;; Error when calling an undefined back-end.
748 (let (org-export-registered-backends)
749 (org-export-data-with-backend 'test
"Test" nil
)))
750 ;; Otherwise, export data recursively, using correct back-end.
754 (let (org-export-registered-backends)
755 (org-export-define-backend test
756 ((plain-text .
(lambda (text info
) "Success"))
757 (bold .
(lambda (bold contents info
) (concat contents
"!")))))
758 (org-export-data-with-backend
759 '(bold nil
"Test") 'test
'(:with-emphasize t
))))))
765 (ert-deftest test-org-export
/export-snippet
()
766 "Test export snippets transcoding."
767 (org-test-with-temp-text "@@test:A@@@@t:B@@"
768 (org-test-with-backend test
770 (cdr (assq 'test org-export-registered-backends
))
772 (cons (cons 'export-snippet
773 (lambda (snippet contents info
)
774 (when (eq (org-export-snippet-backend snippet
) 'test
)
775 (org-element-property :value snippet
))))
776 (org-export-backend-translate-table 'test
)))
777 (let ((org-export-snippet-translation-alist nil
))
778 (should (equal (org-export-as 'test
) "A\n")))
779 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
780 (should (equal (org-export-as 'test
) "AB\n"))))))
786 (ert-deftest test-org-export
/footnotes
()
787 "Test footnotes specifications."
788 (let ((org-footnote-section nil
)
789 (org-export-with-footnotes t
))
790 ;; 1. Read every type of footnote.
793 '((1 .
"A\n") (2 .
"B") (3 .
"C") (4 .
"D"))
794 (org-test-with-parsed-data
795 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
797 tree
'footnote-reference
799 (let ((def (org-export-get-footnote-definition ref info
)))
800 (cons (org-export-get-footnote-number ref info
)
801 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
802 (car (org-element-contents
803 (car (org-element-contents def
))))))))
805 ;; 2. Test nested footnotes order.
806 (org-test-with-parsed-data
807 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
810 '((1 .
"fn:1") (2 .
"fn:2") (3 .
"fn:3") (4))
812 tree
'footnote-reference
814 (when (org-export-footnote-first-reference-p ref info
)
815 (cons (org-export-get-footnote-number ref info
)
816 (org-element-property :label ref
))))
818 ;; 3. Test nested footnote in invisible definitions.
819 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
821 (narrow-to-region (point) (point-at-eol))
822 (let* ((tree (org-element-parse-buffer))
823 (info (org-combine-plists
825 (org-export-collect-tree-properties
826 tree
(org-export-get-environment)))))
827 ;; Both footnotes should be seen.
829 (= (length (org-export-collect-footnote-definitions tree info
)) 2))))
830 ;; 4. Test footnotes definitions collection.
831 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
833 \[fn:2] B [fn:3] [fn::D].
836 (should (= (length (org-export-collect-footnote-definitions tree info
))
838 ;; 5. Test export of footnotes defined outside parsing scope.
839 (org-test-with-temp-text "[fn:1] Out of scope
842 (org-test-with-backend test
844 (cdr (assq 'test org-export-registered-backends
))
846 (cons (cons 'footnote-reference
847 (lambda (fn contents info
)
848 (org-element-interpret-data
849 (org-export-get-footnote-definition fn info
))))
850 (org-export-backend-translate-table 'test
)))
852 (should (equal "ParagraphOut of scope\n"
853 (org-export-as 'test
'subtree
)))))))
857 ;;; Headlines and Inlinetasks
859 (ert-deftest test-org-export
/get-relative-level
()
860 "Test `org-export-get-relative-level' specifications."
864 (let ((org-odd-levels-only nil
))
865 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
868 (lambda (h) (org-export-get-relative-level h info
))
873 (let ((org-odd-levels-only nil
))
874 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
877 (lambda (h) (org-export-get-relative-level h info
))
880 (ert-deftest test-org-export
/low-level-p
()
881 "Test `org-export-low-level-p' specifications."
885 (let ((org-odd-levels-only nil
))
886 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
889 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
890 (plist-put info
:headline-levels
1)))))))
892 (ert-deftest test-org-export
/get-headline-number
()
893 "Test `org-export-get-headline-number' specifications."
898 (let ((org-odd-levels-only nil
))
899 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
902 (lambda (h) (org-export-get-headline-number h info
))
904 ;; Missing levels are replaced with 0.
908 (let ((org-odd-levels-only nil
))
909 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
912 (lambda (h) (org-export-get-headline-number h info
))
915 (ert-deftest test-org-export
/numbered-headline-p
()
916 "Test `org-export-numbered-headline-p' specifications."
917 ;; If `:section-numbers' is nil, never number headlines.
919 (org-test-with-parsed-data "* Headline"
922 (lambda (h) (org-export-numbered-headline-p h info
))
923 (plist-put info
:section-numbers nil
))))
924 ;; If `:section-numbers' is a number, only number headlines with
925 ;; a level greater that it.
929 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
932 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
933 (plist-put info
:section-numbers
1)))))
934 ;; Otherwise, headlines are always numbered.
936 (org-test-with-parsed-data "* Headline"
939 (lambda (h) (org-export-numbered-headline-p h info
))
940 (plist-put info
:section-numbers t
)))))
942 (ert-deftest test-org-export
/number-to-roman
()
943 "Test `org-export-number-to-roman' specifications."
944 ;; If number is negative, return it as a string.
945 (should (equal (org-export-number-to-roman -
1) "-1"))
946 ;; Otherwise, return it as a roman number.
947 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
949 (ert-deftest test-org-export
/get-tags
()
950 "Test `org-export-get-tags' specifications."
951 (let ((org-export-exclude-tags '("noexport"))
952 (org-export-select-tags '("export")))
953 ;; Standard test: tags which are not a select tag, an exclude tag,
954 ;; or specified as optional argument shouldn't be ignored.
956 (org-test-with-parsed-data "* Headline :tag:"
957 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
959 ;; Exclude tags are removed.
961 (org-test-with-parsed-data "* Headline :noexport:"
962 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
964 ;; Select tags are removed.
966 (org-test-with-parsed-data "* Headline :export:"
967 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
972 (org-test-with-parsed-data "* Headline :tag:export:"
973 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
975 ;; Tags provided in the optional argument are also ignored.
977 (org-test-with-parsed-data "* Headline :ignore:"
978 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
980 ;; Allow tag inheritance.
984 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
987 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))
988 ;; Tag inheritance checks FILETAGS keywords.
992 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
995 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))))
997 (ert-deftest test-org-export
/get-node-property
()
998 "Test`org-export-get-node-property' specifications."
1002 (org-test-with-parsed-data "* Headline
1006 (org-export-get-node-property
1007 :prop
(org-element-map tree
'headline
'identity nil t
)))))
1008 ;; Test inheritance.
1011 (org-test-with-parsed-data "* Parent
1017 (org-export-get-node-property
1018 :prop
(org-element-map tree
'paragraph
'identity nil t
) t
))))
1019 ;; Cannot return a value before the first headline.
1021 (org-test-with-parsed-data "Paragraph
1026 (org-export-get-node-property
1027 :prop
(org-element-map tree
'paragraph
'identity nil t
)))))
1029 (ert-deftest test-org-export
/get-category
()
1030 "Test `org-export-get-category' specifications."
1034 (org-test-with-parsed-data "* Headline
1038 (org-export-get-category
1039 (org-element-map tree
'headline
'identity nil t
) info
))))
1040 ;; Test inheritance from a parent headline.
1042 (equal '("value" "value")
1043 (org-test-with-parsed-data "* Headline1
1050 (lambda (hl) (org-export-get-category hl info
)) info
))))
1051 ;; Test inheritance from #+CATEGORY keyword
1054 (org-test-with-parsed-data "#+CATEGORY: value
1056 (org-export-get-category
1057 (org-element-map tree
'headline
'identity nil t
) info
))))
1058 ;; Test inheritance from file name.
1061 (org-test-with-parsed-data "* Headline"
1062 (let ((info (plist-put info
:input-file
"~/test.org")))
1063 (org-export-get-category
1064 (org-element-map tree
'headline
'identity nil t
) info
)))))
1068 (org-test-with-parsed-data "* Headline"
1069 (org-export-get-category
1070 (org-element-map tree
'headline
'identity nil t
) info
)))))
1072 (ert-deftest test-org-export
/first-sibling-p
()
1073 "Test `org-export-first-sibling-p' specifications."
1078 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1081 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1083 ;; Ignore headlines not exported.
1087 (let ((org-export-exclude-tags '("ignore")))
1088 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
1091 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1094 (ert-deftest test-org-export
/last-sibling-p
()
1095 "Test `org-export-last-sibling-p' specifications."
1100 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1103 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1105 ;; Ignore headlines not exported.
1109 (let ((org-export-exclude-tags '("ignore")))
1110 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
1113 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1120 (ert-deftest test-org-export
/get-coderef-format
()
1121 "Test `org-export-get-coderef-format' specifications."
1122 ;; A link without description returns "%s"
1123 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
1125 ;; Return "%s" when path is matched within description.
1126 (should (equal (org-export-get-coderef-format "path" "desc (path)")
1128 ;; Otherwise return description.
1129 (should (equal (org-export-get-coderef-format "path" "desc")
1132 (ert-deftest test-org-export
/inline-image-p
()
1133 "Test `org-export-inline-image-p' specifications."
1135 (org-export-inline-image-p
1136 (org-test-with-temp-text "[[#id]]"
1138 (org-element-parse-buffer) 'link
'identity nil t
))
1139 '(("custom-id" .
"id")))))
1141 (ert-deftest test-org-export
/fuzzy-link
()
1142 "Test fuzzy links specifications."
1143 ;; 1. Links to invisible (keyword) targets should be ignored.
1144 (org-test-with-parsed-data
1145 "Paragraph.\n#+TARGET: Test\n[[Test]]"
1150 (org-export-get-ordinal
1151 (org-export-resolve-fuzzy-link link info
) info
)) info
)))
1152 ;; 2. Link to an headline should return headline's number.
1153 (org-test-with-parsed-data
1154 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
1156 ;; Note: Headline's number is in fact a list of numbers.
1161 (org-export-get-ordinal
1162 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1163 ;; 3. Link to a target in an item should return item's number.
1164 (org-test-with-parsed-data
1165 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
1167 ;; Note: Item's number is in fact a list of numbers.
1172 (org-export-get-ordinal
1173 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1174 ;; 4. Link to a target in a footnote should return footnote's
1176 (org-test-with-parsed-data "
1177 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
1183 (org-export-get-ordinal
1184 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
1185 ;; 5. Link to a named element should return sequence number of that
1187 (org-test-with-parsed-data
1188 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
1194 (org-export-get-ordinal
1195 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1196 ;; 6. Link to a target not within an item, a table, a footnote
1197 ;; reference or definition should return section number.
1198 (org-test-with-parsed-data
1199 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
1205 (org-export-get-ordinal
1206 (org-export-resolve-fuzzy-link link info
) info
)) info t
)))))
1208 (ert-deftest test-org-export
/resolve-coderef
()
1209 "Test `org-export-resolve-coderef' specifications."
1210 (let ((org-coderef-label-format "(ref:%s)"))
1211 ;; 1. A link to a "-n -k -r" block returns line number.
1212 (org-test-with-parsed-data
1213 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
1214 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1215 (org-test-with-parsed-data
1216 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1217 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1218 ;; 2. A link to a "-n -r" block returns line number.
1219 (org-test-with-parsed-data
1220 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
1221 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1222 (org-test-with-parsed-data
1223 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1224 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1225 ;; 3. A link to a "-n" block returns coderef.
1226 (org-test-with-parsed-data
1227 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1228 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1229 (org-test-with-parsed-data
1230 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
1231 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1232 ;; 4. A link to a "-r" block returns line number.
1233 (org-test-with-parsed-data
1234 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1235 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1236 (org-test-with-parsed-data
1237 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
1238 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1239 ;; 5. A link to a block without a switch returns coderef.
1240 (org-test-with-parsed-data
1241 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1242 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1243 (org-test-with-parsed-data
1244 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
1245 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1246 ;; 6. Correctly handle continued line numbers. A "+n" switch
1247 ;; should resume numbering from previous block with numbered
1248 ;; lines, ignoring blocks not numbering lines in the process.
1249 ;; A "-n" switch resets count.
1250 (org-test-with-parsed-data "
1255 #+BEGIN_SRC emacs-lisp
1259 #+BEGIN_SRC emacs-lisp +n -r
1260 \(+ 1 1) (ref:addition)
1263 #+BEGIN_EXAMPLE -n -r
1264 Another text. (ref:text)
1266 (should (= (org-export-resolve-coderef "addition" info
) 2))
1267 (should (= (org-export-resolve-coderef "text" info
) 1)))
1268 ;; 7. Recognize coderef with user-specified syntax.
1269 (org-test-with-parsed-data
1270 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
1271 (should (equal (org-export-resolve-coderef "text" info
) "text")))))
1273 (ert-deftest test-org-export
/resolve-fuzzy-link
()
1274 "Test `org-export-resolve-fuzzy-link' specifications."
1275 ;; 1. Match target objects.
1276 (org-test-with-parsed-data "<<target>> [[target]]"
1278 (org-export-resolve-fuzzy-link
1279 (org-element-map tree
'link
'identity info t
) info
)))
1280 ;; 2. Match target elements.
1281 (org-test-with-parsed-data "#+TARGET: target\n[[target]]"
1283 (org-export-resolve-fuzzy-link
1284 (org-element-map tree
'link
'identity info t
) info
)))
1285 ;; 3. Match named elements.
1286 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
1288 (org-export-resolve-fuzzy-link
1289 (org-element-map tree
'link
'identity info t
) info
)))
1290 ;; 4. Match exact headline's name.
1291 (org-test-with-parsed-data "* My headline\n[[My headline]]"
1293 (org-export-resolve-fuzzy-link
1294 (org-element-map tree
'link
'identity info t
) info
)))
1295 ;; 5. Targets objects have priority over named elements and headline
1297 (org-test-with-parsed-data
1298 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
1302 (org-export-resolve-fuzzy-link
1303 (org-element-map tree
'link
'identity info t
) info
)))))
1304 ;; 6. Named elements have priority over headline titles.
1305 (org-test-with-parsed-data
1306 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
1310 (org-export-resolve-fuzzy-link
1311 (org-element-map tree
'link
'identity info t
) info
)))))
1312 ;; 7. If link's path starts with a "*", only match headline titles,
1314 (org-test-with-parsed-data
1315 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
1319 (org-export-resolve-fuzzy-link
1320 (org-element-map tree
'link
'identity info t
) info
)))))
1321 ;; 8. Return nil if no match.
1322 (org-test-with-parsed-data "[[target]]"
1324 (org-export-resolve-fuzzy-link
1325 (org-element-map tree
'link
'identity info t
) info
))))
1327 (ert-deftest test-org-export
/resolve-id-link
()
1328 "Test `org-export-resolve-id-link' specifications."
1329 ;; 1. Regular test for custom-id link.
1330 (org-test-with-parsed-data "* Headline1
1337 (org-export-resolve-id-link
1338 (org-element-map tree
'link
'identity info t
) info
)))
1339 ;; 2. Failing test for custom-id link.
1340 (org-test-with-parsed-data "* Headline1
1347 (org-export-resolve-id-link
1348 (org-element-map tree
'link
'identity info t
) info
)))
1349 ;; 3. Test for internal id target.
1350 (org-test-with-parsed-data "* Headline1
1357 (org-export-resolve-id-link
1358 (org-element-map tree
'link
'identity info t
) info
)))
1359 ;; 4. Test for external id target.
1360 (org-test-with-parsed-data "[[id:aaaa]]"
1362 (org-export-resolve-id-link
1363 (org-element-map tree
'link
'identity info t
)
1364 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file"))))))))
1366 (ert-deftest test-org-export
/resolve-radio-link
()
1367 "Test `org-export-resolve-radio-link' specifications."
1369 (org-test-with-temp-text "<<<radio>>> radio"
1370 (org-update-radio-target-regexp)
1372 (let* ((tree (org-element-parse-buffer))
1373 (info `(:parse-tree
,tree
)))
1374 (org-export-resolve-radio-link
1375 (org-element-map tree
'link
'identity info t
)
1377 ;; Radio target with objects.
1378 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
1379 (org-update-radio-target-regexp)
1381 (let* ((tree (org-element-parse-buffer))
1382 (info `(:parse-tree
,tree
)))
1383 (org-export-resolve-radio-link
1384 (org-element-map tree
'link
'identity info t
)
1389 ;;; Src-block and example-block
1391 (ert-deftest test-org-export
/unravel-code
()
1392 "Test `org-export-unravel-code' function."
1393 (let ((org-coderef-label-format "(ref:%s)"))
1394 ;; 1. Code without reference.
1395 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
1396 (should (equal (org-export-unravel-code (org-element-at-point))
1398 ;; 2. Code with reference.
1399 (org-test-with-temp-text
1400 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
1401 (should (equal (org-export-unravel-code (org-element-at-point))
1402 '("(+ 1 1)\n" (1 .
"test")))))
1403 ;; 3. Code with user-defined reference.
1404 (org-test-with-temp-text
1405 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
1406 (should (equal (org-export-unravel-code (org-element-at-point))
1407 '("(+ 1 1)\n" (1 .
"test")))))
1408 ;; 4. Code references keys are relative to the current block.
1409 (org-test-with-temp-text "
1418 (should (equal (org-export-unravel-code (org-element-at-point))
1419 '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one")))))))
1425 (ert-deftest test-org-export
/activate-smart-quotes
()
1426 "Test `org-export-activate-smart-quotes' specifications."
1427 ;; Opening double quotes: standard test.
1430 '("some “paragraph")
1431 (let ((org-export-default-language "en"))
1432 (org-test-with-parsed-data "some \"paragraph"
1435 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1437 ;; Opening quotes: at the beginning of a paragraph.
1441 (let ((org-export-default-language "en"))
1442 (org-test-with-parsed-data "\"begin"
1445 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1447 ;; Opening quotes: after an object.
1451 (let ((org-export-default-language "en"))
1452 (org-test-with-parsed-data "=verb= \"begin"
1455 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1457 ;; Closing quotes: standard test.
1460 '("some” paragraph")
1461 (let ((org-export-default-language "en"))
1462 (org-test-with-parsed-data "some\" paragraph"
1465 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1467 ;; Closing quotes: at the end of a paragraph.
1471 (let ((org-export-default-language "en"))
1472 (org-test-with-parsed-data "end\""
1475 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1477 ;; Apostrophe: standard test.
1480 '("It shouldn’t fail")
1481 (let ((org-export-default-language "en"))
1482 (org-test-with-parsed-data "It shouldn't fail"
1485 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1487 ;; Apostrophe: before an object.
1491 (let ((org-export-default-language "en"))
1492 (org-test-with-parsed-data "a'=b="
1495 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1497 ;; Apostrophe: after an object.
1501 (let ((org-export-default-language "en"))
1502 (org-test-with-parsed-data "=code='s"
1505 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1507 ;; Special case: isolated quotes.
1509 (equal '("“" "”")
1510 (let ((org-export-default-language "en"))
1511 (org-test-with-parsed-data "\"$x$\""
1514 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1516 ;; Smart quotes in secondary strings.
1518 (equal '("“" "”")
1519 (let ((org-export-default-language "en"))
1520 (org-test-with-parsed-data "* \"$x$\""
1523 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1525 ;; Smart quotes in document keywords.
1527 (equal '("“" "”")
1528 (let ((org-export-default-language "en"))
1529 (org-test-with-parsed-data "#+TITLE: \"$x$\""
1531 (plist-get info
:title
) 'plain-text
1532 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1534 ;; Smart quotes in parsed affiliated keywords.
1536 (equal '("“" "”" "Paragraph")
1537 (let ((org-export-default-language "en"))
1538 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
1541 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1542 info nil nil t
))))))
1548 (ert-deftest test-org-export
/special-column
()
1549 "Test if the table's special column is properly recognized."
1550 ;; 1. First column is special if it contains only a special marking
1551 ;; characters or empty cells.
1552 (org-test-with-temp-text "
1556 (org-export-table-has-special-column-p
1558 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1559 ;; 2. If the column contains anything else, it isn't special.
1560 (org-test-with-temp-text "
1564 (org-export-table-has-special-column-p
1566 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1567 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
1569 (org-test-with-temp-text "
1578 (org-export-table-has-special-column-p
1580 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1581 ;; 4. A first column with only empty cells isn't considered as
1583 (org-test-with-temp-text "
1587 (org-export-table-has-special-column-p
1589 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
1591 (ert-deftest test-org-export
/table-row-is-special-p
()
1592 "Test `org-export-table-row-is-special-p' specifications."
1593 ;; 1. A row is special if it has a special marking character in the
1595 (org-test-with-parsed-data "| ! | 1 |"
1597 (org-export-table-row-is-special-p
1598 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1599 ;; 2. A row is special when its first field is "/"
1600 (org-test-with-parsed-data "
1604 (org-export-table-row-is-special-p
1605 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1606 ;; 3. A row only containing alignment cookies is also considered as
1608 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
1610 (org-export-table-row-is-special-p
1611 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1612 ;; 4. Everything else isn't considered as special.
1613 (org-test-with-parsed-data "| \alpha | | c |"
1615 (org-export-table-row-is-special-p
1616 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1617 ;; 5. Table's rules are never considered as special rows.
1618 (org-test-with-parsed-data "|---+---|"
1620 (org-export-table-row-is-special-p
1621 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
1623 (ert-deftest test-org-export
/has-header-p
()
1624 "Test `org-export-table-has-header-p' specifications."
1625 ;; 1. With an header.
1626 (org-test-with-parsed-data "
1631 (org-export-table-has-header-p
1632 (org-element-map tree
'table
'identity info
'first-match
)
1634 ;; 2. Without an header.
1635 (org-test-with-parsed-data "
1639 (org-export-table-has-header-p
1640 (org-element-map tree
'table
'identity info
'first-match
)
1642 ;; 3. Don't get fooled with starting and ending rules.
1643 (org-test-with-parsed-data "
1649 (org-export-table-has-header-p
1650 (org-element-map tree
'table
'identity info
'first-match
)
1653 (ert-deftest test-org-export
/table-row-group
()
1654 "Test `org-export-table-row-group' specifications."
1655 ;; 1. A rule creates a new group.
1656 (org-test-with-parsed-data "
1663 (mapcar (lambda (row) (org-export-table-row-group row info
))
1664 (org-element-map tree
'table-row
'identity
)))))
1665 ;; 2. Special rows are ignored in count.
1666 (org-test-with-parsed-data "
1673 (mapcar (lambda (row) (org-export-table-row-group row info
))
1674 (org-element-map tree
'table-row
'identity
)))))
1675 ;; 3. Double rules also are ignored in count.
1676 (org-test-with-parsed-data "
1684 (mapcar (lambda (row) (org-export-table-row-group row info
))
1685 (org-element-map tree
'table-row
'identity
))))))
1687 (ert-deftest test-org-export
/table-cell-width
()
1688 "Test `org-export-table-cell-width' specifications."
1689 ;; 1. Width is primarily determined by width cookies. If no cookie
1690 ;; is found, cell's width is nil.
1691 (org-test-with-parsed-data "
1692 | / | <l> | <6> | <l7> |
1697 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1698 (org-element-map tree
'table-cell
'identity info
)))))
1699 ;; 2. The last width cookie has precedence.
1700 (org-test-with-parsed-data "
1707 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1708 (org-element-map tree
'table-cell
'identity info
)))))
1709 ;; 3. Valid width cookies must have a specific row.
1710 (org-test-with-parsed-data "| <6> | cell |"
1714 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1715 (org-element-map tree
'table-cell
'identity
))))))
1717 (ert-deftest test-org-export
/table-cell-alignment
()
1718 "Test `org-export-table-cell-alignment' specifications."
1719 (let ((org-table-number-fraction 0.5)
1720 (org-table-number-regexp "^[0-9]+$"))
1721 ;; 1. Alignment is primarily determined by alignment cookies.
1722 (org-test-with-temp-text "| <l> | <c> | <r> |"
1723 (let* ((tree (org-element-parse-buffer))
1724 (info `(:parse-tree
,tree
)))
1727 '(left center right
)
1728 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1729 (org-element-map tree
'table-cell
'identity
))))))
1730 ;; 2. The last alignment cookie has precedence.
1731 (org-test-with-parsed-data "
1737 '(right right right
)
1738 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1739 (org-element-map tree
'table-cell
'identity
)))))
1740 ;; 3. If there's no cookie, cell's contents determine alignment.
1741 ;; A column mostly made of cells containing numbers will align
1742 ;; its cells to the right.
1743 (org-test-with-parsed-data "
1749 '(right right right
)
1750 (mapcar (lambda (cell)
1751 (org-export-table-cell-alignment cell info
))
1752 (org-element-map tree
'table-cell
'identity
)))))
1753 ;; 4. Otherwise, they will be aligned to the left.
1754 (org-test-with-parsed-data "
1761 (mapcar (lambda (cell)
1762 (org-export-table-cell-alignment cell info
))
1763 (org-element-map tree
'table-cell
'identity
)))))))
1765 (ert-deftest test-org-export
/table-cell-borders
()
1766 "Test `org-export-table-cell-borders' specifications."
1767 ;; 1. Recognize various column groups indicators.
1768 (org-test-with-parsed-data "| / | < | > | <> |"
1771 '((right bottom top
) (left bottom top
) (right bottom top
)
1772 (right left bottom top
))
1773 (mapcar (lambda (cell)
1774 (org-export-table-cell-borders cell info
))
1775 (org-element-map tree
'table-cell
'identity
)))))
1776 ;; 2. Accept shortcuts to define column groups.
1777 (org-test-with-parsed-data "| / | < | < |"
1780 '((right bottom top
) (right left bottom top
) (left bottom top
))
1781 (mapcar (lambda (cell)
1782 (org-export-table-cell-borders cell info
))
1783 (org-element-map tree
'table-cell
'identity
)))))
1784 ;; 3. A valid column groups row must start with a "/".
1785 (org-test-with-parsed-data "
1789 (equal '((top) (top) (bottom) (bottom))
1790 (mapcar (lambda (cell)
1791 (org-export-table-cell-borders cell info
))
1792 (org-element-map tree
'table-cell
'identity
)))))
1793 ;; 4. Take table rules into consideration.
1794 (org-test-with-parsed-data "
1799 (equal '((below top
) (bottom above
))
1800 (mapcar (lambda (cell)
1801 (org-export-table-cell-borders cell info
))
1802 (org-element-map tree
'table-cell
'identity
)))))
1803 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
1804 ;; (resp. `bottom' and `below') borders. Any special row is
1806 (org-test-with-parsed-data "
1812 (equal '((bottom below top above
))
1814 (mapcar (lambda (cell)
1815 (org-export-table-cell-borders cell info
))
1816 (org-element-map tree
'table-cell
'identity
)))))))
1818 (ert-deftest test-org-export
/table-dimensions
()
1819 "Test `org-export-table-dimensions' specifications."
1820 ;; 1. Standard test.
1821 (org-test-with-parsed-data "
1826 (org-export-table-dimensions
1827 (org-element-map tree
'table
'identity info
'first-match
) info
))))
1828 ;; 2. Ignore horizontal rules and special columns.
1829 (org-test-with-parsed-data "
1836 (org-export-table-dimensions
1837 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
1839 (ert-deftest test-org-export
/table-cell-address
()
1840 "Test `org-export-table-cell-address' specifications."
1841 ;; 1. Standard test: index is 0-based.
1842 (org-test-with-parsed-data "| a | b |"
1844 (equal '((0 .
0) (0 .
1))
1847 (lambda (cell) (org-export-table-cell-address cell info
))
1849 ;; 2. Special column isn't counted, nor are special rows.
1850 (org-test-with-parsed-data "
1855 (org-export-table-cell-address
1856 (car (last (org-element-map tree
'table-cell
'identity info
)))
1858 ;; 3. Tables rules do not count either.
1859 (org-test-with-parsed-data "
1867 (org-export-table-cell-address
1868 (car (last (org-element-map tree
'table-cell
'identity info
)))
1870 ;; 4. Return nil for special cells.
1871 (org-test-with-parsed-data "| / | a |"
1873 (org-export-table-cell-address
1874 (org-element-map tree
'table-cell
'identity nil
'first-match
)
1877 (ert-deftest test-org-export
/get-table-cell-at
()
1878 "Test `org-export-get-table-cell-at' specifications."
1879 ;; 1. Address ignores special columns, special rows and rules.
1880 (org-test-with-parsed-data "
1887 (org-element-contents
1888 (org-export-get-table-cell-at
1890 (org-element-map tree
'table
'identity info
'first-match
)
1892 ;; 2. Return value for a non-existent address is nil.
1893 (org-test-with-parsed-data "| a |"
1895 (org-export-get-table-cell-at
1897 (org-element-map tree
'table
'identity info
'first-match
)
1899 (org-test-with-parsed-data "| / |"
1901 (org-export-get-table-cell-at
1903 (org-element-map tree
'table
'identity info
'first-match
)
1906 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
1907 "Test `org-export-table-cell-starts-colgroup-p' specifications."
1908 ;; 1. A cell at a beginning of a row always starts a column group.
1909 (org-test-with-parsed-data "| a |"
1911 (org-export-table-cell-starts-colgroup-p
1912 (org-element-map tree
'table-cell
'identity info
'first-match
)
1914 ;; 2. Special column should be ignored when determining the
1915 ;; beginning of the row.
1916 (org-test-with-parsed-data "
1920 (org-export-table-cell-starts-colgroup-p
1921 (org-element-map tree
'table-cell
'identity info
'first-match
)
1923 ;; 2. Explicit column groups.
1924 (org-test-with-parsed-data "
1933 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
1936 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
1937 "Test `org-export-table-cell-ends-colgroup-p' specifications."
1938 ;; 1. A cell at the end of a row always ends a column group.
1939 (org-test-with-parsed-data "| a |"
1941 (org-export-table-cell-ends-colgroup-p
1942 (org-element-map tree
'table-cell
'identity info
'first-match
)
1944 ;; 2. Special column should be ignored when determining the
1945 ;; beginning of the row.
1946 (org-test-with-parsed-data "
1950 (org-export-table-cell-ends-colgroup-p
1951 (org-element-map tree
'table-cell
'identity info
'first-match
)
1953 ;; 3. Explicit column groups.
1954 (org-test-with-parsed-data "
1963 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
1966 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
1967 "Test `org-export-table-row-starts-rowgroup-p' specifications."
1968 ;; 1. A row at the beginning of a table always starts a row group.
1969 ;; So does a row following a table rule.
1970 (org-test-with-parsed-data "
1980 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
1982 ;; 2. Special rows should be ignored when determining the beginning
1984 (org-test-with-parsed-data "
1996 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
1999 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
2000 "Test `org-export-table-row-ends-rowgroup-p' specifications."
2001 ;; 1. A row at the end of a table always ends a row group. So does
2002 ;; a row preceding a table rule.
2003 (org-test-with-parsed-data "
2013 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2015 ;; 2. Special rows should be ignored when determining the beginning
2017 (org-test-with-parsed-data "
2029 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
2032 (ert-deftest test-org-export
/table-row-starts-header-p
()
2033 "Test `org-export-table-row-starts-header-p' specifications."
2034 ;; 1. Only the row starting the first row group starts the table
2036 (org-test-with-parsed-data "
2047 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
2049 ;; 2. A row cannot start an header if there's no header in the
2051 (org-test-with-parsed-data "
2055 (org-export-table-row-starts-header-p
2056 (org-element-map tree
'table-row
'identity info
'first-match
)
2059 (ert-deftest test-org-export
/table-row-ends-header-p
()
2060 "Test `org-export-table-row-ends-header-p' specifications."
2061 ;; 1. Only the row starting the first row group starts the table
2063 (org-test-with-parsed-data "
2074 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
2076 ;; 2. A row cannot start an header if there's no header in the
2078 (org-test-with-parsed-data "
2082 (org-export-table-row-ends-header-p
2083 (org-element-map tree
'table-row
'identity info
'first-match
)
2090 (ert-deftest test-org-export
/get-next-element
()
2091 "Test `org-export-get-next-element' specifications."
2095 (org-test-with-parsed-data "* Headline\n*a* b"
2096 (org-export-get-next-element
2097 (org-element-map tree
'bold
'identity info t
) info
))))
2098 ;; Return nil when no previous element.
2100 (org-test-with-parsed-data "* Headline\na *b*"
2101 (org-export-get-next-element
2102 (org-element-map tree
'bold
'identity info t
) info
)))
2103 ;; Non-exportable elements are ignored.
2105 (let ((org-export-with-timestamps nil
))
2106 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
2107 (org-export-get-next-element
2108 (org-element-map tree
'entity
'identity info t
) info
))))
2109 ;; Find next element in secondary strings.
2112 (org-test-with-parsed-data "* a =verb="
2114 (org-export-get-next-element
2115 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2116 ;; Find next element in document keywords.
2119 (org-test-with-parsed-data "#+TITLE: a =verb="
2121 (org-export-get-next-element
2123 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2124 ;; Find next element in parsed affiliated keywords.
2127 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
2129 (org-export-get-next-element
2130 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
2131 ;; With optional argument N, return a list containing all the
2132 ;; following elements.
2135 '(bold code underline
)
2136 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2138 (org-export-get-next-element
2139 (org-element-map tree
'italic
'identity info t
) info t
)))))
2140 ;; When N is a positive integer, return a list containing up to
2141 ;; N following elements.
2145 (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
2147 (org-export-get-next-element
2148 (org-element-map tree
'italic
'identity info t
) info
2))))))
2150 (ert-deftest test-org-export
/get-previous-element
()
2151 "Test `org-export-get-previous-element' specifications."
2155 (org-test-with-parsed-data "* Headline\na *b*"
2156 (org-export-get-previous-element
2157 (org-element-map tree
'bold
'identity info t
) info
))))
2158 ;; Return nil when no previous element.
2160 (org-test-with-parsed-data "* Headline\n*a* b"
2161 (org-export-get-previous-element
2162 (org-element-map tree
'bold
'identity info t
) info
)))
2163 ;; Non-exportable elements are ignored.
2165 (let ((org-export-with-timestamps nil
))
2166 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
2167 (org-export-get-previous-element
2168 (org-element-map tree
'entity
'identity info t
) info
))))
2169 ;; Find previous element in secondary strings.
2172 (org-test-with-parsed-data "* =verb= a"
2174 (org-export-get-previous-element
2175 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2176 ;; Find previous element in document keywords.
2179 (org-test-with-parsed-data "#+TITLE: =verb= a"
2181 (org-export-get-previous-element
2183 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2184 ;; Find previous element in parsed affiliated keywords.
2187 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
2189 (org-export-get-previous-element
2190 (org-element-map tree
'plain-text
'identity info t nil t
) info
)))))
2191 ;; With optional argument N, return a list containing up to
2192 ;; N previous elements.
2194 (equal '(bold italic underline
)
2195 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2197 (org-export-get-previous-element
2198 (org-element-map tree
'code
'identity info t
) info t
)))))
2199 ;; When N is a positive integer, return a list containing up to
2200 ;; N previous elements.
2202 (equal '(bold italic
)
2203 (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
2205 (org-export-get-previous-element
2206 (org-element-map tree
'code
'identity info t
) info
2))))))
2209 (provide 'test-org-export
)
2210 ;;; test-org-export.el end here