test-ox.el 138 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261
  1. ;;; test-ox.el --- Tests for ox.el -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2012-2016 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. (require 'cl-lib)
  17. (unless (featurep 'ox)
  18. (signal 'missing-test-dependency "org-export"))
  19. (defun org-test-default-backend ()
  20. "Return a default export back-end.
  21. This back-end simply returns parsed data as Org syntax."
  22. (org-export-create-backend
  23. :transcoders
  24. (mapcar (lambda (type)
  25. (cons type
  26. (lambda (o c _)
  27. (funcall
  28. (intern (format "org-element-%s-interpreter" type))
  29. o c))))
  30. (append org-element-all-elements org-element-all-objects))))
  31. (defmacro org-test-with-parsed-data (data &rest body)
  32. "Execute body with parsed data available.
  33. DATA is a string containing the data to be parsed. BODY is the
  34. body to execute. Parse tree is available under the `tree'
  35. variable, and communication channel under `info'."
  36. (declare (debug (form body)) (indent 1))
  37. `(org-test-with-temp-text ,data
  38. (org-export--delete-comments)
  39. (let* ((tree (org-element-parse-buffer))
  40. (info (org-combine-plists
  41. (org-export--get-export-attributes)
  42. (org-export-get-environment))))
  43. (org-export--prune-tree tree info)
  44. (org-export--remove-uninterpreted-data tree info)
  45. (let ((info (org-combine-plists
  46. info (org-export--collect-tree-properties tree info))))
  47. ,@body))))
  48. ;;; Internal Tests
  49. (ert-deftest test-org-export/bind-keyword ()
  50. "Test reading #+BIND: keywords."
  51. ;; Test with `org-export-allow-bind-keywords' set to t.
  52. (should
  53. (org-test-with-temp-text "#+BIND: test-ox-var value"
  54. (let ((org-export-allow-bind-keywords t))
  55. (org-export-get-environment)
  56. (eq test-ox-var 'value))))
  57. ;; Test with `org-export-allow-bind-keywords' set to nil.
  58. (should-not
  59. (org-test-with-temp-text "#+BIND: test-ox-var value"
  60. (let ((org-export-allow-bind-keywords nil))
  61. (org-export-get-environment)
  62. (boundp 'test-ox-var))))
  63. ;; BIND keywords are case-insensitive.
  64. (should
  65. (org-test-with-temp-text "#+bind: test-ox-var value"
  66. (let ((org-export-allow-bind-keywords t))
  67. (org-export-get-environment)
  68. (eq test-ox-var 'value))))
  69. ;; Preserve order of BIND keywords.
  70. (should
  71. (org-test-with-temp-text "#+BIND: test-ox-var 1\n#+BIND: test-ox-var 2"
  72. (let ((org-export-allow-bind-keywords t))
  73. (org-export-get-environment)
  74. (eq test-ox-var 2))))
  75. ;; Read BIND keywords in setup files.
  76. (should
  77. (org-test-with-temp-text
  78. (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
  79. (let ((org-export-allow-bind-keywords t))
  80. (org-export-get-environment)
  81. (eq variable 'value))))
  82. ;; Verify that bound variables are seen during export.
  83. (should
  84. (equal "Yes\n"
  85. (org-test-with-temp-text "#+BIND: test-ox-var value"
  86. (let ((org-export-allow-bind-keywords t))
  87. (org-export-as
  88. (org-export-create-backend
  89. :transcoders
  90. '((section . (lambda (s c i)
  91. (if (eq test-ox-var 'value) "Yes" "No")))))))))))
  92. (ert-deftest test-org-export/parse-option-keyword ()
  93. "Test reading all standard #+OPTIONS: items."
  94. (should
  95. (let ((options
  96. (org-export--parse-option-keyword
  97. "H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t \
  98. *:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t inline:nil \
  99. stat:t title:t")))
  100. (and (eq (plist-get options :headline-levels) 1)
  101. (eq (plist-get options :section-numbers) t)
  102. (eq (plist-get options :preserve-breaks) t)
  103. (eq (plist-get options :time-stamp-file) t)
  104. (eq (plist-get options :with-archived-trees) t)
  105. (eq (plist-get options :with-author) t)
  106. (eq (plist-get options :with-drawers) t)
  107. (eq (plist-get options :with-email) t)
  108. (eq (plist-get options :with-emphasize) t)
  109. (eq (plist-get options :with-entities) t)
  110. (eq (plist-get options :with-fixed-width) t)
  111. (eq (plist-get options :with-footnotes) t)
  112. (eq (plist-get options :with-priority) t)
  113. (eq (plist-get options :with-special-strings) t)
  114. (eq (plist-get options :with-sub-superscript) t)
  115. (eq (plist-get options :with-toc) t)
  116. (eq (plist-get options :with-tables) t)
  117. (eq (plist-get options :with-tags) t)
  118. (eq (plist-get options :with-tasks) t)
  119. (eq (plist-get options :with-timestamps) t)
  120. (eq (plist-get options :with-todo-keywords) t)
  121. (eq (plist-get options :with-inlinetasks) nil)
  122. (eq (plist-get options :with-statistics-cookies) t)
  123. (eq (plist-get options :with-title) t))))
  124. ;; Test some special values.
  125. (should
  126. (let ((options
  127. (org-export--parse-option-keyword
  128. "arch:headline d:(\"TEST\") ^:{} toc:1 tags:not-in-toc tasks:todo \
  129. num:2 <:active")))
  130. (and (eq (plist-get options :with-archived-trees) 'headline)
  131. (eq (plist-get options :with-sub-superscript) '{})
  132. (eq (plist-get options :with-toc) 1)
  133. (eq (plist-get options :with-tags) 'not-in-toc)
  134. (eq (plist-get options :with-tasks) 'todo)
  135. (eq (plist-get options :section-numbers) 2)
  136. (eq (plist-get options :with-timestamps) 'active)
  137. (equal (plist-get options :with-drawers) '("TEST")))))
  138. ;; Test back-end specific values.
  139. (should
  140. (equal
  141. (org-export--parse-option-keyword
  142. "opt:t" (org-export-create-backend :options '((:option nil "opt"))))
  143. '(:option t)))
  144. ;; More than one property can refer to the same option item.
  145. (should
  146. (equal '(:opt1 t :opt2 t)
  147. (org-export--parse-option-keyword
  148. "opt:t"
  149. (org-export-create-backend
  150. :options '((:opt1 nil "opt") (:opt2 nil "opt")))))))
  151. (ert-deftest test-org-export/get-inbuffer-options ()
  152. "Test reading all standard export keywords."
  153. ;; Properties should follow buffer order.
  154. (should
  155. (equal
  156. (org-test-with-temp-text "#+LANGUAGE: fr\n#+CREATOR: Me\n#+EMAIL: email"
  157. (org-export--get-inbuffer-options))
  158. '(:language "fr" :creator "Me" :email "email")))
  159. ;; Test `space' behaviour.
  160. (should
  161. (equal
  162. (let ((back-end (org-export-create-backend
  163. :options '((:keyword "KEYWORD" nil nil space)))))
  164. (org-test-with-temp-text "#+KEYWORD: With\n#+KEYWORD: spaces"
  165. (org-export--get-inbuffer-options back-end)))
  166. '(:keyword "With spaces")))
  167. ;; Test `newline' behaviour.
  168. (should
  169. (equal
  170. (let ((back-end (org-export-create-backend
  171. :options '((:keyword "KEYWORD" nil nil newline)))))
  172. (org-test-with-temp-text "#+KEYWORD: With\n#+KEYWORD: two lines"
  173. (org-export--get-inbuffer-options back-end)))
  174. '(:keyword "With\ntwo lines")))
  175. ;; Test `split' behaviour.
  176. (should
  177. (equal
  178. (org-test-with-temp-text "#+SELECT_TAGS: a\n#+SELECT_TAGS: b"
  179. (org-export--get-inbuffer-options))
  180. '(:select-tags ("a" "b"))))
  181. ;; Test `parse' behaviour. `parse' implies `space' but preserve
  182. ;; line breaks. Multi-line objects are allowed.
  183. (should
  184. (org-element-map
  185. (org-test-with-temp-text "#+TITLE: *bold*"
  186. (plist-get (org-export--get-inbuffer-options) :title))
  187. 'bold #'identity nil t))
  188. (should
  189. (equal
  190. (org-test-with-temp-text "#+TITLE: Some title\n#+TITLE: with spaces"
  191. (plist-get (org-export--get-inbuffer-options) :title))
  192. '("Some title with spaces")))
  193. (should
  194. (org-element-map
  195. (org-test-with-temp-text "#+TITLE: Some title\\\\\n#+TITLE: with spaces"
  196. (plist-get (org-export--get-inbuffer-options) :title))
  197. 'line-break #'identity nil t))
  198. (should
  199. (org-element-map
  200. (org-test-with-temp-text "#+TITLE: *bold\n#+TITLE: sentence*"
  201. (plist-get (org-export--get-inbuffer-options) :title))
  202. 'bold #'identity nil t))
  203. ;; Options set through SETUPFILE.
  204. (should
  205. (equal
  206. (org-test-with-temp-text
  207. (format "#+DESCRIPTION: l1
  208. #+LANGUAGE: es
  209. #+SELECT_TAGS: a
  210. #+TITLE: a
  211. #+SETUPFILE: \"%s/examples/setupfile.org\"
  212. #+LANGUAGE: fr
  213. #+SELECT_TAGS: c
  214. #+TITLE: c"
  215. org-test-dir)
  216. (org-export--get-inbuffer-options))
  217. '(:language "fr" :select-tags ("a" "b" "c") :title ("a b c"))))
  218. ;; More than one property can refer to the same buffer keyword.
  219. (should
  220. (equal '(:k2 "value" :k1 "value")
  221. (let ((backend (org-export-create-backend
  222. :options '((:k1 "KEYWORD")
  223. (:k2 "KEYWORD")))))
  224. (org-test-with-temp-text "#+KEYWORD: value"
  225. (org-export--get-inbuffer-options backend)))))
  226. ;; Keywords in commented subtrees are ignored.
  227. (should-not
  228. (equal "Me"
  229. (org-test-with-parsed-data "* COMMENT H1\n#+AUTHOR: Me"
  230. (plist-get info :author))))
  231. (should-not
  232. (equal "Mine"
  233. (org-test-with-parsed-data "* COMMENT H1\n** H2\n#+EMAIL: Mine"
  234. (plist-get info :email)))))
  235. (ert-deftest test-org-export/get-subtree-options ()
  236. "Test setting options from headline's properties."
  237. ;; EXPORT_TITLE.
  238. (should
  239. (equal '("Subtree Title")
  240. (org-test-with-temp-text "#+TITLE: Title
  241. * Headline<point>
  242. :PROPERTIES:
  243. :EXPORT_TITLE: Subtree Title
  244. :END:
  245. Paragraph"
  246. (plist-get (org-export-get-environment nil t) :title))))
  247. ;; EXPORT_OPTIONS.
  248. (should
  249. (= 2
  250. (org-test-with-temp-text "#+OPTIONS: H:1
  251. * Headline<point>
  252. :PROPERTIES:
  253. :EXPORT_OPTIONS: H:2
  254. :END:
  255. Paragraph"
  256. (plist-get (org-export-get-environment nil t) :headline-levels))))
  257. ;; EXPORT_DATE.
  258. (should
  259. (equal '("29-03-2012")
  260. (org-test-with-temp-text "#+DATE: today
  261. * Headline<point>
  262. :PROPERTIES:
  263. :EXPORT_DATE: 29-03-2012
  264. :END:
  265. Paragraph"
  266. (plist-get (org-export-get-environment nil t) :date))))
  267. ;; Properties with `split' behaviour are stored as a list of
  268. ;; strings.
  269. (should
  270. (equal '("a" "b")
  271. (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
  272. * Headline<point>
  273. :PROPERTIES:
  274. :EXPORT_EXCLUDE_TAGS: a b
  275. :END:
  276. Paragraph"
  277. (plist-get (org-export-get-environment nil t) :exclude-tags))))
  278. ;; Handle :PROPERTY+: syntax.
  279. (should
  280. (equal '("a" "b")
  281. (org-test-with-temp-text "#+EXCLUDE_TAGS: noexport
  282. * Headline<point>
  283. :PROPERTIES:
  284. :EXPORT_EXCLUDE_TAGS: a
  285. :EXPORT_EXCLUDE_TAGS+: b
  286. :END:
  287. Paragraph"
  288. (plist-get (org-export-get-environment nil t) :exclude-tags))))
  289. ;; Export properties are case-insensitive.
  290. (should
  291. (equal '("29-03-2012")
  292. (org-test-with-temp-text "* Headline
  293. :PROPERTIES:
  294. :EXPORT_Date: 29-03-2012
  295. :END:
  296. Paragraph"
  297. (plist-get (org-export-get-environment nil t) :date))))
  298. ;; Still grab correct options when section above is empty.
  299. (should
  300. (equal '("H1")
  301. (org-test-with-temp-text "* H1\n** H11\n** H12<point>"
  302. (plist-get (org-export-get-environment nil t) :title))))
  303. ;; More than one property can refer to the same node property.
  304. (should
  305. (equal '("1" "1")
  306. (org-test-with-temp-text
  307. "* H\n:PROPERTIES:\n:EXPORT_A: 1\n:END:\n<point>"
  308. (let* ((backend (org-export-create-backend
  309. :options '((:k1 "A")
  310. (:k2 "A"))))
  311. (options (org-export-get-environment backend t)))
  312. (list (plist-get options :k1) (plist-get options :k2)))))))
  313. (ert-deftest test-org-export/set-title ()
  314. "Test title setting."
  315. ;; Without TITLE keyword.
  316. (should
  317. (equal
  318. ""
  319. (let (org-export-filter-body-functions
  320. org-export-filter-final-output-functions)
  321. (org-test-with-temp-text "Test"
  322. (org-export-as
  323. (org-export-create-backend
  324. :transcoders
  325. '((template . (lambda (text info)
  326. (org-element-interpret-data
  327. (plist-get info :title)))))))))))
  328. ;; With a blank TITLE keyword.
  329. (should
  330. (equal
  331. ""
  332. (let (org-export-filter-body-functions
  333. org-export-filter-final-output-functions)
  334. (org-test-with-temp-text "#+TITLE:\nTest"
  335. (org-export-as
  336. (org-export-create-backend
  337. :transcoders
  338. '((template . (lambda (text info)
  339. (org-element-interpret-data
  340. (plist-get info :title)))))))))))
  341. ;; With a non-empty TITLE keyword.
  342. (should
  343. (equal
  344. "Title"
  345. (org-test-with-temp-text "#+TITLE: Title\nTest"
  346. (org-export-as
  347. (org-export-create-backend
  348. :transcoders
  349. '((template . (lambda (text info)
  350. (org-element-interpret-data
  351. (plist-get info :title))))))))))
  352. ;; When exporting a subtree, its heading becomes the headline of the
  353. ;; document...
  354. (should
  355. (equal
  356. "Headline"
  357. (org-test-with-temp-text "* Headline\nBody"
  358. (org-export-as
  359. (org-export-create-backend
  360. :transcoders
  361. '((template . (lambda (text info)
  362. (org-element-interpret-data
  363. (plist-get info :title))))))
  364. 'subtree))))
  365. ;; ... unless there is an EXPORT_TITLE property at the root of the
  366. ;; subtree.
  367. (should
  368. (equal
  369. "B"
  370. (org-test-with-temp-text
  371. "* A\n :PROPERTIES:\n :EXPORT_TITLE: B\n :END:\nBody"
  372. (org-export-as
  373. (org-export-create-backend
  374. :transcoders
  375. '((template . (lambda (text info)
  376. (org-element-interpret-data
  377. (plist-get info :title))))))
  378. 'subtree)))))
  379. (ert-deftest test-org-export/handle-options ()
  380. "Test if export options have an impact on output."
  381. ;; Test exclude tags for headlines and inlinetasks.
  382. (should
  383. (equal ""
  384. (let (org-export-filter-body-functions
  385. org-export-filter-final-output-functions)
  386. (org-test-with-temp-text "* Head1 :noexp:"
  387. (org-export-as (org-test-default-backend)
  388. nil nil nil '(:exclude-tags ("noexp")))))))
  389. (should
  390. (equal "#+FILETAGS: noexp\n"
  391. (let (org-export-filter-body-functions
  392. org-export-filter-final-output-functions)
  393. (org-test-with-temp-text "#+FILETAGS: noexp\n* Head1"
  394. (org-export-as (org-test-default-backend)
  395. nil nil nil '(:exclude-tags ("noexp")))))))
  396. ;; Test include tags for headlines and inlinetasks.
  397. (should
  398. (equal (org-test-with-temp-text "* H1\n* H2\n** Sub :exp:\n*** Sub Sub\n* H3"
  399. (let ((org-tags-column 0))
  400. (org-export-as (org-test-default-backend)
  401. nil nil nil '(:select-tags ("exp")))))
  402. "* H2\n** Sub :exp:\n*** Sub Sub\n"))
  403. ;; If there is an include tag, ignore the section before the first
  404. ;; headline, if any.
  405. (should
  406. (equal (org-test-with-temp-text "First section\n* H1 :exp:\nBody"
  407. (let ((org-tags-column 0))
  408. (org-export-as (org-test-default-backend)
  409. nil nil nil '(:select-tags ("exp")))))
  410. "* H1 :exp:\nBody\n"))
  411. (should
  412. (equal (org-test-with-temp-text "#+FILETAGS: exp\nFirst section\n* H1\nBody"
  413. (org-export-as (org-test-default-backend)
  414. nil nil nil '(:select-tags ("exp"))))
  415. "* H1\nBody\n"))
  416. (should-not
  417. (equal (org-test-with-temp-text "* H1 :exp:\nBody"
  418. (let ((org-tags-column 0))
  419. (org-export-as (org-test-default-backend)
  420. nil nil nil '(:select-tags ("exp")))))
  421. "* H1 :exp:\n"))
  422. ;; Test mixing include tags and exclude tags.
  423. (should
  424. (string-match
  425. "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
  426. (org-test-with-temp-text "
  427. * Head1 :export:
  428. ** Sub-Head1 :noexport:
  429. ** Sub-Head2
  430. * Head2 :noexport:
  431. ** Sub-Head1 :export:"
  432. (org-export-as (org-test-default-backend) nil nil nil
  433. '(:select-tags ("export") :exclude-tags ("noexport"))))))
  434. ;; Ignore tasks.
  435. (should
  436. (equal ""
  437. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  438. org-export-filter-body-functions
  439. org-export-filter-final-output-functions)
  440. (org-test-with-temp-text "* TODO Head1"
  441. (org-export-as (org-test-default-backend)
  442. nil nil nil '(:with-tasks nil))))))
  443. (should
  444. (equal "* TODO Head1\n"
  445. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  446. (org-test-with-temp-text "* TODO Head1"
  447. (org-export-as (org-test-default-backend)
  448. nil nil nil '(:with-tasks t))))))
  449. ;; Archived tree.
  450. (should
  451. (equal ""
  452. (let (org-export-filter-body-functions
  453. org-export-filter-final-output-functions)
  454. (org-test-with-temp-text "* Head1 :archive:"
  455. (let ((org-archive-tag "archive"))
  456. (org-export-as (org-test-default-backend)
  457. nil nil nil '(:with-archived-trees nil)))))))
  458. (should
  459. (string-match
  460. "\\* Head1[ \t]+:archive:"
  461. (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
  462. (let ((org-archive-tag "archive"))
  463. (org-export-as (org-test-default-backend) nil nil nil
  464. '(:with-archived-trees headline))))))
  465. (should
  466. (string-match
  467. "\\`\\* Head1[ \t]+:archive:\n\\'"
  468. (org-test-with-temp-text "* Head1 :archive:"
  469. (let ((org-archive-tag "archive"))
  470. (org-export-as (org-test-default-backend)
  471. nil nil nil '(:with-archived-trees t))))))
  472. ;; Broken links. Depending on `org-export-with-broken-links', raise
  473. ;; an error, ignore link or mark is as broken in output.
  474. (should-error
  475. (org-test-with-temp-text "[[#broken][link]]"
  476. (let ((backend
  477. (org-export-create-backend
  478. :transcoders
  479. '((section . (lambda (_e c _i) c))
  480. (paragraph . (lambda (_e c _i) c))
  481. (link . (lambda (l c i) (org-export-resolve-id-link l i)))))))
  482. (org-export-as backend nil nil nil '(:with-broken-links nil)))))
  483. (should
  484. (org-test-with-temp-text "[[#broken][link]]"
  485. (let ((backend
  486. (org-export-create-backend
  487. :transcoders
  488. '((section . (lambda (_e c _i) c))
  489. (paragraph . (lambda (_e c _i) c))
  490. (link . (lambda (l c i) (org-export-resolve-id-link l i)))))))
  491. (org-export-as backend nil nil nil '(:with-broken-links t)))))
  492. (should
  493. (org-test-with-temp-text "[[#broken][link]]"
  494. (let ((backend
  495. (org-export-create-backend
  496. :transcoders
  497. '((section . (lambda (_e c _i) c))
  498. (paragraph . (lambda (_e c _i) c))
  499. (link . (lambda (l c i) (org-export-resolve-id-link l i)))))))
  500. (org-string-nw-p
  501. (org-export-as backend nil nil nil '(:with-broken-links mark))))))
  502. ;; Clocks.
  503. (should
  504. (string-match "CLOCK: \\[2012-04-29 .* 10:45\\]"
  505. (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
  506. (org-export-as (org-test-default-backend)
  507. nil nil nil '(:with-clocks t)))))
  508. (should
  509. (equal ""
  510. (let (org-export-filter-body-functions
  511. org-export-filter-final-output-functions)
  512. (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
  513. (org-export-as (org-test-default-backend)
  514. nil nil nil '(:with-clocks nil))))))
  515. ;; Drawers.
  516. (should
  517. (equal ""
  518. (let (org-export-filter-body-functions
  519. org-export-filter-final-output-functions)
  520. (org-test-with-temp-text ":TEST:\ncontents\n:END:"
  521. (org-export-as (org-test-default-backend)
  522. nil nil nil '(:with-drawers nil))))))
  523. (should
  524. (equal ":TEST:\ncontents\n:END:\n"
  525. (org-test-with-temp-text ":TEST:\ncontents\n:END:"
  526. (org-export-as (org-test-default-backend)
  527. nil nil nil '(:with-drawers t)))))
  528. (should
  529. (equal ":FOO:\nkeep\n:END:\n"
  530. (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
  531. (org-export-as (org-test-default-backend)
  532. nil nil nil '(:with-drawers ("FOO"))))))
  533. (should
  534. (equal ":FOO:\nkeep\n:END:\n"
  535. (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
  536. (org-export-as (org-test-default-backend)
  537. nil nil nil '(:with-drawers (not "BAR"))))))
  538. ;; Fixed-width.
  539. (should
  540. (equal ": A\n"
  541. (org-test-with-temp-text ": A"
  542. (org-export-as (org-test-default-backend) nil nil nil
  543. '(:with-fixed-width t)))))
  544. (should
  545. (equal ""
  546. (let (org-export-filter-body-functions
  547. org-export-filter-final-output-functions)
  548. (org-test-with-temp-text ": A"
  549. (org-export-as (org-test-default-backend) nil nil nil
  550. '(:with-fixed-width nil))))))
  551. ;; Footnotes.
  552. (should
  553. (equal "Footnote?"
  554. (let ((org-footnote-section nil))
  555. (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
  556. (org-trim (org-export-as (org-test-default-backend)
  557. nil nil nil '(:with-footnotes nil)))))))
  558. (should
  559. (equal "Footnote?[fn:1]\n\n[fn:1] Def"
  560. (let ((org-footnote-section nil))
  561. (org-test-with-temp-text "Footnote?[fn:1]\n\n[fn:1] Def"
  562. (org-trim (org-export-as (org-test-default-backend)
  563. nil nil nil '(:with-footnotes t)))))))
  564. ;; Inlinetasks.
  565. (when (featurep 'org-inlinetask)
  566. (should
  567. (equal
  568. ""
  569. (let ((org-inlinetask-min-level 15)
  570. org-export-filter-body-functions
  571. org-export-filter-final-output-functions)
  572. (org-test-with-temp-text "*************** Task"
  573. (org-export-as (org-test-default-backend)
  574. nil nil nil '(:with-inlinetasks nil))))))
  575. (should
  576. (equal
  577. ""
  578. (let ((org-inlinetask-min-level 15)
  579. org-export-filter-body-functions
  580. org-export-filter-final-output-functions)
  581. (org-test-with-temp-text
  582. "*************** Task\nContents\n*************** END"
  583. (org-export-as (org-test-default-backend)
  584. nil nil nil '(:with-inlinetasks nil)))))))
  585. ;; Plannings.
  586. (should
  587. (string-match
  588. "* H\nCLOSED: \\[2012-04-29 .* 10:45\\]"
  589. (let ((org-closed-string "CLOSED:"))
  590. (org-test-with-temp-text "* H\nCLOSED: [2012-04-29 sun. 10:45]"
  591. (org-export-as (org-test-default-backend)
  592. nil nil nil '(:with-planning t))))))
  593. (should
  594. (equal "* H\n"
  595. (let ((org-closed-string "CLOSED:"))
  596. (org-test-with-temp-text "* H\nCLOSED: [2012-04-29 sun. 10:45]"
  597. (org-export-as (org-test-default-backend)
  598. nil nil nil '(:with-planning nil))))))
  599. ;; Property Drawers.
  600. (should
  601. (equal "* H1\n"
  602. (org-test-with-temp-text
  603. "* H1\n :PROPERTIES:\n :PROP: value\n :END:"
  604. (org-export-as (org-test-default-backend)
  605. nil nil nil '(:with-properties nil)))))
  606. (should
  607. (equal "* H1\n:PROPERTIES:\n:PROP: value\n:END:\n"
  608. (org-test-with-temp-text
  609. "* H1\n :PROPERTIES:\n :PROP: value\n :END:"
  610. (org-export-as (org-test-default-backend)
  611. nil nil nil '(:with-properties t)))))
  612. (should
  613. (equal "* H1\n:PROPERTIES:\n:B: 2\n:END:\n"
  614. (org-test-with-temp-text
  615. "* H1\n :PROPERTIES:\n :A: 1\n :B: 2\n:END:"
  616. (org-export-as (org-test-default-backend)
  617. nil nil nil '(:with-properties ("B"))))))
  618. ;; Statistics cookies.
  619. (should
  620. (equal "* Stats"
  621. (let (org-export-filter-body-functions
  622. org-export-filter-final-output-functions)
  623. (org-trim
  624. (org-test-with-temp-text "* Stats [0/0]"
  625. (org-export-as (org-test-default-backend)
  626. nil nil nil '(:with-statistics-cookies nil)))))))
  627. ;; Tables.
  628. (should
  629. (equal "| A |\n"
  630. (org-test-with-temp-text "| A |"
  631. (org-export-as (org-test-default-backend) nil nil nil
  632. '(:with-tables t)))))
  633. (should
  634. (equal ""
  635. (let (org-export-filter-body-functions
  636. org-export-filter-final-output-functions)
  637. (org-test-with-temp-text "| A |"
  638. (org-export-as (org-test-default-backend) nil nil nil
  639. '(:with-tables nil)))))))
  640. (ert-deftest test-org-export/with-timestamps ()
  641. "Test `org-export-with-timestamps' specifications."
  642. ;; t value.
  643. (should
  644. (string-match
  645. "\\[2012-04-29 .*? 10:45\\]<2012-04-29 .*? 10:45>"
  646. (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
  647. (org-export-as (org-test-default-backend)
  648. nil nil nil '(:with-timestamps t)))))
  649. ;; nil value.
  650. (should
  651. (equal
  652. ""
  653. (let (org-export-filter-body-functions
  654. org-export-filter-final-output-functions)
  655. (org-trim
  656. (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
  657. (org-export-as (org-test-default-backend)
  658. nil nil nil '(:with-timestamps nil)))))))
  659. ;; `active' value.
  660. (should
  661. (string-match
  662. "<2012-03-29 .*?>\n\nParagraph <2012-03-29 .*?>\\[2012-03-29 .*?\\]"
  663. (org-test-with-temp-text
  664. "<2012-03-29 Thu>[2012-03-29 Thu]
  665. Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
  666. (org-export-as (org-test-default-backend)
  667. nil nil nil '(:with-timestamps active)))))
  668. ;; `inactive' value.
  669. (should
  670. (string-match
  671. "\\[2012-03-29 .*?\\]\n\nParagraph <2012-03-29 .*?>\\[2012-03-29 .*?\\]"
  672. (org-test-with-temp-text
  673. "<2012-03-29 Thu>[2012-03-29 Thu]
  674. Paragraph <2012-03-29 Thu>[2012-03-29 Thu]"
  675. (org-export-as (org-test-default-backend)
  676. nil nil nil '(:with-timestamps inactive))))))
  677. (ert-deftest test-org-export/comment-tree ()
  678. "Test if export process ignores commented trees."
  679. (should
  680. (equal ""
  681. (let (org-export-filter-body-functions
  682. org-export-filter-final-output-functions)
  683. (org-test-with-temp-text "* COMMENT Head1"
  684. (org-export-as (org-test-default-backend)))))))
  685. (ert-deftest test-org-export/uninterpreted ()
  686. "Test handling of uninterpreted elements."
  687. ;; Entities.
  688. (should
  689. (equal "dummy\n"
  690. (org-test-with-temp-text "\\alpha"
  691. (org-export-as
  692. (org-export-create-backend
  693. :transcoders '((entity . (lambda (e c i) "dummy"))
  694. (paragraph . (lambda (p c i) c))
  695. (section . (lambda (s c i) c))))
  696. nil nil nil '(:with-entities t)))))
  697. (should
  698. (equal "\\alpha\n"
  699. (org-test-with-temp-text "\\alpha"
  700. (org-export-as
  701. (org-export-create-backend
  702. :transcoders '((entity . (lambda (e c i) "dummy"))
  703. (paragraph . (lambda (p c i) c))
  704. (section . (lambda (s c i) c))))
  705. nil nil nil '(:with-entities nil)))))
  706. ;; Emphasis.
  707. (should
  708. (equal "dummy\n"
  709. (org-test-with-temp-text "*bold*"
  710. (org-export-as
  711. (org-export-create-backend
  712. :transcoders '((bold . (lambda (b c i) "dummy"))
  713. (paragraph . (lambda (p c i) c))
  714. (section . (lambda (s c i) c))))
  715. nil nil nil '(:with-emphasize t)))))
  716. (should
  717. (equal "*bold*\n"
  718. (org-test-with-temp-text "*bold*"
  719. (org-export-as
  720. (org-export-create-backend
  721. :transcoders '((bold . (lambda (b c i) "dummy"))
  722. (paragraph . (lambda (p c i) c))
  723. (section . (lambda (s c i) c))))
  724. nil nil nil '(:with-emphasize nil)))))
  725. ;; LaTeX environment.
  726. (should
  727. (equal "dummy\n"
  728. (org-test-with-temp-text "\\begin{equation}\n1+1=2\n\\end{equation}"
  729. (org-export-as
  730. (org-export-create-backend
  731. :transcoders '((latex-environment . (lambda (l c i) "dummy"))
  732. (section . (lambda (s c i) c))))
  733. nil nil nil '(:with-latex t)))))
  734. (should
  735. (equal "\\begin{equation}\n1+1=2\n\\end{equation}\n"
  736. (org-test-with-temp-text "\\begin{equation}\n1+1=2\n\\end{equation}"
  737. (org-export-as
  738. (org-export-create-backend
  739. :transcoders '((latex-environment . (lambda (l c i) "dummy"))
  740. (section . (lambda (s c i) c))))
  741. nil nil nil '(:with-latex verbatim)))))
  742. ;; LaTeX fragment.
  743. (should
  744. (equal "dummy\n"
  745. (org-test-with-temp-text "$1$"
  746. (org-export-as
  747. (org-export-create-backend
  748. :transcoders '((latex-fragment . (lambda (l c i) "dummy"))
  749. (paragraph . (lambda (p c i) c))
  750. (section . (lambda (s c i) c))))
  751. nil nil nil '(:with-latex t)))))
  752. (should
  753. (equal "$1$\n"
  754. (org-test-with-temp-text "$1$"
  755. (org-export-as
  756. (org-export-create-backend
  757. :transcoders '((latex-fragment . (lambda (l c i) "dummy"))
  758. (paragraph . (lambda (p c i) c))
  759. (section . (lambda (s c i) c))))
  760. nil nil nil '(:with-latex verbatim)))))
  761. ;; Sub/superscript.
  762. (should
  763. (equal "adummy\n"
  764. (org-test-with-temp-text "a_b"
  765. (org-export-as
  766. (org-export-create-backend
  767. :transcoders '((subscript . (lambda (s c i) "dummy"))
  768. (paragraph . (lambda (p c i) c))
  769. (section . (lambda (s c i) c))))
  770. nil nil nil '(:with-sub-superscript t)))))
  771. (should
  772. (equal "a_b\n"
  773. (org-test-with-temp-text "a_b"
  774. (org-export-as
  775. (org-export-create-backend
  776. :transcoders '((subscript . (lambda (s c i) "dummy"))
  777. (paragraph . (lambda (p c i) c))
  778. (section . (lambda (s c i) c))))
  779. nil nil nil '(:with-sub-superscript nil)))))
  780. (should
  781. (equal "a_b\n"
  782. (org-test-with-temp-text "a_b"
  783. (org-export-as
  784. (org-export-create-backend
  785. :transcoders '((subscript . (lambda (s c i) "dummy"))
  786. (paragraph . (lambda (p c i) c))
  787. (section . (lambda (s c i) c))))
  788. nil nil nil '(:with-sub-superscript {})))))
  789. (should
  790. (equal "adummy\n"
  791. (org-test-with-temp-text "a_{b}"
  792. (org-export-as
  793. (org-export-create-backend
  794. :transcoders '((subscript . (lambda (s c i) "dummy"))
  795. (paragraph . (lambda (p c i) c))
  796. (section . (lambda (s c i) c))))
  797. nil nil nil '(:with-sub-superscript {})))))
  798. (should
  799. (equal "a_entity\n"
  800. (org-test-with-temp-text "a_\\alpha"
  801. (org-export-as
  802. (org-export-create-backend
  803. :transcoders '((entity . (lambda (e c i) "entity"))
  804. (subscript . (lambda (s c i) "dummy"))
  805. (paragraph . (lambda (p c i) c))
  806. (section . (lambda (s c i) c))))
  807. nil nil nil '(:with-sub-superscript nil)))))
  808. ;; Also handle uninterpreted objects in title.
  809. (should
  810. (equal "a_b"
  811. (org-test-with-temp-text "#+TITLE: a_b"
  812. (org-export-as
  813. (org-export-create-backend
  814. :transcoders
  815. '((subscript . (lambda (s c i) "dummy"))
  816. (template . (lambda (c i) (org-export-data
  817. (plist-get i :title) i)))
  818. (section . (lambda (s c i) c))))
  819. nil nil nil '(:with-sub-superscript nil)))))
  820. ;; Handle uninterpreted objects in captions.
  821. (should
  822. (equal "adummy\n"
  823. (org-test-with-temp-text "#+CAPTION: a_b\nParagraph"
  824. (org-export-as
  825. (org-export-create-backend
  826. :transcoders
  827. '((subscript . (lambda (s c i) "dummy"))
  828. (paragraph . (lambda (p c i)
  829. (org-export-data (org-export-get-caption p) i)))
  830. (section . (lambda (s c i) c))))
  831. nil nil nil '(:with-sub-superscript t)))))
  832. (should
  833. (equal "a_b\n"
  834. (org-test-with-temp-text "#+CAPTION: a_b\nParagraph"
  835. (org-export-as
  836. (org-export-create-backend
  837. :transcoders
  838. '((subscript . (lambda (s c i) "dummy"))
  839. (paragraph . (lambda (p c i)
  840. (org-export-data (org-export-get-caption p) i)))
  841. (section . (lambda (s c i) c))))
  842. nil nil nil '(:with-sub-superscript nil)))))
  843. ;; Special case: multiples uninterpreted objects in a row.
  844. (should
  845. (equal "a_b_c_d\n"
  846. (org-test-with-temp-text "a_b_c_d"
  847. (org-export-as
  848. (org-export-create-backend
  849. :transcoders '((subscript . (lambda (s c i) "dummy"))
  850. (paragraph . (lambda (p c i) c))
  851. (section . (lambda (s c i) c))))
  852. nil nil nil '(:with-sub-superscript {}))))))
  853. (ert-deftest test-org-export/export-scope ()
  854. "Test all export scopes."
  855. ;; Subtree.
  856. (should
  857. (equal "text\n*** H3\n"
  858. (org-test-with-temp-text "* H1\n<point>** H2\ntext\n*** H3"
  859. (org-export-as (org-test-default-backend) 'subtree))))
  860. (should
  861. (equal "text\n*** H3\n"
  862. (org-test-with-temp-text "* H1\n** H2\n<point>text\n*** H3"
  863. (org-export-as (org-test-default-backend) 'subtree))))
  864. ;; Subtree with a code block calling another block outside.
  865. (should
  866. (equal ": 3\n"
  867. (org-test-with-temp-text "
  868. <point>* Head1
  869. #+BEGIN_SRC emacs-lisp :noweb yes :exports results
  870. <<test>>
  871. #+END_SRC
  872. * Head2
  873. #+NAME: test
  874. #+BEGIN_SRC emacs-lisp
  875. \(+ 1 2)
  876. #+END_SRC"
  877. (let ((org-export-use-babel t))
  878. (org-export-as (org-test-default-backend) 'subtree)))))
  879. ;; Subtree export should ignore leading planning line and property
  880. ;; drawer.
  881. (should
  882. (equal "Text\n"
  883. (org-test-with-temp-text "
  884. <point>* H
  885. SCHEDULED: <2012-03-29 Thu>
  886. :PROPERTIES:
  887. :A: 1
  888. :END:
  889. Text"
  890. (org-export-as (org-test-default-backend)
  891. 'subtree nil nil
  892. '(:with-planning t :with-properties t)))))
  893. ;; Visible.
  894. (should
  895. (equal "* H1\n"
  896. (org-test-with-temp-text "* H1\n** H2\ntext\n*** H3"
  897. (org-cycle)
  898. (org-export-as (org-test-default-backend) nil 'visible))))
  899. ;; Region.
  900. (should
  901. (equal "text\n"
  902. (org-test-with-temp-text "* H1\n** H2\n<point>text\n*** H3"
  903. (transient-mark-mode 1)
  904. (push-mark (point) t t)
  905. (end-of-line)
  906. (org-export-as (org-test-default-backend)))))
  907. ;; Body only.
  908. (let ((backend (org-test-default-backend)))
  909. (setf (org-export-backend-transcoders backend)
  910. (cons '(template . (lambda (body i)
  911. (format "BEGIN\n%sEND" body)))
  912. (org-export-backend-transcoders backend)))
  913. (org-test-with-temp-text "Text"
  914. (should (equal (org-export-as backend nil nil 'body-only)
  915. "Text\n"))
  916. (should (equal (org-export-as backend) "BEGIN\nText\nEND")))))
  917. (ert-deftest test-org-export/output-file-name ()
  918. "Test `org-export-output-file-name' specifications."
  919. ;; Export from a file: name is built from original file name.
  920. (should
  921. (org-test-with-temp-text-in-file "Test"
  922. (equal (concat (file-name-as-directory ".")
  923. (file-name-nondirectory
  924. (file-name-sans-extension (buffer-file-name))))
  925. (file-name-sans-extension (org-export-output-file-name ".ext")))))
  926. ;; When exporting to subtree, check EXPORT_FILE_NAME property first.
  927. (should
  928. (org-test-with-temp-text-in-file
  929. "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
  930. (equal (org-export-output-file-name ".ext" t) "./test.ext")))
  931. ;; From a buffer not associated to a file, too.
  932. (should
  933. (org-test-with-temp-text
  934. "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: test\n :END:"
  935. (equal (org-export-output-file-name ".ext" t) "./test.ext")))
  936. ;; When provided name is absolute, preserve it.
  937. (should
  938. (org-test-with-temp-text
  939. (format "* Test\n :PROPERTIES:\n :EXPORT_FILE_NAME: %s\n :END:"
  940. (expand-file-name "test"))
  941. (file-name-absolute-p (org-export-output-file-name ".ext" t))))
  942. ;; When PUB-DIR argument is provided, use it.
  943. (should
  944. (org-test-with-temp-text-in-file "Test"
  945. (equal (file-name-directory
  946. (org-export-output-file-name ".ext" nil "dir/"))
  947. "dir/")))
  948. ;; When returned name would overwrite original file, add EXTENSION
  949. ;; another time.
  950. (should
  951. (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
  952. (equal (org-export-output-file-name ".org") "./normal.org.org"))))
  953. (ert-deftest test-org-export/expand-include ()
  954. "Test file inclusion in an Org buffer."
  955. ;; Error when file isn't specified.
  956. (should-error
  957. (org-test-with-temp-text "#+INCLUDE: dummy.org"
  958. (org-export-expand-include-keyword)))
  959. ;; Full insertion with recursive inclusion.
  960. (should
  961. (equal
  962. (with-temp-buffer
  963. (insert-file
  964. (expand-file-name "examples/include.org" org-test-dir))
  965. (replace-regexp-in-string
  966. (regexp-quote "#+INCLUDE: \"include2.org\"")
  967. "Success!" (buffer-string)))
  968. (org-test-with-temp-text
  969. (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir)
  970. (org-export-expand-include-keyword)
  971. (buffer-string))))
  972. ;; Localized insertion.
  973. (org-test-with-temp-text
  974. (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
  975. org-test-dir)
  976. (org-export-expand-include-keyword)
  977. (should (equal (buffer-string)
  978. "Small Org file with an include keyword.\n")))
  979. ;; Insertion with constraints on headlines level.
  980. (should
  981. (equal
  982. "* Top heading\n** Heading\nbody\n"
  983. (org-test-with-temp-text
  984. (format
  985. "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-11\""
  986. org-test-dir)
  987. (org-export-expand-include-keyword)
  988. (buffer-string))))
  989. (should
  990. (equal
  991. "* Top heading\n* Heading\nbody\n"
  992. (org-test-with-temp-text
  993. (format
  994. "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-11\" :minlevel 1"
  995. org-test-dir)
  996. (org-export-expand-include-keyword)
  997. (buffer-string))))
  998. ;; Inclusion within an example block.
  999. (should
  1000. (equal
  1001. "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n"
  1002. (org-test-with-temp-text
  1003. (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" EXAMPLE"
  1004. org-test-dir)
  1005. (org-export-expand-include-keyword)
  1006. (buffer-string))))
  1007. ;; Inclusion within a src-block.
  1008. (should
  1009. (equal
  1010. "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"
  1011. (org-test-with-temp-text
  1012. (format
  1013. "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" SRC emacs-lisp"
  1014. org-test-dir)
  1015. (org-export-expand-include-keyword)
  1016. (buffer-string))))
  1017. ;; Inclusion within an html export-block.
  1018. (should
  1019. (equal
  1020. "#+BEGIN_EXPORT html\n<p>HTML!</p>\n#+END_EXPORT\n"
  1021. (org-test-with-temp-text
  1022. (format
  1023. "#+INCLUDE: \"%s/examples/include.html\" EXPORT html"
  1024. org-test-dir)
  1025. (org-export-expand-include-keyword)
  1026. (buffer-string))))
  1027. ;; Inclusion within an center paragraph
  1028. (should
  1029. (equal
  1030. "#+BEGIN_CENTER\nSuccess!\n#+END_CENTER\n"
  1031. (org-test-with-temp-text
  1032. (format
  1033. "#+INCLUDE: \"%s/examples/include2.org\" CENTER"
  1034. org-test-dir)
  1035. (org-export-expand-include-keyword)
  1036. (buffer-string))))
  1037. ;; Footnotes labels are local to each included file.
  1038. (should
  1039. (= 6
  1040. (length
  1041. (delete-dups
  1042. (let ((contents "
  1043. Footnotes[fn:1], [fn:test], [fn:test] and [fn:inline:inline footnote].
  1044. \[fn:1] Footnote 1
  1045. \[fn:test] Footnote \"test\""))
  1046. (org-test-with-temp-text-in-file contents
  1047. (let ((file1 (buffer-file-name)))
  1048. (org-test-with-temp-text-in-file contents
  1049. (let ((file2 (buffer-file-name)))
  1050. (org-test-with-temp-text
  1051. (format "#+INCLUDE: \"%s\"\n#+INCLUDE: \"%s\""
  1052. file1 file2)
  1053. (org-export-expand-include-keyword)
  1054. (org-element-map (org-element-parse-buffer)
  1055. 'footnote-reference
  1056. (lambda (r) (org-element-property :label r)))))))))))))
  1057. ;; Footnotes labels are not local to each include keyword.
  1058. (should
  1059. (= 3
  1060. (length
  1061. (delete-dups
  1062. (let ((contents "
  1063. Footnotes[fn:1], [fn:test] and [fn:inline:inline footnote].
  1064. \[fn:1] Footnote 1
  1065. \[fn:test] Footnote \"test\""))
  1066. (org-test-with-temp-text-in-file contents
  1067. (let ((file (buffer-file-name)))
  1068. (org-test-with-temp-text
  1069. (format "#+INCLUDE: \"%s\"\n#+INCLUDE: \"%s\"" file file)
  1070. (org-export-expand-include-keyword)
  1071. (org-element-map (org-element-parse-buffer)
  1072. 'footnote-reference
  1073. (lambda (ref) (org-element-property :label ref)))))))))))
  1074. ;; Footnotes are supported by :lines-like elements and unnecessary
  1075. ;; footnotes are dropped.
  1076. (should
  1077. (= 3
  1078. (length
  1079. (delete-dups
  1080. (let ((contents "
  1081. * foo
  1082. Footnotes[fn:1]
  1083. * bar
  1084. Footnotes[fn:2], foot[fn:test] and [fn:inline:inline footnote]
  1085. \[fn:1] Footnote 1
  1086. \[fn:2] Footnote 1
  1087. * Footnotes
  1088. \[fn:test] Footnote \"test\"
  1089. "))
  1090. (org-test-with-temp-text-in-file contents
  1091. (let ((file (buffer-file-name)))
  1092. (org-test-with-temp-text
  1093. (format "#+INCLUDE: \"%s::*bar\"\n" file)
  1094. (org-export-expand-include-keyword)
  1095. (org-element-map (org-element-parse-buffer)
  1096. 'footnote-definition
  1097. (lambda (ref) (org-element-property :label ref)))))))))))
  1098. ;; If only-contents is non-nil only include contents of element.
  1099. (should
  1100. (equal
  1101. "body\n"
  1102. (org-test-with-temp-text
  1103. (concat
  1104. (format "#+INCLUDE: \"%s/examples/include.org::*Heading\" "
  1105. org-test-dir)
  1106. ":only-contents t")
  1107. (org-export-expand-include-keyword)
  1108. (buffer-string))))
  1109. ;; Headings can be included via CUSTOM_ID.
  1110. (should
  1111. (org-test-with-temp-text
  1112. (format "#+INCLUDE: \"%s/examples/include.org::#ah\"" org-test-dir)
  1113. (org-export-expand-include-keyword)
  1114. (goto-char (point-min))
  1115. (looking-at "* Another heading")))
  1116. ;; Named objects can be included.
  1117. (should
  1118. (equal
  1119. "| 1 |\n"
  1120. (org-test-with-temp-text
  1121. (format "#+INCLUDE: \"%s/examples/include.org::tbl\" :only-contents t"
  1122. org-test-dir)
  1123. (org-export-expand-include-keyword)
  1124. (buffer-string))))
  1125. ;; Including non-existing elements should result in an error.
  1126. (should-error
  1127. (org-test-with-temp-text
  1128. (format "#+INCLUDE: \"%s/examples/include.org::*non-existing heading\""
  1129. org-test-dir)
  1130. (org-export-expand-include-keyword)))
  1131. ;; Lines work relatively to an included element.
  1132. (should
  1133. (equal
  1134. "2\n3\n"
  1135. (org-test-with-temp-text
  1136. (format "#+INCLUDE: \"%s/examples/include.org::#ah\" :only-contents t \
  1137. :lines \"2-3\""
  1138. org-test-dir)
  1139. (org-export-expand-include-keyword)
  1140. (buffer-string))))
  1141. ;; Properties should be dropped from headlines.
  1142. (should
  1143. (equal
  1144. (org-test-with-temp-text
  1145. (format "#+INCLUDE: \"%s/examples/include.org::#ht\" :only-contents t"
  1146. org-test-dir)
  1147. (org-export-expand-include-keyword)
  1148. (buffer-string))
  1149. (org-test-with-temp-text
  1150. (format "#+INCLUDE: \"%s/examples/include.org::tbl\"" org-test-dir)
  1151. (org-export-expand-include-keyword)
  1152. (buffer-string))))
  1153. ;; Properties should be dropped, drawers should not be.
  1154. (should
  1155. (equal
  1156. ":LOGBOOK:\ndrawer\n:END:\ncontent\n"
  1157. (org-test-with-temp-text
  1158. (format "#+INCLUDE: \"%s/examples/include.org::#dh\" :only-contents t"
  1159. org-test-dir)
  1160. (org-export-expand-include-keyword)
  1161. (buffer-string))))
  1162. ;; Adjacent INCLUDE-keywords should have the same :minlevel if unspecified.
  1163. (should
  1164. (cl-every (lambda (level) (zerop (1- level)))
  1165. (org-test-with-temp-text
  1166. (concat
  1167. (format "#+INCLUDE: \"%s/examples/include.org::#ah\"\n"
  1168. org-test-dir)
  1169. (format "#+INCLUDE: \"%s/examples/include.org::*Heading\""
  1170. org-test-dir))
  1171. (org-export-expand-include-keyword)
  1172. (org-element-map (org-element-parse-buffer) 'headline
  1173. (lambda (head) (org-element-property :level head))))))
  1174. ;; INCLUDE does not insert induced :minlevel for src-blocks.
  1175. (should-not
  1176. (equal
  1177. (org-test-with-temp-text
  1178. (format "#+INCLUDE: \"%s/examples/include2.org\" src emacs-lisp"
  1179. org-test-dir)
  1180. (org-export-expand-include-keyword)
  1181. (buffer-string))
  1182. (org-test-with-temp-text
  1183. (format
  1184. "#+INCLUDE: \"%s/examples/include2.org\" src emacs-lisp :minlevel 1"
  1185. org-test-dir)
  1186. (org-export-expand-include-keyword)
  1187. (buffer-string))))
  1188. ;; INCLUDE assigns the relative :minlevel conditional on narrowing.
  1189. (should
  1190. (org-test-with-temp-text-in-file
  1191. (format "* h1\n<point>#+INCLUDE: \"%s/examples/include.org::#ah\""
  1192. org-test-dir)
  1193. (narrow-to-region (point) (point-max))
  1194. (org-export-expand-include-keyword)
  1195. (eq 1 (org-current-level))))
  1196. ;; If :minlevel is present do not alter it.
  1197. (should
  1198. (org-test-with-temp-text
  1199. (format
  1200. "* h1\n<point>#+INCLUDE: \"%s/examples/include.org::#ah\" :minlevel 3"
  1201. org-test-dir)
  1202. (narrow-to-region (point) (point-max))
  1203. (org-export-expand-include-keyword)
  1204. (eq 3 (org-current-level)))))
  1205. (ert-deftest test-org-export/expand-macro ()
  1206. "Test macro expansion in an Org buffer."
  1207. (require 'ox-org)
  1208. ;; Standard macro expansion.
  1209. (should
  1210. (equal "#+MACRO: macro1 value\nvalue\n"
  1211. (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
  1212. (org-export-as (org-test-default-backend)))))
  1213. ;; Allow macro in parsed keywords and associated properties.
  1214. ;; Standard macro expansion.
  1215. (should
  1216. (string-match
  1217. "#\\+K: value"
  1218. (let ((backend (org-export-create-backend
  1219. :parent 'org
  1220. :options '((:k "K" nil nil parse)))))
  1221. (org-test-with-temp-text "#+MACRO: macro value\n#+K: {{{macro}}}"
  1222. (org-export-as backend)))))
  1223. (should
  1224. (string-match
  1225. ":EXPORT_K: v"
  1226. (let ((backend (org-export-create-backend
  1227. :parent 'org
  1228. :options '((:k "K" nil nil parse)))))
  1229. (org-test-with-temp-text
  1230. "#+MACRO: m v\n* H\n:PROPERTIES:\n:EXPORT_K: {{{m}}}\n:END:"
  1231. (org-export-as backend nil nil nil '(:with-properties t))))))
  1232. ;; Expand specific macros.
  1233. (should
  1234. (equal "me 2012-03-29 me@here Title\n"
  1235. (org-test-with-temp-text
  1236. "
  1237. #+TITLE: Title
  1238. #+DATE: 2012-03-29
  1239. #+AUTHOR: me
  1240. #+EMAIL: me@here
  1241. {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
  1242. (let ((output (org-export-as (org-test-default-backend))))
  1243. (substring output (string-match ".*\n\\'" output))))))
  1244. ;; Expand specific macros when property contained a regular macro
  1245. ;; already.
  1246. (should
  1247. (equal "value\n"
  1248. (org-test-with-temp-text "
  1249. #+MACRO: macro1 value
  1250. #+TITLE: {{{macro1}}}
  1251. {{{title}}}"
  1252. (let ((output (org-export-as (org-test-default-backend))))
  1253. (substring output (string-match ".*\n\\'" output))))))
  1254. ;; Expand macros with templates in included files.
  1255. (should
  1256. (equal "success\n"
  1257. (org-test-with-temp-text
  1258. (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
  1259. {{{included-macro}}}" org-test-dir)
  1260. (let ((output (org-export-as (org-test-default-backend))))
  1261. (substring output (string-match ".*\n\\'" output))))))
  1262. ;; Date macro takes a optional formatting argument
  1263. (should
  1264. (equal "09-02-15\n"
  1265. (org-test-with-temp-text "{{{date(%d-%m-%y)}}}\n* d :noexport:\n#+DATE: <2015-02-09>"
  1266. (org-export-as (org-test-default-backend)))))
  1267. ;; Only single timestamps are formatted
  1268. (should
  1269. (equal "<2015-02x-09>\n"
  1270. (org-test-with-temp-text "{{{date(%d-%m-%y)}}}\n* d :noexport:\n#+DATE: <2015-02x-09>"
  1271. (org-export-as (org-test-default-backend)))))
  1272. ;; Throw an error when a macro definition is missing.
  1273. (should-error
  1274. (org-test-with-temp-text "{{{missing}}}"
  1275. (org-export-as (org-test-default-backend))))
  1276. ;; Macros defined in commented subtrees are ignored.
  1277. (should-error
  1278. (org-test-with-temp-text
  1279. "* COMMENT H\n#+MACRO: macro1\n* H2\nvalue\n{{{macro1}}}"
  1280. (org-export-as (org-test-default-backend))))
  1281. (should-error
  1282. (org-test-with-temp-text
  1283. "* COMMENT H\n** H2\n#+MACRO: macro1\n* H3\nvalue\n{{{macro1}}}"
  1284. (org-export-as (org-test-default-backend)))))
  1285. (ert-deftest test-org-export/before-processing-hook ()
  1286. "Test `org-export-before-processing-hook'."
  1287. (should
  1288. (equal
  1289. "#+MACRO: mac val\nTest\n"
  1290. (org-test-with-temp-text "#+MACRO: mac val\n{{{mac}}} Test"
  1291. (let ((org-export-before-processing-hook
  1292. '((lambda (backend)
  1293. (while (re-search-forward "{{{" nil t)
  1294. (let ((object (org-element-context)))
  1295. (when (eq (org-element-type object) 'macro)
  1296. (delete-region
  1297. (org-element-property :begin object)
  1298. (org-element-property :end object)))))))))
  1299. (org-export-as (org-test-default-backend)))))))
  1300. (ert-deftest test-org-export/before-parsing-hook ()
  1301. "Test `org-export-before-parsing-hook'."
  1302. (should
  1303. (equal "Body 1\nBody 2\n"
  1304. (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
  1305. (let ((org-export-before-parsing-hook
  1306. '((lambda (backend)
  1307. (goto-char (point-min))
  1308. (while (re-search-forward org-outline-regexp-bol nil t)
  1309. (delete-region
  1310. (point-at-bol) (progn (forward-line) (point))))))))
  1311. (org-export-as (org-test-default-backend)))))))
  1312. ;;; Affiliated Keywords
  1313. (ert-deftest test-org-export/read-attribute ()
  1314. "Test `org-export-read-attribute' specifications."
  1315. ;; Standard test.
  1316. (should
  1317. (equal
  1318. (org-export-read-attribute
  1319. :attr_html
  1320. (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
  1321. (org-element-at-point)))
  1322. '(:a "1" :b "2")))
  1323. ;; Return nil on empty attribute.
  1324. (should-not
  1325. (org-export-read-attribute
  1326. :attr_html
  1327. (org-test-with-temp-text "Paragraph" (org-element-at-point))))
  1328. ;; Return nil on "nil" string.
  1329. (should
  1330. (equal '(:a nil :b nil)
  1331. (org-export-read-attribute
  1332. :attr_html
  1333. (org-test-with-temp-text "#+ATTR_HTML: :a nil :b nil\nParagraph"
  1334. (org-element-at-point)))))
  1335. ;; Return nil on empty string.
  1336. (should
  1337. (equal '(:a nil :b nil)
  1338. (org-export-read-attribute
  1339. :attr_html
  1340. (org-test-with-temp-text "#+ATTR_HTML: :a :b\nParagraph"
  1341. (org-element-at-point)))))
  1342. ;; Return empty string when value is "".
  1343. (should
  1344. (equal '(:a "")
  1345. (org-export-read-attribute
  1346. :attr_html
  1347. (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\nParagraph"
  1348. (org-element-at-point)))))
  1349. ;; Return \"\" when value is """".
  1350. (should
  1351. (equal '(:a "\"\"")
  1352. (org-export-read-attribute
  1353. :attr_html
  1354. (org-test-with-temp-text "#+ATTR_HTML: :a \"\"\"\"\nParagraph"
  1355. (org-element-at-point)))))
  1356. ;; Ignore text before first property.
  1357. (should-not
  1358. (member "ignore"
  1359. (org-export-read-attribute
  1360. :attr_html
  1361. (org-test-with-temp-text "#+ATTR_HTML: ignore :a 1\nParagraph"
  1362. (org-element-at-point))))))
  1363. (ert-deftest test-org-export/get-caption ()
  1364. "Test `org-export-get-caption' specifications."
  1365. ;; Without optional argument, return long caption
  1366. (should
  1367. (equal
  1368. '("l")
  1369. (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
  1370. (org-export-get-caption (org-element-at-point)))))
  1371. ;; With optional argument, return short caption.
  1372. (should
  1373. (equal
  1374. '("s")
  1375. (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
  1376. (org-export-get-caption (org-element-at-point) t))))
  1377. ;; Multiple lines are separated by white spaces.
  1378. (should
  1379. (equal
  1380. '("a" " " "b")
  1381. (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
  1382. (org-export-get-caption (org-element-at-point))))))
  1383. ;;; Back-End Tools
  1384. (ert-deftest test-org-export/define-backend ()
  1385. "Test back-end definition and accessors."
  1386. ;; Translate table.
  1387. (should
  1388. (equal '((headline . my-headline-test))
  1389. (let (org-export-registered-backends)
  1390. (org-export-define-backend 'test '((headline . my-headline-test)))
  1391. (org-export-get-all-transcoders 'test))))
  1392. ;; Filters.
  1393. (should
  1394. (equal '((:filter-headline . my-filter))
  1395. (let (org-export-registered-backends)
  1396. (org-export-define-backend 'test
  1397. '((headline . my-headline-test))
  1398. :filters-alist '((:filter-headline . my-filter)))
  1399. (org-export-backend-filters (org-export-get-backend 'test)))))
  1400. ;; Options.
  1401. (should
  1402. (equal '((:prop value))
  1403. (let (org-export-registered-backends)
  1404. (org-export-define-backend 'test
  1405. '((headline . my-headline-test))
  1406. :options-alist '((:prop value)))
  1407. (org-export-backend-options (org-export-get-backend 'test)))))
  1408. ;; Menu.
  1409. (should
  1410. (equal '(?k "Test Export" test)
  1411. (let (org-export-registered-backends)
  1412. (org-export-define-backend 'test
  1413. '((headline . my-headline-test))
  1414. :menu-entry '(?k "Test Export" test))
  1415. (org-export-backend-menu (org-export-get-backend 'test))))))
  1416. (ert-deftest test-org-export/define-derived-backend ()
  1417. "Test `org-export-define-derived-backend' specifications."
  1418. ;; Error when parent back-end is not defined.
  1419. (should-error
  1420. (let (org-export-registered-backends)
  1421. (org-export-define-derived-backend 'test 'parent)))
  1422. ;; Append translation table to parent's.
  1423. (should
  1424. (equal '((:headline . test) (:headline . parent))
  1425. (let (org-export-registered-backends)
  1426. (org-export-define-backend 'parent '((:headline . parent)))
  1427. (org-export-define-derived-backend 'test 'parent
  1428. :translate-alist '((:headline . test)))
  1429. (org-export-get-all-transcoders 'test))))
  1430. ;; Options defined in the new back have priority over those defined
  1431. ;; in parent.
  1432. (should
  1433. (eq 'test
  1434. (let (org-export-registered-backends)
  1435. (org-export-define-backend 'parent
  1436. '((:headline . parent))
  1437. :options-alist '((:a nil nil 'parent)))
  1438. (org-export-define-derived-backend 'test 'parent
  1439. :options-alist '((:a nil nil 'test)))
  1440. (plist-get (org-export--get-global-options
  1441. (org-export-get-backend 'test))
  1442. :a)))))
  1443. (ert-deftest test-org-export/derived-backend-p ()
  1444. "Test `org-export-derived-backend-p' specifications."
  1445. ;; Non-nil with direct match.
  1446. (should
  1447. (let (org-export-registered-backends)
  1448. (org-export-define-backend 'test '((headline . test)))
  1449. (org-export-derived-backend-p 'test 'test)))
  1450. (should
  1451. (let (org-export-registered-backends)
  1452. (org-export-define-backend 'test '((headline . test)))
  1453. (org-export-define-derived-backend 'test2 'test)
  1454. (org-export-derived-backend-p 'test2 'test2)))
  1455. ;; Non-nil with a direct parent.
  1456. (should
  1457. (let (org-export-registered-backends)
  1458. (org-export-define-backend 'test '((headline . test)))
  1459. (org-export-define-derived-backend 'test2 'test)
  1460. (org-export-derived-backend-p 'test2 'test)))
  1461. ;; Non-nil with an indirect parent.
  1462. (should
  1463. (let (org-export-registered-backends)
  1464. (org-export-define-backend 'test '((headline . test)))
  1465. (org-export-define-derived-backend 'test2 'test)
  1466. (org-export-define-derived-backend 'test3 'test2)
  1467. (org-export-derived-backend-p 'test3 'test)))
  1468. ;; Nil otherwise.
  1469. (should-not
  1470. (let (org-export-registered-backends)
  1471. (org-export-define-backend 'test '((headline . test)))
  1472. (org-export-define-backend 'test2 '((headline . test2)))
  1473. (org-export-derived-backend-p 'test2 'test)))
  1474. (should-not
  1475. (let (org-export-registered-backends)
  1476. (org-export-define-backend 'test '((headline . test)))
  1477. (org-export-define-backend 'test2 '((headline . test2)))
  1478. (org-export-define-derived-backend 'test3 'test2)
  1479. (org-export-derived-backend-p 'test3 'test))))
  1480. (ert-deftest test-org-export/get-all-transcoders ()
  1481. "Test `org-export-get-all-transcoders' specifications."
  1482. ;; Return nil when back-end cannot be found.
  1483. (should-not (org-export-get-all-transcoders nil))
  1484. ;; Same as `org-export-transcoders' if no parent.
  1485. (should
  1486. (equal '((headline . ignore))
  1487. (org-export-get-all-transcoders
  1488. (org-export-create-backend
  1489. :transcoders '((headline . ignore))))))
  1490. ;; But inherit from all ancestors whenever possible.
  1491. (should
  1492. (equal '((section . ignore) (headline . ignore))
  1493. (let (org-export-registered-backends)
  1494. (org-export-define-backend 'b1 '((headline . ignore)))
  1495. (org-export-get-all-transcoders
  1496. (org-export-create-backend
  1497. :parent 'b1 :transcoders '((section . ignore)))))))
  1498. (should
  1499. (equal '((paragraph . ignore) (section . ignore) (headline . ignore))
  1500. (let (org-export-registered-backends)
  1501. (org-export-define-backend 'b1 '((headline . ignore)))
  1502. (org-export-define-derived-backend 'b2 'b1
  1503. :translate-alist '((section . ignore)))
  1504. (org-export-get-all-transcoders
  1505. (org-export-create-backend
  1506. :parent 'b2 :transcoders '((paragraph . ignore)))))))
  1507. ;; Back-end transcoders overrule inherited ones.
  1508. (should
  1509. (eq 'b
  1510. (let (org-export-registered-backends)
  1511. (org-export-define-backend 'b1 '((headline . a)))
  1512. (cdr (assq 'headline
  1513. (org-export-get-all-transcoders
  1514. (org-export-create-backend
  1515. :parent 'b1 :transcoders '((headline . b))))))))))
  1516. (ert-deftest test-org-export/get-all-options ()
  1517. "Test `org-export-get-all-options' specifications."
  1518. ;; Return nil when back-end cannot be found.
  1519. (should-not (org-export-get-all-options nil))
  1520. ;; Same as `org-export-options' if no parent.
  1521. (should
  1522. (equal '((headline . ignore))
  1523. (org-export-get-all-options
  1524. (org-export-create-backend
  1525. :options '((headline . ignore))))))
  1526. ;; But inherit from all ancestors whenever possible.
  1527. (should
  1528. (equal '((:key2 value2) (:key1 value1))
  1529. (let (org-export-registered-backends)
  1530. (org-export-define-backend 'b1 nil :options-alist '((:key1 value1)))
  1531. (org-export-get-all-options
  1532. (org-export-create-backend
  1533. :parent 'b1 :options '((:key2 value2)))))))
  1534. (should
  1535. (equal '((:key3 value3) (:key2 value2) (:key1 value1))
  1536. (let (org-export-registered-backends)
  1537. (org-export-define-backend 'b1 nil :options-alist '((:key1 value1)))
  1538. (org-export-define-derived-backend 'b2 'b1
  1539. :options-alist '((:key2 value2)))
  1540. (org-export-get-all-options
  1541. (org-export-create-backend
  1542. :parent 'b2 :options '((:key3 value3)))))))
  1543. ;; Back-end options overrule inherited ones.
  1544. (should
  1545. (eq 'b
  1546. (let (org-export-registered-backends)
  1547. (org-export-define-backend 'b1 nil :options-alist '((:key1 . a)))
  1548. (cdr (assq :key1
  1549. (org-export-get-all-options
  1550. (org-export-create-backend
  1551. :parent 'b1 :options '((:key1 . b))))))))))
  1552. (ert-deftest test-org-export/get-all-filters ()
  1553. "Test `org-export-get-all-filters' specifications."
  1554. ;; Return nil when back-end cannot be found.
  1555. (should-not (org-export-get-all-filters nil))
  1556. ;; Same as `org-export-filters' if no parent.
  1557. (should
  1558. (equal '((:filter-headline . ignore))
  1559. (org-export-get-all-filters
  1560. (org-export-create-backend
  1561. :filters '((:filter-headline . ignore))))))
  1562. ;; But inherit from all ancestors whenever possible.
  1563. (should
  1564. (equal '((:filter-section . ignore) (:filter-headline . ignore))
  1565. (let (org-export-registered-backends)
  1566. (org-export-define-backend 'b1
  1567. nil :filters-alist '((:filter-headline . ignore)))
  1568. (org-export-get-all-filters
  1569. (org-export-create-backend
  1570. :parent 'b1 :filters '((:filter-section . ignore)))))))
  1571. (should
  1572. (equal '((:filter-paragraph . ignore)
  1573. (:filter-section . ignore)
  1574. (:filter-headline . ignore))
  1575. (let (org-export-registered-backends)
  1576. (org-export-define-backend 'b1
  1577. nil :filters-alist '((:filter-headline . ignore)))
  1578. (org-export-define-derived-backend 'b2 'b1
  1579. :filters-alist '((:filter-section . ignore)))
  1580. (org-export-get-all-filters
  1581. (org-export-create-backend
  1582. :parent 'b2 :filters '((:filter-paragraph . ignore)))))))
  1583. ;; Back-end filters overrule inherited ones.
  1584. (should
  1585. (eq 'b
  1586. (let (org-export-registered-backends)
  1587. (org-export-define-backend 'b1 '((:filter-headline . a)))
  1588. (cdr (assq :filter-headline
  1589. (org-export-get-all-filters
  1590. (org-export-create-backend
  1591. :parent 'b1 :filters '((:filter-headline . b))))))))))
  1592. (ert-deftest test-org-export/with-backend ()
  1593. "Test `org-export-with-backend' definition."
  1594. ;; Error when calling an undefined back-end
  1595. (should-error (org-export-with-backend nil "Test"))
  1596. ;; Error when called back-end doesn't have an appropriate
  1597. ;; transcoder.
  1598. (should-error
  1599. (org-export-with-backend
  1600. (org-export-create-backend :transcoders '((headline . ignore)))
  1601. "Test"))
  1602. ;; Otherwise, export using correct transcoder
  1603. (should
  1604. (equal "Success"
  1605. (let (org-export-registered-backends)
  1606. (org-export-define-backend 'test
  1607. '((plain-text . (lambda (text contents info) "Failure"))))
  1608. (org-export-define-backend 'test2
  1609. '((plain-text . (lambda (text contents info) "Success"))))
  1610. (org-export-with-backend 'test2 "Test"))))
  1611. ;; Provide correct back-end if transcoder needs to use recursive
  1612. ;; calls anyway.
  1613. (should
  1614. (equal "Success\n"
  1615. (let ((test-back-end
  1616. (org-export-create-backend
  1617. :transcoders
  1618. (list (cons 'headline
  1619. (lambda (headline contents info)
  1620. (org-export-data
  1621. (org-element-property :title headline)
  1622. info)))
  1623. (cons 'plain-text (lambda (text info) "Success"))))))
  1624. (org-export-string-as
  1625. "* Test"
  1626. (org-export-create-backend
  1627. :transcoders
  1628. (list (cons 'headline
  1629. (lambda (headline contents info)
  1630. (org-export-with-backend
  1631. test-back-end headline contents info))))))))))
  1632. (ert-deftest test-org-export/data-with-backend ()
  1633. "Test `org-export-data-with-backend' specifications."
  1634. ;; Error when calling an undefined back-end.
  1635. (should-error (org-export-data-with-backend nil "nil" nil))
  1636. ;; Otherwise, export data recursively, using correct back-end.
  1637. (should
  1638. (equal
  1639. "Success!"
  1640. (org-export-data-with-backend
  1641. '(bold nil "Test")
  1642. (org-export-create-backend
  1643. :transcoders
  1644. '((plain-text . (lambda (text info) "Success"))
  1645. (bold . (lambda (bold contents info) (concat contents "!")))))
  1646. '(:with-emphasize t)))))
  1647. ;;; Comments
  1648. (ert-deftest test-org-export/comments ()
  1649. "Test comments handling during export.
  1650. In particular, structure of the document mustn't be altered after
  1651. comments removal."
  1652. (should
  1653. (equal (org-test-with-temp-text "
  1654. Para1
  1655. # Comment
  1656. # Comment
  1657. Para2"
  1658. (org-export-as (org-test-default-backend)))
  1659. "Para1\n\nPara2\n"))
  1660. (should
  1661. (equal (org-test-with-temp-text "
  1662. Para1
  1663. # Comment
  1664. Para2"
  1665. (org-export-as (org-test-default-backend)))
  1666. "Para1\n\nPara2\n"))
  1667. (should
  1668. (equal (org-test-with-temp-text "
  1669. \[fn:1] Para1
  1670. # Inside definition
  1671. # Outside definition
  1672. Para2"
  1673. (org-export-as (org-test-default-backend)))
  1674. "[fn:1] Para1\n\n\nPara2\n"))
  1675. (should
  1676. (equal (org-test-with-temp-text "
  1677. \[fn:1] Para1
  1678. # Inside definition
  1679. # Inside definition
  1680. Para2"
  1681. (org-export-as (org-test-default-backend)))
  1682. "[fn:1] Para1\n\nPara2\n"))
  1683. (should
  1684. (equal (org-test-with-temp-text "
  1685. \[fn:1] Para1
  1686. # Inside definition
  1687. Para2"
  1688. (org-export-as (org-test-default-backend)))
  1689. "[fn:1] Para1\n\nPara2\n"))
  1690. (should
  1691. (equal (org-test-with-temp-text "
  1692. \[fn:1] Para1
  1693. # Inside definition
  1694. Para2"
  1695. (org-export-as (org-test-default-backend)))
  1696. "[fn:1] Para1\n\nPara2\n")))
  1697. ;;; Export blocks
  1698. (ert-deftest test-org-export/export-block ()
  1699. "Test export blocks transcoding."
  1700. (should
  1701. (equal "Success!\n"
  1702. (org-test-with-temp-text
  1703. "#+BEGIN_EXPORT backend\nSuccess!\n#+END_EXPORT"
  1704. (org-export-as
  1705. (org-export-create-backend
  1706. :transcoders '((export-block . (lambda (b _c _i)
  1707. (org-element-property :value b)))
  1708. (section . (lambda (_s c _i) c))))))))
  1709. (should
  1710. (equal "Success!\n"
  1711. (org-test-with-temp-text
  1712. "#+BEGIN_EXPORT backend\nSuccess!\n#+END_EXPORT"
  1713. (org-export-as
  1714. (org-export-create-backend
  1715. :transcoders
  1716. (list
  1717. (cons 'export-block
  1718. (lambda (b _c _i)
  1719. (and (equal (org-element-property :type b) "BACKEND")
  1720. (org-element-property :value b))))
  1721. (cons 'section (lambda (_s c _i) c)))))))))
  1722. ;;; Export Snippets
  1723. (ert-deftest test-org-export/export-snippet ()
  1724. "Test export snippets transcoding."
  1725. ;; Standard test.
  1726. (org-test-with-temp-text "@@test:A@@@@t:B@@"
  1727. (let ((backend (org-test-default-backend)))
  1728. (setf (org-export-backend-name backend) 'test)
  1729. (setf (org-export-backend-transcoders backend)
  1730. (cons (cons 'export-snippet
  1731. (lambda (snippet contents info)
  1732. (when (eq (org-export-snippet-backend snippet) 'test)
  1733. (org-element-property :value snippet))))
  1734. (org-export-backend-transcoders backend)))
  1735. (let ((org-export-snippet-translation-alist nil))
  1736. (should (equal (org-export-as backend) "A\n")))
  1737. (let ((org-export-snippet-translation-alist '(("t" . "test"))))
  1738. (should (equal (org-export-as backend) "AB\n")))))
  1739. ;; Ignored export snippets do not remove any blank.
  1740. (should
  1741. (equal "begin end\n"
  1742. (org-test-with-parsed-data "begin @@test:A@@ end"
  1743. (org-export-data-with-backend
  1744. tree
  1745. (org-export-create-backend
  1746. :transcoders
  1747. '((paragraph . (lambda (paragraph contents info) contents))
  1748. (section . (lambda (section contents info) contents))))
  1749. info)))))
  1750. ;;; Footnotes
  1751. (ert-deftest test-org-export/footnote-first-reference-p ()
  1752. "Test `org-export-footnote-first-reference-p' specifications."
  1753. (should
  1754. (equal
  1755. '(t nil)
  1756. (org-test-with-temp-text "Text[fn:1][fn:1]\n\n[fn:1] Definition"
  1757. (let (result)
  1758. (org-export-as
  1759. (org-export-create-backend
  1760. :transcoders
  1761. `(,(cons 'footnote-reference
  1762. (lambda (f c i)
  1763. (push (org-export-footnote-first-reference-p f i)
  1764. result)
  1765. ""))
  1766. (section . (lambda (s c i) c))
  1767. (paragraph . (lambda (p c i) c))))
  1768. nil nil nil '(:with-footnotes t))
  1769. (nreverse result)))))
  1770. ;; Limit check to DATA, when non-nil.
  1771. (should
  1772. (equal
  1773. '(nil t)
  1774. (org-test-with-parsed-data "Text[fn:1]\n* H\nText[fn:1]\n\n[fn:1] D1"
  1775. (let (result)
  1776. (org-element-map tree 'footnote-reference
  1777. (lambda (ref)
  1778. (push
  1779. (org-export-footnote-first-reference-p
  1780. ref info (org-element-map tree 'headline #'identity info t))
  1781. result))
  1782. info)
  1783. (nreverse result)))))
  1784. (should
  1785. (equal
  1786. '(t nil)
  1787. (org-test-with-parsed-data "Text[fn:1]\n* H\nText[fn:1]\n\n[fn:1] D1"
  1788. (let (result)
  1789. (org-element-map tree 'footnote-reference
  1790. (lambda (ref)
  1791. (push (org-export-footnote-first-reference-p ref info) result))
  1792. info)
  1793. (nreverse result)))))
  1794. ;; If optional argument BODY-FIRST is non-nil, first find footnote
  1795. ;; in the main body of the document. Otherwise, enter footnote
  1796. ;; definitions when they are encountered.
  1797. (should
  1798. (equal
  1799. '(t nil)
  1800. (org-test-with-temp-text
  1801. ":BODY:\nText[fn:1][fn:2]\n:END:\n\n[fn:1] Definition[fn:2]\n\n[fn:2] Inner"
  1802. (let (result)
  1803. (org-export-as
  1804. (org-export-create-backend
  1805. :transcoders
  1806. `(,(cons 'footnote-reference
  1807. (lambda (f c i)
  1808. (when (org-element-lineage f '(drawer))
  1809. (push (org-export-footnote-first-reference-p f i nil)
  1810. result))
  1811. ""))
  1812. (drawer . (lambda (d c i) c))
  1813. (footnote-definition . (lambda (d c i) c))
  1814. (section . (lambda (s c i) c))
  1815. (paragraph . (lambda (p c i) c))))
  1816. nil nil nil '(:with-footnotes t))
  1817. (nreverse result)))))
  1818. (should
  1819. (equal
  1820. '(t t)
  1821. (org-test-with-temp-text
  1822. ":BODY:\nText[fn:1][fn:2]\n:END:\n\n[fn:1] Definition[fn:2]\n\n[fn:2] Inner"
  1823. (let (result)
  1824. (org-export-as
  1825. (org-export-create-backend
  1826. :transcoders
  1827. `(,(cons 'footnote-reference
  1828. (lambda (f c i)
  1829. (when (org-element-lineage f '(drawer))
  1830. (push (org-export-footnote-first-reference-p f i nil t)
  1831. result))
  1832. ""))
  1833. (drawer . (lambda (d c i) c))
  1834. (footnote-definition . (lambda (d c i) c))
  1835. (section . (lambda (s c i) c))
  1836. (paragraph . (lambda (p c i) c))))
  1837. nil nil nil '(:with-footnotes t))
  1838. (nreverse result))))))
  1839. (ert-deftest test-org-export/get-footnote-number ()
  1840. "Test `org-export-get-footnote-number' specifications."
  1841. (should
  1842. (equal '(1 2 1)
  1843. (org-test-with-parsed-data
  1844. "Text[fn:1][fn:2][fn:1]\n\n[fn:1] Def\n[fn:2] Def"
  1845. (org-element-map tree 'footnote-reference
  1846. (lambda (ref) (org-export-get-footnote-number ref info))
  1847. info))))
  1848. ;; Anonymous footnotes all get a new number.
  1849. (should
  1850. (equal '(1 2)
  1851. (org-test-with-parsed-data
  1852. "Text[fn::anon1][fn::anon2]"
  1853. (org-element-map tree 'footnote-reference
  1854. (lambda (ref) (org-export-get-footnote-number ref info))
  1855. info))))
  1856. ;; Test nested footnotes order.
  1857. (should
  1858. (equal
  1859. '((1 . "1") (2 . "2") (3 . "3") (3 . "3") (4))
  1860. (org-test-with-parsed-data
  1861. "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
  1862. (org-element-map tree 'footnote-reference
  1863. (lambda (ref)
  1864. (cons (org-export-get-footnote-number ref info)
  1865. (org-element-property :label ref)))
  1866. info))))
  1867. ;; Limit number to provided DATA, when non-nil.
  1868. (should
  1869. (equal
  1870. '(1)
  1871. (org-test-with-parsed-data
  1872. "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
  1873. (org-element-map tree 'footnote-reference
  1874. (lambda (ref)
  1875. (org-export-get-footnote-number
  1876. ref info (org-element-map tree 'headline #'identity info t)))
  1877. info))))
  1878. (should
  1879. (equal
  1880. '(1 2)
  1881. (org-test-with-parsed-data
  1882. "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2]"
  1883. (org-element-map tree 'footnote-reference
  1884. (lambda (ref) (org-export-get-footnote-number ref info))
  1885. info))))
  1886. ;; With a non-nil BODY-FIRST optional argument, first check body,
  1887. ;; then footnote definitions.
  1888. (should
  1889. (equal
  1890. '(("1" . 1) ("2" . 2) ("3" . 3) ("3" . 3))
  1891. (org-test-with-parsed-data
  1892. "Text[fn:1][fn:2][fn:3]\n\n[fn:1] Def[fn:3]\n[fn:2] Def\n[fn:3] Def"
  1893. (org-element-map tree 'footnote-reference
  1894. (lambda (ref)
  1895. (cons (org-element-property :label ref)
  1896. (org-export-get-footnote-number ref info nil t)))
  1897. info))))
  1898. (should
  1899. (equal
  1900. '(("1" . 1) ("2" . 3) ("3" . 2) ("3" . 2))
  1901. (org-test-with-parsed-data
  1902. "Text[fn:1][fn:2][fn:3]\n\n[fn:1] Def[fn:3]\n[fn:2] Def\n[fn:3] Def"
  1903. (org-element-map tree 'footnote-reference
  1904. (lambda (ref)
  1905. (cons (org-element-property :label ref)
  1906. (org-export-get-footnote-number ref info nil)))
  1907. info)))))
  1908. (ert-deftest test-org-export/get-footnote-definition ()
  1909. "Test `org-export-get-footnote-definition' specifications."
  1910. ;; Standard test.
  1911. (should
  1912. (equal "A\n"
  1913. (org-element-interpret-data
  1914. (org-test-with-parsed-data "Text[fn:1]\n\n[fn:1] A"
  1915. (org-export-get-footnote-definition
  1916. (org-element-map tree 'footnote-reference #'identity nil t)
  1917. info)))))
  1918. ;; Raise an error if no definition is found.
  1919. (should-error
  1920. (org-test-with-parsed-data "Text[fn:1]"
  1921. (org-export-get-footnote-definition
  1922. (org-element-map tree 'footnote-reference #'identity nil t)
  1923. info)))
  1924. ;; Find inline definitions.
  1925. (should
  1926. (equal "A"
  1927. (org-element-interpret-data
  1928. (org-test-with-parsed-data "Text[fn:1:A]"
  1929. (org-export-get-footnote-definition
  1930. (org-element-map tree 'footnote-reference #'identity nil t)
  1931. info)))))
  1932. ;; Find anonymous definitions.
  1933. (should
  1934. (equal "A"
  1935. (org-element-interpret-data
  1936. (org-test-with-parsed-data "Text[fn::A]"
  1937. (org-export-get-footnote-definition
  1938. (org-element-map tree 'footnote-reference #'identity nil t)
  1939. info)))))
  1940. ;; Find empty definitions.
  1941. (should
  1942. (equal ""
  1943. (org-element-interpret-data
  1944. (org-test-with-parsed-data "Text[fn:1]\n\n[fn:1]"
  1945. (org-export-get-footnote-definition
  1946. (org-element-map tree 'footnote-reference #'identity nil t)
  1947. info)))))
  1948. (should
  1949. (equal ""
  1950. (org-element-interpret-data
  1951. (org-test-with-parsed-data "Text[fn:1:]"
  1952. (org-export-get-footnote-definition
  1953. (org-element-map tree 'footnote-reference #'identity nil t)
  1954. info)))))
  1955. (should
  1956. (equal ""
  1957. (org-element-interpret-data
  1958. (org-test-with-parsed-data "Text[fn::]"
  1959. (org-export-get-footnote-definition
  1960. (org-element-map tree 'footnote-reference #'identity nil t)
  1961. info))))))
  1962. (ert-deftest test-org-export/collect-footnote-definitions ()
  1963. "Test `org-export-collect-footnote-definitions' specifications."
  1964. (should
  1965. (= 4
  1966. (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
  1967. \[fn:2] B [fn:3] [fn::D].
  1968. \[fn:3] C."
  1969. (length (org-export-collect-footnote-definitions info)))))
  1970. ;; Limit number to provided DATA, when non-nil.
  1971. (should
  1972. (equal
  1973. '((1 "2"))
  1974. (org-test-with-parsed-data
  1975. "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
  1976. (mapcar #'butlast
  1977. (org-export-collect-footnote-definitions
  1978. info (org-element-map tree 'headline #'identity info t))))))
  1979. (should
  1980. (equal
  1981. '((1 "1") (2 "2"))
  1982. (org-test-with-parsed-data
  1983. "Text[fn:1]\n* H\nText[fn:2]\n\n[fn:1] D1\n[fn:2] D2"
  1984. (mapcar #'butlast (org-export-collect-footnote-definitions info)))))
  1985. ;; With optional argument BODY-FIRST, first check body, then
  1986. ;; footnote definitions.
  1987. (should
  1988. (equal '("1" "3" "2" nil)
  1989. (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
  1990. \[fn:2] B [fn:3] [fn::D].
  1991. \[fn:3] C."
  1992. (mapcar (lambda (e) (nth 1 e))
  1993. (org-export-collect-footnote-definitions info nil t)))))
  1994. (should-not
  1995. (equal '("1" "3" "2" nil)
  1996. (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
  1997. \[fn:2] B [fn:3] [fn::D].
  1998. \[fn:3] C."
  1999. (mapcar (lambda (e) (nth 1 e))
  2000. (org-export-collect-footnote-definitions info))))))
  2001. (ert-deftest test-org-export/footnotes ()
  2002. "Miscellaneous tests on footnotes."
  2003. (let ((org-footnote-section nil)
  2004. (org-export-with-footnotes t))
  2005. ;; Read every type of footnote.
  2006. (should
  2007. (equal
  2008. '((1 . "A\n") (2 . "C") (3 . "D"))
  2009. (org-test-with-parsed-data
  2010. "Text[fn:1] [fn:label:C] [fn::D]\n\n[fn:1] A\n"
  2011. (org-element-map tree 'footnote-reference
  2012. (lambda (ref)
  2013. (let ((def (org-export-get-footnote-definition ref info)))
  2014. (cons (org-export-get-footnote-number ref info)
  2015. (if (eq (org-element-property :type ref) 'inline) (car def)
  2016. (car (org-element-contents
  2017. (car (org-element-contents def))))))))
  2018. info))))
  2019. ;; Export nested footnote in invisible definitions.
  2020. (should
  2021. (= 2
  2022. (org-test-with-temp-text "Text[fn:1]\n\n[fn:1] B [fn:2]\n\n[fn:2] C."
  2023. (narrow-to-region (point) (line-end-position))
  2024. (catch 'exit
  2025. (org-export-as
  2026. (org-export-create-backend
  2027. :transcoders
  2028. '((section
  2029. .
  2030. (lambda (s c i)
  2031. (throw 'exit (length
  2032. (org-export-collect-footnote-definitions
  2033. i))))))))))))
  2034. ;; Export footnotes defined outside parsing scope.
  2035. (should
  2036. (string-match
  2037. "Out of scope"
  2038. (org-test-with-temp-text "[fn:1] Out of scope
  2039. * Title
  2040. <point>Paragraph[fn:1]"
  2041. (org-export-as (org-test-default-backend) 'subtree))))
  2042. (should
  2043. (string-match
  2044. "Out of scope"
  2045. (org-test-with-temp-text "[fn:1] Out of scope
  2046. * Title
  2047. <point>Paragraph[fn:1]"
  2048. (narrow-to-region (point) (point-max))
  2049. (org-export-as (org-test-default-backend)))))
  2050. ;; Export nested footnotes defined outside parsing scope.
  2051. (should
  2052. (string-match
  2053. "Very out of scope"
  2054. (org-test-with-temp-text "
  2055. \[fn:1] Out of scope[fn:2]
  2056. \[fn:2] Very out of scope
  2057. * Title
  2058. <point>Paragraph[fn:1]"
  2059. (org-export-as (org-test-default-backend) 'subtree))))
  2060. (should
  2061. (string-match
  2062. "Very out of scope"
  2063. (org-test-with-temp-text "
  2064. \[fn:1] Out of scope[fn:2]
  2065. \[fn:2] Very out of scope
  2066. * Title
  2067. <point>Paragraph[fn:1]"
  2068. (narrow-to-region (point) (point-max))
  2069. (org-export-as (org-test-default-backend)))))
  2070. (should
  2071. (string-match
  2072. "D2"
  2073. (org-test-with-temp-text "
  2074. \[fn:1] Out of scope[fn:2:D2]
  2075. * Title
  2076. <point>Paragraph[fn:1]"
  2077. (narrow-to-region (point) (point-max))
  2078. (org-export-as (org-test-default-backend)))))
  2079. ;; Export footnotes in pruned parts of tree.
  2080. (should
  2081. (string-match
  2082. "Definition"
  2083. (let ((org-export-exclude-tags '("noexport")))
  2084. (org-test-with-temp-text
  2085. "* H\nText[fn:1]\n* H2 :noexport:\n[fn:1] Definition"
  2086. (org-export-as (org-test-default-backend))))))
  2087. (should
  2088. (string-match
  2089. "Definition"
  2090. (let ((org-export-select-tags '("export")))
  2091. (org-test-with-temp-text
  2092. "* H :export:\nText[fn:1]\n* H2\n[fn:1] Definition"
  2093. (org-export-as (org-test-default-backend))))))
  2094. ;; Export nested footnotes in pruned parts of tree.
  2095. (should
  2096. (string-match
  2097. "D2"
  2098. (let ((org-export-exclude-tags '("noexport")))
  2099. (org-test-with-temp-text
  2100. "* H\nText[fn:1]\n* H2 :noexport:\n[fn:1] D1[fn:2]\n\n[fn:2] D2"
  2101. (org-export-as (org-test-default-backend))))))
  2102. (should
  2103. (string-match
  2104. "D2"
  2105. (let ((org-export-select-tags '("export")))
  2106. (org-test-with-temp-text
  2107. "* H :export:\nText[fn:1]\n* H2\n[fn:1] D1[fn:2]\n\n[fn:2] D2"
  2108. (org-export-as (org-test-default-backend))))))
  2109. ;; Handle uninterpreted data in pruned footnote definitions.
  2110. (should-not
  2111. (string-match
  2112. "|"
  2113. (let ((org-export-with-tables nil))
  2114. (org-test-with-temp-text
  2115. "* H\nText[fn:1]\n* H2 :noexport:\n[fn:1]\n| a |"
  2116. (org-export-as (org-test-default-backend))))))
  2117. ;; Footnotes without a definition should throw an error.
  2118. (should-error
  2119. (org-test-with-parsed-data "Text[fn:1]"
  2120. (org-export-get-footnote-definition
  2121. (org-element-map tree 'footnote-reference #'identity info t) info)))
  2122. ;; Footnote section should be ignored in TOC and in headlines
  2123. ;; numbering.
  2124. (should
  2125. (= 1 (let ((org-footnote-section "Footnotes"))
  2126. (length (org-test-with-parsed-data "* H1\n* Footnotes\n"
  2127. (org-export-collect-headlines info))))))
  2128. (should
  2129. (equal '(2)
  2130. (let ((org-footnote-section "Footnotes"))
  2131. (org-test-with-parsed-data "* H1\n* Footnotes\n* H2"
  2132. (org-element-map tree 'headline
  2133. (lambda (hl)
  2134. (when (equal (org-element-property :raw-value hl) "H2")
  2135. (org-export-get-headline-number hl info)))
  2136. info t)))))))
  2137. ;;; Headlines and Inlinetasks
  2138. (ert-deftest test-org-export/get-relative-level ()
  2139. "Test `org-export-get-relative-level' specifications."
  2140. ;; Standard test.
  2141. (should
  2142. (equal '(1 2)
  2143. (let ((org-odd-levels-only nil))
  2144. (org-test-with-parsed-data "* Headline 1\n** Headline 2"
  2145. (org-element-map tree 'headline
  2146. (lambda (h) (org-export-get-relative-level h info))
  2147. info)))))
  2148. ;; Missing levels
  2149. (should
  2150. (equal '(1 3)
  2151. (let ((org-odd-levels-only nil))
  2152. (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
  2153. (org-element-map tree 'headline
  2154. (lambda (h) (org-export-get-relative-level h info))
  2155. info))))))
  2156. (ert-deftest test-org-export/low-level-p ()
  2157. "Test `org-export-low-level-p' specifications."
  2158. (should
  2159. (equal
  2160. '(no yes)
  2161. (let ((org-odd-levels-only nil))
  2162. (org-test-with-parsed-data "* Headline 1\n** Headline 2"
  2163. (org-element-map tree 'headline
  2164. (lambda (h) (if (org-export-low-level-p h info) 'yes 'no))
  2165. (plist-put info :headline-levels 1)))))))
  2166. (ert-deftest test-org-export/get-headline-number ()
  2167. "Test `org-export-get-headline-number' specifications."
  2168. ;; Standard test.
  2169. (should
  2170. (equal
  2171. '((1) (1 1))
  2172. (let ((org-odd-levels-only nil))
  2173. (org-test-with-parsed-data "* Headline 1\n** Headline 2"
  2174. (org-element-map tree 'headline
  2175. (lambda (h) (org-export-get-headline-number h info))
  2176. info)))))
  2177. ;; Missing levels are replaced with 0.
  2178. (should
  2179. (equal
  2180. '((1) (1 0 1))
  2181. (let ((org-odd-levels-only nil))
  2182. (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
  2183. (org-element-map tree 'headline
  2184. (lambda (h) (org-export-get-headline-number h info))
  2185. info))))))
  2186. (ert-deftest test-org-export/numbered-headline-p ()
  2187. "Test `org-export-numbered-headline-p' specifications."
  2188. ;; If `:section-numbers' is nil, never number headlines.
  2189. (should-not
  2190. (org-test-with-parsed-data "* Headline"
  2191. (org-element-map tree 'headline
  2192. (lambda (h) (org-export-numbered-headline-p h info))
  2193. (plist-put info :section-numbers nil))))
  2194. ;; If `:section-numbers' is a number, only number headlines with
  2195. ;; a level greater that it.
  2196. (should
  2197. (equal
  2198. '(yes no)
  2199. (org-test-with-parsed-data "* Headline 1\n** Headline 2"
  2200. (org-element-map tree 'headline
  2201. (lambda (h) (if (org-export-numbered-headline-p h info) 'yes 'no))
  2202. (plist-put info :section-numbers 1)))))
  2203. ;; Otherwise, headlines are always numbered.
  2204. (should
  2205. (org-test-with-parsed-data "* Headline"
  2206. (org-element-map tree 'headline
  2207. (lambda (h) (org-export-numbered-headline-p h info))
  2208. (plist-put info :section-numbers t))))
  2209. ;; With #+OPTIONS: num:nil all headlines are unnumbered.
  2210. (should-not
  2211. (org-test-with-parsed-data "* H\n#+OPTIONS: num:nil"
  2212. (org-export-numbered-headline-p
  2213. (org-element-map tree 'headline 'identity info t)
  2214. info)))
  2215. ;; Headlines with a non-nil UNNUMBERED property are not numbered.
  2216. (should-not
  2217. (org-test-with-parsed-data "* H\n:PROPERTIES:\n:UNNUMBERED: t\n:END:"
  2218. (org-export-numbered-headline-p
  2219. (org-element-map tree 'headline #'identity info t)
  2220. info)))
  2221. ;; UNNUMBERED ignores inheritance. Any non-nil value among
  2222. ;; ancestors disables numbering.
  2223. (should
  2224. (org-test-with-parsed-data
  2225. "* H
  2226. :PROPERTIES:
  2227. :UNNUMBERED: t
  2228. :END:
  2229. ** H2
  2230. :PROPERTIES:
  2231. :UNNUMBERED: nil
  2232. :END:
  2233. *** H3"
  2234. (cl-every
  2235. (lambda (h) (not (org-export-numbered-headline-p h info)))
  2236. (org-element-map tree 'headline #'identity info)))))
  2237. (ert-deftest test-org-export/number-to-roman ()
  2238. "Test `org-export-number-to-roman' specifications."
  2239. ;; If number is negative, return it as a string.
  2240. (should (equal (org-export-number-to-roman -1) "-1"))
  2241. ;; Otherwise, return it as a roman number.
  2242. (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
  2243. (ert-deftest test-org-export/get-optional-title ()
  2244. "Test `org-export-get-alt-title' specifications."
  2245. ;; If ALT_TITLE property is defined, use it.
  2246. (should
  2247. (equal '("opt")
  2248. (org-test-with-parsed-data
  2249. "* Headline\n:PROPERTIES:\n:ALT_TITLE: opt\n:END:"
  2250. (org-export-get-alt-title
  2251. (org-element-map tree 'headline 'identity info t)
  2252. info))))
  2253. ;; Otherwise, fall-back to regular title.
  2254. (should
  2255. (equal '("Headline")
  2256. (org-test-with-parsed-data "* Headline"
  2257. (org-export-get-alt-title
  2258. (org-element-map tree 'headline 'identity info t)
  2259. info)))))
  2260. (ert-deftest test-org-export/get-tags ()
  2261. "Test `org-export-get-tags' specifications."
  2262. ;; Standard test: tags which are not a select tag, an exclude tag,
  2263. ;; or specified as optional argument shouldn't be ignored.
  2264. (should
  2265. (org-test-with-parsed-data "* Headline :tag:"
  2266. (org-export-get-tags (org-element-map tree 'headline 'identity info t)
  2267. info)))
  2268. ;; Tags provided in the optional argument are ignored.
  2269. (should-not
  2270. (org-test-with-parsed-data "* Headline :ignore:"
  2271. (org-export-get-tags (org-element-map tree 'headline 'identity info t)
  2272. info '("ignore"))))
  2273. ;; Allow tag inheritance.
  2274. (should
  2275. (equal
  2276. '(("tag") ("tag"))
  2277. (org-test-with-parsed-data "* Headline :tag:\n** Sub-heading"
  2278. (org-element-map tree 'headline
  2279. (lambda (hl) (org-export-get-tags hl info nil t)) info))))
  2280. ;; Tag inheritance checks FILETAGS keywords.
  2281. (should
  2282. (equal
  2283. '(("a" "b" "tag"))
  2284. (org-test-with-parsed-data "#+FILETAGS: :a:b:\n* Headline :tag:"
  2285. (org-element-map tree 'headline
  2286. (lambda (hl) (org-export-get-tags hl info nil t)) info)))))
  2287. (ert-deftest test-org-export/get-node-property ()
  2288. "Test`org-export-get-node-property' specifications."
  2289. ;; Standard test.
  2290. (should
  2291. (equal "value"
  2292. (org-test-with-parsed-data "* Headline
  2293. :PROPERTIES:
  2294. :prop: value
  2295. :END:"
  2296. (org-export-get-node-property
  2297. :PROP (org-element-map tree 'headline 'identity nil t)))))
  2298. ;; Test inheritance.
  2299. (should
  2300. (equal "value"
  2301. (org-test-with-parsed-data "* Parent
  2302. :PROPERTIES:
  2303. :prop: value
  2304. :END:
  2305. ** Headline
  2306. Paragraph"
  2307. (org-export-get-node-property
  2308. :PROP (org-element-map tree 'paragraph 'identity nil t) t))))
  2309. ;; Cannot return a value before the first headline.
  2310. (should-not
  2311. (org-test-with-parsed-data "Paragraph
  2312. * Headline
  2313. :PROPERTIES:
  2314. :prop: value
  2315. :END:"
  2316. (org-export-get-node-property
  2317. :PROP (org-element-map tree 'paragraph 'identity nil t)))))
  2318. (ert-deftest test-org-export/get-category ()
  2319. "Test `org-export-get-category' specifications."
  2320. ;; Standard test.
  2321. (should
  2322. (equal "value"
  2323. (org-test-with-parsed-data "* Headline
  2324. :PROPERTIES:
  2325. :CATEGORY: value
  2326. :END:"
  2327. (org-export-get-category
  2328. (org-element-map tree 'headline 'identity nil t) info))))
  2329. ;; Test inheritance from a parent headline.
  2330. (should
  2331. (equal '("value" "value")
  2332. (org-test-with-parsed-data "* Headline1
  2333. :PROPERTIES:
  2334. :CATEGORY: value
  2335. :END:
  2336. ** Headline2"
  2337. (org-element-map tree 'headline
  2338. (lambda (hl) (org-export-get-category hl info)) info))))
  2339. ;; Test inheritance from #+CATEGORY keyword
  2340. (should
  2341. (equal "value"
  2342. (org-test-with-parsed-data "#+CATEGORY: value
  2343. * Headline"
  2344. (org-export-get-category
  2345. (org-element-map tree 'headline 'identity nil t) info))))
  2346. ;; Test inheritance from file name.
  2347. (should
  2348. (equal "test"
  2349. (org-test-with-parsed-data "* Headline"
  2350. (let ((info (plist-put info :input-file "~/test.org")))
  2351. (org-export-get-category
  2352. (org-element-map tree 'headline 'identity nil t) info)))))
  2353. ;; Fall-back value.
  2354. (should
  2355. (equal "???"
  2356. (org-test-with-parsed-data "* Headline"
  2357. (org-export-get-category
  2358. (org-element-map tree 'headline 'identity nil t) info)))))
  2359. (ert-deftest test-org-export/first-sibling-p ()
  2360. "Test `org-export-first-sibling-p' specifications."
  2361. ;; Standard test.
  2362. (should
  2363. (equal
  2364. '(yes yes no)
  2365. (org-test-with-parsed-data "* H\n** H 2\n** H 3"
  2366. (org-element-map tree 'headline
  2367. (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
  2368. info))))
  2369. (should
  2370. (equal '(yes no)
  2371. (org-test-with-parsed-data "- item\n\n para"
  2372. (org-element-map tree 'paragraph
  2373. (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
  2374. info))))
  2375. ;; Ignore sections for headlines.
  2376. (should
  2377. (equal '(yes yes)
  2378. (org-test-with-parsed-data "* H\nSection\n** H 2"
  2379. (org-element-map tree 'headline
  2380. (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
  2381. info))))
  2382. ;; Ignore headlines not exported.
  2383. (should
  2384. (equal
  2385. '(yes)
  2386. (let ((org-export-exclude-tags '("ignore")))
  2387. (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
  2388. (org-element-map tree 'headline
  2389. (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
  2390. info))))))
  2391. (ert-deftest test-org-export/last-sibling-p ()
  2392. "Test `org-export-last-sibling-p' specifications."
  2393. ;; Standard test.
  2394. (should
  2395. (equal
  2396. '(yes no yes)
  2397. (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
  2398. (org-element-map tree 'headline
  2399. (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
  2400. info))))
  2401. (should
  2402. (equal '(no yes)
  2403. (org-test-with-parsed-data "- item\n\n para"
  2404. (org-element-map tree 'paragraph
  2405. (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
  2406. info))))
  2407. ;; Ignore headlines not exported.
  2408. (should
  2409. (equal
  2410. '(yes)
  2411. (let ((org-export-exclude-tags '("ignore")))
  2412. (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
  2413. (org-element-map tree 'headline
  2414. (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
  2415. info))))))
  2416. (ert-deftest test-org-export/handle-inlinetasks ()
  2417. "Test inlinetask export."
  2418. ;; Inlinetask with an exclude tag.
  2419. (when (featurep 'org-inlinetask)
  2420. (should
  2421. (equal
  2422. ""
  2423. (let ((org-inlinetask-min-level 3)
  2424. org-export-filter-body-functions
  2425. org-export-filter-final-output-functions)
  2426. (org-test-with-temp-text "*** Inlinetask :noexp:\nContents\n*** end"
  2427. (org-export-as (org-test-default-backend)
  2428. nil nil nil '(:exclude-tags ("noexp")))))))
  2429. ;; Inlinetask with an include tag.
  2430. (should
  2431. (equal
  2432. "* H2\n*** Inline :exp:\n"
  2433. (let ((org-inlinetask-min-level 3)
  2434. (org-tags-column 0))
  2435. (org-test-with-temp-text "* H1\n* H2\n*** Inline :exp:"
  2436. (org-export-as (org-test-default-backend)
  2437. nil nil nil '(:select-tags ("exp")))))))
  2438. ;; Ignore inlinetask with a TODO keyword and tasks excluded.
  2439. (should
  2440. (equal ""
  2441. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  2442. (org-inlinetask-min-level 3)
  2443. org-export-filter-body-functions
  2444. org-export-filter-final-output-functions)
  2445. (org-test-with-temp-text "*** TODO Inline"
  2446. (org-export-as (org-test-default-backend)
  2447. nil nil nil '(:with-tasks nil))))))))
  2448. ;;; Keywords
  2449. (ert-deftest test-org-export/get-date ()
  2450. "Test `org-export-get-date' specifications."
  2451. ;; Return a properly formatted string when
  2452. ;; `org-export-date-timestamp-format' is non-nil and DATE keyword
  2453. ;; consists in a single timestamp.
  2454. (should
  2455. (equal "29 03 2012"
  2456. (let ((org-export-date-timestamp-format "%d %m %Y"))
  2457. (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
  2458. (org-export-get-date info)))))
  2459. ;; Return a secondary string otherwise.
  2460. (should-not
  2461. (stringp
  2462. (let ((org-export-date-timestamp-format nil))
  2463. (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
  2464. (org-export-get-date info)))))
  2465. (should
  2466. (equal '("Date")
  2467. (org-test-with-parsed-data "#+DATE: Date"
  2468. (org-export-get-date info))))
  2469. ;; Optional argument has precedence over
  2470. ;; `org-export-date-timestamp-format'.
  2471. (should
  2472. (equal "29 03"
  2473. (let ((org-export-date-timestamp-format "%d %m %Y"))
  2474. (org-test-with-parsed-data "#+DATE: <2012-03-29 Thu>"
  2475. (org-export-get-date info "%d %m"))))))
  2476. ;;; Links
  2477. (ert-deftest test-org-export/custom-protocol-maybe ()
  2478. "Test `org-export-custom-protocol-maybe' specifications."
  2479. (should
  2480. (string-match
  2481. "success"
  2482. (progn
  2483. (org-link-set-parameters "foo" :export (lambda (p d f) "success"))
  2484. (org-export-string-as
  2485. "[[foo:path]]"
  2486. (org-export-create-backend
  2487. :name 'test
  2488. :transcoders
  2489. '((section . (lambda (s c i) c))
  2490. (paragraph . (lambda (p c i) c))
  2491. (link . (lambda (l c i)
  2492. (or (org-export-custom-protocol-maybe l c 'test)
  2493. "failure")))))))))
  2494. (should-not
  2495. (string-match
  2496. "success"
  2497. (progn
  2498. (org-link-set-parameters
  2499. "foo" :export (lambda (p d f) (and (eq f 'test) "success")))
  2500. (org-export-string-as
  2501. "[[foo:path]]"
  2502. (org-export-create-backend
  2503. :name 'no-test
  2504. :transcoders
  2505. '((section . (lambda (s c i) c))
  2506. (paragraph . (lambda (p c i) c))
  2507. (link . (lambda (l c i)
  2508. (or (org-export-custom-protocol-maybe l c 'no-test)
  2509. "failure")))))))))
  2510. ;; Ignore anonymous back-ends.
  2511. (should-not
  2512. (string-match
  2513. "success"
  2514. (progn
  2515. (org-link-set-parameters
  2516. "foo" :export (lambda (p d f) (and (eq f 'test) "success")))
  2517. (org-export-string-as
  2518. "[[foo:path]]"
  2519. (org-export-create-backend
  2520. :transcoders
  2521. '((section . (lambda (s c i) c))
  2522. (paragraph . (lambda (p c i) c))
  2523. (link . (lambda (l c i)
  2524. (or (org-export-custom-protocol-maybe l c nil)
  2525. "failure"))))))))))
  2526. (ert-deftest test-org-export/get-coderef-format ()
  2527. "Test `org-export-get-coderef-format' specifications."
  2528. ;; A link without description returns "%s"
  2529. (should (equal (org-export-get-coderef-format "(ref:line)" nil)
  2530. "%s"))
  2531. ;; Return "%s" when path is matched within description.
  2532. (should (equal (org-export-get-coderef-format "path" "desc (path)")
  2533. "desc %s"))
  2534. ;; Otherwise return description.
  2535. (should (equal (org-export-get-coderef-format "path" "desc")
  2536. "desc")))
  2537. (ert-deftest test-org-export/inline-image-p ()
  2538. "Test `org-export-inline-image-p' specifications."
  2539. (should
  2540. (org-export-inline-image-p
  2541. (org-test-with-temp-text "[[#id]]"
  2542. (org-element-map (org-element-parse-buffer) 'link 'identity nil t))
  2543. '(("custom-id" . "id")))))
  2544. (ert-deftest test-org-export/fuzzy-link ()
  2545. "Test fuzzy links specifications."
  2546. ;; Link to an headline should return headline's number.
  2547. (should
  2548. ;; Note: Headline's number is in fact a list of numbers.
  2549. (equal '(2)
  2550. (org-test-with-parsed-data
  2551. "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
  2552. (org-element-map tree 'link
  2553. (lambda (link)
  2554. (org-export-get-ordinal
  2555. (org-export-resolve-fuzzy-link link info) info)) info t))))
  2556. ;; Link to a target in an item should return item's number.
  2557. (should
  2558. ;; Note: Item's number is in fact a list of numbers.
  2559. (equal '(1 2)
  2560. (org-test-with-parsed-data
  2561. "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
  2562. (org-element-map tree 'link
  2563. (lambda (link)
  2564. (org-export-get-ordinal
  2565. (org-export-resolve-fuzzy-link link info) info)) info t))))
  2566. ;; Link to a target in a footnote should return footnote's number.
  2567. (should
  2568. (equal '(2 3)
  2569. (org-test-with-parsed-data "
  2570. Paragraph[fn:1][fn:2][fn:lbl3:C<<target>>][[test]][[target]]
  2571. \[fn:1] A
  2572. \[fn:2] <<test>>B"
  2573. (org-element-map tree 'link
  2574. (lambda (link)
  2575. (org-export-get-ordinal
  2576. (org-export-resolve-fuzzy-link link info) info)) info))))
  2577. ;; Link to a named element should return sequence number of that
  2578. ;; element.
  2579. (should
  2580. (= 2
  2581. (org-test-with-parsed-data
  2582. "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
  2583. (org-element-map tree 'link
  2584. (lambda (link)
  2585. (org-export-get-ordinal
  2586. (org-export-resolve-fuzzy-link link info) info)) info t))))
  2587. ;; Link to a target not within an item, a table, a footnote
  2588. ;; reference or definition should return section number.
  2589. (should
  2590. (equal '(2)
  2591. (org-test-with-parsed-data
  2592. "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
  2593. (org-element-map tree 'link
  2594. (lambda (link)
  2595. (org-export-get-ordinal
  2596. (org-export-resolve-fuzzy-link link info) info)) info t))))
  2597. ;; Space are not significant when matching a fuzzy link.
  2598. (should
  2599. (org-test-with-parsed-data "* Head 1\n[[Head\n 1]]"
  2600. (org-element-map tree 'link
  2601. (lambda (link) (org-export-resolve-fuzzy-link link info))
  2602. info t)))
  2603. ;; Statistics cookies are ignored for headline match.
  2604. (should
  2605. (org-test-with-parsed-data "* Head [0/0]\n[[Head]]"
  2606. (org-element-map tree 'link
  2607. (lambda (link) (org-export-resolve-fuzzy-link link info))
  2608. info t)))
  2609. (should
  2610. (org-test-with-parsed-data "* Head [100%]\n[[Head]]"
  2611. (org-element-map tree 'link
  2612. (lambda (link) (org-export-resolve-fuzzy-link link info))
  2613. info t))))
  2614. (defun test-org-gen-loc-list(text type)
  2615. (org-test-with-parsed-data text
  2616. (org-element-map tree type
  2617. (lambda (el) (or (org-export-get-loc el info) 'no-loc)))))
  2618. (ert-deftest test-org-export/get-loc ()
  2619. "Test `org-export-get-loc' specifications."
  2620. (should
  2621. ;; "-n" resets line number.
  2622. (equal '(0)
  2623. (test-org-gen-loc-list "#+BEGIN_EXAMPLE -n\n Text\n#+END_EXAMPLE"
  2624. 'example-block)))
  2625. ;; The first "+n" has 0 lines before it
  2626. (should
  2627. (equal '(0)
  2628. (test-org-gen-loc-list "#+BEGIN_EXAMPLE +n\n Text\n#+END_EXAMPLE"
  2629. 'example-block)))
  2630. ;; "-n 10" resets line number but has "9 lines" before it.
  2631. (should
  2632. (equal '(9)
  2633. (test-org-gen-loc-list "#+BEGIN_EXAMPLE -n 10\n Text\n#+END_EXAMPLE"
  2634. 'example-block)))
  2635. ;; -n10 with two lines then +n 15
  2636. (should
  2637. (equal '(9 25)
  2638. (test-org-gen-loc-list "
  2639. #+BEGIN_EXAMPLE -n 10
  2640. Text_10
  2641. Second line(11)
  2642. #+END_EXAMPLE
  2643. #+BEGIN_EXAMPLE +n 15
  2644. Text line (11 + 15)
  2645. #+END_EXAMPLE"
  2646. 'example-block)))
  2647. (should
  2648. (equal '(9 19 0)
  2649. (test-org-gen-loc-list "
  2650. #+BEGIN_EXAMPLE -n 10
  2651. Text
  2652. #+END_EXAMPLE
  2653. #+BEGIN_EXAMPLE +n 10
  2654. Text
  2655. #+END_EXAMPLE
  2656. #+BEGIN_EXAMPLE -n
  2657. Text
  2658. #+END_EXAMPLE"
  2659. 'example-block)))
  2660. ;; an Example Block without -n does not add to the line count.
  2661. (should
  2662. (equal '(9 no-loc 19)
  2663. (test-org-gen-loc-list "
  2664. #+BEGIN_EXAMPLE -n 10
  2665. Text
  2666. #+END_EXAMPLE
  2667. #+BEGIN_EXAMPLE
  2668. Text
  2669. #+END_EXAMPLE
  2670. #+BEGIN_EXAMPLE +n 10
  2671. Text
  2672. #+END_EXAMPLE"
  2673. 'example-block)))
  2674. ;; "-n" resets line number.
  2675. (should
  2676. (equal
  2677. '(0)
  2678. (test-org-gen-loc-list "#+BEGIN_SRC emacs-lisp -n \n (- 1 1) \n#+END_SRC"
  2679. 'src-block)))
  2680. ;; The first "+n" has 0 lines before it.
  2681. (should
  2682. (equal '(0)
  2683. (test-org-gen-loc-list
  2684. "#+BEGIN_SRC emacs-lisp +n \n (+ 0 (- 1 1))\n#+END_SRC"
  2685. 'src-block)))
  2686. ;; "-n 10" resets line number but has "9 lines" before it.
  2687. (should
  2688. (equal '(9)
  2689. (test-org-gen-loc-list
  2690. "#+BEGIN_SRC emacs-lisp -n 10\n (- 10 1)\n#+END_SRC"
  2691. 'src-block)))
  2692. (should
  2693. (equal '(9 25)
  2694. (test-org-gen-loc-list "
  2695. #+BEGIN_SRC emacs-lisp -n 10
  2696. (- 10 1)
  2697. (+ (- 10 1) 1)
  2698. #+END_SRC
  2699. #+BEGIN_SRC emacs-lisp +n 15
  2700. (+ (- 10 1) 2 (- 15 1))
  2701. #+END_SRC"
  2702. 'src-block)))
  2703. (should
  2704. (equal '(9 19 0)
  2705. (test-org-gen-loc-list "
  2706. #+BEGIN_SRC emacs-lisp -n 10
  2707. (- 10 1)
  2708. #+END_SRC
  2709. #+BEGIN_SRC emacs-lisp +n 10
  2710. (+ (- 10 1) 1 (- 10 1))
  2711. #+END_SRC
  2712. #+BEGIN_SRC emacs-lisp -n
  2713. (- 1 1)
  2714. #+END_SRC"
  2715. 'src-block)))
  2716. ;; A SRC Block without -n does not add to the line count.
  2717. (should
  2718. (equal '(9 no-loc 19)
  2719. (test-org-gen-loc-list
  2720. "#+BEGIN_SRC emacs-lisp -n 10
  2721. (+ (-10 1) 1)
  2722. #+END_SRC
  2723. #+BEGIN_SRC emacs-lisp
  2724. (+ 2 2)
  2725. #+END_SRC
  2726. #+BEGIN_SRC emacs-lisp +n 10
  2727. (+ (- 10 1) 1 (- 10 1))
  2728. #+END_SRC"
  2729. 'src-block))))
  2730. (ert-deftest test-org-export/resolve-coderef ()
  2731. "Test `org-export-resolve-coderef' specifications."
  2732. (let ((org-coderef-label-format "(ref:%s)"))
  2733. ;; A link to a "-n -k -r" block returns line number.
  2734. (should
  2735. (= 1
  2736. (org-test-with-parsed-data
  2737. "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
  2738. (org-export-resolve-coderef "coderef" info))))
  2739. (should
  2740. (= 10
  2741. (org-test-with-parsed-data
  2742. "#+BEGIN_EXAMPLE -n 10 -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
  2743. (org-export-resolve-coderef "coderef" info))))
  2744. (should
  2745. (= 135
  2746. (org-test-with-parsed-data
  2747. "#+BEGIN_EXAMPLE -n 10 -k -r\nText \n#+END_EXAMPLE\n
  2748. #+BEGIN_EXAMPLE +n 125 -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
  2749. (org-export-resolve-coderef "coderef" info))))
  2750. (should
  2751. (= 1
  2752. (org-test-with-parsed-data
  2753. "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  2754. (org-export-resolve-coderef "coderef" info))))
  2755. (should
  2756. (= 10
  2757. (org-test-with-parsed-data
  2758. "#+BEGIN_SRC emacs-lisp -n 10 -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  2759. (org-export-resolve-coderef "coderef" info))))
  2760. (should
  2761. (= 135
  2762. (org-test-with-parsed-data
  2763. "#+BEGIN_SRC emacs-lisp -n 10 -k -r\n(+ 1 1) \n#+END_SRC\n
  2764. #+BEGIN_SRC emacs-lisp +n 125 -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  2765. (org-export-resolve-coderef "coderef" info))))
  2766. ;; A link to a "-n -r" block returns line number.
  2767. (should
  2768. (= 1
  2769. (org-test-with-parsed-data
  2770. "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
  2771. (org-export-resolve-coderef "coderef" info))))
  2772. (should
  2773. (= 10
  2774. (org-test-with-parsed-data
  2775. "#+BEGIN_EXAMPLE -n 10 -r\nText (ref:coderef)\n#+END_EXAMPLE"
  2776. (org-export-resolve-coderef "coderef" info))))
  2777. (should
  2778. (= 135
  2779. (org-test-with-parsed-data
  2780. "#+BEGIN_EXAMPLE +n 10 -r\nText \n#+END_EXAMPLE
  2781. #+BEGIN_EXAMPLE +n 125 -r\nText (ref:coderef)\n#+END_EXAMPLE"
  2782. (org-export-resolve-coderef "coderef" info))))
  2783. (should
  2784. (= 1
  2785. (org-test-with-parsed-data
  2786. "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  2787. (org-export-resolve-coderef "coderef" info))))
  2788. (should
  2789. (= 10
  2790. (org-test-with-parsed-data
  2791. "#+BEGIN_SRC emacs-lisp -n10 -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  2792. (org-export-resolve-coderef "coderef" info))))
  2793. (should
  2794. (= 135
  2795. (org-test-with-parsed-data
  2796. "#+BEGIN_SRC emacs-lisp -n10 -r\n(+ 1 1) \n#+END_SRC
  2797. #+BEGIN_SRC emacs-lisp +n125 -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  2798. (org-export-resolve-coderef "coderef" info))))
  2799. ;; A link to a "-n" block returns coderef.
  2800. (should
  2801. (equal "coderef"
  2802. (org-test-with-parsed-data
  2803. "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  2804. (org-export-resolve-coderef "coderef" info))))
  2805. (should
  2806. (equal "coderef"
  2807. (org-test-with-parsed-data
  2808. "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
  2809. (org-export-resolve-coderef "coderef" info))))
  2810. ;; A link to a "-r" block returns line number.
  2811. (should
  2812. (= 1
  2813. (org-test-with-parsed-data
  2814. "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  2815. (org-export-resolve-coderef "coderef" info))))
  2816. (should
  2817. (= 1
  2818. (org-test-with-parsed-data
  2819. "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
  2820. (org-export-resolve-coderef "coderef" info))))
  2821. ;; A link to a block without a switch returns coderef.
  2822. (should
  2823. (equal "coderef"
  2824. (org-test-with-parsed-data
  2825. "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  2826. (org-export-resolve-coderef "coderef" info))))
  2827. (org-test-with-parsed-data
  2828. "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
  2829. (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
  2830. ;; Correctly handle continued line numbers. A "+n" switch should
  2831. ;; resume numbering from previous block with numbered lines,
  2832. ;; ignoring blocks not numbering lines in the process. A "-n"
  2833. ;; switch resets count.
  2834. (should
  2835. (equal '(2 1)
  2836. (org-test-with-parsed-data "
  2837. #+BEGIN_EXAMPLE -n
  2838. Text.
  2839. #+END_EXAMPLE
  2840. #+BEGIN_SRC emacs-lisp
  2841. \(- 1 1)
  2842. #+END_SRC
  2843. #+BEGIN_SRC emacs-lisp +n -r
  2844. \(+ 1 1) (ref:addition)
  2845. #+END_SRC
  2846. #+BEGIN_EXAMPLE -n -r
  2847. Another text. (ref:text)
  2848. #+END_EXAMPLE"
  2849. (list (org-export-resolve-coderef "addition" info)
  2850. (org-export-resolve-coderef "text" info)))))
  2851. ;; Recognize coderef with user-specified syntax.
  2852. (should
  2853. (equal
  2854. "text"
  2855. (org-test-with-parsed-data
  2856. "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
  2857. (org-export-resolve-coderef "text" info))))
  2858. ;; Unresolved coderefs raise a `org-link-broken' signal.
  2859. (should
  2860. (condition-case nil
  2861. (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  2862. (org-export-resolve-coderef "unknown" info))
  2863. (org-link-broken t)))))
  2864. (ert-deftest test-org-export/resolve-fuzzy-link ()
  2865. "Test `org-export-resolve-fuzzy-link' specifications."
  2866. ;; Match target objects.
  2867. (should
  2868. (org-test-with-parsed-data "<<target>> [[target]]"
  2869. (org-export-resolve-fuzzy-link
  2870. (org-element-map tree 'link 'identity info t) info)))
  2871. ;; Match named elements.
  2872. (should
  2873. (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
  2874. (org-export-resolve-fuzzy-link
  2875. (org-element-map tree 'link 'identity info t) info)))
  2876. ;; Match exact headline's name.
  2877. (should
  2878. (org-test-with-parsed-data "* My headline\n[[My headline]]"
  2879. (org-export-resolve-fuzzy-link
  2880. (org-element-map tree 'link 'identity info t) info)))
  2881. ;; Targets objects have priority over headline titles.
  2882. (should
  2883. (eq 'target
  2884. (org-test-with-parsed-data "* target\n<<target>>[[target]]"
  2885. (org-element-type
  2886. (org-export-resolve-fuzzy-link
  2887. (org-element-map tree 'link 'identity info t) info)))))
  2888. ;; Named elements have priority over headline titles.
  2889. (should
  2890. (eq 'paragraph
  2891. (org-test-with-parsed-data
  2892. "* target\n#+NAME: target\nParagraph\n\n[[target]]"
  2893. (org-element-type
  2894. (org-export-resolve-fuzzy-link
  2895. (org-element-map tree 'link 'identity info t) info)))))
  2896. ;; If link's path starts with a "*", only match headline titles,
  2897. ;; though.
  2898. (should
  2899. (eq 'headline
  2900. (org-test-with-parsed-data
  2901. "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
  2902. (org-element-type
  2903. (org-export-resolve-fuzzy-link
  2904. (org-element-map tree 'link 'identity info t) info)))))
  2905. ;; Raise a `org-link-broken' signal if no match.
  2906. (should
  2907. (org-test-with-parsed-data "[[target]]"
  2908. (condition-case nil
  2909. (org-export-resolve-fuzzy-link
  2910. (org-element-map tree 'link #'identity info t) info)
  2911. (org-link-broken t))))
  2912. ;; Match fuzzy link even when before first headline.
  2913. (should
  2914. (eq 'headline
  2915. (org-test-with-parsed-data "[[hl]]\n* hl"
  2916. (org-element-type
  2917. (org-export-resolve-fuzzy-link
  2918. (org-element-map tree 'link 'identity info t) info)))))
  2919. ;; Handle url-encoded fuzzy links.
  2920. (should
  2921. (org-test-with-parsed-data "* A B\n[[A%20B]]"
  2922. (org-export-resolve-fuzzy-link
  2923. (org-element-map tree 'link #'identity info t) info))))
  2924. (ert-deftest test-org-export/resolve-id-link ()
  2925. "Test `org-export-resolve-id-link' specifications."
  2926. ;; Regular test for custom-id link.
  2927. (should
  2928. (equal '("Headline1")
  2929. (org-test-with-parsed-data "* Headline1
  2930. :PROPERTIES:
  2931. :CUSTOM_ID: test
  2932. :END:
  2933. * Headline 2
  2934. \[[#test]]"
  2935. (org-element-property
  2936. :title
  2937. (org-export-resolve-id-link
  2938. (org-element-map tree 'link 'identity info t) info)))))
  2939. ;; Raise a `org-link-broken' signal on failing searches.
  2940. (should
  2941. (org-test-with-parsed-data "* Headline1
  2942. :PROPERTIES:
  2943. :CUSTOM_ID: test
  2944. :END:
  2945. * Headline 2
  2946. \[[#no-match]]"
  2947. (condition-case nil
  2948. (org-export-resolve-id-link
  2949. (org-element-map tree 'link #'identity info t) info)
  2950. (org-link-broken t))))
  2951. ;; Test for internal id target.
  2952. (should
  2953. (equal '("Headline1")
  2954. (org-test-with-parsed-data "* Headline1
  2955. :PROPERTIES:
  2956. :ID: aaaa
  2957. :END:
  2958. * Headline 2
  2959. \[[id:aaaa]]"
  2960. (org-element-property
  2961. :title
  2962. (org-export-resolve-id-link
  2963. (org-element-map tree 'link 'identity info t) info)))))
  2964. ;; Test for external id target.
  2965. (should
  2966. (equal
  2967. "external-file"
  2968. (org-test-with-parsed-data "[[id:aaaa]]"
  2969. (org-export-resolve-id-link
  2970. (org-element-map tree 'link 'identity info t)
  2971. (org-combine-plists info '(:id-alist (("aaaa" . "external-file")))))))))
  2972. (ert-deftest test-org-export/resolve-radio-link ()
  2973. "Test `org-export-resolve-radio-link' specifications."
  2974. ;; Standard test.
  2975. (should
  2976. (org-test-with-temp-text "<<<radio>>> radio"
  2977. (org-update-radio-target-regexp)
  2978. (let* ((tree (org-element-parse-buffer))
  2979. (info `(:parse-tree ,tree)))
  2980. (org-export-resolve-radio-link
  2981. (org-element-map tree 'link 'identity info t)
  2982. info))))
  2983. ;; Radio targets are case-insensitive.
  2984. (should
  2985. (org-test-with-temp-text "<<<RADIO>>> radio"
  2986. (org-update-radio-target-regexp)
  2987. (let* ((tree (org-element-parse-buffer))
  2988. (info `(:parse-tree ,tree)))
  2989. (org-export-resolve-radio-link
  2990. (org-element-map tree 'link 'identity info t)
  2991. info))))
  2992. ;; Radio target with objects.
  2993. (should
  2994. (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
  2995. (org-update-radio-target-regexp)
  2996. (let* ((tree (org-element-parse-buffer))
  2997. (info `(:parse-tree ,tree)))
  2998. (org-export-resolve-radio-link
  2999. (org-element-map tree 'link 'identity info t)
  3000. info))))
  3001. ;; Radio target with objects at its beginning.
  3002. (should
  3003. (org-test-with-temp-text "<<<\\alpha radio>>> \\alpha radio"
  3004. (org-update-radio-target-regexp)
  3005. (let* ((tree (org-element-parse-buffer))
  3006. (info `(:parse-tree ,tree)))
  3007. (org-export-resolve-radio-link
  3008. (org-element-map tree 'link 'identity info t)
  3009. info))))
  3010. ;; Radio link next to an apostrophe.
  3011. (should
  3012. (org-test-with-temp-text "<<<radio>>> radio's"
  3013. (org-update-radio-target-regexp)
  3014. (let* ((tree (org-element-parse-buffer))
  3015. (info `(:parse-tree ,tree)))
  3016. (org-export-resolve-radio-link
  3017. (org-element-map tree 'link 'identity info t)
  3018. info))))
  3019. ;; Multiple radio targets.
  3020. (should
  3021. (equal '("radio1" "radio2")
  3022. (org-test-with-temp-text "<<<radio1>>> <<<radio2>>> radio1 radio2"
  3023. (org-update-radio-target-regexp)
  3024. (let* ((tree (org-element-parse-buffer))
  3025. (info `(:parse-tree ,tree)))
  3026. (org-element-map tree 'link
  3027. (lambda (link)
  3028. (org-element-property
  3029. :value (org-export-resolve-radio-link link info)))
  3030. info)))))
  3031. ;; Radio target is whitespace insensitive.
  3032. (should
  3033. (org-test-with-temp-text "<<<a radio>>> a\n radio"
  3034. (org-update-radio-target-regexp)
  3035. (let* ((tree (org-element-parse-buffer))
  3036. (info `(:parse-tree ,tree)))
  3037. (org-element-map tree 'link
  3038. (lambda (link) (org-export-resolve-radio-link link info)) info t)))))
  3039. (ert-deftest test-org-export/file-uri ()
  3040. "Test `org-export-file-uri' specifications."
  3041. ;; Preserve relative filenames.
  3042. (should (equal "relative.org" (org-export-file-uri "relative.org")))
  3043. ;; Local files start with "file:///"
  3044. (should (equal "file:///local.org" (org-export-file-uri "/local.org")))
  3045. ;; Remote files start with "file://"
  3046. (should (equal "file://myself@some.where:papers/last.pdf"
  3047. (org-export-file-uri "/myself@some.where:papers/last.pdf")))
  3048. (should (equal "file://localhost/etc/fstab"
  3049. (org-export-file-uri "//localhost/etc/fstab")))
  3050. ;; Expand filename starting with "~".
  3051. (should (equal (org-export-file-uri "~/file.org")
  3052. (concat "file://" (expand-file-name "~/file.org")))))
  3053. (ert-deftest test-org-export/get-reference ()
  3054. "Test `org-export-get-reference' specifications."
  3055. (should
  3056. (org-test-with-parsed-data "* Headline"
  3057. (org-export-get-reference (org-element-map tree 'headline #'identity nil t)
  3058. info)))
  3059. ;; For a given element always return the same reference.
  3060. (should
  3061. (org-test-with-parsed-data "* Headline"
  3062. (let ((headline (org-element-map tree 'headline #'identity nil t)))
  3063. (equal (org-export-get-reference headline info)
  3064. (org-export-get-reference headline info)))))
  3065. ;; Use search cells defined in `:crossrefs'. However, handle
  3066. ;; duplicate search cells.
  3067. (should
  3068. (equal "org0000001"
  3069. (org-test-with-parsed-data "* Headline"
  3070. (let* ((headline (org-element-map tree 'headline #'identity nil t))
  3071. (search-cell (car (org-export-search-cells headline))))
  3072. (setq info
  3073. (plist-put info :crossrefs (list (cons search-cell 1))))
  3074. (org-export-get-reference headline info)))))
  3075. (should-not
  3076. (equal '("org0000001" "org0000001")
  3077. (org-test-with-parsed-data "* H\n** H"
  3078. (org-element-map tree 'headline
  3079. (lambda (h)
  3080. (let* ((search-cell (car (org-export-search-cells h)))
  3081. (info (plist-put info :crossrefs
  3082. (list (cons search-cell 1)))))
  3083. (org-export-get-reference h info))))))))
  3084. ;;; Pseudo objects and pseudo elements
  3085. (ert-deftest test-org-export/pseudo-elements ()
  3086. "Test exporting pseudo-elements."
  3087. ;; Handle blank lines after pseudo-elements. In particular, do not
  3088. ;; replace them with white spaces.
  3089. (should
  3090. (equal "contents\n\nparagraph\n"
  3091. (let ((backend (org-export-create-backend
  3092. :transcoders
  3093. '((pseudo-element . (lambda (_p c _i) c))
  3094. (paragraph . (lambda (_p c _i) c))
  3095. (plain-text . (lambda (c _i) c)))))
  3096. (element '(pseudo-element (:post-blank 1) "contents"))
  3097. (paragraph '(paragraph nil "paragraph"))
  3098. (data '(org-data nil)))
  3099. (org-element-adopt-elements data element paragraph)
  3100. (org-export-data-with-backend data backend nil)))))
  3101. (ert-deftest test-org-export/pseudo-objects ()
  3102. "Test exporting pseudo-objects."
  3103. ;; Handle blank spaces after pseudo-objects. In particular, do not
  3104. ;; replace them with newlines.
  3105. (should
  3106. (equal "begin x end\n"
  3107. (let ((backend (org-export-create-backend
  3108. :transcoders
  3109. '((pseudo-object . (lambda (_p c _i) c))
  3110. (paragraph . (lambda (_p c _i) c))
  3111. (plain-text . (lambda (c _i) c)))))
  3112. (object '(pseudo-object (:post-blank 1) "x"))
  3113. (paragraph '(paragraph nil)))
  3114. (org-element-adopt-elements paragraph "begin " object "end")
  3115. (org-export-data-with-backend paragraph backend nil)))))
  3116. ;;; Src-block and example-block
  3117. (ert-deftest test-org-export/unravel-code ()
  3118. "Test `org-export-unravel-code' function."
  3119. ;; Code without reference.
  3120. (should
  3121. (equal '("(+ 1 1)\n")
  3122. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
  3123. (org-export-unravel-code (org-element-at-point)))))
  3124. ;; Code with reference.
  3125. (should
  3126. (equal '("(+ 1 1)\n" (1 . "test"))
  3127. (org-test-with-temp-text
  3128. "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
  3129. (let ((org-coderef-label-format "(ref:%s)"))
  3130. (org-export-unravel-code (org-element-at-point))))))
  3131. ;; Code with user-defined reference.
  3132. (should
  3133. (equal
  3134. '("(+ 1 1)\n" (1 . "test"))
  3135. (org-test-with-temp-text
  3136. "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
  3137. (let ((org-coderef-label-format "(ref:%s)"))
  3138. (org-export-unravel-code (org-element-at-point))))))
  3139. ;; Code references keys are relative to the current block.
  3140. (should
  3141. (equal '("(+ 2 2)\n(+ 3 3)\n" (2 . "one"))
  3142. (org-test-with-temp-text "
  3143. #+BEGIN_EXAMPLE -n
  3144. \(+ 1 1)
  3145. #+END_EXAMPLE
  3146. #+BEGIN_EXAMPLE +n
  3147. \(+ 2 2)
  3148. \(+ 3 3) (ref:one)
  3149. #+END_EXAMPLE"
  3150. (goto-line 5)
  3151. (let ((org-coderef-label-format "(ref:%s)"))
  3152. (org-export-unravel-code (org-element-at-point)))))))
  3153. (ert-deftest test-org-export/format-code-default ()
  3154. "Test `org-export-format-code-default' specifications."
  3155. ;; Return the empty string when code is empty.
  3156. (should
  3157. (equal ""
  3158. (org-test-with-parsed-data "#+BEGIN_SRC emacs-lisp\n\n\n#+END_SRC"
  3159. (org-export-format-code-default
  3160. (org-element-map tree 'src-block 'identity info t) info))))
  3161. ;; Number lines, two whitespace characters before the actual loc.
  3162. (should
  3163. (equal "1 a\n2 b\n"
  3164. (org-test-with-parsed-data
  3165. "#+BEGIN_SRC emacs-lisp +n\na\nb\n#+END_SRC"
  3166. (org-export-format-code-default
  3167. (org-element-map tree 'src-block 'identity info t) info))))
  3168. ;; Put references 6 whitespace characters after the widest line,
  3169. ;; wrapped within parenthesis.
  3170. (should
  3171. (equal "123 (a)\n1 (b)\n"
  3172. (let ((org-coderef-label-format "(ref:%s)"))
  3173. (org-test-with-parsed-data
  3174. "#+BEGIN_SRC emacs-lisp\n123 (ref:a)\n1 (ref:b)\n#+END_SRC"
  3175. (org-export-format-code-default
  3176. (org-element-map tree 'src-block 'identity info t) info))))))
  3177. ;;; Smart Quotes
  3178. (ert-deftest test-org-export/activate-smart-quotes ()
  3179. "Test `org-export-activate-smart-quotes' specifications."
  3180. ;; Double quotes: standard test.
  3181. (should
  3182. (equal
  3183. '("some &ldquo;quoted&rdquo; text")
  3184. (let ((org-export-default-language "en"))
  3185. (org-test-with-parsed-data "some \"quoted\" text"
  3186. (org-element-map tree 'plain-text
  3187. (lambda (s) (org-export-activate-smart-quotes s :html info))
  3188. info)))))
  3189. ;; Opening quotes: at the beginning of a paragraph.
  3190. (should
  3191. (equal
  3192. '("&ldquo;begin")
  3193. (let ((org-export-default-language "en"))
  3194. (org-test-with-parsed-data "\"begin"
  3195. (org-element-map tree 'plain-text
  3196. (lambda (s) (org-export-activate-smart-quotes s :html info))
  3197. info)))))
  3198. ;; Opening quotes: after an object.
  3199. (should
  3200. (equal
  3201. '("&ldquo;quoted&rdquo; text")
  3202. (let ((org-export-default-language "en"))
  3203. (org-test-with-parsed-data "=verb= \"quoted\" text"
  3204. (org-element-map tree 'plain-text
  3205. (lambda (s) (org-export-activate-smart-quotes s :html info))
  3206. info)))))
  3207. ;; Closing quotes: at the end of a paragraph.
  3208. (should
  3209. (equal
  3210. '("Quoted &ldquo;text&rdquo;")
  3211. (let ((org-export-default-language "en"))
  3212. (org-test-with-parsed-data "Quoted \"text\""
  3213. (org-element-map tree 'plain-text
  3214. (lambda (s) (org-export-activate-smart-quotes s :html info))
  3215. info)))))
  3216. ;; Inner quotes: standard test.
  3217. (should
  3218. (equal '("« outer « inner » outer »")
  3219. (let ((org-export-default-language "fr"))
  3220. (org-test-with-parsed-data "\"outer 'inner' outer\""
  3221. (org-element-map tree 'plain-text
  3222. (lambda (s) (org-export-activate-smart-quotes s :utf-8 info))
  3223. info)))))
  3224. ;; Inner quotes: close to special symbols.
  3225. (should
  3226. (equal '("« outer (« inner ») outer »")
  3227. (let ((org-export-default-language "fr"))
  3228. (org-test-with-parsed-data "\"outer ('inner') outer\""
  3229. (org-element-map tree 'plain-text
  3230. (lambda (s) (org-export-activate-smart-quotes s :utf-8 info))
  3231. info)))))
  3232. (should
  3233. (equal '("« « inner » »")
  3234. (let ((org-export-default-language "fr"))
  3235. (org-test-with-parsed-data "\"'inner'\""
  3236. (org-element-map tree 'plain-text
  3237. (lambda (s) (org-export-activate-smart-quotes s :utf-8 info))
  3238. info)))))
  3239. ;; Apostrophe: standard test.
  3240. (should
  3241. (equal '("It « shouldn’t » fail")
  3242. (let ((org-export-default-language "fr"))
  3243. (org-test-with-parsed-data "It \"shouldn't\" fail"
  3244. (org-element-map tree 'plain-text
  3245. (lambda (s) (org-export-activate-smart-quotes s :utf-8 info))
  3246. info)))))
  3247. (should
  3248. (equal '("It shouldn’t fail")
  3249. (let ((org-export-default-language "fr"))
  3250. (org-test-with-parsed-data "It shouldn't fail"
  3251. (org-element-map tree 'plain-text
  3252. (lambda (s) (org-export-activate-smart-quotes s :utf-8 info))
  3253. info)))))
  3254. ;; Apostrophe: before an object.
  3255. (should
  3256. (equal
  3257. '("« a’" " »")
  3258. (let ((org-export-default-language "fr"))
  3259. (org-test-with-parsed-data "\"a'=b=\""
  3260. (org-element-map tree 'plain-text
  3261. (lambda (s) (org-export-activate-smart-quotes s :utf-8 info))
  3262. info)))))
  3263. ;; Apostrophe: after an object.
  3264. (should
  3265. (equal '("« " "’s »")
  3266. (let ((org-export-default-language "fr"))
  3267. (org-test-with-parsed-data "\"=code='s\""
  3268. (org-element-map tree 'plain-text
  3269. (lambda (s) (org-export-activate-smart-quotes s :utf-8 info))
  3270. info)))))
  3271. ;; Special case: isolated quotes.
  3272. (should
  3273. (equal '("&ldquo;" "&rdquo;")
  3274. (let ((org-export-default-language "en"))
  3275. (org-test-with-parsed-data "\"$x$\""
  3276. (org-element-map tree 'plain-text
  3277. (lambda (s) (org-export-activate-smart-quotes s :html info))
  3278. info)))))
  3279. ;; Smart quotes in secondary strings.
  3280. (should
  3281. (equal '("&ldquo;" "&rdquo;")
  3282. (let ((org-export-default-language "en"))
  3283. (org-test-with-parsed-data "* \"$x$\""
  3284. (org-element-map tree 'plain-text
  3285. (lambda (s) (org-export-activate-smart-quotes s :html info))
  3286. info)))))
  3287. ;; Smart quotes in document keywords.
  3288. (should
  3289. (equal '("&ldquo;" "&rdquo;")
  3290. (let ((org-export-default-language "en"))
  3291. (org-test-with-parsed-data "#+TITLE: \"$x$\""
  3292. (org-element-map (plist-get info :title) 'plain-text
  3293. (lambda (s) (org-export-activate-smart-quotes s :html info))
  3294. info)))))
  3295. ;; Smart quotes in parsed affiliated keywords.
  3296. (should
  3297. (equal '("&ldquo;" "&rdquo;" "Paragraph")
  3298. (let ((org-export-default-language "en"))
  3299. (org-test-with-parsed-data "#+CAPTION: \"$x$\"\nParagraph"
  3300. (org-element-map tree 'plain-text
  3301. (lambda (s) (org-export-activate-smart-quotes s :html info))
  3302. info nil nil t)))))
  3303. ;; Smart quotes within objects.
  3304. (should
  3305. (equal '("&ldquo;foo&rdquo;")
  3306. (let ((org-export-default-language "en"))
  3307. (org-test-with-parsed-data "| \"foo\" |"
  3308. (org-element-map tree 'plain-text
  3309. (lambda (s) (org-export-activate-smart-quotes s :html info))
  3310. info nil nil t)))))
  3311. ;; FIXME: Test failing non-interactively.
  3312. ;;
  3313. ;; (should
  3314. ;; (equal '("&ldquo;foo&rdquo;")
  3315. ;; (let ((org-export-default-language "en"))
  3316. ;; (org-test-with-parsed-data "*\"foo\"*"
  3317. ;; (org-element-map tree 'plain-text
  3318. ;; (lambda (s) (org-export-activate-smart-quotes s :html info))
  3319. ;; info nil nil t)))))
  3320. )
  3321. ;;; Tables
  3322. (ert-deftest test-org-export/special-column ()
  3323. "Test if the table's special column is properly recognized."
  3324. ;; 1. First column is special if it contains only a special marking
  3325. ;; characters or empty cells.
  3326. (org-test-with-temp-text "
  3327. | ! | 1 |
  3328. | | 2 |"
  3329. (should
  3330. (org-export-table-has-special-column-p
  3331. (org-element-map
  3332. (org-element-parse-buffer) 'table 'identity nil 'first-match))))
  3333. ;; 2. If the column contains anything else, it isn't special.
  3334. (org-test-with-temp-text "
  3335. | ! | 1 |
  3336. | b | 2 |"
  3337. (should-not
  3338. (org-export-table-has-special-column-p
  3339. (org-element-map
  3340. (org-element-parse-buffer) 'table 'identity nil 'first-match))))
  3341. ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
  3342. ;; and "!".
  3343. (org-test-with-temp-text "
  3344. | # | 1 |
  3345. | ^ | 2 |
  3346. | * | 3 |
  3347. | _ | 4 |
  3348. | / | 5 |
  3349. | $ | 6 |
  3350. | ! | 7 |"
  3351. (should
  3352. (org-export-table-has-special-column-p
  3353. (org-element-map
  3354. (org-element-parse-buffer) 'table 'identity nil 'first-match))))
  3355. ;; 4. A first column with only empty cells isn't considered as
  3356. ;; special.
  3357. (org-test-with-temp-text "
  3358. | | 1 |
  3359. | | 2 |"
  3360. (should-not
  3361. (org-export-table-has-special-column-p
  3362. (org-element-map
  3363. (org-element-parse-buffer) 'table 'identity nil 'first-match)))))
  3364. (ert-deftest test-org-export/table-row-is-special-p ()
  3365. "Test `org-export-table-row-is-special-p' specifications."
  3366. ;; 1. A row is special if it has a special marking character in the
  3367. ;; special column.
  3368. (org-test-with-parsed-data "| ! | 1 |"
  3369. (should
  3370. (org-export-table-row-is-special-p
  3371. (org-element-map tree 'table-row 'identity nil 'first-match) info)))
  3372. ;; 2. A row is special when its first field is "/"
  3373. (org-test-with-parsed-data "
  3374. | / | 1 |
  3375. | a | b |"
  3376. (should
  3377. (org-export-table-row-is-special-p
  3378. (org-element-map tree 'table-row 'identity nil 'first-match) info)))
  3379. ;; 3. A row only containing alignment cookies is also considered as
  3380. ;; special.
  3381. (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
  3382. (should
  3383. (org-export-table-row-is-special-p
  3384. (org-element-map tree 'table-row 'identity nil 'first-match) info)))
  3385. ;; 4. Everything else isn't considered as special.
  3386. (org-test-with-parsed-data "| \alpha | | c |"
  3387. (should-not
  3388. (org-export-table-row-is-special-p
  3389. (org-element-map tree 'table-row 'identity nil 'first-match) info)))
  3390. ;; 5. Table's rules are never considered as special rows.
  3391. (org-test-with-parsed-data "|---+---|"
  3392. (should-not
  3393. (org-export-table-row-is-special-p
  3394. (org-element-map tree 'table-row 'identity nil 'first-match) info))))
  3395. (ert-deftest test-org-export/has-header-p ()
  3396. "Test `org-export-table-has-header-p' specifications."
  3397. ;; 1. With an header.
  3398. (org-test-with-parsed-data "
  3399. | a | b |
  3400. |---+---|
  3401. | c | d |"
  3402. (should
  3403. (org-export-table-has-header-p
  3404. (org-element-map tree 'table 'identity info 'first-match)
  3405. info)))
  3406. ;; 2. Without an header.
  3407. (org-test-with-parsed-data "
  3408. | a | b |
  3409. | c | d |"
  3410. (should-not
  3411. (org-export-table-has-header-p
  3412. (org-element-map tree 'table 'identity info 'first-match)
  3413. info)))
  3414. ;; 3. Don't get fooled with starting and ending rules.
  3415. (org-test-with-parsed-data "
  3416. |---+---|
  3417. | a | b |
  3418. | c | d |
  3419. |---+---|"
  3420. (should-not
  3421. (org-export-table-has-header-p
  3422. (org-element-map tree 'table 'identity info 'first-match)
  3423. info))))
  3424. (ert-deftest test-org-export/table-row-group ()
  3425. "Test `org-export-table-row-group' specifications."
  3426. ;; 1. A rule creates a new group.
  3427. (should
  3428. (equal '(1 rule 2)
  3429. (org-test-with-parsed-data "
  3430. | a | b |
  3431. |---+---|
  3432. | 1 | 2 |"
  3433. (org-element-map tree 'table-row
  3434. (lambda (row)
  3435. (if (eq (org-element-property :type row) 'rule) 'rule
  3436. (org-export-table-row-group row info)))))))
  3437. ;; 2. Special rows are ignored in count.
  3438. (should
  3439. (equal
  3440. '(rule 1)
  3441. (org-test-with-parsed-data "
  3442. | / | < | > |
  3443. |---|---+---|
  3444. | | 1 | 2 |"
  3445. (org-element-map tree 'table-row
  3446. (lambda (row)
  3447. (if (eq (org-element-property :type row) 'rule) 'rule
  3448. (org-export-table-row-group row info)))
  3449. info))))
  3450. ;; 3. Double rules also are ignored in count.
  3451. (should
  3452. (equal '(1 rule rule 2)
  3453. (org-test-with-parsed-data "
  3454. | a | b |
  3455. |---+---|
  3456. |---+---|
  3457. | 1 | 2 |"
  3458. (org-element-map tree 'table-row
  3459. (lambda (row)
  3460. (if (eq (org-element-property :type row) 'rule) 'rule
  3461. (org-export-table-row-group row info))))))))
  3462. (ert-deftest test-org-export/table-row-number ()
  3463. "Test `org-export-table-row-number' specifications."
  3464. ;; Standard test. Number is 0-indexed.
  3465. (should
  3466. (equal '(0 1)
  3467. (org-test-with-parsed-data "| a | b | c |\n| d | e | f |"
  3468. (org-element-map tree 'table-row
  3469. (lambda (row) (org-export-table-row-number row info)) info))))
  3470. ;; Number ignores separators.
  3471. (should
  3472. (equal '(0 1)
  3473. (org-test-with-parsed-data "
  3474. | a | b | c |
  3475. |---+---+---|
  3476. | d | e | f |"
  3477. (org-element-map tree 'table-row
  3478. (lambda (row) (org-export-table-row-number row info)) info))))
  3479. ;; Number ignores special rows.
  3480. (should
  3481. (equal '(0 1)
  3482. (org-test-with-parsed-data "
  3483. | / | < | > |
  3484. | | b | c |
  3485. |---+-----+-----|
  3486. | | <c> | <c> |
  3487. | | e | f |"
  3488. (org-element-map tree 'table-row
  3489. (lambda (row) (org-export-table-row-number row info)) info)))))
  3490. (ert-deftest test-org-export/table-cell-width ()
  3491. "Test `org-export-table-cell-width' specifications."
  3492. ;; 1. Width is primarily determined by width cookies. If no cookie
  3493. ;; is found, cell's width is nil.
  3494. (org-test-with-parsed-data "
  3495. | / | <l> | <6> | <l7> |
  3496. | | a | b | c |"
  3497. (should
  3498. (equal
  3499. '(nil 6 7)
  3500. (mapcar (lambda (cell) (org-export-table-cell-width cell info))
  3501. (org-element-map tree 'table-cell 'identity info)))))
  3502. ;; 2. The last width cookie has precedence.
  3503. (org-test-with-parsed-data "
  3504. | <6> |
  3505. | <7> |
  3506. | a |"
  3507. (should
  3508. (equal
  3509. '(7)
  3510. (mapcar (lambda (cell) (org-export-table-cell-width cell info))
  3511. (org-element-map tree 'table-cell 'identity info)))))
  3512. ;; 3. Valid width cookies must have a specific row.
  3513. (org-test-with-parsed-data "| <6> | cell |"
  3514. (should
  3515. (equal
  3516. '(nil nil)
  3517. (mapcar (lambda (cell) (org-export-table-cell-width cell info))
  3518. (org-element-map tree 'table-cell 'identity))))))
  3519. (ert-deftest test-org-export/table-cell-alignment ()
  3520. "Test `org-export-table-cell-alignment' specifications."
  3521. ;; 1. Alignment is primarily determined by alignment cookies.
  3522. (should
  3523. (equal '(left center right)
  3524. (let ((org-table-number-fraction 0.5)
  3525. (org-table-number-regexp "^[0-9]+$"))
  3526. (org-test-with-parsed-data "| <l> | <c> | <r> |"
  3527. (mapcar (lambda (cell)
  3528. (org-export-table-cell-alignment cell info))
  3529. (org-element-map tree 'table-cell 'identity))))))
  3530. ;; 2. The last alignment cookie has precedence.
  3531. (should
  3532. (equal '(right right right)
  3533. (org-test-with-parsed-data "
  3534. | <l8> |
  3535. | cell |
  3536. | <r9> |"
  3537. (mapcar (lambda (cell) (org-export-table-cell-alignment cell info))
  3538. (org-element-map tree 'table-cell 'identity)))))
  3539. ;; 3. If there's no cookie, cell's contents determine alignment.
  3540. ;; A column mostly made of cells containing numbers will align
  3541. ;; its cells to the right.
  3542. (should
  3543. (equal '(right right right)
  3544. (let ((org-table-number-fraction 0.5)
  3545. (org-table-number-regexp "^[0-9]+$"))
  3546. (org-test-with-parsed-data "
  3547. | 123 |
  3548. | some text |
  3549. | 12345 |"
  3550. (mapcar (lambda (cell)
  3551. (org-export-table-cell-alignment cell info))
  3552. (org-element-map tree 'table-cell 'identity))))))
  3553. ;; 4. Otherwise, they will be aligned to the left.
  3554. (should
  3555. (equal '(left left left)
  3556. (org-test-with-parsed-data "
  3557. | text |
  3558. | some text |
  3559. | \alpha |"
  3560. (mapcar (lambda (cell)
  3561. (org-export-table-cell-alignment cell info))
  3562. (org-element-map tree 'table-cell 'identity info))))))
  3563. (ert-deftest test-org-export/table-cell-borders ()
  3564. "Test `org-export-table-cell-borders' specifications."
  3565. ;; 1. Recognize various column groups indicators.
  3566. (org-test-with-parsed-data "| / | < | > | <> |"
  3567. (should
  3568. (equal
  3569. '((right bottom top) (left bottom top) (right bottom top)
  3570. (right left bottom top))
  3571. (mapcar (lambda (cell)
  3572. (org-export-table-cell-borders cell info))
  3573. (org-element-map tree 'table-cell 'identity)))))
  3574. ;; 2. Accept shortcuts to define column groups.
  3575. (org-test-with-parsed-data "| / | < | < |"
  3576. (should
  3577. (equal
  3578. '((right bottom top) (right left bottom top) (left bottom top))
  3579. (mapcar (lambda (cell)
  3580. (org-export-table-cell-borders cell info))
  3581. (org-element-map tree 'table-cell 'identity)))))
  3582. ;; 3. A valid column groups row must start with a "/".
  3583. (org-test-with-parsed-data "
  3584. | | < |
  3585. | a | b |"
  3586. (should
  3587. (equal '((top) (top) (bottom) (bottom))
  3588. (mapcar (lambda (cell)
  3589. (org-export-table-cell-borders cell info))
  3590. (org-element-map tree 'table-cell 'identity)))))
  3591. ;; 4. Take table rules into consideration.
  3592. (org-test-with-parsed-data "
  3593. | 1 |
  3594. |---|
  3595. | 2 |"
  3596. (should
  3597. (equal '((below top) (bottom above))
  3598. (mapcar (lambda (cell)
  3599. (org-export-table-cell-borders cell info))
  3600. (org-element-map tree 'table-cell 'identity)))))
  3601. ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
  3602. ;; (resp. `bottom' and `below') borders. Any special row is
  3603. ;; ignored.
  3604. (org-test-with-parsed-data "
  3605. |---+----|
  3606. | / | |
  3607. | | 1 |
  3608. |---+----|"
  3609. (should
  3610. (equal '((bottom below top above))
  3611. (last
  3612. (mapcar (lambda (cell)
  3613. (org-export-table-cell-borders cell info))
  3614. (org-element-map tree 'table-cell 'identity)))))))
  3615. (ert-deftest test-org-export/table-dimensions ()
  3616. "Test `org-export-table-dimensions' specifications."
  3617. ;; 1. Standard test.
  3618. (org-test-with-parsed-data "
  3619. | 1 | 2 | 3 |
  3620. | 4 | 5 | 6 |"
  3621. (should
  3622. (equal '(2 . 3)
  3623. (org-export-table-dimensions
  3624. (org-element-map tree 'table 'identity info 'first-match) info))))
  3625. ;; 2. Ignore horizontal rules and special columns.
  3626. (org-test-with-parsed-data "
  3627. | / | < | > |
  3628. | 1 | 2 | 3 |
  3629. |---+---+---|
  3630. | 4 | 5 | 6 |"
  3631. (should
  3632. (equal '(2 . 3)
  3633. (org-export-table-dimensions
  3634. (org-element-map tree 'table 'identity info 'first-match) info)))))
  3635. (ert-deftest test-org-export/table-cell-address ()
  3636. "Test `org-export-table-cell-address' specifications."
  3637. ;; 1. Standard test: index is 0-based.
  3638. (org-test-with-parsed-data "| a | b |"
  3639. (should
  3640. (equal '((0 . 0) (0 . 1))
  3641. (org-element-map tree 'table-cell
  3642. (lambda (cell) (org-export-table-cell-address cell info))
  3643. info))))
  3644. ;; 2. Special column isn't counted, nor are special rows.
  3645. (org-test-with-parsed-data "
  3646. | / | <> |
  3647. | | c |"
  3648. (should
  3649. (equal '(0 . 0)
  3650. (org-export-table-cell-address
  3651. (car (last (org-element-map tree 'table-cell 'identity info)))
  3652. info))))
  3653. ;; 3. Tables rules do not count either.
  3654. (org-test-with-parsed-data "
  3655. | a |
  3656. |---|
  3657. | b |
  3658. |---|
  3659. | c |"
  3660. (should
  3661. (equal '(2 . 0)
  3662. (org-export-table-cell-address
  3663. (car (last (org-element-map tree 'table-cell 'identity info)))
  3664. info))))
  3665. ;; 4. Return nil for special cells.
  3666. (org-test-with-parsed-data "| / | a |"
  3667. (should-not
  3668. (org-export-table-cell-address
  3669. (org-element-map tree 'table-cell 'identity nil 'first-match)
  3670. info))))
  3671. (ert-deftest test-org-export/get-table-cell-at ()
  3672. "Test `org-export-get-table-cell-at' specifications."
  3673. ;; 1. Address ignores special columns, special rows and rules.
  3674. (org-test-with-parsed-data "
  3675. | / | <> |
  3676. | | a |
  3677. |---+----|
  3678. | | b |"
  3679. (should
  3680. (equal '("b")
  3681. (org-element-contents
  3682. (org-export-get-table-cell-at
  3683. '(1 . 0)
  3684. (org-element-map tree 'table 'identity info 'first-match)
  3685. info)))))
  3686. ;; 2. Return value for a non-existent address is nil.
  3687. (org-test-with-parsed-data "| a |"
  3688. (should-not
  3689. (org-export-get-table-cell-at
  3690. '(2 . 2)
  3691. (org-element-map tree 'table 'identity info 'first-match)
  3692. info)))
  3693. (org-test-with-parsed-data "| / |"
  3694. (should-not
  3695. (org-export-get-table-cell-at
  3696. '(0 . 0)
  3697. (org-element-map tree 'table 'identity info 'first-match)
  3698. info))))
  3699. (ert-deftest test-org-export/table-cell-starts-colgroup-p ()
  3700. "Test `org-export-table-cell-starts-colgroup-p' specifications."
  3701. ;; 1. A cell at a beginning of a row always starts a column group.
  3702. (org-test-with-parsed-data "| a |"
  3703. (should
  3704. (org-export-table-cell-starts-colgroup-p
  3705. (org-element-map tree 'table-cell 'identity info 'first-match)
  3706. info)))
  3707. ;; 2. Special column should be ignored when determining the
  3708. ;; beginning of the row.
  3709. (org-test-with-parsed-data "
  3710. | / | |
  3711. | | a |"
  3712. (should
  3713. (org-export-table-cell-starts-colgroup-p
  3714. (org-element-map tree 'table-cell 'identity info 'first-match)
  3715. info)))
  3716. ;; 2. Explicit column groups.
  3717. (org-test-with-parsed-data "
  3718. | / | | < |
  3719. | a | b | c |"
  3720. (should
  3721. (equal
  3722. '(yes no yes)
  3723. (org-element-map tree 'table-cell
  3724. (lambda (cell)
  3725. (if (org-export-table-cell-starts-colgroup-p cell info) 'yes 'no))
  3726. info)))))
  3727. (ert-deftest test-org-export/table-cell-ends-colgroup-p ()
  3728. "Test `org-export-table-cell-ends-colgroup-p' specifications."
  3729. ;; 1. A cell at the end of a row always ends a column group.
  3730. (org-test-with-parsed-data "| a |"
  3731. (should
  3732. (org-export-table-cell-ends-colgroup-p
  3733. (org-element-map tree 'table-cell 'identity info 'first-match)
  3734. info)))
  3735. ;; 2. Special column should be ignored when determining the
  3736. ;; beginning of the row.
  3737. (org-test-with-parsed-data "
  3738. | / | |
  3739. | | a |"
  3740. (should
  3741. (org-export-table-cell-ends-colgroup-p
  3742. (org-element-map tree 'table-cell 'identity info 'first-match)
  3743. info)))
  3744. ;; 3. Explicit column groups.
  3745. (org-test-with-parsed-data "
  3746. | / | < | |
  3747. | a | b | c |"
  3748. (should
  3749. (equal
  3750. '(yes no yes)
  3751. (org-element-map tree 'table-cell
  3752. (lambda (cell)
  3753. (if (org-export-table-cell-ends-colgroup-p cell info) 'yes 'no))
  3754. info)))))
  3755. (ert-deftest test-org-export/table-row-starts-rowgroup-p ()
  3756. "Test `org-export-table-row-starts-rowgroup-p' specifications."
  3757. ;; 1. A row at the beginning of a table always starts a row group.
  3758. ;; So does a row following a table rule.
  3759. (org-test-with-parsed-data "
  3760. | a |
  3761. |---|
  3762. | b |"
  3763. (should
  3764. (equal
  3765. '(yes no yes)
  3766. (org-element-map tree 'table-row
  3767. (lambda (row)
  3768. (if (org-export-table-row-starts-rowgroup-p row info) 'yes 'no))
  3769. info))))
  3770. ;; 2. Special rows should be ignored when determining the beginning
  3771. ;; of the row.
  3772. (org-test-with-parsed-data "
  3773. | / | < |
  3774. | | a |
  3775. |---+---|
  3776. | / | < |
  3777. | | b |"
  3778. (should
  3779. (equal
  3780. '(yes no yes)
  3781. (org-element-map tree 'table-row
  3782. (lambda (row)
  3783. (if (org-export-table-row-starts-rowgroup-p row info) 'yes 'no))
  3784. info)))))
  3785. (ert-deftest test-org-export/table-row-ends-rowgroup-p ()
  3786. "Test `org-export-table-row-ends-rowgroup-p' specifications."
  3787. ;; 1. A row at the end of a table always ends a row group. So does
  3788. ;; a row preceding a table rule.
  3789. (org-test-with-parsed-data "
  3790. | a |
  3791. |---|
  3792. | b |"
  3793. (should
  3794. (equal
  3795. '(yes no yes)
  3796. (org-element-map tree 'table-row
  3797. (lambda (row)
  3798. (if (org-export-table-row-ends-rowgroup-p row info) 'yes 'no))
  3799. info))))
  3800. ;; 2. Special rows should be ignored when determining the beginning
  3801. ;; of the row.
  3802. (org-test-with-parsed-data "
  3803. | | a |
  3804. | / | < |
  3805. |---+---|
  3806. | | b |
  3807. | / | < |"
  3808. (should
  3809. (equal
  3810. '(yes no yes)
  3811. (org-element-map tree 'table-row
  3812. (lambda (row)
  3813. (if (org-export-table-row-ends-rowgroup-p row info) 'yes 'no))
  3814. info)))))
  3815. (ert-deftest test-org-export/table-row-in-header-p ()
  3816. "Test `org-export-table-row-in-header-p' specifications."
  3817. ;; Standard test. Separators are always nil.
  3818. (should
  3819. (equal
  3820. '(yes no no)
  3821. (org-test-with-parsed-data "| a |\n|---|\n| b |"
  3822. (org-element-map tree 'table-row
  3823. (lambda (row)
  3824. (if (org-export-table-row-in-header-p row info) 'yes 'no)) info))))
  3825. ;; Nil when there is no header.
  3826. (should
  3827. (equal
  3828. '(no no)
  3829. (org-test-with-parsed-data "| a |\n| b |"
  3830. (org-element-map tree 'table-row
  3831. (lambda (row)
  3832. (if (org-export-table-row-in-header-p row info) 'yes 'no)) info)))))
  3833. (ert-deftest test-org-export/table-row-starts-header-p ()
  3834. "Test `org-export-table-row-starts-header-p' specifications."
  3835. ;; 1. Only the row starting the first row group starts the table
  3836. ;; header.
  3837. (org-test-with-parsed-data "
  3838. | a |
  3839. | b |
  3840. |---|
  3841. | c |"
  3842. (should
  3843. (equal
  3844. '(yes no no no)
  3845. (org-element-map tree 'table-row
  3846. (lambda (row)
  3847. (if (org-export-table-row-starts-header-p row info) 'yes 'no))
  3848. info))))
  3849. ;; 2. A row cannot start an header if there's no header in the
  3850. ;; table.
  3851. (org-test-with-parsed-data "
  3852. | a |
  3853. |---|"
  3854. (should-not
  3855. (org-export-table-row-starts-header-p
  3856. (org-element-map tree 'table-row 'identity info 'first-match)
  3857. info))))
  3858. (ert-deftest test-org-export/table-row-ends-header-p ()
  3859. "Test `org-export-table-row-ends-header-p' specifications."
  3860. ;; 1. Only the row starting the first row group starts the table
  3861. ;; header.
  3862. (org-test-with-parsed-data "
  3863. | a |
  3864. | b |
  3865. |---|
  3866. | c |"
  3867. (should
  3868. (equal
  3869. '(no yes no no)
  3870. (org-element-map tree 'table-row
  3871. (lambda (row)
  3872. (if (org-export-table-row-ends-header-p row info) 'yes 'no))
  3873. info))))
  3874. ;; 2. A row cannot start an header if there's no header in the
  3875. ;; table.
  3876. (org-test-with-parsed-data "
  3877. | a |
  3878. |---|"
  3879. (should-not
  3880. (org-export-table-row-ends-header-p
  3881. (org-element-map tree 'table-row 'identity info 'first-match)
  3882. info))))
  3883. ;;; Tables of Contents
  3884. (ert-deftest test-org-export/collect-headlines ()
  3885. "Test `org-export-collect-headlines' specifications."
  3886. ;; Standard test.
  3887. (should
  3888. (= 2
  3889. (length
  3890. (org-test-with-parsed-data "* H1\n** H2"
  3891. (org-export-collect-headlines info)))))
  3892. ;; Do not collect headlines below optional argument.
  3893. (should
  3894. (= 1
  3895. (length
  3896. (org-test-with-parsed-data "* H1\n** H2"
  3897. (org-export-collect-headlines info 1)))))
  3898. ;; Never collect headlines below maximum headline level.
  3899. (should
  3900. (= 1
  3901. (length
  3902. (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
  3903. (org-export-collect-headlines info)))))
  3904. (should
  3905. (= 1
  3906. (length
  3907. (org-test-with-parsed-data "#+OPTIONS: H:1\n* H1\n** H2"
  3908. (org-export-collect-headlines info 2)))))
  3909. ;; Collect headlines locally.
  3910. (should
  3911. (= 2
  3912. (org-test-with-parsed-data "* H1\n** H2\n** H3"
  3913. (let ((scope (org-element-map tree 'headline #'identity info t)))
  3914. (length (org-export-collect-headlines info nil scope))))))
  3915. ;; When collecting locally, optional level is relative.
  3916. (should
  3917. (= 1
  3918. (org-test-with-parsed-data "* H1\n** H2\n*** H3"
  3919. (let ((scope (org-element-map tree 'headline #'identity info t)))
  3920. (length (org-export-collect-headlines info 1 scope)))))))
  3921. ;;; Templates
  3922. (ert-deftest test-org-export/inner-template ()
  3923. "Test `inner-template' translator specifications."
  3924. (should
  3925. (equal "Success!"
  3926. (org-test-with-temp-text "* Headline"
  3927. (org-export-as
  3928. (org-export-create-backend
  3929. :transcoders
  3930. '((inner-template . (lambda (contents info) "Success!"))
  3931. (headline . (lambda (h c i) "Headline"))))))))
  3932. ;; Inner template is applied even in a "body-only" export.
  3933. (should
  3934. (equal "Success!"
  3935. (org-test-with-temp-text "* Headline"
  3936. (org-export-as
  3937. (org-export-create-backend
  3938. :transcoders '((inner-template . (lambda (c i) "Success!"))
  3939. (headline . (lambda (h c i) "Headline"))))
  3940. nil nil 'body-only)))))
  3941. (ert-deftest test-org-export/template ()
  3942. "Test `template' translator specifications."
  3943. (should
  3944. (equal "Success!"
  3945. (org-test-with-temp-text "* Headline"
  3946. (org-export-as
  3947. (org-export-create-backend
  3948. :transcoders '((template . (lambda (contents info) "Success!"))
  3949. (headline . (lambda (h c i) "Headline"))))))))
  3950. ;; Template is not applied in a "body-only" export.
  3951. (should-not
  3952. (equal "Success!"
  3953. (org-test-with-temp-text "* Headline"
  3954. (org-export-as
  3955. (org-export-create-backend
  3956. :transcoders '((template . (lambda (contents info) "Success!"))
  3957. (headline . (lambda (h c i) "Headline"))))
  3958. nil nil 'body-only)))))
  3959. ;;; Topology
  3960. (ert-deftest test-org-export/get-next-element ()
  3961. "Test `org-export-get-next-element' specifications."
  3962. ;; Standard test.
  3963. (should
  3964. (equal "b"
  3965. (org-test-with-parsed-data "* Headline\n*a* b"
  3966. (org-export-get-next-element
  3967. (org-element-map tree 'bold 'identity info t) info))))
  3968. ;; Return nil when no previous element.
  3969. (should-not
  3970. (org-test-with-parsed-data "* Headline\na *b*"
  3971. (org-export-get-next-element
  3972. (org-element-map tree 'bold 'identity info t) info)))
  3973. ;; Non-exportable elements are ignored.
  3974. (should-not
  3975. (let ((org-export-with-timestamps nil))
  3976. (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
  3977. (org-export-get-next-element
  3978. (org-element-map tree 'entity 'identity info t) info))))
  3979. ;; Find next element in secondary strings.
  3980. (should
  3981. (eq 'verbatim
  3982. (org-test-with-parsed-data "* a =verb="
  3983. (org-element-type
  3984. (org-export-get-next-element
  3985. (org-element-map tree 'plain-text 'identity info t) info)))))
  3986. (should
  3987. (eq 'verbatim
  3988. (org-test-with-parsed-data "* /italic/ =verb="
  3989. (org-element-type
  3990. (org-export-get-next-element
  3991. (org-element-map tree 'italic 'identity info t) info)))))
  3992. ;; Find next element in document keywords.
  3993. (should
  3994. (eq 'verbatim
  3995. (org-test-with-parsed-data "#+TITLE: a =verb="
  3996. (org-element-type
  3997. (org-export-get-next-element
  3998. (org-element-map
  3999. (plist-get info :title) 'plain-text 'identity info t) info)))))
  4000. ;; Find next element in parsed affiliated keywords.
  4001. (should
  4002. (eq 'verbatim
  4003. (org-test-with-parsed-data "#+CAPTION: a =verb=\nParagraph"
  4004. (org-element-type
  4005. (org-export-get-next-element
  4006. (org-element-map tree 'plain-text 'identity info t nil t) info)))))
  4007. ;; With optional argument N, return a list containing all the
  4008. ;; following elements.
  4009. (should
  4010. (equal
  4011. '(bold code underline)
  4012. (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
  4013. (mapcar 'car
  4014. (org-export-get-next-element
  4015. (org-element-map tree 'italic 'identity info t) info t)))))
  4016. ;; When N is a positive integer, return a list containing up to
  4017. ;; N following elements.
  4018. (should
  4019. (equal
  4020. '(bold code)
  4021. (org-test-with-parsed-data "_a_ /b/ *c* ~d~ _e_"
  4022. (mapcar 'car
  4023. (org-export-get-next-element
  4024. (org-element-map tree 'italic 'identity info t) info 2))))))
  4025. (ert-deftest test-org-export/get-previous-element ()
  4026. "Test `org-export-get-previous-element' specifications."
  4027. ;; Standard test.
  4028. (should
  4029. (equal "a "
  4030. (org-test-with-parsed-data "* Headline\na *b*"
  4031. (org-export-get-previous-element
  4032. (org-element-map tree 'bold 'identity info t) info))))
  4033. ;; Return nil when no previous element.
  4034. (should-not
  4035. (org-test-with-parsed-data "* Headline\n*a* b"
  4036. (org-export-get-previous-element
  4037. (org-element-map tree 'bold 'identity info t) info)))
  4038. ;; Non-exportable elements are ignored.
  4039. (should-not
  4040. (let ((org-export-with-timestamps nil))
  4041. (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
  4042. (org-export-get-previous-element
  4043. (org-element-map tree 'entity 'identity info t) info))))
  4044. ;; Find previous element in secondary strings.
  4045. (should
  4046. (eq 'verbatim
  4047. (org-test-with-parsed-data "* =verb= a"
  4048. (org-element-type
  4049. (org-export-get-previous-element
  4050. (org-element-map tree 'plain-text 'identity info t) info)))))
  4051. (should
  4052. (eq 'verbatim
  4053. (org-test-with-parsed-data "* =verb= /italic/"
  4054. (org-element-type
  4055. (org-export-get-previous-element
  4056. (org-element-map tree 'italic 'identity info t) info)))))
  4057. ;; Find previous element in document keywords.
  4058. (should
  4059. (eq 'verbatim
  4060. (org-test-with-parsed-data "#+TITLE: =verb= a"
  4061. (org-element-type
  4062. (org-export-get-previous-element
  4063. (org-element-map
  4064. (plist-get info :title) 'plain-text 'identity info t) info)))))
  4065. ;; Find previous element in parsed affiliated keywords.
  4066. (should
  4067. (eq 'verbatim
  4068. (org-test-with-parsed-data "#+CAPTION: =verb= a\nParagraph"
  4069. (org-element-type
  4070. (org-export-get-previous-element
  4071. (org-element-map tree 'plain-text 'identity info t nil t) info)))))
  4072. ;; With optional argument N, return a list containing up to
  4073. ;; N previous elements.
  4074. (should
  4075. (equal '(underline italic bold)
  4076. (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
  4077. (mapcar 'car
  4078. (org-export-get-previous-element
  4079. (org-element-map tree 'code 'identity info t) info t)))))
  4080. ;; When N is a positive integer, return a list containing up to
  4081. ;; N previous elements.
  4082. (should
  4083. (equal '(italic bold)
  4084. (org-test-with-parsed-data "_a_ /b/ *c* ~d~"
  4085. (mapcar 'car
  4086. (org-export-get-previous-element
  4087. (org-element-map tree 'code 'identity info t) info 2))))))
  4088. (provide 'test-ox)
  4089. ;;; test-org-export.el end here