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)
91 (boundp 'variable
)))))
93 (ert-deftest test-org-export
/parse-option-keyword
()
94 "Test reading all standard #+OPTIONS: items."
97 (org-export--parse-option-keyword
98 "H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t
99 *:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t inline:nil
102 1 :preserve-breaks t
:section-numbers t
:time-stamp-file t
103 :with-archived-trees t
:with-author t
:with-creator t
:with-drawers t
104 :with-email t
:with-emphasize t
:with-entities t
:with-fixed-width t
105 :with-footnotes t
:with-inlinetasks nil
:with-priority t
106 :with-special-strings t
:with-statistics-cookies t
:with-sub-superscript t
107 :with-toc t
:with-tables t
:with-tags t
:with-tasks t
:with-timestamps t
108 :with-todo-keywords t
)))
109 ;; Test some special values.
112 (org-export--parse-option-keyword
113 "arch:headline creator:comment d:(\"TEST\")
114 ^:{} toc:1 tags:not-in-toc tasks:todo num:2 <:active")
117 :with-archived-trees headline
:with-creator comment
118 :with-drawers
("TEST") :with-sub-superscript
{} :with-toc
1
119 :with-tags not-in-toc
:with-tasks todo
:with-timestamps active
))))
121 (ert-deftest test-org-export
/get-inbuffer-options
()
122 "Test reading all standard export keywords."
125 (org-test-with-temp-text "#+AUTHOR: Me, Myself and I
128 #+DESCRIPTION: Testing
129 #+DESCRIPTION: with two lines
130 #+EMAIL: some@email.org
131 #+EXCLUDE_TAGS: noexport invisible
134 #+SELECT_TAGS: export
136 #+TITLE: with spaces"
137 (org-export--get-inbuffer-options))
139 ("Me, Myself and I") :creator
"Idem" :date
("Today")
140 :description
"Testing\nwith two lines" :email
"some@email.org"
141 :exclude-tags
("noexport" "invisible") :keywords
"test" :language
"en"
142 :select-tags
("export") :title
("Some title with spaces")))))
144 (ert-deftest test-org-export
/get-subtree-options
()
145 "Test setting options from headline's properties."
147 (org-test-with-temp-text "#+TITLE: Title
150 :EXPORT_TITLE: Subtree Title
154 (should (equal (plist-get (org-export-get-environment nil t
) :title
)
155 '("Subtree Title"))))
159 (org-test-with-temp-text "#+OPTIONS: H:1
167 (= 2 (plist-get (org-export-get-environment nil t
) :headline-levels
))))
169 (org-test-with-temp-text "#+DATE: today
172 :EXPORT_DATE: 29-03-2012
176 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
178 ;; Export properties are case-insensitive.
179 (org-test-with-temp-text "* Headline
181 :EXPORT_Date: 29-03-2012
184 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
187 (ert-deftest test-org-export
/handle-options
()
188 "Test if export options have an impact on output."
189 ;; Test exclude tags.
190 (org-test-with-temp-text "* Head1 :noexport:"
191 (org-test-with-backend test
193 (equal (org-export-as 'test nil nil nil
'(:exclude-tags
("noexport")))
195 ;; Test include tags.
196 (org-test-with-temp-text "
199 ** Sub-Head2.1 :export:
202 (org-test-with-backend test
205 "* Head2\n** Sub-Head2.1 :export:\n*** Sub-Head2.1.1\n"
206 (let ((org-tags-column 0))
207 (org-export-as 'test nil nil nil
'(:select-tags
("export"))))))))
208 ;; Test mixing include tags and exclude tags.
209 (org-test-with-temp-text "
211 ** Sub-Head1 :noexport:
214 ** Sub-Head1 :export:"
215 (org-test-with-backend test
218 "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
221 '(:select-tags
("export") :exclude-tags
("noexport")))))))
223 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
224 (org-test-with-temp-text "* TODO Head1"
225 (org-test-with-backend test
226 (should (equal (org-export-as 'test nil nil nil
'(:with-tasks nil
))
228 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
229 (org-test-with-temp-text "* TODO Head1"
230 (org-test-with-backend test
231 (should (equal (org-export-as 'test nil nil nil
'(:with-tasks t
))
232 "* TODO Head1\n")))))
234 (org-test-with-temp-text "* Head1 :archive:"
235 (let ((org-archive-tag "archive"))
236 (org-test-with-backend test
238 (equal (org-export-as 'test nil nil nil
'(:with-archived-trees nil
))
240 (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
241 (let ((org-archive-tag "archive"))
242 (org-test-with-backend test
245 "\\* Head1[ \t]+:archive:"
246 (org-export-as 'test nil nil nil
247 '(:with-archived-trees headline
)))))))
248 (org-test-with-temp-text "* Head1 :archive:"
249 (let ((org-archive-tag "archive"))
250 (org-test-with-backend test
253 "\\`\\* Head1[ \t]+:archive:\n\\'"
254 (org-export-as 'test nil nil nil
'(:with-archived-trees t
)))))))
256 (let ((org-drawers '("TEST")))
257 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
258 (org-test-with-backend test
259 (should (equal (org-export-as 'test nil nil nil
'(:with-drawers nil
))
261 (should (equal (org-export-as 'test nil nil nil
'(:with-drawers t
))
262 ":TEST:\ncontents\n:END:\n")))))
263 (let ((org-drawers '("FOO" "BAR")))
264 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
265 (org-test-with-backend test
267 (equal (org-export-as 'test nil nil nil
'(:with-drawers
("FOO")))
268 ":FOO:\nkeep\n:END:\n")))))
270 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
271 (org-test-with-backend test
273 (equal (org-export-as 'test nil nil nil
'(:with-timestamps t
))
274 "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>\n"))
276 (equal (org-export-as 'test nil nil nil
'(:with-timestamps nil
)) ""))
278 (equal (org-export-as 'test nil nil nil
'(:with-timestamps active
))
279 "<2012-04-29 sun. 10:45>\n"))
281 (equal (org-export-as 'test nil nil nil
'(:with-timestamps inactive
))
282 "[2012-04-29 sun. 10:45]\n"))))
284 (let ((org-clock-string "CLOCK:"))
285 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
286 (org-test-with-backend test
288 (equal (org-export-as 'test nil nil nil
'(:with-clocks t
))
289 "CLOCK: [2012-04-29 sun. 10:45]\n"))
291 (equal (org-export-as 'test nil nil nil
'(:with-clocks nil
)) "")))))
293 (let ((org-closed-string "CLOSED:"))
294 (org-test-with-temp-text "CLOSED: [2012-04-29 sun. 10:45]"
295 (org-test-with-backend test
297 (equal (org-export-as 'test nil nil nil
'(:with-plannings t
))
298 "CLOSED: [2012-04-29 sun. 10:45]\n"))
300 (equal (org-export-as 'test nil nil nil
'(:with-plannings nil
))
303 (when (featurep 'org-inlinetask
)
306 (let ((org-inlinetask-min-level 15))
307 (org-test-with-temp-text "*************** Task"
308 (org-test-with-backend test
309 (org-export-as 'test nil nil nil
'(:with-inlinetasks nil
)))))
313 (let ((org-inlinetask-min-level 15))
314 (org-test-with-temp-text
315 "*************** Task\nContents\n*************** END"
316 (org-test-with-backend test
317 (org-export-as 'test nil nil nil
'(:with-inlinetasks nil
)))))
319 ;; Statistics cookies.
322 (org-test-with-temp-text "[0/0]"
323 (org-test-with-backend test
325 'test nil nil nil
'(:with-statistics-cookies nil
)))))))
327 (ert-deftest test-org-export
/comment-tree
()
328 "Test if export process ignores commented trees."
329 (let ((org-comment-string "COMMENT"))
330 (org-test-with-temp-text "* COMMENT Head1"
331 (org-test-with-backend test
332 (should (equal (org-export-as 'test
) ""))))))
334 (ert-deftest test-org-export
/export-scope
()
335 "Test all export scopes."
336 (org-test-with-temp-text "
341 (org-test-with-backend test
344 (should (equal (org-export-as 'test
'subtree
) "text\n*** Head3\n"))
346 (goto-char (point-min))
349 (should (equal (org-export-as 'test nil
'visible
) "* Head1\n"))
351 (flet ((org-test-template (body info
) (format "BEGIN\n%sEND" body
)))
352 (push '(template . org-test-template
) org-test-translate-alist
)
353 (should (equal (org-export-as 'test nil nil
'body-only
)
354 "* Head1\n** Head2\ntext\n*** Head3\n"))
355 (should (equal (org-export-as 'test
)
356 "BEGIN\n* Head1\n** Head2\ntext\n*** Head3\nEND")))
358 (goto-char (point-min))
360 (transient-mark-mode 1)
361 (push-mark (point) t t
)
362 (goto-char (point-at-eol))
363 (should (equal (org-export-as 'test
) "text\n"))))
364 ;; Subtree with a code block calling another block outside.
365 (org-test-with-temp-text "
367 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
372 #+BEGIN_SRC emacs-lisp
375 (org-test-with-backend test
377 (should (equal (org-export-as 'test
'subtree
) ": 3\n")))))
379 (ert-deftest test-org-export
/expand-include
()
380 "Test file inclusion in an Org buffer."
381 ;; Full insertion with recursive inclusion.
382 (org-test-with-temp-text
383 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir
)
384 (org-export-expand-include-keyword)
385 (should (equal (buffer-string)
386 "Small Org file with an include keyword.
388 #+BEGIN_SRC emacs-lisp :exports results\n(+ 2 1)\n#+END_SRC
394 ;; Localized insertion.
395 (org-test-with-temp-text
396 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
398 (org-export-expand-include-keyword)
399 (should (equal (buffer-string)
400 "Small Org file with an include keyword.\n")))
401 ;; Insertion with constraints on headlines level.
402 (org-test-with-temp-text
404 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\""
406 (org-export-expand-include-keyword)
407 (should (equal (buffer-string) "* Top heading\n** Heading\nbody\n")))
408 ;; Inclusion within an example block.
409 (org-test-with-temp-text
410 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" example"
412 (org-export-expand-include-keyword)
416 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n")))
417 ;; Inclusion within a src-block.
418 (org-test-with-temp-text
420 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" src emacs-lisp"
422 (org-export-expand-include-keyword)
423 (should (equal (buffer-string)
424 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"))))
426 (ert-deftest test-org-export
/user-ignore-list
()
427 "Test if `:ignore-list' accepts user input."
428 (org-test-with-backend test
429 (flet ((skip-note-head
431 ;; Ignore headlines with the word "note" in their title.
435 (when (string-match "\\<note\\>"
436 (org-element-property :raw-value headline
))
437 (org-export-ignore-element headline info
)))
440 ;; Install function in parse tree filters.
441 (let ((org-export-filter-parse-tree-functions '(skip-note-head)))
442 (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
443 (should (equal (org-export-as 'test
) "* Head1\n")))))))
445 (ert-deftest test-org-export
/before-parsing-hook
()
446 "Test `org-export-before-parsing-hook'."
447 (org-test-with-backend test
448 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
449 (let ((org-export-before-parsing-hook
453 (delete-region (point) (progn (forward-line) (point)))))))))
454 (should (equal (org-export-as 'test
) "Body 1\nBody 2\n"))))))
458 ;;; Affiliated Keywords
460 (ert-deftest test-org-export
/read-attribute
()
461 "Test `org-export-read-attribute' specifications."
465 (org-export-read-attribute
467 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
468 (org-element-at-point)))
470 ;; Return nil on empty attribute.
472 (org-export-read-attribute
474 (org-test-with-temp-text "Paragraph" (org-element-at-point)))))
480 (ert-deftest test-org-export
/export-snippet
()
481 "Test export snippets transcoding."
482 (org-test-with-temp-text "@@test:A@@@@t:B@@"
483 (org-test-with-backend test
484 (let ((org-test-translate-alist
485 (cons (cons 'export-snippet
486 (lambda (snippet contents info
)
487 (when (eq (org-export-snippet-backend snippet
) 'test
)
488 (org-element-property :value snippet
))))
489 org-test-translate-alist
)))
490 (let ((org-export-snippet-translation-alist nil
))
491 (should (equal (org-export-as 'test
) "A\n")))
492 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
493 (should (equal (org-export-as 'test
) "AB\n")))))))
499 (ert-deftest test-org-export
/footnotes
()
500 "Test footnotes specifications."
501 (let ((org-footnote-section nil
)
502 (org-export-with-footnotes t
))
503 ;; 1. Read every type of footnote.
506 '((1 .
"A\n") (2 .
"B") (3 .
"C") (4 .
"D"))
507 (org-test-with-parsed-data
508 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
510 tree
'footnote-reference
512 (let ((def (org-export-get-footnote-definition ref info
)))
513 (cons (org-export-get-footnote-number ref info
)
514 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
515 (car (org-element-contents
516 (car (org-element-contents def
))))))))
518 ;; 2. Test nested footnotes order.
519 (org-test-with-parsed-data
520 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
523 '((1 .
"fn:1") (2 .
"fn:2") (3 .
"fn:3") (4))
525 tree
'footnote-reference
527 (when (org-export-footnote-first-reference-p ref info
)
528 (cons (org-export-get-footnote-number ref info
)
529 (org-element-property :label ref
))))
531 ;; 3. Test nested footnote in invisible definitions.
532 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
534 (narrow-to-region (point) (point-at-eol))
535 (let* ((tree (org-element-parse-buffer))
536 (info (org-combine-plists
538 (org-export-collect-tree-properties
539 tree
(org-export-get-environment)))))
540 ;; Both footnotes should be seen.
542 (= (length (org-export-collect-footnote-definitions tree info
)) 2))))
543 ;; 4. Test footnotes definitions collection.
544 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
546 \[fn:2] B [fn:3] [fn::D].
549 (should (= (length (org-export-collect-footnote-definitions tree info
))
551 ;; 5. Test export of footnotes defined outside parsing scope.
552 (org-test-with-temp-text "[fn:1] Out of scope
555 (org-test-with-backend test
556 (let ((org-test-translate-alist
557 (cons (cons 'footnote-reference
558 (lambda (fn contents info
)
559 (org-element-interpret-data
560 (org-export-get-footnote-definition fn info
))))
561 org-test-translate-alist
)))
563 (should (equal "ParagraphOut of scope\n"
564 (org-export-as 'test
'subtree
))))))))
568 ;;; Headlines and Inlinetasks
570 (ert-deftest test-org-export
/get-relative-level
()
571 "Test `org-export-get-relative-level' specifications."
575 (let ((org-odd-levels-only nil
))
576 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
579 (lambda (h) (org-export-get-relative-level h info
))
584 (let ((org-odd-levels-only nil
))
585 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
588 (lambda (h) (org-export-get-relative-level h info
))
591 (ert-deftest test-org-export
/low-level-p
()
592 "Test `org-export-low-level-p' specifications."
596 (let ((org-odd-levels-only nil
))
597 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
600 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
601 (plist-put info
:headline-levels
1)))))))
603 (ert-deftest test-org-export
/get-headline-number
()
604 "Test `org-export-get-headline-number' specifications."
609 (let ((org-odd-levels-only nil
))
610 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
613 (lambda (h) (org-export-get-headline-number h info
))
615 ;; Missing levels are replaced with 0.
619 (let ((org-odd-levels-only nil
))
620 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
623 (lambda (h) (org-export-get-headline-number h info
))
626 (ert-deftest test-org-export
/numbered-headline-p
()
627 "Test `org-export-numbered-headline-p' specifications."
628 ;; If `:section-numbers' is nil, never number headlines.
630 (org-test-with-parsed-data "* Headline"
633 (lambda (h) (org-export-numbered-headline-p h info
))
634 (plist-put info
:section-numbers nil
))))
635 ;; If `:section-numbers' is a number, only number headlines with
636 ;; a level greater that it.
640 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
643 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
644 (plist-put info
:section-numbers
1)))))
645 ;; Otherwise, headlines are always numbered.
647 (org-test-with-parsed-data "* Headline"
650 (lambda (h) (org-export-numbered-headline-p h info
))
651 (plist-put info
:section-numbers t
)))))
653 (ert-deftest test-org-export
/number-to-roman
()
654 "Test `org-export-number-to-roman' specifications."
655 ;; If number is negative, return it as a string.
656 (should (equal (org-export-number-to-roman -
1) "-1"))
657 ;; Otherwise, return it as a roman number.
658 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
660 (ert-deftest test-org-export
/get-tags
()
661 "Test `org-export-get-tags' specifications."
662 (let ((org-export-exclude-tags '("noexport"))
663 (org-export-select-tags '("export")))
664 ;; Standard test: tags which are not a select tag, an exclude tag,
665 ;; or specified as optional argument shouldn't be ignored.
667 (org-test-with-parsed-data "* Headline :tag:"
668 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
670 ;; Exclude tags are removed.
672 (org-test-with-parsed-data "* Headline :noexport:"
673 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
675 ;; Select tags are removed.
677 (org-test-with-parsed-data "* Headline :export:"
678 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
683 (org-test-with-parsed-data "* Headline :tag:export:"
684 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
686 ;; Tags provided in the optional argument are also ignored.
688 (org-test-with-parsed-data "* Headline :ignore:"
689 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
690 info
'("ignore"))))))
692 (ert-deftest test-org-export
/first-sibling-p
()
693 "Test `org-export-first-sibling-p' specifications."
698 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
701 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
703 ;; Ignore headlines not exported.
707 (let ((org-export-exclude-tags '("ignore")))
708 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
711 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
714 (ert-deftest test-org-export
/last-sibling-p
()
715 "Test `org-export-last-sibling-p' specifications."
720 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
723 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
725 ;; Ignore headlines not exported.
729 (let ((org-export-exclude-tags '("ignore")))
730 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
733 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
740 (ert-deftest test-org-export
/get-coderef-format
()
741 "Test `org-export-get-coderef-format' specifications."
742 ;; A link without description returns "%s"
743 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
745 ;; Return "%s" when path is matched within description.
746 (should (equal (org-export-get-coderef-format "path" "desc (path)")
748 ;; Otherwise return description.
749 (should (equal (org-export-get-coderef-format "path" "desc")
752 (ert-deftest test-org-export
/inline-image-p
()
753 "Test `org-export-inline-image-p' specifications."
755 (org-export-inline-image-p
756 (org-test-with-temp-text "[[#id]]"
758 (org-element-parse-buffer) 'link
'identity nil t
))
759 '(("custom-id" .
"id")))))
761 (ert-deftest test-org-export
/fuzzy-link
()
762 "Test fuzzy links specifications."
763 ;; 1. Links to invisible (keyword) targets should be ignored.
764 (org-test-with-parsed-data
765 "Paragraph.\n#+TARGET: Test\n[[Test]]"
770 (org-export-get-ordinal
771 (org-export-resolve-fuzzy-link link info
) info
)) info
)))
772 ;; 2. Link to an headline should return headline's number.
773 (org-test-with-parsed-data
774 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
776 ;; Note: Headline's number is in fact a list of numbers.
781 (org-export-get-ordinal
782 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
783 ;; 3. Link to a target in an item should return item's number.
784 (org-test-with-parsed-data
785 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
787 ;; Note: Item's number is in fact a list of numbers.
792 (org-export-get-ordinal
793 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
794 ;; 4. Link to a target in a footnote should return footnote's
796 (org-test-with-parsed-data "
797 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
803 (org-export-get-ordinal
804 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
805 ;; 5. Link to a named element should return sequence number of that
807 (org-test-with-parsed-data
808 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
814 (org-export-get-ordinal
815 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
816 ;; 6. Link to a target not within an item, a table, a footnote
817 ;; reference or definition should return section number.
818 (org-test-with-parsed-data
819 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
825 (org-export-get-ordinal
826 (org-export-resolve-fuzzy-link link info
) info
)) info t
)))))
828 (ert-deftest test-org-export
/resolve-coderef
()
829 "Test `org-export-resolve-coderef' specifications."
830 (let ((org-coderef-label-format "(ref:%s)"))
831 ;; 1. A link to a "-n -k -r" block returns line number.
832 (org-test-with-parsed-data
833 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
834 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
835 (org-test-with-parsed-data
836 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
837 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
838 ;; 2. A link to a "-n -r" block returns line number.
839 (org-test-with-parsed-data
840 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
841 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
842 (org-test-with-parsed-data
843 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
844 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
845 ;; 3. A link to a "-n" block returns coderef.
846 (org-test-with-parsed-data
847 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
848 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
849 (org-test-with-parsed-data
850 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
851 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
852 ;; 4. A link to a "-r" block returns line number.
853 (org-test-with-parsed-data
854 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
855 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
856 (org-test-with-parsed-data
857 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
858 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
859 ;; 5. A link to a block without a switch returns coderef.
860 (org-test-with-parsed-data
861 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
862 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
863 (org-test-with-parsed-data
864 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
865 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
866 ;; 6. Correctly handle continued line numbers. A "+n" switch
867 ;; should resume numbering from previous block with numbered
868 ;; lines, ignoring blocks not numbering lines in the process.
869 ;; A "-n" switch resets count.
870 (org-test-with-parsed-data "
875 #+BEGIN_SRC emacs-lisp
879 #+BEGIN_SRC emacs-lisp +n -r
880 \(+ 1 1) (ref:addition)
883 #+BEGIN_EXAMPLE -n -r
884 Another text. (ref:text)
886 (should (= (org-export-resolve-coderef "addition" info
) 2))
887 (should (= (org-export-resolve-coderef "text" info
) 1)))
888 ;; 7. Recognize coderef with user-specified syntax.
889 (org-test-with-parsed-data
890 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
891 (should (equal (org-export-resolve-coderef "text" info
) "text")))))
893 (ert-deftest test-org-export
/resolve-fuzzy-link
()
894 "Test `org-export-resolve-fuzzy-link' specifications."
895 ;; 1. Match target objects.
896 (org-test-with-parsed-data "<<target>> [[target]]"
898 (org-export-resolve-fuzzy-link
899 (org-element-map tree
'link
'identity info t
) info
)))
900 ;; 2. Match target elements.
901 (org-test-with-parsed-data "#+TARGET: target\n[[target]]"
903 (org-export-resolve-fuzzy-link
904 (org-element-map tree
'link
'identity info t
) info
)))
905 ;; 3. Match named elements.
906 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
908 (org-export-resolve-fuzzy-link
909 (org-element-map tree
'link
'identity info t
) info
)))
910 ;; 4. Match exact headline's name.
911 (org-test-with-parsed-data "* My headline\n[[My headline]]"
913 (org-export-resolve-fuzzy-link
914 (org-element-map tree
'link
'identity info t
) info
)))
915 ;; 5. Targets objects have priority over named elements and headline
917 (org-test-with-parsed-data
918 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
922 (org-export-resolve-fuzzy-link
923 (org-element-map tree
'link
'identity info t
) info
)))))
924 ;; 6. Named elements have priority over headline titles.
925 (org-test-with-parsed-data
926 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
930 (org-export-resolve-fuzzy-link
931 (org-element-map tree
'link
'identity info t
) info
)))))
932 ;; 7. If link's path starts with a "*", only match headline titles,
934 (org-test-with-parsed-data
935 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
939 (org-export-resolve-fuzzy-link
940 (org-element-map tree
'link
'identity info t
) info
)))))
941 ;; 8. Return nil if no match.
942 (org-test-with-parsed-data "[[target]]"
944 (org-export-resolve-fuzzy-link
945 (org-element-map tree
'link
'identity info t
) info
))))
947 (ert-deftest test-org-export
/resolve-id-link
()
948 "Test `org-export-resolve-id-link' specifications."
949 ;; 1. Regular test for custom-id link.
950 (org-test-with-parsed-data "* Headline1
957 (org-export-resolve-id-link
958 (org-element-map tree
'link
'identity info t
) info
)))
959 ;; 2. Failing test for custom-id link.
960 (org-test-with-parsed-data "* Headline1
967 (org-export-resolve-id-link
968 (org-element-map tree
'link
'identity info t
) info
)))
969 ;; 3. Test for internal id target.
970 (org-test-with-parsed-data "* Headline1
977 (org-export-resolve-id-link
978 (org-element-map tree
'link
'identity info t
) info
)))
979 ;; 4. Test for external id target.
980 (org-test-with-parsed-data "[[id:aaaa]]"
982 (org-export-resolve-id-link
983 (org-element-map tree
'link
'identity info t
)
984 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file"))))))))
986 (ert-deftest test-org-export
/resolve-radio-link
()
987 "Test `org-export-resolve-radio-link' specifications."
989 (org-test-with-temp-text "<<<radio>>> radio"
990 (org-update-radio-target-regexp)
992 (let* ((tree (org-element-parse-buffer))
993 (info `(:parse-tree
,tree
)))
994 (org-export-resolve-radio-link
995 (org-element-map tree
'link
'identity info t
)
997 ;; Radio target with objects.
998 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
999 (org-update-radio-target-regexp)
1001 (let* ((tree (org-element-parse-buffer))
1002 (info `(:parse-tree
,tree
)))
1003 (org-export-resolve-radio-link
1004 (org-element-map tree
'link
'identity info t
)
1009 ;;; Src-block and example-block
1011 (ert-deftest test-org-export
/unravel-code
()
1012 "Test `org-export-unravel-code' function."
1013 (let ((org-coderef-label-format "(ref:%s)"))
1014 ;; 1. Code without reference.
1015 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
1016 (should (equal (org-export-unravel-code (org-element-at-point))
1018 ;; 2. Code with reference.
1019 (org-test-with-temp-text
1020 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
1021 (should (equal (org-export-unravel-code (org-element-at-point))
1022 '("(+ 1 1)\n" (1 .
"test")))))
1023 ;; 3. Code with user-defined reference.
1024 (org-test-with-temp-text
1025 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
1026 (should (equal (org-export-unravel-code (org-element-at-point))
1027 '("(+ 1 1)\n" (1 .
"test")))))
1028 ;; 4. Code references keys are relative to the current block.
1029 (org-test-with-temp-text "
1038 (should (equal (org-export-unravel-code (org-element-at-point))
1039 '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one")))))
1040 ;; 5. Free up comma-protected lines.
1042 ;; 5.1. In an Org source block, every line is protected.
1043 (org-test-with-temp-text
1044 "#+BEGIN_SRC org\n,* Test\n,# comment\n,Text\n#+END_SRC"
1045 (should (equal (org-export-unravel-code (org-element-at-point))
1046 '("* Test\n# comment\nText\n"))))
1047 ;; 5.2. In other blocks, only headlines, comments and keywords are
1049 (org-test-with-temp-text
1050 "#+BEGIN_EXAMPLE\n,* Headline\n, * Not headline\n,Keep\n#+END_EXAMPLE"
1051 (should (equal (org-export-unravel-code (org-element-at-point))
1052 '("* Headline\n, * Not headline\n,Keep\n"))))))
1058 (ert-deftest test-org-export
/special-column
()
1059 "Test if the table's special column is properly recognized."
1060 ;; 1. First column is special if it contains only a special marking
1061 ;; characters or empty cells.
1062 (org-test-with-temp-text "
1066 (org-export-table-has-special-column-p
1068 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1069 ;; 2. If the column contains anything else, it isn't special.
1070 (org-test-with-temp-text "
1074 (org-export-table-has-special-column-p
1076 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1077 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
1079 (org-test-with-temp-text "
1088 (org-export-table-has-special-column-p
1090 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1091 ;; 4. A first column with only empty cells isn't considered as
1093 (org-test-with-temp-text "
1097 (org-export-table-has-special-column-p
1099 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
1101 (ert-deftest test-org-export
/table-row-is-special-p
()
1102 "Test `org-export-table-row-is-special-p' specifications."
1103 ;; 1. A row is special if it has a special marking character in the
1105 (org-test-with-parsed-data "| ! | 1 |"
1107 (org-export-table-row-is-special-p
1108 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1109 ;; 2. A row is special when its first field is "/"
1110 (org-test-with-parsed-data "
1114 (org-export-table-row-is-special-p
1115 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1116 ;; 3. A row only containing alignment cookies is also considered as
1118 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
1120 (org-export-table-row-is-special-p
1121 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1122 ;; 4. Everything else isn't considered as special.
1123 (org-test-with-parsed-data "| \alpha | | c |"
1125 (org-export-table-row-is-special-p
1126 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1127 ;; 5. Table's rules are never considered as special rows.
1128 (org-test-with-parsed-data "|---+---|"
1130 (org-export-table-row-is-special-p
1131 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
1133 (ert-deftest test-org-export
/has-header-p
()
1134 "Test `org-export-table-has-header-p' specifications."
1135 ;; 1. With an header.
1136 (org-test-with-parsed-data "
1141 (org-export-table-has-header-p
1142 (org-element-map tree
'table
'identity info
'first-match
)
1144 ;; 2. Without an header.
1145 (org-test-with-parsed-data "
1149 (org-export-table-has-header-p
1150 (org-element-map tree
'table
'identity info
'first-match
)
1152 ;; 3. Don't get fooled with starting and ending rules.
1153 (org-test-with-parsed-data "
1159 (org-export-table-has-header-p
1160 (org-element-map tree
'table
'identity info
'first-match
)
1163 (ert-deftest test-org-export
/table-row-group
()
1164 "Test `org-export-table-row-group' specifications."
1165 ;; 1. A rule creates a new group.
1166 (org-test-with-parsed-data "
1173 (mapcar (lambda (row) (org-export-table-row-group row info
))
1174 (org-element-map tree
'table-row
'identity
)))))
1175 ;; 2. Special rows are ignored in count.
1176 (org-test-with-parsed-data "
1183 (mapcar (lambda (row) (org-export-table-row-group row info
))
1184 (org-element-map tree
'table-row
'identity
)))))
1185 ;; 3. Double rules also are ignored in count.
1186 (org-test-with-parsed-data "
1194 (mapcar (lambda (row) (org-export-table-row-group row info
))
1195 (org-element-map tree
'table-row
'identity
))))))
1197 (ert-deftest test-org-export
/table-cell-width
()
1198 "Test `org-export-table-cell-width' specifications."
1199 ;; 1. Width is primarily determined by width cookies. If no cookie
1200 ;; is found, cell's width is nil.
1201 (org-test-with-parsed-data "
1202 | / | <l> | <6> | <l7> |
1207 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1208 (org-element-map tree
'table-cell
'identity info
)))))
1209 ;; 2. The last width cookie has precedence.
1210 (org-test-with-parsed-data "
1217 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1218 (org-element-map tree
'table-cell
'identity info
)))))
1219 ;; 3. Valid width cookies must have a specific row.
1220 (org-test-with-parsed-data "| <6> | cell |"
1224 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1225 (org-element-map tree
'table-cell
'identity
))))))
1227 (ert-deftest test-org-export
/table-cell-alignment
()
1228 "Test `org-export-table-cell-alignment' specifications."
1229 (let ((org-table-number-fraction 0.5)
1230 (org-table-number-regexp "^[0-9]+$"))
1231 ;; 1. Alignment is primarily determined by alignment cookies.
1232 (org-test-with-temp-text "| <l> | <c> | <r> |"
1233 (let* ((tree (org-element-parse-buffer))
1234 (info `(:parse-tree
,tree
)))
1237 '(left center right
)
1238 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1239 (org-element-map tree
'table-cell
'identity
))))))
1240 ;; 2. The last alignment cookie has precedence.
1241 (org-test-with-parsed-data "
1247 '(right right right
)
1248 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1249 (org-element-map tree
'table-cell
'identity
)))))
1250 ;; 3. If there's no cookie, cell's contents determine alignment.
1251 ;; A column mostly made of cells containing numbers will align
1252 ;; its cells to the right.
1253 (org-test-with-parsed-data "
1259 '(right right right
)
1260 (mapcar (lambda (cell)
1261 (org-export-table-cell-alignment cell info
))
1262 (org-element-map tree
'table-cell
'identity
)))))
1263 ;; 4. Otherwise, they will be aligned to the left.
1264 (org-test-with-parsed-data "
1271 (mapcar (lambda (cell)
1272 (org-export-table-cell-alignment cell info
))
1273 (org-element-map tree
'table-cell
'identity
)))))))
1275 (ert-deftest test-org-export
/table-cell-borders
()
1276 "Test `org-export-table-cell-borders' specifications."
1277 ;; 1. Recognize various column groups indicators.
1278 (org-test-with-parsed-data "| / | < | > | <> |"
1281 '((right bottom top
) (left bottom top
) (right bottom top
)
1282 (right left bottom top
))
1283 (mapcar (lambda (cell)
1284 (org-export-table-cell-borders cell info
))
1285 (org-element-map tree
'table-cell
'identity
)))))
1286 ;; 2. Accept shortcuts to define column groups.
1287 (org-test-with-parsed-data "| / | < | < |"
1290 '((right bottom top
) (right left bottom top
) (left bottom top
))
1291 (mapcar (lambda (cell)
1292 (org-export-table-cell-borders cell info
))
1293 (org-element-map tree
'table-cell
'identity
)))))
1294 ;; 3. A valid column groups row must start with a "/".
1295 (org-test-with-parsed-data "
1299 (equal '((top) (top) (bottom) (bottom))
1300 (mapcar (lambda (cell)
1301 (org-export-table-cell-borders cell info
))
1302 (org-element-map tree
'table-cell
'identity
)))))
1303 ;; 4. Take table rules into consideration.
1304 (org-test-with-parsed-data "
1309 (equal '((below top
) (bottom above
))
1310 (mapcar (lambda (cell)
1311 (org-export-table-cell-borders cell info
))
1312 (org-element-map tree
'table-cell
'identity
)))))
1313 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
1314 ;; (resp. `bottom' and `below') borders. Any special row is
1316 (org-test-with-parsed-data "
1322 (equal '((bottom below top above
))
1324 (mapcar (lambda (cell)
1325 (org-export-table-cell-borders cell info
))
1326 (org-element-map tree
'table-cell
'identity
)))))))
1328 (ert-deftest test-org-export
/table-dimensions
()
1329 "Test `org-export-table-dimensions' specifications."
1330 ;; 1. Standard test.
1331 (org-test-with-parsed-data "
1336 (org-export-table-dimensions
1337 (org-element-map tree
'table
'identity info
'first-match
) info
))))
1338 ;; 2. Ignore horizontal rules and special columns.
1339 (org-test-with-parsed-data "
1346 (org-export-table-dimensions
1347 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
1349 (ert-deftest test-org-export
/table-cell-address
()
1350 "Test `org-export-table-cell-address' specifications."
1351 ;; 1. Standard test: index is 0-based.
1352 (org-test-with-parsed-data "| a | b |"
1354 (equal '((0 .
0) (0 .
1))
1357 (lambda (cell) (org-export-table-cell-address cell info
))
1359 ;; 2. Special column isn't counted, nor are special rows.
1360 (org-test-with-parsed-data "
1365 (org-export-table-cell-address
1366 (car (last (org-element-map tree
'table-cell
'identity info
)))
1368 ;; 3. Tables rules do not count either.
1369 (org-test-with-parsed-data "
1377 (org-export-table-cell-address
1378 (car (last (org-element-map tree
'table-cell
'identity info
)))
1380 ;; 4. Return nil for special cells.
1381 (org-test-with-parsed-data "| / | a |"
1383 (org-export-table-cell-address
1384 (org-element-map tree
'table-cell
'identity nil
'first-match
)
1387 (ert-deftest test-org-export
/get-table-cell-at
()
1388 "Test `org-export-get-table-cell-at' specifications."
1389 ;; 1. Address ignores special columns, special rows and rules.
1390 (org-test-with-parsed-data "
1397 (org-element-contents
1398 (org-export-get-table-cell-at
1400 (org-element-map tree
'table
'identity info
'first-match
)
1402 ;; 2. Return value for a non-existent address is nil.
1403 (org-test-with-parsed-data "| a |"
1405 (org-export-get-table-cell-at
1407 (org-element-map tree
'table
'identity info
'first-match
)
1409 (org-test-with-parsed-data "| / |"
1411 (org-export-get-table-cell-at
1413 (org-element-map tree
'table
'identity info
'first-match
)
1416 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
1417 "Test `org-export-table-cell-starts-colgroup-p' specifications."
1418 ;; 1. A cell at a beginning of a row always starts a column group.
1419 (org-test-with-parsed-data "| a |"
1421 (org-export-table-cell-starts-colgroup-p
1422 (org-element-map tree
'table-cell
'identity info
'first-match
)
1424 ;; 2. Special column should be ignored when determining the
1425 ;; beginning of the row.
1426 (org-test-with-parsed-data "
1430 (org-export-table-cell-starts-colgroup-p
1431 (org-element-map tree
'table-cell
'identity info
'first-match
)
1433 ;; 2. Explicit column groups.
1434 (org-test-with-parsed-data "
1443 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
1446 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
1447 "Test `org-export-table-cell-ends-colgroup-p' specifications."
1448 ;; 1. A cell at the end of a row always ends a column group.
1449 (org-test-with-parsed-data "| a |"
1451 (org-export-table-cell-ends-colgroup-p
1452 (org-element-map tree
'table-cell
'identity info
'first-match
)
1454 ;; 2. Special column should be ignored when determining the
1455 ;; beginning of the row.
1456 (org-test-with-parsed-data "
1460 (org-export-table-cell-ends-colgroup-p
1461 (org-element-map tree
'table-cell
'identity info
'first-match
)
1463 ;; 3. Explicit column groups.
1464 (org-test-with-parsed-data "
1473 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
1476 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
1477 "Test `org-export-table-row-starts-rowgroup-p' specifications."
1478 ;; 1. A row at the beginning of a table always starts a row group.
1479 ;; So does a row following a table rule.
1480 (org-test-with-parsed-data "
1490 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
1492 ;; 2. Special rows should be ignored when determining the beginning
1494 (org-test-with-parsed-data "
1506 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
1509 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
1510 "Test `org-export-table-row-ends-rowgroup-p' specifications."
1511 ;; 1. A row at the end of a table always ends a row group. So does
1512 ;; a row preceding a table rule.
1513 (org-test-with-parsed-data "
1523 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
1525 ;; 2. Special rows should be ignored when determining the beginning
1527 (org-test-with-parsed-data "
1539 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
1542 (ert-deftest test-org-export
/table-row-starts-header-p
()
1543 "Test `org-export-table-row-starts-header-p' specifications."
1544 ;; 1. Only the row starting the first row group starts the table
1546 (org-test-with-parsed-data "
1557 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
1559 ;; 2. A row cannot start an header if there's no header in the
1561 (org-test-with-parsed-data "
1565 (org-export-table-row-starts-header-p
1566 (org-element-map tree
'table-row
'identity info
'first-match
)
1569 (ert-deftest test-org-export
/table-row-ends-header-p
()
1570 "Test `org-export-table-row-ends-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-ends-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-ends-header-p
1593 (org-element-map tree
'table-row
'identity info
'first-match
)
1600 (ert-deftest test-org-export
/get-next-element
()
1601 "Test `org-export-get-next-element' specifications."
1605 (org-test-with-parsed-data "* Headline\n*a* b"
1606 (org-export-get-next-element
1607 (org-element-map tree
'bold
'identity info t
) info
))))
1608 ;; Return nil when no previous element.
1610 (org-test-with-parsed-data "* Headline\na *b*"
1611 (org-export-get-next-element
1612 (org-element-map tree
'bold
'identity info t
) info
)))
1613 ;; Non-exportable elements are ignored.
1615 (let ((org-export-with-timestamps nil
))
1616 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
1617 (org-export-get-next-element
1618 (org-element-map tree
'entity
'identity info t
) info
)))))
1620 (ert-deftest test-org-export
/get-previous-element
()
1621 "Test `org-export-get-previous-element' specifications."
1625 (org-test-with-parsed-data "* Headline\na *b*"
1626 (org-export-get-previous-element
1627 (org-element-map tree
'bold
'identity info t
) info
))))
1628 ;; Return nil when no previous element.
1630 (org-test-with-parsed-data "* Headline\n*a* b"
1631 (org-export-get-previous-element
1632 (org-element-map tree
'bold
'identity info t
) info
)))
1633 ;; Non-exportable elements are ignored.
1635 (let ((org-export-with-timestamps nil
))
1636 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
1637 (org-export-get-previous-element
1638 (org-element-map tree
'entity
'identity info t
) info
)))))
1641 (provide 'test-org-export
)
1642 ;;; test-org-export.el end here