test-org.el 257 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917
  1. ;;; test-org.el --- tests for org.el
  2. ;; Copyright (c) David Maus
  3. ;; Authors: David Maus
  4. ;; This file is not part of GNU Emacs.
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;; Template test file for Org tests
  16. ;;; Code:
  17. (eval-and-compile (require 'cl-lib))
  18. ;;; Comments
  19. (ert-deftest test-org/toggle-comment ()
  20. "Test `org-toggle-comment' specifications."
  21. ;; Simple headline.
  22. (should
  23. (equal "* Test"
  24. (org-test-with-temp-text "* COMMENT Test"
  25. (org-toggle-comment)
  26. (buffer-string))))
  27. (should
  28. (equal "* COMMENT Test"
  29. (org-test-with-temp-text "* Test"
  30. (org-toggle-comment)
  31. (buffer-string))))
  32. ;; Headline with a regular keyword.
  33. (should
  34. (equal "* TODO Test"
  35. (org-test-with-temp-text "* TODO COMMENT Test"
  36. (org-toggle-comment)
  37. (buffer-string))))
  38. (should
  39. (equal "* TODO COMMENT Test"
  40. (org-test-with-temp-text "* TODO Test"
  41. (org-toggle-comment)
  42. (buffer-string))))
  43. ;; Empty headline.
  44. (should
  45. (equal "* "
  46. (org-test-with-temp-text "* COMMENT"
  47. (org-toggle-comment)
  48. (buffer-string))))
  49. (should
  50. (equal "* COMMENT"
  51. (org-test-with-temp-text "* "
  52. (org-toggle-comment)
  53. (buffer-string))))
  54. ;; Headline with a single keyword.
  55. (should
  56. (equal "* TODO "
  57. (org-test-with-temp-text "* TODO COMMENT"
  58. (org-toggle-comment)
  59. (buffer-string))))
  60. (should
  61. (equal "* TODO COMMENT"
  62. (org-test-with-temp-text "* TODO"
  63. (org-toggle-comment)
  64. (buffer-string))))
  65. ;; Headline with a keyword, a priority cookie and contents.
  66. (should
  67. (equal "* TODO [#A] Headline"
  68. (org-test-with-temp-text "* TODO [#A] COMMENT Headline"
  69. (org-toggle-comment)
  70. (buffer-string))))
  71. (should
  72. (equal "* TODO [#A] COMMENT Headline"
  73. (org-test-with-temp-text "* TODO [#A] Headline"
  74. (org-toggle-comment)
  75. (buffer-string)))))
  76. (ert-deftest test-org/comment-dwim ()
  77. "Test `comment-dwim' behaviour in an Org buffer."
  78. ;; No region selected, no comment on current line and line not
  79. ;; empty: insert comment on line above.
  80. (should
  81. (equal "# \nComment"
  82. (org-test-with-temp-text "Comment"
  83. (call-interactively #'org-comment-dwim)
  84. (buffer-string))))
  85. ;; No region selected, no comment on current line and line empty:
  86. ;; insert comment on this line.
  87. (should
  88. (equal "# \nParagraph"
  89. (org-test-with-temp-text "\nParagraph"
  90. (call-interactively #'org-comment-dwim)
  91. (buffer-string))))
  92. ;; No region selected, and a comment on this line: indent it.
  93. (should
  94. (equal "* Headline\n # Comment"
  95. (org-test-with-temp-text "* Headline\n# <point>Comment"
  96. (let ((org-adapt-indentation t))
  97. (call-interactively #'org-comment-dwim))
  98. (buffer-string))))
  99. ;; Also recognize single # at column 0 as comments.
  100. (should
  101. (equal "# Comment"
  102. (org-test-with-temp-text "# Comment"
  103. (call-interactively #'org-comment-dwim)
  104. (buffer-string))))
  105. ;; Region selected and only comments and blank lines within it:
  106. ;; un-comment all commented lines.
  107. (should
  108. (equal "Comment 1\n\nComment 2"
  109. (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
  110. (transient-mark-mode 1)
  111. (push-mark (point) t t)
  112. (goto-char (point-max))
  113. (call-interactively #'org-comment-dwim)
  114. (buffer-string))))
  115. ;; Region selected without comments: comment all lines if
  116. ;; `comment-empty-lines' is non-nil, only non-blank lines otherwise.
  117. (should
  118. (equal "# Comment 1\n\n# Comment 2"
  119. (org-test-with-temp-text "Comment 1\n\nComment 2"
  120. (transient-mark-mode 1)
  121. (push-mark (point) t t)
  122. (goto-char (point-max))
  123. (let ((comment-empty-lines nil))
  124. (call-interactively #'org-comment-dwim))
  125. (buffer-string))))
  126. (should
  127. (equal "# Comment 1\n# \n# Comment 2"
  128. (org-test-with-temp-text "Comment 1\n\nComment 2"
  129. (transient-mark-mode 1)
  130. (push-mark (point) t t)
  131. (goto-char (point-max))
  132. (let ((comment-empty-lines t))
  133. (call-interactively #'org-comment-dwim))
  134. (buffer-string))))
  135. ;; In front of a keyword without region, insert a new comment.
  136. (should
  137. (equal "# \n#+KEYWORD: value"
  138. (org-test-with-temp-text "#+KEYWORD: value"
  139. (call-interactively #'org-comment-dwim)
  140. (buffer-string))))
  141. ;; Comment a heading
  142. (should
  143. (equal "* COMMENT Test"
  144. (org-test-with-temp-text "* Test"
  145. (call-interactively #'org-comment-dwim)
  146. (buffer-string))))
  147. ;; In a source block, use appropriate syntax.
  148. (should
  149. (equal " ;; "
  150. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n<point>\n#+END_SRC"
  151. (let ((org-edit-src-content-indentation 2))
  152. (call-interactively #'org-comment-dwim))
  153. (buffer-substring-no-properties (line-beginning-position)
  154. (point)))))
  155. (should
  156. (equal "#+BEGIN_SRC emacs-lisp\n ;; a\n ;; b\n#+END_SRC"
  157. (org-test-with-temp-text
  158. "#+BEGIN_SRC emacs-lisp\n<point>a\nb\n#+END_SRC"
  159. (transient-mark-mode 1)
  160. (push-mark (point) t t)
  161. (forward-line 2)
  162. (let ((org-edit-src-content-indentation 2))
  163. (call-interactively #'org-comment-dwim))
  164. (buffer-string)))))
  165. ;;; Date and time analysis
  166. (ert-deftest test-org/org-read-date ()
  167. "Test `org-read-date' specifications."
  168. ;; Parse ISO date with abbreviated year and month.
  169. (should (equal "2012-03-29 16:40"
  170. (let ((org-time-was-given t))
  171. (org-read-date t nil "12-3-29 16:40"))))
  172. ;; Parse Europeans dates.
  173. (should (equal "2012-03-29 16:40"
  174. (let ((org-time-was-given t))
  175. (org-read-date t nil "29.03.2012 16:40"))))
  176. ;; Parse Europeans dates without year.
  177. (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
  178. (let ((org-time-was-given t))
  179. (org-read-date t nil "29.03. 16:40"))))
  180. ;; Relative date applied to current time if there is single
  181. ;; plus/minus, or to default date when there are two of them.
  182. (should
  183. (equal
  184. "2015-03-04"
  185. (org-test-at-time "2014-03-04"
  186. (org-read-date
  187. t nil "+1y" nil
  188. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))
  189. (should
  190. (equal
  191. "2013-03-29"
  192. (org-test-at-time "2014-03-04"
  193. (org-read-date
  194. t nil "++1y" nil
  195. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))
  196. ;; When `org-read-date-prefer-future' is non-nil, prefer future
  197. ;; dates (relatively to now) when incomplete. Otherwise, use
  198. ;; default date.
  199. (should
  200. (equal
  201. "2014-04-01"
  202. (org-test-at-time "2014-03-04"
  203. (let ((org-read-date-prefer-future t))
  204. (org-read-date t nil "1")))))
  205. (should
  206. (equal
  207. "2013-03-04"
  208. (org-test-at-time "2012-03-29"
  209. (let ((org-read-date-prefer-future t))
  210. (org-read-date t nil "3-4")))))
  211. (should
  212. (equal
  213. "2012-03-04"
  214. (org-test-at-time "2012-03-29"
  215. (let ((org-read-date-prefer-future nil))
  216. (org-read-date t nil "3-4")))))
  217. ;; When set to `org-read-date-prefer-future' is set to `time', read
  218. ;; day is moved to tomorrow if specified hour is before current
  219. ;; time. However, it only happens in no other part of the date is
  220. ;; specified.
  221. (should
  222. (equal
  223. "2012-03-30"
  224. (org-test-at-time "2012-03-29 16:40"
  225. (let ((org-read-date-prefer-future 'time))
  226. (org-read-date t nil "00:40" nil)))))
  227. (should-not
  228. (equal
  229. "2012-03-30"
  230. (org-test-at-time "2012-03-29 16:40"
  231. (let ((org-read-date-prefer-future 'time))
  232. (org-read-date t nil "29 00:40" nil)))))
  233. ;; Caveat: `org-read-date-prefer-future' always refers to current
  234. ;; time, not default time, when they differ.
  235. (should
  236. (equal
  237. "2014-04-01"
  238. (org-test-at-time "2014-03-04"
  239. (let ((org-read-date-prefer-future t))
  240. (org-read-date
  241. t nil "1" nil
  242. (apply #'encode-time (org-parse-time-string "2012-03-29")))))))
  243. (should
  244. (equal
  245. "2014-03-25"
  246. (org-test-at-time "2014-03-04"
  247. (let ((org-read-date-prefer-future t))
  248. (org-read-date
  249. t nil "25" nil
  250. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))))
  251. (ert-deftest test-org/org-parse-time-string ()
  252. "Test `org-parse-time-string'."
  253. (should (equal (org-parse-time-string "2012-03-29 16:40")
  254. '(0 40 16 29 3 2012 nil nil nil)))
  255. (should (equal (org-parse-time-string "[2012-03-29 16:40]")
  256. '(0 40 16 29 3 2012 nil nil nil)))
  257. (should (equal (org-parse-time-string "<2012-03-29 16:40>")
  258. '(0 40 16 29 3 2012 nil nil nil)))
  259. (should (equal (org-parse-time-string "<2012-03-29>")
  260. '(0 0 0 29 3 2012 nil nil nil)))
  261. (should (equal (org-parse-time-string "<2012-03-29>" t)
  262. '(0 nil nil 29 3 2012 nil nil nil))))
  263. (ert-deftest test-org/closest-date ()
  264. "Test `org-closest-date' specifications."
  265. (require 'calendar)
  266. ;; Time stamps without a repeater are returned unchanged.
  267. (should
  268. (equal
  269. '(3 29 2012)
  270. (calendar-gregorian-from-absolute
  271. (org-closest-date "<2012-03-29>" "<2014-03-04>" nil))))
  272. ;; Time stamps with a null repeater are returned unchanged.
  273. (should
  274. (equal
  275. '(3 29 2012)
  276. (calendar-gregorian-from-absolute
  277. (org-closest-date "<2012-03-29 +0d>" "<2014-03-04>" nil))))
  278. ;; if PREFER is set to `past' always return a date before, or equal
  279. ;; to CURRENT.
  280. (should
  281. (equal
  282. '(3 1 2014)
  283. (calendar-gregorian-from-absolute
  284. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'past))))
  285. (should
  286. (equal
  287. '(3 4 2014)
  288. (calendar-gregorian-from-absolute
  289. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'past))))
  290. ;; if PREFER is set to `future' always return a date before, or equal
  291. ;; to CURRENT.
  292. (should
  293. (equal
  294. '(3 29 2014)
  295. (calendar-gregorian-from-absolute
  296. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'future))))
  297. (should
  298. (equal
  299. '(3 4 2014)
  300. (calendar-gregorian-from-absolute
  301. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'future))))
  302. ;; If PREFER is neither `past' nor `future', select closest date.
  303. (should
  304. (equal
  305. '(3 1 2014)
  306. (calendar-gregorian-from-absolute
  307. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" nil))))
  308. (should
  309. (equal
  310. '(5 4 2014)
  311. (calendar-gregorian-from-absolute
  312. (org-closest-date "<2012-03-04 +1m>" "<2014-04-28>" nil))))
  313. ;; Test "day" repeater.
  314. (should
  315. (equal '(3 8 2014)
  316. (calendar-gregorian-from-absolute
  317. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'past))))
  318. (should
  319. (equal '(3 10 2014)
  320. (calendar-gregorian-from-absolute
  321. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'future))))
  322. ;; Test "month" repeater.
  323. (should
  324. (equal '(1 5 2015)
  325. (calendar-gregorian-from-absolute
  326. (org-closest-date "<2014-03-05 +2m>" "<2015-02-04>" 'past))))
  327. (should
  328. (equal '(3 29 2014)
  329. (calendar-gregorian-from-absolute
  330. (org-closest-date "<2012-03-29 +2m>" "<2014-03-04>" 'future))))
  331. ;; Test "year" repeater.
  332. (should
  333. (equal '(3 5 2014)
  334. (calendar-gregorian-from-absolute
  335. (org-closest-date "<2014-03-05 +2y>" "<2015-02-04>" 'past))))
  336. (should
  337. (equal '(3 29 2014)
  338. (calendar-gregorian-from-absolute
  339. (org-closest-date "<2012-03-29 +2y>" "<2014-03-04>" 'future)))))
  340. (ert-deftest test-org/deadline-close-p ()
  341. "Test `org-deadline-close-p' specifications."
  342. (org-test-at-time "2016-06-03 Fri 01:43"
  343. ;; Timestamps are close if they are within `ndays' of lead time.
  344. (org-test-with-temp-text "* Heading"
  345. (should (org-deadline-close-p "2016-06-03 Fri" 0))
  346. (should (org-deadline-close-p "2016-06-02 Thu" 0))
  347. (should-not (org-deadline-close-p "2016-06-04 Sat" 0))
  348. (should (org-deadline-close-p "2016-06-04 Sat" 1))
  349. (should (org-deadline-close-p "2016-06-03 Fri 12:00" 0)))
  350. ;; Read `ndays' from timestamp if argument not given.
  351. (org-test-with-temp-text "* H"
  352. (should (org-deadline-close-p "2016-06-04 Sat -1d"))
  353. (should-not (org-deadline-close-p "2016-06-04 Sat -0d"))
  354. (should (org-deadline-close-p "2016-06-10 Fri -1w"))
  355. (should-not (org-deadline-close-p "2016-06-11 Sat -1w")))
  356. ;; Prefer `ndays' argument over lead time in timestamp.
  357. (org-test-with-temp-text "* H"
  358. (should (org-deadline-close-p "2016-06-04 Sat -0d" 1))
  359. (should-not (org-deadline-close-p "2016-06-04 Sat -0d" 0)))
  360. ;; Completed tasks are never close.
  361. (let ((org-todo-keywords '(("TODO" "|" "DONE"))))
  362. (org-test-with-temp-text "* TODO Heading"
  363. (should (org-deadline-close-p "2016-06-03")))
  364. (org-test-with-temp-text "* DONE Heading"
  365. (should-not (org-deadline-close-p "2016-06-03"))))))
  366. ;;; Drawers
  367. (ert-deftest test-org/at-property-p ()
  368. "Test `org-at-property-p' specifications."
  369. (should
  370. (equal 't
  371. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:PROP: t\n:END:\n"
  372. (org-at-property-p))))
  373. (should
  374. (equal 't
  375. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n:END:\n"
  376. (org-at-property-p)))))
  377. (ert-deftest test-org/at-property-drawer-p ()
  378. "Test `org-at-property-drawer-p' specifications."
  379. (should
  380. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:PROP: t\n:END:\n"
  381. (org-at-property-drawer-p)))
  382. (should
  383. (org-test-with-temp-text ":PROPERTIES:\n:PROP: t\n:END:\n"
  384. (org-at-property-drawer-p)))
  385. ;; The function only returns t if point is at the first line of
  386. ;; a property block.
  387. (should-not
  388. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n:END:\n"
  389. (org-at-property-drawer-p)))
  390. ;; The function ignores incomplete drawers.
  391. (should-not
  392. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n"
  393. (org-at-property-drawer-p))))
  394. (ert-deftest test-org/get-property-block ()
  395. "Test `org-get-property-block' specifications."
  396. (should
  397. (equal '(14 . 14)
  398. (org-test-with-temp-text ":PROPERTIES:\n:END:\n* H\n"
  399. (org-get-property-block))))
  400. (should
  401. (equal '(14 . 14)
  402. (org-test-with-temp-text ":PROPERTIES:\n:END:\n"
  403. (org-get-property-block))))
  404. ;; Comments above a document property block is ok.
  405. (should
  406. (equal '(18 . 18)
  407. (org-test-with-temp-text "# C\n:PROPERTIES:\n:END:\n"
  408. (org-get-property-block))))
  409. ;; Keywords above a document property block is ok.
  410. (should
  411. (equal '(22 . 22)
  412. (org-test-with-temp-text "# C\n# C\n:PROPERTIES:\n:END:\n"
  413. (org-get-property-block))))
  414. ;; Comments and keywords are allowed before a document property block.
  415. (should
  416. (equal '(18 . 27)
  417. (org-test-with-temp-text "# C\n:PROPERTIES:\n:KEY: V:\n:END:\n"
  418. (org-get-property-block))))
  419. ;; A document property block will not be valid if there are lines
  420. ;; with whitespace above it
  421. (should-not
  422. (org-test-with-temp-text "\n:PROPERTIES:\n:END:\n"
  423. (org-get-property-block)))
  424. (should
  425. (equal '(18 . 18)
  426. (org-test-with-temp-text "* H\n:PROPERTIES:\n:END:\n<point>"
  427. (org-get-property-block))))
  428. (should
  429. (equal "* H\n:PROPERTIES:\n:END:\n"
  430. (org-test-with-temp-text "* H"
  431. (let ((org-adapt-indentation nil))
  432. (org-get-property-block nil 'force))
  433. (buffer-string))))
  434. (should
  435. (equal ":PROPERTIES:\n:END:\n"
  436. (org-test-with-temp-text ""
  437. (org-get-property-block nil 'force)
  438. (buffer-string))))
  439. (should
  440. (equal "* H1\n :PROPERTIES:\n :END:\n* H2"
  441. (org-test-with-temp-text "* H1\n* H2"
  442. (let ((org-adapt-indentation t))
  443. (org-get-property-block nil 'force))
  444. (buffer-string)))))
  445. (ert-deftest test-org/insert-property-drawer ()
  446. "Test `org-insert-property-drawer' specifications."
  447. ;; Insert drawer in empty buffer
  448. (should
  449. (equal ":PROPERTIES:\n:END:\n"
  450. (org-test-with-temp-text ""
  451. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  452. (buffer-string))))
  453. ;; Insert drawer in document header with existing comment and
  454. ;; keyword.
  455. (should
  456. (equal "# C\n:PROPERTIES:\n:END:\n#+TITLE: T"
  457. (org-test-with-temp-text "# C\n#+TITLE: T"
  458. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  459. (buffer-string))))
  460. ;; Insert drawer in document header with existing keyword.
  461. (should
  462. (equal ":PROPERTIES:\n:END:\n#+TITLE: T"
  463. (org-test-with-temp-text "#+TITLE: T"
  464. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  465. (buffer-string))))
  466. (should
  467. (equal ":PROPERTIES:\n:END:"
  468. (org-test-with-temp-text ":PROPERTIES:\n:END:"
  469. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  470. (buffer-string))))
  471. ;; Insert drawer in document header with one existing heading in buffer.
  472. (should
  473. (equal ":PROPERTIES:\n:END:\n\n* T\n"
  474. (org-test-with-temp-text "\n* T\n"
  475. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  476. (buffer-string))))
  477. ;; Insert drawer right after headline if there is no planning line,
  478. ;; or after it otherwise.
  479. (should
  480. (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
  481. (org-test-with-temp-text "* H\nParagraph<point>"
  482. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  483. (buffer-string))))
  484. (should
  485. (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
  486. (org-test-with-temp-text
  487. "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
  488. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  489. (buffer-string))))
  490. ;; Indent inserted drawer.
  491. (should
  492. (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
  493. (org-test-with-temp-text "* H\nParagraph<point>"
  494. (let ((org-adapt-indentation t)) (org-insert-property-drawer))
  495. (buffer-string))))
  496. ;; Handle insertion at eob.
  497. (should
  498. (equal "* H\n:PROPERTIES:\n:END:\n"
  499. (org-test-with-temp-text "* H"
  500. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  501. (buffer-string))))
  502. ;; Skip inlinetasks before point.
  503. (when (featurep 'org-inlinetask)
  504. (should
  505. (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
  506. (org-test-with-temp-text
  507. "* H\n*************** I\n*************** END\nP<point>"
  508. (let ((org-adapt-indentation nil)
  509. (org-inlinetask-min-level 15))
  510. (org-insert-property-drawer))
  511. (buffer-string)))))
  512. ;; Correctly set drawer in an inlinetask.
  513. (when (featurep 'org-inlinetask)
  514. (should
  515. (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
  516. (org-test-with-temp-text
  517. "* H\n*************** I\nP<point>\n*************** END"
  518. (let ((org-adapt-indentation nil)
  519. (org-inlinetask-min-level 15))
  520. (org-insert-property-drawer))
  521. (buffer-string))))))
  522. ;;; Filling
  523. (ert-deftest test-org/fill-element ()
  524. "Test `org-fill-element' specifications."
  525. ;; At an Org table, align it.
  526. (should
  527. (equal "| a |\n"
  528. (org-test-with-temp-text "|a|"
  529. (org-fill-element)
  530. (buffer-string))))
  531. (should
  532. (equal "#+name: table\n| a |\n"
  533. (org-test-with-temp-text "#+name: table\n| a |\n"
  534. (org-fill-element)
  535. (buffer-string))))
  536. ;; At a paragraph, preserve line breaks.
  537. (org-test-with-temp-text "some \\\\\nlong\ntext"
  538. (let ((fill-column 20))
  539. (org-fill-element)
  540. (should (equal (buffer-string) "some \\\\\nlong text"))))
  541. ;; Correctly fill a paragraph when point is at its very end.
  542. (should
  543. (equal "A B"
  544. (org-test-with-temp-text "A\nB"
  545. (let ((fill-column 20))
  546. (goto-char (point-max))
  547. (org-fill-element)
  548. (buffer-string)))))
  549. ;; Correctly fill the last paragraph of a greater element.
  550. (should
  551. (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
  552. (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
  553. (let ((fill-column 8))
  554. (forward-line)
  555. (end-of-line)
  556. (org-fill-element)
  557. (buffer-string)))))
  558. ;; Correctly fill an element in a narrowed buffer.
  559. (should
  560. (equal "01234\n6"
  561. (org-test-with-temp-text "01234 6789"
  562. (let ((fill-column 5))
  563. (narrow-to-region 1 8)
  564. (org-fill-element)
  565. (buffer-string)))))
  566. ;; Handle `adaptive-fill-regexp' in paragraphs.
  567. (should
  568. (equal "> a b"
  569. (org-test-with-temp-text "> a\n> b"
  570. (let ((fill-column 5)
  571. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  572. (org-fill-element)
  573. (buffer-string)))))
  574. ;; Special case: Fill first paragraph when point is at an item or
  575. ;; a plain-list or a footnote reference.
  576. (should
  577. (equal "- A B"
  578. (org-test-with-temp-text "- A\n B"
  579. (let ((fill-column 20))
  580. (org-fill-element)
  581. (buffer-string)))))
  582. (should
  583. (equal "[fn:1] A B"
  584. (org-test-with-temp-text "[fn:1] A\nB"
  585. (let ((fill-column 20))
  586. (org-fill-element)
  587. (buffer-string)))))
  588. (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
  589. (let ((fill-column 20))
  590. (org-fill-element)
  591. (should (equal (buffer-string)
  592. "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
  593. ;; Fill contents of `comment-block' elements.
  594. (should
  595. (equal
  596. (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
  597. (let ((fill-column 20))
  598. (forward-line)
  599. (org-fill-element)
  600. (buffer-string)))
  601. "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
  602. ;; Fill `comment' elements.
  603. (should
  604. (equal " # A B"
  605. (org-test-with-temp-text " # A\n # B"
  606. (let ((fill-column 20))
  607. (org-fill-element)
  608. (buffer-string)))))
  609. ;; Do not mix consecutive comments when filling one of them.
  610. (should
  611. (equal "# A B\n\n# C"
  612. (org-test-with-temp-text "# A\n# B\n\n# C"
  613. (let ((fill-column 20))
  614. (org-fill-element)
  615. (buffer-string)))))
  616. ;; Use commented empty lines as separators when filling comments.
  617. (should
  618. (equal "# A B\n#\n# C"
  619. (org-test-with-temp-text "# A\n# B\n#\n# C"
  620. (let ((fill-column 20))
  621. (org-fill-element)
  622. (buffer-string)))))
  623. ;; Handle `adaptive-fill-regexp' in comments.
  624. (should
  625. (equal "# > a b"
  626. (org-test-with-temp-text "# > a\n# > b"
  627. (let ((fill-column 20)
  628. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  629. (org-fill-element)
  630. (buffer-string)))))
  631. ;; Do nothing at affiliated keywords.
  632. (should
  633. (equal "#+NAME: para\nSome\ntext."
  634. (org-test-with-temp-text "#+NAME: para\nSome\ntext."
  635. (let ((fill-column 20))
  636. (org-fill-element)
  637. (buffer-string)))))
  638. ;; Do not move point after table when filling a table.
  639. (should-not
  640. (org-test-with-temp-text "| a | b |\n| c | d |\n"
  641. (forward-char)
  642. (org-fill-element)
  643. (eobp)))
  644. ;; Do not fill "n" macro, with or without arguments, followed by
  645. ;; a dot or a closing parenthesis since it could be confused with
  646. ;; a numbered bullet.
  647. (should-not
  648. (equal "123456789\n{{{n}}}."
  649. (org-test-with-temp-text "123456789 {{{n}}}."
  650. (let ((fill-column 10))
  651. (org-fill-element)
  652. (buffer-string)))))
  653. (should-not
  654. (equal "123456789\n{{{n}}}\)"
  655. (org-test-with-temp-text "123456789 {{{n}}}\)"
  656. (let ((fill-column 10))
  657. (org-fill-element)
  658. (buffer-string)))))
  659. (should-not
  660. (equal "123456789\n{{{n()}}}."
  661. (org-test-with-temp-text "123456789 {{{n()}}}."
  662. (let ((fill-column 10))
  663. (org-fill-element)
  664. (buffer-string)))))
  665. (should-not
  666. (equal "123456789\n{{{n(counter)}}}."
  667. (org-test-with-temp-text "123456789 {{{n(counter)}}}."
  668. (let ((fill-column 10))
  669. (org-fill-element)
  670. (buffer-string))))))
  671. (ert-deftest test-org/auto-fill-function ()
  672. "Test auto-filling features."
  673. ;; Auto fill paragraph.
  674. (should
  675. (equal "12345\n7890"
  676. (org-test-with-temp-text "12345 7890"
  677. (let ((fill-column 5))
  678. (end-of-line)
  679. (org-auto-fill-function)
  680. (buffer-string)))))
  681. ;; Auto fill first paragraph in an item.
  682. (should
  683. (equal "- 12345\n 7890"
  684. (org-test-with-temp-text "- 12345 7890"
  685. (let ((fill-column 7))
  686. (end-of-line)
  687. (org-auto-fill-function)
  688. (buffer-string)))))
  689. ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
  690. (should
  691. (equal "> 12345\n 7890"
  692. (org-test-with-temp-text "> 12345 7890"
  693. (let ((fill-column 10)
  694. (adaptive-fill-regexp "[ \t]*>+[ \t]*")
  695. (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
  696. (end-of-line)
  697. (org-auto-fill-function)
  698. (buffer-string)))))
  699. (should
  700. (equal "> 12345\n> 12345\n> 7890"
  701. (org-test-with-temp-text "> 12345\n> 12345 7890"
  702. (let ((fill-column 10)
  703. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  704. (goto-char (point-max))
  705. (org-auto-fill-function)
  706. (buffer-string)))))
  707. (should-not
  708. (equal " 12345\n *12345\n *12345"
  709. (org-test-with-temp-text " 12345\n *12345 12345"
  710. (let ((fill-column 10)
  711. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  712. (goto-char (point-max))
  713. (org-auto-fill-function)
  714. (buffer-string)))))
  715. ;; Auto fill comments.
  716. (should
  717. (equal " # 12345\n # 7890"
  718. (org-test-with-temp-text " # 12345 7890"
  719. (let ((fill-column 10))
  720. (end-of-line)
  721. (org-auto-fill-function)
  722. (buffer-string)))))
  723. ;; A hash within a line isn't a comment.
  724. (should-not
  725. (equal "12345 # 7890\n# 1"
  726. (org-test-with-temp-text "12345 # 7890 1"
  727. (let ((fill-column 12))
  728. (end-of-line)
  729. (org-auto-fill-function)
  730. (buffer-string)))))
  731. ;; Correctly interpret empty prefix.
  732. (should-not
  733. (equal "# a\n# b\nRegular\n# paragraph"
  734. (org-test-with-temp-text "# a\n# b\nRegular paragraph"
  735. (let ((fill-column 12))
  736. (end-of-line 3)
  737. (org-auto-fill-function)
  738. (buffer-string)))))
  739. ;; Comment block: auto fill contents.
  740. (should
  741. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  742. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  743. (let ((fill-column 5))
  744. (forward-line)
  745. (end-of-line)
  746. (org-auto-fill-function)
  747. (buffer-string)))))
  748. (should
  749. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  750. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  751. (let ((fill-column 5))
  752. (forward-line)
  753. (end-of-line)
  754. (org-auto-fill-function)
  755. (buffer-string)))))
  756. ;; Do not fill if a new item could be created.
  757. (should-not
  758. (equal "12345\n- 90"
  759. (org-test-with-temp-text "12345 - 90"
  760. (let ((fill-column 5))
  761. (end-of-line)
  762. (org-auto-fill-function)
  763. (buffer-string)))))
  764. ;; Do not fill if a line break could be introduced.
  765. (should-not
  766. (equal "123\\\\\n7890"
  767. (org-test-with-temp-text "123\\\\ 7890"
  768. (let ((fill-column 6))
  769. (end-of-line)
  770. (org-auto-fill-function)
  771. (buffer-string)))))
  772. ;; Do not fill affiliated keywords.
  773. (should-not
  774. (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
  775. (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
  776. (let ((fill-column 20))
  777. (end-of-line)
  778. (org-auto-fill-function)
  779. (buffer-string))))))
  780. ;;; Indentation
  781. (ert-deftest test-org/indent-line ()
  782. "Test `org-indent-line' specifications."
  783. ;; Do not indent diary sexps, footnote definitions or headlines.
  784. (should
  785. (zerop
  786. (org-test-with-temp-text "%%(org-calendar-holiday)"
  787. (org-indent-line)
  788. (org-get-indentation))))
  789. (should
  790. (zerop
  791. (org-test-with-temp-text "[fn:1] fn"
  792. (let ((org-adapt-indentation t)) (org-indent-line))
  793. (org-get-indentation))))
  794. (should
  795. (zerop
  796. (org-test-with-temp-text "* H"
  797. (org-indent-line)
  798. (org-get-indentation))))
  799. ;; Do not indent before first headline.
  800. (should
  801. (zerop
  802. (org-test-with-temp-text ""
  803. (org-indent-line)
  804. (org-get-indentation))))
  805. ;; Indent according to headline level otherwise, unless
  806. ;; `org-adapt-indentation' is nil.
  807. (should
  808. (= 2
  809. (org-test-with-temp-text "* H\n<point>A"
  810. (let ((org-adapt-indentation t)) (org-indent-line))
  811. (org-get-indentation))))
  812. (should
  813. (= 2
  814. (org-test-with-temp-text "* H\n<point>\nA"
  815. (let ((org-adapt-indentation t)) (org-indent-line))
  816. (org-get-indentation))))
  817. (should
  818. (zerop
  819. (org-test-with-temp-text "* H\n<point>A"
  820. (let ((org-adapt-indentation nil)) (org-indent-line))
  821. (org-get-indentation))))
  822. ;; Indenting preserves point position.
  823. (should
  824. (org-test-with-temp-text "* H\nA<point>B"
  825. (let ((org-adapt-indentation t)) (org-indent-line))
  826. (looking-at "B")))
  827. ;; Do not change indentation at an item or a LaTeX environment.
  828. (should
  829. (= 1
  830. (org-test-with-temp-text "* H\n<point> - A"
  831. (let ((org-adapt-indentation t)) (org-indent-line))
  832. (org-get-indentation))))
  833. (should
  834. (= 1
  835. (org-test-with-temp-text
  836. "\\begin{equation}\n <point>1+1=2\n\\end{equation}"
  837. (org-indent-line)
  838. (org-get-indentation))))
  839. ;; On blank lines at the end of a list, indent like last element
  840. ;; within it if the line is still in the list. If the last element
  841. ;; is an item, indent like its contents. Otherwise, indent like the
  842. ;; whole list.
  843. (should
  844. (= 4
  845. (org-test-with-temp-text "* H\n- A\n - AA\n<point>"
  846. (let ((org-adapt-indentation t)) (org-indent-line))
  847. (org-get-indentation))))
  848. (should
  849. (= 4
  850. (org-test-with-temp-text "* H\n- A\n -\n\n<point>"
  851. (let ((org-adapt-indentation t)) (org-indent-line))
  852. (org-get-indentation))))
  853. (should
  854. (zerop
  855. (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n<point>"
  856. (let ((org-adapt-indentation t)) (org-indent-line))
  857. (org-get-indentation))))
  858. (should
  859. (= 4
  860. (org-test-with-temp-text "* H\n- A\n - \n<point>"
  861. (let ((org-adapt-indentation t)) (org-indent-line))
  862. (org-get-indentation))))
  863. (should
  864. (= 4
  865. (org-test-with-temp-text
  866. "* H\n - \n #+BEGIN_SRC emacs-lisp\n t\n #+END_SRC\n<point>"
  867. (let ((org-adapt-indentation t)) (org-indent-line))
  868. (org-get-indentation))))
  869. (should
  870. (= 2
  871. (org-test-with-temp-text "- A\n B\n\n<point>"
  872. (let ((org-adapt-indentation nil)) (org-indent-line))
  873. (org-get-indentation))))
  874. (should
  875. (= 2
  876. (org-test-with-temp-text
  877. "- A\n \begin{cases} 1 + 1\n \end{cases}\n\n<point>"
  878. (let ((org-adapt-indentation nil)) (org-indent-line))
  879. (org-get-indentation))))
  880. ;; Likewise, on a blank line at the end of a footnote definition,
  881. ;; indent at column 0 if line belongs to the definition. Otherwise,
  882. ;; indent like the definition itself.
  883. (should
  884. (zerop
  885. (org-test-with-temp-text "* H\n[fn:1] Definition\n<point>"
  886. (let ((org-adapt-indentation t)) (org-indent-line))
  887. (org-get-indentation))))
  888. (should
  889. (zerop
  890. (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n<point>"
  891. (let ((org-adapt-indentation t)) (org-indent-line))
  892. (org-get-indentation))))
  893. ;; After the end of the contents of a greater element, indent like
  894. ;; the beginning of the element.
  895. (should
  896. (= 1
  897. (org-test-with-temp-text
  898. " #+BEGIN_CENTER\n Contents\n<point>#+END_CENTER"
  899. (org-indent-line)
  900. (org-get-indentation))))
  901. ;; On blank lines after a paragraph, indent like its last non-empty
  902. ;; line.
  903. (should
  904. (= 1
  905. (org-test-with-temp-text " Paragraph\n\n<point>"
  906. (org-indent-line)
  907. (org-get-indentation))))
  908. ;; At the first line of an element, indent like previous element's
  909. ;; first line, ignoring footnotes definitions and inline tasks, or
  910. ;; according to parent.
  911. (should
  912. (= 2
  913. (org-test-with-temp-text "A\n\n B\n\nC<point>"
  914. (org-indent-line)
  915. (org-get-indentation))))
  916. (should
  917. (= 1
  918. (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC<point>"
  919. (org-indent-line)
  920. (org-get-indentation))))
  921. (should
  922. (= 1
  923. (org-test-with-temp-text
  924. " #+BEGIN_CENTER\n<point> Contents\n#+END_CENTER"
  925. (org-indent-line)
  926. (org-get-indentation))))
  927. ;; Within code part of a source block, use language major mode if
  928. ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
  929. ;; according to line above.
  930. (should
  931. (= 6
  932. (org-test-with-temp-text
  933. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  934. (let ((org-src-tab-acts-natively t)
  935. (org-edit-src-content-indentation 0))
  936. (org-indent-line))
  937. (org-get-indentation))))
  938. (should
  939. (= 1
  940. (org-test-with-temp-text
  941. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  942. (let ((org-src-tab-acts-natively nil)
  943. (org-edit-src-content-indentation 0))
  944. (org-indent-line))
  945. (org-get-indentation))))
  946. ;; Otherwise, indent like the first non-blank line above.
  947. (should
  948. (zerop
  949. (org-test-with-temp-text
  950. "#+BEGIN_CENTER\nline1\n\n<point> line2\n#+END_CENTER"
  951. (org-indent-line)
  952. (org-get-indentation))))
  953. ;; Align node properties according to `org-property-format'. Handle
  954. ;; nicely empty values.
  955. (should
  956. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  957. (org-test-with-temp-text
  958. "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
  959. (let ((org-property-format "%-10s %s")) (org-indent-line))
  960. (buffer-string))))
  961. (should
  962. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  963. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
  964. (let ((org-property-format "%-10s %s")) (org-indent-line))
  965. (buffer-string)))))
  966. (ert-deftest test-org/indent-region ()
  967. "Test `org-indent-region' specifications."
  968. ;; Indent paragraph.
  969. (should
  970. (equal "A\nB\nC"
  971. (org-test-with-temp-text " A\nB\n C"
  972. (org-indent-region (point-min) (point-max))
  973. (buffer-string))))
  974. ;; Indent greater elements along with their contents.
  975. (should
  976. (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
  977. (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
  978. (org-indent-region (point-min) (point-max))
  979. (buffer-string))))
  980. ;; Ignore contents of verse blocks. Only indent block delimiters.
  981. (should
  982. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  983. (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  984. (org-indent-region (point-min) (point-max))
  985. (buffer-string))))
  986. (should
  987. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  988. (org-test-with-temp-text " #+BEGIN_VERSE\n A\n B\n #+END_VERSE"
  989. (org-indent-region (point-min) (point-max))
  990. (buffer-string))))
  991. ;; Indent example blocks as a single block, unless indentation
  992. ;; should be preserved. In this case only indent the block markers.
  993. (should
  994. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  995. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  996. (org-indent-region (point-min) (point-max))
  997. (buffer-string))))
  998. (should
  999. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1000. (org-test-with-temp-text " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1001. (org-indent-region (point-min) (point-max))
  1002. (buffer-string))))
  1003. (should
  1004. (equal "#+BEGIN_EXAMPLE -i\n A\n B\n#+END_EXAMPLE"
  1005. (org-test-with-temp-text
  1006. " #+BEGIN_EXAMPLE -i\n A\n B\n #+END_EXAMPLE"
  1007. (org-indent-region (point-min) (point-max))
  1008. (buffer-string))))
  1009. (should
  1010. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1011. (org-test-with-temp-text
  1012. " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1013. (let ((org-src-preserve-indentation t))
  1014. (org-indent-region (point-min) (point-max)))
  1015. (buffer-string))))
  1016. ;; Treat export blocks as a whole.
  1017. (should
  1018. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1019. (org-test-with-temp-text "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1020. (org-indent-region (point-min) (point-max))
  1021. (buffer-string))))
  1022. (should
  1023. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1024. (org-test-with-temp-text
  1025. " #+BEGIN_EXPORT latex\n A\n B\n #+END_EXPORT"
  1026. (org-indent-region (point-min) (point-max))
  1027. (buffer-string))))
  1028. ;; Indent according to mode if `org-src-tab-acts-natively' is
  1029. ;; non-nil. Otherwise, do not indent code at all.
  1030. (should
  1031. (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
  1032. (org-test-with-temp-text
  1033. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1034. (let ((org-src-tab-acts-natively t)
  1035. (org-edit-src-content-indentation 0))
  1036. (org-indent-region (point-min) (point-max)))
  1037. (buffer-string))))
  1038. (should
  1039. (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1040. (org-test-with-temp-text
  1041. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1042. (let ((org-src-tab-acts-natively nil)
  1043. (org-edit-src-content-indentation 0))
  1044. (org-indent-region (point-min) (point-max)))
  1045. (buffer-string))))
  1046. ;; Align node properties according to `org-property-format'. Handle
  1047. ;; nicely empty values.
  1048. (should
  1049. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1050. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
  1051. (let ((org-property-format "%-10s %s")
  1052. (org-adapt-indentation nil))
  1053. (org-indent-region (point) (point-max)))
  1054. (buffer-string))))
  1055. (should
  1056. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1057. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
  1058. (let ((org-property-format "%-10s %s")
  1059. (org-adapt-indentation nil))
  1060. (org-indent-region (point) (point-max)))
  1061. (buffer-string))))
  1062. ;; Indent plain lists.
  1063. (should
  1064. (equal "- A\n B\n - C\n\n D"
  1065. (org-test-with-temp-text "- A\n B\n - C\n\n D"
  1066. (org-indent-region (point-min) (point-max))
  1067. (buffer-string))))
  1068. (should
  1069. (equal "- A\n\n- B"
  1070. (org-test-with-temp-text " - A\n\n - B"
  1071. (org-indent-region (point-min) (point-max))
  1072. (buffer-string))))
  1073. ;; Indent footnote definitions.
  1074. (should
  1075. (equal "[fn:1] Definition\n\nDefinition"
  1076. (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
  1077. (org-indent-region (point-min) (point-max))
  1078. (buffer-string))))
  1079. ;; Special case: Start indenting on a blank line.
  1080. (should
  1081. (equal "\nParagraph"
  1082. (org-test-with-temp-text "\n Paragraph"
  1083. (org-indent-region (point-min) (point-max))
  1084. (buffer-string)))))
  1085. ;;; Editing
  1086. (ert-deftest test-org/delete-indentation ()
  1087. "Test `org-delete-indentation' specifications."
  1088. ;; Regular test.
  1089. (should (equal "foo bar"
  1090. (org-test-with-temp-text
  1091. "foo \n bar<point>"
  1092. (org-delete-indentation)
  1093. (buffer-string))))
  1094. ;; With optional argument.
  1095. (should (equal "foo bar"
  1096. (org-test-with-temp-text
  1097. "foo<point> \n bar"
  1098. (org-delete-indentation t)
  1099. (buffer-string))))
  1100. ;; At headline text should be appended to the headline text.
  1101. (should
  1102. (equal"* foo bar :tag:"
  1103. (let (org-auto-align-tags)
  1104. (org-test-with-temp-text
  1105. "* foo :tag:\n bar<point>"
  1106. (org-delete-indentation)
  1107. (buffer-string)))))
  1108. (should
  1109. (equal "* foo bar :tag:"
  1110. (let (org-auto-align-tags)
  1111. (org-test-with-temp-text
  1112. "* foo <point>:tag:\n bar"
  1113. (org-delete-indentation t)
  1114. (buffer-string))))))
  1115. (ert-deftest test-org/return ()
  1116. "Test `org-return' specifications."
  1117. ;; Regular test.
  1118. (should
  1119. (equal "Para\ngraph"
  1120. (org-test-with-temp-text "Para<point>graph"
  1121. (org-return)
  1122. (buffer-string))))
  1123. ;; With optional argument, indent line.
  1124. (should
  1125. (equal " Para\n graph"
  1126. (org-test-with-temp-text " Para<point>graph"
  1127. (org-return t)
  1128. (buffer-string))))
  1129. ;; On a table, call `org-table-next-row'.
  1130. (should
  1131. (org-test-with-temp-text "| <point>a |\n| b |"
  1132. (org-return)
  1133. (looking-at-p "b")))
  1134. ;; Open link or timestamp under point when `org-return-follows-link'
  1135. ;; is non-nil.
  1136. (should
  1137. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1138. (let ((org-return-follows-link t)
  1139. (org-link-search-must-match-exact-headline nil))
  1140. (org-return))
  1141. (looking-at-p "<<target>>")))
  1142. (should-not
  1143. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1144. (let ((org-return-follows-link nil)) (org-return))
  1145. (looking-at-p "<<target>>")))
  1146. (should
  1147. (org-test-with-temp-text "* [[b][a<point>]]\n* b"
  1148. (let ((org-return-follows-link t)) (org-return))
  1149. (looking-at-p "* b")))
  1150. (should
  1151. (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
  1152. (let ((org-return-follows-link t)
  1153. (org-link-search-must-match-exact-headline nil))
  1154. (org-return))
  1155. (looking-at-p "<<target>>")))
  1156. (should-not
  1157. (org-test-with-temp-text "Link [[target]]<point> <<target>>"
  1158. (let ((org-return-follows-link t)
  1159. (org-link-search-must-match-exact-headline nil))
  1160. (org-return))
  1161. (looking-at-p "<<target>>")))
  1162. ;; When `org-return-follows-link' is non-nil, tolerate links and
  1163. ;; timestamps in comments, node properties, etc.
  1164. (should
  1165. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1166. (let ((org-return-follows-link t)
  1167. (org-link-search-must-match-exact-headline nil))
  1168. (org-return))
  1169. (looking-at-p "<<target>>")))
  1170. (should-not
  1171. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1172. (let ((org-return-follows-link nil)) (org-return))
  1173. (looking-at-p "<<target>>")))
  1174. (should-not
  1175. (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
  1176. (let ((org-return-follows-link t)
  1177. (org-link-search-must-match-exact-headline nil))
  1178. (org-return))
  1179. (looking-at-p "<<target>>")))
  1180. ;; Non-nil `org-return-follows-link' ignores read-only state of
  1181. ;; a buffer.
  1182. (should
  1183. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1184. (let ((org-return-follows-link t)
  1185. (org-link-search-must-match-exact-headline nil))
  1186. (setq buffer-read-only t)
  1187. (call-interactively #'org-return))
  1188. (looking-at-p "<<target>>")))
  1189. ;; `org-return-follows-link' handle multi-line lines.
  1190. (should
  1191. (org-test-with-temp-text
  1192. "[[target][This is a very\n long description<point>]]\n <<target>>"
  1193. (let ((org-return-follows-link t)
  1194. (org-link-search-must-match-exact-headline nil))
  1195. (org-return))
  1196. (looking-at-p "<<target>>")))
  1197. (should-not
  1198. (org-test-with-temp-text
  1199. "[[target][This is a very\n long description]]<point>\n <<target>>"
  1200. (let ((org-return-follows-link t)
  1201. (org-link-search-must-match-exact-headline nil))
  1202. (org-return))
  1203. (looking-at-p "<<target>>")))
  1204. ;; However, do not open link when point is in a table.
  1205. (should
  1206. (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
  1207. (let ((org-return-follows-link t)) (org-return))
  1208. (looking-at-p "between")))
  1209. ;; Special case: in a list, when indenting, do not break structure.
  1210. (should
  1211. (equal "- A\n B"
  1212. (org-test-with-temp-text "- A <point>B"
  1213. (org-return t)
  1214. (buffer-string))))
  1215. (should
  1216. (equal "- A\n\n- B"
  1217. (org-test-with-temp-text "- A\n<point>- B"
  1218. (org-return t)
  1219. (buffer-string))))
  1220. ;; On tags part of a headline, add a newline below it instead of
  1221. ;; breaking it.
  1222. (should
  1223. (equal "* H :tag:\n"
  1224. (org-test-with-temp-text "* H :<point>tag:"
  1225. (org-return)
  1226. (buffer-string))))
  1227. ;; Before headline text, add a newline below it instead of breaking
  1228. ;; it.
  1229. (should
  1230. (equal "* TODO H :tag:\n"
  1231. (org-test-with-temp-text "* <point>TODO H :tag:"
  1232. (org-return)
  1233. (buffer-string))))
  1234. (should
  1235. (equal "* TODO [#B] H :tag:\n"
  1236. (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
  1237. (org-return)
  1238. (buffer-string))))
  1239. (should ;TODO are case-sensitive
  1240. (equal "* \nTodo"
  1241. (org-test-with-temp-text "* <point>Todo"
  1242. (org-return)
  1243. (buffer-string))))
  1244. ;; At headline text, break headline text but preserve tags.
  1245. (should
  1246. (equal "* TODO [#B] foo :tag:\nbar"
  1247. (let (org-auto-align-tags)
  1248. (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
  1249. (org-return)
  1250. (buffer-string)))))
  1251. ;; At bol of headline insert newline.
  1252. (should
  1253. (equal "\n* h"
  1254. (org-test-with-temp-text "<point>* h"
  1255. (org-return)
  1256. (buffer-string))))
  1257. ;; Refuse to leave invalid headline in buffer.
  1258. (should
  1259. (equal "* h\n"
  1260. (org-test-with-temp-text "*<point> h"
  1261. (org-return)
  1262. (buffer-string))))
  1263. ;; Before first column or after last one in a table, split the
  1264. ;; table.
  1265. (should
  1266. (equal "| a |\n\n| b |"
  1267. (org-test-with-temp-text "| a |\n<point>| b |"
  1268. (org-return)
  1269. (buffer-string))))
  1270. (should
  1271. (equal "| a |\n\n| b |"
  1272. (org-test-with-temp-text "| a |<point>\n| b |"
  1273. (org-return)
  1274. (buffer-string))))
  1275. ;; Do not auto-fill on hitting <RET> inside a property drawer.
  1276. (should
  1277. (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:"
  1278. (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:"
  1279. (setq-local fill-column 10)
  1280. (auto-fill-mode 1)
  1281. (org-return)
  1282. (buffer-string)))))
  1283. (ert-deftest test-org/with-electric-indent ()
  1284. "Test RET and C-j specifications with `electric-indent-mode' on."
  1285. ;; Call commands interactively, since this is how `newline' knows it
  1286. ;; must run `post-self-insert-hook'.
  1287. ;;
  1288. ;; RET, like `newline', should indent.
  1289. (should
  1290. (equal " Para\n graph"
  1291. (org-test-with-temp-text " Para<point>graph"
  1292. (electric-indent-local-mode 1)
  1293. (call-interactively 'org-return)
  1294. (buffer-string))))
  1295. (should
  1296. (equal "- item1\n item2"
  1297. (org-test-with-temp-text "- item1<point>item2"
  1298. (electric-indent-local-mode 1)
  1299. (call-interactively 'org-return)
  1300. (buffer-string))))
  1301. (should
  1302. (equal "* heading\n body"
  1303. (org-test-with-temp-text "* heading<point>body"
  1304. (electric-indent-local-mode 1)
  1305. (call-interactively 'org-return)
  1306. (buffer-string))))
  1307. ;; C-j, like `electric-newline-and-maybe-indent', should not indent.
  1308. (should
  1309. (equal " Para\ngraph"
  1310. (org-test-with-temp-text " Para<point>graph"
  1311. (electric-indent-local-mode 1)
  1312. (call-interactively 'org-return-and-maybe-indent)
  1313. (buffer-string))))
  1314. (should
  1315. (equal "- item1\nitem2"
  1316. (org-test-with-temp-text "- item1<point>item2"
  1317. (electric-indent-local-mode 1)
  1318. (call-interactively 'org-return-and-maybe-indent)
  1319. (buffer-string))))
  1320. (should
  1321. (equal "* heading\nbody"
  1322. (org-test-with-temp-text "* heading<point>body"
  1323. (electric-indent-local-mode 1)
  1324. (call-interactively 'org-return-and-maybe-indent)
  1325. (buffer-string)))))
  1326. (ert-deftest test-org/without-electric-indent ()
  1327. "Test RET and C-j specifications with `electric-indent-mode' off."
  1328. ;; Call commands interactively, since this is how `newline' knows it
  1329. ;; must run `post-self-insert-hook'.
  1330. ;;
  1331. ;; RET, like `newline', should not indent.
  1332. (should
  1333. (equal " Para\ngraph"
  1334. (org-test-with-temp-text " Para<point>graph"
  1335. (electric-indent-local-mode 0)
  1336. (call-interactively 'org-return)
  1337. (buffer-string))))
  1338. (should
  1339. (equal "- item1\nitem2"
  1340. (org-test-with-temp-text "- item1<point>item2"
  1341. (electric-indent-local-mode 0)
  1342. (call-interactively 'org-return)
  1343. (buffer-string))))
  1344. (should
  1345. (equal "* heading\nbody"
  1346. (org-test-with-temp-text "* heading<point>body"
  1347. (electric-indent-local-mode 0)
  1348. (call-interactively 'org-return)
  1349. (buffer-string))))
  1350. ;; C-j, like `electric-newline-and-maybe-indent', should indent.
  1351. (should
  1352. (equal " Para\n graph"
  1353. (org-test-with-temp-text " Para<point>graph"
  1354. (electric-indent-local-mode 0)
  1355. (call-interactively 'org-return-and-maybe-indent)
  1356. (buffer-string))))
  1357. (should
  1358. (equal "- item1\n item2"
  1359. (org-test-with-temp-text "- item1<point>item2"
  1360. (electric-indent-local-mode 0)
  1361. (call-interactively 'org-return-and-maybe-indent)
  1362. (buffer-string))))
  1363. (should
  1364. (equal "* heading\n body"
  1365. (org-test-with-temp-text "* heading<point>body"
  1366. (electric-indent-local-mode 0)
  1367. (call-interactively 'org-return-and-maybe-indent)
  1368. (buffer-string)))))
  1369. (ert-deftest test-org/meta-return ()
  1370. "Test M-RET (`org-meta-return') specifications."
  1371. ;; In a table field insert a row above.
  1372. (should
  1373. (org-test-with-temp-text "| a |"
  1374. (forward-char)
  1375. (org-meta-return)
  1376. (forward-line -1)
  1377. (looking-at "| |$")))
  1378. ;; In a paragraph change current line into a header.
  1379. (should
  1380. (org-test-with-temp-text "a"
  1381. (org-meta-return)
  1382. (beginning-of-line)
  1383. (looking-at "\* a$")))
  1384. ;; In an item insert an item, in this case above.
  1385. (should
  1386. (org-test-with-temp-text "- a"
  1387. (org-meta-return)
  1388. (beginning-of-line)
  1389. (looking-at "- $")))
  1390. ;; In a drawer and item insert an item, in this case above.
  1391. (should
  1392. (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
  1393. (forward-line)
  1394. (org-meta-return)
  1395. (beginning-of-line)
  1396. (looking-at "- $"))))
  1397. (ert-deftest test-org/insert-heading ()
  1398. "Test `org-insert-heading' specifications."
  1399. ;; In an empty buffer, insert a new headline.
  1400. (should
  1401. (equal "* "
  1402. (org-test-with-temp-text ""
  1403. (org-insert-heading)
  1404. (buffer-string))))
  1405. ;; At the beginning of a line, turn it into a headline.
  1406. (should
  1407. (equal "* P"
  1408. (org-test-with-temp-text "<point>P"
  1409. (org-insert-heading)
  1410. (buffer-string))))
  1411. ;; In the middle of a line, split the line if allowed, otherwise,
  1412. ;; insert the headline at its end.
  1413. (should
  1414. (equal "Para\n* graph"
  1415. (org-test-with-temp-text "Para<point>graph"
  1416. (let ((org-M-RET-may-split-line '((default . t))))
  1417. (org-insert-heading))
  1418. (buffer-string))))
  1419. (should
  1420. (equal "Paragraph\n* "
  1421. (org-test-with-temp-text "Para<point>graph"
  1422. (let ((org-M-RET-may-split-line '((default . nil))))
  1423. (org-insert-heading))
  1424. (buffer-string))))
  1425. ;; At the beginning of a headline, create one above.
  1426. (should
  1427. (equal "* \n* H"
  1428. (org-test-with-temp-text "* H"
  1429. (org-insert-heading)
  1430. (buffer-string))))
  1431. ;; In the middle of a headline, split it if allowed.
  1432. (should
  1433. (equal "* H\n* 1"
  1434. (org-test-with-temp-text "* H<point>1"
  1435. (let ((org-M-RET-may-split-line '((headline . t))))
  1436. (org-insert-heading))
  1437. (buffer-string))))
  1438. (should
  1439. (equal "* H1\n* "
  1440. (org-test-with-temp-text "* H<point>1"
  1441. (let ((org-M-RET-may-split-line '((headline . nil))))
  1442. (org-insert-heading))
  1443. (buffer-string))))
  1444. ;; However, splitting cannot happen on TODO keywords, priorities or
  1445. ;; tags.
  1446. (should
  1447. (equal "* TODO H1\n* "
  1448. (org-test-with-temp-text "* TO<point>DO H1"
  1449. (let ((org-M-RET-may-split-line '((headline . t))))
  1450. (org-insert-heading))
  1451. (buffer-string))))
  1452. (should
  1453. (equal "* [#A] H1\n* "
  1454. (org-test-with-temp-text "* [#<point>A] H1"
  1455. (let ((org-M-RET-may-split-line '((headline . t))))
  1456. (org-insert-heading))
  1457. (buffer-string))))
  1458. (should
  1459. (equal "* H1 :tag:\n* "
  1460. (org-test-with-temp-text "* H1 :ta<point>g:"
  1461. (let ((org-M-RET-may-split-line '((headline . t))))
  1462. (org-insert-heading))
  1463. (buffer-string))))
  1464. ;; New headline level depends on the level of the headline above.
  1465. (should
  1466. (equal "** H\n** P"
  1467. (org-test-with-temp-text "** H\n<point>P"
  1468. (org-insert-heading)
  1469. (buffer-string))))
  1470. (should
  1471. (equal "** H\nPara\n** graph"
  1472. (org-test-with-temp-text "** H\nPara<point>graph"
  1473. (let ((org-M-RET-may-split-line '((default . t))))
  1474. (org-insert-heading))
  1475. (buffer-string))))
  1476. (should
  1477. (equal "** \n** H"
  1478. (org-test-with-temp-text "** H"
  1479. (org-insert-heading)
  1480. (buffer-string))))
  1481. ;; When called with one universal argument, insert a new headline at
  1482. ;; the end of the current subtree, independently on the position of
  1483. ;; point.
  1484. (should
  1485. (equal
  1486. "* H1\n** H2\n* "
  1487. (org-test-with-temp-text "* H1\n** H2"
  1488. (let ((org-insert-heading-respect-content nil))
  1489. (org-insert-heading '(4)))
  1490. (buffer-string))))
  1491. (should
  1492. (equal
  1493. "* H1\n** H2\n* "
  1494. (org-test-with-temp-text "* H<point>1\n** H2"
  1495. (let ((org-insert-heading-respect-content nil))
  1496. (org-insert-heading '(4)))
  1497. (buffer-string))))
  1498. ;; When called with two universal arguments, insert a new headline
  1499. ;; at the end of the grandparent subtree.
  1500. (should
  1501. (equal "* H1\n** H3\n- item\n** H2\n** "
  1502. (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
  1503. (let ((org-insert-heading-respect-content nil))
  1504. (org-insert-heading '(16)))
  1505. (buffer-string))))
  1506. ;; When optional TOP-LEVEL argument is non-nil, always insert
  1507. ;; a level 1 heading.
  1508. (should
  1509. (equal "* H1\n** H2\n* "
  1510. (org-test-with-temp-text "* H1\n** H2<point>"
  1511. (org-insert-heading nil nil t)
  1512. (buffer-string))))
  1513. (should
  1514. (equal "* H1\n- item\n* "
  1515. (org-test-with-temp-text "* H1\n- item<point>"
  1516. (org-insert-heading nil nil t)
  1517. (buffer-string))))
  1518. ;; Obey `org-blank-before-new-entry'.
  1519. (should
  1520. (equal "* H1\n\n* "
  1521. (org-test-with-temp-text "* H1<point>"
  1522. (let ((org-blank-before-new-entry '((heading . t))))
  1523. (org-insert-heading))
  1524. (buffer-string))))
  1525. (should
  1526. (equal "* H1\n* "
  1527. (org-test-with-temp-text "* H1<point>"
  1528. (let ((org-blank-before-new-entry '((heading . nil))))
  1529. (org-insert-heading))
  1530. (buffer-string))))
  1531. (should
  1532. (equal "* H1\n* H2\n* "
  1533. (org-test-with-temp-text "* H1\n* H2<point>"
  1534. (let ((org-blank-before-new-entry '((heading . auto))))
  1535. (org-insert-heading))
  1536. (buffer-string))))
  1537. (should
  1538. (equal "* H1\n\n* H2\n\n* "
  1539. (org-test-with-temp-text "* H1\n\n* H2<point>"
  1540. (let ((org-blank-before-new-entry '((heading . auto))))
  1541. (org-insert-heading))
  1542. (buffer-string))))
  1543. ;; Corner case: correctly insert a headline after an empty one.
  1544. (should
  1545. (equal "* \n* "
  1546. (org-test-with-temp-text "* <point>"
  1547. (org-insert-heading)
  1548. (buffer-string))))
  1549. (should
  1550. (org-test-with-temp-text "* <point>\n"
  1551. (org-insert-heading)
  1552. (looking-at-p "\n\\'")))
  1553. ;; Do not insert spurious headlines when inserting a new headline.
  1554. (should
  1555. (equal "* H1\n* H2\n* \n"
  1556. (org-test-with-temp-text "* H1\n* H2<point>\n"
  1557. (org-insert-heading)
  1558. (buffer-string))))
  1559. ;; Preserve visibility at beginning of line. In particular, when
  1560. ;; removing spurious blank lines, do not visually merge heading with
  1561. ;; the line visible above.
  1562. (should-not
  1563. (org-test-with-temp-text "* H1<point>\nContents\n\n* H2\n"
  1564. (org-overview)
  1565. (let ((org-blank-before-new-entry '((heading . nil))))
  1566. (org-insert-heading '(4)))
  1567. (invisible-p (line-end-position 0))))
  1568. ;; Properly handle empty lines when forcing a headline below current
  1569. ;; one.
  1570. (should
  1571. (equal "* H1\n\n* H\n\n* "
  1572. (org-test-with-temp-text "* H1\n\n* H<point>"
  1573. (let ((org-blank-before-new-entry '((heading . t))))
  1574. (org-insert-heading '(4))
  1575. (buffer-string))))))
  1576. (ert-deftest test-org/insert-todo-heading-respect-content ()
  1577. "Test `org-insert-todo-heading-respect-content' specifications."
  1578. ;; Create a TODO heading.
  1579. (should
  1580. (org-test-with-temp-text "* H1\n Body"
  1581. (org-insert-todo-heading-respect-content)
  1582. (nth 2 (org-heading-components))))
  1583. ;; Add headline at the end of the first subtree
  1584. (should
  1585. (equal
  1586. "* TODO "
  1587. (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
  1588. (org-insert-todo-heading-respect-content)
  1589. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1590. ;; In a list, do not create a new item.
  1591. (should
  1592. (equal
  1593. "* TODO "
  1594. (org-test-with-temp-text "* H\n- an item\n- another one"
  1595. (search-forward "an ")
  1596. (org-insert-todo-heading-respect-content)
  1597. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1598. ;; Use the same TODO keyword as current heading.
  1599. (should
  1600. (equal
  1601. "* TODO \n"
  1602. (org-test-with-temp-text "* TODO\n** WAITING\n"
  1603. (org-insert-todo-heading-respect-content)
  1604. (buffer-substring-no-properties (line-beginning-position) (point-max))))))
  1605. (ert-deftest test-org/clone-with-time-shift ()
  1606. "Test `org-clone-subtree-with-time-shift'."
  1607. ;; Raise an error before first heading.
  1608. (should-error
  1609. (org-test-with-temp-text ""
  1610. (org-clone-subtree-with-time-shift 1)))
  1611. ;; Raise an error on invalid number of clones.
  1612. (should-error
  1613. (org-test-with-temp-text "* Clone me"
  1614. (org-clone-subtree-with-time-shift -1)))
  1615. ;; Clone non-repeating once.
  1616. (should
  1617. (equal "\
  1618. * H1\n<2015-06-21>
  1619. * H1\n<2015-06-23>
  1620. "
  1621. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1622. (org-clone-subtree-with-time-shift 1 "+2d")
  1623. (replace-regexp-in-string
  1624. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1625. nil nil 1))))
  1626. ;; Clone repeating once.
  1627. (should
  1628. (equal "\
  1629. * H1\n<2015-06-21>
  1630. * H1\n<2015-06-23>
  1631. * H1\n<2015-06-25 +1w>
  1632. "
  1633. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1634. (org-clone-subtree-with-time-shift 1 "+2d")
  1635. (replace-regexp-in-string
  1636. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1637. nil nil 1))))
  1638. ;; Clone repeating once in backward.
  1639. (should
  1640. (equal "\
  1641. * H1\n<2015-06-21>
  1642. * H1\n<2015-06-19>
  1643. * H1\n<2015-06-17 +1w>
  1644. "
  1645. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1646. (org-clone-subtree-with-time-shift 1 "-2d")
  1647. (replace-regexp-in-string
  1648. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1649. nil nil 1))))
  1650. ;; Clone non-repeating zero times.
  1651. (should
  1652. (equal "\
  1653. * H1\n<2015-06-21>
  1654. "
  1655. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1656. (org-clone-subtree-with-time-shift 0 "+2d")
  1657. (replace-regexp-in-string
  1658. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1659. nil nil 1))))
  1660. ;; Clone repeating "zero" times.
  1661. (should
  1662. (equal "\
  1663. * H1\n<2015-06-21>
  1664. * H1\n<2015-06-23 +1w>
  1665. "
  1666. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1667. (org-clone-subtree-with-time-shift 0 "+2d")
  1668. (replace-regexp-in-string
  1669. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1670. nil nil 1))))
  1671. ;; Clone with blank SHIFT argument.
  1672. (should
  1673. (string-prefix-p
  1674. "* H <2012-03-29"
  1675. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1676. (org-clone-subtree-with-time-shift 1 "")
  1677. (buffer-substring-no-properties (line-beginning-position 2)
  1678. (line-end-position 2)))))
  1679. ;; Find time stamps before point. If SHIFT is not specified, ask
  1680. ;; for a time shift.
  1681. (should
  1682. (string-prefix-p
  1683. "* H <2012-03-30"
  1684. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1685. (org-clone-subtree-with-time-shift 1 "+1d")
  1686. (buffer-substring-no-properties (line-beginning-position 2)
  1687. (line-end-position 2)))))
  1688. (should
  1689. (string-prefix-p
  1690. "* H <2014-03-05"
  1691. (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
  1692. (cl-letf (((symbol-function 'read-from-minibuffer)
  1693. (lambda (&rest args) "+1d")))
  1694. (org-clone-subtree-with-time-shift 1))
  1695. (buffer-substring-no-properties (line-beginning-position 2)
  1696. (line-end-position 2))))))
  1697. ;;; Fixed-Width Areas
  1698. (ert-deftest test-org/toggle-fixed-width ()
  1699. "Test `org-toggle-fixed-width' specifications."
  1700. ;; No region: Toggle on fixed-width marker in paragraphs.
  1701. (should
  1702. (equal ": A"
  1703. (org-test-with-temp-text "A"
  1704. (org-toggle-fixed-width)
  1705. (buffer-string))))
  1706. ;; No region: Toggle off fixed-width markers in fixed-width areas.
  1707. (should
  1708. (equal "A"
  1709. (org-test-with-temp-text ": A"
  1710. (org-toggle-fixed-width)
  1711. (buffer-string))))
  1712. ;; No region: Toggle on marker in blank lines after elements or just
  1713. ;; after a headline.
  1714. (should
  1715. (equal "* H\n: "
  1716. (org-test-with-temp-text "* H\n"
  1717. (forward-line)
  1718. (org-toggle-fixed-width)
  1719. (buffer-string))))
  1720. (should
  1721. (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
  1722. (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
  1723. (goto-char (point-max))
  1724. (org-toggle-fixed-width)
  1725. (buffer-string))))
  1726. ;; No region: Toggle on marker in front of one line elements (e.g.,
  1727. ;; headlines, clocks)
  1728. (should
  1729. (equal ": * Headline"
  1730. (org-test-with-temp-text "* Headline"
  1731. (org-toggle-fixed-width)
  1732. (buffer-string))))
  1733. (should
  1734. (equal ": #+KEYWORD: value"
  1735. (org-test-with-temp-text "#+KEYWORD: value"
  1736. (org-toggle-fixed-width)
  1737. (buffer-string))))
  1738. ;; No region: error in other situations.
  1739. (should-error
  1740. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
  1741. (forward-line)
  1742. (org-toggle-fixed-width)
  1743. (buffer-string)))
  1744. ;; No region: Indentation is preserved.
  1745. (should
  1746. (equal "- A\n : B"
  1747. (org-test-with-temp-text "- A\n B"
  1748. (forward-line)
  1749. (org-toggle-fixed-width)
  1750. (buffer-string))))
  1751. ;; Region: If it contains only fixed-width elements and blank lines,
  1752. ;; toggle off fixed-width markup.
  1753. (should
  1754. (equal "A\n\nB"
  1755. (org-test-with-temp-text ": A\n\n: B"
  1756. (transient-mark-mode 1)
  1757. (push-mark (point) t t)
  1758. (goto-char (point-max))
  1759. (org-toggle-fixed-width)
  1760. (buffer-string))))
  1761. ;; Region: If it contains anything else, toggle on fixed-width but
  1762. ;; not on fixed-width areas.
  1763. (should
  1764. (equal ": A\n: \n: B\n: \n: C"
  1765. (org-test-with-temp-text "A\n\n: B\n\nC"
  1766. (transient-mark-mode 1)
  1767. (push-mark (point) t t)
  1768. (goto-char (point-max))
  1769. (org-toggle-fixed-width)
  1770. (buffer-string))))
  1771. ;; Region: Ignore blank lines at its end, unless it contains only
  1772. ;; such lines.
  1773. (should
  1774. (equal ": A\n\n"
  1775. (org-test-with-temp-text "A\n\n"
  1776. (transient-mark-mode 1)
  1777. (push-mark (point) t t)
  1778. (goto-char (point-max))
  1779. (org-toggle-fixed-width)
  1780. (buffer-string))))
  1781. (should
  1782. (equal ": \n: \n"
  1783. (org-test-with-temp-text "\n\n"
  1784. (transient-mark-mode 1)
  1785. (push-mark (point) t t)
  1786. (goto-char (point-max))
  1787. (org-toggle-fixed-width)
  1788. (buffer-string)))))
  1789. (ert-deftest test-org/kill-line ()
  1790. "Test `org-kill-line' specifications."
  1791. ;; At the beginning of a line, kill whole line.
  1792. (should
  1793. (equal ""
  1794. (org-test-with-temp-text "abc"
  1795. (org-kill-line)
  1796. (buffer-string))))
  1797. ;; In the middle of a line, kill line until its end.
  1798. (should
  1799. (equal "a"
  1800. (org-test-with-temp-text "a<point>bc"
  1801. (org-kill-line)
  1802. (buffer-string))))
  1803. ;; Do not kill newline character.
  1804. (should
  1805. (equal "\n123"
  1806. (org-test-with-temp-text "abc\n123"
  1807. (org-kill-line)
  1808. (buffer-string))))
  1809. (should
  1810. (equal "a\n123"
  1811. (org-test-with-temp-text "a<point>bc\n123"
  1812. (org-kill-line)
  1813. (buffer-string))))
  1814. ;; When `org-special-ctrl-k' is non-nil and point is at a headline,
  1815. ;; kill until tags.
  1816. (should
  1817. (equal "* A :tag:"
  1818. (org-test-with-temp-text "* A<point>B :tag:"
  1819. (let ((org-special-ctrl-k t)
  1820. (org-tags-column 0))
  1821. (org-kill-line))
  1822. (buffer-string))))
  1823. ;; If point is on tags, only kill part left until the end of line.
  1824. (should
  1825. (equal "* A :tag:"
  1826. (org-test-with-temp-text "* A :tag:<point>tag2:"
  1827. (let ((org-special-ctrl-k t)
  1828. (org-tags-column 0))
  1829. (org-kill-line))
  1830. (buffer-string))))
  1831. ;; However, if point is at the beginning of the line, kill whole
  1832. ;; headline.
  1833. (should
  1834. (equal ""
  1835. (org-test-with-temp-text "* AB :tag:"
  1836. (let ((org-special-ctrl-k t)
  1837. (org-tags-column 0))
  1838. (org-kill-line))
  1839. (buffer-string))))
  1840. ;; When `org-ctrl-k-protect-subtree' is non-nil, and point is in
  1841. ;; invisible text, ask before removing it. When set to `error',
  1842. ;; throw an error.
  1843. (should-error
  1844. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  1845. (org-overview)
  1846. (let ((org-special-ctrl-k nil)
  1847. (org-ctrl-k-protect-subtree t))
  1848. (cl-letf (((symbol-function 'y-or-n-p) 'ignore))
  1849. (org-kill-line)))))
  1850. (should-error
  1851. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  1852. (org-overview)
  1853. (let ((org-special-ctrl-k nil)
  1854. (org-ctrl-k-protect-subtree 'error))
  1855. (org-kill-line)))))
  1856. ;;; Headline
  1857. (ert-deftest test-org/get-heading ()
  1858. "Test `org-get-heading' specifications."
  1859. ;; Return current heading, even if point is not on it.
  1860. (should
  1861. (equal "H"
  1862. (org-test-with-temp-text "* H"
  1863. (org-get-heading))))
  1864. (should
  1865. (equal "H"
  1866. (org-test-with-temp-text "* H\nText<point>"
  1867. (org-get-heading))))
  1868. ;; Without any optional argument, return TODO keyword, priority
  1869. ;; cookie, COMMENT keyword and tags.
  1870. (should
  1871. (equal "TODO H"
  1872. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  1873. (org-get-heading))))
  1874. (should
  1875. (equal "[#A] H"
  1876. (org-test-with-temp-text "* [#A] H"
  1877. (org-get-heading))))
  1878. (should
  1879. (equal "COMMENT H"
  1880. (org-test-with-temp-text "* COMMENT H"
  1881. (org-get-heading))))
  1882. (should
  1883. (equal "H :tag:"
  1884. (org-test-with-temp-text "* H :tag:"
  1885. (org-get-heading))))
  1886. ;; With NO-TAGS argument, ignore tags.
  1887. (should
  1888. (equal "TODO H"
  1889. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  1890. (org-get-heading t))))
  1891. (should
  1892. (equal "H"
  1893. (org-test-with-temp-text "* H :tag:"
  1894. (org-get-heading t))))
  1895. ;; With NO-TODO, ignore TODO keyword.
  1896. (should
  1897. (equal "H"
  1898. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  1899. (org-get-heading nil t))))
  1900. (should
  1901. (equal "H :tag:"
  1902. (org-test-with-temp-text "* H :tag:"
  1903. (org-get-heading nil t))))
  1904. ;; TODO keywords are case-sensitive.
  1905. (should
  1906. (equal "Todo H"
  1907. (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
  1908. (org-get-heading nil t))))
  1909. ;; With NO-PRIORITY, ignore priority.
  1910. (should
  1911. (equal "H"
  1912. (org-test-with-temp-text "* [#A] H"
  1913. (org-get-heading nil nil t))))
  1914. (should
  1915. (equal "H"
  1916. (org-test-with-temp-text "* H"
  1917. (org-get-heading nil nil t))))
  1918. (should
  1919. (equal "TODO H"
  1920. (org-test-with-temp-text "* TODO [#A] H"
  1921. (org-get-heading nil nil t))))
  1922. ;; With NO-COMMENT, ignore COMMENT keyword.
  1923. (should
  1924. (equal "H"
  1925. (org-test-with-temp-text "* COMMENT H"
  1926. (org-get-heading nil nil nil t))))
  1927. (should
  1928. (equal "H"
  1929. (org-test-with-temp-text "* H"
  1930. (org-get-heading nil nil nil t))))
  1931. (should
  1932. (equal "TODO [#A] H"
  1933. (org-test-with-temp-text "* TODO [#A] COMMENT H"
  1934. (org-get-heading nil nil nil t))))
  1935. ;; On an empty headline, return value is consistent.
  1936. (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
  1937. (should (equal "" (org-test-with-temp-text "* " (org-get-heading t))))
  1938. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t))))
  1939. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t))))
  1940. (should
  1941. (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t)))))
  1942. (ert-deftest test-org/in-commented-heading-p ()
  1943. "Test `org-in-commented-heading-p' specifications."
  1944. ;; Commented headline.
  1945. (should
  1946. (org-test-with-temp-text "* COMMENT Headline\nBody"
  1947. (goto-char (point-max))
  1948. (org-in-commented-heading-p)))
  1949. ;; Commented ancestor.
  1950. (should
  1951. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  1952. (goto-char (point-max))
  1953. (org-in-commented-heading-p)))
  1954. ;; Comment keyword is case-sensitive.
  1955. (should-not
  1956. (org-test-with-temp-text "* Comment Headline\nBody"
  1957. (goto-char (point-max))
  1958. (org-in-commented-heading-p)))
  1959. ;; Keyword is standalone.
  1960. (should-not
  1961. (org-test-with-temp-text "* COMMENTHeadline\nBody"
  1962. (goto-char (point-max))
  1963. (org-in-commented-heading-p)))
  1964. ;; Optional argument.
  1965. (should-not
  1966. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  1967. (goto-char (point-max))
  1968. (org-in-commented-heading-p t))))
  1969. (ert-deftest test-org/entry-blocked-p ()
  1970. ;; Check other dependencies.
  1971. (should
  1972. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  1973. (let ((org-enforce-todo-dependencies t)
  1974. (org-blocker-hook
  1975. '(org-block-todo-from-children-or-siblings-or-parent)))
  1976. (org-entry-blocked-p))))
  1977. (should-not
  1978. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  1979. (let ((org-enforce-todo-dependencies t)
  1980. (org-blocker-hook
  1981. '(org-block-todo-from-children-or-siblings-or-parent)))
  1982. (org-entry-blocked-p))))
  1983. ;; Entry without a TODO keyword or with a DONE keyword cannot be
  1984. ;; blocked.
  1985. (should-not
  1986. (org-test-with-temp-text "* Blocked\n** TODO one"
  1987. (let ((org-enforce-todo-dependencies t)
  1988. (org-blocker-hook
  1989. '(org-block-todo-from-children-or-siblings-or-parent)))
  1990. (org-entry-blocked-p))))
  1991. (should-not
  1992. (org-test-with-temp-text "* DONE Blocked\n** TODO one"
  1993. (let ((org-enforce-todo-dependencies t)
  1994. (org-blocker-hook
  1995. '(org-block-todo-from-children-or-siblings-or-parent)))
  1996. (org-entry-blocked-p))))
  1997. ;; Follow :ORDERED: specifications.
  1998. (should
  1999. (org-test-with-temp-text
  2000. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
  2001. (let ((org-enforce-todo-dependencies t)
  2002. (org-blocker-hook
  2003. '(org-block-todo-from-children-or-siblings-or-parent)))
  2004. (org-entry-blocked-p))))
  2005. (should-not
  2006. (org-test-with-temp-text
  2007. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
  2008. (let ((org-enforce-todo-dependencies t)
  2009. (org-blocker-hook
  2010. '(org-block-todo-from-children-or-siblings-or-parent)))
  2011. (org-entry-blocked-p)))))
  2012. (ert-deftest test-org/get-outline-path ()
  2013. "Test `org-get-outline-path' specifications."
  2014. ;; Top-level headlines have no outline path.
  2015. (should-not
  2016. (org-test-with-temp-text "* H"
  2017. (org-get-outline-path)))
  2018. ;; Otherwise, outline path is the path leading to the headline.
  2019. (should
  2020. (equal '("H")
  2021. (org-test-with-temp-text "* H\n** S<point>"
  2022. (org-get-outline-path))))
  2023. ;; Find path even when point is not on a headline.
  2024. (should
  2025. (equal '("H")
  2026. (org-test-with-temp-text "* H\n** S\nText<point>"
  2027. (org-get-outline-path))))
  2028. ;; TODO keywords, tags and statistics cookies are ignored.
  2029. (should
  2030. (equal '("H")
  2031. (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
  2032. (org-get-outline-path))))
  2033. ;; Links are replaced with their description or their path.
  2034. (should
  2035. (equal '("Org")
  2036. (org-test-with-temp-text
  2037. "* [[https://orgmode.org][Org]]\n** S<point>"
  2038. (org-get-outline-path))))
  2039. (should
  2040. (equal '("https://orgmode.org")
  2041. (org-test-with-temp-text
  2042. "* [[https://orgmode.org]]\n** S<point>"
  2043. (org-get-outline-path))))
  2044. ;; When WITH-SELF is non-nil, include current heading.
  2045. (should
  2046. (equal '("H")
  2047. (org-test-with-temp-text "* H"
  2048. (org-get-outline-path t))))
  2049. (should
  2050. (equal '("H" "S")
  2051. (org-test-with-temp-text "* H\n** S\nText<point>"
  2052. (org-get-outline-path t))))
  2053. ;; Using cache is transparent to the user.
  2054. (should
  2055. (equal '("H")
  2056. (org-test-with-temp-text "* H\n** S<point>"
  2057. (setq org-outline-path-cache nil)
  2058. (org-get-outline-path nil t))))
  2059. ;; Do not corrupt cache when finding outline path in distant part of
  2060. ;; the buffer.
  2061. (should
  2062. (equal '("H2")
  2063. (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
  2064. (setq org-outline-path-cache nil)
  2065. (org-get-outline-path nil t)
  2066. (search-forward "S2")
  2067. (org-get-outline-path nil t))))
  2068. ;; Do not choke on empty headlines.
  2069. (should
  2070. (org-test-with-temp-text "* H\n** <point>"
  2071. (org-get-outline-path)))
  2072. (should
  2073. (org-test-with-temp-text "* \n** H<point>"
  2074. (org-get-outline-path))))
  2075. (ert-deftest test-org/format-outline-path ()
  2076. "Test `org-format-outline-path' specifications."
  2077. (should
  2078. (string= (org-format-outline-path (list "one" "two" "three"))
  2079. "one/two/three"))
  2080. ;; Empty path.
  2081. (should
  2082. (string= (org-format-outline-path '())
  2083. ""))
  2084. (should
  2085. (string= (org-format-outline-path '(nil))
  2086. ""))
  2087. ;; Empty path and prefix.
  2088. (should
  2089. (string= (org-format-outline-path '() nil ">>")
  2090. ">>"))
  2091. ;; Trailing whitespace in headings.
  2092. (should
  2093. (string= (org-format-outline-path (list "one\t" "tw o " "three "))
  2094. "one/tw o/three"))
  2095. ;; Non-default prefix and separators.
  2096. (should
  2097. (string= (org-format-outline-path (list "one" "two" "three") nil ">>" "|")
  2098. ">>|one|two|three"))
  2099. ;; Truncate.
  2100. (should
  2101. (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
  2102. "one/two/.."))
  2103. ;; Give a very narrow width.
  2104. (should
  2105. (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
  2106. "on"))
  2107. ;; Give a prefix that extends beyond the width.
  2108. (should
  2109. (string= (org-format-outline-path (list "one" "two" "three" "four") 10
  2110. ">>>>>>>>>>")
  2111. ">>>>>>>>..")))
  2112. (ert-deftest test-org/map-entries ()
  2113. "Test `org-map-entries' specifications."
  2114. ;; Full match.
  2115. (should
  2116. (equal '(1 11)
  2117. (org-test-with-temp-text "* Level 1\n** Level 2"
  2118. (org-map-entries #'point))))
  2119. ;; Level match.
  2120. (should
  2121. (equal '(1)
  2122. (org-test-with-temp-text "* Level 1\n** Level 2"
  2123. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL=1")))))
  2124. (should
  2125. (equal '(11)
  2126. (org-test-with-temp-text "* Level 1\n** Level 2"
  2127. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL>1")))))
  2128. ;; Tag match.
  2129. (should
  2130. (equal '(11)
  2131. (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
  2132. (org-map-entries #'point "yes"))))
  2133. (should
  2134. (equal '(14)
  2135. (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
  2136. (org-map-entries #'point "+yes-a"))))
  2137. (should
  2138. (equal '(11 23)
  2139. (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
  2140. (org-map-entries #'point "{yes?}"))))
  2141. ;; Priority match.
  2142. (should
  2143. (equal '(1)
  2144. (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
  2145. (org-map-entries #'point "PRIORITY=\"A\""))))
  2146. ;; Date match.
  2147. (should
  2148. (equal '(36)
  2149. (org-test-with-temp-text "
  2150. * H1
  2151. SCHEDULED: <2012-03-29 thu.>
  2152. * H2
  2153. SCHEDULED: <2014-03-04 tue.>"
  2154. (org-map-entries #'point "SCHEDULED=\"<2014-03-04 tue.>\""))))
  2155. (should
  2156. (equal '(2)
  2157. (org-test-with-temp-text "
  2158. * H1
  2159. SCHEDULED: <2012-03-29 thu.>
  2160. * H2
  2161. SCHEDULED: <2014-03-04 tue.>"
  2162. (org-map-entries #'point "SCHEDULED<\"<2013-01-01>\""))))
  2163. ;; Regular property match.
  2164. (should
  2165. (equal '(2)
  2166. (org-test-with-temp-text "
  2167. * H1
  2168. :PROPERTIES:
  2169. :TEST: 1
  2170. :END:
  2171. * H2
  2172. :PROPERTIES:
  2173. :TEST: 2
  2174. :END:"
  2175. (org-map-entries #'point "TEST=1"))))
  2176. ;; Multiple criteria.
  2177. (should
  2178. (equal '(23)
  2179. (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
  2180. (let (org-odd-levels-only
  2181. (org-use-tag-inheritance nil))
  2182. (org-map-entries #'point "yes+LEVEL=1")))))
  2183. ;; "or" criteria.
  2184. (should
  2185. (equal '(12 24)
  2186. (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
  2187. (let (org-odd-levels-only)
  2188. (org-map-entries #'point "LEVEL=2|no")))))
  2189. (should
  2190. (equal '(1 12)
  2191. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
  2192. (let (org-odd-levels-only)
  2193. (org-map-entries #'point "yes|no")))))
  2194. ;; "and" criteria.
  2195. (should
  2196. (equal '(22)
  2197. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
  2198. (let (org-odd-levels-only)
  2199. (org-map-entries #'point "yes&no"))))))
  2200. (ert-deftest test-org/edit-headline ()
  2201. "Test `org-edit-headline' specifications."
  2202. (should
  2203. (equal "* B"
  2204. (org-test-with-temp-text "* A"
  2205. (org-edit-headline "B")
  2206. (buffer-string))))
  2207. ;; Handle empty headings.
  2208. (should
  2209. (equal "* "
  2210. (org-test-with-temp-text "* A"
  2211. (org-edit-headline "")
  2212. (buffer-string))))
  2213. (should
  2214. (equal "* A"
  2215. (org-test-with-temp-text "* "
  2216. (org-edit-headline "A")
  2217. (buffer-string))))
  2218. ;; Handle TODO keywords and priority cookies.
  2219. (should
  2220. (equal "* TODO B"
  2221. (org-test-with-temp-text "* TODO A"
  2222. (org-edit-headline "B")
  2223. (buffer-string))))
  2224. (should
  2225. (equal "* [#A] B"
  2226. (org-test-with-temp-text "* [#A] A"
  2227. (org-edit-headline "B")
  2228. (buffer-string))))
  2229. (should
  2230. (equal "* TODO [#A] B"
  2231. (org-test-with-temp-text "* TODO [#A] A"
  2232. (org-edit-headline "B")
  2233. (buffer-string))))
  2234. ;; Handle tags.
  2235. (equal "* B :tag:"
  2236. (org-test-with-temp-text "* A :tag:"
  2237. (let ((org-tags-column 4)) (org-edit-headline "B"))
  2238. (buffer-string))))
  2239. ;;; Keywords
  2240. (ert-deftest test-org/set-regexps-and-options ()
  2241. "Test `org-set-regexps-and-options' specifications."
  2242. ;; TAGS keyword.
  2243. (should
  2244. (equal '(("A"))
  2245. (let ((org-tag-alist '(("A")))
  2246. (org-tag-persistent-alist nil))
  2247. (org-test-with-temp-text ""
  2248. (org-mode-restart)
  2249. org-current-tag-alist))))
  2250. (should
  2251. (equal '(("B"))
  2252. (let ((org-tag-alist '(("A")))
  2253. (org-tag-persistent-alist nil))
  2254. (org-test-with-temp-text "#+TAGS: B"
  2255. (org-mode-restart)
  2256. org-current-tag-alist))))
  2257. (should
  2258. (equal '(("C") ("B"))
  2259. (let ((org-tag-alist '(("A")))
  2260. (org-tag-persistent-alist '(("C"))))
  2261. (org-test-with-temp-text "#+TAGS: B"
  2262. (org-mode-restart)
  2263. org-current-tag-alist))))
  2264. (should
  2265. (equal '(("B"))
  2266. (let ((org-tag-alist '(("A")))
  2267. (org-tag-persistent-alist '(("C"))))
  2268. (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
  2269. (org-mode-restart)
  2270. org-current-tag-alist))))
  2271. (should
  2272. (equal '(("A" . ?a) ("B") ("C"))
  2273. (let ((org-tag-persistant-alist nil))
  2274. (org-test-with-temp-text "#+TAGS: A(a) B C"
  2275. (org-mode-restart)
  2276. org-current-tag-alist))))
  2277. (should
  2278. (equal '(("A") (:newline) ("B"))
  2279. (let ((org-tag-persistent-alist nil))
  2280. (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
  2281. (org-mode-restart)
  2282. org-current-tag-alist))))
  2283. (should
  2284. (equal '((:startgroup) ("A") ("B") (:endgroup) ("C"))
  2285. (let ((org-tag-persistent-alist nil))
  2286. (org-test-with-temp-text "#+TAGS: { A B } C"
  2287. (org-mode-restart)
  2288. org-current-tag-alist))))
  2289. (should
  2290. (equal '((:startgroup) ("A") (:grouptags) ("B") ("C") (:endgroup))
  2291. (let ((org-tag-persistent-alist nil))
  2292. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2293. (org-mode-restart)
  2294. org-current-tag-alist))))
  2295. (should
  2296. (equal '(("A" "B" "C"))
  2297. (let ((org-tag-persistent-alist nil))
  2298. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2299. (org-mode-restart)
  2300. org-tag-groups-alist))))
  2301. (should
  2302. (equal '((:startgrouptag) ("A") (:grouptags) ("B") ("C") (:endgrouptag))
  2303. (let ((org-tag-persistent-alist nil))
  2304. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2305. (org-mode-restart)
  2306. org-current-tag-alist))))
  2307. (should
  2308. (equal '(("A" "B" "C"))
  2309. (let ((org-tag-persistent-alist nil))
  2310. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2311. (org-mode-restart)
  2312. org-tag-groups-alist))))
  2313. ;; FILETAGS keyword.
  2314. (should
  2315. (equal '("A" "B" "C")
  2316. (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
  2317. (org-mode-restart)
  2318. org-file-tags)))
  2319. ;; PROPERTY keyword. Property names are case-insensitive.
  2320. (should
  2321. (equal "foo=1"
  2322. (org-test-with-temp-text "#+PROPERTY: var foo=1"
  2323. (org-mode-restart)
  2324. (cdr (assoc "var" org-keyword-properties)))))
  2325. (should
  2326. (equal
  2327. "foo=1 bar=2"
  2328. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
  2329. (org-mode-restart)
  2330. (cdr (assoc "var" org-keyword-properties)))))
  2331. (should
  2332. (equal
  2333. "foo=1 bar=2"
  2334. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
  2335. (org-mode-restart)
  2336. (cdr (assoc "var" org-keyword-properties)))))
  2337. ;; ARCHIVE keyword.
  2338. (should
  2339. (equal "%s_done::"
  2340. (org-test-with-temp-text "#+ARCHIVE: %s_done::"
  2341. (org-mode-restart)
  2342. org-archive-location)))
  2343. ;; CATEGORY keyword.
  2344. (should
  2345. (eq 'test
  2346. (org-test-with-temp-text "#+CATEGORY: test"
  2347. (org-mode-restart)
  2348. org-category)))
  2349. (should
  2350. (equal "test"
  2351. (org-test-with-temp-text "#+CATEGORY: test"
  2352. (org-mode-restart)
  2353. (cdr (assoc "CATEGORY" org-keyword-properties)))))
  2354. ;; COLUMNS keyword.
  2355. (should
  2356. (equal "%25ITEM %TAGS %PRIORITY %TODO"
  2357. (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
  2358. (org-mode-restart)
  2359. org-columns-default-format)))
  2360. ;; CONSTANTS keyword. Constants names are case sensitive.
  2361. (should
  2362. (equal '("299792458." "3.14")
  2363. (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
  2364. (org-mode-restart)
  2365. (mapcar
  2366. (lambda (n) (cdr (assoc n org-table-formula-constants-local)))
  2367. '("c" "pi")))))
  2368. (should
  2369. (equal "3.14"
  2370. (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
  2371. (org-mode-restart)
  2372. (cdr (assoc "pi" org-table-formula-constants-local)))))
  2373. (should
  2374. (equal "22/7"
  2375. (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
  2376. (org-mode-restart)
  2377. (cdr (assoc "PI" org-table-formula-constants-local)))))
  2378. ;; LINK keyword.
  2379. (should
  2380. (equal
  2381. '("url1" "url2")
  2382. (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
  2383. (org-mode-restart)
  2384. (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local)))
  2385. '("a" "b")))))
  2386. ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
  2387. (should
  2388. (equal
  2389. '(?X ?Z ?Y)
  2390. (org-test-with-temp-text "#+PRIORITIES: X Z Y"
  2391. (org-mode-restart)
  2392. (list org-priority-highest org-priority-lowest org-priority-default))))
  2393. (should
  2394. (equal
  2395. '(?A ?C ?B)
  2396. (org-test-with-temp-text "#+PRIORITIES: X Z"
  2397. (org-mode-restart)
  2398. (list org-priority-highest org-priority-lowest org-priority-default))))
  2399. ;; STARTUP keyword.
  2400. (should
  2401. (equal '(t t)
  2402. (org-test-with-temp-text "#+STARTUP: fold odd"
  2403. (org-mode-restart)
  2404. (list org-startup-folded org-odd-levels-only))))
  2405. ;; TODO keywords.
  2406. (should
  2407. (equal '(("A" "B") ("C"))
  2408. (org-test-with-temp-text "#+TODO: A B | C"
  2409. (org-mode-restart)
  2410. (list org-not-done-keywords org-done-keywords))))
  2411. (should
  2412. (equal '(("A" "C") ("B" "D"))
  2413. (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
  2414. (org-mode-restart)
  2415. (list org-not-done-keywords org-done-keywords))))
  2416. (should
  2417. (equal '(("A" "B") ("C"))
  2418. (org-test-with-temp-text "#+TYP_TODO: A B | C"
  2419. (org-mode-restart)
  2420. (list org-not-done-keywords org-done-keywords))))
  2421. (should
  2422. (equal '((:startgroup) ("A" . ?a) (:endgroup))
  2423. (org-test-with-temp-text "#+TODO: A(a)"
  2424. (org-mode-restart)
  2425. org-todo-key-alist)))
  2426. (should
  2427. (equal '(("D" note nil) ("C" time nil) ("B" note time))
  2428. (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
  2429. (org-mode-restart)
  2430. org-todo-log-states)))
  2431. ;; Enter SETUPFILE keyword.
  2432. (should
  2433. (equal "1"
  2434. (org-test-with-temp-text
  2435. (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
  2436. (org-mode-restart)
  2437. (cdr (assoc "a" org-keyword-properties))))))
  2438. ;;; Links
  2439. ;;;; Coderefs
  2440. (ert-deftest test-org/coderef ()
  2441. "Test coderef links specifications."
  2442. (should
  2443. (org-test-with-temp-text "
  2444. #+BEGIN_SRC emacs-lisp
  2445. \(+ 1 1) (ref:sc)
  2446. #+END_SRC
  2447. \[[(sc)<point>]]"
  2448. (org-open-at-point)
  2449. (looking-at "(ref:sc)")))
  2450. ;; Find coderef even with alternate label format.
  2451. (should
  2452. (org-test-with-temp-text "
  2453. #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
  2454. \(+ 1 1) {ref:sc}
  2455. #+END_SRC
  2456. \[[(sc)<point>]]"
  2457. (org-open-at-point)
  2458. (looking-at "{ref:sc}"))))
  2459. ;;;; Custom ID
  2460. (ert-deftest test-org/custom-id ()
  2461. "Test custom ID links specifications."
  2462. (should
  2463. (org-test-with-temp-text
  2464. "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2465. (org-open-at-point)
  2466. (looking-at-p "\\* H1")))
  2467. ;; Handle escape characters.
  2468. (should
  2469. (org-test-with-temp-text
  2470. "* H1\n:PROPERTIES:\n:CUSTOM_ID: [%]\n:END:\n* H2\n[[#\\[%\\]<point>]]"
  2471. (org-open-at-point)
  2472. (looking-at-p "\\* H1")))
  2473. ;; Throw an error on false positives.
  2474. (should-error
  2475. (org-test-with-temp-text
  2476. "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2477. (org-open-at-point)
  2478. (looking-at-p "\\* H1"))))
  2479. ;;;; Fuzzy Links
  2480. ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
  2481. ;; a named element (#+name: text) and to headlines (* Text).
  2482. (ert-deftest test-org/fuzzy-links ()
  2483. "Test fuzzy links specifications."
  2484. ;; Fuzzy link goes in priority to a matching target.
  2485. (should
  2486. (org-test-with-temp-text
  2487. "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
  2488. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2489. (looking-at "<<Test>>")))
  2490. ;; Then fuzzy link points to an element with a given name.
  2491. (should
  2492. (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
  2493. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2494. (looking-at "#\\+NAME: Test")))
  2495. ;; A target still lead to a matching headline otherwise.
  2496. (should
  2497. (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
  2498. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2499. (looking-at "\\* Head2")))
  2500. ;; With a leading star in link, enforce heading match.
  2501. (should
  2502. (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
  2503. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2504. (looking-at "\\* Test")))
  2505. ;; With a leading star in link, enforce exact heading match, even
  2506. ;; with `org-link-search-must-match-exact-headline' set to nil.
  2507. (should-error
  2508. (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
  2509. (let ((org-link-search-must-match-exact-headline nil))
  2510. (org-open-at-point))))
  2511. ;; Handle non-nil `org-link-search-must-match-exact-headline'.
  2512. (should
  2513. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
  2514. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2515. (looking-at "\\* Test")))
  2516. (should
  2517. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
  2518. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2519. (looking-at "\\* Test")))
  2520. ;; Heading match should not care about spaces, cookies, TODO
  2521. ;; keywords, priorities, and tags. However, TODO keywords are
  2522. ;; case-sensitive.
  2523. (should
  2524. (let ((first-line
  2525. "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
  2526. (org-test-with-temp-text
  2527. (concat first-line "\nFoo Bar\n<point>[[*Test 1 2]]")
  2528. (let ((org-link-search-must-match-exact-headline nil)
  2529. (org-todo-regexp "TODO"))
  2530. (org-open-at-point))
  2531. (looking-at (regexp-quote first-line)))))
  2532. (should-error
  2533. (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
  2534. (let ((org-link-search-must-match-exact-headline nil)
  2535. (org-todo-regexp "TODO"))
  2536. (org-open-at-point))))
  2537. ;; Heading match should still be exact.
  2538. (should-error
  2539. (org-test-with-temp-text "
  2540. ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
  2541. Foo Bar
  2542. <point>[[*Test 1]]"
  2543. (let ((org-link-search-must-match-exact-headline nil)
  2544. (org-todo-regexp "TODO"))
  2545. (org-open-at-point))))
  2546. (should
  2547. (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
  2548. (let ((org-link-search-must-match-exact-headline nil)
  2549. (org-todo-regexp "TODO"))
  2550. (org-open-at-point))
  2551. (looking-at-p (regexp-quote "** Test 1 2"))))
  2552. ;; Heading match ignores COMMENT keyword.
  2553. (should
  2554. (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
  2555. (org-open-at-point)
  2556. (looking-at "\\* COMMENT Test")))
  2557. (should
  2558. (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
  2559. (org-open-at-point)
  2560. (looking-at "\\* TODO COMMENT Test")))
  2561. ;; Correctly un-escape fuzzy links.
  2562. (should
  2563. (org-test-with-temp-text "* [foo]\n[[*\\[foo\\]][With escaped characters]]"
  2564. (org-open-at-point)
  2565. (bobp)))
  2566. ;; Match search strings containing newline characters, including
  2567. ;; blank lines.
  2568. (should
  2569. (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
  2570. (let ((file (buffer-file-name)))
  2571. (goto-char (point-max))
  2572. (insert (format "[[file:%s::line1 line2]]" file))
  2573. (beginning-of-line)
  2574. (let ((org-link-search-must-match-exact-headline nil))
  2575. (org-open-at-point 0))
  2576. (looking-at-p "line1"))))
  2577. (should
  2578. (org-test-with-temp-text-in-file "Paragraph\n\nline1\n\nline2\n\n"
  2579. (let ((file (buffer-file-name)))
  2580. (goto-char (point-max))
  2581. (insert (format "[[file:%s::line1 line2]]" file))
  2582. (beginning-of-line)
  2583. (let ((org-link-search-must-match-exact-headline nil))
  2584. (org-open-at-point 0))
  2585. (looking-at-p "line1")))))
  2586. ;;;; Open at point
  2587. (ert-deftest test-org/open-at-point/keyword ()
  2588. "Does `org-open-at-point' open link in a keyword line?"
  2589. (should
  2590. (org-test-with-temp-text
  2591. "<<top>>\n#+KEYWORD: <point>[[top]]"
  2592. (org-open-at-point) t))
  2593. (should
  2594. (org-test-with-temp-text
  2595. "* H\n<<top>>\n#+KEYWORD: <point>[[top]]"
  2596. (org-open-at-point) t)))
  2597. (ert-deftest test-org/open-at-point/property ()
  2598. "Does `org-open-at-point' open link in property drawer?"
  2599. (should
  2600. (org-test-with-temp-text
  2601. "* Headline
  2602. :PROPERTIES:
  2603. :URL: <point>[[*Headline]]
  2604. :END:"
  2605. (org-open-at-point) t)))
  2606. (ert-deftest test-org/open-at-point/comment ()
  2607. "Does `org-open-at-point' open link in a commented line?"
  2608. (should
  2609. (org-test-with-temp-text
  2610. "<<top>>\n# <point>[[top]]"
  2611. (org-open-at-point) t))
  2612. (should
  2613. (org-test-with-temp-text
  2614. "* H\n<<top>>\n# <point>[[top]]"
  2615. (org-open-at-point) t)))
  2616. (ert-deftest test-org/open-at-point/inline-image ()
  2617. "Test `org-open-at-point' on nested links."
  2618. (should
  2619. (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
  2620. (org-open-at-point)
  2621. (bobp))))
  2622. (ert-deftest test-org/open-at-point/radio-target ()
  2623. "Test `org-open-at-point' on radio targets."
  2624. (should
  2625. (org-test-with-temp-text "<<<target>>> <point>target"
  2626. (org-update-radio-target-regexp)
  2627. (org-open-at-point)
  2628. (eq (org-element-type (org-element-context)) 'radio-target))))
  2629. (ert-deftest test-org/open-at-point/tag ()
  2630. "Test `org-open-at-point' on tags."
  2631. (should
  2632. (org-test-with-temp-text "* H :<point>tag:"
  2633. (catch :result
  2634. (cl-letf (((symbol-function 'org-tags-view)
  2635. (lambda (&rest args) (throw :result t))))
  2636. (org-open-at-point)
  2637. nil))))
  2638. (should-not
  2639. (org-test-with-temp-text-in-file "* H<point> :tag:"
  2640. (catch :result
  2641. (cl-letf (((symbol-function 'org-tags-view)
  2642. (lambda (&rest args) (throw :result t))))
  2643. ;; When point isn't on a tag it's going to try other things,
  2644. ;; possibly trying to open attachments which will return an
  2645. ;; error if there isn't an attachment. Suppress that error.
  2646. (ignore-errors
  2647. (org-open-at-point))
  2648. nil)))))
  2649. ;;; Node Properties
  2650. (ert-deftest test-org/accumulated-properties-in-drawers ()
  2651. "Ensure properties accumulate in subtree drawers."
  2652. (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
  2653. (org-babel-next-src-block)
  2654. (should (equal '(2 1) (org-babel-execute-src-block)))))
  2655. (ert-deftest test-org/custom-properties ()
  2656. "Test custom properties specifications."
  2657. ;; Standard test.
  2658. (should
  2659. (let ((org-custom-properties '("FOO")))
  2660. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2661. (org-toggle-custom-properties-visibility)
  2662. (org-invisible-p2))))
  2663. ;; Properties are case-insensitive.
  2664. (should
  2665. (let ((org-custom-properties '("FOO")))
  2666. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
  2667. (org-toggle-custom-properties-visibility)
  2668. (org-invisible-p2))))
  2669. (should
  2670. (let ((org-custom-properties '("foo")))
  2671. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2672. (org-toggle-custom-properties-visibility)
  2673. (org-invisible-p2))))
  2674. ;; Multiple custom properties in the same drawer.
  2675. (should
  2676. (let ((org-custom-properties '("FOO" "BAR")))
  2677. (org-test-with-temp-text
  2678. "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
  2679. (org-toggle-custom-properties-visibility)
  2680. (and (org-invisible-p2)
  2681. (not (progn (forward-line) (org-invisible-p2)))
  2682. (progn (forward-line) (org-invisible-p2))))))
  2683. ;; Hide custom properties with an empty value.
  2684. (should
  2685. (let ((org-custom-properties '("FOO")))
  2686. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
  2687. (org-toggle-custom-properties-visibility)
  2688. (org-invisible-p2))))
  2689. ;; Do not hide fake properties.
  2690. (should-not
  2691. (let ((org-custom-properties '("FOO")))
  2692. (org-test-with-temp-text ":FOO: val\n"
  2693. (org-toggle-custom-properties-visibility)
  2694. (org-invisible-p2))))
  2695. (should-not
  2696. (let ((org-custom-properties '("A")))
  2697. (org-test-with-temp-text
  2698. "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
  2699. (org-toggle-custom-properties-visibility)
  2700. (org-invisible-p2)))))
  2701. ;;; Mark Region
  2702. (ert-deftest test-org/mark-element ()
  2703. "Test `org-mark-element' specifications."
  2704. ;; Mark beginning and end of element.
  2705. (should
  2706. (equal '(t t)
  2707. (org-test-with-temp-text "Para<point>graph"
  2708. (org-mark-element)
  2709. (list (bobp) (= (mark) (point-max))))))
  2710. (should
  2711. (equal '(t t)
  2712. (org-test-with-temp-text "P1\n\nPara<point>graph\n\nP2"
  2713. (org-mark-element)
  2714. (list (looking-at "Paragraph")
  2715. (org-with-point-at (mark) (looking-at "P2"))))))
  2716. ;; Do not set mark past (point-max).
  2717. (should
  2718. (org-test-with-temp-text "Para<point>graph"
  2719. (narrow-to-region 2 6)
  2720. (org-mark-element)
  2721. (= 6 (mark)))))
  2722. (ert-deftest test-org/mark-subtree ()
  2723. "Test `org-mark-subtree' specifications."
  2724. ;; Error when point is before first headline.
  2725. (should-error
  2726. (org-test-with-temp-text "Paragraph\n* Headline\nBody"
  2727. (progn (transient-mark-mode 1)
  2728. (org-mark-subtree))))
  2729. ;; Without argument, mark current subtree.
  2730. (should
  2731. (equal
  2732. '(12 32)
  2733. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  2734. (progn (transient-mark-mode 1)
  2735. (forward-line 2)
  2736. (org-mark-subtree)
  2737. (list (region-beginning) (region-end))))))
  2738. ;; With an argument, move ARG up.
  2739. (should
  2740. (equal
  2741. '(1 32)
  2742. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  2743. (progn (transient-mark-mode 1)
  2744. (forward-line 2)
  2745. (org-mark-subtree 1)
  2746. (list (region-beginning) (region-end))))))
  2747. ;; Do not get fooled by inlinetasks.
  2748. (when (featurep 'org-inlinetask)
  2749. (should
  2750. (= 1
  2751. (org-test-with-temp-text "* Headline\n*************** Task\nContents"
  2752. (progn (transient-mark-mode 1)
  2753. (forward-line 1)
  2754. (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
  2755. (region-beginning)))))))
  2756. ;;; Miscellaneous
  2757. (ert-deftest test-org/sort-entries ()
  2758. "Test `org-sort-entries'."
  2759. ;; Sort alphabetically.
  2760. (should
  2761. (equal "\n* abc\n* def\n* xyz\n"
  2762. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  2763. (org-sort-entries nil ?a)
  2764. (buffer-string))))
  2765. (should
  2766. (equal "\n* xyz\n* def\n* abc\n"
  2767. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  2768. (org-sort-entries nil ?A)
  2769. (buffer-string))))
  2770. (should
  2771. (equal "\n* \n* klm\n* xyz\n"
  2772. (org-test-with-temp-text "\n* xyz\n* \n* klm\n"
  2773. (org-sort-entries nil ?a)
  2774. (buffer-string))))
  2775. ;; Sort numerically.
  2776. (should
  2777. (equal "\n* 1\n* 2\n* 10\n"
  2778. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  2779. (org-sort-entries nil ?n)
  2780. (buffer-string))))
  2781. (should
  2782. (equal "\n* 10\n* 2\n* 1\n"
  2783. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  2784. (org-sort-entries nil ?N)
  2785. (buffer-string))))
  2786. (should
  2787. (equal "\n* \n* 1\n* 2\n"
  2788. (org-test-with-temp-text "\n* 1\n* \n* 2\n"
  2789. (org-sort-entries nil ?n)
  2790. (buffer-string))))
  2791. ;; Sort by custom function.
  2792. (should
  2793. (equal "\n* b\n* aa\n* ccc\n"
  2794. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  2795. (org-sort-entries nil ?f
  2796. (lambda ()
  2797. (length (buffer-substring (point-at-bol)
  2798. (point-at-eol))))
  2799. #'<)
  2800. (buffer-string))))
  2801. (should
  2802. (equal "\n* ccc\n* aa\n* b\n"
  2803. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  2804. (org-sort-entries nil ?F
  2805. (lambda ()
  2806. (length (buffer-substring (point-at-bol)
  2807. (point-at-eol))))
  2808. #'<)
  2809. (buffer-string))))
  2810. ;; Sort by TODO keyword.
  2811. (should
  2812. (equal "\n* TODO h1\n* TODO h3\n* DONE h2\n"
  2813. (org-test-with-temp-text
  2814. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  2815. (org-sort-entries nil ?o)
  2816. (buffer-string))))
  2817. (should
  2818. (equal "\n* DONE h2\n* TODO h1\n* TODO h3\n"
  2819. (org-test-with-temp-text
  2820. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  2821. (org-sort-entries nil ?O)
  2822. (buffer-string))))
  2823. ;; Sort by priority.
  2824. (should
  2825. (equal "\n* [#A] h2\n* [#B] h3\n* [#C] h1\n"
  2826. (org-test-with-temp-text
  2827. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  2828. (org-sort-entries nil ?p)
  2829. (buffer-string))))
  2830. (should
  2831. (equal "\n* [#C] h1\n* [#B] h3\n* [#A] h2\n"
  2832. (org-test-with-temp-text
  2833. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  2834. (org-sort-entries nil ?P)
  2835. (buffer-string))))
  2836. ;; Sort by creation time.
  2837. (should
  2838. (equal "
  2839. * h3
  2840. [2017-05-08 Mon]
  2841. * h2
  2842. [2017-05-09 Tue]
  2843. * h1
  2844. [2018-05-09 Wed]
  2845. "
  2846. (org-test-with-temp-text
  2847. "
  2848. * h1
  2849. [2018-05-09 Wed]
  2850. * h2
  2851. [2017-05-09 Tue]
  2852. * h3
  2853. [2017-05-08 Mon]
  2854. "
  2855. (org-sort-entries nil ?c)
  2856. (buffer-string))))
  2857. ;; Sort by scheduled date.
  2858. (should
  2859. (equal "
  2860. * TODO h4
  2861. SCHEDULED: <2017-05-06 Sat>
  2862. * TODO h3
  2863. SCHEDULED: <2017-05-08 Mon>
  2864. * TODO h2
  2865. DEADLINE: <2017-05-09 Tue>
  2866. * TODO h1
  2867. DEADLINE: <2017-05-07 Sun>
  2868. "
  2869. (org-test-with-temp-text
  2870. "
  2871. * TODO h2
  2872. DEADLINE: <2017-05-09 Tue>
  2873. * TODO h1
  2874. DEADLINE: <2017-05-07 Sun>
  2875. * TODO h3
  2876. SCHEDULED: <2017-05-08 Mon>
  2877. * TODO h4
  2878. SCHEDULED: <2017-05-06 Sat>
  2879. "
  2880. (org-sort-entries nil ?s)
  2881. (buffer-string))))
  2882. ;; Sort by deadline date.
  2883. (should
  2884. (equal "
  2885. * TODO h1
  2886. DEADLINE: <2017-05-07 Sun>
  2887. * TODO h2
  2888. DEADLINE: <2017-05-09 Tue>
  2889. * TODO h3
  2890. SCHEDULED: <2017-05-08 Mon>
  2891. * TODO h4
  2892. SCHEDULED: <2017-05-06 Sat>
  2893. "
  2894. (org-test-with-temp-text
  2895. "
  2896. * TODO h2
  2897. DEADLINE: <2017-05-09 Tue>
  2898. * TODO h1
  2899. DEADLINE: <2017-05-07 Sun>
  2900. * TODO h3
  2901. SCHEDULED: <2017-05-08 Mon>
  2902. * TODO h4
  2903. SCHEDULED: <2017-05-06 Sat>
  2904. "
  2905. (org-sort-entries nil ?d)
  2906. (buffer-string))))
  2907. ;; Sort by any date/time
  2908. (should
  2909. (equal "
  2910. * TODO h4
  2911. SCHEDULED: <2017-05-06 Sat>
  2912. * TODO h1
  2913. DEADLINE: <2017-05-07 Sun>
  2914. * TODO h3
  2915. SCHEDULED: <2017-05-08 Mon>
  2916. * TODO h2
  2917. DEADLINE: <2017-05-09 Tue>
  2918. "
  2919. (org-test-with-temp-text
  2920. "
  2921. * TODO h2
  2922. DEADLINE: <2017-05-09 Tue>
  2923. * TODO h1
  2924. DEADLINE: <2017-05-07 Sun>
  2925. * TODO h3
  2926. SCHEDULED: <2017-05-08 Mon>
  2927. * TODO h4
  2928. SCHEDULED: <2017-05-06 Sat>
  2929. "
  2930. (org-sort-entries nil ?t)
  2931. (buffer-string))))
  2932. ;; Sort by clocking time.
  2933. (should
  2934. (equal "
  2935. * clocked h2
  2936. :LOGBOOK:
  2937. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  2938. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  2939. :END:
  2940. * clocked h1
  2941. :LOGBOOK:
  2942. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  2943. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  2944. :END:
  2945. "
  2946. (org-test-with-temp-text
  2947. "
  2948. * clocked h1
  2949. :LOGBOOK:
  2950. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  2951. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  2952. :END:
  2953. * clocked h2
  2954. :LOGBOOK:
  2955. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  2956. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  2957. :END:
  2958. "
  2959. (org-sort-entries nil ?k)
  2960. (buffer-string))))
  2961. ;; Preserve file local variables when sorting.
  2962. (should
  2963. (equal "\n* A\n* B\n# Local Variables:\n# foo: t\n# End:\n"
  2964. (org-test-with-temp-text
  2965. "\n* B\n* A\n# Local Variables:\n# foo: t\n# End:"
  2966. (org-sort-entries nil ?a)
  2967. (buffer-string)))))
  2968. (ert-deftest test-org/string-collate-greaterp ()
  2969. "Test `org-string-collate-greaterp' specifications."
  2970. (should (org-string-collate-greaterp "def" "abc"))
  2971. (should-not (org-string-collate-greaterp "abc" "def")))
  2972. (ert-deftest test-org/file-contents ()
  2973. "Test `org-file-contents' specifications."
  2974. ;; Open files.
  2975. (should
  2976. (string= "#+BIND: variable value
  2977. #+DESCRIPTION: l2
  2978. #+LANGUAGE: en
  2979. #+SELECT_TAGS: b
  2980. #+TITLE: b
  2981. #+PROPERTY: a 1
  2982. " (org-file-contents (expand-file-name "setupfile3.org"
  2983. (concat org-test-dir "examples/")))))
  2984. ;; Throw error when trying to access an invalid file.
  2985. (should-error (org-file-contents "this-file-must-not-exist"))
  2986. ;; Try to access an invalid file, but do not throw an error.
  2987. (should
  2988. (progn (org-file-contents "this-file-must-not-exist" :noerror) t))
  2989. ;; Open URL.
  2990. (should
  2991. (string= "foo"
  2992. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  2993. (unwind-protect
  2994. ;; Simulate successful retrieval of a URL.
  2995. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  2996. (lambda (&rest_)
  2997. (with-current-buffer buffer
  2998. (insert "HTTP/1.1 200 OK\n\nfoo"))
  2999. buffer)))
  3000. (org-file-contents "http://some-valid-url"))
  3001. (kill-buffer buffer)))))
  3002. ;; Throw error when trying to access an invalid URL.
  3003. (should-error
  3004. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3005. (unwind-protect
  3006. ;; Simulate unsuccessful retrieval of a URL.
  3007. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3008. (lambda (&rest_)
  3009. (with-current-buffer buffer
  3010. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3011. buffer)))
  3012. (org-file-contents "http://this-url-must-not-exist"))
  3013. (kill-buffer buffer))))
  3014. ;; Try to access an invalid URL, but do not throw an error.
  3015. (should-error
  3016. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3017. (unwind-protect
  3018. ;; Simulate unsuccessful retrieval of a URL.
  3019. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3020. (lambda (&rest_)
  3021. (with-current-buffer buffer
  3022. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3023. buffer)))
  3024. (org-file-contents "http://this-url-must-not-exist"))
  3025. (kill-buffer buffer))))
  3026. (should
  3027. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3028. (unwind-protect
  3029. ;; Simulate unsuccessful retrieval of a URL.
  3030. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3031. (lambda (&rest_)
  3032. (with-current-buffer buffer
  3033. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3034. buffer)))
  3035. (org-file-contents "http://this-url-must-not-exist" :noerror))
  3036. (kill-buffer buffer))
  3037. t)))
  3038. ;;; Navigation
  3039. (ert-deftest test-org/next-visible-heading ()
  3040. "Test `org-next-visible-heading' specifications."
  3041. ;; Move to the beginning of the next headline, taking into
  3042. ;; consideration ARG.
  3043. (should
  3044. (org-test-with-temp-text "* H1\n* H2"
  3045. (org-next-visible-heading 1)
  3046. (looking-at "\\* H2")))
  3047. (should
  3048. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3049. (org-next-visible-heading 2)
  3050. (looking-at "\\* H3")))
  3051. ;; Ignore invisible headlines.
  3052. (should
  3053. (org-test-with-temp-text "* H1\n** H2\n* H3"
  3054. (org-cycle)
  3055. (org-next-visible-heading 1)
  3056. (looking-at "\\* H3")))
  3057. ;; Move point between headlines, not on blank lines between.
  3058. (should
  3059. (org-test-with-temp-text "* H1\n** H2\n\n\n\n* H3"
  3060. (let ((org-cycle-separator-lines 1))
  3061. (org-cycle)
  3062. (org-next-visible-heading 1))
  3063. (looking-at "\\* H3")))
  3064. ;; Move at end of buffer when there is no more headline.
  3065. (should
  3066. (org-test-with-temp-text "* H1"
  3067. (org-next-visible-heading 1)
  3068. (eobp)))
  3069. (should
  3070. (org-test-with-temp-text "* H1\n* H2"
  3071. (org-next-visible-heading 2)
  3072. (eobp)))
  3073. ;; With a negative argument, move backwards.
  3074. (should
  3075. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3076. (org-next-visible-heading -1)
  3077. (looking-at "\\* H2")))
  3078. (should
  3079. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3080. (org-next-visible-heading -2)
  3081. (looking-at "\\* H1"))))
  3082. (ert-deftest test-org/previous-visible-heading ()
  3083. "Test `org-previous-visible-heading' specifications."
  3084. ;; Move to the beginning of the next headline, taking into
  3085. ;; consideration ARG.
  3086. (should
  3087. (org-test-with-temp-text "* H1\n<point>* H2"
  3088. (org-previous-visible-heading 1)
  3089. (looking-at "\\* H1")))
  3090. (should
  3091. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3092. (org-previous-visible-heading 2)
  3093. (looking-at "\\* H1")))
  3094. ;; Ignore invisible headlines.
  3095. (should
  3096. (org-test-with-temp-text "* H1\n** H2\n<point>* H3"
  3097. (org-overview)
  3098. (org-previous-visible-heading 1)
  3099. (looking-at "\\* H1")))
  3100. ;; Move point between headlines, not on blank lines between.
  3101. (should
  3102. (org-test-with-temp-text "* H1\n\n\n\n** H2\n<point>* H3"
  3103. (let ((org-cycle-separator-lines 1))
  3104. (org-overview)
  3105. (org-previous-visible-heading 1))
  3106. (looking-at "\\* H1")))
  3107. ;; Move at end of buffer when there is no more headline.
  3108. (should
  3109. (org-test-with-temp-text "* H1"
  3110. (org-previous-visible-heading 1)
  3111. (bobp)))
  3112. (should
  3113. (org-test-with-temp-text "* H1\n* <point>H2"
  3114. (org-previous-visible-heading 2)
  3115. (bobp)))
  3116. ;; Invisible parts may not start at a headline, i.e., when revealing
  3117. ;; parts of the buffer. Handle this.
  3118. (should
  3119. (org-test-with-temp-text "* Main\n** H1\nFoo\n** H2\nBar\n** H3\nBaz"
  3120. (org-overview)
  3121. (search-forward "H1")
  3122. (org-show-context 'minimal)
  3123. (org-cycle)
  3124. (search-forward "H3")
  3125. (org-show-context 'minimal)
  3126. ;; At this point, buffer displays, with point at "|",
  3127. ;;
  3128. ;; * Main
  3129. ;; ** H1
  3130. ;; Foo
  3131. ;; ** H3|
  3132. (org-previous-visible-heading 1)
  3133. (looking-at "\\*+ H1"))))
  3134. (ert-deftest test-org/forward-heading-same-level ()
  3135. "Test `org-forward-heading-same-level' specifications."
  3136. ;; Test navigation at top level, forward and backward.
  3137. (should
  3138. (equal "* H2"
  3139. (org-test-with-temp-text "* H1\n* H2"
  3140. (org-forward-heading-same-level 1)
  3141. (buffer-substring-no-properties (point) (line-end-position)))))
  3142. (should
  3143. (equal "* H1"
  3144. (org-test-with-temp-text "* H1\n<point>* H2"
  3145. (org-forward-heading-same-level -1)
  3146. (buffer-substring-no-properties (point) (line-end-position)))))
  3147. ;; Test navigation in a sub-tree, forward and backward.
  3148. (should
  3149. (equal "* H2"
  3150. (org-test-with-temp-text "* H1\n** H11\n** H12\n* H2"
  3151. (org-forward-heading-same-level 1)
  3152. (buffer-substring-no-properties (point) (line-end-position)))))
  3153. (should
  3154. (equal "* H1"
  3155. (org-test-with-temp-text "* H1\n** H11\n** H12\n<point>* H2"
  3156. (org-forward-heading-same-level -1)
  3157. (buffer-substring-no-properties (point) (line-end-position)))))
  3158. ;; Stop at first or last sub-heading.
  3159. (should-not
  3160. (equal "* H2"
  3161. (org-test-with-temp-text "* H1\n** H11\n<point>** H12\n* H2"
  3162. (org-forward-heading-same-level 1)
  3163. (buffer-substring-no-properties (point) (line-end-position)))))
  3164. (should-not
  3165. (equal "* H2"
  3166. (org-test-with-temp-text "* H1\n<point>** H11\n** H12\n* H2"
  3167. (org-forward-heading-same-level -1)
  3168. (buffer-substring-no-properties (point) (line-end-position)))))
  3169. ;; Allow multiple moves.
  3170. (should
  3171. (equal "* H3"
  3172. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3173. (org-forward-heading-same-level 2)
  3174. (buffer-substring-no-properties (point) (line-end-position)))))
  3175. (should
  3176. (equal "* H1"
  3177. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3178. (org-forward-heading-same-level -2)
  3179. (buffer-substring-no-properties (point) (line-end-position)))))
  3180. ;; Ignore spurious moves when first (or last) sibling is reached.
  3181. (should
  3182. (equal "** H3"
  3183. (org-test-with-temp-text "* First\n<point>** H1\n** H2\n** H3\n* Last"
  3184. (org-forward-heading-same-level 100)
  3185. (buffer-substring-no-properties (point) (line-end-position)))))
  3186. (should
  3187. (equal "** H1"
  3188. (org-test-with-temp-text "* First\n** H1\n** H2\n<point>** H3\n* Last"
  3189. (org-forward-heading-same-level -100)
  3190. (buffer-substring-no-properties (point) (line-end-position))))))
  3191. (ert-deftest test-org/end-of-meta-data ()
  3192. "Test `org-end-of-meta-data' specifications."
  3193. ;; Skip planning line.
  3194. (should
  3195. (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
  3196. (org-end-of-meta-data)
  3197. (eobp)))
  3198. ;; Skip properties drawer.
  3199. (should
  3200. (org-test-with-temp-text
  3201. "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
  3202. (org-end-of-meta-data)
  3203. (eobp)))
  3204. ;; Skip both.
  3205. (should
  3206. (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
  3207. (org-end-of-meta-data)
  3208. (eobp)))
  3209. ;; Nothing to skip, go to first line.
  3210. (should
  3211. (org-test-with-temp-text "* Headline\nContents"
  3212. (org-end-of-meta-data)
  3213. (looking-at "Contents")))
  3214. ;; With option argument, skip empty lines, regular drawers and
  3215. ;; clocking lines.
  3216. (should
  3217. (org-test-with-temp-text "* Headline\n\nContents"
  3218. (org-end-of-meta-data t)
  3219. (looking-at "Contents")))
  3220. (should
  3221. (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
  3222. (org-end-of-meta-data t)
  3223. (looking-at "Contents")))
  3224. (should
  3225. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
  3226. (org-end-of-meta-data t)
  3227. (looking-at "Contents")))
  3228. ;; Special case: do not skip incomplete drawers.
  3229. (should
  3230. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
  3231. (org-end-of-meta-data t)
  3232. (looking-at ":LOGBOOK:")))
  3233. ;; Special case: Be careful about consecutive headlines.
  3234. (should-not
  3235. (org-test-with-temp-text "* H1\n*H2\nContents"
  3236. (org-end-of-meta-data t)
  3237. (looking-at "Contents"))))
  3238. (ert-deftest test-org/beginning-of-line ()
  3239. "Test `org-beginning-of-line' specifications."
  3240. ;; Move to beginning of line. If current line in invisible, move to
  3241. ;; beginning of visible line instead.
  3242. (should
  3243. (org-test-with-temp-text "Some text\nSome other text<point>"
  3244. (org-beginning-of-line)
  3245. (bolp)))
  3246. (should
  3247. (org-test-with-temp-text "* H1\n** H2<point>"
  3248. (org-overview)
  3249. (org-beginning-of-line)
  3250. (= (line-beginning-position) 1)))
  3251. ;; With `visual-line-mode' active, move to beginning of visual line.
  3252. (should-not
  3253. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3254. (visual-line-mode)
  3255. (dotimes (i 1000) (insert "very "))
  3256. (org-beginning-of-line)
  3257. (bolp)))
  3258. ;; In a wide headline, with `visual-line-mode', prefer going to the
  3259. ;; beginning of a visual line than to the logical beginning of line,
  3260. ;; even if special movement is active.
  3261. (should-not
  3262. (org-test-with-temp-text "* A <point>long headline"
  3263. (visual-line-mode)
  3264. (dotimes (i 1000) (insert "very "))
  3265. (goto-char (point-max))
  3266. (org-beginning-of-line)
  3267. (bobp)))
  3268. (should-not
  3269. (org-test-with-temp-text "* A <point>long headline"
  3270. (visual-line-mode)
  3271. (dotimes (i 1000) (insert "very "))
  3272. (goto-char (point-max))
  3273. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line))
  3274. (bobp)))
  3275. ;; At an headline with special movement, first move at beginning of
  3276. ;; title, then at the beginning of line, rinse, repeat.
  3277. (should
  3278. (org-test-with-temp-text "* TODO Headline<point>"
  3279. (let ((org-special-ctrl-a/e t))
  3280. (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
  3281. (progn (org-beginning-of-line) (bolp))
  3282. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3283. (should
  3284. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3285. (let ((org-special-ctrl-a/e t))
  3286. (org-beginning-of-line)
  3287. (looking-at "Headline"))))
  3288. (should
  3289. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3290. (let ((org-special-ctrl-a/e '(t . nil)))
  3291. (org-beginning-of-line)
  3292. (looking-at "Headline"))))
  3293. (should-not
  3294. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3295. (let ((org-special-ctrl-a/e '(nil . nil)))
  3296. (org-beginning-of-line)
  3297. (looking-at "Headline"))))
  3298. ;; At an headline with reversed movement, first move to beginning of
  3299. ;; line, then to the beginning of title.
  3300. (should
  3301. (org-test-with-temp-text "* TODO Headline<point>"
  3302. (let ((org-special-ctrl-a/e 'reversed)
  3303. (this-command last-command))
  3304. (and (progn (org-beginning-of-line) (bolp))
  3305. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3306. (should
  3307. (org-test-with-temp-text "* TODO Headline<point>"
  3308. (let ((org-special-ctrl-a/e '(reversed . nil))
  3309. (this-command last-command))
  3310. (and (progn (org-beginning-of-line) (bolp))
  3311. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3312. (should-not
  3313. (org-test-with-temp-text "* TODO Headline<point>"
  3314. (let ((org-special-ctrl-a/e '(t . nil))
  3315. (this-command last-command))
  3316. (and (progn (org-beginning-of-line) (bolp))
  3317. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3318. ;; At an item with special movement, first move after to beginning
  3319. ;; of title, then to the beginning of line, rinse, repeat.
  3320. (should
  3321. (org-test-with-temp-text "- [ ] Item<point>"
  3322. (let ((org-special-ctrl-a/e t))
  3323. (and (progn (org-beginning-of-line) (looking-at-p "Item"))
  3324. (progn (org-beginning-of-line) (bolp))
  3325. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3326. ;; At an item with reversed movement, first move to beginning of
  3327. ;; line, then to the beginning of title.
  3328. (should
  3329. (org-test-with-temp-text "- [X] Item<point>"
  3330. (let ((org-special-ctrl-a/e 'reversed)
  3331. (this-command last-command))
  3332. (and (progn (org-beginning-of-line) (bolp))
  3333. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3334. ;; Leave point before invisible characters at column 0.
  3335. (should
  3336. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3337. (let ((org-special-ctrl-a/e nil))
  3338. (org-beginning-of-line)
  3339. (bolp))))
  3340. (should
  3341. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3342. (let ((org-special-ctrl-a/e t))
  3343. (org-beginning-of-line)
  3344. (bolp))))
  3345. (should
  3346. (org-test-with-temp-text "[[http<point>://orgmode.org]]"
  3347. (visual-line-mode)
  3348. (org-beginning-of-line)
  3349. (bolp)))
  3350. ;; Special case: Do not error when the buffer contains only a single
  3351. ;; asterisk.
  3352. (should
  3353. (org-test-with-temp-text "*<point>"
  3354. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line) t)))
  3355. (should
  3356. (org-test-with-temp-text "*<point>"
  3357. (let ((org-special-ctrl-a/e nil)) (org-beginning-of-line) t))))
  3358. (ert-deftest test-org/end-of-line ()
  3359. "Test `org-end-of-line' specifications."
  3360. ;; Standard test.
  3361. (should
  3362. (org-test-with-temp-text "Some text\nSome other text"
  3363. (org-end-of-line)
  3364. (eolp)))
  3365. ;; With `visual-line-mode' active, move to end of visible line.
  3366. ;; However, never go past ellipsis.
  3367. (should-not
  3368. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3369. (visual-line-mode)
  3370. (dotimes (i 1000) (insert "very "))
  3371. (goto-char (point-min))
  3372. (org-end-of-line)
  3373. (eolp)))
  3374. (should-not
  3375. (org-test-with-temp-text "* A short headline\nSome contents"
  3376. (visual-line-mode)
  3377. (org-overview)
  3378. (org-end-of-line)
  3379. (eobp)))
  3380. ;; In a wide headline, with `visual-line-mode', prefer going to end
  3381. ;; of visible line if tags, or end of line, are farther.
  3382. (should-not
  3383. (org-test-with-temp-text "* A <point>long headline"
  3384. (visual-line-mode)
  3385. (dotimes (i 1000) (insert "very "))
  3386. (goto-char (point-min))
  3387. (org-end-of-line)
  3388. (eolp)))
  3389. (should-not
  3390. (org-test-with-temp-text "* A <point>long headline :tag:"
  3391. (visual-line-mode)
  3392. (dotimes (i 1000) (insert "very "))
  3393. (goto-char (point-min))
  3394. (org-end-of-line)
  3395. (eolp)))
  3396. ;; At an headline without special movement, go to end of line.
  3397. ;; However, never go past ellipsis.
  3398. (should
  3399. (org-test-with-temp-text "* Headline2b :tag:\n"
  3400. (let ((org-special-ctrl-a/e nil))
  3401. (and (progn (org-end-of-line) (eolp))
  3402. (progn (org-end-of-line) (eolp))))))
  3403. (should
  3404. (org-test-with-temp-text "* Headline2b :tag:\n"
  3405. (let ((org-special-ctrl-a/e '(t . nil)))
  3406. (and (progn (org-end-of-line) (eolp))
  3407. (progn (org-end-of-line) (eolp))))))
  3408. (should
  3409. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3410. (org-overview)
  3411. (let ((org-special-ctrl-a/e nil))
  3412. (org-end-of-line)
  3413. (= 1 (line-beginning-position)))))
  3414. ;; At an headline with special movement, first move before tags,
  3415. ;; then at the end of line, rinse, repeat. However, never go past
  3416. ;; ellipsis.
  3417. (should
  3418. (org-test-with-temp-text "* Headline1 :tag:\n"
  3419. (let ((org-special-ctrl-a/e t))
  3420. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3421. (progn (org-end-of-line) (eolp))
  3422. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3423. (should
  3424. (org-test-with-temp-text "* Headline1 :tag:\n"
  3425. (let ((org-special-ctrl-a/e '(nil . t)))
  3426. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3427. (progn (org-end-of-line) (eolp))
  3428. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3429. (should-not
  3430. (org-test-with-temp-text "* Headline1 :tag:\n"
  3431. (let ((org-special-ctrl-a/e '(nil . nil)))
  3432. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3433. (progn (org-end-of-line) (eolp))
  3434. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3435. (should
  3436. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3437. (org-overview)
  3438. (let ((org-special-ctrl-a/e t))
  3439. (org-end-of-line)
  3440. (org-end-of-line)
  3441. (= 1 (line-beginning-position)))))
  3442. ;; At an headline, with reversed movement, first go to end of line,
  3443. ;; then before tags. However, never go past ellipsis.
  3444. (should
  3445. (org-test-with-temp-text "* Headline3 :tag:\n"
  3446. (let ((org-special-ctrl-a/e 'reversed)
  3447. (this-command last-command))
  3448. (and (progn (org-end-of-line) (eolp))
  3449. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3450. (should
  3451. (org-test-with-temp-text "* Headline3 :tag:\n"
  3452. (let ((org-special-ctrl-a/e '(nil . reversed))
  3453. (this-command last-command))
  3454. (and (progn (org-end-of-line) (eolp))
  3455. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3456. (should-not
  3457. (org-test-with-temp-text "* Headline3 :tag:\n"
  3458. (let ((org-special-ctrl-a/e '(nil . t))
  3459. (this-command last-command))
  3460. (and (progn (org-end-of-line) (eolp))
  3461. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3462. (should
  3463. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3464. (org-overview)
  3465. (let ((org-special-ctrl-a/e 'reversed))
  3466. (org-end-of-line)
  3467. (= 1 (line-beginning-position)))))
  3468. ;; At a block without hidden contents.
  3469. (should
  3470. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3471. (progn (org-end-of-line) (eolp))))
  3472. ;; At a block with hidden contents.
  3473. (should-not
  3474. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3475. (let ((org-special-ctrl-a/e t))
  3476. (org-hide-block-toggle)
  3477. (org-end-of-line)
  3478. (eobp))))
  3479. ;; Get past invisible characters at the end of line.
  3480. (should
  3481. (org-test-with-temp-text "[[https://orgmode.org]]"
  3482. (org-end-of-line)
  3483. (eolp))))
  3484. (ert-deftest test-org/open-line ()
  3485. "Test `org-open-line' specifications."
  3486. ;; Call `open-line' outside of tables.
  3487. (should
  3488. (equal "\nText"
  3489. (org-test-with-temp-text "Text"
  3490. (org-open-line 1)
  3491. (buffer-string))))
  3492. ;; At a table, create a row above.
  3493. (should
  3494. (equal "\n| |\n| a |"
  3495. (org-test-with-temp-text "\n<point>| a |"
  3496. (org-open-line 1)
  3497. (buffer-string))))
  3498. ;; At the very first character of the buffer, also call `open-line'.
  3499. (should
  3500. (equal "\n| a |"
  3501. (org-test-with-temp-text "| a |"
  3502. (org-open-line 1)
  3503. (buffer-string))))
  3504. ;; Narrowing does not count.
  3505. (should
  3506. (equal "Text\n| |\n| a |"
  3507. (org-test-with-temp-text "Text\n<point>| a |"
  3508. (narrow-to-region (point) (point-max))
  3509. (org-open-line 1)
  3510. (widen)
  3511. (buffer-string)))))
  3512. (ert-deftest test-org/forward-sentence ()
  3513. "Test `org-forward-sentence' specifications."
  3514. ;; At the end of a table cell, move to the end of the next one.
  3515. (should
  3516. (org-test-with-temp-text "| a<point> | b |"
  3517. (org-forward-sentence)
  3518. (looking-at " |$")))
  3519. ;; Elsewhere in a cell, move to its end.
  3520. (should
  3521. (org-test-with-temp-text "| a<point>c | b |"
  3522. (org-forward-sentence)
  3523. (looking-at " | b |$")))
  3524. ;; Otherwise, simply call `forward-sentence'.
  3525. (should
  3526. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3527. (org-forward-sentence)
  3528. (looking-at " Sentence 2.")))
  3529. (should
  3530. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3531. (org-forward-sentence)
  3532. (org-forward-sentence)
  3533. (eobp)))
  3534. ;; At the end of an element, jump to the next one, without stopping
  3535. ;; on blank lines in-between.
  3536. (should
  3537. (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
  3538. (org-forward-sentence)
  3539. (eobp)))
  3540. ;; Headlines are considered to be sentences by themselves, even if
  3541. ;; they do not end with a full stop.
  3542. (should
  3543. (equal
  3544. "* Headline"
  3545. (org-test-with-temp-text "* <point>Headline\nSentence."
  3546. (org-forward-sentence)
  3547. (buffer-substring-no-properties (line-beginning-position) (point)))))
  3548. (should
  3549. (org-test-with-temp-text "* Headline<point>\nSentence."
  3550. (org-forward-sentence)
  3551. (eobp)))
  3552. (should
  3553. (org-test-with-temp-text "Sentence.<point>\n\n* Headline\n\nSentence 2."
  3554. (org-forward-sentence)
  3555. (and (org-at-heading-p) (eolp)))))
  3556. (ert-deftest test-org/backward-sentence ()
  3557. "Test `org-backward-sentence' specifications."
  3558. ;; At the beginning of a table cell, move to the beginning of the
  3559. ;; previous one.
  3560. (should
  3561. (org-test-with-temp-text "| a | <point>b |"
  3562. (org-backward-sentence)
  3563. (looking-at "a | b |$")))
  3564. ;; Elsewhere in a cell, move to its beginning.
  3565. (should
  3566. (org-test-with-temp-text "| a | b<point>c |"
  3567. (org-backward-sentence)
  3568. (looking-at "bc |$")))
  3569. ;; Otherwise, simply call `backward-sentence'.
  3570. (should
  3571. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3572. (org-backward-sentence)
  3573. (looking-at "Sentence 2.")))
  3574. (should
  3575. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3576. (org-backward-sentence)
  3577. (org-backward-sentence)
  3578. (bobp)))
  3579. ;; Make sure to hit the beginning of a sentence on the same line as
  3580. ;; an item.
  3581. (should
  3582. (org-test-with-temp-text "- Line 1\n line <point>2."
  3583. (org-backward-sentence)
  3584. (looking-at "Line 1"))))
  3585. (ert-deftest test-org/forward-paragraph ()
  3586. "Test `org-forward-paragraph' specifications."
  3587. ;; At end of buffer, do not return an error.
  3588. (should
  3589. (org-test-with-temp-text "Paragraph"
  3590. (goto-char (point-max))
  3591. (org-forward-paragraph)
  3592. t))
  3593. ;; Standard test.
  3594. (should
  3595. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  3596. (org-forward-paragraph)
  3597. (looking-at "P2")))
  3598. ;; Ignore depth.
  3599. (should
  3600. (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
  3601. (org-forward-paragraph)
  3602. (looking-at "P1")))
  3603. ;; Do not enter elements with invisible contents.
  3604. (should
  3605. (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
  3606. (org-hide-block-toggle)
  3607. (org-forward-paragraph)
  3608. (looking-at "P3")))
  3609. ;; On an affiliated keyword, jump to the beginning of the element.
  3610. (should
  3611. (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
  3612. (org-forward-paragraph)
  3613. (looking-at "Para")))
  3614. ;; On an item or a footnote definition, move to the second element
  3615. ;; inside, if any.
  3616. (should
  3617. (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
  3618. (org-forward-paragraph)
  3619. (looking-at " Paragraph")))
  3620. (should
  3621. (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
  3622. (org-forward-paragraph)
  3623. (looking-at "Paragraph")))
  3624. ;; On an item, or a footnote definition, when the first line is
  3625. ;; empty, move to the first item.
  3626. (should
  3627. (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
  3628. (org-forward-paragraph)
  3629. (looking-at " Paragraph")))
  3630. (should
  3631. (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
  3632. (org-forward-paragraph)
  3633. (looking-at "Paragraph")))
  3634. ;; On a table (resp. a property drawer) do not move through table
  3635. ;; rows (resp. node properties).
  3636. (should
  3637. (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
  3638. (org-forward-paragraph)
  3639. (looking-at "Paragraph")))
  3640. (should
  3641. (org-test-with-temp-text
  3642. "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
  3643. (org-forward-paragraph)
  3644. (looking-at "Paragraph")))
  3645. ;; On a verse or source block, stop after blank lines.
  3646. (should
  3647. (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
  3648. (org-forward-paragraph)
  3649. (looking-at "L2")))
  3650. (should
  3651. (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
  3652. (org-forward-paragraph)
  3653. (looking-at "L2"))))
  3654. (ert-deftest test-org/backward-paragraph ()
  3655. "Test `org-backward-paragraph' specifications."
  3656. ;; Do not error at beginning of buffer.
  3657. (should
  3658. (org-test-with-temp-text "Paragraph"
  3659. (org-backward-paragraph)
  3660. t))
  3661. ;; Regular test.
  3662. (should
  3663. (org-test-with-temp-text "P1\n\nP2\n\nP3<point>"
  3664. (org-backward-paragraph)
  3665. (looking-at "P3")))
  3666. (should
  3667. (org-test-with-temp-text "P1\n\nP2\n\n<point>P3"
  3668. (org-backward-paragraph)
  3669. (looking-at-p "P2")))
  3670. ;; Ignore depth.
  3671. (should
  3672. (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\n<point>P3"
  3673. (org-backward-paragraph)
  3674. (looking-at-p "P2")))
  3675. ;; Ignore invisible elements.
  3676. (should
  3677. (org-test-with-temp-text "* H1\n P1\n* H2"
  3678. (org-cycle)
  3679. (goto-char (point-max))
  3680. (beginning-of-line)
  3681. (org-backward-paragraph)
  3682. (bobp)))
  3683. ;; On an affiliated keyword, jump to the first one.
  3684. (should
  3685. (org-test-with-temp-text
  3686. "P1\n#+name: n\n#+caption: c1\n#+caption: <point>c2\nP2"
  3687. (org-backward-paragraph)
  3688. (looking-at-p "#\\+name")))
  3689. ;; On the second element in an item or a footnote definition, jump
  3690. ;; to item or the definition.
  3691. (should
  3692. (org-test-with-temp-text "- line1\n\n<point> line2"
  3693. (org-backward-paragraph)
  3694. (looking-at-p "- line1")))
  3695. (should
  3696. (org-test-with-temp-text "[fn:1] line1\n\n<point> line2"
  3697. (org-backward-paragraph)
  3698. (looking-at-p "\\[fn:1\\] line1")))
  3699. ;; On a table (resp. a property drawer), ignore table rows
  3700. ;; (resp. node properties).
  3701. (should
  3702. (org-test-with-temp-text "| a | b |\n| c | d |\n<point>P1"
  3703. (org-backward-paragraph)
  3704. (bobp)))
  3705. (should
  3706. (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
  3707. (org-backward-paragraph)
  3708. (looking-at-p ":PROPERTIES:")))
  3709. ;; On a comment, example, src and verse blocks, stop before blank
  3710. ;; lines.
  3711. (should
  3712. (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\n<point>L3\n#+END_VERSE"
  3713. (org-backward-paragraph)
  3714. (looking-at-p "L2")))
  3715. (should
  3716. (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\n<point>L3#+END_SRC"
  3717. (org-backward-paragraph)
  3718. (looking-at-p "L2")))
  3719. ;; In comment, example, export, src and verse blocks, stop below
  3720. ;; opening line when called from within the block.
  3721. (should
  3722. (org-test-with-temp-text "#+BEGIN_VERSE\nL1\nL2<point>\n#+END_VERSE"
  3723. (org-backward-paragraph)
  3724. (looking-at-p "L1")))
  3725. (should
  3726. (org-test-with-temp-text "#+BEGIN_EXAMPLE\nL1\nL2<point>\n#+END_EXAMPLE"
  3727. (org-backward-paragraph)
  3728. (looking-at-p "L1")))
  3729. ;; When called from the opening line itself, however, move to
  3730. ;; beginning of block.
  3731. (should
  3732. (org-test-with-temp-text "#+BEGIN_<point>EXAMPLE\nL1\n#+END_EXAMPLE"
  3733. (org-backward-paragraph)
  3734. (bobp)))
  3735. ;; Pathological case: on an empty heading, move to its beginning.
  3736. (should
  3737. (org-test-with-temp-text "* <point>H"
  3738. (org-backward-paragraph)
  3739. (bobp))))
  3740. (ert-deftest test-org/forward-element ()
  3741. "Test `org-forward-element' specifications."
  3742. ;; 1. At EOB: should error.
  3743. (org-test-with-temp-text "Some text\n"
  3744. (goto-char (point-max))
  3745. (should-error (org-forward-element)))
  3746. ;; 2. Standard move: expected to ignore blank lines.
  3747. (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
  3748. (org-forward-element)
  3749. (should (looking-at (regexp-quote "Second paragraph."))))
  3750. ;; 3. Headline tests.
  3751. (org-test-with-temp-text "
  3752. * Head 1
  3753. ** Head 1.1
  3754. *** Head 1.1.1
  3755. ** Head 1.2"
  3756. ;; 3.1. At an headline beginning: move to next headline at the
  3757. ;; same level.
  3758. (goto-line 3)
  3759. (org-forward-element)
  3760. (should (looking-at (regexp-quote "** Head 1.2")))
  3761. ;; 3.2. At an headline beginning: move to parent headline if no
  3762. ;; headline at the same level.
  3763. (goto-line 3)
  3764. (org-forward-element)
  3765. (should (looking-at (regexp-quote "** Head 1.2"))))
  3766. ;; 4. Greater element tests.
  3767. (org-test-with-temp-text
  3768. "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
  3769. ;; 4.1. At a greater element: expected to skip contents.
  3770. (org-forward-element)
  3771. (should (looking-at (regexp-quote "Outside.")))
  3772. ;; 4.2. At the end of greater element contents: expected to skip
  3773. ;; to the end of the greater element.
  3774. (goto-line 2)
  3775. (org-forward-element)
  3776. (should (looking-at (regexp-quote "Outside."))))
  3777. ;; 5. List tests.
  3778. (org-test-with-temp-text "
  3779. - item1
  3780. - sub1
  3781. - sub2
  3782. - sub3
  3783. Inner paragraph.
  3784. - item2
  3785. Outside."
  3786. ;; 5.1. At list top point: expected to move to the element after
  3787. ;; the list.
  3788. (goto-line 2)
  3789. (org-forward-element)
  3790. (should (looking-at (regexp-quote "Outside.")))
  3791. ;; 5.2. Special case: at the first line of a sub-list, but not at
  3792. ;; beginning of line, move to next item.
  3793. (goto-line 2)
  3794. (forward-char)
  3795. (org-forward-element)
  3796. (should (looking-at "- item2"))
  3797. (goto-line 4)
  3798. (forward-char)
  3799. (org-forward-element)
  3800. (should (looking-at " - sub2"))
  3801. ;; 5.3 At sub-list beginning: expected to move after the sub-list.
  3802. (goto-line 4)
  3803. (org-forward-element)
  3804. (should (looking-at (regexp-quote " Inner paragraph.")))
  3805. ;; 5.4. At sub-list end: expected to move outside the sub-list.
  3806. (goto-line 8)
  3807. (org-forward-element)
  3808. (should (looking-at (regexp-quote " Inner paragraph.")))
  3809. ;; 5.5. At an item: expected to move to next item, if any.
  3810. (goto-line 6)
  3811. (org-forward-element)
  3812. (should (looking-at " - sub3"))))
  3813. (ert-deftest test-org/backward-element ()
  3814. "Test `org-backward-element' specifications."
  3815. ;; 1. Should error at BOB.
  3816. (org-test-with-temp-text " \nParagraph."
  3817. (should-error (org-backward-element)))
  3818. ;; 2. Should move at BOB when called on the first element in buffer.
  3819. (should
  3820. (org-test-with-temp-text "\n#+TITLE: test"
  3821. (progn (forward-line)
  3822. (org-backward-element)
  3823. (bobp))))
  3824. ;; 3. Not at the beginning of an element: move at its beginning.
  3825. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  3826. (goto-line 3)
  3827. (end-of-line)
  3828. (org-backward-element)
  3829. (should (looking-at (regexp-quote "Paragraph2."))))
  3830. ;; 4. Headline tests.
  3831. (org-test-with-temp-text "
  3832. * Head 1
  3833. ** Head 1.1
  3834. *** Head 1.1.1
  3835. ** Head 1.2"
  3836. ;; 4.1. At an headline beginning: move to previous headline at the
  3837. ;; same level.
  3838. (goto-line 5)
  3839. (org-backward-element)
  3840. (should (looking-at (regexp-quote "** Head 1.1")))
  3841. ;; 4.2. At an headline beginning: move to parent headline if no
  3842. ;; headline at the same level.
  3843. (goto-line 3)
  3844. (org-backward-element)
  3845. (should (looking-at (regexp-quote "* Head 1")))
  3846. ;; 4.3. At the first top-level headline: should error.
  3847. (goto-line 2)
  3848. (should-error (org-backward-element)))
  3849. ;; 5. At beginning of first element inside a greater element:
  3850. ;; expected to move to greater element's beginning.
  3851. (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
  3852. (goto-line 3)
  3853. (org-backward-element)
  3854. (should (looking-at "#\\+BEGIN_CENTER")))
  3855. ;; 6. At the beginning of the first element in a section: should
  3856. ;; move back to headline, if any.
  3857. (should
  3858. (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
  3859. (progn (goto-char (point-max))
  3860. (beginning-of-line)
  3861. (org-backward-element)
  3862. (org-at-heading-p))))
  3863. ;; 7. List tests.
  3864. (org-test-with-temp-text "
  3865. - item1
  3866. - sub1
  3867. - sub2
  3868. - sub3
  3869. Inner paragraph.
  3870. - item2
  3871. Outside."
  3872. ;; 7.1. At beginning of sub-list: expected to move to the
  3873. ;; paragraph before it.
  3874. (goto-line 4)
  3875. (org-backward-element)
  3876. (should (looking-at "item1"))
  3877. ;; 7.2. At an item in a list: expected to move at previous item.
  3878. (goto-line 8)
  3879. (org-backward-element)
  3880. (should (looking-at " - sub2"))
  3881. (goto-line 12)
  3882. (org-backward-element)
  3883. (should (looking-at "- item1"))
  3884. ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
  3885. ;; beginning.
  3886. (goto-line 10)
  3887. (org-backward-element)
  3888. (should (looking-at " - sub1"))
  3889. (goto-line 15)
  3890. (org-backward-element)
  3891. (should (looking-at "- item1"))
  3892. ;; 7.4. At blank-lines before list end: expected to move to top
  3893. ;; item.
  3894. (goto-line 14)
  3895. (org-backward-element)
  3896. (should (looking-at "- item1"))))
  3897. (ert-deftest test-org/up-element ()
  3898. "Test `org-up-element' specifications."
  3899. ;; 1. At BOB or with no surrounding element: should error.
  3900. (org-test-with-temp-text "Paragraph."
  3901. (should-error (org-up-element)))
  3902. (org-test-with-temp-text "* Head1\n* Head2"
  3903. (goto-line 2)
  3904. (should-error (org-up-element)))
  3905. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  3906. (goto-line 3)
  3907. (should-error (org-up-element)))
  3908. ;; 2. At an headline: move to parent headline.
  3909. (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
  3910. (goto-line 3)
  3911. (org-up-element)
  3912. (should (looking-at "\\* Head1")))
  3913. ;; 3. Inside a greater element: move to greater element beginning.
  3914. (org-test-with-temp-text
  3915. "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
  3916. (goto-line 3)
  3917. (org-up-element)
  3918. (should (looking-at "#\\+BEGIN_CENTER")))
  3919. ;; 4. List tests.
  3920. (org-test-with-temp-text "* Top
  3921. - item1
  3922. - sub1
  3923. - sub2
  3924. Paragraph within sub2.
  3925. - item2"
  3926. ;; 4.1. Within an item: move to the item beginning.
  3927. (goto-line 8)
  3928. (org-up-element)
  3929. (should (looking-at " - sub2"))
  3930. ;; 4.2. At an item in a sub-list: move to parent item.
  3931. (goto-line 4)
  3932. (org-up-element)
  3933. (should (looking-at "- item1"))
  3934. ;; 4.3. At an item in top list: move to beginning of whole list.
  3935. (goto-line 10)
  3936. (org-up-element)
  3937. (should (looking-at "- item1"))
  3938. ;; 4.4. Special case. At very top point: should move to parent of
  3939. ;; list.
  3940. (goto-line 2)
  3941. (org-up-element)
  3942. (should (looking-at "\\* Top"))))
  3943. (ert-deftest test-org/down-element ()
  3944. "Test `org-down-element' specifications."
  3945. ;; Error when the element hasn't got a recursive type.
  3946. (org-test-with-temp-text "Paragraph."
  3947. (should-error (org-down-element)))
  3948. ;; Error when the element has no contents
  3949. (org-test-with-temp-text "* Headline"
  3950. (should-error (org-down-element)))
  3951. ;; When at a plain-list, move to first item.
  3952. (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
  3953. (goto-line 2)
  3954. (org-down-element)
  3955. (should (looking-at " - Item 1.1")))
  3956. (org-test-with-temp-text "#+NAME: list\n- Item 1"
  3957. (org-down-element)
  3958. (should (looking-at " Item 1")))
  3959. ;; When at a table, move to first row
  3960. (org-test-with-temp-text "#+NAME: table\n| a | b |"
  3961. (org-down-element)
  3962. (should (looking-at " a | b |")))
  3963. ;; Otherwise, move inside the greater element.
  3964. (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
  3965. (org-down-element)
  3966. (should (looking-at "Paragraph"))))
  3967. (ert-deftest test-org/drag-element-backward ()
  3968. "Test `org-drag-element-backward' specifications."
  3969. ;; Standard test.
  3970. (should
  3971. (equal
  3972. "#+key2: val2\n#+key1: val1\n#+key3: val3"
  3973. (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
  3974. (org-drag-element-backward)
  3975. (buffer-string))))
  3976. (should
  3977. (equal
  3978. "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
  3979. (org-test-with-temp-text
  3980. "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
  3981. (org-drag-element-backward)
  3982. (buffer-string))))
  3983. ;; Preserve blank lines.
  3984. (should
  3985. (equal "Paragraph 2\n\n\nPara1\n\nPara3"
  3986. (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
  3987. (org-drag-element-backward)
  3988. (buffer-string))))
  3989. ;; Preserve column.
  3990. (should
  3991. (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
  3992. (org-drag-element-backward)
  3993. (looking-at-p "2")))
  3994. ;; Error when trying to move first element of buffer.
  3995. (should-error
  3996. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  3997. (org-drag-element-backward))
  3998. :type 'user-error)
  3999. ;; Error when trying to swap nested elements.
  4000. (should-error
  4001. (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
  4002. (org-drag-element-backward))
  4003. :type 'user-error)
  4004. ;; Error when trying to swap an headline element and a non-headline
  4005. ;; element.
  4006. (should-error
  4007. (org-test-with-temp-text "Test.\n<point>* Head 1"
  4008. (org-drag-element-backward))
  4009. :type 'error)
  4010. ;; Error when called before first element.
  4011. (should-error
  4012. (org-test-with-temp-text "\n<point>"
  4013. (org-drag-element-backward))
  4014. :type 'user-error)
  4015. ;; Preserve visibility of elements and their contents.
  4016. (should
  4017. (equal '((63 . 82) (26 . 48))
  4018. (org-test-with-temp-text "
  4019. #+BEGIN_CENTER
  4020. Text.
  4021. #+END_CENTER
  4022. - item 1
  4023. #+BEGIN_QUOTE
  4024. Text.
  4025. #+END_QUOTE"
  4026. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4027. (search-backward "- item 1")
  4028. (org-drag-element-backward)
  4029. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4030. (overlays-in (point-min) (point-max))))))
  4031. ;; Pathological case: handle call with point in blank lines right
  4032. ;; after a headline.
  4033. (should
  4034. (equal "* H2\n\n* H1\nText\n"
  4035. (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
  4036. (org-drag-element-backward)
  4037. (buffer-string)))))
  4038. (ert-deftest test-org/drag-element-forward ()
  4039. "Test `org-drag-element-forward' specifications."
  4040. ;; 1. Error when trying to move first element of buffer.
  4041. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4042. (goto-line 3)
  4043. (should-error (org-drag-element-forward)))
  4044. ;; 2. Error when trying to swap nested elements.
  4045. (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
  4046. (forward-line)
  4047. (should-error (org-drag-element-forward)))
  4048. ;; 3. Error when trying to swap a non-headline element and an
  4049. ;; headline.
  4050. (org-test-with-temp-text "Test.\n* Head 1"
  4051. (should-error (org-drag-element-forward)))
  4052. ;; 4. Error when called before first element.
  4053. (should-error
  4054. (org-test-with-temp-text "\n"
  4055. (forward-line)
  4056. (org-drag-element-backward))
  4057. :type 'user-error)
  4058. ;; 5. Otherwise, swap elements, preserving column and blank lines
  4059. ;; between elements.
  4060. (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
  4061. (search-forward "graph")
  4062. (org-drag-element-forward)
  4063. (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
  4064. (should (looking-at " 1")))
  4065. ;; 5. Preserve visibility of elements and their contents.
  4066. (org-test-with-temp-text "
  4067. #+BEGIN_CENTER
  4068. Text.
  4069. #+END_CENTER
  4070. - item 1
  4071. #+BEGIN_QUOTE
  4072. Text.
  4073. #+END_QUOTE"
  4074. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4075. (search-backward "#+BEGIN_CENTER")
  4076. (org-drag-element-forward)
  4077. (should
  4078. (equal
  4079. '((63 . 82) (26 . 48))
  4080. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4081. (overlays-in (point-min) (point-max)))))))
  4082. (ert-deftest test-org/next-block ()
  4083. "Test `org-next-block' specifications."
  4084. ;; Regular test.
  4085. (should
  4086. (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  4087. (org-next-block 1)
  4088. (looking-at "#\\+BEGIN_CENTER")))
  4089. ;; Ignore case.
  4090. (should
  4091. (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
  4092. (let ((case-fold-search nil))
  4093. (org-next-block 1)
  4094. (looking-at "#\\+begin_center"))))
  4095. ;; Ignore current line.
  4096. (should
  4097. (org-test-with-temp-text
  4098. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
  4099. (org-next-block 1)
  4100. (looking-at "#\\+BEGIN_CENTER")))
  4101. ;; Throw an error when no block is found.
  4102. (should-error
  4103. (org-test-with-temp-text "Paragraph"
  4104. (org-next-block 1)))
  4105. ;; With an argument, skip many blocks at once.
  4106. (should
  4107. (org-test-with-temp-text
  4108. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4109. (org-next-block 2)
  4110. (looking-at "#\\+BEGIN_QUOTE")))
  4111. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4112. (should
  4113. (org-test-with-temp-text
  4114. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4115. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4116. (looking-at "#\\+BEGIN_QUOTE")))
  4117. ;; Optional argument is also case-insensitive.
  4118. (should
  4119. (org-test-with-temp-text
  4120. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
  4121. (let ((case-fold-search nil))
  4122. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4123. (looking-at "#\\+begin_quote")))))
  4124. (ert-deftest test-org/insert-structure-template ()
  4125. "Test `org-insert-structure-template'."
  4126. ;; Test in empty buffer.
  4127. (should
  4128. (string= "#+begin_foo\n#+end_foo\n"
  4129. (org-test-with-temp-text ""
  4130. (org-insert-structure-template "foo")
  4131. (buffer-string))))
  4132. ;; Test with multiple lines in buffer.
  4133. (should
  4134. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4135. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4136. (transient-mark-mode 1)
  4137. (org-mark-element)
  4138. (org-insert-structure-template "foo")
  4139. (buffer-string))))
  4140. ;; Mark only the current line.
  4141. (should
  4142. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4143. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4144. (transient-mark-mode 1)
  4145. (set-mark (point-min))
  4146. (end-of-line)
  4147. (org-insert-structure-template "foo")
  4148. (buffer-string))))
  4149. ;; Middle of paragraph.
  4150. (should
  4151. (string= "p1\n#+begin_foo\np2\n#+end_foo\np3"
  4152. (org-test-with-temp-text "p1\n<point>p2\np3"
  4153. (set-mark (line-beginning-position))
  4154. (end-of-line)
  4155. (activate-mark)
  4156. (org-insert-structure-template "foo")
  4157. (buffer-string))))
  4158. ;; Test with text in buffer, no region, no final newline.
  4159. (should
  4160. (string= "#+begin_foo\nI'm a paragraph.\n#+end_foo\n"
  4161. (org-test-with-temp-text "I'm a paragraph."
  4162. (org-mark-element)
  4163. (org-insert-structure-template "foo")
  4164. (buffer-string))))
  4165. ;; Test with text in buffer and region set.
  4166. (should
  4167. (string= "#+begin_foo\nI'm a paragraph\n\nI'm a second paragrah\n#+end_foo\n"
  4168. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragrah"
  4169. (set-mark (point))
  4170. (goto-char (point-max))
  4171. (org-insert-structure-template "foo")
  4172. (buffer-string))))
  4173. ;; Test with example escaping.
  4174. (should
  4175. (string= "#+begin_example\n,* Heading\n#+end_example\n"
  4176. (org-test-with-temp-text "* Heading"
  4177. (org-mark-element)
  4178. (org-insert-structure-template "example")
  4179. (buffer-string))))
  4180. ;; Test with indentation.
  4181. (should
  4182. (string= " #+begin_foo\n This is a paragraph\n #+end_foo\n"
  4183. (org-test-with-temp-text " This is a paragraph"
  4184. (org-mark-element)
  4185. (org-insert-structure-template "foo")
  4186. (buffer-string))))
  4187. (should
  4188. (string= " #+begin_foo\n Line 1\n Line2\n #+end_foo\n"
  4189. (org-test-with-temp-text " Line 1\n Line2"
  4190. (org-mark-element)
  4191. (org-insert-structure-template "foo")
  4192. (buffer-string))))
  4193. ;; Test point location.
  4194. (should
  4195. (string= "#+begin_foo\n"
  4196. (org-test-with-temp-text ""
  4197. (org-insert-structure-template "foo")
  4198. (buffer-substring (point-min) (point)))))
  4199. (should
  4200. (string= "#+begin_src "
  4201. (org-test-with-temp-text ""
  4202. (org-insert-structure-template "src")
  4203. (buffer-substring (point-min) (point))))))
  4204. (ert-deftest test-org/previous-block ()
  4205. "Test `org-previous-block' specifications."
  4206. ;; Regular test.
  4207. (should
  4208. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
  4209. (org-previous-block 1)
  4210. (looking-at "#\\+BEGIN_CENTER")))
  4211. ;; Ignore case.
  4212. (should
  4213. (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
  4214. (let ((case-fold-search nil))
  4215. (org-previous-block 1)
  4216. (looking-at "#\\+begin_center"))))
  4217. ;; Ignore current line.
  4218. (should
  4219. (org-test-with-temp-text
  4220. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
  4221. (org-previous-block 1)
  4222. (looking-at "#\\+BEGIN_QUOTE")))
  4223. ;; Throw an error when no block is found.
  4224. (should-error
  4225. (org-test-with-temp-text "Paragraph<point>"
  4226. (org-previous-block 1)))
  4227. ;; With an argument, skip many blocks at once.
  4228. (should
  4229. (org-test-with-temp-text
  4230. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4231. (org-previous-block 2)
  4232. (looking-at "#\\+BEGIN_CENTER")))
  4233. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4234. (should
  4235. (org-test-with-temp-text
  4236. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4237. (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4238. (looking-at "#\\+BEGIN_QUOTE")))
  4239. ;; Optional argument is also case-insensitive.
  4240. (should
  4241. (org-test-with-temp-text
  4242. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
  4243. (let ((case-fold-search nil))
  4244. (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4245. (looking-at "#\\+begin_quote")))))
  4246. ;;; Outline structure
  4247. (ert-deftest test-org/demote ()
  4248. "Test `org-demote' specifications."
  4249. ;; Add correct number of stars according to `org-odd-levels-only'.
  4250. (should
  4251. (= 2
  4252. (org-test-with-temp-text "* H"
  4253. (let ((org-odd-levels-only nil)) (org-demote))
  4254. (org-current-level))))
  4255. (should
  4256. (= 3
  4257. (org-test-with-temp-text "* H"
  4258. (let ((org-odd-levels-only t)) (org-demote))
  4259. (org-current-level))))
  4260. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4261. (should
  4262. (org-test-with-temp-text "* H :tag:"
  4263. (let ((org-tags-column 10)
  4264. (org-auto-align-tags t)
  4265. (org-odd-levels-only nil))
  4266. (org-demote))
  4267. (org-move-to-column 10)
  4268. (looking-at-p ":tag:$")))
  4269. (should-not
  4270. (org-test-with-temp-text "* H :tag:"
  4271. (let ((org-tags-column 10)
  4272. (org-auto-align-tags nil)
  4273. (org-odd-levels-only nil))
  4274. (org-demote))
  4275. (org-move-to-column 10)
  4276. (looking-at-p ":tag:$")))
  4277. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4278. ;; info and property drawers accordingly.
  4279. (should
  4280. (= 3
  4281. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4282. (let ((org-odd-levels-only nil)
  4283. (org-adapt-indentation t))
  4284. (org-demote))
  4285. (forward-line)
  4286. (org-get-indentation))))
  4287. (should
  4288. (= 3
  4289. (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4290. (let ((org-odd-levels-only nil)
  4291. (org-adapt-indentation t))
  4292. (org-demote))
  4293. (forward-line)
  4294. (org-get-indentation))))
  4295. (should-not
  4296. (= 3
  4297. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4298. (let ((org-odd-levels-only nil)
  4299. (org-adapt-indentation nil))
  4300. (org-demote))
  4301. (forward-line)
  4302. (org-get-indentation))))
  4303. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4304. ;; section accordingly. Ignore, however, footnote definitions and
  4305. ;; inlinetasks boundaries.
  4306. (should
  4307. (= 3
  4308. (org-test-with-temp-text "* H\n Paragraph"
  4309. (let ((org-odd-levels-only nil)
  4310. (org-adapt-indentation t))
  4311. (org-demote))
  4312. (forward-line)
  4313. (org-get-indentation))))
  4314. (should
  4315. (= 2
  4316. (org-test-with-temp-text "* H\n Paragraph"
  4317. (let ((org-odd-levels-only nil)
  4318. (org-adapt-indentation nil))
  4319. (org-demote))
  4320. (forward-line)
  4321. (org-get-indentation))))
  4322. (should
  4323. (zerop
  4324. (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
  4325. (let ((org-odd-levels-only nil)
  4326. (org-adapt-indentation t))
  4327. (org-demote))
  4328. (goto-char (point-max))
  4329. (org-get-indentation))))
  4330. (should
  4331. (= 3
  4332. (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
  4333. (let ((org-odd-levels-only nil)
  4334. (org-adapt-indentation t))
  4335. (org-demote))
  4336. (goto-char (point-max))
  4337. (org-get-indentation))))
  4338. (when (featurep 'org-inlinetask)
  4339. (should
  4340. (zerop
  4341. (let ((org-inlinetask-min-level 5)
  4342. (org-adapt-indentation t))
  4343. (org-test-with-temp-text "* H\n***** I\n***** END"
  4344. (org-demote)
  4345. (forward-line)
  4346. (org-get-indentation))))))
  4347. (when (featurep 'org-inlinetask)
  4348. (should
  4349. (= 3
  4350. (let ((org-inlinetask-min-level 5)
  4351. (org-adapt-indentation t))
  4352. (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
  4353. (org-demote)
  4354. (forward-line 2)
  4355. (org-get-indentation))))))
  4356. ;; Ignore contents of source blocks or example blocks when
  4357. ;; indentation should be preserved (through
  4358. ;; `org-src-preserve-indentation' or "-i" flag).
  4359. (should-not
  4360. (zerop
  4361. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4362. (let ((org-adapt-indentation t)
  4363. (org-src-preserve-indentation nil))
  4364. (org-demote))
  4365. (forward-line 2)
  4366. (org-get-indentation))))
  4367. (should
  4368. (zerop
  4369. (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
  4370. (let ((org-adapt-indentation t)
  4371. (org-src-preserve-indentation t))
  4372. (org-demote))
  4373. (forward-line 2)
  4374. (org-get-indentation))))
  4375. (should
  4376. (zerop
  4377. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4378. (let ((org-adapt-indentation t)
  4379. (org-src-preserve-indentation t))
  4380. (org-demote))
  4381. (forward-line 2)
  4382. (org-get-indentation))))
  4383. (should
  4384. (zerop
  4385. (org-test-with-temp-text
  4386. "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
  4387. (let ((org-adapt-indentation t)
  4388. (org-src-preserve-indentation nil))
  4389. (org-demote))
  4390. (forward-line 2)
  4391. (org-get-indentation)))))
  4392. (ert-deftest test-org/promote ()
  4393. "Test `org-promote' specifications."
  4394. ;; Return an error if headline is to be promoted to level 0, unless
  4395. ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
  4396. ;; headline becomes a comment.
  4397. (should-error
  4398. (org-test-with-temp-text "* H"
  4399. (let ((org-allow-promoting-top-level-subtree nil)) (org-promote))))
  4400. (should
  4401. (equal "# H"
  4402. (org-test-with-temp-text "* H"
  4403. (let ((org-allow-promoting-top-level-subtree t)) (org-promote))
  4404. (buffer-string))))
  4405. ;; Remove correct number of stars according to
  4406. ;; `org-odd-levels-only'.
  4407. (should
  4408. (= 2
  4409. (org-test-with-temp-text "*** H"
  4410. (let ((org-odd-levels-only nil)) (org-promote))
  4411. (org-current-level))))
  4412. (should
  4413. (= 1
  4414. (org-test-with-temp-text "*** H"
  4415. (let ((org-odd-levels-only t)) (org-promote))
  4416. (org-current-level))))
  4417. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4418. (should
  4419. (org-test-with-temp-text "** H :tag:"
  4420. (let ((org-tags-column 10)
  4421. (org-auto-align-tags t)
  4422. (org-odd-levels-only nil))
  4423. (org-promote))
  4424. (org-move-to-column 10)
  4425. (looking-at-p ":tag:$")))
  4426. (should-not
  4427. (org-test-with-temp-text "** H :tag:"
  4428. (let ((org-tags-column 10)
  4429. (org-auto-align-tags nil)
  4430. (org-odd-levels-only nil))
  4431. (org-promote))
  4432. (org-move-to-column 10)
  4433. (looking-at-p ":tag:$")))
  4434. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4435. ;; info and property drawers.
  4436. (should
  4437. (= 2
  4438. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4439. (let ((org-odd-levels-only nil)
  4440. (org-adapt-indentation t))
  4441. (org-promote))
  4442. (forward-line)
  4443. (org-get-indentation))))
  4444. (should
  4445. (= 2
  4446. (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4447. (let ((org-odd-levels-only nil)
  4448. (org-adapt-indentation t))
  4449. (org-promote))
  4450. (forward-line)
  4451. (org-get-indentation))))
  4452. (should-not
  4453. (= 2
  4454. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4455. (let ((org-odd-levels-only nil)
  4456. (org-adapt-indentation nil))
  4457. (org-promote))
  4458. (forward-line)
  4459. (org-get-indentation))))
  4460. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4461. ;; section accordingly. Ignore, however, footnote definitions and
  4462. ;; inlinetasks boundaries.
  4463. (should
  4464. (= 2
  4465. (org-test-with-temp-text "** H\n Paragraph"
  4466. (let ((org-odd-levels-only nil)
  4467. (org-adapt-indentation t))
  4468. (org-promote))
  4469. (forward-line)
  4470. (org-get-indentation))))
  4471. (should-not
  4472. (= 2
  4473. (org-test-with-temp-text "** H\n Paragraph"
  4474. (let ((org-odd-levels-only nil)
  4475. (org-adapt-indentation nil))
  4476. (org-promote))
  4477. (forward-line)
  4478. (org-get-indentation))))
  4479. (should
  4480. (= 2
  4481. (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
  4482. (let ((org-odd-levels-only nil)
  4483. (org-adapt-indentation t))
  4484. (org-promote))
  4485. (forward-line)
  4486. (org-get-indentation))))
  4487. (when (featurep 'org-inlinetask)
  4488. (should
  4489. (zerop
  4490. (let ((org-inlinetask-min-level 5)
  4491. (org-adapt-indentation t))
  4492. (org-test-with-temp-text "** H\n***** I\n***** END"
  4493. (org-promote)
  4494. (forward-line)
  4495. (org-get-indentation))))))
  4496. (when (featurep 'org-inlinetask)
  4497. (should
  4498. (= 2
  4499. (let ((org-inlinetask-min-level 5)
  4500. (org-adapt-indentation t))
  4501. (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
  4502. (org-promote)
  4503. (forward-line 2)
  4504. (org-get-indentation))))))
  4505. ;; Give up shifting if it would break document's structure
  4506. ;; otherwise.
  4507. (should
  4508. (= 3
  4509. (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
  4510. (let ((org-odd-levels-only nil)
  4511. (org-adapt-indentation t))
  4512. (org-promote))
  4513. (forward-line)
  4514. (org-get-indentation))))
  4515. (should
  4516. (= 3
  4517. (org-test-with-temp-text "** H\n Paragraph\n * list."
  4518. (let ((org-odd-levels-only nil)
  4519. (org-adapt-indentation t))
  4520. (org-promote))
  4521. (forward-line)
  4522. (org-get-indentation))))
  4523. ;; Ignore contents of source blocks or example blocks when
  4524. ;; indentation should be preserved (through
  4525. ;; `org-src-preserve-indentation' or "-i" flag).
  4526. (should-not
  4527. (zerop
  4528. (org-test-with-temp-text
  4529. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  4530. (let ((org-adapt-indentation t)
  4531. (org-src-preserve-indentation nil)
  4532. (org-odd-levels-only nil))
  4533. (org-promote))
  4534. (forward-line)
  4535. (org-get-indentation))))
  4536. (should
  4537. (zerop
  4538. (org-test-with-temp-text
  4539. "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
  4540. (let ((org-adapt-indentation t)
  4541. (org-src-preserve-indentation t)
  4542. (org-odd-levels-only nil))
  4543. (org-promote))
  4544. (forward-line)
  4545. (org-get-indentation))))
  4546. (should
  4547. (zerop
  4548. (org-test-with-temp-text
  4549. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  4550. (let ((org-adapt-indentation t)
  4551. (org-src-preserve-indentation t)
  4552. (org-odd-levels-only nil))
  4553. (org-promote))
  4554. (forward-line)
  4555. (org-get-indentation))))
  4556. (should
  4557. (zerop
  4558. (org-test-with-temp-text
  4559. "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
  4560. (let ((org-adapt-indentation t)
  4561. (org-src-preserve-indentation nil)
  4562. (org-odd-levels-only nil))
  4563. (org-promote))
  4564. (forward-line)
  4565. (org-get-indentation)))))
  4566. (ert-deftest test-org/org-get-valid-level ()
  4567. "Test function `org-get-valid-level' specifications."
  4568. (let ((org-odd-levels-only nil))
  4569. (should (equal 1 (org-get-valid-level 0 0)))
  4570. (should (equal 1 (org-get-valid-level 0 1)))
  4571. (should (equal 2 (org-get-valid-level 0 2)))
  4572. (should (equal 3 (org-get-valid-level 0 3)))
  4573. (should (equal 1 (org-get-valid-level 1 0)))
  4574. (should (equal 2 (org-get-valid-level 1 1)))
  4575. (should (equal 23 (org-get-valid-level 1 22)))
  4576. (should (equal 1 (org-get-valid-level 1 -1)))
  4577. (should (equal 1 (org-get-valid-level 2 -1))))
  4578. (let ((org-odd-levels-only t))
  4579. (should (equal 1 (org-get-valid-level 0 0)))
  4580. (should (equal 1 (org-get-valid-level 0 1)))
  4581. (should (equal 3 (org-get-valid-level 0 2)))
  4582. (should (equal 5 (org-get-valid-level 0 3)))
  4583. (should (equal 1 (org-get-valid-level 1 0)))
  4584. (should (equal 3 (org-get-valid-level 1 1)))
  4585. (should (equal 3 (org-get-valid-level 2 1)))
  4586. (should (equal 5 (org-get-valid-level 3 1)))
  4587. (should (equal 5 (org-get-valid-level 4 1)))
  4588. (should (equal 43 (org-get-valid-level 1 21)))
  4589. (should (equal 1 (org-get-valid-level 1 -1)))
  4590. (should (equal 1 (org-get-valid-level 2 -1)))
  4591. (should (equal 1 (org-get-valid-level 3 -1)))
  4592. (should (equal 3 (org-get-valid-level 4 -1)))
  4593. (should (equal 3 (org-get-valid-level 5 -1)))))
  4594. ;;; Planning
  4595. (ert-deftest test-org/at-planning-p ()
  4596. "Test `org-at-planning-p' specifications."
  4597. ;; Regular test.
  4598. (should
  4599. (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
  4600. (org-at-planning-p)))
  4601. (should-not
  4602. (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
  4603. (org-at-planning-p)))
  4604. ;; Correctly find planning attached to inlinetasks.
  4605. (when (featurep 'org-inlinetask)
  4606. (should
  4607. (org-test-with-temp-text
  4608. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
  4609. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4610. (should-not
  4611. (org-test-with-temp-text
  4612. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  4613. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4614. (should-not
  4615. (org-test-with-temp-text
  4616. "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  4617. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4618. (should-not
  4619. (org-test-with-temp-text
  4620. "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
  4621. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
  4622. (ert-deftest test-org/add-planning-info ()
  4623. "Test `org-add-planning-info'."
  4624. ;; Create deadline when `org-adapt-indentation' is non-nil.
  4625. (should
  4626. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4627. (org-test-with-temp-text "* H\nParagraph<point>"
  4628. (let ((org-adapt-indentation t))
  4629. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4630. (replace-regexp-in-string
  4631. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4632. nil nil 1))))
  4633. ;; Create deadline when `org-adapt-indentation' is nil.
  4634. (should
  4635. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  4636. (org-test-with-temp-text "* H\nParagraph<point>"
  4637. (let ((org-adapt-indentation nil))
  4638. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4639. (replace-regexp-in-string
  4640. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4641. nil nil 1))))
  4642. ;; Update deadline when `org-adapt-indentation' is non-nil.
  4643. (should
  4644. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4645. (org-test-with-temp-text "\
  4646. * H
  4647. DEADLINE: <2015-06-24 Wed>
  4648. Paragraph<point>"
  4649. (let ((org-adapt-indentation t))
  4650. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4651. (replace-regexp-in-string
  4652. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4653. nil nil 1))))
  4654. ;; Update deadline when `org-adapt-indentation' is nil.
  4655. (should
  4656. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  4657. (org-test-with-temp-text "\
  4658. * H
  4659. DEADLINE: <2015-06-24 Wed>
  4660. Paragraph<point>"
  4661. (let ((org-adapt-indentation nil))
  4662. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4663. (replace-regexp-in-string
  4664. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4665. nil nil 1))))
  4666. ;; Schedule when `org-adapt-indentation' is non-nil.
  4667. (should
  4668. (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
  4669. (org-test-with-temp-text "* H\nParagraph<point>"
  4670. (let ((org-adapt-indentation t))
  4671. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  4672. (replace-regexp-in-string
  4673. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4674. nil nil 1))))
  4675. ;; Schedule when `org-adapt-indentation' is nil.
  4676. (should
  4677. (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
  4678. (org-test-with-temp-text "* H\nParagraph<point>"
  4679. (let ((org-adapt-indentation nil))
  4680. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  4681. (replace-regexp-in-string
  4682. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4683. nil nil 1))))
  4684. ;; Add deadline when scheduled.
  4685. (should
  4686. (equal "\
  4687. * H
  4688. DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
  4689. Paragraph"
  4690. (org-test-with-temp-text "\
  4691. * H
  4692. SCHEDULED: <2015-06-24 Wed>
  4693. Paragraph<point>"
  4694. (let ((org-adapt-indentation t))
  4695. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4696. (replace-regexp-in-string
  4697. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4698. nil nil 1))))
  4699. ;; Remove middle entry.
  4700. (should
  4701. (equal "\
  4702. * H
  4703. CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
  4704. Paragraph"
  4705. (org-test-with-temp-text "\
  4706. * H
  4707. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  4708. Paragraph<point>"
  4709. (let ((org-adapt-indentation t))
  4710. (org-add-planning-info nil nil 'deadline))
  4711. (replace-regexp-in-string
  4712. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  4713. nil nil 1))))
  4714. ;; Remove last entry and then middle entry (order should not
  4715. ;; matter).
  4716. (should
  4717. (equal "\
  4718. * H
  4719. CLOSED: [2015-06-24]
  4720. Paragraph"
  4721. (org-test-with-temp-text "\
  4722. * H
  4723. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  4724. Paragraph<point>"
  4725. (let ((org-adapt-indentation t))
  4726. (org-add-planning-info nil nil 'scheduled 'deadline))
  4727. (replace-regexp-in-string
  4728. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  4729. nil nil 1))))
  4730. ;; Remove closed when `org-adapt-indentation' is non-nil.
  4731. (should
  4732. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4733. (org-test-with-temp-text "\
  4734. * H
  4735. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  4736. Paragraph<point>"
  4737. (let ((org-adapt-indentation t))
  4738. (org-add-planning-info nil nil 'closed))
  4739. (replace-regexp-in-string
  4740. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4741. nil nil 1))))
  4742. (should
  4743. (equal "* H\n Paragraph"
  4744. (org-test-with-temp-text "\
  4745. * H
  4746. CLOSED: [2015-06-25 Thu]
  4747. Paragraph<point>"
  4748. (let ((org-adapt-indentation t))
  4749. (org-add-planning-info nil nil 'closed))
  4750. (replace-regexp-in-string
  4751. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4752. nil nil 1))))
  4753. ;; Remove closed when `org-adapt-indentation' is nil.
  4754. (should
  4755. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  4756. (org-test-with-temp-text "\
  4757. * H
  4758. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  4759. Paragraph<point>"
  4760. (let ((org-adapt-indentation nil))
  4761. (org-add-planning-info nil nil 'closed))
  4762. (replace-regexp-in-string
  4763. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4764. nil nil 1))))
  4765. (should
  4766. (equal "* H\nParagraph"
  4767. (org-test-with-temp-text "\
  4768. * H
  4769. CLOSED: [2015-06-25 Thu]
  4770. Paragraph<point>"
  4771. (let ((org-adapt-indentation nil))
  4772. (org-add-planning-info nil nil 'closed))
  4773. (replace-regexp-in-string
  4774. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4775. nil nil 1))))
  4776. ;; Remove closed entry and delete empty line.
  4777. (should
  4778. (equal "\
  4779. * H
  4780. Paragraph"
  4781. (org-test-with-temp-text "\
  4782. * H
  4783. CLOSED: [2015-06-24 Wed]
  4784. Paragraph<point>"
  4785. (let ((org-adapt-indentation t))
  4786. (org-add-planning-info nil nil 'closed))
  4787. (replace-regexp-in-string
  4788. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4789. nil nil 1))))
  4790. ;; Remove one entry and update another.
  4791. (should
  4792. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4793. (org-test-with-temp-text "\
  4794. * H
  4795. SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
  4796. Paragraph<point>"
  4797. (let ((org-adapt-indentation t))
  4798. (org-add-planning-info 'deadline "<2015-06-25 Thu>" 'scheduled))
  4799. (replace-regexp-in-string
  4800. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4801. nil nil 1)))))
  4802. (ert-deftest test-org/deadline ()
  4803. "Test `org-deadline' specifications."
  4804. ;; Insert a new value or replace existing one.
  4805. (should
  4806. (equal "* H\nDEADLINE: <2012-03-29>"
  4807. (org-test-with-temp-text "* H"
  4808. (let ((org-adapt-indentation nil)
  4809. (org-last-inserted-timestamp nil))
  4810. (org-deadline nil "<2012-03-29 Tue>"))
  4811. (replace-regexp-in-string
  4812. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4813. nil nil 1))))
  4814. (should
  4815. (equal "* H\nDEADLINE: <2014-03-04>"
  4816. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  4817. (let ((org-adapt-indentation nil)
  4818. (org-last-inserted-timestamp nil))
  4819. (org-deadline nil "<2014-03-04 Thu>"))
  4820. (replace-regexp-in-string
  4821. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4822. nil nil 1))))
  4823. ;; Accept delta time, e.g., "+2d".
  4824. (should
  4825. (equal "* H\nDEADLINE: <2015-03-04>"
  4826. (org-test-at-time "2014-03-04"
  4827. (org-test-with-temp-text "* H"
  4828. (let ((org-adapt-indentation nil)
  4829. (org-last-inserted-timestamp nil))
  4830. (org-deadline nil "+1y"))
  4831. (replace-regexp-in-string
  4832. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  4833. ;; Preserve repeater.
  4834. (should
  4835. (equal "* H\nDEADLINE: <2012-03-29 +2y>"
  4836. (org-test-with-temp-text "* H"
  4837. (let ((org-adapt-indentation nil)
  4838. (org-last-inserted-timestamp nil))
  4839. (org-deadline nil "<2012-03-29 Tue +2y>"))
  4840. (replace-regexp-in-string
  4841. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  4842. ;; Remove CLOSED keyword, if any.
  4843. (should
  4844. (equal "* H\nDEADLINE: <2012-03-29>"
  4845. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  4846. (let ((org-adapt-indentation nil)
  4847. (org-last-inserted-timestamp nil))
  4848. (org-deadline nil "<2012-03-29 Tue>"))
  4849. (replace-regexp-in-string
  4850. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  4851. ;; With C-u argument, remove DEADLINE keyword.
  4852. (should
  4853. (equal "* H\n"
  4854. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  4855. (let ((org-adapt-indentation nil)
  4856. (org-last-inserted-timestamp nil))
  4857. (org-deadline '(4)))
  4858. (buffer-string))))
  4859. (should
  4860. (equal "* H"
  4861. (org-test-with-temp-text "* H"
  4862. (let ((org-adapt-indentation nil)
  4863. (org-last-inserted-timestamp nil))
  4864. (org-deadline '(4)))
  4865. (buffer-string))))
  4866. ;; With C-u C-u argument, prompt for a delay cookie.
  4867. (should
  4868. (equal "* H\nDEADLINE: <2012-03-29 -705d>"
  4869. (cl-letf (((symbol-function 'org-read-date)
  4870. (lambda (&rest args)
  4871. (apply #'encode-time
  4872. (org-parse-time-string "2014-03-04")))))
  4873. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  4874. (let ((org-adapt-indentation nil)
  4875. (org-last-inserted-timestamp nil))
  4876. (org-deadline '(16)))
  4877. (buffer-string)))))
  4878. (should-error
  4879. (cl-letf (((symbol-function 'org-read-date)
  4880. (lambda (&rest args)
  4881. (apply #'encode-time
  4882. (org-parse-time-string "2014-03-04")))))
  4883. (org-test-with-temp-text "* H"
  4884. (let ((org-adapt-indentation nil)
  4885. (org-last-inserted-timestamp nil))
  4886. (org-deadline '(16)))
  4887. (buffer-string))))
  4888. ;; When a region is active and
  4889. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  4890. ;; same value in all headlines in region.
  4891. (should
  4892. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  4893. (org-test-with-temp-text "* H1\n* H2"
  4894. (let ((org-adapt-indentation nil)
  4895. (org-last-inserted-timestamp nil)
  4896. (org-loop-over-headlines-in-active-region t))
  4897. (transient-mark-mode 1)
  4898. (push-mark (point) t t)
  4899. (goto-char (point-max))
  4900. (org-deadline nil "2012-03-29"))
  4901. (replace-regexp-in-string
  4902. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  4903. (should-not
  4904. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  4905. (org-test-with-temp-text "* H1\n* H2"
  4906. (let ((org-adapt-indentation nil)
  4907. (org-last-inserted-timestamp nil)
  4908. (org-loop-over-headlines-in-active-region nil))
  4909. (transient-mark-mode 1)
  4910. (push-mark (point) t t)
  4911. (goto-char (point-max))
  4912. (org-deadline nil "2012-03-29"))
  4913. (replace-regexp-in-string
  4914. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  4915. (ert-deftest test-org/schedule ()
  4916. "Test `org-schedule' specifications."
  4917. ;; Insert a new value or replace existing one.
  4918. (should
  4919. (equal "* H\nSCHEDULED: <2012-03-29>"
  4920. (org-test-with-temp-text "* H"
  4921. (let ((org-adapt-indentation nil)
  4922. (org-last-inserted-timestamp nil))
  4923. (org-schedule nil "<2012-03-29 Tue>"))
  4924. (replace-regexp-in-string
  4925. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4926. nil nil 1))))
  4927. (should
  4928. (equal "* H\nSCHEDULED: <2014-03-04>"
  4929. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  4930. (let ((org-adapt-indentation nil)
  4931. (org-last-inserted-timestamp nil))
  4932. (org-schedule nil "<2014-03-04 Thu>"))
  4933. (replace-regexp-in-string
  4934. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4935. nil nil 1))))
  4936. ;; Accept delta time, e.g., "+2d".
  4937. (should
  4938. (equal "* H\nSCHEDULED: <2015-03-04>"
  4939. (org-test-at-time "2014-03-04"
  4940. (org-test-with-temp-text "* H"
  4941. (let ((org-adapt-indentation nil)
  4942. (org-last-inserted-timestamp nil))
  4943. (org-schedule nil "+1y"))
  4944. (replace-regexp-in-string
  4945. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  4946. ;; Preserve repeater.
  4947. (should
  4948. (equal "* H\nSCHEDULED: <2012-03-29 +2y>"
  4949. (org-test-with-temp-text "* H"
  4950. (let ((org-adapt-indentation nil)
  4951. (org-last-inserted-timestamp nil))
  4952. (org-schedule nil "<2012-03-29 Tue +2y>"))
  4953. (replace-regexp-in-string
  4954. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  4955. ;; Remove CLOSED keyword, if any.
  4956. (should
  4957. (equal "* H\nSCHEDULED: <2012-03-29>"
  4958. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  4959. (let ((org-adapt-indentation nil)
  4960. (org-last-inserted-timestamp nil))
  4961. (org-schedule nil "<2012-03-29 Tue>"))
  4962. (replace-regexp-in-string
  4963. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  4964. ;; With C-u argument, remove SCHEDULED keyword.
  4965. (should
  4966. (equal "* H\n"
  4967. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  4968. (let ((org-adapt-indentation nil)
  4969. (org-last-inserted-timestamp nil))
  4970. (org-schedule '(4)))
  4971. (buffer-string))))
  4972. (should
  4973. (equal "* H"
  4974. (org-test-with-temp-text "* H"
  4975. (let ((org-adapt-indentation nil)
  4976. (org-last-inserted-timestamp nil))
  4977. (org-schedule '(4)))
  4978. (buffer-string))))
  4979. ;; With C-u C-u argument, prompt for a delay cookie.
  4980. (should
  4981. (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
  4982. (cl-letf (((symbol-function 'org-read-date)
  4983. (lambda (&rest args)
  4984. (apply #'encode-time
  4985. (org-parse-time-string "2014-03-04")))))
  4986. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  4987. (let ((org-adapt-indentation nil)
  4988. (org-last-inserted-timestamp nil))
  4989. (org-schedule '(16)))
  4990. (buffer-string)))))
  4991. (should-error
  4992. (cl-letf (((symbol-function 'org-read-date)
  4993. (lambda (&rest args)
  4994. (apply #'encode-time
  4995. (org-parse-time-string "2014-03-04")))))
  4996. (org-test-with-temp-text "* H"
  4997. (let ((org-adapt-indentation nil)
  4998. (org-last-inserted-timestamp nil))
  4999. (org-schedule '(16)))
  5000. (buffer-string))))
  5001. ;; When a region is active and
  5002. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5003. ;; same value in all headlines in region.
  5004. (should
  5005. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5006. (org-test-with-temp-text "* H1\n* H2"
  5007. (let ((org-adapt-indentation nil)
  5008. (org-last-inserted-timestamp nil)
  5009. (org-loop-over-headlines-in-active-region t))
  5010. (transient-mark-mode 1)
  5011. (push-mark (point) t t)
  5012. (goto-char (point-max))
  5013. (org-schedule nil "2012-03-29"))
  5014. (replace-regexp-in-string
  5015. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5016. (should-not
  5017. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5018. (org-test-with-temp-text "* H1\n* H2"
  5019. (let ((org-adapt-indentation nil)
  5020. (org-last-inserted-timestamp nil)
  5021. (org-loop-over-headlines-in-active-region nil))
  5022. (transient-mark-mode 1)
  5023. (push-mark (point) t t)
  5024. (goto-char (point-max))
  5025. (org-schedule nil "2012-03-29"))
  5026. (replace-regexp-in-string
  5027. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5028. (should
  5029. ;; check if a repeater survives re-scheduling.
  5030. (string-match-p
  5031. "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
  5032. (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
  5033. (let ((org-adapt-indentation nil)
  5034. (org-last-inserted-timestamp nil))
  5035. (org-schedule nil "2017-02-01"))
  5036. (buffer-string)))))
  5037. ;;; Property API
  5038. (ert-deftest test-org/buffer-property-keys ()
  5039. "Test `org-buffer-property-keys' specifications."
  5040. ;; Retrieve properties across siblings.
  5041. (should
  5042. (equal '("A" "B")
  5043. (org-test-with-temp-text "
  5044. * H1
  5045. :PROPERTIES:
  5046. :A: 1
  5047. :END:
  5048. * H2
  5049. :PROPERTIES:
  5050. :B: 1
  5051. :END:"
  5052. (org-buffer-property-keys))))
  5053. ;; Retrieve properties across children.
  5054. (should
  5055. (equal '("A" "B")
  5056. (org-test-with-temp-text "
  5057. * H1
  5058. :PROPERTIES:
  5059. :A: 1
  5060. :END:
  5061. ** H2
  5062. :PROPERTIES:
  5063. :B: 1
  5064. :END:"
  5065. (org-buffer-property-keys))))
  5066. ;; Retrieve muliple properties in the same drawer.
  5067. (should
  5068. (equal '("A" "B")
  5069. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5070. (org-buffer-property-keys))))
  5071. ;; Ignore extension symbol in property name.
  5072. (should
  5073. (equal '("A")
  5074. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5075. (org-buffer-property-keys))))
  5076. ;; With non-nil COLUMNS, extract property names from columns.
  5077. (should
  5078. (equal '("A" "B")
  5079. (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
  5080. (org-buffer-property-keys nil nil t))))
  5081. (should
  5082. (equal '("A" "B" "COLUMNS")
  5083. (org-test-with-temp-text
  5084. "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
  5085. (org-buffer-property-keys nil nil t))))
  5086. ;; In COLUMNS, ignore title and summary-type.
  5087. (should
  5088. (equal '("A")
  5089. (org-test-with-temp-text "#+COLUMNS: %A(Foo)"
  5090. (org-buffer-property-keys nil nil t))))
  5091. (should
  5092. (equal '("A")
  5093. (org-test-with-temp-text "#+COLUMNS: %A{Foo}"
  5094. (org-buffer-property-keys nil nil t))))
  5095. (should
  5096. (equal '("A")
  5097. (org-test-with-temp-text "#+COLUMNS: %A(Foo){Bar}"
  5098. (org-buffer-property-keys nil nil t)))))
  5099. (ert-deftest test-org/property-values ()
  5100. "Test `org-property-values' specifications."
  5101. ;; Regular test.
  5102. (should
  5103. (equal '("2" "1")
  5104. (org-test-with-temp-text
  5105. "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
  5106. (org-property-values "A"))))
  5107. ;; Ignore empty values.
  5108. (should-not
  5109. (org-test-with-temp-text
  5110. "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
  5111. (org-property-values "A")))
  5112. ;; Take into consideration extended values.
  5113. (should
  5114. (equal '("1 2")
  5115. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5116. (org-property-values "A")))))
  5117. (ert-deftest test-org/set-property ()
  5118. "Test `org-set-property' specifications."
  5119. (should
  5120. (equal
  5121. ":PROPERTIES:\n:TEST: t\n:END:\n"
  5122. (org-test-with-temp-text ""
  5123. (let ((org-property-format "%s %s"))
  5124. (org-set-property "TEST" "t"))
  5125. (buffer-string))))
  5126. (should
  5127. (equal
  5128. "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5129. (org-test-with-temp-text "* H"
  5130. (let ((org-adapt-indentation nil)
  5131. (org-property-format "%s %s"))
  5132. (org-set-property "TEST" "t"))
  5133. (buffer-string)))))
  5134. (ert-deftest test-org/delete-property ()
  5135. "Test `org-delete-property' specifications."
  5136. (should
  5137. (equal
  5138. ""
  5139. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5140. (org-delete-property "TEST")
  5141. (buffer-string))))
  5142. (should
  5143. (equal
  5144. ":PROPERTIES:\n:TEST1: t\n:END:\n"
  5145. (org-test-with-temp-text ":PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5146. (org-delete-property "TEST2")
  5147. (buffer-string))))
  5148. (should
  5149. (equal
  5150. "* H\n"
  5151. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5152. (org-delete-property "TEST")
  5153. (buffer-string))))
  5154. (should
  5155. (equal
  5156. "* H\n:PROPERTIES:\n:TEST1: t\n:END:\n"
  5157. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5158. (org-delete-property "TEST2")
  5159. (buffer-string)))))
  5160. (ert-deftest test-org/delete-property-globally ()
  5161. "Test `org-delete-property-global' specifications."
  5162. (should
  5163. (equal
  5164. ""
  5165. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5166. (org-delete-property-globally "TEST")
  5167. (buffer-string))))
  5168. (should
  5169. (equal
  5170. "* H\n"
  5171. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n* H\n:PROPERTIES:\n:TEST: nil\n:END:"
  5172. (org-delete-property-globally "TEST")
  5173. (buffer-string)))))
  5174. (ert-deftest test-org/find-property ()
  5175. "Test `org-find-property' specifications."
  5176. ;; Regular test.
  5177. (should
  5178. (= 1
  5179. (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
  5180. (org-find-property "prop"))))
  5181. ;; Find properties in top-level property drawer.
  5182. (should
  5183. (= 1
  5184. (org-test-with-temp-text ":PROPERTIES:\n:PROP: value\n:END:"
  5185. (org-find-property "prop"))))
  5186. ;; Ignore false positives.
  5187. (should
  5188. (= 27
  5189. (org-test-with-temp-text
  5190. "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
  5191. (org-find-property "A"))))
  5192. ;; Return first entry found in buffer.
  5193. (should
  5194. (= 1
  5195. (org-test-with-temp-text
  5196. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5197. (org-find-property "A"))))
  5198. ;; Only search visible part of the buffer.
  5199. (should
  5200. (= 31
  5201. (org-test-with-temp-text
  5202. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5203. (org-narrow-to-subtree)
  5204. (org-find-property "A"))))
  5205. ;; With optional argument, only find entries with a specific value.
  5206. (should-not
  5207. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5208. (org-find-property "A" "2")))
  5209. (should
  5210. (= 31
  5211. (org-test-with-temp-text
  5212. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
  5213. (org-find-property "A" "2"))))
  5214. ;; Use "nil" for explicit nil values.
  5215. (should
  5216. (= 31
  5217. (org-test-with-temp-text
  5218. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
  5219. (org-find-property "A" "nil")))))
  5220. (ert-deftest test-org/entry-delete ()
  5221. "Test `org-entry-delete' specifications."
  5222. ;; Regular test.
  5223. (should
  5224. (string-match
  5225. " *:PROPERTIES:\n *:B: +2\n *:END:"
  5226. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5227. (org-entry-delete (point) "A")
  5228. (buffer-string))))
  5229. ;; Also remove accumulated properties.
  5230. (should-not
  5231. (string-match
  5232. ":A"
  5233. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
  5234. (org-entry-delete (point) "A")
  5235. (buffer-string))))
  5236. ;; When last property is removed, remove the property drawer.
  5237. (should-not
  5238. (string-match
  5239. ":PROPERTIES:"
  5240. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
  5241. (org-entry-delete (point) "A")
  5242. (buffer-string))))
  5243. ;; Return a non-nil value when some property was removed.
  5244. (should
  5245. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5246. (org-entry-delete (point) "A")))
  5247. (should-not
  5248. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5249. (org-entry-delete (point) "C")))
  5250. ;; Special properties cannot be located in a drawer. Allow to
  5251. ;; remove them anyway, in case of user error.
  5252. (should
  5253. (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
  5254. (org-entry-delete (point) "SCHEDULED"))))
  5255. (ert-deftest test-org/entry-get ()
  5256. "Test `org-entry-get' specifications."
  5257. ;; Regular test.
  5258. (should
  5259. (equal "1"
  5260. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:"
  5261. (org-entry-get (point) "A"))))
  5262. (should
  5263. (equal "1"
  5264. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5265. (org-entry-get (point) "A"))))
  5266. ;; Ignore case.
  5267. (should
  5268. (equal "1"
  5269. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5270. (org-entry-get (point) "a"))))
  5271. ;; Handle extended values, both before and after base value.
  5272. (should
  5273. (equal "1 2 3"
  5274. (org-test-with-temp-text
  5275. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5276. (org-entry-get (point) "A"))))
  5277. ;; Empty values are returned as the empty string.
  5278. (should
  5279. (equal ""
  5280. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
  5281. (org-entry-get (point) "A"))))
  5282. ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
  5283. ;; otherwise, return nil.
  5284. (should-not
  5285. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5286. (org-entry-get (point) "A")))
  5287. (should
  5288. (equal "nil"
  5289. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5290. (org-entry-get (point) "A" nil t))))
  5291. ;; Return nil when no property is found, independently on the
  5292. ;; LITERAL-NIL argument.
  5293. (should-not
  5294. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5295. (org-entry-get (point) "B")))
  5296. (should-not
  5297. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5298. (org-entry-get (point) "B" nil t)))
  5299. ;; Handle inheritance, when allowed. Include extended values and
  5300. ;; possibly global values.
  5301. (should
  5302. (equal
  5303. "1"
  5304. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:\n* H"
  5305. (org-entry-get (point-max) "A" t))))
  5306. (should
  5307. (equal
  5308. "1"
  5309. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5310. (org-entry-get (point-max) "A" t))))
  5311. (should
  5312. (equal
  5313. "1"
  5314. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5315. (let ((org-use-property-inheritance t))
  5316. (org-entry-get (point-max) "A" 'selective)))))
  5317. (should-not
  5318. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5319. (let ((org-use-property-inheritance nil))
  5320. (org-entry-get (point-max) "A" 'selective))))
  5321. (should
  5322. (equal
  5323. "1 2"
  5324. (org-test-with-temp-text
  5325. ":PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5326. (org-entry-get (point-max) "A" t))))
  5327. (should
  5328. (equal
  5329. "1 2"
  5330. (org-test-with-temp-text
  5331. "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5332. (org-entry-get (point-max) "A" t))))
  5333. (should
  5334. (equal
  5335. "1 2"
  5336. (org-test-with-temp-text
  5337. ":PROPERTIES:\n:A: 1\n:END:\n* H1\n* H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5338. (org-entry-get (point-max) "A" t))))
  5339. (should
  5340. (equal
  5341. "1 2"
  5342. (org-test-with-temp-text
  5343. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2.1\n* H2.2\n:PROPERTIES:\n:A+: 2\n:END:"
  5344. (org-entry-get (point-max) "A" t))))
  5345. (should
  5346. (equal "1"
  5347. (org-test-with-temp-text
  5348. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
  5349. (org-mode-restart)
  5350. (org-entry-get (point-max) "A" t))))
  5351. (should
  5352. (equal "0 1"
  5353. (org-test-with-temp-text
  5354. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
  5355. (org-mode-restart)
  5356. (org-entry-get (point-max) "A" t))))
  5357. ;; document level property-drawer has precedance over
  5358. ;; global-property by PROPERTY-keyword.
  5359. (should
  5360. (equal "0 2"
  5361. (org-test-with-temp-text
  5362. ":PROPERTIES:\n:A: 0\n:END:\n#+PROPERTY: A 1\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5363. (org-mode-restart)
  5364. (org-entry-get (point-max) "A" t)))))
  5365. (ert-deftest test-org/entry-properties ()
  5366. "Test `org-entry-properties' specifications."
  5367. ;; Get "ITEM" property.
  5368. (should
  5369. (equal "H"
  5370. (org-test-with-temp-text "* TODO H"
  5371. (cdr (assoc "ITEM" (org-entry-properties nil "ITEM"))))))
  5372. (should
  5373. (equal "H"
  5374. (org-test-with-temp-text "* TODO H"
  5375. (cdr (assoc "ITEM" (org-entry-properties))))))
  5376. ;; Get "TODO" property. TODO keywords are case sensitive.
  5377. (should
  5378. (equal "TODO"
  5379. (org-test-with-temp-text "* TODO H"
  5380. (cdr (assoc "TODO" (org-entry-properties nil "TODO"))))))
  5381. (should
  5382. (equal "TODO"
  5383. (org-test-with-temp-text "* TODO H"
  5384. (cdr (assoc "TODO" (org-entry-properties))))))
  5385. (should-not
  5386. (org-test-with-temp-text "* H"
  5387. (assoc "TODO" (org-entry-properties nil "TODO"))))
  5388. (should-not
  5389. (org-test-with-temp-text "* todo H"
  5390. (assoc "TODO" (org-entry-properties nil "TODO"))))
  5391. ;; Get "PRIORITY" property.
  5392. (should
  5393. (equal "A"
  5394. (org-test-with-temp-text "* [#A] H"
  5395. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  5396. (should
  5397. (equal "A"
  5398. (org-test-with-temp-text "* [#A] H"
  5399. (cdr (assoc "PRIORITY" (org-entry-properties))))))
  5400. (should
  5401. (equal (char-to-string org-priority-default)
  5402. (org-test-with-temp-text "* H"
  5403. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  5404. ;; Get "FILE" property.
  5405. (should
  5406. (org-test-with-temp-text-in-file "* H\nParagraph"
  5407. (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil "FILE")))
  5408. (buffer-file-name))))
  5409. (should
  5410. (org-test-with-temp-text-in-file "* H\nParagraph"
  5411. (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
  5412. (buffer-file-name))))
  5413. (should-not
  5414. (org-test-with-temp-text "* H\nParagraph"
  5415. (cdr (assoc "FILE" (org-entry-properties nil "FILE")))))
  5416. ;; Get "TAGS" property.
  5417. (should
  5418. (equal ":tag1:tag2:"
  5419. (org-test-with-temp-text "* H :tag1:tag2:"
  5420. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS"))))))
  5421. (should
  5422. (equal ":tag1:tag2:"
  5423. (org-test-with-temp-text "* H :tag1:tag2:"
  5424. (cdr (assoc "TAGS" (org-entry-properties))))))
  5425. (should-not
  5426. (org-test-with-temp-text "* H"
  5427. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS")))))
  5428. ;; Get "ALLTAGS" property.
  5429. (should
  5430. (equal ":tag1:tag2:"
  5431. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  5432. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS"))))))
  5433. (should
  5434. (equal ":tag1:tag2:"
  5435. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  5436. (cdr (assoc "ALLTAGS" (org-entry-properties))))))
  5437. (should-not
  5438. (org-test-with-temp-text "* H"
  5439. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS")))))
  5440. ;; Get "BLOCKED" property.
  5441. (should
  5442. (equal "t"
  5443. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  5444. (let ((org-enforce-todo-dependencies t)
  5445. (org-blocker-hook
  5446. '(org-block-todo-from-children-or-siblings-or-parent)))
  5447. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  5448. (should
  5449. (equal ""
  5450. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  5451. (let ((org-enforce-todo-dependencies t)
  5452. (org-blocker-hook
  5453. '(org-block-todo-from-children-or-siblings-or-parent)))
  5454. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  5455. ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
  5456. (should
  5457. (equal
  5458. "[2012-03-29 thu.]"
  5459. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  5460. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED"))))))
  5461. (should
  5462. (equal
  5463. "[2012-03-29 thu.]"
  5464. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  5465. (cdr (assoc "CLOSED" (org-entry-properties))))))
  5466. (should-not
  5467. (org-test-with-temp-text "* H"
  5468. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED")))))
  5469. (should
  5470. (equal
  5471. "<2014-03-04 tue.>"
  5472. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5473. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE"))))))
  5474. (should
  5475. (equal
  5476. "<2014-03-04 tue.>"
  5477. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5478. (cdr (assoc "DEADLINE" (org-entry-properties))))))
  5479. (should-not
  5480. (org-test-with-temp-text "* H"
  5481. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE")))))
  5482. (should
  5483. (equal
  5484. "<2014-03-04 tue.>"
  5485. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5486. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED"))))))
  5487. (should
  5488. (equal
  5489. "<2014-03-04 tue.>"
  5490. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5491. (cdr (assoc "SCHEDULED" (org-entry-properties))))))
  5492. (should-not
  5493. (org-test-with-temp-text "* H"
  5494. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED")))))
  5495. ;; Get "CATEGORY"
  5496. (should
  5497. (equal "cat"
  5498. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  5499. (cdr (assoc "CATEGORY" (org-entry-properties))))))
  5500. (should
  5501. (equal "cat"
  5502. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  5503. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5504. (should
  5505. (equal "cat"
  5506. (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
  5507. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5508. (should
  5509. (equal "cat2"
  5510. (org-test-with-temp-text
  5511. (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  5512. "\n"
  5513. "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
  5514. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5515. ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
  5516. (should
  5517. (equal "<2012-03-29 thu.>"
  5518. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
  5519. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  5520. (should
  5521. (equal "[2012-03-29 thu.]"
  5522. (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
  5523. (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
  5524. (should
  5525. (equal "<2012-03-29 thu.>"
  5526. (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
  5527. (cdr (assoc "TIMESTAMP" (org-entry-properties nil "TIMESTAMP"))))))
  5528. (should
  5529. (equal "[2014-03-04 tue.]"
  5530. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
  5531. (cdr (assoc "TIMESTAMP_IA"
  5532. (org-entry-properties nil "TIMESTAMP_IA"))))))
  5533. (should-not
  5534. (equal "<2012-03-29 thu.>"
  5535. (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
  5536. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  5537. ;; Get standard properties.
  5538. (should
  5539. (equal "1"
  5540. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5541. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5542. ;; Handle extended properties.
  5543. (should
  5544. (equal "1 2 3"
  5545. (org-test-with-temp-text
  5546. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5547. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5548. (should
  5549. (equal "1 2 3"
  5550. (org-test-with-temp-text
  5551. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
  5552. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5553. ;; Ignore forbidden (special) properties.
  5554. (should-not
  5555. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
  5556. (cdr (assoc "TODO" (org-entry-properties nil 'standard))))))
  5557. (ert-deftest test-org/entry-put ()
  5558. "Test `org-entry-put' specifications."
  5559. ;; Error when not a string or nil.
  5560. (should-error
  5561. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5562. (org-entry-put 1 "test" 2)))
  5563. ;; Error when property name is invalid.
  5564. (should-error
  5565. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5566. (org-entry-put 1 "no space" "value")))
  5567. (should-error
  5568. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5569. (org-entry-put 1 "" "value")))
  5570. ;; Set "TODO" property.
  5571. (should
  5572. (string-match (regexp-quote " TODO H")
  5573. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  5574. (org-entry-put (point) "TODO" "TODO")
  5575. (buffer-string))))
  5576. (should
  5577. (string-match (regexp-quote "* H")
  5578. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  5579. (org-entry-put (point) "TODO" nil)
  5580. (buffer-string))))
  5581. ;; Set "PRIORITY" property.
  5582. (should
  5583. (equal "* [#A] H"
  5584. (org-test-with-temp-text "* [#B] H"
  5585. (org-entry-put (point) "PRIORITY" "A")
  5586. (buffer-string))))
  5587. (should
  5588. (equal "* H"
  5589. (org-test-with-temp-text "* [#B] H"
  5590. (org-entry-put (point) "PRIORITY" nil)
  5591. (buffer-string))))
  5592. ;; Set "SCHEDULED" property.
  5593. (should
  5594. (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
  5595. (org-test-with-temp-text "* H"
  5596. (org-entry-put (point) "SCHEDULED" "2014-03-04")
  5597. (buffer-string))))
  5598. (should
  5599. (string= "* H\n"
  5600. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5601. (org-entry-put (point) "SCHEDULED" nil)
  5602. (buffer-string))))
  5603. (should
  5604. (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
  5605. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5606. (org-entry-put (point) "SCHEDULED" "earlier")
  5607. (buffer-string))))
  5608. (should
  5609. (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
  5610. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5611. (org-entry-put (point) "SCHEDULED" "later")
  5612. (buffer-string))))
  5613. ;; Set "DEADLINE" property.
  5614. (should
  5615. (string-match "^ *DEADLINE: <2014-03-04 .*?>"
  5616. (org-test-with-temp-text "* H"
  5617. (org-entry-put (point) "DEADLINE" "2014-03-04")
  5618. (buffer-string))))
  5619. (should
  5620. (string= "* H\n"
  5621. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5622. (org-entry-put (point) "DEADLINE" nil)
  5623. (buffer-string))))
  5624. (should
  5625. (string-match "^ *DEADLINE: <2014-03-03 .*?>"
  5626. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5627. (org-entry-put (point) "DEADLINE" "earlier")
  5628. (buffer-string))))
  5629. (should
  5630. (string-match "^ *DEADLINE: <2014-03-05 .*?>"
  5631. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5632. (org-entry-put (point) "DEADLINE" "later")
  5633. (buffer-string))))
  5634. ;; Set "CATEGORY" property
  5635. (should
  5636. (string-match "^ *:CATEGORY: cat"
  5637. (org-test-with-temp-text "* H"
  5638. (org-entry-put (point) "CATEGORY" "cat")
  5639. (buffer-string))))
  5640. ;; Regular properties, with or without pre-existing drawer.
  5641. (should
  5642. (string-match "^ *:A: +2$"
  5643. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5644. (org-entry-put (point) "A" "2")
  5645. (buffer-string))))
  5646. (should
  5647. (string-match "^ *:A: +1$"
  5648. (org-test-with-temp-text "* H"
  5649. (org-entry-put (point) "A" "1")
  5650. (buffer-string))))
  5651. ;; Special case: two consecutive headlines.
  5652. (should
  5653. (string-match "\\* A\n *:PROPERTIES:"
  5654. (org-test-with-temp-text "* A\n** B"
  5655. (org-entry-put (point) "A" "1")
  5656. (buffer-string)))))
  5657. (ert-deftest test-org/refresh-properties ()
  5658. "Test `org-refresh-properties' specifications."
  5659. (should
  5660. (equal "1"
  5661. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5662. (org-refresh-properties "A" 'org-test)
  5663. (get-text-property (point) 'org-test))))
  5664. (should-not
  5665. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5666. (org-refresh-properties "B" 'org-test)
  5667. (get-text-property (point) 'org-test)))
  5668. ;; Handle properties only defined with extension syntax, i.e.,
  5669. ;; "PROPERTY+".
  5670. (should
  5671. (equal "1"
  5672. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
  5673. (org-refresh-properties "A" 'org-test)
  5674. (get-text-property (point) 'org-test))))
  5675. ;; When property is inherited, add text property to the whole
  5676. ;; sub-tree.
  5677. (should
  5678. (equal "1"
  5679. (org-test-with-temp-text
  5680. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
  5681. (let ((org-use-property-inheritance t))
  5682. (org-refresh-properties "A" 'org-test))
  5683. (get-text-property (point) 'org-test))))
  5684. ;; When a document level property-drawer is used, those properties
  5685. ;; should work exactly like headline-properties as if at a
  5686. ;; headline-level 0.
  5687. (should
  5688. (equal "1"
  5689. (org-test-with-temp-text
  5690. ":PROPERTIES:\n:A: 1\n:END:\n"
  5691. (org-mode-restart)
  5692. (let ((org-use-property-inheritance t))
  5693. (org-refresh-properties "A" 'org-test))
  5694. (get-text-property (point) 'org-test))))
  5695. (should-not
  5696. (equal "1"
  5697. (org-test-with-temp-text
  5698. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  5699. (org-mode-restart)
  5700. (let ((org-use-property-inheritance nil))
  5701. (org-refresh-properties "A" 'org-test))
  5702. (get-text-property (point) 'org-test))))
  5703. (should
  5704. (equal "1"
  5705. (org-test-with-temp-text
  5706. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  5707. (org-mode-restart)
  5708. (let ((org-use-property-inheritance t))
  5709. (org-refresh-properties "A" 'org-test))
  5710. (get-text-property (point) 'org-test))))
  5711. (should
  5712. (equal "2"
  5713. (org-test-with-temp-text
  5714. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1\n:PROPERTIES:\n:A: 2\n:END:"
  5715. (org-mode-restart)
  5716. (let ((org-use-property-inheritance t))
  5717. (org-refresh-properties "A" 'org-test))
  5718. (get-text-property (point) 'org-test))))
  5719. ;; When property is inherited, use global value across the whole
  5720. ;; buffer. However local values have precedence, as well as the
  5721. ;; document level property-drawer.
  5722. (should-not
  5723. (equal "1"
  5724. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  5725. (org-mode-restart)
  5726. (let ((org-use-property-inheritance nil))
  5727. (org-refresh-properties "A" 'org-test))
  5728. (get-text-property (point) 'org-test))))
  5729. (should
  5730. (equal "1"
  5731. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  5732. (org-mode-restart)
  5733. (let ((org-use-property-inheritance t))
  5734. (org-refresh-properties "A" 'org-test))
  5735. (get-text-property (point) 'org-test))))
  5736. (should
  5737. (equal "2"
  5738. (org-test-with-temp-text
  5739. "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
  5740. (org-mode-restart)
  5741. (let ((org-use-property-inheritance t))
  5742. (org-refresh-properties "A" 'org-test))
  5743. (get-text-property (point) 'org-test))))
  5744. ;; When both keyword-property and document-level property-block is
  5745. ;; defined, the property-block has precedance.
  5746. (should
  5747. (equal "1"
  5748. (org-test-with-temp-text
  5749. ":PROPERTIES:\n:A: 1\n:END:\n#+PROPERTY: A 2\n<point>* H1"
  5750. (org-mode-restart)
  5751. (let ((org-use-property-inheritance t))
  5752. (org-refresh-properties "A" 'org-test))
  5753. (get-text-property (point) 'org-test)))))
  5754. (ert-deftest test-org/refresh-category-properties ()
  5755. "Test `org-refresh-category-properties' specifications"
  5756. (should
  5757. (equal "cat1"
  5758. (org-test-with-temp-text
  5759. ":PROPERTIES:\n:CATEGORY: cat1\n:END:"
  5760. (org-refresh-category-properties)
  5761. (get-text-property (point) 'org-category))))
  5762. (should
  5763. (equal "cat1"
  5764. (org-test-with-temp-text
  5765. "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  5766. (org-refresh-category-properties)
  5767. (get-text-property (point) 'org-category))))
  5768. ;; Even though property-inheritance is deactivated, category
  5769. ;; property should be inherited. As described in
  5770. ;; `org-use-property-inheritance'.
  5771. (should
  5772. (equal "cat1"
  5773. (org-test-with-temp-text
  5774. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  5775. (org-mode-restart)
  5776. (let ((org-use-property-inheritance nil))
  5777. (org-refresh-category-properties))
  5778. (get-text-property (point) 'org-category))))
  5779. (should
  5780. (equal "cat1"
  5781. (org-test-with-temp-text
  5782. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  5783. (org-mode-restart)
  5784. (let ((org-use-property-inheritance t))
  5785. (org-refresh-category-properties))
  5786. (get-text-property (point) 'org-category))))
  5787. (should
  5788. (equal "cat2"
  5789. (org-test-with-temp-text
  5790. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H\n:PROPERTIES:\n:CATEGORY: cat2\n:END:\n"
  5791. (org-mode-restart)
  5792. (let ((org-use-property-inheritance t))
  5793. (org-refresh-category-properties))
  5794. (get-text-property (point) 'org-category)))))
  5795. ;;; Refile
  5796. (ert-deftest test-org/refile-get-targets ()
  5797. "Test `org-refile-get-targets' specifications."
  5798. ;; :maxlevel includes all headings above specified value.
  5799. (should
  5800. (equal '("H1" "H2" "H3")
  5801. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  5802. (let ((org-refile-use-outline-path nil)
  5803. (org-refile-targets `((nil :maxlevel . 3))))
  5804. (mapcar #'car (org-refile-get-targets))))))
  5805. (should
  5806. (equal '("H1" "H2")
  5807. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  5808. (let ((org-refile-use-outline-path nil)
  5809. (org-refile-targets `((nil :maxlevel . 2))))
  5810. (mapcar #'car (org-refile-get-targets))))))
  5811. ;; :level limits targets to headlines with the specified level.
  5812. (should
  5813. (equal '("H2")
  5814. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  5815. (let ((org-refile-use-outline-path nil)
  5816. (org-refile-targets `((nil :level . 2))))
  5817. (mapcar #'car (org-refile-get-targets))))))
  5818. ;; :tag limits targets to headlines with specified tag.
  5819. (should
  5820. (equal '("H1")
  5821. (org-test-with-temp-text "* H1 :foo:\n** H2\n*** H3 :bar:"
  5822. (let ((org-refile-use-outline-path nil)
  5823. (org-refile-targets `((nil :tag . "foo"))))
  5824. (mapcar #'car (org-refile-get-targets))))))
  5825. ;; :todo limits targets to headlines with specified TODO keyword.
  5826. (should
  5827. (equal '("H2")
  5828. (org-test-with-temp-text "* H1\n** TODO H2\n*** DONE H3"
  5829. (let ((org-refile-use-outline-path nil)
  5830. (org-refile-targets `((nil :todo . "TODO"))))
  5831. (mapcar #'car (org-refile-get-targets))))))
  5832. ;; :regexp filters targets matching provided regexp.
  5833. (should
  5834. (equal '("F2" "F3")
  5835. (org-test-with-temp-text "* H1\n** F2\n*** F3"
  5836. (let ((org-refile-use-outline-path nil)
  5837. (org-refile-targets `((nil :regexp . "F"))))
  5838. (mapcar #'car (org-refile-get-targets))))))
  5839. ;; A nil `org-refile-targets' includes only top level headlines in
  5840. ;; current buffer.
  5841. (should
  5842. (equal '("H1" "H2")
  5843. (org-test-with-temp-text "* H1\n** S1\n* H2"
  5844. (let ((org-refile-use-outline-path nil)
  5845. (org-refile-targets nil))
  5846. (mapcar #'car (org-refile-get-targets))))))
  5847. ;; Return value is the union of the targets according to all the
  5848. ;; defined rules. However, prevent duplicates.
  5849. (should
  5850. (equal '("F2" "F3" "H1")
  5851. (org-test-with-temp-text "* TODO H1\n** F2\n*** F3"
  5852. (let ((org-refile-use-outline-path nil)
  5853. (org-refile-targets `((nil :regexp . "F")
  5854. (nil :todo . "TODO"))))
  5855. (mapcar #'car (org-refile-get-targets))))))
  5856. (should
  5857. (equal '("F2" "F3" "H1")
  5858. (org-test-with-temp-text "* TODO H1\n** TODO F2\n*** F3"
  5859. (let ((org-refile-use-outline-path nil)
  5860. (org-refile-targets `((nil :regexp . "F")
  5861. (nil :todo . "TODO"))))
  5862. (mapcar #'car (org-refile-get-targets))))))
  5863. ;; When `org-refile-use-outline-path' is non-nil, provide targets as
  5864. ;; paths.
  5865. (should
  5866. (equal '("H1" "H1/H2" "H1/H2/H3")
  5867. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  5868. (let ((org-refile-use-outline-path t)
  5869. (org-refile-targets `((nil :maxlevel . 3))))
  5870. (mapcar #'car (org-refile-get-targets))))))
  5871. ;; When providing targets as paths, escape forward slashes in
  5872. ;; headings with backslashes.
  5873. (should
  5874. (equal '("H1\\/foo")
  5875. (org-test-with-temp-text "* H1/foo"
  5876. (let ((org-refile-use-outline-path t)
  5877. (org-refile-targets `((nil :maxlevel . 1))))
  5878. (mapcar #'car (org-refile-get-targets))))))
  5879. ;; When `org-refile-use-outline-path' is `file', include file name
  5880. ;; without directory in targets.
  5881. (should
  5882. (org-test-with-temp-text-in-file "* H1"
  5883. (let* ((filename (buffer-file-name))
  5884. (org-refile-use-outline-path 'file)
  5885. (org-refile-targets `(((,filename) :level . 1))))
  5886. (member (file-name-nondirectory filename)
  5887. (mapcar #'car (org-refile-get-targets))))))
  5888. ;; When `org-refile-use-outline-path' is `full-file-path', include
  5889. ;; full file name.
  5890. (should
  5891. (org-test-with-temp-text-in-file "* H1"
  5892. (let* ((filename (file-truename (buffer-file-name)))
  5893. (org-refile-use-outline-path 'full-file-path)
  5894. (org-refile-targets `(((,filename) :level . 1))))
  5895. (member filename (mapcar #'car (org-refile-get-targets))))))
  5896. ;; When `org-refile-use-outline-path' is `buffer-name', include
  5897. ;; buffer name.
  5898. (should
  5899. (org-test-with-temp-text "* H1"
  5900. (let* ((org-refile-use-outline-path 'buffer-name)
  5901. (org-refile-targets `((nil :level . 1))))
  5902. (member (buffer-name) (mapcar #'car (org-refile-get-targets)))))))
  5903. ;;; Sparse trees
  5904. (ert-deftest test-org/match-sparse-tree ()
  5905. "Test `org-match-sparse-tree' specifications."
  5906. ;; Match tags.
  5907. (should-not
  5908. (org-test-with-temp-text "* H\n** H1 :tag:"
  5909. (org-match-sparse-tree nil "tag")
  5910. (search-forward "H1")
  5911. (org-invisible-p2)))
  5912. (should
  5913. (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
  5914. (org-match-sparse-tree nil "tag")
  5915. (search-forward "H2")
  5916. (org-invisible-p2)))
  5917. ;; "-" operator for tags.
  5918. (should-not
  5919. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  5920. (org-match-sparse-tree nil "tag1-tag2")
  5921. (search-forward "H1")
  5922. (org-invisible-p2)))
  5923. (should
  5924. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  5925. (org-match-sparse-tree nil "tag1-tag2")
  5926. (search-forward "H2")
  5927. (org-invisible-p2)))
  5928. ;; "&" operator for tags.
  5929. (should
  5930. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  5931. (org-match-sparse-tree nil "tag1&tag2")
  5932. (search-forward "H1")
  5933. (org-invisible-p2)))
  5934. (should-not
  5935. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  5936. (org-match-sparse-tree nil "tag1&tag2")
  5937. (search-forward "H2")
  5938. (org-invisible-p2)))
  5939. ;; "|" operator for tags.
  5940. (should-not
  5941. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  5942. (org-match-sparse-tree nil "tag1|tag2")
  5943. (search-forward "H1")
  5944. (org-invisible-p2)))
  5945. (should-not
  5946. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  5947. (org-match-sparse-tree nil "tag1|tag2")
  5948. (search-forward "H2")
  5949. (org-invisible-p2)))
  5950. ;; Regexp match on tags.
  5951. (should-not
  5952. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  5953. (org-match-sparse-tree nil "{^tag.*}")
  5954. (search-forward "H1")
  5955. (org-invisible-p2)))
  5956. (should
  5957. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  5958. (org-match-sparse-tree nil "{^tag.*}")
  5959. (search-forward "H2")
  5960. (org-invisible-p2)))
  5961. ;; Match group tags.
  5962. (should-not
  5963. (org-test-with-temp-text
  5964. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  5965. (org-match-sparse-tree nil "work")
  5966. (search-forward "H1")
  5967. (org-invisible-p2)))
  5968. (should-not
  5969. (org-test-with-temp-text
  5970. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  5971. (org-match-sparse-tree nil "work")
  5972. (search-forward "H2")
  5973. (org-invisible-p2)))
  5974. ;; Match group tags with hard brackets.
  5975. (should-not
  5976. (org-test-with-temp-text
  5977. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  5978. (org-match-sparse-tree nil "work")
  5979. (search-forward "H1")
  5980. (org-invisible-p2)))
  5981. (should-not
  5982. (org-test-with-temp-text
  5983. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  5984. (org-match-sparse-tree nil "work")
  5985. (search-forward "H2")
  5986. (org-invisible-p2)))
  5987. ;; Match tags in hierarchies
  5988. (should-not
  5989. (org-test-with-temp-text
  5990. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  5991. #+TAGS: [ Lev_2 : Lev_3 ]\n
  5992. #+TAGS: { Lev_3 : Lev_4 }\n
  5993. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  5994. (org-match-sparse-tree nil "Lev_1")
  5995. (search-forward "H4")
  5996. (org-invisible-p2)))
  5997. (should-not
  5998. (org-test-with-temp-text
  5999. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6000. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6001. #+TAGS: { Lev_3 : Lev_4 }\n
  6002. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6003. (org-match-sparse-tree nil "Lev_1+Lev_3")
  6004. (search-forward "H4")
  6005. (org-invisible-p2)))
  6006. ;; Match regular expressions in tags
  6007. (should-not
  6008. (org-test-with-temp-text
  6009. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
  6010. (org-match-sparse-tree nil "Lev")
  6011. (search-forward "H1")
  6012. (org-invisible-p2)))
  6013. (should
  6014. (org-test-with-temp-text
  6015. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
  6016. (org-match-sparse-tree nil "Lev")
  6017. (search-forward "H1")
  6018. (org-invisible-p2)))
  6019. ;; Match properties.
  6020. (should
  6021. (org-test-with-temp-text
  6022. "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
  6023. (org-match-sparse-tree nil "A=\"1\"")
  6024. (search-forward "H2")
  6025. (org-invisible-p2)))
  6026. (should-not
  6027. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6028. (org-match-sparse-tree nil "A=\"1\"")
  6029. (search-forward "H2")
  6030. (org-invisible-p2)))
  6031. ;; Case is not significant when matching properties.
  6032. (should-not
  6033. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6034. (org-match-sparse-tree nil "a=\"1\"")
  6035. (search-forward "H2")
  6036. (org-invisible-p2)))
  6037. (should-not
  6038. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
  6039. (org-match-sparse-tree nil "A=\"1\"")
  6040. (search-forward "H2")
  6041. (org-invisible-p2)))
  6042. ;; Match special LEVEL property.
  6043. (should-not
  6044. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6045. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6046. (search-forward "H1")
  6047. (org-invisible-p2)))
  6048. (should
  6049. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6050. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6051. (search-forward "H2")
  6052. (org-invisible-p2)))
  6053. ;; Comparison operators when matching properties.
  6054. (should
  6055. (org-test-with-temp-text
  6056. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6057. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6058. (search-forward "H1")
  6059. (org-invisible-p2)))
  6060. (should-not
  6061. (org-test-with-temp-text
  6062. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6063. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6064. (search-forward "H2")
  6065. (org-invisible-p2)))
  6066. ;; Regexp match on properties values.
  6067. (should-not
  6068. (org-test-with-temp-text
  6069. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6070. (org-match-sparse-tree nil "A={f.*}")
  6071. (search-forward "H1")
  6072. (org-invisible-p2)))
  6073. (should
  6074. (org-test-with-temp-text
  6075. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6076. (org-match-sparse-tree nil "A={f.*}")
  6077. (search-forward "H2")
  6078. (org-invisible-p2)))
  6079. ;; With an optional argument, limit match to TODO entries.
  6080. (should-not
  6081. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6082. (org-match-sparse-tree t "tag")
  6083. (search-forward "H1")
  6084. (org-invisible-p2)))
  6085. (should
  6086. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6087. (org-match-sparse-tree t "tag")
  6088. (search-forward "H2")
  6089. (org-invisible-p2))))
  6090. (ert-deftest test-org/occur ()
  6091. "Test `org-occur' specifications."
  6092. ;; Count number of matches.
  6093. (should
  6094. (= 1
  6095. (org-test-with-temp-text "* H\nA\n* H2"
  6096. (org-occur "A"))))
  6097. (should
  6098. (= 2
  6099. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6100. (org-occur "A"))))
  6101. ;; Test CALLBACK optional argument.
  6102. (should
  6103. (= 0
  6104. (org-test-with-temp-text "* H\nA\n* H2"
  6105. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6106. (should
  6107. (= 1
  6108. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6109. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6110. ;; Case-fold searches according to `org-occur-case-fold-search'.
  6111. (should
  6112. (= 2
  6113. (org-test-with-temp-text "Aa"
  6114. (let ((org-occur-case-fold-search t)) (org-occur "A")))))
  6115. (should
  6116. (= 2
  6117. (org-test-with-temp-text "Aa"
  6118. (let ((org-occur-case-fold-search t)) (org-occur "a")))))
  6119. (should
  6120. (= 1
  6121. (org-test-with-temp-text "Aa"
  6122. (let ((org-occur-case-fold-search nil)) (org-occur "A")))))
  6123. (should
  6124. (= 1
  6125. (org-test-with-temp-text "Aa"
  6126. (let ((org-occur-case-fold-search nil)) (org-occur "a")))))
  6127. (should
  6128. (= 1
  6129. (org-test-with-temp-text "Aa"
  6130. (let ((org-occur-case-fold-search 'smart)) (org-occur "A")))))
  6131. (should
  6132. (= 2
  6133. (org-test-with-temp-text "Aa"
  6134. (let ((org-occur-case-fold-search 'smart)) (org-occur "a"))))))
  6135. ;;; Tags
  6136. (ert-deftest test-org/tag-string-to-alist ()
  6137. "Test `org-tag-string-to-alist' specifications."
  6138. ;; Tag without selection key.
  6139. (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
  6140. ;; Tag with selection key.
  6141. (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t))))
  6142. ;; Tag group.
  6143. (should
  6144. (equal
  6145. (org-tag-string-to-alist "[ group : t1 t2 ]")
  6146. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag))))
  6147. ;; Mutually exclusive tags.
  6148. (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
  6149. '((:startgroup) ("tag1") ("tag2") (:endgroup))))
  6150. (should
  6151. (equal
  6152. (org-tag-string-to-alist "{ group : tag1 tag2 }")
  6153. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))))
  6154. (ert-deftest test-org/tag-alist-to-string ()
  6155. "Test `org-tag-alist-to-string' specifications."
  6156. (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
  6157. (should (equal (org-tag-alist-to-string '(("tag1" . ?t))) "tag1(t)"))
  6158. (should
  6159. (equal
  6160. (org-tag-alist-to-string
  6161. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6162. "[ group : t1 t2 ]"))
  6163. (should
  6164. (equal (org-tag-alist-to-string
  6165. '((:startgroup) ("tag1") ("tag2") (:endgroup)))
  6166. "{ tag1 tag2 }"))
  6167. (should
  6168. (equal
  6169. (org-tag-alist-to-string
  6170. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))
  6171. "{ group : tag1 tag2 }")))
  6172. (ert-deftest test-org/tag-alist-to-groups ()
  6173. "Test `org-tag-alist-to-groups' specifications."
  6174. (should
  6175. (equal (org-tag-alist-to-groups
  6176. '((:startgroup) ("group") (:grouptags) ("t1") ("t2") (:endgroup)))
  6177. '(("group" "t1" "t2"))))
  6178. (should
  6179. (equal
  6180. (org-tag-alist-to-groups
  6181. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6182. '(("group" "t1" "t2"))))
  6183. (should-not
  6184. (org-tag-alist-to-groups
  6185. '((:startgroup) ("group") ("t1") ("t2") (:endgroup)))))
  6186. (ert-deftest test-org/tag-align ()
  6187. "Test tags alignment."
  6188. ;; Test aligning tags with different display width.
  6189. (should
  6190. ;; 12345678901234567890
  6191. (equal "* Test :abc:"
  6192. (org-test-with-temp-text "* Test :abc:"
  6193. (let ((org-tags-column -20)
  6194. (indent-tabs-mode nil))
  6195. (org-fix-tags-on-the-fly))
  6196. (buffer-string))))
  6197. (should
  6198. ;; 12345678901234567890
  6199. (equal "* Test :日本語:"
  6200. (org-test-with-temp-text "* Test :日本語:"
  6201. (let ((org-tags-column -20)
  6202. (indent-tabs-mode nil))
  6203. (org-fix-tags-on-the-fly))
  6204. (buffer-string))))
  6205. ;; Make sure aligning tags do not skip invisible text.
  6206. (should
  6207. (equal "* [[linkx]] :tag:"
  6208. (org-test-with-temp-text "* [[link<point>]] :tag:"
  6209. (let ((org-tags-column 0))
  6210. (org-fix-tags-on-the-fly)
  6211. (insert "x")
  6212. (buffer-string)))))
  6213. ;; Aligning tags preserve position.
  6214. (should
  6215. (= 6 (org-test-with-temp-text "* 345 <point> :tag:"
  6216. (let ((org-tags-column 78)
  6217. (indent-tabs-mode nil))
  6218. (org-fix-tags-on-the-fly))
  6219. (current-column))))
  6220. ;; Aligning all tags in visible buffer.
  6221. (should
  6222. ;; 12345678901234567890
  6223. (equal (concat "* Level 1 :abc:\n"
  6224. "** Level 2 :def:")
  6225. (org-test-with-temp-text (concat "* Level 1 :abc:\n"
  6226. "** Level 2 :def:")
  6227. (let ((org-tags-column -20)
  6228. (indent-tabs-mode nil))
  6229. ;; (org-align-tags :all) must work even when the point
  6230. ;; is at the end of the buffer.
  6231. (goto-char (point-max))
  6232. (org-align-tags :all))
  6233. (buffer-string)))))
  6234. (ert-deftest test-org/get-tags ()
  6235. "Test `org-get-tags' specifications."
  6236. ;; Standard test.
  6237. (should
  6238. (equal '("foo")
  6239. (org-test-with-temp-text "* Test :foo:" (org-get-tags))))
  6240. (should
  6241. (equal '("foo" "bar")
  6242. (org-test-with-temp-text "* Test :foo:bar:" (org-get-tags))))
  6243. ;; Return nil when there is no tag.
  6244. (should-not
  6245. (org-test-with-temp-text "* Test" (org-get-tags)))
  6246. ;; Tags are inherited from parent headlines.
  6247. (should
  6248. (equal '("tag")
  6249. (let ((org-use-tag-inheritance t))
  6250. (org-test-with-temp-text "* H0 :foo:\n* H1 :tag:\n<point>** H2"
  6251. (org-get-tags)))))
  6252. ;; Tags are inherited from `org-file-tags'.
  6253. (should
  6254. (equal '("tag")
  6255. (org-test-with-temp-text "* H1"
  6256. (let ((org-file-tags '("tag"))
  6257. (org-use-tag-inheritance t))
  6258. (org-get-tags)))))
  6259. ;; Only inherited tags have the `inherited' text property.
  6260. (should
  6261. (get-text-property 0 'inherited
  6262. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6263. (let ((org-use-tag-inheritance t))
  6264. (assoc-string "foo" (org-get-tags))))))
  6265. (should-not
  6266. (get-text-property 0 'inherited
  6267. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6268. (let ((org-use-tag-inheritance t))
  6269. (assoc-string "bar" (org-get-tags))))))
  6270. ;; Obey to `org-use-tag-inheritance'.
  6271. (should-not
  6272. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6273. (let ((org-use-tag-inheritance nil))
  6274. (assoc-string "foo" (org-get-tags)))))
  6275. (should-not
  6276. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6277. (let ((org-use-tag-inheritance nil)
  6278. (org-file-tags '("foo")))
  6279. (assoc-string "foo" (org-get-tags)))))
  6280. (should-not
  6281. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6282. (let ((org-use-tag-inheritance '("bar")))
  6283. (assoc-string "foo" (org-get-tags)))))
  6284. (should
  6285. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6286. (let ((org-use-tag-inheritance '("bar")))
  6287. (assoc-string "bar" (org-get-tags)))))
  6288. (should-not
  6289. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6290. (let ((org-use-tag-inheritance "b.*"))
  6291. (assoc-string "foo" (org-get-tags)))))
  6292. (should
  6293. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6294. (let ((org-use-tag-inheritance "b.*"))
  6295. (assoc-string "bar" (org-get-tags)))))
  6296. ;; When optional argument LOCAL is non-nil, ignore tag inheritance.
  6297. (should
  6298. (equal '("baz")
  6299. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6300. (let ((org-use-tag-inheritance t))
  6301. (org-get-tags nil t)))))
  6302. ;; When optional argument POS is non-nil, get tags there instead.
  6303. (should
  6304. (equal '("foo")
  6305. (org-test-with-temp-text "* H1 :foo:\n* <point>H2 :bar:"
  6306. (org-get-tags 1))))
  6307. ;; Make sure tags excluded from inheritance are returned if local
  6308. (should
  6309. (equal '("foo")
  6310. (org-test-with-temp-text "* Test :foo:"
  6311. (let ((org-use-tag-inheritance t)
  6312. (org-tags-exclude-from-inheritance '("foo")))
  6313. (org-get-tags)))))
  6314. ;; Test the collection of tags from #+filetags and parent tags.
  6315. (should
  6316. (equal '("a" "b" "c" "d")
  6317. (org-test-with-temp-text (concat "#+filetags: a\n"
  6318. "* Level 1 :b:\n"
  6319. "** Level 2 :c:\n"
  6320. "*** Level 3 :d:\n"
  6321. "<point>")
  6322. (let ((org-use-tag-inheritance t))
  6323. (org-mode-restart) ;So that `org-file-tags' get populated from #+filetags
  6324. (org-get-tags)))))
  6325. ;; Pathological case: tagged headline with an empty body.
  6326. (should (org-test-with-temp-text "* :tag:" (org-get-tags))))
  6327. (ert-deftest test-org/set-tags ()
  6328. "Test `org-set-tags' specifications."
  6329. ;; Throw an error on invalid data.
  6330. (should-error
  6331. (org-test-with-temp-text "* H"
  6332. (org-set-tags 'foo)))
  6333. ;; `nil', an empty, and a blank string remove all tags.
  6334. (should
  6335. (equal "* H"
  6336. (org-test-with-temp-text "* H :tag1:tag2:"
  6337. (org-set-tags nil)
  6338. (buffer-string))))
  6339. (should
  6340. (equal "* H"
  6341. (org-test-with-temp-text "* H :tag1:tag2:"
  6342. (org-set-tags "")
  6343. (buffer-string))))
  6344. (should
  6345. (equal "* H"
  6346. (org-test-with-temp-text "* H :tag1:tag2:"
  6347. (org-set-tags " ")
  6348. (buffer-string))))
  6349. ;; If there's nothing to remove, just bail out.
  6350. (should
  6351. (equal "* H"
  6352. (org-test-with-temp-text "* H"
  6353. (org-set-tags nil)
  6354. (buffer-string))))
  6355. (should
  6356. (equal "* "
  6357. (org-test-with-temp-text "* "
  6358. (org-set-tags nil)
  6359. (buffer-string))))
  6360. ;; If DATA is a tag string, set current tags to it, even if it means
  6361. ;; replacing old tags.
  6362. (should
  6363. (equal "* H :tag0:"
  6364. (org-test-with-temp-text "* H :tag1:tag2:"
  6365. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  6366. (buffer-string))))
  6367. (should
  6368. (equal "* H :tag0:"
  6369. (org-test-with-temp-text "* H"
  6370. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  6371. (buffer-string))))
  6372. ;; If DATA is a list, set tags to this list, even if it means
  6373. ;; replacing old tags.
  6374. (should
  6375. (equal "* H :tag0:"
  6376. (org-test-with-temp-text "* H :tag1:tag2:"
  6377. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6378. (buffer-string))))
  6379. (should
  6380. (equal "* H :tag0:"
  6381. (org-test-with-temp-text "* H"
  6382. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6383. (buffer-string))))
  6384. ;; When set, apply `org-tags-sort-function'.
  6385. (should
  6386. (equal "* H :a:b:"
  6387. (org-test-with-temp-text "* H"
  6388. (let ((org-tags-column 1)
  6389. (org-tags-sort-function #'string<))
  6390. (org-set-tags '("b" "a"))
  6391. (buffer-string)))))
  6392. ;; When new tags are identical to the previous ones, still align.
  6393. (should
  6394. (equal "* H :foo:"
  6395. (org-test-with-temp-text "* H :foo:"
  6396. (let ((org-tags-column 1))
  6397. (org-set-tags '("foo"))
  6398. (buffer-string)))))
  6399. ;; When tags have been changed, run `org-after-tags-change-hook'.
  6400. (should
  6401. (catch :return
  6402. (org-test-with-temp-text "* H :foo:"
  6403. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  6404. (org-set-tags '("bar"))
  6405. nil))))
  6406. (should-not
  6407. (catch :return
  6408. (org-test-with-temp-text "* H :foo:"
  6409. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  6410. (org-set-tags '("foo"))
  6411. nil))))
  6412. ;; Special case: handle empty headlines.
  6413. (should
  6414. (equal "* :tag0:"
  6415. (org-test-with-temp-text "* "
  6416. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6417. (buffer-string))))
  6418. ;; Modify buffer only when a tag change happens or alignment is
  6419. ;; done.
  6420. (should-not
  6421. (org-test-with-temp-text "* H :foo:"
  6422. (set-buffer-modified-p nil)
  6423. (let ((org-tags-column 1)) (org-set-tags '("foo")))
  6424. (buffer-modified-p)))
  6425. (should
  6426. (org-test-with-temp-text "* H :foo:"
  6427. (set-buffer-modified-p nil)
  6428. (let ((org-tags-column 10)) (org-set-tags '("foo")))
  6429. (buffer-modified-p)))
  6430. (should
  6431. (org-test-with-temp-text "* H :foo:"
  6432. (set-buffer-modified-p nil)
  6433. (let ((org-tags-column 10)) (org-set-tags '("bar")))
  6434. (buffer-modified-p)))
  6435. ;; Pathological case: when setting tags of a folded headline, do not
  6436. ;; let new tags being sucked into invisibility.
  6437. (should-not
  6438. (org-test-with-temp-text "* H1\nContent\n* H2\n\n Other Content"
  6439. ;; Show only headlines
  6440. (org-content)
  6441. ;; Set NEXT tag on current entry
  6442. (org-set-tags ":NEXT:")
  6443. ;; Move point to that NEXT tag
  6444. (search-forward "NEXT") (backward-word)
  6445. ;; And it should be visible (i.e. no overlays)
  6446. (overlays-at (point)))))
  6447. (ert-deftest test-org/set-tags-command ()
  6448. "Test `org-set-tags-command' specifications"
  6449. ;; Set tags at current headline.
  6450. (should
  6451. (equal "* H1 :foo:"
  6452. (org-test-with-temp-text "* H1"
  6453. (cl-letf (((symbol-function 'completing-read)
  6454. (lambda (&rest args) ":foo:")))
  6455. (let ((org-use-fast-tag-selection nil)
  6456. (org-tags-column 1))
  6457. (org-set-tags-command)))
  6458. (buffer-string))))
  6459. ;; Preserve position when called from the section below.
  6460. (should
  6461. (equal "* H1 :foo:\nContents"
  6462. (org-test-with-temp-text "* H1\n<point>Contents"
  6463. (cl-letf (((symbol-function 'completing-read)
  6464. (lambda (&rest args) ":foo:")))
  6465. (let ((org-use-fast-tag-selection nil)
  6466. (org-tags-column 1))
  6467. (org-set-tags-command)))
  6468. (buffer-string))))
  6469. (should-not
  6470. (equal "* H1 :foo:\nContents2"
  6471. (org-test-with-temp-text "* H1\n<point>Contents2"
  6472. (cl-letf (((symbol-function 'completing-read)
  6473. (lambda (&rest args) ":foo:")))
  6474. (let ((org-use-fast-tag-selection nil)
  6475. (org-tags-column 1))
  6476. (org-set-tags-command)))
  6477. (org-at-heading-p))))
  6478. ;; Strip all forbidden characters from user-entered tags.
  6479. (should
  6480. (equal "* H1 :foo:"
  6481. (org-test-with-temp-text "* H1"
  6482. (cl-letf (((symbol-function 'completing-read)
  6483. (lambda (&rest args) ": foo *:")))
  6484. (let ((org-use-fast-tag-selection nil)
  6485. (org-tags-column 1))
  6486. (org-set-tags-command)))
  6487. (buffer-string))))
  6488. ;; When a region is active and
  6489. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  6490. ;; same value in all headlines in region.
  6491. (should
  6492. (equal "* H1 :foo:\nContents\n* H2 :foo:"
  6493. (org-test-with-temp-text "* H1\nContents\n* H2"
  6494. (cl-letf (((symbol-function 'completing-read)
  6495. (lambda (&rest args) ":foo:")))
  6496. (let ((org-use-fast-tag-selection nil)
  6497. (org-loop-over-headlines-in-active-region t)
  6498. (org-tags-column 1))
  6499. (transient-mark-mode 1)
  6500. (push-mark (point) t t)
  6501. (goto-char (point-max))
  6502. (org-set-tags-command)))
  6503. (buffer-string))))
  6504. (should
  6505. (equal "* H1\nContents\n* H2 :foo:"
  6506. (org-test-with-temp-text "* H1\nContents\n* H2"
  6507. (cl-letf (((symbol-function 'completing-read)
  6508. (lambda (&rest args) ":foo:")))
  6509. (let ((org-use-fast-tag-selection nil)
  6510. (org-loop-over-headlines-in-active-region nil)
  6511. (org-tags-column 1))
  6512. (transient-mark-mode 1)
  6513. (push-mark (point) t t)
  6514. (goto-char (point-max))
  6515. (org-set-tags-command)))
  6516. (buffer-string))))
  6517. ;; With a C-u prefix argument, align all tags in the buffer.
  6518. (should
  6519. (equal "* H1 :foo:\n* H2 :bar:"
  6520. (org-test-with-temp-text "* H1 :foo:\n* H2 :bar:"
  6521. (let ((org-tags-column 1)) (org-set-tags-command '(4)))
  6522. (buffer-string))))
  6523. ;; Point does not move with empty headline.
  6524. (should
  6525. (equal ":foo:"
  6526. (org-test-with-temp-text "* <point>"
  6527. (cl-letf (((symbol-function 'completing-read)
  6528. (lambda (&rest args) ":foo:")))
  6529. (let ((org-use-fast-tag-selection nil)
  6530. (org-tags-column 1))
  6531. (org-set-tags-command)))
  6532. (buffer-substring (point) (line-end-position)))))
  6533. ;; Point does not move at start of line.
  6534. (should
  6535. (equal "* H1 :foo:"
  6536. (org-test-with-temp-text "* H1"
  6537. (cl-letf (((symbol-function 'completing-read)
  6538. (lambda (&rest args) ":foo:")))
  6539. (let ((org-use-fast-tag-selection nil)
  6540. (org-tags-column 1))
  6541. (org-set-tags-command)))
  6542. (buffer-substring (point) (line-end-position)))))
  6543. ;; Point does not move when within *'s.
  6544. (should
  6545. (equal "* H1 :foo:"
  6546. (org-test-with-temp-text "*<point>* H1"
  6547. (cl-letf (((symbol-function 'completing-read)
  6548. (lambda (&rest args) ":foo:")))
  6549. (let ((org-use-fast-tag-selection nil)
  6550. (org-tags-column 1))
  6551. (org-set-tags-command)))
  6552. (buffer-substring (point) (line-end-position)))))
  6553. ;; Point workaround does not get fooled when looking at a space.
  6554. (should
  6555. (equal " b :foo:"
  6556. (org-test-with-temp-text "* a<point> b"
  6557. (cl-letf (((symbol-function 'completing-read)
  6558. (lambda (&rest args) ":foo:")))
  6559. (let ((org-use-fast-tag-selection nil)
  6560. (org-tags-column 1))
  6561. (org-set-tags-command)))
  6562. (buffer-substring (point) (line-end-position))))))
  6563. (ert-deftest test-org/toggle-tag ()
  6564. "Test `org-toggle-tag' specifications."
  6565. ;; Insert missing tag.
  6566. (should
  6567. (equal "* H :tag:"
  6568. (org-test-with-temp-text "* H"
  6569. (let ((org-tags-column 1)) (org-toggle-tag "tag"))
  6570. (buffer-string))))
  6571. (should
  6572. (equal "* H :tag1:tag2:"
  6573. (org-test-with-temp-text "* H :tag1:"
  6574. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  6575. (buffer-string))))
  6576. ;; Remove existing tag.
  6577. (should
  6578. (equal "* H"
  6579. (org-test-with-temp-text "* H :tag:"
  6580. (org-toggle-tag "tag")
  6581. (buffer-string))))
  6582. (should
  6583. (equal "* H :tag1:"
  6584. (org-test-with-temp-text "* H :tag1:tag2:"
  6585. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  6586. (buffer-string))))
  6587. (should
  6588. (equal "* H :tag2:"
  6589. (org-test-with-temp-text "* H :tag1:tag2:"
  6590. (let ((org-tags-column 1)) (org-toggle-tag "tag1"))
  6591. (buffer-string))))
  6592. ;; With optional argument ONOFF set to `on', try to insert the tag,
  6593. ;; even if its already there.
  6594. (should
  6595. (equal "* H :tag:"
  6596. (org-test-with-temp-text "* H"
  6597. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  6598. (buffer-string))))
  6599. (should
  6600. (equal "* H :tag:"
  6601. (org-test-with-temp-text "* H :tag:"
  6602. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  6603. (buffer-string))))
  6604. ;; With optional argument ONOFF set to `off', try to remove the tag,
  6605. ;; even if its not there.
  6606. (should
  6607. (equal "* H"
  6608. (org-test-with-temp-text "* H :tag:"
  6609. (org-toggle-tag "tag" 'off)
  6610. (buffer-string))))
  6611. (should
  6612. (equal "* H :tag:"
  6613. (org-test-with-temp-text "* H :tag:"
  6614. (let ((org-tags-column 1)) (org-toggle-tag "foo" 'off))
  6615. (buffer-string))))
  6616. ;; Special case: Handle properly tag inheritance. In particular, do
  6617. ;; not set inherited tags.
  6618. (should
  6619. (equal "* H1 :tag:\n** H2 :tag2:tag:"
  6620. (org-test-with-temp-text "* H1 :tag:\n** <point>H2 :tag2:"
  6621. (let ((org-use-tag-inheritance t)
  6622. (org-tags-column 1))
  6623. (org-toggle-tag "tag"))
  6624. (buffer-string))))
  6625. (should
  6626. (equal "* H1 :tag1:tag2:\n** H2 :foo:"
  6627. (org-test-with-temp-text "* H1 :tag1:tag2:\n** <point>H2"
  6628. (let ((org-use-tag-inheritance t)
  6629. (org-tags-column 1))
  6630. (org-toggle-tag "foo"))
  6631. (buffer-string)))))
  6632. (ert-deftest test-org/tags-expand ()
  6633. "Test `org-tags-expand' specifications."
  6634. ;; Expand tag groups as a regexp enclosed within curly brackets.
  6635. (should
  6636. (equal "{\\<[ABC]\\>}"
  6637. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6638. (org-mode-restart)
  6639. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  6640. (should
  6641. (equal "{\\<\\(?:Aa\\|Bb\\|Cc\\)\\>}"
  6642. (org-test-with-temp-text "#+TAGS: [ Aa : Bb Cc ]"
  6643. (org-mode-restart)
  6644. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "Aa")))))
  6645. ;; Preserve operator before the regexp.
  6646. (should
  6647. (equal "+{\\<[ABC]\\>}"
  6648. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6649. (org-mode-restart)
  6650. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "+A")))))
  6651. (should
  6652. (equal "-{\\<[ABC]\\>}"
  6653. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6654. (org-mode-restart)
  6655. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "-A")))))
  6656. ;; Handle "|" syntax.
  6657. (should
  6658. (equal "{\\<[ABC]\\>}|D"
  6659. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6660. (org-mode-restart)
  6661. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|D")))))
  6662. ;; Handle nested groups.
  6663. (should
  6664. (equal "{\\<[A-D]\\>}"
  6665. (org-test-with-temp-text "#+TAGS: [ A : B C ]\n#+TAGS: [ B : D ]"
  6666. (org-mode-restart)
  6667. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  6668. ;; Expand multiple occurrences of the same group.
  6669. (should
  6670. (equal "{\\<[ABC]\\>}|{\\<[ABC]\\>}"
  6671. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6672. (org-mode-restart)
  6673. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|A")))))
  6674. ;; Preserve regexp matches.
  6675. (should
  6676. (equal "{A+}"
  6677. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6678. (org-mode-restart)
  6679. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "{A+}"))))))
  6680. ;;; TODO keywords
  6681. (ert-deftest test-org/auto-repeat-maybe ()
  6682. "Test `org-auto-repeat-maybe' specifications."
  6683. ;; Do not auto repeat when there is no valid time stamp with
  6684. ;; a repeater in the entry.
  6685. (should-not
  6686. (string-prefix-p
  6687. "* TODO H"
  6688. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6689. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
  6690. (org-todo "DONE")
  6691. (buffer-string)))))
  6692. (should-not
  6693. (string-prefix-p
  6694. "* TODO H"
  6695. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6696. (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
  6697. (org-todo "DONE")
  6698. (buffer-string)))))
  6699. ;; When switching to DONE state, switch back to first TODO keyword
  6700. ;; in sequence, or the same keyword if they have different types.
  6701. (should
  6702. (string-prefix-p
  6703. "* TODO H"
  6704. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6705. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  6706. (org-todo "DONE")
  6707. (buffer-string)))))
  6708. (should
  6709. (string-prefix-p
  6710. "* KWD1 H"
  6711. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  6712. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  6713. (org-todo "DONE")
  6714. (buffer-string)))))
  6715. (should
  6716. (string-prefix-p
  6717. "* KWD2 H"
  6718. (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
  6719. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  6720. (org-todo "DONE")
  6721. (buffer-string)))))
  6722. ;; If there was no TODO keyword in the first place, do not insert
  6723. ;; any either.
  6724. (should
  6725. (string-prefix-p
  6726. "* H"
  6727. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6728. (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
  6729. (org-todo "DONE")
  6730. (buffer-string)))))
  6731. ;; Revert to REPEAT_TO_STATE, if set.
  6732. (should
  6733. (string-prefix-p
  6734. "* KWD2 H"
  6735. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  6736. (org-test-with-temp-text
  6737. "* KWD2 H
  6738. :PROPERTIES:
  6739. :REPEAT_TO_STATE: KWD2
  6740. :END:
  6741. <2012-03-29 Thu +2y>"
  6742. (org-todo "DONE")
  6743. (buffer-string)))))
  6744. ;; When switching to DONE state, update base date. If there are
  6745. ;; multiple repeated time stamps, update them all.
  6746. (should
  6747. (string-match-p
  6748. "<2014-03-29 .* \\+2y>"
  6749. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6750. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  6751. (org-todo "DONE")
  6752. (buffer-string)))))
  6753. (should
  6754. (string-match-p
  6755. "<2015-03-04 .* \\+1y>"
  6756. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6757. (org-test-with-temp-text
  6758. "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
  6759. (org-todo "DONE")
  6760. (buffer-string)))))
  6761. ;; Throw an error if repeater unit is the hour and no time is
  6762. ;; provided in the time-stamp.
  6763. (should-error
  6764. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6765. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
  6766. (org-todo "DONE")
  6767. (buffer-string))))
  6768. ;; Handle every repeater type using hours step.
  6769. (should
  6770. (string-match-p
  6771. "2014-03-04 .* 02:00"
  6772. (org-test-at-time "<2014-03-04 02:35>"
  6773. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 +8h>"
  6774. (org-todo "DONE")
  6775. (buffer-string)))))
  6776. (should
  6777. (string-match-p
  6778. "2014-03-04 .* 10:00"
  6779. (org-test-at-time "<2014-03-04 02:35>"
  6780. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 ++8h>"
  6781. (org-todo "DONE")
  6782. (buffer-string)))))
  6783. (should
  6784. (string-match-p
  6785. "2014-03-04 .* 10:35"
  6786. (org-test-at-time "<2014-03-04 02:35>"
  6787. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 .+8h>"
  6788. (org-todo "DONE")
  6789. (buffer-string)))))
  6790. ;; Do not repeat inactive time stamps with a repeater.
  6791. (should-not
  6792. (string-match-p
  6793. "\\[2014-03-29 .* \\+2y\\]"
  6794. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6795. (org-test-with-temp-text
  6796. "* TODO H\n[2012-03-29 Thu. +2y]"
  6797. (org-todo "DONE")
  6798. (buffer-string)))))
  6799. ;; Do not repeat commented time stamps.
  6800. (should-not
  6801. (string-prefix-p
  6802. "<2015-03-04 .* \\+1y>"
  6803. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6804. (org-test-with-temp-text
  6805. "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
  6806. (org-todo "DONE")
  6807. (buffer-string)))))
  6808. (should-not
  6809. (string-prefix-p
  6810. "<2015-03-04 .* \\+1y>"
  6811. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6812. (org-test-with-temp-text
  6813. "* TODO H
  6814. <2012-03-29 Thu. +2y>
  6815. #+BEGIN_EXAMPLE
  6816. <2014-03-04 Tue +1y>
  6817. #+END_EXAMPLE"
  6818. (org-todo "DONE")
  6819. (buffer-string)))))
  6820. ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
  6821. ;; entry, record time of last repeat.
  6822. (should-not
  6823. (string-match-p
  6824. ":LAST_REPEAT:"
  6825. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  6826. (org-log-repeat nil))
  6827. (cl-letf (((symbol-function 'org-add-log-setup)
  6828. (lambda (&rest args) nil)))
  6829. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  6830. (org-todo "DONE")
  6831. (buffer-string))))))
  6832. (should
  6833. (string-match-p
  6834. ":LAST_REPEAT:"
  6835. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  6836. (org-log-repeat t))
  6837. (cl-letf (((symbol-function 'org-add-log-setup)
  6838. (lambda (&rest args) nil)))
  6839. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  6840. (org-todo "DONE")
  6841. (buffer-string))))))
  6842. (should
  6843. (string-match-p
  6844. ":LAST_REPEAT:"
  6845. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6846. (cl-letf (((symbol-function 'org-add-log-setup)
  6847. (lambda (&rest args) nil)))
  6848. (org-test-with-temp-text
  6849. "* TODO H\n<2012-03-29 Thu +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
  6850. (org-todo "DONE")
  6851. (buffer-string))))))
  6852. ;; When a SCHEDULED entry has no repeater, remove it upon repeating
  6853. ;; the entry as it is no longer relevant.
  6854. (should-not
  6855. (string-match-p
  6856. "^SCHEDULED:"
  6857. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6858. (org-test-with-temp-text
  6859. "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
  6860. (org-todo "DONE")
  6861. (buffer-string)))))
  6862. ;; Properly advance repeater even when a clock entry is specified
  6863. ;; and `org-log-repeat' is nil.
  6864. (should
  6865. (string-match-p
  6866. "SCHEDULED: <2014-03-29"
  6867. (let ((org-log-repeat nil)
  6868. (org-todo-keywords '((sequence "TODO" "DONE"))))
  6869. (org-test-with-temp-text
  6870. "* TODO H
  6871. SCHEDULED: <2012-03-29 Thu +2y>
  6872. CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] => 6:40"
  6873. (org-todo "DONE")
  6874. (buffer-string))))))
  6875. ;;; Timestamps API
  6876. (ert-deftest test-org/at-timestamp-p ()
  6877. "Test `org-at-timestamp-p' specifications."
  6878. (should
  6879. (org-test-with-temp-text "<2012-03-29 Thu>"
  6880. (org-at-timestamp-p)))
  6881. (should-not
  6882. (org-test-with-temp-text "2012-03-29 Thu"
  6883. (org-at-timestamp-p)))
  6884. ;; Test return values.
  6885. (should
  6886. (eq 'bracket
  6887. (org-test-with-temp-text "<2012-03-29 Thu>"
  6888. (org-at-timestamp-p))))
  6889. (should
  6890. (eq 'year
  6891. (org-test-with-temp-text "<<point>2012-03-29 Thu>"
  6892. (org-at-timestamp-p))))
  6893. (should
  6894. (eq 'month
  6895. (org-test-with-temp-text "<2012-<point>03-29 Thu>"
  6896. (org-at-timestamp-p))))
  6897. (should
  6898. (eq 'day
  6899. (org-test-with-temp-text "<2012-03-<point>29 Thu>"
  6900. (org-at-timestamp-p))))
  6901. (should
  6902. (eq 'day
  6903. (org-test-with-temp-text "<2012-03-29 T<point>hu>"
  6904. (org-at-timestamp-p))))
  6905. (should
  6906. (wholenump
  6907. (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
  6908. (org-at-timestamp-p))))
  6909. (should
  6910. (eq 'bracket
  6911. (org-test-with-temp-text "<2012-03-29 Thu<point>>"
  6912. (org-at-timestamp-p))))
  6913. (should
  6914. (eq 'after
  6915. (org-test-with-temp-text "<2012-03-29 Thu><point>»"
  6916. (org-at-timestamp-p))))
  6917. ;; Test `inactive' optional argument.
  6918. (should
  6919. (org-test-with-temp-text "[2012-03-29 Thu]"
  6920. (org-at-timestamp-p 'inactive)))
  6921. (should-not
  6922. (org-test-with-temp-text "[2012-03-29 Thu]"
  6923. (org-at-timestamp-p)))
  6924. ;; When optional argument is `agenda', recognize time-stamps in
  6925. ;; planning info line, property drawers and clocks.
  6926. (should
  6927. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  6928. (org-at-timestamp-p 'agenda)))
  6929. (should-not
  6930. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  6931. (org-at-timestamp-p)))
  6932. (should
  6933. (org-test-with-temp-text
  6934. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  6935. (org-at-timestamp-p 'agenda)))
  6936. (should-not
  6937. (org-test-with-temp-text
  6938. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  6939. (org-at-timestamp-p)))
  6940. (should
  6941. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  6942. (let ((org-agenda-include-inactive-timestamps t))
  6943. (org-at-timestamp-p 'agenda))))
  6944. (should-not
  6945. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  6946. (let ((org-agenda-include-inactive-timestamps t))
  6947. (org-at-timestamp-p))))
  6948. (should-not
  6949. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  6950. (let ((org-agenda-include-inactive-timestamps t))
  6951. (org-at-timestamp-p 'inactive))))
  6952. ;; When optional argument is `lax', match any part of the document
  6953. ;; with Org timestamp syntax.
  6954. (should
  6955. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  6956. (org-at-timestamp-p 'lax)))
  6957. (should-not
  6958. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  6959. (org-at-timestamp-p)))
  6960. (should
  6961. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  6962. (org-at-timestamp-p 'lax)))
  6963. (should-not
  6964. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  6965. (org-at-timestamp-p)))
  6966. (should
  6967. (org-test-with-temp-text
  6968. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  6969. (org-at-timestamp-p 'lax)))
  6970. (should-not
  6971. (org-test-with-temp-text
  6972. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  6973. (org-at-timestamp-p)))
  6974. ;; Optional argument `lax' also matches inactive timestamps.
  6975. (should
  6976. (org-test-with-temp-text "# [2012-03-29 Thu]<point>"
  6977. (org-at-timestamp-p 'lax))))
  6978. (ert-deftest test-org/time-stamp ()
  6979. "Test `org-time-stamp' specifications."
  6980. ;; Insert chosen time stamp at point.
  6981. (should
  6982. (string-match
  6983. "Te<2014-03-04 .*?>xt"
  6984. (org-test-with-temp-text "Te<point>xt"
  6985. (cl-letf (((symbol-function 'org-read-date)
  6986. (lambda (&rest args)
  6987. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  6988. (org-time-stamp nil)
  6989. (buffer-string)))))
  6990. ;; With a prefix argument, also insert time.
  6991. (should
  6992. (string-match
  6993. "Te<2014-03-04 .*? 00:41>xt"
  6994. (org-test-with-temp-text "Te<point>xt"
  6995. (cl-letf (((symbol-function 'org-read-date)
  6996. (lambda (&rest args)
  6997. (apply #'encode-time
  6998. (org-parse-time-string "2014-03-04 00:41")))))
  6999. (org-time-stamp '(4))
  7000. (buffer-string)))))
  7001. ;; With two universal prefix arguments, insert an active timestamp
  7002. ;; with the current time without prompting the user.
  7003. (should
  7004. (string-match
  7005. "Te<2014-03-04 .*? 00:41>xt"
  7006. (org-test-with-temp-text "Te<point>xt"
  7007. (org-test-at-time "2014-03-04 00:41"
  7008. (org-time-stamp '(16))
  7009. (buffer-string)))))
  7010. ;; When optional argument is non-nil, insert an inactive timestamp.
  7011. (should
  7012. (string-match
  7013. "Te\\[2014-03-04 .*?\\]xt"
  7014. (org-test-with-temp-text "Te<point>xt"
  7015. (cl-letf (((symbol-function 'org-read-date)
  7016. (lambda (&rest args)
  7017. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7018. (org-time-stamp nil t)
  7019. (buffer-string)))))
  7020. ;; When called from a timestamp, replace existing one.
  7021. (should
  7022. (string-match
  7023. "<2014-03-04 .*?>"
  7024. (org-test-with-temp-text "<2012-03-29<point> thu.>"
  7025. (cl-letf (((symbol-function 'org-read-date)
  7026. (lambda (&rest args)
  7027. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7028. (org-time-stamp nil)
  7029. (buffer-string)))))
  7030. (should
  7031. (string-match
  7032. "<2014-03-04 .*?>--<2014-03-04 .*?>"
  7033. (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
  7034. (cl-letf (((symbol-function 'org-read-date)
  7035. (lambda (&rest args)
  7036. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7037. (org-time-stamp nil)
  7038. (buffer-string)))))
  7039. ;; When replacing a timestamp, preserve repeater, if any.
  7040. (should
  7041. (string-match
  7042. "<2014-03-04 .*? \\+2y>"
  7043. (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
  7044. (cl-letf (((symbol-function 'org-read-date)
  7045. (lambda (&rest args)
  7046. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7047. (org-time-stamp nil)
  7048. (buffer-string)))))
  7049. ;; When called twice in a raw, build a date range.
  7050. (should
  7051. (string-match
  7052. "<2012-03-29 .*?>--<2014-03-04 .*?>"
  7053. (org-test-with-temp-text "<2012-03-29 thu.><point>"
  7054. (cl-letf (((symbol-function 'org-read-date)
  7055. (lambda (&rest args)
  7056. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7057. (let ((last-command 'org-time-stamp)
  7058. (this-command 'org-time-stamp))
  7059. (org-time-stamp nil))
  7060. (buffer-string))))))
  7061. (ert-deftest test-org/timestamp-has-time-p ()
  7062. "Test `org-timestamp-has-time-p' specifications."
  7063. ;; With time.
  7064. (should
  7065. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7066. (org-timestamp-has-time-p (org-element-context))))
  7067. ;; Without time.
  7068. (should-not
  7069. (org-test-with-temp-text "<2012-03-29 Thu>"
  7070. (org-timestamp-has-time-p (org-element-context)))))
  7071. (ert-deftest test-org/get-repeat ()
  7072. "Test `org-get-repeat' specifications."
  7073. (should
  7074. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
  7075. (org-get-repeat)))
  7076. (should-not
  7077. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
  7078. (org-get-repeat)))
  7079. ;; Return proper repeat string.
  7080. (should
  7081. (equal "+2y"
  7082. (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
  7083. (org-get-repeat))))
  7084. ;; Prevent false positive (commented or verbatim time stamps)
  7085. (should-not
  7086. (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
  7087. (org-get-repeat)))
  7088. (should-not
  7089. (org-test-with-temp-text
  7090. "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
  7091. (org-get-repeat)))
  7092. ;; Return nil when called before first heading.
  7093. (should-not
  7094. (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
  7095. (org-get-repeat)))
  7096. ;; When called with an optional argument, extract repeater from that
  7097. ;; string instead.
  7098. (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
  7099. (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
  7100. (ert-deftest test-org/timestamp-format ()
  7101. "Test `org-timestamp-format' specifications."
  7102. ;; Regular test.
  7103. (should
  7104. (equal
  7105. "2012-03-29 16:40"
  7106. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7107. (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
  7108. ;; Range end.
  7109. (should
  7110. (equal
  7111. "2012-03-29"
  7112. (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
  7113. (org-timestamp-format (org-element-context) "%Y-%m-%d" t)))))
  7114. (ert-deftest test-org/timestamp-split-range ()
  7115. "Test `org-timestamp-split-range' specifications."
  7116. ;; Extract range start (active).
  7117. (should
  7118. (equal '(2012 3 29)
  7119. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7120. (let ((ts (org-timestamp-split-range (org-element-context))))
  7121. (mapcar (lambda (p) (org-element-property p ts))
  7122. '(:year-end :month-end :day-end))))))
  7123. ;; Extract range start (inactive)
  7124. (should
  7125. (equal '(2012 3 29)
  7126. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7127. (let ((ts (org-timestamp-split-range (org-element-context))))
  7128. (mapcar (lambda (p) (org-element-property p ts))
  7129. '(:year-end :month-end :day-end))))))
  7130. ;; Extract range end (active).
  7131. (should
  7132. (equal '(2012 3 30)
  7133. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7134. (let ((ts (org-timestamp-split-range
  7135. (org-element-context) t)))
  7136. (mapcar (lambda (p) (org-element-property p ts))
  7137. '(:year-end :month-end :day-end))))))
  7138. ;; Extract range end (inactive)
  7139. (should
  7140. (equal '(2012 3 30)
  7141. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7142. (let ((ts (org-timestamp-split-range
  7143. (org-element-context) t)))
  7144. (mapcar (lambda (p) (org-element-property p ts))
  7145. '(:year-end :month-end :day-end))))))
  7146. ;; Return the timestamp if not a range.
  7147. (should
  7148. (org-test-with-temp-text "[2012-03-29 Thu]"
  7149. (let* ((ts-orig (org-element-context))
  7150. (ts-copy (org-timestamp-split-range ts-orig)))
  7151. (eq ts-orig ts-copy))))
  7152. (should
  7153. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7154. (let* ((ts-orig (org-element-context))
  7155. (ts-copy (org-timestamp-split-range ts-orig)))
  7156. (eq ts-orig ts-copy)))))
  7157. (ert-deftest test-org/timestamp-translate ()
  7158. "Test `org-timestamp-translate' specifications."
  7159. ;; Translate whole date range.
  7160. (should
  7161. (equal "<29>--<30>"
  7162. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7163. (let ((org-display-custom-times t)
  7164. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7165. (org-timestamp-translate (org-element-context))))))
  7166. ;; Translate date range start.
  7167. (should
  7168. (equal "<29>"
  7169. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7170. (let ((org-display-custom-times t)
  7171. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7172. (org-timestamp-translate (org-element-context) 'start)))))
  7173. ;; Translate date range end.
  7174. (should
  7175. (equal "<30>"
  7176. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7177. (let ((org-display-custom-times t)
  7178. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7179. (org-timestamp-translate (org-element-context) 'end)))))
  7180. ;; Translate time range.
  7181. (should
  7182. (equal "<08>--<16>"
  7183. (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
  7184. (let ((org-display-custom-times t)
  7185. (org-time-stamp-custom-formats '("<%d>" . "<%H>")))
  7186. (org-timestamp-translate (org-element-context))))))
  7187. ;; Translate non-range timestamp.
  7188. (should
  7189. (equal "<29>"
  7190. (org-test-with-temp-text "<2012-03-29 Thu>"
  7191. (let ((org-display-custom-times t)
  7192. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7193. (org-timestamp-translate (org-element-context))))))
  7194. ;; Do not change `diary' timestamps.
  7195. (should
  7196. (equal "<%%(org-float t 4 2)>"
  7197. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7198. (let ((org-display-custom-times t)
  7199. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7200. (org-timestamp-translate (org-element-context)))))))
  7201. (ert-deftest test-org/timestamp-from-string ()
  7202. "Test `org-timestamp-from-string' specifications."
  7203. ;; Return nil if argument is not a valid Org timestamp.
  7204. (should-not (org-timestamp-from-string ""))
  7205. (should-not (org-timestamp-from-string nil))
  7206. (should-not (org-timestamp-from-string "<2012-03-29"))
  7207. ;; Otherwise, return a valid Org timestamp object.
  7208. (should
  7209. (string-match-p "<2012-03-29 .+>"
  7210. (org-element-interpret-data
  7211. (org-timestamp-from-string "<2012-03-29 Thu>"))))
  7212. (should
  7213. (string-match-p "[2014-03-04 .+]"
  7214. (org-element-interpret-data
  7215. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  7216. (ert-deftest test-org/timestamp-from-time ()
  7217. "Test `org-timestamp-from-time' specifications."
  7218. ;; Standard test.
  7219. (should
  7220. (string-match-p
  7221. "<2012-03-29 .+>"
  7222. (org-element-interpret-data
  7223. (org-timestamp-from-time
  7224. (apply #'encode-time
  7225. (org-parse-time-string "<2012-03-29 Thu 16:40>"))))))
  7226. ;; When optional argument WITH-TIME is non-nil, provide time
  7227. ;; information.
  7228. (should
  7229. (string-match-p
  7230. "<2012-03-29 .+ 16:40>"
  7231. (org-element-interpret-data
  7232. (org-timestamp-from-time
  7233. (apply #'encode-time
  7234. (org-parse-time-string "<2012-03-29 Thu 16:40>"))
  7235. t))))
  7236. ;; When optional argument INACTIVE is non-nil, return an inactive
  7237. ;; timestamp.
  7238. (should
  7239. (string-match-p
  7240. "[2012-03-29 .+]"
  7241. (org-element-interpret-data
  7242. (org-timestamp-from-time
  7243. (apply #'encode-time
  7244. (org-parse-time-string "<2012-03-29 Thu 16:40>"))
  7245. nil t)))))
  7246. (ert-deftest test-org/timestamp-to-time ()
  7247. "Test `org-timestamp-to-time' specifications."
  7248. (should
  7249. (equal "2014-03-04"
  7250. (format-time-string
  7251. "%Y-%m-%d"
  7252. (org-timestamp-to-time
  7253. (org-timestamp-from-string "<2014-03-04 Tue>")))))
  7254. (should
  7255. (equal "2014-03-04"
  7256. (format-time-string
  7257. "%Y-%m-%d"
  7258. (org-timestamp-to-time
  7259. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  7260. (should
  7261. (equal "2012-03-29 08:30"
  7262. (format-time-string
  7263. "%Y-%m-%d %H:%M"
  7264. (org-timestamp-to-time
  7265. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")))))
  7266. (should
  7267. (equal "2012-03-29"
  7268. (format-time-string
  7269. "%Y-%m-%d"
  7270. (org-timestamp-to-time
  7271. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")))))
  7272. (should
  7273. (equal "2012-03-29"
  7274. (format-time-string
  7275. "%Y-%m-%d"
  7276. (org-timestamp-to-time
  7277. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")))))
  7278. ;; When optional argument END is non-nil, use end of date range or
  7279. ;; time range.
  7280. (should
  7281. (equal "2012-03-29 16:40"
  7282. (format-time-string
  7283. "%Y-%m-%d %H:%M"
  7284. (org-timestamp-to-time
  7285. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")
  7286. t))))
  7287. (should
  7288. (equal "2014-03-04"
  7289. (format-time-string
  7290. "%Y-%m-%d"
  7291. (org-timestamp-to-time
  7292. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")
  7293. t))))
  7294. (should
  7295. (equal "2014-03-04"
  7296. (format-time-string
  7297. "%Y-%m-%d"
  7298. (org-timestamp-to-time
  7299. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")
  7300. t)))))
  7301. ;;; Visibility
  7302. (ert-deftest test-org/hide-drawer-toggle ()
  7303. "Test `org-hide-drawer-toggle' specifications."
  7304. ;; Error when not at a drawer.
  7305. (should-error
  7306. (org-test-with-temp-text ":fake-drawer:\ncontents"
  7307. (org-hide-drawer-toggle 'off)
  7308. (get-char-property (line-end-position) 'invisible)))
  7309. (should-error
  7310. (org-test-with-temp-text
  7311. "#+begin_example\n<point>:D:\nc\n:END:\n#+end_example"
  7312. (org-hide-drawer-toggle t)))
  7313. ;; Hide drawer.
  7314. (should
  7315. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7316. (org-hide-drawer-toggle)
  7317. (get-char-property (line-end-position) 'invisible)))
  7318. ;; Show drawer unconditionally when optional argument is `off'.
  7319. (should-not
  7320. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7321. (org-hide-drawer-toggle)
  7322. (org-hide-drawer-toggle 'off)
  7323. (get-char-property (line-end-position) 'invisible)))
  7324. ;; Hide drawer unconditionally when optional argument is non-nil.
  7325. (should
  7326. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7327. (org-hide-drawer-toggle t)
  7328. (get-char-property (line-end-position) 'invisible)))
  7329. ;; Do not hide drawer when called from final blank lines.
  7330. (should-not
  7331. (org-test-with-temp-text ":drawer:\ncontents\n:end:\n\n<point>"
  7332. (org-hide-drawer-toggle)
  7333. (goto-char (point-min))
  7334. (get-char-property (line-end-position) 'invisible)))
  7335. ;; Don't leave point in an invisible part of the buffer when hiding
  7336. ;; a drawer away.
  7337. (should-not
  7338. (org-test-with-temp-text ":drawer:\ncontents\n<point>:end:"
  7339. (org-hide-drawer-toggle)
  7340. (get-char-property (point) 'invisible))))
  7341. (ert-deftest test-org/hide-block-toggle ()
  7342. "Test `org-hide-block-toggle' specifications."
  7343. ;; Error when not at a block.
  7344. (should-error
  7345. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
  7346. (org-hide-block-toggle 'off)
  7347. (get-char-property (line-end-position) 'invisible)))
  7348. ;; Hide block.
  7349. (should
  7350. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  7351. (org-hide-block-toggle)
  7352. (get-char-property (line-end-position) 'invisible)))
  7353. (should
  7354. (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
  7355. (org-hide-block-toggle)
  7356. (get-char-property (line-end-position) 'invisible)))
  7357. ;; Show block unconditionally when optional argument is `off'.
  7358. (should-not
  7359. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7360. (org-hide-block-toggle)
  7361. (org-hide-block-toggle 'off)
  7362. (get-char-property (line-end-position) 'invisible)))
  7363. (should-not
  7364. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7365. (org-hide-block-toggle 'off)
  7366. (get-char-property (line-end-position) 'invisible)))
  7367. ;; Hide block unconditionally when optional argument is non-nil.
  7368. (should
  7369. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7370. (org-hide-block-toggle t)
  7371. (get-char-property (line-end-position) 'invisible)))
  7372. (should
  7373. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7374. (org-hide-block-toggle)
  7375. (org-hide-block-toggle t)
  7376. (get-char-property (line-end-position) 'invisible)))
  7377. ;; Do not hide block when called from final blank lines.
  7378. (should-not
  7379. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
  7380. (org-hide-block-toggle)
  7381. (goto-char (point-min))
  7382. (get-char-property (line-end-position) 'invisible)))
  7383. ;; Don't leave point in an invisible part of the buffer when hiding
  7384. ;; a block away.
  7385. (should-not
  7386. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
  7387. (org-hide-block-toggle)
  7388. (get-char-property (point) 'invisible))))
  7389. (ert-deftest test-org/hide-block-toggle-maybe ()
  7390. "Test `org-hide-block-toggle-maybe' specifications."
  7391. (should
  7392. (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
  7393. (org-hide-block-toggle-maybe)))
  7394. (should-not
  7395. (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
  7396. (ert-deftest test-org/show-set-visibility ()
  7397. "Test `org-show-set-visibility' specifications."
  7398. ;; Do not throw an error before first heading.
  7399. (should
  7400. (org-test-with-temp-text "Preamble\n* Headline"
  7401. (org-show-set-visibility 'tree)
  7402. t))
  7403. ;; Test all visibility spans, both on headline and in entry.
  7404. (let ((list-visible-lines
  7405. (lambda (state headerp)
  7406. (org-test-with-temp-text "* Grandmother (0)
  7407. ** Uncle (1)
  7408. *** Heir (2)
  7409. ** Father (3)
  7410. Ancestor text (4)
  7411. *** Sister (5)
  7412. Sibling text (6)
  7413. *** Self (7)
  7414. Match (8)
  7415. **** First born (9)
  7416. Child text (10)
  7417. **** The other child (11)
  7418. *** Brother (12)
  7419. ** Aunt (13)
  7420. "
  7421. (org-cycle t)
  7422. (search-forward (if headerp "Self" "Match"))
  7423. (org-show-set-visibility state)
  7424. (goto-char (point-min))
  7425. (let (result (line 0))
  7426. (while (not (eobp))
  7427. (unless (org-invisible-p2) (push line result))
  7428. (cl-incf line)
  7429. (forward-line))
  7430. (nreverse result))))))
  7431. (should (equal '(0 7) (funcall list-visible-lines 'minimal t)))
  7432. (should (equal '(0 7 8) (funcall list-visible-lines 'minimal nil)))
  7433. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local t)))
  7434. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local nil)))
  7435. (should (equal '(0 3 7) (funcall list-visible-lines 'ancestors t)))
  7436. (should (equal '(0 3 7 8) (funcall list-visible-lines 'ancestors nil)))
  7437. (should (equal '(0 3 5 7 12) (funcall list-visible-lines 'lineage t)))
  7438. (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines 'lineage nil)))
  7439. (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines 'tree t)))
  7440. (should (equal '(0 1 3 5 7 8 9 11 12 13)
  7441. (funcall list-visible-lines 'tree nil)))
  7442. (should (equal '(0 1 3 4 5 7 12 13)
  7443. (funcall list-visible-lines 'canonical t)))
  7444. (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
  7445. (funcall list-visible-lines 'canonical nil))))
  7446. ;; When point is hidden in a drawer or a block, make sure to make it
  7447. ;; visible.
  7448. (should-not
  7449. (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
  7450. (org-hide-block-toggle)
  7451. (search-forward "Text")
  7452. (org-show-set-visibility 'minimal)
  7453. (org-invisible-p2)))
  7454. (should-not
  7455. (org-test-with-temp-text ":DRAWER:\nText\n:END:"
  7456. (org-hide-drawer-toggle)
  7457. (search-forward "Text")
  7458. (org-show-set-visibility 'minimal)
  7459. (org-invisible-p2)))
  7460. (should-not
  7461. (org-test-with-temp-text
  7462. "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
  7463. (org-hide-drawer-toggle)
  7464. (forward-line -1)
  7465. (org-hide-block-toggle)
  7466. (search-forward "Text")
  7467. (org-show-set-visibility 'minimal)
  7468. (org-invisible-p2))))
  7469. (defun test-org/copy-visible ()
  7470. "Test `org-copy-visible' specifications."
  7471. (should
  7472. (equal "Foo"
  7473. (org-test-with-temp-text "Foo"
  7474. (let ((kill-ring nil))
  7475. (org-copy-visible (point-min) (point-max))
  7476. (current-kill 0 t)))))
  7477. ;; Skip invisible characters by text property.
  7478. (should
  7479. (equal "Foo"
  7480. (org-test-with-temp-text #("F<hidden>oo" 1 7 (invisible t))
  7481. (let ((kill-ring nil))
  7482. (org-copy-visible (point-min) (point-max))
  7483. (current-kill 0 t)))))
  7484. ;; Skip invisible characters by overlay.
  7485. (should
  7486. (equal "Foo"
  7487. (org-test-with-temp-text "F<hidden>oo"
  7488. (let ((o (make-overlay 2 10)))
  7489. (overlay-put o 'invisible t))
  7490. (let ((kill-ring nil))
  7491. (org-copy-visible (point-min) (point-max))
  7492. (current-kill 0 t)))))
  7493. ;; Handle invisible characters at the beginning and the end of the
  7494. ;; buffer.
  7495. (should
  7496. (equal "Foo"
  7497. (org-test-with-temp-text #("<hidden>Foo" 0 8 (invisible t))
  7498. (let ((kill-ring nil))
  7499. (org-copy-visible (point-min) (point-max))
  7500. (current-kill 0 t)))))
  7501. (should
  7502. (equal "Foo"
  7503. (org-test-with-temp-text #("Foo<hidden>" 3 11 (invisible t))
  7504. (let ((kill-ring nil))
  7505. (org-copy-visible (point-min) (point-max))
  7506. (current-kill 0 t)))))
  7507. ;; Handle multiple visible parts.
  7508. (should
  7509. (equal "abc"
  7510. (org-test-with-temp-text
  7511. #("aXbXc" 1 2 (invisible t) 3 4 (invisible t))
  7512. (let ((kill-ring nil))
  7513. (org-copy-visible (point-min) (point-max))
  7514. (current-kill 0 t))))))
  7515. (ert-deftest test-org/set-visibility-according-to-property ()
  7516. "Test `org-set-visibility-according-to-property' specifications."
  7517. ;; "folded" state.
  7518. (should
  7519. (org-test-with-temp-text
  7520. "
  7521. * a
  7522. :PROPERTIES:
  7523. :VISIBILITY: folded
  7524. :END:
  7525. ** <point>b"
  7526. (org-set-visibility-according-to-property)
  7527. (invisible-p (point))))
  7528. ;; "children" state.
  7529. (should
  7530. (org-test-with-temp-text
  7531. "
  7532. * a
  7533. :PROPERTIES:
  7534. :VISIBILITY: children
  7535. :END:
  7536. ** b
  7537. <point>Contents
  7538. ** c"
  7539. (org-set-visibility-according-to-property)
  7540. (invisible-p (point))))
  7541. (should
  7542. (org-test-with-temp-text
  7543. "
  7544. * a
  7545. :PROPERTIES:
  7546. :VISIBILITY: children
  7547. :END:
  7548. ** b
  7549. Contents
  7550. *** <point>c"
  7551. (org-set-visibility-according-to-property)
  7552. (invisible-p (point))))
  7553. ;; "content" state.
  7554. (should
  7555. (org-test-with-temp-text
  7556. "
  7557. * a
  7558. :PROPERTIES:
  7559. :VISIBILITY: content
  7560. :END:
  7561. ** b
  7562. <point>Contents
  7563. *** c"
  7564. (org-set-visibility-according-to-property)
  7565. (invisible-p (point))))
  7566. (should
  7567. (org-test-with-temp-text
  7568. "
  7569. * a
  7570. :PROPERTIES:
  7571. :VISIBILITY: content
  7572. :END:
  7573. ** b
  7574. Contents
  7575. *** <point>c"
  7576. (org-set-visibility-according-to-property)
  7577. (not (invisible-p (point)))))
  7578. ;; "showall" state.
  7579. (should
  7580. (org-test-with-temp-text
  7581. "
  7582. * a
  7583. :PROPERTIES:
  7584. :VISIBILITY: showall
  7585. :END:
  7586. ** b
  7587. <point>Contents
  7588. *** c"
  7589. (org-set-visibility-according-to-property)
  7590. (not (invisible-p (point)))))
  7591. (should
  7592. (org-test-with-temp-text
  7593. "
  7594. * a
  7595. :PROPERTIES:
  7596. :VISIBILITY: showall
  7597. :END:
  7598. ** b
  7599. Contents
  7600. *** <point>c"
  7601. (org-set-visibility-according-to-property)
  7602. (not (invisible-p (point)))))
  7603. ;; When VISIBILITY properties are nested, ignore inner ones.
  7604. (should
  7605. (org-test-with-temp-text
  7606. "
  7607. * A
  7608. :PROPERTIES:
  7609. :VISIBILITY: folded
  7610. :END:
  7611. ** <point>B
  7612. :PROPERTIES:
  7613. :VISIBILITY: folded
  7614. :END:"
  7615. (org-set-visibility-according-to-property)
  7616. (invisible-p (point)))))
  7617. (ert-deftest test-org/visibility-show-branches ()
  7618. "Test visibility of inline archived subtrees."
  7619. (org-test-with-temp-text
  7620. "* Foo<point>
  7621. ** Bar :ARCHIVE:
  7622. *** Baz
  7623. "
  7624. (org-kill-note-or-show-branches)
  7625. (should (org-invisible-p (- (point-max) 2)))))
  7626. ;;; Yank and Kill
  7627. (ert-deftest test-org/paste-subtree ()
  7628. "Test `org-paste-subtree' specifications."
  7629. ;; Return an error if text to yank is not a set of subtrees.
  7630. (should-error (org-paste-subtree nil "Text"))
  7631. ;; Adjust level according to current one.
  7632. (should
  7633. (equal "* H\n* Text\n"
  7634. (org-test-with-temp-text "* H\n<point>"
  7635. (org-paste-subtree nil "* Text")
  7636. (buffer-string))))
  7637. (should
  7638. (equal "* H1\n** H2\n** Text\n"
  7639. (org-test-with-temp-text "* H1\n** H2\n<point>"
  7640. (org-paste-subtree nil "* Text")
  7641. (buffer-string))))
  7642. ;; When not on a heading, move to next heading before yanking.
  7643. (should
  7644. (equal "* H1\nParagraph\n* Text\n* H2"
  7645. (org-test-with-temp-text "* H1\n<point>Paragraph\n* H2"
  7646. (org-paste-subtree nil "* Text")
  7647. (buffer-string))))
  7648. ;; If point is between two headings, use the deepest level.
  7649. (should
  7650. (equal "* H1\n\n* Text\n* H2"
  7651. (org-test-with-temp-text "* H1\n<point>\n* H2"
  7652. (org-paste-subtree nil "* Text")
  7653. (buffer-string))))
  7654. (should
  7655. (equal "** H1\n\n** Text\n* H2"
  7656. (org-test-with-temp-text "** H1\n<point>\n* H2"
  7657. (org-paste-subtree nil "* Text")
  7658. (buffer-string))))
  7659. (should
  7660. (equal "* H1\n\n** Text\n** H2"
  7661. (org-test-with-temp-text "* H1\n<point>\n** H2"
  7662. (org-paste-subtree nil "* Text")
  7663. (buffer-string))))
  7664. ;; When on an empty heading, after the stars, deduce the new level
  7665. ;; from the number of stars.
  7666. (should
  7667. (equal "*** Text\n"
  7668. (org-test-with-temp-text "*** <point>"
  7669. (org-paste-subtree nil "* Text")
  7670. (buffer-string))))
  7671. ;; Optional argument LEVEL forces a level for the subtree.
  7672. (should
  7673. (equal "* H\n*** Text\n"
  7674. (org-test-with-temp-text "* H<point>"
  7675. (org-paste-subtree 3 "* Text")
  7676. (buffer-string)))))
  7677. (ert-deftest test-org/cut-and-paste-subtree ()
  7678. "Test `org-cut-subtree' and `org-paste-subtree'."
  7679. (should
  7680. (equal
  7681. "* Two
  7682. two
  7683. * One
  7684. "
  7685. (org-test-with-temp-text
  7686. "* One
  7687. <point>* Two
  7688. two
  7689. "
  7690. (call-interactively #'org-cut-subtree)
  7691. (goto-char (point-min))
  7692. (call-interactively #'org-paste-subtree)
  7693. (buffer-string))))
  7694. (should
  7695. (equal
  7696. "* One
  7697. * Two
  7698. "
  7699. (org-test-with-temp-text
  7700. "* One
  7701. <point>* Two
  7702. "
  7703. (call-interactively #'org-cut-subtree)
  7704. (backward-char)
  7705. (call-interactively #'org-paste-subtree)
  7706. (buffer-string)))))
  7707. (provide 'test-org)
  7708. ;;; test-org.el ends here