test-org.el 245 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551
  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. (cl-letf (((symbol-function 'current-time)
  186. (lambda ()
  187. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  188. (org-read-date
  189. t nil "+1y" nil
  190. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))
  191. (should
  192. (equal
  193. "2013-03-29"
  194. (cl-letf (((symbol-function 'current-time)
  195. (lambda ()
  196. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  197. (org-read-date
  198. t nil "++1y" nil
  199. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))
  200. ;; When `org-read-date-prefer-future' is non-nil, prefer future
  201. ;; dates (relatively to now) when incomplete. Otherwise, use
  202. ;; default date.
  203. (should
  204. (equal
  205. "2014-04-01"
  206. (cl-letf (((symbol-function 'current-time)
  207. (lambda ()
  208. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  209. (let ((org-read-date-prefer-future t))
  210. (org-read-date t nil "1")))))
  211. (should
  212. (equal
  213. "2013-03-04"
  214. (cl-letf (((symbol-function 'current-time)
  215. (lambda ()
  216. (apply #'encode-time (org-parse-time-string "2012-03-29")))))
  217. (let ((org-read-date-prefer-future t))
  218. (org-read-date t nil "3-4")))))
  219. (should
  220. (equal
  221. "2012-03-04"
  222. (cl-letf (((symbol-function 'current-time)
  223. (lambda ()
  224. (apply #'encode-time (org-parse-time-string "2012-03-29")))))
  225. (let ((org-read-date-prefer-future nil))
  226. (org-read-date t nil "3-4")))))
  227. ;; When set to `org-read-date-prefer-future' is set to `time', read
  228. ;; day is moved to tomorrow if specified hour is before current
  229. ;; time. However, it only happens in no other part of the date is
  230. ;; specified.
  231. (should
  232. (equal
  233. "2012-03-30"
  234. (cl-letf (((symbol-function 'current-time)
  235. (lambda ()
  236. (apply #'encode-time (org-parse-time-string "2012-03-29 16:40")))))
  237. (let ((org-read-date-prefer-future 'time))
  238. (org-read-date t nil "00:40" nil)))))
  239. (should-not
  240. (equal
  241. "2012-03-30"
  242. (cl-letf (((symbol-function 'current-time)
  243. (lambda ()
  244. (apply #'encode-time (org-parse-time-string "2012-03-29 16:40")))))
  245. (let ((org-read-date-prefer-future 'time))
  246. (org-read-date t nil "29 00:40" nil)))))
  247. ;; Caveat: `org-read-date-prefer-future' always refers to current
  248. ;; time, not default time, when they differ.
  249. (should
  250. (equal
  251. "2014-04-01"
  252. (cl-letf (((symbol-function 'current-time)
  253. (lambda ()
  254. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  255. (let ((org-read-date-prefer-future t))
  256. (org-read-date
  257. t nil "1" nil
  258. (apply #'encode-time (org-parse-time-string "2012-03-29")))))))
  259. (should
  260. (equal
  261. "2014-03-25"
  262. (cl-letf (((symbol-function 'current-time)
  263. (lambda ()
  264. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  265. (let ((org-read-date-prefer-future t))
  266. (org-read-date
  267. t nil "25" nil
  268. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))))
  269. (ert-deftest test-org/org-parse-time-string ()
  270. "Test `org-parse-time-string'."
  271. (should (equal (org-parse-time-string "2012-03-29 16:40")
  272. '(0 40 16 29 3 2012 nil nil nil)))
  273. (should (equal (org-parse-time-string "[2012-03-29 16:40]")
  274. '(0 40 16 29 3 2012 nil nil nil)))
  275. (should (equal (org-parse-time-string "<2012-03-29 16:40>")
  276. '(0 40 16 29 3 2012 nil nil nil)))
  277. (should (equal (org-parse-time-string "<2012-03-29>")
  278. '(0 0 0 29 3 2012 nil nil nil)))
  279. (should (equal (org-parse-time-string "<2012-03-29>" t)
  280. '(0 nil nil 29 3 2012 nil nil nil))))
  281. (ert-deftest test-org/closest-date ()
  282. "Test `org-closest-date' specifications."
  283. (require 'calendar)
  284. ;; Time stamps without a repeater are returned unchanged.
  285. (should
  286. (equal
  287. '(3 29 2012)
  288. (calendar-gregorian-from-absolute
  289. (org-closest-date "<2012-03-29>" "<2014-03-04>" nil))))
  290. ;; Time stamps with a null repeater are returned unchanged.
  291. (should
  292. (equal
  293. '(3 29 2012)
  294. (calendar-gregorian-from-absolute
  295. (org-closest-date "<2012-03-29 +0d>" "<2014-03-04>" nil))))
  296. ;; if PREFER is set to `past' always return a date before, or equal
  297. ;; to CURRENT.
  298. (should
  299. (equal
  300. '(3 1 2014)
  301. (calendar-gregorian-from-absolute
  302. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'past))))
  303. (should
  304. (equal
  305. '(3 4 2014)
  306. (calendar-gregorian-from-absolute
  307. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'past))))
  308. ;; if PREFER is set to `future' always return a date before, or equal
  309. ;; to CURRENT.
  310. (should
  311. (equal
  312. '(3 29 2014)
  313. (calendar-gregorian-from-absolute
  314. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'future))))
  315. (should
  316. (equal
  317. '(3 4 2014)
  318. (calendar-gregorian-from-absolute
  319. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'future))))
  320. ;; If PREFER is neither `past' nor `future', select closest date.
  321. (should
  322. (equal
  323. '(3 1 2014)
  324. (calendar-gregorian-from-absolute
  325. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" nil))))
  326. (should
  327. (equal
  328. '(5 4 2014)
  329. (calendar-gregorian-from-absolute
  330. (org-closest-date "<2012-03-04 +1m>" "<2014-04-28>" nil))))
  331. ;; Test "day" repeater.
  332. (should
  333. (equal '(3 8 2014)
  334. (calendar-gregorian-from-absolute
  335. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'past))))
  336. (should
  337. (equal '(3 10 2014)
  338. (calendar-gregorian-from-absolute
  339. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'future))))
  340. ;; Test "month" repeater.
  341. (should
  342. (equal '(1 5 2015)
  343. (calendar-gregorian-from-absolute
  344. (org-closest-date "<2014-03-05 +2m>" "<2015-02-04>" 'past))))
  345. (should
  346. (equal '(3 29 2014)
  347. (calendar-gregorian-from-absolute
  348. (org-closest-date "<2012-03-29 +2m>" "<2014-03-04>" 'future))))
  349. ;; Test "year" repeater.
  350. (should
  351. (equal '(3 5 2014)
  352. (calendar-gregorian-from-absolute
  353. (org-closest-date "<2014-03-05 +2y>" "<2015-02-04>" 'past))))
  354. (should
  355. (equal '(3 29 2014)
  356. (calendar-gregorian-from-absolute
  357. (org-closest-date "<2012-03-29 +2y>" "<2014-03-04>" 'future)))))
  358. (ert-deftest test-org/deadline-close-p ()
  359. "Test `org-deadline-close-p' specifications."
  360. ;; Pretend that the current time is 2016-06-03 Fri 01:43
  361. (cl-letf (((symbol-function 'current-time)
  362. (lambda ()
  363. (apply #'encode-time
  364. (org-parse-time-string "2016-06-03 Fri 01:43")))))
  365. ;; Timestamps are close if they are within `ndays' of lead time.
  366. (org-test-with-temp-text "* Heading"
  367. (should (org-deadline-close-p "2016-06-03 Fri" 0))
  368. (should (org-deadline-close-p "2016-06-02 Thu" 0))
  369. (should-not (org-deadline-close-p "2016-06-04 Sat" 0))
  370. (should (org-deadline-close-p "2016-06-04 Sat" 1))
  371. (should (org-deadline-close-p "2016-06-03 Fri 12:00" 0)))
  372. ;; Read `ndays' from timestamp if argument not given.
  373. (org-test-with-temp-text "* H"
  374. (should (org-deadline-close-p "2016-06-04 Sat -1d"))
  375. (should-not (org-deadline-close-p "2016-06-04 Sat -0d"))
  376. (should (org-deadline-close-p "2016-06-10 Fri -1w"))
  377. (should-not (org-deadline-close-p "2016-06-11 Sat -1w")))
  378. ;; Prefer `ndays' argument over lead time in timestamp.
  379. (org-test-with-temp-text "* H"
  380. (should (org-deadline-close-p "2016-06-04 Sat -0d" 1))
  381. (should-not (org-deadline-close-p "2016-06-04 Sat -0d" 0)))
  382. ;; Completed tasks are never close.
  383. (let ((org-todo-keywords '(("TODO" "|" "DONE"))))
  384. (org-test-with-temp-text "* TODO Heading"
  385. (should (org-deadline-close-p "2016-06-03")))
  386. (org-test-with-temp-text "* DONE Heading"
  387. (should-not (org-deadline-close-p "2016-06-03"))))))
  388. ;;; Drawers
  389. (ert-deftest test-org/insert-property-drawer ()
  390. "Test `org-insert-property-drawer' specifications."
  391. ;; Error before first headline.
  392. (should-error (org-test-with-temp-text "" (org-insert-property-drawer)))
  393. ;; Insert drawer right after headline if there is no planning line,
  394. ;; or after it otherwise.
  395. (should
  396. (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
  397. (org-test-with-temp-text "* H\nParagraph<point>"
  398. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  399. (buffer-string))))
  400. (should
  401. (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
  402. (org-test-with-temp-text
  403. "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
  404. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  405. (buffer-string))))
  406. ;; Indent inserted drawer.
  407. (should
  408. (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
  409. (org-test-with-temp-text "* H\nParagraph<point>"
  410. (let ((org-adapt-indentation t)) (org-insert-property-drawer))
  411. (buffer-string))))
  412. ;; Handle insertion at eob.
  413. (should
  414. (equal "* H\n:PROPERTIES:\n:END:\n"
  415. (org-test-with-temp-text "* H"
  416. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  417. (buffer-string))))
  418. ;; Skip inlinetasks before point.
  419. (when (featurep 'org-inlinetask)
  420. (should
  421. (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
  422. (org-test-with-temp-text
  423. "* H\n*************** I\n*************** END\nP<point>"
  424. (let ((org-adapt-indentation nil)
  425. (org-inlinetask-min-level 15))
  426. (org-insert-property-drawer))
  427. (buffer-string)))))
  428. ;; Correctly set drawer in an inlinetask.
  429. (when (featurep 'org-inlinetask)
  430. (should
  431. (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
  432. (org-test-with-temp-text
  433. "* H\n*************** I\nP<point>\n*************** END"
  434. (let ((org-adapt-indentation nil)
  435. (org-inlinetask-min-level 15))
  436. (org-insert-property-drawer))
  437. (buffer-string))))))
  438. ;;; Filling
  439. (ert-deftest test-org/fill-element ()
  440. "Test `org-fill-element' specifications."
  441. ;; At an Org table, align it.
  442. (should
  443. (equal "| a |\n"
  444. (org-test-with-temp-text "|a|"
  445. (org-fill-element)
  446. (buffer-string))))
  447. (should
  448. (equal "#+name: table\n| a |\n"
  449. (org-test-with-temp-text "#+name: table\n| a |\n"
  450. (org-fill-element)
  451. (buffer-string))))
  452. ;; At a paragraph, preserve line breaks.
  453. (org-test-with-temp-text "some \\\\\nlong\ntext"
  454. (let ((fill-column 20))
  455. (org-fill-element)
  456. (should (equal (buffer-string) "some \\\\\nlong text"))))
  457. ;; Correctly fill a paragraph when point is at its very end.
  458. (should
  459. (equal "A B"
  460. (org-test-with-temp-text "A\nB"
  461. (let ((fill-column 20))
  462. (goto-char (point-max))
  463. (org-fill-element)
  464. (buffer-string)))))
  465. ;; Correctly fill the last paragraph of a greater element.
  466. (should
  467. (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
  468. (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
  469. (let ((fill-column 8))
  470. (forward-line)
  471. (end-of-line)
  472. (org-fill-element)
  473. (buffer-string)))))
  474. ;; Correctly fill an element in a narrowed buffer.
  475. (should
  476. (equal "01234\n6"
  477. (org-test-with-temp-text "01234 6789"
  478. (let ((fill-column 5))
  479. (narrow-to-region 1 8)
  480. (org-fill-element)
  481. (buffer-string)))))
  482. ;; Handle `adaptive-fill-regexp' in paragraphs.
  483. (should
  484. (equal "> a b"
  485. (org-test-with-temp-text "> a\n> b"
  486. (let ((fill-column 5)
  487. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  488. (org-fill-element)
  489. (buffer-string)))))
  490. ;; Special case: Fill first paragraph when point is at an item or
  491. ;; a plain-list or a footnote reference.
  492. (should
  493. (equal "- A B"
  494. (org-test-with-temp-text "- A\n B"
  495. (let ((fill-column 20))
  496. (org-fill-element)
  497. (buffer-string)))))
  498. (should
  499. (equal "[fn:1] A B"
  500. (org-test-with-temp-text "[fn:1] A\nB"
  501. (let ((fill-column 20))
  502. (org-fill-element)
  503. (buffer-string)))))
  504. (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
  505. (let ((fill-column 20))
  506. (org-fill-element)
  507. (should (equal (buffer-string)
  508. "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
  509. ;; Fill contents of `comment-block' elements.
  510. (should
  511. (equal
  512. (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
  513. (let ((fill-column 20))
  514. (forward-line)
  515. (org-fill-element)
  516. (buffer-string)))
  517. "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
  518. ;; Fill `comment' elements.
  519. (should
  520. (equal " # A B"
  521. (org-test-with-temp-text " # A\n # B"
  522. (let ((fill-column 20))
  523. (org-fill-element)
  524. (buffer-string)))))
  525. ;; Do not mix consecutive comments when filling one of them.
  526. (should
  527. (equal "# A B\n\n# C"
  528. (org-test-with-temp-text "# A\n# B\n\n# C"
  529. (let ((fill-column 20))
  530. (org-fill-element)
  531. (buffer-string)))))
  532. ;; Use commented empty lines as separators when filling comments.
  533. (should
  534. (equal "# A B\n#\n# C"
  535. (org-test-with-temp-text "# A\n# B\n#\n# C"
  536. (let ((fill-column 20))
  537. (org-fill-element)
  538. (buffer-string)))))
  539. ;; Handle `adaptive-fill-regexp' in comments.
  540. (should
  541. (equal "# > a b"
  542. (org-test-with-temp-text "# > a\n# > b"
  543. (let ((fill-column 20)
  544. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  545. (org-fill-element)
  546. (buffer-string)))))
  547. ;; Do nothing at affiliated keywords.
  548. (should
  549. (equal "#+NAME: para\nSome\ntext."
  550. (org-test-with-temp-text "#+NAME: para\nSome\ntext."
  551. (let ((fill-column 20))
  552. (org-fill-element)
  553. (buffer-string)))))
  554. ;; Do not move point after table when filling a table.
  555. (should-not
  556. (org-test-with-temp-text "| a | b |\n| c | d |\n"
  557. (forward-char)
  558. (org-fill-element)
  559. (eobp)))
  560. ;; Do not fill "n" macro, with or without arguments, followed by
  561. ;; a dot or a closing parenthesis since it could be confused with
  562. ;; a numbered bullet.
  563. (should-not
  564. (equal "123456789\n{{{n}}}."
  565. (org-test-with-temp-text "123456789 {{{n}}}."
  566. (let ((fill-column 10))
  567. (org-fill-element)
  568. (buffer-string)))))
  569. (should-not
  570. (equal "123456789\n{{{n}}}\)"
  571. (org-test-with-temp-text "123456789 {{{n}}}\)"
  572. (let ((fill-column 10))
  573. (org-fill-element)
  574. (buffer-string)))))
  575. (should-not
  576. (equal "123456789\n{{{n()}}}."
  577. (org-test-with-temp-text "123456789 {{{n()}}}."
  578. (let ((fill-column 10))
  579. (org-fill-element)
  580. (buffer-string)))))
  581. (should-not
  582. (equal "123456789\n{{{n(counter)}}}."
  583. (org-test-with-temp-text "123456789 {{{n(counter)}}}."
  584. (let ((fill-column 10))
  585. (org-fill-element)
  586. (buffer-string))))))
  587. (ert-deftest test-org/auto-fill-function ()
  588. "Test auto-filling features."
  589. ;; Auto fill paragraph.
  590. (should
  591. (equal "12345\n7890"
  592. (org-test-with-temp-text "12345 7890"
  593. (let ((fill-column 5))
  594. (end-of-line)
  595. (org-auto-fill-function)
  596. (buffer-string)))))
  597. ;; Auto fill first paragraph in an item.
  598. (should
  599. (equal "- 12345\n 7890"
  600. (org-test-with-temp-text "- 12345 7890"
  601. (let ((fill-column 7))
  602. (end-of-line)
  603. (org-auto-fill-function)
  604. (buffer-string)))))
  605. ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
  606. (should
  607. (equal "> 12345\n 7890"
  608. (org-test-with-temp-text "> 12345 7890"
  609. (let ((fill-column 10)
  610. (adaptive-fill-regexp "[ \t]*>+[ \t]*")
  611. (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
  612. (end-of-line)
  613. (org-auto-fill-function)
  614. (buffer-string)))))
  615. (should
  616. (equal "> 12345\n> 12345\n> 7890"
  617. (org-test-with-temp-text "> 12345\n> 12345 7890"
  618. (let ((fill-column 10)
  619. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  620. (goto-char (point-max))
  621. (org-auto-fill-function)
  622. (buffer-string)))))
  623. (should-not
  624. (equal " 12345\n *12345\n *12345"
  625. (org-test-with-temp-text " 12345\n *12345 12345"
  626. (let ((fill-column 10)
  627. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  628. (goto-char (point-max))
  629. (org-auto-fill-function)
  630. (buffer-string)))))
  631. ;; Auto fill comments.
  632. (should
  633. (equal " # 12345\n # 7890"
  634. (org-test-with-temp-text " # 12345 7890"
  635. (let ((fill-column 10))
  636. (end-of-line)
  637. (org-auto-fill-function)
  638. (buffer-string)))))
  639. ;; A hash within a line isn't a comment.
  640. (should-not
  641. (equal "12345 # 7890\n# 1"
  642. (org-test-with-temp-text "12345 # 7890 1"
  643. (let ((fill-column 12))
  644. (end-of-line)
  645. (org-auto-fill-function)
  646. (buffer-string)))))
  647. ;; Correctly interpret empty prefix.
  648. (should-not
  649. (equal "# a\n# b\nRegular\n# paragraph"
  650. (org-test-with-temp-text "# a\n# b\nRegular paragraph"
  651. (let ((fill-column 12))
  652. (end-of-line 3)
  653. (org-auto-fill-function)
  654. (buffer-string)))))
  655. ;; Comment block: auto fill contents.
  656. (should
  657. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  658. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  659. (let ((fill-column 5))
  660. (forward-line)
  661. (end-of-line)
  662. (org-auto-fill-function)
  663. (buffer-string)))))
  664. (should
  665. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  666. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  667. (let ((fill-column 5))
  668. (forward-line)
  669. (end-of-line)
  670. (org-auto-fill-function)
  671. (buffer-string)))))
  672. ;; Do not fill if a new item could be created.
  673. (should-not
  674. (equal "12345\n- 90"
  675. (org-test-with-temp-text "12345 - 90"
  676. (let ((fill-column 5))
  677. (end-of-line)
  678. (org-auto-fill-function)
  679. (buffer-string)))))
  680. ;; Do not fill if a line break could be introduced.
  681. (should-not
  682. (equal "123\\\\\n7890"
  683. (org-test-with-temp-text "123\\\\ 7890"
  684. (let ((fill-column 6))
  685. (end-of-line)
  686. (org-auto-fill-function)
  687. (buffer-string)))))
  688. ;; Do not fill affiliated keywords.
  689. (should-not
  690. (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
  691. (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
  692. (let ((fill-column 20))
  693. (end-of-line)
  694. (org-auto-fill-function)
  695. (buffer-string))))))
  696. ;;; Indentation
  697. (ert-deftest test-org/indent-line ()
  698. "Test `org-indent-line' specifications."
  699. ;; Do not indent diary sexps, footnote definitions or headlines.
  700. (should
  701. (zerop
  702. (org-test-with-temp-text "%%(org-calendar-holiday)"
  703. (org-indent-line)
  704. (org-get-indentation))))
  705. (should
  706. (zerop
  707. (org-test-with-temp-text "[fn:1] fn"
  708. (let ((org-adapt-indentation t)) (org-indent-line))
  709. (org-get-indentation))))
  710. (should
  711. (zerop
  712. (org-test-with-temp-text "* H"
  713. (org-indent-line)
  714. (org-get-indentation))))
  715. ;; Do not indent before first headline.
  716. (should
  717. (zerop
  718. (org-test-with-temp-text ""
  719. (org-indent-line)
  720. (org-get-indentation))))
  721. ;; Indent according to headline level otherwise, unless
  722. ;; `org-adapt-indentation' is nil.
  723. (should
  724. (= 2
  725. (org-test-with-temp-text "* H\n<point>A"
  726. (let ((org-adapt-indentation t)) (org-indent-line))
  727. (org-get-indentation))))
  728. (should
  729. (= 2
  730. (org-test-with-temp-text "* H\n<point>\nA"
  731. (let ((org-adapt-indentation t)) (org-indent-line))
  732. (org-get-indentation))))
  733. (should
  734. (zerop
  735. (org-test-with-temp-text "* H\n<point>A"
  736. (let ((org-adapt-indentation nil)) (org-indent-line))
  737. (org-get-indentation))))
  738. ;; Indenting preserves point position.
  739. (should
  740. (org-test-with-temp-text "* H\nA<point>B"
  741. (let ((org-adapt-indentation t)) (org-indent-line))
  742. (looking-at "B")))
  743. ;; Do not change indentation at an item or a LaTeX environment.
  744. (should
  745. (= 1
  746. (org-test-with-temp-text "* H\n<point> - A"
  747. (let ((org-adapt-indentation t)) (org-indent-line))
  748. (org-get-indentation))))
  749. (should
  750. (= 1
  751. (org-test-with-temp-text
  752. "\\begin{equation}\n <point>1+1=2\n\\end{equation}"
  753. (org-indent-line)
  754. (org-get-indentation))))
  755. ;; On blank lines at the end of a list, indent like last element
  756. ;; within it if the line is still in the list. If the last element
  757. ;; is an item, indent like its contents. Otherwise, indent like the
  758. ;; whole list.
  759. (should
  760. (= 4
  761. (org-test-with-temp-text "* H\n- A\n - AA\n<point>"
  762. (let ((org-adapt-indentation t)) (org-indent-line))
  763. (org-get-indentation))))
  764. (should
  765. (= 4
  766. (org-test-with-temp-text "* H\n- A\n -\n\n<point>"
  767. (let ((org-adapt-indentation t)) (org-indent-line))
  768. (org-get-indentation))))
  769. (should
  770. (zerop
  771. (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n<point>"
  772. (let ((org-adapt-indentation t)) (org-indent-line))
  773. (org-get-indentation))))
  774. (should
  775. (= 4
  776. (org-test-with-temp-text "* H\n- A\n - \n<point>"
  777. (let ((org-adapt-indentation t)) (org-indent-line))
  778. (org-get-indentation))))
  779. (should
  780. (= 4
  781. (org-test-with-temp-text
  782. "* H\n - \n #+BEGIN_SRC emacs-lisp\n t\n #+END_SRC\n<point>"
  783. (let ((org-adapt-indentation t)) (org-indent-line))
  784. (org-get-indentation))))
  785. (should
  786. (= 2
  787. (org-test-with-temp-text "- A\n B\n\n<point>"
  788. (let ((org-adapt-indentation nil)) (org-indent-line))
  789. (org-get-indentation))))
  790. (should
  791. (= 2
  792. (org-test-with-temp-text
  793. "- A\n \begin{cases} 1 + 1\n \end{cases}\n\n<point>"
  794. (let ((org-adapt-indentation nil)) (org-indent-line))
  795. (org-get-indentation))))
  796. ;; Likewise, on a blank line at the end of a footnote definition,
  797. ;; indent at column 0 if line belongs to the definition. Otherwise,
  798. ;; indent like the definition itself.
  799. (should
  800. (zerop
  801. (org-test-with-temp-text "* H\n[fn:1] Definition\n<point>"
  802. (let ((org-adapt-indentation t)) (org-indent-line))
  803. (org-get-indentation))))
  804. (should
  805. (zerop
  806. (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n<point>"
  807. (let ((org-adapt-indentation t)) (org-indent-line))
  808. (org-get-indentation))))
  809. ;; After the end of the contents of a greater element, indent like
  810. ;; the beginning of the element.
  811. (should
  812. (= 1
  813. (org-test-with-temp-text
  814. " #+BEGIN_CENTER\n Contents\n<point>#+END_CENTER"
  815. (org-indent-line)
  816. (org-get-indentation))))
  817. ;; On blank lines after a paragraph, indent like its last non-empty
  818. ;; line.
  819. (should
  820. (= 1
  821. (org-test-with-temp-text " Paragraph\n\n<point>"
  822. (org-indent-line)
  823. (org-get-indentation))))
  824. ;; At the first line of an element, indent like previous element's
  825. ;; first line, ignoring footnotes definitions and inline tasks, or
  826. ;; according to parent.
  827. (should
  828. (= 2
  829. (org-test-with-temp-text "A\n\n B\n\nC<point>"
  830. (org-indent-line)
  831. (org-get-indentation))))
  832. (should
  833. (= 1
  834. (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC<point>"
  835. (org-indent-line)
  836. (org-get-indentation))))
  837. (should
  838. (= 1
  839. (org-test-with-temp-text
  840. " #+BEGIN_CENTER\n<point> Contents\n#+END_CENTER"
  841. (org-indent-line)
  842. (org-get-indentation))))
  843. ;; Within code part of a source block, use language major mode if
  844. ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
  845. ;; according to line above.
  846. (should
  847. (= 6
  848. (org-test-with-temp-text
  849. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  850. (let ((org-src-tab-acts-natively t)
  851. (org-edit-src-content-indentation 0))
  852. (org-indent-line))
  853. (org-get-indentation))))
  854. (should
  855. (= 1
  856. (org-test-with-temp-text
  857. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  858. (let ((org-src-tab-acts-natively nil)
  859. (org-edit-src-content-indentation 0))
  860. (org-indent-line))
  861. (org-get-indentation))))
  862. ;; Otherwise, indent like the first non-blank line above.
  863. (should
  864. (zerop
  865. (org-test-with-temp-text
  866. "#+BEGIN_CENTER\nline1\n\n<point> line2\n#+END_CENTER"
  867. (org-indent-line)
  868. (org-get-indentation))))
  869. ;; Align node properties according to `org-property-format'. Handle
  870. ;; nicely empty values.
  871. (should
  872. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  873. (org-test-with-temp-text
  874. "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
  875. (let ((org-property-format "%-10s %s")) (org-indent-line))
  876. (buffer-string))))
  877. (should
  878. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  879. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
  880. (let ((org-property-format "%-10s %s")) (org-indent-line))
  881. (buffer-string)))))
  882. (ert-deftest test-org/indent-region ()
  883. "Test `org-indent-region' specifications."
  884. ;; Indent paragraph.
  885. (should
  886. (equal "A\nB\nC"
  887. (org-test-with-temp-text " A\nB\n C"
  888. (org-indent-region (point-min) (point-max))
  889. (buffer-string))))
  890. ;; Indent greater elements along with their contents.
  891. (should
  892. (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
  893. (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
  894. (org-indent-region (point-min) (point-max))
  895. (buffer-string))))
  896. ;; Ignore contents of verse blocks. Only indent block delimiters.
  897. (should
  898. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  899. (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  900. (org-indent-region (point-min) (point-max))
  901. (buffer-string))))
  902. (should
  903. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  904. (org-test-with-temp-text " #+BEGIN_VERSE\n A\n B\n #+END_VERSE"
  905. (org-indent-region (point-min) (point-max))
  906. (buffer-string))))
  907. ;; Indent example blocks as a single block, unless indentation
  908. ;; should be preserved. In this case only indent the block markers.
  909. (should
  910. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  911. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  912. (org-indent-region (point-min) (point-max))
  913. (buffer-string))))
  914. (should
  915. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  916. (org-test-with-temp-text " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  917. (org-indent-region (point-min) (point-max))
  918. (buffer-string))))
  919. (should
  920. (equal "#+BEGIN_EXAMPLE -i\n A\n B\n#+END_EXAMPLE"
  921. (org-test-with-temp-text
  922. " #+BEGIN_EXAMPLE -i\n A\n B\n #+END_EXAMPLE"
  923. (org-indent-region (point-min) (point-max))
  924. (buffer-string))))
  925. (should
  926. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  927. (org-test-with-temp-text
  928. " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  929. (let ((org-src-preserve-indentation t))
  930. (org-indent-region (point-min) (point-max)))
  931. (buffer-string))))
  932. ;; Treat export blocks as a whole.
  933. (should
  934. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  935. (org-test-with-temp-text "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  936. (org-indent-region (point-min) (point-max))
  937. (buffer-string))))
  938. (should
  939. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  940. (org-test-with-temp-text
  941. " #+BEGIN_EXPORT latex\n A\n B\n #+END_EXPORT"
  942. (org-indent-region (point-min) (point-max))
  943. (buffer-string))))
  944. ;; Indent according to mode if `org-src-tab-acts-natively' is
  945. ;; non-nil. Otherwise, do not indent code at all.
  946. (should
  947. (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
  948. (org-test-with-temp-text
  949. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  950. (let ((org-src-tab-acts-natively t)
  951. (org-edit-src-content-indentation 0))
  952. (org-indent-region (point-min) (point-max)))
  953. (buffer-string))))
  954. (should
  955. (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  956. (org-test-with-temp-text
  957. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  958. (let ((org-src-tab-acts-natively nil)
  959. (org-edit-src-content-indentation 0))
  960. (org-indent-region (point-min) (point-max)))
  961. (buffer-string))))
  962. ;; Align node properties according to `org-property-format'. Handle
  963. ;; nicely empty values.
  964. (should
  965. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  966. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
  967. (let ((org-property-format "%-10s %s")
  968. (org-adapt-indentation nil))
  969. (org-indent-region (point) (point-max)))
  970. (buffer-string))))
  971. (should
  972. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  973. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
  974. (let ((org-property-format "%-10s %s")
  975. (org-adapt-indentation nil))
  976. (org-indent-region (point) (point-max)))
  977. (buffer-string))))
  978. ;; Indent plain lists.
  979. (should
  980. (equal "- A\n B\n - C\n\n D"
  981. (org-test-with-temp-text "- A\n B\n - C\n\n D"
  982. (org-indent-region (point-min) (point-max))
  983. (buffer-string))))
  984. (should
  985. (equal "- A\n\n- B"
  986. (org-test-with-temp-text " - A\n\n - B"
  987. (org-indent-region (point-min) (point-max))
  988. (buffer-string))))
  989. ;; Indent footnote definitions.
  990. (should
  991. (equal "[fn:1] Definition\n\nDefinition"
  992. (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
  993. (org-indent-region (point-min) (point-max))
  994. (buffer-string))))
  995. ;; Special case: Start indenting on a blank line.
  996. (should
  997. (equal "\nParagraph"
  998. (org-test-with-temp-text "\n Paragraph"
  999. (org-indent-region (point-min) (point-max))
  1000. (buffer-string)))))
  1001. ;;; Editing
  1002. (ert-deftest test-org/delete-indentation ()
  1003. "Test `org-delete-indentation' specifications."
  1004. ;; Regular test.
  1005. (should (equal "foo bar"
  1006. (org-test-with-temp-text
  1007. "foo \n bar<point>"
  1008. (org-delete-indentation)
  1009. (buffer-string))))
  1010. ;; With optional argument.
  1011. (should (equal "foo bar"
  1012. (org-test-with-temp-text
  1013. "foo<point> \n bar"
  1014. (org-delete-indentation t)
  1015. (buffer-string))))
  1016. ;; At headline text should be appended to the headline text.
  1017. (should
  1018. (equal"* foo bar :tag:"
  1019. (let (org-auto-align-tags)
  1020. (org-test-with-temp-text
  1021. "* foo :tag:\n bar<point>"
  1022. (org-delete-indentation)
  1023. (buffer-string)))))
  1024. (should
  1025. (equal "* foo bar :tag:"
  1026. (let (org-auto-align-tags)
  1027. (org-test-with-temp-text
  1028. "* foo <point>:tag:\n bar"
  1029. (org-delete-indentation t)
  1030. (buffer-string))))))
  1031. (ert-deftest test-org/return ()
  1032. "Test `org-return' specifications."
  1033. ;; Regular test.
  1034. (should
  1035. (equal "Para\ngraph"
  1036. (org-test-with-temp-text "Para<point>graph"
  1037. (org-return)
  1038. (buffer-string))))
  1039. ;; With optional argument, indent line.
  1040. (should
  1041. (equal " Para\n graph"
  1042. (org-test-with-temp-text " Para<point>graph"
  1043. (org-return t)
  1044. (buffer-string))))
  1045. ;; On a table, call `org-table-next-row'.
  1046. (should
  1047. (org-test-with-temp-text "| <point>a |\n| b |"
  1048. (org-return)
  1049. (looking-at-p "b")))
  1050. ;; Open link or timestamp under point when `org-return-follows-link'
  1051. ;; is non-nil.
  1052. (should
  1053. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1054. (let ((org-return-follows-link t)
  1055. (org-link-search-must-match-exact-headline nil))
  1056. (org-return))
  1057. (looking-at-p "<<target>>")))
  1058. (should-not
  1059. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1060. (let ((org-return-follows-link nil)) (org-return))
  1061. (looking-at-p "<<target>>")))
  1062. (should
  1063. (org-test-with-temp-text "* [[b][a<point>]]\n* b"
  1064. (let ((org-return-follows-link t)) (org-return))
  1065. (looking-at-p "* b")))
  1066. (should
  1067. (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
  1068. (let ((org-return-follows-link t)
  1069. (org-link-search-must-match-exact-headline nil))
  1070. (org-return))
  1071. (looking-at-p "<<target>>")))
  1072. (should-not
  1073. (org-test-with-temp-text "Link [[target]]<point> <<target>>"
  1074. (let ((org-return-follows-link t)
  1075. (org-link-search-must-match-exact-headline nil))
  1076. (org-return))
  1077. (looking-at-p "<<target>>")))
  1078. ;; When `org-return-follows-link' is non-nil, tolerate links and
  1079. ;; timestamps in comments, node properties, etc.
  1080. (should
  1081. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1082. (let ((org-return-follows-link t)
  1083. (org-link-search-must-match-exact-headline nil))
  1084. (org-return))
  1085. (looking-at-p "<<target>>")))
  1086. (should-not
  1087. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1088. (let ((org-return-follows-link nil)) (org-return))
  1089. (looking-at-p "<<target>>")))
  1090. (should-not
  1091. (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
  1092. (let ((org-return-follows-link t)
  1093. (org-link-search-must-match-exact-headline nil))
  1094. (org-return))
  1095. (looking-at-p "<<target>>")))
  1096. ;; `org-return-follows-link' handle multi-line lines.
  1097. (should
  1098. (org-test-with-temp-text
  1099. "[[target][This is a very\n long description<point>]]\n <<target>>"
  1100. (let ((org-return-follows-link t)
  1101. (org-link-search-must-match-exact-headline nil))
  1102. (org-return))
  1103. (looking-at-p "<<target>>")))
  1104. (should-not
  1105. (org-test-with-temp-text
  1106. "[[target][This is a very\n long description]]<point>\n <<target>>"
  1107. (let ((org-return-follows-link t)
  1108. (org-link-search-must-match-exact-headline nil))
  1109. (org-return))
  1110. (looking-at-p "<<target>>")))
  1111. ;; However, do not open link when point is in a table.
  1112. (should
  1113. (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
  1114. (let ((org-return-follows-link t)) (org-return))
  1115. (looking-at-p "between")))
  1116. ;; Special case: in a list, when indenting, do not break structure.
  1117. (should
  1118. (equal "- A\n B"
  1119. (org-test-with-temp-text "- A <point>B"
  1120. (org-return t)
  1121. (buffer-string))))
  1122. (should
  1123. (equal "- A\n\n- B"
  1124. (org-test-with-temp-text "- A\n<point>- B"
  1125. (org-return t)
  1126. (buffer-string))))
  1127. ;; On tags part of a headline, add a newline below it instead of
  1128. ;; breaking it.
  1129. (should
  1130. (equal "* H :tag:\n"
  1131. (org-test-with-temp-text "* H :<point>tag:"
  1132. (org-return)
  1133. (buffer-string))))
  1134. ;; Before headline text, add a newline below it instead of breaking
  1135. ;; it.
  1136. (should
  1137. (equal "* TODO H :tag:\n"
  1138. (org-test-with-temp-text "* <point>TODO H :tag:"
  1139. (org-return)
  1140. (buffer-string))))
  1141. (should
  1142. (equal "* TODO [#B] H :tag:\n"
  1143. (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
  1144. (org-return)
  1145. (buffer-string))))
  1146. (should ;TODO are case-sensitive
  1147. (equal "* \nTodo"
  1148. (org-test-with-temp-text "* <point>Todo"
  1149. (org-return)
  1150. (buffer-string))))
  1151. ;; At headline text, break headline text but preserve tags.
  1152. (should
  1153. (equal "* TODO [#B] foo :tag:\nbar"
  1154. (let (org-auto-align-tags)
  1155. (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
  1156. (org-return)
  1157. (buffer-string)))))
  1158. ;; At bol of headline insert newline.
  1159. (should
  1160. (equal "\n* h"
  1161. (org-test-with-temp-text "<point>* h"
  1162. (org-return)
  1163. (buffer-string))))
  1164. ;; Refuse to leave invalid headline in buffer.
  1165. (should
  1166. (equal "* h\n"
  1167. (org-test-with-temp-text "*<point> h"
  1168. (org-return)
  1169. (buffer-string))))
  1170. ;; Before first column or after last one in a table, split the
  1171. ;; table.
  1172. (should
  1173. (equal "| a |\n\n| b |"
  1174. (org-test-with-temp-text "| a |\n<point>| b |"
  1175. (org-return)
  1176. (buffer-string))))
  1177. (should
  1178. (equal "| a |\n\n| b |"
  1179. (org-test-with-temp-text "| a |<point>\n| b |"
  1180. (org-return)
  1181. (buffer-string))))
  1182. ;; Do not auto-fill on hitting <RET> inside a property drawer.
  1183. (should
  1184. (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:"
  1185. (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:"
  1186. (setq-local fill-column 10)
  1187. (auto-fill-mode 1)
  1188. (org-return)
  1189. (buffer-string)))))
  1190. (ert-deftest test-org/meta-return ()
  1191. "Test M-RET (`org-meta-return') specifications."
  1192. ;; In a table field insert a row above.
  1193. (should
  1194. (org-test-with-temp-text "| a |"
  1195. (forward-char)
  1196. (org-meta-return)
  1197. (forward-line -1)
  1198. (looking-at "| |$")))
  1199. ;; In a paragraph change current line into a header.
  1200. (should
  1201. (org-test-with-temp-text "a"
  1202. (org-meta-return)
  1203. (beginning-of-line)
  1204. (looking-at "\* a$")))
  1205. ;; In an item insert an item, in this case above.
  1206. (should
  1207. (org-test-with-temp-text "- a"
  1208. (org-meta-return)
  1209. (beginning-of-line)
  1210. (looking-at "- $")))
  1211. ;; In a drawer and item insert an item, in this case above.
  1212. (should
  1213. (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
  1214. (forward-line)
  1215. (org-meta-return)
  1216. (beginning-of-line)
  1217. (looking-at "- $"))))
  1218. (ert-deftest test-org/insert-heading ()
  1219. "Test `org-insert-heading' specifications."
  1220. ;; In an empty buffer, insert a new headline.
  1221. (should
  1222. (equal "* "
  1223. (org-test-with-temp-text ""
  1224. (org-insert-heading)
  1225. (buffer-string))))
  1226. ;; At the beginning of a line, turn it into a headline.
  1227. (should
  1228. (equal "* P"
  1229. (org-test-with-temp-text "<point>P"
  1230. (org-insert-heading)
  1231. (buffer-string))))
  1232. ;; In the middle of a line, split the line if allowed, otherwise,
  1233. ;; insert the headline at its end.
  1234. (should
  1235. (equal "Para\n* graph"
  1236. (org-test-with-temp-text "Para<point>graph"
  1237. (let ((org-M-RET-may-split-line '((default . t))))
  1238. (org-insert-heading))
  1239. (buffer-string))))
  1240. (should
  1241. (equal "Paragraph\n* "
  1242. (org-test-with-temp-text "Para<point>graph"
  1243. (let ((org-M-RET-may-split-line '((default . nil))))
  1244. (org-insert-heading))
  1245. (buffer-string))))
  1246. ;; At the beginning of a headline, create one above.
  1247. (should
  1248. (equal "* \n* H"
  1249. (org-test-with-temp-text "* H"
  1250. (org-insert-heading)
  1251. (buffer-string))))
  1252. ;; In the middle of a headline, split it if allowed.
  1253. (should
  1254. (equal "* H\n* 1\n"
  1255. (org-test-with-temp-text "* H<point>1"
  1256. (let ((org-M-RET-may-split-line '((headline . t))))
  1257. (org-insert-heading))
  1258. (buffer-string))))
  1259. (should
  1260. (equal "* H1\n* \n"
  1261. (org-test-with-temp-text "* H<point>1"
  1262. (let ((org-M-RET-may-split-line '((headline . nil))))
  1263. (org-insert-heading))
  1264. (buffer-string))))
  1265. ;; However, splitting cannot happen on TODO keywords, priorities or
  1266. ;; tags.
  1267. (should
  1268. (equal "* TODO H1\n* \n"
  1269. (org-test-with-temp-text "* TO<point>DO H1"
  1270. (let ((org-M-RET-may-split-line '((headline . t))))
  1271. (org-insert-heading))
  1272. (buffer-string))))
  1273. (should
  1274. (equal "* [#A] H1\n* \n"
  1275. (org-test-with-temp-text "* [#<point>A] H1"
  1276. (let ((org-M-RET-may-split-line '((headline . t))))
  1277. (org-insert-heading))
  1278. (buffer-string))))
  1279. (should
  1280. (equal "* H1 :tag:\n* \n"
  1281. (org-test-with-temp-text "* H1 :ta<point>g:"
  1282. (let ((org-M-RET-may-split-line '((headline . t))))
  1283. (org-insert-heading))
  1284. (buffer-string))))
  1285. ;; New headline level depends on the level of the headline above.
  1286. (should
  1287. (equal "** H\n** P"
  1288. (org-test-with-temp-text "** H\n<point>P"
  1289. (org-insert-heading)
  1290. (buffer-string))))
  1291. (should
  1292. (equal "** H\nPara\n** graph"
  1293. (org-test-with-temp-text "** H\nPara<point>graph"
  1294. (let ((org-M-RET-may-split-line '((default . t))))
  1295. (org-insert-heading))
  1296. (buffer-string))))
  1297. (should
  1298. (equal "** \n** H"
  1299. (org-test-with-temp-text "** H"
  1300. (org-insert-heading)
  1301. (buffer-string))))
  1302. ;; When called with one universal argument, insert a new headline at
  1303. ;; the end of the current subtree, independently on the position of
  1304. ;; point.
  1305. (should
  1306. (equal
  1307. "* H1\n** H2\n* \n"
  1308. (org-test-with-temp-text "* H1\n** H2"
  1309. (let ((org-insert-heading-respect-content nil))
  1310. (org-insert-heading '(4)))
  1311. (buffer-string))))
  1312. (should
  1313. (equal
  1314. "* H1\n** H2\n* \n"
  1315. (org-test-with-temp-text "* H<point>1\n** H2"
  1316. (let ((org-insert-heading-respect-content nil))
  1317. (org-insert-heading '(4)))
  1318. (buffer-string))))
  1319. ;; When called with two universal arguments, insert a new headline
  1320. ;; at the end of the grandparent subtree.
  1321. (should
  1322. (equal "* H1\n** H3\n- item\n** H2\n** \n"
  1323. (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
  1324. (let ((org-insert-heading-respect-content nil))
  1325. (org-insert-heading '(16)))
  1326. (buffer-string))))
  1327. ;; When optional TOP-LEVEL argument is non-nil, always insert
  1328. ;; a level 1 heading.
  1329. (should
  1330. (equal "* H1\n** H2\n* \n"
  1331. (org-test-with-temp-text "* H1\n** H2<point>"
  1332. (org-insert-heading nil nil t)
  1333. (buffer-string))))
  1334. (should
  1335. (equal "* H1\n- item\n* "
  1336. (org-test-with-temp-text "* H1\n- item<point>"
  1337. (org-insert-heading nil nil t)
  1338. (buffer-string))))
  1339. ;; Obey `org-blank-before-new-entry'.
  1340. (should
  1341. (equal "* H1\n\n* \n"
  1342. (org-test-with-temp-text "* H1<point>"
  1343. (let ((org-blank-before-new-entry '((heading . t))))
  1344. (org-insert-heading))
  1345. (buffer-string))))
  1346. (should
  1347. (equal "* H1\n* \n"
  1348. (org-test-with-temp-text "* H1<point>"
  1349. (let ((org-blank-before-new-entry '((heading . nil))))
  1350. (org-insert-heading))
  1351. (buffer-string))))
  1352. (should
  1353. (equal "* H1\n* H2\n* \n"
  1354. (org-test-with-temp-text "* H1\n* H2<point>"
  1355. (let ((org-blank-before-new-entry '((heading . auto))))
  1356. (org-insert-heading))
  1357. (buffer-string))))
  1358. (should
  1359. (equal "* H1\n\n* H2\n\n* \n"
  1360. (org-test-with-temp-text "* H1\n\n* H2<point>"
  1361. (let ((org-blank-before-new-entry '((heading . auto))))
  1362. (org-insert-heading))
  1363. (buffer-string))))
  1364. ;; Corner case: correctly insert a headline after an empty one.
  1365. (should
  1366. (equal "* \n* \n"
  1367. (org-test-with-temp-text "* <point>"
  1368. (org-insert-heading)
  1369. (buffer-string))))
  1370. (should
  1371. (org-test-with-temp-text "* <point>\n"
  1372. (org-insert-heading)
  1373. (looking-at-p "\n\\'")))
  1374. ;; Do not insert spurious headlines when inserting a new headline.
  1375. (should
  1376. (equal "* H1\n* H2\n* \n"
  1377. (org-test-with-temp-text "* H1\n* H2<point>\n"
  1378. (org-insert-heading)
  1379. (buffer-string))))
  1380. ;; Preserve visibility at beginning of line. In particular, when
  1381. ;; removing spurious blank lines, do not visually merge heading with
  1382. ;; the line visible above.
  1383. (should-not
  1384. (org-test-with-temp-text "* H1<point>\nContents\n\n* H2\n"
  1385. (org-overview)
  1386. (let ((org-blank-before-new-entry '((heading . nil))))
  1387. (org-insert-heading '(4)))
  1388. (invisible-p (line-end-position 0))))
  1389. ;; Properly handle empty lines when forcing a headline below current
  1390. ;; one.
  1391. (should
  1392. (equal "* H1\n\n* H\n\n* \n"
  1393. (org-test-with-temp-text "* H1\n\n* H<point>"
  1394. (let ((org-blank-before-new-entry '((heading . t))))
  1395. (org-insert-heading '(4))
  1396. (buffer-string))))))
  1397. (ert-deftest test-org/insert-todo-heading-respect-content ()
  1398. "Test `org-insert-todo-heading-respect-content' specifications."
  1399. ;; Create a TODO heading.
  1400. (should
  1401. (org-test-with-temp-text "* H1\n Body"
  1402. (org-insert-todo-heading-respect-content)
  1403. (nth 2 (org-heading-components))))
  1404. ;; Add headline at the end of the first subtree
  1405. (should
  1406. (equal
  1407. "* TODO \n"
  1408. (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
  1409. (org-insert-todo-heading-respect-content)
  1410. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1411. ;; In a list, do not create a new item.
  1412. (should
  1413. (equal
  1414. "* TODO \n"
  1415. (org-test-with-temp-text "* H\n- an item\n- another one"
  1416. (search-forward "an ")
  1417. (org-insert-todo-heading-respect-content)
  1418. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1419. ;; Use the same TODO keyword as current heading.
  1420. (should
  1421. (equal
  1422. "* TODO \n"
  1423. (org-test-with-temp-text "* TODO\n** WAITING\n"
  1424. (org-insert-todo-heading-respect-content)
  1425. (buffer-substring-no-properties (line-beginning-position) (point-max))))))
  1426. (ert-deftest test-org/clone-with-time-shift ()
  1427. "Test `org-clone-subtree-with-time-shift'."
  1428. ;; Raise an error before first heading.
  1429. (should-error
  1430. (org-test-with-temp-text ""
  1431. (org-clone-subtree-with-time-shift 1)))
  1432. ;; Raise an error on invalid number of clones.
  1433. (should-error
  1434. (org-test-with-temp-text "* Clone me"
  1435. (org-clone-subtree-with-time-shift -1)))
  1436. ;; Clone non-repeating once.
  1437. (should
  1438. (equal "\
  1439. * H1\n<2015-06-21>
  1440. * H1\n<2015-06-23>
  1441. "
  1442. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1443. (org-clone-subtree-with-time-shift 1 "+2d")
  1444. (replace-regexp-in-string
  1445. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1446. nil nil 1))))
  1447. ;; Clone repeating once.
  1448. (should
  1449. (equal "\
  1450. * H1\n<2015-06-21>
  1451. * H1\n<2015-06-23>
  1452. * H1\n<2015-06-25 +1w>
  1453. "
  1454. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1455. (org-clone-subtree-with-time-shift 1 "+2d")
  1456. (replace-regexp-in-string
  1457. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1458. nil nil 1))))
  1459. ;; Clone non-repeating zero times.
  1460. (should
  1461. (equal "\
  1462. * H1\n<2015-06-21>
  1463. "
  1464. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1465. (org-clone-subtree-with-time-shift 0 "+2d")
  1466. (replace-regexp-in-string
  1467. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1468. nil nil 1))))
  1469. ;; Clone repeating "zero" times.
  1470. (should
  1471. (equal "\
  1472. * H1\n<2015-06-21>
  1473. * H1\n<2015-06-23 +1w>
  1474. "
  1475. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1476. (org-clone-subtree-with-time-shift 0 "+2d")
  1477. (replace-regexp-in-string
  1478. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1479. nil nil 1))))
  1480. ;; Clone with blank SHIFT argument.
  1481. (should
  1482. (string-prefix-p
  1483. "* H <2012-03-29"
  1484. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1485. (org-clone-subtree-with-time-shift 1 "")
  1486. (buffer-substring-no-properties (line-beginning-position 2)
  1487. (line-end-position 2)))))
  1488. ;; Find time stamps before point. If SHIFT is not specified, ask
  1489. ;; for a time shift.
  1490. (should
  1491. (string-prefix-p
  1492. "* H <2012-03-30"
  1493. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1494. (org-clone-subtree-with-time-shift 1 "+1d")
  1495. (buffer-substring-no-properties (line-beginning-position 2)
  1496. (line-end-position 2)))))
  1497. (should
  1498. (string-prefix-p
  1499. "* H <2014-03-05"
  1500. (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
  1501. (cl-letf (((symbol-function 'read-from-minibuffer)
  1502. (lambda (&rest args) "+1d")))
  1503. (org-clone-subtree-with-time-shift 1))
  1504. (buffer-substring-no-properties (line-beginning-position 2)
  1505. (line-end-position 2))))))
  1506. ;;; Fixed-Width Areas
  1507. (ert-deftest test-org/toggle-fixed-width ()
  1508. "Test `org-toggle-fixed-width' specifications."
  1509. ;; No region: Toggle on fixed-width marker in paragraphs.
  1510. (should
  1511. (equal ": A"
  1512. (org-test-with-temp-text "A"
  1513. (org-toggle-fixed-width)
  1514. (buffer-string))))
  1515. ;; No region: Toggle off fixed-width markers in fixed-width areas.
  1516. (should
  1517. (equal "A"
  1518. (org-test-with-temp-text ": A"
  1519. (org-toggle-fixed-width)
  1520. (buffer-string))))
  1521. ;; No region: Toggle on marker in blank lines after elements or just
  1522. ;; after a headline.
  1523. (should
  1524. (equal "* H\n: "
  1525. (org-test-with-temp-text "* H\n"
  1526. (forward-line)
  1527. (org-toggle-fixed-width)
  1528. (buffer-string))))
  1529. (should
  1530. (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
  1531. (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
  1532. (goto-char (point-max))
  1533. (org-toggle-fixed-width)
  1534. (buffer-string))))
  1535. ;; No region: Toggle on marker in front of one line elements (e.g.,
  1536. ;; headlines, clocks)
  1537. (should
  1538. (equal ": * Headline"
  1539. (org-test-with-temp-text "* Headline"
  1540. (org-toggle-fixed-width)
  1541. (buffer-string))))
  1542. (should
  1543. (equal ": #+KEYWORD: value"
  1544. (org-test-with-temp-text "#+KEYWORD: value"
  1545. (org-toggle-fixed-width)
  1546. (buffer-string))))
  1547. ;; No region: error in other situations.
  1548. (should-error
  1549. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
  1550. (forward-line)
  1551. (org-toggle-fixed-width)
  1552. (buffer-string)))
  1553. ;; No region: Indentation is preserved.
  1554. (should
  1555. (equal "- A\n : B"
  1556. (org-test-with-temp-text "- A\n B"
  1557. (forward-line)
  1558. (org-toggle-fixed-width)
  1559. (buffer-string))))
  1560. ;; Region: If it contains only fixed-width elements and blank lines,
  1561. ;; toggle off fixed-width markup.
  1562. (should
  1563. (equal "A\n\nB"
  1564. (org-test-with-temp-text ": A\n\n: B"
  1565. (transient-mark-mode 1)
  1566. (push-mark (point) t t)
  1567. (goto-char (point-max))
  1568. (org-toggle-fixed-width)
  1569. (buffer-string))))
  1570. ;; Region: If it contains anything else, toggle on fixed-width but
  1571. ;; not on fixed-width areas.
  1572. (should
  1573. (equal ": A\n: \n: B\n: \n: C"
  1574. (org-test-with-temp-text "A\n\n: B\n\nC"
  1575. (transient-mark-mode 1)
  1576. (push-mark (point) t t)
  1577. (goto-char (point-max))
  1578. (org-toggle-fixed-width)
  1579. (buffer-string))))
  1580. ;; Region: Ignore blank lines at its end, unless it contains only
  1581. ;; such lines.
  1582. (should
  1583. (equal ": A\n\n"
  1584. (org-test-with-temp-text "A\n\n"
  1585. (transient-mark-mode 1)
  1586. (push-mark (point) t t)
  1587. (goto-char (point-max))
  1588. (org-toggle-fixed-width)
  1589. (buffer-string))))
  1590. (should
  1591. (equal ": \n: \n"
  1592. (org-test-with-temp-text "\n\n"
  1593. (transient-mark-mode 1)
  1594. (push-mark (point) t t)
  1595. (goto-char (point-max))
  1596. (org-toggle-fixed-width)
  1597. (buffer-string)))))
  1598. (ert-deftest test-org/kill-line ()
  1599. "Test `org-kill-line' specifications."
  1600. ;; At the beginning of a line, kill whole line.
  1601. (should
  1602. (equal ""
  1603. (org-test-with-temp-text "abc"
  1604. (org-kill-line)
  1605. (buffer-string))))
  1606. ;; In the middle of a line, kill line until its end.
  1607. (should
  1608. (equal "a"
  1609. (org-test-with-temp-text "a<point>bc"
  1610. (org-kill-line)
  1611. (buffer-string))))
  1612. ;; Do not kill newline character.
  1613. (should
  1614. (equal "\n123"
  1615. (org-test-with-temp-text "abc\n123"
  1616. (org-kill-line)
  1617. (buffer-string))))
  1618. (should
  1619. (equal "a\n123"
  1620. (org-test-with-temp-text "a<point>bc\n123"
  1621. (org-kill-line)
  1622. (buffer-string))))
  1623. ;; When `org-special-ctrl-k' is non-nil and point is at a headline,
  1624. ;; kill until tags.
  1625. (should
  1626. (equal "* A :tag:"
  1627. (org-test-with-temp-text "* A<point>B :tag:"
  1628. (let ((org-special-ctrl-k t)
  1629. (org-tags-column 0))
  1630. (org-kill-line))
  1631. (buffer-string))))
  1632. ;; If point is on tags, only kill part left until the end of line.
  1633. (should
  1634. (equal "* A :tag:"
  1635. (org-test-with-temp-text "* A :tag:<point>tag2:"
  1636. (let ((org-special-ctrl-k t)
  1637. (org-tags-column 0))
  1638. (org-kill-line))
  1639. (buffer-string))))
  1640. ;; However, if point is at the beginning of the line, kill whole
  1641. ;; headline.
  1642. (should
  1643. (equal ""
  1644. (org-test-with-temp-text "* AB :tag:"
  1645. (let ((org-special-ctrl-k t)
  1646. (org-tags-column 0))
  1647. (org-kill-line))
  1648. (buffer-string))))
  1649. ;; When `org-ctrl-k-protect-subtree' is non-nil, and point is in
  1650. ;; invisible text, ask before removing it. When set to `error',
  1651. ;; throw an error.
  1652. (should-error
  1653. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  1654. (org-overview)
  1655. (let ((org-special-ctrl-k nil)
  1656. (org-ctrl-k-protect-subtree t))
  1657. (cl-letf (((symbol-function 'y-or-n-p) 'ignore))
  1658. (org-kill-line)))))
  1659. (should-error
  1660. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  1661. (org-overview)
  1662. (let ((org-special-ctrl-k nil)
  1663. (org-ctrl-k-protect-subtree 'error))
  1664. (org-kill-line)))))
  1665. ;;; Headline
  1666. (ert-deftest test-org/get-heading ()
  1667. "Test `org-get-heading' specifications."
  1668. ;; Return current heading, even if point is not on it.
  1669. (should
  1670. (equal "H"
  1671. (org-test-with-temp-text "* H"
  1672. (org-get-heading))))
  1673. (should
  1674. (equal "H"
  1675. (org-test-with-temp-text "* H\nText<point>"
  1676. (org-get-heading))))
  1677. ;; Without any optional argument, return TODO keyword, priority
  1678. ;; cookie, COMMENT keyword and tags.
  1679. (should
  1680. (equal "TODO H"
  1681. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  1682. (org-get-heading))))
  1683. (should
  1684. (equal "[#A] H"
  1685. (org-test-with-temp-text "* [#A] H"
  1686. (org-get-heading))))
  1687. (should
  1688. (equal "COMMENT H"
  1689. (org-test-with-temp-text "* COMMENT H"
  1690. (org-get-heading))))
  1691. (should
  1692. (equal "H :tag:"
  1693. (org-test-with-temp-text "* H :tag:"
  1694. (org-get-heading))))
  1695. ;; With NO-TAGS argument, ignore tags.
  1696. (should
  1697. (equal "TODO H"
  1698. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  1699. (org-get-heading t))))
  1700. (should
  1701. (equal "H"
  1702. (org-test-with-temp-text "* H :tag:"
  1703. (org-get-heading t))))
  1704. ;; With NO-TODO, ignore TODO keyword.
  1705. (should
  1706. (equal "H"
  1707. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  1708. (org-get-heading nil t))))
  1709. (should
  1710. (equal "H :tag:"
  1711. (org-test-with-temp-text "* H :tag:"
  1712. (org-get-heading nil t))))
  1713. ;; TODO keywords are case-sensitive.
  1714. (should
  1715. (equal "Todo H"
  1716. (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
  1717. (org-get-heading nil t))))
  1718. ;; With NO-PRIORITY, ignore priority.
  1719. (should
  1720. (equal "H"
  1721. (org-test-with-temp-text "* [#A] H"
  1722. (org-get-heading nil nil t))))
  1723. (should
  1724. (equal "H"
  1725. (org-test-with-temp-text "* H"
  1726. (org-get-heading nil nil t))))
  1727. (should
  1728. (equal "TODO H"
  1729. (org-test-with-temp-text "* TODO [#A] H"
  1730. (org-get-heading nil nil t))))
  1731. ;; With NO-COMMENT, ignore COMMENT keyword.
  1732. (should
  1733. (equal "H"
  1734. (org-test-with-temp-text "* COMMENT H"
  1735. (org-get-heading nil nil nil t))))
  1736. (should
  1737. (equal "H"
  1738. (org-test-with-temp-text "* H"
  1739. (org-get-heading nil nil nil t))))
  1740. (should
  1741. (equal "TODO [#A] H"
  1742. (org-test-with-temp-text "* TODO [#A] COMMENT H"
  1743. (org-get-heading nil nil nil t))))
  1744. ;; On an empty headline, return value is consistent.
  1745. (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
  1746. (should (equal "" (org-test-with-temp-text "* " (org-get-heading t))))
  1747. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t))))
  1748. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t))))
  1749. (should
  1750. (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t)))))
  1751. (ert-deftest test-org/in-commented-heading-p ()
  1752. "Test `org-in-commented-heading-p' specifications."
  1753. ;; Commented headline.
  1754. (should
  1755. (org-test-with-temp-text "* COMMENT Headline\nBody"
  1756. (goto-char (point-max))
  1757. (org-in-commented-heading-p)))
  1758. ;; Commented ancestor.
  1759. (should
  1760. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  1761. (goto-char (point-max))
  1762. (org-in-commented-heading-p)))
  1763. ;; Comment keyword is case-sensitive.
  1764. (should-not
  1765. (org-test-with-temp-text "* Comment Headline\nBody"
  1766. (goto-char (point-max))
  1767. (org-in-commented-heading-p)))
  1768. ;; Keyword is standalone.
  1769. (should-not
  1770. (org-test-with-temp-text "* COMMENTHeadline\nBody"
  1771. (goto-char (point-max))
  1772. (org-in-commented-heading-p)))
  1773. ;; Optional argument.
  1774. (should-not
  1775. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  1776. (goto-char (point-max))
  1777. (org-in-commented-heading-p t))))
  1778. (ert-deftest test-org/entry-blocked-p ()
  1779. ;; Check other dependencies.
  1780. (should
  1781. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  1782. (let ((org-enforce-todo-dependencies t)
  1783. (org-blocker-hook
  1784. '(org-block-todo-from-children-or-siblings-or-parent)))
  1785. (org-entry-blocked-p))))
  1786. (should-not
  1787. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  1788. (let ((org-enforce-todo-dependencies t)
  1789. (org-blocker-hook
  1790. '(org-block-todo-from-children-or-siblings-or-parent)))
  1791. (org-entry-blocked-p))))
  1792. ;; Entry without a TODO keyword or with a DONE keyword cannot be
  1793. ;; blocked.
  1794. (should-not
  1795. (org-test-with-temp-text "* Blocked\n** TODO one"
  1796. (let ((org-enforce-todo-dependencies t)
  1797. (org-blocker-hook
  1798. '(org-block-todo-from-children-or-siblings-or-parent)))
  1799. (org-entry-blocked-p))))
  1800. (should-not
  1801. (org-test-with-temp-text "* DONE Blocked\n** TODO one"
  1802. (let ((org-enforce-todo-dependencies t)
  1803. (org-blocker-hook
  1804. '(org-block-todo-from-children-or-siblings-or-parent)))
  1805. (org-entry-blocked-p))))
  1806. ;; Follow :ORDERED: specifications.
  1807. (should
  1808. (org-test-with-temp-text
  1809. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
  1810. (let ((org-enforce-todo-dependencies t)
  1811. (org-blocker-hook
  1812. '(org-block-todo-from-children-or-siblings-or-parent)))
  1813. (org-entry-blocked-p))))
  1814. (should-not
  1815. (org-test-with-temp-text
  1816. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
  1817. (let ((org-enforce-todo-dependencies t)
  1818. (org-blocker-hook
  1819. '(org-block-todo-from-children-or-siblings-or-parent)))
  1820. (org-entry-blocked-p)))))
  1821. (ert-deftest test-org/get-outline-path ()
  1822. "Test `org-get-outline-path' specifications."
  1823. ;; Top-level headlines have no outline path.
  1824. (should-not
  1825. (org-test-with-temp-text "* H"
  1826. (org-get-outline-path)))
  1827. ;; Otherwise, outline path is the path leading to the headline.
  1828. (should
  1829. (equal '("H")
  1830. (org-test-with-temp-text "* H\n** S<point>"
  1831. (org-get-outline-path))))
  1832. ;; Find path even when point is not on a headline.
  1833. (should
  1834. (equal '("H")
  1835. (org-test-with-temp-text "* H\n** S\nText<point>"
  1836. (org-get-outline-path))))
  1837. ;; TODO keywords, tags and statistics cookies are ignored.
  1838. (should
  1839. (equal '("H")
  1840. (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
  1841. (org-get-outline-path))))
  1842. ;; Links are replaced with their description or their path.
  1843. (should
  1844. (equal '("Org")
  1845. (org-test-with-temp-text
  1846. "* [[https://orgmode.org][Org]]\n** S<point>"
  1847. (org-get-outline-path))))
  1848. (should
  1849. (equal '("https://orgmode.org")
  1850. (org-test-with-temp-text
  1851. "* [[https://orgmode.org]]\n** S<point>"
  1852. (org-get-outline-path))))
  1853. ;; When WITH-SELF is non-nil, include current heading.
  1854. (should
  1855. (equal '("H")
  1856. (org-test-with-temp-text "* H"
  1857. (org-get-outline-path t))))
  1858. (should
  1859. (equal '("H" "S")
  1860. (org-test-with-temp-text "* H\n** S\nText<point>"
  1861. (org-get-outline-path t))))
  1862. ;; Using cache is transparent to the user.
  1863. (should
  1864. (equal '("H")
  1865. (org-test-with-temp-text "* H\n** S<point>"
  1866. (setq org-outline-path-cache nil)
  1867. (org-get-outline-path nil t))))
  1868. ;; Do not corrupt cache when finding outline path in distant part of
  1869. ;; the buffer.
  1870. (should
  1871. (equal '("H2")
  1872. (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
  1873. (setq org-outline-path-cache nil)
  1874. (org-get-outline-path nil t)
  1875. (search-forward "S2")
  1876. (org-get-outline-path nil t))))
  1877. ;; Do not choke on empty headlines.
  1878. (should
  1879. (org-test-with-temp-text "* H\n** <point>"
  1880. (org-get-outline-path)))
  1881. (should
  1882. (org-test-with-temp-text "* \n** H<point>"
  1883. (org-get-outline-path))))
  1884. (ert-deftest test-org/format-outline-path ()
  1885. "Test `org-format-outline-path' specifications."
  1886. (should
  1887. (string= (org-format-outline-path (list "one" "two" "three"))
  1888. "one/two/three"))
  1889. ;; Empty path.
  1890. (should
  1891. (string= (org-format-outline-path '())
  1892. ""))
  1893. (should
  1894. (string= (org-format-outline-path '(nil))
  1895. ""))
  1896. ;; Empty path and prefix.
  1897. (should
  1898. (string= (org-format-outline-path '() nil ">>")
  1899. ">>"))
  1900. ;; Trailing whitespace in headings.
  1901. (should
  1902. (string= (org-format-outline-path (list "one\t" "tw o " "three "))
  1903. "one/tw o/three"))
  1904. ;; Non-default prefix and separators.
  1905. (should
  1906. (string= (org-format-outline-path (list "one" "two" "three") nil ">>" "|")
  1907. ">>|one|two|three"))
  1908. ;; Truncate.
  1909. (should
  1910. (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
  1911. "one/two/.."))
  1912. ;; Give a very narrow width.
  1913. (should
  1914. (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
  1915. "on"))
  1916. ;; Give a prefix that extends beyond the width.
  1917. (should
  1918. (string= (org-format-outline-path (list "one" "two" "three" "four") 10
  1919. ">>>>>>>>>>")
  1920. ">>>>>>>>..")))
  1921. (ert-deftest test-org/map-entries ()
  1922. "Test `org-map-entries' specifications."
  1923. ;; Full match.
  1924. (should
  1925. (equal '(1 11)
  1926. (org-test-with-temp-text "* Level 1\n** Level 2"
  1927. (org-map-entries #'point))))
  1928. ;; Level match.
  1929. (should
  1930. (equal '(1)
  1931. (org-test-with-temp-text "* Level 1\n** Level 2"
  1932. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL=1")))))
  1933. (should
  1934. (equal '(11)
  1935. (org-test-with-temp-text "* Level 1\n** Level 2"
  1936. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL>1")))))
  1937. ;; Tag match.
  1938. (should
  1939. (equal '(11)
  1940. (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
  1941. (org-map-entries #'point "yes"))))
  1942. (should
  1943. (equal '(14)
  1944. (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
  1945. (org-map-entries #'point "+yes-a"))))
  1946. (should
  1947. (equal '(11 23)
  1948. (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
  1949. (org-map-entries #'point "{yes?}"))))
  1950. ;; Priority match.
  1951. (should
  1952. (equal '(1)
  1953. (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
  1954. (org-map-entries #'point "PRIORITY=\"A\""))))
  1955. ;; Date match.
  1956. (should
  1957. (equal '(36)
  1958. (org-test-with-temp-text "
  1959. * H1
  1960. SCHEDULED: <2012-03-29 thu.>
  1961. * H2
  1962. SCHEDULED: <2014-03-04 tue.>"
  1963. (org-map-entries #'point "SCHEDULED=\"<2014-03-04 tue.>\""))))
  1964. (should
  1965. (equal '(2)
  1966. (org-test-with-temp-text "
  1967. * H1
  1968. SCHEDULED: <2012-03-29 thu.>
  1969. * H2
  1970. SCHEDULED: <2014-03-04 tue.>"
  1971. (org-map-entries #'point "SCHEDULED<\"<2013-01-01>\""))))
  1972. ;; Regular property match.
  1973. (should
  1974. (equal '(2)
  1975. (org-test-with-temp-text "
  1976. * H1
  1977. :PROPERTIES:
  1978. :TEST: 1
  1979. :END:
  1980. * H2
  1981. :PROPERTIES:
  1982. :TEST: 2
  1983. :END:"
  1984. (org-map-entries #'point "TEST=1"))))
  1985. ;; Multiple criteria.
  1986. (should
  1987. (equal '(23)
  1988. (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
  1989. (let (org-odd-levels-only
  1990. (org-use-tag-inheritance nil))
  1991. (org-map-entries #'point "yes+LEVEL=1")))))
  1992. ;; "or" criteria.
  1993. (should
  1994. (equal '(12 24)
  1995. (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
  1996. (let (org-odd-levels-only)
  1997. (org-map-entries #'point "LEVEL=2|no")))))
  1998. (should
  1999. (equal '(1 12)
  2000. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
  2001. (let (org-odd-levels-only)
  2002. (org-map-entries #'point "yes|no")))))
  2003. ;; "and" criteria.
  2004. (should
  2005. (equal '(22)
  2006. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
  2007. (let (org-odd-levels-only)
  2008. (org-map-entries #'point "yes&no"))))))
  2009. (ert-deftest test-org/edit-headline ()
  2010. "Test `org-edit-headline' specifications."
  2011. (should
  2012. (equal "* B"
  2013. (org-test-with-temp-text "* A"
  2014. (org-edit-headline "B")
  2015. (buffer-string))))
  2016. ;; Handle empty headings.
  2017. (should
  2018. (equal "* "
  2019. (org-test-with-temp-text "* A"
  2020. (org-edit-headline "")
  2021. (buffer-string))))
  2022. (should
  2023. (equal "* A"
  2024. (org-test-with-temp-text "* "
  2025. (org-edit-headline "A")
  2026. (buffer-string))))
  2027. ;; Handle TODO keywords and priority cookies.
  2028. (should
  2029. (equal "* TODO B"
  2030. (org-test-with-temp-text "* TODO A"
  2031. (org-edit-headline "B")
  2032. (buffer-string))))
  2033. (should
  2034. (equal "* [#A] B"
  2035. (org-test-with-temp-text "* [#A] A"
  2036. (org-edit-headline "B")
  2037. (buffer-string))))
  2038. (should
  2039. (equal "* TODO [#A] B"
  2040. (org-test-with-temp-text "* TODO [#A] A"
  2041. (org-edit-headline "B")
  2042. (buffer-string))))
  2043. ;; Handle tags.
  2044. (equal "* B :tag:"
  2045. (org-test-with-temp-text "* A :tag:"
  2046. (let ((org-tags-column 4)) (org-edit-headline "B"))
  2047. (buffer-string))))
  2048. ;;; Keywords
  2049. (ert-deftest test-org/set-regexps-and-options ()
  2050. "Test `org-set-regexps-and-options' specifications."
  2051. ;; TAGS keyword.
  2052. (should
  2053. (equal '(("A"))
  2054. (let ((org-tag-alist '(("A")))
  2055. (org-tag-persistent-alist nil))
  2056. (org-test-with-temp-text ""
  2057. (org-mode-restart)
  2058. org-current-tag-alist))))
  2059. (should
  2060. (equal '(("B"))
  2061. (let ((org-tag-alist '(("A")))
  2062. (org-tag-persistent-alist nil))
  2063. (org-test-with-temp-text "#+TAGS: B"
  2064. (org-mode-restart)
  2065. org-current-tag-alist))))
  2066. (should
  2067. (equal '(("C") ("B"))
  2068. (let ((org-tag-alist '(("A")))
  2069. (org-tag-persistent-alist '(("C"))))
  2070. (org-test-with-temp-text "#+TAGS: B"
  2071. (org-mode-restart)
  2072. org-current-tag-alist))))
  2073. (should
  2074. (equal '(("B"))
  2075. (let ((org-tag-alist '(("A")))
  2076. (org-tag-persistent-alist '(("C"))))
  2077. (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
  2078. (org-mode-restart)
  2079. org-current-tag-alist))))
  2080. (should
  2081. (equal '(("A" . ?a) ("B") ("C"))
  2082. (let ((org-tag-persistant-alist nil))
  2083. (org-test-with-temp-text "#+TAGS: A(a) B C"
  2084. (org-mode-restart)
  2085. org-current-tag-alist))))
  2086. (should
  2087. (equal '(("A") (:newline) ("B"))
  2088. (let ((org-tag-persistent-alist nil))
  2089. (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
  2090. (org-mode-restart)
  2091. org-current-tag-alist))))
  2092. (should
  2093. (equal '((:startgroup) ("A") ("B") (:endgroup) ("C"))
  2094. (let ((org-tag-persistent-alist nil))
  2095. (org-test-with-temp-text "#+TAGS: { A B } C"
  2096. (org-mode-restart)
  2097. org-current-tag-alist))))
  2098. (should
  2099. (equal '((:startgroup) ("A") (:grouptags) ("B") ("C") (:endgroup))
  2100. (let ((org-tag-persistent-alist nil))
  2101. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2102. (org-mode-restart)
  2103. org-current-tag-alist))))
  2104. (should
  2105. (equal '(("A" "B" "C"))
  2106. (let ((org-tag-persistent-alist nil))
  2107. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2108. (org-mode-restart)
  2109. org-tag-groups-alist))))
  2110. (should
  2111. (equal '((:startgrouptag) ("A") (:grouptags) ("B") ("C") (:endgrouptag))
  2112. (let ((org-tag-persistent-alist nil))
  2113. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2114. (org-mode-restart)
  2115. org-current-tag-alist))))
  2116. (should
  2117. (equal '(("A" "B" "C"))
  2118. (let ((org-tag-persistent-alist nil))
  2119. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2120. (org-mode-restart)
  2121. org-tag-groups-alist))))
  2122. ;; FILETAGS keyword.
  2123. (should
  2124. (equal '("A" "B" "C")
  2125. (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
  2126. (org-mode-restart)
  2127. org-file-tags)))
  2128. ;; PROPERTY keyword. Property names are case-insensitive.
  2129. (should
  2130. (equal "foo=1"
  2131. (org-test-with-temp-text "#+PROPERTY: var foo=1"
  2132. (org-mode-restart)
  2133. (cdr (assoc "var" org-file-properties)))))
  2134. (should
  2135. (equal
  2136. "foo=1 bar=2"
  2137. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
  2138. (org-mode-restart)
  2139. (cdr (assoc "var" org-file-properties)))))
  2140. (should
  2141. (equal
  2142. "foo=1 bar=2"
  2143. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
  2144. (org-mode-restart)
  2145. (cdr (assoc "var" org-file-properties)))))
  2146. ;; ARCHIVE keyword.
  2147. (should
  2148. (equal "%s_done::"
  2149. (org-test-with-temp-text "#+ARCHIVE: %s_done::"
  2150. (org-mode-restart)
  2151. org-archive-location)))
  2152. ;; CATEGORY keyword.
  2153. (should
  2154. (eq 'test
  2155. (org-test-with-temp-text "#+CATEGORY: test"
  2156. (org-mode-restart)
  2157. org-category)))
  2158. (should
  2159. (equal "test"
  2160. (org-test-with-temp-text "#+CATEGORY: test"
  2161. (org-mode-restart)
  2162. (cdr (assoc "CATEGORY" org-file-properties)))))
  2163. ;; COLUMNS keyword.
  2164. (should
  2165. (equal "%25ITEM %TAGS %PRIORITY %TODO"
  2166. (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
  2167. (org-mode-restart)
  2168. org-columns-default-format)))
  2169. ;; CONSTANTS keyword. Constants names are case sensitive.
  2170. (should
  2171. (equal '("299792458." "3.14")
  2172. (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
  2173. (org-mode-restart)
  2174. (mapcar
  2175. (lambda (n) (cdr (assoc n org-table-formula-constants-local)))
  2176. '("c" "pi")))))
  2177. (should
  2178. (equal "3.14"
  2179. (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
  2180. (org-mode-restart)
  2181. (cdr (assoc "pi" org-table-formula-constants-local)))))
  2182. (should
  2183. (equal "22/7"
  2184. (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
  2185. (org-mode-restart)
  2186. (cdr (assoc "PI" org-table-formula-constants-local)))))
  2187. ;; LINK keyword.
  2188. (should
  2189. (equal
  2190. '("url1" "url2")
  2191. (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
  2192. (org-mode-restart)
  2193. (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local)))
  2194. '("a" "b")))))
  2195. ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
  2196. (should
  2197. (equal
  2198. '(?X ?Z ?Y)
  2199. (org-test-with-temp-text "#+PRIORITIES: X Z Y"
  2200. (org-mode-restart)
  2201. (list org-highest-priority org-lowest-priority org-default-priority))))
  2202. (should
  2203. (equal
  2204. '(?A ?C ?B)
  2205. (org-test-with-temp-text "#+PRIORITIES: X Z"
  2206. (org-mode-restart)
  2207. (list org-highest-priority org-lowest-priority org-default-priority))))
  2208. ;; STARTUP keyword.
  2209. (should
  2210. (equal '(t t)
  2211. (org-test-with-temp-text "#+STARTUP: fold odd"
  2212. (org-mode-restart)
  2213. (list org-startup-folded org-odd-levels-only))))
  2214. ;; TODO keywords.
  2215. (should
  2216. (equal '(("A" "B") ("C"))
  2217. (org-test-with-temp-text "#+TODO: A B | C"
  2218. (org-mode-restart)
  2219. (list org-not-done-keywords org-done-keywords))))
  2220. (should
  2221. (equal '(("A" "C") ("B" "D"))
  2222. (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
  2223. (org-mode-restart)
  2224. (list org-not-done-keywords org-done-keywords))))
  2225. (should
  2226. (equal '(("A" "B") ("C"))
  2227. (org-test-with-temp-text "#+TYP_TODO: A B | C"
  2228. (org-mode-restart)
  2229. (list org-not-done-keywords org-done-keywords))))
  2230. (should
  2231. (equal '((:startgroup) ("A" . ?a) (:endgroup))
  2232. (org-test-with-temp-text "#+TODO: A(a)"
  2233. (org-mode-restart)
  2234. org-todo-key-alist)))
  2235. (should
  2236. (equal '(("D" note nil) ("C" time nil) ("B" note time))
  2237. (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
  2238. (org-mode-restart)
  2239. org-todo-log-states)))
  2240. ;; Enter SETUPFILE keyword.
  2241. (should
  2242. (equal "1"
  2243. (org-test-with-temp-text
  2244. (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
  2245. (org-mode-restart)
  2246. (cdr (assoc "a" org-file-properties))))))
  2247. ;;; Links
  2248. ;;;; Coderefs
  2249. (ert-deftest test-org/coderef ()
  2250. "Test coderef links specifications."
  2251. (should
  2252. (org-test-with-temp-text "
  2253. #+BEGIN_SRC emacs-lisp
  2254. \(+ 1 1) (ref:sc)
  2255. #+END_SRC
  2256. \[[(sc)<point>]]"
  2257. (org-open-at-point)
  2258. (looking-at "(ref:sc)")))
  2259. ;; Find coderef even with alternate label format.
  2260. (should
  2261. (org-test-with-temp-text "
  2262. #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
  2263. \(+ 1 1) {ref:sc}
  2264. #+END_SRC
  2265. \[[(sc)<point>]]"
  2266. (org-open-at-point)
  2267. (looking-at "{ref:sc}"))))
  2268. ;;;; Custom ID
  2269. (ert-deftest test-org/custom-id ()
  2270. "Test custom ID links specifications."
  2271. (should
  2272. (org-test-with-temp-text
  2273. "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2274. (org-open-at-point)
  2275. (looking-at-p "\\* H1")))
  2276. ;; Throw an error on false positives.
  2277. (should-error
  2278. (org-test-with-temp-text
  2279. "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2280. (org-open-at-point)
  2281. (looking-at-p "\\* H1"))))
  2282. ;;;; Fuzzy Links
  2283. ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
  2284. ;; a named element (#+name: text) and to headlines (* Text).
  2285. (ert-deftest test-org/fuzzy-links ()
  2286. "Test fuzzy links specifications."
  2287. ;; Fuzzy link goes in priority to a matching target.
  2288. (should
  2289. (org-test-with-temp-text
  2290. "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
  2291. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2292. (looking-at "<<Test>>")))
  2293. ;; Then fuzzy link points to an element with a given name.
  2294. (should
  2295. (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
  2296. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2297. (looking-at "#\\+NAME: Test")))
  2298. ;; A target still lead to a matching headline otherwise.
  2299. (should
  2300. (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
  2301. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2302. (looking-at "\\* Head2")))
  2303. ;; With a leading star in link, enforce heading match.
  2304. (should
  2305. (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
  2306. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2307. (looking-at "\\* Test")))
  2308. ;; With a leading star in link, enforce exact heading match, even
  2309. ;; with `org-link-search-must-match-exact-headline' set to nil.
  2310. (should-error
  2311. (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
  2312. (let ((org-link-search-must-match-exact-headline nil))
  2313. (org-open-at-point))))
  2314. ;; Handle non-nil `org-link-search-must-match-exact-headline'.
  2315. (should
  2316. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
  2317. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2318. (looking-at "\\* Test")))
  2319. (should
  2320. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
  2321. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2322. (looking-at "\\* Test")))
  2323. ;; Heading match should not care about spaces, cookies, TODO
  2324. ;; keywords, priorities, and tags. However, TODO keywords are
  2325. ;; case-sensitive.
  2326. (should
  2327. (let ((first-line
  2328. "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
  2329. (org-test-with-temp-text
  2330. (concat first-line "\nFoo Bar\n<point>[[*Test 1 2]]")
  2331. (let ((org-link-search-must-match-exact-headline nil)
  2332. (org-todo-regexp "TODO"))
  2333. (org-open-at-point))
  2334. (looking-at (regexp-quote first-line)))))
  2335. (should-error
  2336. (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
  2337. (let ((org-link-search-must-match-exact-headline nil)
  2338. (org-todo-regexp "TODO"))
  2339. (org-open-at-point))))
  2340. ;; Heading match should still be exact.
  2341. (should-error
  2342. (org-test-with-temp-text "
  2343. ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
  2344. Foo Bar
  2345. <point>[[*Test 1]]"
  2346. (let ((org-link-search-must-match-exact-headline nil)
  2347. (org-todo-regexp "TODO"))
  2348. (org-open-at-point))))
  2349. (should
  2350. (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
  2351. (let ((org-link-search-must-match-exact-headline nil)
  2352. (org-todo-regexp "TODO"))
  2353. (org-open-at-point))
  2354. (looking-at-p (regexp-quote "** Test 1 2"))))
  2355. ;; Heading match ignores COMMENT keyword.
  2356. (should
  2357. (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
  2358. (org-open-at-point)
  2359. (looking-at "\\* COMMENT Test")))
  2360. (should
  2361. (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
  2362. (org-open-at-point)
  2363. (looking-at "\\* TODO COMMENT Test")))
  2364. ;; Correctly un-hexify fuzzy links.
  2365. (should
  2366. (org-test-with-temp-text "* With space\n[[*With%20space][With space<point>]]"
  2367. (org-open-at-point)
  2368. (bobp)))
  2369. (should
  2370. (org-test-with-temp-text "* [1]\n[[*%5B1%5D<point>]]"
  2371. (org-open-at-point)
  2372. (bobp)))
  2373. ;; Match search strings containing newline characters, including
  2374. ;; blank lines.
  2375. (should
  2376. (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
  2377. (let ((file (buffer-file-name)))
  2378. (goto-char (point-max))
  2379. (insert (format "[[file:%s::line1 line2]]" file))
  2380. (beginning-of-line)
  2381. (let ((org-link-search-must-match-exact-headline nil))
  2382. (org-open-at-point 0))
  2383. (looking-at-p "line1"))))
  2384. (should
  2385. (org-test-with-temp-text-in-file "Paragraph\n\nline1\n\nline2\n\n"
  2386. (let ((file (buffer-file-name)))
  2387. (goto-char (point-max))
  2388. (insert (format "[[file:%s::line1 line2]]" file))
  2389. (beginning-of-line)
  2390. (let ((org-link-search-must-match-exact-headline nil))
  2391. (org-open-at-point 0))
  2392. (looking-at-p "line1")))))
  2393. ;;;; Link Escaping
  2394. (ert-deftest test-org/org-link-escape-ascii-character ()
  2395. "Escape an ascii character."
  2396. (should
  2397. (string=
  2398. "%5B"
  2399. (org-link-escape "["))))
  2400. (ert-deftest test-org/org-link-escape-ascii-ctrl-character ()
  2401. "Escape an ascii control character."
  2402. (should
  2403. (string=
  2404. "%09"
  2405. (org-link-escape "\t"))))
  2406. (ert-deftest test-org/org-link-escape-multibyte-character ()
  2407. "Escape an unicode multibyte character."
  2408. (should
  2409. (string=
  2410. "%E2%82%AC"
  2411. (org-link-escape "€"))))
  2412. (ert-deftest test-org/org-link-escape-custom-table ()
  2413. "Escape string with custom character table."
  2414. (should
  2415. (string=
  2416. "Foo%3A%42ar%0A"
  2417. (org-link-escape "Foo:Bar\n" '(?\: ?\B)))))
  2418. (ert-deftest test-org/org-link-escape-custom-table-merge ()
  2419. "Escape string with custom table merged with default table."
  2420. (should
  2421. (string=
  2422. "%5BF%6F%6F%3A%42ar%0A%5D"
  2423. (org-link-escape "[Foo:Bar\n]" '(?\: ?\B ?\o) t))))
  2424. (ert-deftest test-org/org-link-unescape-ascii-character ()
  2425. "Unescape an ascii character."
  2426. (should
  2427. (string=
  2428. "["
  2429. (org-link-unescape "%5B"))))
  2430. (ert-deftest test-org/org-link-unescape-ascii-ctrl-character ()
  2431. "Unescpae an ascii control character."
  2432. (should
  2433. (string=
  2434. "\n"
  2435. (org-link-unescape "%0A"))))
  2436. (ert-deftest test-org/org-link-unescape-multibyte-character ()
  2437. "Unescape unicode multibyte character."
  2438. (should
  2439. (string=
  2440. "€"
  2441. (org-link-unescape "%E2%82%AC"))))
  2442. (ert-deftest test-org/org-link-unescape-ascii-extended-char ()
  2443. "Unescape old style percent escaped character."
  2444. (should
  2445. (string=
  2446. "àâçèéêîôùû"
  2447. (decode-coding-string
  2448. (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1))))
  2449. (ert-deftest test-org/org-link-escape-url-with-escaped-char ()
  2450. "Escape and unescape a URL that includes an escaped char.
  2451. http://article.gmane.org/gmane.emacs.orgmode/21459/"
  2452. (should
  2453. (string=
  2454. "http://some.host.com/form?&id=blah%2Bblah25"
  2455. (org-link-unescape
  2456. (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
  2457. ;;;; Open at point
  2458. (ert-deftest test-org/open-at-point/keyword ()
  2459. "Does `org-open-at-point' open link in a keyword line?"
  2460. (should
  2461. (org-test-with-temp-text
  2462. "<<top>>\n#+KEYWORD: <point>[[top]]"
  2463. (org-open-at-point) t))
  2464. (should
  2465. (org-test-with-temp-text
  2466. "* H\n<<top>>\n#+KEYWORD: <point>[[top]]"
  2467. (org-open-at-point) t)))
  2468. (ert-deftest test-org/open-at-point/property ()
  2469. "Does `org-open-at-point' open link in property drawer?"
  2470. (should
  2471. (org-test-with-temp-text
  2472. "* Headline
  2473. :PROPERTIES:
  2474. :URL: <point>[[*Headline]]
  2475. :END:"
  2476. (org-open-at-point) t)))
  2477. (ert-deftest test-org/open-at-point/comment ()
  2478. "Does `org-open-at-point' open link in a commented line?"
  2479. (should
  2480. (org-test-with-temp-text
  2481. "<<top>>\n# <point>[[top]]"
  2482. (org-open-at-point) t))
  2483. (should
  2484. (org-test-with-temp-text
  2485. "* H\n<<top>>\n# <point>[[top]]"
  2486. (org-open-at-point) t)))
  2487. (ert-deftest test-org/open-at-point/inline-image ()
  2488. "Test `org-open-at-point' on nested links."
  2489. (should
  2490. (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
  2491. (org-open-at-point)
  2492. (bobp))))
  2493. (ert-deftest test-org/open-at-point/radio-target ()
  2494. "Test `org-open-at-point' on radio targets."
  2495. (should
  2496. (org-test-with-temp-text "<<<target>>> <point>target"
  2497. (org-update-radio-target-regexp)
  2498. (org-open-at-point)
  2499. (eq (org-element-type (org-element-context)) 'radio-target))))
  2500. (ert-deftest test-org/open-at-point/tag ()
  2501. "Test `org-open-at-point' on tags."
  2502. (should
  2503. (org-test-with-temp-text "* H :<point>tag:"
  2504. (catch :result
  2505. (cl-letf (((symbol-function 'org-tags-view)
  2506. (lambda (&rest args) (throw :result t))))
  2507. (org-open-at-point)
  2508. nil))))
  2509. (should-not
  2510. (org-test-with-temp-text-in-file "* H<point> :tag:"
  2511. (catch :result
  2512. (cl-letf (((symbol-function 'org-tags-view)
  2513. (lambda (&rest args) (throw :result t))))
  2514. (org-open-at-point)
  2515. nil)))))
  2516. ;;;; Stored links
  2517. (ert-deftest test-org/store-link ()
  2518. "Test `org-store-link' specifications."
  2519. ;; On a headline, link to that headline. Use heading as the
  2520. ;; description of the link.
  2521. (should
  2522. (let (org-store-link-props org-stored-links)
  2523. (org-test-with-temp-text-in-file "* H1"
  2524. (let ((file (buffer-file-name)))
  2525. (equal (format "[[file:%s::*H1][H1]]" file)
  2526. (org-store-link nil))))))
  2527. ;; On a headline, remove any link from description.
  2528. (should
  2529. (let (org-store-link-props org-stored-links)
  2530. (org-test-with-temp-text-in-file "* [[#l][d]]"
  2531. (let ((file (buffer-file-name)))
  2532. (equal (format "[[file:%s::*%s][d]]"
  2533. file
  2534. (org-link-escape "[[#l][d]]"))
  2535. (org-store-link nil))))))
  2536. (should
  2537. (let (org-store-link-props org-stored-links)
  2538. (org-test-with-temp-text-in-file "* [[l]]"
  2539. (let ((file (buffer-file-name)))
  2540. (equal (format "[[file:%s::*%s][l]]" file (org-link-escape "[[l]]"))
  2541. (org-store-link nil))))))
  2542. (should
  2543. (let (org-store-link-props org-stored-links)
  2544. (org-test-with-temp-text-in-file "* [[l1][d1]] [[l2][d2]]"
  2545. (let ((file (buffer-file-name)))
  2546. (equal (format "[[file:%s::*%s][d1 d2]]"
  2547. file
  2548. (org-link-escape "[[l1][d1]] [[l2][d2]]"))
  2549. (org-store-link nil))))))
  2550. ;; On a named element, link to that element.
  2551. (should
  2552. (let (org-store-link-props org-stored-links)
  2553. (org-test-with-temp-text-in-file "#+NAME: foo\nParagraph"
  2554. (let ((file (buffer-file-name)))
  2555. (equal (format "[[file:%s::foo][foo]]" file)
  2556. (org-store-link nil))))))
  2557. ;; Store link to Org buffer, with context.
  2558. (should
  2559. (let ((org-stored-links nil)
  2560. (org-id-link-to-org-use-id nil)
  2561. (org-context-in-file-links t))
  2562. (org-test-with-temp-text-in-file "* h1"
  2563. (let ((file (buffer-file-name)))
  2564. (equal (format "[[file:%s::*h1][h1]]" file)
  2565. (org-store-link nil))))))
  2566. ;; Store link to Org buffer, without context.
  2567. (should
  2568. (let ((org-stored-links nil)
  2569. (org-id-link-to-org-use-id nil)
  2570. (org-context-in-file-links nil))
  2571. (org-test-with-temp-text-in-file "* h1"
  2572. (let ((file (buffer-file-name)))
  2573. (equal (format "[[file:%s][file:%s]]" file file)
  2574. (org-store-link nil))))))
  2575. ;; C-u prefix reverses `org-context-in-file-links' in Org buffer.
  2576. (should
  2577. (let ((org-stored-links nil)
  2578. (org-id-link-to-org-use-id nil)
  2579. (org-context-in-file-links nil))
  2580. (org-test-with-temp-text-in-file "* h1"
  2581. (let ((file (buffer-file-name)))
  2582. (equal (format "[[file:%s::*h1][h1]]" file)
  2583. (org-store-link '(4)))))))
  2584. ;; A C-u C-u does *not* reverse `org-context-in-file-links' in Org
  2585. ;; buffer.
  2586. (should
  2587. (let ((org-stored-links nil)
  2588. (org-id-link-to-org-use-id nil)
  2589. (org-context-in-file-links nil))
  2590. (org-test-with-temp-text-in-file "* h1"
  2591. (let ((file (buffer-file-name)))
  2592. (equal (format "[[file:%s][file:%s]]" file file)
  2593. (org-store-link '(16)))))))
  2594. ;; Store file link to non-Org buffer, with context.
  2595. (should
  2596. (let ((org-stored-links nil)
  2597. (org-context-in-file-links t))
  2598. (org-test-with-temp-text-in-file "one\n<point>two"
  2599. (fundamental-mode)
  2600. (let ((file (buffer-file-name)))
  2601. (equal (format "[[file:%s::one]]" file)
  2602. (org-store-link nil))))))
  2603. ;; Store file link to non-Org buffer, without context.
  2604. (should
  2605. (let ((org-stored-links nil)
  2606. (org-context-in-file-links nil))
  2607. (org-test-with-temp-text-in-file "one\n<point>two"
  2608. (fundamental-mode)
  2609. (let ((file (buffer-file-name)))
  2610. (equal (format "[[file:%s][file:%s]]" file file)
  2611. (org-store-link nil))))))
  2612. ;; C-u prefix reverses `org-context-in-file-links' in non-Org
  2613. ;; buffer.
  2614. (should
  2615. (let ((org-stored-links nil)
  2616. (org-context-in-file-links nil))
  2617. (org-test-with-temp-text-in-file "one\n<point>two"
  2618. (fundamental-mode)
  2619. (let ((file (buffer-file-name)))
  2620. (equal (format "[[file:%s::one]]" file)
  2621. (org-store-link '(4)))))))
  2622. ;; A C-u C-u does *not* reverse `org-context-in-file-links' in
  2623. ;; non-Org buffer.
  2624. (should
  2625. (let ((org-stored-links nil)
  2626. (org-context-in-file-links nil))
  2627. (org-test-with-temp-text-in-file "one\n<point>two"
  2628. (fundamental-mode)
  2629. (let ((file (buffer-file-name)))
  2630. (equal (format "[[file:%s][file:%s]]" file file)
  2631. (org-store-link '(16))))))))
  2632. ;;; Node Properties
  2633. (ert-deftest test-org/accumulated-properties-in-drawers ()
  2634. "Ensure properties accumulate in subtree drawers."
  2635. (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
  2636. (org-babel-next-src-block)
  2637. (should (equal '(2 1) (org-babel-execute-src-block)))))
  2638. (ert-deftest test-org/custom-properties ()
  2639. "Test custom properties specifications."
  2640. ;; Standard test.
  2641. (should
  2642. (let ((org-custom-properties '("FOO")))
  2643. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2644. (org-toggle-custom-properties-visibility)
  2645. (org-invisible-p2))))
  2646. ;; Properties are case-insensitive.
  2647. (should
  2648. (let ((org-custom-properties '("FOO")))
  2649. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
  2650. (org-toggle-custom-properties-visibility)
  2651. (org-invisible-p2))))
  2652. (should
  2653. (let ((org-custom-properties '("foo")))
  2654. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2655. (org-toggle-custom-properties-visibility)
  2656. (org-invisible-p2))))
  2657. ;; Multiple custom properties in the same drawer.
  2658. (should
  2659. (let ((org-custom-properties '("FOO" "BAR")))
  2660. (org-test-with-temp-text
  2661. "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
  2662. (org-toggle-custom-properties-visibility)
  2663. (and (org-invisible-p2)
  2664. (not (progn (forward-line) (org-invisible-p2)))
  2665. (progn (forward-line) (org-invisible-p2))))))
  2666. ;; Hide custom properties with an empty value.
  2667. (should
  2668. (let ((org-custom-properties '("FOO")))
  2669. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
  2670. (org-toggle-custom-properties-visibility)
  2671. (org-invisible-p2))))
  2672. ;; Do not hide fake properties.
  2673. (should-not
  2674. (let ((org-custom-properties '("FOO")))
  2675. (org-test-with-temp-text ":FOO: val\n"
  2676. (org-toggle-custom-properties-visibility)
  2677. (org-invisible-p2))))
  2678. (should-not
  2679. (let ((org-custom-properties '("A")))
  2680. (org-test-with-temp-text
  2681. "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
  2682. (org-toggle-custom-properties-visibility)
  2683. (org-invisible-p2)))))
  2684. ;;; Mark Region
  2685. (ert-deftest test-org/mark-subtree ()
  2686. "Test `org-mark-subtree' specifications."
  2687. ;; Error when point is before first headline.
  2688. (should-error
  2689. (org-test-with-temp-text "Paragraph\n* Headline\nBody"
  2690. (progn (transient-mark-mode 1)
  2691. (org-mark-subtree))))
  2692. ;; Without argument, mark current subtree.
  2693. (should
  2694. (equal
  2695. '(12 32)
  2696. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  2697. (progn (transient-mark-mode 1)
  2698. (forward-line 2)
  2699. (org-mark-subtree)
  2700. (list (region-beginning) (region-end))))))
  2701. ;; With an argument, move ARG up.
  2702. (should
  2703. (equal
  2704. '(1 32)
  2705. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  2706. (progn (transient-mark-mode 1)
  2707. (forward-line 2)
  2708. (org-mark-subtree 1)
  2709. (list (region-beginning) (region-end))))))
  2710. ;; Do not get fooled by inlinetasks.
  2711. (when (featurep 'org-inlinetask)
  2712. (should
  2713. (= 1
  2714. (org-test-with-temp-text "* Headline\n*************** Task\nContents"
  2715. (progn (transient-mark-mode 1)
  2716. (forward-line 1)
  2717. (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
  2718. (region-beginning)))))))
  2719. ;;; Miscellaneous
  2720. (ert-deftest test-org/sort-entries ()
  2721. "Test `org-sort-entries'."
  2722. ;; Sort alphabetically.
  2723. (should
  2724. (equal "\n* abc\n* def\n* xyz\n"
  2725. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  2726. (org-sort-entries nil ?a)
  2727. (buffer-string))))
  2728. (should
  2729. (equal "\n* xyz\n* def\n* abc\n"
  2730. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  2731. (org-sort-entries nil ?A)
  2732. (buffer-string))))
  2733. (should
  2734. (equal "\n* \n* klm\n* xyz\n"
  2735. (org-test-with-temp-text "\n* xyz\n* \n* klm\n"
  2736. (org-sort-entries nil ?a)
  2737. (buffer-string))))
  2738. ;; Sort numerically.
  2739. (should
  2740. (equal "\n* 1\n* 2\n* 10\n"
  2741. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  2742. (org-sort-entries nil ?n)
  2743. (buffer-string))))
  2744. (should
  2745. (equal "\n* 10\n* 2\n* 1\n"
  2746. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  2747. (org-sort-entries nil ?N)
  2748. (buffer-string))))
  2749. (should
  2750. (equal "\n* \n* 1\n* 2\n"
  2751. (org-test-with-temp-text "\n* 1\n* \n* 2\n"
  2752. (org-sort-entries nil ?n)
  2753. (buffer-string))))
  2754. ;; Sort by custom function.
  2755. (should
  2756. (equal "\n* b\n* aa\n* ccc\n"
  2757. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  2758. (org-sort-entries nil ?f
  2759. (lambda ()
  2760. (length (buffer-substring (point-at-bol)
  2761. (point-at-eol))))
  2762. #'<)
  2763. (buffer-string))))
  2764. (should
  2765. (equal "\n* ccc\n* aa\n* b\n"
  2766. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  2767. (org-sort-entries nil ?F
  2768. (lambda ()
  2769. (length (buffer-substring (point-at-bol)
  2770. (point-at-eol))))
  2771. #'<)
  2772. (buffer-string))))
  2773. ;; Sort by TODO keyword.
  2774. (should
  2775. (equal "\n* TODO h1\n* TODO h3\n* DONE h2\n"
  2776. (org-test-with-temp-text
  2777. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  2778. (org-sort-entries nil ?o)
  2779. (buffer-string))))
  2780. (should
  2781. (equal "\n* DONE h2\n* TODO h1\n* TODO h3\n"
  2782. (org-test-with-temp-text
  2783. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  2784. (org-sort-entries nil ?O)
  2785. (buffer-string))))
  2786. ;; Sort by priority.
  2787. (should
  2788. (equal "\n* [#A] h2\n* [#B] h3\n* [#C] h1\n"
  2789. (org-test-with-temp-text
  2790. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  2791. (org-sort-entries nil ?p)
  2792. (buffer-string))))
  2793. (should
  2794. (equal "\n* [#C] h1\n* [#B] h3\n* [#A] h2\n"
  2795. (org-test-with-temp-text
  2796. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  2797. (org-sort-entries nil ?P)
  2798. (buffer-string))))
  2799. ;; Sort by creation time.
  2800. (should
  2801. (equal "
  2802. * h3
  2803. [2017-05-08 Mon]
  2804. * h2
  2805. [2017-05-09 Tue]
  2806. * h1
  2807. [2018-05-09 Wed]
  2808. "
  2809. (org-test-with-temp-text
  2810. "
  2811. * h1
  2812. [2018-05-09 Wed]
  2813. * h2
  2814. [2017-05-09 Tue]
  2815. * h3
  2816. [2017-05-08 Mon]
  2817. "
  2818. (org-sort-entries nil ?c)
  2819. (buffer-string))))
  2820. ;; Sort by scheduled date.
  2821. (should
  2822. (equal "
  2823. * TODO h4
  2824. SCHEDULED: <2017-05-06 Sat>
  2825. * TODO h3
  2826. SCHEDULED: <2017-05-08 Mon>
  2827. * TODO h2
  2828. DEADLINE: <2017-05-09 Tue>
  2829. * TODO h1
  2830. DEADLINE: <2017-05-07 Sun>
  2831. "
  2832. (org-test-with-temp-text
  2833. "
  2834. * TODO h2
  2835. DEADLINE: <2017-05-09 Tue>
  2836. * TODO h1
  2837. DEADLINE: <2017-05-07 Sun>
  2838. * TODO h3
  2839. SCHEDULED: <2017-05-08 Mon>
  2840. * TODO h4
  2841. SCHEDULED: <2017-05-06 Sat>
  2842. "
  2843. (org-sort-entries nil ?s)
  2844. (buffer-string))))
  2845. ;; Sort by deadline date.
  2846. (should
  2847. (equal "
  2848. * TODO h1
  2849. DEADLINE: <2017-05-07 Sun>
  2850. * TODO h2
  2851. DEADLINE: <2017-05-09 Tue>
  2852. * TODO h3
  2853. SCHEDULED: <2017-05-08 Mon>
  2854. * TODO h4
  2855. SCHEDULED: <2017-05-06 Sat>
  2856. "
  2857. (org-test-with-temp-text
  2858. "
  2859. * TODO h2
  2860. DEADLINE: <2017-05-09 Tue>
  2861. * TODO h1
  2862. DEADLINE: <2017-05-07 Sun>
  2863. * TODO h3
  2864. SCHEDULED: <2017-05-08 Mon>
  2865. * TODO h4
  2866. SCHEDULED: <2017-05-06 Sat>
  2867. "
  2868. (org-sort-entries nil ?d)
  2869. (buffer-string))))
  2870. ;; Sort by any date/time
  2871. (should
  2872. (equal "
  2873. * TODO h4
  2874. SCHEDULED: <2017-05-06 Sat>
  2875. * TODO h1
  2876. DEADLINE: <2017-05-07 Sun>
  2877. * TODO h3
  2878. SCHEDULED: <2017-05-08 Mon>
  2879. * TODO h2
  2880. DEADLINE: <2017-05-09 Tue>
  2881. "
  2882. (org-test-with-temp-text
  2883. "
  2884. * TODO h2
  2885. DEADLINE: <2017-05-09 Tue>
  2886. * TODO h1
  2887. DEADLINE: <2017-05-07 Sun>
  2888. * TODO h3
  2889. SCHEDULED: <2017-05-08 Mon>
  2890. * TODO h4
  2891. SCHEDULED: <2017-05-06 Sat>
  2892. "
  2893. (org-sort-entries nil ?t)
  2894. (buffer-string))))
  2895. ;; Sort by clocking time.
  2896. (should
  2897. (equal "
  2898. * clocked h2
  2899. :LOGBOOK:
  2900. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  2901. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  2902. :END:
  2903. * clocked h1
  2904. :LOGBOOK:
  2905. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  2906. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  2907. :END:
  2908. "
  2909. (org-test-with-temp-text
  2910. "
  2911. * clocked h1
  2912. :LOGBOOK:
  2913. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  2914. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  2915. :END:
  2916. * clocked h2
  2917. :LOGBOOK:
  2918. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  2919. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  2920. :END:
  2921. "
  2922. (org-sort-entries nil ?k)
  2923. (buffer-string))))
  2924. ;; Preserve file local variables when sorting.
  2925. (should
  2926. (equal "\n* A\n* B\n# Local Variables:\n# foo: t\n# End:\n"
  2927. (org-test-with-temp-text
  2928. "\n* B\n* A\n# Local Variables:\n# foo: t\n# End:"
  2929. (org-sort-entries nil ?a)
  2930. (buffer-string)))))
  2931. (ert-deftest test-org/string-collate-greaterp ()
  2932. "Test `org-string-collate-greaterp' specifications."
  2933. (should (org-string-collate-greaterp "def" "abc"))
  2934. (should-not (org-string-collate-greaterp "abc" "def")))
  2935. (ert-deftest test-org/file-contents ()
  2936. "Test `org-file-contents' specifications."
  2937. ;; Open files.
  2938. (should
  2939. (string= "#+BIND: variable value
  2940. #+DESCRIPTION: l2
  2941. #+LANGUAGE: en
  2942. #+SELECT_TAGS: b
  2943. #+TITLE: b
  2944. #+PROPERTY: a 1
  2945. " (org-file-contents (expand-file-name "setupfile3.org"
  2946. (concat org-test-dir "examples/")))))
  2947. ;; Throw error when trying to access an invalid file.
  2948. (should-error (org-file-contents "this-file-must-not-exist"))
  2949. ;; Try to access an invalid file, but do not throw an error.
  2950. (should
  2951. (progn (org-file-contents "this-file-must-not-exist" :noerror) t))
  2952. ;; Open URL.
  2953. (should
  2954. (string= "foo"
  2955. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  2956. (unwind-protect
  2957. ;; Simulate successful retrieval of a URL.
  2958. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  2959. (lambda (&rest_)
  2960. (with-current-buffer buffer
  2961. (insert "HTTP/1.1 200 OK\n\nfoo"))
  2962. buffer)))
  2963. (org-file-contents "http://some-valid-url"))
  2964. (kill-buffer buffer)))))
  2965. ;; Throw error when trying to access an invalid URL.
  2966. (should-error
  2967. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  2968. (unwind-protect
  2969. ;; Simulate unsuccessful retrieval of a URL.
  2970. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  2971. (lambda (&rest_)
  2972. (with-current-buffer buffer
  2973. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  2974. buffer)))
  2975. (org-file-contents "http://this-url-must-not-exist"))
  2976. (kill-buffer buffer))))
  2977. ;; Try to access an invalid URL, but do not throw an error.
  2978. (should-error
  2979. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  2980. (unwind-protect
  2981. ;; Simulate unsuccessful retrieval of a URL.
  2982. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  2983. (lambda (&rest_)
  2984. (with-current-buffer buffer
  2985. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  2986. buffer)))
  2987. (org-file-contents "http://this-url-must-not-exist"))
  2988. (kill-buffer buffer))))
  2989. (should
  2990. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  2991. (unwind-protect
  2992. ;; Simulate unsuccessful retrieval of a URL.
  2993. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  2994. (lambda (&rest_)
  2995. (with-current-buffer buffer
  2996. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  2997. buffer)))
  2998. (org-file-contents "http://this-url-must-not-exist" :noerror))
  2999. (kill-buffer buffer))
  3000. t)))
  3001. ;;; Navigation
  3002. (ert-deftest test-org/forward-heading-same-level ()
  3003. "Test `org-forward-heading-same-level' specifications."
  3004. ;; Test navigation at top level, forward and backward.
  3005. (should
  3006. (equal "* H2"
  3007. (org-test-with-temp-text "* H1\n* H2"
  3008. (org-forward-heading-same-level 1)
  3009. (buffer-substring-no-properties (point) (line-end-position)))))
  3010. (should
  3011. (equal "* H1"
  3012. (org-test-with-temp-text "* H1\n<point>* H2"
  3013. (org-forward-heading-same-level -1)
  3014. (buffer-substring-no-properties (point) (line-end-position)))))
  3015. ;; Test navigation in a sub-tree, forward and backward.
  3016. (should
  3017. (equal "* H2"
  3018. (org-test-with-temp-text "* H1\n** H11\n** H12\n* H2"
  3019. (org-forward-heading-same-level 1)
  3020. (buffer-substring-no-properties (point) (line-end-position)))))
  3021. (should
  3022. (equal "* H1"
  3023. (org-test-with-temp-text "* H1\n** H11\n** H12\n<point>* H2"
  3024. (org-forward-heading-same-level -1)
  3025. (buffer-substring-no-properties (point) (line-end-position)))))
  3026. ;; Stop at first or last sub-heading.
  3027. (should-not
  3028. (equal "* H2"
  3029. (org-test-with-temp-text "* H1\n** H11\n<point>** H12\n* H2"
  3030. (org-forward-heading-same-level 1)
  3031. (buffer-substring-no-properties (point) (line-end-position)))))
  3032. (should-not
  3033. (equal "* H2"
  3034. (org-test-with-temp-text "* H1\n<point>** H11\n** H12\n* H2"
  3035. (org-forward-heading-same-level -1)
  3036. (buffer-substring-no-properties (point) (line-end-position)))))
  3037. ;; Allow multiple moves.
  3038. (should
  3039. (equal "* H3"
  3040. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3041. (org-forward-heading-same-level 2)
  3042. (buffer-substring-no-properties (point) (line-end-position)))))
  3043. (should
  3044. (equal "* H1"
  3045. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3046. (org-forward-heading-same-level -2)
  3047. (buffer-substring-no-properties (point) (line-end-position)))))
  3048. ;; Ignore spurious moves when first (or last) sibling is reached.
  3049. (should
  3050. (equal "** H3"
  3051. (org-test-with-temp-text "* First\n<point>** H1\n** H2\n** H3\n* Last"
  3052. (org-forward-heading-same-level 100)
  3053. (buffer-substring-no-properties (point) (line-end-position)))))
  3054. (should
  3055. (equal "** H1"
  3056. (org-test-with-temp-text "* First\n** H1\n** H2\n<point>** H3\n* Last"
  3057. (org-forward-heading-same-level -100)
  3058. (buffer-substring-no-properties (point) (line-end-position))))))
  3059. (ert-deftest test-org/end-of-meta-data ()
  3060. "Test `org-end-of-meta-data' specifications."
  3061. ;; Skip planning line.
  3062. (should
  3063. (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
  3064. (org-end-of-meta-data)
  3065. (eobp)))
  3066. ;; Skip properties drawer.
  3067. (should
  3068. (org-test-with-temp-text
  3069. "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
  3070. (org-end-of-meta-data)
  3071. (eobp)))
  3072. ;; Skip both.
  3073. (should
  3074. (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
  3075. (org-end-of-meta-data)
  3076. (eobp)))
  3077. ;; Nothing to skip, go to first line.
  3078. (should
  3079. (org-test-with-temp-text "* Headline\nContents"
  3080. (org-end-of-meta-data)
  3081. (looking-at "Contents")))
  3082. ;; With option argument, skip empty lines, regular drawers and
  3083. ;; clocking lines.
  3084. (should
  3085. (org-test-with-temp-text "* Headline\n\nContents"
  3086. (org-end-of-meta-data t)
  3087. (looking-at "Contents")))
  3088. (should
  3089. (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
  3090. (org-end-of-meta-data t)
  3091. (looking-at "Contents")))
  3092. (should
  3093. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
  3094. (org-end-of-meta-data t)
  3095. (looking-at "Contents")))
  3096. ;; Special case: do not skip incomplete drawers.
  3097. (should
  3098. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
  3099. (org-end-of-meta-data t)
  3100. (looking-at ":LOGBOOK:")))
  3101. ;; Special case: Be careful about consecutive headlines.
  3102. (should-not
  3103. (org-test-with-temp-text "* H1\n*H2\nContents"
  3104. (org-end-of-meta-data t)
  3105. (looking-at "Contents"))))
  3106. (ert-deftest test-org/beginning-of-line ()
  3107. "Test `org-beginning-of-line' specifications."
  3108. ;; Move to beginning of line. If current line in invisible, move to
  3109. ;; beginning of visible line instead.
  3110. (should
  3111. (org-test-with-temp-text "Some text\nSome other text<point>"
  3112. (org-beginning-of-line)
  3113. (bolp)))
  3114. (should
  3115. (org-test-with-temp-text "* H1\n** H2<point>"
  3116. (org-overview)
  3117. (org-beginning-of-line)
  3118. (= (line-beginning-position) 1)))
  3119. ;; With `visual-line-mode' active, move to beginning of visual line.
  3120. (should-not
  3121. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3122. (visual-line-mode)
  3123. (dotimes (i 1000) (insert "very "))
  3124. (org-beginning-of-line)
  3125. (bolp)))
  3126. ;; In a wide headline, with `visual-line-mode', prefer going to the
  3127. ;; beginning of a visual line than to the logical beginning of line,
  3128. ;; even if special movement is active.
  3129. (should-not
  3130. (org-test-with-temp-text "* A <point>long headline"
  3131. (visual-line-mode)
  3132. (dotimes (i 1000) (insert "very "))
  3133. (goto-char (point-max))
  3134. (org-beginning-of-line)
  3135. (bobp)))
  3136. (should-not
  3137. (org-test-with-temp-text "* A <point>long headline"
  3138. (visual-line-mode)
  3139. (dotimes (i 1000) (insert "very "))
  3140. (goto-char (point-max))
  3141. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line))
  3142. (bobp)))
  3143. ;; At an headline with special movement, first move at beginning of
  3144. ;; title, then at the beginning of line, rinse, repeat.
  3145. (should
  3146. (org-test-with-temp-text "* TODO Headline<point>"
  3147. (let ((org-special-ctrl-a/e t))
  3148. (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
  3149. (progn (org-beginning-of-line) (bolp))
  3150. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3151. (should
  3152. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3153. (let ((org-special-ctrl-a/e t))
  3154. (org-beginning-of-line)
  3155. (looking-at "Headline"))))
  3156. (should
  3157. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3158. (let ((org-special-ctrl-a/e '(t . nil)))
  3159. (org-beginning-of-line)
  3160. (looking-at "Headline"))))
  3161. (should-not
  3162. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3163. (let ((org-special-ctrl-a/e '(nil . nil)))
  3164. (org-beginning-of-line)
  3165. (looking-at "Headline"))))
  3166. ;; At an headline with reversed movement, first move to beginning of
  3167. ;; line, then to the beginning of title.
  3168. (should
  3169. (org-test-with-temp-text "* TODO Headline<point>"
  3170. (let ((org-special-ctrl-a/e 'reversed)
  3171. (this-command last-command))
  3172. (and (progn (org-beginning-of-line) (bolp))
  3173. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3174. (should
  3175. (org-test-with-temp-text "* TODO Headline<point>"
  3176. (let ((org-special-ctrl-a/e '(reversed . nil))
  3177. (this-command last-command))
  3178. (and (progn (org-beginning-of-line) (bolp))
  3179. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3180. (should-not
  3181. (org-test-with-temp-text "* TODO Headline<point>"
  3182. (let ((org-special-ctrl-a/e '(t . nil))
  3183. (this-command last-command))
  3184. (and (progn (org-beginning-of-line) (bolp))
  3185. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3186. ;; At an item with special movement, first move after to beginning
  3187. ;; of title, then to the beginning of line, rinse, repeat.
  3188. (should
  3189. (org-test-with-temp-text "- [ ] Item<point>"
  3190. (let ((org-special-ctrl-a/e t))
  3191. (and (progn (org-beginning-of-line) (looking-at-p "Item"))
  3192. (progn (org-beginning-of-line) (bolp))
  3193. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3194. ;; At an item with reversed movement, first move to beginning of
  3195. ;; line, then to the beginning of title.
  3196. (should
  3197. (org-test-with-temp-text "- [X] Item<point>"
  3198. (let ((org-special-ctrl-a/e 'reversed)
  3199. (this-command last-command))
  3200. (and (progn (org-beginning-of-line) (bolp))
  3201. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3202. ;; Leave point before invisible characters at column 0.
  3203. (should
  3204. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3205. (let ((org-special-ctrl-a/e nil))
  3206. (org-beginning-of-line)
  3207. (bolp))))
  3208. (should
  3209. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3210. (let ((org-special-ctrl-a/e t))
  3211. (org-beginning-of-line)
  3212. (bolp))))
  3213. (should
  3214. (org-test-with-temp-text "[[http<point>://orgmode.org]]"
  3215. (visual-line-mode)
  3216. (org-beginning-of-line)
  3217. (bolp)))
  3218. ;; Special case: Do not error when the buffer contains only a single
  3219. ;; asterisk.
  3220. (should
  3221. (org-test-with-temp-text "*<point>"
  3222. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line) t)))
  3223. (should
  3224. (org-test-with-temp-text "*<point>"
  3225. (let ((org-special-ctrl-a/e nil)) (org-beginning-of-line) t))))
  3226. (ert-deftest test-org/end-of-line ()
  3227. "Test `org-end-of-line' specifications."
  3228. ;; Standard test.
  3229. (should
  3230. (org-test-with-temp-text "Some text\nSome other text"
  3231. (org-end-of-line)
  3232. (eolp)))
  3233. ;; With `visual-line-mode' active, move to end of visible line.
  3234. ;; However, never go past ellipsis.
  3235. (should-not
  3236. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3237. (visual-line-mode)
  3238. (dotimes (i 1000) (insert "very "))
  3239. (goto-char (point-min))
  3240. (org-end-of-line)
  3241. (eolp)))
  3242. (should-not
  3243. (org-test-with-temp-text "* A short headline\nSome contents"
  3244. (visual-line-mode)
  3245. (org-overview)
  3246. (org-end-of-line)
  3247. (eobp)))
  3248. ;; In a wide headline, with `visual-line-mode', prefer going to end
  3249. ;; of visible line if tags, or end of line, are farther.
  3250. (should-not
  3251. (org-test-with-temp-text "* A <point>long headline"
  3252. (visual-line-mode)
  3253. (dotimes (i 1000) (insert "very "))
  3254. (goto-char (point-min))
  3255. (org-end-of-line)
  3256. (eolp)))
  3257. (should-not
  3258. (org-test-with-temp-text "* A <point>long headline :tag:"
  3259. (visual-line-mode)
  3260. (dotimes (i 1000) (insert "very "))
  3261. (goto-char (point-min))
  3262. (org-end-of-line)
  3263. (eolp)))
  3264. ;; At an headline without special movement, go to end of line.
  3265. ;; However, never go past ellipsis.
  3266. (should
  3267. (org-test-with-temp-text "* Headline2b :tag:\n"
  3268. (let ((org-special-ctrl-a/e nil))
  3269. (and (progn (org-end-of-line) (eolp))
  3270. (progn (org-end-of-line) (eolp))))))
  3271. (should
  3272. (org-test-with-temp-text "* Headline2b :tag:\n"
  3273. (let ((org-special-ctrl-a/e '(t . nil)))
  3274. (and (progn (org-end-of-line) (eolp))
  3275. (progn (org-end-of-line) (eolp))))))
  3276. (should
  3277. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3278. (org-overview)
  3279. (let ((org-special-ctrl-a/e nil))
  3280. (org-end-of-line)
  3281. (= 1 (line-beginning-position)))))
  3282. ;; At an headline with special movement, first move before tags,
  3283. ;; then at the end of line, rinse, repeat. However, never go past
  3284. ;; ellipsis.
  3285. (should
  3286. (org-test-with-temp-text "* Headline1 :tag:\n"
  3287. (let ((org-special-ctrl-a/e t))
  3288. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3289. (progn (org-end-of-line) (eolp))
  3290. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3291. (should
  3292. (org-test-with-temp-text "* Headline1 :tag:\n"
  3293. (let ((org-special-ctrl-a/e '(nil . t)))
  3294. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3295. (progn (org-end-of-line) (eolp))
  3296. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3297. (should-not
  3298. (org-test-with-temp-text "* Headline1 :tag:\n"
  3299. (let ((org-special-ctrl-a/e '(nil . nil)))
  3300. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3301. (progn (org-end-of-line) (eolp))
  3302. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3303. (should
  3304. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3305. (org-overview)
  3306. (let ((org-special-ctrl-a/e t))
  3307. (org-end-of-line)
  3308. (org-end-of-line)
  3309. (= 1 (line-beginning-position)))))
  3310. ;; At an headline, with reversed movement, first go to end of line,
  3311. ;; then before tags. However, never go past ellipsis.
  3312. (should
  3313. (org-test-with-temp-text "* Headline3 :tag:\n"
  3314. (let ((org-special-ctrl-a/e 'reversed)
  3315. (this-command last-command))
  3316. (and (progn (org-end-of-line) (eolp))
  3317. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3318. (should
  3319. (org-test-with-temp-text "* Headline3 :tag:\n"
  3320. (let ((org-special-ctrl-a/e '(nil . reversed))
  3321. (this-command last-command))
  3322. (and (progn (org-end-of-line) (eolp))
  3323. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3324. (should-not
  3325. (org-test-with-temp-text "* Headline3 :tag:\n"
  3326. (let ((org-special-ctrl-a/e '(nil . t))
  3327. (this-command last-command))
  3328. (and (progn (org-end-of-line) (eolp))
  3329. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3330. (should
  3331. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3332. (org-overview)
  3333. (let ((org-special-ctrl-a/e 'reversed))
  3334. (org-end-of-line)
  3335. (= 1 (line-beginning-position)))))
  3336. ;; At a block without hidden contents.
  3337. (should
  3338. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3339. (progn (org-end-of-line) (eolp))))
  3340. ;; At a block with hidden contents.
  3341. (should-not
  3342. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3343. (let ((org-special-ctrl-a/e t))
  3344. (org-hide-block-toggle)
  3345. (org-end-of-line)
  3346. (eobp))))
  3347. ;; Get past invisible characters at the end of line.
  3348. (should
  3349. (org-test-with-temp-text "[[https://orgmode.org]]"
  3350. (org-end-of-line)
  3351. (eolp))))
  3352. (ert-deftest test-org/open-line ()
  3353. "Test `org-open-line' specifications."
  3354. ;; Call `open-line' outside of tables.
  3355. (should
  3356. (equal "\nText"
  3357. (org-test-with-temp-text "Text"
  3358. (org-open-line 1)
  3359. (buffer-string))))
  3360. ;; At a table, create a row above.
  3361. (should
  3362. (equal "\n| |\n| a |"
  3363. (org-test-with-temp-text "\n<point>| a |"
  3364. (org-open-line 1)
  3365. (buffer-string))))
  3366. ;; At the very first character of the buffer, also call `open-line'.
  3367. (should
  3368. (equal "\n| a |"
  3369. (org-test-with-temp-text "| a |"
  3370. (org-open-line 1)
  3371. (buffer-string))))
  3372. ;; Narrowing does not count.
  3373. (should
  3374. (equal "Text\n| |\n| a |"
  3375. (org-test-with-temp-text "Text\n<point>| a |"
  3376. (narrow-to-region (point) (point-max))
  3377. (org-open-line 1)
  3378. (widen)
  3379. (buffer-string)))))
  3380. (ert-deftest test-org/forward-sentence ()
  3381. "Test `org-forward-sentence' specifications."
  3382. ;; At the end of a table cell, move to the end of the next one.
  3383. (should
  3384. (org-test-with-temp-text "| a<point> | b |"
  3385. (org-forward-sentence)
  3386. (looking-at " |$")))
  3387. ;; Elsewhere in a cell, move to its end.
  3388. (should
  3389. (org-test-with-temp-text "| a<point>c | b |"
  3390. (org-forward-sentence)
  3391. (looking-at " | b |$")))
  3392. ;; Otherwise, simply call `forward-sentence'.
  3393. (should
  3394. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3395. (org-forward-sentence)
  3396. (looking-at " Sentence 2.")))
  3397. (should
  3398. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3399. (org-forward-sentence)
  3400. (org-forward-sentence)
  3401. (eobp)))
  3402. ;; At the end of an element, jump to the next one, without stopping
  3403. ;; on blank lines in-between.
  3404. (should
  3405. (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
  3406. (org-forward-sentence)
  3407. (eobp)))
  3408. ;; Headlines are considered to be sentences by themselves, even if
  3409. ;; they do not end with a full stop.
  3410. (should
  3411. (equal
  3412. "* Headline"
  3413. (org-test-with-temp-text "* <point>Headline\nSentence."
  3414. (org-forward-sentence)
  3415. (buffer-substring-no-properties (line-beginning-position) (point)))))
  3416. (should
  3417. (org-test-with-temp-text "* Headline<point>\nSentence."
  3418. (org-forward-sentence)
  3419. (eobp)))
  3420. (should
  3421. (org-test-with-temp-text "Sentence.<point>\n\n* Headline\n\nSentence 2."
  3422. (org-forward-sentence)
  3423. (and (org-at-heading-p) (eolp)))))
  3424. (ert-deftest test-org/backward-sentence ()
  3425. "Test `org-backward-sentence' specifications."
  3426. ;; At the beginning of a table cell, move to the beginning of the
  3427. ;; previous one.
  3428. (should
  3429. (org-test-with-temp-text "| a | <point>b |"
  3430. (org-backward-sentence)
  3431. (looking-at "a | b |$")))
  3432. ;; Elsewhere in a cell, move to its beginning.
  3433. (should
  3434. (org-test-with-temp-text "| a | b<point>c |"
  3435. (org-backward-sentence)
  3436. (looking-at "bc |$")))
  3437. ;; Otherwise, simply call `backward-sentence'.
  3438. (should
  3439. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3440. (org-backward-sentence)
  3441. (looking-at "Sentence 2.")))
  3442. (should
  3443. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3444. (org-backward-sentence)
  3445. (org-backward-sentence)
  3446. (bobp)))
  3447. ;; Make sure to hit the beginning of a sentence on the same line as
  3448. ;; an item.
  3449. (should
  3450. (org-test-with-temp-text "- Line 1\n line <point>2."
  3451. (org-backward-sentence)
  3452. (looking-at "Line 1"))))
  3453. (ert-deftest test-org/forward-paragraph ()
  3454. "Test `org-forward-paragraph' specifications."
  3455. ;; At end of buffer, do not return an error.
  3456. (should
  3457. (org-test-with-temp-text "Paragraph"
  3458. (goto-char (point-max))
  3459. (org-forward-paragraph)
  3460. t))
  3461. ;; Standard test.
  3462. (should
  3463. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  3464. (org-forward-paragraph)
  3465. (looking-at "P2")))
  3466. ;; Ignore depth.
  3467. (should
  3468. (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n#+END_CENTER\nP2"
  3469. (org-forward-paragraph)
  3470. (looking-at "P1")))
  3471. ;; Do not enter elements with invisible contents.
  3472. (should
  3473. (org-test-with-temp-text "#+BEGIN_CENTER\nP1\n\nP2\n#+END_CENTER\nP3"
  3474. (org-hide-block-toggle)
  3475. (org-forward-paragraph)
  3476. (looking-at "P3")))
  3477. ;; On an affiliated keyword, jump to the beginning of the element.
  3478. (should
  3479. (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
  3480. (org-forward-paragraph)
  3481. (looking-at "Para")))
  3482. ;; On an item or a footnote definition, move to the second element
  3483. ;; inside, if any.
  3484. (should
  3485. (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
  3486. (org-forward-paragraph)
  3487. (looking-at " Paragraph")))
  3488. (should
  3489. (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
  3490. (org-forward-paragraph)
  3491. (looking-at "Paragraph")))
  3492. ;; On an item, or a footnote definition, when the first line is
  3493. ;; empty, move to the first item.
  3494. (should
  3495. (org-test-with-temp-text "- \n\n Paragraph\n- Item2"
  3496. (org-forward-paragraph)
  3497. (looking-at " Paragraph")))
  3498. (should
  3499. (org-test-with-temp-text "[fn:1]\n\nParagraph\n\n[fn:2] Def2"
  3500. (org-forward-paragraph)
  3501. (looking-at "Paragraph")))
  3502. ;; On a table (resp. a property drawer) do not move through table
  3503. ;; rows (resp. node properties).
  3504. (should
  3505. (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
  3506. (org-forward-paragraph)
  3507. (looking-at "Paragraph")))
  3508. (should
  3509. (org-test-with-temp-text
  3510. "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
  3511. (org-forward-paragraph)
  3512. (looking-at "Paragraph")))
  3513. ;; On a verse or source block, stop after blank lines.
  3514. (should
  3515. (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n#+END_VERSE"
  3516. (org-forward-paragraph)
  3517. (looking-at "L2")))
  3518. (should
  3519. (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n#+END_SRC"
  3520. (org-forward-paragraph)
  3521. (looking-at "L2"))))
  3522. (ert-deftest test-org/backward-paragraph ()
  3523. "Test `org-backward-paragraph' specifications."
  3524. ;; Do not error at beginning of buffer.
  3525. (should
  3526. (org-test-with-temp-text "Paragraph"
  3527. (org-backward-paragraph)
  3528. t))
  3529. ;; Regular test.
  3530. (should
  3531. (org-test-with-temp-text "P1\n\nP2\n\nP3<point>"
  3532. (org-backward-paragraph)
  3533. (looking-at "P3")))
  3534. (should
  3535. (org-test-with-temp-text "P1\n\nP2\n\n<point>P3"
  3536. (org-backward-paragraph)
  3537. (looking-at-p "P2")))
  3538. ;; Ignore depth.
  3539. (should
  3540. (org-test-with-temp-text "P1\n\n#+BEGIN_CENTER\nP2\n#+END_CENTER\n<point>P3"
  3541. (org-backward-paragraph)
  3542. (looking-at-p "P2")))
  3543. ;; Ignore invisible elements.
  3544. (should
  3545. (org-test-with-temp-text "* H1\n P1\n* H2"
  3546. (org-cycle)
  3547. (goto-char (point-max))
  3548. (beginning-of-line)
  3549. (org-backward-paragraph)
  3550. (bobp)))
  3551. ;; On an affiliated keyword, jump to the first one.
  3552. (should
  3553. (org-test-with-temp-text
  3554. "P1\n#+name: n\n#+caption: c1\n#+caption: <point>c2\nP2"
  3555. (org-backward-paragraph)
  3556. (looking-at-p "#\\+name")))
  3557. ;; On the second element in an item or a footnote definition, jump
  3558. ;; to item or the definition.
  3559. (should
  3560. (org-test-with-temp-text "- line1\n\n<point> line2"
  3561. (org-backward-paragraph)
  3562. (looking-at-p "- line1")))
  3563. (should
  3564. (org-test-with-temp-text "[fn:1] line1\n\n<point> line2"
  3565. (org-backward-paragraph)
  3566. (looking-at-p "\\[fn:1\\] line1")))
  3567. ;; On a table (resp. a property drawer), ignore table rows
  3568. ;; (resp. node properties).
  3569. (should
  3570. (org-test-with-temp-text "| a | b |\n| c | d |\n<point>P1"
  3571. (org-backward-paragraph)
  3572. (bobp)))
  3573. (should
  3574. (org-test-with-temp-text "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
  3575. (org-backward-paragraph)
  3576. (looking-at-p ":PROPERTIES:")))
  3577. ;; On a comment, example, src and verse blocks, stop before blank
  3578. ;; lines.
  3579. (should
  3580. (org-test-with-temp-text "#+BEGIN_VERSE\nL1\n\nL2\n\n<point>L3\n#+END_VERSE"
  3581. (org-backward-paragraph)
  3582. (looking-at-p "L2")))
  3583. (should
  3584. (org-test-with-temp-text "#+BEGIN_SRC\nL1\n\nL2\n\n<point>L3#+END_SRC"
  3585. (org-backward-paragraph)
  3586. (looking-at-p "L2")))
  3587. ;; In comment, example, export, src and verse blocks, stop below
  3588. ;; opening line when called from within the block.
  3589. (should
  3590. (org-test-with-temp-text "#+BEGIN_VERSE\nL1\nL2<point>\n#+END_VERSE"
  3591. (org-backward-paragraph)
  3592. (looking-at-p "L1")))
  3593. (should
  3594. (org-test-with-temp-text "#+BEGIN_EXAMPLE\nL1\nL2<point>\n#+END_EXAMPLE"
  3595. (org-backward-paragraph)
  3596. (looking-at-p "L1")))
  3597. ;; When called from the opening line itself, however, move to
  3598. ;; beginning of block.
  3599. (should
  3600. (org-test-with-temp-text "#+BEGIN_<point>EXAMPLE\nL1\n#+END_EXAMPLE"
  3601. (org-backward-paragraph)
  3602. (bobp)))
  3603. ;; Pathological case: on an empty heading, move to its beginning.
  3604. (should
  3605. (org-test-with-temp-text "* <point>H"
  3606. (org-backward-paragraph)
  3607. (bobp))))
  3608. (ert-deftest test-org/forward-element ()
  3609. "Test `org-forward-element' specifications."
  3610. ;; 1. At EOB: should error.
  3611. (org-test-with-temp-text "Some text\n"
  3612. (goto-char (point-max))
  3613. (should-error (org-forward-element)))
  3614. ;; 2. Standard move: expected to ignore blank lines.
  3615. (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
  3616. (org-forward-element)
  3617. (should (looking-at (regexp-quote "Second paragraph."))))
  3618. ;; 3. Headline tests.
  3619. (org-test-with-temp-text "
  3620. * Head 1
  3621. ** Head 1.1
  3622. *** Head 1.1.1
  3623. ** Head 1.2"
  3624. ;; 3.1. At an headline beginning: move to next headline at the
  3625. ;; same level.
  3626. (goto-line 3)
  3627. (org-forward-element)
  3628. (should (looking-at (regexp-quote "** Head 1.2")))
  3629. ;; 3.2. At an headline beginning: move to parent headline if no
  3630. ;; headline at the same level.
  3631. (goto-line 3)
  3632. (org-forward-element)
  3633. (should (looking-at (regexp-quote "** Head 1.2"))))
  3634. ;; 4. Greater element tests.
  3635. (org-test-with-temp-text
  3636. "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
  3637. ;; 4.1. At a greater element: expected to skip contents.
  3638. (org-forward-element)
  3639. (should (looking-at (regexp-quote "Outside.")))
  3640. ;; 4.2. At the end of greater element contents: expected to skip
  3641. ;; to the end of the greater element.
  3642. (goto-line 2)
  3643. (org-forward-element)
  3644. (should (looking-at (regexp-quote "Outside."))))
  3645. ;; 5. List tests.
  3646. (org-test-with-temp-text "
  3647. - item1
  3648. - sub1
  3649. - sub2
  3650. - sub3
  3651. Inner paragraph.
  3652. - item2
  3653. Outside."
  3654. ;; 5.1. At list top point: expected to move to the element after
  3655. ;; the list.
  3656. (goto-line 2)
  3657. (org-forward-element)
  3658. (should (looking-at (regexp-quote "Outside.")))
  3659. ;; 5.2. Special case: at the first line of a sub-list, but not at
  3660. ;; beginning of line, move to next item.
  3661. (goto-line 2)
  3662. (forward-char)
  3663. (org-forward-element)
  3664. (should (looking-at "- item2"))
  3665. (goto-line 4)
  3666. (forward-char)
  3667. (org-forward-element)
  3668. (should (looking-at " - sub2"))
  3669. ;; 5.3 At sub-list beginning: expected to move after the sub-list.
  3670. (goto-line 4)
  3671. (org-forward-element)
  3672. (should (looking-at (regexp-quote " Inner paragraph.")))
  3673. ;; 5.4. At sub-list end: expected to move outside the sub-list.
  3674. (goto-line 8)
  3675. (org-forward-element)
  3676. (should (looking-at (regexp-quote " Inner paragraph.")))
  3677. ;; 5.5. At an item: expected to move to next item, if any.
  3678. (goto-line 6)
  3679. (org-forward-element)
  3680. (should (looking-at " - sub3"))))
  3681. (ert-deftest test-org/backward-element ()
  3682. "Test `org-backward-element' specifications."
  3683. ;; 1. Should error at BOB.
  3684. (org-test-with-temp-text " \nParagraph."
  3685. (should-error (org-backward-element)))
  3686. ;; 2. Should move at BOB when called on the first element in buffer.
  3687. (should
  3688. (org-test-with-temp-text "\n#+TITLE: test"
  3689. (progn (forward-line)
  3690. (org-backward-element)
  3691. (bobp))))
  3692. ;; 3. Not at the beginning of an element: move at its beginning.
  3693. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  3694. (goto-line 3)
  3695. (end-of-line)
  3696. (org-backward-element)
  3697. (should (looking-at (regexp-quote "Paragraph2."))))
  3698. ;; 4. Headline tests.
  3699. (org-test-with-temp-text "
  3700. * Head 1
  3701. ** Head 1.1
  3702. *** Head 1.1.1
  3703. ** Head 1.2"
  3704. ;; 4.1. At an headline beginning: move to previous headline at the
  3705. ;; same level.
  3706. (goto-line 5)
  3707. (org-backward-element)
  3708. (should (looking-at (regexp-quote "** Head 1.1")))
  3709. ;; 4.2. At an headline beginning: move to parent headline if no
  3710. ;; headline at the same level.
  3711. (goto-line 3)
  3712. (org-backward-element)
  3713. (should (looking-at (regexp-quote "* Head 1")))
  3714. ;; 4.3. At the first top-level headline: should error.
  3715. (goto-line 2)
  3716. (should-error (org-backward-element)))
  3717. ;; 5. At beginning of first element inside a greater element:
  3718. ;; expected to move to greater element's beginning.
  3719. (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
  3720. (goto-line 3)
  3721. (org-backward-element)
  3722. (should (looking-at "#\\+BEGIN_CENTER")))
  3723. ;; 6. At the beginning of the first element in a section: should
  3724. ;; move back to headline, if any.
  3725. (should
  3726. (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
  3727. (progn (goto-char (point-max))
  3728. (beginning-of-line)
  3729. (org-backward-element)
  3730. (org-at-heading-p))))
  3731. ;; 7. List tests.
  3732. (org-test-with-temp-text "
  3733. - item1
  3734. - sub1
  3735. - sub2
  3736. - sub3
  3737. Inner paragraph.
  3738. - item2
  3739. Outside."
  3740. ;; 7.1. At beginning of sub-list: expected to move to the
  3741. ;; paragraph before it.
  3742. (goto-line 4)
  3743. (org-backward-element)
  3744. (should (looking-at "item1"))
  3745. ;; 7.2. At an item in a list: expected to move at previous item.
  3746. (goto-line 8)
  3747. (org-backward-element)
  3748. (should (looking-at " - sub2"))
  3749. (goto-line 12)
  3750. (org-backward-element)
  3751. (should (looking-at "- item1"))
  3752. ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
  3753. ;; beginning.
  3754. (goto-line 10)
  3755. (org-backward-element)
  3756. (should (looking-at " - sub1"))
  3757. (goto-line 15)
  3758. (org-backward-element)
  3759. (should (looking-at "- item1"))
  3760. ;; 7.4. At blank-lines before list end: expected to move to top
  3761. ;; item.
  3762. (goto-line 14)
  3763. (org-backward-element)
  3764. (should (looking-at "- item1"))))
  3765. (ert-deftest test-org/up-element ()
  3766. "Test `org-up-element' specifications."
  3767. ;; 1. At BOB or with no surrounding element: should error.
  3768. (org-test-with-temp-text "Paragraph."
  3769. (should-error (org-up-element)))
  3770. (org-test-with-temp-text "* Head1\n* Head2"
  3771. (goto-line 2)
  3772. (should-error (org-up-element)))
  3773. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  3774. (goto-line 3)
  3775. (should-error (org-up-element)))
  3776. ;; 2. At an headline: move to parent headline.
  3777. (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
  3778. (goto-line 3)
  3779. (org-up-element)
  3780. (should (looking-at "\\* Head1")))
  3781. ;; 3. Inside a greater element: move to greater element beginning.
  3782. (org-test-with-temp-text
  3783. "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
  3784. (goto-line 3)
  3785. (org-up-element)
  3786. (should (looking-at "#\\+BEGIN_CENTER")))
  3787. ;; 4. List tests.
  3788. (org-test-with-temp-text "* Top
  3789. - item1
  3790. - sub1
  3791. - sub2
  3792. Paragraph within sub2.
  3793. - item2"
  3794. ;; 4.1. Within an item: move to the item beginning.
  3795. (goto-line 8)
  3796. (org-up-element)
  3797. (should (looking-at " - sub2"))
  3798. ;; 4.2. At an item in a sub-list: move to parent item.
  3799. (goto-line 4)
  3800. (org-up-element)
  3801. (should (looking-at "- item1"))
  3802. ;; 4.3. At an item in top list: move to beginning of whole list.
  3803. (goto-line 10)
  3804. (org-up-element)
  3805. (should (looking-at "- item1"))
  3806. ;; 4.4. Special case. At very top point: should move to parent of
  3807. ;; list.
  3808. (goto-line 2)
  3809. (org-up-element)
  3810. (should (looking-at "\\* Top"))))
  3811. (ert-deftest test-org/down-element ()
  3812. "Test `org-down-element' specifications."
  3813. ;; Error when the element hasn't got a recursive type.
  3814. (org-test-with-temp-text "Paragraph."
  3815. (should-error (org-down-element)))
  3816. ;; Error when the element has no contents
  3817. (org-test-with-temp-text "* Headline"
  3818. (should-error (org-down-element)))
  3819. ;; When at a plain-list, move to first item.
  3820. (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
  3821. (goto-line 2)
  3822. (org-down-element)
  3823. (should (looking-at " - Item 1.1")))
  3824. (org-test-with-temp-text "#+NAME: list\n- Item 1"
  3825. (org-down-element)
  3826. (should (looking-at " Item 1")))
  3827. ;; When at a table, move to first row
  3828. (org-test-with-temp-text "#+NAME: table\n| a | b |"
  3829. (org-down-element)
  3830. (should (looking-at " a | b |")))
  3831. ;; Otherwise, move inside the greater element.
  3832. (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
  3833. (org-down-element)
  3834. (should (looking-at "Paragraph"))))
  3835. (ert-deftest test-org/drag-element-backward ()
  3836. "Test `org-drag-element-backward' specifications."
  3837. ;; Standard test.
  3838. (should
  3839. (equal
  3840. "#+key2: val2\n#+key1: val1\n#+key3: val3"
  3841. (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
  3842. (org-drag-element-backward)
  3843. (buffer-string))))
  3844. (should
  3845. (equal
  3846. "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
  3847. (org-test-with-temp-text
  3848. "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
  3849. (org-drag-element-backward)
  3850. (buffer-string))))
  3851. ;; Preserve blank lines.
  3852. (should
  3853. (equal "Paragraph 2\n\n\nPara1\n\nPara3"
  3854. (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
  3855. (org-drag-element-backward)
  3856. (buffer-string))))
  3857. ;; Preserve column.
  3858. (should
  3859. (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
  3860. (org-drag-element-backward)
  3861. (looking-at-p "2")))
  3862. ;; Error when trying to move first element of buffer.
  3863. (should-error
  3864. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  3865. (org-drag-element-backward))
  3866. :type 'user-error)
  3867. ;; Error when trying to swap nested elements.
  3868. (should-error
  3869. (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
  3870. (org-drag-element-backward))
  3871. :type 'user-error)
  3872. ;; Error when trying to swap an headline element and a non-headline
  3873. ;; element.
  3874. (should-error
  3875. (org-test-with-temp-text "Test.\n<point>* Head 1"
  3876. (org-drag-element-backward))
  3877. :type 'error)
  3878. ;; Error when called before first element.
  3879. (should-error
  3880. (org-test-with-temp-text "\n<point>"
  3881. (org-drag-element-backward))
  3882. :type 'user-error)
  3883. ;; Preserve visibility of elements and their contents.
  3884. (should
  3885. (equal '((63 . 82) (26 . 48))
  3886. (org-test-with-temp-text "
  3887. #+BEGIN_CENTER
  3888. Text.
  3889. #+END_CENTER
  3890. - item 1
  3891. #+BEGIN_QUOTE
  3892. Text.
  3893. #+END_QUOTE"
  3894. (while (search-forward "BEGIN_" nil t) (org-cycle))
  3895. (search-backward "- item 1")
  3896. (org-drag-element-backward)
  3897. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  3898. (overlays-in (point-min) (point-max))))))
  3899. ;; Pathological case: handle call with point in blank lines right
  3900. ;; after a headline.
  3901. (should
  3902. (equal "* H2\n\n* H1\nText\n"
  3903. (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
  3904. (org-drag-element-backward)
  3905. (buffer-string)))))
  3906. (ert-deftest test-org/drag-element-forward ()
  3907. "Test `org-drag-element-forward' specifications."
  3908. ;; 1. Error when trying to move first element of buffer.
  3909. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  3910. (goto-line 3)
  3911. (should-error (org-drag-element-forward)))
  3912. ;; 2. Error when trying to swap nested elements.
  3913. (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
  3914. (forward-line)
  3915. (should-error (org-drag-element-forward)))
  3916. ;; 3. Error when trying to swap a non-headline element and an
  3917. ;; headline.
  3918. (org-test-with-temp-text "Test.\n* Head 1"
  3919. (should-error (org-drag-element-forward)))
  3920. ;; 4. Error when called before first element.
  3921. (should-error
  3922. (org-test-with-temp-text "\n"
  3923. (forward-line)
  3924. (org-drag-element-backward))
  3925. :type 'user-error)
  3926. ;; 5. Otherwise, swap elements, preserving column and blank lines
  3927. ;; between elements.
  3928. (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
  3929. (search-forward "graph")
  3930. (org-drag-element-forward)
  3931. (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
  3932. (should (looking-at " 1")))
  3933. ;; 5. Preserve visibility of elements and their contents.
  3934. (org-test-with-temp-text "
  3935. #+BEGIN_CENTER
  3936. Text.
  3937. #+END_CENTER
  3938. - item 1
  3939. #+BEGIN_QUOTE
  3940. Text.
  3941. #+END_QUOTE"
  3942. (while (search-forward "BEGIN_" nil t) (org-cycle))
  3943. (search-backward "#+BEGIN_CENTER")
  3944. (org-drag-element-forward)
  3945. (should
  3946. (equal
  3947. '((63 . 82) (26 . 48))
  3948. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  3949. (overlays-in (point-min) (point-max)))))))
  3950. (ert-deftest test-org/next-block ()
  3951. "Test `org-next-block' specifications."
  3952. ;; Regular test.
  3953. (should
  3954. (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  3955. (org-next-block 1)
  3956. (looking-at "#\\+BEGIN_CENTER")))
  3957. ;; Ignore case.
  3958. (should
  3959. (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
  3960. (let ((case-fold-search nil))
  3961. (org-next-block 1)
  3962. (looking-at "#\\+begin_center"))))
  3963. ;; Ignore current line.
  3964. (should
  3965. (org-test-with-temp-text
  3966. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
  3967. (org-next-block 1)
  3968. (looking-at "#\\+BEGIN_CENTER")))
  3969. ;; Throw an error when no block is found.
  3970. (should-error
  3971. (org-test-with-temp-text "Paragraph"
  3972. (org-next-block 1)))
  3973. ;; With an argument, skip many blocks at once.
  3974. (should
  3975. (org-test-with-temp-text
  3976. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  3977. (org-next-block 2)
  3978. (looking-at "#\\+BEGIN_QUOTE")))
  3979. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  3980. (should
  3981. (org-test-with-temp-text
  3982. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  3983. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  3984. (looking-at "#\\+BEGIN_QUOTE")))
  3985. ;; Optional argument is also case-insensitive.
  3986. (should
  3987. (org-test-with-temp-text
  3988. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
  3989. (let ((case-fold-search nil))
  3990. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  3991. (looking-at "#\\+begin_quote")))))
  3992. (ert-deftest test-org/insert-structure-template ()
  3993. "Test `org-insert-structure-template'."
  3994. ;; Test in empty buffer.
  3995. (should
  3996. (string= "#+begin_foo\n#+end_foo\n"
  3997. (org-test-with-temp-text ""
  3998. (org-insert-structure-template "foo")
  3999. (buffer-string))))
  4000. ;; Test with multiple lines in buffer.
  4001. (should
  4002. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4003. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4004. (transient-mark-mode 1)
  4005. (org-mark-element)
  4006. (org-insert-structure-template "foo")
  4007. (buffer-string))))
  4008. ;; Mark only the current line.
  4009. (should
  4010. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4011. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4012. (transient-mark-mode 1)
  4013. (set-mark (point-min))
  4014. (end-of-line)
  4015. (org-insert-structure-template "foo")
  4016. (buffer-string))))
  4017. ;; Middle of paragraph.
  4018. (should
  4019. (string= "p1\n#+begin_foo\np2\n#+end_foo\np3"
  4020. (org-test-with-temp-text "p1\n<point>p2\np3"
  4021. (set-mark (line-beginning-position))
  4022. (end-of-line)
  4023. (activate-mark)
  4024. (org-insert-structure-template "foo")
  4025. (buffer-string))))
  4026. ;; Test with text in buffer, no region, no final newline.
  4027. (should
  4028. (string= "#+begin_foo\nI'm a paragraph.\n#+end_foo\n"
  4029. (org-test-with-temp-text "I'm a paragraph."
  4030. (org-mark-element)
  4031. (org-insert-structure-template "foo")
  4032. (buffer-string))))
  4033. ;; Test with text in buffer and region set.
  4034. (should
  4035. (string= "#+begin_foo\nI'm a paragraph\n\nI'm a second paragrah\n#+end_foo\n"
  4036. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragrah"
  4037. (set-mark (point))
  4038. (goto-char (point-max))
  4039. (org-insert-structure-template "foo")
  4040. (buffer-string))))
  4041. ;; Test with example escaping.
  4042. (should
  4043. (string= "#+begin_example\n,* Heading\n#+end_example\n"
  4044. (org-test-with-temp-text "* Heading"
  4045. (org-mark-element)
  4046. (org-insert-structure-template "example")
  4047. (buffer-string))))
  4048. ;; Test with indentation.
  4049. (should
  4050. (string= " #+begin_foo\n This is a paragraph\n #+end_foo\n"
  4051. (org-test-with-temp-text " This is a paragraph"
  4052. (org-mark-element)
  4053. (org-insert-structure-template "foo")
  4054. (buffer-string))))
  4055. (should
  4056. (string= " #+begin_foo\n Line 1\n Line2\n #+end_foo\n"
  4057. (org-test-with-temp-text " Line 1\n Line2"
  4058. (org-mark-element)
  4059. (org-insert-structure-template "foo")
  4060. (buffer-string))))
  4061. ;; Test point location.
  4062. (should
  4063. (string= "#+begin_foo\n"
  4064. (org-test-with-temp-text ""
  4065. (org-insert-structure-template "foo")
  4066. (buffer-substring (point-min) (point)))))
  4067. (should
  4068. (string= "#+begin_src "
  4069. (org-test-with-temp-text ""
  4070. (org-insert-structure-template "src")
  4071. (buffer-substring (point-min) (point))))))
  4072. (ert-deftest test-org/previous-block ()
  4073. "Test `org-previous-block' specifications."
  4074. ;; Regular test.
  4075. (should
  4076. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
  4077. (org-previous-block 1)
  4078. (looking-at "#\\+BEGIN_CENTER")))
  4079. ;; Ignore case.
  4080. (should
  4081. (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
  4082. (let ((case-fold-search nil))
  4083. (org-previous-block 1)
  4084. (looking-at "#\\+begin_center"))))
  4085. ;; Ignore current line.
  4086. (should
  4087. (org-test-with-temp-text
  4088. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
  4089. (org-previous-block 1)
  4090. (looking-at "#\\+BEGIN_QUOTE")))
  4091. ;; Throw an error when no block is found.
  4092. (should-error
  4093. (org-test-with-temp-text "Paragraph<point>"
  4094. (org-previous-block 1)))
  4095. ;; With an argument, skip many blocks at once.
  4096. (should
  4097. (org-test-with-temp-text
  4098. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4099. (org-previous-block 2)
  4100. (looking-at "#\\+BEGIN_CENTER")))
  4101. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4102. (should
  4103. (org-test-with-temp-text
  4104. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4105. (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4106. (looking-at "#\\+BEGIN_QUOTE")))
  4107. ;; Optional argument is also case-insensitive.
  4108. (should
  4109. (org-test-with-temp-text
  4110. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
  4111. (let ((case-fold-search nil))
  4112. (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4113. (looking-at "#\\+begin_quote")))))
  4114. ;;; Outline structure
  4115. (ert-deftest test-org/demote ()
  4116. "Test `org-demote' specifications."
  4117. ;; Add correct number of stars according to `org-odd-levels-only'.
  4118. (should
  4119. (= 2
  4120. (org-test-with-temp-text "* H"
  4121. (let ((org-odd-levels-only nil)) (org-demote))
  4122. (org-current-level))))
  4123. (should
  4124. (= 3
  4125. (org-test-with-temp-text "* H"
  4126. (let ((org-odd-levels-only t)) (org-demote))
  4127. (org-current-level))))
  4128. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4129. (should
  4130. (org-test-with-temp-text "* H :tag:"
  4131. (let ((org-tags-column 10)
  4132. (org-auto-align-tags t)
  4133. (org-odd-levels-only nil))
  4134. (org-demote))
  4135. (org-move-to-column 10)
  4136. (looking-at-p ":tag:$")))
  4137. (should-not
  4138. (org-test-with-temp-text "* H :tag:"
  4139. (let ((org-tags-column 10)
  4140. (org-auto-align-tags nil)
  4141. (org-odd-levels-only nil))
  4142. (org-demote))
  4143. (org-move-to-column 10)
  4144. (looking-at-p ":tag:$")))
  4145. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4146. ;; info and property drawers accordingly.
  4147. (should
  4148. (= 3
  4149. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4150. (let ((org-odd-levels-only nil)
  4151. (org-adapt-indentation t))
  4152. (org-demote))
  4153. (forward-line)
  4154. (org-get-indentation))))
  4155. (should
  4156. (= 3
  4157. (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4158. (let ((org-odd-levels-only nil)
  4159. (org-adapt-indentation t))
  4160. (org-demote))
  4161. (forward-line)
  4162. (org-get-indentation))))
  4163. (should-not
  4164. (= 3
  4165. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4166. (let ((org-odd-levels-only nil)
  4167. (org-adapt-indentation nil))
  4168. (org-demote))
  4169. (forward-line)
  4170. (org-get-indentation))))
  4171. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4172. ;; section accordingly. Ignore, however, footnote definitions and
  4173. ;; inlinetasks boundaries.
  4174. (should
  4175. (= 3
  4176. (org-test-with-temp-text "* H\n Paragraph"
  4177. (let ((org-odd-levels-only nil)
  4178. (org-adapt-indentation t))
  4179. (org-demote))
  4180. (forward-line)
  4181. (org-get-indentation))))
  4182. (should
  4183. (= 2
  4184. (org-test-with-temp-text "* H\n Paragraph"
  4185. (let ((org-odd-levels-only nil)
  4186. (org-adapt-indentation nil))
  4187. (org-demote))
  4188. (forward-line)
  4189. (org-get-indentation))))
  4190. (should
  4191. (zerop
  4192. (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
  4193. (let ((org-odd-levels-only nil)
  4194. (org-adapt-indentation t))
  4195. (org-demote))
  4196. (goto-char (point-max))
  4197. (org-get-indentation))))
  4198. (should
  4199. (= 3
  4200. (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
  4201. (let ((org-odd-levels-only nil)
  4202. (org-adapt-indentation t))
  4203. (org-demote))
  4204. (goto-char (point-max))
  4205. (org-get-indentation))))
  4206. (when (featurep 'org-inlinetask)
  4207. (should
  4208. (zerop
  4209. (let ((org-inlinetask-min-level 5)
  4210. (org-adapt-indentation t))
  4211. (org-test-with-temp-text "* H\n***** I\n***** END"
  4212. (org-demote)
  4213. (forward-line)
  4214. (org-get-indentation))))))
  4215. (when (featurep 'org-inlinetask)
  4216. (should
  4217. (= 3
  4218. (let ((org-inlinetask-min-level 5)
  4219. (org-adapt-indentation t))
  4220. (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
  4221. (org-demote)
  4222. (forward-line 2)
  4223. (org-get-indentation))))))
  4224. ;; Ignore contents of source blocks or example blocks when
  4225. ;; indentation should be preserved (through
  4226. ;; `org-src-preserve-indentation' or "-i" flag).
  4227. (should-not
  4228. (zerop
  4229. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4230. (let ((org-adapt-indentation t)
  4231. (org-src-preserve-indentation nil))
  4232. (org-demote))
  4233. (forward-line 2)
  4234. (org-get-indentation))))
  4235. (should
  4236. (zerop
  4237. (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
  4238. (let ((org-adapt-indentation t)
  4239. (org-src-preserve-indentation t))
  4240. (org-demote))
  4241. (forward-line 2)
  4242. (org-get-indentation))))
  4243. (should
  4244. (zerop
  4245. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4246. (let ((org-adapt-indentation t)
  4247. (org-src-preserve-indentation t))
  4248. (org-demote))
  4249. (forward-line 2)
  4250. (org-get-indentation))))
  4251. (should
  4252. (zerop
  4253. (org-test-with-temp-text
  4254. "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
  4255. (let ((org-adapt-indentation t)
  4256. (org-src-preserve-indentation nil))
  4257. (org-demote))
  4258. (forward-line 2)
  4259. (org-get-indentation)))))
  4260. (ert-deftest test-org/promote ()
  4261. "Test `org-promote' specifications."
  4262. ;; Return an error if headline is to be promoted to level 0, unless
  4263. ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
  4264. ;; headline becomes a comment.
  4265. (should-error
  4266. (org-test-with-temp-text "* H"
  4267. (let ((org-allow-promoting-top-level-subtree nil)) (org-promote))))
  4268. (should
  4269. (equal "# H"
  4270. (org-test-with-temp-text "* H"
  4271. (let ((org-allow-promoting-top-level-subtree t)) (org-promote))
  4272. (buffer-string))))
  4273. ;; Remove correct number of stars according to
  4274. ;; `org-odd-levels-only'.
  4275. (should
  4276. (= 2
  4277. (org-test-with-temp-text "*** H"
  4278. (let ((org-odd-levels-only nil)) (org-promote))
  4279. (org-current-level))))
  4280. (should
  4281. (= 1
  4282. (org-test-with-temp-text "*** H"
  4283. (let ((org-odd-levels-only t)) (org-promote))
  4284. (org-current-level))))
  4285. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4286. (should
  4287. (org-test-with-temp-text "** H :tag:"
  4288. (let ((org-tags-column 10)
  4289. (org-auto-align-tags t)
  4290. (org-odd-levels-only nil))
  4291. (org-promote))
  4292. (org-move-to-column 10)
  4293. (looking-at-p ":tag:$")))
  4294. (should-not
  4295. (org-test-with-temp-text "** H :tag:"
  4296. (let ((org-tags-column 10)
  4297. (org-auto-align-tags nil)
  4298. (org-odd-levels-only nil))
  4299. (org-promote))
  4300. (org-move-to-column 10)
  4301. (looking-at-p ":tag:$")))
  4302. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4303. ;; info and property drawers.
  4304. (should
  4305. (= 2
  4306. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4307. (let ((org-odd-levels-only nil)
  4308. (org-adapt-indentation t))
  4309. (org-promote))
  4310. (forward-line)
  4311. (org-get-indentation))))
  4312. (should
  4313. (= 2
  4314. (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4315. (let ((org-odd-levels-only nil)
  4316. (org-adapt-indentation t))
  4317. (org-promote))
  4318. (forward-line)
  4319. (org-get-indentation))))
  4320. (should-not
  4321. (= 2
  4322. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4323. (let ((org-odd-levels-only nil)
  4324. (org-adapt-indentation nil))
  4325. (org-promote))
  4326. (forward-line)
  4327. (org-get-indentation))))
  4328. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4329. ;; section accordingly. Ignore, however, footnote definitions and
  4330. ;; inlinetasks boundaries.
  4331. (should
  4332. (= 2
  4333. (org-test-with-temp-text "** H\n Paragraph"
  4334. (let ((org-odd-levels-only nil)
  4335. (org-adapt-indentation t))
  4336. (org-promote))
  4337. (forward-line)
  4338. (org-get-indentation))))
  4339. (should-not
  4340. (= 2
  4341. (org-test-with-temp-text "** H\n Paragraph"
  4342. (let ((org-odd-levels-only nil)
  4343. (org-adapt-indentation nil))
  4344. (org-promote))
  4345. (forward-line)
  4346. (org-get-indentation))))
  4347. (should
  4348. (= 2
  4349. (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
  4350. (let ((org-odd-levels-only nil)
  4351. (org-adapt-indentation t))
  4352. (org-promote))
  4353. (forward-line)
  4354. (org-get-indentation))))
  4355. (when (featurep 'org-inlinetask)
  4356. (should
  4357. (zerop
  4358. (let ((org-inlinetask-min-level 5)
  4359. (org-adapt-indentation t))
  4360. (org-test-with-temp-text "** H\n***** I\n***** END"
  4361. (org-promote)
  4362. (forward-line)
  4363. (org-get-indentation))))))
  4364. (when (featurep 'org-inlinetask)
  4365. (should
  4366. (= 2
  4367. (let ((org-inlinetask-min-level 5)
  4368. (org-adapt-indentation t))
  4369. (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
  4370. (org-promote)
  4371. (forward-line 2)
  4372. (org-get-indentation))))))
  4373. ;; Give up shifting if it would break document's structure
  4374. ;; otherwise.
  4375. (should
  4376. (= 3
  4377. (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
  4378. (let ((org-odd-levels-only nil)
  4379. (org-adapt-indentation t))
  4380. (org-promote))
  4381. (forward-line)
  4382. (org-get-indentation))))
  4383. (should
  4384. (= 3
  4385. (org-test-with-temp-text "** H\n Paragraph\n * list."
  4386. (let ((org-odd-levels-only nil)
  4387. (org-adapt-indentation t))
  4388. (org-promote))
  4389. (forward-line)
  4390. (org-get-indentation))))
  4391. ;; Ignore contents of source blocks or example blocks when
  4392. ;; indentation should be preserved (through
  4393. ;; `org-src-preserve-indentation' or "-i" flag).
  4394. (should-not
  4395. (zerop
  4396. (org-test-with-temp-text
  4397. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  4398. (let ((org-adapt-indentation t)
  4399. (org-src-preserve-indentation nil)
  4400. (org-odd-levels-only nil))
  4401. (org-promote))
  4402. (forward-line)
  4403. (org-get-indentation))))
  4404. (should
  4405. (zerop
  4406. (org-test-with-temp-text
  4407. "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
  4408. (let ((org-adapt-indentation t)
  4409. (org-src-preserve-indentation t)
  4410. (org-odd-levels-only nil))
  4411. (org-promote))
  4412. (forward-line)
  4413. (org-get-indentation))))
  4414. (should
  4415. (zerop
  4416. (org-test-with-temp-text
  4417. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  4418. (let ((org-adapt-indentation t)
  4419. (org-src-preserve-indentation t)
  4420. (org-odd-levels-only nil))
  4421. (org-promote))
  4422. (forward-line)
  4423. (org-get-indentation))))
  4424. (should
  4425. (zerop
  4426. (org-test-with-temp-text
  4427. "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
  4428. (let ((org-adapt-indentation t)
  4429. (org-src-preserve-indentation nil)
  4430. (org-odd-levels-only nil))
  4431. (org-promote))
  4432. (forward-line)
  4433. (org-get-indentation)))))
  4434. (ert-deftest test-org/org-get-valid-level ()
  4435. "Test function `org-get-valid-level' specifications."
  4436. (let ((org-odd-levels-only nil))
  4437. (should (equal 1 (org-get-valid-level 0 0)))
  4438. (should (equal 1 (org-get-valid-level 0 1)))
  4439. (should (equal 2 (org-get-valid-level 0 2)))
  4440. (should (equal 3 (org-get-valid-level 0 3)))
  4441. (should (equal 1 (org-get-valid-level 1 0)))
  4442. (should (equal 2 (org-get-valid-level 1 1)))
  4443. (should (equal 23 (org-get-valid-level 1 22)))
  4444. (should (equal 1 (org-get-valid-level 1 -1)))
  4445. (should (equal 1 (org-get-valid-level 2 -1))))
  4446. (let ((org-odd-levels-only t))
  4447. (should (equal 1 (org-get-valid-level 0 0)))
  4448. (should (equal 1 (org-get-valid-level 0 1)))
  4449. (should (equal 3 (org-get-valid-level 0 2)))
  4450. (should (equal 5 (org-get-valid-level 0 3)))
  4451. (should (equal 1 (org-get-valid-level 1 0)))
  4452. (should (equal 3 (org-get-valid-level 1 1)))
  4453. (should (equal 3 (org-get-valid-level 2 1)))
  4454. (should (equal 5 (org-get-valid-level 3 1)))
  4455. (should (equal 5 (org-get-valid-level 4 1)))
  4456. (should (equal 43 (org-get-valid-level 1 21)))
  4457. (should (equal 1 (org-get-valid-level 1 -1)))
  4458. (should (equal 1 (org-get-valid-level 2 -1)))
  4459. (should (equal 1 (org-get-valid-level 3 -1)))
  4460. (should (equal 3 (org-get-valid-level 4 -1)))
  4461. (should (equal 3 (org-get-valid-level 5 -1)))))
  4462. ;;; Planning
  4463. (ert-deftest test-org/at-planning-p ()
  4464. "Test `org-at-planning-p' specifications."
  4465. ;; Regular test.
  4466. (should
  4467. (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
  4468. (org-at-planning-p)))
  4469. (should-not
  4470. (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
  4471. (org-at-planning-p)))
  4472. ;; Correctly find planning attached to inlinetasks.
  4473. (when (featurep 'org-inlinetask)
  4474. (should
  4475. (org-test-with-temp-text
  4476. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
  4477. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4478. (should-not
  4479. (org-test-with-temp-text
  4480. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  4481. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4482. (should-not
  4483. (org-test-with-temp-text
  4484. "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  4485. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4486. (should-not
  4487. (org-test-with-temp-text
  4488. "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
  4489. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
  4490. (ert-deftest test-org/add-planning-info ()
  4491. "Test `org-add-planning-info'."
  4492. ;; Create deadline when `org-adapt-indentation' is non-nil.
  4493. (should
  4494. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4495. (org-test-with-temp-text "* H\nParagraph<point>"
  4496. (let ((org-adapt-indentation t))
  4497. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4498. (replace-regexp-in-string
  4499. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4500. nil nil 1))))
  4501. ;; Create deadline when `org-adapt-indentation' is nil.
  4502. (should
  4503. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  4504. (org-test-with-temp-text "* H\nParagraph<point>"
  4505. (let ((org-adapt-indentation nil))
  4506. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4507. (replace-regexp-in-string
  4508. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4509. nil nil 1))))
  4510. ;; Update deadline when `org-adapt-indentation' is non-nil.
  4511. (should
  4512. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4513. (org-test-with-temp-text "\
  4514. * H
  4515. DEADLINE: <2015-06-24 Wed>
  4516. Paragraph<point>"
  4517. (let ((org-adapt-indentation t))
  4518. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4519. (replace-regexp-in-string
  4520. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4521. nil nil 1))))
  4522. ;; Update deadline when `org-adapt-indentation' is nil.
  4523. (should
  4524. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  4525. (org-test-with-temp-text "\
  4526. * H
  4527. DEADLINE: <2015-06-24 Wed>
  4528. Paragraph<point>"
  4529. (let ((org-adapt-indentation nil))
  4530. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4531. (replace-regexp-in-string
  4532. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4533. nil nil 1))))
  4534. ;; Schedule when `org-adapt-indentation' is non-nil.
  4535. (should
  4536. (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
  4537. (org-test-with-temp-text "* H\nParagraph<point>"
  4538. (let ((org-adapt-indentation t))
  4539. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  4540. (replace-regexp-in-string
  4541. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4542. nil nil 1))))
  4543. ;; Schedule when `org-adapt-indentation' is nil.
  4544. (should
  4545. (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
  4546. (org-test-with-temp-text "* H\nParagraph<point>"
  4547. (let ((org-adapt-indentation nil))
  4548. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  4549. (replace-regexp-in-string
  4550. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4551. nil nil 1))))
  4552. ;; Add deadline when scheduled.
  4553. (should
  4554. (equal "\
  4555. * H
  4556. DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
  4557. Paragraph"
  4558. (org-test-with-temp-text "\
  4559. * H
  4560. SCHEDULED: <2015-06-24 Wed>
  4561. Paragraph<point>"
  4562. (let ((org-adapt-indentation t))
  4563. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4564. (replace-regexp-in-string
  4565. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4566. nil nil 1))))
  4567. ;; Remove middle entry.
  4568. (should
  4569. (equal "\
  4570. * H
  4571. CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
  4572. Paragraph"
  4573. (org-test-with-temp-text "\
  4574. * H
  4575. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  4576. Paragraph<point>"
  4577. (let ((org-adapt-indentation t))
  4578. (org-add-planning-info nil nil 'deadline))
  4579. (replace-regexp-in-string
  4580. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  4581. nil nil 1))))
  4582. ;; Remove last entry and then middle entry (order should not
  4583. ;; matter).
  4584. (should
  4585. (equal "\
  4586. * H
  4587. CLOSED: [2015-06-24]
  4588. Paragraph"
  4589. (org-test-with-temp-text "\
  4590. * H
  4591. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  4592. Paragraph<point>"
  4593. (let ((org-adapt-indentation t))
  4594. (org-add-planning-info nil nil 'scheduled 'deadline))
  4595. (replace-regexp-in-string
  4596. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  4597. nil nil 1))))
  4598. ;; Remove closed when `org-adapt-indentation' is non-nil.
  4599. (should
  4600. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4601. (org-test-with-temp-text "\
  4602. * H
  4603. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  4604. Paragraph<point>"
  4605. (let ((org-adapt-indentation t))
  4606. (org-add-planning-info nil nil 'closed))
  4607. (replace-regexp-in-string
  4608. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4609. nil nil 1))))
  4610. (should
  4611. (equal "* H\n Paragraph"
  4612. (org-test-with-temp-text "\
  4613. * H
  4614. CLOSED: [2015-06-25 Thu]
  4615. Paragraph<point>"
  4616. (let ((org-adapt-indentation t))
  4617. (org-add-planning-info nil nil 'closed))
  4618. (replace-regexp-in-string
  4619. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4620. nil nil 1))))
  4621. ;; Remove closed when `org-adapt-indentation' is nil.
  4622. (should
  4623. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  4624. (org-test-with-temp-text "\
  4625. * H
  4626. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  4627. Paragraph<point>"
  4628. (let ((org-adapt-indentation nil))
  4629. (org-add-planning-info nil nil 'closed))
  4630. (replace-regexp-in-string
  4631. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4632. nil nil 1))))
  4633. (should
  4634. (equal "* H\nParagraph"
  4635. (org-test-with-temp-text "\
  4636. * H
  4637. CLOSED: [2015-06-25 Thu]
  4638. Paragraph<point>"
  4639. (let ((org-adapt-indentation nil))
  4640. (org-add-planning-info nil nil 'closed))
  4641. (replace-regexp-in-string
  4642. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4643. nil nil 1))))
  4644. ;; Remove closed entry and delete empty line.
  4645. (should
  4646. (equal "\
  4647. * H
  4648. Paragraph"
  4649. (org-test-with-temp-text "\
  4650. * H
  4651. CLOSED: [2015-06-24 Wed]
  4652. Paragraph<point>"
  4653. (let ((org-adapt-indentation t))
  4654. (org-add-planning-info nil nil 'closed))
  4655. (replace-regexp-in-string
  4656. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4657. nil nil 1))))
  4658. ;; Remove one entry and update another.
  4659. (should
  4660. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4661. (org-test-with-temp-text "\
  4662. * H
  4663. SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
  4664. Paragraph<point>"
  4665. (let ((org-adapt-indentation t))
  4666. (org-add-planning-info 'deadline "<2015-06-25 Thu>" 'scheduled))
  4667. (replace-regexp-in-string
  4668. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4669. nil nil 1)))))
  4670. (ert-deftest test-org/deadline ()
  4671. "Test `org-deadline' specifications."
  4672. ;; Insert a new value or replace existing one.
  4673. (should
  4674. (equal "* H\nDEADLINE: <2012-03-29>\n"
  4675. (org-test-with-temp-text "* H"
  4676. (let ((org-adapt-indentation nil)
  4677. (org-last-inserted-timestamp nil))
  4678. (org-deadline nil "<2012-03-29 Tue>"))
  4679. (replace-regexp-in-string
  4680. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4681. nil nil 1))))
  4682. (should
  4683. (equal "* H\nDEADLINE: <2014-03-04>"
  4684. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  4685. (let ((org-adapt-indentation nil)
  4686. (org-last-inserted-timestamp nil))
  4687. (org-deadline nil "<2014-03-04 Thu>"))
  4688. (replace-regexp-in-string
  4689. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4690. nil nil 1))))
  4691. ;; Accept delta time, e.g., "+2d".
  4692. (should
  4693. (equal "* H\nDEADLINE: <2015-03-04>\n"
  4694. (cl-letf (((symbol-function 'current-time)
  4695. (lambda (&rest args)
  4696. (apply #'encode-time
  4697. (org-parse-time-string "2014-03-04")))))
  4698. (org-test-with-temp-text "* H"
  4699. (let ((org-adapt-indentation nil)
  4700. (org-last-inserted-timestamp nil))
  4701. (org-deadline nil "+1y"))
  4702. (replace-regexp-in-string
  4703. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  4704. ;; Preserve repeater.
  4705. (should
  4706. (equal "* H\nDEADLINE: <2012-03-29 +2y>\n"
  4707. (org-test-with-temp-text "* H"
  4708. (let ((org-adapt-indentation nil)
  4709. (org-last-inserted-timestamp nil))
  4710. (org-deadline nil "<2012-03-29 Tue +2y>"))
  4711. (replace-regexp-in-string
  4712. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  4713. ;; Remove CLOSED keyword, if any.
  4714. (should
  4715. (equal "* H\nDEADLINE: <2012-03-29>"
  4716. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  4717. (let ((org-adapt-indentation nil)
  4718. (org-last-inserted-timestamp nil))
  4719. (org-deadline nil "<2012-03-29 Tue>"))
  4720. (replace-regexp-in-string
  4721. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  4722. ;; With C-u argument, remove DEADLINE keyword.
  4723. (should
  4724. (equal "* H\n"
  4725. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  4726. (let ((org-adapt-indentation nil)
  4727. (org-last-inserted-timestamp nil))
  4728. (org-deadline '(4)))
  4729. (buffer-string))))
  4730. (should
  4731. (equal "* H"
  4732. (org-test-with-temp-text "* H"
  4733. (let ((org-adapt-indentation nil)
  4734. (org-last-inserted-timestamp nil))
  4735. (org-deadline '(4)))
  4736. (buffer-string))))
  4737. ;; With C-u C-u argument, prompt for a delay cookie.
  4738. (should
  4739. (equal "* H\nDEADLINE: <2012-03-29 -705d>"
  4740. (cl-letf (((symbol-function 'org-read-date)
  4741. (lambda (&rest args)
  4742. (apply #'encode-time
  4743. (org-parse-time-string "2014-03-04")))))
  4744. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  4745. (let ((org-adapt-indentation nil)
  4746. (org-last-inserted-timestamp nil))
  4747. (org-deadline '(16)))
  4748. (buffer-string)))))
  4749. (should-error
  4750. (cl-letf (((symbol-function 'org-read-date)
  4751. (lambda (&rest args)
  4752. (apply #'encode-time
  4753. (org-parse-time-string "2014-03-04")))))
  4754. (org-test-with-temp-text "* H"
  4755. (let ((org-adapt-indentation nil)
  4756. (org-last-inserted-timestamp nil))
  4757. (org-deadline '(16)))
  4758. (buffer-string))))
  4759. ;; When a region is active and
  4760. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  4761. ;; same value in all headlines in region.
  4762. (should
  4763. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
  4764. (org-test-with-temp-text "* H1\n* H2"
  4765. (let ((org-adapt-indentation nil)
  4766. (org-last-inserted-timestamp nil)
  4767. (org-loop-over-headlines-in-active-region t))
  4768. (transient-mark-mode 1)
  4769. (push-mark (point) t t)
  4770. (goto-char (point-max))
  4771. (org-deadline nil "2012-03-29"))
  4772. (replace-regexp-in-string
  4773. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  4774. (should-not
  4775. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>\n"
  4776. (org-test-with-temp-text "* H1\n* H2"
  4777. (let ((org-adapt-indentation nil)
  4778. (org-last-inserted-timestamp nil)
  4779. (org-loop-over-headlines-in-active-region nil))
  4780. (transient-mark-mode 1)
  4781. (push-mark (point) t t)
  4782. (goto-char (point-max))
  4783. (org-deadline nil "2012-03-29"))
  4784. (replace-regexp-in-string
  4785. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  4786. (ert-deftest test-org/schedule ()
  4787. "Test `org-schedule' specifications."
  4788. ;; Insert a new value or replace existing one.
  4789. (should
  4790. (equal "* H\nSCHEDULED: <2012-03-29>\n"
  4791. (org-test-with-temp-text "* H"
  4792. (let ((org-adapt-indentation nil)
  4793. (org-last-inserted-timestamp nil))
  4794. (org-schedule nil "<2012-03-29 Tue>"))
  4795. (replace-regexp-in-string
  4796. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4797. nil nil 1))))
  4798. (should
  4799. (equal "* H\nSCHEDULED: <2014-03-04>"
  4800. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  4801. (let ((org-adapt-indentation nil)
  4802. (org-last-inserted-timestamp nil))
  4803. (org-schedule nil "<2014-03-04 Thu>"))
  4804. (replace-regexp-in-string
  4805. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4806. nil nil 1))))
  4807. ;; Accept delta time, e.g., "+2d".
  4808. (should
  4809. (equal "* H\nSCHEDULED: <2015-03-04>\n"
  4810. (cl-letf (((symbol-function 'current-time)
  4811. (lambda (&rest args)
  4812. (apply #'encode-time
  4813. (org-parse-time-string "2014-03-04")))))
  4814. (org-test-with-temp-text "* H"
  4815. (let ((org-adapt-indentation nil)
  4816. (org-last-inserted-timestamp nil))
  4817. (org-schedule nil "+1y"))
  4818. (replace-regexp-in-string
  4819. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  4820. ;; Preserve repeater.
  4821. (should
  4822. (equal "* H\nSCHEDULED: <2012-03-29 +2y>\n"
  4823. (org-test-with-temp-text "* H"
  4824. (let ((org-adapt-indentation nil)
  4825. (org-last-inserted-timestamp nil))
  4826. (org-schedule nil "<2012-03-29 Tue +2y>"))
  4827. (replace-regexp-in-string
  4828. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  4829. ;; Remove CLOSED keyword, if any.
  4830. (should
  4831. (equal "* H\nSCHEDULED: <2012-03-29>"
  4832. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  4833. (let ((org-adapt-indentation nil)
  4834. (org-last-inserted-timestamp nil))
  4835. (org-schedule nil "<2012-03-29 Tue>"))
  4836. (replace-regexp-in-string
  4837. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  4838. ;; With C-u argument, remove SCHEDULED keyword.
  4839. (should
  4840. (equal "* H\n"
  4841. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  4842. (let ((org-adapt-indentation nil)
  4843. (org-last-inserted-timestamp nil))
  4844. (org-schedule '(4)))
  4845. (buffer-string))))
  4846. (should
  4847. (equal "* H"
  4848. (org-test-with-temp-text "* H"
  4849. (let ((org-adapt-indentation nil)
  4850. (org-last-inserted-timestamp nil))
  4851. (org-schedule '(4)))
  4852. (buffer-string))))
  4853. ;; With C-u C-u argument, prompt for a delay cookie.
  4854. (should
  4855. (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
  4856. (cl-letf (((symbol-function 'org-read-date)
  4857. (lambda (&rest args)
  4858. (apply #'encode-time
  4859. (org-parse-time-string "2014-03-04")))))
  4860. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  4861. (let ((org-adapt-indentation nil)
  4862. (org-last-inserted-timestamp nil))
  4863. (org-schedule '(16)))
  4864. (buffer-string)))))
  4865. (should-error
  4866. (cl-letf (((symbol-function 'org-read-date)
  4867. (lambda (&rest args)
  4868. (apply #'encode-time
  4869. (org-parse-time-string "2014-03-04")))))
  4870. (org-test-with-temp-text "* H"
  4871. (let ((org-adapt-indentation nil)
  4872. (org-last-inserted-timestamp nil))
  4873. (org-schedule '(16)))
  4874. (buffer-string))))
  4875. ;; When a region is active and
  4876. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  4877. ;; same value in all headlines in region.
  4878. (should
  4879. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
  4880. (org-test-with-temp-text "* H1\n* H2"
  4881. (let ((org-adapt-indentation nil)
  4882. (org-last-inserted-timestamp nil)
  4883. (org-loop-over-headlines-in-active-region t))
  4884. (transient-mark-mode 1)
  4885. (push-mark (point) t t)
  4886. (goto-char (point-max))
  4887. (org-schedule nil "2012-03-29"))
  4888. (replace-regexp-in-string
  4889. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  4890. (should-not
  4891. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>\n"
  4892. (org-test-with-temp-text "* H1\n* H2"
  4893. (let ((org-adapt-indentation nil)
  4894. (org-last-inserted-timestamp nil)
  4895. (org-loop-over-headlines-in-active-region nil))
  4896. (transient-mark-mode 1)
  4897. (push-mark (point) t t)
  4898. (goto-char (point-max))
  4899. (org-schedule nil "2012-03-29"))
  4900. (replace-regexp-in-string
  4901. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  4902. (should
  4903. ;; check if a repeater survives re-scheduling.
  4904. (string-match-p
  4905. "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
  4906. (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
  4907. (let ((org-adapt-indentation nil)
  4908. (org-last-inserted-timestamp nil))
  4909. (org-schedule nil "2017-02-01"))
  4910. (buffer-string)))))
  4911. ;;; Property API
  4912. (ert-deftest test-org/buffer-property-keys ()
  4913. "Test `org-buffer-property-keys' specifications."
  4914. ;; Retrieve properties accross siblings.
  4915. (should
  4916. (equal '("A" "B")
  4917. (org-test-with-temp-text "
  4918. * H1
  4919. :PROPERTIES:
  4920. :A: 1
  4921. :END:
  4922. * H2
  4923. :PROPERTIES:
  4924. :B: 1
  4925. :END:"
  4926. (org-buffer-property-keys))))
  4927. ;; Retrieve properties accross children.
  4928. (should
  4929. (equal '("A" "B")
  4930. (org-test-with-temp-text "
  4931. * H1
  4932. :PROPERTIES:
  4933. :A: 1
  4934. :END:
  4935. ** H2
  4936. :PROPERTIES:
  4937. :B: 1
  4938. :END:"
  4939. (org-buffer-property-keys))))
  4940. ;; Retrieve muliple properties in the same drawer.
  4941. (should
  4942. (equal '("A" "B")
  4943. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  4944. (org-buffer-property-keys))))
  4945. ;; Ignore extension symbol in property name.
  4946. (should
  4947. (equal '("A")
  4948. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  4949. (org-buffer-property-keys))))
  4950. ;; With non-nil COLUMNS, extract property names from columns.
  4951. (should
  4952. (equal '("A" "B")
  4953. (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
  4954. (org-buffer-property-keys nil nil t))))
  4955. (should
  4956. (equal '("A" "B" "COLUMNS")
  4957. (org-test-with-temp-text
  4958. "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
  4959. (org-buffer-property-keys nil nil t))))
  4960. ;; In COLUMNS, ignore title and summary-type.
  4961. (should
  4962. (equal '("A")
  4963. (org-test-with-temp-text "#+COLUMNS: %A(Foo)"
  4964. (org-buffer-property-keys nil nil t))))
  4965. (should
  4966. (equal '("A")
  4967. (org-test-with-temp-text "#+COLUMNS: %A{Foo}"
  4968. (org-buffer-property-keys nil nil t))))
  4969. (should
  4970. (equal '("A")
  4971. (org-test-with-temp-text "#+COLUMNS: %A(Foo){Bar}"
  4972. (org-buffer-property-keys nil nil t)))))
  4973. (ert-deftest test-org/property-values ()
  4974. "Test `org-property-values' specifications."
  4975. ;; Regular test.
  4976. (should
  4977. (equal '("2" "1")
  4978. (org-test-with-temp-text
  4979. "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
  4980. (org-property-values "A"))))
  4981. ;; Ignore empty values.
  4982. (should-not
  4983. (org-test-with-temp-text
  4984. "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
  4985. (org-property-values "A")))
  4986. ;; Take into consideration extended values.
  4987. (should
  4988. (equal '("1 2")
  4989. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  4990. (org-property-values "A")))))
  4991. (ert-deftest test-org/find-property ()
  4992. "Test `org-find-property' specifications."
  4993. ;; Regular test.
  4994. (should
  4995. (= 1
  4996. (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
  4997. (org-find-property "prop"))))
  4998. ;; Ignore false positives.
  4999. (should
  5000. (= 27
  5001. (org-test-with-temp-text
  5002. "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
  5003. (org-find-property "A"))))
  5004. ;; Return first entry found in buffer.
  5005. (should
  5006. (= 1
  5007. (org-test-with-temp-text
  5008. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5009. (org-find-property "A"))))
  5010. ;; Only search visible part of the buffer.
  5011. (should
  5012. (= 31
  5013. (org-test-with-temp-text
  5014. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5015. (org-narrow-to-subtree)
  5016. (org-find-property "A"))))
  5017. ;; With optional argument, only find entries with a specific value.
  5018. (should-not
  5019. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5020. (org-find-property "A" "2")))
  5021. (should
  5022. (= 31
  5023. (org-test-with-temp-text
  5024. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
  5025. (org-find-property "A" "2"))))
  5026. ;; Use "nil" for explicit nil values.
  5027. (should
  5028. (= 31
  5029. (org-test-with-temp-text
  5030. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
  5031. (org-find-property "A" "nil")))))
  5032. (ert-deftest test-org/entry-delete ()
  5033. "Test `org-entry-delete' specifications."
  5034. ;; Regular test.
  5035. (should
  5036. (string-match
  5037. " *:PROPERTIES:\n *:B: +2\n *:END:"
  5038. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5039. (org-entry-delete (point) "A")
  5040. (buffer-string))))
  5041. ;; Also remove accumulated properties.
  5042. (should-not
  5043. (string-match
  5044. ":A"
  5045. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
  5046. (org-entry-delete (point) "A")
  5047. (buffer-string))))
  5048. ;; When last property is removed, remove the property drawer.
  5049. (should-not
  5050. (string-match
  5051. ":PROPERTIES:"
  5052. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
  5053. (org-entry-delete (point) "A")
  5054. (buffer-string))))
  5055. ;; Return a non-nil value when some property was removed.
  5056. (should
  5057. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5058. (org-entry-delete (point) "A")))
  5059. (should-not
  5060. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5061. (org-entry-delete (point) "C")))
  5062. ;; Special properties cannot be located in a drawer. Allow to
  5063. ;; remove them anyway, in case of user error.
  5064. (should
  5065. (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
  5066. (org-entry-delete (point) "SCHEDULED"))))
  5067. (ert-deftest test-org/entry-get ()
  5068. "Test `org-entry-get' specifications."
  5069. ;; Regular test.
  5070. (should
  5071. (equal "1"
  5072. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5073. (org-entry-get (point) "A"))))
  5074. ;; Ignore case.
  5075. (should
  5076. (equal "1"
  5077. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5078. (org-entry-get (point) "a"))))
  5079. ;; Handle extended values, both before and after base value.
  5080. (should
  5081. (equal "1 2 3"
  5082. (org-test-with-temp-text
  5083. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5084. (org-entry-get (point) "A"))))
  5085. ;; Empty values are returned as the empty string.
  5086. (should
  5087. (equal ""
  5088. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
  5089. (org-entry-get (point) "A"))))
  5090. ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
  5091. ;; otherwise, return nil.
  5092. (should-not
  5093. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5094. (org-entry-get (point) "A")))
  5095. (should
  5096. (equal "nil"
  5097. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5098. (org-entry-get (point) "A" nil t))))
  5099. ;; Return nil when no property is found, independently on the
  5100. ;; LITERAL-NIL argument.
  5101. (should-not
  5102. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5103. (org-entry-get (point) "B")))
  5104. (should-not
  5105. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5106. (org-entry-get (point) "B" nil t)))
  5107. ;; Handle inheritance, when allowed. Include extended values and
  5108. ;; possibly global values.
  5109. (should
  5110. (equal
  5111. "1"
  5112. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
  5113. (org-entry-get (point) "A" t))))
  5114. (should
  5115. (equal
  5116. "1"
  5117. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
  5118. (let ((org-use-property-inheritance t))
  5119. (org-entry-get (point) "A" 'selective)))))
  5120. (should-not
  5121. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** <point>H2"
  5122. (let ((org-use-property-inheritance nil))
  5123. (org-entry-get (point) "A" 'selective))))
  5124. (should
  5125. (equal
  5126. "1 2"
  5127. (org-test-with-temp-text
  5128. "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5129. (org-entry-get (point-max) "A" t))))
  5130. (should
  5131. (equal "1"
  5132. (org-test-with-temp-text
  5133. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
  5134. (org-mode-restart)
  5135. (org-entry-get (point-max) "A" t))))
  5136. (should
  5137. (equal "0 1"
  5138. (org-test-with-temp-text
  5139. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
  5140. (org-mode-restart)
  5141. (org-entry-get (point-max) "A" t)))))
  5142. (ert-deftest test-org/entry-properties ()
  5143. "Test `org-entry-properties' specifications."
  5144. ;; Get "ITEM" property.
  5145. (should
  5146. (equal "H"
  5147. (org-test-with-temp-text "* TODO H"
  5148. (cdr (assoc "ITEM" (org-entry-properties nil "ITEM"))))))
  5149. (should
  5150. (equal "H"
  5151. (org-test-with-temp-text "* TODO H"
  5152. (cdr (assoc "ITEM" (org-entry-properties))))))
  5153. ;; Get "TODO" property. TODO keywords are case sensitive.
  5154. (should
  5155. (equal "TODO"
  5156. (org-test-with-temp-text "* TODO H"
  5157. (cdr (assoc "TODO" (org-entry-properties nil "TODO"))))))
  5158. (should
  5159. (equal "TODO"
  5160. (org-test-with-temp-text "* TODO H"
  5161. (cdr (assoc "TODO" (org-entry-properties))))))
  5162. (should-not
  5163. (org-test-with-temp-text "* H"
  5164. (assoc "TODO" (org-entry-properties nil "TODO"))))
  5165. (should-not
  5166. (org-test-with-temp-text "* todo H"
  5167. (assoc "TODO" (org-entry-properties nil "TODO"))))
  5168. ;; Get "PRIORITY" property.
  5169. (should
  5170. (equal "A"
  5171. (org-test-with-temp-text "* [#A] H"
  5172. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  5173. (should
  5174. (equal "A"
  5175. (org-test-with-temp-text "* [#A] H"
  5176. (cdr (assoc "PRIORITY" (org-entry-properties))))))
  5177. (should
  5178. (equal (char-to-string org-default-priority)
  5179. (org-test-with-temp-text "* H"
  5180. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  5181. ;; Get "FILE" property.
  5182. (should
  5183. (org-test-with-temp-text-in-file "* H\nParagraph"
  5184. (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil "FILE")))
  5185. (buffer-file-name))))
  5186. (should
  5187. (org-test-with-temp-text-in-file "* H\nParagraph"
  5188. (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
  5189. (buffer-file-name))))
  5190. (should-not
  5191. (org-test-with-temp-text "* H\nParagraph"
  5192. (cdr (assoc "FILE" (org-entry-properties nil "FILE")))))
  5193. ;; Get "TAGS" property.
  5194. (should
  5195. (equal ":tag1:tag2:"
  5196. (org-test-with-temp-text "* H :tag1:tag2:"
  5197. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS"))))))
  5198. (should
  5199. (equal ":tag1:tag2:"
  5200. (org-test-with-temp-text "* H :tag1:tag2:"
  5201. (cdr (assoc "TAGS" (org-entry-properties))))))
  5202. (should-not
  5203. (org-test-with-temp-text "* H"
  5204. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS")))))
  5205. ;; Get "ALLTAGS" property.
  5206. (should
  5207. (equal ":tag1:tag2:"
  5208. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  5209. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS"))))))
  5210. (should
  5211. (equal ":tag1:tag2:"
  5212. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  5213. (cdr (assoc "ALLTAGS" (org-entry-properties))))))
  5214. (should-not
  5215. (org-test-with-temp-text "* H"
  5216. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS")))))
  5217. ;; Get "BLOCKED" property.
  5218. (should
  5219. (equal "t"
  5220. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  5221. (let ((org-enforce-todo-dependencies t)
  5222. (org-blocker-hook
  5223. '(org-block-todo-from-children-or-siblings-or-parent)))
  5224. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  5225. (should
  5226. (equal ""
  5227. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  5228. (let ((org-enforce-todo-dependencies t)
  5229. (org-blocker-hook
  5230. '(org-block-todo-from-children-or-siblings-or-parent)))
  5231. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  5232. ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
  5233. (should
  5234. (equal
  5235. "[2012-03-29 thu.]"
  5236. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  5237. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED"))))))
  5238. (should
  5239. (equal
  5240. "[2012-03-29 thu.]"
  5241. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  5242. (cdr (assoc "CLOSED" (org-entry-properties))))))
  5243. (should-not
  5244. (org-test-with-temp-text "* H"
  5245. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED")))))
  5246. (should
  5247. (equal
  5248. "<2014-03-04 tue.>"
  5249. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5250. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE"))))))
  5251. (should
  5252. (equal
  5253. "<2014-03-04 tue.>"
  5254. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5255. (cdr (assoc "DEADLINE" (org-entry-properties))))))
  5256. (should-not
  5257. (org-test-with-temp-text "* H"
  5258. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE")))))
  5259. (should
  5260. (equal
  5261. "<2014-03-04 tue.>"
  5262. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5263. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED"))))))
  5264. (should
  5265. (equal
  5266. "<2014-03-04 tue.>"
  5267. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5268. (cdr (assoc "SCHEDULED" (org-entry-properties))))))
  5269. (should-not
  5270. (org-test-with-temp-text "* H"
  5271. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED")))))
  5272. ;; Get "CATEGORY"
  5273. (should
  5274. (equal "cat"
  5275. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  5276. (cdr (assoc "CATEGORY" (org-entry-properties))))))
  5277. (should
  5278. (equal "cat"
  5279. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  5280. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5281. (should
  5282. (equal "cat"
  5283. (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
  5284. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5285. (should
  5286. (equal "cat2"
  5287. (org-test-with-temp-text
  5288. (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  5289. "\n"
  5290. "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
  5291. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5292. ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
  5293. (should
  5294. (equal "<2012-03-29 thu.>"
  5295. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
  5296. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  5297. (should
  5298. (equal "[2012-03-29 thu.]"
  5299. (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
  5300. (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
  5301. (should
  5302. (equal "<2012-03-29 thu.>"
  5303. (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
  5304. (cdr (assoc "TIMESTAMP" (org-entry-properties nil "TIMESTAMP"))))))
  5305. (should
  5306. (equal "[2014-03-04 tue.]"
  5307. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
  5308. (cdr (assoc "TIMESTAMP_IA"
  5309. (org-entry-properties nil "TIMESTAMP_IA"))))))
  5310. (should-not
  5311. (equal "<2012-03-29 thu.>"
  5312. (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
  5313. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  5314. ;; Get standard properties.
  5315. (should
  5316. (equal "1"
  5317. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5318. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5319. ;; Handle extended properties.
  5320. (should
  5321. (equal "1 2 3"
  5322. (org-test-with-temp-text
  5323. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5324. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5325. (should
  5326. (equal "1 2 3"
  5327. (org-test-with-temp-text
  5328. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
  5329. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5330. ;; Ignore forbidden (special) properties.
  5331. (should-not
  5332. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
  5333. (cdr (assoc "TODO" (org-entry-properties nil 'standard))))))
  5334. (ert-deftest test-org/entry-put ()
  5335. "Test `org-entry-put' specifications."
  5336. ;; Error when not a string or nil.
  5337. (should-error
  5338. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5339. (org-entry-put 1 "test" 2)))
  5340. ;; Error when property name is invalid.
  5341. (should-error
  5342. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5343. (org-entry-put 1 "no space" "value")))
  5344. (should-error
  5345. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5346. (org-entry-put 1 "" "value")))
  5347. ;; Set "TODO" property.
  5348. (should
  5349. (string-match (regexp-quote " TODO H")
  5350. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  5351. (org-entry-put (point) "TODO" "TODO")
  5352. (buffer-string))))
  5353. (should
  5354. (string-match (regexp-quote "* H")
  5355. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  5356. (org-entry-put (point) "TODO" nil)
  5357. (buffer-string))))
  5358. ;; Set "PRIORITY" property.
  5359. (should
  5360. (equal "* [#A] H"
  5361. (org-test-with-temp-text "* [#B] H"
  5362. (org-entry-put (point) "PRIORITY" "A")
  5363. (buffer-string))))
  5364. (should
  5365. (equal "* H"
  5366. (org-test-with-temp-text "* [#B] H"
  5367. (org-entry-put (point) "PRIORITY" nil)
  5368. (buffer-string))))
  5369. ;; Set "SCHEDULED" property.
  5370. (should
  5371. (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
  5372. (org-test-with-temp-text "* H"
  5373. (org-entry-put (point) "SCHEDULED" "2014-03-04")
  5374. (buffer-string))))
  5375. (should
  5376. (string= "* H\n"
  5377. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5378. (org-entry-put (point) "SCHEDULED" nil)
  5379. (buffer-string))))
  5380. (should
  5381. (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
  5382. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5383. (org-entry-put (point) "SCHEDULED" "earlier")
  5384. (buffer-string))))
  5385. (should
  5386. (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
  5387. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5388. (org-entry-put (point) "SCHEDULED" "later")
  5389. (buffer-string))))
  5390. ;; Set "DEADLINE" property.
  5391. (should
  5392. (string-match "^ *DEADLINE: <2014-03-04 .*?>"
  5393. (org-test-with-temp-text "* H"
  5394. (org-entry-put (point) "DEADLINE" "2014-03-04")
  5395. (buffer-string))))
  5396. (should
  5397. (string= "* H\n"
  5398. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5399. (org-entry-put (point) "DEADLINE" nil)
  5400. (buffer-string))))
  5401. (should
  5402. (string-match "^ *DEADLINE: <2014-03-03 .*?>"
  5403. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5404. (org-entry-put (point) "DEADLINE" "earlier")
  5405. (buffer-string))))
  5406. (should
  5407. (string-match "^ *DEADLINE: <2014-03-05 .*?>"
  5408. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5409. (org-entry-put (point) "DEADLINE" "later")
  5410. (buffer-string))))
  5411. ;; Set "CATEGORY" property
  5412. (should
  5413. (string-match "^ *:CATEGORY: cat"
  5414. (org-test-with-temp-text "* H"
  5415. (org-entry-put (point) "CATEGORY" "cat")
  5416. (buffer-string))))
  5417. ;; Regular properties, with or without pre-existing drawer.
  5418. (should
  5419. (string-match "^ *:A: +2$"
  5420. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5421. (org-entry-put (point) "A" "2")
  5422. (buffer-string))))
  5423. (should
  5424. (string-match "^ *:A: +1$"
  5425. (org-test-with-temp-text "* H"
  5426. (org-entry-put (point) "A" "1")
  5427. (buffer-string))))
  5428. ;; Special case: two consecutive headlines.
  5429. (should
  5430. (string-match "\\* A\n *:PROPERTIES:"
  5431. (org-test-with-temp-text "* A\n** B"
  5432. (org-entry-put (point) "A" "1")
  5433. (buffer-string)))))
  5434. (ert-deftest test-org/refresh-properties ()
  5435. "Test `org-refresh-properties' specifications."
  5436. (should
  5437. (equal "1"
  5438. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5439. (org-refresh-properties "A" 'org-test)
  5440. (get-text-property (point) 'org-test))))
  5441. (should-not
  5442. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5443. (org-refresh-properties "B" 'org-test)
  5444. (get-text-property (point) 'org-test)))
  5445. ;; Handle properties only defined with extension syntax, i.e.,
  5446. ;; "PROPERTY+".
  5447. (should
  5448. (equal "1"
  5449. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
  5450. (org-refresh-properties "A" 'org-test)
  5451. (get-text-property (point) 'org-test))))
  5452. ;; When property is inherited, add text property to the whole
  5453. ;; sub-tree.
  5454. (should
  5455. (equal "1"
  5456. (org-test-with-temp-text
  5457. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
  5458. (let ((org-use-property-inheritance t))
  5459. (org-refresh-properties "A" 'org-test))
  5460. (get-text-property (point) 'org-test))))
  5461. ;; When property is inherited, use global value across the whole
  5462. ;; buffer. However local values have precedence.
  5463. (should-not
  5464. (equal "1"
  5465. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  5466. (org-mode-restart)
  5467. (let ((org-use-property-inheritance nil))
  5468. (org-refresh-properties "A" 'org-test))
  5469. (get-text-property (point) 'org-test))))
  5470. (should
  5471. (equal "1"
  5472. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  5473. (org-mode-restart)
  5474. (let ((org-use-property-inheritance t))
  5475. (org-refresh-properties "A" 'org-test))
  5476. (get-text-property (point) 'org-test))))
  5477. (should
  5478. (equal "2"
  5479. (org-test-with-temp-text
  5480. "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
  5481. (org-mode-restart)
  5482. (let ((org-use-property-inheritance t))
  5483. (org-refresh-properties "A" 'org-test))
  5484. (get-text-property (point) 'org-test)))))
  5485. ;;; Radio Targets
  5486. (ert-deftest test-org/update-radio-target-regexp ()
  5487. "Test `org-update-radio-target-regexp' specifications."
  5488. ;; Properly update cache with no previous radio target regexp.
  5489. (should
  5490. (eq 'link
  5491. (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
  5492. (save-excursion (goto-char (point-max)) (org-element-context))
  5493. (insert "<<<")
  5494. (search-forward "o")
  5495. (insert ">>>")
  5496. (org-update-radio-target-regexp)
  5497. (goto-char (point-max))
  5498. (org-element-type (org-element-context)))))
  5499. ;; Properly update cache with previous radio target regexp.
  5500. (should
  5501. (eq 'link
  5502. (org-test-with-temp-text "radio\n\nParagraph\n\nradio"
  5503. (save-excursion (goto-char (point-max)) (org-element-context))
  5504. (insert "<<<")
  5505. (search-forward "o")
  5506. (insert ">>>")
  5507. (org-update-radio-target-regexp)
  5508. (search-backward "r")
  5509. (delete-char 5)
  5510. (insert "new")
  5511. (org-update-radio-target-regexp)
  5512. (goto-char (point-max))
  5513. (delete-region (line-beginning-position) (point))
  5514. (insert "new")
  5515. (org-element-type (org-element-context))))))
  5516. ;;; Refile
  5517. (ert-deftest test-org/refile-get-targets ()
  5518. "Test `org-refile-get-targets' specifications."
  5519. ;; :maxlevel includes all headings above specified value.
  5520. (should
  5521. (equal '("H1" "H2" "H3")
  5522. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  5523. (let ((org-refile-use-outline-path nil)
  5524. (org-refile-targets `((nil :maxlevel . 3))))
  5525. (mapcar #'car (org-refile-get-targets))))))
  5526. (should
  5527. (equal '("H1" "H2")
  5528. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  5529. (let ((org-refile-use-outline-path nil)
  5530. (org-refile-targets `((nil :maxlevel . 2))))
  5531. (mapcar #'car (org-refile-get-targets))))))
  5532. ;; :level limits targets to headlines with the specified level.
  5533. (should
  5534. (equal '("H2")
  5535. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  5536. (let ((org-refile-use-outline-path nil)
  5537. (org-refile-targets `((nil :level . 2))))
  5538. (mapcar #'car (org-refile-get-targets))))))
  5539. ;; :tag limits targets to headlines with specified tag.
  5540. (should
  5541. (equal '("H1")
  5542. (org-test-with-temp-text "* H1 :foo:\n** H2\n*** H3 :bar:"
  5543. (let ((org-refile-use-outline-path nil)
  5544. (org-refile-targets `((nil :tag . "foo"))))
  5545. (mapcar #'car (org-refile-get-targets))))))
  5546. ;; :todo limits targets to headlines with specified TODO keyword.
  5547. (should
  5548. (equal '("H2")
  5549. (org-test-with-temp-text "* H1\n** TODO H2\n*** DONE H3"
  5550. (let ((org-refile-use-outline-path nil)
  5551. (org-refile-targets `((nil :todo . "TODO"))))
  5552. (mapcar #'car (org-refile-get-targets))))))
  5553. ;; :regexp filters targets matching provided regexp.
  5554. (should
  5555. (equal '("F2" "F3")
  5556. (org-test-with-temp-text "* H1\n** F2\n*** F3"
  5557. (let ((org-refile-use-outline-path nil)
  5558. (org-refile-targets `((nil :regexp . "F"))))
  5559. (mapcar #'car (org-refile-get-targets))))))
  5560. ;; A nil `org-refile-targets' includes only top level headlines in
  5561. ;; current buffer.
  5562. (should
  5563. (equal '("H1" "H2")
  5564. (org-test-with-temp-text "* H1\n** S1\n* H2"
  5565. (let ((org-refile-use-outline-path nil)
  5566. (org-refile-targets nil))
  5567. (mapcar #'car (org-refile-get-targets))))))
  5568. ;; Return value is the union of the targets according to all the
  5569. ;; defined rules. However, prevent duplicates.
  5570. (should
  5571. (equal '("F2" "F3" "H1")
  5572. (org-test-with-temp-text "* TODO H1\n** F2\n*** F3"
  5573. (let ((org-refile-use-outline-path nil)
  5574. (org-refile-targets `((nil :regexp . "F")
  5575. (nil :todo . "TODO"))))
  5576. (mapcar #'car (org-refile-get-targets))))))
  5577. (should
  5578. (equal '("F2" "F3" "H1")
  5579. (org-test-with-temp-text "* TODO H1\n** TODO F2\n*** F3"
  5580. (let ((org-refile-use-outline-path nil)
  5581. (org-refile-targets `((nil :regexp . "F")
  5582. (nil :todo . "TODO"))))
  5583. (mapcar #'car (org-refile-get-targets))))))
  5584. ;; When `org-refile-use-outline-path' is non-nil, provide targets as
  5585. ;; paths.
  5586. (should
  5587. (equal '("H1" "H1/H2" "H1/H2/H3")
  5588. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  5589. (let ((org-refile-use-outline-path t)
  5590. (org-refile-targets `((nil :maxlevel . 3))))
  5591. (mapcar #'car (org-refile-get-targets))))))
  5592. ;; When providing targets as paths, escape forward slashes in
  5593. ;; headings with backslashes.
  5594. (should
  5595. (equal '("H1\\/foo")
  5596. (org-test-with-temp-text "* H1/foo"
  5597. (let ((org-refile-use-outline-path t)
  5598. (org-refile-targets `((nil :maxlevel . 1))))
  5599. (mapcar #'car (org-refile-get-targets))))))
  5600. ;; When `org-refile-use-outline-path' is `file', include file name
  5601. ;; without directory in targets.
  5602. (should
  5603. (org-test-with-temp-text-in-file "* H1"
  5604. (let* ((filename (buffer-file-name))
  5605. (org-refile-use-outline-path 'file)
  5606. (org-refile-targets `(((,filename) :level . 1))))
  5607. (member (file-name-nondirectory filename)
  5608. (mapcar #'car (org-refile-get-targets))))))
  5609. ;; When `org-refile-use-outline-path' is `full-file-path', include
  5610. ;; full file name.
  5611. (should
  5612. (org-test-with-temp-text-in-file "* H1"
  5613. (let* ((filename (file-truename (buffer-file-name)))
  5614. (org-refile-use-outline-path 'full-file-path)
  5615. (org-refile-targets `(((,filename) :level . 1))))
  5616. (member filename (mapcar #'car (org-refile-get-targets))))))
  5617. ;; When `org-refile-use-outline-path' is `buffer-name', include
  5618. ;; buffer name.
  5619. (should
  5620. (org-test-with-temp-text "* H1"
  5621. (let* ((org-refile-use-outline-path 'buffer-name)
  5622. (org-refile-targets `((nil :level . 1))))
  5623. (member (buffer-name) (mapcar #'car (org-refile-get-targets)))))))
  5624. ;;; Sparse trees
  5625. (ert-deftest test-org/match-sparse-tree ()
  5626. "Test `org-match-sparse-tree' specifications."
  5627. ;; Match tags.
  5628. (should-not
  5629. (org-test-with-temp-text "* H\n** H1 :tag:"
  5630. (org-match-sparse-tree nil "tag")
  5631. (search-forward "H1")
  5632. (org-invisible-p2)))
  5633. (should
  5634. (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
  5635. (org-match-sparse-tree nil "tag")
  5636. (search-forward "H2")
  5637. (org-invisible-p2)))
  5638. ;; "-" operator for tags.
  5639. (should-not
  5640. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  5641. (org-match-sparse-tree nil "tag1-tag2")
  5642. (search-forward "H1")
  5643. (org-invisible-p2)))
  5644. (should
  5645. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  5646. (org-match-sparse-tree nil "tag1-tag2")
  5647. (search-forward "H2")
  5648. (org-invisible-p2)))
  5649. ;; "&" operator for tags.
  5650. (should
  5651. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  5652. (org-match-sparse-tree nil "tag1&tag2")
  5653. (search-forward "H1")
  5654. (org-invisible-p2)))
  5655. (should-not
  5656. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  5657. (org-match-sparse-tree nil "tag1&tag2")
  5658. (search-forward "H2")
  5659. (org-invisible-p2)))
  5660. ;; "|" operator for tags.
  5661. (should-not
  5662. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  5663. (org-match-sparse-tree nil "tag1|tag2")
  5664. (search-forward "H1")
  5665. (org-invisible-p2)))
  5666. (should-not
  5667. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  5668. (org-match-sparse-tree nil "tag1|tag2")
  5669. (search-forward "H2")
  5670. (org-invisible-p2)))
  5671. ;; Regexp match on tags.
  5672. (should-not
  5673. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  5674. (org-match-sparse-tree nil "{^tag.*}")
  5675. (search-forward "H1")
  5676. (org-invisible-p2)))
  5677. (should
  5678. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  5679. (org-match-sparse-tree nil "{^tag.*}")
  5680. (search-forward "H2")
  5681. (org-invisible-p2)))
  5682. ;; Match group tags.
  5683. (should-not
  5684. (org-test-with-temp-text
  5685. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  5686. (org-match-sparse-tree nil "work")
  5687. (search-forward "H1")
  5688. (org-invisible-p2)))
  5689. (should-not
  5690. (org-test-with-temp-text
  5691. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  5692. (org-match-sparse-tree nil "work")
  5693. (search-forward "H2")
  5694. (org-invisible-p2)))
  5695. ;; Match group tags with hard brackets.
  5696. (should-not
  5697. (org-test-with-temp-text
  5698. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  5699. (org-match-sparse-tree nil "work")
  5700. (search-forward "H1")
  5701. (org-invisible-p2)))
  5702. (should-not
  5703. (org-test-with-temp-text
  5704. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  5705. (org-match-sparse-tree nil "work")
  5706. (search-forward "H2")
  5707. (org-invisible-p2)))
  5708. ;; Match tags in hierarchies
  5709. (should-not
  5710. (org-test-with-temp-text
  5711. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  5712. #+TAGS: [ Lev_2 : Lev_3 ]\n
  5713. #+TAGS: { Lev_3 : Lev_4 }\n
  5714. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  5715. (org-match-sparse-tree nil "Lev_1")
  5716. (search-forward "H4")
  5717. (org-invisible-p2)))
  5718. (should-not
  5719. (org-test-with-temp-text
  5720. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  5721. #+TAGS: [ Lev_2 : Lev_3 ]\n
  5722. #+TAGS: { Lev_3 : Lev_4 }\n
  5723. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  5724. (org-match-sparse-tree nil "Lev_1+Lev_3")
  5725. (search-forward "H4")
  5726. (org-invisible-p2)))
  5727. ;; Match regular expressions in tags
  5728. (should-not
  5729. (org-test-with-temp-text
  5730. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
  5731. (org-match-sparse-tree nil "Lev")
  5732. (search-forward "H1")
  5733. (org-invisible-p2)))
  5734. (should
  5735. (org-test-with-temp-text
  5736. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
  5737. (org-match-sparse-tree nil "Lev")
  5738. (search-forward "H1")
  5739. (org-invisible-p2)))
  5740. ;; Match properties.
  5741. (should
  5742. (org-test-with-temp-text
  5743. "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
  5744. (org-match-sparse-tree nil "A=\"1\"")
  5745. (search-forward "H2")
  5746. (org-invisible-p2)))
  5747. (should-not
  5748. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  5749. (org-match-sparse-tree nil "A=\"1\"")
  5750. (search-forward "H2")
  5751. (org-invisible-p2)))
  5752. ;; Case is not significant when matching properties.
  5753. (should-not
  5754. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  5755. (org-match-sparse-tree nil "a=\"1\"")
  5756. (search-forward "H2")
  5757. (org-invisible-p2)))
  5758. (should-not
  5759. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
  5760. (org-match-sparse-tree nil "A=\"1\"")
  5761. (search-forward "H2")
  5762. (org-invisible-p2)))
  5763. ;; Match special LEVEL property.
  5764. (should-not
  5765. (org-test-with-temp-text "* H\n** H1\n*** H2"
  5766. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  5767. (search-forward "H1")
  5768. (org-invisible-p2)))
  5769. (should
  5770. (org-test-with-temp-text "* H\n** H1\n*** H2"
  5771. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  5772. (search-forward "H2")
  5773. (org-invisible-p2)))
  5774. ;; Comparison operators when matching properties.
  5775. (should
  5776. (org-test-with-temp-text
  5777. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  5778. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  5779. (search-forward "H1")
  5780. (org-invisible-p2)))
  5781. (should-not
  5782. (org-test-with-temp-text
  5783. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  5784. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  5785. (search-forward "H2")
  5786. (org-invisible-p2)))
  5787. ;; Regexp match on properties values.
  5788. (should-not
  5789. (org-test-with-temp-text
  5790. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  5791. (org-match-sparse-tree nil "A={f.*}")
  5792. (search-forward "H1")
  5793. (org-invisible-p2)))
  5794. (should
  5795. (org-test-with-temp-text
  5796. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  5797. (org-match-sparse-tree nil "A={f.*}")
  5798. (search-forward "H2")
  5799. (org-invisible-p2)))
  5800. ;; With an optional argument, limit match to TODO entries.
  5801. (should-not
  5802. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  5803. (org-match-sparse-tree t "tag")
  5804. (search-forward "H1")
  5805. (org-invisible-p2)))
  5806. (should
  5807. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  5808. (org-match-sparse-tree t "tag")
  5809. (search-forward "H2")
  5810. (org-invisible-p2))))
  5811. (ert-deftest test-org/occur ()
  5812. "Test `org-occur' specifications."
  5813. ;; Count number of matches.
  5814. (should
  5815. (= 1
  5816. (org-test-with-temp-text "* H\nA\n* H2"
  5817. (org-occur "A"))))
  5818. (should
  5819. (= 2
  5820. (org-test-with-temp-text "* H\nA\n* H2\nA"
  5821. (org-occur "A"))))
  5822. ;; Test CALLBACK optional argument.
  5823. (should
  5824. (= 0
  5825. (org-test-with-temp-text "* H\nA\n* H2"
  5826. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  5827. (should
  5828. (= 1
  5829. (org-test-with-temp-text "* H\nA\n* H2\nA"
  5830. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  5831. ;; Case-fold searches according to `org-occur-case-fold-search'.
  5832. (should
  5833. (= 2
  5834. (org-test-with-temp-text "Aa"
  5835. (let ((org-occur-case-fold-search t)) (org-occur "A")))))
  5836. (should
  5837. (= 2
  5838. (org-test-with-temp-text "Aa"
  5839. (let ((org-occur-case-fold-search t)) (org-occur "a")))))
  5840. (should
  5841. (= 1
  5842. (org-test-with-temp-text "Aa"
  5843. (let ((org-occur-case-fold-search nil)) (org-occur "A")))))
  5844. (should
  5845. (= 1
  5846. (org-test-with-temp-text "Aa"
  5847. (let ((org-occur-case-fold-search nil)) (org-occur "a")))))
  5848. (should
  5849. (= 1
  5850. (org-test-with-temp-text "Aa"
  5851. (let ((org-occur-case-fold-search 'smart)) (org-occur "A")))))
  5852. (should
  5853. (= 2
  5854. (org-test-with-temp-text "Aa"
  5855. (let ((org-occur-case-fold-search 'smart)) (org-occur "a"))))))
  5856. ;;; Tags
  5857. (ert-deftest test-org/tag-string-to-alist ()
  5858. "Test `org-tag-string-to-alist' specifications."
  5859. ;; Tag without selection key.
  5860. (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
  5861. ;; Tag with selection key.
  5862. (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t))))
  5863. ;; Tag group.
  5864. (should
  5865. (equal
  5866. (org-tag-string-to-alist "[ group : t1 t2 ]")
  5867. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag))))
  5868. ;; Mutually exclusive tags.
  5869. (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
  5870. '((:startgroup) ("tag1") ("tag2") (:endgroup))))
  5871. (should
  5872. (equal
  5873. (org-tag-string-to-alist "{ group : tag1 tag2 }")
  5874. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))))
  5875. (ert-deftest test-org/tag-alist-to-string ()
  5876. "Test `org-tag-alist-to-string' specifications."
  5877. (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
  5878. (should (equal (org-tag-alist-to-string '(("tag1" . ?t))) "tag1(t)"))
  5879. (should
  5880. (equal
  5881. (org-tag-alist-to-string
  5882. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  5883. "[ group : t1 t2 ]"))
  5884. (should
  5885. (equal (org-tag-alist-to-string
  5886. '((:startgroup) ("tag1") ("tag2") (:endgroup)))
  5887. "{ tag1 tag2 }"))
  5888. (should
  5889. (equal
  5890. (org-tag-alist-to-string
  5891. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))
  5892. "{ group : tag1 tag2 }")))
  5893. (ert-deftest test-org/tag-alist-to-groups ()
  5894. "Test `org-tag-alist-to-groups' specifications."
  5895. (should
  5896. (equal (org-tag-alist-to-groups
  5897. '((:startgroup) ("group") (:grouptags) ("t1") ("t2") (:endgroup)))
  5898. '(("group" "t1" "t2"))))
  5899. (should
  5900. (equal
  5901. (org-tag-alist-to-groups
  5902. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  5903. '(("group" "t1" "t2"))))
  5904. (should-not
  5905. (org-tag-alist-to-groups
  5906. '((:startgroup) ("group") ("t1") ("t2") (:endgroup)))))
  5907. (ert-deftest test-org/tag-align ()
  5908. "Test tags alignment."
  5909. ;; Test aligning tags with different display width.
  5910. (should
  5911. ;; 12345678901234567890
  5912. (equal "* Test :abc:"
  5913. (org-test-with-temp-text "* Test :abc:"
  5914. (let ((org-tags-column -20)
  5915. (indent-tabs-mode nil))
  5916. (org-fix-tags-on-the-fly))
  5917. (buffer-string))))
  5918. (should
  5919. ;; 12345678901234567890
  5920. (equal "* Test :日本語:"
  5921. (org-test-with-temp-text "* Test :日本語:"
  5922. (let ((org-tags-column -20)
  5923. (indent-tabs-mode nil))
  5924. (org-fix-tags-on-the-fly))
  5925. (buffer-string))))
  5926. ;; Make sure aligning tags do not skip invisible text.
  5927. (should
  5928. (equal "* [[linkx]] :tag:"
  5929. (org-test-with-temp-text "* [[link<point>]] :tag:"
  5930. (let ((org-tags-column 0))
  5931. (org-fix-tags-on-the-fly)
  5932. (insert "x")
  5933. (buffer-string)))))
  5934. ;; Aligning tags preserve position.
  5935. (should
  5936. (= 6 (org-test-with-temp-text "* 345 <point> :tag:"
  5937. (let ((org-tags-column 78)
  5938. (indent-tabs-mode nil))
  5939. (org-fix-tags-on-the-fly))
  5940. (current-column)))))
  5941. (ert-deftest test-org/get-tags ()
  5942. "Test `org-get-tags' specifications."
  5943. ;; Standard test.
  5944. (should
  5945. (equal '("foo")
  5946. (org-test-with-temp-text "* Test :foo:" (org-get-tags))))
  5947. (should
  5948. (equal '("foo" "bar")
  5949. (org-test-with-temp-text "* Test :foo:bar:" (org-get-tags))))
  5950. ;; Return nil when there is no tag.
  5951. (should-not
  5952. (org-test-with-temp-text "* Test" (org-get-tags)))
  5953. ;; Tags are inherited from parent headlines.
  5954. (should
  5955. (equal '("tag")
  5956. (let ((org-use-tag-inheritance t))
  5957. (org-test-with-temp-text "* H0 :foo:\n* H1 :tag:\n<point>** H2"
  5958. (org-get-tags)))))
  5959. ;; Tags are inherited from `org-file-tags'.
  5960. (should
  5961. (equal '("tag")
  5962. (org-test-with-temp-text "* H1"
  5963. (let ((org-file-tags '("tag"))
  5964. (org-use-tag-inheritance t))
  5965. (org-get-tags)))))
  5966. ;; Only inherited tags have the `inherited' text property.
  5967. (should
  5968. (get-text-property 0 'inherited
  5969. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  5970. (let ((org-use-tag-inheritance t))
  5971. (assoc-string "foo" (org-get-tags))))))
  5972. (should-not
  5973. (get-text-property 0 'inherited
  5974. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  5975. (let ((org-use-tag-inheritance t))
  5976. (assoc-string "bar" (org-get-tags))))))
  5977. ;; Obey to `org-use-tag-inheritance'.
  5978. (should-not
  5979. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  5980. (let ((org-use-tag-inheritance nil))
  5981. (assoc-string "foo" (org-get-tags)))))
  5982. (should-not
  5983. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  5984. (let ((org-use-tag-inheritance nil)
  5985. (org-file-tags '("foo")))
  5986. (assoc-string "foo" (org-get-tags)))))
  5987. (should-not
  5988. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  5989. (let ((org-use-tag-inheritance '("bar")))
  5990. (assoc-string "foo" (org-get-tags)))))
  5991. (should
  5992. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  5993. (let ((org-use-tag-inheritance '("bar")))
  5994. (assoc-string "bar" (org-get-tags)))))
  5995. (should-not
  5996. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  5997. (let ((org-use-tag-inheritance "b.*"))
  5998. (assoc-string "foo" (org-get-tags)))))
  5999. (should
  6000. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6001. (let ((org-use-tag-inheritance "b.*"))
  6002. (assoc-string "bar" (org-get-tags)))))
  6003. ;; When optional argument LOCAL is non-nil, ignore tag inheritance.
  6004. (should
  6005. (equal '("baz")
  6006. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6007. (let ((org-use-tag-inheritance t))
  6008. (org-get-tags nil t)))))
  6009. ;; When optional argument POS is non-nil, get tags there instead.
  6010. (should
  6011. (equal '("foo")
  6012. (org-test-with-temp-text "* H1 :foo:\n* <point>H2 :bar:"
  6013. (org-get-tags 1))))
  6014. ;; Make sure tags excluded from inheritance are returned if local
  6015. (should
  6016. (equal '("foo")
  6017. (org-test-with-temp-text "* Test :foo:"
  6018. (let ((org-use-tag-inheritance t)
  6019. (org-tags-exclude-from-inheritance '("foo")))
  6020. (org-get-tags)))))
  6021. ;; Pathological case: tagged headline with an empty body.
  6022. (should (org-test-with-temp-text "* :tag:" (org-get-tags))))
  6023. (ert-deftest test-org/set-tags ()
  6024. "Test `org-set-tags' specifications."
  6025. ;; Throw an error on invalid data.
  6026. (should-error
  6027. (org-test-with-temp-text "* H"
  6028. (org-set-tags 'foo)))
  6029. ;; `nil', an empty, and a blank string remove all tags.
  6030. (should
  6031. (equal "* H"
  6032. (org-test-with-temp-text "* H :tag1:tag2:"
  6033. (org-set-tags nil)
  6034. (buffer-string))))
  6035. (should
  6036. (equal "* H"
  6037. (org-test-with-temp-text "* H :tag1:tag2:"
  6038. (org-set-tags "")
  6039. (buffer-string))))
  6040. (should
  6041. (equal "* H"
  6042. (org-test-with-temp-text "* H :tag1:tag2:"
  6043. (org-set-tags " ")
  6044. (buffer-string))))
  6045. ;; If there's nothing to remove, just bail out.
  6046. (should
  6047. (equal "* H"
  6048. (org-test-with-temp-text "* H"
  6049. (org-set-tags nil)
  6050. (buffer-string))))
  6051. (should
  6052. (equal "* "
  6053. (org-test-with-temp-text "* "
  6054. (org-set-tags nil)
  6055. (buffer-string))))
  6056. ;; If DATA is a tag string, set current tags to it, even if it means
  6057. ;; replacing old tags.
  6058. (should
  6059. (equal "* H :tag0:"
  6060. (org-test-with-temp-text "* H :tag1:tag2:"
  6061. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  6062. (buffer-string))))
  6063. (should
  6064. (equal "* H :tag0:"
  6065. (org-test-with-temp-text "* H"
  6066. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  6067. (buffer-string))))
  6068. ;; If DATA is a list, set tags to this list, even if it means
  6069. ;; replacing old tags.
  6070. (should
  6071. (equal "* H :tag0:"
  6072. (org-test-with-temp-text "* H :tag1:tag2:"
  6073. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6074. (buffer-string))))
  6075. (should
  6076. (equal "* H :tag0:"
  6077. (org-test-with-temp-text "* H"
  6078. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6079. (buffer-string))))
  6080. ;; When set, apply `org-tags-sort-function'.
  6081. (should
  6082. (equal "* H :a:b:"
  6083. (org-test-with-temp-text "* H"
  6084. (let ((org-tags-column 1)
  6085. (org-tags-sort-function #'string<))
  6086. (org-set-tags '("b" "a"))
  6087. (buffer-string)))))
  6088. ;; When new tags are identical to the previous ones, still align.
  6089. (should
  6090. (equal "* H :foo:"
  6091. (org-test-with-temp-text "* H :foo:"
  6092. (let ((org-tags-column 1))
  6093. (org-set-tags '("foo"))
  6094. (buffer-string)))))
  6095. ;; When tags have been changed, run `org-after-tags-change-hook'.
  6096. (should
  6097. (catch :return
  6098. (org-test-with-temp-text "* H :foo:"
  6099. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  6100. (org-set-tags '("bar"))
  6101. nil))))
  6102. (should-not
  6103. (catch :return
  6104. (org-test-with-temp-text "* H :foo:"
  6105. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  6106. (org-set-tags '("foo"))
  6107. nil))))
  6108. ;; Special case: handle empty headlines.
  6109. (should
  6110. (equal "* :tag0:"
  6111. (org-test-with-temp-text "* "
  6112. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6113. (buffer-string))))
  6114. ;; Modify buffer only when a tag change happens or alignment is
  6115. ;; done.
  6116. (should-not
  6117. (org-test-with-temp-text "* H :foo:"
  6118. (set-buffer-modified-p nil)
  6119. (let ((org-tags-column 1)) (org-set-tags '("foo")))
  6120. (buffer-modified-p)))
  6121. (should
  6122. (org-test-with-temp-text "* H :foo:"
  6123. (set-buffer-modified-p nil)
  6124. (let ((org-tags-column 10)) (org-set-tags '("foo")))
  6125. (buffer-modified-p)))
  6126. (should
  6127. (org-test-with-temp-text "* H :foo:"
  6128. (set-buffer-modified-p nil)
  6129. (let ((org-tags-column 10)) (org-set-tags '("bar")))
  6130. (buffer-modified-p)))
  6131. ;; Pathological case: when setting tags of a folded headline, do not
  6132. ;; let new tags being sucked into invisibility.
  6133. (should-not
  6134. (org-test-with-temp-text "* H1\nContent\n* H2\n\n Other Content"
  6135. ;; Show only headlines
  6136. (org-content)
  6137. ;; Set NEXT tag on current entry
  6138. (org-set-tags ":NEXT:")
  6139. ;; Move point to that NEXT tag
  6140. (search-forward "NEXT") (backward-word)
  6141. ;; And it should be visible (i.e. no overlays)
  6142. (overlays-at (point)))))
  6143. (ert-deftest test-org/set-tags-command ()
  6144. "Test `org-set-tags-command' specifications"
  6145. ;; Set tags at current headline.
  6146. (should
  6147. (equal "* H1 :foo:"
  6148. (org-test-with-temp-text "* H1"
  6149. (cl-letf (((symbol-function 'completing-read)
  6150. (lambda (&rest args) ":foo:")))
  6151. (let ((org-use-fast-tag-selection nil)
  6152. (org-tags-column 1))
  6153. (org-set-tags-command)))
  6154. (buffer-string))))
  6155. ;; Preserve position when called from the section below.
  6156. (should
  6157. (equal "* H1 :foo:\nContents"
  6158. (org-test-with-temp-text "* H1\n<point>Contents"
  6159. (cl-letf (((symbol-function 'completing-read)
  6160. (lambda (&rest args) ":foo:")))
  6161. (let ((org-use-fast-tag-selection nil)
  6162. (org-tags-column 1))
  6163. (org-set-tags-command)))
  6164. (buffer-string))))
  6165. (should-not
  6166. (equal "* H1 :foo:\nContents2"
  6167. (org-test-with-temp-text "* H1\n<point>Contents2"
  6168. (cl-letf (((symbol-function 'completing-read)
  6169. (lambda (&rest args) ":foo:")))
  6170. (let ((org-use-fast-tag-selection nil)
  6171. (org-tags-column 1))
  6172. (org-set-tags-command)))
  6173. (org-at-heading-p))))
  6174. ;; Strip all forbidden characters from user-entered tags.
  6175. (should
  6176. (equal "* H1 :foo:"
  6177. (org-test-with-temp-text "* H1"
  6178. (cl-letf (((symbol-function 'completing-read)
  6179. (lambda (&rest args) ": foo *:")))
  6180. (let ((org-use-fast-tag-selection nil)
  6181. (org-tags-column 1))
  6182. (org-set-tags-command)))
  6183. (buffer-string))))
  6184. ;; When a region is active and
  6185. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  6186. ;; same value in all headlines in region.
  6187. (should
  6188. (equal "* H1 :foo:\nContents\n* H2 :foo:"
  6189. (org-test-with-temp-text "* H1\nContents\n* H2"
  6190. (cl-letf (((symbol-function 'completing-read)
  6191. (lambda (&rest args) ":foo:")))
  6192. (let ((org-use-fast-tag-selection nil)
  6193. (org-loop-over-headlines-in-active-region t)
  6194. (org-tags-column 1))
  6195. (transient-mark-mode 1)
  6196. (push-mark (point) t t)
  6197. (goto-char (point-max))
  6198. (org-set-tags-command)))
  6199. (buffer-string))))
  6200. (should
  6201. (equal "* H1\nContents\n* H2 :foo:"
  6202. (org-test-with-temp-text "* H1\nContents\n* H2"
  6203. (cl-letf (((symbol-function 'completing-read)
  6204. (lambda (&rest args) ":foo:")))
  6205. (let ((org-use-fast-tag-selection nil)
  6206. (org-loop-over-headlines-in-active-region nil)
  6207. (org-tags-column 1))
  6208. (transient-mark-mode 1)
  6209. (push-mark (point) t t)
  6210. (goto-char (point-max))
  6211. (org-set-tags-command)))
  6212. (buffer-string))))
  6213. ;; With a non-nil prefix argument, align all tags in the buffer.
  6214. (should
  6215. (equal "* H1 :foo:\n* H2 :bar:"
  6216. (org-test-with-temp-text "* H1 :foo:\n* H2 :bar:"
  6217. (let ((org-tags-column 1)) (org-set-tags-command t))
  6218. (buffer-string)))))
  6219. (ert-deftest test-org/toggle-tag ()
  6220. "Test `org-toggle-tag' specifications."
  6221. ;; Insert missing tag.
  6222. (should
  6223. (equal "* H :tag:"
  6224. (org-test-with-temp-text "* H"
  6225. (let ((org-tags-column 1)) (org-toggle-tag "tag"))
  6226. (buffer-string))))
  6227. (should
  6228. (equal "* H :tag1:tag2:"
  6229. (org-test-with-temp-text "* H :tag1:"
  6230. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  6231. (buffer-string))))
  6232. ;; Remove existing tag.
  6233. (should
  6234. (equal "* H"
  6235. (org-test-with-temp-text "* H :tag:"
  6236. (org-toggle-tag "tag")
  6237. (buffer-string))))
  6238. (should
  6239. (equal "* H :tag1:"
  6240. (org-test-with-temp-text "* H :tag1:tag2:"
  6241. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  6242. (buffer-string))))
  6243. (should
  6244. (equal "* H :tag2:"
  6245. (org-test-with-temp-text "* H :tag1:tag2:"
  6246. (let ((org-tags-column 1)) (org-toggle-tag "tag1"))
  6247. (buffer-string))))
  6248. ;; With optional argument ONOFF set to `on', try to insert the tag,
  6249. ;; even if its already there.
  6250. (should
  6251. (equal "* H :tag:"
  6252. (org-test-with-temp-text "* H"
  6253. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  6254. (buffer-string))))
  6255. (should
  6256. (equal "* H :tag:"
  6257. (org-test-with-temp-text "* H :tag:"
  6258. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  6259. (buffer-string))))
  6260. ;; With optional argument ONOFF set to `off', try to remove the tag,
  6261. ;; even if its not there.
  6262. (should
  6263. (equal "* H"
  6264. (org-test-with-temp-text "* H :tag:"
  6265. (org-toggle-tag "tag" 'off)
  6266. (buffer-string))))
  6267. (should
  6268. (equal "* H :tag:"
  6269. (org-test-with-temp-text "* H :tag:"
  6270. (let ((org-tags-column 1)) (org-toggle-tag "foo" 'off))
  6271. (buffer-string))))
  6272. ;; Special case: Handle properly tag inheritance. In particular, do
  6273. ;; not set inherited tags.
  6274. (should
  6275. (equal "* H1 :tag:\n** H2 :tag2:tag:"
  6276. (org-test-with-temp-text "* H1 :tag:\n** <point>H2 :tag2:"
  6277. (let ((org-use-tag-inheritance t)
  6278. (org-tags-column 1))
  6279. (org-toggle-tag "tag"))
  6280. (buffer-string))))
  6281. (should
  6282. (equal "* H1 :tag1:tag2:\n** H2 :foo:"
  6283. (org-test-with-temp-text "* H1 :tag1:tag2:\n** <point>H2"
  6284. (let ((org-use-tag-inheritance t)
  6285. (org-tags-column 1))
  6286. (org-toggle-tag "foo"))
  6287. (buffer-string)))))
  6288. (ert-deftest test-org/tags-expand ()
  6289. "Test `org-tags-expand' specifications."
  6290. ;; Expand tag groups as a regexp enclosed withing curly brackets.
  6291. (should
  6292. (equal "{\\<[ABC]\\>}"
  6293. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6294. (org-mode-restart)
  6295. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  6296. (should
  6297. (equal "{\\<\\(?:Aa\\|Bb\\|Cc\\)\\>}"
  6298. (org-test-with-temp-text "#+TAGS: [ Aa : Bb Cc ]"
  6299. (org-mode-restart)
  6300. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "Aa")))))
  6301. ;; Preserve operator before the regexp.
  6302. (should
  6303. (equal "+{\\<[ABC]\\>}"
  6304. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6305. (org-mode-restart)
  6306. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "+A")))))
  6307. (should
  6308. (equal "-{\\<[ABC]\\>}"
  6309. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6310. (org-mode-restart)
  6311. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "-A")))))
  6312. ;; Handle "|" syntax.
  6313. (should
  6314. (equal "{\\<[ABC]\\>}|D"
  6315. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6316. (org-mode-restart)
  6317. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|D")))))
  6318. ;; Handle nested groups.
  6319. (should
  6320. (equal "{\\<[A-D]\\>}"
  6321. (org-test-with-temp-text "#+TAGS: [ A : B C ]\n#+TAGS: [ B : D ]"
  6322. (org-mode-restart)
  6323. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  6324. ;; Expand multiple occurrences of the same group.
  6325. (should
  6326. (equal "{\\<[ABC]\\>}|{\\<[ABC]\\>}"
  6327. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6328. (org-mode-restart)
  6329. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|A")))))
  6330. ;; Preserve regexp matches.
  6331. (should
  6332. (equal "{A+}"
  6333. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6334. (org-mode-restart)
  6335. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "{A+}"))))))
  6336. ;;; TODO keywords
  6337. (ert-deftest test-org/auto-repeat-maybe ()
  6338. "Test `org-auto-repeat-maybe' specifications."
  6339. ;; Do not auto repeat when there is no valid time stamp with
  6340. ;; a repeater in the entry.
  6341. (should-not
  6342. (string-prefix-p
  6343. "* TODO H"
  6344. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6345. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
  6346. (org-todo "DONE")
  6347. (buffer-string)))))
  6348. (should-not
  6349. (string-prefix-p
  6350. "* TODO H"
  6351. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6352. (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
  6353. (org-todo "DONE")
  6354. (buffer-string)))))
  6355. ;; When switching to DONE state, switch back to first TODO keyword
  6356. ;; in sequence, or the same keyword if they have different types.
  6357. (should
  6358. (string-prefix-p
  6359. "* TODO H"
  6360. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6361. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  6362. (org-todo "DONE")
  6363. (buffer-string)))))
  6364. (should
  6365. (string-prefix-p
  6366. "* KWD1 H"
  6367. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  6368. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  6369. (org-todo "DONE")
  6370. (buffer-string)))))
  6371. (should
  6372. (string-prefix-p
  6373. "* KWD2 H"
  6374. (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
  6375. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  6376. (org-todo "DONE")
  6377. (buffer-string)))))
  6378. ;; If there was no TODO keyword in the first place, do not insert
  6379. ;; any either.
  6380. (should
  6381. (string-prefix-p
  6382. "* H"
  6383. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6384. (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
  6385. (org-todo "DONE")
  6386. (buffer-string)))))
  6387. ;; Revert to REPEAT_TO_STATE, if set.
  6388. (should
  6389. (string-prefix-p
  6390. "* KWD2 H"
  6391. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  6392. (org-test-with-temp-text
  6393. "* KWD2 H
  6394. :PROPERTIES:
  6395. :REPEAT_TO_STATE: KWD2
  6396. :END:
  6397. <2012-03-29 Thu +2y>"
  6398. (org-todo "DONE")
  6399. (buffer-string)))))
  6400. ;; When switching to DONE state, update base date. If there are
  6401. ;; multiple repeated time stamps, update them all.
  6402. (should
  6403. (string-match-p
  6404. "<2014-03-29 .* \\+2y>"
  6405. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6406. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  6407. (org-todo "DONE")
  6408. (buffer-string)))))
  6409. (should
  6410. (string-match-p
  6411. "<2015-03-04 .* \\+1y>"
  6412. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6413. (org-test-with-temp-text
  6414. "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
  6415. (org-todo "DONE")
  6416. (buffer-string)))))
  6417. ;; Throw an error if repeater unit is the hour and no time is
  6418. ;; provided in the time-stamp.
  6419. (should-error
  6420. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6421. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
  6422. (org-todo "DONE")
  6423. (buffer-string))))
  6424. ;; Also repeat inactive time stamps with a repeater.
  6425. (should
  6426. (string-match-p
  6427. "\\[2014-03-29 .* \\+2y\\]"
  6428. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6429. (org-test-with-temp-text
  6430. "* TODO H\n[2012-03-29 Thu. +2y]"
  6431. (org-todo "DONE")
  6432. (buffer-string)))))
  6433. ;; Do not repeat commented time stamps.
  6434. (should-not
  6435. (string-prefix-p
  6436. "<2015-03-04 .* \\+1y>"
  6437. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6438. (org-test-with-temp-text
  6439. "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
  6440. (org-todo "DONE")
  6441. (buffer-string)))))
  6442. (should-not
  6443. (string-prefix-p
  6444. "<2015-03-04 .* \\+1y>"
  6445. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6446. (org-test-with-temp-text
  6447. "* TODO H
  6448. <2012-03-29 Thu. +2y>
  6449. #+BEGIN_EXAMPLE
  6450. <2014-03-04 Tue +1y>
  6451. #+END_EXAMPLE"
  6452. (org-todo "DONE")
  6453. (buffer-string)))))
  6454. ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
  6455. ;; entry, record time of last repeat.
  6456. (should-not
  6457. (string-match-p
  6458. ":LAST_REPEAT:"
  6459. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  6460. (org-log-repeat nil))
  6461. (cl-letf (((symbol-function 'org-add-log-setup)
  6462. (lambda (&rest args) nil)))
  6463. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  6464. (org-todo "DONE")
  6465. (buffer-string))))))
  6466. (should
  6467. (string-match-p
  6468. ":LAST_REPEAT:"
  6469. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  6470. (org-log-repeat t))
  6471. (cl-letf (((symbol-function 'org-add-log-setup)
  6472. (lambda (&rest args) nil)))
  6473. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  6474. (org-todo "DONE")
  6475. (buffer-string))))))
  6476. (should
  6477. (string-match-p
  6478. ":LAST_REPEAT:"
  6479. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6480. (cl-letf (((symbol-function 'org-add-log-setup)
  6481. (lambda (&rest args) nil)))
  6482. (org-test-with-temp-text
  6483. "* TODO H\n<2012-03-29 Thu +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
  6484. (org-todo "DONE")
  6485. (buffer-string))))))
  6486. ;; When a SCHEDULED entry has no repeater, remove it upon repeating
  6487. ;; the entry as it is no longer relevant.
  6488. (should-not
  6489. (string-match-p
  6490. "^SCHEDULED:"
  6491. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  6492. (org-test-with-temp-text
  6493. "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
  6494. (org-todo "DONE")
  6495. (buffer-string)))))
  6496. ;; Properly advance repeater even when a clock entry is specified
  6497. ;; and `org-log-repeat' is nil.
  6498. (should
  6499. (string-match-p
  6500. "SCHEDULED: <2014-03-29"
  6501. (let ((org-log-repeat nil)
  6502. (org-todo-keywords '((sequence "TODO" "DONE"))))
  6503. (org-test-with-temp-text
  6504. "* TODO H
  6505. SCHEDULED: <2012-03-29 Thu +2y>
  6506. CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] => 6:40"
  6507. (org-todo "DONE")
  6508. (buffer-string))))))
  6509. ;;; Timestamps API
  6510. (ert-deftest test-org/at-timestamp-p ()
  6511. "Test `org-at-timestamp-p' specifications."
  6512. (should
  6513. (org-test-with-temp-text "<2012-03-29 Thu>"
  6514. (org-at-timestamp-p)))
  6515. (should-not
  6516. (org-test-with-temp-text "2012-03-29 Thu"
  6517. (org-at-timestamp-p)))
  6518. ;; Test return values.
  6519. (should
  6520. (eq 'bracket
  6521. (org-test-with-temp-text "<2012-03-29 Thu>"
  6522. (org-at-timestamp-p))))
  6523. (should
  6524. (eq 'year
  6525. (org-test-with-temp-text "<<point>2012-03-29 Thu>"
  6526. (org-at-timestamp-p))))
  6527. (should
  6528. (eq 'month
  6529. (org-test-with-temp-text "<2012-<point>03-29 Thu>"
  6530. (org-at-timestamp-p))))
  6531. (should
  6532. (eq 'day
  6533. (org-test-with-temp-text "<2012-03-<point>29 Thu>"
  6534. (org-at-timestamp-p))))
  6535. (should
  6536. (eq 'day
  6537. (org-test-with-temp-text "<2012-03-29 T<point>hu>"
  6538. (org-at-timestamp-p))))
  6539. (should
  6540. (wholenump
  6541. (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
  6542. (org-at-timestamp-p))))
  6543. (should
  6544. (eq 'bracket
  6545. (org-test-with-temp-text "<2012-03-29 Thu<point>>"
  6546. (org-at-timestamp-p))))
  6547. (should
  6548. (eq 'after
  6549. (org-test-with-temp-text "<2012-03-29 Thu><point>»"
  6550. (org-at-timestamp-p))))
  6551. ;; Test `inactive' optional argument.
  6552. (should
  6553. (org-test-with-temp-text "[2012-03-29 Thu]"
  6554. (org-at-timestamp-p 'inactive)))
  6555. (should-not
  6556. (org-test-with-temp-text "[2012-03-29 Thu]"
  6557. (org-at-timestamp-p)))
  6558. ;; When optional argument is `agenda', recognize time-stamps in
  6559. ;; planning info line, property drawers and clocks.
  6560. (should
  6561. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  6562. (org-at-timestamp-p 'agenda)))
  6563. (should-not
  6564. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  6565. (org-at-timestamp-p)))
  6566. (should
  6567. (org-test-with-temp-text
  6568. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  6569. (org-at-timestamp-p 'agenda)))
  6570. (should-not
  6571. (org-test-with-temp-text
  6572. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  6573. (org-at-timestamp-p)))
  6574. (should
  6575. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  6576. (let ((org-agenda-include-inactive-timestamps t))
  6577. (org-at-timestamp-p 'agenda))))
  6578. (should-not
  6579. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  6580. (let ((org-agenda-include-inactive-timestamps t))
  6581. (org-at-timestamp-p))))
  6582. (should-not
  6583. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  6584. (let ((org-agenda-include-inactive-timestamps t))
  6585. (org-at-timestamp-p 'inactive))))
  6586. ;; When optional argument is `lax', match any part of the document
  6587. ;; with Org timestamp syntax.
  6588. (should
  6589. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  6590. (org-at-timestamp-p 'lax)))
  6591. (should-not
  6592. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  6593. (org-at-timestamp-p)))
  6594. (should
  6595. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  6596. (org-at-timestamp-p 'lax)))
  6597. (should-not
  6598. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  6599. (org-at-timestamp-p)))
  6600. (should
  6601. (org-test-with-temp-text
  6602. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  6603. (org-at-timestamp-p 'lax)))
  6604. (should-not
  6605. (org-test-with-temp-text
  6606. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  6607. (org-at-timestamp-p)))
  6608. ;; Optional argument `lax' also matches inactive timestamps.
  6609. (should
  6610. (org-test-with-temp-text "# [2012-03-29 Thu]<point>"
  6611. (org-at-timestamp-p 'lax))))
  6612. (ert-deftest test-org/time-stamp ()
  6613. "Test `org-time-stamp' specifications."
  6614. ;; Insert chosen time stamp at point.
  6615. (should
  6616. (string-match
  6617. "Te<2014-03-04 .*?>xt"
  6618. (org-test-with-temp-text "Te<point>xt"
  6619. (cl-letf (((symbol-function 'org-read-date)
  6620. (lambda (&rest args)
  6621. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  6622. (org-time-stamp nil)
  6623. (buffer-string)))))
  6624. ;; With a prefix argument, also insert time.
  6625. (should
  6626. (string-match
  6627. "Te<2014-03-04 .*? 00:41>xt"
  6628. (org-test-with-temp-text "Te<point>xt"
  6629. (cl-letf (((symbol-function 'org-read-date)
  6630. (lambda (&rest args)
  6631. (apply #'encode-time
  6632. (org-parse-time-string "2014-03-04 00:41")))))
  6633. (org-time-stamp '(4))
  6634. (buffer-string)))))
  6635. ;; With two universal prefix arguments, insert an active timestamp
  6636. ;; with the current time without prompting the user.
  6637. (should
  6638. (string-match
  6639. "Te<2014-03-04 .*? 00:41>xt"
  6640. (org-test-with-temp-text "Te<point>xt"
  6641. (cl-letf (((symbol-function 'current-time)
  6642. (lambda ()
  6643. (apply #'encode-time
  6644. (org-parse-time-string "2014-03-04 00:41")))))
  6645. (org-time-stamp '(16))
  6646. (buffer-string)))))
  6647. ;; When optional argument is non-nil, insert an inactive timestamp.
  6648. (should
  6649. (string-match
  6650. "Te\\[2014-03-04 .*?\\]xt"
  6651. (org-test-with-temp-text "Te<point>xt"
  6652. (cl-letf (((symbol-function 'org-read-date)
  6653. (lambda (&rest args)
  6654. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  6655. (org-time-stamp nil t)
  6656. (buffer-string)))))
  6657. ;; When called from a timestamp, replace existing one.
  6658. (should
  6659. (string-match
  6660. "<2014-03-04 .*?>"
  6661. (org-test-with-temp-text "<2012-03-29<point> thu.>"
  6662. (cl-letf (((symbol-function 'org-read-date)
  6663. (lambda (&rest args)
  6664. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  6665. (org-time-stamp nil)
  6666. (buffer-string)))))
  6667. (should
  6668. (string-match
  6669. "<2014-03-04 .*?>--<2014-03-04 .*?>"
  6670. (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
  6671. (cl-letf (((symbol-function 'org-read-date)
  6672. (lambda (&rest args)
  6673. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  6674. (org-time-stamp nil)
  6675. (buffer-string)))))
  6676. ;; When replacing a timestamp, preserve repeater, if any.
  6677. (should
  6678. (string-match
  6679. "<2014-03-04 .*? \\+2y>"
  6680. (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
  6681. (cl-letf (((symbol-function 'org-read-date)
  6682. (lambda (&rest args)
  6683. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  6684. (org-time-stamp nil)
  6685. (buffer-string)))))
  6686. ;; When called twice in a raw, build a date range.
  6687. (should
  6688. (string-match
  6689. "<2012-03-29 .*?>--<2014-03-04 .*?>"
  6690. (org-test-with-temp-text "<2012-03-29 thu.><point>"
  6691. (cl-letf (((symbol-function 'org-read-date)
  6692. (lambda (&rest args)
  6693. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  6694. (let ((last-command 'org-time-stamp)
  6695. (this-command 'org-time-stamp))
  6696. (org-time-stamp nil))
  6697. (buffer-string))))))
  6698. (ert-deftest test-org/timestamp-has-time-p ()
  6699. "Test `org-timestamp-has-time-p' specifications."
  6700. ;; With time.
  6701. (should
  6702. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  6703. (org-timestamp-has-time-p (org-element-context))))
  6704. ;; Without time.
  6705. (should-not
  6706. (org-test-with-temp-text "<2012-03-29 Thu>"
  6707. (org-timestamp-has-time-p (org-element-context)))))
  6708. (ert-deftest test-org/get-repeat ()
  6709. "Test `org-get-repeat' specifications."
  6710. (should
  6711. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
  6712. (org-get-repeat)))
  6713. (should-not
  6714. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
  6715. (org-get-repeat)))
  6716. ;; Return proper repeat string.
  6717. (should
  6718. (equal "+2y"
  6719. (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
  6720. (org-get-repeat))))
  6721. ;; Prevent false positive (commented or verbatim time stamps)
  6722. (should-not
  6723. (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
  6724. (org-get-repeat)))
  6725. (should-not
  6726. (org-test-with-temp-text
  6727. "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
  6728. (org-get-repeat)))
  6729. ;; Return nil when called before first heading.
  6730. (should-not
  6731. (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
  6732. (org-get-repeat)))
  6733. ;; When called with an optional argument, extract repeater from that
  6734. ;; string instead.
  6735. (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
  6736. (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
  6737. (ert-deftest test-org/timestamp-format ()
  6738. "Test `org-timestamp-format' specifications."
  6739. ;; Regular test.
  6740. (should
  6741. (equal
  6742. "2012-03-29 16:40"
  6743. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  6744. (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
  6745. ;; Range end.
  6746. (should
  6747. (equal
  6748. "2012-03-29"
  6749. (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
  6750. (org-timestamp-format (org-element-context) "%Y-%m-%d" t)))))
  6751. (ert-deftest test-org/timestamp-split-range ()
  6752. "Test `org-timestamp-split-range' specifications."
  6753. ;; Extract range start (active).
  6754. (should
  6755. (equal '(2012 3 29)
  6756. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  6757. (let ((ts (org-timestamp-split-range (org-element-context))))
  6758. (mapcar (lambda (p) (org-element-property p ts))
  6759. '(:year-end :month-end :day-end))))))
  6760. ;; Extract range start (inactive)
  6761. (should
  6762. (equal '(2012 3 29)
  6763. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  6764. (let ((ts (org-timestamp-split-range (org-element-context))))
  6765. (mapcar (lambda (p) (org-element-property p ts))
  6766. '(:year-end :month-end :day-end))))))
  6767. ;; Extract range end (active).
  6768. (should
  6769. (equal '(2012 3 30)
  6770. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  6771. (let ((ts (org-timestamp-split-range
  6772. (org-element-context) t)))
  6773. (mapcar (lambda (p) (org-element-property p ts))
  6774. '(:year-end :month-end :day-end))))))
  6775. ;; Extract range end (inactive)
  6776. (should
  6777. (equal '(2012 3 30)
  6778. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  6779. (let ((ts (org-timestamp-split-range
  6780. (org-element-context) t)))
  6781. (mapcar (lambda (p) (org-element-property p ts))
  6782. '(:year-end :month-end :day-end))))))
  6783. ;; Return the timestamp if not a range.
  6784. (should
  6785. (org-test-with-temp-text "[2012-03-29 Thu]"
  6786. (let* ((ts-orig (org-element-context))
  6787. (ts-copy (org-timestamp-split-range ts-orig)))
  6788. (eq ts-orig ts-copy))))
  6789. (should
  6790. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  6791. (let* ((ts-orig (org-element-context))
  6792. (ts-copy (org-timestamp-split-range ts-orig)))
  6793. (eq ts-orig ts-copy)))))
  6794. (ert-deftest test-org/timestamp-translate ()
  6795. "Test `org-timestamp-translate' specifications."
  6796. ;; Translate whole date range.
  6797. (should
  6798. (equal "<29>--<30>"
  6799. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  6800. (let ((org-display-custom-times t)
  6801. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  6802. (org-timestamp-translate (org-element-context))))))
  6803. ;; Translate date range start.
  6804. (should
  6805. (equal "<29>"
  6806. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  6807. (let ((org-display-custom-times t)
  6808. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  6809. (org-timestamp-translate (org-element-context) 'start)))))
  6810. ;; Translate date range end.
  6811. (should
  6812. (equal "<30>"
  6813. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  6814. (let ((org-display-custom-times t)
  6815. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  6816. (org-timestamp-translate (org-element-context) 'end)))))
  6817. ;; Translate time range.
  6818. (should
  6819. (equal "<08>--<16>"
  6820. (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
  6821. (let ((org-display-custom-times t)
  6822. (org-time-stamp-custom-formats '("<%d>" . "<%H>")))
  6823. (org-timestamp-translate (org-element-context))))))
  6824. ;; Translate non-range timestamp.
  6825. (should
  6826. (equal "<29>"
  6827. (org-test-with-temp-text "<2012-03-29 Thu>"
  6828. (let ((org-display-custom-times t)
  6829. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  6830. (org-timestamp-translate (org-element-context))))))
  6831. ;; Do not change `diary' timestamps.
  6832. (should
  6833. (equal "<%%(org-float t 4 2)>"
  6834. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  6835. (let ((org-display-custom-times t)
  6836. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  6837. (org-timestamp-translate (org-element-context)))))))
  6838. (ert-deftest test-org/timestamp-from-string ()
  6839. "Test `org-timestamp-from-string' specifications."
  6840. ;; Return nil if argument is not a valid Org timestamp.
  6841. (should-not (org-timestamp-from-string ""))
  6842. (should-not (org-timestamp-from-string nil))
  6843. (should-not (org-timestamp-from-string "<2012-03-29"))
  6844. ;; Otherwise, return a valid Org timestamp object.
  6845. (should
  6846. (equal "<2012-03-29 Thu>"
  6847. (let ((system-time-locale "en_US"))
  6848. (org-element-interpret-data
  6849. (org-timestamp-from-string "<2012-03-29 Thu>")))))
  6850. (should
  6851. (equal "[2014-03-04 Tue]"
  6852. (let ((system-time-locale "en_US"))
  6853. (org-element-interpret-data
  6854. (org-timestamp-from-string "[2014-03-04 Tue]"))))))
  6855. (ert-deftest test-org/timestamp-from-time ()
  6856. "Test `org-timestamp-from-time' specifications."
  6857. ;; Standard test.
  6858. (should
  6859. (equal "<2012-03-29 Thu>"
  6860. (let ((system-time-locale "en_US"))
  6861. (org-element-interpret-data
  6862. (org-timestamp-from-time
  6863. (apply #'encode-time
  6864. (org-parse-time-string "<2012-03-29 Thu 16:40>")))))))
  6865. ;; When optional argument WITH-TIME is non-nil, provide time
  6866. ;; information.
  6867. (should
  6868. (equal "<2012-03-29 Thu 16:40>"
  6869. (let ((system-time-locale "en_US"))
  6870. (org-element-interpret-data
  6871. (org-timestamp-from-time
  6872. (apply #'encode-time
  6873. (org-parse-time-string "<2012-03-29 Thu 16:40>"))
  6874. t)))))
  6875. ;; When optional argument INACTIVE is non-nil, return an inactive
  6876. ;; timestamp.
  6877. (should
  6878. (equal "[2012-03-29 Thu]"
  6879. (let ((system-time-locale "en_US"))
  6880. (org-element-interpret-data
  6881. (org-timestamp-from-time
  6882. (apply #'encode-time
  6883. (org-parse-time-string "<2012-03-29 Thu 16:40>"))
  6884. nil t))))))
  6885. (ert-deftest test-org/timestamp-to-time ()
  6886. "Test `org-timestamp-to-time' specifications."
  6887. (should
  6888. (equal "2014-03-04"
  6889. (format-time-string
  6890. "%Y-%m-%d"
  6891. (org-timestamp-to-time
  6892. (org-timestamp-from-string "<2014-03-04 Tue>")))))
  6893. (should
  6894. (equal "2014-03-04"
  6895. (format-time-string
  6896. "%Y-%m-%d"
  6897. (org-timestamp-to-time
  6898. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  6899. (should
  6900. (equal "2012-03-29 08:30"
  6901. (format-time-string
  6902. "%Y-%m-%d %H:%M"
  6903. (org-timestamp-to-time
  6904. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")))))
  6905. (should
  6906. (equal "2012-03-29"
  6907. (format-time-string
  6908. "%Y-%m-%d"
  6909. (org-timestamp-to-time
  6910. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")))))
  6911. (should
  6912. (equal "2012-03-29"
  6913. (format-time-string
  6914. "%Y-%m-%d"
  6915. (org-timestamp-to-time
  6916. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")))))
  6917. ;; When optional argument END is non-nil, use end of date range or
  6918. ;; time range.
  6919. (should
  6920. (equal "2012-03-29 16:40"
  6921. (format-time-string
  6922. "%Y-%m-%d %H:%M"
  6923. (org-timestamp-to-time
  6924. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")
  6925. t))))
  6926. (should
  6927. (equal "2014-03-04"
  6928. (format-time-string
  6929. "%Y-%m-%d"
  6930. (org-timestamp-to-time
  6931. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")
  6932. t))))
  6933. (should
  6934. (equal "2014-03-04"
  6935. (format-time-string
  6936. "%Y-%m-%d"
  6937. (org-timestamp-to-time
  6938. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")
  6939. t)))))
  6940. ;;; Visibility
  6941. (ert-deftest test-org/flag-drawer ()
  6942. "Test `org-flag-drawer' specifications."
  6943. ;; Hide drawer.
  6944. (should
  6945. (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
  6946. (org-flag-drawer t)
  6947. (get-char-property (line-end-position) 'invisible)))
  6948. ;; Show drawer.
  6949. (should-not
  6950. (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
  6951. (org-flag-drawer t)
  6952. (org-flag-drawer nil)
  6953. (get-char-property (line-end-position) 'invisible)))
  6954. ;; Test optional argument.
  6955. (should
  6956. (org-test-with-temp-text "Text\n:D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
  6957. (let ((drawer (save-excursion (search-forward ":D2")
  6958. (org-element-at-point))))
  6959. (org-flag-drawer t drawer)
  6960. (get-char-property (progn (search-forward ":D2") (line-end-position))
  6961. 'invisible))))
  6962. (should-not
  6963. (org-test-with-temp-text ":D1:\nc1\n:END:\n\n:D2:\nc2\n:END:"
  6964. (let ((drawer (save-excursion (search-forward ":D2")
  6965. (org-element-at-point))))
  6966. (org-flag-drawer t drawer)
  6967. (get-char-property (line-end-position) 'invisible))))
  6968. ;; Do not hide fake drawers.
  6969. (should-not
  6970. (org-test-with-temp-text "#+begin_example\n:D:\nc\n:END:\n#+end_example"
  6971. (forward-line 1)
  6972. (org-flag-drawer t)
  6973. (get-char-property (line-end-position) 'invisible)))
  6974. ;; Do not hide incomplete drawers.
  6975. (should-not
  6976. (org-test-with-temp-text ":D:\nparagraph"
  6977. (forward-line 1)
  6978. (org-flag-drawer t)
  6979. (get-char-property (line-end-position) 'invisible)))
  6980. ;; Do not hide drawers when called from final blank lines.
  6981. (should-not
  6982. (org-test-with-temp-text ":DRAWER:\nA\n:END:\n\n"
  6983. (goto-char (point-max))
  6984. (org-flag-drawer t)
  6985. (goto-char (point-min))
  6986. (get-char-property (line-end-position) 'invisible)))
  6987. ;; Don't leave point in an invisible part of the buffer when hiding
  6988. ;; a drawer away.
  6989. (should-not
  6990. (org-test-with-temp-text ":DRAWER:\ncontents\n:END:"
  6991. (goto-char (point-max))
  6992. (org-flag-drawer t)
  6993. (get-char-property (point) 'invisible))))
  6994. (ert-deftest test-org/hide-block-toggle ()
  6995. "Test `org-hide-block-toggle' specifications."
  6996. ;; Error when not at a block.
  6997. (should-error
  6998. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
  6999. (org-hide-block-toggle 'off)
  7000. (get-char-property (line-end-position) 'invisible)))
  7001. ;; Hide block.
  7002. (should
  7003. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  7004. (org-hide-block-toggle)
  7005. (get-char-property (line-end-position) 'invisible)))
  7006. (should
  7007. (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
  7008. (org-hide-block-toggle)
  7009. (get-char-property (line-end-position) 'invisible)))
  7010. ;; Show block unconditionally when optional argument is `off'.
  7011. (should-not
  7012. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7013. (org-hide-block-toggle)
  7014. (org-hide-block-toggle 'off)
  7015. (get-char-property (line-end-position) 'invisible)))
  7016. (should-not
  7017. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7018. (org-hide-block-toggle 'off)
  7019. (get-char-property (line-end-position) 'invisible)))
  7020. ;; Hide block unconditionally when optional argument is non-nil.
  7021. (should
  7022. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7023. (org-hide-block-toggle t)
  7024. (get-char-property (line-end-position) 'invisible)))
  7025. (should
  7026. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7027. (org-hide-block-toggle)
  7028. (org-hide-block-toggle t)
  7029. (get-char-property (line-end-position) 'invisible)))
  7030. ;; Do not hide block when called from final blank lines.
  7031. (should-not
  7032. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
  7033. (org-hide-block-toggle)
  7034. (goto-char (point-min))
  7035. (get-char-property (line-end-position) 'invisible)))
  7036. ;; Don't leave point in an invisible part of the buffer when hiding
  7037. ;; a block away.
  7038. (should-not
  7039. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
  7040. (org-hide-block-toggle)
  7041. (get-char-property (point) 'invisible))))
  7042. (ert-deftest test-org/hide-block-toggle-maybe ()
  7043. "Test `org-hide-block-toggle-maybe' specifications."
  7044. (should
  7045. (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
  7046. (org-hide-block-toggle-maybe)))
  7047. (should-not
  7048. (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
  7049. (ert-deftest test-org/show-set-visibility ()
  7050. "Test `org-show-set-visibility' specifications."
  7051. ;; Do not throw an error before first heading.
  7052. (should
  7053. (org-test-with-temp-text "Preamble\n* Headline"
  7054. (org-show-set-visibility 'tree)
  7055. t))
  7056. ;; Test all visibility spans, both on headline and in entry.
  7057. (let ((list-visible-lines
  7058. (lambda (state headerp)
  7059. (org-test-with-temp-text "* Grandmother (0)
  7060. ** Uncle (1)
  7061. *** Heir (2)
  7062. ** Father (3)
  7063. Ancestor text (4)
  7064. *** Sister (5)
  7065. Sibling text (6)
  7066. *** Self (7)
  7067. Match (8)
  7068. **** First born (9)
  7069. Child text (10)
  7070. **** The other child (11)
  7071. *** Brother (12)
  7072. ** Aunt (13)
  7073. "
  7074. (org-cycle t)
  7075. (search-forward (if headerp "Self" "Match"))
  7076. (org-show-set-visibility state)
  7077. (goto-char (point-min))
  7078. (let (result (line 0))
  7079. (while (not (eobp))
  7080. (unless (org-invisible-p2) (push line result))
  7081. (cl-incf line)
  7082. (forward-line))
  7083. (nreverse result))))))
  7084. (should (equal '(0 7) (funcall list-visible-lines 'minimal t)))
  7085. (should (equal '(0 7 8) (funcall list-visible-lines 'minimal nil)))
  7086. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local t)))
  7087. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local nil)))
  7088. (should (equal '(0 3 7) (funcall list-visible-lines 'ancestors t)))
  7089. (should (equal '(0 3 7 8) (funcall list-visible-lines 'ancestors nil)))
  7090. (should (equal '(0 3 5 7 12) (funcall list-visible-lines 'lineage t)))
  7091. (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines 'lineage nil)))
  7092. (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines 'tree t)))
  7093. (should (equal '(0 1 3 5 7 8 9 11 12 13)
  7094. (funcall list-visible-lines 'tree nil)))
  7095. (should (equal '(0 1 3 4 5 7 12 13)
  7096. (funcall list-visible-lines 'canonical t)))
  7097. (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
  7098. (funcall list-visible-lines 'canonical nil))))
  7099. ;; When point is hidden in a drawer or a block, make sure to make it
  7100. ;; visible.
  7101. (should-not
  7102. (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
  7103. (org-hide-block-toggle)
  7104. (search-forward "Text")
  7105. (org-show-set-visibility 'minimal)
  7106. (org-invisible-p2)))
  7107. (should-not
  7108. (org-test-with-temp-text ":DRAWER:\nText\n:END:"
  7109. (org-flag-drawer t)
  7110. (search-forward "Text")
  7111. (org-show-set-visibility 'minimal)
  7112. (org-invisible-p2)))
  7113. (should-not
  7114. (org-test-with-temp-text
  7115. "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
  7116. (org-flag-drawer t)
  7117. (forward-line -1)
  7118. (org-hide-block-toggle)
  7119. (search-forward "Text")
  7120. (org-show-set-visibility 'minimal)
  7121. (org-invisible-p2))))
  7122. (defun test-org/copy-visible ()
  7123. "Test `org-copy-visible' specifications."
  7124. (should
  7125. (equal "Foo"
  7126. (org-test-with-temp-text "Foo"
  7127. (let ((kill-ring nil))
  7128. (org-copy-visible (point-min) (point-max))
  7129. (current-kill 0 t)))))
  7130. ;; Skip invisible characters by text property.
  7131. (should
  7132. (equal "Foo"
  7133. (org-test-with-temp-text #("F<hidden>oo" 1 7 (invisible t))
  7134. (let ((kill-ring nil))
  7135. (org-copy-visible (point-min) (point-max))
  7136. (current-kill 0 t)))))
  7137. ;; Skip invisible characters by overlay.
  7138. (should
  7139. (equal "Foo"
  7140. (org-test-with-temp-text "F<hidden>oo"
  7141. (let ((o (make-overlay 2 10)))
  7142. (overlay-put o 'invisible t))
  7143. (let ((kill-ring nil))
  7144. (org-copy-visible (point-min) (point-max))
  7145. (current-kill 0 t)))))
  7146. ;; Handle invisible characters at the beginning and the end of the
  7147. ;; buffer.
  7148. (should
  7149. (equal "Foo"
  7150. (org-test-with-temp-text #("<hidden>Foo" 0 8 (invisible t))
  7151. (let ((kill-ring nil))
  7152. (org-copy-visible (point-min) (point-max))
  7153. (current-kill 0 t)))))
  7154. (should
  7155. (equal "Foo"
  7156. (org-test-with-temp-text #("Foo<hidden>" 3 11 (invisible t))
  7157. (let ((kill-ring nil))
  7158. (org-copy-visible (point-min) (point-max))
  7159. (current-kill 0 t)))))
  7160. ;; Handle multiple visible parts.
  7161. (should
  7162. (equal "abc"
  7163. (org-test-with-temp-text
  7164. #("aXbXc" 1 2 (invisible t) 3 4 (invisible t))
  7165. (let ((kill-ring nil))
  7166. (org-copy-visible (point-min) (point-max))
  7167. (current-kill 0 t))))))
  7168. (ert-deftest test-org/set-visibility-according-to-property ()
  7169. "Test `org-set-visibility-according-to-property' specifications."
  7170. ;; "folded" state.
  7171. (should
  7172. (org-test-with-temp-text
  7173. "
  7174. * a
  7175. :PROPERTIES:
  7176. :VISIBILITY: folded
  7177. :END:
  7178. ** <point>b"
  7179. (org-set-visibility-according-to-property)
  7180. (invisible-p (point))))
  7181. ;; "children" state.
  7182. (should
  7183. (org-test-with-temp-text
  7184. "
  7185. * a
  7186. :PROPERTIES:
  7187. :VISIBILITY: children
  7188. :END:
  7189. ** b
  7190. <point>Contents
  7191. ** c"
  7192. (org-set-visibility-according-to-property)
  7193. (invisible-p (point))))
  7194. (should
  7195. (org-test-with-temp-text
  7196. "
  7197. * a
  7198. :PROPERTIES:
  7199. :VISIBILITY: children
  7200. :END:
  7201. ** b
  7202. Contents
  7203. *** <point>c"
  7204. (org-set-visibility-according-to-property)
  7205. (invisible-p (point))))
  7206. ;; "content" state.
  7207. (should
  7208. (org-test-with-temp-text
  7209. "
  7210. * a
  7211. :PROPERTIES:
  7212. :VISIBILITY: content
  7213. :END:
  7214. ** b
  7215. <point>Contents
  7216. *** c"
  7217. (org-set-visibility-according-to-property)
  7218. (invisible-p (point))))
  7219. (should
  7220. (org-test-with-temp-text
  7221. "
  7222. * a
  7223. :PROPERTIES:
  7224. :VISIBILITY: content
  7225. :END:
  7226. ** b
  7227. Contents
  7228. *** <point>c"
  7229. (org-set-visibility-according-to-property)
  7230. (not (invisible-p (point)))))
  7231. ;; "showall" state.
  7232. (should
  7233. (org-test-with-temp-text
  7234. "
  7235. * a
  7236. :PROPERTIES:
  7237. :VISIBILITY: showall
  7238. :END:
  7239. ** b
  7240. <point>Contents
  7241. *** c"
  7242. (org-set-visibility-according-to-property)
  7243. (not (invisible-p (point)))))
  7244. (should
  7245. (org-test-with-temp-text
  7246. "
  7247. * a
  7248. :PROPERTIES:
  7249. :VISIBILITY: showall
  7250. :END:
  7251. ** b
  7252. Contents
  7253. *** <point>c"
  7254. (org-set-visibility-according-to-property)
  7255. (not (invisible-p (point))))))
  7256. ;;; Yank and Kill
  7257. (ert-deftest test-org/paste-subtree ()
  7258. "Test `org-paste-subtree' specifications."
  7259. ;; Return an error if text to yank is not a set of subtrees.
  7260. (should-error (org-paste-subtree nil "Text"))
  7261. ;; Adjust level according to current one.
  7262. (should
  7263. (equal "* H\n* Text\n"
  7264. (org-test-with-temp-text "* H\n<point>"
  7265. (org-paste-subtree nil "* Text")
  7266. (buffer-string))))
  7267. (should
  7268. (equal "* H1\n** H2\n** Text\n"
  7269. (org-test-with-temp-text "* H1\n** H2\n<point>"
  7270. (org-paste-subtree nil "* Text")
  7271. (buffer-string))))
  7272. ;; When not on a heading, move to next heading before yanking.
  7273. (should
  7274. (equal "* H1\nParagraph\n* Text\n* H2"
  7275. (org-test-with-temp-text "* H1\n<point>Paragraph\n* H2"
  7276. (org-paste-subtree nil "* Text")
  7277. (buffer-string))))
  7278. ;; If point is between two headings, use the deepest level.
  7279. (should
  7280. (equal "* H1\n\n* Text\n* H2"
  7281. (org-test-with-temp-text "* H1\n<point>\n* H2"
  7282. (org-paste-subtree nil "* Text")
  7283. (buffer-string))))
  7284. (should
  7285. (equal "** H1\n\n** Text\n* H2"
  7286. (org-test-with-temp-text "** H1\n<point>\n* H2"
  7287. (org-paste-subtree nil "* Text")
  7288. (buffer-string))))
  7289. (should
  7290. (equal "* H1\n\n** Text\n** H2"
  7291. (org-test-with-temp-text "* H1\n<point>\n** H2"
  7292. (org-paste-subtree nil "* Text")
  7293. (buffer-string))))
  7294. ;; When on an empty heading, after the stars, deduce the new level
  7295. ;; from the number of stars.
  7296. (should
  7297. (equal "*** Text\n"
  7298. (org-test-with-temp-text "*** <point>"
  7299. (org-paste-subtree nil "* Text")
  7300. (buffer-string))))
  7301. ;; Optional argument LEVEL forces a level for the subtree.
  7302. (should
  7303. (equal "* H\n*** Text\n"
  7304. (org-test-with-temp-text "* H<point>"
  7305. (org-paste-subtree 3 "* Text")
  7306. (buffer-string)))))
  7307. (ert-deftest test-org/cut-and-paste-subtree ()
  7308. "Test `org-cut-subtree' and `org-paste-subtree'."
  7309. (should
  7310. (equal
  7311. "* Two
  7312. two
  7313. * One
  7314. "
  7315. (org-test-with-temp-text
  7316. "* One
  7317. <point>* Two
  7318. two
  7319. "
  7320. (call-interactively #'org-cut-subtree)
  7321. (goto-char (point-min))
  7322. (call-interactively #'org-paste-subtree)
  7323. (buffer-string))))
  7324. (should
  7325. (equal
  7326. "* One
  7327. * Two
  7328. "
  7329. (org-test-with-temp-text
  7330. "* One
  7331. <point>* Two
  7332. "
  7333. (call-interactively #'org-cut-subtree)
  7334. (backward-char)
  7335. (call-interactively #'org-paste-subtree)
  7336. (buffer-string)))))
  7337. (provide 'test-org)
  7338. ;;; test-org.el ends here