test-org.el 247 KB

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