1 ;;; test-org-export.el --- Tests for org-export.el
3 ;; Copyright (C) 2012, 2013 Nicolas Goaziou
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
7 ;; This file is not part of GNU Emacs.
9 ;; This program is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
24 (unless (featurep 'org-export
)
25 (signal 'missing-test-dependency
"org-export"))
27 (defmacro org-test-with-backend
(backend &rest body
)
28 "Execute body with an export back-end defined.
30 BACKEND is the name of the back-end. BODY is the body to
31 execute. The defined back-end simply returns parsed data as Org
33 (declare (debug (form body
)) (indent 1))
34 `(let ((,(intern (format "org-%s-translate-alist" backend
))
35 ',(let (transcode-table)
36 (dolist (type (append org-element-all-elements
37 org-element-all-objects
)
41 (lambda (obj contents info
)
43 (intern (format "org-element-%s-interpreter" type
))
48 (defmacro org-test-with-parsed-data
(data &rest body
)
49 "Execute body with parsed data available.
51 DATA is a string containing the data to be parsed. BODY is the
52 body to execute. Parse tree is available under the `tree'
53 variable, and communication channel under `info'.
55 This function calls `org-export-collect-tree-properties'. As
56 such, `:ignore-list' (for `org-element-map') and
57 `:parse-tree' (for `org-export-get-genealogy') properties are
58 already filled in `info'."
59 (declare (debug (form body
)) (indent 1))
60 `(org-test-with-temp-text ,data
61 (let* ((tree (org-element-parse-buffer))
62 (info (org-export-collect-tree-properties
63 tree
(org-export-get-environment))))
70 (ert-deftest test-org-export
/parse-option-keyword
()
71 "Test reading all standard #+OPTIONS: items."
74 (org-export--parse-option-keyword
75 "H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t
76 *:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t inline:nil")
78 1 :preserve-breaks t
:section-numbers t
:time-stamp-file t
79 :with-archived-trees t
:with-author t
:with-creator t
:with-drawers t
80 :with-email t
:with-emphasize t
:with-entities t
:with-fixed-width t
81 :with-footnotes t
:with-inlinetasks nil
:with-priority t
82 :with-special-strings t
:with-sub-superscript t
:with-toc t
:with-tables t
83 :with-tags t
:with-tasks t
:with-timestamps t
:with-todo-keywords t
)))
84 ;; Test some special values.
87 (org-export--parse-option-keyword
88 "arch:headline creator:comment d:(\"TEST\")
89 ^:{} toc:1 tags:not-in-toc tasks:todo num:2 <:active")
92 :with-archived-trees headline
:with-creator comment
93 :with-drawers
("TEST") :with-sub-superscript
{} :with-toc
1
94 :with-tags not-in-toc
:with-tasks todo
:with-timestamps active
))))
96 (ert-deftest test-org-export
/get-inbuffer-options
()
97 "Test reading all standard export keywords."
100 (org-test-with-temp-text "#+AUTHOR: Me, Myself and I
103 #+DESCRIPTION: Testing
104 #+DESCRIPTION: with two lines
105 #+EMAIL: some@email.org
106 #+EXCLUDE_TAGS: noexport invisible
109 #+SELECT_TAGS: export
111 #+TITLE: with spaces"
112 (org-export--get-inbuffer-options))
114 ("Me, Myself and I") :creator
"Idem" :date
("Today")
115 :description
"Testing\nwith two lines" :email
"some@email.org"
116 :exclude-tags
("noexport" "invisible") :keywords
"test" :language
"en"
117 :select-tags
("export") :title
("Some title with spaces")))))
119 (ert-deftest test-org-export
/get-subtree-options
()
120 "Test setting options from headline's properties."
122 (org-test-with-temp-text "#+TITLE: Title
125 :EXPORT_TITLE: Subtree Title
129 (should (equal (plist-get (org-export-get-environment nil t
) :title
)
130 '("Subtree Title"))))
134 (org-test-with-temp-text "#+OPTIONS: H:1
142 (= 2 (plist-get (org-export-get-environment nil t
) :headline-levels
))))
144 (org-test-with-temp-text "#+DATE: today
147 :EXPORT_DATE: 29-03-2012
151 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
153 ;; Export properties are case-insensitive.
154 (org-test-with-temp-text "* Headline
156 :EXPORT_Date: 29-03-2012
159 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
162 (ert-deftest test-org-export
/handle-options
()
163 "Test if export options have an impact on output."
164 ;; Test exclude tags.
165 (org-test-with-temp-text "* Head1 :noexport:"
166 (org-test-with-backend test
168 (equal (org-export-as 'test nil nil nil
'(:exclude-tags
("noexport")))
170 ;; Test include tags.
171 (org-test-with-temp-text "
174 ** Sub-Head2.1 :export:
177 (org-test-with-backend test
180 "* Head2\n** Sub-Head2.1 :export:\n*** Sub-Head2.1.1\n"
181 (let ((org-tags-column 0))
182 (org-export-as 'test nil nil nil
'(:select-tags
("export"))))))))
183 ;; Test mixing include tags and exclude tags.
184 (org-test-with-temp-text "
186 ** Sub-Head1 :noexport:
189 ** Sub-Head1 :export:"
190 (org-test-with-backend test
193 "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
196 '(:select-tags
("export") :exclude-tags
("noexport")))))))
198 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
199 (org-test-with-temp-text "* TODO Head1"
200 (org-test-with-backend test
201 (should (equal (org-export-as 'test nil nil nil
'(:with-tasks nil
))
203 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
204 (org-test-with-temp-text "* TODO Head1"
205 (org-test-with-backend test
206 (should (equal (org-export-as 'test nil nil nil
'(:with-tasks t
))
207 "* TODO Head1\n")))))
209 (org-test-with-temp-text "* Head1 :archive:"
210 (let ((org-archive-tag "archive"))
211 (org-test-with-backend test
213 (equal (org-export-as 'test nil nil nil
'(:with-archived-trees nil
))
215 (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
216 (let ((org-archive-tag "archive"))
217 (org-test-with-backend test
220 "\\* Head1[ \t]+:archive:"
221 (org-export-as 'test nil nil nil
222 '(:with-archived-trees headline
)))))))
223 (org-test-with-temp-text "* Head1 :archive:"
224 (let ((org-archive-tag "archive"))
225 (org-test-with-backend test
228 "\\`\\* Head1[ \t]+:archive:\n\\'"
229 (org-export-as 'test nil nil nil
'(:with-archived-trees t
)))))))
231 (let ((org-drawers '("TEST")))
232 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
233 (org-test-with-backend test
234 (should (equal (org-export-as 'test nil nil nil
'(:with-drawers nil
))
236 (should (equal (org-export-as 'test nil nil nil
'(:with-drawers t
))
237 ":TEST:\ncontents\n:END:\n")))))
238 (let ((org-drawers '("FOO" "BAR")))
239 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
240 (org-test-with-backend test
242 (equal (org-export-as 'test nil nil nil
'(:with-drawers
("FOO")))
243 ":FOO:\nkeep\n:END:\n")))))
245 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
246 (org-test-with-backend test
248 (equal (org-export-as 'test nil nil nil
'(:with-timestamps t
))
249 "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>\n"))
251 (equal (org-export-as 'test nil nil nil
'(:with-timestamps nil
)) ""))
253 (equal (org-export-as 'test nil nil nil
'(:with-timestamps active
))
254 "<2012-04-29 sun. 10:45>\n"))
256 (equal (org-export-as 'test nil nil nil
'(:with-timestamps inactive
))
257 "[2012-04-29 sun. 10:45]\n"))))
259 (let ((org-clock-string "CLOCK:"))
260 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
261 (org-test-with-backend test
263 (equal (org-export-as 'test nil nil nil
'(:with-clocks t
))
264 "CLOCK: [2012-04-29 sun. 10:45]\n"))
266 (equal (org-export-as 'test nil nil nil
'(:with-clocks nil
)) "")))))
268 (let ((org-closed-string "CLOSED:"))
269 (org-test-with-temp-text "CLOSED: [2012-04-29 sun. 10:45]"
270 (org-test-with-backend test
272 (equal (org-export-as 'test nil nil nil
'(:with-plannings t
))
273 "CLOSED: [2012-04-29 sun. 10:45]\n"))
275 (equal (org-export-as 'test nil nil nil
'(:with-plannings nil
))
278 (when (featurep 'org-inlinetask
)
281 (let ((org-inlinetask-min-level 15))
282 (org-test-with-temp-text "*************** Task"
283 (org-test-with-backend test
284 (org-export-as 'test nil nil nil
'(:with-inlinetasks nil
)))))
288 (let ((org-inlinetask-min-level 15))
289 (org-test-with-temp-text
290 "*************** Task\nContents\n*************** END"
291 (org-test-with-backend test
292 (org-export-as 'test nil nil nil
'(:with-inlinetasks nil
)))))
295 (ert-deftest test-org-export
/comment-tree
()
296 "Test if export process ignores commented trees."
297 (let ((org-comment-string "COMMENT"))
298 (org-test-with-temp-text "* COMMENT Head1"
299 (org-test-with-backend test
300 (should (equal (org-export-as 'test
) ""))))))
302 (ert-deftest test-org-export
/export-scope
()
303 "Test all export scopes."
304 (org-test-with-temp-text "
309 (org-test-with-backend test
312 (should (equal (org-export-as 'test
'subtree
) "text\n*** Head3\n"))
314 (goto-char (point-min))
317 (should (equal (org-export-as 'test nil
'visible
) "* Head1\n"))
319 (flet ((org-test-template (body info
) (format "BEGIN\n%sEND" body
)))
320 (push '(template . org-test-template
) org-test-translate-alist
)
321 (should (equal (org-export-as 'test nil nil
'body-only
)
322 "* Head1\n** Head2\ntext\n*** Head3\n"))
323 (should (equal (org-export-as 'test
)
324 "BEGIN\n* Head1\n** Head2\ntext\n*** Head3\nEND")))
326 (goto-char (point-min))
328 (transient-mark-mode 1)
329 (push-mark (point) t t
)
330 (goto-char (point-at-eol))
331 (should (equal (org-export-as 'test
) "text\n"))))
332 ;; Subtree with a code block calling another block outside.
333 (org-test-with-temp-text "
335 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
340 #+BEGIN_SRC emacs-lisp
343 (org-test-with-backend test
345 (should (equal (org-export-as 'test
'subtree
) ": 3\n")))))
347 (ert-deftest test-org-export
/expand-include
()
348 "Test file inclusion in an Org buffer."
349 ;; Full insertion with recursive inclusion.
350 (org-test-with-temp-text
351 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir
)
352 (org-export-expand-include-keyword)
353 (should (equal (buffer-string)
354 "Small Org file with an include keyword.
356 #+BEGIN_SRC emacs-lisp :exports results\n(+ 2 1)\n#+END_SRC
362 ;; Localized insertion.
363 (org-test-with-temp-text
364 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
366 (org-export-expand-include-keyword)
367 (should (equal (buffer-string)
368 "Small Org file with an include keyword.\n")))
369 ;; Insertion with constraints on headlines level.
370 (org-test-with-temp-text
372 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\""
374 (org-export-expand-include-keyword)
375 (should (equal (buffer-string) "* Top heading\n** Heading\nbody\n")))
376 ;; Inclusion within an example block.
377 (org-test-with-temp-text
378 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" example"
380 (org-export-expand-include-keyword)
384 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n")))
385 ;; Inclusion within a src-block.
386 (org-test-with-temp-text
388 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" src emacs-lisp"
390 (org-export-expand-include-keyword)
391 (should (equal (buffer-string)
392 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"))))
394 (ert-deftest test-org-export
/user-ignore-list
()
395 "Test if `:ignore-list' accepts user input."
396 (org-test-with-backend test
397 (flet ((skip-note-head
399 ;; Ignore headlines with the word "note" in their title.
403 (when (string-match "\\<note\\>"
404 (org-element-property :raw-value headline
))
405 (org-export-ignore-element headline info
)))
408 ;; Install function in parse tree filters.
409 (let ((org-export-filter-parse-tree-functions '(skip-note-head)))
410 (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
411 (should (equal (org-export-as 'test
) "* Head1\n")))))))
413 (ert-deftest test-org-export
/before-parsing-hook
()
414 "Test `org-export-before-parsing-hook'."
415 (org-test-with-backend test
416 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
417 (let ((org-export-before-parsing-hook
421 (delete-region (point) (progn (forward-line) (point)))))))))
422 (should (equal (org-export-as 'test
) "Body 1\nBody 2\n"))))))
426 ;;; Affiliated Keywords
428 (ert-deftest test-org-export
/read-attribute
()
429 "Test `org-export-read-attribute' specifications."
433 (org-export-read-attribute
435 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
436 (org-element-at-point)))
438 ;; Return nil on empty attribute.
440 (org-export-read-attribute
442 (org-test-with-temp-text "Paragraph" (org-element-at-point)))))
448 (ert-deftest test-org-export
/export-snippet
()
449 "Test export snippets transcoding."
450 (org-test-with-temp-text "@@test:A@@@@t:B@@"
451 (org-test-with-backend test
452 (let ((org-test-translate-alist
453 (cons (cons 'export-snippet
454 (lambda (snippet contents info
)
455 (when (eq (org-export-snippet-backend snippet
) 'test
)
456 (org-element-property :value snippet
))))
457 org-test-translate-alist
)))
458 (let ((org-export-snippet-translation-alist nil
))
459 (should (equal (org-export-as 'test
) "A\n")))
460 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
461 (should (equal (org-export-as 'test
) "AB\n")))))))
467 (ert-deftest test-org-export
/footnotes
()
468 "Test footnotes specifications."
469 (let ((org-footnote-section nil
)
470 (org-export-with-footnotes t
))
471 ;; 1. Read every type of footnote.
474 '((1 .
"A\n") (2 .
"B") (3 .
"C") (4 .
"D"))
475 (org-test-with-parsed-data
476 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
478 tree
'footnote-reference
480 (let ((def (org-export-get-footnote-definition ref info
)))
481 (cons (org-export-get-footnote-number ref info
)
482 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
483 (car (org-element-contents
484 (car (org-element-contents def
))))))))
486 ;; 2. Test nested footnotes order.
487 (org-test-with-parsed-data
488 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
491 '((1 .
"fn:1") (2 .
"fn:2") (3 .
"fn:3") (4))
493 tree
'footnote-reference
495 (when (org-export-footnote-first-reference-p ref info
)
496 (cons (org-export-get-footnote-number ref info
)
497 (org-element-property :label ref
))))
499 ;; 3. Test nested footnote in invisible definitions.
500 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
502 (narrow-to-region (point) (point-at-eol))
503 (let* ((tree (org-element-parse-buffer))
504 (info (org-combine-plists
506 (org-export-collect-tree-properties
507 tree
(org-export-get-environment)))))
508 ;; Both footnotes should be seen.
510 (= (length (org-export-collect-footnote-definitions tree info
)) 2))))
511 ;; 4. Test footnotes definitions collection.
512 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
514 \[fn:2] B [fn:3] [fn::D].
517 (should (= (length (org-export-collect-footnote-definitions tree info
))
519 ;; 5. Test export of footnotes defined outside parsing scope.
520 (org-test-with-temp-text "[fn:1] Out of scope
523 (org-test-with-backend test
524 (let ((org-test-translate-alist
525 (cons (cons 'footnote-reference
526 (lambda (fn contents info
)
527 (org-element-interpret-data
528 (org-export-get-footnote-definition fn info
))))
529 org-test-translate-alist
)))
531 (should (equal "ParagraphOut of scope\n"
532 (org-export-as 'test
'subtree
))))))))
536 ;;; Headlines and Inlinetasks
538 (ert-deftest test-org-export
/get-relative-level
()
539 "Test `org-export-get-relative-level' specifications."
543 (let ((org-odd-levels-only nil
))
544 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
547 (lambda (h) (org-export-get-relative-level h info
))
552 (let ((org-odd-levels-only nil
))
553 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
556 (lambda (h) (org-export-get-relative-level h info
))
559 (ert-deftest test-org-export
/low-level-p
()
560 "Test `org-export-low-level-p' specifications."
564 (let ((org-odd-levels-only nil
))
565 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
568 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
569 (plist-put info
:headline-levels
1)))))))
571 (ert-deftest test-org-export
/get-headline-number
()
572 "Test `org-export-get-headline-number' specifications."
577 (let ((org-odd-levels-only nil
))
578 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
581 (lambda (h) (org-export-get-headline-number h info
))
583 ;; Missing levels are replaced with 0.
587 (let ((org-odd-levels-only nil
))
588 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
591 (lambda (h) (org-export-get-headline-number h info
))
594 (ert-deftest test-org-export
/numbered-headline-p
()
595 "Test `org-export-numbered-headline-p' specifications."
596 ;; If `:section-numbers' is nil, never number headlines.
598 (org-test-with-parsed-data "* Headline"
601 (lambda (h) (org-export-numbered-headline-p h info
))
602 (plist-put info
:section-numbers nil
))))
603 ;; If `:section-numbers' is a number, only number headlines with
604 ;; a level greater that it.
608 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
611 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
612 (plist-put info
:section-numbers
1)))))
613 ;; Otherwise, headlines are always numbered.
615 (org-test-with-parsed-data "* Headline"
618 (lambda (h) (org-export-numbered-headline-p h info
))
619 (plist-put info
:section-numbers t
)))))
621 (ert-deftest test-org-export
/number-to-roman
()
622 "Test `org-export-number-to-roman' specifications."
623 ;; If number is negative, return it as a string.
624 (should (equal (org-export-number-to-roman -
1) "-1"))
625 ;; Otherwise, return it as a roman number.
626 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
628 (ert-deftest test-org-export
/get-tags
()
629 "Test `org-export-get-tags' specifications."
630 (let ((org-export-exclude-tags '("noexport"))
631 (org-export-select-tags '("export")))
632 ;; Standard test: tags which are not a select tag, an exclude tag,
633 ;; or specified as optional argument shouldn't be ignored.
635 (org-test-with-parsed-data "* Headline :tag:"
636 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
638 ;; Exclude tags are removed.
640 (org-test-with-parsed-data "* Headline :noexport:"
641 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
643 ;; Select tags are removed.
645 (org-test-with-parsed-data "* Headline :export:"
646 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
651 (org-test-with-parsed-data "* Headline :tag:export:"
652 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
654 ;; Tags provided in the optional argument are also ignored.
656 (org-test-with-parsed-data "* Headline :ignore:"
657 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
658 info
'("ignore"))))))
660 (ert-deftest test-org-export
/first-sibling-p
()
661 "Test `org-export-first-sibling-p' specifications."
666 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
669 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
671 ;; Ignore headlines not exported.
675 (let ((org-export-exclude-tags '("ignore")))
676 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
679 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
682 (ert-deftest test-org-export
/last-sibling-p
()
683 "Test `org-export-last-sibling-p' specifications."
688 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
691 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
693 ;; Ignore headlines not exported.
697 (let ((org-export-exclude-tags '("ignore")))
698 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
701 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
708 (ert-deftest test-org-export
/get-coderef-format
()
709 "Test `org-export-get-coderef-format' specifications."
710 ;; A link without description returns "%s"
711 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
713 ;; Return "%s" when path is matched within description.
714 (should (equal (org-export-get-coderef-format "path" "desc (path)")
716 ;; Otherwise return description.
717 (should (equal (org-export-get-coderef-format "path" "desc")
720 (ert-deftest test-org-export
/inline-image-p
()
721 "Test `org-export-inline-image-p' specifications."
723 (org-export-inline-image-p
724 (org-test-with-temp-text "[[#id]]"
726 (org-element-parse-buffer) 'link
'identity nil t
))
727 '(("custom-id" .
"id")))))
729 (ert-deftest test-org-export
/fuzzy-link
()
730 "Test fuzzy links specifications."
731 ;; 1. Links to invisible (keyword) targets should be ignored.
732 (org-test-with-parsed-data
733 "Paragraph.\n#+TARGET: Test\n[[Test]]"
738 (org-export-get-ordinal
739 (org-export-resolve-fuzzy-link link info
) info
)) info
)))
740 ;; 2. Link to an headline should return headline's number.
741 (org-test-with-parsed-data
742 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
744 ;; Note: Headline's number is in fact a list of numbers.
749 (org-export-get-ordinal
750 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
751 ;; 3. Link to a target in an item should return item's number.
752 (org-test-with-parsed-data
753 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
755 ;; Note: Item's number is in fact a list of numbers.
760 (org-export-get-ordinal
761 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
762 ;; 4. Link to a target in a footnote should return footnote's
764 (org-test-with-parsed-data "
765 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
771 (org-export-get-ordinal
772 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
773 ;; 5. Link to a named element should return sequence number of that
775 (org-test-with-parsed-data
776 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
782 (org-export-get-ordinal
783 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
784 ;; 6. Link to a target not within an item, a table, a footnote
785 ;; reference or definition should return section number.
786 (org-test-with-parsed-data
787 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
793 (org-export-get-ordinal
794 (org-export-resolve-fuzzy-link link info
) info
)) info t
)))))
796 (ert-deftest test-org-export
/resolve-coderef
()
797 "Test `org-export-resolve-coderef' specifications."
798 (let ((org-coderef-label-format "(ref:%s)"))
799 ;; 1. A link to a "-n -k -r" block returns line number.
800 (org-test-with-parsed-data
801 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
802 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
803 (org-test-with-parsed-data
804 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
805 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
806 ;; 2. A link to a "-n -r" block returns line number.
807 (org-test-with-parsed-data
808 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
809 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
810 (org-test-with-parsed-data
811 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
812 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
813 ;; 3. A link to a "-n" block returns coderef.
814 (org-test-with-parsed-data
815 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
816 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
817 (org-test-with-parsed-data
818 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
819 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
820 ;; 4. A link to a "-r" block returns line number.
821 (org-test-with-parsed-data
822 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
823 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
824 (org-test-with-parsed-data
825 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
826 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
827 ;; 5. A link to a block without a switch returns coderef.
828 (org-test-with-parsed-data
829 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
830 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
831 (org-test-with-parsed-data
832 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
833 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
834 ;; 6. Correctly handle continued line numbers. A "+n" switch
835 ;; should resume numbering from previous block with numbered
836 ;; lines, ignoring blocks not numbering lines in the process.
837 ;; A "-n" switch resets count.
838 (org-test-with-parsed-data "
843 #+BEGIN_SRC emacs-lisp
847 #+BEGIN_SRC emacs-lisp +n -r
848 \(+ 1 1) (ref:addition)
851 #+BEGIN_EXAMPLE -n -r
852 Another text. (ref:text)
854 (should (= (org-export-resolve-coderef "addition" info
) 2))
855 (should (= (org-export-resolve-coderef "text" info
) 1)))
856 ;; 7. Recognize coderef with user-specified syntax.
857 (org-test-with-parsed-data
858 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
859 (should (equal (org-export-resolve-coderef "text" info
) "text")))))
861 (ert-deftest test-org-export
/resolve-fuzzy-link
()
862 "Test `org-export-resolve-fuzzy-link' specifications."
863 ;; 1. Match target objects.
864 (org-test-with-parsed-data "<<target>> [[target]]"
866 (org-export-resolve-fuzzy-link
867 (org-element-map tree
'link
'identity info t
) info
)))
868 ;; 2. Match target elements.
869 (org-test-with-parsed-data "#+TARGET: target\n[[target]]"
871 (org-export-resolve-fuzzy-link
872 (org-element-map tree
'link
'identity info t
) info
)))
873 ;; 3. Match named elements.
874 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
876 (org-export-resolve-fuzzy-link
877 (org-element-map tree
'link
'identity info t
) info
)))
878 ;; 4. Match exact headline's name.
879 (org-test-with-parsed-data "* My headline\n[[My headline]]"
881 (org-export-resolve-fuzzy-link
882 (org-element-map tree
'link
'identity info t
) info
)))
883 ;; 5. Targets objects have priority over named elements and headline
885 (org-test-with-parsed-data
886 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
890 (org-export-resolve-fuzzy-link
891 (org-element-map tree
'link
'identity info t
) info
)))))
892 ;; 6. Named elements have priority over headline titles.
893 (org-test-with-parsed-data
894 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
898 (org-export-resolve-fuzzy-link
899 (org-element-map tree
'link
'identity info t
) info
)))))
900 ;; 7. If link's path starts with a "*", only match headline titles,
902 (org-test-with-parsed-data
903 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
907 (org-export-resolve-fuzzy-link
908 (org-element-map tree
'link
'identity info t
) info
)))))
909 ;; 8. Return nil if no match.
910 (org-test-with-parsed-data "[[target]]"
912 (org-export-resolve-fuzzy-link
913 (org-element-map tree
'link
'identity info t
) info
))))
915 (ert-deftest test-org-export
/resolve-id-link
()
916 "Test `org-export-resolve-id-link' specifications."
917 ;; 1. Regular test for custom-id link.
918 (org-test-with-parsed-data "* Headline1
925 (org-export-resolve-id-link
926 (org-element-map tree
'link
'identity info t
) info
)))
927 ;; 2. Failing test for custom-id link.
928 (org-test-with-parsed-data "* Headline1
935 (org-export-resolve-id-link
936 (org-element-map tree
'link
'identity info t
) info
)))
937 ;; 3. Test for internal id target.
938 (org-test-with-parsed-data "* Headline1
945 (org-export-resolve-id-link
946 (org-element-map tree
'link
'identity info t
) info
)))
947 ;; 4. Test for external id target.
948 (org-test-with-parsed-data "[[id:aaaa]]"
950 (org-export-resolve-id-link
951 (org-element-map tree
'link
'identity info t
)
952 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file"))))))))
954 (ert-deftest test-org-export
/resolve-radio-link
()
955 "Test `org-export-resolve-radio-link' specifications."
957 (org-test-with-temp-text "<<<radio>>> radio"
958 (org-update-radio-target-regexp)
960 (let* ((tree (org-element-parse-buffer))
961 (info `(:parse-tree
,tree
)))
962 (org-export-resolve-radio-link
963 (org-element-map tree
'link
'identity info t
)
965 ;; Radio target with objects.
966 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
967 (org-update-radio-target-regexp)
969 (let* ((tree (org-element-parse-buffer))
970 (info `(:parse-tree
,tree
)))
971 (org-export-resolve-radio-link
972 (org-element-map tree
'link
'identity info t
)
979 (ert-deftest test-org-export
/define-macro
()
980 "Try defining various Org macro using in-buffer #+MACRO: keyword."
982 (should (equal (org-test-with-temp-text "#+MACRO: one 1"
983 (org-export--get-inbuffer-options))
984 '(:macro-one
("1"))))
986 (should (equal (org-test-with-temp-text "#+MACRO: two (eval (+ 1 1))"
987 (org-export--get-inbuffer-options))
988 '(:macro-two
("(eval (+ 1 1))"))))
990 (should-not (org-test-with-temp-text "#+MACRO: three"
991 (org-export--get-inbuffer-options)))
992 ;; Macro with newline character.
993 (should (equal (org-test-with-temp-text "#+MACRO: four a\\nb"
994 (org-export--get-inbuffer-options))
995 '(:macro-four
("a\nb"))))
996 ;; Macro with protected newline character.
997 (should (equal (org-test-with-temp-text "#+MACRO: five a\\\\nb"
998 (org-export--get-inbuffer-options))
999 '(:macro-five
("a\\nb"))))
1001 (org-test-with-temp-text "#+MACRO: six 6\n#+MACRO: seven 1 + {{{six}}}"
1004 (org-export--get-inbuffer-options)
1008 ("1 + " (macro (:key
"six" :value
"{{{six}}}" :args nil
:begin
5 :end
14
1009 :post-blank
0 :parent nil
))))))))
1011 (ert-deftest test-org-export
/expand-macro
()
1012 "Test `org-export-expand-macro' specifications."
1017 (org-test-with-parsed-data "#+MACRO: macro some text\n{{{macro}}}"
1018 (org-export-expand-macro
1019 (org-element-map tree
'macro
'identity info t
) info
))))
1020 ;; Macro with arguments.
1024 (org-test-with-parsed-data "#+MACRO: macro $1 $2\n{{{macro(some,text)}}}"
1025 (org-export-expand-macro
1026 (org-element-map tree
'macro
'identity info t
) info
))))
1027 ;; Macro with "eval"
1031 (org-test-with-parsed-data "#+MACRO: add (eval (+ $1 $2))\n{{{add(1,2)}}}"
1032 (org-export-expand-macro
1033 (org-element-map tree
'macro
'identity info t
) info
))))
1038 (org-test-with-parsed-data
1039 "#+MACRO: in inner\n#+MACRO: out {{{in}}} outer\n{{{out}}}"
1040 (flet ((translate-macro (macro contents info
)
1041 (org-export-expand-macro macro info
)))
1042 (org-export-expand-macro
1043 (org-element-map tree
'macro
'identity info t
)
1045 info
`(:translate-alist
((macro . translate-macro
))))))))))
1049 ;;; Src-block and example-block
1051 (ert-deftest test-org-export
/unravel-code
()
1052 "Test `org-export-unravel-code' function."
1053 (let ((org-coderef-label-format "(ref:%s)"))
1054 ;; 1. Code without reference.
1055 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
1056 (should (equal (org-export-unravel-code (org-element-at-point))
1058 ;; 2. Code with reference.
1059 (org-test-with-temp-text
1060 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
1061 (should (equal (org-export-unravel-code (org-element-at-point))
1062 '("(+ 1 1)\n" (1 .
"test")))))
1063 ;; 3. Code with user-defined reference.
1064 (org-test-with-temp-text
1065 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
1066 (should (equal (org-export-unravel-code (org-element-at-point))
1067 '("(+ 1 1)\n" (1 .
"test")))))
1068 ;; 4. Code references keys are relative to the current block.
1069 (org-test-with-temp-text "
1078 (should (equal (org-export-unravel-code (org-element-at-point))
1079 '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one")))))))
1085 (ert-deftest test-org-export
/special-column
()
1086 "Test if the table's special column is properly recognized."
1087 ;; 1. First column is special if it contains only a special marking
1088 ;; characters or empty cells.
1089 (org-test-with-temp-text "
1093 (org-export-table-has-special-column-p
1095 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1096 ;; 2. If the column contains anything else, it isn't special.
1097 (org-test-with-temp-text "
1101 (org-export-table-has-special-column-p
1103 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1104 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
1106 (org-test-with-temp-text "
1115 (org-export-table-has-special-column-p
1117 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1118 ;; 4. A first column with only empty cells isn't considered as
1120 (org-test-with-temp-text "
1124 (org-export-table-has-special-column-p
1126 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
1128 (ert-deftest test-org-export
/table-row-is-special-p
()
1129 "Test `org-export-table-row-is-special-p' specifications."
1130 ;; 1. A row is special if it has a special marking character in the
1132 (org-test-with-parsed-data "| ! | 1 |"
1134 (org-export-table-row-is-special-p
1135 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1136 ;; 2. A row is special when its first field is "/"
1137 (org-test-with-parsed-data "
1141 (org-export-table-row-is-special-p
1142 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1143 ;; 3. A row only containing alignment cookies is also considered as
1145 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
1147 (org-export-table-row-is-special-p
1148 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1149 ;; 4. Everything else isn't considered as special.
1150 (org-test-with-parsed-data "| \alpha | | c |"
1152 (org-export-table-row-is-special-p
1153 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1154 ;; 5. Table's rules are never considered as special rows.
1155 (org-test-with-parsed-data "|---+---|"
1157 (org-export-table-row-is-special-p
1158 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
1160 (ert-deftest test-org-export
/has-header-p
()
1161 "Test `org-export-table-has-header-p' specifications."
1162 ;; 1. With an header.
1163 (org-test-with-parsed-data "
1168 (org-export-table-has-header-p
1169 (org-element-map tree
'table
'identity info
'first-match
)
1171 ;; 2. Without an header.
1172 (org-test-with-parsed-data "
1176 (org-export-table-has-header-p
1177 (org-element-map tree
'table
'identity info
'first-match
)
1179 ;; 3. Don't get fooled with starting and ending rules.
1180 (org-test-with-parsed-data "
1186 (org-export-table-has-header-p
1187 (org-element-map tree
'table
'identity info
'first-match
)
1190 (ert-deftest test-org-export
/table-row-group
()
1191 "Test `org-export-table-row-group' specifications."
1192 ;; 1. A rule creates a new group.
1193 (org-test-with-parsed-data "
1200 (mapcar (lambda (row) (org-export-table-row-group row info
))
1201 (org-element-map tree
'table-row
'identity
)))))
1202 ;; 2. Special rows are ignored in count.
1203 (org-test-with-parsed-data "
1210 (mapcar (lambda (row) (org-export-table-row-group row info
))
1211 (org-element-map tree
'table-row
'identity
)))))
1212 ;; 3. Double rules also are ignored in count.
1213 (org-test-with-parsed-data "
1221 (mapcar (lambda (row) (org-export-table-row-group row info
))
1222 (org-element-map tree
'table-row
'identity
))))))
1224 (ert-deftest test-org-export
/table-cell-width
()
1225 "Test `org-export-table-cell-width' specifications."
1226 ;; 1. Width is primarily determined by width cookies. If no cookie
1227 ;; is found, cell's width is nil.
1228 (org-test-with-parsed-data "
1229 | / | <l> | <6> | <l7> |
1234 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1235 (org-element-map tree
'table-cell
'identity info
)))))
1236 ;; 2. The last width cookie has precedence.
1237 (org-test-with-parsed-data "
1244 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1245 (org-element-map tree
'table-cell
'identity info
)))))
1246 ;; 3. Valid width cookies must have a specific row.
1247 (org-test-with-parsed-data "| <6> | cell |"
1251 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1252 (org-element-map tree
'table-cell
'identity
))))))
1254 (ert-deftest test-org-export
/table-cell-alignment
()
1255 "Test `org-export-table-cell-alignment' specifications."
1256 (let ((org-table-number-fraction 0.5)
1257 (org-table-number-regexp "^[0-9]+$"))
1258 ;; 1. Alignment is primarily determined by alignment cookies.
1259 (org-test-with-temp-text "| <l> | <c> | <r> |"
1260 (let* ((tree (org-element-parse-buffer))
1261 (info `(:parse-tree
,tree
)))
1264 '(left center right
)
1265 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1266 (org-element-map tree
'table-cell
'identity
))))))
1267 ;; 2. The last alignment cookie has precedence.
1268 (org-test-with-parsed-data "
1274 '(right right right
)
1275 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1276 (org-element-map tree
'table-cell
'identity
)))))
1277 ;; 3. If there's no cookie, cell's contents determine alignment.
1278 ;; A column mostly made of cells containing numbers will align
1279 ;; its cells to the right.
1280 (org-test-with-parsed-data "
1286 '(right right right
)
1287 (mapcar (lambda (cell)
1288 (org-export-table-cell-alignment cell info
))
1289 (org-element-map tree
'table-cell
'identity
)))))
1290 ;; 4. Otherwise, they will be aligned to the left.
1291 (org-test-with-parsed-data "
1298 (mapcar (lambda (cell)
1299 (org-export-table-cell-alignment cell info
))
1300 (org-element-map tree
'table-cell
'identity
)))))))
1302 (ert-deftest test-org-export
/table-cell-borders
()
1303 "Test `org-export-table-cell-borders' specifications."
1304 ;; 1. Recognize various column groups indicators.
1305 (org-test-with-parsed-data "| / | < | > | <> |"
1308 '((right bottom top
) (left bottom top
) (right bottom top
)
1309 (right left bottom top
))
1310 (mapcar (lambda (cell)
1311 (org-export-table-cell-borders cell info
))
1312 (org-element-map tree
'table-cell
'identity
)))))
1313 ;; 2. Accept shortcuts to define column groups.
1314 (org-test-with-parsed-data "| / | < | < |"
1317 '((right bottom top
) (right left bottom top
) (left bottom top
))
1318 (mapcar (lambda (cell)
1319 (org-export-table-cell-borders cell info
))
1320 (org-element-map tree
'table-cell
'identity
)))))
1321 ;; 3. A valid column groups row must start with a "/".
1322 (org-test-with-parsed-data "
1326 (equal '((top) (top) (bottom) (bottom))
1327 (mapcar (lambda (cell)
1328 (org-export-table-cell-borders cell info
))
1329 (org-element-map tree
'table-cell
'identity
)))))
1330 ;; 4. Take table rules into consideration.
1331 (org-test-with-parsed-data "
1336 (equal '((below top
) (bottom above
))
1337 (mapcar (lambda (cell)
1338 (org-export-table-cell-borders cell info
))
1339 (org-element-map tree
'table-cell
'identity
)))))
1340 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
1341 ;; (resp. `bottom' and `below') borders. Any special row is
1343 (org-test-with-parsed-data "
1349 (equal '((bottom below top above
))
1351 (mapcar (lambda (cell)
1352 (org-export-table-cell-borders cell info
))
1353 (org-element-map tree
'table-cell
'identity
)))))))
1355 (ert-deftest test-org-export
/table-dimensions
()
1356 "Test `org-export-table-dimensions' specifications."
1357 ;; 1. Standard test.
1358 (org-test-with-parsed-data "
1363 (org-export-table-dimensions
1364 (org-element-map tree
'table
'identity info
'first-match
) info
))))
1365 ;; 2. Ignore horizontal rules and special columns.
1366 (org-test-with-parsed-data "
1373 (org-export-table-dimensions
1374 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
1376 (ert-deftest test-org-export
/table-cell-address
()
1377 "Test `org-export-table-cell-address' specifications."
1378 ;; 1. Standard test: index is 0-based.
1379 (org-test-with-parsed-data "| a | b |"
1381 (equal '((0 .
0) (0 .
1))
1384 (lambda (cell) (org-export-table-cell-address cell info
))
1386 ;; 2. Special column isn't counted, nor are special rows.
1387 (org-test-with-parsed-data "
1392 (org-export-table-cell-address
1393 (car (last (org-element-map tree
'table-cell
'identity info
)))
1395 ;; 3. Tables rules do not count either.
1396 (org-test-with-parsed-data "
1404 (org-export-table-cell-address
1405 (car (last (org-element-map tree
'table-cell
'identity info
)))
1407 ;; 4. Return nil for special cells.
1408 (org-test-with-parsed-data "| / | a |"
1410 (org-export-table-cell-address
1411 (org-element-map tree
'table-cell
'identity nil
'first-match
)
1414 (ert-deftest test-org-export
/get-table-cell-at
()
1415 "Test `org-export-get-table-cell-at' specifications."
1416 ;; 1. Address ignores special columns, special rows and rules.
1417 (org-test-with-parsed-data "
1424 (org-element-contents
1425 (org-export-get-table-cell-at
1427 (org-element-map tree
'table
'identity info
'first-match
)
1429 ;; 2. Return value for a non-existent address is nil.
1430 (org-test-with-parsed-data "| a |"
1432 (org-export-get-table-cell-at
1434 (org-element-map tree
'table
'identity info
'first-match
)
1436 (org-test-with-parsed-data "| / |"
1438 (org-export-get-table-cell-at
1440 (org-element-map tree
'table
'identity info
'first-match
)
1443 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
1444 "Test `org-export-table-cell-starts-colgroup-p' specifications."
1445 ;; 1. A cell at a beginning of a row always starts a column group.
1446 (org-test-with-parsed-data "| a |"
1448 (org-export-table-cell-starts-colgroup-p
1449 (org-element-map tree
'table-cell
'identity info
'first-match
)
1451 ;; 2. Special column should be ignored when determining the
1452 ;; beginning of the row.
1453 (org-test-with-parsed-data "
1457 (org-export-table-cell-starts-colgroup-p
1458 (org-element-map tree
'table-cell
'identity info
'first-match
)
1460 ;; 2. Explicit column groups.
1461 (org-test-with-parsed-data "
1470 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
1473 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
1474 "Test `org-export-table-cell-ends-colgroup-p' specifications."
1475 ;; 1. A cell at the end of a row always ends a column group.
1476 (org-test-with-parsed-data "| a |"
1478 (org-export-table-cell-ends-colgroup-p
1479 (org-element-map tree
'table-cell
'identity info
'first-match
)
1481 ;; 2. Special column should be ignored when determining the
1482 ;; beginning of the row.
1483 (org-test-with-parsed-data "
1487 (org-export-table-cell-ends-colgroup-p
1488 (org-element-map tree
'table-cell
'identity info
'first-match
)
1490 ;; 3. Explicit column groups.
1491 (org-test-with-parsed-data "
1500 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
1503 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
1504 "Test `org-export-table-row-starts-rowgroup-p' specifications."
1505 ;; 1. A row at the beginning of a table always starts a row group.
1506 ;; So does a row following a table rule.
1507 (org-test-with-parsed-data "
1517 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
1519 ;; 2. Special rows should be ignored when determining the beginning
1521 (org-test-with-parsed-data "
1533 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
1536 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
1537 "Test `org-export-table-row-ends-rowgroup-p' specifications."
1538 ;; 1. A row at the end of a table always ends a row group. So does
1539 ;; a row preceding a table rule.
1540 (org-test-with-parsed-data "
1550 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
1552 ;; 2. Special rows should be ignored when determining the beginning
1554 (org-test-with-parsed-data "
1566 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
1569 (ert-deftest test-org-export
/table-row-starts-header-p
()
1570 "Test `org-export-table-row-starts-header-p' specifications."
1571 ;; 1. Only the row starting the first row group starts the table
1573 (org-test-with-parsed-data "
1584 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
1586 ;; 2. A row cannot start an header if there's no header in the
1588 (org-test-with-parsed-data "
1592 (org-export-table-row-starts-header-p
1593 (org-element-map tree
'table-row
'identity info
'first-match
)
1596 (ert-deftest test-org-export
/table-row-ends-header-p
()
1597 "Test `org-export-table-row-ends-header-p' specifications."
1598 ;; 1. Only the row starting the first row group starts the table
1600 (org-test-with-parsed-data "
1611 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
1613 ;; 2. A row cannot start an header if there's no header in the
1615 (org-test-with-parsed-data "
1619 (org-export-table-row-ends-header-p
1620 (org-element-map tree
'table-row
'identity info
'first-match
)
1627 (ert-deftest test-org-export
/get-next-element
()
1628 "Test `org-export-get-next-element' specifications."
1632 (org-test-with-parsed-data "* Headline\n*a* b"
1633 (org-export-get-next-element
1634 (org-element-map tree
'bold
'identity info t
) info
))))
1635 ;; Return nil when no previous element.
1637 (org-test-with-parsed-data "* Headline\na *b*"
1638 (org-export-get-next-element
1639 (org-element-map tree
'bold
'identity info t
) info
)))
1640 ;; Non-exportable elements are ignored.
1642 (let ((org-export-with-timestamps nil
))
1643 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
1644 (org-export-get-next-element
1645 (org-element-map tree
'entity
'identity info t
) info
)))))
1647 (ert-deftest test-org-export
/get-previous-element
()
1648 "Test `org-export-get-previous-element' specifications."
1652 (org-test-with-parsed-data "* Headline\na *b*"
1653 (org-export-get-previous-element
1654 (org-element-map tree
'bold
'identity info t
) info
))))
1655 ;; Return nil when no previous element.
1657 (org-test-with-parsed-data "* Headline\n*a* b"
1658 (org-export-get-previous-element
1659 (org-element-map tree
'bold
'identity info t
) info
)))
1660 ;; Non-exportable elements are ignored.
1662 (let ((org-export-with-timestamps nil
))
1663 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
1664 (org-export-get-previous-element
1665 (org-element-map tree
'entity
'identity info t
) info
)))))
1668 (provide 'test-org-export
)
1669 ;;; test-org-export.el end here