test-org-export.el 54 KB

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