test-org-export.el 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669
  1. ;;; test-org-export.el --- Tests for org-export.el
  2. ;; Copyright (C) 2012 Nicolas Goaziou
  3. ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
  4. ;; This file is not part of GNU Emacs.
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Code:
  16. (unless (featurep 'org-export)
  17. (signal 'missing-test-dependency "org-export"))
  18. (defmacro org-test-with-backend (backend &rest body)
  19. "Execute body with an export back-end defined.
  20. BACKEND is the name of the back-end. BODY is the body to
  21. execute. The defined back-end simply returns parsed data as Org
  22. syntax."
  23. (declare (debug (form body)) (indent 1))
  24. `(let ((,(intern (format "org-%s-translate-alist" backend))
  25. ',(let (transcode-table)
  26. (dolist (type (append org-element-all-elements
  27. org-element-all-objects)
  28. transcode-table)
  29. (push
  30. (cons type
  31. (lambda (obj contents info)
  32. (funcall
  33. (intern (format "org-element-%s-interpreter" type))
  34. obj contents)))
  35. transcode-table)))))
  36. (progn ,@body)))
  37. (defmacro org-test-with-parsed-data (data &rest body)
  38. "Execute body with parsed data available.
  39. DATA is a string containing the data to be parsed. BODY is the
  40. body to execute. Parse tree is available under the `tree'
  41. variable, and communication channel under `info'.
  42. This function calls `org-export-collect-tree-properties'. As
  43. such, `:ignore-list' (for `org-element-map') and
  44. `:parse-tree' (for `org-export-get-genealogy') properties are
  45. already filled in `info'."
  46. (declare (debug (form body)) (indent 1))
  47. `(org-test-with-temp-text ,data
  48. (let* ((tree (org-element-parse-buffer))
  49. (info (org-export-collect-tree-properties
  50. tree (org-export-get-environment))))
  51. ,@body)))
  52. ;;; Tests
  53. (ert-deftest test-org-export/parse-option-keyword ()
  54. "Test reading all standard #+OPTIONS: items."
  55. (should
  56. (equal
  57. (org-export--parse-option-keyword
  58. "H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t
  59. *:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t inline:nil")
  60. '(:headline-levels
  61. 1 :preserve-breaks t :section-numbers t :time-stamp-file t
  62. :with-archived-trees t :with-author t :with-creator t :with-drawers t
  63. :with-email t :with-emphasize t :with-entities t :with-fixed-width t
  64. :with-footnotes t :with-inlinetasks nil :with-priority t
  65. :with-special-strings t :with-sub-superscript t :with-toc t :with-tables t
  66. :with-tags t :with-tasks t :with-timestamps t :with-todo-keywords t)))
  67. ;; Test some special values.
  68. (should
  69. (equal
  70. (org-export--parse-option-keyword
  71. "arch:headline creator:comment d:(\"TEST\")
  72. ^:{} toc:1 tags:not-in-toc tasks:todo num:2 <:active")
  73. '( :section-numbers
  74. 2
  75. :with-archived-trees headline :with-creator comment
  76. :with-drawers ("TEST") :with-sub-superscript {} :with-toc 1
  77. :with-tags not-in-toc :with-tasks todo :with-timestamps active))))
  78. (ert-deftest test-org-export/get-inbuffer-options ()
  79. "Test reading all standard export keywords."
  80. (should
  81. (equal
  82. (org-test-with-temp-text "#+AUTHOR: Me, Myself and I
  83. #+CREATOR: Idem
  84. #+DATE: Today
  85. #+DESCRIPTION: Testing
  86. #+DESCRIPTION: with two lines
  87. #+EMAIL: some@email.org
  88. #+EXCLUDE_TAGS: noexport invisible
  89. #+KEYWORDS: test
  90. #+LANGUAGE: en
  91. #+SELECT_TAGS: export
  92. #+TITLE: Some title
  93. #+TITLE: with spaces"
  94. (org-export--get-inbuffer-options))
  95. '(:author
  96. ("Me, Myself and I") :creator "Idem" :date ("Today")
  97. :description "Testing\nwith two lines" :email "some@email.org"
  98. :exclude-tags ("noexport" "invisible") :keywords "test" :language "en"
  99. :select-tags ("export") :title ("Some title with spaces")))))
  100. (ert-deftest test-org-export/get-subtree-options ()
  101. "Test setting options from headline's properties."
  102. ;; EXPORT_TITLE.
  103. (org-test-with-temp-text "#+TITLE: Title
  104. * Headline
  105. :PROPERTIES:
  106. :EXPORT_TITLE: Subtree Title
  107. :END:
  108. Paragraph"
  109. (forward-line)
  110. (should (equal (plist-get (org-export-get-environment nil t) :title)
  111. '("Subtree Title"))))
  112. :title
  113. '("subtree-title")
  114. ;; EXPORT_OPTIONS.
  115. (org-test-with-temp-text "#+OPTIONS: H:1
  116. * Headline
  117. :PROPERTIES:
  118. :EXPORT_OPTIONS: H:2
  119. :END:
  120. Paragraph"
  121. (forward-line)
  122. (should
  123. (= 2 (plist-get (org-export-get-environment nil t) :headline-levels))))
  124. ;; EXPORT_DATE.
  125. (org-test-with-temp-text "#+DATE: today
  126. * Headline
  127. :PROPERTIES:
  128. :EXPORT_DATE: 29-03-2012
  129. :END:
  130. Paragraph"
  131. (forward-line)
  132. (should (equal (plist-get (org-export-get-environment nil t) :date)
  133. '("29-03-2012"))))
  134. ;; Export properties are case-insensitive.
  135. (org-test-with-temp-text "* Headline
  136. :PROPERTIES:
  137. :EXPORT_Date: 29-03-2012
  138. :END:
  139. Paragraph"
  140. (should (equal (plist-get (org-export-get-environment nil t) :date)
  141. '("29-03-2012")))))
  142. (ert-deftest test-org-export/handle-options ()
  143. "Test if export options have an impact on output."
  144. ;; Test exclude tags.
  145. (org-test-with-temp-text "* Head1 :noexport:"
  146. (org-test-with-backend test
  147. (should
  148. (equal (org-export-as 'test nil nil nil '(:exclude-tags ("noexport")))
  149. ""))))
  150. ;; Test include tags.
  151. (org-test-with-temp-text "
  152. * Head1
  153. * Head2
  154. ** Sub-Head2.1 :export:
  155. *** Sub-Head2.1.1
  156. * Head2"
  157. (org-test-with-backend test
  158. (should
  159. (equal
  160. "* Head2\n** Sub-Head2.1 :export:\n*** Sub-Head2.1.1\n"
  161. (let ((org-tags-column 0))
  162. (org-export-as 'test nil nil nil '(:select-tags ("export"))))))))
  163. ;; Test mixing include tags and exclude tags.
  164. (org-test-with-temp-text "
  165. * Head1 :export:
  166. ** Sub-Head1 :noexport:
  167. ** Sub-Head2
  168. * Head2 :noexport:
  169. ** Sub-Head1 :export:"
  170. (org-test-with-backend test
  171. (should
  172. (string-match
  173. "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
  174. (org-export-as
  175. 'test nil nil nil
  176. '(:select-tags ("export") :exclude-tags ("noexport")))))))
  177. ;; Ignore tasks.
  178. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  179. (org-test-with-temp-text "* TODO Head1"
  180. (org-test-with-backend test
  181. (should (equal (org-export-as 'test nil nil nil '(:with-tasks nil))
  182. "")))))
  183. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  184. (org-test-with-temp-text "* TODO Head1"
  185. (org-test-with-backend test
  186. (should (equal (org-export-as 'test nil nil nil '(:with-tasks t))
  187. "* TODO Head1\n")))))
  188. ;; Archived tree.
  189. (org-test-with-temp-text "* Head1 :archive:"
  190. (let ((org-archive-tag "archive"))
  191. (org-test-with-backend test
  192. (should
  193. (equal (org-export-as 'test nil nil nil '(:with-archived-trees nil))
  194. "")))))
  195. (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
  196. (let ((org-archive-tag "archive"))
  197. (org-test-with-backend test
  198. (should
  199. (string-match
  200. "\\* Head1[ \t]+:archive:"
  201. (org-export-as 'test nil nil nil
  202. '(:with-archived-trees headline)))))))
  203. (org-test-with-temp-text "* Head1 :archive:"
  204. (let ((org-archive-tag "archive"))
  205. (org-test-with-backend test
  206. (should
  207. (string-match
  208. "\\`\\* Head1[ \t]+:archive:\n\\'"
  209. (org-export-as 'test nil nil nil '(:with-archived-trees t)))))))
  210. ;; Drawers.
  211. (let ((org-drawers '("TEST")))
  212. (org-test-with-temp-text ":TEST:\ncontents\n:END:"
  213. (org-test-with-backend test
  214. (should (equal (org-export-as 'test nil nil nil '(:with-drawers nil))
  215. ""))
  216. (should (equal (org-export-as 'test nil nil nil '(:with-drawers t))
  217. ":TEST:\ncontents\n:END:\n")))))
  218. (let ((org-drawers '("FOO" "BAR")))
  219. (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
  220. (org-test-with-backend test
  221. (should
  222. (equal (org-export-as 'test nil nil nil '(:with-drawers ("FOO")))
  223. ":FOO:\nkeep\n:END:\n")))))
  224. ;; Timestamps.
  225. (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
  226. (org-test-with-backend test
  227. (should
  228. (equal (org-export-as 'test nil nil nil '(:with-timestamps t))
  229. "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>\n"))
  230. (should
  231. (equal (org-export-as 'test nil nil nil '(:with-timestamps nil)) ""))
  232. (should
  233. (equal (org-export-as 'test nil nil nil '(:with-timestamps active))
  234. "<2012-04-29 sun. 10:45>\n"))
  235. (should
  236. (equal (org-export-as 'test nil nil nil '(:with-timestamps inactive))
  237. "[2012-04-29 sun. 10:45]\n"))))
  238. ;; Clocks.
  239. (let ((org-clock-string "CLOCK:"))
  240. (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
  241. (org-test-with-backend test
  242. (should
  243. (equal (org-export-as 'test nil nil nil '(:with-clocks t))
  244. "CLOCK: [2012-04-29 sun. 10:45]\n"))
  245. (should
  246. (equal (org-export-as 'test nil nil nil '(:with-clocks nil)) "")))))
  247. ;; Plannings.
  248. (let ((org-closed-string "CLOSED:"))
  249. (org-test-with-temp-text "CLOSED: [2012-04-29 sun. 10:45]"
  250. (org-test-with-backend test
  251. (should
  252. (equal (org-export-as 'test nil nil nil '(:with-plannings t))
  253. "CLOSED: [2012-04-29 sun. 10:45]\n"))
  254. (should
  255. (equal (org-export-as 'test nil nil nil '(:with-plannings nil))
  256. "")))))
  257. ;; Inlinetasks.
  258. (when (featurep 'org-inlinetask)
  259. (should
  260. (equal
  261. (let ((org-inlinetask-min-level 15))
  262. (org-test-with-temp-text "*************** Task"
  263. (org-test-with-backend test
  264. (org-export-as 'test nil nil nil '(:with-inlinetasks nil)))))
  265. ""))
  266. (should
  267. (equal
  268. (let ((org-inlinetask-min-level 15))
  269. (org-test-with-temp-text
  270. "*************** Task\nContents\n*************** END"
  271. (org-test-with-backend test
  272. (org-export-as 'test nil nil nil '(:with-inlinetasks nil)))))
  273. ""))))
  274. (ert-deftest test-org-export/comment-tree ()
  275. "Test if export process ignores commented trees."
  276. (let ((org-comment-string "COMMENT"))
  277. (org-test-with-temp-text "* COMMENT Head1"
  278. (org-test-with-backend test
  279. (should (equal (org-export-as 'test) ""))))))
  280. (ert-deftest test-org-export/export-scope ()
  281. "Test all export scopes."
  282. (org-test-with-temp-text "
  283. * Head1
  284. ** Head2
  285. text
  286. *** Head3"
  287. (org-test-with-backend test
  288. ;; Subtree.
  289. (forward-line 3)
  290. (should (equal (org-export-as 'test 'subtree) "text\n*** Head3\n"))
  291. ;; Visible.
  292. (goto-char (point-min))
  293. (forward-line)
  294. (org-cycle)
  295. (should (equal (org-export-as 'test nil 'visible) "* Head1\n"))
  296. ;; Body only.
  297. (flet ((org-test-template (body info) (format "BEGIN\n%sEND" body)))
  298. (push '(template . org-test-template) org-test-translate-alist)
  299. (should (equal (org-export-as 'test nil nil 'body-only)
  300. "* Head1\n** Head2\ntext\n*** Head3\n"))
  301. (should (equal (org-export-as 'test)
  302. "BEGIN\n* Head1\n** Head2\ntext\n*** Head3\nEND")))
  303. ;; Region.
  304. (goto-char (point-min))
  305. (forward-line 3)
  306. (transient-mark-mode 1)
  307. (push-mark (point) t t)
  308. (goto-char (point-at-eol))
  309. (should (equal (org-export-as 'test) "text\n"))))
  310. ;; Subtree with a code block calling another block outside.
  311. (org-test-with-temp-text "
  312. * Head1
  313. #+BEGIN_SRC emacs-lisp :noweb yes :exports results
  314. <<test>>
  315. #+END_SRC
  316. * Head2
  317. #+NAME: test
  318. #+BEGIN_SRC emacs-lisp
  319. \(+ 1 2)
  320. #+END_SRC"
  321. (org-test-with-backend test
  322. (forward-line 1)
  323. (should (equal (org-export-as 'test 'subtree) ": 3\n")))))
  324. (ert-deftest test-org-export/expand-include ()
  325. "Test file inclusion in an Org buffer."
  326. ;; Full insertion with recursive inclusion.
  327. (org-test-with-temp-text
  328. (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir)
  329. (org-export-expand-include-keyword)
  330. (should (equal (buffer-string)
  331. "Small Org file with an include keyword.
  332. #+BEGIN_SRC emacs-lisp :exports results\n(+ 2 1)\n#+END_SRC
  333. Success!
  334. * Heading
  335. body\n")))
  336. ;; Localized insertion.
  337. (org-test-with-temp-text
  338. (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
  339. org-test-dir)
  340. (org-export-expand-include-keyword)
  341. (should (equal (buffer-string)
  342. "Small Org file with an include keyword.\n")))
  343. ;; Insertion with constraints on headlines level.
  344. (org-test-with-temp-text
  345. (format
  346. "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\""
  347. org-test-dir)
  348. (org-export-expand-include-keyword)
  349. (should (equal (buffer-string) "* Top heading\n** Heading\nbody\n")))
  350. ;; Inclusion within an example block.
  351. (org-test-with-temp-text
  352. (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" example"
  353. org-test-dir)
  354. (org-export-expand-include-keyword)
  355. (should
  356. (equal
  357. (buffer-string)
  358. "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n")))
  359. ;; Inclusion within a src-block.
  360. (org-test-with-temp-text
  361. (format
  362. "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" src emacs-lisp"
  363. org-test-dir)
  364. (org-export-expand-include-keyword)
  365. (should (equal (buffer-string)
  366. "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"))))
  367. (ert-deftest test-org-export/user-ignore-list ()
  368. "Test if `:ignore-list' accepts user input."
  369. (org-test-with-backend test
  370. (flet ((skip-note-head
  371. (data backend info)
  372. ;; Ignore headlines with the word "note" in their title.
  373. (org-element-map
  374. data 'headline
  375. (lambda (headline)
  376. (when (string-match "\\<note\\>"
  377. (org-element-property :raw-value headline))
  378. (org-export-ignore-element headline info)))
  379. info)
  380. data))
  381. ;; Install function in parse tree filters.
  382. (let ((org-export-filter-parse-tree-functions '(skip-note-head)))
  383. (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
  384. (should (equal (org-export-as 'test) "* Head1\n")))))))
  385. (ert-deftest test-org-export/before-parsing-hook ()
  386. "Test `org-export-before-parsing-hook'."
  387. (org-test-with-backend test
  388. (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
  389. (let ((org-export-before-parsing-hook
  390. '((lambda (backend)
  391. (org-map-entries
  392. (lambda ()
  393. (delete-region (point) (progn (forward-line) (point)))))))))
  394. (should (equal (org-export-as 'test) "Body 1\nBody 2\n"))))))
  395. ;;; Affiliated Keywords
  396. (ert-deftest test-org-export/read-attribute ()
  397. "Test `org-export-read-attribute' specifications."
  398. ;; Standard test.
  399. (should
  400. (equal
  401. (org-export-read-attribute
  402. :attr_html
  403. (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
  404. (org-element-at-point)))
  405. '(:a 1 :b 2)))
  406. ;; Return nil on empty attribute.
  407. (should-not
  408. (org-export-read-attribute
  409. :attr_html
  410. (org-test-with-temp-text "Paragraph" (org-element-at-point)))))
  411. ;;; Export Snippets
  412. (ert-deftest test-org-export/export-snippet ()
  413. "Test export snippets transcoding."
  414. (org-test-with-temp-text "@@test:A@@@@t:B@@"
  415. (org-test-with-backend test
  416. (let ((org-test-translate-alist
  417. (cons (cons 'export-snippet
  418. (lambda (snippet contents info)
  419. (when (eq (org-export-snippet-backend snippet) 'test)
  420. (org-element-property :value snippet))))
  421. org-test-translate-alist)))
  422. (let ((org-export-snippet-translation-alist nil))
  423. (should (equal (org-export-as 'test) "A\n")))
  424. (let ((org-export-snippet-translation-alist '(("t" . "test"))))
  425. (should (equal (org-export-as 'test) "AB\n")))))))
  426. ;;; Footnotes
  427. (ert-deftest test-org-export/footnotes ()
  428. "Test footnotes specifications."
  429. (let ((org-footnote-section nil)
  430. (org-export-with-footnotes t))
  431. ;; 1. Read every type of footnote.
  432. (should
  433. (equal
  434. '((1 . "A\n") (2 . "B") (3 . "C") (4 . "D"))
  435. (org-test-with-parsed-data
  436. "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
  437. (org-element-map
  438. tree 'footnote-reference
  439. (lambda (ref)
  440. (let ((def (org-export-get-footnote-definition ref info)))
  441. (cons (org-export-get-footnote-number ref info)
  442. (if (eq (org-element-property :type ref) 'inline) (car def)
  443. (car (org-element-contents
  444. (car (org-element-contents def))))))))
  445. info))))
  446. ;; 2. Test nested footnotes order.
  447. (org-test-with-parsed-data
  448. "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
  449. (should
  450. (equal
  451. '((1 . "fn:1") (2 . "fn:2") (3 . "fn:3") (4))
  452. (org-element-map
  453. tree 'footnote-reference
  454. (lambda (ref)
  455. (when (org-export-footnote-first-reference-p ref info)
  456. (cons (org-export-get-footnote-number ref info)
  457. (org-element-property :label ref))))
  458. info))))
  459. ;; 3. Test nested footnote in invisible definitions.
  460. (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
  461. ;; Hide definitions.
  462. (narrow-to-region (point) (point-at-eol))
  463. (let* ((tree (org-element-parse-buffer))
  464. (info (org-combine-plists
  465. `(:parse-tree ,tree)
  466. (org-export-collect-tree-properties
  467. tree (org-export-get-environment)))))
  468. ;; Both footnotes should be seen.
  469. (should
  470. (= (length (org-export-collect-footnote-definitions tree info)) 2))))
  471. ;; 4. Test footnotes definitions collection.
  472. (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
  473. \[fn:2] B [fn:3] [fn::D].
  474. \[fn:3] C."
  475. (should (= (length (org-export-collect-footnote-definitions tree info))
  476. 4)))
  477. ;; 5. Test export of footnotes defined outside parsing scope.
  478. (org-test-with-temp-text "[fn:1] Out of scope
  479. * Title
  480. Paragraph[fn:1]"
  481. (org-test-with-backend test
  482. (let ((org-test-translate-alist
  483. (cons (cons 'footnote-reference
  484. (lambda (fn contents info)
  485. (org-element-interpret-data
  486. (org-export-get-footnote-definition fn info))))
  487. org-test-translate-alist)))
  488. (forward-line)
  489. (should (equal "ParagraphOut of scope\n"
  490. (org-export-as 'test 'subtree))))))))
  491. ;;; Headlines and Inlinetasks
  492. (ert-deftest test-org-export/get-relative-level ()
  493. "Test `org-export-get-relative-level' specifications."
  494. ;; Standard test.
  495. (should
  496. (equal '(1 2)
  497. (let ((org-odd-levels-only nil))
  498. (org-test-with-parsed-data "* Headline 1\n** Headline 2"
  499. (org-element-map
  500. tree 'headline
  501. (lambda (h) (org-export-get-relative-level h info))
  502. info)))))
  503. ;; Missing levels
  504. (should
  505. (equal '(1 3)
  506. (let ((org-odd-levels-only nil))
  507. (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
  508. (org-element-map
  509. tree 'headline
  510. (lambda (h) (org-export-get-relative-level h info))
  511. info))))))
  512. (ert-deftest test-org-export/low-level-p ()
  513. "Test `org-export-low-level-p' specifications."
  514. (should
  515. (equal
  516. '(no yes)
  517. (let ((org-odd-levels-only nil))
  518. (org-test-with-parsed-data "* Headline 1\n** Headline 2"
  519. (org-element-map
  520. tree 'headline
  521. (lambda (h) (if (org-export-low-level-p h info) 'yes 'no))
  522. (plist-put info :headline-levels 1)))))))
  523. (ert-deftest test-org-export/get-headline-number ()
  524. "Test `org-export-get-headline-number' specifications."
  525. ;; Standard test.
  526. (should
  527. (equal
  528. '((1) (1 1))
  529. (let ((org-odd-levels-only nil))
  530. (org-test-with-parsed-data "* Headline 1\n** Headline 2"
  531. (org-element-map
  532. tree 'headline
  533. (lambda (h) (org-export-get-headline-number h info))
  534. info)))))
  535. ;; Missing levels are replaced with 0.
  536. (should
  537. (equal
  538. '((1) (1 0 1))
  539. (let ((org-odd-levels-only nil))
  540. (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
  541. (org-element-map
  542. tree 'headline
  543. (lambda (h) (org-export-get-headline-number h info))
  544. info))))))
  545. (ert-deftest test-org-export/numbered-headline-p ()
  546. "Test `org-export-numbered-headline-p' specifications."
  547. ;; If `:section-numbers' is nil, never number headlines.
  548. (should-not
  549. (org-test-with-parsed-data "* Headline"
  550. (org-element-map
  551. tree 'headline
  552. (lambda (h) (org-export-numbered-headline-p h info))
  553. (plist-put info :section-numbers nil))))
  554. ;; If `:section-numbers' is a number, only number headlines with
  555. ;; a level greater that it.
  556. (should
  557. (equal
  558. '(yes no)
  559. (org-test-with-parsed-data "* Headline 1\n** Headline 2"
  560. (org-element-map
  561. tree 'headline
  562. (lambda (h) (if (org-export-numbered-headline-p h info) 'yes 'no))
  563. (plist-put info :section-numbers 1)))))
  564. ;; Otherwise, headlines are always numbered.
  565. (should
  566. (org-test-with-parsed-data "* Headline"
  567. (org-element-map
  568. tree 'headline
  569. (lambda (h) (org-export-numbered-headline-p h info))
  570. (plist-put info :section-numbers t)))))
  571. (ert-deftest test-org-export/number-to-roman ()
  572. "Test `org-export-number-to-roman' specifications."
  573. ;; If number is negative, return it as a string.
  574. (should (equal (org-export-number-to-roman -1) "-1"))
  575. ;; Otherwise, return it as a roman number.
  576. (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
  577. (ert-deftest test-org-export/get-tags ()
  578. "Test `org-export-get-tags' specifications."
  579. (let ((org-export-exclude-tags '("noexport"))
  580. (org-export-select-tags '("export")))
  581. ;; Standard test: tags which are not a select tag, an exclude tag,
  582. ;; or specified as optional argument shouldn't be ignored.
  583. (should
  584. (org-test-with-parsed-data "* Headline :tag:"
  585. (org-export-get-tags (org-element-map tree 'headline 'identity info t)
  586. info)))
  587. ;; Exclude tags are removed.
  588. (should-not
  589. (org-test-with-parsed-data "* Headline :noexport:"
  590. (org-export-get-tags (org-element-map tree 'headline 'identity info t)
  591. info)))
  592. ;; Select tags are removed.
  593. (should-not
  594. (org-test-with-parsed-data "* Headline :export:"
  595. (org-export-get-tags (org-element-map tree 'headline 'identity info t)
  596. info)))
  597. (should
  598. (equal
  599. '("tag")
  600. (org-test-with-parsed-data "* Headline :tag:export:"
  601. (org-export-get-tags (org-element-map tree 'headline 'identity info t)
  602. info))))
  603. ;; Tags provided in the optional argument are also ignored.
  604. (should-not
  605. (org-test-with-parsed-data "* Headline :ignore:"
  606. (org-export-get-tags (org-element-map tree 'headline 'identity info t)
  607. info '("ignore"))))))
  608. (ert-deftest test-org-export/first-sibling-p ()
  609. "Test `org-export-first-sibling-p' specifications."
  610. ;; Standard test.
  611. (should
  612. (equal
  613. '(yes yes no)
  614. (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
  615. (org-element-map
  616. tree 'headline
  617. (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
  618. info))))
  619. ;; Ignore headlines not exported.
  620. (should
  621. (equal
  622. '(yes)
  623. (let ((org-export-exclude-tags '("ignore")))
  624. (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
  625. (org-element-map
  626. tree 'headline
  627. (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
  628. info))))))
  629. (ert-deftest test-org-export/last-sibling-p ()
  630. "Test `org-export-last-sibling-p' specifications."
  631. ;; Standard test.
  632. (should
  633. (equal
  634. '(yes no yes)
  635. (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
  636. (org-element-map
  637. tree 'headline
  638. (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
  639. info))))
  640. ;; Ignore headlines not exported.
  641. (should
  642. (equal
  643. '(yes)
  644. (let ((org-export-exclude-tags '("ignore")))
  645. (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
  646. (org-element-map
  647. tree 'headline
  648. (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
  649. info))))))
  650. ;;; Links
  651. (ert-deftest test-org-export/get-coderef-format ()
  652. "Test `org-export-get-coderef-format' specifications."
  653. ;; A link without description returns "%s"
  654. (should (equal (org-export-get-coderef-format "(ref:line)" nil)
  655. "%s"))
  656. ;; Return "%s" when path is matched within description.
  657. (should (equal (org-export-get-coderef-format "path" "desc (path)")
  658. "desc %s"))
  659. ;; Otherwise return description.
  660. (should (equal (org-export-get-coderef-format "path" "desc")
  661. "desc")))
  662. (ert-deftest test-org-export/inline-image-p ()
  663. "Test `org-export-inline-image-p' specifications."
  664. (should
  665. (org-export-inline-image-p
  666. (org-test-with-temp-text "[[#id]]"
  667. (org-element-map
  668. (org-element-parse-buffer) 'link 'identity nil t))
  669. '(("custom-id" . "id")))))
  670. (ert-deftest test-org-export/fuzzy-link ()
  671. "Test fuzzy links specifications."
  672. ;; 1. Links to invisible (keyword) targets should be ignored.
  673. (org-test-with-parsed-data
  674. "Paragraph.\n#+TARGET: Test\n[[Test]]"
  675. (should-not
  676. (org-element-map
  677. tree 'link
  678. (lambda (link)
  679. (org-export-get-ordinal
  680. (org-export-resolve-fuzzy-link link info) info)) info)))
  681. ;; 2. Link to an headline should return headline's number.
  682. (org-test-with-parsed-data
  683. "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
  684. (should
  685. ;; Note: Headline's number is in fact a list of numbers.
  686. (equal '(2)
  687. (org-element-map
  688. tree 'link
  689. (lambda (link)
  690. (org-export-get-ordinal
  691. (org-export-resolve-fuzzy-link link info) info)) info t))))
  692. ;; 3. Link to a target in an item should return item's number.
  693. (org-test-with-parsed-data
  694. "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
  695. (should
  696. ;; Note: Item's number is in fact a list of numbers.
  697. (equal '(1 2)
  698. (org-element-map
  699. tree 'link
  700. (lambda (link)
  701. (org-export-get-ordinal
  702. (org-export-resolve-fuzzy-link link info) info)) info t))))
  703. ;; 4. Link to a target in a footnote should return footnote's
  704. ;; number.
  705. (org-test-with-parsed-data "
  706. Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
  707. (should
  708. (equal '(2 3)
  709. (org-element-map
  710. tree 'link
  711. (lambda (link)
  712. (org-export-get-ordinal
  713. (org-export-resolve-fuzzy-link link info) info)) info))))
  714. ;; 5. Link to a named element should return sequence number of that
  715. ;; element.
  716. (org-test-with-parsed-data
  717. "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
  718. (should
  719. (= 2
  720. (org-element-map
  721. tree 'link
  722. (lambda (link)
  723. (org-export-get-ordinal
  724. (org-export-resolve-fuzzy-link link info) info)) info t))))
  725. ;; 6. Link to a target not within an item, a table, a footnote
  726. ;; reference or definition should return section number.
  727. (org-test-with-parsed-data
  728. "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
  729. (should
  730. (equal '(2)
  731. (org-element-map
  732. tree 'link
  733. (lambda (link)
  734. (org-export-get-ordinal
  735. (org-export-resolve-fuzzy-link link info) info)) info t)))))
  736. (ert-deftest test-org-export/resolve-coderef ()
  737. "Test `org-export-resolve-coderef' specifications."
  738. (let ((org-coderef-label-format "(ref:%s)"))
  739. ;; 1. A link to a "-n -k -r" block returns line number.
  740. (org-test-with-parsed-data
  741. "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
  742. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  743. (org-test-with-parsed-data
  744. "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  745. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  746. ;; 2. A link to a "-n -r" block returns line number.
  747. (org-test-with-parsed-data
  748. "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
  749. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  750. (org-test-with-parsed-data
  751. "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  752. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  753. ;; 3. A link to a "-n" block returns coderef.
  754. (org-test-with-parsed-data
  755. "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  756. (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
  757. (org-test-with-parsed-data
  758. "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
  759. (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
  760. ;; 4. A link to a "-r" block returns line number.
  761. (org-test-with-parsed-data
  762. "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  763. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  764. (org-test-with-parsed-data
  765. "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
  766. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  767. ;; 5. A link to a block without a switch returns coderef.
  768. (org-test-with-parsed-data
  769. "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  770. (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
  771. (org-test-with-parsed-data
  772. "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
  773. (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
  774. ;; 6. Correctly handle continued line numbers. A "+n" switch
  775. ;; should resume numbering from previous block with numbered
  776. ;; lines, ignoring blocks not numbering lines in the process.
  777. ;; A "-n" switch resets count.
  778. (org-test-with-parsed-data "
  779. #+BEGIN_EXAMPLE -n
  780. Text.
  781. #+END_EXAMPLE
  782. #+BEGIN_SRC emacs-lisp
  783. \(- 1 1)
  784. #+END_SRC
  785. #+BEGIN_SRC emacs-lisp +n -r
  786. \(+ 1 1) (ref:addition)
  787. #+END_SRC
  788. #+BEGIN_EXAMPLE -n -r
  789. Another text. (ref:text)
  790. #+END_EXAMPLE"
  791. (should (= (org-export-resolve-coderef "addition" info) 2))
  792. (should (= (org-export-resolve-coderef "text" info) 1)))
  793. ;; 7. Recognize coderef with user-specified syntax.
  794. (org-test-with-parsed-data
  795. "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
  796. (should (equal (org-export-resolve-coderef "text" info) "text")))))
  797. (ert-deftest test-org-export/resolve-fuzzy-link ()
  798. "Test `org-export-resolve-fuzzy-link' specifications."
  799. ;; 1. Match target objects.
  800. (org-test-with-parsed-data "<<target>> [[target]]"
  801. (should
  802. (org-export-resolve-fuzzy-link
  803. (org-element-map tree 'link 'identity info t) info)))
  804. ;; 2. Match target elements.
  805. (org-test-with-parsed-data "#+TARGET: target\n[[target]]"
  806. (should
  807. (org-export-resolve-fuzzy-link
  808. (org-element-map tree 'link 'identity info t) info)))
  809. ;; 3. Match named elements.
  810. (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
  811. (should
  812. (org-export-resolve-fuzzy-link
  813. (org-element-map tree 'link 'identity info t) info)))
  814. ;; 4. Match exact headline's name.
  815. (org-test-with-parsed-data "* My headline\n[[My headline]]"
  816. (should
  817. (org-export-resolve-fuzzy-link
  818. (org-element-map tree 'link 'identity info t) info)))
  819. ;; 5. Targets objects have priority over named elements and headline
  820. ;; titles.
  821. (org-test-with-parsed-data
  822. "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
  823. (should
  824. (eq 'target
  825. (org-element-type
  826. (org-export-resolve-fuzzy-link
  827. (org-element-map tree 'link 'identity info t) info)))))
  828. ;; 6. Named elements have priority over headline titles.
  829. (org-test-with-parsed-data
  830. "* target\n#+NAME: target\nParagraph\n\n[[target]]"
  831. (should
  832. (eq 'paragraph
  833. (org-element-type
  834. (org-export-resolve-fuzzy-link
  835. (org-element-map tree 'link 'identity info t) info)))))
  836. ;; 7. If link's path starts with a "*", only match headline titles,
  837. ;; though.
  838. (org-test-with-parsed-data
  839. "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
  840. (should
  841. (eq 'headline
  842. (org-element-type
  843. (org-export-resolve-fuzzy-link
  844. (org-element-map tree 'link 'identity info t) info)))))
  845. ;; 8. Return nil if no match.
  846. (org-test-with-parsed-data "[[target]]"
  847. (should-not
  848. (org-export-resolve-fuzzy-link
  849. (org-element-map tree 'link 'identity info t) info))))
  850. (ert-deftest test-org-export/resolve-id-link ()
  851. "Test `org-export-resolve-id-link' specifications."
  852. ;; 1. Regular test for custom-id link.
  853. (org-test-with-parsed-data "* Headline1
  854. :PROPERTIES:
  855. :CUSTOM-ID: test
  856. :END:
  857. * Headline 2
  858. \[[#test]]"
  859. (should
  860. (org-export-resolve-id-link
  861. (org-element-map tree 'link 'identity info t) info)))
  862. ;; 2. Failing test for custom-id link.
  863. (org-test-with-parsed-data "* Headline1
  864. :PROPERTIES:
  865. :CUSTOM-ID: test
  866. :END:
  867. * Headline 2
  868. \[[#no-match]]"
  869. (should-not
  870. (org-export-resolve-id-link
  871. (org-element-map tree 'link 'identity info t) info)))
  872. ;; 3. Test for internal id target.
  873. (org-test-with-parsed-data "* Headline1
  874. :PROPERTIES:
  875. :ID: aaaa
  876. :END:
  877. * Headline 2
  878. \[[id:aaaa]]"
  879. (should
  880. (org-export-resolve-id-link
  881. (org-element-map tree 'link 'identity info t) info)))
  882. ;; 4. Test for external id target.
  883. (org-test-with-parsed-data "[[id:aaaa]]"
  884. (should
  885. (org-export-resolve-id-link
  886. (org-element-map tree 'link 'identity info t)
  887. (org-combine-plists info '(:id-alist (("aaaa" . "external-file"))))))))
  888. (ert-deftest test-org-export/resolve-radio-link ()
  889. "Test `org-export-resolve-radio-link' specifications."
  890. ;; Standard test.
  891. (org-test-with-temp-text "<<<radio>>> radio"
  892. (org-update-radio-target-regexp)
  893. (should
  894. (let* ((tree (org-element-parse-buffer))
  895. (info `(:parse-tree ,tree)))
  896. (org-export-resolve-radio-link
  897. (org-element-map tree 'link 'identity info t)
  898. info))))
  899. ;; Radio target with objects.
  900. (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
  901. (org-update-radio-target-regexp)
  902. (should
  903. (let* ((tree (org-element-parse-buffer))
  904. (info `(:parse-tree ,tree)))
  905. (org-export-resolve-radio-link
  906. (org-element-map tree 'link 'identity info t)
  907. info)))))
  908. ;;; Macro
  909. (ert-deftest test-org-export/define-macro ()
  910. "Try defining various Org macro using in-buffer #+MACRO: keyword."
  911. ;; Parsed macro.
  912. (should (equal (org-test-with-temp-text "#+MACRO: one 1"
  913. (org-export--get-inbuffer-options))
  914. '(:macro-one ("1"))))
  915. ;; Evaled macro.
  916. (should (equal (org-test-with-temp-text "#+MACRO: two (eval (+ 1 1))"
  917. (org-export--get-inbuffer-options))
  918. '(:macro-two ("(eval (+ 1 1))"))))
  919. ;; Incomplete macro.
  920. (should-not (org-test-with-temp-text "#+MACRO: three"
  921. (org-export--get-inbuffer-options)))
  922. ;; Macro with newline character.
  923. (should (equal (org-test-with-temp-text "#+MACRO: four a\\nb"
  924. (org-export--get-inbuffer-options))
  925. '(:macro-four ("a\nb"))))
  926. ;; Macro with protected newline character.
  927. (should (equal (org-test-with-temp-text "#+MACRO: five a\\\\nb"
  928. (org-export--get-inbuffer-options))
  929. '(:macro-five ("a\\nb"))))
  930. ;; Recursive macro.
  931. (org-test-with-temp-text "#+MACRO: six 6\n#+MACRO: seven 1 + {{{six}}}"
  932. (should
  933. (equal
  934. (org-export--get-inbuffer-options)
  935. '(:macro-six
  936. ("6")
  937. :macro-seven
  938. ("1 + " (macro (:key "six" :value "{{{six}}}" :args nil :begin 5 :end 14
  939. :post-blank 0 :parent nil))))))))
  940. (ert-deftest test-org-export/expand-macro ()
  941. "Test `org-export-expand-macro' specifications."
  942. ;; Standard test.
  943. (should
  944. (equal
  945. "some text"
  946. (org-test-with-parsed-data "#+MACRO: macro some text\n{{{macro}}}"
  947. (org-export-expand-macro
  948. (org-element-map tree 'macro 'identity info t) info))))
  949. ;; Macro with arguments.
  950. (should
  951. (equal
  952. "some text"
  953. (org-test-with-parsed-data "#+MACRO: macro $1 $2\n{{{macro(some,text)}}}"
  954. (org-export-expand-macro
  955. (org-element-map tree 'macro 'identity info t) info))))
  956. ;; Macro with "eval"
  957. (should
  958. (equal
  959. "3"
  960. (org-test-with-parsed-data "#+MACRO: add (eval (+ $1 $2))\n{{{add(1,2)}}}"
  961. (org-export-expand-macro
  962. (org-element-map tree 'macro 'identity info t) info))))
  963. ;; Nested macros.
  964. (should
  965. (equal
  966. "inner outer"
  967. (org-test-with-parsed-data
  968. "#+MACRO: in inner\n#+MACRO: out {{{in}}} outer\n{{{out}}}"
  969. (flet ((translate-macro (macro contents info)
  970. (org-export-expand-macro macro info)))
  971. (org-export-expand-macro
  972. (org-element-map tree 'macro 'identity info t)
  973. (org-combine-plists
  974. info `(:translate-alist ((macro . translate-macro))))))))))
  975. ;;; Src-block and example-block
  976. (ert-deftest test-org-export/unravel-code ()
  977. "Test `org-export-unravel-code' function."
  978. (let ((org-coderef-label-format "(ref:%s)"))
  979. ;; 1. Code without reference.
  980. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
  981. (should (equal (org-export-unravel-code (org-element-at-point))
  982. '("(+ 1 1)\n"))))
  983. ;; 2. Code with reference.
  984. (org-test-with-temp-text
  985. "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
  986. (should (equal (org-export-unravel-code (org-element-at-point))
  987. '("(+ 1 1)\n" (1 . "test")))))
  988. ;; 3. Code with user-defined reference.
  989. (org-test-with-temp-text
  990. "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
  991. (should (equal (org-export-unravel-code (org-element-at-point))
  992. '("(+ 1 1)\n" (1 . "test")))))
  993. ;; 4. Code references keys are relative to the current block.
  994. (org-test-with-temp-text "
  995. #+BEGIN_EXAMPLE -n
  996. \(+ 1 1)
  997. #+END_EXAMPLE
  998. #+BEGIN_EXAMPLE +n
  999. \(+ 2 2)
  1000. \(+ 3 3) (ref:one)
  1001. #+END_EXAMPLE"
  1002. (goto-line 5)
  1003. (should (equal (org-export-unravel-code (org-element-at-point))
  1004. '("(+ 2 2)\n(+ 3 3)\n" (2 . "one")))))))
  1005. ;;; Tables
  1006. (ert-deftest test-org-export/special-column ()
  1007. "Test if the table's special column is properly recognized."
  1008. ;; 1. First column is special if it contains only a special marking
  1009. ;; characters or empty cells.
  1010. (org-test-with-temp-text "
  1011. | ! | 1 |
  1012. | | 2 |"
  1013. (should
  1014. (org-export-table-has-special-column-p
  1015. (org-element-map
  1016. (org-element-parse-buffer) 'table 'identity nil 'first-match))))
  1017. ;; 2. If the column contains anything else, it isn't special.
  1018. (org-test-with-temp-text "
  1019. | ! | 1 |
  1020. | b | 2 |"
  1021. (should-not
  1022. (org-export-table-has-special-column-p
  1023. (org-element-map
  1024. (org-element-parse-buffer) 'table 'identity nil 'first-match))))
  1025. ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
  1026. ;; and "!".
  1027. (org-test-with-temp-text "
  1028. | # | 1 |
  1029. | ^ | 2 |
  1030. | * | 3 |
  1031. | _ | 4 |
  1032. | / | 5 |
  1033. | $ | 6 |
  1034. | ! | 7 |"
  1035. (should
  1036. (org-export-table-has-special-column-p
  1037. (org-element-map
  1038. (org-element-parse-buffer) 'table 'identity nil 'first-match))))
  1039. ;; 4. A first column with only empty cells isn't considered as
  1040. ;; special.
  1041. (org-test-with-temp-text "
  1042. | | 1 |
  1043. | | 2 |"
  1044. (should-not
  1045. (org-export-table-has-special-column-p
  1046. (org-element-map
  1047. (org-element-parse-buffer) 'table 'identity nil 'first-match)))))
  1048. (ert-deftest test-org-export/table-row-is-special-p ()
  1049. "Test `org-export-table-row-is-special-p' specifications."
  1050. ;; 1. A row is special if it has a special marking character in the
  1051. ;; special column.
  1052. (org-test-with-parsed-data "| ! | 1 |"
  1053. (should
  1054. (org-export-table-row-is-special-p
  1055. (org-element-map tree 'table-row 'identity nil 'first-match) info)))
  1056. ;; 2. A row is special when its first field is "/"
  1057. (org-test-with-parsed-data "
  1058. | / | 1 |
  1059. | a | b |"
  1060. (should
  1061. (org-export-table-row-is-special-p
  1062. (org-element-map tree 'table-row 'identity nil 'first-match) info)))
  1063. ;; 3. A row only containing alignment cookies is also considered as
  1064. ;; special.
  1065. (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
  1066. (should
  1067. (org-export-table-row-is-special-p
  1068. (org-element-map tree 'table-row 'identity nil 'first-match) info)))
  1069. ;; 4. Everything else isn't considered as special.
  1070. (org-test-with-parsed-data "| \alpha | | c |"
  1071. (should-not
  1072. (org-export-table-row-is-special-p
  1073. (org-element-map tree 'table-row 'identity nil 'first-match) info)))
  1074. ;; 5. Table's rules are never considered as special rows.
  1075. (org-test-with-parsed-data "|---+---|"
  1076. (should-not
  1077. (org-export-table-row-is-special-p
  1078. (org-element-map tree 'table-row 'identity nil 'first-match) info))))
  1079. (ert-deftest test-org-export/has-header-p ()
  1080. "Test `org-export-table-has-header-p' specifications."
  1081. ;; 1. With an header.
  1082. (org-test-with-parsed-data "
  1083. | a | b |
  1084. |---+---|
  1085. | c | d |"
  1086. (should
  1087. (org-export-table-has-header-p
  1088. (org-element-map tree 'table 'identity info 'first-match)
  1089. info)))
  1090. ;; 2. Without an header.
  1091. (org-test-with-parsed-data "
  1092. | a | b |
  1093. | c | d |"
  1094. (should-not
  1095. (org-export-table-has-header-p
  1096. (org-element-map tree 'table 'identity info 'first-match)
  1097. info)))
  1098. ;; 3. Don't get fooled with starting and ending rules.
  1099. (org-test-with-parsed-data "
  1100. |---+---|
  1101. | a | b |
  1102. | c | d |
  1103. |---+---|"
  1104. (should-not
  1105. (org-export-table-has-header-p
  1106. (org-element-map tree 'table 'identity info 'first-match)
  1107. info))))
  1108. (ert-deftest test-org-export/table-row-group ()
  1109. "Test `org-export-table-row-group' specifications."
  1110. ;; 1. A rule creates a new group.
  1111. (org-test-with-parsed-data "
  1112. | a | b |
  1113. |---+---|
  1114. | 1 | 2 |"
  1115. (should
  1116. (equal
  1117. '(1 nil 2)
  1118. (mapcar (lambda (row) (org-export-table-row-group row info))
  1119. (org-element-map tree 'table-row 'identity)))))
  1120. ;; 2. Special rows are ignored in count.
  1121. (org-test-with-parsed-data "
  1122. | / | < | > |
  1123. |---|---+---|
  1124. | | 1 | 2 |"
  1125. (should
  1126. (equal
  1127. '(nil nil 1)
  1128. (mapcar (lambda (row) (org-export-table-row-group row info))
  1129. (org-element-map tree 'table-row 'identity)))))
  1130. ;; 3. Double rules also are ignored in count.
  1131. (org-test-with-parsed-data "
  1132. | a | b |
  1133. |---+---|
  1134. |---+---|
  1135. | 1 | 2 |"
  1136. (should
  1137. (equal
  1138. '(1 nil nil 2)
  1139. (mapcar (lambda (row) (org-export-table-row-group row info))
  1140. (org-element-map tree 'table-row 'identity))))))
  1141. (ert-deftest test-org-export/table-cell-width ()
  1142. "Test `org-export-table-cell-width' specifications."
  1143. ;; 1. Width is primarily determined by width cookies. If no cookie
  1144. ;; is found, cell's width is nil.
  1145. (org-test-with-parsed-data "
  1146. | / | <l> | <6> | <l7> |
  1147. | | a | b | c |"
  1148. (should
  1149. (equal
  1150. '(nil 6 7)
  1151. (mapcar (lambda (cell) (org-export-table-cell-width cell info))
  1152. (org-element-map tree 'table-cell 'identity info)))))
  1153. ;; 2. The last width cookie has precedence.
  1154. (org-test-with-parsed-data "
  1155. | <6> |
  1156. | <7> |
  1157. | a |"
  1158. (should
  1159. (equal
  1160. '(7)
  1161. (mapcar (lambda (cell) (org-export-table-cell-width cell info))
  1162. (org-element-map tree 'table-cell 'identity info)))))
  1163. ;; 3. Valid width cookies must have a specific row.
  1164. (org-test-with-parsed-data "| <6> | cell |"
  1165. (should
  1166. (equal
  1167. '(nil nil)
  1168. (mapcar (lambda (cell) (org-export-table-cell-width cell info))
  1169. (org-element-map tree 'table-cell 'identity))))))
  1170. (ert-deftest test-org-export/table-cell-alignment ()
  1171. "Test `org-export-table-cell-alignment' specifications."
  1172. (let ((org-table-number-fraction 0.5)
  1173. (org-table-number-regexp "^[0-9]+$"))
  1174. ;; 1. Alignment is primarily determined by alignment cookies.
  1175. (org-test-with-temp-text "| <l> | <c> | <r> |"
  1176. (let* ((tree (org-element-parse-buffer))
  1177. (info `(:parse-tree ,tree)))
  1178. (should
  1179. (equal
  1180. '(left center right)
  1181. (mapcar (lambda (cell) (org-export-table-cell-alignment cell info))
  1182. (org-element-map tree 'table-cell 'identity))))))
  1183. ;; 2. The last alignment cookie has precedence.
  1184. (org-test-with-parsed-data "
  1185. | <l8> |
  1186. | cell |
  1187. | <r9> |"
  1188. (should
  1189. (equal
  1190. '(right right right)
  1191. (mapcar (lambda (cell) (org-export-table-cell-alignment cell info))
  1192. (org-element-map tree 'table-cell 'identity)))))
  1193. ;; 3. If there's no cookie, cell's contents determine alignment.
  1194. ;; A column mostly made of cells containing numbers will align
  1195. ;; its cells to the right.
  1196. (org-test-with-parsed-data "
  1197. | 123 |
  1198. | some text |
  1199. | 12345 |"
  1200. (should
  1201. (equal
  1202. '(right right right)
  1203. (mapcar (lambda (cell)
  1204. (org-export-table-cell-alignment cell info))
  1205. (org-element-map tree 'table-cell 'identity)))))
  1206. ;; 4. Otherwise, they will be aligned to the left.
  1207. (org-test-with-parsed-data "
  1208. | text |
  1209. | some text |
  1210. | \alpha |"
  1211. (should
  1212. (equal
  1213. '(left left left)
  1214. (mapcar (lambda (cell)
  1215. (org-export-table-cell-alignment cell info))
  1216. (org-element-map tree 'table-cell 'identity)))))))
  1217. (ert-deftest test-org-export/table-cell-borders ()
  1218. "Test `org-export-table-cell-borders' specifications."
  1219. ;; 1. Recognize various column groups indicators.
  1220. (org-test-with-parsed-data "| / | < | > | <> |"
  1221. (should
  1222. (equal
  1223. '((right bottom top) (left bottom top) (right bottom top)
  1224. (right left bottom top))
  1225. (mapcar (lambda (cell)
  1226. (org-export-table-cell-borders cell info))
  1227. (org-element-map tree 'table-cell 'identity)))))
  1228. ;; 2. Accept shortcuts to define column groups.
  1229. (org-test-with-parsed-data "| / | < | < |"
  1230. (should
  1231. (equal
  1232. '((right bottom top) (right left bottom top) (left bottom top))
  1233. (mapcar (lambda (cell)
  1234. (org-export-table-cell-borders cell info))
  1235. (org-element-map tree 'table-cell 'identity)))))
  1236. ;; 3. A valid column groups row must start with a "/".
  1237. (org-test-with-parsed-data "
  1238. | | < |
  1239. | a | b |"
  1240. (should
  1241. (equal '((top) (top) (bottom) (bottom))
  1242. (mapcar (lambda (cell)
  1243. (org-export-table-cell-borders cell info))
  1244. (org-element-map tree 'table-cell 'identity)))))
  1245. ;; 4. Take table rules into consideration.
  1246. (org-test-with-parsed-data "
  1247. | 1 |
  1248. |---|
  1249. | 2 |"
  1250. (should
  1251. (equal '((below top) (bottom above))
  1252. (mapcar (lambda (cell)
  1253. (org-export-table-cell-borders cell info))
  1254. (org-element-map tree 'table-cell 'identity)))))
  1255. ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
  1256. ;; (resp. `bottom' and `below') borders. Any special row is
  1257. ;; ignored.
  1258. (org-test-with-parsed-data "
  1259. |---+----|
  1260. | / | |
  1261. | | 1 |
  1262. |---+----|"
  1263. (should
  1264. (equal '((bottom below top above))
  1265. (last
  1266. (mapcar (lambda (cell)
  1267. (org-export-table-cell-borders cell info))
  1268. (org-element-map tree 'table-cell 'identity)))))))
  1269. (ert-deftest test-org-export/table-dimensions ()
  1270. "Test `org-export-table-dimensions' specifications."
  1271. ;; 1. Standard test.
  1272. (org-test-with-parsed-data "
  1273. | 1 | 2 | 3 |
  1274. | 4 | 5 | 6 |"
  1275. (should
  1276. (equal '(2 . 3)
  1277. (org-export-table-dimensions
  1278. (org-element-map tree 'table 'identity info 'first-match) info))))
  1279. ;; 2. Ignore horizontal rules and special columns.
  1280. (org-test-with-parsed-data "
  1281. | / | < | > |
  1282. | 1 | 2 | 3 |
  1283. |---+---+---|
  1284. | 4 | 5 | 6 |"
  1285. (should
  1286. (equal '(2 . 3)
  1287. (org-export-table-dimensions
  1288. (org-element-map tree 'table 'identity info 'first-match) info)))))
  1289. (ert-deftest test-org-export/table-cell-address ()
  1290. "Test `org-export-table-cell-address' specifications."
  1291. ;; 1. Standard test: index is 0-based.
  1292. (org-test-with-parsed-data "| a | b |"
  1293. (should
  1294. (equal '((0 . 0) (0 . 1))
  1295. (org-element-map
  1296. tree 'table-cell
  1297. (lambda (cell) (org-export-table-cell-address cell info))
  1298. info))))
  1299. ;; 2. Special column isn't counted, nor are special rows.
  1300. (org-test-with-parsed-data "
  1301. | / | <> |
  1302. | | c |"
  1303. (should
  1304. (equal '(0 . 0)
  1305. (org-export-table-cell-address
  1306. (car (last (org-element-map tree 'table-cell 'identity info)))
  1307. info))))
  1308. ;; 3. Tables rules do not count either.
  1309. (org-test-with-parsed-data "
  1310. | a |
  1311. |---|
  1312. | b |
  1313. |---|
  1314. | c |"
  1315. (should
  1316. (equal '(2 . 0)
  1317. (org-export-table-cell-address
  1318. (car (last (org-element-map tree 'table-cell 'identity info)))
  1319. info))))
  1320. ;; 4. Return nil for special cells.
  1321. (org-test-with-parsed-data "| / | a |"
  1322. (should-not
  1323. (org-export-table-cell-address
  1324. (org-element-map tree 'table-cell 'identity nil 'first-match)
  1325. info))))
  1326. (ert-deftest test-org-export/get-table-cell-at ()
  1327. "Test `org-export-get-table-cell-at' specifications."
  1328. ;; 1. Address ignores special columns, special rows and rules.
  1329. (org-test-with-parsed-data "
  1330. | / | <> |
  1331. | | a |
  1332. |---+----|
  1333. | | b |"
  1334. (should
  1335. (equal '("b")
  1336. (org-element-contents
  1337. (org-export-get-table-cell-at
  1338. '(1 . 0)
  1339. (org-element-map tree 'table 'identity info 'first-match)
  1340. info)))))
  1341. ;; 2. Return value for a non-existent address is nil.
  1342. (org-test-with-parsed-data "| a |"
  1343. (should-not
  1344. (org-export-get-table-cell-at
  1345. '(2 . 2)
  1346. (org-element-map tree 'table 'identity info 'first-match)
  1347. info)))
  1348. (org-test-with-parsed-data "| / |"
  1349. (should-not
  1350. (org-export-get-table-cell-at
  1351. '(0 . 0)
  1352. (org-element-map tree 'table 'identity info 'first-match)
  1353. info))))
  1354. (ert-deftest test-org-export/table-cell-starts-colgroup-p ()
  1355. "Test `org-export-table-cell-starts-colgroup-p' specifications."
  1356. ;; 1. A cell at a beginning of a row always starts a column group.
  1357. (org-test-with-parsed-data "| a |"
  1358. (should
  1359. (org-export-table-cell-starts-colgroup-p
  1360. (org-element-map tree 'table-cell 'identity info 'first-match)
  1361. info)))
  1362. ;; 2. Special column should be ignored when determining the
  1363. ;; beginning of the row.
  1364. (org-test-with-parsed-data "
  1365. | / | |
  1366. | | a |"
  1367. (should
  1368. (org-export-table-cell-starts-colgroup-p
  1369. (org-element-map tree 'table-cell 'identity info 'first-match)
  1370. info)))
  1371. ;; 2. Explicit column groups.
  1372. (org-test-with-parsed-data "
  1373. | / | | < |
  1374. | a | b | c |"
  1375. (should
  1376. (equal
  1377. '(yes no yes)
  1378. (org-element-map
  1379. tree 'table-cell
  1380. (lambda (cell)
  1381. (if (org-export-table-cell-starts-colgroup-p cell info) 'yes 'no))
  1382. info)))))
  1383. (ert-deftest test-org-export/table-cell-ends-colgroup-p ()
  1384. "Test `org-export-table-cell-ends-colgroup-p' specifications."
  1385. ;; 1. A cell at the end of a row always ends a column group.
  1386. (org-test-with-parsed-data "| a |"
  1387. (should
  1388. (org-export-table-cell-ends-colgroup-p
  1389. (org-element-map tree 'table-cell 'identity info 'first-match)
  1390. info)))
  1391. ;; 2. Special column should be ignored when determining the
  1392. ;; beginning of the row.
  1393. (org-test-with-parsed-data "
  1394. | / | |
  1395. | | a |"
  1396. (should
  1397. (org-export-table-cell-ends-colgroup-p
  1398. (org-element-map tree 'table-cell 'identity info 'first-match)
  1399. info)))
  1400. ;; 3. Explicit column groups.
  1401. (org-test-with-parsed-data "
  1402. | / | < | |
  1403. | a | b | c |"
  1404. (should
  1405. (equal
  1406. '(yes no yes)
  1407. (org-element-map
  1408. tree 'table-cell
  1409. (lambda (cell)
  1410. (if (org-export-table-cell-ends-colgroup-p cell info) 'yes 'no))
  1411. info)))))
  1412. (ert-deftest test-org-export/table-row-starts-rowgroup-p ()
  1413. "Test `org-export-table-row-starts-rowgroup-p' specifications."
  1414. ;; 1. A row at the beginning of a table always starts a row group.
  1415. ;; So does a row following a table rule.
  1416. (org-test-with-parsed-data "
  1417. | a |
  1418. |---|
  1419. | b |"
  1420. (should
  1421. (equal
  1422. '(yes no yes)
  1423. (org-element-map
  1424. tree 'table-row
  1425. (lambda (row)
  1426. (if (org-export-table-row-starts-rowgroup-p row info) 'yes 'no))
  1427. info))))
  1428. ;; 2. Special rows should be ignored when determining the beginning
  1429. ;; of the row.
  1430. (org-test-with-parsed-data "
  1431. | / | < |
  1432. | | a |
  1433. |---+---|
  1434. | / | < |
  1435. | | b |"
  1436. (should
  1437. (equal
  1438. '(yes no yes)
  1439. (org-element-map
  1440. tree 'table-row
  1441. (lambda (row)
  1442. (if (org-export-table-row-starts-rowgroup-p row info) 'yes 'no))
  1443. info)))))
  1444. (ert-deftest test-org-export/table-row-ends-rowgroup-p ()
  1445. "Test `org-export-table-row-ends-rowgroup-p' specifications."
  1446. ;; 1. A row at the end of a table always ends a row group. So does
  1447. ;; a row preceding a table rule.
  1448. (org-test-with-parsed-data "
  1449. | a |
  1450. |---|
  1451. | b |"
  1452. (should
  1453. (equal
  1454. '(yes no yes)
  1455. (org-element-map
  1456. tree 'table-row
  1457. (lambda (row)
  1458. (if (org-export-table-row-ends-rowgroup-p row info) 'yes 'no))
  1459. info))))
  1460. ;; 2. Special rows should be ignored when determining the beginning
  1461. ;; of the row.
  1462. (org-test-with-parsed-data "
  1463. | | a |
  1464. | / | < |
  1465. |---+---|
  1466. | | b |
  1467. | / | < |"
  1468. (should
  1469. (equal
  1470. '(yes no yes)
  1471. (org-element-map
  1472. tree 'table-row
  1473. (lambda (row)
  1474. (if (org-export-table-row-ends-rowgroup-p row info) 'yes 'no))
  1475. info)))))
  1476. (ert-deftest test-org-export/table-row-starts-header-p ()
  1477. "Test `org-export-table-row-starts-header-p' specifications."
  1478. ;; 1. Only the row starting the first row group starts the table
  1479. ;; header.
  1480. (org-test-with-parsed-data "
  1481. | a |
  1482. | b |
  1483. |---|
  1484. | c |"
  1485. (should
  1486. (equal
  1487. '(yes no no no)
  1488. (org-element-map
  1489. tree 'table-row
  1490. (lambda (row)
  1491. (if (org-export-table-row-starts-header-p row info) 'yes 'no))
  1492. info))))
  1493. ;; 2. A row cannot start an header if there's no header in the
  1494. ;; table.
  1495. (org-test-with-parsed-data "
  1496. | a |
  1497. |---|"
  1498. (should-not
  1499. (org-export-table-row-starts-header-p
  1500. (org-element-map tree 'table-row 'identity info 'first-match)
  1501. info))))
  1502. (ert-deftest test-org-export/table-row-ends-header-p ()
  1503. "Test `org-export-table-row-ends-header-p' specifications."
  1504. ;; 1. Only the row starting the first row group starts the table
  1505. ;; header.
  1506. (org-test-with-parsed-data "
  1507. | a |
  1508. | b |
  1509. |---|
  1510. | c |"
  1511. (should
  1512. (equal
  1513. '(no yes no no)
  1514. (org-element-map
  1515. tree 'table-row
  1516. (lambda (row)
  1517. (if (org-export-table-row-ends-header-p row info) 'yes 'no))
  1518. info))))
  1519. ;; 2. A row cannot start an header if there's no header in the
  1520. ;; table.
  1521. (org-test-with-parsed-data "
  1522. | a |
  1523. |---|"
  1524. (should-not
  1525. (org-export-table-row-ends-header-p
  1526. (org-element-map tree 'table-row 'identity info 'first-match)
  1527. info))))
  1528. ;;; Topology
  1529. (ert-deftest test-org-export/get-next-element ()
  1530. "Test `org-export-get-next-element' specifications."
  1531. ;; Standard test.
  1532. (should
  1533. (equal "b"
  1534. (org-test-with-parsed-data "* Headline\n*a* b"
  1535. (org-export-get-next-element
  1536. (org-element-map tree 'bold 'identity info t) info))))
  1537. ;; Return nil when no previous element.
  1538. (should-not
  1539. (org-test-with-parsed-data "* Headline\na *b*"
  1540. (org-export-get-next-element
  1541. (org-element-map tree 'bold 'identity info t) info)))
  1542. ;; Non-exportable elements are ignored.
  1543. (should-not
  1544. (let ((org-export-with-timestamps nil))
  1545. (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
  1546. (org-export-get-next-element
  1547. (org-element-map tree 'entity 'identity info t) info)))))
  1548. (ert-deftest test-org-export/get-previous-element ()
  1549. "Test `org-export-get-previous-element' specifications."
  1550. ;; Standard test.
  1551. (should
  1552. (equal "a "
  1553. (org-test-with-parsed-data "* Headline\na *b*"
  1554. (org-export-get-previous-element
  1555. (org-element-map tree 'bold 'identity info t) info))))
  1556. ;; Return nil when no previous element.
  1557. (should-not
  1558. (org-test-with-parsed-data "* Headline\n*a* b"
  1559. (org-export-get-previous-element
  1560. (org-element-map tree 'bold 'identity info t) info)))
  1561. ;; Non-exportable elements are ignored.
  1562. (should-not
  1563. (let ((org-export-with-timestamps nil))
  1564. (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
  1565. (org-export-get-previous-element
  1566. (org-element-map tree 'entity 'identity info t) info)))))
  1567. (provide 'test-org-export)
  1568. ;;; test-org-export.el end here