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