test-org.el 132 KB

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