test-ox.el 72 KB

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