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 ;; Full insertion with recursive inclusion.
390 (org-test-with-temp-text
391 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir
)
392 (org-export-expand-include-keyword)
393 (should (equal (buffer-string)
394 "Small Org file with an include keyword.
396 #+BEGIN_SRC emacs-lisp :exports results\n(+ 2 1)\n#+END_SRC
402 ;; Localized insertion.
403 (org-test-with-temp-text
404 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
406 (org-export-expand-include-keyword)
407 (should (equal (buffer-string)
408 "Small Org file with an include keyword.\n")))
409 ;; Insertion with constraints on headlines level.
410 (org-test-with-temp-text
412 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\""
414 (org-export-expand-include-keyword)
415 (should (equal (buffer-string) "* Top heading\n** Heading\nbody\n")))
416 ;; Inclusion within an example block.
417 (org-test-with-temp-text
418 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" example"
420 (org-export-expand-include-keyword)
424 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n")))
425 ;; Inclusion within a src-block.
426 (org-test-with-temp-text
428 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" src emacs-lisp"
430 (org-export-expand-include-keyword)
431 (should (equal (buffer-string)
432 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"))))
434 (ert-deftest test-org-export
/expand-macro
()
435 "Test macro expansion in an Org buffer."
436 ;; Standard macro expansion.
438 (equal "#+MACRO: macro1 value\nvalue"
439 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
441 (org-export-expand-macro info
) (buffer-string)))))
442 ;; Export specific macros.
444 (equal "me 2012-03-29 me@here Title"
445 (org-test-with-temp-text
451 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
452 (let ((info (org-export-get-environment)))
453 (org-export-expand-macro info
)
454 (goto-char (point-max))
455 (buffer-substring (line-beginning-position)
456 (line-end-position))))))
457 ;; Expand macros with templates in included files.
460 (org-test-with-temp-text
461 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
462 {{{included-macro}}}" org-test-dir
)
464 (org-export-expand-include-keyword)
465 (org-export-expand-macro info
)
466 (goto-char (point-max))
467 (buffer-substring (line-beginning-position)
468 (line-end-position)))))))
470 (ert-deftest test-org-export
/user-ignore-list
()
471 "Test if `:ignore-list' accepts user input."
472 (org-test-with-backend test
473 (flet ((skip-note-head
475 ;; Ignore headlines with the word "note" in their title.
479 (when (string-match "\\<note\\>"
480 (org-element-property :raw-value headline
))
481 (org-export-ignore-element headline info
)))
484 ;; Install function in parse tree filters.
485 (let ((org-export-filter-parse-tree-functions '(skip-note-head)))
486 (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
487 (should (equal (org-export-as 'test
) "* Head1\n")))))))
489 (ert-deftest test-org-export
/before-parsing-hook
()
490 "Test `org-export-before-parsing-hook'."
491 (org-test-with-backend test
492 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
493 (let ((org-export-before-parsing-hook
497 (delete-region (point) (progn (forward-line) (point)))))))))
498 (should (equal (org-export-as 'test
) "Body 1\nBody 2\n"))))))
502 ;;; Affiliated Keywords
504 (ert-deftest test-org-export
/read-attribute
()
505 "Test `org-export-read-attribute' specifications."
509 (org-export-read-attribute
511 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
512 (org-element-at-point)))
514 ;; Return nil on empty attribute.
516 (org-export-read-attribute
518 (org-test-with-temp-text "Paragraph" (org-element-at-point)))))
520 (ert-deftest test-org-export
/get-caption
()
521 "Test `org-export-get-caption' specifications."
522 ;; Without optional argument, return long caption
526 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
527 (org-export-get-caption (org-element-at-point)))))
528 ;; With optional argument, return short caption.
532 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
533 (org-export-get-caption (org-element-at-point) t
))))
534 ;; Multiple lines are separated by white spaces.
538 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
539 (org-export-get-caption (org-element-at-point))))))
545 (ert-deftest test-org-export
/export-snippet
()
546 "Test export snippets transcoding."
547 (org-test-with-temp-text "@@test:A@@@@t:B@@"
548 (org-test-with-backend test
549 (let ((org-test-translate-alist
550 (cons (cons 'export-snippet
551 (lambda (snippet contents info
)
552 (when (eq (org-export-snippet-backend snippet
) 'test
)
553 (org-element-property :value snippet
))))
554 org-test-translate-alist
)))
555 (let ((org-export-snippet-translation-alist nil
))
556 (should (equal (org-export-as 'test
) "A\n")))
557 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
558 (should (equal (org-export-as 'test
) "AB\n")))))))
564 (ert-deftest test-org-export
/footnotes
()
565 "Test footnotes specifications."
566 (let ((org-footnote-section nil
)
567 (org-export-with-footnotes t
))
568 ;; 1. Read every type of footnote.
571 '((1 .
"A\n") (2 .
"B") (3 .
"C") (4 .
"D"))
572 (org-test-with-parsed-data
573 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
575 tree
'footnote-reference
577 (let ((def (org-export-get-footnote-definition ref info
)))
578 (cons (org-export-get-footnote-number ref info
)
579 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
580 (car (org-element-contents
581 (car (org-element-contents def
))))))))
583 ;; 2. Test nested footnotes order.
584 (org-test-with-parsed-data
585 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
588 '((1 .
"fn:1") (2 .
"fn:2") (3 .
"fn:3") (4))
590 tree
'footnote-reference
592 (when (org-export-footnote-first-reference-p ref info
)
593 (cons (org-export-get-footnote-number ref info
)
594 (org-element-property :label ref
))))
596 ;; 3. Test nested footnote in invisible definitions.
597 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
599 (narrow-to-region (point) (point-at-eol))
600 (let* ((tree (org-element-parse-buffer))
601 (info (org-combine-plists
603 (org-export-collect-tree-properties
604 tree
(org-export-get-environment)))))
605 ;; Both footnotes should be seen.
607 (= (length (org-export-collect-footnote-definitions tree info
)) 2))))
608 ;; 4. Test footnotes definitions collection.
609 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
611 \[fn:2] B [fn:3] [fn::D].
614 (should (= (length (org-export-collect-footnote-definitions tree info
))
616 ;; 5. Test export of footnotes defined outside parsing scope.
617 (org-test-with-temp-text "[fn:1] Out of scope
620 (org-test-with-backend test
621 (let ((org-test-translate-alist
622 (cons (cons 'footnote-reference
623 (lambda (fn contents info
)
624 (org-element-interpret-data
625 (org-export-get-footnote-definition fn info
))))
626 org-test-translate-alist
)))
628 (should (equal "ParagraphOut of scope\n"
629 (org-export-as 'test
'subtree
))))))))
633 ;;; Headlines and Inlinetasks
635 (ert-deftest test-org-export
/get-relative-level
()
636 "Test `org-export-get-relative-level' specifications."
640 (let ((org-odd-levels-only nil
))
641 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
644 (lambda (h) (org-export-get-relative-level h info
))
649 (let ((org-odd-levels-only nil
))
650 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
653 (lambda (h) (org-export-get-relative-level h info
))
656 (ert-deftest test-org-export
/low-level-p
()
657 "Test `org-export-low-level-p' specifications."
661 (let ((org-odd-levels-only nil
))
662 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
665 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
666 (plist-put info
:headline-levels
1)))))))
668 (ert-deftest test-org-export
/get-headline-number
()
669 "Test `org-export-get-headline-number' specifications."
674 (let ((org-odd-levels-only nil
))
675 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
678 (lambda (h) (org-export-get-headline-number h info
))
680 ;; Missing levels are replaced with 0.
684 (let ((org-odd-levels-only nil
))
685 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
688 (lambda (h) (org-export-get-headline-number h info
))
691 (ert-deftest test-org-export
/numbered-headline-p
()
692 "Test `org-export-numbered-headline-p' specifications."
693 ;; If `:section-numbers' is nil, never number headlines.
695 (org-test-with-parsed-data "* Headline"
698 (lambda (h) (org-export-numbered-headline-p h info
))
699 (plist-put info
:section-numbers nil
))))
700 ;; If `:section-numbers' is a number, only number headlines with
701 ;; a level greater that it.
705 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
708 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
709 (plist-put info
:section-numbers
1)))))
710 ;; Otherwise, headlines are always numbered.
712 (org-test-with-parsed-data "* Headline"
715 (lambda (h) (org-export-numbered-headline-p h info
))
716 (plist-put info
:section-numbers t
)))))
718 (ert-deftest test-org-export
/number-to-roman
()
719 "Test `org-export-number-to-roman' specifications."
720 ;; If number is negative, return it as a string.
721 (should (equal (org-export-number-to-roman -
1) "-1"))
722 ;; Otherwise, return it as a roman number.
723 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
725 (ert-deftest test-org-export
/get-tags
()
726 "Test `org-export-get-tags' specifications."
727 (let ((org-export-exclude-tags '("noexport"))
728 (org-export-select-tags '("export")))
729 ;; Standard test: tags which are not a select tag, an exclude tag,
730 ;; or specified as optional argument shouldn't be ignored.
732 (org-test-with-parsed-data "* Headline :tag:"
733 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
735 ;; Exclude tags are removed.
737 (org-test-with-parsed-data "* Headline :noexport:"
738 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
740 ;; Select tags are removed.
742 (org-test-with-parsed-data "* Headline :export:"
743 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
748 (org-test-with-parsed-data "* Headline :tag:export:"
749 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
751 ;; Tags provided in the optional argument are also ignored.
753 (org-test-with-parsed-data "* Headline :ignore:"
754 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
756 ;; Allow tag inheritance.
760 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
763 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))))
765 (ert-deftest test-org-export
/get-node-property
()
766 "Test`org-export-get-node-property' specifications."
770 (org-test-with-parsed-data "* Headline
774 (org-export-get-node-property
775 :prop
(org-element-map tree
'headline
'identity nil t
)))))
779 (org-test-with-parsed-data "* Parent
785 (org-export-get-node-property
786 :prop
(org-element-map tree
'paragraph
'identity nil t
) t
))))
787 ;; Cannot return a value before the first headline.
789 (org-test-with-parsed-data "Paragraph
794 (org-export-get-node-property
795 :prop
(org-element-map tree
'paragraph
'identity nil t
)))))
797 (ert-deftest test-org-export
/first-sibling-p
()
798 "Test `org-export-first-sibling-p' specifications."
803 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
806 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
808 ;; Ignore headlines not exported.
812 (let ((org-export-exclude-tags '("ignore")))
813 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
816 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
819 (ert-deftest test-org-export
/last-sibling-p
()
820 "Test `org-export-last-sibling-p' specifications."
825 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
828 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
830 ;; Ignore headlines not exported.
834 (let ((org-export-exclude-tags '("ignore")))
835 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
838 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
845 (ert-deftest test-org-export
/get-coderef-format
()
846 "Test `org-export-get-coderef-format' specifications."
847 ;; A link without description returns "%s"
848 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
850 ;; Return "%s" when path is matched within description.
851 (should (equal (org-export-get-coderef-format "path" "desc (path)")
853 ;; Otherwise return description.
854 (should (equal (org-export-get-coderef-format "path" "desc")
857 (ert-deftest test-org-export
/inline-image-p
()
858 "Test `org-export-inline-image-p' specifications."
860 (org-export-inline-image-p
861 (org-test-with-temp-text "[[#id]]"
863 (org-element-parse-buffer) 'link
'identity nil t
))
864 '(("custom-id" .
"id")))))
866 (ert-deftest test-org-export
/fuzzy-link
()
867 "Test fuzzy links specifications."
868 ;; 1. Links to invisible (keyword) targets should be ignored.
869 (org-test-with-parsed-data
870 "Paragraph.\n#+TARGET: Test\n[[Test]]"
875 (org-export-get-ordinal
876 (org-export-resolve-fuzzy-link link info
) info
)) info
)))
877 ;; 2. Link to an headline should return headline's number.
878 (org-test-with-parsed-data
879 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
881 ;; Note: Headline's number is in fact a list of numbers.
886 (org-export-get-ordinal
887 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
888 ;; 3. Link to a target in an item should return item's number.
889 (org-test-with-parsed-data
890 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
892 ;; Note: Item's number is in fact a list of numbers.
897 (org-export-get-ordinal
898 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
899 ;; 4. Link to a target in a footnote should return footnote's
901 (org-test-with-parsed-data "
902 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
908 (org-export-get-ordinal
909 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
910 ;; 5. Link to a named element should return sequence number of that
912 (org-test-with-parsed-data
913 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
919 (org-export-get-ordinal
920 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
921 ;; 6. Link to a target not within an item, a table, a footnote
922 ;; reference or definition should return section number.
923 (org-test-with-parsed-data
924 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
930 (org-export-get-ordinal
931 (org-export-resolve-fuzzy-link link info
) info
)) info t
)))))
933 (ert-deftest test-org-export
/resolve-coderef
()
934 "Test `org-export-resolve-coderef' specifications."
935 (let ((org-coderef-label-format "(ref:%s)"))
936 ;; 1. A link to a "-n -k -r" block returns line number.
937 (org-test-with-parsed-data
938 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
939 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
940 (org-test-with-parsed-data
941 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
942 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
943 ;; 2. A link to a "-n -r" block returns line number.
944 (org-test-with-parsed-data
945 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
946 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
947 (org-test-with-parsed-data
948 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
949 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
950 ;; 3. A link to a "-n" block returns coderef.
951 (org-test-with-parsed-data
952 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
953 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
954 (org-test-with-parsed-data
955 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
956 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
957 ;; 4. A link to a "-r" block returns line number.
958 (org-test-with-parsed-data
959 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
960 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
961 (org-test-with-parsed-data
962 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
963 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
964 ;; 5. A link to a block without a switch returns coderef.
965 (org-test-with-parsed-data
966 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
967 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
968 (org-test-with-parsed-data
969 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
970 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
971 ;; 6. Correctly handle continued line numbers. A "+n" switch
972 ;; should resume numbering from previous block with numbered
973 ;; lines, ignoring blocks not numbering lines in the process.
974 ;; A "-n" switch resets count.
975 (org-test-with-parsed-data "
980 #+BEGIN_SRC emacs-lisp
984 #+BEGIN_SRC emacs-lisp +n -r
985 \(+ 1 1) (ref:addition)
988 #+BEGIN_EXAMPLE -n -r
989 Another text. (ref:text)
991 (should (= (org-export-resolve-coderef "addition" info
) 2))
992 (should (= (org-export-resolve-coderef "text" info
) 1)))
993 ;; 7. Recognize coderef with user-specified syntax.
994 (org-test-with-parsed-data
995 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
996 (should (equal (org-export-resolve-coderef "text" info
) "text")))))
998 (ert-deftest test-org-export
/resolve-fuzzy-link
()
999 "Test `org-export-resolve-fuzzy-link' specifications."
1000 ;; 1. Match target objects.
1001 (org-test-with-parsed-data "<<target>> [[target]]"
1003 (org-export-resolve-fuzzy-link
1004 (org-element-map tree
'link
'identity info t
) info
)))
1005 ;; 2. Match target elements.
1006 (org-test-with-parsed-data "#+TARGET: target\n[[target]]"
1008 (org-export-resolve-fuzzy-link
1009 (org-element-map tree
'link
'identity info t
) info
)))
1010 ;; 3. Match named elements.
1011 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
1013 (org-export-resolve-fuzzy-link
1014 (org-element-map tree
'link
'identity info t
) info
)))
1015 ;; 4. Match exact headline's name.
1016 (org-test-with-parsed-data "* My headline\n[[My headline]]"
1018 (org-export-resolve-fuzzy-link
1019 (org-element-map tree
'link
'identity info t
) info
)))
1020 ;; 5. Targets objects have priority over named elements and headline
1022 (org-test-with-parsed-data
1023 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
1027 (org-export-resolve-fuzzy-link
1028 (org-element-map tree
'link
'identity info t
) info
)))))
1029 ;; 6. Named elements have priority over headline titles.
1030 (org-test-with-parsed-data
1031 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
1035 (org-export-resolve-fuzzy-link
1036 (org-element-map tree
'link
'identity info t
) info
)))))
1037 ;; 7. If link's path starts with a "*", only match headline titles,
1039 (org-test-with-parsed-data
1040 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
1044 (org-export-resolve-fuzzy-link
1045 (org-element-map tree
'link
'identity info t
) info
)))))
1046 ;; 8. Return nil if no match.
1047 (org-test-with-parsed-data "[[target]]"
1049 (org-export-resolve-fuzzy-link
1050 (org-element-map tree
'link
'identity info t
) info
))))
1052 (ert-deftest test-org-export
/resolve-id-link
()
1053 "Test `org-export-resolve-id-link' specifications."
1054 ;; 1. Regular test for custom-id link.
1055 (org-test-with-parsed-data "* Headline1
1062 (org-export-resolve-id-link
1063 (org-element-map tree
'link
'identity info t
) info
)))
1064 ;; 2. Failing test for custom-id link.
1065 (org-test-with-parsed-data "* Headline1
1072 (org-export-resolve-id-link
1073 (org-element-map tree
'link
'identity info t
) info
)))
1074 ;; 3. Test for internal id target.
1075 (org-test-with-parsed-data "* Headline1
1082 (org-export-resolve-id-link
1083 (org-element-map tree
'link
'identity info t
) info
)))
1084 ;; 4. Test for external id target.
1085 (org-test-with-parsed-data "[[id:aaaa]]"
1087 (org-export-resolve-id-link
1088 (org-element-map tree
'link
'identity info t
)
1089 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file"))))))))
1091 (ert-deftest test-org-export
/resolve-radio-link
()
1092 "Test `org-export-resolve-radio-link' specifications."
1094 (org-test-with-temp-text "<<<radio>>> radio"
1095 (org-update-radio-target-regexp)
1097 (let* ((tree (org-element-parse-buffer))
1098 (info `(:parse-tree
,tree
)))
1099 (org-export-resolve-radio-link
1100 (org-element-map tree
'link
'identity info t
)
1102 ;; Radio target with objects.
1103 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
1104 (org-update-radio-target-regexp)
1106 (let* ((tree (org-element-parse-buffer))
1107 (info `(:parse-tree
,tree
)))
1108 (org-export-resolve-radio-link
1109 (org-element-map tree
'link
'identity info t
)
1114 ;;; Src-block and example-block
1116 (ert-deftest test-org-export
/unravel-code
()
1117 "Test `org-export-unravel-code' function."
1118 (let ((org-coderef-label-format "(ref:%s)"))
1119 ;; 1. Code without reference.
1120 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
1121 (should (equal (org-export-unravel-code (org-element-at-point))
1123 ;; 2. Code with reference.
1124 (org-test-with-temp-text
1125 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
1126 (should (equal (org-export-unravel-code (org-element-at-point))
1127 '("(+ 1 1)\n" (1 .
"test")))))
1128 ;; 3. Code with user-defined reference.
1129 (org-test-with-temp-text
1130 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
1131 (should (equal (org-export-unravel-code (org-element-at-point))
1132 '("(+ 1 1)\n" (1 .
"test")))))
1133 ;; 4. Code references keys are relative to the current block.
1134 (org-test-with-temp-text "
1143 (should (equal (org-export-unravel-code (org-element-at-point))
1144 '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one")))))))
1150 (ert-deftest test-org-export
/activate-smart-quotes
()
1151 "Test `org-export-activate-smart-quotes' specifications."
1152 ;; Opening double quotes: standard test.
1155 '("some “paragraph")
1156 (let ((org-export-default-language "en"))
1157 (org-test-with-parsed-data "some \"paragraph"
1160 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1162 ;; Opening quotes: at the beginning of a paragraph.
1166 (let ((org-export-default-language "en"))
1167 (org-test-with-parsed-data "\"begin"
1170 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1172 ;; Opening quotes: after an object.
1176 (let ((org-export-default-language "en"))
1177 (org-test-with-parsed-data "=verb= \"begin"
1180 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1182 ;; Closing quotes: standard test.
1185 '("some” paragraph")
1186 (let ((org-export-default-language "en"))
1187 (org-test-with-parsed-data "some\" paragraph"
1190 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1192 ;; Closing quotes: at the end of a paragraph.
1196 (let ((org-export-default-language "en"))
1197 (org-test-with-parsed-data "end\""
1200 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1202 ;; Apostrophe: standard test.
1205 '("It shouldn’t fail")
1206 (let ((org-export-default-language "en"))
1207 (org-test-with-parsed-data "It shouldn't fail"
1210 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1212 ;; Apostrophe: before an object.
1216 (let ((org-export-default-language "en"))
1217 (org-test-with-parsed-data "a'=b="
1220 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1222 ;; Apostrophe: after an object.
1226 (let ((org-export-default-language "en"))
1227 (org-test-with-parsed-data "=code='s"
1230 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1237 (ert-deftest test-org-export
/special-column
()
1238 "Test if the table's special column is properly recognized."
1239 ;; 1. First column is special if it contains only a special marking
1240 ;; characters or empty cells.
1241 (org-test-with-temp-text "
1245 (org-export-table-has-special-column-p
1247 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1248 ;; 2. If the column contains anything else, it isn't special.
1249 (org-test-with-temp-text "
1253 (org-export-table-has-special-column-p
1255 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1256 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
1258 (org-test-with-temp-text "
1267 (org-export-table-has-special-column-p
1269 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1270 ;; 4. A first column with only empty cells isn't considered as
1272 (org-test-with-temp-text "
1276 (org-export-table-has-special-column-p
1278 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
1280 (ert-deftest test-org-export
/table-row-is-special-p
()
1281 "Test `org-export-table-row-is-special-p' specifications."
1282 ;; 1. A row is special if it has a special marking character in the
1284 (org-test-with-parsed-data "| ! | 1 |"
1286 (org-export-table-row-is-special-p
1287 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1288 ;; 2. A row is special when its first field is "/"
1289 (org-test-with-parsed-data "
1293 (org-export-table-row-is-special-p
1294 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1295 ;; 3. A row only containing alignment cookies is also considered as
1297 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
1299 (org-export-table-row-is-special-p
1300 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1301 ;; 4. Everything else isn't considered as special.
1302 (org-test-with-parsed-data "| \alpha | | c |"
1304 (org-export-table-row-is-special-p
1305 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1306 ;; 5. Table's rules are never considered as special rows.
1307 (org-test-with-parsed-data "|---+---|"
1309 (org-export-table-row-is-special-p
1310 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
1312 (ert-deftest test-org-export
/has-header-p
()
1313 "Test `org-export-table-has-header-p' specifications."
1314 ;; 1. With an header.
1315 (org-test-with-parsed-data "
1320 (org-export-table-has-header-p
1321 (org-element-map tree
'table
'identity info
'first-match
)
1323 ;; 2. Without an header.
1324 (org-test-with-parsed-data "
1328 (org-export-table-has-header-p
1329 (org-element-map tree
'table
'identity info
'first-match
)
1331 ;; 3. Don't get fooled with starting and ending rules.
1332 (org-test-with-parsed-data "
1338 (org-export-table-has-header-p
1339 (org-element-map tree
'table
'identity info
'first-match
)
1342 (ert-deftest test-org-export
/table-row-group
()
1343 "Test `org-export-table-row-group' specifications."
1344 ;; 1. A rule creates a new group.
1345 (org-test-with-parsed-data "
1352 (mapcar (lambda (row) (org-export-table-row-group row info
))
1353 (org-element-map tree
'table-row
'identity
)))))
1354 ;; 2. Special rows are ignored in count.
1355 (org-test-with-parsed-data "
1362 (mapcar (lambda (row) (org-export-table-row-group row info
))
1363 (org-element-map tree
'table-row
'identity
)))))
1364 ;; 3. Double rules also are ignored in count.
1365 (org-test-with-parsed-data "
1373 (mapcar (lambda (row) (org-export-table-row-group row info
))
1374 (org-element-map tree
'table-row
'identity
))))))
1376 (ert-deftest test-org-export
/table-cell-width
()
1377 "Test `org-export-table-cell-width' specifications."
1378 ;; 1. Width is primarily determined by width cookies. If no cookie
1379 ;; is found, cell's width is nil.
1380 (org-test-with-parsed-data "
1381 | / | <l> | <6> | <l7> |
1386 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1387 (org-element-map tree
'table-cell
'identity info
)))))
1388 ;; 2. The last width cookie has precedence.
1389 (org-test-with-parsed-data "
1396 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1397 (org-element-map tree
'table-cell
'identity info
)))))
1398 ;; 3. Valid width cookies must have a specific row.
1399 (org-test-with-parsed-data "| <6> | cell |"
1403 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1404 (org-element-map tree
'table-cell
'identity
))))))
1406 (ert-deftest test-org-export
/table-cell-alignment
()
1407 "Test `org-export-table-cell-alignment' specifications."
1408 (let ((org-table-number-fraction 0.5)
1409 (org-table-number-regexp "^[0-9]+$"))
1410 ;; 1. Alignment is primarily determined by alignment cookies.
1411 (org-test-with-temp-text "| <l> | <c> | <r> |"
1412 (let* ((tree (org-element-parse-buffer))
1413 (info `(:parse-tree
,tree
)))
1416 '(left center right
)
1417 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1418 (org-element-map tree
'table-cell
'identity
))))))
1419 ;; 2. The last alignment cookie has precedence.
1420 (org-test-with-parsed-data "
1426 '(right right right
)
1427 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1428 (org-element-map tree
'table-cell
'identity
)))))
1429 ;; 3. If there's no cookie, cell's contents determine alignment.
1430 ;; A column mostly made of cells containing numbers will align
1431 ;; its cells to the right.
1432 (org-test-with-parsed-data "
1438 '(right right right
)
1439 (mapcar (lambda (cell)
1440 (org-export-table-cell-alignment cell info
))
1441 (org-element-map tree
'table-cell
'identity
)))))
1442 ;; 4. Otherwise, they will be aligned to the left.
1443 (org-test-with-parsed-data "
1450 (mapcar (lambda (cell)
1451 (org-export-table-cell-alignment cell info
))
1452 (org-element-map tree
'table-cell
'identity
)))))))
1454 (ert-deftest test-org-export
/table-cell-borders
()
1455 "Test `org-export-table-cell-borders' specifications."
1456 ;; 1. Recognize various column groups indicators.
1457 (org-test-with-parsed-data "| / | < | > | <> |"
1460 '((right bottom top
) (left bottom top
) (right bottom top
)
1461 (right left bottom top
))
1462 (mapcar (lambda (cell)
1463 (org-export-table-cell-borders cell info
))
1464 (org-element-map tree
'table-cell
'identity
)))))
1465 ;; 2. Accept shortcuts to define column groups.
1466 (org-test-with-parsed-data "| / | < | < |"
1469 '((right bottom top
) (right left bottom top
) (left bottom top
))
1470 (mapcar (lambda (cell)
1471 (org-export-table-cell-borders cell info
))
1472 (org-element-map tree
'table-cell
'identity
)))))
1473 ;; 3. A valid column groups row must start with a "/".
1474 (org-test-with-parsed-data "
1478 (equal '((top) (top) (bottom) (bottom))
1479 (mapcar (lambda (cell)
1480 (org-export-table-cell-borders cell info
))
1481 (org-element-map tree
'table-cell
'identity
)))))
1482 ;; 4. Take table rules into consideration.
1483 (org-test-with-parsed-data "
1488 (equal '((below top
) (bottom above
))
1489 (mapcar (lambda (cell)
1490 (org-export-table-cell-borders cell info
))
1491 (org-element-map tree
'table-cell
'identity
)))))
1492 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
1493 ;; (resp. `bottom' and `below') borders. Any special row is
1495 (org-test-with-parsed-data "
1501 (equal '((bottom below top above
))
1503 (mapcar (lambda (cell)
1504 (org-export-table-cell-borders cell info
))
1505 (org-element-map tree
'table-cell
'identity
)))))))
1507 (ert-deftest test-org-export
/table-dimensions
()
1508 "Test `org-export-table-dimensions' specifications."
1509 ;; 1. Standard test.
1510 (org-test-with-parsed-data "
1515 (org-export-table-dimensions
1516 (org-element-map tree
'table
'identity info
'first-match
) info
))))
1517 ;; 2. Ignore horizontal rules and special columns.
1518 (org-test-with-parsed-data "
1525 (org-export-table-dimensions
1526 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
1528 (ert-deftest test-org-export
/table-cell-address
()
1529 "Test `org-export-table-cell-address' specifications."
1530 ;; 1. Standard test: index is 0-based.
1531 (org-test-with-parsed-data "| a | b |"
1533 (equal '((0 .
0) (0 .
1))
1536 (lambda (cell) (org-export-table-cell-address cell info
))
1538 ;; 2. Special column isn't counted, nor are special rows.
1539 (org-test-with-parsed-data "
1544 (org-export-table-cell-address
1545 (car (last (org-element-map tree
'table-cell
'identity info
)))
1547 ;; 3. Tables rules do not count either.
1548 (org-test-with-parsed-data "
1556 (org-export-table-cell-address
1557 (car (last (org-element-map tree
'table-cell
'identity info
)))
1559 ;; 4. Return nil for special cells.
1560 (org-test-with-parsed-data "| / | a |"
1562 (org-export-table-cell-address
1563 (org-element-map tree
'table-cell
'identity nil
'first-match
)
1566 (ert-deftest test-org-export
/get-table-cell-at
()
1567 "Test `org-export-get-table-cell-at' specifications."
1568 ;; 1. Address ignores special columns, special rows and rules.
1569 (org-test-with-parsed-data "
1576 (org-element-contents
1577 (org-export-get-table-cell-at
1579 (org-element-map tree
'table
'identity info
'first-match
)
1581 ;; 2. Return value for a non-existent address is nil.
1582 (org-test-with-parsed-data "| a |"
1584 (org-export-get-table-cell-at
1586 (org-element-map tree
'table
'identity info
'first-match
)
1588 (org-test-with-parsed-data "| / |"
1590 (org-export-get-table-cell-at
1592 (org-element-map tree
'table
'identity info
'first-match
)
1595 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
1596 "Test `org-export-table-cell-starts-colgroup-p' specifications."
1597 ;; 1. A cell at a beginning of a row always starts a column group.
1598 (org-test-with-parsed-data "| a |"
1600 (org-export-table-cell-starts-colgroup-p
1601 (org-element-map tree
'table-cell
'identity info
'first-match
)
1603 ;; 2. Special column should be ignored when determining the
1604 ;; beginning of the row.
1605 (org-test-with-parsed-data "
1609 (org-export-table-cell-starts-colgroup-p
1610 (org-element-map tree
'table-cell
'identity info
'first-match
)
1612 ;; 2. Explicit column groups.
1613 (org-test-with-parsed-data "
1622 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
1625 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
1626 "Test `org-export-table-cell-ends-colgroup-p' specifications."
1627 ;; 1. A cell at the end of a row always ends a column group.
1628 (org-test-with-parsed-data "| a |"
1630 (org-export-table-cell-ends-colgroup-p
1631 (org-element-map tree
'table-cell
'identity info
'first-match
)
1633 ;; 2. Special column should be ignored when determining the
1634 ;; beginning of the row.
1635 (org-test-with-parsed-data "
1639 (org-export-table-cell-ends-colgroup-p
1640 (org-element-map tree
'table-cell
'identity info
'first-match
)
1642 ;; 3. Explicit column groups.
1643 (org-test-with-parsed-data "
1652 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
1655 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
1656 "Test `org-export-table-row-starts-rowgroup-p' specifications."
1657 ;; 1. A row at the beginning of a table always starts a row group.
1658 ;; So does a row following a table rule.
1659 (org-test-with-parsed-data "
1669 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
1671 ;; 2. Special rows should be ignored when determining the beginning
1673 (org-test-with-parsed-data "
1685 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
1688 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
1689 "Test `org-export-table-row-ends-rowgroup-p' specifications."
1690 ;; 1. A row at the end of a table always ends a row group. So does
1691 ;; a row preceding a table rule.
1692 (org-test-with-parsed-data "
1702 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
1704 ;; 2. Special rows should be ignored when determining the beginning
1706 (org-test-with-parsed-data "
1718 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
1721 (ert-deftest test-org-export
/table-row-starts-header-p
()
1722 "Test `org-export-table-row-starts-header-p' specifications."
1723 ;; 1. Only the row starting the first row group starts the table
1725 (org-test-with-parsed-data "
1736 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
1738 ;; 2. A row cannot start an header if there's no header in the
1740 (org-test-with-parsed-data "
1744 (org-export-table-row-starts-header-p
1745 (org-element-map tree
'table-row
'identity info
'first-match
)
1748 (ert-deftest test-org-export
/table-row-ends-header-p
()
1749 "Test `org-export-table-row-ends-header-p' specifications."
1750 ;; 1. Only the row starting the first row group starts the table
1752 (org-test-with-parsed-data "
1763 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
1765 ;; 2. A row cannot start an header if there's no header in the
1767 (org-test-with-parsed-data "
1771 (org-export-table-row-ends-header-p
1772 (org-element-map tree
'table-row
'identity info
'first-match
)
1779 (ert-deftest test-org-export
/get-next-element
()
1780 "Test `org-export-get-next-element' specifications."
1784 (org-test-with-parsed-data "* Headline\n*a* b"
1785 (org-export-get-next-element
1786 (org-element-map tree
'bold
'identity info t
) info
))))
1787 ;; Return nil when no previous element.
1789 (org-test-with-parsed-data "* Headline\na *b*"
1790 (org-export-get-next-element
1791 (org-element-map tree
'bold
'identity info t
) info
)))
1792 ;; Non-exportable elements are ignored.
1794 (let ((org-export-with-timestamps nil
))
1795 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
1796 (org-export-get-next-element
1797 (org-element-map tree
'entity
'identity info t
) info
)))))
1799 (ert-deftest test-org-export
/get-previous-element
()
1800 "Test `org-export-get-previous-element' specifications."
1804 (org-test-with-parsed-data "* Headline\na *b*"
1805 (org-export-get-previous-element
1806 (org-element-map tree
'bold
'identity info t
) info
))))
1807 ;; Return nil when no previous element.
1809 (org-test-with-parsed-data "* Headline\n*a* b"
1810 (org-export-get-previous-element
1811 (org-element-map tree
'bold
'identity info t
) info
)))
1812 ;; Non-exportable elements are ignored.
1814 (let ((org-export-with-timestamps nil
))
1815 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
1816 (org-export-get-previous-element
1817 (org-element-map tree
'entity
'identity info t
) info
)))))
1820 (provide 'test-org-export
)
1821 ;;; test-org-export.el end here