test-org.el 119 KB

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