1 ;;; test-org-export.el --- Tests for org-export.el
3 ;; Copyright (C) 2012 Nicolas Goaziou
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
7 ;; Released under the GNU General Public License version 3
8 ;; see: http://www.gnu.org/licenses/gpl-3.0.html
16 (unless (featurep 'org-export
)
17 (signal 'missing-test-dependency
"org-export"))
19 (defmacro org-test-with-backend
(backend &rest body
)
20 "Execute body with an export back-end defined.
22 BACKEND is the name of the back-end. BODY is the body to
23 execute. The defined back-end simply returns parsed data as Org
25 (declare (debug (form body
)) (indent 1))
26 `(let ((org-export-registered-backends
30 (let (transcode-table)
31 (dolist (type (append org-element-all-elements
32 org-element-all-objects
)
36 (lambda (obj contents info
)
38 (intern (format "org-element-%s-interpreter"
41 transcode-table
)))))))
44 (defmacro org-test-with-parsed-data
(data &rest body
)
45 "Execute body with parsed data available.
47 DATA is a string containing the data to be parsed. BODY is the
48 body to execute. Parse tree is available under the `tree'
49 variable, and communication channel under `info'.
51 This function calls `org-export-collect-tree-properties'. As
52 such, `:ignore-list' (for `org-element-map') and
53 `:parse-tree' (for `org-export-get-genealogy') properties are
54 already filled in `info'."
55 (declare (debug (form body
)) (indent 1))
56 `(org-test-with-temp-text ,data
57 (let* ((tree (org-element-parse-buffer))
58 (info (org-export-collect-tree-properties
59 tree
(org-export-get-environment))))
66 (ert-deftest test-org-export
/bind-keyword
()
67 "Test reading #+BIND: keywords."
68 ;; Test with `org-export-all-BIND' set to t.
70 (org-test-with-temp-text "#+BIND: variable value"
71 (let ((org-export-allow-BIND t
))
72 (org-export--install-letbind-maybe)
73 (eq variable
'value
))))
74 ;; Test with `org-export-all-BIND' set to nil.
76 (org-test-with-temp-text "#+BIND: variable value"
77 (let ((org-export-allow-BIND nil
))
78 (org-export--install-letbind-maybe)
80 ;; Test with `org-export-all-BIND' set to 'confirm and
81 ;; `org-export--allow-BIND-local' to t .
83 (org-test-with-temp-text "#+BIND: variable value"
84 (let ((org-export-allow-BIND 'confirm
))
85 (org-set-local 'org-export--allow-BIND-local t
)
86 (org-export--install-letbind-maybe)
87 (eq variable
'value
))))
88 ;; Test with `org-export-all-BIND' set to 'confirm and
89 ;; `org-export--allow-BIND-local' to nil.
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 nil
)
94 (org-export--install-letbind-maybe)
96 ;; BIND keywords are case-insensitive.
98 (org-test-with-temp-text "#+bind: variable value"
99 (let ((org-export-allow-BIND t
))
100 (org-export--install-letbind-maybe)
101 (eq variable
'value
)))))
103 (ert-deftest test-org-export
/parse-option-keyword
()
104 "Test reading all standard #+OPTIONS: items."
107 (org-export--parse-option-keyword
108 "H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t
109 *:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t inline:nil
112 1 :preserve-breaks t
:section-numbers t
:time-stamp-file t
113 :with-archived-trees t
:with-author t
:with-creator t
:with-drawers t
114 :with-email t
:with-emphasize t
:with-entities t
:with-fixed-width t
115 :with-footnotes t
:with-inlinetasks nil
:with-priority t
116 :with-special-strings t
:with-statistics-cookies t
:with-sub-superscript t
117 :with-toc t
:with-tables t
:with-tags t
:with-tasks t
:with-timestamps t
118 :with-todo-keywords t
)))
119 ;; Test some special values.
122 (org-export--parse-option-keyword
123 "arch:headline creator:comment d:(\"TEST\")
124 ^:{} toc:1 tags:not-in-toc tasks:todo num:2 <:active")
127 :with-archived-trees headline
:with-creator comment
128 :with-drawers
("TEST") :with-sub-superscript
{} :with-toc
1
129 :with-tags not-in-toc
:with-tasks todo
:with-timestamps active
))))
131 (ert-deftest test-org-export
/get-inbuffer-options
()
132 "Test reading all standard export keywords."
135 (org-test-with-temp-text "#+AUTHOR: Me, Myself and I
138 #+DESCRIPTION: Testing
139 #+DESCRIPTION: with two lines
140 #+EMAIL: some@email.org
141 #+EXCLUDE_TAGS: noexport invisible
144 #+SELECT_TAGS: export
146 #+TITLE: with spaces"
147 (org-export--get-inbuffer-options))
149 ("Me, Myself and I") :creator
"Idem" :date
("Today")
150 :description
"Testing\nwith two lines" :email
"some@email.org"
151 :exclude-tags
("noexport" "invisible") :keywords
"test" :language
"en"
152 :select-tags
("export") :title
("Some title with spaces")))))
154 (ert-deftest test-org-export
/get-subtree-options
()
155 "Test setting options from headline's properties."
157 (org-test-with-temp-text "#+TITLE: Title
160 :EXPORT_TITLE: Subtree Title
164 (should (equal (plist-get (org-export-get-environment nil t
) :title
)
165 '("Subtree Title"))))
169 (org-test-with-temp-text "#+OPTIONS: H:1
177 (= 2 (plist-get (org-export-get-environment nil t
) :headline-levels
))))
179 (org-test-with-temp-text "#+DATE: today
182 :EXPORT_DATE: 29-03-2012
186 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
188 ;; Properties with `split' behaviour are stored as a list of
192 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
195 :EXPORT_EXCLUDE_TAGS: a b
200 (plist-get (org-export-get-environment nil t
) :exclude-tags
)))))
201 ;; Handle :PROPERTY+: syntax.
204 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
207 :EXPORT_EXCLUDE_TAGS: a
208 :EXPORT_EXCLUDE_TAGS+: b
213 (plist-get (org-export-get-environment nil t
) :exclude-tags
)))))
214 ;; Export properties are case-insensitive.
215 (org-test-with-temp-text "* Headline
217 :EXPORT_Date: 29-03-2012
220 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
223 (ert-deftest test-org-export
/handle-options
()
224 "Test if export options have an impact on output."
225 ;; Test exclude tags.
226 (org-test-with-temp-text "* Head1 :noexport:"
227 (org-test-with-backend test
229 (equal (org-export-as 'test nil nil nil
'(:exclude-tags
("noexport")))
231 ;; Test include tags.
232 (org-test-with-temp-text "
235 ** Sub-Head2.1 :export:
238 (org-test-with-backend test
241 "* Head2\n** Sub-Head2.1 :export:\n*** Sub-Head2.1.1\n"
242 (let ((org-tags-column 0))
243 (org-export-as 'test nil nil nil
'(:select-tags
("export"))))))))
244 ;; Test mixing include tags and exclude tags.
245 (org-test-with-temp-text "
247 ** Sub-Head1 :noexport:
250 ** Sub-Head1 :export:"
251 (org-test-with-backend test
254 "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
257 '(:select-tags
("export") :exclude-tags
("noexport")))))))
259 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
260 (org-test-with-temp-text "* TODO Head1"
261 (org-test-with-backend test
262 (should (equal (org-export-as 'test nil nil nil
'(:with-tasks nil
))
264 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
265 (org-test-with-temp-text "* TODO Head1"
266 (org-test-with-backend test
267 (should (equal (org-export-as 'test nil nil nil
'(:with-tasks t
))
268 "* TODO Head1\n")))))
270 (org-test-with-temp-text "* Head1 :archive:"
271 (let ((org-archive-tag "archive"))
272 (org-test-with-backend test
274 (equal (org-export-as 'test nil nil nil
'(:with-archived-trees nil
))
276 (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
277 (let ((org-archive-tag "archive"))
278 (org-test-with-backend test
281 "\\* Head1[ \t]+:archive:"
282 (org-export-as 'test nil nil nil
283 '(:with-archived-trees headline
)))))))
284 (org-test-with-temp-text "* Head1 :archive:"
285 (let ((org-archive-tag "archive"))
286 (org-test-with-backend test
289 "\\`\\* Head1[ \t]+:archive:\n\\'"
290 (org-export-as 'test nil nil nil
'(:with-archived-trees t
)))))))
292 (let ((org-drawers '("TEST")))
293 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
294 (org-test-with-backend test
295 (should (equal (org-export-as 'test nil nil nil
'(:with-drawers nil
))
297 (should (equal (org-export-as 'test nil nil nil
'(:with-drawers t
))
298 ":TEST:\ncontents\n:END:\n")))))
299 (let ((org-drawers '("FOO" "BAR")))
300 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
301 (org-test-with-backend test
303 (equal (org-export-as 'test nil nil nil
'(:with-drawers
("FOO")))
304 ":FOO:\nkeep\n:END:\n")))))
306 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
307 (org-test-with-backend test
309 (equal (org-export-as 'test nil nil nil
'(:with-timestamps t
))
310 "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>\n"))
312 (equal (org-export-as 'test nil nil nil
'(:with-timestamps nil
)) ""))
314 (equal (org-export-as 'test nil nil nil
'(:with-timestamps active
))
315 "<2012-04-29 sun. 10:45>\n"))
317 (equal (org-export-as 'test nil nil nil
'(:with-timestamps inactive
))
318 "[2012-04-29 sun. 10:45]\n"))))
320 (let ((org-clock-string "CLOCK:"))
321 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
322 (org-test-with-backend test
324 (equal (org-export-as 'test nil nil nil
'(:with-clocks t
))
325 "CLOCK: [2012-04-29 sun. 10:45]\n"))
327 (equal (org-export-as 'test nil nil nil
'(:with-clocks nil
)) "")))))
329 (let ((org-closed-string "CLOSED:"))
330 (org-test-with-temp-text "CLOSED: [2012-04-29 sun. 10:45]"
331 (org-test-with-backend test
333 (equal (org-export-as 'test nil nil nil
'(:with-plannings t
))
334 "CLOSED: [2012-04-29 sun. 10:45]\n"))
336 (equal (org-export-as 'test nil nil nil
'(:with-plannings nil
))
339 (when (featurep 'org-inlinetask
)
342 (let ((org-inlinetask-min-level 15))
343 (org-test-with-temp-text "*************** Task"
344 (org-test-with-backend test
345 (org-export-as 'test nil nil nil
'(:with-inlinetasks nil
)))))
349 (let ((org-inlinetask-min-level 15))
350 (org-test-with-temp-text
351 "*************** Task\nContents\n*************** END"
352 (org-test-with-backend test
353 (org-export-as 'test nil nil nil
'(:with-inlinetasks nil
)))))
355 ;; Statistics cookies.
358 (org-test-with-temp-text "[0/0]"
359 (org-test-with-backend test
361 'test nil nil nil
'(:with-statistics-cookies nil
)))))))
363 (ert-deftest test-org-export
/comment-tree
()
364 "Test if export process ignores commented trees."
365 (let ((org-comment-string "COMMENT"))
366 (org-test-with-temp-text "* COMMENT Head1"
367 (org-test-with-backend test
368 (should (equal (org-export-as 'test
) ""))))))
370 (ert-deftest test-org-export
/export-scope
()
371 "Test all export scopes."
372 (org-test-with-temp-text "
377 (org-test-with-backend test
380 (should (equal (org-export-as 'test
'subtree
) "text\n*** Head3\n"))
382 (goto-char (point-min))
385 (should (equal (org-export-as 'test nil
'visible
) "* Head1\n"))
387 (goto-char (point-min))
389 (transient-mark-mode 1)
390 (push-mark (point) t t
)
391 (goto-char (point-at-eol))
392 (should (equal (org-export-as 'test
) "text\n"))))
393 ;; Subtree with a code block calling another block outside.
396 (org-test-with-temp-text "
398 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
403 #+BEGIN_SRC emacs-lisp
406 (org-test-with-backend test
408 (org-export-as 'test
'subtree
)))))
410 (org-test-with-temp-text "Text"
411 (org-test-with-backend test
413 (cdr (assq 'test org-export-registered-backends
))
415 (cons (cons 'template
(lambda (body info
) (format "BEGIN\n%sEND" body
)))
416 (org-export-backend-translate-table 'test
)))
417 (should (equal (org-export-as 'test nil nil
'body-only
) "Text\n"))
418 (should (equal (org-export-as 'test
) "BEGIN\nText\nEND")))))
420 (ert-deftest test-org-export
/expand-include
()
421 "Test file inclusion in an Org buffer."
422 ;; Error when file isn't specified.
424 (org-test-with-temp-text "#+INCLUDE: dummy.org"
425 (org-export-expand-include-keyword)))
426 ;; Full insertion with recursive inclusion.
427 (org-test-with-temp-text
428 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir
)
429 (org-export-expand-include-keyword)
430 (should (equal (buffer-string)
431 "Small Org file with an include keyword.
433 #+BEGIN_SRC emacs-lisp :exports results\n(+ 2 1)\n#+END_SRC
439 ;; Localized insertion.
440 (org-test-with-temp-text
441 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
443 (org-export-expand-include-keyword)
444 (should (equal (buffer-string)
445 "Small Org file with an include keyword.\n")))
446 ;; Insertion with constraints on headlines level.
447 (org-test-with-temp-text
449 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\""
451 (org-export-expand-include-keyword)
452 (should (equal (buffer-string) "* Top heading\n** Heading\nbody\n")))
453 ;; Inclusion within an example block.
454 (org-test-with-temp-text
455 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" example"
457 (org-export-expand-include-keyword)
461 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n")))
462 ;; Inclusion within a src-block.
463 (org-test-with-temp-text
465 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" src emacs-lisp"
467 (org-export-expand-include-keyword)
468 (should (equal (buffer-string)
469 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"))))
471 (ert-deftest test-org-export
/expand-macro
()
472 "Test macro expansion in an Org buffer."
473 ;; Standard macro expansion.
475 (equal "#+MACRO: macro1 value\nvalue\n"
476 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
477 (org-test-with-backend test
(org-export-as 'test
)))))
478 ;; Expand specific macros.
480 (equal "me 2012-03-29 me@here Title\n"
481 (org-test-with-temp-text
487 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
488 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
489 (substring output
(string-match ".*\n\\'" output
))))))
490 ;; Expand specific macros when property contained a regular macro
494 (org-test-with-temp-text "
495 #+MACRO: macro1 value
496 #+TITLE: {{{macro1}}}
498 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
499 (substring output
(string-match ".*\n\\'" output
))))))
500 ;; Expand macros with templates in included files.
503 (org-test-with-temp-text
504 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
505 {{{included-macro}}}" org-test-dir
)
506 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
507 (substring output
(string-match ".*\n\\'" output
)))))))
509 (ert-deftest test-org-export
/user-ignore-list
()
510 "Test if `:ignore-list' accepts user input."
511 (org-test-with-backend test
512 (flet ((skip-note-head
514 ;; Ignore headlines with the word "note" in their title.
518 (when (string-match "\\<note\\>"
519 (org-element-property :raw-value headline
))
520 (org-export-ignore-element headline info
)))
523 ;; Install function in parse tree filters.
524 (let ((org-export-filter-parse-tree-functions '(skip-note-head)))
525 (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
526 (should (equal (org-export-as 'test
) "* Head1\n")))))))
528 (ert-deftest test-org-export
/before-processing-hook
()
529 "Test `org-export-before-processing-hook'."
532 "#+MACRO: mac val\nTest\n"
533 (org-test-with-backend test
534 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
535 (let ((org-export-before-processing-hook
537 (while (re-search-forward "{{{" nil t
)
538 (let ((object (org-element-context)))
539 (when (eq (org-element-type object
) 'macro
)
541 (org-element-property :begin object
)
542 (org-element-property :end object
)))))))))
543 (org-export-as 'test
)))))))
545 (ert-deftest test-org-export
/before-parsing-hook
()
546 "Test `org-export-before-parsing-hook'."
548 (equal "Body 1\nBody 2\n"
549 (org-test-with-backend test
550 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
551 (let ((org-export-before-parsing-hook
555 (delete-region (point) (progn (forward-line) (point)))))))))
556 (org-export-as 'test
)))))))
560 ;;; Affiliated Keywords
562 (ert-deftest test-org-export
/read-attribute
()
563 "Test `org-export-read-attribute' specifications."
567 (org-export-read-attribute
569 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
570 (org-element-at-point)))
572 ;; Return nil on empty attribute.
574 (org-export-read-attribute
576 (org-test-with-temp-text "Paragraph" (org-element-at-point)))))
578 (ert-deftest test-org-export
/get-caption
()
579 "Test `org-export-get-caption' specifications."
580 ;; Without optional argument, return long caption
584 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
585 (org-export-get-caption (org-element-at-point)))))
586 ;; With optional argument, return short caption.
590 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
591 (org-export-get-caption (org-element-at-point) t
))))
592 ;; Multiple lines are separated by white spaces.
596 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
597 (org-export-get-caption (org-element-at-point))))))
601 ;;; Back-end Definition
603 (ert-deftest test-org-export
/define-backend
()
604 "Test back-end definition and accessors."
607 (equal '((headline . my-headline-test
))
608 (let (org-export-registered-backends)
609 (org-export-define-backend test
((headline . my-headline-test
)))
610 (org-export-backend-translate-table 'test
))))
613 (equal '((:filter-headline . my-filter
))
614 (let (org-export-registered-backends)
615 (org-export-define-backend test
616 ((headline . my-headline-test
))
617 :filters-alist
((:filter-headline . my-filter
)))
618 (org-export-backend-filters 'test
))))
621 (equal '((:prop value
))
622 (let (org-export-registered-backends)
623 (org-export-define-backend test
624 ((headline . my-headline-test
))
625 :options-alist
((:prop value
)))
626 (org-export-backend-options 'test
))))
629 (equal '(?k
"Test Export" test
)
630 (let (org-export-registered-backends)
631 (org-export-define-backend test
632 ((headline . my-headline-test
))
633 :menu-entry
(?k
"Test Export" test
))
634 (org-export-backend-menu 'test
))))
637 (equal '(("TEST" . org-element-export-block-parser
))
638 (let (org-export-registered-backends org-element-block-name-alist
)
639 (org-export-define-backend test
640 ((headline . my-headline-test
))
641 :export-block
("test"))
642 org-element-block-name-alist
))))
644 (ert-deftest test-org-export
/define-derived-backend
()
645 "Test `org-export-define-derived-backend' specifications."
646 ;; Error when parent back-end is not defined.
648 (let (org-export-registered-backends)
649 (org-export-define-derived-backend test parent
)))
650 ;; Append translation table to parent's.
652 (equal '((:headline . test
) (:headline . parent
))
653 (let (org-export-registered-backends)
654 (org-export-define-backend parent
((:headline . parent
)))
655 (org-export-define-derived-backend test parent
656 :translate-alist
((:headline . test
)))
657 (org-export-backend-translate-table 'test
)))))
659 (ert-deftest test-org-export
/derived-backend-p
()
660 "Test `org-export-derived-backend-p' specifications."
661 ;; Non-nil with direct match.
663 (let (org-export-registered-backends)
664 (org-export-define-backend test
((headline . test
)))
665 (org-export-derived-backend-p 'test
'test
)))
667 (let (org-export-registered-backends)
668 (org-export-define-backend test
((headline . test
)))
669 (org-export-define-derived-backend test2 test
)
670 (org-export-derived-backend-p 'test2
'test2
)))
671 ;; Non-nil with a direct parent.
673 (let (org-export-registered-backends)
674 (org-export-define-backend test
((headline . test
)))
675 (org-export-define-derived-backend test2 test
)
676 (org-export-derived-backend-p 'test2
'test
)))
677 ;; Non-nil with an indirect parent.
679 (let (org-export-registered-backends)
680 (org-export-define-backend test
((headline . test
)))
681 (org-export-define-derived-backend test2 test
)
682 (org-export-define-derived-backend test3 test2
)
683 (org-export-derived-backend-p 'test3
'test
)))
686 (let (org-export-registered-backends)
687 (org-export-define-backend test
((headline . test
)))
688 (org-export-define-backend test2
((headline . test2
)))
689 (org-export-derived-backend-p 'test2
'test
)))
691 (let (org-export-registered-backends)
692 (org-export-define-backend test
((headline . test
)))
693 (org-export-define-backend test2
((headline . test2
)))
694 (org-export-define-derived-backend test3 test2
)
695 (org-export-derived-backend-p 'test3
'test
))))
701 (ert-deftest test-org-export
/export-snippet
()
702 "Test export snippets transcoding."
703 (org-test-with-temp-text "@@test:A@@@@t:B@@"
704 (org-test-with-backend test
706 (cdr (assq 'test org-export-registered-backends
))
708 (cons (cons 'export-snippet
709 (lambda (snippet contents info
)
710 (when (eq (org-export-snippet-backend snippet
) 'test
)
711 (org-element-property :value snippet
))))
712 (org-export-backend-translate-table 'test
)))
713 (let ((org-export-snippet-translation-alist nil
))
714 (should (equal (org-export-as 'test
) "A\n")))
715 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
716 (should (equal (org-export-as 'test
) "AB\n"))))))
722 (ert-deftest test-org-export
/footnotes
()
723 "Test footnotes specifications."
724 (let ((org-footnote-section nil
)
725 (org-export-with-footnotes t
))
726 ;; 1. Read every type of footnote.
729 '((1 .
"A\n") (2 .
"B") (3 .
"C") (4 .
"D"))
730 (org-test-with-parsed-data
731 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
733 tree
'footnote-reference
735 (let ((def (org-export-get-footnote-definition ref info
)))
736 (cons (org-export-get-footnote-number ref info
)
737 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
738 (car (org-element-contents
739 (car (org-element-contents def
))))))))
741 ;; 2. Test nested footnotes order.
742 (org-test-with-parsed-data
743 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
746 '((1 .
"fn:1") (2 .
"fn:2") (3 .
"fn:3") (4))
748 tree
'footnote-reference
750 (when (org-export-footnote-first-reference-p ref info
)
751 (cons (org-export-get-footnote-number ref info
)
752 (org-element-property :label ref
))))
754 ;; 3. Test nested footnote in invisible definitions.
755 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
757 (narrow-to-region (point) (point-at-eol))
758 (let* ((tree (org-element-parse-buffer))
759 (info (org-combine-plists
761 (org-export-collect-tree-properties
762 tree
(org-export-get-environment)))))
763 ;; Both footnotes should be seen.
765 (= (length (org-export-collect-footnote-definitions tree info
)) 2))))
766 ;; 4. Test footnotes definitions collection.
767 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
769 \[fn:2] B [fn:3] [fn::D].
772 (should (= (length (org-export-collect-footnote-definitions tree info
))
774 ;; 5. Test export of footnotes defined outside parsing scope.
775 (org-test-with-temp-text "[fn:1] Out of scope
778 (org-test-with-backend test
780 (cdr (assq 'test org-export-registered-backends
))
782 (cons (cons 'footnote-reference
783 (lambda (fn contents info
)
784 (org-element-interpret-data
785 (org-export-get-footnote-definition fn info
))))
786 (org-export-backend-translate-table 'test
)))
788 (should (equal "ParagraphOut of scope\n"
789 (org-export-as 'test
'subtree
)))))))
793 ;;; Headlines and Inlinetasks
795 (ert-deftest test-org-export
/get-relative-level
()
796 "Test `org-export-get-relative-level' specifications."
800 (let ((org-odd-levels-only nil
))
801 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
804 (lambda (h) (org-export-get-relative-level h info
))
809 (let ((org-odd-levels-only nil
))
810 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
813 (lambda (h) (org-export-get-relative-level h info
))
816 (ert-deftest test-org-export
/low-level-p
()
817 "Test `org-export-low-level-p' specifications."
821 (let ((org-odd-levels-only nil
))
822 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
825 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
826 (plist-put info
:headline-levels
1)))))))
828 (ert-deftest test-org-export
/get-headline-number
()
829 "Test `org-export-get-headline-number' specifications."
834 (let ((org-odd-levels-only nil
))
835 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
838 (lambda (h) (org-export-get-headline-number h info
))
840 ;; Missing levels are replaced with 0.
844 (let ((org-odd-levels-only nil
))
845 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
848 (lambda (h) (org-export-get-headline-number h info
))
851 (ert-deftest test-org-export
/numbered-headline-p
()
852 "Test `org-export-numbered-headline-p' specifications."
853 ;; If `:section-numbers' is nil, never number headlines.
855 (org-test-with-parsed-data "* Headline"
858 (lambda (h) (org-export-numbered-headline-p h info
))
859 (plist-put info
:section-numbers nil
))))
860 ;; If `:section-numbers' is a number, only number headlines with
861 ;; a level greater that it.
865 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
868 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
869 (plist-put info
:section-numbers
1)))))
870 ;; Otherwise, headlines are always numbered.
872 (org-test-with-parsed-data "* Headline"
875 (lambda (h) (org-export-numbered-headline-p h info
))
876 (plist-put info
:section-numbers t
)))))
878 (ert-deftest test-org-export
/number-to-roman
()
879 "Test `org-export-number-to-roman' specifications."
880 ;; If number is negative, return it as a string.
881 (should (equal (org-export-number-to-roman -
1) "-1"))
882 ;; Otherwise, return it as a roman number.
883 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
885 (ert-deftest test-org-export
/get-tags
()
886 "Test `org-export-get-tags' specifications."
887 (let ((org-export-exclude-tags '("noexport"))
888 (org-export-select-tags '("export")))
889 ;; Standard test: tags which are not a select tag, an exclude tag,
890 ;; or specified as optional argument shouldn't be ignored.
892 (org-test-with-parsed-data "* Headline :tag:"
893 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
895 ;; Exclude tags are removed.
897 (org-test-with-parsed-data "* Headline :noexport:"
898 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
900 ;; Select tags are removed.
902 (org-test-with-parsed-data "* Headline :export:"
903 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
908 (org-test-with-parsed-data "* Headline :tag:export:"
909 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
911 ;; Tags provided in the optional argument are also ignored.
913 (org-test-with-parsed-data "* Headline :ignore:"
914 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
916 ;; Allow tag inheritance.
920 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
923 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))
924 ;; Tag inheritance checks FILETAGS keywords.
928 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
931 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))))
933 (ert-deftest test-org-export
/get-node-property
()
934 "Test`org-export-get-node-property' specifications."
938 (org-test-with-parsed-data "* Headline
942 (org-export-get-node-property
943 :prop
(org-element-map tree
'headline
'identity nil t
)))))
947 (org-test-with-parsed-data "* Parent
953 (org-export-get-node-property
954 :prop
(org-element-map tree
'paragraph
'identity nil t
) t
))))
955 ;; Cannot return a value before the first headline.
957 (org-test-with-parsed-data "Paragraph
962 (org-export-get-node-property
963 :prop
(org-element-map tree
'paragraph
'identity nil t
)))))
965 (ert-deftest test-org-export
/get-category
()
966 "Test `org-export-get-category' specifications."
970 (org-test-with-parsed-data "* Headline
974 (org-export-get-category
975 (org-element-map tree
'headline
'identity nil t
) info
))))
976 ;; Test inheritance from a parent headline.
978 (equal '("value" "value")
979 (org-test-with-parsed-data "* Headline1
986 (lambda (hl) (org-export-get-category hl info
)) info
))))
987 ;; Test inheritance from #+CATEGORY keyword
990 (org-test-with-parsed-data "#+CATEGORY: value
992 (org-export-get-category
993 (org-element-map tree
'headline
'identity nil t
) info
))))
994 ;; Test inheritance from file name.
997 (org-test-with-parsed-data "* Headline"
998 (let ((info (plist-put info
:input-file
"~/test.org")))
999 (org-export-get-category
1000 (org-element-map tree
'headline
'identity nil t
) info
)))))
1004 (org-test-with-parsed-data "* Headline"
1005 (org-export-get-category
1006 (org-element-map tree
'headline
'identity nil t
) info
)))))
1008 (ert-deftest test-org-export
/first-sibling-p
()
1009 "Test `org-export-first-sibling-p' specifications."
1014 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1017 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1019 ;; Ignore headlines not exported.
1023 (let ((org-export-exclude-tags '("ignore")))
1024 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
1027 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1030 (ert-deftest test-org-export
/last-sibling-p
()
1031 "Test `org-export-last-sibling-p' specifications."
1036 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1039 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1041 ;; Ignore headlines not exported.
1045 (let ((org-export-exclude-tags '("ignore")))
1046 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
1049 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1056 (ert-deftest test-org-export
/get-coderef-format
()
1057 "Test `org-export-get-coderef-format' specifications."
1058 ;; A link without description returns "%s"
1059 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
1061 ;; Return "%s" when path is matched within description.
1062 (should (equal (org-export-get-coderef-format "path" "desc (path)")
1064 ;; Otherwise return description.
1065 (should (equal (org-export-get-coderef-format "path" "desc")
1068 (ert-deftest test-org-export
/inline-image-p
()
1069 "Test `org-export-inline-image-p' specifications."
1071 (org-export-inline-image-p
1072 (org-test-with-temp-text "[[#id]]"
1074 (org-element-parse-buffer) 'link
'identity nil t
))
1075 '(("custom-id" .
"id")))))
1077 (ert-deftest test-org-export
/fuzzy-link
()
1078 "Test fuzzy links specifications."
1079 ;; 1. Links to invisible (keyword) targets should be ignored.
1080 (org-test-with-parsed-data
1081 "Paragraph.\n#+TARGET: Test\n[[Test]]"
1086 (org-export-get-ordinal
1087 (org-export-resolve-fuzzy-link link info
) info
)) info
)))
1088 ;; 2. Link to an headline should return headline's number.
1089 (org-test-with-parsed-data
1090 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
1092 ;; Note: Headline's number is in fact a list of numbers.
1097 (org-export-get-ordinal
1098 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1099 ;; 3. Link to a target in an item should return item's number.
1100 (org-test-with-parsed-data
1101 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
1103 ;; Note: Item's number is in fact a list of numbers.
1108 (org-export-get-ordinal
1109 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1110 ;; 4. Link to a target in a footnote should return footnote's
1112 (org-test-with-parsed-data "
1113 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
1119 (org-export-get-ordinal
1120 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
1121 ;; 5. Link to a named element should return sequence number of that
1123 (org-test-with-parsed-data
1124 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
1130 (org-export-get-ordinal
1131 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1132 ;; 6. Link to a target not within an item, a table, a footnote
1133 ;; reference or definition should return section number.
1134 (org-test-with-parsed-data
1135 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
1141 (org-export-get-ordinal
1142 (org-export-resolve-fuzzy-link link info
) info
)) info t
)))))
1144 (ert-deftest test-org-export
/resolve-coderef
()
1145 "Test `org-export-resolve-coderef' specifications."
1146 (let ((org-coderef-label-format "(ref:%s)"))
1147 ;; 1. A link to a "-n -k -r" block returns line number.
1148 (org-test-with-parsed-data
1149 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
1150 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1151 (org-test-with-parsed-data
1152 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1153 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1154 ;; 2. A link to a "-n -r" block returns line number.
1155 (org-test-with-parsed-data
1156 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
1157 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1158 (org-test-with-parsed-data
1159 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1160 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1161 ;; 3. A link to a "-n" block returns coderef.
1162 (org-test-with-parsed-data
1163 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1164 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1165 (org-test-with-parsed-data
1166 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
1167 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1168 ;; 4. A link to a "-r" block returns line number.
1169 (org-test-with-parsed-data
1170 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1171 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1172 (org-test-with-parsed-data
1173 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
1174 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1175 ;; 5. A link to a block without a switch returns coderef.
1176 (org-test-with-parsed-data
1177 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1178 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1179 (org-test-with-parsed-data
1180 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
1181 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1182 ;; 6. Correctly handle continued line numbers. A "+n" switch
1183 ;; should resume numbering from previous block with numbered
1184 ;; lines, ignoring blocks not numbering lines in the process.
1185 ;; A "-n" switch resets count.
1186 (org-test-with-parsed-data "
1191 #+BEGIN_SRC emacs-lisp
1195 #+BEGIN_SRC emacs-lisp +n -r
1196 \(+ 1 1) (ref:addition)
1199 #+BEGIN_EXAMPLE -n -r
1200 Another text. (ref:text)
1202 (should (= (org-export-resolve-coderef "addition" info
) 2))
1203 (should (= (org-export-resolve-coderef "text" info
) 1)))
1204 ;; 7. Recognize coderef with user-specified syntax.
1205 (org-test-with-parsed-data
1206 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
1207 (should (equal (org-export-resolve-coderef "text" info
) "text")))))
1209 (ert-deftest test-org-export
/resolve-fuzzy-link
()
1210 "Test `org-export-resolve-fuzzy-link' specifications."
1211 ;; 1. Match target objects.
1212 (org-test-with-parsed-data "<<target>> [[target]]"
1214 (org-export-resolve-fuzzy-link
1215 (org-element-map tree
'link
'identity info t
) info
)))
1216 ;; 2. Match target elements.
1217 (org-test-with-parsed-data "#+TARGET: target\n[[target]]"
1219 (org-export-resolve-fuzzy-link
1220 (org-element-map tree
'link
'identity info t
) info
)))
1221 ;; 3. Match named elements.
1222 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
1224 (org-export-resolve-fuzzy-link
1225 (org-element-map tree
'link
'identity info t
) info
)))
1226 ;; 4. Match exact headline's name.
1227 (org-test-with-parsed-data "* My headline\n[[My headline]]"
1229 (org-export-resolve-fuzzy-link
1230 (org-element-map tree
'link
'identity info t
) info
)))
1231 ;; 5. Targets objects have priority over named elements and headline
1233 (org-test-with-parsed-data
1234 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
1238 (org-export-resolve-fuzzy-link
1239 (org-element-map tree
'link
'identity info t
) info
)))))
1240 ;; 6. Named elements have priority over headline titles.
1241 (org-test-with-parsed-data
1242 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
1246 (org-export-resolve-fuzzy-link
1247 (org-element-map tree
'link
'identity info t
) info
)))))
1248 ;; 7. If link's path starts with a "*", only match headline titles,
1250 (org-test-with-parsed-data
1251 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
1255 (org-export-resolve-fuzzy-link
1256 (org-element-map tree
'link
'identity info t
) info
)))))
1257 ;; 8. Return nil if no match.
1258 (org-test-with-parsed-data "[[target]]"
1260 (org-export-resolve-fuzzy-link
1261 (org-element-map tree
'link
'identity info t
) info
))))
1263 (ert-deftest test-org-export
/resolve-id-link
()
1264 "Test `org-export-resolve-id-link' specifications."
1265 ;; 1. Regular test for custom-id link.
1266 (org-test-with-parsed-data "* Headline1
1273 (org-export-resolve-id-link
1274 (org-element-map tree
'link
'identity info t
) info
)))
1275 ;; 2. Failing test for custom-id link.
1276 (org-test-with-parsed-data "* Headline1
1283 (org-export-resolve-id-link
1284 (org-element-map tree
'link
'identity info t
) info
)))
1285 ;; 3. Test for internal id target.
1286 (org-test-with-parsed-data "* Headline1
1293 (org-export-resolve-id-link
1294 (org-element-map tree
'link
'identity info t
) info
)))
1295 ;; 4. Test for external id target.
1296 (org-test-with-parsed-data "[[id:aaaa]]"
1298 (org-export-resolve-id-link
1299 (org-element-map tree
'link
'identity info t
)
1300 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file"))))))))
1302 (ert-deftest test-org-export
/resolve-radio-link
()
1303 "Test `org-export-resolve-radio-link' specifications."
1305 (org-test-with-temp-text "<<<radio>>> radio"
1306 (org-update-radio-target-regexp)
1308 (let* ((tree (org-element-parse-buffer))
1309 (info `(:parse-tree
,tree
)))
1310 (org-export-resolve-radio-link
1311 (org-element-map tree
'link
'identity info t
)
1313 ;; Radio target with objects.
1314 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
1315 (org-update-radio-target-regexp)
1317 (let* ((tree (org-element-parse-buffer))
1318 (info `(:parse-tree
,tree
)))
1319 (org-export-resolve-radio-link
1320 (org-element-map tree
'link
'identity info t
)
1325 ;;; Src-block and example-block
1327 (ert-deftest test-org-export
/unravel-code
()
1328 "Test `org-export-unravel-code' function."
1329 (let ((org-coderef-label-format "(ref:%s)"))
1330 ;; 1. Code without reference.
1331 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
1332 (should (equal (org-export-unravel-code (org-element-at-point))
1334 ;; 2. Code with reference.
1335 (org-test-with-temp-text
1336 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
1337 (should (equal (org-export-unravel-code (org-element-at-point))
1338 '("(+ 1 1)\n" (1 .
"test")))))
1339 ;; 3. Code with user-defined reference.
1340 (org-test-with-temp-text
1341 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
1342 (should (equal (org-export-unravel-code (org-element-at-point))
1343 '("(+ 1 1)\n" (1 .
"test")))))
1344 ;; 4. Code references keys are relative to the current block.
1345 (org-test-with-temp-text "
1354 (should (equal (org-export-unravel-code (org-element-at-point))
1355 '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one")))))))
1361 (ert-deftest test-org-export
/activate-smart-quotes
()
1362 "Test `org-export-activate-smart-quotes' specifications."
1363 ;; Opening double quotes: standard test.
1366 '("some “paragraph")
1367 (let ((org-export-default-language "en"))
1368 (org-test-with-parsed-data "some \"paragraph"
1371 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1373 ;; Opening quotes: at the beginning of a paragraph.
1377 (let ((org-export-default-language "en"))
1378 (org-test-with-parsed-data "\"begin"
1381 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1383 ;; Opening quotes: after an object.
1387 (let ((org-export-default-language "en"))
1388 (org-test-with-parsed-data "=verb= \"begin"
1391 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1393 ;; Closing quotes: standard test.
1396 '("some” paragraph")
1397 (let ((org-export-default-language "en"))
1398 (org-test-with-parsed-data "some\" paragraph"
1401 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1403 ;; Closing quotes: at the end of a paragraph.
1407 (let ((org-export-default-language "en"))
1408 (org-test-with-parsed-data "end\""
1411 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1413 ;; Apostrophe: standard test.
1416 '("It shouldn’t fail")
1417 (let ((org-export-default-language "en"))
1418 (org-test-with-parsed-data "It shouldn't fail"
1421 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1423 ;; Apostrophe: before an object.
1427 (let ((org-export-default-language "en"))
1428 (org-test-with-parsed-data "a'=b="
1431 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1433 ;; Apostrophe: after an object.
1437 (let ((org-export-default-language "en"))
1438 (org-test-with-parsed-data "=code='s"
1441 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1443 ;; Special case: isolated quotes.
1445 (equal '("“" "”")
1446 (let ((org-export-default-language "en"))
1447 (org-test-with-parsed-data "\"$x$\""
1450 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1452 ;; Smart quotes in secondary strings.
1454 (equal '("“" "”")
1455 (let ((org-export-default-language "en"))
1456 (org-test-with-parsed-data "* \"$x$\""
1459 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1461 ;; Smart quotes in document keywords.
1463 (equal '("“" "”")
1464 (let ((org-export-default-language "en"))
1465 (org-test-with-parsed-data "#+TITLE: \"$x$\""
1467 (plist-get info
:title
) 'plain-text
1468 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1470 ;; Smart quotes in parsed affiliated keywords.
1472 (equal '("“" "”" "Paragraph")
1473 (let ((org-export-default-language "en"))
1474 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
1477 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1478 info nil nil t
))))))
1484 (ert-deftest test-org-export
/special-column
()
1485 "Test if the table's special column is properly recognized."
1486 ;; 1. First column is special if it contains only a special marking
1487 ;; characters or empty cells.
1488 (org-test-with-temp-text "
1492 (org-export-table-has-special-column-p
1494 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1495 ;; 2. If the column contains anything else, it isn't special.
1496 (org-test-with-temp-text "
1500 (org-export-table-has-special-column-p
1502 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1503 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
1505 (org-test-with-temp-text "
1514 (org-export-table-has-special-column-p
1516 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1517 ;; 4. A first column with only empty cells isn't considered as
1519 (org-test-with-temp-text "
1523 (org-export-table-has-special-column-p
1525 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
1527 (ert-deftest test-org-export
/table-row-is-special-p
()
1528 "Test `org-export-table-row-is-special-p' specifications."
1529 ;; 1. A row is special if it has a special marking character in the
1531 (org-test-with-parsed-data "| ! | 1 |"
1533 (org-export-table-row-is-special-p
1534 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1535 ;; 2. A row is special when its first field is "/"
1536 (org-test-with-parsed-data "
1540 (org-export-table-row-is-special-p
1541 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1542 ;; 3. A row only containing alignment cookies is also considered as
1544 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
1546 (org-export-table-row-is-special-p
1547 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1548 ;; 4. Everything else isn't considered as special.
1549 (org-test-with-parsed-data "| \alpha | | c |"
1551 (org-export-table-row-is-special-p
1552 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1553 ;; 5. Table's rules are never considered as special rows.
1554 (org-test-with-parsed-data "|---+---|"
1556 (org-export-table-row-is-special-p
1557 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
1559 (ert-deftest test-org-export
/has-header-p
()
1560 "Test `org-export-table-has-header-p' specifications."
1561 ;; 1. With an header.
1562 (org-test-with-parsed-data "
1567 (org-export-table-has-header-p
1568 (org-element-map tree
'table
'identity info
'first-match
)
1570 ;; 2. Without an header.
1571 (org-test-with-parsed-data "
1575 (org-export-table-has-header-p
1576 (org-element-map tree
'table
'identity info
'first-match
)
1578 ;; 3. Don't get fooled with starting and ending rules.
1579 (org-test-with-parsed-data "
1585 (org-export-table-has-header-p
1586 (org-element-map tree
'table
'identity info
'first-match
)
1589 (ert-deftest test-org-export
/table-row-group
()
1590 "Test `org-export-table-row-group' specifications."
1591 ;; 1. A rule creates a new group.
1592 (org-test-with-parsed-data "
1599 (mapcar (lambda (row) (org-export-table-row-group row info
))
1600 (org-element-map tree
'table-row
'identity
)))))
1601 ;; 2. Special rows are ignored in count.
1602 (org-test-with-parsed-data "
1609 (mapcar (lambda (row) (org-export-table-row-group row info
))
1610 (org-element-map tree
'table-row
'identity
)))))
1611 ;; 3. Double rules also are ignored in count.
1612 (org-test-with-parsed-data "
1620 (mapcar (lambda (row) (org-export-table-row-group row info
))
1621 (org-element-map tree
'table-row
'identity
))))))
1623 (ert-deftest test-org-export
/table-cell-width
()
1624 "Test `org-export-table-cell-width' specifications."
1625 ;; 1. Width is primarily determined by width cookies. If no cookie
1626 ;; is found, cell's width is nil.
1627 (org-test-with-parsed-data "
1628 | / | <l> | <6> | <l7> |
1633 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1634 (org-element-map tree
'table-cell
'identity info
)))))
1635 ;; 2. The last width cookie has precedence.
1636 (org-test-with-parsed-data "
1643 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1644 (org-element-map tree
'table-cell
'identity info
)))))
1645 ;; 3. Valid width cookies must have a specific row.
1646 (org-test-with-parsed-data "| <6> | cell |"
1650 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1651 (org-element-map tree
'table-cell
'identity
))))))
1653 (ert-deftest test-org-export
/table-cell-alignment
()
1654 "Test `org-export-table-cell-alignment' specifications."
1655 (let ((org-table-number-fraction 0.5)
1656 (org-table-number-regexp "^[0-9]+$"))
1657 ;; 1. Alignment is primarily determined by alignment cookies.
1658 (org-test-with-temp-text "| <l> | <c> | <r> |"
1659 (let* ((tree (org-element-parse-buffer))
1660 (info `(:parse-tree
,tree
)))
1663 '(left center right
)
1664 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1665 (org-element-map tree
'table-cell
'identity
))))))
1666 ;; 2. The last alignment cookie has precedence.
1667 (org-test-with-parsed-data "
1673 '(right right right
)
1674 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1675 (org-element-map tree
'table-cell
'identity
)))))
1676 ;; 3. If there's no cookie, cell's contents determine alignment.
1677 ;; A column mostly made of cells containing numbers will align
1678 ;; its cells to the right.
1679 (org-test-with-parsed-data "
1685 '(right right right
)
1686 (mapcar (lambda (cell)
1687 (org-export-table-cell-alignment cell info
))
1688 (org-element-map tree
'table-cell
'identity
)))))
1689 ;; 4. Otherwise, they will be aligned to the left.
1690 (org-test-with-parsed-data "
1697 (mapcar (lambda (cell)
1698 (org-export-table-cell-alignment cell info
))
1699 (org-element-map tree
'table-cell
'identity
)))))))
1701 (ert-deftest test-org-export
/table-cell-borders
()
1702 "Test `org-export-table-cell-borders' specifications."
1703 ;; 1. Recognize various column groups indicators.
1704 (org-test-with-parsed-data "| / | < | > | <> |"
1707 '((right bottom top
) (left bottom top
) (right bottom top
)
1708 (right left bottom top
))
1709 (mapcar (lambda (cell)
1710 (org-export-table-cell-borders cell info
))
1711 (org-element-map tree
'table-cell
'identity
)))))
1712 ;; 2. Accept shortcuts to define column groups.
1713 (org-test-with-parsed-data "| / | < | < |"
1716 '((right bottom top
) (right left bottom top
) (left bottom top
))
1717 (mapcar (lambda (cell)
1718 (org-export-table-cell-borders cell info
))
1719 (org-element-map tree
'table-cell
'identity
)))))
1720 ;; 3. A valid column groups row must start with a "/".
1721 (org-test-with-parsed-data "
1725 (equal '((top) (top) (bottom) (bottom))
1726 (mapcar (lambda (cell)
1727 (org-export-table-cell-borders cell info
))
1728 (org-element-map tree
'table-cell
'identity
)))))
1729 ;; 4. Take table rules into consideration.
1730 (org-test-with-parsed-data "
1735 (equal '((below top
) (bottom above
))
1736 (mapcar (lambda (cell)
1737 (org-export-table-cell-borders cell info
))
1738 (org-element-map tree
'table-cell
'identity
)))))
1739 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
1740 ;; (resp. `bottom' and `below') borders. Any special row is
1742 (org-test-with-parsed-data "
1748 (equal '((bottom below top above
))
1750 (mapcar (lambda (cell)
1751 (org-export-table-cell-borders cell info
))
1752 (org-element-map tree
'table-cell
'identity
)))))))
1754 (ert-deftest test-org-export
/table-dimensions
()
1755 "Test `org-export-table-dimensions' specifications."
1756 ;; 1. Standard test.
1757 (org-test-with-parsed-data "
1762 (org-export-table-dimensions
1763 (org-element-map tree
'table
'identity info
'first-match
) info
))))
1764 ;; 2. Ignore horizontal rules and special columns.
1765 (org-test-with-parsed-data "
1772 (org-export-table-dimensions
1773 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
1775 (ert-deftest test-org-export
/table-cell-address
()
1776 "Test `org-export-table-cell-address' specifications."
1777 ;; 1. Standard test: index is 0-based.
1778 (org-test-with-parsed-data "| a | b |"
1780 (equal '((0 .
0) (0 .
1))
1783 (lambda (cell) (org-export-table-cell-address cell info
))
1785 ;; 2. Special column isn't counted, nor are special rows.
1786 (org-test-with-parsed-data "
1791 (org-export-table-cell-address
1792 (car (last (org-element-map tree
'table-cell
'identity info
)))
1794 ;; 3. Tables rules do not count either.
1795 (org-test-with-parsed-data "
1803 (org-export-table-cell-address
1804 (car (last (org-element-map tree
'table-cell
'identity info
)))
1806 ;; 4. Return nil for special cells.
1807 (org-test-with-parsed-data "| / | a |"
1809 (org-export-table-cell-address
1810 (org-element-map tree
'table-cell
'identity nil
'first-match
)
1813 (ert-deftest test-org-export
/get-table-cell-at
()
1814 "Test `org-export-get-table-cell-at' specifications."
1815 ;; 1. Address ignores special columns, special rows and rules.
1816 (org-test-with-parsed-data "
1823 (org-element-contents
1824 (org-export-get-table-cell-at
1826 (org-element-map tree
'table
'identity info
'first-match
)
1828 ;; 2. Return value for a non-existent address is nil.
1829 (org-test-with-parsed-data "| a |"
1831 (org-export-get-table-cell-at
1833 (org-element-map tree
'table
'identity info
'first-match
)
1835 (org-test-with-parsed-data "| / |"
1837 (org-export-get-table-cell-at
1839 (org-element-map tree
'table
'identity info
'first-match
)
1842 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
1843 "Test `org-export-table-cell-starts-colgroup-p' specifications."
1844 ;; 1. A cell at a beginning of a row always starts a column group.
1845 (org-test-with-parsed-data "| a |"
1847 (org-export-table-cell-starts-colgroup-p
1848 (org-element-map tree
'table-cell
'identity info
'first-match
)
1850 ;; 2. Special column should be ignored when determining the
1851 ;; beginning of the row.
1852 (org-test-with-parsed-data "
1856 (org-export-table-cell-starts-colgroup-p
1857 (org-element-map tree
'table-cell
'identity info
'first-match
)
1859 ;; 2. Explicit column groups.
1860 (org-test-with-parsed-data "
1869 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
1872 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
1873 "Test `org-export-table-cell-ends-colgroup-p' specifications."
1874 ;; 1. A cell at the end of a row always ends a column group.
1875 (org-test-with-parsed-data "| a |"
1877 (org-export-table-cell-ends-colgroup-p
1878 (org-element-map tree
'table-cell
'identity info
'first-match
)
1880 ;; 2. Special column should be ignored when determining the
1881 ;; beginning of the row.
1882 (org-test-with-parsed-data "
1886 (org-export-table-cell-ends-colgroup-p
1887 (org-element-map tree
'table-cell
'identity info
'first-match
)
1889 ;; 3. Explicit column groups.
1890 (org-test-with-parsed-data "
1899 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
1902 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
1903 "Test `org-export-table-row-starts-rowgroup-p' specifications."
1904 ;; 1. A row at the beginning of a table always starts a row group.
1905 ;; So does a row following a table rule.
1906 (org-test-with-parsed-data "
1916 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
1918 ;; 2. Special rows should be ignored when determining the beginning
1920 (org-test-with-parsed-data "
1932 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
1935 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
1936 "Test `org-export-table-row-ends-rowgroup-p' specifications."
1937 ;; 1. A row at the end of a table always ends a row group. So does
1938 ;; a row preceding a table rule.
1939 (org-test-with-parsed-data "
1949 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
1951 ;; 2. Special rows should be ignored when determining the beginning
1953 (org-test-with-parsed-data "
1965 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
1968 (ert-deftest test-org-export
/table-row-starts-header-p
()
1969 "Test `org-export-table-row-starts-header-p' specifications."
1970 ;; 1. Only the row starting the first row group starts the table
1972 (org-test-with-parsed-data "
1983 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
1985 ;; 2. A row cannot start an header if there's no header in the
1987 (org-test-with-parsed-data "
1991 (org-export-table-row-starts-header-p
1992 (org-element-map tree
'table-row
'identity info
'first-match
)
1995 (ert-deftest test-org-export
/table-row-ends-header-p
()
1996 "Test `org-export-table-row-ends-header-p' specifications."
1997 ;; 1. Only the row starting the first row group starts the table
1999 (org-test-with-parsed-data "
2010 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
2012 ;; 2. A row cannot start an header if there's no header in the
2014 (org-test-with-parsed-data "
2018 (org-export-table-row-ends-header-p
2019 (org-element-map tree
'table-row
'identity info
'first-match
)
2026 (ert-deftest test-org-export
/get-next-element
()
2027 "Test `org-export-get-next-element' specifications."
2031 (org-test-with-parsed-data "* Headline\n*a* b"
2032 (org-export-get-next-element
2033 (org-element-map tree
'bold
'identity info t
) info
))))
2034 ;; Return nil when no previous element.
2036 (org-test-with-parsed-data "* Headline\na *b*"
2037 (org-export-get-next-element
2038 (org-element-map tree
'bold
'identity info t
) info
)))
2039 ;; Non-exportable elements are ignored.
2041 (let ((org-export-with-timestamps nil
))
2042 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
2043 (org-export-get-next-element
2044 (org-element-map tree
'entity
'identity info t
) info
))))
2045 ;; Find next element in secondary strings.
2048 (org-test-with-parsed-data "* a =verb="
2050 (org-export-get-next-element
2051 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2052 ;; Find next element in document keywords.
2055 (org-test-with-parsed-data "#+TITLE: a =verb="
2057 (org-export-get-next-element
2059 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2060 ;; Find next element in parsed affiliated keywords.
2063 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
2065 (org-export-get-next-element
2066 (org-element-map tree
'plain-text
'identity info t nil t
) info
))))))
2068 (ert-deftest test-org-export
/get-previous-element
()
2069 "Test `org-export-get-previous-element' specifications."
2073 (org-test-with-parsed-data "* Headline\na *b*"
2074 (org-export-get-previous-element
2075 (org-element-map tree
'bold
'identity info t
) info
))))
2076 ;; Return nil when no previous element.
2078 (org-test-with-parsed-data "* Headline\n*a* b"
2079 (org-export-get-previous-element
2080 (org-element-map tree
'bold
'identity info t
) info
)))
2081 ;; Non-exportable elements are ignored.
2083 (let ((org-export-with-timestamps nil
))
2084 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
2085 (org-export-get-previous-element
2086 (org-element-map tree
'entity
'identity info t
) info
))))
2087 ;; Find previous element in secondary strings.
2090 (org-test-with-parsed-data "* =verb= a"
2092 (org-export-get-previous-element
2093 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2094 ;; Find previous element in document keywords.
2097 (org-test-with-parsed-data "#+TITLE: =verb= a"
2099 (org-export-get-previous-element
2101 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2102 ;; Find previous element in parsed affiliated keywords.
2105 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
2107 (org-export-get-previous-element
2108 (org-element-map tree
'plain-text
'identity info t nil t
) info
))))))
2111 (provide 'test-org-export
)
2112 ;;; test-org-export.el end here