test-org-export.el 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688
  1. ;;; test-org-export.el --- Tests for org-export.el
  2. ;; Copyright (C) 2012 Nicolas Goaziou
  3. ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
  4. ;; Released under the GNU General Public License version 3
  5. ;; see: http://www.gnu.org/licenses/gpl-3.0.html
  6. ;;;; Comments
  7. ;;; Code:
  8. (unless (featurep 'org-export)
  9. (signal 'missing-test-dependency "org-export"))
  10. (defmacro org-test-with-backend (backend &rest body)
  11. "Execute body with an export back-end defined.
  12. BACKEND is the name of the back-end. BODY is the body to
  13. execute. The defined back-end simply returns parsed data as Org
  14. syntax."
  15. (declare (debug (form body)) (indent 1))
  16. `(let ((,(intern (format "org-%s-translate-alist" backend))
  17. ',(let (transcode-table)
  18. (dolist (type (append org-element-all-elements
  19. org-element-all-objects)
  20. transcode-table)
  21. (push
  22. (cons type
  23. (lambda (obj contents info)
  24. (funcall
  25. (intern (format "org-element-%s-interpreter" type))
  26. obj contents)))
  27. transcode-table)))))
  28. (progn ,@body)))
  29. (defmacro org-test-with-parsed-data (data &rest body)
  30. "Execute body with parsed data available.
  31. DATA is a string containing the data to be parsed. BODY is the
  32. body to execute. Parse tree is available under the `tree'
  33. variable, and communication channel under `info'.
  34. This function calls `org-export-collect-tree-properties'. As
  35. such, `:ignore-list' (for `org-element-map') and
  36. `:parse-tree' (for `org-export-get-genealogy') properties are
  37. already filled in `info'."
  38. (declare (debug (form body)) (indent 1))
  39. `(org-test-with-temp-text ,data
  40. (let* ((tree (org-element-parse-buffer))
  41. (info (org-export-collect-tree-properties
  42. tree (org-export-get-environment))))
  43. ,@body)))
  44. ;;; Internal Tests
  45. (ert-deftest test-org-export/bind-keyword ()
  46. "Test reading #+BIND: keywords."
  47. ;; Test with `org-export-all-BIND' set to t.
  48. (should
  49. (org-test-with-temp-text "#+BIND: variable value"
  50. (let ((org-export-allow-BIND t))
  51. (org-export--install-letbind-maybe)
  52. (eq variable 'value))))
  53. ;; Test with `org-export-all-BIND' set to nil.
  54. (should-not
  55. (org-test-with-temp-text "#+BIND: variable value"
  56. (let ((org-export-allow-BIND nil))
  57. (org-export--install-letbind-maybe)
  58. (boundp 'variable))))
  59. ;; Test with `org-export-all-BIND' set to 'confirm and
  60. ;; `org-export--allow-BIND-local' to t .
  61. (should
  62. (org-test-with-temp-text "#+BIND: variable value"
  63. (let ((org-export-allow-BIND 'confirm))
  64. (org-set-local 'org-export--allow-BIND-local t)
  65. (org-export--install-letbind-maybe)
  66. (eq variable 'value))))
  67. ;; Test with `org-export-all-BIND' set to 'confirm and
  68. ;; `org-export--allow-BIND-local' to nil.
  69. (should-not
  70. (org-test-with-temp-text "#+BIND: variable value"
  71. (let ((org-export-allow-BIND 'confirm))
  72. (org-set-local 'org-export--allow-BIND-local nil)
  73. (org-export--install-letbind-maybe)
  74. (boundp 'variable))))
  75. ;; BIND keywords are case-insensitive.
  76. (should
  77. (org-test-with-temp-text "#+bind: variable value"
  78. (let ((org-export-allow-BIND t))
  79. (org-export--install-letbind-maybe)
  80. (eq variable 'value)))))
  81. (ert-deftest test-org-export/parse-option-keyword ()
  82. "Test reading all standard #+OPTIONS: items."
  83. (should
  84. (equal
  85. (org-export--parse-option-keyword
  86. "H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t
  87. *:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t inline:nil
  88. stat:t")
  89. '(:headline-levels
  90. 1 :preserve-breaks t :section-numbers t :time-stamp-file t
  91. :with-archived-trees t :with-author t :with-creator t :with-drawers t
  92. :with-email t :with-emphasize t :with-entities t :with-fixed-width t
  93. :with-footnotes t :with-inlinetasks nil :with-priority t
  94. :with-special-strings t :with-statistics-cookies t :with-sub-superscript t
  95. :with-toc t :with-tables t :with-tags t :with-tasks t :with-timestamps t
  96. :with-todo-keywords t)))
  97. ;; Test some special values.
  98. (should
  99. (equal
  100. (org-export--parse-option-keyword
  101. "arch:headline creator:comment d:(\"TEST\")
  102. ^:{} toc:1 tags:not-in-toc tasks:todo num:2 <:active")
  103. '( :section-numbers
  104. 2
  105. :with-archived-trees headline :with-creator comment
  106. :with-drawers ("TEST") :with-sub-superscript {} :with-toc 1
  107. :with-tags not-in-toc :with-tasks todo :with-timestamps active))))
  108. (ert-deftest test-org-export/get-inbuffer-options ()
  109. "Test reading all standard export keywords."
  110. (should
  111. (equal
  112. (org-test-with-temp-text "#+AUTHOR: Me, Myself and I
  113. #+CREATOR: Idem
  114. #+DATE: Today
  115. #+DESCRIPTION: Testing
  116. #+DESCRIPTION: with two lines
  117. #+EMAIL: some@email.org
  118. #+EXCLUDE_TAGS: noexport invisible
  119. #+KEYWORDS: test
  120. #+LANGUAGE: en
  121. #+SELECT_TAGS: export
  122. #+TITLE: Some title
  123. #+TITLE: with spaces"
  124. (org-export--get-inbuffer-options))
  125. '(:author
  126. ("Me, Myself and I") :creator "Idem" :date ("Today")
  127. :description "Testing\nwith two lines" :email "some@email.org"
  128. :exclude-tags ("noexport" "invisible") :keywords "test" :language "en"
  129. :select-tags ("export") :title ("Some title with spaces")))))
  130. (ert-deftest test-org-export/get-subtree-options ()
  131. "Test setting options from headline's properties."
  132. ;; EXPORT_TITLE.
  133. (org-test-with-temp-text "#+TITLE: Title
  134. * Headline
  135. :PROPERTIES:
  136. :EXPORT_TITLE: Subtree Title
  137. :END:
  138. Paragraph"
  139. (forward-line)
  140. (should (equal (plist-get (org-export-get-environment nil t) :title)
  141. '("Subtree Title"))))
  142. :title
  143. '("subtree-title")
  144. ;; EXPORT_OPTIONS.
  145. (org-test-with-temp-text "#+OPTIONS: H:1
  146. * Headline
  147. :PROPERTIES:
  148. :EXPORT_OPTIONS: H:2
  149. :END:
  150. Paragraph"
  151. (forward-line)
  152. (should
  153. (= 2 (plist-get (org-export-get-environment nil t) :headline-levels))))
  154. ;; EXPORT_DATE.
  155. (org-test-with-temp-text "#+DATE: today
  156. * Headline
  157. :PROPERTIES:
  158. :EXPORT_DATE: 29-03-2012
  159. :END:
  160. Paragraph"
  161. (forward-line)
  162. (should (equal (plist-get (org-export-get-environment nil t) :date)
  163. '("29-03-2012"))))
  164. ;; Export properties are case-insensitive.
  165. (org-test-with-temp-text "* Headline
  166. :PROPERTIES:
  167. :EXPORT_Date: 29-03-2012
  168. :END:
  169. Paragraph"
  170. (should (equal (plist-get (org-export-get-environment nil t) :date)
  171. '("29-03-2012")))))
  172. (ert-deftest test-org-export/handle-options ()
  173. "Test if export options have an impact on output."
  174. ;; Test exclude tags.
  175. (org-test-with-temp-text "* Head1 :noexport:"
  176. (org-test-with-backend test
  177. (should
  178. (equal (org-export-as 'test nil nil nil '(:exclude-tags ("noexport")))
  179. ""))))
  180. ;; Test include tags.
  181. (org-test-with-temp-text "
  182. * Head1
  183. * Head2
  184. ** Sub-Head2.1 :export:
  185. *** Sub-Head2.1.1
  186. * Head2"
  187. (org-test-with-backend test
  188. (should
  189. (equal
  190. "* Head2\n** Sub-Head2.1 :export:\n*** Sub-Head2.1.1\n"
  191. (let ((org-tags-column 0))
  192. (org-export-as 'test nil nil nil '(:select-tags ("export"))))))))
  193. ;; Test mixing include tags and exclude tags.
  194. (org-test-with-temp-text "
  195. * Head1 :export:
  196. ** Sub-Head1 :noexport:
  197. ** Sub-Head2
  198. * Head2 :noexport:
  199. ** Sub-Head1 :export:"
  200. (org-test-with-backend test
  201. (should
  202. (string-match
  203. "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
  204. (org-export-as
  205. 'test nil nil nil
  206. '(:select-tags ("export") :exclude-tags ("noexport")))))))
  207. ;; Ignore tasks.
  208. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  209. (org-test-with-temp-text "* TODO Head1"
  210. (org-test-with-backend test
  211. (should (equal (org-export-as 'test nil nil nil '(:with-tasks nil))
  212. "")))))
  213. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  214. (org-test-with-temp-text "* TODO Head1"
  215. (org-test-with-backend test
  216. (should (equal (org-export-as 'test nil nil nil '(:with-tasks t))
  217. "* TODO Head1\n")))))
  218. ;; Archived tree.
  219. (org-test-with-temp-text "* Head1 :archive:"
  220. (let ((org-archive-tag "archive"))
  221. (org-test-with-backend test
  222. (should
  223. (equal (org-export-as 'test nil nil nil '(:with-archived-trees nil))
  224. "")))))
  225. (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
  226. (let ((org-archive-tag "archive"))
  227. (org-test-with-backend test
  228. (should
  229. (string-match
  230. "\\* Head1[ \t]+:archive:"
  231. (org-export-as 'test nil nil nil
  232. '(:with-archived-trees headline)))))))
  233. (org-test-with-temp-text "* Head1 :archive:"
  234. (let ((org-archive-tag "archive"))
  235. (org-test-with-backend test
  236. (should
  237. (string-match
  238. "\\`\\* Head1[ \t]+:archive:\n\\'"
  239. (org-export-as 'test nil nil nil '(:with-archived-trees t)))))))
  240. ;; Drawers.
  241. (let ((org-drawers '("TEST")))
  242. (org-test-with-temp-text ":TEST:\ncontents\n:END:"
  243. (org-test-with-backend test
  244. (should (equal (org-export-as 'test nil nil nil '(:with-drawers nil))
  245. ""))
  246. (should (equal (org-export-as 'test nil nil nil '(:with-drawers t))
  247. ":TEST:\ncontents\n:END:\n")))))
  248. (let ((org-drawers '("FOO" "BAR")))
  249. (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
  250. (org-test-with-backend test
  251. (should
  252. (equal (org-export-as 'test nil nil nil '(:with-drawers ("FOO")))
  253. ":FOO:\nkeep\n:END:\n")))))
  254. ;; Timestamps.
  255. (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
  256. (org-test-with-backend test
  257. (should
  258. (equal (org-export-as 'test nil nil nil '(:with-timestamps t))
  259. "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>\n"))
  260. (should
  261. (equal (org-export-as 'test nil nil nil '(:with-timestamps nil)) ""))
  262. (should
  263. (equal (org-export-as 'test nil nil nil '(:with-timestamps active))
  264. "<2012-04-29 sun. 10:45>\n"))
  265. (should
  266. (equal (org-export-as 'test nil nil nil '(:with-timestamps inactive))
  267. "[2012-04-29 sun. 10:45]\n"))))
  268. ;; Clocks.
  269. (let ((org-clock-string "CLOCK:"))
  270. (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
  271. (org-test-with-backend test
  272. (should
  273. (equal (org-export-as 'test nil nil nil '(:with-clocks t))
  274. "CLOCK: [2012-04-29 sun. 10:45]\n"))
  275. (should
  276. (equal (org-export-as 'test nil nil nil '(:with-clocks nil)) "")))))
  277. ;; Plannings.
  278. (let ((org-closed-string "CLOSED:"))
  279. (org-test-with-temp-text "CLOSED: [2012-04-29 sun. 10:45]"
  280. (org-test-with-backend test
  281. (should
  282. (equal (org-export-as 'test nil nil nil '(:with-plannings t))
  283. "CLOSED: [2012-04-29 sun. 10:45]\n"))
  284. (should
  285. (equal (org-export-as 'test nil nil nil '(:with-plannings nil))
  286. "")))))
  287. ;; Inlinetasks.
  288. (when (featurep 'org-inlinetask)
  289. (should
  290. (equal
  291. (let ((org-inlinetask-min-level 15))
  292. (org-test-with-temp-text "*************** Task"
  293. (org-test-with-backend test
  294. (org-export-as 'test nil nil nil '(:with-inlinetasks nil)))))
  295. ""))
  296. (should
  297. (equal
  298. (let ((org-inlinetask-min-level 15))
  299. (org-test-with-temp-text
  300. "*************** Task\nContents\n*************** END"
  301. (org-test-with-backend test
  302. (org-export-as 'test nil nil nil '(:with-inlinetasks nil)))))
  303. "")))
  304. ;; Statistics cookies.
  305. (should
  306. (equal ""
  307. (org-test-with-temp-text "[0/0]"
  308. (org-test-with-backend test
  309. (org-export-as
  310. 'test nil nil nil '(:with-statistics-cookies nil)))))))
  311. (ert-deftest test-org-export/comment-tree ()
  312. "Test if export process ignores commented trees."
  313. (let ((org-comment-string "COMMENT"))
  314. (org-test-with-temp-text "* COMMENT Head1"
  315. (org-test-with-backend test
  316. (should (equal (org-export-as 'test) ""))))))
  317. (ert-deftest test-org-export/export-scope ()
  318. "Test all export scopes."
  319. (org-test-with-temp-text "
  320. * Head1
  321. ** Head2
  322. text
  323. *** Head3"
  324. (org-test-with-backend test
  325. ;; Subtree.
  326. (forward-line 3)
  327. (should (equal (org-export-as 'test 'subtree) "text\n*** Head3\n"))
  328. ;; Visible.
  329. (goto-char (point-min))
  330. (forward-line)
  331. (org-cycle)
  332. (should (equal (org-export-as 'test nil 'visible) "* Head1\n"))
  333. ;; Body only.
  334. (flet ((org-test-template (body info) (format "BEGIN\n%sEND" body)))
  335. (push '(template . org-test-template) org-test-translate-alist)
  336. (should (equal (org-export-as 'test nil nil 'body-only)
  337. "* Head1\n** Head2\ntext\n*** Head3\n"))
  338. (should (equal (org-export-as 'test)
  339. "BEGIN\n* Head1\n** Head2\ntext\n*** Head3\nEND")))
  340. ;; Region.
  341. (goto-char (point-min))
  342. (forward-line 3)
  343. (transient-mark-mode 1)
  344. (push-mark (point) t t)
  345. (goto-char (point-at-eol))
  346. (should (equal (org-export-as 'test) "text\n"))))
  347. ;; Subtree with a code block calling another block outside.
  348. (org-test-with-temp-text "
  349. * Head1
  350. #+BEGIN_SRC emacs-lisp :noweb yes :exports results
  351. <<test>>
  352. #+END_SRC
  353. * Head2
  354. #+NAME: test
  355. #+BEGIN_SRC emacs-lisp
  356. \(+ 1 2)
  357. #+END_SRC"
  358. (org-test-with-backend test
  359. (forward-line 1)
  360. (should (equal (org-export-as 'test 'subtree) ": 3\n")))))
  361. (ert-deftest test-org-export/expand-include ()
  362. "Test file inclusion in an Org buffer."
  363. ;; Full insertion with recursive inclusion.
  364. (org-test-with-temp-text
  365. (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir)
  366. (org-export-expand-include-keyword)
  367. (should (equal (buffer-string)
  368. "Small Org file with an include keyword.
  369. #+BEGIN_SRC emacs-lisp :exports results\n(+ 2 1)\n#+END_SRC
  370. Success!
  371. * Heading
  372. body\n")))
  373. ;; Localized insertion.
  374. (org-test-with-temp-text
  375. (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
  376. org-test-dir)
  377. (org-export-expand-include-keyword)
  378. (should (equal (buffer-string)
  379. "Small Org file with an include keyword.\n")))
  380. ;; Insertion with constraints on headlines level.
  381. (org-test-with-temp-text
  382. (format
  383. "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\""
  384. org-test-dir)
  385. (org-export-expand-include-keyword)
  386. (should (equal (buffer-string) "* Top heading\n** Heading\nbody\n")))
  387. ;; Inclusion within an example block.
  388. (org-test-with-temp-text
  389. (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" example"
  390. org-test-dir)
  391. (org-export-expand-include-keyword)
  392. (should
  393. (equal
  394. (buffer-string)
  395. "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n")))
  396. ;; Inclusion within a src-block.
  397. (org-test-with-temp-text
  398. (format
  399. "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" src emacs-lisp"
  400. org-test-dir)
  401. (org-export-expand-include-keyword)
  402. (should (equal (buffer-string)
  403. "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"))))
  404. (ert-deftest test-org-export/user-ignore-list ()
  405. "Test if `:ignore-list' accepts user input."
  406. (org-test-with-backend test
  407. (flet ((skip-note-head
  408. (data backend info)
  409. ;; Ignore headlines with the word "note" in their title.
  410. (org-element-map
  411. data 'headline
  412. (lambda (headline)
  413. (when (string-match "\\<note\\>"
  414. (org-element-property :raw-value headline))
  415. (org-export-ignore-element headline info)))
  416. info)
  417. data))
  418. ;; Install function in parse tree filters.
  419. (let ((org-export-filter-parse-tree-functions '(skip-note-head)))
  420. (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
  421. (should (equal (org-export-as 'test) "* Head1\n")))))))
  422. (ert-deftest test-org-export/before-parsing-hook ()
  423. "Test `org-export-before-parsing-hook'."
  424. (org-test-with-backend test
  425. (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
  426. (let ((org-export-before-parsing-hook
  427. '((lambda (backend)
  428. (org-map-entries
  429. (lambda ()
  430. (delete-region (point) (progn (forward-line) (point)))))))))
  431. (should (equal (org-export-as 'test) "Body 1\nBody 2\n"))))))
  432. ;;; Affiliated Keywords
  433. (ert-deftest test-org-export/read-attribute ()
  434. "Test `org-export-read-attribute' specifications."
  435. ;; Standard test.
  436. (should
  437. (equal
  438. (org-export-read-attribute
  439. :attr_html
  440. (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
  441. (org-element-at-point)))
  442. '(:a 1 :b 2)))
  443. ;; Return nil on empty attribute.
  444. (should-not
  445. (org-export-read-attribute
  446. :attr_html
  447. (org-test-with-temp-text "Paragraph" (org-element-at-point)))))
  448. (ert-deftest test-org-export/get-caption ()
  449. "Test `org-export-get-caption' specifications."
  450. ;; Without optional argument, return long caption
  451. (should
  452. (equal
  453. '("l")
  454. (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
  455. (org-export-get-caption (org-element-at-point)))))
  456. ;; With optional argument, return short caption.
  457. (should
  458. (equal
  459. '("s")
  460. (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
  461. (org-export-get-caption (org-element-at-point) t))))
  462. ;; Multiple lines are separated by white spaces.
  463. (should
  464. (equal
  465. '("a" " " "b")
  466. (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
  467. (org-export-get-caption (org-element-at-point))))))
  468. ;;; Export Snippets
  469. (ert-deftest test-org-export/export-snippet ()
  470. "Test export snippets transcoding."
  471. (org-test-with-temp-text "@@test:A@@@@t:B@@"
  472. (org-test-with-backend test
  473. (let ((org-test-translate-alist
  474. (cons (cons 'export-snippet
  475. (lambda (snippet contents info)
  476. (when (eq (org-export-snippet-backend snippet) 'test)
  477. (org-element-property :value snippet))))
  478. org-test-translate-alist)))
  479. (let ((org-export-snippet-translation-alist nil))
  480. (should (equal (org-export-as 'test) "A\n")))
  481. (let ((org-export-snippet-translation-alist '(("t" . "test"))))
  482. (should (equal (org-export-as 'test) "AB\n")))))))
  483. ;;; Footnotes
  484. (ert-deftest test-org-export/footnotes ()
  485. "Test footnotes specifications."
  486. (let ((org-footnote-section nil)
  487. (org-export-with-footnotes t))
  488. ;; 1. Read every type of footnote.
  489. (should
  490. (equal
  491. '((1 . "A\n") (2 . "B") (3 . "C") (4 . "D"))
  492. (org-test-with-parsed-data
  493. "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
  494. (org-element-map
  495. tree 'footnote-reference
  496. (lambda (ref)
  497. (let ((def (org-export-get-footnote-definition ref info)))
  498. (cons (org-export-get-footnote-number ref info)
  499. (if (eq (org-element-property :type ref) 'inline) (car def)
  500. (car (org-element-contents
  501. (car (org-element-contents def))))))))
  502. info))))
  503. ;; 2. Test nested footnotes order.
  504. (org-test-with-parsed-data
  505. "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
  506. (should
  507. (equal
  508. '((1 . "fn:1") (2 . "fn:2") (3 . "fn:3") (4))
  509. (org-element-map
  510. tree 'footnote-reference
  511. (lambda (ref)
  512. (when (org-export-footnote-first-reference-p ref info)
  513. (cons (org-export-get-footnote-number ref info)
  514. (org-element-property :label ref))))
  515. info))))
  516. ;; 3. Test nested footnote in invisible definitions.
  517. (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
  518. ;; Hide definitions.
  519. (narrow-to-region (point) (point-at-eol))
  520. (let* ((tree (org-element-parse-buffer))
  521. (info (org-combine-plists
  522. `(:parse-tree ,tree)
  523. (org-export-collect-tree-properties
  524. tree (org-export-get-environment)))))
  525. ;; Both footnotes should be seen.
  526. (should
  527. (= (length (org-export-collect-footnote-definitions tree info)) 2))))
  528. ;; 4. Test footnotes definitions collection.
  529. (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
  530. \[fn:2] B [fn:3] [fn::D].
  531. \[fn:3] C."
  532. (should (= (length (org-export-collect-footnote-definitions tree info))
  533. 4)))
  534. ;; 5. Test export of footnotes defined outside parsing scope.
  535. (org-test-with-temp-text "[fn:1] Out of scope
  536. * Title
  537. Paragraph[fn:1]"
  538. (org-test-with-backend test
  539. (let ((org-test-translate-alist
  540. (cons (cons 'footnote-reference
  541. (lambda (fn contents info)
  542. (org-element-interpret-data
  543. (org-export-get-footnote-definition fn info))))
  544. org-test-translate-alist)))
  545. (forward-line)
  546. (should (equal "ParagraphOut of scope\n"
  547. (org-export-as 'test 'subtree))))))))
  548. ;;; Headlines and Inlinetasks
  549. (ert-deftest test-org-export/get-relative-level ()
  550. "Test `org-export-get-relative-level' specifications."
  551. ;; Standard test.
  552. (should
  553. (equal '(1 2)
  554. (let ((org-odd-levels-only nil))
  555. (org-test-with-parsed-data "* Headline 1\n** Headline 2"
  556. (org-element-map
  557. tree 'headline
  558. (lambda (h) (org-export-get-relative-level h info))
  559. info)))))
  560. ;; Missing levels
  561. (should
  562. (equal '(1 3)
  563. (let ((org-odd-levels-only nil))
  564. (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
  565. (org-element-map
  566. tree 'headline
  567. (lambda (h) (org-export-get-relative-level h info))
  568. info))))))
  569. (ert-deftest test-org-export/low-level-p ()
  570. "Test `org-export-low-level-p' specifications."
  571. (should
  572. (equal
  573. '(no yes)
  574. (let ((org-odd-levels-only nil))
  575. (org-test-with-parsed-data "* Headline 1\n** Headline 2"
  576. (org-element-map
  577. tree 'headline
  578. (lambda (h) (if (org-export-low-level-p h info) 'yes 'no))
  579. (plist-put info :headline-levels 1)))))))
  580. (ert-deftest test-org-export/get-headline-number ()
  581. "Test `org-export-get-headline-number' specifications."
  582. ;; Standard test.
  583. (should
  584. (equal
  585. '((1) (1 1))
  586. (let ((org-odd-levels-only nil))
  587. (org-test-with-parsed-data "* Headline 1\n** Headline 2"
  588. (org-element-map
  589. tree 'headline
  590. (lambda (h) (org-export-get-headline-number h info))
  591. info)))))
  592. ;; Missing levels are replaced with 0.
  593. (should
  594. (equal
  595. '((1) (1 0 1))
  596. (let ((org-odd-levels-only nil))
  597. (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
  598. (org-element-map
  599. tree 'headline
  600. (lambda (h) (org-export-get-headline-number h info))
  601. info))))))
  602. (ert-deftest test-org-export/numbered-headline-p ()
  603. "Test `org-export-numbered-headline-p' specifications."
  604. ;; If `:section-numbers' is nil, never number headlines.
  605. (should-not
  606. (org-test-with-parsed-data "* Headline"
  607. (org-element-map
  608. tree 'headline
  609. (lambda (h) (org-export-numbered-headline-p h info))
  610. (plist-put info :section-numbers nil))))
  611. ;; If `:section-numbers' is a number, only number headlines with
  612. ;; a level greater that it.
  613. (should
  614. (equal
  615. '(yes no)
  616. (org-test-with-parsed-data "* Headline 1\n** Headline 2"
  617. (org-element-map
  618. tree 'headline
  619. (lambda (h) (if (org-export-numbered-headline-p h info) 'yes 'no))
  620. (plist-put info :section-numbers 1)))))
  621. ;; Otherwise, headlines are always numbered.
  622. (should
  623. (org-test-with-parsed-data "* Headline"
  624. (org-element-map
  625. tree 'headline
  626. (lambda (h) (org-export-numbered-headline-p h info))
  627. (plist-put info :section-numbers t)))))
  628. (ert-deftest test-org-export/number-to-roman ()
  629. "Test `org-export-number-to-roman' specifications."
  630. ;; If number is negative, return it as a string.
  631. (should (equal (org-export-number-to-roman -1) "-1"))
  632. ;; Otherwise, return it as a roman number.
  633. (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
  634. (ert-deftest test-org-export/get-tags ()
  635. "Test `org-export-get-tags' specifications."
  636. (let ((org-export-exclude-tags '("noexport"))
  637. (org-export-select-tags '("export")))
  638. ;; Standard test: tags which are not a select tag, an exclude tag,
  639. ;; or specified as optional argument shouldn't be ignored.
  640. (should
  641. (org-test-with-parsed-data "* Headline :tag:"
  642. (org-export-get-tags (org-element-map tree 'headline 'identity info t)
  643. info)))
  644. ;; Exclude tags are removed.
  645. (should-not
  646. (org-test-with-parsed-data "* Headline :noexport:"
  647. (org-export-get-tags (org-element-map tree 'headline 'identity info t)
  648. info)))
  649. ;; Select tags are removed.
  650. (should-not
  651. (org-test-with-parsed-data "* Headline :export:"
  652. (org-export-get-tags (org-element-map tree 'headline 'identity info t)
  653. info)))
  654. (should
  655. (equal
  656. '("tag")
  657. (org-test-with-parsed-data "* Headline :tag:export:"
  658. (org-export-get-tags (org-element-map tree 'headline 'identity info t)
  659. info))))
  660. ;; Tags provided in the optional argument are also ignored.
  661. (should-not
  662. (org-test-with-parsed-data "* Headline :ignore:"
  663. (org-export-get-tags (org-element-map tree 'headline 'identity info t)
  664. info '("ignore"))))))
  665. (ert-deftest test-org-export/get-node-property ()
  666. "Test`org-export-get-node-property' specifications."
  667. ;; Standard test.
  668. (should
  669. (equal "value"
  670. (org-test-with-parsed-data "* Headline
  671. :PROPERTIES:
  672. :prop: value
  673. :END:"
  674. (org-export-get-node-property
  675. :prop (org-element-map tree 'headline 'identity nil t)))))
  676. ;; Test inheritance.
  677. (should
  678. (equal "value"
  679. (org-test-with-parsed-data "* Parent
  680. :PROPERTIES:
  681. :prop: value
  682. :END:
  683. ** Headline
  684. Paragraph"
  685. (org-export-get-node-property
  686. :prop (org-element-map tree 'paragraph 'identity nil t) t))))
  687. ;; Cannot return a value before the first headline.
  688. (should-not
  689. (org-test-with-parsed-data "Paragraph
  690. * Headline
  691. :PROPERTIES:
  692. :prop: value
  693. :END:"
  694. (org-export-get-node-property
  695. :prop (org-element-map tree 'paragraph 'identity nil t)))))
  696. (ert-deftest test-org-export/first-sibling-p ()
  697. "Test `org-export-first-sibling-p' specifications."
  698. ;; Standard test.
  699. (should
  700. (equal
  701. '(yes yes no)
  702. (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
  703. (org-element-map
  704. tree 'headline
  705. (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
  706. info))))
  707. ;; Ignore headlines not exported.
  708. (should
  709. (equal
  710. '(yes)
  711. (let ((org-export-exclude-tags '("ignore")))
  712. (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
  713. (org-element-map
  714. tree 'headline
  715. (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
  716. info))))))
  717. (ert-deftest test-org-export/last-sibling-p ()
  718. "Test `org-export-last-sibling-p' specifications."
  719. ;; Standard test.
  720. (should
  721. (equal
  722. '(yes no yes)
  723. (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
  724. (org-element-map
  725. tree 'headline
  726. (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
  727. info))))
  728. ;; Ignore headlines not exported.
  729. (should
  730. (equal
  731. '(yes)
  732. (let ((org-export-exclude-tags '("ignore")))
  733. (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
  734. (org-element-map
  735. tree 'headline
  736. (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
  737. info))))))
  738. ;;; Links
  739. (ert-deftest test-org-export/get-coderef-format ()
  740. "Test `org-export-get-coderef-format' specifications."
  741. ;; A link without description returns "%s"
  742. (should (equal (org-export-get-coderef-format "(ref:line)" nil)
  743. "%s"))
  744. ;; Return "%s" when path is matched within description.
  745. (should (equal (org-export-get-coderef-format "path" "desc (path)")
  746. "desc %s"))
  747. ;; Otherwise return description.
  748. (should (equal (org-export-get-coderef-format "path" "desc")
  749. "desc")))
  750. (ert-deftest test-org-export/inline-image-p ()
  751. "Test `org-export-inline-image-p' specifications."
  752. (should
  753. (org-export-inline-image-p
  754. (org-test-with-temp-text "[[#id]]"
  755. (org-element-map
  756. (org-element-parse-buffer) 'link 'identity nil t))
  757. '(("custom-id" . "id")))))
  758. (ert-deftest test-org-export/fuzzy-link ()
  759. "Test fuzzy links specifications."
  760. ;; 1. Links to invisible (keyword) targets should be ignored.
  761. (org-test-with-parsed-data
  762. "Paragraph.\n#+TARGET: Test\n[[Test]]"
  763. (should-not
  764. (org-element-map
  765. tree 'link
  766. (lambda (link)
  767. (org-export-get-ordinal
  768. (org-export-resolve-fuzzy-link link info) info)) info)))
  769. ;; 2. Link to an headline should return headline's number.
  770. (org-test-with-parsed-data
  771. "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
  772. (should
  773. ;; Note: Headline's number is in fact a list of numbers.
  774. (equal '(2)
  775. (org-element-map
  776. tree 'link
  777. (lambda (link)
  778. (org-export-get-ordinal
  779. (org-export-resolve-fuzzy-link link info) info)) info t))))
  780. ;; 3. Link to a target in an item should return item's number.
  781. (org-test-with-parsed-data
  782. "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
  783. (should
  784. ;; Note: Item's number is in fact a list of numbers.
  785. (equal '(1 2)
  786. (org-element-map
  787. tree 'link
  788. (lambda (link)
  789. (org-export-get-ordinal
  790. (org-export-resolve-fuzzy-link link info) info)) info t))))
  791. ;; 4. Link to a target in a footnote should return footnote's
  792. ;; number.
  793. (org-test-with-parsed-data "
  794. Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
  795. (should
  796. (equal '(2 3)
  797. (org-element-map
  798. tree 'link
  799. (lambda (link)
  800. (org-export-get-ordinal
  801. (org-export-resolve-fuzzy-link link info) info)) info))))
  802. ;; 5. Link to a named element should return sequence number of that
  803. ;; element.
  804. (org-test-with-parsed-data
  805. "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
  806. (should
  807. (= 2
  808. (org-element-map
  809. tree 'link
  810. (lambda (link)
  811. (org-export-get-ordinal
  812. (org-export-resolve-fuzzy-link link info) info)) info t))))
  813. ;; 6. Link to a target not within an item, a table, a footnote
  814. ;; reference or definition should return section number.
  815. (org-test-with-parsed-data
  816. "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
  817. (should
  818. (equal '(2)
  819. (org-element-map
  820. tree 'link
  821. (lambda (link)
  822. (org-export-get-ordinal
  823. (org-export-resolve-fuzzy-link link info) info)) info t)))))
  824. (ert-deftest test-org-export/resolve-coderef ()
  825. "Test `org-export-resolve-coderef' specifications."
  826. (let ((org-coderef-label-format "(ref:%s)"))
  827. ;; 1. A link to a "-n -k -r" block returns line number.
  828. (org-test-with-parsed-data
  829. "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
  830. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  831. (org-test-with-parsed-data
  832. "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  833. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  834. ;; 2. A link to a "-n -r" block returns line number.
  835. (org-test-with-parsed-data
  836. "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
  837. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  838. (org-test-with-parsed-data
  839. "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  840. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  841. ;; 3. A link to a "-n" block returns coderef.
  842. (org-test-with-parsed-data
  843. "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  844. (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
  845. (org-test-with-parsed-data
  846. "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
  847. (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
  848. ;; 4. A link to a "-r" block returns line number.
  849. (org-test-with-parsed-data
  850. "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  851. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  852. (org-test-with-parsed-data
  853. "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
  854. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  855. ;; 5. A link to a block without a switch returns coderef.
  856. (org-test-with-parsed-data
  857. "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  858. (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
  859. (org-test-with-parsed-data
  860. "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
  861. (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
  862. ;; 6. Correctly handle continued line numbers. A "+n" switch
  863. ;; should resume numbering from previous block with numbered
  864. ;; lines, ignoring blocks not numbering lines in the process.
  865. ;; A "-n" switch resets count.
  866. (org-test-with-parsed-data "
  867. #+BEGIN_EXAMPLE -n
  868. Text.
  869. #+END_EXAMPLE
  870. #+BEGIN_SRC emacs-lisp
  871. \(- 1 1)
  872. #+END_SRC
  873. #+BEGIN_SRC emacs-lisp +n -r
  874. \(+ 1 1) (ref:addition)
  875. #+END_SRC
  876. #+BEGIN_EXAMPLE -n -r
  877. Another text. (ref:text)
  878. #+END_EXAMPLE"
  879. (should (= (org-export-resolve-coderef "addition" info) 2))
  880. (should (= (org-export-resolve-coderef "text" info) 1)))
  881. ;; 7. Recognize coderef with user-specified syntax.
  882. (org-test-with-parsed-data
  883. "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
  884. (should (equal (org-export-resolve-coderef "text" info) "text")))))
  885. (ert-deftest test-org-export/resolve-fuzzy-link ()
  886. "Test `org-export-resolve-fuzzy-link' specifications."
  887. ;; 1. Match target objects.
  888. (org-test-with-parsed-data "<<target>> [[target]]"
  889. (should
  890. (org-export-resolve-fuzzy-link
  891. (org-element-map tree 'link 'identity info t) info)))
  892. ;; 2. Match target elements.
  893. (org-test-with-parsed-data "#+TARGET: target\n[[target]]"
  894. (should
  895. (org-export-resolve-fuzzy-link
  896. (org-element-map tree 'link 'identity info t) info)))
  897. ;; 3. Match named elements.
  898. (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
  899. (should
  900. (org-export-resolve-fuzzy-link
  901. (org-element-map tree 'link 'identity info t) info)))
  902. ;; 4. Match exact headline's name.
  903. (org-test-with-parsed-data "* My headline\n[[My headline]]"
  904. (should
  905. (org-export-resolve-fuzzy-link
  906. (org-element-map tree 'link 'identity info t) info)))
  907. ;; 5. Targets objects have priority over named elements and headline
  908. ;; titles.
  909. (org-test-with-parsed-data
  910. "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
  911. (should
  912. (eq 'target
  913. (org-element-type
  914. (org-export-resolve-fuzzy-link
  915. (org-element-map tree 'link 'identity info t) info)))))
  916. ;; 6. Named elements have priority over headline titles.
  917. (org-test-with-parsed-data
  918. "* target\n#+NAME: target\nParagraph\n\n[[target]]"
  919. (should
  920. (eq 'paragraph
  921. (org-element-type
  922. (org-export-resolve-fuzzy-link
  923. (org-element-map tree 'link 'identity info t) info)))))
  924. ;; 7. If link's path starts with a "*", only match headline titles,
  925. ;; though.
  926. (org-test-with-parsed-data
  927. "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
  928. (should
  929. (eq 'headline
  930. (org-element-type
  931. (org-export-resolve-fuzzy-link
  932. (org-element-map tree 'link 'identity info t) info)))))
  933. ;; 8. Return nil if no match.
  934. (org-test-with-parsed-data "[[target]]"
  935. (should-not
  936. (org-export-resolve-fuzzy-link
  937. (org-element-map tree 'link 'identity info t) info))))
  938. (ert-deftest test-org-export/resolve-id-link ()
  939. "Test `org-export-resolve-id-link' specifications."
  940. ;; 1. Regular test for custom-id link.
  941. (org-test-with-parsed-data "* Headline1
  942. :PROPERTIES:
  943. :CUSTOM-ID: test
  944. :END:
  945. * Headline 2
  946. \[[#test]]"
  947. (should
  948. (org-export-resolve-id-link
  949. (org-element-map tree 'link 'identity info t) info)))
  950. ;; 2. Failing test for custom-id link.
  951. (org-test-with-parsed-data "* Headline1
  952. :PROPERTIES:
  953. :CUSTOM-ID: test
  954. :END:
  955. * Headline 2
  956. \[[#no-match]]"
  957. (should-not
  958. (org-export-resolve-id-link
  959. (org-element-map tree 'link 'identity info t) info)))
  960. ;; 3. Test for internal id target.
  961. (org-test-with-parsed-data "* Headline1
  962. :PROPERTIES:
  963. :ID: aaaa
  964. :END:
  965. * Headline 2
  966. \[[id:aaaa]]"
  967. (should
  968. (org-export-resolve-id-link
  969. (org-element-map tree 'link 'identity info t) info)))
  970. ;; 4. Test for external id target.
  971. (org-test-with-parsed-data "[[id:aaaa]]"
  972. (should
  973. (org-export-resolve-id-link
  974. (org-element-map tree 'link 'identity info t)
  975. (org-combine-plists info '(:id-alist (("aaaa" . "external-file"))))))))
  976. (ert-deftest test-org-export/resolve-radio-link ()
  977. "Test `org-export-resolve-radio-link' specifications."
  978. ;; Standard test.
  979. (org-test-with-temp-text "<<<radio>>> radio"
  980. (org-update-radio-target-regexp)
  981. (should
  982. (let* ((tree (org-element-parse-buffer))
  983. (info `(:parse-tree ,tree)))
  984. (org-export-resolve-radio-link
  985. (org-element-map tree 'link 'identity info t)
  986. info))))
  987. ;; Radio target with objects.
  988. (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
  989. (org-update-radio-target-regexp)
  990. (should
  991. (let* ((tree (org-element-parse-buffer))
  992. (info `(:parse-tree ,tree)))
  993. (org-export-resolve-radio-link
  994. (org-element-map tree 'link 'identity info t)
  995. info)))))
  996. ;;; Src-block and example-block
  997. (ert-deftest test-org-export/unravel-code ()
  998. "Test `org-export-unravel-code' function."
  999. (let ((org-coderef-label-format "(ref:%s)"))
  1000. ;; 1. Code without reference.
  1001. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
  1002. (should (equal (org-export-unravel-code (org-element-at-point))
  1003. '("(+ 1 1)\n"))))
  1004. ;; 2. Code with reference.
  1005. (org-test-with-temp-text
  1006. "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
  1007. (should (equal (org-export-unravel-code (org-element-at-point))
  1008. '("(+ 1 1)\n" (1 . "test")))))
  1009. ;; 3. Code with user-defined reference.
  1010. (org-test-with-temp-text
  1011. "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
  1012. (should (equal (org-export-unravel-code (org-element-at-point))
  1013. '("(+ 1 1)\n" (1 . "test")))))
  1014. ;; 4. Code references keys are relative to the current block.
  1015. (org-test-with-temp-text "
  1016. #+BEGIN_EXAMPLE -n
  1017. \(+ 1 1)
  1018. #+END_EXAMPLE
  1019. #+BEGIN_EXAMPLE +n
  1020. \(+ 2 2)
  1021. \(+ 3 3) (ref:one)
  1022. #+END_EXAMPLE"
  1023. (goto-line 5)
  1024. (should (equal (org-export-unravel-code (org-element-at-point))
  1025. '("(+ 2 2)\n(+ 3 3)\n" (2 . "one")))))))
  1026. ;;; Tables
  1027. (ert-deftest test-org-export/special-column ()
  1028. "Test if the table's special column is properly recognized."
  1029. ;; 1. First column is special if it contains only a special marking
  1030. ;; characters or empty cells.
  1031. (org-test-with-temp-text "
  1032. | ! | 1 |
  1033. | | 2 |"
  1034. (should
  1035. (org-export-table-has-special-column-p
  1036. (org-element-map
  1037. (org-element-parse-buffer) 'table 'identity nil 'first-match))))
  1038. ;; 2. If the column contains anything else, it isn't special.
  1039. (org-test-with-temp-text "
  1040. | ! | 1 |
  1041. | b | 2 |"
  1042. (should-not
  1043. (org-export-table-has-special-column-p
  1044. (org-element-map
  1045. (org-element-parse-buffer) 'table 'identity nil 'first-match))))
  1046. ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
  1047. ;; and "!".
  1048. (org-test-with-temp-text "
  1049. | # | 1 |
  1050. | ^ | 2 |
  1051. | * | 3 |
  1052. | _ | 4 |
  1053. | / | 5 |
  1054. | $ | 6 |
  1055. | ! | 7 |"
  1056. (should
  1057. (org-export-table-has-special-column-p
  1058. (org-element-map
  1059. (org-element-parse-buffer) 'table 'identity nil 'first-match))))
  1060. ;; 4. A first column with only empty cells isn't considered as
  1061. ;; special.
  1062. (org-test-with-temp-text "
  1063. | | 1 |
  1064. | | 2 |"
  1065. (should-not
  1066. (org-export-table-has-special-column-p
  1067. (org-element-map
  1068. (org-element-parse-buffer) 'table 'identity nil 'first-match)))))
  1069. (ert-deftest test-org-export/table-row-is-special-p ()
  1070. "Test `org-export-table-row-is-special-p' specifications."
  1071. ;; 1. A row is special if it has a special marking character in the
  1072. ;; special column.
  1073. (org-test-with-parsed-data "| ! | 1 |"
  1074. (should
  1075. (org-export-table-row-is-special-p
  1076. (org-element-map tree 'table-row 'identity nil 'first-match) info)))
  1077. ;; 2. A row is special when its first field is "/"
  1078. (org-test-with-parsed-data "
  1079. | / | 1 |
  1080. | a | b |"
  1081. (should
  1082. (org-export-table-row-is-special-p
  1083. (org-element-map tree 'table-row 'identity nil 'first-match) info)))
  1084. ;; 3. A row only containing alignment cookies is also considered as
  1085. ;; special.
  1086. (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
  1087. (should
  1088. (org-export-table-row-is-special-p
  1089. (org-element-map tree 'table-row 'identity nil 'first-match) info)))
  1090. ;; 4. Everything else isn't considered as special.
  1091. (org-test-with-parsed-data "| \alpha | | c |"
  1092. (should-not
  1093. (org-export-table-row-is-special-p
  1094. (org-element-map tree 'table-row 'identity nil 'first-match) info)))
  1095. ;; 5. Table's rules are never considered as special rows.
  1096. (org-test-with-parsed-data "|---+---|"
  1097. (should-not
  1098. (org-export-table-row-is-special-p
  1099. (org-element-map tree 'table-row 'identity nil 'first-match) info))))
  1100. (ert-deftest test-org-export/has-header-p ()
  1101. "Test `org-export-table-has-header-p' specifications."
  1102. ;; 1. With an header.
  1103. (org-test-with-parsed-data "
  1104. | a | b |
  1105. |---+---|
  1106. | c | d |"
  1107. (should
  1108. (org-export-table-has-header-p
  1109. (org-element-map tree 'table 'identity info 'first-match)
  1110. info)))
  1111. ;; 2. Without an header.
  1112. (org-test-with-parsed-data "
  1113. | a | b |
  1114. | c | d |"
  1115. (should-not
  1116. (org-export-table-has-header-p
  1117. (org-element-map tree 'table 'identity info 'first-match)
  1118. info)))
  1119. ;; 3. Don't get fooled with starting and ending rules.
  1120. (org-test-with-parsed-data "
  1121. |---+---|
  1122. | a | b |
  1123. | c | d |
  1124. |---+---|"
  1125. (should-not
  1126. (org-export-table-has-header-p
  1127. (org-element-map tree 'table 'identity info 'first-match)
  1128. info))))
  1129. (ert-deftest test-org-export/table-row-group ()
  1130. "Test `org-export-table-row-group' specifications."
  1131. ;; 1. A rule creates a new group.
  1132. (org-test-with-parsed-data "
  1133. | a | b |
  1134. |---+---|
  1135. | 1 | 2 |"
  1136. (should
  1137. (equal
  1138. '(1 nil 2)
  1139. (mapcar (lambda (row) (org-export-table-row-group row info))
  1140. (org-element-map tree 'table-row 'identity)))))
  1141. ;; 2. Special rows are ignored in count.
  1142. (org-test-with-parsed-data "
  1143. | / | < | > |
  1144. |---|---+---|
  1145. | | 1 | 2 |"
  1146. (should
  1147. (equal
  1148. '(nil nil 1)
  1149. (mapcar (lambda (row) (org-export-table-row-group row info))
  1150. (org-element-map tree 'table-row 'identity)))))
  1151. ;; 3. Double rules also are ignored in count.
  1152. (org-test-with-parsed-data "
  1153. | a | b |
  1154. |---+---|
  1155. |---+---|
  1156. | 1 | 2 |"
  1157. (should
  1158. (equal
  1159. '(1 nil nil 2)
  1160. (mapcar (lambda (row) (org-export-table-row-group row info))
  1161. (org-element-map tree 'table-row 'identity))))))
  1162. (ert-deftest test-org-export/table-cell-width ()
  1163. "Test `org-export-table-cell-width' specifications."
  1164. ;; 1. Width is primarily determined by width cookies. If no cookie
  1165. ;; is found, cell's width is nil.
  1166. (org-test-with-parsed-data "
  1167. | / | <l> | <6> | <l7> |
  1168. | | a | b | c |"
  1169. (should
  1170. (equal
  1171. '(nil 6 7)
  1172. (mapcar (lambda (cell) (org-export-table-cell-width cell info))
  1173. (org-element-map tree 'table-cell 'identity info)))))
  1174. ;; 2. The last width cookie has precedence.
  1175. (org-test-with-parsed-data "
  1176. | <6> |
  1177. | <7> |
  1178. | a |"
  1179. (should
  1180. (equal
  1181. '(7)
  1182. (mapcar (lambda (cell) (org-export-table-cell-width cell info))
  1183. (org-element-map tree 'table-cell 'identity info)))))
  1184. ;; 3. Valid width cookies must have a specific row.
  1185. (org-test-with-parsed-data "| <6> | cell |"
  1186. (should
  1187. (equal
  1188. '(nil nil)
  1189. (mapcar (lambda (cell) (org-export-table-cell-width cell info))
  1190. (org-element-map tree 'table-cell 'identity))))))
  1191. (ert-deftest test-org-export/table-cell-alignment ()
  1192. "Test `org-export-table-cell-alignment' specifications."
  1193. (let ((org-table-number-fraction 0.5)
  1194. (org-table-number-regexp "^[0-9]+$"))
  1195. ;; 1. Alignment is primarily determined by alignment cookies.
  1196. (org-test-with-temp-text "| <l> | <c> | <r> |"
  1197. (let* ((tree (org-element-parse-buffer))
  1198. (info `(:parse-tree ,tree)))
  1199. (should
  1200. (equal
  1201. '(left center right)
  1202. (mapcar (lambda (cell) (org-export-table-cell-alignment cell info))
  1203. (org-element-map tree 'table-cell 'identity))))))
  1204. ;; 2. The last alignment cookie has precedence.
  1205. (org-test-with-parsed-data "
  1206. | <l8> |
  1207. | cell |
  1208. | <r9> |"
  1209. (should
  1210. (equal
  1211. '(right right right)
  1212. (mapcar (lambda (cell) (org-export-table-cell-alignment cell info))
  1213. (org-element-map tree 'table-cell 'identity)))))
  1214. ;; 3. If there's no cookie, cell's contents determine alignment.
  1215. ;; A column mostly made of cells containing numbers will align
  1216. ;; its cells to the right.
  1217. (org-test-with-parsed-data "
  1218. | 123 |
  1219. | some text |
  1220. | 12345 |"
  1221. (should
  1222. (equal
  1223. '(right right right)
  1224. (mapcar (lambda (cell)
  1225. (org-export-table-cell-alignment cell info))
  1226. (org-element-map tree 'table-cell 'identity)))))
  1227. ;; 4. Otherwise, they will be aligned to the left.
  1228. (org-test-with-parsed-data "
  1229. | text |
  1230. | some text |
  1231. | \alpha |"
  1232. (should
  1233. (equal
  1234. '(left left left)
  1235. (mapcar (lambda (cell)
  1236. (org-export-table-cell-alignment cell info))
  1237. (org-element-map tree 'table-cell 'identity)))))))
  1238. (ert-deftest test-org-export/table-cell-borders ()
  1239. "Test `org-export-table-cell-borders' specifications."
  1240. ;; 1. Recognize various column groups indicators.
  1241. (org-test-with-parsed-data "| / | < | > | <> |"
  1242. (should
  1243. (equal
  1244. '((right bottom top) (left bottom top) (right bottom top)
  1245. (right left bottom top))
  1246. (mapcar (lambda (cell)
  1247. (org-export-table-cell-borders cell info))
  1248. (org-element-map tree 'table-cell 'identity)))))
  1249. ;; 2. Accept shortcuts to define column groups.
  1250. (org-test-with-parsed-data "| / | < | < |"
  1251. (should
  1252. (equal
  1253. '((right bottom top) (right left bottom top) (left bottom top))
  1254. (mapcar (lambda (cell)
  1255. (org-export-table-cell-borders cell info))
  1256. (org-element-map tree 'table-cell 'identity)))))
  1257. ;; 3. A valid column groups row must start with a "/".
  1258. (org-test-with-parsed-data "
  1259. | | < |
  1260. | a | b |"
  1261. (should
  1262. (equal '((top) (top) (bottom) (bottom))
  1263. (mapcar (lambda (cell)
  1264. (org-export-table-cell-borders cell info))
  1265. (org-element-map tree 'table-cell 'identity)))))
  1266. ;; 4. Take table rules into consideration.
  1267. (org-test-with-parsed-data "
  1268. | 1 |
  1269. |---|
  1270. | 2 |"
  1271. (should
  1272. (equal '((below top) (bottom above))
  1273. (mapcar (lambda (cell)
  1274. (org-export-table-cell-borders cell info))
  1275. (org-element-map tree 'table-cell 'identity)))))
  1276. ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
  1277. ;; (resp. `bottom' and `below') borders. Any special row is
  1278. ;; ignored.
  1279. (org-test-with-parsed-data "
  1280. |---+----|
  1281. | / | |
  1282. | | 1 |
  1283. |---+----|"
  1284. (should
  1285. (equal '((bottom below top above))
  1286. (last
  1287. (mapcar (lambda (cell)
  1288. (org-export-table-cell-borders cell info))
  1289. (org-element-map tree 'table-cell 'identity)))))))
  1290. (ert-deftest test-org-export/table-dimensions ()
  1291. "Test `org-export-table-dimensions' specifications."
  1292. ;; 1. Standard test.
  1293. (org-test-with-parsed-data "
  1294. | 1 | 2 | 3 |
  1295. | 4 | 5 | 6 |"
  1296. (should
  1297. (equal '(2 . 3)
  1298. (org-export-table-dimensions
  1299. (org-element-map tree 'table 'identity info 'first-match) info))))
  1300. ;; 2. Ignore horizontal rules and special columns.
  1301. (org-test-with-parsed-data "
  1302. | / | < | > |
  1303. | 1 | 2 | 3 |
  1304. |---+---+---|
  1305. | 4 | 5 | 6 |"
  1306. (should
  1307. (equal '(2 . 3)
  1308. (org-export-table-dimensions
  1309. (org-element-map tree 'table 'identity info 'first-match) info)))))
  1310. (ert-deftest test-org-export/table-cell-address ()
  1311. "Test `org-export-table-cell-address' specifications."
  1312. ;; 1. Standard test: index is 0-based.
  1313. (org-test-with-parsed-data "| a | b |"
  1314. (should
  1315. (equal '((0 . 0) (0 . 1))
  1316. (org-element-map
  1317. tree 'table-cell
  1318. (lambda (cell) (org-export-table-cell-address cell info))
  1319. info))))
  1320. ;; 2. Special column isn't counted, nor are special rows.
  1321. (org-test-with-parsed-data "
  1322. | / | <> |
  1323. | | c |"
  1324. (should
  1325. (equal '(0 . 0)
  1326. (org-export-table-cell-address
  1327. (car (last (org-element-map tree 'table-cell 'identity info)))
  1328. info))))
  1329. ;; 3. Tables rules do not count either.
  1330. (org-test-with-parsed-data "
  1331. | a |
  1332. |---|
  1333. | b |
  1334. |---|
  1335. | c |"
  1336. (should
  1337. (equal '(2 . 0)
  1338. (org-export-table-cell-address
  1339. (car (last (org-element-map tree 'table-cell 'identity info)))
  1340. info))))
  1341. ;; 4. Return nil for special cells.
  1342. (org-test-with-parsed-data "| / | a |"
  1343. (should-not
  1344. (org-export-table-cell-address
  1345. (org-element-map tree 'table-cell 'identity nil 'first-match)
  1346. info))))
  1347. (ert-deftest test-org-export/get-table-cell-at ()
  1348. "Test `org-export-get-table-cell-at' specifications."
  1349. ;; 1. Address ignores special columns, special rows and rules.
  1350. (org-test-with-parsed-data "
  1351. | / | <> |
  1352. | | a |
  1353. |---+----|
  1354. | | b |"
  1355. (should
  1356. (equal '("b")
  1357. (org-element-contents
  1358. (org-export-get-table-cell-at
  1359. '(1 . 0)
  1360. (org-element-map tree 'table 'identity info 'first-match)
  1361. info)))))
  1362. ;; 2. Return value for a non-existent address is nil.
  1363. (org-test-with-parsed-data "| a |"
  1364. (should-not
  1365. (org-export-get-table-cell-at
  1366. '(2 . 2)
  1367. (org-element-map tree 'table 'identity info 'first-match)
  1368. info)))
  1369. (org-test-with-parsed-data "| / |"
  1370. (should-not
  1371. (org-export-get-table-cell-at
  1372. '(0 . 0)
  1373. (org-element-map tree 'table 'identity info 'first-match)
  1374. info))))
  1375. (ert-deftest test-org-export/table-cell-starts-colgroup-p ()
  1376. "Test `org-export-table-cell-starts-colgroup-p' specifications."
  1377. ;; 1. A cell at a beginning of a row always starts a column group.
  1378. (org-test-with-parsed-data "| a |"
  1379. (should
  1380. (org-export-table-cell-starts-colgroup-p
  1381. (org-element-map tree 'table-cell 'identity info 'first-match)
  1382. info)))
  1383. ;; 2. Special column should be ignored when determining the
  1384. ;; beginning of the row.
  1385. (org-test-with-parsed-data "
  1386. | / | |
  1387. | | a |"
  1388. (should
  1389. (org-export-table-cell-starts-colgroup-p
  1390. (org-element-map tree 'table-cell 'identity info 'first-match)
  1391. info)))
  1392. ;; 2. Explicit column groups.
  1393. (org-test-with-parsed-data "
  1394. | / | | < |
  1395. | a | b | c |"
  1396. (should
  1397. (equal
  1398. '(yes no yes)
  1399. (org-element-map
  1400. tree 'table-cell
  1401. (lambda (cell)
  1402. (if (org-export-table-cell-starts-colgroup-p cell info) 'yes 'no))
  1403. info)))))
  1404. (ert-deftest test-org-export/table-cell-ends-colgroup-p ()
  1405. "Test `org-export-table-cell-ends-colgroup-p' specifications."
  1406. ;; 1. A cell at the end of a row always ends a column group.
  1407. (org-test-with-parsed-data "| a |"
  1408. (should
  1409. (org-export-table-cell-ends-colgroup-p
  1410. (org-element-map tree 'table-cell 'identity info 'first-match)
  1411. info)))
  1412. ;; 2. Special column should be ignored when determining the
  1413. ;; beginning of the row.
  1414. (org-test-with-parsed-data "
  1415. | / | |
  1416. | | a |"
  1417. (should
  1418. (org-export-table-cell-ends-colgroup-p
  1419. (org-element-map tree 'table-cell 'identity info 'first-match)
  1420. info)))
  1421. ;; 3. Explicit column groups.
  1422. (org-test-with-parsed-data "
  1423. | / | < | |
  1424. | a | b | c |"
  1425. (should
  1426. (equal
  1427. '(yes no yes)
  1428. (org-element-map
  1429. tree 'table-cell
  1430. (lambda (cell)
  1431. (if (org-export-table-cell-ends-colgroup-p cell info) 'yes 'no))
  1432. info)))))
  1433. (ert-deftest test-org-export/table-row-starts-rowgroup-p ()
  1434. "Test `org-export-table-row-starts-rowgroup-p' specifications."
  1435. ;; 1. A row at the beginning of a table always starts a row group.
  1436. ;; So does a row following a table rule.
  1437. (org-test-with-parsed-data "
  1438. | a |
  1439. |---|
  1440. | b |"
  1441. (should
  1442. (equal
  1443. '(yes no yes)
  1444. (org-element-map
  1445. tree 'table-row
  1446. (lambda (row)
  1447. (if (org-export-table-row-starts-rowgroup-p row info) 'yes 'no))
  1448. info))))
  1449. ;; 2. Special rows should be ignored when determining the beginning
  1450. ;; of the row.
  1451. (org-test-with-parsed-data "
  1452. | / | < |
  1453. | | a |
  1454. |---+---|
  1455. | / | < |
  1456. | | b |"
  1457. (should
  1458. (equal
  1459. '(yes no yes)
  1460. (org-element-map
  1461. tree 'table-row
  1462. (lambda (row)
  1463. (if (org-export-table-row-starts-rowgroup-p row info) 'yes 'no))
  1464. info)))))
  1465. (ert-deftest test-org-export/table-row-ends-rowgroup-p ()
  1466. "Test `org-export-table-row-ends-rowgroup-p' specifications."
  1467. ;; 1. A row at the end of a table always ends a row group. So does
  1468. ;; a row preceding a table rule.
  1469. (org-test-with-parsed-data "
  1470. | a |
  1471. |---|
  1472. | b |"
  1473. (should
  1474. (equal
  1475. '(yes no yes)
  1476. (org-element-map
  1477. tree 'table-row
  1478. (lambda (row)
  1479. (if (org-export-table-row-ends-rowgroup-p row info) 'yes 'no))
  1480. info))))
  1481. ;; 2. Special rows should be ignored when determining the beginning
  1482. ;; of the row.
  1483. (org-test-with-parsed-data "
  1484. | | a |
  1485. | / | < |
  1486. |---+---|
  1487. | | b |
  1488. | / | < |"
  1489. (should
  1490. (equal
  1491. '(yes no yes)
  1492. (org-element-map
  1493. tree 'table-row
  1494. (lambda (row)
  1495. (if (org-export-table-row-ends-rowgroup-p row info) 'yes 'no))
  1496. info)))))
  1497. (ert-deftest test-org-export/table-row-starts-header-p ()
  1498. "Test `org-export-table-row-starts-header-p' specifications."
  1499. ;; 1. Only the row starting the first row group starts the table
  1500. ;; header.
  1501. (org-test-with-parsed-data "
  1502. | a |
  1503. | b |
  1504. |---|
  1505. | c |"
  1506. (should
  1507. (equal
  1508. '(yes no no no)
  1509. (org-element-map
  1510. tree 'table-row
  1511. (lambda (row)
  1512. (if (org-export-table-row-starts-header-p row info) 'yes 'no))
  1513. info))))
  1514. ;; 2. A row cannot start an header if there's no header in the
  1515. ;; table.
  1516. (org-test-with-parsed-data "
  1517. | a |
  1518. |---|"
  1519. (should-not
  1520. (org-export-table-row-starts-header-p
  1521. (org-element-map tree 'table-row 'identity info 'first-match)
  1522. info))))
  1523. (ert-deftest test-org-export/table-row-ends-header-p ()
  1524. "Test `org-export-table-row-ends-header-p' specifications."
  1525. ;; 1. Only the row starting the first row group starts the table
  1526. ;; header.
  1527. (org-test-with-parsed-data "
  1528. | a |
  1529. | b |
  1530. |---|
  1531. | c |"
  1532. (should
  1533. (equal
  1534. '(no yes no no)
  1535. (org-element-map
  1536. tree 'table-row
  1537. (lambda (row)
  1538. (if (org-export-table-row-ends-header-p row info) 'yes 'no))
  1539. info))))
  1540. ;; 2. A row cannot start an header if there's no header in the
  1541. ;; table.
  1542. (org-test-with-parsed-data "
  1543. | a |
  1544. |---|"
  1545. (should-not
  1546. (org-export-table-row-ends-header-p
  1547. (org-element-map tree 'table-row 'identity info 'first-match)
  1548. info))))
  1549. ;;; Topology
  1550. (ert-deftest test-org-export/get-next-element ()
  1551. "Test `org-export-get-next-element' specifications."
  1552. ;; Standard test.
  1553. (should
  1554. (equal "b"
  1555. (org-test-with-parsed-data "* Headline\n*a* b"
  1556. (org-export-get-next-element
  1557. (org-element-map tree 'bold 'identity info t) info))))
  1558. ;; Return nil when no previous element.
  1559. (should-not
  1560. (org-test-with-parsed-data "* Headline\na *b*"
  1561. (org-export-get-next-element
  1562. (org-element-map tree 'bold 'identity info t) info)))
  1563. ;; Non-exportable elements are ignored.
  1564. (should-not
  1565. (let ((org-export-with-timestamps nil))
  1566. (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
  1567. (org-export-get-next-element
  1568. (org-element-map tree 'entity 'identity info t) info)))))
  1569. (ert-deftest test-org-export/get-previous-element ()
  1570. "Test `org-export-get-previous-element' specifications."
  1571. ;; Standard test.
  1572. (should
  1573. (equal "a "
  1574. (org-test-with-parsed-data "* Headline\na *b*"
  1575. (org-export-get-previous-element
  1576. (org-element-map tree 'bold 'identity info t) info))))
  1577. ;; Return nil when no previous element.
  1578. (should-not
  1579. (org-test-with-parsed-data "* Headline\n*a* b"
  1580. (org-export-get-previous-element
  1581. (org-element-map tree 'bold 'identity info t) info)))
  1582. ;; Non-exportable elements are ignored.
  1583. (should-not
  1584. (let ((org-export-with-timestamps nil))
  1585. (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
  1586. (org-export-get-previous-element
  1587. (org-element-map tree 'entity 'identity info t) info)))))
  1588. (provide 'test-org-export)
  1589. ;;; test-org-export.el end here