test-org.el 155 KB

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