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 ((,(intern (format "org-%s-translate-alist" backend
))
27 ',(let (transcode-table)
28 (dolist (type (append org-element-all-elements
29 org-element-all-objects
)
33 (lambda (obj contents info
)
35 (intern (format "org-element-%s-interpreter" type
))
40 (defmacro org-test-with-parsed-data
(data &rest body
)
41 "Execute body with parsed data available.
43 DATA is a string containing the data to be parsed. BODY is the
44 body to execute. Parse tree is available under the `tree'
45 variable, and communication channel under `info'.
47 This function calls `org-export-collect-tree-properties'. As
48 such, `:ignore-list' (for `org-element-map') and
49 `:parse-tree' (for `org-export-get-genealogy') properties are
50 already filled in `info'."
51 (declare (debug (form body
)) (indent 1))
52 `(org-test-with-temp-text ,data
53 (let* ((tree (org-element-parse-buffer))
54 (info (org-export-collect-tree-properties
55 tree
(org-export-get-environment))))
62 (ert-deftest test-org-export
/bind-keyword
()
63 "Test reading #+BIND: keywords."
64 ;; Test with `org-export-all-BIND' set to t.
66 (org-test-with-temp-text "#+BIND: variable value"
67 (let ((org-export-allow-BIND t
))
68 (org-export--install-letbind-maybe)
69 (eq variable
'value
))))
70 ;; Test with `org-export-all-BIND' set to nil.
72 (org-test-with-temp-text "#+BIND: variable value"
73 (let ((org-export-allow-BIND nil
))
74 (org-export--install-letbind-maybe)
76 ;; Test with `org-export-all-BIND' set to 'confirm and
77 ;; `org-export--allow-BIND-local' to t .
79 (org-test-with-temp-text "#+BIND: variable value"
80 (let ((org-export-allow-BIND 'confirm
))
81 (org-set-local 'org-export--allow-BIND-local t
)
82 (org-export--install-letbind-maybe)
83 (eq variable
'value
))))
84 ;; Test with `org-export-all-BIND' set to 'confirm and
85 ;; `org-export--allow-BIND-local' to nil.
87 (org-test-with-temp-text "#+BIND: variable value"
88 (let ((org-export-allow-BIND 'confirm
))
89 (org-set-local 'org-export--allow-BIND-local nil
)
90 (org-export--install-letbind-maybe)
92 ;; BIND keywords are case-insensitive.
94 (org-test-with-temp-text "#+bind: variable value"
95 (let ((org-export-allow-BIND t
))
96 (org-export--install-letbind-maybe)
97 (eq variable
'value
)))))
99 (ert-deftest test-org-export
/parse-option-keyword
()
100 "Test reading all standard #+OPTIONS: items."
103 (org-export--parse-option-keyword
104 "H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t
105 *:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t inline:nil
108 1 :preserve-breaks t
:section-numbers t
:time-stamp-file t
109 :with-archived-trees t
:with-author t
:with-creator t
:with-drawers t
110 :with-email t
:with-emphasize t
:with-entities t
:with-fixed-width t
111 :with-footnotes t
:with-inlinetasks nil
:with-priority t
112 :with-special-strings t
:with-statistics-cookies t
:with-sub-superscript t
113 :with-toc t
:with-tables t
:with-tags t
:with-tasks t
:with-timestamps t
114 :with-todo-keywords t
)))
115 ;; Test some special values.
118 (org-export--parse-option-keyword
119 "arch:headline creator:comment d:(\"TEST\")
120 ^:{} toc:1 tags:not-in-toc tasks:todo num:2 <:active")
123 :with-archived-trees headline
:with-creator comment
124 :with-drawers
("TEST") :with-sub-superscript
{} :with-toc
1
125 :with-tags not-in-toc
:with-tasks todo
:with-timestamps active
))))
127 (ert-deftest test-org-export
/get-inbuffer-options
()
128 "Test reading all standard export keywords."
131 (org-test-with-temp-text "#+AUTHOR: Me, Myself and I
134 #+DESCRIPTION: Testing
135 #+DESCRIPTION: with two lines
136 #+EMAIL: some@email.org
137 #+EXCLUDE_TAGS: noexport invisible
140 #+SELECT_TAGS: export
142 #+TITLE: with spaces"
143 (org-export--get-inbuffer-options))
145 ("Me, Myself and I") :creator
"Idem" :date
("Today")
146 :description
"Testing\nwith two lines" :email
"some@email.org"
147 :exclude-tags
("noexport" "invisible") :keywords
"test" :language
"en"
148 :select-tags
("export") :title
("Some title with spaces")))))
150 (ert-deftest test-org-export
/get-subtree-options
()
151 "Test setting options from headline's properties."
153 (org-test-with-temp-text "#+TITLE: Title
156 :EXPORT_TITLE: Subtree Title
160 (should (equal (plist-get (org-export-get-environment nil t
) :title
)
161 '("Subtree Title"))))
165 (org-test-with-temp-text "#+OPTIONS: H:1
173 (= 2 (plist-get (org-export-get-environment nil t
) :headline-levels
))))
175 (org-test-with-temp-text "#+DATE: today
178 :EXPORT_DATE: 29-03-2012
182 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
184 ;; Export properties are case-insensitive.
185 (org-test-with-temp-text "* Headline
187 :EXPORT_Date: 29-03-2012
190 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
193 (ert-deftest test-org-export
/handle-options
()
194 "Test if export options have an impact on output."
195 ;; Test exclude tags.
196 (org-test-with-temp-text "* Head1 :noexport:"
197 (org-test-with-backend test
199 (equal (org-export-as 'test nil nil nil
'(:exclude-tags
("noexport")))
201 ;; Test include tags.
202 (org-test-with-temp-text "
205 ** Sub-Head2.1 :export:
208 (org-test-with-backend test
211 "* Head2\n** Sub-Head2.1 :export:\n*** Sub-Head2.1.1\n"
212 (let ((org-tags-column 0))
213 (org-export-as 'test nil nil nil
'(:select-tags
("export"))))))))
214 ;; Test mixing include tags and exclude tags.
215 (org-test-with-temp-text "
217 ** Sub-Head1 :noexport:
220 ** Sub-Head1 :export:"
221 (org-test-with-backend test
224 "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
227 '(:select-tags
("export") :exclude-tags
("noexport")))))))
229 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
230 (org-test-with-temp-text "* TODO Head1"
231 (org-test-with-backend test
232 (should (equal (org-export-as 'test nil nil nil
'(:with-tasks nil
))
234 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
235 (org-test-with-temp-text "* TODO Head1"
236 (org-test-with-backend test
237 (should (equal (org-export-as 'test nil nil nil
'(:with-tasks t
))
238 "* TODO Head1\n")))))
240 (org-test-with-temp-text "* Head1 :archive:"
241 (let ((org-archive-tag "archive"))
242 (org-test-with-backend test
244 (equal (org-export-as 'test nil nil nil
'(:with-archived-trees nil
))
246 (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
247 (let ((org-archive-tag "archive"))
248 (org-test-with-backend test
251 "\\* Head1[ \t]+:archive:"
252 (org-export-as 'test nil nil nil
253 '(:with-archived-trees headline
)))))))
254 (org-test-with-temp-text "* Head1 :archive:"
255 (let ((org-archive-tag "archive"))
256 (org-test-with-backend test
259 "\\`\\* Head1[ \t]+:archive:\n\\'"
260 (org-export-as 'test nil nil nil
'(:with-archived-trees t
)))))))
262 (let ((org-drawers '("TEST")))
263 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
264 (org-test-with-backend test
265 (should (equal (org-export-as 'test nil nil nil
'(:with-drawers nil
))
267 (should (equal (org-export-as 'test nil nil nil
'(:with-drawers t
))
268 ":TEST:\ncontents\n:END:\n")))))
269 (let ((org-drawers '("FOO" "BAR")))
270 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
271 (org-test-with-backend test
273 (equal (org-export-as 'test nil nil nil
'(:with-drawers
("FOO")))
274 ":FOO:\nkeep\n:END:\n")))))
276 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
277 (org-test-with-backend test
279 (equal (org-export-as 'test nil nil nil
'(:with-timestamps t
))
280 "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>\n"))
282 (equal (org-export-as 'test nil nil nil
'(:with-timestamps nil
)) ""))
284 (equal (org-export-as 'test nil nil nil
'(:with-timestamps active
))
285 "<2012-04-29 sun. 10:45>\n"))
287 (equal (org-export-as 'test nil nil nil
'(:with-timestamps inactive
))
288 "[2012-04-29 sun. 10:45]\n"))))
290 (let ((org-clock-string "CLOCK:"))
291 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
292 (org-test-with-backend test
294 (equal (org-export-as 'test nil nil nil
'(:with-clocks t
))
295 "CLOCK: [2012-04-29 sun. 10:45]\n"))
297 (equal (org-export-as 'test nil nil nil
'(:with-clocks nil
)) "")))))
299 (let ((org-closed-string "CLOSED:"))
300 (org-test-with-temp-text "CLOSED: [2012-04-29 sun. 10:45]"
301 (org-test-with-backend test
303 (equal (org-export-as 'test nil nil nil
'(:with-plannings t
))
304 "CLOSED: [2012-04-29 sun. 10:45]\n"))
306 (equal (org-export-as 'test nil nil nil
'(:with-plannings nil
))
309 (when (featurep 'org-inlinetask
)
312 (let ((org-inlinetask-min-level 15))
313 (org-test-with-temp-text "*************** Task"
314 (org-test-with-backend test
315 (org-export-as 'test nil nil nil
'(:with-inlinetasks nil
)))))
319 (let ((org-inlinetask-min-level 15))
320 (org-test-with-temp-text
321 "*************** Task\nContents\n*************** END"
322 (org-test-with-backend test
323 (org-export-as 'test nil nil nil
'(:with-inlinetasks nil
)))))
325 ;; Statistics cookies.
328 (org-test-with-temp-text "[0/0]"
329 (org-test-with-backend test
331 'test nil nil nil
'(:with-statistics-cookies nil
)))))))
333 (ert-deftest test-org-export
/comment-tree
()
334 "Test if export process ignores commented trees."
335 (let ((org-comment-string "COMMENT"))
336 (org-test-with-temp-text "* COMMENT Head1"
337 (org-test-with-backend test
338 (should (equal (org-export-as 'test
) ""))))))
340 (ert-deftest test-org-export
/export-scope
()
341 "Test all export scopes."
342 (org-test-with-temp-text "
347 (org-test-with-backend test
350 (should (equal (org-export-as 'test
'subtree
) "text\n*** Head3\n"))
352 (goto-char (point-min))
355 (should (equal (org-export-as 'test nil
'visible
) "* Head1\n"))
357 (flet ((org-test-template (body info
) (format "BEGIN\n%sEND" body
)))
358 (push '(template . org-test-template
) org-test-translate-alist
)
359 (should (equal (org-export-as 'test nil nil
'body-only
)
360 "* Head1\n** Head2\ntext\n*** Head3\n"))
361 (should (equal (org-export-as 'test
)
362 "BEGIN\n* Head1\n** Head2\ntext\n*** Head3\nEND")))
364 (goto-char (point-min))
366 (transient-mark-mode 1)
367 (push-mark (point) t t
)
368 (goto-char (point-at-eol))
369 (should (equal (org-export-as 'test
) "text\n"))))
370 ;; Subtree with a code block calling another block outside.
373 (org-test-with-temp-text "
375 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
380 #+BEGIN_SRC emacs-lisp
383 (org-test-with-backend test
385 (org-export-as 'test
'subtree
))))))
387 (ert-deftest test-org-export
/expand-include
()
388 "Test file inclusion in an Org buffer."
389 ;; Error when file isn't specified.
391 (org-test-with-temp-text "#+INCLUDE: dummy.org"
392 (org-export-expand-include-keyword)))
393 ;; Full insertion with recursive inclusion.
394 (org-test-with-temp-text
395 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir
)
396 (org-export-expand-include-keyword)
397 (should (equal (buffer-string)
398 "Small Org file with an include keyword.
400 #+BEGIN_SRC emacs-lisp :exports results\n(+ 2 1)\n#+END_SRC
406 ;; Localized insertion.
407 (org-test-with-temp-text
408 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
410 (org-export-expand-include-keyword)
411 (should (equal (buffer-string)
412 "Small Org file with an include keyword.\n")))
413 ;; Insertion with constraints on headlines level.
414 (org-test-with-temp-text
416 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\""
418 (org-export-expand-include-keyword)
419 (should (equal (buffer-string) "* Top heading\n** Heading\nbody\n")))
420 ;; Inclusion within an example block.
421 (org-test-with-temp-text
422 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" example"
424 (org-export-expand-include-keyword)
428 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n")))
429 ;; Inclusion within a src-block.
430 (org-test-with-temp-text
432 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" src emacs-lisp"
434 (org-export-expand-include-keyword)
435 (should (equal (buffer-string)
436 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"))))
438 (ert-deftest test-org-export
/expand-macro
()
439 "Test macro expansion in an Org buffer."
440 ;; Standard macro expansion.
442 (equal "#+MACRO: macro1 value\nvalue\n"
443 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
444 (org-test-with-backend test
(org-export-as 'test
)))))
445 ;; Expand specific macros.
447 (equal "me 2012-03-29 me@here Title\n"
448 (org-test-with-temp-text
454 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
455 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
456 (substring output
(string-match ".*\n\\'" output
))))))
457 ;; Expand specific macros when property contained a regular macro
461 (org-test-with-temp-text "
462 #+MACRO: macro1 value
463 #+TITLE: {{{macro1}}}
465 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
466 (substring output
(string-match ".*\n\\'" output
))))))
467 ;; Expand macros with templates in included files.
470 (org-test-with-temp-text
471 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
472 {{{included-macro}}}" org-test-dir
)
473 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
474 (substring output
(string-match ".*\n\\'" output
)))))))
476 (ert-deftest test-org-export
/user-ignore-list
()
477 "Test if `:ignore-list' accepts user input."
478 (org-test-with-backend test
479 (flet ((skip-note-head
481 ;; Ignore headlines with the word "note" in their title.
485 (when (string-match "\\<note\\>"
486 (org-element-property :raw-value headline
))
487 (org-export-ignore-element headline info
)))
490 ;; Install function in parse tree filters.
491 (let ((org-export-filter-parse-tree-functions '(skip-note-head)))
492 (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
493 (should (equal (org-export-as 'test
) "* Head1\n")))))))
495 (ert-deftest test-org-export
/before-processing-hook
()
496 "Test `org-export-before-processing-hook'."
499 "#+MACRO: mac val\nTest\n"
500 (org-test-with-backend test
501 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
502 (let ((org-export-before-processing-hook
504 (while (re-search-forward "{{{" nil t
)
505 (let ((object (org-element-context)))
506 (when (eq (org-element-type object
) 'macro
)
508 (org-element-property :begin object
)
509 (org-element-property :end object
)))))))))
510 (org-export-as 'test
)))))))
512 (ert-deftest test-org-export
/before-parsing-hook
()
513 "Test `org-export-before-parsing-hook'."
515 (equal "Body 1\nBody 2\n"
516 (org-test-with-backend test
517 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
518 (let ((org-export-before-parsing-hook
522 (delete-region (point) (progn (forward-line) (point)))))))))
523 (org-export-as 'test
)))))))
527 ;;; Affiliated Keywords
529 (ert-deftest test-org-export
/read-attribute
()
530 "Test `org-export-read-attribute' specifications."
534 (org-export-read-attribute
536 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
537 (org-element-at-point)))
539 ;; Return nil on empty attribute.
541 (org-export-read-attribute
543 (org-test-with-temp-text "Paragraph" (org-element-at-point)))))
545 (ert-deftest test-org-export
/get-caption
()
546 "Test `org-export-get-caption' specifications."
547 ;; Without optional argument, return long caption
551 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
552 (org-export-get-caption (org-element-at-point)))))
553 ;; With optional argument, return short caption.
557 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
558 (org-export-get-caption (org-element-at-point) t
))))
559 ;; Multiple lines are separated by white spaces.
563 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
564 (org-export-get-caption (org-element-at-point))))))
570 (ert-deftest test-org-export
/export-snippet
()
571 "Test export snippets transcoding."
572 (org-test-with-temp-text "@@test:A@@@@t:B@@"
573 (org-test-with-backend test
574 (let ((org-test-translate-alist
575 (cons (cons 'export-snippet
576 (lambda (snippet contents info
)
577 (when (eq (org-export-snippet-backend snippet
) 'test
)
578 (org-element-property :value snippet
))))
579 org-test-translate-alist
)))
580 (let ((org-export-snippet-translation-alist nil
))
581 (should (equal (org-export-as 'test
) "A\n")))
582 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
583 (should (equal (org-export-as 'test
) "AB\n")))))))
589 (ert-deftest test-org-export
/footnotes
()
590 "Test footnotes specifications."
591 (let ((org-footnote-section nil
)
592 (org-export-with-footnotes t
))
593 ;; 1. Read every type of footnote.
596 '((1 .
"A\n") (2 .
"B") (3 .
"C") (4 .
"D"))
597 (org-test-with-parsed-data
598 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
600 tree
'footnote-reference
602 (let ((def (org-export-get-footnote-definition ref info
)))
603 (cons (org-export-get-footnote-number ref info
)
604 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
605 (car (org-element-contents
606 (car (org-element-contents def
))))))))
608 ;; 2. Test nested footnotes order.
609 (org-test-with-parsed-data
610 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
613 '((1 .
"fn:1") (2 .
"fn:2") (3 .
"fn:3") (4))
615 tree
'footnote-reference
617 (when (org-export-footnote-first-reference-p ref info
)
618 (cons (org-export-get-footnote-number ref info
)
619 (org-element-property :label ref
))))
621 ;; 3. Test nested footnote in invisible definitions.
622 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
624 (narrow-to-region (point) (point-at-eol))
625 (let* ((tree (org-element-parse-buffer))
626 (info (org-combine-plists
628 (org-export-collect-tree-properties
629 tree
(org-export-get-environment)))))
630 ;; Both footnotes should be seen.
632 (= (length (org-export-collect-footnote-definitions tree info
)) 2))))
633 ;; 4. Test footnotes definitions collection.
634 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
636 \[fn:2] B [fn:3] [fn::D].
639 (should (= (length (org-export-collect-footnote-definitions tree info
))
641 ;; 5. Test export of footnotes defined outside parsing scope.
642 (org-test-with-temp-text "[fn:1] Out of scope
645 (org-test-with-backend test
646 (let ((org-test-translate-alist
647 (cons (cons 'footnote-reference
648 (lambda (fn contents info
)
649 (org-element-interpret-data
650 (org-export-get-footnote-definition fn info
))))
651 org-test-translate-alist
)))
653 (should (equal "ParagraphOut of scope\n"
654 (org-export-as 'test
'subtree
))))))))
658 ;;; Headlines and Inlinetasks
660 (ert-deftest test-org-export
/get-relative-level
()
661 "Test `org-export-get-relative-level' specifications."
665 (let ((org-odd-levels-only nil
))
666 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
669 (lambda (h) (org-export-get-relative-level h info
))
674 (let ((org-odd-levels-only nil
))
675 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
678 (lambda (h) (org-export-get-relative-level h info
))
681 (ert-deftest test-org-export
/low-level-p
()
682 "Test `org-export-low-level-p' specifications."
686 (let ((org-odd-levels-only nil
))
687 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
690 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
691 (plist-put info
:headline-levels
1)))))))
693 (ert-deftest test-org-export
/get-headline-number
()
694 "Test `org-export-get-headline-number' specifications."
699 (let ((org-odd-levels-only nil
))
700 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
703 (lambda (h) (org-export-get-headline-number h info
))
705 ;; Missing levels are replaced with 0.
709 (let ((org-odd-levels-only nil
))
710 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
713 (lambda (h) (org-export-get-headline-number h info
))
716 (ert-deftest test-org-export
/numbered-headline-p
()
717 "Test `org-export-numbered-headline-p' specifications."
718 ;; If `:section-numbers' is nil, never number headlines.
720 (org-test-with-parsed-data "* Headline"
723 (lambda (h) (org-export-numbered-headline-p h info
))
724 (plist-put info
:section-numbers nil
))))
725 ;; If `:section-numbers' is a number, only number headlines with
726 ;; a level greater that it.
730 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
733 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
734 (plist-put info
:section-numbers
1)))))
735 ;; Otherwise, headlines are always numbered.
737 (org-test-with-parsed-data "* Headline"
740 (lambda (h) (org-export-numbered-headline-p h info
))
741 (plist-put info
:section-numbers t
)))))
743 (ert-deftest test-org-export
/number-to-roman
()
744 "Test `org-export-number-to-roman' specifications."
745 ;; If number is negative, return it as a string.
746 (should (equal (org-export-number-to-roman -
1) "-1"))
747 ;; Otherwise, return it as a roman number.
748 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
750 (ert-deftest test-org-export
/get-tags
()
751 "Test `org-export-get-tags' specifications."
752 (let ((org-export-exclude-tags '("noexport"))
753 (org-export-select-tags '("export")))
754 ;; Standard test: tags which are not a select tag, an exclude tag,
755 ;; or specified as optional argument shouldn't be ignored.
757 (org-test-with-parsed-data "* Headline :tag:"
758 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
760 ;; Exclude tags are removed.
762 (org-test-with-parsed-data "* Headline :noexport:"
763 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
765 ;; Select tags are removed.
767 (org-test-with-parsed-data "* Headline :export:"
768 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
773 (org-test-with-parsed-data "* Headline :tag:export:"
774 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
776 ;; Tags provided in the optional argument are also ignored.
778 (org-test-with-parsed-data "* Headline :ignore:"
779 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
781 ;; Allow tag inheritance.
785 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
788 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))
789 ;; Tag inheritance checks FILETAGS keywords.
793 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
796 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))))
798 (ert-deftest test-org-export
/get-node-property
()
799 "Test`org-export-get-node-property' specifications."
803 (org-test-with-parsed-data "* Headline
807 (org-export-get-node-property
808 :prop
(org-element-map tree
'headline
'identity nil t
)))))
812 (org-test-with-parsed-data "* Parent
818 (org-export-get-node-property
819 :prop
(org-element-map tree
'paragraph
'identity nil t
) t
))))
820 ;; Cannot return a value before the first headline.
822 (org-test-with-parsed-data "Paragraph
827 (org-export-get-node-property
828 :prop
(org-element-map tree
'paragraph
'identity nil t
)))))
830 (ert-deftest test-org-export
/get-category
()
831 "Test `org-export-get-category' specifications."
835 (org-test-with-parsed-data "* Headline
839 (org-export-get-category
840 (org-element-map tree
'headline
'identity nil t
) info
))))
841 ;; Test inheritance from a parent headline.
843 (equal '("value" "value")
844 (org-test-with-parsed-data "* Headline1
851 (lambda (hl) (org-export-get-category hl info
)) info
))))
852 ;; Test inheritance from #+CATEGORY keyword
855 (org-test-with-parsed-data "#+CATEGORY: value
857 (org-export-get-category
858 (org-element-map tree
'headline
'identity nil t
) info
))))
859 ;; Test inheritance from file name.
862 (org-test-with-parsed-data "* Headline"
863 (let ((info (plist-put info
:input-file
"~/test.org")))
864 (org-export-get-category
865 (org-element-map tree
'headline
'identity nil t
) info
)))))
869 (org-test-with-parsed-data "* Headline"
870 (org-export-get-category
871 (org-element-map tree
'headline
'identity nil t
) info
)))))
873 (ert-deftest test-org-export
/first-sibling-p
()
874 "Test `org-export-first-sibling-p' specifications."
879 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
882 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
884 ;; Ignore headlines not exported.
888 (let ((org-export-exclude-tags '("ignore")))
889 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
892 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
895 (ert-deftest test-org-export
/last-sibling-p
()
896 "Test `org-export-last-sibling-p' specifications."
901 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
904 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
906 ;; Ignore headlines not exported.
910 (let ((org-export-exclude-tags '("ignore")))
911 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
914 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
921 (ert-deftest test-org-export
/get-coderef-format
()
922 "Test `org-export-get-coderef-format' specifications."
923 ;; A link without description returns "%s"
924 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
926 ;; Return "%s" when path is matched within description.
927 (should (equal (org-export-get-coderef-format "path" "desc (path)")
929 ;; Otherwise return description.
930 (should (equal (org-export-get-coderef-format "path" "desc")
933 (ert-deftest test-org-export
/inline-image-p
()
934 "Test `org-export-inline-image-p' specifications."
936 (org-export-inline-image-p
937 (org-test-with-temp-text "[[#id]]"
939 (org-element-parse-buffer) 'link
'identity nil t
))
940 '(("custom-id" .
"id")))))
942 (ert-deftest test-org-export
/fuzzy-link
()
943 "Test fuzzy links specifications."
944 ;; 1. Links to invisible (keyword) targets should be ignored.
945 (org-test-with-parsed-data
946 "Paragraph.\n#+TARGET: Test\n[[Test]]"
951 (org-export-get-ordinal
952 (org-export-resolve-fuzzy-link link info
) info
)) info
)))
953 ;; 2. Link to an headline should return headline's number.
954 (org-test-with-parsed-data
955 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
957 ;; Note: Headline's number is in fact a list of numbers.
962 (org-export-get-ordinal
963 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
964 ;; 3. Link to a target in an item should return item's number.
965 (org-test-with-parsed-data
966 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
968 ;; Note: Item's number is in fact a list of numbers.
973 (org-export-get-ordinal
974 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
975 ;; 4. Link to a target in a footnote should return footnote's
977 (org-test-with-parsed-data "
978 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
984 (org-export-get-ordinal
985 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
986 ;; 5. Link to a named element should return sequence number of that
988 (org-test-with-parsed-data
989 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
995 (org-export-get-ordinal
996 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
997 ;; 6. Link to a target not within an item, a table, a footnote
998 ;; reference or definition should return section number.
999 (org-test-with-parsed-data
1000 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
1006 (org-export-get-ordinal
1007 (org-export-resolve-fuzzy-link link info
) info
)) info t
)))))
1009 (ert-deftest test-org-export
/resolve-coderef
()
1010 "Test `org-export-resolve-coderef' specifications."
1011 (let ((org-coderef-label-format "(ref:%s)"))
1012 ;; 1. A link to a "-n -k -r" block returns line number.
1013 (org-test-with-parsed-data
1014 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
1015 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1016 (org-test-with-parsed-data
1017 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1018 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1019 ;; 2. A link to a "-n -r" block returns line number.
1020 (org-test-with-parsed-data
1021 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
1022 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1023 (org-test-with-parsed-data
1024 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1025 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1026 ;; 3. A link to a "-n" block returns coderef.
1027 (org-test-with-parsed-data
1028 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1029 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1030 (org-test-with-parsed-data
1031 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
1032 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1033 ;; 4. A link to a "-r" block returns line number.
1034 (org-test-with-parsed-data
1035 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1036 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1037 (org-test-with-parsed-data
1038 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
1039 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1040 ;; 5. A link to a block without a switch returns coderef.
1041 (org-test-with-parsed-data
1042 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1043 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1044 (org-test-with-parsed-data
1045 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
1046 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1047 ;; 6. Correctly handle continued line numbers. A "+n" switch
1048 ;; should resume numbering from previous block with numbered
1049 ;; lines, ignoring blocks not numbering lines in the process.
1050 ;; A "-n" switch resets count.
1051 (org-test-with-parsed-data "
1056 #+BEGIN_SRC emacs-lisp
1060 #+BEGIN_SRC emacs-lisp +n -r
1061 \(+ 1 1) (ref:addition)
1064 #+BEGIN_EXAMPLE -n -r
1065 Another text. (ref:text)
1067 (should (= (org-export-resolve-coderef "addition" info
) 2))
1068 (should (= (org-export-resolve-coderef "text" info
) 1)))
1069 ;; 7. Recognize coderef with user-specified syntax.
1070 (org-test-with-parsed-data
1071 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
1072 (should (equal (org-export-resolve-coderef "text" info
) "text")))))
1074 (ert-deftest test-org-export
/resolve-fuzzy-link
()
1075 "Test `org-export-resolve-fuzzy-link' specifications."
1076 ;; 1. Match target objects.
1077 (org-test-with-parsed-data "<<target>> [[target]]"
1079 (org-export-resolve-fuzzy-link
1080 (org-element-map tree
'link
'identity info t
) info
)))
1081 ;; 2. Match target elements.
1082 (org-test-with-parsed-data "#+TARGET: target\n[[target]]"
1084 (org-export-resolve-fuzzy-link
1085 (org-element-map tree
'link
'identity info t
) info
)))
1086 ;; 3. Match named elements.
1087 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
1089 (org-export-resolve-fuzzy-link
1090 (org-element-map tree
'link
'identity info t
) info
)))
1091 ;; 4. Match exact headline's name.
1092 (org-test-with-parsed-data "* My headline\n[[My headline]]"
1094 (org-export-resolve-fuzzy-link
1095 (org-element-map tree
'link
'identity info t
) info
)))
1096 ;; 5. Targets objects have priority over named elements and headline
1098 (org-test-with-parsed-data
1099 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
1103 (org-export-resolve-fuzzy-link
1104 (org-element-map tree
'link
'identity info t
) info
)))))
1105 ;; 6. Named elements have priority over headline titles.
1106 (org-test-with-parsed-data
1107 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
1111 (org-export-resolve-fuzzy-link
1112 (org-element-map tree
'link
'identity info t
) info
)))))
1113 ;; 7. If link's path starts with a "*", only match headline titles,
1115 (org-test-with-parsed-data
1116 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
1120 (org-export-resolve-fuzzy-link
1121 (org-element-map tree
'link
'identity info t
) info
)))))
1122 ;; 8. Return nil if no match.
1123 (org-test-with-parsed-data "[[target]]"
1125 (org-export-resolve-fuzzy-link
1126 (org-element-map tree
'link
'identity info t
) info
))))
1128 (ert-deftest test-org-export
/resolve-id-link
()
1129 "Test `org-export-resolve-id-link' specifications."
1130 ;; 1. Regular test for custom-id link.
1131 (org-test-with-parsed-data "* Headline1
1138 (org-export-resolve-id-link
1139 (org-element-map tree
'link
'identity info t
) info
)))
1140 ;; 2. Failing test for custom-id link.
1141 (org-test-with-parsed-data "* Headline1
1148 (org-export-resolve-id-link
1149 (org-element-map tree
'link
'identity info t
) info
)))
1150 ;; 3. Test for internal id target.
1151 (org-test-with-parsed-data "* Headline1
1158 (org-export-resolve-id-link
1159 (org-element-map tree
'link
'identity info t
) info
)))
1160 ;; 4. Test for external id target.
1161 (org-test-with-parsed-data "[[id:aaaa]]"
1163 (org-export-resolve-id-link
1164 (org-element-map tree
'link
'identity info t
)
1165 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file"))))))))
1167 (ert-deftest test-org-export
/resolve-radio-link
()
1168 "Test `org-export-resolve-radio-link' specifications."
1170 (org-test-with-temp-text "<<<radio>>> radio"
1171 (org-update-radio-target-regexp)
1173 (let* ((tree (org-element-parse-buffer))
1174 (info `(:parse-tree
,tree
)))
1175 (org-export-resolve-radio-link
1176 (org-element-map tree
'link
'identity info t
)
1178 ;; Radio target with objects.
1179 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
1180 (org-update-radio-target-regexp)
1182 (let* ((tree (org-element-parse-buffer))
1183 (info `(:parse-tree
,tree
)))
1184 (org-export-resolve-radio-link
1185 (org-element-map tree
'link
'identity info t
)
1190 ;;; Src-block and example-block
1192 (ert-deftest test-org-export
/unravel-code
()
1193 "Test `org-export-unravel-code' function."
1194 (let ((org-coderef-label-format "(ref:%s)"))
1195 ;; 1. Code without reference.
1196 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
1197 (should (equal (org-export-unravel-code (org-element-at-point))
1199 ;; 2. Code with reference.
1200 (org-test-with-temp-text
1201 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
1202 (should (equal (org-export-unravel-code (org-element-at-point))
1203 '("(+ 1 1)\n" (1 .
"test")))))
1204 ;; 3. Code with user-defined reference.
1205 (org-test-with-temp-text
1206 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
1207 (should (equal (org-export-unravel-code (org-element-at-point))
1208 '("(+ 1 1)\n" (1 .
"test")))))
1209 ;; 4. Code references keys are relative to the current block.
1210 (org-test-with-temp-text "
1219 (should (equal (org-export-unravel-code (org-element-at-point))
1220 '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one")))))))
1226 (ert-deftest test-org-export
/activate-smart-quotes
()
1227 "Test `org-export-activate-smart-quotes' specifications."
1228 ;; Opening double quotes: standard test.
1231 '("some “paragraph")
1232 (let ((org-export-default-language "en"))
1233 (org-test-with-parsed-data "some \"paragraph"
1236 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1238 ;; Opening quotes: at the beginning of a paragraph.
1242 (let ((org-export-default-language "en"))
1243 (org-test-with-parsed-data "\"begin"
1246 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1248 ;; Opening quotes: after an object.
1252 (let ((org-export-default-language "en"))
1253 (org-test-with-parsed-data "=verb= \"begin"
1256 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1258 ;; Closing quotes: standard test.
1261 '("some” paragraph")
1262 (let ((org-export-default-language "en"))
1263 (org-test-with-parsed-data "some\" paragraph"
1266 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1268 ;; Closing quotes: at the end of a paragraph.
1272 (let ((org-export-default-language "en"))
1273 (org-test-with-parsed-data "end\""
1276 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1278 ;; Apostrophe: standard test.
1281 '("It shouldn’t fail")
1282 (let ((org-export-default-language "en"))
1283 (org-test-with-parsed-data "It shouldn't fail"
1286 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1288 ;; Apostrophe: before an object.
1292 (let ((org-export-default-language "en"))
1293 (org-test-with-parsed-data "a'=b="
1296 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1298 ;; Apostrophe: after an object.
1302 (let ((org-export-default-language "en"))
1303 (org-test-with-parsed-data "=code='s"
1306 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1308 ;; Special case: isolated quotes.
1310 (equal '("“" "”")
1311 (let ((org-export-default-language "en"))
1312 (org-test-with-parsed-data "\"$x$\""
1315 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1317 ;; Smart quotes in secondary strings.
1319 (equal '("“" "”")
1320 (let ((org-export-default-language "en"))
1321 (org-test-with-parsed-data "* \"$x$\""
1324 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1326 ;; Smart quotes in document keywords.
1328 (equal '("“" "”")
1329 (let ((org-export-default-language "en"))
1330 (org-test-with-parsed-data "#+TITLE: \"$x$\""
1332 (plist-get info
:title
) 'plain-text
1333 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1335 ;; Smart quotes in parsed affiliated keywords.
1337 (equal '("“" "”" "Paragraph")
1338 (let ((org-export-default-language "en"))
1339 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
1342 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1343 info nil nil t
))))))
1349 (ert-deftest test-org-export
/special-column
()
1350 "Test if the table's special column is properly recognized."
1351 ;; 1. First column is special if it contains only a special marking
1352 ;; characters or empty cells.
1353 (org-test-with-temp-text "
1357 (org-export-table-has-special-column-p
1359 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1360 ;; 2. If the column contains anything else, it isn't special.
1361 (org-test-with-temp-text "
1365 (org-export-table-has-special-column-p
1367 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1368 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
1370 (org-test-with-temp-text "
1379 (org-export-table-has-special-column-p
1381 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1382 ;; 4. A first column with only empty cells isn't considered as
1384 (org-test-with-temp-text "
1388 (org-export-table-has-special-column-p
1390 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
1392 (ert-deftest test-org-export
/table-row-is-special-p
()
1393 "Test `org-export-table-row-is-special-p' specifications."
1394 ;; 1. A row is special if it has a special marking character in the
1396 (org-test-with-parsed-data "| ! | 1 |"
1398 (org-export-table-row-is-special-p
1399 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1400 ;; 2. A row is special when its first field is "/"
1401 (org-test-with-parsed-data "
1405 (org-export-table-row-is-special-p
1406 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1407 ;; 3. A row only containing alignment cookies is also considered as
1409 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
1411 (org-export-table-row-is-special-p
1412 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1413 ;; 4. Everything else isn't considered as special.
1414 (org-test-with-parsed-data "| \alpha | | c |"
1416 (org-export-table-row-is-special-p
1417 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1418 ;; 5. Table's rules are never considered as special rows.
1419 (org-test-with-parsed-data "|---+---|"
1421 (org-export-table-row-is-special-p
1422 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
1424 (ert-deftest test-org-export
/has-header-p
()
1425 "Test `org-export-table-has-header-p' specifications."
1426 ;; 1. With an header.
1427 (org-test-with-parsed-data "
1432 (org-export-table-has-header-p
1433 (org-element-map tree
'table
'identity info
'first-match
)
1435 ;; 2. Without an header.
1436 (org-test-with-parsed-data "
1440 (org-export-table-has-header-p
1441 (org-element-map tree
'table
'identity info
'first-match
)
1443 ;; 3. Don't get fooled with starting and ending rules.
1444 (org-test-with-parsed-data "
1450 (org-export-table-has-header-p
1451 (org-element-map tree
'table
'identity info
'first-match
)
1454 (ert-deftest test-org-export
/table-row-group
()
1455 "Test `org-export-table-row-group' specifications."
1456 ;; 1. A rule creates a new group.
1457 (org-test-with-parsed-data "
1464 (mapcar (lambda (row) (org-export-table-row-group row info
))
1465 (org-element-map tree
'table-row
'identity
)))))
1466 ;; 2. Special rows are ignored in count.
1467 (org-test-with-parsed-data "
1474 (mapcar (lambda (row) (org-export-table-row-group row info
))
1475 (org-element-map tree
'table-row
'identity
)))))
1476 ;; 3. Double rules also are ignored in count.
1477 (org-test-with-parsed-data "
1485 (mapcar (lambda (row) (org-export-table-row-group row info
))
1486 (org-element-map tree
'table-row
'identity
))))))
1488 (ert-deftest test-org-export
/table-cell-width
()
1489 "Test `org-export-table-cell-width' specifications."
1490 ;; 1. Width is primarily determined by width cookies. If no cookie
1491 ;; is found, cell's width is nil.
1492 (org-test-with-parsed-data "
1493 | / | <l> | <6> | <l7> |
1498 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1499 (org-element-map tree
'table-cell
'identity info
)))))
1500 ;; 2. The last width cookie has precedence.
1501 (org-test-with-parsed-data "
1508 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1509 (org-element-map tree
'table-cell
'identity info
)))))
1510 ;; 3. Valid width cookies must have a specific row.
1511 (org-test-with-parsed-data "| <6> | cell |"
1515 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1516 (org-element-map tree
'table-cell
'identity
))))))
1518 (ert-deftest test-org-export
/table-cell-alignment
()
1519 "Test `org-export-table-cell-alignment' specifications."
1520 (let ((org-table-number-fraction 0.5)
1521 (org-table-number-regexp "^[0-9]+$"))
1522 ;; 1. Alignment is primarily determined by alignment cookies.
1523 (org-test-with-temp-text "| <l> | <c> | <r> |"
1524 (let* ((tree (org-element-parse-buffer))
1525 (info `(:parse-tree
,tree
)))
1528 '(left center right
)
1529 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1530 (org-element-map tree
'table-cell
'identity
))))))
1531 ;; 2. The last alignment cookie has precedence.
1532 (org-test-with-parsed-data "
1538 '(right right right
)
1539 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1540 (org-element-map tree
'table-cell
'identity
)))))
1541 ;; 3. If there's no cookie, cell's contents determine alignment.
1542 ;; A column mostly made of cells containing numbers will align
1543 ;; its cells to the right.
1544 (org-test-with-parsed-data "
1550 '(right right right
)
1551 (mapcar (lambda (cell)
1552 (org-export-table-cell-alignment cell info
))
1553 (org-element-map tree
'table-cell
'identity
)))))
1554 ;; 4. Otherwise, they will be aligned to the left.
1555 (org-test-with-parsed-data "
1562 (mapcar (lambda (cell)
1563 (org-export-table-cell-alignment cell info
))
1564 (org-element-map tree
'table-cell
'identity
)))))))
1566 (ert-deftest test-org-export
/table-cell-borders
()
1567 "Test `org-export-table-cell-borders' specifications."
1568 ;; 1. Recognize various column groups indicators.
1569 (org-test-with-parsed-data "| / | < | > | <> |"
1572 '((right bottom top
) (left bottom top
) (right bottom top
)
1573 (right left bottom top
))
1574 (mapcar (lambda (cell)
1575 (org-export-table-cell-borders cell info
))
1576 (org-element-map tree
'table-cell
'identity
)))))
1577 ;; 2. Accept shortcuts to define column groups.
1578 (org-test-with-parsed-data "| / | < | < |"
1581 '((right bottom top
) (right left bottom top
) (left bottom top
))
1582 (mapcar (lambda (cell)
1583 (org-export-table-cell-borders cell info
))
1584 (org-element-map tree
'table-cell
'identity
)))))
1585 ;; 3. A valid column groups row must start with a "/".
1586 (org-test-with-parsed-data "
1590 (equal '((top) (top) (bottom) (bottom))
1591 (mapcar (lambda (cell)
1592 (org-export-table-cell-borders cell info
))
1593 (org-element-map tree
'table-cell
'identity
)))))
1594 ;; 4. Take table rules into consideration.
1595 (org-test-with-parsed-data "
1600 (equal '((below top
) (bottom above
))
1601 (mapcar (lambda (cell)
1602 (org-export-table-cell-borders cell info
))
1603 (org-element-map tree
'table-cell
'identity
)))))
1604 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
1605 ;; (resp. `bottom' and `below') borders. Any special row is
1607 (org-test-with-parsed-data "
1613 (equal '((bottom below top above
))
1615 (mapcar (lambda (cell)
1616 (org-export-table-cell-borders cell info
))
1617 (org-element-map tree
'table-cell
'identity
)))))))
1619 (ert-deftest test-org-export
/table-dimensions
()
1620 "Test `org-export-table-dimensions' specifications."
1621 ;; 1. Standard test.
1622 (org-test-with-parsed-data "
1627 (org-export-table-dimensions
1628 (org-element-map tree
'table
'identity info
'first-match
) info
))))
1629 ;; 2. Ignore horizontal rules and special columns.
1630 (org-test-with-parsed-data "
1637 (org-export-table-dimensions
1638 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
1640 (ert-deftest test-org-export
/table-cell-address
()
1641 "Test `org-export-table-cell-address' specifications."
1642 ;; 1. Standard test: index is 0-based.
1643 (org-test-with-parsed-data "| a | b |"
1645 (equal '((0 .
0) (0 .
1))
1648 (lambda (cell) (org-export-table-cell-address cell info
))
1650 ;; 2. Special column isn't counted, nor are special rows.
1651 (org-test-with-parsed-data "
1656 (org-export-table-cell-address
1657 (car (last (org-element-map tree
'table-cell
'identity info
)))
1659 ;; 3. Tables rules do not count either.
1660 (org-test-with-parsed-data "
1668 (org-export-table-cell-address
1669 (car (last (org-element-map tree
'table-cell
'identity info
)))
1671 ;; 4. Return nil for special cells.
1672 (org-test-with-parsed-data "| / | a |"
1674 (org-export-table-cell-address
1675 (org-element-map tree
'table-cell
'identity nil
'first-match
)
1678 (ert-deftest test-org-export
/get-table-cell-at
()
1679 "Test `org-export-get-table-cell-at' specifications."
1680 ;; 1. Address ignores special columns, special rows and rules.
1681 (org-test-with-parsed-data "
1688 (org-element-contents
1689 (org-export-get-table-cell-at
1691 (org-element-map tree
'table
'identity info
'first-match
)
1693 ;; 2. Return value for a non-existent address is nil.
1694 (org-test-with-parsed-data "| a |"
1696 (org-export-get-table-cell-at
1698 (org-element-map tree
'table
'identity info
'first-match
)
1700 (org-test-with-parsed-data "| / |"
1702 (org-export-get-table-cell-at
1704 (org-element-map tree
'table
'identity info
'first-match
)
1707 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
1708 "Test `org-export-table-cell-starts-colgroup-p' specifications."
1709 ;; 1. A cell at a beginning of a row always starts a column group.
1710 (org-test-with-parsed-data "| a |"
1712 (org-export-table-cell-starts-colgroup-p
1713 (org-element-map tree
'table-cell
'identity info
'first-match
)
1715 ;; 2. Special column should be ignored when determining the
1716 ;; beginning of the row.
1717 (org-test-with-parsed-data "
1721 (org-export-table-cell-starts-colgroup-p
1722 (org-element-map tree
'table-cell
'identity info
'first-match
)
1724 ;; 2. Explicit column groups.
1725 (org-test-with-parsed-data "
1734 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
1737 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
1738 "Test `org-export-table-cell-ends-colgroup-p' specifications."
1739 ;; 1. A cell at the end of a row always ends a column group.
1740 (org-test-with-parsed-data "| a |"
1742 (org-export-table-cell-ends-colgroup-p
1743 (org-element-map tree
'table-cell
'identity info
'first-match
)
1745 ;; 2. Special column should be ignored when determining the
1746 ;; beginning of the row.
1747 (org-test-with-parsed-data "
1751 (org-export-table-cell-ends-colgroup-p
1752 (org-element-map tree
'table-cell
'identity info
'first-match
)
1754 ;; 3. Explicit column groups.
1755 (org-test-with-parsed-data "
1764 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
1767 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
1768 "Test `org-export-table-row-starts-rowgroup-p' specifications."
1769 ;; 1. A row at the beginning of a table always starts a row group.
1770 ;; So does a row following a table rule.
1771 (org-test-with-parsed-data "
1781 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
1783 ;; 2. Special rows should be ignored when determining the beginning
1785 (org-test-with-parsed-data "
1797 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
1800 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
1801 "Test `org-export-table-row-ends-rowgroup-p' specifications."
1802 ;; 1. A row at the end of a table always ends a row group. So does
1803 ;; a row preceding a table rule.
1804 (org-test-with-parsed-data "
1814 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
1816 ;; 2. Special rows should be ignored when determining the beginning
1818 (org-test-with-parsed-data "
1830 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
1833 (ert-deftest test-org-export
/table-row-starts-header-p
()
1834 "Test `org-export-table-row-starts-header-p' specifications."
1835 ;; 1. Only the row starting the first row group starts the table
1837 (org-test-with-parsed-data "
1848 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
1850 ;; 2. A row cannot start an header if there's no header in the
1852 (org-test-with-parsed-data "
1856 (org-export-table-row-starts-header-p
1857 (org-element-map tree
'table-row
'identity info
'first-match
)
1860 (ert-deftest test-org-export
/table-row-ends-header-p
()
1861 "Test `org-export-table-row-ends-header-p' specifications."
1862 ;; 1. Only the row starting the first row group starts the table
1864 (org-test-with-parsed-data "
1875 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
1877 ;; 2. A row cannot start an header if there's no header in the
1879 (org-test-with-parsed-data "
1883 (org-export-table-row-ends-header-p
1884 (org-element-map tree
'table-row
'identity info
'first-match
)
1891 (ert-deftest test-org-export
/get-next-element
()
1892 "Test `org-export-get-next-element' specifications."
1896 (org-test-with-parsed-data "* Headline\n*a* b"
1897 (org-export-get-next-element
1898 (org-element-map tree
'bold
'identity info t
) info
))))
1899 ;; Return nil when no previous element.
1901 (org-test-with-parsed-data "* Headline\na *b*"
1902 (org-export-get-next-element
1903 (org-element-map tree
'bold
'identity info t
) info
)))
1904 ;; Non-exportable elements are ignored.
1906 (let ((org-export-with-timestamps nil
))
1907 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
1908 (org-export-get-next-element
1909 (org-element-map tree
'entity
'identity info t
) info
))))
1910 ;; Find next element in secondary strings.
1913 (org-test-with-parsed-data "* a =verb="
1915 (org-export-get-next-element
1916 (org-element-map tree
'plain-text
'identity info t
) info
)))))
1917 ;; Find next element in document keywords.
1920 (org-test-with-parsed-data "#+TITLE: a =verb="
1922 (org-export-get-next-element
1924 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
1925 ;; Find next element in parsed affiliated keywords.
1928 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
1930 (org-export-get-next-element
1931 (org-element-map tree
'plain-text
'identity info t nil t
) info
))))))
1933 (ert-deftest test-org-export
/get-previous-element
()
1934 "Test `org-export-get-previous-element' specifications."
1938 (org-test-with-parsed-data "* Headline\na *b*"
1939 (org-export-get-previous-element
1940 (org-element-map tree
'bold
'identity info t
) info
))))
1941 ;; Return nil when no previous element.
1943 (org-test-with-parsed-data "* Headline\n*a* b"
1944 (org-export-get-previous-element
1945 (org-element-map tree
'bold
'identity info t
) info
)))
1946 ;; Non-exportable elements are ignored.
1948 (let ((org-export-with-timestamps nil
))
1949 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
1950 (org-export-get-previous-element
1951 (org-element-map tree
'entity
'identity info t
) info
))))
1952 ;; Find previous element in secondary strings.
1955 (org-test-with-parsed-data "* =verb= a"
1957 (org-export-get-previous-element
1958 (org-element-map tree
'plain-text
'identity info t
) info
)))))
1959 ;; Find previous element in document keywords.
1962 (org-test-with-parsed-data "#+TITLE: =verb= a"
1964 (org-export-get-previous-element
1966 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
1967 ;; Find previous element in parsed affiliated keywords.
1970 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
1972 (org-export-get-previous-element
1973 (org-element-map tree
'plain-text
'identity info t nil t
) info
))))))
1976 (provide 'test-org-export
)
1977 ;;; test-org-export.el end here