test-org.el 117 KB

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