test-org.el 119 KB

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