test-org-export.el 71 KB

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