org-export: Run a hook just before expanding include keywords and macros
[org-mode.git] / testing / lisp / test-org-export.el
blob132b5902e055b63669a362a2dd60bebb2ac00e07
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-processing-hook ()
496 "Test `org-export-before-processing-hook'."
497 (should
498 (equal
499 "#+MACRO: mac val\nTest\n"
500 (org-test-with-backend test
501 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
502 (let ((org-export-before-processing-hook
503 '((lambda (backend)
504 (while (re-search-forward "{{{" nil t)
505 (let ((object (org-element-context)))
506 (when (eq (org-element-type object) 'macro)
507 (delete-region
508 (org-element-property :begin object)
509 (org-element-property :end object)))))))))
510 (org-export-as 'test)))))))
512 (ert-deftest test-org-export/before-parsing-hook ()
513 "Test `org-export-before-parsing-hook'."
514 (should
515 (equal "Body 1\nBody 2\n"
516 (org-test-with-backend test
517 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
518 (let ((org-export-before-parsing-hook
519 '((lambda (backend)
520 (org-map-entries
521 (lambda ()
522 (delete-region (point) (progn (forward-line) (point)))))))))
523 (org-export-as 'test)))))))
527 ;;; Affiliated Keywords
529 (ert-deftest test-org-export/read-attribute ()
530 "Test `org-export-read-attribute' specifications."
531 ;; Standard test.
532 (should
533 (equal
534 (org-export-read-attribute
535 :attr_html
536 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
537 (org-element-at-point)))
538 '(:a 1 :b 2)))
539 ;; Return nil on empty attribute.
540 (should-not
541 (org-export-read-attribute
542 :attr_html
543 (org-test-with-temp-text "Paragraph" (org-element-at-point)))))
545 (ert-deftest test-org-export/get-caption ()
546 "Test `org-export-get-caption' specifications."
547 ;; Without optional argument, return long caption
548 (should
549 (equal
550 '("l")
551 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
552 (org-export-get-caption (org-element-at-point)))))
553 ;; With optional argument, return short caption.
554 (should
555 (equal
556 '("s")
557 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
558 (org-export-get-caption (org-element-at-point) t))))
559 ;; Multiple lines are separated by white spaces.
560 (should
561 (equal
562 '("a" " " "b")
563 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
564 (org-export-get-caption (org-element-at-point))))))
568 ;;; Export Snippets
570 (ert-deftest test-org-export/export-snippet ()
571 "Test export snippets transcoding."
572 (org-test-with-temp-text "@@test:A@@@@t:B@@"
573 (org-test-with-backend test
574 (let ((org-test-translate-alist
575 (cons (cons 'export-snippet
576 (lambda (snippet contents info)
577 (when (eq (org-export-snippet-backend snippet) 'test)
578 (org-element-property :value snippet))))
579 org-test-translate-alist)))
580 (let ((org-export-snippet-translation-alist nil))
581 (should (equal (org-export-as 'test) "A\n")))
582 (let ((org-export-snippet-translation-alist '(("t" . "test"))))
583 (should (equal (org-export-as 'test) "AB\n")))))))
587 ;;; Footnotes
589 (ert-deftest test-org-export/footnotes ()
590 "Test footnotes specifications."
591 (let ((org-footnote-section nil)
592 (org-export-with-footnotes t))
593 ;; 1. Read every type of footnote.
594 (should
595 (equal
596 '((1 . "A\n") (2 . "B") (3 . "C") (4 . "D"))
597 (org-test-with-parsed-data
598 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
599 (org-element-map
600 tree 'footnote-reference
601 (lambda (ref)
602 (let ((def (org-export-get-footnote-definition ref info)))
603 (cons (org-export-get-footnote-number ref info)
604 (if (eq (org-element-property :type ref) 'inline) (car def)
605 (car (org-element-contents
606 (car (org-element-contents def))))))))
607 info))))
608 ;; 2. Test nested footnotes order.
609 (org-test-with-parsed-data
610 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
611 (should
612 (equal
613 '((1 . "fn:1") (2 . "fn:2") (3 . "fn:3") (4))
614 (org-element-map
615 tree 'footnote-reference
616 (lambda (ref)
617 (when (org-export-footnote-first-reference-p ref info)
618 (cons (org-export-get-footnote-number ref info)
619 (org-element-property :label ref))))
620 info))))
621 ;; 3. Test nested footnote in invisible definitions.
622 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
623 ;; Hide definitions.
624 (narrow-to-region (point) (point-at-eol))
625 (let* ((tree (org-element-parse-buffer))
626 (info (org-combine-plists
627 `(:parse-tree ,tree)
628 (org-export-collect-tree-properties
629 tree (org-export-get-environment)))))
630 ;; Both footnotes should be seen.
631 (should
632 (= (length (org-export-collect-footnote-definitions tree info)) 2))))
633 ;; 4. Test footnotes definitions collection.
634 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
636 \[fn:2] B [fn:3] [fn::D].
638 \[fn:3] C."
639 (should (= (length (org-export-collect-footnote-definitions tree info))
640 4)))
641 ;; 5. Test export of footnotes defined outside parsing scope.
642 (org-test-with-temp-text "[fn:1] Out of scope
643 * Title
644 Paragraph[fn:1]"
645 (org-test-with-backend test
646 (let ((org-test-translate-alist
647 (cons (cons 'footnote-reference
648 (lambda (fn contents info)
649 (org-element-interpret-data
650 (org-export-get-footnote-definition fn info))))
651 org-test-translate-alist)))
652 (forward-line)
653 (should (equal "ParagraphOut of scope\n"
654 (org-export-as 'test 'subtree))))))))
658 ;;; Headlines and Inlinetasks
660 (ert-deftest test-org-export/get-relative-level ()
661 "Test `org-export-get-relative-level' specifications."
662 ;; Standard test.
663 (should
664 (equal '(1 2)
665 (let ((org-odd-levels-only nil))
666 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
667 (org-element-map
668 tree 'headline
669 (lambda (h) (org-export-get-relative-level h info))
670 info)))))
671 ;; Missing levels
672 (should
673 (equal '(1 3)
674 (let ((org-odd-levels-only nil))
675 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
676 (org-element-map
677 tree 'headline
678 (lambda (h) (org-export-get-relative-level h info))
679 info))))))
681 (ert-deftest test-org-export/low-level-p ()
682 "Test `org-export-low-level-p' specifications."
683 (should
684 (equal
685 '(no yes)
686 (let ((org-odd-levels-only nil))
687 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
688 (org-element-map
689 tree 'headline
690 (lambda (h) (if (org-export-low-level-p h info) 'yes 'no))
691 (plist-put info :headline-levels 1)))))))
693 (ert-deftest test-org-export/get-headline-number ()
694 "Test `org-export-get-headline-number' specifications."
695 ;; Standard test.
696 (should
697 (equal
698 '((1) (1 1))
699 (let ((org-odd-levels-only nil))
700 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
701 (org-element-map
702 tree 'headline
703 (lambda (h) (org-export-get-headline-number h info))
704 info)))))
705 ;; Missing levels are replaced with 0.
706 (should
707 (equal
708 '((1) (1 0 1))
709 (let ((org-odd-levels-only nil))
710 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
711 (org-element-map
712 tree 'headline
713 (lambda (h) (org-export-get-headline-number h info))
714 info))))))
716 (ert-deftest test-org-export/numbered-headline-p ()
717 "Test `org-export-numbered-headline-p' specifications."
718 ;; If `:section-numbers' is nil, never number headlines.
719 (should-not
720 (org-test-with-parsed-data "* Headline"
721 (org-element-map
722 tree 'headline
723 (lambda (h) (org-export-numbered-headline-p h info))
724 (plist-put info :section-numbers nil))))
725 ;; If `:section-numbers' is a number, only number headlines with
726 ;; a level greater that it.
727 (should
728 (equal
729 '(yes no)
730 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
731 (org-element-map
732 tree 'headline
733 (lambda (h) (if (org-export-numbered-headline-p h info) 'yes 'no))
734 (plist-put info :section-numbers 1)))))
735 ;; Otherwise, headlines are always numbered.
736 (should
737 (org-test-with-parsed-data "* Headline"
738 (org-element-map
739 tree 'headline
740 (lambda (h) (org-export-numbered-headline-p h info))
741 (plist-put info :section-numbers t)))))
743 (ert-deftest test-org-export/number-to-roman ()
744 "Test `org-export-number-to-roman' specifications."
745 ;; If number is negative, return it as a string.
746 (should (equal (org-export-number-to-roman -1) "-1"))
747 ;; Otherwise, return it as a roman number.
748 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
750 (ert-deftest test-org-export/get-tags ()
751 "Test `org-export-get-tags' specifications."
752 (let ((org-export-exclude-tags '("noexport"))
753 (org-export-select-tags '("export")))
754 ;; Standard test: tags which are not a select tag, an exclude tag,
755 ;; or specified as optional argument shouldn't be ignored.
756 (should
757 (org-test-with-parsed-data "* Headline :tag:"
758 (org-export-get-tags (org-element-map tree 'headline 'identity info t)
759 info)))
760 ;; Exclude tags are removed.
761 (should-not
762 (org-test-with-parsed-data "* Headline :noexport:"
763 (org-export-get-tags (org-element-map tree 'headline 'identity info t)
764 info)))
765 ;; Select tags are removed.
766 (should-not
767 (org-test-with-parsed-data "* Headline :export:"
768 (org-export-get-tags (org-element-map tree 'headline 'identity info t)
769 info)))
770 (should
771 (equal
772 '("tag")
773 (org-test-with-parsed-data "* Headline :tag:export:"
774 (org-export-get-tags (org-element-map tree 'headline 'identity info t)
775 info))))
776 ;; Tags provided in the optional argument are also ignored.
777 (should-not
778 (org-test-with-parsed-data "* Headline :ignore:"
779 (org-export-get-tags (org-element-map tree 'headline 'identity info t)
780 info '("ignore"))))
781 ;; Allow tag inheritance.
782 (should
783 (equal
784 '(("tag") ("tag"))
785 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
786 (org-element-map
787 tree 'headline
788 (lambda (hl) (org-export-get-tags hl info nil t)) info))))
789 ;; Tag inheritance checks FILETAGS keywords.
790 (should
791 (equal
792 '(("a" "b" "tag"))
793 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
794 (org-element-map
795 tree 'headline
796 (lambda (hl) (org-export-get-tags hl info nil t)) info))))))
798 (ert-deftest test-org-export/get-node-property ()
799 "Test`org-export-get-node-property' specifications."
800 ;; Standard test.
801 (should
802 (equal "value"
803 (org-test-with-parsed-data "* Headline
804 :PROPERTIES:
805 :prop: value
806 :END:"
807 (org-export-get-node-property
808 :prop (org-element-map tree 'headline 'identity nil t)))))
809 ;; Test inheritance.
810 (should
811 (equal "value"
812 (org-test-with-parsed-data "* Parent
813 :PROPERTIES:
814 :prop: value
815 :END:
816 ** Headline
817 Paragraph"
818 (org-export-get-node-property
819 :prop (org-element-map tree 'paragraph 'identity nil t) t))))
820 ;; Cannot return a value before the first headline.
821 (should-not
822 (org-test-with-parsed-data "Paragraph
823 * Headline
824 :PROPERTIES:
825 :prop: value
826 :END:"
827 (org-export-get-node-property
828 :prop (org-element-map tree 'paragraph 'identity nil t)))))
830 (ert-deftest test-org-export/get-category ()
831 "Test `org-export-get-category' specifications."
832 ;; Standard test.
833 (should
834 (equal "value"
835 (org-test-with-parsed-data "* Headline
836 :PROPERTIES:
837 :CATEGORY: value
838 :END:"
839 (org-export-get-category
840 (org-element-map tree 'headline 'identity nil t) info))))
841 ;; Test inheritance from a parent headline.
842 (should
843 (equal '("value" "value")
844 (org-test-with-parsed-data "* Headline1
845 :PROPERTIES:
846 :CATEGORY: value
847 :END:
848 ** Headline2"
849 (org-element-map
850 tree 'headline
851 (lambda (hl) (org-export-get-category hl info)) info))))
852 ;; Test inheritance from #+CATEGORY keyword
853 (should
854 (equal "value"
855 (org-test-with-parsed-data "#+CATEGORY: value
856 * Headline"
857 (org-export-get-category
858 (org-element-map tree 'headline 'identity nil t) info))))
859 ;; Test inheritance from file name.
860 (should
861 (equal "test"
862 (org-test-with-parsed-data "* Headline"
863 (let ((info (plist-put info :input-file "~/test.org")))
864 (org-export-get-category
865 (org-element-map tree 'headline 'identity nil t) info)))))
866 ;; Fall-back value.
867 (should
868 (equal "???"
869 (org-test-with-parsed-data "* Headline"
870 (org-export-get-category
871 (org-element-map tree 'headline 'identity nil t) info)))))
873 (ert-deftest test-org-export/first-sibling-p ()
874 "Test `org-export-first-sibling-p' specifications."
875 ;; Standard test.
876 (should
877 (equal
878 '(yes yes no)
879 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
880 (org-element-map
881 tree 'headline
882 (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
883 info))))
884 ;; Ignore headlines not exported.
885 (should
886 (equal
887 '(yes)
888 (let ((org-export-exclude-tags '("ignore")))
889 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
890 (org-element-map
891 tree 'headline
892 (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
893 info))))))
895 (ert-deftest test-org-export/last-sibling-p ()
896 "Test `org-export-last-sibling-p' specifications."
897 ;; Standard test.
898 (should
899 (equal
900 '(yes no yes)
901 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
902 (org-element-map
903 tree 'headline
904 (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
905 info))))
906 ;; Ignore headlines not exported.
907 (should
908 (equal
909 '(yes)
910 (let ((org-export-exclude-tags '("ignore")))
911 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
912 (org-element-map
913 tree 'headline
914 (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
915 info))))))
919 ;;; Links
921 (ert-deftest test-org-export/get-coderef-format ()
922 "Test `org-export-get-coderef-format' specifications."
923 ;; A link without description returns "%s"
924 (should (equal (org-export-get-coderef-format "(ref:line)" nil)
925 "%s"))
926 ;; Return "%s" when path is matched within description.
927 (should (equal (org-export-get-coderef-format "path" "desc (path)")
928 "desc %s"))
929 ;; Otherwise return description.
930 (should (equal (org-export-get-coderef-format "path" "desc")
931 "desc")))
933 (ert-deftest test-org-export/inline-image-p ()
934 "Test `org-export-inline-image-p' specifications."
935 (should
936 (org-export-inline-image-p
937 (org-test-with-temp-text "[[#id]]"
938 (org-element-map
939 (org-element-parse-buffer) 'link 'identity nil t))
940 '(("custom-id" . "id")))))
942 (ert-deftest test-org-export/fuzzy-link ()
943 "Test fuzzy links specifications."
944 ;; 1. Links to invisible (keyword) targets should be ignored.
945 (org-test-with-parsed-data
946 "Paragraph.\n#+TARGET: Test\n[[Test]]"
947 (should-not
948 (org-element-map
949 tree 'link
950 (lambda (link)
951 (org-export-get-ordinal
952 (org-export-resolve-fuzzy-link link info) info)) info)))
953 ;; 2. Link to an headline should return headline's number.
954 (org-test-with-parsed-data
955 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
956 (should
957 ;; Note: Headline's number is in fact a list of numbers.
958 (equal '(2)
959 (org-element-map
960 tree 'link
961 (lambda (link)
962 (org-export-get-ordinal
963 (org-export-resolve-fuzzy-link link info) info)) info t))))
964 ;; 3. Link to a target in an item should return item's number.
965 (org-test-with-parsed-data
966 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
967 (should
968 ;; Note: Item's number is in fact a list of numbers.
969 (equal '(1 2)
970 (org-element-map
971 tree 'link
972 (lambda (link)
973 (org-export-get-ordinal
974 (org-export-resolve-fuzzy-link link info) info)) info t))))
975 ;; 4. Link to a target in a footnote should return footnote's
976 ;; number.
977 (org-test-with-parsed-data "
978 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
979 (should
980 (equal '(2 3)
981 (org-element-map
982 tree 'link
983 (lambda (link)
984 (org-export-get-ordinal
985 (org-export-resolve-fuzzy-link link info) info)) info))))
986 ;; 5. Link to a named element should return sequence number of that
987 ;; element.
988 (org-test-with-parsed-data
989 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
990 (should
991 (= 2
992 (org-element-map
993 tree 'link
994 (lambda (link)
995 (org-export-get-ordinal
996 (org-export-resolve-fuzzy-link link info) info)) info t))))
997 ;; 6. Link to a target not within an item, a table, a footnote
998 ;; reference or definition should return section number.
999 (org-test-with-parsed-data
1000 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
1001 (should
1002 (equal '(2)
1003 (org-element-map
1004 tree 'link
1005 (lambda (link)
1006 (org-export-get-ordinal
1007 (org-export-resolve-fuzzy-link link info) info)) info t)))))
1009 (ert-deftest test-org-export/resolve-coderef ()
1010 "Test `org-export-resolve-coderef' specifications."
1011 (let ((org-coderef-label-format "(ref:%s)"))
1012 ;; 1. A link to a "-n -k -r" block returns line number.
1013 (org-test-with-parsed-data
1014 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
1015 (should (= (org-export-resolve-coderef "coderef" info) 1)))
1016 (org-test-with-parsed-data
1017 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1018 (should (= (org-export-resolve-coderef "coderef" info) 1)))
1019 ;; 2. A link to a "-n -r" block returns line number.
1020 (org-test-with-parsed-data
1021 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
1022 (should (= (org-export-resolve-coderef "coderef" info) 1)))
1023 (org-test-with-parsed-data
1024 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1025 (should (= (org-export-resolve-coderef "coderef" info) 1)))
1026 ;; 3. A link to a "-n" block returns coderef.
1027 (org-test-with-parsed-data
1028 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1029 (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
1030 (org-test-with-parsed-data
1031 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
1032 (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
1033 ;; 4. A link to a "-r" block returns line number.
1034 (org-test-with-parsed-data
1035 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1036 (should (= (org-export-resolve-coderef "coderef" info) 1)))
1037 (org-test-with-parsed-data
1038 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
1039 (should (= (org-export-resolve-coderef "coderef" info) 1)))
1040 ;; 5. A link to a block without a switch returns coderef.
1041 (org-test-with-parsed-data
1042 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1043 (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
1044 (org-test-with-parsed-data
1045 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
1046 (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
1047 ;; 6. Correctly handle continued line numbers. A "+n" switch
1048 ;; should resume numbering from previous block with numbered
1049 ;; lines, ignoring blocks not numbering lines in the process.
1050 ;; A "-n" switch resets count.
1051 (org-test-with-parsed-data "
1052 #+BEGIN_EXAMPLE -n
1053 Text.
1054 #+END_EXAMPLE
1056 #+BEGIN_SRC emacs-lisp
1057 \(- 1 1)
1058 #+END_SRC
1060 #+BEGIN_SRC emacs-lisp +n -r
1061 \(+ 1 1) (ref:addition)
1062 #+END_SRC
1064 #+BEGIN_EXAMPLE -n -r
1065 Another text. (ref:text)
1066 #+END_EXAMPLE"
1067 (should (= (org-export-resolve-coderef "addition" info) 2))
1068 (should (= (org-export-resolve-coderef "text" info) 1)))
1069 ;; 7. Recognize coderef with user-specified syntax.
1070 (org-test-with-parsed-data
1071 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
1072 (should (equal (org-export-resolve-coderef "text" info) "text")))))
1074 (ert-deftest test-org-export/resolve-fuzzy-link ()
1075 "Test `org-export-resolve-fuzzy-link' specifications."
1076 ;; 1. Match target objects.
1077 (org-test-with-parsed-data "<<target>> [[target]]"
1078 (should
1079 (org-export-resolve-fuzzy-link
1080 (org-element-map tree 'link 'identity info t) info)))
1081 ;; 2. Match target elements.
1082 (org-test-with-parsed-data "#+TARGET: target\n[[target]]"
1083 (should
1084 (org-export-resolve-fuzzy-link
1085 (org-element-map tree 'link 'identity info t) info)))
1086 ;; 3. Match named elements.
1087 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
1088 (should
1089 (org-export-resolve-fuzzy-link
1090 (org-element-map tree 'link 'identity info t) info)))
1091 ;; 4. Match exact headline's name.
1092 (org-test-with-parsed-data "* My headline\n[[My headline]]"
1093 (should
1094 (org-export-resolve-fuzzy-link
1095 (org-element-map tree 'link 'identity info t) info)))
1096 ;; 5. Targets objects have priority over named elements and headline
1097 ;; titles.
1098 (org-test-with-parsed-data
1099 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
1100 (should
1101 (eq 'target
1102 (org-element-type
1103 (org-export-resolve-fuzzy-link
1104 (org-element-map tree 'link 'identity info t) info)))))
1105 ;; 6. Named elements have priority over headline titles.
1106 (org-test-with-parsed-data
1107 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
1108 (should
1109 (eq 'paragraph
1110 (org-element-type
1111 (org-export-resolve-fuzzy-link
1112 (org-element-map tree 'link 'identity info t) info)))))
1113 ;; 7. If link's path starts with a "*", only match headline titles,
1114 ;; though.
1115 (org-test-with-parsed-data
1116 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
1117 (should
1118 (eq 'headline
1119 (org-element-type
1120 (org-export-resolve-fuzzy-link
1121 (org-element-map tree 'link 'identity info t) info)))))
1122 ;; 8. Return nil if no match.
1123 (org-test-with-parsed-data "[[target]]"
1124 (should-not
1125 (org-export-resolve-fuzzy-link
1126 (org-element-map tree 'link 'identity info t) info))))
1128 (ert-deftest test-org-export/resolve-id-link ()
1129 "Test `org-export-resolve-id-link' specifications."
1130 ;; 1. Regular test for custom-id link.
1131 (org-test-with-parsed-data "* Headline1
1132 :PROPERTIES:
1133 :CUSTOM-ID: test
1134 :END:
1135 * Headline 2
1136 \[[#test]]"
1137 (should
1138 (org-export-resolve-id-link
1139 (org-element-map tree 'link 'identity info t) info)))
1140 ;; 2. Failing test for custom-id link.
1141 (org-test-with-parsed-data "* Headline1
1142 :PROPERTIES:
1143 :CUSTOM-ID: test
1144 :END:
1145 * Headline 2
1146 \[[#no-match]]"
1147 (should-not
1148 (org-export-resolve-id-link
1149 (org-element-map tree 'link 'identity info t) info)))
1150 ;; 3. Test for internal id target.
1151 (org-test-with-parsed-data "* Headline1
1152 :PROPERTIES:
1153 :ID: aaaa
1154 :END:
1155 * Headline 2
1156 \[[id:aaaa]]"
1157 (should
1158 (org-export-resolve-id-link
1159 (org-element-map tree 'link 'identity info t) info)))
1160 ;; 4. Test for external id target.
1161 (org-test-with-parsed-data "[[id:aaaa]]"
1162 (should
1163 (org-export-resolve-id-link
1164 (org-element-map tree 'link 'identity info t)
1165 (org-combine-plists info '(:id-alist (("aaaa" . "external-file"))))))))
1167 (ert-deftest test-org-export/resolve-radio-link ()
1168 "Test `org-export-resolve-radio-link' specifications."
1169 ;; Standard test.
1170 (org-test-with-temp-text "<<<radio>>> radio"
1171 (org-update-radio-target-regexp)
1172 (should
1173 (let* ((tree (org-element-parse-buffer))
1174 (info `(:parse-tree ,tree)))
1175 (org-export-resolve-radio-link
1176 (org-element-map tree 'link 'identity info t)
1177 info))))
1178 ;; Radio target with objects.
1179 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
1180 (org-update-radio-target-regexp)
1181 (should
1182 (let* ((tree (org-element-parse-buffer))
1183 (info `(:parse-tree ,tree)))
1184 (org-export-resolve-radio-link
1185 (org-element-map tree 'link 'identity info t)
1186 info)))))
1190 ;;; Src-block and example-block
1192 (ert-deftest test-org-export/unravel-code ()
1193 "Test `org-export-unravel-code' function."
1194 (let ((org-coderef-label-format "(ref:%s)"))
1195 ;; 1. Code without reference.
1196 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
1197 (should (equal (org-export-unravel-code (org-element-at-point))
1198 '("(+ 1 1)\n"))))
1199 ;; 2. Code with reference.
1200 (org-test-with-temp-text
1201 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
1202 (should (equal (org-export-unravel-code (org-element-at-point))
1203 '("(+ 1 1)\n" (1 . "test")))))
1204 ;; 3. Code with user-defined reference.
1205 (org-test-with-temp-text
1206 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
1207 (should (equal (org-export-unravel-code (org-element-at-point))
1208 '("(+ 1 1)\n" (1 . "test")))))
1209 ;; 4. Code references keys are relative to the current block.
1210 (org-test-with-temp-text "
1211 #+BEGIN_EXAMPLE -n
1212 \(+ 1 1)
1213 #+END_EXAMPLE
1214 #+BEGIN_EXAMPLE +n
1215 \(+ 2 2)
1216 \(+ 3 3) (ref:one)
1217 #+END_EXAMPLE"
1218 (goto-line 5)
1219 (should (equal (org-export-unravel-code (org-element-at-point))
1220 '("(+ 2 2)\n(+ 3 3)\n" (2 . "one")))))))
1224 ;;; Smart Quotes
1226 (ert-deftest test-org-export/activate-smart-quotes ()
1227 "Test `org-export-activate-smart-quotes' specifications."
1228 ;; Opening double quotes: standard test.
1229 (should
1230 (equal
1231 '("some &ldquo;paragraph")
1232 (let ((org-export-default-language "en"))
1233 (org-test-with-parsed-data "some \"paragraph"
1234 (org-element-map
1235 tree 'plain-text
1236 (lambda (s) (org-export-activate-smart-quotes s :html info))
1237 info)))))
1238 ;; Opening quotes: at the beginning of a paragraph.
1239 (should
1240 (equal
1241 '("&ldquo;begin")
1242 (let ((org-export-default-language "en"))
1243 (org-test-with-parsed-data "\"begin"
1244 (org-element-map
1245 tree 'plain-text
1246 (lambda (s) (org-export-activate-smart-quotes s :html info))
1247 info)))))
1248 ;; Opening quotes: after an object.
1249 (should
1250 (equal
1251 '("&ldquo;begin")
1252 (let ((org-export-default-language "en"))
1253 (org-test-with-parsed-data "=verb= \"begin"
1254 (org-element-map
1255 tree 'plain-text
1256 (lambda (s) (org-export-activate-smart-quotes s :html info))
1257 info)))))
1258 ;; Closing quotes: standard test.
1259 (should
1260 (equal
1261 '("some&rdquo; paragraph")
1262 (let ((org-export-default-language "en"))
1263 (org-test-with-parsed-data "some\" paragraph"
1264 (org-element-map
1265 tree 'plain-text
1266 (lambda (s) (org-export-activate-smart-quotes s :html info))
1267 info)))))
1268 ;; Closing quotes: at the end of a paragraph.
1269 (should
1270 (equal
1271 '("end&rdquo;")
1272 (let ((org-export-default-language "en"))
1273 (org-test-with-parsed-data "end\""
1274 (org-element-map
1275 tree 'plain-text
1276 (lambda (s) (org-export-activate-smart-quotes s :html info))
1277 info)))))
1278 ;; Apostrophe: standard test.
1279 (should
1280 (equal
1281 '("It shouldn&rsquo;t fail")
1282 (let ((org-export-default-language "en"))
1283 (org-test-with-parsed-data "It shouldn't fail"
1284 (org-element-map
1285 tree 'plain-text
1286 (lambda (s) (org-export-activate-smart-quotes s :html info))
1287 info)))))
1288 ;; Apostrophe: before an object.
1289 (should
1290 (equal
1291 '("a&rsquo;")
1292 (let ((org-export-default-language "en"))
1293 (org-test-with-parsed-data "a'=b="
1294 (org-element-map
1295 tree 'plain-text
1296 (lambda (s) (org-export-activate-smart-quotes s :html info))
1297 info)))))
1298 ;; Apostrophe: after an object.
1299 (should
1300 (equal
1301 '("&rsquo;s")
1302 (let ((org-export-default-language "en"))
1303 (org-test-with-parsed-data "=code='s"
1304 (org-element-map
1305 tree 'plain-text
1306 (lambda (s) (org-export-activate-smart-quotes s :html info))
1307 info)))))
1308 ;; Special case: isolated quotes.
1309 (should
1310 (equal '("&ldquo;" "&rdquo;")
1311 (let ((org-export-default-language "en"))
1312 (org-test-with-parsed-data "\"$x$\""
1313 (org-element-map
1314 tree 'plain-text
1315 (lambda (s) (org-export-activate-smart-quotes s :html info))
1316 info)))))
1317 ;; Smart quotes in secondary strings.
1318 (should
1319 (equal '("&ldquo;" "&rdquo;")
1320 (let ((org-export-default-language "en"))
1321 (org-test-with-parsed-data "* \"$x$\""
1322 (org-element-map
1323 tree 'plain-text
1324 (lambda (s) (org-export-activate-smart-quotes s :html info))
1325 info)))))
1326 ;; Smart quotes in document keywords.
1327 (should
1328 (equal '("&ldquo;" "&rdquo;")
1329 (let ((org-export-default-language "en"))
1330 (org-test-with-parsed-data "#+TITLE: \"$x$\""
1331 (org-element-map
1332 (plist-get info :title) 'plain-text
1333 (lambda (s) (org-export-activate-smart-quotes s :html info))
1334 info)))))
1335 ;; Smart quotes in parsed affiliated keywords.
1336 (should
1337 (equal '("&ldquo;" "&rdquo;" "Paragraph")
1338 (let ((org-export-default-language "en"))
1339 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
1340 (org-element-map
1341 tree 'plain-text
1342 (lambda (s) (org-export-activate-smart-quotes s :html info))
1343 info nil nil t))))))
1347 ;;; Tables
1349 (ert-deftest test-org-export/special-column ()
1350 "Test if the table's special column is properly recognized."
1351 ;; 1. First column is special if it contains only a special marking
1352 ;; characters or empty cells.
1353 (org-test-with-temp-text "
1354 | ! | 1 |
1355 | | 2 |"
1356 (should
1357 (org-export-table-has-special-column-p
1358 (org-element-map
1359 (org-element-parse-buffer) 'table 'identity nil 'first-match))))
1360 ;; 2. If the column contains anything else, it isn't special.
1361 (org-test-with-temp-text "
1362 | ! | 1 |
1363 | b | 2 |"
1364 (should-not
1365 (org-export-table-has-special-column-p
1366 (org-element-map
1367 (org-element-parse-buffer) 'table 'identity nil 'first-match))))
1368 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
1369 ;; and "!".
1370 (org-test-with-temp-text "
1371 | # | 1 |
1372 | ^ | 2 |
1373 | * | 3 |
1374 | _ | 4 |
1375 | / | 5 |
1376 | $ | 6 |
1377 | ! | 7 |"
1378 (should
1379 (org-export-table-has-special-column-p
1380 (org-element-map
1381 (org-element-parse-buffer) 'table 'identity nil 'first-match))))
1382 ;; 4. A first column with only empty cells isn't considered as
1383 ;; special.
1384 (org-test-with-temp-text "
1385 | | 1 |
1386 | | 2 |"
1387 (should-not
1388 (org-export-table-has-special-column-p
1389 (org-element-map
1390 (org-element-parse-buffer) 'table 'identity nil 'first-match)))))
1392 (ert-deftest test-org-export/table-row-is-special-p ()
1393 "Test `org-export-table-row-is-special-p' specifications."
1394 ;; 1. A row is special if it has a special marking character in the
1395 ;; special column.
1396 (org-test-with-parsed-data "| ! | 1 |"
1397 (should
1398 (org-export-table-row-is-special-p
1399 (org-element-map tree 'table-row 'identity nil 'first-match) info)))
1400 ;; 2. A row is special when its first field is "/"
1401 (org-test-with-parsed-data "
1402 | / | 1 |
1403 | a | b |"
1404 (should
1405 (org-export-table-row-is-special-p
1406 (org-element-map tree 'table-row 'identity nil 'first-match) info)))
1407 ;; 3. A row only containing alignment cookies is also considered as
1408 ;; special.
1409 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
1410 (should
1411 (org-export-table-row-is-special-p
1412 (org-element-map tree 'table-row 'identity nil 'first-match) info)))
1413 ;; 4. Everything else isn't considered as special.
1414 (org-test-with-parsed-data "| \alpha | | c |"
1415 (should-not
1416 (org-export-table-row-is-special-p
1417 (org-element-map tree 'table-row 'identity nil 'first-match) info)))
1418 ;; 5. Table's rules are never considered as special rows.
1419 (org-test-with-parsed-data "|---+---|"
1420 (should-not
1421 (org-export-table-row-is-special-p
1422 (org-element-map tree 'table-row 'identity nil 'first-match) info))))
1424 (ert-deftest test-org-export/has-header-p ()
1425 "Test `org-export-table-has-header-p' specifications."
1426 ;; 1. With an header.
1427 (org-test-with-parsed-data "
1428 | a | b |
1429 |---+---|
1430 | c | d |"
1431 (should
1432 (org-export-table-has-header-p
1433 (org-element-map tree 'table 'identity info 'first-match)
1434 info)))
1435 ;; 2. Without an header.
1436 (org-test-with-parsed-data "
1437 | a | b |
1438 | c | d |"
1439 (should-not
1440 (org-export-table-has-header-p
1441 (org-element-map tree 'table 'identity info 'first-match)
1442 info)))
1443 ;; 3. Don't get fooled with starting and ending rules.
1444 (org-test-with-parsed-data "
1445 |---+---|
1446 | a | b |
1447 | c | d |
1448 |---+---|"
1449 (should-not
1450 (org-export-table-has-header-p
1451 (org-element-map tree 'table 'identity info 'first-match)
1452 info))))
1454 (ert-deftest test-org-export/table-row-group ()
1455 "Test `org-export-table-row-group' specifications."
1456 ;; 1. A rule creates a new group.
1457 (org-test-with-parsed-data "
1458 | a | b |
1459 |---+---|
1460 | 1 | 2 |"
1461 (should
1462 (equal
1463 '(1 nil 2)
1464 (mapcar (lambda (row) (org-export-table-row-group row info))
1465 (org-element-map tree 'table-row 'identity)))))
1466 ;; 2. Special rows are ignored in count.
1467 (org-test-with-parsed-data "
1468 | / | < | > |
1469 |---|---+---|
1470 | | 1 | 2 |"
1471 (should
1472 (equal
1473 '(nil nil 1)
1474 (mapcar (lambda (row) (org-export-table-row-group row info))
1475 (org-element-map tree 'table-row 'identity)))))
1476 ;; 3. Double rules also are ignored in count.
1477 (org-test-with-parsed-data "
1478 | a | b |
1479 |---+---|
1480 |---+---|
1481 | 1 | 2 |"
1482 (should
1483 (equal
1484 '(1 nil nil 2)
1485 (mapcar (lambda (row) (org-export-table-row-group row info))
1486 (org-element-map tree 'table-row 'identity))))))
1488 (ert-deftest test-org-export/table-cell-width ()
1489 "Test `org-export-table-cell-width' specifications."
1490 ;; 1. Width is primarily determined by width cookies. If no cookie
1491 ;; is found, cell's width is nil.
1492 (org-test-with-parsed-data "
1493 | / | <l> | <6> | <l7> |
1494 | | a | b | c |"
1495 (should
1496 (equal
1497 '(nil 6 7)
1498 (mapcar (lambda (cell) (org-export-table-cell-width cell info))
1499 (org-element-map tree 'table-cell 'identity info)))))
1500 ;; 2. The last width cookie has precedence.
1501 (org-test-with-parsed-data "
1502 | <6> |
1503 | <7> |
1504 | a |"
1505 (should
1506 (equal
1507 '(7)
1508 (mapcar (lambda (cell) (org-export-table-cell-width cell info))
1509 (org-element-map tree 'table-cell 'identity info)))))
1510 ;; 3. Valid width cookies must have a specific row.
1511 (org-test-with-parsed-data "| <6> | cell |"
1512 (should
1513 (equal
1514 '(nil nil)
1515 (mapcar (lambda (cell) (org-export-table-cell-width cell info))
1516 (org-element-map tree 'table-cell 'identity))))))
1518 (ert-deftest test-org-export/table-cell-alignment ()
1519 "Test `org-export-table-cell-alignment' specifications."
1520 (let ((org-table-number-fraction 0.5)
1521 (org-table-number-regexp "^[0-9]+$"))
1522 ;; 1. Alignment is primarily determined by alignment cookies.
1523 (org-test-with-temp-text "| <l> | <c> | <r> |"
1524 (let* ((tree (org-element-parse-buffer))
1525 (info `(:parse-tree ,tree)))
1526 (should
1527 (equal
1528 '(left center right)
1529 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info))
1530 (org-element-map tree 'table-cell 'identity))))))
1531 ;; 2. The last alignment cookie has precedence.
1532 (org-test-with-parsed-data "
1533 | <l8> |
1534 | cell |
1535 | <r9> |"
1536 (should
1537 (equal
1538 '(right right right)
1539 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info))
1540 (org-element-map tree 'table-cell 'identity)))))
1541 ;; 3. If there's no cookie, cell's contents determine alignment.
1542 ;; A column mostly made of cells containing numbers will align
1543 ;; its cells to the right.
1544 (org-test-with-parsed-data "
1545 | 123 |
1546 | some text |
1547 | 12345 |"
1548 (should
1549 (equal
1550 '(right right right)
1551 (mapcar (lambda (cell)
1552 (org-export-table-cell-alignment cell info))
1553 (org-element-map tree 'table-cell 'identity)))))
1554 ;; 4. Otherwise, they will be aligned to the left.
1555 (org-test-with-parsed-data "
1556 | text |
1557 | some text |
1558 | \alpha |"
1559 (should
1560 (equal
1561 '(left left left)
1562 (mapcar (lambda (cell)
1563 (org-export-table-cell-alignment cell info))
1564 (org-element-map tree 'table-cell 'identity)))))))
1566 (ert-deftest test-org-export/table-cell-borders ()
1567 "Test `org-export-table-cell-borders' specifications."
1568 ;; 1. Recognize various column groups indicators.
1569 (org-test-with-parsed-data "| / | < | > | <> |"
1570 (should
1571 (equal
1572 '((right bottom top) (left bottom top) (right bottom top)
1573 (right left bottom top))
1574 (mapcar (lambda (cell)
1575 (org-export-table-cell-borders cell info))
1576 (org-element-map tree 'table-cell 'identity)))))
1577 ;; 2. Accept shortcuts to define column groups.
1578 (org-test-with-parsed-data "| / | < | < |"
1579 (should
1580 (equal
1581 '((right bottom top) (right left bottom top) (left bottom top))
1582 (mapcar (lambda (cell)
1583 (org-export-table-cell-borders cell info))
1584 (org-element-map tree 'table-cell 'identity)))))
1585 ;; 3. A valid column groups row must start with a "/".
1586 (org-test-with-parsed-data "
1587 | | < |
1588 | a | b |"
1589 (should
1590 (equal '((top) (top) (bottom) (bottom))
1591 (mapcar (lambda (cell)
1592 (org-export-table-cell-borders cell info))
1593 (org-element-map tree 'table-cell 'identity)))))
1594 ;; 4. Take table rules into consideration.
1595 (org-test-with-parsed-data "
1596 | 1 |
1597 |---|
1598 | 2 |"
1599 (should
1600 (equal '((below top) (bottom above))
1601 (mapcar (lambda (cell)
1602 (org-export-table-cell-borders cell info))
1603 (org-element-map tree 'table-cell 'identity)))))
1604 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
1605 ;; (resp. `bottom' and `below') borders. Any special row is
1606 ;; ignored.
1607 (org-test-with-parsed-data "
1608 |---+----|
1609 | / | |
1610 | | 1 |
1611 |---+----|"
1612 (should
1613 (equal '((bottom below top above))
1614 (last
1615 (mapcar (lambda (cell)
1616 (org-export-table-cell-borders cell info))
1617 (org-element-map tree 'table-cell 'identity)))))))
1619 (ert-deftest test-org-export/table-dimensions ()
1620 "Test `org-export-table-dimensions' specifications."
1621 ;; 1. Standard test.
1622 (org-test-with-parsed-data "
1623 | 1 | 2 | 3 |
1624 | 4 | 5 | 6 |"
1625 (should
1626 (equal '(2 . 3)
1627 (org-export-table-dimensions
1628 (org-element-map tree 'table 'identity info 'first-match) info))))
1629 ;; 2. Ignore horizontal rules and special columns.
1630 (org-test-with-parsed-data "
1631 | / | < | > |
1632 | 1 | 2 | 3 |
1633 |---+---+---|
1634 | 4 | 5 | 6 |"
1635 (should
1636 (equal '(2 . 3)
1637 (org-export-table-dimensions
1638 (org-element-map tree 'table 'identity info 'first-match) info)))))
1640 (ert-deftest test-org-export/table-cell-address ()
1641 "Test `org-export-table-cell-address' specifications."
1642 ;; 1. Standard test: index is 0-based.
1643 (org-test-with-parsed-data "| a | b |"
1644 (should
1645 (equal '((0 . 0) (0 . 1))
1646 (org-element-map
1647 tree 'table-cell
1648 (lambda (cell) (org-export-table-cell-address cell info))
1649 info))))
1650 ;; 2. Special column isn't counted, nor are special rows.
1651 (org-test-with-parsed-data "
1652 | / | <> |
1653 | | c |"
1654 (should
1655 (equal '(0 . 0)
1656 (org-export-table-cell-address
1657 (car (last (org-element-map tree 'table-cell 'identity info)))
1658 info))))
1659 ;; 3. Tables rules do not count either.
1660 (org-test-with-parsed-data "
1661 | a |
1662 |---|
1663 | b |
1664 |---|
1665 | c |"
1666 (should
1667 (equal '(2 . 0)
1668 (org-export-table-cell-address
1669 (car (last (org-element-map tree 'table-cell 'identity info)))
1670 info))))
1671 ;; 4. Return nil for special cells.
1672 (org-test-with-parsed-data "| / | a |"
1673 (should-not
1674 (org-export-table-cell-address
1675 (org-element-map tree 'table-cell 'identity nil 'first-match)
1676 info))))
1678 (ert-deftest test-org-export/get-table-cell-at ()
1679 "Test `org-export-get-table-cell-at' specifications."
1680 ;; 1. Address ignores special columns, special rows and rules.
1681 (org-test-with-parsed-data "
1682 | / | <> |
1683 | | a |
1684 |---+----|
1685 | | b |"
1686 (should
1687 (equal '("b")
1688 (org-element-contents
1689 (org-export-get-table-cell-at
1690 '(1 . 0)
1691 (org-element-map tree 'table 'identity info 'first-match)
1692 info)))))
1693 ;; 2. Return value for a non-existent address is nil.
1694 (org-test-with-parsed-data "| a |"
1695 (should-not
1696 (org-export-get-table-cell-at
1697 '(2 . 2)
1698 (org-element-map tree 'table 'identity info 'first-match)
1699 info)))
1700 (org-test-with-parsed-data "| / |"
1701 (should-not
1702 (org-export-get-table-cell-at
1703 '(0 . 0)
1704 (org-element-map tree 'table 'identity info 'first-match)
1705 info))))
1707 (ert-deftest test-org-export/table-cell-starts-colgroup-p ()
1708 "Test `org-export-table-cell-starts-colgroup-p' specifications."
1709 ;; 1. A cell at a beginning of a row always starts a column group.
1710 (org-test-with-parsed-data "| a |"
1711 (should
1712 (org-export-table-cell-starts-colgroup-p
1713 (org-element-map tree 'table-cell 'identity info 'first-match)
1714 info)))
1715 ;; 2. Special column should be ignored when determining the
1716 ;; beginning of the row.
1717 (org-test-with-parsed-data "
1718 | / | |
1719 | | a |"
1720 (should
1721 (org-export-table-cell-starts-colgroup-p
1722 (org-element-map tree 'table-cell 'identity info 'first-match)
1723 info)))
1724 ;; 2. Explicit column groups.
1725 (org-test-with-parsed-data "
1726 | / | | < |
1727 | a | b | c |"
1728 (should
1729 (equal
1730 '(yes no yes)
1731 (org-element-map
1732 tree 'table-cell
1733 (lambda (cell)
1734 (if (org-export-table-cell-starts-colgroup-p cell info) 'yes 'no))
1735 info)))))
1737 (ert-deftest test-org-export/table-cell-ends-colgroup-p ()
1738 "Test `org-export-table-cell-ends-colgroup-p' specifications."
1739 ;; 1. A cell at the end of a row always ends a column group.
1740 (org-test-with-parsed-data "| a |"
1741 (should
1742 (org-export-table-cell-ends-colgroup-p
1743 (org-element-map tree 'table-cell 'identity info 'first-match)
1744 info)))
1745 ;; 2. Special column should be ignored when determining the
1746 ;; beginning of the row.
1747 (org-test-with-parsed-data "
1748 | / | |
1749 | | a |"
1750 (should
1751 (org-export-table-cell-ends-colgroup-p
1752 (org-element-map tree 'table-cell 'identity info 'first-match)
1753 info)))
1754 ;; 3. Explicit column groups.
1755 (org-test-with-parsed-data "
1756 | / | < | |
1757 | a | b | c |"
1758 (should
1759 (equal
1760 '(yes no yes)
1761 (org-element-map
1762 tree 'table-cell
1763 (lambda (cell)
1764 (if (org-export-table-cell-ends-colgroup-p cell info) 'yes 'no))
1765 info)))))
1767 (ert-deftest test-org-export/table-row-starts-rowgroup-p ()
1768 "Test `org-export-table-row-starts-rowgroup-p' specifications."
1769 ;; 1. A row at the beginning of a table always starts a row group.
1770 ;; So does a row following a table rule.
1771 (org-test-with-parsed-data "
1772 | a |
1773 |---|
1774 | b |"
1775 (should
1776 (equal
1777 '(yes no yes)
1778 (org-element-map
1779 tree 'table-row
1780 (lambda (row)
1781 (if (org-export-table-row-starts-rowgroup-p row info) 'yes 'no))
1782 info))))
1783 ;; 2. Special rows should be ignored when determining the beginning
1784 ;; of the row.
1785 (org-test-with-parsed-data "
1786 | / | < |
1787 | | a |
1788 |---+---|
1789 | / | < |
1790 | | b |"
1791 (should
1792 (equal
1793 '(yes no yes)
1794 (org-element-map
1795 tree 'table-row
1796 (lambda (row)
1797 (if (org-export-table-row-starts-rowgroup-p row info) 'yes 'no))
1798 info)))))
1800 (ert-deftest test-org-export/table-row-ends-rowgroup-p ()
1801 "Test `org-export-table-row-ends-rowgroup-p' specifications."
1802 ;; 1. A row at the end of a table always ends a row group. So does
1803 ;; a row preceding a table rule.
1804 (org-test-with-parsed-data "
1805 | a |
1806 |---|
1807 | b |"
1808 (should
1809 (equal
1810 '(yes no yes)
1811 (org-element-map
1812 tree 'table-row
1813 (lambda (row)
1814 (if (org-export-table-row-ends-rowgroup-p row info) 'yes 'no))
1815 info))))
1816 ;; 2. Special rows should be ignored when determining the beginning
1817 ;; of the row.
1818 (org-test-with-parsed-data "
1819 | | a |
1820 | / | < |
1821 |---+---|
1822 | | b |
1823 | / | < |"
1824 (should
1825 (equal
1826 '(yes no yes)
1827 (org-element-map
1828 tree 'table-row
1829 (lambda (row)
1830 (if (org-export-table-row-ends-rowgroup-p row info) 'yes 'no))
1831 info)))))
1833 (ert-deftest test-org-export/table-row-starts-header-p ()
1834 "Test `org-export-table-row-starts-header-p' specifications."
1835 ;; 1. Only the row starting the first row group starts the table
1836 ;; header.
1837 (org-test-with-parsed-data "
1838 | a |
1839 | b |
1840 |---|
1841 | c |"
1842 (should
1843 (equal
1844 '(yes no no no)
1845 (org-element-map
1846 tree 'table-row
1847 (lambda (row)
1848 (if (org-export-table-row-starts-header-p row info) 'yes 'no))
1849 info))))
1850 ;; 2. A row cannot start an header if there's no header in the
1851 ;; table.
1852 (org-test-with-parsed-data "
1853 | a |
1854 |---|"
1855 (should-not
1856 (org-export-table-row-starts-header-p
1857 (org-element-map tree 'table-row 'identity info 'first-match)
1858 info))))
1860 (ert-deftest test-org-export/table-row-ends-header-p ()
1861 "Test `org-export-table-row-ends-header-p' specifications."
1862 ;; 1. Only the row starting the first row group starts the table
1863 ;; header.
1864 (org-test-with-parsed-data "
1865 | a |
1866 | b |
1867 |---|
1868 | c |"
1869 (should
1870 (equal
1871 '(no yes no no)
1872 (org-element-map
1873 tree 'table-row
1874 (lambda (row)
1875 (if (org-export-table-row-ends-header-p row info) 'yes 'no))
1876 info))))
1877 ;; 2. A row cannot start an header if there's no header in the
1878 ;; table.
1879 (org-test-with-parsed-data "
1880 | a |
1881 |---|"
1882 (should-not
1883 (org-export-table-row-ends-header-p
1884 (org-element-map tree 'table-row 'identity info 'first-match)
1885 info))))
1889 ;;; Topology
1891 (ert-deftest test-org-export/get-next-element ()
1892 "Test `org-export-get-next-element' specifications."
1893 ;; Standard test.
1894 (should
1895 (equal "b"
1896 (org-test-with-parsed-data "* Headline\n*a* b"
1897 (org-export-get-next-element
1898 (org-element-map tree 'bold 'identity info t) info))))
1899 ;; Return nil when no previous element.
1900 (should-not
1901 (org-test-with-parsed-data "* Headline\na *b*"
1902 (org-export-get-next-element
1903 (org-element-map tree 'bold 'identity info t) info)))
1904 ;; Non-exportable elements are ignored.
1905 (should-not
1906 (let ((org-export-with-timestamps nil))
1907 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
1908 (org-export-get-next-element
1909 (org-element-map tree 'entity 'identity info t) info))))
1910 ;; Find next element in secondary strings.
1911 (should
1912 (eq 'verbatim
1913 (org-test-with-parsed-data "* a =verb="
1914 (org-element-type
1915 (org-export-get-next-element
1916 (org-element-map tree 'plain-text 'identity info t) info)))))
1917 ;; Find next element in document keywords.
1918 (should
1919 (eq 'verbatim
1920 (org-test-with-parsed-data "#+TITLE: a =verb="
1921 (org-element-type
1922 (org-export-get-next-element
1923 (org-element-map
1924 (plist-get info :title) 'plain-text 'identity info t) info)))))
1925 ;; Find next element in parsed affiliated keywords.
1926 (should
1927 (eq 'verbatim
1928 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
1929 (org-element-type
1930 (org-export-get-next-element
1931 (org-element-map tree 'plain-text 'identity info t nil t) info))))))
1933 (ert-deftest test-org-export/get-previous-element ()
1934 "Test `org-export-get-previous-element' specifications."
1935 ;; Standard test.
1936 (should
1937 (equal "a "
1938 (org-test-with-parsed-data "* Headline\na *b*"
1939 (org-export-get-previous-element
1940 (org-element-map tree 'bold 'identity info t) info))))
1941 ;; Return nil when no previous element.
1942 (should-not
1943 (org-test-with-parsed-data "* Headline\n*a* b"
1944 (org-export-get-previous-element
1945 (org-element-map tree 'bold 'identity info t) info)))
1946 ;; Non-exportable elements are ignored.
1947 (should-not
1948 (let ((org-export-with-timestamps nil))
1949 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
1950 (org-export-get-previous-element
1951 (org-element-map tree 'entity 'identity info t) info))))
1952 ;; Find previous element in secondary strings.
1953 (should
1954 (eq 'verbatim
1955 (org-test-with-parsed-data "* =verb= a"
1956 (org-element-type
1957 (org-export-get-previous-element
1958 (org-element-map tree 'plain-text 'identity info t) info)))))
1959 ;; Find previous element in document keywords.
1960 (should
1961 (eq 'verbatim
1962 (org-test-with-parsed-data "#+TITLE: =verb= a"
1963 (org-element-type
1964 (org-export-get-previous-element
1965 (org-element-map
1966 (plist-get info :title) 'plain-text 'identity info t) info)))))
1967 ;; Find previous element in parsed affiliated keywords.
1968 (should
1969 (eq 'verbatim
1970 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
1971 (org-element-type
1972 (org-export-get-previous-element
1973 (org-element-map tree 'plain-text 'identity info t nil t) info))))))
1976 (provide 'test-org-export)
1977 ;;; test-org-export.el end here