test-org.el 270 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301
  1. ;;; test-org.el --- tests for org.el
  2. ;; Copyright (c) David Maus
  3. ;; Authors: David Maus
  4. ;; This file is not part of GNU Emacs.
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. ;; Template test file for Org tests
  16. ;;; Code:
  17. (eval-and-compile (require 'cl-lib))
  18. ;;; Comments
  19. (ert-deftest test-org/toggle-comment ()
  20. "Test `org-toggle-comment' specifications."
  21. ;; Simple headline.
  22. (should
  23. (equal "* Test"
  24. (org-test-with-temp-text "* COMMENT Test"
  25. (org-toggle-comment)
  26. (buffer-string))))
  27. (should
  28. (equal "* COMMENT Test"
  29. (org-test-with-temp-text "* Test"
  30. (org-toggle-comment)
  31. (buffer-string))))
  32. ;; Headline with a regular keyword.
  33. (should
  34. (equal "* TODO Test"
  35. (org-test-with-temp-text "* TODO COMMENT Test"
  36. (org-toggle-comment)
  37. (buffer-string))))
  38. (should
  39. (equal "* TODO COMMENT Test"
  40. (org-test-with-temp-text "* TODO Test"
  41. (org-toggle-comment)
  42. (buffer-string))))
  43. ;; Empty headline.
  44. (should
  45. (equal "* "
  46. (org-test-with-temp-text "* COMMENT"
  47. (org-toggle-comment)
  48. (buffer-string))))
  49. (should
  50. (equal "* COMMENT"
  51. (org-test-with-temp-text "* "
  52. (org-toggle-comment)
  53. (buffer-string))))
  54. ;; Headline with a single keyword.
  55. (should
  56. (equal "* TODO "
  57. (org-test-with-temp-text "* TODO COMMENT"
  58. (org-toggle-comment)
  59. (buffer-string))))
  60. (should
  61. (equal "* TODO COMMENT"
  62. (org-test-with-temp-text "* TODO"
  63. (org-toggle-comment)
  64. (buffer-string))))
  65. ;; Headline with a keyword, a priority cookie and contents.
  66. (should
  67. (equal "* TODO [#A] Headline"
  68. (org-test-with-temp-text "* TODO [#A] COMMENT Headline"
  69. (org-toggle-comment)
  70. (buffer-string))))
  71. (should
  72. (equal "* TODO [#A] COMMENT Headline"
  73. (org-test-with-temp-text "* TODO [#A] Headline"
  74. (org-toggle-comment)
  75. (buffer-string)))))
  76. (ert-deftest test-org/comment-dwim ()
  77. "Test `comment-dwim' behaviour in an Org buffer."
  78. ;; No region selected, no comment on current line and line not
  79. ;; empty: insert comment on line above.
  80. (should
  81. (equal "# \nComment"
  82. (org-test-with-temp-text "Comment"
  83. (call-interactively #'org-comment-dwim)
  84. (buffer-string))))
  85. ;; No region selected, no comment on current line and line empty:
  86. ;; insert comment on this line.
  87. (should
  88. (equal "# \nParagraph"
  89. (org-test-with-temp-text "\nParagraph"
  90. (call-interactively #'org-comment-dwim)
  91. (buffer-string))))
  92. ;; No region selected, and a comment on this line: indent it.
  93. (should
  94. (equal "* Headline\n # Comment"
  95. (org-test-with-temp-text "* Headline\n# <point>Comment"
  96. (let ((org-adapt-indentation t))
  97. (call-interactively #'org-comment-dwim))
  98. (buffer-string))))
  99. ;; Also recognize single # at column 0 as comments.
  100. (should
  101. (equal "# Comment"
  102. (org-test-with-temp-text "# Comment"
  103. (call-interactively #'org-comment-dwim)
  104. (buffer-string))))
  105. ;; Region selected and only comments and blank lines within it:
  106. ;; un-comment all commented lines.
  107. (should
  108. (equal "Comment 1\n\nComment 2"
  109. (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
  110. (transient-mark-mode 1)
  111. (push-mark (point) t t)
  112. (goto-char (point-max))
  113. (call-interactively #'org-comment-dwim)
  114. (buffer-string))))
  115. ;; Region selected without comments: comment all lines if
  116. ;; `comment-empty-lines' is non-nil, only non-blank lines otherwise.
  117. (should
  118. (equal "# Comment 1\n\n# Comment 2"
  119. (org-test-with-temp-text "Comment 1\n\nComment 2"
  120. (transient-mark-mode 1)
  121. (push-mark (point) t t)
  122. (goto-char (point-max))
  123. (let ((comment-empty-lines nil))
  124. (call-interactively #'org-comment-dwim))
  125. (buffer-string))))
  126. (should
  127. (equal "# Comment 1\n# \n# Comment 2"
  128. (org-test-with-temp-text "Comment 1\n\nComment 2"
  129. (transient-mark-mode 1)
  130. (push-mark (point) t t)
  131. (goto-char (point-max))
  132. (let ((comment-empty-lines t))
  133. (call-interactively #'org-comment-dwim))
  134. (buffer-string))))
  135. ;; In front of a keyword without region, insert a new comment.
  136. (should
  137. (equal "# \n#+KEYWORD: value"
  138. (org-test-with-temp-text "#+KEYWORD: value"
  139. (call-interactively #'org-comment-dwim)
  140. (buffer-string))))
  141. ;; Comment a heading
  142. (should
  143. (equal "* COMMENT Test"
  144. (org-test-with-temp-text "* Test"
  145. (call-interactively #'org-comment-dwim)
  146. (buffer-string))))
  147. ;; In a source block, use appropriate syntax.
  148. (should
  149. (equal " ;; "
  150. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n<point>\n#+END_SRC"
  151. (let ((org-edit-src-content-indentation 2))
  152. (call-interactively #'org-comment-dwim))
  153. (buffer-substring-no-properties (line-beginning-position)
  154. (point)))))
  155. (should
  156. (equal "#+BEGIN_SRC emacs-lisp\n ;; a\n ;; b\n#+END_SRC"
  157. (org-test-with-temp-text
  158. "#+BEGIN_SRC emacs-lisp\n<point>a\nb\n#+END_SRC"
  159. (transient-mark-mode 1)
  160. (push-mark (point) t t)
  161. (forward-line 2)
  162. (let ((org-edit-src-content-indentation 2))
  163. (call-interactively #'org-comment-dwim))
  164. (buffer-string)))))
  165. ;;; Date and time analysis
  166. (ert-deftest test-org/org-read-date ()
  167. "Test `org-read-date' specifications."
  168. ;; Parse ISO date with abbreviated year and month.
  169. (should (equal "2012-03-29 16:40"
  170. (let ((org-time-was-given t))
  171. (org-read-date t nil "12-3-29 16:40"))))
  172. ;; Parse Europeans dates.
  173. (should (equal "2012-03-29 16:40"
  174. (let ((org-time-was-given t))
  175. (org-read-date t nil "29.03.2012 16:40"))))
  176. ;; Parse Europeans dates without year.
  177. (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
  178. (let ((org-time-was-given t))
  179. (org-read-date t nil "29.03. 16:40"))))
  180. ;; Relative date applied to current time if there is single
  181. ;; plus/minus, or to default date when there are two of them.
  182. (should
  183. (equal
  184. "2015-03-04"
  185. (org-test-at-time "2014-03-04"
  186. (org-read-date
  187. t nil "+1y" nil
  188. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))
  189. (should
  190. (equal
  191. "2013-03-29"
  192. (org-test-at-time "2014-03-04"
  193. (org-read-date
  194. t nil "++1y" nil
  195. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))
  196. ;; When `org-read-date-prefer-future' is non-nil, prefer future
  197. ;; dates (relatively to now) when incomplete. Otherwise, use
  198. ;; default date.
  199. (should
  200. (equal
  201. "2014-04-01"
  202. (org-test-at-time "2014-03-04"
  203. (let ((org-read-date-prefer-future t))
  204. (org-read-date t nil "1")))))
  205. (should
  206. (equal
  207. "2013-03-04"
  208. (org-test-at-time "2012-03-29"
  209. (let ((org-read-date-prefer-future t))
  210. (org-read-date t nil "3-4")))))
  211. (should
  212. (equal
  213. "2012-03-04"
  214. (org-test-at-time "2012-03-29"
  215. (let ((org-read-date-prefer-future nil))
  216. (org-read-date t nil "3-4")))))
  217. ;; When set to `org-read-date-prefer-future' is set to `time', read
  218. ;; day is moved to tomorrow if specified hour is before current
  219. ;; time. However, it only happens in no other part of the date is
  220. ;; specified.
  221. (should
  222. (equal
  223. "2012-03-30"
  224. (org-test-at-time "2012-03-29 16:40"
  225. (let ((org-read-date-prefer-future 'time))
  226. (org-read-date t nil "00:40" nil)))))
  227. (should-not
  228. (equal
  229. "2012-03-30"
  230. (org-test-at-time "2012-03-29 16:40"
  231. (let ((org-read-date-prefer-future 'time))
  232. (org-read-date t nil "29 00:40" nil)))))
  233. ;; Caveat: `org-read-date-prefer-future' always refers to current
  234. ;; time, not default time, when they differ.
  235. (should
  236. (equal
  237. "2014-04-01"
  238. (org-test-at-time "2014-03-04"
  239. (let ((org-read-date-prefer-future t))
  240. (org-read-date
  241. t nil "1" nil
  242. (apply #'encode-time (org-parse-time-string "2012-03-29")))))))
  243. (should
  244. (equal
  245. "2014-03-25"
  246. (org-test-at-time "2014-03-04"
  247. (let ((org-read-date-prefer-future t))
  248. (org-read-date
  249. t nil "25" nil
  250. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))))
  251. (ert-deftest test-org/org-parse-time-string ()
  252. "Test `org-parse-time-string'."
  253. (should (equal (org-parse-time-string "2012-03-29 16:40")
  254. '(0 40 16 29 3 2012 nil nil nil)))
  255. (should (equal (org-parse-time-string "[2012-03-29 16:40]")
  256. '(0 40 16 29 3 2012 nil nil nil)))
  257. (should (equal (org-parse-time-string "<2012-03-29 16:40>")
  258. '(0 40 16 29 3 2012 nil nil nil)))
  259. (should (equal (org-parse-time-string "<2012-03-29>")
  260. '(0 0 0 29 3 2012 nil nil nil)))
  261. (should (equal (org-parse-time-string "<2012-03-29>" t)
  262. '(0 nil nil 29 3 2012 nil nil nil))))
  263. (ert-deftest test-org/closest-date ()
  264. "Test `org-closest-date' specifications."
  265. (require 'calendar)
  266. ;; Time stamps without a repeater are returned unchanged.
  267. (should
  268. (equal
  269. '(3 29 2012)
  270. (calendar-gregorian-from-absolute
  271. (org-closest-date "<2012-03-29>" "<2014-03-04>" nil))))
  272. ;; Time stamps with a null repeater are returned unchanged.
  273. (should
  274. (equal
  275. '(3 29 2012)
  276. (calendar-gregorian-from-absolute
  277. (org-closest-date "<2012-03-29 +0d>" "<2014-03-04>" nil))))
  278. ;; if PREFER is set to `past' always return a date before, or equal
  279. ;; to CURRENT.
  280. (should
  281. (equal
  282. '(3 1 2014)
  283. (calendar-gregorian-from-absolute
  284. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'past))))
  285. (should
  286. (equal
  287. '(3 4 2014)
  288. (calendar-gregorian-from-absolute
  289. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'past))))
  290. ;; if PREFER is set to `future' always return a date before, or equal
  291. ;; to CURRENT.
  292. (should
  293. (equal
  294. '(3 29 2014)
  295. (calendar-gregorian-from-absolute
  296. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'future))))
  297. (should
  298. (equal
  299. '(3 4 2014)
  300. (calendar-gregorian-from-absolute
  301. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'future))))
  302. ;; If PREFER is neither `past' nor `future', select closest date.
  303. (should
  304. (equal
  305. '(3 1 2014)
  306. (calendar-gregorian-from-absolute
  307. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" nil))))
  308. (should
  309. (equal
  310. '(5 4 2014)
  311. (calendar-gregorian-from-absolute
  312. (org-closest-date "<2012-03-04 +1m>" "<2014-04-28>" nil))))
  313. ;; Test "day" repeater.
  314. (should
  315. (equal '(3 8 2014)
  316. (calendar-gregorian-from-absolute
  317. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'past))))
  318. (should
  319. (equal '(3 10 2014)
  320. (calendar-gregorian-from-absolute
  321. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'future))))
  322. ;; Test "month" repeater.
  323. (should
  324. (equal '(1 5 2015)
  325. (calendar-gregorian-from-absolute
  326. (org-closest-date "<2014-03-05 +2m>" "<2015-02-04>" 'past))))
  327. (should
  328. (equal '(3 29 2014)
  329. (calendar-gregorian-from-absolute
  330. (org-closest-date "<2012-03-29 +2m>" "<2014-03-04>" 'future))))
  331. ;; Test "year" repeater.
  332. (should
  333. (equal '(3 5 2014)
  334. (calendar-gregorian-from-absolute
  335. (org-closest-date "<2014-03-05 +2y>" "<2015-02-04>" 'past))))
  336. (should
  337. (equal '(3 29 2014)
  338. (calendar-gregorian-from-absolute
  339. (org-closest-date "<2012-03-29 +2y>" "<2014-03-04>" 'future)))))
  340. (ert-deftest test-org/deadline-close-p ()
  341. "Test `org-deadline-close-p' specifications."
  342. (org-test-at-time "2016-06-03 Fri 01:43"
  343. ;; Timestamps are close if they are within `ndays' of lead time.
  344. (org-test-with-temp-text "* Heading"
  345. (should (org-deadline-close-p "2016-06-03 Fri" 0))
  346. (should (org-deadline-close-p "2016-06-02 Thu" 0))
  347. (should-not (org-deadline-close-p "2016-06-04 Sat" 0))
  348. (should (org-deadline-close-p "2016-06-04 Sat" 1))
  349. (should (org-deadline-close-p "2016-06-03 Fri 12:00" 0)))
  350. ;; Read `ndays' from timestamp if argument not given.
  351. (org-test-with-temp-text "* H"
  352. (should (org-deadline-close-p "2016-06-04 Sat -1d"))
  353. (should-not (org-deadline-close-p "2016-06-04 Sat -0d"))
  354. (should (org-deadline-close-p "2016-06-10 Fri -1w"))
  355. (should-not (org-deadline-close-p "2016-06-11 Sat -1w")))
  356. ;; Prefer `ndays' argument over lead time in timestamp.
  357. (org-test-with-temp-text "* H"
  358. (should (org-deadline-close-p "2016-06-04 Sat -0d" 1))
  359. (should-not (org-deadline-close-p "2016-06-04 Sat -0d" 0)))
  360. ;; Completed tasks are never close.
  361. (let ((org-todo-keywords '(("TODO" "|" "DONE"))))
  362. (org-test-with-temp-text "* TODO Heading"
  363. (should (org-deadline-close-p "2016-06-03")))
  364. (org-test-with-temp-text "* DONE Heading"
  365. (should-not (org-deadline-close-p "2016-06-03"))))))
  366. ;;; Drawers
  367. (ert-deftest test-org/at-property-p ()
  368. "Test `org-at-property-p' specifications."
  369. (should
  370. (equal 't
  371. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:PROP: t\n:END:\n"
  372. (org-at-property-p))))
  373. (should
  374. (equal 't
  375. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n:END:\n"
  376. (org-at-property-p)))))
  377. (ert-deftest test-org/at-property-drawer-p ()
  378. "Test `org-at-property-drawer-p' specifications."
  379. (should
  380. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:PROP: t\n:END:\n"
  381. (org-at-property-drawer-p)))
  382. (should
  383. (org-test-with-temp-text ":PROPERTIES:\n:PROP: t\n:END:\n"
  384. (org-at-property-drawer-p)))
  385. ;; The function only returns t if point is at the first line of
  386. ;; a property block.
  387. (should-not
  388. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n:END:\n"
  389. (org-at-property-drawer-p)))
  390. ;; The function ignores incomplete drawers.
  391. (should-not
  392. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n"
  393. (org-at-property-drawer-p)))
  394. ;; tab separating the value.
  395. (should
  396. (org-test-with-temp-text ":PROPERTIES:\n:PROP: t\n:END:\n"
  397. (org-at-property-drawer-p))))
  398. (ert-deftest test-org/get-property-block ()
  399. "Test `org-get-property-block' specifications."
  400. (should
  401. (equal '(14 . 14)
  402. (org-test-with-temp-text ":PROPERTIES:\n:END:\n* H\n"
  403. (org-get-property-block))))
  404. (should
  405. (equal '(14 . 14)
  406. (org-test-with-temp-text ":PROPERTIES:\n:END:\n"
  407. (org-get-property-block))))
  408. ;; Comments above a document property block is ok.
  409. (should
  410. (equal '(18 . 18)
  411. (org-test-with-temp-text "# C\n:PROPERTIES:\n:END:\n"
  412. (org-get-property-block))))
  413. ;; Keywords above a document property block is ok.
  414. (should
  415. (equal '(22 . 22)
  416. (org-test-with-temp-text "# C\n# C\n:PROPERTIES:\n:END:\n"
  417. (org-get-property-block))))
  418. ;; Comments and keywords are allowed before a document property block.
  419. (should
  420. (equal '(18 . 27)
  421. (org-test-with-temp-text "# C\n:PROPERTIES:\n:KEY: V:\n:END:\n"
  422. (org-get-property-block))))
  423. ;; A document property block will not be valid if there are lines
  424. ;; with whitespace above it
  425. (should-not
  426. (org-test-with-temp-text "\n:PROPERTIES:\n:END:\n"
  427. (org-get-property-block)))
  428. (should
  429. (equal '(18 . 18)
  430. (org-test-with-temp-text "* H\n:PROPERTIES:\n:END:\n<point>"
  431. (org-get-property-block))))
  432. (should
  433. (equal "* H\n:PROPERTIES:\n:END:\n"
  434. (org-test-with-temp-text "* H"
  435. (let ((org-adapt-indentation nil))
  436. (org-get-property-block nil 'force))
  437. (buffer-string))))
  438. (should
  439. (equal ":PROPERTIES:\n:END:\n"
  440. (org-test-with-temp-text ""
  441. (org-get-property-block nil 'force)
  442. (buffer-string))))
  443. (should
  444. (equal "* H1\n :PROPERTIES:\n :END:\n* H2"
  445. (org-test-with-temp-text "* H1\n* H2"
  446. (let ((org-adapt-indentation t))
  447. (org-get-property-block nil 'force))
  448. (buffer-string)))))
  449. (ert-deftest test-org/insert-property-drawer ()
  450. "Test `org-insert-property-drawer' specifications."
  451. ;; Insert drawer in empty buffer
  452. (should
  453. (equal ":PROPERTIES:\n:END:\n"
  454. (org-test-with-temp-text ""
  455. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  456. (buffer-string))))
  457. ;; Insert drawer in document header with existing comment and
  458. ;; keyword.
  459. (should
  460. (equal "# C\n:PROPERTIES:\n:END:\n#+TITLE: T"
  461. (org-test-with-temp-text "# C\n#+TITLE: T"
  462. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  463. (buffer-string))))
  464. ;; Insert drawer in document header with existing keyword.
  465. (should
  466. (equal ":PROPERTIES:\n:END:\n#+TITLE: T"
  467. (org-test-with-temp-text "#+TITLE: T"
  468. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  469. (buffer-string))))
  470. (should
  471. (equal ":PROPERTIES:\n:END:"
  472. (org-test-with-temp-text ":PROPERTIES:\n:END:"
  473. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  474. (buffer-string))))
  475. ;; Insert drawer in document header with one existing heading in buffer.
  476. (should
  477. (equal ":PROPERTIES:\n:END:\n\n* T\n"
  478. (org-test-with-temp-text "\n* T\n"
  479. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  480. (buffer-string))))
  481. ;; Insert drawer right after headline if there is no planning line,
  482. ;; or after it otherwise.
  483. (should
  484. (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
  485. (org-test-with-temp-text "* H\nParagraph<point>"
  486. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  487. (buffer-string))))
  488. (should
  489. (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
  490. (org-test-with-temp-text
  491. "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
  492. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  493. (buffer-string))))
  494. ;; Indent inserted drawer.
  495. (should
  496. (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
  497. (org-test-with-temp-text "* H\nParagraph<point>"
  498. (let ((org-adapt-indentation t)) (org-insert-property-drawer))
  499. (buffer-string))))
  500. ;; Handle insertion at eob.
  501. (should
  502. (equal "* H\n:PROPERTIES:\n:END:\n"
  503. (org-test-with-temp-text "* H"
  504. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  505. (buffer-string))))
  506. ;; Skip inlinetasks before point.
  507. (when (featurep 'org-inlinetask)
  508. (should
  509. (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
  510. (org-test-with-temp-text
  511. "* H\n*************** I\n*************** END\nP<point>"
  512. (let ((org-adapt-indentation nil)
  513. (org-inlinetask-min-level 15))
  514. (org-insert-property-drawer))
  515. (buffer-string)))))
  516. ;; Correctly set drawer in an inlinetask.
  517. (when (featurep 'org-inlinetask)
  518. (should
  519. (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
  520. (org-test-with-temp-text
  521. "* H\n*************** I\nP<point>\n*************** END"
  522. (let ((org-adapt-indentation nil)
  523. (org-inlinetask-min-level 15))
  524. (org-insert-property-drawer))
  525. (buffer-string))))))
  526. ;;; Filling
  527. (ert-deftest test-org/fill-element ()
  528. "Test `org-fill-element' specifications."
  529. ;; At an Org table, align it.
  530. (should
  531. (equal "| a |\n"
  532. (org-test-with-temp-text "|a|"
  533. (org-fill-element)
  534. (buffer-string))))
  535. (should
  536. (equal "#+name: table\n| a |\n"
  537. (org-test-with-temp-text "#+name: table\n| a |\n"
  538. (org-fill-element)
  539. (buffer-string))))
  540. ;; At a paragraph, preserve line breaks.
  541. (org-test-with-temp-text "some \\\\\nlong\ntext"
  542. (let ((fill-column 20))
  543. (org-fill-element)
  544. (should (equal (buffer-string) "some \\\\\nlong text"))))
  545. ;; Correctly fill a paragraph when point is at its very end.
  546. (should
  547. (equal "A B"
  548. (org-test-with-temp-text "A\nB"
  549. (let ((fill-column 20))
  550. (goto-char (point-max))
  551. (org-fill-element)
  552. (buffer-string)))))
  553. ;; Correctly fill the last paragraph of a greater element.
  554. (should
  555. (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
  556. (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
  557. (let ((fill-column 8))
  558. (forward-line)
  559. (end-of-line)
  560. (org-fill-element)
  561. (buffer-string)))))
  562. ;; Correctly fill an element in a narrowed buffer.
  563. (should
  564. (equal "01234\n6"
  565. (org-test-with-temp-text "01234 6789"
  566. (let ((fill-column 5))
  567. (narrow-to-region 1 8)
  568. (org-fill-element)
  569. (buffer-string)))))
  570. ;; Handle `adaptive-fill-regexp' in paragraphs.
  571. (should
  572. (equal "> a b"
  573. (org-test-with-temp-text "> a\n> b"
  574. (let ((fill-column 5)
  575. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  576. (org-fill-element)
  577. (buffer-string)))))
  578. ;; Special case: Fill first paragraph when point is at an item or
  579. ;; a plain-list or a footnote reference.
  580. (should
  581. (equal "- A B"
  582. (org-test-with-temp-text "- A\n B"
  583. (let ((fill-column 20))
  584. (org-fill-element)
  585. (buffer-string)))))
  586. (should
  587. (equal "[fn:1] A B"
  588. (org-test-with-temp-text "[fn:1] A\nB"
  589. (let ((fill-column 20))
  590. (org-fill-element)
  591. (buffer-string)))))
  592. (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
  593. (let ((fill-column 20))
  594. (org-fill-element)
  595. (should (equal (buffer-string)
  596. "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
  597. ;; Fill contents of `comment-block' elements.
  598. (should
  599. (equal
  600. (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
  601. (let ((fill-column 20))
  602. (forward-line)
  603. (org-fill-element)
  604. (buffer-string)))
  605. "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
  606. ;; Fill `comment' elements.
  607. (should
  608. (equal " # A B"
  609. (org-test-with-temp-text " # A\n # B"
  610. (let ((fill-column 20))
  611. (org-fill-element)
  612. (buffer-string)))))
  613. ;; Do not mix consecutive comments when filling one of them.
  614. (should
  615. (equal "# A B\n\n# C"
  616. (org-test-with-temp-text "# A\n# B\n\n# C"
  617. (let ((fill-column 20))
  618. (org-fill-element)
  619. (buffer-string)))))
  620. ;; Use commented empty lines as separators when filling comments.
  621. (should
  622. (equal "# A B\n#\n# C"
  623. (org-test-with-temp-text "# A\n# B\n#\n# C"
  624. (let ((fill-column 20))
  625. (org-fill-element)
  626. (buffer-string)))))
  627. ;; Handle `adaptive-fill-regexp' in comments.
  628. (should
  629. (equal "# > a b"
  630. (org-test-with-temp-text "# > a\n# > b"
  631. (let ((fill-column 20)
  632. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  633. (org-fill-element)
  634. (buffer-string)))))
  635. ;; Do nothing at affiliated keywords.
  636. (should
  637. (equal "#+NAME: para\nSome\ntext."
  638. (org-test-with-temp-text "#+NAME: para\nSome\ntext."
  639. (let ((fill-column 20))
  640. (org-fill-element)
  641. (buffer-string)))))
  642. ;; Do not move point after table when filling a table.
  643. (should-not
  644. (org-test-with-temp-text "| a | b |\n| c | d |\n"
  645. (forward-char)
  646. (org-fill-element)
  647. (eobp)))
  648. ;; Do not fill "n" macro, with or without arguments, followed by
  649. ;; a dot or a closing parenthesis since it could be confused with
  650. ;; a numbered bullet.
  651. (should-not
  652. (equal "123456789\n{{{n}}}."
  653. (org-test-with-temp-text "123456789 {{{n}}}."
  654. (let ((fill-column 10))
  655. (org-fill-element)
  656. (buffer-string)))))
  657. (should-not
  658. (equal "123456789\n{{{n}}}\)"
  659. (org-test-with-temp-text "123456789 {{{n}}}\)"
  660. (let ((fill-column 10))
  661. (org-fill-element)
  662. (buffer-string)))))
  663. (should-not
  664. (equal "123456789\n{{{n()}}}."
  665. (org-test-with-temp-text "123456789 {{{n()}}}."
  666. (let ((fill-column 10))
  667. (org-fill-element)
  668. (buffer-string)))))
  669. (should-not
  670. (equal "123456789\n{{{n(counter)}}}."
  671. (org-test-with-temp-text "123456789 {{{n(counter)}}}."
  672. (let ((fill-column 10))
  673. (org-fill-element)
  674. (buffer-string))))))
  675. (ert-deftest test-org/fill-paragraph ()
  676. "Test `org-fill-paragraph' specifications."
  677. ;; Regular test.
  678. (should
  679. (equal "012345678\n9"
  680. (org-test-with-temp-text "012345678 9"
  681. (let ((fill-column 10))
  682. (org-fill-paragraph)
  683. (buffer-string)))))
  684. ;; Fill paragraph even at end of buffer.
  685. (should
  686. (equal "012345678\n9\n"
  687. (org-test-with-temp-text "012345678 9\n<point>"
  688. (let ((fill-column 10))
  689. (org-fill-paragraph)
  690. (buffer-string)))))
  691. ;; Between two paragraphs, fill the next one.
  692. (should
  693. (equal "012345678 9\n\n012345678\n9"
  694. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  695. (let ((fill-column 10))
  696. (org-fill-paragraph)
  697. (buffer-string)))))
  698. (should
  699. (equal "012345678\n9\n\n012345678 9"
  700. (org-test-with-temp-text "012345678 9<point>\n\n012345678 9"
  701. (let ((fill-column 10))
  702. (org-fill-paragraph)
  703. (buffer-string)))))
  704. ;; Fill paragraph in a comment block.
  705. (should
  706. (equal "#+begin_comment\n012345678\n9\n#+end_comment"
  707. (org-test-with-temp-text
  708. "#+begin_comment\n<point>012345678 9\n#+end_comment"
  709. (let ((fill-column 10))
  710. (org-fill-paragraph)
  711. (buffer-string)))))
  712. ;; When a region is selected, fill every paragraph in the region.
  713. (should
  714. (equal "012345678\n9\n\n012345678\n9"
  715. (org-test-with-temp-text "012345678 9\n\n012345678 9"
  716. (let ((fill-column 10))
  717. (transient-mark-mode 1)
  718. (push-mark (point-min) t t)
  719. (goto-char (point-max))
  720. (call-interactively #'org-fill-paragraph)
  721. (buffer-string)))))
  722. (should
  723. (equal "012345678\n9\n\n012345678 9"
  724. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  725. (let ((fill-column 10))
  726. (transient-mark-mode 1)
  727. (push-mark (point) t t)
  728. (goto-char (point-min))
  729. (call-interactively #'org-fill-paragraph)
  730. (buffer-string)))))
  731. (should
  732. (equal "012345678 9\n\n012345678\n9"
  733. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  734. (let ((fill-column 10))
  735. (transient-mark-mode 1)
  736. (push-mark (point) t t)
  737. (goto-char (point-max))
  738. (call-interactively #'org-fill-paragraph)
  739. (buffer-string))))))
  740. (ert-deftest test-org/auto-fill-function ()
  741. "Test auto-filling features."
  742. ;; Auto fill paragraph.
  743. (should
  744. (equal "12345\n7890"
  745. (org-test-with-temp-text "12345 7890"
  746. (let ((fill-column 5))
  747. (end-of-line)
  748. (org-auto-fill-function)
  749. (buffer-string)))))
  750. ;; Auto fill first paragraph in an item.
  751. (should
  752. (equal "- 12345\n 7890"
  753. (org-test-with-temp-text "- 12345 7890"
  754. (let ((fill-column 7))
  755. (end-of-line)
  756. (org-auto-fill-function)
  757. (buffer-string)))))
  758. ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
  759. (should
  760. (equal "> 12345\n 7890"
  761. (org-test-with-temp-text "> 12345 7890"
  762. (let ((fill-column 10)
  763. (adaptive-fill-regexp "[ \t]*>+[ \t]*")
  764. (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
  765. (end-of-line)
  766. (org-auto-fill-function)
  767. (buffer-string)))))
  768. (should
  769. (equal "> 12345\n> 12345\n> 7890"
  770. (org-test-with-temp-text "> 12345\n> 12345 7890"
  771. (let ((fill-column 10)
  772. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  773. (goto-char (point-max))
  774. (org-auto-fill-function)
  775. (buffer-string)))))
  776. (should-not
  777. (equal " 12345\n *12345\n *12345"
  778. (org-test-with-temp-text " 12345\n *12345 12345"
  779. (let ((fill-column 10)
  780. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  781. (goto-char (point-max))
  782. (org-auto-fill-function)
  783. (buffer-string)))))
  784. ;; Auto fill comments.
  785. (should
  786. (equal " # 12345\n # 7890"
  787. (org-test-with-temp-text " # 12345 7890"
  788. (let ((fill-column 10))
  789. (end-of-line)
  790. (org-auto-fill-function)
  791. (buffer-string)))))
  792. ;; A hash within a line isn't a comment.
  793. (should-not
  794. (equal "12345 # 7890\n# 1"
  795. (org-test-with-temp-text "12345 # 7890 1"
  796. (let ((fill-column 12))
  797. (end-of-line)
  798. (org-auto-fill-function)
  799. (buffer-string)))))
  800. ;; Correctly interpret empty prefix.
  801. (should-not
  802. (equal "# a\n# b\nRegular\n# paragraph"
  803. (org-test-with-temp-text "# a\n# b\nRegular paragraph"
  804. (let ((fill-column 12))
  805. (end-of-line 3)
  806. (org-auto-fill-function)
  807. (buffer-string)))))
  808. ;; Comment block: auto fill contents.
  809. (should
  810. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  811. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  812. (let ((fill-column 5))
  813. (forward-line)
  814. (end-of-line)
  815. (org-auto-fill-function)
  816. (buffer-string)))))
  817. (should
  818. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  819. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  820. (let ((fill-column 5))
  821. (forward-line)
  822. (end-of-line)
  823. (org-auto-fill-function)
  824. (buffer-string)))))
  825. ;; Do not fill if a new item could be created.
  826. (should-not
  827. (equal "12345\n- 90"
  828. (org-test-with-temp-text "12345 - 90"
  829. (let ((fill-column 5))
  830. (end-of-line)
  831. (org-auto-fill-function)
  832. (buffer-string)))))
  833. ;; Do not fill if a line break could be introduced.
  834. (should-not
  835. (equal "123\\\\\n7890"
  836. (org-test-with-temp-text "123\\\\ 7890"
  837. (let ((fill-column 6))
  838. (end-of-line)
  839. (org-auto-fill-function)
  840. (buffer-string)))))
  841. ;; Do not fill affiliated keywords.
  842. (should-not
  843. (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
  844. (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
  845. (let ((fill-column 20))
  846. (end-of-line)
  847. (org-auto-fill-function)
  848. (buffer-string))))))
  849. ;;; Indentation
  850. (ert-deftest test-org/indent-line ()
  851. "Test `org-indent-line' specifications."
  852. ;; Do not indent diary sexps, footnote definitions or headlines.
  853. (should
  854. (zerop
  855. (org-test-with-temp-text "%%(org-calendar-holiday)"
  856. (org-indent-line)
  857. (org-get-indentation))))
  858. (should
  859. (zerop
  860. (org-test-with-temp-text "[fn:1] fn"
  861. (let ((org-adapt-indentation t)) (org-indent-line))
  862. (org-get-indentation))))
  863. (should
  864. (zerop
  865. (org-test-with-temp-text "* H"
  866. (org-indent-line)
  867. (org-get-indentation))))
  868. ;; Do not indent before first headline.
  869. (should
  870. (zerop
  871. (org-test-with-temp-text ""
  872. (org-indent-line)
  873. (org-get-indentation))))
  874. ;; Indent according to headline level otherwise, unless
  875. ;; `org-adapt-indentation' is nil.
  876. (should
  877. (= 2
  878. (org-test-with-temp-text "* H\n<point>A"
  879. (let ((org-adapt-indentation t)) (org-indent-line))
  880. (org-get-indentation))))
  881. (should
  882. (= 2
  883. (org-test-with-temp-text "* H\n<point>\nA"
  884. (let ((org-adapt-indentation t)) (org-indent-line))
  885. (org-get-indentation))))
  886. (should
  887. (zerop
  888. (org-test-with-temp-text "* H\n<point>A"
  889. (let ((org-adapt-indentation nil)) (org-indent-line))
  890. (org-get-indentation))))
  891. ;; Indenting preserves point position.
  892. (should
  893. (org-test-with-temp-text "* H\nA<point>B"
  894. (let ((org-adapt-indentation t)) (org-indent-line))
  895. (looking-at "B")))
  896. ;; Do not change indentation at an item or a LaTeX environment.
  897. (should
  898. (= 1
  899. (org-test-with-temp-text "* H\n<point> - A"
  900. (let ((org-adapt-indentation t)) (org-indent-line))
  901. (org-get-indentation))))
  902. (should
  903. (= 1
  904. (org-test-with-temp-text
  905. "\\begin{equation}\n <point>1+1=2\n\\end{equation}"
  906. (org-indent-line)
  907. (org-get-indentation))))
  908. ;; On blank lines at the end of a list, indent like last element
  909. ;; within it if the line is still in the list. If the last element
  910. ;; is an item, indent like its contents. Otherwise, indent like the
  911. ;; whole list.
  912. (should
  913. (= 4
  914. (org-test-with-temp-text "* H\n- A\n - AA\n<point>"
  915. (let ((org-adapt-indentation t)) (org-indent-line))
  916. (org-get-indentation))))
  917. (should
  918. (= 4
  919. (org-test-with-temp-text "* H\n- A\n -\n\n<point>"
  920. (let ((org-adapt-indentation t)) (org-indent-line))
  921. (org-get-indentation))))
  922. (should
  923. (zerop
  924. (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n<point>"
  925. (let ((org-adapt-indentation t)) (org-indent-line))
  926. (org-get-indentation))))
  927. (should
  928. (= 4
  929. (org-test-with-temp-text "* H\n- A\n - \n<point>"
  930. (let ((org-adapt-indentation t)) (org-indent-line))
  931. (org-get-indentation))))
  932. (should
  933. (= 4
  934. (org-test-with-temp-text
  935. "* H\n - \n #+BEGIN_SRC emacs-lisp\n t\n #+END_SRC\n<point>"
  936. (let ((org-adapt-indentation t)) (org-indent-line))
  937. (org-get-indentation))))
  938. (should
  939. (= 2
  940. (org-test-with-temp-text "- A\n B\n\n<point>"
  941. (let ((org-adapt-indentation nil)) (org-indent-line))
  942. (org-get-indentation))))
  943. (should
  944. (= 2
  945. (org-test-with-temp-text
  946. "- A\n \begin{cases} 1 + 1\n \end{cases}\n\n<point>"
  947. (let ((org-adapt-indentation nil)) (org-indent-line))
  948. (org-get-indentation))))
  949. ;; Likewise, on a blank line at the end of a footnote definition,
  950. ;; indent at column 0 if line belongs to the definition. Otherwise,
  951. ;; indent like the definition itself.
  952. (should
  953. (zerop
  954. (org-test-with-temp-text "* H\n[fn:1] Definition\n<point>"
  955. (let ((org-adapt-indentation t)) (org-indent-line))
  956. (org-get-indentation))))
  957. (should
  958. (zerop
  959. (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n<point>"
  960. (let ((org-adapt-indentation t)) (org-indent-line))
  961. (org-get-indentation))))
  962. ;; After the end of the contents of a greater element, indent like
  963. ;; the beginning of the element.
  964. (should
  965. (= 1
  966. (org-test-with-temp-text
  967. " #+BEGIN_CENTER\n Contents\n<point>#+END_CENTER"
  968. (org-indent-line)
  969. (org-get-indentation))))
  970. ;; On blank lines after a paragraph, indent like its last non-empty
  971. ;; line.
  972. (should
  973. (= 1
  974. (org-test-with-temp-text " Paragraph\n\n<point>"
  975. (org-indent-line)
  976. (org-get-indentation))))
  977. ;; At the first line of an element, indent like previous element's
  978. ;; first line, ignoring footnotes definitions and inline tasks, or
  979. ;; according to parent.
  980. (let ((org-adapt-indentation t))
  981. (should
  982. (= 2
  983. (org-test-with-temp-text "A\n\n B\n\nC<point>"
  984. (org-indent-line)
  985. (org-get-indentation))))
  986. (should
  987. (= 1
  988. (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC<point>"
  989. (org-indent-line)
  990. (org-get-indentation))))
  991. (should
  992. (= 1
  993. (org-test-with-temp-text
  994. " #+BEGIN_CENTER\n<point> Contents\n#+END_CENTER"
  995. (org-indent-line)
  996. (org-get-indentation)))))
  997. ;; Within code part of a source block, use language major mode if
  998. ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
  999. ;; according to line above.
  1000. (should
  1001. (= 6
  1002. (org-test-with-temp-text
  1003. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  1004. (let ((org-src-tab-acts-natively t)
  1005. (org-edit-src-content-indentation 0))
  1006. (org-indent-line))
  1007. (org-get-indentation))))
  1008. (should
  1009. (= 1
  1010. (org-test-with-temp-text
  1011. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  1012. (let ((org-src-tab-acts-natively nil)
  1013. (org-edit-src-content-indentation 0))
  1014. (org-indent-line))
  1015. (org-get-indentation))))
  1016. ;; Otherwise, indent like the first non-blank line above.
  1017. (should
  1018. (zerop
  1019. (org-test-with-temp-text
  1020. "#+BEGIN_CENTER\nline1\n\n<point> line2\n#+END_CENTER"
  1021. (org-indent-line)
  1022. (org-get-indentation))))
  1023. ;; Align node properties according to `org-property-format'. Handle
  1024. ;; nicely empty values.
  1025. (should
  1026. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1027. (org-test-with-temp-text
  1028. "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
  1029. (let ((org-property-format "%-10s %s")) (org-indent-line))
  1030. (buffer-string))))
  1031. (should
  1032. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1033. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
  1034. (let ((org-property-format "%-10s %s")) (org-indent-line))
  1035. (buffer-string)))))
  1036. (ert-deftest test-org/indent-region ()
  1037. "Test `org-indent-region' specifications."
  1038. ;; Indent paragraph.
  1039. (let ((org-adapt-indentation t))
  1040. (should
  1041. (equal "A\nB\nC"
  1042. (org-test-with-temp-text " A\nB\n C"
  1043. (org-indent-region (point-min) (point-max))
  1044. (buffer-string)))))
  1045. ;; Indent greater elements along with their contents.
  1046. (should
  1047. (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
  1048. (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
  1049. (org-indent-region (point-min) (point-max))
  1050. (buffer-string))))
  1051. ;; Ignore contents of verse blocks. Only indent block delimiters.
  1052. (should
  1053. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1054. (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1055. (org-indent-region (point-min) (point-max))
  1056. (buffer-string))))
  1057. (let ((org-adapt-indentation t))
  1058. (should
  1059. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1060. (org-test-with-temp-text " #+BEGIN_VERSE\n A\n B\n #+END_VERSE"
  1061. (org-indent-region (point-min) (point-max))
  1062. (buffer-string)))))
  1063. ;; Indent example blocks as a single block, unless indentation
  1064. ;; should be preserved. In this case only indent the block markers.
  1065. (should
  1066. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1067. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1068. (org-indent-region (point-min) (point-max))
  1069. (buffer-string))))
  1070. (let ((org-adapt-indentation t))
  1071. (should
  1072. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1073. (org-test-with-temp-text " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1074. (org-indent-region (point-min) (point-max))
  1075. (buffer-string))))
  1076. (should
  1077. (equal "#+BEGIN_EXAMPLE -i\n A\n B\n#+END_EXAMPLE"
  1078. (org-test-with-temp-text
  1079. " #+BEGIN_EXAMPLE -i\n A\n B\n #+END_EXAMPLE"
  1080. (org-indent-region (point-min) (point-max))
  1081. (buffer-string))))
  1082. (should
  1083. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1084. (org-test-with-temp-text
  1085. " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1086. (let ((org-src-preserve-indentation t))
  1087. (org-indent-region (point-min) (point-max)))
  1088. (buffer-string)))))
  1089. ;; Treat export blocks as a whole.
  1090. (should
  1091. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1092. (org-test-with-temp-text "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1093. (org-indent-region (point-min) (point-max))
  1094. (buffer-string))))
  1095. (let ((org-adapt-indentation t))
  1096. (should
  1097. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1098. (org-test-with-temp-text
  1099. " #+BEGIN_EXPORT latex\n A\n B\n #+END_EXPORT"
  1100. (org-indent-region (point-min) (point-max))
  1101. (buffer-string)))))
  1102. ;; Indent according to mode if `org-src-tab-acts-natively' is
  1103. ;; non-nil. Otherwise, do not indent code at all.
  1104. (should
  1105. (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
  1106. (org-test-with-temp-text
  1107. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1108. (let ((org-src-tab-acts-natively t)
  1109. (org-edit-src-content-indentation 0))
  1110. (org-indent-region (point-min) (point-max)))
  1111. (buffer-string))))
  1112. (should
  1113. (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1114. (org-test-with-temp-text
  1115. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1116. (let ((org-src-tab-acts-natively nil)
  1117. (org-edit-src-content-indentation 0))
  1118. (org-indent-region (point-min) (point-max)))
  1119. (buffer-string))))
  1120. ;; Align node properties according to `org-property-format'. Handle
  1121. ;; nicely empty values.
  1122. (should
  1123. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1124. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
  1125. (let ((org-property-format "%-10s %s")
  1126. (org-adapt-indentation nil))
  1127. (org-indent-region (point) (point-max)))
  1128. (buffer-string))))
  1129. (should
  1130. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1131. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
  1132. (let ((org-property-format "%-10s %s")
  1133. (org-adapt-indentation nil))
  1134. (org-indent-region (point) (point-max)))
  1135. (buffer-string))))
  1136. ;; Indent property drawers according to `org-adapt-indentation'.
  1137. (let ((org-adapt-indentation 'headline-data))
  1138. (should
  1139. (equal "* H\n :PROPERTIES:\n :key:\n :END:"
  1140. (org-test-with-temp-text "* H\n:PROPERTIES:\n:key:\n:END:"
  1141. (org-indent-region (point-min) (point-max))
  1142. (buffer-string)))))
  1143. ;; Indent plain lists.
  1144. (let ((org-adapt-indentation t))
  1145. (should
  1146. (equal "- A\n B\n - C\n\n D"
  1147. (org-test-with-temp-text "- A\n B\n - C\n\n D"
  1148. (org-indent-region (point-min) (point-max))
  1149. (buffer-string))))
  1150. (should
  1151. (equal "- A\n\n- B"
  1152. (org-test-with-temp-text " - A\n\n - B"
  1153. (org-indent-region (point-min) (point-max))
  1154. (buffer-string)))))
  1155. ;; Indent footnote definitions.
  1156. (should
  1157. (equal "[fn:1] Definition\n\nDefinition"
  1158. (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
  1159. (org-indent-region (point-min) (point-max))
  1160. (buffer-string))))
  1161. ;; Special case: Start indenting on a blank line.
  1162. (should
  1163. (equal "\nParagraph"
  1164. (org-test-with-temp-text "\n Paragraph"
  1165. (org-indent-region (point-min) (point-max))
  1166. (buffer-string)))))
  1167. ;;; Editing
  1168. (ert-deftest test-org/delete-indentation ()
  1169. "Test `org-delete-indentation' specifications."
  1170. ;; Regular test.
  1171. (should (equal "foo bar"
  1172. (org-test-with-temp-text
  1173. "foo \n bar<point>"
  1174. (org-delete-indentation)
  1175. (buffer-string))))
  1176. ;; With optional argument.
  1177. (should (equal "foo bar"
  1178. (org-test-with-temp-text
  1179. "foo<point> \n bar"
  1180. (org-delete-indentation t)
  1181. (buffer-string))))
  1182. ;; At headline text should be appended to the headline text.
  1183. (should
  1184. (equal"* foo bar :tag:"
  1185. (let (org-auto-align-tags)
  1186. (org-test-with-temp-text
  1187. "* foo :tag:\n bar<point>"
  1188. (org-delete-indentation)
  1189. (buffer-string)))))
  1190. (should
  1191. (equal "* foo bar :tag:"
  1192. (let (org-auto-align-tags)
  1193. (org-test-with-temp-text
  1194. "* foo <point>:tag:\n bar"
  1195. (org-delete-indentation t)
  1196. (buffer-string))))))
  1197. (ert-deftest test-org/return ()
  1198. "Test `org-return' specifications."
  1199. ;; Regular test.
  1200. (should
  1201. (equal "Para\ngraph"
  1202. (org-test-with-temp-text "Para<point>graph"
  1203. (org-return)
  1204. (buffer-string))))
  1205. ;; With optional argument, indent line.
  1206. (should
  1207. (equal " Para\n graph"
  1208. (org-test-with-temp-text " Para<point>graph"
  1209. (org-return t)
  1210. (buffer-string))))
  1211. ;; On a table, call `org-table-next-row'.
  1212. (should
  1213. (org-test-with-temp-text "| <point>a |\n| b |"
  1214. (org-return)
  1215. (looking-at-p "b")))
  1216. ;; Open link or timestamp under point when `org-return-follows-link'
  1217. ;; is non-nil.
  1218. (should
  1219. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1220. (let ((org-return-follows-link t)
  1221. (org-link-search-must-match-exact-headline nil))
  1222. (org-return))
  1223. (looking-at-p "<<target>>")))
  1224. (should-not
  1225. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1226. (let ((org-return-follows-link nil)) (org-return))
  1227. (looking-at-p "<<target>>")))
  1228. (should
  1229. (org-test-with-temp-text "* [[b][a<point>]]\n* b"
  1230. (let ((org-return-follows-link t)) (org-return))
  1231. (looking-at-p "* b")))
  1232. (should
  1233. (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
  1234. (let ((org-return-follows-link t)
  1235. (org-link-search-must-match-exact-headline nil))
  1236. (org-return))
  1237. (looking-at-p "<<target>>")))
  1238. (should-not
  1239. (org-test-with-temp-text "Link [[target]]<point> <<target>>"
  1240. (let ((org-return-follows-link t)
  1241. (org-link-search-must-match-exact-headline nil))
  1242. (org-return))
  1243. (looking-at-p "<<target>>")))
  1244. ;; When `org-return-follows-link' is non-nil, tolerate links and
  1245. ;; timestamps in comments, node properties, etc.
  1246. (should
  1247. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1248. (let ((org-return-follows-link t)
  1249. (org-link-search-must-match-exact-headline nil))
  1250. (org-return))
  1251. (looking-at-p "<<target>>")))
  1252. (should-not
  1253. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1254. (let ((org-return-follows-link nil)) (org-return))
  1255. (looking-at-p "<<target>>")))
  1256. (should-not
  1257. (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
  1258. (let ((org-return-follows-link t)
  1259. (org-link-search-must-match-exact-headline nil))
  1260. (org-return))
  1261. (looking-at-p "<<target>>")))
  1262. ;; Non-nil `org-return-follows-link' ignores read-only state of
  1263. ;; a buffer.
  1264. (should
  1265. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1266. (let ((org-return-follows-link t)
  1267. (org-link-search-must-match-exact-headline nil))
  1268. (setq buffer-read-only t)
  1269. (call-interactively #'org-return))
  1270. (looking-at-p "<<target>>")))
  1271. ;; `org-return-follows-link' handle multi-line lines.
  1272. (should
  1273. (org-test-with-temp-text
  1274. "[[target][This is a very\n long description<point>]]\n <<target>>"
  1275. (let ((org-return-follows-link t)
  1276. (org-link-search-must-match-exact-headline nil))
  1277. (org-return))
  1278. (looking-at-p "<<target>>")))
  1279. (should-not
  1280. (org-test-with-temp-text
  1281. "[[target][This is a very\n long description]]<point>\n <<target>>"
  1282. (let ((org-return-follows-link t)
  1283. (org-link-search-must-match-exact-headline nil))
  1284. (org-return))
  1285. (looking-at-p "<<target>>")))
  1286. ;; However, do not open link when point is in a table.
  1287. (should
  1288. (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
  1289. (let ((org-return-follows-link t)) (org-return))
  1290. (looking-at-p "between")))
  1291. ;; Special case: in a list, when indenting, do not break structure.
  1292. (should
  1293. (equal "- A\n B"
  1294. (org-test-with-temp-text "- A <point>B"
  1295. (org-return t)
  1296. (buffer-string))))
  1297. (should
  1298. (equal "- A\n\n- B"
  1299. (org-test-with-temp-text "- A\n<point>- B"
  1300. (org-return t)
  1301. (buffer-string))))
  1302. ;; On tags part of a headline, add a newline below it instead of
  1303. ;; breaking it.
  1304. (should
  1305. (equal "* H :tag:\n"
  1306. (org-test-with-temp-text "* H :<point>tag:"
  1307. (org-return)
  1308. (buffer-string))))
  1309. ;; Before headline text, add a newline below it instead of breaking
  1310. ;; it.
  1311. (should
  1312. (equal "* TODO H :tag:\n"
  1313. (org-test-with-temp-text "* <point>TODO H :tag:"
  1314. (org-return)
  1315. (buffer-string))))
  1316. (should
  1317. (equal "* TODO [#B] H :tag:\n"
  1318. (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
  1319. (org-return)
  1320. (buffer-string))))
  1321. (should ;TODO are case-sensitive
  1322. (equal "* \nTodo"
  1323. (org-test-with-temp-text "* <point>Todo"
  1324. (org-return)
  1325. (buffer-string))))
  1326. ;; At headline text, break headline text but preserve tags.
  1327. (should
  1328. (equal "* TODO [#B] foo :tag:\nbar"
  1329. (let (org-auto-align-tags)
  1330. (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
  1331. (org-return)
  1332. (buffer-string)))))
  1333. ;; At bol of headline insert newline.
  1334. (should
  1335. (equal "\n* h"
  1336. (org-test-with-temp-text "<point>* h"
  1337. (org-return)
  1338. (buffer-string))))
  1339. ;; Refuse to leave invalid headline in buffer.
  1340. (should
  1341. (equal "* h\n"
  1342. (org-test-with-temp-text "*<point> h"
  1343. (org-return)
  1344. (buffer-string))))
  1345. ;; Before first column or after last one in a table, split the
  1346. ;; table.
  1347. (should
  1348. (equal "| a |\n\n| b |"
  1349. (org-test-with-temp-text "| a |\n<point>| b |"
  1350. (org-return)
  1351. (buffer-string))))
  1352. (should
  1353. (equal "| a |\n\n| b |"
  1354. (org-test-with-temp-text "| a |<point>\n| b |"
  1355. (org-return)
  1356. (buffer-string))))
  1357. ;; Do not auto-fill on hitting <RET> inside a property drawer.
  1358. (should
  1359. (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:"
  1360. (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:"
  1361. (setq-local fill-column 10)
  1362. (auto-fill-mode 1)
  1363. (org-return)
  1364. (buffer-string)))))
  1365. (ert-deftest test-org/with-electric-indent ()
  1366. "Test RET and C-j specifications with `electric-indent-mode' on."
  1367. ;; Call commands interactively, since this is how `newline' knows it
  1368. ;; must run `post-self-insert-hook'.
  1369. ;;
  1370. ;; RET, like `newline', should indent.
  1371. (should
  1372. (equal " Para\n graph"
  1373. (org-test-with-temp-text " Para<point>graph"
  1374. (electric-indent-local-mode 1)
  1375. (call-interactively 'org-return)
  1376. (buffer-string))))
  1377. (should
  1378. (equal "- item1\n item2"
  1379. (org-test-with-temp-text "- item1<point>item2"
  1380. (electric-indent-local-mode 1)
  1381. (call-interactively 'org-return)
  1382. (buffer-string))))
  1383. ;; TODO: test more values of `org-adapt-indentation'.
  1384. (let ((org-adapt-indentation t))
  1385. (should
  1386. (equal "* heading\n body"
  1387. (org-test-with-temp-text "* heading<point>body"
  1388. (electric-indent-local-mode 1)
  1389. (call-interactively 'org-return)
  1390. (buffer-string)))))
  1391. ;; C-j, like `electric-newline-and-maybe-indent', should not indent.
  1392. (should
  1393. (equal " Para\ngraph"
  1394. (org-test-with-temp-text " Para<point>graph"
  1395. (electric-indent-local-mode 1)
  1396. (call-interactively 'org-return-and-maybe-indent)
  1397. (buffer-string))))
  1398. (should
  1399. (equal "- item1\nitem2"
  1400. (org-test-with-temp-text "- item1<point>item2"
  1401. (electric-indent-local-mode 1)
  1402. (call-interactively 'org-return-and-maybe-indent)
  1403. (buffer-string))))
  1404. ;; TODO: test more values of `org-adapt-indentation'.
  1405. (let ((org-adapt-indentation t))
  1406. (should
  1407. (equal "* heading\nbody"
  1408. (org-test-with-temp-text "* heading<point>body"
  1409. (electric-indent-local-mode 1)
  1410. (call-interactively 'org-return-and-maybe-indent)
  1411. (buffer-string))))))
  1412. (ert-deftest test-org/without-electric-indent ()
  1413. "Test RET and C-j specifications with `electric-indent-mode' off."
  1414. ;; Call commands interactively, since this is how `newline' knows it
  1415. ;; must run `post-self-insert-hook'.
  1416. ;;
  1417. ;; RET, like `newline', should not indent.
  1418. (should
  1419. (equal " Para\ngraph"
  1420. (org-test-with-temp-text " Para<point>graph"
  1421. (electric-indent-local-mode 0)
  1422. (call-interactively 'org-return)
  1423. (buffer-string))))
  1424. (should
  1425. (equal "- item1\nitem2"
  1426. (org-test-with-temp-text "- item1<point>item2"
  1427. (electric-indent-local-mode 0)
  1428. (call-interactively 'org-return)
  1429. (buffer-string))))
  1430. (should
  1431. (equal "* heading\nbody"
  1432. (org-test-with-temp-text "* heading<point>body"
  1433. (electric-indent-local-mode 0)
  1434. (call-interactively 'org-return)
  1435. (buffer-string))))
  1436. ;; C-j, like `electric-newline-and-maybe-indent', should indent.
  1437. (should
  1438. (equal " Para\n graph"
  1439. (org-test-with-temp-text " Para<point>graph"
  1440. (electric-indent-local-mode 0)
  1441. (call-interactively 'org-return-and-maybe-indent)
  1442. (buffer-string))))
  1443. (should
  1444. (equal "- item1\n item2"
  1445. (org-test-with-temp-text "- item1<point>item2"
  1446. (electric-indent-local-mode 0)
  1447. (call-interactively 'org-return-and-maybe-indent)
  1448. (buffer-string))))
  1449. ;; TODO: test more values of `org-adapt-indentation'.
  1450. (let ((org-adapt-indentation t))
  1451. (should
  1452. (equal "* heading\n body"
  1453. (org-test-with-temp-text "* heading<point>body"
  1454. (electric-indent-local-mode 0)
  1455. (call-interactively 'org-return-and-maybe-indent)
  1456. (buffer-string))))))
  1457. (ert-deftest test-org/meta-return ()
  1458. "Test M-RET (`org-meta-return') specifications."
  1459. ;; In a table field insert a row above.
  1460. (should
  1461. (org-test-with-temp-text "| a |"
  1462. (forward-char)
  1463. (org-meta-return)
  1464. (forward-line -1)
  1465. (looking-at "| |$")))
  1466. ;; In a paragraph change current line into a header.
  1467. (should
  1468. (org-test-with-temp-text "a"
  1469. (org-meta-return)
  1470. (beginning-of-line)
  1471. (looking-at "\* a$")))
  1472. ;; In an item insert an item, in this case above.
  1473. (should
  1474. (org-test-with-temp-text "- a"
  1475. (org-meta-return)
  1476. (beginning-of-line)
  1477. (looking-at "- $")))
  1478. ;; In a drawer and item insert an item, in this case above.
  1479. (should
  1480. (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
  1481. (forward-line)
  1482. (org-fold-reveal)
  1483. (org-meta-return)
  1484. (beginning-of-line)
  1485. (looking-at "- $"))))
  1486. (ert-deftest test-org/insert-heading ()
  1487. "Test `org-insert-heading' specifications."
  1488. ;; In an empty buffer, insert a new headline.
  1489. (should
  1490. (equal "* "
  1491. (org-test-with-temp-text ""
  1492. (org-insert-heading)
  1493. (buffer-string))))
  1494. ;; At the beginning of a line, turn it into a headline.
  1495. (should
  1496. (equal "* P"
  1497. (org-test-with-temp-text "<point>P"
  1498. (org-insert-heading)
  1499. (buffer-string))))
  1500. ;; In the middle of a line, split the line if allowed, otherwise,
  1501. ;; insert the headline at its end.
  1502. (should
  1503. (equal "Para\n* graph"
  1504. (org-test-with-temp-text "Para<point>graph"
  1505. (let ((org-M-RET-may-split-line '((default . t))))
  1506. (org-insert-heading))
  1507. (buffer-string))))
  1508. (should
  1509. (equal "Paragraph\n* "
  1510. (org-test-with-temp-text "Para<point>graph"
  1511. (let ((org-M-RET-may-split-line '((default . nil))))
  1512. (org-insert-heading))
  1513. (buffer-string))))
  1514. ;; At the beginning of a headline, create one above.
  1515. (should
  1516. (equal "* \n* H"
  1517. (org-test-with-temp-text "* H"
  1518. (org-insert-heading)
  1519. (buffer-string))))
  1520. ;; In the middle of a headline, split it if allowed.
  1521. (should
  1522. (equal "* H\n* 1"
  1523. (org-test-with-temp-text "* H<point>1"
  1524. (let ((org-M-RET-may-split-line '((headline . t))))
  1525. (org-insert-heading))
  1526. (buffer-string))))
  1527. (should
  1528. (equal "* H1\n* "
  1529. (org-test-with-temp-text "* H<point>1"
  1530. (let ((org-M-RET-may-split-line '((headline . nil))))
  1531. (org-insert-heading))
  1532. (buffer-string))))
  1533. ;; However, splitting cannot happen on TODO keywords, priorities or
  1534. ;; tags.
  1535. (should
  1536. (equal "* TODO H1\n* "
  1537. (org-test-with-temp-text "* TO<point>DO H1"
  1538. (let ((org-M-RET-may-split-line '((headline . t))))
  1539. (org-insert-heading))
  1540. (buffer-string))))
  1541. (should
  1542. (equal "* [#A] H1\n* "
  1543. (org-test-with-temp-text "* [#<point>A] H1"
  1544. (let ((org-M-RET-may-split-line '((headline . t))))
  1545. (org-insert-heading))
  1546. (buffer-string))))
  1547. (should
  1548. (equal "* H1 :tag:\n* "
  1549. (org-test-with-temp-text "* H1 :ta<point>g:"
  1550. (let ((org-M-RET-may-split-line '((headline . t))))
  1551. (org-insert-heading))
  1552. (buffer-string))))
  1553. ;; New headline level depends on the level of the headline above.
  1554. (should
  1555. (equal "** H\n** P"
  1556. (org-test-with-temp-text "** H\n<point>P"
  1557. (org-insert-heading)
  1558. (buffer-string))))
  1559. (should
  1560. (equal "** H\nPara\n** graph"
  1561. (org-test-with-temp-text "** H\nPara<point>graph"
  1562. (let ((org-M-RET-may-split-line '((default . t))))
  1563. (org-insert-heading))
  1564. (buffer-string))))
  1565. (should
  1566. (equal "** \n** H"
  1567. (org-test-with-temp-text "** H"
  1568. (org-insert-heading)
  1569. (buffer-string))))
  1570. ;; When called with one universal argument, insert a new headline at
  1571. ;; the end of the current subtree, independently on the position of
  1572. ;; point.
  1573. (should
  1574. (equal
  1575. "* "
  1576. (org-test-with-temp-text ""
  1577. (let ((org-insert-heading-respect-content nil))
  1578. (org-insert-heading '(4)))
  1579. (buffer-string))))
  1580. (should
  1581. (equal
  1582. "entry
  1583. * "
  1584. (org-test-with-temp-text "entry"
  1585. (let ((org-insert-heading-respect-content nil))
  1586. (org-insert-heading '(4)))
  1587. (buffer-string))))
  1588. (should
  1589. (equal
  1590. "* H1\n** H2\n* "
  1591. (org-test-with-temp-text "* H1\n** H2"
  1592. (let ((org-insert-heading-respect-content nil))
  1593. (org-insert-heading '(4)))
  1594. (buffer-string))))
  1595. (should
  1596. (equal
  1597. "* H1\n** H2\n* "
  1598. (org-test-with-temp-text "* H<point>1\n** H2"
  1599. (let ((org-insert-heading-respect-content nil))
  1600. (org-insert-heading '(4)))
  1601. (buffer-string))))
  1602. ;; When called with two universal arguments, insert a new headline
  1603. ;; at the end of the grandparent subtree.
  1604. (should
  1605. (equal "* H1\n** H3\n- item\n** H2\n** "
  1606. (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
  1607. (let ((org-insert-heading-respect-content nil))
  1608. (org-insert-heading '(16)))
  1609. (buffer-string))))
  1610. ;; When optional TOP-LEVEL argument is non-nil, always insert
  1611. ;; a level 1 heading.
  1612. (should
  1613. (equal "* H1\n** H2\n* "
  1614. (org-test-with-temp-text "* H1\n** H2<point>"
  1615. (org-insert-heading nil nil t)
  1616. (buffer-string))))
  1617. (should
  1618. (equal "* H1\n- item\n* "
  1619. (org-test-with-temp-text "* H1\n- item<point>"
  1620. (org-insert-heading nil nil t)
  1621. (buffer-string))))
  1622. ;; Obey `org-blank-before-new-entry'.
  1623. (should
  1624. (equal "* H1\n\n* "
  1625. (org-test-with-temp-text "* H1<point>"
  1626. (let ((org-blank-before-new-entry '((heading . t))))
  1627. (org-insert-heading))
  1628. (buffer-string))))
  1629. (should
  1630. (equal "* H1\n* "
  1631. (org-test-with-temp-text "* H1<point>"
  1632. (let ((org-blank-before-new-entry '((heading . nil))))
  1633. (org-insert-heading))
  1634. (buffer-string))))
  1635. (should
  1636. (equal "* H1\n* H2\n* "
  1637. (org-test-with-temp-text "* H1\n* H2<point>"
  1638. (let ((org-blank-before-new-entry '((heading . auto))))
  1639. (org-insert-heading))
  1640. (buffer-string))))
  1641. (should
  1642. (equal "* H1\n\n* H2\n\n* "
  1643. (org-test-with-temp-text "* H1\n\n* H2<point>"
  1644. (let ((org-blank-before-new-entry '((heading . auto))))
  1645. (org-insert-heading))
  1646. (buffer-string))))
  1647. ;; Corner case: correctly insert a headline after an empty one.
  1648. (should
  1649. (equal "* \n* "
  1650. (org-test-with-temp-text "* <point>"
  1651. (org-insert-heading)
  1652. (buffer-string))))
  1653. (should
  1654. (org-test-with-temp-text "* <point>\n"
  1655. (org-insert-heading)
  1656. (looking-at-p "\n\\'")))
  1657. ;; Do not insert spurious headlines when inserting a new headline.
  1658. (should
  1659. (equal "* H1\n* H2\n* \n"
  1660. (org-test-with-temp-text "* H1\n* H2<point>\n"
  1661. (org-insert-heading)
  1662. (buffer-string))))
  1663. ;; Preserve visibility at beginning of line. In particular, when
  1664. ;; removing spurious blank lines, do not visually merge heading with
  1665. ;; the line visible above.
  1666. (should-not
  1667. (org-test-with-temp-text "* H1<point>\nContents\n\n* H2\n"
  1668. (org-overview)
  1669. (let ((org-blank-before-new-entry '((heading . nil))))
  1670. (org-insert-heading '(4)))
  1671. (invisible-p (line-end-position 0))))
  1672. ;; Properly handle empty lines when forcing a headline below current
  1673. ;; one.
  1674. (should
  1675. (equal "* H1\n\n* H\n\n* "
  1676. (org-test-with-temp-text "* H1\n\n* H<point>"
  1677. (let ((org-blank-before-new-entry '((heading . t))))
  1678. (org-insert-heading '(4))
  1679. (buffer-string))))))
  1680. (ert-deftest test-org/insert-todo-heading-respect-content ()
  1681. "Test `org-insert-todo-heading-respect-content' specifications."
  1682. ;; Create a TODO heading.
  1683. (should
  1684. (org-test-with-temp-text "* H1\n Body"
  1685. (org-insert-todo-heading-respect-content)
  1686. (nth 2 (org-heading-components))))
  1687. ;; Add headline at the end of the first subtree
  1688. (should
  1689. (equal
  1690. "* TODO "
  1691. (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
  1692. (org-insert-todo-heading-respect-content)
  1693. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1694. ;; In a list, do not create a new item.
  1695. (should
  1696. (equal
  1697. "* TODO "
  1698. (org-test-with-temp-text "* H\n- an item\n- another one"
  1699. (search-forward "an ")
  1700. (org-insert-todo-heading-respect-content)
  1701. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1702. ;; Use the same TODO keyword as current heading.
  1703. (should
  1704. (equal
  1705. "* TODO \n"
  1706. (org-test-with-temp-text "* TODO\n** WAITING\n"
  1707. (org-insert-todo-heading-respect-content)
  1708. (buffer-substring-no-properties (line-beginning-position) (point-max))))))
  1709. (ert-deftest test-org/clone-with-time-shift ()
  1710. "Test `org-clone-subtree-with-time-shift'."
  1711. ;; Raise an error before first heading.
  1712. (should-error
  1713. (org-test-with-temp-text ""
  1714. (org-clone-subtree-with-time-shift 1)))
  1715. ;; Raise an error on invalid number of clones.
  1716. (should-error
  1717. (org-test-with-temp-text "* Clone me"
  1718. (org-clone-subtree-with-time-shift -1)))
  1719. ;; Clone non-repeating once.
  1720. (should
  1721. (equal "\
  1722. * H1\n<2015-06-21>
  1723. * H1\n<2015-06-23>
  1724. "
  1725. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1726. (org-clone-subtree-with-time-shift 1 "+2d")
  1727. (replace-regexp-in-string
  1728. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1729. nil nil 1))))
  1730. ;; Clone repeating once.
  1731. (should
  1732. (equal "\
  1733. * H1\n<2015-06-21>
  1734. * H1\n<2015-06-23>
  1735. * H1\n<2015-06-25 +1w>
  1736. "
  1737. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1738. (org-clone-subtree-with-time-shift 1 "+2d")
  1739. (replace-regexp-in-string
  1740. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1741. nil nil 1))))
  1742. ;; Clone repeating once in backward.
  1743. (should
  1744. (equal "\
  1745. * H1\n<2015-06-21>
  1746. * H1\n<2015-06-19>
  1747. * H1\n<2015-06-17 +1w>
  1748. "
  1749. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1750. (org-clone-subtree-with-time-shift 1 "-2d")
  1751. (replace-regexp-in-string
  1752. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1753. nil nil 1))))
  1754. ;; Clone non-repeating zero times.
  1755. (should
  1756. (equal "\
  1757. * H1\n<2015-06-21>
  1758. "
  1759. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1760. (org-clone-subtree-with-time-shift 0 "+2d")
  1761. (replace-regexp-in-string
  1762. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1763. nil nil 1))))
  1764. ;; Clone repeating "zero" times.
  1765. (should
  1766. (equal "\
  1767. * H1\n<2015-06-21>
  1768. * H1\n<2015-06-23 +1w>
  1769. "
  1770. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1771. (org-clone-subtree-with-time-shift 0 "+2d")
  1772. (replace-regexp-in-string
  1773. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1774. nil nil 1))))
  1775. ;; Clone with blank SHIFT argument.
  1776. (should
  1777. (string-prefix-p
  1778. "* H <2012-03-29"
  1779. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1780. (org-clone-subtree-with-time-shift 1 "")
  1781. (buffer-substring-no-properties (line-beginning-position 2)
  1782. (line-end-position 2)))))
  1783. ;; Find time stamps before point. If SHIFT is not specified, ask
  1784. ;; for a time shift.
  1785. (should
  1786. (string-prefix-p
  1787. "* H <2012-03-30"
  1788. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1789. (org-clone-subtree-with-time-shift 1 "+1d")
  1790. (buffer-substring-no-properties (line-beginning-position 2)
  1791. (line-end-position 2)))))
  1792. (should
  1793. (string-prefix-p
  1794. "* H <2014-03-05"
  1795. (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
  1796. (cl-letf (((symbol-function 'read-from-minibuffer)
  1797. (lambda (&rest args) "+1d")))
  1798. (org-clone-subtree-with-time-shift 1))
  1799. (buffer-substring-no-properties (line-beginning-position 2)
  1800. (line-end-position 2)))))
  1801. ;; Hour shift.
  1802. (should
  1803. (equal "\
  1804. * H1\n<2015-06-21 20:00>
  1805. * H1\n<2015-06-21 23:00>
  1806. * H1\n<2015-06-22 02:00>
  1807. "
  1808. (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>"
  1809. (org-clone-subtree-with-time-shift 2 "+3h")
  1810. (replace-regexp-in-string
  1811. "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" ""
  1812. (buffer-substring-no-properties (point-min) (point-max))
  1813. nil nil 1))))
  1814. (should
  1815. (equal "\
  1816. * H1\n<2015-06-21 20:00>
  1817. * H1\n<2015-06-21 18:00>
  1818. "
  1819. (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>"
  1820. (org-clone-subtree-with-time-shift 1 "-2h")
  1821. (replace-regexp-in-string
  1822. "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" ""
  1823. (buffer-substring-no-properties (point-min) (point-max))
  1824. nil nil 1)))))
  1825. ;;; Fixed-Width Areas
  1826. (ert-deftest test-org/toggle-fixed-width ()
  1827. "Test `org-toggle-fixed-width' specifications."
  1828. ;; No region: Toggle on fixed-width marker in paragraphs.
  1829. (should
  1830. (equal ": A"
  1831. (org-test-with-temp-text "A"
  1832. (org-toggle-fixed-width)
  1833. (buffer-string))))
  1834. ;; No region: Toggle off fixed-width markers in fixed-width areas.
  1835. (should
  1836. (equal "A"
  1837. (org-test-with-temp-text ": A"
  1838. (org-toggle-fixed-width)
  1839. (buffer-string))))
  1840. ;; No region: Toggle on marker in blank lines after elements or just
  1841. ;; after a headline.
  1842. (should
  1843. (equal "* H\n: "
  1844. (org-test-with-temp-text "* H\n"
  1845. (forward-line)
  1846. (org-toggle-fixed-width)
  1847. (buffer-string))))
  1848. (should
  1849. (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
  1850. (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
  1851. (goto-char (point-max))
  1852. (org-toggle-fixed-width)
  1853. (buffer-string))))
  1854. ;; No region: Toggle on marker in front of one line elements (e.g.,
  1855. ;; headlines, clocks)
  1856. (should
  1857. (equal ": * Headline"
  1858. (org-test-with-temp-text "* Headline"
  1859. (org-toggle-fixed-width)
  1860. (buffer-string))))
  1861. (should
  1862. (equal ": #+KEYWORD: value"
  1863. (org-test-with-temp-text "#+KEYWORD: value"
  1864. (org-toggle-fixed-width)
  1865. (buffer-string))))
  1866. ;; No region: error in other situations.
  1867. (should-error
  1868. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
  1869. (forward-line)
  1870. (org-toggle-fixed-width)
  1871. (buffer-string)))
  1872. ;; No region: Indentation is preserved.
  1873. (should
  1874. (equal "- A\n : B"
  1875. (org-test-with-temp-text "- A\n B"
  1876. (forward-line)
  1877. (org-toggle-fixed-width)
  1878. (buffer-string))))
  1879. ;; Region: If it contains only fixed-width elements and blank lines,
  1880. ;; toggle off fixed-width markup.
  1881. (should
  1882. (equal "A\n\nB"
  1883. (org-test-with-temp-text ": A\n\n: B"
  1884. (transient-mark-mode 1)
  1885. (push-mark (point) t t)
  1886. (goto-char (point-max))
  1887. (org-toggle-fixed-width)
  1888. (buffer-string))))
  1889. ;; Region: If it contains anything else, toggle on fixed-width but
  1890. ;; not on fixed-width areas.
  1891. (should
  1892. (equal ": A\n: \n: B\n: \n: C"
  1893. (org-test-with-temp-text "A\n\n: B\n\nC"
  1894. (transient-mark-mode 1)
  1895. (push-mark (point) t t)
  1896. (goto-char (point-max))
  1897. (org-toggle-fixed-width)
  1898. (buffer-string))))
  1899. ;; Region: Ignore blank lines at its end, unless it contains only
  1900. ;; such lines.
  1901. (should
  1902. (equal ": A\n\n"
  1903. (org-test-with-temp-text "A\n\n"
  1904. (transient-mark-mode 1)
  1905. (push-mark (point) t t)
  1906. (goto-char (point-max))
  1907. (org-toggle-fixed-width)
  1908. (buffer-string))))
  1909. (should
  1910. (equal ": \n: \n"
  1911. (org-test-with-temp-text "\n\n"
  1912. (transient-mark-mode 1)
  1913. (push-mark (point) t t)
  1914. (goto-char (point-max))
  1915. (org-toggle-fixed-width)
  1916. (buffer-string)))))
  1917. (ert-deftest test-org/kill-line ()
  1918. "Test `org-kill-line' specifications."
  1919. ;; At the beginning of a line, kill whole line.
  1920. (should
  1921. (equal ""
  1922. (org-test-with-temp-text "abc"
  1923. (org-kill-line)
  1924. (buffer-string))))
  1925. ;; In the middle of a line, kill line until its end.
  1926. (should
  1927. (equal "a"
  1928. (org-test-with-temp-text "a<point>bc"
  1929. (org-kill-line)
  1930. (buffer-string))))
  1931. ;; Do not kill newline character.
  1932. (should
  1933. (equal "\n123"
  1934. (org-test-with-temp-text "abc\n123"
  1935. (org-kill-line)
  1936. (buffer-string))))
  1937. (should
  1938. (equal "a\n123"
  1939. (org-test-with-temp-text "a<point>bc\n123"
  1940. (org-kill-line)
  1941. (buffer-string))))
  1942. ;; When `org-special-ctrl-k' is non-nil and point is at a headline,
  1943. ;; kill until tags.
  1944. (should
  1945. (equal "* A :tag:"
  1946. (org-test-with-temp-text "* A<point>B :tag:"
  1947. (let ((org-special-ctrl-k t)
  1948. (org-tags-column 0))
  1949. (org-kill-line))
  1950. (buffer-string))))
  1951. ;; If point is on tags, only kill part left until the end of line.
  1952. (should
  1953. (equal "* A :tag:"
  1954. (org-test-with-temp-text "* A :tag:<point>tag2:"
  1955. (let ((org-special-ctrl-k t)
  1956. (org-tags-column 0))
  1957. (org-kill-line))
  1958. (buffer-string))))
  1959. ;; However, if point is at the beginning of the line, kill whole
  1960. ;; headline.
  1961. (should
  1962. (equal ""
  1963. (org-test-with-temp-text "* AB :tag:"
  1964. (let ((org-special-ctrl-k t)
  1965. (org-tags-column 0))
  1966. (org-kill-line))
  1967. (buffer-string))))
  1968. ;; When `org-ctrl-k-protect-subtree' is non-nil, and point is in
  1969. ;; invisible text, ask before removing it. When set to `error',
  1970. ;; throw an error.
  1971. (should-error
  1972. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  1973. (org-overview)
  1974. (let ((org-special-ctrl-k nil)
  1975. (org-ctrl-k-protect-subtree t))
  1976. (cl-letf (((symbol-function 'y-or-n-p) 'ignore))
  1977. (org-kill-line)))))
  1978. (should-error
  1979. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  1980. (org-overview)
  1981. (let ((org-special-ctrl-k nil)
  1982. (org-ctrl-k-protect-subtree 'error))
  1983. (org-kill-line)))))
  1984. ;;; Headline
  1985. (ert-deftest test-org/get-heading ()
  1986. "Test `org-get-heading' specifications."
  1987. ;; Return current heading, even if point is not on it.
  1988. (should
  1989. (equal "H"
  1990. (org-test-with-temp-text "* H"
  1991. (org-get-heading))))
  1992. (should
  1993. (equal "H"
  1994. (org-test-with-temp-text "* H\nText<point>"
  1995. (org-get-heading))))
  1996. ;; Without any optional argument, return TODO keyword, priority
  1997. ;; cookie, COMMENT keyword and tags.
  1998. (should
  1999. (equal "TODO H"
  2000. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2001. (org-get-heading))))
  2002. (should
  2003. (equal "[#A] H"
  2004. (org-test-with-temp-text "* [#A] H"
  2005. (org-get-heading))))
  2006. (should
  2007. (equal "COMMENT H"
  2008. (org-test-with-temp-text "* COMMENT H"
  2009. (org-get-heading))))
  2010. (should
  2011. (equal "H :tag:"
  2012. (org-test-with-temp-text "* H :tag:"
  2013. (org-get-heading))))
  2014. ;; With NO-TAGS argument, ignore tags.
  2015. (should
  2016. (equal "TODO H"
  2017. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2018. (org-get-heading t))))
  2019. (should
  2020. (equal "H"
  2021. (org-test-with-temp-text "* H :tag:"
  2022. (org-get-heading t))))
  2023. ;; With NO-TODO, ignore TODO keyword.
  2024. (should
  2025. (equal "H"
  2026. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2027. (org-get-heading nil t))))
  2028. (should
  2029. (equal "H :tag:"
  2030. (org-test-with-temp-text "* H :tag:"
  2031. (org-get-heading nil t))))
  2032. ;; TODO keywords are case-sensitive.
  2033. (should
  2034. (equal "Todo H"
  2035. (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
  2036. (org-get-heading nil t))))
  2037. ;; With NO-PRIORITY, ignore priority.
  2038. (should
  2039. (equal "H"
  2040. (org-test-with-temp-text "* [#A] H"
  2041. (org-get-heading nil nil t))))
  2042. (should
  2043. (equal "H"
  2044. (org-test-with-temp-text "* H"
  2045. (org-get-heading nil nil t))))
  2046. (should
  2047. (equal "TODO H"
  2048. (org-test-with-temp-text "* TODO [#A] H"
  2049. (org-get-heading nil nil t))))
  2050. ;; With NO-COMMENT, ignore COMMENT keyword.
  2051. (should
  2052. (equal "H"
  2053. (org-test-with-temp-text "* COMMENT H"
  2054. (org-get-heading nil nil nil t))))
  2055. (should
  2056. (equal "H"
  2057. (org-test-with-temp-text "* H"
  2058. (org-get-heading nil nil nil t))))
  2059. (should
  2060. (equal "TODO [#A] H"
  2061. (org-test-with-temp-text "* TODO [#A] COMMENT H"
  2062. (org-get-heading nil nil nil t))))
  2063. ;; On an empty headline, return value is consistent.
  2064. (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
  2065. (should (equal "" (org-test-with-temp-text "* " (org-get-heading t))))
  2066. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t))))
  2067. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t))))
  2068. (should
  2069. (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t)))))
  2070. (ert-deftest test-org/in-commented-heading-p ()
  2071. "Test `org-in-commented-heading-p' specifications."
  2072. ;; Commented headline.
  2073. (should
  2074. (org-test-with-temp-text "* COMMENT Headline\nBody"
  2075. (goto-char (point-max))
  2076. (org-in-commented-heading-p)))
  2077. ;; Commented ancestor.
  2078. (should
  2079. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  2080. (goto-char (point-max))
  2081. (org-in-commented-heading-p)))
  2082. ;; Comment keyword is case-sensitive.
  2083. (should-not
  2084. (org-test-with-temp-text "* Comment Headline\nBody"
  2085. (goto-char (point-max))
  2086. (org-in-commented-heading-p)))
  2087. ;; Keyword is standalone.
  2088. (should-not
  2089. (org-test-with-temp-text "* COMMENTHeadline\nBody"
  2090. (goto-char (point-max))
  2091. (org-in-commented-heading-p)))
  2092. ;; Optional argument.
  2093. (should-not
  2094. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  2095. (goto-char (point-max))
  2096. (org-in-commented-heading-p t))))
  2097. (ert-deftest test-org/in-archived-heading-p ()
  2098. "Test `org-in-archived-heading-p' specifications."
  2099. ;; Archived headline.
  2100. (should
  2101. (org-test-with-temp-text "* Headline :ARCHIVE:\nBody"
  2102. (goto-char (point-max))
  2103. (org-in-archived-heading-p)))
  2104. ;; Archived ancestor.
  2105. (should
  2106. (org-test-with-temp-text "* Headline :ARCHIVE:\n** Level 2\nBody"
  2107. (goto-char (point-max))
  2108. (org-in-archived-heading-p)))
  2109. ;; Optional argument.
  2110. (should-not
  2111. (org-test-with-temp-text "* Headline :ARCHIVE:\n** Level 2\nBody"
  2112. (goto-char (point-max))
  2113. (org-in-archived-heading-p t)))
  2114. ;; Archive tag containing ARCHIVE as substring
  2115. (should-not
  2116. (org-test-with-temp-text "* Headline :NOARCHIVE:\n** Level 2\nBody"
  2117. (goto-char (point-max))
  2118. (org-in-archived-heading-p))))
  2119. (ert-deftest test-org/entry-blocked-p ()
  2120. ;; Check other dependencies.
  2121. (should
  2122. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  2123. (let ((org-enforce-todo-dependencies t)
  2124. (org-blocker-hook
  2125. '(org-block-todo-from-children-or-siblings-or-parent)))
  2126. (org-entry-blocked-p))))
  2127. (should-not
  2128. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  2129. (let ((org-enforce-todo-dependencies t)
  2130. (org-blocker-hook
  2131. '(org-block-todo-from-children-or-siblings-or-parent)))
  2132. (org-entry-blocked-p))))
  2133. ;; Entry without a TODO keyword or with a DONE keyword cannot be
  2134. ;; blocked.
  2135. (should-not
  2136. (org-test-with-temp-text "* Blocked\n** TODO one"
  2137. (let ((org-enforce-todo-dependencies t)
  2138. (org-blocker-hook
  2139. '(org-block-todo-from-children-or-siblings-or-parent)))
  2140. (org-entry-blocked-p))))
  2141. (should-not
  2142. (org-test-with-temp-text "* DONE Blocked\n** TODO one"
  2143. (let ((org-enforce-todo-dependencies t)
  2144. (org-blocker-hook
  2145. '(org-block-todo-from-children-or-siblings-or-parent)))
  2146. (org-entry-blocked-p))))
  2147. ;; Follow :ORDERED: specifications.
  2148. (should
  2149. (org-test-with-temp-text
  2150. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
  2151. (let ((org-enforce-todo-dependencies t)
  2152. (org-blocker-hook
  2153. '(org-block-todo-from-children-or-siblings-or-parent)))
  2154. (org-entry-blocked-p))))
  2155. (should-not
  2156. (org-test-with-temp-text
  2157. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
  2158. (let ((org-enforce-todo-dependencies t)
  2159. (org-blocker-hook
  2160. '(org-block-todo-from-children-or-siblings-or-parent)))
  2161. (org-entry-blocked-p)))))
  2162. (ert-deftest test-org/get-outline-path ()
  2163. "Test `org-get-outline-path' specifications."
  2164. ;; Top-level headlines have no outline path.
  2165. (should-not
  2166. (org-test-with-temp-text "* H"
  2167. (org-get-outline-path)))
  2168. ;; Otherwise, outline path is the path leading to the headline.
  2169. (should
  2170. (equal '("H")
  2171. (org-test-with-temp-text "* H\n** S<point>"
  2172. (org-get-outline-path))))
  2173. ;; Find path even when point is not on a headline.
  2174. (should
  2175. (equal '("H")
  2176. (org-test-with-temp-text "* H\n** S\nText<point>"
  2177. (org-get-outline-path))))
  2178. ;; TODO keywords, tags and statistics cookies are ignored.
  2179. (should
  2180. (equal '("H")
  2181. (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
  2182. (org-get-outline-path))))
  2183. ;; Links are replaced with their description or their path.
  2184. (should
  2185. (equal '("Org")
  2186. (org-test-with-temp-text
  2187. "* [[https://orgmode.org][Org]]\n** S<point>"
  2188. (org-get-outline-path))))
  2189. (should
  2190. (equal '("https://orgmode.org")
  2191. (org-test-with-temp-text
  2192. "* [[https://orgmode.org]]\n** S<point>"
  2193. (org-get-outline-path))))
  2194. ;; When WITH-SELF is non-nil, include current heading.
  2195. (should
  2196. (equal '("H")
  2197. (org-test-with-temp-text "* H"
  2198. (org-get-outline-path t))))
  2199. (should
  2200. (equal '("H" "S")
  2201. (org-test-with-temp-text "* H\n** S\nText<point>"
  2202. (org-get-outline-path t))))
  2203. ;; Using cache is transparent to the user.
  2204. (should
  2205. (equal '("H")
  2206. (org-test-with-temp-text "* H\n** S<point>"
  2207. (setq org-outline-path-cache nil)
  2208. (org-get-outline-path nil t))))
  2209. ;; Do not corrupt cache when finding outline path in distant part of
  2210. ;; the buffer.
  2211. (should
  2212. (equal '("H2")
  2213. (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
  2214. (setq org-outline-path-cache nil)
  2215. (org-get-outline-path nil t)
  2216. (search-forward "S2")
  2217. (org-get-outline-path nil t))))
  2218. ;; Do not choke on empty headlines.
  2219. (should
  2220. (org-test-with-temp-text "* H\n** <point>"
  2221. (org-get-outline-path)))
  2222. (should
  2223. (org-test-with-temp-text "* \n** H<point>"
  2224. (org-get-outline-path))))
  2225. (ert-deftest test-org/format-outline-path ()
  2226. "Test `org-format-outline-path' specifications."
  2227. (should
  2228. (string= (org-format-outline-path (list "one" "two" "three"))
  2229. "one/two/three"))
  2230. ;; Empty path.
  2231. (should
  2232. (string= (org-format-outline-path '())
  2233. ""))
  2234. (should
  2235. (string= (org-format-outline-path '(nil))
  2236. ""))
  2237. ;; Empty path and prefix.
  2238. (should
  2239. (string= (org-format-outline-path '() nil ">>")
  2240. ">>"))
  2241. ;; Trailing whitespace in headings.
  2242. (should
  2243. (string= (org-format-outline-path (list "one\t" "tw o " "three "))
  2244. "one/tw o/three"))
  2245. ;; Non-default prefix and separators.
  2246. (should
  2247. (string= (org-format-outline-path (list "one" "two" "three") nil ">>" "|")
  2248. ">>|one|two|three"))
  2249. ;; Truncate.
  2250. (should
  2251. (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
  2252. "one/two/.."))
  2253. ;; Give a very narrow width.
  2254. (should
  2255. (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
  2256. "on"))
  2257. ;; Give a prefix that extends beyond the width.
  2258. (should
  2259. (string= (org-format-outline-path (list "one" "two" "three" "four") 10
  2260. ">>>>>>>>>>")
  2261. ">>>>>>>>..")))
  2262. (ert-deftest test-org/org-find-olp ()
  2263. "Test `org-find-olp' specifications."
  2264. (org-test-with-temp-text
  2265. "
  2266. * Headline
  2267. ** COMMENT headline2
  2268. ** TODO headline3
  2269. *** [#A] headline4 :tags:
  2270. ** [#A]headline5
  2271. ** [0%] headline6
  2272. ** headline7 [100%]
  2273. ** headline8 [1/5] :some:more:tags:
  2274. * Test
  2275. "
  2276. (should (org-find-olp '("Headline") t))
  2277. (should-error (org-find-olp '("Headline" "Test") t))
  2278. (should-error (org-find-olp '("Headlinealksjd") t))
  2279. (should (org-find-olp '("Headline" "headline2") t))
  2280. (should (org-find-olp '("Headline" "headline3") t))
  2281. (should (org-find-olp '("Headline" "headline3" "headline4") t))
  2282. (should-error (org-find-olp '("Headline" "headline5") t))
  2283. (should (org-find-olp '("Headline" "headline6") t))
  2284. (should (org-find-olp '("Headline" "headline7") t))
  2285. (should (org-find-olp '("Headline" "headline8") t))))
  2286. (ert-deftest test-org/map-entries ()
  2287. "Test `org-map-entries' specifications."
  2288. ;; Full match.
  2289. (should
  2290. (equal '(1 11)
  2291. (org-test-with-temp-text "* Level 1\n** Level 2"
  2292. (org-map-entries #'point))))
  2293. ;; Level match.
  2294. (should
  2295. (equal '(1)
  2296. (org-test-with-temp-text "* Level 1\n** Level 2"
  2297. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL=1")))))
  2298. (should
  2299. (equal '(11)
  2300. (org-test-with-temp-text "* Level 1\n** Level 2"
  2301. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL>1")))))
  2302. ;; Tag match.
  2303. (should
  2304. (equal '(11)
  2305. (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
  2306. (org-map-entries #'point "yes"))))
  2307. (should
  2308. (equal '(14)
  2309. (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
  2310. (org-map-entries #'point "+yes-a"))))
  2311. (should
  2312. (equal '(11 23)
  2313. (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
  2314. (org-map-entries #'point "{yes?}"))))
  2315. ;; Priority match.
  2316. (should
  2317. (equal '(1)
  2318. (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
  2319. (org-map-entries #'point "PRIORITY=\"A\""))))
  2320. ;; Date match.
  2321. (should
  2322. (equal '(36)
  2323. (org-test-with-temp-text "
  2324. * H1
  2325. SCHEDULED: <2012-03-29 thu.>
  2326. * H2
  2327. SCHEDULED: <2014-03-04 tue.>"
  2328. (org-map-entries #'point "SCHEDULED=\"<2014-03-04 tue.>\""))))
  2329. (should
  2330. (equal '(2)
  2331. (org-test-with-temp-text "
  2332. * H1
  2333. SCHEDULED: <2012-03-29 thu.>
  2334. * H2
  2335. SCHEDULED: <2014-03-04 tue.>"
  2336. (org-map-entries #'point "SCHEDULED<\"<2013-01-01>\""))))
  2337. ;; Regular property match.
  2338. (should
  2339. (equal '(2)
  2340. (org-test-with-temp-text "
  2341. * H1
  2342. :PROPERTIES:
  2343. :TEST: 1
  2344. :END:
  2345. * H2
  2346. :PROPERTIES:
  2347. :TEST: 2
  2348. :END:"
  2349. (org-map-entries #'point "TEST=1"))))
  2350. ;; Multiple criteria.
  2351. (should
  2352. (equal '(23)
  2353. (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
  2354. (let (org-odd-levels-only
  2355. (org-use-tag-inheritance nil))
  2356. (org-map-entries #'point "yes+LEVEL=1")))))
  2357. ;; "or" criteria.
  2358. (should
  2359. (equal '(12 24)
  2360. (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
  2361. (let (org-odd-levels-only)
  2362. (org-map-entries #'point "LEVEL=2|no")))))
  2363. (should
  2364. (equal '(1 12)
  2365. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
  2366. (let (org-odd-levels-only)
  2367. (org-map-entries #'point "yes|no")))))
  2368. ;; "and" criteria.
  2369. (should
  2370. (equal '(22)
  2371. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
  2372. (let (org-odd-levels-only)
  2373. (org-map-entries #'point "yes&no")))))
  2374. ;; Setting `org-map-continue-from'
  2375. (should
  2376. (string= ""
  2377. (org-test-with-temp-text "* H1\n* H2\n* H3n* H4"
  2378. (org-map-entries
  2379. (lambda ()
  2380. (org-cut-subtree)
  2381. (setq org-map-continue-from (point))))
  2382. (buffer-string))))
  2383. (should
  2384. (string= "* H1\n* H2\n* H3\n"
  2385. (org-test-with-temp-text "* H1\n* H2\n* H3\n* H4"
  2386. (org-map-entries
  2387. (lambda ()
  2388. (when (string= "H4"
  2389. (org-element-property
  2390. :raw-value (org-element-at-point)))
  2391. (org-cut-subtree)
  2392. (setq org-map-continue-from
  2393. (org-element-property
  2394. :begin (org-element-at-point))))))
  2395. (buffer-string)))))
  2396. (ert-deftest test-org/edit-headline ()
  2397. "Test `org-edit-headline' specifications."
  2398. (should
  2399. (equal "* B"
  2400. (org-test-with-temp-text "* A"
  2401. (org-edit-headline "B")
  2402. (buffer-string))))
  2403. ;; Handle empty headings.
  2404. (should
  2405. (equal "* "
  2406. (org-test-with-temp-text "* A"
  2407. (org-edit-headline "")
  2408. (buffer-string))))
  2409. (should
  2410. (equal "* A"
  2411. (org-test-with-temp-text "* "
  2412. (org-edit-headline "A")
  2413. (buffer-string))))
  2414. ;; Handle TODO keywords and priority cookies.
  2415. (should
  2416. (equal "* TODO B"
  2417. (org-test-with-temp-text "* TODO A"
  2418. (org-edit-headline "B")
  2419. (buffer-string))))
  2420. (should
  2421. (equal "* [#A] B"
  2422. (org-test-with-temp-text "* [#A] A"
  2423. (org-edit-headline "B")
  2424. (buffer-string))))
  2425. (should
  2426. (equal "* TODO [#A] B"
  2427. (org-test-with-temp-text "* TODO [#A] A"
  2428. (org-edit-headline "B")
  2429. (buffer-string))))
  2430. ;; Handle tags.
  2431. (equal "* B :tag:"
  2432. (org-test-with-temp-text "* A :tag:"
  2433. (let ((org-tags-column 4)) (org-edit-headline "B"))
  2434. (buffer-string))))
  2435. ;;; Keywords
  2436. (ert-deftest test-org/set-regexps-and-options ()
  2437. "Test `org-set-regexps-and-options' specifications."
  2438. ;; TAGS keyword.
  2439. (should
  2440. (equal '(("A"))
  2441. (let ((org-tag-alist '(("A")))
  2442. (org-tag-persistent-alist nil))
  2443. (org-test-with-temp-text ""
  2444. (org-mode-restart)
  2445. org-current-tag-alist))))
  2446. (should
  2447. (equal '(("B"))
  2448. (let ((org-tag-alist '(("A")))
  2449. (org-tag-persistent-alist nil))
  2450. (org-test-with-temp-text "#+TAGS: B"
  2451. (org-mode-restart)
  2452. org-current-tag-alist))))
  2453. (should
  2454. (equal '(("C") ("B"))
  2455. (let ((org-tag-alist '(("A")))
  2456. (org-tag-persistent-alist '(("C"))))
  2457. (org-test-with-temp-text "#+TAGS: B"
  2458. (org-mode-restart)
  2459. org-current-tag-alist))))
  2460. (should
  2461. (equal '(("B"))
  2462. (let ((org-tag-alist '(("A")))
  2463. (org-tag-persistent-alist '(("C"))))
  2464. (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
  2465. (org-mode-restart)
  2466. org-current-tag-alist))))
  2467. (should
  2468. (equal '(("A" . ?a) ("B") ("C"))
  2469. (let ((org-tag-persistant-alist nil))
  2470. (org-test-with-temp-text "#+TAGS: A(a) B C"
  2471. (org-mode-restart)
  2472. org-current-tag-alist))))
  2473. (should
  2474. (equal '(("A") (:newline) ("B"))
  2475. (let ((org-tag-persistent-alist nil))
  2476. (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
  2477. (org-mode-restart)
  2478. org-current-tag-alist))))
  2479. (should
  2480. (equal '((:startgroup) ("A") ("B") (:endgroup) ("C"))
  2481. (let ((org-tag-persistent-alist nil))
  2482. (org-test-with-temp-text "#+TAGS: { A B } C"
  2483. (org-mode-restart)
  2484. org-current-tag-alist))))
  2485. (should
  2486. (equal '((:startgroup) ("A") (:grouptags) ("B") ("C") (:endgroup))
  2487. (let ((org-tag-persistent-alist nil))
  2488. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2489. (org-mode-restart)
  2490. org-current-tag-alist))))
  2491. (should
  2492. (equal '(("A" "B" "C"))
  2493. (let ((org-tag-persistent-alist nil))
  2494. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2495. (org-mode-restart)
  2496. org-tag-groups-alist))))
  2497. (should
  2498. (equal '((:startgrouptag) ("A") (:grouptags) ("B") ("C") (:endgrouptag))
  2499. (let ((org-tag-persistent-alist nil))
  2500. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2501. (org-mode-restart)
  2502. org-current-tag-alist))))
  2503. (should
  2504. (equal '(("A" "B" "C"))
  2505. (let ((org-tag-persistent-alist nil))
  2506. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2507. (org-mode-restart)
  2508. org-tag-groups-alist))))
  2509. (should-not
  2510. (let ((org-tag-alist '(("A"))))
  2511. (org-test-with-temp-text "#+TAGS:"
  2512. (org-mode-restart)
  2513. org-current-tag-alist)))
  2514. ;; FILETAGS keyword.
  2515. (should
  2516. (equal '("A" "B" "C")
  2517. (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
  2518. (org-mode-restart)
  2519. org-file-tags)))
  2520. ;; PROPERTY keyword. Property names are case-insensitive.
  2521. (should
  2522. (equal "foo=1"
  2523. (org-test-with-temp-text "#+PROPERTY: var foo=1"
  2524. (org-mode-restart)
  2525. (cdr (assoc "var" org-keyword-properties)))))
  2526. (should
  2527. (equal
  2528. "foo=1 bar=2"
  2529. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
  2530. (org-mode-restart)
  2531. (cdr (assoc "var" org-keyword-properties)))))
  2532. (should
  2533. (equal
  2534. "foo=1 bar=2"
  2535. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
  2536. (org-mode-restart)
  2537. (cdr (assoc "var" org-keyword-properties)))))
  2538. ;; ARCHIVE keyword.
  2539. (should
  2540. (equal "%s_done::"
  2541. (org-test-with-temp-text "#+ARCHIVE: %s_done::"
  2542. (org-mode-restart)
  2543. org-archive-location)))
  2544. ;; CATEGORY keyword.
  2545. (should
  2546. (eq 'test
  2547. (org-test-with-temp-text "#+CATEGORY: test"
  2548. (org-mode-restart)
  2549. org-category)))
  2550. (should
  2551. (equal "test"
  2552. (org-test-with-temp-text "#+CATEGORY: test"
  2553. (org-mode-restart)
  2554. (cdr (assoc "CATEGORY" org-keyword-properties)))))
  2555. ;; COLUMNS keyword.
  2556. (should
  2557. (equal "%25ITEM %TAGS %PRIORITY %TODO"
  2558. (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
  2559. (org-mode-restart)
  2560. org-columns-default-format)))
  2561. ;; CONSTANTS keyword. Constants names are case sensitive.
  2562. (should
  2563. (equal '("299792458." "3.14")
  2564. (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
  2565. (org-mode-restart)
  2566. (mapcar
  2567. (lambda (n) (cdr (assoc n org-table-formula-constants-local)))
  2568. '("c" "pi")))))
  2569. (should
  2570. (equal "3.14"
  2571. (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
  2572. (org-mode-restart)
  2573. (cdr (assoc "pi" org-table-formula-constants-local)))))
  2574. (should
  2575. (equal "22/7"
  2576. (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
  2577. (org-mode-restart)
  2578. (cdr (assoc "PI" org-table-formula-constants-local)))))
  2579. ;; LINK keyword.
  2580. (should
  2581. (equal
  2582. '("url1" "url2")
  2583. (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
  2584. (org-mode-restart)
  2585. (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local)))
  2586. '("a" "b")))))
  2587. ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
  2588. (should
  2589. (equal
  2590. '(?X ?Z ?Y)
  2591. (org-test-with-temp-text "#+PRIORITIES: X Z Y"
  2592. (org-mode-restart)
  2593. (list org-priority-highest org-priority-lowest org-priority-default))))
  2594. (should
  2595. (equal
  2596. '(?A ?C ?B)
  2597. (org-test-with-temp-text "#+PRIORITIES: X Z"
  2598. (org-mode-restart)
  2599. (list org-priority-highest org-priority-lowest org-priority-default))))
  2600. ;; STARTUP keyword.
  2601. (should
  2602. (equal '(t t)
  2603. (org-test-with-temp-text "#+STARTUP: fold odd"
  2604. (org-mode-restart)
  2605. (list org-startup-folded org-odd-levels-only))))
  2606. ;; TODO keywords.
  2607. (should
  2608. (equal '(("A" "B") ("C"))
  2609. (org-test-with-temp-text "#+TODO: A B | C"
  2610. (org-mode-restart)
  2611. (list org-not-done-keywords org-done-keywords))))
  2612. (should
  2613. (equal '(("A" "C") ("B" "D"))
  2614. (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
  2615. (org-mode-restart)
  2616. (list org-not-done-keywords org-done-keywords))))
  2617. (should
  2618. (equal '(("A" "B") ("C"))
  2619. (org-test-with-temp-text "#+TYP_TODO: A B | C"
  2620. (org-mode-restart)
  2621. (list org-not-done-keywords org-done-keywords))))
  2622. (should
  2623. (equal '((:startgroup) ("A" . ?a) (:endgroup))
  2624. (org-test-with-temp-text "#+TODO: A(a)"
  2625. (org-mode-restart)
  2626. org-todo-key-alist)))
  2627. (should
  2628. (equal '(("D" note nil) ("C" time nil) ("B" note time))
  2629. (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
  2630. (org-mode-restart)
  2631. org-todo-log-states)))
  2632. ;; Enter SETUPFILE keyword.
  2633. (should
  2634. (equal "1"
  2635. (org-test-with-temp-text
  2636. (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
  2637. (org-mode-restart)
  2638. (cdr (assoc "a" org-keyword-properties))))))
  2639. (ert-deftest test-org/collect-keywords ()
  2640. "Test `org-collect-keywords'."
  2641. (should-not
  2642. (org-test-with-temp-text "#+begin_example\n#+foo: bar\n#+end_example"
  2643. (org-collect-keywords '("FOO")))))
  2644. ;;; Links
  2645. ;;;; Coderefs
  2646. (ert-deftest test-org/coderef ()
  2647. "Test coderef links specifications."
  2648. (should
  2649. (org-test-with-temp-text "
  2650. #+BEGIN_SRC emacs-lisp
  2651. \(+ 1 1) (ref:sc)
  2652. #+END_SRC
  2653. \[[(sc)<point>]]"
  2654. (org-open-at-point)
  2655. (looking-at "(ref:sc)")))
  2656. ;; Find coderef even with alternate label format.
  2657. (should
  2658. (org-test-with-temp-text "
  2659. #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
  2660. \(+ 1 1) {ref:sc}
  2661. #+END_SRC
  2662. \[[(sc)<point>]]"
  2663. (org-open-at-point)
  2664. (looking-at "{ref:sc}"))))
  2665. ;;;; Custom ID
  2666. (ert-deftest test-org/custom-id ()
  2667. "Test custom ID links specifications."
  2668. (should
  2669. (org-test-with-temp-text
  2670. "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2671. (org-open-at-point)
  2672. (looking-at-p "\\* H1")))
  2673. ;; Handle escape characters.
  2674. (should
  2675. (org-test-with-temp-text
  2676. "* H1\n:PROPERTIES:\n:CUSTOM_ID: [%]\n:END:\n* H2\n[[#\\[%\\]<point>]]"
  2677. (org-open-at-point)
  2678. (looking-at-p "\\* H1")))
  2679. ;; Throw an error on false positives.
  2680. (should-error
  2681. (org-test-with-temp-text
  2682. "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2683. (org-open-at-point)
  2684. (looking-at-p "\\* H1"))))
  2685. ;;;; Fuzzy Links
  2686. ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
  2687. ;; a named element (#+name: text) and to headlines (* Text).
  2688. (ert-deftest test-org/fuzzy-links ()
  2689. "Test fuzzy links specifications."
  2690. ;; Fuzzy link goes in priority to a matching target.
  2691. (should
  2692. (org-test-with-temp-text
  2693. "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
  2694. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2695. (looking-at "<<Test>>")))
  2696. ;; Then fuzzy link points to an element with a given name.
  2697. (should
  2698. (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
  2699. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2700. (looking-at "#\\+NAME: Test")))
  2701. ;; A target still lead to a matching headline otherwise.
  2702. (should
  2703. (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
  2704. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2705. (looking-at "\\* Head2")))
  2706. ;; With a leading star in link, enforce heading match.
  2707. (should
  2708. (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
  2709. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2710. (looking-at "\\* Test")))
  2711. ;; With a leading star in link, enforce exact heading match, even
  2712. ;; with `org-link-search-must-match-exact-headline' set to nil.
  2713. (should-error
  2714. (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
  2715. (let ((org-link-search-must-match-exact-headline nil))
  2716. (org-open-at-point))))
  2717. ;; Handle non-nil `org-link-search-must-match-exact-headline'.
  2718. (should
  2719. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
  2720. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2721. (looking-at "\\* Test")))
  2722. (should
  2723. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
  2724. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2725. (looking-at "\\* Test")))
  2726. ;; Heading match should not care about spaces, cookies, TODO
  2727. ;; keywords, priorities, and tags. However, TODO keywords are
  2728. ;; case-sensitive.
  2729. (should
  2730. (let ((first-line
  2731. "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
  2732. (org-test-with-temp-text
  2733. (concat first-line "\nFoo Bar\n<point>[[*Test 1 2]]")
  2734. (let ((org-link-search-must-match-exact-headline nil)
  2735. (org-todo-regexp "TODO"))
  2736. (org-open-at-point))
  2737. (looking-at (regexp-quote first-line)))))
  2738. (should-error
  2739. (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
  2740. (let ((org-link-search-must-match-exact-headline nil)
  2741. (org-todo-regexp "TODO"))
  2742. (org-open-at-point))))
  2743. ;; Heading match should still be exact.
  2744. (should-error
  2745. (org-test-with-temp-text "
  2746. ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
  2747. Foo Bar
  2748. <point>[[*Test 1]]"
  2749. (let ((org-link-search-must-match-exact-headline nil)
  2750. (org-todo-regexp "TODO"))
  2751. (org-open-at-point))))
  2752. (should
  2753. (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
  2754. (let ((org-link-search-must-match-exact-headline nil)
  2755. (org-todo-regexp "TODO"))
  2756. (org-open-at-point))
  2757. (looking-at-p (regexp-quote "** Test 1 2"))))
  2758. ;; Heading match ignores COMMENT keyword.
  2759. (should
  2760. (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
  2761. (org-open-at-point)
  2762. (looking-at "\\* COMMENT Test")))
  2763. (should
  2764. (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
  2765. (org-open-at-point)
  2766. (looking-at "\\* TODO COMMENT Test")))
  2767. ;; Correctly un-escape fuzzy links.
  2768. (should
  2769. (org-test-with-temp-text "* [foo]\n[[*\\[foo\\]][With escaped characters]]"
  2770. (org-open-at-point)
  2771. (bobp)))
  2772. ;; Match search strings containing newline characters, including
  2773. ;; blank lines.
  2774. (should
  2775. (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
  2776. (let ((file (buffer-file-name)))
  2777. (goto-char (point-max))
  2778. (insert (format "[[file:%s::line1 line2]]" file))
  2779. (beginning-of-line)
  2780. (let ((org-link-search-must-match-exact-headline nil))
  2781. (org-open-at-point 0))
  2782. (looking-at-p "line1"))))
  2783. (should
  2784. (org-test-with-temp-text-in-file "Paragraph\n\nline1\n\nline2\n\n"
  2785. (let ((file (buffer-file-name)))
  2786. (goto-char (point-max))
  2787. (insert (format "[[file:%s::line1 line2]]" file))
  2788. (beginning-of-line)
  2789. (let ((org-link-search-must-match-exact-headline nil))
  2790. (org-open-at-point 0))
  2791. (looking-at-p "line1")))))
  2792. ;;;; Open at point
  2793. (ert-deftest test-org/open-at-point/keyword ()
  2794. "Does `org-open-at-point' open link in a keyword line?"
  2795. (should
  2796. (org-test-with-temp-text
  2797. "<<top>>\n#+KEYWORD: <point>[[top]]"
  2798. (org-open-at-point) t))
  2799. (should
  2800. (org-test-with-temp-text
  2801. "* H\n<<top>>\n#+KEYWORD: <point>[[top]]"
  2802. (org-open-at-point) t)))
  2803. (ert-deftest test-org/open-at-point/property ()
  2804. "Does `org-open-at-point' open link in property drawer?"
  2805. (should
  2806. (org-test-with-temp-text
  2807. "* Headline
  2808. :PROPERTIES:
  2809. :URL: <point>[[*Headline]]
  2810. :END:"
  2811. (org-open-at-point) t)))
  2812. (ert-deftest test-org/open-at-point/comment ()
  2813. "Does `org-open-at-point' open link in a commented line?"
  2814. (should
  2815. (org-test-with-temp-text
  2816. "<<top>>\n# <point>[[top]]"
  2817. (org-open-at-point) t))
  2818. (should
  2819. (org-test-with-temp-text
  2820. "* H\n<<top>>\n# <point>[[top]]"
  2821. (org-open-at-point) t)))
  2822. (ert-deftest test-org/open-at-point/inline-image ()
  2823. "Test `org-open-at-point' on nested links."
  2824. (should
  2825. (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
  2826. (org-open-at-point)
  2827. (bobp))))
  2828. (ert-deftest test-org/open-at-point/radio-target ()
  2829. "Test `org-open-at-point' on radio targets."
  2830. (should
  2831. (org-test-with-temp-text "<<<target>>> <point>target"
  2832. (org-update-radio-target-regexp)
  2833. (org-open-at-point)
  2834. (eq (org-element-type (org-element-context)) 'radio-target))))
  2835. (ert-deftest test-org/open-at-point/radio-target-shadowed ()
  2836. "Test `org-open-at-point' on shadowed radio targets."
  2837. (should
  2838. (org-test-with-temp-text
  2839. "<<<target shadowed>>> <<<target>>> <point>target shadowed"
  2840. (org-update-radio-target-regexp)
  2841. (org-open-at-point)
  2842. (string=
  2843. (org-element-property :value
  2844. (org-element-radio-target-parser))
  2845. "target shadowed"))))
  2846. (ert-deftest test-org/open-at-point/tag ()
  2847. "Test `org-open-at-point' on tags."
  2848. (should
  2849. (org-test-with-temp-text "* H :<point>tag:"
  2850. (catch :result
  2851. (cl-letf (((symbol-function 'org-tags-view)
  2852. (lambda (&rest args) (throw :result t))))
  2853. (org-open-at-point)
  2854. nil))))
  2855. (should-not
  2856. (org-test-with-temp-text-in-file "* H<point> :tag:"
  2857. (catch :result
  2858. (cl-letf (((symbol-function 'org-tags-view)
  2859. (lambda (&rest args) (throw :result t))))
  2860. ;; When point isn't on a tag it's going to try other things,
  2861. ;; possibly trying to open attachments which will return an
  2862. ;; error if there isn't an attachment. Suppress that error.
  2863. (ignore-errors
  2864. (org-open-at-point))
  2865. nil)))))
  2866. ;;; Node Properties
  2867. (ert-deftest test-org/accumulated-properties-in-drawers ()
  2868. "Ensure properties accumulate in subtree drawers."
  2869. (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
  2870. (org-babel-next-src-block)
  2871. (should (equal '(2 1) (org-babel-execute-src-block)))))
  2872. (ert-deftest test-org/custom-properties ()
  2873. "Test custom properties specifications."
  2874. ;; Standard test.
  2875. (should
  2876. (let ((org-custom-properties '("FOO")))
  2877. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2878. (org-toggle-custom-properties-visibility)
  2879. (org-invisible-p2))))
  2880. ;; Properties are case-insensitive.
  2881. (should
  2882. (let ((org-custom-properties '("FOO")))
  2883. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
  2884. (org-toggle-custom-properties-visibility)
  2885. (org-invisible-p2))))
  2886. (should
  2887. (let ((org-custom-properties '("foo")))
  2888. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2889. (org-toggle-custom-properties-visibility)
  2890. (org-invisible-p2))))
  2891. ;; Multiple custom properties in the same drawer.
  2892. (should
  2893. (let ((org-custom-properties '("FOO" "BAR")))
  2894. (org-test-with-temp-text
  2895. "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
  2896. (org-fold-reveal)
  2897. (org-toggle-custom-properties-visibility)
  2898. (and (org-invisible-p2)
  2899. (not (progn (forward-line) (org-invisible-p2)))
  2900. (progn (forward-line) (org-invisible-p2))))))
  2901. ;; Hide custom properties with an empty value.
  2902. (should
  2903. (let ((org-custom-properties '("FOO")))
  2904. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
  2905. (org-toggle-custom-properties-visibility)
  2906. (org-invisible-p2))))
  2907. ;; Do not hide fake properties.
  2908. (should-not
  2909. (let ((org-custom-properties '("FOO")))
  2910. (org-test-with-temp-text ":FOO: val\n"
  2911. (org-toggle-custom-properties-visibility)
  2912. (org-invisible-p2))))
  2913. (should-not
  2914. (let ((org-custom-properties '("A")))
  2915. (org-test-with-temp-text
  2916. "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
  2917. (org-fold-reveal)
  2918. (org-toggle-custom-properties-visibility)
  2919. (org-invisible-p2)))))
  2920. ;;; Mark Region
  2921. (ert-deftest test-org/mark-element ()
  2922. "Test `org-mark-element' specifications."
  2923. ;; Mark beginning and end of element.
  2924. (should
  2925. (equal '(t t)
  2926. (org-test-with-temp-text "Para<point>graph"
  2927. (org-mark-element)
  2928. (list (bobp) (= (mark) (point-max))))))
  2929. (should
  2930. (equal '(t t)
  2931. (org-test-with-temp-text "P1\n\nPara<point>graph\n\nP2"
  2932. (org-mark-element)
  2933. (list (looking-at "Paragraph")
  2934. (org-with-point-at (mark) (looking-at "P2"))))))
  2935. ;; Do not set mark past (point-max).
  2936. (should
  2937. (org-test-with-temp-text "Para<point>graph"
  2938. (narrow-to-region 2 6)
  2939. (org-mark-element)
  2940. (= 6 (mark)))))
  2941. (ert-deftest test-org/mark-subtree ()
  2942. "Test `org-mark-subtree' specifications."
  2943. ;; Error when point is before first headline.
  2944. (should-error
  2945. (org-test-with-temp-text "Paragraph\n* Headline\nBody"
  2946. (progn (transient-mark-mode 1)
  2947. (org-mark-subtree))))
  2948. ;; Without argument, mark current subtree.
  2949. (should
  2950. (equal
  2951. '(12 32)
  2952. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  2953. (progn (transient-mark-mode 1)
  2954. (forward-line 2)
  2955. (org-mark-subtree)
  2956. (list (region-beginning) (region-end))))))
  2957. ;; With an argument, move ARG up.
  2958. (should
  2959. (equal
  2960. '(1 32)
  2961. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  2962. (progn (transient-mark-mode 1)
  2963. (forward-line 2)
  2964. (org-mark-subtree 1)
  2965. (list (region-beginning) (region-end))))))
  2966. ;; Do not get fooled by inlinetasks.
  2967. (when (featurep 'org-inlinetask)
  2968. (should
  2969. (= 1
  2970. (org-test-with-temp-text "* Headline\n*************** Task\nContents"
  2971. (progn (transient-mark-mode 1)
  2972. (forward-line 1)
  2973. (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
  2974. (region-beginning)))))))
  2975. ;;; Miscellaneous
  2976. (ert-deftest test-org/sort-entries ()
  2977. "Test `org-sort-entries'."
  2978. ;; Sort alphabetically.
  2979. (should
  2980. (equal "\n* abc\n* def\n* xyz\n"
  2981. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  2982. (org-sort-entries nil ?a)
  2983. (buffer-string))))
  2984. (should
  2985. (equal "\n* xyz\n* def\n* abc\n"
  2986. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  2987. (org-sort-entries nil ?A)
  2988. (buffer-string))))
  2989. (should
  2990. (equal "\n* \n* klm\n* xyz\n"
  2991. (org-test-with-temp-text "\n* xyz\n* \n* klm\n"
  2992. (org-sort-entries nil ?a)
  2993. (buffer-string))))
  2994. ;; Sort numerically.
  2995. (should
  2996. (equal "\n* 1\n* 2\n* 10\n"
  2997. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  2998. (org-sort-entries nil ?n)
  2999. (buffer-string))))
  3000. (should
  3001. (equal "\n* 10\n* 2\n* 1\n"
  3002. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  3003. (org-sort-entries nil ?N)
  3004. (buffer-string))))
  3005. (should
  3006. (equal "\n* \n* 1\n* 2\n"
  3007. (org-test-with-temp-text "\n* 1\n* \n* 2\n"
  3008. (org-sort-entries nil ?n)
  3009. (buffer-string))))
  3010. ;; Sort by custom function.
  3011. (should
  3012. (equal "\n* b\n* aa\n* ccc\n"
  3013. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  3014. (org-sort-entries nil ?f
  3015. (lambda ()
  3016. (length (buffer-substring (point-at-bol)
  3017. (point-at-eol))))
  3018. #'<)
  3019. (buffer-string))))
  3020. (should
  3021. (equal "\n* ccc\n* aa\n* b\n"
  3022. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  3023. (org-sort-entries nil ?F
  3024. (lambda ()
  3025. (length (buffer-substring (point-at-bol)
  3026. (point-at-eol))))
  3027. #'<)
  3028. (buffer-string))))
  3029. ;; Sort by TODO keyword.
  3030. (should
  3031. (equal "\n* TODO h1\n* TODO h3\n* DONE h2\n"
  3032. (org-test-with-temp-text
  3033. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  3034. (org-sort-entries nil ?o)
  3035. (buffer-string))))
  3036. (should
  3037. (equal "\n* DONE h2\n* TODO h1\n* TODO h3\n"
  3038. (org-test-with-temp-text
  3039. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  3040. (org-sort-entries nil ?O)
  3041. (buffer-string))))
  3042. ;; Sort by priority.
  3043. (should
  3044. (equal "\n* [#A] h2\n* [#B] h3\n* [#C] h1\n"
  3045. (org-test-with-temp-text
  3046. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  3047. (org-sort-entries nil ?p)
  3048. (buffer-string))))
  3049. (should
  3050. (equal "\n* [#C] h1\n* [#B] h3\n* [#A] h2\n"
  3051. (org-test-with-temp-text
  3052. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  3053. (org-sort-entries nil ?P)
  3054. (buffer-string))))
  3055. ;; Sort by creation time.
  3056. (should
  3057. (equal "
  3058. * h3
  3059. [2017-05-08 Mon]
  3060. * h2
  3061. [2017-05-09 Tue]
  3062. * h1
  3063. [2018-05-09 Wed]
  3064. "
  3065. (org-test-with-temp-text
  3066. "
  3067. * h1
  3068. [2018-05-09 Wed]
  3069. * h2
  3070. [2017-05-09 Tue]
  3071. * h3
  3072. [2017-05-08 Mon]
  3073. "
  3074. (org-sort-entries nil ?c)
  3075. (buffer-string))))
  3076. ;; Sort by scheduled date.
  3077. (should
  3078. (equal "
  3079. * TODO h4
  3080. SCHEDULED: <2017-05-06 Sat>
  3081. * TODO h3
  3082. SCHEDULED: <2017-05-08 Mon>
  3083. * TODO h2
  3084. DEADLINE: <2017-05-09 Tue>
  3085. * TODO h1
  3086. DEADLINE: <2017-05-07 Sun>
  3087. "
  3088. (org-test-with-temp-text
  3089. "
  3090. * TODO h2
  3091. DEADLINE: <2017-05-09 Tue>
  3092. * TODO h1
  3093. DEADLINE: <2017-05-07 Sun>
  3094. * TODO h3
  3095. SCHEDULED: <2017-05-08 Mon>
  3096. * TODO h4
  3097. SCHEDULED: <2017-05-06 Sat>
  3098. "
  3099. (org-sort-entries nil ?s)
  3100. (buffer-string))))
  3101. ;; Sort by deadline date.
  3102. (should
  3103. (equal "
  3104. * TODO h1
  3105. DEADLINE: <2017-05-07 Sun>
  3106. * TODO h2
  3107. DEADLINE: <2017-05-09 Tue>
  3108. * TODO h3
  3109. SCHEDULED: <2017-05-08 Mon>
  3110. * TODO h4
  3111. SCHEDULED: <2017-05-06 Sat>
  3112. "
  3113. (org-test-with-temp-text
  3114. "
  3115. * TODO h2
  3116. DEADLINE: <2017-05-09 Tue>
  3117. * TODO h1
  3118. DEADLINE: <2017-05-07 Sun>
  3119. * TODO h3
  3120. SCHEDULED: <2017-05-08 Mon>
  3121. * TODO h4
  3122. SCHEDULED: <2017-05-06 Sat>
  3123. "
  3124. (org-sort-entries nil ?d)
  3125. (buffer-string))))
  3126. ;; Sort by any date/time
  3127. (should
  3128. (equal "
  3129. * TODO h4
  3130. SCHEDULED: <2017-05-06 Sat>
  3131. * TODO h1
  3132. DEADLINE: <2017-05-07 Sun>
  3133. * TODO h3
  3134. SCHEDULED: <2017-05-08 Mon>
  3135. * TODO h2
  3136. DEADLINE: <2017-05-09 Tue>
  3137. "
  3138. (org-test-with-temp-text
  3139. "
  3140. * TODO h2
  3141. DEADLINE: <2017-05-09 Tue>
  3142. * TODO h1
  3143. DEADLINE: <2017-05-07 Sun>
  3144. * TODO h3
  3145. SCHEDULED: <2017-05-08 Mon>
  3146. * TODO h4
  3147. SCHEDULED: <2017-05-06 Sat>
  3148. "
  3149. (org-sort-entries nil ?t)
  3150. (buffer-string))))
  3151. ;; Sort by clocking time.
  3152. (should
  3153. (equal "
  3154. * clocked h2
  3155. :LOGBOOK:
  3156. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3157. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  3158. :END:
  3159. * clocked h1
  3160. :LOGBOOK:
  3161. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3162. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  3163. :END:
  3164. "
  3165. (org-test-with-temp-text
  3166. "
  3167. * clocked h1
  3168. :LOGBOOK:
  3169. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3170. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  3171. :END:
  3172. * clocked h2
  3173. :LOGBOOK:
  3174. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3175. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  3176. :END:
  3177. "
  3178. (org-sort-entries nil ?k)
  3179. (buffer-string))))
  3180. ;; Preserve file local variables when sorting.
  3181. (should
  3182. (equal "\n* A\n* B\n# Local Variables:\n# foo: t\n# End:\n"
  3183. (org-test-with-temp-text
  3184. "\n* B\n* A\n# Local Variables:\n# foo: t\n# End:"
  3185. (org-sort-entries nil ?a)
  3186. (buffer-string)))))
  3187. (ert-deftest test-org/string-collate-greaterp ()
  3188. "Test `org-string-collate-greaterp' specifications."
  3189. (should (org-string-collate-greaterp "def" "abc"))
  3190. (should-not (org-string-collate-greaterp "abc" "def")))
  3191. (ert-deftest test-org/file-contents ()
  3192. "Test `org-file-contents' specifications."
  3193. ;; Open files.
  3194. (should
  3195. (string= "#+BIND: variable value
  3196. #+DESCRIPTION: l2
  3197. #+LANGUAGE: en
  3198. #+SELECT_TAGS: b
  3199. #+TITLE: b
  3200. #+PROPERTY: a 1
  3201. " (org-file-contents (expand-file-name "setupfile3.org"
  3202. (concat org-test-dir "examples/")))))
  3203. ;; Throw error when trying to access an invalid file.
  3204. (should-error (org-file-contents "this-file-must-not-exist"))
  3205. ;; Try to access an invalid file, but do not throw an error.
  3206. (should
  3207. (progn (org-file-contents "this-file-must-not-exist" :noerror) t))
  3208. ;; Open URL.
  3209. (should
  3210. (string= "foo"
  3211. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3212. (unwind-protect
  3213. ;; Simulate successful retrieval of a URL.
  3214. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3215. (lambda (&rest_)
  3216. (with-current-buffer buffer
  3217. (insert "HTTP/1.1 200 OK\n\nfoo"))
  3218. buffer)))
  3219. (org-file-contents "http://some-valid-url"))
  3220. (kill-buffer buffer)))))
  3221. ;; Throw error when trying to access an invalid URL.
  3222. (should-error
  3223. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3224. (unwind-protect
  3225. ;; Simulate unsuccessful retrieval of a URL.
  3226. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3227. (lambda (&rest_)
  3228. (with-current-buffer buffer
  3229. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3230. buffer)))
  3231. (org-file-contents "http://this-url-must-not-exist"))
  3232. (kill-buffer buffer))))
  3233. ;; Try to access an invalid URL, but do not throw an error.
  3234. (should-error
  3235. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3236. (unwind-protect
  3237. ;; Simulate unsuccessful retrieval of a URL.
  3238. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3239. (lambda (&rest_)
  3240. (with-current-buffer buffer
  3241. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3242. buffer)))
  3243. (org-file-contents "http://this-url-must-not-exist"))
  3244. (kill-buffer buffer))))
  3245. (should
  3246. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3247. (unwind-protect
  3248. ;; Simulate unsuccessful retrieval of a URL.
  3249. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3250. (lambda (&rest_)
  3251. (with-current-buffer buffer
  3252. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3253. buffer)))
  3254. (org-file-contents "http://this-url-must-not-exist" :noerror))
  3255. (kill-buffer buffer))
  3256. t)))
  3257. ;;; Navigation
  3258. (ert-deftest test-org/next-visible-heading ()
  3259. "Test `org-next-visible-heading' specifications."
  3260. ;; Move to the beginning of the next headline, taking into
  3261. ;; consideration ARG.
  3262. (should
  3263. (org-test-with-temp-text "* H1\n* H2"
  3264. (org-next-visible-heading 1)
  3265. (looking-at "\\* H2")))
  3266. (should
  3267. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3268. (org-next-visible-heading 2)
  3269. (looking-at "\\* H3")))
  3270. ;; Ignore invisible headlines.
  3271. (should
  3272. (org-test-with-temp-text "* H1\n** H2\n* H3"
  3273. (org-cycle)
  3274. (org-next-visible-heading 1)
  3275. (looking-at "\\* H3")))
  3276. ;; Move point between headlines, not on blank lines between.
  3277. (should
  3278. (org-test-with-temp-text "* H1\n** H2\n\n\n\n* H3"
  3279. (let ((org-cycle-separator-lines 1))
  3280. (org-cycle)
  3281. (org-next-visible-heading 1))
  3282. (looking-at "\\* H3")))
  3283. ;; Move at end of buffer when there is no more headline.
  3284. (should
  3285. (org-test-with-temp-text "* H1"
  3286. (org-next-visible-heading 1)
  3287. (eobp)))
  3288. (should
  3289. (org-test-with-temp-text "* H1\n* H2"
  3290. (org-next-visible-heading 2)
  3291. (eobp)))
  3292. ;; With a negative argument, move backwards.
  3293. (should
  3294. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3295. (org-next-visible-heading -1)
  3296. (looking-at "\\* H2")))
  3297. (should
  3298. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3299. (org-next-visible-heading -2)
  3300. (looking-at "\\* H1"))))
  3301. (ert-deftest test-org/previous-visible-heading ()
  3302. "Test `org-previous-visible-heading' specifications."
  3303. ;; Move to the beginning of the next headline, taking into
  3304. ;; consideration ARG.
  3305. (should
  3306. (org-test-with-temp-text "* H1\n<point>* H2"
  3307. (org-previous-visible-heading 1)
  3308. (looking-at "\\* H1")))
  3309. (should
  3310. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3311. (org-previous-visible-heading 2)
  3312. (looking-at "\\* H1")))
  3313. ;; Ignore invisible headlines.
  3314. (should
  3315. (org-test-with-temp-text "* H1\n** H2\n<point>* H3"
  3316. (org-overview)
  3317. (org-previous-visible-heading 1)
  3318. (looking-at "\\* H1")))
  3319. ;; Move point between headlines, not on blank lines between.
  3320. (should
  3321. (org-test-with-temp-text "* H1\n\n\n\n** H2\n<point>* H3"
  3322. (let ((org-cycle-separator-lines 1))
  3323. (org-overview)
  3324. (org-previous-visible-heading 1))
  3325. (looking-at "\\* H1")))
  3326. ;; Move at end of buffer when there is no more headline.
  3327. (should
  3328. (org-test-with-temp-text "* H1"
  3329. (org-previous-visible-heading 1)
  3330. (bobp)))
  3331. (should
  3332. (org-test-with-temp-text "* H1\n* <point>H2"
  3333. (org-previous-visible-heading 2)
  3334. (bobp)))
  3335. ;; Invisible parts may not start at a headline, i.e., when revealing
  3336. ;; parts of the buffer. Handle this.
  3337. (should
  3338. (org-test-with-temp-text "* Main\n** H1\nFoo\n** H2\nBar\n** H3\nBaz"
  3339. (org-overview)
  3340. (search-forward "H1")
  3341. (org-show-context 'minimal)
  3342. (org-cycle)
  3343. (search-forward "H3")
  3344. (org-show-context 'minimal)
  3345. ;; At this point, buffer displays, with point at "|",
  3346. ;;
  3347. ;; * Main
  3348. ;; ** H1
  3349. ;; Foo
  3350. ;; ** H3|
  3351. (org-previous-visible-heading 1)
  3352. (looking-at "\\*+ H1"))))
  3353. (ert-deftest test-org/forward-heading-same-level ()
  3354. "Test `org-forward-heading-same-level' specifications."
  3355. ;; Test navigation at top level, forward and backward.
  3356. (should
  3357. (equal "* H2"
  3358. (org-test-with-temp-text "* H1\n* H2"
  3359. (org-forward-heading-same-level 1)
  3360. (buffer-substring-no-properties (point) (line-end-position)))))
  3361. (should
  3362. (equal "* H1"
  3363. (org-test-with-temp-text "* H1\n<point>* H2"
  3364. (org-forward-heading-same-level -1)
  3365. (buffer-substring-no-properties (point) (line-end-position)))))
  3366. ;; Test navigation in a sub-tree, forward and backward.
  3367. (should
  3368. (equal "* H2"
  3369. (org-test-with-temp-text "* H1\n** H11\n** H12\n* H2"
  3370. (org-forward-heading-same-level 1)
  3371. (buffer-substring-no-properties (point) (line-end-position)))))
  3372. (should
  3373. (equal "* H1"
  3374. (org-test-with-temp-text "* H1\n** H11\n** H12\n<point>* H2"
  3375. (org-forward-heading-same-level -1)
  3376. (buffer-substring-no-properties (point) (line-end-position)))))
  3377. ;; Stop at first or last sub-heading.
  3378. (should-not
  3379. (equal "* H2"
  3380. (org-test-with-temp-text "* H1\n** H11\n<point>** H12\n* H2"
  3381. (org-forward-heading-same-level 1)
  3382. (buffer-substring-no-properties (point) (line-end-position)))))
  3383. (should-not
  3384. (equal "* H2"
  3385. (org-test-with-temp-text "* H1\n<point>** H11\n** H12\n* H2"
  3386. (org-forward-heading-same-level -1)
  3387. (buffer-substring-no-properties (point) (line-end-position)))))
  3388. ;; Allow multiple moves.
  3389. (should
  3390. (equal "* H3"
  3391. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3392. (org-forward-heading-same-level 2)
  3393. (buffer-substring-no-properties (point) (line-end-position)))))
  3394. (should
  3395. (equal "* H1"
  3396. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3397. (org-forward-heading-same-level -2)
  3398. (buffer-substring-no-properties (point) (line-end-position)))))
  3399. ;; Ignore spurious moves when first (or last) sibling is reached.
  3400. (should
  3401. (equal "** H3"
  3402. (org-test-with-temp-text "* First\n<point>** H1\n** H2\n** H3\n* Last"
  3403. (org-forward-heading-same-level 100)
  3404. (buffer-substring-no-properties (point) (line-end-position)))))
  3405. (should
  3406. (equal "** H1"
  3407. (org-test-with-temp-text "* First\n** H1\n** H2\n<point>** H3\n* Last"
  3408. (org-forward-heading-same-level -100)
  3409. (buffer-substring-no-properties (point) (line-end-position))))))
  3410. (ert-deftest test-org/end-of-meta-data ()
  3411. "Test `org-end-of-meta-data' specifications."
  3412. ;; Skip planning line.
  3413. (should
  3414. (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
  3415. (org-end-of-meta-data)
  3416. (eobp)))
  3417. ;; Skip properties drawer.
  3418. (should
  3419. (org-test-with-temp-text
  3420. "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
  3421. (org-end-of-meta-data)
  3422. (eobp)))
  3423. ;; Skip both.
  3424. (should
  3425. (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
  3426. (org-end-of-meta-data)
  3427. (eobp)))
  3428. ;; Nothing to skip, go to first line.
  3429. (should
  3430. (org-test-with-temp-text "* Headline\nContents"
  3431. (org-end-of-meta-data)
  3432. (looking-at "Contents")))
  3433. ;; With option argument, skip empty lines, regular drawers and
  3434. ;; clocking lines.
  3435. (should
  3436. (org-test-with-temp-text "* Headline\n\nContents"
  3437. (org-end-of-meta-data t)
  3438. (looking-at "Contents")))
  3439. (should
  3440. (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
  3441. (org-end-of-meta-data t)
  3442. (looking-at "Contents")))
  3443. (should
  3444. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
  3445. (org-end-of-meta-data t)
  3446. (looking-at "Contents")))
  3447. ;; Special case: do not skip incomplete drawers.
  3448. (should
  3449. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
  3450. (org-end-of-meta-data t)
  3451. (looking-at ":LOGBOOK:")))
  3452. ;; Special case: Be careful about consecutive headlines.
  3453. (should-not
  3454. (org-test-with-temp-text "* H1\n*H2\nContents"
  3455. (org-end-of-meta-data t)
  3456. (looking-at "Contents"))))
  3457. (ert-deftest test-org/shiftright-heading ()
  3458. "Test `org-shiftright' on headings."
  3459. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  3460. (should
  3461. (equal "* TODO a1\n** a2\n* DONE b1\n"
  3462. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3463. (org-shiftright)
  3464. (buffer-string))))
  3465. (should
  3466. (equal "* TODO a1\n** TODO a2\n* b1\n"
  3467. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3468. (let ((org-loop-over-headlines-in-active-region t))
  3469. (transient-mark-mode 1)
  3470. (push-mark (point) t t)
  3471. (search-forward "* DONE b1")
  3472. (org-shiftright))
  3473. (buffer-string))))
  3474. (should
  3475. (equal "* TODO a1\n** a2\n* b1\n"
  3476. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3477. (let ((org-loop-over-headlines-in-active-region 'start-level))
  3478. (transient-mark-mode 1)
  3479. (push-mark (point) t t)
  3480. (search-forward "* DONE b1")
  3481. (org-shiftright))
  3482. (buffer-string))))))
  3483. (ert-deftest test-org/beginning-of-line ()
  3484. "Test `org-beginning-of-line' specifications."
  3485. ;; Move to beginning of line. If current line in invisible, move to
  3486. ;; beginning of visible line instead.
  3487. (should
  3488. (org-test-with-temp-text "Some text\nSome other text<point>"
  3489. (org-beginning-of-line)
  3490. (bolp)))
  3491. (should
  3492. (org-test-with-temp-text "* H1\n** H2<point>"
  3493. (org-overview)
  3494. (org-beginning-of-line)
  3495. (= (line-beginning-position) 1)))
  3496. ;; With `visual-line-mode' active, move to beginning of visual line.
  3497. (should-not
  3498. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3499. (visual-line-mode)
  3500. (dotimes (i 1000) (insert "very "))
  3501. (org-beginning-of-line)
  3502. (bolp)))
  3503. ;; In a wide headline, with `visual-line-mode', prefer going to the
  3504. ;; beginning of a visual line than to the logical beginning of line,
  3505. ;; even if special movement is active.
  3506. (should-not
  3507. (org-test-with-temp-text "* A <point>long headline"
  3508. (visual-line-mode)
  3509. (dotimes (i 1000) (insert "very "))
  3510. (goto-char (point-max))
  3511. (org-beginning-of-line)
  3512. (bobp)))
  3513. (should-not
  3514. (org-test-with-temp-text "* A <point>long headline"
  3515. (visual-line-mode)
  3516. (dotimes (i 1000) (insert "very "))
  3517. (goto-char (point-max))
  3518. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line))
  3519. (bobp)))
  3520. ;; At an headline with special movement, first move at beginning of
  3521. ;; title, then at the beginning of line, rinse, repeat.
  3522. (should
  3523. (org-test-with-temp-text "* TODO Headline<point>"
  3524. (let ((org-special-ctrl-a/e t))
  3525. (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
  3526. (progn (org-beginning-of-line) (bolp))
  3527. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3528. (should
  3529. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3530. (let ((org-special-ctrl-a/e t))
  3531. (org-beginning-of-line)
  3532. (looking-at "Headline"))))
  3533. (should
  3534. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3535. (let ((org-special-ctrl-a/e '(t . nil)))
  3536. (org-beginning-of-line)
  3537. (looking-at "Headline"))))
  3538. (should-not
  3539. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3540. (let ((org-special-ctrl-a/e '(nil . nil)))
  3541. (org-beginning-of-line)
  3542. (looking-at "Headline"))))
  3543. ;; At an headline with reversed movement, first move to beginning of
  3544. ;; line, then to the beginning of title.
  3545. (should
  3546. (org-test-with-temp-text "* TODO Headline<point>"
  3547. (let ((org-special-ctrl-a/e 'reversed)
  3548. (this-command last-command))
  3549. (and (progn (org-beginning-of-line) (bolp))
  3550. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3551. (should
  3552. (org-test-with-temp-text "* TODO Headline<point>"
  3553. (let ((org-special-ctrl-a/e '(reversed . nil))
  3554. (this-command last-command))
  3555. (and (progn (org-beginning-of-line) (bolp))
  3556. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3557. (should-not
  3558. (org-test-with-temp-text "* TODO Headline<point>"
  3559. (let ((org-special-ctrl-a/e '(t . nil))
  3560. (this-command last-command))
  3561. (and (progn (org-beginning-of-line) (bolp))
  3562. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3563. ;; At an item with special movement, first move after to beginning
  3564. ;; of title, then to the beginning of line, rinse, repeat.
  3565. (should
  3566. (org-test-with-temp-text "- [ ] Item<point>"
  3567. (let ((org-special-ctrl-a/e t))
  3568. (and (progn (org-beginning-of-line) (looking-at-p "Item"))
  3569. (progn (org-beginning-of-line) (bolp))
  3570. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3571. ;; At an item with reversed movement, first move to beginning of
  3572. ;; line, then to the beginning of title.
  3573. (should
  3574. (org-test-with-temp-text "- [X] Item<point>"
  3575. (let ((org-special-ctrl-a/e 'reversed)
  3576. (this-command last-command))
  3577. (and (progn (org-beginning-of-line) (bolp))
  3578. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3579. ;; Leave point before invisible characters at column 0.
  3580. (should
  3581. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3582. (let ((org-special-ctrl-a/e nil))
  3583. (org-beginning-of-line)
  3584. (bolp))))
  3585. (should
  3586. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3587. (let ((org-special-ctrl-a/e t))
  3588. (org-beginning-of-line)
  3589. (bolp))))
  3590. (should
  3591. (org-test-with-temp-text "[[http<point>://orgmode.org]]"
  3592. (visual-line-mode)
  3593. (org-beginning-of-line)
  3594. (bolp)))
  3595. ;; Special case: Do not error when the buffer contains only a single
  3596. ;; asterisk.
  3597. (should
  3598. (org-test-with-temp-text "*<point>"
  3599. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line) t)))
  3600. (should
  3601. (org-test-with-temp-text "*<point>"
  3602. (let ((org-special-ctrl-a/e nil)) (org-beginning-of-line) t))))
  3603. (ert-deftest test-org/end-of-line ()
  3604. "Test `org-end-of-line' specifications."
  3605. ;; Standard test.
  3606. (should
  3607. (org-test-with-temp-text "Some text\nSome other text"
  3608. (org-end-of-line)
  3609. (eolp)))
  3610. ;; With `visual-line-mode' active, move to end of visible line.
  3611. ;; However, never go past ellipsis.
  3612. (should-not
  3613. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3614. (visual-line-mode)
  3615. (dotimes (i 1000) (insert "very "))
  3616. (goto-char (point-min))
  3617. (org-end-of-line)
  3618. (eolp)))
  3619. (should-not
  3620. (org-test-with-temp-text "* A short headline\nSome contents"
  3621. (visual-line-mode)
  3622. (org-overview)
  3623. (org-end-of-line)
  3624. (eobp)))
  3625. ;; In a wide headline, with `visual-line-mode', prefer going to end
  3626. ;; of visible line if tags, or end of line, are farther.
  3627. (should-not
  3628. (org-test-with-temp-text "* A <point>long headline"
  3629. (visual-line-mode)
  3630. (dotimes (i 1000) (insert "very "))
  3631. (goto-char (point-min))
  3632. (org-end-of-line)
  3633. (eolp)))
  3634. (should-not
  3635. (org-test-with-temp-text "* A <point>long headline :tag:"
  3636. (visual-line-mode)
  3637. (dotimes (i 1000) (insert "very "))
  3638. (goto-char (point-min))
  3639. (org-end-of-line)
  3640. (eolp)))
  3641. ;; At an headline without special movement, go to end of line.
  3642. ;; However, never go past ellipsis.
  3643. (should
  3644. (org-test-with-temp-text "* Headline2b :tag:\n"
  3645. (let ((org-special-ctrl-a/e nil))
  3646. (and (progn (org-end-of-line) (eolp))
  3647. (progn (org-end-of-line) (eolp))))))
  3648. (should
  3649. (org-test-with-temp-text "* Headline2b :tag:\n"
  3650. (let ((org-special-ctrl-a/e '(t . nil)))
  3651. (and (progn (org-end-of-line) (eolp))
  3652. (progn (org-end-of-line) (eolp))))))
  3653. (should
  3654. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3655. (org-overview)
  3656. (let ((org-special-ctrl-a/e nil))
  3657. (org-end-of-line)
  3658. (= 1 (line-beginning-position)))))
  3659. ;; At an headline with special movement, first move before tags,
  3660. ;; then at the end of line, rinse, repeat. However, never go past
  3661. ;; ellipsis.
  3662. (should
  3663. (org-test-with-temp-text "* Headline1 :tag:\n"
  3664. (let ((org-special-ctrl-a/e t))
  3665. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3666. (progn (org-end-of-line) (eolp))
  3667. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3668. (should
  3669. (org-test-with-temp-text "* Headline1 :tag:\n"
  3670. (let ((org-special-ctrl-a/e '(nil . t)))
  3671. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3672. (progn (org-end-of-line) (eolp))
  3673. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3674. (should-not
  3675. (org-test-with-temp-text "* Headline1 :tag:\n"
  3676. (let ((org-special-ctrl-a/e '(nil . nil)))
  3677. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3678. (progn (org-end-of-line) (eolp))
  3679. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3680. (should
  3681. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3682. (org-overview)
  3683. (let ((org-special-ctrl-a/e t))
  3684. (org-end-of-line)
  3685. (org-end-of-line)
  3686. (= 1 (line-beginning-position)))))
  3687. ;; At an headline, with reversed movement, first go to end of line,
  3688. ;; then before tags. However, never go past ellipsis.
  3689. (should
  3690. (org-test-with-temp-text "* Headline3 :tag:\n"
  3691. (let ((org-special-ctrl-a/e 'reversed)
  3692. (this-command last-command))
  3693. (and (progn (org-end-of-line) (eolp))
  3694. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3695. (should
  3696. (org-test-with-temp-text "* Headline3 :tag:\n"
  3697. (let ((org-special-ctrl-a/e '(nil . reversed))
  3698. (this-command last-command))
  3699. (and (progn (org-end-of-line) (eolp))
  3700. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3701. (should-not
  3702. (org-test-with-temp-text "* Headline3 :tag:\n"
  3703. (let ((org-special-ctrl-a/e '(nil . t))
  3704. (this-command last-command))
  3705. (and (progn (org-end-of-line) (eolp))
  3706. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3707. (should
  3708. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3709. (org-overview)
  3710. (let ((org-special-ctrl-a/e 'reversed))
  3711. (org-end-of-line)
  3712. (= 1 (line-beginning-position)))))
  3713. ;; At a block without hidden contents.
  3714. (should
  3715. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3716. (progn (org-end-of-line) (eolp))))
  3717. ;; At a block with hidden contents.
  3718. (should-not
  3719. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3720. (let ((org-special-ctrl-a/e t))
  3721. (org-fold-hide-block-toggle)
  3722. (org-end-of-line)
  3723. (eobp))))
  3724. ;; Get past invisible characters at the end of line.
  3725. (should
  3726. (org-test-with-temp-text "[[https://orgmode.org]]"
  3727. (org-end-of-line)
  3728. (eolp))))
  3729. (ert-deftest test-org/open-line ()
  3730. "Test `org-open-line' specifications."
  3731. ;; Call `open-line' outside of tables.
  3732. (should
  3733. (equal "\nText"
  3734. (org-test-with-temp-text "Text"
  3735. (org-open-line 1)
  3736. (buffer-string))))
  3737. ;; At a table, create a row above.
  3738. (should
  3739. (equal "\n| |\n| a |"
  3740. (org-test-with-temp-text "\n<point>| a |"
  3741. (org-open-line 1)
  3742. (buffer-string))))
  3743. ;; At the very first character of the buffer, also call `open-line'.
  3744. (should
  3745. (equal "\n| a |"
  3746. (org-test-with-temp-text "| a |"
  3747. (org-open-line 1)
  3748. (buffer-string))))
  3749. ;; Narrowing does not count.
  3750. (should
  3751. (equal "Text\n| |\n| a |"
  3752. (org-test-with-temp-text "Text\n<point>| a |"
  3753. (narrow-to-region (point) (point-max))
  3754. (org-open-line 1)
  3755. (widen)
  3756. (buffer-string)))))
  3757. (ert-deftest test-org/forward-sentence ()
  3758. "Test `org-forward-sentence' specifications."
  3759. ;; At the end of a table cell, move to the end of the next one.
  3760. (should
  3761. (org-test-with-temp-text "| a<point> | b |"
  3762. (org-forward-sentence)
  3763. (looking-at " |$")))
  3764. ;; Elsewhere in a cell, move to its end.
  3765. (should
  3766. (org-test-with-temp-text "| a<point>c | b |"
  3767. (org-forward-sentence)
  3768. (looking-at " | b |$")))
  3769. ;; Otherwise, simply call `forward-sentence'.
  3770. (should
  3771. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3772. (org-forward-sentence)
  3773. (looking-at " Sentence 2.")))
  3774. (should
  3775. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3776. (org-forward-sentence)
  3777. (org-forward-sentence)
  3778. (eobp)))
  3779. ;; At the end of an element, jump to the next one, without stopping
  3780. ;; on blank lines in-between.
  3781. (should
  3782. (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
  3783. (org-forward-sentence)
  3784. (eobp)))
  3785. ;; Headlines are considered to be sentences by themselves, even if
  3786. ;; they do not end with a full stop.
  3787. (should
  3788. (equal
  3789. "* Headline"
  3790. (org-test-with-temp-text "* <point>Headline\nSentence."
  3791. (org-forward-sentence)
  3792. (buffer-substring-no-properties (line-beginning-position) (point)))))
  3793. (should
  3794. (org-test-with-temp-text "* Headline<point>\nSentence."
  3795. (org-forward-sentence)
  3796. (eobp)))
  3797. (should
  3798. (org-test-with-temp-text "Sentence.<point>\n\n* Headline\n\nSentence 2."
  3799. (org-forward-sentence)
  3800. (and (org-at-heading-p) (eolp)))))
  3801. (ert-deftest test-org/backward-sentence ()
  3802. "Test `org-backward-sentence' specifications."
  3803. ;; At the beginning of a table cell, move to the beginning of the
  3804. ;; previous one.
  3805. (should
  3806. (org-test-with-temp-text "| a | <point>b |"
  3807. (org-backward-sentence)
  3808. (looking-at "a | b |$")))
  3809. ;; Elsewhere in a cell, move to its beginning.
  3810. (should
  3811. (org-test-with-temp-text "| a | b<point>c |"
  3812. (org-backward-sentence)
  3813. (looking-at "bc |$")))
  3814. ;; Otherwise, simply call `backward-sentence'.
  3815. (should
  3816. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3817. (org-backward-sentence)
  3818. (looking-at "Sentence 2.")))
  3819. (should
  3820. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3821. (org-backward-sentence)
  3822. (org-backward-sentence)
  3823. (bobp)))
  3824. ;; Make sure to hit the beginning of a sentence on the same line as
  3825. ;; an item.
  3826. (should
  3827. (org-test-with-temp-text "- Line 1\n line <point>2."
  3828. (org-backward-sentence)
  3829. (looking-at "Line 1"))))
  3830. (ert-deftest test-org/forward-paragraph ()
  3831. "Test `org-forward-paragraph' specifications."
  3832. ;; At end of buffer, do not return an error.
  3833. (should
  3834. (org-test-with-temp-text "Paragraph"
  3835. (goto-char (point-max))
  3836. (org-forward-paragraph)
  3837. t))
  3838. ;; Standard test.
  3839. (should
  3840. (= 2
  3841. (org-test-with-temp-text "P1\n\nP2"
  3842. (org-forward-paragraph)
  3843. (org-current-line))))
  3844. (should
  3845. (= 2
  3846. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  3847. (org-forward-paragraph)
  3848. (org-current-line))))
  3849. ;; Enter greater elements.
  3850. (should
  3851. (= 2
  3852. (org-test-with-temp-text "#+begin_center\nP1\n#+end_center\nP2"
  3853. (org-forward-paragraph)
  3854. (org-current-line))))
  3855. ;; Do not enter elements with invisible contents.
  3856. (should
  3857. (= 4
  3858. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  3859. (org-cycle)
  3860. (org-forward-paragraph)
  3861. (org-current-line))))
  3862. (should
  3863. (= 6
  3864. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\nP3"
  3865. (org-fold-hide-block-toggle)
  3866. (org-forward-paragraph)
  3867. (org-current-line))))
  3868. ;; On an item or a footnote definition, move past the first element
  3869. ;; inside, if any.
  3870. (should
  3871. (= 2
  3872. (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
  3873. (org-forward-paragraph)
  3874. (org-current-line))))
  3875. (should
  3876. (= 2
  3877. (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
  3878. (org-forward-paragraph)
  3879. (org-current-line))))
  3880. ;; On a table (resp. a property drawer) do not move through table
  3881. ;; rows (resp. node properties).
  3882. (should
  3883. (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
  3884. (org-forward-paragraph)
  3885. (looking-at "Paragraph")))
  3886. (should
  3887. (org-test-with-temp-text
  3888. "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
  3889. (org-forward-paragraph)
  3890. (looking-at "Paragraph")))
  3891. ;; Skip consecutive keywords, clocks and diary S-exps.
  3892. (should
  3893. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n"
  3894. (org-forward-paragraph)
  3895. (eobp)))
  3896. (should
  3897. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n"
  3898. (org-forward-paragraph)
  3899. (eobp)))
  3900. (should
  3901. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n"
  3902. (org-forward-paragraph)
  3903. (eobp)))
  3904. (should-not
  3905. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n"
  3906. (org-forward-paragraph)
  3907. (eobp)))
  3908. (should-not
  3909. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n"
  3910. (org-forward-paragraph)
  3911. (eobp)))
  3912. ;; In a plain list with one item every line, skip the whole list,
  3913. ;; even with point in the middle of the list.
  3914. (should
  3915. (org-test-with-temp-text "- A\n - B\n- C\n"
  3916. (org-forward-paragraph)
  3917. (eobp)))
  3918. (should
  3919. (org-test-with-temp-text "- A\n - <point>B\n- C\n"
  3920. (org-forward-paragraph)
  3921. (eobp)))
  3922. ;; On a comment, verse or source block, stop at "contents"
  3923. ;; boundaries and blank lines.
  3924. (should
  3925. (= 2
  3926. (org-test-with-temp-text "#+begin_src emacs-lisp\nL1\n\nL2\n#+end_src"
  3927. (org-forward-paragraph)
  3928. (org-current-line))))
  3929. (should
  3930. (= 3
  3931. (org-test-with-temp-text "#+begin_verse\n<point>L1\n\nL2\n#+end_verse"
  3932. (org-forward-paragraph)
  3933. (org-current-line))))
  3934. (should
  3935. (= 5
  3936. (org-test-with-temp-text "#+begin_comment\nL1\n\n<point>L2\n#+end_comment"
  3937. (org-forward-paragraph)
  3938. (org-current-line))))
  3939. ;; Being on an affiliated keyword shouldn't make any difference.
  3940. (should
  3941. (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
  3942. (org-forward-paragraph)
  3943. (eobp))))
  3944. (ert-deftest test-org/backward-paragraph ()
  3945. "Test `org-backward-paragraph' specifications."
  3946. ;; Do not error at beginning of buffer.
  3947. (should
  3948. (org-test-with-temp-text "Paragraph"
  3949. (org-backward-paragraph)
  3950. t))
  3951. ;; At blank lines at the very beginning of a buffer, move to
  3952. ;; point-min.
  3953. (should
  3954. (org-test-with-temp-text "\n\n<point>\n\nParagraph"
  3955. (org-backward-paragraph)
  3956. (bobp)))
  3957. ;; Regular test.
  3958. (should
  3959. (= 2
  3960. (org-test-with-temp-text "P1\n\nP2<point>"
  3961. (org-backward-paragraph)
  3962. (org-current-line))))
  3963. (should
  3964. (= 4
  3965. (org-test-with-temp-text "P1\n\nP2\n\nP3<point>"
  3966. (org-backward-paragraph)
  3967. (org-current-line))))
  3968. ;; Try to move on the line above current element.
  3969. (should
  3970. (= 2
  3971. (org-test-with-temp-text "\n\n<point>Paragraph"
  3972. (org-backward-paragraph)
  3973. (org-current-line))))
  3974. ;; Do not leave point in an invisible area.
  3975. (should
  3976. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  3977. (org-cycle)
  3978. (goto-char (point-max))
  3979. (beginning-of-line)
  3980. (org-backward-paragraph)
  3981. (bobp)))
  3982. (should
  3983. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\n"
  3984. (org-fold-hide-block-toggle)
  3985. (goto-char (point-max))
  3986. (org-backward-paragraph)
  3987. (bobp)))
  3988. ;; On the first element in an item or a footnote definition, jump
  3989. ;; before the footnote or the item.
  3990. (should
  3991. (org-test-with-temp-text "- line1<point>"
  3992. (org-backward-paragraph)
  3993. (bobp)))
  3994. (should
  3995. (org-test-with-temp-text "[fn:1] line1n<point>"
  3996. (org-backward-paragraph)
  3997. (bobp)))
  3998. ;; On the second element in an item or a footnote definition, jump
  3999. ;; to item or the definition.
  4000. (should
  4001. (= 2
  4002. (org-test-with-temp-text "- line1\n\n<point> line2"
  4003. (org-backward-paragraph)
  4004. (org-current-line))))
  4005. (should
  4006. (= 2
  4007. (org-test-with-temp-text "[fn:1] line1\n\n<point> line2"
  4008. (org-backward-paragraph)
  4009. (org-current-line))))
  4010. ;; On a table (resp. a property drawer), ignore table rows
  4011. ;; (resp. node properties).
  4012. (should
  4013. (org-test-with-temp-text "| a | b |\n| c | d |\n<point>P1"
  4014. (org-backward-paragraph)
  4015. (bobp)))
  4016. (should
  4017. (= 2
  4018. (org-test-with-temp-text
  4019. "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
  4020. (org-backward-paragraph)
  4021. (org-current-line))))
  4022. ;; In a plain list with one item every line, skip the whole list,
  4023. ;; even with point in the middle of the list.
  4024. (should
  4025. (org-test-with-temp-text "- A\n - B\n- C\n<point>"
  4026. (org-backward-paragraph)
  4027. (bobp)))
  4028. (should
  4029. (org-test-with-temp-text "- A\n - B\n- <point>C\n"
  4030. (org-backward-paragraph)
  4031. (bobp)))
  4032. ;; Skip consecutive keywords, clocks and diary S-exps.
  4033. (should
  4034. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n<point>"
  4035. (org-backward-paragraph)
  4036. (bobp)))
  4037. (should
  4038. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n<point>"
  4039. (org-backward-paragraph)
  4040. (bobp)))
  4041. (should
  4042. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n<point>"
  4043. (org-backward-paragraph)
  4044. (bobp)))
  4045. (should-not
  4046. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n<point>"
  4047. (org-backward-paragraph)
  4048. (bobp)))
  4049. (should-not
  4050. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n<point>"
  4051. (org-backward-paragraph)
  4052. (bobp)))
  4053. ;; On a comment, example, source and verse blocks, stop at blank
  4054. ;; lines.
  4055. (should
  4056. (= 1
  4057. (org-test-with-temp-text
  4058. "#+begin_comment\n<point>L1\n\nL2\n\nL3\n#+end_comment"
  4059. (org-backward-paragraph)
  4060. (org-current-line))))
  4061. (should
  4062. (= 2
  4063. (org-test-with-temp-text
  4064. "#+begin_verse\nL1\n\n<point>L2\n\nL3\n#+end_verse"
  4065. (org-backward-paragraph)
  4066. (org-current-line))))
  4067. (should
  4068. (= 3
  4069. (org-test-with-temp-text
  4070. "#+begin_src emacs-lisp\nL1\n\nL2\n\n<point>L3\n#+end_src"
  4071. (org-backward-paragraph)
  4072. (org-current-line))))
  4073. ;; When called from the opening line itself, however, move to
  4074. ;; beginning of block.
  4075. (should
  4076. (org-test-with-temp-text "#+begin_<point>example\nL1\n#+end_example"
  4077. (org-backward-paragraph)
  4078. (bobp)))
  4079. ;; On an empty heading, move above it.
  4080. (should
  4081. (org-test-with-temp-text "\n* <point>"
  4082. (org-backward-paragraph)
  4083. (bobp)))
  4084. (should
  4085. (org-test-with-temp-text "\n* \n<point>"
  4086. (org-backward-paragraph)
  4087. (bobp))))
  4088. (ert-deftest test-org/forward-element ()
  4089. "Test `org-forward-element' specifications."
  4090. ;; 1. At EOB: should error.
  4091. (org-test-with-temp-text "Some text\n"
  4092. (goto-char (point-max))
  4093. (should-error (org-forward-element)))
  4094. ;; 2. Standard move: expected to ignore blank lines.
  4095. (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
  4096. (org-forward-element)
  4097. (should (looking-at (regexp-quote "Second paragraph."))))
  4098. ;; 3. Headline tests.
  4099. (org-test-with-temp-text "
  4100. * Head 1
  4101. ** Head 1.1
  4102. *** Head 1.1.1
  4103. ** Head 1.2"
  4104. ;; 3.1. At an headline beginning: move to next headline at the
  4105. ;; same level.
  4106. (goto-line 3)
  4107. (org-forward-element)
  4108. (should (looking-at (regexp-quote "** Head 1.2")))
  4109. ;; 3.2. At an headline beginning: move to parent headline if no
  4110. ;; headline at the same level.
  4111. (goto-line 3)
  4112. (org-forward-element)
  4113. (should (looking-at (regexp-quote "** Head 1.2"))))
  4114. ;; 4. Greater element tests.
  4115. (org-test-with-temp-text
  4116. "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
  4117. ;; 4.1. At a greater element: expected to skip contents.
  4118. (org-forward-element)
  4119. (should (looking-at (regexp-quote "Outside.")))
  4120. ;; 4.2. At the end of greater element contents: expected to skip
  4121. ;; to the end of the greater element.
  4122. (goto-line 2)
  4123. (org-forward-element)
  4124. (should (looking-at (regexp-quote "Outside."))))
  4125. ;; 5. List tests.
  4126. (org-test-with-temp-text "
  4127. - item1
  4128. - sub1
  4129. - sub2
  4130. - sub3
  4131. Inner paragraph.
  4132. - item2
  4133. Outside."
  4134. ;; 5.1. At list top point: expected to move to the element after
  4135. ;; the list.
  4136. (goto-line 2)
  4137. (org-forward-element)
  4138. (should (looking-at (regexp-quote "Outside.")))
  4139. ;; 5.2. Special case: at the first line of a sub-list, but not at
  4140. ;; beginning of line, move to next item.
  4141. (goto-line 2)
  4142. (forward-char)
  4143. (org-forward-element)
  4144. (should (looking-at "- item2"))
  4145. (goto-line 4)
  4146. (forward-char)
  4147. (org-forward-element)
  4148. (should (looking-at " - sub2"))
  4149. ;; 5.3 At sub-list beginning: expected to move after the sub-list.
  4150. (goto-line 4)
  4151. (org-forward-element)
  4152. (should (looking-at (regexp-quote " Inner paragraph.")))
  4153. ;; 5.4. At sub-list end: expected to move outside the sub-list.
  4154. (goto-line 8)
  4155. (org-forward-element)
  4156. (should (looking-at (regexp-quote " Inner paragraph.")))
  4157. ;; 5.5. At an item: expected to move to next item, if any.
  4158. (goto-line 6)
  4159. (org-forward-element)
  4160. (should (looking-at " - sub3"))))
  4161. (ert-deftest test-org/backward-element ()
  4162. "Test `org-backward-element' specifications."
  4163. ;; 1. Should error at BOB.
  4164. (org-test-with-temp-text " \nParagraph."
  4165. (should-error (org-backward-element)))
  4166. ;; 2. Should move at BOB when called on the first element in buffer.
  4167. (should
  4168. (org-test-with-temp-text "\n#+TITLE: test"
  4169. (progn (forward-line)
  4170. (org-backward-element)
  4171. (bobp))))
  4172. ;; 3. Not at the beginning of an element: move at its beginning.
  4173. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  4174. (goto-line 3)
  4175. (end-of-line)
  4176. (org-backward-element)
  4177. (should (looking-at (regexp-quote "Paragraph2."))))
  4178. ;; 4. Headline tests.
  4179. (org-test-with-temp-text "
  4180. * Head 1
  4181. ** Head 1.1
  4182. *** Head 1.1.1
  4183. ** Head 1.2"
  4184. ;; 4.1. At an headline beginning: move to previous headline at the
  4185. ;; same level.
  4186. (goto-line 5)
  4187. (org-backward-element)
  4188. (should (looking-at (regexp-quote "** Head 1.1")))
  4189. ;; 4.2. At an headline beginning: move to parent headline if no
  4190. ;; headline at the same level.
  4191. (goto-line 3)
  4192. (org-backward-element)
  4193. (should (looking-at (regexp-quote "* Head 1")))
  4194. ;; 4.3. At the first top-level headline: should error.
  4195. (goto-line 2)
  4196. (should-error (org-backward-element)))
  4197. ;; 5. At beginning of first element inside a greater element:
  4198. ;; expected to move to greater element's beginning.
  4199. (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
  4200. (goto-line 3)
  4201. (org-backward-element)
  4202. (should (looking-at "#\\+BEGIN_CENTER")))
  4203. ;; 6. At the beginning of the first element in a section: should
  4204. ;; move back to headline, if any.
  4205. (should
  4206. (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
  4207. (progn (goto-char (point-max))
  4208. (beginning-of-line)
  4209. (org-backward-element)
  4210. (org-at-heading-p))))
  4211. ;; 7. List tests.
  4212. (org-test-with-temp-text "
  4213. - item1
  4214. - sub1
  4215. - sub2
  4216. - sub3
  4217. Inner paragraph.
  4218. - item2
  4219. Outside."
  4220. ;; 7.1. At beginning of sub-list: expected to move to the
  4221. ;; paragraph before it.
  4222. (goto-line 4)
  4223. (org-backward-element)
  4224. (should (looking-at "item1"))
  4225. ;; 7.2. At an item in a list: expected to move at previous item.
  4226. (goto-line 8)
  4227. (org-backward-element)
  4228. (should (looking-at " - sub2"))
  4229. (goto-line 12)
  4230. (org-backward-element)
  4231. (should (looking-at "- item1"))
  4232. ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
  4233. ;; beginning.
  4234. (goto-line 10)
  4235. (org-backward-element)
  4236. (should (looking-at " - sub1"))
  4237. (goto-line 15)
  4238. (org-backward-element)
  4239. (should (looking-at "- item1"))
  4240. ;; 7.4. At blank-lines before list end: expected to move to top
  4241. ;; item.
  4242. (goto-line 14)
  4243. (org-backward-element)
  4244. (should (looking-at "- item1"))))
  4245. (ert-deftest test-org/up-element ()
  4246. "Test `org-up-element' specifications."
  4247. ;; 1. At BOB or with no surrounding element: should error.
  4248. (org-test-with-temp-text "Paragraph."
  4249. (should-error (org-up-element)))
  4250. (org-test-with-temp-text "* Head1\n* Head2"
  4251. (goto-line 2)
  4252. (should-error (org-up-element)))
  4253. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  4254. (goto-line 3)
  4255. (should-error (org-up-element)))
  4256. ;; 2. At an headline: move to parent headline.
  4257. (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
  4258. (goto-line 3)
  4259. (org-up-element)
  4260. (should (looking-at "\\* Head1")))
  4261. ;; 3. Inside a greater element: move to greater element beginning.
  4262. (org-test-with-temp-text
  4263. "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
  4264. (goto-line 3)
  4265. (org-up-element)
  4266. (should (looking-at "#\\+BEGIN_CENTER")))
  4267. ;; 4. List tests.
  4268. (org-test-with-temp-text "* Top
  4269. - item1
  4270. - sub1
  4271. - sub2
  4272. Paragraph within sub2.
  4273. - item2"
  4274. ;; 4.1. Within an item: move to the item beginning.
  4275. (goto-line 8)
  4276. (org-up-element)
  4277. (should (looking-at " - sub2"))
  4278. ;; 4.2. At an item in a sub-list: move to parent item.
  4279. (goto-line 4)
  4280. (org-up-element)
  4281. (should (looking-at "- item1"))
  4282. ;; 4.3. At an item in top list: move to beginning of whole list.
  4283. (goto-line 10)
  4284. (org-up-element)
  4285. (should (looking-at "- item1"))
  4286. ;; 4.4. Special case. At very top point: should move to parent of
  4287. ;; list.
  4288. (goto-line 2)
  4289. (org-up-element)
  4290. (should (looking-at "\\* Top"))))
  4291. (ert-deftest test-org/down-element ()
  4292. "Test `org-down-element' specifications."
  4293. ;; Error when the element hasn't got a recursive type.
  4294. (org-test-with-temp-text "Paragraph."
  4295. (should-error (org-down-element)))
  4296. ;; Error when the element has no contents
  4297. (org-test-with-temp-text "* Headline"
  4298. (should-error (org-down-element)))
  4299. ;; When at a plain-list, move to first item.
  4300. (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
  4301. (goto-line 2)
  4302. (org-down-element)
  4303. (should (looking-at " - Item 1.1")))
  4304. (org-test-with-temp-text "#+NAME: list\n- Item 1"
  4305. (org-down-element)
  4306. (should (looking-at " Item 1")))
  4307. ;; When at a table, move to first row
  4308. (org-test-with-temp-text "#+NAME: table\n| a | b |"
  4309. (org-down-element)
  4310. (should (looking-at " a | b |")))
  4311. ;; Otherwise, move inside the greater element.
  4312. (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
  4313. (org-down-element)
  4314. (should (looking-at "Paragraph"))))
  4315. (ert-deftest test-org/drag-element-backward ()
  4316. "Test `org-drag-element-backward' specifications."
  4317. ;; Standard test.
  4318. (should
  4319. (equal
  4320. "#+key2: val2\n#+key1: val1\n#+key3: val3"
  4321. (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
  4322. (org-drag-element-backward)
  4323. (buffer-string))))
  4324. (should
  4325. (equal
  4326. "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
  4327. (org-test-with-temp-text
  4328. "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
  4329. (org-drag-element-backward)
  4330. (buffer-string))))
  4331. ;; Preserve blank lines.
  4332. (should
  4333. (equal "Paragraph 2\n\n\nPara1\n\nPara3"
  4334. (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
  4335. (org-drag-element-backward)
  4336. (buffer-string))))
  4337. ;; Preserve column.
  4338. (should
  4339. (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
  4340. (org-drag-element-backward)
  4341. (looking-at-p "2")))
  4342. ;; Error when trying to move first element of buffer.
  4343. (should-error
  4344. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4345. (org-drag-element-backward))
  4346. :type 'user-error)
  4347. ;; Error when trying to swap nested elements.
  4348. (should-error
  4349. (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
  4350. (org-drag-element-backward))
  4351. :type 'user-error)
  4352. ;; Error when trying to swap an headline element and a non-headline
  4353. ;; element.
  4354. (should-error
  4355. (org-test-with-temp-text "Test.\n<point>* Head 1"
  4356. (org-drag-element-backward))
  4357. :type 'error)
  4358. ;; Error when called before first element.
  4359. (should-error
  4360. (org-test-with-temp-text "\n<point>"
  4361. (org-drag-element-backward))
  4362. :type 'user-error)
  4363. ;; Preserve visibility of elements and their contents.
  4364. (should
  4365. (equal '((63 . 82) (26 . 48))
  4366. (let ((org-fold-core-style 'text-properties))
  4367. (org-test-with-temp-text
  4368. "
  4369. #+BEGIN_CENTER
  4370. Text.
  4371. #+END_CENTER
  4372. - item 1
  4373. #+BEGIN_QUOTE
  4374. Text.
  4375. #+END_QUOTE"
  4376. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4377. (search-backward "- item 1")
  4378. (org-drag-element-backward)
  4379. (let (regions)
  4380. (goto-char (point-min))
  4381. (while (< (point) (point-max))
  4382. (let ((region (org-fold-get-region-at-point)))
  4383. (if (not region)
  4384. (goto-char (org-fold-next-folding-state-change))
  4385. (goto-char (cdr region))
  4386. (push region regions))))
  4387. regions)))))
  4388. (should
  4389. (equal '((63 . 82) (26 . 48))
  4390. (let ((org-fold-core-style 'overlays))
  4391. (org-test-with-temp-text
  4392. "
  4393. #+BEGIN_CENTER
  4394. Text.
  4395. #+END_CENTER
  4396. - item 1
  4397. #+BEGIN_QUOTE
  4398. Text.
  4399. #+END_QUOTE"
  4400. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4401. (search-backward "- item 1")
  4402. (org-drag-element-backward)
  4403. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4404. (overlays-in (point-min) (point-max)))))))
  4405. ;; Pathological case: handle call with point in blank lines right
  4406. ;; after a headline.
  4407. (should
  4408. (equal "* H2\n\n* H1\nText\n"
  4409. (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
  4410. (org-drag-element-backward)
  4411. (buffer-string)))))
  4412. (ert-deftest test-org/drag-element-forward ()
  4413. "Test `org-drag-element-forward' specifications."
  4414. ;; 1. Error when trying to move first element of buffer.
  4415. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4416. (goto-line 3)
  4417. (should-error (org-drag-element-forward)))
  4418. ;; 2. Error when trying to swap nested elements.
  4419. (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
  4420. (forward-line)
  4421. (should-error (org-drag-element-forward)))
  4422. ;; 3. Error when trying to swap a non-headline element and an
  4423. ;; headline.
  4424. (org-test-with-temp-text "Test.\n* Head 1"
  4425. (should-error (org-drag-element-forward)))
  4426. ;; 4. Error when called before first element.
  4427. (should-error
  4428. (org-test-with-temp-text "\n"
  4429. (forward-line)
  4430. (org-drag-element-backward))
  4431. :type 'user-error)
  4432. ;; 5. Otherwise, swap elements, preserving column and blank lines
  4433. ;; between elements.
  4434. (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
  4435. (search-forward "graph")
  4436. (org-drag-element-forward)
  4437. (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
  4438. (should (looking-at " 1")))
  4439. ;; 5. Preserve visibility of elements and their contents.
  4440. (let ((org-fold-core-style 'text-properties))
  4441. (org-test-with-temp-text
  4442. "
  4443. #+BEGIN_CENTER
  4444. Text.
  4445. #+END_CENTER
  4446. - item 1
  4447. #+BEGIN_QUOTE
  4448. Text.
  4449. #+END_QUOTE"
  4450. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4451. (search-backward "#+BEGIN_CENTER")
  4452. (org-drag-element-forward)
  4453. (should
  4454. (equal
  4455. '((63 . 82) (26 . 48))
  4456. (let (regions)
  4457. (goto-char (point-min))
  4458. (while (< (point) (point-max))
  4459. (let ((region (org-fold-get-region-at-point)))
  4460. (if (not region)
  4461. (goto-char (org-fold-next-folding-state-change))
  4462. (goto-char (cdr region))
  4463. (push region regions))))
  4464. regions)))))
  4465. (let ((org-fold-core-style 'overlays))
  4466. (org-test-with-temp-text
  4467. "
  4468. #+BEGIN_CENTER
  4469. Text.
  4470. #+END_CENTER
  4471. - item 1
  4472. #+BEGIN_QUOTE
  4473. Text.
  4474. #+END_QUOTE"
  4475. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4476. (search-backward "#+BEGIN_CENTER")
  4477. (org-drag-element-forward)
  4478. (should
  4479. (equal
  4480. '((63 . 82) (26 . 48))
  4481. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4482. (overlays-in (point-min) (point-max))))))))
  4483. (ert-deftest test-org/next-block ()
  4484. "Test `org-next-block' specifications."
  4485. ;; Regular test.
  4486. (should
  4487. (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  4488. (org-next-block 1)
  4489. (looking-at "#\\+BEGIN_CENTER")))
  4490. ;; Ignore case.
  4491. (should
  4492. (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
  4493. (let ((case-fold-search nil))
  4494. (org-next-block 1)
  4495. (looking-at "#\\+begin_center"))))
  4496. ;; Ignore current line.
  4497. (should
  4498. (org-test-with-temp-text
  4499. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
  4500. (org-next-block 1)
  4501. (looking-at "#\\+BEGIN_CENTER")))
  4502. ;; Throw an error when no block is found.
  4503. (should-error
  4504. (org-test-with-temp-text "Paragraph"
  4505. (org-next-block 1)))
  4506. ;; With an argument, skip many blocks at once.
  4507. (should
  4508. (org-test-with-temp-text
  4509. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4510. (org-next-block 2)
  4511. (looking-at "#\\+BEGIN_QUOTE")))
  4512. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4513. (should
  4514. (org-test-with-temp-text
  4515. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4516. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4517. (looking-at "#\\+BEGIN_QUOTE")))
  4518. ;; Optional argument is also case-insensitive.
  4519. (should
  4520. (org-test-with-temp-text
  4521. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
  4522. (let ((case-fold-search nil))
  4523. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4524. (looking-at "#\\+begin_quote")))))
  4525. (ert-deftest test-org/insert-structure-template ()
  4526. "Test `org-insert-structure-template'."
  4527. ;; Test in empty buffer.
  4528. (should
  4529. (string= "#+begin_foo\n#+end_foo\n"
  4530. (org-test-with-temp-text ""
  4531. (org-insert-structure-template "foo")
  4532. (buffer-string))))
  4533. ;; Test with multiple lines in buffer.
  4534. (should
  4535. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4536. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4537. (transient-mark-mode 1)
  4538. (org-mark-element)
  4539. (org-insert-structure-template "foo")
  4540. (buffer-string))))
  4541. ;; Mark only the current line.
  4542. (should
  4543. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4544. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4545. (transient-mark-mode 1)
  4546. (set-mark (point-min))
  4547. (end-of-line)
  4548. (org-insert-structure-template "foo")
  4549. (buffer-string))))
  4550. ;; Middle of paragraph.
  4551. (should
  4552. (string= "p1\n#+begin_foo\np2\n#+end_foo\np3"
  4553. (org-test-with-temp-text "p1\n<point>p2\np3"
  4554. (set-mark (line-beginning-position))
  4555. (end-of-line)
  4556. (activate-mark)
  4557. (org-insert-structure-template "foo")
  4558. (buffer-string))))
  4559. ;; Test with text in buffer, no region, no final newline.
  4560. (should
  4561. (string= "#+begin_foo\nI'm a paragraph.\n#+end_foo\n"
  4562. (org-test-with-temp-text "I'm a paragraph."
  4563. (org-mark-element)
  4564. (org-insert-structure-template "foo")
  4565. (buffer-string))))
  4566. ;; Test with text in buffer and region set.
  4567. (should
  4568. (string= "#+begin_foo\nI'm a paragraph\n\nI'm a second paragrah\n#+end_foo\n"
  4569. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragrah"
  4570. (set-mark (point))
  4571. (goto-char (point-max))
  4572. (org-insert-structure-template "foo")
  4573. (buffer-string))))
  4574. ;; Test with example escaping.
  4575. (should
  4576. (string= "#+begin_example\n,* Heading\n#+end_example\n"
  4577. (org-test-with-temp-text "* Heading"
  4578. (org-mark-element)
  4579. (org-insert-structure-template "example")
  4580. (buffer-string))))
  4581. ;; Test with indentation.
  4582. (should
  4583. (string= " #+begin_foo\n This is a paragraph\n #+end_foo\n"
  4584. (org-test-with-temp-text " This is a paragraph"
  4585. (org-mark-element)
  4586. (org-insert-structure-template "foo")
  4587. (buffer-string))))
  4588. (should
  4589. (string= " #+begin_foo\n Line 1\n Line2\n #+end_foo\n"
  4590. (org-test-with-temp-text " Line 1\n Line2"
  4591. (org-mark-element)
  4592. (org-insert-structure-template "foo")
  4593. (buffer-string))))
  4594. ;; Test point location.
  4595. (should
  4596. (string= "#+begin_foo\n"
  4597. (org-test-with-temp-text ""
  4598. (org-insert-structure-template "foo")
  4599. (buffer-substring (point-min) (point)))))
  4600. (should
  4601. (string= "#+begin_src "
  4602. (org-test-with-temp-text ""
  4603. (org-insert-structure-template "src")
  4604. (buffer-substring (point-min) (point))))))
  4605. (ert-deftest test-org/previous-block ()
  4606. "Test `org-previous-block' specifications."
  4607. ;; Regular test.
  4608. (should
  4609. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
  4610. (org-previous-block 1)
  4611. (looking-at "#\\+BEGIN_CENTER")))
  4612. ;; Ignore case.
  4613. (should
  4614. (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
  4615. (let ((case-fold-search nil))
  4616. (org-previous-block 1)
  4617. (looking-at "#\\+begin_center"))))
  4618. ;; Ignore current line.
  4619. (should
  4620. (org-test-with-temp-text
  4621. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
  4622. (org-previous-block 1)
  4623. (looking-at "#\\+BEGIN_QUOTE")))
  4624. ;; Throw an error when no block is found.
  4625. (should-error
  4626. (org-test-with-temp-text "Paragraph<point>"
  4627. (org-previous-block 1)))
  4628. ;; With an argument, skip many blocks at once.
  4629. (should
  4630. (org-test-with-temp-text
  4631. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4632. (org-previous-block 2)
  4633. (looking-at "#\\+BEGIN_CENTER")))
  4634. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4635. (should
  4636. (org-test-with-temp-text
  4637. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4638. (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4639. (looking-at "#\\+BEGIN_QUOTE")))
  4640. ;; Optional argument is also case-insensitive.
  4641. (should
  4642. (org-test-with-temp-text
  4643. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
  4644. (let ((case-fold-search nil))
  4645. (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4646. (looking-at "#\\+begin_quote")))))
  4647. ;;; Outline structure
  4648. (ert-deftest test-org/demote ()
  4649. "Test `org-demote' specifications."
  4650. ;; Add correct number of stars according to `org-odd-levels-only'.
  4651. (should
  4652. (= 2
  4653. (org-test-with-temp-text "* H"
  4654. (let ((org-odd-levels-only nil)) (org-demote))
  4655. (org-current-level))))
  4656. (should
  4657. (= 3
  4658. (org-test-with-temp-text "* H"
  4659. (let ((org-odd-levels-only t)) (org-demote))
  4660. (org-current-level))))
  4661. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4662. (should
  4663. (org-test-with-temp-text "* H :tag:"
  4664. (let ((org-tags-column 10)
  4665. (org-auto-align-tags t)
  4666. (org-odd-levels-only nil))
  4667. (org-demote))
  4668. (org-move-to-column 10)
  4669. (looking-at-p ":tag:$")))
  4670. (should-not
  4671. (org-test-with-temp-text "* H :tag:"
  4672. (let ((org-tags-column 10)
  4673. (org-auto-align-tags nil)
  4674. (org-odd-levels-only nil))
  4675. (org-demote))
  4676. (org-move-to-column 10)
  4677. (looking-at-p ":tag:$")))
  4678. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4679. ;; info and property drawers accordingly.
  4680. (should
  4681. (= 3
  4682. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4683. (let ((org-odd-levels-only nil)
  4684. (org-adapt-indentation t))
  4685. (org-demote))
  4686. (forward-line)
  4687. (org-get-indentation))))
  4688. (should
  4689. (= 3
  4690. (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4691. (let ((org-odd-levels-only nil)
  4692. (org-adapt-indentation t))
  4693. (org-demote))
  4694. (forward-line)
  4695. (org-get-indentation))))
  4696. (should-not
  4697. (= 3
  4698. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4699. (let ((org-odd-levels-only nil)
  4700. (org-adapt-indentation nil))
  4701. (org-demote))
  4702. (forward-line)
  4703. (org-get-indentation))))
  4704. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4705. ;; section accordingly. Ignore, however, footnote definitions and
  4706. ;; inlinetasks boundaries.
  4707. (should
  4708. (= 3
  4709. (org-test-with-temp-text "* H\n Paragraph"
  4710. (let ((org-odd-levels-only nil)
  4711. (org-adapt-indentation t))
  4712. (org-demote))
  4713. (forward-line)
  4714. (org-get-indentation))))
  4715. (should
  4716. (= 2
  4717. (org-test-with-temp-text "* H\n Paragraph"
  4718. (let ((org-odd-levels-only nil)
  4719. (org-adapt-indentation nil))
  4720. (org-demote))
  4721. (forward-line)
  4722. (org-get-indentation))))
  4723. (should
  4724. (zerop
  4725. (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
  4726. (let ((org-odd-levels-only nil)
  4727. (org-adapt-indentation t))
  4728. (org-demote))
  4729. (goto-char (point-max))
  4730. (org-get-indentation))))
  4731. (should
  4732. (= 3
  4733. (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
  4734. (let ((org-odd-levels-only nil)
  4735. (org-adapt-indentation t))
  4736. (org-demote))
  4737. (goto-char (point-max))
  4738. (org-get-indentation))))
  4739. (when (featurep 'org-inlinetask)
  4740. (should
  4741. (zerop
  4742. (let ((org-inlinetask-min-level 5)
  4743. (org-adapt-indentation t))
  4744. (org-test-with-temp-text "* H\n***** I\n***** END"
  4745. (org-demote)
  4746. (forward-line)
  4747. (org-get-indentation))))))
  4748. (when (featurep 'org-inlinetask)
  4749. (should
  4750. (= 3
  4751. (let ((org-inlinetask-min-level 5)
  4752. (org-adapt-indentation t))
  4753. (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
  4754. (org-demote)
  4755. (forward-line 2)
  4756. (org-get-indentation))))))
  4757. ;; When `org-adapt-indentation' is non-nil, log drawers are
  4758. ;; adjusted.
  4759. (should
  4760. (equal
  4761. "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4762. (org-test-with-temp-text "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4763. (let ((org-odd-levels-only nil)
  4764. (org-adapt-indentation t))
  4765. (org-demote))
  4766. (buffer-string))))
  4767. (should
  4768. (equal
  4769. "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4770. (org-test-with-temp-text "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4771. (let ((org-odd-levels-only nil)
  4772. (org-adapt-indentation 'headline-data))
  4773. (org-demote))
  4774. (buffer-string))))
  4775. (should
  4776. (equal
  4777. "** H\n :LOGBOOK:\n - a\n :END:"
  4778. (org-test-with-temp-text "* H\n:LOGBOOK:\n- a\n:END:"
  4779. (let ((org-odd-levels-only nil)
  4780. (org-adapt-indentation t))
  4781. (org-demote))
  4782. (buffer-string))))
  4783. ;; Ignore contents of source blocks or example blocks when
  4784. ;; indentation should be preserved (through
  4785. ;; `org-src-preserve-indentation' or "-i" flag).
  4786. (should-not
  4787. (zerop
  4788. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4789. (let ((org-adapt-indentation t)
  4790. (org-src-preserve-indentation nil))
  4791. (org-demote))
  4792. (forward-line 2)
  4793. (org-get-indentation))))
  4794. (should
  4795. (zerop
  4796. (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
  4797. (let ((org-adapt-indentation t)
  4798. (org-src-preserve-indentation t))
  4799. (org-demote))
  4800. (forward-line 2)
  4801. (org-get-indentation))))
  4802. (should
  4803. (zerop
  4804. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4805. (let ((org-adapt-indentation t)
  4806. (org-src-preserve-indentation t))
  4807. (org-demote))
  4808. (forward-line 2)
  4809. (org-get-indentation))))
  4810. (should
  4811. (zerop
  4812. (org-test-with-temp-text
  4813. "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
  4814. (let ((org-adapt-indentation t)
  4815. (org-src-preserve-indentation nil))
  4816. (org-demote))
  4817. (forward-line 2)
  4818. (org-get-indentation)))))
  4819. (ert-deftest test-org/promote ()
  4820. "Test `org-promote' specifications."
  4821. ;; Return an error if headline is to be promoted to level 0, unless
  4822. ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
  4823. ;; headline becomes a comment.
  4824. (should-error
  4825. (org-test-with-temp-text "* H"
  4826. (let ((org-allow-promoting-top-level-subtree nil)) (org-promote))))
  4827. (should
  4828. (equal "# H"
  4829. (org-test-with-temp-text "* H"
  4830. (let ((org-allow-promoting-top-level-subtree t)) (org-promote))
  4831. (buffer-string))))
  4832. ;; Remove correct number of stars according to
  4833. ;; `org-odd-levels-only'.
  4834. (should
  4835. (= 2
  4836. (org-test-with-temp-text "*** H"
  4837. (let ((org-odd-levels-only nil)) (org-promote))
  4838. (org-current-level))))
  4839. (should
  4840. (= 1
  4841. (org-test-with-temp-text "*** H"
  4842. (let ((org-odd-levels-only t)) (org-promote))
  4843. (org-current-level))))
  4844. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4845. (should
  4846. (org-test-with-temp-text "** H :tag:"
  4847. (let ((org-tags-column 10)
  4848. (org-auto-align-tags t)
  4849. (org-odd-levels-only nil))
  4850. (org-promote))
  4851. (org-move-to-column 10)
  4852. (looking-at-p ":tag:$")))
  4853. (should-not
  4854. (org-test-with-temp-text "** H :tag:"
  4855. (let ((org-tags-column 10)
  4856. (org-auto-align-tags nil)
  4857. (org-odd-levels-only nil))
  4858. (org-promote))
  4859. (org-move-to-column 10)
  4860. (looking-at-p ":tag:$")))
  4861. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4862. ;; info and property drawers.
  4863. (should
  4864. (= 2
  4865. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4866. (let ((org-odd-levels-only nil)
  4867. (org-adapt-indentation t))
  4868. (org-promote))
  4869. (forward-line)
  4870. (org-get-indentation))))
  4871. (should
  4872. (= 2
  4873. (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4874. (let ((org-odd-levels-only nil)
  4875. (org-adapt-indentation t))
  4876. (org-promote))
  4877. (forward-line)
  4878. (org-get-indentation))))
  4879. (should-not
  4880. (= 2
  4881. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4882. (let ((org-odd-levels-only nil)
  4883. (org-adapt-indentation nil))
  4884. (org-promote))
  4885. (forward-line)
  4886. (org-get-indentation))))
  4887. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4888. ;; section accordingly. Ignore, however, footnote definitions and
  4889. ;; inlinetasks boundaries.
  4890. (should
  4891. (= 2
  4892. (org-test-with-temp-text "** H\n Paragraph"
  4893. (let ((org-odd-levels-only nil)
  4894. (org-adapt-indentation t))
  4895. (org-promote))
  4896. (forward-line)
  4897. (org-get-indentation))))
  4898. (should-not
  4899. (= 2
  4900. (org-test-with-temp-text "** H\n Paragraph"
  4901. (let ((org-odd-levels-only nil)
  4902. (org-adapt-indentation nil))
  4903. (org-promote))
  4904. (forward-line)
  4905. (org-get-indentation))))
  4906. (should
  4907. (= 2
  4908. (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
  4909. (let ((org-odd-levels-only nil)
  4910. (org-adapt-indentation t))
  4911. (org-promote))
  4912. (forward-line)
  4913. (org-get-indentation))))
  4914. (when (featurep 'org-inlinetask)
  4915. (should
  4916. (zerop
  4917. (let ((org-inlinetask-min-level 5)
  4918. (org-adapt-indentation t))
  4919. (org-test-with-temp-text "** H\n***** I\n***** END"
  4920. (org-promote)
  4921. (forward-line)
  4922. (org-get-indentation))))))
  4923. (when (featurep 'org-inlinetask)
  4924. (should
  4925. (= 2
  4926. (let ((org-inlinetask-min-level 5)
  4927. (org-adapt-indentation t))
  4928. (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
  4929. (org-promote)
  4930. (forward-line 2)
  4931. (org-get-indentation))))))
  4932. ;; Give up shifting if it would break document's structure
  4933. ;; otherwise.
  4934. (should
  4935. (= 3
  4936. (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
  4937. (let ((org-odd-levels-only nil)
  4938. (org-adapt-indentation t))
  4939. (org-promote))
  4940. (forward-line)
  4941. (org-get-indentation))))
  4942. (should
  4943. (= 3
  4944. (org-test-with-temp-text "** H\n Paragraph\n * list."
  4945. (let ((org-odd-levels-only nil)
  4946. (org-adapt-indentation t))
  4947. (org-promote))
  4948. (forward-line)
  4949. (org-get-indentation))))
  4950. ;; When `org-adapt-indentation' is non-nil, log drawers are
  4951. ;; adjusted.
  4952. (should
  4953. (equal
  4954. "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4955. (org-test-with-temp-text "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4956. (let ((org-odd-levels-only nil)
  4957. (org-adapt-indentation t))
  4958. (org-promote))
  4959. (buffer-string))))
  4960. (should
  4961. (equal
  4962. "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4963. (org-test-with-temp-text "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4964. (let ((org-odd-levels-only nil)
  4965. (org-adapt-indentation 'headline-data))
  4966. (org-promote))
  4967. (buffer-string))))
  4968. (should
  4969. (equal
  4970. "* H\n:LOGBOOK:\n- a\n:END:"
  4971. (org-test-with-temp-text "** H\n:LOGBOOK:\n- a\n:END:"
  4972. (let ((org-odd-levels-only nil)
  4973. (org-adapt-indentation t))
  4974. (org-promote))
  4975. (buffer-string))))
  4976. (should
  4977. (equal
  4978. "# H\n:LOGBOOK:\n- a\n:END:"
  4979. (org-test-with-temp-text "* H\n:LOGBOOK:\n- a\n:END:"
  4980. (let ((org-odd-levels-only nil)
  4981. (org-allow-promoting-top-level-subtree t)
  4982. (org-adapt-indentation t))
  4983. (org-promote))
  4984. (buffer-string))))
  4985. ;; Ignore contents of source blocks or example blocks when
  4986. ;; indentation should be preserved (through
  4987. ;; `org-src-preserve-indentation' or "-i" flag).
  4988. (should-not
  4989. (zerop
  4990. (org-test-with-temp-text
  4991. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  4992. (let ((org-adapt-indentation t)
  4993. (org-src-preserve-indentation nil)
  4994. (org-odd-levels-only nil))
  4995. (org-promote))
  4996. (forward-line)
  4997. (org-get-indentation))))
  4998. (should
  4999. (zerop
  5000. (org-test-with-temp-text
  5001. "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
  5002. (let ((org-adapt-indentation t)
  5003. (org-src-preserve-indentation t)
  5004. (org-odd-levels-only nil))
  5005. (org-promote))
  5006. (forward-line)
  5007. (org-get-indentation))))
  5008. (should
  5009. (zerop
  5010. (org-test-with-temp-text
  5011. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  5012. (let ((org-adapt-indentation t)
  5013. (org-src-preserve-indentation t)
  5014. (org-odd-levels-only nil))
  5015. (org-promote))
  5016. (forward-line)
  5017. (org-get-indentation))))
  5018. (should
  5019. (zerop
  5020. (org-test-with-temp-text
  5021. "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
  5022. (let ((org-adapt-indentation t)
  5023. (org-src-preserve-indentation nil)
  5024. (org-odd-levels-only nil))
  5025. (org-promote))
  5026. (forward-line)
  5027. (org-get-indentation)))))
  5028. (ert-deftest test-org/org-get-valid-level ()
  5029. "Test function `org-get-valid-level' specifications."
  5030. (let ((org-odd-levels-only nil))
  5031. (should (equal 1 (org-get-valid-level 0 0)))
  5032. (should (equal 1 (org-get-valid-level 0 1)))
  5033. (should (equal 2 (org-get-valid-level 0 2)))
  5034. (should (equal 3 (org-get-valid-level 0 3)))
  5035. (should (equal 1 (org-get-valid-level 1 0)))
  5036. (should (equal 2 (org-get-valid-level 1 1)))
  5037. (should (equal 23 (org-get-valid-level 1 22)))
  5038. (should (equal 1 (org-get-valid-level 1 -1)))
  5039. (should (equal 1 (org-get-valid-level 2 -1))))
  5040. (let ((org-odd-levels-only t))
  5041. (should (equal 1 (org-get-valid-level 0 0)))
  5042. (should (equal 1 (org-get-valid-level 0 1)))
  5043. (should (equal 3 (org-get-valid-level 0 2)))
  5044. (should (equal 5 (org-get-valid-level 0 3)))
  5045. (should (equal 1 (org-get-valid-level 1 0)))
  5046. (should (equal 3 (org-get-valid-level 1 1)))
  5047. (should (equal 3 (org-get-valid-level 2 1)))
  5048. (should (equal 5 (org-get-valid-level 3 1)))
  5049. (should (equal 5 (org-get-valid-level 4 1)))
  5050. (should (equal 43 (org-get-valid-level 1 21)))
  5051. (should (equal 1 (org-get-valid-level 1 -1)))
  5052. (should (equal 1 (org-get-valid-level 2 -1)))
  5053. (should (equal 1 (org-get-valid-level 3 -1)))
  5054. (should (equal 3 (org-get-valid-level 4 -1)))
  5055. (should (equal 3 (org-get-valid-level 5 -1)))))
  5056. ;;; Planning
  5057. (ert-deftest test-org/at-planning-p ()
  5058. "Test `org-at-planning-p' specifications."
  5059. ;; Regular test.
  5060. (should
  5061. (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
  5062. (org-at-planning-p)))
  5063. (should-not
  5064. (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
  5065. (org-at-planning-p)))
  5066. ;; Correctly find planning attached to inlinetasks.
  5067. (when (featurep 'org-inlinetask)
  5068. (should
  5069. (org-test-with-temp-text
  5070. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
  5071. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  5072. (should-not
  5073. (org-test-with-temp-text
  5074. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  5075. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  5076. (should-not
  5077. (org-test-with-temp-text
  5078. "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  5079. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  5080. (should-not
  5081. (org-test-with-temp-text
  5082. "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
  5083. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
  5084. (ert-deftest test-org/add-planning-info ()
  5085. "Test `org-add-planning-info'."
  5086. ;; Create deadline when `org-adapt-indentation' is non-nil.
  5087. (should
  5088. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5089. (org-test-with-temp-text "* H\nParagraph<point>"
  5090. (let ((org-adapt-indentation t))
  5091. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5092. (replace-regexp-in-string
  5093. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5094. nil nil 1))))
  5095. ;; Create deadline when `org-adapt-indentation' is nil.
  5096. (should
  5097. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  5098. (org-test-with-temp-text "* H\nParagraph<point>"
  5099. (let ((org-adapt-indentation nil))
  5100. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5101. (replace-regexp-in-string
  5102. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5103. nil nil 1))))
  5104. ;; Update deadline when `org-adapt-indentation' is non-nil.
  5105. (should
  5106. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5107. (org-test-with-temp-text "\
  5108. * H
  5109. DEADLINE: <2015-06-24 Wed>
  5110. Paragraph<point>"
  5111. (let ((org-adapt-indentation t))
  5112. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5113. (replace-regexp-in-string
  5114. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5115. nil nil 1))))
  5116. ;; Update deadline when `org-adapt-indentation' is nil.
  5117. (should
  5118. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  5119. (org-test-with-temp-text "\
  5120. * H
  5121. DEADLINE: <2015-06-24 Wed>
  5122. Paragraph<point>"
  5123. (let ((org-adapt-indentation nil))
  5124. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5125. (replace-regexp-in-string
  5126. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5127. nil nil 1))))
  5128. ;; Schedule when `org-adapt-indentation' is non-nil.
  5129. (should
  5130. (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
  5131. (org-test-with-temp-text "* H\nParagraph<point>"
  5132. (let ((org-adapt-indentation t))
  5133. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  5134. (replace-regexp-in-string
  5135. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5136. nil nil 1))))
  5137. ;; Schedule when `org-adapt-indentation' is nil.
  5138. (should
  5139. (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
  5140. (org-test-with-temp-text "* H\nParagraph<point>"
  5141. (let ((org-adapt-indentation nil))
  5142. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  5143. (replace-regexp-in-string
  5144. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5145. nil nil 1))))
  5146. ;; Add deadline when scheduled.
  5147. (should
  5148. (equal "\
  5149. * H
  5150. DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
  5151. Paragraph"
  5152. (org-test-with-temp-text "\
  5153. * H
  5154. SCHEDULED: <2015-06-24 Wed>
  5155. Paragraph<point>"
  5156. (let ((org-adapt-indentation t))
  5157. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5158. (replace-regexp-in-string
  5159. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5160. nil nil 1))))
  5161. ;; Remove middle entry.
  5162. (should
  5163. (equal "\
  5164. * H
  5165. CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
  5166. Paragraph"
  5167. (org-test-with-temp-text "\
  5168. * H
  5169. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  5170. Paragraph<point>"
  5171. (let ((org-adapt-indentation t))
  5172. (org-add-planning-info nil nil 'deadline))
  5173. (replace-regexp-in-string
  5174. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  5175. nil nil 1))))
  5176. ;; Remove last entry and then middle entry (order should not
  5177. ;; matter).
  5178. (should
  5179. (equal "\
  5180. * H
  5181. CLOSED: [2015-06-24]
  5182. Paragraph"
  5183. (org-test-with-temp-text "\
  5184. * H
  5185. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  5186. Paragraph<point>"
  5187. (let ((org-adapt-indentation t))
  5188. (org-add-planning-info nil nil 'scheduled 'deadline))
  5189. (replace-regexp-in-string
  5190. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  5191. nil nil 1))))
  5192. ;; Remove closed when `org-adapt-indentation' is non-nil.
  5193. (should
  5194. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5195. (org-test-with-temp-text "\
  5196. * H
  5197. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  5198. Paragraph<point>"
  5199. (let ((org-adapt-indentation t))
  5200. (org-add-planning-info nil nil 'closed))
  5201. (replace-regexp-in-string
  5202. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5203. nil nil 1))))
  5204. (should
  5205. (equal "* H\n Paragraph"
  5206. (org-test-with-temp-text "\
  5207. * H
  5208. CLOSED: [2015-06-25 Thu]
  5209. Paragraph<point>"
  5210. (let ((org-adapt-indentation t))
  5211. (org-add-planning-info nil nil 'closed))
  5212. (replace-regexp-in-string
  5213. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5214. nil nil 1))))
  5215. ;; Remove closed when `org-adapt-indentation' is nil.
  5216. (should
  5217. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  5218. (org-test-with-temp-text "\
  5219. * H
  5220. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  5221. Paragraph<point>"
  5222. (let ((org-adapt-indentation nil))
  5223. (org-add-planning-info nil nil 'closed))
  5224. (replace-regexp-in-string
  5225. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5226. nil nil 1))))
  5227. (should
  5228. (equal "* H\nParagraph"
  5229. (org-test-with-temp-text "\
  5230. * H
  5231. CLOSED: [2015-06-25 Thu]
  5232. Paragraph<point>"
  5233. (let ((org-adapt-indentation nil))
  5234. (org-add-planning-info nil nil 'closed))
  5235. (replace-regexp-in-string
  5236. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5237. nil nil 1))))
  5238. ;; Remove closed entry and delete empty line.
  5239. (should
  5240. (equal "\
  5241. * H
  5242. Paragraph"
  5243. (org-test-with-temp-text "\
  5244. * H
  5245. CLOSED: [2015-06-24 Wed]
  5246. Paragraph<point>"
  5247. (let ((org-adapt-indentation t))
  5248. (org-add-planning-info nil nil 'closed))
  5249. (replace-regexp-in-string
  5250. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5251. nil nil 1))))
  5252. ;; Remove one entry and update another.
  5253. (should
  5254. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5255. (org-test-with-temp-text "\
  5256. * H
  5257. SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
  5258. Paragraph<point>"
  5259. (let ((org-adapt-indentation t))
  5260. (org-add-planning-info 'deadline "<2015-06-25 Thu>" 'scheduled))
  5261. (replace-regexp-in-string
  5262. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5263. nil nil 1)))))
  5264. (ert-deftest test-org/deadline ()
  5265. "Test `org-deadline' specifications."
  5266. ;; Insert a new value or replace existing one.
  5267. (should
  5268. (equal "* H\nDEADLINE: <2012-03-29>"
  5269. (org-test-with-temp-text "* H"
  5270. (let ((org-adapt-indentation nil)
  5271. (org-last-inserted-timestamp nil))
  5272. (org-deadline nil "<2012-03-29 Tue>"))
  5273. (replace-regexp-in-string
  5274. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5275. nil nil 1))))
  5276. (should
  5277. (equal "* H\nDEADLINE: <2014-03-04>"
  5278. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5279. (let ((org-adapt-indentation nil)
  5280. (org-last-inserted-timestamp nil))
  5281. (org-deadline nil "<2014-03-04 Thu>"))
  5282. (replace-regexp-in-string
  5283. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5284. nil nil 1))))
  5285. ;; Accept delta time, e.g., "+2d".
  5286. (should
  5287. (equal "* H\nDEADLINE: <2015-03-04>"
  5288. (org-test-at-time "2014-03-04"
  5289. (org-test-with-temp-text "* H"
  5290. (let ((org-adapt-indentation nil)
  5291. (org-last-inserted-timestamp nil))
  5292. (org-deadline nil "+1y"))
  5293. (replace-regexp-in-string
  5294. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5295. ;; Preserve repeater.
  5296. (should
  5297. (equal "* H\nDEADLINE: <2012-03-29 +2y>"
  5298. (org-test-with-temp-text "* H"
  5299. (let ((org-adapt-indentation nil)
  5300. (org-last-inserted-timestamp nil))
  5301. (org-deadline nil "<2012-03-29 Tue +2y>"))
  5302. (replace-regexp-in-string
  5303. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5304. ;; Preserve warning period.
  5305. (should
  5306. (equal "* H\nDEADLINE: <2021-07-20 -1d>"
  5307. (org-test-with-temp-text "* H"
  5308. (let ((org-adapt-indentation nil)
  5309. (org-last-inserted-timestamp nil))
  5310. (org-deadline nil "<2021-07-20 Tue -1d>"))
  5311. (replace-regexp-in-string
  5312. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5313. (should
  5314. (equal "* H\nDEADLINE: <2021-07-20 +1m -3d>"
  5315. (org-test-with-temp-text "* H"
  5316. (let ((org-adapt-indentation nil)
  5317. (org-last-inserted-timestamp nil))
  5318. (org-deadline nil "<2021-07-20 Tue +1m -3d>"))
  5319. (replace-regexp-in-string
  5320. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5321. ;; Remove CLOSED keyword, if any.
  5322. (should
  5323. (equal "* H\nDEADLINE: <2012-03-29>"
  5324. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  5325. (let ((org-adapt-indentation nil)
  5326. (org-last-inserted-timestamp nil))
  5327. (org-deadline nil "<2012-03-29 Tue>"))
  5328. (replace-regexp-in-string
  5329. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5330. ;; With C-u argument, remove DEADLINE keyword.
  5331. (should
  5332. (equal "* H\n"
  5333. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5334. (let ((org-adapt-indentation nil)
  5335. (org-last-inserted-timestamp nil))
  5336. (org-deadline '(4)))
  5337. (buffer-string))))
  5338. (should
  5339. (equal "* H"
  5340. (org-test-with-temp-text "* H"
  5341. (let ((org-adapt-indentation nil)
  5342. (org-last-inserted-timestamp nil))
  5343. (org-deadline '(4)))
  5344. (buffer-string))))
  5345. ;; With C-u C-u argument, prompt for a delay cookie.
  5346. (should
  5347. (equal "* H\nDEADLINE: <2012-03-29 -705d>"
  5348. (cl-letf (((symbol-function 'org-read-date)
  5349. (lambda (&rest args)
  5350. (apply #'encode-time
  5351. (org-parse-time-string "2014-03-04")))))
  5352. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5353. (let ((org-adapt-indentation nil)
  5354. (org-last-inserted-timestamp nil))
  5355. (org-deadline '(16)))
  5356. (buffer-string)))))
  5357. (should-error
  5358. (cl-letf (((symbol-function 'org-read-date)
  5359. (lambda (&rest args)
  5360. (apply #'encode-time
  5361. (org-parse-time-string "2014-03-04")))))
  5362. (org-test-with-temp-text "* H"
  5363. (let ((org-adapt-indentation nil)
  5364. (org-last-inserted-timestamp nil))
  5365. (org-deadline '(16)))
  5366. (buffer-string))))
  5367. ;; When a region is active and
  5368. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5369. ;; same value in all headlines in region.
  5370. (should
  5371. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5372. (org-test-with-temp-text "* H1\n* H2"
  5373. (let ((org-adapt-indentation nil)
  5374. (org-last-inserted-timestamp nil)
  5375. (org-loop-over-headlines-in-active-region t))
  5376. (transient-mark-mode 1)
  5377. (push-mark (point) t t)
  5378. (goto-char (point-max))
  5379. (org-deadline nil "2012-03-29"))
  5380. (replace-regexp-in-string
  5381. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5382. (should-not
  5383. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5384. (org-test-with-temp-text "* H1\n* H2"
  5385. (let ((org-adapt-indentation nil)
  5386. (org-last-inserted-timestamp nil)
  5387. (org-loop-over-headlines-in-active-region nil))
  5388. (transient-mark-mode 1)
  5389. (push-mark (point) t t)
  5390. (goto-char (point-max))
  5391. (org-deadline nil "2012-03-29"))
  5392. (replace-regexp-in-string
  5393. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5394. (ert-deftest test-org/schedule ()
  5395. "Test `org-schedule' specifications."
  5396. ;; Insert a new value or replace existing one.
  5397. (should
  5398. (equal "* H\nSCHEDULED: <2012-03-29>"
  5399. (org-test-with-temp-text "* H"
  5400. (let ((org-adapt-indentation nil)
  5401. (org-last-inserted-timestamp nil))
  5402. (org-schedule nil "<2012-03-29 Tue>"))
  5403. (replace-regexp-in-string
  5404. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5405. nil nil 1))))
  5406. (should
  5407. (equal "* H\nSCHEDULED: <2014-03-04>"
  5408. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5409. (let ((org-adapt-indentation nil)
  5410. (org-last-inserted-timestamp nil))
  5411. (org-schedule nil "<2014-03-04 Thu>"))
  5412. (replace-regexp-in-string
  5413. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5414. nil nil 1))))
  5415. ;; Accept delta time, e.g., "+2d".
  5416. (should
  5417. (equal "* H\nSCHEDULED: <2015-03-04>"
  5418. (org-test-at-time "2014-03-04"
  5419. (org-test-with-temp-text "* H"
  5420. (let ((org-adapt-indentation nil)
  5421. (org-last-inserted-timestamp nil))
  5422. (org-schedule nil "+1y"))
  5423. (replace-regexp-in-string
  5424. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5425. ;; Preserve repeater.
  5426. (should
  5427. (equal "* H\nSCHEDULED: <2012-03-29 +2y>"
  5428. (org-test-with-temp-text "* H"
  5429. (let ((org-adapt-indentation nil)
  5430. (org-last-inserted-timestamp nil))
  5431. (org-schedule nil "<2012-03-29 Tue +2y>"))
  5432. (replace-regexp-in-string
  5433. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5434. ;; Remove CLOSED keyword, if any.
  5435. (should
  5436. (equal "* H\nSCHEDULED: <2012-03-29>"
  5437. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  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) nil nil 1))))
  5443. ;; With C-u argument, remove SCHEDULED keyword.
  5444. (should
  5445. (equal "* H\n"
  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 '(4)))
  5450. (buffer-string))))
  5451. (should
  5452. (equal "* H"
  5453. (org-test-with-temp-text "* H"
  5454. (let ((org-adapt-indentation nil)
  5455. (org-last-inserted-timestamp nil))
  5456. (org-schedule '(4)))
  5457. (buffer-string))))
  5458. ;; With C-u C-u argument, prompt for a delay cookie.
  5459. (should
  5460. (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
  5461. (cl-letf (((symbol-function 'org-read-date)
  5462. (lambda (&rest args)
  5463. (apply #'encode-time
  5464. (org-parse-time-string "2014-03-04")))))
  5465. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5466. (let ((org-adapt-indentation nil)
  5467. (org-last-inserted-timestamp nil))
  5468. (org-schedule '(16)))
  5469. (buffer-string)))))
  5470. (should-error
  5471. (cl-letf (((symbol-function 'org-read-date)
  5472. (lambda (&rest args)
  5473. (apply #'encode-time
  5474. (org-parse-time-string "2014-03-04")))))
  5475. (org-test-with-temp-text "* H"
  5476. (let ((org-adapt-indentation nil)
  5477. (org-last-inserted-timestamp nil))
  5478. (org-schedule '(16)))
  5479. (buffer-string))))
  5480. ;; When a region is active and
  5481. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5482. ;; same value in all headlines in region.
  5483. (should
  5484. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5485. (org-test-with-temp-text "* H1\n* H2"
  5486. (let ((org-adapt-indentation nil)
  5487. (org-last-inserted-timestamp nil)
  5488. (org-loop-over-headlines-in-active-region t))
  5489. (transient-mark-mode 1)
  5490. (push-mark (point) t t)
  5491. (goto-char (point-max))
  5492. (org-schedule nil "2012-03-29"))
  5493. (replace-regexp-in-string
  5494. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5495. (should-not
  5496. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5497. (org-test-with-temp-text "* H1\n* H2"
  5498. (let ((org-adapt-indentation nil)
  5499. (org-last-inserted-timestamp nil)
  5500. (org-loop-over-headlines-in-active-region nil))
  5501. (transient-mark-mode 1)
  5502. (push-mark (point) t t)
  5503. (goto-char (point-max))
  5504. (org-schedule nil "2012-03-29"))
  5505. (replace-regexp-in-string
  5506. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5507. (should
  5508. ;; check if a repeater survives re-scheduling.
  5509. (string-match-p
  5510. "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
  5511. (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
  5512. (let ((org-adapt-indentation nil)
  5513. (org-last-inserted-timestamp nil))
  5514. (org-schedule nil "2017-02-01"))
  5515. (buffer-string)))))
  5516. ;;; Property API
  5517. (ert-deftest test-org/buffer-property-keys ()
  5518. "Test `org-buffer-property-keys' specifications."
  5519. ;; Retrieve properties across siblings.
  5520. (should
  5521. (equal '("A" "B")
  5522. (org-test-with-temp-text "
  5523. * H1
  5524. :PROPERTIES:
  5525. :A: 1
  5526. :END:
  5527. * H2
  5528. :PROPERTIES:
  5529. :B: 1
  5530. :END:"
  5531. (org-buffer-property-keys))))
  5532. ;; Retrieve properties across children.
  5533. (should
  5534. (equal '("A" "B")
  5535. (org-test-with-temp-text "
  5536. * H1
  5537. :PROPERTIES:
  5538. :A: 1
  5539. :END:
  5540. ** H2
  5541. :PROPERTIES:
  5542. :B: 1
  5543. :END:"
  5544. (org-buffer-property-keys))))
  5545. ;; Retrieve muliple properties in the same drawer.
  5546. (should
  5547. (equal '("A" "B")
  5548. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5549. (org-buffer-property-keys))))
  5550. ;; Ignore extension symbol in property name.
  5551. (should
  5552. (equal '("A")
  5553. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5554. (org-buffer-property-keys))))
  5555. ;; Add bare property if xxx_ALL property is there
  5556. (should
  5557. (equal '("A" "B" "B_ALL")
  5558. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B_ALL: foo bar\n:END:"
  5559. (org-buffer-property-keys))))
  5560. ;; Add bare property if xxx_ALL property is there - check dupes
  5561. (should
  5562. (equal '("A" "B" "B_ALL")
  5563. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:B_ALL: foo bar\n:END:"
  5564. (org-buffer-property-keys))))
  5565. ;; Retrieve properties from #+PROPERTY keyword lines
  5566. (should
  5567. (equal '("A" "C")
  5568. (org-test-with-temp-text "#+PROPERTY: C foo\n* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5569. (org-buffer-property-keys))))
  5570. ;; Retrieve properties from #+PROPERTY keyword lines - make sure an _ALL property also
  5571. ;; adds the bare property
  5572. (should
  5573. (equal '("A" "C" "C_ALL")
  5574. (org-test-with-temp-text "#+PROPERTY: C_ALL foo bar\n* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5575. (org-buffer-property-keys))))
  5576. ;; With non-nil COLUMNS, extract property names from columns.
  5577. (should
  5578. (equal '("A" "B")
  5579. (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
  5580. (org-buffer-property-keys nil nil t))))
  5581. (should
  5582. (equal '("A" "B" "COLUMNS")
  5583. (org-test-with-temp-text
  5584. "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
  5585. (org-buffer-property-keys nil nil t))))
  5586. ;; In COLUMNS, ignore title and summary-type.
  5587. (should
  5588. (equal '("A")
  5589. (org-test-with-temp-text "#+COLUMNS: %A(Foo)"
  5590. (org-buffer-property-keys nil nil t))))
  5591. (should
  5592. (equal '("A")
  5593. (org-test-with-temp-text "#+COLUMNS: %A{Foo}"
  5594. (org-buffer-property-keys nil nil t))))
  5595. (should
  5596. (equal '("A")
  5597. (org-test-with-temp-text "#+COLUMNS: %A(Foo){Bar}"
  5598. (org-buffer-property-keys nil nil t)))))
  5599. (ert-deftest test-org/property-values ()
  5600. "Test `org-property-values' specifications."
  5601. ;; Regular test.
  5602. (should
  5603. (equal '("2" "1")
  5604. (org-test-with-temp-text
  5605. "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
  5606. (org-property-values "A"))))
  5607. ;; Ignore empty values.
  5608. (should-not
  5609. (org-test-with-temp-text
  5610. "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
  5611. (org-property-values "A")))
  5612. ;; Take into consideration extended values.
  5613. (should
  5614. (equal '("1 2")
  5615. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5616. (org-property-values "A")))))
  5617. (ert-deftest test-org/set-property ()
  5618. "Test `org-set-property' specifications."
  5619. (should
  5620. (equal
  5621. ":PROPERTIES:\n:TEST: t\n:END:\n"
  5622. (org-test-with-temp-text ""
  5623. (let ((org-property-format "%s %s"))
  5624. (org-set-property "TEST" "t"))
  5625. (buffer-string))))
  5626. (should
  5627. (equal
  5628. "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5629. (org-test-with-temp-text "* H"
  5630. (let ((org-adapt-indentation nil)
  5631. (org-property-format "%s %s"))
  5632. (org-set-property "TEST" "t"))
  5633. (buffer-string)))))
  5634. (ert-deftest test-org/delete-property ()
  5635. "Test `org-delete-property' specifications."
  5636. (should
  5637. (equal
  5638. ""
  5639. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5640. (org-delete-property "TEST")
  5641. (buffer-string))))
  5642. (should
  5643. (equal
  5644. ":PROPERTIES:\n:TEST1: t\n:END:\n"
  5645. (org-test-with-temp-text ":PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5646. (org-delete-property "TEST2")
  5647. (buffer-string))))
  5648. (should
  5649. (equal
  5650. "* H\n"
  5651. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5652. (org-delete-property "TEST")
  5653. (buffer-string))))
  5654. (should
  5655. (equal
  5656. "* H\n:PROPERTIES:\n:TEST1: t\n:END:\n"
  5657. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5658. (org-delete-property "TEST2")
  5659. (buffer-string)))))
  5660. (ert-deftest test-org/delete-property-globally ()
  5661. "Test `org-delete-property-global' specifications."
  5662. (should
  5663. (equal
  5664. ""
  5665. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5666. (org-delete-property-globally "TEST")
  5667. (buffer-string))))
  5668. (should
  5669. (equal
  5670. "* H\n"
  5671. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n* H\n:PROPERTIES:\n:TEST: nil\n:END:"
  5672. (org-delete-property-globally "TEST")
  5673. (buffer-string)))))
  5674. (ert-deftest test-org/find-property ()
  5675. "Test `org-find-property' specifications."
  5676. ;; Regular test.
  5677. (should
  5678. (= 1
  5679. (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
  5680. (org-find-property "prop"))))
  5681. ;; Find properties in top-level property drawer.
  5682. (should
  5683. (= 1
  5684. (org-test-with-temp-text ":PROPERTIES:\n:PROP: value\n:END:"
  5685. (org-find-property "prop"))))
  5686. ;; Ignore false positives.
  5687. (should
  5688. (= 27
  5689. (org-test-with-temp-text
  5690. "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
  5691. (org-find-property "A"))))
  5692. ;; Return first entry found in buffer.
  5693. (should
  5694. (= 1
  5695. (org-test-with-temp-text
  5696. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5697. (org-find-property "A"))))
  5698. ;; Only search visible part of the buffer.
  5699. (should
  5700. (= 31
  5701. (org-test-with-temp-text
  5702. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5703. (org-narrow-to-subtree)
  5704. (org-find-property "A"))))
  5705. ;; With optional argument, only find entries with a specific value.
  5706. (should-not
  5707. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5708. (org-find-property "A" "2")))
  5709. (should
  5710. (= 31
  5711. (org-test-with-temp-text
  5712. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
  5713. (org-find-property "A" "2"))))
  5714. ;; Use "nil" for explicit nil values.
  5715. (should
  5716. (= 31
  5717. (org-test-with-temp-text
  5718. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
  5719. (org-find-property "A" "nil")))))
  5720. (ert-deftest test-org/entry-delete ()
  5721. "Test `org-entry-delete' specifications."
  5722. ;; Regular test.
  5723. (should
  5724. (string-match
  5725. " *:PROPERTIES:\n *:B: +2\n *:END:"
  5726. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5727. (org-entry-delete (point) "A")
  5728. (buffer-string))))
  5729. ;; Also remove accumulated properties.
  5730. (should-not
  5731. (string-match
  5732. ":A"
  5733. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
  5734. (org-entry-delete (point) "A")
  5735. (buffer-string))))
  5736. ;; When last property is removed, remove the property drawer.
  5737. (should-not
  5738. (string-match
  5739. ":PROPERTIES:"
  5740. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
  5741. (org-entry-delete (point) "A")
  5742. (buffer-string))))
  5743. ;; Return a non-nil value when some property was removed.
  5744. (should
  5745. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5746. (org-entry-delete (point) "A")))
  5747. (should-not
  5748. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5749. (org-entry-delete (point) "C")))
  5750. ;; Special properties cannot be located in a drawer. Allow to
  5751. ;; remove them anyway, in case of user error.
  5752. (should
  5753. (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
  5754. (org-entry-delete (point) "SCHEDULED"))))
  5755. (ert-deftest test-org/entry-get ()
  5756. "Test `org-entry-get' specifications."
  5757. ;; Regular test.
  5758. (should
  5759. (equal "1"
  5760. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:"
  5761. (org-entry-get (point) "A"))))
  5762. (should
  5763. (equal "1"
  5764. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5765. (org-entry-get (point) "A"))))
  5766. ;; Ignore case.
  5767. (should
  5768. (equal "1"
  5769. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5770. (org-entry-get (point) "a"))))
  5771. ;; Handle extended values, both before and after base value.
  5772. (should
  5773. (equal "1 2 3"
  5774. (org-test-with-temp-text
  5775. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5776. (org-entry-get (point) "A"))))
  5777. ;; Empty values are returned as the empty string.
  5778. (should
  5779. (equal ""
  5780. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
  5781. (org-entry-get (point) "A"))))
  5782. ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
  5783. ;; otherwise, return nil.
  5784. (should-not
  5785. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5786. (org-entry-get (point) "A")))
  5787. (should
  5788. (equal "nil"
  5789. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5790. (org-entry-get (point) "A" nil t))))
  5791. ;; Return nil when no property is found, independently on the
  5792. ;; LITERAL-NIL argument.
  5793. (should-not
  5794. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5795. (org-entry-get (point) "B")))
  5796. (should-not
  5797. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5798. (org-entry-get (point) "B" nil t)))
  5799. ;; Handle inheritance, when allowed. Include extended values and
  5800. ;; possibly global values.
  5801. (should
  5802. (equal
  5803. "1"
  5804. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:\n* H"
  5805. (org-entry-get (point-max) "A" t))))
  5806. (should
  5807. (equal
  5808. "1"
  5809. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5810. (org-entry-get (point-max) "A" t))))
  5811. (should
  5812. (equal
  5813. "1"
  5814. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5815. (let ((org-use-property-inheritance t))
  5816. (org-entry-get (point-max) "A" 'selective)))))
  5817. (should-not
  5818. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5819. (let ((org-use-property-inheritance nil))
  5820. (org-entry-get (point-max) "A" 'selective))))
  5821. (should-not
  5822. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H2"
  5823. (let ((org-use-property-inheritance t))
  5824. (org-entry-get (point-max) "A" t))))
  5825. (should
  5826. (equal
  5827. "1 2"
  5828. (org-test-with-temp-text
  5829. ":PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5830. (org-entry-get (point-max) "A" t))))
  5831. (should
  5832. (equal
  5833. "1 2"
  5834. (org-test-with-temp-text
  5835. "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5836. (org-entry-get (point-max) "A" t))))
  5837. (should
  5838. (equal
  5839. "1 2"
  5840. (org-test-with-temp-text
  5841. ":PROPERTIES:\n:A: 1\n:END:\n* H1\n* H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5842. (org-entry-get (point-max) "A" t))))
  5843. (should
  5844. (equal
  5845. "1 2"
  5846. (org-test-with-temp-text
  5847. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2.1\n** H2.2\n:PROPERTIES:\n:A+: 2\n:END:"
  5848. (org-entry-get (point-max) "A" t))))
  5849. (should
  5850. (equal "1"
  5851. (org-test-with-temp-text
  5852. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
  5853. (org-mode-restart)
  5854. (org-entry-get (point-max) "A" t))))
  5855. (should
  5856. (equal "0 1"
  5857. (org-test-with-temp-text
  5858. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
  5859. (org-mode-restart)
  5860. (org-entry-get (point-max) "A" t))))
  5861. ;; document level property-drawer has precedance over
  5862. ;; global-property by PROPERTY-keyword.
  5863. (should
  5864. (equal "0 2"
  5865. (org-test-with-temp-text
  5866. ":PROPERTIES:\n:A: 0\n:END:\n#+PROPERTY: A 1\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5867. (org-mode-restart)
  5868. (org-entry-get (point-max) "A" t))))
  5869. ;; Use alternate separators
  5870. (should
  5871. (equal "0~2"
  5872. (org-test-with-temp-text
  5873. ":PROPERTIES:\n:A: 0\n:A+: 2\n:END:"
  5874. (let ((org-property-separators '((("A") . "~"))))
  5875. (org-entry-get (point) "A")))))
  5876. ;; Default separator is single space
  5877. (should
  5878. (equal "0 2"
  5879. (org-test-with-temp-text
  5880. ":PROPERTIES:\n:A: 0\n:B: 1\n:A+: 2\n:B+: 3\n:END:"
  5881. (let ((org-property-separators '((("B") . "~"))))
  5882. (org-entry-get (point) "A")))))
  5883. ;; Regular expression matching for separator
  5884. (should
  5885. (equal "0/2"
  5886. (org-test-with-temp-text
  5887. ":PROPERTIES:\n:A: 0\n:A+: 2\n:END:"
  5888. (let ((org-property-separators '((("B") . "~") ("[AC]" . "/"))))
  5889. (org-entry-get (point) "A")))))
  5890. ;; Separator works with inheritance
  5891. (should
  5892. (equal "1~2"
  5893. (org-test-with-temp-text
  5894. "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5895. (let ((org-property-separators '((("A") . "~"))))
  5896. (org-entry-get (point-max) "A" t))))))
  5897. (ert-deftest test-org/entry-properties ()
  5898. "Test `org-entry-properties' specifications."
  5899. ;; Get "ITEM" property.
  5900. (should
  5901. (equal "H"
  5902. (org-test-with-temp-text "* TODO H"
  5903. (cdr (assoc "ITEM" (org-entry-properties nil "ITEM"))))))
  5904. (should
  5905. (equal "H"
  5906. (org-test-with-temp-text "* TODO H"
  5907. (cdr (assoc "ITEM" (org-entry-properties))))))
  5908. ;; Get "TODO" property. TODO keywords are case sensitive.
  5909. (should
  5910. (equal "TODO"
  5911. (org-test-with-temp-text "* TODO H"
  5912. (cdr (assoc "TODO" (org-entry-properties nil "TODO"))))))
  5913. (should
  5914. (equal "TODO"
  5915. (org-test-with-temp-text "* TODO H"
  5916. (cdr (assoc "TODO" (org-entry-properties))))))
  5917. (should-not
  5918. (org-test-with-temp-text "* H"
  5919. (assoc "TODO" (org-entry-properties nil "TODO"))))
  5920. (should-not
  5921. (org-test-with-temp-text "* todo H"
  5922. (assoc "TODO" (org-entry-properties nil "TODO"))))
  5923. ;; Get "PRIORITY" property.
  5924. (should
  5925. (equal "A"
  5926. (org-test-with-temp-text "* [#A] H"
  5927. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  5928. (should
  5929. (equal "A"
  5930. (org-test-with-temp-text "* [#A] H"
  5931. (cdr (assoc "PRIORITY" (org-entry-properties))))))
  5932. (should
  5933. (equal (char-to-string org-priority-default)
  5934. (org-test-with-temp-text "* H"
  5935. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  5936. ;; Get "FILE" property.
  5937. (should
  5938. (org-test-with-temp-text-in-file "* H\nParagraph"
  5939. (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil "FILE")))
  5940. (buffer-file-name))))
  5941. (should
  5942. (org-test-with-temp-text-in-file "* H\nParagraph"
  5943. (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
  5944. (buffer-file-name))))
  5945. (should-not
  5946. (org-test-with-temp-text "* H\nParagraph"
  5947. (cdr (assoc "FILE" (org-entry-properties nil "FILE")))))
  5948. ;; Get "TAGS" property.
  5949. (should
  5950. (equal ":tag1:tag2:"
  5951. (org-test-with-temp-text "* H :tag1:tag2:"
  5952. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS"))))))
  5953. (should
  5954. (equal ":tag1:tag2:"
  5955. (org-test-with-temp-text "* H :tag1:tag2:"
  5956. (cdr (assoc "TAGS" (org-entry-properties))))))
  5957. (should-not
  5958. (org-test-with-temp-text "* H"
  5959. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS")))))
  5960. ;; Get "ALLTAGS" property.
  5961. (should
  5962. (equal ":tag1:tag2:"
  5963. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  5964. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS"))))))
  5965. (should
  5966. (equal ":tag1:tag2:"
  5967. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  5968. (cdr (assoc "ALLTAGS" (org-entry-properties))))))
  5969. (should-not
  5970. (org-test-with-temp-text "* H"
  5971. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS")))))
  5972. ;; Get "BLOCKED" property.
  5973. (should
  5974. (equal "t"
  5975. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  5976. (let ((org-enforce-todo-dependencies t)
  5977. (org-blocker-hook
  5978. '(org-block-todo-from-children-or-siblings-or-parent)))
  5979. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  5980. (should
  5981. (equal ""
  5982. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  5983. (let ((org-enforce-todo-dependencies t)
  5984. (org-blocker-hook
  5985. '(org-block-todo-from-children-or-siblings-or-parent)))
  5986. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  5987. ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
  5988. (should
  5989. (equal
  5990. "[2012-03-29 thu.]"
  5991. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  5992. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED"))))))
  5993. (should
  5994. (equal
  5995. "[2012-03-29 thu.]"
  5996. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  5997. (cdr (assoc "CLOSED" (org-entry-properties))))))
  5998. (should-not
  5999. (org-test-with-temp-text "* H"
  6000. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED")))))
  6001. (should
  6002. (equal
  6003. "<2014-03-04 tue.>"
  6004. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6005. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE"))))))
  6006. (should
  6007. (equal
  6008. "<2014-03-04 tue.>"
  6009. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6010. (cdr (assoc "DEADLINE" (org-entry-properties))))))
  6011. (should-not
  6012. (org-test-with-temp-text "* H"
  6013. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE")))))
  6014. (should
  6015. (equal
  6016. "<2014-03-04 tue.>"
  6017. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6018. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED"))))))
  6019. (should
  6020. (equal
  6021. "<2014-03-04 tue.>"
  6022. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6023. (cdr (assoc "SCHEDULED" (org-entry-properties))))))
  6024. (should-not
  6025. (org-test-with-temp-text "* H"
  6026. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED")))))
  6027. ;; Get "CATEGORY"
  6028. (should
  6029. (equal "cat"
  6030. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  6031. (cdr (assoc "CATEGORY" (org-entry-properties))))))
  6032. (should
  6033. (equal "cat"
  6034. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  6035. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  6036. (should
  6037. (equal "cat"
  6038. (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
  6039. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  6040. (should
  6041. (equal "cat2"
  6042. (org-test-with-temp-text
  6043. (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6044. "\n"
  6045. "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
  6046. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  6047. ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
  6048. (should
  6049. (equal "<2012-03-29 thu.>"
  6050. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
  6051. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  6052. (should
  6053. (equal "[2012-03-29 thu.]"
  6054. (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
  6055. (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
  6056. (should
  6057. (equal "<2012-03-29 thu.>"
  6058. (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
  6059. (cdr (assoc "TIMESTAMP" (org-entry-properties nil "TIMESTAMP"))))))
  6060. (should
  6061. (equal "[2014-03-04 tue.]"
  6062. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
  6063. (cdr (assoc "TIMESTAMP_IA"
  6064. (org-entry-properties nil "TIMESTAMP_IA"))))))
  6065. (should-not
  6066. (equal "<2012-03-29 thu.>"
  6067. (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
  6068. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  6069. ;; Get standard properties.
  6070. (should
  6071. (equal "1"
  6072. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6073. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  6074. ;; Handle extended properties.
  6075. (should
  6076. (equal "1 2 3"
  6077. (org-test-with-temp-text
  6078. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  6079. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  6080. (should
  6081. (equal "1 2 3"
  6082. (org-test-with-temp-text
  6083. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
  6084. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  6085. ;; Ignore forbidden (special) properties.
  6086. (should-not
  6087. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
  6088. (cdr (assoc "TODO" (org-entry-properties nil 'standard))))))
  6089. (ert-deftest test-org/entry-put ()
  6090. "Test `org-entry-put' specifications."
  6091. ;; Error when not a string or nil.
  6092. (should-error
  6093. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  6094. (org-entry-put 1 "test" 2)))
  6095. ;; Error when property name is invalid.
  6096. (should-error
  6097. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  6098. (org-entry-put 1 "no space" "value")))
  6099. (should-error
  6100. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  6101. (org-entry-put 1 "" "value")))
  6102. ;; Set "TODO" property.
  6103. (should
  6104. (string-match (regexp-quote " TODO H")
  6105. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  6106. (org-entry-put (point) "TODO" "TODO")
  6107. (buffer-string))))
  6108. (should
  6109. (string-match (regexp-quote "* H")
  6110. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  6111. (org-entry-put (point) "TODO" nil)
  6112. (buffer-string))))
  6113. ;; Set "PRIORITY" property.
  6114. (should
  6115. (equal "* [#A] H"
  6116. (org-test-with-temp-text "* [#B] H"
  6117. (org-entry-put (point) "PRIORITY" "A")
  6118. (buffer-string))))
  6119. (should
  6120. (equal "* H"
  6121. (org-test-with-temp-text "* [#B] H"
  6122. (org-entry-put (point) "PRIORITY" nil)
  6123. (buffer-string))))
  6124. ;; Set "SCHEDULED" property.
  6125. (should
  6126. (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
  6127. (org-test-with-temp-text "* H"
  6128. (org-entry-put (point) "SCHEDULED" "2014-03-04")
  6129. (buffer-string))))
  6130. (should
  6131. (string= "* H\n"
  6132. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6133. (org-entry-put (point) "SCHEDULED" nil)
  6134. (buffer-string))))
  6135. (should
  6136. (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
  6137. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6138. (org-entry-put (point) "SCHEDULED" "earlier")
  6139. (buffer-string))))
  6140. (should
  6141. (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
  6142. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6143. (org-entry-put (point) "SCHEDULED" "later")
  6144. (buffer-string))))
  6145. ;; Set "DEADLINE" property.
  6146. (should
  6147. (string-match "^ *DEADLINE: <2014-03-04 .*?>"
  6148. (org-test-with-temp-text "* H"
  6149. (org-entry-put (point) "DEADLINE" "2014-03-04")
  6150. (buffer-string))))
  6151. (should
  6152. (string= "* H\n"
  6153. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6154. (org-entry-put (point) "DEADLINE" nil)
  6155. (buffer-string))))
  6156. (should
  6157. (string-match "^ *DEADLINE: <2014-03-03 .*?>"
  6158. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6159. (org-entry-put (point) "DEADLINE" "earlier")
  6160. (buffer-string))))
  6161. (should
  6162. (string-match "^ *DEADLINE: <2014-03-05 .*?>"
  6163. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6164. (org-entry-put (point) "DEADLINE" "later")
  6165. (buffer-string))))
  6166. ;; Set "CATEGORY" property
  6167. (should
  6168. (string-match "^ *:CATEGORY: cat"
  6169. (org-test-with-temp-text "* H"
  6170. (org-entry-put (point) "CATEGORY" "cat")
  6171. (buffer-string))))
  6172. ;; Regular properties, with or without pre-existing drawer.
  6173. (should
  6174. (string-match "^ *:A: +2$"
  6175. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6176. (org-entry-put (point) "A" "2")
  6177. (buffer-string))))
  6178. (should
  6179. (string-match "^ *:A: +1$"
  6180. (org-test-with-temp-text "* H"
  6181. (org-entry-put (point) "A" "1")
  6182. (buffer-string))))
  6183. ;; Special case: two consecutive headlines.
  6184. (should
  6185. (string-match "\\* A\n *:PROPERTIES:"
  6186. (org-test-with-temp-text "* A\n** B"
  6187. (org-entry-put (point) "A" "1")
  6188. (buffer-string)))))
  6189. (ert-deftest test-org/refresh-properties ()
  6190. "Test `org-refresh-properties' specifications."
  6191. (should
  6192. (equal "1"
  6193. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6194. (org-refresh-properties "A" 'org-test)
  6195. (get-text-property (point) 'org-test))))
  6196. (should-not
  6197. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6198. (org-refresh-properties "B" 'org-test)
  6199. (get-text-property (point) 'org-test)))
  6200. ;; Handle properties only defined with extension syntax, i.e.,
  6201. ;; "PROPERTY+".
  6202. (should
  6203. (equal "1"
  6204. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
  6205. (org-refresh-properties "A" 'org-test)
  6206. (get-text-property (point) 'org-test))))
  6207. ;; When property is inherited, add text property to the whole
  6208. ;; sub-tree.
  6209. (should
  6210. (equal "1"
  6211. (org-test-with-temp-text
  6212. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
  6213. (let ((org-use-property-inheritance t))
  6214. (org-refresh-properties "A" 'org-test))
  6215. (get-text-property (point) 'org-test))))
  6216. ;; When a document level property-drawer is used, those properties
  6217. ;; should work exactly like headline-properties as if at a
  6218. ;; headline-level 0.
  6219. (should
  6220. (equal "1"
  6221. (org-test-with-temp-text
  6222. ":PROPERTIES:\n:A: 1\n:END:\n"
  6223. (org-mode-restart)
  6224. (let ((org-use-property-inheritance t))
  6225. (org-refresh-properties "A" 'org-test))
  6226. (get-text-property (point) 'org-test))))
  6227. (should-not
  6228. (equal "1"
  6229. (org-test-with-temp-text
  6230. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  6231. (org-mode-restart)
  6232. (let ((org-use-property-inheritance nil))
  6233. (org-refresh-properties "A" 'org-test))
  6234. (get-text-property (point) 'org-test))))
  6235. (should
  6236. (equal "1"
  6237. (org-test-with-temp-text
  6238. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  6239. (org-mode-restart)
  6240. (let ((org-use-property-inheritance t))
  6241. (org-refresh-properties "A" 'org-test))
  6242. (get-text-property (point) 'org-test))))
  6243. (should
  6244. (equal "2"
  6245. (org-test-with-temp-text
  6246. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1\n:PROPERTIES:\n:A: 2\n:END:"
  6247. (org-mode-restart)
  6248. (let ((org-use-property-inheritance t))
  6249. (org-refresh-properties "A" 'org-test))
  6250. (get-text-property (point) 'org-test))))
  6251. ;; When property is inherited, use global value across the whole
  6252. ;; buffer. However local values have precedence, as well as the
  6253. ;; document level property-drawer.
  6254. (should-not
  6255. (equal "1"
  6256. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  6257. (org-mode-restart)
  6258. (let ((org-use-property-inheritance nil))
  6259. (org-refresh-properties "A" 'org-test))
  6260. (get-text-property (point) 'org-test))))
  6261. (should
  6262. (equal "1"
  6263. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  6264. (org-mode-restart)
  6265. (let ((org-use-property-inheritance t))
  6266. (org-refresh-properties "A" 'org-test))
  6267. (get-text-property (point) 'org-test))))
  6268. (should
  6269. (equal "2"
  6270. (org-test-with-temp-text
  6271. "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
  6272. (org-mode-restart)
  6273. (let ((org-use-property-inheritance t))
  6274. (org-refresh-properties "A" 'org-test))
  6275. (get-text-property (point) 'org-test))))
  6276. ;; When both keyword-property and document-level property-block is
  6277. ;; defined, the property-block has precedance.
  6278. (should
  6279. (equal "1"
  6280. (org-test-with-temp-text
  6281. ":PROPERTIES:\n:A: 1\n:END:\n#+PROPERTY: A 2\n<point>* H1"
  6282. (org-mode-restart)
  6283. (let ((org-use-property-inheritance t))
  6284. (org-refresh-properties "A" 'org-test))
  6285. (get-text-property (point) 'org-test)))))
  6286. (ert-deftest test-org/refresh-category-properties ()
  6287. "Test `org-refresh-category-properties' specifications"
  6288. (should
  6289. (equal "cat1"
  6290. (org-test-with-temp-text
  6291. ":PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6292. (org-refresh-category-properties)
  6293. (org-get-category))))
  6294. (should
  6295. (equal "cat1"
  6296. (org-test-with-temp-text
  6297. "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6298. (org-refresh-category-properties)
  6299. (org-get-category))))
  6300. ;; Even though property-inheritance is deactivated, category
  6301. ;; property should be inherited. As described in
  6302. ;; `org-use-property-inheritance'.
  6303. (should
  6304. (equal "cat1"
  6305. (org-test-with-temp-text
  6306. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  6307. (org-mode-restart)
  6308. (let ((org-use-property-inheritance nil))
  6309. (org-refresh-category-properties))
  6310. (org-get-category))))
  6311. (should
  6312. (equal "cat1"
  6313. (org-test-with-temp-text
  6314. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  6315. (org-mode-restart)
  6316. (let ((org-use-property-inheritance t))
  6317. (org-refresh-category-properties))
  6318. (org-get-category))))
  6319. (should
  6320. (equal "cat2"
  6321. (org-test-with-temp-text
  6322. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H\n:PROPERTIES:\n:CATEGORY: cat2\n:END:\n"
  6323. (org-mode-restart)
  6324. (let ((org-use-property-inheritance t))
  6325. (org-refresh-category-properties))
  6326. (org-get-category)))))
  6327. ;;; Refile
  6328. (ert-deftest test-org/refile-get-targets ()
  6329. "Test `org-refile-get-targets' specifications."
  6330. ;; :maxlevel includes all headings above specified value.
  6331. (should
  6332. (equal '("H1" "H2" "H3")
  6333. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6334. (let ((org-refile-use-outline-path nil)
  6335. (org-refile-targets `((nil :maxlevel . 3))))
  6336. (mapcar #'car (org-refile-get-targets))))))
  6337. (should
  6338. (equal '("H1" "H2")
  6339. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6340. (let ((org-refile-use-outline-path nil)
  6341. (org-refile-targets `((nil :maxlevel . 2))))
  6342. (mapcar #'car (org-refile-get-targets))))))
  6343. ;; :level limits targets to headlines with the specified level.
  6344. (should
  6345. (equal '("H2")
  6346. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6347. (let ((org-refile-use-outline-path nil)
  6348. (org-refile-targets `((nil :level . 2))))
  6349. (mapcar #'car (org-refile-get-targets))))))
  6350. ;; :tag limits targets to headlines with specified tag.
  6351. (should
  6352. (equal '("H1")
  6353. (org-test-with-temp-text "* H1 :foo:\n** H2\n*** H3 :bar:"
  6354. (let ((org-refile-use-outline-path nil)
  6355. (org-refile-targets `((nil :tag . "foo"))))
  6356. (mapcar #'car (org-refile-get-targets))))))
  6357. ;; :todo limits targets to headlines with specified TODO keyword.
  6358. (should
  6359. (equal '("H2")
  6360. (org-test-with-temp-text "* H1\n** TODO H2\n*** DONE H3"
  6361. (let ((org-refile-use-outline-path nil)
  6362. (org-refile-targets `((nil :todo . "TODO"))))
  6363. (mapcar #'car (org-refile-get-targets))))))
  6364. ;; :regexp filters targets matching provided regexp.
  6365. (should
  6366. (equal '("F2" "F3")
  6367. (org-test-with-temp-text "* H1\n** F2\n*** F3"
  6368. (let ((org-refile-use-outline-path nil)
  6369. (org-refile-targets `((nil :regexp . "F"))))
  6370. (mapcar #'car (org-refile-get-targets))))))
  6371. ;; A nil `org-refile-targets' includes only top level headlines in
  6372. ;; current buffer.
  6373. (should
  6374. (equal '("H1" "H2")
  6375. (org-test-with-temp-text "* H1\n** S1\n* H2"
  6376. (let ((org-refile-use-outline-path nil)
  6377. (org-refile-targets nil))
  6378. (mapcar #'car (org-refile-get-targets))))))
  6379. ;; Return value is the union of the targets according to all the
  6380. ;; defined rules. However, prevent duplicates.
  6381. (should
  6382. (equal '("F2" "F3" "H1")
  6383. (org-test-with-temp-text "* TODO H1\n** F2\n*** F3"
  6384. (let ((org-refile-use-outline-path nil)
  6385. (org-refile-targets `((nil :regexp . "F")
  6386. (nil :todo . "TODO"))))
  6387. (mapcar #'car (org-refile-get-targets))))))
  6388. (should
  6389. (equal '("F2" "F3" "H1")
  6390. (org-test-with-temp-text "* TODO H1\n** TODO F2\n*** F3"
  6391. (let ((org-refile-use-outline-path nil)
  6392. (org-refile-targets `((nil :regexp . "F")
  6393. (nil :todo . "TODO"))))
  6394. (mapcar #'car (org-refile-get-targets))))))
  6395. ;; When `org-refile-use-outline-path' is non-nil, provide targets as
  6396. ;; paths.
  6397. (should
  6398. (equal '("H1" "H1/H2" "H1/H2/H3")
  6399. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6400. (let ((org-refile-use-outline-path t)
  6401. (org-refile-targets `((nil :maxlevel . 3))))
  6402. (mapcar #'car (org-refile-get-targets))))))
  6403. ;; When providing targets as paths, escape forward slashes in
  6404. ;; headings with backslashes.
  6405. (should
  6406. (equal '("H1\\/foo")
  6407. (org-test-with-temp-text "* H1/foo"
  6408. (let ((org-refile-use-outline-path t)
  6409. (org-refile-targets `((nil :maxlevel . 1))))
  6410. (mapcar #'car (org-refile-get-targets))))))
  6411. ;; When `org-refile-use-outline-path' is `file', include file name
  6412. ;; without directory in targets.
  6413. (should
  6414. (org-test-with-temp-text-in-file "* H1"
  6415. (let* ((filename (buffer-file-name))
  6416. (org-refile-use-outline-path 'file)
  6417. (org-refile-targets `(((,filename) :level . 1))))
  6418. (member (file-name-nondirectory filename)
  6419. (mapcar #'car (org-refile-get-targets))))))
  6420. ;; When `org-refile-use-outline-path' is `full-file-path', include
  6421. ;; full file name.
  6422. (should
  6423. (org-test-with-temp-text-in-file "* H1"
  6424. (let* ((filename (file-truename (buffer-file-name)))
  6425. (org-refile-use-outline-path 'full-file-path)
  6426. (org-refile-targets `(((,filename) :level . 1))))
  6427. (member filename (mapcar #'car (org-refile-get-targets))))))
  6428. ;; When `org-refile-use-outline-path' is `buffer-name', include
  6429. ;; buffer name.
  6430. (should
  6431. (org-test-with-temp-text "* H1"
  6432. (let* ((org-refile-use-outline-path 'buffer-name)
  6433. (org-refile-targets `((nil :level . 1))))
  6434. (member (buffer-name) (mapcar #'car (org-refile-get-targets)))))))
  6435. ;;; Sparse trees
  6436. (ert-deftest test-org/match-sparse-tree ()
  6437. "Test `org-match-sparse-tree' specifications."
  6438. ;; Match tags.
  6439. (should-not
  6440. (org-test-with-temp-text "* H\n** H1 :tag:"
  6441. (org-match-sparse-tree nil "tag")
  6442. (search-forward "H1")
  6443. (org-invisible-p2)))
  6444. (should
  6445. (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
  6446. (org-match-sparse-tree nil "tag")
  6447. (search-forward "H2")
  6448. (org-invisible-p2)))
  6449. ;; "-" operator for tags.
  6450. (should-not
  6451. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6452. (org-match-sparse-tree nil "tag1-tag2")
  6453. (search-forward "H1")
  6454. (org-invisible-p2)))
  6455. (should
  6456. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6457. (org-match-sparse-tree nil "tag1-tag2")
  6458. (search-forward "H2")
  6459. (org-invisible-p2)))
  6460. ;; "&" operator for tags.
  6461. (should
  6462. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6463. (org-match-sparse-tree nil "tag1&tag2")
  6464. (search-forward "H1")
  6465. (org-invisible-p2)))
  6466. (should-not
  6467. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6468. (org-match-sparse-tree nil "tag1&tag2")
  6469. (search-forward "H2")
  6470. (org-invisible-p2)))
  6471. ;; "|" operator for tags.
  6472. (should-not
  6473. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6474. (org-match-sparse-tree nil "tag1|tag2")
  6475. (search-forward "H1")
  6476. (org-invisible-p2)))
  6477. (should-not
  6478. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6479. (org-match-sparse-tree nil "tag1|tag2")
  6480. (search-forward "H2")
  6481. (org-invisible-p2)))
  6482. ;; Regexp match on tags.
  6483. (should-not
  6484. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6485. (org-match-sparse-tree nil "{^tag.*}")
  6486. (search-forward "H1")
  6487. (org-invisible-p2)))
  6488. (should
  6489. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6490. (org-match-sparse-tree nil "{^tag.*}")
  6491. (search-forward "H2")
  6492. (org-invisible-p2)))
  6493. ;; Match group tags.
  6494. (should-not
  6495. (org-test-with-temp-text
  6496. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6497. (org-match-sparse-tree nil "work")
  6498. (search-forward "H1")
  6499. (org-invisible-p2)))
  6500. (should-not
  6501. (org-test-with-temp-text
  6502. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6503. (org-match-sparse-tree nil "work")
  6504. (search-forward "H2")
  6505. (org-invisible-p2)))
  6506. ;; Match group tags with hard brackets.
  6507. (should-not
  6508. (org-test-with-temp-text
  6509. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6510. (org-match-sparse-tree nil "work")
  6511. (search-forward "H1")
  6512. (org-invisible-p2)))
  6513. (should-not
  6514. (org-test-with-temp-text
  6515. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6516. (org-match-sparse-tree nil "work")
  6517. (search-forward "H2")
  6518. (org-invisible-p2)))
  6519. ;; Match tags in hierarchies
  6520. (should-not
  6521. (org-test-with-temp-text
  6522. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6523. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6524. #+TAGS: { Lev_3 : Lev_4 }\n
  6525. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6526. (org-match-sparse-tree nil "Lev_1")
  6527. (search-forward "H4")
  6528. (org-invisible-p2)))
  6529. (should-not
  6530. (org-test-with-temp-text
  6531. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6532. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6533. #+TAGS: { Lev_3 : Lev_4 }\n
  6534. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6535. (org-match-sparse-tree nil "Lev_1+Lev_3")
  6536. (search-forward "H4")
  6537. (org-invisible-p2)))
  6538. ;; Match regular expressions in tags
  6539. (should-not
  6540. (org-test-with-temp-text
  6541. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
  6542. (org-match-sparse-tree nil "Lev")
  6543. (search-forward "H1")
  6544. (org-invisible-p2)))
  6545. (should
  6546. (org-test-with-temp-text
  6547. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
  6548. (org-match-sparse-tree nil "Lev")
  6549. (search-forward "H1")
  6550. (org-invisible-p2)))
  6551. ;; Match properties.
  6552. (should
  6553. (org-test-with-temp-text
  6554. "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
  6555. (org-match-sparse-tree nil "A=\"1\"")
  6556. (search-forward "H2")
  6557. (org-invisible-p2)))
  6558. (should-not
  6559. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6560. (org-match-sparse-tree nil "A=\"1\"")
  6561. (search-forward "H2")
  6562. (org-invisible-p2)))
  6563. ;; Case is not significant when matching properties.
  6564. (should-not
  6565. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6566. (org-match-sparse-tree nil "a=\"1\"")
  6567. (search-forward "H2")
  6568. (org-invisible-p2)))
  6569. (should-not
  6570. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
  6571. (org-match-sparse-tree nil "A=\"1\"")
  6572. (search-forward "H2")
  6573. (org-invisible-p2)))
  6574. ;; Match special LEVEL property.
  6575. (should-not
  6576. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6577. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6578. (search-forward "H1")
  6579. (org-invisible-p2)))
  6580. (should
  6581. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6582. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6583. (search-forward "H2")
  6584. (org-invisible-p2)))
  6585. ;; Comparison operators when matching properties.
  6586. (should
  6587. (org-test-with-temp-text
  6588. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6589. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6590. (search-forward "H1")
  6591. (org-invisible-p2)))
  6592. (should-not
  6593. (org-test-with-temp-text
  6594. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6595. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6596. (search-forward "H2")
  6597. (org-invisible-p2)))
  6598. ;; Regexp match on properties values.
  6599. (should-not
  6600. (org-test-with-temp-text
  6601. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6602. (org-match-sparse-tree nil "A={f.*}")
  6603. (search-forward "H1")
  6604. (org-invisible-p2)))
  6605. (should
  6606. (org-test-with-temp-text
  6607. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6608. (org-match-sparse-tree nil "A={f.*}")
  6609. (search-forward "H2")
  6610. (org-invisible-p2)))
  6611. ;; With an optional argument, limit match to TODO entries.
  6612. (should-not
  6613. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6614. (org-match-sparse-tree t "tag")
  6615. (search-forward "H1")
  6616. (org-invisible-p2)))
  6617. (should
  6618. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6619. (org-match-sparse-tree t "tag")
  6620. (search-forward "H2")
  6621. (org-invisible-p2))))
  6622. (ert-deftest test-org/occur ()
  6623. "Test `org-occur' specifications."
  6624. ;; Count number of matches.
  6625. (should
  6626. (= 1
  6627. (org-test-with-temp-text "* H\nA\n* H2"
  6628. (org-occur "A"))))
  6629. (should
  6630. (= 2
  6631. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6632. (org-occur "A"))))
  6633. ;; Test CALLBACK optional argument.
  6634. (should
  6635. (= 0
  6636. (org-test-with-temp-text "* H\nA\n* H2"
  6637. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6638. (should
  6639. (= 1
  6640. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6641. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6642. ;; Case-fold searches according to `org-occur-case-fold-search'.
  6643. (should
  6644. (= 2
  6645. (org-test-with-temp-text "Aa"
  6646. (let ((org-occur-case-fold-search t)) (org-occur "A")))))
  6647. (should
  6648. (= 2
  6649. (org-test-with-temp-text "Aa"
  6650. (let ((org-occur-case-fold-search t)) (org-occur "a")))))
  6651. (should
  6652. (= 1
  6653. (org-test-with-temp-text "Aa"
  6654. (let ((org-occur-case-fold-search nil)) (org-occur "A")))))
  6655. (should
  6656. (= 1
  6657. (org-test-with-temp-text "Aa"
  6658. (let ((org-occur-case-fold-search nil)) (org-occur "a")))))
  6659. (should
  6660. (= 1
  6661. (org-test-with-temp-text "Aa"
  6662. (let ((org-occur-case-fold-search 'smart)) (org-occur "A")))))
  6663. (should
  6664. (= 2
  6665. (org-test-with-temp-text "Aa"
  6666. (let ((org-occur-case-fold-search 'smart)) (org-occur "a"))))))
  6667. ;;; Tags
  6668. (ert-deftest test-org/tag-string-to-alist ()
  6669. "Test `org-tag-string-to-alist' specifications."
  6670. ;; Tag without selection key.
  6671. (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
  6672. ;; Tag with selection key.
  6673. (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t))))
  6674. ;; Tag group.
  6675. (should
  6676. (equal
  6677. (org-tag-string-to-alist "[ group : t1 t2 ]")
  6678. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag))))
  6679. ;; Mutually exclusive tags.
  6680. (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
  6681. '((:startgroup) ("tag1") ("tag2") (:endgroup))))
  6682. (should
  6683. (equal
  6684. (org-tag-string-to-alist "{ group : tag1 tag2 }")
  6685. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))))
  6686. (ert-deftest test-org/tag-alist-to-string ()
  6687. "Test `org-tag-alist-to-string' specifications."
  6688. (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
  6689. (should (equal (org-tag-alist-to-string '(("tag1" . ?t))) "tag1(t)"))
  6690. (should
  6691. (equal
  6692. (org-tag-alist-to-string
  6693. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6694. "[ group : t1 t2 ]"))
  6695. (should
  6696. (equal (org-tag-alist-to-string
  6697. '((:startgroup) ("tag1") ("tag2") (:endgroup)))
  6698. "{ tag1 tag2 }"))
  6699. (should
  6700. (equal
  6701. (org-tag-alist-to-string
  6702. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))
  6703. "{ group : tag1 tag2 }")))
  6704. (ert-deftest test-org/tag-alist-to-groups ()
  6705. "Test `org-tag-alist-to-groups' specifications."
  6706. (should
  6707. (equal (org-tag-alist-to-groups
  6708. '((:startgroup) ("group") (:grouptags) ("t1") ("t2") (:endgroup)))
  6709. '(("group" "t1" "t2"))))
  6710. (should
  6711. (equal
  6712. (org-tag-alist-to-groups
  6713. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6714. '(("group" "t1" "t2"))))
  6715. (should-not
  6716. (org-tag-alist-to-groups
  6717. '((:startgroup) ("group") ("t1") ("t2") (:endgroup)))))
  6718. (ert-deftest test-org/tag-align ()
  6719. "Test tags alignment."
  6720. ;; Test aligning tags with different display width.
  6721. (should
  6722. ;; 12345678901234567890
  6723. (equal "* Test :abc:"
  6724. (org-test-with-temp-text "* Test :abc:"
  6725. (let ((org-tags-column -20)
  6726. (indent-tabs-mode nil))
  6727. (org-fix-tags-on-the-fly))
  6728. (buffer-string))))
  6729. (should
  6730. ;; 12345678901234567890
  6731. (equal "* Test :日本語:"
  6732. (org-test-with-temp-text "* Test :日本語:"
  6733. (let ((org-tags-column -20)
  6734. (indent-tabs-mode nil))
  6735. (org-fix-tags-on-the-fly))
  6736. (buffer-string))))
  6737. ;; Make sure aligning tags do not skip invisible text.
  6738. (should
  6739. (equal "* [[linkx]] :tag:"
  6740. (org-test-with-temp-text "* [[link<point>]] :tag:"
  6741. (let ((org-tags-column 0))
  6742. (org-fix-tags-on-the-fly)
  6743. (insert "x")
  6744. (buffer-string)))))
  6745. ;; Aligning tags preserve position.
  6746. (should
  6747. (= 6 (org-test-with-temp-text "* 345 <point> :tag:"
  6748. (let ((org-tags-column 78)
  6749. (indent-tabs-mode nil))
  6750. (org-fix-tags-on-the-fly))
  6751. (current-column))))
  6752. ;; Aligning all tags in visible buffer.
  6753. (should
  6754. ;; 12345678901234567890
  6755. (equal (concat "* Level 1 :abc:\n"
  6756. "** Level 2 :def:")
  6757. (org-test-with-temp-text (concat "* Level 1 :abc:\n"
  6758. "** Level 2 :def:")
  6759. (let ((org-tags-column -20)
  6760. (indent-tabs-mode nil))
  6761. ;; (org-align-tags :all) must work even when the point
  6762. ;; is at the end of the buffer.
  6763. (goto-char (point-max))
  6764. (org-align-tags :all))
  6765. (buffer-string)))))
  6766. (ert-deftest test-org/get-tags ()
  6767. "Test `org-get-tags' specifications."
  6768. ;; Standard test.
  6769. (should
  6770. (equal '("foo")
  6771. (org-test-with-temp-text "* Test :foo:" (org-get-tags))))
  6772. (should
  6773. (equal '("foo" "bar")
  6774. (org-test-with-temp-text "* Test :foo:bar:" (org-get-tags))))
  6775. ;; Tags for inlinetasks.
  6776. (should
  6777. (equal '("foo" "bar")
  6778. (progn
  6779. (require 'org-inlinetask)
  6780. (org-test-with-temp-text (concat (make-string org-inlinetask-min-level ?*) " Test :foo:bar:")
  6781. (org-get-tags (org-element-at-point))))))
  6782. (should
  6783. (equal '("foo" "bar")
  6784. (progn
  6785. (require 'org-inlinetask)
  6786. (org-test-with-temp-text (concat (make-string org-inlinetask-min-level ?*) " Test :foo:bar:")
  6787. (org-get-tags nil)))))
  6788. ;; Return nil when there is no tag.
  6789. (should-not
  6790. (org-test-with-temp-text "* Test" (org-get-tags)))
  6791. ;; Tags are inherited from parent headlines.
  6792. (should
  6793. (equal '("tag")
  6794. (let ((org-use-tag-inheritance t))
  6795. (org-test-with-temp-text "* H0 :foo:\n* H1 :tag:\n<point>** H2"
  6796. (org-get-tags)))))
  6797. ;; Tags are inherited from `org-file-tags'.
  6798. (should
  6799. (equal '("tag")
  6800. (org-test-with-temp-text "* H1"
  6801. (let ((org-file-tags '("tag"))
  6802. (org-use-tag-inheritance t))
  6803. (org-get-tags)))))
  6804. ;; Only inherited tags have the `inherited' text property.
  6805. (should
  6806. (get-text-property 0 'inherited
  6807. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6808. (let ((org-use-tag-inheritance t))
  6809. (assoc-string "foo" (org-get-tags))))))
  6810. (should-not
  6811. (get-text-property 0 'inherited
  6812. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6813. (let ((org-use-tag-inheritance t))
  6814. (assoc-string "bar" (org-get-tags))))))
  6815. ;; Obey to `org-use-tag-inheritance'.
  6816. (should-not
  6817. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6818. (let ((org-use-tag-inheritance nil))
  6819. (assoc-string "foo" (org-get-tags)))))
  6820. (should-not
  6821. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6822. (let ((org-use-tag-inheritance nil)
  6823. (org-file-tags '("foo")))
  6824. (assoc-string "foo" (org-get-tags)))))
  6825. (should-not
  6826. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6827. (let ((org-use-tag-inheritance '("bar")))
  6828. (assoc-string "foo" (org-get-tags)))))
  6829. (should
  6830. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6831. (let ((org-use-tag-inheritance '("bar")))
  6832. (assoc-string "bar" (org-get-tags)))))
  6833. (should-not
  6834. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6835. (let ((org-use-tag-inheritance "b.*"))
  6836. (assoc-string "foo" (org-get-tags)))))
  6837. (should
  6838. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6839. (let ((org-use-tag-inheritance "b.*"))
  6840. (assoc-string "bar" (org-get-tags)))))
  6841. ;; When optional argument LOCAL is non-nil, ignore tag inheritance.
  6842. (should
  6843. (equal '("baz")
  6844. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6845. (let ((org-use-tag-inheritance t))
  6846. (org-get-tags nil t)))))
  6847. ;; When optional argument POS is non-nil, get tags there instead.
  6848. (should
  6849. (equal '("foo")
  6850. (org-test-with-temp-text "* H1 :foo:\n* <point>H2 :bar:"
  6851. (org-get-tags 1))))
  6852. ;; Make sure tags excluded from inheritance are returned if local
  6853. (should
  6854. (equal '("foo")
  6855. (org-test-with-temp-text "* Test :foo:"
  6856. (let ((org-use-tag-inheritance t)
  6857. (org-tags-exclude-from-inheritance '("foo")))
  6858. (org-get-tags)))))
  6859. ;; Test the collection of tags from #+filetags and parent tags.
  6860. (should
  6861. (equal '("a" "b" "c" "d")
  6862. (org-test-with-temp-text (concat "#+filetags: a\n"
  6863. "* Level 1 :b:\n"
  6864. "** Level 2 :c:\n"
  6865. "*** Level 3 :d:\n"
  6866. "<point>")
  6867. (let ((org-use-tag-inheritance t))
  6868. (org-mode-restart) ;So that `org-file-tags' get populated from #+filetags
  6869. (org-get-tags)))))
  6870. ;; Pathological case: tagged headline with an empty body.
  6871. (should (org-test-with-temp-text "* :tag:" (org-get-tags))))
  6872. (ert-deftest test-org/set-tags ()
  6873. "Test `org-set-tags' specifications."
  6874. ;; Throw an error on invalid data.
  6875. (should-error
  6876. (org-test-with-temp-text "* H"
  6877. (org-set-tags 'foo)))
  6878. ;; `nil', an empty, and a blank string remove all tags.
  6879. (should
  6880. (equal "* H"
  6881. (org-test-with-temp-text "* H :tag1:tag2:"
  6882. (org-set-tags nil)
  6883. (buffer-string))))
  6884. (should
  6885. (equal "* H"
  6886. (org-test-with-temp-text "* H :tag1:tag2:"
  6887. (org-set-tags "")
  6888. (buffer-string))))
  6889. (should
  6890. (equal "* H"
  6891. (org-test-with-temp-text "* H :tag1:tag2:"
  6892. (org-set-tags " ")
  6893. (buffer-string))))
  6894. ;; If there's nothing to remove, just bail out.
  6895. (should
  6896. (equal "* H"
  6897. (org-test-with-temp-text "* H"
  6898. (org-set-tags nil)
  6899. (buffer-string))))
  6900. (should
  6901. (equal "* "
  6902. (org-test-with-temp-text "* "
  6903. (org-set-tags nil)
  6904. (buffer-string))))
  6905. ;; If DATA is a tag string, set current tags to it, even if it means
  6906. ;; replacing old tags.
  6907. (should
  6908. (equal "* H :tag0:"
  6909. (org-test-with-temp-text "* H :tag1:tag2:"
  6910. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  6911. (buffer-string))))
  6912. (should
  6913. (equal "* H :tag0:"
  6914. (org-test-with-temp-text "* H"
  6915. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  6916. (buffer-string))))
  6917. ;; If DATA is a list, set tags to this list, even if it means
  6918. ;; replacing old tags.
  6919. (should
  6920. (equal "* H :tag0:"
  6921. (org-test-with-temp-text "* H :tag1:tag2:"
  6922. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6923. (buffer-string))))
  6924. (should
  6925. (equal "* H :tag0:"
  6926. (org-test-with-temp-text "* H"
  6927. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6928. (buffer-string))))
  6929. ;; When set, apply `org-tags-sort-function'.
  6930. (should
  6931. (equal "* H :a:b:"
  6932. (org-test-with-temp-text "* H"
  6933. (let ((org-tags-column 1)
  6934. (org-tags-sort-function #'string<))
  6935. (org-set-tags '("b" "a"))
  6936. (buffer-string)))))
  6937. ;; When new tags are identical to the previous ones, still align.
  6938. (should
  6939. (equal "* H :foo:"
  6940. (org-test-with-temp-text "* H :foo:"
  6941. (let ((org-tags-column 1))
  6942. (org-set-tags '("foo"))
  6943. (buffer-string)))))
  6944. ;; When tags have been changed, run `org-after-tags-change-hook'.
  6945. (should
  6946. (catch :return
  6947. (org-test-with-temp-text "* H :foo:"
  6948. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  6949. (org-set-tags '("bar"))
  6950. nil))))
  6951. (should-not
  6952. (catch :return
  6953. (org-test-with-temp-text "* H :foo:"
  6954. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  6955. (org-set-tags '("foo"))
  6956. nil))))
  6957. ;; Special case: handle empty headlines.
  6958. (should
  6959. (equal "* :tag0:"
  6960. (org-test-with-temp-text "* "
  6961. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6962. (buffer-string))))
  6963. ;; Modify buffer only when a tag change happens or alignment is
  6964. ;; done.
  6965. (should-not
  6966. (org-test-with-temp-text "* H :foo:"
  6967. (set-buffer-modified-p nil)
  6968. (let ((org-tags-column 1)) (org-set-tags '("foo")))
  6969. (buffer-modified-p)))
  6970. (should
  6971. (org-test-with-temp-text "* H :foo:"
  6972. (set-buffer-modified-p nil)
  6973. (let ((org-tags-column 10)) (org-set-tags '("foo")))
  6974. (buffer-modified-p)))
  6975. (should
  6976. (org-test-with-temp-text "* H :foo:"
  6977. (set-buffer-modified-p nil)
  6978. (let ((org-tags-column 10)) (org-set-tags '("bar")))
  6979. (buffer-modified-p)))
  6980. ;; Pathological case: when setting tags of a folded headline, do not
  6981. ;; let new tags being sucked into invisibility.
  6982. (should-not
  6983. (org-test-with-temp-text "* H1\nContent\n* H2\n\n Other Content"
  6984. ;; Show only headlines
  6985. (org-content)
  6986. ;; Set NEXT tag on current entry
  6987. (org-set-tags ":NEXT:")
  6988. ;; Move point to that NEXT tag
  6989. (search-forward "NEXT") (backward-word)
  6990. ;; And it should be visible (i.e. no overlays)
  6991. (overlays-at (point)))))
  6992. (ert-deftest test-org/set-tags-command ()
  6993. "Test `org-set-tags-command' specifications"
  6994. ;; Set tags at current headline.
  6995. (should
  6996. (equal "* H1 :foo:"
  6997. (org-test-with-temp-text "* H1"
  6998. (cl-letf (((symbol-function 'completing-read-multiple)
  6999. (lambda (&rest args) '("foo"))))
  7000. (let ((org-use-fast-tag-selection nil)
  7001. (org-tags-column 1))
  7002. (org-set-tags-command)))
  7003. (buffer-string))))
  7004. ;; Preserve position when called from the section below.
  7005. (should
  7006. (equal "* H1 :foo:\nContents"
  7007. (org-test-with-temp-text "* H1\n<point>Contents"
  7008. (cl-letf (((symbol-function 'completing-read-multiple)
  7009. (lambda (&rest args) '("foo"))))
  7010. (let ((org-use-fast-tag-selection nil)
  7011. (org-tags-column 1))
  7012. (org-set-tags-command)))
  7013. (buffer-string))))
  7014. (should-not
  7015. (equal "* H1 :foo:\nContents2"
  7016. (org-test-with-temp-text "* H1\n<point>Contents2"
  7017. (cl-letf (((symbol-function 'completing-read-multiple)
  7018. (lambda (&rest args) '("foo"))))
  7019. (let ((org-use-fast-tag-selection nil)
  7020. (org-tags-column 1))
  7021. (org-set-tags-command)))
  7022. (org-at-heading-p))))
  7023. ;; When a region is active and
  7024. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  7025. ;; same value in all headlines in region.
  7026. (should
  7027. (equal "* H1 :foo:\nContents\n* H2 :foo:"
  7028. (org-test-with-temp-text "* H1\nContents\n* H2"
  7029. (cl-letf (((symbol-function 'completing-read-multiple)
  7030. (lambda (&rest args) '("foo"))))
  7031. (let ((org-use-fast-tag-selection nil)
  7032. (org-loop-over-headlines-in-active-region t)
  7033. (org-tags-column 1))
  7034. (transient-mark-mode 1)
  7035. (push-mark (point) t t)
  7036. (goto-char (point-max))
  7037. (org-set-tags-command)))
  7038. (buffer-string))))
  7039. (should
  7040. (equal "* H1\nContents\n* H2 :foo:"
  7041. (org-test-with-temp-text "* H1\nContents\n* H2"
  7042. (cl-letf (((symbol-function 'completing-read-multiple)
  7043. (lambda (&rest args) '("foo"))))
  7044. (let ((org-use-fast-tag-selection nil)
  7045. (org-loop-over-headlines-in-active-region nil)
  7046. (org-tags-column 1))
  7047. (transient-mark-mode 1)
  7048. (push-mark (point) t t)
  7049. (goto-char (point-max))
  7050. (org-set-tags-command)))
  7051. (buffer-string))))
  7052. ;; With a C-u prefix argument, align all tags in the buffer.
  7053. (should
  7054. (equal "* H1 :foo:\n* H2 :bar:"
  7055. (org-test-with-temp-text "* H1 :foo:\n* H2 :bar:"
  7056. (let ((org-tags-column 1)) (org-set-tags-command '(4)))
  7057. (buffer-string))))
  7058. ;; Point does not move with empty headline.
  7059. (should
  7060. (equal ":foo:"
  7061. (org-test-with-temp-text "* <point>"
  7062. (cl-letf (((symbol-function 'completing-read-multiple)
  7063. (lambda (&rest args) '("foo"))))
  7064. (let ((org-use-fast-tag-selection nil)
  7065. (org-tags-column 1))
  7066. (org-set-tags-command)))
  7067. (buffer-substring (point) (line-end-position)))))
  7068. ;; Point does not move at start of line.
  7069. (should
  7070. (equal "* H1 :foo:"
  7071. (org-test-with-temp-text "* H1"
  7072. (cl-letf (((symbol-function 'completing-read-multiple)
  7073. (lambda (&rest args) '("foo"))))
  7074. (let ((org-use-fast-tag-selection nil)
  7075. (org-tags-column 1))
  7076. (org-set-tags-command)))
  7077. (buffer-substring (point) (line-end-position)))))
  7078. ;; Point does not move when within *'s.
  7079. (should
  7080. (equal "* H1 :foo:"
  7081. (org-test-with-temp-text "*<point>* H1"
  7082. (cl-letf (((symbol-function 'completing-read-multiple)
  7083. (lambda (&rest args) '("foo"))))
  7084. (let ((org-use-fast-tag-selection nil)
  7085. (org-tags-column 1))
  7086. (org-set-tags-command)))
  7087. (buffer-substring (point) (line-end-position)))))
  7088. ;; Point workaround does not get fooled when looking at a space.
  7089. (should
  7090. (equal " b :foo:"
  7091. (org-test-with-temp-text "* a<point> b"
  7092. (cl-letf (((symbol-function 'completing-read-multiple)
  7093. (lambda (&rest args) '("foo"))))
  7094. (let ((org-use-fast-tag-selection nil)
  7095. (org-tags-column 1))
  7096. (org-set-tags-command)))
  7097. (buffer-substring (point) (line-end-position)))))
  7098. ;; Handle tags both set locally and inherited.
  7099. (should
  7100. (equal "b :foo:"
  7101. (org-test-with-temp-text "* a :foo:\n** <point>b :foo:"
  7102. (cl-letf (((symbol-function 'completing-read-multiple)
  7103. (lambda (prompt coll &optional pred req initial &rest args)
  7104. (list initial))))
  7105. (let ((org-use-fast-tag-selection nil)
  7106. (org-tags-column 1))
  7107. (org-set-tags-command)))
  7108. (buffer-substring (point) (line-end-position))))))
  7109. (ert-deftest test-org/toggle-tag ()
  7110. "Test `org-toggle-tag' specifications."
  7111. ;; Insert missing tag.
  7112. (should
  7113. (equal "* H :tag:"
  7114. (org-test-with-temp-text "* H"
  7115. (let ((org-tags-column 1)) (org-toggle-tag "tag"))
  7116. (buffer-string))))
  7117. (should
  7118. (equal "* H :tag1:tag2:"
  7119. (org-test-with-temp-text "* H :tag1:"
  7120. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  7121. (buffer-string))))
  7122. ;; Remove existing tag.
  7123. (should
  7124. (equal "* H"
  7125. (org-test-with-temp-text "* H :tag:"
  7126. (org-toggle-tag "tag")
  7127. (buffer-string))))
  7128. (should
  7129. (equal "* H :tag1:"
  7130. (org-test-with-temp-text "* H :tag1:tag2:"
  7131. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  7132. (buffer-string))))
  7133. (should
  7134. (equal "* H :tag2:"
  7135. (org-test-with-temp-text "* H :tag1:tag2:"
  7136. (let ((org-tags-column 1)) (org-toggle-tag "tag1"))
  7137. (buffer-string))))
  7138. ;; With optional argument ONOFF set to `on', try to insert the tag,
  7139. ;; even if its already there.
  7140. (should
  7141. (equal "* H :tag:"
  7142. (org-test-with-temp-text "* H"
  7143. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  7144. (buffer-string))))
  7145. (should
  7146. (equal "* H :tag:"
  7147. (org-test-with-temp-text "* H :tag:"
  7148. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  7149. (buffer-string))))
  7150. ;; With optional argument ONOFF set to `off', try to remove the tag,
  7151. ;; even if its not there.
  7152. (should
  7153. (equal "* H"
  7154. (org-test-with-temp-text "* H :tag:"
  7155. (org-toggle-tag "tag" 'off)
  7156. (buffer-string))))
  7157. (should
  7158. (equal "* H :tag:"
  7159. (org-test-with-temp-text "* H :tag:"
  7160. (let ((org-tags-column 1)) (org-toggle-tag "foo" 'off))
  7161. (buffer-string))))
  7162. ;; Special case: Handle properly tag inheritance. In particular, do
  7163. ;; not set inherited tags.
  7164. (should
  7165. (equal "* H1 :tag:\n** H2 :tag2:tag:"
  7166. (org-test-with-temp-text "* H1 :tag:\n** <point>H2 :tag2:"
  7167. (let ((org-use-tag-inheritance t)
  7168. (org-tags-column 1))
  7169. (org-toggle-tag "tag"))
  7170. (buffer-string))))
  7171. (should
  7172. (equal "* H1 :tag1:tag2:\n** H2 :foo:"
  7173. (org-test-with-temp-text "* H1 :tag1:tag2:\n** <point>H2"
  7174. (let ((org-use-tag-inheritance t)
  7175. (org-tags-column 1))
  7176. (org-toggle-tag "foo"))
  7177. (buffer-string)))))
  7178. (ert-deftest test-org/tags-expand ()
  7179. "Test `org-tags-expand' specifications."
  7180. ;; Expand tag groups as a regexp enclosed within curly brackets.
  7181. (should
  7182. (equal "{\\<[ABC]\\>}"
  7183. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7184. (org-mode-restart)
  7185. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  7186. (should
  7187. (equal "{\\<\\(?:Aa\\|Bb\\|Cc\\)\\>}"
  7188. (org-test-with-temp-text "#+TAGS: [ Aa : Bb Cc ]"
  7189. (org-mode-restart)
  7190. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "Aa")))))
  7191. ;; Preserve operator before the regexp.
  7192. (should
  7193. (equal "+{\\<[ABC]\\>}"
  7194. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7195. (org-mode-restart)
  7196. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "+A")))))
  7197. (should
  7198. (equal "-{\\<[ABC]\\>}"
  7199. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7200. (org-mode-restart)
  7201. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "-A")))))
  7202. ;; Handle "|" syntax.
  7203. (should
  7204. (equal "{\\<[ABC]\\>}|D"
  7205. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7206. (org-mode-restart)
  7207. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|D")))))
  7208. ;; Handle nested groups.
  7209. (should
  7210. (equal "{\\<[A-D]\\>}"
  7211. (org-test-with-temp-text "#+TAGS: [ A : B C ]\n#+TAGS: [ B : D ]"
  7212. (org-mode-restart)
  7213. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  7214. ;; Expand multiple occurrences of the same group.
  7215. (should
  7216. (equal "{\\<[ABC]\\>}|{\\<[ABC]\\>}"
  7217. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7218. (org-mode-restart)
  7219. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|A")))))
  7220. ;; Preserve regexp matches.
  7221. (should
  7222. (equal "{A+}"
  7223. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7224. (org-mode-restart)
  7225. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "{A+}"))))))
  7226. ;;; TODO keywords
  7227. (ert-deftest test-org/auto-repeat-maybe ()
  7228. "Test `org-auto-repeat-maybe' specifications."
  7229. ;; Do not auto repeat when there is no valid time stamp with
  7230. ;; a repeater in the entry.
  7231. (should-not
  7232. (string-prefix-p
  7233. "* TODO H"
  7234. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7235. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
  7236. (org-todo "DONE")
  7237. (buffer-string)))))
  7238. (should-not
  7239. (string-prefix-p
  7240. "* TODO H"
  7241. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7242. (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
  7243. (org-todo "DONE")
  7244. (buffer-string)))))
  7245. ;; When switching to DONE state, switch back to first TODO keyword
  7246. ;; in sequence, or the same keyword if they have different types.
  7247. (should
  7248. (string-prefix-p
  7249. "* TODO H"
  7250. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7251. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7252. (org-todo "DONE")
  7253. (buffer-string)))))
  7254. (should
  7255. (string-prefix-p
  7256. "* KWD1 H"
  7257. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  7258. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  7259. (org-todo "DONE")
  7260. (buffer-string)))))
  7261. (should
  7262. (string-prefix-p
  7263. "* KWD2 H"
  7264. (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
  7265. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  7266. (org-todo "DONE")
  7267. (buffer-string)))))
  7268. ;; If there was no TODO keyword in the first place, do not insert
  7269. ;; any either.
  7270. (should
  7271. (string-prefix-p
  7272. "* H"
  7273. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7274. (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
  7275. (org-todo "DONE")
  7276. (buffer-string)))))
  7277. ;; Revert to REPEAT_TO_STATE, if set.
  7278. (should
  7279. (string-prefix-p
  7280. "* KWD2 H"
  7281. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  7282. (org-test-with-temp-text
  7283. "* KWD2 H
  7284. :PROPERTIES:
  7285. :REPEAT_TO_STATE: KWD2
  7286. :END:
  7287. <2012-03-29 Thu +2y>"
  7288. (org-todo "DONE")
  7289. (buffer-string)))))
  7290. ;; When switching to DONE state, update base date. If there are
  7291. ;; multiple repeated time stamps, update them all.
  7292. (should
  7293. (string-match-p
  7294. "<2014-03-29 .* \\+2y>"
  7295. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7296. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7297. (org-todo "DONE")
  7298. (buffer-string)))))
  7299. (should
  7300. (string-match-p
  7301. "<2015-03-04 .* \\+1y>"
  7302. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7303. (org-test-with-temp-text
  7304. "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
  7305. (org-todo "DONE")
  7306. (buffer-string)))))
  7307. ;; Throw an error if repeater unit is the hour and no time is
  7308. ;; provided in the time-stamp.
  7309. (should-error
  7310. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7311. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
  7312. (org-todo "DONE")
  7313. (buffer-string))))
  7314. ;; Handle every repeater type using hours step.
  7315. (should
  7316. (string-match-p
  7317. "2014-03-04 .* 02:00"
  7318. (org-test-at-time "<2014-03-04 02:35>"
  7319. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 +8h>"
  7320. (org-todo "DONE")
  7321. (buffer-string)))))
  7322. (should
  7323. (string-match-p
  7324. "2014-03-04 .* 10:00"
  7325. (org-test-at-time "<2014-03-04 02:35>"
  7326. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 ++8h>"
  7327. (org-todo "DONE")
  7328. (buffer-string)))))
  7329. (should
  7330. (string-match-p
  7331. "2014-03-04 .* 10:35"
  7332. (org-test-at-time "<2014-03-04 02:35>"
  7333. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 .+8h>"
  7334. (org-todo "DONE")
  7335. (buffer-string)))))
  7336. ;; Do not repeat inactive time stamps with a repeater.
  7337. (should-not
  7338. (string-match-p
  7339. "\\[2014-03-29 .* \\+2y\\]"
  7340. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7341. (org-test-with-temp-text
  7342. "* TODO H\n[2012-03-29 Thu. +2y]"
  7343. (org-todo "DONE")
  7344. (buffer-string)))))
  7345. ;; Do not repeat commented time stamps.
  7346. (should-not
  7347. (string-prefix-p
  7348. "<2015-03-04 .* \\+1y>"
  7349. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7350. (org-test-with-temp-text
  7351. "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
  7352. (org-todo "DONE")
  7353. (buffer-string)))))
  7354. (should-not
  7355. (string-prefix-p
  7356. "<2015-03-04 .* \\+1y>"
  7357. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7358. (org-test-with-temp-text
  7359. "* TODO H
  7360. <2012-03-29 Thu. +2y>
  7361. #+BEGIN_EXAMPLE
  7362. <2014-03-04 Tue +1y>
  7363. #+END_EXAMPLE"
  7364. (org-todo "DONE")
  7365. (buffer-string)))))
  7366. ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
  7367. ;; entry, record time of last repeat.
  7368. (should-not
  7369. (string-match-p
  7370. ":LAST_REPEAT:"
  7371. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  7372. (org-log-repeat nil))
  7373. (cl-letf (((symbol-function 'org-add-log-setup)
  7374. (lambda (&rest args) nil)))
  7375. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  7376. (org-todo "DONE")
  7377. (buffer-string))))))
  7378. (should
  7379. (string-match-p
  7380. ":LAST_REPEAT:"
  7381. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  7382. (org-log-repeat t))
  7383. (cl-letf (((symbol-function 'org-add-log-setup)
  7384. (lambda (&rest args) nil)))
  7385. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  7386. (org-todo "DONE")
  7387. (buffer-string))))))
  7388. (should
  7389. (string-match-p
  7390. ":LAST_REPEAT:"
  7391. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7392. (cl-letf (((symbol-function 'org-add-log-setup)
  7393. (lambda (&rest args) nil)))
  7394. (org-test-with-temp-text
  7395. "* TODO H\n<2012-03-29 Thu +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
  7396. (org-todo "DONE")
  7397. (buffer-string))))))
  7398. ;; When a SCHEDULED entry has no repeater, remove it upon repeating
  7399. ;; the entry as it is no longer relevant.
  7400. (should-not
  7401. (string-match-p
  7402. "^SCHEDULED:"
  7403. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7404. (org-test-with-temp-text
  7405. "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
  7406. (org-todo "DONE")
  7407. (buffer-string)))))
  7408. ;; Properly advance repeater even when a clock entry is specified
  7409. ;; and `org-log-repeat' is nil.
  7410. (should
  7411. (string-match-p
  7412. "SCHEDULED: <2014-03-29"
  7413. (let ((org-log-repeat nil)
  7414. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7415. (org-test-with-temp-text
  7416. "* TODO H
  7417. SCHEDULED: <2012-03-29 Thu +2y>
  7418. CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] => 6:40"
  7419. (org-todo "DONE")
  7420. (buffer-string)))))
  7421. ;; Make sure that logbook state change record does not get
  7422. ;; duplicated when `org-log-repeat' `org-log-done' are non-nil.
  7423. (should
  7424. (string-match-p
  7425. (rx "* TODO Read book
  7426. SCHEDULED: <2021-06-16 " (1+ (not space)) " +1d>
  7427. :PROPERTIES:
  7428. :LAST_REPEAT:" (1+ nonl) "
  7429. :END:
  7430. - State \"DONE\" from \"TODO\"" (1+ nonl) buffer-end)
  7431. (let ((org-log-repeat 'time)
  7432. (org-todo-keywords '((sequence "TODO" "|" "DONE(d!)")))
  7433. (org-log-into-drawer nil))
  7434. (org-test-with-temp-text
  7435. "* TODO Read book
  7436. SCHEDULED: <2021-06-15 Tue +1d>"
  7437. (org-todo "DONE")
  7438. (when (memq 'org-add-log-note post-command-hook)
  7439. (org-add-log-note))
  7440. (buffer-string))))))
  7441. (ert-deftest test-org/org-log-done ()
  7442. "Test `org-log-done' specifications."
  7443. ;; nil value.
  7444. (should
  7445. (string=
  7446. "* DONE task"
  7447. (let ((org-log-done nil)
  7448. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7449. (org-test-with-temp-text
  7450. "* TODO task"
  7451. (org-todo "DONE")
  7452. (when (memq 'org-add-log-note post-command-hook)
  7453. (org-add-log-note))
  7454. (buffer-string)))))
  7455. ;; `time' value.
  7456. (should
  7457. (string=
  7458. (format
  7459. "* DONE task
  7460. CLOSED: %s"
  7461. (org-test-with-temp-text ""
  7462. (org-insert-time-stamp (current-time) t t)
  7463. (buffer-string)))
  7464. (let ((org-log-done 'time)
  7465. (org-log-done-with-time t)
  7466. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7467. (org-test-with-temp-text
  7468. "* TODO task"
  7469. (org-todo "DONE")
  7470. (when (memq 'org-add-log-note post-command-hook)
  7471. (org-add-log-note))
  7472. (buffer-string)))))
  7473. (should
  7474. (string=
  7475. (format
  7476. "* DONE task
  7477. CLOSED: %s"
  7478. (org-test-with-temp-text ""
  7479. (org-insert-time-stamp (current-time) nil t)
  7480. (buffer-string)))
  7481. (let ((org-log-done 'time)
  7482. (org-log-done-with-time nil)
  7483. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7484. (org-test-with-temp-text
  7485. "* TODO task"
  7486. (org-todo "DONE")
  7487. (when (memq 'org-add-log-note post-command-hook)
  7488. (org-add-log-note))
  7489. (buffer-string)))))
  7490. ;; TODO: Test `note' value.
  7491. ;; Test startup overrides.
  7492. (should
  7493. (string=
  7494. "#+STARTUP: nologdone
  7495. * DONE task"
  7496. (let ((org-log-done 'time)
  7497. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7498. (org-test-with-temp-text
  7499. "#+STARTUP: nologdone
  7500. <point>* TODO task"
  7501. (org-set-regexps-and-options)
  7502. (org-todo "DONE")
  7503. (when (memq 'org-add-log-note post-command-hook)
  7504. (org-add-log-note))
  7505. (buffer-string)))))
  7506. (should
  7507. (string=
  7508. (format
  7509. "#+STARTUP: logdone
  7510. * DONE task
  7511. CLOSED: %s"
  7512. (org-test-with-temp-text ""
  7513. (org-insert-time-stamp (current-time) t t)
  7514. (buffer-string)))
  7515. (let ((org-log-done nil)
  7516. (org-log-done-with-time t)
  7517. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7518. (org-test-with-temp-text
  7519. "#+STARTUP: logdone
  7520. <point>* TODO task"
  7521. (org-set-regexps-and-options)
  7522. (org-todo "DONE")
  7523. (when (memq 'org-add-log-note post-command-hook)
  7524. (org-add-log-note))
  7525. (buffer-string)))))
  7526. ;; Test local property overrides.
  7527. (should
  7528. (string=
  7529. "* DONE task
  7530. :PROPERTIES:
  7531. :LOGGING: nil
  7532. :END:"
  7533. (let ((org-log-done 'time)
  7534. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7535. (org-test-with-temp-text
  7536. "* TODO task
  7537. :PROPERTIES:
  7538. :LOGGING: nil
  7539. :END:"
  7540. (org-todo "DONE")
  7541. (when (memq 'org-add-log-note post-command-hook)
  7542. (org-add-log-note))
  7543. (buffer-string)))))
  7544. (should
  7545. (string=
  7546. (format
  7547. "* DONE task
  7548. CLOSED: %s
  7549. :PROPERTIES:
  7550. :LOGGING: logdone
  7551. :END:"
  7552. (org-test-with-temp-text ""
  7553. (org-insert-time-stamp (current-time) t t)
  7554. (buffer-string)))
  7555. (let ((org-log-done nil)
  7556. (org-log-done-with-time t)
  7557. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7558. (org-test-with-temp-text
  7559. "* TODO task
  7560. :PROPERTIES:
  7561. :LOGGING: logdone
  7562. :END:"
  7563. (org-todo "DONE")
  7564. (when (memq 'org-add-log-note post-command-hook)
  7565. (org-add-log-note))
  7566. (buffer-string))))))
  7567. (ert-deftest test-org/org-todo-prefix ()
  7568. "Test `org-todo' prefix arg behavior."
  7569. ;; FIXME: Add tests for all other allowed prefix arguments.
  7570. ;; -1 prefix arg should cancel repeater and mark DONE.
  7571. (should
  7572. (string-match-p
  7573. "DONE H\\(.*\n\\)*<2012-03-29 Thu \\+0y>"
  7574. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7575. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7576. (org-todo -1)
  7577. (buffer-string)))))
  7578. ;; - prefix arg should cancel repeater and mark DONE.
  7579. (should
  7580. (string-match-p
  7581. "DONE H\\(.*\n\\)*<2012-03-29 Thu \\+0y>"
  7582. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7583. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7584. (org-todo '-)
  7585. (buffer-string))))))
  7586. ;;; Timestamps API
  7587. (ert-deftest test-org/at-timestamp-p ()
  7588. "Test `org-at-timestamp-p' specifications."
  7589. (should
  7590. (org-test-with-temp-text "<2012-03-29 Thu>"
  7591. (org-at-timestamp-p)))
  7592. (should-not
  7593. (org-test-with-temp-text "2012-03-29 Thu"
  7594. (org-at-timestamp-p)))
  7595. ;; Test return values.
  7596. (should
  7597. (eq 'bracket
  7598. (org-test-with-temp-text "<2012-03-29 Thu>"
  7599. (org-at-timestamp-p))))
  7600. (should
  7601. (eq 'year
  7602. (org-test-with-temp-text "<<point>2012-03-29 Thu>"
  7603. (org-at-timestamp-p))))
  7604. (should
  7605. (eq 'month
  7606. (org-test-with-temp-text "<2012-<point>03-29 Thu>"
  7607. (org-at-timestamp-p))))
  7608. (should
  7609. (eq 'day
  7610. (org-test-with-temp-text "<2012-03-<point>29 Thu>"
  7611. (org-at-timestamp-p))))
  7612. (should
  7613. (eq 'day
  7614. (org-test-with-temp-text "<2012-03-29 T<point>hu>"
  7615. (org-at-timestamp-p))))
  7616. (should
  7617. (wholenump
  7618. (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
  7619. (org-at-timestamp-p))))
  7620. (should
  7621. (eq 'bracket
  7622. (org-test-with-temp-text "<2012-03-29 Thu<point>>"
  7623. (org-at-timestamp-p))))
  7624. (should
  7625. (eq 'after
  7626. (org-test-with-temp-text "<2012-03-29 Thu><point>»"
  7627. (org-at-timestamp-p))))
  7628. ;; Test `inactive' optional argument.
  7629. (should
  7630. (org-test-with-temp-text "[2012-03-29 Thu]"
  7631. (org-at-timestamp-p 'inactive)))
  7632. (should-not
  7633. (org-test-with-temp-text "[2012-03-29 Thu]"
  7634. (org-at-timestamp-p)))
  7635. ;; When optional argument is `agenda', recognize time-stamps in
  7636. ;; planning info line, property drawers and clocks.
  7637. (should
  7638. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7639. (org-at-timestamp-p 'agenda)))
  7640. (should-not
  7641. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7642. (org-at-timestamp-p)))
  7643. (should
  7644. (org-test-with-temp-text
  7645. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7646. (org-at-timestamp-p 'agenda)))
  7647. (should-not
  7648. (org-test-with-temp-text
  7649. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7650. (org-at-timestamp-p)))
  7651. (should
  7652. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7653. (let ((org-agenda-include-inactive-timestamps t))
  7654. (org-at-timestamp-p 'agenda))))
  7655. (should-not
  7656. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7657. (let ((org-agenda-include-inactive-timestamps t))
  7658. (org-at-timestamp-p))))
  7659. (should-not
  7660. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7661. (let ((org-agenda-include-inactive-timestamps t))
  7662. (org-at-timestamp-p 'inactive))))
  7663. ;; When optional argument is `lax', match any part of the document
  7664. ;; with Org timestamp syntax.
  7665. (should
  7666. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7667. (org-at-timestamp-p 'lax)))
  7668. (should-not
  7669. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7670. (org-at-timestamp-p)))
  7671. (should
  7672. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7673. (org-at-timestamp-p 'lax)))
  7674. (should-not
  7675. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7676. (org-at-timestamp-p)))
  7677. (should
  7678. (org-test-with-temp-text
  7679. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7680. (org-at-timestamp-p 'lax)))
  7681. (should-not
  7682. (org-test-with-temp-text
  7683. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7684. (org-at-timestamp-p)))
  7685. ;; Optional argument `lax' also matches inactive timestamps.
  7686. (should
  7687. (org-test-with-temp-text "# [2012-03-29 Thu]<point>"
  7688. (org-at-timestamp-p 'lax))))
  7689. (ert-deftest test-org/time-stamp ()
  7690. "Test `org-time-stamp' specifications."
  7691. ;; Insert chosen time stamp at point.
  7692. (should
  7693. (string-match
  7694. "Te<2014-03-04 .*?>xt"
  7695. (org-test-with-temp-text "Te<point>xt"
  7696. (cl-letf (((symbol-function 'org-read-date)
  7697. (lambda (&rest args)
  7698. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7699. (org-time-stamp nil)
  7700. (buffer-string)))))
  7701. ;; With a prefix argument, also insert time.
  7702. (should
  7703. (string-match
  7704. "Te<2014-03-04 .*? 00:41>xt"
  7705. (org-test-with-temp-text "Te<point>xt"
  7706. (cl-letf (((symbol-function 'org-read-date)
  7707. (lambda (&rest args)
  7708. (apply #'encode-time
  7709. (org-parse-time-string "2014-03-04 00:41")))))
  7710. (org-time-stamp '(4))
  7711. (buffer-string)))))
  7712. ;; With two universal prefix arguments, insert an active timestamp
  7713. ;; with the current time without prompting the user.
  7714. (should
  7715. (string-match
  7716. "Te<2014-03-04 .*? 00:41>xt"
  7717. (org-test-with-temp-text "Te<point>xt"
  7718. (org-test-at-time "2014-03-04 00:41"
  7719. (org-time-stamp '(16))
  7720. (buffer-string)))))
  7721. ;; When optional argument is non-nil, insert an inactive timestamp.
  7722. (should
  7723. (string-match
  7724. "Te\\[2014-03-04 .*?\\]xt"
  7725. (org-test-with-temp-text "Te<point>xt"
  7726. (cl-letf (((symbol-function 'org-read-date)
  7727. (lambda (&rest args)
  7728. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7729. (org-time-stamp nil t)
  7730. (buffer-string)))))
  7731. ;; When called from a timestamp, replace existing one.
  7732. (should
  7733. (string-match
  7734. "<2014-03-04 .*?>"
  7735. (org-test-with-temp-text "<2012-03-29<point> thu.>"
  7736. (cl-letf (((symbol-function 'org-read-date)
  7737. (lambda (&rest args)
  7738. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7739. (org-time-stamp nil)
  7740. (buffer-string)))))
  7741. (should
  7742. (string-match
  7743. "<2014-03-04 .*?>--<2014-03-04 .*?>"
  7744. (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
  7745. (cl-letf (((symbol-function 'org-read-date)
  7746. (lambda (&rest args)
  7747. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7748. (org-time-stamp nil)
  7749. (buffer-string)))))
  7750. ;; When replacing a timestamp, preserve repeater, if any.
  7751. (should
  7752. (string-match
  7753. "<2014-03-04 .*? \\+2y>"
  7754. (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
  7755. (cl-letf (((symbol-function 'org-read-date)
  7756. (lambda (&rest args)
  7757. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7758. (org-time-stamp nil)
  7759. (buffer-string)))))
  7760. ;; When called twice in a raw, build a date range.
  7761. (should
  7762. (string-match
  7763. "<2012-03-29 .*?>--<2014-03-04 .*?>"
  7764. (org-test-with-temp-text "<2012-03-29 thu.><point>"
  7765. (cl-letf (((symbol-function 'org-read-date)
  7766. (lambda (&rest args)
  7767. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7768. (let ((last-command 'org-time-stamp)
  7769. (this-command 'org-time-stamp))
  7770. (org-time-stamp nil))
  7771. (buffer-string))))))
  7772. (ert-deftest test-org/timestamp-has-time-p ()
  7773. "Test `org-timestamp-has-time-p' specifications."
  7774. ;; With time.
  7775. (should
  7776. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7777. (org-timestamp-has-time-p (org-element-context))))
  7778. ;; Without time.
  7779. (should-not
  7780. (org-test-with-temp-text "<2012-03-29 Thu>"
  7781. (org-timestamp-has-time-p (org-element-context)))))
  7782. (ert-deftest test-org/get-repeat ()
  7783. "Test `org-get-repeat' specifications."
  7784. (should
  7785. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
  7786. (org-get-repeat)))
  7787. (should-not
  7788. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
  7789. (org-get-repeat)))
  7790. ;; Return proper repeat string.
  7791. (should
  7792. (equal "+2y"
  7793. (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
  7794. (org-get-repeat))))
  7795. ;; Prevent false positive (commented or verbatim time stamps)
  7796. (should-not
  7797. (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
  7798. (org-get-repeat)))
  7799. (should-not
  7800. (org-test-with-temp-text
  7801. "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
  7802. (org-get-repeat)))
  7803. ;; Return nil when called before first heading.
  7804. (should-not
  7805. (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
  7806. (org-get-repeat)))
  7807. ;; When called with an optional argument, extract repeater from that
  7808. ;; string instead.
  7809. (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
  7810. (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
  7811. (ert-deftest test-org/timestamp-format ()
  7812. "Test `org-timestamp-format' specifications."
  7813. ;; Regular test.
  7814. (should
  7815. (equal
  7816. "2012-03-29 16:40"
  7817. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7818. (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
  7819. ;; Range end.
  7820. (should
  7821. (equal
  7822. "2012-03-29"
  7823. (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
  7824. (org-timestamp-format (org-element-context) "%Y-%m-%d" t)))))
  7825. (ert-deftest test-org/timestamp-split-range ()
  7826. "Test `org-timestamp-split-range' specifications."
  7827. ;; Extract range start (active).
  7828. (should
  7829. (equal '(2012 3 29)
  7830. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7831. (let ((ts (org-timestamp-split-range (org-element-context))))
  7832. (mapcar (lambda (p) (org-element-property p ts))
  7833. '(:year-end :month-end :day-end))))))
  7834. ;; Extract range start (inactive)
  7835. (should
  7836. (equal '(2012 3 29)
  7837. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7838. (let ((ts (org-timestamp-split-range (org-element-context))))
  7839. (mapcar (lambda (p) (org-element-property p ts))
  7840. '(:year-end :month-end :day-end))))))
  7841. ;; Extract range end (active).
  7842. (should
  7843. (equal '(2012 3 30)
  7844. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7845. (let ((ts (org-timestamp-split-range
  7846. (org-element-context) t)))
  7847. (mapcar (lambda (p) (org-element-property p ts))
  7848. '(:year-end :month-end :day-end))))))
  7849. ;; Extract range end (inactive)
  7850. (should
  7851. (equal '(2012 3 30)
  7852. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7853. (let ((ts (org-timestamp-split-range
  7854. (org-element-context) t)))
  7855. (mapcar (lambda (p) (org-element-property p ts))
  7856. '(:year-end :month-end :day-end))))))
  7857. ;; Return the timestamp if not a range.
  7858. (should
  7859. (org-test-with-temp-text "[2012-03-29 Thu]"
  7860. (let* ((ts-orig (org-element-context))
  7861. (ts-copy (org-timestamp-split-range ts-orig)))
  7862. (eq ts-orig ts-copy))))
  7863. (should
  7864. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7865. (let* ((ts-orig (org-element-context))
  7866. (ts-copy (org-timestamp-split-range ts-orig)))
  7867. (eq ts-orig ts-copy)))))
  7868. (ert-deftest test-org/timestamp-translate ()
  7869. "Test `org-timestamp-translate' specifications."
  7870. ;; Translate whole date range.
  7871. (should
  7872. (equal "<29>--<30>"
  7873. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7874. (let ((org-display-custom-times t)
  7875. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7876. (org-timestamp-translate (org-element-context))))))
  7877. ;; Translate date range start.
  7878. (should
  7879. (equal "<29>"
  7880. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7881. (let ((org-display-custom-times t)
  7882. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7883. (org-timestamp-translate (org-element-context) 'start)))))
  7884. ;; Translate date range end.
  7885. (should
  7886. (equal "<30>"
  7887. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7888. (let ((org-display-custom-times t)
  7889. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7890. (org-timestamp-translate (org-element-context) 'end)))))
  7891. ;; Translate time range.
  7892. (should
  7893. (equal "<08>--<16>"
  7894. (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
  7895. (let ((org-display-custom-times t)
  7896. (org-time-stamp-custom-formats '("<%d>" . "<%H>")))
  7897. (org-timestamp-translate (org-element-context))))))
  7898. ;; Translate non-range timestamp.
  7899. (should
  7900. (equal "<29>"
  7901. (org-test-with-temp-text "<2012-03-29 Thu>"
  7902. (let ((org-display-custom-times t)
  7903. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7904. (org-timestamp-translate (org-element-context))))))
  7905. ;; Do not change `diary' timestamps.
  7906. (should
  7907. (equal "<%%(org-float t 4 2)>"
  7908. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7909. (let ((org-display-custom-times t)
  7910. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7911. (org-timestamp-translate (org-element-context)))))))
  7912. (ert-deftest test-org/timestamp-from-string ()
  7913. "Test `org-timestamp-from-string' specifications."
  7914. ;; Return nil if argument is not a valid Org timestamp.
  7915. (should-not (org-timestamp-from-string ""))
  7916. (should-not (org-timestamp-from-string nil))
  7917. (should-not (org-timestamp-from-string "<2012-03-29"))
  7918. ;; Otherwise, return a valid Org timestamp object.
  7919. (should
  7920. (string-match-p "<2012-03-29 .+>"
  7921. (org-element-interpret-data
  7922. (org-timestamp-from-string "<2012-03-29 Thu>"))))
  7923. (should
  7924. (string-match-p "[2014-03-04 .+]"
  7925. (org-element-interpret-data
  7926. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  7927. (ert-deftest test-org/timestamp-from-time ()
  7928. "Test `org-timestamp-from-time' specifications."
  7929. ;; Standard test.
  7930. (should
  7931. (string-match-p
  7932. "<2012-03-29 .+>"
  7933. (org-element-interpret-data
  7934. (org-timestamp-from-time
  7935. (apply #'encode-time
  7936. (org-parse-time-string "<2012-03-29 Thu 16:40>"))))))
  7937. ;; When optional argument WITH-TIME is non-nil, provide time
  7938. ;; information.
  7939. (should
  7940. (string-match-p
  7941. "<2012-03-29 .+ 16:40>"
  7942. (org-element-interpret-data
  7943. (org-timestamp-from-time
  7944. (apply #'encode-time
  7945. (org-parse-time-string "<2012-03-29 Thu 16:40>"))
  7946. t))))
  7947. ;; When optional argument INACTIVE is non-nil, return an inactive
  7948. ;; timestamp.
  7949. (should
  7950. (string-match-p
  7951. "[2012-03-29 .+]"
  7952. (org-element-interpret-data
  7953. (org-timestamp-from-time
  7954. (apply #'encode-time
  7955. (org-parse-time-string "<2012-03-29 Thu 16:40>"))
  7956. nil t)))))
  7957. (ert-deftest test-org/timestamp-to-time ()
  7958. "Test `org-timestamp-to-time' specifications."
  7959. (should
  7960. (equal "2014-03-04"
  7961. (format-time-string
  7962. "%Y-%m-%d"
  7963. (org-timestamp-to-time
  7964. (org-timestamp-from-string "<2014-03-04 Tue>")))))
  7965. (should
  7966. (equal "2014-03-04"
  7967. (format-time-string
  7968. "%Y-%m-%d"
  7969. (org-timestamp-to-time
  7970. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  7971. (should
  7972. (equal "2012-03-29 08:30"
  7973. (format-time-string
  7974. "%Y-%m-%d %H:%M"
  7975. (org-timestamp-to-time
  7976. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")))))
  7977. (should
  7978. (equal "2012-03-29"
  7979. (format-time-string
  7980. "%Y-%m-%d"
  7981. (org-timestamp-to-time
  7982. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")))))
  7983. (should
  7984. (equal "2012-03-29"
  7985. (format-time-string
  7986. "%Y-%m-%d"
  7987. (org-timestamp-to-time
  7988. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")))))
  7989. ;; When optional argument END is non-nil, use end of date range or
  7990. ;; time range.
  7991. (should
  7992. (equal "2012-03-29 16:40"
  7993. (format-time-string
  7994. "%Y-%m-%d %H:%M"
  7995. (org-timestamp-to-time
  7996. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")
  7997. t))))
  7998. (should
  7999. (equal "2014-03-04"
  8000. (format-time-string
  8001. "%Y-%m-%d"
  8002. (org-timestamp-to-time
  8003. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")
  8004. t))))
  8005. (should
  8006. (equal "2014-03-04"
  8007. (format-time-string
  8008. "%Y-%m-%d"
  8009. (org-timestamp-to-time
  8010. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")
  8011. t)))))
  8012. ;;; Yank and Kill
  8013. (ert-deftest test-org/paste-subtree ()
  8014. "Test `org-paste-subtree' specifications."
  8015. ;; Return an error if text to yank is not a set of subtrees.
  8016. (should-error (org-paste-subtree nil "Text"))
  8017. ;; Adjust level according to current one.
  8018. (should
  8019. (equal "* H\n* Text\n"
  8020. (org-test-with-temp-text "* H\n<point>"
  8021. (org-paste-subtree nil "* Text")
  8022. (buffer-string))))
  8023. (should
  8024. (equal "* H1\n** H2\n** Text\n"
  8025. (org-test-with-temp-text "* H1\n** H2\n<point>"
  8026. (org-paste-subtree nil "* Text")
  8027. (buffer-string))))
  8028. ;; When not on a heading, move to next heading before yanking.
  8029. (should
  8030. (equal "* H1\nParagraph\n* Text\n* H2"
  8031. (org-test-with-temp-text "* H1\n<point>Paragraph\n* H2"
  8032. (org-paste-subtree nil "* Text")
  8033. (buffer-string))))
  8034. ;; If point is between two headings, use the deepest level.
  8035. (should
  8036. (equal "* H1\n\n* Text\n* H2"
  8037. (org-test-with-temp-text "* H1\n<point>\n* H2"
  8038. (org-paste-subtree nil "* Text")
  8039. (buffer-string))))
  8040. (should
  8041. (equal "** H1\n\n** Text\n* H2"
  8042. (org-test-with-temp-text "** H1\n<point>\n* H2"
  8043. (org-paste-subtree nil "* Text")
  8044. (buffer-string))))
  8045. (should
  8046. (equal "* H1\n\n** Text\n** H2"
  8047. (org-test-with-temp-text "* H1\n<point>\n** H2"
  8048. (org-paste-subtree nil "* Text")
  8049. (buffer-string))))
  8050. ;; When on an empty heading, after the stars, deduce the new level
  8051. ;; from the number of stars.
  8052. (should
  8053. (equal "*** Text\n"
  8054. (org-test-with-temp-text "*** <point>"
  8055. (org-paste-subtree nil "* Text")
  8056. (buffer-string))))
  8057. ;; Optional argument LEVEL forces a level for the subtree.
  8058. (should
  8059. (equal "* H\n*** Text\n"
  8060. (org-test-with-temp-text "* H<point>"
  8061. (org-paste-subtree 3 "* Text")
  8062. (buffer-string)))))
  8063. (ert-deftest test-org/cut-and-paste-subtree ()
  8064. "Test `org-cut-subtree' and `org-paste-subtree'."
  8065. (should
  8066. (equal
  8067. "* Two
  8068. two
  8069. * One
  8070. "
  8071. (org-test-with-temp-text
  8072. "* One
  8073. <point>* Two
  8074. two
  8075. "
  8076. (call-interactively #'org-cut-subtree)
  8077. (goto-char (point-min))
  8078. (call-interactively #'org-paste-subtree)
  8079. (buffer-string))))
  8080. (should
  8081. (equal
  8082. "* One
  8083. * Two
  8084. "
  8085. (org-test-with-temp-text
  8086. "* One
  8087. <point>* Two
  8088. "
  8089. (call-interactively #'org-cut-subtree)
  8090. (backward-char)
  8091. (call-interactively #'org-paste-subtree)
  8092. (buffer-string)))))
  8093. (provide 'test-org)
  8094. ;;; test-org.el ends here