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
/parse-option-keyword
()
63 "Test reading all standard #+OPTIONS: items."
66 (org-export--parse-option-keyword
67 "H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t
68 *:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t")
70 1 :preserve-breaks t
:section-numbers t
:time-stamp-file t
71 :with-archived-trees t
:with-author t
:with-creator t
:with-drawers t
72 :with-email t
:with-emphasize t
:with-entities t
:with-fixed-width t
73 :with-footnotes t
:with-priority t
:with-special-strings t
74 :with-sub-superscript t
:with-toc t
:with-tables t
:with-tags t
75 :with-tasks t
:with-timestamps t
:with-todo-keywords t
)))
76 ;; Test some special values.
79 (org-export--parse-option-keyword
80 "arch:headline creator:comment d:(\"TEST\")
81 ^:{} toc:1 tags:not-in-toc tasks:todo num:2 <:active")
84 :with-archived-trees headline
:with-creator comment
85 :with-drawers
("TEST") :with-sub-superscript
{} :with-toc
1
86 :with-tags not-in-toc
:with-tasks todo
:with-timestamps active
))))
88 (ert-deftest test-org-export
/get-inbuffer-options
()
89 "Test reading all standard export keywords."
92 (org-test-with-temp-text "#+AUTHOR: Me, Myself and I
95 #+DESCRIPTION: Testing
96 #+DESCRIPTION: with two lines
97 #+EMAIL: some@email.org
98 #+EXCLUDE_TAGS: noexport invisible
101 #+SELECT_TAGS: export
103 #+TITLE: with spaces"
104 (org-export--get-inbuffer-options))
106 ("Me, Myself and I") :creator
"Idem" :date
("Today")
107 :description
"Testing\nwith two lines" :email
"some@email.org"
108 :exclude-tags
("noexport" "invisible") :keywords
"test" :language
"en"
109 :select-tags
("export") :title
("Some title with spaces")))))
111 (ert-deftest test-org-export
/get-subtree-options
()
112 "Test setting options from headline's properties."
114 (org-test-with-temp-text "#+TITLE: Title
117 :EXPORT_TITLE: Subtree Title
121 (should (equal (plist-get (org-export-get-environment nil t
) :title
)
122 '("Subtree Title"))))
126 (org-test-with-temp-text "#+OPTIONS: H:1
134 (= 2 (plist-get (org-export-get-environment nil t
) :headline-levels
))))
136 (org-test-with-temp-text "#+DATE: today
139 :EXPORT_DATE: 29-03-2012
143 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
145 ;; Export properties are case-insensitive.
146 (org-test-with-temp-text "* Headline
148 :EXPORT_Date: 29-03-2012
151 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
154 (ert-deftest test-org-export
/handle-options
()
155 "Test if export options have an impact on output."
156 ;; Test exclude tags.
157 (org-test-with-temp-text "* Head1 :noexport:"
158 (org-test-with-backend test
160 (equal (org-export-as 'test nil nil nil
'(:exclude-tags
("noexport")))
162 ;; Test include tags.
163 (org-test-with-temp-text "
166 ** Sub-Head2.1 :export:
169 (org-test-with-backend test
172 "* Head2\n** Sub-Head2.1 :export:\n*** Sub-Head2.1.1\n"
173 (let ((org-tags-column 0))
174 (org-export-as 'test nil nil nil
'(:select-tags
("export"))))))))
175 ;; Test mixing include tags and exclude tags.
176 (org-test-with-temp-text "
178 ** Sub-Head1 :noexport:
181 ** Sub-Head1 :export:"
182 (org-test-with-backend test
185 "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
188 '(:select-tags
("export") :exclude-tags
("noexport")))))))
190 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
191 (org-test-with-temp-text "* TODO Head1"
192 (org-test-with-backend test
193 (should (equal (org-export-as 'test nil nil nil
'(:with-tasks nil
))
195 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
196 (org-test-with-temp-text "* TODO Head1"
197 (org-test-with-backend test
198 (should (equal (org-export-as 'test nil nil nil
'(:with-tasks t
))
199 "* TODO Head1\n")))))
201 (org-test-with-temp-text "* Head1 :archive:"
202 (let ((org-archive-tag "archive"))
203 (org-test-with-backend test
205 (equal (org-export-as 'test nil nil nil
'(:with-archived-trees nil
))
207 (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
208 (let ((org-archive-tag "archive"))
209 (org-test-with-backend test
212 "\\* Head1[ \t]+:archive:"
213 (org-export-as 'test nil nil nil
214 '(:with-archived-trees headline
)))))))
215 (org-test-with-temp-text "* Head1 :archive:"
216 (let ((org-archive-tag "archive"))
217 (org-test-with-backend test
220 "\\`\\* Head1[ \t]+:archive:\n\\'"
221 (org-export-as 'test nil nil nil
'(:with-archived-trees t
)))))))
223 (let ((org-drawers '("TEST")))
224 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
225 (org-test-with-backend test
226 (should (equal (org-export-as 'test nil nil nil
'(:with-drawers nil
))
228 (should (equal (org-export-as 'test nil nil nil
'(:with-drawers t
))
229 ":TEST:\ncontents\n:END:\n")))))
230 (let ((org-drawers '("FOO" "BAR")))
231 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
232 (org-test-with-backend test
234 (equal (org-export-as 'test nil nil nil
'(:with-drawers
("FOO")))
235 ":FOO:\nkeep\n:END:\n")))))
237 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
238 (org-test-with-backend test
240 (equal (org-export-as 'test nil nil nil
'(:with-timestamps t
))
241 "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>\n"))
243 (equal (org-export-as 'test nil nil nil
'(:with-timestamps nil
)) ""))
245 (equal (org-export-as 'test nil nil nil
'(:with-timestamps active
))
246 "<2012-04-29 sun. 10:45>\n"))
248 (equal (org-export-as 'test nil nil nil
'(:with-timestamps inactive
))
249 "[2012-04-29 sun. 10:45]\n"))))
251 (let ((org-clock-string "CLOCK:"))
252 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
253 (org-test-with-backend test
255 (equal (org-export-as 'test nil nil nil
'(:with-clocks t
))
256 "CLOCK: [2012-04-29 sun. 10:45]\n"))
258 (equal (org-export-as 'test nil nil nil
'(:with-clocks nil
)) "")))))
260 (let ((org-closed-string "CLOSED:"))
261 (org-test-with-temp-text "CLOSED: [2012-04-29 sun. 10:45]"
262 (org-test-with-backend test
264 (equal (org-export-as 'test nil nil nil
'(:with-plannings t
))
265 "CLOSED: [2012-04-29 sun. 10:45]\n"))
267 (equal (org-export-as 'test nil nil nil
'(:with-plannings nil
))
270 (ert-deftest test-org-export
/comment-tree
()
271 "Test if export process ignores commented trees."
272 (let ((org-comment-string "COMMENT"))
273 (org-test-with-temp-text "* COMMENT Head1"
274 (org-test-with-backend test
275 (should (equal (org-export-as 'test
) ""))))))
277 (ert-deftest test-org-export
/export-scope
()
278 "Test all export scopes."
279 (org-test-with-temp-text "
284 (org-test-with-backend test
287 (should (equal (org-export-as 'test
'subtree
) "text\n*** Head3\n"))
289 (goto-char (point-min))
292 (should (equal (org-export-as 'test nil
'visible
) "* Head1\n"))
294 (flet ((org-test-template (body info
) (format "BEGIN\n%sEND" body
)))
295 (push '(template . org-test-template
) org-test-translate-alist
)
296 (should (equal (org-export-as 'test nil nil
'body-only
)
297 "* Head1\n** Head2\ntext\n*** Head3\n"))
298 (should (equal (org-export-as 'test
)
299 "BEGIN\n* Head1\n** Head2\ntext\n*** Head3\nEND")))
301 (goto-char (point-min))
303 (transient-mark-mode 1)
304 (push-mark (point) t t
)
305 (goto-char (point-at-eol))
306 (should (equal (org-export-as 'test
) "text\n"))))
307 ;; Subtree with a code block calling another block outside.
308 (org-test-with-temp-text "
310 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
315 #+BEGIN_SRC emacs-lisp
318 (org-test-with-backend test
320 (should (equal (org-export-as 'test
'subtree
) ": 3\n")))))
322 (ert-deftest test-org-export
/expand-include
()
323 "Test file inclusion in an Org buffer."
324 ;; Full insertion with recursive inclusion.
325 (org-test-with-temp-text
326 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir
)
327 (org-export-expand-include-keyword)
328 (should (equal (buffer-string)
329 "Small Org file with an include keyword.
331 #+BEGIN_SRC emacs-lisp :exports results\n(+ 2 1)\n#+END_SRC
337 ;; Localized insertion.
338 (org-test-with-temp-text
339 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
341 (org-export-expand-include-keyword)
342 (should (equal (buffer-string)
343 "Small Org file with an include keyword.\n")))
344 ;; Insertion with constraints on headlines level.
345 (org-test-with-temp-text
347 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\""
349 (org-export-expand-include-keyword)
350 (should (equal (buffer-string) "* Top heading\n** Heading\nbody\n")))
351 ;; Inclusion within an example block.
352 (org-test-with-temp-text
353 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" example"
355 (org-export-expand-include-keyword)
359 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n")))
360 ;; Inclusion within a src-block.
361 (org-test-with-temp-text
363 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" src emacs-lisp"
365 (org-export-expand-include-keyword)
366 (should (equal (buffer-string)
367 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"))))
369 (ert-deftest test-org-export
/user-ignore-list
()
370 "Test if `:ignore-list' accepts user input."
371 (org-test-with-backend test
372 (flet ((skip-note-head
374 ;; Ignore headlines with the word "note" in their title.
378 (when (string-match "\\<note\\>"
379 (org-element-property :raw-value headline
))
380 (org-export-ignore-element headline info
)))
383 ;; Install function in parse tree filters.
384 (let ((org-export-filter-parse-tree-functions '(skip-note-head)))
385 (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
386 (should (equal (org-export-as 'test
) "* Head1\n")))))))
388 (ert-deftest test-org-export
/before-parsing-hook
()
389 "Test `org-export-before-parsing-hook'."
390 (org-test-with-backend test
391 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
392 (let ((org-export-before-parsing-hook
396 (delete-region (point) (progn (forward-line) (point)))))))))
397 (should (equal (org-export-as 'test
) "Body 1\nBody 2\n"))))))
401 ;;; Affiliated Keywords
403 (ert-deftest test-org-export
/read-attribute
()
404 "Test `org-export-read-attribute' specifications."
408 (org-export-read-attribute
410 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
411 (org-element-at-point)))
413 ;; Return nil on empty attribute.
415 (org-export-read-attribute
417 (org-test-with-temp-text "Paragraph" (org-element-at-point)))))
423 (ert-deftest test-org-export
/export-snippet
()
424 "Test export snippets transcoding."
425 (org-test-with-temp-text "@@test:A@@@@t:B@@"
426 (org-test-with-backend test
427 (let ((org-test-translate-alist
428 (cons (cons 'export-snippet
429 (lambda (snippet contents info
)
430 (when (eq (org-export-snippet-backend snippet
) 'test
)
431 (org-element-property :value snippet
))))
432 org-test-translate-alist
)))
433 (let ((org-export-snippet-translation-alist nil
))
434 (should (equal (org-export-as 'test
) "A\n")))
435 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
436 (should (equal (org-export-as 'test
) "AB\n")))))))
442 (ert-deftest test-org-export
/footnotes
()
443 "Test footnotes specifications."
444 (let ((org-footnote-section nil
)
445 (org-export-with-footnotes t
))
446 ;; 1. Read every type of footnote.
449 '((1 .
"A\n") (2 .
"B") (3 .
"C") (4 .
"D"))
450 (org-test-with-parsed-data
451 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
453 tree
'footnote-reference
455 (let ((def (org-export-get-footnote-definition ref info
)))
456 (cons (org-export-get-footnote-number ref info
)
457 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
458 (car (org-element-contents
459 (car (org-element-contents def
))))))))
461 ;; 2. Test nested footnotes order.
462 (org-test-with-parsed-data
463 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
466 '((1 .
"fn:1") (2 .
"fn:2") (3 .
"fn:3") (4))
468 tree
'footnote-reference
470 (when (org-export-footnote-first-reference-p ref info
)
471 (cons (org-export-get-footnote-number ref info
)
472 (org-element-property :label ref
))))
474 ;; 3. Test nested footnote in invisible definitions.
475 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
477 (narrow-to-region (point) (point-at-eol))
478 (let* ((tree (org-element-parse-buffer))
479 (info (org-combine-plists
481 (org-export-collect-tree-properties
482 tree
(org-export-get-environment)))))
483 ;; Both footnotes should be seen.
485 (= (length (org-export-collect-footnote-definitions tree info
)) 2))))
486 ;; 4. Test footnotes definitions collection.
487 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
489 \[fn:2] B [fn:3] [fn::D].
492 (should (= (length (org-export-collect-footnote-definitions tree info
))
494 ;; 5. Test export of footnotes defined outside parsing scope.
495 (org-test-with-temp-text "[fn:1] Out of scope
498 (org-test-with-backend test
499 (let ((org-test-translate-alist
500 (cons (cons 'footnote-reference
501 (lambda (fn contents info
)
502 (org-element-interpret-data
503 (org-export-get-footnote-definition fn info
))))
504 org-test-translate-alist
)))
506 (should (equal "ParagraphOut of scope\n"
507 (org-export-as 'test
'subtree
))))))))
511 ;;; Headlines and Inlinetasks
513 (ert-deftest test-org-export
/get-relative-level
()
514 "Test `org-export-get-relative-level' specifications."
518 (let ((org-odd-levels-only nil
))
519 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
522 (lambda (h) (org-export-get-relative-level h info
))
527 (let ((org-odd-levels-only nil
))
528 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
531 (lambda (h) (org-export-get-relative-level h info
))
534 (ert-deftest test-org-export
/low-level-p
()
535 "Test `org-export-low-level-p' specifications."
539 (let ((org-odd-levels-only nil
))
540 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
543 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
544 (plist-put info
:headline-levels
1)))))))
546 (ert-deftest test-org-export
/get-headline-number
()
547 "Test `org-export-get-headline-number' specifications."
552 (let ((org-odd-levels-only nil
))
553 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
556 (lambda (h) (org-export-get-headline-number h info
))
558 ;; Missing levels are replaced with 0.
562 (let ((org-odd-levels-only nil
))
563 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
566 (lambda (h) (org-export-get-headline-number h info
))
569 (ert-deftest test-org-export
/numbered-headline-p
()
570 "Test `org-export-numbered-headline-p' specifications."
571 ;; If `:section-numbers' is nil, never number headlines.
573 (org-test-with-parsed-data "* Headline"
576 (lambda (h) (org-export-numbered-headline-p h info
))
577 (plist-put info
:section-numbers nil
))))
578 ;; If `:section-numbers' is a number, only number headlines with
579 ;; a level greater that it.
583 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
586 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
587 (plist-put info
:section-numbers
1)))))
588 ;; Otherwise, headlines are always numbered.
590 (org-test-with-parsed-data "* Headline"
593 (lambda (h) (org-export-numbered-headline-p h info
))
594 (plist-put info
:section-numbers t
)))))
596 (ert-deftest test-org-export
/number-to-roman
()
597 "Test `org-export-number-to-roman' specifications."
598 ;; If number is negative, return it as a string.
599 (should (equal (org-export-number-to-roman -
1) "-1"))
600 ;; Otherwise, return it as a roman number.
601 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
603 (ert-deftest test-org-export
/get-tags
()
604 "Test `org-export-get-tags' specifications."
605 (let ((org-export-exclude-tags '("noexport"))
606 (org-export-select-tags '("export")))
607 ;; Standard test: tags which are not a select tag, an exclude tag,
608 ;; or specified as optional argument shouldn't be ignored.
610 (org-test-with-parsed-data "* Headline :tag:"
611 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
613 ;; Exclude tags are removed.
615 (org-test-with-parsed-data "* Headline :noexport:"
616 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
618 ;; Select tags are removed.
620 (org-test-with-parsed-data "* Headline :export:"
621 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
626 (org-test-with-parsed-data "* Headline :tag:export:"
627 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
629 ;; Tags provided in the optional argument are also ignored.
631 (org-test-with-parsed-data "* Headline :ignore:"
632 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
633 info
'("ignore"))))))
635 (ert-deftest test-org-export
/first-sibling-p
()
636 "Test `org-export-first-sibling-p' specifications."
641 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
644 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
646 ;; Ignore headlines not exported.
650 (let ((org-export-exclude-tags '("ignore")))
651 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
654 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
657 (ert-deftest test-org-export
/last-sibling-p
()
658 "Test `org-export-last-sibling-p' specifications."
663 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
666 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
668 ;; Ignore headlines not exported.
672 (let ((org-export-exclude-tags '("ignore")))
673 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
676 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
683 (ert-deftest test-org-export
/get-coderef-format
()
684 "Test `org-export-get-coderef-format' specifications."
685 ;; A link without description returns "%s"
686 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
688 ;; Return "%s" when path is matched within description.
689 (should (equal (org-export-get-coderef-format "path" "desc (path)")
691 ;; Otherwise return description.
692 (should (equal (org-export-get-coderef-format "path" "desc")
695 (ert-deftest test-org-export
/inline-image-p
()
696 "Test `org-export-inline-image-p' specifications."
698 (org-export-inline-image-p
699 (org-test-with-temp-text "[[#id]]"
701 (org-element-parse-buffer) 'link
'identity nil t
))
702 '(("custom-id" .
"id")))))
704 (ert-deftest test-org-export
/fuzzy-link
()
705 "Test fuzzy links specifications."
706 ;; 1. Links to invisible (keyword) targets should be ignored.
707 (org-test-with-parsed-data
708 "Paragraph.\n#+TARGET: Test\n[[Test]]"
713 (org-export-get-ordinal
714 (org-export-resolve-fuzzy-link link info
) info
)) info
)))
715 ;; 2. Link to an headline should return headline's number.
716 (org-test-with-parsed-data
717 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
719 ;; Note: Headline's number is in fact a list of numbers.
724 (org-export-get-ordinal
725 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
726 ;; 3. Link to a target in an item should return item's number.
727 (org-test-with-parsed-data
728 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
730 ;; Note: Item's number is in fact a list of numbers.
735 (org-export-get-ordinal
736 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
737 ;; 4. Link to a target in a footnote should return footnote's
739 (org-test-with-parsed-data "
740 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
746 (org-export-get-ordinal
747 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
748 ;; 5. Link to a named element should return sequence number of that
750 (org-test-with-parsed-data
751 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
757 (org-export-get-ordinal
758 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
759 ;; 6. Link to a target not within an item, a table, a footnote
760 ;; reference or definition should return section number.
761 (org-test-with-parsed-data
762 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
768 (org-export-get-ordinal
769 (org-export-resolve-fuzzy-link link info
) info
)) info t
)))))
771 (ert-deftest test-org-export
/resolve-coderef
()
772 "Test `org-export-resolve-coderef' specifications."
773 (let ((org-coderef-label-format "(ref:%s)"))
774 ;; 1. A link to a "-n -k -r" block returns line number.
775 (org-test-with-parsed-data
776 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
777 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
778 (org-test-with-parsed-data
779 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
780 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
781 ;; 2. A link to a "-n -r" block returns line number.
782 (org-test-with-parsed-data
783 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
784 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
785 (org-test-with-parsed-data
786 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
787 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
788 ;; 3. A link to a "-n" block returns coderef.
789 (org-test-with-parsed-data
790 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
791 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
792 (org-test-with-parsed-data
793 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
794 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
795 ;; 4. A link to a "-r" block returns line number.
796 (org-test-with-parsed-data
797 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
798 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
799 (org-test-with-parsed-data
800 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
801 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
802 ;; 5. A link to a block without a switch returns coderef.
803 (org-test-with-parsed-data
804 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
805 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
806 (org-test-with-parsed-data
807 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
808 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
809 ;; 6. Correctly handle continued line numbers. A "+n" switch
810 ;; should resume numbering from previous block with numbered
811 ;; lines, ignoring blocks not numbering lines in the process.
812 ;; A "-n" switch resets count.
813 (org-test-with-parsed-data "
818 #+BEGIN_SRC emacs-lisp
822 #+BEGIN_SRC emacs-lisp +n -r
823 \(+ 1 1) (ref:addition)
826 #+BEGIN_EXAMPLE -n -r
827 Another text. (ref:text)
829 (should (= (org-export-resolve-coderef "addition" info
) 2))
830 (should (= (org-export-resolve-coderef "text" info
) 1)))
831 ;; 7. Recognize coderef with user-specified syntax.
832 (org-test-with-parsed-data
833 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
834 (should (equal (org-export-resolve-coderef "text" info
) "text")))))
836 (ert-deftest test-org-export
/resolve-fuzzy-link
()
837 "Test `org-export-resolve-fuzzy-link' specifications."
838 ;; 1. Match target objects.
839 (org-test-with-parsed-data "<<target>> [[target]]"
841 (org-export-resolve-fuzzy-link
842 (org-element-map tree
'link
'identity info t
) info
)))
843 ;; 2. Match target elements.
844 (org-test-with-parsed-data "#+TARGET: target\n[[target]]"
846 (org-export-resolve-fuzzy-link
847 (org-element-map tree
'link
'identity info t
) info
)))
848 ;; 3. Match named elements.
849 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
851 (org-export-resolve-fuzzy-link
852 (org-element-map tree
'link
'identity info t
) info
)))
853 ;; 4. Match exact headline's name.
854 (org-test-with-parsed-data "* My headline\n[[My headline]]"
856 (org-export-resolve-fuzzy-link
857 (org-element-map tree
'link
'identity info t
) info
)))
858 ;; 5. Targets objects have priority over named elements and headline
860 (org-test-with-parsed-data
861 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
865 (org-export-resolve-fuzzy-link
866 (org-element-map tree
'link
'identity info t
) info
)))))
867 ;; 6. Named elements have priority over headline titles.
868 (org-test-with-parsed-data
869 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
873 (org-export-resolve-fuzzy-link
874 (org-element-map tree
'link
'identity info t
) info
)))))
875 ;; 7. If link's path starts with a "*", only match headline titles,
877 (org-test-with-parsed-data
878 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
882 (org-export-resolve-fuzzy-link
883 (org-element-map tree
'link
'identity info t
) info
)))))
884 ;; 8. Return nil if no match.
885 (org-test-with-parsed-data "[[target]]"
887 (org-export-resolve-fuzzy-link
888 (org-element-map tree
'link
'identity info t
) info
))))
890 (ert-deftest test-org-export
/resolve-id-link
()
891 "Test `org-export-resolve-id-link' specifications."
892 ;; 1. Regular test for custom-id link.
893 (org-test-with-parsed-data "* Headline1
900 (org-export-resolve-id-link
901 (org-element-map tree
'link
'identity info t
) info
)))
902 ;; 2. Failing test for custom-id link.
903 (org-test-with-parsed-data "* Headline1
910 (org-export-resolve-id-link
911 (org-element-map tree
'link
'identity info t
) info
)))
912 ;; 3. Test for internal id target.
913 (org-test-with-parsed-data "* Headline1
920 (org-export-resolve-id-link
921 (org-element-map tree
'link
'identity info t
) info
)))
922 ;; 4. Test for external id target.
923 (org-test-with-parsed-data "[[id:aaaa]]"
925 (org-export-resolve-id-link
926 (org-element-map tree
'link
'identity info t
)
927 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file"))))))))
929 (ert-deftest test-org-export
/resolve-radio-link
()
930 "Test `org-export-resolve-radio-link' specifications."
932 (org-test-with-temp-text "<<<radio>>> radio"
933 (org-update-radio-target-regexp)
935 (let* ((tree (org-element-parse-buffer))
936 (info `(:parse-tree
,tree
)))
937 (org-export-resolve-radio-link
938 (org-element-map tree
'link
'identity info t
)
940 ;; Radio target with objects.
941 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
942 (org-update-radio-target-regexp)
944 (let* ((tree (org-element-parse-buffer))
945 (info `(:parse-tree
,tree
)))
946 (org-export-resolve-radio-link
947 (org-element-map tree
'link
'identity info t
)
954 (ert-deftest test-org-export
/define-macro
()
955 "Try defining various Org macro using in-buffer #+MACRO: keyword."
957 (should (equal (org-test-with-temp-text "#+MACRO: one 1"
958 (org-export--get-inbuffer-options))
959 '(:macro-one
("1"))))
961 (should (equal (org-test-with-temp-text "#+MACRO: two (eval (+ 1 1))"
962 (org-export--get-inbuffer-options))
963 '(:macro-two
("(eval (+ 1 1))"))))
965 (should-not (org-test-with-temp-text "#+MACRO: three"
966 (org-export--get-inbuffer-options)))
967 ;; Macro with newline character.
968 (should (equal (org-test-with-temp-text "#+MACRO: four a\\nb"
969 (org-export--get-inbuffer-options))
970 '(:macro-four
("a\nb"))))
971 ;; Macro with protected newline character.
972 (should (equal (org-test-with-temp-text "#+MACRO: five a\\\\nb"
973 (org-export--get-inbuffer-options))
974 '(:macro-five
("a\\nb"))))
976 (org-test-with-temp-text "#+MACRO: six 6\n#+MACRO: seven 1 + {{{six}}}"
979 (org-export--get-inbuffer-options)
983 ("1 + " (macro (:key
"six" :value
"{{{six}}}" :args nil
:begin
5 :end
14
984 :post-blank
0 :parent nil
))))))))
986 (ert-deftest test-org-export
/expand-macro
()
987 "Test `org-export-expand-macro' specifications."
992 (org-test-with-parsed-data "#+MACRO: macro some text\n{{{macro}}}"
993 (org-export-expand-macro
994 (org-element-map tree
'macro
'identity info t
) info
))))
995 ;; Macro with arguments.
999 (org-test-with-parsed-data "#+MACRO: macro $1 $2\n{{{macro(some,text)}}}"
1000 (org-export-expand-macro
1001 (org-element-map tree
'macro
'identity info t
) info
))))
1002 ;; Macro with "eval"
1006 (org-test-with-parsed-data "#+MACRO: add (eval (+ $1 $2))\n{{{add(1,2)}}}"
1007 (org-export-expand-macro
1008 (org-element-map tree
'macro
'identity info t
) info
))))
1013 (org-test-with-parsed-data
1014 "#+MACRO: in inner\n#+MACRO: out {{{in}}} outer\n{{{out}}}"
1015 (flet ((translate-macro (macro contents info
)
1016 (org-export-expand-macro macro info
)))
1017 (org-export-expand-macro
1018 (org-element-map tree
'macro
'identity info t
)
1020 info
`(:translate-alist
((macro . translate-macro
))))))))))
1024 ;;; Src-block and example-block
1026 (ert-deftest test-org-export
/unravel-code
()
1027 "Test `org-export-unravel-code' function."
1028 (let ((org-coderef-label-format "(ref:%s)"))
1029 ;; 1. Code without reference.
1030 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
1031 (should (equal (org-export-unravel-code (org-element-at-point))
1033 ;; 2. Code with reference.
1034 (org-test-with-temp-text
1035 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
1036 (should (equal (org-export-unravel-code (org-element-at-point))
1037 '("(+ 1 1)\n" (1 .
"test")))))
1038 ;; 3. Code with user-defined reference.
1039 (org-test-with-temp-text
1040 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
1041 (should (equal (org-export-unravel-code (org-element-at-point))
1042 '("(+ 1 1)\n" (1 .
"test")))))
1043 ;; 4. Code references keys are relative to the current block.
1044 (org-test-with-temp-text "
1053 (should (equal (org-export-unravel-code (org-element-at-point))
1054 '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one")))))
1055 ;; 5. Free up comma-protected lines.
1057 ;; 5.1. In an Org source block, every line is protected.
1058 (org-test-with-temp-text
1059 "#+BEGIN_SRC org\n,* Test\n,# comment\n,Text\n#+END_SRC"
1060 (should (equal (org-export-unravel-code (org-element-at-point))
1061 '("* Test\n# comment\nText\n"))))
1062 ;; 5.2. In other blocks, only headlines, comments and keywords are
1064 (org-test-with-temp-text
1065 "#+BEGIN_EXAMPLE\n,* Headline\n, * Not headline\n,Keep\n#+END_EXAMPLE"
1066 (should (equal (org-export-unravel-code (org-element-at-point))
1067 '("* Headline\n, * Not headline\n,Keep\n"))))))
1073 (ert-deftest test-org-export
/special-column
()
1074 "Test if the table's special column is properly recognized."
1075 ;; 1. First column is special if it contains only a special marking
1076 ;; characters or empty cells.
1077 (org-test-with-temp-text "
1081 (org-export-table-has-special-column-p
1083 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1084 ;; 2. If the column contains anything else, it isn't special.
1085 (org-test-with-temp-text "
1089 (org-export-table-has-special-column-p
1091 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1092 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
1094 (org-test-with-temp-text "
1103 (org-export-table-has-special-column-p
1105 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1106 ;; 4. A first column with only empty cells isn't considered as
1108 (org-test-with-temp-text "
1112 (org-export-table-has-special-column-p
1114 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
1116 (ert-deftest test-org-export
/table-row-is-special-p
()
1117 "Test `org-export-table-row-is-special-p' specifications."
1118 ;; 1. A row is special if it has a special marking character in the
1120 (org-test-with-parsed-data "| ! | 1 |"
1122 (org-export-table-row-is-special-p
1123 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1124 ;; 2. A row is special when its first field is "/"
1125 (org-test-with-parsed-data "
1129 (org-export-table-row-is-special-p
1130 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1131 ;; 3. A row only containing alignment cookies is also considered as
1133 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
1135 (org-export-table-row-is-special-p
1136 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1137 ;; 4. Everything else isn't considered as special.
1138 (org-test-with-parsed-data "| \alpha | | c |"
1140 (org-export-table-row-is-special-p
1141 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1142 ;; 5. Table's rules are never considered as special rows.
1143 (org-test-with-parsed-data "|---+---|"
1145 (org-export-table-row-is-special-p
1146 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
1148 (ert-deftest test-org-export
/has-header-p
()
1149 "Test `org-export-table-has-header-p' specifications."
1150 ;; 1. With an header.
1151 (org-test-with-parsed-data "
1156 (org-export-table-has-header-p
1157 (org-element-map tree
'table
'identity info
'first-match
)
1159 ;; 2. Without an header.
1160 (org-test-with-parsed-data "
1164 (org-export-table-has-header-p
1165 (org-element-map tree
'table
'identity info
'first-match
)
1167 ;; 3. Don't get fooled with starting and ending rules.
1168 (org-test-with-parsed-data "
1174 (org-export-table-has-header-p
1175 (org-element-map tree
'table
'identity info
'first-match
)
1178 (ert-deftest test-org-export
/table-row-group
()
1179 "Test `org-export-table-row-group' specifications."
1180 ;; 1. A rule creates a new group.
1181 (org-test-with-parsed-data "
1188 (mapcar (lambda (row) (org-export-table-row-group row info
))
1189 (org-element-map tree
'table-row
'identity
)))))
1190 ;; 2. Special rows are ignored in count.
1191 (org-test-with-parsed-data "
1198 (mapcar (lambda (row) (org-export-table-row-group row info
))
1199 (org-element-map tree
'table-row
'identity
)))))
1200 ;; 3. Double rules also are ignored in count.
1201 (org-test-with-parsed-data "
1209 (mapcar (lambda (row) (org-export-table-row-group row info
))
1210 (org-element-map tree
'table-row
'identity
))))))
1212 (ert-deftest test-org-export
/table-cell-width
()
1213 "Test `org-export-table-cell-width' specifications."
1214 ;; 1. Width is primarily determined by width cookies. If no cookie
1215 ;; is found, cell's width is nil.
1216 (org-test-with-parsed-data "
1217 | / | <l> | <6> | <l7> |
1222 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1223 (org-element-map tree
'table-cell
'identity info
)))))
1224 ;; 2. The last width cookie has precedence.
1225 (org-test-with-parsed-data "
1232 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1233 (org-element-map tree
'table-cell
'identity info
)))))
1234 ;; 3. Valid width cookies must have a specific row.
1235 (org-test-with-parsed-data "| <6> | cell |"
1239 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1240 (org-element-map tree
'table-cell
'identity
))))))
1242 (ert-deftest test-org-export
/table-cell-alignment
()
1243 "Test `org-export-table-cell-alignment' specifications."
1244 (let ((org-table-number-fraction 0.5)
1245 (org-table-number-regexp "^[0-9]+$"))
1246 ;; 1. Alignment is primarily determined by alignment cookies.
1247 (org-test-with-temp-text "| <l> | <c> | <r> |"
1248 (let* ((tree (org-element-parse-buffer))
1249 (info `(:parse-tree
,tree
)))
1252 '(left center right
)
1253 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1254 (org-element-map tree
'table-cell
'identity
))))))
1255 ;; 2. The last alignment cookie has precedence.
1256 (org-test-with-parsed-data "
1262 '(right right right
)
1263 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1264 (org-element-map tree
'table-cell
'identity
)))))
1265 ;; 3. If there's no cookie, cell's contents determine alignment.
1266 ;; A column mostly made of cells containing numbers will align
1267 ;; its cells to the right.
1268 (org-test-with-parsed-data "
1274 '(right right right
)
1275 (mapcar (lambda (cell)
1276 (org-export-table-cell-alignment cell info
))
1277 (org-element-map tree
'table-cell
'identity
)))))
1278 ;; 4. Otherwise, they will be aligned to the left.
1279 (org-test-with-parsed-data "
1286 (mapcar (lambda (cell)
1287 (org-export-table-cell-alignment cell info
))
1288 (org-element-map tree
'table-cell
'identity
)))))))
1290 (ert-deftest test-org-export
/table-cell-borders
()
1291 "Test `org-export-table-cell-borders' specifications."
1292 ;; 1. Recognize various column groups indicators.
1293 (org-test-with-parsed-data "| / | < | > | <> |"
1296 '((right bottom top
) (left bottom top
) (right bottom top
)
1297 (right left bottom top
))
1298 (mapcar (lambda (cell)
1299 (org-export-table-cell-borders cell info
))
1300 (org-element-map tree
'table-cell
'identity
)))))
1301 ;; 2. Accept shortcuts to define column groups.
1302 (org-test-with-parsed-data "| / | < | < |"
1305 '((right bottom top
) (right left bottom top
) (left bottom top
))
1306 (mapcar (lambda (cell)
1307 (org-export-table-cell-borders cell info
))
1308 (org-element-map tree
'table-cell
'identity
)))))
1309 ;; 3. A valid column groups row must start with a "/".
1310 (org-test-with-parsed-data "
1314 (equal '((top) (top) (bottom) (bottom))
1315 (mapcar (lambda (cell)
1316 (org-export-table-cell-borders cell info
))
1317 (org-element-map tree
'table-cell
'identity
)))))
1318 ;; 4. Take table rules into consideration.
1319 (org-test-with-parsed-data "
1324 (equal '((below top
) (bottom above
))
1325 (mapcar (lambda (cell)
1326 (org-export-table-cell-borders cell info
))
1327 (org-element-map tree
'table-cell
'identity
)))))
1328 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
1329 ;; (resp. `bottom' and `below') borders. Any special row is
1331 (org-test-with-parsed-data "
1337 (equal '((bottom below top above
))
1339 (mapcar (lambda (cell)
1340 (org-export-table-cell-borders cell info
))
1341 (org-element-map tree
'table-cell
'identity
)))))))
1343 (ert-deftest test-org-export
/table-dimensions
()
1344 "Test `org-export-table-dimensions' specifications."
1345 ;; 1. Standard test.
1346 (org-test-with-parsed-data "
1351 (org-export-table-dimensions
1352 (org-element-map tree
'table
'identity info
'first-match
) info
))))
1353 ;; 2. Ignore horizontal rules and special columns.
1354 (org-test-with-parsed-data "
1361 (org-export-table-dimensions
1362 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
1364 (ert-deftest test-org-export
/table-cell-address
()
1365 "Test `org-export-table-cell-address' specifications."
1366 ;; 1. Standard test: index is 0-based.
1367 (org-test-with-parsed-data "| a | b |"
1369 (equal '((0 .
0) (0 .
1))
1372 (lambda (cell) (org-export-table-cell-address cell info
))
1374 ;; 2. Special column isn't counted, nor are special rows.
1375 (org-test-with-parsed-data "
1380 (org-export-table-cell-address
1381 (car (last (org-element-map tree
'table-cell
'identity info
)))
1383 ;; 3. Tables rules do not count either.
1384 (org-test-with-parsed-data "
1392 (org-export-table-cell-address
1393 (car (last (org-element-map tree
'table-cell
'identity info
)))
1395 ;; 4. Return nil for special cells.
1396 (org-test-with-parsed-data "| / | a |"
1398 (org-export-table-cell-address
1399 (org-element-map tree
'table-cell
'identity nil
'first-match
)
1402 (ert-deftest test-org-export
/get-table-cell-at
()
1403 "Test `org-export-get-table-cell-at' specifications."
1404 ;; 1. Address ignores special columns, special rows and rules.
1405 (org-test-with-parsed-data "
1412 (org-element-contents
1413 (org-export-get-table-cell-at
1415 (org-element-map tree
'table
'identity info
'first-match
)
1417 ;; 2. Return value for a non-existent address is nil.
1418 (org-test-with-parsed-data "| a |"
1420 (org-export-get-table-cell-at
1422 (org-element-map tree
'table
'identity info
'first-match
)
1424 (org-test-with-parsed-data "| / |"
1426 (org-export-get-table-cell-at
1428 (org-element-map tree
'table
'identity info
'first-match
)
1431 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
1432 "Test `org-export-table-cell-starts-colgroup-p' specifications."
1433 ;; 1. A cell at a beginning of a row always starts a column group.
1434 (org-test-with-parsed-data "| a |"
1436 (org-export-table-cell-starts-colgroup-p
1437 (org-element-map tree
'table-cell
'identity info
'first-match
)
1439 ;; 2. Special column should be ignored when determining the
1440 ;; beginning of the row.
1441 (org-test-with-parsed-data "
1445 (org-export-table-cell-starts-colgroup-p
1446 (org-element-map tree
'table-cell
'identity info
'first-match
)
1448 ;; 2. Explicit column groups.
1449 (org-test-with-parsed-data "
1458 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
1461 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
1462 "Test `org-export-table-cell-ends-colgroup-p' specifications."
1463 ;; 1. A cell at the end of a row always ends a column group.
1464 (org-test-with-parsed-data "| a |"
1466 (org-export-table-cell-ends-colgroup-p
1467 (org-element-map tree
'table-cell
'identity info
'first-match
)
1469 ;; 2. Special column should be ignored when determining the
1470 ;; beginning of the row.
1471 (org-test-with-parsed-data "
1475 (org-export-table-cell-ends-colgroup-p
1476 (org-element-map tree
'table-cell
'identity info
'first-match
)
1478 ;; 3. Explicit column groups.
1479 (org-test-with-parsed-data "
1488 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
1491 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
1492 "Test `org-export-table-row-starts-rowgroup-p' specifications."
1493 ;; 1. A row at the beginning of a table always starts a row group.
1494 ;; So does a row following a table rule.
1495 (org-test-with-parsed-data "
1505 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
1507 ;; 2. Special rows should be ignored when determining the beginning
1509 (org-test-with-parsed-data "
1521 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
1524 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
1525 "Test `org-export-table-row-ends-rowgroup-p' specifications."
1526 ;; 1. A row at the end of a table always ends a row group. So does
1527 ;; a row preceding a table rule.
1528 (org-test-with-parsed-data "
1538 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
1540 ;; 2. Special rows should be ignored when determining the beginning
1542 (org-test-with-parsed-data "
1554 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
1557 (ert-deftest test-org-export
/table-row-starts-header-p
()
1558 "Test `org-export-table-row-starts-header-p' specifications."
1559 ;; 1. Only the row starting the first row group starts the table
1561 (org-test-with-parsed-data "
1572 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
1574 ;; 2. A row cannot start an header if there's no header in the
1576 (org-test-with-parsed-data "
1580 (org-export-table-row-starts-header-p
1581 (org-element-map tree
'table-row
'identity info
'first-match
)
1584 (ert-deftest test-org-export
/table-row-ends-header-p
()
1585 "Test `org-export-table-row-ends-header-p' specifications."
1586 ;; 1. Only the row starting the first row group starts the table
1588 (org-test-with-parsed-data "
1599 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
1601 ;; 2. A row cannot start an header if there's no header in the
1603 (org-test-with-parsed-data "
1607 (org-export-table-row-ends-header-p
1608 (org-element-map tree
'table-row
'identity info
'first-match
)
1615 (ert-deftest test-org-export
/get-next-element
()
1616 "Test `org-export-get-next-element' specifications."
1620 (org-test-with-parsed-data "* Headline\n*a* b"
1621 (org-export-get-next-element
1622 (org-element-map tree
'bold
'identity info t
) info
))))
1623 ;; Return nil when no previous element.
1625 (org-test-with-parsed-data "* Headline\na *b*"
1626 (org-export-get-next-element
1627 (org-element-map tree
'bold
'identity info t
) info
)))
1628 ;; Non-exportable elements are ignored.
1630 (let ((org-export-with-timestamps nil
))
1631 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
1632 (org-export-get-next-element
1633 (org-element-map tree
'entity
'identity info t
) info
)))))
1635 (ert-deftest test-org-export
/get-previous-element
()
1636 "Test `org-export-get-previous-element' specifications."
1640 (org-test-with-parsed-data "* Headline\na *b*"
1641 (org-export-get-previous-element
1642 (org-element-map tree
'bold
'identity info t
) info
))))
1643 ;; Return nil when no previous element.
1645 (org-test-with-parsed-data "* Headline\n*a* b"
1646 (org-export-get-previous-element
1647 (org-element-map tree
'bold
'identity info t
) info
)))
1648 ;; Non-exportable elements are ignored.
1650 (let ((org-export-with-timestamps nil
))
1651 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
1652 (org-export-get-previous-element
1653 (org-element-map tree
'entity
'identity info t
) info
)))))
1656 (provide 'test-org-export
)
1657 ;;; test-org-export.el end here