test-ox.el 108 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260
  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 be provided a fallback
  1477. ;; definition.
  1478. (should
  1479. (org-test-with-parsed-data "[fn:1]"
  1480. (org-export-get-footnote-definition
  1481. (org-element-map tree 'footnote-reference 'identity info t) info)))
  1482. ;; 7. Footnote section should be ignored in TOC and in headlines
  1483. ;; numbering.
  1484. (should
  1485. (= 1 (let ((org-footnote-section "Footnotes"))
  1486. (length (org-test-with-parsed-data "* H1\n* Footnotes\n"
  1487. (org-export-collect-headlines info))))))
  1488. (should
  1489. (equal '(2)
  1490. (let ((org-footnote-section "Footnotes"))
  1491. (org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
  1492. (org-element-map tree 'headline
  1493. (lambda (hl)
  1494. (when (equal (org-element-property :raw-value hl) "H2")
  1495. (org-export-get-headline-number hl info)))
  1496. info t)))))))
  1497. ;;; Headlines and Inlinetasks
  1498. (ert-deftest test-org-export/get-relative-level ()
  1499. "Test `org-export-get-relative-level' specifications."
  1500. ;; Standard test.
  1501. (should
  1502. (equal '(1 2)
  1503. (let ((org-odd-levels-only nil))
  1504. (org-test-with-parsed-data "* Headline 1\n** Headline 2"
  1505. (org-element-map tree 'headline
  1506. (lambda (h) (org-export-get-relative-level h info))
  1507. info)))))
  1508. ;; Missing levels
  1509. (should
  1510. (equal '(1 3)
  1511. (let ((org-odd-levels-only nil))
  1512. (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
  1513. (org-element-map tree 'headline
  1514. (lambda (h) (org-export-get-relative-level h info))
  1515. info))))))
  1516. (ert-deftest test-org-export/low-level-p ()
  1517. "Test `org-export-low-level-p' specifications."
  1518. (should
  1519. (equal
  1520. '(no yes)
  1521. (let ((org-odd-levels-only nil))
  1522. (org-test-with-parsed-data "* Headline 1\n** Headline 2"
  1523. (org-element-map tree 'headline
  1524. (lambda (h) (if (org-export-low-level-p h info) 'yes 'no))
  1525. (plist-put info :headline-levels 1)))))))
  1526. (ert-deftest test-org-export/get-headline-number ()
  1527. "Test `org-export-get-headline-number' specifications."
  1528. ;; Standard test.
  1529. (should
  1530. (equal
  1531. '((1) (1 1))
  1532. (let ((org-odd-levels-only nil))
  1533. (org-test-with-parsed-data "* Headline 1\n** Headline 2"
  1534. (org-element-map tree 'headline
  1535. (lambda (h) (org-export-get-headline-number h info))
  1536. info)))))
  1537. ;; Missing levels are replaced with 0.
  1538. (should
  1539. (equal
  1540. '((1) (1 0 1))
  1541. (let ((org-odd-levels-only nil))
  1542. (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
  1543. (org-element-map tree 'headline
  1544. (lambda (h) (org-export-get-headline-number h info))
  1545. info))))))
  1546. (ert-deftest test-org-export/numbered-headline-p ()
  1547. "Test `org-export-numbered-headline-p' specifications."
  1548. ;; If `:section-numbers' is nil, never number headlines.
  1549. (should-not
  1550. (org-test-with-parsed-data "* Headline"
  1551. (org-element-map tree 'headline
  1552. (lambda (h) (org-export-numbered-headline-p h info))
  1553. (plist-put info :section-numbers nil))))
  1554. ;; If `:section-numbers' is a number, only number headlines with
  1555. ;; a level greater that it.
  1556. (should
  1557. (equal
  1558. '(yes no)
  1559. (org-test-with-parsed-data "* Headline 1\n** Headline 2"
  1560. (org-element-map tree 'headline
  1561. (lambda (h) (if (org-export-numbered-headline-p h info) 'yes 'no))
  1562. (plist-put info :section-numbers 1)))))
  1563. ;; Otherwise, headlines are always numbered.
  1564. (should
  1565. (org-test-with-parsed-data "* Headline"
  1566. (org-element-map tree 'headline
  1567. (lambda (h) (org-export-numbered-headline-p h info))
  1568. (plist-put info :section-numbers t)))))
  1569. (ert-deftest test-org-export/org-export-get-headline-id ()
  1570. "Test `org-export-get-headline-id' specifications."
  1571. ;; Numbered headlines have IDs akin to "sec-N".
  1572. (should
  1573. (equal "sec-1"
  1574. (org-test-with-parsed-data "* H"
  1575. (org-export-get-headline-id
  1576. (org-element-map tree 'headline #'identity info t)
  1577. info))))
  1578. ;; The ID of numbered headlines reflect the hierarchy.
  1579. (should
  1580. (equal "sec-1-1"
  1581. (org-test-with-parsed-data "* H1\n** H2"
  1582. (org-export-get-headline-id
  1583. (org-element-map tree 'headline
  1584. (lambda (h)
  1585. (and (equal "H2" (org-element-property :raw-value h)) h))
  1586. info t)
  1587. info))))
  1588. ;; Unnumbered headlines have IDs akin to "unnumbered-N".
  1589. (should
  1590. (equal "unnumbered-1"
  1591. (org-test-with-parsed-data
  1592. "* H\n:PROPERTIES:\n:UNNUMBERED: t\n:END:"
  1593. (org-export-get-headline-id
  1594. (org-element-map tree 'headline #'identity info t)
  1595. info))))
  1596. ;; The ID of Unnumbered headlines do not reflect the hierarchy.
  1597. (should
  1598. (equal "unnumbered-2"
  1599. (org-test-with-parsed-data
  1600. "* H1\n:PROPERTIES:\n:UNNUMBERED: t\n:END:\n** H2"
  1601. (org-export-get-headline-id
  1602. (org-element-map tree 'headline
  1603. (lambda (h)
  1604. (and (equal "H2" (org-element-property :raw-value h)) h))
  1605. info t)
  1606. info))))
  1607. ;; When #+OPTIONS: num:nil all headlines are unnumbered.
  1608. (should
  1609. (equal "unnumbered-1"
  1610. (org-test-with-parsed-data "* H\n#+OPTIONS: num:nil"
  1611. (org-export-get-headline-id
  1612. (org-element-map tree 'headline 'identity info t)
  1613. info))))
  1614. ;; UNNUMBERED ignores inheritance. Any non-nil value among
  1615. ;; ancestors disables numbering.
  1616. (should
  1617. (org-test-with-parsed-data
  1618. "* H
  1619. :PROPERTIES:
  1620. :UNNUMBERED: t
  1621. :END:
  1622. ** H2
  1623. :PROPERTIES:
  1624. :UNNUMBERED: nil
  1625. :END:
  1626. *** H3"
  1627. (org-every
  1628. (lambda (h) (not (org-export-numbered-headline-p h info)))
  1629. (org-element-map tree 'headline #'identity info)))))
  1630. (ert-deftest test-org-export/number-to-roman ()
  1631. "Test `org-export-number-to-roman' specifications."
  1632. ;; If number is negative, return it as a string.
  1633. (should (equal (org-export-number-to-roman -1) "-1"))
  1634. ;; Otherwise, return it as a roman number.
  1635. (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
  1636. (ert-deftest test-org-export/get-optional-title ()
  1637. "Test `org-export-get-alt-title' specifications."
  1638. ;; If ALT_TITLE property is defined, use it.
  1639. (should
  1640. (equal '("opt")
  1641. (org-test-with-parsed-data
  1642. "* Headline\n:PROPERTIES:\n:ALT_TITLE: opt\n:END:"
  1643. (org-export-get-alt-title
  1644. (org-element-map tree 'headline 'identity info t)
  1645. info))))
  1646. ;; Otherwise, fall-back to regular title.
  1647. (should
  1648. (equal '("Headline")
  1649. (org-test-with-parsed-data "* Headline"
  1650. (org-export-get-alt-title
  1651. (org-element-map tree 'headline 'identity info t)
  1652. info)))))
  1653. (ert-deftest test-org-export/get-tags ()
  1654. "Test `org-export-get-tags' specifications."
  1655. (let ((org-export-exclude-tags '("noexport"))
  1656. (org-export-select-tags '("export")))
  1657. ;; Standard test: tags which are not a select tag, an exclude tag,
  1658. ;; or specified as optional argument shouldn't be ignored.
  1659. (should
  1660. (org-test-with-parsed-data "* Headline :tag:"
  1661. (org-export-get-tags (org-element-map tree 'headline 'identity info t)
  1662. info)))
  1663. ;; Exclude tags are removed.
  1664. (should-not
  1665. (org-test-with-parsed-data "* Headline :noexport:"
  1666. (org-export-get-tags (org-element-map tree 'headline 'identity info t)
  1667. info)))
  1668. ;; Select tags are removed.
  1669. (should-not
  1670. (org-test-with-parsed-data "* Headline :export:"
  1671. (org-export-get-tags (org-element-map tree 'headline 'identity info t)
  1672. info)))
  1673. (should
  1674. (equal
  1675. '("tag")
  1676. (org-test-with-parsed-data "* Headline :tag:export:"
  1677. (org-export-get-tags (org-element-map tree 'headline 'identity info t)
  1678. info))))
  1679. ;; Tags provided in the optional argument are also ignored.
  1680. (should-not
  1681. (org-test-with-parsed-data "* Headline :ignore:"
  1682. (org-export-get-tags (org-element-map tree 'headline 'identity info t)
  1683. info '("ignore"))))
  1684. ;; Allow tag inheritance.
  1685. (should
  1686. (equal
  1687. '(("tag") ("tag"))
  1688. (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
  1689. (org-element-map tree 'headline
  1690. (lambda (hl) (org-export-get-tags hl info nil t)) info))))
  1691. ;; Tag inheritance checks FILETAGS keywords.
  1692. (should
  1693. (equal
  1694. '(("a" "b" "tag"))
  1695. (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
  1696. (org-element-map tree 'headline
  1697. (lambda (hl) (org-export-get-tags hl info nil t)) info))))))
  1698. (ert-deftest test-org-export/get-node-property ()
  1699. "Test`org-export-get-node-property' specifications."
  1700. ;; Standard test.
  1701. (should
  1702. (equal "value"
  1703. (org-test-with-parsed-data "* Headline
  1704. :PROPERTIES:
  1705. :prop: value
  1706. :END:"
  1707. (org-export-get-node-property
  1708. :PROP (org-element-map tree 'headline 'identity nil t)))))
  1709. ;; Test inheritance.
  1710. (should
  1711. (equal "value"
  1712. (org-test-with-parsed-data "* Parent
  1713. :PROPERTIES:
  1714. :prop: value
  1715. :END:
  1716. ** Headline
  1717. Paragraph"
  1718. (org-export-get-node-property
  1719. :PROP (org-element-map tree 'paragraph 'identity nil t) t))))
  1720. ;; Cannot return a value before the first headline.
  1721. (should-not
  1722. (org-test-with-parsed-data "Paragraph
  1723. * Headline
  1724. :PROPERTIES:
  1725. :prop: value
  1726. :END:"
  1727. (org-export-get-node-property
  1728. :PROP (org-element-map tree 'paragraph 'identity nil t)))))
  1729. (ert-deftest test-org-export/get-category ()
  1730. "Test `org-export-get-category' specifications."
  1731. ;; Standard test.
  1732. (should
  1733. (equal "value"
  1734. (org-test-with-parsed-data "* Headline
  1735. :PROPERTIES:
  1736. :CATEGORY: value
  1737. :END:"
  1738. (org-export-get-category
  1739. (org-element-map tree 'headline 'identity nil t) info))))
  1740. ;; Test inheritance from a parent headline.
  1741. (should
  1742. (equal '("value" "value")
  1743. (org-test-with-parsed-data "* Headline1
  1744. :PROPERTIES:
  1745. :CATEGORY: value
  1746. :END:
  1747. ** Headline2"
  1748. (org-element-map tree 'headline
  1749. (lambda (hl) (org-export-get-category hl info)) info))))
  1750. ;; Test inheritance from #+CATEGORY keyword
  1751. (should
  1752. (equal "value"
  1753. (org-test-with-parsed-data "#+CATEGORY: value
  1754. * Headline"
  1755. (org-export-get-category
  1756. (org-element-map tree 'headline 'identity nil t) info))))
  1757. ;; Test inheritance from file name.
  1758. (should
  1759. (equal "test"
  1760. (org-test-with-parsed-data "* Headline"
  1761. (let ((info (plist-put info :input-file "~/test.org")))
  1762. (org-export-get-category
  1763. (org-element-map tree 'headline 'identity nil t) info)))))
  1764. ;; Fall-back value.
  1765. (should
  1766. (equal "???"
  1767. (org-test-with-parsed-data "* Headline"
  1768. (org-export-get-category
  1769. (org-element-map tree 'headline 'identity nil t) info)))))
  1770. (ert-deftest test-org-export/first-sibling-p ()
  1771. "Test `org-export-first-sibling-p' specifications."
  1772. ;; Standard test.
  1773. (should
  1774. (equal
  1775. '(yes yes no)
  1776. (org-test-with-parsed-data "* H\n** H 2\n** H 3"
  1777. (org-element-map tree 'headline
  1778. (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
  1779. info))))
  1780. (should
  1781. (equal '(yes no)
  1782. (org-test-with-parsed-data "- item\n\n para"
  1783. (org-element-map tree 'paragraph
  1784. (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
  1785. info))))
  1786. ;; Ignore sections for headlines.
  1787. (should
  1788. (equal '(yes yes)
  1789. (org-test-with-parsed-data "* H\nSection\n** H 2"
  1790. (org-element-map tree 'headline
  1791. (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
  1792. info))))
  1793. ;; Ignore headlines not exported.
  1794. (should
  1795. (equal
  1796. '(yes)
  1797. (let ((org-export-exclude-tags '("ignore")))
  1798. (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
  1799. (org-element-map tree 'headline
  1800. (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
  1801. info))))))
  1802. (ert-deftest test-org-export/last-sibling-p ()
  1803. "Test `org-export-last-sibling-p' specifications."
  1804. ;; Standard test.
  1805. (should
  1806. (equal
  1807. '(yes no yes)
  1808. (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
  1809. (org-element-map tree 'headline
  1810. (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
  1811. info))))
  1812. (should
  1813. (equal '(no yes)
  1814. (org-test-with-parsed-data "- item\n\n para"
  1815. (org-element-map tree 'paragraph
  1816. (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
  1817. info))))
  1818. ;; Ignore headlines not exported.
  1819. (should
  1820. (equal
  1821. '(yes)
  1822. (let ((org-export-exclude-tags '("ignore")))
  1823. (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
  1824. (org-element-map tree 'headline
  1825. (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
  1826. info))))))
  1827. (ert-deftest test-org-export/handle-inlinetasks ()
  1828. "Test inlinetask export."
  1829. ;; Inlinetask with an exclude tag.
  1830. (when (featurep 'org-inlinetask)
  1831. (should
  1832. (equal
  1833. ""
  1834. (let ((org-inlinetask-min-level 3))
  1835. (org-test-with-temp-text "*** Inlinetask :noexp:\nContents\n*** end"
  1836. (org-export-as (org-test-default-backend)
  1837. nil nil nil '(:exclude-tags ("noexp")))))))
  1838. ;; Inlinetask with an include tag.
  1839. (should
  1840. (equal
  1841. "* H2\n*** Inline :exp:\n"
  1842. (let ((org-inlinetask-min-level 3)
  1843. (org-tags-column 0))
  1844. (org-test-with-temp-text "* H1\n* H2\n*** Inline :exp:"
  1845. (org-export-as (org-test-default-backend)
  1846. nil nil nil '(:select-tags ("exp")))))))
  1847. ;; Ignore inlinetask with a TODO keyword and tasks excluded.
  1848. (should
  1849. (equal ""
  1850. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  1851. (org-inlinetask-min-level 3))
  1852. (org-test-with-temp-text "*** TODO Inline"
  1853. (org-export-as (org-test-default-backend)
  1854. nil nil nil '(:with-tasks nil))))))))
  1855. ;;; Keywords
  1856. (ert-deftest test-org-export/get-date ()
  1857. "Test `org-export-get-date' specifications."
  1858. ;; Return a properly formatted string when
  1859. ;; `org-export-date-timestamp-format' is non-nil and DATE keyword
  1860. ;; consists in a single timestamp.
  1861. (should
  1862. (equal "29 03 2012"
  1863. (let ((org-export-date-timestamp-format "%d %m %Y"))
  1864. (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
  1865. (org-export-get-date info)))))
  1866. ;; Return a secondary string otherwise.
  1867. (should-not
  1868. (stringp
  1869. (let ((org-export-date-timestamp-format nil))
  1870. (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
  1871. (org-export-get-date info)))))
  1872. (should
  1873. (equal '("Date")
  1874. (org-test-with-parsed-data "#+DATE: Date"
  1875. (org-export-get-date info))))
  1876. ;; Optional argument has precedence over
  1877. ;; `org-export-date-timestamp-format'.
  1878. (should
  1879. (equal "29 03"
  1880. (let ((org-export-date-timestamp-format "%d %m %Y"))
  1881. (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
  1882. (org-export-get-date info "%d %m"))))))
  1883. ;;; Links
  1884. (ert-deftest test-org-export/get-coderef-format ()
  1885. "Test `org-export-get-coderef-format' specifications."
  1886. ;; A link without description returns "%s"
  1887. (should (equal (org-export-get-coderef-format "(ref:line)" nil)
  1888. "%s"))
  1889. ;; Return "%s" when path is matched within description.
  1890. (should (equal (org-export-get-coderef-format "path" "desc (path)")
  1891. "desc %s"))
  1892. ;; Otherwise return description.
  1893. (should (equal (org-export-get-coderef-format "path" "desc")
  1894. "desc")))
  1895. (ert-deftest test-org-export/inline-image-p ()
  1896. "Test `org-export-inline-image-p' specifications."
  1897. (should
  1898. (org-export-inline-image-p
  1899. (org-test-with-temp-text "[[#id]]"
  1900. (org-element-map (org-element-parse-buffer) 'link 'identity nil t))
  1901. '(("custom-id" . "id")))))
  1902. (ert-deftest test-org-export/fuzzy-link ()
  1903. "Test fuzzy links specifications."
  1904. ;; Link to an headline should return headline's number.
  1905. (org-test-with-parsed-data
  1906. "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
  1907. (should
  1908. ;; Note: Headline's number is in fact a list of numbers.
  1909. (equal '(2)
  1910. (org-element-map tree 'link
  1911. (lambda (link)
  1912. (org-export-get-ordinal
  1913. (org-export-resolve-fuzzy-link link info) info)) info t))))
  1914. ;; Link to a target in an item should return item's number.
  1915. (org-test-with-parsed-data
  1916. "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
  1917. (should
  1918. ;; Note: Item's number is in fact a list of numbers.
  1919. (equal '(1 2)
  1920. (org-element-map tree 'link
  1921. (lambda (link)
  1922. (org-export-get-ordinal
  1923. (org-export-resolve-fuzzy-link link info) info)) info t))))
  1924. ;; Link to a target in a footnote should return footnote's number.
  1925. (org-test-with-parsed-data "
  1926. Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
  1927. (should
  1928. (equal '(2 3)
  1929. (org-element-map tree 'link
  1930. (lambda (link)
  1931. (org-export-get-ordinal
  1932. (org-export-resolve-fuzzy-link link info) info)) info))))
  1933. ;; Link to a named element should return sequence number of that
  1934. ;; element.
  1935. (org-test-with-parsed-data
  1936. "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
  1937. (should
  1938. (= 2
  1939. (org-element-map tree 'link
  1940. (lambda (link)
  1941. (org-export-get-ordinal
  1942. (org-export-resolve-fuzzy-link link info) info)) info t))))
  1943. ;; Link to a target not within an item, a table, a footnote
  1944. ;; reference or definition should return section number.
  1945. (org-test-with-parsed-data
  1946. "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
  1947. (should
  1948. (equal '(2)
  1949. (org-element-map tree 'link
  1950. (lambda (link)
  1951. (org-export-get-ordinal
  1952. (org-export-resolve-fuzzy-link link info) info)) info t))))
  1953. ;; Space are not significant when matching a fuzzy link.
  1954. (should
  1955. (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
  1956. (org-element-map tree 'link
  1957. (lambda (link) (org-export-resolve-fuzzy-link link info))
  1958. info t)))
  1959. ;; Statistics cookies are ignored for headline match.
  1960. (should
  1961. (org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
  1962. (org-element-map tree 'link
  1963. (lambda (link) (org-export-resolve-fuzzy-link link info))
  1964. info t)))
  1965. (should
  1966. (org-test-with-parsed-data "* Head [100%]\n[[Head]]"
  1967. (org-element-map tree 'link
  1968. (lambda (link) (org-export-resolve-fuzzy-link link info))
  1969. info t)))
  1970. ;; Headline match is position dependent.
  1971. (should-not
  1972. (apply
  1973. 'eq
  1974. (org-test-with-parsed-data "* H1\n[[*H1]]\n* H1\n[[*H1]]"
  1975. (org-element-map tree 'link
  1976. (lambda (link) (org-export-resolve-fuzzy-link link info)) info)))))
  1977. (ert-deftest test-org-export/resolve-coderef ()
  1978. "Test `org-export-resolve-coderef' specifications."
  1979. (let ((org-coderef-label-format "(ref:%s)"))
  1980. ;; 1. A link to a "-n -k -r" block returns line number.
  1981. (org-test-with-parsed-data
  1982. "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
  1983. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  1984. (org-test-with-parsed-data
  1985. "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  1986. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  1987. ;; 2. A link to a "-n -r" block returns line number.
  1988. (org-test-with-parsed-data
  1989. "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
  1990. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  1991. (org-test-with-parsed-data
  1992. "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  1993. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  1994. ;; 3. A link to a "-n" block returns coderef.
  1995. (org-test-with-parsed-data
  1996. "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  1997. (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
  1998. (org-test-with-parsed-data
  1999. "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
  2000. (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
  2001. ;; 4. A link to a "-r" block returns line number.
  2002. (org-test-with-parsed-data
  2003. "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  2004. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  2005. (org-test-with-parsed-data
  2006. "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
  2007. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  2008. ;; 5. A link to a block without a switch returns coderef.
  2009. (org-test-with-parsed-data
  2010. "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  2011. (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
  2012. (org-test-with-parsed-data
  2013. "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
  2014. (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
  2015. ;; 6. Correctly handle continued line numbers. A "+n" switch
  2016. ;; should resume numbering from previous block with numbered
  2017. ;; lines, ignoring blocks not numbering lines in the process.
  2018. ;; A "-n" switch resets count.
  2019. (org-test-with-parsed-data "
  2020. #+BEGIN_EXAMPLE -n
  2021. Text.
  2022. #+END_EXAMPLE
  2023. #+BEGIN_SRC emacs-lisp
  2024. \(- 1 1)
  2025. #+END_SRC
  2026. #+BEGIN_SRC emacs-lisp +n -r
  2027. \(+ 1 1) (ref:addition)
  2028. #+END_SRC
  2029. #+BEGIN_EXAMPLE -n -r
  2030. Another text. (ref:text)
  2031. #+END_EXAMPLE"
  2032. (should (= (org-export-resolve-coderef "addition" info) 2))
  2033. (should (= (org-export-resolve-coderef "text" info) 1)))
  2034. ;; 7. Recognize coderef with user-specified syntax.
  2035. (org-test-with-parsed-data
  2036. "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
  2037. (should (equal (org-export-resolve-coderef "text" info) "text")))))
  2038. (ert-deftest test-org-export/resolve-fuzzy-link ()
  2039. "Test `org-export-resolve-fuzzy-link' specifications."
  2040. ;; Match target objects.
  2041. (should
  2042. (org-test-with-parsed-data "<<target>> [[target]]"
  2043. (org-export-resolve-fuzzy-link
  2044. (org-element-map tree 'link 'identity info t) info)))
  2045. ;; Match named elements.
  2046. (should
  2047. (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
  2048. (org-export-resolve-fuzzy-link
  2049. (org-element-map tree 'link 'identity info t) info)))
  2050. ;; Match exact headline's name.
  2051. (should
  2052. (org-test-with-parsed-data "* My headline\n[[My headline]]"
  2053. (org-export-resolve-fuzzy-link
  2054. (org-element-map tree 'link 'identity info t) info)))
  2055. ;; Targets objects have priority over named elements and headline
  2056. ;; titles.
  2057. (should
  2058. (eq 'target
  2059. (org-test-with-parsed-data
  2060. "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
  2061. (org-element-type
  2062. (org-export-resolve-fuzzy-link
  2063. (org-element-map tree 'link 'identity info t) info)))))
  2064. ;; Named elements have priority over headline titles.
  2065. (should
  2066. (eq 'paragraph
  2067. (org-test-with-parsed-data
  2068. "* target\n#+NAME: target\nParagraph\n\n[[target]]"
  2069. (org-element-type
  2070. (org-export-resolve-fuzzy-link
  2071. (org-element-map tree 'link 'identity info t) info)))))
  2072. ;; If link's path starts with a "*", only match headline titles,
  2073. ;; though.
  2074. (should
  2075. (eq 'headline
  2076. (org-test-with-parsed-data
  2077. "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
  2078. (org-element-type
  2079. (org-export-resolve-fuzzy-link
  2080. (org-element-map tree 'link 'identity info t) info)))))
  2081. ;; Return nil if no match.
  2082. (should-not
  2083. (org-test-with-parsed-data "[[target]]"
  2084. (org-export-resolve-fuzzy-link
  2085. (org-element-map tree 'link 'identity info t) info)))
  2086. ;; Match fuzzy link even when before first headline.
  2087. (should
  2088. (eq 'headline
  2089. (org-test-with-parsed-data "[[hl]]\n* hl"
  2090. (org-element-type
  2091. (org-export-resolve-fuzzy-link
  2092. (org-element-map tree 'link 'identity info t) info))))))
  2093. (ert-deftest test-org-export/resolve-id-link ()
  2094. "Test `org-export-resolve-id-link' specifications."
  2095. ;; 1. Regular test for custom-id link.
  2096. (org-test-with-parsed-data "* Headline1
  2097. :PROPERTIES:
  2098. :CUSTOM_ID: test
  2099. :END:
  2100. * Headline 2
  2101. \[[#test]]"
  2102. (should
  2103. (org-export-resolve-id-link
  2104. (org-element-map tree 'link 'identity info t) info)))
  2105. ;; 2. Failing test for custom-id link.
  2106. (org-test-with-parsed-data "* Headline1
  2107. :PROPERTIES:
  2108. :CUSTOM_ID: test
  2109. :END:
  2110. * Headline 2
  2111. \[[#no-match]]"
  2112. (should-not
  2113. (org-export-resolve-id-link
  2114. (org-element-map tree 'link 'identity info t) info)))
  2115. ;; 3. Test for internal id target.
  2116. (org-test-with-parsed-data "* Headline1
  2117. :PROPERTIES:
  2118. :ID: aaaa
  2119. :END:
  2120. * Headline 2
  2121. \[[id:aaaa]]"
  2122. (should
  2123. (org-export-resolve-id-link
  2124. (org-element-map tree 'link 'identity info t) info)))
  2125. ;; 4. Test for external id target.
  2126. (org-test-with-parsed-data "[[id:aaaa]]"
  2127. (should
  2128. (org-export-resolve-id-link
  2129. (org-element-map tree 'link 'identity info t)
  2130. (org-combine-plists info '(:id-alist (("aaaa" . "external-file"))))))))
  2131. (ert-deftest test-org-export/resolve-radio-link ()
  2132. "Test `org-export-resolve-radio-link' specifications."
  2133. ;; Standard test.
  2134. (should
  2135. (org-test-with-temp-text "<<<radio>>> radio"
  2136. (org-update-radio-target-regexp)
  2137. (let* ((tree (org-element-parse-buffer))
  2138. (info `(:parse-tree ,tree)))
  2139. (org-export-resolve-radio-link
  2140. (org-element-map tree 'link 'identity info t)
  2141. info))))
  2142. ;; Radio targets are case-insensitive.
  2143. (should
  2144. (org-test-with-temp-text "<<<RADIO>>> radio"
  2145. (org-update-radio-target-regexp)
  2146. (let* ((tree (org-element-parse-buffer))
  2147. (info `(:parse-tree ,tree)))
  2148. (org-export-resolve-radio-link
  2149. (org-element-map tree 'link 'identity info t)
  2150. info))))
  2151. ;; Radio target with objects.
  2152. (should
  2153. (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
  2154. (org-update-radio-target-regexp)
  2155. (let* ((tree (org-element-parse-buffer))
  2156. (info `(:parse-tree ,tree)))
  2157. (org-export-resolve-radio-link
  2158. (org-element-map tree 'link 'identity info t)
  2159. info))))
  2160. ;; Radio target with objects at its beginning.
  2161. (should
  2162. (org-test-with-temp-text "<<<\\alpha radio>>> \\alpha radio"
  2163. (org-update-radio-target-regexp)
  2164. (let* ((tree (org-element-parse-buffer))
  2165. (info `(:parse-tree ,tree)))
  2166. (org-export-resolve-radio-link
  2167. (org-element-map tree 'link 'identity info t)
  2168. info))))
  2169. ;; Radio link next to an apostrophe.
  2170. (should
  2171. (org-test-with-temp-text "<<<radio>>> radio's"
  2172. (org-update-radio-target-regexp)
  2173. (let* ((tree (org-element-parse-buffer))
  2174. (info `(:parse-tree ,tree)))
  2175. (org-export-resolve-radio-link
  2176. (org-element-map tree 'link 'identity info t)
  2177. info))))
  2178. ;; Multiple radio targets.
  2179. (should
  2180. (equal '("radio1" "radio2")
  2181. (org-test-with-temp-text "<<<radio1>>> <<<radio2>>> radio1 radio2"
  2182. (org-update-radio-target-regexp)
  2183. (let* ((tree (org-element-parse-buffer))
  2184. (info `(:parse-tree ,tree)))
  2185. (org-element-map tree 'link
  2186. (lambda (link)
  2187. (org-element-property
  2188. :value (org-export-resolve-radio-link link info)))
  2189. info)))))
  2190. ;; Radio target is whitespace insensitive.
  2191. (should
  2192. (org-test-with-temp-text "<<<a radio>>> a\n radio"
  2193. (org-update-radio-target-regexp)
  2194. (let* ((tree (org-element-parse-buffer))
  2195. (info `(:parse-tree ,tree)))
  2196. (org-element-map tree 'link
  2197. (lambda (link) (org-export-resolve-radio-link link info)) info t)))))
  2198. ;;; Src-block and example-block
  2199. (ert-deftest test-org-export/unravel-code ()
  2200. "Test `org-export-unravel-code' function."
  2201. ;; Code without reference.
  2202. (should
  2203. (equal '("(+ 1 1)\n")
  2204. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
  2205. (org-export-unravel-code (org-element-at-point)))))
  2206. ;; Code with reference.
  2207. (should
  2208. (equal '("(+ 1 1)\n" (1 . "test"))
  2209. (org-test-with-temp-text
  2210. "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
  2211. (let ((org-coderef-label-format "(ref:%s)"))
  2212. (org-export-unravel-code (org-element-at-point))))))
  2213. ;; Code with user-defined reference.
  2214. (should
  2215. (equal
  2216. '("(+ 1 1)\n" (1 . "test"))
  2217. (org-test-with-temp-text
  2218. "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
  2219. (let ((org-coderef-label-format "(ref:%s)"))
  2220. (org-export-unravel-code (org-element-at-point))))))
  2221. ;; Code references keys are relative to the current block.
  2222. (should
  2223. (equal '("(+ 2 2)\n(+ 3 3)\n" (2 . "one"))
  2224. (org-test-with-temp-text "
  2225. #+BEGIN_EXAMPLE -n
  2226. \(+ 1 1)
  2227. #+END_EXAMPLE
  2228. #+BEGIN_EXAMPLE +n
  2229. \(+ 2 2)
  2230. \(+ 3 3) (ref:one)
  2231. #+END_EXAMPLE"
  2232. (goto-line 5)
  2233. (let ((org-coderef-label-format "(ref:%s)"))
  2234. (org-export-unravel-code (org-element-at-point)))))))
  2235. (ert-deftest test-org-export/format-code-default ()
  2236. "Test `org-export-format-code-default' specifications."
  2237. ;; Return the empty string when code is empty.
  2238. (should
  2239. (equal ""
  2240. (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n\n\n#+END_SRC"
  2241. (org-export-format-code-default
  2242. (org-element-map tree 'src-block 'identity info t) info))))
  2243. ;; Number lines, two whitespace characters before the actual loc.
  2244. (should
  2245. (equal "1 a\n2 b\n"
  2246. (org-test-with-parsed-data
  2247. "#+BEGIN_SRC emacs-lisp +n\na\nb\n#+END_SRC"
  2248. (org-export-format-code-default
  2249. (org-element-map tree 'src-block 'identity info t) info))))
  2250. ;; Put references 6 whitespace characters after the widest line,
  2251. ;; wrapped within parenthesis.
  2252. (should
  2253. (equal "123 (a)\n1 (b)\n"
  2254. (let ((org-coderef-label-format "(ref:%s)"))
  2255. (org-test-with-parsed-data
  2256. "#+BEGIN_SRC emacs-lisp\n123 (ref:a)\n1 (ref:b)\n#+END_SRC"
  2257. (org-export-format-code-default
  2258. (org-element-map tree 'src-block 'identity info t) info))))))
  2259. ;;; Smart Quotes
  2260. (ert-deftest test-org-export/activate-smart-quotes ()
  2261. "Test `org-export-activate-smart-quotes' specifications."
  2262. ;; Opening double quotes: standard test.
  2263. (should
  2264. (equal
  2265. '("some &ldquo;paragraph")
  2266. (let ((org-export-default-language "en"))
  2267. (org-test-with-parsed-data "some \"paragraph"
  2268. (org-element-map tree 'plain-text
  2269. (lambda (s) (org-export-activate-smart-quotes s :html info))
  2270. info)))))
  2271. ;; Opening quotes: at the beginning of a paragraph.
  2272. (should
  2273. (equal
  2274. '("&ldquo;begin")
  2275. (let ((org-export-default-language "en"))
  2276. (org-test-with-parsed-data "\"begin"
  2277. (org-element-map tree 'plain-text
  2278. (lambda (s) (org-export-activate-smart-quotes s :html info))
  2279. info)))))
  2280. ;; Opening quotes: after an object.
  2281. (should
  2282. (equal
  2283. '("&ldquo;begin")
  2284. (let ((org-export-default-language "en"))
  2285. (org-test-with-parsed-data "=verb= \"begin"
  2286. (org-element-map tree 'plain-text
  2287. (lambda (s) (org-export-activate-smart-quotes s :html info))
  2288. info)))))
  2289. ;; Closing quotes: standard test.
  2290. (should
  2291. (equal
  2292. '("some&rdquo; paragraph")
  2293. (let ((org-export-default-language "en"))
  2294. (org-test-with-parsed-data "some\" paragraph"
  2295. (org-element-map tree 'plain-text
  2296. (lambda (s) (org-export-activate-smart-quotes s :html info))
  2297. info)))))
  2298. ;; Closing quotes: at the end of a paragraph.
  2299. (should
  2300. (equal
  2301. '("end&rdquo;")
  2302. (let ((org-export-default-language "en"))
  2303. (org-test-with-parsed-data "end\""
  2304. (org-element-map tree 'plain-text
  2305. (lambda (s) (org-export-activate-smart-quotes s :html info))
  2306. info)))))
  2307. ;; Apostrophe: standard test.
  2308. (should
  2309. (equal
  2310. '("It shouldn&rsquo;t fail")
  2311. (let ((org-export-default-language "en"))
  2312. (org-test-with-parsed-data "It shouldn't fail"
  2313. (org-element-map tree 'plain-text
  2314. (lambda (s) (org-export-activate-smart-quotes s :html info))
  2315. info)))))
  2316. ;; Apostrophe: before an object.
  2317. (should
  2318. (equal
  2319. '("a&rsquo;")
  2320. (let ((org-export-default-language "en"))
  2321. (org-test-with-parsed-data "a'=b="
  2322. (org-element-map tree 'plain-text
  2323. (lambda (s) (org-export-activate-smart-quotes s :html info))
  2324. info)))))
  2325. ;; Apostrophe: after an object.
  2326. (should
  2327. (equal
  2328. '("&rsquo;s")
  2329. (let ((org-export-default-language "en"))
  2330. (org-test-with-parsed-data "=code='s"
  2331. (org-element-map tree 'plain-text
  2332. (lambda (s) (org-export-activate-smart-quotes s :html info))
  2333. info)))))
  2334. ;; Special case: isolated quotes.
  2335. (should
  2336. (equal '("&ldquo;" "&rdquo;")
  2337. (let ((org-export-default-language "en"))
  2338. (org-test-with-parsed-data "\"$x$\""
  2339. (org-element-map tree 'plain-text
  2340. (lambda (s) (org-export-activate-smart-quotes s :html info))
  2341. info)))))
  2342. ;; Smart quotes in secondary strings.
  2343. (should
  2344. (equal '("&ldquo;" "&rdquo;")
  2345. (let ((org-export-default-language "en"))
  2346. (org-test-with-parsed-data "* \"$x$\""
  2347. (org-element-map tree 'plain-text
  2348. (lambda (s) (org-export-activate-smart-quotes s :html info))
  2349. info)))))
  2350. ;; Smart quotes in document keywords.
  2351. (should
  2352. (equal '("&ldquo;" "&rdquo;")
  2353. (let ((org-export-default-language "en"))
  2354. (org-test-with-parsed-data "#+TITLE: \"$x$\""
  2355. (org-element-map (plist-get info :title) 'plain-text
  2356. (lambda (s) (org-export-activate-smart-quotes s :html info))
  2357. info)))))
  2358. ;; Smart quotes in parsed affiliated keywords.
  2359. (should
  2360. (equal '("&ldquo;" "&rdquo;" "Paragraph")
  2361. (let ((org-export-default-language "en"))
  2362. (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
  2363. (org-element-map tree 'plain-text
  2364. (lambda (s) (org-export-activate-smart-quotes s :html info))
  2365. info nil nil t))))))
  2366. ;;; Tables
  2367. (ert-deftest test-org-export/special-column ()
  2368. "Test if the table's special column is properly recognized."
  2369. ;; 1. First column is special if it contains only a special marking
  2370. ;; characters or empty cells.
  2371. (org-test-with-temp-text "
  2372. | ! | 1 |
  2373. | | 2 |"
  2374. (should
  2375. (org-export-table-has-special-column-p
  2376. (org-element-map
  2377. (org-element-parse-buffer) 'table 'identity nil 'first-match))))
  2378. ;; 2. If the column contains anything else, it isn't special.
  2379. (org-test-with-temp-text "
  2380. | ! | 1 |
  2381. | b | 2 |"
  2382. (should-not
  2383. (org-export-table-has-special-column-p
  2384. (org-element-map
  2385. (org-element-parse-buffer) 'table 'identity nil 'first-match))))
  2386. ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
  2387. ;; and "!".
  2388. (org-test-with-temp-text "
  2389. | # | 1 |
  2390. | ^ | 2 |
  2391. | * | 3 |
  2392. | _ | 4 |
  2393. | / | 5 |
  2394. | $ | 6 |
  2395. | ! | 7 |"
  2396. (should
  2397. (org-export-table-has-special-column-p
  2398. (org-element-map
  2399. (org-element-parse-buffer) 'table 'identity nil 'first-match))))
  2400. ;; 4. A first column with only empty cells isn't considered as
  2401. ;; special.
  2402. (org-test-with-temp-text "
  2403. | | 1 |
  2404. | | 2 |"
  2405. (should-not
  2406. (org-export-table-has-special-column-p
  2407. (org-element-map
  2408. (org-element-parse-buffer) 'table 'identity nil 'first-match)))))
  2409. (ert-deftest test-org-export/table-row-is-special-p ()
  2410. "Test `org-export-table-row-is-special-p' specifications."
  2411. ;; 1. A row is special if it has a special marking character in the
  2412. ;; special column.
  2413. (org-test-with-parsed-data "| ! | 1 |"
  2414. (should
  2415. (org-export-table-row-is-special-p
  2416. (org-element-map tree 'table-row 'identity nil 'first-match) info)))
  2417. ;; 2. A row is special when its first field is "/"
  2418. (org-test-with-parsed-data "
  2419. | / | 1 |
  2420. | a | b |"
  2421. (should
  2422. (org-export-table-row-is-special-p
  2423. (org-element-map tree 'table-row 'identity nil 'first-match) info)))
  2424. ;; 3. A row only containing alignment cookies is also considered as
  2425. ;; special.
  2426. (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
  2427. (should
  2428. (org-export-table-row-is-special-p
  2429. (org-element-map tree 'table-row 'identity nil 'first-match) info)))
  2430. ;; 4. Everything else isn't considered as special.
  2431. (org-test-with-parsed-data "| \alpha | | c |"
  2432. (should-not
  2433. (org-export-table-row-is-special-p
  2434. (org-element-map tree 'table-row 'identity nil 'first-match) info)))
  2435. ;; 5. Table's rules are never considered as special rows.
  2436. (org-test-with-parsed-data "|---+---|"
  2437. (should-not
  2438. (org-export-table-row-is-special-p
  2439. (org-element-map tree 'table-row 'identity nil 'first-match) info))))
  2440. (ert-deftest test-org-export/has-header-p ()
  2441. "Test `org-export-table-has-header-p' specifications."
  2442. ;; 1. With an header.
  2443. (org-test-with-parsed-data "
  2444. | a | b |
  2445. |---+---|
  2446. | c | d |"
  2447. (should
  2448. (org-export-table-has-header-p
  2449. (org-element-map tree 'table 'identity info 'first-match)
  2450. info)))
  2451. ;; 2. Without an header.
  2452. (org-test-with-parsed-data "
  2453. | a | b |
  2454. | c | d |"
  2455. (should-not
  2456. (org-export-table-has-header-p
  2457. (org-element-map tree 'table 'identity info 'first-match)
  2458. info)))
  2459. ;; 3. Don't get fooled with starting and ending rules.
  2460. (org-test-with-parsed-data "
  2461. |---+---|
  2462. | a | b |
  2463. | c | d |
  2464. |---+---|"
  2465. (should-not
  2466. (org-export-table-has-header-p
  2467. (org-element-map tree 'table 'identity info 'first-match)
  2468. info))))
  2469. (ert-deftest test-org-export/table-row-group ()
  2470. "Test `org-export-table-row-group' specifications."
  2471. ;; 1. A rule creates a new group.
  2472. (should
  2473. (equal '(1 rule 2)
  2474. (org-test-with-parsed-data "
  2475. | a | b |
  2476. |---+---|
  2477. | 1 | 2 |"
  2478. (org-element-map tree 'table-row
  2479. (lambda (row)
  2480. (if (eq (org-element-property :type row) 'rule) 'rule
  2481. (org-export-table-row-group row info)))))))
  2482. ;; 2. Special rows are ignored in count.
  2483. (should
  2484. (equal
  2485. '(rule 1)
  2486. (org-test-with-parsed-data "
  2487. | / | < | > |
  2488. |---|---+---|
  2489. | | 1 | 2 |"
  2490. (org-element-map tree 'table-row
  2491. (lambda (row)
  2492. (if (eq (org-element-property :type row) 'rule) 'rule
  2493. (org-export-table-row-group row info)))
  2494. info))))
  2495. ;; 3. Double rules also are ignored in count.
  2496. (should
  2497. (equal '(1 rule rule 2)
  2498. (org-test-with-parsed-data "
  2499. | a | b |
  2500. |---+---|
  2501. |---+---|
  2502. | 1 | 2 |"
  2503. (org-element-map tree 'table-row
  2504. (lambda (row)
  2505. (if (eq (org-element-property :type row) 'rule) 'rule
  2506. (org-export-table-row-group row info))))))))
  2507. (ert-deftest test-org-export/table-row-number ()
  2508. "Test `org-export-table-row-number' specifications."
  2509. ;; Standard test. Number is 0-indexed.
  2510. (should
  2511. (equal '(0 1)
  2512. (org-test-with-parsed-data "| a | b | c |\n| d | e | f |"
  2513. (org-element-map tree 'table-row
  2514. (lambda (row) (org-export-table-row-number row info)) info))))
  2515. ;; Number ignores separators.
  2516. (should
  2517. (equal '(0 1)
  2518. (org-test-with-parsed-data "
  2519. | a | b | c |
  2520. |---+---+---|
  2521. | d | e | f |"
  2522. (org-element-map tree 'table-row
  2523. (lambda (row) (org-export-table-row-number row info)) info))))
  2524. ;; Number ignores special rows.
  2525. (should
  2526. (equal '(0 1)
  2527. (org-test-with-parsed-data "
  2528. | / | < | > |
  2529. | | b | c |
  2530. |---+-----+-----|
  2531. | | <c> | <c> |
  2532. | | e | f |"
  2533. (org-element-map tree 'table-row
  2534. (lambda (row) (org-export-table-row-number row info)) info)))))
  2535. (ert-deftest test-org-export/table-cell-width ()
  2536. "Test `org-export-table-cell-width' specifications."
  2537. ;; 1. Width is primarily determined by width cookies. If no cookie
  2538. ;; is found, cell's width is nil.
  2539. (org-test-with-parsed-data "
  2540. | / | <l> | <6> | <l7> |
  2541. | | a | b | c |"
  2542. (should
  2543. (equal
  2544. '(nil 6 7)
  2545. (mapcar (lambda (cell) (org-export-table-cell-width cell info))
  2546. (org-element-map tree 'table-cell 'identity info)))))
  2547. ;; 2. The last width cookie has precedence.
  2548. (org-test-with-parsed-data "
  2549. | <6> |
  2550. | <7> |
  2551. | a |"
  2552. (should
  2553. (equal
  2554. '(7)
  2555. (mapcar (lambda (cell) (org-export-table-cell-width cell info))
  2556. (org-element-map tree 'table-cell 'identity info)))))
  2557. ;; 3. Valid width cookies must have a specific row.
  2558. (org-test-with-parsed-data "| <6> | cell |"
  2559. (should
  2560. (equal
  2561. '(nil nil)
  2562. (mapcar (lambda (cell) (org-export-table-cell-width cell info))
  2563. (org-element-map tree 'table-cell 'identity))))))
  2564. (ert-deftest test-org-export/table-cell-alignment ()
  2565. "Test `org-export-table-cell-alignment' specifications."
  2566. ;; 1. Alignment is primarily determined by alignment cookies.
  2567. (should
  2568. (equal '(left center right)
  2569. (let ((org-table-number-fraction 0.5)
  2570. (org-table-number-regexp "^[0-9]+$"))
  2571. (org-test-with-parsed-data "| <l> | <c> | <r> |"
  2572. (mapcar (lambda (cell)
  2573. (org-export-table-cell-alignment cell info))
  2574. (org-element-map tree 'table-cell 'identity))))))
  2575. ;; 2. The last alignment cookie has precedence.
  2576. (should
  2577. (equal '(right right right)
  2578. (org-test-with-parsed-data "
  2579. | <l8> |
  2580. | cell |
  2581. | <r9> |"
  2582. (mapcar (lambda (cell) (org-export-table-cell-alignment cell info))
  2583. (org-element-map tree 'table-cell 'identity)))))
  2584. ;; 3. If there's no cookie, cell's contents determine alignment.
  2585. ;; A column mostly made of cells containing numbers will align
  2586. ;; its cells to the right.
  2587. (should
  2588. (equal '(right right right)
  2589. (let ((org-table-number-fraction 0.5)
  2590. (org-table-number-regexp "^[0-9]+$"))
  2591. (org-test-with-parsed-data "
  2592. | 123 |
  2593. | some text |
  2594. | 12345 |"
  2595. (mapcar (lambda (cell)
  2596. (org-export-table-cell-alignment cell info))
  2597. (org-element-map tree 'table-cell 'identity))))))
  2598. ;; 4. Otherwise, they will be aligned to the left.
  2599. (should
  2600. (equal '(left left left)
  2601. (org-test-with-parsed-data "
  2602. | text |
  2603. | some text |
  2604. | \alpha |"
  2605. (mapcar (lambda (cell)
  2606. (org-export-table-cell-alignment cell info))
  2607. (org-element-map tree 'table-cell 'identity info))))))
  2608. (ert-deftest test-org-export/table-cell-borders ()
  2609. "Test `org-export-table-cell-borders' specifications."
  2610. ;; 1. Recognize various column groups indicators.
  2611. (org-test-with-parsed-data "| / | < | > | <> |"
  2612. (should
  2613. (equal
  2614. '((right bottom top) (left bottom top) (right bottom top)
  2615. (right left bottom top))
  2616. (mapcar (lambda (cell)
  2617. (org-export-table-cell-borders cell info))
  2618. (org-element-map tree 'table-cell 'identity)))))
  2619. ;; 2. Accept shortcuts to define column groups.
  2620. (org-test-with-parsed-data "| / | < | < |"
  2621. (should
  2622. (equal
  2623. '((right bottom top) (right left bottom top) (left bottom top))
  2624. (mapcar (lambda (cell)
  2625. (org-export-table-cell-borders cell info))
  2626. (org-element-map tree 'table-cell 'identity)))))
  2627. ;; 3. A valid column groups row must start with a "/".
  2628. (org-test-with-parsed-data "
  2629. | | < |
  2630. | a | b |"
  2631. (should
  2632. (equal '((top) (top) (bottom) (bottom))
  2633. (mapcar (lambda (cell)
  2634. (org-export-table-cell-borders cell info))
  2635. (org-element-map tree 'table-cell 'identity)))))
  2636. ;; 4. Take table rules into consideration.
  2637. (org-test-with-parsed-data "
  2638. | 1 |
  2639. |---|
  2640. | 2 |"
  2641. (should
  2642. (equal '((below top) (bottom above))
  2643. (mapcar (lambda (cell)
  2644. (org-export-table-cell-borders cell info))
  2645. (org-element-map tree 'table-cell 'identity)))))
  2646. ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
  2647. ;; (resp. `bottom' and `below') borders. Any special row is
  2648. ;; ignored.
  2649. (org-test-with-parsed-data "
  2650. |---+----|
  2651. | / | |
  2652. | | 1 |
  2653. |---+----|"
  2654. (should
  2655. (equal '((bottom below top above))
  2656. (last
  2657. (mapcar (lambda (cell)
  2658. (org-export-table-cell-borders cell info))
  2659. (org-element-map tree 'table-cell 'identity)))))))
  2660. (ert-deftest test-org-export/table-dimensions ()
  2661. "Test `org-export-table-dimensions' specifications."
  2662. ;; 1. Standard test.
  2663. (org-test-with-parsed-data "
  2664. | 1 | 2 | 3 |
  2665. | 4 | 5 | 6 |"
  2666. (should
  2667. (equal '(2 . 3)
  2668. (org-export-table-dimensions
  2669. (org-element-map tree 'table 'identity info 'first-match) info))))
  2670. ;; 2. Ignore horizontal rules and special columns.
  2671. (org-test-with-parsed-data "
  2672. | / | < | > |
  2673. | 1 | 2 | 3 |
  2674. |---+---+---|
  2675. | 4 | 5 | 6 |"
  2676. (should
  2677. (equal '(2 . 3)
  2678. (org-export-table-dimensions
  2679. (org-element-map tree 'table 'identity info 'first-match) info)))))
  2680. (ert-deftest test-org-export/table-cell-address ()
  2681. "Test `org-export-table-cell-address' specifications."
  2682. ;; 1. Standard test: index is 0-based.
  2683. (org-test-with-parsed-data "| a | b |"
  2684. (should
  2685. (equal '((0 . 0) (0 . 1))
  2686. (org-element-map tree 'table-cell
  2687. (lambda (cell) (org-export-table-cell-address cell info))
  2688. info))))
  2689. ;; 2. Special column isn't counted, nor are special rows.
  2690. (org-test-with-parsed-data "
  2691. | / | <> |
  2692. | | c |"
  2693. (should
  2694. (equal '(0 . 0)
  2695. (org-export-table-cell-address
  2696. (car (last (org-element-map tree 'table-cell 'identity info)))
  2697. info))))
  2698. ;; 3. Tables rules do not count either.
  2699. (org-test-with-parsed-data "
  2700. | a |
  2701. |---|
  2702. | b |
  2703. |---|
  2704. | c |"
  2705. (should
  2706. (equal '(2 . 0)
  2707. (org-export-table-cell-address
  2708. (car (last (org-element-map tree 'table-cell 'identity info)))
  2709. info))))
  2710. ;; 4. Return nil for special cells.
  2711. (org-test-with-parsed-data "| / | a |"
  2712. (should-not
  2713. (org-export-table-cell-address
  2714. (org-element-map tree 'table-cell 'identity nil 'first-match)
  2715. info))))
  2716. (ert-deftest test-org-export/get-table-cell-at ()
  2717. "Test `org-export-get-table-cell-at' specifications."
  2718. ;; 1. Address ignores special columns, special rows and rules.
  2719. (org-test-with-parsed-data "
  2720. | / | <> |
  2721. | | a |
  2722. |---+----|
  2723. | | b |"
  2724. (should
  2725. (equal '("b")
  2726. (org-element-contents
  2727. (org-export-get-table-cell-at
  2728. '(1 . 0)
  2729. (org-element-map tree 'table 'identity info 'first-match)
  2730. info)))))
  2731. ;; 2. Return value for a non-existent address is nil.
  2732. (org-test-with-parsed-data "| a |"
  2733. (should-not
  2734. (org-export-get-table-cell-at
  2735. '(2 . 2)
  2736. (org-element-map tree 'table 'identity info 'first-match)
  2737. info)))
  2738. (org-test-with-parsed-data "| / |"
  2739. (should-not
  2740. (org-export-get-table-cell-at
  2741. '(0 . 0)
  2742. (org-element-map tree 'table 'identity info 'first-match)
  2743. info))))
  2744. (ert-deftest test-org-export/table-cell-starts-colgroup-p ()
  2745. "Test `org-export-table-cell-starts-colgroup-p' specifications."
  2746. ;; 1. A cell at a beginning of a row always starts a column group.
  2747. (org-test-with-parsed-data "| a |"
  2748. (should
  2749. (org-export-table-cell-starts-colgroup-p
  2750. (org-element-map tree 'table-cell 'identity info 'first-match)
  2751. info)))
  2752. ;; 2. Special column should be ignored when determining the
  2753. ;; beginning of the row.
  2754. (org-test-with-parsed-data "
  2755. | / | |
  2756. | | a |"
  2757. (should
  2758. (org-export-table-cell-starts-colgroup-p
  2759. (org-element-map tree 'table-cell 'identity info 'first-match)
  2760. info)))
  2761. ;; 2. Explicit column groups.
  2762. (org-test-with-parsed-data "
  2763. | / | | < |
  2764. | a | b | c |"
  2765. (should
  2766. (equal
  2767. '(yes no yes)
  2768. (org-element-map tree 'table-cell
  2769. (lambda (cell)
  2770. (if (org-export-table-cell-starts-colgroup-p cell info) 'yes 'no))
  2771. info)))))
  2772. (ert-deftest test-org-export/table-cell-ends-colgroup-p ()
  2773. "Test `org-export-table-cell-ends-colgroup-p' specifications."
  2774. ;; 1. A cell at the end of a row always ends a column group.
  2775. (org-test-with-parsed-data "| a |"
  2776. (should
  2777. (org-export-table-cell-ends-colgroup-p
  2778. (org-element-map tree 'table-cell 'identity info 'first-match)
  2779. info)))
  2780. ;; 2. Special column should be ignored when determining the
  2781. ;; beginning of the row.
  2782. (org-test-with-parsed-data "
  2783. | / | |
  2784. | | a |"
  2785. (should
  2786. (org-export-table-cell-ends-colgroup-p
  2787. (org-element-map tree 'table-cell 'identity info 'first-match)
  2788. info)))
  2789. ;; 3. Explicit column groups.
  2790. (org-test-with-parsed-data "
  2791. | / | < | |
  2792. | a | b | c |"
  2793. (should
  2794. (equal
  2795. '(yes no yes)
  2796. (org-element-map tree 'table-cell
  2797. (lambda (cell)
  2798. (if (org-export-table-cell-ends-colgroup-p cell info) 'yes 'no))
  2799. info)))))
  2800. (ert-deftest test-org-export/table-row-starts-rowgroup-p ()
  2801. "Test `org-export-table-row-starts-rowgroup-p' specifications."
  2802. ;; 1. A row at the beginning of a table always starts a row group.
  2803. ;; So does a row following a table rule.
  2804. (org-test-with-parsed-data "
  2805. | a |
  2806. |---|
  2807. | b |"
  2808. (should
  2809. (equal
  2810. '(yes no yes)
  2811. (org-element-map tree 'table-row
  2812. (lambda (row)
  2813. (if (org-export-table-row-starts-rowgroup-p row info) 'yes 'no))
  2814. info))))
  2815. ;; 2. Special rows should be ignored when determining the beginning
  2816. ;; of the row.
  2817. (org-test-with-parsed-data "
  2818. | / | < |
  2819. | | a |
  2820. |---+---|
  2821. | / | < |
  2822. | | b |"
  2823. (should
  2824. (equal
  2825. '(yes no yes)
  2826. (org-element-map tree 'table-row
  2827. (lambda (row)
  2828. (if (org-export-table-row-starts-rowgroup-p row info) 'yes 'no))
  2829. info)))))
  2830. (ert-deftest test-org-export/table-row-ends-rowgroup-p ()
  2831. "Test `org-export-table-row-ends-rowgroup-p' specifications."
  2832. ;; 1. A row at the end of a table always ends a row group. So does
  2833. ;; a row preceding a table rule.
  2834. (org-test-with-parsed-data "
  2835. | a |
  2836. |---|
  2837. | b |"
  2838. (should
  2839. (equal
  2840. '(yes no yes)
  2841. (org-element-map tree 'table-row
  2842. (lambda (row)
  2843. (if (org-export-table-row-ends-rowgroup-p row info) 'yes 'no))
  2844. info))))
  2845. ;; 2. Special rows should be ignored when determining the beginning
  2846. ;; of the row.
  2847. (org-test-with-parsed-data "
  2848. | | a |
  2849. | / | < |
  2850. |---+---|
  2851. | | b |
  2852. | / | < |"
  2853. (should
  2854. (equal
  2855. '(yes no yes)
  2856. (org-element-map tree 'table-row
  2857. (lambda (row)
  2858. (if (org-export-table-row-ends-rowgroup-p row info) 'yes 'no))
  2859. info)))))
  2860. (ert-deftest test-org-export/table-row-in-header-p ()
  2861. "Test `org-export-table-row-in-header-p' specifications."
  2862. ;; Standard test. Separators are always nil.
  2863. (should
  2864. (equal
  2865. '(yes no no)
  2866. (org-test-with-parsed-data "| a |\n|---|\n| b |"
  2867. (org-element-map tree 'table-row
  2868. (lambda (row)
  2869. (if (org-export-table-row-in-header-p row info) 'yes 'no)) info))))
  2870. ;; Nil when there is no header.
  2871. (should
  2872. (equal
  2873. '(no no)
  2874. (org-test-with-parsed-data "| a |\n| b |"
  2875. (org-element-map tree 'table-row
  2876. (lambda (row)
  2877. (if (org-export-table-row-in-header-p row info) 'yes 'no)) info)))))
  2878. (ert-deftest test-org-export/table-row-starts-header-p ()
  2879. "Test `org-export-table-row-starts-header-p' specifications."
  2880. ;; 1. Only the row starting the first row group starts the table
  2881. ;; header.
  2882. (org-test-with-parsed-data "
  2883. | a |
  2884. | b |
  2885. |---|
  2886. | c |"
  2887. (should
  2888. (equal
  2889. '(yes no no no)
  2890. (org-element-map tree 'table-row
  2891. (lambda (row)
  2892. (if (org-export-table-row-starts-header-p row info) 'yes 'no))
  2893. info))))
  2894. ;; 2. A row cannot start an header if there's no header in the
  2895. ;; table.
  2896. (org-test-with-parsed-data "
  2897. | a |
  2898. |---|"
  2899. (should-not
  2900. (org-export-table-row-starts-header-p
  2901. (org-element-map tree 'table-row 'identity info 'first-match)
  2902. info))))
  2903. (ert-deftest test-org-export/table-row-ends-header-p ()
  2904. "Test `org-export-table-row-ends-header-p' specifications."
  2905. ;; 1. Only the row starting the first row group starts the table
  2906. ;; header.
  2907. (org-test-with-parsed-data "
  2908. | a |
  2909. | b |
  2910. |---|
  2911. | c |"
  2912. (should
  2913. (equal
  2914. '(no yes no no)
  2915. (org-element-map tree 'table-row
  2916. (lambda (row)
  2917. (if (org-export-table-row-ends-header-p row info) 'yes 'no))
  2918. info))))
  2919. ;; 2. A row cannot start an header if there's no header in the
  2920. ;; table.
  2921. (org-test-with-parsed-data "
  2922. | a |
  2923. |---|"
  2924. (should-not
  2925. (org-export-table-row-ends-header-p
  2926. (org-element-map tree 'table-row 'identity info 'first-match)
  2927. info))))
  2928. ;;; Tables of Contents
  2929. (ert-deftest test-org-export/collect-headlines ()
  2930. "Test `org-export-collect-headlines' specifications."
  2931. ;; Standard test.
  2932. (should
  2933. (= 2
  2934. (length
  2935. (org-test-with-parsed-data "* H1\n** H2"
  2936. (org-export-collect-headlines info)))))
  2937. ;; Do not collect headlines below optional argument.
  2938. (should
  2939. (= 1
  2940. (length
  2941. (org-test-with-parsed-data "* H1\n** H2"
  2942. (org-export-collect-headlines info 1)))))
  2943. ;; Never collect headlines below maximum headline level.
  2944. (should
  2945. (= 1
  2946. (length
  2947. (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
  2948. (org-export-collect-headlines info)))))
  2949. (should
  2950. (= 1
  2951. (length
  2952. (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
  2953. (org-export-collect-headlines info 2))))))
  2954. ;;; Templates
  2955. (ert-deftest test-org-export/inner-template ()
  2956. "Test `inner-template' translator specifications."
  2957. (should
  2958. (equal "Success!"
  2959. (org-test-with-temp-text "* Headline"
  2960. (org-export-as
  2961. (org-export-create-backend
  2962. :transcoders
  2963. '((inner-template . (lambda (contents info) "Success!"))
  2964. (headline . (lambda (h c i) "Headline"))))))))
  2965. ;; Inner template is applied even in a "body-only" export.
  2966. (should
  2967. (equal "Success!"
  2968. (org-test-with-temp-text "* Headline"
  2969. (org-export-as
  2970. (org-export-create-backend
  2971. :transcoders '((inner-template . (lambda (c i) "Success!"))
  2972. (headline . (lambda (h c i) "Headline"))))
  2973. nil nil 'body-only)))))
  2974. (ert-deftest test-org-export/template ()
  2975. "Test `template' translator specifications."
  2976. (should
  2977. (equal "Success!"
  2978. (org-test-with-temp-text "* Headline"
  2979. (org-export-as
  2980. (org-export-create-backend
  2981. :transcoders '((template . (lambda (contents info) "Success!"))
  2982. (headline . (lambda (h c i) "Headline"))))))))
  2983. ;; Template is not applied in a "body-only" export.
  2984. (should-not
  2985. (equal "Success!"
  2986. (org-test-with-temp-text "* Headline"
  2987. (org-export-as
  2988. (org-export-create-backend
  2989. :transcoders '((template . (lambda (contents info) "Success!"))
  2990. (headline . (lambda (h c i) "Headline"))))
  2991. nil nil 'body-only)))))
  2992. ;;; Topology
  2993. (ert-deftest test-org-export/get-next-element ()
  2994. "Test `org-export-get-next-element' specifications."
  2995. ;; Standard test.
  2996. (should
  2997. (equal "b"
  2998. (org-test-with-parsed-data "* Headline\n*a* b"
  2999. (org-export-get-next-element
  3000. (org-element-map tree 'bold 'identity info t) info))))
  3001. ;; Return nil when no previous element.
  3002. (should-not
  3003. (org-test-with-parsed-data "* Headline\na *b*"
  3004. (org-export-get-next-element
  3005. (org-element-map tree 'bold 'identity info t) info)))
  3006. ;; Non-exportable elements are ignored.
  3007. (should-not
  3008. (let ((org-export-with-timestamps nil))
  3009. (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
  3010. (org-export-get-next-element
  3011. (org-element-map tree 'entity 'identity info t) info))))
  3012. ;; Find next element in secondary strings.
  3013. (should
  3014. (eq 'verbatim
  3015. (org-test-with-parsed-data "* a =verb="
  3016. (org-element-type
  3017. (org-export-get-next-element
  3018. (org-element-map tree 'plain-text 'identity info t) info)))))
  3019. (should
  3020. (eq 'verbatim
  3021. (org-test-with-parsed-data "* /italic/ =verb="
  3022. (org-element-type
  3023. (org-export-get-next-element
  3024. (org-element-map tree 'italic 'identity info t) info)))))
  3025. ;; Find next element in document keywords.
  3026. (should
  3027. (eq 'verbatim
  3028. (org-test-with-parsed-data "#+TITLE: a =verb="
  3029. (org-element-type
  3030. (org-export-get-next-element
  3031. (org-element-map
  3032. (plist-get info :title) 'plain-text 'identity info t) info)))))
  3033. ;; Find next element in parsed affiliated keywords.
  3034. (should
  3035. (eq 'verbatim
  3036. (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
  3037. (org-element-type
  3038. (org-export-get-next-element
  3039. (org-element-map tree 'plain-text 'identity info t nil t) info)))))
  3040. ;; With optional argument N, return a list containing all the
  3041. ;; following elements.
  3042. (should
  3043. (equal
  3044. '(bold code underline)
  3045. (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
  3046. (mapcar 'car
  3047. (org-export-get-next-element
  3048. (org-element-map tree 'italic 'identity info t) info t)))))
  3049. ;; When N is a positive integer, return a list containing up to
  3050. ;; N following elements.
  3051. (should
  3052. (equal
  3053. '(bold code)
  3054. (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
  3055. (mapcar 'car
  3056. (org-export-get-next-element
  3057. (org-element-map tree 'italic 'identity info t) info 2))))))
  3058. (ert-deftest test-org-export/get-previous-element ()
  3059. "Test `org-export-get-previous-element' specifications."
  3060. ;; Standard test.
  3061. (should
  3062. (equal "a "
  3063. (org-test-with-parsed-data "* Headline\na *b*"
  3064. (org-export-get-previous-element
  3065. (org-element-map tree 'bold 'identity info t) info))))
  3066. ;; Return nil when no previous element.
  3067. (should-not
  3068. (org-test-with-parsed-data "* Headline\n*a* b"
  3069. (org-export-get-previous-element
  3070. (org-element-map tree 'bold 'identity info t) info)))
  3071. ;; Non-exportable elements are ignored.
  3072. (should-not
  3073. (let ((org-export-with-timestamps nil))
  3074. (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
  3075. (org-export-get-previous-element
  3076. (org-element-map tree 'entity 'identity info t) info))))
  3077. ;; Find previous element in secondary strings.
  3078. (should
  3079. (eq 'verbatim
  3080. (org-test-with-parsed-data "* =verb= a"
  3081. (org-element-type
  3082. (org-export-get-previous-element
  3083. (org-element-map tree 'plain-text 'identity info t) info)))))
  3084. (should
  3085. (eq 'verbatim
  3086. (org-test-with-parsed-data "* =verb= /italic/"
  3087. (org-element-type
  3088. (org-export-get-previous-element
  3089. (org-element-map tree 'italic 'identity info t) info)))))
  3090. ;; Find previous element in document keywords.
  3091. (should
  3092. (eq 'verbatim
  3093. (org-test-with-parsed-data "#+TITLE: =verb= a"
  3094. (org-element-type
  3095. (org-export-get-previous-element
  3096. (org-element-map
  3097. (plist-get info :title) 'plain-text 'identity info t) info)))))
  3098. ;; Find previous element in parsed affiliated keywords.
  3099. (should
  3100. (eq 'verbatim
  3101. (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
  3102. (org-element-type
  3103. (org-export-get-previous-element
  3104. (org-element-map tree 'plain-text 'identity info t nil t) info)))))
  3105. ;; With optional argument N, return a list containing up to
  3106. ;; N previous elements.
  3107. (should
  3108. (equal '(underline italic bold)
  3109. (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
  3110. (mapcar 'car
  3111. (org-export-get-previous-element
  3112. (org-element-map tree 'code 'identity info t) info t)))))
  3113. ;; When N is a positive integer, return a list containing up to
  3114. ;; N previous elements.
  3115. (should
  3116. (equal '(italic bold)
  3117. (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
  3118. (mapcar 'car
  3119. (org-export-get-previous-element
  3120. (org-element-map tree 'code 'identity info t) info 2))))))
  3121. (provide 'test-ox)
  3122. ;;; test-org-export.el end here