test-org.el 145 KB

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