test-org.el 102 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196
  1. ;;; test-org.el --- tests for org.el
  2. ;; Copyright (c) David Maus
  3. ;; Authors: David Maus
  4. ;; This file is not part of GNU Emacs.
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Comments:
  16. ;; Template test file for Org-mode tests
  17. ;;; Code:
  18. ;;; Comments
  19. (ert-deftest test-org/toggle-comment ()
  20. "Test `org-toggle-comment' specifications."
  21. ;; Simple headline.
  22. (should
  23. (equal "* Test"
  24. (org-test-with-temp-text "* COMMENT Test"
  25. (org-toggle-comment)
  26. (buffer-string))))
  27. (should
  28. (equal "* COMMENT Test"
  29. (org-test-with-temp-text "* Test"
  30. (org-toggle-comment)
  31. (buffer-string))))
  32. ;; Headline with a regular keyword.
  33. (should
  34. (equal "* TODO Test"
  35. (org-test-with-temp-text "* TODO COMMENT Test"
  36. (org-toggle-comment)
  37. (buffer-string))))
  38. (should
  39. (equal "* TODO COMMENT Test"
  40. (org-test-with-temp-text "* TODO Test"
  41. (org-toggle-comment)
  42. (buffer-string))))
  43. ;; Empty headline.
  44. (should
  45. (equal "* "
  46. (org-test-with-temp-text "* COMMENT"
  47. (org-toggle-comment)
  48. (buffer-string))))
  49. (should
  50. (equal "* COMMENT"
  51. (org-test-with-temp-text "* "
  52. (org-toggle-comment)
  53. (buffer-string))))
  54. ;; Headline with a single keyword.
  55. (should
  56. (equal "* TODO "
  57. (org-test-with-temp-text "* TODO COMMENT"
  58. (org-toggle-comment)
  59. (buffer-string))))
  60. (should
  61. (equal "* TODO COMMENT"
  62. (org-test-with-temp-text "* TODO"
  63. (org-toggle-comment)
  64. (buffer-string))))
  65. ;; Headline with a keyword, a priority cookie and contents.
  66. (should
  67. (equal "* TODO [#A] Headline"
  68. (org-test-with-temp-text "* TODO [#A] COMMENT Headline"
  69. (org-toggle-comment)
  70. (buffer-string))))
  71. (should
  72. (equal "* TODO [#A] COMMENT Headline"
  73. (org-test-with-temp-text "* TODO [#A] Headline"
  74. (org-toggle-comment)
  75. (buffer-string)))))
  76. (ert-deftest test-org/comment-dwim ()
  77. "Test `comment-dwim' behaviour in an Org buffer."
  78. ;; No region selected, no comment on current line and line not
  79. ;; empty: insert comment on line above.
  80. (should
  81. (equal "# \nComment"
  82. (org-test-with-temp-text "Comment"
  83. (progn (call-interactively 'comment-dwim)
  84. (buffer-string)))))
  85. ;; No region selected, no comment on current line and line empty:
  86. ;; insert comment on this line.
  87. (should
  88. (equal "# \nParagraph"
  89. (org-test-with-temp-text "\nParagraph"
  90. (progn (call-interactively 'comment-dwim)
  91. (buffer-string)))))
  92. ;; No region selected, and a comment on this line: indent it.
  93. (should
  94. (equal "* Headline\n # Comment"
  95. (org-test-with-temp-text "* Headline\n# Comment"
  96. (progn (forward-line)
  97. (let ((org-adapt-indentation t))
  98. (call-interactively 'comment-dwim))
  99. (buffer-string)))))
  100. ;; Also recognize single # at column 0 as comments.
  101. (should
  102. (equal "# Comment"
  103. (org-test-with-temp-text "# Comment"
  104. (progn (forward-line)
  105. (call-interactively 'comment-dwim)
  106. (buffer-string)))))
  107. ;; Region selected and only comments and blank lines within it:
  108. ;; un-comment all commented lines.
  109. (should
  110. (equal "Comment 1\n\nComment 2"
  111. (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
  112. (progn
  113. (transient-mark-mode 1)
  114. (push-mark (point) t t)
  115. (goto-char (point-max))
  116. (call-interactively 'comment-dwim)
  117. (buffer-string)))))
  118. ;; Region selected without comments: comment all lines if
  119. ;; `comment-empty-lines' is non-nil, only non-blank lines otherwise.
  120. (should
  121. (equal "# Comment 1\n\n# Comment 2"
  122. (org-test-with-temp-text "Comment 1\n\nComment 2"
  123. (progn
  124. (transient-mark-mode 1)
  125. (push-mark (point) t t)
  126. (goto-char (point-max))
  127. (let ((comment-empty-lines nil))
  128. (call-interactively 'comment-dwim))
  129. (buffer-string)))))
  130. (should
  131. (equal "# Comment 1\n# \n# Comment 2"
  132. (org-test-with-temp-text "Comment 1\n\nComment 2"
  133. (progn
  134. (transient-mark-mode 1)
  135. (push-mark (point) t t)
  136. (goto-char (point-max))
  137. (let ((comment-empty-lines t))
  138. (call-interactively 'comment-dwim))
  139. (buffer-string)))))
  140. ;; In front of a keyword without region, insert a new comment.
  141. (should
  142. (equal "# \n#+KEYWORD: value"
  143. (org-test-with-temp-text "#+KEYWORD: value"
  144. (progn (call-interactively 'comment-dwim)
  145. (buffer-string)))))
  146. ;; In a source block, use appropriate syntax.
  147. (should
  148. (equal " ;; "
  149. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n\n#+END_SRC"
  150. (forward-line)
  151. (let ((org-edit-src-content-indentation 2))
  152. (call-interactively 'comment-dwim))
  153. (buffer-substring-no-properties (line-beginning-position) (point)))))
  154. (should
  155. (equal "#+BEGIN_SRC emacs-lisp\n ;; a\n ;; b\n#+END_SRC"
  156. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\na\nb\n#+END_SRC"
  157. (forward-line)
  158. (transient-mark-mode 1)
  159. (push-mark (point) t t)
  160. (forward-line 2)
  161. (let ((org-edit-src-content-indentation 2))
  162. (call-interactively 'comment-dwim))
  163. (buffer-string)))))
  164. ;;; Date and time analysis
  165. (ert-deftest test-org/org-read-date ()
  166. "Test `org-read-date' specifications."
  167. ;; Parse ISO date with abbreviated year and month.
  168. (should (equal "2012-03-29 16:40"
  169. (let ((org-time-was-given t))
  170. (org-read-date t nil "12-3-29 16:40"))))
  171. ;; Parse Europeans dates.
  172. (should (equal "2012-03-29 16:40"
  173. (let ((org-time-was-given t))
  174. (org-read-date t nil "29.03.2012 16:40"))))
  175. ;; Parse Europeans dates without year.
  176. (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
  177. (let ((org-time-was-given t))
  178. (org-read-date t nil "29.03. 16:40")))))
  179. (ert-deftest test-org/org-parse-time-string ()
  180. "Test `org-parse-time-string'."
  181. (should (equal (org-parse-time-string "2012-03-29 16:40")
  182. '(0 40 16 29 3 2012 nil nil nil)))
  183. (should (equal (org-parse-time-string "[2012-03-29 16:40]")
  184. '(0 40 16 29 3 2012 nil nil nil)))
  185. (should (equal (org-parse-time-string "<2012-03-29 16:40>")
  186. '(0 40 16 29 3 2012 nil nil nil)))
  187. (should (equal (org-parse-time-string "<2012-03-29>")
  188. '(0 0 0 29 3 2012 nil nil nil)))
  189. (should (equal (org-parse-time-string "<2012-03-29>" t)
  190. '(0 nil nil 29 3 2012 nil nil nil))))
  191. ;;; Drawers
  192. (ert-deftest test-org/insert-property-drawer ()
  193. "Test `org-insert-property-drawer' specifications."
  194. ;; Error before first headline.
  195. (should-error (org-test-with-temp-text "" (org-insert-property-drawer)))
  196. ;; Insert drawer right after headline if there is no planning line,
  197. ;; or after it otherwise.
  198. (should
  199. (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
  200. (org-test-with-temp-text "* H\nParagraph<point>"
  201. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  202. (buffer-string))))
  203. (should
  204. (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
  205. (org-test-with-temp-text
  206. "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
  207. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  208. (buffer-string))))
  209. ;; Indent inserted drawer.
  210. (should
  211. (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
  212. (org-test-with-temp-text "* H\nParagraph<point>"
  213. (let ((org-adapt-indentation t)) (org-insert-property-drawer))
  214. (buffer-string))))
  215. ;; Handle insertion at eob.
  216. (should
  217. (equal "* H\n:PROPERTIES:\n:END:\n"
  218. (org-test-with-temp-text "* H"
  219. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  220. (buffer-string))))
  221. ;; Skip inlinetasks before point.
  222. (when (featurep 'org-inlinetask)
  223. (should
  224. (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
  225. (org-test-with-temp-text
  226. "* H\n*************** I\n*************** END\nP<point>"
  227. (let ((org-adapt-indentation nil)
  228. (org-inlinetask-min-level 15))
  229. (org-insert-property-drawer))
  230. (buffer-string)))))
  231. ;; Correctly set drawer in an inlinetask.
  232. (when (featurep 'org-inlinetask)
  233. (should
  234. (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
  235. (org-test-with-temp-text
  236. "* H\n*************** I\nP<point>\n*************** END"
  237. (let ((org-adapt-indentation nil)
  238. (org-inlinetask-min-level 15))
  239. (org-insert-property-drawer))
  240. (buffer-string))))))
  241. ;;; Filling
  242. (ert-deftest test-org/fill-paragraph ()
  243. "Test `org-fill-paragraph' specifications."
  244. ;; At an Org table, align it.
  245. (should
  246. (equal "| a |\n"
  247. (org-test-with-temp-text "|a|"
  248. (org-fill-paragraph)
  249. (buffer-string))))
  250. (should
  251. (equal "#+name: table\n| a |\n"
  252. (org-test-with-temp-text "#+name: table\n| a |"
  253. (org-fill-paragraph)
  254. (buffer-string))))
  255. ;; At a paragraph, preserve line breaks.
  256. (org-test-with-temp-text "some \\\\\nlong\ntext"
  257. (let ((fill-column 20))
  258. (org-fill-paragraph)
  259. (should (equal (buffer-string) "some \\\\\nlong text"))))
  260. ;; Correctly fill a paragraph when point is at its very end.
  261. (should
  262. (equal "A B"
  263. (org-test-with-temp-text "A\nB"
  264. (let ((fill-column 20))
  265. (goto-char (point-max))
  266. (org-fill-paragraph)
  267. (buffer-string)))))
  268. ;; Correctly fill the last paragraph of a greater element.
  269. (should
  270. (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
  271. (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
  272. (let ((fill-column 8))
  273. (forward-line)
  274. (end-of-line)
  275. (org-fill-paragraph)
  276. (buffer-string)))))
  277. ;; Correctly fill an element in a narrowed buffer.
  278. (should
  279. (equal "01234\n6"
  280. (org-test-with-temp-text "01234 6789"
  281. (let ((fill-column 5))
  282. (narrow-to-region 1 8)
  283. (org-fill-paragraph)
  284. (buffer-string)))))
  285. ;; Handle `adaptive-fill-regexp' in paragraphs.
  286. (should
  287. (equal "> a b"
  288. (org-test-with-temp-text "> a\n> b"
  289. (let ((fill-column 5)
  290. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  291. (org-fill-paragraph)
  292. (buffer-string)))))
  293. ;; Special case: Fill first paragraph when point is at an item or
  294. ;; a plain-list or a footnote reference.
  295. (should
  296. (equal "- A B"
  297. (org-test-with-temp-text "- A\n B"
  298. (let ((fill-column 20))
  299. (org-fill-paragraph)
  300. (buffer-string)))))
  301. (should
  302. (equal "[fn:1] A B"
  303. (org-test-with-temp-text "[fn:1] A\nB"
  304. (let ((fill-column 20))
  305. (org-fill-paragraph)
  306. (buffer-string)))))
  307. (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
  308. (let ((fill-column 20))
  309. (org-fill-paragraph)
  310. (should (equal (buffer-string)
  311. "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
  312. ;; Fill contents of `comment-block' elements.
  313. (should
  314. (equal
  315. (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
  316. (let ((fill-column 20))
  317. (forward-line)
  318. (org-fill-paragraph)
  319. (buffer-string)))
  320. "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
  321. ;; Fill `comment' elements.
  322. (should
  323. (equal " # A B"
  324. (org-test-with-temp-text " # A\n # B"
  325. (let ((fill-column 20))
  326. (org-fill-paragraph)
  327. (buffer-string)))))
  328. ;; Do not mix consecutive comments when filling one of them.
  329. (should
  330. (equal "# A B\n\n# C"
  331. (org-test-with-temp-text "# A\n# B\n\n# C"
  332. (let ((fill-column 20))
  333. (org-fill-paragraph)
  334. (buffer-string)))))
  335. ;; Use commented empty lines as separators when filling comments.
  336. (should
  337. (equal "# A B\n#\n# C"
  338. (org-test-with-temp-text "# A\n# B\n#\n# C"
  339. (let ((fill-column 20))
  340. (org-fill-paragraph)
  341. (buffer-string)))))
  342. ;; Handle `adaptive-fill-regexp' in comments.
  343. (should
  344. (equal "# > a b"
  345. (org-test-with-temp-text "# > a\n# > b"
  346. (let ((fill-column 20)
  347. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  348. (org-fill-paragraph)
  349. (buffer-string)))))
  350. ;; Do nothing at affiliated keywords.
  351. (org-test-with-temp-text "#+NAME: para\nSome\ntext."
  352. (let ((fill-column 20))
  353. (org-fill-paragraph)
  354. (should (equal (buffer-string) "#+NAME: para\nSome\ntext."))))
  355. ;; Do not move point after table when filling a table.
  356. (should-not
  357. (org-test-with-temp-text "| a | b |\n| c | d |\n"
  358. (forward-char)
  359. (org-fill-paragraph)
  360. (eobp))))
  361. (ert-deftest test-org/auto-fill-function ()
  362. "Test auto-filling features."
  363. ;; Auto fill paragraph.
  364. (should
  365. (equal "12345\n7890"
  366. (org-test-with-temp-text "12345 7890"
  367. (let ((fill-column 5))
  368. (end-of-line)
  369. (org-auto-fill-function)
  370. (buffer-string)))))
  371. ;; Auto fill first paragraph in an item.
  372. (should
  373. (equal "- 12345\n 7890"
  374. (org-test-with-temp-text "- 12345 7890"
  375. (let ((fill-column 7))
  376. (end-of-line)
  377. (org-auto-fill-function)
  378. (buffer-string)))))
  379. ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
  380. (should
  381. (equal "> 12345\n 7890"
  382. (org-test-with-temp-text "> 12345 7890"
  383. (let ((fill-column 10)
  384. (adaptive-fill-regexp "[ \t]*>+[ \t]*")
  385. (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
  386. (end-of-line)
  387. (org-auto-fill-function)
  388. (buffer-string)))))
  389. (should
  390. (equal "> 12345\n> 12345\n> 7890"
  391. (org-test-with-temp-text "> 12345\n> 12345 7890"
  392. (let ((fill-column 10)
  393. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  394. (goto-char (point-max))
  395. (org-auto-fill-function)
  396. (buffer-string)))))
  397. (should-not
  398. (equal " 12345\n *12345\n *12345"
  399. (org-test-with-temp-text " 12345\n *12345 12345"
  400. (let ((fill-column 10)
  401. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  402. (goto-char (point-max))
  403. (org-auto-fill-function)
  404. (buffer-string)))))
  405. ;; Auto fill comments.
  406. (should
  407. (equal " # 12345\n # 7890"
  408. (org-test-with-temp-text " # 12345 7890"
  409. (let ((fill-column 10))
  410. (end-of-line)
  411. (org-auto-fill-function)
  412. (buffer-string)))))
  413. ;; A hash within a line isn't a comment.
  414. (should-not
  415. (equal "12345 # 7890\n# 1"
  416. (org-test-with-temp-text "12345 # 7890 1"
  417. (let ((fill-column 12))
  418. (end-of-line)
  419. (org-auto-fill-function)
  420. (buffer-string)))))
  421. ;; Correctly interpret empty prefix.
  422. (should-not
  423. (equal "# a\n# b\nRegular\n# paragraph"
  424. (org-test-with-temp-text "# a\n# b\nRegular paragraph"
  425. (let ((fill-column 12))
  426. (end-of-line 3)
  427. (org-auto-fill-function)
  428. (buffer-string)))))
  429. ;; Comment block: auto fill contents.
  430. (should
  431. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  432. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  433. (let ((fill-column 5))
  434. (forward-line)
  435. (end-of-line)
  436. (org-auto-fill-function)
  437. (buffer-string)))))
  438. (should
  439. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  440. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  441. (let ((fill-column 5))
  442. (forward-line)
  443. (end-of-line)
  444. (org-auto-fill-function)
  445. (buffer-string)))))
  446. ;; Do not fill if a new item could be created.
  447. (should-not
  448. (equal "12345\n- 90"
  449. (org-test-with-temp-text "12345 - 90"
  450. (let ((fill-column 5))
  451. (end-of-line)
  452. (org-auto-fill-function)
  453. (buffer-string)))))
  454. ;; Do not fill if a line break could be introduced.
  455. (should-not
  456. (equal "123\\\\\n7890"
  457. (org-test-with-temp-text "123\\\\ 7890"
  458. (let ((fill-column 6))
  459. (end-of-line)
  460. (org-auto-fill-function)
  461. (buffer-string)))))
  462. ;; Do not fill affiliated keywords.
  463. (should-not
  464. (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
  465. (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
  466. (let ((fill-column 20))
  467. (end-of-line)
  468. (org-auto-fill-function)
  469. (buffer-string))))))
  470. ;;; Indentation
  471. (ert-deftest test-org/indent-line ()
  472. "Test `org-indent-line' specifications."
  473. ;; Do not indent footnote definitions or headlines.
  474. (should
  475. (zerop
  476. (org-test-with-temp-text "* H"
  477. (org-indent-line)
  478. (org-get-indentation))))
  479. (should
  480. (zerop
  481. (org-test-with-temp-text "[fn:1] fn"
  482. (let ((org-adapt-indentation t)) (org-indent-line))
  483. (org-get-indentation))))
  484. ;; Do not indent before first headline.
  485. (should
  486. (zerop
  487. (org-test-with-temp-text ""
  488. (org-indent-line)
  489. (org-get-indentation))))
  490. ;; Indent according to headline level otherwise, unless
  491. ;; `org-adapt-indentation' is nil.
  492. (should
  493. (= 2
  494. (org-test-with-temp-text "* H\nA"
  495. (forward-line)
  496. (let ((org-adapt-indentation t)) (org-indent-line))
  497. (org-get-indentation))))
  498. (should
  499. (= 2
  500. (org-test-with-temp-text "* H\n\nA"
  501. (forward-line)
  502. (let ((org-adapt-indentation t)) (org-indent-line))
  503. (org-get-indentation))))
  504. (should
  505. (zerop
  506. (org-test-with-temp-text "* H\nA"
  507. (forward-line)
  508. (let ((org-adapt-indentation nil)) (org-indent-line))
  509. (org-get-indentation))))
  510. ;; Indenting preserves point position.
  511. (should
  512. (org-test-with-temp-text "* H\nAB"
  513. (forward-line)
  514. (forward-char)
  515. (let ((org-adapt-indentation t)) (org-indent-line))
  516. (looking-at "B")))
  517. ;; Do not change indentation at an item.
  518. (should
  519. (= 1
  520. (org-test-with-temp-text "* H\n - A"
  521. (forward-line)
  522. (let ((org-adapt-indentation t)) (org-indent-line))
  523. (org-get-indentation))))
  524. ;; On blank lines at the end of a list, indent like last element
  525. ;; within it if the line is still in the list. Otherwise, indent
  526. ;; like the whole list.
  527. (should
  528. (= 4
  529. (org-test-with-temp-text "* H\n- A\n - AA\n"
  530. (goto-char (point-max))
  531. (let ((org-adapt-indentation t)) (org-indent-line))
  532. (org-get-indentation))))
  533. (should
  534. (zerop
  535. (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n"
  536. (goto-char (point-max))
  537. (let ((org-adapt-indentation t)) (org-indent-line))
  538. (org-get-indentation))))
  539. ;; Likewise, on a blank line at the end of a footnote definition,
  540. ;; indent at column 0 if line belongs to the definition. Otherwise,
  541. ;; indent like the definition itself.
  542. (should
  543. (zerop
  544. (org-test-with-temp-text "* H\n[fn:1] Definition\n"
  545. (goto-char (point-max))
  546. (let ((org-adapt-indentation t)) (org-indent-line))
  547. (org-get-indentation))))
  548. (should
  549. (zerop
  550. (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n"
  551. (goto-char (point-max))
  552. (let ((org-adapt-indentation t)) (org-indent-line))
  553. (org-get-indentation))))
  554. ;; After the end of the contents of a greater element, indent like
  555. ;; the beginning of the element.
  556. (should
  557. (= 1
  558. (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
  559. (forward-line 2)
  560. (org-indent-line)
  561. (org-get-indentation))))
  562. ;; On blank lines after a paragraph, indent like its last non-empty
  563. ;; line.
  564. (should
  565. (= 1
  566. (org-test-with-temp-text " Paragraph\n\n<point>"
  567. (org-indent-line)
  568. (org-get-indentation))))
  569. ;; At the first line of an element, indent like previous element's
  570. ;; first line, ignoring footnotes definitions and inline tasks, or
  571. ;; according to parent.
  572. (should
  573. (= 2
  574. (org-test-with-temp-text "A\n\n B\n\nC"
  575. (goto-char (point-max))
  576. (org-indent-line)
  577. (org-get-indentation))))
  578. (should
  579. (= 1
  580. (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC"
  581. (goto-char (point-max))
  582. (org-indent-line)
  583. (org-get-indentation))))
  584. (should
  585. (= 1
  586. (org-test-with-temp-text " #+BEGIN_CENTER\n Contents\n#+END_CENTER"
  587. (forward-line 1)
  588. (org-indent-line)
  589. (org-get-indentation))))
  590. ;; Within code part of a source block, use language major mode if
  591. ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
  592. ;; according to line above.
  593. (should
  594. (= 6
  595. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  596. (forward-line 2)
  597. (let ((org-src-tab-acts-natively t)
  598. (org-edit-src-content-indentation 0))
  599. (org-indent-line))
  600. (org-get-indentation))))
  601. (should
  602. (= 1
  603. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  604. (forward-line 2)
  605. (let ((org-src-tab-acts-natively nil)
  606. (org-edit-src-content-indentation 0))
  607. (org-indent-line))
  608. (org-get-indentation))))
  609. ;; Otherwise, indent like the first non-blank line above.
  610. (should
  611. (zerop
  612. (org-test-with-temp-text "#+BEGIN_CENTER\nline1\n\n line2\n#+END_CENTER"
  613. (forward-line 3)
  614. (org-indent-line)
  615. (org-get-indentation))))
  616. ;; Align node properties according to `org-property-format'. Handle
  617. ;; nicely empty values.
  618. (should
  619. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  620. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
  621. (let ((org-property-format "%-10s %s")) (org-indent-line))
  622. (buffer-string))))
  623. (should
  624. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  625. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
  626. (let ((org-property-format "%-10s %s")) (org-indent-line))
  627. (buffer-string)))))
  628. (ert-deftest test-org/indent-region ()
  629. "Test `org-indent-region' specifications."
  630. ;; Indent paragraph.
  631. (should
  632. (equal "A\nB\nC"
  633. (org-test-with-temp-text " A\nB\n C"
  634. (org-indent-region (point-min) (point-max))
  635. (buffer-string))))
  636. ;; Indent greater elements along with their contents.
  637. (should
  638. (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
  639. (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
  640. (org-indent-region (point-min) (point-max))
  641. (buffer-string))))
  642. ;; Ignore contents of verse blocks and example blocks.
  643. (should
  644. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  645. (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  646. (org-indent-region (point-min) (point-max))
  647. (buffer-string))))
  648. (should
  649. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  650. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  651. (org-indent-region (point-min) (point-max))
  652. (buffer-string))))
  653. ;; Indent according to mode if `org-src-tab-acts-natively' is
  654. ;; non-nil. Otherwise, do not indent code at all.
  655. (should
  656. (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
  657. (org-test-with-temp-text
  658. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  659. (let ((org-src-tab-acts-natively t)
  660. (org-edit-src-content-indentation 0))
  661. (org-indent-region (point-min) (point-max)))
  662. (buffer-string))))
  663. (should
  664. (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  665. (org-test-with-temp-text
  666. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  667. (let ((org-src-tab-acts-natively nil)
  668. (org-edit-src-content-indentation 0))
  669. (org-indent-region (point-min) (point-max)))
  670. (buffer-string))))
  671. ;; Align node properties according to `org-property-format'. Handle
  672. ;; nicely empty values.
  673. (should
  674. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  675. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
  676. (let ((org-property-format "%-10s %s")
  677. (org-adapt-indentation nil))
  678. (org-indent-region (point) (point-max)))
  679. (buffer-string))))
  680. (should
  681. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  682. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
  683. (let ((org-property-format "%-10s %s")
  684. (org-adapt-indentation nil))
  685. (org-indent-region (point) (point-max)))
  686. (buffer-string))))
  687. ;; Indent plain lists.
  688. (should
  689. (equal "- A\n B\n - C\n\n D"
  690. (org-test-with-temp-text "- A\n B\n - C\n\n D"
  691. (org-indent-region (point-min) (point-max))
  692. (buffer-string))))
  693. (should
  694. (equal "- A\n\n- B"
  695. (org-test-with-temp-text " - A\n\n - B"
  696. (org-indent-region (point-min) (point-max))
  697. (buffer-string))))
  698. ;; Indent footnote definitions.
  699. (should
  700. (equal "[fn:1] Definition\n\nDefinition"
  701. (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
  702. (org-indent-region (point-min) (point-max))
  703. (buffer-string))))
  704. ;; Special case: Start indenting on a blank line.
  705. (should
  706. (equal "\nParagraph"
  707. (org-test-with-temp-text "\n Paragraph"
  708. (org-indent-region (point-min) (point-max))
  709. (buffer-string)))))
  710. ;;; Editing
  711. (ert-deftest test-org/return ()
  712. "Test RET (`org-return') specifications."
  713. ;; Regular test.
  714. (should
  715. (equal "Para\ngraph"
  716. (org-test-with-temp-text "Para<point>graph"
  717. (org-return)
  718. (buffer-string))))
  719. ;; With optional argument, indent line.
  720. (should
  721. (equal " Para\n graph"
  722. (org-test-with-temp-text " Para<point>graph"
  723. (org-return t)
  724. (buffer-string))))
  725. ;; On a table, call `org-table-next-row'.
  726. (should
  727. (org-test-with-temp-text "| <point>a |\n| b |"
  728. (org-return)
  729. (org-looking-at-p "b")))
  730. ;; Open link or timestamp under point when `org-return-follows-link'
  731. ;; is non-nil.
  732. (should
  733. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  734. (let ((org-return-follows-link t)) (org-return))
  735. (org-looking-at-p "<<target>>")))
  736. (should-not
  737. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  738. (let ((org-return-follows-link nil)) (org-return))
  739. (org-looking-at-p "<<target>>")))
  740. ;; However, do not open link when point is in a table.
  741. (should
  742. (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
  743. (let ((org-return-follows-link t)) (org-return))
  744. (org-looking-at-p "between")))
  745. ;; Special case: in a list, when indenting, do not break structure.
  746. (should
  747. (equal "- A\n B"
  748. (org-test-with-temp-text "- A <point>B"
  749. (org-return t)
  750. (buffer-string))))
  751. ;; Special case: on tags part of a headline, add a newline below it
  752. ;; instead of breaking it.
  753. (should
  754. (equal "* H :tag:\n"
  755. (org-test-with-temp-text "* H :<point>tag:"
  756. (org-return)
  757. (buffer-string)))))
  758. (ert-deftest test-org/meta-return ()
  759. "Test M-RET (`org-meta-return') specifications."
  760. ;; In a table field insert a row above.
  761. (should
  762. (org-test-with-temp-text "| a |"
  763. (forward-char)
  764. (org-meta-return)
  765. (forward-line -1)
  766. (looking-at "| |$")))
  767. ;; In a paragraph change current line into a header.
  768. (should
  769. (org-test-with-temp-text "a"
  770. (org-meta-return)
  771. (beginning-of-line)
  772. (looking-at "\* a$")))
  773. ;; In an item insert an item, in this case above.
  774. (should
  775. (org-test-with-temp-text "- a"
  776. (org-meta-return)
  777. (beginning-of-line)
  778. (looking-at "- $")))
  779. ;; In a drawer and item insert an item, in this case above.
  780. (should
  781. (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
  782. (forward-line)
  783. (org-meta-return)
  784. (beginning-of-line)
  785. (looking-at "- $"))))
  786. (ert-deftest test-org/insert-heading ()
  787. "Test `org-insert-heading' specifications."
  788. ;; FIXME: Test coverage is incomplete yet.
  789. ;;
  790. ;; In an empty buffer, insert a new headline.
  791. (should
  792. (equal "* "
  793. (org-test-with-temp-text ""
  794. (org-insert-heading)
  795. (buffer-string))))
  796. ;; At the beginning of a line, turn it into a headline
  797. (should
  798. (equal "* P"
  799. (org-test-with-temp-text "<point>P"
  800. (org-insert-heading)
  801. (buffer-string))))
  802. ;; In the middle of a line, split the line if allowed, otherwise,
  803. ;; insert the headline at its end.
  804. (should
  805. (equal "Para\n* graph"
  806. (org-test-with-temp-text "Para<point>graph"
  807. (let ((org-M-RET-may-split-line '((default . t))))
  808. (org-insert-heading))
  809. (buffer-string))))
  810. (should
  811. (equal "Paragraph\n* "
  812. (org-test-with-temp-text "Para<point>graph"
  813. (let ((org-M-RET-may-split-line '((default . nil))))
  814. (org-insert-heading))
  815. (buffer-string))))
  816. ;; When on a list, insert an item instead, unless called with an
  817. ;; universal argument or if list is invisible. In this case, create
  818. ;; a new headline after contents.
  819. (should
  820. (equal "* H\n- item\n- "
  821. (org-test-with-temp-text "* H\n- item<point>"
  822. (let ((org-insert-heading-respect-content nil))
  823. (org-insert-heading))
  824. (buffer-string))))
  825. (should
  826. (equal "* H\n- item\n- item 2\n* "
  827. (org-test-with-temp-text "* H\n- item<point>\n- item 2"
  828. (let ((org-insert-heading-respect-content nil))
  829. (org-insert-heading '(4)))
  830. (buffer-string))))
  831. (should
  832. (equal "* H\n- item\n* "
  833. (org-test-with-temp-text "* H\n- item"
  834. (org-cycle)
  835. (goto-char (point-max))
  836. (let ((org-insert-heading-respect-content nil)) (org-insert-heading))
  837. (buffer-string))))
  838. ;; When called with two universal arguments, insert a new headline
  839. ;; at the end of the grandparent subtree.
  840. (should
  841. (equal "* H1\n** H3\n- item\n** H2\n** "
  842. (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
  843. (let ((org-insert-heading-respect-content nil))
  844. (org-insert-heading '(16)))
  845. (buffer-string))))
  846. ;; Corner case: correctly insert a headline after an empty one.
  847. (should
  848. (equal "* \n* "
  849. (org-test-with-temp-text "* <point>"
  850. (org-insert-heading)
  851. (buffer-string)))))
  852. (ert-deftest test-org/insert-todo-heading-respect-content ()
  853. "Test `org-insert-todo-heading-respect-content' specifications."
  854. ;; Create a TODO heading.
  855. (should
  856. (org-test-with-temp-text "* H1\n Body"
  857. (org-insert-todo-heading-respect-content)
  858. (nth 2 (org-heading-components))))
  859. ;; Add headline at the end of the first subtree
  860. (should
  861. (org-test-with-temp-text "* H1\nH1Body\n** H2\nH2Body"
  862. (search-forward "H1Body")
  863. (org-insert-todo-heading-respect-content)
  864. (and (eobp) (org-at-heading-p))))
  865. ;; In a list, do not create a new item.
  866. (should
  867. (org-test-with-temp-text "* H\n- an item\n- another one"
  868. (search-forward "an ")
  869. (org-insert-todo-heading-respect-content)
  870. (and (eobp) (org-at-heading-p)))))
  871. ;;; Fixed-Width Areas
  872. (ert-deftest test-org/toggle-fixed-width ()
  873. "Test `org-toggle-fixed-width' specifications."
  874. ;; No region: Toggle on fixed-width marker in paragraphs.
  875. (should
  876. (equal ": A"
  877. (org-test-with-temp-text "A"
  878. (org-toggle-fixed-width)
  879. (buffer-string))))
  880. ;; No region: Toggle off fixed-width markers in fixed-width areas.
  881. (should
  882. (equal "A"
  883. (org-test-with-temp-text ": A"
  884. (org-toggle-fixed-width)
  885. (buffer-string))))
  886. ;; No region: Toggle on marker in blank lines after elements or just
  887. ;; after a headline.
  888. (should
  889. (equal "* H\n: "
  890. (org-test-with-temp-text "* H\n"
  891. (forward-line)
  892. (org-toggle-fixed-width)
  893. (buffer-string))))
  894. (should
  895. (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
  896. (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
  897. (goto-char (point-max))
  898. (org-toggle-fixed-width)
  899. (buffer-string))))
  900. ;; No region: Toggle on marker in front of one line elements (e.g.,
  901. ;; headlines, clocks)
  902. (should
  903. (equal ": * Headline"
  904. (org-test-with-temp-text "* Headline"
  905. (org-toggle-fixed-width)
  906. (buffer-string))))
  907. (should
  908. (equal ": #+KEYWORD: value"
  909. (org-test-with-temp-text "#+KEYWORD: value"
  910. (org-toggle-fixed-width)
  911. (buffer-string))))
  912. ;; No region: error in other situations.
  913. (should-error
  914. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
  915. (forward-line)
  916. (org-toggle-fixed-width)
  917. (buffer-string)))
  918. ;; No region: Indentation is preserved.
  919. (should
  920. (equal "- A\n : B"
  921. (org-test-with-temp-text "- A\n B"
  922. (forward-line)
  923. (org-toggle-fixed-width)
  924. (buffer-string))))
  925. ;; Region: If it contains only fixed-width elements and blank lines,
  926. ;; toggle off fixed-width markup.
  927. (should
  928. (equal "A\n\nB"
  929. (org-test-with-temp-text ": A\n\n: B"
  930. (transient-mark-mode 1)
  931. (push-mark (point) t t)
  932. (goto-char (point-max))
  933. (org-toggle-fixed-width)
  934. (buffer-string))))
  935. ;; Region: If it contains anything else, toggle on fixed-width but
  936. ;; not on fixed-width areas.
  937. (should
  938. (equal ": A\n: \n: B\n: \n: C"
  939. (org-test-with-temp-text "A\n\n: B\n\nC"
  940. (transient-mark-mode 1)
  941. (push-mark (point) t t)
  942. (goto-char (point-max))
  943. (org-toggle-fixed-width)
  944. (buffer-string))))
  945. ;; Region: Ignore blank lines at its end, unless it contains only
  946. ;; such lines.
  947. (should
  948. (equal ": A\n\n"
  949. (org-test-with-temp-text "A\n\n"
  950. (transient-mark-mode 1)
  951. (push-mark (point) t t)
  952. (goto-char (point-max))
  953. (org-toggle-fixed-width)
  954. (buffer-string))))
  955. (should
  956. (equal ": \n: \n"
  957. (org-test-with-temp-text "\n\n"
  958. (transient-mark-mode 1)
  959. (push-mark (point) t t)
  960. (goto-char (point-max))
  961. (org-toggle-fixed-width)
  962. (buffer-string)))))
  963. ;;; Headline
  964. (ert-deftest test-org/in-commented-heading-p ()
  965. "Test `org-in-commented-heading-p' specifications."
  966. ;; Commented headline.
  967. (should
  968. (org-test-with-temp-text "* COMMENT Headline\nBody"
  969. (goto-char (point-max))
  970. (org-in-commented-heading-p)))
  971. ;; Commented ancestor.
  972. (should
  973. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  974. (goto-char (point-max))
  975. (org-in-commented-heading-p)))
  976. ;; Comment keyword is case-sensitive.
  977. (should-not
  978. (org-test-with-temp-text "* Comment Headline\nBody"
  979. (goto-char (point-max))
  980. (org-in-commented-heading-p)))
  981. ;; Keyword is standalone.
  982. (should-not
  983. (org-test-with-temp-text "* COMMENTHeadline\nBody"
  984. (goto-char (point-max))
  985. (org-in-commented-heading-p)))
  986. ;; Optional argument.
  987. (should-not
  988. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  989. (goto-char (point-max))
  990. (org-in-commented-heading-p t))))
  991. ;;; Keywords
  992. (ert-deftest test-org/set-regexps-and-options ()
  993. "Test `org-set-regexps-and-options' specifications."
  994. ;; TAGS keyword.
  995. (should
  996. (equal '(("A" . ?a) ("B") ("C"))
  997. (org-test-with-temp-text "#+TAGS: A(a) B C"
  998. (org-mode-restart)
  999. org-tag-alist)))
  1000. (should
  1001. (equal '(("A") (:newline) ("B"))
  1002. (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
  1003. (org-mode-restart)
  1004. org-tag-alist)))
  1005. (should
  1006. (equal '((:startgroup) ("A") ("B") (:endgroup) ("C"))
  1007. (org-test-with-temp-text "#+TAGS: { A B } C"
  1008. (org-mode-restart)
  1009. org-tag-alist)))
  1010. (should
  1011. (equal '((:startgroup) ("A") (:grouptags) ("B") ("C") (:endgroup))
  1012. (org-test-with-temp-text "#+TAGS: { A : B C }"
  1013. (org-mode-restart)
  1014. org-tag-alist)))
  1015. (should
  1016. (equal '(("A" "B" "C"))
  1017. (org-test-with-temp-text "#+TAGS: { A : B C }"
  1018. (org-mode-restart)
  1019. org-tag-groups-alist)))
  1020. ;; FILETAGS keyword.
  1021. (should
  1022. (equal '("A" "B" "C")
  1023. (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
  1024. (org-mode-restart)
  1025. org-file-tags)))
  1026. ;; PROPERTY keyword. Property names are case-insensitive.
  1027. (should
  1028. (equal "foo=1"
  1029. (org-test-with-temp-text "#+PROPERTY: var foo=1"
  1030. (org-mode-restart)
  1031. (cdr (assoc "var" org-file-properties)))))
  1032. (should
  1033. (equal
  1034. "foo=1 bar=2"
  1035. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
  1036. (org-mode-restart)
  1037. (cdr (assoc "var" org-file-properties)))))
  1038. (should
  1039. (equal
  1040. "foo=1 bar=2"
  1041. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
  1042. (org-mode-restart)
  1043. (cdr (assoc "var" org-file-properties)))))
  1044. ;; ARCHIVE keyword.
  1045. (should
  1046. (equal "%s_done::"
  1047. (org-test-with-temp-text "#+ARCHIVE: %s_done::"
  1048. (org-mode-restart)
  1049. org-archive-location)))
  1050. ;; CATEGORY keyword.
  1051. (should
  1052. (eq 'test
  1053. (org-test-with-temp-text "#+CATEGORY: test"
  1054. (org-mode-restart)
  1055. org-category)))
  1056. (should
  1057. (equal "test"
  1058. (org-test-with-temp-text "#+CATEGORY: test"
  1059. (org-mode-restart)
  1060. (cdr (assoc "CATEGORY" org-file-properties)))))
  1061. ;; COLUMNS keyword.
  1062. (should
  1063. (equal "%25ITEM %TAGS %PRIORITY %TODO"
  1064. (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
  1065. (org-mode-restart)
  1066. org-columns-default-format)))
  1067. ;; CONSTANTS keyword. Constants names are case sensitive.
  1068. (should
  1069. (equal '("299792458." "3.14")
  1070. (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
  1071. (org-mode-restart)
  1072. (mapcar
  1073. (lambda (n) (cdr (assoc n org-table-formula-constants-local)))
  1074. '("c" "pi")))))
  1075. (should
  1076. (equal "3.14"
  1077. (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
  1078. (org-mode-restart)
  1079. (cdr (assoc "pi" org-table-formula-constants-local)))))
  1080. (should
  1081. (equal "22/7"
  1082. (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
  1083. (org-mode-restart)
  1084. (cdr (assoc "PI" org-table-formula-constants-local)))))
  1085. ;; LINK keyword.
  1086. (should
  1087. (equal
  1088. '("url1" "url2")
  1089. (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
  1090. (org-mode-restart)
  1091. (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local)))
  1092. '("a" "b")))))
  1093. ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
  1094. (should
  1095. (equal
  1096. '(?X ?Z ?Y)
  1097. (org-test-with-temp-text "#+PRIORITIES: X Z Y"
  1098. (org-mode-restart)
  1099. (list org-highest-priority org-lowest-priority org-default-priority))))
  1100. (should
  1101. (equal
  1102. '(?A ?C ?B)
  1103. (org-test-with-temp-text "#+PRIORITIES: X Z"
  1104. (org-mode-restart)
  1105. (list org-highest-priority org-lowest-priority org-default-priority))))
  1106. ;; STARTUP keyword.
  1107. (should
  1108. (equal '(t t)
  1109. (org-test-with-temp-text "#+STARTUP: fold odd"
  1110. (org-mode-restart)
  1111. (list org-startup-folded org-odd-levels-only))))
  1112. ;; TODO keywords.
  1113. (should
  1114. (equal '(("A" "B") ("C"))
  1115. (org-test-with-temp-text "#+TODO: A B | C"
  1116. (org-mode-restart)
  1117. (list org-not-done-keywords org-done-keywords))))
  1118. (should
  1119. (equal '(("A" "C") ("B" "D"))
  1120. (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
  1121. (org-mode-restart)
  1122. (list org-not-done-keywords org-done-keywords))))
  1123. (should
  1124. (equal '(("A" "B") ("C"))
  1125. (org-test-with-temp-text "#+TYP_TODO: A B | C"
  1126. (org-mode-restart)
  1127. (list org-not-done-keywords org-done-keywords))))
  1128. (should
  1129. (equal '((:startgroup) ("A" . ?a) (:endgroup))
  1130. (org-test-with-temp-text "#+TODO: A(a)"
  1131. (org-mode-restart)
  1132. org-todo-key-alist)))
  1133. (should
  1134. (equal '(("D" note nil) ("C" time nil) ("B" note time))
  1135. (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
  1136. (org-mode-restart)
  1137. org-todo-log-states)))
  1138. ;; Enter SETUPFILE keyword.
  1139. (should
  1140. (equal "1"
  1141. (org-test-with-temp-text
  1142. (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
  1143. (org-mode-restart)
  1144. (cdr (assoc "a" org-file-properties))))))
  1145. ;;; Links
  1146. ;;;; Coderefs
  1147. (ert-deftest test-org/coderef ()
  1148. "Test coderef links specifications."
  1149. (should
  1150. (org-test-with-temp-text "
  1151. #+BEGIN_SRC emacs-lisp
  1152. \(+ 1 1) (ref:sc)
  1153. #+END_SRC
  1154. \[[(sc)]]"
  1155. (goto-char (point-max))
  1156. (org-open-at-point)
  1157. (looking-at "(ref:sc)"))))
  1158. ;;;; Custom ID
  1159. (ert-deftest test-org/custom-id ()
  1160. "Test custom ID links specifications."
  1161. (should
  1162. (org-test-with-temp-text
  1163. "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom]]"
  1164. (goto-char (point-max))
  1165. (org-open-at-point)
  1166. (org-looking-at-p "\\* H1"))))
  1167. ;;;; Fuzzy Links
  1168. ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
  1169. ;; a named element (#+name: text) and to headlines (* Text).
  1170. (ert-deftest test-org/fuzzy-links ()
  1171. "Test fuzzy links specifications."
  1172. ;; Fuzzy link goes in priority to a matching target.
  1173. (should
  1174. (org-test-with-temp-text "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n[[Test]]"
  1175. (goto-line 5)
  1176. (org-open-at-point)
  1177. (looking-at "<<Test>>")))
  1178. ;; Then fuzzy link points to an element with a given name.
  1179. (should
  1180. (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n[[Test]]"
  1181. (goto-line 5)
  1182. (org-open-at-point)
  1183. (looking-at "#\\+NAME: Test")))
  1184. ;; A target still lead to a matching headline otherwise.
  1185. (should
  1186. (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n[[Head2]]"
  1187. (goto-line 4)
  1188. (org-open-at-point)
  1189. (looking-at "\\* Head2")))
  1190. ;; With a leading star in link, enforce heading match.
  1191. (should
  1192. (org-test-with-temp-text "* Test\n<<Test>>\n[[*Test]]"
  1193. (goto-line 3)
  1194. (org-open-at-point)
  1195. (looking-at "\\* Test")))
  1196. ;; Correctly un-hexify fuzzy links.
  1197. (should
  1198. (org-test-with-temp-text "* With space\n[[*With%20space][With space]]"
  1199. (goto-char (point-max))
  1200. (org-open-at-point)
  1201. (bobp))))
  1202. ;;;; Link Escaping
  1203. (ert-deftest test-org/org-link-escape-ascii-character ()
  1204. "Escape an ascii character."
  1205. (should
  1206. (string=
  1207. "%5B"
  1208. (org-link-escape "["))))
  1209. (ert-deftest test-org/org-link-escape-ascii-ctrl-character ()
  1210. "Escape an ascii control character."
  1211. (should
  1212. (string=
  1213. "%09"
  1214. (org-link-escape "\t"))))
  1215. (ert-deftest test-org/org-link-escape-multibyte-character ()
  1216. "Escape an unicode multibyte character."
  1217. (should
  1218. (string=
  1219. "%E2%82%AC"
  1220. (org-link-escape "€"))))
  1221. (ert-deftest test-org/org-link-escape-custom-table ()
  1222. "Escape string with custom character table."
  1223. (should
  1224. (string=
  1225. "Foo%3A%42ar%0A"
  1226. (org-link-escape "Foo:Bar\n" '(?\: ?\B)))))
  1227. (ert-deftest test-org/org-link-escape-custom-table-merge ()
  1228. "Escape string with custom table merged with default table."
  1229. (should
  1230. (string=
  1231. "%5BF%6F%6F%3A%42ar%0A%5D"
  1232. (org-link-escape "[Foo:Bar\n]" '(?\: ?\B ?\o) t))))
  1233. (ert-deftest test-org/org-link-unescape-ascii-character ()
  1234. "Unescape an ascii character."
  1235. (should
  1236. (string=
  1237. "["
  1238. (org-link-unescape "%5B"))))
  1239. (ert-deftest test-org/org-link-unescape-ascii-ctrl-character ()
  1240. "Unescpae an ascii control character."
  1241. (should
  1242. (string=
  1243. "\n"
  1244. (org-link-unescape "%0A"))))
  1245. (ert-deftest test-org/org-link-unescape-multibyte-character ()
  1246. "Unescape unicode multibyte character."
  1247. (should
  1248. (string=
  1249. "€"
  1250. (org-link-unescape "%E2%82%AC"))))
  1251. (ert-deftest test-org/org-link-unescape-ascii-extended-char ()
  1252. "Unescape old style percent escaped character."
  1253. (should
  1254. (string=
  1255. "àâçèéêîôùû"
  1256. (decode-coding-string
  1257. (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1))))
  1258. (ert-deftest test-org/org-link-escape-url-with-escaped-char ()
  1259. "Escape and unescape a URL that includes an escaped char.
  1260. http://article.gmane.org/gmane.emacs.orgmode/21459/"
  1261. (should
  1262. (string=
  1263. "http://some.host.com/form?&id=blah%2Bblah25"
  1264. (org-link-unescape
  1265. (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
  1266. (ert-deftest test-org/org-link-escape-chars-browser ()
  1267. "Test of the constant `org-link-escape-chars-browser'.
  1268. See there why this test is a candidate to be removed once Org
  1269. drops support for Emacs 24.1 and 24.2."
  1270. (should
  1271. (string=
  1272. (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
  1273. "%22Release%208.2%22&idxname=emacs-orgmode")
  1274. (org-link-escape-browser ; Do not replace with `url-encode-url',
  1275. ; see docstring above.
  1276. (concat "http://lists.gnu.org/archive/cgi-bin/namazu.cgi?query="
  1277. "\"Release 8.2\"&idxname=emacs-orgmode")))))
  1278. ;;;; Open at point
  1279. (ert-deftest test-org/open-at-point-in-property ()
  1280. "Does `org-open-at-point' open link in property drawer?"
  1281. (should
  1282. (org-test-with-temp-text
  1283. "* Headline
  1284. :PROPERTIES:
  1285. :URL: <point>[[info:emacs#Top]]
  1286. :END:"
  1287. (org-open-at-point) t)))
  1288. (ert-deftest test-org/open-at-point-in-comment ()
  1289. "Does `org-open-at-point' open link in a commented line?"
  1290. (should
  1291. (org-test-with-temp-text
  1292. "# <point>[[info:emacs#Top]]"
  1293. (org-open-at-point) t)))
  1294. (ert-deftest test-org/open-at-point/info ()
  1295. "Test `org-open-at-point' on info links."
  1296. (should
  1297. (org-test-with-temp-text
  1298. "<point>[[info:emacs#Top]]"
  1299. (org-open-at-point)
  1300. (and (switch-to-buffer "*info*")
  1301. (prog1
  1302. (looking-at "\nThe Emacs Editor")
  1303. (kill-buffer))))))
  1304. (ert-deftest test-org/open-at-point/inline-image ()
  1305. "Test `org-open-at-point' on nested links."
  1306. (should
  1307. (org-test-with-temp-text "[[info:org#Top][info:<point>emacs#Top]]"
  1308. (org-open-at-point)
  1309. (prog1 (with-current-buffer "*info*" (looking-at "\nOrg Mode Manual"))
  1310. (kill-buffer "*info*")))))
  1311. ;;; Node Properties
  1312. (ert-deftest test-org/accumulated-properties-in-drawers ()
  1313. "Ensure properties accumulate in subtree drawers."
  1314. (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
  1315. (org-babel-next-src-block)
  1316. (should (equal '(2 1) (org-babel-execute-src-block)))))
  1317. (ert-deftest test-org/custom-properties ()
  1318. "Test custom properties specifications."
  1319. ;; Standard test.
  1320. (should
  1321. (let ((org-custom-properties '("FOO")))
  1322. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  1323. (org-toggle-custom-properties-visibility)
  1324. (org-invisible-p2))))
  1325. ;; Properties are case-insensitive.
  1326. (should
  1327. (let ((org-custom-properties '("FOO")))
  1328. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
  1329. (org-toggle-custom-properties-visibility)
  1330. (org-invisible-p2))))
  1331. (should
  1332. (let ((org-custom-properties '("foo")))
  1333. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  1334. (org-toggle-custom-properties-visibility)
  1335. (org-invisible-p2))))
  1336. ;; Multiple custom properties in the same drawer.
  1337. (should
  1338. (let ((org-custom-properties '("FOO" "BAR")))
  1339. (org-test-with-temp-text
  1340. "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
  1341. (org-toggle-custom-properties-visibility)
  1342. (and (org-invisible-p2)
  1343. (not (progn (forward-line) (org-invisible-p2)))
  1344. (progn (forward-line) (org-invisible-p2))))))
  1345. ;; Hide custom properties with an empty value.
  1346. (should
  1347. (let ((org-custom-properties '("FOO")))
  1348. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
  1349. (org-toggle-custom-properties-visibility)
  1350. (org-invisible-p2))))
  1351. ;; Do not hide fake properties.
  1352. (should-not
  1353. (let ((org-custom-properties '("FOO")))
  1354. (org-test-with-temp-text ":FOO: val\n"
  1355. (org-toggle-custom-properties-visibility)
  1356. (org-invisible-p2))))
  1357. (should-not
  1358. (let ((org-custom-properties '("A")))
  1359. (org-test-with-temp-text
  1360. "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
  1361. (org-toggle-custom-properties-visibility)
  1362. (org-invisible-p2)))))
  1363. ;;; Mark Region
  1364. (ert-deftest test-org/mark-subtree ()
  1365. "Test `org-mark-subtree' specifications."
  1366. ;; Error when point is before first headline.
  1367. (should-error
  1368. (org-test-with-temp-text "Paragraph\n* Headline\nBody"
  1369. (progn (transient-mark-mode 1)
  1370. (org-mark-subtree))))
  1371. ;; Without argument, mark current subtree.
  1372. (should
  1373. (equal
  1374. '(12 32)
  1375. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  1376. (progn (transient-mark-mode 1)
  1377. (forward-line 2)
  1378. (org-mark-subtree)
  1379. (list (region-beginning) (region-end))))))
  1380. ;; With an argument, move ARG up.
  1381. (should
  1382. (equal
  1383. '(1 32)
  1384. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  1385. (progn (transient-mark-mode 1)
  1386. (forward-line 2)
  1387. (org-mark-subtree 1)
  1388. (list (region-beginning) (region-end))))))
  1389. ;; Do not get fooled by inlinetasks.
  1390. (when (featurep 'org-inlinetask)
  1391. (should
  1392. (= 1
  1393. (org-test-with-temp-text "* Headline\n*************** Task\nContents"
  1394. (progn (transient-mark-mode 1)
  1395. (forward-line 1)
  1396. (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
  1397. (region-beginning)))))))
  1398. ;;; Navigation
  1399. (ert-deftest test-org/beginning-of-line ()
  1400. "Test `org-beginning-of-line' specifications."
  1401. ;; Standard test.
  1402. (should
  1403. (org-test-with-temp-text "Some text\nSome other text"
  1404. (progn (org-beginning-of-line) (bolp))))
  1405. ;; Standard test with `visual-line-mode'.
  1406. (should-not
  1407. (org-test-with-temp-text "A long line of text\nSome other text"
  1408. (progn (visual-line-mode)
  1409. (forward-char 2)
  1410. (dotimes (i 1000) (insert "very "))
  1411. (org-beginning-of-line)
  1412. (bolp))))
  1413. ;; At an headline with special movement.
  1414. (should
  1415. (org-test-with-temp-text "* TODO Headline"
  1416. (let ((org-special-ctrl-a/e t))
  1417. (org-end-of-line)
  1418. (and (progn (org-beginning-of-line) (looking-at "Headline"))
  1419. (progn (org-beginning-of-line) (bolp))
  1420. (progn (org-beginning-of-line) (looking-at "Headline")))))))
  1421. (ert-deftest test-org/end-of-line ()
  1422. "Test `org-end-of-line' specifications."
  1423. ;; Standard test.
  1424. (should
  1425. (org-test-with-temp-text "Some text\nSome other text"
  1426. (progn (org-end-of-line) (eolp))))
  1427. ;; Standard test with `visual-line-mode'.
  1428. (should-not
  1429. (org-test-with-temp-text "A long line of text\nSome other text"
  1430. (progn (visual-line-mode)
  1431. (forward-char 2)
  1432. (dotimes (i 1000) (insert "very "))
  1433. (goto-char (point-min))
  1434. (org-end-of-line)
  1435. (eolp))))
  1436. ;; At an headline with special movement.
  1437. (should
  1438. (org-test-with-temp-text "* Headline1 :tag:\n"
  1439. (let ((org-special-ctrl-a/e t))
  1440. (and (progn (org-end-of-line) (looking-at " :tag:"))
  1441. (progn (org-end-of-line) (eolp))
  1442. (progn (org-end-of-line) (looking-at " :tag:"))))))
  1443. ;; At an headline without special movement.
  1444. (should
  1445. (org-test-with-temp-text "* Headline2 :tag:\n"
  1446. (let ((org-special-ctrl-a/e nil))
  1447. (and (progn (org-end-of-line) (eolp))
  1448. (progn (org-end-of-line) (eolp))))))
  1449. ;; At an headline, with reversed movement.
  1450. (should
  1451. (org-test-with-temp-text "* Headline3 :tag:\n"
  1452. (let ((org-special-ctrl-a/e 'reversed)
  1453. (this-command last-command))
  1454. (and (progn (org-end-of-line) (eolp))
  1455. (progn (org-end-of-line) (looking-at " :tag:"))))))
  1456. ;; At a block without hidden contents.
  1457. (should
  1458. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  1459. (progn (org-end-of-line) (eolp))))
  1460. ;; At a block with hidden contents.
  1461. (should-not
  1462. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  1463. (let ((org-special-ctrl-a/e t))
  1464. (org-hide-block-toggle)
  1465. (org-end-of-line)
  1466. (eobp)))))
  1467. (ert-deftest test-org/forward-paragraph ()
  1468. "Test `org-forward-paragraph' specifications."
  1469. ;; At end of buffer, return an error.
  1470. (should-error
  1471. (org-test-with-temp-text "Paragraph"
  1472. (goto-char (point-max))
  1473. (org-forward-paragraph)))
  1474. ;; Standard test.
  1475. (should
  1476. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  1477. (org-forward-paragraph)
  1478. (looking-at "P2")))
  1479. ;; Ignore depth.
  1480. (should
  1481. (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
  1482. (org-forward-paragraph)
  1483. (looking-at "P1")))
  1484. ;; Do not enter elements with invisible contents.
  1485. (should
  1486. (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
  1487. (org-hide-block-toggle)
  1488. (org-forward-paragraph)
  1489. (looking-at "P3")))
  1490. ;; On an affiliated keyword, jump to the beginning of the element.
  1491. (should
  1492. (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
  1493. (org-forward-paragraph)
  1494. (looking-at "Para")))
  1495. ;; On an item or a footnote definition, move to the second element
  1496. ;; inside, if any.
  1497. (should
  1498. (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
  1499. (org-forward-paragraph)
  1500. (looking-at " Paragraph")))
  1501. (should
  1502. (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
  1503. (org-forward-paragraph)
  1504. (looking-at "Paragraph")))
  1505. ;; On an item, or a footnote definition, when the first line is
  1506. ;; empty, move to the first item.
  1507. (should
  1508. (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
  1509. (org-forward-paragraph)
  1510. (looking-at " Paragraph")))
  1511. (should
  1512. (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
  1513. (org-forward-paragraph)
  1514. (looking-at "Paragraph")))
  1515. ;; On a table (resp. a property drawer) do not move through table
  1516. ;; rows (resp. node properties).
  1517. (should
  1518. (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
  1519. (org-forward-paragraph)
  1520. (looking-at "Paragraph")))
  1521. (should
  1522. (org-test-with-temp-text
  1523. "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
  1524. (org-forward-paragraph)
  1525. (looking-at "Paragraph")))
  1526. ;; On a verse or source block, stop after blank lines.
  1527. (should
  1528. (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
  1529. (org-forward-paragraph)
  1530. (looking-at "L2")))
  1531. (should
  1532. (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
  1533. (org-forward-paragraph)
  1534. (looking-at "L2"))))
  1535. (ert-deftest test-org/backward-paragraph ()
  1536. "Test `org-backward-paragraph' specifications."
  1537. ;; Error at beginning of buffer.
  1538. (should-error
  1539. (org-test-with-temp-text "Paragraph"
  1540. (org-backward-paragraph)))
  1541. ;; Regular test.
  1542. (should
  1543. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  1544. (goto-char (point-max))
  1545. (org-backward-paragraph)
  1546. (looking-at "P3")))
  1547. (should
  1548. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  1549. (goto-char (point-max))
  1550. (beginning-of-line)
  1551. (org-backward-paragraph)
  1552. (looking-at "P2")))
  1553. ;; Ignore depth.
  1554. (should
  1555. (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\nP3"
  1556. (goto-char (point-max))
  1557. (beginning-of-line)
  1558. (org-backward-paragraph)
  1559. (looking-at "P2")))
  1560. ;; Ignore invisible elements.
  1561. (should
  1562. (org-test-with-temp-text "* H1\n P1\n* H2"
  1563. (org-cycle)
  1564. (goto-char (point-max))
  1565. (beginning-of-line)
  1566. (org-backward-paragraph)
  1567. (bobp)))
  1568. ;; On an affiliated keyword, jump to the first one.
  1569. (should
  1570. (org-test-with-temp-text "P1\n#+name: n\n#+caption: c1\n#+caption: c2\nP2"
  1571. (search-forward "c2")
  1572. (org-backward-paragraph)
  1573. (looking-at "#\\+name")))
  1574. ;; On the second element in an item or a footnote definition, jump
  1575. ;; to item or the definition.
  1576. (should
  1577. (org-test-with-temp-text "- line1\n\n line2"
  1578. (goto-char (point-max))
  1579. (beginning-of-line)
  1580. (org-backward-paragraph)
  1581. (looking-at "- line1")))
  1582. (should
  1583. (org-test-with-temp-text "[fn:1] line1\n\n line2"
  1584. (goto-char (point-max))
  1585. (beginning-of-line)
  1586. (org-backward-paragraph)
  1587. (looking-at "\\[fn:1\\] line1")))
  1588. ;; On a table (resp. a property drawer), ignore table rows
  1589. ;; (resp. node properties).
  1590. (should
  1591. (org-test-with-temp-text "| a | b |\n| c | d |\nP1"
  1592. (goto-char (point-max))
  1593. (beginning-of-line)
  1594. (org-backward-paragraph)
  1595. (bobp)))
  1596. (should
  1597. (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
  1598. (org-backward-paragraph)
  1599. (looking-at ":PROPERTIES:")))
  1600. ;; On a source or verse block, stop before blank lines.
  1601. (should
  1602. (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\nL3\n#+END_VERSE"
  1603. (search-forward "L3")
  1604. (beginning-of-line)
  1605. (org-backward-paragraph)
  1606. (looking-at "L2")))
  1607. (should
  1608. (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\nL3#+END_SRC"
  1609. (search-forward "L3")
  1610. (beginning-of-line)
  1611. (org-backward-paragraph)
  1612. (looking-at "L2"))))
  1613. (ert-deftest test-org/forward-element ()
  1614. "Test `org-forward-element' specifications."
  1615. ;; 1. At EOB: should error.
  1616. (org-test-with-temp-text "Some text\n"
  1617. (goto-char (point-max))
  1618. (should-error (org-forward-element)))
  1619. ;; 2. Standard move: expected to ignore blank lines.
  1620. (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
  1621. (org-forward-element)
  1622. (should (looking-at (regexp-quote "Second paragraph."))))
  1623. ;; 3. Headline tests.
  1624. (org-test-with-temp-text "
  1625. * Head 1
  1626. ** Head 1.1
  1627. *** Head 1.1.1
  1628. ** Head 1.2"
  1629. ;; 3.1. At an headline beginning: move to next headline at the
  1630. ;; same level.
  1631. (goto-line 3)
  1632. (org-forward-element)
  1633. (should (looking-at (regexp-quote "** Head 1.2")))
  1634. ;; 3.2. At an headline beginning: move to parent headline if no
  1635. ;; headline at the same level.
  1636. (goto-line 3)
  1637. (org-forward-element)
  1638. (should (looking-at (regexp-quote "** Head 1.2"))))
  1639. ;; 4. Greater element tests.
  1640. (org-test-with-temp-text
  1641. "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
  1642. ;; 4.1. At a greater element: expected to skip contents.
  1643. (org-forward-element)
  1644. (should (looking-at (regexp-quote "Outside.")))
  1645. ;; 4.2. At the end of greater element contents: expected to skip
  1646. ;; to the end of the greater element.
  1647. (goto-line 2)
  1648. (org-forward-element)
  1649. (should (looking-at (regexp-quote "Outside."))))
  1650. ;; 5. List tests.
  1651. (org-test-with-temp-text "
  1652. - item1
  1653. - sub1
  1654. - sub2
  1655. - sub3
  1656. Inner paragraph.
  1657. - item2
  1658. Outside."
  1659. ;; 5.1. At list top point: expected to move to the element after
  1660. ;; the list.
  1661. (goto-line 2)
  1662. (org-forward-element)
  1663. (should (looking-at (regexp-quote "Outside.")))
  1664. ;; 5.2. Special case: at the first line of a sub-list, but not at
  1665. ;; beginning of line, move to next item.
  1666. (goto-line 2)
  1667. (forward-char)
  1668. (org-forward-element)
  1669. (should (looking-at "- item2"))
  1670. (goto-line 4)
  1671. (forward-char)
  1672. (org-forward-element)
  1673. (should (looking-at " - sub2"))
  1674. ;; 5.3 At sub-list beginning: expected to move after the sub-list.
  1675. (goto-line 4)
  1676. (org-forward-element)
  1677. (should (looking-at (regexp-quote " Inner paragraph.")))
  1678. ;; 5.4. At sub-list end: expected to move outside the sub-list.
  1679. (goto-line 8)
  1680. (org-forward-element)
  1681. (should (looking-at (regexp-quote " Inner paragraph.")))
  1682. ;; 5.5. At an item: expected to move to next item, if any.
  1683. (goto-line 6)
  1684. (org-forward-element)
  1685. (should (looking-at " - sub3"))))
  1686. (ert-deftest test-org/backward-element ()
  1687. "Test `org-backward-element' specifications."
  1688. ;; 1. Should error at BOB.
  1689. (org-test-with-temp-text " \nParagraph."
  1690. (should-error (org-backward-element)))
  1691. ;; 2. Should move at BOB when called on the first element in buffer.
  1692. (should
  1693. (org-test-with-temp-text "\n#+TITLE: test"
  1694. (progn (forward-line)
  1695. (org-backward-element)
  1696. (bobp))))
  1697. ;; 3. Not at the beginning of an element: move at its beginning.
  1698. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  1699. (goto-line 3)
  1700. (end-of-line)
  1701. (org-backward-element)
  1702. (should (looking-at (regexp-quote "Paragraph2."))))
  1703. ;; 4. Headline tests.
  1704. (org-test-with-temp-text "
  1705. * Head 1
  1706. ** Head 1.1
  1707. *** Head 1.1.1
  1708. ** Head 1.2"
  1709. ;; 4.1. At an headline beginning: move to previous headline at the
  1710. ;; same level.
  1711. (goto-line 5)
  1712. (org-backward-element)
  1713. (should (looking-at (regexp-quote "** Head 1.1")))
  1714. ;; 4.2. At an headline beginning: move to parent headline if no
  1715. ;; headline at the same level.
  1716. (goto-line 3)
  1717. (org-backward-element)
  1718. (should (looking-at (regexp-quote "* Head 1")))
  1719. ;; 4.3. At the first top-level headline: should error.
  1720. (goto-line 2)
  1721. (should-error (org-backward-element)))
  1722. ;; 5. At beginning of first element inside a greater element:
  1723. ;; expected to move to greater element's beginning.
  1724. (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
  1725. (goto-line 3)
  1726. (org-backward-element)
  1727. (should (looking-at "#\\+BEGIN_CENTER")))
  1728. ;; 6. At the beginning of the first element in a section: should
  1729. ;; move back to headline, if any.
  1730. (should
  1731. (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
  1732. (progn (goto-char (point-max))
  1733. (beginning-of-line)
  1734. (org-backward-element)
  1735. (org-at-heading-p))))
  1736. ;; 7. List tests.
  1737. (org-test-with-temp-text "
  1738. - item1
  1739. - sub1
  1740. - sub2
  1741. - sub3
  1742. Inner paragraph.
  1743. - item2
  1744. Outside."
  1745. ;; 7.1. At beginning of sub-list: expected to move to the
  1746. ;; paragraph before it.
  1747. (goto-line 4)
  1748. (org-backward-element)
  1749. (should (looking-at "item1"))
  1750. ;; 7.2. At an item in a list: expected to move at previous item.
  1751. (goto-line 8)
  1752. (org-backward-element)
  1753. (should (looking-at " - sub2"))
  1754. (goto-line 12)
  1755. (org-backward-element)
  1756. (should (looking-at "- item1"))
  1757. ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
  1758. ;; beginning.
  1759. (goto-line 10)
  1760. (org-backward-element)
  1761. (should (looking-at " - sub1"))
  1762. (goto-line 15)
  1763. (org-backward-element)
  1764. (should (looking-at "- item1"))
  1765. ;; 7.4. At blank-lines before list end: expected to move to top
  1766. ;; item.
  1767. (goto-line 14)
  1768. (org-backward-element)
  1769. (should (looking-at "- item1"))))
  1770. (ert-deftest test-org/up-element ()
  1771. "Test `org-up-element' specifications."
  1772. ;; 1. At BOB or with no surrounding element: should error.
  1773. (org-test-with-temp-text "Paragraph."
  1774. (should-error (org-up-element)))
  1775. (org-test-with-temp-text "* Head1\n* Head2"
  1776. (goto-line 2)
  1777. (should-error (org-up-element)))
  1778. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  1779. (goto-line 3)
  1780. (should-error (org-up-element)))
  1781. ;; 2. At an headline: move to parent headline.
  1782. (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
  1783. (goto-line 3)
  1784. (org-up-element)
  1785. (should (looking-at "\\* Head1")))
  1786. ;; 3. Inside a greater element: move to greater element beginning.
  1787. (org-test-with-temp-text
  1788. "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
  1789. (goto-line 3)
  1790. (org-up-element)
  1791. (should (looking-at "#\\+BEGIN_CENTER")))
  1792. ;; 4. List tests.
  1793. (org-test-with-temp-text "* Top
  1794. - item1
  1795. - sub1
  1796. - sub2
  1797. Paragraph within sub2.
  1798. - item2"
  1799. ;; 4.1. Within an item: move to the item beginning.
  1800. (goto-line 8)
  1801. (org-up-element)
  1802. (should (looking-at " - sub2"))
  1803. ;; 4.2. At an item in a sub-list: move to parent item.
  1804. (goto-line 4)
  1805. (org-up-element)
  1806. (should (looking-at "- item1"))
  1807. ;; 4.3. At an item in top list: move to beginning of whole list.
  1808. (goto-line 10)
  1809. (org-up-element)
  1810. (should (looking-at "- item1"))
  1811. ;; 4.4. Special case. At very top point: should move to parent of
  1812. ;; list.
  1813. (goto-line 2)
  1814. (org-up-element)
  1815. (should (looking-at "\\* Top"))))
  1816. (ert-deftest test-org/down-element ()
  1817. "Test `org-down-element' specifications."
  1818. ;; Error when the element hasn't got a recursive type.
  1819. (org-test-with-temp-text "Paragraph."
  1820. (should-error (org-down-element)))
  1821. ;; Error when the element has no contents
  1822. (org-test-with-temp-text "* Headline"
  1823. (should-error (org-down-element)))
  1824. ;; When at a plain-list, move to first item.
  1825. (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
  1826. (goto-line 2)
  1827. (org-down-element)
  1828. (should (looking-at " - Item 1.1")))
  1829. (org-test-with-temp-text "#+NAME: list\n- Item 1"
  1830. (org-down-element)
  1831. (should (looking-at " Item 1")))
  1832. ;; When at a table, move to first row
  1833. (org-test-with-temp-text "#+NAME: table\n| a | b |"
  1834. (org-down-element)
  1835. (should (looking-at " a | b |")))
  1836. ;; Otherwise, move inside the greater element.
  1837. (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
  1838. (org-down-element)
  1839. (should (looking-at "Paragraph"))))
  1840. (ert-deftest test-org/drag-element-backward ()
  1841. "Test `org-drag-element-backward' specifications."
  1842. ;; Standard test.
  1843. (should
  1844. (equal
  1845. "#+key2: val2\n#+key1: val1\n#+key3: val3"
  1846. (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
  1847. (org-drag-element-backward)
  1848. (buffer-string))))
  1849. (should
  1850. (equal
  1851. "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
  1852. (org-test-with-temp-text
  1853. "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
  1854. (org-drag-element-backward)
  1855. (buffer-string))))
  1856. ;; Preserve blank lines.
  1857. (should
  1858. (equal "Paragraph 2\n\n\nPara1\n\nPara3"
  1859. (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
  1860. (org-drag-element-backward)
  1861. (buffer-string))))
  1862. ;; Preserve column.
  1863. (should
  1864. (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
  1865. (org-drag-element-backward)
  1866. (org-looking-at-p "2")))
  1867. ;; Error when trying to move first element of buffer.
  1868. (should-error
  1869. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  1870. (org-drag-element-backward)))
  1871. ;; Error when trying to swap nested elements.
  1872. (should-error
  1873. (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
  1874. (forward-line)
  1875. (org-drag-element-backward)))
  1876. ;; Error when trying to swap an headline element and a non-headline
  1877. ;; element.
  1878. (should-error
  1879. (org-test-with-temp-text "Test.\n* Head 1"
  1880. (forward-line)
  1881. (org-drag-element-backward)))
  1882. ;; Preserve visibility of elements and their contents.
  1883. (should
  1884. (equal '((63 . 82) (26 . 48))
  1885. (org-test-with-temp-text "
  1886. #+BEGIN_CENTER
  1887. Text.
  1888. #+END_CENTER
  1889. - item 1
  1890. #+BEGIN_QUOTE
  1891. Text.
  1892. #+END_QUOTE"
  1893. (while (search-forward "BEGIN_" nil t) (org-cycle))
  1894. (search-backward "- item 1")
  1895. (org-drag-element-backward)
  1896. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  1897. (overlays-in (point-min) (point-max)))))))
  1898. (ert-deftest test-org/drag-element-forward ()
  1899. "Test `org-drag-element-forward' specifications."
  1900. ;; 1. Error when trying to move first element of buffer.
  1901. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  1902. (goto-line 3)
  1903. (should-error (org-drag-element-forward)))
  1904. ;; 2. Error when trying to swap nested elements.
  1905. (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
  1906. (forward-line)
  1907. (should-error (org-drag-element-forward)))
  1908. ;; 3. Error when trying to swap a non-headline element and an
  1909. ;; headline.
  1910. (org-test-with-temp-text "Test.\n* Head 1"
  1911. (should-error (org-drag-element-forward)))
  1912. ;; 4. Otherwise, swap elements, preserving column and blank lines
  1913. ;; between elements.
  1914. (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
  1915. (search-forward "graph")
  1916. (org-drag-element-forward)
  1917. (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
  1918. (should (looking-at " 1")))
  1919. ;; 5. Preserve visibility of elements and their contents.
  1920. (org-test-with-temp-text "
  1921. #+BEGIN_CENTER
  1922. Text.
  1923. #+END_CENTER
  1924. - item 1
  1925. #+BEGIN_QUOTE
  1926. Text.
  1927. #+END_QUOTE"
  1928. (while (search-forward "BEGIN_" nil t) (org-cycle))
  1929. (search-backward "#+BEGIN_CENTER")
  1930. (org-drag-element-forward)
  1931. (should
  1932. (equal
  1933. '((63 . 82) (26 . 48))
  1934. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  1935. (overlays-in (point-min) (point-max)))))))
  1936. ;;; Outline structure
  1937. (ert-deftest test-org/demote ()
  1938. "Test `org-demote' specifications."
  1939. ;; Add correct number of stars according to `org-odd-levels-only'.
  1940. (should
  1941. (= 2
  1942. (org-test-with-temp-text "* H"
  1943. (let ((org-odd-levels-only nil)) (org-demote))
  1944. (org-current-level))))
  1945. (should
  1946. (= 3
  1947. (org-test-with-temp-text "* H"
  1948. (let ((org-odd-levels-only t)) (org-demote))
  1949. (org-current-level))))
  1950. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  1951. (should
  1952. (org-test-with-temp-text "* H :tag:"
  1953. (let ((org-tags-column 10)
  1954. (org-auto-align-tags t)
  1955. (org-odd-levels-only nil))
  1956. (org-demote))
  1957. (org-move-to-column 10)
  1958. (org-looking-at-p ":tag:$")))
  1959. (should-not
  1960. (org-test-with-temp-text "* H :tag:"
  1961. (let ((org-tags-column 10)
  1962. (org-auto-align-tags nil)
  1963. (org-odd-levels-only nil))
  1964. (org-demote))
  1965. (org-move-to-column 10)
  1966. (org-looking-at-p ":tag:$")))
  1967. ;; When `org-adapt-indentation' is non-nil, always indent planning
  1968. ;; info and property drawers accordingly.
  1969. (should
  1970. (= 3
  1971. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  1972. (let ((org-odd-levels-only nil)
  1973. (org-adapt-indentation t))
  1974. (org-demote))
  1975. (forward-line)
  1976. (org-get-indentation))))
  1977. (should
  1978. (= 3
  1979. (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  1980. (let ((org-odd-levels-only nil)
  1981. (org-adapt-indentation t))
  1982. (org-demote))
  1983. (forward-line)
  1984. (org-get-indentation))))
  1985. (should-not
  1986. (= 3
  1987. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  1988. (let ((org-odd-levels-only nil)
  1989. (org-adapt-indentation nil))
  1990. (org-demote))
  1991. (forward-line)
  1992. (org-get-indentation))))
  1993. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  1994. ;; section accordingly. Ignore, however, footnote definitions and
  1995. ;; inlinetasks boundaries.
  1996. (should
  1997. (= 3
  1998. (org-test-with-temp-text "* H\n Paragraph"
  1999. (let ((org-odd-levels-only nil)
  2000. (org-adapt-indentation t))
  2001. (org-demote))
  2002. (forward-line)
  2003. (org-get-indentation))))
  2004. (should
  2005. (= 2
  2006. (org-test-with-temp-text "* H\n Paragraph"
  2007. (let ((org-odd-levels-only nil)
  2008. (org-adapt-indentation nil))
  2009. (org-demote))
  2010. (forward-line)
  2011. (org-get-indentation))))
  2012. (should
  2013. (zerop
  2014. (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
  2015. (let ((org-odd-levels-only nil)
  2016. (org-adapt-indentation t))
  2017. (org-demote))
  2018. (goto-char (point-max))
  2019. (org-get-indentation))))
  2020. (should
  2021. (= 3
  2022. (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
  2023. (let ((org-odd-levels-only nil)
  2024. (org-adapt-indentation t))
  2025. (org-demote))
  2026. (goto-char (point-max))
  2027. (org-get-indentation))))
  2028. (when (featurep 'org-inlinetask)
  2029. (should
  2030. (zerop
  2031. (let ((org-inlinetask-min-level 5)
  2032. (org-adapt-indentation t))
  2033. (org-test-with-temp-text "* H\n***** I\n***** END"
  2034. (org-demote)
  2035. (forward-line)
  2036. (org-get-indentation))))))
  2037. (when (featurep 'org-inlinetask)
  2038. (should
  2039. (= 3
  2040. (let ((org-inlinetask-min-level 5)
  2041. (org-adapt-indentation t))
  2042. (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
  2043. (org-demote)
  2044. (forward-line 2)
  2045. (org-get-indentation))))))
  2046. ;; Ignore contents of source blocks or example blocks when
  2047. ;; indentation should be preserved (through
  2048. ;; `org-src-preserve-indentation' or "-i" flag).
  2049. (should-not
  2050. (zerop
  2051. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  2052. (let ((org-adapt-indentation t)
  2053. (org-src-preserve-indentation nil))
  2054. (org-demote))
  2055. (forward-line 2)
  2056. (org-get-indentation))))
  2057. (should
  2058. (zerop
  2059. (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
  2060. (let ((org-adapt-indentation t)
  2061. (org-src-preserve-indentation t))
  2062. (org-demote))
  2063. (forward-line 2)
  2064. (org-get-indentation))))
  2065. (should
  2066. (zerop
  2067. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  2068. (let ((org-adapt-indentation t)
  2069. (org-src-preserve-indentation t))
  2070. (org-demote))
  2071. (forward-line 2)
  2072. (org-get-indentation))))
  2073. (should
  2074. (zerop
  2075. (org-test-with-temp-text
  2076. "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
  2077. (let ((org-adapt-indentation t)
  2078. (org-src-preserve-indentation nil))
  2079. (org-demote))
  2080. (forward-line 2)
  2081. (org-get-indentation)))))
  2082. (ert-deftest test-org/promote ()
  2083. "Test `org-promote' specifications."
  2084. ;; Return an error if headline is to be promoted to level 0, unless
  2085. ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
  2086. ;; headline becomes a comment.
  2087. (should-error
  2088. (org-test-with-temp-text "* H"
  2089. (let ((org-allow-promoting-top-level-subtree nil)) (org-promote))))
  2090. (should
  2091. (equal "# H"
  2092. (org-test-with-temp-text "* H"
  2093. (let ((org-allow-promoting-top-level-subtree t)) (org-promote))
  2094. (buffer-string))))
  2095. ;; Remove correct number of stars according to
  2096. ;; `org-odd-levels-only'.
  2097. (should
  2098. (= 2
  2099. (org-test-with-temp-text "*** H"
  2100. (let ((org-odd-levels-only nil)) (org-promote))
  2101. (org-current-level))))
  2102. (should
  2103. (= 1
  2104. (org-test-with-temp-text "*** H"
  2105. (let ((org-odd-levels-only t)) (org-promote))
  2106. (org-current-level))))
  2107. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  2108. (should
  2109. (org-test-with-temp-text "** H :tag:"
  2110. (let ((org-tags-column 10)
  2111. (org-auto-align-tags t)
  2112. (org-odd-levels-only nil))
  2113. (org-promote))
  2114. (org-move-to-column 10)
  2115. (org-looking-at-p ":tag:$")))
  2116. (should-not
  2117. (org-test-with-temp-text "** H :tag:"
  2118. (let ((org-tags-column 10)
  2119. (org-auto-align-tags nil)
  2120. (org-odd-levels-only nil))
  2121. (org-promote))
  2122. (org-move-to-column 10)
  2123. (org-looking-at-p ":tag:$")))
  2124. ;; When `org-adapt-indentation' is non-nil, always indent planning
  2125. ;; info and property drawers.
  2126. (should
  2127. (= 2
  2128. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  2129. (let ((org-odd-levels-only nil)
  2130. (org-adapt-indentation t))
  2131. (org-promote))
  2132. (forward-line)
  2133. (org-get-indentation))))
  2134. (should
  2135. (= 2
  2136. (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  2137. (let ((org-odd-levels-only nil)
  2138. (org-adapt-indentation t))
  2139. (org-promote))
  2140. (forward-line)
  2141. (org-get-indentation))))
  2142. (should-not
  2143. (= 2
  2144. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  2145. (let ((org-odd-levels-only nil)
  2146. (org-adapt-indentation nil))
  2147. (org-promote))
  2148. (forward-line)
  2149. (org-get-indentation))))
  2150. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  2151. ;; section accordingly. Ignore, however, footnote definitions and
  2152. ;; inlinetasks boundaries.
  2153. (should
  2154. (= 2
  2155. (org-test-with-temp-text "** H\n Paragraph"
  2156. (let ((org-odd-levels-only nil)
  2157. (org-adapt-indentation t))
  2158. (org-promote))
  2159. (forward-line)
  2160. (org-get-indentation))))
  2161. (should-not
  2162. (= 2
  2163. (org-test-with-temp-text "** H\n Paragraph"
  2164. (let ((org-odd-levels-only nil)
  2165. (org-adapt-indentation nil))
  2166. (org-promote))
  2167. (forward-line)
  2168. (org-get-indentation))))
  2169. (should
  2170. (= 2
  2171. (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
  2172. (let ((org-odd-levels-only nil)
  2173. (org-adapt-indentation t))
  2174. (org-promote))
  2175. (forward-line)
  2176. (org-get-indentation))))
  2177. (when (featurep 'org-inlinetask)
  2178. (should
  2179. (zerop
  2180. (let ((org-inlinetask-min-level 5)
  2181. (org-adapt-indentation t))
  2182. (org-test-with-temp-text "** H\n***** I\n***** END"
  2183. (org-promote)
  2184. (forward-line)
  2185. (org-get-indentation))))))
  2186. (when (featurep 'org-inlinetask)
  2187. (should
  2188. (= 2
  2189. (let ((org-inlinetask-min-level 5)
  2190. (org-adapt-indentation t))
  2191. (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
  2192. (org-promote)
  2193. (forward-line 2)
  2194. (org-get-indentation))))))
  2195. ;; Give up shifting if it would break document's structure
  2196. ;; otherwise.
  2197. (should
  2198. (= 3
  2199. (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
  2200. (let ((org-odd-levels-only nil)
  2201. (org-adapt-indentation t))
  2202. (org-promote))
  2203. (forward-line)
  2204. (org-get-indentation))))
  2205. (should
  2206. (= 3
  2207. (org-test-with-temp-text "** H\n Paragraph\n * list."
  2208. (let ((org-odd-levels-only nil)
  2209. (org-adapt-indentation t))
  2210. (org-promote))
  2211. (forward-line)
  2212. (org-get-indentation))))
  2213. ;; Ignore contents of source blocks or example blocks when
  2214. ;; indentation should be preserved (through
  2215. ;; `org-src-preserve-indentation' or "-i" flag).
  2216. (should-not
  2217. (zerop
  2218. (org-test-with-temp-text
  2219. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  2220. (let ((org-adapt-indentation t)
  2221. (org-src-preserve-indentation nil)
  2222. (org-odd-levels-only nil))
  2223. (org-promote))
  2224. (forward-line)
  2225. (org-get-indentation))))
  2226. (should
  2227. (zerop
  2228. (org-test-with-temp-text
  2229. "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
  2230. (let ((org-adapt-indentation t)
  2231. (org-src-preserve-indentation t)
  2232. (org-odd-levels-only nil))
  2233. (org-promote))
  2234. (forward-line)
  2235. (org-get-indentation))))
  2236. (should
  2237. (zerop
  2238. (org-test-with-temp-text
  2239. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  2240. (let ((org-adapt-indentation t)
  2241. (org-src-preserve-indentation t)
  2242. (org-odd-levels-only nil))
  2243. (org-promote))
  2244. (forward-line)
  2245. (org-get-indentation))))
  2246. (should
  2247. (zerop
  2248. (org-test-with-temp-text
  2249. "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
  2250. (let ((org-adapt-indentation t)
  2251. (org-src-preserve-indentation nil)
  2252. (org-odd-levels-only nil))
  2253. (org-promote))
  2254. (forward-line)
  2255. (org-get-indentation)))))
  2256. ;;; Planning
  2257. (ert-deftest test-org/timestamp-has-time-p ()
  2258. "Test `org-timestamp-has-time-p' specifications."
  2259. ;; With time.
  2260. (should
  2261. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  2262. (org-timestamp-has-time-p (org-element-context))))
  2263. ;; Without time.
  2264. (should-not
  2265. (org-test-with-temp-text "<2012-03-29 Thu>"
  2266. (org-timestamp-has-time-p (org-element-context)))))
  2267. (ert-deftest test-org/timestamp-format ()
  2268. "Test `org-timestamp-format' specifications."
  2269. ;; Regular test.
  2270. (should
  2271. (equal
  2272. "2012-03-29 16:40"
  2273. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  2274. (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
  2275. ;; Range end.
  2276. (should
  2277. (equal
  2278. "2012-03-29"
  2279. (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
  2280. (org-timestamp-format (org-element-context) "%Y-%m-%d" t)))))
  2281. (ert-deftest test-org/timestamp-split-range ()
  2282. "Test `org-timestamp-split-range' specifications."
  2283. ;; Extract range start (active).
  2284. (should
  2285. (equal '(2012 3 29)
  2286. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  2287. (let ((ts (org-timestamp-split-range (org-element-context))))
  2288. (mapcar (lambda (p) (org-element-property p ts))
  2289. '(:year-end :month-end :day-end))))))
  2290. ;; Extract range start (inactive)
  2291. (should
  2292. (equal '(2012 3 29)
  2293. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  2294. (let ((ts (org-timestamp-split-range (org-element-context))))
  2295. (mapcar (lambda (p) (org-element-property p ts))
  2296. '(:year-end :month-end :day-end))))))
  2297. ;; Extract range end (active).
  2298. (should
  2299. (equal '(2012 3 30)
  2300. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  2301. (let ((ts (org-timestamp-split-range
  2302. (org-element-context) t)))
  2303. (mapcar (lambda (p) (org-element-property p ts))
  2304. '(:year-end :month-end :day-end))))))
  2305. ;; Extract range end (inactive)
  2306. (should
  2307. (equal '(2012 3 30)
  2308. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  2309. (let ((ts (org-timestamp-split-range
  2310. (org-element-context) t)))
  2311. (mapcar (lambda (p) (org-element-property p ts))
  2312. '(:year-end :month-end :day-end))))))
  2313. ;; Return the timestamp if not a range.
  2314. (should
  2315. (org-test-with-temp-text "[2012-03-29 Thu]"
  2316. (let* ((ts-orig (org-element-context))
  2317. (ts-copy (org-timestamp-split-range ts-orig)))
  2318. (eq ts-orig ts-copy))))
  2319. (should
  2320. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  2321. (let* ((ts-orig (org-element-context))
  2322. (ts-copy (org-timestamp-split-range ts-orig)))
  2323. (eq ts-orig ts-copy))))
  2324. ;; Check that parent is the same when a range was split.
  2325. (should
  2326. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  2327. (let* ((ts-orig (org-element-context))
  2328. (ts-copy (org-timestamp-split-range ts-orig)))
  2329. (eq (org-element-property :parent ts-orig)
  2330. (org-element-property :parent ts-copy))))))
  2331. (ert-deftest test-org/timestamp-translate ()
  2332. "Test `org-timestamp-translate' specifications."
  2333. ;; Translate whole date range.
  2334. (should
  2335. (equal "<29>--<30>"
  2336. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  2337. (let ((org-display-custom-times t)
  2338. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  2339. (org-timestamp-translate (org-element-context))))))
  2340. ;; Translate date range start.
  2341. (should
  2342. (equal "<29>"
  2343. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  2344. (let ((org-display-custom-times t)
  2345. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  2346. (org-timestamp-translate (org-element-context) 'start)))))
  2347. ;; Translate date range end.
  2348. (should
  2349. (equal "<30>"
  2350. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  2351. (let ((org-display-custom-times t)
  2352. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  2353. (org-timestamp-translate (org-element-context) 'end)))))
  2354. ;; Translate time range.
  2355. (should
  2356. (equal "<08>--<16>"
  2357. (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
  2358. (let ((org-display-custom-times t)
  2359. (org-time-stamp-custom-formats '("<%d>" . "<%H>")))
  2360. (org-timestamp-translate (org-element-context))))))
  2361. ;; Translate non-range timestamp.
  2362. (should
  2363. (equal "<29>"
  2364. (org-test-with-temp-text "<2012-03-29 Thu>"
  2365. (let ((org-display-custom-times t)
  2366. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  2367. (org-timestamp-translate (org-element-context))))))
  2368. ;; Do not change `diary' timestamps.
  2369. (should
  2370. (equal "<%%(org-float t 4 2)>"
  2371. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  2372. (let ((org-display-custom-times t)
  2373. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  2374. (org-timestamp-translate (org-element-context)))))))
  2375. ;;; Property API
  2376. (ert-deftest test-org/buffer-property-keys ()
  2377. "Test `org-buffer-property-keys' specifications."
  2378. ;; Retrieve properties accross siblings.
  2379. (should
  2380. (equal '("A" "B")
  2381. (org-test-with-temp-text "
  2382. * H1
  2383. :PROPERTIES:
  2384. :A: 1
  2385. :END:
  2386. * H2
  2387. :PROPERTIES:
  2388. :B: 1
  2389. :END:"
  2390. (org-buffer-property-keys))))
  2391. ;; Retrieve properties accross children.
  2392. (should
  2393. (equal '("A" "B")
  2394. (org-test-with-temp-text "
  2395. * H1
  2396. :PROPERTIES:
  2397. :A: 1
  2398. :END:
  2399. ** H2
  2400. :PROPERTIES:
  2401. :B: 1
  2402. :END:"
  2403. (org-buffer-property-keys))))
  2404. ;; Retrieve muliple properties in the same drawer.
  2405. (should
  2406. (equal '("A" "B")
  2407. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  2408. (org-buffer-property-keys))))
  2409. ;; Ignore extension symbol in property name.
  2410. (should
  2411. (equal '("A")
  2412. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  2413. (org-buffer-property-keys))))
  2414. ;; With non-nil COLUMNS, extract property names from columns.
  2415. (should
  2416. (equal '("A" "B")
  2417. (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
  2418. (org-buffer-property-keys nil nil t))))
  2419. (should
  2420. (equal '("A" "B" "COLUMNS")
  2421. (org-test-with-temp-text
  2422. "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
  2423. (org-buffer-property-keys nil nil t)))))
  2424. (ert-deftest test-org/property-values ()
  2425. "Test `org-property-values' specifications."
  2426. ;; Regular test.
  2427. (should
  2428. (equal '("2" "1")
  2429. (org-test-with-temp-text
  2430. "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
  2431. (org-property-values "A"))))
  2432. ;; Ignore empty values.
  2433. (should-not
  2434. (org-test-with-temp-text
  2435. "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
  2436. (org-property-values "A")))
  2437. ;; Take into consideration extended values.
  2438. (should
  2439. (equal '("1 2")
  2440. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  2441. (org-property-values "A")))))
  2442. (ert-deftest test-org/entry-delete ()
  2443. "Test `org-entry-delete' specifications."
  2444. ;; Regular test.
  2445. (should
  2446. (string-match
  2447. " *:PROPERTIES:\n *:B: +2\n *:END:"
  2448. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  2449. (org-entry-delete (point) "A")
  2450. (buffer-string))))
  2451. ;; When last property is removed, remove the property drawer.
  2452. (should-not
  2453. (string-match
  2454. ":PROPERTIES:"
  2455. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
  2456. (org-entry-delete (point) "A")
  2457. (buffer-string)))))
  2458. (ert-deftest test-org/entry-get ()
  2459. "Test `org-entry-get' specifications."
  2460. ;; Regular test.
  2461. (should
  2462. (equal "1"
  2463. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  2464. (org-entry-get (point) "A"))))
  2465. ;; Ignore case.
  2466. (should
  2467. (equal "1"
  2468. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  2469. (org-entry-get (point) "a"))))
  2470. ;; Handle extended values, both before and after base value.
  2471. (should
  2472. (equal "1 2 3"
  2473. (org-test-with-temp-text
  2474. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  2475. (org-entry-get (point) "A"))))
  2476. ;; Empty values are returned as the empty string.
  2477. (should
  2478. (equal ""
  2479. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
  2480. (org-entry-get (point) "A"))))
  2481. ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
  2482. ;; otherwise, return nil.
  2483. (should-not
  2484. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  2485. (org-entry-get (point) "A")))
  2486. (should
  2487. (equal "nil"
  2488. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  2489. (org-entry-get (point) "A" nil t))))
  2490. ;; Return nil when no property is found, independently on the
  2491. ;; LITERAL-NIL argument.
  2492. (should-not
  2493. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  2494. (org-entry-get (point) "B")))
  2495. (should-not
  2496. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  2497. (org-entry-get (point) "B" nil t)))
  2498. ;; Handle inheritance, when allowed.
  2499. (should
  2500. (equal
  2501. "1"
  2502. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
  2503. (org-entry-get (point) "A" t))))
  2504. (should
  2505. (equal
  2506. "1"
  2507. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
  2508. (let ((org-use-property-inheritance t))
  2509. (org-entry-get (point) "A" 'selective)))))
  2510. (should-not
  2511. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
  2512. (let ((org-use-property-inheritance nil))
  2513. (org-entry-get (point) "A" 'selective)))))
  2514. (ert-deftest test-org/entry-properties ()
  2515. "Test `org-entry-properties' specifications."
  2516. ;; Get "ITEM" property.
  2517. (should
  2518. (equal "* H"
  2519. (org-test-with-temp-text "* TODO H"
  2520. (cdr (assoc "ITEM" (org-entry-properties nil "ITEM"))))))
  2521. (should
  2522. (equal "* H"
  2523. (org-test-with-temp-text "* TODO H"
  2524. (cdr (assoc "ITEM" (org-entry-properties))))))
  2525. ;; Get "TODO" property.
  2526. (should
  2527. (equal "TODO"
  2528. (org-test-with-temp-text "* TODO H"
  2529. (cdr (assoc "TODO" (org-entry-properties nil "TODO"))))))
  2530. (should
  2531. (equal "TODO"
  2532. (org-test-with-temp-text "* TODO H"
  2533. (cdr (assoc "TODO" (org-entry-properties))))))
  2534. (should-not
  2535. (org-test-with-temp-text "* H"
  2536. (assoc "TODO" (org-entry-properties nil "TODO"))))
  2537. ;; Get "PRIORITY" property.
  2538. (should
  2539. (equal "A"
  2540. (org-test-with-temp-text "* [#A] H"
  2541. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  2542. (should
  2543. (equal "A"
  2544. (org-test-with-temp-text "* [#A] H"
  2545. (cdr (assoc "PRIORITY" (org-entry-properties))))))
  2546. (should-not
  2547. (org-test-with-temp-text "* H"
  2548. (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))
  2549. ;; Get "FILE" property.
  2550. (should
  2551. (org-test-with-temp-text-in-file "* H\nParagraph"
  2552. (org-file-equal-p (cdr (assoc "FILE" (org-entry-properties nil "FILE")))
  2553. (buffer-file-name))))
  2554. (should
  2555. (org-test-with-temp-text-in-file "* H\nParagraph"
  2556. (org-file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
  2557. (buffer-file-name))))
  2558. (should-not
  2559. (org-test-with-temp-text "* H\nParagraph"
  2560. (cdr (assoc "FILE" (org-entry-properties nil "FILE")))))
  2561. ;; Get "TAGS" property.
  2562. (should
  2563. (equal ":tag1:tag2:"
  2564. (org-test-with-temp-text "* H :tag1:tag2:"
  2565. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS"))))))
  2566. (should
  2567. (equal ":tag1:tag2:"
  2568. (org-test-with-temp-text "* H :tag1:tag2:"
  2569. (cdr (assoc "TAGS" (org-entry-properties))))))
  2570. (should-not
  2571. (org-test-with-temp-text "* H"
  2572. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS")))))
  2573. ;; Get "ALLTAGS" property.
  2574. (should
  2575. (equal ":tag1:tag2:"
  2576. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  2577. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS"))))))
  2578. (should
  2579. (equal ":tag1:tag2:"
  2580. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  2581. (cdr (assoc "ALLTAGS" (org-entry-properties))))))
  2582. (should-not
  2583. (org-test-with-temp-text "* H"
  2584. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS")))))
  2585. ;; Get "BLOCKED" property.
  2586. (should
  2587. (equal "t"
  2588. (org-test-with-temp-text "* Blocked\n** DONE one\n** TODO two"
  2589. (let ((org-enforce-todo-dependencies t)
  2590. (org-blocker-hook
  2591. '(org-block-todo-from-children-or-siblings-or-parent)))
  2592. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  2593. (should
  2594. (equal "t"
  2595. (org-test-with-temp-text "* Blocked\n** DONE one\n** TODO two"
  2596. (let ((org-enforce-todo-dependencies t)
  2597. (org-blocker-hook
  2598. '(org-block-todo-from-children-or-siblings-or-parent)))
  2599. (cdr (assoc "BLOCKED" (org-entry-properties)))))))
  2600. (should
  2601. (equal ""
  2602. (org-test-with-temp-text "* Blocked\n** DONE one\n** DONE two"
  2603. (let ((org-enforce-todo-dependencies t))
  2604. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  2605. ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
  2606. (should
  2607. (equal
  2608. "[2012-03-29 thu.]"
  2609. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  2610. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED"))))))
  2611. (should
  2612. (equal
  2613. "[2012-03-29 thu.]"
  2614. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  2615. (cdr (assoc "CLOSED" (org-entry-properties))))))
  2616. (should-not
  2617. (org-test-with-temp-text "* H"
  2618. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED")))))
  2619. (should
  2620. (equal
  2621. "<2014-03-04 tue.>"
  2622. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  2623. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE"))))))
  2624. (should
  2625. (equal
  2626. "<2014-03-04 tue.>"
  2627. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  2628. (cdr (assoc "DEADLINE" (org-entry-properties))))))
  2629. (should-not
  2630. (org-test-with-temp-text "* H"
  2631. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE")))))
  2632. (should
  2633. (equal
  2634. "<2014-03-04 tue.>"
  2635. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  2636. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED"))))))
  2637. (should
  2638. (equal
  2639. "<2014-03-04 tue.>"
  2640. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  2641. (cdr (assoc "SCHEDULED" (org-entry-properties))))))
  2642. (should-not
  2643. (org-test-with-temp-text "* H"
  2644. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED")))))
  2645. ;; Get "CATEGORY"
  2646. (should
  2647. (equal "cat"
  2648. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  2649. (cdr (assoc "CATEGORY" (org-entry-properties))))))
  2650. (should
  2651. (equal "cat"
  2652. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  2653. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  2654. (should
  2655. (equal "cat"
  2656. (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
  2657. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  2658. ;; Get standard properties.
  2659. (should
  2660. (equal "1"
  2661. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  2662. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  2663. ;; Handle extended properties.
  2664. (should
  2665. (equal "1 2 3"
  2666. (org-test-with-temp-text
  2667. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  2668. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  2669. (should
  2670. (equal "1 2 3"
  2671. (org-test-with-temp-text
  2672. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
  2673. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  2674. ;; Ignore forbidden (special) properties.
  2675. (should-not
  2676. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
  2677. (cdr (assoc "TODO" (org-entry-properties nil 'standard))))))
  2678. (ert-deftest test-org/entry-put ()
  2679. "Test `org-entry-put' specifications."
  2680. ;; Error when not a string or nil.
  2681. (should-error
  2682. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  2683. (org-entry-put 1 "test" 2)))
  2684. ;; Set "TODO" property.
  2685. (should
  2686. (string-match (regexp-quote " TODO H")
  2687. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  2688. (org-entry-put (point) "TODO" "TODO")
  2689. (buffer-string))))
  2690. (should
  2691. (string-match (regexp-quote "* H")
  2692. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  2693. (org-entry-put (point) "TODO" nil)
  2694. (buffer-string))))
  2695. ;; Set "PRIORITY" property.
  2696. (should
  2697. (equal "* [#A] H"
  2698. (org-test-with-temp-text "* [#B] H"
  2699. (org-entry-put (point) "PRIORITY" "A")
  2700. (buffer-string))))
  2701. (should
  2702. (equal "* H"
  2703. (org-test-with-temp-text "* [#B] H"
  2704. (org-entry-put (point) "PRIORITY" nil)
  2705. (buffer-string))))
  2706. ;; Set "SCHEDULED" property.
  2707. (should
  2708. (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
  2709. (org-test-with-temp-text "* H"
  2710. (org-entry-put (point) "SCHEDULED" "2014-03-04")
  2711. (buffer-string))))
  2712. (should
  2713. (string= "* H\n"
  2714. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  2715. (org-entry-put (point) "SCHEDULED" nil)
  2716. (buffer-string))))
  2717. (should
  2718. (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
  2719. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  2720. (org-entry-put (point) "SCHEDULED" "earlier")
  2721. (buffer-string))))
  2722. (should
  2723. (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
  2724. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  2725. (org-entry-put (point) "SCHEDULED" "later")
  2726. (buffer-string))))
  2727. ;; Set "DEADLINE" property.
  2728. (should
  2729. (string-match "^ *DEADLINE: <2014-03-04 .*?>"
  2730. (org-test-with-temp-text "* H"
  2731. (org-entry-put (point) "DEADLINE" "2014-03-04")
  2732. (buffer-string))))
  2733. (should
  2734. (string= "* H\n"
  2735. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  2736. (org-entry-put (point) "DEADLINE" nil)
  2737. (buffer-string))))
  2738. (should
  2739. (string-match "^ *DEADLINE: <2014-03-03 .*?>"
  2740. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  2741. (org-entry-put (point) "DEADLINE" "earlier")
  2742. (buffer-string))))
  2743. (should
  2744. (string-match "^ *DEADLINE: <2014-03-05 .*?>"
  2745. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  2746. (org-entry-put (point) "DEADLINE" "later")
  2747. (buffer-string))))
  2748. ;; Regular properties, with or without pre-existing drawer.
  2749. (should
  2750. (string-match "^ *:A: +2$"
  2751. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  2752. (org-entry-put (point) "A" "2")
  2753. (buffer-string))))
  2754. (should
  2755. (string-match "^ *:A: +1$"
  2756. (org-test-with-temp-text "* H"
  2757. (org-entry-put (point) "A" "1")
  2758. (buffer-string))))
  2759. ;; Special case: two consecutive headlines.
  2760. (should
  2761. (string-match "\\* A\n *:PROPERTIES:"
  2762. (org-test-with-temp-text "* A\n** B"
  2763. (org-entry-put (point) "A" "1")
  2764. (buffer-string)))))
  2765. ;;; Radio Targets
  2766. (ert-deftest test-org/update-radio-target-regexp ()
  2767. "Test `org-update-radio-target-regexp' specifications."
  2768. ;; Properly update cache with no previous radio target regexp.
  2769. (should
  2770. (eq 'link
  2771. (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
  2772. (save-excursion (goto-char (point-max)) (org-element-context))
  2773. (insert "<<<")
  2774. (search-forward "o")
  2775. (insert ">>>")
  2776. (org-update-radio-target-regexp)
  2777. (goto-char (point-max))
  2778. (org-element-type (org-element-context)))))
  2779. ;; Properly update cache with previous radio target regexp.
  2780. (should
  2781. (eq 'link
  2782. (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
  2783. (save-excursion (goto-char (point-max)) (org-element-context))
  2784. (insert "<<<")
  2785. (search-forward "o")
  2786. (insert ">>>")
  2787. (org-update-radio-target-regexp)
  2788. (search-backward "r")
  2789. (delete-char 5)
  2790. (insert "new")
  2791. (org-update-radio-target-regexp)
  2792. (goto-char (point-max))
  2793. (delete-region (line-beginning-position) (point))
  2794. (insert "new")
  2795. (org-element-type (org-element-context))))))
  2796. ;;; Sparse trees
  2797. (ert-deftest test-org/match-sparse-tree ()
  2798. "Test `org-match-sparse-tree' specifications."
  2799. ;; Match tags.
  2800. (should-not
  2801. (org-test-with-temp-text "* H\n** H1 :tag:"
  2802. (org-match-sparse-tree nil "tag")
  2803. (search-forward "H1")
  2804. (org-invisible-p2)))
  2805. (should
  2806. (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
  2807. (org-match-sparse-tree nil "tag")
  2808. (search-forward "H2")
  2809. (org-invisible-p2)))
  2810. ;; "-" operator for tags.
  2811. (should-not
  2812. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  2813. (org-match-sparse-tree nil "tag1-tag2")
  2814. (search-forward "H1")
  2815. (org-invisible-p2)))
  2816. (should
  2817. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  2818. (org-match-sparse-tree nil "tag1-tag2")
  2819. (search-forward "H2")
  2820. (org-invisible-p2)))
  2821. ;; "&" operator for tags.
  2822. (should
  2823. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  2824. (org-match-sparse-tree nil "tag1&tag2")
  2825. (search-forward "H1")
  2826. (org-invisible-p2)))
  2827. (should-not
  2828. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  2829. (org-match-sparse-tree nil "tag1&tag2")
  2830. (search-forward "H2")
  2831. (org-invisible-p2)))
  2832. ;; "|" operator for tags.
  2833. (should-not
  2834. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  2835. (org-match-sparse-tree nil "tag1|tag2")
  2836. (search-forward "H1")
  2837. (org-invisible-p2)))
  2838. (should-not
  2839. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  2840. (org-match-sparse-tree nil "tag1|tag2")
  2841. (search-forward "H2")
  2842. (org-invisible-p2)))
  2843. ;; Regexp match on tags.
  2844. (should-not
  2845. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  2846. (org-match-sparse-tree nil "{^tag.*}")
  2847. (search-forward "H1")
  2848. (org-invisible-p2)))
  2849. (should
  2850. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  2851. (org-match-sparse-tree nil "{^tag.*}")
  2852. (search-forward "H2")
  2853. (org-invisible-p2)))
  2854. ;; Match group tags.
  2855. (should-not
  2856. (org-test-with-temp-text
  2857. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  2858. (org-match-sparse-tree nil "work")
  2859. (search-forward "H1")
  2860. (org-invisible-p2)))
  2861. (should-not
  2862. (org-test-with-temp-text
  2863. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  2864. (org-match-sparse-tree nil "work")
  2865. (search-forward "H2")
  2866. (org-invisible-p2)))
  2867. ;; Match properties.
  2868. (should
  2869. (org-test-with-temp-text
  2870. "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
  2871. (org-match-sparse-tree nil "A=\"1\"")
  2872. (search-forward "H2")
  2873. (org-invisible-p2)))
  2874. (should-not
  2875. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  2876. (org-match-sparse-tree nil "A=\"1\"")
  2877. (search-forward "H2")
  2878. (org-invisible-p2)))
  2879. ;; Case is not significant when matching properties.
  2880. (should-not
  2881. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  2882. (org-match-sparse-tree nil "a=\"1\"")
  2883. (search-forward "H2")
  2884. (org-invisible-p2)))
  2885. (should-not
  2886. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
  2887. (org-match-sparse-tree nil "A=\"1\"")
  2888. (search-forward "H2")
  2889. (org-invisible-p2)))
  2890. ;; Match special LEVEL property.
  2891. (should-not
  2892. (org-test-with-temp-text "* H\n** H1\n*** H2"
  2893. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  2894. (search-forward "H1")
  2895. (org-invisible-p2)))
  2896. (should
  2897. (org-test-with-temp-text "* H\n** H1\n*** H2"
  2898. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  2899. (search-forward "H2")
  2900. (org-invisible-p2)))
  2901. ;; Comparison operators when matching properties.
  2902. (should
  2903. (org-test-with-temp-text
  2904. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  2905. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  2906. (search-forward "H1")
  2907. (org-invisible-p2)))
  2908. (should-not
  2909. (org-test-with-temp-text
  2910. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  2911. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  2912. (search-forward "H2")
  2913. (org-invisible-p2)))
  2914. ;; Regexp match on properties values.
  2915. (should-not
  2916. (org-test-with-temp-text
  2917. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  2918. (org-match-sparse-tree nil "A={f.*}")
  2919. (search-forward "H1")
  2920. (org-invisible-p2)))
  2921. (should
  2922. (org-test-with-temp-text
  2923. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  2924. (org-match-sparse-tree nil "A={f.*}")
  2925. (search-forward "H2")
  2926. (org-invisible-p2)))
  2927. ;; With an optional argument, limit match to TODO entries.
  2928. (should-not
  2929. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  2930. (org-match-sparse-tree t "tag")
  2931. (search-forward "H1")
  2932. (org-invisible-p2)))
  2933. (should
  2934. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  2935. (org-match-sparse-tree t "tag")
  2936. (search-forward "H2")
  2937. (org-invisible-p2))))
  2938. ;;; Visibility
  2939. (ert-deftest test-org/flag-drawer ()
  2940. "Test `org-flag-drawer' specifications."
  2941. ;; Hide drawer.
  2942. (should
  2943. (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
  2944. (org-flag-drawer t)
  2945. (get-char-property (line-end-position) 'invisible)))
  2946. ;; Show drawer.
  2947. (should-not
  2948. (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
  2949. (org-flag-drawer t)
  2950. (org-flag-drawer nil)
  2951. (get-char-property (line-end-position) 'invisible)))
  2952. ;; Test optional argument.
  2953. (should
  2954. (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
  2955. (let ((drawer (save-excursion (search-forward ":D2")
  2956. (org-element-at-point))))
  2957. (org-flag-drawer t drawer)
  2958. (get-char-property (progn (search-forward ":D2") (line-end-position))
  2959. 'invisible))))
  2960. (should-not
  2961. (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
  2962. (let ((drawer (save-excursion (search-forward ":D2")
  2963. (org-element-at-point))))
  2964. (org-flag-drawer t drawer)
  2965. (get-char-property (line-end-position) 'invisible))))
  2966. ;; Do not hide fake drawers.
  2967. (should-not
  2968. (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
  2969. (forward-line 1)
  2970. (org-flag-drawer t)
  2971. (get-char-property (line-end-position) 'invisible)))
  2972. ;; Do not hide incomplete drawers.
  2973. (should-not
  2974. (org-test-with-temp-text ":D:\nparagraph"
  2975. (forward-line 1)
  2976. (org-flag-drawer t)
  2977. (get-char-property (line-end-position) 'invisible)))
  2978. ;; Do not hide drawers when called from final blank lines.
  2979. (should-not
  2980. (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
  2981. (goto-char (point-max))
  2982. (org-flag-drawer t)
  2983. (goto-char (point-min))
  2984. (get-char-property (line-end-position) 'invisible)))
  2985. ;; Don't leave point in an invisible part of the buffer when hiding
  2986. ;; a drawer away.
  2987. (should-not
  2988. (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
  2989. (goto-char (point-max))
  2990. (org-flag-drawer t)
  2991. (get-char-property (point) 'invisible))))
  2992. (ert-deftest test-org/hide-block-toggle ()
  2993. "Test `org-hide-block-toggle' specifications."
  2994. ;; Error when not at a block.
  2995. (should-error
  2996. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
  2997. (org-hide-block-toggle 'off)
  2998. (get-char-property (line-end-position) 'invisible)))
  2999. ;; Hide block.
  3000. (should
  3001. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  3002. (org-hide-block-toggle)
  3003. (get-char-property (line-end-position) 'invisible)))
  3004. (should
  3005. (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
  3006. (org-hide-block-toggle)
  3007. (get-char-property (line-end-position) 'invisible)))
  3008. ;; Show block unconditionally when optional argument is `off'.
  3009. (should-not
  3010. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  3011. (org-hide-block-toggle)
  3012. (org-hide-block-toggle 'off)
  3013. (get-char-property (line-end-position) 'invisible)))
  3014. (should-not
  3015. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  3016. (org-hide-block-toggle 'off)
  3017. (get-char-property (line-end-position) 'invisible)))
  3018. ;; Hide block unconditionally when optional argument is non-nil.
  3019. (should
  3020. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  3021. (org-hide-block-toggle t)
  3022. (get-char-property (line-end-position) 'invisible)))
  3023. (should
  3024. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  3025. (org-hide-block-toggle)
  3026. (org-hide-block-toggle t)
  3027. (get-char-property (line-end-position) 'invisible)))
  3028. ;; Do not hide block when called from final blank lines.
  3029. (should-not
  3030. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
  3031. (org-hide-block-toggle)
  3032. (goto-char (point-min))
  3033. (get-char-property (line-end-position) 'invisible)))
  3034. ;; Don't leave point in an invisible part of the buffer when hiding
  3035. ;; a block away.
  3036. (should-not
  3037. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
  3038. (org-hide-block-toggle)
  3039. (get-char-property (point) 'invisible))))
  3040. (ert-deftest test-org/hide-block-toggle-maybe ()
  3041. "Test `org-hide-block-toggle-maybe' specifications."
  3042. (should
  3043. (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
  3044. (org-hide-block-toggle-maybe)))
  3045. (should-not
  3046. (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
  3047. (provide 'test-org)
  3048. ;;; test-org.el ends here