test-org-export.el 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231
  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. ;;; Tests
  11. (defmacro org-test-with-backend (backend &rest body)
  12. "Execute body with an export back-end defined.
  13. BACKEND is the name of the back-end. BODY is the body to
  14. execute. The defined back-end simply returns parsed data as Org
  15. syntax."
  16. (declare (debug (form body)) (indent 1))
  17. `(let ((,(intern (format "org-%s-translate-alist" backend))
  18. ',(let (transcode-table)
  19. (dolist (type (append org-element-all-elements
  20. org-element-all-objects)
  21. transcode-table)
  22. (push (cons type (intern (format "org-%s-%s" backend type)))
  23. transcode-table)))))
  24. (flet ,(let (transcoders)
  25. (dolist (type (append org-element-all-elements
  26. org-element-all-objects)
  27. transcoders)
  28. (push `(,(intern (format "org-%s-%s" backend type))
  29. (obj contents info)
  30. (,(intern (format "org-element-%s-interpreter" type))
  31. obj contents))
  32. transcoders)))
  33. ,@body)))
  34. (defmacro org-test-with-parsed-data (data &rest body)
  35. "Execute body with parsed data available.
  36. DATA is a string containing the data to be parsed. BODY is the
  37. body to execute. Parse tree is available under the `tree'
  38. variable, and communication channel under `info'.
  39. This function calls `org-export-collect-tree-properties'. As
  40. such, `:ignore-list' (for `org-element-map') and
  41. `:parse-tree' (for `org-export-get-genealogy') properties are
  42. already filled in `info'."
  43. (declare (debug (form body)) (indent 1))
  44. `(org-test-with-temp-text ,data
  45. (let* ((tree (org-element-parse-buffer))
  46. (info (org-export-collect-tree-properties tree nil)))
  47. ,@body)))
  48. (ert-deftest test-org-export/parse-option-keyword ()
  49. "Test reading all standard #+OPTIONS: items."
  50. (should
  51. (equal
  52. (org-export-parse-option-keyword
  53. "H:1 num:t \\n:t timestamp:t arch:t author:t creator:t d:t email:t
  54. *:t e:t ::t f:t pri:t -:t ^:t toc:t |:t tags:t tasks:t <:t todo:t")
  55. '(:headline-levels
  56. 1 :preserve-breaks t :section-numbers t :time-stamp-file t
  57. :with-archived-trees t :with-author t :with-creator t :with-drawers t
  58. :with-email t :with-emphasize t :with-entities t :with-fixed-width t
  59. :with-footnotes t :with-priority t :with-special-strings t
  60. :with-sub-superscript t :with-toc t :with-tables t :with-tags t
  61. :with-tasks t :with-timestamps t :with-todo-keywords t)))
  62. ;; Test some special values.
  63. (should
  64. (equal
  65. (org-export-parse-option-keyword
  66. "arch:headline creator:comment d:(\"TEST\")
  67. ^:{} toc:1 tags:not-in-toc tasks:todo num:2 <:active")
  68. '( :section-numbers
  69. 2
  70. :with-archived-trees headline :with-creator comment
  71. :with-drawers ("TEST") :with-sub-superscript {} :with-toc 1
  72. :with-tags not-in-toc :with-tasks todo :with-timestamps active))))
  73. (ert-deftest test-org-export/get-inbuffer-options ()
  74. "Test reading all standard export keywords."
  75. (should
  76. (equal
  77. (org-test-with-temp-text "#+AUTHOR: Me, Myself and I
  78. #+CREATOR: Idem
  79. #+DATE: Today
  80. #+DESCRIPTION: Testing
  81. #+DESCRIPTION: with two lines
  82. #+EMAIL: some@email.org
  83. #+EXPORT_EXCLUDE_TAGS: noexport invisible
  84. #+KEYWORDS: test
  85. #+LANGUAGE: en
  86. #+EXPORT_SELECT_TAGS: export
  87. #+TITLE: Some title
  88. #+TITLE: with spaces"
  89. (org-export-get-inbuffer-options))
  90. '(:author
  91. ("Me, Myself and I") :creator "Idem" :date "Today"
  92. :description "Testing\nwith two lines" :email "some@email.org"
  93. :exclude-tags ("noexport" "invisible") :keywords "test" :language "en"
  94. :select-tags ("export") :title ("Some title with spaces")))))
  95. (ert-deftest test-org-export/define-macro ()
  96. "Try defining various Org macro using in-buffer #+MACRO: keyword."
  97. ;; Parsed macro.
  98. (should (equal (org-test-with-temp-text "#+MACRO: one 1"
  99. (org-export-get-inbuffer-options))
  100. '(:macro-one ("1"))))
  101. ;; Evaled macro.
  102. (should (equal (org-test-with-temp-text "#+MACRO: two (eval (+ 1 1))"
  103. (org-export-get-inbuffer-options))
  104. '(:macro-two "(eval (+ 1 1))")))
  105. ;; Incomplete macro.
  106. (should-not (org-test-with-temp-text "#+MACRO: three"
  107. (org-export-get-inbuffer-options)))
  108. ;; Macro with newline character.
  109. (should (equal (org-test-with-temp-text "#+MACRO: four a\\nb"
  110. (org-export-get-inbuffer-options))
  111. '(:macro-four ("a\nb"))))
  112. ;; Macro with protected newline character.
  113. (should (equal (org-test-with-temp-text "#+MACRO: five a\\\\nb"
  114. (org-export-get-inbuffer-options))
  115. '(:macro-five ("a\\nb"))))
  116. ;; Recursive macro.
  117. (org-test-with-temp-text "#+MACRO: six 6\n#+MACRO: seven 1 + {{{six}}}"
  118. (should
  119. (equal
  120. (org-export-get-inbuffer-options)
  121. '(:macro-six
  122. ("6")
  123. :macro-seven
  124. ("1 + " (macro (:key "six" :value "{{{six}}}" :args nil :begin 5 :end 14
  125. :post-blank 0))))))))
  126. (ert-deftest test-org-export/handle-options ()
  127. "Test if export options have an impact on output."
  128. ;; Test exclude tags.
  129. (org-test-with-temp-text "* Head1 :noexport:"
  130. (org-test-with-backend test
  131. (should
  132. (equal (org-export-as 'test nil nil nil '(:exclude-tags ("noexport")))
  133. ""))))
  134. ;; Test include tags.
  135. (org-test-with-temp-text "
  136. * Head1
  137. ** Sub-Head1.1 :export:
  138. *** Sub-Head1.1.1
  139. * Head2"
  140. (org-test-with-backend test
  141. (should
  142. (string-match
  143. "\\* Head1\n\\*\\* Sub-Head1.1[ \t]+:export:\n\\*\\*\\* Sub-Head1.1.1\n"
  144. (org-export-as 'test nil nil nil '(:select-tags ("export")))))))
  145. ;; Test mixing include tags and exclude tags.
  146. (org-test-with-temp-text "
  147. * Head1 :export:
  148. ** Sub-Head1 :noexport:
  149. ** Sub-Head2
  150. * Head2 :noexport:
  151. ** Sub-Head1 :export:"
  152. (org-test-with-backend test
  153. (should
  154. (string-match
  155. "\\* Head1[ \t]+:export:\n\\*\\* Sub-Head2\n"
  156. (org-export-as
  157. 'test nil nil nil
  158. '(:select-tags ("export") :exclude-tags ("noexport")))))))
  159. ;; Ignore tasks.
  160. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  161. (org-test-with-temp-text "* TODO Head1"
  162. (org-test-with-backend test
  163. (should (equal (org-export-as 'test nil nil nil '(:with-tasks nil))
  164. "")))))
  165. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  166. (org-test-with-temp-text "* TODO Head1"
  167. (org-test-with-backend test
  168. (should (equal (org-export-as 'test nil nil nil '(:with-tasks t))
  169. "* TODO Head1\n")))))
  170. ;; Archived tree.
  171. (org-test-with-temp-text "* Head1 :archive:"
  172. (let ((org-archive-tag "archive"))
  173. (org-test-with-backend test
  174. (should
  175. (equal (org-export-as 'test nil nil nil '(:with-archived-trees nil))
  176. "")))))
  177. (org-test-with-temp-text "* Head1 :archive:\nbody\n** Sub-head 2"
  178. (let ((org-archive-tag "archive"))
  179. (org-test-with-backend test
  180. (should
  181. (string-match
  182. "\\* Head1[ \t]+:archive:"
  183. (org-export-as 'test nil nil nil
  184. '(:with-archived-trees headline)))))))
  185. (org-test-with-temp-text "* Head1 :archive:"
  186. (let ((org-archive-tag "archive"))
  187. (org-test-with-backend test
  188. (should
  189. (string-match
  190. "\\`\\* Head1[ \t]+:archive:\n\\'"
  191. (org-export-as 'test nil nil nil '(:with-archived-trees t)))))))
  192. ;; Drawers.
  193. (let ((org-drawers '("TEST")))
  194. (org-test-with-temp-text ":TEST:\ncontents\n:END:"
  195. (org-test-with-backend test
  196. (should (equal (org-export-as 'test nil nil nil '(:with-drawers nil))
  197. ""))
  198. (should (equal (org-export-as 'test nil nil nil '(:with-drawers t))
  199. ":TEST:\ncontents\n:END:\n")))))
  200. (let ((org-drawers '("FOO" "BAR")))
  201. (org-test-with-temp-text ":FOO:\nkeep\n:END:\n:BAR:\nremove\n:END:"
  202. (org-test-with-backend test
  203. (should
  204. (equal (org-export-as 'test nil nil nil '(:with-drawers ("FOO")))
  205. ":FOO:\nkeep\n:END:\n")))))
  206. ;; Timestamps.
  207. (org-test-with-temp-text "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>"
  208. (org-test-with-backend test
  209. (should
  210. (equal (org-export-as 'test nil nil nil '(:with-timestamps t))
  211. "[2012-04-29 sun. 10:45]<2012-04-29 sun. 10:45>\n"))
  212. (should
  213. (equal (org-export-as 'test nil nil nil '(:with-timestamps nil)) ""))
  214. (should
  215. (equal (org-export-as 'test nil nil nil '(:with-timestamps active))
  216. "<2012-04-29 sun. 10:45>\n"))
  217. (should
  218. (equal (org-export-as 'test nil nil nil '(:with-timestamps inactive))
  219. "[2012-04-29 sun. 10:45]\n"))))
  220. ;; Clocks.
  221. (let ((org-clock-string "CLOCK:"))
  222. (org-test-with-temp-text "CLOCK: [2012-04-29 sun. 10:45]"
  223. (org-test-with-backend test
  224. (should
  225. (equal (org-export-as 'test nil nil nil '(:with-clocks t))
  226. "CLOCK: [2012-04-29 sun. 10:45]\n"))
  227. (should
  228. (equal (org-export-as 'test nil nil nil '(:with-clocks nil)) "")))))
  229. ;; Plannings.
  230. (let ((org-closed-string "CLOSED:"))
  231. (org-test-with-temp-text "CLOSED: [2012-04-29 sun. 10:45]"
  232. (org-test-with-backend test
  233. (should
  234. (equal (org-export-as 'test nil nil nil '(:with-plannings t))
  235. "CLOSED: [2012-04-29 sun. 10:45]\n"))
  236. (should
  237. (equal (org-export-as 'test nil nil nil '(:with-plannings nil))
  238. ""))))))
  239. (ert-deftest test-org-export/comment-tree ()
  240. "Test if export process ignores commented trees."
  241. (let ((org-comment-string "COMMENT"))
  242. (org-test-with-temp-text "* COMMENT Head1"
  243. (org-test-with-backend test
  244. (should (equal (org-export-as 'test) ""))))))
  245. (ert-deftest test-org-export/export-scope ()
  246. "Test all export scopes."
  247. (org-test-with-temp-text "
  248. * Head1
  249. ** Head2
  250. text
  251. *** Head3"
  252. (org-test-with-backend test
  253. ;; Subtree.
  254. (forward-line 3)
  255. (should (equal (org-export-as 'test 'subtree) "text\n*** Head3\n"))
  256. ;; Visible.
  257. (goto-char (point-min))
  258. (forward-line)
  259. (org-cycle)
  260. (should (equal (org-export-as 'test nil 'visible) "* Head1\n"))
  261. ;; Body only.
  262. (flet ((org-test-template (body info) (format "BEGIN\n%sEND" body)))
  263. (should (equal (org-export-as 'test nil nil 'body-only)
  264. "* Head1\n** Head2\ntext\n*** Head3\n"))
  265. (should (equal (org-export-as 'test)
  266. "BEGIN\n* Head1\n** Head2\ntext\n*** Head3\nEND")))
  267. ;; Region.
  268. (goto-char (point-min))
  269. (forward-line 3)
  270. (transient-mark-mode 1)
  271. (push-mark (point) t t)
  272. (goto-char (point-at-eol))
  273. (should (equal (org-export-as 'test) "text\n"))))
  274. ;; Subtree with a code block calling another block outside.
  275. (org-test-with-temp-text "
  276. * Head1
  277. #+BEGIN_SRC emacs-lisp :noweb yes :exports results
  278. <<test>>
  279. #+END_SRC
  280. * Head2
  281. #+NAME: test
  282. #+BEGIN_SRC emacs-lisp
  283. \(+ 1 2)
  284. #+END_SRC"
  285. (org-test-with-backend test
  286. (forward-line 1)
  287. (should (equal (org-export-as 'test 'subtree) ": 3\n")))))
  288. (ert-deftest test-org-export/export-snippet ()
  289. "Test export snippets transcoding."
  290. (org-test-with-temp-text "<test@A><t@B>"
  291. (org-test-with-backend test
  292. (flet ((org-test-export-snippet
  293. (snippet contents info)
  294. (when (eq (org-export-snippet-backend snippet) 'test)
  295. (org-element-property :value snippet))))
  296. (let ((org-export-snippet-translation-alist nil))
  297. (should (equal (org-export-as 'test) "A\n")))
  298. (let ((org-export-snippet-translation-alist '(("t" . "test"))))
  299. (should (equal (org-export-as 'test) "AB\n")))))))
  300. (ert-deftest test-org-export/expand-include ()
  301. "Test file inclusion in an Org buffer."
  302. ;; Full insertion with recursive inclusion.
  303. (org-test-with-temp-text
  304. (format "#+INCLUDE: \"%s/examples/include.org\"" org-test-dir)
  305. (org-export-expand-include-keyword)
  306. (should (equal (buffer-string)
  307. "Small Org file with an include keyword.
  308. #+BEGIN_SRC emacs-lisp :exports results\n(+ 2 1)\n#+END_SRC
  309. Success!
  310. * Heading
  311. body\n")))
  312. ;; Localized insertion.
  313. (org-test-with-temp-text
  314. (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\""
  315. org-test-dir)
  316. (org-export-expand-include-keyword)
  317. (should (equal (buffer-string)
  318. "Small Org file with an include keyword.\n")))
  319. ;; Insertion with constraints on headlines level.
  320. (org-test-with-temp-text
  321. (format
  322. "* Top heading\n#+INCLUDE: \"%s/examples/include.org\" :lines \"9-\""
  323. org-test-dir)
  324. (org-export-expand-include-keyword)
  325. (should (equal (buffer-string) "* Top heading\n** Heading\nbody\n")))
  326. ;; Inclusion within an example block.
  327. (org-test-with-temp-text
  328. (format "#+INCLUDE: \"%s/examples/include.org\" :lines \"1-2\" example"
  329. org-test-dir)
  330. (org-export-expand-include-keyword)
  331. (should
  332. (equal
  333. (buffer-string)
  334. "#+BEGIN_EXAMPLE\nSmall Org file with an include keyword.\n#+END_EXAMPLE\n")))
  335. ;; Inclusion within a src-block.
  336. (org-test-with-temp-text
  337. (format
  338. "#+INCLUDE: \"%s/examples/include.org\" :lines \"4-5\" src emacs-lisp"
  339. org-test-dir)
  340. (org-export-expand-include-keyword)
  341. (should (equal (buffer-string)
  342. "#+BEGIN_SRC emacs-lisp\n(+ 2 1)\n#+END_SRC\n"))))
  343. (ert-deftest test-org-export/user-ignore-list ()
  344. "Test if `:ignore-list' accepts user input."
  345. (org-test-with-backend test
  346. (flet ((skip-note-head
  347. (data backend info)
  348. ;; Ignore headlines with the word "note" in their title.
  349. (org-element-map
  350. data 'headline
  351. (lambda (headline)
  352. (when (string-match "\\<note\\>"
  353. (org-element-property :raw-value headline))
  354. (org-export-ignore-element headline info)))
  355. info)
  356. data))
  357. ;; Install function in parse tree filters.
  358. (let ((org-export-filter-parse-tree-functions '(skip-note-head)))
  359. (org-test-with-temp-text "* Head1\n* Head2 (note)\n"
  360. (should (equal (org-export-as 'test) "* Head1\n")))))))
  361. (ert-deftest test-org-export/before-parsing-hook ()
  362. "Test `org-export-before-parsing-hook'."
  363. (org-test-with-backend test
  364. (org-test-with-temp-text "* Headline 1\nBody 1\n* Headline 2\nBody 2"
  365. (let ((org-export-before-parsing-hook
  366. '((lambda ()
  367. (org-map-entries
  368. (lambda ()
  369. (delete-region (point) (progn (forward-line) (point)))))))))
  370. (should (equal (org-export-as 'test) "Body 1\nBody 2\n"))))))
  371. ;;; Footnotes
  372. (ert-deftest test-org-export/footnotes ()
  373. "Test footnotes specifications."
  374. (let ((org-footnote-section nil))
  375. ;; 1. Read every type of footnote.
  376. (org-test-with-temp-text
  377. "Text[fn:1] [1] [fn:label:C] [fn::D]\n\n[fn:1] A\n\n[1] B"
  378. (let* ((tree (org-element-parse-buffer))
  379. (info (org-export-store-footnote-definitions
  380. `(:parse-tree ,tree :with-footnotes t))))
  381. (should
  382. (equal
  383. '((1 . "A") (2 . "B") (3 . "C") (4 . "D"))
  384. (org-element-map
  385. tree 'footnote-reference
  386. (lambda (ref)
  387. (let ((def (org-export-get-footnote-definition ref info)))
  388. (cons (org-export-get-footnote-number ref info)
  389. (if (eq (org-element-property :type ref) 'inline) (car def)
  390. (car (org-element-contents
  391. (car (org-element-contents def))))))))
  392. info)))))
  393. ;; 2. Test nested footnotes order.
  394. (org-test-with-temp-text
  395. "Text[fn:1:A[fn:2]] [fn:3].\n\n[fn:2] B [fn:3] [fn::D].\n\n[fn:3] C."
  396. (let* ((tree (org-element-parse-buffer))
  397. (info (org-export-store-footnote-definitions
  398. `(:parse-tree ,tree :with-footnotes t))))
  399. (should
  400. (equal
  401. '((1 . "fn:1") (2 . "fn:2") (3 . "fn:3") (4))
  402. (org-element-map
  403. tree 'footnote-reference
  404. (lambda (ref)
  405. (when (org-export-footnote-first-reference-p ref info)
  406. (cons (org-export-get-footnote-number ref info)
  407. (org-element-property :label ref))))
  408. info)))))
  409. ;; 3. Test nested footnote in invisible definitions.
  410. (org-test-with-temp-text "Text[1]\n\n[1] B [2]\n\n[2] C."
  411. ;; Hide definitions.
  412. (narrow-to-region (point) (point-at-eol))
  413. (let* ((tree (org-element-parse-buffer))
  414. (info (org-export-store-footnote-definitions
  415. `(:parse-tree ,tree :with-footnotes t))))
  416. ;; Both footnotes should be seen.
  417. (should
  418. (= (length (org-export-collect-footnote-definitions tree info)) 2))))
  419. ;; 4. Test footnotes definitions collection.
  420. (org-test-with-temp-text "Text[fn:1:A[fn:2]] [fn:3].
  421. \[fn:2] B [fn:3] [fn::D].
  422. \[fn:3] C."
  423. (let* ((tree (org-element-parse-buffer))
  424. (info (org-export-store-footnote-definitions
  425. `(:parse-tree ,tree :with-footnotes t))))
  426. (should (= (length (org-export-collect-footnote-definitions tree info))
  427. 4))))
  428. ;; 5. Test export of footnotes defined outside parsing scope.
  429. (org-test-with-temp-text "[fn:1] Out of scope
  430. * Title
  431. Paragraph[fn:1]"
  432. (org-test-with-backend test
  433. (flet ((org-test-footnote-reference
  434. (fn-ref contents info)
  435. (org-element-interpret-data
  436. (org-export-get-footnote-definition fn-ref info))))
  437. (forward-line)
  438. (should (equal "ParagraphOut of scope\n"
  439. (org-export-as 'test 'subtree))))))))
  440. ;;; Links
  441. (ert-deftest test-org-export/fuzzy-links ()
  442. "Test fuzzy link export specifications."
  443. ;; 1. Links to invisible (keyword) targets should be ignored.
  444. (org-test-with-parsed-data
  445. "Paragraph.\n#+TARGET: Test\n[[Test]]"
  446. (should-not
  447. (org-element-map
  448. tree 'link
  449. (lambda (link)
  450. (org-export-get-ordinal
  451. (org-export-resolve-fuzzy-link link info) info)) info)))
  452. ;; 2. Link to an headline should return headline's number.
  453. (org-test-with-parsed-data
  454. "Paragraph.\n* Head1\n* Head2\n* Head3\n[[Head2]]"
  455. (should
  456. ;; Note: Headline's number is in fact a list of numbers.
  457. (equal '(2)
  458. (org-element-map
  459. tree 'link
  460. (lambda (link)
  461. (org-export-get-ordinal
  462. (org-export-resolve-fuzzy-link link info) info)) info t))))
  463. ;; 3. Link to a target in an item should return item's number.
  464. (org-test-with-parsed-data
  465. "- Item1\n - Item11\n - <<test>>Item12\n- Item2\n\n\n[[test]]"
  466. (should
  467. ;; Note: Item's number is in fact a list of numbers.
  468. (equal '(1 2)
  469. (org-element-map
  470. tree 'link
  471. (lambda (link)
  472. (org-export-get-ordinal
  473. (org-export-resolve-fuzzy-link link info) info)) info t))))
  474. ;; 4. Link to a target in a footnote should return footnote's
  475. ;; number.
  476. (org-test-with-parsed-data "
  477. Paragraph[1][2][fn:lbl3:C<<target>>][[test]][[target]]\n[1] A\n\n[2] <<test>>B"
  478. (should
  479. (equal '(2 3)
  480. (org-element-map
  481. tree 'link
  482. (lambda (link)
  483. (org-export-get-ordinal
  484. (org-export-resolve-fuzzy-link link info) info)) info))))
  485. ;; 5. Link to a named element should return sequence number of that
  486. ;; element.
  487. (org-test-with-parsed-data
  488. "#+NAME: tbl1\n|1|2|\n#+NAME: tbl2\n|3|4|\n#+NAME: tbl3\n|5|6|\n[[tbl2]]"
  489. (should
  490. (= 2
  491. (org-element-map
  492. tree 'link
  493. (lambda (link)
  494. (org-export-get-ordinal
  495. (org-export-resolve-fuzzy-link link info) info)) info t))))
  496. ;; 6. Link to a target not within an item, a table, a footnote
  497. ;; reference or definition should return section number.
  498. (org-test-with-parsed-data
  499. "* Head1\n* Head2\nParagraph<<target>>\n* Head3\n[[target]]"
  500. (should
  501. (equal '(2)
  502. (org-element-map
  503. tree 'link
  504. (lambda (link)
  505. (org-export-get-ordinal
  506. (org-export-resolve-fuzzy-link link info) info)) info t)))))
  507. (defun test-org-export/resolve-coderef ()
  508. "Test `org-export-resolve-coderef' specifications."
  509. (let ((org-coderef-label-format "(ref:%s)"))
  510. ;; 1. A link to a "-n -k -r" block returns line number.
  511. (org-test-with-temp-text
  512. "#+BEGIN_EXAMPLE -n -k -r\nText (ref:coderef)\n#+END_EXAMPLE"
  513. (let ((tree (org-element-parse-buffer)))
  514. (should
  515. (= (org-export-resolve-coderef "coderef" `(:parse-tree ,tree)) 1))))
  516. (org-test-with-temp-text
  517. "#+BEGIN_SRC emacs-lisp -n -k -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  518. (let ((tree (org-element-parse-buffer)))
  519. (should
  520. (= (org-export-resolve-coderef "coderef" `(:parse-tree ,tree)) 1))))
  521. ;; 2. A link to a "-n -r" block returns line number.
  522. (org-test-with-temp-text
  523. "#+BEGIN_EXAMPLE -n -r\nText (ref:coderef)\n#+END_EXAMPLE"
  524. (let ((tree (org-element-parse-buffer)))
  525. (should
  526. (= (org-export-resolve-coderef "coderef" `(:parse-tree ,tree)) 1))))
  527. (org-test-with-temp-text
  528. "#+BEGIN_SRC emacs-lisp -n -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  529. (let ((tree (org-element-parse-buffer)))
  530. (should
  531. (= (org-export-resolve-coderef "coderef" `(:parse-tree ,tree)) 1))))
  532. ;; 3. A link to a "-n" block returns coderef.
  533. (org-test-with-temp-text
  534. "#+BEGIN_SRC emacs-lisp -n\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  535. (let ((tree (org-element-parse-buffer)))
  536. (should
  537. (equal (org-export-resolve-coderef "coderef" `(:parse-tree ,tree))
  538. "coderef"))))
  539. (org-test-with-temp-text
  540. "#+BEGIN_EXAMPLE -n\nText (ref:coderef)\n#+END_EXAMPLE"
  541. (let ((tree (org-element-parse-buffer)))
  542. (should
  543. (equal (org-export-resolve-coderef "coderef" `(:parse-tree ,tree))
  544. "coderef"))))
  545. ;; 4. A link to a "-r" block returns line number.
  546. (org-test-with-temp-text
  547. "#+BEGIN_SRC emacs-lisp -r\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  548. (let ((tree (org-element-parse-buffer)))
  549. (should
  550. (= (org-export-resolve-coderef "coderef" `(:parse-tree ,tree)) 1))))
  551. (org-test-with-temp-text
  552. "#+BEGIN_EXAMPLE -r\nText (ref:coderef)\n#+END_EXAMPLE"
  553. (let ((tree (org-element-parse-buffer)))
  554. (should
  555. (= (org-export-resolve-coderef "coderef" `(:parse-tree ,tree)) 1))))
  556. ;; 5. A link to a block without a switch returns coderef.
  557. (org-test-with-temp-text
  558. "#+BEGIN_SRC emacs-lisp\n(+ 1 1) (ref:coderef)\n#+END_SRC"
  559. (let ((tree (org-element-parse-buffer)))
  560. (should
  561. (equal (org-export-resolve-coderef "coderef" `(:parse-tree ,tree))
  562. "coderef"))))
  563. (org-test-with-temp-text
  564. "#+BEGIN_EXAMPLE\nText (ref:coderef)\n#+END_EXAMPLE"
  565. (let ((tree (org-element-parse-buffer)))
  566. (should
  567. (equal (org-export-resolve-coderef "coderef" `(:parse-tree ,tree))
  568. "coderef"))))
  569. ;; 6. Correctly handle continued line numbers. A "+n" switch
  570. ;; should resume numbering from previous block with numbered
  571. ;; lines, ignoring blocks not numbering lines in the process.
  572. ;; A "-n" switch resets count.
  573. (org-test-with-temp-text "
  574. #+BEGIN_EXAMPLE -n
  575. Text.
  576. #+END_EXAMPLE
  577. #+BEGIN_SRC emacs-lisp
  578. \(- 1 1)
  579. #+END_SRC
  580. #+BEGIN_SRC emacs-lisp +n -r
  581. \(+ 1 1) (ref:addition)
  582. #+END_SRC
  583. #+BEGIN_EXAMPLE -n -r
  584. Another text. (ref:text)
  585. #+END_EXAMPLE"
  586. (let* ((tree (org-element-parse-buffer))
  587. (info `(:parse-tree ,tree)))
  588. (should (= (org-export-resolve-coderef "addition" info) 2))
  589. (should (= (org-export-resolve-coderef "text" info) 1))))
  590. ;; 7. Recognize coderef with user-specified syntax.
  591. (org-test-with-temp-text
  592. "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\nText. [ref:text]\n#+END_EXAMPLE"
  593. (let ((tree (org-element-parse-buffer)))
  594. (should (equal (org-export-resolve-coderef "text" `(:parse-tree ,tree))
  595. "text"))))))
  596. ;;; Src-block and example-block
  597. (ert-deftest test-org-export/unravel-code ()
  598. "Test `org-export-unravel-code' function."
  599. (let ((org-coderef-label-format "(ref:%s)"))
  600. ;; 1. Code without reference.
  601. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
  602. (should (equal (org-export-unravel-code (org-element-current-element))
  603. '("(+ 1 1)\n"))))
  604. ;; 2. Code with reference.
  605. (org-test-with-temp-text
  606. "#+BEGIN_EXAMPLE\n(+ 1 1) (ref:test)\n#+END_EXAMPLE"
  607. (should (equal (org-export-unravel-code (org-element-current-element))
  608. '("(+ 1 1)\n" (1 . "test")))))
  609. ;; 3. Code with user-defined reference.
  610. (org-test-with-temp-text
  611. "#+BEGIN_EXAMPLE -l \"[ref:%s]\"\n(+ 1 1) [ref:test]\n#+END_EXAMPLE"
  612. (should (equal (org-export-unravel-code (org-element-current-element))
  613. '("(+ 1 1)\n" (1 . "test")))))
  614. ;; 4. Code references keys are relative to the current block.
  615. (org-test-with-temp-text "
  616. #+BEGIN_EXAMPLE -n
  617. \(+ 1 1)
  618. #+END_EXAMPLE
  619. #+BEGIN_EXAMPLE +n
  620. \(+ 2 2)
  621. \(+ 3 3) (ref:one)
  622. #+END_EXAMPLE"
  623. (goto-line 5)
  624. (should (equal (org-export-unravel-code (org-element-current-element))
  625. '("(+ 2 2)\n(+ 3 3)\n" (2 . "one")))))
  626. ;; 5. Free up comma-protected lines.
  627. ;;
  628. ;; 5.1. In an Org source block, every line is protected.
  629. (org-test-with-temp-text
  630. "#+BEGIN_SRC org\n,* Test\n,# comment\n,Text\n#+END_SRC"
  631. (should (equal (org-export-unravel-code (org-element-current-element))
  632. '("* Test\n# comment\nText\n"))))
  633. ;; 5.2. In other blocks, only headlines, comments and keywords are
  634. ;; protected.
  635. (org-test-with-temp-text
  636. "#+BEGIN_EXAMPLE\n,* Headline\n, * Not headline\n,Keep\n#+END_EXAMPLE"
  637. (should (equal (org-export-unravel-code (org-element-current-element))
  638. '("* Headline\n, * Not headline\n,Keep\n"))))))
  639. ;;; Tables
  640. (ert-deftest test-org-export/special-column ()
  641. "Test if the table's special column is properly recognized."
  642. ;; 1. First column is special if it contains only a special marking
  643. ;; characters or empty cells.
  644. (org-test-with-temp-text "
  645. | ! | 1 |
  646. | | 2 |"
  647. (should
  648. (org-export-table-has-special-column-p
  649. (org-element-map
  650. (org-element-parse-buffer) 'table 'identity nil 'first-match))))
  651. ;; 2. If the column contains anything else, it isn't special.
  652. (org-test-with-temp-text "
  653. | ! | 1 |
  654. | b | 2 |"
  655. (should-not
  656. (org-export-table-has-special-column-p
  657. (org-element-map
  658. (org-element-parse-buffer) 'table 'identity nil 'first-match))))
  659. ;; 3. Special marking characters are "#", "^", "*", "_", "/", "$"
  660. ;; and "!".
  661. (org-test-with-temp-text "
  662. | # | 1 |
  663. | ^ | 2 |
  664. | * | 3 |
  665. | _ | 4 |
  666. | / | 5 |
  667. | $ | 6 |
  668. | ! | 7 |"
  669. (should
  670. (org-export-table-has-special-column-p
  671. (org-element-map
  672. (org-element-parse-buffer) 'table 'identity nil 'first-match))))
  673. ;; 4. A first column with only empty cells isn't considered as
  674. ;; special.
  675. (org-test-with-temp-text "
  676. | | 1 |
  677. | | 2 |"
  678. (should-not
  679. (org-export-table-has-special-column-p
  680. (org-element-map
  681. (org-element-parse-buffer) 'table 'identity nil 'first-match)))))
  682. (ert-deftest test-org-export/table-row-is-special-p ()
  683. "Test `org-export-table-row-is-special-p' specifications."
  684. ;; 1. A row is special if it has a special marking character in the
  685. ;; special column.
  686. (org-test-with-parsed-data "| ! | 1 |"
  687. (should
  688. (org-export-table-row-is-special-p
  689. (org-element-map tree 'table-row 'identity nil 'first-match) info)))
  690. ;; 2. A row is special when its first field is "/"
  691. (org-test-with-parsed-data "
  692. | / | 1 |
  693. | a | b |"
  694. (should
  695. (org-export-table-row-is-special-p
  696. (org-element-map tree 'table-row 'identity nil 'first-match) info)))
  697. ;; 3. A row only containing alignment cookies is also considered as
  698. ;; special.
  699. (org-test-with-parsed-data "| <5> | | <l> | <l22> |"
  700. (should
  701. (org-export-table-row-is-special-p
  702. (org-element-map tree 'table-row 'identity nil 'first-match) info)))
  703. ;; 4. Everything else isn't considered as special.
  704. (org-test-with-parsed-data "| \alpha | | c |"
  705. (should-not
  706. (org-export-table-row-is-special-p
  707. (org-element-map tree 'table-row 'identity nil 'first-match) info)))
  708. ;; 5. Table's rules are never considered as special rows.
  709. (org-test-with-parsed-data "|---+---|"
  710. (should-not
  711. (org-export-table-row-is-special-p
  712. (org-element-map tree 'table-row 'identity nil 'first-match) info))))
  713. (ert-deftest test-org-export/has-header-p ()
  714. "Test `org-export-table-has-header-p' specifications."
  715. ;; 1. With an header.
  716. (org-test-with-parsed-data "
  717. | a | b |
  718. |---+---|
  719. | c | d |"
  720. (should
  721. (org-export-table-has-header-p
  722. (org-element-map tree 'table 'identity info 'first-match)
  723. info)))
  724. ;; 2. Without an header.
  725. (org-test-with-parsed-data "
  726. | a | b |
  727. | c | d |"
  728. (should-not
  729. (org-export-table-has-header-p
  730. (org-element-map tree 'table 'identity info 'first-match)
  731. info)))
  732. ;; 3. Don't get fooled with starting and ending rules.
  733. (org-test-with-parsed-data "
  734. |---+---|
  735. | a | b |
  736. | c | d |
  737. |---+---|"
  738. (should-not
  739. (org-export-table-has-header-p
  740. (org-element-map tree 'table 'identity info 'first-match)
  741. info))))
  742. (ert-deftest test-org-export/table-row-group ()
  743. "Test `org-export-table-row-group' specifications."
  744. ;; 1. A rule creates a new group.
  745. (org-test-with-parsed-data "
  746. | a | b |
  747. |---+---|
  748. | 1 | 2 |"
  749. (should
  750. (equal
  751. '(1 nil 2)
  752. (mapcar (lambda (row) (org-export-table-row-group row info))
  753. (org-element-map tree 'table-row 'identity)))))
  754. ;; 2. Special rows are ignored in count.
  755. (org-test-with-parsed-data "
  756. | / | < | > |
  757. |---|---+---|
  758. | | 1 | 2 |"
  759. (should
  760. (equal
  761. '(nil nil 1)
  762. (mapcar (lambda (row) (org-export-table-row-group row info))
  763. (org-element-map tree 'table-row 'identity)))))
  764. ;; 3. Double rules also are ignored in count.
  765. (org-test-with-parsed-data "
  766. | a | b |
  767. |---+---|
  768. |---+---|
  769. | 1 | 2 |"
  770. (should
  771. (equal
  772. '(1 nil nil 2)
  773. (mapcar (lambda (row) (org-export-table-row-group row info))
  774. (org-element-map tree 'table-row 'identity))))))
  775. (ert-deftest test-org-export/table-cell-width ()
  776. "Test `org-export-table-cell-width' specifications."
  777. ;; 1. Width is primarily determined by width cookies. If no cookie
  778. ;; is found, cell's width is nil.
  779. (org-test-with-parsed-data "
  780. | / | <l> | <6> | <l7> |
  781. | | a | b | c |"
  782. (should
  783. (equal
  784. '(nil 6 7)
  785. (mapcar (lambda (cell) (org-export-table-cell-width cell info))
  786. (org-element-map tree 'table-cell 'identity info)))))
  787. ;; 2. The last width cookie has precedence.
  788. (org-test-with-parsed-data "
  789. | <6> |
  790. | <7> |
  791. | a |"
  792. (should
  793. (equal
  794. '(7)
  795. (mapcar (lambda (cell) (org-export-table-cell-width cell info))
  796. (org-element-map tree 'table-cell 'identity info)))))
  797. ;; 3. Valid width cookies must have a specific row.
  798. (org-test-with-parsed-data "| <6> | cell |"
  799. (should
  800. (equal
  801. '(nil nil)
  802. (mapcar (lambda (cell) (org-export-table-cell-width cell info))
  803. (org-element-map tree 'table-cell 'identity))))))
  804. (ert-deftest test-org-export/table-cell-alignment ()
  805. "Test `org-export-table-cell-alignment' specifications."
  806. (let ((org-table-number-fraction 0.5)
  807. (org-table-number-regexp "^[0-9]+$"))
  808. ;; 1. Alignment is primarily determined by alignment cookies.
  809. (org-test-with-temp-text "| <l> | <c> | <r> |"
  810. (let* ((tree (org-element-parse-buffer))
  811. (info `(:parse-tree ,tree)))
  812. (should
  813. (equal
  814. '(left center right)
  815. (mapcar (lambda (cell) (org-export-table-cell-alignment cell info))
  816. (org-element-map tree 'table-cell 'identity))))))
  817. ;; 2. The last alignment cookie has precedence.
  818. (org-test-with-parsed-data "
  819. | <l8> |
  820. | cell |
  821. | <r9> |"
  822. (should
  823. (equal
  824. '(right right right)
  825. (mapcar (lambda (cell) (org-export-table-cell-alignment cell info))
  826. (org-element-map tree 'table-cell 'identity)))))
  827. ;; 3. If there's no cookie, cell's contents determine alignment.
  828. ;; A column mostly made of cells containing numbers will align
  829. ;; its cells to the right.
  830. (org-test-with-parsed-data "
  831. | 123 |
  832. | some text |
  833. | 12345 |"
  834. (should
  835. (equal
  836. '(right right right)
  837. (mapcar (lambda (cell)
  838. (org-export-table-cell-alignment cell info))
  839. (org-element-map tree 'table-cell 'identity)))))
  840. ;; 4. Otherwise, they will be aligned to the left.
  841. (org-test-with-parsed-data "
  842. | text |
  843. | some text |
  844. | \alpha |"
  845. (should
  846. (equal
  847. '(left left left)
  848. (mapcar (lambda (cell)
  849. (org-export-table-cell-alignment cell info))
  850. (org-element-map tree 'table-cell 'identity)))))))
  851. (ert-deftest test-org-export/table-cell-borders ()
  852. "Test `org-export-table-cell-borders' specifications."
  853. ;; 1. Recognize various column groups indicators.
  854. (org-test-with-parsed-data "| / | < | > | <> |"
  855. (should
  856. (equal
  857. '((right bottom top) (left bottom top) (right bottom top)
  858. (right left bottom top))
  859. (mapcar (lambda (cell)
  860. (org-export-table-cell-borders cell info))
  861. (org-element-map tree 'table-cell 'identity)))))
  862. ;; 2. Accept shortcuts to define column groups.
  863. (org-test-with-parsed-data "| / | < | < |"
  864. (should
  865. (equal
  866. '((right bottom top) (right left bottom top) (left bottom top))
  867. (mapcar (lambda (cell)
  868. (org-export-table-cell-borders cell info))
  869. (org-element-map tree 'table-cell 'identity)))))
  870. ;; 3. A valid column groups row must start with a "/".
  871. (org-test-with-parsed-data "
  872. | | < |
  873. | a | b |"
  874. (should
  875. (equal '((top) (top) (bottom) (bottom))
  876. (mapcar (lambda (cell)
  877. (org-export-table-cell-borders cell info))
  878. (org-element-map tree 'table-cell 'identity)))))
  879. ;; 4. Take table rules into consideration.
  880. (org-test-with-parsed-data "
  881. | 1 |
  882. |---|
  883. | 2 |"
  884. (should
  885. (equal '((below top) (bottom above))
  886. (mapcar (lambda (cell)
  887. (org-export-table-cell-borders cell info))
  888. (org-element-map tree 'table-cell 'identity)))))
  889. ;; 5. Top and (resp. bottom) rules induce both `top' and `above'
  890. ;; (resp. `bottom' and `below') borders. Any special row is
  891. ;; ignored.
  892. (org-test-with-parsed-data "
  893. |---+----|
  894. | / | |
  895. | | 1 |
  896. |---+----|"
  897. (should
  898. (equal '((bottom below top above))
  899. (last
  900. (mapcar (lambda (cell)
  901. (org-export-table-cell-borders cell info))
  902. (org-element-map tree 'table-cell 'identity)))))))
  903. (ert-deftest test-org-export/table-dimensions ()
  904. "Test `org-export-table-dimensions' specifications."
  905. ;; 1. Standard test.
  906. (org-test-with-parsed-data "
  907. | 1 | 2 | 3 |
  908. | 4 | 5 | 6 |"
  909. (should
  910. (equal '(2 . 3)
  911. (org-export-table-dimensions
  912. (org-element-map tree 'table 'identity info 'first-match) info))))
  913. ;; 2. Ignore horizontal rules and special columns.
  914. (org-test-with-parsed-data "
  915. | / | < | > |
  916. | 1 | 2 | 3 |
  917. |---+---+---|
  918. | 4 | 5 | 6 |"
  919. (should
  920. (equal '(2 . 3)
  921. (org-export-table-dimensions
  922. (org-element-map tree 'table 'identity info 'first-match) info)))))
  923. (ert-deftest test-org-export/table-cell-address ()
  924. "Test `org-export-table-cell-address' specifications."
  925. ;; 1. Standard test: index is 0-based.
  926. (org-test-with-parsed-data "| a | b |"
  927. (should
  928. (equal '((0 . 0) (0 . 1))
  929. (org-element-map
  930. tree 'table-cell
  931. (lambda (cell) (org-export-table-cell-address cell info))
  932. info))))
  933. ;; 2. Special column isn't counted, nor are special rows.
  934. (org-test-with-parsed-data "
  935. | / | <> |
  936. | | c |"
  937. (should
  938. (equal '(0 . 0)
  939. (org-export-table-cell-address
  940. (car (last (org-element-map tree 'table-cell 'identity info)))
  941. info))))
  942. ;; 3. Tables rules do not count either.
  943. (org-test-with-parsed-data "
  944. | a |
  945. |---|
  946. | b |
  947. |---|
  948. | c |"
  949. (should
  950. (equal '(2 . 0)
  951. (org-export-table-cell-address
  952. (car (last (org-element-map tree 'table-cell 'identity info)))
  953. info))))
  954. ;; 4. Return nil for special cells.
  955. (org-test-with-parsed-data "| / | a |"
  956. (should-not
  957. (org-export-table-cell-address
  958. (org-element-map tree 'table-cell 'identity nil 'first-match)
  959. info))))
  960. (ert-deftest test-org-export/get-table-cell-at ()
  961. "Test `org-export-get-table-cell-at' specifications."
  962. ;; 1. Address ignores special columns, special rows and rules.
  963. (org-test-with-parsed-data "
  964. | / | <> |
  965. | | a |
  966. |---+----|
  967. | | b |"
  968. (should
  969. (equal '("b")
  970. (org-element-contents
  971. (org-export-get-table-cell-at
  972. '(1 . 0)
  973. (org-element-map tree 'table 'identity info 'first-match)
  974. info)))))
  975. ;; 2. Return value for a non-existent address is nil.
  976. (org-test-with-parsed-data "| a |"
  977. (should-not
  978. (org-export-get-table-cell-at
  979. '(2 . 2)
  980. (org-element-map tree 'table 'identity info 'first-match)
  981. info)))
  982. (org-test-with-parsed-data "| / |"
  983. (should-not
  984. (org-export-get-table-cell-at
  985. '(0 . 0)
  986. (org-element-map tree 'table 'identity info 'first-match)
  987. info))))
  988. (ert-deftest test-org-export/table-cell-starts-colgroup-p ()
  989. "Test `org-export-table-cell-starts-colgroup-p' specifications."
  990. ;; 1. A cell at a beginning of a row always starts a column group.
  991. (org-test-with-parsed-data "| a |"
  992. (should
  993. (org-export-table-cell-starts-colgroup-p
  994. (org-element-map tree 'table-cell 'identity info 'first-match)
  995. info)))
  996. ;; 2. Special column should be ignored when determining the
  997. ;; beginning of the row.
  998. (org-test-with-parsed-data "
  999. | / | |
  1000. | | a |"
  1001. (should
  1002. (org-export-table-cell-starts-colgroup-p
  1003. (org-element-map tree 'table-cell 'identity info 'first-match)
  1004. info)))
  1005. ;; 2. Explicit column groups.
  1006. (org-test-with-parsed-data "
  1007. | / | | < |
  1008. | a | b | c |"
  1009. (should
  1010. (equal
  1011. '(yes no yes)
  1012. (org-element-map
  1013. tree 'table-cell
  1014. (lambda (cell)
  1015. (if (org-export-table-cell-starts-colgroup-p cell info) 'yes 'no))
  1016. info)))))
  1017. (ert-deftest test-org-export/table-cell-ends-colgroup-p ()
  1018. "Test `org-export-table-cell-ends-colgroup-p' specifications."
  1019. ;; 1. A cell at the end of a row always ends a column group.
  1020. (org-test-with-parsed-data "| a |"
  1021. (should
  1022. (org-export-table-cell-ends-colgroup-p
  1023. (org-element-map tree 'table-cell 'identity info 'first-match)
  1024. info)))
  1025. ;; 2. Special column should be ignored when determining the
  1026. ;; beginning of the row.
  1027. (org-test-with-parsed-data "
  1028. | / | |
  1029. | | a |"
  1030. (should
  1031. (org-export-table-cell-ends-colgroup-p
  1032. (org-element-map tree 'table-cell 'identity info 'first-match)
  1033. info)))
  1034. ;; 3. Explicit column groups.
  1035. (org-test-with-parsed-data "
  1036. | / | < | |
  1037. | a | b | c |"
  1038. (should
  1039. (equal
  1040. '(yes no yes)
  1041. (org-element-map
  1042. tree 'table-cell
  1043. (lambda (cell)
  1044. (if (org-export-table-cell-ends-colgroup-p cell info) 'yes 'no))
  1045. info)))))
  1046. (ert-deftest test-org-export/table-row-starts-rowgroup-p ()
  1047. "Test `org-export-table-row-starts-rowgroup-p' specifications."
  1048. ;; 1. A row at the beginning of a table always starts a row group.
  1049. ;; So does a row following a table rule.
  1050. (org-test-with-parsed-data "
  1051. | a |
  1052. |---|
  1053. | b |"
  1054. (should
  1055. (equal
  1056. '(yes no yes)
  1057. (org-element-map
  1058. tree 'table-row
  1059. (lambda (row)
  1060. (if (org-export-table-row-starts-rowgroup-p row info) 'yes 'no))
  1061. info))))
  1062. ;; 2. Special rows should be ignored when determining the beginning
  1063. ;; of the row.
  1064. (org-test-with-parsed-data "
  1065. | / | < |
  1066. | | a |
  1067. |---+---|
  1068. | / | < |
  1069. | | b |"
  1070. (should
  1071. (equal
  1072. '(yes no yes)
  1073. (org-element-map
  1074. tree 'table-row
  1075. (lambda (row)
  1076. (if (org-export-table-row-starts-rowgroup-p row info) 'yes 'no))
  1077. info)))))
  1078. (ert-deftest test-org-export/table-row-ends-rowgroup-p ()
  1079. "Test `org-export-table-row-ends-rowgroup-p' specifications."
  1080. ;; 1. A row at the end of a table always ends a row group. So does
  1081. ;; a row preceding a table rule.
  1082. (org-test-with-parsed-data "
  1083. | a |
  1084. |---|
  1085. | b |"
  1086. (should
  1087. (equal
  1088. '(yes no yes)
  1089. (org-element-map
  1090. tree 'table-row
  1091. (lambda (row)
  1092. (if (org-export-table-row-ends-rowgroup-p row info) 'yes 'no))
  1093. info))))
  1094. ;; 2. Special rows should be ignored when determining the beginning
  1095. ;; of the row.
  1096. (org-test-with-parsed-data "
  1097. | | a |
  1098. | / | < |
  1099. |---+---|
  1100. | | b |
  1101. | / | < |"
  1102. (should
  1103. (equal
  1104. '(yes no yes)
  1105. (org-element-map
  1106. tree 'table-row
  1107. (lambda (row)
  1108. (if (org-export-table-row-ends-rowgroup-p row info) 'yes 'no))
  1109. info)))))
  1110. (ert-deftest test-org-export/table-row-starts-header-p ()
  1111. "Test `org-export-table-row-starts-header-p' specifications."
  1112. ;; 1. Only the row starting the first row group starts the table
  1113. ;; header.
  1114. (org-test-with-parsed-data "
  1115. | a |
  1116. | b |
  1117. |---|
  1118. | c |"
  1119. (should
  1120. (equal
  1121. '(yes no no no)
  1122. (org-element-map
  1123. tree 'table-row
  1124. (lambda (row)
  1125. (if (org-export-table-row-starts-header-p row info) 'yes 'no))
  1126. info))))
  1127. ;; 2. A row cannot start an header if there's no header in the
  1128. ;; table.
  1129. (org-test-with-parsed-data "
  1130. | a |
  1131. |---|"
  1132. (should-not
  1133. (org-export-table-row-starts-header-p
  1134. (org-element-map tree 'table-row 'identity info 'first-match)
  1135. info))))
  1136. (ert-deftest test-org-export/table-row-ends-header-p ()
  1137. "Test `org-export-table-row-ends-header-p' specifications."
  1138. ;; 1. Only the row starting the first row group starts the table
  1139. ;; header.
  1140. (org-test-with-parsed-data "
  1141. | a |
  1142. | b |
  1143. |---|
  1144. | c |"
  1145. (should
  1146. (equal
  1147. '(no yes no no)
  1148. (org-element-map
  1149. tree 'table-row
  1150. (lambda (row)
  1151. (if (org-export-table-row-ends-header-p row info) 'yes 'no))
  1152. info))))
  1153. ;; 2. A row cannot start an header if there's no header in the
  1154. ;; table.
  1155. (org-test-with-parsed-data "
  1156. | a |
  1157. |---|"
  1158. (should-not
  1159. (org-export-table-row-ends-header-p
  1160. (org-element-map tree 'table-row 'identity info 'first-match)
  1161. info))))
  1162. (provide 'test-org-export)
  1163. ;;; test-org-export.el end here