test-org.el 282 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592
  1. ;;; test-org.el --- tests for org.el -*- lexical-binding: t -*-
  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. (eval-when-compile (require 'org-macs)) ;For `org-with-gensyms'.
  19. (require 'org)
  20. (require 'org-inlinetask)
  21. (require 'org-refile)
  22. (require 'org-agenda)
  23. ;;; Helpers
  24. (defmacro org-test-with-timezone (tz &rest body)
  25. "Evaluate BODY with TZ environment temporary set to the passed value."
  26. (declare (indent 1))
  27. (org-with-gensyms (tz-saved)
  28. `(let ((,tz-saved (getenv "TZ")))
  29. (unwind-protect
  30. (progn
  31. (setenv "TZ" ,tz)
  32. ,@body)
  33. (setenv "TZ" ,tz-saved)))))
  34. ;;; Comments
  35. (ert-deftest test-org/toggle-comment ()
  36. "Test `org-toggle-comment' specifications."
  37. ;; Simple headline.
  38. (should
  39. (equal "* Test"
  40. (org-test-with-temp-text "* COMMENT Test"
  41. (org-toggle-comment)
  42. (buffer-string))))
  43. (should
  44. (equal "* COMMENT Test"
  45. (org-test-with-temp-text "* Test"
  46. (org-toggle-comment)
  47. (buffer-string))))
  48. ;; Headline with a regular keyword.
  49. (should
  50. (equal "* TODO Test"
  51. (org-test-with-temp-text "* TODO COMMENT Test"
  52. (org-toggle-comment)
  53. (buffer-string))))
  54. (should
  55. (equal "* TODO COMMENT Test"
  56. (org-test-with-temp-text "* TODO Test"
  57. (org-toggle-comment)
  58. (buffer-string))))
  59. ;; Empty headline.
  60. (should
  61. (equal "* "
  62. (org-test-with-temp-text "* COMMENT"
  63. (org-toggle-comment)
  64. (buffer-string))))
  65. (should
  66. (equal "* COMMENT"
  67. (org-test-with-temp-text "* "
  68. (org-toggle-comment)
  69. (buffer-string))))
  70. ;; Headline with a single keyword.
  71. (should
  72. (equal "* TODO "
  73. (org-test-with-temp-text "* TODO COMMENT"
  74. (org-toggle-comment)
  75. (buffer-string))))
  76. (should
  77. (equal "* TODO COMMENT"
  78. (org-test-with-temp-text "* TODO"
  79. (org-toggle-comment)
  80. (buffer-string))))
  81. ;; Headline with a keyword, a priority cookie and contents.
  82. (should
  83. (equal "* TODO [#A] Headline"
  84. (org-test-with-temp-text "* TODO [#A] COMMENT Headline"
  85. (org-toggle-comment)
  86. (buffer-string))))
  87. (should
  88. (equal "* TODO [#A] COMMENT Headline"
  89. (org-test-with-temp-text "* TODO [#A] Headline"
  90. (org-toggle-comment)
  91. (buffer-string)))))
  92. (ert-deftest test-org/comment-dwim ()
  93. "Test `comment-dwim' behaviour in an Org buffer."
  94. ;; No region selected, no comment on current line and line not
  95. ;; empty: insert comment on line above.
  96. (should
  97. (equal "# \nComment"
  98. (org-test-with-temp-text "Comment"
  99. (call-interactively #'org-comment-dwim)
  100. (buffer-string))))
  101. ;; No region selected, no comment on current line and line empty:
  102. ;; insert comment on this line.
  103. (should
  104. (equal "# \nParagraph"
  105. (org-test-with-temp-text "\nParagraph"
  106. (call-interactively #'org-comment-dwim)
  107. (buffer-string))))
  108. ;; No region selected, and a comment on this line: indent it.
  109. (should
  110. (equal "* Headline\n # Comment"
  111. (org-test-with-temp-text "* Headline\n# <point>Comment"
  112. (let ((org-adapt-indentation t))
  113. (call-interactively #'org-comment-dwim))
  114. (buffer-string))))
  115. ;; Also recognize single # at column 0 as comments.
  116. (should
  117. (equal "# Comment"
  118. (org-test-with-temp-text "# Comment"
  119. (call-interactively #'org-comment-dwim)
  120. (buffer-string))))
  121. ;; Region selected and only comments and blank lines within it:
  122. ;; un-comment all commented lines.
  123. (should
  124. (equal "Comment 1\n\nComment 2"
  125. (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
  126. (transient-mark-mode 1)
  127. (push-mark (point) t t)
  128. (goto-char (point-max))
  129. (call-interactively #'org-comment-dwim)
  130. (buffer-string))))
  131. ;; Region selected without comments: comment all lines if
  132. ;; `comment-empty-lines' is non-nil, only non-blank lines otherwise.
  133. (should
  134. (equal "# Comment 1\n\n# Comment 2"
  135. (org-test-with-temp-text "Comment 1\n\nComment 2"
  136. (transient-mark-mode 1)
  137. (push-mark (point) t t)
  138. (goto-char (point-max))
  139. (let ((comment-empty-lines nil))
  140. (call-interactively #'org-comment-dwim))
  141. (buffer-string))))
  142. (should
  143. (equal "# Comment 1\n# \n# Comment 2"
  144. (org-test-with-temp-text "Comment 1\n\nComment 2"
  145. (transient-mark-mode 1)
  146. (push-mark (point) t t)
  147. (goto-char (point-max))
  148. (let ((comment-empty-lines t))
  149. (call-interactively #'org-comment-dwim))
  150. (buffer-string))))
  151. ;; In front of a keyword without region, insert a new comment.
  152. (should
  153. (equal "# \n#+KEYWORD: value"
  154. (org-test-with-temp-text "#+KEYWORD: value"
  155. (call-interactively #'org-comment-dwim)
  156. (buffer-string))))
  157. ;; Comment a heading
  158. (should
  159. (equal "* COMMENT Test"
  160. (org-test-with-temp-text "* Test"
  161. (call-interactively #'org-comment-dwim)
  162. (buffer-string))))
  163. ;; In a source block, use appropriate syntax.
  164. (should
  165. (equal " ;; "
  166. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n<point>\n#+END_SRC"
  167. (let ((org-edit-src-content-indentation 2))
  168. (call-interactively #'org-comment-dwim))
  169. (buffer-substring-no-properties (line-beginning-position)
  170. (point)))))
  171. (should
  172. (equal "#+BEGIN_SRC emacs-lisp\n ;; a\n ;; b\n#+END_SRC"
  173. (org-test-with-temp-text
  174. "#+BEGIN_SRC emacs-lisp\n<point>a\nb\n#+END_SRC"
  175. (transient-mark-mode 1)
  176. (push-mark (point) t t)
  177. (forward-line 2)
  178. (let ((org-edit-src-content-indentation 2))
  179. (call-interactively #'org-comment-dwim))
  180. (buffer-string)))))
  181. ;;; Date and time analysis
  182. (ert-deftest test-org/org-encode-time ()
  183. "Test various ways to call `org-encode-time'"
  184. (org-test-with-timezone "UTC"
  185. ;; list as the sole argument
  186. (should (string-equal
  187. "2022-03-24 23:30:01"
  188. (format-time-string
  189. "%F %T"
  190. (org-encode-time '(1 30 23 24 3 2022 nil -1 nil)))))
  191. ;; SECOND...YEAR
  192. (should (string-equal
  193. "2022-03-24 23:30:02"
  194. (format-time-string
  195. "%F %T"
  196. (org-encode-time 2 30 23 24 3 2022))))
  197. ;; SECOND...YEAR IGNORED DST ZONE
  198. (should (string-equal
  199. "2022-03-24 23:30:03"
  200. (format-time-string
  201. "%F %T"
  202. (org-encode-time 3 30 23 24 3 2022 nil -1 nil))))
  203. ;; function call
  204. (should (string-equal
  205. "2022-03-24 23:30:04"
  206. (format-time-string
  207. "%F %T"
  208. (org-encode-time (apply #'list 4 30 23 '(24 3 2022 nil -1 nil))))))
  209. ;; wrong number of arguments
  210. (if (not (version< emacs-version "27.1"))
  211. (should-error (string-equal
  212. "2022-03-24 23:30:05"
  213. (format-time-string
  214. "%F %T"
  215. (org-encode-time 5 30 23 24 3 2022 nil))))))
  216. ;; daylight saving time
  217. (if (not (version< emacs-version "27.1"))
  218. ;; DST value is not ignored for multiple arguments unlike for `encode-time'
  219. (should (string-equal
  220. "2022-04-01 00:30:06 +0200 CEST"
  221. (format-time-string
  222. "%F %T %z %Z"
  223. (org-encode-time 6 30 23 31 3 2022 nil nil "Europe/Madrid")
  224. "Europe/Madrid")))
  225. (should (string-equal
  226. "2022-03-31 23:30:07 +0200 CEST"
  227. (format-time-string
  228. "%F %T %z %Z"
  229. (org-encode-time 7 30 23 31 3 2022 nil t "Europe/Madrid")
  230. "Europe/Madrid"))))
  231. (org-test-with-timezone "Europe/Madrid"
  232. ;; Standard time is not forced when DST is not specified
  233. (should (string-equal
  234. "2022-03-31 23:30:08"
  235. (format-time-string
  236. "%F %T"
  237. (org-encode-time 8 30 23 31 3 2022))))))
  238. (ert-deftest test-org/org-time-string-to-time ()
  239. "Test `org-time-string-to-time' around DST transition."
  240. (org-test-with-timezone "UTC"
  241. (should (string-equal
  242. "2022-03-31 23:31:00"
  243. (format-time-string
  244. "%F %T"
  245. (org-time-string-to-time "2022-03-31 23:31")))))
  246. (org-test-with-timezone "Europe/Madrid"
  247. (should (string-equal
  248. "2022-03-24 23:32:00 +0100 CET"
  249. (format-time-string
  250. "%F %T %z %Z"
  251. (org-time-string-to-time "2022-03-24 23:32"))))
  252. (should (string-equal
  253. "2022-03-31 23:33:00 +0200 CEST"
  254. (format-time-string
  255. "%F %T %z %Z"
  256. (org-time-string-to-time "2022-03-31 23:33"))))))
  257. (ert-deftest test-org/org-read-date ()
  258. "Test `org-read-date' specifications."
  259. (defvar org-time-was-given) ; dynamically scoped parameter
  260. ;; Parse ISO date with abbreviated year and month.
  261. (should (equal "2012-03-29 16:40"
  262. (let ((org-time-was-given t))
  263. (org-read-date t nil "12-3-29 16:40"))))
  264. ;; Parse Europeans dates.
  265. (should (equal "2012-03-29 16:40"
  266. (let ((org-time-was-given t))
  267. (org-read-date t nil "29.03.2012 16:40"))))
  268. ;; Parse Europeans dates without year.
  269. (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
  270. (let ((org-time-was-given t))
  271. (org-read-date t nil "29.03. 16:40"))))
  272. ;; Relative date applied to current time if there is single
  273. ;; plus/minus, or to default date when there are two of them.
  274. (should
  275. (equal
  276. "2015-03-04"
  277. (org-test-at-time "2014-03-04"
  278. (org-read-date
  279. t nil "+1y" nil
  280. (org-time-string-to-time "2012-03-29")))))
  281. (should
  282. (equal
  283. "2013-03-29"
  284. (org-test-at-time "2014-03-04"
  285. (org-read-date
  286. t nil "++1y" nil
  287. (org-time-string-to-time "2012-03-29")))))
  288. ;; When `org-read-date-prefer-future' is non-nil, prefer future
  289. ;; dates (relatively to now) when incomplete. Otherwise, use
  290. ;; default date.
  291. (should
  292. (equal
  293. "2014-04-01"
  294. (org-test-at-time "2014-03-04"
  295. (let ((org-read-date-prefer-future t))
  296. (org-read-date t nil "1")))))
  297. (should
  298. (equal
  299. "2013-03-04"
  300. (org-test-at-time "2012-03-29"
  301. (let ((org-read-date-prefer-future t))
  302. (org-read-date t nil "3-4")))))
  303. (should
  304. (equal
  305. "2012-03-04"
  306. (org-test-at-time "2012-03-29"
  307. (let ((org-read-date-prefer-future nil))
  308. (org-read-date t nil "3-4")))))
  309. ;; When set to `org-read-date-prefer-future' is set to `time', read
  310. ;; day is moved to tomorrow if specified hour is before current
  311. ;; time. However, it only happens in no other part of the date is
  312. ;; specified.
  313. (should
  314. (equal
  315. "2012-03-30"
  316. (org-test-at-time "2012-03-29 16:40"
  317. (let ((org-read-date-prefer-future 'time))
  318. (org-read-date t nil "00:40" nil)))))
  319. (should-not
  320. (equal
  321. "2012-03-30"
  322. (org-test-at-time "2012-03-29 16:40"
  323. (let ((org-read-date-prefer-future 'time))
  324. (org-read-date t nil "29 00:40" nil)))))
  325. ;; Caveat: `org-read-date-prefer-future' always refers to current
  326. ;; time, not default time, when they differ.
  327. (should
  328. (equal
  329. "2014-04-01"
  330. (org-test-at-time "2014-03-04"
  331. (let ((org-read-date-prefer-future t))
  332. (org-read-date
  333. t nil "1" nil
  334. (org-time-string-to-time "2012-03-29"))))))
  335. (should
  336. (equal
  337. "2014-03-25"
  338. (org-test-at-time "2014-03-04"
  339. (let ((org-read-date-prefer-future t))
  340. (org-read-date
  341. t nil "25" nil
  342. (org-time-string-to-time "2012-03-29")))))))
  343. (ert-deftest test-org/org-parse-time-string ()
  344. "Test `org-parse-time-string'."
  345. (should (equal (org-parse-time-string "2012-03-29 16:40")
  346. '(0 40 16 29 3 2012 nil -1 nil)))
  347. (should (equal (org-parse-time-string "[2012-03-29 16:40]")
  348. '(0 40 16 29 3 2012 nil -1 nil)))
  349. (should (equal (org-parse-time-string "<2012-03-29 16:40>")
  350. '(0 40 16 29 3 2012 nil -1 nil)))
  351. (should (equal (org-parse-time-string "<2012-03-29>")
  352. '(0 0 0 29 3 2012 nil -1 nil)))
  353. (should (equal (org-parse-time-string "<2012-03-29>" t)
  354. '(0 nil nil 29 3 2012 nil -1 nil))))
  355. (ert-deftest test-org/closest-date ()
  356. "Test `org-closest-date' specifications."
  357. (require 'calendar)
  358. ;; Time stamps without a repeater are returned unchanged.
  359. (should
  360. (equal
  361. '(3 29 2012)
  362. (calendar-gregorian-from-absolute
  363. (org-closest-date "<2012-03-29>" "<2014-03-04>" nil))))
  364. ;; Time stamps with a null repeater are returned unchanged.
  365. (should
  366. (equal
  367. '(3 29 2012)
  368. (calendar-gregorian-from-absolute
  369. (org-closest-date "<2012-03-29 +0d>" "<2014-03-04>" nil))))
  370. ;; if PREFER is set to `past' always return a date before, or equal
  371. ;; to CURRENT.
  372. (should
  373. (equal
  374. '(3 1 2014)
  375. (calendar-gregorian-from-absolute
  376. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'past))))
  377. (should
  378. (equal
  379. '(3 4 2014)
  380. (calendar-gregorian-from-absolute
  381. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'past))))
  382. ;; if PREFER is set to `future' always return a date before, or equal
  383. ;; to CURRENT.
  384. (should
  385. (equal
  386. '(3 29 2014)
  387. (calendar-gregorian-from-absolute
  388. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'future))))
  389. (should
  390. (equal
  391. '(3 4 2014)
  392. (calendar-gregorian-from-absolute
  393. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'future))))
  394. ;; If PREFER is neither `past' nor `future', select closest date.
  395. (should
  396. (equal
  397. '(3 1 2014)
  398. (calendar-gregorian-from-absolute
  399. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" nil))))
  400. (should
  401. (equal
  402. '(5 4 2014)
  403. (calendar-gregorian-from-absolute
  404. (org-closest-date "<2012-03-04 +1m>" "<2014-04-28>" nil))))
  405. ;; Test "day" repeater.
  406. (should
  407. (equal '(3 8 2014)
  408. (calendar-gregorian-from-absolute
  409. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'past))))
  410. (should
  411. (equal '(3 10 2014)
  412. (calendar-gregorian-from-absolute
  413. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'future))))
  414. ;; Test "month" repeater.
  415. (should
  416. (equal '(1 5 2015)
  417. (calendar-gregorian-from-absolute
  418. (org-closest-date "<2014-03-05 +2m>" "<2015-02-04>" 'past))))
  419. (should
  420. (equal '(3 29 2014)
  421. (calendar-gregorian-from-absolute
  422. (org-closest-date "<2012-03-29 +2m>" "<2014-03-04>" 'future))))
  423. ;; Test "year" repeater.
  424. (should
  425. (equal '(3 5 2014)
  426. (calendar-gregorian-from-absolute
  427. (org-closest-date "<2014-03-05 +2y>" "<2015-02-04>" 'past))))
  428. (should
  429. (equal '(3 29 2014)
  430. (calendar-gregorian-from-absolute
  431. (org-closest-date "<2012-03-29 +2y>" "<2014-03-04>" 'future)))))
  432. (ert-deftest test-org/deadline-close-p ()
  433. "Test `org-deadline-close-p' specifications."
  434. (org-test-at-time "2016-06-03 Fri 01:43"
  435. ;; Timestamps are close if they are within `ndays' of lead time.
  436. (org-test-with-temp-text "* Heading"
  437. (should (org-deadline-close-p "2016-06-03 Fri" 0))
  438. (should (org-deadline-close-p "2016-06-02 Thu" 0))
  439. (should-not (org-deadline-close-p "2016-06-04 Sat" 0))
  440. (should (org-deadline-close-p "2016-06-04 Sat" 1))
  441. (should (org-deadline-close-p "2016-06-03 Fri 12:00" 0)))
  442. ;; Read `ndays' from timestamp if argument not given.
  443. (org-test-with-temp-text "* H"
  444. (should (org-deadline-close-p "2016-06-04 Sat -1d"))
  445. (should-not (org-deadline-close-p "2016-06-04 Sat -0d"))
  446. (should (org-deadline-close-p "2016-06-10 Fri -1w"))
  447. (should-not (org-deadline-close-p "2016-06-11 Sat -1w")))
  448. ;; Prefer `ndays' argument over lead time in timestamp.
  449. (org-test-with-temp-text "* H"
  450. (should (org-deadline-close-p "2016-06-04 Sat -0d" 1))
  451. (should-not (org-deadline-close-p "2016-06-04 Sat -0d" 0)))
  452. ;; Completed tasks are never close.
  453. (let ((org-todo-keywords '(("TODO" "|" "DONE"))))
  454. (org-test-with-temp-text "* TODO Heading"
  455. (should (org-deadline-close-p "2016-06-03")))
  456. (org-test-with-temp-text "* DONE Heading"
  457. (should-not (org-deadline-close-p "2016-06-03"))))))
  458. ;;; Drawers
  459. (ert-deftest test-org/at-property-p ()
  460. "Test `org-at-property-p' specifications."
  461. (should
  462. (equal 't
  463. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:PROP: t\n:END:\n"
  464. (org-at-property-p))))
  465. (should
  466. (equal 't
  467. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n:END:\n"
  468. (org-at-property-p)))))
  469. (ert-deftest test-org/at-property-drawer-p ()
  470. "Test `org-at-property-drawer-p' specifications."
  471. (should
  472. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:PROP: t\n:END:\n"
  473. (org-at-property-drawer-p)))
  474. (should
  475. (org-test-with-temp-text ":PROPERTIES:\n:PROP: t\n:END:\n"
  476. (org-at-property-drawer-p)))
  477. ;; The function only returns t if point is at the first line of
  478. ;; a property block.
  479. (should-not
  480. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n:END:\n"
  481. (org-at-property-drawer-p)))
  482. ;; The function ignores incomplete drawers.
  483. (should-not
  484. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n"
  485. (org-at-property-drawer-p)))
  486. ;; tab separating the value.
  487. (should
  488. (org-test-with-temp-text ":PROPERTIES:\n:PROP: t\n:END:\n"
  489. (org-at-property-drawer-p))))
  490. (ert-deftest test-org/get-property-block ()
  491. "Test `org-get-property-block' specifications."
  492. (should
  493. (equal '(14 . 14)
  494. (org-test-with-temp-text ":PROPERTIES:\n:END:\n* H\n"
  495. (org-get-property-block))))
  496. (should
  497. (equal '(14 . 14)
  498. (org-test-with-temp-text ":PROPERTIES:\n:END:\n"
  499. (org-get-property-block))))
  500. ;; Comments above a document property block is ok.
  501. (should
  502. (equal '(18 . 18)
  503. (org-test-with-temp-text "# C\n:PROPERTIES:\n:END:\n"
  504. (org-get-property-block))))
  505. ;; Keywords above a document property block is ok.
  506. (should
  507. (equal '(22 . 22)
  508. (org-test-with-temp-text "# C\n# C\n:PROPERTIES:\n:END:\n"
  509. (org-get-property-block))))
  510. ;; Comments and keywords are allowed before a document property block.
  511. (should
  512. (equal '(18 . 27)
  513. (org-test-with-temp-text "# C\n:PROPERTIES:\n:KEY: V:\n:END:\n"
  514. (org-get-property-block))))
  515. ;; A document property block will not be valid if there are lines
  516. ;; with whitespace above it
  517. (should-not
  518. (org-test-with-temp-text "\n:PROPERTIES:\n:END:\n"
  519. (org-get-property-block)))
  520. (should
  521. (equal '(18 . 18)
  522. (org-test-with-temp-text "* H\n:PROPERTIES:\n:END:\n<point>"
  523. (org-get-property-block))))
  524. (should
  525. (equal "* H\n:PROPERTIES:\n:END:\n"
  526. (org-test-with-temp-text "* H"
  527. (let ((org-adapt-indentation nil))
  528. (org-get-property-block nil 'force))
  529. (buffer-string))))
  530. (should
  531. (equal ":PROPERTIES:\n:END:\n"
  532. (org-test-with-temp-text ""
  533. (org-get-property-block nil 'force)
  534. (buffer-string))))
  535. (should
  536. (equal "* H1\n :PROPERTIES:\n :END:\n* H2"
  537. (org-test-with-temp-text "* H1\n* H2"
  538. (let ((org-adapt-indentation t))
  539. (org-get-property-block nil 'force))
  540. (buffer-string)))))
  541. (ert-deftest test-org/insert-property-drawer ()
  542. "Test `org-insert-property-drawer' specifications."
  543. ;; Insert drawer in empty buffer
  544. (should
  545. (equal ":PROPERTIES:\n:END:\n"
  546. (org-test-with-temp-text ""
  547. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  548. (buffer-string))))
  549. ;; Insert drawer in document header with existing comment and
  550. ;; keyword.
  551. (should
  552. (equal "# C\n:PROPERTIES:\n:END:\n#+TITLE: T"
  553. (org-test-with-temp-text "# C\n#+TITLE: T"
  554. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  555. (buffer-string))))
  556. ;; Insert drawer in document header with existing keyword.
  557. (should
  558. (equal ":PROPERTIES:\n:END:\n#+TITLE: T"
  559. (org-test-with-temp-text "#+TITLE: T"
  560. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  561. (buffer-string))))
  562. (should
  563. (equal ":PROPERTIES:\n:END:"
  564. (org-test-with-temp-text ":PROPERTIES:\n:END:"
  565. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  566. (buffer-string))))
  567. ;; Insert drawer in document header with one existing heading in buffer.
  568. (should
  569. (equal ":PROPERTIES:\n:END:\n\n* T\n"
  570. (org-test-with-temp-text "\n* T\n"
  571. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  572. (buffer-string))))
  573. ;; Insert drawer right after headline if there is no planning line,
  574. ;; or after it otherwise.
  575. (should
  576. (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
  577. (org-test-with-temp-text "* H\nParagraph<point>"
  578. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  579. (buffer-string))))
  580. (should
  581. (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
  582. (org-test-with-temp-text
  583. "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
  584. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  585. (buffer-string))))
  586. ;; Indent inserted drawer.
  587. (should
  588. (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
  589. (org-test-with-temp-text "* H\nParagraph<point>"
  590. (let ((org-adapt-indentation t)) (org-insert-property-drawer))
  591. (buffer-string))))
  592. ;; Handle insertion at eob.
  593. (should
  594. (equal "* H\n:PROPERTIES:\n:END:\n"
  595. (org-test-with-temp-text "* H"
  596. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  597. (buffer-string))))
  598. ;; Skip inlinetasks before point.
  599. (when (featurep 'org-inlinetask)
  600. (should
  601. (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
  602. (org-test-with-temp-text
  603. "* H\n*************** I\n*************** END\nP<point>"
  604. (let ((org-adapt-indentation nil)
  605. (org-inlinetask-min-level 15))
  606. (org-insert-property-drawer))
  607. (buffer-string)))))
  608. ;; Correctly set drawer in an inlinetask.
  609. (when (featurep 'org-inlinetask)
  610. (should
  611. (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
  612. (org-test-with-temp-text
  613. "* H\n*************** I\nP<point>\n*************** END"
  614. (let ((org-adapt-indentation nil)
  615. (org-inlinetask-min-level 15))
  616. (org-insert-property-drawer))
  617. (buffer-string))))))
  618. ;;; Filling
  619. (ert-deftest test-org/fill-element ()
  620. "Test `org-fill-element' specifications."
  621. ;; At an Org table, align it.
  622. (should
  623. (equal "| a |\n"
  624. (org-test-with-temp-text "|a|"
  625. (org-fill-element)
  626. (buffer-string))))
  627. (should
  628. (equal "#+name: table\n| a |\n"
  629. (org-test-with-temp-text "#+name: table\n| a |\n"
  630. (org-fill-element)
  631. (buffer-string))))
  632. ;; At a paragraph, preserve line breaks.
  633. (org-test-with-temp-text "some \\\\\nlong\ntext"
  634. (let ((fill-column 20))
  635. (org-fill-element)
  636. (should (equal (buffer-string) "some \\\\\nlong text"))))
  637. ;; Correctly fill a paragraph when point is at its very end.
  638. (should
  639. (equal "A B"
  640. (org-test-with-temp-text "A\nB"
  641. (let ((fill-column 20))
  642. (goto-char (point-max))
  643. (org-fill-element)
  644. (buffer-string)))))
  645. ;; Correctly fill the last paragraph of a greater element.
  646. (should
  647. (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
  648. (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
  649. (let ((fill-column 8))
  650. (forward-line)
  651. (end-of-line)
  652. (org-fill-element)
  653. (buffer-string)))))
  654. ;; Correctly fill an element in a narrowed buffer.
  655. (should
  656. (equal "01234\n6"
  657. (org-test-with-temp-text "01234 6789"
  658. (let ((fill-column 5))
  659. (narrow-to-region 1 8)
  660. (org-fill-element)
  661. (buffer-string)))))
  662. ;; Handle `adaptive-fill-regexp' in paragraphs.
  663. (should
  664. (equal "> a b"
  665. (org-test-with-temp-text "> a\n> b"
  666. (let ((fill-column 5)
  667. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  668. (org-fill-element)
  669. (buffer-string)))))
  670. ;; Special case: Fill first paragraph when point is at an item or
  671. ;; a plain-list or a footnote reference.
  672. (should
  673. (equal "- A B"
  674. (org-test-with-temp-text "- A\n B"
  675. (let ((fill-column 20))
  676. (org-fill-element)
  677. (buffer-string)))))
  678. (should
  679. (equal "[fn:1] A B"
  680. (org-test-with-temp-text "[fn:1] A\nB"
  681. (let ((fill-column 20))
  682. (org-fill-element)
  683. (buffer-string)))))
  684. (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
  685. (let ((fill-column 20))
  686. (org-fill-element)
  687. (should (equal (buffer-string)
  688. "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
  689. ;; Fill contents of `comment-block' elements.
  690. (should
  691. (equal
  692. (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
  693. (let ((fill-column 20))
  694. (forward-line)
  695. (org-fill-element)
  696. (buffer-string)))
  697. "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
  698. ;; Fill `comment' elements.
  699. (should
  700. (equal " # A B"
  701. (org-test-with-temp-text " # A\n # B"
  702. (let ((fill-column 20))
  703. (org-fill-element)
  704. (buffer-string)))))
  705. ;; Do not mix consecutive comments when filling one of them.
  706. (should
  707. (equal "# A B\n\n# C"
  708. (org-test-with-temp-text "# A\n# B\n\n# C"
  709. (let ((fill-column 20))
  710. (org-fill-element)
  711. (buffer-string)))))
  712. ;; Use commented empty lines as separators when filling comments.
  713. (should
  714. (equal "# A B\n#\n# C"
  715. (org-test-with-temp-text "# A\n# B\n#\n# C"
  716. (let ((fill-column 20))
  717. (org-fill-element)
  718. (buffer-string)))))
  719. ;; Handle `adaptive-fill-regexp' in comments.
  720. (should
  721. (equal "# > a b"
  722. (org-test-with-temp-text "# > a\n# > b"
  723. (let ((fill-column 20)
  724. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  725. (org-fill-element)
  726. (buffer-string)))))
  727. ;; Do nothing at affiliated keywords.
  728. (should
  729. (equal "#+NAME: para\nSome\ntext."
  730. (org-test-with-temp-text "#+NAME: para\nSome\ntext."
  731. (let ((fill-column 20))
  732. (org-fill-element)
  733. (buffer-string)))))
  734. ;; Do not move point after table when filling a table.
  735. (should-not
  736. (org-test-with-temp-text "| a | b |\n| c | d |\n"
  737. (forward-char)
  738. (org-fill-element)
  739. (eobp)))
  740. ;; Do not fill "n" macro, with or without arguments, followed by
  741. ;; a dot or a closing parenthesis since it could be confused with
  742. ;; a numbered bullet.
  743. (should-not
  744. (equal "123456789\n{{{n}}}."
  745. (org-test-with-temp-text "123456789 {{{n}}}."
  746. (let ((fill-column 10))
  747. (org-fill-element)
  748. (buffer-string)))))
  749. (should-not
  750. (equal "123456789\n{{{n}}}\)"
  751. (org-test-with-temp-text "123456789 {{{n}}}\)"
  752. (let ((fill-column 10))
  753. (org-fill-element)
  754. (buffer-string)))))
  755. (should-not
  756. (equal "123456789\n{{{n()}}}."
  757. (org-test-with-temp-text "123456789 {{{n()}}}."
  758. (let ((fill-column 10))
  759. (org-fill-element)
  760. (buffer-string)))))
  761. (should-not
  762. (equal "123456789\n{{{n(counter)}}}."
  763. (org-test-with-temp-text "123456789 {{{n(counter)}}}."
  764. (let ((fill-column 10))
  765. (org-fill-element)
  766. (buffer-string))))))
  767. (ert-deftest test-org/fill-paragraph ()
  768. "Test `org-fill-paragraph' specifications."
  769. ;; Regular test.
  770. (should
  771. (equal "012345678\n9"
  772. (org-test-with-temp-text "012345678 9"
  773. (let ((fill-column 10))
  774. (org-fill-paragraph)
  775. (buffer-string)))))
  776. ;; Fill paragraph even at end of buffer.
  777. (should
  778. (equal "012345678\n9\n"
  779. (org-test-with-temp-text "012345678 9\n<point>"
  780. (let ((fill-column 10))
  781. (org-fill-paragraph)
  782. (buffer-string)))))
  783. ;; Between two paragraphs, fill the next one.
  784. (should
  785. (equal "012345678 9\n\n012345678\n9"
  786. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  787. (let ((fill-column 10))
  788. (org-fill-paragraph)
  789. (buffer-string)))))
  790. (should
  791. (equal "012345678\n9\n\n012345678 9"
  792. (org-test-with-temp-text "012345678 9<point>\n\n012345678 9"
  793. (let ((fill-column 10))
  794. (org-fill-paragraph)
  795. (buffer-string)))))
  796. ;; Fill paragraph in a comment block.
  797. (should
  798. (equal "#+begin_comment\n012345678\n9\n#+end_comment"
  799. (org-test-with-temp-text
  800. "#+begin_comment\n<point>012345678 9\n#+end_comment"
  801. (let ((fill-column 10))
  802. (org-fill-paragraph)
  803. (buffer-string)))))
  804. ;; When a region is selected, fill every paragraph in the region.
  805. (should
  806. (equal "012345678\n9\n\n012345678\n9"
  807. (org-test-with-temp-text "012345678 9\n\n012345678 9"
  808. (let ((fill-column 10))
  809. (transient-mark-mode 1)
  810. (push-mark (point-min) t t)
  811. (goto-char (point-max))
  812. (call-interactively #'org-fill-paragraph)
  813. (buffer-string)))))
  814. (should
  815. (equal "012345678\n9\n\n012345678 9"
  816. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  817. (let ((fill-column 10))
  818. (transient-mark-mode 1)
  819. (push-mark (point) t t)
  820. (goto-char (point-min))
  821. (call-interactively #'org-fill-paragraph)
  822. (buffer-string)))))
  823. (should
  824. (equal "012345678 9\n\n012345678\n9"
  825. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  826. (let ((fill-column 10))
  827. (transient-mark-mode 1)
  828. (push-mark (point) t t)
  829. (goto-char (point-max))
  830. (call-interactively #'org-fill-paragraph)
  831. (buffer-string)))))
  832. ;; Fill every list item in a region
  833. (should
  834. (equal "\n- 2345678\n 9\n- 2345678\n 9"
  835. (org-test-with-temp-text "\n- 2345678 9\n- 2345678 9"
  836. (let ((fill-column 10))
  837. (transient-mark-mode 1)
  838. (push-mark (point-min) t t)
  839. (goto-char (point-max))
  840. (call-interactively #'org-fill-paragraph)
  841. (buffer-string)))))
  842. (should
  843. (equal "\n- 2345678\n 9\n- 2345678"
  844. (org-test-with-temp-text "\n- 2345678 9\n- 2345678"
  845. (let ((fill-column 10))
  846. (transient-mark-mode 1)
  847. (push-mark (point-min) t t)
  848. (goto-char (point-max))
  849. (call-interactively #'org-fill-paragraph)
  850. (buffer-string))))))
  851. (ert-deftest test-org/fill-region ()
  852. "Test `fill-region' behaviour."
  853. ;; fill-region should fill every item of a list
  854. (should
  855. (equal "\n- 2345678\n 9\n- 2345678\n 9"
  856. (org-test-with-temp-text "\n- 2345678 9\n- 2345678 9"
  857. (let ((fill-column 10))
  858. (transient-mark-mode 1)
  859. (push-mark (point-min) t t)
  860. (goto-char (point-max))
  861. (call-interactively #'fill-region)
  862. (buffer-string)))))
  863. (should
  864. (equal "\n- 1 2\n- 1 2"
  865. (org-test-with-temp-text "\n- 1\n 2\n- 1\n 2"
  866. (let ((fill-column 10))
  867. (transient-mark-mode 1)
  868. (push-mark (point-min) t t)
  869. (goto-char (point-max))
  870. (call-interactively #'fill-region)
  871. (buffer-string))))) )
  872. (ert-deftest test-org/auto-fill-function ()
  873. "Test auto-filling features."
  874. ;; Auto fill paragraph.
  875. (should
  876. (equal "12345\n7890"
  877. (org-test-with-temp-text "12345 7890"
  878. (let ((fill-column 5))
  879. (end-of-line)
  880. (org-auto-fill-function)
  881. (buffer-string)))))
  882. ;; Auto fill first paragraph in an item.
  883. (should
  884. (equal "- 12345\n 7890"
  885. (org-test-with-temp-text "- 12345 7890"
  886. (let ((fill-column 7))
  887. (end-of-line)
  888. (org-auto-fill-function)
  889. (buffer-string)))))
  890. ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
  891. (should
  892. (equal "> 12345\n 7890"
  893. (org-test-with-temp-text "> 12345 7890"
  894. (let ((fill-column 10)
  895. (adaptive-fill-regexp "[ \t]*>+[ \t]*")
  896. (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
  897. (end-of-line)
  898. (org-auto-fill-function)
  899. (buffer-string)))))
  900. (should
  901. (equal "> 12345\n> 12345\n> 7890"
  902. (org-test-with-temp-text "> 12345\n> 12345 7890"
  903. (let ((fill-column 10)
  904. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  905. (goto-char (point-max))
  906. (org-auto-fill-function)
  907. (buffer-string)))))
  908. (should-not
  909. (equal " 12345\n *12345\n *12345"
  910. (org-test-with-temp-text " 12345\n *12345 12345"
  911. (let ((fill-column 10)
  912. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  913. (goto-char (point-max))
  914. (org-auto-fill-function)
  915. (buffer-string)))))
  916. ;; Auto fill comments.
  917. (should
  918. (equal " # 12345\n # 7890"
  919. (org-test-with-temp-text " # 12345 7890"
  920. (let ((fill-column 10))
  921. (end-of-line)
  922. (org-auto-fill-function)
  923. (buffer-string)))))
  924. ;; A hash within a line isn't a comment.
  925. (should-not
  926. (equal "12345 # 7890\n# 1"
  927. (org-test-with-temp-text "12345 # 7890 1"
  928. (let ((fill-column 12))
  929. (end-of-line)
  930. (org-auto-fill-function)
  931. (buffer-string)))))
  932. ;; Correctly interpret empty prefix.
  933. (should-not
  934. (equal "# a\n# b\nRegular\n# paragraph"
  935. (org-test-with-temp-text "# a\n# b\nRegular paragraph"
  936. (let ((fill-column 12))
  937. (end-of-line 3)
  938. (org-auto-fill-function)
  939. (buffer-string)))))
  940. ;; Comment block: auto fill contents.
  941. (should
  942. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  943. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  944. (let ((fill-column 5))
  945. (forward-line)
  946. (end-of-line)
  947. (org-auto-fill-function)
  948. (buffer-string)))))
  949. (should
  950. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  951. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  952. (let ((fill-column 5))
  953. (forward-line)
  954. (end-of-line)
  955. (org-auto-fill-function)
  956. (buffer-string)))))
  957. ;; Do not fill if a new item could be created.
  958. (should-not
  959. (equal "12345\n- 90"
  960. (org-test-with-temp-text "12345 - 90"
  961. (let ((fill-column 5))
  962. (end-of-line)
  963. (org-auto-fill-function)
  964. (buffer-string)))))
  965. ;; Do not fill if a line break could be introduced.
  966. (should-not
  967. (equal "123\\\\\n7890"
  968. (org-test-with-temp-text "123\\\\ 7890"
  969. (let ((fill-column 6))
  970. (end-of-line)
  971. (org-auto-fill-function)
  972. (buffer-string)))))
  973. ;; Do not fill affiliated keywords.
  974. (should-not
  975. (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
  976. (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
  977. (let ((fill-column 20))
  978. (end-of-line)
  979. (org-auto-fill-function)
  980. (buffer-string))))))
  981. ;;; Indentation
  982. (ert-deftest test-org/indent-line ()
  983. "Test `org-indent-line' specifications."
  984. ;; Do not indent diary sexps, footnote definitions or headlines.
  985. (should
  986. (zerop
  987. (org-test-with-temp-text "%%(org-calendar-holiday)"
  988. (org-indent-line)
  989. (org-get-indentation))))
  990. (should
  991. (zerop
  992. (org-test-with-temp-text "[fn:1] fn"
  993. (let ((org-adapt-indentation t)) (org-indent-line))
  994. (org-get-indentation))))
  995. (should
  996. (zerop
  997. (org-test-with-temp-text "* H"
  998. (org-indent-line)
  999. (org-get-indentation))))
  1000. ;; Do not indent before first headline.
  1001. (should
  1002. (zerop
  1003. (org-test-with-temp-text ""
  1004. (org-indent-line)
  1005. (org-get-indentation))))
  1006. ;; Indent according to headline level otherwise, unless
  1007. ;; `org-adapt-indentation' is nil.
  1008. (should
  1009. (= 2
  1010. (org-test-with-temp-text "* H\n<point>A"
  1011. (let ((org-adapt-indentation t)) (org-indent-line))
  1012. (org-get-indentation))))
  1013. (should
  1014. (= 2
  1015. (org-test-with-temp-text "* H\n<point>\nA"
  1016. (let ((org-adapt-indentation t)) (org-indent-line))
  1017. (org-get-indentation))))
  1018. (should
  1019. (zerop
  1020. (org-test-with-temp-text "* H\n<point>A"
  1021. (let ((org-adapt-indentation nil)) (org-indent-line))
  1022. (org-get-indentation))))
  1023. ;; Indenting preserves point position.
  1024. (should
  1025. (org-test-with-temp-text "* H\nA<point>B"
  1026. (let ((org-adapt-indentation t)) (org-indent-line))
  1027. (looking-at "B")))
  1028. ;; Do not change indentation at an item or a LaTeX environment.
  1029. (should
  1030. (= 1
  1031. (org-test-with-temp-text "* H\n<point> - A"
  1032. (let ((org-adapt-indentation t)) (org-indent-line))
  1033. (org-get-indentation))))
  1034. (should
  1035. (= 1
  1036. (org-test-with-temp-text
  1037. "\\begin{equation}\n <point>1+1=2\n\\end{equation}"
  1038. (org-indent-line)
  1039. (org-get-indentation))))
  1040. ;; On blank lines at the end of a list, indent like last element
  1041. ;; within it if the line is still in the list. If the last element
  1042. ;; is an item, indent like its contents. Otherwise, indent like the
  1043. ;; whole list.
  1044. (should
  1045. (= 4
  1046. (org-test-with-temp-text "* H\n- A\n - AA\n<point>"
  1047. (let ((org-adapt-indentation t)) (org-indent-line))
  1048. (org-get-indentation))))
  1049. (should
  1050. (= 4
  1051. (org-test-with-temp-text "* H\n- A\n -\n\n<point>"
  1052. (let ((org-adapt-indentation t)) (org-indent-line))
  1053. (org-get-indentation))))
  1054. (should
  1055. (zerop
  1056. (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n<point>"
  1057. (let ((org-adapt-indentation t)) (org-indent-line))
  1058. (org-get-indentation))))
  1059. (should
  1060. (= 4
  1061. (org-test-with-temp-text "* H\n- A\n - \n<point>"
  1062. (let ((org-adapt-indentation t)) (org-indent-line))
  1063. (org-get-indentation))))
  1064. (should
  1065. (= 4
  1066. (org-test-with-temp-text
  1067. "* H\n - \n #+BEGIN_SRC emacs-lisp\n t\n #+END_SRC\n<point>"
  1068. (let ((org-adapt-indentation t)) (org-indent-line))
  1069. (org-get-indentation))))
  1070. (should
  1071. (= 2
  1072. (org-test-with-temp-text "- A\n B\n\n<point>"
  1073. (let ((org-adapt-indentation nil)) (org-indent-line))
  1074. (org-get-indentation))))
  1075. (should
  1076. (= 2
  1077. (org-test-with-temp-text
  1078. "- A\n \begin{cases} 1 + 1\n \end{cases}\n\n<point>"
  1079. (let ((org-adapt-indentation nil)) (org-indent-line))
  1080. (org-get-indentation))))
  1081. ;; Likewise, on a blank line at the end of a footnote definition,
  1082. ;; indent at column 0 if line belongs to the definition. Otherwise,
  1083. ;; indent like the definition itself.
  1084. (should
  1085. (zerop
  1086. (org-test-with-temp-text "* H\n[fn:1] Definition\n<point>"
  1087. (let ((org-adapt-indentation t)) (org-indent-line))
  1088. (org-get-indentation))))
  1089. (should
  1090. (zerop
  1091. (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n<point>"
  1092. (let ((org-adapt-indentation t)) (org-indent-line))
  1093. (org-get-indentation))))
  1094. ;; After the end of the contents of a greater element, indent like
  1095. ;; the beginning of the element.
  1096. (should
  1097. (= 1
  1098. (org-test-with-temp-text
  1099. " #+BEGIN_CENTER\n Contents\n<point>#+END_CENTER"
  1100. (org-indent-line)
  1101. (org-get-indentation))))
  1102. ;; On blank lines after a paragraph, indent like its last non-empty
  1103. ;; line.
  1104. (should
  1105. (= 1
  1106. (org-test-with-temp-text " Paragraph\n\n<point>"
  1107. (org-indent-line)
  1108. (org-get-indentation))))
  1109. ;; At the first line of an element, indent like previous element's
  1110. ;; first line, ignoring footnotes definitions and inline tasks, or
  1111. ;; according to parent.
  1112. (let ((org-adapt-indentation t))
  1113. (should
  1114. (= 2
  1115. (org-test-with-temp-text "A\n\n B\n\nC<point>"
  1116. (org-indent-line)
  1117. (org-get-indentation))))
  1118. (should
  1119. (= 1
  1120. (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC<point>"
  1121. (org-indent-line)
  1122. (org-get-indentation))))
  1123. (should
  1124. (= 1
  1125. (org-test-with-temp-text
  1126. " #+BEGIN_CENTER\n<point> Contents\n#+END_CENTER"
  1127. (org-indent-line)
  1128. (org-get-indentation)))))
  1129. ;; Within code part of a source block, use language major mode if
  1130. ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
  1131. ;; according to line above.
  1132. (should
  1133. (= 6
  1134. (org-test-with-temp-text
  1135. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  1136. (let ((org-src-tab-acts-natively t)
  1137. (org-edit-src-content-indentation 0))
  1138. (org-indent-line))
  1139. (org-get-indentation))))
  1140. (should
  1141. (= 1
  1142. (org-test-with-temp-text
  1143. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  1144. (let ((org-src-tab-acts-natively nil)
  1145. (org-edit-src-content-indentation 0))
  1146. (org-indent-line))
  1147. (org-get-indentation))))
  1148. ;; Otherwise, indent like the first non-blank line above.
  1149. (should
  1150. (zerop
  1151. (org-test-with-temp-text
  1152. "#+BEGIN_CENTER\nline1\n\n<point> line2\n#+END_CENTER"
  1153. (org-indent-line)
  1154. (org-get-indentation))))
  1155. ;; Align node properties according to `org-property-format'. Handle
  1156. ;; nicely empty values.
  1157. (should
  1158. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1159. (org-test-with-temp-text
  1160. "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
  1161. (let ((org-property-format "%-10s %s")) (org-indent-line))
  1162. (buffer-string))))
  1163. (should
  1164. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1165. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
  1166. (let ((org-property-format "%-10s %s")) (org-indent-line))
  1167. (buffer-string)))))
  1168. (ert-deftest test-org/indent-region ()
  1169. "Test `org-indent-region' specifications."
  1170. ;; Indent paragraph.
  1171. (let ((org-adapt-indentation t))
  1172. (should
  1173. (equal "A\nB\nC"
  1174. (org-test-with-temp-text " A\nB\n C"
  1175. (org-indent-region (point-min) (point-max))
  1176. (buffer-string)))))
  1177. ;; Indent greater elements along with their contents.
  1178. (should
  1179. (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
  1180. (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
  1181. (org-indent-region (point-min) (point-max))
  1182. (buffer-string))))
  1183. ;; Ignore contents of verse blocks. Only indent block delimiters.
  1184. (should
  1185. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1186. (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1187. (org-indent-region (point-min) (point-max))
  1188. (buffer-string))))
  1189. (let ((org-adapt-indentation t))
  1190. (should
  1191. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1192. (org-test-with-temp-text " #+BEGIN_VERSE\n A\n B\n #+END_VERSE"
  1193. (org-indent-region (point-min) (point-max))
  1194. (buffer-string)))))
  1195. ;; Indent example blocks as a single block, unless indentation
  1196. ;; should be preserved. In this case only indent the block markers.
  1197. (should
  1198. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1199. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1200. (org-indent-region (point-min) (point-max))
  1201. (buffer-string))))
  1202. (let ((org-adapt-indentation t))
  1203. (should
  1204. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1205. (org-test-with-temp-text " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1206. (org-indent-region (point-min) (point-max))
  1207. (buffer-string))))
  1208. (should
  1209. (equal "#+BEGIN_EXAMPLE -i\n A\n B\n#+END_EXAMPLE"
  1210. (org-test-with-temp-text
  1211. " #+BEGIN_EXAMPLE -i\n A\n B\n #+END_EXAMPLE"
  1212. (org-indent-region (point-min) (point-max))
  1213. (buffer-string))))
  1214. (should
  1215. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1216. (org-test-with-temp-text
  1217. " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1218. (let ((org-src-preserve-indentation t))
  1219. (org-indent-region (point-min) (point-max)))
  1220. (buffer-string)))))
  1221. ;; Treat export blocks as a whole.
  1222. (should
  1223. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1224. (org-test-with-temp-text "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1225. (org-indent-region (point-min) (point-max))
  1226. (buffer-string))))
  1227. (let ((org-adapt-indentation t))
  1228. (should
  1229. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1230. (org-test-with-temp-text
  1231. " #+BEGIN_EXPORT latex\n A\n B\n #+END_EXPORT"
  1232. (org-indent-region (point-min) (point-max))
  1233. (buffer-string)))))
  1234. ;; Indent according to mode if `org-src-tab-acts-natively' is
  1235. ;; non-nil. Otherwise, do not indent code at all.
  1236. (should
  1237. (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
  1238. (org-test-with-temp-text
  1239. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1240. (let ((org-src-tab-acts-natively t)
  1241. (org-edit-src-content-indentation 0))
  1242. (org-indent-region (point-min) (point-max)))
  1243. (buffer-string))))
  1244. (should
  1245. (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1246. (org-test-with-temp-text
  1247. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1248. (let ((org-src-tab-acts-natively nil)
  1249. (org-edit-src-content-indentation 0))
  1250. (org-indent-region (point-min) (point-max)))
  1251. (buffer-string))))
  1252. ;; Align node properties according to `org-property-format'. Handle
  1253. ;; nicely empty values.
  1254. (should
  1255. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1256. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
  1257. (let ((org-property-format "%-10s %s")
  1258. (org-adapt-indentation nil))
  1259. (org-indent-region (point) (point-max)))
  1260. (buffer-string))))
  1261. (should
  1262. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1263. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
  1264. (let ((org-property-format "%-10s %s")
  1265. (org-adapt-indentation nil))
  1266. (org-indent-region (point) (point-max)))
  1267. (buffer-string))))
  1268. ;; Indent property drawers according to `org-adapt-indentation'.
  1269. (let ((org-adapt-indentation 'headline-data))
  1270. (should
  1271. (equal "* H\n :PROPERTIES:\n :key:\n :END:"
  1272. (org-test-with-temp-text "* H\n:PROPERTIES:\n:key:\n:END:"
  1273. (org-indent-region (point-min) (point-max))
  1274. (buffer-string)))))
  1275. ;; Indent plain lists.
  1276. (let ((org-adapt-indentation t))
  1277. (should
  1278. (equal "- A\n B\n - C\n\n D"
  1279. (org-test-with-temp-text "- A\n B\n - C\n\n D"
  1280. (org-indent-region (point-min) (point-max))
  1281. (buffer-string))))
  1282. (should
  1283. (equal "- A\n\n- B"
  1284. (org-test-with-temp-text " - A\n\n - B"
  1285. (org-indent-region (point-min) (point-max))
  1286. (buffer-string)))))
  1287. ;; Indent footnote definitions.
  1288. (should
  1289. (equal "[fn:1] Definition\n\nDefinition"
  1290. (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
  1291. (org-indent-region (point-min) (point-max))
  1292. (buffer-string))))
  1293. ;; Special case: Start indenting on a blank line.
  1294. (should
  1295. (equal "\nParagraph"
  1296. (org-test-with-temp-text "\n Paragraph"
  1297. (org-indent-region (point-min) (point-max))
  1298. (buffer-string)))))
  1299. ;;; Editing
  1300. (ert-deftest test-org/delete-indentation ()
  1301. "Test `org-delete-indentation' specifications."
  1302. ;; Regular test.
  1303. (should (equal "foo bar"
  1304. (org-test-with-temp-text
  1305. "foo \n bar<point>"
  1306. (org-delete-indentation)
  1307. (buffer-string))))
  1308. ;; With optional argument.
  1309. (should (equal "foo bar"
  1310. (org-test-with-temp-text
  1311. "foo<point> \n bar"
  1312. (org-delete-indentation t)
  1313. (buffer-string))))
  1314. ;; At headline text should be appended to the headline text.
  1315. (should
  1316. (equal"* foo bar :tag:"
  1317. (let (org-auto-align-tags)
  1318. (org-test-with-temp-text
  1319. "* foo :tag:\n bar<point>"
  1320. (org-delete-indentation)
  1321. (buffer-string)))))
  1322. (should
  1323. (equal "* foo bar :tag:"
  1324. (let (org-auto-align-tags)
  1325. (org-test-with-temp-text
  1326. "* foo <point>:tag:\n bar"
  1327. (org-delete-indentation t)
  1328. (buffer-string))))))
  1329. (ert-deftest test-org/return ()
  1330. "Test `org-return' specifications."
  1331. ;; Regular test.
  1332. (should
  1333. (equal "Para\ngraph"
  1334. (org-test-with-temp-text "Para<point>graph"
  1335. (org-return)
  1336. (buffer-string))))
  1337. ;; With optional argument, indent line.
  1338. (should
  1339. (equal " Para\n graph"
  1340. (org-test-with-temp-text " Para<point>graph"
  1341. (org-return t)
  1342. (buffer-string))))
  1343. ;; On a table, call `org-table-next-row'.
  1344. (should
  1345. (org-test-with-temp-text "| <point>a |\n| b |"
  1346. (org-return)
  1347. (looking-at-p "b")))
  1348. ;; Open link or timestamp under point when `org-return-follows-link'
  1349. ;; is non-nil.
  1350. (should
  1351. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1352. (let ((org-return-follows-link t)
  1353. (org-link-search-must-match-exact-headline nil))
  1354. (org-return))
  1355. (looking-at-p "<<target>>")))
  1356. (should-not
  1357. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1358. (let ((org-return-follows-link nil)) (org-return))
  1359. (looking-at-p "<<target>>")))
  1360. (should
  1361. (org-test-with-temp-text "* [[b][a<point>]]\n* b"
  1362. (let ((org-return-follows-link t)) (org-return))
  1363. (looking-at-p "* b")))
  1364. (should
  1365. (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
  1366. (let ((org-return-follows-link t)
  1367. (org-link-search-must-match-exact-headline nil))
  1368. (org-return))
  1369. (looking-at-p "<<target>>")))
  1370. (should-not
  1371. (org-test-with-temp-text "Link [[target]]<point> <<target>>"
  1372. (let ((org-return-follows-link t)
  1373. (org-link-search-must-match-exact-headline nil))
  1374. (org-return))
  1375. (looking-at-p "<<target>>")))
  1376. ;; When `org-return-follows-link' is non-nil, tolerate links and
  1377. ;; timestamps in comments, node properties, etc.
  1378. (should
  1379. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1380. (let ((org-return-follows-link t)
  1381. (org-link-search-must-match-exact-headline nil))
  1382. (org-return))
  1383. (looking-at-p "<<target>>")))
  1384. (should-not
  1385. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1386. (let ((org-return-follows-link nil)) (org-return))
  1387. (looking-at-p "<<target>>")))
  1388. (should-not
  1389. (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
  1390. (let ((org-return-follows-link t)
  1391. (org-link-search-must-match-exact-headline nil))
  1392. (org-return))
  1393. (looking-at-p "<<target>>")))
  1394. ;; Non-nil `org-return-follows-link' ignores read-only state of
  1395. ;; a buffer.
  1396. (should
  1397. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1398. (let ((org-return-follows-link t)
  1399. (org-link-search-must-match-exact-headline nil))
  1400. (setq buffer-read-only t)
  1401. (call-interactively #'org-return))
  1402. (looking-at-p "<<target>>")))
  1403. ;; `org-return-follows-link' handle multi-line lines.
  1404. (should
  1405. (org-test-with-temp-text
  1406. "[[target][This is a very\n long description<point>]]\n <<target>>"
  1407. (let ((org-return-follows-link t)
  1408. (org-link-search-must-match-exact-headline nil))
  1409. (org-return))
  1410. (looking-at-p "<<target>>")))
  1411. (should-not
  1412. (org-test-with-temp-text
  1413. "[[target][This is a very\n long description]]<point>\n <<target>>"
  1414. (let ((org-return-follows-link t)
  1415. (org-link-search-must-match-exact-headline nil))
  1416. (org-return))
  1417. (looking-at-p "<<target>>")))
  1418. ;; However, do not open link when point is in a table.
  1419. (should
  1420. (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
  1421. (let ((org-return-follows-link t)) (org-return))
  1422. (looking-at-p "between")))
  1423. ;; Special case: in a list, when indenting, do not break structure.
  1424. (should
  1425. (equal "- A\n B"
  1426. (org-test-with-temp-text "- A <point>B"
  1427. (org-return t)
  1428. (buffer-string))))
  1429. (should
  1430. (equal "- A\n\n- B"
  1431. (org-test-with-temp-text "- A\n<point>- B"
  1432. (org-return t)
  1433. (buffer-string))))
  1434. ;; On tags part of a headline, add a newline below it instead of
  1435. ;; breaking it.
  1436. (should
  1437. (equal "* H :tag:\n"
  1438. (org-test-with-temp-text "* H :<point>tag:"
  1439. (org-return)
  1440. (buffer-string))))
  1441. ;; Before headline text, add a newline below it instead of breaking
  1442. ;; it.
  1443. (should
  1444. (equal "* TODO H :tag:\n"
  1445. (org-test-with-temp-text "* <point>TODO H :tag:"
  1446. (org-return)
  1447. (buffer-string))))
  1448. (should
  1449. (equal "* TODO [#B] H :tag:\n"
  1450. (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
  1451. (org-return)
  1452. (buffer-string))))
  1453. (should ;TODO are case-sensitive
  1454. (equal "* \nTodo"
  1455. (org-test-with-temp-text "* <point>Todo"
  1456. (org-return)
  1457. (buffer-string))))
  1458. ;; At headline text, break headline text but preserve tags.
  1459. (should
  1460. (equal "* TODO [#B] foo :tag:\nbar"
  1461. (let (org-auto-align-tags)
  1462. (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
  1463. (org-return)
  1464. (buffer-string)))))
  1465. ;; At bol of headline insert newline.
  1466. (should
  1467. (equal "\n* h"
  1468. (org-test-with-temp-text "<point>* h"
  1469. (org-return)
  1470. (buffer-string))))
  1471. ;; Refuse to leave invalid headline in buffer.
  1472. (should
  1473. (equal "* h\n"
  1474. (org-test-with-temp-text "*<point> h"
  1475. (org-return)
  1476. (buffer-string))))
  1477. ;; Before first column or after last one in a table, split the
  1478. ;; table.
  1479. (should
  1480. (equal "| a |\n\n| b |"
  1481. (org-test-with-temp-text "| a |\n<point>| b |"
  1482. (org-return)
  1483. (buffer-string))))
  1484. (should
  1485. (equal "| a |\n\n| b |"
  1486. (org-test-with-temp-text "| a |<point>\n| b |"
  1487. (org-return)
  1488. (buffer-string))))
  1489. ;; Do not auto-fill on hitting <RET> inside a property drawer.
  1490. (should
  1491. (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:"
  1492. (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:"
  1493. (setq-local fill-column 10)
  1494. (auto-fill-mode 1)
  1495. (org-return)
  1496. (buffer-string)))))
  1497. (ert-deftest test-org/with-electric-indent ()
  1498. "Test RET and C-j specifications with `electric-indent-mode' on."
  1499. ;; Call commands interactively, since this is how `newline' knows it
  1500. ;; must run `post-self-insert-hook'.
  1501. ;;
  1502. ;; RET, like `newline', should indent.
  1503. (should
  1504. (equal " Para\n graph"
  1505. (org-test-with-temp-text " Para<point>graph"
  1506. (electric-indent-local-mode 1)
  1507. (call-interactively 'org-return)
  1508. (buffer-string))))
  1509. (should
  1510. (equal "- item1\n item2"
  1511. (org-test-with-temp-text "- item1<point>item2"
  1512. (electric-indent-local-mode 1)
  1513. (call-interactively 'org-return)
  1514. (buffer-string))))
  1515. ;; TODO: test more values of `org-adapt-indentation'.
  1516. (let ((org-adapt-indentation t))
  1517. (should
  1518. (equal "* heading\n body"
  1519. (org-test-with-temp-text "* heading<point>body"
  1520. (electric-indent-local-mode 1)
  1521. (call-interactively 'org-return)
  1522. (buffer-string)))))
  1523. ;; C-j, like `electric-newline-and-maybe-indent', should not indent.
  1524. (should
  1525. (equal " Para\ngraph"
  1526. (org-test-with-temp-text " Para<point>graph"
  1527. (electric-indent-local-mode 1)
  1528. (call-interactively 'org-return-and-maybe-indent)
  1529. (buffer-string))))
  1530. (should
  1531. (equal "- item1\nitem2"
  1532. (org-test-with-temp-text "- item1<point>item2"
  1533. (electric-indent-local-mode 1)
  1534. (call-interactively 'org-return-and-maybe-indent)
  1535. (buffer-string))))
  1536. ;; TODO: test more values of `org-adapt-indentation'.
  1537. (let ((org-adapt-indentation t))
  1538. (should
  1539. (equal "* heading\nbody"
  1540. (org-test-with-temp-text "* heading<point>body"
  1541. (electric-indent-local-mode 1)
  1542. (call-interactively 'org-return-and-maybe-indent)
  1543. (buffer-string))))))
  1544. (ert-deftest test-org/without-electric-indent ()
  1545. "Test RET and C-j specifications with `electric-indent-mode' off."
  1546. ;; Call commands interactively, since this is how `newline' knows it
  1547. ;; must run `post-self-insert-hook'.
  1548. ;;
  1549. ;; RET, like `newline', should not indent.
  1550. (should
  1551. (equal " Para\ngraph"
  1552. (org-test-with-temp-text " Para<point>graph"
  1553. (electric-indent-local-mode 0)
  1554. (call-interactively 'org-return)
  1555. (buffer-string))))
  1556. (should
  1557. (equal "- item1\nitem2"
  1558. (org-test-with-temp-text "- item1<point>item2"
  1559. (electric-indent-local-mode 0)
  1560. (call-interactively 'org-return)
  1561. (buffer-string))))
  1562. (should
  1563. (equal "* heading\nbody"
  1564. (org-test-with-temp-text "* heading<point>body"
  1565. (electric-indent-local-mode 0)
  1566. (call-interactively 'org-return)
  1567. (buffer-string))))
  1568. ;; C-j, like `electric-newline-and-maybe-indent', should indent.
  1569. (should
  1570. (equal " Para\n graph"
  1571. (org-test-with-temp-text " Para<point>graph"
  1572. (electric-indent-local-mode 0)
  1573. (call-interactively 'org-return-and-maybe-indent)
  1574. (buffer-string))))
  1575. (should
  1576. (equal "- item1\n item2"
  1577. (org-test-with-temp-text "- item1<point>item2"
  1578. (electric-indent-local-mode 0)
  1579. (call-interactively 'org-return-and-maybe-indent)
  1580. (buffer-string))))
  1581. ;; TODO: test more values of `org-adapt-indentation'.
  1582. (let ((org-adapt-indentation t))
  1583. (should
  1584. (equal "* heading\n body"
  1585. (org-test-with-temp-text "* heading<point>body"
  1586. (electric-indent-local-mode 0)
  1587. (call-interactively 'org-return-and-maybe-indent)
  1588. (buffer-string))))))
  1589. (ert-deftest test-org/meta-return ()
  1590. "Test M-RET (`org-meta-return') specifications."
  1591. ;; In a table field insert a row above.
  1592. (should
  1593. (org-test-with-temp-text "| a |"
  1594. (forward-char)
  1595. (org-meta-return)
  1596. (forward-line -1)
  1597. (looking-at "| |$")))
  1598. ;; In a paragraph change current line into a header.
  1599. (should
  1600. (org-test-with-temp-text "a"
  1601. (org-meta-return)
  1602. (beginning-of-line)
  1603. (looking-at "\* a$")))
  1604. ;; In an item insert an item, in this case above.
  1605. (should
  1606. (org-test-with-temp-text "- a"
  1607. (org-meta-return)
  1608. (beginning-of-line)
  1609. (looking-at "- $")))
  1610. ;; In a drawer and item insert an item, in this case above.
  1611. (should
  1612. (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
  1613. (forward-line)
  1614. (org-fold-reveal)
  1615. (org-meta-return)
  1616. (beginning-of-line)
  1617. (looking-at "- $"))))
  1618. (ert-deftest test-org/insert-heading ()
  1619. "Test `org-insert-heading' specifications."
  1620. ;; In an empty buffer, insert a new headline.
  1621. (should
  1622. (equal "* "
  1623. (org-test-with-temp-text ""
  1624. (org-insert-heading)
  1625. (buffer-string))))
  1626. ;; At the beginning of a line, turn it into a headline.
  1627. (should
  1628. (equal "* P"
  1629. (org-test-with-temp-text "<point>P"
  1630. (org-insert-heading)
  1631. (buffer-string))))
  1632. ;; In the middle of a line, split the line if allowed, otherwise,
  1633. ;; insert the headline at its end.
  1634. (should
  1635. (equal "Para\n* graph"
  1636. (org-test-with-temp-text "Para<point>graph"
  1637. (let ((org-M-RET-may-split-line '((default . t))))
  1638. (org-insert-heading))
  1639. (buffer-string))))
  1640. (should
  1641. (equal "Paragraph\n* "
  1642. (org-test-with-temp-text "Para<point>graph"
  1643. (let ((org-M-RET-may-split-line '((default . nil))))
  1644. (org-insert-heading))
  1645. (buffer-string))))
  1646. ;; At the beginning of a headline, create one above.
  1647. (should
  1648. (equal "* \n* H"
  1649. (org-test-with-temp-text "* H"
  1650. (org-insert-heading)
  1651. (buffer-string))))
  1652. ;; In the middle of a headline, split it if allowed.
  1653. (should
  1654. (equal "* H\n* 1"
  1655. (org-test-with-temp-text "* H<point>1"
  1656. (let ((org-M-RET-may-split-line '((headline . t))))
  1657. (org-insert-heading))
  1658. (buffer-string))))
  1659. (should
  1660. (equal "* H1\n* "
  1661. (org-test-with-temp-text "* H<point>1"
  1662. (let ((org-M-RET-may-split-line '((headline . nil))))
  1663. (org-insert-heading))
  1664. (buffer-string))))
  1665. ;; However, splitting cannot happen on TODO keywords, priorities or
  1666. ;; tags.
  1667. (should
  1668. (equal "* TODO H1\n* "
  1669. (org-test-with-temp-text "* TO<point>DO H1"
  1670. (let ((org-M-RET-may-split-line '((headline . t))))
  1671. (org-insert-heading))
  1672. (buffer-string))))
  1673. (should
  1674. (equal "* [#A] H1\n* "
  1675. (org-test-with-temp-text "* [#<point>A] H1"
  1676. (let ((org-M-RET-may-split-line '((headline . t))))
  1677. (org-insert-heading))
  1678. (buffer-string))))
  1679. (should
  1680. (equal "* H1 :tag:\n* "
  1681. (org-test-with-temp-text "* H1 :ta<point>g:"
  1682. (let ((org-M-RET-may-split-line '((headline . t))))
  1683. (org-insert-heading))
  1684. (buffer-string))))
  1685. ;; New headline level depends on the level of the headline above.
  1686. (should
  1687. (equal "** H\n** P"
  1688. (org-test-with-temp-text "** H\n<point>P"
  1689. (org-insert-heading)
  1690. (buffer-string))))
  1691. (should
  1692. (equal "** H\nPara\n** graph"
  1693. (org-test-with-temp-text "** H\nPara<point>graph"
  1694. (let ((org-M-RET-may-split-line '((default . t))))
  1695. (org-insert-heading))
  1696. (buffer-string))))
  1697. (should
  1698. (equal "** \n** H"
  1699. (org-test-with-temp-text "** H"
  1700. (org-insert-heading)
  1701. (buffer-string))))
  1702. ;; When called with one universal argument, insert a new headline at
  1703. ;; the end of the current subtree, independently on the position of
  1704. ;; point.
  1705. (should
  1706. (equal
  1707. "* "
  1708. (org-test-with-temp-text ""
  1709. (let ((org-insert-heading-respect-content nil))
  1710. (org-insert-heading '(4)))
  1711. (buffer-string))))
  1712. (should
  1713. (equal
  1714. "entry
  1715. * "
  1716. (org-test-with-temp-text "entry"
  1717. (let ((org-insert-heading-respect-content nil))
  1718. (org-insert-heading '(4)))
  1719. (buffer-string))))
  1720. (should
  1721. (equal
  1722. "* H1\n** H2\n* "
  1723. (org-test-with-temp-text "* H1\n** H2"
  1724. (let ((org-insert-heading-respect-content nil))
  1725. (org-insert-heading '(4)))
  1726. (buffer-string))))
  1727. (should
  1728. (equal
  1729. "* H1\n** H2\n* "
  1730. (org-test-with-temp-text "* H<point>1\n** H2"
  1731. (let ((org-insert-heading-respect-content nil))
  1732. (org-insert-heading '(4)))
  1733. (buffer-string))))
  1734. ;; When called with two universal arguments, insert a new headline
  1735. ;; at the end of the grandparent subtree.
  1736. (should
  1737. (equal "* H1\n** H3\n- item\n** H2\n** "
  1738. (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
  1739. (let ((org-insert-heading-respect-content nil))
  1740. (org-insert-heading '(16)))
  1741. (buffer-string))))
  1742. ;; When optional TOP-LEVEL argument is non-nil, always insert
  1743. ;; a level 1 heading.
  1744. (should
  1745. (equal "* H1\n** H2\n* "
  1746. (org-test-with-temp-text "* H1\n** H2<point>"
  1747. (org-insert-heading nil nil t)
  1748. (buffer-string))))
  1749. (should
  1750. (equal "* H1\n- item\n* "
  1751. (org-test-with-temp-text "* H1\n- item<point>"
  1752. (org-insert-heading nil nil t)
  1753. (buffer-string))))
  1754. ;; Obey `org-blank-before-new-entry'.
  1755. (should
  1756. (equal "* H1\n\n* "
  1757. (org-test-with-temp-text "* H1<point>"
  1758. (let ((org-blank-before-new-entry '((heading . t))))
  1759. (org-insert-heading))
  1760. (buffer-string))))
  1761. (should
  1762. (equal "* H1\n* "
  1763. (org-test-with-temp-text "* H1<point>"
  1764. (let ((org-blank-before-new-entry '((heading . nil))))
  1765. (org-insert-heading))
  1766. (buffer-string))))
  1767. (should
  1768. (equal "* H1\n* H2\n* "
  1769. (org-test-with-temp-text "* H1\n* H2<point>"
  1770. (let ((org-blank-before-new-entry '((heading . auto))))
  1771. (org-insert-heading))
  1772. (buffer-string))))
  1773. (should
  1774. (equal "* H1\n\n* H2\n\n* "
  1775. (org-test-with-temp-text "* H1\n\n* H2<point>"
  1776. (let ((org-blank-before-new-entry '((heading . auto))))
  1777. (org-insert-heading))
  1778. (buffer-string))))
  1779. ;; Corner case: correctly insert a headline after an empty one.
  1780. (should
  1781. (equal "* \n* "
  1782. (org-test-with-temp-text "* <point>"
  1783. (org-insert-heading)
  1784. (buffer-string))))
  1785. (should
  1786. (org-test-with-temp-text "* <point>\n"
  1787. (org-insert-heading)
  1788. (looking-at-p "\n\\'")))
  1789. ;; Do not insert spurious headlines when inserting a new headline.
  1790. (should
  1791. (equal "* H1\n* H2\n* \n"
  1792. (org-test-with-temp-text "* H1\n* H2<point>\n"
  1793. (org-insert-heading)
  1794. (buffer-string))))
  1795. ;; Preserve visibility at beginning of line. In particular, when
  1796. ;; removing spurious blank lines, do not visually merge heading with
  1797. ;; the line visible above.
  1798. (should-not
  1799. (org-test-with-temp-text "* H1<point>\nContents\n\n* H2\n"
  1800. (org-overview)
  1801. (let ((org-blank-before-new-entry '((heading . nil))))
  1802. (org-insert-heading '(4)))
  1803. (invisible-p (line-end-position 0))))
  1804. ;; Properly handle empty lines when forcing a headline below current
  1805. ;; one.
  1806. (should
  1807. (equal "* H1\n\n* H\n\n* "
  1808. (org-test-with-temp-text "* H1\n\n* H<point>"
  1809. (let ((org-blank-before-new-entry '((heading . t))))
  1810. (org-insert-heading '(4))
  1811. (buffer-string))))))
  1812. (ert-deftest test-org/insert-todo-heading-respect-content ()
  1813. "Test `org-insert-todo-heading-respect-content' specifications."
  1814. ;; Create a TODO heading.
  1815. (should
  1816. (org-test-with-temp-text "* H1\n Body"
  1817. (org-insert-todo-heading-respect-content)
  1818. (nth 2 (org-heading-components))))
  1819. ;; Add headline at the end of the first subtree
  1820. (should
  1821. (equal
  1822. "* TODO "
  1823. (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
  1824. (org-insert-todo-heading-respect-content)
  1825. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1826. ;; In a list, do not create a new item.
  1827. (should
  1828. (equal
  1829. "* TODO "
  1830. (org-test-with-temp-text "* H\n- an item\n- another one"
  1831. (search-forward "an ")
  1832. (org-insert-todo-heading-respect-content)
  1833. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1834. ;; Use the same TODO keyword as current heading.
  1835. (should
  1836. (equal
  1837. "* TODO \n"
  1838. (org-test-with-temp-text "* TODO\n** WAITING\n"
  1839. (org-insert-todo-heading-respect-content)
  1840. (buffer-substring-no-properties (line-beginning-position) (point-max))))))
  1841. (ert-deftest test-org/clone-with-time-shift ()
  1842. "Test `org-clone-subtree-with-time-shift'."
  1843. ;; Raise an error before first heading.
  1844. (should-error
  1845. (org-test-with-temp-text ""
  1846. (org-clone-subtree-with-time-shift 1)))
  1847. ;; Raise an error on invalid number of clones.
  1848. (should-error
  1849. (org-test-with-temp-text "* Clone me"
  1850. (org-clone-subtree-with-time-shift -1)))
  1851. ;; Clone non-repeating once.
  1852. (should
  1853. (equal "\
  1854. * H1\n<2015-06-21>
  1855. * H1\n<2015-06-23>
  1856. "
  1857. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1858. (org-clone-subtree-with-time-shift 1 "+2d")
  1859. (replace-regexp-in-string
  1860. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1861. nil nil 1))))
  1862. ;; Clone repeating once.
  1863. (should
  1864. (equal "\
  1865. * H1\n<2015-06-21>
  1866. * H1\n<2015-06-23>
  1867. * H1\n<2015-06-25 +1w>
  1868. "
  1869. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1870. (org-clone-subtree-with-time-shift 1 "+2d")
  1871. (replace-regexp-in-string
  1872. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1873. nil nil 1))))
  1874. ;; Clone repeating once in backward.
  1875. (should
  1876. (equal "\
  1877. * H1\n<2015-06-21>
  1878. * H1\n<2015-06-19>
  1879. * H1\n<2015-06-17 +1w>
  1880. "
  1881. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1882. (org-clone-subtree-with-time-shift 1 "-2d")
  1883. (replace-regexp-in-string
  1884. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1885. nil nil 1))))
  1886. ;; Clone non-repeating zero times.
  1887. (should
  1888. (equal "\
  1889. * H1\n<2015-06-21>
  1890. "
  1891. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1892. (org-clone-subtree-with-time-shift 0 "+2d")
  1893. (replace-regexp-in-string
  1894. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1895. nil nil 1))))
  1896. ;; Clone repeating "zero" times.
  1897. (should
  1898. (equal "\
  1899. * H1\n<2015-06-21>
  1900. * H1\n<2015-06-23 +1w>
  1901. "
  1902. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1903. (org-clone-subtree-with-time-shift 0 "+2d")
  1904. (replace-regexp-in-string
  1905. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1906. nil nil 1))))
  1907. ;; Clone with blank SHIFT argument.
  1908. (should
  1909. (string-prefix-p
  1910. "* H <2012-03-29"
  1911. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1912. (org-clone-subtree-with-time-shift 1 "")
  1913. (buffer-substring-no-properties (line-beginning-position 2)
  1914. (line-end-position 2)))))
  1915. ;; Find time stamps before point. If SHIFT is not specified, ask
  1916. ;; for a time shift.
  1917. (should
  1918. (string-prefix-p
  1919. "* H <2012-03-30"
  1920. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1921. (org-clone-subtree-with-time-shift 1 "+1d")
  1922. (buffer-substring-no-properties (line-beginning-position 2)
  1923. (line-end-position 2)))))
  1924. (should
  1925. (string-prefix-p
  1926. "* H <2014-03-05"
  1927. (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
  1928. (cl-letf (((symbol-function 'read-from-minibuffer)
  1929. (lambda (&rest _args) "+1d")))
  1930. (org-clone-subtree-with-time-shift 1))
  1931. (buffer-substring-no-properties (line-beginning-position 2)
  1932. (line-end-position 2)))))
  1933. ;; Hour shift.
  1934. (should
  1935. (equal "\
  1936. * H1\n<2015-06-21 20:00>
  1937. * H1\n<2015-06-21 23:00>
  1938. * H1\n<2015-06-22 02:00>
  1939. "
  1940. (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>"
  1941. (org-clone-subtree-with-time-shift 2 "+3h")
  1942. (replace-regexp-in-string
  1943. "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" ""
  1944. (buffer-substring-no-properties (point-min) (point-max))
  1945. nil nil 1))))
  1946. (should
  1947. (equal "\
  1948. * H1\n<2015-06-21 20:00>
  1949. * H1\n<2015-06-21 18:00>
  1950. "
  1951. (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>"
  1952. (org-clone-subtree-with-time-shift 1 "-2h")
  1953. (replace-regexp-in-string
  1954. "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" ""
  1955. (buffer-substring-no-properties (point-min) (point-max))
  1956. nil nil 1)))))
  1957. ;;; Fixed-Width Areas
  1958. (ert-deftest test-org/toggle-fixed-width ()
  1959. "Test `org-toggle-fixed-width' specifications."
  1960. ;; No region: Toggle on fixed-width marker in paragraphs.
  1961. (should
  1962. (equal ": A"
  1963. (org-test-with-temp-text "A"
  1964. (org-toggle-fixed-width)
  1965. (buffer-string))))
  1966. ;; No region: Toggle off fixed-width markers in fixed-width areas.
  1967. (should
  1968. (equal "A"
  1969. (org-test-with-temp-text ": A"
  1970. (org-toggle-fixed-width)
  1971. (buffer-string))))
  1972. ;; No region: Toggle on marker in blank lines after elements or just
  1973. ;; after a headline.
  1974. (should
  1975. (equal "* H\n: "
  1976. (org-test-with-temp-text "* H\n"
  1977. (forward-line)
  1978. (org-toggle-fixed-width)
  1979. (buffer-string))))
  1980. (should
  1981. (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
  1982. (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
  1983. (goto-char (point-max))
  1984. (org-toggle-fixed-width)
  1985. (buffer-string))))
  1986. ;; No region: Toggle on marker in front of one line elements (e.g.,
  1987. ;; headlines, clocks)
  1988. (should
  1989. (equal ": * Headline"
  1990. (org-test-with-temp-text "* Headline"
  1991. (org-toggle-fixed-width)
  1992. (buffer-string))))
  1993. (should
  1994. (equal ": #+KEYWORD: value"
  1995. (org-test-with-temp-text "#+KEYWORD: value"
  1996. (org-toggle-fixed-width)
  1997. (buffer-string))))
  1998. ;; No region: error in other situations.
  1999. (should-error
  2000. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
  2001. (forward-line)
  2002. (org-toggle-fixed-width)
  2003. (buffer-string)))
  2004. ;; No region: Indentation is preserved.
  2005. (should
  2006. (equal "- A\n : B"
  2007. (org-test-with-temp-text "- A\n B"
  2008. (forward-line)
  2009. (org-toggle-fixed-width)
  2010. (buffer-string))))
  2011. ;; Region: If it contains only fixed-width elements and blank lines,
  2012. ;; toggle off fixed-width markup.
  2013. (should
  2014. (equal "A\n\nB"
  2015. (org-test-with-temp-text ": A\n\n: B"
  2016. (transient-mark-mode 1)
  2017. (push-mark (point) t t)
  2018. (goto-char (point-max))
  2019. (org-toggle-fixed-width)
  2020. (buffer-string))))
  2021. ;; Region: If it contains anything else, toggle on fixed-width but
  2022. ;; not on fixed-width areas.
  2023. (should
  2024. (equal ": A\n: \n: B\n: \n: C"
  2025. (org-test-with-temp-text "A\n\n: B\n\nC"
  2026. (transient-mark-mode 1)
  2027. (push-mark (point) t t)
  2028. (goto-char (point-max))
  2029. (org-toggle-fixed-width)
  2030. (buffer-string))))
  2031. ;; Region: Ignore blank lines at its end, unless it contains only
  2032. ;; such lines.
  2033. (should
  2034. (equal ": A\n\n"
  2035. (org-test-with-temp-text "A\n\n"
  2036. (transient-mark-mode 1)
  2037. (push-mark (point) t t)
  2038. (goto-char (point-max))
  2039. (org-toggle-fixed-width)
  2040. (buffer-string))))
  2041. (should
  2042. (equal ": \n: \n"
  2043. (org-test-with-temp-text "\n\n"
  2044. (transient-mark-mode 1)
  2045. (push-mark (point) t t)
  2046. (goto-char (point-max))
  2047. (org-toggle-fixed-width)
  2048. (buffer-string)))))
  2049. (ert-deftest test-org/kill-line ()
  2050. "Test `org-kill-line' specifications."
  2051. ;; At the beginning of a line, kill whole line.
  2052. (should
  2053. (equal ""
  2054. (org-test-with-temp-text "abc"
  2055. (org-kill-line)
  2056. (buffer-string))))
  2057. ;; In the middle of a line, kill line until its end.
  2058. (should
  2059. (equal "a"
  2060. (org-test-with-temp-text "a<point>bc"
  2061. (org-kill-line)
  2062. (buffer-string))))
  2063. ;; Do not kill newline character.
  2064. (should
  2065. (equal "\n123"
  2066. (org-test-with-temp-text "abc\n123"
  2067. (org-kill-line)
  2068. (buffer-string))))
  2069. (should
  2070. (equal "a\n123"
  2071. (org-test-with-temp-text "a<point>bc\n123"
  2072. (org-kill-line)
  2073. (buffer-string))))
  2074. ;; When `org-special-ctrl-k' is non-nil and point is at a headline,
  2075. ;; kill until tags.
  2076. (should
  2077. (equal "* A :tag:"
  2078. (org-test-with-temp-text "* A<point>B :tag:"
  2079. (let ((org-special-ctrl-k t)
  2080. (org-tags-column 0))
  2081. (org-kill-line))
  2082. (buffer-string))))
  2083. ;; If point is on tags, only kill part left until the end of line.
  2084. (should
  2085. (equal "* A :tag:"
  2086. (org-test-with-temp-text "* A :tag:<point>tag2:"
  2087. (let ((org-special-ctrl-k t)
  2088. (org-tags-column 0))
  2089. (org-kill-line))
  2090. (buffer-string))))
  2091. ;; However, if point is at the beginning of the line, kill whole
  2092. ;; headline.
  2093. (should
  2094. (equal ""
  2095. (org-test-with-temp-text "* AB :tag:"
  2096. (let ((org-special-ctrl-k t)
  2097. (org-tags-column 0))
  2098. (org-kill-line))
  2099. (buffer-string))))
  2100. ;; When `org-ctrl-k-protect-subtree' is non-nil, and point is in
  2101. ;; invisible text, ask before removing it. When set to `error',
  2102. ;; throw an error.
  2103. (should-error
  2104. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  2105. (org-overview)
  2106. (let ((org-special-ctrl-k nil)
  2107. (org-ctrl-k-protect-subtree t))
  2108. (cl-letf (((symbol-function 'y-or-n-p) 'ignore))
  2109. (org-kill-line)))))
  2110. (should-error
  2111. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  2112. (org-overview)
  2113. (let ((org-special-ctrl-k nil)
  2114. (org-ctrl-k-protect-subtree 'error))
  2115. (org-kill-line)))))
  2116. ;;; Headline
  2117. (ert-deftest test-org/get-heading ()
  2118. "Test `org-get-heading' specifications."
  2119. ;; Return current heading, even if point is not on it.
  2120. (should
  2121. (equal "H"
  2122. (org-test-with-temp-text "* H"
  2123. (org-get-heading))))
  2124. (should
  2125. (equal "H"
  2126. (org-test-with-temp-text "* H\nText<point>"
  2127. (org-get-heading))))
  2128. ;; Without any optional argument, return TODO keyword, priority
  2129. ;; cookie, COMMENT keyword and tags.
  2130. (should
  2131. (equal "TODO H"
  2132. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2133. (org-get-heading))))
  2134. (should
  2135. (equal "[#A] H"
  2136. (org-test-with-temp-text "* [#A] H"
  2137. (org-get-heading))))
  2138. (should
  2139. (equal "COMMENT H"
  2140. (org-test-with-temp-text "* COMMENT H"
  2141. (org-get-heading))))
  2142. (should
  2143. (equal "H :tag:"
  2144. (org-test-with-temp-text "* H :tag:"
  2145. (org-get-heading))))
  2146. ;; With NO-TAGS argument, ignore tags.
  2147. (should
  2148. (equal "TODO H"
  2149. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2150. (org-get-heading t))))
  2151. (should
  2152. (equal "H"
  2153. (org-test-with-temp-text "* H :tag:"
  2154. (org-get-heading t))))
  2155. ;; With NO-TODO, ignore TODO keyword.
  2156. (should
  2157. (equal "H"
  2158. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2159. (org-get-heading nil t))))
  2160. (should
  2161. (equal "H :tag:"
  2162. (org-test-with-temp-text "* H :tag:"
  2163. (org-get-heading nil t))))
  2164. ;; TODO keywords are case-sensitive.
  2165. (should
  2166. (equal "Todo H"
  2167. (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
  2168. (org-get-heading nil t))))
  2169. ;; With NO-PRIORITY, ignore priority.
  2170. (should
  2171. (equal "H"
  2172. (org-test-with-temp-text "* [#A] H"
  2173. (org-get-heading nil nil t))))
  2174. (should
  2175. (equal "H"
  2176. (org-test-with-temp-text "* H"
  2177. (org-get-heading nil nil t))))
  2178. (should
  2179. (equal "TODO H"
  2180. (org-test-with-temp-text "* TODO [#A] H"
  2181. (org-get-heading nil nil t))))
  2182. ;; With NO-COMMENT, ignore COMMENT keyword.
  2183. (should
  2184. (equal "H"
  2185. (org-test-with-temp-text "* COMMENT H"
  2186. (org-get-heading nil nil nil t))))
  2187. (should
  2188. (equal "H"
  2189. (org-test-with-temp-text "* H"
  2190. (org-get-heading nil nil nil t))))
  2191. (should
  2192. (equal "TODO [#A] H"
  2193. (org-test-with-temp-text "* TODO [#A] COMMENT H"
  2194. (org-get-heading nil nil nil t))))
  2195. ;; On an empty headline, return value is consistent.
  2196. (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
  2197. (should (equal "" (org-test-with-temp-text "* " (org-get-heading t))))
  2198. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t))))
  2199. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t))))
  2200. (should
  2201. (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t)))))
  2202. (ert-deftest test-org/in-commented-heading-p ()
  2203. "Test `org-in-commented-heading-p' specifications."
  2204. ;; Commented headline.
  2205. (should
  2206. (org-test-with-temp-text "* COMMENT Headline\nBody"
  2207. (goto-char (point-max))
  2208. (org-in-commented-heading-p)))
  2209. ;; Commented ancestor.
  2210. (should
  2211. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  2212. (goto-char (point-max))
  2213. (org-in-commented-heading-p)))
  2214. ;; Comment keyword is case-sensitive.
  2215. (should-not
  2216. (org-test-with-temp-text "* Comment Headline\nBody"
  2217. (goto-char (point-max))
  2218. (org-in-commented-heading-p)))
  2219. ;; Keyword is standalone.
  2220. (should-not
  2221. (org-test-with-temp-text "* COMMENTHeadline\nBody"
  2222. (goto-char (point-max))
  2223. (org-in-commented-heading-p)))
  2224. ;; Optional argument.
  2225. (should-not
  2226. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  2227. (goto-char (point-max))
  2228. (org-in-commented-heading-p t))))
  2229. (ert-deftest test-org/in-archived-heading-p ()
  2230. "Test `org-in-archived-heading-p' specifications."
  2231. ;; Archived headline.
  2232. (should
  2233. (org-test-with-temp-text "* Headline :ARCHIVE:\nBody"
  2234. (goto-char (point-max))
  2235. (org-in-archived-heading-p)))
  2236. ;; Archived ancestor.
  2237. (should
  2238. (org-test-with-temp-text "* Headline :ARCHIVE:\n** Level 2\nBody"
  2239. (goto-char (point-max))
  2240. (org-in-archived-heading-p)))
  2241. ;; Optional argument.
  2242. (should-not
  2243. (org-test-with-temp-text "* Headline :ARCHIVE:\n** Level 2\nBody"
  2244. (goto-char (point-max))
  2245. (org-in-archived-heading-p t)))
  2246. ;; Archive tag containing ARCHIVE as substring
  2247. (should-not
  2248. (org-test-with-temp-text "* Headline :NOARCHIVE:\n** Level 2\nBody"
  2249. (goto-char (point-max))
  2250. (org-in-archived-heading-p))))
  2251. (ert-deftest test-org/entry-blocked-p ()
  2252. ;; Check other dependencies.
  2253. (should
  2254. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  2255. (let ((org-enforce-todo-dependencies t)
  2256. (org-blocker-hook
  2257. '(org-block-todo-from-children-or-siblings-or-parent)))
  2258. (org-entry-blocked-p))))
  2259. (should-not
  2260. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  2261. (let ((org-enforce-todo-dependencies t)
  2262. (org-blocker-hook
  2263. '(org-block-todo-from-children-or-siblings-or-parent)))
  2264. (org-entry-blocked-p))))
  2265. ;; Entry without a TODO keyword or with a DONE keyword cannot be
  2266. ;; blocked.
  2267. (should-not
  2268. (org-test-with-temp-text "* Blocked\n** TODO one"
  2269. (let ((org-enforce-todo-dependencies t)
  2270. (org-blocker-hook
  2271. '(org-block-todo-from-children-or-siblings-or-parent)))
  2272. (org-entry-blocked-p))))
  2273. (should-not
  2274. (org-test-with-temp-text "* DONE Blocked\n** TODO one"
  2275. (let ((org-enforce-todo-dependencies t)
  2276. (org-blocker-hook
  2277. '(org-block-todo-from-children-or-siblings-or-parent)))
  2278. (org-entry-blocked-p))))
  2279. ;; Follow :ORDERED: specifications.
  2280. (should
  2281. (org-test-with-temp-text
  2282. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
  2283. (let ((org-enforce-todo-dependencies t)
  2284. (org-blocker-hook
  2285. '(org-block-todo-from-children-or-siblings-or-parent)))
  2286. (org-entry-blocked-p))))
  2287. (should-not
  2288. (org-test-with-temp-text
  2289. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
  2290. (let ((org-enforce-todo-dependencies t)
  2291. (org-blocker-hook
  2292. '(org-block-todo-from-children-or-siblings-or-parent)))
  2293. (org-entry-blocked-p)))))
  2294. (ert-deftest test-org/get-outline-path ()
  2295. "Test `org-get-outline-path' specifications."
  2296. ;; Top-level headlines have no outline path.
  2297. (should-not
  2298. (org-test-with-temp-text "* H"
  2299. (org-get-outline-path)))
  2300. ;; Otherwise, outline path is the path leading to the headline.
  2301. (should
  2302. (equal '("H")
  2303. (org-test-with-temp-text "* H\n** S<point>"
  2304. (org-get-outline-path))))
  2305. ;; Find path even when point is not on a headline.
  2306. (should
  2307. (equal '("H")
  2308. (org-test-with-temp-text "* H\n** S\nText<point>"
  2309. (org-get-outline-path))))
  2310. ;; TODO keywords, tags and statistics cookies are ignored.
  2311. (should
  2312. (equal '("H")
  2313. (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
  2314. (org-get-outline-path))))
  2315. ;; Links are replaced with their description or their path.
  2316. (should
  2317. (equal '("Org")
  2318. (org-test-with-temp-text
  2319. "* [[https://orgmode.org][Org]]\n** S<point>"
  2320. (org-get-outline-path))))
  2321. (should
  2322. (equal '("https://orgmode.org")
  2323. (org-test-with-temp-text
  2324. "* [[https://orgmode.org]]\n** S<point>"
  2325. (org-get-outline-path))))
  2326. ;; When WITH-SELF is non-nil, include current heading.
  2327. (should
  2328. (equal '("H")
  2329. (org-test-with-temp-text "* H"
  2330. (org-get-outline-path t))))
  2331. (should
  2332. (equal '("H" "S")
  2333. (org-test-with-temp-text "* H\n** S\nText<point>"
  2334. (org-get-outline-path t))))
  2335. ;; Using cache is transparent to the user.
  2336. (should
  2337. (equal '("H")
  2338. (org-test-with-temp-text "* H\n** S<point>"
  2339. (setq org-outline-path-cache nil)
  2340. (org-get-outline-path nil t))))
  2341. ;; Do not corrupt cache when finding outline path in distant part of
  2342. ;; the buffer.
  2343. (should
  2344. (equal '("H2")
  2345. (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
  2346. (setq org-outline-path-cache nil)
  2347. (org-get-outline-path nil t)
  2348. (search-forward "S2")
  2349. (org-get-outline-path nil t))))
  2350. ;; Do not choke on empty headlines.
  2351. (should
  2352. (org-test-with-temp-text "* H\n** <point>"
  2353. (org-get-outline-path)))
  2354. (should
  2355. (org-test-with-temp-text "* \n** H<point>"
  2356. (org-get-outline-path))))
  2357. (ert-deftest test-org/format-outline-path ()
  2358. "Test `org-format-outline-path' specifications."
  2359. (should
  2360. (string= (org-format-outline-path (list "one" "two" "three"))
  2361. "one/two/three"))
  2362. ;; Empty path.
  2363. (should
  2364. (string= (org-format-outline-path '())
  2365. ""))
  2366. (should
  2367. (string= (org-format-outline-path '(nil))
  2368. ""))
  2369. ;; Empty path and prefix.
  2370. (should
  2371. (string= (org-format-outline-path '() nil ">>")
  2372. ">>"))
  2373. ;; Trailing whitespace in headings.
  2374. (should
  2375. (string= (org-format-outline-path (list "one\t" "tw o " "three "))
  2376. "one/tw o/three"))
  2377. ;; Non-default prefix and separators.
  2378. (should
  2379. (string= (org-format-outline-path (list "one" "two" "three") nil ">>" "|")
  2380. ">>|one|two|three"))
  2381. ;; Truncate.
  2382. (should
  2383. (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
  2384. "one/two/.."))
  2385. ;; Give a very narrow width.
  2386. (should
  2387. (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
  2388. "on"))
  2389. ;; Give a prefix that extends beyond the width.
  2390. (should
  2391. (string= (org-format-outline-path (list "one" "two" "three" "four") 10
  2392. ">>>>>>>>>>")
  2393. ">>>>>>>>..")))
  2394. (ert-deftest test-org/org-find-olp ()
  2395. "Test `org-find-olp' specifications."
  2396. (org-test-with-temp-text
  2397. "
  2398. * Headline
  2399. ** COMMENT headline2
  2400. ** TODO headline3
  2401. *** [#A] headline4 :tags:
  2402. ** [#A]headline5
  2403. ** [0%] headline6
  2404. ** headline7 [100%]
  2405. ** headline8 [1/5] :some:more:tags:
  2406. * Test
  2407. "
  2408. (should (org-find-olp '("Headline") t))
  2409. (should-error (org-find-olp '("Headline" "Test") t))
  2410. (should-error (org-find-olp '("Headlinealksjd") t))
  2411. (should (org-find-olp '("Headline" "headline2") t))
  2412. (should (org-find-olp '("Headline" "headline3") t))
  2413. (should (org-find-olp '("Headline" "headline3" "headline4") t))
  2414. (should-error (org-find-olp '("Headline" "headline5") t))
  2415. (should (org-find-olp '("Headline" "headline6") t))
  2416. (should (org-find-olp '("Headline" "headline7") t))
  2417. (should (org-find-olp '("Headline" "headline8") t))))
  2418. (ert-deftest test-org/map-entries ()
  2419. "Test `org-map-entries' specifications."
  2420. ;; Full match.
  2421. (should
  2422. (equal '(1 11)
  2423. (org-test-with-temp-text "* Level 1\n** Level 2"
  2424. (org-map-entries #'point))))
  2425. ;; Level match.
  2426. (should
  2427. (equal '(1)
  2428. (org-test-with-temp-text "* Level 1\n** Level 2"
  2429. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL=1")))))
  2430. (should
  2431. (equal '(11)
  2432. (org-test-with-temp-text "* Level 1\n** Level 2"
  2433. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL>1")))))
  2434. ;; Tag match.
  2435. (should
  2436. (equal '(11)
  2437. (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
  2438. (org-map-entries #'point "yes"))))
  2439. (should
  2440. (equal '(14)
  2441. (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
  2442. (org-map-entries #'point "+yes-a"))))
  2443. (should
  2444. (equal '(11 23)
  2445. (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
  2446. (org-map-entries #'point "{yes?}"))))
  2447. ;; Priority match.
  2448. (should
  2449. (equal '(1)
  2450. (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
  2451. (org-map-entries #'point "PRIORITY=\"A\""))))
  2452. ;; Date match.
  2453. (should
  2454. (equal '(36)
  2455. (org-test-with-temp-text "
  2456. * H1
  2457. SCHEDULED: <2012-03-29 thu.>
  2458. * H2
  2459. SCHEDULED: <2014-03-04 tue.>"
  2460. (org-map-entries #'point "SCHEDULED=\"<2014-03-04 tue.>\""))))
  2461. (should
  2462. (equal '(2)
  2463. (org-test-with-temp-text "
  2464. * H1
  2465. SCHEDULED: <2012-03-29 thu.>
  2466. * H2
  2467. SCHEDULED: <2014-03-04 tue.>"
  2468. (org-map-entries #'point "SCHEDULED<\"<2013-01-01>\""))))
  2469. ;; Regular property match.
  2470. (should
  2471. (equal '(2)
  2472. (org-test-with-temp-text "
  2473. * H1
  2474. :PROPERTIES:
  2475. :TEST: 1
  2476. :END:
  2477. * H2
  2478. :PROPERTIES:
  2479. :TEST: 2
  2480. :END:"
  2481. (org-map-entries #'point "TEST=1"))))
  2482. ;; Multiple criteria.
  2483. (should
  2484. (equal '(23)
  2485. (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
  2486. (let (org-odd-levels-only
  2487. (org-use-tag-inheritance nil))
  2488. (org-map-entries #'point "yes+LEVEL=1")))))
  2489. ;; "or" criteria.
  2490. (should
  2491. (equal '(12 24)
  2492. (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
  2493. (let (org-odd-levels-only)
  2494. (org-map-entries #'point "LEVEL=2|no")))))
  2495. (should
  2496. (equal '(1 12)
  2497. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
  2498. (let (org-odd-levels-only)
  2499. (org-map-entries #'point "yes|no")))))
  2500. ;; "and" criteria.
  2501. (should
  2502. (equal '(22)
  2503. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
  2504. (let (org-odd-levels-only)
  2505. (org-map-entries #'point "yes&no")))))
  2506. ;; Setting `org-map-continue-from'
  2507. (should
  2508. (string= ""
  2509. (org-test-with-temp-text "* H1\n* H2\n* H3n* H4"
  2510. (org-map-entries
  2511. (lambda ()
  2512. (org-cut-subtree)
  2513. (setq org-map-continue-from (point))))
  2514. (buffer-string))))
  2515. (should
  2516. (string= "* H1\n* H2\n* H3\n"
  2517. (org-test-with-temp-text "* H1\n* H2\n* H3\n* H4"
  2518. (org-map-entries
  2519. (lambda ()
  2520. (when (string= "H4"
  2521. (org-element-property
  2522. :raw-value (org-element-at-point)))
  2523. (org-cut-subtree)
  2524. (setq org-map-continue-from
  2525. (org-element-property
  2526. :begin (org-element-at-point))))))
  2527. (buffer-string)))))
  2528. (ert-deftest test-org/edit-headline ()
  2529. "Test `org-edit-headline' specifications."
  2530. (should
  2531. (equal "* B"
  2532. (org-test-with-temp-text "* A"
  2533. (org-edit-headline "B")
  2534. (buffer-string))))
  2535. ;; Handle empty headings.
  2536. (should
  2537. (equal "* "
  2538. (org-test-with-temp-text "* A"
  2539. (org-edit-headline "")
  2540. (buffer-string))))
  2541. (should
  2542. (equal "* A"
  2543. (org-test-with-temp-text "* "
  2544. (org-edit-headline "A")
  2545. (buffer-string))))
  2546. ;; Handle TODO keywords and priority cookies.
  2547. (should
  2548. (equal "* TODO B"
  2549. (org-test-with-temp-text "* TODO A"
  2550. (org-edit-headline "B")
  2551. (buffer-string))))
  2552. (should
  2553. (equal "* [#A] B"
  2554. (org-test-with-temp-text "* [#A] A"
  2555. (org-edit-headline "B")
  2556. (buffer-string))))
  2557. (should
  2558. (equal "* TODO [#A] B"
  2559. (org-test-with-temp-text "* TODO [#A] A"
  2560. (org-edit-headline "B")
  2561. (buffer-string))))
  2562. ;; Handle tags.
  2563. (equal "* B :tag:"
  2564. (org-test-with-temp-text "* A :tag:"
  2565. (let ((org-tags-column 4)) (org-edit-headline "B"))
  2566. (buffer-string))))
  2567. ;;; Keywords
  2568. (ert-deftest test-org/set-regexps-and-options ()
  2569. "Test `org-set-regexps-and-options' specifications."
  2570. ;; TAGS keyword.
  2571. (should
  2572. (equal '(("A"))
  2573. (let ((org-tag-alist '(("A")))
  2574. (org-tag-persistent-alist nil))
  2575. (org-test-with-temp-text ""
  2576. (org-mode-restart)
  2577. org-current-tag-alist))))
  2578. (should
  2579. (equal '(("B"))
  2580. (let ((org-tag-alist '(("A")))
  2581. (org-tag-persistent-alist nil))
  2582. (org-test-with-temp-text "#+TAGS: B"
  2583. (org-mode-restart)
  2584. org-current-tag-alist))))
  2585. (should
  2586. (equal '(("C") ("B"))
  2587. (let ((org-tag-alist '(("A")))
  2588. (org-tag-persistent-alist '(("C"))))
  2589. (org-test-with-temp-text "#+TAGS: B"
  2590. (org-mode-restart)
  2591. org-current-tag-alist))))
  2592. (should
  2593. (equal '(("B"))
  2594. (let ((org-tag-alist '(("A")))
  2595. (org-tag-persistent-alist '(("C"))))
  2596. (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
  2597. (org-mode-restart)
  2598. org-current-tag-alist))))
  2599. (should
  2600. (equal '(("A" . ?a) ("B") ("C"))
  2601. (let ((org-tag-persistent-alist nil))
  2602. (org-test-with-temp-text "#+TAGS: A(a) B C"
  2603. (org-mode-restart)
  2604. org-current-tag-alist))))
  2605. (should
  2606. (equal '(("A") (:newline) ("B"))
  2607. (let ((org-tag-persistent-alist nil))
  2608. (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
  2609. (org-mode-restart)
  2610. org-current-tag-alist))))
  2611. (should
  2612. (equal '((:startgroup) ("A") ("B") (:endgroup) ("C"))
  2613. (let ((org-tag-persistent-alist nil))
  2614. (org-test-with-temp-text "#+TAGS: { A B } C"
  2615. (org-mode-restart)
  2616. org-current-tag-alist))))
  2617. (should
  2618. (equal '((:startgroup) ("A") (:grouptags) ("B") ("C") (:endgroup))
  2619. (let ((org-tag-persistent-alist nil))
  2620. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2621. (org-mode-restart)
  2622. org-current-tag-alist))))
  2623. (should
  2624. (equal '(("A" "B" "C"))
  2625. (let ((org-tag-persistent-alist nil))
  2626. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2627. (org-mode-restart)
  2628. org-tag-groups-alist))))
  2629. (should
  2630. (equal '((:startgrouptag) ("A") (:grouptags) ("B") ("C") (:endgrouptag))
  2631. (let ((org-tag-persistent-alist nil))
  2632. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2633. (org-mode-restart)
  2634. org-current-tag-alist))))
  2635. (should
  2636. (equal '(("A" "B" "C"))
  2637. (let ((org-tag-persistent-alist nil))
  2638. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2639. (org-mode-restart)
  2640. org-tag-groups-alist))))
  2641. (should-not
  2642. (let ((org-tag-alist '(("A"))))
  2643. (org-test-with-temp-text "#+TAGS:"
  2644. (org-mode-restart)
  2645. org-current-tag-alist)))
  2646. ;; FILETAGS keyword.
  2647. (should
  2648. (equal '("A" "B" "C")
  2649. (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
  2650. (org-mode-restart)
  2651. org-file-tags)))
  2652. ;; PROPERTY keyword. Property names are case-insensitive.
  2653. (should
  2654. (equal "foo=1"
  2655. (org-test-with-temp-text "#+PROPERTY: var foo=1"
  2656. (org-mode-restart)
  2657. (cdr (assoc "var" org-keyword-properties)))))
  2658. (should
  2659. (equal
  2660. "foo=1 bar=2"
  2661. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
  2662. (org-mode-restart)
  2663. (cdr (assoc "var" org-keyword-properties)))))
  2664. (should
  2665. (equal
  2666. "foo=1 bar=2"
  2667. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
  2668. (org-mode-restart)
  2669. (cdr (assoc "var" org-keyword-properties)))))
  2670. ;; ARCHIVE keyword.
  2671. (should
  2672. (equal "%s_done::"
  2673. (org-test-with-temp-text "#+ARCHIVE: %s_done::"
  2674. (org-mode-restart)
  2675. org-archive-location)))
  2676. ;; CATEGORY keyword.
  2677. (should
  2678. (eq 'test
  2679. (org-test-with-temp-text "#+CATEGORY: test"
  2680. (org-mode-restart)
  2681. org-category)))
  2682. (should
  2683. (equal "test"
  2684. (org-test-with-temp-text "#+CATEGORY: test"
  2685. (org-mode-restart)
  2686. (cdr (assoc "CATEGORY" org-keyword-properties)))))
  2687. ;; COLUMNS keyword.
  2688. (should
  2689. (equal "%25ITEM %TAGS %PRIORITY %TODO"
  2690. (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
  2691. (org-mode-restart)
  2692. org-columns-default-format)))
  2693. ;; CONSTANTS keyword. Constants names are case sensitive.
  2694. (should
  2695. (equal '("299792458." "3.14")
  2696. (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
  2697. (org-mode-restart)
  2698. (mapcar
  2699. (lambda (n) (cdr (assoc n org-table-formula-constants-local)))
  2700. '("c" "pi")))))
  2701. (should
  2702. (equal "3.14"
  2703. (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
  2704. (org-mode-restart)
  2705. (cdr (assoc "pi" org-table-formula-constants-local)))))
  2706. (should
  2707. (equal "22/7"
  2708. (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
  2709. (org-mode-restart)
  2710. (cdr (assoc "PI" org-table-formula-constants-local)))))
  2711. ;; LINK keyword.
  2712. (should
  2713. (equal
  2714. '("url1" "url2")
  2715. (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
  2716. (org-mode-restart)
  2717. (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local)))
  2718. '("a" "b")))))
  2719. ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
  2720. (should
  2721. (equal
  2722. '(?X ?Z ?Y)
  2723. (org-test-with-temp-text "#+PRIORITIES: X Z Y"
  2724. (org-mode-restart)
  2725. (list org-priority-highest org-priority-lowest org-priority-default))))
  2726. (should
  2727. (equal
  2728. '(?A ?C ?B)
  2729. (org-test-with-temp-text "#+PRIORITIES: X Z"
  2730. (org-mode-restart)
  2731. (list org-priority-highest org-priority-lowest org-priority-default))))
  2732. ;; STARTUP keyword.
  2733. (should
  2734. (equal '(t t)
  2735. (org-test-with-temp-text "#+STARTUP: fold odd"
  2736. (org-mode-restart)
  2737. (list org-startup-folded org-odd-levels-only))))
  2738. ;; TODO keywords.
  2739. (should
  2740. (equal '(("A" "B") ("C"))
  2741. (org-test-with-temp-text "#+TODO: A B | C"
  2742. (org-mode-restart)
  2743. (list org-not-done-keywords org-done-keywords))))
  2744. (should
  2745. (equal '(("A" "C") ("B" "D"))
  2746. (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
  2747. (org-mode-restart)
  2748. (list org-not-done-keywords org-done-keywords))))
  2749. (should
  2750. (equal '(("A" "B") ("C"))
  2751. (org-test-with-temp-text "#+TYP_TODO: A B | C"
  2752. (org-mode-restart)
  2753. (list org-not-done-keywords org-done-keywords))))
  2754. (should
  2755. (equal '((:startgroup) ("A" . ?a) (:endgroup))
  2756. (org-test-with-temp-text "#+TODO: A(a)"
  2757. (org-mode-restart)
  2758. org-todo-key-alist)))
  2759. (should
  2760. (equal '(("D" note nil) ("C" time nil) ("B" note time))
  2761. (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
  2762. (org-mode-restart)
  2763. org-todo-log-states)))
  2764. ;; Enter SETUPFILE keyword.
  2765. (should
  2766. (equal "1"
  2767. (org-test-with-temp-text
  2768. (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
  2769. (org-mode-restart)
  2770. (cdr (assoc "a" org-keyword-properties))))))
  2771. (ert-deftest test-org/collect-keywords ()
  2772. "Test `org-collect-keywords'."
  2773. (should-not
  2774. (org-test-with-temp-text "#+begin_example\n#+foo: bar\n#+end_example"
  2775. (org-collect-keywords '("FOO")))))
  2776. ;;; Links
  2777. ;;;; Coderefs
  2778. (ert-deftest test-org/coderef ()
  2779. "Test coderef links specifications."
  2780. (should
  2781. (org-test-with-temp-text "
  2782. #+BEGIN_SRC emacs-lisp
  2783. \(+ 1 1) (ref:sc)
  2784. #+END_SRC
  2785. \[[(sc)<point>]]"
  2786. (org-open-at-point)
  2787. (looking-at "(ref:sc)")))
  2788. ;; Find coderef even with alternate label format.
  2789. (should
  2790. (org-test-with-temp-text "
  2791. #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
  2792. \(+ 1 1) {ref:sc}
  2793. #+END_SRC
  2794. \[[(sc)<point>]]"
  2795. (org-open-at-point)
  2796. (looking-at "{ref:sc}"))))
  2797. ;;;; Custom ID
  2798. (ert-deftest test-org/custom-id ()
  2799. "Test custom ID links specifications."
  2800. (should
  2801. (org-test-with-temp-text
  2802. "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2803. (org-open-at-point)
  2804. (looking-at-p "\\* H1")))
  2805. ;; Handle escape characters.
  2806. (should
  2807. (org-test-with-temp-text
  2808. "* H1\n:PROPERTIES:\n:CUSTOM_ID: [%]\n:END:\n* H2\n[[#\\[%\\]<point>]]"
  2809. (org-open-at-point)
  2810. (looking-at-p "\\* H1")))
  2811. ;; Throw an error on false positives.
  2812. (should-error
  2813. (org-test-with-temp-text
  2814. "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2815. (org-open-at-point)
  2816. (looking-at-p "\\* H1"))))
  2817. ;;;; Fuzzy Links
  2818. ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
  2819. ;; a named element (#+name: text) and to headlines (* Text).
  2820. (ert-deftest test-org/fuzzy-links ()
  2821. "Test fuzzy links specifications."
  2822. ;; Fuzzy link goes in priority to a matching target.
  2823. (should
  2824. (org-test-with-temp-text
  2825. "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
  2826. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2827. (looking-at "<<Test>>")))
  2828. ;; Then fuzzy link points to an element with a given name.
  2829. (should
  2830. (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
  2831. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2832. (looking-at "#\\+NAME: Test")))
  2833. ;; A target still lead to a matching headline otherwise.
  2834. (should
  2835. (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
  2836. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2837. (looking-at "\\* Head2")))
  2838. ;; With a leading star in link, enforce heading match.
  2839. (should
  2840. (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
  2841. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2842. (looking-at "\\* Test")))
  2843. ;; With a leading star in link, enforce exact heading match, even
  2844. ;; with `org-link-search-must-match-exact-headline' set to nil.
  2845. (should-error
  2846. (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
  2847. (let ((org-link-search-must-match-exact-headline nil))
  2848. (org-open-at-point))))
  2849. ;; Handle non-nil `org-link-search-must-match-exact-headline'.
  2850. (should
  2851. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
  2852. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2853. (looking-at "\\* Test")))
  2854. (should
  2855. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
  2856. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2857. (looking-at "\\* Test")))
  2858. ;; Heading match should not care about spaces, cookies, TODO
  2859. ;; keywords, priorities, and tags. However, TODO keywords are
  2860. ;; case-sensitive.
  2861. (should
  2862. (let ((first-line
  2863. "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
  2864. (org-test-with-temp-text
  2865. (concat first-line "\nFoo Bar\n<point>[[*Test 1 2]]")
  2866. (let ((org-link-search-must-match-exact-headline nil)
  2867. (org-todo-regexp "TODO"))
  2868. (org-open-at-point))
  2869. (looking-at (regexp-quote first-line)))))
  2870. (should-error
  2871. (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
  2872. (let ((org-link-search-must-match-exact-headline nil)
  2873. (org-todo-regexp "TODO"))
  2874. (org-open-at-point))))
  2875. ;; Heading match should still be exact.
  2876. (should-error
  2877. (org-test-with-temp-text "
  2878. ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
  2879. Foo Bar
  2880. <point>[[*Test 1]]"
  2881. (let ((org-link-search-must-match-exact-headline nil)
  2882. (org-todo-regexp "TODO"))
  2883. (org-open-at-point))))
  2884. (should
  2885. (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
  2886. (let ((org-link-search-must-match-exact-headline nil)
  2887. (org-todo-regexp "TODO"))
  2888. (org-open-at-point))
  2889. (looking-at-p (regexp-quote "** Test 1 2"))))
  2890. ;; Heading match ignores COMMENT keyword.
  2891. (should
  2892. (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
  2893. (org-open-at-point)
  2894. (looking-at "\\* COMMENT Test")))
  2895. (should
  2896. (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
  2897. (org-open-at-point)
  2898. (looking-at "\\* TODO COMMENT Test")))
  2899. ;; Correctly un-escape fuzzy links.
  2900. (should
  2901. (org-test-with-temp-text "* [foo]\n[[*\\[foo\\]][With escaped characters]]"
  2902. (org-open-at-point)
  2903. (bobp)))
  2904. ;; Match search strings containing newline characters, including
  2905. ;; blank lines.
  2906. (should
  2907. (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
  2908. (let ((file (buffer-file-name)))
  2909. (goto-char (point-max))
  2910. (insert (format "[[file:%s::line1 line2]]" file))
  2911. (beginning-of-line)
  2912. (let ((org-link-search-must-match-exact-headline nil))
  2913. (org-open-at-point 0))
  2914. (looking-at-p "line1"))))
  2915. (should
  2916. (org-test-with-temp-text-in-file "Paragraph\n\nline1\n\nline2\n\n"
  2917. (let ((file (buffer-file-name)))
  2918. (goto-char (point-max))
  2919. (insert (format "[[file:%s::line1 line2]]" file))
  2920. (beginning-of-line)
  2921. (let ((org-link-search-must-match-exact-headline nil))
  2922. (org-open-at-point 0))
  2923. (looking-at-p "line1")))))
  2924. ;;;; Open at point
  2925. (ert-deftest test-org/open-at-point/keyword ()
  2926. "Does `org-open-at-point' open link in a keyword line?"
  2927. (should
  2928. (org-test-with-temp-text
  2929. "<<top>>\n#+KEYWORD: <point>[[top]]"
  2930. (org-open-at-point) t))
  2931. (should
  2932. (org-test-with-temp-text
  2933. "* H\n<<top>>\n#+KEYWORD: <point>[[top]]"
  2934. (org-open-at-point) t)))
  2935. (ert-deftest test-org/open-at-point/property ()
  2936. "Does `org-open-at-point' open link in property drawer?"
  2937. (should
  2938. (org-test-with-temp-text
  2939. "* Headline
  2940. :PROPERTIES:
  2941. :URL: <point>[[*Headline]]
  2942. :END:"
  2943. (org-open-at-point) t)))
  2944. (ert-deftest test-org/open-at-point/comment ()
  2945. "Does `org-open-at-point' open link in a commented line?"
  2946. (should
  2947. (org-test-with-temp-text
  2948. "<<top>>\n# <point>[[top]]"
  2949. (org-open-at-point) t))
  2950. (should
  2951. (org-test-with-temp-text
  2952. "* H\n<<top>>\n# <point>[[top]]"
  2953. (org-open-at-point) t)))
  2954. (ert-deftest test-org/open-at-point/inline-image ()
  2955. "Test `org-open-at-point' on nested links."
  2956. (should
  2957. (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
  2958. (org-open-at-point)
  2959. (bobp))))
  2960. (ert-deftest test-org/open-at-point/radio-target ()
  2961. "Test `org-open-at-point' on radio targets."
  2962. (should
  2963. (org-test-with-temp-text "<<<target>>> <point>target"
  2964. (org-update-radio-target-regexp)
  2965. (org-open-at-point)
  2966. (eq (org-element-type (org-element-context)) 'radio-target))))
  2967. (ert-deftest test-org/open-at-point/radio-target-shadowed ()
  2968. "Test `org-open-at-point' on shadowed radio targets."
  2969. (should
  2970. (org-test-with-temp-text
  2971. "<<<target shadowed>>> <<<target>>> <point>target shadowed"
  2972. (org-update-radio-target-regexp)
  2973. (org-open-at-point)
  2974. (string=
  2975. (org-element-property :value
  2976. (org-element-radio-target-parser))
  2977. "target shadowed"))))
  2978. (ert-deftest test-org/open-at-point/tag ()
  2979. "Test `org-open-at-point' on tags."
  2980. (should
  2981. (org-test-with-temp-text "* H :<point>tag:"
  2982. (catch :result
  2983. (cl-letf (((symbol-function 'org-tags-view)
  2984. (lambda (&rest _args) (throw :result t))))
  2985. (org-open-at-point)
  2986. nil))))
  2987. (should-not
  2988. (org-test-with-temp-text-in-file "* H<point> :tag:"
  2989. (catch :result
  2990. (cl-letf (((symbol-function 'org-tags-view)
  2991. (lambda (&rest _args) (throw :result t))))
  2992. ;; When point isn't on a tag it's going to try other things,
  2993. ;; possibly trying to open attachments which will return an
  2994. ;; error if there isn't an attachment. Suppress that error.
  2995. (ignore-errors
  2996. (org-open-at-point))
  2997. nil)))))
  2998. ;;; Node Properties
  2999. (ert-deftest test-org/accumulated-properties-in-drawers ()
  3000. "Ensure properties accumulate in subtree drawers."
  3001. (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
  3002. (org-babel-next-src-block)
  3003. (should (equal '(2 1) (org-babel-execute-src-block)))))
  3004. (ert-deftest test-org/custom-properties ()
  3005. "Test custom properties specifications."
  3006. ;; Standard test.
  3007. (should
  3008. (let ((org-custom-properties '("FOO")))
  3009. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  3010. (org-toggle-custom-properties-visibility)
  3011. (org-invisible-p2))))
  3012. ;; Properties are case-insensitive.
  3013. (should
  3014. (let ((org-custom-properties '("FOO")))
  3015. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
  3016. (org-toggle-custom-properties-visibility)
  3017. (org-invisible-p2))))
  3018. (should
  3019. (let ((org-custom-properties '("foo")))
  3020. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  3021. (org-toggle-custom-properties-visibility)
  3022. (org-invisible-p2))))
  3023. ;; Multiple custom properties in the same drawer.
  3024. (should
  3025. (let ((org-custom-properties '("FOO" "BAR")))
  3026. (org-test-with-temp-text
  3027. "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
  3028. (org-fold-reveal)
  3029. (org-toggle-custom-properties-visibility)
  3030. (and (org-invisible-p2)
  3031. (not (progn (forward-line) (org-invisible-p2)))
  3032. (progn (forward-line) (org-invisible-p2))))))
  3033. ;; Hide custom properties with an empty value.
  3034. (should
  3035. (let ((org-custom-properties '("FOO")))
  3036. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
  3037. (org-toggle-custom-properties-visibility)
  3038. (org-invisible-p2))))
  3039. ;; Do not hide fake properties.
  3040. (should-not
  3041. (let ((org-custom-properties '("FOO")))
  3042. (org-test-with-temp-text ":FOO: val\n"
  3043. (org-toggle-custom-properties-visibility)
  3044. (org-invisible-p2))))
  3045. (should-not
  3046. (let ((org-custom-properties '("A")))
  3047. (org-test-with-temp-text
  3048. "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
  3049. (org-fold-reveal)
  3050. (org-toggle-custom-properties-visibility)
  3051. (org-invisible-p2)))))
  3052. ;;; Mark Region
  3053. (ert-deftest test-org/mark-element ()
  3054. "Test `org-mark-element' specifications."
  3055. ;; Mark beginning and end of element.
  3056. (should
  3057. (equal '(t t)
  3058. (org-test-with-temp-text "Para<point>graph"
  3059. (org-mark-element)
  3060. (list (bobp) (= (mark) (point-max))))))
  3061. (should
  3062. (equal '(t t)
  3063. (org-test-with-temp-text "P1\n\nPara<point>graph\n\nP2"
  3064. (org-mark-element)
  3065. (list (looking-at "Paragraph")
  3066. (org-with-point-at (mark) (looking-at "P2"))))))
  3067. ;; Do not set mark past (point-max).
  3068. (should
  3069. (org-test-with-temp-text "Para<point>graph"
  3070. (narrow-to-region 2 6)
  3071. (org-mark-element)
  3072. (= 6 (mark)))))
  3073. (ert-deftest test-org/mark-subtree ()
  3074. "Test `org-mark-subtree' specifications."
  3075. ;; Error when point is before first headline.
  3076. (should-error
  3077. (org-test-with-temp-text "Paragraph\n* Headline\nBody"
  3078. (progn (transient-mark-mode 1)
  3079. (org-mark-subtree))))
  3080. ;; Without argument, mark current subtree.
  3081. (should
  3082. (equal
  3083. '(12 32)
  3084. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  3085. (progn (transient-mark-mode 1)
  3086. (forward-line 2)
  3087. (org-mark-subtree)
  3088. (list (region-beginning) (region-end))))))
  3089. ;; With an argument, move ARG up.
  3090. (should
  3091. (equal
  3092. '(1 32)
  3093. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  3094. (progn (transient-mark-mode 1)
  3095. (forward-line 2)
  3096. (org-mark-subtree 1)
  3097. (list (region-beginning) (region-end))))))
  3098. ;; Do not get fooled by inlinetasks.
  3099. (when (featurep 'org-inlinetask)
  3100. (should
  3101. (= 1
  3102. (org-test-with-temp-text "* Headline\n*************** Task\nContents"
  3103. (progn (transient-mark-mode 1)
  3104. (forward-line 1)
  3105. (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
  3106. (region-beginning)))))))
  3107. ;;; Miscellaneous
  3108. (ert-deftest test-org/sort-entries ()
  3109. "Test `org-sort-entries'."
  3110. ;; Sort alphabetically.
  3111. (should
  3112. (equal "\n* abc\n* def\n* xyz\n"
  3113. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  3114. (org-sort-entries nil ?a)
  3115. (buffer-string))))
  3116. (should
  3117. (equal "\n* xyz\n* def\n* abc\n"
  3118. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  3119. (org-sort-entries nil ?A)
  3120. (buffer-string))))
  3121. (should
  3122. (equal "\n* \n* klm\n* xyz\n"
  3123. (org-test-with-temp-text "\n* xyz\n* \n* klm\n"
  3124. (org-sort-entries nil ?a)
  3125. (buffer-string))))
  3126. ;; Sort numerically.
  3127. (should
  3128. (equal "\n* 1\n* 2\n* 10\n"
  3129. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  3130. (org-sort-entries nil ?n)
  3131. (buffer-string))))
  3132. (should
  3133. (equal "\n* 10\n* 2\n* 1\n"
  3134. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  3135. (org-sort-entries nil ?N)
  3136. (buffer-string))))
  3137. (should
  3138. (equal "\n* \n* 1\n* 2\n"
  3139. (org-test-with-temp-text "\n* 1\n* \n* 2\n"
  3140. (org-sort-entries nil ?n)
  3141. (buffer-string))))
  3142. ;; Sort by custom function.
  3143. (should
  3144. (equal "\n* b\n* aa\n* ccc\n"
  3145. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  3146. (org-sort-entries nil ?f
  3147. (lambda ()
  3148. (length (buffer-substring (point-at-bol)
  3149. (point-at-eol))))
  3150. #'<)
  3151. (buffer-string))))
  3152. (should
  3153. (equal "\n* ccc\n* aa\n* b\n"
  3154. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  3155. (org-sort-entries nil ?F
  3156. (lambda ()
  3157. (length (buffer-substring (point-at-bol)
  3158. (point-at-eol))))
  3159. #'<)
  3160. (buffer-string))))
  3161. ;; Sort by TODO keyword.
  3162. (should
  3163. (equal "\n* TODO h1\n* TODO h3\n* DONE h2\n"
  3164. (org-test-with-temp-text
  3165. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  3166. (org-sort-entries nil ?o)
  3167. (buffer-string))))
  3168. (should
  3169. (equal "\n* DONE h2\n* TODO h1\n* TODO h3\n"
  3170. (org-test-with-temp-text
  3171. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  3172. (org-sort-entries nil ?O)
  3173. (buffer-string))))
  3174. ;; Sort by priority.
  3175. (should
  3176. (equal "\n* [#A] h2\n* [#B] h3\n* [#C] h1\n"
  3177. (org-test-with-temp-text
  3178. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  3179. (org-sort-entries nil ?p)
  3180. (buffer-string))))
  3181. (should
  3182. (equal "\n* [#C] h1\n* [#B] h3\n* [#A] h2\n"
  3183. (org-test-with-temp-text
  3184. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  3185. (org-sort-entries nil ?P)
  3186. (buffer-string))))
  3187. ;; Sort by creation time.
  3188. (should
  3189. (equal "
  3190. * h3
  3191. [2017-05-08 Mon]
  3192. * h2
  3193. [2017-05-09 Tue]
  3194. * h1
  3195. [2018-05-09 Wed]
  3196. "
  3197. (org-test-with-temp-text
  3198. "
  3199. * h1
  3200. [2018-05-09 Wed]
  3201. * h2
  3202. [2017-05-09 Tue]
  3203. * h3
  3204. [2017-05-08 Mon]
  3205. "
  3206. (org-sort-entries nil ?c)
  3207. (buffer-string))))
  3208. ;; Sort by scheduled date.
  3209. (should
  3210. (equal "
  3211. * TODO h4
  3212. SCHEDULED: <2017-05-06 Sat>
  3213. * TODO h3
  3214. SCHEDULED: <2017-05-08 Mon>
  3215. * TODO h2
  3216. DEADLINE: <2017-05-09 Tue>
  3217. * TODO h1
  3218. DEADLINE: <2017-05-07 Sun>
  3219. "
  3220. (org-test-with-temp-text
  3221. "
  3222. * TODO h2
  3223. DEADLINE: <2017-05-09 Tue>
  3224. * TODO h1
  3225. DEADLINE: <2017-05-07 Sun>
  3226. * TODO h3
  3227. SCHEDULED: <2017-05-08 Mon>
  3228. * TODO h4
  3229. SCHEDULED: <2017-05-06 Sat>
  3230. "
  3231. (org-sort-entries nil ?s)
  3232. (buffer-string))))
  3233. ;; Sort by deadline date.
  3234. (should
  3235. (equal "
  3236. * TODO h1
  3237. DEADLINE: <2017-05-07 Sun>
  3238. * TODO h2
  3239. DEADLINE: <2017-05-09 Tue>
  3240. * TODO h3
  3241. SCHEDULED: <2017-05-08 Mon>
  3242. * TODO h4
  3243. SCHEDULED: <2017-05-06 Sat>
  3244. "
  3245. (org-test-with-temp-text
  3246. "
  3247. * TODO h2
  3248. DEADLINE: <2017-05-09 Tue>
  3249. * TODO h1
  3250. DEADLINE: <2017-05-07 Sun>
  3251. * TODO h3
  3252. SCHEDULED: <2017-05-08 Mon>
  3253. * TODO h4
  3254. SCHEDULED: <2017-05-06 Sat>
  3255. "
  3256. (org-sort-entries nil ?d)
  3257. (buffer-string))))
  3258. ;; Sort by any date/time
  3259. (should
  3260. (equal "
  3261. * TODO h4
  3262. SCHEDULED: <2017-05-06 Sat>
  3263. * TODO h1
  3264. DEADLINE: <2017-05-07 Sun>
  3265. * TODO h3
  3266. SCHEDULED: <2017-05-08 Mon>
  3267. * TODO h2
  3268. DEADLINE: <2017-05-09 Tue>
  3269. "
  3270. (org-test-with-temp-text
  3271. "
  3272. * TODO h2
  3273. DEADLINE: <2017-05-09 Tue>
  3274. * TODO h1
  3275. DEADLINE: <2017-05-07 Sun>
  3276. * TODO h3
  3277. SCHEDULED: <2017-05-08 Mon>
  3278. * TODO h4
  3279. SCHEDULED: <2017-05-06 Sat>
  3280. "
  3281. (org-sort-entries nil ?t)
  3282. (buffer-string))))
  3283. ;; Sort by clocking time.
  3284. (should
  3285. (equal "
  3286. * clocked h2
  3287. :LOGBOOK:
  3288. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3289. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  3290. :END:
  3291. * clocked h1
  3292. :LOGBOOK:
  3293. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3294. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  3295. :END:
  3296. "
  3297. (org-test-with-temp-text
  3298. "
  3299. * clocked h1
  3300. :LOGBOOK:
  3301. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3302. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  3303. :END:
  3304. * clocked h2
  3305. :LOGBOOK:
  3306. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3307. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  3308. :END:
  3309. "
  3310. (org-sort-entries nil ?k)
  3311. (buffer-string))))
  3312. ;; Preserve file local variables when sorting.
  3313. (should
  3314. (equal "\n* A\n* B\n# Local Variables:\n# foo: t\n# End:\n"
  3315. (org-test-with-temp-text
  3316. "\n* B\n* A\n# Local Variables:\n# foo: t\n# End:"
  3317. (org-sort-entries nil ?a)
  3318. (buffer-string)))))
  3319. (ert-deftest test-org/string-collate-greaterp ()
  3320. "Test `org-string-collate-greaterp' specifications."
  3321. (should (org-string-collate-greaterp "def" "abc"))
  3322. (should-not (org-string-collate-greaterp "abc" "def")))
  3323. (ert-deftest test-org/file-contents ()
  3324. "Test `org-file-contents' specifications."
  3325. ;; Open files.
  3326. (should
  3327. (string= "#+BIND: variable value
  3328. #+DESCRIPTION: l2
  3329. #+LANGUAGE: en
  3330. #+SELECT_TAGS: b
  3331. #+TITLE: b
  3332. #+PROPERTY: a 1
  3333. " (org-file-contents (expand-file-name "setupfile3.org"
  3334. (concat org-test-dir "examples/")))))
  3335. ;; Throw error when trying to access an invalid file.
  3336. (should-error (org-file-contents "this-file-must-not-exist"))
  3337. ;; Try to access an invalid file, but do not throw an error.
  3338. (should
  3339. (progn (org-file-contents "this-file-must-not-exist" :noerror) t))
  3340. ;; Open URL.
  3341. (should
  3342. (let ((org-resource-download-policy t))
  3343. (string= "foo"
  3344. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3345. (unwind-protect
  3346. ;; Simulate successful retrieval of a URL.
  3347. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3348. (lambda (&rest_)
  3349. (with-current-buffer buffer
  3350. (insert "HTTP/1.1 200 OK\n\nfoo"))
  3351. buffer)))
  3352. (org-file-contents "http://some-valid-url"))
  3353. (kill-buffer buffer))))))
  3354. ;; Throw error when trying to access an invalid URL.
  3355. (should-error
  3356. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3357. (unwind-protect
  3358. ;; Simulate unsuccessful retrieval of a URL.
  3359. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3360. (lambda (&rest_)
  3361. (with-current-buffer buffer
  3362. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3363. buffer)))
  3364. (org-file-contents "http://this-url-must-not-exist"))
  3365. (kill-buffer buffer))))
  3366. ;; Try to access an invalid URL, but do not throw an error.
  3367. (should-error
  3368. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3369. (unwind-protect
  3370. ;; Simulate unsuccessful retrieval of a URL.
  3371. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3372. (lambda (&rest_)
  3373. (with-current-buffer buffer
  3374. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3375. buffer)))
  3376. (org-file-contents "http://this-url-must-not-exist"))
  3377. (kill-buffer buffer))))
  3378. (should
  3379. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3380. (unwind-protect
  3381. ;; Simulate unsuccessful retrieval of a URL.
  3382. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3383. (lambda (&rest_)
  3384. (with-current-buffer buffer
  3385. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3386. buffer)))
  3387. (org-file-contents "http://this-url-must-not-exist" :noerror))
  3388. (kill-buffer buffer))
  3389. t)))
  3390. ;;; Navigation
  3391. (ert-deftest test-org/next-visible-heading ()
  3392. "Test `org-next-visible-heading' specifications."
  3393. ;; Move to the beginning of the next headline, taking into
  3394. ;; consideration ARG.
  3395. (should
  3396. (org-test-with-temp-text "* H1\n* H2"
  3397. (org-next-visible-heading 1)
  3398. (looking-at "\\* H2")))
  3399. (should
  3400. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3401. (org-next-visible-heading 2)
  3402. (looking-at "\\* H3")))
  3403. ;; Ignore invisible headlines.
  3404. (should
  3405. (org-test-with-temp-text "* H1\n** H2\n* H3"
  3406. (org-cycle)
  3407. (org-next-visible-heading 1)
  3408. (looking-at "\\* H3")))
  3409. ;; Move point between headlines, not on blank lines between.
  3410. (should
  3411. (org-test-with-temp-text "* H1\n** H2\n\n\n\n* H3"
  3412. (let ((org-cycle-separator-lines 1))
  3413. (org-cycle)
  3414. (org-next-visible-heading 1))
  3415. (looking-at "\\* H3")))
  3416. ;; Move at end of buffer when there is no more headline.
  3417. (should
  3418. (org-test-with-temp-text "* H1"
  3419. (org-next-visible-heading 1)
  3420. (eobp)))
  3421. (should
  3422. (org-test-with-temp-text "* H1\n* H2"
  3423. (org-next-visible-heading 2)
  3424. (eobp)))
  3425. ;; With a negative argument, move backwards.
  3426. (should
  3427. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3428. (org-next-visible-heading -1)
  3429. (looking-at "\\* H2")))
  3430. (should
  3431. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3432. (org-next-visible-heading -2)
  3433. (looking-at "\\* H1"))))
  3434. (ert-deftest test-org/previous-visible-heading ()
  3435. "Test `org-previous-visible-heading' specifications."
  3436. ;; Move to the beginning of the next headline, taking into
  3437. ;; consideration ARG.
  3438. (should
  3439. (org-test-with-temp-text "* H1\n<point>* H2"
  3440. (org-previous-visible-heading 1)
  3441. (looking-at "\\* H1")))
  3442. (should
  3443. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3444. (org-previous-visible-heading 2)
  3445. (looking-at "\\* H1")))
  3446. ;; Ignore invisible headlines.
  3447. (should
  3448. (org-test-with-temp-text "* H1\n** H2\n<point>* H3"
  3449. (org-overview)
  3450. (org-previous-visible-heading 1)
  3451. (looking-at "\\* H1")))
  3452. ;; Move point between headlines, not on blank lines between.
  3453. (should
  3454. (org-test-with-temp-text "* H1\n\n\n\n** H2\n<point>* H3"
  3455. (let ((org-cycle-separator-lines 1))
  3456. (org-overview)
  3457. (org-previous-visible-heading 1))
  3458. (looking-at "\\* H1")))
  3459. ;; Move at end of buffer when there is no more headline.
  3460. (should
  3461. (org-test-with-temp-text "* H1"
  3462. (org-previous-visible-heading 1)
  3463. (bobp)))
  3464. (should
  3465. (org-test-with-temp-text "* H1\n* <point>H2"
  3466. (org-previous-visible-heading 2)
  3467. (bobp)))
  3468. ;; Invisible parts may not start at a headline, i.e., when revealing
  3469. ;; parts of the buffer. Handle this.
  3470. (should
  3471. (org-test-with-temp-text "* Main\n** H1\nFoo\n** H2\nBar\n** H3\nBaz"
  3472. (org-overview)
  3473. (search-forward "H1")
  3474. (org-show-context 'minimal)
  3475. (org-cycle)
  3476. (search-forward "H3")
  3477. (org-show-context 'minimal)
  3478. ;; At this point, buffer displays, with point at "|",
  3479. ;;
  3480. ;; * Main
  3481. ;; ** H1
  3482. ;; Foo
  3483. ;; ** H3|
  3484. (org-previous-visible-heading 1)
  3485. (looking-at "\\*+ H1"))))
  3486. (ert-deftest test-org/forward-heading-same-level ()
  3487. "Test `org-forward-heading-same-level' specifications."
  3488. ;; Test navigation at top level, forward and backward.
  3489. (should
  3490. (equal "* H2"
  3491. (org-test-with-temp-text "* H1\n* H2"
  3492. (org-forward-heading-same-level 1)
  3493. (buffer-substring-no-properties (point) (line-end-position)))))
  3494. (should
  3495. (equal "* H1"
  3496. (org-test-with-temp-text "* H1\n<point>* H2"
  3497. (org-forward-heading-same-level -1)
  3498. (buffer-substring-no-properties (point) (line-end-position)))))
  3499. ;; Test navigation in a sub-tree, forward and backward.
  3500. (should
  3501. (equal "* H2"
  3502. (org-test-with-temp-text "* H1\n** H11\n** H12\n* H2"
  3503. (org-forward-heading-same-level 1)
  3504. (buffer-substring-no-properties (point) (line-end-position)))))
  3505. (should
  3506. (equal "* H1"
  3507. (org-test-with-temp-text "* H1\n** H11\n** H12\n<point>* H2"
  3508. (org-forward-heading-same-level -1)
  3509. (buffer-substring-no-properties (point) (line-end-position)))))
  3510. ;; Stop at first or last sub-heading.
  3511. (should-not
  3512. (equal "* H2"
  3513. (org-test-with-temp-text "* H1\n** H11\n<point>** H12\n* H2"
  3514. (org-forward-heading-same-level 1)
  3515. (buffer-substring-no-properties (point) (line-end-position)))))
  3516. (should-not
  3517. (equal "* H2"
  3518. (org-test-with-temp-text "* H1\n<point>** H11\n** H12\n* H2"
  3519. (org-forward-heading-same-level -1)
  3520. (buffer-substring-no-properties (point) (line-end-position)))))
  3521. ;; Allow multiple moves.
  3522. (should
  3523. (equal "* H3"
  3524. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3525. (org-forward-heading-same-level 2)
  3526. (buffer-substring-no-properties (point) (line-end-position)))))
  3527. (should
  3528. (equal "* H1"
  3529. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3530. (org-forward-heading-same-level -2)
  3531. (buffer-substring-no-properties (point) (line-end-position)))))
  3532. ;; Ignore spurious moves when first (or last) sibling is reached.
  3533. (should
  3534. (equal "** H3"
  3535. (org-test-with-temp-text "* First\n<point>** H1\n** H2\n** H3\n* Last"
  3536. (org-forward-heading-same-level 100)
  3537. (buffer-substring-no-properties (point) (line-end-position)))))
  3538. (should
  3539. (equal "** H1"
  3540. (org-test-with-temp-text "* First\n** H1\n** H2\n<point>** H3\n* Last"
  3541. (org-forward-heading-same-level -100)
  3542. (buffer-substring-no-properties (point) (line-end-position))))))
  3543. (ert-deftest test-org/end-of-meta-data ()
  3544. "Test `org-end-of-meta-data' specifications."
  3545. ;; Skip planning line.
  3546. (should
  3547. (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
  3548. (org-end-of-meta-data)
  3549. (eobp)))
  3550. ;; Skip properties drawer.
  3551. (should
  3552. (org-test-with-temp-text
  3553. "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
  3554. (org-end-of-meta-data)
  3555. (eobp)))
  3556. ;; Skip both.
  3557. (should
  3558. (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
  3559. (org-end-of-meta-data)
  3560. (eobp)))
  3561. ;; Nothing to skip, go to first line.
  3562. (should
  3563. (org-test-with-temp-text "* Headline\nContents"
  3564. (org-end-of-meta-data)
  3565. (looking-at "Contents")))
  3566. ;; With option argument, skip empty lines, regular drawers and
  3567. ;; clocking lines.
  3568. (should
  3569. (org-test-with-temp-text "* Headline\n\nContents"
  3570. (org-end-of-meta-data t)
  3571. (looking-at "Contents")))
  3572. (should
  3573. (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
  3574. (org-end-of-meta-data t)
  3575. (looking-at "Contents")))
  3576. (should
  3577. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
  3578. (org-end-of-meta-data t)
  3579. (looking-at "Contents")))
  3580. ;; Special case: do not skip incomplete drawers.
  3581. (should
  3582. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
  3583. (org-end-of-meta-data t)
  3584. (looking-at ":LOGBOOK:")))
  3585. ;; Special case: Be careful about consecutive headlines.
  3586. (should-not
  3587. (org-test-with-temp-text "* H1\n*H2\nContents"
  3588. (org-end-of-meta-data t)
  3589. (looking-at "Contents"))))
  3590. (ert-deftest test-org/shiftright-heading ()
  3591. "Test `org-shiftright' on headings."
  3592. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  3593. (should
  3594. (equal "* TODO a1\n** a2\n* DONE b1\n"
  3595. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3596. (org-shiftright)
  3597. (buffer-string))))
  3598. (should
  3599. (equal "* TODO a1\n** TODO a2\n* b1\n"
  3600. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3601. (let ((org-loop-over-headlines-in-active-region t))
  3602. (transient-mark-mode 1)
  3603. (push-mark (point) t t)
  3604. (search-forward "* DONE b1")
  3605. (org-shiftright))
  3606. (buffer-string))))
  3607. (should
  3608. (equal "* TODO a1\n** a2\n* b1\n"
  3609. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3610. (let ((org-loop-over-headlines-in-active-region 'start-level))
  3611. (transient-mark-mode 1)
  3612. (push-mark (point) t t)
  3613. (search-forward "* DONE b1")
  3614. (org-shiftright))
  3615. (buffer-string))))))
  3616. (ert-deftest test-org/beginning-of-line ()
  3617. "Test `org-beginning-of-line' specifications."
  3618. ;; Move to beginning of line. If current line in invisible, move to
  3619. ;; beginning of visible line instead.
  3620. (should
  3621. (org-test-with-temp-text "Some text\nSome other text<point>"
  3622. (org-beginning-of-line)
  3623. (bolp)))
  3624. (should
  3625. (org-test-with-temp-text "* H1\n** H2<point>"
  3626. (org-overview)
  3627. (org-beginning-of-line)
  3628. (= (line-beginning-position) 1)))
  3629. ;; With `visual-line-mode' active, move to beginning of visual line.
  3630. (should-not
  3631. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3632. (visual-line-mode)
  3633. (dotimes (_ 1000) (insert "very "))
  3634. (org-beginning-of-line)
  3635. (bolp)))
  3636. ;; In a wide headline, with `visual-line-mode', prefer going to the
  3637. ;; beginning of a visual line than to the logical beginning of line,
  3638. ;; even if special movement is active.
  3639. (should-not
  3640. (org-test-with-temp-text "* A <point>long headline"
  3641. (visual-line-mode)
  3642. (dotimes (_ 1000) (insert "very "))
  3643. (goto-char (point-max))
  3644. (org-beginning-of-line)
  3645. (bobp)))
  3646. (should-not
  3647. (org-test-with-temp-text "* A <point>long headline"
  3648. (visual-line-mode)
  3649. (dotimes (_ 1000) (insert "very "))
  3650. (goto-char (point-max))
  3651. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line))
  3652. (bobp)))
  3653. ;; At an headline with special movement, first move at beginning of
  3654. ;; title, then at the beginning of line, rinse, repeat.
  3655. (should
  3656. (org-test-with-temp-text "* TODO Headline<point>"
  3657. (let ((org-special-ctrl-a/e t))
  3658. (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
  3659. (progn (org-beginning-of-line) (bolp))
  3660. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3661. (should
  3662. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3663. (let ((org-special-ctrl-a/e t))
  3664. (org-beginning-of-line)
  3665. (looking-at "Headline"))))
  3666. (should
  3667. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3668. (let ((org-special-ctrl-a/e '(t . nil)))
  3669. (org-beginning-of-line)
  3670. (looking-at "Headline"))))
  3671. (should-not
  3672. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3673. (let ((org-special-ctrl-a/e '(nil . nil)))
  3674. (org-beginning-of-line)
  3675. (looking-at "Headline"))))
  3676. ;; At an headline with reversed movement, first move to beginning of
  3677. ;; line, then to the beginning of title.
  3678. (should
  3679. (org-test-with-temp-text "* TODO Headline<point>"
  3680. (let ((org-special-ctrl-a/e 'reversed)
  3681. (this-command last-command))
  3682. (and (progn (org-beginning-of-line) (bolp))
  3683. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3684. (should
  3685. (org-test-with-temp-text "* TODO Headline<point>"
  3686. (let ((org-special-ctrl-a/e '(reversed . nil))
  3687. (this-command last-command))
  3688. (and (progn (org-beginning-of-line) (bolp))
  3689. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3690. (should-not
  3691. (org-test-with-temp-text "* TODO Headline<point>"
  3692. (let ((org-special-ctrl-a/e '(t . nil))
  3693. (this-command last-command))
  3694. (and (progn (org-beginning-of-line) (bolp))
  3695. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3696. ;; At an item with special movement, first move after to beginning
  3697. ;; of title, then to the beginning of line, rinse, repeat.
  3698. (should
  3699. (org-test-with-temp-text "- [ ] Item<point>"
  3700. (let ((org-special-ctrl-a/e t))
  3701. (and (progn (org-beginning-of-line) (looking-at-p "Item"))
  3702. (progn (org-beginning-of-line) (bolp))
  3703. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3704. ;; At an item with reversed movement, first move to beginning of
  3705. ;; line, then to the beginning of title.
  3706. (should
  3707. (org-test-with-temp-text "- [X] Item<point>"
  3708. (let ((org-special-ctrl-a/e 'reversed)
  3709. (this-command last-command))
  3710. (and (progn (org-beginning-of-line) (bolp))
  3711. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3712. ;; Leave point before invisible characters at column 0.
  3713. (should
  3714. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3715. (let ((org-special-ctrl-a/e nil))
  3716. (org-beginning-of-line)
  3717. (bolp))))
  3718. (should
  3719. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3720. (let ((org-special-ctrl-a/e t))
  3721. (org-beginning-of-line)
  3722. (bolp))))
  3723. (should
  3724. (org-test-with-temp-text "[[http<point>://orgmode.org]]"
  3725. (visual-line-mode)
  3726. (org-beginning-of-line)
  3727. (bolp)))
  3728. ;; Special case: Do not error when the buffer contains only a single
  3729. ;; asterisk.
  3730. (should
  3731. (org-test-with-temp-text "*<point>"
  3732. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line) t)))
  3733. (should
  3734. (org-test-with-temp-text "*<point>"
  3735. (let ((org-special-ctrl-a/e nil)) (org-beginning-of-line) t))))
  3736. (ert-deftest test-org/end-of-line ()
  3737. "Test `org-end-of-line' specifications."
  3738. ;; Standard test.
  3739. (should
  3740. (org-test-with-temp-text "Some text\nSome other text"
  3741. (org-end-of-line)
  3742. (eolp)))
  3743. ;; With `visual-line-mode' active, move to end of visible line.
  3744. ;; However, never go past ellipsis.
  3745. (should-not
  3746. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3747. (visual-line-mode)
  3748. (dotimes (_ 1000) (insert "very "))
  3749. (goto-char (point-min))
  3750. (org-end-of-line)
  3751. (eolp)))
  3752. (should-not
  3753. (org-test-with-temp-text "* A short headline\nSome contents"
  3754. (visual-line-mode)
  3755. (org-overview)
  3756. (org-end-of-line)
  3757. (eobp)))
  3758. ;; In a wide headline, with `visual-line-mode', prefer going to end
  3759. ;; of visible line if tags, or end of line, are farther.
  3760. (should-not
  3761. (org-test-with-temp-text "* A <point>long headline"
  3762. (visual-line-mode)
  3763. (dotimes (_ 1000) (insert "very "))
  3764. (goto-char (point-min))
  3765. (org-end-of-line)
  3766. (eolp)))
  3767. (should-not
  3768. (org-test-with-temp-text "* A <point>long headline :tag:"
  3769. (visual-line-mode)
  3770. (dotimes (_ 1000) (insert "very "))
  3771. (goto-char (point-min))
  3772. (org-end-of-line)
  3773. (eolp)))
  3774. ;; At an headline without special movement, go to end of line.
  3775. ;; However, never go past ellipsis.
  3776. (should
  3777. (org-test-with-temp-text "* Headline2b :tag:\n"
  3778. (let ((org-special-ctrl-a/e nil))
  3779. (and (progn (org-end-of-line) (eolp))
  3780. (progn (org-end-of-line) (eolp))))))
  3781. (should
  3782. (org-test-with-temp-text "* Headline2b :tag:\n"
  3783. (let ((org-special-ctrl-a/e '(t . nil)))
  3784. (and (progn (org-end-of-line) (eolp))
  3785. (progn (org-end-of-line) (eolp))))))
  3786. (should
  3787. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3788. (org-overview)
  3789. (let ((org-special-ctrl-a/e nil))
  3790. (org-end-of-line)
  3791. (= 1 (line-beginning-position)))))
  3792. ;; At an headline with special movement, first move before tags,
  3793. ;; then at the end of line, rinse, repeat. However, never go past
  3794. ;; ellipsis.
  3795. (should
  3796. (org-test-with-temp-text "* Headline1 :tag:\n"
  3797. (let ((org-special-ctrl-a/e t))
  3798. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3799. (progn (org-end-of-line) (eolp))
  3800. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3801. (should
  3802. (org-test-with-temp-text "* Headline1 :tag:\n"
  3803. (let ((org-special-ctrl-a/e '(nil . t)))
  3804. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3805. (progn (org-end-of-line) (eolp))
  3806. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3807. (should-not
  3808. (org-test-with-temp-text "* Headline1 :tag:\n"
  3809. (let ((org-special-ctrl-a/e '(nil . nil)))
  3810. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3811. (progn (org-end-of-line) (eolp))
  3812. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3813. (should
  3814. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3815. (org-overview)
  3816. (let ((org-special-ctrl-a/e t))
  3817. (org-end-of-line)
  3818. (org-end-of-line)
  3819. (= 1 (line-beginning-position)))))
  3820. ;; At an headline, with reversed movement, first go to end of line,
  3821. ;; then before tags. However, never go past ellipsis.
  3822. (should
  3823. (org-test-with-temp-text "* Headline3 :tag:\n"
  3824. (let ((org-special-ctrl-a/e 'reversed)
  3825. (this-command last-command))
  3826. (and (progn (org-end-of-line) (eolp))
  3827. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3828. (should
  3829. (org-test-with-temp-text "* Headline3 :tag:\n"
  3830. (let ((org-special-ctrl-a/e '(nil . reversed))
  3831. (this-command last-command))
  3832. (and (progn (org-end-of-line) (eolp))
  3833. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3834. (should-not
  3835. (org-test-with-temp-text "* Headline3 :tag:\n"
  3836. (let ((org-special-ctrl-a/e '(nil . t))
  3837. (this-command last-command))
  3838. (and (progn (org-end-of-line) (eolp))
  3839. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3840. (should
  3841. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3842. (org-overview)
  3843. (let ((org-special-ctrl-a/e 'reversed))
  3844. (org-end-of-line)
  3845. (= 1 (line-beginning-position)))))
  3846. ;; At a block without hidden contents.
  3847. (should
  3848. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3849. (progn (org-end-of-line) (eolp))))
  3850. ;; At a block with hidden contents.
  3851. (should-not
  3852. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3853. (let ((org-special-ctrl-a/e t))
  3854. (org-fold-hide-block-toggle)
  3855. (org-end-of-line)
  3856. (eobp))))
  3857. ;; Get past invisible characters at the end of line.
  3858. (should
  3859. (org-test-with-temp-text "[[https://orgmode.org]]"
  3860. (org-end-of-line)
  3861. (eolp))))
  3862. (ert-deftest test-org/open-line ()
  3863. "Test `org-open-line' specifications."
  3864. ;; Call `open-line' outside of tables.
  3865. (should
  3866. (equal "\nText"
  3867. (org-test-with-temp-text "Text"
  3868. (org-open-line 1)
  3869. (buffer-string))))
  3870. ;; At a table, create a row above.
  3871. (should
  3872. (equal "\n| |\n| a |"
  3873. (org-test-with-temp-text "\n<point>| a |"
  3874. (org-open-line 1)
  3875. (buffer-string))))
  3876. ;; At the very first character of the buffer, also call `open-line'.
  3877. (should
  3878. (equal "\n| a |"
  3879. (org-test-with-temp-text "| a |"
  3880. (org-open-line 1)
  3881. (buffer-string))))
  3882. ;; Narrowing does not count.
  3883. (should
  3884. (equal "Text\n| |\n| a |"
  3885. (org-test-with-temp-text "Text\n<point>| a |"
  3886. (narrow-to-region (point) (point-max))
  3887. (org-open-line 1)
  3888. (widen)
  3889. (buffer-string)))))
  3890. (ert-deftest test-org/forward-sentence ()
  3891. "Test `org-forward-sentence' specifications."
  3892. ;; At the end of a table cell, move to the end of the next one.
  3893. (should
  3894. (org-test-with-temp-text "| a<point> | b |"
  3895. (org-forward-sentence)
  3896. (looking-at " |$")))
  3897. ;; Elsewhere in a cell, move to its end.
  3898. (should
  3899. (org-test-with-temp-text "| a<point>c | b |"
  3900. (org-forward-sentence)
  3901. (looking-at " | b |$")))
  3902. ;; Otherwise, simply call `forward-sentence'.
  3903. (should
  3904. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3905. (org-forward-sentence)
  3906. (looking-at " Sentence 2.")))
  3907. (should
  3908. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3909. (org-forward-sentence)
  3910. (org-forward-sentence)
  3911. (eobp)))
  3912. ;; At the end of an element, jump to the next one, without stopping
  3913. ;; on blank lines in-between.
  3914. (should
  3915. (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
  3916. (org-forward-sentence)
  3917. (eobp)))
  3918. ;; Headlines are considered to be sentences by themselves, even if
  3919. ;; they do not end with a full stop.
  3920. (should
  3921. (equal
  3922. "* Headline"
  3923. (org-test-with-temp-text "* <point>Headline\nSentence."
  3924. (org-forward-sentence)
  3925. (buffer-substring-no-properties (line-beginning-position) (point)))))
  3926. (should
  3927. (org-test-with-temp-text "* Headline<point>\nSentence."
  3928. (org-forward-sentence)
  3929. (eobp)))
  3930. (should
  3931. (org-test-with-temp-text "Sentence.<point>\n\n* Headline\n\nSentence 2."
  3932. (org-forward-sentence)
  3933. (and (org-at-heading-p) (eolp)))))
  3934. (ert-deftest test-org/backward-sentence ()
  3935. "Test `org-backward-sentence' specifications."
  3936. ;; At the beginning of a table cell, move to the beginning of the
  3937. ;; previous one.
  3938. (should
  3939. (org-test-with-temp-text "| a | <point>b |"
  3940. (org-backward-sentence)
  3941. (looking-at "a | b |$")))
  3942. ;; Elsewhere in a cell, move to its beginning.
  3943. (should
  3944. (org-test-with-temp-text "| a | b<point>c |"
  3945. (org-backward-sentence)
  3946. (looking-at "bc |$")))
  3947. ;; Otherwise, simply call `backward-sentence'.
  3948. (should
  3949. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3950. (org-backward-sentence)
  3951. (looking-at "Sentence 2.")))
  3952. (should
  3953. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3954. (org-backward-sentence)
  3955. (org-backward-sentence)
  3956. (bobp)))
  3957. ;; Make sure to hit the beginning of a sentence on the same line as
  3958. ;; an item.
  3959. (should
  3960. (org-test-with-temp-text "- Line 1\n line <point>2."
  3961. (org-backward-sentence)
  3962. (looking-at "Line 1"))))
  3963. (ert-deftest test-org/forward-paragraph ()
  3964. "Test `org-forward-paragraph' specifications."
  3965. ;; At end of buffer, do not return an error.
  3966. (should
  3967. (org-test-with-temp-text "Paragraph"
  3968. (goto-char (point-max))
  3969. (org-forward-paragraph)
  3970. t))
  3971. ;; Standard test.
  3972. (should
  3973. (= 2
  3974. (org-test-with-temp-text "P1\n\nP2"
  3975. (org-forward-paragraph)
  3976. (org-current-line))))
  3977. (should
  3978. (= 2
  3979. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  3980. (org-forward-paragraph)
  3981. (org-current-line))))
  3982. ;; Enter greater elements.
  3983. (should
  3984. (= 2
  3985. (org-test-with-temp-text "#+begin_center\nP1\n#+end_center\nP2"
  3986. (org-forward-paragraph)
  3987. (org-current-line))))
  3988. ;; Do not enter elements with invisible contents.
  3989. (should
  3990. (= 4
  3991. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  3992. (org-cycle)
  3993. (org-forward-paragraph)
  3994. (org-current-line))))
  3995. (should
  3996. (= 6
  3997. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\nP3"
  3998. (org-fold-hide-block-toggle)
  3999. (org-forward-paragraph)
  4000. (org-current-line))))
  4001. ;; On an item or a footnote definition, move past the first element
  4002. ;; inside, if any.
  4003. (should
  4004. (= 2
  4005. (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
  4006. (org-forward-paragraph)
  4007. (org-current-line))))
  4008. (should
  4009. (= 2
  4010. (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
  4011. (org-forward-paragraph)
  4012. (org-current-line))))
  4013. ;; On a table (resp. a property drawer) do not move through table
  4014. ;; rows (resp. node properties).
  4015. (should
  4016. (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
  4017. (org-forward-paragraph)
  4018. (looking-at "Paragraph")))
  4019. (should
  4020. (org-test-with-temp-text
  4021. "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
  4022. (org-forward-paragraph)
  4023. (looking-at "Paragraph")))
  4024. ;; Skip consecutive keywords, clocks and diary S-exps.
  4025. (should
  4026. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n"
  4027. (org-forward-paragraph)
  4028. (eobp)))
  4029. (should
  4030. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n"
  4031. (org-forward-paragraph)
  4032. (eobp)))
  4033. (should
  4034. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n"
  4035. (org-forward-paragraph)
  4036. (eobp)))
  4037. (should-not
  4038. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n"
  4039. (org-forward-paragraph)
  4040. (eobp)))
  4041. (should-not
  4042. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n"
  4043. (org-forward-paragraph)
  4044. (eobp)))
  4045. ;; In a plain list with one item every line, skip the whole list,
  4046. ;; even with point in the middle of the list.
  4047. (should
  4048. (org-test-with-temp-text "- A\n - B\n- C\n"
  4049. (org-forward-paragraph)
  4050. (eobp)))
  4051. (should
  4052. (org-test-with-temp-text "- A\n - <point>B\n- C\n"
  4053. (org-forward-paragraph)
  4054. (eobp)))
  4055. ;; On a comment, verse or source block, stop at "contents"
  4056. ;; boundaries and blank lines.
  4057. (should
  4058. (= 2
  4059. (org-test-with-temp-text "#+begin_src emacs-lisp\nL1\n\nL2\n#+end_src"
  4060. (org-forward-paragraph)
  4061. (org-current-line))))
  4062. (should
  4063. (= 3
  4064. (org-test-with-temp-text "#+begin_verse\n<point>L1\n\nL2\n#+end_verse"
  4065. (org-forward-paragraph)
  4066. (org-current-line))))
  4067. (should
  4068. (= 5
  4069. (org-test-with-temp-text "#+begin_comment\nL1\n\n<point>L2\n#+end_comment"
  4070. (org-forward-paragraph)
  4071. (org-current-line))))
  4072. ;; Being on an affiliated keyword shouldn't make any difference.
  4073. (should
  4074. (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
  4075. (org-forward-paragraph)
  4076. (eobp))))
  4077. (ert-deftest test-org/backward-paragraph ()
  4078. "Test `org-backward-paragraph' specifications."
  4079. ;; Do not error at beginning of buffer.
  4080. (should
  4081. (org-test-with-temp-text "Paragraph"
  4082. (org-backward-paragraph)
  4083. t))
  4084. ;; At blank lines at the very beginning of a buffer, move to
  4085. ;; point-min.
  4086. (should
  4087. (org-test-with-temp-text "\n\n<point>\n\nParagraph"
  4088. (org-backward-paragraph)
  4089. (bobp)))
  4090. ;; Regular test.
  4091. (should
  4092. (= 2
  4093. (org-test-with-temp-text "P1\n\nP2<point>"
  4094. (org-backward-paragraph)
  4095. (org-current-line))))
  4096. (should
  4097. (= 4
  4098. (org-test-with-temp-text "P1\n\nP2\n\nP3<point>"
  4099. (org-backward-paragraph)
  4100. (org-current-line))))
  4101. ;; Try to move on the line above current element.
  4102. (should
  4103. (= 2
  4104. (org-test-with-temp-text "\n\n<point>Paragraph"
  4105. (org-backward-paragraph)
  4106. (org-current-line))))
  4107. ;; Do not leave point in an invisible area.
  4108. (should
  4109. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  4110. (org-cycle)
  4111. (goto-char (point-max))
  4112. (beginning-of-line)
  4113. (org-backward-paragraph)
  4114. (bobp)))
  4115. (should
  4116. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\n"
  4117. (org-fold-hide-block-toggle)
  4118. (goto-char (point-max))
  4119. (org-backward-paragraph)
  4120. (bobp)))
  4121. ;; On the first element in an item or a footnote definition, jump
  4122. ;; before the footnote or the item.
  4123. (should
  4124. (org-test-with-temp-text "- line1<point>"
  4125. (org-backward-paragraph)
  4126. (bobp)))
  4127. (should
  4128. (org-test-with-temp-text "[fn:1] line1n<point>"
  4129. (org-backward-paragraph)
  4130. (bobp)))
  4131. ;; On the second element in an item or a footnote definition, jump
  4132. ;; to item or the definition.
  4133. (should
  4134. (= 2
  4135. (org-test-with-temp-text "- line1\n\n<point> line2"
  4136. (org-backward-paragraph)
  4137. (org-current-line))))
  4138. (should
  4139. (= 2
  4140. (org-test-with-temp-text "[fn:1] line1\n\n<point> line2"
  4141. (org-backward-paragraph)
  4142. (org-current-line))))
  4143. ;; On a table (resp. a property drawer), ignore table rows
  4144. ;; (resp. node properties).
  4145. (should
  4146. (org-test-with-temp-text "| a | b |\n| c | d |\n<point>P1"
  4147. (org-backward-paragraph)
  4148. (bobp)))
  4149. (should
  4150. (= 2
  4151. (org-test-with-temp-text
  4152. "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
  4153. (org-backward-paragraph)
  4154. (org-current-line))))
  4155. ;; In a plain list with one item every line, skip the whole list,
  4156. ;; even with point in the middle of the list.
  4157. (should
  4158. (org-test-with-temp-text "- A\n - B\n- C\n<point>"
  4159. (org-backward-paragraph)
  4160. (bobp)))
  4161. (should
  4162. (org-test-with-temp-text "- A\n - B\n- <point>C\n"
  4163. (org-backward-paragraph)
  4164. (bobp)))
  4165. ;; Skip consecutive keywords, clocks and diary S-exps.
  4166. (should
  4167. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n<point>"
  4168. (org-backward-paragraph)
  4169. (bobp)))
  4170. (should
  4171. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n<point>"
  4172. (org-backward-paragraph)
  4173. (bobp)))
  4174. (should
  4175. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n<point>"
  4176. (org-backward-paragraph)
  4177. (bobp)))
  4178. (should-not
  4179. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n<point>"
  4180. (org-backward-paragraph)
  4181. (bobp)))
  4182. (should-not
  4183. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n<point>"
  4184. (org-backward-paragraph)
  4185. (bobp)))
  4186. ;; On a comment, example, source and verse blocks, stop at blank
  4187. ;; lines.
  4188. (should
  4189. (= 1
  4190. (org-test-with-temp-text
  4191. "#+begin_comment\n<point>L1\n\nL2\n\nL3\n#+end_comment"
  4192. (org-backward-paragraph)
  4193. (org-current-line))))
  4194. (should
  4195. (= 2
  4196. (org-test-with-temp-text
  4197. "#+begin_verse\nL1\n\n<point>L2\n\nL3\n#+end_verse"
  4198. (org-backward-paragraph)
  4199. (org-current-line))))
  4200. (should
  4201. (= 3
  4202. (org-test-with-temp-text
  4203. "#+begin_src emacs-lisp\nL1\n\nL2\n\n<point>L3\n#+end_src"
  4204. (org-backward-paragraph)
  4205. (org-current-line))))
  4206. ;; When called from the opening line itself, however, move to
  4207. ;; beginning of block.
  4208. (should
  4209. (org-test-with-temp-text "#+begin_<point>example\nL1\n#+end_example"
  4210. (org-backward-paragraph)
  4211. (bobp)))
  4212. ;; On an empty heading, move above it.
  4213. (should
  4214. (org-test-with-temp-text "\n* <point>"
  4215. (org-backward-paragraph)
  4216. (bobp)))
  4217. (should
  4218. (org-test-with-temp-text "\n* \n<point>"
  4219. (org-backward-paragraph)
  4220. (bobp))))
  4221. (ert-deftest test-org/forward-element ()
  4222. "Test `org-forward-element' specifications."
  4223. ;; 1. At EOB: should error.
  4224. (org-test-with-temp-text "Some text\n"
  4225. (goto-char (point-max))
  4226. (should-error (org-forward-element)))
  4227. ;; 2. Standard move: expected to ignore blank lines.
  4228. (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
  4229. (org-forward-element)
  4230. (should (looking-at (regexp-quote "Second paragraph."))))
  4231. ;; 3. Headline tests.
  4232. (org-test-with-temp-text "
  4233. * Head 1
  4234. ** Head 1.1
  4235. *** Head 1.1.1
  4236. ** Head 1.2"
  4237. ;; 3.1. At an headline beginning: move to next headline at the
  4238. ;; same level.
  4239. (goto-line 3)
  4240. (org-forward-element)
  4241. (should (looking-at (regexp-quote "** Head 1.2")))
  4242. ;; 3.2. At an headline beginning: move to parent headline if no
  4243. ;; headline at the same level.
  4244. (goto-line 3)
  4245. (org-forward-element)
  4246. (should (looking-at (regexp-quote "** Head 1.2"))))
  4247. ;; 4. Greater element tests.
  4248. (org-test-with-temp-text
  4249. "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
  4250. ;; 4.1. At a greater element: expected to skip contents.
  4251. (org-forward-element)
  4252. (should (looking-at (regexp-quote "Outside.")))
  4253. ;; 4.2. At the end of greater element contents: expected to skip
  4254. ;; to the end of the greater element.
  4255. (goto-line 2)
  4256. (org-forward-element)
  4257. (should (looking-at (regexp-quote "Outside."))))
  4258. ;; 5. List tests.
  4259. (org-test-with-temp-text "
  4260. - item1
  4261. - sub1
  4262. - sub2
  4263. - sub3
  4264. Inner paragraph.
  4265. - item2
  4266. Outside."
  4267. ;; 5.1. At list top point: expected to move to the element after
  4268. ;; the list.
  4269. (goto-line 2)
  4270. (org-forward-element)
  4271. (should (looking-at (regexp-quote "Outside.")))
  4272. ;; 5.2. Special case: at the first line of a sub-list, but not at
  4273. ;; beginning of line, move to next item.
  4274. (goto-line 2)
  4275. (forward-char)
  4276. (org-forward-element)
  4277. (should (looking-at "- item2"))
  4278. (goto-line 4)
  4279. (forward-char)
  4280. (org-forward-element)
  4281. (should (looking-at " - sub2"))
  4282. ;; 5.3 At sub-list beginning: expected to move after the sub-list.
  4283. (goto-line 4)
  4284. (org-forward-element)
  4285. (should (looking-at (regexp-quote " Inner paragraph.")))
  4286. ;; 5.4. At sub-list end: expected to move outside the sub-list.
  4287. (goto-line 8)
  4288. (org-forward-element)
  4289. (should (looking-at (regexp-quote " Inner paragraph.")))
  4290. ;; 5.5. At an item: expected to move to next item, if any.
  4291. (goto-line 6)
  4292. (org-forward-element)
  4293. (should (looking-at " - sub3"))))
  4294. (ert-deftest test-org/backward-element ()
  4295. "Test `org-backward-element' specifications."
  4296. ;; 1. Should error at BOB.
  4297. (org-test-with-temp-text " \nParagraph."
  4298. (should-error (org-backward-element)))
  4299. ;; 2. Should move at BOB when called on the first element in buffer.
  4300. (should
  4301. (org-test-with-temp-text "\n#+TITLE: test"
  4302. (progn (forward-line)
  4303. (org-backward-element)
  4304. (bobp))))
  4305. ;; 3. Not at the beginning of an element: move at its beginning.
  4306. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  4307. (goto-line 3)
  4308. (end-of-line)
  4309. (org-backward-element)
  4310. (should (looking-at (regexp-quote "Paragraph2."))))
  4311. ;; 4. Headline tests.
  4312. (org-test-with-temp-text "
  4313. * Head 1
  4314. ** Head 1.1
  4315. *** Head 1.1.1
  4316. ** Head 1.2"
  4317. ;; 4.1. At an headline beginning: move to previous headline at the
  4318. ;; same level.
  4319. (goto-line 5)
  4320. (org-backward-element)
  4321. (should (looking-at (regexp-quote "** Head 1.1")))
  4322. ;; 4.2. At an headline beginning: move to parent headline if no
  4323. ;; headline at the same level.
  4324. (goto-line 3)
  4325. (org-backward-element)
  4326. (should (looking-at (regexp-quote "* Head 1")))
  4327. ;; 4.3. At the first top-level headline: should error.
  4328. (goto-line 2)
  4329. (should-error (org-backward-element)))
  4330. ;; 5. At beginning of first element inside a greater element:
  4331. ;; expected to move to greater element's beginning.
  4332. (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
  4333. (goto-line 3)
  4334. (org-backward-element)
  4335. (should (looking-at "#\\+BEGIN_CENTER")))
  4336. ;; 6. At the beginning of the first element in a section: should
  4337. ;; move back to headline, if any.
  4338. (should
  4339. (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
  4340. (progn (goto-char (point-max))
  4341. (beginning-of-line)
  4342. (org-backward-element)
  4343. (org-at-heading-p))))
  4344. ;; 7. List tests.
  4345. (org-test-with-temp-text "
  4346. - item1
  4347. - sub1
  4348. - sub2
  4349. - sub3
  4350. Inner paragraph.
  4351. - item2
  4352. Outside."
  4353. ;; 7.1. At beginning of sub-list: expected to move to the
  4354. ;; paragraph before it.
  4355. (goto-line 4)
  4356. (org-backward-element)
  4357. (should (looking-at "item1"))
  4358. ;; 7.2. At an item in a list: expected to move at previous item.
  4359. (goto-line 8)
  4360. (org-backward-element)
  4361. (should (looking-at " - sub2"))
  4362. (goto-line 12)
  4363. (org-backward-element)
  4364. (should (looking-at "- item1"))
  4365. ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
  4366. ;; beginning.
  4367. (goto-line 10)
  4368. (org-backward-element)
  4369. (should (looking-at " - sub1"))
  4370. (goto-line 15)
  4371. (org-backward-element)
  4372. (should (looking-at "- item1"))
  4373. ;; 7.4. At blank-lines before list end: expected to move to top
  4374. ;; item.
  4375. (goto-line 14)
  4376. (org-backward-element)
  4377. (should (looking-at "- item1"))))
  4378. (ert-deftest test-org/up-element ()
  4379. "Test `org-up-element' specifications."
  4380. ;; 1. At BOB or with no surrounding element: should error.
  4381. (org-test-with-temp-text "Paragraph."
  4382. (should-error (org-up-element)))
  4383. (org-test-with-temp-text "* Head1\n* Head2"
  4384. (goto-line 2)
  4385. (should-error (org-up-element)))
  4386. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  4387. (goto-line 3)
  4388. (should-error (org-up-element)))
  4389. ;; 2. At an headline: move to parent headline.
  4390. (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
  4391. (goto-line 3)
  4392. (org-up-element)
  4393. (should (looking-at "\\* Head1")))
  4394. ;; 3. Inside a greater element: move to greater element beginning.
  4395. (org-test-with-temp-text
  4396. "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
  4397. (goto-line 3)
  4398. (org-up-element)
  4399. (should (looking-at "#\\+BEGIN_CENTER")))
  4400. ;; 4. List tests.
  4401. (org-test-with-temp-text "* Top
  4402. - item1
  4403. - sub1
  4404. - sub2
  4405. Paragraph within sub2.
  4406. - item2"
  4407. ;; 4.1. Within an item: move to the item beginning.
  4408. (goto-line 8)
  4409. (org-up-element)
  4410. (should (looking-at " - sub2"))
  4411. ;; 4.2. At an item in a sub-list: move to parent item.
  4412. (goto-line 4)
  4413. (org-up-element)
  4414. (should (looking-at "- item1"))
  4415. ;; 4.3. At an item in top list: move to beginning of whole list.
  4416. (goto-line 10)
  4417. (org-up-element)
  4418. (should (looking-at "- item1"))
  4419. ;; 4.4. Special case. At very top point: should move to parent of
  4420. ;; list.
  4421. (goto-line 2)
  4422. (org-up-element)
  4423. (should (looking-at "\\* Top"))))
  4424. (ert-deftest test-org/down-element ()
  4425. "Test `org-down-element' specifications."
  4426. ;; Error when the element hasn't got a recursive type.
  4427. (org-test-with-temp-text "Paragraph."
  4428. (should-error (org-down-element)))
  4429. ;; Error when the element has no contents
  4430. (org-test-with-temp-text "* Headline"
  4431. (should-error (org-down-element)))
  4432. ;; When at a plain-list, move to first item.
  4433. (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
  4434. (goto-line 2)
  4435. (org-down-element)
  4436. (should (looking-at " - Item 1.1")))
  4437. (org-test-with-temp-text "#+NAME: list\n- Item 1"
  4438. (org-down-element)
  4439. (should (looking-at " Item 1")))
  4440. ;; When at a table, move to first row
  4441. (org-test-with-temp-text "#+NAME: table\n| a | b |"
  4442. (org-down-element)
  4443. (should (looking-at " a | b |")))
  4444. ;; Otherwise, move inside the greater element.
  4445. (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
  4446. (org-down-element)
  4447. (should (looking-at "Paragraph"))))
  4448. (ert-deftest test-org/drag-element-backward ()
  4449. "Test `org-drag-element-backward' specifications."
  4450. ;; Standard test.
  4451. (should
  4452. (equal
  4453. "#+key2: val2\n#+key1: val1\n#+key3: val3"
  4454. (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
  4455. (org-drag-element-backward)
  4456. (buffer-string))))
  4457. (should
  4458. (equal
  4459. "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
  4460. (org-test-with-temp-text
  4461. "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
  4462. (org-drag-element-backward)
  4463. (buffer-string))))
  4464. ;; Preserve blank lines.
  4465. (should
  4466. (equal "Paragraph 2\n\n\nPara1\n\nPara3"
  4467. (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
  4468. (org-drag-element-backward)
  4469. (buffer-string))))
  4470. ;; Preserve column.
  4471. (should
  4472. (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
  4473. (org-drag-element-backward)
  4474. (looking-at-p "2")))
  4475. ;; Error when trying to move first element of buffer.
  4476. (should-error
  4477. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4478. (org-drag-element-backward))
  4479. :type 'user-error)
  4480. ;; Error when trying to swap nested elements.
  4481. (should-error
  4482. (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
  4483. (org-drag-element-backward))
  4484. :type 'user-error)
  4485. ;; Error when trying to swap an headline element and a non-headline
  4486. ;; element.
  4487. (should-error
  4488. (org-test-with-temp-text "Test.\n<point>* Head 1"
  4489. (org-drag-element-backward))
  4490. :type 'error)
  4491. ;; Error when called before first element.
  4492. (should-error
  4493. (org-test-with-temp-text "\n<point>"
  4494. (org-drag-element-backward))
  4495. :type 'user-error)
  4496. ;; Preserve visibility of elements and their contents.
  4497. (should
  4498. (equal '((63 . 82) (26 . 48))
  4499. (let ((org-fold-core-style 'text-properties))
  4500. (org-test-with-temp-text
  4501. "
  4502. #+BEGIN_CENTER
  4503. Text.
  4504. #+END_CENTER
  4505. - item 1
  4506. #+BEGIN_QUOTE
  4507. Text.
  4508. #+END_QUOTE"
  4509. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4510. (search-backward "- item 1")
  4511. (org-drag-element-backward)
  4512. (let (regions)
  4513. (goto-char (point-min))
  4514. (while (< (point) (point-max))
  4515. (let ((region (org-fold-get-region-at-point)))
  4516. (if (not region)
  4517. (goto-char (org-fold-next-folding-state-change))
  4518. (goto-char (cdr region))
  4519. (push region regions))))
  4520. regions)))))
  4521. (should
  4522. (equal '((26 . 48) (63 . 82))
  4523. (let ((org-fold-core-style 'overlays))
  4524. (org-test-with-temp-text
  4525. "
  4526. #+BEGIN_CENTER
  4527. Text.
  4528. #+END_CENTER
  4529. - item 1
  4530. #+BEGIN_QUOTE
  4531. Text.
  4532. #+END_QUOTE"
  4533. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4534. (search-backward "- item 1")
  4535. (org-drag-element-backward)
  4536. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4537. (overlays-in (point-min) (point-max)))))))
  4538. ;; Pathological case: handle call with point in blank lines right
  4539. ;; after a headline.
  4540. (should
  4541. (equal "* H2\n\n* H1\nText\n"
  4542. (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
  4543. (org-drag-element-backward)
  4544. (buffer-string)))))
  4545. (ert-deftest test-org/drag-element-forward ()
  4546. "Test `org-drag-element-forward' specifications."
  4547. ;; 1. Error when trying to move first element of buffer.
  4548. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4549. (goto-line 3)
  4550. (should-error (org-drag-element-forward)))
  4551. ;; 2. Error when trying to swap nested elements.
  4552. (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
  4553. (forward-line)
  4554. (should-error (org-drag-element-forward)))
  4555. ;; 3. Error when trying to swap a non-headline element and an
  4556. ;; headline.
  4557. (org-test-with-temp-text "Test.\n* Head 1"
  4558. (should-error (org-drag-element-forward)))
  4559. ;; 4. Error when called before first element.
  4560. (should-error
  4561. (org-test-with-temp-text "\n"
  4562. (forward-line)
  4563. (org-drag-element-backward))
  4564. :type 'user-error)
  4565. ;; 5. Otherwise, swap elements, preserving column and blank lines
  4566. ;; between elements.
  4567. (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
  4568. (search-forward "graph")
  4569. (org-drag-element-forward)
  4570. (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
  4571. (should (looking-at " 1")))
  4572. ;; 5. Preserve visibility of elements and their contents.
  4573. (let ((org-fold-core-style 'text-properties))
  4574. (org-test-with-temp-text
  4575. "
  4576. #+BEGIN_CENTER
  4577. Text.
  4578. #+END_CENTER
  4579. - item 1
  4580. #+BEGIN_QUOTE
  4581. Text.
  4582. #+END_QUOTE"
  4583. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4584. (search-backward "#+BEGIN_CENTER")
  4585. (org-drag-element-forward)
  4586. (should
  4587. (equal
  4588. '((63 . 82) (26 . 48))
  4589. (let (regions)
  4590. (goto-char (point-min))
  4591. (while (< (point) (point-max))
  4592. (let ((region (org-fold-get-region-at-point)))
  4593. (if (not region)
  4594. (goto-char (org-fold-next-folding-state-change))
  4595. (goto-char (cdr region))
  4596. (push region regions))))
  4597. regions)))))
  4598. (let ((org-fold-core-style 'overlays))
  4599. (org-test-with-temp-text
  4600. "
  4601. #+BEGIN_CENTER
  4602. Text.
  4603. #+END_CENTER
  4604. - item 1
  4605. #+BEGIN_QUOTE
  4606. Text.
  4607. #+END_QUOTE"
  4608. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4609. (search-backward "#+BEGIN_CENTER")
  4610. (org-drag-element-forward)
  4611. (should
  4612. (equal
  4613. '((26 . 48) (63 . 82))
  4614. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4615. (overlays-in (point-min) (point-max))))))))
  4616. (ert-deftest test-org/next-block ()
  4617. "Test `org-next-block' specifications."
  4618. ;; Regular test.
  4619. (should
  4620. (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  4621. (org-next-block 1)
  4622. (looking-at "#\\+BEGIN_CENTER")))
  4623. ;; Ignore case.
  4624. (should
  4625. (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
  4626. (let ((case-fold-search nil))
  4627. (org-next-block 1)
  4628. (looking-at "#\\+begin_center"))))
  4629. ;; Ignore current line.
  4630. (should
  4631. (org-test-with-temp-text
  4632. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
  4633. (org-next-block 1)
  4634. (looking-at "#\\+BEGIN_CENTER")))
  4635. ;; Throw an error when no block is found.
  4636. (should-error
  4637. (org-test-with-temp-text "Paragraph"
  4638. (org-next-block 1)))
  4639. ;; With an argument, skip many blocks at once.
  4640. (should
  4641. (org-test-with-temp-text
  4642. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4643. (org-next-block 2)
  4644. (looking-at "#\\+BEGIN_QUOTE")))
  4645. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4646. (should
  4647. (org-test-with-temp-text
  4648. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4649. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4650. (looking-at "#\\+BEGIN_QUOTE")))
  4651. ;; Optional argument is also case-insensitive.
  4652. (should
  4653. (org-test-with-temp-text
  4654. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
  4655. (let ((case-fold-search nil))
  4656. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4657. (looking-at "#\\+begin_quote")))))
  4658. (ert-deftest test-org/insert-structure-template ()
  4659. "Test `org-insert-structure-template'."
  4660. ;; Test in empty buffer.
  4661. (should
  4662. (string= "#+begin_foo\n#+end_foo\n"
  4663. (org-test-with-temp-text ""
  4664. (org-insert-structure-template "foo")
  4665. (buffer-string))))
  4666. ;; Test with multiple lines in buffer.
  4667. (should
  4668. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4669. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4670. (transient-mark-mode 1)
  4671. (org-mark-element)
  4672. (org-insert-structure-template "foo")
  4673. (buffer-string))))
  4674. ;; Mark only the current line.
  4675. (should
  4676. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4677. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4678. (transient-mark-mode 1)
  4679. (set-mark (point-min))
  4680. (end-of-line)
  4681. (org-insert-structure-template "foo")
  4682. (buffer-string))))
  4683. ;; Middle of paragraph.
  4684. (should
  4685. (string= "p1\n#+begin_foo\np2\n#+end_foo\np3"
  4686. (org-test-with-temp-text "p1\n<point>p2\np3"
  4687. (set-mark (line-beginning-position))
  4688. (end-of-line)
  4689. (activate-mark)
  4690. (org-insert-structure-template "foo")
  4691. (buffer-string))))
  4692. ;; Test with text in buffer, no region, no final newline.
  4693. (should
  4694. (string= "#+begin_foo\nI'm a paragraph.\n#+end_foo\n"
  4695. (org-test-with-temp-text "I'm a paragraph."
  4696. (org-mark-element)
  4697. (org-insert-structure-template "foo")
  4698. (buffer-string))))
  4699. ;; Test with text in buffer and region set.
  4700. (should
  4701. (string= "#+begin_foo\nI'm a paragraph\n\nI'm a second paragrah\n#+end_foo\n"
  4702. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragrah"
  4703. (set-mark (point))
  4704. (goto-char (point-max))
  4705. (org-insert-structure-template "foo")
  4706. (buffer-string))))
  4707. ;; Test with example escaping.
  4708. (should
  4709. (string= "#+begin_example\n,* Heading\n#+end_example\n"
  4710. (org-test-with-temp-text "* Heading"
  4711. (org-mark-element)
  4712. (org-insert-structure-template "example")
  4713. (buffer-string))))
  4714. ;; Test with indentation.
  4715. (should
  4716. (string= " #+begin_foo\n This is a paragraph\n #+end_foo\n"
  4717. (org-test-with-temp-text " This is a paragraph"
  4718. (org-mark-element)
  4719. (org-insert-structure-template "foo")
  4720. (buffer-string))))
  4721. (should
  4722. (string= " #+begin_foo\n Line 1\n Line2\n #+end_foo\n"
  4723. (org-test-with-temp-text " Line 1\n Line2"
  4724. (org-mark-element)
  4725. (org-insert-structure-template "foo")
  4726. (buffer-string))))
  4727. ;; Test point location.
  4728. (should
  4729. (string= "#+begin_foo\n"
  4730. (org-test-with-temp-text ""
  4731. (org-insert-structure-template "foo")
  4732. (buffer-substring (point-min) (point)))))
  4733. (should
  4734. (string= "#+begin_src "
  4735. (org-test-with-temp-text ""
  4736. (org-insert-structure-template "src")
  4737. (buffer-substring (point-min) (point))))))
  4738. (ert-deftest test-org/previous-block ()
  4739. "Test `org-previous-block' specifications."
  4740. ;; Regular test.
  4741. (should
  4742. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
  4743. (org-previous-block 1)
  4744. (looking-at "#\\+BEGIN_CENTER")))
  4745. ;; Ignore case.
  4746. (should
  4747. (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
  4748. (let ((case-fold-search nil))
  4749. (org-previous-block 1)
  4750. (looking-at "#\\+begin_center"))))
  4751. ;; Ignore current line.
  4752. (should
  4753. (org-test-with-temp-text
  4754. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
  4755. (org-previous-block 1)
  4756. (looking-at "#\\+BEGIN_QUOTE")))
  4757. ;; Throw an error when no block is found.
  4758. (should-error
  4759. (org-test-with-temp-text "Paragraph<point>"
  4760. (org-previous-block 1)))
  4761. ;; With an argument, skip many blocks at once.
  4762. (should
  4763. (org-test-with-temp-text
  4764. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4765. (org-previous-block 2)
  4766. (looking-at "#\\+BEGIN_CENTER")))
  4767. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4768. (should
  4769. (org-test-with-temp-text
  4770. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4771. (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4772. (looking-at "#\\+BEGIN_QUOTE")))
  4773. ;; Optional argument is also case-insensitive.
  4774. (should
  4775. (org-test-with-temp-text
  4776. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
  4777. (let ((case-fold-search nil))
  4778. (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4779. (looking-at "#\\+begin_quote")))))
  4780. ;;; Outline structure
  4781. (ert-deftest test-org/demote ()
  4782. "Test `org-demote' specifications."
  4783. ;; Add correct number of stars according to `org-odd-levels-only'.
  4784. (should
  4785. (= 2
  4786. (org-test-with-temp-text "* H"
  4787. (let ((org-odd-levels-only nil)) (org-demote))
  4788. (org-current-level))))
  4789. (should
  4790. (= 3
  4791. (org-test-with-temp-text "* H"
  4792. (let ((org-odd-levels-only t)) (org-demote))
  4793. (org-current-level))))
  4794. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4795. (should
  4796. (org-test-with-temp-text "* H :tag:"
  4797. (let ((org-tags-column 10)
  4798. (org-auto-align-tags t)
  4799. (org-odd-levels-only nil))
  4800. (org-demote))
  4801. (org-move-to-column 10)
  4802. (looking-at-p ":tag:$")))
  4803. (should-not
  4804. (org-test-with-temp-text "* H :tag:"
  4805. (let ((org-tags-column 10)
  4806. (org-auto-align-tags nil)
  4807. (org-odd-levels-only nil))
  4808. (org-demote))
  4809. (org-move-to-column 10)
  4810. (looking-at-p ":tag:$")))
  4811. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4812. ;; info and property drawers accordingly.
  4813. (should
  4814. (= 3
  4815. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4816. (let ((org-odd-levels-only nil)
  4817. (org-adapt-indentation t))
  4818. (org-demote))
  4819. (forward-line)
  4820. (org-get-indentation))))
  4821. (should
  4822. (= 3
  4823. (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4824. (let ((org-odd-levels-only nil)
  4825. (org-adapt-indentation t))
  4826. (org-demote))
  4827. (forward-line)
  4828. (org-get-indentation))))
  4829. (should-not
  4830. (= 3
  4831. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4832. (let ((org-odd-levels-only nil)
  4833. (org-adapt-indentation nil))
  4834. (org-demote))
  4835. (forward-line)
  4836. (org-get-indentation))))
  4837. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4838. ;; section accordingly. Ignore, however, footnote definitions and
  4839. ;; inlinetasks boundaries.
  4840. (should
  4841. (= 3
  4842. (org-test-with-temp-text "* H\n Paragraph"
  4843. (let ((org-odd-levels-only nil)
  4844. (org-adapt-indentation t))
  4845. (org-demote))
  4846. (forward-line)
  4847. (org-get-indentation))))
  4848. (should
  4849. (= 2
  4850. (org-test-with-temp-text "* H\n Paragraph"
  4851. (let ((org-odd-levels-only nil)
  4852. (org-adapt-indentation nil))
  4853. (org-demote))
  4854. (forward-line)
  4855. (org-get-indentation))))
  4856. (should
  4857. (zerop
  4858. (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
  4859. (let ((org-odd-levels-only nil)
  4860. (org-adapt-indentation t))
  4861. (org-demote))
  4862. (goto-char (point-max))
  4863. (org-get-indentation))))
  4864. (should
  4865. (= 3
  4866. (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
  4867. (let ((org-odd-levels-only nil)
  4868. (org-adapt-indentation t))
  4869. (org-demote))
  4870. (goto-char (point-max))
  4871. (org-get-indentation))))
  4872. (when (featurep 'org-inlinetask)
  4873. (should
  4874. (zerop
  4875. (let ((org-inlinetask-min-level 5)
  4876. (org-adapt-indentation t))
  4877. (org-test-with-temp-text "* H\n***** I\n***** END"
  4878. (org-demote)
  4879. (forward-line)
  4880. (org-get-indentation))))))
  4881. (when (featurep 'org-inlinetask)
  4882. (should
  4883. (= 3
  4884. (let ((org-inlinetask-min-level 5)
  4885. (org-adapt-indentation t))
  4886. (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
  4887. (org-demote)
  4888. (forward-line 2)
  4889. (org-get-indentation))))))
  4890. ;; When `org-adapt-indentation' is non-nil, log drawers are
  4891. ;; adjusted.
  4892. (should
  4893. (equal
  4894. "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4895. (org-test-with-temp-text "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4896. (let ((org-odd-levels-only nil)
  4897. (org-adapt-indentation t))
  4898. (org-demote))
  4899. (buffer-string))))
  4900. (should
  4901. (equal
  4902. "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4903. (org-test-with-temp-text "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4904. (let ((org-odd-levels-only nil)
  4905. (org-adapt-indentation 'headline-data))
  4906. (org-demote))
  4907. (buffer-string))))
  4908. (should
  4909. (equal
  4910. "** H\n :LOGBOOK:\n - a\n :END:"
  4911. (org-test-with-temp-text "* H\n:LOGBOOK:\n- a\n:END:"
  4912. (let ((org-odd-levels-only nil)
  4913. (org-adapt-indentation t))
  4914. (org-demote))
  4915. (buffer-string))))
  4916. ;; Ignore contents of source blocks or example blocks when
  4917. ;; indentation should be preserved (through
  4918. ;; `org-src-preserve-indentation' or "-i" flag).
  4919. (should-not
  4920. (zerop
  4921. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4922. (let ((org-adapt-indentation t)
  4923. (org-src-preserve-indentation nil))
  4924. (org-demote))
  4925. (forward-line 2)
  4926. (org-get-indentation))))
  4927. (should
  4928. (zerop
  4929. (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
  4930. (let ((org-adapt-indentation t)
  4931. (org-src-preserve-indentation t))
  4932. (org-demote))
  4933. (forward-line 2)
  4934. (org-get-indentation))))
  4935. (should
  4936. (zerop
  4937. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4938. (let ((org-adapt-indentation t)
  4939. (org-src-preserve-indentation t))
  4940. (org-demote))
  4941. (forward-line 2)
  4942. (org-get-indentation))))
  4943. (should
  4944. (zerop
  4945. (org-test-with-temp-text
  4946. "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
  4947. (let ((org-adapt-indentation t)
  4948. (org-src-preserve-indentation nil))
  4949. (org-demote))
  4950. (forward-line 2)
  4951. (org-get-indentation)))))
  4952. (ert-deftest test-org/promote ()
  4953. "Test `org-promote' specifications."
  4954. ;; Return an error if headline is to be promoted to level 0, unless
  4955. ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
  4956. ;; headline becomes a comment.
  4957. (should-error
  4958. (org-test-with-temp-text "* H"
  4959. (let ((org-allow-promoting-top-level-subtree nil)) (org-promote))))
  4960. (should
  4961. (equal "# H"
  4962. (org-test-with-temp-text "* H"
  4963. (let ((org-allow-promoting-top-level-subtree t)) (org-promote))
  4964. (buffer-string))))
  4965. ;; Remove correct number of stars according to
  4966. ;; `org-odd-levels-only'.
  4967. (should
  4968. (= 2
  4969. (org-test-with-temp-text "*** H"
  4970. (let ((org-odd-levels-only nil)) (org-promote))
  4971. (org-current-level))))
  4972. (should
  4973. (= 1
  4974. (org-test-with-temp-text "*** H"
  4975. (let ((org-odd-levels-only t)) (org-promote))
  4976. (org-current-level))))
  4977. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4978. (should
  4979. (org-test-with-temp-text "** H :tag:"
  4980. (let ((org-tags-column 10)
  4981. (org-auto-align-tags t)
  4982. (org-odd-levels-only nil))
  4983. (org-promote))
  4984. (org-move-to-column 10)
  4985. (looking-at-p ":tag:$")))
  4986. (should-not
  4987. (org-test-with-temp-text "** H :tag:"
  4988. (let ((org-tags-column 10)
  4989. (org-auto-align-tags nil)
  4990. (org-odd-levels-only nil))
  4991. (org-promote))
  4992. (org-move-to-column 10)
  4993. (looking-at-p ":tag:$")))
  4994. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4995. ;; info and property drawers.
  4996. (should
  4997. (= 2
  4998. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4999. (let ((org-odd-levels-only nil)
  5000. (org-adapt-indentation t))
  5001. (org-promote))
  5002. (forward-line)
  5003. (org-get-indentation))))
  5004. (should
  5005. (= 2
  5006. (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  5007. (let ((org-odd-levels-only nil)
  5008. (org-adapt-indentation t))
  5009. (org-promote))
  5010. (forward-line)
  5011. (org-get-indentation))))
  5012. (should-not
  5013. (= 2
  5014. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  5015. (let ((org-odd-levels-only nil)
  5016. (org-adapt-indentation nil))
  5017. (org-promote))
  5018. (forward-line)
  5019. (org-get-indentation))))
  5020. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  5021. ;; section accordingly. Ignore, however, footnote definitions and
  5022. ;; inlinetasks boundaries.
  5023. (should
  5024. (= 2
  5025. (org-test-with-temp-text "** H\n Paragraph"
  5026. (let ((org-odd-levels-only nil)
  5027. (org-adapt-indentation t))
  5028. (org-promote))
  5029. (forward-line)
  5030. (org-get-indentation))))
  5031. (should-not
  5032. (= 2
  5033. (org-test-with-temp-text "** H\n Paragraph"
  5034. (let ((org-odd-levels-only nil)
  5035. (org-adapt-indentation nil))
  5036. (org-promote))
  5037. (forward-line)
  5038. (org-get-indentation))))
  5039. (should
  5040. (= 2
  5041. (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
  5042. (let ((org-odd-levels-only nil)
  5043. (org-adapt-indentation t))
  5044. (org-promote))
  5045. (forward-line)
  5046. (org-get-indentation))))
  5047. (when (featurep 'org-inlinetask)
  5048. (should
  5049. (zerop
  5050. (let ((org-inlinetask-min-level 5)
  5051. (org-adapt-indentation t))
  5052. (org-test-with-temp-text "** H\n***** I\n***** END"
  5053. (org-promote)
  5054. (forward-line)
  5055. (org-get-indentation))))))
  5056. (when (featurep 'org-inlinetask)
  5057. (should
  5058. (= 2
  5059. (let ((org-inlinetask-min-level 5)
  5060. (org-adapt-indentation t))
  5061. (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
  5062. (org-promote)
  5063. (forward-line 2)
  5064. (org-get-indentation))))))
  5065. ;; Give up shifting if it would break document's structure
  5066. ;; otherwise.
  5067. (should
  5068. (= 3
  5069. (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
  5070. (let ((org-odd-levels-only nil)
  5071. (org-adapt-indentation t))
  5072. (org-promote))
  5073. (forward-line)
  5074. (org-get-indentation))))
  5075. (should
  5076. (= 3
  5077. (org-test-with-temp-text "** H\n Paragraph\n * list."
  5078. (let ((org-odd-levels-only nil)
  5079. (org-adapt-indentation t))
  5080. (org-promote))
  5081. (forward-line)
  5082. (org-get-indentation))))
  5083. ;; When `org-adapt-indentation' is non-nil, log drawers are
  5084. ;; adjusted.
  5085. (should
  5086. (equal
  5087. "* H\n :LOGBOOK:\n - a\n :END:\n b"
  5088. (org-test-with-temp-text "** H\n :LOGBOOK:\n - a\n :END:\n b"
  5089. (let ((org-odd-levels-only nil)
  5090. (org-adapt-indentation t))
  5091. (org-promote))
  5092. (buffer-string))))
  5093. (should
  5094. (equal
  5095. "* H\n :LOGBOOK:\n - a\n :END:\n b"
  5096. (org-test-with-temp-text "** H\n :LOGBOOK:\n - a\n :END:\n b"
  5097. (let ((org-odd-levels-only nil)
  5098. (org-adapt-indentation 'headline-data))
  5099. (org-promote))
  5100. (buffer-string))))
  5101. (should
  5102. (equal
  5103. "* H\n:LOGBOOK:\n- a\n:END:"
  5104. (org-test-with-temp-text "** H\n:LOGBOOK:\n- a\n:END:"
  5105. (let ((org-odd-levels-only nil)
  5106. (org-adapt-indentation t))
  5107. (org-promote))
  5108. (buffer-string))))
  5109. (should
  5110. (equal
  5111. "# H\n:LOGBOOK:\n- a\n:END:"
  5112. (org-test-with-temp-text "* H\n:LOGBOOK:\n- a\n:END:"
  5113. (let ((org-odd-levels-only nil)
  5114. (org-allow-promoting-top-level-subtree t)
  5115. (org-adapt-indentation t))
  5116. (org-promote))
  5117. (buffer-string))))
  5118. ;; Ignore contents of source blocks or example blocks when
  5119. ;; indentation should be preserved (through
  5120. ;; `org-src-preserve-indentation' or "-i" flag).
  5121. (should-not
  5122. (zerop
  5123. (org-test-with-temp-text
  5124. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  5125. (let ((org-adapt-indentation t)
  5126. (org-src-preserve-indentation nil)
  5127. (org-odd-levels-only nil))
  5128. (org-promote))
  5129. (forward-line)
  5130. (org-get-indentation))))
  5131. (should
  5132. (zerop
  5133. (org-test-with-temp-text
  5134. "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
  5135. (let ((org-adapt-indentation t)
  5136. (org-src-preserve-indentation t)
  5137. (org-odd-levels-only nil))
  5138. (org-promote))
  5139. (forward-line)
  5140. (org-get-indentation))))
  5141. (should
  5142. (zerop
  5143. (org-test-with-temp-text
  5144. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  5145. (let ((org-adapt-indentation t)
  5146. (org-src-preserve-indentation t)
  5147. (org-odd-levels-only nil))
  5148. (org-promote))
  5149. (forward-line)
  5150. (org-get-indentation))))
  5151. (should
  5152. (zerop
  5153. (org-test-with-temp-text
  5154. "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
  5155. (let ((org-adapt-indentation t)
  5156. (org-src-preserve-indentation nil)
  5157. (org-odd-levels-only nil))
  5158. (org-promote))
  5159. (forward-line)
  5160. (org-get-indentation)))))
  5161. (ert-deftest test-org/org-get-valid-level ()
  5162. "Test function `org-get-valid-level' specifications."
  5163. (let ((org-odd-levels-only nil))
  5164. (should (equal 1 (org-get-valid-level 0 0)))
  5165. (should (equal 1 (org-get-valid-level 0 1)))
  5166. (should (equal 2 (org-get-valid-level 0 2)))
  5167. (should (equal 3 (org-get-valid-level 0 3)))
  5168. (should (equal 1 (org-get-valid-level 1 0)))
  5169. (should (equal 2 (org-get-valid-level 1 1)))
  5170. (should (equal 23 (org-get-valid-level 1 22)))
  5171. (should (equal 1 (org-get-valid-level 1 -1)))
  5172. (should (equal 1 (org-get-valid-level 2 -1))))
  5173. (let ((org-odd-levels-only t))
  5174. (should (equal 1 (org-get-valid-level 0 0)))
  5175. (should (equal 1 (org-get-valid-level 0 1)))
  5176. (should (equal 3 (org-get-valid-level 0 2)))
  5177. (should (equal 5 (org-get-valid-level 0 3)))
  5178. (should (equal 1 (org-get-valid-level 1 0)))
  5179. (should (equal 3 (org-get-valid-level 1 1)))
  5180. (should (equal 3 (org-get-valid-level 2 1)))
  5181. (should (equal 5 (org-get-valid-level 3 1)))
  5182. (should (equal 5 (org-get-valid-level 4 1)))
  5183. (should (equal 43 (org-get-valid-level 1 21)))
  5184. (should (equal 1 (org-get-valid-level 1 -1)))
  5185. (should (equal 1 (org-get-valid-level 2 -1)))
  5186. (should (equal 1 (org-get-valid-level 3 -1)))
  5187. (should (equal 3 (org-get-valid-level 4 -1)))
  5188. (should (equal 3 (org-get-valid-level 5 -1)))))
  5189. ;;; Planning
  5190. (ert-deftest test-org/at-planning-p ()
  5191. "Test `org-at-planning-p' specifications."
  5192. ;; Regular test.
  5193. (should
  5194. (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
  5195. (org-at-planning-p)))
  5196. (should-not
  5197. (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
  5198. (org-at-planning-p)))
  5199. ;; Correctly find planning attached to inlinetasks.
  5200. (when (featurep 'org-inlinetask)
  5201. (should
  5202. (org-test-with-temp-text
  5203. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
  5204. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  5205. (should-not
  5206. (org-test-with-temp-text
  5207. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  5208. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  5209. (should-not
  5210. (org-test-with-temp-text
  5211. "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  5212. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  5213. (should-not
  5214. (org-test-with-temp-text
  5215. "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
  5216. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
  5217. (ert-deftest test-org/add-planning-info ()
  5218. "Test `org-add-planning-info'."
  5219. ;; Create deadline when `org-adapt-indentation' is non-nil.
  5220. (should
  5221. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5222. (org-test-with-temp-text "* H\nParagraph<point>"
  5223. (let ((org-adapt-indentation t))
  5224. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5225. (replace-regexp-in-string
  5226. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5227. nil nil 1))))
  5228. ;; Create deadline when `org-adapt-indentation' is nil.
  5229. (should
  5230. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  5231. (org-test-with-temp-text "* H\nParagraph<point>"
  5232. (let ((org-adapt-indentation nil))
  5233. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5234. (replace-regexp-in-string
  5235. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5236. nil nil 1))))
  5237. ;; Update deadline when `org-adapt-indentation' is non-nil.
  5238. (should
  5239. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5240. (org-test-with-temp-text "\
  5241. * H
  5242. DEADLINE: <2015-06-24 Wed>
  5243. Paragraph<point>"
  5244. (let ((org-adapt-indentation t))
  5245. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5246. (replace-regexp-in-string
  5247. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5248. nil nil 1))))
  5249. ;; Update deadline when `org-adapt-indentation' is nil.
  5250. (should
  5251. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  5252. (org-test-with-temp-text "\
  5253. * H
  5254. DEADLINE: <2015-06-24 Wed>
  5255. Paragraph<point>"
  5256. (let ((org-adapt-indentation nil))
  5257. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5258. (replace-regexp-in-string
  5259. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5260. nil nil 1))))
  5261. ;; Schedule when `org-adapt-indentation' is non-nil.
  5262. (should
  5263. (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
  5264. (org-test-with-temp-text "* H\nParagraph<point>"
  5265. (let ((org-adapt-indentation t))
  5266. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  5267. (replace-regexp-in-string
  5268. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5269. nil nil 1))))
  5270. ;; Schedule when `org-adapt-indentation' is nil.
  5271. (should
  5272. (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
  5273. (org-test-with-temp-text "* H\nParagraph<point>"
  5274. (let ((org-adapt-indentation nil))
  5275. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  5276. (replace-regexp-in-string
  5277. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5278. nil nil 1))))
  5279. ;; Add deadline when scheduled.
  5280. (should
  5281. (equal "\
  5282. * H
  5283. DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
  5284. Paragraph"
  5285. (org-test-with-temp-text "\
  5286. * H
  5287. SCHEDULED: <2015-06-24 Wed>
  5288. Paragraph<point>"
  5289. (let ((org-adapt-indentation t))
  5290. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5291. (replace-regexp-in-string
  5292. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5293. nil nil 1))))
  5294. ;; Remove middle entry.
  5295. (should
  5296. (equal "\
  5297. * H
  5298. CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
  5299. Paragraph"
  5300. (org-test-with-temp-text "\
  5301. * H
  5302. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  5303. Paragraph<point>"
  5304. (let ((org-adapt-indentation t))
  5305. (org-add-planning-info nil nil 'deadline))
  5306. (replace-regexp-in-string
  5307. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  5308. nil nil 1))))
  5309. ;; Remove last entry and then middle entry (order should not
  5310. ;; matter).
  5311. (should
  5312. (equal "\
  5313. * H
  5314. CLOSED: [2015-06-24]
  5315. Paragraph"
  5316. (org-test-with-temp-text "\
  5317. * H
  5318. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  5319. Paragraph<point>"
  5320. (let ((org-adapt-indentation t))
  5321. (org-add-planning-info nil nil 'scheduled 'deadline))
  5322. (replace-regexp-in-string
  5323. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  5324. nil nil 1))))
  5325. ;; Remove closed when `org-adapt-indentation' is non-nil.
  5326. (should
  5327. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5328. (org-test-with-temp-text "\
  5329. * H
  5330. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  5331. Paragraph<point>"
  5332. (let ((org-adapt-indentation t))
  5333. (org-add-planning-info nil nil 'closed))
  5334. (replace-regexp-in-string
  5335. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5336. nil nil 1))))
  5337. (should
  5338. (equal "* H\n Paragraph"
  5339. (org-test-with-temp-text "\
  5340. * H
  5341. CLOSED: [2015-06-25 Thu]
  5342. Paragraph<point>"
  5343. (let ((org-adapt-indentation t))
  5344. (org-add-planning-info nil nil 'closed))
  5345. (replace-regexp-in-string
  5346. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5347. nil nil 1))))
  5348. ;; Remove closed when `org-adapt-indentation' is nil.
  5349. (should
  5350. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  5351. (org-test-with-temp-text "\
  5352. * H
  5353. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  5354. Paragraph<point>"
  5355. (let ((org-adapt-indentation nil))
  5356. (org-add-planning-info nil nil 'closed))
  5357. (replace-regexp-in-string
  5358. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5359. nil nil 1))))
  5360. (should
  5361. (equal "* H\nParagraph"
  5362. (org-test-with-temp-text "\
  5363. * H
  5364. CLOSED: [2015-06-25 Thu]
  5365. Paragraph<point>"
  5366. (let ((org-adapt-indentation nil))
  5367. (org-add-planning-info nil nil 'closed))
  5368. (replace-regexp-in-string
  5369. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5370. nil nil 1))))
  5371. ;; Remove closed entry and delete empty line.
  5372. (should
  5373. (equal "\
  5374. * H
  5375. Paragraph"
  5376. (org-test-with-temp-text "\
  5377. * H
  5378. CLOSED: [2015-06-24 Wed]
  5379. Paragraph<point>"
  5380. (let ((org-adapt-indentation t))
  5381. (org-add-planning-info nil nil 'closed))
  5382. (replace-regexp-in-string
  5383. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5384. nil nil 1))))
  5385. ;; Remove one entry and update another.
  5386. (should
  5387. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5388. (org-test-with-temp-text "\
  5389. * H
  5390. SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
  5391. Paragraph<point>"
  5392. (let ((org-adapt-indentation t))
  5393. (org-add-planning-info 'deadline "<2015-06-25 Thu>" 'scheduled))
  5394. (replace-regexp-in-string
  5395. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5396. nil nil 1)))))
  5397. (ert-deftest test-org/deadline ()
  5398. "Test `org-deadline' specifications."
  5399. ;; Insert a new value or replace existing one.
  5400. (should
  5401. (equal "* H\nDEADLINE: <2012-03-29>"
  5402. (org-test-with-temp-text "* H"
  5403. (let ((org-adapt-indentation nil)
  5404. (org-last-inserted-timestamp nil))
  5405. (org-deadline nil "<2012-03-29 Tue>"))
  5406. (replace-regexp-in-string
  5407. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5408. nil nil 1))))
  5409. (should
  5410. (equal "* H\nDEADLINE: <2014-03-04>"
  5411. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5412. (let ((org-adapt-indentation nil)
  5413. (org-last-inserted-timestamp nil))
  5414. (org-deadline nil "<2014-03-04 Thu>"))
  5415. (replace-regexp-in-string
  5416. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5417. nil nil 1))))
  5418. ;; Accept delta time, e.g., "+2d".
  5419. (should
  5420. (equal "* H\nDEADLINE: <2015-03-04>"
  5421. (org-test-at-time "2014-03-04"
  5422. (org-test-with-temp-text "* H"
  5423. (let ((org-adapt-indentation nil)
  5424. (org-last-inserted-timestamp nil))
  5425. (org-deadline nil "+1y"))
  5426. (replace-regexp-in-string
  5427. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5428. ;; Preserve repeater.
  5429. (should
  5430. (equal "* H\nDEADLINE: <2012-03-29 +2y>"
  5431. (org-test-with-temp-text "* H"
  5432. (let ((org-adapt-indentation nil)
  5433. (org-last-inserted-timestamp nil))
  5434. (org-deadline nil "<2012-03-29 Tue +2y>"))
  5435. (replace-regexp-in-string
  5436. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5437. ;; Preserve warning period.
  5438. (should
  5439. (equal "* H\nDEADLINE: <2021-07-20 -1d>"
  5440. (org-test-with-temp-text "* H"
  5441. (let ((org-adapt-indentation nil)
  5442. (org-last-inserted-timestamp nil))
  5443. (org-deadline nil "<2021-07-20 Tue -1d>"))
  5444. (replace-regexp-in-string
  5445. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5446. (should
  5447. (equal "* H\nDEADLINE: <2021-07-20 +1m -3d>"
  5448. (org-test-with-temp-text "* H"
  5449. (let ((org-adapt-indentation nil)
  5450. (org-last-inserted-timestamp nil))
  5451. (org-deadline nil "<2021-07-20 Tue +1m -3d>"))
  5452. (replace-regexp-in-string
  5453. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5454. ;; Remove CLOSED keyword, if any.
  5455. (should
  5456. (equal "* H\nDEADLINE: <2012-03-29>"
  5457. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  5458. (let ((org-adapt-indentation nil)
  5459. (org-last-inserted-timestamp nil))
  5460. (org-deadline nil "<2012-03-29 Tue>"))
  5461. (replace-regexp-in-string
  5462. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5463. ;; With C-u argument, remove DEADLINE keyword.
  5464. (should
  5465. (equal "* H\n"
  5466. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5467. (let ((org-adapt-indentation nil)
  5468. (org-last-inserted-timestamp nil))
  5469. (org-deadline '(4)))
  5470. (buffer-string))))
  5471. (should
  5472. (equal "* H"
  5473. (org-test-with-temp-text "* H"
  5474. (let ((org-adapt-indentation nil)
  5475. (org-last-inserted-timestamp nil))
  5476. (org-deadline '(4)))
  5477. (buffer-string))))
  5478. ;; With C-u C-u argument, prompt for a delay cookie.
  5479. (should
  5480. (equal "* H\nDEADLINE: <2012-03-29 -705d>"
  5481. (cl-letf (((symbol-function 'org-read-date)
  5482. (lambda (&rest _args)
  5483. (org-time-string-to-time "2014-03-04"))))
  5484. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5485. (let ((org-adapt-indentation nil)
  5486. (org-last-inserted-timestamp nil))
  5487. (org-deadline '(16)))
  5488. (buffer-string)))))
  5489. (should-error
  5490. (cl-letf (((symbol-function 'org-read-date)
  5491. (lambda (&rest _args)
  5492. (org-time-string-to-time "2014-03-04"))))
  5493. (org-test-with-temp-text "* H"
  5494. (let ((org-adapt-indentation nil)
  5495. (org-last-inserted-timestamp nil))
  5496. (org-deadline '(16)))
  5497. (buffer-string))))
  5498. ;; When a region is active and
  5499. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5500. ;; same value in all headlines in region.
  5501. (should
  5502. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5503. (org-test-with-temp-text "* H1\n* H2"
  5504. (let ((org-adapt-indentation nil)
  5505. (org-last-inserted-timestamp nil)
  5506. (org-loop-over-headlines-in-active-region t))
  5507. (transient-mark-mode 1)
  5508. (push-mark (point) t t)
  5509. (goto-char (point-max))
  5510. (org-deadline nil "2012-03-29"))
  5511. (replace-regexp-in-string
  5512. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5513. (should-not
  5514. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5515. (org-test-with-temp-text "* H1\n* H2"
  5516. (let ((org-adapt-indentation nil)
  5517. (org-last-inserted-timestamp nil)
  5518. (org-loop-over-headlines-in-active-region nil))
  5519. (transient-mark-mode 1)
  5520. (push-mark (point) t t)
  5521. (goto-char (point-max))
  5522. (org-deadline nil "2012-03-29"))
  5523. (replace-regexp-in-string
  5524. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5525. (ert-deftest test-org/schedule ()
  5526. "Test `org-schedule' specifications."
  5527. ;; Insert a new value or replace existing one.
  5528. (should
  5529. (equal "* H\nSCHEDULED: <2012-03-29>"
  5530. (org-test-with-temp-text "* H"
  5531. (let ((org-adapt-indentation nil)
  5532. (org-last-inserted-timestamp nil))
  5533. (org-schedule nil "<2012-03-29 Tue>"))
  5534. (replace-regexp-in-string
  5535. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5536. nil nil 1))))
  5537. (should
  5538. (equal "* H\nSCHEDULED: <2014-03-04>"
  5539. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5540. (let ((org-adapt-indentation nil)
  5541. (org-last-inserted-timestamp nil))
  5542. (org-schedule nil "<2014-03-04 Thu>"))
  5543. (replace-regexp-in-string
  5544. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5545. nil nil 1))))
  5546. ;; Accept delta time, e.g., "+2d".
  5547. (should
  5548. (equal "* H\nSCHEDULED: <2015-03-04>"
  5549. (org-test-at-time "2014-03-04"
  5550. (org-test-with-temp-text "* H"
  5551. (let ((org-adapt-indentation nil)
  5552. (org-last-inserted-timestamp nil))
  5553. (org-schedule nil "+1y"))
  5554. (replace-regexp-in-string
  5555. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5556. ;; Preserve repeater.
  5557. (should
  5558. (equal "* H\nSCHEDULED: <2012-03-29 +2y>"
  5559. (org-test-with-temp-text "* H"
  5560. (let ((org-adapt-indentation nil)
  5561. (org-last-inserted-timestamp nil))
  5562. (org-schedule nil "<2012-03-29 Tue +2y>"))
  5563. (replace-regexp-in-string
  5564. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5565. ;; Remove CLOSED keyword, if any.
  5566. (should
  5567. (equal "* H\nSCHEDULED: <2012-03-29>"
  5568. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  5569. (let ((org-adapt-indentation nil)
  5570. (org-last-inserted-timestamp nil))
  5571. (org-schedule nil "<2012-03-29 Tue>"))
  5572. (replace-regexp-in-string
  5573. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5574. ;; With C-u argument, remove SCHEDULED keyword.
  5575. (should
  5576. (equal "* H\n"
  5577. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5578. (let ((org-adapt-indentation nil)
  5579. (org-last-inserted-timestamp nil))
  5580. (org-schedule '(4)))
  5581. (buffer-string))))
  5582. (should
  5583. (equal "* H"
  5584. (org-test-with-temp-text "* H"
  5585. (let ((org-adapt-indentation nil)
  5586. (org-last-inserted-timestamp nil))
  5587. (org-schedule '(4)))
  5588. (buffer-string))))
  5589. ;; With C-u C-u argument, prompt for a delay cookie.
  5590. (should
  5591. (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
  5592. (cl-letf (((symbol-function 'org-read-date)
  5593. (lambda (&rest _args)
  5594. (org-time-string-to-time "2014-03-04"))))
  5595. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5596. (let ((org-adapt-indentation nil)
  5597. (org-last-inserted-timestamp nil))
  5598. (org-schedule '(16)))
  5599. (buffer-string)))))
  5600. (should-error
  5601. (cl-letf (((symbol-function 'org-read-date)
  5602. (lambda (&rest _args)
  5603. (org-time-string-to-time "2014-03-04"))))
  5604. (org-test-with-temp-text "* H"
  5605. (let ((org-adapt-indentation nil)
  5606. (org-last-inserted-timestamp nil))
  5607. (org-schedule '(16)))
  5608. (buffer-string))))
  5609. ;; When a region is active and
  5610. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5611. ;; same value in all headlines in region.
  5612. (should
  5613. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5614. (org-test-with-temp-text "* H1\n* H2"
  5615. (let ((org-adapt-indentation nil)
  5616. (org-last-inserted-timestamp nil)
  5617. (org-loop-over-headlines-in-active-region t))
  5618. (transient-mark-mode 1)
  5619. (push-mark (point) t t)
  5620. (goto-char (point-max))
  5621. (org-schedule nil "2012-03-29"))
  5622. (replace-regexp-in-string
  5623. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5624. (should-not
  5625. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5626. (org-test-with-temp-text "* H1\n* H2"
  5627. (let ((org-adapt-indentation nil)
  5628. (org-last-inserted-timestamp nil)
  5629. (org-loop-over-headlines-in-active-region nil))
  5630. (transient-mark-mode 1)
  5631. (push-mark (point) t t)
  5632. (goto-char (point-max))
  5633. (org-schedule nil "2012-03-29"))
  5634. (replace-regexp-in-string
  5635. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5636. (should
  5637. ;; check if a repeater survives re-scheduling.
  5638. (string-match-p
  5639. "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
  5640. (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
  5641. (let ((org-adapt-indentation nil)
  5642. (org-last-inserted-timestamp nil))
  5643. (org-schedule nil "2017-02-01"))
  5644. (buffer-string)))))
  5645. ;;; Property API
  5646. (ert-deftest test-org/buffer-property-keys ()
  5647. "Test `org-buffer-property-keys' specifications."
  5648. ;; Retrieve properties across siblings.
  5649. (should
  5650. (equal '("A" "B")
  5651. (org-test-with-temp-text "
  5652. * H1
  5653. :PROPERTIES:
  5654. :A: 1
  5655. :END:
  5656. * H2
  5657. :PROPERTIES:
  5658. :B: 1
  5659. :END:"
  5660. (org-buffer-property-keys))))
  5661. ;; Retrieve properties across children.
  5662. (should
  5663. (equal '("A" "B")
  5664. (org-test-with-temp-text "
  5665. * H1
  5666. :PROPERTIES:
  5667. :A: 1
  5668. :END:
  5669. ** H2
  5670. :PROPERTIES:
  5671. :B: 1
  5672. :END:"
  5673. (org-buffer-property-keys))))
  5674. ;; Retrieve muliple properties in the same drawer.
  5675. (should
  5676. (equal '("A" "B")
  5677. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5678. (org-buffer-property-keys))))
  5679. ;; Ignore extension symbol in property name.
  5680. (should
  5681. (equal '("A")
  5682. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5683. (org-buffer-property-keys))))
  5684. ;; Add bare property if xxx_ALL property is there
  5685. (should
  5686. (equal '("A" "B" "B_ALL")
  5687. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B_ALL: foo bar\n:END:"
  5688. (org-buffer-property-keys))))
  5689. ;; Add bare property if xxx_ALL property is there - check dupes
  5690. (should
  5691. (equal '("A" "B" "B_ALL")
  5692. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:B_ALL: foo bar\n:END:"
  5693. (org-buffer-property-keys))))
  5694. ;; Retrieve properties from #+PROPERTY keyword lines
  5695. (should
  5696. (equal '("A" "C")
  5697. (org-test-with-temp-text "#+PROPERTY: C foo\n* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5698. (org-buffer-property-keys))))
  5699. ;; Retrieve properties from #+PROPERTY keyword lines - make sure an _ALL property also
  5700. ;; adds the bare property
  5701. (should
  5702. (equal '("A" "C" "C_ALL")
  5703. (org-test-with-temp-text "#+PROPERTY: C_ALL foo bar\n* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5704. (org-buffer-property-keys))))
  5705. ;; With non-nil COLUMNS, extract property names from columns.
  5706. (should
  5707. (equal '("A" "B")
  5708. (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
  5709. (org-buffer-property-keys nil nil t))))
  5710. (should
  5711. (equal '("A" "B" "COLUMNS")
  5712. (org-test-with-temp-text
  5713. "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
  5714. (org-buffer-property-keys nil nil t))))
  5715. ;; In COLUMNS, ignore title and summary-type.
  5716. (should
  5717. (equal '("A")
  5718. (org-test-with-temp-text "#+COLUMNS: %A(Foo)"
  5719. (org-buffer-property-keys nil nil t))))
  5720. (should
  5721. (equal '("A")
  5722. (org-test-with-temp-text "#+COLUMNS: %A{Foo}"
  5723. (org-buffer-property-keys nil nil t))))
  5724. (should
  5725. (equal '("A")
  5726. (org-test-with-temp-text "#+COLUMNS: %A(Foo){Bar}"
  5727. (org-buffer-property-keys nil nil t)))))
  5728. (ert-deftest test-org/property-values ()
  5729. "Test `org-property-values' specifications."
  5730. ;; Regular test.
  5731. (should
  5732. (equal '("2" "1")
  5733. (org-test-with-temp-text
  5734. "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
  5735. (org-property-values "A"))))
  5736. ;; Ignore empty values.
  5737. (should-not
  5738. (org-test-with-temp-text
  5739. "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
  5740. (org-property-values "A")))
  5741. ;; Take into consideration extended values.
  5742. (should
  5743. (equal '("1 2")
  5744. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5745. (org-property-values "A")))))
  5746. (ert-deftest test-org/set-property ()
  5747. "Test `org-set-property' specifications."
  5748. (should
  5749. (equal
  5750. ":PROPERTIES:\n:TEST: t\n:END:\n"
  5751. (org-test-with-temp-text ""
  5752. (let ((org-property-format "%s %s"))
  5753. (org-set-property "TEST" "t"))
  5754. (buffer-string))))
  5755. (should
  5756. (equal
  5757. "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5758. (org-test-with-temp-text "* H"
  5759. (let ((org-adapt-indentation nil)
  5760. (org-property-format "%s %s"))
  5761. (org-set-property "TEST" "t"))
  5762. (buffer-string)))))
  5763. (ert-deftest test-org/delete-property ()
  5764. "Test `org-delete-property' specifications."
  5765. (should
  5766. (equal
  5767. ""
  5768. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5769. (org-delete-property "TEST")
  5770. (buffer-string))))
  5771. (should
  5772. (equal
  5773. ":PROPERTIES:\n:TEST1: t\n:END:\n"
  5774. (org-test-with-temp-text ":PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5775. (org-delete-property "TEST2")
  5776. (buffer-string))))
  5777. (should
  5778. (equal
  5779. "* H\n"
  5780. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5781. (org-delete-property "TEST")
  5782. (buffer-string))))
  5783. (should
  5784. (equal
  5785. "* H\n:PROPERTIES:\n:TEST1: t\n:END:\n"
  5786. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5787. (org-delete-property "TEST2")
  5788. (buffer-string)))))
  5789. (ert-deftest test-org/delete-property-globally ()
  5790. "Test `org-delete-property-global' specifications."
  5791. (should
  5792. (equal
  5793. ""
  5794. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5795. (org-delete-property-globally "TEST")
  5796. (buffer-string))))
  5797. (should
  5798. (equal
  5799. "* H\n"
  5800. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n* H\n:PROPERTIES:\n:TEST: nil\n:END:"
  5801. (org-delete-property-globally "TEST")
  5802. (buffer-string)))))
  5803. (ert-deftest test-org/find-property ()
  5804. "Test `org-find-property' specifications."
  5805. ;; Regular test.
  5806. (should
  5807. (= 1
  5808. (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
  5809. (org-find-property "prop"))))
  5810. ;; Find properties in top-level property drawer.
  5811. (should
  5812. (= 1
  5813. (org-test-with-temp-text ":PROPERTIES:\n:PROP: value\n:END:"
  5814. (org-find-property "prop"))))
  5815. ;; Ignore false positives.
  5816. (should
  5817. (= 27
  5818. (org-test-with-temp-text
  5819. "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
  5820. (org-find-property "A"))))
  5821. ;; Return first entry found in buffer.
  5822. (should
  5823. (= 1
  5824. (org-test-with-temp-text
  5825. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5826. (org-find-property "A"))))
  5827. ;; Only search visible part of the buffer.
  5828. (should
  5829. (= 31
  5830. (org-test-with-temp-text
  5831. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5832. (org-narrow-to-subtree)
  5833. (org-find-property "A"))))
  5834. ;; With optional argument, only find entries with a specific value.
  5835. (should-not
  5836. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5837. (org-find-property "A" "2")))
  5838. (should
  5839. (= 31
  5840. (org-test-with-temp-text
  5841. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
  5842. (org-find-property "A" "2"))))
  5843. ;; Use "nil" for explicit nil values.
  5844. (should
  5845. (= 31
  5846. (org-test-with-temp-text
  5847. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
  5848. (org-find-property "A" "nil")))))
  5849. (ert-deftest test-org/entry-delete ()
  5850. "Test `org-entry-delete' specifications."
  5851. ;; Regular test.
  5852. (should
  5853. (string-match
  5854. " *:PROPERTIES:\n *:B: +2\n *:END:"
  5855. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5856. (org-entry-delete (point) "A")
  5857. (buffer-string))))
  5858. ;; Also remove accumulated properties.
  5859. (should-not
  5860. (string-match
  5861. ":A"
  5862. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
  5863. (org-entry-delete (point) "A")
  5864. (buffer-string))))
  5865. ;; When last property is removed, remove the property drawer.
  5866. (should-not
  5867. (string-match
  5868. ":PROPERTIES:"
  5869. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
  5870. (org-entry-delete (point) "A")
  5871. (buffer-string))))
  5872. ;; Return a non-nil value when some property was removed.
  5873. (should
  5874. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5875. (org-entry-delete (point) "A")))
  5876. (should-not
  5877. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5878. (org-entry-delete (point) "C")))
  5879. ;; Special properties cannot be located in a drawer. Allow to
  5880. ;; remove them anyway, in case of user error.
  5881. (should
  5882. (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
  5883. (org-entry-delete (point) "SCHEDULED"))))
  5884. (ert-deftest test-org/entry-get ()
  5885. "Test `org-entry-get' specifications."
  5886. ;; Regular test.
  5887. (should
  5888. (equal "1"
  5889. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:"
  5890. (org-entry-get (point) "A"))))
  5891. (should
  5892. (equal "1"
  5893. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5894. (org-entry-get (point) "A"))))
  5895. ;; Ignore case.
  5896. (should
  5897. (equal "1"
  5898. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5899. (org-entry-get (point) "a"))))
  5900. ;; Handle extended values, both before and after base value.
  5901. (should
  5902. (equal "1 2 3"
  5903. (org-test-with-temp-text
  5904. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5905. (org-entry-get (point) "A"))))
  5906. ;; Empty values are returned as the empty string.
  5907. (should
  5908. (equal ""
  5909. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
  5910. (org-entry-get (point) "A"))))
  5911. ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
  5912. ;; otherwise, return nil.
  5913. (should-not
  5914. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5915. (org-entry-get (point) "A")))
  5916. (should
  5917. (equal "nil"
  5918. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5919. (org-entry-get (point) "A" nil t))))
  5920. ;; Return nil when no property is found, independently on the
  5921. ;; LITERAL-NIL argument.
  5922. (should-not
  5923. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5924. (org-entry-get (point) "B")))
  5925. (should-not
  5926. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5927. (org-entry-get (point) "B" nil t)))
  5928. ;; Handle inheritance, when allowed. Include extended values and
  5929. ;; possibly global values.
  5930. (should
  5931. (equal
  5932. "1"
  5933. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:\n* H"
  5934. (org-entry-get (point-max) "A" t))))
  5935. (should
  5936. (equal
  5937. "1"
  5938. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5939. (org-entry-get (point-max) "A" t))))
  5940. (should
  5941. (equal
  5942. "1"
  5943. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5944. (let ((org-use-property-inheritance t))
  5945. (org-entry-get (point-max) "A" 'selective)))))
  5946. (should-not
  5947. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5948. (let ((org-use-property-inheritance nil))
  5949. (org-entry-get (point-max) "A" 'selective))))
  5950. (should-not
  5951. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H2"
  5952. (let ((org-use-property-inheritance t))
  5953. (org-entry-get (point-max) "A" t))))
  5954. (should
  5955. (equal
  5956. "1 2"
  5957. (org-test-with-temp-text
  5958. ":PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5959. (org-entry-get (point-max) "A" t))))
  5960. (should
  5961. (equal
  5962. "1 2"
  5963. (org-test-with-temp-text
  5964. "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5965. (org-entry-get (point-max) "A" t))))
  5966. (should
  5967. (equal
  5968. "1 2"
  5969. (org-test-with-temp-text
  5970. ":PROPERTIES:\n:A: 1\n:END:\n* H1\n* H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5971. (org-entry-get (point-max) "A" t))))
  5972. (should
  5973. (equal
  5974. "1 2"
  5975. (org-test-with-temp-text
  5976. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2.1\n** H2.2\n:PROPERTIES:\n:A+: 2\n:END:"
  5977. (org-entry-get (point-max) "A" t))))
  5978. (should
  5979. (equal "1"
  5980. (org-test-with-temp-text
  5981. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
  5982. (org-mode-restart)
  5983. (org-entry-get (point-max) "A" t))))
  5984. (should
  5985. (equal "0 1"
  5986. (org-test-with-temp-text
  5987. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
  5988. (org-mode-restart)
  5989. (org-entry-get (point-max) "A" t))))
  5990. ;; document level property-drawer has precedance over
  5991. ;; global-property by PROPERTY-keyword.
  5992. (should
  5993. (equal "0 2"
  5994. (org-test-with-temp-text
  5995. ":PROPERTIES:\n:A: 0\n:END:\n#+PROPERTY: A 1\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5996. (org-mode-restart)
  5997. (org-entry-get (point-max) "A" t))))
  5998. ;; Use alternate separators
  5999. (should
  6000. (equal "0~2"
  6001. (org-test-with-temp-text
  6002. ":PROPERTIES:\n:A: 0\n:A+: 2\n:END:"
  6003. (let ((org-property-separators '((("A") . "~"))))
  6004. (org-entry-get (point) "A")))))
  6005. ;; Default separator is single space
  6006. (should
  6007. (equal "0 2"
  6008. (org-test-with-temp-text
  6009. ":PROPERTIES:\n:A: 0\n:B: 1\n:A+: 2\n:B+: 3\n:END:"
  6010. (let ((org-property-separators '((("B") . "~"))))
  6011. (org-entry-get (point) "A")))))
  6012. ;; Regular expression matching for separator
  6013. (should
  6014. (equal "0/2"
  6015. (org-test-with-temp-text
  6016. ":PROPERTIES:\n:A: 0\n:A+: 2\n:END:"
  6017. (let ((org-property-separators '((("B") . "~") ("[AC]" . "/"))))
  6018. (org-entry-get (point) "A")))))
  6019. ;; Separator works with inheritance
  6020. (should
  6021. (equal "1~2"
  6022. (org-test-with-temp-text
  6023. "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
  6024. (let ((org-property-separators '((("A") . "~"))))
  6025. (org-entry-get (point-max) "A" t))))))
  6026. (ert-deftest test-org/entry-properties ()
  6027. "Test `org-entry-properties' specifications."
  6028. ;; Get "ITEM" property.
  6029. (should
  6030. (equal "H"
  6031. (org-test-with-temp-text "* TODO H"
  6032. (cdr (assoc "ITEM" (org-entry-properties nil "ITEM"))))))
  6033. (should
  6034. (equal "H"
  6035. (org-test-with-temp-text "* TODO H"
  6036. (cdr (assoc "ITEM" (org-entry-properties))))))
  6037. ;; Get "TODO" property. TODO keywords are case sensitive.
  6038. (should
  6039. (equal "TODO"
  6040. (org-test-with-temp-text "* TODO H"
  6041. (cdr (assoc "TODO" (org-entry-properties nil "TODO"))))))
  6042. (should
  6043. (equal "TODO"
  6044. (org-test-with-temp-text "* TODO H"
  6045. (cdr (assoc "TODO" (org-entry-properties))))))
  6046. (should-not
  6047. (org-test-with-temp-text "* H"
  6048. (assoc "TODO" (org-entry-properties nil "TODO"))))
  6049. (should-not
  6050. (org-test-with-temp-text "* todo H"
  6051. (assoc "TODO" (org-entry-properties nil "TODO"))))
  6052. ;; Get "PRIORITY" property.
  6053. (should
  6054. (equal "A"
  6055. (org-test-with-temp-text "* [#A] H"
  6056. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  6057. (should
  6058. (equal "A"
  6059. (org-test-with-temp-text "* [#A] H"
  6060. (cdr (assoc "PRIORITY" (org-entry-properties))))))
  6061. (should
  6062. (equal (char-to-string org-priority-default)
  6063. (org-test-with-temp-text "* H"
  6064. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  6065. ;; Get "FILE" property.
  6066. (should
  6067. (org-test-with-temp-text-in-file "* H\nParagraph"
  6068. (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil "FILE")))
  6069. (buffer-file-name))))
  6070. (should
  6071. (org-test-with-temp-text-in-file "* H\nParagraph"
  6072. (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
  6073. (buffer-file-name))))
  6074. (should-not
  6075. (org-test-with-temp-text "* H\nParagraph"
  6076. (cdr (assoc "FILE" (org-entry-properties nil "FILE")))))
  6077. ;; Get "TAGS" property.
  6078. (should
  6079. (equal ":tag1:tag2:"
  6080. (org-test-with-temp-text "* H :tag1:tag2:"
  6081. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS"))))))
  6082. (should
  6083. (equal ":tag1:tag2:"
  6084. (org-test-with-temp-text "* H :tag1:tag2:"
  6085. (cdr (assoc "TAGS" (org-entry-properties))))))
  6086. (should-not
  6087. (org-test-with-temp-text "* H"
  6088. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS")))))
  6089. ;; Get "ALLTAGS" property.
  6090. (should
  6091. (equal ":tag1:tag2:"
  6092. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  6093. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS"))))))
  6094. (should
  6095. (equal ":tag1:tag2:"
  6096. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  6097. (cdr (assoc "ALLTAGS" (org-entry-properties))))))
  6098. (should-not
  6099. (org-test-with-temp-text "* H"
  6100. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS")))))
  6101. ;; Get "BLOCKED" property.
  6102. (should
  6103. (equal "t"
  6104. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  6105. (let ((org-enforce-todo-dependencies t)
  6106. (org-blocker-hook
  6107. '(org-block-todo-from-children-or-siblings-or-parent)))
  6108. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  6109. (should
  6110. (equal ""
  6111. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  6112. (let ((org-enforce-todo-dependencies t)
  6113. (org-blocker-hook
  6114. '(org-block-todo-from-children-or-siblings-or-parent)))
  6115. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  6116. ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
  6117. (should
  6118. (equal
  6119. "[2012-03-29 thu.]"
  6120. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  6121. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED"))))))
  6122. (should
  6123. (equal
  6124. "[2012-03-29 thu.]"
  6125. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  6126. (cdr (assoc "CLOSED" (org-entry-properties))))))
  6127. (should-not
  6128. (org-test-with-temp-text "* H"
  6129. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED")))))
  6130. (should
  6131. (equal
  6132. "<2014-03-04 tue.>"
  6133. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6134. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE"))))))
  6135. (should
  6136. (equal
  6137. "<2014-03-04 tue.>"
  6138. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6139. (cdr (assoc "DEADLINE" (org-entry-properties))))))
  6140. (should-not
  6141. (org-test-with-temp-text "* H"
  6142. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE")))))
  6143. (should
  6144. (equal
  6145. "<2014-03-04 tue.>"
  6146. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6147. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED"))))))
  6148. (should
  6149. (equal
  6150. "<2014-03-04 tue.>"
  6151. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6152. (cdr (assoc "SCHEDULED" (org-entry-properties))))))
  6153. (should-not
  6154. (org-test-with-temp-text "* H"
  6155. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED")))))
  6156. ;; Get "CATEGORY"
  6157. (should
  6158. (equal "cat"
  6159. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  6160. (cdr (assoc "CATEGORY" (org-entry-properties))))))
  6161. (should
  6162. (equal "cat"
  6163. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  6164. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  6165. (should
  6166. (equal "cat"
  6167. (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
  6168. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  6169. (should
  6170. (equal "cat2"
  6171. (org-test-with-temp-text
  6172. (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6173. "\n"
  6174. "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
  6175. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  6176. ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
  6177. (should
  6178. (equal "<2012-03-29 thu.>"
  6179. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
  6180. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  6181. (should
  6182. (equal "[2012-03-29 thu.]"
  6183. (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
  6184. (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
  6185. (should
  6186. (equal "<2012-03-29 thu.>"
  6187. (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
  6188. (cdr (assoc "TIMESTAMP" (org-entry-properties nil "TIMESTAMP"))))))
  6189. (should
  6190. (equal "[2014-03-04 tue.]"
  6191. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
  6192. (cdr (assoc "TIMESTAMP_IA"
  6193. (org-entry-properties nil "TIMESTAMP_IA"))))))
  6194. (should-not
  6195. (equal "<2012-03-29 thu.>"
  6196. (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
  6197. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  6198. ;; Get standard properties.
  6199. (should
  6200. (equal "1"
  6201. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6202. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  6203. ;; Handle extended properties.
  6204. (should
  6205. (equal "1 2 3"
  6206. (org-test-with-temp-text
  6207. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  6208. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  6209. (should
  6210. (equal "1 2 3"
  6211. (org-test-with-temp-text
  6212. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
  6213. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  6214. ;; Ignore forbidden (special) properties.
  6215. (should-not
  6216. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
  6217. (cdr (assoc "TODO" (org-entry-properties nil 'standard))))))
  6218. (ert-deftest test-org/entry-put ()
  6219. "Test `org-entry-put' specifications."
  6220. ;; Error when not a string or nil.
  6221. (should-error
  6222. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  6223. (org-entry-put 1 "test" 2)))
  6224. ;; Error when property name is invalid.
  6225. (should-error
  6226. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  6227. (org-entry-put 1 "no space" "value")))
  6228. (should-error
  6229. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  6230. (org-entry-put 1 "" "value")))
  6231. ;; Set "TODO" property.
  6232. (should
  6233. (string-match (regexp-quote " TODO H")
  6234. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  6235. (org-entry-put (point) "TODO" "TODO")
  6236. (buffer-string))))
  6237. (should
  6238. (string-match (regexp-quote "* H")
  6239. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  6240. (org-entry-put (point) "TODO" nil)
  6241. (buffer-string))))
  6242. ;; Set "PRIORITY" property.
  6243. (should
  6244. (equal "* [#A] H"
  6245. (org-test-with-temp-text "* [#B] H"
  6246. (org-entry-put (point) "PRIORITY" "A")
  6247. (buffer-string))))
  6248. (should
  6249. (equal "* H"
  6250. (org-test-with-temp-text "* [#B] H"
  6251. (org-entry-put (point) "PRIORITY" nil)
  6252. (buffer-string))))
  6253. ;; Set "SCHEDULED" property.
  6254. (should
  6255. (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
  6256. (org-test-with-temp-text "* H"
  6257. (org-entry-put (point) "SCHEDULED" "2014-03-04")
  6258. (buffer-string))))
  6259. (should
  6260. (string= "* H\n"
  6261. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6262. (org-entry-put (point) "SCHEDULED" nil)
  6263. (buffer-string))))
  6264. (should
  6265. (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
  6266. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6267. (org-entry-put (point) "SCHEDULED" "earlier")
  6268. (buffer-string))))
  6269. (should
  6270. (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
  6271. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  6272. (org-entry-put (point) "SCHEDULED" "later")
  6273. (buffer-string))))
  6274. ;; Set "DEADLINE" property.
  6275. (should
  6276. (string-match "^ *DEADLINE: <2014-03-04 .*?>"
  6277. (org-test-with-temp-text "* H"
  6278. (org-entry-put (point) "DEADLINE" "2014-03-04")
  6279. (buffer-string))))
  6280. (should
  6281. (string= "* H\n"
  6282. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6283. (org-entry-put (point) "DEADLINE" nil)
  6284. (buffer-string))))
  6285. (should
  6286. (string-match "^ *DEADLINE: <2014-03-03 .*?>"
  6287. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6288. (org-entry-put (point) "DEADLINE" "earlier")
  6289. (buffer-string))))
  6290. (should
  6291. (string-match "^ *DEADLINE: <2014-03-05 .*?>"
  6292. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  6293. (org-entry-put (point) "DEADLINE" "later")
  6294. (buffer-string))))
  6295. ;; Set "CATEGORY" property
  6296. (should
  6297. (string-match "^ *:CATEGORY: cat"
  6298. (org-test-with-temp-text "* H"
  6299. (org-entry-put (point) "CATEGORY" "cat")
  6300. (buffer-string))))
  6301. ;; Regular properties, with or without pre-existing drawer.
  6302. (should
  6303. (string-match "^ *:A: +2$"
  6304. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6305. (org-entry-put (point) "A" "2")
  6306. (buffer-string))))
  6307. (should
  6308. (string-match "^ *:A: +1$"
  6309. (org-test-with-temp-text "* H"
  6310. (org-entry-put (point) "A" "1")
  6311. (buffer-string))))
  6312. ;; Special case: two consecutive headlines.
  6313. (should
  6314. (string-match "\\* A\n *:PROPERTIES:"
  6315. (org-test-with-temp-text "* A\n** B"
  6316. (org-entry-put (point) "A" "1")
  6317. (buffer-string)))))
  6318. (ert-deftest test-org/refresh-properties ()
  6319. "Test `org-refresh-properties' specifications."
  6320. (should
  6321. (equal "1"
  6322. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6323. (org-refresh-properties "A" 'org-test)
  6324. (get-text-property (point) 'org-test))))
  6325. (should-not
  6326. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6327. (org-refresh-properties "B" 'org-test)
  6328. (get-text-property (point) 'org-test)))
  6329. ;; Handle properties only defined with extension syntax, i.e.,
  6330. ;; "PROPERTY+".
  6331. (should
  6332. (equal "1"
  6333. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
  6334. (org-refresh-properties "A" 'org-test)
  6335. (get-text-property (point) 'org-test))))
  6336. ;; When property is inherited, add text property to the whole
  6337. ;; sub-tree.
  6338. (should
  6339. (equal "1"
  6340. (org-test-with-temp-text
  6341. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
  6342. (let ((org-use-property-inheritance t))
  6343. (org-refresh-properties "A" 'org-test))
  6344. (get-text-property (point) 'org-test))))
  6345. ;; When a document level property-drawer is used, those properties
  6346. ;; should work exactly like headline-properties as if at a
  6347. ;; headline-level 0.
  6348. (should
  6349. (equal "1"
  6350. (org-test-with-temp-text
  6351. ":PROPERTIES:\n:A: 1\n:END:\n"
  6352. (org-mode-restart)
  6353. (let ((org-use-property-inheritance t))
  6354. (org-refresh-properties "A" 'org-test))
  6355. (get-text-property (point) 'org-test))))
  6356. (should-not
  6357. (equal "1"
  6358. (org-test-with-temp-text
  6359. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  6360. (org-mode-restart)
  6361. (let ((org-use-property-inheritance nil))
  6362. (org-refresh-properties "A" 'org-test))
  6363. (get-text-property (point) 'org-test))))
  6364. (should
  6365. (equal "1"
  6366. (org-test-with-temp-text
  6367. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  6368. (org-mode-restart)
  6369. (let ((org-use-property-inheritance t))
  6370. (org-refresh-properties "A" 'org-test))
  6371. (get-text-property (point) 'org-test))))
  6372. (should
  6373. (equal "2"
  6374. (org-test-with-temp-text
  6375. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1\n:PROPERTIES:\n:A: 2\n:END:"
  6376. (org-mode-restart)
  6377. (let ((org-use-property-inheritance t))
  6378. (org-refresh-properties "A" 'org-test))
  6379. (get-text-property (point) 'org-test))))
  6380. ;; When property is inherited, use global value across the whole
  6381. ;; buffer. However local values have precedence, as well as the
  6382. ;; document level property-drawer.
  6383. (should-not
  6384. (equal "1"
  6385. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  6386. (org-mode-restart)
  6387. (let ((org-use-property-inheritance nil))
  6388. (org-refresh-properties "A" 'org-test))
  6389. (get-text-property (point) 'org-test))))
  6390. (should
  6391. (equal "1"
  6392. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  6393. (org-mode-restart)
  6394. (let ((org-use-property-inheritance t))
  6395. (org-refresh-properties "A" 'org-test))
  6396. (get-text-property (point) 'org-test))))
  6397. (should
  6398. (equal "2"
  6399. (org-test-with-temp-text
  6400. "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
  6401. (org-mode-restart)
  6402. (let ((org-use-property-inheritance t))
  6403. (org-refresh-properties "A" 'org-test))
  6404. (get-text-property (point) 'org-test))))
  6405. ;; When both keyword-property and document-level property-block is
  6406. ;; defined, the property-block has precedance.
  6407. (should
  6408. (equal "1"
  6409. (org-test-with-temp-text
  6410. ":PROPERTIES:\n:A: 1\n:END:\n#+PROPERTY: A 2\n<point>* H1"
  6411. (org-mode-restart)
  6412. (let ((org-use-property-inheritance t))
  6413. (org-refresh-properties "A" 'org-test))
  6414. (get-text-property (point) 'org-test)))))
  6415. (ert-deftest test-org/refresh-category-properties ()
  6416. "Test `org-refresh-category-properties' specifications"
  6417. (should
  6418. (equal "cat1"
  6419. (org-test-with-temp-text
  6420. ":PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6421. (org-refresh-category-properties)
  6422. (org-get-category))))
  6423. (should
  6424. (equal "cat1"
  6425. (org-test-with-temp-text
  6426. "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6427. (org-refresh-category-properties)
  6428. (org-get-category))))
  6429. ;; Even though property-inheritance is deactivated, category
  6430. ;; property should be inherited. As described in
  6431. ;; `org-use-property-inheritance'.
  6432. (should
  6433. (equal "cat1"
  6434. (org-test-with-temp-text
  6435. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  6436. (org-mode-restart)
  6437. (let ((org-use-property-inheritance nil))
  6438. (org-refresh-category-properties))
  6439. (org-get-category))))
  6440. (should
  6441. (equal "cat1"
  6442. (org-test-with-temp-text
  6443. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  6444. (org-mode-restart)
  6445. (let ((org-use-property-inheritance t))
  6446. (org-refresh-category-properties))
  6447. (org-get-category))))
  6448. (should
  6449. (equal "cat2"
  6450. (org-test-with-temp-text
  6451. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H\n:PROPERTIES:\n:CATEGORY: cat2\n:END:\n"
  6452. (org-mode-restart)
  6453. (let ((org-use-property-inheritance t))
  6454. (org-refresh-category-properties))
  6455. (org-get-category)))))
  6456. ;;; Refile
  6457. (ert-deftest test-org/refile-get-targets ()
  6458. "Test `org-refile-get-targets' specifications."
  6459. ;; :maxlevel includes all headings above specified value.
  6460. (should
  6461. (equal '("H1" "H2" "H3")
  6462. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6463. (let ((org-refile-use-outline-path nil)
  6464. (org-refile-targets `((nil :maxlevel . 3))))
  6465. (mapcar #'car (org-refile-get-targets))))))
  6466. (should
  6467. (equal '("H1" "H2")
  6468. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6469. (let ((org-refile-use-outline-path nil)
  6470. (org-refile-targets `((nil :maxlevel . 2))))
  6471. (mapcar #'car (org-refile-get-targets))))))
  6472. ;; :level limits targets to headlines with the specified level.
  6473. (should
  6474. (equal '("H2")
  6475. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6476. (let ((org-refile-use-outline-path nil)
  6477. (org-refile-targets `((nil :level . 2))))
  6478. (mapcar #'car (org-refile-get-targets))))))
  6479. ;; :tag limits targets to headlines with specified tag.
  6480. (should
  6481. (equal '("H1")
  6482. (org-test-with-temp-text "* H1 :foo:\n** H2\n*** H3 :bar:"
  6483. (let ((org-refile-use-outline-path nil)
  6484. (org-refile-targets `((nil :tag . "foo"))))
  6485. (mapcar #'car (org-refile-get-targets))))))
  6486. ;; :todo limits targets to headlines with specified TODO keyword.
  6487. (should
  6488. (equal '("H2")
  6489. (org-test-with-temp-text "* H1\n** TODO H2\n*** DONE H3"
  6490. (let ((org-refile-use-outline-path nil)
  6491. (org-refile-targets `((nil :todo . "TODO"))))
  6492. (mapcar #'car (org-refile-get-targets))))))
  6493. ;; :regexp filters targets matching provided regexp.
  6494. (should
  6495. (equal '("F2" "F3")
  6496. (org-test-with-temp-text "* H1\n** F2\n*** F3"
  6497. (let ((org-refile-use-outline-path nil)
  6498. (org-refile-targets `((nil :regexp . "F"))))
  6499. (mapcar #'car (org-refile-get-targets))))))
  6500. ;; A nil `org-refile-targets' includes only top level headlines in
  6501. ;; current buffer.
  6502. (should
  6503. (equal '("H1" "H2")
  6504. (org-test-with-temp-text "* H1\n** S1\n* H2"
  6505. (let ((org-refile-use-outline-path nil)
  6506. (org-refile-targets nil))
  6507. (mapcar #'car (org-refile-get-targets))))))
  6508. ;; Return value is the union of the targets according to all the
  6509. ;; defined rules. However, prevent duplicates.
  6510. (should
  6511. (equal '("F2" "F3" "H1")
  6512. (org-test-with-temp-text "* TODO H1\n** F2\n*** F3"
  6513. (let ((org-refile-use-outline-path nil)
  6514. (org-refile-targets `((nil :regexp . "F")
  6515. (nil :todo . "TODO"))))
  6516. (mapcar #'car (org-refile-get-targets))))))
  6517. (should
  6518. (equal '("F2" "F3" "H1")
  6519. (org-test-with-temp-text "* TODO H1\n** TODO F2\n*** F3"
  6520. (let ((org-refile-use-outline-path nil)
  6521. (org-refile-targets `((nil :regexp . "F")
  6522. (nil :todo . "TODO"))))
  6523. (mapcar #'car (org-refile-get-targets))))))
  6524. ;; When `org-refile-use-outline-path' is non-nil, provide targets as
  6525. ;; paths.
  6526. (should
  6527. (equal '("H1" "H1/H2" "H1/H2/H3")
  6528. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6529. (let ((org-refile-use-outline-path t)
  6530. (org-refile-targets `((nil :maxlevel . 3))))
  6531. (mapcar #'car (org-refile-get-targets))))))
  6532. ;; When providing targets as paths, escape forward slashes in
  6533. ;; headings with backslashes.
  6534. (should
  6535. (equal '("H1\\/foo")
  6536. (org-test-with-temp-text "* H1/foo"
  6537. (let ((org-refile-use-outline-path t)
  6538. (org-refile-targets `((nil :maxlevel . 1))))
  6539. (mapcar #'car (org-refile-get-targets))))))
  6540. ;; When `org-refile-use-outline-path' is `file', include file name
  6541. ;; without directory in targets.
  6542. (should
  6543. (org-test-with-temp-text-in-file "* H1"
  6544. (let* ((filename (buffer-file-name))
  6545. (org-refile-use-outline-path 'file)
  6546. (org-refile-targets `(((,filename) :level . 1))))
  6547. (member (file-name-nondirectory filename)
  6548. (mapcar #'car (org-refile-get-targets))))))
  6549. ;; When `org-refile-use-outline-path' is `full-file-path', include
  6550. ;; full file name.
  6551. (should
  6552. (org-test-with-temp-text-in-file "* H1"
  6553. (let* ((filename (file-truename (buffer-file-name)))
  6554. (org-refile-use-outline-path 'full-file-path)
  6555. (org-refile-targets `(((,filename) :level . 1))))
  6556. (member filename (mapcar #'car (org-refile-get-targets))))))
  6557. ;; When `org-refile-use-outline-path' is `buffer-name', include
  6558. ;; buffer name.
  6559. (should
  6560. (org-test-with-temp-text "* H1"
  6561. (let* ((org-refile-use-outline-path 'buffer-name)
  6562. (org-refile-targets `((nil :level . 1))))
  6563. (member (buffer-name) (mapcar #'car (org-refile-get-targets)))))))
  6564. ;;; Sparse trees
  6565. (ert-deftest test-org/match-sparse-tree ()
  6566. "Test `org-match-sparse-tree' specifications."
  6567. ;; Match tags.
  6568. (should-not
  6569. (org-test-with-temp-text "* H\n** H1 :tag:"
  6570. (org-match-sparse-tree nil "tag")
  6571. (search-forward "H1")
  6572. (org-invisible-p2)))
  6573. (should
  6574. (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
  6575. (org-match-sparse-tree nil "tag")
  6576. (search-forward "H2")
  6577. (org-invisible-p2)))
  6578. ;; "-" operator for tags.
  6579. (should-not
  6580. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6581. (org-match-sparse-tree nil "tag1-tag2")
  6582. (search-forward "H1")
  6583. (org-invisible-p2)))
  6584. (should
  6585. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6586. (org-match-sparse-tree nil "tag1-tag2")
  6587. (search-forward "H2")
  6588. (org-invisible-p2)))
  6589. ;; "&" operator for tags.
  6590. (should
  6591. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6592. (org-match-sparse-tree nil "tag1&tag2")
  6593. (search-forward "H1")
  6594. (org-invisible-p2)))
  6595. (should-not
  6596. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6597. (org-match-sparse-tree nil "tag1&tag2")
  6598. (search-forward "H2")
  6599. (org-invisible-p2)))
  6600. ;; "|" operator for tags.
  6601. (should-not
  6602. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6603. (org-match-sparse-tree nil "tag1|tag2")
  6604. (search-forward "H1")
  6605. (org-invisible-p2)))
  6606. (should-not
  6607. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6608. (org-match-sparse-tree nil "tag1|tag2")
  6609. (search-forward "H2")
  6610. (org-invisible-p2)))
  6611. ;; Regexp match on tags.
  6612. (should-not
  6613. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6614. (org-match-sparse-tree nil "{^tag.*}")
  6615. (search-forward "H1")
  6616. (org-invisible-p2)))
  6617. (should
  6618. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6619. (org-match-sparse-tree nil "{^tag.*}")
  6620. (search-forward "H2")
  6621. (org-invisible-p2)))
  6622. ;; Match group tags.
  6623. (should-not
  6624. (org-test-with-temp-text
  6625. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6626. (org-match-sparse-tree nil "work")
  6627. (search-forward "H1")
  6628. (org-invisible-p2)))
  6629. (should-not
  6630. (org-test-with-temp-text
  6631. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6632. (org-match-sparse-tree nil "work")
  6633. (search-forward "H2")
  6634. (org-invisible-p2)))
  6635. ;; Match group tags with hard brackets.
  6636. (should-not
  6637. (org-test-with-temp-text
  6638. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6639. (org-match-sparse-tree nil "work")
  6640. (search-forward "H1")
  6641. (org-invisible-p2)))
  6642. (should-not
  6643. (org-test-with-temp-text
  6644. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6645. (org-match-sparse-tree nil "work")
  6646. (search-forward "H2")
  6647. (org-invisible-p2)))
  6648. ;; Match tags in hierarchies
  6649. (should-not
  6650. (org-test-with-temp-text
  6651. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6652. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6653. #+TAGS: { Lev_3 : Lev_4 }\n
  6654. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6655. (org-match-sparse-tree nil "Lev_1")
  6656. (search-forward "H4")
  6657. (org-invisible-p2)))
  6658. (should-not
  6659. (org-test-with-temp-text
  6660. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6661. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6662. #+TAGS: { Lev_3 : Lev_4 }\n
  6663. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6664. (org-match-sparse-tree nil "Lev_1+Lev_3")
  6665. (search-forward "H4")
  6666. (org-invisible-p2)))
  6667. ;; Match regular expressions in tags
  6668. (should-not
  6669. (org-test-with-temp-text
  6670. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
  6671. (org-match-sparse-tree nil "Lev")
  6672. (search-forward "H1")
  6673. (org-invisible-p2)))
  6674. (should
  6675. (org-test-with-temp-text
  6676. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
  6677. (org-match-sparse-tree nil "Lev")
  6678. (search-forward "H1")
  6679. (org-invisible-p2)))
  6680. ;; Match properties.
  6681. (should
  6682. (org-test-with-temp-text
  6683. "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
  6684. (org-match-sparse-tree nil "A=\"1\"")
  6685. (search-forward "H2")
  6686. (org-invisible-p2)))
  6687. (should-not
  6688. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6689. (org-match-sparse-tree nil "A=\"1\"")
  6690. (search-forward "H2")
  6691. (org-invisible-p2)))
  6692. ;; Case is not significant when matching properties.
  6693. (should-not
  6694. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6695. (org-match-sparse-tree nil "a=\"1\"")
  6696. (search-forward "H2")
  6697. (org-invisible-p2)))
  6698. (should-not
  6699. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
  6700. (org-match-sparse-tree nil "A=\"1\"")
  6701. (search-forward "H2")
  6702. (org-invisible-p2)))
  6703. ;; Match special LEVEL property.
  6704. (should-not
  6705. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6706. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6707. (search-forward "H1")
  6708. (org-invisible-p2)))
  6709. (should
  6710. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6711. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6712. (search-forward "H2")
  6713. (org-invisible-p2)))
  6714. ;; Comparison operators when matching properties.
  6715. (should
  6716. (org-test-with-temp-text
  6717. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6718. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6719. (search-forward "H1")
  6720. (org-invisible-p2)))
  6721. (should-not
  6722. (org-test-with-temp-text
  6723. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6724. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6725. (search-forward "H2")
  6726. (org-invisible-p2)))
  6727. ;; Regexp match on properties values.
  6728. (should-not
  6729. (org-test-with-temp-text
  6730. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6731. (org-match-sparse-tree nil "A={f.*}")
  6732. (search-forward "H1")
  6733. (org-invisible-p2)))
  6734. (should
  6735. (org-test-with-temp-text
  6736. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6737. (org-match-sparse-tree nil "A={f.*}")
  6738. (search-forward "H2")
  6739. (org-invisible-p2)))
  6740. ;; With an optional argument, limit match to TODO entries.
  6741. (should-not
  6742. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6743. (org-match-sparse-tree t "tag")
  6744. (search-forward "H1")
  6745. (org-invisible-p2)))
  6746. (should
  6747. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6748. (org-match-sparse-tree t "tag")
  6749. (search-forward "H2")
  6750. (org-invisible-p2))))
  6751. (ert-deftest test-org/occur ()
  6752. "Test `org-occur' specifications."
  6753. ;; Count number of matches.
  6754. (should
  6755. (= 1
  6756. (org-test-with-temp-text "* H\nA\n* H2"
  6757. (org-occur "A"))))
  6758. (should
  6759. (= 2
  6760. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6761. (org-occur "A"))))
  6762. ;; Test CALLBACK optional argument.
  6763. (should
  6764. (= 0
  6765. (org-test-with-temp-text "* H\nA\n* H2"
  6766. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6767. (should
  6768. (= 1
  6769. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6770. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6771. ;; Case-fold searches according to `org-occur-case-fold-search'.
  6772. (should
  6773. (= 2
  6774. (org-test-with-temp-text "Aa"
  6775. (let ((org-occur-case-fold-search t)) (org-occur "A")))))
  6776. (should
  6777. (= 2
  6778. (org-test-with-temp-text "Aa"
  6779. (let ((org-occur-case-fold-search t)) (org-occur "a")))))
  6780. (should
  6781. (= 1
  6782. (org-test-with-temp-text "Aa"
  6783. (let ((org-occur-case-fold-search nil)) (org-occur "A")))))
  6784. (should
  6785. (= 1
  6786. (org-test-with-temp-text "Aa"
  6787. (let ((org-occur-case-fold-search nil)) (org-occur "a")))))
  6788. (should
  6789. (= 1
  6790. (org-test-with-temp-text "Aa"
  6791. (let ((org-occur-case-fold-search 'smart)) (org-occur "A")))))
  6792. (should
  6793. (= 2
  6794. (org-test-with-temp-text "Aa"
  6795. (let ((org-occur-case-fold-search 'smart)) (org-occur "a"))))))
  6796. ;;; Tags
  6797. (ert-deftest test-org/tag-string-to-alist ()
  6798. "Test `org-tag-string-to-alist' specifications."
  6799. ;; Tag without selection key.
  6800. (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
  6801. ;; Tag with selection key.
  6802. (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t))))
  6803. ;; Tag group.
  6804. (should
  6805. (equal
  6806. (org-tag-string-to-alist "[ group : t1 t2 ]")
  6807. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag))))
  6808. ;; Mutually exclusive tags.
  6809. (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
  6810. '((:startgroup) ("tag1") ("tag2") (:endgroup))))
  6811. (should
  6812. (equal
  6813. (org-tag-string-to-alist "{ group : tag1 tag2 }")
  6814. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))))
  6815. (ert-deftest test-org/tag-alist-to-string ()
  6816. "Test `org-tag-alist-to-string' specifications."
  6817. (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
  6818. (should (equal (org-tag-alist-to-string '(("tag1" . ?t))) "tag1(t)"))
  6819. (should
  6820. (equal
  6821. (org-tag-alist-to-string
  6822. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6823. "[ group : t1 t2 ]"))
  6824. (should
  6825. (equal (org-tag-alist-to-string
  6826. '((:startgroup) ("tag1") ("tag2") (:endgroup)))
  6827. "{ tag1 tag2 }"))
  6828. (should
  6829. (equal
  6830. (org-tag-alist-to-string
  6831. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))
  6832. "{ group : tag1 tag2 }")))
  6833. (ert-deftest test-org/tag-alist-to-groups ()
  6834. "Test `org-tag-alist-to-groups' specifications."
  6835. (should
  6836. (equal (org-tag-alist-to-groups
  6837. '((:startgroup) ("group") (:grouptags) ("t1") ("t2") (:endgroup)))
  6838. '(("group" "t1" "t2"))))
  6839. (should
  6840. (equal
  6841. (org-tag-alist-to-groups
  6842. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6843. '(("group" "t1" "t2"))))
  6844. (should-not
  6845. (org-tag-alist-to-groups
  6846. '((:startgroup) ("group") ("t1") ("t2") (:endgroup)))))
  6847. (ert-deftest test-org/tag-align ()
  6848. "Test tags alignment."
  6849. ;; Test aligning tags with different display width.
  6850. (should
  6851. ;; 12345678901234567890
  6852. (equal "* Test :abc:"
  6853. (org-test-with-temp-text "* Test :abc:"
  6854. (let ((org-tags-column -20)
  6855. (indent-tabs-mode nil))
  6856. (org-fix-tags-on-the-fly))
  6857. (buffer-string))))
  6858. (should
  6859. ;; 12345678901234567890
  6860. (equal "* Test :日本語:"
  6861. (org-test-with-temp-text "* Test :日本語:"
  6862. (let ((org-tags-column -20)
  6863. (indent-tabs-mode nil))
  6864. (org-fix-tags-on-the-fly))
  6865. (buffer-string))))
  6866. ;; Make sure aligning tags do not skip invisible text.
  6867. (should
  6868. (equal "* [[linkx]] :tag:"
  6869. (org-test-with-temp-text "* [[link<point>]] :tag:"
  6870. (let ((org-tags-column 0))
  6871. (org-fix-tags-on-the-fly)
  6872. (insert "x")
  6873. (buffer-string)))))
  6874. ;; Aligning tags preserve position.
  6875. (should
  6876. (= 6 (org-test-with-temp-text "* 345 <point> :tag:"
  6877. (let ((org-tags-column 78)
  6878. (indent-tabs-mode nil))
  6879. (org-fix-tags-on-the-fly))
  6880. (current-column))))
  6881. ;; Aligning all tags in visible buffer.
  6882. (should
  6883. ;; 12345678901234567890
  6884. (equal (concat "* Level 1 :abc:\n"
  6885. "** Level 2 :def:")
  6886. (org-test-with-temp-text (concat "* Level 1 :abc:\n"
  6887. "** Level 2 :def:")
  6888. (let ((org-tags-column -20)
  6889. (indent-tabs-mode nil))
  6890. ;; (org-align-tags :all) must work even when the point
  6891. ;; is at the end of the buffer.
  6892. (goto-char (point-max))
  6893. (org-align-tags :all))
  6894. (buffer-string)))))
  6895. (ert-deftest test-org/get-tags ()
  6896. "Test `org-get-tags' specifications."
  6897. ;; Standard test.
  6898. (should
  6899. (equal '("foo")
  6900. (org-test-with-temp-text "* Test :foo:" (org-get-tags))))
  6901. (should
  6902. (equal '("foo" "bar")
  6903. (org-test-with-temp-text "* Test :foo:bar:" (org-get-tags))))
  6904. ;; Tags for inlinetasks.
  6905. (should
  6906. (equal '("foo" "bar")
  6907. (progn
  6908. (require 'org-inlinetask)
  6909. (org-test-with-temp-text (concat (make-string org-inlinetask-min-level ?*) " Test :foo:bar:")
  6910. (org-get-tags (org-element-at-point))))))
  6911. (should
  6912. (equal '("foo" "bar")
  6913. (progn
  6914. (require 'org-inlinetask)
  6915. (org-test-with-temp-text (concat (make-string org-inlinetask-min-level ?*) " Test :foo:bar:")
  6916. (org-get-tags nil)))))
  6917. ;; Return nil when there is no tag.
  6918. (should-not
  6919. (org-test-with-temp-text "* Test" (org-get-tags)))
  6920. ;; Tags are inherited from parent headlines.
  6921. (should
  6922. (equal '("tag")
  6923. (let ((org-use-tag-inheritance t))
  6924. (org-test-with-temp-text "* H0 :foo:\n* H1 :tag:\n<point>** H2"
  6925. (org-get-tags)))))
  6926. ;; Tags are inherited from `org-file-tags'.
  6927. (should
  6928. (equal '("tag")
  6929. (org-test-with-temp-text "* H1"
  6930. (let ((org-file-tags '("tag"))
  6931. (org-use-tag-inheritance t))
  6932. (org-get-tags)))))
  6933. ;; Only inherited tags have the `inherited' text property.
  6934. (should
  6935. (get-text-property 0 'inherited
  6936. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6937. (let ((org-use-tag-inheritance t))
  6938. (assoc-string "foo" (org-get-tags))))))
  6939. (should-not
  6940. (get-text-property 0 'inherited
  6941. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6942. (let ((org-use-tag-inheritance t))
  6943. (assoc-string "bar" (org-get-tags))))))
  6944. ;; Obey to `org-use-tag-inheritance'.
  6945. (should-not
  6946. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6947. (let ((org-use-tag-inheritance nil))
  6948. (assoc-string "foo" (org-get-tags)))))
  6949. (should-not
  6950. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6951. (let ((org-use-tag-inheritance nil)
  6952. (org-file-tags '("foo")))
  6953. (assoc-string "foo" (org-get-tags)))))
  6954. (should-not
  6955. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6956. (let ((org-use-tag-inheritance '("bar")))
  6957. (assoc-string "foo" (org-get-tags)))))
  6958. (should
  6959. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6960. (let ((org-use-tag-inheritance '("bar")))
  6961. (assoc-string "bar" (org-get-tags)))))
  6962. (should-not
  6963. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6964. (let ((org-use-tag-inheritance "b.*"))
  6965. (assoc-string "foo" (org-get-tags)))))
  6966. (should
  6967. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6968. (let ((org-use-tag-inheritance "b.*"))
  6969. (assoc-string "bar" (org-get-tags)))))
  6970. ;; When optional argument LOCAL is non-nil, ignore tag inheritance.
  6971. (should
  6972. (equal '("baz")
  6973. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6974. (let ((org-use-tag-inheritance t))
  6975. (org-get-tags nil t)))))
  6976. ;; When optional argument POS is non-nil, get tags there instead.
  6977. (should
  6978. (equal '("foo")
  6979. (org-test-with-temp-text "* H1 :foo:\n* <point>H2 :bar:"
  6980. (org-get-tags 1))))
  6981. ;; Make sure tags excluded from inheritance are returned if local
  6982. (should
  6983. (equal '("foo")
  6984. (org-test-with-temp-text "* Test :foo:"
  6985. (let ((org-use-tag-inheritance t)
  6986. (org-tags-exclude-from-inheritance '("foo")))
  6987. (org-get-tags)))))
  6988. ;; Test the collection of tags from #+filetags and parent tags.
  6989. (should
  6990. (equal '("a" "b" "c" "d")
  6991. (org-test-with-temp-text (concat "#+filetags: a\n"
  6992. "* Level 1 :b:\n"
  6993. "** Level 2 :c:\n"
  6994. "*** Level 3 :d:\n"
  6995. "<point>")
  6996. (let ((org-use-tag-inheritance t))
  6997. (org-mode-restart) ;So that `org-file-tags' get populated from #+filetags
  6998. (org-get-tags)))))
  6999. ;; Pathological case: tagged headline with an empty body.
  7000. (should (org-test-with-temp-text "* :tag:" (org-get-tags))))
  7001. (ert-deftest test-org/set-tags ()
  7002. "Test `org-set-tags' specifications."
  7003. ;; Throw an error on invalid data.
  7004. (should-error
  7005. (org-test-with-temp-text "* H"
  7006. (org-set-tags 'foo)))
  7007. ;; `nil', an empty, and a blank string remove all tags.
  7008. (should
  7009. (equal "* H"
  7010. (org-test-with-temp-text "* H :tag1:tag2:"
  7011. (org-set-tags nil)
  7012. (buffer-string))))
  7013. (should
  7014. (equal "* H"
  7015. (org-test-with-temp-text "* H :tag1:tag2:"
  7016. (org-set-tags "")
  7017. (buffer-string))))
  7018. (should
  7019. (equal "* H"
  7020. (org-test-with-temp-text "* H :tag1:tag2:"
  7021. (org-set-tags " ")
  7022. (buffer-string))))
  7023. ;; If there's nothing to remove, just bail out.
  7024. (should
  7025. (equal "* H"
  7026. (org-test-with-temp-text "* H"
  7027. (org-set-tags nil)
  7028. (buffer-string))))
  7029. (should
  7030. (equal "* "
  7031. (org-test-with-temp-text "* "
  7032. (org-set-tags nil)
  7033. (buffer-string))))
  7034. ;; If DATA is a tag string, set current tags to it, even if it means
  7035. ;; replacing old tags.
  7036. (should
  7037. (equal "* H :tag0:"
  7038. (org-test-with-temp-text "* H :tag1:tag2:"
  7039. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  7040. (buffer-string))))
  7041. (should
  7042. (equal "* H :tag0:"
  7043. (org-test-with-temp-text "* H"
  7044. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  7045. (buffer-string))))
  7046. ;; If DATA is a list, set tags to this list, even if it means
  7047. ;; replacing old tags.
  7048. (should
  7049. (equal "* H :tag0:"
  7050. (org-test-with-temp-text "* H :tag1:tag2:"
  7051. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  7052. (buffer-string))))
  7053. (should
  7054. (equal "* H :tag0:"
  7055. (org-test-with-temp-text "* H"
  7056. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  7057. (buffer-string))))
  7058. ;; When set, apply `org-tags-sort-function'.
  7059. (should
  7060. (equal "* H :a:b:"
  7061. (org-test-with-temp-text "* H"
  7062. (let ((org-tags-column 1)
  7063. (org-tags-sort-function #'string<))
  7064. (org-set-tags '("b" "a"))
  7065. (buffer-string)))))
  7066. ;; When new tags are identical to the previous ones, still align.
  7067. (should
  7068. (equal "* H :foo:"
  7069. (org-test-with-temp-text "* H :foo:"
  7070. (let ((org-tags-column 1))
  7071. (org-set-tags '("foo"))
  7072. (buffer-string)))))
  7073. ;; When tags have been changed, run `org-after-tags-change-hook'.
  7074. (should
  7075. (catch :return
  7076. (org-test-with-temp-text "* H :foo:"
  7077. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  7078. (org-set-tags '("bar"))
  7079. nil))))
  7080. (should-not
  7081. (catch :return
  7082. (org-test-with-temp-text "* H :foo:"
  7083. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  7084. (org-set-tags '("foo"))
  7085. nil))))
  7086. ;; Special case: handle empty headlines.
  7087. (should
  7088. (equal "* :tag0:"
  7089. (org-test-with-temp-text "* "
  7090. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  7091. (buffer-string))))
  7092. ;; Modify buffer only when a tag change happens or alignment is
  7093. ;; done.
  7094. (should-not
  7095. (org-test-with-temp-text "* H :foo:"
  7096. (set-buffer-modified-p nil)
  7097. (let ((org-tags-column 1)) (org-set-tags '("foo")))
  7098. (buffer-modified-p)))
  7099. (should
  7100. (org-test-with-temp-text "* H :foo:"
  7101. (set-buffer-modified-p nil)
  7102. (let ((org-tags-column 10)) (org-set-tags '("foo")))
  7103. (buffer-modified-p)))
  7104. (should
  7105. (org-test-with-temp-text "* H :foo:"
  7106. (set-buffer-modified-p nil)
  7107. (let ((org-tags-column 10)) (org-set-tags '("bar")))
  7108. (buffer-modified-p)))
  7109. ;; Pathological case: when setting tags of a folded headline, do not
  7110. ;; let new tags being sucked into invisibility.
  7111. (should-not
  7112. (org-test-with-temp-text "* H1\nContent\n* H2\n\n Other Content"
  7113. ;; Show only headlines
  7114. (org-content)
  7115. ;; Set NEXT tag on current entry
  7116. (org-set-tags ":NEXT:")
  7117. ;; Move point to that NEXT tag
  7118. (search-forward "NEXT") (backward-word)
  7119. ;; And it should be visible (i.e. no overlays)
  7120. (overlays-at (point)))))
  7121. (ert-deftest test-org/set-tags-command ()
  7122. "Test `org-set-tags-command' specifications"
  7123. ;; Set tags at current headline.
  7124. (should
  7125. (equal "* H1 :foo:"
  7126. (org-test-with-temp-text "* H1"
  7127. (cl-letf (((symbol-function 'completing-read-multiple)
  7128. (lambda (&rest _args) '("foo"))))
  7129. (let ((org-use-fast-tag-selection nil)
  7130. (org-tags-column 1))
  7131. (org-set-tags-command)))
  7132. (buffer-string))))
  7133. ;; Preserve position when called from the section below.
  7134. (should
  7135. (equal "* H1 :foo:\nContents"
  7136. (org-test-with-temp-text "* H1\n<point>Contents"
  7137. (cl-letf (((symbol-function 'completing-read-multiple)
  7138. (lambda (&rest _args) '("foo"))))
  7139. (let ((org-use-fast-tag-selection nil)
  7140. (org-tags-column 1))
  7141. (org-set-tags-command)))
  7142. (buffer-string))))
  7143. (should-not
  7144. (equal "* H1 :foo:\nContents2"
  7145. (org-test-with-temp-text "* H1\n<point>Contents2"
  7146. (cl-letf (((symbol-function 'completing-read-multiple)
  7147. (lambda (&rest _args) '("foo"))))
  7148. (let ((org-use-fast-tag-selection nil)
  7149. (org-tags-column 1))
  7150. (org-set-tags-command)))
  7151. (org-at-heading-p))))
  7152. ;; When a region is active and
  7153. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  7154. ;; same value in all headlines in region.
  7155. (should
  7156. (equal "* H1 :foo:\nContents\n* H2 :foo:"
  7157. (org-test-with-temp-text "* H1\nContents\n* H2"
  7158. (cl-letf (((symbol-function 'completing-read-multiple)
  7159. (lambda (&rest _args) '("foo"))))
  7160. (let ((org-use-fast-tag-selection nil)
  7161. (org-loop-over-headlines-in-active-region t)
  7162. (org-tags-column 1))
  7163. (transient-mark-mode 1)
  7164. (push-mark (point) t t)
  7165. (goto-char (point-max))
  7166. (org-set-tags-command)))
  7167. (buffer-string))))
  7168. (should
  7169. (equal "* H1\nContents\n* H2 :foo:"
  7170. (org-test-with-temp-text "* H1\nContents\n* H2"
  7171. (cl-letf (((symbol-function 'completing-read-multiple)
  7172. (lambda (&rest _args) '("foo"))))
  7173. (let ((org-use-fast-tag-selection nil)
  7174. (org-loop-over-headlines-in-active-region nil)
  7175. (org-tags-column 1))
  7176. (transient-mark-mode 1)
  7177. (push-mark (point) t t)
  7178. (goto-char (point-max))
  7179. (org-set-tags-command)))
  7180. (buffer-string))))
  7181. ;; With a C-u prefix argument, align all tags in the buffer.
  7182. (should
  7183. (equal "* H1 :foo:\n* H2 :bar:"
  7184. (org-test-with-temp-text "* H1 :foo:\n* H2 :bar:"
  7185. (let ((org-tags-column 1)) (org-set-tags-command '(4)))
  7186. (buffer-string))))
  7187. ;; Point does not move with empty headline.
  7188. (should
  7189. (equal ":foo:"
  7190. (org-test-with-temp-text "* <point>"
  7191. (cl-letf (((symbol-function 'completing-read-multiple)
  7192. (lambda (&rest _args) '("foo"))))
  7193. (let ((org-use-fast-tag-selection nil)
  7194. (org-tags-column 1))
  7195. (org-set-tags-command)))
  7196. (buffer-substring (point) (line-end-position)))))
  7197. ;; Point does not move at start of line.
  7198. (should
  7199. (equal "* H1 :foo:"
  7200. (org-test-with-temp-text "* H1"
  7201. (cl-letf (((symbol-function 'completing-read-multiple)
  7202. (lambda (&rest _args) '("foo"))))
  7203. (let ((org-use-fast-tag-selection nil)
  7204. (org-tags-column 1))
  7205. (org-set-tags-command)))
  7206. (buffer-substring (point) (line-end-position)))))
  7207. ;; Point does not move when within *'s.
  7208. (should
  7209. (equal "* H1 :foo:"
  7210. (org-test-with-temp-text "*<point>* H1"
  7211. (cl-letf (((symbol-function 'completing-read-multiple)
  7212. (lambda (&rest _args) '("foo"))))
  7213. (let ((org-use-fast-tag-selection nil)
  7214. (org-tags-column 1))
  7215. (org-set-tags-command)))
  7216. (buffer-substring (point) (line-end-position)))))
  7217. ;; Point workaround does not get fooled when looking at a space.
  7218. (should
  7219. (equal " b :foo:"
  7220. (org-test-with-temp-text "* a<point> b"
  7221. (cl-letf (((symbol-function 'completing-read-multiple)
  7222. (lambda (&rest _args) '("foo"))))
  7223. (let ((org-use-fast-tag-selection nil)
  7224. (org-tags-column 1))
  7225. (org-set-tags-command)))
  7226. (buffer-substring (point) (line-end-position)))))
  7227. ;; Handle tags both set locally and inherited.
  7228. (should
  7229. (equal "b :foo:"
  7230. (org-test-with-temp-text "* a :foo:\n** <point>b :foo:"
  7231. (cl-letf (((symbol-function 'completing-read-multiple)
  7232. (lambda (_prompt _coll &optional _pred _req initial &rest _)
  7233. (list initial))))
  7234. (let ((org-use-fast-tag-selection nil)
  7235. (org-tags-column 1))
  7236. (org-set-tags-command)))
  7237. (buffer-substring (point) (line-end-position))))))
  7238. (ert-deftest test-org/toggle-tag ()
  7239. "Test `org-toggle-tag' specifications."
  7240. ;; Insert missing tag.
  7241. (should
  7242. (equal "* H :tag:"
  7243. (org-test-with-temp-text "* H"
  7244. (let ((org-tags-column 1)) (org-toggle-tag "tag"))
  7245. (buffer-string))))
  7246. (should
  7247. (equal "* H :tag1:tag2:"
  7248. (org-test-with-temp-text "* H :tag1:"
  7249. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  7250. (buffer-string))))
  7251. ;; Remove existing tag.
  7252. (should
  7253. (equal "* H"
  7254. (org-test-with-temp-text "* H :tag:"
  7255. (org-toggle-tag "tag")
  7256. (buffer-string))))
  7257. (should
  7258. (equal "* H :tag1:"
  7259. (org-test-with-temp-text "* H :tag1:tag2:"
  7260. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  7261. (buffer-string))))
  7262. (should
  7263. (equal "* H :tag2:"
  7264. (org-test-with-temp-text "* H :tag1:tag2:"
  7265. (let ((org-tags-column 1)) (org-toggle-tag "tag1"))
  7266. (buffer-string))))
  7267. ;; With optional argument ONOFF set to `on', try to insert the tag,
  7268. ;; even if its already there.
  7269. (should
  7270. (equal "* H :tag:"
  7271. (org-test-with-temp-text "* H"
  7272. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  7273. (buffer-string))))
  7274. (should
  7275. (equal "* H :tag:"
  7276. (org-test-with-temp-text "* H :tag:"
  7277. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  7278. (buffer-string))))
  7279. ;; With optional argument ONOFF set to `off', try to remove the tag,
  7280. ;; even if its not there.
  7281. (should
  7282. (equal "* H"
  7283. (org-test-with-temp-text "* H :tag:"
  7284. (org-toggle-tag "tag" 'off)
  7285. (buffer-string))))
  7286. (should
  7287. (equal "* H :tag:"
  7288. (org-test-with-temp-text "* H :tag:"
  7289. (let ((org-tags-column 1)) (org-toggle-tag "foo" 'off))
  7290. (buffer-string))))
  7291. ;; Special case: Handle properly tag inheritance. In particular, do
  7292. ;; not set inherited tags.
  7293. (should
  7294. (equal "* H1 :tag:\n** H2 :tag2:tag:"
  7295. (org-test-with-temp-text "* H1 :tag:\n** <point>H2 :tag2:"
  7296. (let ((org-use-tag-inheritance t)
  7297. (org-tags-column 1))
  7298. (org-toggle-tag "tag"))
  7299. (buffer-string))))
  7300. (should
  7301. (equal "* H1 :tag1:tag2:\n** H2 :foo:"
  7302. (org-test-with-temp-text "* H1 :tag1:tag2:\n** <point>H2"
  7303. (let ((org-use-tag-inheritance t)
  7304. (org-tags-column 1))
  7305. (org-toggle-tag "foo"))
  7306. (buffer-string)))))
  7307. (ert-deftest test-org/tags-expand ()
  7308. "Test `org-tags-expand' specifications."
  7309. ;; Expand tag groups as a regexp enclosed within curly brackets.
  7310. (should
  7311. (equal "{\\<[ABC]\\>}"
  7312. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7313. (org-mode-restart)
  7314. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  7315. (should
  7316. (equal "{\\<\\(?:Aa\\|Bb\\|Cc\\)\\>}"
  7317. (org-test-with-temp-text "#+TAGS: [ Aa : Bb Cc ]"
  7318. (org-mode-restart)
  7319. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "Aa")))))
  7320. ;; Preserve operator before the regexp.
  7321. (should
  7322. (equal "+{\\<[ABC]\\>}"
  7323. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7324. (org-mode-restart)
  7325. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "+A")))))
  7326. (should
  7327. (equal "-{\\<[ABC]\\>}"
  7328. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7329. (org-mode-restart)
  7330. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "-A")))))
  7331. ;; Handle "|" syntax.
  7332. (should
  7333. (equal "{\\<[ABC]\\>}|D"
  7334. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7335. (org-mode-restart)
  7336. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|D")))))
  7337. ;; Handle nested groups.
  7338. (should
  7339. (equal "{\\<[A-D]\\>}"
  7340. (org-test-with-temp-text "#+TAGS: [ A : B C ]\n#+TAGS: [ B : D ]"
  7341. (org-mode-restart)
  7342. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  7343. ;; Expand multiple occurrences of the same group.
  7344. (should
  7345. (equal "{\\<[ABC]\\>}|{\\<[ABC]\\>}"
  7346. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7347. (org-mode-restart)
  7348. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|A")))))
  7349. ;; Preserve regexp matches.
  7350. (should
  7351. (equal "{A+}"
  7352. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7353. (org-mode-restart)
  7354. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "{A+}"))))))
  7355. ;;; TODO keywords
  7356. (ert-deftest test-org/auto-repeat-maybe ()
  7357. "Test `org-auto-repeat-maybe' specifications."
  7358. ;; Do not auto repeat when there is no valid time stamp with
  7359. ;; a repeater in the entry.
  7360. (should-not
  7361. (string-prefix-p
  7362. "* TODO H"
  7363. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7364. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
  7365. (org-todo "DONE")
  7366. (buffer-string)))))
  7367. (should-not
  7368. (string-prefix-p
  7369. "* TODO H"
  7370. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7371. (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
  7372. (org-todo "DONE")
  7373. (buffer-string)))))
  7374. ;; When switching to DONE state, switch back to first TODO keyword
  7375. ;; in sequence, or the same keyword if they have different types.
  7376. (should
  7377. (string-prefix-p
  7378. "* TODO H"
  7379. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7380. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7381. (org-todo "DONE")
  7382. (buffer-string)))))
  7383. (should
  7384. (string-prefix-p
  7385. "* KWD1 H"
  7386. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  7387. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  7388. (org-todo "DONE")
  7389. (buffer-string)))))
  7390. (should
  7391. (string-prefix-p
  7392. "* KWD2 H"
  7393. (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
  7394. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  7395. (org-todo "DONE")
  7396. (buffer-string)))))
  7397. ;; If there was no TODO keyword in the first place, do not insert
  7398. ;; any either.
  7399. (should
  7400. (string-prefix-p
  7401. "* H"
  7402. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7403. (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
  7404. (org-todo "DONE")
  7405. (buffer-string)))))
  7406. ;; Revert to REPEAT_TO_STATE, if set.
  7407. (should
  7408. (string-prefix-p
  7409. "* KWD2 H"
  7410. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  7411. (org-test-with-temp-text
  7412. "* KWD2 H
  7413. :PROPERTIES:
  7414. :REPEAT_TO_STATE: KWD2
  7415. :END:
  7416. <2012-03-29 Thu +2y>"
  7417. (org-todo "DONE")
  7418. (buffer-string)))))
  7419. ;; When switching to DONE state, update base date. If there are
  7420. ;; multiple repeated time stamps, update them all.
  7421. (should
  7422. (string-match-p
  7423. "<2014-03-29 .* \\+2y>"
  7424. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7425. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7426. (org-todo "DONE")
  7427. (buffer-string)))))
  7428. (should
  7429. (string-match-p
  7430. "<2015-03-04 .* \\+1y>"
  7431. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7432. (org-test-with-temp-text
  7433. "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
  7434. (org-todo "DONE")
  7435. (buffer-string)))))
  7436. ;; Throw an error if repeater unit is the hour and no time is
  7437. ;; provided in the time-stamp.
  7438. (should-error
  7439. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7440. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
  7441. (org-todo "DONE")
  7442. (buffer-string))))
  7443. ;; Handle every repeater type using hours step.
  7444. (should
  7445. (string-match-p
  7446. "2014-03-04 .* 02:00"
  7447. (org-test-at-time "<2014-03-04 02:35>"
  7448. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 +8h>"
  7449. (org-todo "DONE")
  7450. (buffer-string)))))
  7451. (should
  7452. (string-match-p
  7453. "2014-03-04 .* 10:00"
  7454. (org-test-at-time "<2014-03-04 02:35>"
  7455. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 ++8h>"
  7456. (org-todo "DONE")
  7457. (buffer-string)))))
  7458. (should
  7459. (string-match-p
  7460. "2014-03-04 .* 10:35"
  7461. (org-test-at-time "<2014-03-04 02:35>"
  7462. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 .+8h>"
  7463. (org-todo "DONE")
  7464. (buffer-string)))))
  7465. ;; Do not repeat inactive time stamps with a repeater.
  7466. (should-not
  7467. (string-match-p
  7468. "\\[2014-03-29 .* \\+2y\\]"
  7469. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7470. (org-test-with-temp-text
  7471. "* TODO H\n[2012-03-29 Thu. +2y]"
  7472. (org-todo "DONE")
  7473. (buffer-string)))))
  7474. ;; Do not repeat commented time stamps.
  7475. (should-not
  7476. (string-prefix-p
  7477. "<2015-03-04 .* \\+1y>"
  7478. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7479. (org-test-with-temp-text
  7480. "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
  7481. (org-todo "DONE")
  7482. (buffer-string)))))
  7483. (should-not
  7484. (string-prefix-p
  7485. "<2015-03-04 .* \\+1y>"
  7486. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7487. (org-test-with-temp-text
  7488. "* TODO H
  7489. <2012-03-29 Thu. +2y>
  7490. #+BEGIN_EXAMPLE
  7491. <2014-03-04 Tue +1y>
  7492. #+END_EXAMPLE"
  7493. (org-todo "DONE")
  7494. (buffer-string)))))
  7495. ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
  7496. ;; entry, record time of last repeat.
  7497. (should-not
  7498. (string-match-p
  7499. ":LAST_REPEAT:"
  7500. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  7501. (org-log-repeat nil))
  7502. (cl-letf (((symbol-function 'org-add-log-setup)
  7503. (lambda (&rest _args) nil)))
  7504. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  7505. (org-todo "DONE")
  7506. (buffer-string))))))
  7507. (should
  7508. (string-match-p
  7509. ":LAST_REPEAT:"
  7510. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  7511. (org-log-repeat t))
  7512. (cl-letf (((symbol-function 'org-add-log-setup)
  7513. (lambda (&rest _args) nil)))
  7514. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  7515. (org-todo "DONE")
  7516. (buffer-string))))))
  7517. (should
  7518. (string-match-p
  7519. ":LAST_REPEAT:"
  7520. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7521. (cl-letf (((symbol-function 'org-add-log-setup)
  7522. (lambda (&rest _args) nil)))
  7523. (org-test-with-temp-text
  7524. "* TODO H\n<2012-03-29 Thu +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
  7525. (org-todo "DONE")
  7526. (buffer-string))))))
  7527. ;; When a SCHEDULED entry has no repeater, remove it upon repeating
  7528. ;; the entry as it is no longer relevant.
  7529. (should-not
  7530. (string-match-p
  7531. "^SCHEDULED:"
  7532. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7533. (org-test-with-temp-text
  7534. "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
  7535. (org-todo "DONE")
  7536. (buffer-string)))))
  7537. ;; Properly advance repeater even when a clock entry is specified
  7538. ;; and `org-log-repeat' is nil.
  7539. (should
  7540. (string-match-p
  7541. "SCHEDULED: <2014-03-29"
  7542. (let ((org-log-repeat nil)
  7543. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7544. (org-test-with-temp-text
  7545. "* TODO H
  7546. SCHEDULED: <2012-03-29 Thu +2y>
  7547. CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] => 6:40"
  7548. (org-todo "DONE")
  7549. (buffer-string)))))
  7550. ;; Make sure that logbook state change record does not get
  7551. ;; duplicated when `org-log-repeat' `org-log-done' are non-nil.
  7552. (should
  7553. (string-match-p
  7554. (rx "* TODO Read book
  7555. SCHEDULED: <2021-06-16 " (1+ (not space)) " +1d>
  7556. :PROPERTIES:
  7557. :LAST_REPEAT:" (1+ nonl) "
  7558. :END:
  7559. - State \"DONE\" from \"TODO\"" (1+ nonl) buffer-end)
  7560. (let ((org-log-repeat 'time)
  7561. (org-todo-keywords '((sequence "TODO" "|" "DONE(d!)")))
  7562. (org-log-into-drawer nil))
  7563. (org-test-with-temp-text
  7564. "* TODO Read book
  7565. SCHEDULED: <2021-06-15 Tue +1d>"
  7566. (org-todo "DONE")
  7567. (when (memq 'org-add-log-note post-command-hook)
  7568. (org-add-log-note))
  7569. (buffer-string))))))
  7570. (ert-deftest test-org/org-log-done ()
  7571. "Test `org-log-done' specifications."
  7572. ;; nil value.
  7573. (should
  7574. (string=
  7575. "* DONE task"
  7576. (let ((org-log-done nil)
  7577. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7578. (org-test-with-temp-text
  7579. "* TODO task"
  7580. (org-todo "DONE")
  7581. (when (memq 'org-add-log-note post-command-hook)
  7582. (org-add-log-note))
  7583. (buffer-string)))))
  7584. ;; `time' value.
  7585. (should
  7586. (string=
  7587. (format
  7588. "* DONE task
  7589. CLOSED: %s"
  7590. (org-test-with-temp-text ""
  7591. (org-insert-time-stamp (current-time) t t)
  7592. (buffer-string)))
  7593. (let ((org-log-done 'time)
  7594. (org-log-done-with-time t)
  7595. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7596. (org-test-with-temp-text
  7597. "* TODO task"
  7598. (org-todo "DONE")
  7599. (when (memq 'org-add-log-note post-command-hook)
  7600. (org-add-log-note))
  7601. (buffer-string)))))
  7602. (should
  7603. (string=
  7604. (format
  7605. "* DONE task
  7606. CLOSED: %s"
  7607. (org-test-with-temp-text ""
  7608. (org-insert-time-stamp (current-time) nil t)
  7609. (buffer-string)))
  7610. (let ((org-log-done 'time)
  7611. (org-log-done-with-time nil)
  7612. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7613. (org-test-with-temp-text
  7614. "* TODO task"
  7615. (org-todo "DONE")
  7616. (when (memq 'org-add-log-note post-command-hook)
  7617. (org-add-log-note))
  7618. (buffer-string)))))
  7619. ;; TODO: Test `note' value.
  7620. ;; Test startup overrides.
  7621. (should
  7622. (string=
  7623. "#+STARTUP: nologdone
  7624. * DONE task"
  7625. (let ((org-log-done 'time)
  7626. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7627. (org-test-with-temp-text
  7628. "#+STARTUP: nologdone
  7629. <point>* TODO task"
  7630. (org-set-regexps-and-options)
  7631. (org-todo "DONE")
  7632. (when (memq 'org-add-log-note post-command-hook)
  7633. (org-add-log-note))
  7634. (buffer-string)))))
  7635. (should
  7636. (string=
  7637. (format
  7638. "#+STARTUP: logdone
  7639. * DONE task
  7640. CLOSED: %s"
  7641. (org-test-with-temp-text ""
  7642. (org-insert-time-stamp (current-time) t t)
  7643. (buffer-string)))
  7644. (let ((org-log-done nil)
  7645. (org-log-done-with-time t)
  7646. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7647. (org-test-with-temp-text
  7648. "#+STARTUP: logdone
  7649. <point>* TODO task"
  7650. (org-set-regexps-and-options)
  7651. (org-todo "DONE")
  7652. (when (memq 'org-add-log-note post-command-hook)
  7653. (org-add-log-note))
  7654. (buffer-string)))))
  7655. ;; Test local property overrides.
  7656. (should
  7657. (string=
  7658. "* DONE task
  7659. :PROPERTIES:
  7660. :LOGGING: nil
  7661. :END:"
  7662. (let ((org-log-done 'time)
  7663. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7664. (org-test-with-temp-text
  7665. "* TODO task
  7666. :PROPERTIES:
  7667. :LOGGING: nil
  7668. :END:"
  7669. (org-todo "DONE")
  7670. (when (memq 'org-add-log-note post-command-hook)
  7671. (org-add-log-note))
  7672. (buffer-string)))))
  7673. (should
  7674. (string=
  7675. (format
  7676. "* DONE task
  7677. CLOSED: %s
  7678. :PROPERTIES:
  7679. :LOGGING: logdone
  7680. :END:"
  7681. (org-test-with-temp-text ""
  7682. (org-insert-time-stamp (current-time) t t)
  7683. (buffer-string)))
  7684. (let ((org-log-done nil)
  7685. (org-log-done-with-time t)
  7686. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7687. (org-test-with-temp-text
  7688. "* TODO task
  7689. :PROPERTIES:
  7690. :LOGGING: logdone
  7691. :END:"
  7692. (org-todo "DONE")
  7693. (when (memq 'org-add-log-note post-command-hook)
  7694. (org-add-log-note))
  7695. (buffer-string))))))
  7696. (ert-deftest test-org/org-todo-prefix ()
  7697. "Test `org-todo' prefix arg behavior."
  7698. ;; FIXME: Add tests for all other allowed prefix arguments.
  7699. ;; -1 prefix arg should cancel repeater and mark DONE.
  7700. (should
  7701. (string-match-p
  7702. "DONE H\\(.*\n\\)*<2012-03-29 Thu \\+0y>"
  7703. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7704. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7705. (org-todo -1)
  7706. (buffer-string)))))
  7707. ;; - prefix arg should cancel repeater and mark DONE.
  7708. (should
  7709. (string-match-p
  7710. "DONE H\\(.*\n\\)*<2012-03-29 Thu \\+0y>"
  7711. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7712. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7713. (org-todo '-)
  7714. (buffer-string))))))
  7715. ;;; Timestamps API
  7716. (ert-deftest test-org/at-timestamp-p ()
  7717. "Test `org-at-timestamp-p' specifications."
  7718. (should
  7719. (org-test-with-temp-text "<2012-03-29 Thu>"
  7720. (org-at-timestamp-p)))
  7721. (should-not
  7722. (org-test-with-temp-text "2012-03-29 Thu"
  7723. (org-at-timestamp-p)))
  7724. ;; Test return values.
  7725. (should
  7726. (eq 'bracket
  7727. (org-test-with-temp-text "<2012-03-29 Thu>"
  7728. (org-at-timestamp-p))))
  7729. (should
  7730. (eq 'year
  7731. (org-test-with-temp-text "<<point>2012-03-29 Thu>"
  7732. (org-at-timestamp-p))))
  7733. (should
  7734. (eq 'month
  7735. (org-test-with-temp-text "<2012-<point>03-29 Thu>"
  7736. (org-at-timestamp-p))))
  7737. (should
  7738. (eq 'day
  7739. (org-test-with-temp-text "<2012-03-<point>29 Thu>"
  7740. (org-at-timestamp-p))))
  7741. (should
  7742. (eq 'day
  7743. (org-test-with-temp-text "<2012-03-29 T<point>hu>"
  7744. (org-at-timestamp-p))))
  7745. (should
  7746. (wholenump
  7747. (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
  7748. (org-at-timestamp-p))))
  7749. (should
  7750. (eq 'bracket
  7751. (org-test-with-temp-text "<2012-03-29 Thu<point>>"
  7752. (org-at-timestamp-p))))
  7753. (should
  7754. (eq 'after
  7755. (org-test-with-temp-text "<2012-03-29 Thu><point>»"
  7756. (org-at-timestamp-p))))
  7757. ;; Test `inactive' optional argument.
  7758. (should
  7759. (org-test-with-temp-text "[2012-03-29 Thu]"
  7760. (org-at-timestamp-p 'inactive)))
  7761. (should-not
  7762. (org-test-with-temp-text "[2012-03-29 Thu]"
  7763. (org-at-timestamp-p)))
  7764. ;; When optional argument is `agenda', recognize time-stamps in
  7765. ;; planning info line, property drawers and clocks.
  7766. (should
  7767. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7768. (org-at-timestamp-p 'agenda)))
  7769. (should-not
  7770. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7771. (org-at-timestamp-p)))
  7772. (should
  7773. (org-test-with-temp-text
  7774. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7775. (org-at-timestamp-p 'agenda)))
  7776. (should-not
  7777. (org-test-with-temp-text
  7778. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7779. (org-at-timestamp-p)))
  7780. (should
  7781. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7782. (let ((org-agenda-include-inactive-timestamps t))
  7783. (org-at-timestamp-p 'agenda))))
  7784. (should-not
  7785. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7786. (let ((org-agenda-include-inactive-timestamps t))
  7787. (org-at-timestamp-p))))
  7788. (should-not
  7789. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7790. (let ((org-agenda-include-inactive-timestamps t))
  7791. (org-at-timestamp-p 'inactive))))
  7792. ;; When optional argument is `lax', match any part of the document
  7793. ;; with Org timestamp syntax.
  7794. (should
  7795. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7796. (org-at-timestamp-p 'lax)))
  7797. (should-not
  7798. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7799. (org-at-timestamp-p)))
  7800. (should
  7801. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7802. (org-at-timestamp-p 'lax)))
  7803. (should-not
  7804. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7805. (org-at-timestamp-p)))
  7806. (should
  7807. (org-test-with-temp-text
  7808. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7809. (org-at-timestamp-p 'lax)))
  7810. (should-not
  7811. (org-test-with-temp-text
  7812. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7813. (org-at-timestamp-p)))
  7814. ;; Optional argument `lax' also matches inactive timestamps.
  7815. (should
  7816. (org-test-with-temp-text "# [2012-03-29 Thu]<point>"
  7817. (org-at-timestamp-p 'lax))))
  7818. (ert-deftest test-org/time-stamp ()
  7819. "Test `org-time-stamp' specifications."
  7820. ;; Insert chosen time stamp at point.
  7821. (should
  7822. (string-match
  7823. "Te<2014-03-04 .*?>xt"
  7824. (org-test-with-temp-text "Te<point>xt"
  7825. (cl-letf (((symbol-function 'org-read-date)
  7826. (lambda (&rest _args)
  7827. (org-time-string-to-time "2014-03-04"))))
  7828. (org-time-stamp nil)
  7829. (buffer-string)))))
  7830. ;; With a prefix argument, also insert time.
  7831. (should
  7832. (string-match
  7833. "Te<2014-03-04 .*? 00:41>xt"
  7834. (org-test-with-temp-text "Te<point>xt"
  7835. (cl-letf (((symbol-function 'org-read-date)
  7836. (lambda (&rest _args)
  7837. (org-time-string-to-time "2014-03-04 00:41"))))
  7838. (org-time-stamp '(4))
  7839. (buffer-string)))))
  7840. ;; With two universal prefix arguments, insert an active timestamp
  7841. ;; with the current time without prompting the user.
  7842. (should
  7843. (string-match
  7844. "Te<2014-03-04 .*? 00:41>xt"
  7845. (org-test-with-temp-text "Te<point>xt"
  7846. (org-test-at-time "2014-03-04 00:41"
  7847. (org-time-stamp '(16))
  7848. (buffer-string)))))
  7849. ;; When optional argument is non-nil, insert an inactive timestamp.
  7850. (should
  7851. (string-match
  7852. "Te\\[2014-03-04 .*?\\]xt"
  7853. (org-test-with-temp-text "Te<point>xt"
  7854. (cl-letf (((symbol-function 'org-read-date)
  7855. (lambda (&rest _args)
  7856. (org-time-string-to-time "2014-03-04"))))
  7857. (org-time-stamp nil t)
  7858. (buffer-string)))))
  7859. ;; When called from a timestamp, replace existing one.
  7860. (should
  7861. (string-match
  7862. "<2014-03-04 .*?>"
  7863. (org-test-with-temp-text "<2012-03-29<point> thu.>"
  7864. (cl-letf (((symbol-function 'org-read-date)
  7865. (lambda (&rest _args)
  7866. (org-time-string-to-time "2014-03-04"))))
  7867. (org-time-stamp nil)
  7868. (buffer-string)))))
  7869. (should
  7870. (string-match
  7871. "<2014-03-04 .*?>--<2014-03-04 .*?>"
  7872. (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
  7873. (cl-letf (((symbol-function 'org-read-date)
  7874. (lambda (&rest _args)
  7875. (org-time-string-to-time "2014-03-04"))))
  7876. (org-time-stamp nil)
  7877. (buffer-string)))))
  7878. ;; When replacing a timestamp, preserve repeater, if any.
  7879. (should
  7880. (string-match
  7881. "<2014-03-04 .*? \\+2y>"
  7882. (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
  7883. (cl-letf (((symbol-function 'org-read-date)
  7884. (lambda (&rest _args)
  7885. (org-time-string-to-time "2014-03-04"))))
  7886. (org-time-stamp nil)
  7887. (buffer-string)))))
  7888. ;; When called twice in a raw, build a date range.
  7889. (should
  7890. (string-match
  7891. "<2012-03-29 .*?>--<2014-03-04 .*?>"
  7892. (org-test-with-temp-text "<2012-03-29 thu.><point>"
  7893. (cl-letf (((symbol-function 'org-read-date)
  7894. (lambda (&rest _args)
  7895. (org-time-string-to-time "2014-03-04"))))
  7896. (let ((last-command 'org-time-stamp)
  7897. (this-command 'org-time-stamp))
  7898. (org-time-stamp nil))
  7899. (buffer-string))))))
  7900. (ert-deftest test-org/timestamp-has-time-p ()
  7901. "Test `org-timestamp-has-time-p' specifications."
  7902. ;; With time.
  7903. (should
  7904. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7905. (org-timestamp-has-time-p (org-element-context))))
  7906. ;; Without time.
  7907. (should-not
  7908. (org-test-with-temp-text "<2012-03-29 Thu>"
  7909. (org-timestamp-has-time-p (org-element-context)))))
  7910. (ert-deftest test-org/get-repeat ()
  7911. "Test `org-get-repeat' specifications."
  7912. (should
  7913. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
  7914. (org-get-repeat)))
  7915. (should-not
  7916. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
  7917. (org-get-repeat)))
  7918. ;; Return proper repeat string.
  7919. (should
  7920. (equal "+2y"
  7921. (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
  7922. (org-get-repeat))))
  7923. ;; Prevent false positive (commented or verbatim time stamps)
  7924. (should-not
  7925. (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
  7926. (org-get-repeat)))
  7927. (should-not
  7928. (org-test-with-temp-text
  7929. "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
  7930. (org-get-repeat)))
  7931. ;; Return nil when called before first heading.
  7932. (should-not
  7933. (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
  7934. (org-get-repeat)))
  7935. ;; When called with an optional argument, extract repeater from that
  7936. ;; string instead.
  7937. (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
  7938. (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
  7939. (ert-deftest test-org/timestamp-format ()
  7940. "Test `org-timestamp-format' specifications."
  7941. ;; Regular test.
  7942. (should
  7943. (equal
  7944. "2012-03-29 16:40"
  7945. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7946. (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
  7947. ;; Range end.
  7948. (should
  7949. (equal
  7950. "2012-03-29"
  7951. (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
  7952. (org-timestamp-format (org-element-context) "%Y-%m-%d" t)))))
  7953. (ert-deftest test-org/timestamp-split-range ()
  7954. "Test `org-timestamp-split-range' specifications."
  7955. ;; Extract range start (active).
  7956. (should
  7957. (equal '(2012 3 29)
  7958. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7959. (let ((ts (org-timestamp-split-range (org-element-context))))
  7960. (mapcar (lambda (p) (org-element-property p ts))
  7961. '(:year-end :month-end :day-end))))))
  7962. ;; Extract range start (inactive)
  7963. (should
  7964. (equal '(2012 3 29)
  7965. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7966. (let ((ts (org-timestamp-split-range (org-element-context))))
  7967. (mapcar (lambda (p) (org-element-property p ts))
  7968. '(:year-end :month-end :day-end))))))
  7969. ;; Extract range end (active).
  7970. (should
  7971. (equal '(2012 3 30)
  7972. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7973. (let ((ts (org-timestamp-split-range
  7974. (org-element-context) t)))
  7975. (mapcar (lambda (p) (org-element-property p ts))
  7976. '(:year-end :month-end :day-end))))))
  7977. ;; Extract range end (inactive)
  7978. (should
  7979. (equal '(2012 3 30)
  7980. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7981. (let ((ts (org-timestamp-split-range
  7982. (org-element-context) t)))
  7983. (mapcar (lambda (p) (org-element-property p ts))
  7984. '(:year-end :month-end :day-end))))))
  7985. ;; Return the timestamp if not a range.
  7986. (should
  7987. (org-test-with-temp-text "[2012-03-29 Thu]"
  7988. (let* ((ts-orig (org-element-context))
  7989. (ts-copy (org-timestamp-split-range ts-orig)))
  7990. (eq ts-orig ts-copy))))
  7991. (should
  7992. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7993. (let* ((ts-orig (org-element-context))
  7994. (ts-copy (org-timestamp-split-range ts-orig)))
  7995. (eq ts-orig ts-copy)))))
  7996. (ert-deftest test-org/timestamp-translate ()
  7997. "Test `org-timestamp-translate' specifications."
  7998. ;; Translate whole date range.
  7999. (should
  8000. (equal "<29>--<30>"
  8001. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  8002. (let ((org-display-custom-times t)
  8003. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  8004. (org-timestamp-translate (org-element-context))))))
  8005. ;; Translate date range start.
  8006. (should
  8007. (equal "<29>"
  8008. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  8009. (let ((org-display-custom-times t)
  8010. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  8011. (org-timestamp-translate (org-element-context) 'start)))))
  8012. ;; Translate date range end.
  8013. (should
  8014. (equal "<30>"
  8015. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  8016. (let ((org-display-custom-times t)
  8017. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  8018. (org-timestamp-translate (org-element-context) 'end)))))
  8019. ;; Translate time range.
  8020. (should
  8021. (equal "<08>--<16>"
  8022. (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
  8023. (let ((org-display-custom-times t)
  8024. (org-time-stamp-custom-formats '("<%d>" . "<%H>")))
  8025. (org-timestamp-translate (org-element-context))))))
  8026. ;; Translate non-range timestamp.
  8027. (should
  8028. (equal "<29>"
  8029. (org-test-with-temp-text "<2012-03-29 Thu>"
  8030. (let ((org-display-custom-times t)
  8031. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  8032. (org-timestamp-translate (org-element-context))))))
  8033. ;; Do not change `diary' timestamps.
  8034. (should
  8035. (equal "<%%(org-float t 4 2)>"
  8036. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  8037. (let ((org-display-custom-times t)
  8038. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  8039. (org-timestamp-translate (org-element-context)))))))
  8040. (ert-deftest test-org/timestamp-from-string ()
  8041. "Test `org-timestamp-from-string' specifications."
  8042. ;; Return nil if argument is not a valid Org timestamp.
  8043. (should-not (org-timestamp-from-string ""))
  8044. (should-not (org-timestamp-from-string nil))
  8045. (should-not (org-timestamp-from-string "<2012-03-29"))
  8046. ;; Otherwise, return a valid Org timestamp object.
  8047. (should
  8048. (string-match-p "<2012-03-29 .+>"
  8049. (org-element-interpret-data
  8050. (org-timestamp-from-string "<2012-03-29 Thu>"))))
  8051. (should
  8052. (string-match-p "[2014-03-04 .+]"
  8053. (org-element-interpret-data
  8054. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  8055. (ert-deftest test-org/timestamp-from-time ()
  8056. "Test `org-timestamp-from-time' specifications."
  8057. ;; Standard test.
  8058. (should
  8059. (string-match-p
  8060. "<2012-03-29 .+>"
  8061. (org-element-interpret-data
  8062. (org-timestamp-from-time
  8063. (org-time-string-to-time "<2012-03-29 Thu 16:40>")))))
  8064. ;; When optional argument WITH-TIME is non-nil, provide time
  8065. ;; information.
  8066. (should
  8067. (string-match-p
  8068. "<2012-03-29 .+ 16:40>"
  8069. (org-element-interpret-data
  8070. (org-timestamp-from-time
  8071. (org-time-string-to-time "<2012-03-29 Thu 16:40>")
  8072. t))))
  8073. ;; When optional argument INACTIVE is non-nil, return an inactive
  8074. ;; timestamp.
  8075. (should
  8076. (string-match-p
  8077. "[2012-03-29 .+]"
  8078. (org-element-interpret-data
  8079. (org-timestamp-from-time
  8080. (org-time-string-to-time "<2012-03-29 Thu 16:40>")
  8081. nil t)))))
  8082. (ert-deftest test-org/timestamp-to-time ()
  8083. "Test `org-timestamp-to-time' specifications."
  8084. (should
  8085. (equal "2014-03-04"
  8086. (format-time-string
  8087. "%Y-%m-%d"
  8088. (org-timestamp-to-time
  8089. (org-timestamp-from-string "<2014-03-04 Tue>")))))
  8090. (should
  8091. (equal "2014-03-04"
  8092. (format-time-string
  8093. "%Y-%m-%d"
  8094. (org-timestamp-to-time
  8095. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  8096. (should
  8097. (equal "2012-03-29 08:30"
  8098. (format-time-string
  8099. "%Y-%m-%d %H:%M"
  8100. (org-timestamp-to-time
  8101. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")))))
  8102. (should
  8103. (equal "2012-03-29"
  8104. (format-time-string
  8105. "%Y-%m-%d"
  8106. (org-timestamp-to-time
  8107. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")))))
  8108. (should
  8109. (equal "2012-03-29"
  8110. (format-time-string
  8111. "%Y-%m-%d"
  8112. (org-timestamp-to-time
  8113. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")))))
  8114. ;; When optional argument END is non-nil, use end of date range or
  8115. ;; time range.
  8116. (should
  8117. (equal "2012-03-29 16:40"
  8118. (format-time-string
  8119. "%Y-%m-%d %H:%M"
  8120. (org-timestamp-to-time
  8121. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")
  8122. t))))
  8123. (should
  8124. (equal "2014-03-04"
  8125. (format-time-string
  8126. "%Y-%m-%d"
  8127. (org-timestamp-to-time
  8128. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")
  8129. t))))
  8130. (should
  8131. (equal "2014-03-04"
  8132. (format-time-string
  8133. "%Y-%m-%d"
  8134. (org-timestamp-to-time
  8135. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")
  8136. t)))))
  8137. ;;; Yank and Kill
  8138. (ert-deftest test-org/paste-subtree ()
  8139. "Test `org-paste-subtree' specifications."
  8140. ;; Return an error if text to yank is not a set of subtrees.
  8141. (should-error (org-paste-subtree nil "Text"))
  8142. ;; Adjust level according to current one.
  8143. (should
  8144. (equal "* H\n* Text\n"
  8145. (org-test-with-temp-text "* H\n<point>"
  8146. (org-paste-subtree nil "* Text")
  8147. (buffer-string))))
  8148. (should
  8149. (equal "* H1\n** H2\n** Text\n"
  8150. (org-test-with-temp-text "* H1\n** H2\n<point>"
  8151. (org-paste-subtree nil "* Text")
  8152. (buffer-string))))
  8153. ;; When not on a heading, move to next heading before yanking.
  8154. (should
  8155. (equal "* H1\nParagraph\n* Text\n* H2"
  8156. (org-test-with-temp-text "* H1\n<point>Paragraph\n* H2"
  8157. (org-paste-subtree nil "* Text")
  8158. (buffer-string))))
  8159. ;; If point is between two headings, use the deepest level.
  8160. (should
  8161. (equal "* H1\n\n* Text\n* H2"
  8162. (org-test-with-temp-text "* H1\n<point>\n* H2"
  8163. (org-paste-subtree nil "* Text")
  8164. (buffer-string))))
  8165. (should
  8166. (equal "** H1\n\n** Text\n* H2"
  8167. (org-test-with-temp-text "** H1\n<point>\n* H2"
  8168. (org-paste-subtree nil "* Text")
  8169. (buffer-string))))
  8170. (should
  8171. (equal "* H1\n\n** Text\n** H2"
  8172. (org-test-with-temp-text "* H1\n<point>\n** H2"
  8173. (org-paste-subtree nil "* Text")
  8174. (buffer-string))))
  8175. ;; When on an empty heading, after the stars, deduce the new level
  8176. ;; from the number of stars.
  8177. (should
  8178. (equal "*** Text\n"
  8179. (org-test-with-temp-text "*** <point>"
  8180. (org-paste-subtree nil "* Text")
  8181. (buffer-string))))
  8182. ;; Optional argument LEVEL forces a level for the subtree.
  8183. (should
  8184. (equal "* H\n*** Text\n"
  8185. (org-test-with-temp-text "* H<point>"
  8186. (org-paste-subtree 3 "* Text")
  8187. (buffer-string)))))
  8188. (ert-deftest test-org/cut-and-paste-subtree ()
  8189. "Test `org-cut-subtree' and `org-paste-subtree'."
  8190. (should
  8191. (equal
  8192. "* Two
  8193. two
  8194. * One
  8195. "
  8196. (org-test-with-temp-text
  8197. "* One
  8198. <point>* Two
  8199. two
  8200. "
  8201. (call-interactively #'org-cut-subtree)
  8202. (goto-char (point-min))
  8203. (call-interactively #'org-paste-subtree)
  8204. (buffer-string))))
  8205. (should
  8206. (equal
  8207. "* One
  8208. * Two
  8209. "
  8210. (org-test-with-temp-text
  8211. "* One
  8212. <point>* Two
  8213. "
  8214. (call-interactively #'org-cut-subtree)
  8215. (backward-char)
  8216. (call-interactively #'org-paste-subtree)
  8217. (buffer-string)))))
  8218. (ert-deftest test-org/org--open-file-format-command ()
  8219. "Test `org--open-file-format-command' helper for `org-open-file'."
  8220. (let ((system-type 'gnu/linux)) ; Fix behavior of `shell-quote-argument'.
  8221. ;; No additional groups in `org-file-apps' key.
  8222. (let ((file "/file.pdf")
  8223. (pattern "\\.pdf\\'"))
  8224. (should
  8225. (equal "simple /file.pdf"
  8226. (and (string-match pattern file)
  8227. (org--open-file-format-command
  8228. "simple %s" file file (match-data)))))
  8229. (should
  8230. (equal "single-quotes /file.pdf"
  8231. (and (string-match pattern file)
  8232. (org--open-file-format-command
  8233. "single-quotes '%s'" file file (match-data)))))
  8234. (should
  8235. (equal "double-quotes /file.pdf"
  8236. (and (string-match pattern file)
  8237. (org--open-file-format-command
  8238. "double-quotes \"%s\"" file file (match-data)))))
  8239. (should
  8240. (equal "quotes 'mismatch \"/file.pdf'"
  8241. (and (string-match pattern file)
  8242. (org--open-file-format-command
  8243. "quotes 'mismatch \"%s'" file file (match-data)))))
  8244. (should
  8245. (equal "no subst"
  8246. (and (string-match pattern file)
  8247. (org--open-file-format-command
  8248. "no subst" file file (match-data)))))
  8249. (should
  8250. (equal "% literal percent 100% %s"
  8251. (and (string-match pattern file)
  8252. (org--open-file-format-command
  8253. "\\% literal percent 100\\% \\%s" file file (match-data)))))
  8254. (should
  8255. (equal "escape \"/file.pdf\" \\ more"
  8256. (and (string-match pattern file)
  8257. (org--open-file-format-command
  8258. ;; Second quote is not escaped.
  8259. "escape \\\"%s\" \\\\ more" file file (match-data)))))
  8260. (should
  8261. (equal "/file.pdf file at start"
  8262. (and (string-match pattern file)
  8263. (org--open-file-format-command
  8264. "%s file at start" file file (match-data)))))
  8265. (should
  8266. (equal "backslash-newline\n/file.pdf"
  8267. (and (string-match pattern file)
  8268. (org--open-file-format-command
  8269. "backslash-newline\\\n%s" file file (match-data))))))
  8270. ;; Anchors within target file.
  8271. (let ((file "/page-search.pdf")
  8272. (link "/page-search.pdf::10::some words")
  8273. (pattern "\\.pdf::\\([0-9]+\\)::\\(.*\\)\\'"))
  8274. (should
  8275. (equal "zathura --page 10 --find some\\ words /page-search.pdf"
  8276. (and (string-match pattern link)
  8277. (org--open-file-format-command
  8278. "zathura --page '%1' --find %2 \"%s\"" file link (match-data)))))
  8279. ;; Unused %2.
  8280. (should
  8281. (equal "firefox file:///page-search.pdf\\#page=10"
  8282. (and (string-match pattern link)
  8283. (org--open-file-format-command
  8284. "firefox file://%s\\\\#page=%1" file link (match-data)))))
  8285. (should
  8286. (equal "adjucent-subst /page-search.pdfsome\\ words10some\\ words"
  8287. (and (string-match pattern link)
  8288. (org--open-file-format-command
  8289. "adjucent-subst %s%2'%1'%2" file link (match-data))))))
  8290. ;; No more than 9 substitutions are supported.
  8291. (let ((file "/many.pdf")
  8292. (link "/many.pdf::one:2:3:4:5:6:7:8:9:a:b:c")
  8293. (pattern (concat "\\.pdf:"
  8294. (mapconcat (lambda (_) ":\\([^:]+\\)")
  8295. (number-sequence 1 12)
  8296. "")
  8297. "\\'")))
  8298. (should
  8299. (equal "overflow /many.pdf::one:2:3:4:5:6:7:8:9:one0:one1:one2"
  8300. (and (string-match pattern link)
  8301. (org--open-file-format-command
  8302. "overflow %s::%1:%2:%3:%4:%5:%6:%7:%8:%9:%10:%11:%12"
  8303. file link (match-data))))))
  8304. ;; Percent character in link fields does not cause any problem.
  8305. (let ((file "/file-%2.pdf")
  8306. (link "/file-%2.pdf::anchor-%3::search %1")
  8307. (pattern "\\.pdf::\\([^:]+\\)::\\(.+\\)\\'"))
  8308. (should
  8309. (equal "percents --find search\\ \\%1 file:///file-\\%2.pdf\\#anchor-\\%3"
  8310. (and (string-match pattern link)
  8311. (org--open-file-format-command
  8312. "percents --find %2 file://%s\\\\#%1"
  8313. file link (match-data))))))
  8314. ;; Errors.
  8315. (let ((file "/error.pdf")
  8316. (pattern "\\.pdf\\'"))
  8317. (let* ((err (should-error
  8318. (and (string-match pattern file)
  8319. (org--open-file-format-command
  8320. "trailing-percent %s %" file file (match-data)))
  8321. :type 'error))
  8322. (err-text (cadr err)))
  8323. (should-not (unless (and (stringp err-text)
  8324. (string-match-p "\\`Invalid format .*%" err-text))
  8325. err)))
  8326. (let* ((err (should-error
  8327. (and (string-match pattern file)
  8328. (org--open-file-format-command
  8329. "trailing-backslash %s \\" file file (match-data)))
  8330. :type 'error))
  8331. (err-text (cadr err)))
  8332. (should-not (unless (and (stringp err-text)
  8333. (string-match-p "\\`Invalid format .*\\\\" err-text))
  8334. err)))
  8335. (let* ((err (should-error
  8336. (and (string-match pattern file)
  8337. (org--open-file-format-command
  8338. "percent-newline %\n%s" file file (match-data)))
  8339. :type 'error))
  8340. (err-text (cadr err)))
  8341. (should-not (unless (and (stringp err-text)
  8342. (string-match-p "\\`Invalid format .*%\n" err-text))
  8343. err)))
  8344. ;; Mailcap escape for "%" is "\%", not "%%".
  8345. (let* ((err (should-error
  8346. (and (string-match pattern file)
  8347. (org--open-file-format-command
  8348. "percent-percent %s%%" file file (match-data)))
  8349. :type 'error))
  8350. (err-text (cadr err)))
  8351. (should-not (unless (and (stringp err-text)
  8352. (string-match-p "\\`Invalid format .*%%" err-text))
  8353. err)))
  8354. ;; Mailcap allows "%t" for MIME type, but Org has no such information.
  8355. (let* ((err (should-error
  8356. (and (string-match pattern file)
  8357. (org--open-file-format-command
  8358. "percent-t-unsupported --type '%t' %s" file file (match-data)))
  8359. :type 'error))
  8360. (err-text (cadr err)))
  8361. (should-not (unless (and (stringp err-text)
  8362. (string-match-p "\\`Invalid format .*%t" err-text))
  8363. err))))
  8364. ;; Optional regular expression groups have no point in `org-file-apps' patterns.
  8365. (let* ((file "/error.pdf")
  8366. (link "/error.pdf::1")
  8367. (pattern "\\.pdf::\\([^:]+\\)\\(?:::\\(.+\\)\\)?\\'")
  8368. (err (should-error
  8369. (and (string-match pattern link)
  8370. (org--open-file-format-command
  8371. "no-such-match --search %2 %s" file link (match-data)))
  8372. :type 'error))
  8373. (err-text (cadr err)))
  8374. (should-not (unless (and (stringp err-text)
  8375. (string-match-p "\\`Invalid format.*%2" err-text))
  8376. err)))))
  8377. (provide 'test-org)
  8378. ;;; test-org.el ends here