test-org-export.el 58 KB

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