test-org.el 183 KB

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