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.
371 (org-test-with-temp-text "
373 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
378 #+BEGIN_SRC emacs-lisp
381 (org-test-with-backend test
383 (should (equal (org-export-as 'test
'subtree
) ": 3\n")))))
385 (ert-deftest test-org-export
/expand-include
()
386 "Test file inclusion in an Org buffer."
387 ;; Full insertion with recursive inclusion.
388 (org-test-with-temp-text
389 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir
)
390 (org-export-expand-include-keyword)
391 (should (equal (buffer-string)
392 "Small Org file with an include keyword.
394 #+BEGIN_SRC emacs-lisp :exports results\n(+ 2 1)\n#+END_SRC
400 ;; Localized insertion.
401 (org-test-with-temp-text
402 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
404 (org-export-expand-include-keyword)
405 (should (equal (buffer-string)
406 "Small Org file with an include keyword.\n")))
407 ;; Insertion with constraints on headlines level.
408 (org-test-with-temp-text
410 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\""
412 (org-export-expand-include-keyword)
413 (should (equal (buffer-string) "* Top heading\n** Heading\nbody\n")))
414 ;; Inclusion within an example block.
415 (org-test-with-temp-text
416 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" example"
418 (org-export-expand-include-keyword)
422 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n")))
423 ;; Inclusion within a src-block.
424 (org-test-with-temp-text
426 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" src emacs-lisp"
428 (org-export-expand-include-keyword)
429 (should (equal (buffer-string)
430 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"))))
432 (ert-deftest test-org-export
/expand-macro
()
433 "Test macro expansion in an Org buffer."
434 ;; Standard macro expansion.
436 (equal "#+MACRO: macro1 value\nvalue"
437 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
439 (org-export-expand-macro info
) (buffer-string)))))
440 ;; Export specific macros.
442 (equal "me 2012-03-29 me@here Title"
443 (org-test-with-temp-text
449 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
450 (let ((info (org-export-get-environment)))
451 (org-export-expand-macro info
)
452 (goto-char (point-max))
453 (buffer-substring (line-beginning-position)
454 (line-end-position))))))
455 ;; Expand macros with templates in included files.
458 (org-test-with-temp-text
459 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
460 {{{included-macro}}}" org-test-dir
)
462 (org-export-expand-include-keyword)
463 (org-export-expand-macro info
)
464 (goto-char (point-max))
465 (buffer-substring (line-beginning-position)
466 (line-end-position)))))))
468 (ert-deftest test-org-export
/user-ignore-list
()
469 "Test if `:ignore-list' accepts user input."
470 (org-test-with-backend test
471 (flet ((skip-note-head
473 ;; Ignore headlines with the word "note" in their title.
477 (when (string-match "\\<note\\>"
478 (org-element-property :raw-value headline
))
479 (org-export-ignore-element headline info
)))
482 ;; Install function in parse tree filters.
483 (let ((org-export-filter-parse-tree-functions '(skip-note-head)))
484 (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
485 (should (equal (org-export-as 'test
) "* Head1\n")))))))
487 (ert-deftest test-org-export
/before-parsing-hook
()
488 "Test `org-export-before-parsing-hook'."
489 (org-test-with-backend test
490 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
491 (let ((org-export-before-parsing-hook
495 (delete-region (point) (progn (forward-line) (point)))))))))
496 (should (equal (org-export-as 'test
) "Body 1\nBody 2\n"))))))
500 ;;; Affiliated Keywords
502 (ert-deftest test-org-export
/read-attribute
()
503 "Test `org-export-read-attribute' specifications."
507 (org-export-read-attribute
509 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
510 (org-element-at-point)))
512 ;; Return nil on empty attribute.
514 (org-export-read-attribute
516 (org-test-with-temp-text "Paragraph" (org-element-at-point)))))
518 (ert-deftest test-org-export
/get-caption
()
519 "Test `org-export-get-caption' specifications."
520 ;; Without optional argument, return long caption
524 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
525 (org-export-get-caption (org-element-at-point)))))
526 ;; With optional argument, return short caption.
530 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
531 (org-export-get-caption (org-element-at-point) t
))))
532 ;; Multiple lines are separated by white spaces.
536 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
537 (org-export-get-caption (org-element-at-point))))))
543 (ert-deftest test-org-export
/export-snippet
()
544 "Test export snippets transcoding."
545 (org-test-with-temp-text "@@test:A@@@@t:B@@"
546 (org-test-with-backend test
547 (let ((org-test-translate-alist
548 (cons (cons 'export-snippet
549 (lambda (snippet contents info
)
550 (when (eq (org-export-snippet-backend snippet
) 'test
)
551 (org-element-property :value snippet
))))
552 org-test-translate-alist
)))
553 (let ((org-export-snippet-translation-alist nil
))
554 (should (equal (org-export-as 'test
) "A\n")))
555 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
556 (should (equal (org-export-as 'test
) "AB\n")))))))
562 (ert-deftest test-org-export
/footnotes
()
563 "Test footnotes specifications."
564 (let ((org-footnote-section nil
)
565 (org-export-with-footnotes t
))
566 ;; 1. Read every type of footnote.
569 '((1 .
"A\n") (2 .
"B") (3 .
"C") (4 .
"D"))
570 (org-test-with-parsed-data
571 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
573 tree
'footnote-reference
575 (let ((def (org-export-get-footnote-definition ref info
)))
576 (cons (org-export-get-footnote-number ref info
)
577 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
578 (car (org-element-contents
579 (car (org-element-contents def
))))))))
581 ;; 2. Test nested footnotes order.
582 (org-test-with-parsed-data
583 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
586 '((1 .
"fn:1") (2 .
"fn:2") (3 .
"fn:3") (4))
588 tree
'footnote-reference
590 (when (org-export-footnote-first-reference-p ref info
)
591 (cons (org-export-get-footnote-number ref info
)
592 (org-element-property :label ref
))))
594 ;; 3. Test nested footnote in invisible definitions.
595 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
597 (narrow-to-region (point) (point-at-eol))
598 (let* ((tree (org-element-parse-buffer))
599 (info (org-combine-plists
601 (org-export-collect-tree-properties
602 tree
(org-export-get-environment)))))
603 ;; Both footnotes should be seen.
605 (= (length (org-export-collect-footnote-definitions tree info
)) 2))))
606 ;; 4. Test footnotes definitions collection.
607 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
609 \[fn:2] B [fn:3] [fn::D].
612 (should (= (length (org-export-collect-footnote-definitions tree info
))
614 ;; 5. Test export of footnotes defined outside parsing scope.
615 (org-test-with-temp-text "[fn:1] Out of scope
618 (org-test-with-backend test
619 (let ((org-test-translate-alist
620 (cons (cons 'footnote-reference
621 (lambda (fn contents info
)
622 (org-element-interpret-data
623 (org-export-get-footnote-definition fn info
))))
624 org-test-translate-alist
)))
626 (should (equal "ParagraphOut of scope\n"
627 (org-export-as 'test
'subtree
))))))))
631 ;;; Headlines and Inlinetasks
633 (ert-deftest test-org-export
/get-relative-level
()
634 "Test `org-export-get-relative-level' specifications."
638 (let ((org-odd-levels-only nil
))
639 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
642 (lambda (h) (org-export-get-relative-level h info
))
647 (let ((org-odd-levels-only nil
))
648 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
651 (lambda (h) (org-export-get-relative-level h info
))
654 (ert-deftest test-org-export
/low-level-p
()
655 "Test `org-export-low-level-p' specifications."
659 (let ((org-odd-levels-only nil
))
660 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
663 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
664 (plist-put info
:headline-levels
1)))))))
666 (ert-deftest test-org-export
/get-headline-number
()
667 "Test `org-export-get-headline-number' specifications."
672 (let ((org-odd-levels-only nil
))
673 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
676 (lambda (h) (org-export-get-headline-number h info
))
678 ;; Missing levels are replaced with 0.
682 (let ((org-odd-levels-only nil
))
683 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
686 (lambda (h) (org-export-get-headline-number h info
))
689 (ert-deftest test-org-export
/numbered-headline-p
()
690 "Test `org-export-numbered-headline-p' specifications."
691 ;; If `:section-numbers' is nil, never number headlines.
693 (org-test-with-parsed-data "* Headline"
696 (lambda (h) (org-export-numbered-headline-p h info
))
697 (plist-put info
:section-numbers nil
))))
698 ;; If `:section-numbers' is a number, only number headlines with
699 ;; a level greater that it.
703 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
706 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
707 (plist-put info
:section-numbers
1)))))
708 ;; Otherwise, headlines are always numbered.
710 (org-test-with-parsed-data "* Headline"
713 (lambda (h) (org-export-numbered-headline-p h info
))
714 (plist-put info
:section-numbers t
)))))
716 (ert-deftest test-org-export
/number-to-roman
()
717 "Test `org-export-number-to-roman' specifications."
718 ;; If number is negative, return it as a string.
719 (should (equal (org-export-number-to-roman -
1) "-1"))
720 ;; Otherwise, return it as a roman number.
721 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
723 (ert-deftest test-org-export
/get-tags
()
724 "Test `org-export-get-tags' specifications."
725 (let ((org-export-exclude-tags '("noexport"))
726 (org-export-select-tags '("export")))
727 ;; Standard test: tags which are not a select tag, an exclude tag,
728 ;; or specified as optional argument shouldn't be ignored.
730 (org-test-with-parsed-data "* Headline :tag:"
731 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
733 ;; Exclude tags are removed.
735 (org-test-with-parsed-data "* Headline :noexport:"
736 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
738 ;; Select tags are removed.
740 (org-test-with-parsed-data "* Headline :export:"
741 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
746 (org-test-with-parsed-data "* Headline :tag:export:"
747 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
749 ;; Tags provided in the optional argument are also ignored.
751 (org-test-with-parsed-data "* Headline :ignore:"
752 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
754 ;; Allow tag inheritance.
758 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
761 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))))
763 (ert-deftest test-org-export
/get-node-property
()
764 "Test`org-export-get-node-property' specifications."
768 (org-test-with-parsed-data "* Headline
772 (org-export-get-node-property
773 :prop
(org-element-map tree
'headline
'identity nil t
)))))
777 (org-test-with-parsed-data "* Parent
783 (org-export-get-node-property
784 :prop
(org-element-map tree
'paragraph
'identity nil t
) t
))))
785 ;; Cannot return a value before the first headline.
787 (org-test-with-parsed-data "Paragraph
792 (org-export-get-node-property
793 :prop
(org-element-map tree
'paragraph
'identity nil t
)))))
795 (ert-deftest test-org-export
/first-sibling-p
()
796 "Test `org-export-first-sibling-p' specifications."
801 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
804 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
806 ;; Ignore headlines not exported.
810 (let ((org-export-exclude-tags '("ignore")))
811 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
814 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
817 (ert-deftest test-org-export
/last-sibling-p
()
818 "Test `org-export-last-sibling-p' specifications."
823 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
826 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
828 ;; Ignore headlines not exported.
832 (let ((org-export-exclude-tags '("ignore")))
833 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
836 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
843 (ert-deftest test-org-export
/get-coderef-format
()
844 "Test `org-export-get-coderef-format' specifications."
845 ;; A link without description returns "%s"
846 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
848 ;; Return "%s" when path is matched within description.
849 (should (equal (org-export-get-coderef-format "path" "desc (path)")
851 ;; Otherwise return description.
852 (should (equal (org-export-get-coderef-format "path" "desc")
855 (ert-deftest test-org-export
/inline-image-p
()
856 "Test `org-export-inline-image-p' specifications."
858 (org-export-inline-image-p
859 (org-test-with-temp-text "[[#id]]"
861 (org-element-parse-buffer) 'link
'identity nil t
))
862 '(("custom-id" .
"id")))))
864 (ert-deftest test-org-export
/fuzzy-link
()
865 "Test fuzzy links specifications."
866 ;; 1. Links to invisible (keyword) targets should be ignored.
867 (org-test-with-parsed-data
868 "Paragraph.\n#+TARGET: Test\n[[Test]]"
873 (org-export-get-ordinal
874 (org-export-resolve-fuzzy-link link info
) info
)) info
)))
875 ;; 2. Link to an headline should return headline's number.
876 (org-test-with-parsed-data
877 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
879 ;; Note: Headline's number is in fact a list of numbers.
884 (org-export-get-ordinal
885 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
886 ;; 3. Link to a target in an item should return item's number.
887 (org-test-with-parsed-data
888 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
890 ;; Note: Item's number is in fact a list of numbers.
895 (org-export-get-ordinal
896 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
897 ;; 4. Link to a target in a footnote should return footnote's
899 (org-test-with-parsed-data "
900 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
906 (org-export-get-ordinal
907 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
908 ;; 5. Link to a named element should return sequence number of that
910 (org-test-with-parsed-data
911 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
917 (org-export-get-ordinal
918 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
919 ;; 6. Link to a target not within an item, a table, a footnote
920 ;; reference or definition should return section number.
921 (org-test-with-parsed-data
922 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
928 (org-export-get-ordinal
929 (org-export-resolve-fuzzy-link link info
) info
)) info t
)))))
931 (ert-deftest test-org-export
/resolve-coderef
()
932 "Test `org-export-resolve-coderef' specifications."
933 (let ((org-coderef-label-format "(ref:%s)"))
934 ;; 1. A link to a "-n -k -r" block returns line number.
935 (org-test-with-parsed-data
936 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
937 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
938 (org-test-with-parsed-data
939 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
940 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
941 ;; 2. A link to a "-n -r" block returns line number.
942 (org-test-with-parsed-data
943 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
944 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
945 (org-test-with-parsed-data
946 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
947 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
948 ;; 3. A link to a "-n" block returns coderef.
949 (org-test-with-parsed-data
950 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
951 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
952 (org-test-with-parsed-data
953 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
954 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
955 ;; 4. A link to a "-r" block returns line number.
956 (org-test-with-parsed-data
957 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
958 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
959 (org-test-with-parsed-data
960 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
961 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
962 ;; 5. A link to a block without a switch returns coderef.
963 (org-test-with-parsed-data
964 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
965 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
966 (org-test-with-parsed-data
967 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
968 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
969 ;; 6. Correctly handle continued line numbers. A "+n" switch
970 ;; should resume numbering from previous block with numbered
971 ;; lines, ignoring blocks not numbering lines in the process.
972 ;; A "-n" switch resets count.
973 (org-test-with-parsed-data "
978 #+BEGIN_SRC emacs-lisp
982 #+BEGIN_SRC emacs-lisp +n -r
983 \(+ 1 1) (ref:addition)
986 #+BEGIN_EXAMPLE -n -r
987 Another text. (ref:text)
989 (should (= (org-export-resolve-coderef "addition" info
) 2))
990 (should (= (org-export-resolve-coderef "text" info
) 1)))
991 ;; 7. Recognize coderef with user-specified syntax.
992 (org-test-with-parsed-data
993 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
994 (should (equal (org-export-resolve-coderef "text" info
) "text")))))
996 (ert-deftest test-org-export
/resolve-fuzzy-link
()
997 "Test `org-export-resolve-fuzzy-link' specifications."
998 ;; 1. Match target objects.
999 (org-test-with-parsed-data "<<target>> [[target]]"
1001 (org-export-resolve-fuzzy-link
1002 (org-element-map tree
'link
'identity info t
) info
)))
1003 ;; 2. Match target elements.
1004 (org-test-with-parsed-data "#+TARGET: target\n[[target]]"
1006 (org-export-resolve-fuzzy-link
1007 (org-element-map tree
'link
'identity info t
) info
)))
1008 ;; 3. Match named elements.
1009 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
1011 (org-export-resolve-fuzzy-link
1012 (org-element-map tree
'link
'identity info t
) info
)))
1013 ;; 4. Match exact headline's name.
1014 (org-test-with-parsed-data "* My headline\n[[My headline]]"
1016 (org-export-resolve-fuzzy-link
1017 (org-element-map tree
'link
'identity info t
) info
)))
1018 ;; 5. Targets objects have priority over named elements and headline
1020 (org-test-with-parsed-data
1021 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
1025 (org-export-resolve-fuzzy-link
1026 (org-element-map tree
'link
'identity info t
) info
)))))
1027 ;; 6. Named elements have priority over headline titles.
1028 (org-test-with-parsed-data
1029 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
1033 (org-export-resolve-fuzzy-link
1034 (org-element-map tree
'link
'identity info t
) info
)))))
1035 ;; 7. If link's path starts with a "*", only match headline titles,
1037 (org-test-with-parsed-data
1038 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
1042 (org-export-resolve-fuzzy-link
1043 (org-element-map tree
'link
'identity info t
) info
)))))
1044 ;; 8. Return nil if no match.
1045 (org-test-with-parsed-data "[[target]]"
1047 (org-export-resolve-fuzzy-link
1048 (org-element-map tree
'link
'identity info t
) info
))))
1050 (ert-deftest test-org-export
/resolve-id-link
()
1051 "Test `org-export-resolve-id-link' specifications."
1052 ;; 1. Regular test for custom-id link.
1053 (org-test-with-parsed-data "* Headline1
1060 (org-export-resolve-id-link
1061 (org-element-map tree
'link
'identity info t
) info
)))
1062 ;; 2. Failing test for custom-id link.
1063 (org-test-with-parsed-data "* Headline1
1070 (org-export-resolve-id-link
1071 (org-element-map tree
'link
'identity info t
) info
)))
1072 ;; 3. Test for internal id target.
1073 (org-test-with-parsed-data "* Headline1
1080 (org-export-resolve-id-link
1081 (org-element-map tree
'link
'identity info t
) info
)))
1082 ;; 4. Test for external id target.
1083 (org-test-with-parsed-data "[[id:aaaa]]"
1085 (org-export-resolve-id-link
1086 (org-element-map tree
'link
'identity info t
)
1087 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file"))))))))
1089 (ert-deftest test-org-export
/resolve-radio-link
()
1090 "Test `org-export-resolve-radio-link' specifications."
1092 (org-test-with-temp-text "<<<radio>>> radio"
1093 (org-update-radio-target-regexp)
1095 (let* ((tree (org-element-parse-buffer))
1096 (info `(:parse-tree
,tree
)))
1097 (org-export-resolve-radio-link
1098 (org-element-map tree
'link
'identity info t
)
1100 ;; Radio target with objects.
1101 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
1102 (org-update-radio-target-regexp)
1104 (let* ((tree (org-element-parse-buffer))
1105 (info `(:parse-tree
,tree
)))
1106 (org-export-resolve-radio-link
1107 (org-element-map tree
'link
'identity info t
)
1112 ;;; Src-block and example-block
1114 (ert-deftest test-org-export
/unravel-code
()
1115 "Test `org-export-unravel-code' function."
1116 (let ((org-coderef-label-format "(ref:%s)"))
1117 ;; 1. Code without reference.
1118 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
1119 (should (equal (org-export-unravel-code (org-element-at-point))
1121 ;; 2. Code with reference.
1122 (org-test-with-temp-text
1123 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
1124 (should (equal (org-export-unravel-code (org-element-at-point))
1125 '("(+ 1 1)\n" (1 .
"test")))))
1126 ;; 3. Code with user-defined reference.
1127 (org-test-with-temp-text
1128 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
1129 (should (equal (org-export-unravel-code (org-element-at-point))
1130 '("(+ 1 1)\n" (1 .
"test")))))
1131 ;; 4. Code references keys are relative to the current block.
1132 (org-test-with-temp-text "
1141 (should (equal (org-export-unravel-code (org-element-at-point))
1142 '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one")))))))
1148 (ert-deftest test-org-export
/special-column
()
1149 "Test if the table's special column is properly recognized."
1150 ;; 1. First column is special if it contains only a special marking
1151 ;; characters or empty cells.
1152 (org-test-with-temp-text "
1156 (org-export-table-has-special-column-p
1158 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1159 ;; 2. If the column contains anything else, it isn't special.
1160 (org-test-with-temp-text "
1164 (org-export-table-has-special-column-p
1166 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1167 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
1169 (org-test-with-temp-text "
1178 (org-export-table-has-special-column-p
1180 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1181 ;; 4. A first column with only empty cells isn't considered as
1183 (org-test-with-temp-text "
1187 (org-export-table-has-special-column-p
1189 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
1191 (ert-deftest test-org-export
/table-row-is-special-p
()
1192 "Test `org-export-table-row-is-special-p' specifications."
1193 ;; 1. A row is special if it has a special marking character in the
1195 (org-test-with-parsed-data "| ! | 1 |"
1197 (org-export-table-row-is-special-p
1198 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1199 ;; 2. A row is special when its first field is "/"
1200 (org-test-with-parsed-data "
1204 (org-export-table-row-is-special-p
1205 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1206 ;; 3. A row only containing alignment cookies is also considered as
1208 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
1210 (org-export-table-row-is-special-p
1211 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1212 ;; 4. Everything else isn't considered as special.
1213 (org-test-with-parsed-data "| \alpha | | c |"
1215 (org-export-table-row-is-special-p
1216 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1217 ;; 5. Table's rules are never considered as special rows.
1218 (org-test-with-parsed-data "|---+---|"
1220 (org-export-table-row-is-special-p
1221 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
1223 (ert-deftest test-org-export
/has-header-p
()
1224 "Test `org-export-table-has-header-p' specifications."
1225 ;; 1. With an header.
1226 (org-test-with-parsed-data "
1231 (org-export-table-has-header-p
1232 (org-element-map tree
'table
'identity info
'first-match
)
1234 ;; 2. Without an header.
1235 (org-test-with-parsed-data "
1239 (org-export-table-has-header-p
1240 (org-element-map tree
'table
'identity info
'first-match
)
1242 ;; 3. Don't get fooled with starting and ending rules.
1243 (org-test-with-parsed-data "
1249 (org-export-table-has-header-p
1250 (org-element-map tree
'table
'identity info
'first-match
)
1253 (ert-deftest test-org-export
/table-row-group
()
1254 "Test `org-export-table-row-group' specifications."
1255 ;; 1. A rule creates a new group.
1256 (org-test-with-parsed-data "
1263 (mapcar (lambda (row) (org-export-table-row-group row info
))
1264 (org-element-map tree
'table-row
'identity
)))))
1265 ;; 2. Special rows are ignored in count.
1266 (org-test-with-parsed-data "
1273 (mapcar (lambda (row) (org-export-table-row-group row info
))
1274 (org-element-map tree
'table-row
'identity
)))))
1275 ;; 3. Double rules also are ignored in count.
1276 (org-test-with-parsed-data "
1284 (mapcar (lambda (row) (org-export-table-row-group row info
))
1285 (org-element-map tree
'table-row
'identity
))))))
1287 (ert-deftest test-org-export
/table-cell-width
()
1288 "Test `org-export-table-cell-width' specifications."
1289 ;; 1. Width is primarily determined by width cookies. If no cookie
1290 ;; is found, cell's width is nil.
1291 (org-test-with-parsed-data "
1292 | / | <l> | <6> | <l7> |
1297 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1298 (org-element-map tree
'table-cell
'identity info
)))))
1299 ;; 2. The last width cookie has precedence.
1300 (org-test-with-parsed-data "
1307 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1308 (org-element-map tree
'table-cell
'identity info
)))))
1309 ;; 3. Valid width cookies must have a specific row.
1310 (org-test-with-parsed-data "| <6> | cell |"
1314 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1315 (org-element-map tree
'table-cell
'identity
))))))
1317 (ert-deftest test-org-export
/table-cell-alignment
()
1318 "Test `org-export-table-cell-alignment' specifications."
1319 (let ((org-table-number-fraction 0.5)
1320 (org-table-number-regexp "^[0-9]+$"))
1321 ;; 1. Alignment is primarily determined by alignment cookies.
1322 (org-test-with-temp-text "| <l> | <c> | <r> |"
1323 (let* ((tree (org-element-parse-buffer))
1324 (info `(:parse-tree
,tree
)))
1327 '(left center right
)
1328 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1329 (org-element-map tree
'table-cell
'identity
))))))
1330 ;; 2. The last alignment cookie has precedence.
1331 (org-test-with-parsed-data "
1337 '(right right right
)
1338 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1339 (org-element-map tree
'table-cell
'identity
)))))
1340 ;; 3. If there's no cookie, cell's contents determine alignment.
1341 ;; A column mostly made of cells containing numbers will align
1342 ;; its cells to the right.
1343 (org-test-with-parsed-data "
1349 '(right right right
)
1350 (mapcar (lambda (cell)
1351 (org-export-table-cell-alignment cell info
))
1352 (org-element-map tree
'table-cell
'identity
)))))
1353 ;; 4. Otherwise, they will be aligned to the left.
1354 (org-test-with-parsed-data "
1361 (mapcar (lambda (cell)
1362 (org-export-table-cell-alignment cell info
))
1363 (org-element-map tree
'table-cell
'identity
)))))))
1365 (ert-deftest test-org-export
/table-cell-borders
()
1366 "Test `org-export-table-cell-borders' specifications."
1367 ;; 1. Recognize various column groups indicators.
1368 (org-test-with-parsed-data "| / | < | > | <> |"
1371 '((right bottom top
) (left bottom top
) (right bottom top
)
1372 (right left bottom top
))
1373 (mapcar (lambda (cell)
1374 (org-export-table-cell-borders cell info
))
1375 (org-element-map tree
'table-cell
'identity
)))))
1376 ;; 2. Accept shortcuts to define column groups.
1377 (org-test-with-parsed-data "| / | < | < |"
1380 '((right bottom top
) (right left bottom top
) (left bottom top
))
1381 (mapcar (lambda (cell)
1382 (org-export-table-cell-borders cell info
))
1383 (org-element-map tree
'table-cell
'identity
)))))
1384 ;; 3. A valid column groups row must start with a "/".
1385 (org-test-with-parsed-data "
1389 (equal '((top) (top) (bottom) (bottom))
1390 (mapcar (lambda (cell)
1391 (org-export-table-cell-borders cell info
))
1392 (org-element-map tree
'table-cell
'identity
)))))
1393 ;; 4. Take table rules into consideration.
1394 (org-test-with-parsed-data "
1399 (equal '((below top
) (bottom above
))
1400 (mapcar (lambda (cell)
1401 (org-export-table-cell-borders cell info
))
1402 (org-element-map tree
'table-cell
'identity
)))))
1403 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
1404 ;; (resp. `bottom' and `below') borders. Any special row is
1406 (org-test-with-parsed-data "
1412 (equal '((bottom below top above
))
1414 (mapcar (lambda (cell)
1415 (org-export-table-cell-borders cell info
))
1416 (org-element-map tree
'table-cell
'identity
)))))))
1418 (ert-deftest test-org-export
/table-dimensions
()
1419 "Test `org-export-table-dimensions' specifications."
1420 ;; 1. Standard test.
1421 (org-test-with-parsed-data "
1426 (org-export-table-dimensions
1427 (org-element-map tree
'table
'identity info
'first-match
) info
))))
1428 ;; 2. Ignore horizontal rules and special columns.
1429 (org-test-with-parsed-data "
1436 (org-export-table-dimensions
1437 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
1439 (ert-deftest test-org-export
/table-cell-address
()
1440 "Test `org-export-table-cell-address' specifications."
1441 ;; 1. Standard test: index is 0-based.
1442 (org-test-with-parsed-data "| a | b |"
1444 (equal '((0 .
0) (0 .
1))
1447 (lambda (cell) (org-export-table-cell-address cell info
))
1449 ;; 2. Special column isn't counted, nor are special rows.
1450 (org-test-with-parsed-data "
1455 (org-export-table-cell-address
1456 (car (last (org-element-map tree
'table-cell
'identity info
)))
1458 ;; 3. Tables rules do not count either.
1459 (org-test-with-parsed-data "
1467 (org-export-table-cell-address
1468 (car (last (org-element-map tree
'table-cell
'identity info
)))
1470 ;; 4. Return nil for special cells.
1471 (org-test-with-parsed-data "| / | a |"
1473 (org-export-table-cell-address
1474 (org-element-map tree
'table-cell
'identity nil
'first-match
)
1477 (ert-deftest test-org-export
/get-table-cell-at
()
1478 "Test `org-export-get-table-cell-at' specifications."
1479 ;; 1. Address ignores special columns, special rows and rules.
1480 (org-test-with-parsed-data "
1487 (org-element-contents
1488 (org-export-get-table-cell-at
1490 (org-element-map tree
'table
'identity info
'first-match
)
1492 ;; 2. Return value for a non-existent address is nil.
1493 (org-test-with-parsed-data "| a |"
1495 (org-export-get-table-cell-at
1497 (org-element-map tree
'table
'identity info
'first-match
)
1499 (org-test-with-parsed-data "| / |"
1501 (org-export-get-table-cell-at
1503 (org-element-map tree
'table
'identity info
'first-match
)
1506 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
1507 "Test `org-export-table-cell-starts-colgroup-p' specifications."
1508 ;; 1. A cell at a beginning of a row always starts a column group.
1509 (org-test-with-parsed-data "| a |"
1511 (org-export-table-cell-starts-colgroup-p
1512 (org-element-map tree
'table-cell
'identity info
'first-match
)
1514 ;; 2. Special column should be ignored when determining the
1515 ;; beginning of the row.
1516 (org-test-with-parsed-data "
1520 (org-export-table-cell-starts-colgroup-p
1521 (org-element-map tree
'table-cell
'identity info
'first-match
)
1523 ;; 2. Explicit column groups.
1524 (org-test-with-parsed-data "
1533 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
1536 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
1537 "Test `org-export-table-cell-ends-colgroup-p' specifications."
1538 ;; 1. A cell at the end of a row always ends a column group.
1539 (org-test-with-parsed-data "| a |"
1541 (org-export-table-cell-ends-colgroup-p
1542 (org-element-map tree
'table-cell
'identity info
'first-match
)
1544 ;; 2. Special column should be ignored when determining the
1545 ;; beginning of the row.
1546 (org-test-with-parsed-data "
1550 (org-export-table-cell-ends-colgroup-p
1551 (org-element-map tree
'table-cell
'identity info
'first-match
)
1553 ;; 3. Explicit column groups.
1554 (org-test-with-parsed-data "
1563 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
1566 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
1567 "Test `org-export-table-row-starts-rowgroup-p' specifications."
1568 ;; 1. A row at the beginning of a table always starts a row group.
1569 ;; So does a row following a table rule.
1570 (org-test-with-parsed-data "
1580 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
1582 ;; 2. Special rows should be ignored when determining the beginning
1584 (org-test-with-parsed-data "
1596 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
1599 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
1600 "Test `org-export-table-row-ends-rowgroup-p' specifications."
1601 ;; 1. A row at the end of a table always ends a row group. So does
1602 ;; a row preceding a table rule.
1603 (org-test-with-parsed-data "
1613 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
1615 ;; 2. Special rows should be ignored when determining the beginning
1617 (org-test-with-parsed-data "
1629 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
1632 (ert-deftest test-org-export
/table-row-starts-header-p
()
1633 "Test `org-export-table-row-starts-header-p' specifications."
1634 ;; 1. Only the row starting the first row group starts the table
1636 (org-test-with-parsed-data "
1647 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
1649 ;; 2. A row cannot start an header if there's no header in the
1651 (org-test-with-parsed-data "
1655 (org-export-table-row-starts-header-p
1656 (org-element-map tree
'table-row
'identity info
'first-match
)
1659 (ert-deftest test-org-export
/table-row-ends-header-p
()
1660 "Test `org-export-table-row-ends-header-p' specifications."
1661 ;; 1. Only the row starting the first row group starts the table
1663 (org-test-with-parsed-data "
1674 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
1676 ;; 2. A row cannot start an header if there's no header in the
1678 (org-test-with-parsed-data "
1682 (org-export-table-row-ends-header-p
1683 (org-element-map tree
'table-row
'identity info
'first-match
)
1690 (ert-deftest test-org-export
/get-next-element
()
1691 "Test `org-export-get-next-element' specifications."
1695 (org-test-with-parsed-data "* Headline\n*a* b"
1696 (org-export-get-next-element
1697 (org-element-map tree
'bold
'identity info t
) info
))))
1698 ;; Return nil when no previous element.
1700 (org-test-with-parsed-data "* Headline\na *b*"
1701 (org-export-get-next-element
1702 (org-element-map tree
'bold
'identity info t
) info
)))
1703 ;; Non-exportable elements are ignored.
1705 (let ((org-export-with-timestamps nil
))
1706 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
1707 (org-export-get-next-element
1708 (org-element-map tree
'entity
'identity info t
) info
)))))
1710 (ert-deftest test-org-export
/get-previous-element
()
1711 "Test `org-export-get-previous-element' specifications."
1715 (org-test-with-parsed-data "* Headline\na *b*"
1716 (org-export-get-previous-element
1717 (org-element-map tree
'bold
'identity info t
) info
))))
1718 ;; Return nil when no previous element.
1720 (org-test-with-parsed-data "* Headline\n*a* b"
1721 (org-export-get-previous-element
1722 (org-element-map tree
'bold
'identity info t
) info
)))
1723 ;; Non-exportable elements are ignored.
1725 (let ((org-export-with-timestamps nil
))
1726 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
1727 (org-export-get-previous-element
1728 (org-element-map tree
'entity
'identity info t
) info
)))))
1731 (provide 'test-org-export
)
1732 ;;; test-org-export.el end here