test-org.el 148 KB

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