test-org-export.el 58 KB

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