test-org.el 273 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430
  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 <https://www.gnu.org/licenses/>.
  15. ;; Template test file for Org tests
  16. ;;; Code:
  17. (eval-and-compile (require 'cl-lib))
  18. ;;; Comments
  19. (ert-deftest test-org/toggle-comment ()
  20. "Test `org-toggle-comment' specifications."
  21. ;; Simple headline.
  22. (should
  23. (equal "* Test"
  24. (org-test-with-temp-text "* COMMENT Test"
  25. (org-toggle-comment)
  26. (buffer-string))))
  27. (should
  28. (equal "* COMMENT Test"
  29. (org-test-with-temp-text "* Test"
  30. (org-toggle-comment)
  31. (buffer-string))))
  32. ;; Headline with a regular keyword.
  33. (should
  34. (equal "* TODO Test"
  35. (org-test-with-temp-text "* TODO COMMENT Test"
  36. (org-toggle-comment)
  37. (buffer-string))))
  38. (should
  39. (equal "* TODO COMMENT Test"
  40. (org-test-with-temp-text "* TODO Test"
  41. (org-toggle-comment)
  42. (buffer-string))))
  43. ;; Empty headline.
  44. (should
  45. (equal "* "
  46. (org-test-with-temp-text "* COMMENT"
  47. (org-toggle-comment)
  48. (buffer-string))))
  49. (should
  50. (equal "* COMMENT"
  51. (org-test-with-temp-text "* "
  52. (org-toggle-comment)
  53. (buffer-string))))
  54. ;; Headline with a single keyword.
  55. (should
  56. (equal "* TODO "
  57. (org-test-with-temp-text "* TODO COMMENT"
  58. (org-toggle-comment)
  59. (buffer-string))))
  60. (should
  61. (equal "* TODO COMMENT"
  62. (org-test-with-temp-text "* TODO"
  63. (org-toggle-comment)
  64. (buffer-string))))
  65. ;; Headline with a keyword, a priority cookie and contents.
  66. (should
  67. (equal "* TODO [#A] Headline"
  68. (org-test-with-temp-text "* TODO [#A] COMMENT Headline"
  69. (org-toggle-comment)
  70. (buffer-string))))
  71. (should
  72. (equal "* TODO [#A] COMMENT Headline"
  73. (org-test-with-temp-text "* TODO [#A] Headline"
  74. (org-toggle-comment)
  75. (buffer-string)))))
  76. (ert-deftest test-org/comment-dwim ()
  77. "Test `comment-dwim' behaviour in an Org buffer."
  78. ;; No region selected, no comment on current line and line not
  79. ;; empty: insert comment on line above.
  80. (should
  81. (equal "# \nComment"
  82. (org-test-with-temp-text "Comment"
  83. (call-interactively #'org-comment-dwim)
  84. (buffer-string))))
  85. ;; No region selected, no comment on current line and line empty:
  86. ;; insert comment on this line.
  87. (should
  88. (equal "# \nParagraph"
  89. (org-test-with-temp-text "\nParagraph"
  90. (call-interactively #'org-comment-dwim)
  91. (buffer-string))))
  92. ;; No region selected, and a comment on this line: indent it.
  93. (should
  94. (equal "* Headline\n # Comment"
  95. (org-test-with-temp-text "* Headline\n# <point>Comment"
  96. (let ((org-adapt-indentation t))
  97. (call-interactively #'org-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. (call-interactively #'org-comment-dwim)
  104. (buffer-string))))
  105. ;; Region selected and only comments and blank lines within it:
  106. ;; un-comment all commented lines.
  107. (should
  108. (equal "Comment 1\n\nComment 2"
  109. (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
  110. (transient-mark-mode 1)
  111. (push-mark (point) t t)
  112. (goto-char (point-max))
  113. (call-interactively #'org-comment-dwim)
  114. (buffer-string))))
  115. ;; Region selected without comments: comment all lines if
  116. ;; `comment-empty-lines' is non-nil, only non-blank lines otherwise.
  117. (should
  118. (equal "# Comment 1\n\n# Comment 2"
  119. (org-test-with-temp-text "Comment 1\n\nComment 2"
  120. (transient-mark-mode 1)
  121. (push-mark (point) t t)
  122. (goto-char (point-max))
  123. (let ((comment-empty-lines nil))
  124. (call-interactively #'org-comment-dwim))
  125. (buffer-string))))
  126. (should
  127. (equal "# Comment 1\n# \n# Comment 2"
  128. (org-test-with-temp-text "Comment 1\n\nComment 2"
  129. (transient-mark-mode 1)
  130. (push-mark (point) t t)
  131. (goto-char (point-max))
  132. (let ((comment-empty-lines t))
  133. (call-interactively #'org-comment-dwim))
  134. (buffer-string))))
  135. ;; In front of a keyword without region, insert a new comment.
  136. (should
  137. (equal "# \n#+KEYWORD: value"
  138. (org-test-with-temp-text "#+KEYWORD: value"
  139. (call-interactively #'org-comment-dwim)
  140. (buffer-string))))
  141. ;; Comment a heading
  142. (should
  143. (equal "* COMMENT Test"
  144. (org-test-with-temp-text "* Test"
  145. (call-interactively #'org-comment-dwim)
  146. (buffer-string))))
  147. ;; In a source block, use appropriate syntax.
  148. (should
  149. (equal " ;; "
  150. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n<point>\n#+END_SRC"
  151. (let ((org-edit-src-content-indentation 2))
  152. (call-interactively #'org-comment-dwim))
  153. (buffer-substring-no-properties (line-beginning-position)
  154. (point)))))
  155. (should
  156. (equal "#+BEGIN_SRC emacs-lisp\n ;; a\n ;; b\n#+END_SRC"
  157. (org-test-with-temp-text
  158. "#+BEGIN_SRC emacs-lisp\n<point>a\nb\n#+END_SRC"
  159. (transient-mark-mode 1)
  160. (push-mark (point) t t)
  161. (forward-line 2)
  162. (let ((org-edit-src-content-indentation 2))
  163. (call-interactively #'org-comment-dwim))
  164. (buffer-string)))))
  165. ;;; Date and time analysis
  166. (ert-deftest test-org/org-read-date ()
  167. "Test `org-read-date' specifications."
  168. ;; Parse ISO date with abbreviated year and month.
  169. (should (equal "2012-03-29 16:40"
  170. (let ((org-time-was-given t))
  171. (org-read-date t nil "12-3-29 16:40"))))
  172. ;; Parse Europeans dates.
  173. (should (equal "2012-03-29 16:40"
  174. (let ((org-time-was-given t))
  175. (org-read-date t nil "29.03.2012 16:40"))))
  176. ;; Parse Europeans dates without year.
  177. (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
  178. (let ((org-time-was-given t))
  179. (org-read-date t nil "29.03. 16:40"))))
  180. ;; Relative date applied to current time if there is single
  181. ;; plus/minus, or to default date when there are two of them.
  182. (should
  183. (equal
  184. "2015-03-04"
  185. (org-test-at-time "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. (org-test-at-time "2014-03-04"
  193. (org-read-date
  194. t nil "++1y" nil
  195. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))
  196. ;; When `org-read-date-prefer-future' is non-nil, prefer future
  197. ;; dates (relatively to now) when incomplete. Otherwise, use
  198. ;; default date.
  199. (should
  200. (equal
  201. "2014-04-01"
  202. (org-test-at-time "2014-03-04"
  203. (let ((org-read-date-prefer-future t))
  204. (org-read-date t nil "1")))))
  205. (should
  206. (equal
  207. "2013-03-04"
  208. (org-test-at-time "2012-03-29"
  209. (let ((org-read-date-prefer-future t))
  210. (org-read-date t nil "3-4")))))
  211. (should
  212. (equal
  213. "2012-03-04"
  214. (org-test-at-time "2012-03-29"
  215. (let ((org-read-date-prefer-future nil))
  216. (org-read-date t nil "3-4")))))
  217. ;; When set to `org-read-date-prefer-future' is set to `time', read
  218. ;; day is moved to tomorrow if specified hour is before current
  219. ;; time. However, it only happens in no other part of the date is
  220. ;; specified.
  221. (should
  222. (equal
  223. "2012-03-30"
  224. (org-test-at-time "2012-03-29 16:40"
  225. (let ((org-read-date-prefer-future 'time))
  226. (org-read-date t nil "00:40" nil)))))
  227. (should-not
  228. (equal
  229. "2012-03-30"
  230. (org-test-at-time "2012-03-29 16:40"
  231. (let ((org-read-date-prefer-future 'time))
  232. (org-read-date t nil "29 00:40" nil)))))
  233. ;; Caveat: `org-read-date-prefer-future' always refers to current
  234. ;; time, not default time, when they differ.
  235. (should
  236. (equal
  237. "2014-04-01"
  238. (org-test-at-time "2014-03-04"
  239. (let ((org-read-date-prefer-future t))
  240. (org-read-date
  241. t nil "1" nil
  242. (apply #'encode-time (org-parse-time-string "2012-03-29")))))))
  243. (should
  244. (equal
  245. "2014-03-25"
  246. (org-test-at-time "2014-03-04"
  247. (let ((org-read-date-prefer-future t))
  248. (org-read-date
  249. t nil "25" nil
  250. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))))
  251. (ert-deftest test-org/org-parse-time-string ()
  252. "Test `org-parse-time-string'."
  253. (should (equal (org-parse-time-string "2012-03-29 16:40")
  254. '(0 40 16 29 3 2012 nil nil nil)))
  255. (should (equal (org-parse-time-string "[2012-03-29 16:40]")
  256. '(0 40 16 29 3 2012 nil nil nil)))
  257. (should (equal (org-parse-time-string "<2012-03-29 16:40>")
  258. '(0 40 16 29 3 2012 nil nil nil)))
  259. (should (equal (org-parse-time-string "<2012-03-29>")
  260. '(0 0 0 29 3 2012 nil nil nil)))
  261. (should (equal (org-parse-time-string "<2012-03-29>" t)
  262. '(0 nil nil 29 3 2012 nil nil nil))))
  263. (ert-deftest test-org/closest-date ()
  264. "Test `org-closest-date' specifications."
  265. (require 'calendar)
  266. ;; Time stamps without a repeater are returned unchanged.
  267. (should
  268. (equal
  269. '(3 29 2012)
  270. (calendar-gregorian-from-absolute
  271. (org-closest-date "<2012-03-29>" "<2014-03-04>" nil))))
  272. ;; Time stamps with a null repeater are returned unchanged.
  273. (should
  274. (equal
  275. '(3 29 2012)
  276. (calendar-gregorian-from-absolute
  277. (org-closest-date "<2012-03-29 +0d>" "<2014-03-04>" nil))))
  278. ;; if PREFER is set to `past' always return a date before, or equal
  279. ;; to CURRENT.
  280. (should
  281. (equal
  282. '(3 1 2014)
  283. (calendar-gregorian-from-absolute
  284. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'past))))
  285. (should
  286. (equal
  287. '(3 4 2014)
  288. (calendar-gregorian-from-absolute
  289. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'past))))
  290. ;; if PREFER is set to `future' always return a date before, or equal
  291. ;; to CURRENT.
  292. (should
  293. (equal
  294. '(3 29 2014)
  295. (calendar-gregorian-from-absolute
  296. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'future))))
  297. (should
  298. (equal
  299. '(3 4 2014)
  300. (calendar-gregorian-from-absolute
  301. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'future))))
  302. ;; If PREFER is neither `past' nor `future', select closest date.
  303. (should
  304. (equal
  305. '(3 1 2014)
  306. (calendar-gregorian-from-absolute
  307. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" nil))))
  308. (should
  309. (equal
  310. '(5 4 2014)
  311. (calendar-gregorian-from-absolute
  312. (org-closest-date "<2012-03-04 +1m>" "<2014-04-28>" nil))))
  313. ;; Test "day" repeater.
  314. (should
  315. (equal '(3 8 2014)
  316. (calendar-gregorian-from-absolute
  317. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'past))))
  318. (should
  319. (equal '(3 10 2014)
  320. (calendar-gregorian-from-absolute
  321. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'future))))
  322. ;; Test "month" repeater.
  323. (should
  324. (equal '(1 5 2015)
  325. (calendar-gregorian-from-absolute
  326. (org-closest-date "<2014-03-05 +2m>" "<2015-02-04>" 'past))))
  327. (should
  328. (equal '(3 29 2014)
  329. (calendar-gregorian-from-absolute
  330. (org-closest-date "<2012-03-29 +2m>" "<2014-03-04>" 'future))))
  331. ;; Test "year" repeater.
  332. (should
  333. (equal '(3 5 2014)
  334. (calendar-gregorian-from-absolute
  335. (org-closest-date "<2014-03-05 +2y>" "<2015-02-04>" 'past))))
  336. (should
  337. (equal '(3 29 2014)
  338. (calendar-gregorian-from-absolute
  339. (org-closest-date "<2012-03-29 +2y>" "<2014-03-04>" 'future)))))
  340. (ert-deftest test-org/deadline-close-p ()
  341. "Test `org-deadline-close-p' specifications."
  342. (org-test-at-time "2016-06-03 Fri 01:43"
  343. ;; Timestamps are close if they are within `ndays' of lead time.
  344. (org-test-with-temp-text "* Heading"
  345. (should (org-deadline-close-p "2016-06-03 Fri" 0))
  346. (should (org-deadline-close-p "2016-06-02 Thu" 0))
  347. (should-not (org-deadline-close-p "2016-06-04 Sat" 0))
  348. (should (org-deadline-close-p "2016-06-04 Sat" 1))
  349. (should (org-deadline-close-p "2016-06-03 Fri 12:00" 0)))
  350. ;; Read `ndays' from timestamp if argument not given.
  351. (org-test-with-temp-text "* H"
  352. (should (org-deadline-close-p "2016-06-04 Sat -1d"))
  353. (should-not (org-deadline-close-p "2016-06-04 Sat -0d"))
  354. (should (org-deadline-close-p "2016-06-10 Fri -1w"))
  355. (should-not (org-deadline-close-p "2016-06-11 Sat -1w")))
  356. ;; Prefer `ndays' argument over lead time in timestamp.
  357. (org-test-with-temp-text "* H"
  358. (should (org-deadline-close-p "2016-06-04 Sat -0d" 1))
  359. (should-not (org-deadline-close-p "2016-06-04 Sat -0d" 0)))
  360. ;; Completed tasks are never close.
  361. (let ((org-todo-keywords '(("TODO" "|" "DONE"))))
  362. (org-test-with-temp-text "* TODO Heading"
  363. (should (org-deadline-close-p "2016-06-03")))
  364. (org-test-with-temp-text "* DONE Heading"
  365. (should-not (org-deadline-close-p "2016-06-03"))))))
  366. ;;; Drawers
  367. (ert-deftest test-org/at-property-p ()
  368. "Test `org-at-property-p' specifications."
  369. (should
  370. (equal 't
  371. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:PROP: t\n:END:\n"
  372. (org-at-property-p))))
  373. (should
  374. (equal 't
  375. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n:END:\n"
  376. (org-at-property-p)))))
  377. (ert-deftest test-org/at-property-drawer-p ()
  378. "Test `org-at-property-drawer-p' specifications."
  379. (should
  380. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:PROP: t\n:END:\n"
  381. (org-at-property-drawer-p)))
  382. (should
  383. (org-test-with-temp-text ":PROPERTIES:\n:PROP: t\n:END:\n"
  384. (org-at-property-drawer-p)))
  385. ;; The function only returns t if point is at the first line of
  386. ;; a property block.
  387. (should-not
  388. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n:END:\n"
  389. (org-at-property-drawer-p)))
  390. ;; The function ignores incomplete drawers.
  391. (should-not
  392. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n"
  393. (org-at-property-drawer-p)))
  394. ;; tab separating the value.
  395. (should
  396. (org-test-with-temp-text ":PROPERTIES:\n:PROP: t\n:END:\n"
  397. (org-at-property-drawer-p))))
  398. (ert-deftest test-org/get-property-block ()
  399. "Test `org-get-property-block' specifications."
  400. (should
  401. (equal '(14 . 14)
  402. (org-test-with-temp-text ":PROPERTIES:\n:END:\n* H\n"
  403. (org-get-property-block))))
  404. (should
  405. (equal '(14 . 14)
  406. (org-test-with-temp-text ":PROPERTIES:\n:END:\n"
  407. (org-get-property-block))))
  408. ;; Comments above a document property block is ok.
  409. (should
  410. (equal '(18 . 18)
  411. (org-test-with-temp-text "# C\n:PROPERTIES:\n:END:\n"
  412. (org-get-property-block))))
  413. ;; Keywords above a document property block is ok.
  414. (should
  415. (equal '(22 . 22)
  416. (org-test-with-temp-text "# C\n# C\n:PROPERTIES:\n:END:\n"
  417. (org-get-property-block))))
  418. ;; Comments and keywords are allowed before a document property block.
  419. (should
  420. (equal '(18 . 27)
  421. (org-test-with-temp-text "# C\n:PROPERTIES:\n:KEY: V:\n:END:\n"
  422. (org-get-property-block))))
  423. ;; A document property block will not be valid if there are lines
  424. ;; with whitespace above it
  425. (should-not
  426. (org-test-with-temp-text "\n:PROPERTIES:\n:END:\n"
  427. (org-get-property-block)))
  428. (should
  429. (equal '(18 . 18)
  430. (org-test-with-temp-text "* H\n:PROPERTIES:\n:END:\n<point>"
  431. (org-get-property-block))))
  432. (should
  433. (equal "* H\n:PROPERTIES:\n:END:\n"
  434. (org-test-with-temp-text "* H"
  435. (let ((org-adapt-indentation nil))
  436. (org-get-property-block nil 'force))
  437. (buffer-string))))
  438. (should
  439. (equal ":PROPERTIES:\n:END:\n"
  440. (org-test-with-temp-text ""
  441. (org-get-property-block nil 'force)
  442. (buffer-string))))
  443. (should
  444. (equal "* H1\n :PROPERTIES:\n :END:\n* H2"
  445. (org-test-with-temp-text "* H1\n* H2"
  446. (let ((org-adapt-indentation t))
  447. (org-get-property-block nil 'force))
  448. (buffer-string)))))
  449. (ert-deftest test-org/insert-property-drawer ()
  450. "Test `org-insert-property-drawer' specifications."
  451. ;; Insert drawer in empty buffer
  452. (should
  453. (equal ":PROPERTIES:\n:END:\n"
  454. (org-test-with-temp-text ""
  455. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  456. (buffer-string))))
  457. ;; Insert drawer in document header with existing comment and
  458. ;; keyword.
  459. (should
  460. (equal "# C\n:PROPERTIES:\n:END:\n#+TITLE: T"
  461. (org-test-with-temp-text "# C\n#+TITLE: T"
  462. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  463. (buffer-string))))
  464. ;; Insert drawer in document header with existing keyword.
  465. (should
  466. (equal ":PROPERTIES:\n:END:\n#+TITLE: T"
  467. (org-test-with-temp-text "#+TITLE: T"
  468. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  469. (buffer-string))))
  470. (should
  471. (equal ":PROPERTIES:\n:END:"
  472. (org-test-with-temp-text ":PROPERTIES:\n:END:"
  473. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  474. (buffer-string))))
  475. ;; Insert drawer in document header with one existing heading in buffer.
  476. (should
  477. (equal ":PROPERTIES:\n:END:\n\n* T\n"
  478. (org-test-with-temp-text "\n* T\n"
  479. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  480. (buffer-string))))
  481. ;; Insert drawer right after headline if there is no planning line,
  482. ;; or after it otherwise.
  483. (should
  484. (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
  485. (org-test-with-temp-text "* H\nParagraph<point>"
  486. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  487. (buffer-string))))
  488. (should
  489. (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
  490. (org-test-with-temp-text
  491. "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
  492. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  493. (buffer-string))))
  494. ;; Indent inserted drawer.
  495. (should
  496. (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
  497. (org-test-with-temp-text "* H\nParagraph<point>"
  498. (let ((org-adapt-indentation t)) (org-insert-property-drawer))
  499. (buffer-string))))
  500. ;; Handle insertion at eob.
  501. (should
  502. (equal "* H\n:PROPERTIES:\n:END:\n"
  503. (org-test-with-temp-text "* H"
  504. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  505. (buffer-string))))
  506. ;; Skip inlinetasks before point.
  507. (when (featurep 'org-inlinetask)
  508. (should
  509. (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
  510. (org-test-with-temp-text
  511. "* H\n*************** I\n*************** END\nP<point>"
  512. (let ((org-adapt-indentation nil)
  513. (org-inlinetask-min-level 15))
  514. (org-insert-property-drawer))
  515. (buffer-string)))))
  516. ;; Correctly set drawer in an inlinetask.
  517. (when (featurep 'org-inlinetask)
  518. (should
  519. (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
  520. (org-test-with-temp-text
  521. "* H\n*************** I\nP<point>\n*************** END"
  522. (let ((org-adapt-indentation nil)
  523. (org-inlinetask-min-level 15))
  524. (org-insert-property-drawer))
  525. (buffer-string))))))
  526. ;;; Filling
  527. (ert-deftest test-org/fill-element ()
  528. "Test `org-fill-element' specifications."
  529. ;; At an Org table, align it.
  530. (should
  531. (equal "| a |\n"
  532. (org-test-with-temp-text "|a|"
  533. (org-fill-element)
  534. (buffer-string))))
  535. (should
  536. (equal "#+name: table\n| a |\n"
  537. (org-test-with-temp-text "#+name: table\n| a |\n"
  538. (org-fill-element)
  539. (buffer-string))))
  540. ;; At a paragraph, preserve line breaks.
  541. (org-test-with-temp-text "some \\\\\nlong\ntext"
  542. (let ((fill-column 20))
  543. (org-fill-element)
  544. (should (equal (buffer-string) "some \\\\\nlong text"))))
  545. ;; Correctly fill a paragraph when point is at its very end.
  546. (should
  547. (equal "A B"
  548. (org-test-with-temp-text "A\nB"
  549. (let ((fill-column 20))
  550. (goto-char (point-max))
  551. (org-fill-element)
  552. (buffer-string)))))
  553. ;; Correctly fill the last paragraph of a greater element.
  554. (should
  555. (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
  556. (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
  557. (let ((fill-column 8))
  558. (forward-line)
  559. (end-of-line)
  560. (org-fill-element)
  561. (buffer-string)))))
  562. ;; Correctly fill an element in a narrowed buffer.
  563. (should
  564. (equal "01234\n6"
  565. (org-test-with-temp-text "01234 6789"
  566. (let ((fill-column 5))
  567. (narrow-to-region 1 8)
  568. (org-fill-element)
  569. (buffer-string)))))
  570. ;; Handle `adaptive-fill-regexp' in paragraphs.
  571. (should
  572. (equal "> a b"
  573. (org-test-with-temp-text "> a\n> b"
  574. (let ((fill-column 5)
  575. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  576. (org-fill-element)
  577. (buffer-string)))))
  578. ;; Special case: Fill first paragraph when point is at an item or
  579. ;; a plain-list or a footnote reference.
  580. (should
  581. (equal "- A B"
  582. (org-test-with-temp-text "- A\n B"
  583. (let ((fill-column 20))
  584. (org-fill-element)
  585. (buffer-string)))))
  586. (should
  587. (equal "[fn:1] A B"
  588. (org-test-with-temp-text "[fn:1] A\nB"
  589. (let ((fill-column 20))
  590. (org-fill-element)
  591. (buffer-string)))))
  592. (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
  593. (let ((fill-column 20))
  594. (org-fill-element)
  595. (should (equal (buffer-string)
  596. "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
  597. ;; Fill contents of `comment-block' elements.
  598. (should
  599. (equal
  600. (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
  601. (let ((fill-column 20))
  602. (forward-line)
  603. (org-fill-element)
  604. (buffer-string)))
  605. "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
  606. ;; Fill `comment' elements.
  607. (should
  608. (equal " # A B"
  609. (org-test-with-temp-text " # A\n # B"
  610. (let ((fill-column 20))
  611. (org-fill-element)
  612. (buffer-string)))))
  613. ;; Do not mix consecutive comments when filling one of them.
  614. (should
  615. (equal "# A B\n\n# C"
  616. (org-test-with-temp-text "# A\n# B\n\n# C"
  617. (let ((fill-column 20))
  618. (org-fill-element)
  619. (buffer-string)))))
  620. ;; Use commented empty lines as separators when filling comments.
  621. (should
  622. (equal "# A B\n#\n# C"
  623. (org-test-with-temp-text "# A\n# B\n#\n# C"
  624. (let ((fill-column 20))
  625. (org-fill-element)
  626. (buffer-string)))))
  627. ;; Handle `adaptive-fill-regexp' in comments.
  628. (should
  629. (equal "# > a b"
  630. (org-test-with-temp-text "# > a\n# > b"
  631. (let ((fill-column 20)
  632. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  633. (org-fill-element)
  634. (buffer-string)))))
  635. ;; Do nothing at affiliated keywords.
  636. (should
  637. (equal "#+NAME: para\nSome\ntext."
  638. (org-test-with-temp-text "#+NAME: para\nSome\ntext."
  639. (let ((fill-column 20))
  640. (org-fill-element)
  641. (buffer-string)))))
  642. ;; Do not move point after table when filling a table.
  643. (should-not
  644. (org-test-with-temp-text "| a | b |\n| c | d |\n"
  645. (forward-char)
  646. (org-fill-element)
  647. (eobp)))
  648. ;; Do not fill "n" macro, with or without arguments, followed by
  649. ;; a dot or a closing parenthesis since it could be confused with
  650. ;; a numbered bullet.
  651. (should-not
  652. (equal "123456789\n{{{n}}}."
  653. (org-test-with-temp-text "123456789 {{{n}}}."
  654. (let ((fill-column 10))
  655. (org-fill-element)
  656. (buffer-string)))))
  657. (should-not
  658. (equal "123456789\n{{{n}}}\)"
  659. (org-test-with-temp-text "123456789 {{{n}}}\)"
  660. (let ((fill-column 10))
  661. (org-fill-element)
  662. (buffer-string)))))
  663. (should-not
  664. (equal "123456789\n{{{n()}}}."
  665. (org-test-with-temp-text "123456789 {{{n()}}}."
  666. (let ((fill-column 10))
  667. (org-fill-element)
  668. (buffer-string)))))
  669. (should-not
  670. (equal "123456789\n{{{n(counter)}}}."
  671. (org-test-with-temp-text "123456789 {{{n(counter)}}}."
  672. (let ((fill-column 10))
  673. (org-fill-element)
  674. (buffer-string))))))
  675. (ert-deftest test-org/fill-paragraph ()
  676. "Test `org-fill-paragraph' specifications."
  677. ;; Regular test.
  678. (should
  679. (equal "012345678\n9"
  680. (org-test-with-temp-text "012345678 9"
  681. (let ((fill-column 10))
  682. (org-fill-paragraph)
  683. (buffer-string)))))
  684. ;; Fill paragraph even at end of buffer.
  685. (should
  686. (equal "012345678\n9\n"
  687. (org-test-with-temp-text "012345678 9\n<point>"
  688. (let ((fill-column 10))
  689. (org-fill-paragraph)
  690. (buffer-string)))))
  691. ;; Between two paragraphs, fill the next one.
  692. (should
  693. (equal "012345678 9\n\n012345678\n9"
  694. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  695. (let ((fill-column 10))
  696. (org-fill-paragraph)
  697. (buffer-string)))))
  698. (should
  699. (equal "012345678\n9\n\n012345678 9"
  700. (org-test-with-temp-text "012345678 9<point>\n\n012345678 9"
  701. (let ((fill-column 10))
  702. (org-fill-paragraph)
  703. (buffer-string)))))
  704. ;; Fill paragraph in a comment block.
  705. (should
  706. (equal "#+begin_comment\n012345678\n9\n#+end_comment"
  707. (org-test-with-temp-text
  708. "#+begin_comment\n<point>012345678 9\n#+end_comment"
  709. (let ((fill-column 10))
  710. (org-fill-paragraph)
  711. (buffer-string)))))
  712. ;; When a region is selected, fill every paragraph in the region.
  713. (should
  714. (equal "012345678\n9\n\n012345678\n9"
  715. (org-test-with-temp-text "012345678 9\n\n012345678 9"
  716. (let ((fill-column 10))
  717. (transient-mark-mode 1)
  718. (push-mark (point-min) t t)
  719. (goto-char (point-max))
  720. (call-interactively #'org-fill-paragraph)
  721. (buffer-string)))))
  722. (should
  723. (equal "012345678\n9\n\n012345678 9"
  724. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  725. (let ((fill-column 10))
  726. (transient-mark-mode 1)
  727. (push-mark (point) t t)
  728. (goto-char (point-min))
  729. (call-interactively #'org-fill-paragraph)
  730. (buffer-string)))))
  731. (should
  732. (equal "012345678 9\n\n012345678\n9"
  733. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  734. (let ((fill-column 10))
  735. (transient-mark-mode 1)
  736. (push-mark (point) t t)
  737. (goto-char (point-max))
  738. (call-interactively #'org-fill-paragraph)
  739. (buffer-string))))))
  740. (ert-deftest test-org/auto-fill-function ()
  741. "Test auto-filling features."
  742. ;; Auto fill paragraph.
  743. (should
  744. (equal "12345\n7890"
  745. (org-test-with-temp-text "12345 7890"
  746. (let ((fill-column 5))
  747. (end-of-line)
  748. (org-auto-fill-function)
  749. (buffer-string)))))
  750. ;; Auto fill first paragraph in an item.
  751. (should
  752. (equal "- 12345\n 7890"
  753. (org-test-with-temp-text "- 12345 7890"
  754. (let ((fill-column 7))
  755. (end-of-line)
  756. (org-auto-fill-function)
  757. (buffer-string)))))
  758. ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
  759. (should
  760. (equal "> 12345\n 7890"
  761. (org-test-with-temp-text "> 12345 7890"
  762. (let ((fill-column 10)
  763. (adaptive-fill-regexp "[ \t]*>+[ \t]*")
  764. (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
  765. (end-of-line)
  766. (org-auto-fill-function)
  767. (buffer-string)))))
  768. (should
  769. (equal "> 12345\n> 12345\n> 7890"
  770. (org-test-with-temp-text "> 12345\n> 12345 7890"
  771. (let ((fill-column 10)
  772. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  773. (goto-char (point-max))
  774. (org-auto-fill-function)
  775. (buffer-string)))))
  776. (should-not
  777. (equal " 12345\n *12345\n *12345"
  778. (org-test-with-temp-text " 12345\n *12345 12345"
  779. (let ((fill-column 10)
  780. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  781. (goto-char (point-max))
  782. (org-auto-fill-function)
  783. (buffer-string)))))
  784. ;; Auto fill comments.
  785. (should
  786. (equal " # 12345\n # 7890"
  787. (org-test-with-temp-text " # 12345 7890"
  788. (let ((fill-column 10))
  789. (end-of-line)
  790. (org-auto-fill-function)
  791. (buffer-string)))))
  792. ;; A hash within a line isn't a comment.
  793. (should-not
  794. (equal "12345 # 7890\n# 1"
  795. (org-test-with-temp-text "12345 # 7890 1"
  796. (let ((fill-column 12))
  797. (end-of-line)
  798. (org-auto-fill-function)
  799. (buffer-string)))))
  800. ;; Correctly interpret empty prefix.
  801. (should-not
  802. (equal "# a\n# b\nRegular\n# paragraph"
  803. (org-test-with-temp-text "# a\n# b\nRegular paragraph"
  804. (let ((fill-column 12))
  805. (end-of-line 3)
  806. (org-auto-fill-function)
  807. (buffer-string)))))
  808. ;; Comment block: auto fill contents.
  809. (should
  810. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  811. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  812. (let ((fill-column 5))
  813. (forward-line)
  814. (end-of-line)
  815. (org-auto-fill-function)
  816. (buffer-string)))))
  817. (should
  818. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  819. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  820. (let ((fill-column 5))
  821. (forward-line)
  822. (end-of-line)
  823. (org-auto-fill-function)
  824. (buffer-string)))))
  825. ;; Do not fill if a new item could be created.
  826. (should-not
  827. (equal "12345\n- 90"
  828. (org-test-with-temp-text "12345 - 90"
  829. (let ((fill-column 5))
  830. (end-of-line)
  831. (org-auto-fill-function)
  832. (buffer-string)))))
  833. ;; Do not fill if a line break could be introduced.
  834. (should-not
  835. (equal "123\\\\\n7890"
  836. (org-test-with-temp-text "123\\\\ 7890"
  837. (let ((fill-column 6))
  838. (end-of-line)
  839. (org-auto-fill-function)
  840. (buffer-string)))))
  841. ;; Do not fill affiliated keywords.
  842. (should-not
  843. (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
  844. (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
  845. (let ((fill-column 20))
  846. (end-of-line)
  847. (org-auto-fill-function)
  848. (buffer-string))))))
  849. ;;; Indentation
  850. (ert-deftest test-org/indent-line ()
  851. "Test `org-indent-line' specifications."
  852. ;; Do not indent diary sexps, footnote definitions or headlines.
  853. (should
  854. (zerop
  855. (org-test-with-temp-text "%%(org-calendar-holiday)"
  856. (org-indent-line)
  857. (org-get-indentation))))
  858. (should
  859. (zerop
  860. (org-test-with-temp-text "[fn:1] fn"
  861. (let ((org-adapt-indentation t)) (org-indent-line))
  862. (org-get-indentation))))
  863. (should
  864. (zerop
  865. (org-test-with-temp-text "* H"
  866. (org-indent-line)
  867. (org-get-indentation))))
  868. ;; Do not indent before first headline.
  869. (should
  870. (zerop
  871. (org-test-with-temp-text ""
  872. (org-indent-line)
  873. (org-get-indentation))))
  874. ;; Indent according to headline level otherwise, unless
  875. ;; `org-adapt-indentation' is nil.
  876. (should
  877. (= 2
  878. (org-test-with-temp-text "* H\n<point>A"
  879. (let ((org-adapt-indentation t)) (org-indent-line))
  880. (org-get-indentation))))
  881. (should
  882. (= 2
  883. (org-test-with-temp-text "* H\n<point>\nA"
  884. (let ((org-adapt-indentation t)) (org-indent-line))
  885. (org-get-indentation))))
  886. (should
  887. (zerop
  888. (org-test-with-temp-text "* H\n<point>A"
  889. (let ((org-adapt-indentation nil)) (org-indent-line))
  890. (org-get-indentation))))
  891. ;; Indenting preserves point position.
  892. (should
  893. (org-test-with-temp-text "* H\nA<point>B"
  894. (let ((org-adapt-indentation t)) (org-indent-line))
  895. (looking-at "B")))
  896. ;; Do not change indentation at an item or a LaTeX environment.
  897. (should
  898. (= 1
  899. (org-test-with-temp-text "* H\n<point> - A"
  900. (let ((org-adapt-indentation t)) (org-indent-line))
  901. (org-get-indentation))))
  902. (should
  903. (= 1
  904. (org-test-with-temp-text
  905. "\\begin{equation}\n <point>1+1=2\n\\end{equation}"
  906. (org-indent-line)
  907. (org-get-indentation))))
  908. ;; On blank lines at the end of a list, indent like last element
  909. ;; within it if the line is still in the list. If the last element
  910. ;; is an item, indent like its contents. Otherwise, indent like the
  911. ;; whole list.
  912. (should
  913. (= 4
  914. (org-test-with-temp-text "* H\n- A\n - AA\n<point>"
  915. (let ((org-adapt-indentation t)) (org-indent-line))
  916. (org-get-indentation))))
  917. (should
  918. (= 4
  919. (org-test-with-temp-text "* H\n- A\n -\n\n<point>"
  920. (let ((org-adapt-indentation t)) (org-indent-line))
  921. (org-get-indentation))))
  922. (should
  923. (zerop
  924. (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n<point>"
  925. (let ((org-adapt-indentation t)) (org-indent-line))
  926. (org-get-indentation))))
  927. (should
  928. (= 4
  929. (org-test-with-temp-text "* H\n- A\n - \n<point>"
  930. (let ((org-adapt-indentation t)) (org-indent-line))
  931. (org-get-indentation))))
  932. (should
  933. (= 4
  934. (org-test-with-temp-text
  935. "* H\n - \n #+BEGIN_SRC emacs-lisp\n t\n #+END_SRC\n<point>"
  936. (let ((org-adapt-indentation t)) (org-indent-line))
  937. (org-get-indentation))))
  938. (should
  939. (= 2
  940. (org-test-with-temp-text "- A\n B\n\n<point>"
  941. (let ((org-adapt-indentation nil)) (org-indent-line))
  942. (org-get-indentation))))
  943. (should
  944. (= 2
  945. (org-test-with-temp-text
  946. "- A\n \begin{cases} 1 + 1\n \end{cases}\n\n<point>"
  947. (let ((org-adapt-indentation nil)) (org-indent-line))
  948. (org-get-indentation))))
  949. ;; Likewise, on a blank line at the end of a footnote definition,
  950. ;; indent at column 0 if line belongs to the definition. Otherwise,
  951. ;; indent like the definition itself.
  952. (should
  953. (zerop
  954. (org-test-with-temp-text "* H\n[fn:1] Definition\n<point>"
  955. (let ((org-adapt-indentation t)) (org-indent-line))
  956. (org-get-indentation))))
  957. (should
  958. (zerop
  959. (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n<point>"
  960. (let ((org-adapt-indentation t)) (org-indent-line))
  961. (org-get-indentation))))
  962. ;; After the end of the contents of a greater element, indent like
  963. ;; the beginning of the element.
  964. (should
  965. (= 1
  966. (org-test-with-temp-text
  967. " #+BEGIN_CENTER\n Contents\n<point>#+END_CENTER"
  968. (org-indent-line)
  969. (org-get-indentation))))
  970. ;; On blank lines after a paragraph, indent like its last non-empty
  971. ;; line.
  972. (should
  973. (= 1
  974. (org-test-with-temp-text " Paragraph\n\n<point>"
  975. (org-indent-line)
  976. (org-get-indentation))))
  977. ;; At the first line of an element, indent like previous element's
  978. ;; first line, ignoring footnotes definitions and inline tasks, or
  979. ;; according to parent.
  980. (let ((org-adapt-indentation t))
  981. (should
  982. (= 2
  983. (org-test-with-temp-text "A\n\n B\n\nC<point>"
  984. (org-indent-line)
  985. (org-get-indentation))))
  986. (should
  987. (= 1
  988. (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC<point>"
  989. (org-indent-line)
  990. (org-get-indentation))))
  991. (should
  992. (= 1
  993. (org-test-with-temp-text
  994. " #+BEGIN_CENTER\n<point> Contents\n#+END_CENTER"
  995. (org-indent-line)
  996. (org-get-indentation)))))
  997. ;; Within code part of a source block, use language major mode if
  998. ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
  999. ;; according to line above.
  1000. (should
  1001. (= 6
  1002. (org-test-with-temp-text
  1003. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  1004. (let ((org-src-tab-acts-natively t)
  1005. (org-edit-src-content-indentation 0))
  1006. (org-indent-line))
  1007. (org-get-indentation))))
  1008. (should
  1009. (= 1
  1010. (org-test-with-temp-text
  1011. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  1012. (let ((org-src-tab-acts-natively nil)
  1013. (org-edit-src-content-indentation 0))
  1014. (org-indent-line))
  1015. (org-get-indentation))))
  1016. ;; Otherwise, indent like the first non-blank line above.
  1017. (should
  1018. (zerop
  1019. (org-test-with-temp-text
  1020. "#+BEGIN_CENTER\nline1\n\n<point> line2\n#+END_CENTER"
  1021. (org-indent-line)
  1022. (org-get-indentation))))
  1023. ;; Align node properties according to `org-property-format'. Handle
  1024. ;; nicely empty values.
  1025. (should
  1026. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1027. (org-test-with-temp-text
  1028. "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
  1029. (let ((org-property-format "%-10s %s")) (org-indent-line))
  1030. (buffer-string))))
  1031. (should
  1032. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1033. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
  1034. (let ((org-property-format "%-10s %s")) (org-indent-line))
  1035. (buffer-string)))))
  1036. (ert-deftest test-org/indent-region ()
  1037. "Test `org-indent-region' specifications."
  1038. ;; Indent paragraph.
  1039. (let ((org-adapt-indentation t))
  1040. (should
  1041. (equal "A\nB\nC"
  1042. (org-test-with-temp-text " A\nB\n C"
  1043. (org-indent-region (point-min) (point-max))
  1044. (buffer-string)))))
  1045. ;; Indent greater elements along with their contents.
  1046. (should
  1047. (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
  1048. (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
  1049. (org-indent-region (point-min) (point-max))
  1050. (buffer-string))))
  1051. ;; Ignore contents of verse blocks. Only indent block delimiters.
  1052. (should
  1053. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1054. (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1055. (org-indent-region (point-min) (point-max))
  1056. (buffer-string))))
  1057. (let ((org-adapt-indentation t))
  1058. (should
  1059. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1060. (org-test-with-temp-text " #+BEGIN_VERSE\n A\n B\n #+END_VERSE"
  1061. (org-indent-region (point-min) (point-max))
  1062. (buffer-string)))))
  1063. ;; Indent example blocks as a single block, unless indentation
  1064. ;; should be preserved. In this case only indent the block markers.
  1065. (should
  1066. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1067. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1068. (org-indent-region (point-min) (point-max))
  1069. (buffer-string))))
  1070. (let ((org-adapt-indentation t))
  1071. (should
  1072. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1073. (org-test-with-temp-text " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1074. (org-indent-region (point-min) (point-max))
  1075. (buffer-string))))
  1076. (should
  1077. (equal "#+BEGIN_EXAMPLE -i\n A\n B\n#+END_EXAMPLE"
  1078. (org-test-with-temp-text
  1079. " #+BEGIN_EXAMPLE -i\n A\n B\n #+END_EXAMPLE"
  1080. (org-indent-region (point-min) (point-max))
  1081. (buffer-string))))
  1082. (should
  1083. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1084. (org-test-with-temp-text
  1085. " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1086. (let ((org-src-preserve-indentation t))
  1087. (org-indent-region (point-min) (point-max)))
  1088. (buffer-string)))))
  1089. ;; Treat export blocks as a whole.
  1090. (should
  1091. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1092. (org-test-with-temp-text "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1093. (org-indent-region (point-min) (point-max))
  1094. (buffer-string))))
  1095. (let ((org-adapt-indentation t))
  1096. (should
  1097. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1098. (org-test-with-temp-text
  1099. " #+BEGIN_EXPORT latex\n A\n B\n #+END_EXPORT"
  1100. (org-indent-region (point-min) (point-max))
  1101. (buffer-string)))))
  1102. ;; Indent according to mode if `org-src-tab-acts-natively' is
  1103. ;; non-nil. Otherwise, do not indent code at all.
  1104. (should
  1105. (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
  1106. (org-test-with-temp-text
  1107. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1108. (let ((org-src-tab-acts-natively t)
  1109. (org-edit-src-content-indentation 0))
  1110. (org-indent-region (point-min) (point-max)))
  1111. (buffer-string))))
  1112. (should
  1113. (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1114. (org-test-with-temp-text
  1115. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1116. (let ((org-src-tab-acts-natively nil)
  1117. (org-edit-src-content-indentation 0))
  1118. (org-indent-region (point-min) (point-max)))
  1119. (buffer-string))))
  1120. ;; Align node properties according to `org-property-format'. Handle
  1121. ;; nicely empty values.
  1122. (should
  1123. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1124. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
  1125. (let ((org-property-format "%-10s %s")
  1126. (org-adapt-indentation nil))
  1127. (org-indent-region (point) (point-max)))
  1128. (buffer-string))))
  1129. (should
  1130. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1131. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
  1132. (let ((org-property-format "%-10s %s")
  1133. (org-adapt-indentation nil))
  1134. (org-indent-region (point) (point-max)))
  1135. (buffer-string))))
  1136. ;; Indent plain lists.
  1137. (let ((org-adapt-indentation t))
  1138. (should
  1139. (equal "- A\n B\n - C\n\n D"
  1140. (org-test-with-temp-text "- A\n B\n - C\n\n D"
  1141. (org-indent-region (point-min) (point-max))
  1142. (buffer-string))))
  1143. (should
  1144. (equal "- A\n\n- B"
  1145. (org-test-with-temp-text " - A\n\n - B"
  1146. (org-indent-region (point-min) (point-max))
  1147. (buffer-string)))))
  1148. ;; Indent footnote definitions.
  1149. (should
  1150. (equal "[fn:1] Definition\n\nDefinition"
  1151. (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
  1152. (org-indent-region (point-min) (point-max))
  1153. (buffer-string))))
  1154. ;; Special case: Start indenting on a blank line.
  1155. (should
  1156. (equal "\nParagraph"
  1157. (org-test-with-temp-text "\n Paragraph"
  1158. (org-indent-region (point-min) (point-max))
  1159. (buffer-string)))))
  1160. ;;; Editing
  1161. (ert-deftest test-org/delete-indentation ()
  1162. "Test `org-delete-indentation' specifications."
  1163. ;; Regular test.
  1164. (should (equal "foo bar"
  1165. (org-test-with-temp-text
  1166. "foo \n bar<point>"
  1167. (org-delete-indentation)
  1168. (buffer-string))))
  1169. ;; With optional argument.
  1170. (should (equal "foo bar"
  1171. (org-test-with-temp-text
  1172. "foo<point> \n bar"
  1173. (org-delete-indentation t)
  1174. (buffer-string))))
  1175. ;; At headline text should be appended to the headline text.
  1176. (should
  1177. (equal"* foo bar :tag:"
  1178. (let (org-auto-align-tags)
  1179. (org-test-with-temp-text
  1180. "* foo :tag:\n bar<point>"
  1181. (org-delete-indentation)
  1182. (buffer-string)))))
  1183. (should
  1184. (equal "* foo bar :tag:"
  1185. (let (org-auto-align-tags)
  1186. (org-test-with-temp-text
  1187. "* foo <point>:tag:\n bar"
  1188. (org-delete-indentation t)
  1189. (buffer-string))))))
  1190. (ert-deftest test-org/return ()
  1191. "Test `org-return' specifications."
  1192. ;; Regular test.
  1193. (should
  1194. (equal "Para\ngraph"
  1195. (org-test-with-temp-text "Para<point>graph"
  1196. (org-return)
  1197. (buffer-string))))
  1198. ;; With optional argument, indent line.
  1199. (should
  1200. (equal " Para\n graph"
  1201. (org-test-with-temp-text " Para<point>graph"
  1202. (org-return t)
  1203. (buffer-string))))
  1204. ;; On a table, call `org-table-next-row'.
  1205. (should
  1206. (org-test-with-temp-text "| <point>a |\n| b |"
  1207. (org-return)
  1208. (looking-at-p "b")))
  1209. ;; Open link or timestamp under point when `org-return-follows-link'
  1210. ;; is non-nil.
  1211. (should
  1212. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1213. (let ((org-return-follows-link t)
  1214. (org-link-search-must-match-exact-headline nil))
  1215. (org-return))
  1216. (looking-at-p "<<target>>")))
  1217. (should-not
  1218. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1219. (let ((org-return-follows-link nil)) (org-return))
  1220. (looking-at-p "<<target>>")))
  1221. (should
  1222. (org-test-with-temp-text "* [[b][a<point>]]\n* b"
  1223. (let ((org-return-follows-link t)) (org-return))
  1224. (looking-at-p "* b")))
  1225. (should
  1226. (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
  1227. (let ((org-return-follows-link t)
  1228. (org-link-search-must-match-exact-headline nil))
  1229. (org-return))
  1230. (looking-at-p "<<target>>")))
  1231. (should-not
  1232. (org-test-with-temp-text "Link [[target]]<point> <<target>>"
  1233. (let ((org-return-follows-link t)
  1234. (org-link-search-must-match-exact-headline nil))
  1235. (org-return))
  1236. (looking-at-p "<<target>>")))
  1237. ;; When `org-return-follows-link' is non-nil, tolerate links and
  1238. ;; timestamps in comments, node properties, etc.
  1239. (should
  1240. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1241. (let ((org-return-follows-link t)
  1242. (org-link-search-must-match-exact-headline nil))
  1243. (org-return))
  1244. (looking-at-p "<<target>>")))
  1245. (should-not
  1246. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1247. (let ((org-return-follows-link nil)) (org-return))
  1248. (looking-at-p "<<target>>")))
  1249. (should-not
  1250. (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
  1251. (let ((org-return-follows-link t)
  1252. (org-link-search-must-match-exact-headline nil))
  1253. (org-return))
  1254. (looking-at-p "<<target>>")))
  1255. ;; Non-nil `org-return-follows-link' ignores read-only state of
  1256. ;; a buffer.
  1257. (should
  1258. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1259. (let ((org-return-follows-link t)
  1260. (org-link-search-must-match-exact-headline nil))
  1261. (setq buffer-read-only t)
  1262. (call-interactively #'org-return))
  1263. (looking-at-p "<<target>>")))
  1264. ;; `org-return-follows-link' handle multi-line lines.
  1265. (should
  1266. (org-test-with-temp-text
  1267. "[[target][This is a very\n long description<point>]]\n <<target>>"
  1268. (let ((org-return-follows-link t)
  1269. (org-link-search-must-match-exact-headline nil))
  1270. (org-return))
  1271. (looking-at-p "<<target>>")))
  1272. (should-not
  1273. (org-test-with-temp-text
  1274. "[[target][This is a very\n long description]]<point>\n <<target>>"
  1275. (let ((org-return-follows-link t)
  1276. (org-link-search-must-match-exact-headline nil))
  1277. (org-return))
  1278. (looking-at-p "<<target>>")))
  1279. ;; However, do not open link when point is in a table.
  1280. (should
  1281. (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
  1282. (let ((org-return-follows-link t)) (org-return))
  1283. (looking-at-p "between")))
  1284. ;; Special case: in a list, when indenting, do not break structure.
  1285. (should
  1286. (equal "- A\n B"
  1287. (org-test-with-temp-text "- A <point>B"
  1288. (org-return t)
  1289. (buffer-string))))
  1290. (should
  1291. (equal "- A\n\n- B"
  1292. (org-test-with-temp-text "- A\n<point>- B"
  1293. (org-return t)
  1294. (buffer-string))))
  1295. ;; On tags part of a headline, add a newline below it instead of
  1296. ;; breaking it.
  1297. (should
  1298. (equal "* H :tag:\n"
  1299. (org-test-with-temp-text "* H :<point>tag:"
  1300. (org-return)
  1301. (buffer-string))))
  1302. ;; Before headline text, add a newline below it instead of breaking
  1303. ;; it.
  1304. (should
  1305. (equal "* TODO H :tag:\n"
  1306. (org-test-with-temp-text "* <point>TODO H :tag:"
  1307. (org-return)
  1308. (buffer-string))))
  1309. (should
  1310. (equal "* TODO [#B] H :tag:\n"
  1311. (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
  1312. (org-return)
  1313. (buffer-string))))
  1314. (should ;TODO are case-sensitive
  1315. (equal "* \nTodo"
  1316. (org-test-with-temp-text "* <point>Todo"
  1317. (org-return)
  1318. (buffer-string))))
  1319. ;; At headline text, break headline text but preserve tags.
  1320. (should
  1321. (equal "* TODO [#B] foo :tag:\nbar"
  1322. (let (org-auto-align-tags)
  1323. (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
  1324. (org-return)
  1325. (buffer-string)))))
  1326. ;; At bol of headline insert newline.
  1327. (should
  1328. (equal "\n* h"
  1329. (org-test-with-temp-text "<point>* h"
  1330. (org-return)
  1331. (buffer-string))))
  1332. ;; Refuse to leave invalid headline in buffer.
  1333. (should
  1334. (equal "* h\n"
  1335. (org-test-with-temp-text "*<point> h"
  1336. (org-return)
  1337. (buffer-string))))
  1338. ;; Before first column or after last one in a table, split the
  1339. ;; table.
  1340. (should
  1341. (equal "| a |\n\n| b |"
  1342. (org-test-with-temp-text "| a |\n<point>| b |"
  1343. (org-return)
  1344. (buffer-string))))
  1345. (should
  1346. (equal "| a |\n\n| b |"
  1347. (org-test-with-temp-text "| a |<point>\n| b |"
  1348. (org-return)
  1349. (buffer-string))))
  1350. ;; Do not auto-fill on hitting <RET> inside a property drawer.
  1351. (should
  1352. (equal "* Heading\n:PROPERTIES:\n:SOME_PROP: This is a very long property value that goes beyond the fill-column. But this is inside a property drawer, so the auto-filling should be disabled.\n\n:END:"
  1353. (org-test-with-temp-text "* Heading\n:PROPERTIES:\n:SOME_PROP: This is a very long property value that goes beyond the fill-column. But this is inside a property drawer, so the auto-filling should be disabled.<point>\n:END:"
  1354. (setq-local fill-column 10)
  1355. (auto-fill-mode 1)
  1356. (org-return)
  1357. (buffer-string)))))
  1358. (ert-deftest test-org/with-electric-indent ()
  1359. "Test RET and C-j specifications with `electric-indent-mode' on."
  1360. ;; Call commands interactively, since this is how `newline' knows it
  1361. ;; must run `post-self-insert-hook'.
  1362. ;;
  1363. ;; RET, like `newline', should indent.
  1364. (should
  1365. (equal " Para\n graph"
  1366. (org-test-with-temp-text " Para<point>graph"
  1367. (electric-indent-local-mode 1)
  1368. (call-interactively 'org-return)
  1369. (buffer-string))))
  1370. (should
  1371. (equal "- item1\n item2"
  1372. (org-test-with-temp-text "- item1<point>item2"
  1373. (electric-indent-local-mode 1)
  1374. (call-interactively 'org-return)
  1375. (buffer-string))))
  1376. ;; TODO: test more values of `org-adapt-indentation'.
  1377. (let ((org-adapt-indentation t))
  1378. (should
  1379. (equal "* heading\n body"
  1380. (org-test-with-temp-text "* heading<point>body"
  1381. (electric-indent-local-mode 1)
  1382. (call-interactively 'org-return)
  1383. (buffer-string)))))
  1384. ;; C-j, like `electric-newline-and-maybe-indent', should not indent.
  1385. (should
  1386. (equal " Para\ngraph"
  1387. (org-test-with-temp-text " Para<point>graph"
  1388. (electric-indent-local-mode 1)
  1389. (call-interactively 'org-return-and-maybe-indent)
  1390. (buffer-string))))
  1391. (should
  1392. (equal "- item1\nitem2"
  1393. (org-test-with-temp-text "- item1<point>item2"
  1394. (electric-indent-local-mode 1)
  1395. (call-interactively 'org-return-and-maybe-indent)
  1396. (buffer-string))))
  1397. ;; TODO: test more values of `org-adapt-indentation'.
  1398. (let ((org-adapt-indentation t))
  1399. (should
  1400. (equal "* heading\nbody"
  1401. (org-test-with-temp-text "* heading<point>body"
  1402. (electric-indent-local-mode 1)
  1403. (call-interactively 'org-return-and-maybe-indent)
  1404. (buffer-string))))))
  1405. (ert-deftest test-org/without-electric-indent ()
  1406. "Test RET and C-j specifications with `electric-indent-mode' off."
  1407. ;; Call commands interactively, since this is how `newline' knows it
  1408. ;; must run `post-self-insert-hook'.
  1409. ;;
  1410. ;; RET, like `newline', should not indent.
  1411. (should
  1412. (equal " Para\ngraph"
  1413. (org-test-with-temp-text " Para<point>graph"
  1414. (electric-indent-local-mode 0)
  1415. (call-interactively 'org-return)
  1416. (buffer-string))))
  1417. (should
  1418. (equal "- item1\nitem2"
  1419. (org-test-with-temp-text "- item1<point>item2"
  1420. (electric-indent-local-mode 0)
  1421. (call-interactively 'org-return)
  1422. (buffer-string))))
  1423. (should
  1424. (equal "* heading\nbody"
  1425. (org-test-with-temp-text "* heading<point>body"
  1426. (electric-indent-local-mode 0)
  1427. (call-interactively 'org-return)
  1428. (buffer-string))))
  1429. ;; C-j, like `electric-newline-and-maybe-indent', should indent.
  1430. (should
  1431. (equal " Para\n graph"
  1432. (org-test-with-temp-text " Para<point>graph"
  1433. (electric-indent-local-mode 0)
  1434. (call-interactively 'org-return-and-maybe-indent)
  1435. (buffer-string))))
  1436. (should
  1437. (equal "- item1\n item2"
  1438. (org-test-with-temp-text "- item1<point>item2"
  1439. (electric-indent-local-mode 0)
  1440. (call-interactively 'org-return-and-maybe-indent)
  1441. (buffer-string))))
  1442. ;; TODO: test more values of `org-adapt-indentation'.
  1443. (let ((org-adapt-indentation t))
  1444. (should
  1445. (equal "* heading\n body"
  1446. (org-test-with-temp-text "* heading<point>body"
  1447. (electric-indent-local-mode 0)
  1448. (call-interactively 'org-return-and-maybe-indent)
  1449. (buffer-string))))))
  1450. (ert-deftest test-org/meta-return ()
  1451. "Test M-RET (`org-meta-return') specifications."
  1452. ;; In a table field insert a row above.
  1453. (should
  1454. (org-test-with-temp-text "| a |"
  1455. (forward-char)
  1456. (org-meta-return)
  1457. (forward-line -1)
  1458. (looking-at "| |$")))
  1459. ;; In a paragraph change current line into a header.
  1460. (should
  1461. (org-test-with-temp-text "a"
  1462. (org-meta-return)
  1463. (beginning-of-line)
  1464. (looking-at "\* a$")))
  1465. ;; In an item insert an item, in this case above.
  1466. (should
  1467. (org-test-with-temp-text "- a"
  1468. (org-meta-return)
  1469. (beginning-of-line)
  1470. (looking-at "- $")))
  1471. ;; In a drawer and item insert an item, in this case above.
  1472. (should
  1473. (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
  1474. (forward-line)
  1475. (org-meta-return)
  1476. (beginning-of-line)
  1477. (looking-at "- $"))))
  1478. (ert-deftest test-org/insert-heading ()
  1479. "Test `org-insert-heading' specifications."
  1480. ;; In an empty buffer, insert a new headline.
  1481. (should
  1482. (equal "* "
  1483. (org-test-with-temp-text ""
  1484. (org-insert-heading)
  1485. (buffer-string))))
  1486. ;; At the beginning of a line, turn it into a headline.
  1487. (should
  1488. (equal "* P"
  1489. (org-test-with-temp-text "<point>P"
  1490. (org-insert-heading)
  1491. (buffer-string))))
  1492. ;; In the middle of a line, split the line if allowed, otherwise,
  1493. ;; insert the headline at its end.
  1494. (should
  1495. (equal "Para\n* graph"
  1496. (org-test-with-temp-text "Para<point>graph"
  1497. (let ((org-M-RET-may-split-line '((default . t))))
  1498. (org-insert-heading))
  1499. (buffer-string))))
  1500. (should
  1501. (equal "Paragraph\n* "
  1502. (org-test-with-temp-text "Para<point>graph"
  1503. (let ((org-M-RET-may-split-line '((default . nil))))
  1504. (org-insert-heading))
  1505. (buffer-string))))
  1506. ;; At the beginning of a headline, create one above.
  1507. (should
  1508. (equal "* \n* H"
  1509. (org-test-with-temp-text "* H"
  1510. (org-insert-heading)
  1511. (buffer-string))))
  1512. ;; In the middle of a headline, split it if allowed.
  1513. (should
  1514. (equal "* H\n* 1"
  1515. (org-test-with-temp-text "* H<point>1"
  1516. (let ((org-M-RET-may-split-line '((headline . t))))
  1517. (org-insert-heading))
  1518. (buffer-string))))
  1519. (should
  1520. (equal "* H1\n* "
  1521. (org-test-with-temp-text "* H<point>1"
  1522. (let ((org-M-RET-may-split-line '((headline . nil))))
  1523. (org-insert-heading))
  1524. (buffer-string))))
  1525. ;; However, splitting cannot happen on TODO keywords, priorities or
  1526. ;; tags.
  1527. (should
  1528. (equal "* TODO H1\n* "
  1529. (org-test-with-temp-text "* TO<point>DO H1"
  1530. (let ((org-M-RET-may-split-line '((headline . t))))
  1531. (org-insert-heading))
  1532. (buffer-string))))
  1533. (should
  1534. (equal "* [#A] H1\n* "
  1535. (org-test-with-temp-text "* [#<point>A] H1"
  1536. (let ((org-M-RET-may-split-line '((headline . t))))
  1537. (org-insert-heading))
  1538. (buffer-string))))
  1539. (should
  1540. (equal "* H1 :tag:\n* "
  1541. (org-test-with-temp-text "* H1 :ta<point>g:"
  1542. (let ((org-M-RET-may-split-line '((headline . t))))
  1543. (org-insert-heading))
  1544. (buffer-string))))
  1545. ;; New headline level depends on the level of the headline above.
  1546. (should
  1547. (equal "** H\n** P"
  1548. (org-test-with-temp-text "** H\n<point>P"
  1549. (org-insert-heading)
  1550. (buffer-string))))
  1551. (should
  1552. (equal "** H\nPara\n** graph"
  1553. (org-test-with-temp-text "** H\nPara<point>graph"
  1554. (let ((org-M-RET-may-split-line '((default . t))))
  1555. (org-insert-heading))
  1556. (buffer-string))))
  1557. (should
  1558. (equal "** \n** H"
  1559. (org-test-with-temp-text "** H"
  1560. (org-insert-heading)
  1561. (buffer-string))))
  1562. ;; When called with one universal argument, insert a new headline at
  1563. ;; the end of the current subtree, independently on the position of
  1564. ;; point.
  1565. (should
  1566. (equal
  1567. "* "
  1568. (org-test-with-temp-text ""
  1569. (let ((org-insert-heading-respect-content nil))
  1570. (org-insert-heading '(4)))
  1571. (buffer-string))))
  1572. (should
  1573. (equal
  1574. "entry
  1575. * "
  1576. (org-test-with-temp-text "entry"
  1577. (let ((org-insert-heading-respect-content nil))
  1578. (org-insert-heading '(4)))
  1579. (buffer-string))))
  1580. (should
  1581. (equal
  1582. "* H1\n** H2\n* "
  1583. (org-test-with-temp-text "* H1\n** H2"
  1584. (let ((org-insert-heading-respect-content nil))
  1585. (org-insert-heading '(4)))
  1586. (buffer-string))))
  1587. (should
  1588. (equal
  1589. "* H1\n** H2\n* "
  1590. (org-test-with-temp-text "* H<point>1\n** H2"
  1591. (let ((org-insert-heading-respect-content nil))
  1592. (org-insert-heading '(4)))
  1593. (buffer-string))))
  1594. ;; When called with two universal arguments, insert a new headline
  1595. ;; at the end of the grandparent subtree.
  1596. (should
  1597. (equal "* H1\n** H3\n- item\n** H2\n** "
  1598. (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
  1599. (let ((org-insert-heading-respect-content nil))
  1600. (org-insert-heading '(16)))
  1601. (buffer-string))))
  1602. ;; When optional TOP-LEVEL argument is non-nil, always insert
  1603. ;; a level 1 heading.
  1604. (should
  1605. (equal "* H1\n** H2\n* "
  1606. (org-test-with-temp-text "* H1\n** H2<point>"
  1607. (org-insert-heading nil nil t)
  1608. (buffer-string))))
  1609. (should
  1610. (equal "* H1\n- item\n* "
  1611. (org-test-with-temp-text "* H1\n- item<point>"
  1612. (org-insert-heading nil nil t)
  1613. (buffer-string))))
  1614. ;; Obey `org-blank-before-new-entry'.
  1615. (should
  1616. (equal "* H1\n\n* "
  1617. (org-test-with-temp-text "* H1<point>"
  1618. (let ((org-blank-before-new-entry '((heading . t))))
  1619. (org-insert-heading))
  1620. (buffer-string))))
  1621. (should
  1622. (equal "* H1\n* "
  1623. (org-test-with-temp-text "* H1<point>"
  1624. (let ((org-blank-before-new-entry '((heading . nil))))
  1625. (org-insert-heading))
  1626. (buffer-string))))
  1627. (should
  1628. (equal "* H1\n* H2\n* "
  1629. (org-test-with-temp-text "* H1\n* H2<point>"
  1630. (let ((org-blank-before-new-entry '((heading . auto))))
  1631. (org-insert-heading))
  1632. (buffer-string))))
  1633. (should
  1634. (equal "* H1\n\n* H2\n\n* "
  1635. (org-test-with-temp-text "* H1\n\n* H2<point>"
  1636. (let ((org-blank-before-new-entry '((heading . auto))))
  1637. (org-insert-heading))
  1638. (buffer-string))))
  1639. ;; Corner case: correctly insert a headline after an empty one.
  1640. (should
  1641. (equal "* \n* "
  1642. (org-test-with-temp-text "* <point>"
  1643. (org-insert-heading)
  1644. (buffer-string))))
  1645. (should
  1646. (org-test-with-temp-text "* <point>\n"
  1647. (org-insert-heading)
  1648. (looking-at-p "\n\\'")))
  1649. ;; Do not insert spurious headlines when inserting a new headline.
  1650. (should
  1651. (equal "* H1\n* H2\n* \n"
  1652. (org-test-with-temp-text "* H1\n* H2<point>\n"
  1653. (org-insert-heading)
  1654. (buffer-string))))
  1655. ;; Preserve visibility at beginning of line. In particular, when
  1656. ;; removing spurious blank lines, do not visually merge heading with
  1657. ;; the line visible above.
  1658. (should-not
  1659. (org-test-with-temp-text "* H1<point>\nContents\n\n* H2\n"
  1660. (org-overview)
  1661. (let ((org-blank-before-new-entry '((heading . nil))))
  1662. (org-insert-heading '(4)))
  1663. (invisible-p (line-end-position 0))))
  1664. ;; Properly handle empty lines when forcing a headline below current
  1665. ;; one.
  1666. (should
  1667. (equal "* H1\n\n* H\n\n* "
  1668. (org-test-with-temp-text "* H1\n\n* H<point>"
  1669. (let ((org-blank-before-new-entry '((heading . t))))
  1670. (org-insert-heading '(4))
  1671. (buffer-string))))))
  1672. (ert-deftest test-org/insert-todo-heading-respect-content ()
  1673. "Test `org-insert-todo-heading-respect-content' specifications."
  1674. ;; Create a TODO heading.
  1675. (should
  1676. (org-test-with-temp-text "* H1\n Body"
  1677. (org-insert-todo-heading-respect-content)
  1678. (nth 2 (org-heading-components))))
  1679. ;; Add headline at the end of the first subtree
  1680. (should
  1681. (equal
  1682. "* TODO "
  1683. (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
  1684. (org-insert-todo-heading-respect-content)
  1685. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1686. ;; In a list, do not create a new item.
  1687. (should
  1688. (equal
  1689. "* TODO "
  1690. (org-test-with-temp-text "* H\n- an item\n- another one"
  1691. (search-forward "an ")
  1692. (org-insert-todo-heading-respect-content)
  1693. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1694. ;; Use the same TODO keyword as current heading.
  1695. (should
  1696. (equal
  1697. "* TODO \n"
  1698. (org-test-with-temp-text "* TODO\n** WAITING\n"
  1699. (org-insert-todo-heading-respect-content)
  1700. (buffer-substring-no-properties (line-beginning-position) (point-max))))))
  1701. (ert-deftest test-org/clone-with-time-shift ()
  1702. "Test `org-clone-subtree-with-time-shift'."
  1703. ;; Raise an error before first heading.
  1704. (should-error
  1705. (org-test-with-temp-text ""
  1706. (org-clone-subtree-with-time-shift 1)))
  1707. ;; Raise an error on invalid number of clones.
  1708. (should-error
  1709. (org-test-with-temp-text "* Clone me"
  1710. (org-clone-subtree-with-time-shift -1)))
  1711. ;; Clone non-repeating once.
  1712. (should
  1713. (equal "\
  1714. * H1\n<2015-06-21>
  1715. * H1\n<2015-06-23>
  1716. "
  1717. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1718. (org-clone-subtree-with-time-shift 1 "+2d")
  1719. (replace-regexp-in-string
  1720. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1721. nil nil 1))))
  1722. ;; Clone repeating once.
  1723. (should
  1724. (equal "\
  1725. * H1\n<2015-06-21>
  1726. * H1\n<2015-06-23>
  1727. * H1\n<2015-06-25 +1w>
  1728. "
  1729. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1730. (org-clone-subtree-with-time-shift 1 "+2d")
  1731. (replace-regexp-in-string
  1732. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1733. nil nil 1))))
  1734. ;; Clone repeating once in backward.
  1735. (should
  1736. (equal "\
  1737. * H1\n<2015-06-21>
  1738. * H1\n<2015-06-19>
  1739. * H1\n<2015-06-17 +1w>
  1740. "
  1741. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1742. (org-clone-subtree-with-time-shift 1 "-2d")
  1743. (replace-regexp-in-string
  1744. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1745. nil nil 1))))
  1746. ;; Clone non-repeating zero times.
  1747. (should
  1748. (equal "\
  1749. * H1\n<2015-06-21>
  1750. "
  1751. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1752. (org-clone-subtree-with-time-shift 0 "+2d")
  1753. (replace-regexp-in-string
  1754. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1755. nil nil 1))))
  1756. ;; Clone repeating "zero" times.
  1757. (should
  1758. (equal "\
  1759. * H1\n<2015-06-21>
  1760. * H1\n<2015-06-23 +1w>
  1761. "
  1762. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1763. (org-clone-subtree-with-time-shift 0 "+2d")
  1764. (replace-regexp-in-string
  1765. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1766. nil nil 1))))
  1767. ;; Clone with blank SHIFT argument.
  1768. (should
  1769. (string-prefix-p
  1770. "* H <2012-03-29"
  1771. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1772. (org-clone-subtree-with-time-shift 1 "")
  1773. (buffer-substring-no-properties (line-beginning-position 2)
  1774. (line-end-position 2)))))
  1775. ;; Find time stamps before point. If SHIFT is not specified, ask
  1776. ;; for a time shift.
  1777. (should
  1778. (string-prefix-p
  1779. "* H <2012-03-30"
  1780. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1781. (org-clone-subtree-with-time-shift 1 "+1d")
  1782. (buffer-substring-no-properties (line-beginning-position 2)
  1783. (line-end-position 2)))))
  1784. (should
  1785. (string-prefix-p
  1786. "* H <2014-03-05"
  1787. (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
  1788. (cl-letf (((symbol-function 'read-from-minibuffer)
  1789. (lambda (&rest args) "+1d")))
  1790. (org-clone-subtree-with-time-shift 1))
  1791. (buffer-substring-no-properties (line-beginning-position 2)
  1792. (line-end-position 2)))))
  1793. ;; Hour shift.
  1794. (should
  1795. (equal "\
  1796. * H1\n<2015-06-21 20:00>
  1797. * H1\n<2015-06-21 23:00>
  1798. * H1\n<2015-06-22 02:00>
  1799. "
  1800. (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>"
  1801. (org-clone-subtree-with-time-shift 2 "+3h")
  1802. (replace-regexp-in-string
  1803. "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" ""
  1804. (buffer-substring-no-properties (point-min) (point-max))
  1805. nil nil 1))))
  1806. (should
  1807. (equal "\
  1808. * H1\n<2015-06-21 20:00>
  1809. * H1\n<2015-06-21 18:00>
  1810. "
  1811. (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>"
  1812. (org-clone-subtree-with-time-shift 1 "-2h")
  1813. (replace-regexp-in-string
  1814. "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" ""
  1815. (buffer-substring-no-properties (point-min) (point-max))
  1816. nil nil 1)))))
  1817. ;;; Fixed-Width Areas
  1818. (ert-deftest test-org/toggle-fixed-width ()
  1819. "Test `org-toggle-fixed-width' specifications."
  1820. ;; No region: Toggle on fixed-width marker in paragraphs.
  1821. (should
  1822. (equal ": A"
  1823. (org-test-with-temp-text "A"
  1824. (org-toggle-fixed-width)
  1825. (buffer-string))))
  1826. ;; No region: Toggle off fixed-width markers in fixed-width areas.
  1827. (should
  1828. (equal "A"
  1829. (org-test-with-temp-text ": A"
  1830. (org-toggle-fixed-width)
  1831. (buffer-string))))
  1832. ;; No region: Toggle on marker in blank lines after elements or just
  1833. ;; after a headline.
  1834. (should
  1835. (equal "* H\n: "
  1836. (org-test-with-temp-text "* H\n"
  1837. (forward-line)
  1838. (org-toggle-fixed-width)
  1839. (buffer-string))))
  1840. (should
  1841. (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
  1842. (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
  1843. (goto-char (point-max))
  1844. (org-toggle-fixed-width)
  1845. (buffer-string))))
  1846. ;; No region: Toggle on marker in front of one line elements (e.g.,
  1847. ;; headlines, clocks)
  1848. (should
  1849. (equal ": * Headline"
  1850. (org-test-with-temp-text "* Headline"
  1851. (org-toggle-fixed-width)
  1852. (buffer-string))))
  1853. (should
  1854. (equal ": #+KEYWORD: value"
  1855. (org-test-with-temp-text "#+KEYWORD: value"
  1856. (org-toggle-fixed-width)
  1857. (buffer-string))))
  1858. ;; No region: error in other situations.
  1859. (should-error
  1860. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
  1861. (forward-line)
  1862. (org-toggle-fixed-width)
  1863. (buffer-string)))
  1864. ;; No region: Indentation is preserved.
  1865. (should
  1866. (equal "- A\n : B"
  1867. (org-test-with-temp-text "- A\n B"
  1868. (forward-line)
  1869. (org-toggle-fixed-width)
  1870. (buffer-string))))
  1871. ;; Region: If it contains only fixed-width elements and blank lines,
  1872. ;; toggle off fixed-width markup.
  1873. (should
  1874. (equal "A\n\nB"
  1875. (org-test-with-temp-text ": A\n\n: B"
  1876. (transient-mark-mode 1)
  1877. (push-mark (point) t t)
  1878. (goto-char (point-max))
  1879. (org-toggle-fixed-width)
  1880. (buffer-string))))
  1881. ;; Region: If it contains anything else, toggle on fixed-width but
  1882. ;; not on fixed-width areas.
  1883. (should
  1884. (equal ": A\n: \n: B\n: \n: C"
  1885. (org-test-with-temp-text "A\n\n: B\n\nC"
  1886. (transient-mark-mode 1)
  1887. (push-mark (point) t t)
  1888. (goto-char (point-max))
  1889. (org-toggle-fixed-width)
  1890. (buffer-string))))
  1891. ;; Region: Ignore blank lines at its end, unless it contains only
  1892. ;; such lines.
  1893. (should
  1894. (equal ": A\n\n"
  1895. (org-test-with-temp-text "A\n\n"
  1896. (transient-mark-mode 1)
  1897. (push-mark (point) t t)
  1898. (goto-char (point-max))
  1899. (org-toggle-fixed-width)
  1900. (buffer-string))))
  1901. (should
  1902. (equal ": \n: \n"
  1903. (org-test-with-temp-text "\n\n"
  1904. (transient-mark-mode 1)
  1905. (push-mark (point) t t)
  1906. (goto-char (point-max))
  1907. (org-toggle-fixed-width)
  1908. (buffer-string)))))
  1909. (ert-deftest test-org/kill-line ()
  1910. "Test `org-kill-line' specifications."
  1911. ;; At the beginning of a line, kill whole line.
  1912. (should
  1913. (equal ""
  1914. (org-test-with-temp-text "abc"
  1915. (org-kill-line)
  1916. (buffer-string))))
  1917. ;; In the middle of a line, kill line until its end.
  1918. (should
  1919. (equal "a"
  1920. (org-test-with-temp-text "a<point>bc"
  1921. (org-kill-line)
  1922. (buffer-string))))
  1923. ;; Do not kill newline character.
  1924. (should
  1925. (equal "\n123"
  1926. (org-test-with-temp-text "abc\n123"
  1927. (org-kill-line)
  1928. (buffer-string))))
  1929. (should
  1930. (equal "a\n123"
  1931. (org-test-with-temp-text "a<point>bc\n123"
  1932. (org-kill-line)
  1933. (buffer-string))))
  1934. ;; When `org-special-ctrl-k' is non-nil and point is at a headline,
  1935. ;; kill until tags.
  1936. (should
  1937. (equal "* A :tag:"
  1938. (org-test-with-temp-text "* A<point>B :tag:"
  1939. (let ((org-special-ctrl-k t)
  1940. (org-tags-column 0))
  1941. (org-kill-line))
  1942. (buffer-string))))
  1943. ;; If point is on tags, only kill part left until the end of line.
  1944. (should
  1945. (equal "* A :tag:"
  1946. (org-test-with-temp-text "* A :tag:<point>tag2:"
  1947. (let ((org-special-ctrl-k t)
  1948. (org-tags-column 0))
  1949. (org-kill-line))
  1950. (buffer-string))))
  1951. ;; However, if point is at the beginning of the line, kill whole
  1952. ;; headline.
  1953. (should
  1954. (equal ""
  1955. (org-test-with-temp-text "* AB :tag:"
  1956. (let ((org-special-ctrl-k t)
  1957. (org-tags-column 0))
  1958. (org-kill-line))
  1959. (buffer-string))))
  1960. ;; When `org-ctrl-k-protect-subtree' is non-nil, and point is in
  1961. ;; invisible text, ask before removing it. When set to `error',
  1962. ;; throw an error.
  1963. (should-error
  1964. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  1965. (org-overview)
  1966. (let ((org-special-ctrl-k nil)
  1967. (org-ctrl-k-protect-subtree t))
  1968. (cl-letf (((symbol-function 'y-or-n-p) 'ignore))
  1969. (org-kill-line)))))
  1970. (should-error
  1971. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  1972. (org-overview)
  1973. (let ((org-special-ctrl-k nil)
  1974. (org-ctrl-k-protect-subtree 'error))
  1975. (org-kill-line)))))
  1976. ;;; Headline
  1977. (ert-deftest test-org/get-heading ()
  1978. "Test `org-get-heading' specifications."
  1979. ;; Return current heading, even if point is not on it.
  1980. (should
  1981. (equal "H"
  1982. (org-test-with-temp-text "* H"
  1983. (org-get-heading))))
  1984. (should
  1985. (equal "H"
  1986. (org-test-with-temp-text "* H\nText<point>"
  1987. (org-get-heading))))
  1988. ;; Without any optional argument, return TODO keyword, priority
  1989. ;; cookie, COMMENT keyword and tags.
  1990. (should
  1991. (equal "TODO H"
  1992. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  1993. (org-get-heading))))
  1994. (should
  1995. (equal "[#A] H"
  1996. (org-test-with-temp-text "* [#A] H"
  1997. (org-get-heading))))
  1998. (should
  1999. (equal "COMMENT H"
  2000. (org-test-with-temp-text "* COMMENT H"
  2001. (org-get-heading))))
  2002. (should
  2003. (equal "H :tag:"
  2004. (org-test-with-temp-text "* H :tag:"
  2005. (org-get-heading))))
  2006. ;; With NO-TAGS argument, ignore tags.
  2007. (should
  2008. (equal "TODO H"
  2009. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2010. (org-get-heading t))))
  2011. (should
  2012. (equal "H"
  2013. (org-test-with-temp-text "* H :tag:"
  2014. (org-get-heading t))))
  2015. ;; With NO-TODO, ignore TODO keyword.
  2016. (should
  2017. (equal "H"
  2018. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2019. (org-get-heading nil t))))
  2020. (should
  2021. (equal "H :tag:"
  2022. (org-test-with-temp-text "* H :tag:"
  2023. (org-get-heading nil t))))
  2024. ;; TODO keywords are case-sensitive.
  2025. (should
  2026. (equal "Todo H"
  2027. (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
  2028. (org-get-heading nil t))))
  2029. ;; With NO-PRIORITY, ignore priority.
  2030. (should
  2031. (equal "H"
  2032. (org-test-with-temp-text "* [#A] H"
  2033. (org-get-heading nil nil t))))
  2034. (should
  2035. (equal "H"
  2036. (org-test-with-temp-text "* H"
  2037. (org-get-heading nil nil t))))
  2038. (should
  2039. (equal "TODO H"
  2040. (org-test-with-temp-text "* TODO [#A] H"
  2041. (org-get-heading nil nil t))))
  2042. ;; With NO-COMMENT, ignore COMMENT keyword.
  2043. (should
  2044. (equal "H"
  2045. (org-test-with-temp-text "* COMMENT H"
  2046. (org-get-heading nil nil nil t))))
  2047. (should
  2048. (equal "H"
  2049. (org-test-with-temp-text "* H"
  2050. (org-get-heading nil nil nil t))))
  2051. (should
  2052. (equal "TODO [#A] H"
  2053. (org-test-with-temp-text "* TODO [#A] COMMENT H"
  2054. (org-get-heading nil nil nil t))))
  2055. ;; On an empty headline, return value is consistent.
  2056. (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
  2057. (should (equal "" (org-test-with-temp-text "* " (org-get-heading t))))
  2058. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t))))
  2059. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t))))
  2060. (should
  2061. (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t)))))
  2062. (ert-deftest test-org/in-commented-heading-p ()
  2063. "Test `org-in-commented-heading-p' specifications."
  2064. ;; Commented headline.
  2065. (should
  2066. (org-test-with-temp-text "* COMMENT Headline\nBody"
  2067. (goto-char (point-max))
  2068. (org-in-commented-heading-p)))
  2069. ;; Commented ancestor.
  2070. (should
  2071. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  2072. (goto-char (point-max))
  2073. (org-in-commented-heading-p)))
  2074. ;; Comment keyword is case-sensitive.
  2075. (should-not
  2076. (org-test-with-temp-text "* Comment Headline\nBody"
  2077. (goto-char (point-max))
  2078. (org-in-commented-heading-p)))
  2079. ;; Keyword is standalone.
  2080. (should-not
  2081. (org-test-with-temp-text "* COMMENTHeadline\nBody"
  2082. (goto-char (point-max))
  2083. (org-in-commented-heading-p)))
  2084. ;; Optional argument.
  2085. (should-not
  2086. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  2087. (goto-char (point-max))
  2088. (org-in-commented-heading-p t))))
  2089. (ert-deftest test-org/in-archived-heading-p ()
  2090. "Test `org-in-archived-heading-p' specifications."
  2091. ;; Archived headline.
  2092. (should
  2093. (org-test-with-temp-text "* Headline :ARCHIVE:\nBody"
  2094. (goto-char (point-max))
  2095. (org-in-archived-heading-p)))
  2096. ;; Archived ancestor.
  2097. (should
  2098. (org-test-with-temp-text "* Headline :ARCHIVE:\n** Level 2\nBody"
  2099. (goto-char (point-max))
  2100. (org-in-archived-heading-p)))
  2101. ;; Optional argument.
  2102. (should-not
  2103. (org-test-with-temp-text "* Headline :ARCHIVE:\n** Level 2\nBody"
  2104. (goto-char (point-max))
  2105. (org-in-archived-heading-p t)))
  2106. ;; Archive tag containing ARCHIVE as substring
  2107. (should-not
  2108. (org-test-with-temp-text "* Headline :NOARCHIVE:\n** Level 2\nBody"
  2109. (goto-char (point-max))
  2110. (org-in-archived-heading-p))))
  2111. (ert-deftest test-org/entry-blocked-p ()
  2112. ;; Check other dependencies.
  2113. (should
  2114. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  2115. (let ((org-enforce-todo-dependencies t)
  2116. (org-blocker-hook
  2117. '(org-block-todo-from-children-or-siblings-or-parent)))
  2118. (org-entry-blocked-p))))
  2119. (should-not
  2120. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  2121. (let ((org-enforce-todo-dependencies t)
  2122. (org-blocker-hook
  2123. '(org-block-todo-from-children-or-siblings-or-parent)))
  2124. (org-entry-blocked-p))))
  2125. ;; Entry without a TODO keyword or with a DONE keyword cannot be
  2126. ;; blocked.
  2127. (should-not
  2128. (org-test-with-temp-text "* Blocked\n** TODO one"
  2129. (let ((org-enforce-todo-dependencies t)
  2130. (org-blocker-hook
  2131. '(org-block-todo-from-children-or-siblings-or-parent)))
  2132. (org-entry-blocked-p))))
  2133. (should-not
  2134. (org-test-with-temp-text "* DONE Blocked\n** TODO one"
  2135. (let ((org-enforce-todo-dependencies t)
  2136. (org-blocker-hook
  2137. '(org-block-todo-from-children-or-siblings-or-parent)))
  2138. (org-entry-blocked-p))))
  2139. ;; Follow :ORDERED: specifications.
  2140. (should
  2141. (org-test-with-temp-text
  2142. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
  2143. (let ((org-enforce-todo-dependencies t)
  2144. (org-blocker-hook
  2145. '(org-block-todo-from-children-or-siblings-or-parent)))
  2146. (org-entry-blocked-p))))
  2147. (should-not
  2148. (org-test-with-temp-text
  2149. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
  2150. (let ((org-enforce-todo-dependencies t)
  2151. (org-blocker-hook
  2152. '(org-block-todo-from-children-or-siblings-or-parent)))
  2153. (org-entry-blocked-p)))))
  2154. (ert-deftest test-org/get-outline-path ()
  2155. "Test `org-get-outline-path' specifications."
  2156. ;; Top-level headlines have no outline path.
  2157. (should-not
  2158. (org-test-with-temp-text "* H"
  2159. (org-get-outline-path)))
  2160. ;; Otherwise, outline path is the path leading to the headline.
  2161. (should
  2162. (equal '("H")
  2163. (org-test-with-temp-text "* H\n** S<point>"
  2164. (org-get-outline-path))))
  2165. ;; Find path even when point is not on a headline.
  2166. (should
  2167. (equal '("H")
  2168. (org-test-with-temp-text "* H\n** S\nText<point>"
  2169. (org-get-outline-path))))
  2170. ;; TODO keywords, tags and statistics cookies are ignored.
  2171. (should
  2172. (equal '("H")
  2173. (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
  2174. (org-get-outline-path))))
  2175. ;; Links are replaced with their description or their path.
  2176. (should
  2177. (equal '("Org")
  2178. (org-test-with-temp-text
  2179. "* [[https://orgmode.org][Org]]\n** S<point>"
  2180. (org-get-outline-path))))
  2181. (should
  2182. (equal '("https://orgmode.org")
  2183. (org-test-with-temp-text
  2184. "* [[https://orgmode.org]]\n** S<point>"
  2185. (org-get-outline-path))))
  2186. ;; When WITH-SELF is non-nil, include current heading.
  2187. (should
  2188. (equal '("H")
  2189. (org-test-with-temp-text "* H"
  2190. (org-get-outline-path t))))
  2191. (should
  2192. (equal '("H" "S")
  2193. (org-test-with-temp-text "* H\n** S\nText<point>"
  2194. (org-get-outline-path t))))
  2195. ;; Using cache is transparent to the user.
  2196. (should
  2197. (equal '("H")
  2198. (org-test-with-temp-text "* H\n** S<point>"
  2199. (setq org-outline-path-cache nil)
  2200. (org-get-outline-path nil t))))
  2201. ;; Do not corrupt cache when finding outline path in distant part of
  2202. ;; the buffer.
  2203. (should
  2204. (equal '("H2")
  2205. (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
  2206. (setq org-outline-path-cache nil)
  2207. (org-get-outline-path nil t)
  2208. (search-forward "S2")
  2209. (org-get-outline-path nil t))))
  2210. ;; Do not choke on empty headlines.
  2211. (should
  2212. (org-test-with-temp-text "* H\n** <point>"
  2213. (org-get-outline-path)))
  2214. (should
  2215. (org-test-with-temp-text "* \n** H<point>"
  2216. (org-get-outline-path))))
  2217. (ert-deftest test-org/format-outline-path ()
  2218. "Test `org-format-outline-path' specifications."
  2219. (should
  2220. (string= (org-format-outline-path (list "one" "two" "three"))
  2221. "one/two/three"))
  2222. ;; Empty path.
  2223. (should
  2224. (string= (org-format-outline-path '())
  2225. ""))
  2226. (should
  2227. (string= (org-format-outline-path '(nil))
  2228. ""))
  2229. ;; Empty path and prefix.
  2230. (should
  2231. (string= (org-format-outline-path '() nil ">>")
  2232. ">>"))
  2233. ;; Trailing whitespace in headings.
  2234. (should
  2235. (string= (org-format-outline-path (list "one\t" "tw o " "three "))
  2236. "one/tw o/three"))
  2237. ;; Non-default prefix and separators.
  2238. (should
  2239. (string= (org-format-outline-path (list "one" "two" "three") nil ">>" "|")
  2240. ">>|one|two|three"))
  2241. ;; Truncate.
  2242. (should
  2243. (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
  2244. "one/two/.."))
  2245. ;; Give a very narrow width.
  2246. (should
  2247. (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
  2248. "on"))
  2249. ;; Give a prefix that extends beyond the width.
  2250. (should
  2251. (string= (org-format-outline-path (list "one" "two" "three" "four") 10
  2252. ">>>>>>>>>>")
  2253. ">>>>>>>>..")))
  2254. (ert-deftest test-org/map-entries ()
  2255. "Test `org-map-entries' specifications."
  2256. ;; Full match.
  2257. (should
  2258. (equal '(1 11)
  2259. (org-test-with-temp-text "* Level 1\n** Level 2"
  2260. (org-map-entries #'point))))
  2261. ;; Level match.
  2262. (should
  2263. (equal '(1)
  2264. (org-test-with-temp-text "* Level 1\n** Level 2"
  2265. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL=1")))))
  2266. (should
  2267. (equal '(11)
  2268. (org-test-with-temp-text "* Level 1\n** Level 2"
  2269. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL>1")))))
  2270. ;; Tag match.
  2271. (should
  2272. (equal '(11)
  2273. (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
  2274. (org-map-entries #'point "yes"))))
  2275. (should
  2276. (equal '(14)
  2277. (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
  2278. (org-map-entries #'point "+yes-a"))))
  2279. (should
  2280. (equal '(11 23)
  2281. (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
  2282. (org-map-entries #'point "{yes?}"))))
  2283. ;; Priority match.
  2284. (should
  2285. (equal '(1)
  2286. (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
  2287. (org-map-entries #'point "PRIORITY=\"A\""))))
  2288. ;; Date match.
  2289. (should
  2290. (equal '(36)
  2291. (org-test-with-temp-text "
  2292. * H1
  2293. SCHEDULED: <2012-03-29 thu.>
  2294. * H2
  2295. SCHEDULED: <2014-03-04 tue.>"
  2296. (org-map-entries #'point "SCHEDULED=\"<2014-03-04 tue.>\""))))
  2297. (should
  2298. (equal '(2)
  2299. (org-test-with-temp-text "
  2300. * H1
  2301. SCHEDULED: <2012-03-29 thu.>
  2302. * H2
  2303. SCHEDULED: <2014-03-04 tue.>"
  2304. (org-map-entries #'point "SCHEDULED<\"<2013-01-01>\""))))
  2305. ;; Regular property match.
  2306. (should
  2307. (equal '(2)
  2308. (org-test-with-temp-text "
  2309. * H1
  2310. :PROPERTIES:
  2311. :TEST: 1
  2312. :END:
  2313. * H2
  2314. :PROPERTIES:
  2315. :TEST: 2
  2316. :END:"
  2317. (org-map-entries #'point "TEST=1"))))
  2318. ;; Multiple criteria.
  2319. (should
  2320. (equal '(23)
  2321. (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
  2322. (let (org-odd-levels-only
  2323. (org-use-tag-inheritance nil))
  2324. (org-map-entries #'point "yes+LEVEL=1")))))
  2325. ;; "or" criteria.
  2326. (should
  2327. (equal '(12 24)
  2328. (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
  2329. (let (org-odd-levels-only)
  2330. (org-map-entries #'point "LEVEL=2|no")))))
  2331. (should
  2332. (equal '(1 12)
  2333. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
  2334. (let (org-odd-levels-only)
  2335. (org-map-entries #'point "yes|no")))))
  2336. ;; "and" criteria.
  2337. (should
  2338. (equal '(22)
  2339. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
  2340. (let (org-odd-levels-only)
  2341. (org-map-entries #'point "yes&no"))))))
  2342. (ert-deftest test-org/edit-headline ()
  2343. "Test `org-edit-headline' specifications."
  2344. (should
  2345. (equal "* B"
  2346. (org-test-with-temp-text "* A"
  2347. (org-edit-headline "B")
  2348. (buffer-string))))
  2349. ;; Handle empty headings.
  2350. (should
  2351. (equal "* "
  2352. (org-test-with-temp-text "* A"
  2353. (org-edit-headline "")
  2354. (buffer-string))))
  2355. (should
  2356. (equal "* A"
  2357. (org-test-with-temp-text "* "
  2358. (org-edit-headline "A")
  2359. (buffer-string))))
  2360. ;; Handle TODO keywords and priority cookies.
  2361. (should
  2362. (equal "* TODO B"
  2363. (org-test-with-temp-text "* TODO A"
  2364. (org-edit-headline "B")
  2365. (buffer-string))))
  2366. (should
  2367. (equal "* [#A] B"
  2368. (org-test-with-temp-text "* [#A] A"
  2369. (org-edit-headline "B")
  2370. (buffer-string))))
  2371. (should
  2372. (equal "* TODO [#A] B"
  2373. (org-test-with-temp-text "* TODO [#A] A"
  2374. (org-edit-headline "B")
  2375. (buffer-string))))
  2376. ;; Handle tags.
  2377. (equal "* B :tag:"
  2378. (org-test-with-temp-text "* A :tag:"
  2379. (let ((org-tags-column 4)) (org-edit-headline "B"))
  2380. (buffer-string))))
  2381. ;;; Keywords
  2382. (ert-deftest test-org/set-regexps-and-options ()
  2383. "Test `org-set-regexps-and-options' specifications."
  2384. ;; TAGS keyword.
  2385. (should
  2386. (equal '(("A"))
  2387. (let ((org-tag-alist '(("A")))
  2388. (org-tag-persistent-alist nil))
  2389. (org-test-with-temp-text ""
  2390. (org-mode-restart)
  2391. org-current-tag-alist))))
  2392. (should
  2393. (equal '(("B"))
  2394. (let ((org-tag-alist '(("A")))
  2395. (org-tag-persistent-alist nil))
  2396. (org-test-with-temp-text "#+TAGS: B"
  2397. (org-mode-restart)
  2398. org-current-tag-alist))))
  2399. (should
  2400. (equal '(("C") ("B"))
  2401. (let ((org-tag-alist '(("A")))
  2402. (org-tag-persistent-alist '(("C"))))
  2403. (org-test-with-temp-text "#+TAGS: B"
  2404. (org-mode-restart)
  2405. org-current-tag-alist))))
  2406. (should
  2407. (equal '(("B"))
  2408. (let ((org-tag-alist '(("A")))
  2409. (org-tag-persistent-alist '(("C"))))
  2410. (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
  2411. (org-mode-restart)
  2412. org-current-tag-alist))))
  2413. (should
  2414. (equal '(("A" . ?a) ("B") ("C"))
  2415. (let ((org-tag-persistant-alist nil))
  2416. (org-test-with-temp-text "#+TAGS: A(a) B C"
  2417. (org-mode-restart)
  2418. org-current-tag-alist))))
  2419. (should
  2420. (equal '(("A") (:newline) ("B"))
  2421. (let ((org-tag-persistent-alist nil))
  2422. (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
  2423. (org-mode-restart)
  2424. org-current-tag-alist))))
  2425. (should
  2426. (equal '((:startgroup) ("A") ("B") (:endgroup) ("C"))
  2427. (let ((org-tag-persistent-alist nil))
  2428. (org-test-with-temp-text "#+TAGS: { A B } C"
  2429. (org-mode-restart)
  2430. org-current-tag-alist))))
  2431. (should
  2432. (equal '((:startgroup) ("A") (:grouptags) ("B") ("C") (:endgroup))
  2433. (let ((org-tag-persistent-alist nil))
  2434. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2435. (org-mode-restart)
  2436. org-current-tag-alist))))
  2437. (should
  2438. (equal '(("A" "B" "C"))
  2439. (let ((org-tag-persistent-alist nil))
  2440. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2441. (org-mode-restart)
  2442. org-tag-groups-alist))))
  2443. (should
  2444. (equal '((:startgrouptag) ("A") (:grouptags) ("B") ("C") (:endgrouptag))
  2445. (let ((org-tag-persistent-alist nil))
  2446. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2447. (org-mode-restart)
  2448. org-current-tag-alist))))
  2449. (should
  2450. (equal '(("A" "B" "C"))
  2451. (let ((org-tag-persistent-alist nil))
  2452. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2453. (org-mode-restart)
  2454. org-tag-groups-alist))))
  2455. (should-not
  2456. (let ((org-tag-alist '(("A"))))
  2457. (org-test-with-temp-text "#+TAGS:"
  2458. (org-mode-restart)
  2459. org-current-tag-alist)))
  2460. ;; FILETAGS keyword.
  2461. (should
  2462. (equal '("A" "B" "C")
  2463. (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
  2464. (org-mode-restart)
  2465. org-file-tags)))
  2466. ;; PROPERTY keyword. Property names are case-insensitive.
  2467. (should
  2468. (equal "foo=1"
  2469. (org-test-with-temp-text "#+PROPERTY: var foo=1"
  2470. (org-mode-restart)
  2471. (cdr (assoc "var" org-keyword-properties)))))
  2472. (should
  2473. (equal
  2474. "foo=1 bar=2"
  2475. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
  2476. (org-mode-restart)
  2477. (cdr (assoc "var" org-keyword-properties)))))
  2478. (should
  2479. (equal
  2480. "foo=1 bar=2"
  2481. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
  2482. (org-mode-restart)
  2483. (cdr (assoc "var" org-keyword-properties)))))
  2484. ;; ARCHIVE keyword.
  2485. (should
  2486. (equal "%s_done::"
  2487. (org-test-with-temp-text "#+ARCHIVE: %s_done::"
  2488. (org-mode-restart)
  2489. org-archive-location)))
  2490. ;; CATEGORY keyword.
  2491. (should
  2492. (eq 'test
  2493. (org-test-with-temp-text "#+CATEGORY: test"
  2494. (org-mode-restart)
  2495. org-category)))
  2496. (should
  2497. (equal "test"
  2498. (org-test-with-temp-text "#+CATEGORY: test"
  2499. (org-mode-restart)
  2500. (cdr (assoc "CATEGORY" org-keyword-properties)))))
  2501. ;; COLUMNS keyword.
  2502. (should
  2503. (equal "%25ITEM %TAGS %PRIORITY %TODO"
  2504. (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
  2505. (org-mode-restart)
  2506. org-columns-default-format)))
  2507. ;; CONSTANTS keyword. Constants names are case sensitive.
  2508. (should
  2509. (equal '("299792458." "3.14")
  2510. (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
  2511. (org-mode-restart)
  2512. (mapcar
  2513. (lambda (n) (cdr (assoc n org-table-formula-constants-local)))
  2514. '("c" "pi")))))
  2515. (should
  2516. (equal "3.14"
  2517. (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
  2518. (org-mode-restart)
  2519. (cdr (assoc "pi" org-table-formula-constants-local)))))
  2520. (should
  2521. (equal "22/7"
  2522. (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
  2523. (org-mode-restart)
  2524. (cdr (assoc "PI" org-table-formula-constants-local)))))
  2525. ;; LINK keyword.
  2526. (should
  2527. (equal
  2528. '("url1" "url2")
  2529. (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
  2530. (org-mode-restart)
  2531. (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local)))
  2532. '("a" "b")))))
  2533. ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
  2534. (should
  2535. (equal
  2536. '(?X ?Z ?Y)
  2537. (org-test-with-temp-text "#+PRIORITIES: X Z Y"
  2538. (org-mode-restart)
  2539. (list org-priority-highest org-priority-lowest org-priority-default))))
  2540. (should
  2541. (equal
  2542. '(?A ?C ?B)
  2543. (org-test-with-temp-text "#+PRIORITIES: X Z"
  2544. (org-mode-restart)
  2545. (list org-priority-highest org-priority-lowest org-priority-default))))
  2546. ;; STARTUP keyword.
  2547. (should
  2548. (equal '(t t)
  2549. (org-test-with-temp-text "#+STARTUP: fold odd"
  2550. (org-mode-restart)
  2551. (list org-startup-folded org-odd-levels-only))))
  2552. ;; TODO keywords.
  2553. (should
  2554. (equal '(("A" "B") ("C"))
  2555. (org-test-with-temp-text "#+TODO: A B | C"
  2556. (org-mode-restart)
  2557. (list org-not-done-keywords org-done-keywords))))
  2558. (should
  2559. (equal '(("A" "C") ("B" "D"))
  2560. (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
  2561. (org-mode-restart)
  2562. (list org-not-done-keywords org-done-keywords))))
  2563. (should
  2564. (equal '(("A" "B") ("C"))
  2565. (org-test-with-temp-text "#+TYP_TODO: A B | C"
  2566. (org-mode-restart)
  2567. (list org-not-done-keywords org-done-keywords))))
  2568. (should
  2569. (equal '((:startgroup) ("A" . ?a) (:endgroup))
  2570. (org-test-with-temp-text "#+TODO: A(a)"
  2571. (org-mode-restart)
  2572. org-todo-key-alist)))
  2573. (should
  2574. (equal '(("D" note nil) ("C" time nil) ("B" note time))
  2575. (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
  2576. (org-mode-restart)
  2577. org-todo-log-states)))
  2578. ;; Enter SETUPFILE keyword.
  2579. (should
  2580. (equal "1"
  2581. (org-test-with-temp-text
  2582. (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
  2583. (org-mode-restart)
  2584. (cdr (assoc "a" org-keyword-properties))))))
  2585. ;;; Links
  2586. ;;;; Coderefs
  2587. (ert-deftest test-org/coderef ()
  2588. "Test coderef links specifications."
  2589. (should
  2590. (org-test-with-temp-text "
  2591. #+BEGIN_SRC emacs-lisp
  2592. \(+ 1 1) (ref:sc)
  2593. #+END_SRC
  2594. \[[(sc)<point>]]"
  2595. (org-open-at-point)
  2596. (looking-at "(ref:sc)")))
  2597. ;; Find coderef even with alternate label format.
  2598. (should
  2599. (org-test-with-temp-text "
  2600. #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
  2601. \(+ 1 1) {ref:sc}
  2602. #+END_SRC
  2603. \[[(sc)<point>]]"
  2604. (org-open-at-point)
  2605. (looking-at "{ref:sc}"))))
  2606. ;;;; Custom ID
  2607. (ert-deftest test-org/custom-id ()
  2608. "Test custom ID links specifications."
  2609. (should
  2610. (org-test-with-temp-text
  2611. "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2612. (org-open-at-point)
  2613. (looking-at-p "\\* H1")))
  2614. ;; Handle escape characters.
  2615. (should
  2616. (org-test-with-temp-text
  2617. "* H1\n:PROPERTIES:\n:CUSTOM_ID: [%]\n:END:\n* H2\n[[#\\[%\\]<point>]]"
  2618. (org-open-at-point)
  2619. (looking-at-p "\\* H1")))
  2620. ;; Throw an error on false positives.
  2621. (should-error
  2622. (org-test-with-temp-text
  2623. "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2624. (org-open-at-point)
  2625. (looking-at-p "\\* H1"))))
  2626. ;;;; Fuzzy Links
  2627. ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
  2628. ;; a named element (#+name: text) and to headlines (* Text).
  2629. (ert-deftest test-org/fuzzy-links ()
  2630. "Test fuzzy links specifications."
  2631. ;; Fuzzy link goes in priority to a matching target.
  2632. (should
  2633. (org-test-with-temp-text
  2634. "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
  2635. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2636. (looking-at "<<Test>>")))
  2637. ;; Then fuzzy link points to an element with a given name.
  2638. (should
  2639. (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
  2640. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2641. (looking-at "#\\+NAME: Test")))
  2642. ;; A target still lead to a matching headline otherwise.
  2643. (should
  2644. (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
  2645. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2646. (looking-at "\\* Head2")))
  2647. ;; With a leading star in link, enforce heading match.
  2648. (should
  2649. (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
  2650. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2651. (looking-at "\\* Test")))
  2652. ;; With a leading star in link, enforce exact heading match, even
  2653. ;; with `org-link-search-must-match-exact-headline' set to nil.
  2654. (should-error
  2655. (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
  2656. (let ((org-link-search-must-match-exact-headline nil))
  2657. (org-open-at-point))))
  2658. ;; Handle non-nil `org-link-search-must-match-exact-headline'.
  2659. (should
  2660. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
  2661. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2662. (looking-at "\\* Test")))
  2663. (should
  2664. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
  2665. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2666. (looking-at "\\* Test")))
  2667. ;; Heading match should not care about spaces, cookies, TODO
  2668. ;; keywords, priorities, and tags. However, TODO keywords are
  2669. ;; case-sensitive.
  2670. (should
  2671. (let ((first-line
  2672. "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
  2673. (org-test-with-temp-text
  2674. (concat first-line "\nFoo Bar\n<point>[[*Test 1 2]]")
  2675. (let ((org-link-search-must-match-exact-headline nil)
  2676. (org-todo-regexp "TODO"))
  2677. (org-open-at-point))
  2678. (looking-at (regexp-quote first-line)))))
  2679. (should-error
  2680. (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
  2681. (let ((org-link-search-must-match-exact-headline nil)
  2682. (org-todo-regexp "TODO"))
  2683. (org-open-at-point))))
  2684. ;; Heading match should still be exact.
  2685. (should-error
  2686. (org-test-with-temp-text "
  2687. ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
  2688. Foo Bar
  2689. <point>[[*Test 1]]"
  2690. (let ((org-link-search-must-match-exact-headline nil)
  2691. (org-todo-regexp "TODO"))
  2692. (org-open-at-point))))
  2693. (should
  2694. (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
  2695. (let ((org-link-search-must-match-exact-headline nil)
  2696. (org-todo-regexp "TODO"))
  2697. (org-open-at-point))
  2698. (looking-at-p (regexp-quote "** Test 1 2"))))
  2699. ;; Heading match ignores COMMENT keyword.
  2700. (should
  2701. (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
  2702. (org-open-at-point)
  2703. (looking-at "\\* COMMENT Test")))
  2704. (should
  2705. (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
  2706. (org-open-at-point)
  2707. (looking-at "\\* TODO COMMENT Test")))
  2708. ;; Correctly un-escape fuzzy links.
  2709. (should
  2710. (org-test-with-temp-text "* [foo]\n[[*\\[foo\\]][With escaped characters]]"
  2711. (org-open-at-point)
  2712. (bobp)))
  2713. ;; Match search strings containing newline characters, including
  2714. ;; blank lines.
  2715. (should
  2716. (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
  2717. (let ((file (buffer-file-name)))
  2718. (goto-char (point-max))
  2719. (insert (format "[[file:%s::line1 line2]]" file))
  2720. (beginning-of-line)
  2721. (let ((org-link-search-must-match-exact-headline nil))
  2722. (org-open-at-point 0))
  2723. (looking-at-p "line1"))))
  2724. (should
  2725. (org-test-with-temp-text-in-file "Paragraph\n\nline1\n\nline2\n\n"
  2726. (let ((file (buffer-file-name)))
  2727. (goto-char (point-max))
  2728. (insert (format "[[file:%s::line1 line2]]" file))
  2729. (beginning-of-line)
  2730. (let ((org-link-search-must-match-exact-headline nil))
  2731. (org-open-at-point 0))
  2732. (looking-at-p "line1")))))
  2733. ;;;; Open at point
  2734. (ert-deftest test-org/open-at-point/keyword ()
  2735. "Does `org-open-at-point' open link in a keyword line?"
  2736. (should
  2737. (org-test-with-temp-text
  2738. "<<top>>\n#+KEYWORD: <point>[[top]]"
  2739. (org-open-at-point) t))
  2740. (should
  2741. (org-test-with-temp-text
  2742. "* H\n<<top>>\n#+KEYWORD: <point>[[top]]"
  2743. (org-open-at-point) t)))
  2744. (ert-deftest test-org/open-at-point/property ()
  2745. "Does `org-open-at-point' open link in property drawer?"
  2746. (should
  2747. (org-test-with-temp-text
  2748. "* Headline
  2749. :PROPERTIES:
  2750. :URL: <point>[[*Headline]]
  2751. :END:"
  2752. (org-open-at-point) t)))
  2753. (ert-deftest test-org/open-at-point/comment ()
  2754. "Does `org-open-at-point' open link in a commented line?"
  2755. (should
  2756. (org-test-with-temp-text
  2757. "<<top>>\n# <point>[[top]]"
  2758. (org-open-at-point) t))
  2759. (should
  2760. (org-test-with-temp-text
  2761. "* H\n<<top>>\n# <point>[[top]]"
  2762. (org-open-at-point) t)))
  2763. (ert-deftest test-org/open-at-point/inline-image ()
  2764. "Test `org-open-at-point' on nested links."
  2765. (should
  2766. (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
  2767. (org-open-at-point)
  2768. (bobp))))
  2769. (ert-deftest test-org/open-at-point/radio-target ()
  2770. "Test `org-open-at-point' on radio targets."
  2771. (should
  2772. (org-test-with-temp-text "<<<target>>> <point>target"
  2773. (org-update-radio-target-regexp)
  2774. (org-open-at-point)
  2775. (eq (org-element-type (org-element-context)) 'radio-target))))
  2776. (ert-deftest test-org/open-at-point/tag ()
  2777. "Test `org-open-at-point' on tags."
  2778. (should
  2779. (org-test-with-temp-text "* H :<point>tag:"
  2780. (catch :result
  2781. (cl-letf (((symbol-function 'org-tags-view)
  2782. (lambda (&rest args) (throw :result t))))
  2783. (org-open-at-point)
  2784. nil))))
  2785. (should-not
  2786. (org-test-with-temp-text-in-file "* H<point> :tag:"
  2787. (catch :result
  2788. (cl-letf (((symbol-function 'org-tags-view)
  2789. (lambda (&rest args) (throw :result t))))
  2790. ;; When point isn't on a tag it's going to try other things,
  2791. ;; possibly trying to open attachments which will return an
  2792. ;; error if there isn't an attachment. Suppress that error.
  2793. (ignore-errors
  2794. (org-open-at-point))
  2795. nil)))))
  2796. ;;; Node Properties
  2797. (ert-deftest test-org/accumulated-properties-in-drawers ()
  2798. "Ensure properties accumulate in subtree drawers."
  2799. (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
  2800. (org-babel-next-src-block)
  2801. (should (equal '(2 1) (org-babel-execute-src-block)))))
  2802. (ert-deftest test-org/custom-properties ()
  2803. "Test custom properties specifications."
  2804. ;; Standard test.
  2805. (should
  2806. (let ((org-custom-properties '("FOO")))
  2807. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2808. (org-toggle-custom-properties-visibility)
  2809. (org-invisible-p2))))
  2810. ;; Properties are case-insensitive.
  2811. (should
  2812. (let ((org-custom-properties '("FOO")))
  2813. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
  2814. (org-toggle-custom-properties-visibility)
  2815. (org-invisible-p2))))
  2816. (should
  2817. (let ((org-custom-properties '("foo")))
  2818. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2819. (org-toggle-custom-properties-visibility)
  2820. (org-invisible-p2))))
  2821. ;; Multiple custom properties in the same drawer.
  2822. (should
  2823. (let ((org-custom-properties '("FOO" "BAR")))
  2824. (org-test-with-temp-text
  2825. "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
  2826. (org-toggle-custom-properties-visibility)
  2827. (and (org-invisible-p2)
  2828. (not (progn (forward-line) (org-invisible-p2)))
  2829. (progn (forward-line) (org-invisible-p2))))))
  2830. ;; Hide custom properties with an empty value.
  2831. (should
  2832. (let ((org-custom-properties '("FOO")))
  2833. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
  2834. (org-toggle-custom-properties-visibility)
  2835. (org-invisible-p2))))
  2836. ;; Do not hide fake properties.
  2837. (should-not
  2838. (let ((org-custom-properties '("FOO")))
  2839. (org-test-with-temp-text ":FOO: val\n"
  2840. (org-toggle-custom-properties-visibility)
  2841. (org-invisible-p2))))
  2842. (should-not
  2843. (let ((org-custom-properties '("A")))
  2844. (org-test-with-temp-text
  2845. "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
  2846. (org-toggle-custom-properties-visibility)
  2847. (org-invisible-p2)))))
  2848. ;;; Mark Region
  2849. (ert-deftest test-org/mark-element ()
  2850. "Test `org-mark-element' specifications."
  2851. ;; Mark beginning and end of element.
  2852. (should
  2853. (equal '(t t)
  2854. (org-test-with-temp-text "Para<point>graph"
  2855. (org-mark-element)
  2856. (list (bobp) (= (mark) (point-max))))))
  2857. (should
  2858. (equal '(t t)
  2859. (org-test-with-temp-text "P1\n\nPara<point>graph\n\nP2"
  2860. (org-mark-element)
  2861. (list (looking-at "Paragraph")
  2862. (org-with-point-at (mark) (looking-at "P2"))))))
  2863. ;; Do not set mark past (point-max).
  2864. (should
  2865. (org-test-with-temp-text "Para<point>graph"
  2866. (narrow-to-region 2 6)
  2867. (org-mark-element)
  2868. (= 6 (mark)))))
  2869. (ert-deftest test-org/mark-subtree ()
  2870. "Test `org-mark-subtree' specifications."
  2871. ;; Error when point is before first headline.
  2872. (should-error
  2873. (org-test-with-temp-text "Paragraph\n* Headline\nBody"
  2874. (progn (transient-mark-mode 1)
  2875. (org-mark-subtree))))
  2876. ;; Without argument, mark current subtree.
  2877. (should
  2878. (equal
  2879. '(12 32)
  2880. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  2881. (progn (transient-mark-mode 1)
  2882. (forward-line 2)
  2883. (org-mark-subtree)
  2884. (list (region-beginning) (region-end))))))
  2885. ;; With an argument, move ARG up.
  2886. (should
  2887. (equal
  2888. '(1 32)
  2889. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  2890. (progn (transient-mark-mode 1)
  2891. (forward-line 2)
  2892. (org-mark-subtree 1)
  2893. (list (region-beginning) (region-end))))))
  2894. ;; Do not get fooled by inlinetasks.
  2895. (when (featurep 'org-inlinetask)
  2896. (should
  2897. (= 1
  2898. (org-test-with-temp-text "* Headline\n*************** Task\nContents"
  2899. (progn (transient-mark-mode 1)
  2900. (forward-line 1)
  2901. (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
  2902. (region-beginning)))))))
  2903. ;;; Miscellaneous
  2904. (ert-deftest test-org/sort-entries ()
  2905. "Test `org-sort-entries'."
  2906. ;; Sort alphabetically.
  2907. (should
  2908. (equal "\n* abc\n* def\n* xyz\n"
  2909. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  2910. (org-sort-entries nil ?a)
  2911. (buffer-string))))
  2912. (should
  2913. (equal "\n* xyz\n* def\n* abc\n"
  2914. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  2915. (org-sort-entries nil ?A)
  2916. (buffer-string))))
  2917. (should
  2918. (equal "\n* \n* klm\n* xyz\n"
  2919. (org-test-with-temp-text "\n* xyz\n* \n* klm\n"
  2920. (org-sort-entries nil ?a)
  2921. (buffer-string))))
  2922. ;; Sort numerically.
  2923. (should
  2924. (equal "\n* 1\n* 2\n* 10\n"
  2925. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  2926. (org-sort-entries nil ?n)
  2927. (buffer-string))))
  2928. (should
  2929. (equal "\n* 10\n* 2\n* 1\n"
  2930. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  2931. (org-sort-entries nil ?N)
  2932. (buffer-string))))
  2933. (should
  2934. (equal "\n* \n* 1\n* 2\n"
  2935. (org-test-with-temp-text "\n* 1\n* \n* 2\n"
  2936. (org-sort-entries nil ?n)
  2937. (buffer-string))))
  2938. ;; Sort by custom function.
  2939. (should
  2940. (equal "\n* b\n* aa\n* ccc\n"
  2941. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  2942. (org-sort-entries nil ?f
  2943. (lambda ()
  2944. (length (buffer-substring (point-at-bol)
  2945. (point-at-eol))))
  2946. #'<)
  2947. (buffer-string))))
  2948. (should
  2949. (equal "\n* ccc\n* aa\n* b\n"
  2950. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  2951. (org-sort-entries nil ?F
  2952. (lambda ()
  2953. (length (buffer-substring (point-at-bol)
  2954. (point-at-eol))))
  2955. #'<)
  2956. (buffer-string))))
  2957. ;; Sort by TODO keyword.
  2958. (should
  2959. (equal "\n* TODO h1\n* TODO h3\n* DONE h2\n"
  2960. (org-test-with-temp-text
  2961. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  2962. (org-sort-entries nil ?o)
  2963. (buffer-string))))
  2964. (should
  2965. (equal "\n* DONE h2\n* TODO h1\n* TODO h3\n"
  2966. (org-test-with-temp-text
  2967. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  2968. (org-sort-entries nil ?O)
  2969. (buffer-string))))
  2970. ;; Sort by priority.
  2971. (should
  2972. (equal "\n* [#A] h2\n* [#B] h3\n* [#C] h1\n"
  2973. (org-test-with-temp-text
  2974. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  2975. (org-sort-entries nil ?p)
  2976. (buffer-string))))
  2977. (should
  2978. (equal "\n* [#C] h1\n* [#B] h3\n* [#A] h2\n"
  2979. (org-test-with-temp-text
  2980. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  2981. (org-sort-entries nil ?P)
  2982. (buffer-string))))
  2983. ;; Sort by creation time.
  2984. (should
  2985. (equal "
  2986. * h3
  2987. [2017-05-08 Mon]
  2988. * h2
  2989. [2017-05-09 Tue]
  2990. * h1
  2991. [2018-05-09 Wed]
  2992. "
  2993. (org-test-with-temp-text
  2994. "
  2995. * h1
  2996. [2018-05-09 Wed]
  2997. * h2
  2998. [2017-05-09 Tue]
  2999. * h3
  3000. [2017-05-08 Mon]
  3001. "
  3002. (org-sort-entries nil ?c)
  3003. (buffer-string))))
  3004. ;; Sort by scheduled date.
  3005. (should
  3006. (equal "
  3007. * TODO h4
  3008. SCHEDULED: <2017-05-06 Sat>
  3009. * TODO h3
  3010. SCHEDULED: <2017-05-08 Mon>
  3011. * TODO h2
  3012. DEADLINE: <2017-05-09 Tue>
  3013. * TODO h1
  3014. DEADLINE: <2017-05-07 Sun>
  3015. "
  3016. (org-test-with-temp-text
  3017. "
  3018. * TODO h2
  3019. DEADLINE: <2017-05-09 Tue>
  3020. * TODO h1
  3021. DEADLINE: <2017-05-07 Sun>
  3022. * TODO h3
  3023. SCHEDULED: <2017-05-08 Mon>
  3024. * TODO h4
  3025. SCHEDULED: <2017-05-06 Sat>
  3026. "
  3027. (org-sort-entries nil ?s)
  3028. (buffer-string))))
  3029. ;; Sort by deadline date.
  3030. (should
  3031. (equal "
  3032. * TODO h1
  3033. DEADLINE: <2017-05-07 Sun>
  3034. * TODO h2
  3035. DEADLINE: <2017-05-09 Tue>
  3036. * TODO h3
  3037. SCHEDULED: <2017-05-08 Mon>
  3038. * TODO h4
  3039. SCHEDULED: <2017-05-06 Sat>
  3040. "
  3041. (org-test-with-temp-text
  3042. "
  3043. * TODO h2
  3044. DEADLINE: <2017-05-09 Tue>
  3045. * TODO h1
  3046. DEADLINE: <2017-05-07 Sun>
  3047. * TODO h3
  3048. SCHEDULED: <2017-05-08 Mon>
  3049. * TODO h4
  3050. SCHEDULED: <2017-05-06 Sat>
  3051. "
  3052. (org-sort-entries nil ?d)
  3053. (buffer-string))))
  3054. ;; Sort by any date/time
  3055. (should
  3056. (equal "
  3057. * TODO h4
  3058. SCHEDULED: <2017-05-06 Sat>
  3059. * TODO h1
  3060. DEADLINE: <2017-05-07 Sun>
  3061. * TODO h3
  3062. SCHEDULED: <2017-05-08 Mon>
  3063. * TODO h2
  3064. DEADLINE: <2017-05-09 Tue>
  3065. "
  3066. (org-test-with-temp-text
  3067. "
  3068. * TODO h2
  3069. DEADLINE: <2017-05-09 Tue>
  3070. * TODO h1
  3071. DEADLINE: <2017-05-07 Sun>
  3072. * TODO h3
  3073. SCHEDULED: <2017-05-08 Mon>
  3074. * TODO h4
  3075. SCHEDULED: <2017-05-06 Sat>
  3076. "
  3077. (org-sort-entries nil ?t)
  3078. (buffer-string))))
  3079. ;; Sort by clocking time.
  3080. (should
  3081. (equal "
  3082. * clocked h2
  3083. :LOGBOOK:
  3084. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3085. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  3086. :END:
  3087. * clocked h1
  3088. :LOGBOOK:
  3089. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3090. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  3091. :END:
  3092. "
  3093. (org-test-with-temp-text
  3094. "
  3095. * clocked h1
  3096. :LOGBOOK:
  3097. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3098. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  3099. :END:
  3100. * clocked h2
  3101. :LOGBOOK:
  3102. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3103. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  3104. :END:
  3105. "
  3106. (org-sort-entries nil ?k)
  3107. (buffer-string))))
  3108. ;; Preserve file local variables when sorting.
  3109. (should
  3110. (equal "\n* A\n* B\n# Local Variables:\n# foo: t\n# End:\n"
  3111. (org-test-with-temp-text
  3112. "\n* B\n* A\n# Local Variables:\n# foo: t\n# End:"
  3113. (org-sort-entries nil ?a)
  3114. (buffer-string)))))
  3115. (ert-deftest test-org/string-collate-greaterp ()
  3116. "Test `org-string-collate-greaterp' specifications."
  3117. (should (org-string-collate-greaterp "def" "abc"))
  3118. (should-not (org-string-collate-greaterp "abc" "def")))
  3119. (ert-deftest test-org/file-contents ()
  3120. "Test `org-file-contents' specifications."
  3121. ;; Open files.
  3122. (should
  3123. (string= "#+BIND: variable value
  3124. #+DESCRIPTION: l2
  3125. #+LANGUAGE: en
  3126. #+SELECT_TAGS: b
  3127. #+TITLE: b
  3128. #+PROPERTY: a 1
  3129. " (org-file-contents (expand-file-name "setupfile3.org"
  3130. (concat org-test-dir "examples/")))))
  3131. ;; Throw error when trying to access an invalid file.
  3132. (should-error (org-file-contents "this-file-must-not-exist"))
  3133. ;; Try to access an invalid file, but do not throw an error.
  3134. (should
  3135. (progn (org-file-contents "this-file-must-not-exist" :noerror) t))
  3136. ;; Open URL.
  3137. (should
  3138. (string= "foo"
  3139. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3140. (unwind-protect
  3141. ;; Simulate successful retrieval of a URL.
  3142. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3143. (lambda (&rest_)
  3144. (with-current-buffer buffer
  3145. (insert "HTTP/1.1 200 OK\n\nfoo"))
  3146. buffer)))
  3147. (org-file-contents "http://some-valid-url"))
  3148. (kill-buffer buffer)))))
  3149. ;; Throw error when trying to access an invalid URL.
  3150. (should-error
  3151. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3152. (unwind-protect
  3153. ;; Simulate unsuccessful retrieval of a URL.
  3154. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3155. (lambda (&rest_)
  3156. (with-current-buffer buffer
  3157. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3158. buffer)))
  3159. (org-file-contents "http://this-url-must-not-exist"))
  3160. (kill-buffer buffer))))
  3161. ;; Try to access an invalid URL, but do not throw an error.
  3162. (should-error
  3163. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3164. (unwind-protect
  3165. ;; Simulate unsuccessful retrieval of a URL.
  3166. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3167. (lambda (&rest_)
  3168. (with-current-buffer buffer
  3169. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3170. buffer)))
  3171. (org-file-contents "http://this-url-must-not-exist"))
  3172. (kill-buffer buffer))))
  3173. (should
  3174. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3175. (unwind-protect
  3176. ;; Simulate unsuccessful retrieval of a URL.
  3177. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3178. (lambda (&rest_)
  3179. (with-current-buffer buffer
  3180. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3181. buffer)))
  3182. (org-file-contents "http://this-url-must-not-exist" :noerror))
  3183. (kill-buffer buffer))
  3184. t)))
  3185. ;;; Navigation
  3186. (ert-deftest test-org/next-visible-heading ()
  3187. "Test `org-next-visible-heading' specifications."
  3188. ;; Move to the beginning of the next headline, taking into
  3189. ;; consideration ARG.
  3190. (should
  3191. (org-test-with-temp-text "* H1\n* H2"
  3192. (org-next-visible-heading 1)
  3193. (looking-at "\\* H2")))
  3194. (should
  3195. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3196. (org-next-visible-heading 2)
  3197. (looking-at "\\* H3")))
  3198. ;; Ignore invisible headlines.
  3199. (should
  3200. (org-test-with-temp-text "* H1\n** H2\n* H3"
  3201. (org-cycle)
  3202. (org-next-visible-heading 1)
  3203. (looking-at "\\* H3")))
  3204. ;; Move point between headlines, not on blank lines between.
  3205. (should
  3206. (org-test-with-temp-text "* H1\n** H2\n\n\n\n* H3"
  3207. (let ((org-cycle-separator-lines 1))
  3208. (org-cycle)
  3209. (org-next-visible-heading 1))
  3210. (looking-at "\\* H3")))
  3211. ;; Move at end of buffer when there is no more headline.
  3212. (should
  3213. (org-test-with-temp-text "* H1"
  3214. (org-next-visible-heading 1)
  3215. (eobp)))
  3216. (should
  3217. (org-test-with-temp-text "* H1\n* H2"
  3218. (org-next-visible-heading 2)
  3219. (eobp)))
  3220. ;; With a negative argument, move backwards.
  3221. (should
  3222. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3223. (org-next-visible-heading -1)
  3224. (looking-at "\\* H2")))
  3225. (should
  3226. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3227. (org-next-visible-heading -2)
  3228. (looking-at "\\* H1"))))
  3229. (ert-deftest test-org/previous-visible-heading ()
  3230. "Test `org-previous-visible-heading' specifications."
  3231. ;; Move to the beginning of the next headline, taking into
  3232. ;; consideration ARG.
  3233. (should
  3234. (org-test-with-temp-text "* H1\n<point>* H2"
  3235. (org-previous-visible-heading 1)
  3236. (looking-at "\\* H1")))
  3237. (should
  3238. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3239. (org-previous-visible-heading 2)
  3240. (looking-at "\\* H1")))
  3241. ;; Ignore invisible headlines.
  3242. (should
  3243. (org-test-with-temp-text "* H1\n** H2\n<point>* H3"
  3244. (org-overview)
  3245. (org-previous-visible-heading 1)
  3246. (looking-at "\\* H1")))
  3247. ;; Move point between headlines, not on blank lines between.
  3248. (should
  3249. (org-test-with-temp-text "* H1\n\n\n\n** H2\n<point>* H3"
  3250. (let ((org-cycle-separator-lines 1))
  3251. (org-overview)
  3252. (org-previous-visible-heading 1))
  3253. (looking-at "\\* H1")))
  3254. ;; Move at end of buffer when there is no more headline.
  3255. (should
  3256. (org-test-with-temp-text "* H1"
  3257. (org-previous-visible-heading 1)
  3258. (bobp)))
  3259. (should
  3260. (org-test-with-temp-text "* H1\n* <point>H2"
  3261. (org-previous-visible-heading 2)
  3262. (bobp)))
  3263. ;; Invisible parts may not start at a headline, i.e., when revealing
  3264. ;; parts of the buffer. Handle this.
  3265. (should
  3266. (org-test-with-temp-text "* Main\n** H1\nFoo\n** H2\nBar\n** H3\nBaz"
  3267. (org-overview)
  3268. (search-forward "H1")
  3269. (org-show-context 'minimal)
  3270. (org-cycle)
  3271. (search-forward "H3")
  3272. (org-show-context 'minimal)
  3273. ;; At this point, buffer displays, with point at "|",
  3274. ;;
  3275. ;; * Main
  3276. ;; ** H1
  3277. ;; Foo
  3278. ;; ** H3|
  3279. (org-previous-visible-heading 1)
  3280. (looking-at "\\*+ H1"))))
  3281. (ert-deftest test-org/forward-heading-same-level ()
  3282. "Test `org-forward-heading-same-level' specifications."
  3283. ;; Test navigation at top level, forward and backward.
  3284. (should
  3285. (equal "* H2"
  3286. (org-test-with-temp-text "* H1\n* H2"
  3287. (org-forward-heading-same-level 1)
  3288. (buffer-substring-no-properties (point) (line-end-position)))))
  3289. (should
  3290. (equal "* H1"
  3291. (org-test-with-temp-text "* H1\n<point>* H2"
  3292. (org-forward-heading-same-level -1)
  3293. (buffer-substring-no-properties (point) (line-end-position)))))
  3294. ;; Test navigation in a sub-tree, forward and backward.
  3295. (should
  3296. (equal "* H2"
  3297. (org-test-with-temp-text "* H1\n** H11\n** H12\n* H2"
  3298. (org-forward-heading-same-level 1)
  3299. (buffer-substring-no-properties (point) (line-end-position)))))
  3300. (should
  3301. (equal "* H1"
  3302. (org-test-with-temp-text "* H1\n** H11\n** H12\n<point>* H2"
  3303. (org-forward-heading-same-level -1)
  3304. (buffer-substring-no-properties (point) (line-end-position)))))
  3305. ;; Stop at first or last sub-heading.
  3306. (should-not
  3307. (equal "* H2"
  3308. (org-test-with-temp-text "* H1\n** H11\n<point>** H12\n* H2"
  3309. (org-forward-heading-same-level 1)
  3310. (buffer-substring-no-properties (point) (line-end-position)))))
  3311. (should-not
  3312. (equal "* H2"
  3313. (org-test-with-temp-text "* H1\n<point>** H11\n** H12\n* H2"
  3314. (org-forward-heading-same-level -1)
  3315. (buffer-substring-no-properties (point) (line-end-position)))))
  3316. ;; Allow multiple moves.
  3317. (should
  3318. (equal "* H3"
  3319. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3320. (org-forward-heading-same-level 2)
  3321. (buffer-substring-no-properties (point) (line-end-position)))))
  3322. (should
  3323. (equal "* H1"
  3324. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3325. (org-forward-heading-same-level -2)
  3326. (buffer-substring-no-properties (point) (line-end-position)))))
  3327. ;; Ignore spurious moves when first (or last) sibling is reached.
  3328. (should
  3329. (equal "** H3"
  3330. (org-test-with-temp-text "* First\n<point>** H1\n** H2\n** H3\n* Last"
  3331. (org-forward-heading-same-level 100)
  3332. (buffer-substring-no-properties (point) (line-end-position)))))
  3333. (should
  3334. (equal "** H1"
  3335. (org-test-with-temp-text "* First\n** H1\n** H2\n<point>** H3\n* Last"
  3336. (org-forward-heading-same-level -100)
  3337. (buffer-substring-no-properties (point) (line-end-position))))))
  3338. (ert-deftest test-org/end-of-meta-data ()
  3339. "Test `org-end-of-meta-data' specifications."
  3340. ;; Skip planning line.
  3341. (should
  3342. (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
  3343. (org-end-of-meta-data)
  3344. (eobp)))
  3345. ;; Skip properties drawer.
  3346. (should
  3347. (org-test-with-temp-text
  3348. "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
  3349. (org-end-of-meta-data)
  3350. (eobp)))
  3351. ;; Skip both.
  3352. (should
  3353. (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
  3354. (org-end-of-meta-data)
  3355. (eobp)))
  3356. ;; Nothing to skip, go to first line.
  3357. (should
  3358. (org-test-with-temp-text "* Headline\nContents"
  3359. (org-end-of-meta-data)
  3360. (looking-at "Contents")))
  3361. ;; With option argument, skip empty lines, regular drawers and
  3362. ;; clocking lines.
  3363. (should
  3364. (org-test-with-temp-text "* Headline\n\nContents"
  3365. (org-end-of-meta-data t)
  3366. (looking-at "Contents")))
  3367. (should
  3368. (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
  3369. (org-end-of-meta-data t)
  3370. (looking-at "Contents")))
  3371. (should
  3372. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
  3373. (org-end-of-meta-data t)
  3374. (looking-at "Contents")))
  3375. ;; Special case: do not skip incomplete drawers.
  3376. (should
  3377. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
  3378. (org-end-of-meta-data t)
  3379. (looking-at ":LOGBOOK:")))
  3380. ;; Special case: Be careful about consecutive headlines.
  3381. (should-not
  3382. (org-test-with-temp-text "* H1\n*H2\nContents"
  3383. (org-end-of-meta-data t)
  3384. (looking-at "Contents"))))
  3385. (ert-deftest test-org/shiftright-heading ()
  3386. "Test `org-shiftright' on headings."
  3387. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  3388. (should
  3389. (equal "* TODO a1\n** a2\n* DONE b1\n"
  3390. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3391. (org-shiftright)
  3392. (buffer-string))))
  3393. (should
  3394. (equal "* TODO a1\n** TODO a2\n* b1\n"
  3395. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3396. (let ((org-loop-over-headlines-in-active-region t))
  3397. (transient-mark-mode 1)
  3398. (push-mark (point) t t)
  3399. (search-forward "* DONE b1")
  3400. (org-shiftright))
  3401. (buffer-string))))
  3402. (should
  3403. (equal "* TODO a1\n** a2\n* b1\n"
  3404. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3405. (let ((org-loop-over-headlines-in-active-region 'start-level))
  3406. (transient-mark-mode 1)
  3407. (push-mark (point) t t)
  3408. (search-forward "* DONE b1")
  3409. (org-shiftright))
  3410. (buffer-string))))))
  3411. (ert-deftest test-org/beginning-of-line ()
  3412. "Test `org-beginning-of-line' specifications."
  3413. ;; Move to beginning of line. If current line in invisible, move to
  3414. ;; beginning of visible line instead.
  3415. (should
  3416. (org-test-with-temp-text "Some text\nSome other text<point>"
  3417. (org-beginning-of-line)
  3418. (bolp)))
  3419. (should
  3420. (org-test-with-temp-text "* H1\n** H2<point>"
  3421. (org-overview)
  3422. (org-beginning-of-line)
  3423. (= (line-beginning-position) 1)))
  3424. ;; With `visual-line-mode' active, move to beginning of visual line.
  3425. (should-not
  3426. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3427. (visual-line-mode)
  3428. (dotimes (i 1000) (insert "very "))
  3429. (org-beginning-of-line)
  3430. (bolp)))
  3431. ;; In a wide headline, with `visual-line-mode', prefer going to the
  3432. ;; beginning of a visual line than to the logical beginning of line,
  3433. ;; even if special movement is active.
  3434. (should-not
  3435. (org-test-with-temp-text "* A <point>long headline"
  3436. (visual-line-mode)
  3437. (dotimes (i 1000) (insert "very "))
  3438. (goto-char (point-max))
  3439. (org-beginning-of-line)
  3440. (bobp)))
  3441. (should-not
  3442. (org-test-with-temp-text "* A <point>long headline"
  3443. (visual-line-mode)
  3444. (dotimes (i 1000) (insert "very "))
  3445. (goto-char (point-max))
  3446. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line))
  3447. (bobp)))
  3448. ;; At an headline with special movement, first move at beginning of
  3449. ;; title, then at the beginning of line, rinse, repeat.
  3450. (should
  3451. (org-test-with-temp-text "* TODO Headline<point>"
  3452. (let ((org-special-ctrl-a/e t))
  3453. (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
  3454. (progn (org-beginning-of-line) (bolp))
  3455. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3456. (should
  3457. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3458. (let ((org-special-ctrl-a/e t))
  3459. (org-beginning-of-line)
  3460. (looking-at "Headline"))))
  3461. (should
  3462. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3463. (let ((org-special-ctrl-a/e '(t . nil)))
  3464. (org-beginning-of-line)
  3465. (looking-at "Headline"))))
  3466. (should-not
  3467. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3468. (let ((org-special-ctrl-a/e '(nil . nil)))
  3469. (org-beginning-of-line)
  3470. (looking-at "Headline"))))
  3471. ;; At an headline with reversed movement, first move to beginning of
  3472. ;; line, then to the beginning of title.
  3473. (should
  3474. (org-test-with-temp-text "* TODO Headline<point>"
  3475. (let ((org-special-ctrl-a/e 'reversed)
  3476. (this-command last-command))
  3477. (and (progn (org-beginning-of-line) (bolp))
  3478. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3479. (should
  3480. (org-test-with-temp-text "* TODO Headline<point>"
  3481. (let ((org-special-ctrl-a/e '(reversed . nil))
  3482. (this-command last-command))
  3483. (and (progn (org-beginning-of-line) (bolp))
  3484. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3485. (should-not
  3486. (org-test-with-temp-text "* TODO Headline<point>"
  3487. (let ((org-special-ctrl-a/e '(t . nil))
  3488. (this-command last-command))
  3489. (and (progn (org-beginning-of-line) (bolp))
  3490. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3491. ;; At an item with special movement, first move after to beginning
  3492. ;; of title, then to the beginning of line, rinse, repeat.
  3493. (should
  3494. (org-test-with-temp-text "- [ ] Item<point>"
  3495. (let ((org-special-ctrl-a/e t))
  3496. (and (progn (org-beginning-of-line) (looking-at-p "Item"))
  3497. (progn (org-beginning-of-line) (bolp))
  3498. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3499. ;; At an item with reversed movement, first move to beginning of
  3500. ;; line, then to the beginning of title.
  3501. (should
  3502. (org-test-with-temp-text "- [X] Item<point>"
  3503. (let ((org-special-ctrl-a/e 'reversed)
  3504. (this-command last-command))
  3505. (and (progn (org-beginning-of-line) (bolp))
  3506. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3507. ;; Leave point before invisible characters at column 0.
  3508. (should
  3509. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3510. (let ((org-special-ctrl-a/e nil))
  3511. (org-beginning-of-line)
  3512. (bolp))))
  3513. (should
  3514. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3515. (let ((org-special-ctrl-a/e t))
  3516. (org-beginning-of-line)
  3517. (bolp))))
  3518. (should
  3519. (org-test-with-temp-text "[[http<point>://orgmode.org]]"
  3520. (visual-line-mode)
  3521. (org-beginning-of-line)
  3522. (bolp)))
  3523. ;; Special case: Do not error when the buffer contains only a single
  3524. ;; asterisk.
  3525. (should
  3526. (org-test-with-temp-text "*<point>"
  3527. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line) t)))
  3528. (should
  3529. (org-test-with-temp-text "*<point>"
  3530. (let ((org-special-ctrl-a/e nil)) (org-beginning-of-line) t))))
  3531. (ert-deftest test-org/end-of-line ()
  3532. "Test `org-end-of-line' specifications."
  3533. ;; Standard test.
  3534. (should
  3535. (org-test-with-temp-text "Some text\nSome other text"
  3536. (org-end-of-line)
  3537. (eolp)))
  3538. ;; With `visual-line-mode' active, move to end of visible line.
  3539. ;; However, never go past ellipsis.
  3540. (should-not
  3541. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3542. (visual-line-mode)
  3543. (dotimes (i 1000) (insert "very "))
  3544. (goto-char (point-min))
  3545. (org-end-of-line)
  3546. (eolp)))
  3547. (should-not
  3548. (org-test-with-temp-text "* A short headline\nSome contents"
  3549. (visual-line-mode)
  3550. (org-overview)
  3551. (org-end-of-line)
  3552. (eobp)))
  3553. ;; In a wide headline, with `visual-line-mode', prefer going to end
  3554. ;; of visible line if tags, or end of line, are farther.
  3555. (should-not
  3556. (org-test-with-temp-text "* A <point>long headline"
  3557. (visual-line-mode)
  3558. (dotimes (i 1000) (insert "very "))
  3559. (goto-char (point-min))
  3560. (org-end-of-line)
  3561. (eolp)))
  3562. (should-not
  3563. (org-test-with-temp-text "* A <point>long headline :tag:"
  3564. (visual-line-mode)
  3565. (dotimes (i 1000) (insert "very "))
  3566. (goto-char (point-min))
  3567. (org-end-of-line)
  3568. (eolp)))
  3569. ;; At an headline without special movement, go to end of line.
  3570. ;; However, never go past ellipsis.
  3571. (should
  3572. (org-test-with-temp-text "* Headline2b :tag:\n"
  3573. (let ((org-special-ctrl-a/e nil))
  3574. (and (progn (org-end-of-line) (eolp))
  3575. (progn (org-end-of-line) (eolp))))))
  3576. (should
  3577. (org-test-with-temp-text "* Headline2b :tag:\n"
  3578. (let ((org-special-ctrl-a/e '(t . nil)))
  3579. (and (progn (org-end-of-line) (eolp))
  3580. (progn (org-end-of-line) (eolp))))))
  3581. (should
  3582. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3583. (org-overview)
  3584. (let ((org-special-ctrl-a/e nil))
  3585. (org-end-of-line)
  3586. (= 1 (line-beginning-position)))))
  3587. ;; At an headline with special movement, first move before tags,
  3588. ;; then at the end of line, rinse, repeat. However, never go past
  3589. ;; ellipsis.
  3590. (should
  3591. (org-test-with-temp-text "* Headline1 :tag:\n"
  3592. (let ((org-special-ctrl-a/e t))
  3593. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3594. (progn (org-end-of-line) (eolp))
  3595. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3596. (should
  3597. (org-test-with-temp-text "* Headline1 :tag:\n"
  3598. (let ((org-special-ctrl-a/e '(nil . t)))
  3599. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3600. (progn (org-end-of-line) (eolp))
  3601. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3602. (should-not
  3603. (org-test-with-temp-text "* Headline1 :tag:\n"
  3604. (let ((org-special-ctrl-a/e '(nil . nil)))
  3605. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3606. (progn (org-end-of-line) (eolp))
  3607. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3608. (should
  3609. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3610. (org-overview)
  3611. (let ((org-special-ctrl-a/e t))
  3612. (org-end-of-line)
  3613. (org-end-of-line)
  3614. (= 1 (line-beginning-position)))))
  3615. ;; At an headline, with reversed movement, first go to end of line,
  3616. ;; then before tags. However, never go past ellipsis.
  3617. (should
  3618. (org-test-with-temp-text "* Headline3 :tag:\n"
  3619. (let ((org-special-ctrl-a/e 'reversed)
  3620. (this-command last-command))
  3621. (and (progn (org-end-of-line) (eolp))
  3622. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3623. (should
  3624. (org-test-with-temp-text "* Headline3 :tag:\n"
  3625. (let ((org-special-ctrl-a/e '(nil . reversed))
  3626. (this-command last-command))
  3627. (and (progn (org-end-of-line) (eolp))
  3628. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3629. (should-not
  3630. (org-test-with-temp-text "* Headline3 :tag:\n"
  3631. (let ((org-special-ctrl-a/e '(nil . t))
  3632. (this-command last-command))
  3633. (and (progn (org-end-of-line) (eolp))
  3634. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3635. (should
  3636. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3637. (org-overview)
  3638. (let ((org-special-ctrl-a/e 'reversed))
  3639. (org-end-of-line)
  3640. (= 1 (line-beginning-position)))))
  3641. ;; At a block without hidden contents.
  3642. (should
  3643. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3644. (progn (org-end-of-line) (eolp))))
  3645. ;; At a block with hidden contents.
  3646. (should-not
  3647. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3648. (let ((org-special-ctrl-a/e t))
  3649. (org-hide-block-toggle)
  3650. (org-end-of-line)
  3651. (eobp))))
  3652. ;; Get past invisible characters at the end of line.
  3653. (should
  3654. (org-test-with-temp-text "[[https://orgmode.org]]"
  3655. (org-end-of-line)
  3656. (eolp))))
  3657. (ert-deftest test-org/open-line ()
  3658. "Test `org-open-line' specifications."
  3659. ;; Call `open-line' outside of tables.
  3660. (should
  3661. (equal "\nText"
  3662. (org-test-with-temp-text "Text"
  3663. (org-open-line 1)
  3664. (buffer-string))))
  3665. ;; At a table, create a row above.
  3666. (should
  3667. (equal "\n| |\n| a |"
  3668. (org-test-with-temp-text "\n<point>| a |"
  3669. (org-open-line 1)
  3670. (buffer-string))))
  3671. ;; At the very first character of the buffer, also call `open-line'.
  3672. (should
  3673. (equal "\n| a |"
  3674. (org-test-with-temp-text "| a |"
  3675. (org-open-line 1)
  3676. (buffer-string))))
  3677. ;; Narrowing does not count.
  3678. (should
  3679. (equal "Text\n| |\n| a |"
  3680. (org-test-with-temp-text "Text\n<point>| a |"
  3681. (narrow-to-region (point) (point-max))
  3682. (org-open-line 1)
  3683. (widen)
  3684. (buffer-string)))))
  3685. (ert-deftest test-org/forward-sentence ()
  3686. "Test `org-forward-sentence' specifications."
  3687. ;; At the end of a table cell, move to the end of the next one.
  3688. (should
  3689. (org-test-with-temp-text "| a<point> | b |"
  3690. (org-forward-sentence)
  3691. (looking-at " |$")))
  3692. ;; Elsewhere in a cell, move to its end.
  3693. (should
  3694. (org-test-with-temp-text "| a<point>c | b |"
  3695. (org-forward-sentence)
  3696. (looking-at " | b |$")))
  3697. ;; Otherwise, simply call `forward-sentence'.
  3698. (should
  3699. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3700. (org-forward-sentence)
  3701. (looking-at " Sentence 2.")))
  3702. (should
  3703. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3704. (org-forward-sentence)
  3705. (org-forward-sentence)
  3706. (eobp)))
  3707. ;; At the end of an element, jump to the next one, without stopping
  3708. ;; on blank lines in-between.
  3709. (should
  3710. (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
  3711. (org-forward-sentence)
  3712. (eobp)))
  3713. ;; Headlines are considered to be sentences by themselves, even if
  3714. ;; they do not end with a full stop.
  3715. (should
  3716. (equal
  3717. "* Headline"
  3718. (org-test-with-temp-text "* <point>Headline\nSentence."
  3719. (org-forward-sentence)
  3720. (buffer-substring-no-properties (line-beginning-position) (point)))))
  3721. (should
  3722. (org-test-with-temp-text "* Headline<point>\nSentence."
  3723. (org-forward-sentence)
  3724. (eobp)))
  3725. (should
  3726. (org-test-with-temp-text "Sentence.<point>\n\n* Headline\n\nSentence 2."
  3727. (org-forward-sentence)
  3728. (and (org-at-heading-p) (eolp)))))
  3729. (ert-deftest test-org/backward-sentence ()
  3730. "Test `org-backward-sentence' specifications."
  3731. ;; At the beginning of a table cell, move to the beginning of the
  3732. ;; previous one.
  3733. (should
  3734. (org-test-with-temp-text "| a | <point>b |"
  3735. (org-backward-sentence)
  3736. (looking-at "a | b |$")))
  3737. ;; Elsewhere in a cell, move to its beginning.
  3738. (should
  3739. (org-test-with-temp-text "| a | b<point>c |"
  3740. (org-backward-sentence)
  3741. (looking-at "bc |$")))
  3742. ;; Otherwise, simply call `backward-sentence'.
  3743. (should
  3744. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3745. (org-backward-sentence)
  3746. (looking-at "Sentence 2.")))
  3747. (should
  3748. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3749. (org-backward-sentence)
  3750. (org-backward-sentence)
  3751. (bobp)))
  3752. ;; Make sure to hit the beginning of a sentence on the same line as
  3753. ;; an item.
  3754. (should
  3755. (org-test-with-temp-text "- Line 1\n line <point>2."
  3756. (org-backward-sentence)
  3757. (looking-at "Line 1"))))
  3758. (ert-deftest test-org/forward-paragraph ()
  3759. "Test `org-forward-paragraph' specifications."
  3760. ;; At end of buffer, do not return an error.
  3761. (should
  3762. (org-test-with-temp-text "Paragraph"
  3763. (goto-char (point-max))
  3764. (org-forward-paragraph)
  3765. t))
  3766. ;; Standard test.
  3767. (should
  3768. (= 2
  3769. (org-test-with-temp-text "P1\n\nP2"
  3770. (org-forward-paragraph)
  3771. (org-current-line))))
  3772. (should
  3773. (= 2
  3774. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  3775. (org-forward-paragraph)
  3776. (org-current-line))))
  3777. ;; Enter greater elements.
  3778. (should
  3779. (= 2
  3780. (org-test-with-temp-text "#+begin_center\nP1\n#+end_center\nP2"
  3781. (org-forward-paragraph)
  3782. (org-current-line))))
  3783. ;; Do not enter elements with invisible contents.
  3784. (should
  3785. (= 4
  3786. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  3787. (org-cycle)
  3788. (org-forward-paragraph)
  3789. (org-current-line))))
  3790. (should
  3791. (= 6
  3792. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\nP3"
  3793. (org-hide-block-toggle)
  3794. (org-forward-paragraph)
  3795. (org-current-line))))
  3796. ;; On an item or a footnote definition, move past the first element
  3797. ;; inside, if any.
  3798. (should
  3799. (= 2
  3800. (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
  3801. (org-forward-paragraph)
  3802. (org-current-line))))
  3803. (should
  3804. (= 2
  3805. (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
  3806. (org-forward-paragraph)
  3807. (org-current-line))))
  3808. ;; On a table (resp. a property drawer) do not move through table
  3809. ;; rows (resp. node properties).
  3810. (should
  3811. (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
  3812. (org-forward-paragraph)
  3813. (looking-at "Paragraph")))
  3814. (should
  3815. (org-test-with-temp-text
  3816. "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
  3817. (org-forward-paragraph)
  3818. (looking-at "Paragraph")))
  3819. ;; Skip consecutive keywords, clocks and diary S-exps.
  3820. (should
  3821. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n"
  3822. (org-forward-paragraph)
  3823. (eobp)))
  3824. (should
  3825. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n"
  3826. (org-forward-paragraph)
  3827. (eobp)))
  3828. (should
  3829. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n"
  3830. (org-forward-paragraph)
  3831. (eobp)))
  3832. (should-not
  3833. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n"
  3834. (org-forward-paragraph)
  3835. (eobp)))
  3836. (should-not
  3837. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n"
  3838. (org-forward-paragraph)
  3839. (eobp)))
  3840. ;; In a plain list with one item every line, skip the whole list,
  3841. ;; even with point in the middle of the list.
  3842. (should
  3843. (org-test-with-temp-text "- A\n - B\n- C\n"
  3844. (org-forward-paragraph)
  3845. (eobp)))
  3846. (should
  3847. (org-test-with-temp-text "- A\n - <point>B\n- C\n"
  3848. (org-forward-paragraph)
  3849. (eobp)))
  3850. ;; On a comment, verse or source block, stop at "contents"
  3851. ;; boundaries and blank lines.
  3852. (should
  3853. (= 2
  3854. (org-test-with-temp-text "#+begin_src emacs-lisp\nL1\n\nL2\n#+end_src"
  3855. (org-forward-paragraph)
  3856. (org-current-line))))
  3857. (should
  3858. (= 3
  3859. (org-test-with-temp-text "#+begin_verse\n<point>L1\n\nL2\n#+end_verse"
  3860. (org-forward-paragraph)
  3861. (org-current-line))))
  3862. (should
  3863. (= 5
  3864. (org-test-with-temp-text "#+begin_comment\nL1\n\n<point>L2\n#+end_comment"
  3865. (org-forward-paragraph)
  3866. (org-current-line))))
  3867. ;; Being on an affiliated keyword shouldn't make any difference.
  3868. (should
  3869. (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
  3870. (org-forward-paragraph)
  3871. (eobp))))
  3872. (ert-deftest test-org/backward-paragraph ()
  3873. "Test `org-backward-paragraph' specifications."
  3874. ;; Do not error at beginning of buffer.
  3875. (should
  3876. (org-test-with-temp-text "Paragraph"
  3877. (org-backward-paragraph)
  3878. t))
  3879. ;; At blank lines at the very beginning of a buffer, move to
  3880. ;; point-min.
  3881. (should
  3882. (org-test-with-temp-text "\n\n<point>\n\nParagraph"
  3883. (org-backward-paragraph)
  3884. (bobp)))
  3885. ;; Regular test.
  3886. (should
  3887. (= 2
  3888. (org-test-with-temp-text "P1\n\nP2<point>"
  3889. (org-backward-paragraph)
  3890. (org-current-line))))
  3891. (should
  3892. (= 4
  3893. (org-test-with-temp-text "P1\n\nP2\n\nP3<point>"
  3894. (org-backward-paragraph)
  3895. (org-current-line))))
  3896. ;; Try to move on the line above current element.
  3897. (should
  3898. (= 2
  3899. (org-test-with-temp-text "\n\n<point>Paragraph"
  3900. (org-backward-paragraph)
  3901. (org-current-line))))
  3902. ;; Do not leave point in an invisible area.
  3903. (should
  3904. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  3905. (org-cycle)
  3906. (goto-char (point-max))
  3907. (beginning-of-line)
  3908. (org-backward-paragraph)
  3909. (bobp)))
  3910. (should
  3911. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\n"
  3912. (org-hide-block-toggle)
  3913. (goto-char (point-max))
  3914. (org-backward-paragraph)
  3915. (bobp)))
  3916. ;; On the first element in an item or a footnote definition, jump
  3917. ;; before the footnote or the item.
  3918. (should
  3919. (org-test-with-temp-text "- line1<point>"
  3920. (org-backward-paragraph)
  3921. (bobp)))
  3922. (should
  3923. (org-test-with-temp-text "[fn:1] line1n<point>"
  3924. (org-backward-paragraph)
  3925. (bobp)))
  3926. ;; On the second element in an item or a footnote definition, jump
  3927. ;; to item or the definition.
  3928. (should
  3929. (= 2
  3930. (org-test-with-temp-text "- line1\n\n<point> line2"
  3931. (org-backward-paragraph)
  3932. (org-current-line))))
  3933. (should
  3934. (= 2
  3935. (org-test-with-temp-text "[fn:1] line1\n\n<point> line2"
  3936. (org-backward-paragraph)
  3937. (org-current-line))))
  3938. ;; On a table (resp. a property drawer), ignore table rows
  3939. ;; (resp. node properties).
  3940. (should
  3941. (org-test-with-temp-text "| a | b |\n| c | d |\n<point>P1"
  3942. (org-backward-paragraph)
  3943. (bobp)))
  3944. (should
  3945. (= 2
  3946. (org-test-with-temp-text
  3947. "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
  3948. (org-backward-paragraph)
  3949. (org-current-line))))
  3950. ;; In a plain list with one item every line, skip the whole list,
  3951. ;; even with point in the middle of the list.
  3952. (should
  3953. (org-test-with-temp-text "- A\n - B\n- C\n<point>"
  3954. (org-backward-paragraph)
  3955. (bobp)))
  3956. (should
  3957. (org-test-with-temp-text "- A\n - B\n- <point>C\n"
  3958. (org-backward-paragraph)
  3959. (bobp)))
  3960. ;; Skip consecutive keywords, clocks and diary S-exps.
  3961. (should
  3962. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n<point>"
  3963. (org-backward-paragraph)
  3964. (bobp)))
  3965. (should
  3966. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n<point>"
  3967. (org-backward-paragraph)
  3968. (bobp)))
  3969. (should
  3970. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n<point>"
  3971. (org-backward-paragraph)
  3972. (bobp)))
  3973. (should-not
  3974. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n<point>"
  3975. (org-backward-paragraph)
  3976. (bobp)))
  3977. (should-not
  3978. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n<point>"
  3979. (org-backward-paragraph)
  3980. (bobp)))
  3981. ;; On a comment, example, source and verse blocks, stop at blank
  3982. ;; lines.
  3983. (should
  3984. (= 1
  3985. (org-test-with-temp-text
  3986. "#+begin_comment\n<point>L1\n\nL2\n\nL3\n#+end_comment"
  3987. (org-backward-paragraph)
  3988. (org-current-line))))
  3989. (should
  3990. (= 2
  3991. (org-test-with-temp-text
  3992. "#+begin_verse\nL1\n\n<point>L2\n\nL3\n#+end_verse"
  3993. (org-backward-paragraph)
  3994. (org-current-line))))
  3995. (should
  3996. (= 3
  3997. (org-test-with-temp-text
  3998. "#+begin_src emacs-lisp\nL1\n\nL2\n\n<point>L3\n#+end_src"
  3999. (org-backward-paragraph)
  4000. (org-current-line))))
  4001. ;; When called from the opening line itself, however, move to
  4002. ;; beginning of block.
  4003. (should
  4004. (org-test-with-temp-text "#+begin_<point>example\nL1\n#+end_example"
  4005. (org-backward-paragraph)
  4006. (bobp)))
  4007. ;; On an empty heading, move above it.
  4008. (should
  4009. (org-test-with-temp-text "\n* <point>"
  4010. (org-backward-paragraph)
  4011. (bobp)))
  4012. (should
  4013. (org-test-with-temp-text "\n* \n<point>"
  4014. (org-backward-paragraph)
  4015. (bobp))))
  4016. (ert-deftest test-org/forward-element ()
  4017. "Test `org-forward-element' specifications."
  4018. ;; 1. At EOB: should error.
  4019. (org-test-with-temp-text "Some text\n"
  4020. (goto-char (point-max))
  4021. (should-error (org-forward-element)))
  4022. ;; 2. Standard move: expected to ignore blank lines.
  4023. (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
  4024. (org-forward-element)
  4025. (should (looking-at (regexp-quote "Second paragraph."))))
  4026. ;; 3. Headline tests.
  4027. (org-test-with-temp-text "
  4028. * Head 1
  4029. ** Head 1.1
  4030. *** Head 1.1.1
  4031. ** Head 1.2"
  4032. ;; 3.1. At an headline beginning: move to next headline at the
  4033. ;; same level.
  4034. (goto-line 3)
  4035. (org-forward-element)
  4036. (should (looking-at (regexp-quote "** Head 1.2")))
  4037. ;; 3.2. At an headline beginning: move to parent headline if no
  4038. ;; headline at the same level.
  4039. (goto-line 3)
  4040. (org-forward-element)
  4041. (should (looking-at (regexp-quote "** Head 1.2"))))
  4042. ;; 4. Greater element tests.
  4043. (org-test-with-temp-text
  4044. "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
  4045. ;; 4.1. At a greater element: expected to skip contents.
  4046. (org-forward-element)
  4047. (should (looking-at (regexp-quote "Outside.")))
  4048. ;; 4.2. At the end of greater element contents: expected to skip
  4049. ;; to the end of the greater element.
  4050. (goto-line 2)
  4051. (org-forward-element)
  4052. (should (looking-at (regexp-quote "Outside."))))
  4053. ;; 5. List tests.
  4054. (org-test-with-temp-text "
  4055. - item1
  4056. - sub1
  4057. - sub2
  4058. - sub3
  4059. Inner paragraph.
  4060. - item2
  4061. Outside."
  4062. ;; 5.1. At list top point: expected to move to the element after
  4063. ;; the list.
  4064. (goto-line 2)
  4065. (org-forward-element)
  4066. (should (looking-at (regexp-quote "Outside.")))
  4067. ;; 5.2. Special case: at the first line of a sub-list, but not at
  4068. ;; beginning of line, move to next item.
  4069. (goto-line 2)
  4070. (forward-char)
  4071. (org-forward-element)
  4072. (should (looking-at "- item2"))
  4073. (goto-line 4)
  4074. (forward-char)
  4075. (org-forward-element)
  4076. (should (looking-at " - sub2"))
  4077. ;; 5.3 At sub-list beginning: expected to move after the sub-list.
  4078. (goto-line 4)
  4079. (org-forward-element)
  4080. (should (looking-at (regexp-quote " Inner paragraph.")))
  4081. ;; 5.4. At sub-list end: expected to move outside the sub-list.
  4082. (goto-line 8)
  4083. (org-forward-element)
  4084. (should (looking-at (regexp-quote " Inner paragraph.")))
  4085. ;; 5.5. At an item: expected to move to next item, if any.
  4086. (goto-line 6)
  4087. (org-forward-element)
  4088. (should (looking-at " - sub3"))))
  4089. (ert-deftest test-org/backward-element ()
  4090. "Test `org-backward-element' specifications."
  4091. ;; 1. Should error at BOB.
  4092. (org-test-with-temp-text " \nParagraph."
  4093. (should-error (org-backward-element)))
  4094. ;; 2. Should move at BOB when called on the first element in buffer.
  4095. (should
  4096. (org-test-with-temp-text "\n#+TITLE: test"
  4097. (progn (forward-line)
  4098. (org-backward-element)
  4099. (bobp))))
  4100. ;; 3. Not at the beginning of an element: move at its beginning.
  4101. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  4102. (goto-line 3)
  4103. (end-of-line)
  4104. (org-backward-element)
  4105. (should (looking-at (regexp-quote "Paragraph2."))))
  4106. ;; 4. Headline tests.
  4107. (org-test-with-temp-text "
  4108. * Head 1
  4109. ** Head 1.1
  4110. *** Head 1.1.1
  4111. ** Head 1.2"
  4112. ;; 4.1. At an headline beginning: move to previous headline at the
  4113. ;; same level.
  4114. (goto-line 5)
  4115. (org-backward-element)
  4116. (should (looking-at (regexp-quote "** Head 1.1")))
  4117. ;; 4.2. At an headline beginning: move to parent headline if no
  4118. ;; headline at the same level.
  4119. (goto-line 3)
  4120. (org-backward-element)
  4121. (should (looking-at (regexp-quote "* Head 1")))
  4122. ;; 4.3. At the first top-level headline: should error.
  4123. (goto-line 2)
  4124. (should-error (org-backward-element)))
  4125. ;; 5. At beginning of first element inside a greater element:
  4126. ;; expected to move to greater element's beginning.
  4127. (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
  4128. (goto-line 3)
  4129. (org-backward-element)
  4130. (should (looking-at "#\\+BEGIN_CENTER")))
  4131. ;; 6. At the beginning of the first element in a section: should
  4132. ;; move back to headline, if any.
  4133. (should
  4134. (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
  4135. (progn (goto-char (point-max))
  4136. (beginning-of-line)
  4137. (org-backward-element)
  4138. (org-at-heading-p))))
  4139. ;; 7. List tests.
  4140. (org-test-with-temp-text "
  4141. - item1
  4142. - sub1
  4143. - sub2
  4144. - sub3
  4145. Inner paragraph.
  4146. - item2
  4147. Outside."
  4148. ;; 7.1. At beginning of sub-list: expected to move to the
  4149. ;; paragraph before it.
  4150. (goto-line 4)
  4151. (org-backward-element)
  4152. (should (looking-at "item1"))
  4153. ;; 7.2. At an item in a list: expected to move at previous item.
  4154. (goto-line 8)
  4155. (org-backward-element)
  4156. (should (looking-at " - sub2"))
  4157. (goto-line 12)
  4158. (org-backward-element)
  4159. (should (looking-at "- item1"))
  4160. ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
  4161. ;; beginning.
  4162. (goto-line 10)
  4163. (org-backward-element)
  4164. (should (looking-at " - sub1"))
  4165. (goto-line 15)
  4166. (org-backward-element)
  4167. (should (looking-at "- item1"))
  4168. ;; 7.4. At blank-lines before list end: expected to move to top
  4169. ;; item.
  4170. (goto-line 14)
  4171. (org-backward-element)
  4172. (should (looking-at "- item1"))))
  4173. (ert-deftest test-org/up-element ()
  4174. "Test `org-up-element' specifications."
  4175. ;; 1. At BOB or with no surrounding element: should error.
  4176. (org-test-with-temp-text "Paragraph."
  4177. (should-error (org-up-element)))
  4178. (org-test-with-temp-text "* Head1\n* Head2"
  4179. (goto-line 2)
  4180. (should-error (org-up-element)))
  4181. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  4182. (goto-line 3)
  4183. (should-error (org-up-element)))
  4184. ;; 2. At an headline: move to parent headline.
  4185. (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
  4186. (goto-line 3)
  4187. (org-up-element)
  4188. (should (looking-at "\\* Head1")))
  4189. ;; 3. Inside a greater element: move to greater element beginning.
  4190. (org-test-with-temp-text
  4191. "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
  4192. (goto-line 3)
  4193. (org-up-element)
  4194. (should (looking-at "#\\+BEGIN_CENTER")))
  4195. ;; 4. List tests.
  4196. (org-test-with-temp-text "* Top
  4197. - item1
  4198. - sub1
  4199. - sub2
  4200. Paragraph within sub2.
  4201. - item2"
  4202. ;; 4.1. Within an item: move to the item beginning.
  4203. (goto-line 8)
  4204. (org-up-element)
  4205. (should (looking-at " - sub2"))
  4206. ;; 4.2. At an item in a sub-list: move to parent item.
  4207. (goto-line 4)
  4208. (org-up-element)
  4209. (should (looking-at "- item1"))
  4210. ;; 4.3. At an item in top list: move to beginning of whole list.
  4211. (goto-line 10)
  4212. (org-up-element)
  4213. (should (looking-at "- item1"))
  4214. ;; 4.4. Special case. At very top point: should move to parent of
  4215. ;; list.
  4216. (goto-line 2)
  4217. (org-up-element)
  4218. (should (looking-at "\\* Top"))))
  4219. (ert-deftest test-org/down-element ()
  4220. "Test `org-down-element' specifications."
  4221. ;; Error when the element hasn't got a recursive type.
  4222. (org-test-with-temp-text "Paragraph."
  4223. (should-error (org-down-element)))
  4224. ;; Error when the element has no contents
  4225. (org-test-with-temp-text "* Headline"
  4226. (should-error (org-down-element)))
  4227. ;; When at a plain-list, move to first item.
  4228. (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
  4229. (goto-line 2)
  4230. (org-down-element)
  4231. (should (looking-at " - Item 1.1")))
  4232. (org-test-with-temp-text "#+NAME: list\n- Item 1"
  4233. (org-down-element)
  4234. (should (looking-at " Item 1")))
  4235. ;; When at a table, move to first row
  4236. (org-test-with-temp-text "#+NAME: table\n| a | b |"
  4237. (org-down-element)
  4238. (should (looking-at " a | b |")))
  4239. ;; Otherwise, move inside the greater element.
  4240. (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
  4241. (org-down-element)
  4242. (should (looking-at "Paragraph"))))
  4243. (ert-deftest test-org/drag-element-backward ()
  4244. "Test `org-drag-element-backward' specifications."
  4245. ;; Standard test.
  4246. (should
  4247. (equal
  4248. "#+key2: val2\n#+key1: val1\n#+key3: val3"
  4249. (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
  4250. (org-drag-element-backward)
  4251. (buffer-string))))
  4252. (should
  4253. (equal
  4254. "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
  4255. (org-test-with-temp-text
  4256. "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
  4257. (org-drag-element-backward)
  4258. (buffer-string))))
  4259. ;; Preserve blank lines.
  4260. (should
  4261. (equal "Paragraph 2\n\n\nPara1\n\nPara3"
  4262. (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
  4263. (org-drag-element-backward)
  4264. (buffer-string))))
  4265. ;; Preserve column.
  4266. (should
  4267. (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
  4268. (org-drag-element-backward)
  4269. (looking-at-p "2")))
  4270. ;; Error when trying to move first element of buffer.
  4271. (should-error
  4272. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4273. (org-drag-element-backward))
  4274. :type 'user-error)
  4275. ;; Error when trying to swap nested elements.
  4276. (should-error
  4277. (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
  4278. (org-drag-element-backward))
  4279. :type 'user-error)
  4280. ;; Error when trying to swap an headline element and a non-headline
  4281. ;; element.
  4282. (should-error
  4283. (org-test-with-temp-text "Test.\n<point>* Head 1"
  4284. (org-drag-element-backward))
  4285. :type 'error)
  4286. ;; Error when called before first element.
  4287. (should-error
  4288. (org-test-with-temp-text "\n<point>"
  4289. (org-drag-element-backward))
  4290. :type 'user-error)
  4291. ;; Preserve visibility of elements and their contents.
  4292. (should
  4293. (equal '((63 . 82) (26 . 48))
  4294. (org-test-with-temp-text "
  4295. #+BEGIN_CENTER
  4296. Text.
  4297. #+END_CENTER
  4298. - item 1
  4299. #+BEGIN_QUOTE
  4300. Text.
  4301. #+END_QUOTE"
  4302. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4303. (search-backward "- item 1")
  4304. (org-drag-element-backward)
  4305. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4306. (overlays-in (point-min) (point-max))))))
  4307. ;; Pathological case: handle call with point in blank lines right
  4308. ;; after a headline.
  4309. (should
  4310. (equal "* H2\n\n* H1\nText\n"
  4311. (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
  4312. (org-drag-element-backward)
  4313. (buffer-string)))))
  4314. (ert-deftest test-org/drag-element-forward ()
  4315. "Test `org-drag-element-forward' specifications."
  4316. ;; 1. Error when trying to move first element of buffer.
  4317. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4318. (goto-line 3)
  4319. (should-error (org-drag-element-forward)))
  4320. ;; 2. Error when trying to swap nested elements.
  4321. (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
  4322. (forward-line)
  4323. (should-error (org-drag-element-forward)))
  4324. ;; 3. Error when trying to swap a non-headline element and an
  4325. ;; headline.
  4326. (org-test-with-temp-text "Test.\n* Head 1"
  4327. (should-error (org-drag-element-forward)))
  4328. ;; 4. Error when called before first element.
  4329. (should-error
  4330. (org-test-with-temp-text "\n"
  4331. (forward-line)
  4332. (org-drag-element-backward))
  4333. :type 'user-error)
  4334. ;; 5. Otherwise, swap elements, preserving column and blank lines
  4335. ;; between elements.
  4336. (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
  4337. (search-forward "graph")
  4338. (org-drag-element-forward)
  4339. (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
  4340. (should (looking-at " 1")))
  4341. ;; 5. Preserve visibility of elements and their contents.
  4342. (org-test-with-temp-text "
  4343. #+BEGIN_CENTER
  4344. Text.
  4345. #+END_CENTER
  4346. - item 1
  4347. #+BEGIN_QUOTE
  4348. Text.
  4349. #+END_QUOTE"
  4350. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4351. (search-backward "#+BEGIN_CENTER")
  4352. (org-drag-element-forward)
  4353. (should
  4354. (equal
  4355. '((63 . 82) (26 . 48))
  4356. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4357. (overlays-in (point-min) (point-max)))))))
  4358. (ert-deftest test-org/next-block ()
  4359. "Test `org-next-block' specifications."
  4360. ;; Regular test.
  4361. (should
  4362. (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  4363. (org-next-block 1)
  4364. (looking-at "#\\+BEGIN_CENTER")))
  4365. ;; Ignore case.
  4366. (should
  4367. (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
  4368. (let ((case-fold-search nil))
  4369. (org-next-block 1)
  4370. (looking-at "#\\+begin_center"))))
  4371. ;; Ignore current line.
  4372. (should
  4373. (org-test-with-temp-text
  4374. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
  4375. (org-next-block 1)
  4376. (looking-at "#\\+BEGIN_CENTER")))
  4377. ;; Throw an error when no block is found.
  4378. (should-error
  4379. (org-test-with-temp-text "Paragraph"
  4380. (org-next-block 1)))
  4381. ;; With an argument, skip many blocks at once.
  4382. (should
  4383. (org-test-with-temp-text
  4384. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4385. (org-next-block 2)
  4386. (looking-at "#\\+BEGIN_QUOTE")))
  4387. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4388. (should
  4389. (org-test-with-temp-text
  4390. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4391. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4392. (looking-at "#\\+BEGIN_QUOTE")))
  4393. ;; Optional argument is also case-insensitive.
  4394. (should
  4395. (org-test-with-temp-text
  4396. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
  4397. (let ((case-fold-search nil))
  4398. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4399. (looking-at "#\\+begin_quote")))))
  4400. (ert-deftest test-org/insert-structure-template ()
  4401. "Test `org-insert-structure-template'."
  4402. ;; Test in empty buffer.
  4403. (should
  4404. (string= "#+begin_foo\n#+end_foo\n"
  4405. (org-test-with-temp-text ""
  4406. (org-insert-structure-template "foo")
  4407. (buffer-string))))
  4408. ;; Test with multiple lines in buffer.
  4409. (should
  4410. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4411. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4412. (transient-mark-mode 1)
  4413. (org-mark-element)
  4414. (org-insert-structure-template "foo")
  4415. (buffer-string))))
  4416. ;; Mark only the current line.
  4417. (should
  4418. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4419. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4420. (transient-mark-mode 1)
  4421. (set-mark (point-min))
  4422. (end-of-line)
  4423. (org-insert-structure-template "foo")
  4424. (buffer-string))))
  4425. ;; Middle of paragraph.
  4426. (should
  4427. (string= "p1\n#+begin_foo\np2\n#+end_foo\np3"
  4428. (org-test-with-temp-text "p1\n<point>p2\np3"
  4429. (set-mark (line-beginning-position))
  4430. (end-of-line)
  4431. (activate-mark)
  4432. (org-insert-structure-template "foo")
  4433. (buffer-string))))
  4434. ;; Test with text in buffer, no region, no final newline.
  4435. (should
  4436. (string= "#+begin_foo\nI'm a paragraph.\n#+end_foo\n"
  4437. (org-test-with-temp-text "I'm a paragraph."
  4438. (org-mark-element)
  4439. (org-insert-structure-template "foo")
  4440. (buffer-string))))
  4441. ;; Test with text in buffer and region set.
  4442. (should
  4443. (string= "#+begin_foo\nI'm a paragraph\n\nI'm a second paragrah\n#+end_foo\n"
  4444. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragrah"
  4445. (set-mark (point))
  4446. (goto-char (point-max))
  4447. (org-insert-structure-template "foo")
  4448. (buffer-string))))
  4449. ;; Test with example escaping.
  4450. (should
  4451. (string= "#+begin_example\n,* Heading\n#+end_example\n"
  4452. (org-test-with-temp-text "* Heading"
  4453. (org-mark-element)
  4454. (org-insert-structure-template "example")
  4455. (buffer-string))))
  4456. ;; Test with indentation.
  4457. (should
  4458. (string= " #+begin_foo\n This is a paragraph\n #+end_foo\n"
  4459. (org-test-with-temp-text " This is a paragraph"
  4460. (org-mark-element)
  4461. (org-insert-structure-template "foo")
  4462. (buffer-string))))
  4463. (should
  4464. (string= " #+begin_foo\n Line 1\n Line2\n #+end_foo\n"
  4465. (org-test-with-temp-text " Line 1\n Line2"
  4466. (org-mark-element)
  4467. (org-insert-structure-template "foo")
  4468. (buffer-string))))
  4469. ;; Test point location.
  4470. (should
  4471. (string= "#+begin_foo\n"
  4472. (org-test-with-temp-text ""
  4473. (org-insert-structure-template "foo")
  4474. (buffer-substring (point-min) (point)))))
  4475. (should
  4476. (string= "#+begin_src "
  4477. (org-test-with-temp-text ""
  4478. (org-insert-structure-template "src")
  4479. (buffer-substring (point-min) (point))))))
  4480. (ert-deftest test-org/previous-block ()
  4481. "Test `org-previous-block' specifications."
  4482. ;; Regular test.
  4483. (should
  4484. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
  4485. (org-previous-block 1)
  4486. (looking-at "#\\+BEGIN_CENTER")))
  4487. ;; Ignore case.
  4488. (should
  4489. (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
  4490. (let ((case-fold-search nil))
  4491. (org-previous-block 1)
  4492. (looking-at "#\\+begin_center"))))
  4493. ;; Ignore current line.
  4494. (should
  4495. (org-test-with-temp-text
  4496. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
  4497. (org-previous-block 1)
  4498. (looking-at "#\\+BEGIN_QUOTE")))
  4499. ;; Throw an error when no block is found.
  4500. (should-error
  4501. (org-test-with-temp-text "Paragraph<point>"
  4502. (org-previous-block 1)))
  4503. ;; With an argument, skip many blocks at once.
  4504. (should
  4505. (org-test-with-temp-text
  4506. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4507. (org-previous-block 2)
  4508. (looking-at "#\\+BEGIN_CENTER")))
  4509. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4510. (should
  4511. (org-test-with-temp-text
  4512. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4513. (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4514. (looking-at "#\\+BEGIN_QUOTE")))
  4515. ;; Optional argument is also case-insensitive.
  4516. (should
  4517. (org-test-with-temp-text
  4518. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
  4519. (let ((case-fold-search nil))
  4520. (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4521. (looking-at "#\\+begin_quote")))))
  4522. ;;; Outline structure
  4523. (ert-deftest test-org/demote ()
  4524. "Test `org-demote' specifications."
  4525. ;; Add correct number of stars according to `org-odd-levels-only'.
  4526. (should
  4527. (= 2
  4528. (org-test-with-temp-text "* H"
  4529. (let ((org-odd-levels-only nil)) (org-demote))
  4530. (org-current-level))))
  4531. (should
  4532. (= 3
  4533. (org-test-with-temp-text "* H"
  4534. (let ((org-odd-levels-only t)) (org-demote))
  4535. (org-current-level))))
  4536. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4537. (should
  4538. (org-test-with-temp-text "* H :tag:"
  4539. (let ((org-tags-column 10)
  4540. (org-auto-align-tags t)
  4541. (org-odd-levels-only nil))
  4542. (org-demote))
  4543. (org-move-to-column 10)
  4544. (looking-at-p ":tag:$")))
  4545. (should-not
  4546. (org-test-with-temp-text "* H :tag:"
  4547. (let ((org-tags-column 10)
  4548. (org-auto-align-tags nil)
  4549. (org-odd-levels-only nil))
  4550. (org-demote))
  4551. (org-move-to-column 10)
  4552. (looking-at-p ":tag:$")))
  4553. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4554. ;; info and property drawers accordingly.
  4555. (should
  4556. (= 3
  4557. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4558. (let ((org-odd-levels-only nil)
  4559. (org-adapt-indentation t))
  4560. (org-demote))
  4561. (forward-line)
  4562. (org-get-indentation))))
  4563. (should
  4564. (= 3
  4565. (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4566. (let ((org-odd-levels-only nil)
  4567. (org-adapt-indentation t))
  4568. (org-demote))
  4569. (forward-line)
  4570. (org-get-indentation))))
  4571. (should-not
  4572. (= 3
  4573. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4574. (let ((org-odd-levels-only nil)
  4575. (org-adapt-indentation nil))
  4576. (org-demote))
  4577. (forward-line)
  4578. (org-get-indentation))))
  4579. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4580. ;; section accordingly. Ignore, however, footnote definitions and
  4581. ;; inlinetasks boundaries.
  4582. (should
  4583. (= 3
  4584. (org-test-with-temp-text "* H\n Paragraph"
  4585. (let ((org-odd-levels-only nil)
  4586. (org-adapt-indentation t))
  4587. (org-demote))
  4588. (forward-line)
  4589. (org-get-indentation))))
  4590. (should
  4591. (= 2
  4592. (org-test-with-temp-text "* H\n Paragraph"
  4593. (let ((org-odd-levels-only nil)
  4594. (org-adapt-indentation nil))
  4595. (org-demote))
  4596. (forward-line)
  4597. (org-get-indentation))))
  4598. (should
  4599. (zerop
  4600. (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
  4601. (let ((org-odd-levels-only nil)
  4602. (org-adapt-indentation t))
  4603. (org-demote))
  4604. (goto-char (point-max))
  4605. (org-get-indentation))))
  4606. (should
  4607. (= 3
  4608. (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
  4609. (let ((org-odd-levels-only nil)
  4610. (org-adapt-indentation t))
  4611. (org-demote))
  4612. (goto-char (point-max))
  4613. (org-get-indentation))))
  4614. (when (featurep 'org-inlinetask)
  4615. (should
  4616. (zerop
  4617. (let ((org-inlinetask-min-level 5)
  4618. (org-adapt-indentation t))
  4619. (org-test-with-temp-text "* H\n***** I\n***** END"
  4620. (org-demote)
  4621. (forward-line)
  4622. (org-get-indentation))))))
  4623. (when (featurep 'org-inlinetask)
  4624. (should
  4625. (= 3
  4626. (let ((org-inlinetask-min-level 5)
  4627. (org-adapt-indentation t))
  4628. (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
  4629. (org-demote)
  4630. (forward-line 2)
  4631. (org-get-indentation))))))
  4632. ;; When `org-adapt-indentation' is non-nil, log drawers are
  4633. ;; adjusted.
  4634. (should
  4635. (equal
  4636. "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4637. (org-test-with-temp-text "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4638. (let ((org-odd-levels-only nil)
  4639. (org-adapt-indentation t))
  4640. (org-demote))
  4641. (buffer-string))))
  4642. (should
  4643. (equal
  4644. "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4645. (org-test-with-temp-text "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4646. (let ((org-odd-levels-only nil)
  4647. (org-adapt-indentation 'headline-data))
  4648. (org-demote))
  4649. (buffer-string))))
  4650. (should
  4651. (equal
  4652. "** H\n :LOGBOOK:\n - a\n :END:"
  4653. (org-test-with-temp-text "* H\n:LOGBOOK:\n- a\n:END:"
  4654. (let ((org-odd-levels-only nil)
  4655. (org-adapt-indentation t))
  4656. (org-demote))
  4657. (buffer-string))))
  4658. ;; Ignore contents of source blocks or example blocks when
  4659. ;; indentation should be preserved (through
  4660. ;; `org-src-preserve-indentation' or "-i" flag).
  4661. (should-not
  4662. (zerop
  4663. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4664. (let ((org-adapt-indentation t)
  4665. (org-src-preserve-indentation nil))
  4666. (org-demote))
  4667. (forward-line 2)
  4668. (org-get-indentation))))
  4669. (should
  4670. (zerop
  4671. (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
  4672. (let ((org-adapt-indentation t)
  4673. (org-src-preserve-indentation t))
  4674. (org-demote))
  4675. (forward-line 2)
  4676. (org-get-indentation))))
  4677. (should
  4678. (zerop
  4679. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4680. (let ((org-adapt-indentation t)
  4681. (org-src-preserve-indentation t))
  4682. (org-demote))
  4683. (forward-line 2)
  4684. (org-get-indentation))))
  4685. (should
  4686. (zerop
  4687. (org-test-with-temp-text
  4688. "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
  4689. (let ((org-adapt-indentation t)
  4690. (org-src-preserve-indentation nil))
  4691. (org-demote))
  4692. (forward-line 2)
  4693. (org-get-indentation)))))
  4694. (ert-deftest test-org/promote ()
  4695. "Test `org-promote' specifications."
  4696. ;; Return an error if headline is to be promoted to level 0, unless
  4697. ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
  4698. ;; headline becomes a comment.
  4699. (should-error
  4700. (org-test-with-temp-text "* H"
  4701. (let ((org-allow-promoting-top-level-subtree nil)) (org-promote))))
  4702. (should
  4703. (equal "# H"
  4704. (org-test-with-temp-text "* H"
  4705. (let ((org-allow-promoting-top-level-subtree t)) (org-promote))
  4706. (buffer-string))))
  4707. ;; Remove correct number of stars according to
  4708. ;; `org-odd-levels-only'.
  4709. (should
  4710. (= 2
  4711. (org-test-with-temp-text "*** H"
  4712. (let ((org-odd-levels-only nil)) (org-promote))
  4713. (org-current-level))))
  4714. (should
  4715. (= 1
  4716. (org-test-with-temp-text "*** H"
  4717. (let ((org-odd-levels-only t)) (org-promote))
  4718. (org-current-level))))
  4719. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4720. (should
  4721. (org-test-with-temp-text "** H :tag:"
  4722. (let ((org-tags-column 10)
  4723. (org-auto-align-tags t)
  4724. (org-odd-levels-only nil))
  4725. (org-promote))
  4726. (org-move-to-column 10)
  4727. (looking-at-p ":tag:$")))
  4728. (should-not
  4729. (org-test-with-temp-text "** H :tag:"
  4730. (let ((org-tags-column 10)
  4731. (org-auto-align-tags nil)
  4732. (org-odd-levels-only nil))
  4733. (org-promote))
  4734. (org-move-to-column 10)
  4735. (looking-at-p ":tag:$")))
  4736. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4737. ;; info and property drawers.
  4738. (should
  4739. (= 2
  4740. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4741. (let ((org-odd-levels-only nil)
  4742. (org-adapt-indentation t))
  4743. (org-promote))
  4744. (forward-line)
  4745. (org-get-indentation))))
  4746. (should
  4747. (= 2
  4748. (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4749. (let ((org-odd-levels-only nil)
  4750. (org-adapt-indentation t))
  4751. (org-promote))
  4752. (forward-line)
  4753. (org-get-indentation))))
  4754. (should-not
  4755. (= 2
  4756. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4757. (let ((org-odd-levels-only nil)
  4758. (org-adapt-indentation nil))
  4759. (org-promote))
  4760. (forward-line)
  4761. (org-get-indentation))))
  4762. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4763. ;; section accordingly. Ignore, however, footnote definitions and
  4764. ;; inlinetasks boundaries.
  4765. (should
  4766. (= 2
  4767. (org-test-with-temp-text "** H\n Paragraph"
  4768. (let ((org-odd-levels-only nil)
  4769. (org-adapt-indentation t))
  4770. (org-promote))
  4771. (forward-line)
  4772. (org-get-indentation))))
  4773. (should-not
  4774. (= 2
  4775. (org-test-with-temp-text "** H\n Paragraph"
  4776. (let ((org-odd-levels-only nil)
  4777. (org-adapt-indentation nil))
  4778. (org-promote))
  4779. (forward-line)
  4780. (org-get-indentation))))
  4781. (should
  4782. (= 2
  4783. (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
  4784. (let ((org-odd-levels-only nil)
  4785. (org-adapt-indentation t))
  4786. (org-promote))
  4787. (forward-line)
  4788. (org-get-indentation))))
  4789. (when (featurep 'org-inlinetask)
  4790. (should
  4791. (zerop
  4792. (let ((org-inlinetask-min-level 5)
  4793. (org-adapt-indentation t))
  4794. (org-test-with-temp-text "** H\n***** I\n***** END"
  4795. (org-promote)
  4796. (forward-line)
  4797. (org-get-indentation))))))
  4798. (when (featurep 'org-inlinetask)
  4799. (should
  4800. (= 2
  4801. (let ((org-inlinetask-min-level 5)
  4802. (org-adapt-indentation t))
  4803. (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
  4804. (org-promote)
  4805. (forward-line 2)
  4806. (org-get-indentation))))))
  4807. ;; Give up shifting if it would break document's structure
  4808. ;; otherwise.
  4809. (should
  4810. (= 3
  4811. (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
  4812. (let ((org-odd-levels-only nil)
  4813. (org-adapt-indentation t))
  4814. (org-promote))
  4815. (forward-line)
  4816. (org-get-indentation))))
  4817. (should
  4818. (= 3
  4819. (org-test-with-temp-text "** H\n Paragraph\n * list."
  4820. (let ((org-odd-levels-only nil)
  4821. (org-adapt-indentation t))
  4822. (org-promote))
  4823. (forward-line)
  4824. (org-get-indentation))))
  4825. ;; When `org-adapt-indentation' is non-nil, log drawers are
  4826. ;; adjusted.
  4827. (should
  4828. (equal
  4829. "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4830. (org-test-with-temp-text "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4831. (let ((org-odd-levels-only nil)
  4832. (org-adapt-indentation t))
  4833. (org-promote))
  4834. (buffer-string))))
  4835. (should
  4836. (equal
  4837. "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4838. (org-test-with-temp-text "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4839. (let ((org-odd-levels-only nil)
  4840. (org-adapt-indentation 'headline-data))
  4841. (org-promote))
  4842. (buffer-string))))
  4843. (should
  4844. (equal
  4845. "* H\n:LOGBOOK:\n- a\n:END:"
  4846. (org-test-with-temp-text "** H\n:LOGBOOK:\n- a\n:END:"
  4847. (let ((org-odd-levels-only nil)
  4848. (org-adapt-indentation t))
  4849. (org-promote))
  4850. (buffer-string))))
  4851. (should
  4852. (equal
  4853. "# H\n:LOGBOOK:\n- a\n:END:"
  4854. (org-test-with-temp-text "* H\n:LOGBOOK:\n- a\n:END:"
  4855. (let ((org-odd-levels-only nil)
  4856. (org-allow-promoting-top-level-subtree t)
  4857. (org-adapt-indentation t))
  4858. (org-promote))
  4859. (buffer-string))))
  4860. ;; Ignore contents of source blocks or example blocks when
  4861. ;; indentation should be preserved (through
  4862. ;; `org-src-preserve-indentation' or "-i" flag).
  4863. (should-not
  4864. (zerop
  4865. (org-test-with-temp-text
  4866. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  4867. (let ((org-adapt-indentation t)
  4868. (org-src-preserve-indentation nil)
  4869. (org-odd-levels-only nil))
  4870. (org-promote))
  4871. (forward-line)
  4872. (org-get-indentation))))
  4873. (should
  4874. (zerop
  4875. (org-test-with-temp-text
  4876. "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
  4877. (let ((org-adapt-indentation t)
  4878. (org-src-preserve-indentation t)
  4879. (org-odd-levels-only nil))
  4880. (org-promote))
  4881. (forward-line)
  4882. (org-get-indentation))))
  4883. (should
  4884. (zerop
  4885. (org-test-with-temp-text
  4886. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  4887. (let ((org-adapt-indentation t)
  4888. (org-src-preserve-indentation t)
  4889. (org-odd-levels-only nil))
  4890. (org-promote))
  4891. (forward-line)
  4892. (org-get-indentation))))
  4893. (should
  4894. (zerop
  4895. (org-test-with-temp-text
  4896. "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
  4897. (let ((org-adapt-indentation t)
  4898. (org-src-preserve-indentation nil)
  4899. (org-odd-levels-only nil))
  4900. (org-promote))
  4901. (forward-line)
  4902. (org-get-indentation)))))
  4903. (ert-deftest test-org/org-get-valid-level ()
  4904. "Test function `org-get-valid-level' specifications."
  4905. (let ((org-odd-levels-only nil))
  4906. (should (equal 1 (org-get-valid-level 0 0)))
  4907. (should (equal 1 (org-get-valid-level 0 1)))
  4908. (should (equal 2 (org-get-valid-level 0 2)))
  4909. (should (equal 3 (org-get-valid-level 0 3)))
  4910. (should (equal 1 (org-get-valid-level 1 0)))
  4911. (should (equal 2 (org-get-valid-level 1 1)))
  4912. (should (equal 23 (org-get-valid-level 1 22)))
  4913. (should (equal 1 (org-get-valid-level 1 -1)))
  4914. (should (equal 1 (org-get-valid-level 2 -1))))
  4915. (let ((org-odd-levels-only t))
  4916. (should (equal 1 (org-get-valid-level 0 0)))
  4917. (should (equal 1 (org-get-valid-level 0 1)))
  4918. (should (equal 3 (org-get-valid-level 0 2)))
  4919. (should (equal 5 (org-get-valid-level 0 3)))
  4920. (should (equal 1 (org-get-valid-level 1 0)))
  4921. (should (equal 3 (org-get-valid-level 1 1)))
  4922. (should (equal 3 (org-get-valid-level 2 1)))
  4923. (should (equal 5 (org-get-valid-level 3 1)))
  4924. (should (equal 5 (org-get-valid-level 4 1)))
  4925. (should (equal 43 (org-get-valid-level 1 21)))
  4926. (should (equal 1 (org-get-valid-level 1 -1)))
  4927. (should (equal 1 (org-get-valid-level 2 -1)))
  4928. (should (equal 1 (org-get-valid-level 3 -1)))
  4929. (should (equal 3 (org-get-valid-level 4 -1)))
  4930. (should (equal 3 (org-get-valid-level 5 -1)))))
  4931. ;;; Planning
  4932. (ert-deftest test-org/at-planning-p ()
  4933. "Test `org-at-planning-p' specifications."
  4934. ;; Regular test.
  4935. (should
  4936. (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
  4937. (org-at-planning-p)))
  4938. (should-not
  4939. (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
  4940. (org-at-planning-p)))
  4941. ;; Correctly find planning attached to inlinetasks.
  4942. (when (featurep 'org-inlinetask)
  4943. (should
  4944. (org-test-with-temp-text
  4945. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
  4946. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4947. (should-not
  4948. (org-test-with-temp-text
  4949. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  4950. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4951. (should-not
  4952. (org-test-with-temp-text
  4953. "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  4954. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4955. (should-not
  4956. (org-test-with-temp-text
  4957. "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
  4958. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
  4959. (ert-deftest test-org/add-planning-info ()
  4960. "Test `org-add-planning-info'."
  4961. ;; Create deadline when `org-adapt-indentation' is non-nil.
  4962. (should
  4963. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4964. (org-test-with-temp-text "* H\nParagraph<point>"
  4965. (let ((org-adapt-indentation t))
  4966. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4967. (replace-regexp-in-string
  4968. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4969. nil nil 1))))
  4970. ;; Create deadline when `org-adapt-indentation' is nil.
  4971. (should
  4972. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  4973. (org-test-with-temp-text "* H\nParagraph<point>"
  4974. (let ((org-adapt-indentation nil))
  4975. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4976. (replace-regexp-in-string
  4977. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4978. nil nil 1))))
  4979. ;; Update deadline when `org-adapt-indentation' is non-nil.
  4980. (should
  4981. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4982. (org-test-with-temp-text "\
  4983. * H
  4984. DEADLINE: <2015-06-24 Wed>
  4985. Paragraph<point>"
  4986. (let ((org-adapt-indentation t))
  4987. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4988. (replace-regexp-in-string
  4989. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4990. nil nil 1))))
  4991. ;; Update deadline when `org-adapt-indentation' is nil.
  4992. (should
  4993. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  4994. (org-test-with-temp-text "\
  4995. * H
  4996. DEADLINE: <2015-06-24 Wed>
  4997. Paragraph<point>"
  4998. (let ((org-adapt-indentation nil))
  4999. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5000. (replace-regexp-in-string
  5001. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5002. nil nil 1))))
  5003. ;; Schedule when `org-adapt-indentation' is non-nil.
  5004. (should
  5005. (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
  5006. (org-test-with-temp-text "* H\nParagraph<point>"
  5007. (let ((org-adapt-indentation t))
  5008. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  5009. (replace-regexp-in-string
  5010. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5011. nil nil 1))))
  5012. ;; Schedule when `org-adapt-indentation' is nil.
  5013. (should
  5014. (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
  5015. (org-test-with-temp-text "* H\nParagraph<point>"
  5016. (let ((org-adapt-indentation nil))
  5017. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  5018. (replace-regexp-in-string
  5019. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5020. nil nil 1))))
  5021. ;; Add deadline when scheduled.
  5022. (should
  5023. (equal "\
  5024. * H
  5025. DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
  5026. Paragraph"
  5027. (org-test-with-temp-text "\
  5028. * H
  5029. SCHEDULED: <2015-06-24 Wed>
  5030. Paragraph<point>"
  5031. (let ((org-adapt-indentation t))
  5032. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5033. (replace-regexp-in-string
  5034. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5035. nil nil 1))))
  5036. ;; Remove middle entry.
  5037. (should
  5038. (equal "\
  5039. * H
  5040. CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
  5041. Paragraph"
  5042. (org-test-with-temp-text "\
  5043. * H
  5044. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  5045. Paragraph<point>"
  5046. (let ((org-adapt-indentation t))
  5047. (org-add-planning-info nil nil 'deadline))
  5048. (replace-regexp-in-string
  5049. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  5050. nil nil 1))))
  5051. ;; Remove last entry and then middle entry (order should not
  5052. ;; matter).
  5053. (should
  5054. (equal "\
  5055. * H
  5056. CLOSED: [2015-06-24]
  5057. Paragraph"
  5058. (org-test-with-temp-text "\
  5059. * H
  5060. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  5061. Paragraph<point>"
  5062. (let ((org-adapt-indentation t))
  5063. (org-add-planning-info nil nil 'scheduled 'deadline))
  5064. (replace-regexp-in-string
  5065. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  5066. nil nil 1))))
  5067. ;; Remove closed when `org-adapt-indentation' is non-nil.
  5068. (should
  5069. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5070. (org-test-with-temp-text "\
  5071. * H
  5072. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  5073. Paragraph<point>"
  5074. (let ((org-adapt-indentation t))
  5075. (org-add-planning-info nil nil 'closed))
  5076. (replace-regexp-in-string
  5077. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5078. nil nil 1))))
  5079. (should
  5080. (equal "* H\n Paragraph"
  5081. (org-test-with-temp-text "\
  5082. * H
  5083. CLOSED: [2015-06-25 Thu]
  5084. Paragraph<point>"
  5085. (let ((org-adapt-indentation t))
  5086. (org-add-planning-info nil nil 'closed))
  5087. (replace-regexp-in-string
  5088. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5089. nil nil 1))))
  5090. ;; Remove closed when `org-adapt-indentation' is nil.
  5091. (should
  5092. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  5093. (org-test-with-temp-text "\
  5094. * H
  5095. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  5096. Paragraph<point>"
  5097. (let ((org-adapt-indentation nil))
  5098. (org-add-planning-info nil nil 'closed))
  5099. (replace-regexp-in-string
  5100. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5101. nil nil 1))))
  5102. (should
  5103. (equal "* H\nParagraph"
  5104. (org-test-with-temp-text "\
  5105. * H
  5106. CLOSED: [2015-06-25 Thu]
  5107. Paragraph<point>"
  5108. (let ((org-adapt-indentation nil))
  5109. (org-add-planning-info nil nil 'closed))
  5110. (replace-regexp-in-string
  5111. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5112. nil nil 1))))
  5113. ;; Remove closed entry and delete empty line.
  5114. (should
  5115. (equal "\
  5116. * H
  5117. Paragraph"
  5118. (org-test-with-temp-text "\
  5119. * H
  5120. CLOSED: [2015-06-24 Wed]
  5121. Paragraph<point>"
  5122. (let ((org-adapt-indentation t))
  5123. (org-add-planning-info nil nil 'closed))
  5124. (replace-regexp-in-string
  5125. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5126. nil nil 1))))
  5127. ;; Remove one entry and update another.
  5128. (should
  5129. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5130. (org-test-with-temp-text "\
  5131. * H
  5132. SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
  5133. Paragraph<point>"
  5134. (let ((org-adapt-indentation t))
  5135. (org-add-planning-info 'deadline "<2015-06-25 Thu>" 'scheduled))
  5136. (replace-regexp-in-string
  5137. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5138. nil nil 1)))))
  5139. (ert-deftest test-org/deadline ()
  5140. "Test `org-deadline' specifications."
  5141. ;; Insert a new value or replace existing one.
  5142. (should
  5143. (equal "* H\nDEADLINE: <2012-03-29>"
  5144. (org-test-with-temp-text "* H"
  5145. (let ((org-adapt-indentation nil)
  5146. (org-last-inserted-timestamp nil))
  5147. (org-deadline nil "<2012-03-29 Tue>"))
  5148. (replace-regexp-in-string
  5149. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5150. nil nil 1))))
  5151. (should
  5152. (equal "* H\nDEADLINE: <2014-03-04>"
  5153. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5154. (let ((org-adapt-indentation nil)
  5155. (org-last-inserted-timestamp nil))
  5156. (org-deadline nil "<2014-03-04 Thu>"))
  5157. (replace-regexp-in-string
  5158. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5159. nil nil 1))))
  5160. ;; Accept delta time, e.g., "+2d".
  5161. (should
  5162. (equal "* H\nDEADLINE: <2015-03-04>"
  5163. (org-test-at-time "2014-03-04"
  5164. (org-test-with-temp-text "* H"
  5165. (let ((org-adapt-indentation nil)
  5166. (org-last-inserted-timestamp nil))
  5167. (org-deadline nil "+1y"))
  5168. (replace-regexp-in-string
  5169. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5170. ;; Preserve repeater.
  5171. (should
  5172. (equal "* H\nDEADLINE: <2012-03-29 +2y>"
  5173. (org-test-with-temp-text "* H"
  5174. (let ((org-adapt-indentation nil)
  5175. (org-last-inserted-timestamp nil))
  5176. (org-deadline nil "<2012-03-29 Tue +2y>"))
  5177. (replace-regexp-in-string
  5178. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5179. ;; Remove CLOSED keyword, if any.
  5180. (should
  5181. (equal "* H\nDEADLINE: <2012-03-29>"
  5182. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  5183. (let ((org-adapt-indentation nil)
  5184. (org-last-inserted-timestamp nil))
  5185. (org-deadline nil "<2012-03-29 Tue>"))
  5186. (replace-regexp-in-string
  5187. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5188. ;; With C-u argument, remove DEADLINE keyword.
  5189. (should
  5190. (equal "* H\n"
  5191. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5192. (let ((org-adapt-indentation nil)
  5193. (org-last-inserted-timestamp nil))
  5194. (org-deadline '(4)))
  5195. (buffer-string))))
  5196. (should
  5197. (equal "* H"
  5198. (org-test-with-temp-text "* H"
  5199. (let ((org-adapt-indentation nil)
  5200. (org-last-inserted-timestamp nil))
  5201. (org-deadline '(4)))
  5202. (buffer-string))))
  5203. ;; With C-u C-u argument, prompt for a delay cookie.
  5204. (should
  5205. (equal "* H\nDEADLINE: <2012-03-29 -705d>"
  5206. (cl-letf (((symbol-function 'org-read-date)
  5207. (lambda (&rest args)
  5208. (apply #'encode-time
  5209. (org-parse-time-string "2014-03-04")))))
  5210. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5211. (let ((org-adapt-indentation nil)
  5212. (org-last-inserted-timestamp nil))
  5213. (org-deadline '(16)))
  5214. (buffer-string)))))
  5215. (should-error
  5216. (cl-letf (((symbol-function 'org-read-date)
  5217. (lambda (&rest args)
  5218. (apply #'encode-time
  5219. (org-parse-time-string "2014-03-04")))))
  5220. (org-test-with-temp-text "* H"
  5221. (let ((org-adapt-indentation nil)
  5222. (org-last-inserted-timestamp nil))
  5223. (org-deadline '(16)))
  5224. (buffer-string))))
  5225. ;; When a region is active and
  5226. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5227. ;; same value in all headlines in region.
  5228. (should
  5229. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5230. (org-test-with-temp-text "* H1\n* H2"
  5231. (let ((org-adapt-indentation nil)
  5232. (org-last-inserted-timestamp nil)
  5233. (org-loop-over-headlines-in-active-region t))
  5234. (transient-mark-mode 1)
  5235. (push-mark (point) t t)
  5236. (goto-char (point-max))
  5237. (org-deadline nil "2012-03-29"))
  5238. (replace-regexp-in-string
  5239. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5240. (should-not
  5241. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5242. (org-test-with-temp-text "* H1\n* H2"
  5243. (let ((org-adapt-indentation nil)
  5244. (org-last-inserted-timestamp nil)
  5245. (org-loop-over-headlines-in-active-region nil))
  5246. (transient-mark-mode 1)
  5247. (push-mark (point) t t)
  5248. (goto-char (point-max))
  5249. (org-deadline nil "2012-03-29"))
  5250. (replace-regexp-in-string
  5251. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5252. (ert-deftest test-org/schedule ()
  5253. "Test `org-schedule' specifications."
  5254. ;; Insert a new value or replace existing one.
  5255. (should
  5256. (equal "* H\nSCHEDULED: <2012-03-29>"
  5257. (org-test-with-temp-text "* H"
  5258. (let ((org-adapt-indentation nil)
  5259. (org-last-inserted-timestamp nil))
  5260. (org-schedule nil "<2012-03-29 Tue>"))
  5261. (replace-regexp-in-string
  5262. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5263. nil nil 1))))
  5264. (should
  5265. (equal "* H\nSCHEDULED: <2014-03-04>"
  5266. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5267. (let ((org-adapt-indentation nil)
  5268. (org-last-inserted-timestamp nil))
  5269. (org-schedule nil "<2014-03-04 Thu>"))
  5270. (replace-regexp-in-string
  5271. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5272. nil nil 1))))
  5273. ;; Accept delta time, e.g., "+2d".
  5274. (should
  5275. (equal "* H\nSCHEDULED: <2015-03-04>"
  5276. (org-test-at-time "2014-03-04"
  5277. (org-test-with-temp-text "* H"
  5278. (let ((org-adapt-indentation nil)
  5279. (org-last-inserted-timestamp nil))
  5280. (org-schedule nil "+1y"))
  5281. (replace-regexp-in-string
  5282. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5283. ;; Preserve repeater.
  5284. (should
  5285. (equal "* H\nSCHEDULED: <2012-03-29 +2y>"
  5286. (org-test-with-temp-text "* H"
  5287. (let ((org-adapt-indentation nil)
  5288. (org-last-inserted-timestamp nil))
  5289. (org-schedule nil "<2012-03-29 Tue +2y>"))
  5290. (replace-regexp-in-string
  5291. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5292. ;; Remove CLOSED keyword, if any.
  5293. (should
  5294. (equal "* H\nSCHEDULED: <2012-03-29>"
  5295. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  5296. (let ((org-adapt-indentation nil)
  5297. (org-last-inserted-timestamp nil))
  5298. (org-schedule nil "<2012-03-29 Tue>"))
  5299. (replace-regexp-in-string
  5300. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5301. ;; With C-u argument, remove SCHEDULED keyword.
  5302. (should
  5303. (equal "* H\n"
  5304. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5305. (let ((org-adapt-indentation nil)
  5306. (org-last-inserted-timestamp nil))
  5307. (org-schedule '(4)))
  5308. (buffer-string))))
  5309. (should
  5310. (equal "* H"
  5311. (org-test-with-temp-text "* H"
  5312. (let ((org-adapt-indentation nil)
  5313. (org-last-inserted-timestamp nil))
  5314. (org-schedule '(4)))
  5315. (buffer-string))))
  5316. ;; With C-u C-u argument, prompt for a delay cookie.
  5317. (should
  5318. (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
  5319. (cl-letf (((symbol-function 'org-read-date)
  5320. (lambda (&rest args)
  5321. (apply #'encode-time
  5322. (org-parse-time-string "2014-03-04")))))
  5323. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5324. (let ((org-adapt-indentation nil)
  5325. (org-last-inserted-timestamp nil))
  5326. (org-schedule '(16)))
  5327. (buffer-string)))))
  5328. (should-error
  5329. (cl-letf (((symbol-function 'org-read-date)
  5330. (lambda (&rest args)
  5331. (apply #'encode-time
  5332. (org-parse-time-string "2014-03-04")))))
  5333. (org-test-with-temp-text "* H"
  5334. (let ((org-adapt-indentation nil)
  5335. (org-last-inserted-timestamp nil))
  5336. (org-schedule '(16)))
  5337. (buffer-string))))
  5338. ;; When a region is active and
  5339. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5340. ;; same value in all headlines in region.
  5341. (should
  5342. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5343. (org-test-with-temp-text "* H1\n* H2"
  5344. (let ((org-adapt-indentation nil)
  5345. (org-last-inserted-timestamp nil)
  5346. (org-loop-over-headlines-in-active-region t))
  5347. (transient-mark-mode 1)
  5348. (push-mark (point) t t)
  5349. (goto-char (point-max))
  5350. (org-schedule nil "2012-03-29"))
  5351. (replace-regexp-in-string
  5352. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5353. (should-not
  5354. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5355. (org-test-with-temp-text "* H1\n* H2"
  5356. (let ((org-adapt-indentation nil)
  5357. (org-last-inserted-timestamp nil)
  5358. (org-loop-over-headlines-in-active-region nil))
  5359. (transient-mark-mode 1)
  5360. (push-mark (point) t t)
  5361. (goto-char (point-max))
  5362. (org-schedule nil "2012-03-29"))
  5363. (replace-regexp-in-string
  5364. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5365. (should
  5366. ;; check if a repeater survives re-scheduling.
  5367. (string-match-p
  5368. "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
  5369. (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
  5370. (let ((org-adapt-indentation nil)
  5371. (org-last-inserted-timestamp nil))
  5372. (org-schedule nil "2017-02-01"))
  5373. (buffer-string)))))
  5374. ;;; Property API
  5375. (ert-deftest test-org/buffer-property-keys ()
  5376. "Test `org-buffer-property-keys' specifications."
  5377. ;; Retrieve properties across siblings.
  5378. (should
  5379. (equal '("A" "B")
  5380. (org-test-with-temp-text "
  5381. * H1
  5382. :PROPERTIES:
  5383. :A: 1
  5384. :END:
  5385. * H2
  5386. :PROPERTIES:
  5387. :B: 1
  5388. :END:"
  5389. (org-buffer-property-keys))))
  5390. ;; Retrieve properties across children.
  5391. (should
  5392. (equal '("A" "B")
  5393. (org-test-with-temp-text "
  5394. * H1
  5395. :PROPERTIES:
  5396. :A: 1
  5397. :END:
  5398. ** H2
  5399. :PROPERTIES:
  5400. :B: 1
  5401. :END:"
  5402. (org-buffer-property-keys))))
  5403. ;; Retrieve muliple properties in the same drawer.
  5404. (should
  5405. (equal '("A" "B")
  5406. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5407. (org-buffer-property-keys))))
  5408. ;; Ignore extension symbol in property name.
  5409. (should
  5410. (equal '("A")
  5411. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5412. (org-buffer-property-keys))))
  5413. ;; Add bare property if xxx_ALL property is there
  5414. (should
  5415. (equal '("A" "B" "B_ALL")
  5416. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B_ALL: foo bar\n:END:"
  5417. (org-buffer-property-keys))))
  5418. ;; Add bare property if xxx_ALL property is there - check dupes
  5419. (should
  5420. (equal '("A" "B" "B_ALL")
  5421. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:B_ALL: foo bar\n:END:"
  5422. (org-buffer-property-keys))))
  5423. ;; Retrieve properties from #+PROPERTY keyword lines
  5424. (should
  5425. (equal '("A" "C")
  5426. (org-test-with-temp-text "#+PROPERTY: C foo\n* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5427. (org-buffer-property-keys))))
  5428. ;; Retrieve properties from #+PROPERTY keyword lines - make sure an _ALL property also
  5429. ;; adds the bare property
  5430. (should
  5431. (equal '("A" "C" "C_ALL")
  5432. (org-test-with-temp-text "#+PROPERTY: C_ALL foo bar\n* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5433. (org-buffer-property-keys))))
  5434. ;; With non-nil COLUMNS, extract property names from columns.
  5435. (should
  5436. (equal '("A" "B")
  5437. (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
  5438. (org-buffer-property-keys nil nil t))))
  5439. (should
  5440. (equal '("A" "B" "COLUMNS")
  5441. (org-test-with-temp-text
  5442. "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
  5443. (org-buffer-property-keys nil nil t))))
  5444. ;; In COLUMNS, ignore title and summary-type.
  5445. (should
  5446. (equal '("A")
  5447. (org-test-with-temp-text "#+COLUMNS: %A(Foo)"
  5448. (org-buffer-property-keys nil nil t))))
  5449. (should
  5450. (equal '("A")
  5451. (org-test-with-temp-text "#+COLUMNS: %A{Foo}"
  5452. (org-buffer-property-keys nil nil t))))
  5453. (should
  5454. (equal '("A")
  5455. (org-test-with-temp-text "#+COLUMNS: %A(Foo){Bar}"
  5456. (org-buffer-property-keys nil nil t)))))
  5457. (ert-deftest test-org/property-values ()
  5458. "Test `org-property-values' specifications."
  5459. ;; Regular test.
  5460. (should
  5461. (equal '("2" "1")
  5462. (org-test-with-temp-text
  5463. "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
  5464. (org-property-values "A"))))
  5465. ;; Ignore empty values.
  5466. (should-not
  5467. (org-test-with-temp-text
  5468. "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
  5469. (org-property-values "A")))
  5470. ;; Take into consideration extended values.
  5471. (should
  5472. (equal '("1 2")
  5473. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5474. (org-property-values "A")))))
  5475. (ert-deftest test-org/set-property ()
  5476. "Test `org-set-property' specifications."
  5477. (should
  5478. (equal
  5479. ":PROPERTIES:\n:TEST: t\n:END:\n"
  5480. (org-test-with-temp-text ""
  5481. (let ((org-property-format "%s %s"))
  5482. (org-set-property "TEST" "t"))
  5483. (buffer-string))))
  5484. (should
  5485. (equal
  5486. "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5487. (org-test-with-temp-text "* H"
  5488. (let ((org-adapt-indentation nil)
  5489. (org-property-format "%s %s"))
  5490. (org-set-property "TEST" "t"))
  5491. (buffer-string)))))
  5492. (ert-deftest test-org/delete-property ()
  5493. "Test `org-delete-property' specifications."
  5494. (should
  5495. (equal
  5496. ""
  5497. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5498. (org-delete-property "TEST")
  5499. (buffer-string))))
  5500. (should
  5501. (equal
  5502. ":PROPERTIES:\n:TEST1: t\n:END:\n"
  5503. (org-test-with-temp-text ":PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5504. (org-delete-property "TEST2")
  5505. (buffer-string))))
  5506. (should
  5507. (equal
  5508. "* H\n"
  5509. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5510. (org-delete-property "TEST")
  5511. (buffer-string))))
  5512. (should
  5513. (equal
  5514. "* H\n:PROPERTIES:\n:TEST1: t\n:END:\n"
  5515. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5516. (org-delete-property "TEST2")
  5517. (buffer-string)))))
  5518. (ert-deftest test-org/delete-property-globally ()
  5519. "Test `org-delete-property-global' specifications."
  5520. (should
  5521. (equal
  5522. ""
  5523. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5524. (org-delete-property-globally "TEST")
  5525. (buffer-string))))
  5526. (should
  5527. (equal
  5528. "* H\n"
  5529. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n* H\n:PROPERTIES:\n:TEST: nil\n:END:"
  5530. (org-delete-property-globally "TEST")
  5531. (buffer-string)))))
  5532. (ert-deftest test-org/find-property ()
  5533. "Test `org-find-property' specifications."
  5534. ;; Regular test.
  5535. (should
  5536. (= 1
  5537. (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
  5538. (org-find-property "prop"))))
  5539. ;; Find properties in top-level property drawer.
  5540. (should
  5541. (= 1
  5542. (org-test-with-temp-text ":PROPERTIES:\n:PROP: value\n:END:"
  5543. (org-find-property "prop"))))
  5544. ;; Ignore false positives.
  5545. (should
  5546. (= 27
  5547. (org-test-with-temp-text
  5548. "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
  5549. (org-find-property "A"))))
  5550. ;; Return first entry found in buffer.
  5551. (should
  5552. (= 1
  5553. (org-test-with-temp-text
  5554. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5555. (org-find-property "A"))))
  5556. ;; Only search visible part of the buffer.
  5557. (should
  5558. (= 31
  5559. (org-test-with-temp-text
  5560. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5561. (org-narrow-to-subtree)
  5562. (org-find-property "A"))))
  5563. ;; With optional argument, only find entries with a specific value.
  5564. (should-not
  5565. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5566. (org-find-property "A" "2")))
  5567. (should
  5568. (= 31
  5569. (org-test-with-temp-text
  5570. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
  5571. (org-find-property "A" "2"))))
  5572. ;; Use "nil" for explicit nil values.
  5573. (should
  5574. (= 31
  5575. (org-test-with-temp-text
  5576. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
  5577. (org-find-property "A" "nil")))))
  5578. (ert-deftest test-org/entry-delete ()
  5579. "Test `org-entry-delete' specifications."
  5580. ;; Regular test.
  5581. (should
  5582. (string-match
  5583. " *:PROPERTIES:\n *:B: +2\n *:END:"
  5584. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5585. (org-entry-delete (point) "A")
  5586. (buffer-string))))
  5587. ;; Also remove accumulated properties.
  5588. (should-not
  5589. (string-match
  5590. ":A"
  5591. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
  5592. (org-entry-delete (point) "A")
  5593. (buffer-string))))
  5594. ;; When last property is removed, remove the property drawer.
  5595. (should-not
  5596. (string-match
  5597. ":PROPERTIES:"
  5598. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
  5599. (org-entry-delete (point) "A")
  5600. (buffer-string))))
  5601. ;; Return a non-nil value when some property was removed.
  5602. (should
  5603. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5604. (org-entry-delete (point) "A")))
  5605. (should-not
  5606. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5607. (org-entry-delete (point) "C")))
  5608. ;; Special properties cannot be located in a drawer. Allow to
  5609. ;; remove them anyway, in case of user error.
  5610. (should
  5611. (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
  5612. (org-entry-delete (point) "SCHEDULED"))))
  5613. (ert-deftest test-org/entry-get ()
  5614. "Test `org-entry-get' specifications."
  5615. ;; Regular test.
  5616. (should
  5617. (equal "1"
  5618. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:"
  5619. (org-entry-get (point) "A"))))
  5620. (should
  5621. (equal "1"
  5622. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5623. (org-entry-get (point) "A"))))
  5624. ;; Ignore case.
  5625. (should
  5626. (equal "1"
  5627. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5628. (org-entry-get (point) "a"))))
  5629. ;; Handle extended values, both before and after base value.
  5630. (should
  5631. (equal "1 2 3"
  5632. (org-test-with-temp-text
  5633. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5634. (org-entry-get (point) "A"))))
  5635. ;; Empty values are returned as the empty string.
  5636. (should
  5637. (equal ""
  5638. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
  5639. (org-entry-get (point) "A"))))
  5640. ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
  5641. ;; otherwise, return nil.
  5642. (should-not
  5643. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5644. (org-entry-get (point) "A")))
  5645. (should
  5646. (equal "nil"
  5647. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5648. (org-entry-get (point) "A" nil t))))
  5649. ;; Return nil when no property is found, independently on the
  5650. ;; LITERAL-NIL argument.
  5651. (should-not
  5652. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5653. (org-entry-get (point) "B")))
  5654. (should-not
  5655. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5656. (org-entry-get (point) "B" nil t)))
  5657. ;; Handle inheritance, when allowed. Include extended values and
  5658. ;; possibly global values.
  5659. (should
  5660. (equal
  5661. "1"
  5662. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:\n* H"
  5663. (org-entry-get (point-max) "A" t))))
  5664. (should
  5665. (equal
  5666. "1"
  5667. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5668. (org-entry-get (point-max) "A" t))))
  5669. (should
  5670. (equal
  5671. "1"
  5672. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5673. (let ((org-use-property-inheritance t))
  5674. (org-entry-get (point-max) "A" 'selective)))))
  5675. (should-not
  5676. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5677. (let ((org-use-property-inheritance nil))
  5678. (org-entry-get (point-max) "A" 'selective))))
  5679. (should
  5680. (equal
  5681. "1 2"
  5682. (org-test-with-temp-text
  5683. ":PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5684. (org-entry-get (point-max) "A" t))))
  5685. (should
  5686. (equal
  5687. "1 2"
  5688. (org-test-with-temp-text
  5689. "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5690. (org-entry-get (point-max) "A" t))))
  5691. (should
  5692. (equal
  5693. "1 2"
  5694. (org-test-with-temp-text
  5695. ":PROPERTIES:\n:A: 1\n:END:\n* H1\n* H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5696. (org-entry-get (point-max) "A" t))))
  5697. (should
  5698. (equal
  5699. "1 2"
  5700. (org-test-with-temp-text
  5701. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2.1\n* H2.2\n:PROPERTIES:\n:A+: 2\n:END:"
  5702. (org-entry-get (point-max) "A" t))))
  5703. (should
  5704. (equal "1"
  5705. (org-test-with-temp-text
  5706. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
  5707. (org-mode-restart)
  5708. (org-entry-get (point-max) "A" t))))
  5709. (should
  5710. (equal "0 1"
  5711. (org-test-with-temp-text
  5712. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
  5713. (org-mode-restart)
  5714. (org-entry-get (point-max) "A" t))))
  5715. ;; document level property-drawer has precedance over
  5716. ;; global-property by PROPERTY-keyword.
  5717. (should
  5718. (equal "0 2"
  5719. (org-test-with-temp-text
  5720. ":PROPERTIES:\n:A: 0\n:END:\n#+PROPERTY: A 1\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5721. (org-mode-restart)
  5722. (org-entry-get (point-max) "A" t)))))
  5723. (ert-deftest test-org/entry-properties ()
  5724. "Test `org-entry-properties' specifications."
  5725. ;; Get "ITEM" property.
  5726. (should
  5727. (equal "H"
  5728. (org-test-with-temp-text "* TODO H"
  5729. (cdr (assoc "ITEM" (org-entry-properties nil "ITEM"))))))
  5730. (should
  5731. (equal "H"
  5732. (org-test-with-temp-text "* TODO H"
  5733. (cdr (assoc "ITEM" (org-entry-properties))))))
  5734. ;; Get "TODO" property. TODO keywords are case sensitive.
  5735. (should
  5736. (equal "TODO"
  5737. (org-test-with-temp-text "* TODO H"
  5738. (cdr (assoc "TODO" (org-entry-properties nil "TODO"))))))
  5739. (should
  5740. (equal "TODO"
  5741. (org-test-with-temp-text "* TODO H"
  5742. (cdr (assoc "TODO" (org-entry-properties))))))
  5743. (should-not
  5744. (org-test-with-temp-text "* H"
  5745. (assoc "TODO" (org-entry-properties nil "TODO"))))
  5746. (should-not
  5747. (org-test-with-temp-text "* todo H"
  5748. (assoc "TODO" (org-entry-properties nil "TODO"))))
  5749. ;; Get "PRIORITY" property.
  5750. (should
  5751. (equal "A"
  5752. (org-test-with-temp-text "* [#A] H"
  5753. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  5754. (should
  5755. (equal "A"
  5756. (org-test-with-temp-text "* [#A] H"
  5757. (cdr (assoc "PRIORITY" (org-entry-properties))))))
  5758. (should
  5759. (equal (char-to-string org-priority-default)
  5760. (org-test-with-temp-text "* H"
  5761. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  5762. ;; Get "FILE" property.
  5763. (should
  5764. (org-test-with-temp-text-in-file "* H\nParagraph"
  5765. (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil "FILE")))
  5766. (buffer-file-name))))
  5767. (should
  5768. (org-test-with-temp-text-in-file "* H\nParagraph"
  5769. (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
  5770. (buffer-file-name))))
  5771. (should-not
  5772. (org-test-with-temp-text "* H\nParagraph"
  5773. (cdr (assoc "FILE" (org-entry-properties nil "FILE")))))
  5774. ;; Get "TAGS" property.
  5775. (should
  5776. (equal ":tag1:tag2:"
  5777. (org-test-with-temp-text "* H :tag1:tag2:"
  5778. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS"))))))
  5779. (should
  5780. (equal ":tag1:tag2:"
  5781. (org-test-with-temp-text "* H :tag1:tag2:"
  5782. (cdr (assoc "TAGS" (org-entry-properties))))))
  5783. (should-not
  5784. (org-test-with-temp-text "* H"
  5785. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS")))))
  5786. ;; Get "ALLTAGS" property.
  5787. (should
  5788. (equal ":tag1:tag2:"
  5789. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  5790. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS"))))))
  5791. (should
  5792. (equal ":tag1:tag2:"
  5793. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  5794. (cdr (assoc "ALLTAGS" (org-entry-properties))))))
  5795. (should-not
  5796. (org-test-with-temp-text "* H"
  5797. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS")))))
  5798. ;; Get "BLOCKED" property.
  5799. (should
  5800. (equal "t"
  5801. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  5802. (let ((org-enforce-todo-dependencies t)
  5803. (org-blocker-hook
  5804. '(org-block-todo-from-children-or-siblings-or-parent)))
  5805. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  5806. (should
  5807. (equal ""
  5808. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  5809. (let ((org-enforce-todo-dependencies t)
  5810. (org-blocker-hook
  5811. '(org-block-todo-from-children-or-siblings-or-parent)))
  5812. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  5813. ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
  5814. (should
  5815. (equal
  5816. "[2012-03-29 thu.]"
  5817. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  5818. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED"))))))
  5819. (should
  5820. (equal
  5821. "[2012-03-29 thu.]"
  5822. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  5823. (cdr (assoc "CLOSED" (org-entry-properties))))))
  5824. (should-not
  5825. (org-test-with-temp-text "* H"
  5826. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED")))))
  5827. (should
  5828. (equal
  5829. "<2014-03-04 tue.>"
  5830. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5831. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE"))))))
  5832. (should
  5833. (equal
  5834. "<2014-03-04 tue.>"
  5835. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5836. (cdr (assoc "DEADLINE" (org-entry-properties))))))
  5837. (should-not
  5838. (org-test-with-temp-text "* H"
  5839. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE")))))
  5840. (should
  5841. (equal
  5842. "<2014-03-04 tue.>"
  5843. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5844. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED"))))))
  5845. (should
  5846. (equal
  5847. "<2014-03-04 tue.>"
  5848. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5849. (cdr (assoc "SCHEDULED" (org-entry-properties))))))
  5850. (should-not
  5851. (org-test-with-temp-text "* H"
  5852. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED")))))
  5853. ;; Get "CATEGORY"
  5854. (should
  5855. (equal "cat"
  5856. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  5857. (cdr (assoc "CATEGORY" (org-entry-properties))))))
  5858. (should
  5859. (equal "cat"
  5860. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  5861. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5862. (should
  5863. (equal "cat"
  5864. (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
  5865. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5866. (should
  5867. (equal "cat2"
  5868. (org-test-with-temp-text
  5869. (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  5870. "\n"
  5871. "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
  5872. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5873. ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
  5874. (should
  5875. (equal "<2012-03-29 thu.>"
  5876. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
  5877. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  5878. (should
  5879. (equal "[2012-03-29 thu.]"
  5880. (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
  5881. (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
  5882. (should
  5883. (equal "<2012-03-29 thu.>"
  5884. (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
  5885. (cdr (assoc "TIMESTAMP" (org-entry-properties nil "TIMESTAMP"))))))
  5886. (should
  5887. (equal "[2014-03-04 tue.]"
  5888. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
  5889. (cdr (assoc "TIMESTAMP_IA"
  5890. (org-entry-properties nil "TIMESTAMP_IA"))))))
  5891. (should-not
  5892. (equal "<2012-03-29 thu.>"
  5893. (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
  5894. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  5895. ;; Get standard properties.
  5896. (should
  5897. (equal "1"
  5898. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5899. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5900. ;; Handle extended properties.
  5901. (should
  5902. (equal "1 2 3"
  5903. (org-test-with-temp-text
  5904. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5905. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5906. (should
  5907. (equal "1 2 3"
  5908. (org-test-with-temp-text
  5909. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
  5910. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5911. ;; Ignore forbidden (special) properties.
  5912. (should-not
  5913. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
  5914. (cdr (assoc "TODO" (org-entry-properties nil 'standard))))))
  5915. (ert-deftest test-org/entry-put ()
  5916. "Test `org-entry-put' specifications."
  5917. ;; Error when not a string or nil.
  5918. (should-error
  5919. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5920. (org-entry-put 1 "test" 2)))
  5921. ;; Error when property name is invalid.
  5922. (should-error
  5923. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5924. (org-entry-put 1 "no space" "value")))
  5925. (should-error
  5926. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5927. (org-entry-put 1 "" "value")))
  5928. ;; Set "TODO" property.
  5929. (should
  5930. (string-match (regexp-quote " TODO H")
  5931. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  5932. (org-entry-put (point) "TODO" "TODO")
  5933. (buffer-string))))
  5934. (should
  5935. (string-match (regexp-quote "* H")
  5936. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  5937. (org-entry-put (point) "TODO" nil)
  5938. (buffer-string))))
  5939. ;; Set "PRIORITY" property.
  5940. (should
  5941. (equal "* [#A] H"
  5942. (org-test-with-temp-text "* [#B] H"
  5943. (org-entry-put (point) "PRIORITY" "A")
  5944. (buffer-string))))
  5945. (should
  5946. (equal "* H"
  5947. (org-test-with-temp-text "* [#B] H"
  5948. (org-entry-put (point) "PRIORITY" nil)
  5949. (buffer-string))))
  5950. ;; Set "SCHEDULED" property.
  5951. (should
  5952. (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
  5953. (org-test-with-temp-text "* H"
  5954. (org-entry-put (point) "SCHEDULED" "2014-03-04")
  5955. (buffer-string))))
  5956. (should
  5957. (string= "* H\n"
  5958. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5959. (org-entry-put (point) "SCHEDULED" nil)
  5960. (buffer-string))))
  5961. (should
  5962. (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
  5963. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5964. (org-entry-put (point) "SCHEDULED" "earlier")
  5965. (buffer-string))))
  5966. (should
  5967. (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
  5968. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5969. (org-entry-put (point) "SCHEDULED" "later")
  5970. (buffer-string))))
  5971. ;; Set "DEADLINE" property.
  5972. (should
  5973. (string-match "^ *DEADLINE: <2014-03-04 .*?>"
  5974. (org-test-with-temp-text "* H"
  5975. (org-entry-put (point) "DEADLINE" "2014-03-04")
  5976. (buffer-string))))
  5977. (should
  5978. (string= "* H\n"
  5979. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5980. (org-entry-put (point) "DEADLINE" nil)
  5981. (buffer-string))))
  5982. (should
  5983. (string-match "^ *DEADLINE: <2014-03-03 .*?>"
  5984. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5985. (org-entry-put (point) "DEADLINE" "earlier")
  5986. (buffer-string))))
  5987. (should
  5988. (string-match "^ *DEADLINE: <2014-03-05 .*?>"
  5989. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5990. (org-entry-put (point) "DEADLINE" "later")
  5991. (buffer-string))))
  5992. ;; Set "CATEGORY" property
  5993. (should
  5994. (string-match "^ *:CATEGORY: cat"
  5995. (org-test-with-temp-text "* H"
  5996. (org-entry-put (point) "CATEGORY" "cat")
  5997. (buffer-string))))
  5998. ;; Regular properties, with or without pre-existing drawer.
  5999. (should
  6000. (string-match "^ *:A: +2$"
  6001. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6002. (org-entry-put (point) "A" "2")
  6003. (buffer-string))))
  6004. (should
  6005. (string-match "^ *:A: +1$"
  6006. (org-test-with-temp-text "* H"
  6007. (org-entry-put (point) "A" "1")
  6008. (buffer-string))))
  6009. ;; Special case: two consecutive headlines.
  6010. (should
  6011. (string-match "\\* A\n *:PROPERTIES:"
  6012. (org-test-with-temp-text "* A\n** B"
  6013. (org-entry-put (point) "A" "1")
  6014. (buffer-string)))))
  6015. (ert-deftest test-org/refresh-properties ()
  6016. "Test `org-refresh-properties' specifications."
  6017. (should
  6018. (equal "1"
  6019. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6020. (org-refresh-properties "A" 'org-test)
  6021. (get-text-property (point) 'org-test))))
  6022. (should-not
  6023. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6024. (org-refresh-properties "B" 'org-test)
  6025. (get-text-property (point) 'org-test)))
  6026. ;; Handle properties only defined with extension syntax, i.e.,
  6027. ;; "PROPERTY+".
  6028. (should
  6029. (equal "1"
  6030. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
  6031. (org-refresh-properties "A" 'org-test)
  6032. (get-text-property (point) 'org-test))))
  6033. ;; When property is inherited, add text property to the whole
  6034. ;; sub-tree.
  6035. (should
  6036. (equal "1"
  6037. (org-test-with-temp-text
  6038. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
  6039. (let ((org-use-property-inheritance t))
  6040. (org-refresh-properties "A" 'org-test))
  6041. (get-text-property (point) 'org-test))))
  6042. ;; When a document level property-drawer is used, those properties
  6043. ;; should work exactly like headline-properties as if at a
  6044. ;; headline-level 0.
  6045. (should
  6046. (equal "1"
  6047. (org-test-with-temp-text
  6048. ":PROPERTIES:\n:A: 1\n:END:\n"
  6049. (org-mode-restart)
  6050. (let ((org-use-property-inheritance t))
  6051. (org-refresh-properties "A" 'org-test))
  6052. (get-text-property (point) 'org-test))))
  6053. (should-not
  6054. (equal "1"
  6055. (org-test-with-temp-text
  6056. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  6057. (org-mode-restart)
  6058. (let ((org-use-property-inheritance nil))
  6059. (org-refresh-properties "A" 'org-test))
  6060. (get-text-property (point) 'org-test))))
  6061. (should
  6062. (equal "1"
  6063. (org-test-with-temp-text
  6064. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  6065. (org-mode-restart)
  6066. (let ((org-use-property-inheritance t))
  6067. (org-refresh-properties "A" 'org-test))
  6068. (get-text-property (point) 'org-test))))
  6069. (should
  6070. (equal "2"
  6071. (org-test-with-temp-text
  6072. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1\n:PROPERTIES:\n:A: 2\n:END:"
  6073. (org-mode-restart)
  6074. (let ((org-use-property-inheritance t))
  6075. (org-refresh-properties "A" 'org-test))
  6076. (get-text-property (point) 'org-test))))
  6077. ;; When property is inherited, use global value across the whole
  6078. ;; buffer. However local values have precedence, as well as the
  6079. ;; document level property-drawer.
  6080. (should-not
  6081. (equal "1"
  6082. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  6083. (org-mode-restart)
  6084. (let ((org-use-property-inheritance nil))
  6085. (org-refresh-properties "A" 'org-test))
  6086. (get-text-property (point) 'org-test))))
  6087. (should
  6088. (equal "1"
  6089. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  6090. (org-mode-restart)
  6091. (let ((org-use-property-inheritance t))
  6092. (org-refresh-properties "A" 'org-test))
  6093. (get-text-property (point) 'org-test))))
  6094. (should
  6095. (equal "2"
  6096. (org-test-with-temp-text
  6097. "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
  6098. (org-mode-restart)
  6099. (let ((org-use-property-inheritance t))
  6100. (org-refresh-properties "A" 'org-test))
  6101. (get-text-property (point) 'org-test))))
  6102. ;; When both keyword-property and document-level property-block is
  6103. ;; defined, the property-block has precedance.
  6104. (should
  6105. (equal "1"
  6106. (org-test-with-temp-text
  6107. ":PROPERTIES:\n:A: 1\n:END:\n#+PROPERTY: A 2\n<point>* H1"
  6108. (org-mode-restart)
  6109. (let ((org-use-property-inheritance t))
  6110. (org-refresh-properties "A" 'org-test))
  6111. (get-text-property (point) 'org-test)))))
  6112. (ert-deftest test-org/refresh-category-properties ()
  6113. "Test `org-refresh-category-properties' specifications"
  6114. (should
  6115. (equal "cat1"
  6116. (org-test-with-temp-text
  6117. ":PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6118. (org-refresh-category-properties)
  6119. (org-get-category))))
  6120. (should
  6121. (equal "cat1"
  6122. (org-test-with-temp-text
  6123. "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6124. (org-refresh-category-properties)
  6125. (org-get-category))))
  6126. ;; Even though property-inheritance is deactivated, category
  6127. ;; property should be inherited. As described in
  6128. ;; `org-use-property-inheritance'.
  6129. (should
  6130. (equal "cat1"
  6131. (org-test-with-temp-text
  6132. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  6133. (org-mode-restart)
  6134. (let ((org-use-property-inheritance nil))
  6135. (org-refresh-category-properties))
  6136. (org-get-category))))
  6137. (should
  6138. (equal "cat1"
  6139. (org-test-with-temp-text
  6140. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  6141. (org-mode-restart)
  6142. (let ((org-use-property-inheritance t))
  6143. (org-refresh-category-properties))
  6144. (org-get-category))))
  6145. (should
  6146. (equal "cat2"
  6147. (org-test-with-temp-text
  6148. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H\n:PROPERTIES:\n:CATEGORY: cat2\n:END:\n"
  6149. (org-mode-restart)
  6150. (let ((org-use-property-inheritance t))
  6151. (org-refresh-category-properties))
  6152. (org-get-category)))))
  6153. ;;; Refile
  6154. (ert-deftest test-org/refile-get-targets ()
  6155. "Test `org-refile-get-targets' specifications."
  6156. ;; :maxlevel includes all headings above specified value.
  6157. (should
  6158. (equal '("H1" "H2" "H3")
  6159. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6160. (let ((org-refile-use-outline-path nil)
  6161. (org-refile-targets `((nil :maxlevel . 3))))
  6162. (mapcar #'car (org-refile-get-targets))))))
  6163. (should
  6164. (equal '("H1" "H2")
  6165. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6166. (let ((org-refile-use-outline-path nil)
  6167. (org-refile-targets `((nil :maxlevel . 2))))
  6168. (mapcar #'car (org-refile-get-targets))))))
  6169. ;; :level limits targets to headlines with the specified level.
  6170. (should
  6171. (equal '("H2")
  6172. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6173. (let ((org-refile-use-outline-path nil)
  6174. (org-refile-targets `((nil :level . 2))))
  6175. (mapcar #'car (org-refile-get-targets))))))
  6176. ;; :tag limits targets to headlines with specified tag.
  6177. (should
  6178. (equal '("H1")
  6179. (org-test-with-temp-text "* H1 :foo:\n** H2\n*** H3 :bar:"
  6180. (let ((org-refile-use-outline-path nil)
  6181. (org-refile-targets `((nil :tag . "foo"))))
  6182. (mapcar #'car (org-refile-get-targets))))))
  6183. ;; :todo limits targets to headlines with specified TODO keyword.
  6184. (should
  6185. (equal '("H2")
  6186. (org-test-with-temp-text "* H1\n** TODO H2\n*** DONE H3"
  6187. (let ((org-refile-use-outline-path nil)
  6188. (org-refile-targets `((nil :todo . "TODO"))))
  6189. (mapcar #'car (org-refile-get-targets))))))
  6190. ;; :regexp filters targets matching provided regexp.
  6191. (should
  6192. (equal '("F2" "F3")
  6193. (org-test-with-temp-text "* H1\n** F2\n*** F3"
  6194. (let ((org-refile-use-outline-path nil)
  6195. (org-refile-targets `((nil :regexp . "F"))))
  6196. (mapcar #'car (org-refile-get-targets))))))
  6197. ;; A nil `org-refile-targets' includes only top level headlines in
  6198. ;; current buffer.
  6199. (should
  6200. (equal '("H1" "H2")
  6201. (org-test-with-temp-text "* H1\n** S1\n* H2"
  6202. (let ((org-refile-use-outline-path nil)
  6203. (org-refile-targets nil))
  6204. (mapcar #'car (org-refile-get-targets))))))
  6205. ;; Return value is the union of the targets according to all the
  6206. ;; defined rules. However, prevent duplicates.
  6207. (should
  6208. (equal '("F2" "F3" "H1")
  6209. (org-test-with-temp-text "* TODO H1\n** F2\n*** F3"
  6210. (let ((org-refile-use-outline-path nil)
  6211. (org-refile-targets `((nil :regexp . "F")
  6212. (nil :todo . "TODO"))))
  6213. (mapcar #'car (org-refile-get-targets))))))
  6214. (should
  6215. (equal '("F2" "F3" "H1")
  6216. (org-test-with-temp-text "* TODO H1\n** TODO F2\n*** F3"
  6217. (let ((org-refile-use-outline-path nil)
  6218. (org-refile-targets `((nil :regexp . "F")
  6219. (nil :todo . "TODO"))))
  6220. (mapcar #'car (org-refile-get-targets))))))
  6221. ;; When `org-refile-use-outline-path' is non-nil, provide targets as
  6222. ;; paths.
  6223. (should
  6224. (equal '("H1" "H1/H2" "H1/H2/H3")
  6225. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6226. (let ((org-refile-use-outline-path t)
  6227. (org-refile-targets `((nil :maxlevel . 3))))
  6228. (mapcar #'car (org-refile-get-targets))))))
  6229. ;; When providing targets as paths, escape forward slashes in
  6230. ;; headings with backslashes.
  6231. (should
  6232. (equal '("H1\\/foo")
  6233. (org-test-with-temp-text "* H1/foo"
  6234. (let ((org-refile-use-outline-path t)
  6235. (org-refile-targets `((nil :maxlevel . 1))))
  6236. (mapcar #'car (org-refile-get-targets))))))
  6237. ;; When `org-refile-use-outline-path' is `file', include file name
  6238. ;; without directory in targets.
  6239. (should
  6240. (org-test-with-temp-text-in-file "* H1"
  6241. (let* ((filename (buffer-file-name))
  6242. (org-refile-use-outline-path 'file)
  6243. (org-refile-targets `(((,filename) :level . 1))))
  6244. (member (file-name-nondirectory filename)
  6245. (mapcar #'car (org-refile-get-targets))))))
  6246. ;; When `org-refile-use-outline-path' is `full-file-path', include
  6247. ;; full file name.
  6248. (should
  6249. (org-test-with-temp-text-in-file "* H1"
  6250. (let* ((filename (file-truename (buffer-file-name)))
  6251. (org-refile-use-outline-path 'full-file-path)
  6252. (org-refile-targets `(((,filename) :level . 1))))
  6253. (member filename (mapcar #'car (org-refile-get-targets))))))
  6254. ;; When `org-refile-use-outline-path' is `buffer-name', include
  6255. ;; buffer name.
  6256. (should
  6257. (org-test-with-temp-text "* H1"
  6258. (let* ((org-refile-use-outline-path 'buffer-name)
  6259. (org-refile-targets `((nil :level . 1))))
  6260. (member (buffer-name) (mapcar #'car (org-refile-get-targets)))))))
  6261. ;;; Sparse trees
  6262. (ert-deftest test-org/match-sparse-tree ()
  6263. "Test `org-match-sparse-tree' specifications."
  6264. ;; Match tags.
  6265. (should-not
  6266. (org-test-with-temp-text "* H\n** H1 :tag:"
  6267. (org-match-sparse-tree nil "tag")
  6268. (search-forward "H1")
  6269. (org-invisible-p2)))
  6270. (should
  6271. (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
  6272. (org-match-sparse-tree nil "tag")
  6273. (search-forward "H2")
  6274. (org-invisible-p2)))
  6275. ;; "-" operator for tags.
  6276. (should-not
  6277. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6278. (org-match-sparse-tree nil "tag1-tag2")
  6279. (search-forward "H1")
  6280. (org-invisible-p2)))
  6281. (should
  6282. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6283. (org-match-sparse-tree nil "tag1-tag2")
  6284. (search-forward "H2")
  6285. (org-invisible-p2)))
  6286. ;; "&" operator for tags.
  6287. (should
  6288. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6289. (org-match-sparse-tree nil "tag1&tag2")
  6290. (search-forward "H1")
  6291. (org-invisible-p2)))
  6292. (should-not
  6293. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6294. (org-match-sparse-tree nil "tag1&tag2")
  6295. (search-forward "H2")
  6296. (org-invisible-p2)))
  6297. ;; "|" operator for tags.
  6298. (should-not
  6299. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6300. (org-match-sparse-tree nil "tag1|tag2")
  6301. (search-forward "H1")
  6302. (org-invisible-p2)))
  6303. (should-not
  6304. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6305. (org-match-sparse-tree nil "tag1|tag2")
  6306. (search-forward "H2")
  6307. (org-invisible-p2)))
  6308. ;; Regexp match on tags.
  6309. (should-not
  6310. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6311. (org-match-sparse-tree nil "{^tag.*}")
  6312. (search-forward "H1")
  6313. (org-invisible-p2)))
  6314. (should
  6315. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6316. (org-match-sparse-tree nil "{^tag.*}")
  6317. (search-forward "H2")
  6318. (org-invisible-p2)))
  6319. ;; Match group tags.
  6320. (should-not
  6321. (org-test-with-temp-text
  6322. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6323. (org-match-sparse-tree nil "work")
  6324. (search-forward "H1")
  6325. (org-invisible-p2)))
  6326. (should-not
  6327. (org-test-with-temp-text
  6328. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6329. (org-match-sparse-tree nil "work")
  6330. (search-forward "H2")
  6331. (org-invisible-p2)))
  6332. ;; Match group tags with hard brackets.
  6333. (should-not
  6334. (org-test-with-temp-text
  6335. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6336. (org-match-sparse-tree nil "work")
  6337. (search-forward "H1")
  6338. (org-invisible-p2)))
  6339. (should-not
  6340. (org-test-with-temp-text
  6341. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6342. (org-match-sparse-tree nil "work")
  6343. (search-forward "H2")
  6344. (org-invisible-p2)))
  6345. ;; Match tags in hierarchies
  6346. (should-not
  6347. (org-test-with-temp-text
  6348. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6349. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6350. #+TAGS: { Lev_3 : Lev_4 }\n
  6351. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6352. (org-match-sparse-tree nil "Lev_1")
  6353. (search-forward "H4")
  6354. (org-invisible-p2)))
  6355. (should-not
  6356. (org-test-with-temp-text
  6357. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6358. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6359. #+TAGS: { Lev_3 : Lev_4 }\n
  6360. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6361. (org-match-sparse-tree nil "Lev_1+Lev_3")
  6362. (search-forward "H4")
  6363. (org-invisible-p2)))
  6364. ;; Match regular expressions in tags
  6365. (should-not
  6366. (org-test-with-temp-text
  6367. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
  6368. (org-match-sparse-tree nil "Lev")
  6369. (search-forward "H1")
  6370. (org-invisible-p2)))
  6371. (should
  6372. (org-test-with-temp-text
  6373. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
  6374. (org-match-sparse-tree nil "Lev")
  6375. (search-forward "H1")
  6376. (org-invisible-p2)))
  6377. ;; Match properties.
  6378. (should
  6379. (org-test-with-temp-text
  6380. "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
  6381. (org-match-sparse-tree nil "A=\"1\"")
  6382. (search-forward "H2")
  6383. (org-invisible-p2)))
  6384. (should-not
  6385. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6386. (org-match-sparse-tree nil "A=\"1\"")
  6387. (search-forward "H2")
  6388. (org-invisible-p2)))
  6389. ;; Case is not significant when matching properties.
  6390. (should-not
  6391. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6392. (org-match-sparse-tree nil "a=\"1\"")
  6393. (search-forward "H2")
  6394. (org-invisible-p2)))
  6395. (should-not
  6396. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
  6397. (org-match-sparse-tree nil "A=\"1\"")
  6398. (search-forward "H2")
  6399. (org-invisible-p2)))
  6400. ;; Match special LEVEL property.
  6401. (should-not
  6402. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6403. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6404. (search-forward "H1")
  6405. (org-invisible-p2)))
  6406. (should
  6407. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6408. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6409. (search-forward "H2")
  6410. (org-invisible-p2)))
  6411. ;; Comparison operators when matching properties.
  6412. (should
  6413. (org-test-with-temp-text
  6414. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6415. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6416. (search-forward "H1")
  6417. (org-invisible-p2)))
  6418. (should-not
  6419. (org-test-with-temp-text
  6420. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6421. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6422. (search-forward "H2")
  6423. (org-invisible-p2)))
  6424. ;; Regexp match on properties values.
  6425. (should-not
  6426. (org-test-with-temp-text
  6427. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6428. (org-match-sparse-tree nil "A={f.*}")
  6429. (search-forward "H1")
  6430. (org-invisible-p2)))
  6431. (should
  6432. (org-test-with-temp-text
  6433. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6434. (org-match-sparse-tree nil "A={f.*}")
  6435. (search-forward "H2")
  6436. (org-invisible-p2)))
  6437. ;; With an optional argument, limit match to TODO entries.
  6438. (should-not
  6439. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6440. (org-match-sparse-tree t "tag")
  6441. (search-forward "H1")
  6442. (org-invisible-p2)))
  6443. (should
  6444. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6445. (org-match-sparse-tree t "tag")
  6446. (search-forward "H2")
  6447. (org-invisible-p2))))
  6448. (ert-deftest test-org/occur ()
  6449. "Test `org-occur' specifications."
  6450. ;; Count number of matches.
  6451. (should
  6452. (= 1
  6453. (org-test-with-temp-text "* H\nA\n* H2"
  6454. (org-occur "A"))))
  6455. (should
  6456. (= 2
  6457. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6458. (org-occur "A"))))
  6459. ;; Test CALLBACK optional argument.
  6460. (should
  6461. (= 0
  6462. (org-test-with-temp-text "* H\nA\n* H2"
  6463. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6464. (should
  6465. (= 1
  6466. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6467. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6468. ;; Case-fold searches according to `org-occur-case-fold-search'.
  6469. (should
  6470. (= 2
  6471. (org-test-with-temp-text "Aa"
  6472. (let ((org-occur-case-fold-search t)) (org-occur "A")))))
  6473. (should
  6474. (= 2
  6475. (org-test-with-temp-text "Aa"
  6476. (let ((org-occur-case-fold-search t)) (org-occur "a")))))
  6477. (should
  6478. (= 1
  6479. (org-test-with-temp-text "Aa"
  6480. (let ((org-occur-case-fold-search nil)) (org-occur "A")))))
  6481. (should
  6482. (= 1
  6483. (org-test-with-temp-text "Aa"
  6484. (let ((org-occur-case-fold-search nil)) (org-occur "a")))))
  6485. (should
  6486. (= 1
  6487. (org-test-with-temp-text "Aa"
  6488. (let ((org-occur-case-fold-search 'smart)) (org-occur "A")))))
  6489. (should
  6490. (= 2
  6491. (org-test-with-temp-text "Aa"
  6492. (let ((org-occur-case-fold-search 'smart)) (org-occur "a"))))))
  6493. ;;; Tags
  6494. (ert-deftest test-org/tag-string-to-alist ()
  6495. "Test `org-tag-string-to-alist' specifications."
  6496. ;; Tag without selection key.
  6497. (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
  6498. ;; Tag with selection key.
  6499. (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t))))
  6500. ;; Tag group.
  6501. (should
  6502. (equal
  6503. (org-tag-string-to-alist "[ group : t1 t2 ]")
  6504. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag))))
  6505. ;; Mutually exclusive tags.
  6506. (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
  6507. '((:startgroup) ("tag1") ("tag2") (:endgroup))))
  6508. (should
  6509. (equal
  6510. (org-tag-string-to-alist "{ group : tag1 tag2 }")
  6511. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))))
  6512. (ert-deftest test-org/tag-alist-to-string ()
  6513. "Test `org-tag-alist-to-string' specifications."
  6514. (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
  6515. (should (equal (org-tag-alist-to-string '(("tag1" . ?t))) "tag1(t)"))
  6516. (should
  6517. (equal
  6518. (org-tag-alist-to-string
  6519. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6520. "[ group : t1 t2 ]"))
  6521. (should
  6522. (equal (org-tag-alist-to-string
  6523. '((:startgroup) ("tag1") ("tag2") (:endgroup)))
  6524. "{ tag1 tag2 }"))
  6525. (should
  6526. (equal
  6527. (org-tag-alist-to-string
  6528. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))
  6529. "{ group : tag1 tag2 }")))
  6530. (ert-deftest test-org/tag-alist-to-groups ()
  6531. "Test `org-tag-alist-to-groups' specifications."
  6532. (should
  6533. (equal (org-tag-alist-to-groups
  6534. '((:startgroup) ("group") (:grouptags) ("t1") ("t2") (:endgroup)))
  6535. '(("group" "t1" "t2"))))
  6536. (should
  6537. (equal
  6538. (org-tag-alist-to-groups
  6539. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6540. '(("group" "t1" "t2"))))
  6541. (should-not
  6542. (org-tag-alist-to-groups
  6543. '((:startgroup) ("group") ("t1") ("t2") (:endgroup)))))
  6544. (ert-deftest test-org/tag-align ()
  6545. "Test tags alignment."
  6546. ;; Test aligning tags with different display width.
  6547. (should
  6548. ;; 12345678901234567890
  6549. (equal "* Test :abc:"
  6550. (org-test-with-temp-text "* Test :abc:"
  6551. (let ((org-tags-column -20)
  6552. (indent-tabs-mode nil))
  6553. (org-fix-tags-on-the-fly))
  6554. (buffer-string))))
  6555. (should
  6556. ;; 12345678901234567890
  6557. (equal "* Test :日本語:"
  6558. (org-test-with-temp-text "* Test :日本語:"
  6559. (let ((org-tags-column -20)
  6560. (indent-tabs-mode nil))
  6561. (org-fix-tags-on-the-fly))
  6562. (buffer-string))))
  6563. ;; Make sure aligning tags do not skip invisible text.
  6564. (should
  6565. (equal "* [[linkx]] :tag:"
  6566. (org-test-with-temp-text "* [[link<point>]] :tag:"
  6567. (let ((org-tags-column 0))
  6568. (org-fix-tags-on-the-fly)
  6569. (insert "x")
  6570. (buffer-string)))))
  6571. ;; Aligning tags preserve position.
  6572. (should
  6573. (= 6 (org-test-with-temp-text "* 345 <point> :tag:"
  6574. (let ((org-tags-column 78)
  6575. (indent-tabs-mode nil))
  6576. (org-fix-tags-on-the-fly))
  6577. (current-column))))
  6578. ;; Aligning all tags in visible buffer.
  6579. (should
  6580. ;; 12345678901234567890
  6581. (equal (concat "* Level 1 :abc:\n"
  6582. "** Level 2 :def:")
  6583. (org-test-with-temp-text (concat "* Level 1 :abc:\n"
  6584. "** Level 2 :def:")
  6585. (let ((org-tags-column -20)
  6586. (indent-tabs-mode nil))
  6587. ;; (org-align-tags :all) must work even when the point
  6588. ;; is at the end of the buffer.
  6589. (goto-char (point-max))
  6590. (org-align-tags :all))
  6591. (buffer-string)))))
  6592. (ert-deftest test-org/get-tags ()
  6593. "Test `org-get-tags' specifications."
  6594. ;; Standard test.
  6595. (should
  6596. (equal '("foo")
  6597. (org-test-with-temp-text "* Test :foo:" (org-get-tags))))
  6598. (should
  6599. (equal '("foo" "bar")
  6600. (org-test-with-temp-text "* Test :foo:bar:" (org-get-tags))))
  6601. ;; Return nil when there is no tag.
  6602. (should-not
  6603. (org-test-with-temp-text "* Test" (org-get-tags)))
  6604. ;; Tags are inherited from parent headlines.
  6605. (should
  6606. (equal '("tag")
  6607. (let ((org-use-tag-inheritance t))
  6608. (org-test-with-temp-text "* H0 :foo:\n* H1 :tag:\n<point>** H2"
  6609. (org-get-tags)))))
  6610. ;; Tags are inherited from `org-file-tags'.
  6611. (should
  6612. (equal '("tag")
  6613. (org-test-with-temp-text "* H1"
  6614. (let ((org-file-tags '("tag"))
  6615. (org-use-tag-inheritance t))
  6616. (org-get-tags)))))
  6617. ;; Only inherited tags have the `inherited' text property.
  6618. (should
  6619. (get-text-property 0 'inherited
  6620. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6621. (let ((org-use-tag-inheritance t))
  6622. (assoc-string "foo" (org-get-tags))))))
  6623. (should-not
  6624. (get-text-property 0 'inherited
  6625. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6626. (let ((org-use-tag-inheritance t))
  6627. (assoc-string "bar" (org-get-tags))))))
  6628. ;; Obey to `org-use-tag-inheritance'.
  6629. (should-not
  6630. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6631. (let ((org-use-tag-inheritance nil))
  6632. (assoc-string "foo" (org-get-tags)))))
  6633. (should-not
  6634. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6635. (let ((org-use-tag-inheritance nil)
  6636. (org-file-tags '("foo")))
  6637. (assoc-string "foo" (org-get-tags)))))
  6638. (should-not
  6639. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6640. (let ((org-use-tag-inheritance '("bar")))
  6641. (assoc-string "foo" (org-get-tags)))))
  6642. (should
  6643. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6644. (let ((org-use-tag-inheritance '("bar")))
  6645. (assoc-string "bar" (org-get-tags)))))
  6646. (should-not
  6647. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6648. (let ((org-use-tag-inheritance "b.*"))
  6649. (assoc-string "foo" (org-get-tags)))))
  6650. (should
  6651. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6652. (let ((org-use-tag-inheritance "b.*"))
  6653. (assoc-string "bar" (org-get-tags)))))
  6654. ;; When optional argument LOCAL is non-nil, ignore tag inheritance.
  6655. (should
  6656. (equal '("baz")
  6657. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6658. (let ((org-use-tag-inheritance t))
  6659. (org-get-tags nil t)))))
  6660. ;; When optional argument POS is non-nil, get tags there instead.
  6661. (should
  6662. (equal '("foo")
  6663. (org-test-with-temp-text "* H1 :foo:\n* <point>H2 :bar:"
  6664. (org-get-tags 1))))
  6665. ;; Make sure tags excluded from inheritance are returned if local
  6666. (should
  6667. (equal '("foo")
  6668. (org-test-with-temp-text "* Test :foo:"
  6669. (let ((org-use-tag-inheritance t)
  6670. (org-tags-exclude-from-inheritance '("foo")))
  6671. (org-get-tags)))))
  6672. ;; Test the collection of tags from #+filetags and parent tags.
  6673. (should
  6674. (equal '("a" "b" "c" "d")
  6675. (org-test-with-temp-text (concat "#+filetags: a\n"
  6676. "* Level 1 :b:\n"
  6677. "** Level 2 :c:\n"
  6678. "*** Level 3 :d:\n"
  6679. "<point>")
  6680. (let ((org-use-tag-inheritance t))
  6681. (org-mode-restart) ;So that `org-file-tags' get populated from #+filetags
  6682. (org-get-tags)))))
  6683. ;; Pathological case: tagged headline with an empty body.
  6684. (should (org-test-with-temp-text "* :tag:" (org-get-tags))))
  6685. (ert-deftest test-org/set-tags ()
  6686. "Test `org-set-tags' specifications."
  6687. ;; Throw an error on invalid data.
  6688. (should-error
  6689. (org-test-with-temp-text "* H"
  6690. (org-set-tags 'foo)))
  6691. ;; `nil', an empty, and a blank string remove all tags.
  6692. (should
  6693. (equal "* H"
  6694. (org-test-with-temp-text "* H :tag1:tag2:"
  6695. (org-set-tags nil)
  6696. (buffer-string))))
  6697. (should
  6698. (equal "* H"
  6699. (org-test-with-temp-text "* H :tag1:tag2:"
  6700. (org-set-tags "")
  6701. (buffer-string))))
  6702. (should
  6703. (equal "* H"
  6704. (org-test-with-temp-text "* H :tag1:tag2:"
  6705. (org-set-tags " ")
  6706. (buffer-string))))
  6707. ;; If there's nothing to remove, just bail out.
  6708. (should
  6709. (equal "* H"
  6710. (org-test-with-temp-text "* H"
  6711. (org-set-tags nil)
  6712. (buffer-string))))
  6713. (should
  6714. (equal "* "
  6715. (org-test-with-temp-text "* "
  6716. (org-set-tags nil)
  6717. (buffer-string))))
  6718. ;; If DATA is a tag string, set current tags to it, even if it means
  6719. ;; replacing old tags.
  6720. (should
  6721. (equal "* H :tag0:"
  6722. (org-test-with-temp-text "* H :tag1:tag2:"
  6723. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  6724. (buffer-string))))
  6725. (should
  6726. (equal "* H :tag0:"
  6727. (org-test-with-temp-text "* H"
  6728. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  6729. (buffer-string))))
  6730. ;; If DATA is a list, set tags to this list, even if it means
  6731. ;; replacing old tags.
  6732. (should
  6733. (equal "* H :tag0:"
  6734. (org-test-with-temp-text "* H :tag1:tag2:"
  6735. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6736. (buffer-string))))
  6737. (should
  6738. (equal "* H :tag0:"
  6739. (org-test-with-temp-text "* H"
  6740. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6741. (buffer-string))))
  6742. ;; When set, apply `org-tags-sort-function'.
  6743. (should
  6744. (equal "* H :a:b:"
  6745. (org-test-with-temp-text "* H"
  6746. (let ((org-tags-column 1)
  6747. (org-tags-sort-function #'string<))
  6748. (org-set-tags '("b" "a"))
  6749. (buffer-string)))))
  6750. ;; When new tags are identical to the previous ones, still align.
  6751. (should
  6752. (equal "* H :foo:"
  6753. (org-test-with-temp-text "* H :foo:"
  6754. (let ((org-tags-column 1))
  6755. (org-set-tags '("foo"))
  6756. (buffer-string)))))
  6757. ;; When tags have been changed, run `org-after-tags-change-hook'.
  6758. (should
  6759. (catch :return
  6760. (org-test-with-temp-text "* H :foo:"
  6761. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  6762. (org-set-tags '("bar"))
  6763. nil))))
  6764. (should-not
  6765. (catch :return
  6766. (org-test-with-temp-text "* H :foo:"
  6767. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  6768. (org-set-tags '("foo"))
  6769. nil))))
  6770. ;; Special case: handle empty headlines.
  6771. (should
  6772. (equal "* :tag0:"
  6773. (org-test-with-temp-text "* "
  6774. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6775. (buffer-string))))
  6776. ;; Modify buffer only when a tag change happens or alignment is
  6777. ;; done.
  6778. (should-not
  6779. (org-test-with-temp-text "* H :foo:"
  6780. (set-buffer-modified-p nil)
  6781. (let ((org-tags-column 1)) (org-set-tags '("foo")))
  6782. (buffer-modified-p)))
  6783. (should
  6784. (org-test-with-temp-text "* H :foo:"
  6785. (set-buffer-modified-p nil)
  6786. (let ((org-tags-column 10)) (org-set-tags '("foo")))
  6787. (buffer-modified-p)))
  6788. (should
  6789. (org-test-with-temp-text "* H :foo:"
  6790. (set-buffer-modified-p nil)
  6791. (let ((org-tags-column 10)) (org-set-tags '("bar")))
  6792. (buffer-modified-p)))
  6793. ;; Pathological case: when setting tags of a folded headline, do not
  6794. ;; let new tags being sucked into invisibility.
  6795. (should-not
  6796. (org-test-with-temp-text "* H1\nContent\n* H2\n\n Other Content"
  6797. ;; Show only headlines
  6798. (org-content)
  6799. ;; Set NEXT tag on current entry
  6800. (org-set-tags ":NEXT:")
  6801. ;; Move point to that NEXT tag
  6802. (search-forward "NEXT") (backward-word)
  6803. ;; And it should be visible (i.e. no overlays)
  6804. (overlays-at (point)))))
  6805. (ert-deftest test-org/set-tags-command ()
  6806. "Test `org-set-tags-command' specifications"
  6807. ;; Set tags at current headline.
  6808. (should
  6809. (equal "* H1 :foo:"
  6810. (org-test-with-temp-text "* H1"
  6811. (cl-letf (((symbol-function 'completing-read-multiple)
  6812. (lambda (&rest args) '("foo"))))
  6813. (let ((org-use-fast-tag-selection nil)
  6814. (org-tags-column 1))
  6815. (org-set-tags-command)))
  6816. (buffer-string))))
  6817. ;; Preserve position when called from the section below.
  6818. (should
  6819. (equal "* H1 :foo:\nContents"
  6820. (org-test-with-temp-text "* H1\n<point>Contents"
  6821. (cl-letf (((symbol-function 'completing-read-multiple)
  6822. (lambda (&rest args) '("foo"))))
  6823. (let ((org-use-fast-tag-selection nil)
  6824. (org-tags-column 1))
  6825. (org-set-tags-command)))
  6826. (buffer-string))))
  6827. (should-not
  6828. (equal "* H1 :foo:\nContents2"
  6829. (org-test-with-temp-text "* H1\n<point>Contents2"
  6830. (cl-letf (((symbol-function 'completing-read-multiple)
  6831. (lambda (&rest args) '("foo"))))
  6832. (let ((org-use-fast-tag-selection nil)
  6833. (org-tags-column 1))
  6834. (org-set-tags-command)))
  6835. (org-at-heading-p))))
  6836. ;; When a region is active and
  6837. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  6838. ;; same value in all headlines in region.
  6839. (should
  6840. (equal "* H1 :foo:\nContents\n* H2 :foo:"
  6841. (org-test-with-temp-text "* H1\nContents\n* H2"
  6842. (cl-letf (((symbol-function 'completing-read-multiple)
  6843. (lambda (&rest args) '("foo"))))
  6844. (let ((org-use-fast-tag-selection nil)
  6845. (org-loop-over-headlines-in-active-region t)
  6846. (org-tags-column 1))
  6847. (transient-mark-mode 1)
  6848. (push-mark (point) t t)
  6849. (goto-char (point-max))
  6850. (org-set-tags-command)))
  6851. (buffer-string))))
  6852. (should
  6853. (equal "* H1\nContents\n* H2 :foo:"
  6854. (org-test-with-temp-text "* H1\nContents\n* H2"
  6855. (cl-letf (((symbol-function 'completing-read-multiple)
  6856. (lambda (&rest args) '("foo"))))
  6857. (let ((org-use-fast-tag-selection nil)
  6858. (org-loop-over-headlines-in-active-region nil)
  6859. (org-tags-column 1))
  6860. (transient-mark-mode 1)
  6861. (push-mark (point) t t)
  6862. (goto-char (point-max))
  6863. (org-set-tags-command)))
  6864. (buffer-string))))
  6865. ;; With a C-u prefix argument, align all tags in the buffer.
  6866. (should
  6867. (equal "* H1 :foo:\n* H2 :bar:"
  6868. (org-test-with-temp-text "* H1 :foo:\n* H2 :bar:"
  6869. (let ((org-tags-column 1)) (org-set-tags-command '(4)))
  6870. (buffer-string))))
  6871. ;; Point does not move with empty headline.
  6872. (should
  6873. (equal ":foo:"
  6874. (org-test-with-temp-text "* <point>"
  6875. (cl-letf (((symbol-function 'completing-read-multiple)
  6876. (lambda (&rest args) '("foo"))))
  6877. (let ((org-use-fast-tag-selection nil)
  6878. (org-tags-column 1))
  6879. (org-set-tags-command)))
  6880. (buffer-substring (point) (line-end-position)))))
  6881. ;; Point does not move at start of line.
  6882. (should
  6883. (equal "* H1 :foo:"
  6884. (org-test-with-temp-text "* H1"
  6885. (cl-letf (((symbol-function 'completing-read-multiple)
  6886. (lambda (&rest args) '("foo"))))
  6887. (let ((org-use-fast-tag-selection nil)
  6888. (org-tags-column 1))
  6889. (org-set-tags-command)))
  6890. (buffer-substring (point) (line-end-position)))))
  6891. ;; Point does not move when within *'s.
  6892. (should
  6893. (equal "* H1 :foo:"
  6894. (org-test-with-temp-text "*<point>* H1"
  6895. (cl-letf (((symbol-function 'completing-read-multiple)
  6896. (lambda (&rest args) '("foo"))))
  6897. (let ((org-use-fast-tag-selection nil)
  6898. (org-tags-column 1))
  6899. (org-set-tags-command)))
  6900. (buffer-substring (point) (line-end-position)))))
  6901. ;; Point workaround does not get fooled when looking at a space.
  6902. (should
  6903. (equal " b :foo:"
  6904. (org-test-with-temp-text "* a<point> b"
  6905. (cl-letf (((symbol-function 'completing-read-multiple)
  6906. (lambda (&rest args) '("foo"))))
  6907. (let ((org-use-fast-tag-selection nil)
  6908. (org-tags-column 1))
  6909. (org-set-tags-command)))
  6910. (buffer-substring (point) (line-end-position)))))
  6911. ;; Handle tags both set locally and inherited.
  6912. (should
  6913. (equal "b :foo:"
  6914. (org-test-with-temp-text "* a :foo:\n** <point>b :foo:"
  6915. (cl-letf (((symbol-function 'completing-read-multiple)
  6916. (lambda (prompt coll &optional pred req initial &rest args)
  6917. (list initial))))
  6918. (let ((org-use-fast-tag-selection nil)
  6919. (org-tags-column 1))
  6920. (org-set-tags-command)))
  6921. (buffer-substring (point) (line-end-position))))))
  6922. (ert-deftest test-org/toggle-tag ()
  6923. "Test `org-toggle-tag' specifications."
  6924. ;; Insert missing tag.
  6925. (should
  6926. (equal "* H :tag:"
  6927. (org-test-with-temp-text "* H"
  6928. (let ((org-tags-column 1)) (org-toggle-tag "tag"))
  6929. (buffer-string))))
  6930. (should
  6931. (equal "* H :tag1:tag2:"
  6932. (org-test-with-temp-text "* H :tag1:"
  6933. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  6934. (buffer-string))))
  6935. ;; Remove existing tag.
  6936. (should
  6937. (equal "* H"
  6938. (org-test-with-temp-text "* H :tag:"
  6939. (org-toggle-tag "tag")
  6940. (buffer-string))))
  6941. (should
  6942. (equal "* H :tag1:"
  6943. (org-test-with-temp-text "* H :tag1:tag2:"
  6944. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  6945. (buffer-string))))
  6946. (should
  6947. (equal "* H :tag2:"
  6948. (org-test-with-temp-text "* H :tag1:tag2:"
  6949. (let ((org-tags-column 1)) (org-toggle-tag "tag1"))
  6950. (buffer-string))))
  6951. ;; With optional argument ONOFF set to `on', try to insert the tag,
  6952. ;; even if its already there.
  6953. (should
  6954. (equal "* H :tag:"
  6955. (org-test-with-temp-text "* H"
  6956. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  6957. (buffer-string))))
  6958. (should
  6959. (equal "* H :tag:"
  6960. (org-test-with-temp-text "* H :tag:"
  6961. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  6962. (buffer-string))))
  6963. ;; With optional argument ONOFF set to `off', try to remove the tag,
  6964. ;; even if its not there.
  6965. (should
  6966. (equal "* H"
  6967. (org-test-with-temp-text "* H :tag:"
  6968. (org-toggle-tag "tag" 'off)
  6969. (buffer-string))))
  6970. (should
  6971. (equal "* H :tag:"
  6972. (org-test-with-temp-text "* H :tag:"
  6973. (let ((org-tags-column 1)) (org-toggle-tag "foo" 'off))
  6974. (buffer-string))))
  6975. ;; Special case: Handle properly tag inheritance. In particular, do
  6976. ;; not set inherited tags.
  6977. (should
  6978. (equal "* H1 :tag:\n** H2 :tag2:tag:"
  6979. (org-test-with-temp-text "* H1 :tag:\n** <point>H2 :tag2:"
  6980. (let ((org-use-tag-inheritance t)
  6981. (org-tags-column 1))
  6982. (org-toggle-tag "tag"))
  6983. (buffer-string))))
  6984. (should
  6985. (equal "* H1 :tag1:tag2:\n** H2 :foo:"
  6986. (org-test-with-temp-text "* H1 :tag1:tag2:\n** <point>H2"
  6987. (let ((org-use-tag-inheritance t)
  6988. (org-tags-column 1))
  6989. (org-toggle-tag "foo"))
  6990. (buffer-string)))))
  6991. (ert-deftest test-org/tags-expand ()
  6992. "Test `org-tags-expand' specifications."
  6993. ;; Expand tag groups as a regexp enclosed within curly brackets.
  6994. (should
  6995. (equal "{\\<[ABC]\\>}"
  6996. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6997. (org-mode-restart)
  6998. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  6999. (should
  7000. (equal "{\\<\\(?:Aa\\|Bb\\|Cc\\)\\>}"
  7001. (org-test-with-temp-text "#+TAGS: [ Aa : Bb Cc ]"
  7002. (org-mode-restart)
  7003. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "Aa")))))
  7004. ;; Preserve operator before the regexp.
  7005. (should
  7006. (equal "+{\\<[ABC]\\>}"
  7007. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7008. (org-mode-restart)
  7009. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "+A")))))
  7010. (should
  7011. (equal "-{\\<[ABC]\\>}"
  7012. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7013. (org-mode-restart)
  7014. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "-A")))))
  7015. ;; Handle "|" syntax.
  7016. (should
  7017. (equal "{\\<[ABC]\\>}|D"
  7018. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7019. (org-mode-restart)
  7020. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|D")))))
  7021. ;; Handle nested groups.
  7022. (should
  7023. (equal "{\\<[A-D]\\>}"
  7024. (org-test-with-temp-text "#+TAGS: [ A : B C ]\n#+TAGS: [ B : D ]"
  7025. (org-mode-restart)
  7026. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  7027. ;; Expand multiple occurrences of the same group.
  7028. (should
  7029. (equal "{\\<[ABC]\\>}|{\\<[ABC]\\>}"
  7030. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7031. (org-mode-restart)
  7032. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|A")))))
  7033. ;; Preserve regexp matches.
  7034. (should
  7035. (equal "{A+}"
  7036. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7037. (org-mode-restart)
  7038. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "{A+}"))))))
  7039. ;;; TODO keywords
  7040. (ert-deftest test-org/auto-repeat-maybe ()
  7041. "Test `org-auto-repeat-maybe' specifications."
  7042. ;; Do not auto repeat when there is no valid time stamp with
  7043. ;; a repeater in the entry.
  7044. (should-not
  7045. (string-prefix-p
  7046. "* TODO H"
  7047. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7048. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
  7049. (org-todo "DONE")
  7050. (buffer-string)))))
  7051. (should-not
  7052. (string-prefix-p
  7053. "* TODO H"
  7054. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7055. (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
  7056. (org-todo "DONE")
  7057. (buffer-string)))))
  7058. ;; When switching to DONE state, switch back to first TODO keyword
  7059. ;; in sequence, or the same keyword if they have different types.
  7060. (should
  7061. (string-prefix-p
  7062. "* TODO H"
  7063. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7064. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7065. (org-todo "DONE")
  7066. (buffer-string)))))
  7067. (should
  7068. (string-prefix-p
  7069. "* KWD1 H"
  7070. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  7071. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  7072. (org-todo "DONE")
  7073. (buffer-string)))))
  7074. (should
  7075. (string-prefix-p
  7076. "* KWD2 H"
  7077. (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
  7078. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  7079. (org-todo "DONE")
  7080. (buffer-string)))))
  7081. ;; If there was no TODO keyword in the first place, do not insert
  7082. ;; any either.
  7083. (should
  7084. (string-prefix-p
  7085. "* H"
  7086. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7087. (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
  7088. (org-todo "DONE")
  7089. (buffer-string)))))
  7090. ;; Revert to REPEAT_TO_STATE, if set.
  7091. (should
  7092. (string-prefix-p
  7093. "* KWD2 H"
  7094. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  7095. (org-test-with-temp-text
  7096. "* KWD2 H
  7097. :PROPERTIES:
  7098. :REPEAT_TO_STATE: KWD2
  7099. :END:
  7100. <2012-03-29 Thu +2y>"
  7101. (org-todo "DONE")
  7102. (buffer-string)))))
  7103. ;; When switching to DONE state, update base date. If there are
  7104. ;; multiple repeated time stamps, update them all.
  7105. (should
  7106. (string-match-p
  7107. "<2014-03-29 .* \\+2y>"
  7108. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7109. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7110. (org-todo "DONE")
  7111. (buffer-string)))))
  7112. (should
  7113. (string-match-p
  7114. "<2015-03-04 .* \\+1y>"
  7115. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7116. (org-test-with-temp-text
  7117. "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
  7118. (org-todo "DONE")
  7119. (buffer-string)))))
  7120. ;; Throw an error if repeater unit is the hour and no time is
  7121. ;; provided in the time-stamp.
  7122. (should-error
  7123. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7124. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
  7125. (org-todo "DONE")
  7126. (buffer-string))))
  7127. ;; Handle every repeater type using hours step.
  7128. (should
  7129. (string-match-p
  7130. "2014-03-04 .* 02:00"
  7131. (org-test-at-time "<2014-03-04 02:35>"
  7132. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 +8h>"
  7133. (org-todo "DONE")
  7134. (buffer-string)))))
  7135. (should
  7136. (string-match-p
  7137. "2014-03-04 .* 10:00"
  7138. (org-test-at-time "<2014-03-04 02:35>"
  7139. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 ++8h>"
  7140. (org-todo "DONE")
  7141. (buffer-string)))))
  7142. (should
  7143. (string-match-p
  7144. "2014-03-04 .* 10:35"
  7145. (org-test-at-time "<2014-03-04 02:35>"
  7146. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 .+8h>"
  7147. (org-todo "DONE")
  7148. (buffer-string)))))
  7149. ;; Do not repeat inactive time stamps with a repeater.
  7150. (should-not
  7151. (string-match-p
  7152. "\\[2014-03-29 .* \\+2y\\]"
  7153. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7154. (org-test-with-temp-text
  7155. "* TODO H\n[2012-03-29 Thu. +2y]"
  7156. (org-todo "DONE")
  7157. (buffer-string)))))
  7158. ;; Do not repeat commented time stamps.
  7159. (should-not
  7160. (string-prefix-p
  7161. "<2015-03-04 .* \\+1y>"
  7162. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7163. (org-test-with-temp-text
  7164. "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
  7165. (org-todo "DONE")
  7166. (buffer-string)))))
  7167. (should-not
  7168. (string-prefix-p
  7169. "<2015-03-04 .* \\+1y>"
  7170. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7171. (org-test-with-temp-text
  7172. "* TODO H
  7173. <2012-03-29 Thu. +2y>
  7174. #+BEGIN_EXAMPLE
  7175. <2014-03-04 Tue +1y>
  7176. #+END_EXAMPLE"
  7177. (org-todo "DONE")
  7178. (buffer-string)))))
  7179. ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
  7180. ;; entry, record time of last repeat.
  7181. (should-not
  7182. (string-match-p
  7183. ":LAST_REPEAT:"
  7184. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  7185. (org-log-repeat nil))
  7186. (cl-letf (((symbol-function 'org-add-log-setup)
  7187. (lambda (&rest args) nil)))
  7188. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  7189. (org-todo "DONE")
  7190. (buffer-string))))))
  7191. (should
  7192. (string-match-p
  7193. ":LAST_REPEAT:"
  7194. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  7195. (org-log-repeat t))
  7196. (cl-letf (((symbol-function 'org-add-log-setup)
  7197. (lambda (&rest args) nil)))
  7198. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  7199. (org-todo "DONE")
  7200. (buffer-string))))))
  7201. (should
  7202. (string-match-p
  7203. ":LAST_REPEAT:"
  7204. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7205. (cl-letf (((symbol-function 'org-add-log-setup)
  7206. (lambda (&rest args) nil)))
  7207. (org-test-with-temp-text
  7208. "* TODO H\n<2012-03-29 Thu +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
  7209. (org-todo "DONE")
  7210. (buffer-string))))))
  7211. ;; When a SCHEDULED entry has no repeater, remove it upon repeating
  7212. ;; the entry as it is no longer relevant.
  7213. (should-not
  7214. (string-match-p
  7215. "^SCHEDULED:"
  7216. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7217. (org-test-with-temp-text
  7218. "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
  7219. (org-todo "DONE")
  7220. (buffer-string)))))
  7221. ;; Properly advance repeater even when a clock entry is specified
  7222. ;; and `org-log-repeat' is nil.
  7223. (should
  7224. (string-match-p
  7225. "SCHEDULED: <2014-03-29"
  7226. (let ((org-log-repeat nil)
  7227. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7228. (org-test-with-temp-text
  7229. "* TODO H
  7230. SCHEDULED: <2012-03-29 Thu +2y>
  7231. CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] => 6:40"
  7232. (org-todo "DONE")
  7233. (buffer-string)))))
  7234. ;; Make sure that logbook state change record does not get
  7235. ;; duplicated when `org-log-repeat' `org-log-done' are non-nil.
  7236. (should
  7237. (string-match-p
  7238. (rx "* TODO Read book
  7239. SCHEDULED: <2021-06-16 Wed +1d>
  7240. :PROPERTIES:
  7241. :LAST_REPEAT:" (1+ nonl) "
  7242. :END:
  7243. - State \"DONE\" from \"TODO\"" (1+ nonl) buffer-end)
  7244. (let ((org-log-repeat 'time)
  7245. (org-todo-keywords '((sequence "TODO" "|" "DONE(d!)")))
  7246. (org-log-into-drawer nil))
  7247. (org-test-with-temp-text
  7248. "* TODO Read book
  7249. SCHEDULED: <2021-06-15 Tue +1d>"
  7250. (org-todo "DONE")
  7251. (when (memq 'org-add-log-note post-command-hook)
  7252. (org-add-log-note))
  7253. (buffer-string))))))
  7254. (ert-deftest test-org/org-log-done ()
  7255. "Test `org-log-done' specifications."
  7256. ;; nil value.
  7257. (should
  7258. (string=
  7259. "* DONE task"
  7260. (let ((org-log-done nil)
  7261. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7262. (org-test-with-temp-text
  7263. "* TODO task"
  7264. (org-todo "DONE")
  7265. (when (memq 'org-add-log-note post-command-hook)
  7266. (org-add-log-note))
  7267. (buffer-string)))))
  7268. ;; `time' value.
  7269. (should
  7270. (string=
  7271. (format
  7272. "* DONE task
  7273. CLOSED: %s"
  7274. (org-test-with-temp-text ""
  7275. (org-insert-time-stamp (current-time) t t)
  7276. (buffer-string)))
  7277. (let ((org-log-done 'time)
  7278. (org-log-done-with-time t)
  7279. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7280. (org-test-with-temp-text
  7281. "* TODO task"
  7282. (org-todo "DONE")
  7283. (when (memq 'org-add-log-note post-command-hook)
  7284. (org-add-log-note))
  7285. (buffer-string)))))
  7286. (should
  7287. (string=
  7288. (format
  7289. "* DONE task
  7290. CLOSED: %s"
  7291. (org-test-with-temp-text ""
  7292. (org-insert-time-stamp (current-time) nil t)
  7293. (buffer-string)))
  7294. (let ((org-log-done 'time)
  7295. (org-log-done-with-time nil)
  7296. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7297. (org-test-with-temp-text
  7298. "* TODO task"
  7299. (org-todo "DONE")
  7300. (when (memq 'org-add-log-note post-command-hook)
  7301. (org-add-log-note))
  7302. (buffer-string)))))
  7303. ;; TODO: Test `note' value.
  7304. ;; Test startup overrides.
  7305. (should
  7306. (string=
  7307. "#+STARTUP: nologdone
  7308. * DONE task"
  7309. (let ((org-log-done 'time)
  7310. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7311. (org-test-with-temp-text
  7312. "#+STARTUP: nologdone
  7313. <point>* TODO task"
  7314. (org-set-regexps-and-options)
  7315. (org-todo "DONE")
  7316. (when (memq 'org-add-log-note post-command-hook)
  7317. (org-add-log-note))
  7318. (buffer-string)))))
  7319. (should
  7320. (string=
  7321. (format
  7322. "#+STARTUP: logdone
  7323. * DONE task
  7324. CLOSED: %s"
  7325. (org-test-with-temp-text ""
  7326. (org-insert-time-stamp (current-time) t t)
  7327. (buffer-string)))
  7328. (let ((org-log-done nil)
  7329. (org-log-done-with-time t)
  7330. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7331. (org-test-with-temp-text
  7332. "#+STARTUP: logdone
  7333. <point>* TODO task"
  7334. (org-set-regexps-and-options)
  7335. (org-todo "DONE")
  7336. (when (memq 'org-add-log-note post-command-hook)
  7337. (org-add-log-note))
  7338. (buffer-string)))))
  7339. ;; Test local property overrides.
  7340. (should
  7341. (string=
  7342. "* DONE task
  7343. :PROPERTIES:
  7344. :LOGGING: nil
  7345. :END:"
  7346. (let ((org-log-done 'time)
  7347. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7348. (org-test-with-temp-text
  7349. "* TODO task
  7350. :PROPERTIES:
  7351. :LOGGING: nil
  7352. :END:"
  7353. (org-todo "DONE")
  7354. (when (memq 'org-add-log-note post-command-hook)
  7355. (org-add-log-note))
  7356. (buffer-string)))))
  7357. (should
  7358. (string=
  7359. (format
  7360. "* DONE task
  7361. CLOSED: %s
  7362. :PROPERTIES:
  7363. :LOGGING: logdone
  7364. :END:"
  7365. (org-test-with-temp-text ""
  7366. (org-insert-time-stamp (current-time) t t)
  7367. (buffer-string)))
  7368. (let ((org-log-done nil)
  7369. (org-log-done-with-time t)
  7370. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7371. (org-test-with-temp-text
  7372. "* TODO task
  7373. :PROPERTIES:
  7374. :LOGGING: logdone
  7375. :END:"
  7376. (org-todo "DONE")
  7377. (when (memq 'org-add-log-note post-command-hook)
  7378. (org-add-log-note))
  7379. (buffer-string))))))
  7380. ;;; Timestamps API
  7381. (ert-deftest test-org/at-timestamp-p ()
  7382. "Test `org-at-timestamp-p' specifications."
  7383. (should
  7384. (org-test-with-temp-text "<2012-03-29 Thu>"
  7385. (org-at-timestamp-p)))
  7386. (should-not
  7387. (org-test-with-temp-text "2012-03-29 Thu"
  7388. (org-at-timestamp-p)))
  7389. ;; Test return values.
  7390. (should
  7391. (eq 'bracket
  7392. (org-test-with-temp-text "<2012-03-29 Thu>"
  7393. (org-at-timestamp-p))))
  7394. (should
  7395. (eq 'year
  7396. (org-test-with-temp-text "<<point>2012-03-29 Thu>"
  7397. (org-at-timestamp-p))))
  7398. (should
  7399. (eq 'month
  7400. (org-test-with-temp-text "<2012-<point>03-29 Thu>"
  7401. (org-at-timestamp-p))))
  7402. (should
  7403. (eq 'day
  7404. (org-test-with-temp-text "<2012-03-<point>29 Thu>"
  7405. (org-at-timestamp-p))))
  7406. (should
  7407. (eq 'day
  7408. (org-test-with-temp-text "<2012-03-29 T<point>hu>"
  7409. (org-at-timestamp-p))))
  7410. (should
  7411. (wholenump
  7412. (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
  7413. (org-at-timestamp-p))))
  7414. (should
  7415. (eq 'bracket
  7416. (org-test-with-temp-text "<2012-03-29 Thu<point>>"
  7417. (org-at-timestamp-p))))
  7418. (should
  7419. (eq 'after
  7420. (org-test-with-temp-text "<2012-03-29 Thu><point>»"
  7421. (org-at-timestamp-p))))
  7422. ;; Test `inactive' optional argument.
  7423. (should
  7424. (org-test-with-temp-text "[2012-03-29 Thu]"
  7425. (org-at-timestamp-p 'inactive)))
  7426. (should-not
  7427. (org-test-with-temp-text "[2012-03-29 Thu]"
  7428. (org-at-timestamp-p)))
  7429. ;; When optional argument is `agenda', recognize time-stamps in
  7430. ;; planning info line, property drawers and clocks.
  7431. (should
  7432. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7433. (org-at-timestamp-p 'agenda)))
  7434. (should-not
  7435. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7436. (org-at-timestamp-p)))
  7437. (should
  7438. (org-test-with-temp-text
  7439. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7440. (org-at-timestamp-p 'agenda)))
  7441. (should-not
  7442. (org-test-with-temp-text
  7443. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7444. (org-at-timestamp-p)))
  7445. (should
  7446. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7447. (let ((org-agenda-include-inactive-timestamps t))
  7448. (org-at-timestamp-p 'agenda))))
  7449. (should-not
  7450. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7451. (let ((org-agenda-include-inactive-timestamps t))
  7452. (org-at-timestamp-p))))
  7453. (should-not
  7454. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7455. (let ((org-agenda-include-inactive-timestamps t))
  7456. (org-at-timestamp-p 'inactive))))
  7457. ;; When optional argument is `lax', match any part of the document
  7458. ;; with Org timestamp syntax.
  7459. (should
  7460. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7461. (org-at-timestamp-p 'lax)))
  7462. (should-not
  7463. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7464. (org-at-timestamp-p)))
  7465. (should
  7466. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7467. (org-at-timestamp-p 'lax)))
  7468. (should-not
  7469. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7470. (org-at-timestamp-p)))
  7471. (should
  7472. (org-test-with-temp-text
  7473. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7474. (org-at-timestamp-p 'lax)))
  7475. (should-not
  7476. (org-test-with-temp-text
  7477. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7478. (org-at-timestamp-p)))
  7479. ;; Optional argument `lax' also matches inactive timestamps.
  7480. (should
  7481. (org-test-with-temp-text "# [2012-03-29 Thu]<point>"
  7482. (org-at-timestamp-p 'lax))))
  7483. (ert-deftest test-org/time-stamp ()
  7484. "Test `org-time-stamp' specifications."
  7485. ;; Insert chosen time stamp at point.
  7486. (should
  7487. (string-match
  7488. "Te<2014-03-04 .*?>xt"
  7489. (org-test-with-temp-text "Te<point>xt"
  7490. (cl-letf (((symbol-function 'org-read-date)
  7491. (lambda (&rest args)
  7492. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7493. (org-time-stamp nil)
  7494. (buffer-string)))))
  7495. ;; With a prefix argument, also insert time.
  7496. (should
  7497. (string-match
  7498. "Te<2014-03-04 .*? 00:41>xt"
  7499. (org-test-with-temp-text "Te<point>xt"
  7500. (cl-letf (((symbol-function 'org-read-date)
  7501. (lambda (&rest args)
  7502. (apply #'encode-time
  7503. (org-parse-time-string "2014-03-04 00:41")))))
  7504. (org-time-stamp '(4))
  7505. (buffer-string)))))
  7506. ;; With two universal prefix arguments, insert an active timestamp
  7507. ;; with the current time without prompting the user.
  7508. (should
  7509. (string-match
  7510. "Te<2014-03-04 .*? 00:41>xt"
  7511. (org-test-with-temp-text "Te<point>xt"
  7512. (org-test-at-time "2014-03-04 00:41"
  7513. (org-time-stamp '(16))
  7514. (buffer-string)))))
  7515. ;; When optional argument is non-nil, insert an inactive timestamp.
  7516. (should
  7517. (string-match
  7518. "Te\\[2014-03-04 .*?\\]xt"
  7519. (org-test-with-temp-text "Te<point>xt"
  7520. (cl-letf (((symbol-function 'org-read-date)
  7521. (lambda (&rest args)
  7522. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7523. (org-time-stamp nil t)
  7524. (buffer-string)))))
  7525. ;; When called from a timestamp, replace existing one.
  7526. (should
  7527. (string-match
  7528. "<2014-03-04 .*?>"
  7529. (org-test-with-temp-text "<2012-03-29<point> thu.>"
  7530. (cl-letf (((symbol-function 'org-read-date)
  7531. (lambda (&rest args)
  7532. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7533. (org-time-stamp nil)
  7534. (buffer-string)))))
  7535. (should
  7536. (string-match
  7537. "<2014-03-04 .*?>--<2014-03-04 .*?>"
  7538. (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
  7539. (cl-letf (((symbol-function 'org-read-date)
  7540. (lambda (&rest args)
  7541. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7542. (org-time-stamp nil)
  7543. (buffer-string)))))
  7544. ;; When replacing a timestamp, preserve repeater, if any.
  7545. (should
  7546. (string-match
  7547. "<2014-03-04 .*? \\+2y>"
  7548. (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
  7549. (cl-letf (((symbol-function 'org-read-date)
  7550. (lambda (&rest args)
  7551. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7552. (org-time-stamp nil)
  7553. (buffer-string)))))
  7554. ;; When called twice in a raw, build a date range.
  7555. (should
  7556. (string-match
  7557. "<2012-03-29 .*?>--<2014-03-04 .*?>"
  7558. (org-test-with-temp-text "<2012-03-29 thu.><point>"
  7559. (cl-letf (((symbol-function 'org-read-date)
  7560. (lambda (&rest args)
  7561. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7562. (let ((last-command 'org-time-stamp)
  7563. (this-command 'org-time-stamp))
  7564. (org-time-stamp nil))
  7565. (buffer-string))))))
  7566. (ert-deftest test-org/timestamp-has-time-p ()
  7567. "Test `org-timestamp-has-time-p' specifications."
  7568. ;; With time.
  7569. (should
  7570. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7571. (org-timestamp-has-time-p (org-element-context))))
  7572. ;; Without time.
  7573. (should-not
  7574. (org-test-with-temp-text "<2012-03-29 Thu>"
  7575. (org-timestamp-has-time-p (org-element-context)))))
  7576. (ert-deftest test-org/get-repeat ()
  7577. "Test `org-get-repeat' specifications."
  7578. (should
  7579. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
  7580. (org-get-repeat)))
  7581. (should-not
  7582. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
  7583. (org-get-repeat)))
  7584. ;; Return proper repeat string.
  7585. (should
  7586. (equal "+2y"
  7587. (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
  7588. (org-get-repeat))))
  7589. ;; Prevent false positive (commented or verbatim time stamps)
  7590. (should-not
  7591. (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
  7592. (org-get-repeat)))
  7593. (should-not
  7594. (org-test-with-temp-text
  7595. "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
  7596. (org-get-repeat)))
  7597. ;; Return nil when called before first heading.
  7598. (should-not
  7599. (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
  7600. (org-get-repeat)))
  7601. ;; When called with an optional argument, extract repeater from that
  7602. ;; string instead.
  7603. (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
  7604. (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
  7605. (ert-deftest test-org/timestamp-format ()
  7606. "Test `org-timestamp-format' specifications."
  7607. ;; Regular test.
  7608. (should
  7609. (equal
  7610. "2012-03-29 16:40"
  7611. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7612. (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
  7613. ;; Range end.
  7614. (should
  7615. (equal
  7616. "2012-03-29"
  7617. (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
  7618. (org-timestamp-format (org-element-context) "%Y-%m-%d" t)))))
  7619. (ert-deftest test-org/timestamp-split-range ()
  7620. "Test `org-timestamp-split-range' specifications."
  7621. ;; Extract range start (active).
  7622. (should
  7623. (equal '(2012 3 29)
  7624. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7625. (let ((ts (org-timestamp-split-range (org-element-context))))
  7626. (mapcar (lambda (p) (org-element-property p ts))
  7627. '(:year-end :month-end :day-end))))))
  7628. ;; Extract range start (inactive)
  7629. (should
  7630. (equal '(2012 3 29)
  7631. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7632. (let ((ts (org-timestamp-split-range (org-element-context))))
  7633. (mapcar (lambda (p) (org-element-property p ts))
  7634. '(:year-end :month-end :day-end))))))
  7635. ;; Extract range end (active).
  7636. (should
  7637. (equal '(2012 3 30)
  7638. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7639. (let ((ts (org-timestamp-split-range
  7640. (org-element-context) t)))
  7641. (mapcar (lambda (p) (org-element-property p ts))
  7642. '(:year-end :month-end :day-end))))))
  7643. ;; Extract range end (inactive)
  7644. (should
  7645. (equal '(2012 3 30)
  7646. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7647. (let ((ts (org-timestamp-split-range
  7648. (org-element-context) t)))
  7649. (mapcar (lambda (p) (org-element-property p ts))
  7650. '(:year-end :month-end :day-end))))))
  7651. ;; Return the timestamp if not a range.
  7652. (should
  7653. (org-test-with-temp-text "[2012-03-29 Thu]"
  7654. (let* ((ts-orig (org-element-context))
  7655. (ts-copy (org-timestamp-split-range ts-orig)))
  7656. (eq ts-orig ts-copy))))
  7657. (should
  7658. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7659. (let* ((ts-orig (org-element-context))
  7660. (ts-copy (org-timestamp-split-range ts-orig)))
  7661. (eq ts-orig ts-copy)))))
  7662. (ert-deftest test-org/timestamp-translate ()
  7663. "Test `org-timestamp-translate' specifications."
  7664. ;; Translate whole date range.
  7665. (should
  7666. (equal "<29>--<30>"
  7667. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7668. (let ((org-display-custom-times t)
  7669. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7670. (org-timestamp-translate (org-element-context))))))
  7671. ;; Translate date range start.
  7672. (should
  7673. (equal "<29>"
  7674. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7675. (let ((org-display-custom-times t)
  7676. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7677. (org-timestamp-translate (org-element-context) 'start)))))
  7678. ;; Translate date range end.
  7679. (should
  7680. (equal "<30>"
  7681. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7682. (let ((org-display-custom-times t)
  7683. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7684. (org-timestamp-translate (org-element-context) 'end)))))
  7685. ;; Translate time range.
  7686. (should
  7687. (equal "<08>--<16>"
  7688. (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
  7689. (let ((org-display-custom-times t)
  7690. (org-time-stamp-custom-formats '("<%d>" . "<%H>")))
  7691. (org-timestamp-translate (org-element-context))))))
  7692. ;; Translate non-range timestamp.
  7693. (should
  7694. (equal "<29>"
  7695. (org-test-with-temp-text "<2012-03-29 Thu>"
  7696. (let ((org-display-custom-times t)
  7697. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7698. (org-timestamp-translate (org-element-context))))))
  7699. ;; Do not change `diary' timestamps.
  7700. (should
  7701. (equal "<%%(org-float t 4 2)>"
  7702. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7703. (let ((org-display-custom-times t)
  7704. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7705. (org-timestamp-translate (org-element-context)))))))
  7706. (ert-deftest test-org/timestamp-from-string ()
  7707. "Test `org-timestamp-from-string' specifications."
  7708. ;; Return nil if argument is not a valid Org timestamp.
  7709. (should-not (org-timestamp-from-string ""))
  7710. (should-not (org-timestamp-from-string nil))
  7711. (should-not (org-timestamp-from-string "<2012-03-29"))
  7712. ;; Otherwise, return a valid Org timestamp object.
  7713. (should
  7714. (string-match-p "<2012-03-29 .+>"
  7715. (org-element-interpret-data
  7716. (org-timestamp-from-string "<2012-03-29 Thu>"))))
  7717. (should
  7718. (string-match-p "[2014-03-04 .+]"
  7719. (org-element-interpret-data
  7720. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  7721. (ert-deftest test-org/timestamp-from-time ()
  7722. "Test `org-timestamp-from-time' specifications."
  7723. ;; Standard test.
  7724. (should
  7725. (string-match-p
  7726. "<2012-03-29 .+>"
  7727. (org-element-interpret-data
  7728. (org-timestamp-from-time
  7729. (apply #'encode-time
  7730. (org-parse-time-string "<2012-03-29 Thu 16:40>"))))))
  7731. ;; When optional argument WITH-TIME is non-nil, provide time
  7732. ;; information.
  7733. (should
  7734. (string-match-p
  7735. "<2012-03-29 .+ 16:40>"
  7736. (org-element-interpret-data
  7737. (org-timestamp-from-time
  7738. (apply #'encode-time
  7739. (org-parse-time-string "<2012-03-29 Thu 16:40>"))
  7740. t))))
  7741. ;; When optional argument INACTIVE is non-nil, return an inactive
  7742. ;; timestamp.
  7743. (should
  7744. (string-match-p
  7745. "[2012-03-29 .+]"
  7746. (org-element-interpret-data
  7747. (org-timestamp-from-time
  7748. (apply #'encode-time
  7749. (org-parse-time-string "<2012-03-29 Thu 16:40>"))
  7750. nil t)))))
  7751. (ert-deftest test-org/timestamp-to-time ()
  7752. "Test `org-timestamp-to-time' specifications."
  7753. (should
  7754. (equal "2014-03-04"
  7755. (format-time-string
  7756. "%Y-%m-%d"
  7757. (org-timestamp-to-time
  7758. (org-timestamp-from-string "<2014-03-04 Tue>")))))
  7759. (should
  7760. (equal "2014-03-04"
  7761. (format-time-string
  7762. "%Y-%m-%d"
  7763. (org-timestamp-to-time
  7764. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  7765. (should
  7766. (equal "2012-03-29 08:30"
  7767. (format-time-string
  7768. "%Y-%m-%d %H:%M"
  7769. (org-timestamp-to-time
  7770. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")))))
  7771. (should
  7772. (equal "2012-03-29"
  7773. (format-time-string
  7774. "%Y-%m-%d"
  7775. (org-timestamp-to-time
  7776. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")))))
  7777. (should
  7778. (equal "2012-03-29"
  7779. (format-time-string
  7780. "%Y-%m-%d"
  7781. (org-timestamp-to-time
  7782. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")))))
  7783. ;; When optional argument END is non-nil, use end of date range or
  7784. ;; time range.
  7785. (should
  7786. (equal "2012-03-29 16:40"
  7787. (format-time-string
  7788. "%Y-%m-%d %H:%M"
  7789. (org-timestamp-to-time
  7790. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")
  7791. t))))
  7792. (should
  7793. (equal "2014-03-04"
  7794. (format-time-string
  7795. "%Y-%m-%d"
  7796. (org-timestamp-to-time
  7797. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")
  7798. t))))
  7799. (should
  7800. (equal "2014-03-04"
  7801. (format-time-string
  7802. "%Y-%m-%d"
  7803. (org-timestamp-to-time
  7804. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")
  7805. t)))))
  7806. ;;; Visibility
  7807. (ert-deftest test-org/hide-drawer-toggle ()
  7808. "Test `org-hide-drawer-toggle' specifications."
  7809. ;; Error when not at a drawer.
  7810. (should-error
  7811. (org-test-with-temp-text ":fake-drawer:\ncontents"
  7812. (org-hide-drawer-toggle 'off)
  7813. (get-char-property (line-end-position) 'invisible)))
  7814. (should-error
  7815. (org-test-with-temp-text
  7816. "#+begin_example\n<point>:D:\nc\n:END:\n#+end_example"
  7817. (org-hide-drawer-toggle t)))
  7818. ;; Hide drawer.
  7819. (should
  7820. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7821. (org-hide-drawer-toggle)
  7822. (get-char-property (line-end-position) 'invisible)))
  7823. ;; Show drawer unconditionally when optional argument is `off'.
  7824. (should-not
  7825. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7826. (org-hide-drawer-toggle)
  7827. (org-hide-drawer-toggle 'off)
  7828. (get-char-property (line-end-position) 'invisible)))
  7829. ;; Hide drawer unconditionally when optional argument is non-nil.
  7830. (should
  7831. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7832. (org-hide-drawer-toggle t)
  7833. (get-char-property (line-end-position) 'invisible)))
  7834. ;; Do not hide drawer when called from final blank lines.
  7835. (should-not
  7836. (org-test-with-temp-text ":drawer:\ncontents\n:end:\n\n<point>"
  7837. (org-hide-drawer-toggle)
  7838. (goto-char (point-min))
  7839. (get-char-property (line-end-position) 'invisible)))
  7840. ;; Don't leave point in an invisible part of the buffer when hiding
  7841. ;; a drawer away.
  7842. (should-not
  7843. (org-test-with-temp-text ":drawer:\ncontents\n<point>:end:"
  7844. (org-hide-drawer-toggle)
  7845. (get-char-property (point) 'invisible))))
  7846. (ert-deftest test-org/hide-block-toggle ()
  7847. "Test `org-hide-block-toggle' specifications."
  7848. ;; Error when not at a block.
  7849. (should-error
  7850. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
  7851. (org-hide-block-toggle 'off)
  7852. (get-char-property (line-end-position) 'invisible)))
  7853. ;; Hide block.
  7854. (should
  7855. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  7856. (org-hide-block-toggle)
  7857. (get-char-property (line-end-position) 'invisible)))
  7858. (should
  7859. (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
  7860. (org-hide-block-toggle)
  7861. (get-char-property (line-end-position) 'invisible)))
  7862. ;; Show block unconditionally when optional argument is `off'.
  7863. (should-not
  7864. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7865. (org-hide-block-toggle)
  7866. (org-hide-block-toggle 'off)
  7867. (get-char-property (line-end-position) 'invisible)))
  7868. (should-not
  7869. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7870. (org-hide-block-toggle 'off)
  7871. (get-char-property (line-end-position) 'invisible)))
  7872. ;; Hide block unconditionally when optional argument is non-nil.
  7873. (should
  7874. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7875. (org-hide-block-toggle t)
  7876. (get-char-property (line-end-position) 'invisible)))
  7877. (should
  7878. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7879. (org-hide-block-toggle)
  7880. (org-hide-block-toggle t)
  7881. (get-char-property (line-end-position) 'invisible)))
  7882. ;; Do not hide block when called from final blank lines.
  7883. (should-not
  7884. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
  7885. (org-hide-block-toggle)
  7886. (goto-char (point-min))
  7887. (get-char-property (line-end-position) 'invisible)))
  7888. ;; Don't leave point in an invisible part of the buffer when hiding
  7889. ;; a block away.
  7890. (should-not
  7891. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
  7892. (org-hide-block-toggle)
  7893. (get-char-property (point) 'invisible))))
  7894. (ert-deftest test-org/hide-block-toggle-maybe ()
  7895. "Test `org-hide-block-toggle-maybe' specifications."
  7896. (should
  7897. (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
  7898. (org-hide-block-toggle-maybe)))
  7899. (should-not
  7900. (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
  7901. (ert-deftest test-org/show-set-visibility ()
  7902. "Test `org-show-set-visibility' specifications."
  7903. ;; Do not throw an error before first heading.
  7904. (should
  7905. (org-test-with-temp-text "Preamble\n* Headline"
  7906. (org-show-set-visibility 'tree)
  7907. t))
  7908. ;; Test all visibility spans, both on headline and in entry.
  7909. (let ((list-visible-lines
  7910. (lambda (state headerp)
  7911. (org-test-with-temp-text "* Grandmother (0)
  7912. ** Uncle (1)
  7913. *** Heir (2)
  7914. ** Father (3)
  7915. Ancestor text (4)
  7916. *** Sister (5)
  7917. Sibling text (6)
  7918. *** Self (7)
  7919. Match (8)
  7920. **** First born (9)
  7921. Child text (10)
  7922. **** The other child (11)
  7923. *** Brother (12)
  7924. ** Aunt (13)
  7925. "
  7926. (org-cycle t)
  7927. (search-forward (if headerp "Self" "Match"))
  7928. (org-show-set-visibility state)
  7929. (goto-char (point-min))
  7930. (let (result (line 0))
  7931. (while (not (eobp))
  7932. (unless (org-invisible-p2) (push line result))
  7933. (cl-incf line)
  7934. (forward-line))
  7935. (nreverse result))))))
  7936. (should (equal '(0 7) (funcall list-visible-lines 'minimal t)))
  7937. (should (equal '(0 7 8) (funcall list-visible-lines 'minimal nil)))
  7938. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local t)))
  7939. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local nil)))
  7940. (should (equal '(0 3 7) (funcall list-visible-lines 'ancestors t)))
  7941. (should (equal '(0 3 7 8) (funcall list-visible-lines 'ancestors nil)))
  7942. (should (equal '(0 3 7 8 9 10 11)
  7943. (funcall list-visible-lines 'ancestors-full t)))
  7944. (should (equal '(0 3 7 8 9 10 11)
  7945. (funcall list-visible-lines 'ancestors-full nil)))
  7946. (should (equal '(0 3 5 7 12) (funcall list-visible-lines 'lineage t)))
  7947. (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines 'lineage nil)))
  7948. (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines 'tree t)))
  7949. (should (equal '(0 1 3 5 7 8 9 11 12 13)
  7950. (funcall list-visible-lines 'tree nil)))
  7951. (should (equal '(0 1 3 4 5 7 12 13)
  7952. (funcall list-visible-lines 'canonical t)))
  7953. (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
  7954. (funcall list-visible-lines 'canonical nil))))
  7955. ;; When point is hidden in a drawer or a block, make sure to make it
  7956. ;; visible.
  7957. (should-not
  7958. (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
  7959. (org-hide-block-toggle)
  7960. (search-forward "Text")
  7961. (org-show-set-visibility 'minimal)
  7962. (org-invisible-p2)))
  7963. (should-not
  7964. (org-test-with-temp-text ":DRAWER:\nText\n:END:"
  7965. (org-hide-drawer-toggle)
  7966. (search-forward "Text")
  7967. (org-show-set-visibility 'minimal)
  7968. (org-invisible-p2)))
  7969. (should-not
  7970. (org-test-with-temp-text
  7971. "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
  7972. (org-hide-drawer-toggle)
  7973. (forward-line -1)
  7974. (org-hide-block-toggle)
  7975. (search-forward "Text")
  7976. (org-show-set-visibility 'minimal)
  7977. (org-invisible-p2))))
  7978. (defun test-org/copy-visible ()
  7979. "Test `org-copy-visible' specifications."
  7980. (should
  7981. (equal "Foo"
  7982. (org-test-with-temp-text "Foo"
  7983. (let ((kill-ring nil))
  7984. (org-copy-visible (point-min) (point-max))
  7985. (current-kill 0 t)))))
  7986. ;; Skip invisible characters by text property.
  7987. (should
  7988. (equal "Foo"
  7989. (org-test-with-temp-text #("F<hidden>oo" 1 7 (invisible t))
  7990. (let ((kill-ring nil))
  7991. (org-copy-visible (point-min) (point-max))
  7992. (current-kill 0 t)))))
  7993. ;; Skip invisible characters by overlay.
  7994. (should
  7995. (equal "Foo"
  7996. (org-test-with-temp-text "F<hidden>oo"
  7997. (let ((o (make-overlay 2 10)))
  7998. (overlay-put o 'invisible t))
  7999. (let ((kill-ring nil))
  8000. (org-copy-visible (point-min) (point-max))
  8001. (current-kill 0 t)))))
  8002. ;; Handle invisible characters at the beginning and the end of the
  8003. ;; buffer.
  8004. (should
  8005. (equal "Foo"
  8006. (org-test-with-temp-text #("<hidden>Foo" 0 8 (invisible t))
  8007. (let ((kill-ring nil))
  8008. (org-copy-visible (point-min) (point-max))
  8009. (current-kill 0 t)))))
  8010. (should
  8011. (equal "Foo"
  8012. (org-test-with-temp-text #("Foo<hidden>" 3 11 (invisible t))
  8013. (let ((kill-ring nil))
  8014. (org-copy-visible (point-min) (point-max))
  8015. (current-kill 0 t)))))
  8016. ;; Handle multiple visible parts.
  8017. (should
  8018. (equal "abc"
  8019. (org-test-with-temp-text
  8020. #("aXbXc" 1 2 (invisible t) 3 4 (invisible t))
  8021. (let ((kill-ring nil))
  8022. (org-copy-visible (point-min) (point-max))
  8023. (current-kill 0 t))))))
  8024. (ert-deftest test-org/set-visibility-according-to-property ()
  8025. "Test `org-set-visibility-according-to-property' specifications."
  8026. ;; "folded" state.
  8027. (should
  8028. (org-test-with-temp-text
  8029. "
  8030. * a
  8031. :PROPERTIES:
  8032. :VISIBILITY: folded
  8033. :END:
  8034. ** <point>b"
  8035. (org-set-visibility-according-to-property)
  8036. (invisible-p (point))))
  8037. ;; "children" state.
  8038. (should
  8039. (org-test-with-temp-text
  8040. "
  8041. * a
  8042. :PROPERTIES:
  8043. :VISIBILITY: children
  8044. :END:
  8045. ** b
  8046. <point>Contents
  8047. ** c"
  8048. (org-set-visibility-according-to-property)
  8049. (invisible-p (point))))
  8050. (should
  8051. (org-test-with-temp-text
  8052. "
  8053. * a
  8054. :PROPERTIES:
  8055. :VISIBILITY: children
  8056. :END:
  8057. ** b
  8058. Contents
  8059. *** <point>c"
  8060. (org-set-visibility-according-to-property)
  8061. (invisible-p (point))))
  8062. ;; "content" state.
  8063. (should
  8064. (org-test-with-temp-text
  8065. "
  8066. * a
  8067. :PROPERTIES:
  8068. :VISIBILITY: content
  8069. :END:
  8070. ** b
  8071. <point>Contents
  8072. *** c"
  8073. (org-set-visibility-according-to-property)
  8074. (invisible-p (point))))
  8075. (should
  8076. (org-test-with-temp-text
  8077. "
  8078. * a
  8079. :PROPERTIES:
  8080. :VISIBILITY: content
  8081. :END:
  8082. ** b
  8083. Contents
  8084. *** <point>c"
  8085. (org-set-visibility-according-to-property)
  8086. (not (invisible-p (point)))))
  8087. ;; "showall" state.
  8088. (should
  8089. (org-test-with-temp-text
  8090. "
  8091. * a
  8092. :PROPERTIES:
  8093. :VISIBILITY: showall
  8094. :END:
  8095. ** b
  8096. <point>Contents
  8097. *** c"
  8098. (org-set-visibility-according-to-property)
  8099. (not (invisible-p (point)))))
  8100. (should
  8101. (org-test-with-temp-text
  8102. "
  8103. * a
  8104. :PROPERTIES:
  8105. :VISIBILITY: showall
  8106. :END:
  8107. ** b
  8108. Contents
  8109. *** <point>c"
  8110. (org-set-visibility-according-to-property)
  8111. (not (invisible-p (point)))))
  8112. ;; When VISIBILITY properties are nested, ignore inner ones.
  8113. (should
  8114. (org-test-with-temp-text
  8115. "
  8116. * A
  8117. :PROPERTIES:
  8118. :VISIBILITY: folded
  8119. :END:
  8120. ** <point>B
  8121. :PROPERTIES:
  8122. :VISIBILITY: folded
  8123. :END:"
  8124. (org-set-visibility-according-to-property)
  8125. (invisible-p (point)))))
  8126. (ert-deftest test-org/visibility-show-branches ()
  8127. "Test visibility of inline archived subtrees."
  8128. (org-test-with-temp-text
  8129. "* Foo<point>
  8130. ** Bar :ARCHIVE:
  8131. *** Baz
  8132. "
  8133. (org-kill-note-or-show-branches)
  8134. (should (org-invisible-p (- (point-max) 2)))))
  8135. ;;; Yank and Kill
  8136. (ert-deftest test-org/paste-subtree ()
  8137. "Test `org-paste-subtree' specifications."
  8138. ;; Return an error if text to yank is not a set of subtrees.
  8139. (should-error (org-paste-subtree nil "Text"))
  8140. ;; Adjust level according to current one.
  8141. (should
  8142. (equal "* H\n* Text\n"
  8143. (org-test-with-temp-text "* H\n<point>"
  8144. (org-paste-subtree nil "* Text")
  8145. (buffer-string))))
  8146. (should
  8147. (equal "* H1\n** H2\n** Text\n"
  8148. (org-test-with-temp-text "* H1\n** H2\n<point>"
  8149. (org-paste-subtree nil "* Text")
  8150. (buffer-string))))
  8151. ;; When not on a heading, move to next heading before yanking.
  8152. (should
  8153. (equal "* H1\nParagraph\n* Text\n* H2"
  8154. (org-test-with-temp-text "* H1\n<point>Paragraph\n* H2"
  8155. (org-paste-subtree nil "* Text")
  8156. (buffer-string))))
  8157. ;; If point is between two headings, use the deepest level.
  8158. (should
  8159. (equal "* H1\n\n* Text\n* H2"
  8160. (org-test-with-temp-text "* H1\n<point>\n* H2"
  8161. (org-paste-subtree nil "* Text")
  8162. (buffer-string))))
  8163. (should
  8164. (equal "** H1\n\n** Text\n* H2"
  8165. (org-test-with-temp-text "** H1\n<point>\n* H2"
  8166. (org-paste-subtree nil "* Text")
  8167. (buffer-string))))
  8168. (should
  8169. (equal "* H1\n\n** Text\n** H2"
  8170. (org-test-with-temp-text "* H1\n<point>\n** H2"
  8171. (org-paste-subtree nil "* Text")
  8172. (buffer-string))))
  8173. ;; When on an empty heading, after the stars, deduce the new level
  8174. ;; from the number of stars.
  8175. (should
  8176. (equal "*** Text\n"
  8177. (org-test-with-temp-text "*** <point>"
  8178. (org-paste-subtree nil "* Text")
  8179. (buffer-string))))
  8180. ;; Optional argument LEVEL forces a level for the subtree.
  8181. (should
  8182. (equal "* H\n*** Text\n"
  8183. (org-test-with-temp-text "* H<point>"
  8184. (org-paste-subtree 3 "* Text")
  8185. (buffer-string)))))
  8186. (ert-deftest test-org/cut-and-paste-subtree ()
  8187. "Test `org-cut-subtree' and `org-paste-subtree'."
  8188. (should
  8189. (equal
  8190. "* Two
  8191. two
  8192. * One
  8193. "
  8194. (org-test-with-temp-text
  8195. "* One
  8196. <point>* Two
  8197. two
  8198. "
  8199. (call-interactively #'org-cut-subtree)
  8200. (goto-char (point-min))
  8201. (call-interactively #'org-paste-subtree)
  8202. (buffer-string))))
  8203. (should
  8204. (equal
  8205. "* One
  8206. * Two
  8207. "
  8208. (org-test-with-temp-text
  8209. "* One
  8210. <point>* Two
  8211. "
  8212. (call-interactively #'org-cut-subtree)
  8213. (backward-char)
  8214. (call-interactively #'org-paste-subtree)
  8215. (buffer-string)))))
  8216. (provide 'test-org)
  8217. ;;; test-org.el ends here