test-org-export.el 55 KB

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