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"
443 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
445 (org-export-expand-macro info
) (buffer-string)))))
446 ;; Export specific macros.
448 (equal "me 2012-03-29 me@here Title"
449 (org-test-with-temp-text
455 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
456 (let ((info (org-export-get-environment)))
457 (org-export-expand-macro info
)
458 (goto-char (point-max))
459 (buffer-substring (line-beginning-position)
460 (line-end-position))))))
461 ;; Expand macros with templates in included files.
464 (org-test-with-temp-text
465 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
466 {{{included-macro}}}" org-test-dir
)
468 (org-export-expand-include-keyword)
469 (org-export-expand-macro info
)
470 (goto-char (point-max))
471 (buffer-substring (line-beginning-position)
472 (line-end-position)))))))
474 (ert-deftest test-org-export
/user-ignore-list
()
475 "Test if `:ignore-list' accepts user input."
476 (org-test-with-backend test
477 (flet ((skip-note-head
479 ;; Ignore headlines with the word "note" in their title.
483 (when (string-match "\\<note\\>"
484 (org-element-property :raw-value headline
))
485 (org-export-ignore-element headline info
)))
488 ;; Install function in parse tree filters.
489 (let ((org-export-filter-parse-tree-functions '(skip-note-head)))
490 (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
491 (should (equal (org-export-as 'test
) "* Head1\n")))))))
493 (ert-deftest test-org-export
/before-parsing-hook
()
494 "Test `org-export-before-parsing-hook'."
495 (org-test-with-backend test
496 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
497 (let ((org-export-before-parsing-hook
501 (delete-region (point) (progn (forward-line) (point)))))))))
502 (should (equal (org-export-as 'test
) "Body 1\nBody 2\n"))))))
506 ;;; Affiliated Keywords
508 (ert-deftest test-org-export
/read-attribute
()
509 "Test `org-export-read-attribute' specifications."
513 (org-export-read-attribute
515 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
516 (org-element-at-point)))
518 ;; Return nil on empty attribute.
520 (org-export-read-attribute
522 (org-test-with-temp-text "Paragraph" (org-element-at-point)))))
524 (ert-deftest test-org-export
/get-caption
()
525 "Test `org-export-get-caption' specifications."
526 ;; Without optional argument, return long caption
530 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
531 (org-export-get-caption (org-element-at-point)))))
532 ;; With optional argument, return short caption.
536 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
537 (org-export-get-caption (org-element-at-point) t
))))
538 ;; Multiple lines are separated by white spaces.
542 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
543 (org-export-get-caption (org-element-at-point))))))
549 (ert-deftest test-org-export
/export-snippet
()
550 "Test export snippets transcoding."
551 (org-test-with-temp-text "@@test:A@@@@t:B@@"
552 (org-test-with-backend test
553 (let ((org-test-translate-alist
554 (cons (cons 'export-snippet
555 (lambda (snippet contents info
)
556 (when (eq (org-export-snippet-backend snippet
) 'test
)
557 (org-element-property :value snippet
))))
558 org-test-translate-alist
)))
559 (let ((org-export-snippet-translation-alist nil
))
560 (should (equal (org-export-as 'test
) "A\n")))
561 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
562 (should (equal (org-export-as 'test
) "AB\n")))))))
568 (ert-deftest test-org-export
/footnotes
()
569 "Test footnotes specifications."
570 (let ((org-footnote-section nil
)
571 (org-export-with-footnotes t
))
572 ;; 1. Read every type of footnote.
575 '((1 .
"A\n") (2 .
"B") (3 .
"C") (4 .
"D"))
576 (org-test-with-parsed-data
577 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
579 tree
'footnote-reference
581 (let ((def (org-export-get-footnote-definition ref info
)))
582 (cons (org-export-get-footnote-number ref info
)
583 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
584 (car (org-element-contents
585 (car (org-element-contents def
))))))))
587 ;; 2. Test nested footnotes order.
588 (org-test-with-parsed-data
589 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
592 '((1 .
"fn:1") (2 .
"fn:2") (3 .
"fn:3") (4))
594 tree
'footnote-reference
596 (when (org-export-footnote-first-reference-p ref info
)
597 (cons (org-export-get-footnote-number ref info
)
598 (org-element-property :label ref
))))
600 ;; 3. Test nested footnote in invisible definitions.
601 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
603 (narrow-to-region (point) (point-at-eol))
604 (let* ((tree (org-element-parse-buffer))
605 (info (org-combine-plists
607 (org-export-collect-tree-properties
608 tree
(org-export-get-environment)))))
609 ;; Both footnotes should be seen.
611 (= (length (org-export-collect-footnote-definitions tree info
)) 2))))
612 ;; 4. Test footnotes definitions collection.
613 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
615 \[fn:2] B [fn:3] [fn::D].
618 (should (= (length (org-export-collect-footnote-definitions tree info
))
620 ;; 5. Test export of footnotes defined outside parsing scope.
621 (org-test-with-temp-text "[fn:1] Out of scope
624 (org-test-with-backend test
625 (let ((org-test-translate-alist
626 (cons (cons 'footnote-reference
627 (lambda (fn contents info
)
628 (org-element-interpret-data
629 (org-export-get-footnote-definition fn info
))))
630 org-test-translate-alist
)))
632 (should (equal "ParagraphOut of scope\n"
633 (org-export-as 'test
'subtree
))))))))
637 ;;; Headlines and Inlinetasks
639 (ert-deftest test-org-export
/get-relative-level
()
640 "Test `org-export-get-relative-level' specifications."
644 (let ((org-odd-levels-only nil
))
645 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
648 (lambda (h) (org-export-get-relative-level h info
))
653 (let ((org-odd-levels-only nil
))
654 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
657 (lambda (h) (org-export-get-relative-level h info
))
660 (ert-deftest test-org-export
/low-level-p
()
661 "Test `org-export-low-level-p' specifications."
665 (let ((org-odd-levels-only nil
))
666 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
669 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
670 (plist-put info
:headline-levels
1)))))))
672 (ert-deftest test-org-export
/get-headline-number
()
673 "Test `org-export-get-headline-number' specifications."
678 (let ((org-odd-levels-only nil
))
679 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
682 (lambda (h) (org-export-get-headline-number h info
))
684 ;; Missing levels are replaced with 0.
688 (let ((org-odd-levels-only nil
))
689 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
692 (lambda (h) (org-export-get-headline-number h info
))
695 (ert-deftest test-org-export
/numbered-headline-p
()
696 "Test `org-export-numbered-headline-p' specifications."
697 ;; If `:section-numbers' is nil, never number headlines.
699 (org-test-with-parsed-data "* Headline"
702 (lambda (h) (org-export-numbered-headline-p h info
))
703 (plist-put info
:section-numbers nil
))))
704 ;; If `:section-numbers' is a number, only number headlines with
705 ;; a level greater that it.
709 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
712 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
713 (plist-put info
:section-numbers
1)))))
714 ;; Otherwise, headlines are always numbered.
716 (org-test-with-parsed-data "* Headline"
719 (lambda (h) (org-export-numbered-headline-p h info
))
720 (plist-put info
:section-numbers t
)))))
722 (ert-deftest test-org-export
/number-to-roman
()
723 "Test `org-export-number-to-roman' specifications."
724 ;; If number is negative, return it as a string.
725 (should (equal (org-export-number-to-roman -
1) "-1"))
726 ;; Otherwise, return it as a roman number.
727 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
729 (ert-deftest test-org-export
/get-tags
()
730 "Test `org-export-get-tags' specifications."
731 (let ((org-export-exclude-tags '("noexport"))
732 (org-export-select-tags '("export")))
733 ;; Standard test: tags which are not a select tag, an exclude tag,
734 ;; or specified as optional argument shouldn't be ignored.
736 (org-test-with-parsed-data "* Headline :tag:"
737 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
739 ;; Exclude tags are removed.
741 (org-test-with-parsed-data "* Headline :noexport:"
742 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
744 ;; Select tags are removed.
746 (org-test-with-parsed-data "* Headline :export:"
747 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
752 (org-test-with-parsed-data "* Headline :tag:export:"
753 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
755 ;; Tags provided in the optional argument are also ignored.
757 (org-test-with-parsed-data "* Headline :ignore:"
758 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
760 ;; Allow tag inheritance.
764 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
767 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))))
769 (ert-deftest test-org-export
/get-node-property
()
770 "Test`org-export-get-node-property' specifications."
774 (org-test-with-parsed-data "* Headline
778 (org-export-get-node-property
779 :prop
(org-element-map tree
'headline
'identity nil t
)))))
783 (org-test-with-parsed-data "* Parent
789 (org-export-get-node-property
790 :prop
(org-element-map tree
'paragraph
'identity nil t
) t
))))
791 ;; Cannot return a value before the first headline.
793 (org-test-with-parsed-data "Paragraph
798 (org-export-get-node-property
799 :prop
(org-element-map tree
'paragraph
'identity nil t
)))))
801 (ert-deftest test-org-export
/first-sibling-p
()
802 "Test `org-export-first-sibling-p' specifications."
807 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
810 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
812 ;; Ignore headlines not exported.
816 (let ((org-export-exclude-tags '("ignore")))
817 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
820 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
823 (ert-deftest test-org-export
/last-sibling-p
()
824 "Test `org-export-last-sibling-p' specifications."
829 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
832 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
834 ;; Ignore headlines not exported.
838 (let ((org-export-exclude-tags '("ignore")))
839 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
842 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
849 (ert-deftest test-org-export
/get-coderef-format
()
850 "Test `org-export-get-coderef-format' specifications."
851 ;; A link without description returns "%s"
852 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
854 ;; Return "%s" when path is matched within description.
855 (should (equal (org-export-get-coderef-format "path" "desc (path)")
857 ;; Otherwise return description.
858 (should (equal (org-export-get-coderef-format "path" "desc")
861 (ert-deftest test-org-export
/inline-image-p
()
862 "Test `org-export-inline-image-p' specifications."
864 (org-export-inline-image-p
865 (org-test-with-temp-text "[[#id]]"
867 (org-element-parse-buffer) 'link
'identity nil t
))
868 '(("custom-id" .
"id")))))
870 (ert-deftest test-org-export
/fuzzy-link
()
871 "Test fuzzy links specifications."
872 ;; 1. Links to invisible (keyword) targets should be ignored.
873 (org-test-with-parsed-data
874 "Paragraph.\n#+TARGET: Test\n[[Test]]"
879 (org-export-get-ordinal
880 (org-export-resolve-fuzzy-link link info
) info
)) info
)))
881 ;; 2. Link to an headline should return headline's number.
882 (org-test-with-parsed-data
883 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
885 ;; Note: Headline's number is in fact a list of numbers.
890 (org-export-get-ordinal
891 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
892 ;; 3. Link to a target in an item should return item's number.
893 (org-test-with-parsed-data
894 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
896 ;; Note: Item's number is in fact a list of numbers.
901 (org-export-get-ordinal
902 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
903 ;; 4. Link to a target in a footnote should return footnote's
905 (org-test-with-parsed-data "
906 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
912 (org-export-get-ordinal
913 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
914 ;; 5. Link to a named element should return sequence number of that
916 (org-test-with-parsed-data
917 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
923 (org-export-get-ordinal
924 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
925 ;; 6. Link to a target not within an item, a table, a footnote
926 ;; reference or definition should return section number.
927 (org-test-with-parsed-data
928 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
934 (org-export-get-ordinal
935 (org-export-resolve-fuzzy-link link info
) info
)) info t
)))))
937 (ert-deftest test-org-export
/resolve-coderef
()
938 "Test `org-export-resolve-coderef' specifications."
939 (let ((org-coderef-label-format "(ref:%s)"))
940 ;; 1. A link to a "-n -k -r" block returns line number.
941 (org-test-with-parsed-data
942 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
943 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
944 (org-test-with-parsed-data
945 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
946 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
947 ;; 2. A link to a "-n -r" block returns line number.
948 (org-test-with-parsed-data
949 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
950 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
951 (org-test-with-parsed-data
952 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
953 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
954 ;; 3. A link to a "-n" block returns coderef.
955 (org-test-with-parsed-data
956 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
957 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
958 (org-test-with-parsed-data
959 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
960 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
961 ;; 4. A link to a "-r" block returns line number.
962 (org-test-with-parsed-data
963 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
964 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
965 (org-test-with-parsed-data
966 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
967 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
968 ;; 5. A link to a block without a switch returns coderef.
969 (org-test-with-parsed-data
970 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
971 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
972 (org-test-with-parsed-data
973 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
974 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
975 ;; 6. Correctly handle continued line numbers. A "+n" switch
976 ;; should resume numbering from previous block with numbered
977 ;; lines, ignoring blocks not numbering lines in the process.
978 ;; A "-n" switch resets count.
979 (org-test-with-parsed-data "
984 #+BEGIN_SRC emacs-lisp
988 #+BEGIN_SRC emacs-lisp +n -r
989 \(+ 1 1) (ref:addition)
992 #+BEGIN_EXAMPLE -n -r
993 Another text. (ref:text)
995 (should (= (org-export-resolve-coderef "addition" info
) 2))
996 (should (= (org-export-resolve-coderef "text" info
) 1)))
997 ;; 7. Recognize coderef with user-specified syntax.
998 (org-test-with-parsed-data
999 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
1000 (should (equal (org-export-resolve-coderef "text" info
) "text")))))
1002 (ert-deftest test-org-export
/resolve-fuzzy-link
()
1003 "Test `org-export-resolve-fuzzy-link' specifications."
1004 ;; 1. Match target objects.
1005 (org-test-with-parsed-data "<<target>> [[target]]"
1007 (org-export-resolve-fuzzy-link
1008 (org-element-map tree
'link
'identity info t
) info
)))
1009 ;; 2. Match target elements.
1010 (org-test-with-parsed-data "#+TARGET: target\n[[target]]"
1012 (org-export-resolve-fuzzy-link
1013 (org-element-map tree
'link
'identity info t
) info
)))
1014 ;; 3. Match named elements.
1015 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
1017 (org-export-resolve-fuzzy-link
1018 (org-element-map tree
'link
'identity info t
) info
)))
1019 ;; 4. Match exact headline's name.
1020 (org-test-with-parsed-data "* My headline\n[[My headline]]"
1022 (org-export-resolve-fuzzy-link
1023 (org-element-map tree
'link
'identity info t
) info
)))
1024 ;; 5. Targets objects have priority over named elements and headline
1026 (org-test-with-parsed-data
1027 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
1031 (org-export-resolve-fuzzy-link
1032 (org-element-map tree
'link
'identity info t
) info
)))))
1033 ;; 6. Named elements have priority over headline titles.
1034 (org-test-with-parsed-data
1035 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
1039 (org-export-resolve-fuzzy-link
1040 (org-element-map tree
'link
'identity info t
) info
)))))
1041 ;; 7. If link's path starts with a "*", only match headline titles,
1043 (org-test-with-parsed-data
1044 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
1048 (org-export-resolve-fuzzy-link
1049 (org-element-map tree
'link
'identity info t
) info
)))))
1050 ;; 8. Return nil if no match.
1051 (org-test-with-parsed-data "[[target]]"
1053 (org-export-resolve-fuzzy-link
1054 (org-element-map tree
'link
'identity info t
) info
))))
1056 (ert-deftest test-org-export
/resolve-id-link
()
1057 "Test `org-export-resolve-id-link' specifications."
1058 ;; 1. Regular test for custom-id link.
1059 (org-test-with-parsed-data "* Headline1
1066 (org-export-resolve-id-link
1067 (org-element-map tree
'link
'identity info t
) info
)))
1068 ;; 2. Failing test for custom-id link.
1069 (org-test-with-parsed-data "* Headline1
1076 (org-export-resolve-id-link
1077 (org-element-map tree
'link
'identity info t
) info
)))
1078 ;; 3. Test for internal id target.
1079 (org-test-with-parsed-data "* Headline1
1086 (org-export-resolve-id-link
1087 (org-element-map tree
'link
'identity info t
) info
)))
1088 ;; 4. Test for external id target.
1089 (org-test-with-parsed-data "[[id:aaaa]]"
1091 (org-export-resolve-id-link
1092 (org-element-map tree
'link
'identity info t
)
1093 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file"))))))))
1095 (ert-deftest test-org-export
/resolve-radio-link
()
1096 "Test `org-export-resolve-radio-link' specifications."
1098 (org-test-with-temp-text "<<<radio>>> radio"
1099 (org-update-radio-target-regexp)
1101 (let* ((tree (org-element-parse-buffer))
1102 (info `(:parse-tree
,tree
)))
1103 (org-export-resolve-radio-link
1104 (org-element-map tree
'link
'identity info t
)
1106 ;; Radio target with objects.
1107 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
1108 (org-update-radio-target-regexp)
1110 (let* ((tree (org-element-parse-buffer))
1111 (info `(:parse-tree
,tree
)))
1112 (org-export-resolve-radio-link
1113 (org-element-map tree
'link
'identity info t
)
1118 ;;; Src-block and example-block
1120 (ert-deftest test-org-export
/unravel-code
()
1121 "Test `org-export-unravel-code' function."
1122 (let ((org-coderef-label-format "(ref:%s)"))
1123 ;; 1. Code without reference.
1124 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
1125 (should (equal (org-export-unravel-code (org-element-at-point))
1127 ;; 2. Code with reference.
1128 (org-test-with-temp-text
1129 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
1130 (should (equal (org-export-unravel-code (org-element-at-point))
1131 '("(+ 1 1)\n" (1 .
"test")))))
1132 ;; 3. Code with user-defined reference.
1133 (org-test-with-temp-text
1134 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
1135 (should (equal (org-export-unravel-code (org-element-at-point))
1136 '("(+ 1 1)\n" (1 .
"test")))))
1137 ;; 4. Code references keys are relative to the current block.
1138 (org-test-with-temp-text "
1147 (should (equal (org-export-unravel-code (org-element-at-point))
1148 '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one")))))))
1154 (ert-deftest test-org-export
/activate-smart-quotes
()
1155 "Test `org-export-activate-smart-quotes' specifications."
1156 ;; Opening double quotes: standard test.
1159 '("some “paragraph")
1160 (let ((org-export-default-language "en"))
1161 (org-test-with-parsed-data "some \"paragraph"
1164 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1166 ;; Opening quotes: at the beginning of a paragraph.
1170 (let ((org-export-default-language "en"))
1171 (org-test-with-parsed-data "\"begin"
1174 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1176 ;; Opening quotes: after an object.
1180 (let ((org-export-default-language "en"))
1181 (org-test-with-parsed-data "=verb= \"begin"
1184 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1186 ;; Closing quotes: standard test.
1189 '("some” paragraph")
1190 (let ((org-export-default-language "en"))
1191 (org-test-with-parsed-data "some\" paragraph"
1194 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1196 ;; Closing quotes: at the end of a paragraph.
1200 (let ((org-export-default-language "en"))
1201 (org-test-with-parsed-data "end\""
1204 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1206 ;; Apostrophe: standard test.
1209 '("It shouldn’t fail")
1210 (let ((org-export-default-language "en"))
1211 (org-test-with-parsed-data "It shouldn't fail"
1214 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1216 ;; Apostrophe: before an object.
1220 (let ((org-export-default-language "en"))
1221 (org-test-with-parsed-data "a'=b="
1224 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1226 ;; Apostrophe: after an object.
1230 (let ((org-export-default-language "en"))
1231 (org-test-with-parsed-data "=code='s"
1234 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1241 (ert-deftest test-org-export
/special-column
()
1242 "Test if the table's special column is properly recognized."
1243 ;; 1. First column is special if it contains only a special marking
1244 ;; characters or empty cells.
1245 (org-test-with-temp-text "
1249 (org-export-table-has-special-column-p
1251 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1252 ;; 2. If the column contains anything else, it isn't special.
1253 (org-test-with-temp-text "
1257 (org-export-table-has-special-column-p
1259 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1260 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
1262 (org-test-with-temp-text "
1271 (org-export-table-has-special-column-p
1273 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1274 ;; 4. A first column with only empty cells isn't considered as
1276 (org-test-with-temp-text "
1280 (org-export-table-has-special-column-p
1282 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
1284 (ert-deftest test-org-export
/table-row-is-special-p
()
1285 "Test `org-export-table-row-is-special-p' specifications."
1286 ;; 1. A row is special if it has a special marking character in the
1288 (org-test-with-parsed-data "| ! | 1 |"
1290 (org-export-table-row-is-special-p
1291 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1292 ;; 2. A row is special when its first field is "/"
1293 (org-test-with-parsed-data "
1297 (org-export-table-row-is-special-p
1298 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1299 ;; 3. A row only containing alignment cookies is also considered as
1301 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
1303 (org-export-table-row-is-special-p
1304 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1305 ;; 4. Everything else isn't considered as special.
1306 (org-test-with-parsed-data "| \alpha | | c |"
1308 (org-export-table-row-is-special-p
1309 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1310 ;; 5. Table's rules are never considered as special rows.
1311 (org-test-with-parsed-data "|---+---|"
1313 (org-export-table-row-is-special-p
1314 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
1316 (ert-deftest test-org-export
/has-header-p
()
1317 "Test `org-export-table-has-header-p' specifications."
1318 ;; 1. With an header.
1319 (org-test-with-parsed-data "
1324 (org-export-table-has-header-p
1325 (org-element-map tree
'table
'identity info
'first-match
)
1327 ;; 2. Without an header.
1328 (org-test-with-parsed-data "
1332 (org-export-table-has-header-p
1333 (org-element-map tree
'table
'identity info
'first-match
)
1335 ;; 3. Don't get fooled with starting and ending rules.
1336 (org-test-with-parsed-data "
1342 (org-export-table-has-header-p
1343 (org-element-map tree
'table
'identity info
'first-match
)
1346 (ert-deftest test-org-export
/table-row-group
()
1347 "Test `org-export-table-row-group' specifications."
1348 ;; 1. A rule creates a new group.
1349 (org-test-with-parsed-data "
1356 (mapcar (lambda (row) (org-export-table-row-group row info
))
1357 (org-element-map tree
'table-row
'identity
)))))
1358 ;; 2. Special rows are ignored in count.
1359 (org-test-with-parsed-data "
1366 (mapcar (lambda (row) (org-export-table-row-group row info
))
1367 (org-element-map tree
'table-row
'identity
)))))
1368 ;; 3. Double rules also are ignored in count.
1369 (org-test-with-parsed-data "
1377 (mapcar (lambda (row) (org-export-table-row-group row info
))
1378 (org-element-map tree
'table-row
'identity
))))))
1380 (ert-deftest test-org-export
/table-cell-width
()
1381 "Test `org-export-table-cell-width' specifications."
1382 ;; 1. Width is primarily determined by width cookies. If no cookie
1383 ;; is found, cell's width is nil.
1384 (org-test-with-parsed-data "
1385 | / | <l> | <6> | <l7> |
1390 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1391 (org-element-map tree
'table-cell
'identity info
)))))
1392 ;; 2. The last width cookie has precedence.
1393 (org-test-with-parsed-data "
1400 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1401 (org-element-map tree
'table-cell
'identity info
)))))
1402 ;; 3. Valid width cookies must have a specific row.
1403 (org-test-with-parsed-data "| <6> | cell |"
1407 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1408 (org-element-map tree
'table-cell
'identity
))))))
1410 (ert-deftest test-org-export
/table-cell-alignment
()
1411 "Test `org-export-table-cell-alignment' specifications."
1412 (let ((org-table-number-fraction 0.5)
1413 (org-table-number-regexp "^[0-9]+$"))
1414 ;; 1. Alignment is primarily determined by alignment cookies.
1415 (org-test-with-temp-text "| <l> | <c> | <r> |"
1416 (let* ((tree (org-element-parse-buffer))
1417 (info `(:parse-tree
,tree
)))
1420 '(left center right
)
1421 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1422 (org-element-map tree
'table-cell
'identity
))))))
1423 ;; 2. The last alignment cookie has precedence.
1424 (org-test-with-parsed-data "
1430 '(right right right
)
1431 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1432 (org-element-map tree
'table-cell
'identity
)))))
1433 ;; 3. If there's no cookie, cell's contents determine alignment.
1434 ;; A column mostly made of cells containing numbers will align
1435 ;; its cells to the right.
1436 (org-test-with-parsed-data "
1442 '(right right right
)
1443 (mapcar (lambda (cell)
1444 (org-export-table-cell-alignment cell info
))
1445 (org-element-map tree
'table-cell
'identity
)))))
1446 ;; 4. Otherwise, they will be aligned to the left.
1447 (org-test-with-parsed-data "
1454 (mapcar (lambda (cell)
1455 (org-export-table-cell-alignment cell info
))
1456 (org-element-map tree
'table-cell
'identity
)))))))
1458 (ert-deftest test-org-export
/table-cell-borders
()
1459 "Test `org-export-table-cell-borders' specifications."
1460 ;; 1. Recognize various column groups indicators.
1461 (org-test-with-parsed-data "| / | < | > | <> |"
1464 '((right bottom top
) (left bottom top
) (right bottom top
)
1465 (right left bottom top
))
1466 (mapcar (lambda (cell)
1467 (org-export-table-cell-borders cell info
))
1468 (org-element-map tree
'table-cell
'identity
)))))
1469 ;; 2. Accept shortcuts to define column groups.
1470 (org-test-with-parsed-data "| / | < | < |"
1473 '((right bottom top
) (right left bottom top
) (left bottom top
))
1474 (mapcar (lambda (cell)
1475 (org-export-table-cell-borders cell info
))
1476 (org-element-map tree
'table-cell
'identity
)))))
1477 ;; 3. A valid column groups row must start with a "/".
1478 (org-test-with-parsed-data "
1482 (equal '((top) (top) (bottom) (bottom))
1483 (mapcar (lambda (cell)
1484 (org-export-table-cell-borders cell info
))
1485 (org-element-map tree
'table-cell
'identity
)))))
1486 ;; 4. Take table rules into consideration.
1487 (org-test-with-parsed-data "
1492 (equal '((below top
) (bottom above
))
1493 (mapcar (lambda (cell)
1494 (org-export-table-cell-borders cell info
))
1495 (org-element-map tree
'table-cell
'identity
)))))
1496 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
1497 ;; (resp. `bottom' and `below') borders. Any special row is
1499 (org-test-with-parsed-data "
1505 (equal '((bottom below top above
))
1507 (mapcar (lambda (cell)
1508 (org-export-table-cell-borders cell info
))
1509 (org-element-map tree
'table-cell
'identity
)))))))
1511 (ert-deftest test-org-export
/table-dimensions
()
1512 "Test `org-export-table-dimensions' specifications."
1513 ;; 1. Standard test.
1514 (org-test-with-parsed-data "
1519 (org-export-table-dimensions
1520 (org-element-map tree
'table
'identity info
'first-match
) info
))))
1521 ;; 2. Ignore horizontal rules and special columns.
1522 (org-test-with-parsed-data "
1529 (org-export-table-dimensions
1530 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
1532 (ert-deftest test-org-export
/table-cell-address
()
1533 "Test `org-export-table-cell-address' specifications."
1534 ;; 1. Standard test: index is 0-based.
1535 (org-test-with-parsed-data "| a | b |"
1537 (equal '((0 .
0) (0 .
1))
1540 (lambda (cell) (org-export-table-cell-address cell info
))
1542 ;; 2. Special column isn't counted, nor are special rows.
1543 (org-test-with-parsed-data "
1548 (org-export-table-cell-address
1549 (car (last (org-element-map tree
'table-cell
'identity info
)))
1551 ;; 3. Tables rules do not count either.
1552 (org-test-with-parsed-data "
1560 (org-export-table-cell-address
1561 (car (last (org-element-map tree
'table-cell
'identity info
)))
1563 ;; 4. Return nil for special cells.
1564 (org-test-with-parsed-data "| / | a |"
1566 (org-export-table-cell-address
1567 (org-element-map tree
'table-cell
'identity nil
'first-match
)
1570 (ert-deftest test-org-export
/get-table-cell-at
()
1571 "Test `org-export-get-table-cell-at' specifications."
1572 ;; 1. Address ignores special columns, special rows and rules.
1573 (org-test-with-parsed-data "
1580 (org-element-contents
1581 (org-export-get-table-cell-at
1583 (org-element-map tree
'table
'identity info
'first-match
)
1585 ;; 2. Return value for a non-existent address is nil.
1586 (org-test-with-parsed-data "| a |"
1588 (org-export-get-table-cell-at
1590 (org-element-map tree
'table
'identity info
'first-match
)
1592 (org-test-with-parsed-data "| / |"
1594 (org-export-get-table-cell-at
1596 (org-element-map tree
'table
'identity info
'first-match
)
1599 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
1600 "Test `org-export-table-cell-starts-colgroup-p' specifications."
1601 ;; 1. A cell at a beginning of a row always starts a column group.
1602 (org-test-with-parsed-data "| a |"
1604 (org-export-table-cell-starts-colgroup-p
1605 (org-element-map tree
'table-cell
'identity info
'first-match
)
1607 ;; 2. Special column should be ignored when determining the
1608 ;; beginning of the row.
1609 (org-test-with-parsed-data "
1613 (org-export-table-cell-starts-colgroup-p
1614 (org-element-map tree
'table-cell
'identity info
'first-match
)
1616 ;; 2. Explicit column groups.
1617 (org-test-with-parsed-data "
1626 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
1629 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
1630 "Test `org-export-table-cell-ends-colgroup-p' specifications."
1631 ;; 1. A cell at the end of a row always ends a column group.
1632 (org-test-with-parsed-data "| a |"
1634 (org-export-table-cell-ends-colgroup-p
1635 (org-element-map tree
'table-cell
'identity info
'first-match
)
1637 ;; 2. Special column should be ignored when determining the
1638 ;; beginning of the row.
1639 (org-test-with-parsed-data "
1643 (org-export-table-cell-ends-colgroup-p
1644 (org-element-map tree
'table-cell
'identity info
'first-match
)
1646 ;; 3. Explicit column groups.
1647 (org-test-with-parsed-data "
1656 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
1659 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
1660 "Test `org-export-table-row-starts-rowgroup-p' specifications."
1661 ;; 1. A row at the beginning of a table always starts a row group.
1662 ;; So does a row following a table rule.
1663 (org-test-with-parsed-data "
1673 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
1675 ;; 2. Special rows should be ignored when determining the beginning
1677 (org-test-with-parsed-data "
1689 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
1692 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
1693 "Test `org-export-table-row-ends-rowgroup-p' specifications."
1694 ;; 1. A row at the end of a table always ends a row group. So does
1695 ;; a row preceding a table rule.
1696 (org-test-with-parsed-data "
1706 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
1708 ;; 2. Special rows should be ignored when determining the beginning
1710 (org-test-with-parsed-data "
1722 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
1725 (ert-deftest test-org-export
/table-row-starts-header-p
()
1726 "Test `org-export-table-row-starts-header-p' specifications."
1727 ;; 1. Only the row starting the first row group starts the table
1729 (org-test-with-parsed-data "
1740 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
1742 ;; 2. A row cannot start an header if there's no header in the
1744 (org-test-with-parsed-data "
1748 (org-export-table-row-starts-header-p
1749 (org-element-map tree
'table-row
'identity info
'first-match
)
1752 (ert-deftest test-org-export
/table-row-ends-header-p
()
1753 "Test `org-export-table-row-ends-header-p' specifications."
1754 ;; 1. Only the row starting the first row group starts the table
1756 (org-test-with-parsed-data "
1767 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
1769 ;; 2. A row cannot start an header if there's no header in the
1771 (org-test-with-parsed-data "
1775 (org-export-table-row-ends-header-p
1776 (org-element-map tree
'table-row
'identity info
'first-match
)
1783 (ert-deftest test-org-export
/get-next-element
()
1784 "Test `org-export-get-next-element' specifications."
1788 (org-test-with-parsed-data "* Headline\n*a* b"
1789 (org-export-get-next-element
1790 (org-element-map tree
'bold
'identity info t
) info
))))
1791 ;; Return nil when no previous element.
1793 (org-test-with-parsed-data "* Headline\na *b*"
1794 (org-export-get-next-element
1795 (org-element-map tree
'bold
'identity info t
) info
)))
1796 ;; Non-exportable elements are ignored.
1798 (let ((org-export-with-timestamps nil
))
1799 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
1800 (org-export-get-next-element
1801 (org-element-map tree
'entity
'identity info t
) info
)))))
1803 (ert-deftest test-org-export
/get-previous-element
()
1804 "Test `org-export-get-previous-element' specifications."
1808 (org-test-with-parsed-data "* Headline\na *b*"
1809 (org-export-get-previous-element
1810 (org-element-map tree
'bold
'identity info t
) info
))))
1811 ;; Return nil when no previous element.
1813 (org-test-with-parsed-data "* Headline\n*a* b"
1814 (org-export-get-previous-element
1815 (org-element-map tree
'bold
'identity info t
) info
)))
1816 ;; Non-exportable elements are ignored.
1818 (let ((org-export-with-timestamps nil
))
1819 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
1820 (org-export-get-previous-element
1821 (org-element-map tree
'entity
'identity info t
) info
)))))
1824 (provide 'test-org-export
)
1825 ;;; test-org-export.el end here