test-org.el 271 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334
  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. (org-time-string-to-time "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. (org-time-string-to-time "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. (org-time-string-to-time "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. (org-time-string-to-time "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 -1 nil)))
  255. (should (equal (org-parse-time-string "[2012-03-29 16:40]")
  256. '(0 40 16 29 3 2012 nil -1 nil)))
  257. (should (equal (org-parse-time-string "<2012-03-29 16:40>")
  258. '(0 40 16 29 3 2012 nil -1 nil)))
  259. (should (equal (org-parse-time-string "<2012-03-29>")
  260. '(0 0 0 29 3 2012 nil -1 nil)))
  261. (should (equal (org-parse-time-string "<2012-03-29>" t)
  262. '(0 nil nil 29 3 2012 nil -1 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. ;; Fill every list item in a region
  741. (should
  742. (equal "\n- 2345678\n 9\n- 2345678\n 9"
  743. (org-test-with-temp-text "\n- 2345678 9\n- 2345678 9"
  744. (let ((fill-column 10))
  745. (transient-mark-mode 1)
  746. (push-mark (point-min) t t)
  747. (goto-char (point-max))
  748. (call-interactively #'org-fill-paragraph)
  749. (buffer-string)))))
  750. (should
  751. (equal "\n- 2345678\n 9\n- 2345678"
  752. (org-test-with-temp-text "\n- 2345678 9\n- 2345678"
  753. (let ((fill-column 10))
  754. (transient-mark-mode 1)
  755. (push-mark (point-min) t t)
  756. (goto-char (point-max))
  757. (call-interactively #'org-fill-paragraph)
  758. (buffer-string))))))
  759. (ert-deftest test-org/fill-region ()
  760. "Test `fill-region' behaviour."
  761. ;; fill-region should fill every item of a list
  762. (should
  763. (equal "\n- 2345678\n 9\n- 2345678\n 9"
  764. (org-test-with-temp-text "\n- 2345678 9\n- 2345678 9"
  765. (let ((fill-column 10))
  766. (transient-mark-mode 1)
  767. (push-mark (point-min) t t)
  768. (goto-char (point-max))
  769. (call-interactively #'fill-region)
  770. (buffer-string)))))
  771. (should
  772. (equal "\n- 1 2\n- 1 2"
  773. (org-test-with-temp-text "\n- 1\n 2\n- 1\n 2"
  774. (let ((fill-column 10))
  775. (transient-mark-mode 1)
  776. (push-mark (point-min) t t)
  777. (goto-char (point-max))
  778. (call-interactively #'fill-region)
  779. (buffer-string))))) )
  780. (ert-deftest test-org/auto-fill-function ()
  781. "Test auto-filling features."
  782. ;; Auto fill paragraph.
  783. (should
  784. (equal "12345\n7890"
  785. (org-test-with-temp-text "12345 7890"
  786. (let ((fill-column 5))
  787. (end-of-line)
  788. (org-auto-fill-function)
  789. (buffer-string)))))
  790. ;; Auto fill first paragraph in an item.
  791. (should
  792. (equal "- 12345\n 7890"
  793. (org-test-with-temp-text "- 12345 7890"
  794. (let ((fill-column 7))
  795. (end-of-line)
  796. (org-auto-fill-function)
  797. (buffer-string)))))
  798. ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
  799. (should
  800. (equal "> 12345\n 7890"
  801. (org-test-with-temp-text "> 12345 7890"
  802. (let ((fill-column 10)
  803. (adaptive-fill-regexp "[ \t]*>+[ \t]*")
  804. (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
  805. (end-of-line)
  806. (org-auto-fill-function)
  807. (buffer-string)))))
  808. (should
  809. (equal "> 12345\n> 12345\n> 7890"
  810. (org-test-with-temp-text "> 12345\n> 12345 7890"
  811. (let ((fill-column 10)
  812. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  813. (goto-char (point-max))
  814. (org-auto-fill-function)
  815. (buffer-string)))))
  816. (should-not
  817. (equal " 12345\n *12345\n *12345"
  818. (org-test-with-temp-text " 12345\n *12345 12345"
  819. (let ((fill-column 10)
  820. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  821. (goto-char (point-max))
  822. (org-auto-fill-function)
  823. (buffer-string)))))
  824. ;; Auto fill comments.
  825. (should
  826. (equal " # 12345\n # 7890"
  827. (org-test-with-temp-text " # 12345 7890"
  828. (let ((fill-column 10))
  829. (end-of-line)
  830. (org-auto-fill-function)
  831. (buffer-string)))))
  832. ;; A hash within a line isn't a comment.
  833. (should-not
  834. (equal "12345 # 7890\n# 1"
  835. (org-test-with-temp-text "12345 # 7890 1"
  836. (let ((fill-column 12))
  837. (end-of-line)
  838. (org-auto-fill-function)
  839. (buffer-string)))))
  840. ;; Correctly interpret empty prefix.
  841. (should-not
  842. (equal "# a\n# b\nRegular\n# paragraph"
  843. (org-test-with-temp-text "# a\n# b\nRegular paragraph"
  844. (let ((fill-column 12))
  845. (end-of-line 3)
  846. (org-auto-fill-function)
  847. (buffer-string)))))
  848. ;; Comment block: auto fill contents.
  849. (should
  850. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  851. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  852. (let ((fill-column 5))
  853. (forward-line)
  854. (end-of-line)
  855. (org-auto-fill-function)
  856. (buffer-string)))))
  857. (should
  858. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  859. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  860. (let ((fill-column 5))
  861. (forward-line)
  862. (end-of-line)
  863. (org-auto-fill-function)
  864. (buffer-string)))))
  865. ;; Do not fill if a new item could be created.
  866. (should-not
  867. (equal "12345\n- 90"
  868. (org-test-with-temp-text "12345 - 90"
  869. (let ((fill-column 5))
  870. (end-of-line)
  871. (org-auto-fill-function)
  872. (buffer-string)))))
  873. ;; Do not fill if a line break could be introduced.
  874. (should-not
  875. (equal "123\\\\\n7890"
  876. (org-test-with-temp-text "123\\\\ 7890"
  877. (let ((fill-column 6))
  878. (end-of-line)
  879. (org-auto-fill-function)
  880. (buffer-string)))))
  881. ;; Do not fill affiliated keywords.
  882. (should-not
  883. (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
  884. (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
  885. (let ((fill-column 20))
  886. (end-of-line)
  887. (org-auto-fill-function)
  888. (buffer-string))))))
  889. ;;; Indentation
  890. (ert-deftest test-org/indent-line ()
  891. "Test `org-indent-line' specifications."
  892. ;; Do not indent diary sexps, footnote definitions or headlines.
  893. (should
  894. (zerop
  895. (org-test-with-temp-text "%%(org-calendar-holiday)"
  896. (org-indent-line)
  897. (org-get-indentation))))
  898. (should
  899. (zerop
  900. (org-test-with-temp-text "[fn:1] fn"
  901. (let ((org-adapt-indentation t)) (org-indent-line))
  902. (org-get-indentation))))
  903. (should
  904. (zerop
  905. (org-test-with-temp-text "* H"
  906. (org-indent-line)
  907. (org-get-indentation))))
  908. ;; Do not indent before first headline.
  909. (should
  910. (zerop
  911. (org-test-with-temp-text ""
  912. (org-indent-line)
  913. (org-get-indentation))))
  914. ;; Indent according to headline level otherwise, unless
  915. ;; `org-adapt-indentation' is nil.
  916. (should
  917. (= 2
  918. (org-test-with-temp-text "* H\n<point>A"
  919. (let ((org-adapt-indentation t)) (org-indent-line))
  920. (org-get-indentation))))
  921. (should
  922. (= 2
  923. (org-test-with-temp-text "* H\n<point>\nA"
  924. (let ((org-adapt-indentation t)) (org-indent-line))
  925. (org-get-indentation))))
  926. (should
  927. (zerop
  928. (org-test-with-temp-text "* H\n<point>A"
  929. (let ((org-adapt-indentation nil)) (org-indent-line))
  930. (org-get-indentation))))
  931. ;; Indenting preserves point position.
  932. (should
  933. (org-test-with-temp-text "* H\nA<point>B"
  934. (let ((org-adapt-indentation t)) (org-indent-line))
  935. (looking-at "B")))
  936. ;; Do not change indentation at an item or a LaTeX environment.
  937. (should
  938. (= 1
  939. (org-test-with-temp-text "* H\n<point> - A"
  940. (let ((org-adapt-indentation t)) (org-indent-line))
  941. (org-get-indentation))))
  942. (should
  943. (= 1
  944. (org-test-with-temp-text
  945. "\\begin{equation}\n <point>1+1=2\n\\end{equation}"
  946. (org-indent-line)
  947. (org-get-indentation))))
  948. ;; On blank lines at the end of a list, indent like last element
  949. ;; within it if the line is still in the list. If the last element
  950. ;; is an item, indent like its contents. Otherwise, indent like the
  951. ;; whole list.
  952. (should
  953. (= 4
  954. (org-test-with-temp-text "* H\n- A\n - AA\n<point>"
  955. (let ((org-adapt-indentation t)) (org-indent-line))
  956. (org-get-indentation))))
  957. (should
  958. (= 4
  959. (org-test-with-temp-text "* H\n- A\n -\n\n<point>"
  960. (let ((org-adapt-indentation t)) (org-indent-line))
  961. (org-get-indentation))))
  962. (should
  963. (zerop
  964. (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n<point>"
  965. (let ((org-adapt-indentation t)) (org-indent-line))
  966. (org-get-indentation))))
  967. (should
  968. (= 4
  969. (org-test-with-temp-text "* H\n- A\n - \n<point>"
  970. (let ((org-adapt-indentation t)) (org-indent-line))
  971. (org-get-indentation))))
  972. (should
  973. (= 4
  974. (org-test-with-temp-text
  975. "* H\n - \n #+BEGIN_SRC emacs-lisp\n t\n #+END_SRC\n<point>"
  976. (let ((org-adapt-indentation t)) (org-indent-line))
  977. (org-get-indentation))))
  978. (should
  979. (= 2
  980. (org-test-with-temp-text "- A\n B\n\n<point>"
  981. (let ((org-adapt-indentation nil)) (org-indent-line))
  982. (org-get-indentation))))
  983. (should
  984. (= 2
  985. (org-test-with-temp-text
  986. "- A\n \begin{cases} 1 + 1\n \end{cases}\n\n<point>"
  987. (let ((org-adapt-indentation nil)) (org-indent-line))
  988. (org-get-indentation))))
  989. ;; Likewise, on a blank line at the end of a footnote definition,
  990. ;; indent at column 0 if line belongs to the definition. Otherwise,
  991. ;; indent like the definition itself.
  992. (should
  993. (zerop
  994. (org-test-with-temp-text "* H\n[fn:1] Definition\n<point>"
  995. (let ((org-adapt-indentation t)) (org-indent-line))
  996. (org-get-indentation))))
  997. (should
  998. (zerop
  999. (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n<point>"
  1000. (let ((org-adapt-indentation t)) (org-indent-line))
  1001. (org-get-indentation))))
  1002. ;; After the end of the contents of a greater element, indent like
  1003. ;; the beginning of the element.
  1004. (should
  1005. (= 1
  1006. (org-test-with-temp-text
  1007. " #+BEGIN_CENTER\n Contents\n<point>#+END_CENTER"
  1008. (org-indent-line)
  1009. (org-get-indentation))))
  1010. ;; On blank lines after a paragraph, indent like its last non-empty
  1011. ;; line.
  1012. (should
  1013. (= 1
  1014. (org-test-with-temp-text " Paragraph\n\n<point>"
  1015. (org-indent-line)
  1016. (org-get-indentation))))
  1017. ;; At the first line of an element, indent like previous element's
  1018. ;; first line, ignoring footnotes definitions and inline tasks, or
  1019. ;; according to parent.
  1020. (let ((org-adapt-indentation t))
  1021. (should
  1022. (= 2
  1023. (org-test-with-temp-text "A\n\n B\n\nC<point>"
  1024. (org-indent-line)
  1025. (org-get-indentation))))
  1026. (should
  1027. (= 1
  1028. (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC<point>"
  1029. (org-indent-line)
  1030. (org-get-indentation))))
  1031. (should
  1032. (= 1
  1033. (org-test-with-temp-text
  1034. " #+BEGIN_CENTER\n<point> Contents\n#+END_CENTER"
  1035. (org-indent-line)
  1036. (org-get-indentation)))))
  1037. ;; Within code part of a source block, use language major mode if
  1038. ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
  1039. ;; according to line above.
  1040. (should
  1041. (= 6
  1042. (org-test-with-temp-text
  1043. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  1044. (let ((org-src-tab-acts-natively t)
  1045. (org-edit-src-content-indentation 0))
  1046. (org-indent-line))
  1047. (org-get-indentation))))
  1048. (should
  1049. (= 1
  1050. (org-test-with-temp-text
  1051. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  1052. (let ((org-src-tab-acts-natively nil)
  1053. (org-edit-src-content-indentation 0))
  1054. (org-indent-line))
  1055. (org-get-indentation))))
  1056. ;; Otherwise, indent like the first non-blank line above.
  1057. (should
  1058. (zerop
  1059. (org-test-with-temp-text
  1060. "#+BEGIN_CENTER\nline1\n\n<point> line2\n#+END_CENTER"
  1061. (org-indent-line)
  1062. (org-get-indentation))))
  1063. ;; Align node properties according to `org-property-format'. Handle
  1064. ;; nicely empty values.
  1065. (should
  1066. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1067. (org-test-with-temp-text
  1068. "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
  1069. (let ((org-property-format "%-10s %s")) (org-indent-line))
  1070. (buffer-string))))
  1071. (should
  1072. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1073. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
  1074. (let ((org-property-format "%-10s %s")) (org-indent-line))
  1075. (buffer-string)))))
  1076. (ert-deftest test-org/indent-region ()
  1077. "Test `org-indent-region' specifications."
  1078. ;; Indent paragraph.
  1079. (let ((org-adapt-indentation t))
  1080. (should
  1081. (equal "A\nB\nC"
  1082. (org-test-with-temp-text " A\nB\n C"
  1083. (org-indent-region (point-min) (point-max))
  1084. (buffer-string)))))
  1085. ;; Indent greater elements along with their contents.
  1086. (should
  1087. (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
  1088. (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
  1089. (org-indent-region (point-min) (point-max))
  1090. (buffer-string))))
  1091. ;; Ignore contents of verse blocks. Only indent block delimiters.
  1092. (should
  1093. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1094. (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1095. (org-indent-region (point-min) (point-max))
  1096. (buffer-string))))
  1097. (let ((org-adapt-indentation t))
  1098. (should
  1099. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1100. (org-test-with-temp-text " #+BEGIN_VERSE\n A\n B\n #+END_VERSE"
  1101. (org-indent-region (point-min) (point-max))
  1102. (buffer-string)))))
  1103. ;; Indent example blocks as a single block, unless indentation
  1104. ;; should be preserved. In this case only indent the block markers.
  1105. (should
  1106. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1107. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1108. (org-indent-region (point-min) (point-max))
  1109. (buffer-string))))
  1110. (let ((org-adapt-indentation t))
  1111. (should
  1112. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1113. (org-test-with-temp-text " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1114. (org-indent-region (point-min) (point-max))
  1115. (buffer-string))))
  1116. (should
  1117. (equal "#+BEGIN_EXAMPLE -i\n A\n B\n#+END_EXAMPLE"
  1118. (org-test-with-temp-text
  1119. " #+BEGIN_EXAMPLE -i\n A\n B\n #+END_EXAMPLE"
  1120. (org-indent-region (point-min) (point-max))
  1121. (buffer-string))))
  1122. (should
  1123. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1124. (org-test-with-temp-text
  1125. " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1126. (let ((org-src-preserve-indentation t))
  1127. (org-indent-region (point-min) (point-max)))
  1128. (buffer-string)))))
  1129. ;; Treat export blocks as a whole.
  1130. (should
  1131. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1132. (org-test-with-temp-text "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1133. (org-indent-region (point-min) (point-max))
  1134. (buffer-string))))
  1135. (let ((org-adapt-indentation t))
  1136. (should
  1137. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1138. (org-test-with-temp-text
  1139. " #+BEGIN_EXPORT latex\n A\n B\n #+END_EXPORT"
  1140. (org-indent-region (point-min) (point-max))
  1141. (buffer-string)))))
  1142. ;; Indent according to mode if `org-src-tab-acts-natively' is
  1143. ;; non-nil. Otherwise, do not indent code at all.
  1144. (should
  1145. (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
  1146. (org-test-with-temp-text
  1147. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1148. (let ((org-src-tab-acts-natively t)
  1149. (org-edit-src-content-indentation 0))
  1150. (org-indent-region (point-min) (point-max)))
  1151. (buffer-string))))
  1152. (should
  1153. (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1154. (org-test-with-temp-text
  1155. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1156. (let ((org-src-tab-acts-natively nil)
  1157. (org-edit-src-content-indentation 0))
  1158. (org-indent-region (point-min) (point-max)))
  1159. (buffer-string))))
  1160. ;; Align node properties according to `org-property-format'. Handle
  1161. ;; nicely empty values.
  1162. (should
  1163. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1164. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
  1165. (let ((org-property-format "%-10s %s")
  1166. (org-adapt-indentation nil))
  1167. (org-indent-region (point) (point-max)))
  1168. (buffer-string))))
  1169. (should
  1170. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1171. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
  1172. (let ((org-property-format "%-10s %s")
  1173. (org-adapt-indentation nil))
  1174. (org-indent-region (point) (point-max)))
  1175. (buffer-string))))
  1176. ;; Indent property drawers according to `org-adapt-indentation'.
  1177. (let ((org-adapt-indentation 'headline-data))
  1178. (should
  1179. (equal "* H\n :PROPERTIES:\n :key:\n :END:"
  1180. (org-test-with-temp-text "* H\n:PROPERTIES:\n:key:\n:END:"
  1181. (org-indent-region (point-min) (point-max))
  1182. (buffer-string)))))
  1183. ;; Indent plain lists.
  1184. (let ((org-adapt-indentation t))
  1185. (should
  1186. (equal "- A\n B\n - C\n\n D"
  1187. (org-test-with-temp-text "- A\n B\n - C\n\n D"
  1188. (org-indent-region (point-min) (point-max))
  1189. (buffer-string))))
  1190. (should
  1191. (equal "- A\n\n- B"
  1192. (org-test-with-temp-text " - A\n\n - B"
  1193. (org-indent-region (point-min) (point-max))
  1194. (buffer-string)))))
  1195. ;; Indent footnote definitions.
  1196. (should
  1197. (equal "[fn:1] Definition\n\nDefinition"
  1198. (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
  1199. (org-indent-region (point-min) (point-max))
  1200. (buffer-string))))
  1201. ;; Special case: Start indenting on a blank line.
  1202. (should
  1203. (equal "\nParagraph"
  1204. (org-test-with-temp-text "\n Paragraph"
  1205. (org-indent-region (point-min) (point-max))
  1206. (buffer-string)))))
  1207. ;;; Editing
  1208. (ert-deftest test-org/delete-indentation ()
  1209. "Test `org-delete-indentation' specifications."
  1210. ;; Regular test.
  1211. (should (equal "foo bar"
  1212. (org-test-with-temp-text
  1213. "foo \n bar<point>"
  1214. (org-delete-indentation)
  1215. (buffer-string))))
  1216. ;; With optional argument.
  1217. (should (equal "foo bar"
  1218. (org-test-with-temp-text
  1219. "foo<point> \n bar"
  1220. (org-delete-indentation t)
  1221. (buffer-string))))
  1222. ;; At headline text should be appended to the headline text.
  1223. (should
  1224. (equal"* foo bar :tag:"
  1225. (let (org-auto-align-tags)
  1226. (org-test-with-temp-text
  1227. "* foo :tag:\n bar<point>"
  1228. (org-delete-indentation)
  1229. (buffer-string)))))
  1230. (should
  1231. (equal "* foo bar :tag:"
  1232. (let (org-auto-align-tags)
  1233. (org-test-with-temp-text
  1234. "* foo <point>:tag:\n bar"
  1235. (org-delete-indentation t)
  1236. (buffer-string))))))
  1237. (ert-deftest test-org/return ()
  1238. "Test `org-return' specifications."
  1239. ;; Regular test.
  1240. (should
  1241. (equal "Para\ngraph"
  1242. (org-test-with-temp-text "Para<point>graph"
  1243. (org-return)
  1244. (buffer-string))))
  1245. ;; With optional argument, indent line.
  1246. (should
  1247. (equal " Para\n graph"
  1248. (org-test-with-temp-text " Para<point>graph"
  1249. (org-return t)
  1250. (buffer-string))))
  1251. ;; On a table, call `org-table-next-row'.
  1252. (should
  1253. (org-test-with-temp-text "| <point>a |\n| b |"
  1254. (org-return)
  1255. (looking-at-p "b")))
  1256. ;; Open link or timestamp under point when `org-return-follows-link'
  1257. ;; is non-nil.
  1258. (should
  1259. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1260. (let ((org-return-follows-link t)
  1261. (org-link-search-must-match-exact-headline nil))
  1262. (org-return))
  1263. (looking-at-p "<<target>>")))
  1264. (should-not
  1265. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1266. (let ((org-return-follows-link nil)) (org-return))
  1267. (looking-at-p "<<target>>")))
  1268. (should
  1269. (org-test-with-temp-text "* [[b][a<point>]]\n* b"
  1270. (let ((org-return-follows-link t)) (org-return))
  1271. (looking-at-p "* b")))
  1272. (should
  1273. (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
  1274. (let ((org-return-follows-link t)
  1275. (org-link-search-must-match-exact-headline nil))
  1276. (org-return))
  1277. (looking-at-p "<<target>>")))
  1278. (should-not
  1279. (org-test-with-temp-text "Link [[target]]<point> <<target>>"
  1280. (let ((org-return-follows-link t)
  1281. (org-link-search-must-match-exact-headline nil))
  1282. (org-return))
  1283. (looking-at-p "<<target>>")))
  1284. ;; When `org-return-follows-link' is non-nil, tolerate links and
  1285. ;; timestamps in comments, node properties, etc.
  1286. (should
  1287. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1288. (let ((org-return-follows-link t)
  1289. (org-link-search-must-match-exact-headline nil))
  1290. (org-return))
  1291. (looking-at-p "<<target>>")))
  1292. (should-not
  1293. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1294. (let ((org-return-follows-link nil)) (org-return))
  1295. (looking-at-p "<<target>>")))
  1296. (should-not
  1297. (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
  1298. (let ((org-return-follows-link t)
  1299. (org-link-search-must-match-exact-headline nil))
  1300. (org-return))
  1301. (looking-at-p "<<target>>")))
  1302. ;; Non-nil `org-return-follows-link' ignores read-only state of
  1303. ;; a buffer.
  1304. (should
  1305. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1306. (let ((org-return-follows-link t)
  1307. (org-link-search-must-match-exact-headline nil))
  1308. (setq buffer-read-only t)
  1309. (call-interactively #'org-return))
  1310. (looking-at-p "<<target>>")))
  1311. ;; `org-return-follows-link' handle multi-line lines.
  1312. (should
  1313. (org-test-with-temp-text
  1314. "[[target][This is a very\n long description<point>]]\n <<target>>"
  1315. (let ((org-return-follows-link t)
  1316. (org-link-search-must-match-exact-headline nil))
  1317. (org-return))
  1318. (looking-at-p "<<target>>")))
  1319. (should-not
  1320. (org-test-with-temp-text
  1321. "[[target][This is a very\n long description]]<point>\n <<target>>"
  1322. (let ((org-return-follows-link t)
  1323. (org-link-search-must-match-exact-headline nil))
  1324. (org-return))
  1325. (looking-at-p "<<target>>")))
  1326. ;; However, do not open link when point is in a table.
  1327. (should
  1328. (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
  1329. (let ((org-return-follows-link t)) (org-return))
  1330. (looking-at-p "between")))
  1331. ;; Special case: in a list, when indenting, do not break structure.
  1332. (should
  1333. (equal "- A\n B"
  1334. (org-test-with-temp-text "- A <point>B"
  1335. (org-return t)
  1336. (buffer-string))))
  1337. (should
  1338. (equal "- A\n\n- B"
  1339. (org-test-with-temp-text "- A\n<point>- B"
  1340. (org-return t)
  1341. (buffer-string))))
  1342. ;; On tags part of a headline, add a newline below it instead of
  1343. ;; breaking it.
  1344. (should
  1345. (equal "* H :tag:\n"
  1346. (org-test-with-temp-text "* H :<point>tag:"
  1347. (org-return)
  1348. (buffer-string))))
  1349. ;; Before headline text, add a newline below it instead of breaking
  1350. ;; it.
  1351. (should
  1352. (equal "* TODO H :tag:\n"
  1353. (org-test-with-temp-text "* <point>TODO H :tag:"
  1354. (org-return)
  1355. (buffer-string))))
  1356. (should
  1357. (equal "* TODO [#B] H :tag:\n"
  1358. (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
  1359. (org-return)
  1360. (buffer-string))))
  1361. (should ;TODO are case-sensitive
  1362. (equal "* \nTodo"
  1363. (org-test-with-temp-text "* <point>Todo"
  1364. (org-return)
  1365. (buffer-string))))
  1366. ;; At headline text, break headline text but preserve tags.
  1367. (should
  1368. (equal "* TODO [#B] foo :tag:\nbar"
  1369. (let (org-auto-align-tags)
  1370. (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
  1371. (org-return)
  1372. (buffer-string)))))
  1373. ;; At bol of headline insert newline.
  1374. (should
  1375. (equal "\n* h"
  1376. (org-test-with-temp-text "<point>* h"
  1377. (org-return)
  1378. (buffer-string))))
  1379. ;; Refuse to leave invalid headline in buffer.
  1380. (should
  1381. (equal "* h\n"
  1382. (org-test-with-temp-text "*<point> h"
  1383. (org-return)
  1384. (buffer-string))))
  1385. ;; Before first column or after last one in a table, split the
  1386. ;; table.
  1387. (should
  1388. (equal "| a |\n\n| b |"
  1389. (org-test-with-temp-text "| a |\n<point>| b |"
  1390. (org-return)
  1391. (buffer-string))))
  1392. (should
  1393. (equal "| a |\n\n| b |"
  1394. (org-test-with-temp-text "| a |<point>\n| b |"
  1395. (org-return)
  1396. (buffer-string))))
  1397. ;; Do not auto-fill on hitting <RET> inside a property drawer.
  1398. (should
  1399. (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:"
  1400. (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:"
  1401. (setq-local fill-column 10)
  1402. (auto-fill-mode 1)
  1403. (org-return)
  1404. (buffer-string)))))
  1405. (ert-deftest test-org/with-electric-indent ()
  1406. "Test RET and C-j specifications with `electric-indent-mode' on."
  1407. ;; Call commands interactively, since this is how `newline' knows it
  1408. ;; must run `post-self-insert-hook'.
  1409. ;;
  1410. ;; RET, like `newline', should indent.
  1411. (should
  1412. (equal " Para\n graph"
  1413. (org-test-with-temp-text " Para<point>graph"
  1414. (electric-indent-local-mode 1)
  1415. (call-interactively 'org-return)
  1416. (buffer-string))))
  1417. (should
  1418. (equal "- item1\n item2"
  1419. (org-test-with-temp-text "- item1<point>item2"
  1420. (electric-indent-local-mode 1)
  1421. (call-interactively 'org-return)
  1422. (buffer-string))))
  1423. ;; TODO: test more values of `org-adapt-indentation'.
  1424. (let ((org-adapt-indentation t))
  1425. (should
  1426. (equal "* heading\n body"
  1427. (org-test-with-temp-text "* heading<point>body"
  1428. (electric-indent-local-mode 1)
  1429. (call-interactively 'org-return)
  1430. (buffer-string)))))
  1431. ;; C-j, like `electric-newline-and-maybe-indent', should not indent.
  1432. (should
  1433. (equal " Para\ngraph"
  1434. (org-test-with-temp-text " Para<point>graph"
  1435. (electric-indent-local-mode 1)
  1436. (call-interactively 'org-return-and-maybe-indent)
  1437. (buffer-string))))
  1438. (should
  1439. (equal "- item1\nitem2"
  1440. (org-test-with-temp-text "- item1<point>item2"
  1441. (electric-indent-local-mode 1)
  1442. (call-interactively 'org-return-and-maybe-indent)
  1443. (buffer-string))))
  1444. ;; TODO: test more values of `org-adapt-indentation'.
  1445. (let ((org-adapt-indentation t))
  1446. (should
  1447. (equal "* heading\nbody"
  1448. (org-test-with-temp-text "* heading<point>body"
  1449. (electric-indent-local-mode 1)
  1450. (call-interactively 'org-return-and-maybe-indent)
  1451. (buffer-string))))))
  1452. (ert-deftest test-org/without-electric-indent ()
  1453. "Test RET and C-j specifications with `electric-indent-mode' off."
  1454. ;; Call commands interactively, since this is how `newline' knows it
  1455. ;; must run `post-self-insert-hook'.
  1456. ;;
  1457. ;; RET, like `newline', should not indent.
  1458. (should
  1459. (equal " Para\ngraph"
  1460. (org-test-with-temp-text " Para<point>graph"
  1461. (electric-indent-local-mode 0)
  1462. (call-interactively 'org-return)
  1463. (buffer-string))))
  1464. (should
  1465. (equal "- item1\nitem2"
  1466. (org-test-with-temp-text "- item1<point>item2"
  1467. (electric-indent-local-mode 0)
  1468. (call-interactively 'org-return)
  1469. (buffer-string))))
  1470. (should
  1471. (equal "* heading\nbody"
  1472. (org-test-with-temp-text "* heading<point>body"
  1473. (electric-indent-local-mode 0)
  1474. (call-interactively 'org-return)
  1475. (buffer-string))))
  1476. ;; C-j, like `electric-newline-and-maybe-indent', should indent.
  1477. (should
  1478. (equal " Para\n graph"
  1479. (org-test-with-temp-text " Para<point>graph"
  1480. (electric-indent-local-mode 0)
  1481. (call-interactively 'org-return-and-maybe-indent)
  1482. (buffer-string))))
  1483. (should
  1484. (equal "- item1\n item2"
  1485. (org-test-with-temp-text "- item1<point>item2"
  1486. (electric-indent-local-mode 0)
  1487. (call-interactively 'org-return-and-maybe-indent)
  1488. (buffer-string))))
  1489. ;; TODO: test more values of `org-adapt-indentation'.
  1490. (let ((org-adapt-indentation t))
  1491. (should
  1492. (equal "* heading\n body"
  1493. (org-test-with-temp-text "* heading<point>body"
  1494. (electric-indent-local-mode 0)
  1495. (call-interactively 'org-return-and-maybe-indent)
  1496. (buffer-string))))))
  1497. (ert-deftest test-org/meta-return ()
  1498. "Test M-RET (`org-meta-return') specifications."
  1499. ;; In a table field insert a row above.
  1500. (should
  1501. (org-test-with-temp-text "| a |"
  1502. (forward-char)
  1503. (org-meta-return)
  1504. (forward-line -1)
  1505. (looking-at "| |$")))
  1506. ;; In a paragraph change current line into a header.
  1507. (should
  1508. (org-test-with-temp-text "a"
  1509. (org-meta-return)
  1510. (beginning-of-line)
  1511. (looking-at "\* a$")))
  1512. ;; In an item insert an item, in this case above.
  1513. (should
  1514. (org-test-with-temp-text "- a"
  1515. (org-meta-return)
  1516. (beginning-of-line)
  1517. (looking-at "- $")))
  1518. ;; In a drawer and item insert an item, in this case above.
  1519. (should
  1520. (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
  1521. (forward-line)
  1522. (org-fold-reveal)
  1523. (org-meta-return)
  1524. (beginning-of-line)
  1525. (looking-at "- $"))))
  1526. (ert-deftest test-org/insert-heading ()
  1527. "Test `org-insert-heading' specifications."
  1528. ;; In an empty buffer, insert a new headline.
  1529. (should
  1530. (equal "* "
  1531. (org-test-with-temp-text ""
  1532. (org-insert-heading)
  1533. (buffer-string))))
  1534. ;; At the beginning of a line, turn it into a headline.
  1535. (should
  1536. (equal "* P"
  1537. (org-test-with-temp-text "<point>P"
  1538. (org-insert-heading)
  1539. (buffer-string))))
  1540. ;; In the middle of a line, split the line if allowed, otherwise,
  1541. ;; insert the headline at its end.
  1542. (should
  1543. (equal "Para\n* graph"
  1544. (org-test-with-temp-text "Para<point>graph"
  1545. (let ((org-M-RET-may-split-line '((default . t))))
  1546. (org-insert-heading))
  1547. (buffer-string))))
  1548. (should
  1549. (equal "Paragraph\n* "
  1550. (org-test-with-temp-text "Para<point>graph"
  1551. (let ((org-M-RET-may-split-line '((default . nil))))
  1552. (org-insert-heading))
  1553. (buffer-string))))
  1554. ;; At the beginning of a headline, create one above.
  1555. (should
  1556. (equal "* \n* H"
  1557. (org-test-with-temp-text "* H"
  1558. (org-insert-heading)
  1559. (buffer-string))))
  1560. ;; In the middle of a headline, split it if allowed.
  1561. (should
  1562. (equal "* H\n* 1"
  1563. (org-test-with-temp-text "* H<point>1"
  1564. (let ((org-M-RET-may-split-line '((headline . t))))
  1565. (org-insert-heading))
  1566. (buffer-string))))
  1567. (should
  1568. (equal "* H1\n* "
  1569. (org-test-with-temp-text "* H<point>1"
  1570. (let ((org-M-RET-may-split-line '((headline . nil))))
  1571. (org-insert-heading))
  1572. (buffer-string))))
  1573. ;; However, splitting cannot happen on TODO keywords, priorities or
  1574. ;; tags.
  1575. (should
  1576. (equal "* TODO H1\n* "
  1577. (org-test-with-temp-text "* TO<point>DO H1"
  1578. (let ((org-M-RET-may-split-line '((headline . t))))
  1579. (org-insert-heading))
  1580. (buffer-string))))
  1581. (should
  1582. (equal "* [#A] H1\n* "
  1583. (org-test-with-temp-text "* [#<point>A] H1"
  1584. (let ((org-M-RET-may-split-line '((headline . t))))
  1585. (org-insert-heading))
  1586. (buffer-string))))
  1587. (should
  1588. (equal "* H1 :tag:\n* "
  1589. (org-test-with-temp-text "* H1 :ta<point>g:"
  1590. (let ((org-M-RET-may-split-line '((headline . t))))
  1591. (org-insert-heading))
  1592. (buffer-string))))
  1593. ;; New headline level depends on the level of the headline above.
  1594. (should
  1595. (equal "** H\n** P"
  1596. (org-test-with-temp-text "** H\n<point>P"
  1597. (org-insert-heading)
  1598. (buffer-string))))
  1599. (should
  1600. (equal "** H\nPara\n** graph"
  1601. (org-test-with-temp-text "** H\nPara<point>graph"
  1602. (let ((org-M-RET-may-split-line '((default . t))))
  1603. (org-insert-heading))
  1604. (buffer-string))))
  1605. (should
  1606. (equal "** \n** H"
  1607. (org-test-with-temp-text "** H"
  1608. (org-insert-heading)
  1609. (buffer-string))))
  1610. ;; When called with one universal argument, insert a new headline at
  1611. ;; the end of the current subtree, independently on the position of
  1612. ;; point.
  1613. (should
  1614. (equal
  1615. "* "
  1616. (org-test-with-temp-text ""
  1617. (let ((org-insert-heading-respect-content nil))
  1618. (org-insert-heading '(4)))
  1619. (buffer-string))))
  1620. (should
  1621. (equal
  1622. "entry
  1623. * "
  1624. (org-test-with-temp-text "entry"
  1625. (let ((org-insert-heading-respect-content nil))
  1626. (org-insert-heading '(4)))
  1627. (buffer-string))))
  1628. (should
  1629. (equal
  1630. "* H1\n** H2\n* "
  1631. (org-test-with-temp-text "* H1\n** H2"
  1632. (let ((org-insert-heading-respect-content nil))
  1633. (org-insert-heading '(4)))
  1634. (buffer-string))))
  1635. (should
  1636. (equal
  1637. "* H1\n** H2\n* "
  1638. (org-test-with-temp-text "* H<point>1\n** H2"
  1639. (let ((org-insert-heading-respect-content nil))
  1640. (org-insert-heading '(4)))
  1641. (buffer-string))))
  1642. ;; When called with two universal arguments, insert a new headline
  1643. ;; at the end of the grandparent subtree.
  1644. (should
  1645. (equal "* H1\n** H3\n- item\n** H2\n** "
  1646. (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
  1647. (let ((org-insert-heading-respect-content nil))
  1648. (org-insert-heading '(16)))
  1649. (buffer-string))))
  1650. ;; When optional TOP-LEVEL argument is non-nil, always insert
  1651. ;; a level 1 heading.
  1652. (should
  1653. (equal "* H1\n** H2\n* "
  1654. (org-test-with-temp-text "* H1\n** H2<point>"
  1655. (org-insert-heading nil nil t)
  1656. (buffer-string))))
  1657. (should
  1658. (equal "* H1\n- item\n* "
  1659. (org-test-with-temp-text "* H1\n- item<point>"
  1660. (org-insert-heading nil nil t)
  1661. (buffer-string))))
  1662. ;; Obey `org-blank-before-new-entry'.
  1663. (should
  1664. (equal "* H1\n\n* "
  1665. (org-test-with-temp-text "* H1<point>"
  1666. (let ((org-blank-before-new-entry '((heading . t))))
  1667. (org-insert-heading))
  1668. (buffer-string))))
  1669. (should
  1670. (equal "* H1\n* "
  1671. (org-test-with-temp-text "* H1<point>"
  1672. (let ((org-blank-before-new-entry '((heading . nil))))
  1673. (org-insert-heading))
  1674. (buffer-string))))
  1675. (should
  1676. (equal "* H1\n* H2\n* "
  1677. (org-test-with-temp-text "* H1\n* H2<point>"
  1678. (let ((org-blank-before-new-entry '((heading . auto))))
  1679. (org-insert-heading))
  1680. (buffer-string))))
  1681. (should
  1682. (equal "* H1\n\n* H2\n\n* "
  1683. (org-test-with-temp-text "* H1\n\n* H2<point>"
  1684. (let ((org-blank-before-new-entry '((heading . auto))))
  1685. (org-insert-heading))
  1686. (buffer-string))))
  1687. ;; Corner case: correctly insert a headline after an empty one.
  1688. (should
  1689. (equal "* \n* "
  1690. (org-test-with-temp-text "* <point>"
  1691. (org-insert-heading)
  1692. (buffer-string))))
  1693. (should
  1694. (org-test-with-temp-text "* <point>\n"
  1695. (org-insert-heading)
  1696. (looking-at-p "\n\\'")))
  1697. ;; Do not insert spurious headlines when inserting a new headline.
  1698. (should
  1699. (equal "* H1\n* H2\n* \n"
  1700. (org-test-with-temp-text "* H1\n* H2<point>\n"
  1701. (org-insert-heading)
  1702. (buffer-string))))
  1703. ;; Preserve visibility at beginning of line. In particular, when
  1704. ;; removing spurious blank lines, do not visually merge heading with
  1705. ;; the line visible above.
  1706. (should-not
  1707. (org-test-with-temp-text "* H1<point>\nContents\n\n* H2\n"
  1708. (org-overview)
  1709. (let ((org-blank-before-new-entry '((heading . nil))))
  1710. (org-insert-heading '(4)))
  1711. (invisible-p (line-end-position 0))))
  1712. ;; Properly handle empty lines when forcing a headline below current
  1713. ;; one.
  1714. (should
  1715. (equal "* H1\n\n* H\n\n* "
  1716. (org-test-with-temp-text "* H1\n\n* H<point>"
  1717. (let ((org-blank-before-new-entry '((heading . t))))
  1718. (org-insert-heading '(4))
  1719. (buffer-string))))))
  1720. (ert-deftest test-org/insert-todo-heading-respect-content ()
  1721. "Test `org-insert-todo-heading-respect-content' specifications."
  1722. ;; Create a TODO heading.
  1723. (should
  1724. (org-test-with-temp-text "* H1\n Body"
  1725. (org-insert-todo-heading-respect-content)
  1726. (nth 2 (org-heading-components))))
  1727. ;; Add headline at the end of the first subtree
  1728. (should
  1729. (equal
  1730. "* TODO "
  1731. (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
  1732. (org-insert-todo-heading-respect-content)
  1733. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1734. ;; In a list, do not create a new item.
  1735. (should
  1736. (equal
  1737. "* TODO "
  1738. (org-test-with-temp-text "* H\n- an item\n- another one"
  1739. (search-forward "an ")
  1740. (org-insert-todo-heading-respect-content)
  1741. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1742. ;; Use the same TODO keyword as current heading.
  1743. (should
  1744. (equal
  1745. "* TODO \n"
  1746. (org-test-with-temp-text "* TODO\n** WAITING\n"
  1747. (org-insert-todo-heading-respect-content)
  1748. (buffer-substring-no-properties (line-beginning-position) (point-max))))))
  1749. (ert-deftest test-org/clone-with-time-shift ()
  1750. "Test `org-clone-subtree-with-time-shift'."
  1751. ;; Raise an error before first heading.
  1752. (should-error
  1753. (org-test-with-temp-text ""
  1754. (org-clone-subtree-with-time-shift 1)))
  1755. ;; Raise an error on invalid number of clones.
  1756. (should-error
  1757. (org-test-with-temp-text "* Clone me"
  1758. (org-clone-subtree-with-time-shift -1)))
  1759. ;; Clone non-repeating once.
  1760. (should
  1761. (equal "\
  1762. * H1\n<2015-06-21>
  1763. * H1\n<2015-06-23>
  1764. "
  1765. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1766. (org-clone-subtree-with-time-shift 1 "+2d")
  1767. (replace-regexp-in-string
  1768. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1769. nil nil 1))))
  1770. ;; Clone repeating once.
  1771. (should
  1772. (equal "\
  1773. * H1\n<2015-06-21>
  1774. * H1\n<2015-06-23>
  1775. * H1\n<2015-06-25 +1w>
  1776. "
  1777. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1778. (org-clone-subtree-with-time-shift 1 "+2d")
  1779. (replace-regexp-in-string
  1780. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1781. nil nil 1))))
  1782. ;; Clone repeating once in backward.
  1783. (should
  1784. (equal "\
  1785. * H1\n<2015-06-21>
  1786. * H1\n<2015-06-19>
  1787. * H1\n<2015-06-17 +1w>
  1788. "
  1789. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1790. (org-clone-subtree-with-time-shift 1 "-2d")
  1791. (replace-regexp-in-string
  1792. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1793. nil nil 1))))
  1794. ;; Clone non-repeating zero times.
  1795. (should
  1796. (equal "\
  1797. * H1\n<2015-06-21>
  1798. "
  1799. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1800. (org-clone-subtree-with-time-shift 0 "+2d")
  1801. (replace-regexp-in-string
  1802. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1803. nil nil 1))))
  1804. ;; Clone repeating "zero" times.
  1805. (should
  1806. (equal "\
  1807. * H1\n<2015-06-21>
  1808. * H1\n<2015-06-23 +1w>
  1809. "
  1810. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1811. (org-clone-subtree-with-time-shift 0 "+2d")
  1812. (replace-regexp-in-string
  1813. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1814. nil nil 1))))
  1815. ;; Clone with blank SHIFT argument.
  1816. (should
  1817. (string-prefix-p
  1818. "* H <2012-03-29"
  1819. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1820. (org-clone-subtree-with-time-shift 1 "")
  1821. (buffer-substring-no-properties (line-beginning-position 2)
  1822. (line-end-position 2)))))
  1823. ;; Find time stamps before point. If SHIFT is not specified, ask
  1824. ;; for a time shift.
  1825. (should
  1826. (string-prefix-p
  1827. "* H <2012-03-30"
  1828. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1829. (org-clone-subtree-with-time-shift 1 "+1d")
  1830. (buffer-substring-no-properties (line-beginning-position 2)
  1831. (line-end-position 2)))))
  1832. (should
  1833. (string-prefix-p
  1834. "* H <2014-03-05"
  1835. (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
  1836. (cl-letf (((symbol-function 'read-from-minibuffer)
  1837. (lambda (&rest args) "+1d")))
  1838. (org-clone-subtree-with-time-shift 1))
  1839. (buffer-substring-no-properties (line-beginning-position 2)
  1840. (line-end-position 2)))))
  1841. ;; Hour shift.
  1842. (should
  1843. (equal "\
  1844. * H1\n<2015-06-21 20:00>
  1845. * H1\n<2015-06-21 23:00>
  1846. * H1\n<2015-06-22 02:00>
  1847. "
  1848. (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>"
  1849. (org-clone-subtree-with-time-shift 2 "+3h")
  1850. (replace-regexp-in-string
  1851. "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" ""
  1852. (buffer-substring-no-properties (point-min) (point-max))
  1853. nil nil 1))))
  1854. (should
  1855. (equal "\
  1856. * H1\n<2015-06-21 20:00>
  1857. * H1\n<2015-06-21 18:00>
  1858. "
  1859. (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>"
  1860. (org-clone-subtree-with-time-shift 1 "-2h")
  1861. (replace-regexp-in-string
  1862. "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" ""
  1863. (buffer-substring-no-properties (point-min) (point-max))
  1864. nil nil 1)))))
  1865. ;;; Fixed-Width Areas
  1866. (ert-deftest test-org/toggle-fixed-width ()
  1867. "Test `org-toggle-fixed-width' specifications."
  1868. ;; No region: Toggle on fixed-width marker in paragraphs.
  1869. (should
  1870. (equal ": A"
  1871. (org-test-with-temp-text "A"
  1872. (org-toggle-fixed-width)
  1873. (buffer-string))))
  1874. ;; No region: Toggle off fixed-width markers in fixed-width areas.
  1875. (should
  1876. (equal "A"
  1877. (org-test-with-temp-text ": A"
  1878. (org-toggle-fixed-width)
  1879. (buffer-string))))
  1880. ;; No region: Toggle on marker in blank lines after elements or just
  1881. ;; after a headline.
  1882. (should
  1883. (equal "* H\n: "
  1884. (org-test-with-temp-text "* H\n"
  1885. (forward-line)
  1886. (org-toggle-fixed-width)
  1887. (buffer-string))))
  1888. (should
  1889. (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
  1890. (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
  1891. (goto-char (point-max))
  1892. (org-toggle-fixed-width)
  1893. (buffer-string))))
  1894. ;; No region: Toggle on marker in front of one line elements (e.g.,
  1895. ;; headlines, clocks)
  1896. (should
  1897. (equal ": * Headline"
  1898. (org-test-with-temp-text "* Headline"
  1899. (org-toggle-fixed-width)
  1900. (buffer-string))))
  1901. (should
  1902. (equal ": #+KEYWORD: value"
  1903. (org-test-with-temp-text "#+KEYWORD: value"
  1904. (org-toggle-fixed-width)
  1905. (buffer-string))))
  1906. ;; No region: error in other situations.
  1907. (should-error
  1908. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
  1909. (forward-line)
  1910. (org-toggle-fixed-width)
  1911. (buffer-string)))
  1912. ;; No region: Indentation is preserved.
  1913. (should
  1914. (equal "- A\n : B"
  1915. (org-test-with-temp-text "- A\n B"
  1916. (forward-line)
  1917. (org-toggle-fixed-width)
  1918. (buffer-string))))
  1919. ;; Region: If it contains only fixed-width elements and blank lines,
  1920. ;; toggle off fixed-width markup.
  1921. (should
  1922. (equal "A\n\nB"
  1923. (org-test-with-temp-text ": A\n\n: B"
  1924. (transient-mark-mode 1)
  1925. (push-mark (point) t t)
  1926. (goto-char (point-max))
  1927. (org-toggle-fixed-width)
  1928. (buffer-string))))
  1929. ;; Region: If it contains anything else, toggle on fixed-width but
  1930. ;; not on fixed-width areas.
  1931. (should
  1932. (equal ": A\n: \n: B\n: \n: C"
  1933. (org-test-with-temp-text "A\n\n: B\n\nC"
  1934. (transient-mark-mode 1)
  1935. (push-mark (point) t t)
  1936. (goto-char (point-max))
  1937. (org-toggle-fixed-width)
  1938. (buffer-string))))
  1939. ;; Region: Ignore blank lines at its end, unless it contains only
  1940. ;; such lines.
  1941. (should
  1942. (equal ": A\n\n"
  1943. (org-test-with-temp-text "A\n\n"
  1944. (transient-mark-mode 1)
  1945. (push-mark (point) t t)
  1946. (goto-char (point-max))
  1947. (org-toggle-fixed-width)
  1948. (buffer-string))))
  1949. (should
  1950. (equal ": \n: \n"
  1951. (org-test-with-temp-text "\n\n"
  1952. (transient-mark-mode 1)
  1953. (push-mark (point) t t)
  1954. (goto-char (point-max))
  1955. (org-toggle-fixed-width)
  1956. (buffer-string)))))
  1957. (ert-deftest test-org/kill-line ()
  1958. "Test `org-kill-line' specifications."
  1959. ;; At the beginning of a line, kill whole line.
  1960. (should
  1961. (equal ""
  1962. (org-test-with-temp-text "abc"
  1963. (org-kill-line)
  1964. (buffer-string))))
  1965. ;; In the middle of a line, kill line until its end.
  1966. (should
  1967. (equal "a"
  1968. (org-test-with-temp-text "a<point>bc"
  1969. (org-kill-line)
  1970. (buffer-string))))
  1971. ;; Do not kill newline character.
  1972. (should
  1973. (equal "\n123"
  1974. (org-test-with-temp-text "abc\n123"
  1975. (org-kill-line)
  1976. (buffer-string))))
  1977. (should
  1978. (equal "a\n123"
  1979. (org-test-with-temp-text "a<point>bc\n123"
  1980. (org-kill-line)
  1981. (buffer-string))))
  1982. ;; When `org-special-ctrl-k' is non-nil and point is at a headline,
  1983. ;; kill until tags.
  1984. (should
  1985. (equal "* A :tag:"
  1986. (org-test-with-temp-text "* A<point>B :tag:"
  1987. (let ((org-special-ctrl-k t)
  1988. (org-tags-column 0))
  1989. (org-kill-line))
  1990. (buffer-string))))
  1991. ;; If point is on tags, only kill part left until the end of line.
  1992. (should
  1993. (equal "* A :tag:"
  1994. (org-test-with-temp-text "* A :tag:<point>tag2:"
  1995. (let ((org-special-ctrl-k t)
  1996. (org-tags-column 0))
  1997. (org-kill-line))
  1998. (buffer-string))))
  1999. ;; However, if point is at the beginning of the line, kill whole
  2000. ;; headline.
  2001. (should
  2002. (equal ""
  2003. (org-test-with-temp-text "* AB :tag:"
  2004. (let ((org-special-ctrl-k t)
  2005. (org-tags-column 0))
  2006. (org-kill-line))
  2007. (buffer-string))))
  2008. ;; When `org-ctrl-k-protect-subtree' is non-nil, and point is in
  2009. ;; invisible text, ask before removing it. When set to `error',
  2010. ;; throw an error.
  2011. (should-error
  2012. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  2013. (org-overview)
  2014. (let ((org-special-ctrl-k nil)
  2015. (org-ctrl-k-protect-subtree t))
  2016. (cl-letf (((symbol-function 'y-or-n-p) 'ignore))
  2017. (org-kill-line)))))
  2018. (should-error
  2019. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  2020. (org-overview)
  2021. (let ((org-special-ctrl-k nil)
  2022. (org-ctrl-k-protect-subtree 'error))
  2023. (org-kill-line)))))
  2024. ;;; Headline
  2025. (ert-deftest test-org/get-heading ()
  2026. "Test `org-get-heading' specifications."
  2027. ;; Return current heading, even if point is not on it.
  2028. (should
  2029. (equal "H"
  2030. (org-test-with-temp-text "* H"
  2031. (org-get-heading))))
  2032. (should
  2033. (equal "H"
  2034. (org-test-with-temp-text "* H\nText<point>"
  2035. (org-get-heading))))
  2036. ;; Without any optional argument, return TODO keyword, priority
  2037. ;; cookie, COMMENT keyword and tags.
  2038. (should
  2039. (equal "TODO H"
  2040. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2041. (org-get-heading))))
  2042. (should
  2043. (equal "[#A] H"
  2044. (org-test-with-temp-text "* [#A] H"
  2045. (org-get-heading))))
  2046. (should
  2047. (equal "COMMENT H"
  2048. (org-test-with-temp-text "* COMMENT H"
  2049. (org-get-heading))))
  2050. (should
  2051. (equal "H :tag:"
  2052. (org-test-with-temp-text "* H :tag:"
  2053. (org-get-heading))))
  2054. ;; With NO-TAGS argument, ignore tags.
  2055. (should
  2056. (equal "TODO H"
  2057. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2058. (org-get-heading t))))
  2059. (should
  2060. (equal "H"
  2061. (org-test-with-temp-text "* H :tag:"
  2062. (org-get-heading t))))
  2063. ;; With NO-TODO, ignore TODO keyword.
  2064. (should
  2065. (equal "H"
  2066. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2067. (org-get-heading nil t))))
  2068. (should
  2069. (equal "H :tag:"
  2070. (org-test-with-temp-text "* H :tag:"
  2071. (org-get-heading nil t))))
  2072. ;; TODO keywords are case-sensitive.
  2073. (should
  2074. (equal "Todo H"
  2075. (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
  2076. (org-get-heading nil t))))
  2077. ;; With NO-PRIORITY, ignore priority.
  2078. (should
  2079. (equal "H"
  2080. (org-test-with-temp-text "* [#A] H"
  2081. (org-get-heading nil nil t))))
  2082. (should
  2083. (equal "H"
  2084. (org-test-with-temp-text "* H"
  2085. (org-get-heading nil nil t))))
  2086. (should
  2087. (equal "TODO H"
  2088. (org-test-with-temp-text "* TODO [#A] H"
  2089. (org-get-heading nil nil t))))
  2090. ;; With NO-COMMENT, ignore COMMENT keyword.
  2091. (should
  2092. (equal "H"
  2093. (org-test-with-temp-text "* COMMENT H"
  2094. (org-get-heading nil nil nil t))))
  2095. (should
  2096. (equal "H"
  2097. (org-test-with-temp-text "* H"
  2098. (org-get-heading nil nil nil t))))
  2099. (should
  2100. (equal "TODO [#A] H"
  2101. (org-test-with-temp-text "* TODO [#A] COMMENT H"
  2102. (org-get-heading nil nil nil t))))
  2103. ;; On an empty headline, return value is consistent.
  2104. (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
  2105. (should (equal "" (org-test-with-temp-text "* " (org-get-heading t))))
  2106. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t))))
  2107. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t))))
  2108. (should
  2109. (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t)))))
  2110. (ert-deftest test-org/in-commented-heading-p ()
  2111. "Test `org-in-commented-heading-p' specifications."
  2112. ;; Commented headline.
  2113. (should
  2114. (org-test-with-temp-text "* COMMENT Headline\nBody"
  2115. (goto-char (point-max))
  2116. (org-in-commented-heading-p)))
  2117. ;; Commented ancestor.
  2118. (should
  2119. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  2120. (goto-char (point-max))
  2121. (org-in-commented-heading-p)))
  2122. ;; Comment keyword is case-sensitive.
  2123. (should-not
  2124. (org-test-with-temp-text "* Comment Headline\nBody"
  2125. (goto-char (point-max))
  2126. (org-in-commented-heading-p)))
  2127. ;; Keyword is standalone.
  2128. (should-not
  2129. (org-test-with-temp-text "* COMMENTHeadline\nBody"
  2130. (goto-char (point-max))
  2131. (org-in-commented-heading-p)))
  2132. ;; Optional argument.
  2133. (should-not
  2134. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  2135. (goto-char (point-max))
  2136. (org-in-commented-heading-p t))))
  2137. (ert-deftest test-org/in-archived-heading-p ()
  2138. "Test `org-in-archived-heading-p' specifications."
  2139. ;; Archived headline.
  2140. (should
  2141. (org-test-with-temp-text "* Headline :ARCHIVE:\nBody"
  2142. (goto-char (point-max))
  2143. (org-in-archived-heading-p)))
  2144. ;; Archived ancestor.
  2145. (should
  2146. (org-test-with-temp-text "* Headline :ARCHIVE:\n** Level 2\nBody"
  2147. (goto-char (point-max))
  2148. (org-in-archived-heading-p)))
  2149. ;; Optional argument.
  2150. (should-not
  2151. (org-test-with-temp-text "* Headline :ARCHIVE:\n** Level 2\nBody"
  2152. (goto-char (point-max))
  2153. (org-in-archived-heading-p t)))
  2154. ;; Archive tag containing ARCHIVE as substring
  2155. (should-not
  2156. (org-test-with-temp-text "* Headline :NOARCHIVE:\n** Level 2\nBody"
  2157. (goto-char (point-max))
  2158. (org-in-archived-heading-p))))
  2159. (ert-deftest test-org/entry-blocked-p ()
  2160. ;; Check other dependencies.
  2161. (should
  2162. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  2163. (let ((org-enforce-todo-dependencies t)
  2164. (org-blocker-hook
  2165. '(org-block-todo-from-children-or-siblings-or-parent)))
  2166. (org-entry-blocked-p))))
  2167. (should-not
  2168. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  2169. (let ((org-enforce-todo-dependencies t)
  2170. (org-blocker-hook
  2171. '(org-block-todo-from-children-or-siblings-or-parent)))
  2172. (org-entry-blocked-p))))
  2173. ;; Entry without a TODO keyword or with a DONE keyword cannot be
  2174. ;; blocked.
  2175. (should-not
  2176. (org-test-with-temp-text "* Blocked\n** TODO one"
  2177. (let ((org-enforce-todo-dependencies t)
  2178. (org-blocker-hook
  2179. '(org-block-todo-from-children-or-siblings-or-parent)))
  2180. (org-entry-blocked-p))))
  2181. (should-not
  2182. (org-test-with-temp-text "* DONE Blocked\n** TODO one"
  2183. (let ((org-enforce-todo-dependencies t)
  2184. (org-blocker-hook
  2185. '(org-block-todo-from-children-or-siblings-or-parent)))
  2186. (org-entry-blocked-p))))
  2187. ;; Follow :ORDERED: specifications.
  2188. (should
  2189. (org-test-with-temp-text
  2190. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
  2191. (let ((org-enforce-todo-dependencies t)
  2192. (org-blocker-hook
  2193. '(org-block-todo-from-children-or-siblings-or-parent)))
  2194. (org-entry-blocked-p))))
  2195. (should-not
  2196. (org-test-with-temp-text
  2197. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
  2198. (let ((org-enforce-todo-dependencies t)
  2199. (org-blocker-hook
  2200. '(org-block-todo-from-children-or-siblings-or-parent)))
  2201. (org-entry-blocked-p)))))
  2202. (ert-deftest test-org/get-outline-path ()
  2203. "Test `org-get-outline-path' specifications."
  2204. ;; Top-level headlines have no outline path.
  2205. (should-not
  2206. (org-test-with-temp-text "* H"
  2207. (org-get-outline-path)))
  2208. ;; Otherwise, outline path is the path leading to the headline.
  2209. (should
  2210. (equal '("H")
  2211. (org-test-with-temp-text "* H\n** S<point>"
  2212. (org-get-outline-path))))
  2213. ;; Find path even when point is not on a headline.
  2214. (should
  2215. (equal '("H")
  2216. (org-test-with-temp-text "* H\n** S\nText<point>"
  2217. (org-get-outline-path))))
  2218. ;; TODO keywords, tags and statistics cookies are ignored.
  2219. (should
  2220. (equal '("H")
  2221. (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
  2222. (org-get-outline-path))))
  2223. ;; Links are replaced with their description or their path.
  2224. (should
  2225. (equal '("Org")
  2226. (org-test-with-temp-text
  2227. "* [[https://orgmode.org][Org]]\n** S<point>"
  2228. (org-get-outline-path))))
  2229. (should
  2230. (equal '("https://orgmode.org")
  2231. (org-test-with-temp-text
  2232. "* [[https://orgmode.org]]\n** S<point>"
  2233. (org-get-outline-path))))
  2234. ;; When WITH-SELF is non-nil, include current heading.
  2235. (should
  2236. (equal '("H")
  2237. (org-test-with-temp-text "* H"
  2238. (org-get-outline-path t))))
  2239. (should
  2240. (equal '("H" "S")
  2241. (org-test-with-temp-text "* H\n** S\nText<point>"
  2242. (org-get-outline-path t))))
  2243. ;; Using cache is transparent to the user.
  2244. (should
  2245. (equal '("H")
  2246. (org-test-with-temp-text "* H\n** S<point>"
  2247. (setq org-outline-path-cache nil)
  2248. (org-get-outline-path nil t))))
  2249. ;; Do not corrupt cache when finding outline path in distant part of
  2250. ;; the buffer.
  2251. (should
  2252. (equal '("H2")
  2253. (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
  2254. (setq org-outline-path-cache nil)
  2255. (org-get-outline-path nil t)
  2256. (search-forward "S2")
  2257. (org-get-outline-path nil t))))
  2258. ;; Do not choke on empty headlines.
  2259. (should
  2260. (org-test-with-temp-text "* H\n** <point>"
  2261. (org-get-outline-path)))
  2262. (should
  2263. (org-test-with-temp-text "* \n** H<point>"
  2264. (org-get-outline-path))))
  2265. (ert-deftest test-org/format-outline-path ()
  2266. "Test `org-format-outline-path' specifications."
  2267. (should
  2268. (string= (org-format-outline-path (list "one" "two" "three"))
  2269. "one/two/three"))
  2270. ;; Empty path.
  2271. (should
  2272. (string= (org-format-outline-path '())
  2273. ""))
  2274. (should
  2275. (string= (org-format-outline-path '(nil))
  2276. ""))
  2277. ;; Empty path and prefix.
  2278. (should
  2279. (string= (org-format-outline-path '() nil ">>")
  2280. ">>"))
  2281. ;; Trailing whitespace in headings.
  2282. (should
  2283. (string= (org-format-outline-path (list "one\t" "tw o " "three "))
  2284. "one/tw o/three"))
  2285. ;; Non-default prefix and separators.
  2286. (should
  2287. (string= (org-format-outline-path (list "one" "two" "three") nil ">>" "|")
  2288. ">>|one|two|three"))
  2289. ;; Truncate.
  2290. (should
  2291. (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
  2292. "one/two/.."))
  2293. ;; Give a very narrow width.
  2294. (should
  2295. (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
  2296. "on"))
  2297. ;; Give a prefix that extends beyond the width.
  2298. (should
  2299. (string= (org-format-outline-path (list "one" "two" "three" "four") 10
  2300. ">>>>>>>>>>")
  2301. ">>>>>>>>..")))
  2302. (ert-deftest test-org/org-find-olp ()
  2303. "Test `org-find-olp' specifications."
  2304. (org-test-with-temp-text
  2305. "
  2306. * Headline
  2307. ** COMMENT headline2
  2308. ** TODO headline3
  2309. *** [#A] headline4 :tags:
  2310. ** [#A]headline5
  2311. ** [0%] headline6
  2312. ** headline7 [100%]
  2313. ** headline8 [1/5] :some:more:tags:
  2314. * Test
  2315. "
  2316. (should (org-find-olp '("Headline") t))
  2317. (should-error (org-find-olp '("Headline" "Test") t))
  2318. (should-error (org-find-olp '("Headlinealksjd") t))
  2319. (should (org-find-olp '("Headline" "headline2") t))
  2320. (should (org-find-olp '("Headline" "headline3") t))
  2321. (should (org-find-olp '("Headline" "headline3" "headline4") t))
  2322. (should-error (org-find-olp '("Headline" "headline5") t))
  2323. (should (org-find-olp '("Headline" "headline6") t))
  2324. (should (org-find-olp '("Headline" "headline7") t))
  2325. (should (org-find-olp '("Headline" "headline8") t))))
  2326. (ert-deftest test-org/map-entries ()
  2327. "Test `org-map-entries' specifications."
  2328. ;; Full match.
  2329. (should
  2330. (equal '(1 11)
  2331. (org-test-with-temp-text "* Level 1\n** Level 2"
  2332. (org-map-entries #'point))))
  2333. ;; Level match.
  2334. (should
  2335. (equal '(1)
  2336. (org-test-with-temp-text "* Level 1\n** Level 2"
  2337. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL=1")))))
  2338. (should
  2339. (equal '(11)
  2340. (org-test-with-temp-text "* Level 1\n** Level 2"
  2341. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL>1")))))
  2342. ;; Tag match.
  2343. (should
  2344. (equal '(11)
  2345. (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
  2346. (org-map-entries #'point "yes"))))
  2347. (should
  2348. (equal '(14)
  2349. (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
  2350. (org-map-entries #'point "+yes-a"))))
  2351. (should
  2352. (equal '(11 23)
  2353. (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
  2354. (org-map-entries #'point "{yes?}"))))
  2355. ;; Priority match.
  2356. (should
  2357. (equal '(1)
  2358. (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
  2359. (org-map-entries #'point "PRIORITY=\"A\""))))
  2360. ;; Date match.
  2361. (should
  2362. (equal '(36)
  2363. (org-test-with-temp-text "
  2364. * H1
  2365. SCHEDULED: <2012-03-29 thu.>
  2366. * H2
  2367. SCHEDULED: <2014-03-04 tue.>"
  2368. (org-map-entries #'point "SCHEDULED=\"<2014-03-04 tue.>\""))))
  2369. (should
  2370. (equal '(2)
  2371. (org-test-with-temp-text "
  2372. * H1
  2373. SCHEDULED: <2012-03-29 thu.>
  2374. * H2
  2375. SCHEDULED: <2014-03-04 tue.>"
  2376. (org-map-entries #'point "SCHEDULED<\"<2013-01-01>\""))))
  2377. ;; Regular property match.
  2378. (should
  2379. (equal '(2)
  2380. (org-test-with-temp-text "
  2381. * H1
  2382. :PROPERTIES:
  2383. :TEST: 1
  2384. :END:
  2385. * H2
  2386. :PROPERTIES:
  2387. :TEST: 2
  2388. :END:"
  2389. (org-map-entries #'point "TEST=1"))))
  2390. ;; Multiple criteria.
  2391. (should
  2392. (equal '(23)
  2393. (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
  2394. (let (org-odd-levels-only
  2395. (org-use-tag-inheritance nil))
  2396. (org-map-entries #'point "yes+LEVEL=1")))))
  2397. ;; "or" criteria.
  2398. (should
  2399. (equal '(12 24)
  2400. (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
  2401. (let (org-odd-levels-only)
  2402. (org-map-entries #'point "LEVEL=2|no")))))
  2403. (should
  2404. (equal '(1 12)
  2405. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
  2406. (let (org-odd-levels-only)
  2407. (org-map-entries #'point "yes|no")))))
  2408. ;; "and" criteria.
  2409. (should
  2410. (equal '(22)
  2411. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
  2412. (let (org-odd-levels-only)
  2413. (org-map-entries #'point "yes&no")))))
  2414. ;; Setting `org-map-continue-from'
  2415. (should
  2416. (string= ""
  2417. (org-test-with-temp-text "* H1\n* H2\n* H3n* H4"
  2418. (org-map-entries
  2419. (lambda ()
  2420. (org-cut-subtree)
  2421. (setq org-map-continue-from (point))))
  2422. (buffer-string))))
  2423. (should
  2424. (string= "* H1\n* H2\n* H3\n"
  2425. (org-test-with-temp-text "* H1\n* H2\n* H3\n* H4"
  2426. (org-map-entries
  2427. (lambda ()
  2428. (when (string= "H4"
  2429. (org-element-property
  2430. :raw-value (org-element-at-point)))
  2431. (org-cut-subtree)
  2432. (setq org-map-continue-from
  2433. (org-element-property
  2434. :begin (org-element-at-point))))))
  2435. (buffer-string)))))
  2436. (ert-deftest test-org/edit-headline ()
  2437. "Test `org-edit-headline' specifications."
  2438. (should
  2439. (equal "* B"
  2440. (org-test-with-temp-text "* A"
  2441. (org-edit-headline "B")
  2442. (buffer-string))))
  2443. ;; Handle empty headings.
  2444. (should
  2445. (equal "* "
  2446. (org-test-with-temp-text "* A"
  2447. (org-edit-headline "")
  2448. (buffer-string))))
  2449. (should
  2450. (equal "* A"
  2451. (org-test-with-temp-text "* "
  2452. (org-edit-headline "A")
  2453. (buffer-string))))
  2454. ;; Handle TODO keywords and priority cookies.
  2455. (should
  2456. (equal "* TODO B"
  2457. (org-test-with-temp-text "* TODO A"
  2458. (org-edit-headline "B")
  2459. (buffer-string))))
  2460. (should
  2461. (equal "* [#A] B"
  2462. (org-test-with-temp-text "* [#A] A"
  2463. (org-edit-headline "B")
  2464. (buffer-string))))
  2465. (should
  2466. (equal "* TODO [#A] B"
  2467. (org-test-with-temp-text "* TODO [#A] A"
  2468. (org-edit-headline "B")
  2469. (buffer-string))))
  2470. ;; Handle tags.
  2471. (equal "* B :tag:"
  2472. (org-test-with-temp-text "* A :tag:"
  2473. (let ((org-tags-column 4)) (org-edit-headline "B"))
  2474. (buffer-string))))
  2475. ;;; Keywords
  2476. (ert-deftest test-org/set-regexps-and-options ()
  2477. "Test `org-set-regexps-and-options' specifications."
  2478. ;; TAGS keyword.
  2479. (should
  2480. (equal '(("A"))
  2481. (let ((org-tag-alist '(("A")))
  2482. (org-tag-persistent-alist nil))
  2483. (org-test-with-temp-text ""
  2484. (org-mode-restart)
  2485. org-current-tag-alist))))
  2486. (should
  2487. (equal '(("B"))
  2488. (let ((org-tag-alist '(("A")))
  2489. (org-tag-persistent-alist nil))
  2490. (org-test-with-temp-text "#+TAGS: B"
  2491. (org-mode-restart)
  2492. org-current-tag-alist))))
  2493. (should
  2494. (equal '(("C") ("B"))
  2495. (let ((org-tag-alist '(("A")))
  2496. (org-tag-persistent-alist '(("C"))))
  2497. (org-test-with-temp-text "#+TAGS: B"
  2498. (org-mode-restart)
  2499. org-current-tag-alist))))
  2500. (should
  2501. (equal '(("B"))
  2502. (let ((org-tag-alist '(("A")))
  2503. (org-tag-persistent-alist '(("C"))))
  2504. (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
  2505. (org-mode-restart)
  2506. org-current-tag-alist))))
  2507. (should
  2508. (equal '(("A" . ?a) ("B") ("C"))
  2509. (let ((org-tag-persistant-alist nil))
  2510. (org-test-with-temp-text "#+TAGS: A(a) B C"
  2511. (org-mode-restart)
  2512. org-current-tag-alist))))
  2513. (should
  2514. (equal '(("A") (:newline) ("B"))
  2515. (let ((org-tag-persistent-alist nil))
  2516. (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
  2517. (org-mode-restart)
  2518. org-current-tag-alist))))
  2519. (should
  2520. (equal '((:startgroup) ("A") ("B") (:endgroup) ("C"))
  2521. (let ((org-tag-persistent-alist nil))
  2522. (org-test-with-temp-text "#+TAGS: { A B } C"
  2523. (org-mode-restart)
  2524. org-current-tag-alist))))
  2525. (should
  2526. (equal '((:startgroup) ("A") (:grouptags) ("B") ("C") (:endgroup))
  2527. (let ((org-tag-persistent-alist nil))
  2528. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2529. (org-mode-restart)
  2530. org-current-tag-alist))))
  2531. (should
  2532. (equal '(("A" "B" "C"))
  2533. (let ((org-tag-persistent-alist nil))
  2534. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2535. (org-mode-restart)
  2536. org-tag-groups-alist))))
  2537. (should
  2538. (equal '((:startgrouptag) ("A") (:grouptags) ("B") ("C") (:endgrouptag))
  2539. (let ((org-tag-persistent-alist nil))
  2540. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2541. (org-mode-restart)
  2542. org-current-tag-alist))))
  2543. (should
  2544. (equal '(("A" "B" "C"))
  2545. (let ((org-tag-persistent-alist nil))
  2546. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2547. (org-mode-restart)
  2548. org-tag-groups-alist))))
  2549. (should-not
  2550. (let ((org-tag-alist '(("A"))))
  2551. (org-test-with-temp-text "#+TAGS:"
  2552. (org-mode-restart)
  2553. org-current-tag-alist)))
  2554. ;; FILETAGS keyword.
  2555. (should
  2556. (equal '("A" "B" "C")
  2557. (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
  2558. (org-mode-restart)
  2559. org-file-tags)))
  2560. ;; PROPERTY keyword. Property names are case-insensitive.
  2561. (should
  2562. (equal "foo=1"
  2563. (org-test-with-temp-text "#+PROPERTY: var foo=1"
  2564. (org-mode-restart)
  2565. (cdr (assoc "var" org-keyword-properties)))))
  2566. (should
  2567. (equal
  2568. "foo=1 bar=2"
  2569. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
  2570. (org-mode-restart)
  2571. (cdr (assoc "var" org-keyword-properties)))))
  2572. (should
  2573. (equal
  2574. "foo=1 bar=2"
  2575. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
  2576. (org-mode-restart)
  2577. (cdr (assoc "var" org-keyword-properties)))))
  2578. ;; ARCHIVE keyword.
  2579. (should
  2580. (equal "%s_done::"
  2581. (org-test-with-temp-text "#+ARCHIVE: %s_done::"
  2582. (org-mode-restart)
  2583. org-archive-location)))
  2584. ;; CATEGORY keyword.
  2585. (should
  2586. (eq 'test
  2587. (org-test-with-temp-text "#+CATEGORY: test"
  2588. (org-mode-restart)
  2589. org-category)))
  2590. (should
  2591. (equal "test"
  2592. (org-test-with-temp-text "#+CATEGORY: test"
  2593. (org-mode-restart)
  2594. (cdr (assoc "CATEGORY" org-keyword-properties)))))
  2595. ;; COLUMNS keyword.
  2596. (should
  2597. (equal "%25ITEM %TAGS %PRIORITY %TODO"
  2598. (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
  2599. (org-mode-restart)
  2600. org-columns-default-format)))
  2601. ;; CONSTANTS keyword. Constants names are case sensitive.
  2602. (should
  2603. (equal '("299792458." "3.14")
  2604. (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
  2605. (org-mode-restart)
  2606. (mapcar
  2607. (lambda (n) (cdr (assoc n org-table-formula-constants-local)))
  2608. '("c" "pi")))))
  2609. (should
  2610. (equal "3.14"
  2611. (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
  2612. (org-mode-restart)
  2613. (cdr (assoc "pi" org-table-formula-constants-local)))))
  2614. (should
  2615. (equal "22/7"
  2616. (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
  2617. (org-mode-restart)
  2618. (cdr (assoc "PI" org-table-formula-constants-local)))))
  2619. ;; LINK keyword.
  2620. (should
  2621. (equal
  2622. '("url1" "url2")
  2623. (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
  2624. (org-mode-restart)
  2625. (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local)))
  2626. '("a" "b")))))
  2627. ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
  2628. (should
  2629. (equal
  2630. '(?X ?Z ?Y)
  2631. (org-test-with-temp-text "#+PRIORITIES: X Z Y"
  2632. (org-mode-restart)
  2633. (list org-priority-highest org-priority-lowest org-priority-default))))
  2634. (should
  2635. (equal
  2636. '(?A ?C ?B)
  2637. (org-test-with-temp-text "#+PRIORITIES: X Z"
  2638. (org-mode-restart)
  2639. (list org-priority-highest org-priority-lowest org-priority-default))))
  2640. ;; STARTUP keyword.
  2641. (should
  2642. (equal '(t t)
  2643. (org-test-with-temp-text "#+STARTUP: fold odd"
  2644. (org-mode-restart)
  2645. (list org-startup-folded org-odd-levels-only))))
  2646. ;; TODO keywords.
  2647. (should
  2648. (equal '(("A" "B") ("C"))
  2649. (org-test-with-temp-text "#+TODO: A B | C"
  2650. (org-mode-restart)
  2651. (list org-not-done-keywords org-done-keywords))))
  2652. (should
  2653. (equal '(("A" "C") ("B" "D"))
  2654. (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
  2655. (org-mode-restart)
  2656. (list org-not-done-keywords org-done-keywords))))
  2657. (should
  2658. (equal '(("A" "B") ("C"))
  2659. (org-test-with-temp-text "#+TYP_TODO: A B | C"
  2660. (org-mode-restart)
  2661. (list org-not-done-keywords org-done-keywords))))
  2662. (should
  2663. (equal '((:startgroup) ("A" . ?a) (:endgroup))
  2664. (org-test-with-temp-text "#+TODO: A(a)"
  2665. (org-mode-restart)
  2666. org-todo-key-alist)))
  2667. (should
  2668. (equal '(("D" note nil) ("C" time nil) ("B" note time))
  2669. (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
  2670. (org-mode-restart)
  2671. org-todo-log-states)))
  2672. ;; Enter SETUPFILE keyword.
  2673. (should
  2674. (equal "1"
  2675. (org-test-with-temp-text
  2676. (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
  2677. (org-mode-restart)
  2678. (cdr (assoc "a" org-keyword-properties))))))
  2679. (ert-deftest test-org/collect-keywords ()
  2680. "Test `org-collect-keywords'."
  2681. (should-not
  2682. (org-test-with-temp-text "#+begin_example\n#+foo: bar\n#+end_example"
  2683. (org-collect-keywords '("FOO")))))
  2684. ;;; Links
  2685. ;;;; Coderefs
  2686. (ert-deftest test-org/coderef ()
  2687. "Test coderef links specifications."
  2688. (should
  2689. (org-test-with-temp-text "
  2690. #+BEGIN_SRC emacs-lisp
  2691. \(+ 1 1) (ref:sc)
  2692. #+END_SRC
  2693. \[[(sc)<point>]]"
  2694. (org-open-at-point)
  2695. (looking-at "(ref:sc)")))
  2696. ;; Find coderef even with alternate label format.
  2697. (should
  2698. (org-test-with-temp-text "
  2699. #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
  2700. \(+ 1 1) {ref:sc}
  2701. #+END_SRC
  2702. \[[(sc)<point>]]"
  2703. (org-open-at-point)
  2704. (looking-at "{ref:sc}"))))
  2705. ;;;; Custom ID
  2706. (ert-deftest test-org/custom-id ()
  2707. "Test custom ID links specifications."
  2708. (should
  2709. (org-test-with-temp-text
  2710. "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2711. (org-open-at-point)
  2712. (looking-at-p "\\* H1")))
  2713. ;; Handle escape characters.
  2714. (should
  2715. (org-test-with-temp-text
  2716. "* H1\n:PROPERTIES:\n:CUSTOM_ID: [%]\n:END:\n* H2\n[[#\\[%\\]<point>]]"
  2717. (org-open-at-point)
  2718. (looking-at-p "\\* H1")))
  2719. ;; Throw an error on false positives.
  2720. (should-error
  2721. (org-test-with-temp-text
  2722. "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2723. (org-open-at-point)
  2724. (looking-at-p "\\* H1"))))
  2725. ;;;; Fuzzy Links
  2726. ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
  2727. ;; a named element (#+name: text) and to headlines (* Text).
  2728. (ert-deftest test-org/fuzzy-links ()
  2729. "Test fuzzy links specifications."
  2730. ;; Fuzzy link goes in priority to a matching target.
  2731. (should
  2732. (org-test-with-temp-text
  2733. "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
  2734. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2735. (looking-at "<<Test>>")))
  2736. ;; Then fuzzy link points to an element with a given name.
  2737. (should
  2738. (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
  2739. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2740. (looking-at "#\\+NAME: Test")))
  2741. ;; A target still lead to a matching headline otherwise.
  2742. (should
  2743. (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
  2744. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2745. (looking-at "\\* Head2")))
  2746. ;; With a leading star in link, enforce heading match.
  2747. (should
  2748. (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
  2749. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2750. (looking-at "\\* Test")))
  2751. ;; With a leading star in link, enforce exact heading match, even
  2752. ;; with `org-link-search-must-match-exact-headline' set to nil.
  2753. (should-error
  2754. (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
  2755. (let ((org-link-search-must-match-exact-headline nil))
  2756. (org-open-at-point))))
  2757. ;; Handle non-nil `org-link-search-must-match-exact-headline'.
  2758. (should
  2759. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
  2760. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2761. (looking-at "\\* Test")))
  2762. (should
  2763. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
  2764. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2765. (looking-at "\\* Test")))
  2766. ;; Heading match should not care about spaces, cookies, TODO
  2767. ;; keywords, priorities, and tags. However, TODO keywords are
  2768. ;; case-sensitive.
  2769. (should
  2770. (let ((first-line
  2771. "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
  2772. (org-test-with-temp-text
  2773. (concat first-line "\nFoo Bar\n<point>[[*Test 1 2]]")
  2774. (let ((org-link-search-must-match-exact-headline nil)
  2775. (org-todo-regexp "TODO"))
  2776. (org-open-at-point))
  2777. (looking-at (regexp-quote first-line)))))
  2778. (should-error
  2779. (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
  2780. (let ((org-link-search-must-match-exact-headline nil)
  2781. (org-todo-regexp "TODO"))
  2782. (org-open-at-point))))
  2783. ;; Heading match should still be exact.
  2784. (should-error
  2785. (org-test-with-temp-text "
  2786. ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
  2787. Foo Bar
  2788. <point>[[*Test 1]]"
  2789. (let ((org-link-search-must-match-exact-headline nil)
  2790. (org-todo-regexp "TODO"))
  2791. (org-open-at-point))))
  2792. (should
  2793. (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
  2794. (let ((org-link-search-must-match-exact-headline nil)
  2795. (org-todo-regexp "TODO"))
  2796. (org-open-at-point))
  2797. (looking-at-p (regexp-quote "** Test 1 2"))))
  2798. ;; Heading match ignores COMMENT keyword.
  2799. (should
  2800. (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
  2801. (org-open-at-point)
  2802. (looking-at "\\* COMMENT Test")))
  2803. (should
  2804. (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
  2805. (org-open-at-point)
  2806. (looking-at "\\* TODO COMMENT Test")))
  2807. ;; Correctly un-escape fuzzy links.
  2808. (should
  2809. (org-test-with-temp-text "* [foo]\n[[*\\[foo\\]][With escaped characters]]"
  2810. (org-open-at-point)
  2811. (bobp)))
  2812. ;; Match search strings containing newline characters, including
  2813. ;; blank lines.
  2814. (should
  2815. (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
  2816. (let ((file (buffer-file-name)))
  2817. (goto-char (point-max))
  2818. (insert (format "[[file:%s::line1 line2]]" file))
  2819. (beginning-of-line)
  2820. (let ((org-link-search-must-match-exact-headline nil))
  2821. (org-open-at-point 0))
  2822. (looking-at-p "line1"))))
  2823. (should
  2824. (org-test-with-temp-text-in-file "Paragraph\n\nline1\n\nline2\n\n"
  2825. (let ((file (buffer-file-name)))
  2826. (goto-char (point-max))
  2827. (insert (format "[[file:%s::line1 line2]]" file))
  2828. (beginning-of-line)
  2829. (let ((org-link-search-must-match-exact-headline nil))
  2830. (org-open-at-point 0))
  2831. (looking-at-p "line1")))))
  2832. ;;;; Open at point
  2833. (ert-deftest test-org/open-at-point/keyword ()
  2834. "Does `org-open-at-point' open link in a keyword line?"
  2835. (should
  2836. (org-test-with-temp-text
  2837. "<<top>>\n#+KEYWORD: <point>[[top]]"
  2838. (org-open-at-point) t))
  2839. (should
  2840. (org-test-with-temp-text
  2841. "* H\n<<top>>\n#+KEYWORD: <point>[[top]]"
  2842. (org-open-at-point) t)))
  2843. (ert-deftest test-org/open-at-point/property ()
  2844. "Does `org-open-at-point' open link in property drawer?"
  2845. (should
  2846. (org-test-with-temp-text
  2847. "* Headline
  2848. :PROPERTIES:
  2849. :URL: <point>[[*Headline]]
  2850. :END:"
  2851. (org-open-at-point) t)))
  2852. (ert-deftest test-org/open-at-point/comment ()
  2853. "Does `org-open-at-point' open link in a commented line?"
  2854. (should
  2855. (org-test-with-temp-text
  2856. "<<top>>\n# <point>[[top]]"
  2857. (org-open-at-point) t))
  2858. (should
  2859. (org-test-with-temp-text
  2860. "* H\n<<top>>\n# <point>[[top]]"
  2861. (org-open-at-point) t)))
  2862. (ert-deftest test-org/open-at-point/inline-image ()
  2863. "Test `org-open-at-point' on nested links."
  2864. (should
  2865. (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
  2866. (org-open-at-point)
  2867. (bobp))))
  2868. (ert-deftest test-org/open-at-point/radio-target ()
  2869. "Test `org-open-at-point' on radio targets."
  2870. (should
  2871. (org-test-with-temp-text "<<<target>>> <point>target"
  2872. (org-update-radio-target-regexp)
  2873. (org-open-at-point)
  2874. (eq (org-element-type (org-element-context)) 'radio-target))))
  2875. (ert-deftest test-org/open-at-point/radio-target-shadowed ()
  2876. "Test `org-open-at-point' on shadowed radio targets."
  2877. (should
  2878. (org-test-with-temp-text
  2879. "<<<target shadowed>>> <<<target>>> <point>target shadowed"
  2880. (org-update-radio-target-regexp)
  2881. (org-open-at-point)
  2882. (string=
  2883. (org-element-property :value
  2884. (org-element-radio-target-parser))
  2885. "target shadowed"))))
  2886. (ert-deftest test-org/open-at-point/tag ()
  2887. "Test `org-open-at-point' on tags."
  2888. (should
  2889. (org-test-with-temp-text "* H :<point>tag:"
  2890. (catch :result
  2891. (cl-letf (((symbol-function 'org-tags-view)
  2892. (lambda (&rest args) (throw :result t))))
  2893. (org-open-at-point)
  2894. nil))))
  2895. (should-not
  2896. (org-test-with-temp-text-in-file "* H<point> :tag:"
  2897. (catch :result
  2898. (cl-letf (((symbol-function 'org-tags-view)
  2899. (lambda (&rest args) (throw :result t))))
  2900. ;; When point isn't on a tag it's going to try other things,
  2901. ;; possibly trying to open attachments which will return an
  2902. ;; error if there isn't an attachment. Suppress that error.
  2903. (ignore-errors
  2904. (org-open-at-point))
  2905. nil)))))
  2906. ;;; Node Properties
  2907. (ert-deftest test-org/accumulated-properties-in-drawers ()
  2908. "Ensure properties accumulate in subtree drawers."
  2909. (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
  2910. (org-babel-next-src-block)
  2911. (should (equal '(2 1) (org-babel-execute-src-block)))))
  2912. (ert-deftest test-org/custom-properties ()
  2913. "Test custom properties specifications."
  2914. ;; Standard test.
  2915. (should
  2916. (let ((org-custom-properties '("FOO")))
  2917. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2918. (org-toggle-custom-properties-visibility)
  2919. (org-invisible-p2))))
  2920. ;; Properties are case-insensitive.
  2921. (should
  2922. (let ((org-custom-properties '("FOO")))
  2923. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
  2924. (org-toggle-custom-properties-visibility)
  2925. (org-invisible-p2))))
  2926. (should
  2927. (let ((org-custom-properties '("foo")))
  2928. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2929. (org-toggle-custom-properties-visibility)
  2930. (org-invisible-p2))))
  2931. ;; Multiple custom properties in the same drawer.
  2932. (should
  2933. (let ((org-custom-properties '("FOO" "BAR")))
  2934. (org-test-with-temp-text
  2935. "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
  2936. (org-fold-reveal)
  2937. (org-toggle-custom-properties-visibility)
  2938. (and (org-invisible-p2)
  2939. (not (progn (forward-line) (org-invisible-p2)))
  2940. (progn (forward-line) (org-invisible-p2))))))
  2941. ;; Hide custom properties with an empty value.
  2942. (should
  2943. (let ((org-custom-properties '("FOO")))
  2944. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
  2945. (org-toggle-custom-properties-visibility)
  2946. (org-invisible-p2))))
  2947. ;; Do not hide fake properties.
  2948. (should-not
  2949. (let ((org-custom-properties '("FOO")))
  2950. (org-test-with-temp-text ":FOO: val\n"
  2951. (org-toggle-custom-properties-visibility)
  2952. (org-invisible-p2))))
  2953. (should-not
  2954. (let ((org-custom-properties '("A")))
  2955. (org-test-with-temp-text
  2956. "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
  2957. (org-fold-reveal)
  2958. (org-toggle-custom-properties-visibility)
  2959. (org-invisible-p2)))))
  2960. ;;; Mark Region
  2961. (ert-deftest test-org/mark-element ()
  2962. "Test `org-mark-element' specifications."
  2963. ;; Mark beginning and end of element.
  2964. (should
  2965. (equal '(t t)
  2966. (org-test-with-temp-text "Para<point>graph"
  2967. (org-mark-element)
  2968. (list (bobp) (= (mark) (point-max))))))
  2969. (should
  2970. (equal '(t t)
  2971. (org-test-with-temp-text "P1\n\nPara<point>graph\n\nP2"
  2972. (org-mark-element)
  2973. (list (looking-at "Paragraph")
  2974. (org-with-point-at (mark) (looking-at "P2"))))))
  2975. ;; Do not set mark past (point-max).
  2976. (should
  2977. (org-test-with-temp-text "Para<point>graph"
  2978. (narrow-to-region 2 6)
  2979. (org-mark-element)
  2980. (= 6 (mark)))))
  2981. (ert-deftest test-org/mark-subtree ()
  2982. "Test `org-mark-subtree' specifications."
  2983. ;; Error when point is before first headline.
  2984. (should-error
  2985. (org-test-with-temp-text "Paragraph\n* Headline\nBody"
  2986. (progn (transient-mark-mode 1)
  2987. (org-mark-subtree))))
  2988. ;; Without argument, mark current subtree.
  2989. (should
  2990. (equal
  2991. '(12 32)
  2992. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  2993. (progn (transient-mark-mode 1)
  2994. (forward-line 2)
  2995. (org-mark-subtree)
  2996. (list (region-beginning) (region-end))))))
  2997. ;; With an argument, move ARG up.
  2998. (should
  2999. (equal
  3000. '(1 32)
  3001. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  3002. (progn (transient-mark-mode 1)
  3003. (forward-line 2)
  3004. (org-mark-subtree 1)
  3005. (list (region-beginning) (region-end))))))
  3006. ;; Do not get fooled by inlinetasks.
  3007. (when (featurep 'org-inlinetask)
  3008. (should
  3009. (= 1
  3010. (org-test-with-temp-text "* Headline\n*************** Task\nContents"
  3011. (progn (transient-mark-mode 1)
  3012. (forward-line 1)
  3013. (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
  3014. (region-beginning)))))))
  3015. ;;; Miscellaneous
  3016. (ert-deftest test-org/sort-entries ()
  3017. "Test `org-sort-entries'."
  3018. ;; Sort alphabetically.
  3019. (should
  3020. (equal "\n* abc\n* def\n* xyz\n"
  3021. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  3022. (org-sort-entries nil ?a)
  3023. (buffer-string))))
  3024. (should
  3025. (equal "\n* xyz\n* def\n* abc\n"
  3026. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  3027. (org-sort-entries nil ?A)
  3028. (buffer-string))))
  3029. (should
  3030. (equal "\n* \n* klm\n* xyz\n"
  3031. (org-test-with-temp-text "\n* xyz\n* \n* klm\n"
  3032. (org-sort-entries nil ?a)
  3033. (buffer-string))))
  3034. ;; Sort numerically.
  3035. (should
  3036. (equal "\n* 1\n* 2\n* 10\n"
  3037. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  3038. (org-sort-entries nil ?n)
  3039. (buffer-string))))
  3040. (should
  3041. (equal "\n* 10\n* 2\n* 1\n"
  3042. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  3043. (org-sort-entries nil ?N)
  3044. (buffer-string))))
  3045. (should
  3046. (equal "\n* \n* 1\n* 2\n"
  3047. (org-test-with-temp-text "\n* 1\n* \n* 2\n"
  3048. (org-sort-entries nil ?n)
  3049. (buffer-string))))
  3050. ;; Sort by custom function.
  3051. (should
  3052. (equal "\n* b\n* aa\n* ccc\n"
  3053. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  3054. (org-sort-entries nil ?f
  3055. (lambda ()
  3056. (length (buffer-substring (point-at-bol)
  3057. (point-at-eol))))
  3058. #'<)
  3059. (buffer-string))))
  3060. (should
  3061. (equal "\n* ccc\n* aa\n* b\n"
  3062. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  3063. (org-sort-entries nil ?F
  3064. (lambda ()
  3065. (length (buffer-substring (point-at-bol)
  3066. (point-at-eol))))
  3067. #'<)
  3068. (buffer-string))))
  3069. ;; Sort by TODO keyword.
  3070. (should
  3071. (equal "\n* TODO h1\n* TODO h3\n* DONE h2\n"
  3072. (org-test-with-temp-text
  3073. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  3074. (org-sort-entries nil ?o)
  3075. (buffer-string))))
  3076. (should
  3077. (equal "\n* DONE h2\n* TODO h1\n* TODO h3\n"
  3078. (org-test-with-temp-text
  3079. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  3080. (org-sort-entries nil ?O)
  3081. (buffer-string))))
  3082. ;; Sort by priority.
  3083. (should
  3084. (equal "\n* [#A] h2\n* [#B] h3\n* [#C] h1\n"
  3085. (org-test-with-temp-text
  3086. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  3087. (org-sort-entries nil ?p)
  3088. (buffer-string))))
  3089. (should
  3090. (equal "\n* [#C] h1\n* [#B] h3\n* [#A] h2\n"
  3091. (org-test-with-temp-text
  3092. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  3093. (org-sort-entries nil ?P)
  3094. (buffer-string))))
  3095. ;; Sort by creation time.
  3096. (should
  3097. (equal "
  3098. * h3
  3099. [2017-05-08 Mon]
  3100. * h2
  3101. [2017-05-09 Tue]
  3102. * h1
  3103. [2018-05-09 Wed]
  3104. "
  3105. (org-test-with-temp-text
  3106. "
  3107. * h1
  3108. [2018-05-09 Wed]
  3109. * h2
  3110. [2017-05-09 Tue]
  3111. * h3
  3112. [2017-05-08 Mon]
  3113. "
  3114. (org-sort-entries nil ?c)
  3115. (buffer-string))))
  3116. ;; Sort by scheduled date.
  3117. (should
  3118. (equal "
  3119. * TODO h4
  3120. SCHEDULED: <2017-05-06 Sat>
  3121. * TODO h3
  3122. SCHEDULED: <2017-05-08 Mon>
  3123. * TODO h2
  3124. DEADLINE: <2017-05-09 Tue>
  3125. * TODO h1
  3126. DEADLINE: <2017-05-07 Sun>
  3127. "
  3128. (org-test-with-temp-text
  3129. "
  3130. * TODO h2
  3131. DEADLINE: <2017-05-09 Tue>
  3132. * TODO h1
  3133. DEADLINE: <2017-05-07 Sun>
  3134. * TODO h3
  3135. SCHEDULED: <2017-05-08 Mon>
  3136. * TODO h4
  3137. SCHEDULED: <2017-05-06 Sat>
  3138. "
  3139. (org-sort-entries nil ?s)
  3140. (buffer-string))))
  3141. ;; Sort by deadline date.
  3142. (should
  3143. (equal "
  3144. * TODO h1
  3145. DEADLINE: <2017-05-07 Sun>
  3146. * TODO h2
  3147. DEADLINE: <2017-05-09 Tue>
  3148. * TODO h3
  3149. SCHEDULED: <2017-05-08 Mon>
  3150. * TODO h4
  3151. SCHEDULED: <2017-05-06 Sat>
  3152. "
  3153. (org-test-with-temp-text
  3154. "
  3155. * TODO h2
  3156. DEADLINE: <2017-05-09 Tue>
  3157. * TODO h1
  3158. DEADLINE: <2017-05-07 Sun>
  3159. * TODO h3
  3160. SCHEDULED: <2017-05-08 Mon>
  3161. * TODO h4
  3162. SCHEDULED: <2017-05-06 Sat>
  3163. "
  3164. (org-sort-entries nil ?d)
  3165. (buffer-string))))
  3166. ;; Sort by any date/time
  3167. (should
  3168. (equal "
  3169. * TODO h4
  3170. SCHEDULED: <2017-05-06 Sat>
  3171. * TODO h1
  3172. DEADLINE: <2017-05-07 Sun>
  3173. * TODO h3
  3174. SCHEDULED: <2017-05-08 Mon>
  3175. * TODO h2
  3176. DEADLINE: <2017-05-09 Tue>
  3177. "
  3178. (org-test-with-temp-text
  3179. "
  3180. * TODO h2
  3181. DEADLINE: <2017-05-09 Tue>
  3182. * TODO h1
  3183. DEADLINE: <2017-05-07 Sun>
  3184. * TODO h3
  3185. SCHEDULED: <2017-05-08 Mon>
  3186. * TODO h4
  3187. SCHEDULED: <2017-05-06 Sat>
  3188. "
  3189. (org-sort-entries nil ?t)
  3190. (buffer-string))))
  3191. ;; Sort by clocking time.
  3192. (should
  3193. (equal "
  3194. * clocked h2
  3195. :LOGBOOK:
  3196. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3197. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  3198. :END:
  3199. * clocked h1
  3200. :LOGBOOK:
  3201. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3202. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  3203. :END:
  3204. "
  3205. (org-test-with-temp-text
  3206. "
  3207. * clocked h1
  3208. :LOGBOOK:
  3209. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3210. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  3211. :END:
  3212. * clocked h2
  3213. :LOGBOOK:
  3214. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3215. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  3216. :END:
  3217. "
  3218. (org-sort-entries nil ?k)
  3219. (buffer-string))))
  3220. ;; Preserve file local variables when sorting.
  3221. (should
  3222. (equal "\n* A\n* B\n# Local Variables:\n# foo: t\n# End:\n"
  3223. (org-test-with-temp-text
  3224. "\n* B\n* A\n# Local Variables:\n# foo: t\n# End:"
  3225. (org-sort-entries nil ?a)
  3226. (buffer-string)))))
  3227. (ert-deftest test-org/string-collate-greaterp ()
  3228. "Test `org-string-collate-greaterp' specifications."
  3229. (should (org-string-collate-greaterp "def" "abc"))
  3230. (should-not (org-string-collate-greaterp "abc" "def")))
  3231. (ert-deftest test-org/file-contents ()
  3232. "Test `org-file-contents' specifications."
  3233. ;; Open files.
  3234. (should
  3235. (string= "#+BIND: variable value
  3236. #+DESCRIPTION: l2
  3237. #+LANGUAGE: en
  3238. #+SELECT_TAGS: b
  3239. #+TITLE: b
  3240. #+PROPERTY: a 1
  3241. " (org-file-contents (expand-file-name "setupfile3.org"
  3242. (concat org-test-dir "examples/")))))
  3243. ;; Throw error when trying to access an invalid file.
  3244. (should-error (org-file-contents "this-file-must-not-exist"))
  3245. ;; Try to access an invalid file, but do not throw an error.
  3246. (should
  3247. (progn (org-file-contents "this-file-must-not-exist" :noerror) t))
  3248. ;; Open URL.
  3249. (should
  3250. (string= "foo"
  3251. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3252. (unwind-protect
  3253. ;; Simulate successful retrieval of a URL.
  3254. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3255. (lambda (&rest_)
  3256. (with-current-buffer buffer
  3257. (insert "HTTP/1.1 200 OK\n\nfoo"))
  3258. buffer)))
  3259. (org-file-contents "http://some-valid-url"))
  3260. (kill-buffer buffer)))))
  3261. ;; Throw error when trying to access an invalid URL.
  3262. (should-error
  3263. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3264. (unwind-protect
  3265. ;; Simulate unsuccessful retrieval of a URL.
  3266. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3267. (lambda (&rest_)
  3268. (with-current-buffer buffer
  3269. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3270. buffer)))
  3271. (org-file-contents "http://this-url-must-not-exist"))
  3272. (kill-buffer buffer))))
  3273. ;; Try to access an invalid URL, but do not throw an error.
  3274. (should-error
  3275. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3276. (unwind-protect
  3277. ;; Simulate unsuccessful retrieval of a URL.
  3278. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3279. (lambda (&rest_)
  3280. (with-current-buffer buffer
  3281. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3282. buffer)))
  3283. (org-file-contents "http://this-url-must-not-exist"))
  3284. (kill-buffer buffer))))
  3285. (should
  3286. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3287. (unwind-protect
  3288. ;; Simulate unsuccessful retrieval of a URL.
  3289. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3290. (lambda (&rest_)
  3291. (with-current-buffer buffer
  3292. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3293. buffer)))
  3294. (org-file-contents "http://this-url-must-not-exist" :noerror))
  3295. (kill-buffer buffer))
  3296. t)))
  3297. ;;; Navigation
  3298. (ert-deftest test-org/next-visible-heading ()
  3299. "Test `org-next-visible-heading' specifications."
  3300. ;; Move to the beginning of the next headline, taking into
  3301. ;; consideration ARG.
  3302. (should
  3303. (org-test-with-temp-text "* H1\n* H2"
  3304. (org-next-visible-heading 1)
  3305. (looking-at "\\* H2")))
  3306. (should
  3307. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3308. (org-next-visible-heading 2)
  3309. (looking-at "\\* H3")))
  3310. ;; Ignore invisible headlines.
  3311. (should
  3312. (org-test-with-temp-text "* H1\n** H2\n* H3"
  3313. (org-cycle)
  3314. (org-next-visible-heading 1)
  3315. (looking-at "\\* H3")))
  3316. ;; Move point between headlines, not on blank lines between.
  3317. (should
  3318. (org-test-with-temp-text "* H1\n** H2\n\n\n\n* H3"
  3319. (let ((org-cycle-separator-lines 1))
  3320. (org-cycle)
  3321. (org-next-visible-heading 1))
  3322. (looking-at "\\* H3")))
  3323. ;; Move at end of buffer when there is no more headline.
  3324. (should
  3325. (org-test-with-temp-text "* H1"
  3326. (org-next-visible-heading 1)
  3327. (eobp)))
  3328. (should
  3329. (org-test-with-temp-text "* H1\n* H2"
  3330. (org-next-visible-heading 2)
  3331. (eobp)))
  3332. ;; With a negative argument, move backwards.
  3333. (should
  3334. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3335. (org-next-visible-heading -1)
  3336. (looking-at "\\* H2")))
  3337. (should
  3338. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3339. (org-next-visible-heading -2)
  3340. (looking-at "\\* H1"))))
  3341. (ert-deftest test-org/previous-visible-heading ()
  3342. "Test `org-previous-visible-heading' specifications."
  3343. ;; Move to the beginning of the next headline, taking into
  3344. ;; consideration ARG.
  3345. (should
  3346. (org-test-with-temp-text "* H1\n<point>* H2"
  3347. (org-previous-visible-heading 1)
  3348. (looking-at "\\* H1")))
  3349. (should
  3350. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3351. (org-previous-visible-heading 2)
  3352. (looking-at "\\* H1")))
  3353. ;; Ignore invisible headlines.
  3354. (should
  3355. (org-test-with-temp-text "* H1\n** H2\n<point>* H3"
  3356. (org-overview)
  3357. (org-previous-visible-heading 1)
  3358. (looking-at "\\* H1")))
  3359. ;; Move point between headlines, not on blank lines between.
  3360. (should
  3361. (org-test-with-temp-text "* H1\n\n\n\n** H2\n<point>* H3"
  3362. (let ((org-cycle-separator-lines 1))
  3363. (org-overview)
  3364. (org-previous-visible-heading 1))
  3365. (looking-at "\\* H1")))
  3366. ;; Move at end of buffer when there is no more headline.
  3367. (should
  3368. (org-test-with-temp-text "* H1"
  3369. (org-previous-visible-heading 1)
  3370. (bobp)))
  3371. (should
  3372. (org-test-with-temp-text "* H1\n* <point>H2"
  3373. (org-previous-visible-heading 2)
  3374. (bobp)))
  3375. ;; Invisible parts may not start at a headline, i.e., when revealing
  3376. ;; parts of the buffer. Handle this.
  3377. (should
  3378. (org-test-with-temp-text "* Main\n** H1\nFoo\n** H2\nBar\n** H3\nBaz"
  3379. (org-overview)
  3380. (search-forward "H1")
  3381. (org-show-context 'minimal)
  3382. (org-cycle)
  3383. (search-forward "H3")
  3384. (org-show-context 'minimal)
  3385. ;; At this point, buffer displays, with point at "|",
  3386. ;;
  3387. ;; * Main
  3388. ;; ** H1
  3389. ;; Foo
  3390. ;; ** H3|
  3391. (org-previous-visible-heading 1)
  3392. (looking-at "\\*+ H1"))))
  3393. (ert-deftest test-org/forward-heading-same-level ()
  3394. "Test `org-forward-heading-same-level' specifications."
  3395. ;; Test navigation at top level, forward and backward.
  3396. (should
  3397. (equal "* H2"
  3398. (org-test-with-temp-text "* H1\n* H2"
  3399. (org-forward-heading-same-level 1)
  3400. (buffer-substring-no-properties (point) (line-end-position)))))
  3401. (should
  3402. (equal "* H1"
  3403. (org-test-with-temp-text "* H1\n<point>* H2"
  3404. (org-forward-heading-same-level -1)
  3405. (buffer-substring-no-properties (point) (line-end-position)))))
  3406. ;; Test navigation in a sub-tree, forward and backward.
  3407. (should
  3408. (equal "* H2"
  3409. (org-test-with-temp-text "* H1\n** H11\n** H12\n* H2"
  3410. (org-forward-heading-same-level 1)
  3411. (buffer-substring-no-properties (point) (line-end-position)))))
  3412. (should
  3413. (equal "* H1"
  3414. (org-test-with-temp-text "* H1\n** H11\n** H12\n<point>* H2"
  3415. (org-forward-heading-same-level -1)
  3416. (buffer-substring-no-properties (point) (line-end-position)))))
  3417. ;; Stop at first or last sub-heading.
  3418. (should-not
  3419. (equal "* H2"
  3420. (org-test-with-temp-text "* H1\n** H11\n<point>** H12\n* H2"
  3421. (org-forward-heading-same-level 1)
  3422. (buffer-substring-no-properties (point) (line-end-position)))))
  3423. (should-not
  3424. (equal "* H2"
  3425. (org-test-with-temp-text "* H1\n<point>** H11\n** H12\n* H2"
  3426. (org-forward-heading-same-level -1)
  3427. (buffer-substring-no-properties (point) (line-end-position)))))
  3428. ;; Allow multiple moves.
  3429. (should
  3430. (equal "* H3"
  3431. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3432. (org-forward-heading-same-level 2)
  3433. (buffer-substring-no-properties (point) (line-end-position)))))
  3434. (should
  3435. (equal "* H1"
  3436. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3437. (org-forward-heading-same-level -2)
  3438. (buffer-substring-no-properties (point) (line-end-position)))))
  3439. ;; Ignore spurious moves when first (or last) sibling is reached.
  3440. (should
  3441. (equal "** H3"
  3442. (org-test-with-temp-text "* First\n<point>** H1\n** H2\n** H3\n* Last"
  3443. (org-forward-heading-same-level 100)
  3444. (buffer-substring-no-properties (point) (line-end-position)))))
  3445. (should
  3446. (equal "** H1"
  3447. (org-test-with-temp-text "* First\n** H1\n** H2\n<point>** H3\n* Last"
  3448. (org-forward-heading-same-level -100)
  3449. (buffer-substring-no-properties (point) (line-end-position))))))
  3450. (ert-deftest test-org/end-of-meta-data ()
  3451. "Test `org-end-of-meta-data' specifications."
  3452. ;; Skip planning line.
  3453. (should
  3454. (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
  3455. (org-end-of-meta-data)
  3456. (eobp)))
  3457. ;; Skip properties drawer.
  3458. (should
  3459. (org-test-with-temp-text
  3460. "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
  3461. (org-end-of-meta-data)
  3462. (eobp)))
  3463. ;; Skip both.
  3464. (should
  3465. (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
  3466. (org-end-of-meta-data)
  3467. (eobp)))
  3468. ;; Nothing to skip, go to first line.
  3469. (should
  3470. (org-test-with-temp-text "* Headline\nContents"
  3471. (org-end-of-meta-data)
  3472. (looking-at "Contents")))
  3473. ;; With option argument, skip empty lines, regular drawers and
  3474. ;; clocking lines.
  3475. (should
  3476. (org-test-with-temp-text "* Headline\n\nContents"
  3477. (org-end-of-meta-data t)
  3478. (looking-at "Contents")))
  3479. (should
  3480. (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
  3481. (org-end-of-meta-data t)
  3482. (looking-at "Contents")))
  3483. (should
  3484. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
  3485. (org-end-of-meta-data t)
  3486. (looking-at "Contents")))
  3487. ;; Special case: do not skip incomplete drawers.
  3488. (should
  3489. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
  3490. (org-end-of-meta-data t)
  3491. (looking-at ":LOGBOOK:")))
  3492. ;; Special case: Be careful about consecutive headlines.
  3493. (should-not
  3494. (org-test-with-temp-text "* H1\n*H2\nContents"
  3495. (org-end-of-meta-data t)
  3496. (looking-at "Contents"))))
  3497. (ert-deftest test-org/shiftright-heading ()
  3498. "Test `org-shiftright' on headings."
  3499. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  3500. (should
  3501. (equal "* TODO a1\n** a2\n* DONE b1\n"
  3502. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3503. (org-shiftright)
  3504. (buffer-string))))
  3505. (should
  3506. (equal "* TODO a1\n** TODO a2\n* b1\n"
  3507. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3508. (let ((org-loop-over-headlines-in-active-region t))
  3509. (transient-mark-mode 1)
  3510. (push-mark (point) t t)
  3511. (search-forward "* DONE b1")
  3512. (org-shiftright))
  3513. (buffer-string))))
  3514. (should
  3515. (equal "* TODO a1\n** a2\n* b1\n"
  3516. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3517. (let ((org-loop-over-headlines-in-active-region 'start-level))
  3518. (transient-mark-mode 1)
  3519. (push-mark (point) t t)
  3520. (search-forward "* DONE b1")
  3521. (org-shiftright))
  3522. (buffer-string))))))
  3523. (ert-deftest test-org/beginning-of-line ()
  3524. "Test `org-beginning-of-line' specifications."
  3525. ;; Move to beginning of line. If current line in invisible, move to
  3526. ;; beginning of visible line instead.
  3527. (should
  3528. (org-test-with-temp-text "Some text\nSome other text<point>"
  3529. (org-beginning-of-line)
  3530. (bolp)))
  3531. (should
  3532. (org-test-with-temp-text "* H1\n** H2<point>"
  3533. (org-overview)
  3534. (org-beginning-of-line)
  3535. (= (line-beginning-position) 1)))
  3536. ;; With `visual-line-mode' active, move to beginning of visual line.
  3537. (should-not
  3538. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3539. (visual-line-mode)
  3540. (dotimes (i 1000) (insert "very "))
  3541. (org-beginning-of-line)
  3542. (bolp)))
  3543. ;; In a wide headline, with `visual-line-mode', prefer going to the
  3544. ;; beginning of a visual line than to the logical beginning of line,
  3545. ;; even if special movement is active.
  3546. (should-not
  3547. (org-test-with-temp-text "* A <point>long headline"
  3548. (visual-line-mode)
  3549. (dotimes (i 1000) (insert "very "))
  3550. (goto-char (point-max))
  3551. (org-beginning-of-line)
  3552. (bobp)))
  3553. (should-not
  3554. (org-test-with-temp-text "* A <point>long headline"
  3555. (visual-line-mode)
  3556. (dotimes (i 1000) (insert "very "))
  3557. (goto-char (point-max))
  3558. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line))
  3559. (bobp)))
  3560. ;; At an headline with special movement, first move at beginning of
  3561. ;; title, then at the beginning of line, rinse, repeat.
  3562. (should
  3563. (org-test-with-temp-text "* TODO Headline<point>"
  3564. (let ((org-special-ctrl-a/e t))
  3565. (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
  3566. (progn (org-beginning-of-line) (bolp))
  3567. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3568. (should
  3569. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3570. (let ((org-special-ctrl-a/e t))
  3571. (org-beginning-of-line)
  3572. (looking-at "Headline"))))
  3573. (should
  3574. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3575. (let ((org-special-ctrl-a/e '(t . nil)))
  3576. (org-beginning-of-line)
  3577. (looking-at "Headline"))))
  3578. (should-not
  3579. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3580. (let ((org-special-ctrl-a/e '(nil . nil)))
  3581. (org-beginning-of-line)
  3582. (looking-at "Headline"))))
  3583. ;; At an headline with reversed movement, first move to beginning of
  3584. ;; line, then to the beginning of title.
  3585. (should
  3586. (org-test-with-temp-text "* TODO Headline<point>"
  3587. (let ((org-special-ctrl-a/e 'reversed)
  3588. (this-command last-command))
  3589. (and (progn (org-beginning-of-line) (bolp))
  3590. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3591. (should
  3592. (org-test-with-temp-text "* TODO Headline<point>"
  3593. (let ((org-special-ctrl-a/e '(reversed . nil))
  3594. (this-command last-command))
  3595. (and (progn (org-beginning-of-line) (bolp))
  3596. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3597. (should-not
  3598. (org-test-with-temp-text "* TODO Headline<point>"
  3599. (let ((org-special-ctrl-a/e '(t . nil))
  3600. (this-command last-command))
  3601. (and (progn (org-beginning-of-line) (bolp))
  3602. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3603. ;; At an item with special movement, first move after to beginning
  3604. ;; of title, then to the beginning of line, rinse, repeat.
  3605. (should
  3606. (org-test-with-temp-text "- [ ] Item<point>"
  3607. (let ((org-special-ctrl-a/e t))
  3608. (and (progn (org-beginning-of-line) (looking-at-p "Item"))
  3609. (progn (org-beginning-of-line) (bolp))
  3610. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3611. ;; At an item with reversed movement, first move to beginning of
  3612. ;; line, then to the beginning of title.
  3613. (should
  3614. (org-test-with-temp-text "- [X] Item<point>"
  3615. (let ((org-special-ctrl-a/e 'reversed)
  3616. (this-command last-command))
  3617. (and (progn (org-beginning-of-line) (bolp))
  3618. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3619. ;; Leave point before invisible characters at column 0.
  3620. (should
  3621. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3622. (let ((org-special-ctrl-a/e nil))
  3623. (org-beginning-of-line)
  3624. (bolp))))
  3625. (should
  3626. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3627. (let ((org-special-ctrl-a/e t))
  3628. (org-beginning-of-line)
  3629. (bolp))))
  3630. (should
  3631. (org-test-with-temp-text "[[http<point>://orgmode.org]]"
  3632. (visual-line-mode)
  3633. (org-beginning-of-line)
  3634. (bolp)))
  3635. ;; Special case: Do not error when the buffer contains only a single
  3636. ;; asterisk.
  3637. (should
  3638. (org-test-with-temp-text "*<point>"
  3639. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line) t)))
  3640. (should
  3641. (org-test-with-temp-text "*<point>"
  3642. (let ((org-special-ctrl-a/e nil)) (org-beginning-of-line) t))))
  3643. (ert-deftest test-org/end-of-line ()
  3644. "Test `org-end-of-line' specifications."
  3645. ;; Standard test.
  3646. (should
  3647. (org-test-with-temp-text "Some text\nSome other text"
  3648. (org-end-of-line)
  3649. (eolp)))
  3650. ;; With `visual-line-mode' active, move to end of visible line.
  3651. ;; However, never go past ellipsis.
  3652. (should-not
  3653. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3654. (visual-line-mode)
  3655. (dotimes (i 1000) (insert "very "))
  3656. (goto-char (point-min))
  3657. (org-end-of-line)
  3658. (eolp)))
  3659. (should-not
  3660. (org-test-with-temp-text "* A short headline\nSome contents"
  3661. (visual-line-mode)
  3662. (org-overview)
  3663. (org-end-of-line)
  3664. (eobp)))
  3665. ;; In a wide headline, with `visual-line-mode', prefer going to end
  3666. ;; of visible line if tags, or end of line, are farther.
  3667. (should-not
  3668. (org-test-with-temp-text "* A <point>long headline"
  3669. (visual-line-mode)
  3670. (dotimes (i 1000) (insert "very "))
  3671. (goto-char (point-min))
  3672. (org-end-of-line)
  3673. (eolp)))
  3674. (should-not
  3675. (org-test-with-temp-text "* A <point>long headline :tag:"
  3676. (visual-line-mode)
  3677. (dotimes (i 1000) (insert "very "))
  3678. (goto-char (point-min))
  3679. (org-end-of-line)
  3680. (eolp)))
  3681. ;; At an headline without special movement, go to end of line.
  3682. ;; However, never go past ellipsis.
  3683. (should
  3684. (org-test-with-temp-text "* Headline2b :tag:\n"
  3685. (let ((org-special-ctrl-a/e nil))
  3686. (and (progn (org-end-of-line) (eolp))
  3687. (progn (org-end-of-line) (eolp))))))
  3688. (should
  3689. (org-test-with-temp-text "* Headline2b :tag:\n"
  3690. (let ((org-special-ctrl-a/e '(t . nil)))
  3691. (and (progn (org-end-of-line) (eolp))
  3692. (progn (org-end-of-line) (eolp))))))
  3693. (should
  3694. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3695. (org-overview)
  3696. (let ((org-special-ctrl-a/e nil))
  3697. (org-end-of-line)
  3698. (= 1 (line-beginning-position)))))
  3699. ;; At an headline with special movement, first move before tags,
  3700. ;; then at the end of line, rinse, repeat. However, never go past
  3701. ;; ellipsis.
  3702. (should
  3703. (org-test-with-temp-text "* Headline1 :tag:\n"
  3704. (let ((org-special-ctrl-a/e t))
  3705. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3706. (progn (org-end-of-line) (eolp))
  3707. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3708. (should
  3709. (org-test-with-temp-text "* Headline1 :tag:\n"
  3710. (let ((org-special-ctrl-a/e '(nil . t)))
  3711. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3712. (progn (org-end-of-line) (eolp))
  3713. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3714. (should-not
  3715. (org-test-with-temp-text "* Headline1 :tag:\n"
  3716. (let ((org-special-ctrl-a/e '(nil . nil)))
  3717. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3718. (progn (org-end-of-line) (eolp))
  3719. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3720. (should
  3721. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3722. (org-overview)
  3723. (let ((org-special-ctrl-a/e t))
  3724. (org-end-of-line)
  3725. (org-end-of-line)
  3726. (= 1 (line-beginning-position)))))
  3727. ;; At an headline, with reversed movement, first go to end of line,
  3728. ;; then before tags. However, never go past ellipsis.
  3729. (should
  3730. (org-test-with-temp-text "* Headline3 :tag:\n"
  3731. (let ((org-special-ctrl-a/e 'reversed)
  3732. (this-command last-command))
  3733. (and (progn (org-end-of-line) (eolp))
  3734. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3735. (should
  3736. (org-test-with-temp-text "* Headline3 :tag:\n"
  3737. (let ((org-special-ctrl-a/e '(nil . reversed))
  3738. (this-command last-command))
  3739. (and (progn (org-end-of-line) (eolp))
  3740. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3741. (should-not
  3742. (org-test-with-temp-text "* Headline3 :tag:\n"
  3743. (let ((org-special-ctrl-a/e '(nil . t))
  3744. (this-command last-command))
  3745. (and (progn (org-end-of-line) (eolp))
  3746. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3747. (should
  3748. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3749. (org-overview)
  3750. (let ((org-special-ctrl-a/e 'reversed))
  3751. (org-end-of-line)
  3752. (= 1 (line-beginning-position)))))
  3753. ;; At a block without hidden contents.
  3754. (should
  3755. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3756. (progn (org-end-of-line) (eolp))))
  3757. ;; At a block with hidden contents.
  3758. (should-not
  3759. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3760. (let ((org-special-ctrl-a/e t))
  3761. (org-fold-hide-block-toggle)
  3762. (org-end-of-line)
  3763. (eobp))))
  3764. ;; Get past invisible characters at the end of line.
  3765. (should
  3766. (org-test-with-temp-text "[[https://orgmode.org]]"
  3767. (org-end-of-line)
  3768. (eolp))))
  3769. (ert-deftest test-org/open-line ()
  3770. "Test `org-open-line' specifications."
  3771. ;; Call `open-line' outside of tables.
  3772. (should
  3773. (equal "\nText"
  3774. (org-test-with-temp-text "Text"
  3775. (org-open-line 1)
  3776. (buffer-string))))
  3777. ;; At a table, create a row above.
  3778. (should
  3779. (equal "\n| |\n| a |"
  3780. (org-test-with-temp-text "\n<point>| a |"
  3781. (org-open-line 1)
  3782. (buffer-string))))
  3783. ;; At the very first character of the buffer, also call `open-line'.
  3784. (should
  3785. (equal "\n| a |"
  3786. (org-test-with-temp-text "| a |"
  3787. (org-open-line 1)
  3788. (buffer-string))))
  3789. ;; Narrowing does not count.
  3790. (should
  3791. (equal "Text\n| |\n| a |"
  3792. (org-test-with-temp-text "Text\n<point>| a |"
  3793. (narrow-to-region (point) (point-max))
  3794. (org-open-line 1)
  3795. (widen)
  3796. (buffer-string)))))
  3797. (ert-deftest test-org/forward-sentence ()
  3798. "Test `org-forward-sentence' specifications."
  3799. ;; At the end of a table cell, move to the end of the next one.
  3800. (should
  3801. (org-test-with-temp-text "| a<point> | b |"
  3802. (org-forward-sentence)
  3803. (looking-at " |$")))
  3804. ;; Elsewhere in a cell, move to its end.
  3805. (should
  3806. (org-test-with-temp-text "| a<point>c | b |"
  3807. (org-forward-sentence)
  3808. (looking-at " | b |$")))
  3809. ;; Otherwise, simply call `forward-sentence'.
  3810. (should
  3811. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3812. (org-forward-sentence)
  3813. (looking-at " Sentence 2.")))
  3814. (should
  3815. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3816. (org-forward-sentence)
  3817. (org-forward-sentence)
  3818. (eobp)))
  3819. ;; At the end of an element, jump to the next one, without stopping
  3820. ;; on blank lines in-between.
  3821. (should
  3822. (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
  3823. (org-forward-sentence)
  3824. (eobp)))
  3825. ;; Headlines are considered to be sentences by themselves, even if
  3826. ;; they do not end with a full stop.
  3827. (should
  3828. (equal
  3829. "* Headline"
  3830. (org-test-with-temp-text "* <point>Headline\nSentence."
  3831. (org-forward-sentence)
  3832. (buffer-substring-no-properties (line-beginning-position) (point)))))
  3833. (should
  3834. (org-test-with-temp-text "* Headline<point>\nSentence."
  3835. (org-forward-sentence)
  3836. (eobp)))
  3837. (should
  3838. (org-test-with-temp-text "Sentence.<point>\n\n* Headline\n\nSentence 2."
  3839. (org-forward-sentence)
  3840. (and (org-at-heading-p) (eolp)))))
  3841. (ert-deftest test-org/backward-sentence ()
  3842. "Test `org-backward-sentence' specifications."
  3843. ;; At the beginning of a table cell, move to the beginning of the
  3844. ;; previous one.
  3845. (should
  3846. (org-test-with-temp-text "| a | <point>b |"
  3847. (org-backward-sentence)
  3848. (looking-at "a | b |$")))
  3849. ;; Elsewhere in a cell, move to its beginning.
  3850. (should
  3851. (org-test-with-temp-text "| a | b<point>c |"
  3852. (org-backward-sentence)
  3853. (looking-at "bc |$")))
  3854. ;; Otherwise, simply call `backward-sentence'.
  3855. (should
  3856. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3857. (org-backward-sentence)
  3858. (looking-at "Sentence 2.")))
  3859. (should
  3860. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3861. (org-backward-sentence)
  3862. (org-backward-sentence)
  3863. (bobp)))
  3864. ;; Make sure to hit the beginning of a sentence on the same line as
  3865. ;; an item.
  3866. (should
  3867. (org-test-with-temp-text "- Line 1\n line <point>2."
  3868. (org-backward-sentence)
  3869. (looking-at "Line 1"))))
  3870. (ert-deftest test-org/forward-paragraph ()
  3871. "Test `org-forward-paragraph' specifications."
  3872. ;; At end of buffer, do not return an error.
  3873. (should
  3874. (org-test-with-temp-text "Paragraph"
  3875. (goto-char (point-max))
  3876. (org-forward-paragraph)
  3877. t))
  3878. ;; Standard test.
  3879. (should
  3880. (= 2
  3881. (org-test-with-temp-text "P1\n\nP2"
  3882. (org-forward-paragraph)
  3883. (org-current-line))))
  3884. (should
  3885. (= 2
  3886. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  3887. (org-forward-paragraph)
  3888. (org-current-line))))
  3889. ;; Enter greater elements.
  3890. (should
  3891. (= 2
  3892. (org-test-with-temp-text "#+begin_center\nP1\n#+end_center\nP2"
  3893. (org-forward-paragraph)
  3894. (org-current-line))))
  3895. ;; Do not enter elements with invisible contents.
  3896. (should
  3897. (= 4
  3898. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  3899. (org-cycle)
  3900. (org-forward-paragraph)
  3901. (org-current-line))))
  3902. (should
  3903. (= 6
  3904. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\nP3"
  3905. (org-fold-hide-block-toggle)
  3906. (org-forward-paragraph)
  3907. (org-current-line))))
  3908. ;; On an item or a footnote definition, move past the first element
  3909. ;; inside, if any.
  3910. (should
  3911. (= 2
  3912. (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
  3913. (org-forward-paragraph)
  3914. (org-current-line))))
  3915. (should
  3916. (= 2
  3917. (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
  3918. (org-forward-paragraph)
  3919. (org-current-line))))
  3920. ;; On a table (resp. a property drawer) do not move through table
  3921. ;; rows (resp. node properties).
  3922. (should
  3923. (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
  3924. (org-forward-paragraph)
  3925. (looking-at "Paragraph")))
  3926. (should
  3927. (org-test-with-temp-text
  3928. "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
  3929. (org-forward-paragraph)
  3930. (looking-at "Paragraph")))
  3931. ;; Skip consecutive keywords, clocks and diary S-exps.
  3932. (should
  3933. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n"
  3934. (org-forward-paragraph)
  3935. (eobp)))
  3936. (should
  3937. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n"
  3938. (org-forward-paragraph)
  3939. (eobp)))
  3940. (should
  3941. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n"
  3942. (org-forward-paragraph)
  3943. (eobp)))
  3944. (should-not
  3945. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n"
  3946. (org-forward-paragraph)
  3947. (eobp)))
  3948. (should-not
  3949. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n"
  3950. (org-forward-paragraph)
  3951. (eobp)))
  3952. ;; In a plain list with one item every line, skip the whole list,
  3953. ;; even with point in the middle of the list.
  3954. (should
  3955. (org-test-with-temp-text "- A\n - B\n- C\n"
  3956. (org-forward-paragraph)
  3957. (eobp)))
  3958. (should
  3959. (org-test-with-temp-text "- A\n - <point>B\n- C\n"
  3960. (org-forward-paragraph)
  3961. (eobp)))
  3962. ;; On a comment, verse or source block, stop at "contents"
  3963. ;; boundaries and blank lines.
  3964. (should
  3965. (= 2
  3966. (org-test-with-temp-text "#+begin_src emacs-lisp\nL1\n\nL2\n#+end_src"
  3967. (org-forward-paragraph)
  3968. (org-current-line))))
  3969. (should
  3970. (= 3
  3971. (org-test-with-temp-text "#+begin_verse\n<point>L1\n\nL2\n#+end_verse"
  3972. (org-forward-paragraph)
  3973. (org-current-line))))
  3974. (should
  3975. (= 5
  3976. (org-test-with-temp-text "#+begin_comment\nL1\n\n<point>L2\n#+end_comment"
  3977. (org-forward-paragraph)
  3978. (org-current-line))))
  3979. ;; Being on an affiliated keyword shouldn't make any difference.
  3980. (should
  3981. (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
  3982. (org-forward-paragraph)
  3983. (eobp))))
  3984. (ert-deftest test-org/backward-paragraph ()
  3985. "Test `org-backward-paragraph' specifications."
  3986. ;; Do not error at beginning of buffer.
  3987. (should
  3988. (org-test-with-temp-text "Paragraph"
  3989. (org-backward-paragraph)
  3990. t))
  3991. ;; At blank lines at the very beginning of a buffer, move to
  3992. ;; point-min.
  3993. (should
  3994. (org-test-with-temp-text "\n\n<point>\n\nParagraph"
  3995. (org-backward-paragraph)
  3996. (bobp)))
  3997. ;; Regular test.
  3998. (should
  3999. (= 2
  4000. (org-test-with-temp-text "P1\n\nP2<point>"
  4001. (org-backward-paragraph)
  4002. (org-current-line))))
  4003. (should
  4004. (= 4
  4005. (org-test-with-temp-text "P1\n\nP2\n\nP3<point>"
  4006. (org-backward-paragraph)
  4007. (org-current-line))))
  4008. ;; Try to move on the line above current element.
  4009. (should
  4010. (= 2
  4011. (org-test-with-temp-text "\n\n<point>Paragraph"
  4012. (org-backward-paragraph)
  4013. (org-current-line))))
  4014. ;; Do not leave point in an invisible area.
  4015. (should
  4016. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  4017. (org-cycle)
  4018. (goto-char (point-max))
  4019. (beginning-of-line)
  4020. (org-backward-paragraph)
  4021. (bobp)))
  4022. (should
  4023. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\n"
  4024. (org-fold-hide-block-toggle)
  4025. (goto-char (point-max))
  4026. (org-backward-paragraph)
  4027. (bobp)))
  4028. ;; On the first element in an item or a footnote definition, jump
  4029. ;; before the footnote or the item.
  4030. (should
  4031. (org-test-with-temp-text "- line1<point>"
  4032. (org-backward-paragraph)
  4033. (bobp)))
  4034. (should
  4035. (org-test-with-temp-text "[fn:1] line1n<point>"
  4036. (org-backward-paragraph)
  4037. (bobp)))
  4038. ;; On the second element in an item or a footnote definition, jump
  4039. ;; to item or the definition.
  4040. (should
  4041. (= 2
  4042. (org-test-with-temp-text "- line1\n\n<point> line2"
  4043. (org-backward-paragraph)
  4044. (org-current-line))))
  4045. (should
  4046. (= 2
  4047. (org-test-with-temp-text "[fn:1] line1\n\n<point> line2"
  4048. (org-backward-paragraph)
  4049. (org-current-line))))
  4050. ;; On a table (resp. a property drawer), ignore table rows
  4051. ;; (resp. node properties).
  4052. (should
  4053. (org-test-with-temp-text "| a | b |\n| c | d |\n<point>P1"
  4054. (org-backward-paragraph)
  4055. (bobp)))
  4056. (should
  4057. (= 2
  4058. (org-test-with-temp-text
  4059. "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
  4060. (org-backward-paragraph)
  4061. (org-current-line))))
  4062. ;; In a plain list with one item every line, skip the whole list,
  4063. ;; even with point in the middle of the list.
  4064. (should
  4065. (org-test-with-temp-text "- A\n - B\n- C\n<point>"
  4066. (org-backward-paragraph)
  4067. (bobp)))
  4068. (should
  4069. (org-test-with-temp-text "- A\n - B\n- <point>C\n"
  4070. (org-backward-paragraph)
  4071. (bobp)))
  4072. ;; Skip consecutive keywords, clocks and diary S-exps.
  4073. (should
  4074. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n<point>"
  4075. (org-backward-paragraph)
  4076. (bobp)))
  4077. (should
  4078. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n<point>"
  4079. (org-backward-paragraph)
  4080. (bobp)))
  4081. (should
  4082. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n<point>"
  4083. (org-backward-paragraph)
  4084. (bobp)))
  4085. (should-not
  4086. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n<point>"
  4087. (org-backward-paragraph)
  4088. (bobp)))
  4089. (should-not
  4090. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n<point>"
  4091. (org-backward-paragraph)
  4092. (bobp)))
  4093. ;; On a comment, example, source and verse blocks, stop at blank
  4094. ;; lines.
  4095. (should
  4096. (= 1
  4097. (org-test-with-temp-text
  4098. "#+begin_comment\n<point>L1\n\nL2\n\nL3\n#+end_comment"
  4099. (org-backward-paragraph)
  4100. (org-current-line))))
  4101. (should
  4102. (= 2
  4103. (org-test-with-temp-text
  4104. "#+begin_verse\nL1\n\n<point>L2\n\nL3\n#+end_verse"
  4105. (org-backward-paragraph)
  4106. (org-current-line))))
  4107. (should
  4108. (= 3
  4109. (org-test-with-temp-text
  4110. "#+begin_src emacs-lisp\nL1\n\nL2\n\n<point>L3\n#+end_src"
  4111. (org-backward-paragraph)
  4112. (org-current-line))))
  4113. ;; When called from the opening line itself, however, move to
  4114. ;; beginning of block.
  4115. (should
  4116. (org-test-with-temp-text "#+begin_<point>example\nL1\n#+end_example"
  4117. (org-backward-paragraph)
  4118. (bobp)))
  4119. ;; On an empty heading, move above it.
  4120. (should
  4121. (org-test-with-temp-text "\n* <point>"
  4122. (org-backward-paragraph)
  4123. (bobp)))
  4124. (should
  4125. (org-test-with-temp-text "\n* \n<point>"
  4126. (org-backward-paragraph)
  4127. (bobp))))
  4128. (ert-deftest test-org/forward-element ()
  4129. "Test `org-forward-element' specifications."
  4130. ;; 1. At EOB: should error.
  4131. (org-test-with-temp-text "Some text\n"
  4132. (goto-char (point-max))
  4133. (should-error (org-forward-element)))
  4134. ;; 2. Standard move: expected to ignore blank lines.
  4135. (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
  4136. (org-forward-element)
  4137. (should (looking-at (regexp-quote "Second paragraph."))))
  4138. ;; 3. Headline tests.
  4139. (org-test-with-temp-text "
  4140. * Head 1
  4141. ** Head 1.1
  4142. *** Head 1.1.1
  4143. ** Head 1.2"
  4144. ;; 3.1. At an headline beginning: move to next headline at the
  4145. ;; same level.
  4146. (goto-line 3)
  4147. (org-forward-element)
  4148. (should (looking-at (regexp-quote "** Head 1.2")))
  4149. ;; 3.2. At an headline beginning: move to parent headline if no
  4150. ;; headline at the same level.
  4151. (goto-line 3)
  4152. (org-forward-element)
  4153. (should (looking-at (regexp-quote "** Head 1.2"))))
  4154. ;; 4. Greater element tests.
  4155. (org-test-with-temp-text
  4156. "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
  4157. ;; 4.1. At a greater element: expected to skip contents.
  4158. (org-forward-element)
  4159. (should (looking-at (regexp-quote "Outside.")))
  4160. ;; 4.2. At the end of greater element contents: expected to skip
  4161. ;; to the end of the greater element.
  4162. (goto-line 2)
  4163. (org-forward-element)
  4164. (should (looking-at (regexp-quote "Outside."))))
  4165. ;; 5. List tests.
  4166. (org-test-with-temp-text "
  4167. - item1
  4168. - sub1
  4169. - sub2
  4170. - sub3
  4171. Inner paragraph.
  4172. - item2
  4173. Outside."
  4174. ;; 5.1. At list top point: expected to move to the element after
  4175. ;; the list.
  4176. (goto-line 2)
  4177. (org-forward-element)
  4178. (should (looking-at (regexp-quote "Outside.")))
  4179. ;; 5.2. Special case: at the first line of a sub-list, but not at
  4180. ;; beginning of line, move to next item.
  4181. (goto-line 2)
  4182. (forward-char)
  4183. (org-forward-element)
  4184. (should (looking-at "- item2"))
  4185. (goto-line 4)
  4186. (forward-char)
  4187. (org-forward-element)
  4188. (should (looking-at " - sub2"))
  4189. ;; 5.3 At sub-list beginning: expected to move after the sub-list.
  4190. (goto-line 4)
  4191. (org-forward-element)
  4192. (should (looking-at (regexp-quote " Inner paragraph.")))
  4193. ;; 5.4. At sub-list end: expected to move outside the sub-list.
  4194. (goto-line 8)
  4195. (org-forward-element)
  4196. (should (looking-at (regexp-quote " Inner paragraph.")))
  4197. ;; 5.5. At an item: expected to move to next item, if any.
  4198. (goto-line 6)
  4199. (org-forward-element)
  4200. (should (looking-at " - sub3"))))
  4201. (ert-deftest test-org/backward-element ()
  4202. "Test `org-backward-element' specifications."
  4203. ;; 1. Should error at BOB.
  4204. (org-test-with-temp-text " \nParagraph."
  4205. (should-error (org-backward-element)))
  4206. ;; 2. Should move at BOB when called on the first element in buffer.
  4207. (should
  4208. (org-test-with-temp-text "\n#+TITLE: test"
  4209. (progn (forward-line)
  4210. (org-backward-element)
  4211. (bobp))))
  4212. ;; 3. Not at the beginning of an element: move at its beginning.
  4213. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  4214. (goto-line 3)
  4215. (end-of-line)
  4216. (org-backward-element)
  4217. (should (looking-at (regexp-quote "Paragraph2."))))
  4218. ;; 4. Headline tests.
  4219. (org-test-with-temp-text "
  4220. * Head 1
  4221. ** Head 1.1
  4222. *** Head 1.1.1
  4223. ** Head 1.2"
  4224. ;; 4.1. At an headline beginning: move to previous headline at the
  4225. ;; same level.
  4226. (goto-line 5)
  4227. (org-backward-element)
  4228. (should (looking-at (regexp-quote "** Head 1.1")))
  4229. ;; 4.2. At an headline beginning: move to parent headline if no
  4230. ;; headline at the same level.
  4231. (goto-line 3)
  4232. (org-backward-element)
  4233. (should (looking-at (regexp-quote "* Head 1")))
  4234. ;; 4.3. At the first top-level headline: should error.
  4235. (goto-line 2)
  4236. (should-error (org-backward-element)))
  4237. ;; 5. At beginning of first element inside a greater element:
  4238. ;; expected to move to greater element's beginning.
  4239. (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
  4240. (goto-line 3)
  4241. (org-backward-element)
  4242. (should (looking-at "#\\+BEGIN_CENTER")))
  4243. ;; 6. At the beginning of the first element in a section: should
  4244. ;; move back to headline, if any.
  4245. (should
  4246. (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
  4247. (progn (goto-char (point-max))
  4248. (beginning-of-line)
  4249. (org-backward-element)
  4250. (org-at-heading-p))))
  4251. ;; 7. List tests.
  4252. (org-test-with-temp-text "
  4253. - item1
  4254. - sub1
  4255. - sub2
  4256. - sub3
  4257. Inner paragraph.
  4258. - item2
  4259. Outside."
  4260. ;; 7.1. At beginning of sub-list: expected to move to the
  4261. ;; paragraph before it.
  4262. (goto-line 4)
  4263. (org-backward-element)
  4264. (should (looking-at "item1"))
  4265. ;; 7.2. At an item in a list: expected to move at previous item.
  4266. (goto-line 8)
  4267. (org-backward-element)
  4268. (should (looking-at " - sub2"))
  4269. (goto-line 12)
  4270. (org-backward-element)
  4271. (should (looking-at "- item1"))
  4272. ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
  4273. ;; beginning.
  4274. (goto-line 10)
  4275. (org-backward-element)
  4276. (should (looking-at " - sub1"))
  4277. (goto-line 15)
  4278. (org-backward-element)
  4279. (should (looking-at "- item1"))
  4280. ;; 7.4. At blank-lines before list end: expected to move to top
  4281. ;; item.
  4282. (goto-line 14)
  4283. (org-backward-element)
  4284. (should (looking-at "- item1"))))
  4285. (ert-deftest test-org/up-element ()
  4286. "Test `org-up-element' specifications."
  4287. ;; 1. At BOB or with no surrounding element: should error.
  4288. (org-test-with-temp-text "Paragraph."
  4289. (should-error (org-up-element)))
  4290. (org-test-with-temp-text "* Head1\n* Head2"
  4291. (goto-line 2)
  4292. (should-error (org-up-element)))
  4293. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  4294. (goto-line 3)
  4295. (should-error (org-up-element)))
  4296. ;; 2. At an headline: move to parent headline.
  4297. (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
  4298. (goto-line 3)
  4299. (org-up-element)
  4300. (should (looking-at "\\* Head1")))
  4301. ;; 3. Inside a greater element: move to greater element beginning.
  4302. (org-test-with-temp-text
  4303. "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
  4304. (goto-line 3)
  4305. (org-up-element)
  4306. (should (looking-at "#\\+BEGIN_CENTER")))
  4307. ;; 4. List tests.
  4308. (org-test-with-temp-text "* Top
  4309. - item1
  4310. - sub1
  4311. - sub2
  4312. Paragraph within sub2.
  4313. - item2"
  4314. ;; 4.1. Within an item: move to the item beginning.
  4315. (goto-line 8)
  4316. (org-up-element)
  4317. (should (looking-at " - sub2"))
  4318. ;; 4.2. At an item in a sub-list: move to parent item.
  4319. (goto-line 4)
  4320. (org-up-element)
  4321. (should (looking-at "- item1"))
  4322. ;; 4.3. At an item in top list: move to beginning of whole list.
  4323. (goto-line 10)
  4324. (org-up-element)
  4325. (should (looking-at "- item1"))
  4326. ;; 4.4. Special case. At very top point: should move to parent of
  4327. ;; list.
  4328. (goto-line 2)
  4329. (org-up-element)
  4330. (should (looking-at "\\* Top"))))
  4331. (ert-deftest test-org/down-element ()
  4332. "Test `org-down-element' specifications."
  4333. ;; Error when the element hasn't got a recursive type.
  4334. (org-test-with-temp-text "Paragraph."
  4335. (should-error (org-down-element)))
  4336. ;; Error when the element has no contents
  4337. (org-test-with-temp-text "* Headline"
  4338. (should-error (org-down-element)))
  4339. ;; When at a plain-list, move to first item.
  4340. (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
  4341. (goto-line 2)
  4342. (org-down-element)
  4343. (should (looking-at " - Item 1.1")))
  4344. (org-test-with-temp-text "#+NAME: list\n- Item 1"
  4345. (org-down-element)
  4346. (should (looking-at " Item 1")))
  4347. ;; When at a table, move to first row
  4348. (org-test-with-temp-text "#+NAME: table\n| a | b |"
  4349. (org-down-element)
  4350. (should (looking-at " a | b |")))
  4351. ;; Otherwise, move inside the greater element.
  4352. (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
  4353. (org-down-element)
  4354. (should (looking-at "Paragraph"))))
  4355. (ert-deftest test-org/drag-element-backward ()
  4356. "Test `org-drag-element-backward' specifications."
  4357. ;; Standard test.
  4358. (should
  4359. (equal
  4360. "#+key2: val2\n#+key1: val1\n#+key3: val3"
  4361. (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
  4362. (org-drag-element-backward)
  4363. (buffer-string))))
  4364. (should
  4365. (equal
  4366. "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
  4367. (org-test-with-temp-text
  4368. "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
  4369. (org-drag-element-backward)
  4370. (buffer-string))))
  4371. ;; Preserve blank lines.
  4372. (should
  4373. (equal "Paragraph 2\n\n\nPara1\n\nPara3"
  4374. (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
  4375. (org-drag-element-backward)
  4376. (buffer-string))))
  4377. ;; Preserve column.
  4378. (should
  4379. (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
  4380. (org-drag-element-backward)
  4381. (looking-at-p "2")))
  4382. ;; Error when trying to move first element of buffer.
  4383. (should-error
  4384. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4385. (org-drag-element-backward))
  4386. :type 'user-error)
  4387. ;; Error when trying to swap nested elements.
  4388. (should-error
  4389. (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
  4390. (org-drag-element-backward))
  4391. :type 'user-error)
  4392. ;; Error when trying to swap an headline element and a non-headline
  4393. ;; element.
  4394. (should-error
  4395. (org-test-with-temp-text "Test.\n<point>* Head 1"
  4396. (org-drag-element-backward))
  4397. :type 'error)
  4398. ;; Error when called before first element.
  4399. (should-error
  4400. (org-test-with-temp-text "\n<point>"
  4401. (org-drag-element-backward))
  4402. :type 'user-error)
  4403. ;; Preserve visibility of elements and their contents.
  4404. (should
  4405. (equal '((63 . 82) (26 . 48))
  4406. (let ((org-fold-core-style 'text-properties))
  4407. (org-test-with-temp-text
  4408. "
  4409. #+BEGIN_CENTER
  4410. Text.
  4411. #+END_CENTER
  4412. - item 1
  4413. #+BEGIN_QUOTE
  4414. Text.
  4415. #+END_QUOTE"
  4416. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4417. (search-backward "- item 1")
  4418. (org-drag-element-backward)
  4419. (let (regions)
  4420. (goto-char (point-min))
  4421. (while (< (point) (point-max))
  4422. (let ((region (org-fold-get-region-at-point)))
  4423. (if (not region)
  4424. (goto-char (org-fold-next-folding-state-change))
  4425. (goto-char (cdr region))
  4426. (push region regions))))
  4427. regions)))))
  4428. (should
  4429. (equal '((63 . 82) (26 . 48))
  4430. (let ((org-fold-core-style 'overlays))
  4431. (org-test-with-temp-text
  4432. "
  4433. #+BEGIN_CENTER
  4434. Text.
  4435. #+END_CENTER
  4436. - item 1
  4437. #+BEGIN_QUOTE
  4438. Text.
  4439. #+END_QUOTE"
  4440. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4441. (search-backward "- item 1")
  4442. (org-drag-element-backward)
  4443. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4444. (overlays-in (point-min) (point-max)))))))
  4445. ;; Pathological case: handle call with point in blank lines right
  4446. ;; after a headline.
  4447. (should
  4448. (equal "* H2\n\n* H1\nText\n"
  4449. (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
  4450. (org-drag-element-backward)
  4451. (buffer-string)))))
  4452. (ert-deftest test-org/drag-element-forward ()
  4453. "Test `org-drag-element-forward' specifications."
  4454. ;; 1. Error when trying to move first element of buffer.
  4455. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4456. (goto-line 3)
  4457. (should-error (org-drag-element-forward)))
  4458. ;; 2. Error when trying to swap nested elements.
  4459. (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
  4460. (forward-line)
  4461. (should-error (org-drag-element-forward)))
  4462. ;; 3. Error when trying to swap a non-headline element and an
  4463. ;; headline.
  4464. (org-test-with-temp-text "Test.\n* Head 1"
  4465. (should-error (org-drag-element-forward)))
  4466. ;; 4. Error when called before first element.
  4467. (should-error
  4468. (org-test-with-temp-text "\n"
  4469. (forward-line)
  4470. (org-drag-element-backward))
  4471. :type 'user-error)
  4472. ;; 5. Otherwise, swap elements, preserving column and blank lines
  4473. ;; between elements.
  4474. (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
  4475. (search-forward "graph")
  4476. (org-drag-element-forward)
  4477. (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
  4478. (should (looking-at " 1")))
  4479. ;; 5. Preserve visibility of elements and their contents.
  4480. (let ((org-fold-core-style 'text-properties))
  4481. (org-test-with-temp-text
  4482. "
  4483. #+BEGIN_CENTER
  4484. Text.
  4485. #+END_CENTER
  4486. - item 1
  4487. #+BEGIN_QUOTE
  4488. Text.
  4489. #+END_QUOTE"
  4490. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4491. (search-backward "#+BEGIN_CENTER")
  4492. (org-drag-element-forward)
  4493. (should
  4494. (equal
  4495. '((63 . 82) (26 . 48))
  4496. (let (regions)
  4497. (goto-char (point-min))
  4498. (while (< (point) (point-max))
  4499. (let ((region (org-fold-get-region-at-point)))
  4500. (if (not region)
  4501. (goto-char (org-fold-next-folding-state-change))
  4502. (goto-char (cdr region))
  4503. (push region regions))))
  4504. regions)))))
  4505. (let ((org-fold-core-style 'overlays))
  4506. (org-test-with-temp-text
  4507. "
  4508. #+BEGIN_CENTER
  4509. Text.
  4510. #+END_CENTER
  4511. - item 1
  4512. #+BEGIN_QUOTE
  4513. Text.
  4514. #+END_QUOTE"
  4515. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4516. (search-backward "#+BEGIN_CENTER")
  4517. (org-drag-element-forward)
  4518. (should
  4519. (equal
  4520. '((63 . 82) (26 . 48))
  4521. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4522. (overlays-in (point-min) (point-max))))))))
  4523. (ert-deftest test-org/next-block ()
  4524. "Test `org-next-block' specifications."
  4525. ;; Regular test.
  4526. (should
  4527. (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  4528. (org-next-block 1)
  4529. (looking-at "#\\+BEGIN_CENTER")))
  4530. ;; Ignore case.
  4531. (should
  4532. (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
  4533. (let ((case-fold-search nil))
  4534. (org-next-block 1)
  4535. (looking-at "#\\+begin_center"))))
  4536. ;; Ignore current line.
  4537. (should
  4538. (org-test-with-temp-text
  4539. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
  4540. (org-next-block 1)
  4541. (looking-at "#\\+BEGIN_CENTER")))
  4542. ;; Throw an error when no block is found.
  4543. (should-error
  4544. (org-test-with-temp-text "Paragraph"
  4545. (org-next-block 1)))
  4546. ;; With an argument, skip many blocks at once.
  4547. (should
  4548. (org-test-with-temp-text
  4549. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4550. (org-next-block 2)
  4551. (looking-at "#\\+BEGIN_QUOTE")))
  4552. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4553. (should
  4554. (org-test-with-temp-text
  4555. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4556. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4557. (looking-at "#\\+BEGIN_QUOTE")))
  4558. ;; Optional argument is also case-insensitive.
  4559. (should
  4560. (org-test-with-temp-text
  4561. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
  4562. (let ((case-fold-search nil))
  4563. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4564. (looking-at "#\\+begin_quote")))))
  4565. (ert-deftest test-org/insert-structure-template ()
  4566. "Test `org-insert-structure-template'."
  4567. ;; Test in empty buffer.
  4568. (should
  4569. (string= "#+begin_foo\n#+end_foo\n"
  4570. (org-test-with-temp-text ""
  4571. (org-insert-structure-template "foo")
  4572. (buffer-string))))
  4573. ;; Test with multiple lines in buffer.
  4574. (should
  4575. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4576. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4577. (transient-mark-mode 1)
  4578. (org-mark-element)
  4579. (org-insert-structure-template "foo")
  4580. (buffer-string))))
  4581. ;; Mark only the current line.
  4582. (should
  4583. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4584. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4585. (transient-mark-mode 1)
  4586. (set-mark (point-min))
  4587. (end-of-line)
  4588. (org-insert-structure-template "foo")
  4589. (buffer-string))))
  4590. ;; Middle of paragraph.
  4591. (should
  4592. (string= "p1\n#+begin_foo\np2\n#+end_foo\np3"
  4593. (org-test-with-temp-text "p1\n<point>p2\np3"
  4594. (set-mark (line-beginning-position))
  4595. (end-of-line)
  4596. (activate-mark)
  4597. (org-insert-structure-template "foo")
  4598. (buffer-string))))
  4599. ;; Test with text in buffer, no region, no final newline.
  4600. (should
  4601. (string= "#+begin_foo\nI'm a paragraph.\n#+end_foo\n"
  4602. (org-test-with-temp-text "I'm a paragraph."
  4603. (org-mark-element)
  4604. (org-insert-structure-template "foo")
  4605. (buffer-string))))
  4606. ;; Test with text in buffer and region set.
  4607. (should
  4608. (string= "#+begin_foo\nI'm a paragraph\n\nI'm a second paragrah\n#+end_foo\n"
  4609. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragrah"
  4610. (set-mark (point))
  4611. (goto-char (point-max))
  4612. (org-insert-structure-template "foo")
  4613. (buffer-string))))
  4614. ;; Test with example escaping.
  4615. (should
  4616. (string= "#+begin_example\n,* Heading\n#+end_example\n"
  4617. (org-test-with-temp-text "* Heading"
  4618. (org-mark-element)
  4619. (org-insert-structure-template "example")
  4620. (buffer-string))))
  4621. ;; Test with indentation.
  4622. (should
  4623. (string= " #+begin_foo\n This is a paragraph\n #+end_foo\n"
  4624. (org-test-with-temp-text " This is a paragraph"
  4625. (org-mark-element)
  4626. (org-insert-structure-template "foo")
  4627. (buffer-string))))
  4628. (should
  4629. (string= " #+begin_foo\n Line 1\n Line2\n #+end_foo\n"
  4630. (org-test-with-temp-text " Line 1\n Line2"
  4631. (org-mark-element)
  4632. (org-insert-structure-template "foo")
  4633. (buffer-string))))
  4634. ;; Test point location.
  4635. (should
  4636. (string= "#+begin_foo\n"
  4637. (org-test-with-temp-text ""
  4638. (org-insert-structure-template "foo")
  4639. (buffer-substring (point-min) (point)))))
  4640. (should
  4641. (string= "#+begin_src "
  4642. (org-test-with-temp-text ""
  4643. (org-insert-structure-template "src")
  4644. (buffer-substring (point-min) (point))))))
  4645. (ert-deftest test-org/previous-block ()
  4646. "Test `org-previous-block' specifications."
  4647. ;; Regular test.
  4648. (should
  4649. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
  4650. (org-previous-block 1)
  4651. (looking-at "#\\+BEGIN_CENTER")))
  4652. ;; Ignore case.
  4653. (should
  4654. (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
  4655. (let ((case-fold-search nil))
  4656. (org-previous-block 1)
  4657. (looking-at "#\\+begin_center"))))
  4658. ;; Ignore current line.
  4659. (should
  4660. (org-test-with-temp-text
  4661. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
  4662. (org-previous-block 1)
  4663. (looking-at "#\\+BEGIN_QUOTE")))
  4664. ;; Throw an error when no block is found.
  4665. (should-error
  4666. (org-test-with-temp-text "Paragraph<point>"
  4667. (org-previous-block 1)))
  4668. ;; With an argument, skip many blocks at once.
  4669. (should
  4670. (org-test-with-temp-text
  4671. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4672. (org-previous-block 2)
  4673. (looking-at "#\\+BEGIN_CENTER")))
  4674. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4675. (should
  4676. (org-test-with-temp-text
  4677. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4678. (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4679. (looking-at "#\\+BEGIN_QUOTE")))
  4680. ;; Optional argument is also case-insensitive.
  4681. (should
  4682. (org-test-with-temp-text
  4683. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
  4684. (let ((case-fold-search nil))
  4685. (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4686. (looking-at "#\\+begin_quote")))))
  4687. ;;; Outline structure
  4688. (ert-deftest test-org/demote ()
  4689. "Test `org-demote' specifications."
  4690. ;; Add correct number of stars according to `org-odd-levels-only'.
  4691. (should
  4692. (= 2
  4693. (org-test-with-temp-text "* H"
  4694. (let ((org-odd-levels-only nil)) (org-demote))
  4695. (org-current-level))))
  4696. (should
  4697. (= 3
  4698. (org-test-with-temp-text "* H"
  4699. (let ((org-odd-levels-only t)) (org-demote))
  4700. (org-current-level))))
  4701. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4702. (should
  4703. (org-test-with-temp-text "* H :tag:"
  4704. (let ((org-tags-column 10)
  4705. (org-auto-align-tags t)
  4706. (org-odd-levels-only nil))
  4707. (org-demote))
  4708. (org-move-to-column 10)
  4709. (looking-at-p ":tag:$")))
  4710. (should-not
  4711. (org-test-with-temp-text "* H :tag:"
  4712. (let ((org-tags-column 10)
  4713. (org-auto-align-tags nil)
  4714. (org-odd-levels-only nil))
  4715. (org-demote))
  4716. (org-move-to-column 10)
  4717. (looking-at-p ":tag:$")))
  4718. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4719. ;; info and property drawers accordingly.
  4720. (should
  4721. (= 3
  4722. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4723. (let ((org-odd-levels-only nil)
  4724. (org-adapt-indentation t))
  4725. (org-demote))
  4726. (forward-line)
  4727. (org-get-indentation))))
  4728. (should
  4729. (= 3
  4730. (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4731. (let ((org-odd-levels-only nil)
  4732. (org-adapt-indentation t))
  4733. (org-demote))
  4734. (forward-line)
  4735. (org-get-indentation))))
  4736. (should-not
  4737. (= 3
  4738. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4739. (let ((org-odd-levels-only nil)
  4740. (org-adapt-indentation nil))
  4741. (org-demote))
  4742. (forward-line)
  4743. (org-get-indentation))))
  4744. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4745. ;; section accordingly. Ignore, however, footnote definitions and
  4746. ;; inlinetasks boundaries.
  4747. (should
  4748. (= 3
  4749. (org-test-with-temp-text "* H\n Paragraph"
  4750. (let ((org-odd-levels-only nil)
  4751. (org-adapt-indentation t))
  4752. (org-demote))
  4753. (forward-line)
  4754. (org-get-indentation))))
  4755. (should
  4756. (= 2
  4757. (org-test-with-temp-text "* H\n Paragraph"
  4758. (let ((org-odd-levels-only nil)
  4759. (org-adapt-indentation nil))
  4760. (org-demote))
  4761. (forward-line)
  4762. (org-get-indentation))))
  4763. (should
  4764. (zerop
  4765. (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
  4766. (let ((org-odd-levels-only nil)
  4767. (org-adapt-indentation t))
  4768. (org-demote))
  4769. (goto-char (point-max))
  4770. (org-get-indentation))))
  4771. (should
  4772. (= 3
  4773. (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
  4774. (let ((org-odd-levels-only nil)
  4775. (org-adapt-indentation t))
  4776. (org-demote))
  4777. (goto-char (point-max))
  4778. (org-get-indentation))))
  4779. (when (featurep 'org-inlinetask)
  4780. (should
  4781. (zerop
  4782. (let ((org-inlinetask-min-level 5)
  4783. (org-adapt-indentation t))
  4784. (org-test-with-temp-text "* H\n***** I\n***** END"
  4785. (org-demote)
  4786. (forward-line)
  4787. (org-get-indentation))))))
  4788. (when (featurep 'org-inlinetask)
  4789. (should
  4790. (= 3
  4791. (let ((org-inlinetask-min-level 5)
  4792. (org-adapt-indentation t))
  4793. (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
  4794. (org-demote)
  4795. (forward-line 2)
  4796. (org-get-indentation))))))
  4797. ;; When `org-adapt-indentation' is non-nil, log drawers are
  4798. ;; adjusted.
  4799. (should
  4800. (equal
  4801. "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4802. (org-test-with-temp-text "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4803. (let ((org-odd-levels-only nil)
  4804. (org-adapt-indentation t))
  4805. (org-demote))
  4806. (buffer-string))))
  4807. (should
  4808. (equal
  4809. "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4810. (org-test-with-temp-text "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4811. (let ((org-odd-levels-only nil)
  4812. (org-adapt-indentation 'headline-data))
  4813. (org-demote))
  4814. (buffer-string))))
  4815. (should
  4816. (equal
  4817. "** H\n :LOGBOOK:\n - a\n :END:"
  4818. (org-test-with-temp-text "* H\n:LOGBOOK:\n- a\n:END:"
  4819. (let ((org-odd-levels-only nil)
  4820. (org-adapt-indentation t))
  4821. (org-demote))
  4822. (buffer-string))))
  4823. ;; Ignore contents of source blocks or example blocks when
  4824. ;; indentation should be preserved (through
  4825. ;; `org-src-preserve-indentation' or "-i" flag).
  4826. (should-not
  4827. (zerop
  4828. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4829. (let ((org-adapt-indentation t)
  4830. (org-src-preserve-indentation nil))
  4831. (org-demote))
  4832. (forward-line 2)
  4833. (org-get-indentation))))
  4834. (should
  4835. (zerop
  4836. (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
  4837. (let ((org-adapt-indentation t)
  4838. (org-src-preserve-indentation t))
  4839. (org-demote))
  4840. (forward-line 2)
  4841. (org-get-indentation))))
  4842. (should
  4843. (zerop
  4844. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4845. (let ((org-adapt-indentation t)
  4846. (org-src-preserve-indentation t))
  4847. (org-demote))
  4848. (forward-line 2)
  4849. (org-get-indentation))))
  4850. (should
  4851. (zerop
  4852. (org-test-with-temp-text
  4853. "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
  4854. (let ((org-adapt-indentation t)
  4855. (org-src-preserve-indentation nil))
  4856. (org-demote))
  4857. (forward-line 2)
  4858. (org-get-indentation)))))
  4859. (ert-deftest test-org/promote ()
  4860. "Test `org-promote' specifications."
  4861. ;; Return an error if headline is to be promoted to level 0, unless
  4862. ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
  4863. ;; headline becomes a comment.
  4864. (should-error
  4865. (org-test-with-temp-text "* H"
  4866. (let ((org-allow-promoting-top-level-subtree nil)) (org-promote))))
  4867. (should
  4868. (equal "# H"
  4869. (org-test-with-temp-text "* H"
  4870. (let ((org-allow-promoting-top-level-subtree t)) (org-promote))
  4871. (buffer-string))))
  4872. ;; Remove correct number of stars according to
  4873. ;; `org-odd-levels-only'.
  4874. (should
  4875. (= 2
  4876. (org-test-with-temp-text "*** H"
  4877. (let ((org-odd-levels-only nil)) (org-promote))
  4878. (org-current-level))))
  4879. (should
  4880. (= 1
  4881. (org-test-with-temp-text "*** H"
  4882. (let ((org-odd-levels-only t)) (org-promote))
  4883. (org-current-level))))
  4884. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4885. (should
  4886. (org-test-with-temp-text "** H :tag:"
  4887. (let ((org-tags-column 10)
  4888. (org-auto-align-tags t)
  4889. (org-odd-levels-only nil))
  4890. (org-promote))
  4891. (org-move-to-column 10)
  4892. (looking-at-p ":tag:$")))
  4893. (should-not
  4894. (org-test-with-temp-text "** H :tag:"
  4895. (let ((org-tags-column 10)
  4896. (org-auto-align-tags nil)
  4897. (org-odd-levels-only nil))
  4898. (org-promote))
  4899. (org-move-to-column 10)
  4900. (looking-at-p ":tag:$")))
  4901. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4902. ;; info and property drawers.
  4903. (should
  4904. (= 2
  4905. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4906. (let ((org-odd-levels-only nil)
  4907. (org-adapt-indentation t))
  4908. (org-promote))
  4909. (forward-line)
  4910. (org-get-indentation))))
  4911. (should
  4912. (= 2
  4913. (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4914. (let ((org-odd-levels-only nil)
  4915. (org-adapt-indentation t))
  4916. (org-promote))
  4917. (forward-line)
  4918. (org-get-indentation))))
  4919. (should-not
  4920. (= 2
  4921. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4922. (let ((org-odd-levels-only nil)
  4923. (org-adapt-indentation nil))
  4924. (org-promote))
  4925. (forward-line)
  4926. (org-get-indentation))))
  4927. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4928. ;; section accordingly. Ignore, however, footnote definitions and
  4929. ;; inlinetasks boundaries.
  4930. (should
  4931. (= 2
  4932. (org-test-with-temp-text "** H\n Paragraph"
  4933. (let ((org-odd-levels-only nil)
  4934. (org-adapt-indentation t))
  4935. (org-promote))
  4936. (forward-line)
  4937. (org-get-indentation))))
  4938. (should-not
  4939. (= 2
  4940. (org-test-with-temp-text "** H\n Paragraph"
  4941. (let ((org-odd-levels-only nil)
  4942. (org-adapt-indentation nil))
  4943. (org-promote))
  4944. (forward-line)
  4945. (org-get-indentation))))
  4946. (should
  4947. (= 2
  4948. (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
  4949. (let ((org-odd-levels-only nil)
  4950. (org-adapt-indentation t))
  4951. (org-promote))
  4952. (forward-line)
  4953. (org-get-indentation))))
  4954. (when (featurep 'org-inlinetask)
  4955. (should
  4956. (zerop
  4957. (let ((org-inlinetask-min-level 5)
  4958. (org-adapt-indentation t))
  4959. (org-test-with-temp-text "** H\n***** I\n***** END"
  4960. (org-promote)
  4961. (forward-line)
  4962. (org-get-indentation))))))
  4963. (when (featurep 'org-inlinetask)
  4964. (should
  4965. (= 2
  4966. (let ((org-inlinetask-min-level 5)
  4967. (org-adapt-indentation t))
  4968. (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
  4969. (org-promote)
  4970. (forward-line 2)
  4971. (org-get-indentation))))))
  4972. ;; Give up shifting if it would break document's structure
  4973. ;; otherwise.
  4974. (should
  4975. (= 3
  4976. (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
  4977. (let ((org-odd-levels-only nil)
  4978. (org-adapt-indentation t))
  4979. (org-promote))
  4980. (forward-line)
  4981. (org-get-indentation))))
  4982. (should
  4983. (= 3
  4984. (org-test-with-temp-text "** H\n Paragraph\n * list."
  4985. (let ((org-odd-levels-only nil)
  4986. (org-adapt-indentation t))
  4987. (org-promote))
  4988. (forward-line)
  4989. (org-get-indentation))))
  4990. ;; When `org-adapt-indentation' is non-nil, log drawers are
  4991. ;; adjusted.
  4992. (should
  4993. (equal
  4994. "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4995. (org-test-with-temp-text "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4996. (let ((org-odd-levels-only nil)
  4997. (org-adapt-indentation t))
  4998. (org-promote))
  4999. (buffer-string))))
  5000. (should
  5001. (equal
  5002. "* H\n :LOGBOOK:\n - a\n :END:\n b"
  5003. (org-test-with-temp-text "** H\n :LOGBOOK:\n - a\n :END:\n b"
  5004. (let ((org-odd-levels-only nil)
  5005. (org-adapt-indentation 'headline-data))
  5006. (org-promote))
  5007. (buffer-string))))
  5008. (should
  5009. (equal
  5010. "* H\n:LOGBOOK:\n- a\n:END:"
  5011. (org-test-with-temp-text "** H\n:LOGBOOK:\n- a\n:END:"
  5012. (let ((org-odd-levels-only nil)
  5013. (org-adapt-indentation t))
  5014. (org-promote))
  5015. (buffer-string))))
  5016. (should
  5017. (equal
  5018. "# H\n:LOGBOOK:\n- a\n:END:"
  5019. (org-test-with-temp-text "* H\n:LOGBOOK:\n- a\n:END:"
  5020. (let ((org-odd-levels-only nil)
  5021. (org-allow-promoting-top-level-subtree t)
  5022. (org-adapt-indentation t))
  5023. (org-promote))
  5024. (buffer-string))))
  5025. ;; Ignore contents of source blocks or example blocks when
  5026. ;; indentation should be preserved (through
  5027. ;; `org-src-preserve-indentation' or "-i" flag).
  5028. (should-not
  5029. (zerop
  5030. (org-test-with-temp-text
  5031. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  5032. (let ((org-adapt-indentation t)
  5033. (org-src-preserve-indentation nil)
  5034. (org-odd-levels-only nil))
  5035. (org-promote))
  5036. (forward-line)
  5037. (org-get-indentation))))
  5038. (should
  5039. (zerop
  5040. (org-test-with-temp-text
  5041. "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
  5042. (let ((org-adapt-indentation t)
  5043. (org-src-preserve-indentation t)
  5044. (org-odd-levels-only nil))
  5045. (org-promote))
  5046. (forward-line)
  5047. (org-get-indentation))))
  5048. (should
  5049. (zerop
  5050. (org-test-with-temp-text
  5051. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  5052. (let ((org-adapt-indentation t)
  5053. (org-src-preserve-indentation t)
  5054. (org-odd-levels-only nil))
  5055. (org-promote))
  5056. (forward-line)
  5057. (org-get-indentation))))
  5058. (should
  5059. (zerop
  5060. (org-test-with-temp-text
  5061. "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
  5062. (let ((org-adapt-indentation t)
  5063. (org-src-preserve-indentation nil)
  5064. (org-odd-levels-only nil))
  5065. (org-promote))
  5066. (forward-line)
  5067. (org-get-indentation)))))
  5068. (ert-deftest test-org/org-get-valid-level ()
  5069. "Test function `org-get-valid-level' specifications."
  5070. (let ((org-odd-levels-only nil))
  5071. (should (equal 1 (org-get-valid-level 0 0)))
  5072. (should (equal 1 (org-get-valid-level 0 1)))
  5073. (should (equal 2 (org-get-valid-level 0 2)))
  5074. (should (equal 3 (org-get-valid-level 0 3)))
  5075. (should (equal 1 (org-get-valid-level 1 0)))
  5076. (should (equal 2 (org-get-valid-level 1 1)))
  5077. (should (equal 23 (org-get-valid-level 1 22)))
  5078. (should (equal 1 (org-get-valid-level 1 -1)))
  5079. (should (equal 1 (org-get-valid-level 2 -1))))
  5080. (let ((org-odd-levels-only t))
  5081. (should (equal 1 (org-get-valid-level 0 0)))
  5082. (should (equal 1 (org-get-valid-level 0 1)))
  5083. (should (equal 3 (org-get-valid-level 0 2)))
  5084. (should (equal 5 (org-get-valid-level 0 3)))
  5085. (should (equal 1 (org-get-valid-level 1 0)))
  5086. (should (equal 3 (org-get-valid-level 1 1)))
  5087. (should (equal 3 (org-get-valid-level 2 1)))
  5088. (should (equal 5 (org-get-valid-level 3 1)))
  5089. (should (equal 5 (org-get-valid-level 4 1)))
  5090. (should (equal 43 (org-get-valid-level 1 21)))
  5091. (should (equal 1 (org-get-valid-level 1 -1)))
  5092. (should (equal 1 (org-get-valid-level 2 -1)))
  5093. (should (equal 1 (org-get-valid-level 3 -1)))
  5094. (should (equal 3 (org-get-valid-level 4 -1)))
  5095. (should (equal 3 (org-get-valid-level 5 -1)))))
  5096. ;;; Planning
  5097. (ert-deftest test-org/at-planning-p ()
  5098. "Test `org-at-planning-p' specifications."
  5099. ;; Regular test.
  5100. (should
  5101. (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
  5102. (org-at-planning-p)))
  5103. (should-not
  5104. (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
  5105. (org-at-planning-p)))
  5106. ;; Correctly find planning attached to inlinetasks.
  5107. (when (featurep 'org-inlinetask)
  5108. (should
  5109. (org-test-with-temp-text
  5110. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
  5111. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  5112. (should-not
  5113. (org-test-with-temp-text
  5114. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  5115. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  5116. (should-not
  5117. (org-test-with-temp-text
  5118. "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  5119. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  5120. (should-not
  5121. (org-test-with-temp-text
  5122. "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
  5123. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
  5124. (ert-deftest test-org/add-planning-info ()
  5125. "Test `org-add-planning-info'."
  5126. ;; Create deadline when `org-adapt-indentation' is non-nil.
  5127. (should
  5128. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5129. (org-test-with-temp-text "* H\nParagraph<point>"
  5130. (let ((org-adapt-indentation t))
  5131. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5132. (replace-regexp-in-string
  5133. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5134. nil nil 1))))
  5135. ;; Create deadline when `org-adapt-indentation' is nil.
  5136. (should
  5137. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  5138. (org-test-with-temp-text "* H\nParagraph<point>"
  5139. (let ((org-adapt-indentation nil))
  5140. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5141. (replace-regexp-in-string
  5142. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5143. nil nil 1))))
  5144. ;; Update deadline when `org-adapt-indentation' is non-nil.
  5145. (should
  5146. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5147. (org-test-with-temp-text "\
  5148. * H
  5149. DEADLINE: <2015-06-24 Wed>
  5150. Paragraph<point>"
  5151. (let ((org-adapt-indentation t))
  5152. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5153. (replace-regexp-in-string
  5154. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5155. nil nil 1))))
  5156. ;; Update deadline when `org-adapt-indentation' is nil.
  5157. (should
  5158. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  5159. (org-test-with-temp-text "\
  5160. * H
  5161. DEADLINE: <2015-06-24 Wed>
  5162. Paragraph<point>"
  5163. (let ((org-adapt-indentation nil))
  5164. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5165. (replace-regexp-in-string
  5166. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5167. nil nil 1))))
  5168. ;; Schedule when `org-adapt-indentation' is non-nil.
  5169. (should
  5170. (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
  5171. (org-test-with-temp-text "* H\nParagraph<point>"
  5172. (let ((org-adapt-indentation t))
  5173. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  5174. (replace-regexp-in-string
  5175. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5176. nil nil 1))))
  5177. ;; Schedule when `org-adapt-indentation' is nil.
  5178. (should
  5179. (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
  5180. (org-test-with-temp-text "* H\nParagraph<point>"
  5181. (let ((org-adapt-indentation nil))
  5182. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  5183. (replace-regexp-in-string
  5184. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5185. nil nil 1))))
  5186. ;; Add deadline when scheduled.
  5187. (should
  5188. (equal "\
  5189. * H
  5190. DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
  5191. Paragraph"
  5192. (org-test-with-temp-text "\
  5193. * H
  5194. SCHEDULED: <2015-06-24 Wed>
  5195. Paragraph<point>"
  5196. (let ((org-adapt-indentation t))
  5197. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5198. (replace-regexp-in-string
  5199. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5200. nil nil 1))))
  5201. ;; Remove middle entry.
  5202. (should
  5203. (equal "\
  5204. * H
  5205. CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
  5206. Paragraph"
  5207. (org-test-with-temp-text "\
  5208. * H
  5209. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  5210. Paragraph<point>"
  5211. (let ((org-adapt-indentation t))
  5212. (org-add-planning-info nil nil 'deadline))
  5213. (replace-regexp-in-string
  5214. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  5215. nil nil 1))))
  5216. ;; Remove last entry and then middle entry (order should not
  5217. ;; matter).
  5218. (should
  5219. (equal "\
  5220. * H
  5221. CLOSED: [2015-06-24]
  5222. Paragraph"
  5223. (org-test-with-temp-text "\
  5224. * H
  5225. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  5226. Paragraph<point>"
  5227. (let ((org-adapt-indentation t))
  5228. (org-add-planning-info nil nil 'scheduled 'deadline))
  5229. (replace-regexp-in-string
  5230. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  5231. nil nil 1))))
  5232. ;; Remove closed when `org-adapt-indentation' is non-nil.
  5233. (should
  5234. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5235. (org-test-with-temp-text "\
  5236. * H
  5237. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  5238. Paragraph<point>"
  5239. (let ((org-adapt-indentation t))
  5240. (org-add-planning-info nil nil 'closed))
  5241. (replace-regexp-in-string
  5242. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5243. nil nil 1))))
  5244. (should
  5245. (equal "* H\n Paragraph"
  5246. (org-test-with-temp-text "\
  5247. * H
  5248. CLOSED: [2015-06-25 Thu]
  5249. Paragraph<point>"
  5250. (let ((org-adapt-indentation t))
  5251. (org-add-planning-info nil nil 'closed))
  5252. (replace-regexp-in-string
  5253. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5254. nil nil 1))))
  5255. ;; Remove closed when `org-adapt-indentation' is nil.
  5256. (should
  5257. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  5258. (org-test-with-temp-text "\
  5259. * H
  5260. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  5261. Paragraph<point>"
  5262. (let ((org-adapt-indentation nil))
  5263. (org-add-planning-info nil nil 'closed))
  5264. (replace-regexp-in-string
  5265. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5266. nil nil 1))))
  5267. (should
  5268. (equal "* H\nParagraph"
  5269. (org-test-with-temp-text "\
  5270. * H
  5271. CLOSED: [2015-06-25 Thu]
  5272. Paragraph<point>"
  5273. (let ((org-adapt-indentation nil))
  5274. (org-add-planning-info nil nil 'closed))
  5275. (replace-regexp-in-string
  5276. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5277. nil nil 1))))
  5278. ;; Remove closed entry and delete empty line.
  5279. (should
  5280. (equal "\
  5281. * H
  5282. Paragraph"
  5283. (org-test-with-temp-text "\
  5284. * H
  5285. CLOSED: [2015-06-24 Wed]
  5286. Paragraph<point>"
  5287. (let ((org-adapt-indentation t))
  5288. (org-add-planning-info nil nil 'closed))
  5289. (replace-regexp-in-string
  5290. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5291. nil nil 1))))
  5292. ;; Remove one entry and update another.
  5293. (should
  5294. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5295. (org-test-with-temp-text "\
  5296. * H
  5297. SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
  5298. Paragraph<point>"
  5299. (let ((org-adapt-indentation t))
  5300. (org-add-planning-info 'deadline "<2015-06-25 Thu>" 'scheduled))
  5301. (replace-regexp-in-string
  5302. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5303. nil nil 1)))))
  5304. (ert-deftest test-org/deadline ()
  5305. "Test `org-deadline' specifications."
  5306. ;; Insert a new value or replace existing one.
  5307. (should
  5308. (equal "* H\nDEADLINE: <2012-03-29>"
  5309. (org-test-with-temp-text "* H"
  5310. (let ((org-adapt-indentation nil)
  5311. (org-last-inserted-timestamp nil))
  5312. (org-deadline nil "<2012-03-29 Tue>"))
  5313. (replace-regexp-in-string
  5314. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5315. nil nil 1))))
  5316. (should
  5317. (equal "* H\nDEADLINE: <2014-03-04>"
  5318. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5319. (let ((org-adapt-indentation nil)
  5320. (org-last-inserted-timestamp nil))
  5321. (org-deadline nil "<2014-03-04 Thu>"))
  5322. (replace-regexp-in-string
  5323. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5324. nil nil 1))))
  5325. ;; Accept delta time, e.g., "+2d".
  5326. (should
  5327. (equal "* H\nDEADLINE: <2015-03-04>"
  5328. (org-test-at-time "2014-03-04"
  5329. (org-test-with-temp-text "* H"
  5330. (let ((org-adapt-indentation nil)
  5331. (org-last-inserted-timestamp nil))
  5332. (org-deadline nil "+1y"))
  5333. (replace-regexp-in-string
  5334. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5335. ;; Preserve repeater.
  5336. (should
  5337. (equal "* H\nDEADLINE: <2012-03-29 +2y>"
  5338. (org-test-with-temp-text "* H"
  5339. (let ((org-adapt-indentation nil)
  5340. (org-last-inserted-timestamp nil))
  5341. (org-deadline nil "<2012-03-29 Tue +2y>"))
  5342. (replace-regexp-in-string
  5343. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5344. ;; Preserve warning period.
  5345. (should
  5346. (equal "* H\nDEADLINE: <2021-07-20 -1d>"
  5347. (org-test-with-temp-text "* H"
  5348. (let ((org-adapt-indentation nil)
  5349. (org-last-inserted-timestamp nil))
  5350. (org-deadline nil "<2021-07-20 Tue -1d>"))
  5351. (replace-regexp-in-string
  5352. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5353. (should
  5354. (equal "* H\nDEADLINE: <2021-07-20 +1m -3d>"
  5355. (org-test-with-temp-text "* H"
  5356. (let ((org-adapt-indentation nil)
  5357. (org-last-inserted-timestamp nil))
  5358. (org-deadline nil "<2021-07-20 Tue +1m -3d>"))
  5359. (replace-regexp-in-string
  5360. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5361. ;; Remove CLOSED keyword, if any.
  5362. (should
  5363. (equal "* H\nDEADLINE: <2012-03-29>"
  5364. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  5365. (let ((org-adapt-indentation nil)
  5366. (org-last-inserted-timestamp nil))
  5367. (org-deadline nil "<2012-03-29 Tue>"))
  5368. (replace-regexp-in-string
  5369. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5370. ;; With C-u argument, remove DEADLINE keyword.
  5371. (should
  5372. (equal "* H\n"
  5373. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5374. (let ((org-adapt-indentation nil)
  5375. (org-last-inserted-timestamp nil))
  5376. (org-deadline '(4)))
  5377. (buffer-string))))
  5378. (should
  5379. (equal "* H"
  5380. (org-test-with-temp-text "* H"
  5381. (let ((org-adapt-indentation nil)
  5382. (org-last-inserted-timestamp nil))
  5383. (org-deadline '(4)))
  5384. (buffer-string))))
  5385. ;; With C-u C-u argument, prompt for a delay cookie.
  5386. (should
  5387. (equal "* H\nDEADLINE: <2012-03-29 -705d>"
  5388. (cl-letf (((symbol-function 'org-read-date)
  5389. (lambda (&rest args)
  5390. (org-time-string-to-time "2014-03-04"))))
  5391. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5392. (let ((org-adapt-indentation nil)
  5393. (org-last-inserted-timestamp nil))
  5394. (org-deadline '(16)))
  5395. (buffer-string)))))
  5396. (should-error
  5397. (cl-letf (((symbol-function 'org-read-date)
  5398. (lambda (&rest args)
  5399. (org-time-string-to-time "2014-03-04"))))
  5400. (org-test-with-temp-text "* H"
  5401. (let ((org-adapt-indentation nil)
  5402. (org-last-inserted-timestamp nil))
  5403. (org-deadline '(16)))
  5404. (buffer-string))))
  5405. ;; When a region is active and
  5406. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5407. ;; same value in all headlines in region.
  5408. (should
  5409. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5410. (org-test-with-temp-text "* H1\n* H2"
  5411. (let ((org-adapt-indentation nil)
  5412. (org-last-inserted-timestamp nil)
  5413. (org-loop-over-headlines-in-active-region t))
  5414. (transient-mark-mode 1)
  5415. (push-mark (point) t t)
  5416. (goto-char (point-max))
  5417. (org-deadline nil "2012-03-29"))
  5418. (replace-regexp-in-string
  5419. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5420. (should-not
  5421. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5422. (org-test-with-temp-text "* H1\n* H2"
  5423. (let ((org-adapt-indentation nil)
  5424. (org-last-inserted-timestamp nil)
  5425. (org-loop-over-headlines-in-active-region nil))
  5426. (transient-mark-mode 1)
  5427. (push-mark (point) t t)
  5428. (goto-char (point-max))
  5429. (org-deadline nil "2012-03-29"))
  5430. (replace-regexp-in-string
  5431. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5432. (ert-deftest test-org/schedule ()
  5433. "Test `org-schedule' specifications."
  5434. ;; Insert a new value or replace existing one.
  5435. (should
  5436. (equal "* H\nSCHEDULED: <2012-03-29>"
  5437. (org-test-with-temp-text "* H"
  5438. (let ((org-adapt-indentation nil)
  5439. (org-last-inserted-timestamp nil))
  5440. (org-schedule nil "<2012-03-29 Tue>"))
  5441. (replace-regexp-in-string
  5442. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5443. nil nil 1))))
  5444. (should
  5445. (equal "* H\nSCHEDULED: <2014-03-04>"
  5446. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5447. (let ((org-adapt-indentation nil)
  5448. (org-last-inserted-timestamp nil))
  5449. (org-schedule nil "<2014-03-04 Thu>"))
  5450. (replace-regexp-in-string
  5451. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5452. nil nil 1))))
  5453. ;; Accept delta time, e.g., "+2d".
  5454. (should
  5455. (equal "* H\nSCHEDULED: <2015-03-04>"
  5456. (org-test-at-time "2014-03-04"
  5457. (org-test-with-temp-text "* H"
  5458. (let ((org-adapt-indentation nil)
  5459. (org-last-inserted-timestamp nil))
  5460. (org-schedule nil "+1y"))
  5461. (replace-regexp-in-string
  5462. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5463. ;; Preserve repeater.
  5464. (should
  5465. (equal "* H\nSCHEDULED: <2012-03-29 +2y>"
  5466. (org-test-with-temp-text "* H"
  5467. (let ((org-adapt-indentation nil)
  5468. (org-last-inserted-timestamp nil))
  5469. (org-schedule nil "<2012-03-29 Tue +2y>"))
  5470. (replace-regexp-in-string
  5471. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5472. ;; Remove CLOSED keyword, if any.
  5473. (should
  5474. (equal "* H\nSCHEDULED: <2012-03-29>"
  5475. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  5476. (let ((org-adapt-indentation nil)
  5477. (org-last-inserted-timestamp nil))
  5478. (org-schedule nil "<2012-03-29 Tue>"))
  5479. (replace-regexp-in-string
  5480. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5481. ;; With C-u argument, remove SCHEDULED keyword.
  5482. (should
  5483. (equal "* H\n"
  5484. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5485. (let ((org-adapt-indentation nil)
  5486. (org-last-inserted-timestamp nil))
  5487. (org-schedule '(4)))
  5488. (buffer-string))))
  5489. (should
  5490. (equal "* H"
  5491. (org-test-with-temp-text "* H"
  5492. (let ((org-adapt-indentation nil)
  5493. (org-last-inserted-timestamp nil))
  5494. (org-schedule '(4)))
  5495. (buffer-string))))
  5496. ;; With C-u C-u argument, prompt for a delay cookie.
  5497. (should
  5498. (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
  5499. (cl-letf (((symbol-function 'org-read-date)
  5500. (lambda (&rest args)
  5501. (org-time-string-to-time "2014-03-04"))))
  5502. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5503. (let ((org-adapt-indentation nil)
  5504. (org-last-inserted-timestamp nil))
  5505. (org-schedule '(16)))
  5506. (buffer-string)))))
  5507. (should-error
  5508. (cl-letf (((symbol-function 'org-read-date)
  5509. (lambda (&rest args)
  5510. (org-time-string-to-time "2014-03-04"))))
  5511. (org-test-with-temp-text "* H"
  5512. (let ((org-adapt-indentation nil)
  5513. (org-last-inserted-timestamp nil))
  5514. (org-schedule '(16)))
  5515. (buffer-string))))
  5516. ;; When a region is active and
  5517. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5518. ;; same value in all headlines in region.
  5519. (should
  5520. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5521. (org-test-with-temp-text "* H1\n* H2"
  5522. (let ((org-adapt-indentation nil)
  5523. (org-last-inserted-timestamp nil)
  5524. (org-loop-over-headlines-in-active-region t))
  5525. (transient-mark-mode 1)
  5526. (push-mark (point) t t)
  5527. (goto-char (point-max))
  5528. (org-schedule nil "2012-03-29"))
  5529. (replace-regexp-in-string
  5530. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5531. (should-not
  5532. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5533. (org-test-with-temp-text "* H1\n* H2"
  5534. (let ((org-adapt-indentation nil)
  5535. (org-last-inserted-timestamp nil)
  5536. (org-loop-over-headlines-in-active-region nil))
  5537. (transient-mark-mode 1)
  5538. (push-mark (point) t t)
  5539. (goto-char (point-max))
  5540. (org-schedule nil "2012-03-29"))
  5541. (replace-regexp-in-string
  5542. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5543. (should
  5544. ;; check if a repeater survives re-scheduling.
  5545. (string-match-p
  5546. "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
  5547. (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
  5548. (let ((org-adapt-indentation nil)
  5549. (org-last-inserted-timestamp nil))
  5550. (org-schedule nil "2017-02-01"))
  5551. (buffer-string)))))
  5552. ;;; Property API
  5553. (ert-deftest test-org/buffer-property-keys ()
  5554. "Test `org-buffer-property-keys' specifications."
  5555. ;; Retrieve properties across siblings.
  5556. (should
  5557. (equal '("A" "B")
  5558. (org-test-with-temp-text "
  5559. * H1
  5560. :PROPERTIES:
  5561. :A: 1
  5562. :END:
  5563. * H2
  5564. :PROPERTIES:
  5565. :B: 1
  5566. :END:"
  5567. (org-buffer-property-keys))))
  5568. ;; Retrieve properties across children.
  5569. (should
  5570. (equal '("A" "B")
  5571. (org-test-with-temp-text "
  5572. * H1
  5573. :PROPERTIES:
  5574. :A: 1
  5575. :END:
  5576. ** H2
  5577. :PROPERTIES:
  5578. :B: 1
  5579. :END:"
  5580. (org-buffer-property-keys))))
  5581. ;; Retrieve muliple properties in the same drawer.
  5582. (should
  5583. (equal '("A" "B")
  5584. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5585. (org-buffer-property-keys))))
  5586. ;; Ignore extension symbol in property name.
  5587. (should
  5588. (equal '("A")
  5589. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5590. (org-buffer-property-keys))))
  5591. ;; Add bare property if xxx_ALL property is there
  5592. (should
  5593. (equal '("A" "B" "B_ALL")
  5594. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B_ALL: foo bar\n:END:"
  5595. (org-buffer-property-keys))))
  5596. ;; Add bare property if xxx_ALL property is there - check dupes
  5597. (should
  5598. (equal '("A" "B" "B_ALL")
  5599. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:B_ALL: foo bar\n:END:"
  5600. (org-buffer-property-keys))))
  5601. ;; Retrieve properties from #+PROPERTY keyword lines
  5602. (should
  5603. (equal '("A" "C")
  5604. (org-test-with-temp-text "#+PROPERTY: C foo\n* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5605. (org-buffer-property-keys))))
  5606. ;; Retrieve properties from #+PROPERTY keyword lines - make sure an _ALL property also
  5607. ;; adds the bare property
  5608. (should
  5609. (equal '("A" "C" "C_ALL")
  5610. (org-test-with-temp-text "#+PROPERTY: C_ALL foo bar\n* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5611. (org-buffer-property-keys))))
  5612. ;; With non-nil COLUMNS, extract property names from columns.
  5613. (should
  5614. (equal '("A" "B")
  5615. (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
  5616. (org-buffer-property-keys nil nil t))))
  5617. (should
  5618. (equal '("A" "B" "COLUMNS")
  5619. (org-test-with-temp-text
  5620. "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
  5621. (org-buffer-property-keys nil nil t))))
  5622. ;; In COLUMNS, ignore title and summary-type.
  5623. (should
  5624. (equal '("A")
  5625. (org-test-with-temp-text "#+COLUMNS: %A(Foo)"
  5626. (org-buffer-property-keys nil nil t))))
  5627. (should
  5628. (equal '("A")
  5629. (org-test-with-temp-text "#+COLUMNS: %A{Foo}"
  5630. (org-buffer-property-keys nil nil t))))
  5631. (should
  5632. (equal '("A")
  5633. (org-test-with-temp-text "#+COLUMNS: %A(Foo){Bar}"
  5634. (org-buffer-property-keys nil nil t)))))
  5635. (ert-deftest test-org/property-values ()
  5636. "Test `org-property-values' specifications."
  5637. ;; Regular test.
  5638. (should
  5639. (equal '("2" "1")
  5640. (org-test-with-temp-text
  5641. "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
  5642. (org-property-values "A"))))
  5643. ;; Ignore empty values.
  5644. (should-not
  5645. (org-test-with-temp-text
  5646. "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
  5647. (org-property-values "A")))
  5648. ;; Take into consideration extended values.
  5649. (should
  5650. (equal '("1 2")
  5651. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5652. (org-property-values "A")))))
  5653. (ert-deftest test-org/set-property ()
  5654. "Test `org-set-property' specifications."
  5655. (should
  5656. (equal
  5657. ":PROPERTIES:\n:TEST: t\n:END:\n"
  5658. (org-test-with-temp-text ""
  5659. (let ((org-property-format "%s %s"))
  5660. (org-set-property "TEST" "t"))
  5661. (buffer-string))))
  5662. (should
  5663. (equal
  5664. "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5665. (org-test-with-temp-text "* H"
  5666. (let ((org-adapt-indentation nil)
  5667. (org-property-format "%s %s"))
  5668. (org-set-property "TEST" "t"))
  5669. (buffer-string)))))
  5670. (ert-deftest test-org/delete-property ()
  5671. "Test `org-delete-property' specifications."
  5672. (should
  5673. (equal
  5674. ""
  5675. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5676. (org-delete-property "TEST")
  5677. (buffer-string))))
  5678. (should
  5679. (equal
  5680. ":PROPERTIES:\n:TEST1: t\n:END:\n"
  5681. (org-test-with-temp-text ":PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5682. (org-delete-property "TEST2")
  5683. (buffer-string))))
  5684. (should
  5685. (equal
  5686. "* H\n"
  5687. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5688. (org-delete-property "TEST")
  5689. (buffer-string))))
  5690. (should
  5691. (equal
  5692. "* H\n:PROPERTIES:\n:TEST1: t\n:END:\n"
  5693. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5694. (org-delete-property "TEST2")
  5695. (buffer-string)))))
  5696. (ert-deftest test-org/delete-property-globally ()
  5697. "Test `org-delete-property-global' specifications."
  5698. (should
  5699. (equal
  5700. ""
  5701. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5702. (org-delete-property-globally "TEST")
  5703. (buffer-string))))
  5704. (should
  5705. (equal
  5706. "* H\n"
  5707. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n* H\n:PROPERTIES:\n:TEST: nil\n:END:"
  5708. (org-delete-property-globally "TEST")
  5709. (buffer-string)))))
  5710. (ert-deftest test-org/find-property ()
  5711. "Test `org-find-property' specifications."
  5712. ;; Regular test.
  5713. (should
  5714. (= 1
  5715. (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
  5716. (org-find-property "prop"))))
  5717. ;; Find properties in top-level property drawer.
  5718. (should
  5719. (= 1
  5720. (org-test-with-temp-text ":PROPERTIES:\n:PROP: value\n:END:"
  5721. (org-find-property "prop"))))
  5722. ;; Ignore false positives.
  5723. (should
  5724. (= 27
  5725. (org-test-with-temp-text
  5726. "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
  5727. (org-find-property "A"))))
  5728. ;; Return first entry found in buffer.
  5729. (should
  5730. (= 1
  5731. (org-test-with-temp-text
  5732. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5733. (org-find-property "A"))))
  5734. ;; Only search visible part of the buffer.
  5735. (should
  5736. (= 31
  5737. (org-test-with-temp-text
  5738. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5739. (org-narrow-to-subtree)
  5740. (org-find-property "A"))))
  5741. ;; With optional argument, only find entries with a specific value.
  5742. (should-not
  5743. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5744. (org-find-property "A" "2")))
  5745. (should
  5746. (= 31
  5747. (org-test-with-temp-text
  5748. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
  5749. (org-find-property "A" "2"))))
  5750. ;; Use "nil" for explicit nil values.
  5751. (should
  5752. (= 31
  5753. (org-test-with-temp-text
  5754. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
  5755. (org-find-property "A" "nil")))))
  5756. (ert-deftest test-org/entry-delete ()
  5757. "Test `org-entry-delete' specifications."
  5758. ;; Regular test.
  5759. (should
  5760. (string-match
  5761. " *:PROPERTIES:\n *:B: +2\n *:END:"
  5762. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5763. (org-entry-delete (point) "A")
  5764. (buffer-string))))
  5765. ;; Also remove accumulated properties.
  5766. (should-not
  5767. (string-match
  5768. ":A"
  5769. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
  5770. (org-entry-delete (point) "A")
  5771. (buffer-string))))
  5772. ;; When last property is removed, remove the property drawer.
  5773. (should-not
  5774. (string-match
  5775. ":PROPERTIES:"
  5776. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
  5777. (org-entry-delete (point) "A")
  5778. (buffer-string))))
  5779. ;; Return a non-nil value when some property was removed.
  5780. (should
  5781. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5782. (org-entry-delete (point) "A")))
  5783. (should-not
  5784. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5785. (org-entry-delete (point) "C")))
  5786. ;; Special properties cannot be located in a drawer. Allow to
  5787. ;; remove them anyway, in case of user error.
  5788. (should
  5789. (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
  5790. (org-entry-delete (point) "SCHEDULED"))))
  5791. (ert-deftest test-org/entry-get ()
  5792. "Test `org-entry-get' specifications."
  5793. ;; Regular test.
  5794. (should
  5795. (equal "1"
  5796. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:"
  5797. (org-entry-get (point) "A"))))
  5798. (should
  5799. (equal "1"
  5800. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5801. (org-entry-get (point) "A"))))
  5802. ;; Ignore case.
  5803. (should
  5804. (equal "1"
  5805. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5806. (org-entry-get (point) "a"))))
  5807. ;; Handle extended values, both before and after base value.
  5808. (should
  5809. (equal "1 2 3"
  5810. (org-test-with-temp-text
  5811. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5812. (org-entry-get (point) "A"))))
  5813. ;; Empty values are returned as the empty string.
  5814. (should
  5815. (equal ""
  5816. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
  5817. (org-entry-get (point) "A"))))
  5818. ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
  5819. ;; otherwise, return nil.
  5820. (should-not
  5821. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5822. (org-entry-get (point) "A")))
  5823. (should
  5824. (equal "nil"
  5825. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5826. (org-entry-get (point) "A" nil t))))
  5827. ;; Return nil when no property is found, independently on the
  5828. ;; LITERAL-NIL argument.
  5829. (should-not
  5830. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5831. (org-entry-get (point) "B")))
  5832. (should-not
  5833. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5834. (org-entry-get (point) "B" nil t)))
  5835. ;; Handle inheritance, when allowed. Include extended values and
  5836. ;; possibly global values.
  5837. (should
  5838. (equal
  5839. "1"
  5840. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:\n* H"
  5841. (org-entry-get (point-max) "A" t))))
  5842. (should
  5843. (equal
  5844. "1"
  5845. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5846. (org-entry-get (point-max) "A" t))))
  5847. (should
  5848. (equal
  5849. "1"
  5850. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5851. (let ((org-use-property-inheritance t))
  5852. (org-entry-get (point-max) "A" 'selective)))))
  5853. (should-not
  5854. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5855. (let ((org-use-property-inheritance nil))
  5856. (org-entry-get (point-max) "A" 'selective))))
  5857. (should-not
  5858. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H2"
  5859. (let ((org-use-property-inheritance t))
  5860. (org-entry-get (point-max) "A" t))))
  5861. (should
  5862. (equal
  5863. "1 2"
  5864. (org-test-with-temp-text
  5865. ":PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5866. (org-entry-get (point-max) "A" t))))
  5867. (should
  5868. (equal
  5869. "1 2"
  5870. (org-test-with-temp-text
  5871. "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5872. (org-entry-get (point-max) "A" t))))
  5873. (should
  5874. (equal
  5875. "1 2"
  5876. (org-test-with-temp-text
  5877. ":PROPERTIES:\n:A: 1\n:END:\n* H1\n* H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5878. (org-entry-get (point-max) "A" t))))
  5879. (should
  5880. (equal
  5881. "1 2"
  5882. (org-test-with-temp-text
  5883. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2.1\n** H2.2\n:PROPERTIES:\n:A+: 2\n:END:"
  5884. (org-entry-get (point-max) "A" t))))
  5885. (should
  5886. (equal "1"
  5887. (org-test-with-temp-text
  5888. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
  5889. (org-mode-restart)
  5890. (org-entry-get (point-max) "A" t))))
  5891. (should
  5892. (equal "0 1"
  5893. (org-test-with-temp-text
  5894. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
  5895. (org-mode-restart)
  5896. (org-entry-get (point-max) "A" t))))
  5897. ;; document level property-drawer has precedance over
  5898. ;; global-property by PROPERTY-keyword.
  5899. (should
  5900. (equal "0 2"
  5901. (org-test-with-temp-text
  5902. ":PROPERTIES:\n:A: 0\n:END:\n#+PROPERTY: A 1\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5903. (org-mode-restart)
  5904. (org-entry-get (point-max) "A" t))))
  5905. ;; Use alternate separators
  5906. (should
  5907. (equal "0~2"
  5908. (org-test-with-temp-text
  5909. ":PROPERTIES:\n:A: 0\n:A+: 2\n:END:"
  5910. (let ((org-property-separators '((("A") . "~"))))
  5911. (org-entry-get (point) "A")))))
  5912. ;; Default separator is single space
  5913. (should
  5914. (equal "0 2"
  5915. (org-test-with-temp-text
  5916. ":PROPERTIES:\n:A: 0\n:B: 1\n:A+: 2\n:B+: 3\n:END:"
  5917. (let ((org-property-separators '((("B") . "~"))))
  5918. (org-entry-get (point) "A")))))
  5919. ;; Regular expression matching for separator
  5920. (should
  5921. (equal "0/2"
  5922. (org-test-with-temp-text
  5923. ":PROPERTIES:\n:A: 0\n:A+: 2\n:END:"
  5924. (let ((org-property-separators '((("B") . "~") ("[AC]" . "/"))))
  5925. (org-entry-get (point) "A")))))
  5926. ;; Separator works with inheritance
  5927. (should
  5928. (equal "1~2"
  5929. (org-test-with-temp-text
  5930. "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5931. (let ((org-property-separators '((("A") . "~"))))
  5932. (org-entry-get (point-max) "A" t))))))
  5933. (ert-deftest test-org/entry-properties ()
  5934. "Test `org-entry-properties' specifications."
  5935. ;; Get "ITEM" property.
  5936. (should
  5937. (equal "H"
  5938. (org-test-with-temp-text "* TODO H"
  5939. (cdr (assoc "ITEM" (org-entry-properties nil "ITEM"))))))
  5940. (should
  5941. (equal "H"
  5942. (org-test-with-temp-text "* TODO H"
  5943. (cdr (assoc "ITEM" (org-entry-properties))))))
  5944. ;; Get "TODO" property. TODO keywords are case sensitive.
  5945. (should
  5946. (equal "TODO"
  5947. (org-test-with-temp-text "* TODO H"
  5948. (cdr (assoc "TODO" (org-entry-properties nil "TODO"))))))
  5949. (should
  5950. (equal "TODO"
  5951. (org-test-with-temp-text "* TODO H"
  5952. (cdr (assoc "TODO" (org-entry-properties))))))
  5953. (should-not
  5954. (org-test-with-temp-text "* H"
  5955. (assoc "TODO" (org-entry-properties nil "TODO"))))
  5956. (should-not
  5957. (org-test-with-temp-text "* todo H"
  5958. (assoc "TODO" (org-entry-properties nil "TODO"))))
  5959. ;; Get "PRIORITY" property.
  5960. (should
  5961. (equal "A"
  5962. (org-test-with-temp-text "* [#A] H"
  5963. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  5964. (should
  5965. (equal "A"
  5966. (org-test-with-temp-text "* [#A] H"
  5967. (cdr (assoc "PRIORITY" (org-entry-properties))))))
  5968. (should
  5969. (equal (char-to-string org-priority-default)
  5970. (org-test-with-temp-text "* H"
  5971. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  5972. ;; Get "FILE" property.
  5973. (should
  5974. (org-test-with-temp-text-in-file "* H\nParagraph"
  5975. (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil "FILE")))
  5976. (buffer-file-name))))
  5977. (should
  5978. (org-test-with-temp-text-in-file "* H\nParagraph"
  5979. (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
  5980. (buffer-file-name))))
  5981. (should-not
  5982. (org-test-with-temp-text "* H\nParagraph"
  5983. (cdr (assoc "FILE" (org-entry-properties nil "FILE")))))
  5984. ;; Get "TAGS" property.
  5985. (should
  5986. (equal ":tag1:tag2:"
  5987. (org-test-with-temp-text "* H :tag1:tag2:"
  5988. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS"))))))
  5989. (should
  5990. (equal ":tag1:tag2:"
  5991. (org-test-with-temp-text "* H :tag1:tag2:"
  5992. (cdr (assoc "TAGS" (org-entry-properties))))))
  5993. (should-not
  5994. (org-test-with-temp-text "* H"
  5995. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS")))))
  5996. ;; Get "ALLTAGS" property.
  5997. (should
  5998. (equal ":tag1:tag2:"
  5999. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  6000. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS"))))))
  6001. (should
  6002. (equal ":tag1:tag2:"
  6003. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  6004. (cdr (assoc "ALLTAGS" (org-entry-properties))))))
  6005. (should-not
  6006. (org-test-with-temp-text "* H"
  6007. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS")))))
  6008. ;; Get "BLOCKED" property.
  6009. (should
  6010. (equal "t"
  6011. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  6012. (let ((org-enforce-todo-dependencies t)
  6013. (org-blocker-hook
  6014. '(org-block-todo-from-children-or-siblings-or-parent)))
  6015. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  6016. (should
  6017. (equal ""
  6018. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  6019. (let ((org-enforce-todo-dependencies t)
  6020. (org-blocker-hook
  6021. '(org-block-todo-from-children-or-siblings-or-parent)))
  6022. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  6023. ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
  6024. (should
  6025. (equal
  6026. "[2012-03-29 thu.]"
  6027. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  6028. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED"))))))
  6029. (should
  6030. (equal
  6031. "[2012-03-29 thu.]"
  6032. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  6033. (cdr (assoc "CLOSED" (org-entry-properties))))))
  6034. (should-not
  6035. (org-test-with-temp-text "* H"
  6036. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED")))))
  6037. (should
  6038. (equal
  6039. "<2014-03-04 tue.>"
  6040. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6041. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE"))))))
  6042. (should
  6043. (equal
  6044. "<2014-03-04 tue.>"
  6045. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6046. (cdr (assoc "DEADLINE" (org-entry-properties))))))
  6047. (should-not
  6048. (org-test-with-temp-text "* H"
  6049. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE")))))
  6050. (should
  6051. (equal
  6052. "<2014-03-04 tue.>"
  6053. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6054. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED"))))))
  6055. (should
  6056. (equal
  6057. "<2014-03-04 tue.>"
  6058. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6059. (cdr (assoc "SCHEDULED" (org-entry-properties))))))
  6060. (should-not
  6061. (org-test-with-temp-text "* H"
  6062. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED")))))
  6063. ;; Get "CATEGORY"
  6064. (should
  6065. (equal "cat"
  6066. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  6067. (cdr (assoc "CATEGORY" (org-entry-properties))))))
  6068. (should
  6069. (equal "cat"
  6070. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  6071. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  6072. (should
  6073. (equal "cat"
  6074. (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
  6075. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  6076. (should
  6077. (equal "cat2"
  6078. (org-test-with-temp-text
  6079. (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6080. "\n"
  6081. "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
  6082. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  6083. ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
  6084. (should
  6085. (equal "<2012-03-29 thu.>"
  6086. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
  6087. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  6088. (should
  6089. (equal "[2012-03-29 thu.]"
  6090. (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
  6091. (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
  6092. (should
  6093. (equal "<2012-03-29 thu.>"
  6094. (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
  6095. (cdr (assoc "TIMESTAMP" (org-entry-properties nil "TIMESTAMP"))))))
  6096. (should
  6097. (equal "[2014-03-04 tue.]"
  6098. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
  6099. (cdr (assoc "TIMESTAMP_IA"
  6100. (org-entry-properties nil "TIMESTAMP_IA"))))))
  6101. (should-not
  6102. (equal "<2012-03-29 thu.>"
  6103. (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
  6104. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  6105. ;; Get standard properties.
  6106. (should
  6107. (equal "1"
  6108. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6109. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  6110. ;; Handle extended properties.
  6111. (should
  6112. (equal "1 2 3"
  6113. (org-test-with-temp-text
  6114. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  6115. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  6116. (should
  6117. (equal "1 2 3"
  6118. (org-test-with-temp-text
  6119. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
  6120. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  6121. ;; Ignore forbidden (special) properties.
  6122. (should-not
  6123. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
  6124. (cdr (assoc "TODO" (org-entry-properties nil 'standard))))))
  6125. (ert-deftest test-org/entry-put ()
  6126. "Test `org-entry-put' specifications."
  6127. ;; Error when not a string or nil.
  6128. (should-error
  6129. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  6130. (org-entry-put 1 "test" 2)))
  6131. ;; Error when property name is invalid.
  6132. (should-error
  6133. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  6134. (org-entry-put 1 "no space" "value")))
  6135. (should-error
  6136. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  6137. (org-entry-put 1 "" "value")))
  6138. ;; Set "TODO" property.
  6139. (should
  6140. (string-match (regexp-quote " TODO H")
  6141. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  6142. (org-entry-put (point) "TODO" "TODO")
  6143. (buffer-string))))
  6144. (should
  6145. (string-match (regexp-quote "* H")
  6146. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  6147. (org-entry-put (point) "TODO" nil)
  6148. (buffer-string))))
  6149. ;; Set "PRIORITY" property.
  6150. (should
  6151. (equal "* [#A] H"
  6152. (org-test-with-temp-text "* [#B] H"
  6153. (org-entry-put (point) "PRIORITY" "A")
  6154. (buffer-string))))
  6155. (should
  6156. (equal "* H"
  6157. (org-test-with-temp-text "* [#B] H"
  6158. (org-entry-put (point) "PRIORITY" nil)
  6159. (buffer-string))))
  6160. ;; Set "SCHEDULED" property.
  6161. (should
  6162. (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
  6163. (org-test-with-temp-text "* H"
  6164. (org-entry-put (point) "SCHEDULED" "2014-03-04")
  6165. (buffer-string))))
  6166. (should
  6167. (string= "* H\n"
  6168. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6169. (org-entry-put (point) "SCHEDULED" nil)
  6170. (buffer-string))))
  6171. (should
  6172. (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
  6173. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6174. (org-entry-put (point) "SCHEDULED" "earlier")
  6175. (buffer-string))))
  6176. (should
  6177. (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
  6178. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6179. (org-entry-put (point) "SCHEDULED" "later")
  6180. (buffer-string))))
  6181. ;; Set "DEADLINE" property.
  6182. (should
  6183. (string-match "^ *DEADLINE: <2014-03-04 .*?>"
  6184. (org-test-with-temp-text "* H"
  6185. (org-entry-put (point) "DEADLINE" "2014-03-04")
  6186. (buffer-string))))
  6187. (should
  6188. (string= "* H\n"
  6189. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6190. (org-entry-put (point) "DEADLINE" nil)
  6191. (buffer-string))))
  6192. (should
  6193. (string-match "^ *DEADLINE: <2014-03-03 .*?>"
  6194. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6195. (org-entry-put (point) "DEADLINE" "earlier")
  6196. (buffer-string))))
  6197. (should
  6198. (string-match "^ *DEADLINE: <2014-03-05 .*?>"
  6199. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6200. (org-entry-put (point) "DEADLINE" "later")
  6201. (buffer-string))))
  6202. ;; Set "CATEGORY" property
  6203. (should
  6204. (string-match "^ *:CATEGORY: cat"
  6205. (org-test-with-temp-text "* H"
  6206. (org-entry-put (point) "CATEGORY" "cat")
  6207. (buffer-string))))
  6208. ;; Regular properties, with or without pre-existing drawer.
  6209. (should
  6210. (string-match "^ *:A: +2$"
  6211. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6212. (org-entry-put (point) "A" "2")
  6213. (buffer-string))))
  6214. (should
  6215. (string-match "^ *:A: +1$"
  6216. (org-test-with-temp-text "* H"
  6217. (org-entry-put (point) "A" "1")
  6218. (buffer-string))))
  6219. ;; Special case: two consecutive headlines.
  6220. (should
  6221. (string-match "\\* A\n *:PROPERTIES:"
  6222. (org-test-with-temp-text "* A\n** B"
  6223. (org-entry-put (point) "A" "1")
  6224. (buffer-string)))))
  6225. (ert-deftest test-org/refresh-properties ()
  6226. "Test `org-refresh-properties' specifications."
  6227. (should
  6228. (equal "1"
  6229. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6230. (org-refresh-properties "A" 'org-test)
  6231. (get-text-property (point) 'org-test))))
  6232. (should-not
  6233. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6234. (org-refresh-properties "B" 'org-test)
  6235. (get-text-property (point) 'org-test)))
  6236. ;; Handle properties only defined with extension syntax, i.e.,
  6237. ;; "PROPERTY+".
  6238. (should
  6239. (equal "1"
  6240. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
  6241. (org-refresh-properties "A" 'org-test)
  6242. (get-text-property (point) 'org-test))))
  6243. ;; When property is inherited, add text property to the whole
  6244. ;; sub-tree.
  6245. (should
  6246. (equal "1"
  6247. (org-test-with-temp-text
  6248. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
  6249. (let ((org-use-property-inheritance t))
  6250. (org-refresh-properties "A" 'org-test))
  6251. (get-text-property (point) 'org-test))))
  6252. ;; When a document level property-drawer is used, those properties
  6253. ;; should work exactly like headline-properties as if at a
  6254. ;; headline-level 0.
  6255. (should
  6256. (equal "1"
  6257. (org-test-with-temp-text
  6258. ":PROPERTIES:\n:A: 1\n:END:\n"
  6259. (org-mode-restart)
  6260. (let ((org-use-property-inheritance t))
  6261. (org-refresh-properties "A" 'org-test))
  6262. (get-text-property (point) 'org-test))))
  6263. (should-not
  6264. (equal "1"
  6265. (org-test-with-temp-text
  6266. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  6267. (org-mode-restart)
  6268. (let ((org-use-property-inheritance nil))
  6269. (org-refresh-properties "A" 'org-test))
  6270. (get-text-property (point) 'org-test))))
  6271. (should
  6272. (equal "1"
  6273. (org-test-with-temp-text
  6274. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  6275. (org-mode-restart)
  6276. (let ((org-use-property-inheritance t))
  6277. (org-refresh-properties "A" 'org-test))
  6278. (get-text-property (point) 'org-test))))
  6279. (should
  6280. (equal "2"
  6281. (org-test-with-temp-text
  6282. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1\n:PROPERTIES:\n:A: 2\n:END:"
  6283. (org-mode-restart)
  6284. (let ((org-use-property-inheritance t))
  6285. (org-refresh-properties "A" 'org-test))
  6286. (get-text-property (point) 'org-test))))
  6287. ;; When property is inherited, use global value across the whole
  6288. ;; buffer. However local values have precedence, as well as the
  6289. ;; document level property-drawer.
  6290. (should-not
  6291. (equal "1"
  6292. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  6293. (org-mode-restart)
  6294. (let ((org-use-property-inheritance nil))
  6295. (org-refresh-properties "A" 'org-test))
  6296. (get-text-property (point) 'org-test))))
  6297. (should
  6298. (equal "1"
  6299. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  6300. (org-mode-restart)
  6301. (let ((org-use-property-inheritance t))
  6302. (org-refresh-properties "A" 'org-test))
  6303. (get-text-property (point) 'org-test))))
  6304. (should
  6305. (equal "2"
  6306. (org-test-with-temp-text
  6307. "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
  6308. (org-mode-restart)
  6309. (let ((org-use-property-inheritance t))
  6310. (org-refresh-properties "A" 'org-test))
  6311. (get-text-property (point) 'org-test))))
  6312. ;; When both keyword-property and document-level property-block is
  6313. ;; defined, the property-block has precedance.
  6314. (should
  6315. (equal "1"
  6316. (org-test-with-temp-text
  6317. ":PROPERTIES:\n:A: 1\n:END:\n#+PROPERTY: A 2\n<point>* H1"
  6318. (org-mode-restart)
  6319. (let ((org-use-property-inheritance t))
  6320. (org-refresh-properties "A" 'org-test))
  6321. (get-text-property (point) 'org-test)))))
  6322. (ert-deftest test-org/refresh-category-properties ()
  6323. "Test `org-refresh-category-properties' specifications"
  6324. (should
  6325. (equal "cat1"
  6326. (org-test-with-temp-text
  6327. ":PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6328. (org-refresh-category-properties)
  6329. (org-get-category))))
  6330. (should
  6331. (equal "cat1"
  6332. (org-test-with-temp-text
  6333. "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6334. (org-refresh-category-properties)
  6335. (org-get-category))))
  6336. ;; Even though property-inheritance is deactivated, category
  6337. ;; property should be inherited. As described in
  6338. ;; `org-use-property-inheritance'.
  6339. (should
  6340. (equal "cat1"
  6341. (org-test-with-temp-text
  6342. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  6343. (org-mode-restart)
  6344. (let ((org-use-property-inheritance nil))
  6345. (org-refresh-category-properties))
  6346. (org-get-category))))
  6347. (should
  6348. (equal "cat1"
  6349. (org-test-with-temp-text
  6350. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  6351. (org-mode-restart)
  6352. (let ((org-use-property-inheritance t))
  6353. (org-refresh-category-properties))
  6354. (org-get-category))))
  6355. (should
  6356. (equal "cat2"
  6357. (org-test-with-temp-text
  6358. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H\n:PROPERTIES:\n:CATEGORY: cat2\n:END:\n"
  6359. (org-mode-restart)
  6360. (let ((org-use-property-inheritance t))
  6361. (org-refresh-category-properties))
  6362. (org-get-category)))))
  6363. ;;; Refile
  6364. (ert-deftest test-org/refile-get-targets ()
  6365. "Test `org-refile-get-targets' specifications."
  6366. ;; :maxlevel includes all headings above specified value.
  6367. (should
  6368. (equal '("H1" "H2" "H3")
  6369. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6370. (let ((org-refile-use-outline-path nil)
  6371. (org-refile-targets `((nil :maxlevel . 3))))
  6372. (mapcar #'car (org-refile-get-targets))))))
  6373. (should
  6374. (equal '("H1" "H2")
  6375. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6376. (let ((org-refile-use-outline-path nil)
  6377. (org-refile-targets `((nil :maxlevel . 2))))
  6378. (mapcar #'car (org-refile-get-targets))))))
  6379. ;; :level limits targets to headlines with the specified level.
  6380. (should
  6381. (equal '("H2")
  6382. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6383. (let ((org-refile-use-outline-path nil)
  6384. (org-refile-targets `((nil :level . 2))))
  6385. (mapcar #'car (org-refile-get-targets))))))
  6386. ;; :tag limits targets to headlines with specified tag.
  6387. (should
  6388. (equal '("H1")
  6389. (org-test-with-temp-text "* H1 :foo:\n** H2\n*** H3 :bar:"
  6390. (let ((org-refile-use-outline-path nil)
  6391. (org-refile-targets `((nil :tag . "foo"))))
  6392. (mapcar #'car (org-refile-get-targets))))))
  6393. ;; :todo limits targets to headlines with specified TODO keyword.
  6394. (should
  6395. (equal '("H2")
  6396. (org-test-with-temp-text "* H1\n** TODO H2\n*** DONE H3"
  6397. (let ((org-refile-use-outline-path nil)
  6398. (org-refile-targets `((nil :todo . "TODO"))))
  6399. (mapcar #'car (org-refile-get-targets))))))
  6400. ;; :regexp filters targets matching provided regexp.
  6401. (should
  6402. (equal '("F2" "F3")
  6403. (org-test-with-temp-text "* H1\n** F2\n*** F3"
  6404. (let ((org-refile-use-outline-path nil)
  6405. (org-refile-targets `((nil :regexp . "F"))))
  6406. (mapcar #'car (org-refile-get-targets))))))
  6407. ;; A nil `org-refile-targets' includes only top level headlines in
  6408. ;; current buffer.
  6409. (should
  6410. (equal '("H1" "H2")
  6411. (org-test-with-temp-text "* H1\n** S1\n* H2"
  6412. (let ((org-refile-use-outline-path nil)
  6413. (org-refile-targets nil))
  6414. (mapcar #'car (org-refile-get-targets))))))
  6415. ;; Return value is the union of the targets according to all the
  6416. ;; defined rules. However, prevent duplicates.
  6417. (should
  6418. (equal '("F2" "F3" "H1")
  6419. (org-test-with-temp-text "* TODO H1\n** F2\n*** F3"
  6420. (let ((org-refile-use-outline-path nil)
  6421. (org-refile-targets `((nil :regexp . "F")
  6422. (nil :todo . "TODO"))))
  6423. (mapcar #'car (org-refile-get-targets))))))
  6424. (should
  6425. (equal '("F2" "F3" "H1")
  6426. (org-test-with-temp-text "* TODO H1\n** TODO F2\n*** F3"
  6427. (let ((org-refile-use-outline-path nil)
  6428. (org-refile-targets `((nil :regexp . "F")
  6429. (nil :todo . "TODO"))))
  6430. (mapcar #'car (org-refile-get-targets))))))
  6431. ;; When `org-refile-use-outline-path' is non-nil, provide targets as
  6432. ;; paths.
  6433. (should
  6434. (equal '("H1" "H1/H2" "H1/H2/H3")
  6435. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6436. (let ((org-refile-use-outline-path t)
  6437. (org-refile-targets `((nil :maxlevel . 3))))
  6438. (mapcar #'car (org-refile-get-targets))))))
  6439. ;; When providing targets as paths, escape forward slashes in
  6440. ;; headings with backslashes.
  6441. (should
  6442. (equal '("H1\\/foo")
  6443. (org-test-with-temp-text "* H1/foo"
  6444. (let ((org-refile-use-outline-path t)
  6445. (org-refile-targets `((nil :maxlevel . 1))))
  6446. (mapcar #'car (org-refile-get-targets))))))
  6447. ;; When `org-refile-use-outline-path' is `file', include file name
  6448. ;; without directory in targets.
  6449. (should
  6450. (org-test-with-temp-text-in-file "* H1"
  6451. (let* ((filename (buffer-file-name))
  6452. (org-refile-use-outline-path 'file)
  6453. (org-refile-targets `(((,filename) :level . 1))))
  6454. (member (file-name-nondirectory filename)
  6455. (mapcar #'car (org-refile-get-targets))))))
  6456. ;; When `org-refile-use-outline-path' is `full-file-path', include
  6457. ;; full file name.
  6458. (should
  6459. (org-test-with-temp-text-in-file "* H1"
  6460. (let* ((filename (file-truename (buffer-file-name)))
  6461. (org-refile-use-outline-path 'full-file-path)
  6462. (org-refile-targets `(((,filename) :level . 1))))
  6463. (member filename (mapcar #'car (org-refile-get-targets))))))
  6464. ;; When `org-refile-use-outline-path' is `buffer-name', include
  6465. ;; buffer name.
  6466. (should
  6467. (org-test-with-temp-text "* H1"
  6468. (let* ((org-refile-use-outline-path 'buffer-name)
  6469. (org-refile-targets `((nil :level . 1))))
  6470. (member (buffer-name) (mapcar #'car (org-refile-get-targets)))))))
  6471. ;;; Sparse trees
  6472. (ert-deftest test-org/match-sparse-tree ()
  6473. "Test `org-match-sparse-tree' specifications."
  6474. ;; Match tags.
  6475. (should-not
  6476. (org-test-with-temp-text "* H\n** H1 :tag:"
  6477. (org-match-sparse-tree nil "tag")
  6478. (search-forward "H1")
  6479. (org-invisible-p2)))
  6480. (should
  6481. (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
  6482. (org-match-sparse-tree nil "tag")
  6483. (search-forward "H2")
  6484. (org-invisible-p2)))
  6485. ;; "-" operator for tags.
  6486. (should-not
  6487. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6488. (org-match-sparse-tree nil "tag1-tag2")
  6489. (search-forward "H1")
  6490. (org-invisible-p2)))
  6491. (should
  6492. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6493. (org-match-sparse-tree nil "tag1-tag2")
  6494. (search-forward "H2")
  6495. (org-invisible-p2)))
  6496. ;; "&" operator for tags.
  6497. (should
  6498. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6499. (org-match-sparse-tree nil "tag1&tag2")
  6500. (search-forward "H1")
  6501. (org-invisible-p2)))
  6502. (should-not
  6503. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6504. (org-match-sparse-tree nil "tag1&tag2")
  6505. (search-forward "H2")
  6506. (org-invisible-p2)))
  6507. ;; "|" operator for tags.
  6508. (should-not
  6509. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6510. (org-match-sparse-tree nil "tag1|tag2")
  6511. (search-forward "H1")
  6512. (org-invisible-p2)))
  6513. (should-not
  6514. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6515. (org-match-sparse-tree nil "tag1|tag2")
  6516. (search-forward "H2")
  6517. (org-invisible-p2)))
  6518. ;; Regexp match on tags.
  6519. (should-not
  6520. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6521. (org-match-sparse-tree nil "{^tag.*}")
  6522. (search-forward "H1")
  6523. (org-invisible-p2)))
  6524. (should
  6525. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6526. (org-match-sparse-tree nil "{^tag.*}")
  6527. (search-forward "H2")
  6528. (org-invisible-p2)))
  6529. ;; Match group tags.
  6530. (should-not
  6531. (org-test-with-temp-text
  6532. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6533. (org-match-sparse-tree nil "work")
  6534. (search-forward "H1")
  6535. (org-invisible-p2)))
  6536. (should-not
  6537. (org-test-with-temp-text
  6538. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6539. (org-match-sparse-tree nil "work")
  6540. (search-forward "H2")
  6541. (org-invisible-p2)))
  6542. ;; Match group tags with hard brackets.
  6543. (should-not
  6544. (org-test-with-temp-text
  6545. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6546. (org-match-sparse-tree nil "work")
  6547. (search-forward "H1")
  6548. (org-invisible-p2)))
  6549. (should-not
  6550. (org-test-with-temp-text
  6551. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6552. (org-match-sparse-tree nil "work")
  6553. (search-forward "H2")
  6554. (org-invisible-p2)))
  6555. ;; Match tags in hierarchies
  6556. (should-not
  6557. (org-test-with-temp-text
  6558. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6559. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6560. #+TAGS: { Lev_3 : Lev_4 }\n
  6561. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6562. (org-match-sparse-tree nil "Lev_1")
  6563. (search-forward "H4")
  6564. (org-invisible-p2)))
  6565. (should-not
  6566. (org-test-with-temp-text
  6567. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6568. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6569. #+TAGS: { Lev_3 : Lev_4 }\n
  6570. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6571. (org-match-sparse-tree nil "Lev_1+Lev_3")
  6572. (search-forward "H4")
  6573. (org-invisible-p2)))
  6574. ;; Match regular expressions in tags
  6575. (should-not
  6576. (org-test-with-temp-text
  6577. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
  6578. (org-match-sparse-tree nil "Lev")
  6579. (search-forward "H1")
  6580. (org-invisible-p2)))
  6581. (should
  6582. (org-test-with-temp-text
  6583. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
  6584. (org-match-sparse-tree nil "Lev")
  6585. (search-forward "H1")
  6586. (org-invisible-p2)))
  6587. ;; Match properties.
  6588. (should
  6589. (org-test-with-temp-text
  6590. "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
  6591. (org-match-sparse-tree nil "A=\"1\"")
  6592. (search-forward "H2")
  6593. (org-invisible-p2)))
  6594. (should-not
  6595. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6596. (org-match-sparse-tree nil "A=\"1\"")
  6597. (search-forward "H2")
  6598. (org-invisible-p2)))
  6599. ;; Case is not significant when matching properties.
  6600. (should-not
  6601. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6602. (org-match-sparse-tree nil "a=\"1\"")
  6603. (search-forward "H2")
  6604. (org-invisible-p2)))
  6605. (should-not
  6606. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
  6607. (org-match-sparse-tree nil "A=\"1\"")
  6608. (search-forward "H2")
  6609. (org-invisible-p2)))
  6610. ;; Match special LEVEL property.
  6611. (should-not
  6612. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6613. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6614. (search-forward "H1")
  6615. (org-invisible-p2)))
  6616. (should
  6617. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6618. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6619. (search-forward "H2")
  6620. (org-invisible-p2)))
  6621. ;; Comparison operators when matching properties.
  6622. (should
  6623. (org-test-with-temp-text
  6624. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6625. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6626. (search-forward "H1")
  6627. (org-invisible-p2)))
  6628. (should-not
  6629. (org-test-with-temp-text
  6630. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6631. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6632. (search-forward "H2")
  6633. (org-invisible-p2)))
  6634. ;; Regexp match on properties values.
  6635. (should-not
  6636. (org-test-with-temp-text
  6637. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6638. (org-match-sparse-tree nil "A={f.*}")
  6639. (search-forward "H1")
  6640. (org-invisible-p2)))
  6641. (should
  6642. (org-test-with-temp-text
  6643. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6644. (org-match-sparse-tree nil "A={f.*}")
  6645. (search-forward "H2")
  6646. (org-invisible-p2)))
  6647. ;; With an optional argument, limit match to TODO entries.
  6648. (should-not
  6649. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6650. (org-match-sparse-tree t "tag")
  6651. (search-forward "H1")
  6652. (org-invisible-p2)))
  6653. (should
  6654. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6655. (org-match-sparse-tree t "tag")
  6656. (search-forward "H2")
  6657. (org-invisible-p2))))
  6658. (ert-deftest test-org/occur ()
  6659. "Test `org-occur' specifications."
  6660. ;; Count number of matches.
  6661. (should
  6662. (= 1
  6663. (org-test-with-temp-text "* H\nA\n* H2"
  6664. (org-occur "A"))))
  6665. (should
  6666. (= 2
  6667. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6668. (org-occur "A"))))
  6669. ;; Test CALLBACK optional argument.
  6670. (should
  6671. (= 0
  6672. (org-test-with-temp-text "* H\nA\n* H2"
  6673. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6674. (should
  6675. (= 1
  6676. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6677. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6678. ;; Case-fold searches according to `org-occur-case-fold-search'.
  6679. (should
  6680. (= 2
  6681. (org-test-with-temp-text "Aa"
  6682. (let ((org-occur-case-fold-search t)) (org-occur "A")))))
  6683. (should
  6684. (= 2
  6685. (org-test-with-temp-text "Aa"
  6686. (let ((org-occur-case-fold-search t)) (org-occur "a")))))
  6687. (should
  6688. (= 1
  6689. (org-test-with-temp-text "Aa"
  6690. (let ((org-occur-case-fold-search nil)) (org-occur "A")))))
  6691. (should
  6692. (= 1
  6693. (org-test-with-temp-text "Aa"
  6694. (let ((org-occur-case-fold-search nil)) (org-occur "a")))))
  6695. (should
  6696. (= 1
  6697. (org-test-with-temp-text "Aa"
  6698. (let ((org-occur-case-fold-search 'smart)) (org-occur "A")))))
  6699. (should
  6700. (= 2
  6701. (org-test-with-temp-text "Aa"
  6702. (let ((org-occur-case-fold-search 'smart)) (org-occur "a"))))))
  6703. ;;; Tags
  6704. (ert-deftest test-org/tag-string-to-alist ()
  6705. "Test `org-tag-string-to-alist' specifications."
  6706. ;; Tag without selection key.
  6707. (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
  6708. ;; Tag with selection key.
  6709. (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t))))
  6710. ;; Tag group.
  6711. (should
  6712. (equal
  6713. (org-tag-string-to-alist "[ group : t1 t2 ]")
  6714. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag))))
  6715. ;; Mutually exclusive tags.
  6716. (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
  6717. '((:startgroup) ("tag1") ("tag2") (:endgroup))))
  6718. (should
  6719. (equal
  6720. (org-tag-string-to-alist "{ group : tag1 tag2 }")
  6721. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))))
  6722. (ert-deftest test-org/tag-alist-to-string ()
  6723. "Test `org-tag-alist-to-string' specifications."
  6724. (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
  6725. (should (equal (org-tag-alist-to-string '(("tag1" . ?t))) "tag1(t)"))
  6726. (should
  6727. (equal
  6728. (org-tag-alist-to-string
  6729. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6730. "[ group : t1 t2 ]"))
  6731. (should
  6732. (equal (org-tag-alist-to-string
  6733. '((:startgroup) ("tag1") ("tag2") (:endgroup)))
  6734. "{ tag1 tag2 }"))
  6735. (should
  6736. (equal
  6737. (org-tag-alist-to-string
  6738. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))
  6739. "{ group : tag1 tag2 }")))
  6740. (ert-deftest test-org/tag-alist-to-groups ()
  6741. "Test `org-tag-alist-to-groups' specifications."
  6742. (should
  6743. (equal (org-tag-alist-to-groups
  6744. '((:startgroup) ("group") (:grouptags) ("t1") ("t2") (:endgroup)))
  6745. '(("group" "t1" "t2"))))
  6746. (should
  6747. (equal
  6748. (org-tag-alist-to-groups
  6749. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6750. '(("group" "t1" "t2"))))
  6751. (should-not
  6752. (org-tag-alist-to-groups
  6753. '((:startgroup) ("group") ("t1") ("t2") (:endgroup)))))
  6754. (ert-deftest test-org/tag-align ()
  6755. "Test tags alignment."
  6756. ;; Test aligning tags with different display width.
  6757. (should
  6758. ;; 12345678901234567890
  6759. (equal "* Test :abc:"
  6760. (org-test-with-temp-text "* Test :abc:"
  6761. (let ((org-tags-column -20)
  6762. (indent-tabs-mode nil))
  6763. (org-fix-tags-on-the-fly))
  6764. (buffer-string))))
  6765. (should
  6766. ;; 12345678901234567890
  6767. (equal "* Test :日本語:"
  6768. (org-test-with-temp-text "* Test :日本語:"
  6769. (let ((org-tags-column -20)
  6770. (indent-tabs-mode nil))
  6771. (org-fix-tags-on-the-fly))
  6772. (buffer-string))))
  6773. ;; Make sure aligning tags do not skip invisible text.
  6774. (should
  6775. (equal "* [[linkx]] :tag:"
  6776. (org-test-with-temp-text "* [[link<point>]] :tag:"
  6777. (let ((org-tags-column 0))
  6778. (org-fix-tags-on-the-fly)
  6779. (insert "x")
  6780. (buffer-string)))))
  6781. ;; Aligning tags preserve position.
  6782. (should
  6783. (= 6 (org-test-with-temp-text "* 345 <point> :tag:"
  6784. (let ((org-tags-column 78)
  6785. (indent-tabs-mode nil))
  6786. (org-fix-tags-on-the-fly))
  6787. (current-column))))
  6788. ;; Aligning all tags in visible buffer.
  6789. (should
  6790. ;; 12345678901234567890
  6791. (equal (concat "* Level 1 :abc:\n"
  6792. "** Level 2 :def:")
  6793. (org-test-with-temp-text (concat "* Level 1 :abc:\n"
  6794. "** Level 2 :def:")
  6795. (let ((org-tags-column -20)
  6796. (indent-tabs-mode nil))
  6797. ;; (org-align-tags :all) must work even when the point
  6798. ;; is at the end of the buffer.
  6799. (goto-char (point-max))
  6800. (org-align-tags :all))
  6801. (buffer-string)))))
  6802. (ert-deftest test-org/get-tags ()
  6803. "Test `org-get-tags' specifications."
  6804. ;; Standard test.
  6805. (should
  6806. (equal '("foo")
  6807. (org-test-with-temp-text "* Test :foo:" (org-get-tags))))
  6808. (should
  6809. (equal '("foo" "bar")
  6810. (org-test-with-temp-text "* Test :foo:bar:" (org-get-tags))))
  6811. ;; Tags for inlinetasks.
  6812. (should
  6813. (equal '("foo" "bar")
  6814. (progn
  6815. (require 'org-inlinetask)
  6816. (org-test-with-temp-text (concat (make-string org-inlinetask-min-level ?*) " Test :foo:bar:")
  6817. (org-get-tags (org-element-at-point))))))
  6818. (should
  6819. (equal '("foo" "bar")
  6820. (progn
  6821. (require 'org-inlinetask)
  6822. (org-test-with-temp-text (concat (make-string org-inlinetask-min-level ?*) " Test :foo:bar:")
  6823. (org-get-tags nil)))))
  6824. ;; Return nil when there is no tag.
  6825. (should-not
  6826. (org-test-with-temp-text "* Test" (org-get-tags)))
  6827. ;; Tags are inherited from parent headlines.
  6828. (should
  6829. (equal '("tag")
  6830. (let ((org-use-tag-inheritance t))
  6831. (org-test-with-temp-text "* H0 :foo:\n* H1 :tag:\n<point>** H2"
  6832. (org-get-tags)))))
  6833. ;; Tags are inherited from `org-file-tags'.
  6834. (should
  6835. (equal '("tag")
  6836. (org-test-with-temp-text "* H1"
  6837. (let ((org-file-tags '("tag"))
  6838. (org-use-tag-inheritance t))
  6839. (org-get-tags)))))
  6840. ;; Only inherited tags have the `inherited' text property.
  6841. (should
  6842. (get-text-property 0 'inherited
  6843. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6844. (let ((org-use-tag-inheritance t))
  6845. (assoc-string "foo" (org-get-tags))))))
  6846. (should-not
  6847. (get-text-property 0 'inherited
  6848. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6849. (let ((org-use-tag-inheritance t))
  6850. (assoc-string "bar" (org-get-tags))))))
  6851. ;; Obey to `org-use-tag-inheritance'.
  6852. (should-not
  6853. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6854. (let ((org-use-tag-inheritance nil))
  6855. (assoc-string "foo" (org-get-tags)))))
  6856. (should-not
  6857. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6858. (let ((org-use-tag-inheritance nil)
  6859. (org-file-tags '("foo")))
  6860. (assoc-string "foo" (org-get-tags)))))
  6861. (should-not
  6862. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6863. (let ((org-use-tag-inheritance '("bar")))
  6864. (assoc-string "foo" (org-get-tags)))))
  6865. (should
  6866. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6867. (let ((org-use-tag-inheritance '("bar")))
  6868. (assoc-string "bar" (org-get-tags)))))
  6869. (should-not
  6870. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6871. (let ((org-use-tag-inheritance "b.*"))
  6872. (assoc-string "foo" (org-get-tags)))))
  6873. (should
  6874. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6875. (let ((org-use-tag-inheritance "b.*"))
  6876. (assoc-string "bar" (org-get-tags)))))
  6877. ;; When optional argument LOCAL is non-nil, ignore tag inheritance.
  6878. (should
  6879. (equal '("baz")
  6880. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6881. (let ((org-use-tag-inheritance t))
  6882. (org-get-tags nil t)))))
  6883. ;; When optional argument POS is non-nil, get tags there instead.
  6884. (should
  6885. (equal '("foo")
  6886. (org-test-with-temp-text "* H1 :foo:\n* <point>H2 :bar:"
  6887. (org-get-tags 1))))
  6888. ;; Make sure tags excluded from inheritance are returned if local
  6889. (should
  6890. (equal '("foo")
  6891. (org-test-with-temp-text "* Test :foo:"
  6892. (let ((org-use-tag-inheritance t)
  6893. (org-tags-exclude-from-inheritance '("foo")))
  6894. (org-get-tags)))))
  6895. ;; Test the collection of tags from #+filetags and parent tags.
  6896. (should
  6897. (equal '("a" "b" "c" "d")
  6898. (org-test-with-temp-text (concat "#+filetags: a\n"
  6899. "* Level 1 :b:\n"
  6900. "** Level 2 :c:\n"
  6901. "*** Level 3 :d:\n"
  6902. "<point>")
  6903. (let ((org-use-tag-inheritance t))
  6904. (org-mode-restart) ;So that `org-file-tags' get populated from #+filetags
  6905. (org-get-tags)))))
  6906. ;; Pathological case: tagged headline with an empty body.
  6907. (should (org-test-with-temp-text "* :tag:" (org-get-tags))))
  6908. (ert-deftest test-org/set-tags ()
  6909. "Test `org-set-tags' specifications."
  6910. ;; Throw an error on invalid data.
  6911. (should-error
  6912. (org-test-with-temp-text "* H"
  6913. (org-set-tags 'foo)))
  6914. ;; `nil', an empty, and a blank string remove all tags.
  6915. (should
  6916. (equal "* H"
  6917. (org-test-with-temp-text "* H :tag1:tag2:"
  6918. (org-set-tags nil)
  6919. (buffer-string))))
  6920. (should
  6921. (equal "* H"
  6922. (org-test-with-temp-text "* H :tag1:tag2:"
  6923. (org-set-tags "")
  6924. (buffer-string))))
  6925. (should
  6926. (equal "* H"
  6927. (org-test-with-temp-text "* H :tag1:tag2:"
  6928. (org-set-tags " ")
  6929. (buffer-string))))
  6930. ;; If there's nothing to remove, just bail out.
  6931. (should
  6932. (equal "* H"
  6933. (org-test-with-temp-text "* H"
  6934. (org-set-tags nil)
  6935. (buffer-string))))
  6936. (should
  6937. (equal "* "
  6938. (org-test-with-temp-text "* "
  6939. (org-set-tags nil)
  6940. (buffer-string))))
  6941. ;; If DATA is a tag string, set current tags to it, even if it means
  6942. ;; replacing old tags.
  6943. (should
  6944. (equal "* H :tag0:"
  6945. (org-test-with-temp-text "* H :tag1:tag2:"
  6946. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  6947. (buffer-string))))
  6948. (should
  6949. (equal "* H :tag0:"
  6950. (org-test-with-temp-text "* H"
  6951. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  6952. (buffer-string))))
  6953. ;; If DATA is a list, set tags to this list, even if it means
  6954. ;; replacing old tags.
  6955. (should
  6956. (equal "* H :tag0:"
  6957. (org-test-with-temp-text "* H :tag1:tag2:"
  6958. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6959. (buffer-string))))
  6960. (should
  6961. (equal "* H :tag0:"
  6962. (org-test-with-temp-text "* H"
  6963. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6964. (buffer-string))))
  6965. ;; When set, apply `org-tags-sort-function'.
  6966. (should
  6967. (equal "* H :a:b:"
  6968. (org-test-with-temp-text "* H"
  6969. (let ((org-tags-column 1)
  6970. (org-tags-sort-function #'string<))
  6971. (org-set-tags '("b" "a"))
  6972. (buffer-string)))))
  6973. ;; When new tags are identical to the previous ones, still align.
  6974. (should
  6975. (equal "* H :foo:"
  6976. (org-test-with-temp-text "* H :foo:"
  6977. (let ((org-tags-column 1))
  6978. (org-set-tags '("foo"))
  6979. (buffer-string)))))
  6980. ;; When tags have been changed, run `org-after-tags-change-hook'.
  6981. (should
  6982. (catch :return
  6983. (org-test-with-temp-text "* H :foo:"
  6984. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  6985. (org-set-tags '("bar"))
  6986. nil))))
  6987. (should-not
  6988. (catch :return
  6989. (org-test-with-temp-text "* H :foo:"
  6990. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  6991. (org-set-tags '("foo"))
  6992. nil))))
  6993. ;; Special case: handle empty headlines.
  6994. (should
  6995. (equal "* :tag0:"
  6996. (org-test-with-temp-text "* "
  6997. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6998. (buffer-string))))
  6999. ;; Modify buffer only when a tag change happens or alignment is
  7000. ;; done.
  7001. (should-not
  7002. (org-test-with-temp-text "* H :foo:"
  7003. (set-buffer-modified-p nil)
  7004. (let ((org-tags-column 1)) (org-set-tags '("foo")))
  7005. (buffer-modified-p)))
  7006. (should
  7007. (org-test-with-temp-text "* H :foo:"
  7008. (set-buffer-modified-p nil)
  7009. (let ((org-tags-column 10)) (org-set-tags '("foo")))
  7010. (buffer-modified-p)))
  7011. (should
  7012. (org-test-with-temp-text "* H :foo:"
  7013. (set-buffer-modified-p nil)
  7014. (let ((org-tags-column 10)) (org-set-tags '("bar")))
  7015. (buffer-modified-p)))
  7016. ;; Pathological case: when setting tags of a folded headline, do not
  7017. ;; let new tags being sucked into invisibility.
  7018. (should-not
  7019. (org-test-with-temp-text "* H1\nContent\n* H2\n\n Other Content"
  7020. ;; Show only headlines
  7021. (org-content)
  7022. ;; Set NEXT tag on current entry
  7023. (org-set-tags ":NEXT:")
  7024. ;; Move point to that NEXT tag
  7025. (search-forward "NEXT") (backward-word)
  7026. ;; And it should be visible (i.e. no overlays)
  7027. (overlays-at (point)))))
  7028. (ert-deftest test-org/set-tags-command ()
  7029. "Test `org-set-tags-command' specifications"
  7030. ;; Set tags at current headline.
  7031. (should
  7032. (equal "* H1 :foo:"
  7033. (org-test-with-temp-text "* H1"
  7034. (cl-letf (((symbol-function 'completing-read-multiple)
  7035. (lambda (&rest args) '("foo"))))
  7036. (let ((org-use-fast-tag-selection nil)
  7037. (org-tags-column 1))
  7038. (org-set-tags-command)))
  7039. (buffer-string))))
  7040. ;; Preserve position when called from the section below.
  7041. (should
  7042. (equal "* H1 :foo:\nContents"
  7043. (org-test-with-temp-text "* H1\n<point>Contents"
  7044. (cl-letf (((symbol-function 'completing-read-multiple)
  7045. (lambda (&rest args) '("foo"))))
  7046. (let ((org-use-fast-tag-selection nil)
  7047. (org-tags-column 1))
  7048. (org-set-tags-command)))
  7049. (buffer-string))))
  7050. (should-not
  7051. (equal "* H1 :foo:\nContents2"
  7052. (org-test-with-temp-text "* H1\n<point>Contents2"
  7053. (cl-letf (((symbol-function 'completing-read-multiple)
  7054. (lambda (&rest args) '("foo"))))
  7055. (let ((org-use-fast-tag-selection nil)
  7056. (org-tags-column 1))
  7057. (org-set-tags-command)))
  7058. (org-at-heading-p))))
  7059. ;; When a region is active and
  7060. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  7061. ;; same value in all headlines in region.
  7062. (should
  7063. (equal "* H1 :foo:\nContents\n* H2 :foo:"
  7064. (org-test-with-temp-text "* H1\nContents\n* H2"
  7065. (cl-letf (((symbol-function 'completing-read-multiple)
  7066. (lambda (&rest args) '("foo"))))
  7067. (let ((org-use-fast-tag-selection nil)
  7068. (org-loop-over-headlines-in-active-region t)
  7069. (org-tags-column 1))
  7070. (transient-mark-mode 1)
  7071. (push-mark (point) t t)
  7072. (goto-char (point-max))
  7073. (org-set-tags-command)))
  7074. (buffer-string))))
  7075. (should
  7076. (equal "* H1\nContents\n* H2 :foo:"
  7077. (org-test-with-temp-text "* H1\nContents\n* H2"
  7078. (cl-letf (((symbol-function 'completing-read-multiple)
  7079. (lambda (&rest args) '("foo"))))
  7080. (let ((org-use-fast-tag-selection nil)
  7081. (org-loop-over-headlines-in-active-region nil)
  7082. (org-tags-column 1))
  7083. (transient-mark-mode 1)
  7084. (push-mark (point) t t)
  7085. (goto-char (point-max))
  7086. (org-set-tags-command)))
  7087. (buffer-string))))
  7088. ;; With a C-u prefix argument, align all tags in the buffer.
  7089. (should
  7090. (equal "* H1 :foo:\n* H2 :bar:"
  7091. (org-test-with-temp-text "* H1 :foo:\n* H2 :bar:"
  7092. (let ((org-tags-column 1)) (org-set-tags-command '(4)))
  7093. (buffer-string))))
  7094. ;; Point does not move with empty headline.
  7095. (should
  7096. (equal ":foo:"
  7097. (org-test-with-temp-text "* <point>"
  7098. (cl-letf (((symbol-function 'completing-read-multiple)
  7099. (lambda (&rest args) '("foo"))))
  7100. (let ((org-use-fast-tag-selection nil)
  7101. (org-tags-column 1))
  7102. (org-set-tags-command)))
  7103. (buffer-substring (point) (line-end-position)))))
  7104. ;; Point does not move at start of line.
  7105. (should
  7106. (equal "* H1 :foo:"
  7107. (org-test-with-temp-text "* H1"
  7108. (cl-letf (((symbol-function 'completing-read-multiple)
  7109. (lambda (&rest args) '("foo"))))
  7110. (let ((org-use-fast-tag-selection nil)
  7111. (org-tags-column 1))
  7112. (org-set-tags-command)))
  7113. (buffer-substring (point) (line-end-position)))))
  7114. ;; Point does not move when within *'s.
  7115. (should
  7116. (equal "* H1 :foo:"
  7117. (org-test-with-temp-text "*<point>* H1"
  7118. (cl-letf (((symbol-function 'completing-read-multiple)
  7119. (lambda (&rest args) '("foo"))))
  7120. (let ((org-use-fast-tag-selection nil)
  7121. (org-tags-column 1))
  7122. (org-set-tags-command)))
  7123. (buffer-substring (point) (line-end-position)))))
  7124. ;; Point workaround does not get fooled when looking at a space.
  7125. (should
  7126. (equal " b :foo:"
  7127. (org-test-with-temp-text "* a<point> b"
  7128. (cl-letf (((symbol-function 'completing-read-multiple)
  7129. (lambda (&rest args) '("foo"))))
  7130. (let ((org-use-fast-tag-selection nil)
  7131. (org-tags-column 1))
  7132. (org-set-tags-command)))
  7133. (buffer-substring (point) (line-end-position)))))
  7134. ;; Handle tags both set locally and inherited.
  7135. (should
  7136. (equal "b :foo:"
  7137. (org-test-with-temp-text "* a :foo:\n** <point>b :foo:"
  7138. (cl-letf (((symbol-function 'completing-read-multiple)
  7139. (lambda (prompt coll &optional pred req initial &rest args)
  7140. (list initial))))
  7141. (let ((org-use-fast-tag-selection nil)
  7142. (org-tags-column 1))
  7143. (org-set-tags-command)))
  7144. (buffer-substring (point) (line-end-position))))))
  7145. (ert-deftest test-org/toggle-tag ()
  7146. "Test `org-toggle-tag' specifications."
  7147. ;; Insert missing tag.
  7148. (should
  7149. (equal "* H :tag:"
  7150. (org-test-with-temp-text "* H"
  7151. (let ((org-tags-column 1)) (org-toggle-tag "tag"))
  7152. (buffer-string))))
  7153. (should
  7154. (equal "* H :tag1:tag2:"
  7155. (org-test-with-temp-text "* H :tag1:"
  7156. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  7157. (buffer-string))))
  7158. ;; Remove existing tag.
  7159. (should
  7160. (equal "* H"
  7161. (org-test-with-temp-text "* H :tag:"
  7162. (org-toggle-tag "tag")
  7163. (buffer-string))))
  7164. (should
  7165. (equal "* H :tag1:"
  7166. (org-test-with-temp-text "* H :tag1:tag2:"
  7167. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  7168. (buffer-string))))
  7169. (should
  7170. (equal "* H :tag2:"
  7171. (org-test-with-temp-text "* H :tag1:tag2:"
  7172. (let ((org-tags-column 1)) (org-toggle-tag "tag1"))
  7173. (buffer-string))))
  7174. ;; With optional argument ONOFF set to `on', try to insert the tag,
  7175. ;; even if its already there.
  7176. (should
  7177. (equal "* H :tag:"
  7178. (org-test-with-temp-text "* H"
  7179. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  7180. (buffer-string))))
  7181. (should
  7182. (equal "* H :tag:"
  7183. (org-test-with-temp-text "* H :tag:"
  7184. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  7185. (buffer-string))))
  7186. ;; With optional argument ONOFF set to `off', try to remove the tag,
  7187. ;; even if its not there.
  7188. (should
  7189. (equal "* H"
  7190. (org-test-with-temp-text "* H :tag:"
  7191. (org-toggle-tag "tag" 'off)
  7192. (buffer-string))))
  7193. (should
  7194. (equal "* H :tag:"
  7195. (org-test-with-temp-text "* H :tag:"
  7196. (let ((org-tags-column 1)) (org-toggle-tag "foo" 'off))
  7197. (buffer-string))))
  7198. ;; Special case: Handle properly tag inheritance. In particular, do
  7199. ;; not set inherited tags.
  7200. (should
  7201. (equal "* H1 :tag:\n** H2 :tag2:tag:"
  7202. (org-test-with-temp-text "* H1 :tag:\n** <point>H2 :tag2:"
  7203. (let ((org-use-tag-inheritance t)
  7204. (org-tags-column 1))
  7205. (org-toggle-tag "tag"))
  7206. (buffer-string))))
  7207. (should
  7208. (equal "* H1 :tag1:tag2:\n** H2 :foo:"
  7209. (org-test-with-temp-text "* H1 :tag1:tag2:\n** <point>H2"
  7210. (let ((org-use-tag-inheritance t)
  7211. (org-tags-column 1))
  7212. (org-toggle-tag "foo"))
  7213. (buffer-string)))))
  7214. (ert-deftest test-org/tags-expand ()
  7215. "Test `org-tags-expand' specifications."
  7216. ;; Expand tag groups as a regexp enclosed within curly brackets.
  7217. (should
  7218. (equal "{\\<[ABC]\\>}"
  7219. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7220. (org-mode-restart)
  7221. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  7222. (should
  7223. (equal "{\\<\\(?:Aa\\|Bb\\|Cc\\)\\>}"
  7224. (org-test-with-temp-text "#+TAGS: [ Aa : Bb Cc ]"
  7225. (org-mode-restart)
  7226. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "Aa")))))
  7227. ;; Preserve operator before the regexp.
  7228. (should
  7229. (equal "+{\\<[ABC]\\>}"
  7230. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7231. (org-mode-restart)
  7232. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "+A")))))
  7233. (should
  7234. (equal "-{\\<[ABC]\\>}"
  7235. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7236. (org-mode-restart)
  7237. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "-A")))))
  7238. ;; Handle "|" syntax.
  7239. (should
  7240. (equal "{\\<[ABC]\\>}|D"
  7241. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7242. (org-mode-restart)
  7243. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|D")))))
  7244. ;; Handle nested groups.
  7245. (should
  7246. (equal "{\\<[A-D]\\>}"
  7247. (org-test-with-temp-text "#+TAGS: [ A : B C ]\n#+TAGS: [ B : D ]"
  7248. (org-mode-restart)
  7249. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  7250. ;; Expand multiple occurrences of the same group.
  7251. (should
  7252. (equal "{\\<[ABC]\\>}|{\\<[ABC]\\>}"
  7253. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7254. (org-mode-restart)
  7255. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|A")))))
  7256. ;; Preserve regexp matches.
  7257. (should
  7258. (equal "{A+}"
  7259. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7260. (org-mode-restart)
  7261. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "{A+}"))))))
  7262. ;;; TODO keywords
  7263. (ert-deftest test-org/auto-repeat-maybe ()
  7264. "Test `org-auto-repeat-maybe' specifications."
  7265. ;; Do not auto repeat when there is no valid time stamp with
  7266. ;; a repeater in the entry.
  7267. (should-not
  7268. (string-prefix-p
  7269. "* TODO H"
  7270. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7271. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
  7272. (org-todo "DONE")
  7273. (buffer-string)))))
  7274. (should-not
  7275. (string-prefix-p
  7276. "* TODO H"
  7277. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7278. (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
  7279. (org-todo "DONE")
  7280. (buffer-string)))))
  7281. ;; When switching to DONE state, switch back to first TODO keyword
  7282. ;; in sequence, or the same keyword if they have different types.
  7283. (should
  7284. (string-prefix-p
  7285. "* TODO H"
  7286. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7287. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7288. (org-todo "DONE")
  7289. (buffer-string)))))
  7290. (should
  7291. (string-prefix-p
  7292. "* KWD1 H"
  7293. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  7294. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  7295. (org-todo "DONE")
  7296. (buffer-string)))))
  7297. (should
  7298. (string-prefix-p
  7299. "* KWD2 H"
  7300. (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
  7301. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  7302. (org-todo "DONE")
  7303. (buffer-string)))))
  7304. ;; If there was no TODO keyword in the first place, do not insert
  7305. ;; any either.
  7306. (should
  7307. (string-prefix-p
  7308. "* H"
  7309. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7310. (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
  7311. (org-todo "DONE")
  7312. (buffer-string)))))
  7313. ;; Revert to REPEAT_TO_STATE, if set.
  7314. (should
  7315. (string-prefix-p
  7316. "* KWD2 H"
  7317. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  7318. (org-test-with-temp-text
  7319. "* KWD2 H
  7320. :PROPERTIES:
  7321. :REPEAT_TO_STATE: KWD2
  7322. :END:
  7323. <2012-03-29 Thu +2y>"
  7324. (org-todo "DONE")
  7325. (buffer-string)))))
  7326. ;; When switching to DONE state, update base date. If there are
  7327. ;; multiple repeated time stamps, update them all.
  7328. (should
  7329. (string-match-p
  7330. "<2014-03-29 .* \\+2y>"
  7331. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7332. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7333. (org-todo "DONE")
  7334. (buffer-string)))))
  7335. (should
  7336. (string-match-p
  7337. "<2015-03-04 .* \\+1y>"
  7338. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7339. (org-test-with-temp-text
  7340. "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
  7341. (org-todo "DONE")
  7342. (buffer-string)))))
  7343. ;; Throw an error if repeater unit is the hour and no time is
  7344. ;; provided in the time-stamp.
  7345. (should-error
  7346. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7347. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
  7348. (org-todo "DONE")
  7349. (buffer-string))))
  7350. ;; Handle every repeater type using hours step.
  7351. (should
  7352. (string-match-p
  7353. "2014-03-04 .* 02:00"
  7354. (org-test-at-time "<2014-03-04 02:35>"
  7355. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 +8h>"
  7356. (org-todo "DONE")
  7357. (buffer-string)))))
  7358. (should
  7359. (string-match-p
  7360. "2014-03-04 .* 10:00"
  7361. (org-test-at-time "<2014-03-04 02:35>"
  7362. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 ++8h>"
  7363. (org-todo "DONE")
  7364. (buffer-string)))))
  7365. (should
  7366. (string-match-p
  7367. "2014-03-04 .* 10:35"
  7368. (org-test-at-time "<2014-03-04 02:35>"
  7369. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 .+8h>"
  7370. (org-todo "DONE")
  7371. (buffer-string)))))
  7372. ;; Do not repeat inactive time stamps with a repeater.
  7373. (should-not
  7374. (string-match-p
  7375. "\\[2014-03-29 .* \\+2y\\]"
  7376. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7377. (org-test-with-temp-text
  7378. "* TODO H\n[2012-03-29 Thu. +2y]"
  7379. (org-todo "DONE")
  7380. (buffer-string)))))
  7381. ;; Do not repeat commented time stamps.
  7382. (should-not
  7383. (string-prefix-p
  7384. "<2015-03-04 .* \\+1y>"
  7385. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7386. (org-test-with-temp-text
  7387. "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
  7388. (org-todo "DONE")
  7389. (buffer-string)))))
  7390. (should-not
  7391. (string-prefix-p
  7392. "<2015-03-04 .* \\+1y>"
  7393. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7394. (org-test-with-temp-text
  7395. "* TODO H
  7396. <2012-03-29 Thu. +2y>
  7397. #+BEGIN_EXAMPLE
  7398. <2014-03-04 Tue +1y>
  7399. #+END_EXAMPLE"
  7400. (org-todo "DONE")
  7401. (buffer-string)))))
  7402. ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
  7403. ;; entry, record time of last repeat.
  7404. (should-not
  7405. (string-match-p
  7406. ":LAST_REPEAT:"
  7407. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  7408. (org-log-repeat nil))
  7409. (cl-letf (((symbol-function 'org-add-log-setup)
  7410. (lambda (&rest args) nil)))
  7411. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  7412. (org-todo "DONE")
  7413. (buffer-string))))))
  7414. (should
  7415. (string-match-p
  7416. ":LAST_REPEAT:"
  7417. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  7418. (org-log-repeat t))
  7419. (cl-letf (((symbol-function 'org-add-log-setup)
  7420. (lambda (&rest args) nil)))
  7421. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  7422. (org-todo "DONE")
  7423. (buffer-string))))))
  7424. (should
  7425. (string-match-p
  7426. ":LAST_REPEAT:"
  7427. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7428. (cl-letf (((symbol-function 'org-add-log-setup)
  7429. (lambda (&rest args) nil)))
  7430. (org-test-with-temp-text
  7431. "* TODO H\n<2012-03-29 Thu +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
  7432. (org-todo "DONE")
  7433. (buffer-string))))))
  7434. ;; When a SCHEDULED entry has no repeater, remove it upon repeating
  7435. ;; the entry as it is no longer relevant.
  7436. (should-not
  7437. (string-match-p
  7438. "^SCHEDULED:"
  7439. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7440. (org-test-with-temp-text
  7441. "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
  7442. (org-todo "DONE")
  7443. (buffer-string)))))
  7444. ;; Properly advance repeater even when a clock entry is specified
  7445. ;; and `org-log-repeat' is nil.
  7446. (should
  7447. (string-match-p
  7448. "SCHEDULED: <2014-03-29"
  7449. (let ((org-log-repeat nil)
  7450. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7451. (org-test-with-temp-text
  7452. "* TODO H
  7453. SCHEDULED: <2012-03-29 Thu +2y>
  7454. CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] => 6:40"
  7455. (org-todo "DONE")
  7456. (buffer-string)))))
  7457. ;; Make sure that logbook state change record does not get
  7458. ;; duplicated when `org-log-repeat' `org-log-done' are non-nil.
  7459. (should
  7460. (string-match-p
  7461. (rx "* TODO Read book
  7462. SCHEDULED: <2021-06-16 " (1+ (not space)) " +1d>
  7463. :PROPERTIES:
  7464. :LAST_REPEAT:" (1+ nonl) "
  7465. :END:
  7466. - State \"DONE\" from \"TODO\"" (1+ nonl) buffer-end)
  7467. (let ((org-log-repeat 'time)
  7468. (org-todo-keywords '((sequence "TODO" "|" "DONE(d!)")))
  7469. (org-log-into-drawer nil))
  7470. (org-test-with-temp-text
  7471. "* TODO Read book
  7472. SCHEDULED: <2021-06-15 Tue +1d>"
  7473. (org-todo "DONE")
  7474. (when (memq 'org-add-log-note post-command-hook)
  7475. (org-add-log-note))
  7476. (buffer-string))))))
  7477. (ert-deftest test-org/org-log-done ()
  7478. "Test `org-log-done' specifications."
  7479. ;; nil value.
  7480. (should
  7481. (string=
  7482. "* DONE task"
  7483. (let ((org-log-done nil)
  7484. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7485. (org-test-with-temp-text
  7486. "* TODO task"
  7487. (org-todo "DONE")
  7488. (when (memq 'org-add-log-note post-command-hook)
  7489. (org-add-log-note))
  7490. (buffer-string)))))
  7491. ;; `time' value.
  7492. (should
  7493. (string=
  7494. (format
  7495. "* DONE task
  7496. CLOSED: %s"
  7497. (org-test-with-temp-text ""
  7498. (org-insert-time-stamp (current-time) t t)
  7499. (buffer-string)))
  7500. (let ((org-log-done 'time)
  7501. (org-log-done-with-time t)
  7502. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7503. (org-test-with-temp-text
  7504. "* TODO task"
  7505. (org-todo "DONE")
  7506. (when (memq 'org-add-log-note post-command-hook)
  7507. (org-add-log-note))
  7508. (buffer-string)))))
  7509. (should
  7510. (string=
  7511. (format
  7512. "* DONE task
  7513. CLOSED: %s"
  7514. (org-test-with-temp-text ""
  7515. (org-insert-time-stamp (current-time) nil t)
  7516. (buffer-string)))
  7517. (let ((org-log-done 'time)
  7518. (org-log-done-with-time nil)
  7519. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7520. (org-test-with-temp-text
  7521. "* TODO task"
  7522. (org-todo "DONE")
  7523. (when (memq 'org-add-log-note post-command-hook)
  7524. (org-add-log-note))
  7525. (buffer-string)))))
  7526. ;; TODO: Test `note' value.
  7527. ;; Test startup overrides.
  7528. (should
  7529. (string=
  7530. "#+STARTUP: nologdone
  7531. * DONE task"
  7532. (let ((org-log-done 'time)
  7533. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7534. (org-test-with-temp-text
  7535. "#+STARTUP: nologdone
  7536. <point>* TODO task"
  7537. (org-set-regexps-and-options)
  7538. (org-todo "DONE")
  7539. (when (memq 'org-add-log-note post-command-hook)
  7540. (org-add-log-note))
  7541. (buffer-string)))))
  7542. (should
  7543. (string=
  7544. (format
  7545. "#+STARTUP: logdone
  7546. * DONE task
  7547. CLOSED: %s"
  7548. (org-test-with-temp-text ""
  7549. (org-insert-time-stamp (current-time) t t)
  7550. (buffer-string)))
  7551. (let ((org-log-done nil)
  7552. (org-log-done-with-time t)
  7553. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7554. (org-test-with-temp-text
  7555. "#+STARTUP: logdone
  7556. <point>* TODO task"
  7557. (org-set-regexps-and-options)
  7558. (org-todo "DONE")
  7559. (when (memq 'org-add-log-note post-command-hook)
  7560. (org-add-log-note))
  7561. (buffer-string)))))
  7562. ;; Test local property overrides.
  7563. (should
  7564. (string=
  7565. "* DONE task
  7566. :PROPERTIES:
  7567. :LOGGING: nil
  7568. :END:"
  7569. (let ((org-log-done 'time)
  7570. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7571. (org-test-with-temp-text
  7572. "* TODO task
  7573. :PROPERTIES:
  7574. :LOGGING: nil
  7575. :END:"
  7576. (org-todo "DONE")
  7577. (when (memq 'org-add-log-note post-command-hook)
  7578. (org-add-log-note))
  7579. (buffer-string)))))
  7580. (should
  7581. (string=
  7582. (format
  7583. "* DONE task
  7584. CLOSED: %s
  7585. :PROPERTIES:
  7586. :LOGGING: logdone
  7587. :END:"
  7588. (org-test-with-temp-text ""
  7589. (org-insert-time-stamp (current-time) t t)
  7590. (buffer-string)))
  7591. (let ((org-log-done nil)
  7592. (org-log-done-with-time t)
  7593. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7594. (org-test-with-temp-text
  7595. "* TODO task
  7596. :PROPERTIES:
  7597. :LOGGING: logdone
  7598. :END:"
  7599. (org-todo "DONE")
  7600. (when (memq 'org-add-log-note post-command-hook)
  7601. (org-add-log-note))
  7602. (buffer-string))))))
  7603. (ert-deftest test-org/org-todo-prefix ()
  7604. "Test `org-todo' prefix arg behavior."
  7605. ;; FIXME: Add tests for all other allowed prefix arguments.
  7606. ;; -1 prefix arg should cancel repeater and mark DONE.
  7607. (should
  7608. (string-match-p
  7609. "DONE H\\(.*\n\\)*<2012-03-29 Thu \\+0y>"
  7610. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7611. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7612. (org-todo -1)
  7613. (buffer-string)))))
  7614. ;; - prefix arg should cancel repeater and mark DONE.
  7615. (should
  7616. (string-match-p
  7617. "DONE H\\(.*\n\\)*<2012-03-29 Thu \\+0y>"
  7618. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7619. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7620. (org-todo '-)
  7621. (buffer-string))))))
  7622. ;;; Timestamps API
  7623. (ert-deftest test-org/at-timestamp-p ()
  7624. "Test `org-at-timestamp-p' specifications."
  7625. (should
  7626. (org-test-with-temp-text "<2012-03-29 Thu>"
  7627. (org-at-timestamp-p)))
  7628. (should-not
  7629. (org-test-with-temp-text "2012-03-29 Thu"
  7630. (org-at-timestamp-p)))
  7631. ;; Test return values.
  7632. (should
  7633. (eq 'bracket
  7634. (org-test-with-temp-text "<2012-03-29 Thu>"
  7635. (org-at-timestamp-p))))
  7636. (should
  7637. (eq 'year
  7638. (org-test-with-temp-text "<<point>2012-03-29 Thu>"
  7639. (org-at-timestamp-p))))
  7640. (should
  7641. (eq 'month
  7642. (org-test-with-temp-text "<2012-<point>03-29 Thu>"
  7643. (org-at-timestamp-p))))
  7644. (should
  7645. (eq 'day
  7646. (org-test-with-temp-text "<2012-03-<point>29 Thu>"
  7647. (org-at-timestamp-p))))
  7648. (should
  7649. (eq 'day
  7650. (org-test-with-temp-text "<2012-03-29 T<point>hu>"
  7651. (org-at-timestamp-p))))
  7652. (should
  7653. (wholenump
  7654. (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
  7655. (org-at-timestamp-p))))
  7656. (should
  7657. (eq 'bracket
  7658. (org-test-with-temp-text "<2012-03-29 Thu<point>>"
  7659. (org-at-timestamp-p))))
  7660. (should
  7661. (eq 'after
  7662. (org-test-with-temp-text "<2012-03-29 Thu><point>»"
  7663. (org-at-timestamp-p))))
  7664. ;; Test `inactive' optional argument.
  7665. (should
  7666. (org-test-with-temp-text "[2012-03-29 Thu]"
  7667. (org-at-timestamp-p 'inactive)))
  7668. (should-not
  7669. (org-test-with-temp-text "[2012-03-29 Thu]"
  7670. (org-at-timestamp-p)))
  7671. ;; When optional argument is `agenda', recognize time-stamps in
  7672. ;; planning info line, property drawers and clocks.
  7673. (should
  7674. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7675. (org-at-timestamp-p 'agenda)))
  7676. (should-not
  7677. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7678. (org-at-timestamp-p)))
  7679. (should
  7680. (org-test-with-temp-text
  7681. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7682. (org-at-timestamp-p 'agenda)))
  7683. (should-not
  7684. (org-test-with-temp-text
  7685. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7686. (org-at-timestamp-p)))
  7687. (should
  7688. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7689. (let ((org-agenda-include-inactive-timestamps t))
  7690. (org-at-timestamp-p 'agenda))))
  7691. (should-not
  7692. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7693. (let ((org-agenda-include-inactive-timestamps t))
  7694. (org-at-timestamp-p))))
  7695. (should-not
  7696. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7697. (let ((org-agenda-include-inactive-timestamps t))
  7698. (org-at-timestamp-p 'inactive))))
  7699. ;; When optional argument is `lax', match any part of the document
  7700. ;; with Org timestamp syntax.
  7701. (should
  7702. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7703. (org-at-timestamp-p 'lax)))
  7704. (should-not
  7705. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7706. (org-at-timestamp-p)))
  7707. (should
  7708. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7709. (org-at-timestamp-p 'lax)))
  7710. (should-not
  7711. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7712. (org-at-timestamp-p)))
  7713. (should
  7714. (org-test-with-temp-text
  7715. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7716. (org-at-timestamp-p 'lax)))
  7717. (should-not
  7718. (org-test-with-temp-text
  7719. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7720. (org-at-timestamp-p)))
  7721. ;; Optional argument `lax' also matches inactive timestamps.
  7722. (should
  7723. (org-test-with-temp-text "# [2012-03-29 Thu]<point>"
  7724. (org-at-timestamp-p 'lax))))
  7725. (ert-deftest test-org/time-stamp ()
  7726. "Test `org-time-stamp' specifications."
  7727. ;; Insert chosen time stamp at point.
  7728. (should
  7729. (string-match
  7730. "Te<2014-03-04 .*?>xt"
  7731. (org-test-with-temp-text "Te<point>xt"
  7732. (cl-letf (((symbol-function 'org-read-date)
  7733. (lambda (&rest args)
  7734. (org-time-string-to-time "2014-03-04"))))
  7735. (org-time-stamp nil)
  7736. (buffer-string)))))
  7737. ;; With a prefix argument, also insert time.
  7738. (should
  7739. (string-match
  7740. "Te<2014-03-04 .*? 00:41>xt"
  7741. (org-test-with-temp-text "Te<point>xt"
  7742. (cl-letf (((symbol-function 'org-read-date)
  7743. (lambda (&rest args)
  7744. (org-time-string-to-time "2014-03-04 00:41"))))
  7745. (org-time-stamp '(4))
  7746. (buffer-string)))))
  7747. ;; With two universal prefix arguments, insert an active timestamp
  7748. ;; with the current time without prompting the user.
  7749. (should
  7750. (string-match
  7751. "Te<2014-03-04 .*? 00:41>xt"
  7752. (org-test-with-temp-text "Te<point>xt"
  7753. (org-test-at-time "2014-03-04 00:41"
  7754. (org-time-stamp '(16))
  7755. (buffer-string)))))
  7756. ;; When optional argument is non-nil, insert an inactive timestamp.
  7757. (should
  7758. (string-match
  7759. "Te\\[2014-03-04 .*?\\]xt"
  7760. (org-test-with-temp-text "Te<point>xt"
  7761. (cl-letf (((symbol-function 'org-read-date)
  7762. (lambda (&rest args)
  7763. (org-time-string-to-time "2014-03-04"))))
  7764. (org-time-stamp nil t)
  7765. (buffer-string)))))
  7766. ;; When called from a timestamp, replace existing one.
  7767. (should
  7768. (string-match
  7769. "<2014-03-04 .*?>"
  7770. (org-test-with-temp-text "<2012-03-29<point> thu.>"
  7771. (cl-letf (((symbol-function 'org-read-date)
  7772. (lambda (&rest args)
  7773. (org-time-string-to-time "2014-03-04"))))
  7774. (org-time-stamp nil)
  7775. (buffer-string)))))
  7776. (should
  7777. (string-match
  7778. "<2014-03-04 .*?>--<2014-03-04 .*?>"
  7779. (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
  7780. (cl-letf (((symbol-function 'org-read-date)
  7781. (lambda (&rest args)
  7782. (org-time-string-to-time "2014-03-04"))))
  7783. (org-time-stamp nil)
  7784. (buffer-string)))))
  7785. ;; When replacing a timestamp, preserve repeater, if any.
  7786. (should
  7787. (string-match
  7788. "<2014-03-04 .*? \\+2y>"
  7789. (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
  7790. (cl-letf (((symbol-function 'org-read-date)
  7791. (lambda (&rest args)
  7792. (org-time-string-to-time "2014-03-04"))))
  7793. (org-time-stamp nil)
  7794. (buffer-string)))))
  7795. ;; When called twice in a raw, build a date range.
  7796. (should
  7797. (string-match
  7798. "<2012-03-29 .*?>--<2014-03-04 .*?>"
  7799. (org-test-with-temp-text "<2012-03-29 thu.><point>"
  7800. (cl-letf (((symbol-function 'org-read-date)
  7801. (lambda (&rest args)
  7802. (org-time-string-to-time "2014-03-04"))))
  7803. (let ((last-command 'org-time-stamp)
  7804. (this-command 'org-time-stamp))
  7805. (org-time-stamp nil))
  7806. (buffer-string))))))
  7807. (ert-deftest test-org/timestamp-has-time-p ()
  7808. "Test `org-timestamp-has-time-p' specifications."
  7809. ;; With time.
  7810. (should
  7811. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7812. (org-timestamp-has-time-p (org-element-context))))
  7813. ;; Without time.
  7814. (should-not
  7815. (org-test-with-temp-text "<2012-03-29 Thu>"
  7816. (org-timestamp-has-time-p (org-element-context)))))
  7817. (ert-deftest test-org/get-repeat ()
  7818. "Test `org-get-repeat' specifications."
  7819. (should
  7820. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
  7821. (org-get-repeat)))
  7822. (should-not
  7823. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
  7824. (org-get-repeat)))
  7825. ;; Return proper repeat string.
  7826. (should
  7827. (equal "+2y"
  7828. (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
  7829. (org-get-repeat))))
  7830. ;; Prevent false positive (commented or verbatim time stamps)
  7831. (should-not
  7832. (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
  7833. (org-get-repeat)))
  7834. (should-not
  7835. (org-test-with-temp-text
  7836. "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
  7837. (org-get-repeat)))
  7838. ;; Return nil when called before first heading.
  7839. (should-not
  7840. (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
  7841. (org-get-repeat)))
  7842. ;; When called with an optional argument, extract repeater from that
  7843. ;; string instead.
  7844. (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
  7845. (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
  7846. (ert-deftest test-org/timestamp-format ()
  7847. "Test `org-timestamp-format' specifications."
  7848. ;; Regular test.
  7849. (should
  7850. (equal
  7851. "2012-03-29 16:40"
  7852. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7853. (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
  7854. ;; Range end.
  7855. (should
  7856. (equal
  7857. "2012-03-29"
  7858. (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
  7859. (org-timestamp-format (org-element-context) "%Y-%m-%d" t)))))
  7860. (ert-deftest test-org/timestamp-split-range ()
  7861. "Test `org-timestamp-split-range' specifications."
  7862. ;; Extract range start (active).
  7863. (should
  7864. (equal '(2012 3 29)
  7865. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7866. (let ((ts (org-timestamp-split-range (org-element-context))))
  7867. (mapcar (lambda (p) (org-element-property p ts))
  7868. '(:year-end :month-end :day-end))))))
  7869. ;; Extract range start (inactive)
  7870. (should
  7871. (equal '(2012 3 29)
  7872. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7873. (let ((ts (org-timestamp-split-range (org-element-context))))
  7874. (mapcar (lambda (p) (org-element-property p ts))
  7875. '(:year-end :month-end :day-end))))))
  7876. ;; Extract range end (active).
  7877. (should
  7878. (equal '(2012 3 30)
  7879. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7880. (let ((ts (org-timestamp-split-range
  7881. (org-element-context) t)))
  7882. (mapcar (lambda (p) (org-element-property p ts))
  7883. '(:year-end :month-end :day-end))))))
  7884. ;; Extract range end (inactive)
  7885. (should
  7886. (equal '(2012 3 30)
  7887. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7888. (let ((ts (org-timestamp-split-range
  7889. (org-element-context) t)))
  7890. (mapcar (lambda (p) (org-element-property p ts))
  7891. '(:year-end :month-end :day-end))))))
  7892. ;; Return the timestamp if not a range.
  7893. (should
  7894. (org-test-with-temp-text "[2012-03-29 Thu]"
  7895. (let* ((ts-orig (org-element-context))
  7896. (ts-copy (org-timestamp-split-range ts-orig)))
  7897. (eq ts-orig ts-copy))))
  7898. (should
  7899. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7900. (let* ((ts-orig (org-element-context))
  7901. (ts-copy (org-timestamp-split-range ts-orig)))
  7902. (eq ts-orig ts-copy)))))
  7903. (ert-deftest test-org/timestamp-translate ()
  7904. "Test `org-timestamp-translate' specifications."
  7905. ;; Translate whole date range.
  7906. (should
  7907. (equal "<29>--<30>"
  7908. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7909. (let ((org-display-custom-times t)
  7910. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7911. (org-timestamp-translate (org-element-context))))))
  7912. ;; Translate date range start.
  7913. (should
  7914. (equal "<29>"
  7915. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7916. (let ((org-display-custom-times t)
  7917. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7918. (org-timestamp-translate (org-element-context) 'start)))))
  7919. ;; Translate date range end.
  7920. (should
  7921. (equal "<30>"
  7922. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7923. (let ((org-display-custom-times t)
  7924. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7925. (org-timestamp-translate (org-element-context) 'end)))))
  7926. ;; Translate time range.
  7927. (should
  7928. (equal "<08>--<16>"
  7929. (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
  7930. (let ((org-display-custom-times t)
  7931. (org-time-stamp-custom-formats '("<%d>" . "<%H>")))
  7932. (org-timestamp-translate (org-element-context))))))
  7933. ;; Translate non-range timestamp.
  7934. (should
  7935. (equal "<29>"
  7936. (org-test-with-temp-text "<2012-03-29 Thu>"
  7937. (let ((org-display-custom-times t)
  7938. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7939. (org-timestamp-translate (org-element-context))))))
  7940. ;; Do not change `diary' timestamps.
  7941. (should
  7942. (equal "<%%(org-float t 4 2)>"
  7943. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7944. (let ((org-display-custom-times t)
  7945. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7946. (org-timestamp-translate (org-element-context)))))))
  7947. (ert-deftest test-org/timestamp-from-string ()
  7948. "Test `org-timestamp-from-string' specifications."
  7949. ;; Return nil if argument is not a valid Org timestamp.
  7950. (should-not (org-timestamp-from-string ""))
  7951. (should-not (org-timestamp-from-string nil))
  7952. (should-not (org-timestamp-from-string "<2012-03-29"))
  7953. ;; Otherwise, return a valid Org timestamp object.
  7954. (should
  7955. (string-match-p "<2012-03-29 .+>"
  7956. (org-element-interpret-data
  7957. (org-timestamp-from-string "<2012-03-29 Thu>"))))
  7958. (should
  7959. (string-match-p "[2014-03-04 .+]"
  7960. (org-element-interpret-data
  7961. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  7962. (ert-deftest test-org/timestamp-from-time ()
  7963. "Test `org-timestamp-from-time' specifications."
  7964. ;; Standard test.
  7965. (should
  7966. (string-match-p
  7967. "<2012-03-29 .+>"
  7968. (org-element-interpret-data
  7969. (org-timestamp-from-time
  7970. (org-time-string-to-time "<2012-03-29 Thu 16:40>")))))
  7971. ;; When optional argument WITH-TIME is non-nil, provide time
  7972. ;; information.
  7973. (should
  7974. (string-match-p
  7975. "<2012-03-29 .+ 16:40>"
  7976. (org-element-interpret-data
  7977. (org-timestamp-from-time
  7978. (org-time-string-to-time "<2012-03-29 Thu 16:40>")
  7979. t))))
  7980. ;; When optional argument INACTIVE is non-nil, return an inactive
  7981. ;; timestamp.
  7982. (should
  7983. (string-match-p
  7984. "[2012-03-29 .+]"
  7985. (org-element-interpret-data
  7986. (org-timestamp-from-time
  7987. (org-time-string-to-time "<2012-03-29 Thu 16:40>")
  7988. nil t)))))
  7989. (ert-deftest test-org/timestamp-to-time ()
  7990. "Test `org-timestamp-to-time' specifications."
  7991. (should
  7992. (equal "2014-03-04"
  7993. (format-time-string
  7994. "%Y-%m-%d"
  7995. (org-timestamp-to-time
  7996. (org-timestamp-from-string "<2014-03-04 Tue>")))))
  7997. (should
  7998. (equal "2014-03-04"
  7999. (format-time-string
  8000. "%Y-%m-%d"
  8001. (org-timestamp-to-time
  8002. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  8003. (should
  8004. (equal "2012-03-29 08:30"
  8005. (format-time-string
  8006. "%Y-%m-%d %H:%M"
  8007. (org-timestamp-to-time
  8008. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")))))
  8009. (should
  8010. (equal "2012-03-29"
  8011. (format-time-string
  8012. "%Y-%m-%d"
  8013. (org-timestamp-to-time
  8014. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")))))
  8015. (should
  8016. (equal "2012-03-29"
  8017. (format-time-string
  8018. "%Y-%m-%d"
  8019. (org-timestamp-to-time
  8020. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")))))
  8021. ;; When optional argument END is non-nil, use end of date range or
  8022. ;; time range.
  8023. (should
  8024. (equal "2012-03-29 16:40"
  8025. (format-time-string
  8026. "%Y-%m-%d %H:%M"
  8027. (org-timestamp-to-time
  8028. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")
  8029. t))))
  8030. (should
  8031. (equal "2014-03-04"
  8032. (format-time-string
  8033. "%Y-%m-%d"
  8034. (org-timestamp-to-time
  8035. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")
  8036. t))))
  8037. (should
  8038. (equal "2014-03-04"
  8039. (format-time-string
  8040. "%Y-%m-%d"
  8041. (org-timestamp-to-time
  8042. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")
  8043. t)))))
  8044. ;;; Yank and Kill
  8045. (ert-deftest test-org/paste-subtree ()
  8046. "Test `org-paste-subtree' specifications."
  8047. ;; Return an error if text to yank is not a set of subtrees.
  8048. (should-error (org-paste-subtree nil "Text"))
  8049. ;; Adjust level according to current one.
  8050. (should
  8051. (equal "* H\n* Text\n"
  8052. (org-test-with-temp-text "* H\n<point>"
  8053. (org-paste-subtree nil "* Text")
  8054. (buffer-string))))
  8055. (should
  8056. (equal "* H1\n** H2\n** Text\n"
  8057. (org-test-with-temp-text "* H1\n** H2\n<point>"
  8058. (org-paste-subtree nil "* Text")
  8059. (buffer-string))))
  8060. ;; When not on a heading, move to next heading before yanking.
  8061. (should
  8062. (equal "* H1\nParagraph\n* Text\n* H2"
  8063. (org-test-with-temp-text "* H1\n<point>Paragraph\n* H2"
  8064. (org-paste-subtree nil "* Text")
  8065. (buffer-string))))
  8066. ;; If point is between two headings, use the deepest level.
  8067. (should
  8068. (equal "* H1\n\n* Text\n* H2"
  8069. (org-test-with-temp-text "* H1\n<point>\n* H2"
  8070. (org-paste-subtree nil "* Text")
  8071. (buffer-string))))
  8072. (should
  8073. (equal "** H1\n\n** Text\n* H2"
  8074. (org-test-with-temp-text "** H1\n<point>\n* H2"
  8075. (org-paste-subtree nil "* Text")
  8076. (buffer-string))))
  8077. (should
  8078. (equal "* H1\n\n** Text\n** H2"
  8079. (org-test-with-temp-text "* H1\n<point>\n** H2"
  8080. (org-paste-subtree nil "* Text")
  8081. (buffer-string))))
  8082. ;; When on an empty heading, after the stars, deduce the new level
  8083. ;; from the number of stars.
  8084. (should
  8085. (equal "*** Text\n"
  8086. (org-test-with-temp-text "*** <point>"
  8087. (org-paste-subtree nil "* Text")
  8088. (buffer-string))))
  8089. ;; Optional argument LEVEL forces a level for the subtree.
  8090. (should
  8091. (equal "* H\n*** Text\n"
  8092. (org-test-with-temp-text "* H<point>"
  8093. (org-paste-subtree 3 "* Text")
  8094. (buffer-string)))))
  8095. (ert-deftest test-org/cut-and-paste-subtree ()
  8096. "Test `org-cut-subtree' and `org-paste-subtree'."
  8097. (should
  8098. (equal
  8099. "* Two
  8100. two
  8101. * One
  8102. "
  8103. (org-test-with-temp-text
  8104. "* One
  8105. <point>* Two
  8106. two
  8107. "
  8108. (call-interactively #'org-cut-subtree)
  8109. (goto-char (point-min))
  8110. (call-interactively #'org-paste-subtree)
  8111. (buffer-string))))
  8112. (should
  8113. (equal
  8114. "* One
  8115. * Two
  8116. "
  8117. (org-test-with-temp-text
  8118. "* One
  8119. <point>* Two
  8120. "
  8121. (call-interactively #'org-cut-subtree)
  8122. (backward-char)
  8123. (call-interactively #'org-paste-subtree)
  8124. (buffer-string)))))
  8125. (provide 'test-org)
  8126. ;;; test-org.el ends here