test-org.el 184 KB

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