test-org-export.el 54 KB

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