test-org.el 198 KB

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