test-org-export.el 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724
  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/expand-macro ()
  405. "Test macro expansion in an Org buffer."
  406. ;; Standard macro expansion.
  407. (should
  408. (equal "#+MACRO: macro1 value\nvalue"
  409. (org-test-with-temp-text "#+MACRO: macro1 value\n{{{macro1}}}"
  410. (let (info)
  411. (org-export-expand-macro info) (buffer-string)))))
  412. ;; Export specific macros.
  413. (should
  414. (equal "me 2012-03-29 me@here Title"
  415. (org-test-with-temp-text
  416. "
  417. #+TITLE: Title
  418. #+DATE: 2012-03-29
  419. #+AUTHOR: me
  420. #+EMAIL: me@here
  421. {{{author}}} {{{date}}} {{{email}}} {{{title}}}"
  422. (let ((info (org-export-get-environment)))
  423. (org-export-expand-macro info)
  424. (goto-char (point-max))
  425. (buffer-substring (line-beginning-position)
  426. (line-end-position))))))
  427. ;; Expand macros with templates in included files.
  428. (should
  429. (equal "success"
  430. (org-test-with-temp-text
  431. (format "#+INCLUDE: \"%s/examples/macro-templates.org\"
  432. {{{included-macro}}}" org-test-dir)
  433. (let (info)
  434. (org-export-expand-include-keyword)
  435. (org-export-expand-macro info)
  436. (goto-char (point-max))
  437. (buffer-substring (line-beginning-position)
  438. (line-end-position)))))))
  439. (ert-deftest test-org-export/user-ignore-list ()
  440. "Test if `:ignore-list' accepts user input."
  441. (org-test-with-backend test
  442. (flet ((skip-note-head
  443. (data backend info)
  444. ;; Ignore headlines with the word "note" in their title.
  445. (org-element-map
  446. data 'headline
  447. (lambda (headline)
  448. (when (string-match "\\<note\\>"
  449. (org-element-property :raw-value headline))
  450. (org-export-ignore-element headline info)))
  451. info)
  452. data))
  453. ;; Install function in parse tree filters.
  454. (let ((org-export-filter-parse-tree-functions '(skip-note-head)))
  455. (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
  456. (should (equal (org-export-as 'test) "* Head1\n")))))))
  457. (ert-deftest test-org-export/before-parsing-hook ()
  458. "Test `org-export-before-parsing-hook'."
  459. (org-test-with-backend test
  460. (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
  461. (let ((org-export-before-parsing-hook
  462. '((lambda (backend)
  463. (org-map-entries
  464. (lambda ()
  465. (delete-region (point) (progn (forward-line) (point)))))))))
  466. (should (equal (org-export-as 'test) "Body 1\nBody 2\n"))))))
  467. ;;; Affiliated Keywords
  468. (ert-deftest test-org-export/read-attribute ()
  469. "Test `org-export-read-attribute' specifications."
  470. ;; Standard test.
  471. (should
  472. (equal
  473. (org-export-read-attribute
  474. :attr_html
  475. (org-test-with-temp-text "#+ATTR_HTML: :a 1 :b 2\nParagraph"
  476. (org-element-at-point)))
  477. '(:a 1 :b 2)))
  478. ;; Return nil on empty attribute.
  479. (should-not
  480. (org-export-read-attribute
  481. :attr_html
  482. (org-test-with-temp-text "Paragraph" (org-element-at-point)))))
  483. (ert-deftest test-org-export/get-caption ()
  484. "Test `org-export-get-caption' specifications."
  485. ;; Without optional argument, return long caption
  486. (should
  487. (equal
  488. '("l")
  489. (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
  490. (org-export-get-caption (org-element-at-point)))))
  491. ;; With optional argument, return short caption.
  492. (should
  493. (equal
  494. '("s")
  495. (org-test-with-temp-text "#+CAPTION[s]: l\nPara"
  496. (org-export-get-caption (org-element-at-point) t))))
  497. ;; Multiple lines are separated by white spaces.
  498. (should
  499. (equal
  500. '("a" " " "b")
  501. (org-test-with-temp-text "#+CAPTION: a\n#+CAPTION: b\nPara"
  502. (org-export-get-caption (org-element-at-point))))))
  503. ;;; Export Snippets
  504. (ert-deftest test-org-export/export-snippet ()
  505. "Test export snippets transcoding."
  506. (org-test-with-temp-text "@@test:A@@@@t:B@@"
  507. (org-test-with-backend test
  508. (let ((org-test-translate-alist
  509. (cons (cons 'export-snippet
  510. (lambda (snippet contents info)
  511. (when (eq (org-export-snippet-backend snippet) 'test)
  512. (org-element-property :value snippet))))
  513. org-test-translate-alist)))
  514. (let ((org-export-snippet-translation-alist nil))
  515. (should (equal (org-export-as 'test) "A\n")))
  516. (let ((org-export-snippet-translation-alist '(("t" . "test"))))
  517. (should (equal (org-export-as 'test) "AB\n")))))))
  518. ;;; Footnotes
  519. (ert-deftest test-org-export/footnotes ()
  520. "Test footnotes specifications."
  521. (let ((org-footnote-section nil)
  522. (org-export-with-footnotes t))
  523. ;; 1. Read every type of footnote.
  524. (should
  525. (equal
  526. '((1 . "A\n") (2 . "B") (3 . "C") (4 . "D"))
  527. (org-test-with-parsed-data
  528. "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
  529. (org-element-map
  530. tree 'footnote-reference
  531. (lambda (ref)
  532. (let ((def (org-export-get-footnote-definition ref info)))
  533. (cons (org-export-get-footnote-number ref info)
  534. (if (eq (org-element-property :type ref) 'inline) (car def)
  535. (car (org-element-contents
  536. (car (org-element-contents def))))))))
  537. info))))
  538. ;; 2. Test nested footnotes order.
  539. (org-test-with-parsed-data
  540. "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
  541. (should
  542. (equal
  543. '((1 . "fn:1") (2 . "fn:2") (3 . "fn:3") (4))
  544. (org-element-map
  545. tree 'footnote-reference
  546. (lambda (ref)
  547. (when (org-export-footnote-first-reference-p ref info)
  548. (cons (org-export-get-footnote-number ref info)
  549. (org-element-property :label ref))))
  550. info))))
  551. ;; 3. Test nested footnote in invisible definitions.
  552. (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
  553. ;; Hide definitions.
  554. (narrow-to-region (point) (point-at-eol))
  555. (let* ((tree (org-element-parse-buffer))
  556. (info (org-combine-plists
  557. `(:parse-tree ,tree)
  558. (org-export-collect-tree-properties
  559. tree (org-export-get-environment)))))
  560. ;; Both footnotes should be seen.
  561. (should
  562. (= (length (org-export-collect-footnote-definitions tree info)) 2))))
  563. ;; 4. Test footnotes definitions collection.
  564. (org-test-with-parsed-data "Text[fn:1:A[fn:2]] [fn:3].
  565. \[fn:2] B [fn:3] [fn::D].
  566. \[fn:3] C."
  567. (should (= (length (org-export-collect-footnote-definitions tree info))
  568. 4)))
  569. ;; 5. Test export of footnotes defined outside parsing scope.
  570. (org-test-with-temp-text "[fn:1] Out of scope
  571. * Title
  572. Paragraph[fn:1]"
  573. (org-test-with-backend test
  574. (let ((org-test-translate-alist
  575. (cons (cons 'footnote-reference
  576. (lambda (fn contents info)
  577. (org-element-interpret-data
  578. (org-export-get-footnote-definition fn info))))
  579. org-test-translate-alist)))
  580. (forward-line)
  581. (should (equal "ParagraphOut of scope\n"
  582. (org-export-as 'test 'subtree))))))))
  583. ;;; Headlines and Inlinetasks
  584. (ert-deftest test-org-export/get-relative-level ()
  585. "Test `org-export-get-relative-level' specifications."
  586. ;; Standard test.
  587. (should
  588. (equal '(1 2)
  589. (let ((org-odd-levels-only nil))
  590. (org-test-with-parsed-data "* Headline 1\n** Headline 2"
  591. (org-element-map
  592. tree 'headline
  593. (lambda (h) (org-export-get-relative-level h info))
  594. info)))))
  595. ;; Missing levels
  596. (should
  597. (equal '(1 3)
  598. (let ((org-odd-levels-only nil))
  599. (org-test-with-parsed-data "** Headline 1\n**** Headline 2"
  600. (org-element-map
  601. tree 'headline
  602. (lambda (h) (org-export-get-relative-level h info))
  603. info))))))
  604. (ert-deftest test-org-export/low-level-p ()
  605. "Test `org-export-low-level-p' specifications."
  606. (should
  607. (equal
  608. '(no yes)
  609. (let ((org-odd-levels-only nil))
  610. (org-test-with-parsed-data "* Headline 1\n** Headline 2"
  611. (org-element-map
  612. tree 'headline
  613. (lambda (h) (if (org-export-low-level-p h info) 'yes 'no))
  614. (plist-put info :headline-levels 1)))))))
  615. (ert-deftest test-org-export/get-headline-number ()
  616. "Test `org-export-get-headline-number' specifications."
  617. ;; Standard test.
  618. (should
  619. (equal
  620. '((1) (1 1))
  621. (let ((org-odd-levels-only nil))
  622. (org-test-with-parsed-data "* Headline 1\n** Headline 2"
  623. (org-element-map
  624. tree 'headline
  625. (lambda (h) (org-export-get-headline-number h info))
  626. info)))))
  627. ;; Missing levels are replaced with 0.
  628. (should
  629. (equal
  630. '((1) (1 0 1))
  631. (let ((org-odd-levels-only nil))
  632. (org-test-with-parsed-data "* Headline 1\n*** Headline 2"
  633. (org-element-map
  634. tree 'headline
  635. (lambda (h) (org-export-get-headline-number h info))
  636. info))))))
  637. (ert-deftest test-org-export/numbered-headline-p ()
  638. "Test `org-export-numbered-headline-p' specifications."
  639. ;; If `:section-numbers' is nil, never number headlines.
  640. (should-not
  641. (org-test-with-parsed-data "* Headline"
  642. (org-element-map
  643. tree 'headline
  644. (lambda (h) (org-export-numbered-headline-p h info))
  645. (plist-put info :section-numbers nil))))
  646. ;; If `:section-numbers' is a number, only number headlines with
  647. ;; a level greater that it.
  648. (should
  649. (equal
  650. '(yes no)
  651. (org-test-with-parsed-data "* Headline 1\n** Headline 2"
  652. (org-element-map
  653. tree 'headline
  654. (lambda (h) (if (org-export-numbered-headline-p h info) 'yes 'no))
  655. (plist-put info :section-numbers 1)))))
  656. ;; Otherwise, headlines are always numbered.
  657. (should
  658. (org-test-with-parsed-data "* Headline"
  659. (org-element-map
  660. tree 'headline
  661. (lambda (h) (org-export-numbered-headline-p h info))
  662. (plist-put info :section-numbers t)))))
  663. (ert-deftest test-org-export/number-to-roman ()
  664. "Test `org-export-number-to-roman' specifications."
  665. ;; If number is negative, return it as a string.
  666. (should (equal (org-export-number-to-roman -1) "-1"))
  667. ;; Otherwise, return it as a roman number.
  668. (should (equal (org-export-number-to-roman 1449) "MCDXLIX")))
  669. (ert-deftest test-org-export/get-tags ()
  670. "Test `org-export-get-tags' specifications."
  671. (let ((org-export-exclude-tags '("noexport"))
  672. (org-export-select-tags '("export")))
  673. ;; Standard test: tags which are not a select tag, an exclude tag,
  674. ;; or specified as optional argument shouldn't be ignored.
  675. (should
  676. (org-test-with-parsed-data "* Headline :tag:"
  677. (org-export-get-tags (org-element-map tree 'headline 'identity info t)
  678. info)))
  679. ;; Exclude tags are removed.
  680. (should-not
  681. (org-test-with-parsed-data "* Headline :noexport:"
  682. (org-export-get-tags (org-element-map tree 'headline 'identity info t)
  683. info)))
  684. ;; Select tags are removed.
  685. (should-not
  686. (org-test-with-parsed-data "* Headline :export:"
  687. (org-export-get-tags (org-element-map tree 'headline 'identity info t)
  688. info)))
  689. (should
  690. (equal
  691. '("tag")
  692. (org-test-with-parsed-data "* Headline :tag:export:"
  693. (org-export-get-tags (org-element-map tree 'headline 'identity info t)
  694. info))))
  695. ;; Tags provided in the optional argument are also ignored.
  696. (should-not
  697. (org-test-with-parsed-data "* Headline :ignore:"
  698. (org-export-get-tags (org-element-map tree 'headline 'identity info t)
  699. info '("ignore"))))))
  700. (ert-deftest test-org-export/get-node-property ()
  701. "Test`org-export-get-node-property' specifications."
  702. ;; Standard test.
  703. (should
  704. (equal "value"
  705. (org-test-with-parsed-data "* Headline
  706. :PROPERTIES:
  707. :prop: value
  708. :END:"
  709. (org-export-get-node-property
  710. :prop (org-element-map tree 'headline 'identity nil t)))))
  711. ;; Test inheritance.
  712. (should
  713. (equal "value"
  714. (org-test-with-parsed-data "* Parent
  715. :PROPERTIES:
  716. :prop: value
  717. :END:
  718. ** Headline
  719. Paragraph"
  720. (org-export-get-node-property
  721. :prop (org-element-map tree 'paragraph 'identity nil t) t))))
  722. ;; Cannot return a value before the first headline.
  723. (should-not
  724. (org-test-with-parsed-data "Paragraph
  725. * Headline
  726. :PROPERTIES:
  727. :prop: value
  728. :END:"
  729. (org-export-get-node-property
  730. :prop (org-element-map tree 'paragraph 'identity nil t)))))
  731. (ert-deftest test-org-export/first-sibling-p ()
  732. "Test `org-export-first-sibling-p' specifications."
  733. ;; Standard test.
  734. (should
  735. (equal
  736. '(yes yes no)
  737. (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
  738. (org-element-map
  739. tree 'headline
  740. (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
  741. info))))
  742. ;; Ignore headlines not exported.
  743. (should
  744. (equal
  745. '(yes)
  746. (let ((org-export-exclude-tags '("ignore")))
  747. (org-test-with-parsed-data "* Headline :ignore:\n* Headline 2"
  748. (org-element-map
  749. tree 'headline
  750. (lambda (h) (if (org-export-first-sibling-p h info) 'yes 'no))
  751. info))))))
  752. (ert-deftest test-org-export/last-sibling-p ()
  753. "Test `org-export-last-sibling-p' specifications."
  754. ;; Standard test.
  755. (should
  756. (equal
  757. '(yes no yes)
  758. (org-test-with-parsed-data "* Headline\n** Headline 2\n** Headline 3"
  759. (org-element-map
  760. tree 'headline
  761. (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
  762. info))))
  763. ;; Ignore headlines not exported.
  764. (should
  765. (equal
  766. '(yes)
  767. (let ((org-export-exclude-tags '("ignore")))
  768. (org-test-with-parsed-data "* Headline\n* Headline 2 :ignore:"
  769. (org-element-map
  770. tree 'headline
  771. (lambda (h) (if (org-export-last-sibling-p h info) 'yes 'no))
  772. info))))))
  773. ;;; Links
  774. (ert-deftest test-org-export/get-coderef-format ()
  775. "Test `org-export-get-coderef-format' specifications."
  776. ;; A link without description returns "%s"
  777. (should (equal (org-export-get-coderef-format "(ref:line)" nil)
  778. "%s"))
  779. ;; Return "%s" when path is matched within description.
  780. (should (equal (org-export-get-coderef-format "path" "desc (path)")
  781. "desc %s"))
  782. ;; Otherwise return description.
  783. (should (equal (org-export-get-coderef-format "path" "desc")
  784. "desc")))
  785. (ert-deftest test-org-export/inline-image-p ()
  786. "Test `org-export-inline-image-p' specifications."
  787. (should
  788. (org-export-inline-image-p
  789. (org-test-with-temp-text "[[#id]]"
  790. (org-element-map
  791. (org-element-parse-buffer) 'link 'identity nil t))
  792. '(("custom-id" . "id")))))
  793. (ert-deftest test-org-export/fuzzy-link ()
  794. "Test fuzzy links specifications."
  795. ;; 1. Links to invisible (keyword) targets should be ignored.
  796. (org-test-with-parsed-data
  797. "Paragraph.\n#+TARGET: Test\n[[Test]]"
  798. (should-not
  799. (org-element-map
  800. tree 'link
  801. (lambda (link)
  802. (org-export-get-ordinal
  803. (org-export-resolve-fuzzy-link link info) info)) info)))
  804. ;; 2. Link to an headline should return headline's number.
  805. (org-test-with-parsed-data
  806. "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
  807. (should
  808. ;; Note: Headline's number is in fact a list of numbers.
  809. (equal '(2)
  810. (org-element-map
  811. tree 'link
  812. (lambda (link)
  813. (org-export-get-ordinal
  814. (org-export-resolve-fuzzy-link link info) info)) info t))))
  815. ;; 3. Link to a target in an item should return item's number.
  816. (org-test-with-parsed-data
  817. "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
  818. (should
  819. ;; Note: Item's number is in fact a list of numbers.
  820. (equal '(1 2)
  821. (org-element-map
  822. tree 'link
  823. (lambda (link)
  824. (org-export-get-ordinal
  825. (org-export-resolve-fuzzy-link link info) info)) info t))))
  826. ;; 4. Link to a target in a footnote should return footnote's
  827. ;; number.
  828. (org-test-with-parsed-data "
  829. Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
  830. (should
  831. (equal '(2 3)
  832. (org-element-map
  833. tree 'link
  834. (lambda (link)
  835. (org-export-get-ordinal
  836. (org-export-resolve-fuzzy-link link info) info)) info))))
  837. ;; 5. Link to a named element should return sequence number of that
  838. ;; element.
  839. (org-test-with-parsed-data
  840. "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
  841. (should
  842. (= 2
  843. (org-element-map
  844. tree 'link
  845. (lambda (link)
  846. (org-export-get-ordinal
  847. (org-export-resolve-fuzzy-link link info) info)) info t))))
  848. ;; 6. Link to a target not within an item, a table, a footnote
  849. ;; reference or definition should return section number.
  850. (org-test-with-parsed-data
  851. "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
  852. (should
  853. (equal '(2)
  854. (org-element-map
  855. tree 'link
  856. (lambda (link)
  857. (org-export-get-ordinal
  858. (org-export-resolve-fuzzy-link link info) info)) info t)))))
  859. (ert-deftest test-org-export/resolve-coderef ()
  860. "Test `org-export-resolve-coderef' specifications."
  861. (let ((org-coderef-label-format "(ref:%s)"))
  862. ;; 1. A link to a "-n -k -r" block returns line number.
  863. (org-test-with-parsed-data
  864. "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
  865. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  866. (org-test-with-parsed-data
  867. "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  868. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  869. ;; 2. A link to a "-n -r" block returns line number.
  870. (org-test-with-parsed-data
  871. "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
  872. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  873. (org-test-with-parsed-data
  874. "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  875. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  876. ;; 3. A link to a "-n" block returns coderef.
  877. (org-test-with-parsed-data
  878. "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  879. (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
  880. (org-test-with-parsed-data
  881. "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
  882. (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
  883. ;; 4. A link to a "-r" block returns line number.
  884. (org-test-with-parsed-data
  885. "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  886. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  887. (org-test-with-parsed-data
  888. "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
  889. (should (= (org-export-resolve-coderef "coderef" info) 1)))
  890. ;; 5. A link to a block without a switch returns coderef.
  891. (org-test-with-parsed-data
  892. "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  893. (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
  894. (org-test-with-parsed-data
  895. "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
  896. (should (equal (org-export-resolve-coderef "coderef" info) "coderef")))
  897. ;; 6. Correctly handle continued line numbers. A "+n" switch
  898. ;; should resume numbering from previous block with numbered
  899. ;; lines, ignoring blocks not numbering lines in the process.
  900. ;; A "-n" switch resets count.
  901. (org-test-with-parsed-data "
  902. #+BEGIN_EXAMPLE -n
  903. Text.
  904. #+END_EXAMPLE
  905. #+BEGIN_SRC emacs-lisp
  906. \(- 1 1)
  907. #+END_SRC
  908. #+BEGIN_SRC emacs-lisp +n -r
  909. \(+ 1 1) (ref:addition)
  910. #+END_SRC
  911. #+BEGIN_EXAMPLE -n -r
  912. Another text. (ref:text)
  913. #+END_EXAMPLE"
  914. (should (= (org-export-resolve-coderef "addition" info) 2))
  915. (should (= (org-export-resolve-coderef "text" info) 1)))
  916. ;; 7. Recognize coderef with user-specified syntax.
  917. (org-test-with-parsed-data
  918. "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
  919. (should (equal (org-export-resolve-coderef "text" info) "text")))))
  920. (ert-deftest test-org-export/resolve-fuzzy-link ()
  921. "Test `org-export-resolve-fuzzy-link' specifications."
  922. ;; 1. Match target objects.
  923. (org-test-with-parsed-data "<<target>> [[target]]"
  924. (should
  925. (org-export-resolve-fuzzy-link
  926. (org-element-map tree 'link 'identity info t) info)))
  927. ;; 2. Match target elements.
  928. (org-test-with-parsed-data "#+TARGET: target\n[[target]]"
  929. (should
  930. (org-export-resolve-fuzzy-link
  931. (org-element-map tree 'link 'identity info t) info)))
  932. ;; 3. Match named elements.
  933. (org-test-with-parsed-data "#+NAME: target\nParagraph\n\n[[target]]"
  934. (should
  935. (org-export-resolve-fuzzy-link
  936. (org-element-map tree 'link 'identity info t) info)))
  937. ;; 4. Match exact headline's name.
  938. (org-test-with-parsed-data "* My headline\n[[My headline]]"
  939. (should
  940. (org-export-resolve-fuzzy-link
  941. (org-element-map tree 'link 'identity info t) info)))
  942. ;; 5. Targets objects have priority over named elements and headline
  943. ;; titles.
  944. (org-test-with-parsed-data
  945. "* target\n#+NAME: target\n<<target>>\n\n[[target]]"
  946. (should
  947. (eq 'target
  948. (org-element-type
  949. (org-export-resolve-fuzzy-link
  950. (org-element-map tree 'link 'identity info t) info)))))
  951. ;; 6. Named elements have priority over headline titles.
  952. (org-test-with-parsed-data
  953. "* target\n#+NAME: target\nParagraph\n\n[[target]]"
  954. (should
  955. (eq 'paragraph
  956. (org-element-type
  957. (org-export-resolve-fuzzy-link
  958. (org-element-map tree 'link 'identity info t) info)))))
  959. ;; 7. If link's path starts with a "*", only match headline titles,
  960. ;; though.
  961. (org-test-with-parsed-data
  962. "* target\n#+NAME: target\n<<target>>\n\n[[*target]]"
  963. (should
  964. (eq 'headline
  965. (org-element-type
  966. (org-export-resolve-fuzzy-link
  967. (org-element-map tree 'link 'identity info t) info)))))
  968. ;; 8. Return nil if no match.
  969. (org-test-with-parsed-data "[[target]]"
  970. (should-not
  971. (org-export-resolve-fuzzy-link
  972. (org-element-map tree 'link 'identity info t) info))))
  973. (ert-deftest test-org-export/resolve-id-link ()
  974. "Test `org-export-resolve-id-link' specifications."
  975. ;; 1. Regular test for custom-id link.
  976. (org-test-with-parsed-data "* Headline1
  977. :PROPERTIES:
  978. :CUSTOM-ID: test
  979. :END:
  980. * Headline 2
  981. \[[#test]]"
  982. (should
  983. (org-export-resolve-id-link
  984. (org-element-map tree 'link 'identity info t) info)))
  985. ;; 2. Failing test for custom-id link.
  986. (org-test-with-parsed-data "* Headline1
  987. :PROPERTIES:
  988. :CUSTOM-ID: test
  989. :END:
  990. * Headline 2
  991. \[[#no-match]]"
  992. (should-not
  993. (org-export-resolve-id-link
  994. (org-element-map tree 'link 'identity info t) info)))
  995. ;; 3. Test for internal id target.
  996. (org-test-with-parsed-data "* Headline1
  997. :PROPERTIES:
  998. :ID: aaaa
  999. :END:
  1000. * Headline 2
  1001. \[[id:aaaa]]"
  1002. (should
  1003. (org-export-resolve-id-link
  1004. (org-element-map tree 'link 'identity info t) info)))
  1005. ;; 4. Test for external id target.
  1006. (org-test-with-parsed-data "[[id:aaaa]]"
  1007. (should
  1008. (org-export-resolve-id-link
  1009. (org-element-map tree 'link 'identity info t)
  1010. (org-combine-plists info '(:id-alist (("aaaa" . "external-file"))))))))
  1011. (ert-deftest test-org-export/resolve-radio-link ()
  1012. "Test `org-export-resolve-radio-link' specifications."
  1013. ;; Standard test.
  1014. (org-test-with-temp-text "<<<radio>>> radio"
  1015. (org-update-radio-target-regexp)
  1016. (should
  1017. (let* ((tree (org-element-parse-buffer))
  1018. (info `(:parse-tree ,tree)))
  1019. (org-export-resolve-radio-link
  1020. (org-element-map tree 'link 'identity info t)
  1021. info))))
  1022. ;; Radio target with objects.
  1023. (org-test-with-temp-text "<<<radio \\alpha>>> radio \\alpha"
  1024. (org-update-radio-target-regexp)
  1025. (should
  1026. (let* ((tree (org-element-parse-buffer))
  1027. (info `(:parse-tree ,tree)))
  1028. (org-export-resolve-radio-link
  1029. (org-element-map tree 'link 'identity info t)
  1030. info)))))
  1031. ;;; Src-block and example-block
  1032. (ert-deftest test-org-export/unravel-code ()
  1033. "Test `org-export-unravel-code' function."
  1034. (let ((org-coderef-label-format "(ref:%s)"))
  1035. ;; 1. Code without reference.
  1036. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
  1037. (should (equal (org-export-unravel-code (org-element-at-point))
  1038. '("(+ 1 1)\n"))))
  1039. ;; 2. Code with reference.
  1040. (org-test-with-temp-text
  1041. "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
  1042. (should (equal (org-export-unravel-code (org-element-at-point))
  1043. '("(+ 1 1)\n" (1 . "test")))))
  1044. ;; 3. Code with user-defined reference.
  1045. (org-test-with-temp-text
  1046. "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
  1047. (should (equal (org-export-unravel-code (org-element-at-point))
  1048. '("(+ 1 1)\n" (1 . "test")))))
  1049. ;; 4. Code references keys are relative to the current block.
  1050. (org-test-with-temp-text "
  1051. #+BEGIN_EXAMPLE -n
  1052. \(+ 1 1)
  1053. #+END_EXAMPLE
  1054. #+BEGIN_EXAMPLE +n
  1055. \(+ 2 2)
  1056. \(+ 3 3) (ref:one)
  1057. #+END_EXAMPLE"
  1058. (goto-line 5)
  1059. (should (equal (org-export-unravel-code (org-element-at-point))
  1060. '("(+ 2 2)\n(+ 3 3)\n" (2 . "one")))))))
  1061. ;;; Tables
  1062. (ert-deftest test-org-export/special-column ()
  1063. "Test if the table's special column is properly recognized."
  1064. ;; 1. First column is special if it contains only a special marking
  1065. ;; characters or empty cells.
  1066. (org-test-with-temp-text "
  1067. | ! | 1 |
  1068. | | 2 |"
  1069. (should
  1070. (org-export-table-has-special-column-p
  1071. (org-element-map
  1072. (org-element-parse-buffer) 'table 'identity nil 'first-match))))
  1073. ;; 2. If the column contains anything else, it isn't special.
  1074. (org-test-with-temp-text "
  1075. | ! | 1 |
  1076. | b | 2 |"
  1077. (should-not
  1078. (org-export-table-has-special-column-p
  1079. (org-element-map
  1080. (org-element-parse-buffer) 'table 'identity nil 'first-match))))
  1081. ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
  1082. ;; and "!".
  1083. (org-test-with-temp-text "
  1084. | # | 1 |
  1085. | ^ | 2 |
  1086. | * | 3 |
  1087. | _ | 4 |
  1088. | / | 5 |
  1089. | $ | 6 |
  1090. | ! | 7 |"
  1091. (should
  1092. (org-export-table-has-special-column-p
  1093. (org-element-map
  1094. (org-element-parse-buffer) 'table 'identity nil 'first-match))))
  1095. ;; 4. A first column with only empty cells isn't considered as
  1096. ;; special.
  1097. (org-test-with-temp-text "
  1098. | | 1 |
  1099. | | 2 |"
  1100. (should-not
  1101. (org-export-table-has-special-column-p
  1102. (org-element-map
  1103. (org-element-parse-buffer) 'table 'identity nil 'first-match)))))
  1104. (ert-deftest test-org-export/table-row-is-special-p ()
  1105. "Test `org-export-table-row-is-special-p' specifications."
  1106. ;; 1. A row is special if it has a special marking character in the
  1107. ;; special column.
  1108. (org-test-with-parsed-data "| ! | 1 |"
  1109. (should
  1110. (org-export-table-row-is-special-p
  1111. (org-element-map tree 'table-row 'identity nil 'first-match) info)))
  1112. ;; 2. A row is special when its first field is "/"
  1113. (org-test-with-parsed-data "
  1114. | / | 1 |
  1115. | a | b |"
  1116. (should
  1117. (org-export-table-row-is-special-p
  1118. (org-element-map tree 'table-row 'identity nil 'first-match) info)))
  1119. ;; 3. A row only containing alignment cookies is also considered as
  1120. ;; special.
  1121. (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
  1122. (should
  1123. (org-export-table-row-is-special-p
  1124. (org-element-map tree 'table-row 'identity nil 'first-match) info)))
  1125. ;; 4. Everything else isn't considered as special.
  1126. (org-test-with-parsed-data "| \alpha | | c |"
  1127. (should-not
  1128. (org-export-table-row-is-special-p
  1129. (org-element-map tree 'table-row 'identity nil 'first-match) info)))
  1130. ;; 5. Table's rules are never considered as special rows.
  1131. (org-test-with-parsed-data "|---+---|"
  1132. (should-not
  1133. (org-export-table-row-is-special-p
  1134. (org-element-map tree 'table-row 'identity nil 'first-match) info))))
  1135. (ert-deftest test-org-export/has-header-p ()
  1136. "Test `org-export-table-has-header-p' specifications."
  1137. ;; 1. With an header.
  1138. (org-test-with-parsed-data "
  1139. | a | b |
  1140. |---+---|
  1141. | c | d |"
  1142. (should
  1143. (org-export-table-has-header-p
  1144. (org-element-map tree 'table 'identity info 'first-match)
  1145. info)))
  1146. ;; 2. Without an header.
  1147. (org-test-with-parsed-data "
  1148. | a | b |
  1149. | c | d |"
  1150. (should-not
  1151. (org-export-table-has-header-p
  1152. (org-element-map tree 'table 'identity info 'first-match)
  1153. info)))
  1154. ;; 3. Don't get fooled with starting and ending rules.
  1155. (org-test-with-parsed-data "
  1156. |---+---|
  1157. | a | b |
  1158. | c | d |
  1159. |---+---|"
  1160. (should-not
  1161. (org-export-table-has-header-p
  1162. (org-element-map tree 'table 'identity info 'first-match)
  1163. info))))
  1164. (ert-deftest test-org-export/table-row-group ()
  1165. "Test `org-export-table-row-group' specifications."
  1166. ;; 1. A rule creates a new group.
  1167. (org-test-with-parsed-data "
  1168. | a | b |
  1169. |---+---|
  1170. | 1 | 2 |"
  1171. (should
  1172. (equal
  1173. '(1 nil 2)
  1174. (mapcar (lambda (row) (org-export-table-row-group row info))
  1175. (org-element-map tree 'table-row 'identity)))))
  1176. ;; 2. Special rows are ignored in count.
  1177. (org-test-with-parsed-data "
  1178. | / | < | > |
  1179. |---|---+---|
  1180. | | 1 | 2 |"
  1181. (should
  1182. (equal
  1183. '(nil nil 1)
  1184. (mapcar (lambda (row) (org-export-table-row-group row info))
  1185. (org-element-map tree 'table-row 'identity)))))
  1186. ;; 3. Double rules also are ignored in count.
  1187. (org-test-with-parsed-data "
  1188. | a | b |
  1189. |---+---|
  1190. |---+---|
  1191. | 1 | 2 |"
  1192. (should
  1193. (equal
  1194. '(1 nil nil 2)
  1195. (mapcar (lambda (row) (org-export-table-row-group row info))
  1196. (org-element-map tree 'table-row 'identity))))))
  1197. (ert-deftest test-org-export/table-cell-width ()
  1198. "Test `org-export-table-cell-width' specifications."
  1199. ;; 1. Width is primarily determined by width cookies. If no cookie
  1200. ;; is found, cell's width is nil.
  1201. (org-test-with-parsed-data "
  1202. | / | <l> | <6> | <l7> |
  1203. | | a | b | c |"
  1204. (should
  1205. (equal
  1206. '(nil 6 7)
  1207. (mapcar (lambda (cell) (org-export-table-cell-width cell info))
  1208. (org-element-map tree 'table-cell 'identity info)))))
  1209. ;; 2. The last width cookie has precedence.
  1210. (org-test-with-parsed-data "
  1211. | <6> |
  1212. | <7> |
  1213. | a |"
  1214. (should
  1215. (equal
  1216. '(7)
  1217. (mapcar (lambda (cell) (org-export-table-cell-width cell info))
  1218. (org-element-map tree 'table-cell 'identity info)))))
  1219. ;; 3. Valid width cookies must have a specific row.
  1220. (org-test-with-parsed-data "| <6> | cell |"
  1221. (should
  1222. (equal
  1223. '(nil nil)
  1224. (mapcar (lambda (cell) (org-export-table-cell-width cell info))
  1225. (org-element-map tree 'table-cell 'identity))))))
  1226. (ert-deftest test-org-export/table-cell-alignment ()
  1227. "Test `org-export-table-cell-alignment' specifications."
  1228. (let ((org-table-number-fraction 0.5)
  1229. (org-table-number-regexp "^[0-9]+$"))
  1230. ;; 1. Alignment is primarily determined by alignment cookies.
  1231. (org-test-with-temp-text "| <l> | <c> | <r> |"
  1232. (let* ((tree (org-element-parse-buffer))
  1233. (info `(:parse-tree ,tree)))
  1234. (should
  1235. (equal
  1236. '(left center right)
  1237. (mapcar (lambda (cell) (org-export-table-cell-alignment cell info))
  1238. (org-element-map tree 'table-cell 'identity))))))
  1239. ;; 2. The last alignment cookie has precedence.
  1240. (org-test-with-parsed-data "
  1241. | <l8> |
  1242. | cell |
  1243. | <r9> |"
  1244. (should
  1245. (equal
  1246. '(right right right)
  1247. (mapcar (lambda (cell) (org-export-table-cell-alignment cell info))
  1248. (org-element-map tree 'table-cell 'identity)))))
  1249. ;; 3. If there's no cookie, cell's contents determine alignment.
  1250. ;; A column mostly made of cells containing numbers will align
  1251. ;; its cells to the right.
  1252. (org-test-with-parsed-data "
  1253. | 123 |
  1254. | some text |
  1255. | 12345 |"
  1256. (should
  1257. (equal
  1258. '(right right right)
  1259. (mapcar (lambda (cell)
  1260. (org-export-table-cell-alignment cell info))
  1261. (org-element-map tree 'table-cell 'identity)))))
  1262. ;; 4. Otherwise, they will be aligned to the left.
  1263. (org-test-with-parsed-data "
  1264. | text |
  1265. | some text |
  1266. | \alpha |"
  1267. (should
  1268. (equal
  1269. '(left left left)
  1270. (mapcar (lambda (cell)
  1271. (org-export-table-cell-alignment cell info))
  1272. (org-element-map tree 'table-cell 'identity)))))))
  1273. (ert-deftest test-org-export/table-cell-borders ()
  1274. "Test `org-export-table-cell-borders' specifications."
  1275. ;; 1. Recognize various column groups indicators.
  1276. (org-test-with-parsed-data "| / | < | > | <> |"
  1277. (should
  1278. (equal
  1279. '((right bottom top) (left bottom top) (right bottom top)
  1280. (right left bottom top))
  1281. (mapcar (lambda (cell)
  1282. (org-export-table-cell-borders cell info))
  1283. (org-element-map tree 'table-cell 'identity)))))
  1284. ;; 2. Accept shortcuts to define column groups.
  1285. (org-test-with-parsed-data "| / | < | < |"
  1286. (should
  1287. (equal
  1288. '((right bottom top) (right left bottom top) (left bottom top))
  1289. (mapcar (lambda (cell)
  1290. (org-export-table-cell-borders cell info))
  1291. (org-element-map tree 'table-cell 'identity)))))
  1292. ;; 3. A valid column groups row must start with a "/".
  1293. (org-test-with-parsed-data "
  1294. | | < |
  1295. | a | b |"
  1296. (should
  1297. (equal '((top) (top) (bottom) (bottom))
  1298. (mapcar (lambda (cell)
  1299. (org-export-table-cell-borders cell info))
  1300. (org-element-map tree 'table-cell 'identity)))))
  1301. ;; 4. Take table rules into consideration.
  1302. (org-test-with-parsed-data "
  1303. | 1 |
  1304. |---|
  1305. | 2 |"
  1306. (should
  1307. (equal '((below top) (bottom above))
  1308. (mapcar (lambda (cell)
  1309. (org-export-table-cell-borders cell info))
  1310. (org-element-map tree 'table-cell 'identity)))))
  1311. ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
  1312. ;; (resp. `bottom' and `below') borders. Any special row is
  1313. ;; ignored.
  1314. (org-test-with-parsed-data "
  1315. |---+----|
  1316. | / | |
  1317. | | 1 |
  1318. |---+----|"
  1319. (should
  1320. (equal '((bottom below top above))
  1321. (last
  1322. (mapcar (lambda (cell)
  1323. (org-export-table-cell-borders cell info))
  1324. (org-element-map tree 'table-cell 'identity)))))))
  1325. (ert-deftest test-org-export/table-dimensions ()
  1326. "Test `org-export-table-dimensions' specifications."
  1327. ;; 1. Standard test.
  1328. (org-test-with-parsed-data "
  1329. | 1 | 2 | 3 |
  1330. | 4 | 5 | 6 |"
  1331. (should
  1332. (equal '(2 . 3)
  1333. (org-export-table-dimensions
  1334. (org-element-map tree 'table 'identity info 'first-match) info))))
  1335. ;; 2. Ignore horizontal rules and special columns.
  1336. (org-test-with-parsed-data "
  1337. | / | < | > |
  1338. | 1 | 2 | 3 |
  1339. |---+---+---|
  1340. | 4 | 5 | 6 |"
  1341. (should
  1342. (equal '(2 . 3)
  1343. (org-export-table-dimensions
  1344. (org-element-map tree 'table 'identity info 'first-match) info)))))
  1345. (ert-deftest test-org-export/table-cell-address ()
  1346. "Test `org-export-table-cell-address' specifications."
  1347. ;; 1. Standard test: index is 0-based.
  1348. (org-test-with-parsed-data "| a | b |"
  1349. (should
  1350. (equal '((0 . 0) (0 . 1))
  1351. (org-element-map
  1352. tree 'table-cell
  1353. (lambda (cell) (org-export-table-cell-address cell info))
  1354. info))))
  1355. ;; 2. Special column isn't counted, nor are special rows.
  1356. (org-test-with-parsed-data "
  1357. | / | <> |
  1358. | | c |"
  1359. (should
  1360. (equal '(0 . 0)
  1361. (org-export-table-cell-address
  1362. (car (last (org-element-map tree 'table-cell 'identity info)))
  1363. info))))
  1364. ;; 3. Tables rules do not count either.
  1365. (org-test-with-parsed-data "
  1366. | a |
  1367. |---|
  1368. | b |
  1369. |---|
  1370. | c |"
  1371. (should
  1372. (equal '(2 . 0)
  1373. (org-export-table-cell-address
  1374. (car (last (org-element-map tree 'table-cell 'identity info)))
  1375. info))))
  1376. ;; 4. Return nil for special cells.
  1377. (org-test-with-parsed-data "| / | a |"
  1378. (should-not
  1379. (org-export-table-cell-address
  1380. (org-element-map tree 'table-cell 'identity nil 'first-match)
  1381. info))))
  1382. (ert-deftest test-org-export/get-table-cell-at ()
  1383. "Test `org-export-get-table-cell-at' specifications."
  1384. ;; 1. Address ignores special columns, special rows and rules.
  1385. (org-test-with-parsed-data "
  1386. | / | <> |
  1387. | | a |
  1388. |---+----|
  1389. | | b |"
  1390. (should
  1391. (equal '("b")
  1392. (org-element-contents
  1393. (org-export-get-table-cell-at
  1394. '(1 . 0)
  1395. (org-element-map tree 'table 'identity info 'first-match)
  1396. info)))))
  1397. ;; 2. Return value for a non-existent address is nil.
  1398. (org-test-with-parsed-data "| a |"
  1399. (should-not
  1400. (org-export-get-table-cell-at
  1401. '(2 . 2)
  1402. (org-element-map tree 'table 'identity info 'first-match)
  1403. info)))
  1404. (org-test-with-parsed-data "| / |"
  1405. (should-not
  1406. (org-export-get-table-cell-at
  1407. '(0 . 0)
  1408. (org-element-map tree 'table 'identity info 'first-match)
  1409. info))))
  1410. (ert-deftest test-org-export/table-cell-starts-colgroup-p ()
  1411. "Test `org-export-table-cell-starts-colgroup-p' specifications."
  1412. ;; 1. A cell at a beginning of a row always starts a column group.
  1413. (org-test-with-parsed-data "| a |"
  1414. (should
  1415. (org-export-table-cell-starts-colgroup-p
  1416. (org-element-map tree 'table-cell 'identity info 'first-match)
  1417. info)))
  1418. ;; 2. Special column should be ignored when determining the
  1419. ;; beginning of the row.
  1420. (org-test-with-parsed-data "
  1421. | / | |
  1422. | | a |"
  1423. (should
  1424. (org-export-table-cell-starts-colgroup-p
  1425. (org-element-map tree 'table-cell 'identity info 'first-match)
  1426. info)))
  1427. ;; 2. Explicit column groups.
  1428. (org-test-with-parsed-data "
  1429. | / | | < |
  1430. | a | b | c |"
  1431. (should
  1432. (equal
  1433. '(yes no yes)
  1434. (org-element-map
  1435. tree 'table-cell
  1436. (lambda (cell)
  1437. (if (org-export-table-cell-starts-colgroup-p cell info) 'yes 'no))
  1438. info)))))
  1439. (ert-deftest test-org-export/table-cell-ends-colgroup-p ()
  1440. "Test `org-export-table-cell-ends-colgroup-p' specifications."
  1441. ;; 1. A cell at the end of a row always ends a column group.
  1442. (org-test-with-parsed-data "| a |"
  1443. (should
  1444. (org-export-table-cell-ends-colgroup-p
  1445. (org-element-map tree 'table-cell 'identity info 'first-match)
  1446. info)))
  1447. ;; 2. Special column should be ignored when determining the
  1448. ;; beginning of the row.
  1449. (org-test-with-parsed-data "
  1450. | / | |
  1451. | | a |"
  1452. (should
  1453. (org-export-table-cell-ends-colgroup-p
  1454. (org-element-map tree 'table-cell 'identity info 'first-match)
  1455. info)))
  1456. ;; 3. Explicit column groups.
  1457. (org-test-with-parsed-data "
  1458. | / | < | |
  1459. | a | b | c |"
  1460. (should
  1461. (equal
  1462. '(yes no yes)
  1463. (org-element-map
  1464. tree 'table-cell
  1465. (lambda (cell)
  1466. (if (org-export-table-cell-ends-colgroup-p cell info) 'yes 'no))
  1467. info)))))
  1468. (ert-deftest test-org-export/table-row-starts-rowgroup-p ()
  1469. "Test `org-export-table-row-starts-rowgroup-p' specifications."
  1470. ;; 1. A row at the beginning of a table always starts a row group.
  1471. ;; So does a row following a table rule.
  1472. (org-test-with-parsed-data "
  1473. | a |
  1474. |---|
  1475. | b |"
  1476. (should
  1477. (equal
  1478. '(yes no yes)
  1479. (org-element-map
  1480. tree 'table-row
  1481. (lambda (row)
  1482. (if (org-export-table-row-starts-rowgroup-p row info) 'yes 'no))
  1483. info))))
  1484. ;; 2. Special rows should be ignored when determining the beginning
  1485. ;; of the row.
  1486. (org-test-with-parsed-data "
  1487. | / | < |
  1488. | | a |
  1489. |---+---|
  1490. | / | < |
  1491. | | b |"
  1492. (should
  1493. (equal
  1494. '(yes no yes)
  1495. (org-element-map
  1496. tree 'table-row
  1497. (lambda (row)
  1498. (if (org-export-table-row-starts-rowgroup-p row info) 'yes 'no))
  1499. info)))))
  1500. (ert-deftest test-org-export/table-row-ends-rowgroup-p ()
  1501. "Test `org-export-table-row-ends-rowgroup-p' specifications."
  1502. ;; 1. A row at the end of a table always ends a row group. So does
  1503. ;; a row preceding a table rule.
  1504. (org-test-with-parsed-data "
  1505. | a |
  1506. |---|
  1507. | b |"
  1508. (should
  1509. (equal
  1510. '(yes no yes)
  1511. (org-element-map
  1512. tree 'table-row
  1513. (lambda (row)
  1514. (if (org-export-table-row-ends-rowgroup-p row info) 'yes 'no))
  1515. info))))
  1516. ;; 2. Special rows should be ignored when determining the beginning
  1517. ;; of the row.
  1518. (org-test-with-parsed-data "
  1519. | | a |
  1520. | / | < |
  1521. |---+---|
  1522. | | b |
  1523. | / | < |"
  1524. (should
  1525. (equal
  1526. '(yes no yes)
  1527. (org-element-map
  1528. tree 'table-row
  1529. (lambda (row)
  1530. (if (org-export-table-row-ends-rowgroup-p row info) 'yes 'no))
  1531. info)))))
  1532. (ert-deftest test-org-export/table-row-starts-header-p ()
  1533. "Test `org-export-table-row-starts-header-p' specifications."
  1534. ;; 1. Only the row starting the first row group starts the table
  1535. ;; header.
  1536. (org-test-with-parsed-data "
  1537. | a |
  1538. | b |
  1539. |---|
  1540. | c |"
  1541. (should
  1542. (equal
  1543. '(yes no no no)
  1544. (org-element-map
  1545. tree 'table-row
  1546. (lambda (row)
  1547. (if (org-export-table-row-starts-header-p row info) 'yes 'no))
  1548. info))))
  1549. ;; 2. A row cannot start an header if there's no header in the
  1550. ;; table.
  1551. (org-test-with-parsed-data "
  1552. | a |
  1553. |---|"
  1554. (should-not
  1555. (org-export-table-row-starts-header-p
  1556. (org-element-map tree 'table-row 'identity info 'first-match)
  1557. info))))
  1558. (ert-deftest test-org-export/table-row-ends-header-p ()
  1559. "Test `org-export-table-row-ends-header-p' specifications."
  1560. ;; 1. Only the row starting the first row group starts the table
  1561. ;; header.
  1562. (org-test-with-parsed-data "
  1563. | a |
  1564. | b |
  1565. |---|
  1566. | c |"
  1567. (should
  1568. (equal
  1569. '(no yes no no)
  1570. (org-element-map
  1571. tree 'table-row
  1572. (lambda (row)
  1573. (if (org-export-table-row-ends-header-p row info) 'yes 'no))
  1574. info))))
  1575. ;; 2. A row cannot start an header if there's no header in the
  1576. ;; table.
  1577. (org-test-with-parsed-data "
  1578. | a |
  1579. |---|"
  1580. (should-not
  1581. (org-export-table-row-ends-header-p
  1582. (org-element-map tree 'table-row 'identity info 'first-match)
  1583. info))))
  1584. ;;; Topology
  1585. (ert-deftest test-org-export/get-next-element ()
  1586. "Test `org-export-get-next-element' specifications."
  1587. ;; Standard test.
  1588. (should
  1589. (equal "b"
  1590. (org-test-with-parsed-data "* Headline\n*a* b"
  1591. (org-export-get-next-element
  1592. (org-element-map tree 'bold 'identity info t) info))))
  1593. ;; Return nil when no previous element.
  1594. (should-not
  1595. (org-test-with-parsed-data "* Headline\na *b*"
  1596. (org-export-get-next-element
  1597. (org-element-map tree 'bold 'identity info t) info)))
  1598. ;; Non-exportable elements are ignored.
  1599. (should-not
  1600. (let ((org-export-with-timestamps nil))
  1601. (org-test-with-parsed-data "\alpha <2012-03-29 Thu>"
  1602. (org-export-get-next-element
  1603. (org-element-map tree 'entity 'identity info t) info)))))
  1604. (ert-deftest test-org-export/get-previous-element ()
  1605. "Test `org-export-get-previous-element' specifications."
  1606. ;; Standard test.
  1607. (should
  1608. (equal "a "
  1609. (org-test-with-parsed-data "* Headline\na *b*"
  1610. (org-export-get-previous-element
  1611. (org-element-map tree 'bold 'identity info t) info))))
  1612. ;; Return nil when no previous element.
  1613. (should-not
  1614. (org-test-with-parsed-data "* Headline\n*a* b"
  1615. (org-export-get-previous-element
  1616. (org-element-map tree 'bold 'identity info t) info)))
  1617. ;; Non-exportable elements are ignored.
  1618. (should-not
  1619. (let ((org-export-with-timestamps nil))
  1620. (org-test-with-parsed-data "<2012-03-29 Thu> \alpha"
  1621. (org-export-get-previous-element
  1622. (org-element-map tree 'entity 'identity info t) info)))))
  1623. (provide 'test-org-export)
  1624. ;;; test-org-export.el end here