org-export: Add a function to retrieve category of an element or object
[org-mode.git] / testing / lisp / test-org-export.el
blob735fe1c2fb85d31e8522e09970a97f7cb36ca636
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
10 ;;;; Comments
14 ;;; Code:
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
24 syntax."
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)
30 transcode-table)
31 (push
32 (cons type
33 (lambda (obj contents info)
34 (funcall
35 (intern (format "org-element-%s-interpreter" type))
36 obj contents)))
37 transcode-table)))))
38 (progn ,@body)))
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))))
56 ,@body)))
60 ;;; Internal Tests
62 (ert-deftest test-org-export/bind-keyword ()
63 "Test reading #+BIND: keywords."
64 ;; Test with `org-export-all-BIND' set to t.
65 (should
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.
71 (should-not
72 (org-test-with-temp-text "#+BIND: variable value"
73 (let ((org-export-allow-BIND nil))
74 (org-export--install-letbind-maybe)
75 (boundp 'variable))))
76 ;; Test with `org-export-all-BIND' set to 'confirm and
77 ;; `org-export--allow-BIND-local' to t .
78 (should
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.
86 (should-not
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))))
92 ;; BIND keywords are case-insensitive.
93 (should
94 (org-test-with-temp-text "#+bind: variable value"
95 (let ((org-export-allow-BIND t))
96 (org-export--install-letbind-maybe)
97 (eq variable 'value)))))
99 (ert-deftest test-org-export/parse-option-keyword ()
100 "Test reading all standard #+OPTIONS: items."
101 (should
102 (equal
103 (org-export--parse-option-keyword
104 "H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t
105 *:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t inline:nil
106 stat:t")
107 '(:headline-levels
108 1 :preserve-breaks t :section-numbers t :time-stamp-file t
109 :with-archived-trees t :with-author t :with-creator t :with-drawers t
110 :with-email t :with-emphasize t :with-entities t :with-fixed-width t
111 :with-footnotes t :with-inlinetasks nil :with-priority t
112 :with-special-strings t :with-statistics-cookies t :with-sub-superscript t
113 :with-toc t :with-tables t :with-tags t :with-tasks t :with-timestamps t
114 :with-todo-keywords t)))
115 ;; Test some special values.
116 (should
117 (equal
118 (org-export--parse-option-keyword
119 "arch:headline creator:comment d:(\"TEST\")
120 ^:{} toc:1 tags:not-in-toc tasks:todo num:2 <:active")
121 '( :section-numbers
123 :with-archived-trees headline :with-creator comment
124 :with-drawers ("TEST") :with-sub-superscript {} :with-toc 1
125 :with-tags not-in-toc :with-tasks todo :with-timestamps active))))
127 (ert-deftest test-org-export/get-inbuffer-options ()
128 "Test reading all standard export keywords."
129 (should
130 (equal
131 (org-test-with-temp-text "#+AUTHOR: Me, Myself and I
132 #+CREATOR: Idem
133 #+DATE: Today
134 #+DESCRIPTION: Testing
135 #+DESCRIPTION: with two lines
136 #+EMAIL: some@email.org
137 #+EXCLUDE_TAGS: noexport invisible
138 #+KEYWORDS: test
139 #+LANGUAGE: en
140 #+SELECT_TAGS: export
141 #+TITLE: Some title
142 #+TITLE: with spaces"
143 (org-export--get-inbuffer-options))
144 '(:author
145 ("Me, Myself and I") :creator "Idem" :date ("Today")
146 :description "Testing\nwith two lines" :email "some@email.org"
147 :exclude-tags ("noexport" "invisible") :keywords "test" :language "en"
148 :select-tags ("export") :title ("Some title with spaces")))))
150 (ert-deftest test-org-export/get-subtree-options ()
151 "Test setting options from headline's properties."
152 ;; EXPORT_TITLE.
153 (org-test-with-temp-text "#+TITLE: Title
154 * Headline
155 :PROPERTIES:
156 :EXPORT_TITLE: Subtree Title
157 :END:
158 Paragraph"
159 (forward-line)
160 (should (equal (plist-get (org-export-get-environment nil t) :title)
161 '("Subtree Title"))))
162 :title
163 '("subtree-title")
164 ;; EXPORT_OPTIONS.
165 (org-test-with-temp-text "#+OPTIONS: H:1
166 * Headline
167 :PROPERTIES:
168 :EXPORT_OPTIONS: H:2
169 :END:
170 Paragraph"
171 (forward-line)
172 (should
173 (= 2 (plist-get (org-export-get-environment nil t) :headline-levels))))
174 ;; EXPORT_DATE.
175 (org-test-with-temp-text "#+DATE: today
176 * Headline
177 :PROPERTIES:
178 :EXPORT_DATE: 29-03-2012
179 :END:
180 Paragraph"
181 (forward-line)
182 (should (equal (plist-get (org-export-get-environment nil t) :date)
183 '("29-03-2012"))))
184 ;; Export properties are case-insensitive.
185 (org-test-with-temp-text "* Headline
186 :PROPERTIES:
187 :EXPORT_Date: 29-03-2012
188 :END:
189 Paragraph"
190 (should (equal (plist-get (org-export-get-environment nil t) :date)
191 '("29-03-2012")))))
193 (ert-deftest test-org-export/handle-options ()
194 "Test if export options have an impact on output."
195 ;; Test exclude tags.
196 (org-test-with-temp-text "* Head1 :noexport:"
197 (org-test-with-backend test
198 (should
199 (equal (org-export-as 'test nil nil nil '(:exclude-tags ("noexport")))
200 ""))))
201 ;; Test include tags.
202 (org-test-with-temp-text "
203 * Head1
204 * Head2
205 ** Sub-Head2.1 :export:
206 *** Sub-Head2.1.1
207 * Head2"
208 (org-test-with-backend test
209 (should
210 (equal
211 "* Head2\n** Sub-Head2.1 :export:\n*** Sub-Head2.1.1\n"
212 (let ((org-tags-column 0))
213 (org-export-as 'test nil nil nil '(:select-tags ("export"))))))))
214 ;; Test mixing include tags and exclude tags.
215 (org-test-with-temp-text "
216 * Head1 :export:
217 ** Sub-Head1 :noexport:
218 ** Sub-Head2
219 * Head2 :noexport:
220 ** Sub-Head1 :export:"
221 (org-test-with-backend test
222 (should
223 (string-match
224 "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
225 (org-export-as
226 'test nil nil nil
227 '(:select-tags ("export") :exclude-tags ("noexport")))))))
228 ;; Ignore tasks.
229 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
230 (org-test-with-temp-text "* TODO Head1"
231 (org-test-with-backend test
232 (should (equal (org-export-as 'test nil nil nil '(:with-tasks nil))
233 "")))))
234 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
235 (org-test-with-temp-text "* TODO Head1"
236 (org-test-with-backend test
237 (should (equal (org-export-as 'test nil nil nil '(:with-tasks t))
238 "* TODO Head1\n")))))
239 ;; Archived tree.
240 (org-test-with-temp-text "* Head1 :archive:"
241 (let ((org-archive-tag "archive"))
242 (org-test-with-backend test
243 (should
244 (equal (org-export-as 'test nil nil nil '(:with-archived-trees nil))
245 "")))))
246 (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
247 (let ((org-archive-tag "archive"))
248 (org-test-with-backend test
249 (should
250 (string-match
251 "\\* Head1[ \t]+:archive:"
252 (org-export-as 'test nil nil nil
253 '(:with-archived-trees headline)))))))
254 (org-test-with-temp-text "* Head1 :archive:"
255 (let ((org-archive-tag "archive"))
256 (org-test-with-backend test
257 (should
258 (string-match
259 "\\`\\* Head1[ \t]+:archive:\n\\'"
260 (org-export-as 'test nil nil nil '(:with-archived-trees t)))))))
261 ;; Drawers.
262 (let ((org-drawers '("TEST")))
263 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
264 (org-test-with-backend test
265 (should (equal (org-export-as 'test nil nil nil '(:with-drawers nil))
266 ""))
267 (should (equal (org-export-as 'test nil nil nil '(:with-drawers t))
268 ":TEST:\ncontents\n:END:\n")))))
269 (let ((org-drawers '("FOO" "BAR")))
270 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
271 (org-test-with-backend test
272 (should
273 (equal (org-export-as 'test nil nil nil '(:with-drawers ("FOO")))
274 ":FOO:\nkeep\n:END:\n")))))
275 ;; Timestamps.
276 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
277 (org-test-with-backend test
278 (should
279 (equal (org-export-as 'test nil nil nil '(:with-timestamps t))
280 "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>\n"))
281 (should
282 (equal (org-export-as 'test nil nil nil '(:with-timestamps nil)) ""))
283 (should
284 (equal (org-export-as 'test nil nil nil '(:with-timestamps active))
285 "<2012-04-29 sun. 10:45>\n"))
286 (should
287 (equal (org-export-as 'test nil nil nil '(:with-timestamps inactive))
288 "[2012-04-29 sun. 10:45]\n"))))
289 ;; Clocks.
290 (let ((org-clock-string "CLOCK:"))
291 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
292 (org-test-with-backend test
293 (should
294 (equal (org-export-as 'test nil nil nil '(:with-clocks t))
295 "CLOCK: [2012-04-29 sun. 10:45]\n"))
296 (should
297 (equal (org-export-as 'test nil nil nil '(:with-clocks nil)) "")))))
298 ;; Plannings.
299 (let ((org-closed-string "CLOSED:"))
300 (org-test-with-temp-text "CLOSED: [2012-04-29 sun. 10:45]"
301 (org-test-with-backend test
302 (should
303 (equal (org-export-as 'test nil nil nil '(:with-plannings t))
304 "CLOSED: [2012-04-29 sun. 10:45]\n"))
305 (should
306 (equal (org-export-as 'test nil nil nil '(:with-plannings nil))
307 "")))))
308 ;; Inlinetasks.
309 (when (featurep 'org-inlinetask)
310 (should
311 (equal
312 (let ((org-inlinetask-min-level 15))
313 (org-test-with-temp-text "*************** Task"
314 (org-test-with-backend test
315 (org-export-as 'test nil nil nil '(:with-inlinetasks nil)))))
316 ""))
317 (should
318 (equal
319 (let ((org-inlinetask-min-level 15))
320 (org-test-with-temp-text
321 "*************** Task\nContents\n*************** END"
322 (org-test-with-backend test
323 (org-export-as 'test nil nil nil '(:with-inlinetasks nil)))))
324 "")))
325 ;; Statistics cookies.
326 (should
327 (equal ""
328 (org-test-with-temp-text "[0/0]"
329 (org-test-with-backend test
330 (org-export-as
331 'test nil nil nil '(:with-statistics-cookies nil)))))))
333 (ert-deftest test-org-export/comment-tree ()
334 "Test if export process ignores commented trees."
335 (let ((org-comment-string "COMMENT"))
336 (org-test-with-temp-text "* COMMENT Head1"
337 (org-test-with-backend test
338 (should (equal (org-export-as 'test) ""))))))
340 (ert-deftest test-org-export/export-scope ()
341 "Test all export scopes."
342 (org-test-with-temp-text "
343 * Head1
344 ** Head2
345 text
346 *** Head3"
347 (org-test-with-backend test
348 ;; Subtree.
349 (forward-line 3)
350 (should (equal (org-export-as 'test 'subtree) "text\n*** Head3\n"))
351 ;; Visible.
352 (goto-char (point-min))
353 (forward-line)
354 (org-cycle)
355 (should (equal (org-export-as 'test nil 'visible) "* Head1\n"))
356 ;; Body only.
357 (flet ((org-test-template (body info) (format "BEGIN\n%sEND" body)))
358 (push '(template . org-test-template) org-test-translate-alist)
359 (should (equal (org-export-as 'test nil nil 'body-only)
360 "* Head1\n** Head2\ntext\n*** Head3\n"))
361 (should (equal (org-export-as 'test)
362 "BEGIN\n* Head1\n** Head2\ntext\n*** Head3\nEND")))
363 ;; Region.
364 (goto-char (point-min))
365 (forward-line 3)
366 (transient-mark-mode 1)
367 (push-mark (point) t t)
368 (goto-char (point-at-eol))
369 (should (equal (org-export-as 'test) "text\n"))))
370 ;; Subtree with a code block calling another block outside.
371 (should
372 (equal ": 3\n"
373 (org-test-with-temp-text "
374 * Head1
375 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
376 <<test>>
377 #+END_SRC
378 * Head2
379 #+NAME: test
380 #+BEGIN_SRC emacs-lisp
381 \(+ 1 2)
382 #+END_SRC"
383 (org-test-with-backend test
384 (forward-line 1)
385 (org-export-as 'test 'subtree))))))
387 (ert-deftest test-org-export/expand-include ()
388 "Test file inclusion in an Org buffer."
389 ;; Error when file isn't specified.
390 (should-error
391 (org-test-with-temp-text "#+INCLUDE: dummy.org"
392 (org-export-expand-include-keyword)))
393 ;; Full insertion with recursive inclusion.
394 (org-test-with-temp-text
395 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir)
396 (org-export-expand-include-keyword)
397 (should (equal (buffer-string)
398 "Small Org file with an include keyword.
400 #+BEGIN_SRC emacs-lisp :exports results\n(+ 2 1)\n#+END_SRC
402 Success!
404 * Heading
405 body\n")))
406 ;; Localized insertion.
407 (org-test-with-temp-text
408 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
409 org-test-dir)
410 (org-export-expand-include-keyword)
411 (should (equal (buffer-string)
412 "Small Org file with an include keyword.\n")))
413 ;; Insertion with constraints on headlines level.
414 (org-test-with-temp-text
415 (format
416 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\""
417 org-test-dir)
418 (org-export-expand-include-keyword)
419 (should (equal (buffer-string) "* Top heading\n** Heading\nbody\n")))
420 ;; Inclusion within an example block.
421 (org-test-with-temp-text
422 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" example"
423 org-test-dir)
424 (org-export-expand-include-keyword)
425 (should
426 (equal
427 (buffer-string)
428 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n")))
429 ;; Inclusion within a src-block.
430 (org-test-with-temp-text
431 (format
432 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" src emacs-lisp"
433 org-test-dir)
434 (org-export-expand-include-keyword)
435 (should (equal (buffer-string)
436 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"))))
438 (ert-deftest test-org-export/expand-macro ()
439 "Test macro expansion in an Org buffer."
440 ;; Standard macro expansion.
441 (should
442 (equal "#+MACRO: macro1 value\nvalue\n"
443 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
444 (org-test-with-backend test (org-export-as 'test)))))
445 ;; Expand specific macros.
446 (should
447 (equal "me 2012-03-29 me@here Title\n"
448 (org-test-with-temp-text
450 #+TITLE: Title
451 #+DATE: 2012-03-29
452 #+AUTHOR: me
453 #+EMAIL: me@here
454 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
455 (let ((output (org-test-with-backend test (org-export-as 'test))))
456 (substring output (string-match ".*\n\\'" output))))))
457 ;; Expand specific macros when property contained a regular macro
458 ;; already.
459 (should
460 (equal "value\n"
461 (org-test-with-temp-text "
462 #+MACRO: macro1 value
463 #+TITLE: {{{macro1}}}
464 {{{title}}}"
465 (let ((output (org-test-with-backend test (org-export-as 'test))))
466 (substring output (string-match ".*\n\\'" output))))))
467 ;; Expand macros with templates in included files.
468 (should
469 (equal "success\n"
470 (org-test-with-temp-text
471 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
472 {{{included-macro}}}" org-test-dir)
473 (let ((output (org-test-with-backend test (org-export-as 'test))))
474 (substring output (string-match ".*\n\\'" output)))))))
476 (ert-deftest test-org-export/user-ignore-list ()
477 "Test if `:ignore-list' accepts user input."
478 (org-test-with-backend test
479 (flet ((skip-note-head
480 (data backend info)
481 ;; Ignore headlines with the word "note" in their title.
482 (org-element-map
483 data 'headline
484 (lambda (headline)
485 (when (string-match "\\<note\\>"
486 (org-element-property :raw-value headline))
487 (org-export-ignore-element headline info)))
488 info)
489 data))
490 ;; Install function in parse tree filters.
491 (let ((org-export-filter-parse-tree-functions '(skip-note-head)))
492 (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
493 (should (equal (org-export-as 'test) "* Head1\n")))))))
495 (ert-deftest test-org-export/before-parsing-hook ()
496 "Test `org-export-before-parsing-hook'."
497 (org-test-with-backend test
498 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
499 (let ((org-export-before-parsing-hook
500 '((lambda (backend)
501 (org-map-entries
502 (lambda ()
503 (delete-region (point) (progn (forward-line) (point)))))))))
504 (should (equal (org-export-as 'test) "Body 1\nBody 2\n"))))))
508 ;;; Affiliated Keywords
510 (ert-deftest test-org-export/read-attribute ()
511 "Test `org-export-read-attribute' specifications."
512 ;; Standard test.
513 (should
514 (equal
515 (org-export-read-attribute
516 :attr_html
517 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
518 (org-element-at-point)))
519 '(:a 1 :b 2)))
520 ;; Return nil on empty attribute.
521 (should-not
522 (org-export-read-attribute
523 :attr_html
524 (org-test-with-temp-text "Paragraph" (org-element-at-point)))))
526 (ert-deftest test-org-export/get-caption ()
527 "Test `org-export-get-caption' specifications."
528 ;; Without optional argument, return long caption
529 (should
530 (equal
531 '("l")
532 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
533 (org-export-get-caption (org-element-at-point)))))
534 ;; With optional argument, return short caption.
535 (should
536 (equal
537 '("s")
538 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
539 (org-export-get-caption (org-element-at-point) t))))
540 ;; Multiple lines are separated by white spaces.
541 (should
542 (equal
543 '("a" " " "b")
544 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
545 (org-export-get-caption (org-element-at-point))))))
549 ;;; Export Snippets
551 (ert-deftest test-org-export/export-snippet ()
552 "Test export snippets transcoding."
553 (org-test-with-temp-text "@@test:A@@@@t:B@@"
554 (org-test-with-backend test
555 (let ((org-test-translate-alist
556 (cons (cons 'export-snippet
557 (lambda (snippet contents info)
558 (when (eq (org-export-snippet-backend snippet) 'test)
559 (org-element-property :value snippet))))
560 org-test-translate-alist)))
561 (let ((org-export-snippet-translation-alist nil))
562 (should (equal (org-export-as 'test) "A\n")))
563 (let ((org-export-snippet-translation-alist '(("t" . "test"))))
564 (should (equal (org-export-as 'test) "AB\n")))))))
568 ;;; Footnotes
570 (ert-deftest test-org-export/footnotes ()
571 "Test footnotes specifications."
572 (let ((org-footnote-section nil)
573 (org-export-with-footnotes t))
574 ;; 1. Read every type of footnote.
575 (should
576 (equal
577 '((1 . "A\n") (2 . "B") (3 . "C") (4 . "D"))
578 (org-test-with-parsed-data
579 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
580 (org-element-map
581 tree 'footnote-reference
582 (lambda (ref)
583 (let ((def (org-export-get-footnote-definition ref info)))
584 (cons (org-export-get-footnote-number ref info)
585 (if (eq (org-element-property :type ref) 'inline) (car def)
586 (car (org-element-contents
587 (car (org-element-contents def))))))))
588 info))))
589 ;; 2. Test nested footnotes order.
590 (org-test-with-parsed-data
591 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
592 (should
593 (equal
594 '((1 . "fn:1") (2 . "fn:2") (3 . "fn:3") (4))
595 (org-element-map
596 tree 'footnote-reference
597 (lambda (ref)
598 (when (org-export-footnote-first-reference-p ref info)
599 (cons (org-export-get-footnote-number ref info)
600 (org-element-property :label ref))))
601 info))))
602 ;; 3. Test nested footnote in invisible definitions.
603 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
604 ;; Hide definitions.
605 (narrow-to-region (point) (point-at-eol))
606 (let* ((tree (org-element-parse-buffer))
607 (info (org-combine-plists
608 `(:parse-tree ,tree)
609 (org-export-collect-tree-properties
610 tree (org-export-get-environment)))))
611 ;; Both footnotes should be seen.
612 (should
613 (= (length (org-export-collect-footnote-definitions tree info)) 2))))
614 ;; 4. Test footnotes definitions collection.
615 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
617 \[fn:2] B [fn:3] [fn::D].
619 \[fn:3] C."
620 (should (= (length (org-export-collect-footnote-definitions tree info))
621 4)))
622 ;; 5. Test export of footnotes defined outside parsing scope.
623 (org-test-with-temp-text "[fn:1] Out of scope
624 * Title
625 Paragraph[fn:1]"
626 (org-test-with-backend test
627 (let ((org-test-translate-alist
628 (cons (cons 'footnote-reference
629 (lambda (fn contents info)
630 (org-element-interpret-data
631 (org-export-get-footnote-definition fn info))))
632 org-test-translate-alist)))
633 (forward-line)
634 (should (equal "ParagraphOut of scope\n"
635 (org-export-as 'test 'subtree))))))))
639 ;;; Headlines and Inlinetasks
641 (ert-deftest test-org-export/get-relative-level ()
642 "Test `org-export-get-relative-level' specifications."
643 ;; Standard test.
644 (should
645 (equal '(1 2)
646 (let ((org-odd-levels-only nil))
647 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
648 (org-element-map
649 tree 'headline
650 (lambda (h) (org-export-get-relative-level h info))
651 info)))))
652 ;; Missing levels
653 (should
654 (equal '(1 3)
655 (let ((org-odd-levels-only nil))
656 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
657 (org-element-map
658 tree 'headline
659 (lambda (h) (org-export-get-relative-level h info))
660 info))))))
662 (ert-deftest test-org-export/low-level-p ()
663 "Test `org-export-low-level-p' specifications."
664 (should
665 (equal
666 '(no yes)
667 (let ((org-odd-levels-only nil))
668 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
669 (org-element-map
670 tree 'headline
671 (lambda (h) (if (org-export-low-level-p h info) 'yes 'no))
672 (plist-put info :headline-levels 1)))))))
674 (ert-deftest test-org-export/get-headline-number ()
675 "Test `org-export-get-headline-number' specifications."
676 ;; Standard test.
677 (should
678 (equal
679 '((1) (1 1))
680 (let ((org-odd-levels-only nil))
681 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
682 (org-element-map
683 tree 'headline
684 (lambda (h) (org-export-get-headline-number h info))
685 info)))))
686 ;; Missing levels are replaced with 0.
687 (should
688 (equal
689 '((1) (1 0 1))
690 (let ((org-odd-levels-only nil))
691 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
692 (org-element-map
693 tree 'headline
694 (lambda (h) (org-export-get-headline-number h info))
695 info))))))
697 (ert-deftest test-org-export/numbered-headline-p ()
698 "Test `org-export-numbered-headline-p' specifications."
699 ;; If `:section-numbers' is nil, never number headlines.
700 (should-not
701 (org-test-with-parsed-data "* Headline"
702 (org-element-map
703 tree 'headline
704 (lambda (h) (org-export-numbered-headline-p h info))
705 (plist-put info :section-numbers nil))))
706 ;; If `:section-numbers' is a number, only number headlines with
707 ;; a level greater that it.
708 (should
709 (equal
710 '(yes no)
711 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
712 (org-element-map
713 tree 'headline
714 (lambda (h) (if (org-export-numbered-headline-p h info) 'yes 'no))
715 (plist-put info :section-numbers 1)))))
716 ;; Otherwise, headlines are always numbered.
717 (should
718 (org-test-with-parsed-data "* Headline"
719 (org-element-map
720 tree 'headline
721 (lambda (h) (org-export-numbered-headline-p h info))
722 (plist-put info :section-numbers t)))))
724 (ert-deftest test-org-export/number-to-roman ()
725 "Test `org-export-number-to-roman' specifications."
726 ;; If number is negative, return it as a string.
727 (should (equal (org-export-number-to-roman -1) "-1"))
728 ;; Otherwise, return it as a roman number.
729 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
731 (ert-deftest test-org-export/get-tags ()
732 "Test `org-export-get-tags' specifications."
733 (let ((org-export-exclude-tags '("noexport"))
734 (org-export-select-tags '("export")))
735 ;; Standard test: tags which are not a select tag, an exclude tag,
736 ;; or specified as optional argument shouldn't be ignored.
737 (should
738 (org-test-with-parsed-data "* Headline :tag:"
739 (org-export-get-tags (org-element-map tree 'headline 'identity info t)
740 info)))
741 ;; Exclude tags are removed.
742 (should-not
743 (org-test-with-parsed-data "* Headline :noexport:"
744 (org-export-get-tags (org-element-map tree 'headline 'identity info t)
745 info)))
746 ;; Select tags are removed.
747 (should-not
748 (org-test-with-parsed-data "* Headline :export:"
749 (org-export-get-tags (org-element-map tree 'headline 'identity info t)
750 info)))
751 (should
752 (equal
753 '("tag")
754 (org-test-with-parsed-data "* Headline :tag:export:"
755 (org-export-get-tags (org-element-map tree 'headline 'identity info t)
756 info))))
757 ;; Tags provided in the optional argument are also ignored.
758 (should-not
759 (org-test-with-parsed-data "* Headline :ignore:"
760 (org-export-get-tags (org-element-map tree 'headline 'identity info t)
761 info '("ignore"))))
762 ;; Allow tag inheritance.
763 (should
764 (equal
765 '(("tag") ("tag"))
766 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
767 (org-element-map
768 tree 'headline
769 (lambda (hl) (org-export-get-tags hl info nil t)) info))))
770 ;; Tag inheritance checks FILETAGS keywords.
771 (should
772 (equal
773 '(("a" "b" "tag"))
774 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
775 (org-element-map
776 tree 'headline
777 (lambda (hl) (org-export-get-tags hl info nil t)) info))))))
779 (ert-deftest test-org-export/get-node-property ()
780 "Test`org-export-get-node-property' specifications."
781 ;; Standard test.
782 (should
783 (equal "value"
784 (org-test-with-parsed-data "* Headline
785 :PROPERTIES:
786 :prop: value
787 :END:"
788 (org-export-get-node-property
789 :prop (org-element-map tree 'headline 'identity nil t)))))
790 ;; Test inheritance.
791 (should
792 (equal "value"
793 (org-test-with-parsed-data "* Parent
794 :PROPERTIES:
795 :prop: value
796 :END:
797 ** Headline
798 Paragraph"
799 (org-export-get-node-property
800 :prop (org-element-map tree 'paragraph 'identity nil t) t))))
801 ;; Cannot return a value before the first headline.
802 (should-not
803 (org-test-with-parsed-data "Paragraph
804 * Headline
805 :PROPERTIES:
806 :prop: value
807 :END:"
808 (org-export-get-node-property
809 :prop (org-element-map tree 'paragraph 'identity nil t)))))
811 (ert-deftest test-org-export/get-category ()
812 "Test `org-export-get-category' specifications."
813 ;; Standard test.
814 (should
815 (equal "value"
816 (org-test-with-parsed-data "* Headline
817 :PROPERTIES:
818 :CATEGORY: value
819 :END:"
820 (org-export-get-category
821 (org-element-map tree 'headline 'identity nil t) info))))
822 ;; Test inheritance from a parent headline.
823 (should
824 (equal '("value" "value")
825 (org-test-with-parsed-data "* Headline1
826 :PROPERTIES:
827 :CATEGORY: value
828 :END:
829 ** Headline2"
830 (org-element-map
831 tree 'headline
832 (lambda (hl) (org-export-get-category hl info)) info))))
833 ;; Test inheritance from #+CATEGORY keyword
834 (should
835 (equal "value"
836 (org-test-with-parsed-data "#+CATEGORY: value
837 * Headline"
838 (org-export-get-category
839 (org-element-map tree 'headline 'identity nil t) info))))
840 ;; Test inheritance from file name.
841 (should
842 (equal "test"
843 (org-test-with-parsed-data "* Headline"
844 (let ((info (plist-put info :input-file "~/test.org")))
845 (org-export-get-category
846 (org-element-map tree 'headline 'identity nil t) info)))))
847 ;; Fall-back value.
848 (should
849 (equal "???"
850 (org-test-with-parsed-data "* Headline"
851 (org-export-get-category
852 (org-element-map tree 'headline 'identity nil t) info)))))
854 (ert-deftest test-org-export/first-sibling-p ()
855 "Test `org-export-first-sibling-p' specifications."
856 ;; Standard test.
857 (should
858 (equal
859 '(yes yes no)
860 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
861 (org-element-map
862 tree 'headline
863 (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
864 info))))
865 ;; Ignore headlines not exported.
866 (should
867 (equal
868 '(yes)
869 (let ((org-export-exclude-tags '("ignore")))
870 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
871 (org-element-map
872 tree 'headline
873 (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
874 info))))))
876 (ert-deftest test-org-export/last-sibling-p ()
877 "Test `org-export-last-sibling-p' specifications."
878 ;; Standard test.
879 (should
880 (equal
881 '(yes no yes)
882 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
883 (org-element-map
884 tree 'headline
885 (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
886 info))))
887 ;; Ignore headlines not exported.
888 (should
889 (equal
890 '(yes)
891 (let ((org-export-exclude-tags '("ignore")))
892 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
893 (org-element-map
894 tree 'headline
895 (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
896 info))))))
900 ;;; Links
902 (ert-deftest test-org-export/get-coderef-format ()
903 "Test `org-export-get-coderef-format' specifications."
904 ;; A link without description returns "%s"
905 (should (equal (org-export-get-coderef-format "(ref:line)" nil)
906 "%s"))
907 ;; Return "%s" when path is matched within description.
908 (should (equal (org-export-get-coderef-format "path" "desc (path)")
909 "desc %s"))
910 ;; Otherwise return description.
911 (should (equal (org-export-get-coderef-format "path" "desc")
912 "desc")))
914 (ert-deftest test-org-export/inline-image-p ()
915 "Test `org-export-inline-image-p' specifications."
916 (should
917 (org-export-inline-image-p
918 (org-test-with-temp-text "[[#id]]"
919 (org-element-map
920 (org-element-parse-buffer) 'link 'identity nil t))
921 '(("custom-id" . "id")))))
923 (ert-deftest test-org-export/fuzzy-link ()
924 "Test fuzzy links specifications."
925 ;; 1. Links to invisible (keyword) targets should be ignored.
926 (org-test-with-parsed-data
927 "Paragraph.\n#+TARGET: Test\n[[Test]]"
928 (should-not
929 (org-element-map
930 tree 'link
931 (lambda (link)
932 (org-export-get-ordinal
933 (org-export-resolve-fuzzy-link link info) info)) info)))
934 ;; 2. Link to an headline should return headline's number.
935 (org-test-with-parsed-data
936 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
937 (should
938 ;; Note: Headline's number is in fact a list of numbers.
939 (equal '(2)
940 (org-element-map
941 tree 'link
942 (lambda (link)
943 (org-export-get-ordinal
944 (org-export-resolve-fuzzy-link link info) info)) info t))))
945 ;; 3. Link to a target in an item should return item's number.
946 (org-test-with-parsed-data
947 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
948 (should
949 ;; Note: Item's number is in fact a list of numbers.
950 (equal '(1 2)
951 (org-element-map
952 tree 'link
953 (lambda (link)
954 (org-export-get-ordinal
955 (org-export-resolve-fuzzy-link link info) info)) info t))))
956 ;; 4. Link to a target in a footnote should return footnote's
957 ;; number.
958 (org-test-with-parsed-data "
959 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
960 (should
961 (equal '(2 3)
962 (org-element-map
963 tree 'link
964 (lambda (link)
965 (org-export-get-ordinal
966 (org-export-resolve-fuzzy-link link info) info)) info))))
967 ;; 5. Link to a named element should return sequence number of that
968 ;; element.
969 (org-test-with-parsed-data
970 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
971 (should
972 (= 2
973 (org-element-map
974 tree 'link
975 (lambda (link)
976 (org-export-get-ordinal
977 (org-export-resolve-fuzzy-link link info) info)) info t))))
978 ;; 6. Link to a target not within an item, a table, a footnote
979 ;; reference or definition should return section number.
980 (org-test-with-parsed-data
981 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
982 (should
983 (equal '(2)
984 (org-element-map
985 tree 'link
986 (lambda (link)
987 (org-export-get-ordinal
988 (org-export-resolve-fuzzy-link link info) info)) info t)))))
990 (ert-deftest test-org-export/resolve-coderef ()
991 "Test `org-export-resolve-coderef' specifications."
992 (let ((org-coderef-label-format "(ref:%s)"))
993 ;; 1. A link to a "-n -k -r" block returns line number.
994 (org-test-with-parsed-data
995 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
996 (should (= (org-export-resolve-coderef "coderef" info) 1)))
997 (org-test-with-parsed-data
998 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
999 (should (= (org-export-resolve-coderef "coderef" info) 1)))
1000 ;; 2. A link to a "-n -r" block returns line number.
1001 (org-test-with-parsed-data
1002 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
1003 (should (= (org-export-resolve-coderef "coderef" info) 1)))
1004 (org-test-with-parsed-data
1005 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1006 (should (= (org-export-resolve-coderef "coderef" info) 1)))
1007 ;; 3. A link to a "-n" block returns coderef.
1008 (org-test-with-parsed-data
1009 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1010 (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
1011 (org-test-with-parsed-data
1012 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
1013 (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
1014 ;; 4. A link to a "-r" block returns line number.
1015 (org-test-with-parsed-data
1016 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1017 (should (= (org-export-resolve-coderef "coderef" info) 1)))
1018 (org-test-with-parsed-data
1019 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
1020 (should (= (org-export-resolve-coderef "coderef" info) 1)))
1021 ;; 5. A link to a block without a switch returns coderef.
1022 (org-test-with-parsed-data
1023 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1024 (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
1025 (org-test-with-parsed-data
1026 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
1027 (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
1028 ;; 6. Correctly handle continued line numbers. A "+n" switch
1029 ;; should resume numbering from previous block with numbered
1030 ;; lines, ignoring blocks not numbering lines in the process.
1031 ;; A "-n" switch resets count.
1032 (org-test-with-parsed-data "
1033 #+BEGIN_EXAMPLE -n
1034 Text.
1035 #+END_EXAMPLE
1037 #+BEGIN_SRC emacs-lisp
1038 \(- 1 1)
1039 #+END_SRC
1041 #+BEGIN_SRC emacs-lisp +n -r
1042 \(+ 1 1) (ref:addition)
1043 #+END_SRC
1045 #+BEGIN_EXAMPLE -n -r
1046 Another text. (ref:text)
1047 #+END_EXAMPLE"
1048 (should (= (org-export-resolve-coderef "addition" info) 2))
1049 (should (= (org-export-resolve-coderef "text" info) 1)))
1050 ;; 7. Recognize coderef with user-specified syntax.
1051 (org-test-with-parsed-data
1052 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
1053 (should (equal (org-export-resolve-coderef "text" info) "text")))))
1055 (ert-deftest test-org-export/resolve-fuzzy-link ()
1056 "Test `org-export-resolve-fuzzy-link' specifications."
1057 ;; 1. Match target objects.
1058 (org-test-with-parsed-data "<<target>> [[target]]"
1059 (should
1060 (org-export-resolve-fuzzy-link
1061 (org-element-map tree 'link 'identity info t) info)))
1062 ;; 2. Match target elements.
1063 (org-test-with-parsed-data "#+TARGET: target\n[[target]]"
1064 (should
1065 (org-export-resolve-fuzzy-link
1066 (org-element-map tree 'link 'identity info t) info)))
1067 ;; 3. Match named elements.
1068 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
1069 (should
1070 (org-export-resolve-fuzzy-link
1071 (org-element-map tree 'link 'identity info t) info)))
1072 ;; 4. Match exact headline's name.
1073 (org-test-with-parsed-data "* My headline\n[[My headline]]"
1074 (should
1075 (org-export-resolve-fuzzy-link
1076 (org-element-map tree 'link 'identity info t) info)))
1077 ;; 5. Targets objects have priority over named elements and headline
1078 ;; titles.
1079 (org-test-with-parsed-data
1080 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
1081 (should
1082 (eq 'target
1083 (org-element-type
1084 (org-export-resolve-fuzzy-link
1085 (org-element-map tree 'link 'identity info t) info)))))
1086 ;; 6. Named elements have priority over headline titles.
1087 (org-test-with-parsed-data
1088 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
1089 (should
1090 (eq 'paragraph
1091 (org-element-type
1092 (org-export-resolve-fuzzy-link
1093 (org-element-map tree 'link 'identity info t) info)))))
1094 ;; 7. If link's path starts with a "*", only match headline titles,
1095 ;; though.
1096 (org-test-with-parsed-data
1097 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
1098 (should
1099 (eq 'headline
1100 (org-element-type
1101 (org-export-resolve-fuzzy-link
1102 (org-element-map tree 'link 'identity info t) info)))))
1103 ;; 8. Return nil if no match.
1104 (org-test-with-parsed-data "[[target]]"
1105 (should-not
1106 (org-export-resolve-fuzzy-link
1107 (org-element-map tree 'link 'identity info t) info))))
1109 (ert-deftest test-org-export/resolve-id-link ()
1110 "Test `org-export-resolve-id-link' specifications."
1111 ;; 1. Regular test for custom-id link.
1112 (org-test-with-parsed-data "* Headline1
1113 :PROPERTIES:
1114 :CUSTOM-ID: test
1115 :END:
1116 * Headline 2
1117 \[[#test]]"
1118 (should
1119 (org-export-resolve-id-link
1120 (org-element-map tree 'link 'identity info t) info)))
1121 ;; 2. Failing test for custom-id link.
1122 (org-test-with-parsed-data "* Headline1
1123 :PROPERTIES:
1124 :CUSTOM-ID: test
1125 :END:
1126 * Headline 2
1127 \[[#no-match]]"
1128 (should-not
1129 (org-export-resolve-id-link
1130 (org-element-map tree 'link 'identity info t) info)))
1131 ;; 3. Test for internal id target.
1132 (org-test-with-parsed-data "* Headline1
1133 :PROPERTIES:
1134 :ID: aaaa
1135 :END:
1136 * Headline 2
1137 \[[id:aaaa]]"
1138 (should
1139 (org-export-resolve-id-link
1140 (org-element-map tree 'link 'identity info t) info)))
1141 ;; 4. Test for external id target.
1142 (org-test-with-parsed-data "[[id:aaaa]]"
1143 (should
1144 (org-export-resolve-id-link
1145 (org-element-map tree 'link 'identity info t)
1146 (org-combine-plists info '(:id-alist (("aaaa" . "external-file"))))))))
1148 (ert-deftest test-org-export/resolve-radio-link ()
1149 "Test `org-export-resolve-radio-link' specifications."
1150 ;; Standard test.
1151 (org-test-with-temp-text "<<<radio>>> radio"
1152 (org-update-radio-target-regexp)
1153 (should
1154 (let* ((tree (org-element-parse-buffer))
1155 (info `(:parse-tree ,tree)))
1156 (org-export-resolve-radio-link
1157 (org-element-map tree 'link 'identity info t)
1158 info))))
1159 ;; Radio target with objects.
1160 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
1161 (org-update-radio-target-regexp)
1162 (should
1163 (let* ((tree (org-element-parse-buffer))
1164 (info `(:parse-tree ,tree)))
1165 (org-export-resolve-radio-link
1166 (org-element-map tree 'link 'identity info t)
1167 info)))))
1171 ;;; Src-block and example-block
1173 (ert-deftest test-org-export/unravel-code ()
1174 "Test `org-export-unravel-code' function."
1175 (let ((org-coderef-label-format "(ref:%s)"))
1176 ;; 1. Code without reference.
1177 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
1178 (should (equal (org-export-unravel-code (org-element-at-point))
1179 '("(+ 1 1)\n"))))
1180 ;; 2. Code with reference.
1181 (org-test-with-temp-text
1182 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
1183 (should (equal (org-export-unravel-code (org-element-at-point))
1184 '("(+ 1 1)\n" (1 . "test")))))
1185 ;; 3. Code with user-defined reference.
1186 (org-test-with-temp-text
1187 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
1188 (should (equal (org-export-unravel-code (org-element-at-point))
1189 '("(+ 1 1)\n" (1 . "test")))))
1190 ;; 4. Code references keys are relative to the current block.
1191 (org-test-with-temp-text "
1192 #+BEGIN_EXAMPLE -n
1193 \(+ 1 1)
1194 #+END_EXAMPLE
1195 #+BEGIN_EXAMPLE +n
1196 \(+ 2 2)
1197 \(+ 3 3) (ref:one)
1198 #+END_EXAMPLE"
1199 (goto-line 5)
1200 (should (equal (org-export-unravel-code (org-element-at-point))
1201 '("(+ 2 2)\n(+ 3 3)\n" (2 . "one")))))))
1205 ;;; Smart Quotes
1207 (ert-deftest test-org-export/activate-smart-quotes ()
1208 "Test `org-export-activate-smart-quotes' specifications."
1209 ;; Opening double quotes: standard test.
1210 (should
1211 (equal
1212 '("some &ldquo;paragraph")
1213 (let ((org-export-default-language "en"))
1214 (org-test-with-parsed-data "some \"paragraph"
1215 (org-element-map
1216 tree 'plain-text
1217 (lambda (s) (org-export-activate-smart-quotes s :html info))
1218 info)))))
1219 ;; Opening quotes: at the beginning of a paragraph.
1220 (should
1221 (equal
1222 '("&ldquo;begin")
1223 (let ((org-export-default-language "en"))
1224 (org-test-with-parsed-data "\"begin"
1225 (org-element-map
1226 tree 'plain-text
1227 (lambda (s) (org-export-activate-smart-quotes s :html info))
1228 info)))))
1229 ;; Opening quotes: after an object.
1230 (should
1231 (equal
1232 '("&ldquo;begin")
1233 (let ((org-export-default-language "en"))
1234 (org-test-with-parsed-data "=verb= \"begin"
1235 (org-element-map
1236 tree 'plain-text
1237 (lambda (s) (org-export-activate-smart-quotes s :html info))
1238 info)))))
1239 ;; Closing quotes: standard test.
1240 (should
1241 (equal
1242 '("some&rdquo; paragraph")
1243 (let ((org-export-default-language "en"))
1244 (org-test-with-parsed-data "some\" paragraph"
1245 (org-element-map
1246 tree 'plain-text
1247 (lambda (s) (org-export-activate-smart-quotes s :html info))
1248 info)))))
1249 ;; Closing quotes: at the end of a paragraph.
1250 (should
1251 (equal
1252 '("end&rdquo;")
1253 (let ((org-export-default-language "en"))
1254 (org-test-with-parsed-data "end\""
1255 (org-element-map
1256 tree 'plain-text
1257 (lambda (s) (org-export-activate-smart-quotes s :html info))
1258 info)))))
1259 ;; Apostrophe: standard test.
1260 (should
1261 (equal
1262 '("It shouldn&rsquo;t fail")
1263 (let ((org-export-default-language "en"))
1264 (org-test-with-parsed-data "It shouldn't fail"
1265 (org-element-map
1266 tree 'plain-text
1267 (lambda (s) (org-export-activate-smart-quotes s :html info))
1268 info)))))
1269 ;; Apostrophe: before an object.
1270 (should
1271 (equal
1272 '("a&rsquo;")
1273 (let ((org-export-default-language "en"))
1274 (org-test-with-parsed-data "a'=b="
1275 (org-element-map
1276 tree 'plain-text
1277 (lambda (s) (org-export-activate-smart-quotes s :html info))
1278 info)))))
1279 ;; Apostrophe: after an object.
1280 (should
1281 (equal
1282 '("&rsquo;s")
1283 (let ((org-export-default-language "en"))
1284 (org-test-with-parsed-data "=code='s"
1285 (org-element-map
1286 tree 'plain-text
1287 (lambda (s) (org-export-activate-smart-quotes s :html info))
1288 info)))))
1289 ;; Special case: isolated quotes.
1290 (should
1291 (equal '("&ldquo;" "&rdquo;")
1292 (let ((org-export-default-language "en"))
1293 (org-test-with-parsed-data "\"$x$\""
1294 (org-element-map
1295 tree 'plain-text
1296 (lambda (s) (org-export-activate-smart-quotes s :html info))
1297 info)))))
1298 ;; Smart quotes in secondary strings.
1299 (should
1300 (equal '("&ldquo;" "&rdquo;")
1301 (let ((org-export-default-language "en"))
1302 (org-test-with-parsed-data "* \"$x$\""
1303 (org-element-map
1304 tree 'plain-text
1305 (lambda (s) (org-export-activate-smart-quotes s :html info))
1306 info)))))
1307 ;; Smart quotes in document keywords.
1308 (should
1309 (equal '("&ldquo;" "&rdquo;")
1310 (let ((org-export-default-language "en"))
1311 (org-test-with-parsed-data "#+TITLE: \"$x$\""
1312 (org-element-map
1313 (plist-get info :title) 'plain-text
1314 (lambda (s) (org-export-activate-smart-quotes s :html info))
1315 info)))))
1316 ;; Smart quotes in parsed affiliated keywords.
1317 (should
1318 (equal '("&ldquo;" "&rdquo;" "Paragraph")
1319 (let ((org-export-default-language "en"))
1320 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
1321 (org-element-map
1322 tree 'plain-text
1323 (lambda (s) (org-export-activate-smart-quotes s :html info))
1324 info nil nil t))))))
1328 ;;; Tables
1330 (ert-deftest test-org-export/special-column ()
1331 "Test if the table's special column is properly recognized."
1332 ;; 1. First column is special if it contains only a special marking
1333 ;; characters or empty cells.
1334 (org-test-with-temp-text "
1335 | ! | 1 |
1336 | | 2 |"
1337 (should
1338 (org-export-table-has-special-column-p
1339 (org-element-map
1340 (org-element-parse-buffer) 'table 'identity nil 'first-match))))
1341 ;; 2. If the column contains anything else, it isn't special.
1342 (org-test-with-temp-text "
1343 | ! | 1 |
1344 | b | 2 |"
1345 (should-not
1346 (org-export-table-has-special-column-p
1347 (org-element-map
1348 (org-element-parse-buffer) 'table 'identity nil 'first-match))))
1349 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
1350 ;; and "!".
1351 (org-test-with-temp-text "
1352 | # | 1 |
1353 | ^ | 2 |
1354 | * | 3 |
1355 | _ | 4 |
1356 | / | 5 |
1357 | $ | 6 |
1358 | ! | 7 |"
1359 (should
1360 (org-export-table-has-special-column-p
1361 (org-element-map
1362 (org-element-parse-buffer) 'table 'identity nil 'first-match))))
1363 ;; 4. A first column with only empty cells isn't considered as
1364 ;; special.
1365 (org-test-with-temp-text "
1366 | | 1 |
1367 | | 2 |"
1368 (should-not
1369 (org-export-table-has-special-column-p
1370 (org-element-map
1371 (org-element-parse-buffer) 'table 'identity nil 'first-match)))))
1373 (ert-deftest test-org-export/table-row-is-special-p ()
1374 "Test `org-export-table-row-is-special-p' specifications."
1375 ;; 1. A row is special if it has a special marking character in the
1376 ;; special column.
1377 (org-test-with-parsed-data "| ! | 1 |"
1378 (should
1379 (org-export-table-row-is-special-p
1380 (org-element-map tree 'table-row 'identity nil 'first-match) info)))
1381 ;; 2. A row is special when its first field is "/"
1382 (org-test-with-parsed-data "
1383 | / | 1 |
1384 | a | b |"
1385 (should
1386 (org-export-table-row-is-special-p
1387 (org-element-map tree 'table-row 'identity nil 'first-match) info)))
1388 ;; 3. A row only containing alignment cookies is also considered as
1389 ;; special.
1390 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
1391 (should
1392 (org-export-table-row-is-special-p
1393 (org-element-map tree 'table-row 'identity nil 'first-match) info)))
1394 ;; 4. Everything else isn't considered as special.
1395 (org-test-with-parsed-data "| \alpha | | c |"
1396 (should-not
1397 (org-export-table-row-is-special-p
1398 (org-element-map tree 'table-row 'identity nil 'first-match) info)))
1399 ;; 5. Table's rules are never considered as special rows.
1400 (org-test-with-parsed-data "|---+---|"
1401 (should-not
1402 (org-export-table-row-is-special-p
1403 (org-element-map tree 'table-row 'identity nil 'first-match) info))))
1405 (ert-deftest test-org-export/has-header-p ()
1406 "Test `org-export-table-has-header-p' specifications."
1407 ;; 1. With an header.
1408 (org-test-with-parsed-data "
1409 | a | b |
1410 |---+---|
1411 | c | d |"
1412 (should
1413 (org-export-table-has-header-p
1414 (org-element-map tree 'table 'identity info 'first-match)
1415 info)))
1416 ;; 2. Without an header.
1417 (org-test-with-parsed-data "
1418 | a | b |
1419 | c | d |"
1420 (should-not
1421 (org-export-table-has-header-p
1422 (org-element-map tree 'table 'identity info 'first-match)
1423 info)))
1424 ;; 3. Don't get fooled with starting and ending rules.
1425 (org-test-with-parsed-data "
1426 |---+---|
1427 | a | b |
1428 | c | d |
1429 |---+---|"
1430 (should-not
1431 (org-export-table-has-header-p
1432 (org-element-map tree 'table 'identity info 'first-match)
1433 info))))
1435 (ert-deftest test-org-export/table-row-group ()
1436 "Test `org-export-table-row-group' specifications."
1437 ;; 1. A rule creates a new group.
1438 (org-test-with-parsed-data "
1439 | a | b |
1440 |---+---|
1441 | 1 | 2 |"
1442 (should
1443 (equal
1444 '(1 nil 2)
1445 (mapcar (lambda (row) (org-export-table-row-group row info))
1446 (org-element-map tree 'table-row 'identity)))))
1447 ;; 2. Special rows are ignored in count.
1448 (org-test-with-parsed-data "
1449 | / | < | > |
1450 |---|---+---|
1451 | | 1 | 2 |"
1452 (should
1453 (equal
1454 '(nil nil 1)
1455 (mapcar (lambda (row) (org-export-table-row-group row info))
1456 (org-element-map tree 'table-row 'identity)))))
1457 ;; 3. Double rules also are ignored in count.
1458 (org-test-with-parsed-data "
1459 | a | b |
1460 |---+---|
1461 |---+---|
1462 | 1 | 2 |"
1463 (should
1464 (equal
1465 '(1 nil nil 2)
1466 (mapcar (lambda (row) (org-export-table-row-group row info))
1467 (org-element-map tree 'table-row 'identity))))))
1469 (ert-deftest test-org-export/table-cell-width ()
1470 "Test `org-export-table-cell-width' specifications."
1471 ;; 1. Width is primarily determined by width cookies. If no cookie
1472 ;; is found, cell's width is nil.
1473 (org-test-with-parsed-data "
1474 | / | <l> | <6> | <l7> |
1475 | | a | b | c |"
1476 (should
1477 (equal
1478 '(nil 6 7)
1479 (mapcar (lambda (cell) (org-export-table-cell-width cell info))
1480 (org-element-map tree 'table-cell 'identity info)))))
1481 ;; 2. The last width cookie has precedence.
1482 (org-test-with-parsed-data "
1483 | <6> |
1484 | <7> |
1485 | a |"
1486 (should
1487 (equal
1488 '(7)
1489 (mapcar (lambda (cell) (org-export-table-cell-width cell info))
1490 (org-element-map tree 'table-cell 'identity info)))))
1491 ;; 3. Valid width cookies must have a specific row.
1492 (org-test-with-parsed-data "| <6> | cell |"
1493 (should
1494 (equal
1495 '(nil nil)
1496 (mapcar (lambda (cell) (org-export-table-cell-width cell info))
1497 (org-element-map tree 'table-cell 'identity))))))
1499 (ert-deftest test-org-export/table-cell-alignment ()
1500 "Test `org-export-table-cell-alignment' specifications."
1501 (let ((org-table-number-fraction 0.5)
1502 (org-table-number-regexp "^[0-9]+$"))
1503 ;; 1. Alignment is primarily determined by alignment cookies.
1504 (org-test-with-temp-text "| <l> | <c> | <r> |"
1505 (let* ((tree (org-element-parse-buffer))
1506 (info `(:parse-tree ,tree)))
1507 (should
1508 (equal
1509 '(left center right)
1510 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info))
1511 (org-element-map tree 'table-cell 'identity))))))
1512 ;; 2. The last alignment cookie has precedence.
1513 (org-test-with-parsed-data "
1514 | <l8> |
1515 | cell |
1516 | <r9> |"
1517 (should
1518 (equal
1519 '(right right right)
1520 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info))
1521 (org-element-map tree 'table-cell 'identity)))))
1522 ;; 3. If there's no cookie, cell's contents determine alignment.
1523 ;; A column mostly made of cells containing numbers will align
1524 ;; its cells to the right.
1525 (org-test-with-parsed-data "
1526 | 123 |
1527 | some text |
1528 | 12345 |"
1529 (should
1530 (equal
1531 '(right right right)
1532 (mapcar (lambda (cell)
1533 (org-export-table-cell-alignment cell info))
1534 (org-element-map tree 'table-cell 'identity)))))
1535 ;; 4. Otherwise, they will be aligned to the left.
1536 (org-test-with-parsed-data "
1537 | text |
1538 | some text |
1539 | \alpha |"
1540 (should
1541 (equal
1542 '(left left left)
1543 (mapcar (lambda (cell)
1544 (org-export-table-cell-alignment cell info))
1545 (org-element-map tree 'table-cell 'identity)))))))
1547 (ert-deftest test-org-export/table-cell-borders ()
1548 "Test `org-export-table-cell-borders' specifications."
1549 ;; 1. Recognize various column groups indicators.
1550 (org-test-with-parsed-data "| / | < | > | <> |"
1551 (should
1552 (equal
1553 '((right bottom top) (left bottom top) (right bottom top)
1554 (right left bottom top))
1555 (mapcar (lambda (cell)
1556 (org-export-table-cell-borders cell info))
1557 (org-element-map tree 'table-cell 'identity)))))
1558 ;; 2. Accept shortcuts to define column groups.
1559 (org-test-with-parsed-data "| / | < | < |"
1560 (should
1561 (equal
1562 '((right bottom top) (right left bottom top) (left bottom top))
1563 (mapcar (lambda (cell)
1564 (org-export-table-cell-borders cell info))
1565 (org-element-map tree 'table-cell 'identity)))))
1566 ;; 3. A valid column groups row must start with a "/".
1567 (org-test-with-parsed-data "
1568 | | < |
1569 | a | b |"
1570 (should
1571 (equal '((top) (top) (bottom) (bottom))
1572 (mapcar (lambda (cell)
1573 (org-export-table-cell-borders cell info))
1574 (org-element-map tree 'table-cell 'identity)))))
1575 ;; 4. Take table rules into consideration.
1576 (org-test-with-parsed-data "
1577 | 1 |
1578 |---|
1579 | 2 |"
1580 (should
1581 (equal '((below top) (bottom above))
1582 (mapcar (lambda (cell)
1583 (org-export-table-cell-borders cell info))
1584 (org-element-map tree 'table-cell 'identity)))))
1585 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
1586 ;; (resp. `bottom' and `below') borders. Any special row is
1587 ;; ignored.
1588 (org-test-with-parsed-data "
1589 |---+----|
1590 | / | |
1591 | | 1 |
1592 |---+----|"
1593 (should
1594 (equal '((bottom below top above))
1595 (last
1596 (mapcar (lambda (cell)
1597 (org-export-table-cell-borders cell info))
1598 (org-element-map tree 'table-cell 'identity)))))))
1600 (ert-deftest test-org-export/table-dimensions ()
1601 "Test `org-export-table-dimensions' specifications."
1602 ;; 1. Standard test.
1603 (org-test-with-parsed-data "
1604 | 1 | 2 | 3 |
1605 | 4 | 5 | 6 |"
1606 (should
1607 (equal '(2 . 3)
1608 (org-export-table-dimensions
1609 (org-element-map tree 'table 'identity info 'first-match) info))))
1610 ;; 2. Ignore horizontal rules and special columns.
1611 (org-test-with-parsed-data "
1612 | / | < | > |
1613 | 1 | 2 | 3 |
1614 |---+---+---|
1615 | 4 | 5 | 6 |"
1616 (should
1617 (equal '(2 . 3)
1618 (org-export-table-dimensions
1619 (org-element-map tree 'table 'identity info 'first-match) info)))))
1621 (ert-deftest test-org-export/table-cell-address ()
1622 "Test `org-export-table-cell-address' specifications."
1623 ;; 1. Standard test: index is 0-based.
1624 (org-test-with-parsed-data "| a | b |"
1625 (should
1626 (equal '((0 . 0) (0 . 1))
1627 (org-element-map
1628 tree 'table-cell
1629 (lambda (cell) (org-export-table-cell-address cell info))
1630 info))))
1631 ;; 2. Special column isn't counted, nor are special rows.
1632 (org-test-with-parsed-data "
1633 | / | <> |
1634 | | c |"
1635 (should
1636 (equal '(0 . 0)
1637 (org-export-table-cell-address
1638 (car (last (org-element-map tree 'table-cell 'identity info)))
1639 info))))
1640 ;; 3. Tables rules do not count either.
1641 (org-test-with-parsed-data "
1642 | a |
1643 |---|
1644 | b |
1645 |---|
1646 | c |"
1647 (should
1648 (equal '(2 . 0)
1649 (org-export-table-cell-address
1650 (car (last (org-element-map tree 'table-cell 'identity info)))
1651 info))))
1652 ;; 4. Return nil for special cells.
1653 (org-test-with-parsed-data "| / | a |"
1654 (should-not
1655 (org-export-table-cell-address
1656 (org-element-map tree 'table-cell 'identity nil 'first-match)
1657 info))))
1659 (ert-deftest test-org-export/get-table-cell-at ()
1660 "Test `org-export-get-table-cell-at' specifications."
1661 ;; 1. Address ignores special columns, special rows and rules.
1662 (org-test-with-parsed-data "
1663 | / | <> |
1664 | | a |
1665 |---+----|
1666 | | b |"
1667 (should
1668 (equal '("b")
1669 (org-element-contents
1670 (org-export-get-table-cell-at
1671 '(1 . 0)
1672 (org-element-map tree 'table 'identity info 'first-match)
1673 info)))))
1674 ;; 2. Return value for a non-existent address is nil.
1675 (org-test-with-parsed-data "| a |"
1676 (should-not
1677 (org-export-get-table-cell-at
1678 '(2 . 2)
1679 (org-element-map tree 'table 'identity info 'first-match)
1680 info)))
1681 (org-test-with-parsed-data "| / |"
1682 (should-not
1683 (org-export-get-table-cell-at
1684 '(0 . 0)
1685 (org-element-map tree 'table 'identity info 'first-match)
1686 info))))
1688 (ert-deftest test-org-export/table-cell-starts-colgroup-p ()
1689 "Test `org-export-table-cell-starts-colgroup-p' specifications."
1690 ;; 1. A cell at a beginning of a row always starts a column group.
1691 (org-test-with-parsed-data "| a |"
1692 (should
1693 (org-export-table-cell-starts-colgroup-p
1694 (org-element-map tree 'table-cell 'identity info 'first-match)
1695 info)))
1696 ;; 2. Special column should be ignored when determining the
1697 ;; beginning of the row.
1698 (org-test-with-parsed-data "
1699 | / | |
1700 | | a |"
1701 (should
1702 (org-export-table-cell-starts-colgroup-p
1703 (org-element-map tree 'table-cell 'identity info 'first-match)
1704 info)))
1705 ;; 2. Explicit column groups.
1706 (org-test-with-parsed-data "
1707 | / | | < |
1708 | a | b | c |"
1709 (should
1710 (equal
1711 '(yes no yes)
1712 (org-element-map
1713 tree 'table-cell
1714 (lambda (cell)
1715 (if (org-export-table-cell-starts-colgroup-p cell info) 'yes 'no))
1716 info)))))
1718 (ert-deftest test-org-export/table-cell-ends-colgroup-p ()
1719 "Test `org-export-table-cell-ends-colgroup-p' specifications."
1720 ;; 1. A cell at the end of a row always ends a column group.
1721 (org-test-with-parsed-data "| a |"
1722 (should
1723 (org-export-table-cell-ends-colgroup-p
1724 (org-element-map tree 'table-cell 'identity info 'first-match)
1725 info)))
1726 ;; 2. Special column should be ignored when determining the
1727 ;; beginning of the row.
1728 (org-test-with-parsed-data "
1729 | / | |
1730 | | a |"
1731 (should
1732 (org-export-table-cell-ends-colgroup-p
1733 (org-element-map tree 'table-cell 'identity info 'first-match)
1734 info)))
1735 ;; 3. Explicit column groups.
1736 (org-test-with-parsed-data "
1737 | / | < | |
1738 | a | b | c |"
1739 (should
1740 (equal
1741 '(yes no yes)
1742 (org-element-map
1743 tree 'table-cell
1744 (lambda (cell)
1745 (if (org-export-table-cell-ends-colgroup-p cell info) 'yes 'no))
1746 info)))))
1748 (ert-deftest test-org-export/table-row-starts-rowgroup-p ()
1749 "Test `org-export-table-row-starts-rowgroup-p' specifications."
1750 ;; 1. A row at the beginning of a table always starts a row group.
1751 ;; So does a row following a table rule.
1752 (org-test-with-parsed-data "
1753 | a |
1754 |---|
1755 | b |"
1756 (should
1757 (equal
1758 '(yes no yes)
1759 (org-element-map
1760 tree 'table-row
1761 (lambda (row)
1762 (if (org-export-table-row-starts-rowgroup-p row info) 'yes 'no))
1763 info))))
1764 ;; 2. Special rows should be ignored when determining the beginning
1765 ;; of the row.
1766 (org-test-with-parsed-data "
1767 | / | < |
1768 | | a |
1769 |---+---|
1770 | / | < |
1771 | | b |"
1772 (should
1773 (equal
1774 '(yes no yes)
1775 (org-element-map
1776 tree 'table-row
1777 (lambda (row)
1778 (if (org-export-table-row-starts-rowgroup-p row info) 'yes 'no))
1779 info)))))
1781 (ert-deftest test-org-export/table-row-ends-rowgroup-p ()
1782 "Test `org-export-table-row-ends-rowgroup-p' specifications."
1783 ;; 1. A row at the end of a table always ends a row group. So does
1784 ;; a row preceding a table rule.
1785 (org-test-with-parsed-data "
1786 | a |
1787 |---|
1788 | b |"
1789 (should
1790 (equal
1791 '(yes no yes)
1792 (org-element-map
1793 tree 'table-row
1794 (lambda (row)
1795 (if (org-export-table-row-ends-rowgroup-p row info) 'yes 'no))
1796 info))))
1797 ;; 2. Special rows should be ignored when determining the beginning
1798 ;; of the row.
1799 (org-test-with-parsed-data "
1800 | | a |
1801 | / | < |
1802 |---+---|
1803 | | b |
1804 | / | < |"
1805 (should
1806 (equal
1807 '(yes no yes)
1808 (org-element-map
1809 tree 'table-row
1810 (lambda (row)
1811 (if (org-export-table-row-ends-rowgroup-p row info) 'yes 'no))
1812 info)))))
1814 (ert-deftest test-org-export/table-row-starts-header-p ()
1815 "Test `org-export-table-row-starts-header-p' specifications."
1816 ;; 1. Only the row starting the first row group starts the table
1817 ;; header.
1818 (org-test-with-parsed-data "
1819 | a |
1820 | b |
1821 |---|
1822 | c |"
1823 (should
1824 (equal
1825 '(yes no no no)
1826 (org-element-map
1827 tree 'table-row
1828 (lambda (row)
1829 (if (org-export-table-row-starts-header-p row info) 'yes 'no))
1830 info))))
1831 ;; 2. A row cannot start an header if there's no header in the
1832 ;; table.
1833 (org-test-with-parsed-data "
1834 | a |
1835 |---|"
1836 (should-not
1837 (org-export-table-row-starts-header-p
1838 (org-element-map tree 'table-row 'identity info 'first-match)
1839 info))))
1841 (ert-deftest test-org-export/table-row-ends-header-p ()
1842 "Test `org-export-table-row-ends-header-p' specifications."
1843 ;; 1. Only the row starting the first row group starts the table
1844 ;; header.
1845 (org-test-with-parsed-data "
1846 | a |
1847 | b |
1848 |---|
1849 | c |"
1850 (should
1851 (equal
1852 '(no yes no no)
1853 (org-element-map
1854 tree 'table-row
1855 (lambda (row)
1856 (if (org-export-table-row-ends-header-p row info) 'yes 'no))
1857 info))))
1858 ;; 2. A row cannot start an header if there's no header in the
1859 ;; table.
1860 (org-test-with-parsed-data "
1861 | a |
1862 |---|"
1863 (should-not
1864 (org-export-table-row-ends-header-p
1865 (org-element-map tree 'table-row 'identity info 'first-match)
1866 info))))
1870 ;;; Topology
1872 (ert-deftest test-org-export/get-next-element ()
1873 "Test `org-export-get-next-element' specifications."
1874 ;; Standard test.
1875 (should
1876 (equal "b"
1877 (org-test-with-parsed-data "* Headline\n*a* b"
1878 (org-export-get-next-element
1879 (org-element-map tree 'bold 'identity info t) info))))
1880 ;; Return nil when no previous element.
1881 (should-not
1882 (org-test-with-parsed-data "* Headline\na *b*"
1883 (org-export-get-next-element
1884 (org-element-map tree 'bold 'identity info t) info)))
1885 ;; Non-exportable elements are ignored.
1886 (should-not
1887 (let ((org-export-with-timestamps nil))
1888 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
1889 (org-export-get-next-element
1890 (org-element-map tree 'entity 'identity info t) info))))
1891 ;; Find next element in secondary strings.
1892 (should
1893 (eq 'verbatim
1894 (org-test-with-parsed-data "* a =verb="
1895 (org-element-type
1896 (org-export-get-next-element
1897 (org-element-map tree 'plain-text 'identity info t) info)))))
1898 ;; Find next element in document keywords.
1899 (should
1900 (eq 'verbatim
1901 (org-test-with-parsed-data "#+TITLE: a =verb="
1902 (org-element-type
1903 (org-export-get-next-element
1904 (org-element-map
1905 (plist-get info :title) 'plain-text 'identity info t) info)))))
1906 ;; Find next element in parsed affiliated keywords.
1907 (should
1908 (eq 'verbatim
1909 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
1910 (org-element-type
1911 (org-export-get-next-element
1912 (org-element-map tree 'plain-text 'identity info t nil t) info))))))
1914 (ert-deftest test-org-export/get-previous-element ()
1915 "Test `org-export-get-previous-element' specifications."
1916 ;; Standard test.
1917 (should
1918 (equal "a "
1919 (org-test-with-parsed-data "* Headline\na *b*"
1920 (org-export-get-previous-element
1921 (org-element-map tree 'bold 'identity info t) info))))
1922 ;; Return nil when no previous element.
1923 (should-not
1924 (org-test-with-parsed-data "* Headline\n*a* b"
1925 (org-export-get-previous-element
1926 (org-element-map tree 'bold 'identity info t) info)))
1927 ;; Non-exportable elements are ignored.
1928 (should-not
1929 (let ((org-export-with-timestamps nil))
1930 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
1931 (org-export-get-previous-element
1932 (org-element-map tree 'entity 'identity info t) info))))
1933 ;; Find previous element in secondary strings.
1934 (should
1935 (eq 'verbatim
1936 (org-test-with-parsed-data "* =verb= a"
1937 (org-element-type
1938 (org-export-get-previous-element
1939 (org-element-map tree 'plain-text 'identity info t) info)))))
1940 ;; Find previous element in document keywords.
1941 (should
1942 (eq 'verbatim
1943 (org-test-with-parsed-data "#+TITLE: =verb= a"
1944 (org-element-type
1945 (org-export-get-previous-element
1946 (org-element-map
1947 (plist-get info :title) 'plain-text 'identity info t) info)))))
1948 ;; Find previous element in parsed affiliated keywords.
1949 (should
1950 (eq 'verbatim
1951 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
1952 (org-element-type
1953 (org-export-get-previous-element
1954 (org-element-map tree 'plain-text 'identity info t nil t) info))))))
1957 (provide 'test-org-export)
1958 ;;; test-org-export.el end here