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-parsing-hook
()
496 "Test `org-export-before-parsing-hook'."
497 (org-test-with-backend test
498 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
499 (let ((org-export-before-parsing-hook
503 (delete-region (point) (progn (forward-line) (point)))))))))
504 (should (equal (org-export-as 'test
) "Body 1\nBody 2\n"))))))
508 ;;; Affiliated Keywords
510 (ert-deftest test-org-export
/read-attribute
()
511 "Test `org-export-read-attribute' specifications."
515 (org-export-read-attribute
517 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
518 (org-element-at-point)))
520 ;; Return nil on empty attribute.
522 (org-export-read-attribute
524 (org-test-with-temp-text "Paragraph" (org-element-at-point)))))
526 (ert-deftest test-org-export
/get-caption
()
527 "Test `org-export-get-caption' specifications."
528 ;; Without optional argument, return long caption
532 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
533 (org-export-get-caption (org-element-at-point)))))
534 ;; With optional argument, return short caption.
538 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
539 (org-export-get-caption (org-element-at-point) t
))))
540 ;; Multiple lines are separated by white spaces.
544 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
545 (org-export-get-caption (org-element-at-point))))))
551 (ert-deftest test-org-export
/export-snippet
()
552 "Test export snippets transcoding."
553 (org-test-with-temp-text "@@test:A@@@@t:B@@"
554 (org-test-with-backend test
555 (let ((org-test-translate-alist
556 (cons (cons 'export-snippet
557 (lambda (snippet contents info
)
558 (when (eq (org-export-snippet-backend snippet
) 'test
)
559 (org-element-property :value snippet
))))
560 org-test-translate-alist
)))
561 (let ((org-export-snippet-translation-alist nil
))
562 (should (equal (org-export-as 'test
) "A\n")))
563 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
564 (should (equal (org-export-as 'test
) "AB\n")))))))
570 (ert-deftest test-org-export
/footnotes
()
571 "Test footnotes specifications."
572 (let ((org-footnote-section nil
)
573 (org-export-with-footnotes t
))
574 ;; 1. Read every type of footnote.
577 '((1 .
"A\n") (2 .
"B") (3 .
"C") (4 .
"D"))
578 (org-test-with-parsed-data
579 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
581 tree
'footnote-reference
583 (let ((def (org-export-get-footnote-definition ref info
)))
584 (cons (org-export-get-footnote-number ref info
)
585 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
586 (car (org-element-contents
587 (car (org-element-contents def
))))))))
589 ;; 2. Test nested footnotes order.
590 (org-test-with-parsed-data
591 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
594 '((1 .
"fn:1") (2 .
"fn:2") (3 .
"fn:3") (4))
596 tree
'footnote-reference
598 (when (org-export-footnote-first-reference-p ref info
)
599 (cons (org-export-get-footnote-number ref info
)
600 (org-element-property :label ref
))))
602 ;; 3. Test nested footnote in invisible definitions.
603 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
605 (narrow-to-region (point) (point-at-eol))
606 (let* ((tree (org-element-parse-buffer))
607 (info (org-combine-plists
609 (org-export-collect-tree-properties
610 tree
(org-export-get-environment)))))
611 ;; Both footnotes should be seen.
613 (= (length (org-export-collect-footnote-definitions tree info
)) 2))))
614 ;; 4. Test footnotes definitions collection.
615 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
617 \[fn:2] B [fn:3] [fn::D].
620 (should (= (length (org-export-collect-footnote-definitions tree info
))
622 ;; 5. Test export of footnotes defined outside parsing scope.
623 (org-test-with-temp-text "[fn:1] Out of scope
626 (org-test-with-backend test
627 (let ((org-test-translate-alist
628 (cons (cons 'footnote-reference
629 (lambda (fn contents info
)
630 (org-element-interpret-data
631 (org-export-get-footnote-definition fn info
))))
632 org-test-translate-alist
)))
634 (should (equal "ParagraphOut of scope\n"
635 (org-export-as 'test
'subtree
))))))))
639 ;;; Headlines and Inlinetasks
641 (ert-deftest test-org-export
/get-relative-level
()
642 "Test `org-export-get-relative-level' specifications."
646 (let ((org-odd-levels-only nil
))
647 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
650 (lambda (h) (org-export-get-relative-level h info
))
655 (let ((org-odd-levels-only nil
))
656 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
659 (lambda (h) (org-export-get-relative-level h info
))
662 (ert-deftest test-org-export
/low-level-p
()
663 "Test `org-export-low-level-p' specifications."
667 (let ((org-odd-levels-only nil
))
668 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
671 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
672 (plist-put info
:headline-levels
1)))))))
674 (ert-deftest test-org-export
/get-headline-number
()
675 "Test `org-export-get-headline-number' specifications."
680 (let ((org-odd-levels-only nil
))
681 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
684 (lambda (h) (org-export-get-headline-number h info
))
686 ;; Missing levels are replaced with 0.
690 (let ((org-odd-levels-only nil
))
691 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
694 (lambda (h) (org-export-get-headline-number h info
))
697 (ert-deftest test-org-export
/numbered-headline-p
()
698 "Test `org-export-numbered-headline-p' specifications."
699 ;; If `:section-numbers' is nil, never number headlines.
701 (org-test-with-parsed-data "* Headline"
704 (lambda (h) (org-export-numbered-headline-p h info
))
705 (plist-put info
:section-numbers nil
))))
706 ;; If `:section-numbers' is a number, only number headlines with
707 ;; a level greater that it.
711 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
714 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
715 (plist-put info
:section-numbers
1)))))
716 ;; Otherwise, headlines are always numbered.
718 (org-test-with-parsed-data "* Headline"
721 (lambda (h) (org-export-numbered-headline-p h info
))
722 (plist-put info
:section-numbers t
)))))
724 (ert-deftest test-org-export
/number-to-roman
()
725 "Test `org-export-number-to-roman' specifications."
726 ;; If number is negative, return it as a string.
727 (should (equal (org-export-number-to-roman -
1) "-1"))
728 ;; Otherwise, return it as a roman number.
729 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
731 (ert-deftest test-org-export
/get-tags
()
732 "Test `org-export-get-tags' specifications."
733 (let ((org-export-exclude-tags '("noexport"))
734 (org-export-select-tags '("export")))
735 ;; Standard test: tags which are not a select tag, an exclude tag,
736 ;; or specified as optional argument shouldn't be ignored.
738 (org-test-with-parsed-data "* Headline :tag:"
739 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
741 ;; Exclude tags are removed.
743 (org-test-with-parsed-data "* Headline :noexport:"
744 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
746 ;; Select tags are removed.
748 (org-test-with-parsed-data "* Headline :export:"
749 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
754 (org-test-with-parsed-data "* Headline :tag:export:"
755 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
757 ;; Tags provided in the optional argument are also ignored.
759 (org-test-with-parsed-data "* Headline :ignore:"
760 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
762 ;; Allow tag inheritance.
766 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
769 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))))
771 (ert-deftest test-org-export
/get-node-property
()
772 "Test`org-export-get-node-property' specifications."
776 (org-test-with-parsed-data "* Headline
780 (org-export-get-node-property
781 :prop
(org-element-map tree
'headline
'identity nil t
)))))
785 (org-test-with-parsed-data "* Parent
791 (org-export-get-node-property
792 :prop
(org-element-map tree
'paragraph
'identity nil t
) t
))))
793 ;; Cannot return a value before the first headline.
795 (org-test-with-parsed-data "Paragraph
800 (org-export-get-node-property
801 :prop
(org-element-map tree
'paragraph
'identity nil t
)))))
803 (ert-deftest test-org-export
/first-sibling-p
()
804 "Test `org-export-first-sibling-p' specifications."
809 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
812 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
814 ;; Ignore headlines not exported.
818 (let ((org-export-exclude-tags '("ignore")))
819 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
822 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
825 (ert-deftest test-org-export
/last-sibling-p
()
826 "Test `org-export-last-sibling-p' specifications."
831 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
834 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
836 ;; Ignore headlines not exported.
840 (let ((org-export-exclude-tags '("ignore")))
841 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
844 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
851 (ert-deftest test-org-export
/get-coderef-format
()
852 "Test `org-export-get-coderef-format' specifications."
853 ;; A link without description returns "%s"
854 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
856 ;; Return "%s" when path is matched within description.
857 (should (equal (org-export-get-coderef-format "path" "desc (path)")
859 ;; Otherwise return description.
860 (should (equal (org-export-get-coderef-format "path" "desc")
863 (ert-deftest test-org-export
/inline-image-p
()
864 "Test `org-export-inline-image-p' specifications."
866 (org-export-inline-image-p
867 (org-test-with-temp-text "[[#id]]"
869 (org-element-parse-buffer) 'link
'identity nil t
))
870 '(("custom-id" .
"id")))))
872 (ert-deftest test-org-export
/fuzzy-link
()
873 "Test fuzzy links specifications."
874 ;; 1. Links to invisible (keyword) targets should be ignored.
875 (org-test-with-parsed-data
876 "Paragraph.\n#+TARGET: Test\n[[Test]]"
881 (org-export-get-ordinal
882 (org-export-resolve-fuzzy-link link info
) info
)) info
)))
883 ;; 2. Link to an headline should return headline's number.
884 (org-test-with-parsed-data
885 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
887 ;; Note: Headline's number is in fact a list of numbers.
892 (org-export-get-ordinal
893 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
894 ;; 3. Link to a target in an item should return item's number.
895 (org-test-with-parsed-data
896 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
898 ;; Note: Item's number is in fact a list of numbers.
903 (org-export-get-ordinal
904 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
905 ;; 4. Link to a target in a footnote should return footnote's
907 (org-test-with-parsed-data "
908 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
914 (org-export-get-ordinal
915 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
916 ;; 5. Link to a named element should return sequence number of that
918 (org-test-with-parsed-data
919 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
925 (org-export-get-ordinal
926 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
927 ;; 6. Link to a target not within an item, a table, a footnote
928 ;; reference or definition should return section number.
929 (org-test-with-parsed-data
930 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
936 (org-export-get-ordinal
937 (org-export-resolve-fuzzy-link link info
) info
)) info t
)))))
939 (ert-deftest test-org-export
/resolve-coderef
()
940 "Test `org-export-resolve-coderef' specifications."
941 (let ((org-coderef-label-format "(ref:%s)"))
942 ;; 1. A link to a "-n -k -r" block returns line number.
943 (org-test-with-parsed-data
944 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
945 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
946 (org-test-with-parsed-data
947 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
948 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
949 ;; 2. A link to a "-n -r" block returns line number.
950 (org-test-with-parsed-data
951 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
952 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
953 (org-test-with-parsed-data
954 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
955 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
956 ;; 3. A link to a "-n" block returns coderef.
957 (org-test-with-parsed-data
958 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
959 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
960 (org-test-with-parsed-data
961 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
962 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
963 ;; 4. A link to a "-r" block returns line number.
964 (org-test-with-parsed-data
965 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
966 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
967 (org-test-with-parsed-data
968 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
969 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
970 ;; 5. A link to a block without a switch returns coderef.
971 (org-test-with-parsed-data
972 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
973 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
974 (org-test-with-parsed-data
975 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
976 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
977 ;; 6. Correctly handle continued line numbers. A "+n" switch
978 ;; should resume numbering from previous block with numbered
979 ;; lines, ignoring blocks not numbering lines in the process.
980 ;; A "-n" switch resets count.
981 (org-test-with-parsed-data "
986 #+BEGIN_SRC emacs-lisp
990 #+BEGIN_SRC emacs-lisp +n -r
991 \(+ 1 1) (ref:addition)
994 #+BEGIN_EXAMPLE -n -r
995 Another text. (ref:text)
997 (should (= (org-export-resolve-coderef "addition" info
) 2))
998 (should (= (org-export-resolve-coderef "text" info
) 1)))
999 ;; 7. Recognize coderef with user-specified syntax.
1000 (org-test-with-parsed-data
1001 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
1002 (should (equal (org-export-resolve-coderef "text" info
) "text")))))
1004 (ert-deftest test-org-export
/resolve-fuzzy-link
()
1005 "Test `org-export-resolve-fuzzy-link' specifications."
1006 ;; 1. Match target objects.
1007 (org-test-with-parsed-data "<<target>> [[target]]"
1009 (org-export-resolve-fuzzy-link
1010 (org-element-map tree
'link
'identity info t
) info
)))
1011 ;; 2. Match target elements.
1012 (org-test-with-parsed-data "#+TARGET: target\n[[target]]"
1014 (org-export-resolve-fuzzy-link
1015 (org-element-map tree
'link
'identity info t
) info
)))
1016 ;; 3. Match named elements.
1017 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
1019 (org-export-resolve-fuzzy-link
1020 (org-element-map tree
'link
'identity info t
) info
)))
1021 ;; 4. Match exact headline's name.
1022 (org-test-with-parsed-data "* My headline\n[[My headline]]"
1024 (org-export-resolve-fuzzy-link
1025 (org-element-map tree
'link
'identity info t
) info
)))
1026 ;; 5. Targets objects have priority over named elements and headline
1028 (org-test-with-parsed-data
1029 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
1033 (org-export-resolve-fuzzy-link
1034 (org-element-map tree
'link
'identity info t
) info
)))))
1035 ;; 6. Named elements have priority over headline titles.
1036 (org-test-with-parsed-data
1037 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
1041 (org-export-resolve-fuzzy-link
1042 (org-element-map tree
'link
'identity info t
) info
)))))
1043 ;; 7. If link's path starts with a "*", only match headline titles,
1045 (org-test-with-parsed-data
1046 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
1050 (org-export-resolve-fuzzy-link
1051 (org-element-map tree
'link
'identity info t
) info
)))))
1052 ;; 8. Return nil if no match.
1053 (org-test-with-parsed-data "[[target]]"
1055 (org-export-resolve-fuzzy-link
1056 (org-element-map tree
'link
'identity info t
) info
))))
1058 (ert-deftest test-org-export
/resolve-id-link
()
1059 "Test `org-export-resolve-id-link' specifications."
1060 ;; 1. Regular test for custom-id link.
1061 (org-test-with-parsed-data "* Headline1
1068 (org-export-resolve-id-link
1069 (org-element-map tree
'link
'identity info t
) info
)))
1070 ;; 2. Failing test for custom-id link.
1071 (org-test-with-parsed-data "* Headline1
1078 (org-export-resolve-id-link
1079 (org-element-map tree
'link
'identity info t
) info
)))
1080 ;; 3. Test for internal id target.
1081 (org-test-with-parsed-data "* Headline1
1088 (org-export-resolve-id-link
1089 (org-element-map tree
'link
'identity info t
) info
)))
1090 ;; 4. Test for external id target.
1091 (org-test-with-parsed-data "[[id:aaaa]]"
1093 (org-export-resolve-id-link
1094 (org-element-map tree
'link
'identity info t
)
1095 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file"))))))))
1097 (ert-deftest test-org-export
/resolve-radio-link
()
1098 "Test `org-export-resolve-radio-link' specifications."
1100 (org-test-with-temp-text "<<<radio>>> radio"
1101 (org-update-radio-target-regexp)
1103 (let* ((tree (org-element-parse-buffer))
1104 (info `(:parse-tree
,tree
)))
1105 (org-export-resolve-radio-link
1106 (org-element-map tree
'link
'identity info t
)
1108 ;; Radio target with objects.
1109 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
1110 (org-update-radio-target-regexp)
1112 (let* ((tree (org-element-parse-buffer))
1113 (info `(:parse-tree
,tree
)))
1114 (org-export-resolve-radio-link
1115 (org-element-map tree
'link
'identity info t
)
1120 ;;; Src-block and example-block
1122 (ert-deftest test-org-export
/unravel-code
()
1123 "Test `org-export-unravel-code' function."
1124 (let ((org-coderef-label-format "(ref:%s)"))
1125 ;; 1. Code without reference.
1126 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
1127 (should (equal (org-export-unravel-code (org-element-at-point))
1129 ;; 2. Code with reference.
1130 (org-test-with-temp-text
1131 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
1132 (should (equal (org-export-unravel-code (org-element-at-point))
1133 '("(+ 1 1)\n" (1 .
"test")))))
1134 ;; 3. Code with user-defined reference.
1135 (org-test-with-temp-text
1136 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
1137 (should (equal (org-export-unravel-code (org-element-at-point))
1138 '("(+ 1 1)\n" (1 .
"test")))))
1139 ;; 4. Code references keys are relative to the current block.
1140 (org-test-with-temp-text "
1149 (should (equal (org-export-unravel-code (org-element-at-point))
1150 '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one")))))))
1156 (ert-deftest test-org-export
/activate-smart-quotes
()
1157 "Test `org-export-activate-smart-quotes' specifications."
1158 ;; Opening double quotes: standard test.
1161 '("some “paragraph")
1162 (let ((org-export-default-language "en"))
1163 (org-test-with-parsed-data "some \"paragraph"
1166 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1168 ;; Opening quotes: at the beginning of a paragraph.
1172 (let ((org-export-default-language "en"))
1173 (org-test-with-parsed-data "\"begin"
1176 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1178 ;; Opening quotes: after an object.
1182 (let ((org-export-default-language "en"))
1183 (org-test-with-parsed-data "=verb= \"begin"
1186 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1188 ;; Closing quotes: standard test.
1191 '("some” paragraph")
1192 (let ((org-export-default-language "en"))
1193 (org-test-with-parsed-data "some\" paragraph"
1196 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1198 ;; Closing quotes: at the end of a paragraph.
1202 (let ((org-export-default-language "en"))
1203 (org-test-with-parsed-data "end\""
1206 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1208 ;; Apostrophe: standard test.
1211 '("It shouldn’t fail")
1212 (let ((org-export-default-language "en"))
1213 (org-test-with-parsed-data "It shouldn't fail"
1216 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1218 ;; Apostrophe: before an object.
1222 (let ((org-export-default-language "en"))
1223 (org-test-with-parsed-data "a'=b="
1226 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1228 ;; Apostrophe: after an object.
1232 (let ((org-export-default-language "en"))
1233 (org-test-with-parsed-data "=code='s"
1236 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1238 ;; Special case: isolated quotes.
1240 (equal '("“" "”")
1241 (let ((org-export-default-language "en"))
1242 (org-test-with-parsed-data "\"$x$\""
1245 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1252 (ert-deftest test-org-export
/special-column
()
1253 "Test if the table's special column is properly recognized."
1254 ;; 1. First column is special if it contains only a special marking
1255 ;; characters or empty cells.
1256 (org-test-with-temp-text "
1260 (org-export-table-has-special-column-p
1262 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1263 ;; 2. If the column contains anything else, it isn't special.
1264 (org-test-with-temp-text "
1268 (org-export-table-has-special-column-p
1270 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1271 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
1273 (org-test-with-temp-text "
1282 (org-export-table-has-special-column-p
1284 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1285 ;; 4. A first column with only empty cells isn't considered as
1287 (org-test-with-temp-text "
1291 (org-export-table-has-special-column-p
1293 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
1295 (ert-deftest test-org-export
/table-row-is-special-p
()
1296 "Test `org-export-table-row-is-special-p' specifications."
1297 ;; 1. A row is special if it has a special marking character in the
1299 (org-test-with-parsed-data "| ! | 1 |"
1301 (org-export-table-row-is-special-p
1302 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1303 ;; 2. A row is special when its first field is "/"
1304 (org-test-with-parsed-data "
1308 (org-export-table-row-is-special-p
1309 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1310 ;; 3. A row only containing alignment cookies is also considered as
1312 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
1314 (org-export-table-row-is-special-p
1315 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1316 ;; 4. Everything else isn't considered as special.
1317 (org-test-with-parsed-data "| \alpha | | c |"
1319 (org-export-table-row-is-special-p
1320 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1321 ;; 5. Table's rules are never considered as special rows.
1322 (org-test-with-parsed-data "|---+---|"
1324 (org-export-table-row-is-special-p
1325 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
1327 (ert-deftest test-org-export
/has-header-p
()
1328 "Test `org-export-table-has-header-p' specifications."
1329 ;; 1. With an header.
1330 (org-test-with-parsed-data "
1335 (org-export-table-has-header-p
1336 (org-element-map tree
'table
'identity info
'first-match
)
1338 ;; 2. Without an header.
1339 (org-test-with-parsed-data "
1343 (org-export-table-has-header-p
1344 (org-element-map tree
'table
'identity info
'first-match
)
1346 ;; 3. Don't get fooled with starting and ending rules.
1347 (org-test-with-parsed-data "
1353 (org-export-table-has-header-p
1354 (org-element-map tree
'table
'identity info
'first-match
)
1357 (ert-deftest test-org-export
/table-row-group
()
1358 "Test `org-export-table-row-group' specifications."
1359 ;; 1. A rule creates a new group.
1360 (org-test-with-parsed-data "
1367 (mapcar (lambda (row) (org-export-table-row-group row info
))
1368 (org-element-map tree
'table-row
'identity
)))))
1369 ;; 2. Special rows are ignored in count.
1370 (org-test-with-parsed-data "
1377 (mapcar (lambda (row) (org-export-table-row-group row info
))
1378 (org-element-map tree
'table-row
'identity
)))))
1379 ;; 3. Double rules also are ignored in count.
1380 (org-test-with-parsed-data "
1388 (mapcar (lambda (row) (org-export-table-row-group row info
))
1389 (org-element-map tree
'table-row
'identity
))))))
1391 (ert-deftest test-org-export
/table-cell-width
()
1392 "Test `org-export-table-cell-width' specifications."
1393 ;; 1. Width is primarily determined by width cookies. If no cookie
1394 ;; is found, cell's width is nil.
1395 (org-test-with-parsed-data "
1396 | / | <l> | <6> | <l7> |
1401 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1402 (org-element-map tree
'table-cell
'identity info
)))))
1403 ;; 2. The last width cookie has precedence.
1404 (org-test-with-parsed-data "
1411 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1412 (org-element-map tree
'table-cell
'identity info
)))))
1413 ;; 3. Valid width cookies must have a specific row.
1414 (org-test-with-parsed-data "| <6> | cell |"
1418 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1419 (org-element-map tree
'table-cell
'identity
))))))
1421 (ert-deftest test-org-export
/table-cell-alignment
()
1422 "Test `org-export-table-cell-alignment' specifications."
1423 (let ((org-table-number-fraction 0.5)
1424 (org-table-number-regexp "^[0-9]+$"))
1425 ;; 1. Alignment is primarily determined by alignment cookies.
1426 (org-test-with-temp-text "| <l> | <c> | <r> |"
1427 (let* ((tree (org-element-parse-buffer))
1428 (info `(:parse-tree
,tree
)))
1431 '(left center right
)
1432 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1433 (org-element-map tree
'table-cell
'identity
))))))
1434 ;; 2. The last alignment cookie has precedence.
1435 (org-test-with-parsed-data "
1441 '(right right right
)
1442 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1443 (org-element-map tree
'table-cell
'identity
)))))
1444 ;; 3. If there's no cookie, cell's contents determine alignment.
1445 ;; A column mostly made of cells containing numbers will align
1446 ;; its cells to the right.
1447 (org-test-with-parsed-data "
1453 '(right right right
)
1454 (mapcar (lambda (cell)
1455 (org-export-table-cell-alignment cell info
))
1456 (org-element-map tree
'table-cell
'identity
)))))
1457 ;; 4. Otherwise, they will be aligned to the left.
1458 (org-test-with-parsed-data "
1465 (mapcar (lambda (cell)
1466 (org-export-table-cell-alignment cell info
))
1467 (org-element-map tree
'table-cell
'identity
)))))))
1469 (ert-deftest test-org-export
/table-cell-borders
()
1470 "Test `org-export-table-cell-borders' specifications."
1471 ;; 1. Recognize various column groups indicators.
1472 (org-test-with-parsed-data "| / | < | > | <> |"
1475 '((right bottom top
) (left bottom top
) (right bottom top
)
1476 (right left bottom top
))
1477 (mapcar (lambda (cell)
1478 (org-export-table-cell-borders cell info
))
1479 (org-element-map tree
'table-cell
'identity
)))))
1480 ;; 2. Accept shortcuts to define column groups.
1481 (org-test-with-parsed-data "| / | < | < |"
1484 '((right bottom top
) (right left bottom top
) (left bottom top
))
1485 (mapcar (lambda (cell)
1486 (org-export-table-cell-borders cell info
))
1487 (org-element-map tree
'table-cell
'identity
)))))
1488 ;; 3. A valid column groups row must start with a "/".
1489 (org-test-with-parsed-data "
1493 (equal '((top) (top) (bottom) (bottom))
1494 (mapcar (lambda (cell)
1495 (org-export-table-cell-borders cell info
))
1496 (org-element-map tree
'table-cell
'identity
)))))
1497 ;; 4. Take table rules into consideration.
1498 (org-test-with-parsed-data "
1503 (equal '((below top
) (bottom above
))
1504 (mapcar (lambda (cell)
1505 (org-export-table-cell-borders cell info
))
1506 (org-element-map tree
'table-cell
'identity
)))))
1507 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
1508 ;; (resp. `bottom' and `below') borders. Any special row is
1510 (org-test-with-parsed-data "
1516 (equal '((bottom below top above
))
1518 (mapcar (lambda (cell)
1519 (org-export-table-cell-borders cell info
))
1520 (org-element-map tree
'table-cell
'identity
)))))))
1522 (ert-deftest test-org-export
/table-dimensions
()
1523 "Test `org-export-table-dimensions' specifications."
1524 ;; 1. Standard test.
1525 (org-test-with-parsed-data "
1530 (org-export-table-dimensions
1531 (org-element-map tree
'table
'identity info
'first-match
) info
))))
1532 ;; 2. Ignore horizontal rules and special columns.
1533 (org-test-with-parsed-data "
1540 (org-export-table-dimensions
1541 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
1543 (ert-deftest test-org-export
/table-cell-address
()
1544 "Test `org-export-table-cell-address' specifications."
1545 ;; 1. Standard test: index is 0-based.
1546 (org-test-with-parsed-data "| a | b |"
1548 (equal '((0 .
0) (0 .
1))
1551 (lambda (cell) (org-export-table-cell-address cell info
))
1553 ;; 2. Special column isn't counted, nor are special rows.
1554 (org-test-with-parsed-data "
1559 (org-export-table-cell-address
1560 (car (last (org-element-map tree
'table-cell
'identity info
)))
1562 ;; 3. Tables rules do not count either.
1563 (org-test-with-parsed-data "
1571 (org-export-table-cell-address
1572 (car (last (org-element-map tree
'table-cell
'identity info
)))
1574 ;; 4. Return nil for special cells.
1575 (org-test-with-parsed-data "| / | a |"
1577 (org-export-table-cell-address
1578 (org-element-map tree
'table-cell
'identity nil
'first-match
)
1581 (ert-deftest test-org-export
/get-table-cell-at
()
1582 "Test `org-export-get-table-cell-at' specifications."
1583 ;; 1. Address ignores special columns, special rows and rules.
1584 (org-test-with-parsed-data "
1591 (org-element-contents
1592 (org-export-get-table-cell-at
1594 (org-element-map tree
'table
'identity info
'first-match
)
1596 ;; 2. Return value for a non-existent address is nil.
1597 (org-test-with-parsed-data "| a |"
1599 (org-export-get-table-cell-at
1601 (org-element-map tree
'table
'identity info
'first-match
)
1603 (org-test-with-parsed-data "| / |"
1605 (org-export-get-table-cell-at
1607 (org-element-map tree
'table
'identity info
'first-match
)
1610 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
1611 "Test `org-export-table-cell-starts-colgroup-p' specifications."
1612 ;; 1. A cell at a beginning of a row always starts a column group.
1613 (org-test-with-parsed-data "| a |"
1615 (org-export-table-cell-starts-colgroup-p
1616 (org-element-map tree
'table-cell
'identity info
'first-match
)
1618 ;; 2. Special column should be ignored when determining the
1619 ;; beginning of the row.
1620 (org-test-with-parsed-data "
1624 (org-export-table-cell-starts-colgroup-p
1625 (org-element-map tree
'table-cell
'identity info
'first-match
)
1627 ;; 2. Explicit column groups.
1628 (org-test-with-parsed-data "
1637 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
1640 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
1641 "Test `org-export-table-cell-ends-colgroup-p' specifications."
1642 ;; 1. A cell at the end of a row always ends a column group.
1643 (org-test-with-parsed-data "| a |"
1645 (org-export-table-cell-ends-colgroup-p
1646 (org-element-map tree
'table-cell
'identity info
'first-match
)
1648 ;; 2. Special column should be ignored when determining the
1649 ;; beginning of the row.
1650 (org-test-with-parsed-data "
1654 (org-export-table-cell-ends-colgroup-p
1655 (org-element-map tree
'table-cell
'identity info
'first-match
)
1657 ;; 3. Explicit column groups.
1658 (org-test-with-parsed-data "
1667 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
1670 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
1671 "Test `org-export-table-row-starts-rowgroup-p' specifications."
1672 ;; 1. A row at the beginning of a table always starts a row group.
1673 ;; So does a row following a table rule.
1674 (org-test-with-parsed-data "
1684 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
1686 ;; 2. Special rows should be ignored when determining the beginning
1688 (org-test-with-parsed-data "
1700 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
1703 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
1704 "Test `org-export-table-row-ends-rowgroup-p' specifications."
1705 ;; 1. A row at the end of a table always ends a row group. So does
1706 ;; a row preceding a table rule.
1707 (org-test-with-parsed-data "
1717 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
1719 ;; 2. Special rows should be ignored when determining the beginning
1721 (org-test-with-parsed-data "
1733 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
1736 (ert-deftest test-org-export
/table-row-starts-header-p
()
1737 "Test `org-export-table-row-starts-header-p' specifications."
1738 ;; 1. Only the row starting the first row group starts the table
1740 (org-test-with-parsed-data "
1751 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
1753 ;; 2. A row cannot start an header if there's no header in the
1755 (org-test-with-parsed-data "
1759 (org-export-table-row-starts-header-p
1760 (org-element-map tree
'table-row
'identity info
'first-match
)
1763 (ert-deftest test-org-export
/table-row-ends-header-p
()
1764 "Test `org-export-table-row-ends-header-p' specifications."
1765 ;; 1. Only the row starting the first row group starts the table
1767 (org-test-with-parsed-data "
1778 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
1780 ;; 2. A row cannot start an header if there's no header in the
1782 (org-test-with-parsed-data "
1786 (org-export-table-row-ends-header-p
1787 (org-element-map tree
'table-row
'identity info
'first-match
)
1794 (ert-deftest test-org-export
/get-next-element
()
1795 "Test `org-export-get-next-element' specifications."
1799 (org-test-with-parsed-data "* Headline\n*a* b"
1800 (org-export-get-next-element
1801 (org-element-map tree
'bold
'identity info t
) info
))))
1802 ;; Return nil when no previous element.
1804 (org-test-with-parsed-data "* Headline\na *b*"
1805 (org-export-get-next-element
1806 (org-element-map tree
'bold
'identity info t
) info
)))
1807 ;; Non-exportable elements are ignored.
1809 (let ((org-export-with-timestamps nil
))
1810 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
1811 (org-export-get-next-element
1812 (org-element-map tree
'entity
'identity info t
) info
)))))
1814 (ert-deftest test-org-export
/get-previous-element
()
1815 "Test `org-export-get-previous-element' specifications."
1819 (org-test-with-parsed-data "* Headline\na *b*"
1820 (org-export-get-previous-element
1821 (org-element-map tree
'bold
'identity info t
) info
))))
1822 ;; Return nil when no previous element.
1824 (org-test-with-parsed-data "* Headline\n*a* b"
1825 (org-export-get-previous-element
1826 (org-element-map tree
'bold
'identity info t
) info
)))
1827 ;; Non-exportable elements are ignored.
1829 (let ((org-export-with-timestamps nil
))
1830 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
1831 (org-export-get-previous-element
1832 (org-element-map tree
'entity
'identity info t
) info
)))))
1835 (provide 'test-org-export
)
1836 ;;; test-org-export.el end here