test-ox.el 157 KB

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