1 ;;; test-org-export.el --- Tests for org-export.el
3 ;; Copyright (C) 2012 Nicolas Goaziou
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
7 ;; Released under the GNU General Public License version 3
8 ;; see: http://www.gnu.org/licenses/gpl-3.0.html
16 (unless (featurep 'org-export
)
17 (signal 'missing-test-dependency
"org-export"))
19 (defmacro org-test-with-backend
(backend &rest body
)
20 "Execute body with an export back-end defined.
22 BACKEND is the name of the back-end. BODY is the body to
23 execute. The defined back-end simply returns parsed data as Org
25 (declare (debug (form body
)) (indent 1))
26 `(let ((,(intern (format "org-%s-translate-alist" backend
))
27 ',(let (transcode-table)
28 (dolist (type (append org-element-all-elements
29 org-element-all-objects
)
33 (lambda (obj contents info
)
35 (intern (format "org-element-%s-interpreter" type
))
40 (defmacro org-test-with-parsed-data
(data &rest body
)
41 "Execute body with parsed data available.
43 DATA is a string containing the data to be parsed. BODY is the
44 body to execute. Parse tree is available under the `tree'
45 variable, and communication channel under `info'.
47 This function calls `org-export-collect-tree-properties'. As
48 such, `:ignore-list' (for `org-element-map') and
49 `:parse-tree' (for `org-export-get-genealogy') properties are
50 already filled in `info'."
51 (declare (debug (form body
)) (indent 1))
52 `(org-test-with-temp-text ,data
53 (let* ((tree (org-element-parse-buffer))
54 (info (org-export-collect-tree-properties
55 tree
(org-export-get-environment))))
62 (ert-deftest test-org-export
/bind-keyword
()
63 "Test reading #+BIND: keywords."
64 ;; Test with `org-export-all-BIND' set to t.
66 (org-test-with-temp-text "#+BIND: variable value"
67 (let ((org-export-allow-BIND t
))
68 (org-export--install-letbind-maybe)
69 (eq variable
'value
))))
70 ;; Test with `org-export-all-BIND' set to nil.
72 (org-test-with-temp-text "#+BIND: variable value"
73 (let ((org-export-allow-BIND nil
))
74 (org-export--install-letbind-maybe)
76 ;; Test with `org-export-all-BIND' set to 'confirm and
77 ;; `org-export--allow-BIND-local' to t .
79 (org-test-with-temp-text "#+BIND: variable value"
80 (let ((org-export-allow-BIND 'confirm
))
81 (org-set-local 'org-export--allow-BIND-local t
)
82 (org-export--install-letbind-maybe)
83 (eq variable
'value
))))
84 ;; Test with `org-export-all-BIND' set to 'confirm and
85 ;; `org-export--allow-BIND-local' to nil.
87 (org-test-with-temp-text "#+BIND: variable value"
88 (let ((org-export-allow-BIND 'confirm
))
89 (org-set-local 'org-export--allow-BIND-local nil
)
90 (org-export--install-letbind-maybe)
92 ;; BIND keywords are case-insensitive.
94 (org-test-with-temp-text "#+bind: variable value"
95 (let ((org-export-allow-BIND t
))
96 (org-export--install-letbind-maybe)
97 (eq variable
'value
)))))
99 (ert-deftest test-org-export
/parse-option-keyword
()
100 "Test reading all standard #+OPTIONS: items."
103 (org-export--parse-option-keyword
104 "H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t
105 *:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t inline:nil
108 1 :preserve-breaks t
:section-numbers t
:time-stamp-file t
109 :with-archived-trees t
:with-author t
:with-creator t
:with-drawers t
110 :with-email t
:with-emphasize t
:with-entities t
:with-fixed-width t
111 :with-footnotes t
:with-inlinetasks nil
:with-priority t
112 :with-special-strings t
:with-statistics-cookies t
:with-sub-superscript t
113 :with-toc t
:with-tables t
:with-tags t
:with-tasks t
:with-timestamps t
114 :with-todo-keywords t
)))
115 ;; Test some special values.
118 (org-export--parse-option-keyword
119 "arch:headline creator:comment d:(\"TEST\")
120 ^:{} toc:1 tags:not-in-toc tasks:todo num:2 <:active")
123 :with-archived-trees headline
:with-creator comment
124 :with-drawers
("TEST") :with-sub-superscript
{} :with-toc
1
125 :with-tags not-in-toc
:with-tasks todo
:with-timestamps active
))))
127 (ert-deftest test-org-export
/get-inbuffer-options
()
128 "Test reading all standard export keywords."
131 (org-test-with-temp-text "#+AUTHOR: Me, Myself and I
134 #+DESCRIPTION: Testing
135 #+DESCRIPTION: with two lines
136 #+EMAIL: some@email.org
137 #+EXCLUDE_TAGS: noexport invisible
140 #+SELECT_TAGS: export
142 #+TITLE: with spaces"
143 (org-export--get-inbuffer-options))
145 ("Me, Myself and I") :creator
"Idem" :date
("Today")
146 :description
"Testing\nwith two lines" :email
"some@email.org"
147 :exclude-tags
("noexport" "invisible") :keywords
"test" :language
"en"
148 :select-tags
("export") :title
("Some title with spaces")))))
150 (ert-deftest test-org-export
/get-subtree-options
()
151 "Test setting options from headline's properties."
153 (org-test-with-temp-text "#+TITLE: Title
156 :EXPORT_TITLE: Subtree Title
160 (should (equal (plist-get (org-export-get-environment nil t
) :title
)
161 '("Subtree Title"))))
165 (org-test-with-temp-text "#+OPTIONS: H:1
173 (= 2 (plist-get (org-export-get-environment nil t
) :headline-levels
))))
175 (org-test-with-temp-text "#+DATE: today
178 :EXPORT_DATE: 29-03-2012
182 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
184 ;; Export properties are case-insensitive.
185 (org-test-with-temp-text "* Headline
187 :EXPORT_Date: 29-03-2012
190 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
193 (ert-deftest test-org-export
/handle-options
()
194 "Test if export options have an impact on output."
195 ;; Test exclude tags.
196 (org-test-with-temp-text "* Head1 :noexport:"
197 (org-test-with-backend test
199 (equal (org-export-as 'test nil nil nil
'(:exclude-tags
("noexport")))
201 ;; Test include tags.
202 (org-test-with-temp-text "
205 ** Sub-Head2.1 :export:
208 (org-test-with-backend test
211 "* Head2\n** Sub-Head2.1 :export:\n*** Sub-Head2.1.1\n"
212 (let ((org-tags-column 0))
213 (org-export-as 'test nil nil nil
'(:select-tags
("export"))))))))
214 ;; Test mixing include tags and exclude tags.
215 (org-test-with-temp-text "
217 ** Sub-Head1 :noexport:
220 ** Sub-Head1 :export:"
221 (org-test-with-backend test
224 "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
227 '(:select-tags
("export") :exclude-tags
("noexport")))))))
229 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
230 (org-test-with-temp-text "* TODO Head1"
231 (org-test-with-backend test
232 (should (equal (org-export-as 'test nil nil nil
'(:with-tasks nil
))
234 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
235 (org-test-with-temp-text "* TODO Head1"
236 (org-test-with-backend test
237 (should (equal (org-export-as 'test nil nil nil
'(:with-tasks t
))
238 "* TODO Head1\n")))))
240 (org-test-with-temp-text "* Head1 :archive:"
241 (let ((org-archive-tag "archive"))
242 (org-test-with-backend test
244 (equal (org-export-as 'test nil nil nil
'(:with-archived-trees nil
))
246 (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
247 (let ((org-archive-tag "archive"))
248 (org-test-with-backend test
251 "\\* Head1[ \t]+:archive:"
252 (org-export-as 'test nil nil nil
253 '(:with-archived-trees headline
)))))))
254 (org-test-with-temp-text "* Head1 :archive:"
255 (let ((org-archive-tag "archive"))
256 (org-test-with-backend test
259 "\\`\\* Head1[ \t]+:archive:\n\\'"
260 (org-export-as 'test nil nil nil
'(:with-archived-trees t
)))))))
262 (let ((org-drawers '("TEST")))
263 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
264 (org-test-with-backend test
265 (should (equal (org-export-as 'test nil nil nil
'(:with-drawers nil
))
267 (should (equal (org-export-as 'test nil nil nil
'(:with-drawers t
))
268 ":TEST:\ncontents\n:END:\n")))))
269 (let ((org-drawers '("FOO" "BAR")))
270 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
271 (org-test-with-backend test
273 (equal (org-export-as 'test nil nil nil
'(:with-drawers
("FOO")))
274 ":FOO:\nkeep\n:END:\n")))))
276 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
277 (org-test-with-backend test
279 (equal (org-export-as 'test nil nil nil
'(:with-timestamps t
))
280 "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>\n"))
282 (equal (org-export-as 'test nil nil nil
'(:with-timestamps nil
)) ""))
284 (equal (org-export-as 'test nil nil nil
'(:with-timestamps active
))
285 "<2012-04-29 sun. 10:45>\n"))
287 (equal (org-export-as 'test nil nil nil
'(:with-timestamps inactive
))
288 "[2012-04-29 sun. 10:45]\n"))))
290 (let ((org-clock-string "CLOCK:"))
291 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
292 (org-test-with-backend test
294 (equal (org-export-as 'test nil nil nil
'(:with-clocks t
))
295 "CLOCK: [2012-04-29 sun. 10:45]\n"))
297 (equal (org-export-as 'test nil nil nil
'(:with-clocks nil
)) "")))))
299 (let ((org-closed-string "CLOSED:"))
300 (org-test-with-temp-text "CLOSED: [2012-04-29 sun. 10:45]"
301 (org-test-with-backend test
303 (equal (org-export-as 'test nil nil nil
'(:with-plannings t
))
304 "CLOSED: [2012-04-29 sun. 10:45]\n"))
306 (equal (org-export-as 'test nil nil nil
'(:with-plannings nil
))
309 (when (featurep 'org-inlinetask
)
312 (let ((org-inlinetask-min-level 15))
313 (org-test-with-temp-text "*************** Task"
314 (org-test-with-backend test
315 (org-export-as 'test nil nil nil
'(:with-inlinetasks nil
)))))
319 (let ((org-inlinetask-min-level 15))
320 (org-test-with-temp-text
321 "*************** Task\nContents\n*************** END"
322 (org-test-with-backend test
323 (org-export-as 'test nil nil nil
'(:with-inlinetasks nil
)))))
325 ;; Statistics cookies.
328 (org-test-with-temp-text "[0/0]"
329 (org-test-with-backend test
331 'test nil nil nil
'(:with-statistics-cookies nil
)))))))
333 (ert-deftest test-org-export
/comment-tree
()
334 "Test if export process ignores commented trees."
335 (let ((org-comment-string "COMMENT"))
336 (org-test-with-temp-text "* COMMENT Head1"
337 (org-test-with-backend test
338 (should (equal (org-export-as 'test
) ""))))))
340 (ert-deftest test-org-export
/export-scope
()
341 "Test all export scopes."
342 (org-test-with-temp-text "
347 (org-test-with-backend test
350 (should (equal (org-export-as 'test
'subtree
) "text\n*** Head3\n"))
352 (goto-char (point-min))
355 (should (equal (org-export-as 'test nil
'visible
) "* Head1\n"))
357 (flet ((org-test-template (body info
) (format "BEGIN\n%sEND" body
)))
358 (push '(template . org-test-template
) org-test-translate-alist
)
359 (should (equal (org-export-as 'test nil nil
'body-only
)
360 "* Head1\n** Head2\ntext\n*** Head3\n"))
361 (should (equal (org-export-as 'test
)
362 "BEGIN\n* Head1\n** Head2\ntext\n*** Head3\nEND")))
364 (goto-char (point-min))
366 (transient-mark-mode 1)
367 (push-mark (point) t t
)
368 (goto-char (point-at-eol))
369 (should (equal (org-export-as 'test
) "text\n"))))
370 ;; Subtree with a code block calling another block outside.
371 (org-test-with-temp-text "
373 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
378 #+BEGIN_SRC emacs-lisp
381 (org-test-with-backend test
383 (should (equal (org-export-as 'test
'subtree
) ": 3\n")))))
385 (ert-deftest test-org-export
/expand-include
()
386 "Test file inclusion in an Org buffer."
387 ;; Full insertion with recursive inclusion.
388 (org-test-with-temp-text
389 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir
)
390 (org-export-expand-include-keyword)
391 (should (equal (buffer-string)
392 "Small Org file with an include keyword.
394 #+BEGIN_SRC emacs-lisp :exports results\n(+ 2 1)\n#+END_SRC
400 ;; Localized insertion.
401 (org-test-with-temp-text
402 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
404 (org-export-expand-include-keyword)
405 (should (equal (buffer-string)
406 "Small Org file with an include keyword.\n")))
407 ;; Insertion with constraints on headlines level.
408 (org-test-with-temp-text
410 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\""
412 (org-export-expand-include-keyword)
413 (should (equal (buffer-string) "* Top heading\n** Heading\nbody\n")))
414 ;; Inclusion within an example block.
415 (org-test-with-temp-text
416 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" example"
418 (org-export-expand-include-keyword)
422 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n")))
423 ;; Inclusion within a src-block.
424 (org-test-with-temp-text
426 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" src emacs-lisp"
428 (org-export-expand-include-keyword)
429 (should (equal (buffer-string)
430 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"))))
432 (ert-deftest test-org-export
/expand-macro
()
433 "Test macro expansion in an Org buffer."
434 ;; Standard macro expansion.
436 (equal "#+MACRO: macro1 value\nvalue"
437 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
439 (org-macro-initialize-templates)
440 (org-export-expand-macro info
) (buffer-string)))))
441 ;; Export specific macros.
443 (equal "me 2012-03-29 me@here Title"
444 (org-test-with-temp-text
450 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
451 (let ((info (org-export-get-environment)))
452 (org-macro-initialize-templates)
453 (org-export-expand-macro info
)
454 (goto-char (point-max))
455 (buffer-substring (line-beginning-position)
456 (line-end-position)))))))
458 (ert-deftest test-org-export
/user-ignore-list
()
459 "Test if `:ignore-list' accepts user input."
460 (org-test-with-backend test
461 (flet ((skip-note-head
463 ;; Ignore headlines with the word "note" in their title.
467 (when (string-match "\\<note\\>"
468 (org-element-property :raw-value headline
))
469 (org-export-ignore-element headline info
)))
472 ;; Install function in parse tree filters.
473 (let ((org-export-filter-parse-tree-functions '(skip-note-head)))
474 (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
475 (should (equal (org-export-as 'test
) "* Head1\n")))))))
477 (ert-deftest test-org-export
/before-parsing-hook
()
478 "Test `org-export-before-parsing-hook'."
479 (org-test-with-backend test
480 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
481 (let ((org-export-before-parsing-hook
485 (delete-region (point) (progn (forward-line) (point)))))))))
486 (should (equal (org-export-as 'test
) "Body 1\nBody 2\n"))))))
490 ;;; Affiliated Keywords
492 (ert-deftest test-org-export
/read-attribute
()
493 "Test `org-export-read-attribute' specifications."
497 (org-export-read-attribute
499 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
500 (org-element-at-point)))
502 ;; Return nil on empty attribute.
504 (org-export-read-attribute
506 (org-test-with-temp-text "Paragraph" (org-element-at-point)))))
508 (ert-deftest test-org-export
/get-caption
()
509 "Test `org-export-get-caption' specifications."
510 ;; Without optional argument, return long caption
514 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
515 (org-export-get-caption (org-element-at-point)))))
516 ;; With optional argument, return short caption.
520 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
521 (org-export-get-caption (org-element-at-point) t
))))
522 ;; Multiple lines are separated by white spaces.
526 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
527 (org-export-get-caption (org-element-at-point))))))
533 (ert-deftest test-org-export
/export-snippet
()
534 "Test export snippets transcoding."
535 (org-test-with-temp-text "@@test:A@@@@t:B@@"
536 (org-test-with-backend test
537 (let ((org-test-translate-alist
538 (cons (cons 'export-snippet
539 (lambda (snippet contents info
)
540 (when (eq (org-export-snippet-backend snippet
) 'test
)
541 (org-element-property :value snippet
))))
542 org-test-translate-alist
)))
543 (let ((org-export-snippet-translation-alist nil
))
544 (should (equal (org-export-as 'test
) "A\n")))
545 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
546 (should (equal (org-export-as 'test
) "AB\n")))))))
552 (ert-deftest test-org-export
/footnotes
()
553 "Test footnotes specifications."
554 (let ((org-footnote-section nil
)
555 (org-export-with-footnotes t
))
556 ;; 1. Read every type of footnote.
559 '((1 .
"A\n") (2 .
"B") (3 .
"C") (4 .
"D"))
560 (org-test-with-parsed-data
561 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
563 tree
'footnote-reference
565 (let ((def (org-export-get-footnote-definition ref info
)))
566 (cons (org-export-get-footnote-number ref info
)
567 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
568 (car (org-element-contents
569 (car (org-element-contents def
))))))))
571 ;; 2. Test nested footnotes order.
572 (org-test-with-parsed-data
573 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
576 '((1 .
"fn:1") (2 .
"fn:2") (3 .
"fn:3") (4))
578 tree
'footnote-reference
580 (when (org-export-footnote-first-reference-p ref info
)
581 (cons (org-export-get-footnote-number ref info
)
582 (org-element-property :label ref
))))
584 ;; 3. Test nested footnote in invisible definitions.
585 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
587 (narrow-to-region (point) (point-at-eol))
588 (let* ((tree (org-element-parse-buffer))
589 (info (org-combine-plists
591 (org-export-collect-tree-properties
592 tree
(org-export-get-environment)))))
593 ;; Both footnotes should be seen.
595 (= (length (org-export-collect-footnote-definitions tree info
)) 2))))
596 ;; 4. Test footnotes definitions collection.
597 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
599 \[fn:2] B [fn:3] [fn::D].
602 (should (= (length (org-export-collect-footnote-definitions tree info
))
604 ;; 5. Test export of footnotes defined outside parsing scope.
605 (org-test-with-temp-text "[fn:1] Out of scope
608 (org-test-with-backend test
609 (let ((org-test-translate-alist
610 (cons (cons 'footnote-reference
611 (lambda (fn contents info
)
612 (org-element-interpret-data
613 (org-export-get-footnote-definition fn info
))))
614 org-test-translate-alist
)))
616 (should (equal "ParagraphOut of scope\n"
617 (org-export-as 'test
'subtree
))))))))
621 ;;; Headlines and Inlinetasks
623 (ert-deftest test-org-export
/get-relative-level
()
624 "Test `org-export-get-relative-level' specifications."
628 (let ((org-odd-levels-only nil
))
629 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
632 (lambda (h) (org-export-get-relative-level h info
))
637 (let ((org-odd-levels-only nil
))
638 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
641 (lambda (h) (org-export-get-relative-level h info
))
644 (ert-deftest test-org-export
/low-level-p
()
645 "Test `org-export-low-level-p' specifications."
649 (let ((org-odd-levels-only nil
))
650 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
653 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
654 (plist-put info
:headline-levels
1)))))))
656 (ert-deftest test-org-export
/get-headline-number
()
657 "Test `org-export-get-headline-number' specifications."
662 (let ((org-odd-levels-only nil
))
663 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
666 (lambda (h) (org-export-get-headline-number h info
))
668 ;; Missing levels are replaced with 0.
672 (let ((org-odd-levels-only nil
))
673 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
676 (lambda (h) (org-export-get-headline-number h info
))
679 (ert-deftest test-org-export
/numbered-headline-p
()
680 "Test `org-export-numbered-headline-p' specifications."
681 ;; If `:section-numbers' is nil, never number headlines.
683 (org-test-with-parsed-data "* Headline"
686 (lambda (h) (org-export-numbered-headline-p h info
))
687 (plist-put info
:section-numbers nil
))))
688 ;; If `:section-numbers' is a number, only number headlines with
689 ;; a level greater that it.
693 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
696 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
697 (plist-put info
:section-numbers
1)))))
698 ;; Otherwise, headlines are always numbered.
700 (org-test-with-parsed-data "* Headline"
703 (lambda (h) (org-export-numbered-headline-p h info
))
704 (plist-put info
:section-numbers t
)))))
706 (ert-deftest test-org-export
/number-to-roman
()
707 "Test `org-export-number-to-roman' specifications."
708 ;; If number is negative, return it as a string.
709 (should (equal (org-export-number-to-roman -
1) "-1"))
710 ;; Otherwise, return it as a roman number.
711 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
713 (ert-deftest test-org-export
/get-tags
()
714 "Test `org-export-get-tags' specifications."
715 (let ((org-export-exclude-tags '("noexport"))
716 (org-export-select-tags '("export")))
717 ;; Standard test: tags which are not a select tag, an exclude tag,
718 ;; or specified as optional argument shouldn't be ignored.
720 (org-test-with-parsed-data "* Headline :tag:"
721 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
723 ;; Exclude tags are removed.
725 (org-test-with-parsed-data "* Headline :noexport:"
726 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
728 ;; Select tags are removed.
730 (org-test-with-parsed-data "* Headline :export:"
731 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
736 (org-test-with-parsed-data "* Headline :tag:export:"
737 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
739 ;; Tags provided in the optional argument are also ignored.
741 (org-test-with-parsed-data "* Headline :ignore:"
742 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
743 info
'("ignore"))))))
745 (ert-deftest test-org-export
/get-node-property
()
746 "Test`org-export-get-node-property' specifications."
750 (org-test-with-parsed-data "* Headline
754 (org-export-get-node-property
755 :prop
(org-element-map tree
'headline
'identity nil t
)))))
759 (org-test-with-parsed-data "* Parent
765 (org-export-get-node-property
766 :prop
(org-element-map tree
'paragraph
'identity nil t
) t
))))
767 ;; Cannot return a value before the first headline.
769 (org-test-with-parsed-data "Paragraph
774 (org-export-get-node-property
775 :prop
(org-element-map tree
'paragraph
'identity nil t
)))))
777 (ert-deftest test-org-export
/first-sibling-p
()
778 "Test `org-export-first-sibling-p' specifications."
783 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
786 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
788 ;; Ignore headlines not exported.
792 (let ((org-export-exclude-tags '("ignore")))
793 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
796 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
799 (ert-deftest test-org-export
/last-sibling-p
()
800 "Test `org-export-last-sibling-p' specifications."
805 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
808 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
810 ;; Ignore headlines not exported.
814 (let ((org-export-exclude-tags '("ignore")))
815 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
818 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
825 (ert-deftest test-org-export
/get-coderef-format
()
826 "Test `org-export-get-coderef-format' specifications."
827 ;; A link without description returns "%s"
828 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
830 ;; Return "%s" when path is matched within description.
831 (should (equal (org-export-get-coderef-format "path" "desc (path)")
833 ;; Otherwise return description.
834 (should (equal (org-export-get-coderef-format "path" "desc")
837 (ert-deftest test-org-export
/inline-image-p
()
838 "Test `org-export-inline-image-p' specifications."
840 (org-export-inline-image-p
841 (org-test-with-temp-text "[[#id]]"
843 (org-element-parse-buffer) 'link
'identity nil t
))
844 '(("custom-id" .
"id")))))
846 (ert-deftest test-org-export
/fuzzy-link
()
847 "Test fuzzy links specifications."
848 ;; 1. Links to invisible (keyword) targets should be ignored.
849 (org-test-with-parsed-data
850 "Paragraph.\n#+TARGET: Test\n[[Test]]"
855 (org-export-get-ordinal
856 (org-export-resolve-fuzzy-link link info
) info
)) info
)))
857 ;; 2. Link to an headline should return headline's number.
858 (org-test-with-parsed-data
859 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
861 ;; Note: Headline's number is in fact a list of numbers.
866 (org-export-get-ordinal
867 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
868 ;; 3. Link to a target in an item should return item's number.
869 (org-test-with-parsed-data
870 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
872 ;; Note: Item's number is in fact a list of numbers.
877 (org-export-get-ordinal
878 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
879 ;; 4. Link to a target in a footnote should return footnote's
881 (org-test-with-parsed-data "
882 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
888 (org-export-get-ordinal
889 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
890 ;; 5. Link to a named element should return sequence number of that
892 (org-test-with-parsed-data
893 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
899 (org-export-get-ordinal
900 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
901 ;; 6. Link to a target not within an item, a table, a footnote
902 ;; reference or definition should return section number.
903 (org-test-with-parsed-data
904 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
910 (org-export-get-ordinal
911 (org-export-resolve-fuzzy-link link info
) info
)) info t
)))))
913 (ert-deftest test-org-export
/resolve-coderef
()
914 "Test `org-export-resolve-coderef' specifications."
915 (let ((org-coderef-label-format "(ref:%s)"))
916 ;; 1. A link to a "-n -k -r" block returns line number.
917 (org-test-with-parsed-data
918 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
919 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
920 (org-test-with-parsed-data
921 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
922 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
923 ;; 2. A link to a "-n -r" block returns line number.
924 (org-test-with-parsed-data
925 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
926 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
927 (org-test-with-parsed-data
928 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
929 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
930 ;; 3. A link to a "-n" block returns coderef.
931 (org-test-with-parsed-data
932 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
933 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
934 (org-test-with-parsed-data
935 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
936 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
937 ;; 4. A link to a "-r" block returns line number.
938 (org-test-with-parsed-data
939 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
940 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
941 (org-test-with-parsed-data
942 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
943 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
944 ;; 5. A link to a block without a switch returns coderef.
945 (org-test-with-parsed-data
946 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
947 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
948 (org-test-with-parsed-data
949 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
950 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
951 ;; 6. Correctly handle continued line numbers. A "+n" switch
952 ;; should resume numbering from previous block with numbered
953 ;; lines, ignoring blocks not numbering lines in the process.
954 ;; A "-n" switch resets count.
955 (org-test-with-parsed-data "
960 #+BEGIN_SRC emacs-lisp
964 #+BEGIN_SRC emacs-lisp +n -r
965 \(+ 1 1) (ref:addition)
968 #+BEGIN_EXAMPLE -n -r
969 Another text. (ref:text)
971 (should (= (org-export-resolve-coderef "addition" info
) 2))
972 (should (= (org-export-resolve-coderef "text" info
) 1)))
973 ;; 7. Recognize coderef with user-specified syntax.
974 (org-test-with-parsed-data
975 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
976 (should (equal (org-export-resolve-coderef "text" info
) "text")))))
978 (ert-deftest test-org-export
/resolve-fuzzy-link
()
979 "Test `org-export-resolve-fuzzy-link' specifications."
980 ;; 1. Match target objects.
981 (org-test-with-parsed-data "<<target>> [[target]]"
983 (org-export-resolve-fuzzy-link
984 (org-element-map tree
'link
'identity info t
) info
)))
985 ;; 2. Match target elements.
986 (org-test-with-parsed-data "#+TARGET: target\n[[target]]"
988 (org-export-resolve-fuzzy-link
989 (org-element-map tree
'link
'identity info t
) info
)))
990 ;; 3. Match named elements.
991 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
993 (org-export-resolve-fuzzy-link
994 (org-element-map tree
'link
'identity info t
) info
)))
995 ;; 4. Match exact headline's name.
996 (org-test-with-parsed-data "* My headline\n[[My headline]]"
998 (org-export-resolve-fuzzy-link
999 (org-element-map tree
'link
'identity info t
) info
)))
1000 ;; 5. Targets objects have priority over named elements and headline
1002 (org-test-with-parsed-data
1003 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
1007 (org-export-resolve-fuzzy-link
1008 (org-element-map tree
'link
'identity info t
) info
)))))
1009 ;; 6. Named elements have priority over headline titles.
1010 (org-test-with-parsed-data
1011 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
1015 (org-export-resolve-fuzzy-link
1016 (org-element-map tree
'link
'identity info t
) info
)))))
1017 ;; 7. If link's path starts with a "*", only match headline titles,
1019 (org-test-with-parsed-data
1020 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
1024 (org-export-resolve-fuzzy-link
1025 (org-element-map tree
'link
'identity info t
) info
)))))
1026 ;; 8. Return nil if no match.
1027 (org-test-with-parsed-data "[[target]]"
1029 (org-export-resolve-fuzzy-link
1030 (org-element-map tree
'link
'identity info t
) info
))))
1032 (ert-deftest test-org-export
/resolve-id-link
()
1033 "Test `org-export-resolve-id-link' specifications."
1034 ;; 1. Regular test for custom-id link.
1035 (org-test-with-parsed-data "* Headline1
1042 (org-export-resolve-id-link
1043 (org-element-map tree
'link
'identity info t
) info
)))
1044 ;; 2. Failing test for custom-id link.
1045 (org-test-with-parsed-data "* Headline1
1052 (org-export-resolve-id-link
1053 (org-element-map tree
'link
'identity info t
) info
)))
1054 ;; 3. Test for internal id target.
1055 (org-test-with-parsed-data "* Headline1
1062 (org-export-resolve-id-link
1063 (org-element-map tree
'link
'identity info t
) info
)))
1064 ;; 4. Test for external id target.
1065 (org-test-with-parsed-data "[[id:aaaa]]"
1067 (org-export-resolve-id-link
1068 (org-element-map tree
'link
'identity info t
)
1069 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file"))))))))
1071 (ert-deftest test-org-export
/resolve-radio-link
()
1072 "Test `org-export-resolve-radio-link' specifications."
1074 (org-test-with-temp-text "<<<radio>>> radio"
1075 (org-update-radio-target-regexp)
1077 (let* ((tree (org-element-parse-buffer))
1078 (info `(:parse-tree
,tree
)))
1079 (org-export-resolve-radio-link
1080 (org-element-map tree
'link
'identity info t
)
1082 ;; Radio target with objects.
1083 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
1084 (org-update-radio-target-regexp)
1086 (let* ((tree (org-element-parse-buffer))
1087 (info `(:parse-tree
,tree
)))
1088 (org-export-resolve-radio-link
1089 (org-element-map tree
'link
'identity info t
)
1094 ;;; Src-block and example-block
1096 (ert-deftest test-org-export
/unravel-code
()
1097 "Test `org-export-unravel-code' function."
1098 (let ((org-coderef-label-format "(ref:%s)"))
1099 ;; 1. Code without reference.
1100 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
1101 (should (equal (org-export-unravel-code (org-element-at-point))
1103 ;; 2. Code with reference.
1104 (org-test-with-temp-text
1105 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
1106 (should (equal (org-export-unravel-code (org-element-at-point))
1107 '("(+ 1 1)\n" (1 .
"test")))))
1108 ;; 3. Code with user-defined reference.
1109 (org-test-with-temp-text
1110 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
1111 (should (equal (org-export-unravel-code (org-element-at-point))
1112 '("(+ 1 1)\n" (1 .
"test")))))
1113 ;; 4. Code references keys are relative to the current block.
1114 (org-test-with-temp-text "
1123 (should (equal (org-export-unravel-code (org-element-at-point))
1124 '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one")))))))
1130 (ert-deftest test-org-export
/special-column
()
1131 "Test if the table's special column is properly recognized."
1132 ;; 1. First column is special if it contains only a special marking
1133 ;; characters or empty cells.
1134 (org-test-with-temp-text "
1138 (org-export-table-has-special-column-p
1140 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1141 ;; 2. If the column contains anything else, it isn't special.
1142 (org-test-with-temp-text "
1146 (org-export-table-has-special-column-p
1148 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1149 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
1151 (org-test-with-temp-text "
1160 (org-export-table-has-special-column-p
1162 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1163 ;; 4. A first column with only empty cells isn't considered as
1165 (org-test-with-temp-text "
1169 (org-export-table-has-special-column-p
1171 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
1173 (ert-deftest test-org-export
/table-row-is-special-p
()
1174 "Test `org-export-table-row-is-special-p' specifications."
1175 ;; 1. A row is special if it has a special marking character in the
1177 (org-test-with-parsed-data "| ! | 1 |"
1179 (org-export-table-row-is-special-p
1180 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1181 ;; 2. A row is special when its first field is "/"
1182 (org-test-with-parsed-data "
1186 (org-export-table-row-is-special-p
1187 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1188 ;; 3. A row only containing alignment cookies is also considered as
1190 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
1192 (org-export-table-row-is-special-p
1193 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1194 ;; 4. Everything else isn't considered as special.
1195 (org-test-with-parsed-data "| \alpha | | c |"
1197 (org-export-table-row-is-special-p
1198 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1199 ;; 5. Table's rules are never considered as special rows.
1200 (org-test-with-parsed-data "|---+---|"
1202 (org-export-table-row-is-special-p
1203 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
1205 (ert-deftest test-org-export
/has-header-p
()
1206 "Test `org-export-table-has-header-p' specifications."
1207 ;; 1. With an header.
1208 (org-test-with-parsed-data "
1213 (org-export-table-has-header-p
1214 (org-element-map tree
'table
'identity info
'first-match
)
1216 ;; 2. Without an header.
1217 (org-test-with-parsed-data "
1221 (org-export-table-has-header-p
1222 (org-element-map tree
'table
'identity info
'first-match
)
1224 ;; 3. Don't get fooled with starting and ending rules.
1225 (org-test-with-parsed-data "
1231 (org-export-table-has-header-p
1232 (org-element-map tree
'table
'identity info
'first-match
)
1235 (ert-deftest test-org-export
/table-row-group
()
1236 "Test `org-export-table-row-group' specifications."
1237 ;; 1. A rule creates a new group.
1238 (org-test-with-parsed-data "
1245 (mapcar (lambda (row) (org-export-table-row-group row info
))
1246 (org-element-map tree
'table-row
'identity
)))))
1247 ;; 2. Special rows are ignored in count.
1248 (org-test-with-parsed-data "
1255 (mapcar (lambda (row) (org-export-table-row-group row info
))
1256 (org-element-map tree
'table-row
'identity
)))))
1257 ;; 3. Double rules also are ignored in count.
1258 (org-test-with-parsed-data "
1266 (mapcar (lambda (row) (org-export-table-row-group row info
))
1267 (org-element-map tree
'table-row
'identity
))))))
1269 (ert-deftest test-org-export
/table-cell-width
()
1270 "Test `org-export-table-cell-width' specifications."
1271 ;; 1. Width is primarily determined by width cookies. If no cookie
1272 ;; is found, cell's width is nil.
1273 (org-test-with-parsed-data "
1274 | / | <l> | <6> | <l7> |
1279 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1280 (org-element-map tree
'table-cell
'identity info
)))))
1281 ;; 2. The last width cookie has precedence.
1282 (org-test-with-parsed-data "
1289 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1290 (org-element-map tree
'table-cell
'identity info
)))))
1291 ;; 3. Valid width cookies must have a specific row.
1292 (org-test-with-parsed-data "| <6> | cell |"
1296 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1297 (org-element-map tree
'table-cell
'identity
))))))
1299 (ert-deftest test-org-export
/table-cell-alignment
()
1300 "Test `org-export-table-cell-alignment' specifications."
1301 (let ((org-table-number-fraction 0.5)
1302 (org-table-number-regexp "^[0-9]+$"))
1303 ;; 1. Alignment is primarily determined by alignment cookies.
1304 (org-test-with-temp-text "| <l> | <c> | <r> |"
1305 (let* ((tree (org-element-parse-buffer))
1306 (info `(:parse-tree
,tree
)))
1309 '(left center right
)
1310 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1311 (org-element-map tree
'table-cell
'identity
))))))
1312 ;; 2. The last alignment cookie has precedence.
1313 (org-test-with-parsed-data "
1319 '(right right right
)
1320 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1321 (org-element-map tree
'table-cell
'identity
)))))
1322 ;; 3. If there's no cookie, cell's contents determine alignment.
1323 ;; A column mostly made of cells containing numbers will align
1324 ;; its cells to the right.
1325 (org-test-with-parsed-data "
1331 '(right right right
)
1332 (mapcar (lambda (cell)
1333 (org-export-table-cell-alignment cell info
))
1334 (org-element-map tree
'table-cell
'identity
)))))
1335 ;; 4. Otherwise, they will be aligned to the left.
1336 (org-test-with-parsed-data "
1343 (mapcar (lambda (cell)
1344 (org-export-table-cell-alignment cell info
))
1345 (org-element-map tree
'table-cell
'identity
)))))))
1347 (ert-deftest test-org-export
/table-cell-borders
()
1348 "Test `org-export-table-cell-borders' specifications."
1349 ;; 1. Recognize various column groups indicators.
1350 (org-test-with-parsed-data "| / | < | > | <> |"
1353 '((right bottom top
) (left bottom top
) (right bottom top
)
1354 (right left bottom top
))
1355 (mapcar (lambda (cell)
1356 (org-export-table-cell-borders cell info
))
1357 (org-element-map tree
'table-cell
'identity
)))))
1358 ;; 2. Accept shortcuts to define column groups.
1359 (org-test-with-parsed-data "| / | < | < |"
1362 '((right bottom top
) (right left bottom top
) (left bottom top
))
1363 (mapcar (lambda (cell)
1364 (org-export-table-cell-borders cell info
))
1365 (org-element-map tree
'table-cell
'identity
)))))
1366 ;; 3. A valid column groups row must start with a "/".
1367 (org-test-with-parsed-data "
1371 (equal '((top) (top) (bottom) (bottom))
1372 (mapcar (lambda (cell)
1373 (org-export-table-cell-borders cell info
))
1374 (org-element-map tree
'table-cell
'identity
)))))
1375 ;; 4. Take table rules into consideration.
1376 (org-test-with-parsed-data "
1381 (equal '((below top
) (bottom above
))
1382 (mapcar (lambda (cell)
1383 (org-export-table-cell-borders cell info
))
1384 (org-element-map tree
'table-cell
'identity
)))))
1385 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
1386 ;; (resp. `bottom' and `below') borders. Any special row is
1388 (org-test-with-parsed-data "
1394 (equal '((bottom below top above
))
1396 (mapcar (lambda (cell)
1397 (org-export-table-cell-borders cell info
))
1398 (org-element-map tree
'table-cell
'identity
)))))))
1400 (ert-deftest test-org-export
/table-dimensions
()
1401 "Test `org-export-table-dimensions' specifications."
1402 ;; 1. Standard test.
1403 (org-test-with-parsed-data "
1408 (org-export-table-dimensions
1409 (org-element-map tree
'table
'identity info
'first-match
) info
))))
1410 ;; 2. Ignore horizontal rules and special columns.
1411 (org-test-with-parsed-data "
1418 (org-export-table-dimensions
1419 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
1421 (ert-deftest test-org-export
/table-cell-address
()
1422 "Test `org-export-table-cell-address' specifications."
1423 ;; 1. Standard test: index is 0-based.
1424 (org-test-with-parsed-data "| a | b |"
1426 (equal '((0 .
0) (0 .
1))
1429 (lambda (cell) (org-export-table-cell-address cell info
))
1431 ;; 2. Special column isn't counted, nor are special rows.
1432 (org-test-with-parsed-data "
1437 (org-export-table-cell-address
1438 (car (last (org-element-map tree
'table-cell
'identity info
)))
1440 ;; 3. Tables rules do not count either.
1441 (org-test-with-parsed-data "
1449 (org-export-table-cell-address
1450 (car (last (org-element-map tree
'table-cell
'identity info
)))
1452 ;; 4. Return nil for special cells.
1453 (org-test-with-parsed-data "| / | a |"
1455 (org-export-table-cell-address
1456 (org-element-map tree
'table-cell
'identity nil
'first-match
)
1459 (ert-deftest test-org-export
/get-table-cell-at
()
1460 "Test `org-export-get-table-cell-at' specifications."
1461 ;; 1. Address ignores special columns, special rows and rules.
1462 (org-test-with-parsed-data "
1469 (org-element-contents
1470 (org-export-get-table-cell-at
1472 (org-element-map tree
'table
'identity info
'first-match
)
1474 ;; 2. Return value for a non-existent address is nil.
1475 (org-test-with-parsed-data "| a |"
1477 (org-export-get-table-cell-at
1479 (org-element-map tree
'table
'identity info
'first-match
)
1481 (org-test-with-parsed-data "| / |"
1483 (org-export-get-table-cell-at
1485 (org-element-map tree
'table
'identity info
'first-match
)
1488 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
1489 "Test `org-export-table-cell-starts-colgroup-p' specifications."
1490 ;; 1. A cell at a beginning of a row always starts a column group.
1491 (org-test-with-parsed-data "| a |"
1493 (org-export-table-cell-starts-colgroup-p
1494 (org-element-map tree
'table-cell
'identity info
'first-match
)
1496 ;; 2. Special column should be ignored when determining the
1497 ;; beginning of the row.
1498 (org-test-with-parsed-data "
1502 (org-export-table-cell-starts-colgroup-p
1503 (org-element-map tree
'table-cell
'identity info
'first-match
)
1505 ;; 2. Explicit column groups.
1506 (org-test-with-parsed-data "
1515 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
1518 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
1519 "Test `org-export-table-cell-ends-colgroup-p' specifications."
1520 ;; 1. A cell at the end of a row always ends a column group.
1521 (org-test-with-parsed-data "| a |"
1523 (org-export-table-cell-ends-colgroup-p
1524 (org-element-map tree
'table-cell
'identity info
'first-match
)
1526 ;; 2. Special column should be ignored when determining the
1527 ;; beginning of the row.
1528 (org-test-with-parsed-data "
1532 (org-export-table-cell-ends-colgroup-p
1533 (org-element-map tree
'table-cell
'identity info
'first-match
)
1535 ;; 3. Explicit column groups.
1536 (org-test-with-parsed-data "
1545 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
1548 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
1549 "Test `org-export-table-row-starts-rowgroup-p' specifications."
1550 ;; 1. A row at the beginning of a table always starts a row group.
1551 ;; So does a row following a table rule.
1552 (org-test-with-parsed-data "
1562 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
1564 ;; 2. Special rows should be ignored when determining the beginning
1566 (org-test-with-parsed-data "
1578 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
1581 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
1582 "Test `org-export-table-row-ends-rowgroup-p' specifications."
1583 ;; 1. A row at the end of a table always ends a row group. So does
1584 ;; a row preceding a table rule.
1585 (org-test-with-parsed-data "
1595 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
1597 ;; 2. Special rows should be ignored when determining the beginning
1599 (org-test-with-parsed-data "
1611 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
1614 (ert-deftest test-org-export
/table-row-starts-header-p
()
1615 "Test `org-export-table-row-starts-header-p' specifications."
1616 ;; 1. Only the row starting the first row group starts the table
1618 (org-test-with-parsed-data "
1629 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
1631 ;; 2. A row cannot start an header if there's no header in the
1633 (org-test-with-parsed-data "
1637 (org-export-table-row-starts-header-p
1638 (org-element-map tree
'table-row
'identity info
'first-match
)
1641 (ert-deftest test-org-export
/table-row-ends-header-p
()
1642 "Test `org-export-table-row-ends-header-p' specifications."
1643 ;; 1. Only the row starting the first row group starts the table
1645 (org-test-with-parsed-data "
1656 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
1658 ;; 2. A row cannot start an header if there's no header in the
1660 (org-test-with-parsed-data "
1664 (org-export-table-row-ends-header-p
1665 (org-element-map tree
'table-row
'identity info
'first-match
)
1672 (ert-deftest test-org-export
/get-next-element
()
1673 "Test `org-export-get-next-element' specifications."
1677 (org-test-with-parsed-data "* Headline\n*a* b"
1678 (org-export-get-next-element
1679 (org-element-map tree
'bold
'identity info t
) info
))))
1680 ;; Return nil when no previous element.
1682 (org-test-with-parsed-data "* Headline\na *b*"
1683 (org-export-get-next-element
1684 (org-element-map tree
'bold
'identity info t
) info
)))
1685 ;; Non-exportable elements are ignored.
1687 (let ((org-export-with-timestamps nil
))
1688 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
1689 (org-export-get-next-element
1690 (org-element-map tree
'entity
'identity info t
) info
)))))
1692 (ert-deftest test-org-export
/get-previous-element
()
1693 "Test `org-export-get-previous-element' specifications."
1697 (org-test-with-parsed-data "* Headline\na *b*"
1698 (org-export-get-previous-element
1699 (org-element-map tree
'bold
'identity info t
) info
))))
1700 ;; Return nil when no previous element.
1702 (org-test-with-parsed-data "* Headline\n*a* b"
1703 (org-export-get-previous-element
1704 (org-element-map tree
'bold
'identity info t
) info
)))
1705 ;; Non-exportable elements are ignored.
1707 (let ((org-export-with-timestamps nil
))
1708 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
1709 (org-export-get-previous-element
1710 (org-element-map tree
'entity
'identity info t
) info
)))))
1713 (provide 'test-org-export
)
1714 ;;; test-org-export.el end here