test-org-export.el 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216
  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. ;; 6. Footnotes without a definition should be provided a fallback
  800. ;; definition.
  801. (should
  802. (org-test-with-parsed-data "[fn:1]"
  803. (org-export-get-footnote-definition
  804. (org-element-map tree 'footnote-reference 'identity info t) info)))))
  805. ;;; Headlines and Inlinetasks
  806. (ert-deftest test-org-export/get-relative-level ()
  807. "Test `org-export-get-relative-level' specifications."
  808. ;; Standard test.
  809. (should
  810. (equal '(1 2)
  811. (let ((org-odd-levels-only nil))
  812. (org-test-with-parsed-data "* Headline 1\n** Headline 2"
  813. (org-element-map
  814. tree 'headline
  815. (lambda (h) (org-export-get-relative-level h info))
  816. info)))))
  817. ;; Missing levels
  818. (should
  819. (equal '(1 3)
  820. (let ((org-odd-levels-only nil))
  821. (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
  822. (org-element-map
  823. tree 'headline
  824. (lambda (h) (org-export-get-relative-level h info))
  825. info))))))
  826. (ert-deftest test-org-export/low-level-p ()
  827. "Test `org-export-low-level-p' specifications."
  828. (should
  829. (equal
  830. '(no yes)
  831. (let ((org-odd-levels-only nil))
  832. (org-test-with-parsed-data "* Headline 1\n** Headline 2"
  833. (org-element-map
  834. tree 'headline
  835. (lambda (h) (if (org-export-low-level-p h info) 'yes 'no))
  836. (plist-put info :headline-levels 1)))))))
  837. (ert-deftest test-org-export/get-headline-number ()
  838. "Test `org-export-get-headline-number' specifications."
  839. ;; Standard test.
  840. (should
  841. (equal
  842. '((1) (1 1))
  843. (let ((org-odd-levels-only nil))
  844. (org-test-with-parsed-data "* Headline 1\n** Headline 2"
  845. (org-element-map
  846. tree 'headline
  847. (lambda (h) (org-export-get-headline-number h info))
  848. info)))))
  849. ;; Missing levels are replaced with 0.
  850. (should
  851. (equal
  852. '((1) (1 0 1))
  853. (let ((org-odd-levels-only nil))
  854. (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
  855. (org-element-map
  856. tree 'headline
  857. (lambda (h) (org-export-get-headline-number h info))
  858. info))))))
  859. (ert-deftest test-org-export/numbered-headline-p ()
  860. "Test `org-export-numbered-headline-p' specifications."
  861. ;; If `:section-numbers' is nil, never number headlines.
  862. (should-not
  863. (org-test-with-parsed-data "* Headline"
  864. (org-element-map
  865. tree 'headline
  866. (lambda (h) (org-export-numbered-headline-p h info))
  867. (plist-put info :section-numbers nil))))
  868. ;; If `:section-numbers' is a number, only number headlines with
  869. ;; a level greater that it.
  870. (should
  871. (equal
  872. '(yes no)
  873. (org-test-with-parsed-data "* Headline 1\n** Headline 2"
  874. (org-element-map
  875. tree 'headline
  876. (lambda (h) (if (org-export-numbered-headline-p h info) 'yes 'no))
  877. (plist-put info :section-numbers 1)))))
  878. ;; Otherwise, headlines are always numbered.
  879. (should
  880. (org-test-with-parsed-data "* Headline"
  881. (org-element-map
  882. tree 'headline
  883. (lambda (h) (org-export-numbered-headline-p h info))
  884. (plist-put info :section-numbers t)))))
  885. (ert-deftest test-org-export/number-to-roman ()
  886. "Test `org-export-number-to-roman' specifications."
  887. ;; If number is negative, return it as a string.
  888. (should (equal (org-export-number-to-roman -1) "-1"))
  889. ;; Otherwise, return it as a roman number.
  890. (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
  891. (ert-deftest test-org-export/get-tags ()
  892. "Test `org-export-get-tags' specifications."
  893. (let ((org-export-exclude-tags '("noexport"))
  894. (org-export-select-tags '("export")))
  895. ;; Standard test: tags which are not a select tag, an exclude tag,
  896. ;; or specified as optional argument shouldn't be ignored.
  897. (should
  898. (org-test-with-parsed-data "* Headline :tag:"
  899. (org-export-get-tags (org-element-map tree 'headline 'identity info t)
  900. info)))
  901. ;; Exclude tags are removed.
  902. (should-not
  903. (org-test-with-parsed-data "* Headline :noexport:"
  904. (org-export-get-tags (org-element-map tree 'headline 'identity info t)
  905. info)))
  906. ;; Select tags are removed.
  907. (should-not
  908. (org-test-with-parsed-data "* Headline :export:"
  909. (org-export-get-tags (org-element-map tree 'headline 'identity info t)
  910. info)))
  911. (should
  912. (equal
  913. '("tag")
  914. (org-test-with-parsed-data "* Headline :tag:export:"
  915. (org-export-get-tags (org-element-map tree 'headline 'identity info t)
  916. info))))
  917. ;; Tags provided in the optional argument are also ignored.
  918. (should-not
  919. (org-test-with-parsed-data "* Headline :ignore:"
  920. (org-export-get-tags (org-element-map tree 'headline 'identity info t)
  921. info '("ignore"))))
  922. ;; Allow tag inheritance.
  923. (should
  924. (equal
  925. '(("tag") ("tag"))
  926. (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
  927. (org-element-map
  928. tree 'headline
  929. (lambda (hl) (org-export-get-tags hl info nil t)) info))))
  930. ;; Tag inheritance checks FILETAGS keywords.
  931. (should
  932. (equal
  933. '(("a" "b" "tag"))
  934. (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
  935. (org-element-map
  936. tree 'headline
  937. (lambda (hl) (org-export-get-tags hl info nil t)) info))))))
  938. (ert-deftest test-org-export/get-node-property ()
  939. "Test`org-export-get-node-property' specifications."
  940. ;; Standard test.
  941. (should
  942. (equal "value"
  943. (org-test-with-parsed-data "* Headline
  944. :PROPERTIES:
  945. :prop: value
  946. :END:"
  947. (org-export-get-node-property
  948. :prop (org-element-map tree 'headline 'identity nil t)))))
  949. ;; Test inheritance.
  950. (should
  951. (equal "value"
  952. (org-test-with-parsed-data "* Parent
  953. :PROPERTIES:
  954. :prop: value
  955. :END:
  956. ** Headline
  957. Paragraph"
  958. (org-export-get-node-property
  959. :prop (org-element-map tree 'paragraph 'identity nil t) t))))
  960. ;; Cannot return a value before the first headline.
  961. (should-not
  962. (org-test-with-parsed-data "Paragraph
  963. * Headline
  964. :PROPERTIES:
  965. :prop: value
  966. :END:"
  967. (org-export-get-node-property
  968. :prop (org-element-map tree 'paragraph 'identity nil t)))))
  969. (ert-deftest test-org-export/get-category ()
  970. "Test `org-export-get-category' specifications."
  971. ;; Standard test.
  972. (should
  973. (equal "value"
  974. (org-test-with-parsed-data "* Headline
  975. :PROPERTIES:
  976. :CATEGORY: value
  977. :END:"
  978. (org-export-get-category
  979. (org-element-map tree 'headline 'identity nil t) info))))
  980. ;; Test inheritance from a parent headline.
  981. (should
  982. (equal '("value" "value")
  983. (org-test-with-parsed-data "* Headline1
  984. :PROPERTIES:
  985. :CATEGORY: value
  986. :END:
  987. ** Headline2"
  988. (org-element-map
  989. tree 'headline
  990. (lambda (hl) (org-export-get-category hl info)) info))))
  991. ;; Test inheritance from #+CATEGORY keyword
  992. (should
  993. (equal "value"
  994. (org-test-with-parsed-data "#+CATEGORY: value
  995. * Headline"
  996. (org-export-get-category
  997. (org-element-map tree 'headline 'identity nil t) info))))
  998. ;; Test inheritance from file name.
  999. (should
  1000. (equal "test"
  1001. (org-test-with-parsed-data "* Headline"
  1002. (let ((info (plist-put info :input-file "~/test.org")))
  1003. (org-export-get-category
  1004. (org-element-map tree 'headline 'identity nil t) info)))))
  1005. ;; Fall-back value.
  1006. (should
  1007. (equal "???"
  1008. (org-test-with-parsed-data "* Headline"
  1009. (org-export-get-category
  1010. (org-element-map tree 'headline 'identity nil t) info)))))
  1011. (ert-deftest test-org-export/first-sibling-p ()
  1012. "Test `org-export-first-sibling-p' specifications."
  1013. ;; Standard test.
  1014. (should
  1015. (equal
  1016. '(yes yes no)
  1017. (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
  1018. (org-element-map
  1019. tree 'headline
  1020. (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
  1021. info))))
  1022. ;; Ignore headlines not exported.
  1023. (should
  1024. (equal
  1025. '(yes)
  1026. (let ((org-export-exclude-tags '("ignore")))
  1027. (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
  1028. (org-element-map
  1029. tree 'headline
  1030. (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
  1031. info))))))
  1032. (ert-deftest test-org-export/last-sibling-p ()
  1033. "Test `org-export-last-sibling-p' specifications."
  1034. ;; Standard test.
  1035. (should
  1036. (equal
  1037. '(yes no yes)
  1038. (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
  1039. (org-element-map
  1040. tree 'headline
  1041. (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
  1042. info))))
  1043. ;; Ignore headlines not exported.
  1044. (should
  1045. (equal
  1046. '(yes)
  1047. (let ((org-export-exclude-tags '("ignore")))
  1048. (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
  1049. (org-element-map
  1050. tree 'headline
  1051. (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
  1052. info))))))
  1053. ;;; Links
  1054. (ert-deftest test-org-export/get-coderef-format ()
  1055. "Test `org-export-get-coderef-format' specifications."
  1056. ;; A link without description returns "%s"
  1057. (should (equal (org-export-get-coderef-format "(ref:line)" nil)
  1058. "%s"))
  1059. ;; Return "%s" when path is matched within description.
  1060. (should (equal (org-export-get-coderef-format "path" "desc (path)")
  1061. "desc %s"))
  1062. ;; Otherwise return description.
  1063. (should (equal (org-export-get-coderef-format "path" "desc")
  1064. "desc")))
  1065. (ert-deftest test-org-export/inline-image-p ()
  1066. "Test `org-export-inline-image-p' specifications."
  1067. (should
  1068. (org-export-inline-image-p
  1069. (org-test-with-temp-text "[[#id]]"
  1070. (org-element-map
  1071. (org-element-parse-buffer) 'link 'identity nil t))
  1072. '(("custom-id" . "id")))))
  1073. (ert-deftest test-org-export/fuzzy-link ()
  1074. "Test fuzzy links specifications."
  1075. ;; 1. Links to invisible (keyword) targets should be ignored.
  1076. (org-test-with-parsed-data
  1077. "Paragraph.\n#+TARGET: Test\n[[Test]]"
  1078. (should-not
  1079. (org-element-map
  1080. tree 'link
  1081. (lambda (link)
  1082. (org-export-get-ordinal
  1083. (org-export-resolve-fuzzy-link link info) info)) info)))
  1084. ;; 2. Link to an headline should return headline's number.
  1085. (org-test-with-parsed-data
  1086. "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
  1087. (should
  1088. ;; Note: Headline's number is in fact a list of numbers.
  1089. (equal '(2)
  1090. (org-element-map
  1091. tree 'link
  1092. (lambda (link)
  1093. (org-export-get-ordinal
  1094. (org-export-resolve-fuzzy-link link info) info)) info t))))
  1095. ;; 3. Link to a target in an item should return item's number.
  1096. (org-test-with-parsed-data
  1097. "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
  1098. (should
  1099. ;; Note: Item's number is in fact a list of numbers.
  1100. (equal '(1 2)
  1101. (org-element-map
  1102. tree 'link
  1103. (lambda (link)
  1104. (org-export-get-ordinal
  1105. (org-export-resolve-fuzzy-link link info) info)) info t))))
  1106. ;; 4. Link to a target in a footnote should return footnote's
  1107. ;; number.
  1108. (org-test-with-parsed-data "
  1109. Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
  1110. (should
  1111. (equal '(2 3)
  1112. (org-element-map
  1113. tree 'link
  1114. (lambda (link)
  1115. (org-export-get-ordinal
  1116. (org-export-resolve-fuzzy-link link info) info)) info))))
  1117. ;; 5. Link to a named element should return sequence number of that
  1118. ;; element.
  1119. (org-test-with-parsed-data
  1120. "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
  1121. (should
  1122. (= 2
  1123. (org-element-map
  1124. tree 'link
  1125. (lambda (link)
  1126. (org-export-get-ordinal
  1127. (org-export-resolve-fuzzy-link link info) info)) info t))))
  1128. ;; 6. Link to a target not within an item, a table, a footnote
  1129. ;; reference or definition should return section number.
  1130. (org-test-with-parsed-data
  1131. "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
  1132. (should
  1133. (equal '(2)
  1134. (org-element-map
  1135. tree 'link
  1136. (lambda (link)
  1137. (org-export-get-ordinal
  1138. (org-export-resolve-fuzzy-link link info) info)) info t)))))
  1139. (ert-deftest test-org-export/resolve-coderef ()
  1140. "Test `org-export-resolve-coderef' specifications."
  1141. (let ((org-coderef-label-format "(ref:%s)"))
  1142. ;; 1. A link to a "-n -k -r" block returns line number.
  1143. (org-test-with-parsed-data
  1144. "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
  1145. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  1146. (org-test-with-parsed-data
  1147. "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  1148. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  1149. ;; 2. A link to a "-n -r" block returns line number.
  1150. (org-test-with-parsed-data
  1151. "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
  1152. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  1153. (org-test-with-parsed-data
  1154. "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  1155. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  1156. ;; 3. A link to a "-n" block returns coderef.
  1157. (org-test-with-parsed-data
  1158. "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  1159. (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
  1160. (org-test-with-parsed-data
  1161. "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
  1162. (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
  1163. ;; 4. A link to a "-r" block returns line number.
  1164. (org-test-with-parsed-data
  1165. "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  1166. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  1167. (org-test-with-parsed-data
  1168. "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
  1169. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  1170. ;; 5. A link to a block without a switch returns coderef.
  1171. (org-test-with-parsed-data
  1172. "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  1173. (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
  1174. (org-test-with-parsed-data
  1175. "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
  1176. (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
  1177. ;; 6. Correctly handle continued line numbers. A "+n" switch
  1178. ;; should resume numbering from previous block with numbered
  1179. ;; lines, ignoring blocks not numbering lines in the process.
  1180. ;; A "-n" switch resets count.
  1181. (org-test-with-parsed-data "
  1182. #+BEGIN_EXAMPLE -n
  1183. Text.
  1184. #+END_EXAMPLE
  1185. #+BEGIN_SRC emacs-lisp
  1186. \(- 1 1)
  1187. #+END_SRC
  1188. #+BEGIN_SRC emacs-lisp +n -r
  1189. \(+ 1 1) (ref:addition)
  1190. #+END_SRC
  1191. #+BEGIN_EXAMPLE -n -r
  1192. Another text. (ref:text)
  1193. #+END_EXAMPLE"
  1194. (should (= (org-export-resolve-coderef "addition" info) 2))
  1195. (should (= (org-export-resolve-coderef "text" info) 1)))
  1196. ;; 7. Recognize coderef with user-specified syntax.
  1197. (org-test-with-parsed-data
  1198. "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
  1199. (should (equal (org-export-resolve-coderef "text" info) "text")))))
  1200. (ert-deftest test-org-export/resolve-fuzzy-link ()
  1201. "Test `org-export-resolve-fuzzy-link' specifications."
  1202. ;; 1. Match target objects.
  1203. (org-test-with-parsed-data "<<target>> [[target]]"
  1204. (should
  1205. (org-export-resolve-fuzzy-link
  1206. (org-element-map tree 'link 'identity info t) info)))
  1207. ;; 2. Match target elements.
  1208. (org-test-with-parsed-data "#+TARGET: target\n[[target]]"
  1209. (should
  1210. (org-export-resolve-fuzzy-link
  1211. (org-element-map tree 'link 'identity info t) info)))
  1212. ;; 3. Match named elements.
  1213. (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
  1214. (should
  1215. (org-export-resolve-fuzzy-link
  1216. (org-element-map tree 'link 'identity info t) info)))
  1217. ;; 4. Match exact headline's name.
  1218. (org-test-with-parsed-data "* My headline\n[[My headline]]"
  1219. (should
  1220. (org-export-resolve-fuzzy-link
  1221. (org-element-map tree 'link 'identity info t) info)))
  1222. ;; 5. Targets objects have priority over named elements and headline
  1223. ;; titles.
  1224. (org-test-with-parsed-data
  1225. "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
  1226. (should
  1227. (eq 'target
  1228. (org-element-type
  1229. (org-export-resolve-fuzzy-link
  1230. (org-element-map tree 'link 'identity info t) info)))))
  1231. ;; 6. Named elements have priority over headline titles.
  1232. (org-test-with-parsed-data
  1233. "* target\n#+NAME: target\nParagraph\n\n[[target]]"
  1234. (should
  1235. (eq 'paragraph
  1236. (org-element-type
  1237. (org-export-resolve-fuzzy-link
  1238. (org-element-map tree 'link 'identity info t) info)))))
  1239. ;; 7. If link's path starts with a "*", only match headline titles,
  1240. ;; though.
  1241. (org-test-with-parsed-data
  1242. "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
  1243. (should
  1244. (eq 'headline
  1245. (org-element-type
  1246. (org-export-resolve-fuzzy-link
  1247. (org-element-map tree 'link 'identity info t) info)))))
  1248. ;; 8. Return nil if no match.
  1249. (org-test-with-parsed-data "[[target]]"
  1250. (should-not
  1251. (org-export-resolve-fuzzy-link
  1252. (org-element-map tree 'link 'identity info t) info))))
  1253. (ert-deftest test-org-export/resolve-id-link ()
  1254. "Test `org-export-resolve-id-link' specifications."
  1255. ;; 1. Regular test for custom-id link.
  1256. (org-test-with-parsed-data "* Headline1
  1257. :PROPERTIES:
  1258. :CUSTOM-ID: test
  1259. :END:
  1260. * Headline 2
  1261. \[[#test]]"
  1262. (should
  1263. (org-export-resolve-id-link
  1264. (org-element-map tree 'link 'identity info t) info)))
  1265. ;; 2. Failing test for custom-id link.
  1266. (org-test-with-parsed-data "* Headline1
  1267. :PROPERTIES:
  1268. :CUSTOM-ID: test
  1269. :END:
  1270. * Headline 2
  1271. \[[#no-match]]"
  1272. (should-not
  1273. (org-export-resolve-id-link
  1274. (org-element-map tree 'link 'identity info t) info)))
  1275. ;; 3. Test for internal id target.
  1276. (org-test-with-parsed-data "* Headline1
  1277. :PROPERTIES:
  1278. :ID: aaaa
  1279. :END:
  1280. * Headline 2
  1281. \[[id:aaaa]]"
  1282. (should
  1283. (org-export-resolve-id-link
  1284. (org-element-map tree 'link 'identity info t) info)))
  1285. ;; 4. Test for external id target.
  1286. (org-test-with-parsed-data "[[id:aaaa]]"
  1287. (should
  1288. (org-export-resolve-id-link
  1289. (org-element-map tree 'link 'identity info t)
  1290. (org-combine-plists info '(:id-alist (("aaaa" . "external-file"))))))))
  1291. (ert-deftest test-org-export/resolve-radio-link ()
  1292. "Test `org-export-resolve-radio-link' specifications."
  1293. ;; Standard test.
  1294. (org-test-with-temp-text "<<<radio>>> radio"
  1295. (org-update-radio-target-regexp)
  1296. (should
  1297. (let* ((tree (org-element-parse-buffer))
  1298. (info `(:parse-tree ,tree)))
  1299. (org-export-resolve-radio-link
  1300. (org-element-map tree 'link 'identity info t)
  1301. info))))
  1302. ;; Radio target with objects.
  1303. (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
  1304. (org-update-radio-target-regexp)
  1305. (should
  1306. (let* ((tree (org-element-parse-buffer))
  1307. (info `(:parse-tree ,tree)))
  1308. (org-export-resolve-radio-link
  1309. (org-element-map tree 'link 'identity info t)
  1310. info)))))
  1311. ;;; Src-block and example-block
  1312. (ert-deftest test-org-export/unravel-code ()
  1313. "Test `org-export-unravel-code' function."
  1314. (let ((org-coderef-label-format "(ref:%s)"))
  1315. ;; 1. Code without reference.
  1316. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
  1317. (should (equal (org-export-unravel-code (org-element-at-point))
  1318. '("(+ 1 1)\n"))))
  1319. ;; 2. Code with reference.
  1320. (org-test-with-temp-text
  1321. "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
  1322. (should (equal (org-export-unravel-code (org-element-at-point))
  1323. '("(+ 1 1)\n" (1 . "test")))))
  1324. ;; 3. Code with user-defined reference.
  1325. (org-test-with-temp-text
  1326. "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
  1327. (should (equal (org-export-unravel-code (org-element-at-point))
  1328. '("(+ 1 1)\n" (1 . "test")))))
  1329. ;; 4. Code references keys are relative to the current block.
  1330. (org-test-with-temp-text "
  1331. #+BEGIN_EXAMPLE -n
  1332. \(+ 1 1)
  1333. #+END_EXAMPLE
  1334. #+BEGIN_EXAMPLE +n
  1335. \(+ 2 2)
  1336. \(+ 3 3) (ref:one)
  1337. #+END_EXAMPLE"
  1338. (goto-line 5)
  1339. (should (equal (org-export-unravel-code (org-element-at-point))
  1340. '("(+ 2 2)\n(+ 3 3)\n" (2 . "one")))))))
  1341. ;;; Smart Quotes
  1342. (ert-deftest test-org-export/activate-smart-quotes ()
  1343. "Test `org-export-activate-smart-quotes' specifications."
  1344. ;; Opening double quotes: standard test.
  1345. (should
  1346. (equal
  1347. '("some &ldquo;paragraph")
  1348. (let ((org-export-default-language "en"))
  1349. (org-test-with-parsed-data "some \"paragraph"
  1350. (org-element-map
  1351. tree 'plain-text
  1352. (lambda (s) (org-export-activate-smart-quotes s :html info))
  1353. info)))))
  1354. ;; Opening quotes: at the beginning of a paragraph.
  1355. (should
  1356. (equal
  1357. '("&ldquo;begin")
  1358. (let ((org-export-default-language "en"))
  1359. (org-test-with-parsed-data "\"begin"
  1360. (org-element-map
  1361. tree 'plain-text
  1362. (lambda (s) (org-export-activate-smart-quotes s :html info))
  1363. info)))))
  1364. ;; Opening quotes: after an object.
  1365. (should
  1366. (equal
  1367. '("&ldquo;begin")
  1368. (let ((org-export-default-language "en"))
  1369. (org-test-with-parsed-data "=verb= \"begin"
  1370. (org-element-map
  1371. tree 'plain-text
  1372. (lambda (s) (org-export-activate-smart-quotes s :html info))
  1373. info)))))
  1374. ;; Closing quotes: standard test.
  1375. (should
  1376. (equal
  1377. '("some&rdquo; paragraph")
  1378. (let ((org-export-default-language "en"))
  1379. (org-test-with-parsed-data "some\" paragraph"
  1380. (org-element-map
  1381. tree 'plain-text
  1382. (lambda (s) (org-export-activate-smart-quotes s :html info))
  1383. info)))))
  1384. ;; Closing quotes: at the end of a paragraph.
  1385. (should
  1386. (equal
  1387. '("end&rdquo;")
  1388. (let ((org-export-default-language "en"))
  1389. (org-test-with-parsed-data "end\""
  1390. (org-element-map
  1391. tree 'plain-text
  1392. (lambda (s) (org-export-activate-smart-quotes s :html info))
  1393. info)))))
  1394. ;; Apostrophe: standard test.
  1395. (should
  1396. (equal
  1397. '("It shouldn&rsquo;t fail")
  1398. (let ((org-export-default-language "en"))
  1399. (org-test-with-parsed-data "It shouldn't fail"
  1400. (org-element-map
  1401. tree 'plain-text
  1402. (lambda (s) (org-export-activate-smart-quotes s :html info))
  1403. info)))))
  1404. ;; Apostrophe: before an object.
  1405. (should
  1406. (equal
  1407. '("a&rsquo;")
  1408. (let ((org-export-default-language "en"))
  1409. (org-test-with-parsed-data "a'=b="
  1410. (org-element-map
  1411. tree 'plain-text
  1412. (lambda (s) (org-export-activate-smart-quotes s :html info))
  1413. info)))))
  1414. ;; Apostrophe: after an object.
  1415. (should
  1416. (equal
  1417. '("&rsquo;s")
  1418. (let ((org-export-default-language "en"))
  1419. (org-test-with-parsed-data "=code='s"
  1420. (org-element-map
  1421. tree 'plain-text
  1422. (lambda (s) (org-export-activate-smart-quotes s :html info))
  1423. info)))))
  1424. ;; Special case: isolated quotes.
  1425. (should
  1426. (equal '("&ldquo;" "&rdquo;")
  1427. (let ((org-export-default-language "en"))
  1428. (org-test-with-parsed-data "\"$x$\""
  1429. (org-element-map
  1430. tree 'plain-text
  1431. (lambda (s) (org-export-activate-smart-quotes s :html info))
  1432. info)))))
  1433. ;; Smart quotes in secondary strings.
  1434. (should
  1435. (equal '("&ldquo;" "&rdquo;")
  1436. (let ((org-export-default-language "en"))
  1437. (org-test-with-parsed-data "* \"$x$\""
  1438. (org-element-map
  1439. tree 'plain-text
  1440. (lambda (s) (org-export-activate-smart-quotes s :html info))
  1441. info)))))
  1442. ;; Smart quotes in document keywords.
  1443. (should
  1444. (equal '("&ldquo;" "&rdquo;")
  1445. (let ((org-export-default-language "en"))
  1446. (org-test-with-parsed-data "#+TITLE: \"$x$\""
  1447. (org-element-map
  1448. (plist-get info :title) 'plain-text
  1449. (lambda (s) (org-export-activate-smart-quotes s :html info))
  1450. info)))))
  1451. ;; Smart quotes in parsed affiliated keywords.
  1452. (should
  1453. (equal '("&ldquo;" "&rdquo;" "Paragraph")
  1454. (let ((org-export-default-language "en"))
  1455. (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
  1456. (org-element-map
  1457. tree 'plain-text
  1458. (lambda (s) (org-export-activate-smart-quotes s :html info))
  1459. info nil nil t))))))
  1460. ;;; Tables
  1461. (ert-deftest test-org-export/special-column ()
  1462. "Test if the table's special column is properly recognized."
  1463. ;; 1. First column is special if it contains only a special marking
  1464. ;; characters or empty cells.
  1465. (org-test-with-temp-text "
  1466. | ! | 1 |
  1467. | | 2 |"
  1468. (should
  1469. (org-export-table-has-special-column-p
  1470. (org-element-map
  1471. (org-element-parse-buffer) 'table 'identity nil 'first-match))))
  1472. ;; 2. If the column contains anything else, it isn't special.
  1473. (org-test-with-temp-text "
  1474. | ! | 1 |
  1475. | b | 2 |"
  1476. (should-not
  1477. (org-export-table-has-special-column-p
  1478. (org-element-map
  1479. (org-element-parse-buffer) 'table 'identity nil 'first-match))))
  1480. ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
  1481. ;; and "!".
  1482. (org-test-with-temp-text "
  1483. | # | 1 |
  1484. | ^ | 2 |
  1485. | * | 3 |
  1486. | _ | 4 |
  1487. | / | 5 |
  1488. | $ | 6 |
  1489. | ! | 7 |"
  1490. (should
  1491. (org-export-table-has-special-column-p
  1492. (org-element-map
  1493. (org-element-parse-buffer) 'table 'identity nil 'first-match))))
  1494. ;; 4. A first column with only empty cells isn't considered as
  1495. ;; special.
  1496. (org-test-with-temp-text "
  1497. | | 1 |
  1498. | | 2 |"
  1499. (should-not
  1500. (org-export-table-has-special-column-p
  1501. (org-element-map
  1502. (org-element-parse-buffer) 'table 'identity nil 'first-match)))))
  1503. (ert-deftest test-org-export/table-row-is-special-p ()
  1504. "Test `org-export-table-row-is-special-p' specifications."
  1505. ;; 1. A row is special if it has a special marking character in the
  1506. ;; special column.
  1507. (org-test-with-parsed-data "| ! | 1 |"
  1508. (should
  1509. (org-export-table-row-is-special-p
  1510. (org-element-map tree 'table-row 'identity nil 'first-match) info)))
  1511. ;; 2. A row is special when its first field is "/"
  1512. (org-test-with-parsed-data "
  1513. | / | 1 |
  1514. | a | b |"
  1515. (should
  1516. (org-export-table-row-is-special-p
  1517. (org-element-map tree 'table-row 'identity nil 'first-match) info)))
  1518. ;; 3. A row only containing alignment cookies is also considered as
  1519. ;; special.
  1520. (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
  1521. (should
  1522. (org-export-table-row-is-special-p
  1523. (org-element-map tree 'table-row 'identity nil 'first-match) info)))
  1524. ;; 4. Everything else isn't considered as special.
  1525. (org-test-with-parsed-data "| \alpha | | c |"
  1526. (should-not
  1527. (org-export-table-row-is-special-p
  1528. (org-element-map tree 'table-row 'identity nil 'first-match) info)))
  1529. ;; 5. Table's rules are never considered as special rows.
  1530. (org-test-with-parsed-data "|---+---|"
  1531. (should-not
  1532. (org-export-table-row-is-special-p
  1533. (org-element-map tree 'table-row 'identity nil 'first-match) info))))
  1534. (ert-deftest test-org-export/has-header-p ()
  1535. "Test `org-export-table-has-header-p' specifications."
  1536. ;; 1. With an header.
  1537. (org-test-with-parsed-data "
  1538. | a | b |
  1539. |---+---|
  1540. | c | d |"
  1541. (should
  1542. (org-export-table-has-header-p
  1543. (org-element-map tree 'table 'identity info 'first-match)
  1544. info)))
  1545. ;; 2. Without an header.
  1546. (org-test-with-parsed-data "
  1547. | a | b |
  1548. | c | d |"
  1549. (should-not
  1550. (org-export-table-has-header-p
  1551. (org-element-map tree 'table 'identity info 'first-match)
  1552. info)))
  1553. ;; 3. Don't get fooled with starting and ending rules.
  1554. (org-test-with-parsed-data "
  1555. |---+---|
  1556. | a | b |
  1557. | c | d |
  1558. |---+---|"
  1559. (should-not
  1560. (org-export-table-has-header-p
  1561. (org-element-map tree 'table 'identity info 'first-match)
  1562. info))))
  1563. (ert-deftest test-org-export/table-row-group ()
  1564. "Test `org-export-table-row-group' specifications."
  1565. ;; 1. A rule creates a new group.
  1566. (org-test-with-parsed-data "
  1567. | a | b |
  1568. |---+---|
  1569. | 1 | 2 |"
  1570. (should
  1571. (equal
  1572. '(1 nil 2)
  1573. (mapcar (lambda (row) (org-export-table-row-group row info))
  1574. (org-element-map tree 'table-row 'identity)))))
  1575. ;; 2. Special rows are ignored in count.
  1576. (org-test-with-parsed-data "
  1577. | / | < | > |
  1578. |---|---+---|
  1579. | | 1 | 2 |"
  1580. (should
  1581. (equal
  1582. '(nil nil 1)
  1583. (mapcar (lambda (row) (org-export-table-row-group row info))
  1584. (org-element-map tree 'table-row 'identity)))))
  1585. ;; 3. Double rules also are ignored in count.
  1586. (org-test-with-parsed-data "
  1587. | a | b |
  1588. |---+---|
  1589. |---+---|
  1590. | 1 | 2 |"
  1591. (should
  1592. (equal
  1593. '(1 nil nil 2)
  1594. (mapcar (lambda (row) (org-export-table-row-group row info))
  1595. (org-element-map tree 'table-row 'identity))))))
  1596. (ert-deftest test-org-export/table-cell-width ()
  1597. "Test `org-export-table-cell-width' specifications."
  1598. ;; 1. Width is primarily determined by width cookies. If no cookie
  1599. ;; is found, cell's width is nil.
  1600. (org-test-with-parsed-data "
  1601. | / | <l> | <6> | <l7> |
  1602. | | a | b | c |"
  1603. (should
  1604. (equal
  1605. '(nil 6 7)
  1606. (mapcar (lambda (cell) (org-export-table-cell-width cell info))
  1607. (org-element-map tree 'table-cell 'identity info)))))
  1608. ;; 2. The last width cookie has precedence.
  1609. (org-test-with-parsed-data "
  1610. | <6> |
  1611. | <7> |
  1612. | a |"
  1613. (should
  1614. (equal
  1615. '(7)
  1616. (mapcar (lambda (cell) (org-export-table-cell-width cell info))
  1617. (org-element-map tree 'table-cell 'identity info)))))
  1618. ;; 3. Valid width cookies must have a specific row.
  1619. (org-test-with-parsed-data "| <6> | cell |"
  1620. (should
  1621. (equal
  1622. '(nil nil)
  1623. (mapcar (lambda (cell) (org-export-table-cell-width cell info))
  1624. (org-element-map tree 'table-cell 'identity))))))
  1625. (ert-deftest test-org-export/table-cell-alignment ()
  1626. "Test `org-export-table-cell-alignment' specifications."
  1627. (let ((org-table-number-fraction 0.5)
  1628. (org-table-number-regexp "^[0-9]+$"))
  1629. ;; 1. Alignment is primarily determined by alignment cookies.
  1630. (org-test-with-temp-text "| <l> | <c> | <r> |"
  1631. (let* ((tree (org-element-parse-buffer))
  1632. (info `(:parse-tree ,tree)))
  1633. (should
  1634. (equal
  1635. '(left center right)
  1636. (mapcar (lambda (cell) (org-export-table-cell-alignment cell info))
  1637. (org-element-map tree 'table-cell 'identity))))))
  1638. ;; 2. The last alignment cookie has precedence.
  1639. (org-test-with-parsed-data "
  1640. | <l8> |
  1641. | cell |
  1642. | <r9> |"
  1643. (should
  1644. (equal
  1645. '(right right right)
  1646. (mapcar (lambda (cell) (org-export-table-cell-alignment cell info))
  1647. (org-element-map tree 'table-cell 'identity)))))
  1648. ;; 3. If there's no cookie, cell's contents determine alignment.
  1649. ;; A column mostly made of cells containing numbers will align
  1650. ;; its cells to the right.
  1651. (org-test-with-parsed-data "
  1652. | 123 |
  1653. | some text |
  1654. | 12345 |"
  1655. (should
  1656. (equal
  1657. '(right right right)
  1658. (mapcar (lambda (cell)
  1659. (org-export-table-cell-alignment cell info))
  1660. (org-element-map tree 'table-cell 'identity)))))
  1661. ;; 4. Otherwise, they will be aligned to the left.
  1662. (org-test-with-parsed-data "
  1663. | text |
  1664. | some text |
  1665. | \alpha |"
  1666. (should
  1667. (equal
  1668. '(left left left)
  1669. (mapcar (lambda (cell)
  1670. (org-export-table-cell-alignment cell info))
  1671. (org-element-map tree 'table-cell 'identity)))))))
  1672. (ert-deftest test-org-export/table-cell-borders ()
  1673. "Test `org-export-table-cell-borders' specifications."
  1674. ;; 1. Recognize various column groups indicators.
  1675. (org-test-with-parsed-data "| / | < | > | <> |"
  1676. (should
  1677. (equal
  1678. '((right bottom top) (left bottom top) (right bottom top)
  1679. (right left bottom top))
  1680. (mapcar (lambda (cell)
  1681. (org-export-table-cell-borders cell info))
  1682. (org-element-map tree 'table-cell 'identity)))))
  1683. ;; 2. Accept shortcuts to define column groups.
  1684. (org-test-with-parsed-data "| / | < | < |"
  1685. (should
  1686. (equal
  1687. '((right bottom top) (right left bottom top) (left bottom top))
  1688. (mapcar (lambda (cell)
  1689. (org-export-table-cell-borders cell info))
  1690. (org-element-map tree 'table-cell 'identity)))))
  1691. ;; 3. A valid column groups row must start with a "/".
  1692. (org-test-with-parsed-data "
  1693. | | < |
  1694. | a | b |"
  1695. (should
  1696. (equal '((top) (top) (bottom) (bottom))
  1697. (mapcar (lambda (cell)
  1698. (org-export-table-cell-borders cell info))
  1699. (org-element-map tree 'table-cell 'identity)))))
  1700. ;; 4. Take table rules into consideration.
  1701. (org-test-with-parsed-data "
  1702. | 1 |
  1703. |---|
  1704. | 2 |"
  1705. (should
  1706. (equal '((below top) (bottom above))
  1707. (mapcar (lambda (cell)
  1708. (org-export-table-cell-borders cell info))
  1709. (org-element-map tree 'table-cell 'identity)))))
  1710. ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
  1711. ;; (resp. `bottom' and `below') borders. Any special row is
  1712. ;; ignored.
  1713. (org-test-with-parsed-data "
  1714. |---+----|
  1715. | / | |
  1716. | | 1 |
  1717. |---+----|"
  1718. (should
  1719. (equal '((bottom below top above))
  1720. (last
  1721. (mapcar (lambda (cell)
  1722. (org-export-table-cell-borders cell info))
  1723. (org-element-map tree 'table-cell 'identity)))))))
  1724. (ert-deftest test-org-export/table-dimensions ()
  1725. "Test `org-export-table-dimensions' specifications."
  1726. ;; 1. Standard test.
  1727. (org-test-with-parsed-data "
  1728. | 1 | 2 | 3 |
  1729. | 4 | 5 | 6 |"
  1730. (should
  1731. (equal '(2 . 3)
  1732. (org-export-table-dimensions
  1733. (org-element-map tree 'table 'identity info 'first-match) info))))
  1734. ;; 2. Ignore horizontal rules and special columns.
  1735. (org-test-with-parsed-data "
  1736. | / | < | > |
  1737. | 1 | 2 | 3 |
  1738. |---+---+---|
  1739. | 4 | 5 | 6 |"
  1740. (should
  1741. (equal '(2 . 3)
  1742. (org-export-table-dimensions
  1743. (org-element-map tree 'table 'identity info 'first-match) info)))))
  1744. (ert-deftest test-org-export/table-cell-address ()
  1745. "Test `org-export-table-cell-address' specifications."
  1746. ;; 1. Standard test: index is 0-based.
  1747. (org-test-with-parsed-data "| a | b |"
  1748. (should
  1749. (equal '((0 . 0) (0 . 1))
  1750. (org-element-map
  1751. tree 'table-cell
  1752. (lambda (cell) (org-export-table-cell-address cell info))
  1753. info))))
  1754. ;; 2. Special column isn't counted, nor are special rows.
  1755. (org-test-with-parsed-data "
  1756. | / | <> |
  1757. | | c |"
  1758. (should
  1759. (equal '(0 . 0)
  1760. (org-export-table-cell-address
  1761. (car (last (org-element-map tree 'table-cell 'identity info)))
  1762. info))))
  1763. ;; 3. Tables rules do not count either.
  1764. (org-test-with-parsed-data "
  1765. | a |
  1766. |---|
  1767. | b |
  1768. |---|
  1769. | c |"
  1770. (should
  1771. (equal '(2 . 0)
  1772. (org-export-table-cell-address
  1773. (car (last (org-element-map tree 'table-cell 'identity info)))
  1774. info))))
  1775. ;; 4. Return nil for special cells.
  1776. (org-test-with-parsed-data "| / | a |"
  1777. (should-not
  1778. (org-export-table-cell-address
  1779. (org-element-map tree 'table-cell 'identity nil 'first-match)
  1780. info))))
  1781. (ert-deftest test-org-export/get-table-cell-at ()
  1782. "Test `org-export-get-table-cell-at' specifications."
  1783. ;; 1. Address ignores special columns, special rows and rules.
  1784. (org-test-with-parsed-data "
  1785. | / | <> |
  1786. | | a |
  1787. |---+----|
  1788. | | b |"
  1789. (should
  1790. (equal '("b")
  1791. (org-element-contents
  1792. (org-export-get-table-cell-at
  1793. '(1 . 0)
  1794. (org-element-map tree 'table 'identity info 'first-match)
  1795. info)))))
  1796. ;; 2. Return value for a non-existent address is nil.
  1797. (org-test-with-parsed-data "| a |"
  1798. (should-not
  1799. (org-export-get-table-cell-at
  1800. '(2 . 2)
  1801. (org-element-map tree 'table 'identity info 'first-match)
  1802. info)))
  1803. (org-test-with-parsed-data "| / |"
  1804. (should-not
  1805. (org-export-get-table-cell-at
  1806. '(0 . 0)
  1807. (org-element-map tree 'table 'identity info 'first-match)
  1808. info))))
  1809. (ert-deftest test-org-export/table-cell-starts-colgroup-p ()
  1810. "Test `org-export-table-cell-starts-colgroup-p' specifications."
  1811. ;; 1. A cell at a beginning of a row always starts a column group.
  1812. (org-test-with-parsed-data "| a |"
  1813. (should
  1814. (org-export-table-cell-starts-colgroup-p
  1815. (org-element-map tree 'table-cell 'identity info 'first-match)
  1816. info)))
  1817. ;; 2. Special column should be ignored when determining the
  1818. ;; beginning of the row.
  1819. (org-test-with-parsed-data "
  1820. | / | |
  1821. | | a |"
  1822. (should
  1823. (org-export-table-cell-starts-colgroup-p
  1824. (org-element-map tree 'table-cell 'identity info 'first-match)
  1825. info)))
  1826. ;; 2. Explicit column groups.
  1827. (org-test-with-parsed-data "
  1828. | / | | < |
  1829. | a | b | c |"
  1830. (should
  1831. (equal
  1832. '(yes no yes)
  1833. (org-element-map
  1834. tree 'table-cell
  1835. (lambda (cell)
  1836. (if (org-export-table-cell-starts-colgroup-p cell info) 'yes 'no))
  1837. info)))))
  1838. (ert-deftest test-org-export/table-cell-ends-colgroup-p ()
  1839. "Test `org-export-table-cell-ends-colgroup-p' specifications."
  1840. ;; 1. A cell at the end of a row always ends a column group.
  1841. (org-test-with-parsed-data "| a |"
  1842. (should
  1843. (org-export-table-cell-ends-colgroup-p
  1844. (org-element-map tree 'table-cell 'identity info 'first-match)
  1845. info)))
  1846. ;; 2. Special column should be ignored when determining the
  1847. ;; beginning of the row.
  1848. (org-test-with-parsed-data "
  1849. | / | |
  1850. | | a |"
  1851. (should
  1852. (org-export-table-cell-ends-colgroup-p
  1853. (org-element-map tree 'table-cell 'identity info 'first-match)
  1854. info)))
  1855. ;; 3. Explicit column groups.
  1856. (org-test-with-parsed-data "
  1857. | / | < | |
  1858. | a | b | c |"
  1859. (should
  1860. (equal
  1861. '(yes no yes)
  1862. (org-element-map
  1863. tree 'table-cell
  1864. (lambda (cell)
  1865. (if (org-export-table-cell-ends-colgroup-p cell info) 'yes 'no))
  1866. info)))))
  1867. (ert-deftest test-org-export/table-row-starts-rowgroup-p ()
  1868. "Test `org-export-table-row-starts-rowgroup-p' specifications."
  1869. ;; 1. A row at the beginning of a table always starts a row group.
  1870. ;; So does a row following a table rule.
  1871. (org-test-with-parsed-data "
  1872. | a |
  1873. |---|
  1874. | b |"
  1875. (should
  1876. (equal
  1877. '(yes no yes)
  1878. (org-element-map
  1879. tree 'table-row
  1880. (lambda (row)
  1881. (if (org-export-table-row-starts-rowgroup-p row info) 'yes 'no))
  1882. info))))
  1883. ;; 2. Special rows should be ignored when determining the beginning
  1884. ;; of the row.
  1885. (org-test-with-parsed-data "
  1886. | / | < |
  1887. | | a |
  1888. |---+---|
  1889. | / | < |
  1890. | | b |"
  1891. (should
  1892. (equal
  1893. '(yes no yes)
  1894. (org-element-map
  1895. tree 'table-row
  1896. (lambda (row)
  1897. (if (org-export-table-row-starts-rowgroup-p row info) 'yes 'no))
  1898. info)))))
  1899. (ert-deftest test-org-export/table-row-ends-rowgroup-p ()
  1900. "Test `org-export-table-row-ends-rowgroup-p' specifications."
  1901. ;; 1. A row at the end of a table always ends a row group. So does
  1902. ;; a row preceding a table rule.
  1903. (org-test-with-parsed-data "
  1904. | a |
  1905. |---|
  1906. | b |"
  1907. (should
  1908. (equal
  1909. '(yes no yes)
  1910. (org-element-map
  1911. tree 'table-row
  1912. (lambda (row)
  1913. (if (org-export-table-row-ends-rowgroup-p row info) 'yes 'no))
  1914. info))))
  1915. ;; 2. Special rows should be ignored when determining the beginning
  1916. ;; of the row.
  1917. (org-test-with-parsed-data "
  1918. | | a |
  1919. | / | < |
  1920. |---+---|
  1921. | | b |
  1922. | / | < |"
  1923. (should
  1924. (equal
  1925. '(yes no yes)
  1926. (org-element-map
  1927. tree 'table-row
  1928. (lambda (row)
  1929. (if (org-export-table-row-ends-rowgroup-p row info) 'yes 'no))
  1930. info)))))
  1931. (ert-deftest test-org-export/table-row-starts-header-p ()
  1932. "Test `org-export-table-row-starts-header-p' specifications."
  1933. ;; 1. Only the row starting the first row group starts the table
  1934. ;; header.
  1935. (org-test-with-parsed-data "
  1936. | a |
  1937. | b |
  1938. |---|
  1939. | c |"
  1940. (should
  1941. (equal
  1942. '(yes no no no)
  1943. (org-element-map
  1944. tree 'table-row
  1945. (lambda (row)
  1946. (if (org-export-table-row-starts-header-p row info) 'yes 'no))
  1947. info))))
  1948. ;; 2. A row cannot start an header if there's no header in the
  1949. ;; table.
  1950. (org-test-with-parsed-data "
  1951. | a |
  1952. |---|"
  1953. (should-not
  1954. (org-export-table-row-starts-header-p
  1955. (org-element-map tree 'table-row 'identity info 'first-match)
  1956. info))))
  1957. (ert-deftest test-org-export/table-row-ends-header-p ()
  1958. "Test `org-export-table-row-ends-header-p' specifications."
  1959. ;; 1. Only the row starting the first row group starts the table
  1960. ;; header.
  1961. (org-test-with-parsed-data "
  1962. | a |
  1963. | b |
  1964. |---|
  1965. | c |"
  1966. (should
  1967. (equal
  1968. '(no yes no no)
  1969. (org-element-map
  1970. tree 'table-row
  1971. (lambda (row)
  1972. (if (org-export-table-row-ends-header-p row info) 'yes 'no))
  1973. info))))
  1974. ;; 2. A row cannot start an header if there's no header in the
  1975. ;; table.
  1976. (org-test-with-parsed-data "
  1977. | a |
  1978. |---|"
  1979. (should-not
  1980. (org-export-table-row-ends-header-p
  1981. (org-element-map tree 'table-row 'identity info 'first-match)
  1982. info))))
  1983. ;;; Topology
  1984. (ert-deftest test-org-export/get-next-element ()
  1985. "Test `org-export-get-next-element' specifications."
  1986. ;; Standard test.
  1987. (should
  1988. (equal "b"
  1989. (org-test-with-parsed-data "* Headline\n*a* b"
  1990. (org-export-get-next-element
  1991. (org-element-map tree 'bold 'identity info t) info))))
  1992. ;; Return nil when no previous element.
  1993. (should-not
  1994. (org-test-with-parsed-data "* Headline\na *b*"
  1995. (org-export-get-next-element
  1996. (org-element-map tree 'bold 'identity info t) info)))
  1997. ;; Non-exportable elements are ignored.
  1998. (should-not
  1999. (let ((org-export-with-timestamps nil))
  2000. (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
  2001. (org-export-get-next-element
  2002. (org-element-map tree 'entity 'identity info t) info))))
  2003. ;; Find next element in secondary strings.
  2004. (should
  2005. (eq 'verbatim
  2006. (org-test-with-parsed-data "* a =verb="
  2007. (org-element-type
  2008. (org-export-get-next-element
  2009. (org-element-map tree 'plain-text 'identity info t) info)))))
  2010. ;; Find next element in document keywords.
  2011. (should
  2012. (eq 'verbatim
  2013. (org-test-with-parsed-data "#+TITLE: a =verb="
  2014. (org-element-type
  2015. (org-export-get-next-element
  2016. (org-element-map
  2017. (plist-get info :title) 'plain-text 'identity info t) info)))))
  2018. ;; Find next element in parsed affiliated keywords.
  2019. (should
  2020. (eq 'verbatim
  2021. (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
  2022. (org-element-type
  2023. (org-export-get-next-element
  2024. (org-element-map tree 'plain-text 'identity info t nil t) info)))))
  2025. ;; With optional argument N, return a list containing all the
  2026. ;; following elements.
  2027. (should
  2028. (equal
  2029. '(bold code underline)
  2030. (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
  2031. (mapcar 'car
  2032. (org-export-get-next-element
  2033. (org-element-map tree 'italic 'identity info t) info t)))))
  2034. ;; When N is a positive integer, return a list containing up to
  2035. ;; N following elements.
  2036. (should
  2037. (equal
  2038. '(bold code)
  2039. (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
  2040. (mapcar 'car
  2041. (org-export-get-next-element
  2042. (org-element-map tree 'italic 'identity info t) info 2))))))
  2043. (ert-deftest test-org-export/get-previous-element ()
  2044. "Test `org-export-get-previous-element' specifications."
  2045. ;; Standard test.
  2046. (should
  2047. (equal "a "
  2048. (org-test-with-parsed-data "* Headline\na *b*"
  2049. (org-export-get-previous-element
  2050. (org-element-map tree 'bold 'identity info t) info))))
  2051. ;; Return nil when no previous element.
  2052. (should-not
  2053. (org-test-with-parsed-data "* Headline\n*a* b"
  2054. (org-export-get-previous-element
  2055. (org-element-map tree 'bold 'identity info t) info)))
  2056. ;; Non-exportable elements are ignored.
  2057. (should-not
  2058. (let ((org-export-with-timestamps nil))
  2059. (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
  2060. (org-export-get-previous-element
  2061. (org-element-map tree 'entity 'identity info t) info))))
  2062. ;; Find previous element in secondary strings.
  2063. (should
  2064. (eq 'verbatim
  2065. (org-test-with-parsed-data "* =verb= a"
  2066. (org-element-type
  2067. (org-export-get-previous-element
  2068. (org-element-map tree 'plain-text 'identity info t) info)))))
  2069. ;; Find previous element in document keywords.
  2070. (should
  2071. (eq 'verbatim
  2072. (org-test-with-parsed-data "#+TITLE: =verb= a"
  2073. (org-element-type
  2074. (org-export-get-previous-element
  2075. (org-element-map
  2076. (plist-get info :title) 'plain-text 'identity info t) info)))))
  2077. ;; Find previous element in parsed affiliated keywords.
  2078. (should
  2079. (eq 'verbatim
  2080. (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
  2081. (org-element-type
  2082. (org-export-get-previous-element
  2083. (org-element-map tree 'plain-text 'identity info t nil t) info)))))
  2084. ;; With optional argument N, return a list containing up to
  2085. ;; N previous elements.
  2086. (should
  2087. (equal '(bold italic underline)
  2088. (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
  2089. (mapcar 'car
  2090. (org-export-get-previous-element
  2091. (org-element-map tree 'code 'identity info t) info t)))))
  2092. ;; When N is a positive integer, return a list containing up to
  2093. ;; N previous elements.
  2094. (should
  2095. (equal '(bold italic)
  2096. (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
  2097. (mapcar 'car
  2098. (org-export-get-previous-element
  2099. (org-element-map tree 'code 'identity info t) info 2))))))
  2100. (provide 'test-org-export)
  2101. ;;; test-org-export.el end here