test-ox.el 96 KB

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