1 ;;; test-org-export.el --- Tests for org-export.el
3 ;; Copyright (C) 2012 Nicolas Goaziou
5 ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
7 ;; Released under the GNU General Public License version 3
8 ;; see: http://www.gnu.org/licenses/gpl-3.0.html
16 (unless (featurep 'org-export
)
17 (signal 'missing-test-dependency
"org-export"))
19 (defmacro org-test-with-backend
(backend &rest body
)
20 "Execute body with an export back-end defined.
22 BACKEND is the name of the back-end. BODY is the body to
23 execute. The defined back-end simply returns parsed data as Org
25 (declare (debug (form body
)) (indent 1))
26 `(let ((org-export-registered-backends
30 (let (transcode-table)
31 (dolist (type (append org-element-all-elements
32 org-element-all-objects
)
36 (lambda (obj contents info
)
38 (intern (format "org-element-%s-interpreter"
41 transcode-table
)))))))
44 (defmacro org-test-with-parsed-data
(data &rest body
)
45 "Execute body with parsed data available.
47 DATA is a string containing the data to be parsed. BODY is the
48 body to execute. Parse tree is available under the `tree'
49 variable, and communication channel under `info'.
51 This function calls `org-export-collect-tree-properties'. As
52 such, `:ignore-list' (for `org-element-map') and
53 `:parse-tree' (for `org-export-get-genealogy') properties are
54 already filled in `info'."
55 (declare (debug (form body
)) (indent 1))
56 `(org-test-with-temp-text ,data
57 (let* ((tree (org-element-parse-buffer))
58 (info (org-export-collect-tree-properties
59 tree
(org-export-get-environment))))
66 (ert-deftest test-org-export
/bind-keyword
()
67 "Test reading #+BIND: keywords."
68 ;; Test with `org-export-all-BIND' set to t.
70 (org-test-with-temp-text "#+BIND: variable value"
71 (let ((org-export-allow-BIND t
))
72 (org-export--install-letbind-maybe)
73 (eq variable
'value
))))
74 ;; Test with `org-export-all-BIND' set to nil.
76 (org-test-with-temp-text "#+BIND: variable value"
77 (let ((org-export-allow-BIND nil
))
78 (org-export--install-letbind-maybe)
80 ;; Test with `org-export-all-BIND' set to 'confirm and
81 ;; `org-export--allow-BIND-local' to t .
83 (org-test-with-temp-text "#+BIND: variable value"
84 (let ((org-export-allow-BIND 'confirm
))
85 (org-set-local 'org-export--allow-BIND-local t
)
86 (org-export--install-letbind-maybe)
87 (eq variable
'value
))))
88 ;; Test with `org-export-all-BIND' set to 'confirm and
89 ;; `org-export--allow-BIND-local' to nil.
91 (org-test-with-temp-text "#+BIND: variable value"
92 (let ((org-export-allow-BIND 'confirm
))
93 (org-set-local 'org-export--allow-BIND-local nil
)
94 (org-export--install-letbind-maybe)
96 ;; BIND keywords are case-insensitive.
98 (org-test-with-temp-text "#+bind: variable value"
99 (let ((org-export-allow-BIND t
))
100 (org-export--install-letbind-maybe)
101 (eq variable
'value
)))))
103 (ert-deftest test-org-export
/parse-option-keyword
()
104 "Test reading all standard #+OPTIONS: items."
107 (org-export--parse-option-keyword
108 "H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t
109 *:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t inline:nil
112 1 :preserve-breaks t
:section-numbers t
:time-stamp-file t
113 :with-archived-trees t
:with-author t
:with-creator t
:with-drawers t
114 :with-email t
:with-emphasize t
:with-entities t
:with-fixed-width t
115 :with-footnotes t
:with-inlinetasks nil
:with-priority t
116 :with-special-strings t
:with-statistics-cookies t
:with-sub-superscript t
117 :with-toc t
:with-tables t
:with-tags t
:with-tasks t
:with-timestamps t
118 :with-todo-keywords t
)))
119 ;; Test some special values.
122 (org-export--parse-option-keyword
123 "arch:headline creator:comment d:(\"TEST\")
124 ^:{} toc:1 tags:not-in-toc tasks:todo num:2 <:active")
127 :with-archived-trees headline
:with-creator comment
128 :with-drawers
("TEST") :with-sub-superscript
{} :with-toc
1
129 :with-tags not-in-toc
:with-tasks todo
:with-timestamps active
))))
131 (ert-deftest test-org-export
/get-inbuffer-options
()
132 "Test reading all standard export keywords."
135 (org-test-with-temp-text "#+AUTHOR: Me, Myself and I
138 #+DESCRIPTION: Testing
139 #+DESCRIPTION: with two lines
140 #+EMAIL: some@email.org
141 #+EXCLUDE_TAGS: noexport invisible
144 #+SELECT_TAGS: export
146 #+TITLE: with spaces"
147 (org-export--get-inbuffer-options))
149 ("Me, Myself and I") :creator
"Idem" :date
("Today")
150 :description
"Testing\nwith two lines" :email
"some@email.org"
151 :exclude-tags
("noexport" "invisible") :keywords
"test" :language
"en"
152 :select-tags
("export") :title
("Some title with spaces")))))
154 (ert-deftest test-org-export
/get-subtree-options
()
155 "Test setting options from headline's properties."
157 (org-test-with-temp-text "#+TITLE: Title
160 :EXPORT_TITLE: Subtree Title
164 (should (equal (plist-get (org-export-get-environment nil t
) :title
)
165 '("Subtree Title"))))
169 (org-test-with-temp-text "#+OPTIONS: H:1
177 (= 2 (plist-get (org-export-get-environment nil t
) :headline-levels
))))
179 (org-test-with-temp-text "#+DATE: today
182 :EXPORT_DATE: 29-03-2012
186 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
188 ;; Properties with `split' behaviour are stored as a list of
192 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
195 :EXPORT_EXCLUDE_TAGS: a b
200 (plist-get (org-export-get-environment nil t
) :exclude-tags
)))))
201 ;; Handle :PROPERTY+: syntax.
204 (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
207 :EXPORT_EXCLUDE_TAGS: a
208 :EXPORT_EXCLUDE_TAGS+: b
213 (plist-get (org-export-get-environment nil t
) :exclude-tags
)))))
214 ;; Export properties are case-insensitive.
215 (org-test-with-temp-text "* Headline
217 :EXPORT_Date: 29-03-2012
220 (should (equal (plist-get (org-export-get-environment nil t
) :date
)
223 (ert-deftest test-org-export
/handle-options
()
224 "Test if export options have an impact on output."
225 ;; Test exclude tags.
226 (org-test-with-temp-text "* Head1 :noexport:"
227 (org-test-with-backend test
229 (equal (org-export-as 'test nil nil nil
'(:exclude-tags
("noexport")))
231 ;; Test include tags.
232 (org-test-with-temp-text "
235 ** Sub-Head2.1 :export:
238 (org-test-with-backend test
241 "* Head2\n** Sub-Head2.1 :export:\n*** Sub-Head2.1.1\n"
242 (let ((org-tags-column 0))
243 (org-export-as 'test nil nil nil
'(:select-tags
("export"))))))))
244 ;; Test mixing include tags and exclude tags.
245 (org-test-with-temp-text "
247 ** Sub-Head1 :noexport:
250 ** Sub-Head1 :export:"
251 (org-test-with-backend test
254 "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
257 '(:select-tags
("export") :exclude-tags
("noexport")))))))
259 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
260 (org-test-with-temp-text "* TODO Head1"
261 (org-test-with-backend test
262 (should (equal (org-export-as 'test nil nil nil
'(:with-tasks nil
))
264 (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
265 (org-test-with-temp-text "* TODO Head1"
266 (org-test-with-backend test
267 (should (equal (org-export-as 'test nil nil nil
'(:with-tasks t
))
268 "* TODO Head1\n")))))
270 (org-test-with-temp-text "* Head1 :archive:"
271 (let ((org-archive-tag "archive"))
272 (org-test-with-backend test
274 (equal (org-export-as 'test nil nil nil
'(:with-archived-trees nil
))
276 (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
277 (let ((org-archive-tag "archive"))
278 (org-test-with-backend test
281 "\\* Head1[ \t]+:archive:"
282 (org-export-as 'test nil nil nil
283 '(:with-archived-trees headline
)))))))
284 (org-test-with-temp-text "* Head1 :archive:"
285 (let ((org-archive-tag "archive"))
286 (org-test-with-backend test
289 "\\`\\* Head1[ \t]+:archive:\n\\'"
290 (org-export-as 'test nil nil nil
'(:with-archived-trees t
)))))))
292 (let ((org-drawers '("TEST")))
293 (org-test-with-temp-text ":TEST:\ncontents\n:END:"
294 (org-test-with-backend test
295 (should (equal (org-export-as 'test nil nil nil
'(:with-drawers nil
))
297 (should (equal (org-export-as 'test nil nil nil
'(:with-drawers t
))
298 ":TEST:\ncontents\n:END:\n")))))
299 (let ((org-drawers '("FOO" "BAR")))
300 (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
301 (org-test-with-backend test
303 (equal (org-export-as 'test nil nil nil
'(:with-drawers
("FOO")))
304 ":FOO:\nkeep\n:END:\n")))))
306 (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
307 (org-test-with-backend test
309 (equal (org-export-as 'test nil nil nil
'(:with-timestamps t
))
310 "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>\n"))
312 (equal (org-export-as 'test nil nil nil
'(:with-timestamps nil
)) ""))
314 (equal (org-export-as 'test nil nil nil
'(:with-timestamps active
))
315 "<2012-04-29 sun. 10:45>\n"))
317 (equal (org-export-as 'test nil nil nil
'(:with-timestamps inactive
))
318 "[2012-04-29 sun. 10:45]\n"))))
320 (let ((org-clock-string "CLOCK:"))
321 (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
322 (org-test-with-backend test
324 (equal (org-export-as 'test nil nil nil
'(:with-clocks t
))
325 "CLOCK: [2012-04-29 sun. 10:45]\n"))
327 (equal (org-export-as 'test nil nil nil
'(:with-clocks nil
)) "")))))
329 (let ((org-closed-string "CLOSED:"))
330 (org-test-with-temp-text "CLOSED: [2012-04-29 sun. 10:45]"
331 (org-test-with-backend test
333 (equal (org-export-as 'test nil nil nil
'(:with-plannings t
))
334 "CLOSED: [2012-04-29 sun. 10:45]\n"))
336 (equal (org-export-as 'test nil nil nil
'(:with-plannings nil
))
339 (when (featurep 'org-inlinetask
)
342 (let ((org-inlinetask-min-level 15))
343 (org-test-with-temp-text "*************** Task"
344 (org-test-with-backend test
345 (org-export-as 'test nil nil nil
'(:with-inlinetasks nil
)))))
349 (let ((org-inlinetask-min-level 15))
350 (org-test-with-temp-text
351 "*************** Task\nContents\n*************** END"
352 (org-test-with-backend test
353 (org-export-as 'test nil nil nil
'(:with-inlinetasks nil
)))))
355 ;; Statistics cookies.
358 (org-test-with-temp-text "[0/0]"
359 (org-test-with-backend test
361 'test nil nil nil
'(:with-statistics-cookies nil
)))))))
363 (ert-deftest test-org-export
/comment-tree
()
364 "Test if export process ignores commented trees."
365 (let ((org-comment-string "COMMENT"))
366 (org-test-with-temp-text "* COMMENT Head1"
367 (org-test-with-backend test
368 (should (equal (org-export-as 'test
) ""))))))
370 (ert-deftest test-org-export
/export-scope
()
371 "Test all export scopes."
372 (org-test-with-temp-text "
377 (org-test-with-backend test
380 (should (equal (org-export-as 'test
'subtree
) "text\n*** Head3\n"))
382 (goto-char (point-min))
385 (should (equal (org-export-as 'test nil
'visible
) "* Head1\n"))
387 (goto-char (point-min))
389 (transient-mark-mode 1)
390 (push-mark (point) t t
)
391 (goto-char (point-at-eol))
392 (should (equal (org-export-as 'test
) "text\n"))))
393 ;; Subtree with a code block calling another block outside.
396 (org-test-with-temp-text "
398 #+BEGIN_SRC emacs-lisp :noweb yes :exports results
403 #+BEGIN_SRC emacs-lisp
406 (org-test-with-backend test
408 (org-export-as 'test
'subtree
)))))
410 (org-test-with-temp-text "Text"
411 (org-test-with-backend test
413 (cdr (assq 'test org-export-registered-backends
))
415 (cons (cons 'template
(lambda (body info
) (format "BEGIN\n%sEND" body
)))
416 (org-export-backend-translate-table 'test
)))
417 (should (equal (org-export-as 'test nil nil
'body-only
) "Text\n"))
418 (should (equal (org-export-as 'test
) "BEGIN\nText\nEND")))))
420 (ert-deftest test-org-export
/expand-include
()
421 "Test file inclusion in an Org buffer."
422 ;; Error when file isn't specified.
424 (org-test-with-temp-text "#+INCLUDE: dummy.org"
425 (org-export-expand-include-keyword)))
426 ;; Full insertion with recursive inclusion.
427 (org-test-with-temp-text
428 (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir
)
429 (org-export-expand-include-keyword)
430 (should (equal (buffer-string)
431 "Small Org file with an include keyword.
433 #+BEGIN_SRC emacs-lisp :exports results\n(+ 2 1)\n#+END_SRC
439 ;; Localized insertion.
440 (org-test-with-temp-text
441 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
443 (org-export-expand-include-keyword)
444 (should (equal (buffer-string)
445 "Small Org file with an include keyword.\n")))
446 ;; Insertion with constraints on headlines level.
447 (org-test-with-temp-text
449 "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\""
451 (org-export-expand-include-keyword)
452 (should (equal (buffer-string) "* Top heading\n** Heading\nbody\n")))
453 ;; Inclusion within an example block.
454 (org-test-with-temp-text
455 (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" example"
457 (org-export-expand-include-keyword)
461 "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n")))
462 ;; Inclusion within a src-block.
463 (org-test-with-temp-text
465 "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" src emacs-lisp"
467 (org-export-expand-include-keyword)
468 (should (equal (buffer-string)
469 "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"))))
471 (ert-deftest test-org-export
/expand-macro
()
472 "Test macro expansion in an Org buffer."
473 ;; Standard macro expansion.
475 (equal "#+MACRO: macro1 value\nvalue\n"
476 (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
477 (org-test-with-backend test
(org-export-as 'test
)))))
478 ;; Expand specific macros.
480 (equal "me 2012-03-29 me@here Title\n"
481 (org-test-with-temp-text
487 {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
488 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
489 (substring output
(string-match ".*\n\\'" output
))))))
490 ;; Expand specific macros when property contained a regular macro
494 (org-test-with-temp-text "
495 #+MACRO: macro1 value
496 #+TITLE: {{{macro1}}}
498 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
499 (substring output
(string-match ".*\n\\'" output
))))))
500 ;; Expand macros with templates in included files.
503 (org-test-with-temp-text
504 (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
505 {{{included-macro}}}" org-test-dir
)
506 (let ((output (org-test-with-backend test
(org-export-as 'test
))))
507 (substring output
(string-match ".*\n\\'" output
)))))))
509 (ert-deftest test-org-export
/user-ignore-list
()
510 "Test if `:ignore-list' accepts user input."
511 (org-test-with-backend test
512 (flet ((skip-note-head
514 ;; Ignore headlines with the word "note" in their title.
518 (when (string-match "\\<note\\>"
519 (org-element-property :raw-value headline
))
520 (org-export-ignore-element headline info
)))
523 ;; Install function in parse tree filters.
524 (let ((org-export-filter-parse-tree-functions '(skip-note-head)))
525 (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
526 (should (equal (org-export-as 'test
) "* Head1\n")))))))
528 (ert-deftest test-org-export
/before-processing-hook
()
529 "Test `org-export-before-processing-hook'."
532 "#+MACRO: mac val\nTest\n"
533 (org-test-with-backend test
534 (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
535 (let ((org-export-before-processing-hook
537 (while (re-search-forward "{{{" nil t
)
538 (let ((object (org-element-context)))
539 (when (eq (org-element-type object
) 'macro
)
541 (org-element-property :begin object
)
542 (org-element-property :end object
)))))))))
543 (org-export-as 'test
)))))))
545 (ert-deftest test-org-export
/before-parsing-hook
()
546 "Test `org-export-before-parsing-hook'."
548 (equal "Body 1\nBody 2\n"
549 (org-test-with-backend test
550 (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
551 (let ((org-export-before-parsing-hook
555 (delete-region (point) (progn (forward-line) (point)))))))))
556 (org-export-as 'test
)))))))
560 ;;; Affiliated Keywords
562 (ert-deftest test-org-export
/read-attribute
()
563 "Test `org-export-read-attribute' specifications."
567 (org-export-read-attribute
569 (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
570 (org-element-at-point)))
572 ;; Return nil on empty attribute.
574 (org-export-read-attribute
576 (org-test-with-temp-text "Paragraph" (org-element-at-point)))))
578 (ert-deftest test-org-export
/get-caption
()
579 "Test `org-export-get-caption' specifications."
580 ;; Without optional argument, return long caption
584 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
585 (org-export-get-caption (org-element-at-point)))))
586 ;; With optional argument, return short caption.
590 (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
591 (org-export-get-caption (org-element-at-point) t
))))
592 ;; Multiple lines are separated by white spaces.
596 (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
597 (org-export-get-caption (org-element-at-point))))))
603 (ert-deftest test-org-export
/define-backend
()
604 "Test back-end definition and accessors."
607 (equal '((headline . my-headline-test
))
608 (let (org-export-registered-backends)
609 (org-export-define-backend test
((headline . my-headline-test
)))
610 (org-export-backend-translate-table 'test
))))
613 (equal '((:filter-headline . my-filter
))
614 (let (org-export-registered-backends)
615 (org-export-define-backend test
616 ((headline . my-headline-test
))
617 :filters-alist
((:filter-headline . my-filter
)))
618 (org-export-backend-filters 'test
))))
621 (equal '((:prop value
))
622 (let (org-export-registered-backends)
623 (org-export-define-backend test
624 ((headline . my-headline-test
))
625 :options-alist
((:prop value
)))
626 (org-export-backend-options 'test
))))
629 (equal '(?k
"Test Export" test
)
630 (let (org-export-registered-backends)
631 (org-export-define-backend test
632 ((headline . my-headline-test
))
633 :menu-entry
(?k
"Test Export" test
))
634 (org-export-backend-menu 'test
))))
637 (equal '(("TEST" . org-element-export-block-parser
))
638 (let (org-export-registered-backends org-element-block-name-alist
)
639 (org-export-define-backend test
640 ((headline . my-headline-test
))
641 :export-block
("test"))
642 org-element-block-name-alist
))))
644 (ert-deftest test-org-export
/define-derived-backend
()
645 "Test `org-export-define-derived-backend' specifications."
646 ;; Error when parent back-end is not defined.
648 (let (org-export-registered-backends)
649 (org-export-define-derived-backend test parent
)))
650 ;; Append translation table to parent's.
652 (equal '((:headline . test
) (:headline . parent
))
653 (let (org-export-registered-backends)
654 (org-export-define-backend parent
((:headline . parent
)))
655 (org-export-define-derived-backend test parent
656 :translate-alist
((:headline . test
)))
657 (org-export-backend-translate-table 'test
)))))
659 (ert-deftest test-org-export
/derived-backend-p
()
660 "Test `org-export-derived-backend-p' specifications."
661 ;; Non-nil with direct match.
663 (let (org-export-registered-backends)
664 (org-export-define-backend test
((headline . test
)))
665 (org-export-derived-backend-p 'test
'test
)))
667 (let (org-export-registered-backends)
668 (org-export-define-backend test
((headline . test
)))
669 (org-export-define-derived-backend test2 test
)
670 (org-export-derived-backend-p 'test2
'test2
)))
671 ;; Non-nil with a direct parent.
673 (let (org-export-registered-backends)
674 (org-export-define-backend test
((headline . test
)))
675 (org-export-define-derived-backend test2 test
)
676 (org-export-derived-backend-p 'test2
'test
)))
677 ;; Non-nil with an indirect parent.
679 (let (org-export-registered-backends)
680 (org-export-define-backend test
((headline . test
)))
681 (org-export-define-derived-backend test2 test
)
682 (org-export-define-derived-backend test3 test2
)
683 (org-export-derived-backend-p 'test3
'test
)))
686 (let (org-export-registered-backends)
687 (org-export-define-backend test
((headline . test
)))
688 (org-export-define-backend test2
((headline . test2
)))
689 (org-export-derived-backend-p 'test2
'test
)))
691 (let (org-export-registered-backends)
692 (org-export-define-backend test
((headline . test
)))
693 (org-export-define-backend test2
((headline . test2
)))
694 (org-export-define-derived-backend test3 test2
)
695 (org-export-derived-backend-p 'test3
'test
))))
697 (ert-deftest test-org-export
/with-backend
()
698 "Test `org-export-with-backend' definition."
699 ;; Error when calling an undefined back-end
701 (let (org-export-registered-backends)
702 (org-export-with-backend 'test
"Test")))
703 ;; Error when called back-end doesn't have an appropriate
706 (let (org-export-registered-backends)
707 (org-export-define-backend test
((headline . ignore
)))
708 (org-export-with-backend 'test
"Test")))
709 ;; Otherwise, export using correct transcoder
712 (let (org-export-registered-backends)
713 (org-export-define-backend test
714 ((plain-text .
(lambda (text contents info
) "Failure"))))
715 (org-export-define-backend test2
716 ((plain-text .
(lambda (text contents info
) "Success"))))
717 (org-export-with-backend 'test2
"Test")))))
723 (ert-deftest test-org-export
/export-snippet
()
724 "Test export snippets transcoding."
725 (org-test-with-temp-text "@@test:A@@@@t:B@@"
726 (org-test-with-backend test
728 (cdr (assq 'test org-export-registered-backends
))
730 (cons (cons 'export-snippet
731 (lambda (snippet contents info
)
732 (when (eq (org-export-snippet-backend snippet
) 'test
)
733 (org-element-property :value snippet
))))
734 (org-export-backend-translate-table 'test
)))
735 (let ((org-export-snippet-translation-alist nil
))
736 (should (equal (org-export-as 'test
) "A\n")))
737 (let ((org-export-snippet-translation-alist '(("t" .
"test"))))
738 (should (equal (org-export-as 'test
) "AB\n"))))))
744 (ert-deftest test-org-export
/footnotes
()
745 "Test footnotes specifications."
746 (let ((org-footnote-section nil
)
747 (org-export-with-footnotes t
))
748 ;; 1. Read every type of footnote.
751 '((1 .
"A\n") (2 .
"B") (3 .
"C") (4 .
"D"))
752 (org-test-with-parsed-data
753 "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
755 tree
'footnote-reference
757 (let ((def (org-export-get-footnote-definition ref info
)))
758 (cons (org-export-get-footnote-number ref info
)
759 (if (eq (org-element-property :type ref
) 'inline
) (car def
)
760 (car (org-element-contents
761 (car (org-element-contents def
))))))))
763 ;; 2. Test nested footnotes order.
764 (org-test-with-parsed-data
765 "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
768 '((1 .
"fn:1") (2 .
"fn:2") (3 .
"fn:3") (4))
770 tree
'footnote-reference
772 (when (org-export-footnote-first-reference-p ref info
)
773 (cons (org-export-get-footnote-number ref info
)
774 (org-element-property :label ref
))))
776 ;; 3. Test nested footnote in invisible definitions.
777 (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
779 (narrow-to-region (point) (point-at-eol))
780 (let* ((tree (org-element-parse-buffer))
781 (info (org-combine-plists
783 (org-export-collect-tree-properties
784 tree
(org-export-get-environment)))))
785 ;; Both footnotes should be seen.
787 (= (length (org-export-collect-footnote-definitions tree info
)) 2))))
788 ;; 4. Test footnotes definitions collection.
789 (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
791 \[fn:2] B [fn:3] [fn::D].
794 (should (= (length (org-export-collect-footnote-definitions tree info
))
796 ;; 5. Test export of footnotes defined outside parsing scope.
797 (org-test-with-temp-text "[fn:1] Out of scope
800 (org-test-with-backend test
802 (cdr (assq 'test org-export-registered-backends
))
804 (cons (cons 'footnote-reference
805 (lambda (fn contents info
)
806 (org-element-interpret-data
807 (org-export-get-footnote-definition fn info
))))
808 (org-export-backend-translate-table 'test
)))
810 (should (equal "ParagraphOut of scope\n"
811 (org-export-as 'test
'subtree
)))))))
815 ;;; Headlines and Inlinetasks
817 (ert-deftest test-org-export
/get-relative-level
()
818 "Test `org-export-get-relative-level' specifications."
822 (let ((org-odd-levels-only nil
))
823 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
826 (lambda (h) (org-export-get-relative-level h info
))
831 (let ((org-odd-levels-only nil
))
832 (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
835 (lambda (h) (org-export-get-relative-level h info
))
838 (ert-deftest test-org-export
/low-level-p
()
839 "Test `org-export-low-level-p' specifications."
843 (let ((org-odd-levels-only nil
))
844 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
847 (lambda (h) (if (org-export-low-level-p h info
) 'yes
'no
))
848 (plist-put info
:headline-levels
1)))))))
850 (ert-deftest test-org-export
/get-headline-number
()
851 "Test `org-export-get-headline-number' specifications."
856 (let ((org-odd-levels-only nil
))
857 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
860 (lambda (h) (org-export-get-headline-number h info
))
862 ;; Missing levels are replaced with 0.
866 (let ((org-odd-levels-only nil
))
867 (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
870 (lambda (h) (org-export-get-headline-number h info
))
873 (ert-deftest test-org-export
/numbered-headline-p
()
874 "Test `org-export-numbered-headline-p' specifications."
875 ;; If `:section-numbers' is nil, never number headlines.
877 (org-test-with-parsed-data "* Headline"
880 (lambda (h) (org-export-numbered-headline-p h info
))
881 (plist-put info
:section-numbers nil
))))
882 ;; If `:section-numbers' is a number, only number headlines with
883 ;; a level greater that it.
887 (org-test-with-parsed-data "* Headline 1\n** Headline 2"
890 (lambda (h) (if (org-export-numbered-headline-p h info
) 'yes
'no
))
891 (plist-put info
:section-numbers
1)))))
892 ;; Otherwise, headlines are always numbered.
894 (org-test-with-parsed-data "* Headline"
897 (lambda (h) (org-export-numbered-headline-p h info
))
898 (plist-put info
:section-numbers t
)))))
900 (ert-deftest test-org-export
/number-to-roman
()
901 "Test `org-export-number-to-roman' specifications."
902 ;; If number is negative, return it as a string.
903 (should (equal (org-export-number-to-roman -
1) "-1"))
904 ;; Otherwise, return it as a roman number.
905 (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
907 (ert-deftest test-org-export
/get-tags
()
908 "Test `org-export-get-tags' specifications."
909 (let ((org-export-exclude-tags '("noexport"))
910 (org-export-select-tags '("export")))
911 ;; Standard test: tags which are not a select tag, an exclude tag,
912 ;; or specified as optional argument shouldn't be ignored.
914 (org-test-with-parsed-data "* Headline :tag:"
915 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
917 ;; Exclude tags are removed.
919 (org-test-with-parsed-data "* Headline :noexport:"
920 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
922 ;; Select tags are removed.
924 (org-test-with-parsed-data "* Headline :export:"
925 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
930 (org-test-with-parsed-data "* Headline :tag:export:"
931 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
933 ;; Tags provided in the optional argument are also ignored.
935 (org-test-with-parsed-data "* Headline :ignore:"
936 (org-export-get-tags (org-element-map tree
'headline
'identity info t
)
938 ;; Allow tag inheritance.
942 (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
945 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))
946 ;; Tag inheritance checks FILETAGS keywords.
950 (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
953 (lambda (hl) (org-export-get-tags hl info nil t
)) info
))))))
955 (ert-deftest test-org-export
/get-node-property
()
956 "Test`org-export-get-node-property' specifications."
960 (org-test-with-parsed-data "* Headline
964 (org-export-get-node-property
965 :prop
(org-element-map tree
'headline
'identity nil t
)))))
969 (org-test-with-parsed-data "* Parent
975 (org-export-get-node-property
976 :prop
(org-element-map tree
'paragraph
'identity nil t
) t
))))
977 ;; Cannot return a value before the first headline.
979 (org-test-with-parsed-data "Paragraph
984 (org-export-get-node-property
985 :prop
(org-element-map tree
'paragraph
'identity nil t
)))))
987 (ert-deftest test-org-export
/get-category
()
988 "Test `org-export-get-category' specifications."
992 (org-test-with-parsed-data "* Headline
996 (org-export-get-category
997 (org-element-map tree
'headline
'identity nil t
) info
))))
998 ;; Test inheritance from a parent headline.
1000 (equal '("value" "value")
1001 (org-test-with-parsed-data "* Headline1
1008 (lambda (hl) (org-export-get-category hl info
)) info
))))
1009 ;; Test inheritance from #+CATEGORY keyword
1012 (org-test-with-parsed-data "#+CATEGORY: value
1014 (org-export-get-category
1015 (org-element-map tree
'headline
'identity nil t
) info
))))
1016 ;; Test inheritance from file name.
1019 (org-test-with-parsed-data "* Headline"
1020 (let ((info (plist-put info
:input-file
"~/test.org")))
1021 (org-export-get-category
1022 (org-element-map tree
'headline
'identity nil t
) info
)))))
1026 (org-test-with-parsed-data "* Headline"
1027 (org-export-get-category
1028 (org-element-map tree
'headline
'identity nil t
) info
)))))
1030 (ert-deftest test-org-export
/first-sibling-p
()
1031 "Test `org-export-first-sibling-p' specifications."
1036 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1039 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1041 ;; Ignore headlines not exported.
1045 (let ((org-export-exclude-tags '("ignore")))
1046 (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
1049 (lambda (h) (if (org-export-first-sibling-p h info
) 'yes
'no
))
1052 (ert-deftest test-org-export
/last-sibling-p
()
1053 "Test `org-export-last-sibling-p' specifications."
1058 (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
1061 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1063 ;; Ignore headlines not exported.
1067 (let ((org-export-exclude-tags '("ignore")))
1068 (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
1071 (lambda (h) (if (org-export-last-sibling-p h info
) 'yes
'no
))
1078 (ert-deftest test-org-export
/get-coderef-format
()
1079 "Test `org-export-get-coderef-format' specifications."
1080 ;; A link without description returns "%s"
1081 (should (equal (org-export-get-coderef-format "(ref:line)" nil
)
1083 ;; Return "%s" when path is matched within description.
1084 (should (equal (org-export-get-coderef-format "path" "desc (path)")
1086 ;; Otherwise return description.
1087 (should (equal (org-export-get-coderef-format "path" "desc")
1090 (ert-deftest test-org-export
/inline-image-p
()
1091 "Test `org-export-inline-image-p' specifications."
1093 (org-export-inline-image-p
1094 (org-test-with-temp-text "[[#id]]"
1096 (org-element-parse-buffer) 'link
'identity nil t
))
1097 '(("custom-id" .
"id")))))
1099 (ert-deftest test-org-export
/fuzzy-link
()
1100 "Test fuzzy links specifications."
1101 ;; 1. Links to invisible (keyword) targets should be ignored.
1102 (org-test-with-parsed-data
1103 "Paragraph.\n#+TARGET: Test\n[[Test]]"
1108 (org-export-get-ordinal
1109 (org-export-resolve-fuzzy-link link info
) info
)) info
)))
1110 ;; 2. Link to an headline should return headline's number.
1111 (org-test-with-parsed-data
1112 "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
1114 ;; Note: Headline's number is in fact a list of numbers.
1119 (org-export-get-ordinal
1120 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1121 ;; 3. Link to a target in an item should return item's number.
1122 (org-test-with-parsed-data
1123 "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
1125 ;; Note: Item's number is in fact a list of numbers.
1130 (org-export-get-ordinal
1131 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1132 ;; 4. Link to a target in a footnote should return footnote's
1134 (org-test-with-parsed-data "
1135 Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
1141 (org-export-get-ordinal
1142 (org-export-resolve-fuzzy-link link info
) info
)) info
))))
1143 ;; 5. Link to a named element should return sequence number of that
1145 (org-test-with-parsed-data
1146 "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
1152 (org-export-get-ordinal
1153 (org-export-resolve-fuzzy-link link info
) info
)) info t
))))
1154 ;; 6. Link to a target not within an item, a table, a footnote
1155 ;; reference or definition should return section number.
1156 (org-test-with-parsed-data
1157 "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
1163 (org-export-get-ordinal
1164 (org-export-resolve-fuzzy-link link info
) info
)) info t
)))))
1166 (ert-deftest test-org-export
/resolve-coderef
()
1167 "Test `org-export-resolve-coderef' specifications."
1168 (let ((org-coderef-label-format "(ref:%s)"))
1169 ;; 1. A link to a "-n -k -r" block returns line number.
1170 (org-test-with-parsed-data
1171 "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
1172 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1173 (org-test-with-parsed-data
1174 "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1175 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1176 ;; 2. A link to a "-n -r" block returns line number.
1177 (org-test-with-parsed-data
1178 "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
1179 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1180 (org-test-with-parsed-data
1181 "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1182 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1183 ;; 3. A link to a "-n" block returns coderef.
1184 (org-test-with-parsed-data
1185 "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1186 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1187 (org-test-with-parsed-data
1188 "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
1189 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1190 ;; 4. A link to a "-r" block returns line number.
1191 (org-test-with-parsed-data
1192 "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1193 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1194 (org-test-with-parsed-data
1195 "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
1196 (should (= (org-export-resolve-coderef "coderef" info
) 1)))
1197 ;; 5. A link to a block without a switch returns coderef.
1198 (org-test-with-parsed-data
1199 "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
1200 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1201 (org-test-with-parsed-data
1202 "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
1203 (should (equal (org-export-resolve-coderef "coderef" info
) "coderef")))
1204 ;; 6. Correctly handle continued line numbers. A "+n" switch
1205 ;; should resume numbering from previous block with numbered
1206 ;; lines, ignoring blocks not numbering lines in the process.
1207 ;; A "-n" switch resets count.
1208 (org-test-with-parsed-data "
1213 #+BEGIN_SRC emacs-lisp
1217 #+BEGIN_SRC emacs-lisp +n -r
1218 \(+ 1 1) (ref:addition)
1221 #+BEGIN_EXAMPLE -n -r
1222 Another text. (ref:text)
1224 (should (= (org-export-resolve-coderef "addition" info
) 2))
1225 (should (= (org-export-resolve-coderef "text" info
) 1)))
1226 ;; 7. Recognize coderef with user-specified syntax.
1227 (org-test-with-parsed-data
1228 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
1229 (should (equal (org-export-resolve-coderef "text" info
) "text")))))
1231 (ert-deftest test-org-export
/resolve-fuzzy-link
()
1232 "Test `org-export-resolve-fuzzy-link' specifications."
1233 ;; 1. Match target objects.
1234 (org-test-with-parsed-data "<<target>> [[target]]"
1236 (org-export-resolve-fuzzy-link
1237 (org-element-map tree
'link
'identity info t
) info
)))
1238 ;; 2. Match target elements.
1239 (org-test-with-parsed-data "#+TARGET: target\n[[target]]"
1241 (org-export-resolve-fuzzy-link
1242 (org-element-map tree
'link
'identity info t
) info
)))
1243 ;; 3. Match named elements.
1244 (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
1246 (org-export-resolve-fuzzy-link
1247 (org-element-map tree
'link
'identity info t
) info
)))
1248 ;; 4. Match exact headline's name.
1249 (org-test-with-parsed-data "* My headline\n[[My headline]]"
1251 (org-export-resolve-fuzzy-link
1252 (org-element-map tree
'link
'identity info t
) info
)))
1253 ;; 5. Targets objects have priority over named elements and headline
1255 (org-test-with-parsed-data
1256 "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
1260 (org-export-resolve-fuzzy-link
1261 (org-element-map tree
'link
'identity info t
) info
)))))
1262 ;; 6. Named elements have priority over headline titles.
1263 (org-test-with-parsed-data
1264 "* target\n#+NAME: target\nParagraph\n\n[[target]]"
1268 (org-export-resolve-fuzzy-link
1269 (org-element-map tree
'link
'identity info t
) info
)))))
1270 ;; 7. If link's path starts with a "*", only match headline titles,
1272 (org-test-with-parsed-data
1273 "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
1277 (org-export-resolve-fuzzy-link
1278 (org-element-map tree
'link
'identity info t
) info
)))))
1279 ;; 8. Return nil if no match.
1280 (org-test-with-parsed-data "[[target]]"
1282 (org-export-resolve-fuzzy-link
1283 (org-element-map tree
'link
'identity info t
) info
))))
1285 (ert-deftest test-org-export
/resolve-id-link
()
1286 "Test `org-export-resolve-id-link' specifications."
1287 ;; 1. Regular test for custom-id link.
1288 (org-test-with-parsed-data "* Headline1
1295 (org-export-resolve-id-link
1296 (org-element-map tree
'link
'identity info t
) info
)))
1297 ;; 2. Failing test for custom-id link.
1298 (org-test-with-parsed-data "* Headline1
1305 (org-export-resolve-id-link
1306 (org-element-map tree
'link
'identity info t
) info
)))
1307 ;; 3. Test for internal id target.
1308 (org-test-with-parsed-data "* Headline1
1315 (org-export-resolve-id-link
1316 (org-element-map tree
'link
'identity info t
) info
)))
1317 ;; 4. Test for external id target.
1318 (org-test-with-parsed-data "[[id:aaaa]]"
1320 (org-export-resolve-id-link
1321 (org-element-map tree
'link
'identity info t
)
1322 (org-combine-plists info
'(:id-alist
(("aaaa" .
"external-file"))))))))
1324 (ert-deftest test-org-export
/resolve-radio-link
()
1325 "Test `org-export-resolve-radio-link' specifications."
1327 (org-test-with-temp-text "<<<radio>>> radio"
1328 (org-update-radio-target-regexp)
1330 (let* ((tree (org-element-parse-buffer))
1331 (info `(:parse-tree
,tree
)))
1332 (org-export-resolve-radio-link
1333 (org-element-map tree
'link
'identity info t
)
1335 ;; Radio target with objects.
1336 (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
1337 (org-update-radio-target-regexp)
1339 (let* ((tree (org-element-parse-buffer))
1340 (info `(:parse-tree
,tree
)))
1341 (org-export-resolve-radio-link
1342 (org-element-map tree
'link
'identity info t
)
1347 ;;; Src-block and example-block
1349 (ert-deftest test-org-export
/unravel-code
()
1350 "Test `org-export-unravel-code' function."
1351 (let ((org-coderef-label-format "(ref:%s)"))
1352 ;; 1. Code without reference.
1353 (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
1354 (should (equal (org-export-unravel-code (org-element-at-point))
1356 ;; 2. Code with reference.
1357 (org-test-with-temp-text
1358 "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
1359 (should (equal (org-export-unravel-code (org-element-at-point))
1360 '("(+ 1 1)\n" (1 .
"test")))))
1361 ;; 3. Code with user-defined reference.
1362 (org-test-with-temp-text
1363 "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
1364 (should (equal (org-export-unravel-code (org-element-at-point))
1365 '("(+ 1 1)\n" (1 .
"test")))))
1366 ;; 4. Code references keys are relative to the current block.
1367 (org-test-with-temp-text "
1376 (should (equal (org-export-unravel-code (org-element-at-point))
1377 '("(+ 2 2)\n(+ 3 3)\n" (2 .
"one")))))))
1383 (ert-deftest test-org-export
/activate-smart-quotes
()
1384 "Test `org-export-activate-smart-quotes' specifications."
1385 ;; Opening double quotes: standard test.
1388 '("some “paragraph")
1389 (let ((org-export-default-language "en"))
1390 (org-test-with-parsed-data "some \"paragraph"
1393 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1395 ;; Opening quotes: at the beginning of a paragraph.
1399 (let ((org-export-default-language "en"))
1400 (org-test-with-parsed-data "\"begin"
1403 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1405 ;; Opening quotes: after an object.
1409 (let ((org-export-default-language "en"))
1410 (org-test-with-parsed-data "=verb= \"begin"
1413 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1415 ;; Closing quotes: standard test.
1418 '("some” paragraph")
1419 (let ((org-export-default-language "en"))
1420 (org-test-with-parsed-data "some\" paragraph"
1423 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1425 ;; Closing quotes: at the end of a paragraph.
1429 (let ((org-export-default-language "en"))
1430 (org-test-with-parsed-data "end\""
1433 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1435 ;; Apostrophe: standard test.
1438 '("It shouldn’t fail")
1439 (let ((org-export-default-language "en"))
1440 (org-test-with-parsed-data "It shouldn't fail"
1443 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1445 ;; Apostrophe: before an object.
1449 (let ((org-export-default-language "en"))
1450 (org-test-with-parsed-data "a'=b="
1453 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1455 ;; Apostrophe: after an object.
1459 (let ((org-export-default-language "en"))
1460 (org-test-with-parsed-data "=code='s"
1463 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1465 ;; Special case: isolated quotes.
1467 (equal '("“" "”")
1468 (let ((org-export-default-language "en"))
1469 (org-test-with-parsed-data "\"$x$\""
1472 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1474 ;; Smart quotes in secondary strings.
1476 (equal '("“" "”")
1477 (let ((org-export-default-language "en"))
1478 (org-test-with-parsed-data "* \"$x$\""
1481 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1483 ;; Smart quotes in document keywords.
1485 (equal '("“" "”")
1486 (let ((org-export-default-language "en"))
1487 (org-test-with-parsed-data "#+TITLE: \"$x$\""
1489 (plist-get info
:title
) 'plain-text
1490 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1492 ;; Smart quotes in parsed affiliated keywords.
1494 (equal '("“" "”" "Paragraph")
1495 (let ((org-export-default-language "en"))
1496 (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
1499 (lambda (s) (org-export-activate-smart-quotes s
:html info
))
1500 info nil nil t
))))))
1506 (ert-deftest test-org-export
/special-column
()
1507 "Test if the table's special column is properly recognized."
1508 ;; 1. First column is special if it contains only a special marking
1509 ;; characters or empty cells.
1510 (org-test-with-temp-text "
1514 (org-export-table-has-special-column-p
1516 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1517 ;; 2. If the column contains anything else, it isn't special.
1518 (org-test-with-temp-text "
1522 (org-export-table-has-special-column-p
1524 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1525 ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
1527 (org-test-with-temp-text "
1536 (org-export-table-has-special-column-p
1538 (org-element-parse-buffer) 'table
'identity nil
'first-match
))))
1539 ;; 4. A first column with only empty cells isn't considered as
1541 (org-test-with-temp-text "
1545 (org-export-table-has-special-column-p
1547 (org-element-parse-buffer) 'table
'identity nil
'first-match
)))))
1549 (ert-deftest test-org-export
/table-row-is-special-p
()
1550 "Test `org-export-table-row-is-special-p' specifications."
1551 ;; 1. A row is special if it has a special marking character in the
1553 (org-test-with-parsed-data "| ! | 1 |"
1555 (org-export-table-row-is-special-p
1556 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1557 ;; 2. A row is special when its first field is "/"
1558 (org-test-with-parsed-data "
1562 (org-export-table-row-is-special-p
1563 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1564 ;; 3. A row only containing alignment cookies is also considered as
1566 (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
1568 (org-export-table-row-is-special-p
1569 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1570 ;; 4. Everything else isn't considered as special.
1571 (org-test-with-parsed-data "| \alpha | | c |"
1573 (org-export-table-row-is-special-p
1574 (org-element-map tree
'table-row
'identity nil
'first-match
) info
)))
1575 ;; 5. Table's rules are never considered as special rows.
1576 (org-test-with-parsed-data "|---+---|"
1578 (org-export-table-row-is-special-p
1579 (org-element-map tree
'table-row
'identity nil
'first-match
) info
))))
1581 (ert-deftest test-org-export
/has-header-p
()
1582 "Test `org-export-table-has-header-p' specifications."
1583 ;; 1. With an header.
1584 (org-test-with-parsed-data "
1589 (org-export-table-has-header-p
1590 (org-element-map tree
'table
'identity info
'first-match
)
1592 ;; 2. Without an header.
1593 (org-test-with-parsed-data "
1597 (org-export-table-has-header-p
1598 (org-element-map tree
'table
'identity info
'first-match
)
1600 ;; 3. Don't get fooled with starting and ending rules.
1601 (org-test-with-parsed-data "
1607 (org-export-table-has-header-p
1608 (org-element-map tree
'table
'identity info
'first-match
)
1611 (ert-deftest test-org-export
/table-row-group
()
1612 "Test `org-export-table-row-group' specifications."
1613 ;; 1. A rule creates a new group.
1614 (org-test-with-parsed-data "
1621 (mapcar (lambda (row) (org-export-table-row-group row info
))
1622 (org-element-map tree
'table-row
'identity
)))))
1623 ;; 2. Special rows are ignored in count.
1624 (org-test-with-parsed-data "
1631 (mapcar (lambda (row) (org-export-table-row-group row info
))
1632 (org-element-map tree
'table-row
'identity
)))))
1633 ;; 3. Double rules also are ignored in count.
1634 (org-test-with-parsed-data "
1642 (mapcar (lambda (row) (org-export-table-row-group row info
))
1643 (org-element-map tree
'table-row
'identity
))))))
1645 (ert-deftest test-org-export
/table-cell-width
()
1646 "Test `org-export-table-cell-width' specifications."
1647 ;; 1. Width is primarily determined by width cookies. If no cookie
1648 ;; is found, cell's width is nil.
1649 (org-test-with-parsed-data "
1650 | / | <l> | <6> | <l7> |
1655 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1656 (org-element-map tree
'table-cell
'identity info
)))))
1657 ;; 2. The last width cookie has precedence.
1658 (org-test-with-parsed-data "
1665 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1666 (org-element-map tree
'table-cell
'identity info
)))))
1667 ;; 3. Valid width cookies must have a specific row.
1668 (org-test-with-parsed-data "| <6> | cell |"
1672 (mapcar (lambda (cell) (org-export-table-cell-width cell info
))
1673 (org-element-map tree
'table-cell
'identity
))))))
1675 (ert-deftest test-org-export
/table-cell-alignment
()
1676 "Test `org-export-table-cell-alignment' specifications."
1677 (let ((org-table-number-fraction 0.5)
1678 (org-table-number-regexp "^[0-9]+$"))
1679 ;; 1. Alignment is primarily determined by alignment cookies.
1680 (org-test-with-temp-text "| <l> | <c> | <r> |"
1681 (let* ((tree (org-element-parse-buffer))
1682 (info `(:parse-tree
,tree
)))
1685 '(left center right
)
1686 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1687 (org-element-map tree
'table-cell
'identity
))))))
1688 ;; 2. The last alignment cookie has precedence.
1689 (org-test-with-parsed-data "
1695 '(right right right
)
1696 (mapcar (lambda (cell) (org-export-table-cell-alignment cell info
))
1697 (org-element-map tree
'table-cell
'identity
)))))
1698 ;; 3. If there's no cookie, cell's contents determine alignment.
1699 ;; A column mostly made of cells containing numbers will align
1700 ;; its cells to the right.
1701 (org-test-with-parsed-data "
1707 '(right right right
)
1708 (mapcar (lambda (cell)
1709 (org-export-table-cell-alignment cell info
))
1710 (org-element-map tree
'table-cell
'identity
)))))
1711 ;; 4. Otherwise, they will be aligned to the left.
1712 (org-test-with-parsed-data "
1719 (mapcar (lambda (cell)
1720 (org-export-table-cell-alignment cell info
))
1721 (org-element-map tree
'table-cell
'identity
)))))))
1723 (ert-deftest test-org-export
/table-cell-borders
()
1724 "Test `org-export-table-cell-borders' specifications."
1725 ;; 1. Recognize various column groups indicators.
1726 (org-test-with-parsed-data "| / | < | > | <> |"
1729 '((right bottom top
) (left bottom top
) (right bottom top
)
1730 (right left bottom top
))
1731 (mapcar (lambda (cell)
1732 (org-export-table-cell-borders cell info
))
1733 (org-element-map tree
'table-cell
'identity
)))))
1734 ;; 2. Accept shortcuts to define column groups.
1735 (org-test-with-parsed-data "| / | < | < |"
1738 '((right bottom top
) (right left bottom top
) (left bottom top
))
1739 (mapcar (lambda (cell)
1740 (org-export-table-cell-borders cell info
))
1741 (org-element-map tree
'table-cell
'identity
)))))
1742 ;; 3. A valid column groups row must start with a "/".
1743 (org-test-with-parsed-data "
1747 (equal '((top) (top) (bottom) (bottom))
1748 (mapcar (lambda (cell)
1749 (org-export-table-cell-borders cell info
))
1750 (org-element-map tree
'table-cell
'identity
)))))
1751 ;; 4. Take table rules into consideration.
1752 (org-test-with-parsed-data "
1757 (equal '((below top
) (bottom above
))
1758 (mapcar (lambda (cell)
1759 (org-export-table-cell-borders cell info
))
1760 (org-element-map tree
'table-cell
'identity
)))))
1761 ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
1762 ;; (resp. `bottom' and `below') borders. Any special row is
1764 (org-test-with-parsed-data "
1770 (equal '((bottom below top above
))
1772 (mapcar (lambda (cell)
1773 (org-export-table-cell-borders cell info
))
1774 (org-element-map tree
'table-cell
'identity
)))))))
1776 (ert-deftest test-org-export
/table-dimensions
()
1777 "Test `org-export-table-dimensions' specifications."
1778 ;; 1. Standard test.
1779 (org-test-with-parsed-data "
1784 (org-export-table-dimensions
1785 (org-element-map tree
'table
'identity info
'first-match
) info
))))
1786 ;; 2. Ignore horizontal rules and special columns.
1787 (org-test-with-parsed-data "
1794 (org-export-table-dimensions
1795 (org-element-map tree
'table
'identity info
'first-match
) info
)))))
1797 (ert-deftest test-org-export
/table-cell-address
()
1798 "Test `org-export-table-cell-address' specifications."
1799 ;; 1. Standard test: index is 0-based.
1800 (org-test-with-parsed-data "| a | b |"
1802 (equal '((0 .
0) (0 .
1))
1805 (lambda (cell) (org-export-table-cell-address cell info
))
1807 ;; 2. Special column isn't counted, nor are special rows.
1808 (org-test-with-parsed-data "
1813 (org-export-table-cell-address
1814 (car (last (org-element-map tree
'table-cell
'identity info
)))
1816 ;; 3. Tables rules do not count either.
1817 (org-test-with-parsed-data "
1825 (org-export-table-cell-address
1826 (car (last (org-element-map tree
'table-cell
'identity info
)))
1828 ;; 4. Return nil for special cells.
1829 (org-test-with-parsed-data "| / | a |"
1831 (org-export-table-cell-address
1832 (org-element-map tree
'table-cell
'identity nil
'first-match
)
1835 (ert-deftest test-org-export
/get-table-cell-at
()
1836 "Test `org-export-get-table-cell-at' specifications."
1837 ;; 1. Address ignores special columns, special rows and rules.
1838 (org-test-with-parsed-data "
1845 (org-element-contents
1846 (org-export-get-table-cell-at
1848 (org-element-map tree
'table
'identity info
'first-match
)
1850 ;; 2. Return value for a non-existent address is nil.
1851 (org-test-with-parsed-data "| a |"
1853 (org-export-get-table-cell-at
1855 (org-element-map tree
'table
'identity info
'first-match
)
1857 (org-test-with-parsed-data "| / |"
1859 (org-export-get-table-cell-at
1861 (org-element-map tree
'table
'identity info
'first-match
)
1864 (ert-deftest test-org-export
/table-cell-starts-colgroup-p
()
1865 "Test `org-export-table-cell-starts-colgroup-p' specifications."
1866 ;; 1. A cell at a beginning of a row always starts a column group.
1867 (org-test-with-parsed-data "| a |"
1869 (org-export-table-cell-starts-colgroup-p
1870 (org-element-map tree
'table-cell
'identity info
'first-match
)
1872 ;; 2. Special column should be ignored when determining the
1873 ;; beginning of the row.
1874 (org-test-with-parsed-data "
1878 (org-export-table-cell-starts-colgroup-p
1879 (org-element-map tree
'table-cell
'identity info
'first-match
)
1881 ;; 2. Explicit column groups.
1882 (org-test-with-parsed-data "
1891 (if (org-export-table-cell-starts-colgroup-p cell info
) 'yes
'no
))
1894 (ert-deftest test-org-export
/table-cell-ends-colgroup-p
()
1895 "Test `org-export-table-cell-ends-colgroup-p' specifications."
1896 ;; 1. A cell at the end of a row always ends a column group.
1897 (org-test-with-parsed-data "| a |"
1899 (org-export-table-cell-ends-colgroup-p
1900 (org-element-map tree
'table-cell
'identity info
'first-match
)
1902 ;; 2. Special column should be ignored when determining the
1903 ;; beginning of the row.
1904 (org-test-with-parsed-data "
1908 (org-export-table-cell-ends-colgroup-p
1909 (org-element-map tree
'table-cell
'identity info
'first-match
)
1911 ;; 3. Explicit column groups.
1912 (org-test-with-parsed-data "
1921 (if (org-export-table-cell-ends-colgroup-p cell info
) 'yes
'no
))
1924 (ert-deftest test-org-export
/table-row-starts-rowgroup-p
()
1925 "Test `org-export-table-row-starts-rowgroup-p' specifications."
1926 ;; 1. A row at the beginning of a table always starts a row group.
1927 ;; So does a row following a table rule.
1928 (org-test-with-parsed-data "
1938 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
1940 ;; 2. Special rows should be ignored when determining the beginning
1942 (org-test-with-parsed-data "
1954 (if (org-export-table-row-starts-rowgroup-p row info
) 'yes
'no
))
1957 (ert-deftest test-org-export
/table-row-ends-rowgroup-p
()
1958 "Test `org-export-table-row-ends-rowgroup-p' specifications."
1959 ;; 1. A row at the end of a table always ends a row group. So does
1960 ;; a row preceding a table rule.
1961 (org-test-with-parsed-data "
1971 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
1973 ;; 2. Special rows should be ignored when determining the beginning
1975 (org-test-with-parsed-data "
1987 (if (org-export-table-row-ends-rowgroup-p row info
) 'yes
'no
))
1990 (ert-deftest test-org-export
/table-row-starts-header-p
()
1991 "Test `org-export-table-row-starts-header-p' specifications."
1992 ;; 1. Only the row starting the first row group starts the table
1994 (org-test-with-parsed-data "
2005 (if (org-export-table-row-starts-header-p row info
) 'yes
'no
))
2007 ;; 2. A row cannot start an header if there's no header in the
2009 (org-test-with-parsed-data "
2013 (org-export-table-row-starts-header-p
2014 (org-element-map tree
'table-row
'identity info
'first-match
)
2017 (ert-deftest test-org-export
/table-row-ends-header-p
()
2018 "Test `org-export-table-row-ends-header-p' specifications."
2019 ;; 1. Only the row starting the first row group starts the table
2021 (org-test-with-parsed-data "
2032 (if (org-export-table-row-ends-header-p row info
) 'yes
'no
))
2034 ;; 2. A row cannot start an header if there's no header in the
2036 (org-test-with-parsed-data "
2040 (org-export-table-row-ends-header-p
2041 (org-element-map tree
'table-row
'identity info
'first-match
)
2048 (ert-deftest test-org-export
/timestamp-has-time-p
()
2049 "Test `org-export-timestamp-has-time-p' specifications."
2052 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
2053 (org-export-timestamp-has-time-p (org-element-context))))
2056 (org-test-with-temp-text "<2012-03-29 Thu>"
2057 (org-export-timestamp-has-time-p (org-element-context)))))
2059 (ert-deftest test-org-export
/format-timestamp
()
2060 "Test `org-export-format-timestamp' specifications."
2065 (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
2066 (org-export-format-timestamp (org-element-context) "%Y-%m-%d %R"))))
2071 (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
2072 (org-export-format-timestamp (org-element-context) "%Y-%m-%d" t
)))))
2074 (ert-deftest test-org-export
/split-timestamp-range
()
2075 "Test `org-export-split-timestamp-range' specifications."
2076 ;; Extract range start (active).
2079 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
2080 (let ((ts (org-export-split-timestamp-range (org-element-context))))
2081 (mapcar (lambda (p) (org-element-property p ts
))
2082 '(:year-end
:month-end
:day-end
))))))
2083 ;; Extract range start (inactive)
2086 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
2087 (let ((ts (org-export-split-timestamp-range (org-element-context))))
2088 (mapcar (lambda (p) (org-element-property p ts
))
2089 '(:year-end
:month-end
:day-end
))))))
2090 ;; Extract range end (active).
2093 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
2094 (let ((ts (org-export-split-timestamp-range
2095 (org-element-context) t
)))
2096 (mapcar (lambda (p) (org-element-property p ts
))
2097 '(:year-end
:month-end
:day-end
))))))
2098 ;; Extract range end (inactive)
2101 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
2102 (let ((ts (org-export-split-timestamp-range
2103 (org-element-context) t
)))
2104 (mapcar (lambda (p) (org-element-property p ts
))
2105 '(:year-end
:month-end
:day-end
))))))
2106 ;; Return the timestamp if not a range.
2108 (org-test-with-temp-text "[2012-03-29 Thu]"
2109 (let* ((ts-orig (org-element-context))
2110 (ts-copy (org-export-split-timestamp-range ts-orig
)))
2111 (eq ts-orig ts-copy
))))
2113 (org-test-with-temp-text "<%%(org-float t 4 2)>"
2114 (let* ((ts-orig (org-element-context))
2115 (ts-copy (org-export-split-timestamp-range ts-orig
)))
2116 (eq ts-orig ts-copy
))))
2117 ;; Check that parent is the same when a range was split.
2119 (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
2120 (let* ((ts-orig (org-element-context))
2121 (ts-copy (org-export-split-timestamp-range ts-orig
)))
2122 (eq (org-element-property :parent ts-orig
)
2123 (org-element-property :parent ts-copy
))))))
2125 (ert-deftest test-org-export
/translate-timestamp
()
2126 "Test `org-export-translate-timestamp' specifications."
2127 ;; Translate whole date range.
2130 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
2131 (let ((org-display-custom-times t
)
2132 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
2133 (org-export-translate-timestamp (org-element-context))))))
2134 ;; Translate date range start.
2137 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
2138 (let ((org-display-custom-times t
)
2139 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
2140 (org-export-translate-timestamp (org-element-context) 'start
)))))
2141 ;; Translate date range end.
2144 (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
2145 (let ((org-display-custom-times t
)
2146 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
2147 (org-export-translate-timestamp (org-element-context) 'end
)))))
2148 ;; Translate time range.
2151 (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
2152 (let ((org-display-custom-times t
)
2153 (org-time-stamp-custom-formats '("<%d>" .
"<%H>")))
2154 (org-export-translate-timestamp (org-element-context))))))
2155 ;; Translate non-range timestamp.
2158 (org-test-with-temp-text "<2012-03-29 Thu>"
2159 (let ((org-display-custom-times t
)
2160 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
2161 (org-export-translate-timestamp (org-element-context))))))
2162 ;; Do not change `diary' timestamps.
2164 (equal "<%%(org-float t 4 2)>"
2165 (org-test-with-temp-text "<%%(org-float t 4 2)>"
2166 (let ((org-display-custom-times t
)
2167 (org-time-stamp-custom-formats '("<%d>" .
"<%d>")))
2168 (org-export-translate-timestamp (org-element-context)))))))
2174 (ert-deftest test-org-export
/get-next-element
()
2175 "Test `org-export-get-next-element' specifications."
2179 (org-test-with-parsed-data "* Headline\n*a* b"
2180 (org-export-get-next-element
2181 (org-element-map tree
'bold
'identity info t
) info
))))
2182 ;; Return nil when no previous element.
2184 (org-test-with-parsed-data "* Headline\na *b*"
2185 (org-export-get-next-element
2186 (org-element-map tree
'bold
'identity info t
) info
)))
2187 ;; Non-exportable elements are ignored.
2189 (let ((org-export-with-timestamps nil
))
2190 (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
2191 (org-export-get-next-element
2192 (org-element-map tree
'entity
'identity info t
) info
))))
2193 ;; Find next element in secondary strings.
2196 (org-test-with-parsed-data "* a =verb="
2198 (org-export-get-next-element
2199 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2200 ;; Find next element in document keywords.
2203 (org-test-with-parsed-data "#+TITLE: a =verb="
2205 (org-export-get-next-element
2207 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2208 ;; Find next element in parsed affiliated keywords.
2211 (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
2213 (org-export-get-next-element
2214 (org-element-map tree
'plain-text
'identity info t nil t
) info
))))))
2216 (ert-deftest test-org-export
/get-previous-element
()
2217 "Test `org-export-get-previous-element' specifications."
2221 (org-test-with-parsed-data "* Headline\na *b*"
2222 (org-export-get-previous-element
2223 (org-element-map tree
'bold
'identity info t
) info
))))
2224 ;; Return nil when no previous element.
2226 (org-test-with-parsed-data "* Headline\n*a* b"
2227 (org-export-get-previous-element
2228 (org-element-map tree
'bold
'identity info t
) info
)))
2229 ;; Non-exportable elements are ignored.
2231 (let ((org-export-with-timestamps nil
))
2232 (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
2233 (org-export-get-previous-element
2234 (org-element-map tree
'entity
'identity info t
) info
))))
2235 ;; Find previous element in secondary strings.
2238 (org-test-with-parsed-data "* =verb= a"
2240 (org-export-get-previous-element
2241 (org-element-map tree
'plain-text
'identity info t
) info
)))))
2242 ;; Find previous element in document keywords.
2245 (org-test-with-parsed-data "#+TITLE: =verb= a"
2247 (org-export-get-previous-element
2249 (plist-get info
:title
) 'plain-text
'identity info t
) info
)))))
2250 ;; Find previous element in parsed affiliated keywords.
2253 (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
2255 (org-export-get-previous-element
2256 (org-element-map tree
'plain-text
'identity info t nil t
) info
))))))
2259 (provide 'test-org-export
)
2260 ;;; test-org-export.el end here