test-org.el 198 KB

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