test-ox.el 107 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259
  1. ;;; test-ox.el --- Tests for ox.el
  2. ;; Copyright (C) 2012, 2013, 2014 Nicolas Goaziou
  3. ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
  4. ;; This file is not part of GNU Emacs.
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Code:
  16. (unless (featurep 'ox)
  17. (signal 'missing-test-dependency "org-export"))
  18. (defun org-test-default-backend ()
  19. "Return a default export back-end.
  20. This back-end simply returns parsed data as Org syntax."
  21. (org-export-create-backend
  22. :transcoders (let (transcode-table)
  23. (dolist (type (append org-element-all-elements
  24. org-element-all-objects)
  25. transcode-table)
  26. (push
  27. (cons type
  28. (lambda (obj contents info)
  29. (funcall
  30. (intern (format "org-element-%s-interpreter"
  31. type))
  32. obj contents)))
  33. transcode-table)))))
  34. (defmacro org-test-with-parsed-data (data &rest body)
  35. "Execute body with parsed data available.
  36. DATA is a string containing the data to be parsed. BODY is the
  37. body to execute. Parse tree is available under the `tree'
  38. variable, and communication channel under `info'.
  39. This function calls `org-export-collect-tree-properties'. As
  40. such, `:ignore-list' (for `org-element-map') and
  41. `:parse-tree' (for `org-export-get-genealogy') properties are
  42. already filled in `info'."
  43. (declare (debug (form body)) (indent 1))
  44. `(org-test-with-temp-text ,data
  45. (let* ((tree (org-element-parse-buffer))
  46. (info (org-export-collect-tree-properties
  47. tree (org-export-get-environment))))
  48. ,@body)))
  49. ;;; Internal Tests
  50. (ert-deftest test-org-export/bind-keyword ()
  51. "Test reading #+BIND: keywords."
  52. ;; Test with `org-export-allow-bind-keywords' set to t.
  53. (should
  54. (org-test-with-temp-text "#+BIND: test-ox-var value"
  55. (let ((org-export-allow-bind-keywords t))
  56. (org-export-get-environment)
  57. (eq test-ox-var 'value))))
  58. ;; Test with `org-export-allow-bind-keywords' set to nil.
  59. (should-not
  60. (org-test-with-temp-text "#+BIND: test-ox-var value"
  61. (let ((org-export-allow-bind-keywords nil))
  62. (org-export-get-environment)
  63. (boundp 'test-ox-var))))
  64. ;; BIND keywords are case-insensitive.
  65. (should
  66. (org-test-with-temp-text "#+bind: test-ox-var value"
  67. (let ((org-export-allow-bind-keywords t))
  68. (org-export-get-environment)
  69. (eq test-ox-var 'value))))
  70. ;; Preserve order of BIND keywords.
  71. (should
  72. (org-test-with-temp-text "#+BIND: test-ox-var 1\n#+BIND: test-ox-var 2"
  73. (let ((org-export-allow-bind-keywords t))
  74. (org-export-get-environment)
  75. (eq test-ox-var 2))))
  76. ;; Read BIND keywords in setup files.
  77. (should
  78. (org-test-with-temp-text
  79. (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
  80. (let ((org-export-allow-bind-keywords t))
  81. (org-export-get-environment)
  82. (eq variable 'value))))
  83. ;; Verify that bound variables are seen during export.
  84. (should
  85. (equal "Yes\n"
  86. (org-test-with-temp-text "#+BIND: test-ox-var value"
  87. (let ((org-export-allow-bind-keywords t))
  88. (org-export-as
  89. (org-export-create-backend
  90. :transcoders
  91. '((section . (lambda (s c i)
  92. (if (eq test-ox-var 'value) "Yes" "No")))))))))))
  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. ;; Properties should follow buffer order.
  123. (should
  124. (equal
  125. (org-test-with-temp-text "#+LANGUAGE: fr\n#+CREATOR: Me\n#+EMAIL: email"
  126. (org-export--get-inbuffer-options))
  127. '(:language "fr" :creator "Me" :email "email")))
  128. ;; Parse document keywords.
  129. (should
  130. (equal
  131. (org-test-with-temp-text "#+AUTHOR: Me"
  132. (org-export--get-inbuffer-options))
  133. '(:author ("Me"))))
  134. ;; Test `space' behaviour.
  135. (should
  136. (equal
  137. (org-test-with-temp-text "#+TITLE: Some title\n#+TITLE: with spaces"
  138. (org-export--get-inbuffer-options))
  139. '(:title ("Some title with spaces"))))
  140. ;; Test `newline' behaviour.
  141. (should
  142. (equal
  143. (org-test-with-temp-text "#+DESCRIPTION: With\n#+DESCRIPTION: two lines"
  144. (org-export--get-inbuffer-options))
  145. '(:description "With\ntwo lines")))
  146. ;; Test `split' behaviour.
  147. (should
  148. (equal
  149. (org-test-with-temp-text "#+SELECT_TAGS: a\n#+SELECT_TAGS: b"
  150. (org-export--get-inbuffer-options))
  151. '(:select-tags ("a" "b"))))
  152. ;; Options set through SETUPFILE.
  153. (should
  154. (equal
  155. (org-test-with-temp-text
  156. (format "#+DESCRIPTION: l1
  157. #+LANGUAGE: es
  158. #+SELECT_TAGS: a
  159. #+TITLE: a
  160. #+SETUPFILE: \"%s/examples/setupfile.org\"
  161. #+DESCRIPTION: l3
  162. #+LANGUAGE: fr
  163. #+SELECT_TAGS: c
  164. #+TITLE: c"
  165. org-test-dir)
  166. (org-export--get-inbuffer-options))
  167. '(:description "l1\nl2\nl3":language "fr" :select-tags ("a" "b" "c")
  168. :title ("a b c"))))
  169. ;; More than one property can refer to the same buffer keyword.
  170. (should
  171. (equal '(:k2 "value" :k1 "value")
  172. (let ((backend (org-export-create-backend
  173. :options '((:k1 "KEYWORD")
  174. (:k2 "KEYWORD")))))
  175. (org-test-with-temp-text "#+KEYWORD: value"
  176. (org-export--get-inbuffer-options backend))))))
  177. (ert-deftest test-org-export/get-subtree-options ()
  178. "Test setting options from headline's properties."
  179. ;; EXPORT_TITLE.
  180. (org-test-with-temp-text "#+TITLE: Title
  181. * Headline
  182. :PROPERTIES:
  183. :EXPORT_TITLE: Subtree Title
  184. :END:
  185. Paragraph"
  186. (forward-line)
  187. (should (equal (plist-get (org-export-get-environment nil t) :title)
  188. '("Subtree Title"))))
  189. :title
  190. '("subtree-title")
  191. ;; EXPORT_OPTIONS.
  192. (org-test-with-temp-text "#+OPTIONS: H:1
  193. * Headline
  194. :PROPERTIES:
  195. :EXPORT_OPTIONS: H:2
  196. :END:
  197. Paragraph"
  198. (forward-line)
  199. (should
  200. (= 2 (plist-get (org-export-get-environment nil t) :headline-levels))))
  201. ;; EXPORT_DATE.
  202. (org-test-with-temp-text "#+DATE: today
  203. * Headline
  204. :PROPERTIES:
  205. :EXPORT_DATE: 29-03-2012
  206. :END:
  207. Paragraph"
  208. (forward-line)
  209. (should (equal (plist-get (org-export-get-environment nil t) :date)
  210. '("29-03-2012"))))
  211. ;; Properties with `split' behaviour are stored as a list of
  212. ;; strings.
  213. (should
  214. (equal '("a" "b")
  215. (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
  216. * Headline
  217. :PROPERTIES:
  218. :EXPORT_EXCLUDE_TAGS: a b
  219. :END:
  220. Paragraph"
  221. (progn
  222. (forward-line)
  223. (plist-get (org-export-get-environment nil t) :exclude-tags)))))
  224. ;; Handle :PROPERTY+: syntax.
  225. (should
  226. (equal '("a" "b")
  227. (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
  228. * Headline
  229. :PROPERTIES:
  230. :EXPORT_EXCLUDE_TAGS: a
  231. :EXPORT_EXCLUDE_TAGS+: b
  232. :END:
  233. Paragraph"
  234. (progn
  235. (forward-line)
  236. (plist-get (org-export-get-environment nil t) :exclude-tags)))))
  237. ;; Export properties are case-insensitive.
  238. (org-test-with-temp-text "* Headline
  239. :PROPERTIES:
  240. :EXPORT_Date: 29-03-2012
  241. :END:
  242. Paragraph"
  243. (should (equal (plist-get (org-export-get-environment nil t) :date)
  244. '("29-03-2012"))))
  245. ;; Still grab correct options when section above is empty.
  246. (should
  247. (equal '("H1")
  248. (org-test-with-temp-text "* H1\n** H11\n** H12"
  249. (progn (forward-line 2)
  250. (plist-get (org-export-get-environment nil t) :title))))))
  251. (ert-deftest test-org-export/set-title ()
  252. "Test title setting."
  253. ;; Without TITLE keyword.
  254. (should
  255. (equal
  256. ""
  257. (org-test-with-temp-text "Test"
  258. (org-export-as
  259. (org-export-create-backend
  260. :transcoders
  261. '((template . (lambda (text info)
  262. (org-element-interpret-data
  263. (plist-get info :title))))))))))
  264. ;; With a blank TITLE keyword.
  265. (should
  266. (equal
  267. ""
  268. (org-test-with-temp-text "#+TITLE:\nTest"
  269. (org-export-as
  270. (org-export-create-backend
  271. :transcoders
  272. '((template . (lambda (text info)
  273. (org-element-interpret-data
  274. (plist-get info :title))))))))))
  275. ;; With a non-empty TITLE keyword.
  276. (should
  277. (equal
  278. "Title"
  279. (org-test-with-temp-text "#+TITLE: Title\nTest"
  280. (org-export-as
  281. (org-export-create-backend
  282. :transcoders
  283. '((template . (lambda (text info)
  284. (org-element-interpret-data
  285. (plist-get info :title))))))))))
  286. ;; When exporting a subtree, its heading becomes the headline of the
  287. ;; document...
  288. (should
  289. (equal
  290. "Headline"
  291. (org-test-with-temp-text "* Headline\nBody"
  292. (org-export-as
  293. (org-export-create-backend
  294. :transcoders
  295. '((template . (lambda (text info)
  296. (org-element-interpret-data
  297. (plist-get info :title))))))
  298. 'subtree))))
  299. ;; ... unless there is an EXPORT_TITLE property at the root of the
  300. ;; subtree.
  301. (should
  302. (equal
  303. "B"
  304. (org-test-with-temp-text
  305. "* A\n :PROPERTIES:\n :EXPORT_TITLE: B\n :END:\nBody"
  306. (org-export-as
  307. (org-export-create-backend
  308. :transcoders
  309. '((template . (lambda (text info)
  310. (org-element-interpret-data
  311. (plist-get info :title))))))
  312. 'subtree)))))
  313. (ert-deftest test-org-export/handle-options ()
  314. "Test if export options have an impact on output."
  315. ;; Test exclude tags for headlines and inlinetasks.
  316. (should
  317. (equal ""
  318. (org-test-with-temp-text "* Head1 :noexp:"
  319. (org-export-as (org-test-default-backend)
  320. nil nil nil '(:exclude-tags ("noexp"))))))
  321. ;; Test include tags for headlines and inlinetasks.
  322. (should
  323. (equal "* H2\n** Sub :exp:\n*** Sub Sub\n"
  324. (org-test-with-temp-text "* H1\n* H2\n** Sub :exp:\n*** Sub Sub\n* H3"
  325. (let ((org-tags-column 0))
  326. (org-export-as (org-test-default-backend)
  327. nil nil nil '(:select-tags ("exp")))))))
  328. ;; If there is an include tag, ignore the section before the first
  329. ;; headline, if any.
  330. (should
  331. (equal "* H1 :exp:\nBody\n"
  332. (org-test-with-temp-text "First section\n* H1 :exp:\nBody"
  333. (let ((org-tags-column 0))
  334. (org-export-as (org-test-default-backend)
  335. nil nil nil '(:select-tags ("exp")))))))
  336. (should-not
  337. (equal "* H1 :exp:\n"
  338. (org-test-with-temp-text "* H1 :exp:\nBody"
  339. (let ((org-tags-column 0))
  340. (org-export-as (org-test-default-backend)
  341. nil nil nil '(:select-tags ("exp")))))))
  342. ;; Test mixing include tags and exclude tags.
  343. (should
  344. (string-match
  345. "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
  346. (org-test-with-temp-text "
  347. * Head1 :export:
  348. ** Sub-Head1 :noexport:
  349. ** Sub-Head2
  350. * Head2 :noexport:
  351. ** Sub-Head1 :export:"
  352. (org-export-as (org-test-default-backend) nil nil nil
  353. '(:select-tags ("export") :exclude-tags ("noexport"))))))
  354. ;; Ignore tasks.
  355. (should
  356. (equal ""
  357. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  358. (org-test-with-temp-text "* TODO Head1"
  359. (org-export-as (org-test-default-backend)
  360. nil nil nil '(:with-tasks nil))))))
  361. (should
  362. (equal "* TODO Head1\n"
  363. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  364. (org-test-with-temp-text "* TODO Head1"
  365. (org-export-as (org-test-default-backend)
  366. nil nil nil '(:with-tasks t))))))
  367. ;; Archived tree.
  368. (should
  369. (equal ""
  370. (org-test-with-temp-text "* Head1 :archive:"
  371. (let ((org-archive-tag "archive"))
  372. (org-export-as (org-test-default-backend)
  373. nil nil nil '(:with-archived-trees nil))))))
  374. (should
  375. (string-match
  376. "\\* Head1[ \t]+:archive:"
  377. (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
  378. (let ((org-archive-tag "archive"))
  379. (org-export-as (org-test-default-backend) nil nil nil
  380. '(:with-archived-trees headline))))))
  381. (should
  382. (string-match
  383. "\\`\\* Head1[ \t]+:archive:\n\\'"
  384. (org-test-with-temp-text "* Head1 :archive:"
  385. (let ((org-archive-tag "archive"))
  386. (org-export-as (org-test-default-backend)
  387. nil nil nil '(:with-archived-trees t))))))
  388. ;; Clocks.
  389. (should
  390. (string-match "CLOCK: \\[2012-04-29 .* 10:45\\]"
  391. (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
  392. (org-export-as (org-test-default-backend)
  393. nil nil nil '(:with-clocks t)))))
  394. (should
  395. (equal ""
  396. (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
  397. (org-export-as (org-test-default-backend)
  398. nil nil nil '(:with-clocks nil)))))
  399. ;; Drawers.
  400. (should
  401. (equal ""
  402. (org-test-with-temp-text ":TEST:\ncontents\n:END:"
  403. (org-export-as (org-test-default-backend)
  404. nil nil nil '(:with-drawers nil)))))
  405. (should
  406. (equal ":TEST:\ncontents\n:END:\n"
  407. (org-test-with-temp-text ":TEST:\ncontents\n:END:"
  408. (org-export-as (org-test-default-backend)
  409. nil nil nil '(:with-drawers t)))))
  410. (should
  411. (equal ":FOO:\nkeep\n:END:\n"
  412. (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
  413. (org-export-as (org-test-default-backend)
  414. nil nil nil '(:with-drawers ("FOO"))))))
  415. (should
  416. (equal ":FOO:\nkeep\n:END:\n"
  417. (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
  418. (org-export-as (org-test-default-backend)
  419. nil nil nil '(:with-drawers (not "BAR"))))))
  420. ;; Fixed-width.
  421. (should
  422. (equal ": A\n"
  423. (org-test-with-temp-text ": A"
  424. (org-export-as (org-test-default-backend) nil nil nil
  425. '(:with-fixed-width t)))))
  426. (should
  427. (equal ""
  428. (org-test-with-temp-text ": A"
  429. (org-export-as (org-test-default-backend) nil nil nil
  430. '(:with-fixed-width nil)))))
  431. ;; Footnotes.
  432. (should
  433. (equal "Footnote?"
  434. (let ((org-footnote-section nil))
  435. (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
  436. (org-trim (org-export-as (org-test-default-backend)
  437. nil nil nil '(:with-footnotes nil)))))))
  438. (should
  439. (equal "Footnote?[fn:1]\n\n[fn:1] Def"
  440. (let ((org-footnote-section nil))
  441. (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
  442. (org-trim (org-export-as (org-test-default-backend)
  443. nil nil nil '(:with-footnotes t)))))))
  444. ;; Inlinetasks.
  445. (when (featurep 'org-inlinetask)
  446. (should
  447. (equal
  448. ""
  449. (let ((org-inlinetask-min-level 15))
  450. (org-test-with-temp-text "*************** Task"
  451. (org-export-as (org-test-default-backend)
  452. nil nil nil '(:with-inlinetasks nil))))))
  453. (should
  454. (equal
  455. ""
  456. (let ((org-inlinetask-min-level 15))
  457. (org-test-with-temp-text
  458. "*************** Task\nContents\n*************** END"
  459. (org-export-as (org-test-default-backend)
  460. nil nil nil '(:with-inlinetasks nil)))))))
  461. ;; Plannings.
  462. (should
  463. (string-match
  464. "* H\nCLOSED: \\[2012-04-29 .* 10:45\\]"
  465. (let ((org-closed-string "CLOSED:"))
  466. (org-test-with-temp-text "* H\nCLOSED: [2012-04-29 sun. 10:45]"
  467. (org-export-as (org-test-default-backend)
  468. nil nil nil '(:with-planning t))))))
  469. (should
  470. (equal "* H\n"
  471. (let ((org-closed-string "CLOSED:"))
  472. (org-test-with-temp-text "* H\nCLOSED: [2012-04-29 sun. 10:45]"
  473. (org-export-as (org-test-default-backend)
  474. nil nil nil '(:with-planning nil))))))
  475. ;; Property Drawers.
  476. (should
  477. (equal "* H1\n"
  478. (org-test-with-temp-text
  479. "* H1\n :PROPERTIES:\n :PROP: value\n :END:"
  480. (org-export-as (org-test-default-backend)
  481. nil nil nil '(:with-properties nil)))))
  482. (should
  483. (equal "* H1\n:PROPERTIES:\n:PROP: value\n:END:\n"
  484. (org-test-with-temp-text
  485. "* H1\n :PROPERTIES:\n :PROP: value\n :END:"
  486. (org-export-as (org-test-default-backend)
  487. nil nil nil '(:with-properties t)))))
  488. (should
  489. (equal "* H1\n:PROPERTIES:\n:B: 2\n:END:\n"
  490. (org-test-with-temp-text
  491. "* H1\n :PROPERTIES:\n :A: 1\n :B: 2\n:END:"
  492. (org-export-as (org-test-default-backend)
  493. nil nil nil '(:with-properties ("B"))))))
  494. ;; Statistics cookies.
  495. (should
  496. (equal ""
  497. (org-test-with-temp-text "[0/0]"
  498. (org-export-as (org-test-default-backend)
  499. nil nil nil '(:with-statistics-cookies nil)))))
  500. ;; Tables.
  501. (should
  502. (equal "| A |\n"
  503. (org-test-with-temp-text "| A |"
  504. (org-export-as (org-test-default-backend) nil nil nil
  505. '(:with-tables t)))))
  506. (should
  507. (equal ""
  508. (org-test-with-temp-text "| A |"
  509. (org-export-as (org-test-default-backend) nil nil nil
  510. '(:with-tables nil))))))
  511. (ert-deftest test-org-export/with-timestamps ()
  512. "Test `org-export-with-timestamps' specifications."
  513. ;; t value.
  514. (should
  515. (string-match
  516. "\\[2012-04-29 .*? 10:45\\]<2012-04-29 .*? 10:45>"
  517. (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
  518. (org-export-as (org-test-default-backend)
  519. nil nil nil '(:with-timestamps t)))))
  520. ;; nil value.
  521. (should
  522. (equal
  523. ""
  524. (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
  525. (org-export-as (org-test-default-backend)
  526. nil nil nil '(:with-timestamps nil)))))
  527. ;; `active' value.
  528. (should
  529. (string-match
  530. "<2012-03-29 .*?>\n\nParagraph <2012-03-29 .*?>\\[2012-03-29 .*?\\]"
  531. (org-test-with-temp-text
  532. "<2012-03-29 Thu>[2012-03-29 Thu]
  533. Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
  534. (org-export-as (org-test-default-backend)
  535. nil nil nil '(:with-timestamps active)))))
  536. ;; `inactive' value.
  537. (should
  538. (string-match
  539. "\\[2012-03-29 .*?\\]\n\nParagraph <2012-03-29 .*?>\\[2012-03-29 .*?\\]"
  540. (org-test-with-temp-text
  541. "<2012-03-29 Thu>[2012-03-29 Thu]
  542. Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
  543. (org-export-as (org-test-default-backend)
  544. nil nil nil '(:with-timestamps inactive))))))
  545. (ert-deftest test-org-export/comment-tree ()
  546. "Test if export process ignores commented trees."
  547. (should
  548. (equal ""
  549. (org-test-with-temp-text "* COMMENT Head1"
  550. (org-export-as (org-test-default-backend))))))
  551. (ert-deftest test-org-export/uninterpreted ()
  552. "Test handling of uninterpreted elements."
  553. ;; Entities.
  554. (should
  555. (equal "dummy\n"
  556. (org-test-with-temp-text "\\alpha"
  557. (org-export-as
  558. (org-export-create-backend
  559. :transcoders '((entity . (lambda (e c i) "dummy"))
  560. (paragraph . (lambda (p c i) c))
  561. (section . (lambda (s c i) c))))
  562. nil nil nil '(:with-entities t)))))
  563. (should
  564. (equal "\\alpha\n"
  565. (org-test-with-temp-text "\\alpha"
  566. (org-export-as
  567. (org-export-create-backend
  568. :transcoders '((entity . (lambda (e c i) "dummy"))
  569. (paragraph . (lambda (p c i) c))
  570. (section . (lambda (s c i) c))))
  571. nil nil nil '(:with-entities nil)))))
  572. ;; Emphasis.
  573. (should
  574. (equal "dummy\n"
  575. (org-test-with-temp-text "*bold*"
  576. (org-export-as
  577. (org-export-create-backend
  578. :transcoders '((bold . (lambda (b c i) "dummy"))
  579. (paragraph . (lambda (p c i) c))
  580. (section . (lambda (s c i) c))))
  581. nil nil nil '(:with-emphasize t)))))
  582. (should
  583. (equal "*bold*\n"
  584. (org-test-with-temp-text "*bold*"
  585. (org-export-as
  586. (org-export-create-backend
  587. :transcoders '((bold . (lambda (b c i) "dummy"))
  588. (paragraph . (lambda (p c i) c))
  589. (section . (lambda (s c i) c))))
  590. nil nil nil '(:with-emphasize nil)))))
  591. ;; LaTeX environment.
  592. (should
  593. (equal "dummy\n"
  594. (org-test-with-temp-text "\\begin{equation}\n1+1=2\n\\end{equation}"
  595. (org-export-as
  596. (org-export-create-backend
  597. :transcoders '((latex-environment . (lambda (l c i) "dummy"))
  598. (section . (lambda (s c i) c))))
  599. nil nil nil '(:with-latex t)))))
  600. (should
  601. (equal "\\begin{equation}\n1+1=2\n\\end{equation}\n"
  602. (org-test-with-temp-text "\\begin{equation}\n1+1=2\n\\end{equation}"
  603. (org-export-as
  604. (org-export-create-backend
  605. :transcoders '((latex-environment . (lambda (l c i) "dummy"))
  606. (section . (lambda (s c i) c))))
  607. nil nil nil '(:with-latex verbatim)))))
  608. ;; LaTeX fragment.
  609. (should
  610. (equal "dummy\n"
  611. (org-test-with-temp-text "$1$"
  612. (org-export-as
  613. (org-export-create-backend
  614. :transcoders '((latex-fragment . (lambda (l c i) "dummy"))
  615. (paragraph . (lambda (p c i) c))
  616. (section . (lambda (s c i) c))))
  617. nil nil nil '(:with-latex t)))))
  618. (should
  619. (equal "$1$\n"
  620. (org-test-with-temp-text "$1$"
  621. (org-export-as
  622. (org-export-create-backend
  623. :transcoders '((latex-fragment . (lambda (l c i) "dummy"))
  624. (paragraph . (lambda (p c i) c))
  625. (section . (lambda (s c i) c))))
  626. nil nil nil '(:with-latex verbatim)))))
  627. ;; Sub/superscript.
  628. (should
  629. (equal "adummy\n"
  630. (org-test-with-temp-text "a_b"
  631. (org-export-as
  632. (org-export-create-backend
  633. :transcoders '((subscript . (lambda (s c i) "dummy"))
  634. (paragraph . (lambda (p c i) c))
  635. (section . (lambda (s c i) c))))
  636. nil nil nil '(:with-sub-superscript t)))))
  637. (should
  638. (equal "a_b\n"
  639. (org-test-with-temp-text "a_b"
  640. (org-export-as
  641. (org-export-create-backend
  642. :transcoders '((subscript . (lambda (s c i) "dummy"))
  643. (paragraph . (lambda (p c i) c))
  644. (section . (lambda (s c i) c))))
  645. nil nil nil '(:with-sub-superscript nil)))))
  646. (should
  647. (equal "a_b\n"
  648. (org-test-with-temp-text "a_b"
  649. (org-export-as
  650. (org-export-create-backend
  651. :transcoders '((subscript . (lambda (s c i) "dummy"))
  652. (paragraph . (lambda (p c i) c))
  653. (section . (lambda (s c i) c))))
  654. nil nil nil '(:with-sub-superscript {})))))
  655. (should
  656. (equal "adummy\n"
  657. (org-test-with-temp-text "a_{b}"
  658. (org-export-as
  659. (org-export-create-backend
  660. :transcoders '((subscript . (lambda (s c i) "dummy"))
  661. (paragraph . (lambda (p c i) c))
  662. (section . (lambda (s c i) c))))
  663. nil nil nil '(:with-sub-superscript {})))))
  664. ;; Also handle uninterpreted objects in title.
  665. (should
  666. (equal "a_b"
  667. (org-test-with-temp-text "#+TITLE: a_b"
  668. (org-export-as
  669. (org-export-create-backend
  670. :transcoders
  671. '((subscript . (lambda (s c i) "dummy"))
  672. (template . (lambda (c i) (org-export-data
  673. (plist-get i :title) i)))
  674. (section . (lambda (s c i) c))))
  675. nil nil nil '(:with-sub-superscript nil)))))
  676. ;; Special case: multiples uninterpreted objects in a row.
  677. (should
  678. (equal "a_b_c_d\n"
  679. (org-test-with-temp-text "a_b_c_d"
  680. (org-export-as
  681. (org-export-create-backend
  682. :transcoders '((subscript . (lambda (s c i) "dummy"))
  683. (paragraph . (lambda (p c i) c))
  684. (section . (lambda (s c i) c))))
  685. nil nil nil '(:with-sub-superscript {}))))))
  686. (ert-deftest test-org-export/export-scope ()
  687. "Test all export scopes."
  688. (org-test-with-temp-text "
  689. * Head1
  690. ** Head2
  691. text
  692. *** Head3"
  693. ;; Subtree.
  694. (forward-line 3)
  695. (should (equal (org-export-as (org-test-default-backend) 'subtree)
  696. "text\n*** Head3\n"))
  697. ;; Visible.
  698. (goto-char (point-min))
  699. (forward-line)
  700. (org-cycle)
  701. (should (equal (org-export-as (org-test-default-backend) nil 'visible)
  702. "* Head1\n"))
  703. ;; Region.
  704. (goto-char (point-min))
  705. (forward-line 3)
  706. (transient-mark-mode 1)
  707. (push-mark (point) t t)
  708. (goto-char (point-at-eol))
  709. (should (equal (org-export-as (org-test-default-backend)) "text\n")))
  710. ;; Subtree with a code block calling another block outside.
  711. (should
  712. (equal ": 3\n"
  713. (org-test-with-temp-text "
  714. * Head1
  715. #+BEGIN_SRC emacs-lisp :noweb yes :exports results
  716. <<test>>
  717. #+END_SRC
  718. * Head2
  719. #+NAME: test
  720. #+BEGIN_SRC emacs-lisp
  721. \(+ 1 2)
  722. #+END_SRC"
  723. (forward-line 1)
  724. (org-export-as (org-test-default-backend) 'subtree))))
  725. ;; Body only.
  726. (let ((backend (org-test-default-backend)))
  727. (setf (org-export-backend-transcoders backend)
  728. (cons '(template . (lambda (body i)
  729. (format "BEGIN\n%sEND" body)))
  730. (org-export-backend-transcoders backend)))
  731. (org-test-with-temp-text "Text"
  732. (should (equal (org-export-as backend nil nil 'body-only)
  733. "Text\n"))
  734. (should (equal (org-export-as backend) "BEGIN\nText\nEND")))))
  735. (ert-deftest test-org-export/output-file-name ()
  736. "Test `org-export-output-file-name' specifications."
  737. ;; Export from a file: name is built from original file name.
  738. (should
  739. (org-test-with-temp-text-in-file "Test"
  740. (equal (concat (file-name-as-directory ".")
  741. (file-name-nondirectory
  742. (file-name-sans-extension (buffer-file-name))))
  743. (file-name-sans-extension (org-export-output-file-name ".ext")))))
  744. ;; When exporting to subtree, check EXPORT_FILE_NAME property first.
  745. (should
  746. (org-test-with-temp-text-in-file
  747. "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
  748. (equal (org-export-output-file-name ".ext" t) "./test.ext")))
  749. ;; From a buffer not associated to a file, too.
  750. (should
  751. (org-test-with-temp-text
  752. "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
  753. (equal (org-export-output-file-name ".ext" t) "./test.ext")))
  754. ;; When provided name is absolute, preserve it.
  755. (should
  756. (org-test-with-temp-text
  757. (format "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: %s\n :END:"
  758. (expand-file-name "test"))
  759. (file-name-absolute-p (org-export-output-file-name ".ext" t))))
  760. ;; When PUB-DIR argument is provided, use it.
  761. (should
  762. (org-test-with-temp-text-in-file "Test"
  763. (equal (file-name-directory
  764. (org-export-output-file-name ".ext" nil "dir/"))
  765. "dir/")))
  766. ;; When returned name would overwrite original file, add EXTENSION
  767. ;; another time.
  768. (should
  769. (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
  770. (equal (org-export-output-file-name ".org") "./normal.org.org"))))
  771. (ert-deftest test-org-export/expand-include ()
  772. "Test file inclusion in an Org buffer."
  773. ;; Error when file isn't specified.
  774. (should-error
  775. (org-test-with-temp-text "#+INCLUDE: dummy.org"
  776. (org-export-expand-include-keyword)))
  777. ;; Full insertion with recursive inclusion.
  778. (should
  779. (equal
  780. (with-temp-buffer
  781. (insert-file
  782. (expand-file-name "examples/include.org" org-test-dir))
  783. (replace-regexp-in-string
  784. (regexp-quote "#+INCLUDE: \"include2.org\"")
  785. "Success!" (buffer-string)))
  786. (org-test-with-temp-text
  787. (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir)
  788. (org-export-expand-include-keyword)
  789. (buffer-string))))
  790. ;; Localized insertion.
  791. (org-test-with-temp-text
  792. (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
  793. org-test-dir)
  794. (org-export-expand-include-keyword)
  795. (should (equal (buffer-string)
  796. "Small Org file with an include keyword.\n")))
  797. ;; Insertion with constraints on headlines level.
  798. (should
  799. (equal
  800. "* Top heading\n** Heading\nbody\n"
  801. (org-test-with-temp-text
  802. (format
  803. "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-11\""
  804. org-test-dir)
  805. (org-export-expand-include-keyword)
  806. (buffer-string))))
  807. (should
  808. (equal
  809. "* Top heading\n* Heading\nbody\n"
  810. (org-test-with-temp-text
  811. (format
  812. "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-11\" :minlevel 1"
  813. org-test-dir)
  814. (org-export-expand-include-keyword)
  815. (buffer-string))))
  816. ;; Inclusion within an example block.
  817. (should
  818. (equal
  819. "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n"
  820. (org-test-with-temp-text
  821. (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" EXAMPLE"
  822. org-test-dir)
  823. (org-export-expand-include-keyword)
  824. (buffer-string))))
  825. ;; Inclusion within a src-block.
  826. (should
  827. (equal
  828. "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"
  829. (org-test-with-temp-text
  830. (format
  831. "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" SRC emacs-lisp"
  832. org-test-dir)
  833. (org-export-expand-include-keyword)
  834. (buffer-string))))
  835. ;; Inclusion within an html export-block.
  836. (should
  837. (equal
  838. "#+BEGIN_HTML\n<p>HTML!</p>\n#+END_HTML\n"
  839. (org-test-with-temp-text
  840. (format
  841. "#+INCLUDE: \"%s/examples/include.html\" HTML"
  842. org-test-dir)
  843. (org-export-expand-include-keyword)
  844. (buffer-string))))
  845. ;; Inclusion within an center paragraph
  846. (should
  847. (equal
  848. "#+BEGIN_CENTER\nSuccess!\n#+END_CENTER\n"
  849. (org-test-with-temp-text
  850. (format
  851. "#+INCLUDE: \"%s/examples/include2.org\" CENTER"
  852. org-test-dir)
  853. (org-export-expand-include-keyword)
  854. (buffer-string))))
  855. ;; Footnotes labels are local to each included file.
  856. (should
  857. (= 6
  858. (length
  859. (delete-dups
  860. (let ((contents "
  861. Footnotes[fn:1], [fn:test] and [fn:inline:anonymous footnote].
  862. \[fn:1] Footnote 1
  863. \[fn:test] Footnote \"test\""))
  864. (org-test-with-temp-text-in-file contents
  865. (let ((file1 (buffer-file-name)))
  866. (org-test-with-temp-text-in-file contents
  867. (let ((file2 (buffer-file-name)))
  868. (org-test-with-temp-text
  869. (format "#+INCLUDE: \"%s\"\n#+INCLUDE: \"%s\""
  870. file1 file2)
  871. (org-export-expand-include-keyword)
  872. (org-element-map (org-element-parse-buffer)
  873. 'footnote-reference
  874. (lambda (ref)
  875. (org-element-property :label ref)))))))))))))
  876. ;; Footnotes labels are not local to each include keyword.
  877. (should
  878. (= 3
  879. (length
  880. (delete-dups
  881. (let ((contents "
  882. Footnotes[fn:1], [fn:test] and [fn:inline:anonymous footnote].
  883. \[fn:1] Footnote 1
  884. \[fn:test] Footnote \"test\""))
  885. (org-test-with-temp-text-in-file contents
  886. (let ((file (buffer-file-name)))
  887. (org-test-with-temp-text
  888. (format "#+INCLUDE: \"%s\"\n#+INCLUDE: \"%s\"" file file)
  889. (org-export-expand-include-keyword)
  890. (org-element-map (org-element-parse-buffer)
  891. 'footnote-reference
  892. (lambda (ref) (org-element-property :label ref)))))))))))
  893. ;; If only-contents is non-nil only include contents of element.
  894. (should
  895. (equal
  896. "body\n"
  897. (org-test-with-temp-text
  898. (concat
  899. (format "#+INCLUDE: \"%s/examples/include.org::*Heading\" " org-test-dir)
  900. ":only-contents t")
  901. (org-export-expand-include-keyword)
  902. (buffer-string))))
  903. ;; Headings can be included via CUSTOM_ID.
  904. (should
  905. (org-test-with-temp-text
  906. (format "#+INCLUDE: \"%s/examples/include.org::#ah\"" org-test-dir)
  907. (org-export-expand-include-keyword)
  908. (goto-char (point-min))
  909. (looking-at "* Another heading")))
  910. ;; Named objects can be included.
  911. (should
  912. (equal
  913. "| 1 |\n"
  914. (org-test-with-temp-text
  915. (format "#+INCLUDE: \"%s/examples/include.org::tbl\" :only-contents t" org-test-dir)
  916. (org-export-expand-include-keyword)
  917. (buffer-string))))
  918. ;; Including non-existing elements should result in an error.
  919. (should-error
  920. (org-test-with-temp-text
  921. (format "#+INCLUDE: \"%s/examples/include.org::*non-existing heading\"" org-test-dir)
  922. (org-export-expand-include-keyword)))
  923. ;; Lines work relatively to an included element.
  924. (should
  925. (equal
  926. "2\n3\n"
  927. (org-test-with-temp-text
  928. (format "#+INCLUDE: \"%s/examples/include.org::#ah\" :only-contents t :lines \"2-3\"" org-test-dir)
  929. (org-export-expand-include-keyword)
  930. (buffer-string))))
  931. ;; Properties should be dropped from headlines.
  932. (should
  933. (equal
  934. (org-test-with-temp-text
  935. (format "#+INCLUDE: \"%s/examples/include.org::#ht\" :only-contents t" org-test-dir)
  936. (org-export-expand-include-keyword)
  937. (buffer-string))
  938. (org-test-with-temp-text
  939. (format "#+INCLUDE: \"%s/examples/include.org::tbl\"" org-test-dir)
  940. (org-export-expand-include-keyword)
  941. (buffer-string))))
  942. ;; Properties should be dropped, drawers should not be.
  943. (should
  944. (equal
  945. ":LOGBOOK:\ndrawer\n:END:\ncontent\n"
  946. (org-test-with-temp-text
  947. (format "#+INCLUDE: \"%s/examples/include.org::#dh\" :only-contents t" org-test-dir)
  948. (org-export-expand-include-keyword)
  949. (buffer-string)))))
  950. (ert-deftest test-org-export/expand-macro ()
  951. "Test macro expansion in an Org buffer."
  952. ;; Standard macro expansion.
  953. (should
  954. (equal "#+MACRO: macro1 value\nvalue\n"
  955. (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
  956. (org-export-as (org-test-default-backend)))))
  957. ;; Expand specific macros.
  958. (should
  959. (equal "me 2012-03-29 me@here Title\n"
  960. (org-test-with-temp-text
  961. "
  962. #+TITLE: Title
  963. #+DATE: 2012-03-29
  964. #+AUTHOR: me
  965. #+EMAIL: me@here
  966. {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
  967. (let ((output (org-export-as (org-test-default-backend))))
  968. (substring output (string-match ".*\n\\'" output))))))
  969. ;; Expand specific macros when property contained a regular macro
  970. ;; already.
  971. (should
  972. (equal "value\n"
  973. (org-test-with-temp-text "
  974. #+MACRO: macro1 value
  975. #+TITLE: {{{macro1}}}
  976. {{{title}}}"
  977. (let ((output (org-export-as (org-test-default-backend))))
  978. (substring output (string-match ".*\n\\'" output))))))
  979. ;; Expand macros with templates in included files.
  980. (should
  981. (equal "success\n"
  982. (org-test-with-temp-text
  983. (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
  984. {{{included-macro}}}" org-test-dir)
  985. (let ((output (org-export-as (org-test-default-backend))))
  986. (substring output (string-match ".*\n\\'" output)))))))
  987. (ert-deftest test-org-export/user-ignore-list ()
  988. "Test if `:ignore-list' accepts user input."
  989. (let ((backend (org-test-default-backend)))
  990. (setf (org-export-backend-transcoders backend)
  991. (cons '(template . (lambda (body i)
  992. (format "BEGIN\n%sEND" body)))
  993. (org-export-backend-transcoders backend)))
  994. (org-test-with-temp-text "Text"
  995. (should (equal (org-export-as backend nil nil 'body-only)
  996. "Text\n"))
  997. (should (equal (org-export-as backend) "BEGIN\nText\nEND"))))
  998. (should
  999. (equal
  1000. "* Head1\n"
  1001. (let ((org-export-filter-parse-tree-functions
  1002. '((lambda (data backend info)
  1003. ;; Ignore headlines with the word "note" in their title.
  1004. (org-element-map data 'headline
  1005. (lambda (headline)
  1006. (when (string-match "\\<note\\>"
  1007. (org-element-property :raw-value
  1008. headline))
  1009. (org-export-ignore-element headline info)))
  1010. info)
  1011. data))))
  1012. (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
  1013. (org-export-as (org-test-default-backend)))))))
  1014. (ert-deftest test-org-export/before-processing-hook ()
  1015. "Test `org-export-before-processing-hook'."
  1016. (should
  1017. (equal
  1018. "#+MACRO: mac val\nTest\n"
  1019. (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
  1020. (let ((org-export-before-processing-hook
  1021. '((lambda (backend)
  1022. (while (re-search-forward "{{{" nil t)
  1023. (let ((object (org-element-context)))
  1024. (when (eq (org-element-type object) 'macro)
  1025. (delete-region
  1026. (org-element-property :begin object)
  1027. (org-element-property :end object)))))))))
  1028. (org-export-as (org-test-default-backend)))))))
  1029. (ert-deftest test-org-export/before-parsing-hook ()
  1030. "Test `org-export-before-parsing-hook'."
  1031. (should
  1032. (equal "Body 1\nBody 2\n"
  1033. (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
  1034. (let ((org-export-before-parsing-hook
  1035. '((lambda (backend)
  1036. (goto-char (point-min))
  1037. (while (re-search-forward org-outline-regexp-bol nil t)
  1038. (delete-region
  1039. (point-at-bol) (progn (forward-line) (point))))))))
  1040. (org-export-as (org-test-default-backend)))))))
  1041. ;;; Affiliated Keywords
  1042. (ert-deftest test-org-export/read-attribute ()
  1043. "Test `org-export-read-attribute' specifications."
  1044. ;; Standard test.
  1045. (should
  1046. (equal
  1047. (org-export-read-attribute
  1048. :attr_html
  1049. (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
  1050. (org-element-at-point)))
  1051. '(:a "1" :b "2")))
  1052. ;; Return nil on empty attribute.
  1053. (should-not
  1054. (org-export-read-attribute
  1055. :attr_html
  1056. (org-test-with-temp-text "Paragraph" (org-element-at-point))))
  1057. ;; Return nil on "nil" string.
  1058. (should
  1059. (equal '(:a nil :b nil)
  1060. (org-export-read-attribute
  1061. :attr_html
  1062. (org-test-with-temp-text "#+ATTR_HTML: :a nil :b nil\nParagraph"
  1063. (org-element-at-point)))))
  1064. ;; Return nil on empty string.
  1065. (should
  1066. (equal '(:a nil :b nil)
  1067. (org-export-read-attribute
  1068. :attr_html
  1069. (org-test-with-temp-text "#+ATTR_HTML: :a :b\nParagraph"
  1070. (org-element-at-point)))))
  1071. ;; Return empty string when value is "".
  1072. (should
  1073. (equal '(:a "")
  1074. (org-export-read-attribute
  1075. :attr_html
  1076. (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\nParagraph"
  1077. (org-element-at-point)))))
  1078. ;; Return \"\" when value is """".
  1079. (should
  1080. (equal '(:a "\"\"")
  1081. (org-export-read-attribute
  1082. :attr_html
  1083. (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\"\"\nParagraph"
  1084. (org-element-at-point)))))
  1085. ;; Ignore text before first property.
  1086. (should-not
  1087. (member "ignore"
  1088. (org-export-read-attribute
  1089. :attr_html
  1090. (org-test-with-temp-text "#+ATTR_HTML: ignore :a 1\nParagraph"
  1091. (org-element-at-point))))))
  1092. (ert-deftest test-org-export/get-caption ()
  1093. "Test `org-export-get-caption' specifications."
  1094. ;; Without optional argument, return long caption
  1095. (should
  1096. (equal
  1097. '("l")
  1098. (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
  1099. (org-export-get-caption (org-element-at-point)))))
  1100. ;; With optional argument, return short caption.
  1101. (should
  1102. (equal
  1103. '("s")
  1104. (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
  1105. (org-export-get-caption (org-element-at-point) t))))
  1106. ;; Multiple lines are separated by white spaces.
  1107. (should
  1108. (equal
  1109. '("a" " " "b")
  1110. (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
  1111. (org-export-get-caption (org-element-at-point))))))
  1112. ;;; Back-End Tools
  1113. (ert-deftest test-org-export/define-backend ()
  1114. "Test back-end definition and accessors."
  1115. ;; Translate table.
  1116. (should
  1117. (equal '((headline . my-headline-test))
  1118. (let (org-export--registered-backends)
  1119. (org-export-define-backend 'test '((headline . my-headline-test)))
  1120. (org-export-get-all-transcoders 'test))))
  1121. ;; Filters.
  1122. (should
  1123. (equal '((:filter-headline . my-filter))
  1124. (let (org-export--registered-backends)
  1125. (org-export-define-backend 'test
  1126. '((headline . my-headline-test))
  1127. :filters-alist '((:filter-headline . my-filter)))
  1128. (org-export-backend-filters (org-export-get-backend 'test)))))
  1129. ;; Options.
  1130. (should
  1131. (equal '((:prop value))
  1132. (let (org-export--registered-backends)
  1133. (org-export-define-backend 'test
  1134. '((headline . my-headline-test))
  1135. :options-alist '((:prop value)))
  1136. (org-export-backend-options (org-export-get-backend 'test)))))
  1137. ;; Menu.
  1138. (should
  1139. (equal '(?k "Test Export" test)
  1140. (let (org-export--registered-backends)
  1141. (org-export-define-backend 'test
  1142. '((headline . my-headline-test))
  1143. :menu-entry '(?k "Test Export" test))
  1144. (org-export-backend-menu (org-export-get-backend 'test)))))
  1145. ;; Export Blocks.
  1146. (should
  1147. (equal '(("TEST" . org-element-export-block-parser))
  1148. (let (org-export--registered-backends org-element-block-name-alist)
  1149. (org-export-define-backend 'test
  1150. '((headline . my-headline-test))
  1151. :export-block '("test"))
  1152. org-element-block-name-alist))))
  1153. (ert-deftest test-org-export/define-derived-backend ()
  1154. "Test `org-export-define-derived-backend' specifications."
  1155. ;; Error when parent back-end is not defined.
  1156. (should-error
  1157. (let (org-export--registered-backends)
  1158. (org-export-define-derived-backend 'test 'parent)))
  1159. ;; Append translation table to parent's.
  1160. (should
  1161. (equal '((:headline . test) (:headline . parent))
  1162. (let (org-export--registered-backends)
  1163. (org-export-define-backend 'parent '((:headline . parent)))
  1164. (org-export-define-derived-backend 'test 'parent
  1165. :translate-alist '((:headline . test)))
  1166. (org-export-get-all-transcoders 'test))))
  1167. ;; Options defined in the new back have priority over those defined
  1168. ;; in parent.
  1169. (should
  1170. (eq 'test
  1171. (let (org-export--registered-backends)
  1172. (org-export-define-backend 'parent
  1173. '((:headline . parent))
  1174. :options-alist '((:a nil nil 'parent)))
  1175. (org-export-define-derived-backend 'test 'parent
  1176. :options-alist '((:a nil nil 'test)))
  1177. (plist-get (org-export--get-global-options
  1178. (org-export-get-backend 'test))
  1179. :a)))))
  1180. (ert-deftest test-org-export/derived-backend-p ()
  1181. "Test `org-export-derived-backend-p' specifications."
  1182. ;; Non-nil with direct match.
  1183. (should
  1184. (let (org-export--registered-backends)
  1185. (org-export-define-backend 'test '((headline . test)))
  1186. (org-export-derived-backend-p 'test 'test)))
  1187. (should
  1188. (let (org-export--registered-backends)
  1189. (org-export-define-backend 'test '((headline . test)))
  1190. (org-export-define-derived-backend 'test2 'test)
  1191. (org-export-derived-backend-p 'test2 'test2)))
  1192. ;; Non-nil with a direct parent.
  1193. (should
  1194. (let (org-export--registered-backends)
  1195. (org-export-define-backend 'test '((headline . test)))
  1196. (org-export-define-derived-backend 'test2 'test)
  1197. (org-export-derived-backend-p 'test2 'test)))
  1198. ;; Non-nil with an indirect parent.
  1199. (should
  1200. (let (org-export--registered-backends)
  1201. (org-export-define-backend 'test '((headline . test)))
  1202. (org-export-define-derived-backend 'test2 'test)
  1203. (org-export-define-derived-backend 'test3 'test2)
  1204. (org-export-derived-backend-p 'test3 'test)))
  1205. ;; Nil otherwise.
  1206. (should-not
  1207. (let (org-export--registered-backends)
  1208. (org-export-define-backend 'test '((headline . test)))
  1209. (org-export-define-backend 'test2 '((headline . test2)))
  1210. (org-export-derived-backend-p 'test2 'test)))
  1211. (should-not
  1212. (let (org-export--registered-backends)
  1213. (org-export-define-backend 'test '((headline . test)))
  1214. (org-export-define-backend 'test2 '((headline . test2)))
  1215. (org-export-define-derived-backend 'test3 'test2)
  1216. (org-export-derived-backend-p 'test3 'test))))
  1217. (ert-deftest test-org-export/get-all-transcoders ()
  1218. "Test `org-export-get-all-transcoders' specifications."
  1219. ;; Return nil when back-end cannot be found.
  1220. (should-not (org-export-get-all-transcoders nil))
  1221. ;; Same as `org-export-transcoders' if no parent.
  1222. (should
  1223. (equal '((headline . ignore))
  1224. (org-export-get-all-transcoders
  1225. (org-export-create-backend
  1226. :transcoders '((headline . ignore))))))
  1227. ;; But inherit from all ancestors whenever possible.
  1228. (should
  1229. (equal '((section . ignore) (headline . ignore))
  1230. (let (org-export--registered-backends)
  1231. (org-export-define-backend 'b1 '((headline . ignore)))
  1232. (org-export-get-all-transcoders
  1233. (org-export-create-backend
  1234. :parent 'b1 :transcoders '((section . ignore)))))))
  1235. (should
  1236. (equal '((paragraph . ignore) (section . ignore) (headline . ignore))
  1237. (let (org-export--registered-backends)
  1238. (org-export-define-backend 'b1 '((headline . ignore)))
  1239. (org-export-define-derived-backend 'b2 'b1
  1240. :translate-alist '((section . ignore)))
  1241. (org-export-get-all-transcoders
  1242. (org-export-create-backend
  1243. :parent 'b2 :transcoders '((paragraph . ignore)))))))
  1244. ;; Back-end transcoders overrule inherited ones.
  1245. (should
  1246. (eq 'b
  1247. (let (org-export--registered-backends)
  1248. (org-export-define-backend 'b1 '((headline . a)))
  1249. (cdr (assq 'headline
  1250. (org-export-get-all-transcoders
  1251. (org-export-create-backend
  1252. :parent 'b1 :transcoders '((headline . b))))))))))
  1253. (ert-deftest test-org-export/get-all-options ()
  1254. "Test `org-export-get-all-options' specifications."
  1255. ;; Return nil when back-end cannot be found.
  1256. (should-not (org-export-get-all-options nil))
  1257. ;; Same as `org-export-options' if no parent.
  1258. (should
  1259. (equal '((headline . ignore))
  1260. (org-export-get-all-options
  1261. (org-export-create-backend
  1262. :options '((headline . ignore))))))
  1263. ;; But inherit from all ancestors whenever possible.
  1264. (should
  1265. (equal '((:key2 value2) (:key1 value1))
  1266. (let (org-export--registered-backends)
  1267. (org-export-define-backend 'b1 nil :options-alist '((:key1 value1)))
  1268. (org-export-get-all-options
  1269. (org-export-create-backend
  1270. :parent 'b1 :options '((:key2 value2)))))))
  1271. (should
  1272. (equal '((:key3 value3) (:key2 value2) (:key1 value1))
  1273. (let (org-export--registered-backends)
  1274. (org-export-define-backend 'b1 nil :options-alist '((:key1 value1)))
  1275. (org-export-define-derived-backend 'b2 'b1
  1276. :options-alist '((:key2 value2)))
  1277. (org-export-get-all-options
  1278. (org-export-create-backend
  1279. :parent 'b2 :options '((:key3 value3)))))))
  1280. ;; Back-end options overrule inherited ones.
  1281. (should
  1282. (eq 'b
  1283. (let (org-export--registered-backends)
  1284. (org-export-define-backend 'b1 nil :options-alist '((:key1 . a)))
  1285. (cdr (assq :key1
  1286. (org-export-get-all-options
  1287. (org-export-create-backend
  1288. :parent 'b1 :options '((:key1 . b))))))))))
  1289. (ert-deftest test-org-export/get-all-filters ()
  1290. "Test `org-export-get-all-filters' specifications."
  1291. ;; Return nil when back-end cannot be found.
  1292. (should-not (org-export-get-all-filters nil))
  1293. ;; Same as `org-export-filters' if no parent.
  1294. (should
  1295. (equal '((:filter-headline . ignore))
  1296. (org-export-get-all-filters
  1297. (org-export-create-backend
  1298. :filters '((:filter-headline . ignore))))))
  1299. ;; But inherit from all ancestors whenever possible.
  1300. (should
  1301. (equal '((:filter-section . ignore) (:filter-headline . ignore))
  1302. (let (org-export--registered-backends)
  1303. (org-export-define-backend 'b1
  1304. nil :filters-alist '((:filter-headline . ignore)))
  1305. (org-export-get-all-filters
  1306. (org-export-create-backend
  1307. :parent 'b1 :filters '((:filter-section . ignore)))))))
  1308. (should
  1309. (equal '((:filter-paragraph . ignore)
  1310. (:filter-section . ignore)
  1311. (:filter-headline . ignore))
  1312. (let (org-export--registered-backends)
  1313. (org-export-define-backend 'b1
  1314. nil :filters-alist '((:filter-headline . ignore)))
  1315. (org-export-define-derived-backend 'b2 'b1
  1316. :filters-alist '((:filter-section . ignore)))
  1317. (org-export-get-all-filters
  1318. (org-export-create-backend
  1319. :parent 'b2 :filters '((:filter-paragraph . ignore)))))))
  1320. ;; Back-end filters overrule inherited ones.
  1321. (should
  1322. (eq 'b
  1323. (let (org-export--registered-backends)
  1324. (org-export-define-backend 'b1 '((:filter-headline . a)))
  1325. (cdr (assq :filter-headline
  1326. (org-export-get-all-filters
  1327. (org-export-create-backend
  1328. :parent 'b1 :filters '((:filter-headline . b))))))))))
  1329. (ert-deftest test-org-export/with-backend ()
  1330. "Test `org-export-with-backend' definition."
  1331. ;; Error when calling an undefined back-end
  1332. (should-error (org-export-with-backend nil "Test"))
  1333. ;; Error when called back-end doesn't have an appropriate
  1334. ;; transcoder.
  1335. (should-error
  1336. (org-export-with-backend
  1337. (org-export-create-backend :transcoders '((headline . ignore)))
  1338. "Test"))
  1339. ;; Otherwise, export using correct transcoder
  1340. (should
  1341. (equal "Success"
  1342. (let (org-export--registered-backends)
  1343. (org-export-define-backend 'test
  1344. '((plain-text . (lambda (text contents info) "Failure"))))
  1345. (org-export-define-backend 'test2
  1346. '((plain-text . (lambda (text contents info) "Success"))))
  1347. (org-export-with-backend 'test2 "Test"))))
  1348. ;; Provide correct back-end if transcoder needs to use recursive
  1349. ;; calls anyway.
  1350. (should
  1351. (equal "Success\n"
  1352. (let ((test-back-end
  1353. (org-export-create-backend
  1354. :transcoders
  1355. '((headline . (lambda (headline contents info)
  1356. (org-export-data
  1357. (org-element-property :title headline)
  1358. info)))
  1359. (plain-text . (lambda (text info) "Success"))))))
  1360. (org-export-string-as
  1361. "* Test"
  1362. (org-export-create-backend
  1363. :transcoders
  1364. '((headline . (lambda (headline contents info)
  1365. (org-export-with-backend
  1366. test-back-end headline contents info))))))))))
  1367. (ert-deftest test-org-export/data-with-backend ()
  1368. "Test `org-export-data-with-backend' specifications."
  1369. ;; Error when calling an undefined back-end.
  1370. (should-error (org-export-data-with-backend nil "nil" nil))
  1371. ;; Otherwise, export data recursively, using correct back-end.
  1372. (should
  1373. (equal
  1374. "Success!"
  1375. (org-export-data-with-backend
  1376. '(bold nil "Test")
  1377. (org-export-create-backend
  1378. :transcoders
  1379. '((plain-text . (lambda (text info) "Success"))
  1380. (bold . (lambda (bold contents info) (concat contents "!")))))
  1381. '(:with-emphasize t)))))
  1382. ;;; Export Snippets
  1383. (ert-deftest test-org-export/export-snippet ()
  1384. "Test export snippets transcoding."
  1385. ;; Standard test.
  1386. (org-test-with-temp-text "@@test:A@@@@t:B@@"
  1387. (let ((backend (org-test-default-backend)))
  1388. (setf (org-export-backend-name backend) 'test)
  1389. (setf (org-export-backend-transcoders backend)
  1390. (cons (cons 'export-snippet
  1391. (lambda (snippet contents info)
  1392. (when (eq (org-export-snippet-backend snippet) 'test)
  1393. (org-element-property :value snippet))))
  1394. (org-export-backend-transcoders backend)))
  1395. (let ((org-export-snippet-translation-alist nil))
  1396. (should (equal (org-export-as backend) "A\n")))
  1397. (let ((org-export-snippet-translation-alist '(("t" . "test"))))
  1398. (should (equal (org-export-as backend) "AB\n")))))
  1399. ;; Ignored export snippets do not remove any blank.
  1400. (should
  1401. (equal "begin end\n"
  1402. (org-test-with-parsed-data "begin @@test:A@@ end"
  1403. (org-export-data-with-backend
  1404. tree
  1405. (org-export-create-backend
  1406. :transcoders
  1407. '((paragraph . (lambda (paragraph contents info) contents))
  1408. (section . (lambda (section contents info) contents))))
  1409. info)))))
  1410. ;;; Footnotes
  1411. (ert-deftest test-org-export/footnotes ()
  1412. "Test footnotes specifications."
  1413. (let ((org-footnote-section nil)
  1414. (org-export-with-footnotes t))
  1415. ;; 1. Read every type of footnote.
  1416. (should
  1417. (equal
  1418. '((1 . "A\n") (2 . "B") (3 . "C") (4 . "D"))
  1419. (org-test-with-parsed-data
  1420. "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
  1421. (org-element-map tree 'footnote-reference
  1422. (lambda (ref)
  1423. (let ((def (org-export-get-footnote-definition ref info)))
  1424. (cons (org-export-get-footnote-number ref info)
  1425. (if (eq (org-element-property :type ref) 'inline) (car def)
  1426. (car (org-element-contents
  1427. (car (org-element-contents def))))))))
  1428. info))))
  1429. ;; 2. Test nested footnotes order.
  1430. (should
  1431. (equal
  1432. '((1 . "fn:1") (2 . "fn:2") (3 . "fn:3") (4))
  1433. (org-test-with-parsed-data
  1434. "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
  1435. (org-element-map tree 'footnote-reference
  1436. (lambda (ref)
  1437. (when (org-export-footnote-first-reference-p ref info)
  1438. (cons (org-export-get-footnote-number ref info)
  1439. (org-element-property :label ref))))
  1440. info))))
  1441. ;; 3. Test nested footnote in invisible definitions.
  1442. (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
  1443. ;; Hide definitions.
  1444. (narrow-to-region (point) (point-at-eol))
  1445. (let* ((tree (org-element-parse-buffer))
  1446. (info (org-combine-plists
  1447. `(:parse-tree ,tree)
  1448. (org-export-collect-tree-properties
  1449. tree (org-export-get-environment)))))
  1450. ;; Both footnotes should be seen.
  1451. (should
  1452. (= (length (org-export-collect-footnote-definitions tree info)) 2))))
  1453. ;; 4. Test footnotes definitions collection.
  1454. (should
  1455. (= 4
  1456. (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
  1457. \[fn:2] B [fn:3] [fn::D].
  1458. \[fn:3] C."
  1459. (length (org-export-collect-footnote-definitions tree info)))))
  1460. ;; 5. Test export of footnotes defined outside parsing scope.
  1461. (should
  1462. (equal
  1463. "ParagraphOut of scope\n"
  1464. (org-test-with-temp-text "[fn:1] Out of scope
  1465. * Title
  1466. Paragraph[fn:1]"
  1467. (let ((backend (org-test-default-backend)))
  1468. (setf (org-export-backend-transcoders backend)
  1469. (cons (cons 'footnote-reference
  1470. (lambda (fn contents info)
  1471. (org-element-interpret-data
  1472. (org-export-get-footnote-definition fn info))))
  1473. (org-export-backend-transcoders backend)))
  1474. (forward-line)
  1475. (org-export-as backend 'subtree)))))
  1476. ;; 6. Footnotes without a definition should throw an error.
  1477. (should-error
  1478. (org-test-with-parsed-data "Text[fn:1]"
  1479. (org-export-get-footnote-definition
  1480. (org-element-map tree 'footnote-reference 'identity info t) info)))
  1481. ;; 7. Footnote section should be ignored in TOC and in headlines
  1482. ;; numbering.
  1483. (should
  1484. (= 1 (let ((org-footnote-section "Footnotes"))
  1485. (length (org-test-with-parsed-data "* H1\n* Footnotes\n"
  1486. (org-export-collect-headlines info))))))
  1487. (should
  1488. (equal '(2)
  1489. (let ((org-footnote-section "Footnotes"))
  1490. (org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
  1491. (org-element-map tree 'headline
  1492. (lambda (hl)
  1493. (when (equal (org-element-property :raw-value hl) "H2")
  1494. (org-export-get-headline-number hl info)))
  1495. info t)))))))
  1496. ;;; Headlines and Inlinetasks
  1497. (ert-deftest test-org-export/get-relative-level ()
  1498. "Test `org-export-get-relative-level' specifications."
  1499. ;; Standard test.
  1500. (should
  1501. (equal '(1 2)
  1502. (let ((org-odd-levels-only nil))
  1503. (org-test-with-parsed-data "* Headline 1\n** Headline 2"
  1504. (org-element-map tree 'headline
  1505. (lambda (h) (org-export-get-relative-level h info))
  1506. info)))))
  1507. ;; Missing levels
  1508. (should
  1509. (equal '(1 3)
  1510. (let ((org-odd-levels-only nil))
  1511. (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
  1512. (org-element-map tree 'headline
  1513. (lambda (h) (org-export-get-relative-level h info))
  1514. info))))))
  1515. (ert-deftest test-org-export/low-level-p ()
  1516. "Test `org-export-low-level-p' specifications."
  1517. (should
  1518. (equal
  1519. '(no yes)
  1520. (let ((org-odd-levels-only nil))
  1521. (org-test-with-parsed-data "* Headline 1\n** Headline 2"
  1522. (org-element-map tree 'headline
  1523. (lambda (h) (if (org-export-low-level-p h info) 'yes 'no))
  1524. (plist-put info :headline-levels 1)))))))
  1525. (ert-deftest test-org-export/get-headline-number ()
  1526. "Test `org-export-get-headline-number' specifications."
  1527. ;; Standard test.
  1528. (should
  1529. (equal
  1530. '((1) (1 1))
  1531. (let ((org-odd-levels-only nil))
  1532. (org-test-with-parsed-data "* Headline 1\n** Headline 2"
  1533. (org-element-map tree 'headline
  1534. (lambda (h) (org-export-get-headline-number h info))
  1535. info)))))
  1536. ;; Missing levels are replaced with 0.
  1537. (should
  1538. (equal
  1539. '((1) (1 0 1))
  1540. (let ((org-odd-levels-only nil))
  1541. (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
  1542. (org-element-map tree 'headline
  1543. (lambda (h) (org-export-get-headline-number h info))
  1544. info))))))
  1545. (ert-deftest test-org-export/numbered-headline-p ()
  1546. "Test `org-export-numbered-headline-p' specifications."
  1547. ;; If `:section-numbers' is nil, never number headlines.
  1548. (should-not
  1549. (org-test-with-parsed-data "* Headline"
  1550. (org-element-map tree 'headline
  1551. (lambda (h) (org-export-numbered-headline-p h info))
  1552. (plist-put info :section-numbers nil))))
  1553. ;; If `:section-numbers' is a number, only number headlines with
  1554. ;; a level greater that it.
  1555. (should
  1556. (equal
  1557. '(yes no)
  1558. (org-test-with-parsed-data "* Headline 1\n** Headline 2"
  1559. (org-element-map tree 'headline
  1560. (lambda (h) (if (org-export-numbered-headline-p h info) 'yes 'no))
  1561. (plist-put info :section-numbers 1)))))
  1562. ;; Otherwise, headlines are always numbered.
  1563. (should
  1564. (org-test-with-parsed-data "* Headline"
  1565. (org-element-map tree 'headline
  1566. (lambda (h) (org-export-numbered-headline-p h info))
  1567. (plist-put info :section-numbers t)))))
  1568. (ert-deftest test-org-export/org-export-get-headline-id ()
  1569. "Test `org-export-get-headline-id' specifications."
  1570. ;; Numbered headlines have IDs akin to "sec-N".
  1571. (should
  1572. (equal "sec-1"
  1573. (org-test-with-parsed-data "* H"
  1574. (org-export-get-headline-id
  1575. (org-element-map tree 'headline #'identity info t)
  1576. info))))
  1577. ;; The ID of numbered headlines reflect the hierarchy.
  1578. (should
  1579. (equal "sec-1-1"
  1580. (org-test-with-parsed-data "* H1\n** H2"
  1581. (org-export-get-headline-id
  1582. (org-element-map tree 'headline
  1583. (lambda (h)
  1584. (and (equal "H2" (org-element-property :raw-value h)) h))
  1585. info t)
  1586. info))))
  1587. ;; Unnumbered headlines have IDs akin to "unnumbered-N".
  1588. (should
  1589. (equal "unnumbered-1"
  1590. (org-test-with-parsed-data
  1591. "* H\n:PROPERTIES:\n:UNNUMBERED: t\n:END:"
  1592. (org-export-get-headline-id
  1593. (org-element-map tree 'headline #'identity info t)
  1594. info))))
  1595. ;; The ID of Unnumbered headlines do not reflect the hierarchy.
  1596. (should
  1597. (equal "unnumbered-2"
  1598. (org-test-with-parsed-data
  1599. "* H1\n:PROPERTIES:\n:UNNUMBERED: t\n:END:\n** H2"
  1600. (org-export-get-headline-id
  1601. (org-element-map tree 'headline
  1602. (lambda (h)
  1603. (and (equal "H2" (org-element-property :raw-value h)) h))
  1604. info t)
  1605. info))))
  1606. ;; When #+OPTIONS: num:nil all headlines are unnumbered.
  1607. (should
  1608. (equal "unnumbered-1"
  1609. (org-test-with-parsed-data "* H\n#+OPTIONS: num:nil"
  1610. (org-export-get-headline-id
  1611. (org-element-map tree 'headline 'identity info t)
  1612. info))))
  1613. ;; UNNUMBERED ignores inheritance. Any non-nil value among
  1614. ;; ancestors disables numbering.
  1615. (should
  1616. (org-test-with-parsed-data
  1617. "* H
  1618. :PROPERTIES:
  1619. :UNNUMBERED: t
  1620. :END:
  1621. ** H2
  1622. :PROPERTIES:
  1623. :UNNUMBERED: nil
  1624. :END:
  1625. *** H3"
  1626. (org-every
  1627. (lambda (h) (not (org-export-numbered-headline-p h info)))
  1628. (org-element-map tree 'headline #'identity info)))))
  1629. (ert-deftest test-org-export/number-to-roman ()
  1630. "Test `org-export-number-to-roman' specifications."
  1631. ;; If number is negative, return it as a string.
  1632. (should (equal (org-export-number-to-roman -1) "-1"))
  1633. ;; Otherwise, return it as a roman number.
  1634. (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
  1635. (ert-deftest test-org-export/get-optional-title ()
  1636. "Test `org-export-get-alt-title' specifications."
  1637. ;; If ALT_TITLE property is defined, use it.
  1638. (should
  1639. (equal '("opt")
  1640. (org-test-with-parsed-data
  1641. "* Headline\n:PROPERTIES:\n:ALT_TITLE: opt\n:END:"
  1642. (org-export-get-alt-title
  1643. (org-element-map tree 'headline 'identity info t)
  1644. info))))
  1645. ;; Otherwise, fall-back to regular title.
  1646. (should
  1647. (equal '("Headline")
  1648. (org-test-with-parsed-data "* Headline"
  1649. (org-export-get-alt-title
  1650. (org-element-map tree 'headline 'identity info t)
  1651. info)))))
  1652. (ert-deftest test-org-export/get-tags ()
  1653. "Test `org-export-get-tags' specifications."
  1654. (let ((org-export-exclude-tags '("noexport"))
  1655. (org-export-select-tags '("export")))
  1656. ;; Standard test: tags which are not a select tag, an exclude tag,
  1657. ;; or specified as optional argument shouldn't be ignored.
  1658. (should
  1659. (org-test-with-parsed-data "* Headline :tag:"
  1660. (org-export-get-tags (org-element-map tree 'headline 'identity info t)
  1661. info)))
  1662. ;; Exclude tags are removed.
  1663. (should-not
  1664. (org-test-with-parsed-data "* Headline :noexport:"
  1665. (org-export-get-tags (org-element-map tree 'headline 'identity info t)
  1666. info)))
  1667. ;; Select tags are removed.
  1668. (should-not
  1669. (org-test-with-parsed-data "* Headline :export:"
  1670. (org-export-get-tags (org-element-map tree 'headline 'identity info t)
  1671. info)))
  1672. (should
  1673. (equal
  1674. '("tag")
  1675. (org-test-with-parsed-data "* Headline :tag:export:"
  1676. (org-export-get-tags (org-element-map tree 'headline 'identity info t)
  1677. info))))
  1678. ;; Tags provided in the optional argument are also ignored.
  1679. (should-not
  1680. (org-test-with-parsed-data "* Headline :ignore:"
  1681. (org-export-get-tags (org-element-map tree 'headline 'identity info t)
  1682. info '("ignore"))))
  1683. ;; Allow tag inheritance.
  1684. (should
  1685. (equal
  1686. '(("tag") ("tag"))
  1687. (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
  1688. (org-element-map tree 'headline
  1689. (lambda (hl) (org-export-get-tags hl info nil t)) info))))
  1690. ;; Tag inheritance checks FILETAGS keywords.
  1691. (should
  1692. (equal
  1693. '(("a" "b" "tag"))
  1694. (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
  1695. (org-element-map tree 'headline
  1696. (lambda (hl) (org-export-get-tags hl info nil t)) info))))))
  1697. (ert-deftest test-org-export/get-node-property ()
  1698. "Test`org-export-get-node-property' specifications."
  1699. ;; Standard test.
  1700. (should
  1701. (equal "value"
  1702. (org-test-with-parsed-data "* Headline
  1703. :PROPERTIES:
  1704. :prop: value
  1705. :END:"
  1706. (org-export-get-node-property
  1707. :PROP (org-element-map tree 'headline 'identity nil t)))))
  1708. ;; Test inheritance.
  1709. (should
  1710. (equal "value"
  1711. (org-test-with-parsed-data "* Parent
  1712. :PROPERTIES:
  1713. :prop: value
  1714. :END:
  1715. ** Headline
  1716. Paragraph"
  1717. (org-export-get-node-property
  1718. :PROP (org-element-map tree 'paragraph 'identity nil t) t))))
  1719. ;; Cannot return a value before the first headline.
  1720. (should-not
  1721. (org-test-with-parsed-data "Paragraph
  1722. * Headline
  1723. :PROPERTIES:
  1724. :prop: value
  1725. :END:"
  1726. (org-export-get-node-property
  1727. :PROP (org-element-map tree 'paragraph 'identity nil t)))))
  1728. (ert-deftest test-org-export/get-category ()
  1729. "Test `org-export-get-category' specifications."
  1730. ;; Standard test.
  1731. (should
  1732. (equal "value"
  1733. (org-test-with-parsed-data "* Headline
  1734. :PROPERTIES:
  1735. :CATEGORY: value
  1736. :END:"
  1737. (org-export-get-category
  1738. (org-element-map tree 'headline 'identity nil t) info))))
  1739. ;; Test inheritance from a parent headline.
  1740. (should
  1741. (equal '("value" "value")
  1742. (org-test-with-parsed-data "* Headline1
  1743. :PROPERTIES:
  1744. :CATEGORY: value
  1745. :END:
  1746. ** Headline2"
  1747. (org-element-map tree 'headline
  1748. (lambda (hl) (org-export-get-category hl info)) info))))
  1749. ;; Test inheritance from #+CATEGORY keyword
  1750. (should
  1751. (equal "value"
  1752. (org-test-with-parsed-data "#+CATEGORY: value
  1753. * Headline"
  1754. (org-export-get-category
  1755. (org-element-map tree 'headline 'identity nil t) info))))
  1756. ;; Test inheritance from file name.
  1757. (should
  1758. (equal "test"
  1759. (org-test-with-parsed-data "* Headline"
  1760. (let ((info (plist-put info :input-file "~/test.org")))
  1761. (org-export-get-category
  1762. (org-element-map tree 'headline 'identity nil t) info)))))
  1763. ;; Fall-back value.
  1764. (should
  1765. (equal "???"
  1766. (org-test-with-parsed-data "* Headline"
  1767. (org-export-get-category
  1768. (org-element-map tree 'headline 'identity nil t) info)))))
  1769. (ert-deftest test-org-export/first-sibling-p ()
  1770. "Test `org-export-first-sibling-p' specifications."
  1771. ;; Standard test.
  1772. (should
  1773. (equal
  1774. '(yes yes no)
  1775. (org-test-with-parsed-data "* H\n** H 2\n** H 3"
  1776. (org-element-map tree 'headline
  1777. (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
  1778. info))))
  1779. (should
  1780. (equal '(yes no)
  1781. (org-test-with-parsed-data "- item\n\n para"
  1782. (org-element-map tree 'paragraph
  1783. (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
  1784. info))))
  1785. ;; Ignore sections for headlines.
  1786. (should
  1787. (equal '(yes yes)
  1788. (org-test-with-parsed-data "* H\nSection\n** H 2"
  1789. (org-element-map tree 'headline
  1790. (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
  1791. info))))
  1792. ;; Ignore headlines not exported.
  1793. (should
  1794. (equal
  1795. '(yes)
  1796. (let ((org-export-exclude-tags '("ignore")))
  1797. (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
  1798. (org-element-map tree 'headline
  1799. (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
  1800. info))))))
  1801. (ert-deftest test-org-export/last-sibling-p ()
  1802. "Test `org-export-last-sibling-p' specifications."
  1803. ;; Standard test.
  1804. (should
  1805. (equal
  1806. '(yes no yes)
  1807. (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
  1808. (org-element-map tree 'headline
  1809. (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
  1810. info))))
  1811. (should
  1812. (equal '(no yes)
  1813. (org-test-with-parsed-data "- item\n\n para"
  1814. (org-element-map tree 'paragraph
  1815. (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
  1816. info))))
  1817. ;; Ignore headlines not exported.
  1818. (should
  1819. (equal
  1820. '(yes)
  1821. (let ((org-export-exclude-tags '("ignore")))
  1822. (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
  1823. (org-element-map tree 'headline
  1824. (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
  1825. info))))))
  1826. (ert-deftest test-org-export/handle-inlinetasks ()
  1827. "Test inlinetask export."
  1828. ;; Inlinetask with an exclude tag.
  1829. (when (featurep 'org-inlinetask)
  1830. (should
  1831. (equal
  1832. ""
  1833. (let ((org-inlinetask-min-level 3))
  1834. (org-test-with-temp-text "*** Inlinetask :noexp:\nContents\n*** end"
  1835. (org-export-as (org-test-default-backend)
  1836. nil nil nil '(:exclude-tags ("noexp")))))))
  1837. ;; Inlinetask with an include tag.
  1838. (should
  1839. (equal
  1840. "* H2\n*** Inline :exp:\n"
  1841. (let ((org-inlinetask-min-level 3)
  1842. (org-tags-column 0))
  1843. (org-test-with-temp-text "* H1\n* H2\n*** Inline :exp:"
  1844. (org-export-as (org-test-default-backend)
  1845. nil nil nil '(:select-tags ("exp")))))))
  1846. ;; Ignore inlinetask with a TODO keyword and tasks excluded.
  1847. (should
  1848. (equal ""
  1849. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  1850. (org-inlinetask-min-level 3))
  1851. (org-test-with-temp-text "*** TODO Inline"
  1852. (org-export-as (org-test-default-backend)
  1853. nil nil nil '(:with-tasks nil))))))))
  1854. ;;; Keywords
  1855. (ert-deftest test-org-export/get-date ()
  1856. "Test `org-export-get-date' specifications."
  1857. ;; Return a properly formatted string when
  1858. ;; `org-export-date-timestamp-format' is non-nil and DATE keyword
  1859. ;; consists in a single timestamp.
  1860. (should
  1861. (equal "29 03 2012"
  1862. (let ((org-export-date-timestamp-format "%d %m %Y"))
  1863. (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
  1864. (org-export-get-date info)))))
  1865. ;; Return a secondary string otherwise.
  1866. (should-not
  1867. (stringp
  1868. (let ((org-export-date-timestamp-format nil))
  1869. (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
  1870. (org-export-get-date info)))))
  1871. (should
  1872. (equal '("Date")
  1873. (org-test-with-parsed-data "#+DATE: Date"
  1874. (org-export-get-date info))))
  1875. ;; Optional argument has precedence over
  1876. ;; `org-export-date-timestamp-format'.
  1877. (should
  1878. (equal "29 03"
  1879. (let ((org-export-date-timestamp-format "%d %m %Y"))
  1880. (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
  1881. (org-export-get-date info "%d %m"))))))
  1882. ;;; Links
  1883. (ert-deftest test-org-export/get-coderef-format ()
  1884. "Test `org-export-get-coderef-format' specifications."
  1885. ;; A link without description returns "%s"
  1886. (should (equal (org-export-get-coderef-format "(ref:line)" nil)
  1887. "%s"))
  1888. ;; Return "%s" when path is matched within description.
  1889. (should (equal (org-export-get-coderef-format "path" "desc (path)")
  1890. "desc %s"))
  1891. ;; Otherwise return description.
  1892. (should (equal (org-export-get-coderef-format "path" "desc")
  1893. "desc")))
  1894. (ert-deftest test-org-export/inline-image-p ()
  1895. "Test `org-export-inline-image-p' specifications."
  1896. (should
  1897. (org-export-inline-image-p
  1898. (org-test-with-temp-text "[[#id]]"
  1899. (org-element-map (org-element-parse-buffer) 'link 'identity nil t))
  1900. '(("custom-id" . "id")))))
  1901. (ert-deftest test-org-export/fuzzy-link ()
  1902. "Test fuzzy links specifications."
  1903. ;; Link to an headline should return headline's number.
  1904. (org-test-with-parsed-data
  1905. "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
  1906. (should
  1907. ;; Note: Headline's number is in fact a list of numbers.
  1908. (equal '(2)
  1909. (org-element-map tree 'link
  1910. (lambda (link)
  1911. (org-export-get-ordinal
  1912. (org-export-resolve-fuzzy-link link info) info)) info t))))
  1913. ;; Link to a target in an item should return item's number.
  1914. (org-test-with-parsed-data
  1915. "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
  1916. (should
  1917. ;; Note: Item's number is in fact a list of numbers.
  1918. (equal '(1 2)
  1919. (org-element-map tree 'link
  1920. (lambda (link)
  1921. (org-export-get-ordinal
  1922. (org-export-resolve-fuzzy-link link info) info)) info t))))
  1923. ;; Link to a target in a footnote should return footnote's number.
  1924. (org-test-with-parsed-data "
  1925. Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
  1926. (should
  1927. (equal '(2 3)
  1928. (org-element-map tree 'link
  1929. (lambda (link)
  1930. (org-export-get-ordinal
  1931. (org-export-resolve-fuzzy-link link info) info)) info))))
  1932. ;; Link to a named element should return sequence number of that
  1933. ;; element.
  1934. (org-test-with-parsed-data
  1935. "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
  1936. (should
  1937. (= 2
  1938. (org-element-map tree 'link
  1939. (lambda (link)
  1940. (org-export-get-ordinal
  1941. (org-export-resolve-fuzzy-link link info) info)) info t))))
  1942. ;; Link to a target not within an item, a table, a footnote
  1943. ;; reference or definition should return section number.
  1944. (org-test-with-parsed-data
  1945. "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
  1946. (should
  1947. (equal '(2)
  1948. (org-element-map tree 'link
  1949. (lambda (link)
  1950. (org-export-get-ordinal
  1951. (org-export-resolve-fuzzy-link link info) info)) info t))))
  1952. ;; Space are not significant when matching a fuzzy link.
  1953. (should
  1954. (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
  1955. (org-element-map tree 'link
  1956. (lambda (link) (org-export-resolve-fuzzy-link link info))
  1957. info t)))
  1958. ;; Statistics cookies are ignored for headline match.
  1959. (should
  1960. (org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
  1961. (org-element-map tree 'link
  1962. (lambda (link) (org-export-resolve-fuzzy-link link info))
  1963. info t)))
  1964. (should
  1965. (org-test-with-parsed-data "* Head [100%]\n[[Head]]"
  1966. (org-element-map tree 'link
  1967. (lambda (link) (org-export-resolve-fuzzy-link link info))
  1968. info t)))
  1969. ;; Headline match is position dependent.
  1970. (should-not
  1971. (apply
  1972. 'eq
  1973. (org-test-with-parsed-data "* H1\n[[*H1]]\n* H1\n[[*H1]]"
  1974. (org-element-map tree 'link
  1975. (lambda (link) (org-export-resolve-fuzzy-link link info)) info)))))
  1976. (ert-deftest test-org-export/resolve-coderef ()
  1977. "Test `org-export-resolve-coderef' specifications."
  1978. (let ((org-coderef-label-format "(ref:%s)"))
  1979. ;; 1. A link to a "-n -k -r" block returns line number.
  1980. (org-test-with-parsed-data
  1981. "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
  1982. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  1983. (org-test-with-parsed-data
  1984. "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  1985. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  1986. ;; 2. A link to a "-n -r" block returns line number.
  1987. (org-test-with-parsed-data
  1988. "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
  1989. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  1990. (org-test-with-parsed-data
  1991. "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  1992. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  1993. ;; 3. A link to a "-n" block returns coderef.
  1994. (org-test-with-parsed-data
  1995. "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  1996. (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
  1997. (org-test-with-parsed-data
  1998. "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
  1999. (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
  2000. ;; 4. A link to a "-r" block returns line number.
  2001. (org-test-with-parsed-data
  2002. "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  2003. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  2004. (org-test-with-parsed-data
  2005. "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
  2006. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  2007. ;; 5. A link to a block without a switch returns coderef.
  2008. (org-test-with-parsed-data
  2009. "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  2010. (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
  2011. (org-test-with-parsed-data
  2012. "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
  2013. (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
  2014. ;; 6. Correctly handle continued line numbers. A "+n" switch
  2015. ;; should resume numbering from previous block with numbered
  2016. ;; lines, ignoring blocks not numbering lines in the process.
  2017. ;; A "-n" switch resets count.
  2018. (org-test-with-parsed-data "
  2019. #+BEGIN_EXAMPLE -n
  2020. Text.
  2021. #+END_EXAMPLE
  2022. #+BEGIN_SRC emacs-lisp
  2023. \(- 1 1)
  2024. #+END_SRC
  2025. #+BEGIN_SRC emacs-lisp +n -r
  2026. \(+ 1 1) (ref:addition)
  2027. #+END_SRC
  2028. #+BEGIN_EXAMPLE -n -r
  2029. Another text. (ref:text)
  2030. #+END_EXAMPLE"
  2031. (should (= (org-export-resolve-coderef "addition" info) 2))
  2032. (should (= (org-export-resolve-coderef "text" info) 1)))
  2033. ;; 7. Recognize coderef with user-specified syntax.
  2034. (org-test-with-parsed-data
  2035. "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
  2036. (should (equal (org-export-resolve-coderef "text" info) "text")))))
  2037. (ert-deftest test-org-export/resolve-fuzzy-link ()
  2038. "Test `org-export-resolve-fuzzy-link' specifications."
  2039. ;; Match target objects.
  2040. (should
  2041. (org-test-with-parsed-data "<<target>> [[target]]"
  2042. (org-export-resolve-fuzzy-link
  2043. (org-element-map tree 'link 'identity info t) info)))
  2044. ;; Match named elements.
  2045. (should
  2046. (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
  2047. (org-export-resolve-fuzzy-link
  2048. (org-element-map tree 'link 'identity info t) info)))
  2049. ;; Match exact headline's name.
  2050. (should
  2051. (org-test-with-parsed-data "* My headline\n[[My headline]]"
  2052. (org-export-resolve-fuzzy-link
  2053. (org-element-map tree 'link 'identity info t) info)))
  2054. ;; Targets objects have priority over named elements and headline
  2055. ;; titles.
  2056. (should
  2057. (eq 'target
  2058. (org-test-with-parsed-data
  2059. "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
  2060. (org-element-type
  2061. (org-export-resolve-fuzzy-link
  2062. (org-element-map tree 'link 'identity info t) info)))))
  2063. ;; Named elements have priority over headline titles.
  2064. (should
  2065. (eq 'paragraph
  2066. (org-test-with-parsed-data
  2067. "* target\n#+NAME: target\nParagraph\n\n[[target]]"
  2068. (org-element-type
  2069. (org-export-resolve-fuzzy-link
  2070. (org-element-map tree 'link 'identity info t) info)))))
  2071. ;; If link's path starts with a "*", only match headline titles,
  2072. ;; though.
  2073. (should
  2074. (eq 'headline
  2075. (org-test-with-parsed-data
  2076. "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
  2077. (org-element-type
  2078. (org-export-resolve-fuzzy-link
  2079. (org-element-map tree 'link 'identity info t) info)))))
  2080. ;; Return nil if no match.
  2081. (should-not
  2082. (org-test-with-parsed-data "[[target]]"
  2083. (org-export-resolve-fuzzy-link
  2084. (org-element-map tree 'link 'identity info t) info)))
  2085. ;; Match fuzzy link even when before first headline.
  2086. (should
  2087. (eq 'headline
  2088. (org-test-with-parsed-data "[[hl]]\n* hl"
  2089. (org-element-type
  2090. (org-export-resolve-fuzzy-link
  2091. (org-element-map tree 'link 'identity info t) info))))))
  2092. (ert-deftest test-org-export/resolve-id-link ()
  2093. "Test `org-export-resolve-id-link' specifications."
  2094. ;; 1. Regular test for custom-id link.
  2095. (org-test-with-parsed-data "* Headline1
  2096. :PROPERTIES:
  2097. :CUSTOM_ID: test
  2098. :END:
  2099. * Headline 2
  2100. \[[#test]]"
  2101. (should
  2102. (org-export-resolve-id-link
  2103. (org-element-map tree 'link 'identity info t) info)))
  2104. ;; 2. Failing test for custom-id link.
  2105. (org-test-with-parsed-data "* Headline1
  2106. :PROPERTIES:
  2107. :CUSTOM_ID: test
  2108. :END:
  2109. * Headline 2
  2110. \[[#no-match]]"
  2111. (should-not
  2112. (org-export-resolve-id-link
  2113. (org-element-map tree 'link 'identity info t) info)))
  2114. ;; 3. Test for internal id target.
  2115. (org-test-with-parsed-data "* Headline1
  2116. :PROPERTIES:
  2117. :ID: aaaa
  2118. :END:
  2119. * Headline 2
  2120. \[[id:aaaa]]"
  2121. (should
  2122. (org-export-resolve-id-link
  2123. (org-element-map tree 'link 'identity info t) info)))
  2124. ;; 4. Test for external id target.
  2125. (org-test-with-parsed-data "[[id:aaaa]]"
  2126. (should
  2127. (org-export-resolve-id-link
  2128. (org-element-map tree 'link 'identity info t)
  2129. (org-combine-plists info '(:id-alist (("aaaa" . "external-file"))))))))
  2130. (ert-deftest test-org-export/resolve-radio-link ()
  2131. "Test `org-export-resolve-radio-link' specifications."
  2132. ;; Standard test.
  2133. (should
  2134. (org-test-with-temp-text "<<<radio>>> radio"
  2135. (org-update-radio-target-regexp)
  2136. (let* ((tree (org-element-parse-buffer))
  2137. (info `(:parse-tree ,tree)))
  2138. (org-export-resolve-radio-link
  2139. (org-element-map tree 'link 'identity info t)
  2140. info))))
  2141. ;; Radio targets are case-insensitive.
  2142. (should
  2143. (org-test-with-temp-text "<<<RADIO>>> radio"
  2144. (org-update-radio-target-regexp)
  2145. (let* ((tree (org-element-parse-buffer))
  2146. (info `(:parse-tree ,tree)))
  2147. (org-export-resolve-radio-link
  2148. (org-element-map tree 'link 'identity info t)
  2149. info))))
  2150. ;; Radio target with objects.
  2151. (should
  2152. (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
  2153. (org-update-radio-target-regexp)
  2154. (let* ((tree (org-element-parse-buffer))
  2155. (info `(:parse-tree ,tree)))
  2156. (org-export-resolve-radio-link
  2157. (org-element-map tree 'link 'identity info t)
  2158. info))))
  2159. ;; Radio target with objects at its beginning.
  2160. (should
  2161. (org-test-with-temp-text "<<<\\alpha radio>>> \\alpha radio"
  2162. (org-update-radio-target-regexp)
  2163. (let* ((tree (org-element-parse-buffer))
  2164. (info `(:parse-tree ,tree)))
  2165. (org-export-resolve-radio-link
  2166. (org-element-map tree 'link 'identity info t)
  2167. info))))
  2168. ;; Radio link next to an apostrophe.
  2169. (should
  2170. (org-test-with-temp-text "<<<radio>>> radio's"
  2171. (org-update-radio-target-regexp)
  2172. (let* ((tree (org-element-parse-buffer))
  2173. (info `(:parse-tree ,tree)))
  2174. (org-export-resolve-radio-link
  2175. (org-element-map tree 'link 'identity info t)
  2176. info))))
  2177. ;; Multiple radio targets.
  2178. (should
  2179. (equal '("radio1" "radio2")
  2180. (org-test-with-temp-text "<<<radio1>>> <<<radio2>>> radio1 radio2"
  2181. (org-update-radio-target-regexp)
  2182. (let* ((tree (org-element-parse-buffer))
  2183. (info `(:parse-tree ,tree)))
  2184. (org-element-map tree 'link
  2185. (lambda (link)
  2186. (org-element-property
  2187. :value (org-export-resolve-radio-link link info)))
  2188. info)))))
  2189. ;; Radio target is whitespace insensitive.
  2190. (should
  2191. (org-test-with-temp-text "<<<a radio>>> a\n radio"
  2192. (org-update-radio-target-regexp)
  2193. (let* ((tree (org-element-parse-buffer))
  2194. (info `(:parse-tree ,tree)))
  2195. (org-element-map tree 'link
  2196. (lambda (link) (org-export-resolve-radio-link link info)) info t)))))
  2197. ;;; Src-block and example-block
  2198. (ert-deftest test-org-export/unravel-code ()
  2199. "Test `org-export-unravel-code' function."
  2200. ;; Code without reference.
  2201. (should
  2202. (equal '("(+ 1 1)\n")
  2203. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
  2204. (org-export-unravel-code (org-element-at-point)))))
  2205. ;; Code with reference.
  2206. (should
  2207. (equal '("(+ 1 1)\n" (1 . "test"))
  2208. (org-test-with-temp-text
  2209. "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
  2210. (let ((org-coderef-label-format "(ref:%s)"))
  2211. (org-export-unravel-code (org-element-at-point))))))
  2212. ;; Code with user-defined reference.
  2213. (should
  2214. (equal
  2215. '("(+ 1 1)\n" (1 . "test"))
  2216. (org-test-with-temp-text
  2217. "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
  2218. (let ((org-coderef-label-format "(ref:%s)"))
  2219. (org-export-unravel-code (org-element-at-point))))))
  2220. ;; Code references keys are relative to the current block.
  2221. (should
  2222. (equal '("(+ 2 2)\n(+ 3 3)\n" (2 . "one"))
  2223. (org-test-with-temp-text "
  2224. #+BEGIN_EXAMPLE -n
  2225. \(+ 1 1)
  2226. #+END_EXAMPLE
  2227. #+BEGIN_EXAMPLE +n
  2228. \(+ 2 2)
  2229. \(+ 3 3) (ref:one)
  2230. #+END_EXAMPLE"
  2231. (goto-line 5)
  2232. (let ((org-coderef-label-format "(ref:%s)"))
  2233. (org-export-unravel-code (org-element-at-point)))))))
  2234. (ert-deftest test-org-export/format-code-default ()
  2235. "Test `org-export-format-code-default' specifications."
  2236. ;; Return the empty string when code is empty.
  2237. (should
  2238. (equal ""
  2239. (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n\n\n#+END_SRC"
  2240. (org-export-format-code-default
  2241. (org-element-map tree 'src-block 'identity info t) info))))
  2242. ;; Number lines, two whitespace characters before the actual loc.
  2243. (should
  2244. (equal "1 a\n2 b\n"
  2245. (org-test-with-parsed-data
  2246. "#+BEGIN_SRC emacs-lisp +n\na\nb\n#+END_SRC"
  2247. (org-export-format-code-default
  2248. (org-element-map tree 'src-block 'identity info t) info))))
  2249. ;; Put references 6 whitespace characters after the widest line,
  2250. ;; wrapped within parenthesis.
  2251. (should
  2252. (equal "123 (a)\n1 (b)\n"
  2253. (let ((org-coderef-label-format "(ref:%s)"))
  2254. (org-test-with-parsed-data
  2255. "#+BEGIN_SRC emacs-lisp\n123 (ref:a)\n1 (ref:b)\n#+END_SRC"
  2256. (org-export-format-code-default
  2257. (org-element-map tree 'src-block 'identity info t) info))))))
  2258. ;;; Smart Quotes
  2259. (ert-deftest test-org-export/activate-smart-quotes ()
  2260. "Test `org-export-activate-smart-quotes' specifications."
  2261. ;; Opening double quotes: standard test.
  2262. (should
  2263. (equal
  2264. '("some &ldquo;paragraph")
  2265. (let ((org-export-default-language "en"))
  2266. (org-test-with-parsed-data "some \"paragraph"
  2267. (org-element-map tree 'plain-text
  2268. (lambda (s) (org-export-activate-smart-quotes s :html info))
  2269. info)))))
  2270. ;; Opening quotes: at the beginning of a paragraph.
  2271. (should
  2272. (equal
  2273. '("&ldquo;begin")
  2274. (let ((org-export-default-language "en"))
  2275. (org-test-with-parsed-data "\"begin"
  2276. (org-element-map tree 'plain-text
  2277. (lambda (s) (org-export-activate-smart-quotes s :html info))
  2278. info)))))
  2279. ;; Opening quotes: after an object.
  2280. (should
  2281. (equal
  2282. '("&ldquo;begin")
  2283. (let ((org-export-default-language "en"))
  2284. (org-test-with-parsed-data "=verb= \"begin"
  2285. (org-element-map tree 'plain-text
  2286. (lambda (s) (org-export-activate-smart-quotes s :html info))
  2287. info)))))
  2288. ;; Closing quotes: standard test.
  2289. (should
  2290. (equal
  2291. '("some&rdquo; paragraph")
  2292. (let ((org-export-default-language "en"))
  2293. (org-test-with-parsed-data "some\" paragraph"
  2294. (org-element-map tree 'plain-text
  2295. (lambda (s) (org-export-activate-smart-quotes s :html info))
  2296. info)))))
  2297. ;; Closing quotes: at the end of a paragraph.
  2298. (should
  2299. (equal
  2300. '("end&rdquo;")
  2301. (let ((org-export-default-language "en"))
  2302. (org-test-with-parsed-data "end\""
  2303. (org-element-map tree 'plain-text
  2304. (lambda (s) (org-export-activate-smart-quotes s :html info))
  2305. info)))))
  2306. ;; Apostrophe: standard test.
  2307. (should
  2308. (equal
  2309. '("It shouldn&rsquo;t fail")
  2310. (let ((org-export-default-language "en"))
  2311. (org-test-with-parsed-data "It shouldn't fail"
  2312. (org-element-map tree 'plain-text
  2313. (lambda (s) (org-export-activate-smart-quotes s :html info))
  2314. info)))))
  2315. ;; Apostrophe: before an object.
  2316. (should
  2317. (equal
  2318. '("a&rsquo;")
  2319. (let ((org-export-default-language "en"))
  2320. (org-test-with-parsed-data "a'=b="
  2321. (org-element-map tree 'plain-text
  2322. (lambda (s) (org-export-activate-smart-quotes s :html info))
  2323. info)))))
  2324. ;; Apostrophe: after an object.
  2325. (should
  2326. (equal
  2327. '("&rsquo;s")
  2328. (let ((org-export-default-language "en"))
  2329. (org-test-with-parsed-data "=code='s"
  2330. (org-element-map tree 'plain-text
  2331. (lambda (s) (org-export-activate-smart-quotes s :html info))
  2332. info)))))
  2333. ;; Special case: isolated quotes.
  2334. (should
  2335. (equal '("&ldquo;" "&rdquo;")
  2336. (let ((org-export-default-language "en"))
  2337. (org-test-with-parsed-data "\"$x$\""
  2338. (org-element-map tree 'plain-text
  2339. (lambda (s) (org-export-activate-smart-quotes s :html info))
  2340. info)))))
  2341. ;; Smart quotes in secondary strings.
  2342. (should
  2343. (equal '("&ldquo;" "&rdquo;")
  2344. (let ((org-export-default-language "en"))
  2345. (org-test-with-parsed-data "* \"$x$\""
  2346. (org-element-map tree 'plain-text
  2347. (lambda (s) (org-export-activate-smart-quotes s :html info))
  2348. info)))))
  2349. ;; Smart quotes in document keywords.
  2350. (should
  2351. (equal '("&ldquo;" "&rdquo;")
  2352. (let ((org-export-default-language "en"))
  2353. (org-test-with-parsed-data "#+TITLE: \"$x$\""
  2354. (org-element-map (plist-get info :title) 'plain-text
  2355. (lambda (s) (org-export-activate-smart-quotes s :html info))
  2356. info)))))
  2357. ;; Smart quotes in parsed affiliated keywords.
  2358. (should
  2359. (equal '("&ldquo;" "&rdquo;" "Paragraph")
  2360. (let ((org-export-default-language "en"))
  2361. (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
  2362. (org-element-map tree 'plain-text
  2363. (lambda (s) (org-export-activate-smart-quotes s :html info))
  2364. info nil nil t))))))
  2365. ;;; Tables
  2366. (ert-deftest test-org-export/special-column ()
  2367. "Test if the table's special column is properly recognized."
  2368. ;; 1. First column is special if it contains only a special marking
  2369. ;; characters or empty cells.
  2370. (org-test-with-temp-text "
  2371. | ! | 1 |
  2372. | | 2 |"
  2373. (should
  2374. (org-export-table-has-special-column-p
  2375. (org-element-map
  2376. (org-element-parse-buffer) 'table 'identity nil 'first-match))))
  2377. ;; 2. If the column contains anything else, it isn't special.
  2378. (org-test-with-temp-text "
  2379. | ! | 1 |
  2380. | b | 2 |"
  2381. (should-not
  2382. (org-export-table-has-special-column-p
  2383. (org-element-map
  2384. (org-element-parse-buffer) 'table 'identity nil 'first-match))))
  2385. ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
  2386. ;; and "!".
  2387. (org-test-with-temp-text "
  2388. | # | 1 |
  2389. | ^ | 2 |
  2390. | * | 3 |
  2391. | _ | 4 |
  2392. | / | 5 |
  2393. | $ | 6 |
  2394. | ! | 7 |"
  2395. (should
  2396. (org-export-table-has-special-column-p
  2397. (org-element-map
  2398. (org-element-parse-buffer) 'table 'identity nil 'first-match))))
  2399. ;; 4. A first column with only empty cells isn't considered as
  2400. ;; special.
  2401. (org-test-with-temp-text "
  2402. | | 1 |
  2403. | | 2 |"
  2404. (should-not
  2405. (org-export-table-has-special-column-p
  2406. (org-element-map
  2407. (org-element-parse-buffer) 'table 'identity nil 'first-match)))))
  2408. (ert-deftest test-org-export/table-row-is-special-p ()
  2409. "Test `org-export-table-row-is-special-p' specifications."
  2410. ;; 1. A row is special if it has a special marking character in the
  2411. ;; special column.
  2412. (org-test-with-parsed-data "| ! | 1 |"
  2413. (should
  2414. (org-export-table-row-is-special-p
  2415. (org-element-map tree 'table-row 'identity nil 'first-match) info)))
  2416. ;; 2. A row is special when its first field is "/"
  2417. (org-test-with-parsed-data "
  2418. | / | 1 |
  2419. | a | b |"
  2420. (should
  2421. (org-export-table-row-is-special-p
  2422. (org-element-map tree 'table-row 'identity nil 'first-match) info)))
  2423. ;; 3. A row only containing alignment cookies is also considered as
  2424. ;; special.
  2425. (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
  2426. (should
  2427. (org-export-table-row-is-special-p
  2428. (org-element-map tree 'table-row 'identity nil 'first-match) info)))
  2429. ;; 4. Everything else isn't considered as special.
  2430. (org-test-with-parsed-data "| \alpha | | c |"
  2431. (should-not
  2432. (org-export-table-row-is-special-p
  2433. (org-element-map tree 'table-row 'identity nil 'first-match) info)))
  2434. ;; 5. Table's rules are never considered as special rows.
  2435. (org-test-with-parsed-data "|---+---|"
  2436. (should-not
  2437. (org-export-table-row-is-special-p
  2438. (org-element-map tree 'table-row 'identity nil 'first-match) info))))
  2439. (ert-deftest test-org-export/has-header-p ()
  2440. "Test `org-export-table-has-header-p' specifications."
  2441. ;; 1. With an header.
  2442. (org-test-with-parsed-data "
  2443. | a | b |
  2444. |---+---|
  2445. | c | d |"
  2446. (should
  2447. (org-export-table-has-header-p
  2448. (org-element-map tree 'table 'identity info 'first-match)
  2449. info)))
  2450. ;; 2. Without an header.
  2451. (org-test-with-parsed-data "
  2452. | a | b |
  2453. | c | d |"
  2454. (should-not
  2455. (org-export-table-has-header-p
  2456. (org-element-map tree 'table 'identity info 'first-match)
  2457. info)))
  2458. ;; 3. Don't get fooled with starting and ending rules.
  2459. (org-test-with-parsed-data "
  2460. |---+---|
  2461. | a | b |
  2462. | c | d |
  2463. |---+---|"
  2464. (should-not
  2465. (org-export-table-has-header-p
  2466. (org-element-map tree 'table 'identity info 'first-match)
  2467. info))))
  2468. (ert-deftest test-org-export/table-row-group ()
  2469. "Test `org-export-table-row-group' specifications."
  2470. ;; 1. A rule creates a new group.
  2471. (should
  2472. (equal '(1 rule 2)
  2473. (org-test-with-parsed-data "
  2474. | a | b |
  2475. |---+---|
  2476. | 1 | 2 |"
  2477. (org-element-map tree 'table-row
  2478. (lambda (row)
  2479. (if (eq (org-element-property :type row) 'rule) 'rule
  2480. (org-export-table-row-group row info)))))))
  2481. ;; 2. Special rows are ignored in count.
  2482. (should
  2483. (equal
  2484. '(rule 1)
  2485. (org-test-with-parsed-data "
  2486. | / | < | > |
  2487. |---|---+---|
  2488. | | 1 | 2 |"
  2489. (org-element-map tree 'table-row
  2490. (lambda (row)
  2491. (if (eq (org-element-property :type row) 'rule) 'rule
  2492. (org-export-table-row-group row info)))
  2493. info))))
  2494. ;; 3. Double rules also are ignored in count.
  2495. (should
  2496. (equal '(1 rule rule 2)
  2497. (org-test-with-parsed-data "
  2498. | a | b |
  2499. |---+---|
  2500. |---+---|
  2501. | 1 | 2 |"
  2502. (org-element-map tree 'table-row
  2503. (lambda (row)
  2504. (if (eq (org-element-property :type row) 'rule) 'rule
  2505. (org-export-table-row-group row info))))))))
  2506. (ert-deftest test-org-export/table-row-number ()
  2507. "Test `org-export-table-row-number' specifications."
  2508. ;; Standard test. Number is 0-indexed.
  2509. (should
  2510. (equal '(0 1)
  2511. (org-test-with-parsed-data "| a | b | c |\n| d | e | f |"
  2512. (org-element-map tree 'table-row
  2513. (lambda (row) (org-export-table-row-number row info)) info))))
  2514. ;; Number ignores separators.
  2515. (should
  2516. (equal '(0 1)
  2517. (org-test-with-parsed-data "
  2518. | a | b | c |
  2519. |---+---+---|
  2520. | d | e | f |"
  2521. (org-element-map tree 'table-row
  2522. (lambda (row) (org-export-table-row-number row info)) info))))
  2523. ;; Number ignores special rows.
  2524. (should
  2525. (equal '(0 1)
  2526. (org-test-with-parsed-data "
  2527. | / | < | > |
  2528. | | b | c |
  2529. |---+-----+-----|
  2530. | | <c> | <c> |
  2531. | | e | f |"
  2532. (org-element-map tree 'table-row
  2533. (lambda (row) (org-export-table-row-number row info)) info)))))
  2534. (ert-deftest test-org-export/table-cell-width ()
  2535. "Test `org-export-table-cell-width' specifications."
  2536. ;; 1. Width is primarily determined by width cookies. If no cookie
  2537. ;; is found, cell's width is nil.
  2538. (org-test-with-parsed-data "
  2539. | / | <l> | <6> | <l7> |
  2540. | | a | b | c |"
  2541. (should
  2542. (equal
  2543. '(nil 6 7)
  2544. (mapcar (lambda (cell) (org-export-table-cell-width cell info))
  2545. (org-element-map tree 'table-cell 'identity info)))))
  2546. ;; 2. The last width cookie has precedence.
  2547. (org-test-with-parsed-data "
  2548. | <6> |
  2549. | <7> |
  2550. | a |"
  2551. (should
  2552. (equal
  2553. '(7)
  2554. (mapcar (lambda (cell) (org-export-table-cell-width cell info))
  2555. (org-element-map tree 'table-cell 'identity info)))))
  2556. ;; 3. Valid width cookies must have a specific row.
  2557. (org-test-with-parsed-data "| <6> | cell |"
  2558. (should
  2559. (equal
  2560. '(nil nil)
  2561. (mapcar (lambda (cell) (org-export-table-cell-width cell info))
  2562. (org-element-map tree 'table-cell 'identity))))))
  2563. (ert-deftest test-org-export/table-cell-alignment ()
  2564. "Test `org-export-table-cell-alignment' specifications."
  2565. ;; 1. Alignment is primarily determined by alignment cookies.
  2566. (should
  2567. (equal '(left center right)
  2568. (let ((org-table-number-fraction 0.5)
  2569. (org-table-number-regexp "^[0-9]+$"))
  2570. (org-test-with-parsed-data "| <l> | <c> | <r> |"
  2571. (mapcar (lambda (cell)
  2572. (org-export-table-cell-alignment cell info))
  2573. (org-element-map tree 'table-cell 'identity))))))
  2574. ;; 2. The last alignment cookie has precedence.
  2575. (should
  2576. (equal '(right right right)
  2577. (org-test-with-parsed-data "
  2578. | <l8> |
  2579. | cell |
  2580. | <r9> |"
  2581. (mapcar (lambda (cell) (org-export-table-cell-alignment cell info))
  2582. (org-element-map tree 'table-cell 'identity)))))
  2583. ;; 3. If there's no cookie, cell's contents determine alignment.
  2584. ;; A column mostly made of cells containing numbers will align
  2585. ;; its cells to the right.
  2586. (should
  2587. (equal '(right right right)
  2588. (let ((org-table-number-fraction 0.5)
  2589. (org-table-number-regexp "^[0-9]+$"))
  2590. (org-test-with-parsed-data "
  2591. | 123 |
  2592. | some text |
  2593. | 12345 |"
  2594. (mapcar (lambda (cell)
  2595. (org-export-table-cell-alignment cell info))
  2596. (org-element-map tree 'table-cell 'identity))))))
  2597. ;; 4. Otherwise, they will be aligned to the left.
  2598. (should
  2599. (equal '(left left left)
  2600. (org-test-with-parsed-data "
  2601. | text |
  2602. | some text |
  2603. | \alpha |"
  2604. (mapcar (lambda (cell)
  2605. (org-export-table-cell-alignment cell info))
  2606. (org-element-map tree 'table-cell 'identity info))))))
  2607. (ert-deftest test-org-export/table-cell-borders ()
  2608. "Test `org-export-table-cell-borders' specifications."
  2609. ;; 1. Recognize various column groups indicators.
  2610. (org-test-with-parsed-data "| / | < | > | <> |"
  2611. (should
  2612. (equal
  2613. '((right bottom top) (left bottom top) (right bottom top)
  2614. (right left bottom top))
  2615. (mapcar (lambda (cell)
  2616. (org-export-table-cell-borders cell info))
  2617. (org-element-map tree 'table-cell 'identity)))))
  2618. ;; 2. Accept shortcuts to define column groups.
  2619. (org-test-with-parsed-data "| / | < | < |"
  2620. (should
  2621. (equal
  2622. '((right bottom top) (right left bottom top) (left bottom top))
  2623. (mapcar (lambda (cell)
  2624. (org-export-table-cell-borders cell info))
  2625. (org-element-map tree 'table-cell 'identity)))))
  2626. ;; 3. A valid column groups row must start with a "/".
  2627. (org-test-with-parsed-data "
  2628. | | < |
  2629. | a | b |"
  2630. (should
  2631. (equal '((top) (top) (bottom) (bottom))
  2632. (mapcar (lambda (cell)
  2633. (org-export-table-cell-borders cell info))
  2634. (org-element-map tree 'table-cell 'identity)))))
  2635. ;; 4. Take table rules into consideration.
  2636. (org-test-with-parsed-data "
  2637. | 1 |
  2638. |---|
  2639. | 2 |"
  2640. (should
  2641. (equal '((below top) (bottom above))
  2642. (mapcar (lambda (cell)
  2643. (org-export-table-cell-borders cell info))
  2644. (org-element-map tree 'table-cell 'identity)))))
  2645. ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
  2646. ;; (resp. `bottom' and `below') borders. Any special row is
  2647. ;; ignored.
  2648. (org-test-with-parsed-data "
  2649. |---+----|
  2650. | / | |
  2651. | | 1 |
  2652. |---+----|"
  2653. (should
  2654. (equal '((bottom below top above))
  2655. (last
  2656. (mapcar (lambda (cell)
  2657. (org-export-table-cell-borders cell info))
  2658. (org-element-map tree 'table-cell 'identity)))))))
  2659. (ert-deftest test-org-export/table-dimensions ()
  2660. "Test `org-export-table-dimensions' specifications."
  2661. ;; 1. Standard test.
  2662. (org-test-with-parsed-data "
  2663. | 1 | 2 | 3 |
  2664. | 4 | 5 | 6 |"
  2665. (should
  2666. (equal '(2 . 3)
  2667. (org-export-table-dimensions
  2668. (org-element-map tree 'table 'identity info 'first-match) info))))
  2669. ;; 2. Ignore horizontal rules and special columns.
  2670. (org-test-with-parsed-data "
  2671. | / | < | > |
  2672. | 1 | 2 | 3 |
  2673. |---+---+---|
  2674. | 4 | 5 | 6 |"
  2675. (should
  2676. (equal '(2 . 3)
  2677. (org-export-table-dimensions
  2678. (org-element-map tree 'table 'identity info 'first-match) info)))))
  2679. (ert-deftest test-org-export/table-cell-address ()
  2680. "Test `org-export-table-cell-address' specifications."
  2681. ;; 1. Standard test: index is 0-based.
  2682. (org-test-with-parsed-data "| a | b |"
  2683. (should
  2684. (equal '((0 . 0) (0 . 1))
  2685. (org-element-map tree 'table-cell
  2686. (lambda (cell) (org-export-table-cell-address cell info))
  2687. info))))
  2688. ;; 2. Special column isn't counted, nor are special rows.
  2689. (org-test-with-parsed-data "
  2690. | / | <> |
  2691. | | c |"
  2692. (should
  2693. (equal '(0 . 0)
  2694. (org-export-table-cell-address
  2695. (car (last (org-element-map tree 'table-cell 'identity info)))
  2696. info))))
  2697. ;; 3. Tables rules do not count either.
  2698. (org-test-with-parsed-data "
  2699. | a |
  2700. |---|
  2701. | b |
  2702. |---|
  2703. | c |"
  2704. (should
  2705. (equal '(2 . 0)
  2706. (org-export-table-cell-address
  2707. (car (last (org-element-map tree 'table-cell 'identity info)))
  2708. info))))
  2709. ;; 4. Return nil for special cells.
  2710. (org-test-with-parsed-data "| / | a |"
  2711. (should-not
  2712. (org-export-table-cell-address
  2713. (org-element-map tree 'table-cell 'identity nil 'first-match)
  2714. info))))
  2715. (ert-deftest test-org-export/get-table-cell-at ()
  2716. "Test `org-export-get-table-cell-at' specifications."
  2717. ;; 1. Address ignores special columns, special rows and rules.
  2718. (org-test-with-parsed-data "
  2719. | / | <> |
  2720. | | a |
  2721. |---+----|
  2722. | | b |"
  2723. (should
  2724. (equal '("b")
  2725. (org-element-contents
  2726. (org-export-get-table-cell-at
  2727. '(1 . 0)
  2728. (org-element-map tree 'table 'identity info 'first-match)
  2729. info)))))
  2730. ;; 2. Return value for a non-existent address is nil.
  2731. (org-test-with-parsed-data "| a |"
  2732. (should-not
  2733. (org-export-get-table-cell-at
  2734. '(2 . 2)
  2735. (org-element-map tree 'table 'identity info 'first-match)
  2736. info)))
  2737. (org-test-with-parsed-data "| / |"
  2738. (should-not
  2739. (org-export-get-table-cell-at
  2740. '(0 . 0)
  2741. (org-element-map tree 'table 'identity info 'first-match)
  2742. info))))
  2743. (ert-deftest test-org-export/table-cell-starts-colgroup-p ()
  2744. "Test `org-export-table-cell-starts-colgroup-p' specifications."
  2745. ;; 1. A cell at a beginning of a row always starts a column group.
  2746. (org-test-with-parsed-data "| a |"
  2747. (should
  2748. (org-export-table-cell-starts-colgroup-p
  2749. (org-element-map tree 'table-cell 'identity info 'first-match)
  2750. info)))
  2751. ;; 2. Special column should be ignored when determining the
  2752. ;; beginning of the row.
  2753. (org-test-with-parsed-data "
  2754. | / | |
  2755. | | a |"
  2756. (should
  2757. (org-export-table-cell-starts-colgroup-p
  2758. (org-element-map tree 'table-cell 'identity info 'first-match)
  2759. info)))
  2760. ;; 2. Explicit column groups.
  2761. (org-test-with-parsed-data "
  2762. | / | | < |
  2763. | a | b | c |"
  2764. (should
  2765. (equal
  2766. '(yes no yes)
  2767. (org-element-map tree 'table-cell
  2768. (lambda (cell)
  2769. (if (org-export-table-cell-starts-colgroup-p cell info) 'yes 'no))
  2770. info)))))
  2771. (ert-deftest test-org-export/table-cell-ends-colgroup-p ()
  2772. "Test `org-export-table-cell-ends-colgroup-p' specifications."
  2773. ;; 1. A cell at the end of a row always ends a column group.
  2774. (org-test-with-parsed-data "| a |"
  2775. (should
  2776. (org-export-table-cell-ends-colgroup-p
  2777. (org-element-map tree 'table-cell 'identity info 'first-match)
  2778. info)))
  2779. ;; 2. Special column should be ignored when determining the
  2780. ;; beginning of the row.
  2781. (org-test-with-parsed-data "
  2782. | / | |
  2783. | | a |"
  2784. (should
  2785. (org-export-table-cell-ends-colgroup-p
  2786. (org-element-map tree 'table-cell 'identity info 'first-match)
  2787. info)))
  2788. ;; 3. Explicit column groups.
  2789. (org-test-with-parsed-data "
  2790. | / | < | |
  2791. | a | b | c |"
  2792. (should
  2793. (equal
  2794. '(yes no yes)
  2795. (org-element-map tree 'table-cell
  2796. (lambda (cell)
  2797. (if (org-export-table-cell-ends-colgroup-p cell info) 'yes 'no))
  2798. info)))))
  2799. (ert-deftest test-org-export/table-row-starts-rowgroup-p ()
  2800. "Test `org-export-table-row-starts-rowgroup-p' specifications."
  2801. ;; 1. A row at the beginning of a table always starts a row group.
  2802. ;; So does a row following a table rule.
  2803. (org-test-with-parsed-data "
  2804. | a |
  2805. |---|
  2806. | b |"
  2807. (should
  2808. (equal
  2809. '(yes no yes)
  2810. (org-element-map tree 'table-row
  2811. (lambda (row)
  2812. (if (org-export-table-row-starts-rowgroup-p row info) 'yes 'no))
  2813. info))))
  2814. ;; 2. Special rows should be ignored when determining the beginning
  2815. ;; of the row.
  2816. (org-test-with-parsed-data "
  2817. | / | < |
  2818. | | a |
  2819. |---+---|
  2820. | / | < |
  2821. | | b |"
  2822. (should
  2823. (equal
  2824. '(yes no yes)
  2825. (org-element-map tree 'table-row
  2826. (lambda (row)
  2827. (if (org-export-table-row-starts-rowgroup-p row info) 'yes 'no))
  2828. info)))))
  2829. (ert-deftest test-org-export/table-row-ends-rowgroup-p ()
  2830. "Test `org-export-table-row-ends-rowgroup-p' specifications."
  2831. ;; 1. A row at the end of a table always ends a row group. So does
  2832. ;; a row preceding a table rule.
  2833. (org-test-with-parsed-data "
  2834. | a |
  2835. |---|
  2836. | b |"
  2837. (should
  2838. (equal
  2839. '(yes no yes)
  2840. (org-element-map tree 'table-row
  2841. (lambda (row)
  2842. (if (org-export-table-row-ends-rowgroup-p row info) 'yes 'no))
  2843. info))))
  2844. ;; 2. Special rows should be ignored when determining the beginning
  2845. ;; of the row.
  2846. (org-test-with-parsed-data "
  2847. | | a |
  2848. | / | < |
  2849. |---+---|
  2850. | | b |
  2851. | / | < |"
  2852. (should
  2853. (equal
  2854. '(yes no yes)
  2855. (org-element-map tree 'table-row
  2856. (lambda (row)
  2857. (if (org-export-table-row-ends-rowgroup-p row info) 'yes 'no))
  2858. info)))))
  2859. (ert-deftest test-org-export/table-row-in-header-p ()
  2860. "Test `org-export-table-row-in-header-p' specifications."
  2861. ;; Standard test. Separators are always nil.
  2862. (should
  2863. (equal
  2864. '(yes no no)
  2865. (org-test-with-parsed-data "| a |\n|---|\n| b |"
  2866. (org-element-map tree 'table-row
  2867. (lambda (row)
  2868. (if (org-export-table-row-in-header-p row info) 'yes 'no)) info))))
  2869. ;; Nil when there is no header.
  2870. (should
  2871. (equal
  2872. '(no no)
  2873. (org-test-with-parsed-data "| a |\n| b |"
  2874. (org-element-map tree 'table-row
  2875. (lambda (row)
  2876. (if (org-export-table-row-in-header-p row info) 'yes 'no)) info)))))
  2877. (ert-deftest test-org-export/table-row-starts-header-p ()
  2878. "Test `org-export-table-row-starts-header-p' specifications."
  2879. ;; 1. Only the row starting the first row group starts the table
  2880. ;; header.
  2881. (org-test-with-parsed-data "
  2882. | a |
  2883. | b |
  2884. |---|
  2885. | c |"
  2886. (should
  2887. (equal
  2888. '(yes no no no)
  2889. (org-element-map tree 'table-row
  2890. (lambda (row)
  2891. (if (org-export-table-row-starts-header-p row info) 'yes 'no))
  2892. info))))
  2893. ;; 2. A row cannot start an header if there's no header in the
  2894. ;; table.
  2895. (org-test-with-parsed-data "
  2896. | a |
  2897. |---|"
  2898. (should-not
  2899. (org-export-table-row-starts-header-p
  2900. (org-element-map tree 'table-row 'identity info 'first-match)
  2901. info))))
  2902. (ert-deftest test-org-export/table-row-ends-header-p ()
  2903. "Test `org-export-table-row-ends-header-p' specifications."
  2904. ;; 1. Only the row starting the first row group starts the table
  2905. ;; header.
  2906. (org-test-with-parsed-data "
  2907. | a |
  2908. | b |
  2909. |---|
  2910. | c |"
  2911. (should
  2912. (equal
  2913. '(no yes no no)
  2914. (org-element-map tree 'table-row
  2915. (lambda (row)
  2916. (if (org-export-table-row-ends-header-p row info) 'yes 'no))
  2917. info))))
  2918. ;; 2. A row cannot start an header if there's no header in the
  2919. ;; table.
  2920. (org-test-with-parsed-data "
  2921. | a |
  2922. |---|"
  2923. (should-not
  2924. (org-export-table-row-ends-header-p
  2925. (org-element-map tree 'table-row 'identity info 'first-match)
  2926. info))))
  2927. ;;; Tables of Contents
  2928. (ert-deftest test-org-export/collect-headlines ()
  2929. "Test `org-export-collect-headlines' specifications."
  2930. ;; Standard test.
  2931. (should
  2932. (= 2
  2933. (length
  2934. (org-test-with-parsed-data "* H1\n** H2"
  2935. (org-export-collect-headlines info)))))
  2936. ;; Do not collect headlines below optional argument.
  2937. (should
  2938. (= 1
  2939. (length
  2940. (org-test-with-parsed-data "* H1\n** H2"
  2941. (org-export-collect-headlines info 1)))))
  2942. ;; Never collect headlines below maximum headline level.
  2943. (should
  2944. (= 1
  2945. (length
  2946. (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
  2947. (org-export-collect-headlines info)))))
  2948. (should
  2949. (= 1
  2950. (length
  2951. (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
  2952. (org-export-collect-headlines info 2))))))
  2953. ;;; Templates
  2954. (ert-deftest test-org-export/inner-template ()
  2955. "Test `inner-template' translator specifications."
  2956. (should
  2957. (equal "Success!"
  2958. (org-test-with-temp-text "* Headline"
  2959. (org-export-as
  2960. (org-export-create-backend
  2961. :transcoders
  2962. '((inner-template . (lambda (contents info) "Success!"))
  2963. (headline . (lambda (h c i) "Headline"))))))))
  2964. ;; Inner template is applied even in a "body-only" export.
  2965. (should
  2966. (equal "Success!"
  2967. (org-test-with-temp-text "* Headline"
  2968. (org-export-as
  2969. (org-export-create-backend
  2970. :transcoders '((inner-template . (lambda (c i) "Success!"))
  2971. (headline . (lambda (h c i) "Headline"))))
  2972. nil nil 'body-only)))))
  2973. (ert-deftest test-org-export/template ()
  2974. "Test `template' translator specifications."
  2975. (should
  2976. (equal "Success!"
  2977. (org-test-with-temp-text "* Headline"
  2978. (org-export-as
  2979. (org-export-create-backend
  2980. :transcoders '((template . (lambda (contents info) "Success!"))
  2981. (headline . (lambda (h c i) "Headline"))))))))
  2982. ;; Template is not applied in a "body-only" export.
  2983. (should-not
  2984. (equal "Success!"
  2985. (org-test-with-temp-text "* Headline"
  2986. (org-export-as
  2987. (org-export-create-backend
  2988. :transcoders '((template . (lambda (contents info) "Success!"))
  2989. (headline . (lambda (h c i) "Headline"))))
  2990. nil nil 'body-only)))))
  2991. ;;; Topology
  2992. (ert-deftest test-org-export/get-next-element ()
  2993. "Test `org-export-get-next-element' specifications."
  2994. ;; Standard test.
  2995. (should
  2996. (equal "b"
  2997. (org-test-with-parsed-data "* Headline\n*a* b"
  2998. (org-export-get-next-element
  2999. (org-element-map tree 'bold 'identity info t) info))))
  3000. ;; Return nil when no previous element.
  3001. (should-not
  3002. (org-test-with-parsed-data "* Headline\na *b*"
  3003. (org-export-get-next-element
  3004. (org-element-map tree 'bold 'identity info t) info)))
  3005. ;; Non-exportable elements are ignored.
  3006. (should-not
  3007. (let ((org-export-with-timestamps nil))
  3008. (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
  3009. (org-export-get-next-element
  3010. (org-element-map tree 'entity 'identity info t) info))))
  3011. ;; Find next element in secondary strings.
  3012. (should
  3013. (eq 'verbatim
  3014. (org-test-with-parsed-data "* a =verb="
  3015. (org-element-type
  3016. (org-export-get-next-element
  3017. (org-element-map tree 'plain-text 'identity info t) info)))))
  3018. (should
  3019. (eq 'verbatim
  3020. (org-test-with-parsed-data "* /italic/ =verb="
  3021. (org-element-type
  3022. (org-export-get-next-element
  3023. (org-element-map tree 'italic 'identity info t) info)))))
  3024. ;; Find next element in document keywords.
  3025. (should
  3026. (eq 'verbatim
  3027. (org-test-with-parsed-data "#+TITLE: a =verb="
  3028. (org-element-type
  3029. (org-export-get-next-element
  3030. (org-element-map
  3031. (plist-get info :title) 'plain-text 'identity info t) info)))))
  3032. ;; Find next element in parsed affiliated keywords.
  3033. (should
  3034. (eq 'verbatim
  3035. (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
  3036. (org-element-type
  3037. (org-export-get-next-element
  3038. (org-element-map tree 'plain-text 'identity info t nil t) info)))))
  3039. ;; With optional argument N, return a list containing all the
  3040. ;; following elements.
  3041. (should
  3042. (equal
  3043. '(bold code underline)
  3044. (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
  3045. (mapcar 'car
  3046. (org-export-get-next-element
  3047. (org-element-map tree 'italic 'identity info t) info t)))))
  3048. ;; When N is a positive integer, return a list containing up to
  3049. ;; N following elements.
  3050. (should
  3051. (equal
  3052. '(bold code)
  3053. (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
  3054. (mapcar 'car
  3055. (org-export-get-next-element
  3056. (org-element-map tree 'italic 'identity info t) info 2))))))
  3057. (ert-deftest test-org-export/get-previous-element ()
  3058. "Test `org-export-get-previous-element' specifications."
  3059. ;; Standard test.
  3060. (should
  3061. (equal "a "
  3062. (org-test-with-parsed-data "* Headline\na *b*"
  3063. (org-export-get-previous-element
  3064. (org-element-map tree 'bold 'identity info t) info))))
  3065. ;; Return nil when no previous element.
  3066. (should-not
  3067. (org-test-with-parsed-data "* Headline\n*a* b"
  3068. (org-export-get-previous-element
  3069. (org-element-map tree 'bold 'identity info t) info)))
  3070. ;; Non-exportable elements are ignored.
  3071. (should-not
  3072. (let ((org-export-with-timestamps nil))
  3073. (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
  3074. (org-export-get-previous-element
  3075. (org-element-map tree 'entity 'identity info t) info))))
  3076. ;; Find previous element in secondary strings.
  3077. (should
  3078. (eq 'verbatim
  3079. (org-test-with-parsed-data "* =verb= a"
  3080. (org-element-type
  3081. (org-export-get-previous-element
  3082. (org-element-map tree 'plain-text 'identity info t) info)))))
  3083. (should
  3084. (eq 'verbatim
  3085. (org-test-with-parsed-data "* =verb= /italic/"
  3086. (org-element-type
  3087. (org-export-get-previous-element
  3088. (org-element-map tree 'italic 'identity info t) info)))))
  3089. ;; Find previous element in document keywords.
  3090. (should
  3091. (eq 'verbatim
  3092. (org-test-with-parsed-data "#+TITLE: =verb= a"
  3093. (org-element-type
  3094. (org-export-get-previous-element
  3095. (org-element-map
  3096. (plist-get info :title) 'plain-text 'identity info t) info)))))
  3097. ;; Find previous element in parsed affiliated keywords.
  3098. (should
  3099. (eq 'verbatim
  3100. (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
  3101. (org-element-type
  3102. (org-export-get-previous-element
  3103. (org-element-map tree 'plain-text 'identity info t nil t) info)))))
  3104. ;; With optional argument N, return a list containing up to
  3105. ;; N previous elements.
  3106. (should
  3107. (equal '(underline italic bold)
  3108. (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
  3109. (mapcar 'car
  3110. (org-export-get-previous-element
  3111. (org-element-map tree 'code 'identity info t) info t)))))
  3112. ;; When N is a positive integer, return a list containing up to
  3113. ;; N previous elements.
  3114. (should
  3115. (equal '(italic bold)
  3116. (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
  3117. (mapcar 'car
  3118. (org-export-get-previous-element
  3119. (org-element-map tree 'code 'identity info t) info 2))))))
  3120. (provide 'test-ox)
  3121. ;;; test-org-export.el end here