test-org.el 268 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274
  1. ;;; test-org.el --- tests for org.el
  2. ;; Copyright (c) David Maus
  3. ;; Authors: David Maus
  4. ;; This file is not part of GNU Emacs.
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. ;; Template test file for Org tests
  16. ;;; Code:
  17. (eval-and-compile (require 'cl-lib))
  18. ;;; Comments
  19. (ert-deftest test-org/toggle-comment ()
  20. "Test `org-toggle-comment' specifications."
  21. ;; Simple headline.
  22. (should
  23. (equal "* Test"
  24. (org-test-with-temp-text "* COMMENT Test"
  25. (org-toggle-comment)
  26. (buffer-string))))
  27. (should
  28. (equal "* COMMENT Test"
  29. (org-test-with-temp-text "* Test"
  30. (org-toggle-comment)
  31. (buffer-string))))
  32. ;; Headline with a regular keyword.
  33. (should
  34. (equal "* TODO Test"
  35. (org-test-with-temp-text "* TODO COMMENT Test"
  36. (org-toggle-comment)
  37. (buffer-string))))
  38. (should
  39. (equal "* TODO COMMENT Test"
  40. (org-test-with-temp-text "* TODO Test"
  41. (org-toggle-comment)
  42. (buffer-string))))
  43. ;; Empty headline.
  44. (should
  45. (equal "* "
  46. (org-test-with-temp-text "* COMMENT"
  47. (org-toggle-comment)
  48. (buffer-string))))
  49. (should
  50. (equal "* COMMENT"
  51. (org-test-with-temp-text "* "
  52. (org-toggle-comment)
  53. (buffer-string))))
  54. ;; Headline with a single keyword.
  55. (should
  56. (equal "* TODO "
  57. (org-test-with-temp-text "* TODO COMMENT"
  58. (org-toggle-comment)
  59. (buffer-string))))
  60. (should
  61. (equal "* TODO COMMENT"
  62. (org-test-with-temp-text "* TODO"
  63. (org-toggle-comment)
  64. (buffer-string))))
  65. ;; Headline with a keyword, a priority cookie and contents.
  66. (should
  67. (equal "* TODO [#A] Headline"
  68. (org-test-with-temp-text "* TODO [#A] COMMENT Headline"
  69. (org-toggle-comment)
  70. (buffer-string))))
  71. (should
  72. (equal "* TODO [#A] COMMENT Headline"
  73. (org-test-with-temp-text "* TODO [#A] Headline"
  74. (org-toggle-comment)
  75. (buffer-string)))))
  76. (ert-deftest test-org/comment-dwim ()
  77. "Test `comment-dwim' behaviour in an Org buffer."
  78. ;; No region selected, no comment on current line and line not
  79. ;; empty: insert comment on line above.
  80. (should
  81. (equal "# \nComment"
  82. (org-test-with-temp-text "Comment"
  83. (call-interactively #'org-comment-dwim)
  84. (buffer-string))))
  85. ;; No region selected, no comment on current line and line empty:
  86. ;; insert comment on this line.
  87. (should
  88. (equal "# \nParagraph"
  89. (org-test-with-temp-text "\nParagraph"
  90. (call-interactively #'org-comment-dwim)
  91. (buffer-string))))
  92. ;; No region selected, and a comment on this line: indent it.
  93. (should
  94. (equal "* Headline\n # Comment"
  95. (org-test-with-temp-text "* Headline\n# <point>Comment"
  96. (let ((org-adapt-indentation t))
  97. (call-interactively #'org-comment-dwim))
  98. (buffer-string))))
  99. ;; Also recognize single # at column 0 as comments.
  100. (should
  101. (equal "# Comment"
  102. (org-test-with-temp-text "# Comment"
  103. (call-interactively #'org-comment-dwim)
  104. (buffer-string))))
  105. ;; Region selected and only comments and blank lines within it:
  106. ;; un-comment all commented lines.
  107. (should
  108. (equal "Comment 1\n\nComment 2"
  109. (org-test-with-temp-text "# Comment 1\n\n# Comment 2"
  110. (transient-mark-mode 1)
  111. (push-mark (point) t t)
  112. (goto-char (point-max))
  113. (call-interactively #'org-comment-dwim)
  114. (buffer-string))))
  115. ;; Region selected without comments: comment all lines if
  116. ;; `comment-empty-lines' is non-nil, only non-blank lines otherwise.
  117. (should
  118. (equal "# Comment 1\n\n# Comment 2"
  119. (org-test-with-temp-text "Comment 1\n\nComment 2"
  120. (transient-mark-mode 1)
  121. (push-mark (point) t t)
  122. (goto-char (point-max))
  123. (let ((comment-empty-lines nil))
  124. (call-interactively #'org-comment-dwim))
  125. (buffer-string))))
  126. (should
  127. (equal "# Comment 1\n# \n# Comment 2"
  128. (org-test-with-temp-text "Comment 1\n\nComment 2"
  129. (transient-mark-mode 1)
  130. (push-mark (point) t t)
  131. (goto-char (point-max))
  132. (let ((comment-empty-lines t))
  133. (call-interactively #'org-comment-dwim))
  134. (buffer-string))))
  135. ;; In front of a keyword without region, insert a new comment.
  136. (should
  137. (equal "# \n#+KEYWORD: value"
  138. (org-test-with-temp-text "#+KEYWORD: value"
  139. (call-interactively #'org-comment-dwim)
  140. (buffer-string))))
  141. ;; Comment a heading
  142. (should
  143. (equal "* COMMENT Test"
  144. (org-test-with-temp-text "* Test"
  145. (call-interactively #'org-comment-dwim)
  146. (buffer-string))))
  147. ;; In a source block, use appropriate syntax.
  148. (should
  149. (equal " ;; "
  150. (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n<point>\n#+END_SRC"
  151. (let ((org-edit-src-content-indentation 2))
  152. (call-interactively #'org-comment-dwim))
  153. (buffer-substring-no-properties (line-beginning-position)
  154. (point)))))
  155. (should
  156. (equal "#+BEGIN_SRC emacs-lisp\n ;; a\n ;; b\n#+END_SRC"
  157. (org-test-with-temp-text
  158. "#+BEGIN_SRC emacs-lisp\n<point>a\nb\n#+END_SRC"
  159. (transient-mark-mode 1)
  160. (push-mark (point) t t)
  161. (forward-line 2)
  162. (let ((org-edit-src-content-indentation 2))
  163. (call-interactively #'org-comment-dwim))
  164. (buffer-string)))))
  165. ;;; Date and time analysis
  166. (ert-deftest test-org/org-read-date ()
  167. "Test `org-read-date' specifications."
  168. ;; Parse ISO date with abbreviated year and month.
  169. (should (equal "2012-03-29 16:40"
  170. (let ((org-time-was-given t))
  171. (org-read-date t nil "12-3-29 16:40"))))
  172. ;; Parse Europeans dates.
  173. (should (equal "2012-03-29 16:40"
  174. (let ((org-time-was-given t))
  175. (org-read-date t nil "29.03.2012 16:40"))))
  176. ;; Parse Europeans dates without year.
  177. (should (string-match "2[0-9]\\{3\\}-03-29 16:40"
  178. (let ((org-time-was-given t))
  179. (org-read-date t nil "29.03. 16:40"))))
  180. ;; Relative date applied to current time if there is single
  181. ;; plus/minus, or to default date when there are two of them.
  182. (should
  183. (equal
  184. "2015-03-04"
  185. (org-test-at-time "2014-03-04"
  186. (org-read-date
  187. t nil "+1y" nil
  188. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))
  189. (should
  190. (equal
  191. "2013-03-29"
  192. (org-test-at-time "2014-03-04"
  193. (org-read-date
  194. t nil "++1y" nil
  195. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))
  196. ;; When `org-read-date-prefer-future' is non-nil, prefer future
  197. ;; dates (relatively to now) when incomplete. Otherwise, use
  198. ;; default date.
  199. (should
  200. (equal
  201. "2014-04-01"
  202. (org-test-at-time "2014-03-04"
  203. (let ((org-read-date-prefer-future t))
  204. (org-read-date t nil "1")))))
  205. (should
  206. (equal
  207. "2013-03-04"
  208. (org-test-at-time "2012-03-29"
  209. (let ((org-read-date-prefer-future t))
  210. (org-read-date t nil "3-4")))))
  211. (should
  212. (equal
  213. "2012-03-04"
  214. (org-test-at-time "2012-03-29"
  215. (let ((org-read-date-prefer-future nil))
  216. (org-read-date t nil "3-4")))))
  217. ;; When set to `org-read-date-prefer-future' is set to `time', read
  218. ;; day is moved to tomorrow if specified hour is before current
  219. ;; time. However, it only happens in no other part of the date is
  220. ;; specified.
  221. (should
  222. (equal
  223. "2012-03-30"
  224. (org-test-at-time "2012-03-29 16:40"
  225. (let ((org-read-date-prefer-future 'time))
  226. (org-read-date t nil "00:40" nil)))))
  227. (should-not
  228. (equal
  229. "2012-03-30"
  230. (org-test-at-time "2012-03-29 16:40"
  231. (let ((org-read-date-prefer-future 'time))
  232. (org-read-date t nil "29 00:40" nil)))))
  233. ;; Caveat: `org-read-date-prefer-future' always refers to current
  234. ;; time, not default time, when they differ.
  235. (should
  236. (equal
  237. "2014-04-01"
  238. (org-test-at-time "2014-03-04"
  239. (let ((org-read-date-prefer-future t))
  240. (org-read-date
  241. t nil "1" nil
  242. (apply #'encode-time (org-parse-time-string "2012-03-29")))))))
  243. (should
  244. (equal
  245. "2014-03-25"
  246. (org-test-at-time "2014-03-04"
  247. (let ((org-read-date-prefer-future t))
  248. (org-read-date
  249. t nil "25" nil
  250. (apply #'encode-time (org-parse-time-string "2012-03-29"))))))))
  251. (ert-deftest test-org/org-parse-time-string ()
  252. "Test `org-parse-time-string'."
  253. (should (equal (org-parse-time-string "2012-03-29 16:40")
  254. '(0 40 16 29 3 2012 nil nil nil)))
  255. (should (equal (org-parse-time-string "[2012-03-29 16:40]")
  256. '(0 40 16 29 3 2012 nil nil nil)))
  257. (should (equal (org-parse-time-string "<2012-03-29 16:40>")
  258. '(0 40 16 29 3 2012 nil nil nil)))
  259. (should (equal (org-parse-time-string "<2012-03-29>")
  260. '(0 0 0 29 3 2012 nil nil nil)))
  261. (should (equal (org-parse-time-string "<2012-03-29>" t)
  262. '(0 nil nil 29 3 2012 nil nil nil))))
  263. (ert-deftest test-org/closest-date ()
  264. "Test `org-closest-date' specifications."
  265. (require 'calendar)
  266. ;; Time stamps without a repeater are returned unchanged.
  267. (should
  268. (equal
  269. '(3 29 2012)
  270. (calendar-gregorian-from-absolute
  271. (org-closest-date "<2012-03-29>" "<2014-03-04>" nil))))
  272. ;; Time stamps with a null repeater are returned unchanged.
  273. (should
  274. (equal
  275. '(3 29 2012)
  276. (calendar-gregorian-from-absolute
  277. (org-closest-date "<2012-03-29 +0d>" "<2014-03-04>" nil))))
  278. ;; if PREFER is set to `past' always return a date before, or equal
  279. ;; to CURRENT.
  280. (should
  281. (equal
  282. '(3 1 2014)
  283. (calendar-gregorian-from-absolute
  284. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'past))))
  285. (should
  286. (equal
  287. '(3 4 2014)
  288. (calendar-gregorian-from-absolute
  289. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'past))))
  290. ;; if PREFER is set to `future' always return a date before, or equal
  291. ;; to CURRENT.
  292. (should
  293. (equal
  294. '(3 29 2014)
  295. (calendar-gregorian-from-absolute
  296. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" 'future))))
  297. (should
  298. (equal
  299. '(3 4 2014)
  300. (calendar-gregorian-from-absolute
  301. (org-closest-date "<2012-03-04 +1m>" "<2014-03-04>" 'future))))
  302. ;; If PREFER is neither `past' nor `future', select closest date.
  303. (should
  304. (equal
  305. '(3 1 2014)
  306. (calendar-gregorian-from-absolute
  307. (org-closest-date "<2012-03-29 +1m>" "<2014-03-04>" nil))))
  308. (should
  309. (equal
  310. '(5 4 2014)
  311. (calendar-gregorian-from-absolute
  312. (org-closest-date "<2012-03-04 +1m>" "<2014-04-28>" nil))))
  313. ;; Test "day" repeater.
  314. (should
  315. (equal '(3 8 2014)
  316. (calendar-gregorian-from-absolute
  317. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'past))))
  318. (should
  319. (equal '(3 10 2014)
  320. (calendar-gregorian-from-absolute
  321. (org-closest-date "<2014-03-04 +2d>" "<2014-03-09>" 'future))))
  322. ;; Test "month" repeater.
  323. (should
  324. (equal '(1 5 2015)
  325. (calendar-gregorian-from-absolute
  326. (org-closest-date "<2014-03-05 +2m>" "<2015-02-04>" 'past))))
  327. (should
  328. (equal '(3 29 2014)
  329. (calendar-gregorian-from-absolute
  330. (org-closest-date "<2012-03-29 +2m>" "<2014-03-04>" 'future))))
  331. ;; Test "year" repeater.
  332. (should
  333. (equal '(3 5 2014)
  334. (calendar-gregorian-from-absolute
  335. (org-closest-date "<2014-03-05 +2y>" "<2015-02-04>" 'past))))
  336. (should
  337. (equal '(3 29 2014)
  338. (calendar-gregorian-from-absolute
  339. (org-closest-date "<2012-03-29 +2y>" "<2014-03-04>" 'future)))))
  340. (ert-deftest test-org/deadline-close-p ()
  341. "Test `org-deadline-close-p' specifications."
  342. (org-test-at-time "2016-06-03 Fri 01:43"
  343. ;; Timestamps are close if they are within `ndays' of lead time.
  344. (org-test-with-temp-text "* Heading"
  345. (should (org-deadline-close-p "2016-06-03 Fri" 0))
  346. (should (org-deadline-close-p "2016-06-02 Thu" 0))
  347. (should-not (org-deadline-close-p "2016-06-04 Sat" 0))
  348. (should (org-deadline-close-p "2016-06-04 Sat" 1))
  349. (should (org-deadline-close-p "2016-06-03 Fri 12:00" 0)))
  350. ;; Read `ndays' from timestamp if argument not given.
  351. (org-test-with-temp-text "* H"
  352. (should (org-deadline-close-p "2016-06-04 Sat -1d"))
  353. (should-not (org-deadline-close-p "2016-06-04 Sat -0d"))
  354. (should (org-deadline-close-p "2016-06-10 Fri -1w"))
  355. (should-not (org-deadline-close-p "2016-06-11 Sat -1w")))
  356. ;; Prefer `ndays' argument over lead time in timestamp.
  357. (org-test-with-temp-text "* H"
  358. (should (org-deadline-close-p "2016-06-04 Sat -0d" 1))
  359. (should-not (org-deadline-close-p "2016-06-04 Sat -0d" 0)))
  360. ;; Completed tasks are never close.
  361. (let ((org-todo-keywords '(("TODO" "|" "DONE"))))
  362. (org-test-with-temp-text "* TODO Heading"
  363. (should (org-deadline-close-p "2016-06-03")))
  364. (org-test-with-temp-text "* DONE Heading"
  365. (should-not (org-deadline-close-p "2016-06-03"))))))
  366. ;;; Drawers
  367. (ert-deftest test-org/at-property-p ()
  368. "Test `org-at-property-p' specifications."
  369. (should
  370. (equal 't
  371. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:PROP: t\n:END:\n"
  372. (org-at-property-p))))
  373. (should
  374. (equal 't
  375. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n:END:\n"
  376. (org-at-property-p)))))
  377. (ert-deftest test-org/at-property-drawer-p ()
  378. "Test `org-at-property-drawer-p' specifications."
  379. (should
  380. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:PROP: t\n:END:\n"
  381. (org-at-property-drawer-p)))
  382. (should
  383. (org-test-with-temp-text ":PROPERTIES:\n:PROP: t\n:END:\n"
  384. (org-at-property-drawer-p)))
  385. ;; The function only returns t if point is at the first line of
  386. ;; a property block.
  387. (should-not
  388. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n:END:\n"
  389. (org-at-property-drawer-p)))
  390. ;; The function ignores incomplete drawers.
  391. (should-not
  392. (org-test-with-temp-text ":PROPERTIES:\n<point>:PROP: t\n"
  393. (org-at-property-drawer-p))))
  394. (ert-deftest test-org/get-property-block ()
  395. "Test `org-get-property-block' specifications."
  396. (should
  397. (equal '(14 . 14)
  398. (org-test-with-temp-text ":PROPERTIES:\n:END:\n* H\n"
  399. (org-get-property-block))))
  400. (should
  401. (equal '(14 . 14)
  402. (org-test-with-temp-text ":PROPERTIES:\n:END:\n"
  403. (org-get-property-block))))
  404. ;; Comments above a document property block is ok.
  405. (should
  406. (equal '(18 . 18)
  407. (org-test-with-temp-text "# C\n:PROPERTIES:\n:END:\n"
  408. (org-get-property-block))))
  409. ;; Keywords above a document property block is ok.
  410. (should
  411. (equal '(22 . 22)
  412. (org-test-with-temp-text "# C\n# C\n:PROPERTIES:\n:END:\n"
  413. (org-get-property-block))))
  414. ;; Comments and keywords are allowed before a document property block.
  415. (should
  416. (equal '(18 . 27)
  417. (org-test-with-temp-text "# C\n:PROPERTIES:\n:KEY: V:\n:END:\n"
  418. (org-get-property-block))))
  419. ;; A document property block will not be valid if there are lines
  420. ;; with whitespace above it
  421. (should-not
  422. (org-test-with-temp-text "\n:PROPERTIES:\n:END:\n"
  423. (org-get-property-block)))
  424. (should
  425. (equal '(18 . 18)
  426. (org-test-with-temp-text "* H\n:PROPERTIES:\n:END:\n<point>"
  427. (org-get-property-block))))
  428. (should
  429. (equal "* H\n:PROPERTIES:\n:END:\n"
  430. (org-test-with-temp-text "* H"
  431. (let ((org-adapt-indentation nil))
  432. (org-get-property-block nil 'force))
  433. (buffer-string))))
  434. (should
  435. (equal ":PROPERTIES:\n:END:\n"
  436. (org-test-with-temp-text ""
  437. (org-get-property-block nil 'force)
  438. (buffer-string))))
  439. (should
  440. (equal "* H1\n :PROPERTIES:\n :END:\n* H2"
  441. (org-test-with-temp-text "* H1\n* H2"
  442. (let ((org-adapt-indentation t))
  443. (org-get-property-block nil 'force))
  444. (buffer-string)))))
  445. (ert-deftest test-org/insert-property-drawer ()
  446. "Test `org-insert-property-drawer' specifications."
  447. ;; Insert drawer in empty buffer
  448. (should
  449. (equal ":PROPERTIES:\n:END:\n"
  450. (org-test-with-temp-text ""
  451. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  452. (buffer-string))))
  453. ;; Insert drawer in document header with existing comment and
  454. ;; keyword.
  455. (should
  456. (equal "# C\n:PROPERTIES:\n:END:\n#+TITLE: T"
  457. (org-test-with-temp-text "# C\n#+TITLE: T"
  458. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  459. (buffer-string))))
  460. ;; Insert drawer in document header with existing keyword.
  461. (should
  462. (equal ":PROPERTIES:\n:END:\n#+TITLE: T"
  463. (org-test-with-temp-text "#+TITLE: T"
  464. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  465. (buffer-string))))
  466. (should
  467. (equal ":PROPERTIES:\n:END:"
  468. (org-test-with-temp-text ":PROPERTIES:\n:END:"
  469. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  470. (buffer-string))))
  471. ;; Insert drawer in document header with one existing heading in buffer.
  472. (should
  473. (equal ":PROPERTIES:\n:END:\n\n* T\n"
  474. (org-test-with-temp-text "\n* T\n"
  475. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  476. (buffer-string))))
  477. ;; Insert drawer right after headline if there is no planning line,
  478. ;; or after it otherwise.
  479. (should
  480. (equal "* H\n:PROPERTIES:\n:END:\nParagraph"
  481. (org-test-with-temp-text "* H\nParagraph<point>"
  482. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  483. (buffer-string))))
  484. (should
  485. (equal "* H\nDEADLINE: <2014-03-04 tue.>\n:PROPERTIES:\n:END:\nParagraph"
  486. (org-test-with-temp-text
  487. "* H\nDEADLINE: <2014-03-04 tue.>\nParagraph<point>"
  488. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  489. (buffer-string))))
  490. ;; Indent inserted drawer.
  491. (should
  492. (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
  493. (org-test-with-temp-text "* H\nParagraph<point>"
  494. (let ((org-adapt-indentation t)) (org-insert-property-drawer))
  495. (buffer-string))))
  496. ;; Handle insertion at eob.
  497. (should
  498. (equal "* H\n:PROPERTIES:\n:END:\n"
  499. (org-test-with-temp-text "* H"
  500. (let ((org-adapt-indentation nil)) (org-insert-property-drawer))
  501. (buffer-string))))
  502. ;; Skip inlinetasks before point.
  503. (when (featurep 'org-inlinetask)
  504. (should
  505. (equal "* H\n:PROPERTIES:\n:END:\n*************** I\n*************** END\nP"
  506. (org-test-with-temp-text
  507. "* H\n*************** I\n*************** END\nP<point>"
  508. (let ((org-adapt-indentation nil)
  509. (org-inlinetask-min-level 15))
  510. (org-insert-property-drawer))
  511. (buffer-string)))))
  512. ;; Correctly set drawer in an inlinetask.
  513. (when (featurep 'org-inlinetask)
  514. (should
  515. (equal "* H\n*************** I\n:PROPERTIES:\n:END:\nP\n*************** END"
  516. (org-test-with-temp-text
  517. "* H\n*************** I\nP<point>\n*************** END"
  518. (let ((org-adapt-indentation nil)
  519. (org-inlinetask-min-level 15))
  520. (org-insert-property-drawer))
  521. (buffer-string))))))
  522. ;;; Filling
  523. (ert-deftest test-org/fill-element ()
  524. "Test `org-fill-element' specifications."
  525. ;; At an Org table, align it.
  526. (should
  527. (equal "| a |\n"
  528. (org-test-with-temp-text "|a|"
  529. (org-fill-element)
  530. (buffer-string))))
  531. (should
  532. (equal "#+name: table\n| a |\n"
  533. (org-test-with-temp-text "#+name: table\n| a |\n"
  534. (org-fill-element)
  535. (buffer-string))))
  536. ;; At a paragraph, preserve line breaks.
  537. (org-test-with-temp-text "some \\\\\nlong\ntext"
  538. (let ((fill-column 20))
  539. (org-fill-element)
  540. (should (equal (buffer-string) "some \\\\\nlong text"))))
  541. ;; Correctly fill a paragraph when point is at its very end.
  542. (should
  543. (equal "A B"
  544. (org-test-with-temp-text "A\nB"
  545. (let ((fill-column 20))
  546. (goto-char (point-max))
  547. (org-fill-element)
  548. (buffer-string)))))
  549. ;; Correctly fill the last paragraph of a greater element.
  550. (should
  551. (equal "#+BEGIN_CENTER\n- 012345\n 789\n#+END_CENTER"
  552. (org-test-with-temp-text "#+BEGIN_CENTER\n- 012345 789\n#+END_CENTER"
  553. (let ((fill-column 8))
  554. (forward-line)
  555. (end-of-line)
  556. (org-fill-element)
  557. (buffer-string)))))
  558. ;; Correctly fill an element in a narrowed buffer.
  559. (should
  560. (equal "01234\n6"
  561. (org-test-with-temp-text "01234 6789"
  562. (let ((fill-column 5))
  563. (narrow-to-region 1 8)
  564. (org-fill-element)
  565. (buffer-string)))))
  566. ;; Handle `adaptive-fill-regexp' in paragraphs.
  567. (should
  568. (equal "> a b"
  569. (org-test-with-temp-text "> a\n> b"
  570. (let ((fill-column 5)
  571. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  572. (org-fill-element)
  573. (buffer-string)))))
  574. ;; Special case: Fill first paragraph when point is at an item or
  575. ;; a plain-list or a footnote reference.
  576. (should
  577. (equal "- A B"
  578. (org-test-with-temp-text "- A\n B"
  579. (let ((fill-column 20))
  580. (org-fill-element)
  581. (buffer-string)))))
  582. (should
  583. (equal "[fn:1] A B"
  584. (org-test-with-temp-text "[fn:1] A\nB"
  585. (let ((fill-column 20))
  586. (org-fill-element)
  587. (buffer-string)))))
  588. (org-test-with-temp-text "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"
  589. (let ((fill-column 20))
  590. (org-fill-element)
  591. (should (equal (buffer-string)
  592. "#+BEGIN_VERSE\nSome \\\\\nlong\ntext\n#+END_VERSE"))))
  593. ;; Fill contents of `comment-block' elements.
  594. (should
  595. (equal
  596. (org-test-with-temp-text "#+BEGIN_COMMENT\nSome\ntext\n#+END_COMMENT"
  597. (let ((fill-column 20))
  598. (forward-line)
  599. (org-fill-element)
  600. (buffer-string)))
  601. "#+BEGIN_COMMENT\nSome text\n#+END_COMMENT"))
  602. ;; Fill `comment' elements.
  603. (should
  604. (equal " # A B"
  605. (org-test-with-temp-text " # A\n # B"
  606. (let ((fill-column 20))
  607. (org-fill-element)
  608. (buffer-string)))))
  609. ;; Do not mix consecutive comments when filling one of them.
  610. (should
  611. (equal "# A B\n\n# C"
  612. (org-test-with-temp-text "# A\n# B\n\n# C"
  613. (let ((fill-column 20))
  614. (org-fill-element)
  615. (buffer-string)))))
  616. ;; Use commented empty lines as separators when filling comments.
  617. (should
  618. (equal "# A B\n#\n# C"
  619. (org-test-with-temp-text "# A\n# B\n#\n# C"
  620. (let ((fill-column 20))
  621. (org-fill-element)
  622. (buffer-string)))))
  623. ;; Handle `adaptive-fill-regexp' in comments.
  624. (should
  625. (equal "# > a b"
  626. (org-test-with-temp-text "# > a\n# > b"
  627. (let ((fill-column 20)
  628. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  629. (org-fill-element)
  630. (buffer-string)))))
  631. ;; Do nothing at affiliated keywords.
  632. (should
  633. (equal "#+NAME: para\nSome\ntext."
  634. (org-test-with-temp-text "#+NAME: para\nSome\ntext."
  635. (let ((fill-column 20))
  636. (org-fill-element)
  637. (buffer-string)))))
  638. ;; Do not move point after table when filling a table.
  639. (should-not
  640. (org-test-with-temp-text "| a | b |\n| c | d |\n"
  641. (forward-char)
  642. (org-fill-element)
  643. (eobp)))
  644. ;; Do not fill "n" macro, with or without arguments, followed by
  645. ;; a dot or a closing parenthesis since it could be confused with
  646. ;; a numbered bullet.
  647. (should-not
  648. (equal "123456789\n{{{n}}}."
  649. (org-test-with-temp-text "123456789 {{{n}}}."
  650. (let ((fill-column 10))
  651. (org-fill-element)
  652. (buffer-string)))))
  653. (should-not
  654. (equal "123456789\n{{{n}}}\)"
  655. (org-test-with-temp-text "123456789 {{{n}}}\)"
  656. (let ((fill-column 10))
  657. (org-fill-element)
  658. (buffer-string)))))
  659. (should-not
  660. (equal "123456789\n{{{n()}}}."
  661. (org-test-with-temp-text "123456789 {{{n()}}}."
  662. (let ((fill-column 10))
  663. (org-fill-element)
  664. (buffer-string)))))
  665. (should-not
  666. (equal "123456789\n{{{n(counter)}}}."
  667. (org-test-with-temp-text "123456789 {{{n(counter)}}}."
  668. (let ((fill-column 10))
  669. (org-fill-element)
  670. (buffer-string))))))
  671. (ert-deftest test-org/fill-paragraph ()
  672. "Test `org-fill-paragraph' specifications."
  673. ;; Regular test.
  674. (should
  675. (equal "012345678\n9"
  676. (org-test-with-temp-text "012345678 9"
  677. (let ((fill-column 10))
  678. (org-fill-paragraph)
  679. (buffer-string)))))
  680. ;; Fill paragraph even at end of buffer.
  681. (should
  682. (equal "012345678\n9\n"
  683. (org-test-with-temp-text "012345678 9\n<point>"
  684. (let ((fill-column 10))
  685. (org-fill-paragraph)
  686. (buffer-string)))))
  687. ;; Between two paragraphs, fill the next one.
  688. (should
  689. (equal "012345678 9\n\n012345678\n9"
  690. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  691. (let ((fill-column 10))
  692. (org-fill-paragraph)
  693. (buffer-string)))))
  694. (should
  695. (equal "012345678\n9\n\n012345678 9"
  696. (org-test-with-temp-text "012345678 9<point>\n\n012345678 9"
  697. (let ((fill-column 10))
  698. (org-fill-paragraph)
  699. (buffer-string)))))
  700. ;; Fill paragraph in a comment block.
  701. (should
  702. (equal "#+begin_comment\n012345678\n9\n#+end_comment"
  703. (org-test-with-temp-text
  704. "#+begin_comment\n<point>012345678 9\n#+end_comment"
  705. (let ((fill-column 10))
  706. (org-fill-paragraph)
  707. (buffer-string)))))
  708. ;; When a region is selected, fill every paragraph in the region.
  709. (should
  710. (equal "012345678\n9\n\n012345678\n9"
  711. (org-test-with-temp-text "012345678 9\n\n012345678 9"
  712. (let ((fill-column 10))
  713. (transient-mark-mode 1)
  714. (push-mark (point-min) t t)
  715. (goto-char (point-max))
  716. (call-interactively #'org-fill-paragraph)
  717. (buffer-string)))))
  718. (should
  719. (equal "012345678\n9\n\n012345678 9"
  720. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  721. (let ((fill-column 10))
  722. (transient-mark-mode 1)
  723. (push-mark (point) t t)
  724. (goto-char (point-min))
  725. (call-interactively #'org-fill-paragraph)
  726. (buffer-string)))))
  727. (should
  728. (equal "012345678 9\n\n012345678\n9"
  729. (org-test-with-temp-text "012345678 9\n<point>\n012345678 9"
  730. (let ((fill-column 10))
  731. (transient-mark-mode 1)
  732. (push-mark (point) t t)
  733. (goto-char (point-max))
  734. (call-interactively #'org-fill-paragraph)
  735. (buffer-string))))))
  736. (ert-deftest test-org/auto-fill-function ()
  737. "Test auto-filling features."
  738. ;; Auto fill paragraph.
  739. (should
  740. (equal "12345\n7890"
  741. (org-test-with-temp-text "12345 7890"
  742. (let ((fill-column 5))
  743. (end-of-line)
  744. (org-auto-fill-function)
  745. (buffer-string)))))
  746. ;; Auto fill first paragraph in an item.
  747. (should
  748. (equal "- 12345\n 7890"
  749. (org-test-with-temp-text "- 12345 7890"
  750. (let ((fill-column 7))
  751. (end-of-line)
  752. (org-auto-fill-function)
  753. (buffer-string)))))
  754. ;; Auto fill paragraph when `adaptive-fill-regexp' matches.
  755. (should
  756. (equal "> 12345\n 7890"
  757. (org-test-with-temp-text "> 12345 7890"
  758. (let ((fill-column 10)
  759. (adaptive-fill-regexp "[ \t]*>+[ \t]*")
  760. (adaptive-fill-first-line-regexp "\\`[ ]*\\'"))
  761. (end-of-line)
  762. (org-auto-fill-function)
  763. (buffer-string)))))
  764. (should
  765. (equal "> 12345\n> 12345\n> 7890"
  766. (org-test-with-temp-text "> 12345\n> 12345 7890"
  767. (let ((fill-column 10)
  768. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  769. (goto-char (point-max))
  770. (org-auto-fill-function)
  771. (buffer-string)))))
  772. (should-not
  773. (equal " 12345\n *12345\n *12345"
  774. (org-test-with-temp-text " 12345\n *12345 12345"
  775. (let ((fill-column 10)
  776. (adaptive-fill-regexp "[ \t]*>+[ \t]*"))
  777. (goto-char (point-max))
  778. (org-auto-fill-function)
  779. (buffer-string)))))
  780. ;; Auto fill comments.
  781. (should
  782. (equal " # 12345\n # 7890"
  783. (org-test-with-temp-text " # 12345 7890"
  784. (let ((fill-column 10))
  785. (end-of-line)
  786. (org-auto-fill-function)
  787. (buffer-string)))))
  788. ;; A hash within a line isn't a comment.
  789. (should-not
  790. (equal "12345 # 7890\n# 1"
  791. (org-test-with-temp-text "12345 # 7890 1"
  792. (let ((fill-column 12))
  793. (end-of-line)
  794. (org-auto-fill-function)
  795. (buffer-string)))))
  796. ;; Correctly interpret empty prefix.
  797. (should-not
  798. (equal "# a\n# b\nRegular\n# paragraph"
  799. (org-test-with-temp-text "# a\n# b\nRegular paragraph"
  800. (let ((fill-column 12))
  801. (end-of-line 3)
  802. (org-auto-fill-function)
  803. (buffer-string)))))
  804. ;; Comment block: auto fill contents.
  805. (should
  806. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  807. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  808. (let ((fill-column 5))
  809. (forward-line)
  810. (end-of-line)
  811. (org-auto-fill-function)
  812. (buffer-string)))))
  813. (should
  814. (equal "#+BEGIN_COMMENT\n12345\n7890\n#+END_COMMENT"
  815. (org-test-with-temp-text "#+BEGIN_COMMENT\n12345 7890\n#+END_COMMENT"
  816. (let ((fill-column 5))
  817. (forward-line)
  818. (end-of-line)
  819. (org-auto-fill-function)
  820. (buffer-string)))))
  821. ;; Do not fill if a new item could be created.
  822. (should-not
  823. (equal "12345\n- 90"
  824. (org-test-with-temp-text "12345 - 90"
  825. (let ((fill-column 5))
  826. (end-of-line)
  827. (org-auto-fill-function)
  828. (buffer-string)))))
  829. ;; Do not fill if a line break could be introduced.
  830. (should-not
  831. (equal "123\\\\\n7890"
  832. (org-test-with-temp-text "123\\\\ 7890"
  833. (let ((fill-column 6))
  834. (end-of-line)
  835. (org-auto-fill-function)
  836. (buffer-string)))))
  837. ;; Do not fill affiliated keywords.
  838. (should-not
  839. (equal "#+ATTR_LATEX: ABC\nDEFGHIJKL"
  840. (org-test-with-temp-text "#+ATTR_LATEX: ABC DEFGHIJKL"
  841. (let ((fill-column 20))
  842. (end-of-line)
  843. (org-auto-fill-function)
  844. (buffer-string))))))
  845. ;;; Indentation
  846. (ert-deftest test-org/indent-line ()
  847. "Test `org-indent-line' specifications."
  848. ;; Do not indent diary sexps, footnote definitions or headlines.
  849. (should
  850. (zerop
  851. (org-test-with-temp-text "%%(org-calendar-holiday)"
  852. (org-indent-line)
  853. (org-get-indentation))))
  854. (should
  855. (zerop
  856. (org-test-with-temp-text "[fn:1] fn"
  857. (let ((org-adapt-indentation t)) (org-indent-line))
  858. (org-get-indentation))))
  859. (should
  860. (zerop
  861. (org-test-with-temp-text "* H"
  862. (org-indent-line)
  863. (org-get-indentation))))
  864. ;; Do not indent before first headline.
  865. (should
  866. (zerop
  867. (org-test-with-temp-text ""
  868. (org-indent-line)
  869. (org-get-indentation))))
  870. ;; Indent according to headline level otherwise, unless
  871. ;; `org-adapt-indentation' is nil.
  872. (should
  873. (= 2
  874. (org-test-with-temp-text "* H\n<point>A"
  875. (let ((org-adapt-indentation t)) (org-indent-line))
  876. (org-get-indentation))))
  877. (should
  878. (= 2
  879. (org-test-with-temp-text "* H\n<point>\nA"
  880. (let ((org-adapt-indentation t)) (org-indent-line))
  881. (org-get-indentation))))
  882. (should
  883. (zerop
  884. (org-test-with-temp-text "* H\n<point>A"
  885. (let ((org-adapt-indentation nil)) (org-indent-line))
  886. (org-get-indentation))))
  887. ;; Indenting preserves point position.
  888. (should
  889. (org-test-with-temp-text "* H\nA<point>B"
  890. (let ((org-adapt-indentation t)) (org-indent-line))
  891. (looking-at "B")))
  892. ;; Do not change indentation at an item or a LaTeX environment.
  893. (should
  894. (= 1
  895. (org-test-with-temp-text "* H\n<point> - A"
  896. (let ((org-adapt-indentation t)) (org-indent-line))
  897. (org-get-indentation))))
  898. (should
  899. (= 1
  900. (org-test-with-temp-text
  901. "\\begin{equation}\n <point>1+1=2\n\\end{equation}"
  902. (org-indent-line)
  903. (org-get-indentation))))
  904. ;; On blank lines at the end of a list, indent like last element
  905. ;; within it if the line is still in the list. If the last element
  906. ;; is an item, indent like its contents. Otherwise, indent like the
  907. ;; whole list.
  908. (should
  909. (= 4
  910. (org-test-with-temp-text "* H\n- A\n - AA\n<point>"
  911. (let ((org-adapt-indentation t)) (org-indent-line))
  912. (org-get-indentation))))
  913. (should
  914. (= 4
  915. (org-test-with-temp-text "* H\n- A\n -\n\n<point>"
  916. (let ((org-adapt-indentation t)) (org-indent-line))
  917. (org-get-indentation))))
  918. (should
  919. (zerop
  920. (org-test-with-temp-text "* H\n- A\n - AA\n\n\n\n<point>"
  921. (let ((org-adapt-indentation t)) (org-indent-line))
  922. (org-get-indentation))))
  923. (should
  924. (= 4
  925. (org-test-with-temp-text "* H\n- A\n - \n<point>"
  926. (let ((org-adapt-indentation t)) (org-indent-line))
  927. (org-get-indentation))))
  928. (should
  929. (= 4
  930. (org-test-with-temp-text
  931. "* H\n - \n #+BEGIN_SRC emacs-lisp\n t\n #+END_SRC\n<point>"
  932. (let ((org-adapt-indentation t)) (org-indent-line))
  933. (org-get-indentation))))
  934. (should
  935. (= 2
  936. (org-test-with-temp-text "- A\n B\n\n<point>"
  937. (let ((org-adapt-indentation nil)) (org-indent-line))
  938. (org-get-indentation))))
  939. (should
  940. (= 2
  941. (org-test-with-temp-text
  942. "- A\n \begin{cases} 1 + 1\n \end{cases}\n\n<point>"
  943. (let ((org-adapt-indentation nil)) (org-indent-line))
  944. (org-get-indentation))))
  945. ;; Likewise, on a blank line at the end of a footnote definition,
  946. ;; indent at column 0 if line belongs to the definition. Otherwise,
  947. ;; indent like the definition itself.
  948. (should
  949. (zerop
  950. (org-test-with-temp-text "* H\n[fn:1] Definition\n<point>"
  951. (let ((org-adapt-indentation t)) (org-indent-line))
  952. (org-get-indentation))))
  953. (should
  954. (zerop
  955. (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n<point>"
  956. (let ((org-adapt-indentation t)) (org-indent-line))
  957. (org-get-indentation))))
  958. ;; After the end of the contents of a greater element, indent like
  959. ;; the beginning of the element.
  960. (should
  961. (= 1
  962. (org-test-with-temp-text
  963. " #+BEGIN_CENTER\n Contents\n<point>#+END_CENTER"
  964. (org-indent-line)
  965. (org-get-indentation))))
  966. ;; On blank lines after a paragraph, indent like its last non-empty
  967. ;; line.
  968. (should
  969. (= 1
  970. (org-test-with-temp-text " Paragraph\n\n<point>"
  971. (org-indent-line)
  972. (org-get-indentation))))
  973. ;; At the first line of an element, indent like previous element's
  974. ;; first line, ignoring footnotes definitions and inline tasks, or
  975. ;; according to parent.
  976. (let ((org-adapt-indentation t))
  977. (should
  978. (= 2
  979. (org-test-with-temp-text "A\n\n B\n\nC<point>"
  980. (org-indent-line)
  981. (org-get-indentation))))
  982. (should
  983. (= 1
  984. (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC<point>"
  985. (org-indent-line)
  986. (org-get-indentation))))
  987. (should
  988. (= 1
  989. (org-test-with-temp-text
  990. " #+BEGIN_CENTER\n<point> Contents\n#+END_CENTER"
  991. (org-indent-line)
  992. (org-get-indentation)))))
  993. ;; Within code part of a source block, use language major mode if
  994. ;; `org-src-tab-acts-natively' is non-nil. Otherwise, indent
  995. ;; according to line above.
  996. (should
  997. (= 6
  998. (org-test-with-temp-text
  999. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  1000. (let ((org-src-tab-acts-natively t)
  1001. (org-edit-src-content-indentation 0))
  1002. (org-indent-line))
  1003. (org-get-indentation))))
  1004. (should
  1005. (= 1
  1006. (org-test-with-temp-text
  1007. "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
  1008. (let ((org-src-tab-acts-natively nil)
  1009. (org-edit-src-content-indentation 0))
  1010. (org-indent-line))
  1011. (org-get-indentation))))
  1012. ;; Otherwise, indent like the first non-blank line above.
  1013. (should
  1014. (zerop
  1015. (org-test-with-temp-text
  1016. "#+BEGIN_CENTER\nline1\n\n<point> line2\n#+END_CENTER"
  1017. (org-indent-line)
  1018. (org-get-indentation))))
  1019. ;; Align node properties according to `org-property-format'. Handle
  1020. ;; nicely empty values.
  1021. (should
  1022. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1023. (org-test-with-temp-text
  1024. "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
  1025. (let ((org-property-format "%-10s %s")) (org-indent-line))
  1026. (buffer-string))))
  1027. (should
  1028. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1029. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key:\n:END:"
  1030. (let ((org-property-format "%-10s %s")) (org-indent-line))
  1031. (buffer-string)))))
  1032. (ert-deftest test-org/indent-region ()
  1033. "Test `org-indent-region' specifications."
  1034. ;; Indent paragraph.
  1035. (let ((org-adapt-indentation t))
  1036. (should
  1037. (equal "A\nB\nC"
  1038. (org-test-with-temp-text " A\nB\n C"
  1039. (org-indent-region (point-min) (point-max))
  1040. (buffer-string)))))
  1041. ;; Indent greater elements along with their contents.
  1042. (should
  1043. (equal "#+BEGIN_CENTER\nA\nB\n#+END_CENTER"
  1044. (org-test-with-temp-text "#+BEGIN_CENTER\n A\n B\n#+END_CENTER"
  1045. (org-indent-region (point-min) (point-max))
  1046. (buffer-string))))
  1047. ;; Ignore contents of verse blocks. Only indent block delimiters.
  1048. (should
  1049. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1050. (org-test-with-temp-text "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1051. (org-indent-region (point-min) (point-max))
  1052. (buffer-string))))
  1053. (let ((org-adapt-indentation t))
  1054. (should
  1055. (equal "#+BEGIN_VERSE\n A\n B\n#+END_VERSE"
  1056. (org-test-with-temp-text " #+BEGIN_VERSE\n A\n B\n #+END_VERSE"
  1057. (org-indent-region (point-min) (point-max))
  1058. (buffer-string)))))
  1059. ;; Indent example blocks as a single block, unless indentation
  1060. ;; should be preserved. In this case only indent the block markers.
  1061. (should
  1062. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1063. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1064. (org-indent-region (point-min) (point-max))
  1065. (buffer-string))))
  1066. (let ((org-adapt-indentation t))
  1067. (should
  1068. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1069. (org-test-with-temp-text " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1070. (org-indent-region (point-min) (point-max))
  1071. (buffer-string))))
  1072. (should
  1073. (equal "#+BEGIN_EXAMPLE -i\n A\n B\n#+END_EXAMPLE"
  1074. (org-test-with-temp-text
  1075. " #+BEGIN_EXAMPLE -i\n A\n B\n #+END_EXAMPLE"
  1076. (org-indent-region (point-min) (point-max))
  1077. (buffer-string))))
  1078. (should
  1079. (equal "#+BEGIN_EXAMPLE\n A\n B\n#+END_EXAMPLE"
  1080. (org-test-with-temp-text
  1081. " #+BEGIN_EXAMPLE\n A\n B\n #+END_EXAMPLE"
  1082. (let ((org-src-preserve-indentation t))
  1083. (org-indent-region (point-min) (point-max)))
  1084. (buffer-string)))))
  1085. ;; Treat export blocks as a whole.
  1086. (should
  1087. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1088. (org-test-with-temp-text "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1089. (org-indent-region (point-min) (point-max))
  1090. (buffer-string))))
  1091. (let ((org-adapt-indentation t))
  1092. (should
  1093. (equal "#+BEGIN_EXPORT latex\n A\n B\n#+END_EXPORT"
  1094. (org-test-with-temp-text
  1095. " #+BEGIN_EXPORT latex\n A\n B\n #+END_EXPORT"
  1096. (org-indent-region (point-min) (point-max))
  1097. (buffer-string)))))
  1098. ;; Indent according to mode if `org-src-tab-acts-natively' is
  1099. ;; non-nil. Otherwise, do not indent code at all.
  1100. (should
  1101. (equal "#+BEGIN_SRC emacs-lisp\n(and A\n B)\n#+END_SRC"
  1102. (org-test-with-temp-text
  1103. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1104. (let ((org-src-tab-acts-natively t)
  1105. (org-edit-src-content-indentation 0))
  1106. (org-indent-region (point-min) (point-max)))
  1107. (buffer-string))))
  1108. (should
  1109. (equal "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1110. (org-test-with-temp-text
  1111. "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
  1112. (let ((org-src-tab-acts-natively nil)
  1113. (org-edit-src-content-indentation 0))
  1114. (org-indent-region (point-min) (point-max)))
  1115. (buffer-string))))
  1116. ;; Align node properties according to `org-property-format'. Handle
  1117. ;; nicely empty values.
  1118. (should
  1119. (equal "* H\n:PROPERTIES:\n:key: value\n:END:"
  1120. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key: value\n:END:"
  1121. (let ((org-property-format "%-10s %s")
  1122. (org-adapt-indentation nil))
  1123. (org-indent-region (point) (point-max)))
  1124. (buffer-string))))
  1125. (should
  1126. (equal "* H\n:PROPERTIES:\n:key:\n:END:"
  1127. (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
  1128. (let ((org-property-format "%-10s %s")
  1129. (org-adapt-indentation nil))
  1130. (org-indent-region (point) (point-max)))
  1131. (buffer-string))))
  1132. ;; Indent plain lists.
  1133. (let ((org-adapt-indentation t))
  1134. (should
  1135. (equal "- A\n B\n - C\n\n D"
  1136. (org-test-with-temp-text "- A\n B\n - C\n\n D"
  1137. (org-indent-region (point-min) (point-max))
  1138. (buffer-string))))
  1139. (should
  1140. (equal "- A\n\n- B"
  1141. (org-test-with-temp-text " - A\n\n - B"
  1142. (org-indent-region (point-min) (point-max))
  1143. (buffer-string)))))
  1144. ;; Indent footnote definitions.
  1145. (should
  1146. (equal "[fn:1] Definition\n\nDefinition"
  1147. (org-test-with-temp-text "[fn:1] Definition\n\n Definition"
  1148. (org-indent-region (point-min) (point-max))
  1149. (buffer-string))))
  1150. ;; Special case: Start indenting on a blank line.
  1151. (should
  1152. (equal "\nParagraph"
  1153. (org-test-with-temp-text "\n Paragraph"
  1154. (org-indent-region (point-min) (point-max))
  1155. (buffer-string)))))
  1156. ;;; Editing
  1157. (ert-deftest test-org/delete-indentation ()
  1158. "Test `org-delete-indentation' specifications."
  1159. ;; Regular test.
  1160. (should (equal "foo bar"
  1161. (org-test-with-temp-text
  1162. "foo \n bar<point>"
  1163. (org-delete-indentation)
  1164. (buffer-string))))
  1165. ;; With optional argument.
  1166. (should (equal "foo bar"
  1167. (org-test-with-temp-text
  1168. "foo<point> \n bar"
  1169. (org-delete-indentation t)
  1170. (buffer-string))))
  1171. ;; At headline text should be appended to the headline text.
  1172. (should
  1173. (equal"* foo bar :tag:"
  1174. (let (org-auto-align-tags)
  1175. (org-test-with-temp-text
  1176. "* foo :tag:\n bar<point>"
  1177. (org-delete-indentation)
  1178. (buffer-string)))))
  1179. (should
  1180. (equal "* foo bar :tag:"
  1181. (let (org-auto-align-tags)
  1182. (org-test-with-temp-text
  1183. "* foo <point>:tag:\n bar"
  1184. (org-delete-indentation t)
  1185. (buffer-string))))))
  1186. (ert-deftest test-org/return ()
  1187. "Test `org-return' specifications."
  1188. ;; Regular test.
  1189. (should
  1190. (equal "Para\ngraph"
  1191. (org-test-with-temp-text "Para<point>graph"
  1192. (org-return)
  1193. (buffer-string))))
  1194. ;; With optional argument, indent line.
  1195. (should
  1196. (equal " Para\n graph"
  1197. (org-test-with-temp-text " Para<point>graph"
  1198. (org-return t)
  1199. (buffer-string))))
  1200. ;; On a table, call `org-table-next-row'.
  1201. (should
  1202. (org-test-with-temp-text "| <point>a |\n| b |"
  1203. (org-return)
  1204. (looking-at-p "b")))
  1205. ;; Open link or timestamp under point when `org-return-follows-link'
  1206. ;; is non-nil.
  1207. (should
  1208. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1209. (let ((org-return-follows-link t)
  1210. (org-link-search-must-match-exact-headline nil))
  1211. (org-return))
  1212. (looking-at-p "<<target>>")))
  1213. (should-not
  1214. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1215. (let ((org-return-follows-link nil)) (org-return))
  1216. (looking-at-p "<<target>>")))
  1217. (should
  1218. (org-test-with-temp-text "* [[b][a<point>]]\n* b"
  1219. (let ((org-return-follows-link t)) (org-return))
  1220. (looking-at-p "* b")))
  1221. (should
  1222. (org-test-with-temp-text "Link [[target][/descipt<point>ion/]] <<target>>"
  1223. (let ((org-return-follows-link t)
  1224. (org-link-search-must-match-exact-headline nil))
  1225. (org-return))
  1226. (looking-at-p "<<target>>")))
  1227. (should-not
  1228. (org-test-with-temp-text "Link [[target]]<point> <<target>>"
  1229. (let ((org-return-follows-link t)
  1230. (org-link-search-must-match-exact-headline nil))
  1231. (org-return))
  1232. (looking-at-p "<<target>>")))
  1233. ;; When `org-return-follows-link' is non-nil, tolerate links and
  1234. ;; timestamps in comments, node properties, etc.
  1235. (should
  1236. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1237. (let ((org-return-follows-link t)
  1238. (org-link-search-must-match-exact-headline nil))
  1239. (org-return))
  1240. (looking-at-p "<<target>>")))
  1241. (should-not
  1242. (org-test-with-temp-text "# Comment [[target<point>]]\n <<target>>"
  1243. (let ((org-return-follows-link nil)) (org-return))
  1244. (looking-at-p "<<target>>")))
  1245. (should-not
  1246. (org-test-with-temp-text "# Comment [[target]]<point>\n <<target>>"
  1247. (let ((org-return-follows-link t)
  1248. (org-link-search-must-match-exact-headline nil))
  1249. (org-return))
  1250. (looking-at-p "<<target>>")))
  1251. ;; Non-nil `org-return-follows-link' ignores read-only state of
  1252. ;; a buffer.
  1253. (should
  1254. (org-test-with-temp-text "Link [[target<point>]] <<target>>"
  1255. (let ((org-return-follows-link t)
  1256. (org-link-search-must-match-exact-headline nil))
  1257. (setq buffer-read-only t)
  1258. (call-interactively #'org-return))
  1259. (looking-at-p "<<target>>")))
  1260. ;; `org-return-follows-link' handle multi-line lines.
  1261. (should
  1262. (org-test-with-temp-text
  1263. "[[target][This is a very\n long description<point>]]\n <<target>>"
  1264. (let ((org-return-follows-link t)
  1265. (org-link-search-must-match-exact-headline nil))
  1266. (org-return))
  1267. (looking-at-p "<<target>>")))
  1268. (should-not
  1269. (org-test-with-temp-text
  1270. "[[target][This is a very\n long description]]<point>\n <<target>>"
  1271. (let ((org-return-follows-link t)
  1272. (org-link-search-must-match-exact-headline nil))
  1273. (org-return))
  1274. (looking-at-p "<<target>>")))
  1275. ;; However, do not open link when point is in a table.
  1276. (should
  1277. (org-test-with-temp-text "| [[target<point>]] |\n| between |\n| <<target>> |"
  1278. (let ((org-return-follows-link t)) (org-return))
  1279. (looking-at-p "between")))
  1280. ;; Special case: in a list, when indenting, do not break structure.
  1281. (should
  1282. (equal "- A\n B"
  1283. (org-test-with-temp-text "- A <point>B"
  1284. (org-return t)
  1285. (buffer-string))))
  1286. (should
  1287. (equal "- A\n\n- B"
  1288. (org-test-with-temp-text "- A\n<point>- B"
  1289. (org-return t)
  1290. (buffer-string))))
  1291. ;; On tags part of a headline, add a newline below it instead of
  1292. ;; breaking it.
  1293. (should
  1294. (equal "* H :tag:\n"
  1295. (org-test-with-temp-text "* H :<point>tag:"
  1296. (org-return)
  1297. (buffer-string))))
  1298. ;; Before headline text, add a newline below it instead of breaking
  1299. ;; it.
  1300. (should
  1301. (equal "* TODO H :tag:\n"
  1302. (org-test-with-temp-text "* <point>TODO H :tag:"
  1303. (org-return)
  1304. (buffer-string))))
  1305. (should
  1306. (equal "* TODO [#B] H :tag:\n"
  1307. (org-test-with-temp-text "* TODO<point> [#B] H :tag:"
  1308. (org-return)
  1309. (buffer-string))))
  1310. (should ;TODO are case-sensitive
  1311. (equal "* \nTodo"
  1312. (org-test-with-temp-text "* <point>Todo"
  1313. (org-return)
  1314. (buffer-string))))
  1315. ;; At headline text, break headline text but preserve tags.
  1316. (should
  1317. (equal "* TODO [#B] foo :tag:\nbar"
  1318. (let (org-auto-align-tags)
  1319. (org-test-with-temp-text "* TODO [#B] foo<point>bar :tag:"
  1320. (org-return)
  1321. (buffer-string)))))
  1322. ;; At bol of headline insert newline.
  1323. (should
  1324. (equal "\n* h"
  1325. (org-test-with-temp-text "<point>* h"
  1326. (org-return)
  1327. (buffer-string))))
  1328. ;; Refuse to leave invalid headline in buffer.
  1329. (should
  1330. (equal "* h\n"
  1331. (org-test-with-temp-text "*<point> h"
  1332. (org-return)
  1333. (buffer-string))))
  1334. ;; Before first column or after last one in a table, split the
  1335. ;; table.
  1336. (should
  1337. (equal "| a |\n\n| b |"
  1338. (org-test-with-temp-text "| a |\n<point>| b |"
  1339. (org-return)
  1340. (buffer-string))))
  1341. (should
  1342. (equal "| a |\n\n| b |"
  1343. (org-test-with-temp-text "| a |<point>\n| b |"
  1344. (org-return)
  1345. (buffer-string))))
  1346. ;; Do not auto-fill on hitting <RET> inside a property drawer.
  1347. (should
  1348. (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:"
  1349. (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:"
  1350. (setq-local fill-column 10)
  1351. (auto-fill-mode 1)
  1352. (org-return)
  1353. (buffer-string)))))
  1354. (ert-deftest test-org/with-electric-indent ()
  1355. "Test RET and C-j specifications with `electric-indent-mode' on."
  1356. ;; Call commands interactively, since this is how `newline' knows it
  1357. ;; must run `post-self-insert-hook'.
  1358. ;;
  1359. ;; RET, like `newline', should indent.
  1360. (should
  1361. (equal " Para\n graph"
  1362. (org-test-with-temp-text " Para<point>graph"
  1363. (electric-indent-local-mode 1)
  1364. (call-interactively 'org-return)
  1365. (buffer-string))))
  1366. (should
  1367. (equal "- item1\n item2"
  1368. (org-test-with-temp-text "- item1<point>item2"
  1369. (electric-indent-local-mode 1)
  1370. (call-interactively 'org-return)
  1371. (buffer-string))))
  1372. ;; TODO: test more values of `org-adapt-indentation'.
  1373. (let ((org-adapt-indentation t))
  1374. (should
  1375. (equal "* heading\n body"
  1376. (org-test-with-temp-text "* heading<point>body"
  1377. (electric-indent-local-mode 1)
  1378. (call-interactively 'org-return)
  1379. (buffer-string)))))
  1380. ;; C-j, like `electric-newline-and-maybe-indent', should not indent.
  1381. (should
  1382. (equal " Para\ngraph"
  1383. (org-test-with-temp-text " Para<point>graph"
  1384. (electric-indent-local-mode 1)
  1385. (call-interactively 'org-return-and-maybe-indent)
  1386. (buffer-string))))
  1387. (should
  1388. (equal "- item1\nitem2"
  1389. (org-test-with-temp-text "- item1<point>item2"
  1390. (electric-indent-local-mode 1)
  1391. (call-interactively 'org-return-and-maybe-indent)
  1392. (buffer-string))))
  1393. ;; TODO: test more values of `org-adapt-indentation'.
  1394. (let ((org-adapt-indentation t))
  1395. (should
  1396. (equal "* heading\nbody"
  1397. (org-test-with-temp-text "* heading<point>body"
  1398. (electric-indent-local-mode 1)
  1399. (call-interactively 'org-return-and-maybe-indent)
  1400. (buffer-string))))))
  1401. (ert-deftest test-org/without-electric-indent ()
  1402. "Test RET and C-j specifications with `electric-indent-mode' off."
  1403. ;; Call commands interactively, since this is how `newline' knows it
  1404. ;; must run `post-self-insert-hook'.
  1405. ;;
  1406. ;; RET, like `newline', should not indent.
  1407. (should
  1408. (equal " Para\ngraph"
  1409. (org-test-with-temp-text " Para<point>graph"
  1410. (electric-indent-local-mode 0)
  1411. (call-interactively 'org-return)
  1412. (buffer-string))))
  1413. (should
  1414. (equal "- item1\nitem2"
  1415. (org-test-with-temp-text "- item1<point>item2"
  1416. (electric-indent-local-mode 0)
  1417. (call-interactively 'org-return)
  1418. (buffer-string))))
  1419. (should
  1420. (equal "* heading\nbody"
  1421. (org-test-with-temp-text "* heading<point>body"
  1422. (electric-indent-local-mode 0)
  1423. (call-interactively 'org-return)
  1424. (buffer-string))))
  1425. ;; C-j, like `electric-newline-and-maybe-indent', should indent.
  1426. (should
  1427. (equal " Para\n graph"
  1428. (org-test-with-temp-text " Para<point>graph"
  1429. (electric-indent-local-mode 0)
  1430. (call-interactively 'org-return-and-maybe-indent)
  1431. (buffer-string))))
  1432. (should
  1433. (equal "- item1\n item2"
  1434. (org-test-with-temp-text "- item1<point>item2"
  1435. (electric-indent-local-mode 0)
  1436. (call-interactively 'org-return-and-maybe-indent)
  1437. (buffer-string))))
  1438. ;; TODO: test more values of `org-adapt-indentation'.
  1439. (let ((org-adapt-indentation t))
  1440. (should
  1441. (equal "* heading\n body"
  1442. (org-test-with-temp-text "* heading<point>body"
  1443. (electric-indent-local-mode 0)
  1444. (call-interactively 'org-return-and-maybe-indent)
  1445. (buffer-string))))))
  1446. (ert-deftest test-org/meta-return ()
  1447. "Test M-RET (`org-meta-return') specifications."
  1448. ;; In a table field insert a row above.
  1449. (should
  1450. (org-test-with-temp-text "| a |"
  1451. (forward-char)
  1452. (org-meta-return)
  1453. (forward-line -1)
  1454. (looking-at "| |$")))
  1455. ;; In a paragraph change current line into a header.
  1456. (should
  1457. (org-test-with-temp-text "a"
  1458. (org-meta-return)
  1459. (beginning-of-line)
  1460. (looking-at "\* a$")))
  1461. ;; In an item insert an item, in this case above.
  1462. (should
  1463. (org-test-with-temp-text "- a"
  1464. (org-meta-return)
  1465. (beginning-of-line)
  1466. (looking-at "- $")))
  1467. ;; In a drawer and item insert an item, in this case above.
  1468. (should
  1469. (org-test-with-temp-text ":MYDRAWER:\n- a\n:END:"
  1470. (forward-line)
  1471. (org-meta-return)
  1472. (beginning-of-line)
  1473. (looking-at "- $"))))
  1474. (ert-deftest test-org/insert-heading ()
  1475. "Test `org-insert-heading' specifications."
  1476. ;; In an empty buffer, insert a new headline.
  1477. (should
  1478. (equal "* "
  1479. (org-test-with-temp-text ""
  1480. (org-insert-heading)
  1481. (buffer-string))))
  1482. ;; At the beginning of a line, turn it into a headline.
  1483. (should
  1484. (equal "* P"
  1485. (org-test-with-temp-text "<point>P"
  1486. (org-insert-heading)
  1487. (buffer-string))))
  1488. ;; In the middle of a line, split the line if allowed, otherwise,
  1489. ;; insert the headline at its end.
  1490. (should
  1491. (equal "Para\n* graph"
  1492. (org-test-with-temp-text "Para<point>graph"
  1493. (let ((org-M-RET-may-split-line '((default . t))))
  1494. (org-insert-heading))
  1495. (buffer-string))))
  1496. (should
  1497. (equal "Paragraph\n* "
  1498. (org-test-with-temp-text "Para<point>graph"
  1499. (let ((org-M-RET-may-split-line '((default . nil))))
  1500. (org-insert-heading))
  1501. (buffer-string))))
  1502. ;; At the beginning of a headline, create one above.
  1503. (should
  1504. (equal "* \n* H"
  1505. (org-test-with-temp-text "* H"
  1506. (org-insert-heading)
  1507. (buffer-string))))
  1508. ;; In the middle of a headline, split it if allowed.
  1509. (should
  1510. (equal "* H\n* 1"
  1511. (org-test-with-temp-text "* H<point>1"
  1512. (let ((org-M-RET-may-split-line '((headline . t))))
  1513. (org-insert-heading))
  1514. (buffer-string))))
  1515. (should
  1516. (equal "* H1\n* "
  1517. (org-test-with-temp-text "* H<point>1"
  1518. (let ((org-M-RET-may-split-line '((headline . nil))))
  1519. (org-insert-heading))
  1520. (buffer-string))))
  1521. ;; However, splitting cannot happen on TODO keywords, priorities or
  1522. ;; tags.
  1523. (should
  1524. (equal "* TODO H1\n* "
  1525. (org-test-with-temp-text "* TO<point>DO H1"
  1526. (let ((org-M-RET-may-split-line '((headline . t))))
  1527. (org-insert-heading))
  1528. (buffer-string))))
  1529. (should
  1530. (equal "* [#A] H1\n* "
  1531. (org-test-with-temp-text "* [#<point>A] H1"
  1532. (let ((org-M-RET-may-split-line '((headline . t))))
  1533. (org-insert-heading))
  1534. (buffer-string))))
  1535. (should
  1536. (equal "* H1 :tag:\n* "
  1537. (org-test-with-temp-text "* H1 :ta<point>g:"
  1538. (let ((org-M-RET-may-split-line '((headline . t))))
  1539. (org-insert-heading))
  1540. (buffer-string))))
  1541. ;; New headline level depends on the level of the headline above.
  1542. (should
  1543. (equal "** H\n** P"
  1544. (org-test-with-temp-text "** H\n<point>P"
  1545. (org-insert-heading)
  1546. (buffer-string))))
  1547. (should
  1548. (equal "** H\nPara\n** graph"
  1549. (org-test-with-temp-text "** H\nPara<point>graph"
  1550. (let ((org-M-RET-may-split-line '((default . t))))
  1551. (org-insert-heading))
  1552. (buffer-string))))
  1553. (should
  1554. (equal "** \n** H"
  1555. (org-test-with-temp-text "** H"
  1556. (org-insert-heading)
  1557. (buffer-string))))
  1558. ;; When called with one universal argument, insert a new headline at
  1559. ;; the end of the current subtree, independently on the position of
  1560. ;; point.
  1561. (should
  1562. (equal
  1563. "* H1\n** H2\n* "
  1564. (org-test-with-temp-text "* H1\n** H2"
  1565. (let ((org-insert-heading-respect-content nil))
  1566. (org-insert-heading '(4)))
  1567. (buffer-string))))
  1568. (should
  1569. (equal
  1570. "* H1\n** H2\n* "
  1571. (org-test-with-temp-text "* H<point>1\n** H2"
  1572. (let ((org-insert-heading-respect-content nil))
  1573. (org-insert-heading '(4)))
  1574. (buffer-string))))
  1575. ;; When called with two universal arguments, insert a new headline
  1576. ;; at the end of the grandparent subtree.
  1577. (should
  1578. (equal "* H1\n** H3\n- item\n** H2\n** "
  1579. (org-test-with-temp-text "* H1\n** H3\n- item<point>\n** H2"
  1580. (let ((org-insert-heading-respect-content nil))
  1581. (org-insert-heading '(16)))
  1582. (buffer-string))))
  1583. ;; When optional TOP-LEVEL argument is non-nil, always insert
  1584. ;; a level 1 heading.
  1585. (should
  1586. (equal "* H1\n** H2\n* "
  1587. (org-test-with-temp-text "* H1\n** H2<point>"
  1588. (org-insert-heading nil nil t)
  1589. (buffer-string))))
  1590. (should
  1591. (equal "* H1\n- item\n* "
  1592. (org-test-with-temp-text "* H1\n- item<point>"
  1593. (org-insert-heading nil nil t)
  1594. (buffer-string))))
  1595. ;; Obey `org-blank-before-new-entry'.
  1596. (should
  1597. (equal "* H1\n\n* "
  1598. (org-test-with-temp-text "* H1<point>"
  1599. (let ((org-blank-before-new-entry '((heading . t))))
  1600. (org-insert-heading))
  1601. (buffer-string))))
  1602. (should
  1603. (equal "* H1\n* "
  1604. (org-test-with-temp-text "* H1<point>"
  1605. (let ((org-blank-before-new-entry '((heading . nil))))
  1606. (org-insert-heading))
  1607. (buffer-string))))
  1608. (should
  1609. (equal "* H1\n* H2\n* "
  1610. (org-test-with-temp-text "* H1\n* H2<point>"
  1611. (let ((org-blank-before-new-entry '((heading . auto))))
  1612. (org-insert-heading))
  1613. (buffer-string))))
  1614. (should
  1615. (equal "* H1\n\n* H2\n\n* "
  1616. (org-test-with-temp-text "* H1\n\n* H2<point>"
  1617. (let ((org-blank-before-new-entry '((heading . auto))))
  1618. (org-insert-heading))
  1619. (buffer-string))))
  1620. ;; Corner case: correctly insert a headline after an empty one.
  1621. (should
  1622. (equal "* \n* "
  1623. (org-test-with-temp-text "* <point>"
  1624. (org-insert-heading)
  1625. (buffer-string))))
  1626. (should
  1627. (org-test-with-temp-text "* <point>\n"
  1628. (org-insert-heading)
  1629. (looking-at-p "\n\\'")))
  1630. ;; Do not insert spurious headlines when inserting a new headline.
  1631. (should
  1632. (equal "* H1\n* H2\n* \n"
  1633. (org-test-with-temp-text "* H1\n* H2<point>\n"
  1634. (org-insert-heading)
  1635. (buffer-string))))
  1636. ;; Preserve visibility at beginning of line. In particular, when
  1637. ;; removing spurious blank lines, do not visually merge heading with
  1638. ;; the line visible above.
  1639. (should-not
  1640. (org-test-with-temp-text "* H1<point>\nContents\n\n* H2\n"
  1641. (org-overview)
  1642. (let ((org-blank-before-new-entry '((heading . nil))))
  1643. (org-insert-heading '(4)))
  1644. (invisible-p (line-end-position 0))))
  1645. ;; Properly handle empty lines when forcing a headline below current
  1646. ;; one.
  1647. (should
  1648. (equal "* H1\n\n* H\n\n* "
  1649. (org-test-with-temp-text "* H1\n\n* H<point>"
  1650. (let ((org-blank-before-new-entry '((heading . t))))
  1651. (org-insert-heading '(4))
  1652. (buffer-string))))))
  1653. (ert-deftest test-org/insert-todo-heading-respect-content ()
  1654. "Test `org-insert-todo-heading-respect-content' specifications."
  1655. ;; Create a TODO heading.
  1656. (should
  1657. (org-test-with-temp-text "* H1\n Body"
  1658. (org-insert-todo-heading-respect-content)
  1659. (nth 2 (org-heading-components))))
  1660. ;; Add headline at the end of the first subtree
  1661. (should
  1662. (equal
  1663. "* TODO "
  1664. (org-test-with-temp-text "* H1\nH1Body<point>\n** H2\nH2Body"
  1665. (org-insert-todo-heading-respect-content)
  1666. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1667. ;; In a list, do not create a new item.
  1668. (should
  1669. (equal
  1670. "* TODO "
  1671. (org-test-with-temp-text "* H\n- an item\n- another one"
  1672. (search-forward "an ")
  1673. (org-insert-todo-heading-respect-content)
  1674. (buffer-substring-no-properties (line-beginning-position) (point-max)))))
  1675. ;; Use the same TODO keyword as current heading.
  1676. (should
  1677. (equal
  1678. "* TODO \n"
  1679. (org-test-with-temp-text "* TODO\n** WAITING\n"
  1680. (org-insert-todo-heading-respect-content)
  1681. (buffer-substring-no-properties (line-beginning-position) (point-max))))))
  1682. (ert-deftest test-org/clone-with-time-shift ()
  1683. "Test `org-clone-subtree-with-time-shift'."
  1684. ;; Raise an error before first heading.
  1685. (should-error
  1686. (org-test-with-temp-text ""
  1687. (org-clone-subtree-with-time-shift 1)))
  1688. ;; Raise an error on invalid number of clones.
  1689. (should-error
  1690. (org-test-with-temp-text "* Clone me"
  1691. (org-clone-subtree-with-time-shift -1)))
  1692. ;; Clone non-repeating once.
  1693. (should
  1694. (equal "\
  1695. * H1\n<2015-06-21>
  1696. * H1\n<2015-06-23>
  1697. "
  1698. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1699. (org-clone-subtree-with-time-shift 1 "+2d")
  1700. (replace-regexp-in-string
  1701. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1702. nil nil 1))))
  1703. ;; Clone repeating once.
  1704. (should
  1705. (equal "\
  1706. * H1\n<2015-06-21>
  1707. * H1\n<2015-06-23>
  1708. * H1\n<2015-06-25 +1w>
  1709. "
  1710. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1711. (org-clone-subtree-with-time-shift 1 "+2d")
  1712. (replace-regexp-in-string
  1713. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1714. nil nil 1))))
  1715. ;; Clone repeating once in backward.
  1716. (should
  1717. (equal "\
  1718. * H1\n<2015-06-21>
  1719. * H1\n<2015-06-19>
  1720. * H1\n<2015-06-17 +1w>
  1721. "
  1722. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1723. (org-clone-subtree-with-time-shift 1 "-2d")
  1724. (replace-regexp-in-string
  1725. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1726. nil nil 1))))
  1727. ;; Clone non-repeating zero times.
  1728. (should
  1729. (equal "\
  1730. * H1\n<2015-06-21>
  1731. "
  1732. (org-test-with-temp-text "* H1\n<2015-06-21 Sun>"
  1733. (org-clone-subtree-with-time-shift 0 "+2d")
  1734. (replace-regexp-in-string
  1735. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1736. nil nil 1))))
  1737. ;; Clone repeating "zero" times.
  1738. (should
  1739. (equal "\
  1740. * H1\n<2015-06-21>
  1741. * H1\n<2015-06-23 +1w>
  1742. "
  1743. (org-test-with-temp-text "* H1\n<2015-06-21 Sun +1w>"
  1744. (org-clone-subtree-with-time-shift 0 "+2d")
  1745. (replace-regexp-in-string
  1746. "\\( [.A-Za-z]+\\)\\( \\+[0-9][hdmwy]\\)?>" "" (buffer-string)
  1747. nil nil 1))))
  1748. ;; Clone with blank SHIFT argument.
  1749. (should
  1750. (string-prefix-p
  1751. "* H <2012-03-29"
  1752. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1753. (org-clone-subtree-with-time-shift 1 "")
  1754. (buffer-substring-no-properties (line-beginning-position 2)
  1755. (line-end-position 2)))))
  1756. ;; Find time stamps before point. If SHIFT is not specified, ask
  1757. ;; for a time shift.
  1758. (should
  1759. (string-prefix-p
  1760. "* H <2012-03-30"
  1761. (org-test-with-temp-text "* H <2012-03-29 Thu><point>"
  1762. (org-clone-subtree-with-time-shift 1 "+1d")
  1763. (buffer-substring-no-properties (line-beginning-position 2)
  1764. (line-end-position 2)))))
  1765. (should
  1766. (string-prefix-p
  1767. "* H <2014-03-05"
  1768. (org-test-with-temp-text "* H <2014-03-04 Tue><point>"
  1769. (cl-letf (((symbol-function 'read-from-minibuffer)
  1770. (lambda (&rest args) "+1d")))
  1771. (org-clone-subtree-with-time-shift 1))
  1772. (buffer-substring-no-properties (line-beginning-position 2)
  1773. (line-end-position 2)))))
  1774. ;; Hour shift.
  1775. (should
  1776. (equal "\
  1777. * H1\n<2015-06-21 20:00>
  1778. * H1\n<2015-06-21 23:00>
  1779. * H1\n<2015-06-22 02:00>
  1780. "
  1781. (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>"
  1782. (org-clone-subtree-with-time-shift 2 "+3h")
  1783. (replace-regexp-in-string
  1784. "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" ""
  1785. (buffer-substring-no-properties (point-min) (point-max))
  1786. nil nil 1))))
  1787. (should
  1788. (equal "\
  1789. * H1\n<2015-06-21 20:00>
  1790. * H1\n<2015-06-21 18:00>
  1791. "
  1792. (org-test-with-temp-text "* H1\n<2015-06-21 Sun 20:00>"
  1793. (org-clone-subtree-with-time-shift 1 "-2h")
  1794. (replace-regexp-in-string
  1795. "\\( [.A-Za-z]+\\)\\( [0-9][0-9]:[0-9][0-9]\\)?>" ""
  1796. (buffer-substring-no-properties (point-min) (point-max))
  1797. nil nil 1)))))
  1798. ;;; Fixed-Width Areas
  1799. (ert-deftest test-org/toggle-fixed-width ()
  1800. "Test `org-toggle-fixed-width' specifications."
  1801. ;; No region: Toggle on fixed-width marker in paragraphs.
  1802. (should
  1803. (equal ": A"
  1804. (org-test-with-temp-text "A"
  1805. (org-toggle-fixed-width)
  1806. (buffer-string))))
  1807. ;; No region: Toggle off fixed-width markers in fixed-width areas.
  1808. (should
  1809. (equal "A"
  1810. (org-test-with-temp-text ": A"
  1811. (org-toggle-fixed-width)
  1812. (buffer-string))))
  1813. ;; No region: Toggle on marker in blank lines after elements or just
  1814. ;; after a headline.
  1815. (should
  1816. (equal "* H\n: "
  1817. (org-test-with-temp-text "* H\n"
  1818. (forward-line)
  1819. (org-toggle-fixed-width)
  1820. (buffer-string))))
  1821. (should
  1822. (equal "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n: "
  1823. (org-test-with-temp-text "#+BEGIN_EXAMPLE\nContents\n#+END_EXAMPLE\n"
  1824. (goto-char (point-max))
  1825. (org-toggle-fixed-width)
  1826. (buffer-string))))
  1827. ;; No region: Toggle on marker in front of one line elements (e.g.,
  1828. ;; headlines, clocks)
  1829. (should
  1830. (equal ": * Headline"
  1831. (org-test-with-temp-text "* Headline"
  1832. (org-toggle-fixed-width)
  1833. (buffer-string))))
  1834. (should
  1835. (equal ": #+KEYWORD: value"
  1836. (org-test-with-temp-text "#+KEYWORD: value"
  1837. (org-toggle-fixed-width)
  1838. (buffer-string))))
  1839. ;; No region: error in other situations.
  1840. (should-error
  1841. (org-test-with-temp-text "#+BEGIN_EXAMPLE\n: A\n#+END_EXAMPLE"
  1842. (forward-line)
  1843. (org-toggle-fixed-width)
  1844. (buffer-string)))
  1845. ;; No region: Indentation is preserved.
  1846. (should
  1847. (equal "- A\n : B"
  1848. (org-test-with-temp-text "- A\n B"
  1849. (forward-line)
  1850. (org-toggle-fixed-width)
  1851. (buffer-string))))
  1852. ;; Region: If it contains only fixed-width elements and blank lines,
  1853. ;; toggle off fixed-width markup.
  1854. (should
  1855. (equal "A\n\nB"
  1856. (org-test-with-temp-text ": A\n\n: B"
  1857. (transient-mark-mode 1)
  1858. (push-mark (point) t t)
  1859. (goto-char (point-max))
  1860. (org-toggle-fixed-width)
  1861. (buffer-string))))
  1862. ;; Region: If it contains anything else, toggle on fixed-width but
  1863. ;; not on fixed-width areas.
  1864. (should
  1865. (equal ": A\n: \n: B\n: \n: C"
  1866. (org-test-with-temp-text "A\n\n: B\n\nC"
  1867. (transient-mark-mode 1)
  1868. (push-mark (point) t t)
  1869. (goto-char (point-max))
  1870. (org-toggle-fixed-width)
  1871. (buffer-string))))
  1872. ;; Region: Ignore blank lines at its end, unless it contains only
  1873. ;; such lines.
  1874. (should
  1875. (equal ": A\n\n"
  1876. (org-test-with-temp-text "A\n\n"
  1877. (transient-mark-mode 1)
  1878. (push-mark (point) t t)
  1879. (goto-char (point-max))
  1880. (org-toggle-fixed-width)
  1881. (buffer-string))))
  1882. (should
  1883. (equal ": \n: \n"
  1884. (org-test-with-temp-text "\n\n"
  1885. (transient-mark-mode 1)
  1886. (push-mark (point) t t)
  1887. (goto-char (point-max))
  1888. (org-toggle-fixed-width)
  1889. (buffer-string)))))
  1890. (ert-deftest test-org/kill-line ()
  1891. "Test `org-kill-line' specifications."
  1892. ;; At the beginning of a line, kill whole line.
  1893. (should
  1894. (equal ""
  1895. (org-test-with-temp-text "abc"
  1896. (org-kill-line)
  1897. (buffer-string))))
  1898. ;; In the middle of a line, kill line until its end.
  1899. (should
  1900. (equal "a"
  1901. (org-test-with-temp-text "a<point>bc"
  1902. (org-kill-line)
  1903. (buffer-string))))
  1904. ;; Do not kill newline character.
  1905. (should
  1906. (equal "\n123"
  1907. (org-test-with-temp-text "abc\n123"
  1908. (org-kill-line)
  1909. (buffer-string))))
  1910. (should
  1911. (equal "a\n123"
  1912. (org-test-with-temp-text "a<point>bc\n123"
  1913. (org-kill-line)
  1914. (buffer-string))))
  1915. ;; When `org-special-ctrl-k' is non-nil and point is at a headline,
  1916. ;; kill until tags.
  1917. (should
  1918. (equal "* A :tag:"
  1919. (org-test-with-temp-text "* A<point>B :tag:"
  1920. (let ((org-special-ctrl-k t)
  1921. (org-tags-column 0))
  1922. (org-kill-line))
  1923. (buffer-string))))
  1924. ;; If point is on tags, only kill part left until the end of line.
  1925. (should
  1926. (equal "* A :tag:"
  1927. (org-test-with-temp-text "* A :tag:<point>tag2:"
  1928. (let ((org-special-ctrl-k t)
  1929. (org-tags-column 0))
  1930. (org-kill-line))
  1931. (buffer-string))))
  1932. ;; However, if point is at the beginning of the line, kill whole
  1933. ;; headline.
  1934. (should
  1935. (equal ""
  1936. (org-test-with-temp-text "* AB :tag:"
  1937. (let ((org-special-ctrl-k t)
  1938. (org-tags-column 0))
  1939. (org-kill-line))
  1940. (buffer-string))))
  1941. ;; When `org-ctrl-k-protect-subtree' is non-nil, and point is in
  1942. ;; invisible text, ask before removing it. When set to `error',
  1943. ;; throw an error.
  1944. (should-error
  1945. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  1946. (org-overview)
  1947. (let ((org-special-ctrl-k nil)
  1948. (org-ctrl-k-protect-subtree t))
  1949. (cl-letf (((symbol-function 'y-or-n-p) 'ignore))
  1950. (org-kill-line)))))
  1951. (should-error
  1952. (org-test-with-temp-text "* H\n** <point>H2\nContents\n* H3"
  1953. (org-overview)
  1954. (let ((org-special-ctrl-k nil)
  1955. (org-ctrl-k-protect-subtree 'error))
  1956. (org-kill-line)))))
  1957. ;;; Headline
  1958. (ert-deftest test-org/get-heading ()
  1959. "Test `org-get-heading' specifications."
  1960. ;; Return current heading, even if point is not on it.
  1961. (should
  1962. (equal "H"
  1963. (org-test-with-temp-text "* H"
  1964. (org-get-heading))))
  1965. (should
  1966. (equal "H"
  1967. (org-test-with-temp-text "* H\nText<point>"
  1968. (org-get-heading))))
  1969. ;; Without any optional argument, return TODO keyword, priority
  1970. ;; cookie, COMMENT keyword and tags.
  1971. (should
  1972. (equal "TODO H"
  1973. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  1974. (org-get-heading))))
  1975. (should
  1976. (equal "[#A] H"
  1977. (org-test-with-temp-text "* [#A] H"
  1978. (org-get-heading))))
  1979. (should
  1980. (equal "COMMENT H"
  1981. (org-test-with-temp-text "* COMMENT H"
  1982. (org-get-heading))))
  1983. (should
  1984. (equal "H :tag:"
  1985. (org-test-with-temp-text "* H :tag:"
  1986. (org-get-heading))))
  1987. ;; With NO-TAGS argument, ignore tags.
  1988. (should
  1989. (equal "TODO H"
  1990. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  1991. (org-get-heading t))))
  1992. (should
  1993. (equal "H"
  1994. (org-test-with-temp-text "* H :tag:"
  1995. (org-get-heading t))))
  1996. ;; With NO-TODO, ignore TODO keyword.
  1997. (should
  1998. (equal "H"
  1999. (org-test-with-temp-text "#+TODO: TODO | DONE\n* TODO H<point>"
  2000. (org-get-heading nil t))))
  2001. (should
  2002. (equal "H :tag:"
  2003. (org-test-with-temp-text "* H :tag:"
  2004. (org-get-heading nil t))))
  2005. ;; TODO keywords are case-sensitive.
  2006. (should
  2007. (equal "Todo H"
  2008. (org-test-with-temp-text "#+TODO: TODO | DONE\n* Todo H<point>"
  2009. (org-get-heading nil t))))
  2010. ;; With NO-PRIORITY, ignore priority.
  2011. (should
  2012. (equal "H"
  2013. (org-test-with-temp-text "* [#A] H"
  2014. (org-get-heading nil nil t))))
  2015. (should
  2016. (equal "H"
  2017. (org-test-with-temp-text "* H"
  2018. (org-get-heading nil nil t))))
  2019. (should
  2020. (equal "TODO H"
  2021. (org-test-with-temp-text "* TODO [#A] H"
  2022. (org-get-heading nil nil t))))
  2023. ;; With NO-COMMENT, ignore COMMENT keyword.
  2024. (should
  2025. (equal "H"
  2026. (org-test-with-temp-text "* COMMENT H"
  2027. (org-get-heading nil nil nil t))))
  2028. (should
  2029. (equal "H"
  2030. (org-test-with-temp-text "* H"
  2031. (org-get-heading nil nil nil t))))
  2032. (should
  2033. (equal "TODO [#A] H"
  2034. (org-test-with-temp-text "* TODO [#A] COMMENT H"
  2035. (org-get-heading nil nil nil t))))
  2036. ;; On an empty headline, return value is consistent.
  2037. (should (equal "" (org-test-with-temp-text "* " (org-get-heading))))
  2038. (should (equal "" (org-test-with-temp-text "* " (org-get-heading t))))
  2039. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil t))))
  2040. (should (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil t))))
  2041. (should
  2042. (equal "" (org-test-with-temp-text "* " (org-get-heading nil nil nil t)))))
  2043. (ert-deftest test-org/in-commented-heading-p ()
  2044. "Test `org-in-commented-heading-p' specifications."
  2045. ;; Commented headline.
  2046. (should
  2047. (org-test-with-temp-text "* COMMENT Headline\nBody"
  2048. (goto-char (point-max))
  2049. (org-in-commented-heading-p)))
  2050. ;; Commented ancestor.
  2051. (should
  2052. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  2053. (goto-char (point-max))
  2054. (org-in-commented-heading-p)))
  2055. ;; Comment keyword is case-sensitive.
  2056. (should-not
  2057. (org-test-with-temp-text "* Comment Headline\nBody"
  2058. (goto-char (point-max))
  2059. (org-in-commented-heading-p)))
  2060. ;; Keyword is standalone.
  2061. (should-not
  2062. (org-test-with-temp-text "* COMMENTHeadline\nBody"
  2063. (goto-char (point-max))
  2064. (org-in-commented-heading-p)))
  2065. ;; Optional argument.
  2066. (should-not
  2067. (org-test-with-temp-text "* COMMENT Headline\n** Level 2\nBody"
  2068. (goto-char (point-max))
  2069. (org-in-commented-heading-p t))))
  2070. (ert-deftest test-org/in-archived-heading-p ()
  2071. "Test `org-in-archived-heading-p' specifications."
  2072. ;; Archived headline.
  2073. (should
  2074. (org-test-with-temp-text "* Headline :ARCHIVE:\nBody"
  2075. (goto-char (point-max))
  2076. (org-in-archived-heading-p)))
  2077. ;; Archived ancestor.
  2078. (should
  2079. (org-test-with-temp-text "* Headline :ARCHIVE:\n** Level 2\nBody"
  2080. (goto-char (point-max))
  2081. (org-in-archived-heading-p)))
  2082. ;; Optional argument.
  2083. (should-not
  2084. (org-test-with-temp-text "* Headline :ARCHIVE:\n** Level 2\nBody"
  2085. (goto-char (point-max))
  2086. (org-in-archived-heading-p t)))
  2087. ;; Archive tag containing ARCHIVE as substring
  2088. (should-not
  2089. (org-test-with-temp-text "* Headline :NOARCHIVE:\n** Level 2\nBody"
  2090. (goto-char (point-max))
  2091. (org-in-archived-heading-p))))
  2092. (ert-deftest test-org/entry-blocked-p ()
  2093. ;; Check other dependencies.
  2094. (should
  2095. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  2096. (let ((org-enforce-todo-dependencies t)
  2097. (org-blocker-hook
  2098. '(org-block-todo-from-children-or-siblings-or-parent)))
  2099. (org-entry-blocked-p))))
  2100. (should-not
  2101. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  2102. (let ((org-enforce-todo-dependencies t)
  2103. (org-blocker-hook
  2104. '(org-block-todo-from-children-or-siblings-or-parent)))
  2105. (org-entry-blocked-p))))
  2106. ;; Entry without a TODO keyword or with a DONE keyword cannot be
  2107. ;; blocked.
  2108. (should-not
  2109. (org-test-with-temp-text "* Blocked\n** TODO one"
  2110. (let ((org-enforce-todo-dependencies t)
  2111. (org-blocker-hook
  2112. '(org-block-todo-from-children-or-siblings-or-parent)))
  2113. (org-entry-blocked-p))))
  2114. (should-not
  2115. (org-test-with-temp-text "* DONE Blocked\n** TODO one"
  2116. (let ((org-enforce-todo-dependencies t)
  2117. (org-blocker-hook
  2118. '(org-block-todo-from-children-or-siblings-or-parent)))
  2119. (org-entry-blocked-p))))
  2120. ;; Follow :ORDERED: specifications.
  2121. (should
  2122. (org-test-with-temp-text
  2123. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** TODO one\n** <point>TODO two"
  2124. (let ((org-enforce-todo-dependencies t)
  2125. (org-blocker-hook
  2126. '(org-block-todo-from-children-or-siblings-or-parent)))
  2127. (org-entry-blocked-p))))
  2128. (should-not
  2129. (org-test-with-temp-text
  2130. "* H\n:PROPERTIES:\n:ORDERED: t\n:END:\n** <point>TODO one\n** DONE two"
  2131. (let ((org-enforce-todo-dependencies t)
  2132. (org-blocker-hook
  2133. '(org-block-todo-from-children-or-siblings-or-parent)))
  2134. (org-entry-blocked-p)))))
  2135. (ert-deftest test-org/get-outline-path ()
  2136. "Test `org-get-outline-path' specifications."
  2137. ;; Top-level headlines have no outline path.
  2138. (should-not
  2139. (org-test-with-temp-text "* H"
  2140. (org-get-outline-path)))
  2141. ;; Otherwise, outline path is the path leading to the headline.
  2142. (should
  2143. (equal '("H")
  2144. (org-test-with-temp-text "* H\n** S<point>"
  2145. (org-get-outline-path))))
  2146. ;; Find path even when point is not on a headline.
  2147. (should
  2148. (equal '("H")
  2149. (org-test-with-temp-text "* H\n** S\nText<point>"
  2150. (org-get-outline-path))))
  2151. ;; TODO keywords, tags and statistics cookies are ignored.
  2152. (should
  2153. (equal '("H")
  2154. (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
  2155. (org-get-outline-path))))
  2156. ;; Links are replaced with their description or their path.
  2157. (should
  2158. (equal '("Org")
  2159. (org-test-with-temp-text
  2160. "* [[https://orgmode.org][Org]]\n** S<point>"
  2161. (org-get-outline-path))))
  2162. (should
  2163. (equal '("https://orgmode.org")
  2164. (org-test-with-temp-text
  2165. "* [[https://orgmode.org]]\n** S<point>"
  2166. (org-get-outline-path))))
  2167. ;; When WITH-SELF is non-nil, include current heading.
  2168. (should
  2169. (equal '("H")
  2170. (org-test-with-temp-text "* H"
  2171. (org-get-outline-path t))))
  2172. (should
  2173. (equal '("H" "S")
  2174. (org-test-with-temp-text "* H\n** S\nText<point>"
  2175. (org-get-outline-path t))))
  2176. ;; Using cache is transparent to the user.
  2177. (should
  2178. (equal '("H")
  2179. (org-test-with-temp-text "* H\n** S<point>"
  2180. (setq org-outline-path-cache nil)
  2181. (org-get-outline-path nil t))))
  2182. ;; Do not corrupt cache when finding outline path in distant part of
  2183. ;; the buffer.
  2184. (should
  2185. (equal '("H2")
  2186. (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
  2187. (setq org-outline-path-cache nil)
  2188. (org-get-outline-path nil t)
  2189. (search-forward "S2")
  2190. (org-get-outline-path nil t))))
  2191. ;; Do not choke on empty headlines.
  2192. (should
  2193. (org-test-with-temp-text "* H\n** <point>"
  2194. (org-get-outline-path)))
  2195. (should
  2196. (org-test-with-temp-text "* \n** H<point>"
  2197. (org-get-outline-path))))
  2198. (ert-deftest test-org/format-outline-path ()
  2199. "Test `org-format-outline-path' specifications."
  2200. (should
  2201. (string= (org-format-outline-path (list "one" "two" "three"))
  2202. "one/two/three"))
  2203. ;; Empty path.
  2204. (should
  2205. (string= (org-format-outline-path '())
  2206. ""))
  2207. (should
  2208. (string= (org-format-outline-path '(nil))
  2209. ""))
  2210. ;; Empty path and prefix.
  2211. (should
  2212. (string= (org-format-outline-path '() nil ">>")
  2213. ">>"))
  2214. ;; Trailing whitespace in headings.
  2215. (should
  2216. (string= (org-format-outline-path (list "one\t" "tw o " "three "))
  2217. "one/tw o/three"))
  2218. ;; Non-default prefix and separators.
  2219. (should
  2220. (string= (org-format-outline-path (list "one" "two" "three") nil ">>" "|")
  2221. ">>|one|two|three"))
  2222. ;; Truncate.
  2223. (should
  2224. (string= (org-format-outline-path (list "one" "two" "three" "four") 10)
  2225. "one/two/.."))
  2226. ;; Give a very narrow width.
  2227. (should
  2228. (string= (org-format-outline-path (list "one" "two" "three" "four") 2)
  2229. "on"))
  2230. ;; Give a prefix that extends beyond the width.
  2231. (should
  2232. (string= (org-format-outline-path (list "one" "two" "three" "four") 10
  2233. ">>>>>>>>>>")
  2234. ">>>>>>>>..")))
  2235. (ert-deftest test-org/map-entries ()
  2236. "Test `org-map-entries' specifications."
  2237. ;; Full match.
  2238. (should
  2239. (equal '(1 11)
  2240. (org-test-with-temp-text "* Level 1\n** Level 2"
  2241. (org-map-entries #'point))))
  2242. ;; Level match.
  2243. (should
  2244. (equal '(1)
  2245. (org-test-with-temp-text "* Level 1\n** Level 2"
  2246. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL=1")))))
  2247. (should
  2248. (equal '(11)
  2249. (org-test-with-temp-text "* Level 1\n** Level 2"
  2250. (let (org-odd-levels-only) (org-map-entries #'point "LEVEL>1")))))
  2251. ;; Tag match.
  2252. (should
  2253. (equal '(11)
  2254. (org-test-with-temp-text "* H1 :no:\n* H2 :yes:"
  2255. (org-map-entries #'point "yes"))))
  2256. (should
  2257. (equal '(14)
  2258. (org-test-with-temp-text "* H1 :yes:a:\n* H2 :yes:b:"
  2259. (org-map-entries #'point "+yes-a"))))
  2260. (should
  2261. (equal '(11 23)
  2262. (org-test-with-temp-text "* H1 :no:\n* H2 :yes1:\n* H3 :yes2:"
  2263. (org-map-entries #'point "{yes?}"))))
  2264. ;; Priority match.
  2265. (should
  2266. (equal '(1)
  2267. (org-test-with-temp-text "* [#A] H1\n* [#B] H2"
  2268. (org-map-entries #'point "PRIORITY=\"A\""))))
  2269. ;; Date match.
  2270. (should
  2271. (equal '(36)
  2272. (org-test-with-temp-text "
  2273. * H1
  2274. SCHEDULED: <2012-03-29 thu.>
  2275. * H2
  2276. SCHEDULED: <2014-03-04 tue.>"
  2277. (org-map-entries #'point "SCHEDULED=\"<2014-03-04 tue.>\""))))
  2278. (should
  2279. (equal '(2)
  2280. (org-test-with-temp-text "
  2281. * H1
  2282. SCHEDULED: <2012-03-29 thu.>
  2283. * H2
  2284. SCHEDULED: <2014-03-04 tue.>"
  2285. (org-map-entries #'point "SCHEDULED<\"<2013-01-01>\""))))
  2286. ;; Regular property match.
  2287. (should
  2288. (equal '(2)
  2289. (org-test-with-temp-text "
  2290. * H1
  2291. :PROPERTIES:
  2292. :TEST: 1
  2293. :END:
  2294. * H2
  2295. :PROPERTIES:
  2296. :TEST: 2
  2297. :END:"
  2298. (org-map-entries #'point "TEST=1"))))
  2299. ;; Multiple criteria.
  2300. (should
  2301. (equal '(23)
  2302. (org-test-with-temp-text "* H1 :no:\n** H2 :yes:\n* H3 :yes:"
  2303. (let (org-odd-levels-only
  2304. (org-use-tag-inheritance nil))
  2305. (org-map-entries #'point "yes+LEVEL=1")))))
  2306. ;; "or" criteria.
  2307. (should
  2308. (equal '(12 24)
  2309. (org-test-with-temp-text "* H1 :yes:\n** H2 :yes:\n** H3 :no:"
  2310. (let (org-odd-levels-only)
  2311. (org-map-entries #'point "LEVEL=2|no")))))
  2312. (should
  2313. (equal '(1 12)
  2314. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :maybe:"
  2315. (let (org-odd-levels-only)
  2316. (org-map-entries #'point "yes|no")))))
  2317. ;; "and" criteria.
  2318. (should
  2319. (equal '(22)
  2320. (org-test-with-temp-text "* H1 :yes:\n* H2 :no:\n* H3 :yes:no:"
  2321. (let (org-odd-levels-only)
  2322. (org-map-entries #'point "yes&no"))))))
  2323. (ert-deftest test-org/edit-headline ()
  2324. "Test `org-edit-headline' specifications."
  2325. (should
  2326. (equal "* B"
  2327. (org-test-with-temp-text "* A"
  2328. (org-edit-headline "B")
  2329. (buffer-string))))
  2330. ;; Handle empty headings.
  2331. (should
  2332. (equal "* "
  2333. (org-test-with-temp-text "* A"
  2334. (org-edit-headline "")
  2335. (buffer-string))))
  2336. (should
  2337. (equal "* A"
  2338. (org-test-with-temp-text "* "
  2339. (org-edit-headline "A")
  2340. (buffer-string))))
  2341. ;; Handle TODO keywords and priority cookies.
  2342. (should
  2343. (equal "* TODO B"
  2344. (org-test-with-temp-text "* TODO A"
  2345. (org-edit-headline "B")
  2346. (buffer-string))))
  2347. (should
  2348. (equal "* [#A] B"
  2349. (org-test-with-temp-text "* [#A] A"
  2350. (org-edit-headline "B")
  2351. (buffer-string))))
  2352. (should
  2353. (equal "* TODO [#A] B"
  2354. (org-test-with-temp-text "* TODO [#A] A"
  2355. (org-edit-headline "B")
  2356. (buffer-string))))
  2357. ;; Handle tags.
  2358. (equal "* B :tag:"
  2359. (org-test-with-temp-text "* A :tag:"
  2360. (let ((org-tags-column 4)) (org-edit-headline "B"))
  2361. (buffer-string))))
  2362. ;;; Keywords
  2363. (ert-deftest test-org/set-regexps-and-options ()
  2364. "Test `org-set-regexps-and-options' specifications."
  2365. ;; TAGS keyword.
  2366. (should
  2367. (equal '(("A"))
  2368. (let ((org-tag-alist '(("A")))
  2369. (org-tag-persistent-alist nil))
  2370. (org-test-with-temp-text ""
  2371. (org-mode-restart)
  2372. org-current-tag-alist))))
  2373. (should
  2374. (equal '(("B"))
  2375. (let ((org-tag-alist '(("A")))
  2376. (org-tag-persistent-alist nil))
  2377. (org-test-with-temp-text "#+TAGS: B"
  2378. (org-mode-restart)
  2379. org-current-tag-alist))))
  2380. (should
  2381. (equal '(("C") ("B"))
  2382. (let ((org-tag-alist '(("A")))
  2383. (org-tag-persistent-alist '(("C"))))
  2384. (org-test-with-temp-text "#+TAGS: B"
  2385. (org-mode-restart)
  2386. org-current-tag-alist))))
  2387. (should
  2388. (equal '(("B"))
  2389. (let ((org-tag-alist '(("A")))
  2390. (org-tag-persistent-alist '(("C"))))
  2391. (org-test-with-temp-text "#+STARTUP: noptag\n#+TAGS: B"
  2392. (org-mode-restart)
  2393. org-current-tag-alist))))
  2394. (should
  2395. (equal '(("A" . ?a) ("B") ("C"))
  2396. (let ((org-tag-persistant-alist nil))
  2397. (org-test-with-temp-text "#+TAGS: A(a) B C"
  2398. (org-mode-restart)
  2399. org-current-tag-alist))))
  2400. (should
  2401. (equal '(("A") (:newline) ("B"))
  2402. (let ((org-tag-persistent-alist nil))
  2403. (org-test-with-temp-text "#+TAGS: A\n#+TAGS: B"
  2404. (org-mode-restart)
  2405. org-current-tag-alist))))
  2406. (should
  2407. (equal '((:startgroup) ("A") ("B") (:endgroup) ("C"))
  2408. (let ((org-tag-persistent-alist nil))
  2409. (org-test-with-temp-text "#+TAGS: { A B } C"
  2410. (org-mode-restart)
  2411. org-current-tag-alist))))
  2412. (should
  2413. (equal '((:startgroup) ("A") (:grouptags) ("B") ("C") (:endgroup))
  2414. (let ((org-tag-persistent-alist nil))
  2415. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2416. (org-mode-restart)
  2417. org-current-tag-alist))))
  2418. (should
  2419. (equal '(("A" "B" "C"))
  2420. (let ((org-tag-persistent-alist nil))
  2421. (org-test-with-temp-text "#+TAGS: { A : B C }"
  2422. (org-mode-restart)
  2423. org-tag-groups-alist))))
  2424. (should
  2425. (equal '((:startgrouptag) ("A") (:grouptags) ("B") ("C") (:endgrouptag))
  2426. (let ((org-tag-persistent-alist nil))
  2427. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2428. (org-mode-restart)
  2429. org-current-tag-alist))))
  2430. (should
  2431. (equal '(("A" "B" "C"))
  2432. (let ((org-tag-persistent-alist nil))
  2433. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  2434. (org-mode-restart)
  2435. org-tag-groups-alist))))
  2436. (should-not
  2437. (let ((org-tag-alist '(("A"))))
  2438. (org-test-with-temp-text "#+TAGS:"
  2439. (org-mode-restart)
  2440. org-current-tag-alist)))
  2441. ;; FILETAGS keyword.
  2442. (should
  2443. (equal '("A" "B" "C")
  2444. (org-test-with-temp-text "#+FILETAGS: :A:B:C:"
  2445. (org-mode-restart)
  2446. org-file-tags)))
  2447. ;; PROPERTY keyword. Property names are case-insensitive.
  2448. (should
  2449. (equal "foo=1"
  2450. (org-test-with-temp-text "#+PROPERTY: var foo=1"
  2451. (org-mode-restart)
  2452. (cdr (assoc "var" org-keyword-properties)))))
  2453. (should
  2454. (equal
  2455. "foo=1 bar=2"
  2456. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: var+ bar=2"
  2457. (org-mode-restart)
  2458. (cdr (assoc "var" org-keyword-properties)))))
  2459. (should
  2460. (equal
  2461. "foo=1 bar=2"
  2462. (org-test-with-temp-text "#+PROPERTY: var foo=1\n#+PROPERTY: VAR+ bar=2"
  2463. (org-mode-restart)
  2464. (cdr (assoc "var" org-keyword-properties)))))
  2465. ;; ARCHIVE keyword.
  2466. (should
  2467. (equal "%s_done::"
  2468. (org-test-with-temp-text "#+ARCHIVE: %s_done::"
  2469. (org-mode-restart)
  2470. org-archive-location)))
  2471. ;; CATEGORY keyword.
  2472. (should
  2473. (eq 'test
  2474. (org-test-with-temp-text "#+CATEGORY: test"
  2475. (org-mode-restart)
  2476. org-category)))
  2477. (should
  2478. (equal "test"
  2479. (org-test-with-temp-text "#+CATEGORY: test"
  2480. (org-mode-restart)
  2481. (cdr (assoc "CATEGORY" org-keyword-properties)))))
  2482. ;; COLUMNS keyword.
  2483. (should
  2484. (equal "%25ITEM %TAGS %PRIORITY %TODO"
  2485. (org-test-with-temp-text "#+COLUMNS: %25ITEM %TAGS %PRIORITY %TODO"
  2486. (org-mode-restart)
  2487. org-columns-default-format)))
  2488. ;; CONSTANTS keyword. Constants names are case sensitive.
  2489. (should
  2490. (equal '("299792458." "3.14")
  2491. (org-test-with-temp-text "#+CONSTANTS: c=299792458. pi=3.14"
  2492. (org-mode-restart)
  2493. (mapcar
  2494. (lambda (n) (cdr (assoc n org-table-formula-constants-local)))
  2495. '("c" "pi")))))
  2496. (should
  2497. (equal "3.14"
  2498. (org-test-with-temp-text "#+CONSTANTS: pi=22/7 pi=3.14"
  2499. (org-mode-restart)
  2500. (cdr (assoc "pi" org-table-formula-constants-local)))))
  2501. (should
  2502. (equal "22/7"
  2503. (org-test-with-temp-text "#+CONSTANTS: PI=22/7 pi=3.14"
  2504. (org-mode-restart)
  2505. (cdr (assoc "PI" org-table-formula-constants-local)))))
  2506. ;; LINK keyword.
  2507. (should
  2508. (equal
  2509. '("url1" "url2")
  2510. (org-test-with-temp-text "#+LINK: a url1\n#+LINK: b url2"
  2511. (org-mode-restart)
  2512. (mapcar (lambda (abbrev) (cdr (assoc abbrev org-link-abbrev-alist-local)))
  2513. '("a" "b")))))
  2514. ;; PRIORITIES keyword. Incomplete priorities sets are ignored.
  2515. (should
  2516. (equal
  2517. '(?X ?Z ?Y)
  2518. (org-test-with-temp-text "#+PRIORITIES: X Z Y"
  2519. (org-mode-restart)
  2520. (list org-priority-highest org-priority-lowest org-priority-default))))
  2521. (should
  2522. (equal
  2523. '(?A ?C ?B)
  2524. (org-test-with-temp-text "#+PRIORITIES: X Z"
  2525. (org-mode-restart)
  2526. (list org-priority-highest org-priority-lowest org-priority-default))))
  2527. ;; STARTUP keyword.
  2528. (should
  2529. (equal '(t t)
  2530. (org-test-with-temp-text "#+STARTUP: fold odd"
  2531. (org-mode-restart)
  2532. (list org-startup-folded org-odd-levels-only))))
  2533. ;; TODO keywords.
  2534. (should
  2535. (equal '(("A" "B") ("C"))
  2536. (org-test-with-temp-text "#+TODO: A B | C"
  2537. (org-mode-restart)
  2538. (list org-not-done-keywords org-done-keywords))))
  2539. (should
  2540. (equal '(("A" "C") ("B" "D"))
  2541. (org-test-with-temp-text "#+TODO: A | B\n#+TODO: C | D"
  2542. (org-mode-restart)
  2543. (list org-not-done-keywords org-done-keywords))))
  2544. (should
  2545. (equal '(("A" "B") ("C"))
  2546. (org-test-with-temp-text "#+TYP_TODO: A B | C"
  2547. (org-mode-restart)
  2548. (list org-not-done-keywords org-done-keywords))))
  2549. (should
  2550. (equal '((:startgroup) ("A" . ?a) (:endgroup))
  2551. (org-test-with-temp-text "#+TODO: A(a)"
  2552. (org-mode-restart)
  2553. org-todo-key-alist)))
  2554. (should
  2555. (equal '(("D" note nil) ("C" time nil) ("B" note time))
  2556. (org-test-with-temp-text "#+TODO: A(a) B(b@/!) | C(c!) D(d@)"
  2557. (org-mode-restart)
  2558. org-todo-log-states)))
  2559. ;; Enter SETUPFILE keyword.
  2560. (should
  2561. (equal "1"
  2562. (org-test-with-temp-text
  2563. (format "#+SETUPFILE: \"%s/examples/setupfile.org\"" org-test-dir)
  2564. (org-mode-restart)
  2565. (cdr (assoc "a" org-keyword-properties))))))
  2566. ;;; Links
  2567. ;;;; Coderefs
  2568. (ert-deftest test-org/coderef ()
  2569. "Test coderef links specifications."
  2570. (should
  2571. (org-test-with-temp-text "
  2572. #+BEGIN_SRC emacs-lisp
  2573. \(+ 1 1) (ref:sc)
  2574. #+END_SRC
  2575. \[[(sc)<point>]]"
  2576. (org-open-at-point)
  2577. (looking-at "(ref:sc)")))
  2578. ;; Find coderef even with alternate label format.
  2579. (should
  2580. (org-test-with-temp-text "
  2581. #+BEGIN_SRC emacs-lisp -l \"{ref:%s}\"
  2582. \(+ 1 1) {ref:sc}
  2583. #+END_SRC
  2584. \[[(sc)<point>]]"
  2585. (org-open-at-point)
  2586. (looking-at "{ref:sc}"))))
  2587. ;;;; Custom ID
  2588. (ert-deftest test-org/custom-id ()
  2589. "Test custom ID links specifications."
  2590. (should
  2591. (org-test-with-temp-text
  2592. "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2593. (org-open-at-point)
  2594. (looking-at-p "\\* H1")))
  2595. ;; Handle escape characters.
  2596. (should
  2597. (org-test-with-temp-text
  2598. "* H1\n:PROPERTIES:\n:CUSTOM_ID: [%]\n:END:\n* H2\n[[#\\[%\\]<point>]]"
  2599. (org-open-at-point)
  2600. (looking-at-p "\\* H1")))
  2601. ;; Throw an error on false positives.
  2602. (should-error
  2603. (org-test-with-temp-text
  2604. "* H1\n:DRAWER:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom<point>]]"
  2605. (org-open-at-point)
  2606. (looking-at-p "\\* H1"))))
  2607. ;;;; Fuzzy Links
  2608. ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
  2609. ;; a named element (#+name: text) and to headlines (* Text).
  2610. (ert-deftest test-org/fuzzy-links ()
  2611. "Test fuzzy links specifications."
  2612. ;; Fuzzy link goes in priority to a matching target.
  2613. (should
  2614. (org-test-with-temp-text
  2615. "#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n<point>[[Test]]"
  2616. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2617. (looking-at "<<Test>>")))
  2618. ;; Then fuzzy link points to an element with a given name.
  2619. (should
  2620. (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n<point>[[Test]]"
  2621. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2622. (looking-at "#\\+NAME: Test")))
  2623. ;; A target still lead to a matching headline otherwise.
  2624. (should
  2625. (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n<point>[[Head2]]"
  2626. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2627. (looking-at "\\* Head2")))
  2628. ;; With a leading star in link, enforce heading match.
  2629. (should
  2630. (org-test-with-temp-text "* Test\n<<Test>>\n<point>[[*Test]]"
  2631. (let ((org-link-search-must-match-exact-headline nil)) (org-open-at-point))
  2632. (looking-at "\\* Test")))
  2633. ;; With a leading star in link, enforce exact heading match, even
  2634. ;; with `org-link-search-must-match-exact-headline' set to nil.
  2635. (should-error
  2636. (org-test-with-temp-text "* Test 1\nFoo Bar\n<point>[[*Test]]"
  2637. (let ((org-link-search-must-match-exact-headline nil))
  2638. (org-open-at-point))))
  2639. ;; Handle non-nil `org-link-search-must-match-exact-headline'.
  2640. (should
  2641. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[Test]]"
  2642. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2643. (looking-at "\\* Test")))
  2644. (should
  2645. (org-test-with-temp-text "* Test\nFoo Bar\n<point>[[*Test]]"
  2646. (let ((org-link-search-must-match-exact-headline t)) (org-open-at-point))
  2647. (looking-at "\\* Test")))
  2648. ;; Heading match should not care about spaces, cookies, TODO
  2649. ;; keywords, priorities, and tags. However, TODO keywords are
  2650. ;; case-sensitive.
  2651. (should
  2652. (let ((first-line
  2653. "** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent: "))
  2654. (org-test-with-temp-text
  2655. (concat first-line "\nFoo Bar\n<point>[[*Test 1 2]]")
  2656. (let ((org-link-search-must-match-exact-headline nil)
  2657. (org-todo-regexp "TODO"))
  2658. (org-open-at-point))
  2659. (looking-at (regexp-quote first-line)))))
  2660. (should-error
  2661. (org-test-with-temp-text "** todo Test 1 2\nFoo Bar\n<point>[[*Test 1 2]]"
  2662. (let ((org-link-search-must-match-exact-headline nil)
  2663. (org-todo-regexp "TODO"))
  2664. (org-open-at-point))))
  2665. ;; Heading match should still be exact.
  2666. (should-error
  2667. (org-test-with-temp-text "
  2668. ** TODO [#A] [/] Test [1/2] [33%] 1 \t 2 [%] :work:urgent:
  2669. Foo Bar
  2670. <point>[[*Test 1]]"
  2671. (let ((org-link-search-must-match-exact-headline nil)
  2672. (org-todo-regexp "TODO"))
  2673. (org-open-at-point))))
  2674. (should
  2675. (org-test-with-temp-text "* Test 1 2 3\n** Test 1 2\n<point>[[*Test 1 2]]"
  2676. (let ((org-link-search-must-match-exact-headline nil)
  2677. (org-todo-regexp "TODO"))
  2678. (org-open-at-point))
  2679. (looking-at-p (regexp-quote "** Test 1 2"))))
  2680. ;; Heading match ignores COMMENT keyword.
  2681. (should
  2682. (org-test-with-temp-text "[[*Test]]\n* COMMENT Test"
  2683. (org-open-at-point)
  2684. (looking-at "\\* COMMENT Test")))
  2685. (should
  2686. (org-test-with-temp-text "[[*Test]]\n* TODO COMMENT Test"
  2687. (org-open-at-point)
  2688. (looking-at "\\* TODO COMMENT Test")))
  2689. ;; Correctly un-escape fuzzy links.
  2690. (should
  2691. (org-test-with-temp-text "* [foo]\n[[*\\[foo\\]][With escaped characters]]"
  2692. (org-open-at-point)
  2693. (bobp)))
  2694. ;; Match search strings containing newline characters, including
  2695. ;; blank lines.
  2696. (should
  2697. (org-test-with-temp-text-in-file "Paragraph\n\nline1\nline2\n\n"
  2698. (let ((file (buffer-file-name)))
  2699. (goto-char (point-max))
  2700. (insert (format "[[file:%s::line1 line2]]" file))
  2701. (beginning-of-line)
  2702. (let ((org-link-search-must-match-exact-headline nil))
  2703. (org-open-at-point 0))
  2704. (looking-at-p "line1"))))
  2705. (should
  2706. (org-test-with-temp-text-in-file "Paragraph\n\nline1\n\nline2\n\n"
  2707. (let ((file (buffer-file-name)))
  2708. (goto-char (point-max))
  2709. (insert (format "[[file:%s::line1 line2]]" file))
  2710. (beginning-of-line)
  2711. (let ((org-link-search-must-match-exact-headline nil))
  2712. (org-open-at-point 0))
  2713. (looking-at-p "line1")))))
  2714. ;;;; Open at point
  2715. (ert-deftest test-org/open-at-point/keyword ()
  2716. "Does `org-open-at-point' open link in a keyword line?"
  2717. (should
  2718. (org-test-with-temp-text
  2719. "<<top>>\n#+KEYWORD: <point>[[top]]"
  2720. (org-open-at-point) t))
  2721. (should
  2722. (org-test-with-temp-text
  2723. "* H\n<<top>>\n#+KEYWORD: <point>[[top]]"
  2724. (org-open-at-point) t)))
  2725. (ert-deftest test-org/open-at-point/property ()
  2726. "Does `org-open-at-point' open link in property drawer?"
  2727. (should
  2728. (org-test-with-temp-text
  2729. "* Headline
  2730. :PROPERTIES:
  2731. :URL: <point>[[*Headline]]
  2732. :END:"
  2733. (org-open-at-point) t)))
  2734. (ert-deftest test-org/open-at-point/comment ()
  2735. "Does `org-open-at-point' open link in a commented line?"
  2736. (should
  2737. (org-test-with-temp-text
  2738. "<<top>>\n# <point>[[top]]"
  2739. (org-open-at-point) t))
  2740. (should
  2741. (org-test-with-temp-text
  2742. "* H\n<<top>>\n# <point>[[top]]"
  2743. (org-open-at-point) t)))
  2744. (ert-deftest test-org/open-at-point/inline-image ()
  2745. "Test `org-open-at-point' on nested links."
  2746. (should
  2747. (org-test-with-temp-text "<<top>>\n[[top][file:<point>unicorn.jpg]]"
  2748. (org-open-at-point)
  2749. (bobp))))
  2750. (ert-deftest test-org/open-at-point/radio-target ()
  2751. "Test `org-open-at-point' on radio targets."
  2752. (should
  2753. (org-test-with-temp-text "<<<target>>> <point>target"
  2754. (org-update-radio-target-regexp)
  2755. (org-open-at-point)
  2756. (eq (org-element-type (org-element-context)) 'radio-target))))
  2757. (ert-deftest test-org/open-at-point/tag ()
  2758. "Test `org-open-at-point' on tags."
  2759. (should
  2760. (org-test-with-temp-text "* H :<point>tag:"
  2761. (catch :result
  2762. (cl-letf (((symbol-function 'org-tags-view)
  2763. (lambda (&rest args) (throw :result t))))
  2764. (org-open-at-point)
  2765. nil))))
  2766. (should-not
  2767. (org-test-with-temp-text-in-file "* H<point> :tag:"
  2768. (catch :result
  2769. (cl-letf (((symbol-function 'org-tags-view)
  2770. (lambda (&rest args) (throw :result t))))
  2771. ;; When point isn't on a tag it's going to try other things,
  2772. ;; possibly trying to open attachments which will return an
  2773. ;; error if there isn't an attachment. Suppress that error.
  2774. (ignore-errors
  2775. (org-open-at-point))
  2776. nil)))))
  2777. ;;; Node Properties
  2778. (ert-deftest test-org/accumulated-properties-in-drawers ()
  2779. "Ensure properties accumulate in subtree drawers."
  2780. (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
  2781. (org-babel-next-src-block)
  2782. (should (equal '(2 1) (org-babel-execute-src-block)))))
  2783. (ert-deftest test-org/custom-properties ()
  2784. "Test custom properties specifications."
  2785. ;; Standard test.
  2786. (should
  2787. (let ((org-custom-properties '("FOO")))
  2788. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2789. (org-toggle-custom-properties-visibility)
  2790. (org-invisible-p2))))
  2791. ;; Properties are case-insensitive.
  2792. (should
  2793. (let ((org-custom-properties '("FOO")))
  2794. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:foo: val\n:END:\n"
  2795. (org-toggle-custom-properties-visibility)
  2796. (org-invisible-p2))))
  2797. (should
  2798. (let ((org-custom-properties '("foo")))
  2799. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO: val\n:END:\n"
  2800. (org-toggle-custom-properties-visibility)
  2801. (org-invisible-p2))))
  2802. ;; Multiple custom properties in the same drawer.
  2803. (should
  2804. (let ((org-custom-properties '("FOO" "BAR")))
  2805. (org-test-with-temp-text
  2806. "* H\n:PROPERTIES:\n<point>:FOO: val\n:P: 1\n:BAR: baz\n:END:\n"
  2807. (org-toggle-custom-properties-visibility)
  2808. (and (org-invisible-p2)
  2809. (not (progn (forward-line) (org-invisible-p2)))
  2810. (progn (forward-line) (org-invisible-p2))))))
  2811. ;; Hide custom properties with an empty value.
  2812. (should
  2813. (let ((org-custom-properties '("FOO")))
  2814. (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:FOO:\n:END:\n"
  2815. (org-toggle-custom-properties-visibility)
  2816. (org-invisible-p2))))
  2817. ;; Do not hide fake properties.
  2818. (should-not
  2819. (let ((org-custom-properties '("FOO")))
  2820. (org-test-with-temp-text ":FOO: val\n"
  2821. (org-toggle-custom-properties-visibility)
  2822. (org-invisible-p2))))
  2823. (should-not
  2824. (let ((org-custom-properties '("A")))
  2825. (org-test-with-temp-text
  2826. "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n:PROPERTIES:\n<point>:A: 2\n:END:"
  2827. (org-toggle-custom-properties-visibility)
  2828. (org-invisible-p2)))))
  2829. ;;; Mark Region
  2830. (ert-deftest test-org/mark-element ()
  2831. "Test `org-mark-element' specifications."
  2832. ;; Mark beginning and end of element.
  2833. (should
  2834. (equal '(t t)
  2835. (org-test-with-temp-text "Para<point>graph"
  2836. (org-mark-element)
  2837. (list (bobp) (= (mark) (point-max))))))
  2838. (should
  2839. (equal '(t t)
  2840. (org-test-with-temp-text "P1\n\nPara<point>graph\n\nP2"
  2841. (org-mark-element)
  2842. (list (looking-at "Paragraph")
  2843. (org-with-point-at (mark) (looking-at "P2"))))))
  2844. ;; Do not set mark past (point-max).
  2845. (should
  2846. (org-test-with-temp-text "Para<point>graph"
  2847. (narrow-to-region 2 6)
  2848. (org-mark-element)
  2849. (= 6 (mark)))))
  2850. (ert-deftest test-org/mark-subtree ()
  2851. "Test `org-mark-subtree' specifications."
  2852. ;; Error when point is before first headline.
  2853. (should-error
  2854. (org-test-with-temp-text "Paragraph\n* Headline\nBody"
  2855. (progn (transient-mark-mode 1)
  2856. (org-mark-subtree))))
  2857. ;; Without argument, mark current subtree.
  2858. (should
  2859. (equal
  2860. '(12 32)
  2861. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  2862. (progn (transient-mark-mode 1)
  2863. (forward-line 2)
  2864. (org-mark-subtree)
  2865. (list (region-beginning) (region-end))))))
  2866. ;; With an argument, move ARG up.
  2867. (should
  2868. (equal
  2869. '(1 32)
  2870. (org-test-with-temp-text "* Headline\n** Sub-headline\nBody"
  2871. (progn (transient-mark-mode 1)
  2872. (forward-line 2)
  2873. (org-mark-subtree 1)
  2874. (list (region-beginning) (region-end))))))
  2875. ;; Do not get fooled by inlinetasks.
  2876. (when (featurep 'org-inlinetask)
  2877. (should
  2878. (= 1
  2879. (org-test-with-temp-text "* Headline\n*************** Task\nContents"
  2880. (progn (transient-mark-mode 1)
  2881. (forward-line 1)
  2882. (let ((org-inlinetask-min-level 15)) (org-mark-subtree))
  2883. (region-beginning)))))))
  2884. ;;; Miscellaneous
  2885. (ert-deftest test-org/sort-entries ()
  2886. "Test `org-sort-entries'."
  2887. ;; Sort alphabetically.
  2888. (should
  2889. (equal "\n* abc\n* def\n* xyz\n"
  2890. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  2891. (org-sort-entries nil ?a)
  2892. (buffer-string))))
  2893. (should
  2894. (equal "\n* xyz\n* def\n* abc\n"
  2895. (org-test-with-temp-text "\n* def\n* xyz\n* abc\n"
  2896. (org-sort-entries nil ?A)
  2897. (buffer-string))))
  2898. (should
  2899. (equal "\n* \n* klm\n* xyz\n"
  2900. (org-test-with-temp-text "\n* xyz\n* \n* klm\n"
  2901. (org-sort-entries nil ?a)
  2902. (buffer-string))))
  2903. ;; Sort numerically.
  2904. (should
  2905. (equal "\n* 1\n* 2\n* 10\n"
  2906. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  2907. (org-sort-entries nil ?n)
  2908. (buffer-string))))
  2909. (should
  2910. (equal "\n* 10\n* 2\n* 1\n"
  2911. (org-test-with-temp-text "\n* 10\n* 1\n* 2\n"
  2912. (org-sort-entries nil ?N)
  2913. (buffer-string))))
  2914. (should
  2915. (equal "\n* \n* 1\n* 2\n"
  2916. (org-test-with-temp-text "\n* 1\n* \n* 2\n"
  2917. (org-sort-entries nil ?n)
  2918. (buffer-string))))
  2919. ;; Sort by custom function.
  2920. (should
  2921. (equal "\n* b\n* aa\n* ccc\n"
  2922. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  2923. (org-sort-entries nil ?f
  2924. (lambda ()
  2925. (length (buffer-substring (point-at-bol)
  2926. (point-at-eol))))
  2927. #'<)
  2928. (buffer-string))))
  2929. (should
  2930. (equal "\n* ccc\n* aa\n* b\n"
  2931. (org-test-with-temp-text "\n* ccc\n* b\n* aa\n"
  2932. (org-sort-entries nil ?F
  2933. (lambda ()
  2934. (length (buffer-substring (point-at-bol)
  2935. (point-at-eol))))
  2936. #'<)
  2937. (buffer-string))))
  2938. ;; Sort by TODO keyword.
  2939. (should
  2940. (equal "\n* TODO h1\n* TODO h3\n* DONE h2\n"
  2941. (org-test-with-temp-text
  2942. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  2943. (org-sort-entries nil ?o)
  2944. (buffer-string))))
  2945. (should
  2946. (equal "\n* DONE h2\n* TODO h1\n* TODO h3\n"
  2947. (org-test-with-temp-text
  2948. "\n* TODO h1\n* DONE h2\n* TODO h3\n"
  2949. (org-sort-entries nil ?O)
  2950. (buffer-string))))
  2951. ;; Sort by priority.
  2952. (should
  2953. (equal "\n* [#A] h2\n* [#B] h3\n* [#C] h1\n"
  2954. (org-test-with-temp-text
  2955. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  2956. (org-sort-entries nil ?p)
  2957. (buffer-string))))
  2958. (should
  2959. (equal "\n* [#C] h1\n* [#B] h3\n* [#A] h2\n"
  2960. (org-test-with-temp-text
  2961. "\n* [#C] h1\n* [#A] h2\n* [#B] h3\n"
  2962. (org-sort-entries nil ?P)
  2963. (buffer-string))))
  2964. ;; Sort by creation time.
  2965. (should
  2966. (equal "
  2967. * h3
  2968. [2017-05-08 Mon]
  2969. * h2
  2970. [2017-05-09 Tue]
  2971. * h1
  2972. [2018-05-09 Wed]
  2973. "
  2974. (org-test-with-temp-text
  2975. "
  2976. * h1
  2977. [2018-05-09 Wed]
  2978. * h2
  2979. [2017-05-09 Tue]
  2980. * h3
  2981. [2017-05-08 Mon]
  2982. "
  2983. (org-sort-entries nil ?c)
  2984. (buffer-string))))
  2985. ;; Sort by scheduled date.
  2986. (should
  2987. (equal "
  2988. * TODO h4
  2989. SCHEDULED: <2017-05-06 Sat>
  2990. * TODO h3
  2991. SCHEDULED: <2017-05-08 Mon>
  2992. * TODO h2
  2993. DEADLINE: <2017-05-09 Tue>
  2994. * TODO h1
  2995. DEADLINE: <2017-05-07 Sun>
  2996. "
  2997. (org-test-with-temp-text
  2998. "
  2999. * TODO h2
  3000. DEADLINE: <2017-05-09 Tue>
  3001. * TODO h1
  3002. DEADLINE: <2017-05-07 Sun>
  3003. * TODO h3
  3004. SCHEDULED: <2017-05-08 Mon>
  3005. * TODO h4
  3006. SCHEDULED: <2017-05-06 Sat>
  3007. "
  3008. (org-sort-entries nil ?s)
  3009. (buffer-string))))
  3010. ;; Sort by deadline date.
  3011. (should
  3012. (equal "
  3013. * TODO h1
  3014. DEADLINE: <2017-05-07 Sun>
  3015. * TODO h2
  3016. DEADLINE: <2017-05-09 Tue>
  3017. * TODO h3
  3018. SCHEDULED: <2017-05-08 Mon>
  3019. * TODO h4
  3020. SCHEDULED: <2017-05-06 Sat>
  3021. "
  3022. (org-test-with-temp-text
  3023. "
  3024. * TODO h2
  3025. DEADLINE: <2017-05-09 Tue>
  3026. * TODO h1
  3027. DEADLINE: <2017-05-07 Sun>
  3028. * TODO h3
  3029. SCHEDULED: <2017-05-08 Mon>
  3030. * TODO h4
  3031. SCHEDULED: <2017-05-06 Sat>
  3032. "
  3033. (org-sort-entries nil ?d)
  3034. (buffer-string))))
  3035. ;; Sort by any date/time
  3036. (should
  3037. (equal "
  3038. * TODO h4
  3039. SCHEDULED: <2017-05-06 Sat>
  3040. * TODO h1
  3041. DEADLINE: <2017-05-07 Sun>
  3042. * TODO h3
  3043. SCHEDULED: <2017-05-08 Mon>
  3044. * TODO h2
  3045. DEADLINE: <2017-05-09 Tue>
  3046. "
  3047. (org-test-with-temp-text
  3048. "
  3049. * TODO h2
  3050. DEADLINE: <2017-05-09 Tue>
  3051. * TODO h1
  3052. DEADLINE: <2017-05-07 Sun>
  3053. * TODO h3
  3054. SCHEDULED: <2017-05-08 Mon>
  3055. * TODO h4
  3056. SCHEDULED: <2017-05-06 Sat>
  3057. "
  3058. (org-sort-entries nil ?t)
  3059. (buffer-string))))
  3060. ;; Sort by clocking time.
  3061. (should
  3062. (equal "
  3063. * clocked h2
  3064. :LOGBOOK:
  3065. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3066. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  3067. :END:
  3068. * clocked h1
  3069. :LOGBOOK:
  3070. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3071. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  3072. :END:
  3073. "
  3074. (org-test-with-temp-text
  3075. "
  3076. * clocked h1
  3077. :LOGBOOK:
  3078. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3079. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:12] => 0:12
  3080. :END:
  3081. * clocked h2
  3082. :LOGBOOK:
  3083. CLOCK: [2017-05-09 Tue 00:15]--[2017-05-09 Tue 00:22] => 0:07
  3084. CLOCK: [2017-05-09 Tue 00:00]--[2017-05-09 Tue 00:10] => 0:10
  3085. :END:
  3086. "
  3087. (org-sort-entries nil ?k)
  3088. (buffer-string))))
  3089. ;; Preserve file local variables when sorting.
  3090. (should
  3091. (equal "\n* A\n* B\n# Local Variables:\n# foo: t\n# End:\n"
  3092. (org-test-with-temp-text
  3093. "\n* B\n* A\n# Local Variables:\n# foo: t\n# End:"
  3094. (org-sort-entries nil ?a)
  3095. (buffer-string)))))
  3096. (ert-deftest test-org/string-collate-greaterp ()
  3097. "Test `org-string-collate-greaterp' specifications."
  3098. (should (org-string-collate-greaterp "def" "abc"))
  3099. (should-not (org-string-collate-greaterp "abc" "def")))
  3100. (ert-deftest test-org/file-contents ()
  3101. "Test `org-file-contents' specifications."
  3102. ;; Open files.
  3103. (should
  3104. (string= "#+BIND: variable value
  3105. #+DESCRIPTION: l2
  3106. #+LANGUAGE: en
  3107. #+SELECT_TAGS: b
  3108. #+TITLE: b
  3109. #+PROPERTY: a 1
  3110. " (org-file-contents (expand-file-name "setupfile3.org"
  3111. (concat org-test-dir "examples/")))))
  3112. ;; Throw error when trying to access an invalid file.
  3113. (should-error (org-file-contents "this-file-must-not-exist"))
  3114. ;; Try to access an invalid file, but do not throw an error.
  3115. (should
  3116. (progn (org-file-contents "this-file-must-not-exist" :noerror) t))
  3117. ;; Open URL.
  3118. (should
  3119. (string= "foo"
  3120. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3121. (unwind-protect
  3122. ;; Simulate successful retrieval of a URL.
  3123. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3124. (lambda (&rest_)
  3125. (with-current-buffer buffer
  3126. (insert "HTTP/1.1 200 OK\n\nfoo"))
  3127. buffer)))
  3128. (org-file-contents "http://some-valid-url"))
  3129. (kill-buffer buffer)))))
  3130. ;; Throw error when trying to access an invalid URL.
  3131. (should-error
  3132. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3133. (unwind-protect
  3134. ;; Simulate unsuccessful retrieval of a URL.
  3135. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3136. (lambda (&rest_)
  3137. (with-current-buffer buffer
  3138. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3139. buffer)))
  3140. (org-file-contents "http://this-url-must-not-exist"))
  3141. (kill-buffer buffer))))
  3142. ;; Try to access an invalid URL, but do not throw an error.
  3143. (should-error
  3144. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3145. (unwind-protect
  3146. ;; Simulate unsuccessful retrieval of a URL.
  3147. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3148. (lambda (&rest_)
  3149. (with-current-buffer buffer
  3150. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3151. buffer)))
  3152. (org-file-contents "http://this-url-must-not-exist"))
  3153. (kill-buffer buffer))))
  3154. (should
  3155. (let ((buffer (generate-new-buffer "url-retrieve-output")))
  3156. (unwind-protect
  3157. ;; Simulate unsuccessful retrieval of a URL.
  3158. (cl-letf (((symbol-function 'url-retrieve-synchronously)
  3159. (lambda (&rest_)
  3160. (with-current-buffer buffer
  3161. (insert "HTTP/1.1 404 Not found\n\ndoes not matter"))
  3162. buffer)))
  3163. (org-file-contents "http://this-url-must-not-exist" :noerror))
  3164. (kill-buffer buffer))
  3165. t)))
  3166. ;;; Navigation
  3167. (ert-deftest test-org/next-visible-heading ()
  3168. "Test `org-next-visible-heading' specifications."
  3169. ;; Move to the beginning of the next headline, taking into
  3170. ;; consideration ARG.
  3171. (should
  3172. (org-test-with-temp-text "* H1\n* H2"
  3173. (org-next-visible-heading 1)
  3174. (looking-at "\\* H2")))
  3175. (should
  3176. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3177. (org-next-visible-heading 2)
  3178. (looking-at "\\* H3")))
  3179. ;; Ignore invisible headlines.
  3180. (should
  3181. (org-test-with-temp-text "* H1\n** H2\n* H3"
  3182. (org-cycle)
  3183. (org-next-visible-heading 1)
  3184. (looking-at "\\* H3")))
  3185. ;; Move point between headlines, not on blank lines between.
  3186. (should
  3187. (org-test-with-temp-text "* H1\n** H2\n\n\n\n* H3"
  3188. (let ((org-cycle-separator-lines 1))
  3189. (org-cycle)
  3190. (org-next-visible-heading 1))
  3191. (looking-at "\\* H3")))
  3192. ;; Move at end of buffer when there is no more headline.
  3193. (should
  3194. (org-test-with-temp-text "* H1"
  3195. (org-next-visible-heading 1)
  3196. (eobp)))
  3197. (should
  3198. (org-test-with-temp-text "* H1\n* H2"
  3199. (org-next-visible-heading 2)
  3200. (eobp)))
  3201. ;; With a negative argument, move backwards.
  3202. (should
  3203. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3204. (org-next-visible-heading -1)
  3205. (looking-at "\\* H2")))
  3206. (should
  3207. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3208. (org-next-visible-heading -2)
  3209. (looking-at "\\* H1"))))
  3210. (ert-deftest test-org/previous-visible-heading ()
  3211. "Test `org-previous-visible-heading' specifications."
  3212. ;; Move to the beginning of the next headline, taking into
  3213. ;; consideration ARG.
  3214. (should
  3215. (org-test-with-temp-text "* H1\n<point>* H2"
  3216. (org-previous-visible-heading 1)
  3217. (looking-at "\\* H1")))
  3218. (should
  3219. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3220. (org-previous-visible-heading 2)
  3221. (looking-at "\\* H1")))
  3222. ;; Ignore invisible headlines.
  3223. (should
  3224. (org-test-with-temp-text "* H1\n** H2\n<point>* H3"
  3225. (org-overview)
  3226. (org-previous-visible-heading 1)
  3227. (looking-at "\\* H1")))
  3228. ;; Move point between headlines, not on blank lines between.
  3229. (should
  3230. (org-test-with-temp-text "* H1\n\n\n\n** H2\n<point>* H3"
  3231. (let ((org-cycle-separator-lines 1))
  3232. (org-overview)
  3233. (org-previous-visible-heading 1))
  3234. (looking-at "\\* H1")))
  3235. ;; Move at end of buffer when there is no more headline.
  3236. (should
  3237. (org-test-with-temp-text "* H1"
  3238. (org-previous-visible-heading 1)
  3239. (bobp)))
  3240. (should
  3241. (org-test-with-temp-text "* H1\n* <point>H2"
  3242. (org-previous-visible-heading 2)
  3243. (bobp)))
  3244. ;; Invisible parts may not start at a headline, i.e., when revealing
  3245. ;; parts of the buffer. Handle this.
  3246. (should
  3247. (org-test-with-temp-text "* Main\n** H1\nFoo\n** H2\nBar\n** H3\nBaz"
  3248. (org-overview)
  3249. (search-forward "H1")
  3250. (org-show-context 'minimal)
  3251. (org-cycle)
  3252. (search-forward "H3")
  3253. (org-show-context 'minimal)
  3254. ;; At this point, buffer displays, with point at "|",
  3255. ;;
  3256. ;; * Main
  3257. ;; ** H1
  3258. ;; Foo
  3259. ;; ** H3|
  3260. (org-previous-visible-heading 1)
  3261. (looking-at "\\*+ H1"))))
  3262. (ert-deftest test-org/forward-heading-same-level ()
  3263. "Test `org-forward-heading-same-level' specifications."
  3264. ;; Test navigation at top level, forward and backward.
  3265. (should
  3266. (equal "* H2"
  3267. (org-test-with-temp-text "* H1\n* H2"
  3268. (org-forward-heading-same-level 1)
  3269. (buffer-substring-no-properties (point) (line-end-position)))))
  3270. (should
  3271. (equal "* H1"
  3272. (org-test-with-temp-text "* H1\n<point>* H2"
  3273. (org-forward-heading-same-level -1)
  3274. (buffer-substring-no-properties (point) (line-end-position)))))
  3275. ;; Test navigation in a sub-tree, forward and backward.
  3276. (should
  3277. (equal "* H2"
  3278. (org-test-with-temp-text "* H1\n** H11\n** H12\n* H2"
  3279. (org-forward-heading-same-level 1)
  3280. (buffer-substring-no-properties (point) (line-end-position)))))
  3281. (should
  3282. (equal "* H1"
  3283. (org-test-with-temp-text "* H1\n** H11\n** H12\n<point>* H2"
  3284. (org-forward-heading-same-level -1)
  3285. (buffer-substring-no-properties (point) (line-end-position)))))
  3286. ;; Stop at first or last sub-heading.
  3287. (should-not
  3288. (equal "* H2"
  3289. (org-test-with-temp-text "* H1\n** H11\n<point>** H12\n* H2"
  3290. (org-forward-heading-same-level 1)
  3291. (buffer-substring-no-properties (point) (line-end-position)))))
  3292. (should-not
  3293. (equal "* H2"
  3294. (org-test-with-temp-text "* H1\n<point>** H11\n** H12\n* H2"
  3295. (org-forward-heading-same-level -1)
  3296. (buffer-substring-no-properties (point) (line-end-position)))))
  3297. ;; Allow multiple moves.
  3298. (should
  3299. (equal "* H3"
  3300. (org-test-with-temp-text "* H1\n* H2\n* H3"
  3301. (org-forward-heading-same-level 2)
  3302. (buffer-substring-no-properties (point) (line-end-position)))))
  3303. (should
  3304. (equal "* H1"
  3305. (org-test-with-temp-text "* H1\n* H2\n<point>* H3"
  3306. (org-forward-heading-same-level -2)
  3307. (buffer-substring-no-properties (point) (line-end-position)))))
  3308. ;; Ignore spurious moves when first (or last) sibling is reached.
  3309. (should
  3310. (equal "** H3"
  3311. (org-test-with-temp-text "* First\n<point>** H1\n** H2\n** H3\n* Last"
  3312. (org-forward-heading-same-level 100)
  3313. (buffer-substring-no-properties (point) (line-end-position)))))
  3314. (should
  3315. (equal "** H1"
  3316. (org-test-with-temp-text "* First\n** H1\n** H2\n<point>** H3\n* Last"
  3317. (org-forward-heading-same-level -100)
  3318. (buffer-substring-no-properties (point) (line-end-position))))))
  3319. (ert-deftest test-org/end-of-meta-data ()
  3320. "Test `org-end-of-meta-data' specifications."
  3321. ;; Skip planning line.
  3322. (should
  3323. (org-test-with-temp-text "* Headline\nSCHEDULED: <2014-03-04 tue.>"
  3324. (org-end-of-meta-data)
  3325. (eobp)))
  3326. ;; Skip properties drawer.
  3327. (should
  3328. (org-test-with-temp-text
  3329. "* Headline\nSCHEDULED: <2014-03-04 tue.>\n:PROPERTIES:\n:A: 1\n:END:"
  3330. (org-end-of-meta-data)
  3331. (eobp)))
  3332. ;; Skip both.
  3333. (should
  3334. (org-test-with-temp-text "* Headline\n:PROPERTIES:\n:A: 1\n:END:"
  3335. (org-end-of-meta-data)
  3336. (eobp)))
  3337. ;; Nothing to skip, go to first line.
  3338. (should
  3339. (org-test-with-temp-text "* Headline\nContents"
  3340. (org-end-of-meta-data)
  3341. (looking-at "Contents")))
  3342. ;; With option argument, skip empty lines, regular drawers and
  3343. ;; clocking lines.
  3344. (should
  3345. (org-test-with-temp-text "* Headline\n\nContents"
  3346. (org-end-of-meta-data t)
  3347. (looking-at "Contents")))
  3348. (should
  3349. (org-test-with-temp-text "* Headline\nCLOCK:\nContents"
  3350. (org-end-of-meta-data t)
  3351. (looking-at "Contents")))
  3352. (should
  3353. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\n:END:\nContents"
  3354. (org-end-of-meta-data t)
  3355. (looking-at "Contents")))
  3356. ;; Special case: do not skip incomplete drawers.
  3357. (should
  3358. (org-test-with-temp-text "* Headline\n:LOGBOOK:\nlogging\nContents"
  3359. (org-end-of-meta-data t)
  3360. (looking-at ":LOGBOOK:")))
  3361. ;; Special case: Be careful about consecutive headlines.
  3362. (should-not
  3363. (org-test-with-temp-text "* H1\n*H2\nContents"
  3364. (org-end-of-meta-data t)
  3365. (looking-at "Contents"))))
  3366. (ert-deftest test-org/shiftright-heading ()
  3367. "Test `org-shiftright' on headings."
  3368. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  3369. (should
  3370. (equal "* TODO a1\n** a2\n* DONE b1\n"
  3371. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3372. (org-shiftright)
  3373. (buffer-string))))
  3374. (should
  3375. (equal "* TODO a1\n** TODO a2\n* b1\n"
  3376. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3377. (let ((org-loop-over-headlines-in-active-region t))
  3378. (transient-mark-mode 1)
  3379. (push-mark (point) t t)
  3380. (search-forward "* DONE b1")
  3381. (org-shiftright))
  3382. (buffer-string))))
  3383. (should
  3384. (equal "* TODO a1\n** a2\n* b1\n"
  3385. (org-test-with-temp-text "* a1\n** a2\n* DONE b1\n"
  3386. (let ((org-loop-over-headlines-in-active-region 'start-level))
  3387. (transient-mark-mode 1)
  3388. (push-mark (point) t t)
  3389. (search-forward "* DONE b1")
  3390. (org-shiftright))
  3391. (buffer-string))))))
  3392. (ert-deftest test-org/beginning-of-line ()
  3393. "Test `org-beginning-of-line' specifications."
  3394. ;; Move to beginning of line. If current line in invisible, move to
  3395. ;; beginning of visible line instead.
  3396. (should
  3397. (org-test-with-temp-text "Some text\nSome other text<point>"
  3398. (org-beginning-of-line)
  3399. (bolp)))
  3400. (should
  3401. (org-test-with-temp-text "* H1\n** H2<point>"
  3402. (org-overview)
  3403. (org-beginning-of-line)
  3404. (= (line-beginning-position) 1)))
  3405. ;; With `visual-line-mode' active, move to beginning of visual line.
  3406. (should-not
  3407. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3408. (visual-line-mode)
  3409. (dotimes (i 1000) (insert "very "))
  3410. (org-beginning-of-line)
  3411. (bolp)))
  3412. ;; In a wide headline, with `visual-line-mode', prefer going to the
  3413. ;; beginning of a visual line than to the logical beginning of line,
  3414. ;; even if special movement is active.
  3415. (should-not
  3416. (org-test-with-temp-text "* A <point>long headline"
  3417. (visual-line-mode)
  3418. (dotimes (i 1000) (insert "very "))
  3419. (goto-char (point-max))
  3420. (org-beginning-of-line)
  3421. (bobp)))
  3422. (should-not
  3423. (org-test-with-temp-text "* A <point>long headline"
  3424. (visual-line-mode)
  3425. (dotimes (i 1000) (insert "very "))
  3426. (goto-char (point-max))
  3427. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line))
  3428. (bobp)))
  3429. ;; At an headline with special movement, first move at beginning of
  3430. ;; title, then at the beginning of line, rinse, repeat.
  3431. (should
  3432. (org-test-with-temp-text "* TODO Headline<point>"
  3433. (let ((org-special-ctrl-a/e t))
  3434. (and (progn (org-beginning-of-line) (looking-at-p "Headline"))
  3435. (progn (org-beginning-of-line) (bolp))
  3436. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3437. (should
  3438. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3439. (let ((org-special-ctrl-a/e t))
  3440. (org-beginning-of-line)
  3441. (looking-at "Headline"))))
  3442. (should
  3443. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3444. (let ((org-special-ctrl-a/e '(t . nil)))
  3445. (org-beginning-of-line)
  3446. (looking-at "Headline"))))
  3447. (should-not
  3448. (org-test-with-temp-text "* TODO [#A] Headline<point>"
  3449. (let ((org-special-ctrl-a/e '(nil . nil)))
  3450. (org-beginning-of-line)
  3451. (looking-at "Headline"))))
  3452. ;; At an headline with reversed movement, first move to beginning of
  3453. ;; line, then to the beginning of title.
  3454. (should
  3455. (org-test-with-temp-text "* TODO Headline<point>"
  3456. (let ((org-special-ctrl-a/e 'reversed)
  3457. (this-command last-command))
  3458. (and (progn (org-beginning-of-line) (bolp))
  3459. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3460. (should
  3461. (org-test-with-temp-text "* TODO Headline<point>"
  3462. (let ((org-special-ctrl-a/e '(reversed . nil))
  3463. (this-command last-command))
  3464. (and (progn (org-beginning-of-line) (bolp))
  3465. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3466. (should-not
  3467. (org-test-with-temp-text "* TODO Headline<point>"
  3468. (let ((org-special-ctrl-a/e '(t . nil))
  3469. (this-command last-command))
  3470. (and (progn (org-beginning-of-line) (bolp))
  3471. (progn (org-beginning-of-line) (looking-at-p "Headline"))))))
  3472. ;; At an item with special movement, first move after to beginning
  3473. ;; of title, then to the beginning of line, rinse, repeat.
  3474. (should
  3475. (org-test-with-temp-text "- [ ] Item<point>"
  3476. (let ((org-special-ctrl-a/e t))
  3477. (and (progn (org-beginning-of-line) (looking-at-p "Item"))
  3478. (progn (org-beginning-of-line) (bolp))
  3479. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3480. ;; At an item with reversed movement, first move to beginning of
  3481. ;; line, then to the beginning of title.
  3482. (should
  3483. (org-test-with-temp-text "- [X] Item<point>"
  3484. (let ((org-special-ctrl-a/e 'reversed)
  3485. (this-command last-command))
  3486. (and (progn (org-beginning-of-line) (bolp))
  3487. (progn (org-beginning-of-line) (looking-at-p "Item"))))))
  3488. ;; Leave point before invisible characters at column 0.
  3489. (should
  3490. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3491. (let ((org-special-ctrl-a/e nil))
  3492. (org-beginning-of-line)
  3493. (bolp))))
  3494. (should
  3495. (org-test-with-temp-text "[[https://orgmode.org]]<point>"
  3496. (let ((org-special-ctrl-a/e t))
  3497. (org-beginning-of-line)
  3498. (bolp))))
  3499. (should
  3500. (org-test-with-temp-text "[[http<point>://orgmode.org]]"
  3501. (visual-line-mode)
  3502. (org-beginning-of-line)
  3503. (bolp)))
  3504. ;; Special case: Do not error when the buffer contains only a single
  3505. ;; asterisk.
  3506. (should
  3507. (org-test-with-temp-text "*<point>"
  3508. (let ((org-special-ctrl-a/e t)) (org-beginning-of-line) t)))
  3509. (should
  3510. (org-test-with-temp-text "*<point>"
  3511. (let ((org-special-ctrl-a/e nil)) (org-beginning-of-line) t))))
  3512. (ert-deftest test-org/end-of-line ()
  3513. "Test `org-end-of-line' specifications."
  3514. ;; Standard test.
  3515. (should
  3516. (org-test-with-temp-text "Some text\nSome other text"
  3517. (org-end-of-line)
  3518. (eolp)))
  3519. ;; With `visual-line-mode' active, move to end of visible line.
  3520. ;; However, never go past ellipsis.
  3521. (should-not
  3522. (org-test-with-temp-text "A <point>long line of text\nSome other text"
  3523. (visual-line-mode)
  3524. (dotimes (i 1000) (insert "very "))
  3525. (goto-char (point-min))
  3526. (org-end-of-line)
  3527. (eolp)))
  3528. (should-not
  3529. (org-test-with-temp-text "* A short headline\nSome contents"
  3530. (visual-line-mode)
  3531. (org-overview)
  3532. (org-end-of-line)
  3533. (eobp)))
  3534. ;; In a wide headline, with `visual-line-mode', prefer going to end
  3535. ;; of visible line if tags, or end of line, are farther.
  3536. (should-not
  3537. (org-test-with-temp-text "* A <point>long headline"
  3538. (visual-line-mode)
  3539. (dotimes (i 1000) (insert "very "))
  3540. (goto-char (point-min))
  3541. (org-end-of-line)
  3542. (eolp)))
  3543. (should-not
  3544. (org-test-with-temp-text "* A <point>long headline :tag:"
  3545. (visual-line-mode)
  3546. (dotimes (i 1000) (insert "very "))
  3547. (goto-char (point-min))
  3548. (org-end-of-line)
  3549. (eolp)))
  3550. ;; At an headline without special movement, go to end of line.
  3551. ;; However, never go past ellipsis.
  3552. (should
  3553. (org-test-with-temp-text "* Headline2b :tag:\n"
  3554. (let ((org-special-ctrl-a/e nil))
  3555. (and (progn (org-end-of-line) (eolp))
  3556. (progn (org-end-of-line) (eolp))))))
  3557. (should
  3558. (org-test-with-temp-text "* Headline2b :tag:\n"
  3559. (let ((org-special-ctrl-a/e '(t . nil)))
  3560. (and (progn (org-end-of-line) (eolp))
  3561. (progn (org-end-of-line) (eolp))))))
  3562. (should
  3563. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3564. (org-overview)
  3565. (let ((org-special-ctrl-a/e nil))
  3566. (org-end-of-line)
  3567. (= 1 (line-beginning-position)))))
  3568. ;; At an headline with special movement, first move before tags,
  3569. ;; then at the end of line, rinse, repeat. However, never go past
  3570. ;; ellipsis.
  3571. (should
  3572. (org-test-with-temp-text "* Headline1 :tag:\n"
  3573. (let ((org-special-ctrl-a/e t))
  3574. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3575. (progn (org-end-of-line) (eolp))
  3576. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3577. (should
  3578. (org-test-with-temp-text "* Headline1 :tag:\n"
  3579. (let ((org-special-ctrl-a/e '(nil . t)))
  3580. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3581. (progn (org-end-of-line) (eolp))
  3582. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3583. (should-not
  3584. (org-test-with-temp-text "* Headline1 :tag:\n"
  3585. (let ((org-special-ctrl-a/e '(nil . nil)))
  3586. (and (progn (org-end-of-line) (looking-at-p " :tag:"))
  3587. (progn (org-end-of-line) (eolp))
  3588. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3589. (should
  3590. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3591. (org-overview)
  3592. (let ((org-special-ctrl-a/e t))
  3593. (org-end-of-line)
  3594. (org-end-of-line)
  3595. (= 1 (line-beginning-position)))))
  3596. ;; At an headline, with reversed movement, first go to end of line,
  3597. ;; then before tags. However, never go past ellipsis.
  3598. (should
  3599. (org-test-with-temp-text "* Headline3 :tag:\n"
  3600. (let ((org-special-ctrl-a/e 'reversed)
  3601. (this-command last-command))
  3602. (and (progn (org-end-of-line) (eolp))
  3603. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3604. (should
  3605. (org-test-with-temp-text "* Headline3 :tag:\n"
  3606. (let ((org-special-ctrl-a/e '(nil . reversed))
  3607. (this-command last-command))
  3608. (and (progn (org-end-of-line) (eolp))
  3609. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3610. (should-not
  3611. (org-test-with-temp-text "* Headline3 :tag:\n"
  3612. (let ((org-special-ctrl-a/e '(nil . t))
  3613. (this-command last-command))
  3614. (and (progn (org-end-of-line) (eolp))
  3615. (progn (org-end-of-line) (looking-at-p " :tag:"))))))
  3616. (should
  3617. (org-test-with-temp-text "* Headline2a :tag:\n** Sub"
  3618. (org-overview)
  3619. (let ((org-special-ctrl-a/e 'reversed))
  3620. (org-end-of-line)
  3621. (= 1 (line-beginning-position)))))
  3622. ;; At a block without hidden contents.
  3623. (should
  3624. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3625. (progn (org-end-of-line) (eolp))))
  3626. ;; At a block with hidden contents.
  3627. (should-not
  3628. (org-test-with-temp-text "#+BEGIN_CENTER\nContents\n#+END_CENTER"
  3629. (let ((org-special-ctrl-a/e t))
  3630. (org-hide-block-toggle)
  3631. (org-end-of-line)
  3632. (eobp))))
  3633. ;; Get past invisible characters at the end of line.
  3634. (should
  3635. (org-test-with-temp-text "[[https://orgmode.org]]"
  3636. (org-end-of-line)
  3637. (eolp))))
  3638. (ert-deftest test-org/open-line ()
  3639. "Test `org-open-line' specifications."
  3640. ;; Call `open-line' outside of tables.
  3641. (should
  3642. (equal "\nText"
  3643. (org-test-with-temp-text "Text"
  3644. (org-open-line 1)
  3645. (buffer-string))))
  3646. ;; At a table, create a row above.
  3647. (should
  3648. (equal "\n| |\n| a |"
  3649. (org-test-with-temp-text "\n<point>| a |"
  3650. (org-open-line 1)
  3651. (buffer-string))))
  3652. ;; At the very first character of the buffer, also call `open-line'.
  3653. (should
  3654. (equal "\n| a |"
  3655. (org-test-with-temp-text "| a |"
  3656. (org-open-line 1)
  3657. (buffer-string))))
  3658. ;; Narrowing does not count.
  3659. (should
  3660. (equal "Text\n| |\n| a |"
  3661. (org-test-with-temp-text "Text\n<point>| a |"
  3662. (narrow-to-region (point) (point-max))
  3663. (org-open-line 1)
  3664. (widen)
  3665. (buffer-string)))))
  3666. (ert-deftest test-org/forward-sentence ()
  3667. "Test `org-forward-sentence' specifications."
  3668. ;; At the end of a table cell, move to the end of the next one.
  3669. (should
  3670. (org-test-with-temp-text "| a<point> | b |"
  3671. (org-forward-sentence)
  3672. (looking-at " |$")))
  3673. ;; Elsewhere in a cell, move to its end.
  3674. (should
  3675. (org-test-with-temp-text "| a<point>c | b |"
  3676. (org-forward-sentence)
  3677. (looking-at " | b |$")))
  3678. ;; Otherwise, simply call `forward-sentence'.
  3679. (should
  3680. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3681. (org-forward-sentence)
  3682. (looking-at " Sentence 2.")))
  3683. (should
  3684. (org-test-with-temp-text "Sentence<point> 1. Sentence 2."
  3685. (org-forward-sentence)
  3686. (org-forward-sentence)
  3687. (eobp)))
  3688. ;; At the end of an element, jump to the next one, without stopping
  3689. ;; on blank lines in-between.
  3690. (should
  3691. (org-test-with-temp-text "Paragraph 1.<point>\n\nParagraph 2."
  3692. (org-forward-sentence)
  3693. (eobp)))
  3694. ;; Headlines are considered to be sentences by themselves, even if
  3695. ;; they do not end with a full stop.
  3696. (should
  3697. (equal
  3698. "* Headline"
  3699. (org-test-with-temp-text "* <point>Headline\nSentence."
  3700. (org-forward-sentence)
  3701. (buffer-substring-no-properties (line-beginning-position) (point)))))
  3702. (should
  3703. (org-test-with-temp-text "* Headline<point>\nSentence."
  3704. (org-forward-sentence)
  3705. (eobp)))
  3706. (should
  3707. (org-test-with-temp-text "Sentence.<point>\n\n* Headline\n\nSentence 2."
  3708. (org-forward-sentence)
  3709. (and (org-at-heading-p) (eolp)))))
  3710. (ert-deftest test-org/backward-sentence ()
  3711. "Test `org-backward-sentence' specifications."
  3712. ;; At the beginning of a table cell, move to the beginning of the
  3713. ;; previous one.
  3714. (should
  3715. (org-test-with-temp-text "| a | <point>b |"
  3716. (org-backward-sentence)
  3717. (looking-at "a | b |$")))
  3718. ;; Elsewhere in a cell, move to its beginning.
  3719. (should
  3720. (org-test-with-temp-text "| a | b<point>c |"
  3721. (org-backward-sentence)
  3722. (looking-at "bc |$")))
  3723. ;; Otherwise, simply call `backward-sentence'.
  3724. (should
  3725. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3726. (org-backward-sentence)
  3727. (looking-at "Sentence 2.")))
  3728. (should
  3729. (org-test-with-temp-text "Sentence 1. Sentence<point> 2."
  3730. (org-backward-sentence)
  3731. (org-backward-sentence)
  3732. (bobp)))
  3733. ;; Make sure to hit the beginning of a sentence on the same line as
  3734. ;; an item.
  3735. (should
  3736. (org-test-with-temp-text "- Line 1\n line <point>2."
  3737. (org-backward-sentence)
  3738. (looking-at "Line 1"))))
  3739. (ert-deftest test-org/forward-paragraph ()
  3740. "Test `org-forward-paragraph' specifications."
  3741. ;; At end of buffer, do not return an error.
  3742. (should
  3743. (org-test-with-temp-text "Paragraph"
  3744. (goto-char (point-max))
  3745. (org-forward-paragraph)
  3746. t))
  3747. ;; Standard test.
  3748. (should
  3749. (= 2
  3750. (org-test-with-temp-text "P1\n\nP2"
  3751. (org-forward-paragraph)
  3752. (org-current-line))))
  3753. (should
  3754. (= 2
  3755. (org-test-with-temp-text "P1\n\nP2\n\nP3"
  3756. (org-forward-paragraph)
  3757. (org-current-line))))
  3758. ;; Enter greater elements.
  3759. (should
  3760. (= 2
  3761. (org-test-with-temp-text "#+begin_center\nP1\n#+end_center\nP2"
  3762. (org-forward-paragraph)
  3763. (org-current-line))))
  3764. ;; Do not enter elements with invisible contents.
  3765. (should
  3766. (= 4
  3767. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  3768. (org-cycle)
  3769. (org-forward-paragraph)
  3770. (org-current-line))))
  3771. (should
  3772. (= 6
  3773. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\nP3"
  3774. (org-hide-block-toggle)
  3775. (org-forward-paragraph)
  3776. (org-current-line))))
  3777. ;; On an item or a footnote definition, move past the first element
  3778. ;; inside, if any.
  3779. (should
  3780. (= 2
  3781. (org-test-with-temp-text "- Item1\n\n Paragraph\n- Item2"
  3782. (org-forward-paragraph)
  3783. (org-current-line))))
  3784. (should
  3785. (= 2
  3786. (org-test-with-temp-text "[fn:1] Def1\n\nParagraph\n\n[fn:2] Def2"
  3787. (org-forward-paragraph)
  3788. (org-current-line))))
  3789. ;; On a table (resp. a property drawer) do not move through table
  3790. ;; rows (resp. node properties).
  3791. (should
  3792. (org-test-with-temp-text "| a | b |\n| c | d |\nParagraph"
  3793. (org-forward-paragraph)
  3794. (looking-at "Paragraph")))
  3795. (should
  3796. (org-test-with-temp-text
  3797. "* H\n<point>:PROPERTIES:\n:prop: value\n:END:\nParagraph"
  3798. (org-forward-paragraph)
  3799. (looking-at "Paragraph")))
  3800. ;; Skip consecutive keywords, clocks and diary S-exps.
  3801. (should
  3802. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n"
  3803. (org-forward-paragraph)
  3804. (eobp)))
  3805. (should
  3806. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n"
  3807. (org-forward-paragraph)
  3808. (eobp)))
  3809. (should
  3810. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n"
  3811. (org-forward-paragraph)
  3812. (eobp)))
  3813. (should-not
  3814. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n"
  3815. (org-forward-paragraph)
  3816. (eobp)))
  3817. (should-not
  3818. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n"
  3819. (org-forward-paragraph)
  3820. (eobp)))
  3821. ;; In a plain list with one item every line, skip the whole list,
  3822. ;; even with point in the middle of the list.
  3823. (should
  3824. (org-test-with-temp-text "- A\n - B\n- C\n"
  3825. (org-forward-paragraph)
  3826. (eobp)))
  3827. (should
  3828. (org-test-with-temp-text "- A\n - <point>B\n- C\n"
  3829. (org-forward-paragraph)
  3830. (eobp)))
  3831. ;; On a comment, verse or source block, stop at "contents"
  3832. ;; boundaries and blank lines.
  3833. (should
  3834. (= 2
  3835. (org-test-with-temp-text "#+begin_src emacs-lisp\nL1\n\nL2\n#+end_src"
  3836. (org-forward-paragraph)
  3837. (org-current-line))))
  3838. (should
  3839. (= 3
  3840. (org-test-with-temp-text "#+begin_verse\n<point>L1\n\nL2\n#+end_verse"
  3841. (org-forward-paragraph)
  3842. (org-current-line))))
  3843. (should
  3844. (= 5
  3845. (org-test-with-temp-text "#+begin_comment\nL1\n\n<point>L2\n#+end_comment"
  3846. (org-forward-paragraph)
  3847. (org-current-line))))
  3848. ;; Being on an affiliated keyword shouldn't make any difference.
  3849. (should
  3850. (org-test-with-temp-text "#+name: para\n#+caption: caption\nPara"
  3851. (org-forward-paragraph)
  3852. (eobp))))
  3853. (ert-deftest test-org/backward-paragraph ()
  3854. "Test `org-backward-paragraph' specifications."
  3855. ;; Do not error at beginning of buffer.
  3856. (should
  3857. (org-test-with-temp-text "Paragraph"
  3858. (org-backward-paragraph)
  3859. t))
  3860. ;; At blank lines at the very beginning of a buffer, move to
  3861. ;; point-min.
  3862. (should
  3863. (org-test-with-temp-text "\n\n<point>\n\nParagraph"
  3864. (org-backward-paragraph)
  3865. (bobp)))
  3866. ;; Regular test.
  3867. (should
  3868. (= 2
  3869. (org-test-with-temp-text "P1\n\nP2<point>"
  3870. (org-backward-paragraph)
  3871. (org-current-line))))
  3872. (should
  3873. (= 4
  3874. (org-test-with-temp-text "P1\n\nP2\n\nP3<point>"
  3875. (org-backward-paragraph)
  3876. (org-current-line))))
  3877. ;; Try to move on the line above current element.
  3878. (should
  3879. (= 2
  3880. (org-test-with-temp-text "\n\n<point>Paragraph"
  3881. (org-backward-paragraph)
  3882. (org-current-line))))
  3883. ;; Do not leave point in an invisible area.
  3884. (should
  3885. (org-test-with-temp-text "* H1\n P1\n\n* H2"
  3886. (org-cycle)
  3887. (goto-char (point-max))
  3888. (beginning-of-line)
  3889. (org-backward-paragraph)
  3890. (bobp)))
  3891. (should
  3892. (org-test-with-temp-text "#+begin_center\nP1\n\nP2\n#+end_center\n"
  3893. (org-hide-block-toggle)
  3894. (goto-char (point-max))
  3895. (org-backward-paragraph)
  3896. (bobp)))
  3897. ;; On the first element in an item or a footnote definition, jump
  3898. ;; before the footnote or the item.
  3899. (should
  3900. (org-test-with-temp-text "- line1<point>"
  3901. (org-backward-paragraph)
  3902. (bobp)))
  3903. (should
  3904. (org-test-with-temp-text "[fn:1] line1n<point>"
  3905. (org-backward-paragraph)
  3906. (bobp)))
  3907. ;; On the second element in an item or a footnote definition, jump
  3908. ;; to item or the definition.
  3909. (should
  3910. (= 2
  3911. (org-test-with-temp-text "- line1\n\n<point> line2"
  3912. (org-backward-paragraph)
  3913. (org-current-line))))
  3914. (should
  3915. (= 2
  3916. (org-test-with-temp-text "[fn:1] line1\n\n<point> line2"
  3917. (org-backward-paragraph)
  3918. (org-current-line))))
  3919. ;; On a table (resp. a property drawer), ignore table rows
  3920. ;; (resp. node properties).
  3921. (should
  3922. (org-test-with-temp-text "| a | b |\n| c | d |\n<point>P1"
  3923. (org-backward-paragraph)
  3924. (bobp)))
  3925. (should
  3926. (= 2
  3927. (org-test-with-temp-text
  3928. "* H\n:PROPERTIES:\n:prop: value\n:END:\n<point>P1"
  3929. (org-backward-paragraph)
  3930. (org-current-line))))
  3931. ;; In a plain list with one item every line, skip the whole list,
  3932. ;; even with point in the middle of the list.
  3933. (should
  3934. (org-test-with-temp-text "- A\n - B\n- C\n<point>"
  3935. (org-backward-paragraph)
  3936. (bobp)))
  3937. (should
  3938. (org-test-with-temp-text "- A\n - B\n- <point>C\n"
  3939. (org-backward-paragraph)
  3940. (bobp)))
  3941. ;; Skip consecutive keywords, clocks and diary S-exps.
  3942. (should
  3943. (org-test-with-temp-text "#+key: val\n #+key2: val\n#+key3: val\n<point>"
  3944. (org-backward-paragraph)
  3945. (bobp)))
  3946. (should
  3947. (org-test-with-temp-text "CLOCK: val\n CLOCK: val\nCLOCK: val\n<point>"
  3948. (org-backward-paragraph)
  3949. (bobp)))
  3950. (should
  3951. (org-test-with-temp-text "%%(foo)\n%%(bar)\n%%(baz)\n<point>"
  3952. (org-backward-paragraph)
  3953. (bobp)))
  3954. (should-not
  3955. (org-test-with-temp-text "#+key: val\n #+key2: val\n\n#+key3: val\n<point>"
  3956. (org-backward-paragraph)
  3957. (bobp)))
  3958. (should-not
  3959. (org-test-with-temp-text "#+key: val\nCLOCK: ...\n<point>"
  3960. (org-backward-paragraph)
  3961. (bobp)))
  3962. ;; On a comment, example, source and verse blocks, stop at blank
  3963. ;; lines.
  3964. (should
  3965. (= 1
  3966. (org-test-with-temp-text
  3967. "#+begin_comment\n<point>L1\n\nL2\n\nL3\n#+end_comment"
  3968. (org-backward-paragraph)
  3969. (org-current-line))))
  3970. (should
  3971. (= 2
  3972. (org-test-with-temp-text
  3973. "#+begin_verse\nL1\n\n<point>L2\n\nL3\n#+end_verse"
  3974. (org-backward-paragraph)
  3975. (org-current-line))))
  3976. (should
  3977. (= 3
  3978. (org-test-with-temp-text
  3979. "#+begin_src emacs-lisp\nL1\n\nL2\n\n<point>L3\n#+end_src"
  3980. (org-backward-paragraph)
  3981. (org-current-line))))
  3982. ;; When called from the opening line itself, however, move to
  3983. ;; beginning of block.
  3984. (should
  3985. (org-test-with-temp-text "#+begin_<point>example\nL1\n#+end_example"
  3986. (org-backward-paragraph)
  3987. (bobp)))
  3988. ;; On an empty heading, move above it.
  3989. (should
  3990. (org-test-with-temp-text "\n* <point>"
  3991. (org-backward-paragraph)
  3992. (bobp)))
  3993. (should
  3994. (org-test-with-temp-text "\n* \n<point>"
  3995. (org-backward-paragraph)
  3996. (bobp))))
  3997. (ert-deftest test-org/forward-element ()
  3998. "Test `org-forward-element' specifications."
  3999. ;; 1. At EOB: should error.
  4000. (org-test-with-temp-text "Some text\n"
  4001. (goto-char (point-max))
  4002. (should-error (org-forward-element)))
  4003. ;; 2. Standard move: expected to ignore blank lines.
  4004. (org-test-with-temp-text "First paragraph.\n\n\nSecond paragraph."
  4005. (org-forward-element)
  4006. (should (looking-at (regexp-quote "Second paragraph."))))
  4007. ;; 3. Headline tests.
  4008. (org-test-with-temp-text "
  4009. * Head 1
  4010. ** Head 1.1
  4011. *** Head 1.1.1
  4012. ** Head 1.2"
  4013. ;; 3.1. At an headline beginning: move to next headline at the
  4014. ;; same level.
  4015. (goto-line 3)
  4016. (org-forward-element)
  4017. (should (looking-at (regexp-quote "** Head 1.2")))
  4018. ;; 3.2. At an headline beginning: move to parent headline if no
  4019. ;; headline at the same level.
  4020. (goto-line 3)
  4021. (org-forward-element)
  4022. (should (looking-at (regexp-quote "** Head 1.2"))))
  4023. ;; 4. Greater element tests.
  4024. (org-test-with-temp-text
  4025. "#+BEGIN_CENTER\nInside.\n#+END_CENTER\n\nOutside."
  4026. ;; 4.1. At a greater element: expected to skip contents.
  4027. (org-forward-element)
  4028. (should (looking-at (regexp-quote "Outside.")))
  4029. ;; 4.2. At the end of greater element contents: expected to skip
  4030. ;; to the end of the greater element.
  4031. (goto-line 2)
  4032. (org-forward-element)
  4033. (should (looking-at (regexp-quote "Outside."))))
  4034. ;; 5. List tests.
  4035. (org-test-with-temp-text "
  4036. - item1
  4037. - sub1
  4038. - sub2
  4039. - sub3
  4040. Inner paragraph.
  4041. - item2
  4042. Outside."
  4043. ;; 5.1. At list top point: expected to move to the element after
  4044. ;; the list.
  4045. (goto-line 2)
  4046. (org-forward-element)
  4047. (should (looking-at (regexp-quote "Outside.")))
  4048. ;; 5.2. Special case: at the first line of a sub-list, but not at
  4049. ;; beginning of line, move to next item.
  4050. (goto-line 2)
  4051. (forward-char)
  4052. (org-forward-element)
  4053. (should (looking-at "- item2"))
  4054. (goto-line 4)
  4055. (forward-char)
  4056. (org-forward-element)
  4057. (should (looking-at " - sub2"))
  4058. ;; 5.3 At sub-list beginning: expected to move after the sub-list.
  4059. (goto-line 4)
  4060. (org-forward-element)
  4061. (should (looking-at (regexp-quote " Inner paragraph.")))
  4062. ;; 5.4. At sub-list end: expected to move outside the sub-list.
  4063. (goto-line 8)
  4064. (org-forward-element)
  4065. (should (looking-at (regexp-quote " Inner paragraph.")))
  4066. ;; 5.5. At an item: expected to move to next item, if any.
  4067. (goto-line 6)
  4068. (org-forward-element)
  4069. (should (looking-at " - sub3"))))
  4070. (ert-deftest test-org/backward-element ()
  4071. "Test `org-backward-element' specifications."
  4072. ;; 1. Should error at BOB.
  4073. (org-test-with-temp-text " \nParagraph."
  4074. (should-error (org-backward-element)))
  4075. ;; 2. Should move at BOB when called on the first element in buffer.
  4076. (should
  4077. (org-test-with-temp-text "\n#+TITLE: test"
  4078. (progn (forward-line)
  4079. (org-backward-element)
  4080. (bobp))))
  4081. ;; 3. Not at the beginning of an element: move at its beginning.
  4082. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  4083. (goto-line 3)
  4084. (end-of-line)
  4085. (org-backward-element)
  4086. (should (looking-at (regexp-quote "Paragraph2."))))
  4087. ;; 4. Headline tests.
  4088. (org-test-with-temp-text "
  4089. * Head 1
  4090. ** Head 1.1
  4091. *** Head 1.1.1
  4092. ** Head 1.2"
  4093. ;; 4.1. At an headline beginning: move to previous headline at the
  4094. ;; same level.
  4095. (goto-line 5)
  4096. (org-backward-element)
  4097. (should (looking-at (regexp-quote "** Head 1.1")))
  4098. ;; 4.2. At an headline beginning: move to parent headline if no
  4099. ;; headline at the same level.
  4100. (goto-line 3)
  4101. (org-backward-element)
  4102. (should (looking-at (regexp-quote "* Head 1")))
  4103. ;; 4.3. At the first top-level headline: should error.
  4104. (goto-line 2)
  4105. (should-error (org-backward-element)))
  4106. ;; 5. At beginning of first element inside a greater element:
  4107. ;; expected to move to greater element's beginning.
  4108. (org-test-with-temp-text "Before.\n#+BEGIN_CENTER\nInside.\n#+END_CENTER"
  4109. (goto-line 3)
  4110. (org-backward-element)
  4111. (should (looking-at "#\\+BEGIN_CENTER")))
  4112. ;; 6. At the beginning of the first element in a section: should
  4113. ;; move back to headline, if any.
  4114. (should
  4115. (org-test-with-temp-text "#+TITLE: test\n* Headline\n\nParagraph"
  4116. (progn (goto-char (point-max))
  4117. (beginning-of-line)
  4118. (org-backward-element)
  4119. (org-at-heading-p))))
  4120. ;; 7. List tests.
  4121. (org-test-with-temp-text "
  4122. - item1
  4123. - sub1
  4124. - sub2
  4125. - sub3
  4126. Inner paragraph.
  4127. - item2
  4128. Outside."
  4129. ;; 7.1. At beginning of sub-list: expected to move to the
  4130. ;; paragraph before it.
  4131. (goto-line 4)
  4132. (org-backward-element)
  4133. (should (looking-at "item1"))
  4134. ;; 7.2. At an item in a list: expected to move at previous item.
  4135. (goto-line 8)
  4136. (org-backward-element)
  4137. (should (looking-at " - sub2"))
  4138. (goto-line 12)
  4139. (org-backward-element)
  4140. (should (looking-at "- item1"))
  4141. ;; 7.3. At end of list/sub-list: expected to move to list/sub-list
  4142. ;; beginning.
  4143. (goto-line 10)
  4144. (org-backward-element)
  4145. (should (looking-at " - sub1"))
  4146. (goto-line 15)
  4147. (org-backward-element)
  4148. (should (looking-at "- item1"))
  4149. ;; 7.4. At blank-lines before list end: expected to move to top
  4150. ;; item.
  4151. (goto-line 14)
  4152. (org-backward-element)
  4153. (should (looking-at "- item1"))))
  4154. (ert-deftest test-org/up-element ()
  4155. "Test `org-up-element' specifications."
  4156. ;; 1. At BOB or with no surrounding element: should error.
  4157. (org-test-with-temp-text "Paragraph."
  4158. (should-error (org-up-element)))
  4159. (org-test-with-temp-text "* Head1\n* Head2"
  4160. (goto-line 2)
  4161. (should-error (org-up-element)))
  4162. (org-test-with-temp-text "Paragraph1.\n\nParagraph2."
  4163. (goto-line 3)
  4164. (should-error (org-up-element)))
  4165. ;; 2. At an headline: move to parent headline.
  4166. (org-test-with-temp-text "* Head1\n** Sub-Head1\n** Sub-Head2"
  4167. (goto-line 3)
  4168. (org-up-element)
  4169. (should (looking-at "\\* Head1")))
  4170. ;; 3. Inside a greater element: move to greater element beginning.
  4171. (org-test-with-temp-text
  4172. "Before.\n#+BEGIN_CENTER\nParagraph1\nParagraph2\n#+END_CENTER\n"
  4173. (goto-line 3)
  4174. (org-up-element)
  4175. (should (looking-at "#\\+BEGIN_CENTER")))
  4176. ;; 4. List tests.
  4177. (org-test-with-temp-text "* Top
  4178. - item1
  4179. - sub1
  4180. - sub2
  4181. Paragraph within sub2.
  4182. - item2"
  4183. ;; 4.1. Within an item: move to the item beginning.
  4184. (goto-line 8)
  4185. (org-up-element)
  4186. (should (looking-at " - sub2"))
  4187. ;; 4.2. At an item in a sub-list: move to parent item.
  4188. (goto-line 4)
  4189. (org-up-element)
  4190. (should (looking-at "- item1"))
  4191. ;; 4.3. At an item in top list: move to beginning of whole list.
  4192. (goto-line 10)
  4193. (org-up-element)
  4194. (should (looking-at "- item1"))
  4195. ;; 4.4. Special case. At very top point: should move to parent of
  4196. ;; list.
  4197. (goto-line 2)
  4198. (org-up-element)
  4199. (should (looking-at "\\* Top"))))
  4200. (ert-deftest test-org/down-element ()
  4201. "Test `org-down-element' specifications."
  4202. ;; Error when the element hasn't got a recursive type.
  4203. (org-test-with-temp-text "Paragraph."
  4204. (should-error (org-down-element)))
  4205. ;; Error when the element has no contents
  4206. (org-test-with-temp-text "* Headline"
  4207. (should-error (org-down-element)))
  4208. ;; When at a plain-list, move to first item.
  4209. (org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
  4210. (goto-line 2)
  4211. (org-down-element)
  4212. (should (looking-at " - Item 1.1")))
  4213. (org-test-with-temp-text "#+NAME: list\n- Item 1"
  4214. (org-down-element)
  4215. (should (looking-at " Item 1")))
  4216. ;; When at a table, move to first row
  4217. (org-test-with-temp-text "#+NAME: table\n| a | b |"
  4218. (org-down-element)
  4219. (should (looking-at " a | b |")))
  4220. ;; Otherwise, move inside the greater element.
  4221. (org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
  4222. (org-down-element)
  4223. (should (looking-at "Paragraph"))))
  4224. (ert-deftest test-org/drag-element-backward ()
  4225. "Test `org-drag-element-backward' specifications."
  4226. ;; Standard test.
  4227. (should
  4228. (equal
  4229. "#+key2: val2\n#+key1: val1\n#+key3: val3"
  4230. (org-test-with-temp-text "#+key1: val1\n<point>#+key2: val2\n#+key3: val3"
  4231. (org-drag-element-backward)
  4232. (buffer-string))))
  4233. (should
  4234. (equal
  4235. "#+BEGIN_CENTER\n#+B: 2\n#+A: 1\n#+END_CENTER"
  4236. (org-test-with-temp-text
  4237. "#+BEGIN_CENTER\n#+A: 1\n<point>#+B: 2\n#+END_CENTER"
  4238. (org-drag-element-backward)
  4239. (buffer-string))))
  4240. ;; Preserve blank lines.
  4241. (should
  4242. (equal "Paragraph 2\n\n\nPara1\n\nPara3"
  4243. (org-test-with-temp-text "Para1\n\n\n<point>Paragraph 2\n\nPara3"
  4244. (org-drag-element-backward)
  4245. (buffer-string))))
  4246. ;; Preserve column.
  4247. (should
  4248. (org-test-with-temp-text "#+key1: v\n#+key<point>2: v\n#+key3: v"
  4249. (org-drag-element-backward)
  4250. (looking-at-p "2")))
  4251. ;; Error when trying to move first element of buffer.
  4252. (should-error
  4253. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4254. (org-drag-element-backward))
  4255. :type 'user-error)
  4256. ;; Error when trying to swap nested elements.
  4257. (should-error
  4258. (org-test-with-temp-text "#+BEGIN_CENTER\n<point>Test.\n#+END_CENTER"
  4259. (org-drag-element-backward))
  4260. :type 'user-error)
  4261. ;; Error when trying to swap an headline element and a non-headline
  4262. ;; element.
  4263. (should-error
  4264. (org-test-with-temp-text "Test.\n<point>* Head 1"
  4265. (org-drag-element-backward))
  4266. :type 'error)
  4267. ;; Error when called before first element.
  4268. (should-error
  4269. (org-test-with-temp-text "\n<point>"
  4270. (org-drag-element-backward))
  4271. :type 'user-error)
  4272. ;; Preserve visibility of elements and their contents.
  4273. (should
  4274. (equal '((63 . 82) (26 . 48))
  4275. (org-test-with-temp-text "
  4276. #+BEGIN_CENTER
  4277. Text.
  4278. #+END_CENTER
  4279. - item 1
  4280. #+BEGIN_QUOTE
  4281. Text.
  4282. #+END_QUOTE"
  4283. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4284. (search-backward "- item 1")
  4285. (org-drag-element-backward)
  4286. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4287. (overlays-in (point-min) (point-max))))))
  4288. ;; Pathological case: handle call with point in blank lines right
  4289. ;; after a headline.
  4290. (should
  4291. (equal "* H2\n\n* H1\nText\n"
  4292. (org-test-with-temp-text "* H1\nText\n* H2\n\n<point>"
  4293. (org-drag-element-backward)
  4294. (buffer-string)))))
  4295. (ert-deftest test-org/drag-element-forward ()
  4296. "Test `org-drag-element-forward' specifications."
  4297. ;; 1. Error when trying to move first element of buffer.
  4298. (org-test-with-temp-text "Paragraph 1.\n\nParagraph 2."
  4299. (goto-line 3)
  4300. (should-error (org-drag-element-forward)))
  4301. ;; 2. Error when trying to swap nested elements.
  4302. (org-test-with-temp-text "#+BEGIN_CENTER\nTest.\n#+END_CENTER"
  4303. (forward-line)
  4304. (should-error (org-drag-element-forward)))
  4305. ;; 3. Error when trying to swap a non-headline element and an
  4306. ;; headline.
  4307. (org-test-with-temp-text "Test.\n* Head 1"
  4308. (should-error (org-drag-element-forward)))
  4309. ;; 4. Error when called before first element.
  4310. (should-error
  4311. (org-test-with-temp-text "\n"
  4312. (forward-line)
  4313. (org-drag-element-backward))
  4314. :type 'user-error)
  4315. ;; 5. Otherwise, swap elements, preserving column and blank lines
  4316. ;; between elements.
  4317. (org-test-with-temp-text "Paragraph 1\n\n\nPara2\n\nPara3"
  4318. (search-forward "graph")
  4319. (org-drag-element-forward)
  4320. (should (equal (buffer-string) "Para2\n\n\nParagraph 1\n\nPara3"))
  4321. (should (looking-at " 1")))
  4322. ;; 5. Preserve visibility of elements and their contents.
  4323. (org-test-with-temp-text "
  4324. #+BEGIN_CENTER
  4325. Text.
  4326. #+END_CENTER
  4327. - item 1
  4328. #+BEGIN_QUOTE
  4329. Text.
  4330. #+END_QUOTE"
  4331. (while (search-forward "BEGIN_" nil t) (org-cycle))
  4332. (search-backward "#+BEGIN_CENTER")
  4333. (org-drag-element-forward)
  4334. (should
  4335. (equal
  4336. '((63 . 82) (26 . 48))
  4337. (mapcar (lambda (ov) (cons (overlay-start ov) (overlay-end ov)))
  4338. (overlays-in (point-min) (point-max)))))))
  4339. (ert-deftest test-org/next-block ()
  4340. "Test `org-next-block' specifications."
  4341. ;; Regular test.
  4342. (should
  4343. (org-test-with-temp-text "Paragraph\n#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  4344. (org-next-block 1)
  4345. (looking-at "#\\+BEGIN_CENTER")))
  4346. ;; Ignore case.
  4347. (should
  4348. (org-test-with-temp-text "Paragraph\n#+begin_center\ncontents\n#+end_center"
  4349. (let ((case-fold-search nil))
  4350. (org-next-block 1)
  4351. (looking-at "#\\+begin_center"))))
  4352. ;; Ignore current line.
  4353. (should
  4354. (org-test-with-temp-text
  4355. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER\n#+END_CENTER"
  4356. (org-next-block 1)
  4357. (looking-at "#\\+BEGIN_CENTER")))
  4358. ;; Throw an error when no block is found.
  4359. (should-error
  4360. (org-test-with-temp-text "Paragraph"
  4361. (org-next-block 1)))
  4362. ;; With an argument, skip many blocks at once.
  4363. (should
  4364. (org-test-with-temp-text
  4365. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4366. (org-next-block 2)
  4367. (looking-at "#\\+BEGIN_QUOTE")))
  4368. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4369. (should
  4370. (org-test-with-temp-text
  4371. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE"
  4372. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4373. (looking-at "#\\+BEGIN_QUOTE")))
  4374. ;; Optional argument is also case-insensitive.
  4375. (should
  4376. (org-test-with-temp-text
  4377. "Start\n#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote"
  4378. (let ((case-fold-search nil))
  4379. (org-next-block 1 nil "^[ \t]*#\\+BEGIN_QUOTE")
  4380. (looking-at "#\\+begin_quote")))))
  4381. (ert-deftest test-org/insert-structure-template ()
  4382. "Test `org-insert-structure-template'."
  4383. ;; Test in empty buffer.
  4384. (should
  4385. (string= "#+begin_foo\n#+end_foo\n"
  4386. (org-test-with-temp-text ""
  4387. (org-insert-structure-template "foo")
  4388. (buffer-string))))
  4389. ;; Test with multiple lines in buffer.
  4390. (should
  4391. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4392. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4393. (transient-mark-mode 1)
  4394. (org-mark-element)
  4395. (org-insert-structure-template "foo")
  4396. (buffer-string))))
  4397. ;; Mark only the current line.
  4398. (should
  4399. (string= "#+begin_foo\nI'm a paragraph\n#+end_foo\n\nI'm a second paragraph"
  4400. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragraph"
  4401. (transient-mark-mode 1)
  4402. (set-mark (point-min))
  4403. (end-of-line)
  4404. (org-insert-structure-template "foo")
  4405. (buffer-string))))
  4406. ;; Middle of paragraph.
  4407. (should
  4408. (string= "p1\n#+begin_foo\np2\n#+end_foo\np3"
  4409. (org-test-with-temp-text "p1\n<point>p2\np3"
  4410. (set-mark (line-beginning-position))
  4411. (end-of-line)
  4412. (activate-mark)
  4413. (org-insert-structure-template "foo")
  4414. (buffer-string))))
  4415. ;; Test with text in buffer, no region, no final newline.
  4416. (should
  4417. (string= "#+begin_foo\nI'm a paragraph.\n#+end_foo\n"
  4418. (org-test-with-temp-text "I'm a paragraph."
  4419. (org-mark-element)
  4420. (org-insert-structure-template "foo")
  4421. (buffer-string))))
  4422. ;; Test with text in buffer and region set.
  4423. (should
  4424. (string= "#+begin_foo\nI'm a paragraph\n\nI'm a second paragrah\n#+end_foo\n"
  4425. (org-test-with-temp-text "I'm a paragraph\n\nI'm a second paragrah"
  4426. (set-mark (point))
  4427. (goto-char (point-max))
  4428. (org-insert-structure-template "foo")
  4429. (buffer-string))))
  4430. ;; Test with example escaping.
  4431. (should
  4432. (string= "#+begin_example\n,* Heading\n#+end_example\n"
  4433. (org-test-with-temp-text "* Heading"
  4434. (org-mark-element)
  4435. (org-insert-structure-template "example")
  4436. (buffer-string))))
  4437. ;; Test with indentation.
  4438. (should
  4439. (string= " #+begin_foo\n This is a paragraph\n #+end_foo\n"
  4440. (org-test-with-temp-text " This is a paragraph"
  4441. (org-mark-element)
  4442. (org-insert-structure-template "foo")
  4443. (buffer-string))))
  4444. (should
  4445. (string= " #+begin_foo\n Line 1\n Line2\n #+end_foo\n"
  4446. (org-test-with-temp-text " Line 1\n Line2"
  4447. (org-mark-element)
  4448. (org-insert-structure-template "foo")
  4449. (buffer-string))))
  4450. ;; Test point location.
  4451. (should
  4452. (string= "#+begin_foo\n"
  4453. (org-test-with-temp-text ""
  4454. (org-insert-structure-template "foo")
  4455. (buffer-substring (point-min) (point)))))
  4456. (should
  4457. (string= "#+begin_src "
  4458. (org-test-with-temp-text ""
  4459. (org-insert-structure-template "src")
  4460. (buffer-substring (point-min) (point))))))
  4461. (ert-deftest test-org/previous-block ()
  4462. "Test `org-previous-block' specifications."
  4463. ;; Regular test.
  4464. (should
  4465. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER\n<point>"
  4466. (org-previous-block 1)
  4467. (looking-at "#\\+BEGIN_CENTER")))
  4468. ;; Ignore case.
  4469. (should
  4470. (org-test-with-temp-text "#+begin_center\ncontents\n#+end_center\n<point>"
  4471. (let ((case-fold-search nil))
  4472. (org-previous-block 1)
  4473. (looking-at "#\\+begin_center"))))
  4474. ;; Ignore current line.
  4475. (should
  4476. (org-test-with-temp-text
  4477. "#+BEGIN_QUOTE\n#+END_QUOTE\n#+BEGIN_CENTER<point>\n#+END_CENTER"
  4478. (org-previous-block 1)
  4479. (looking-at "#\\+BEGIN_QUOTE")))
  4480. ;; Throw an error when no block is found.
  4481. (should-error
  4482. (org-test-with-temp-text "Paragraph<point>"
  4483. (org-previous-block 1)))
  4484. ;; With an argument, skip many blocks at once.
  4485. (should
  4486. (org-test-with-temp-text
  4487. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4488. (org-previous-block 2)
  4489. (looking-at "#\\+BEGIN_CENTER")))
  4490. ;; With optional argument BLOCK-REGEXP, filter matched blocks.
  4491. (should
  4492. (org-test-with-temp-text
  4493. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+BEGIN_QUOTE\nB\n#+END_QUOTE\n<point>"
  4494. (org-previous-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4495. (looking-at "#\\+BEGIN_QUOTE")))
  4496. ;; Optional argument is also case-insensitive.
  4497. (should
  4498. (org-test-with-temp-text
  4499. "#+BEGIN_CENTER\nA\n#+END_CENTER\n#+begin_quote\nB\n#+end_quote\n<point>"
  4500. (let ((case-fold-search nil))
  4501. (org-next-block 1 "^[ \t]*#\\+BEGIN_QUOTE")
  4502. (looking-at "#\\+begin_quote")))))
  4503. ;;; Outline structure
  4504. (ert-deftest test-org/demote ()
  4505. "Test `org-demote' specifications."
  4506. ;; Add correct number of stars according to `org-odd-levels-only'.
  4507. (should
  4508. (= 2
  4509. (org-test-with-temp-text "* H"
  4510. (let ((org-odd-levels-only nil)) (org-demote))
  4511. (org-current-level))))
  4512. (should
  4513. (= 3
  4514. (org-test-with-temp-text "* H"
  4515. (let ((org-odd-levels-only t)) (org-demote))
  4516. (org-current-level))))
  4517. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4518. (should
  4519. (org-test-with-temp-text "* H :tag:"
  4520. (let ((org-tags-column 10)
  4521. (org-auto-align-tags t)
  4522. (org-odd-levels-only nil))
  4523. (org-demote))
  4524. (org-move-to-column 10)
  4525. (looking-at-p ":tag:$")))
  4526. (should-not
  4527. (org-test-with-temp-text "* H :tag:"
  4528. (let ((org-tags-column 10)
  4529. (org-auto-align-tags nil)
  4530. (org-odd-levels-only nil))
  4531. (org-demote))
  4532. (org-move-to-column 10)
  4533. (looking-at-p ":tag:$")))
  4534. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4535. ;; info and property drawers accordingly.
  4536. (should
  4537. (= 3
  4538. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4539. (let ((org-odd-levels-only nil)
  4540. (org-adapt-indentation t))
  4541. (org-demote))
  4542. (forward-line)
  4543. (org-get-indentation))))
  4544. (should
  4545. (= 3
  4546. (org-test-with-temp-text "* H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4547. (let ((org-odd-levels-only nil)
  4548. (org-adapt-indentation t))
  4549. (org-demote))
  4550. (forward-line)
  4551. (org-get-indentation))))
  4552. (should-not
  4553. (= 3
  4554. (org-test-with-temp-text "* H\n SCHEDULED: <2014-03-04 tue.>"
  4555. (let ((org-odd-levels-only nil)
  4556. (org-adapt-indentation nil))
  4557. (org-demote))
  4558. (forward-line)
  4559. (org-get-indentation))))
  4560. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4561. ;; section accordingly. Ignore, however, footnote definitions and
  4562. ;; inlinetasks boundaries.
  4563. (should
  4564. (= 3
  4565. (org-test-with-temp-text "* H\n Paragraph"
  4566. (let ((org-odd-levels-only nil)
  4567. (org-adapt-indentation t))
  4568. (org-demote))
  4569. (forward-line)
  4570. (org-get-indentation))))
  4571. (should
  4572. (= 2
  4573. (org-test-with-temp-text "* H\n Paragraph"
  4574. (let ((org-odd-levels-only nil)
  4575. (org-adapt-indentation nil))
  4576. (org-demote))
  4577. (forward-line)
  4578. (org-get-indentation))))
  4579. (should
  4580. (zerop
  4581. (org-test-with-temp-text "* H\n[fn:1] def line 1\ndef line 2"
  4582. (let ((org-odd-levels-only nil)
  4583. (org-adapt-indentation t))
  4584. (org-demote))
  4585. (goto-char (point-max))
  4586. (org-get-indentation))))
  4587. (should
  4588. (= 3
  4589. (org-test-with-temp-text "* H\n[fn:1] Def.\n\n\n After def."
  4590. (let ((org-odd-levels-only nil)
  4591. (org-adapt-indentation t))
  4592. (org-demote))
  4593. (goto-char (point-max))
  4594. (org-get-indentation))))
  4595. (when (featurep 'org-inlinetask)
  4596. (should
  4597. (zerop
  4598. (let ((org-inlinetask-min-level 5)
  4599. (org-adapt-indentation t))
  4600. (org-test-with-temp-text "* H\n***** I\n***** END"
  4601. (org-demote)
  4602. (forward-line)
  4603. (org-get-indentation))))))
  4604. (when (featurep 'org-inlinetask)
  4605. (should
  4606. (= 3
  4607. (let ((org-inlinetask-min-level 5)
  4608. (org-adapt-indentation t))
  4609. (org-test-with-temp-text "* H\n***** I\n Contents\n***** END"
  4610. (org-demote)
  4611. (forward-line 2)
  4612. (org-get-indentation))))))
  4613. ;; When `org-adapt-indentation' is non-nil, log drawers are
  4614. ;; adjusted.
  4615. (should
  4616. (equal
  4617. "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4618. (org-test-with-temp-text "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4619. (let ((org-odd-levels-only nil)
  4620. (org-adapt-indentation t))
  4621. (org-demote))
  4622. (buffer-string))))
  4623. (should
  4624. (equal
  4625. "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4626. (org-test-with-temp-text "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4627. (let ((org-odd-levels-only nil)
  4628. (org-adapt-indentation 'headline-data))
  4629. (org-demote))
  4630. (buffer-string))))
  4631. (should
  4632. (equal
  4633. "** H\n :LOGBOOK:\n - a\n :END:"
  4634. (org-test-with-temp-text "* H\n:LOGBOOK:\n- a\n:END:"
  4635. (let ((org-odd-levels-only nil)
  4636. (org-adapt-indentation t))
  4637. (org-demote))
  4638. (buffer-string))))
  4639. ;; Ignore contents of source blocks or example blocks when
  4640. ;; indentation should be preserved (through
  4641. ;; `org-src-preserve-indentation' or "-i" flag).
  4642. (should-not
  4643. (zerop
  4644. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4645. (let ((org-adapt-indentation t)
  4646. (org-src-preserve-indentation nil))
  4647. (org-demote))
  4648. (forward-line 2)
  4649. (org-get-indentation))))
  4650. (should
  4651. (zerop
  4652. (org-test-with-temp-text "* H\n#+BEGIN_EXAMPLE\n(+ 1 1)\n#+END_EXAMPLE"
  4653. (let ((org-adapt-indentation t)
  4654. (org-src-preserve-indentation t))
  4655. (org-demote))
  4656. (forward-line 2)
  4657. (org-get-indentation))))
  4658. (should
  4659. (zerop
  4660. (org-test-with-temp-text "* H\n#+BEGIN_SRC emacs-lisp\n(+ 1 1)\n#+END_SRC"
  4661. (let ((org-adapt-indentation t)
  4662. (org-src-preserve-indentation t))
  4663. (org-demote))
  4664. (forward-line 2)
  4665. (org-get-indentation))))
  4666. (should
  4667. (zerop
  4668. (org-test-with-temp-text
  4669. "* H\n#+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n#+END_SRC"
  4670. (let ((org-adapt-indentation t)
  4671. (org-src-preserve-indentation nil))
  4672. (org-demote))
  4673. (forward-line 2)
  4674. (org-get-indentation)))))
  4675. (ert-deftest test-org/promote ()
  4676. "Test `org-promote' specifications."
  4677. ;; Return an error if headline is to be promoted to level 0, unless
  4678. ;; `org-allow-promoting-top-level-subtree' is non-nil, in which case
  4679. ;; headline becomes a comment.
  4680. (should-error
  4681. (org-test-with-temp-text "* H"
  4682. (let ((org-allow-promoting-top-level-subtree nil)) (org-promote))))
  4683. (should
  4684. (equal "# H"
  4685. (org-test-with-temp-text "* H"
  4686. (let ((org-allow-promoting-top-level-subtree t)) (org-promote))
  4687. (buffer-string))))
  4688. ;; Remove correct number of stars according to
  4689. ;; `org-odd-levels-only'.
  4690. (should
  4691. (= 2
  4692. (org-test-with-temp-text "*** H"
  4693. (let ((org-odd-levels-only nil)) (org-promote))
  4694. (org-current-level))))
  4695. (should
  4696. (= 1
  4697. (org-test-with-temp-text "*** H"
  4698. (let ((org-odd-levels-only t)) (org-promote))
  4699. (org-current-level))))
  4700. ;; When `org-auto-align-tags' is non-nil, move tags accordingly.
  4701. (should
  4702. (org-test-with-temp-text "** H :tag:"
  4703. (let ((org-tags-column 10)
  4704. (org-auto-align-tags t)
  4705. (org-odd-levels-only nil))
  4706. (org-promote))
  4707. (org-move-to-column 10)
  4708. (looking-at-p ":tag:$")))
  4709. (should-not
  4710. (org-test-with-temp-text "** H :tag:"
  4711. (let ((org-tags-column 10)
  4712. (org-auto-align-tags nil)
  4713. (org-odd-levels-only nil))
  4714. (org-promote))
  4715. (org-move-to-column 10)
  4716. (looking-at-p ":tag:$")))
  4717. ;; When `org-adapt-indentation' is non-nil, always indent planning
  4718. ;; info and property drawers.
  4719. (should
  4720. (= 2
  4721. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4722. (let ((org-odd-levels-only nil)
  4723. (org-adapt-indentation t))
  4724. (org-promote))
  4725. (forward-line)
  4726. (org-get-indentation))))
  4727. (should
  4728. (= 2
  4729. (org-test-with-temp-text "** H\n :PROPERTIES:\n :FOO: Bar\n :END:"
  4730. (let ((org-odd-levels-only nil)
  4731. (org-adapt-indentation t))
  4732. (org-promote))
  4733. (forward-line)
  4734. (org-get-indentation))))
  4735. (should-not
  4736. (= 2
  4737. (org-test-with-temp-text "** H\n SCHEDULED: <2014-03-04 tue.>"
  4738. (let ((org-odd-levels-only nil)
  4739. (org-adapt-indentation nil))
  4740. (org-promote))
  4741. (forward-line)
  4742. (org-get-indentation))))
  4743. ;; When `org-adapt-indentation' is non-nil, shift all lines in
  4744. ;; section accordingly. Ignore, however, footnote definitions and
  4745. ;; inlinetasks boundaries.
  4746. (should
  4747. (= 2
  4748. (org-test-with-temp-text "** H\n Paragraph"
  4749. (let ((org-odd-levels-only nil)
  4750. (org-adapt-indentation t))
  4751. (org-promote))
  4752. (forward-line)
  4753. (org-get-indentation))))
  4754. (should-not
  4755. (= 2
  4756. (org-test-with-temp-text "** H\n Paragraph"
  4757. (let ((org-odd-levels-only nil)
  4758. (org-adapt-indentation nil))
  4759. (org-promote))
  4760. (forward-line)
  4761. (org-get-indentation))))
  4762. (should
  4763. (= 2
  4764. (org-test-with-temp-text "** H\n Paragraph\n[fn:1] line1\nline2"
  4765. (let ((org-odd-levels-only nil)
  4766. (org-adapt-indentation t))
  4767. (org-promote))
  4768. (forward-line)
  4769. (org-get-indentation))))
  4770. (when (featurep 'org-inlinetask)
  4771. (should
  4772. (zerop
  4773. (let ((org-inlinetask-min-level 5)
  4774. (org-adapt-indentation t))
  4775. (org-test-with-temp-text "** H\n***** I\n***** END"
  4776. (org-promote)
  4777. (forward-line)
  4778. (org-get-indentation))))))
  4779. (when (featurep 'org-inlinetask)
  4780. (should
  4781. (= 2
  4782. (let ((org-inlinetask-min-level 5)
  4783. (org-adapt-indentation t))
  4784. (org-test-with-temp-text "** H\n***** I\n Contents\n***** END"
  4785. (org-promote)
  4786. (forward-line 2)
  4787. (org-get-indentation))))))
  4788. ;; Give up shifting if it would break document's structure
  4789. ;; otherwise.
  4790. (should
  4791. (= 3
  4792. (org-test-with-temp-text "** H\n Paragraph\n [fn:1] Def."
  4793. (let ((org-odd-levels-only nil)
  4794. (org-adapt-indentation t))
  4795. (org-promote))
  4796. (forward-line)
  4797. (org-get-indentation))))
  4798. (should
  4799. (= 3
  4800. (org-test-with-temp-text "** H\n Paragraph\n * list."
  4801. (let ((org-odd-levels-only nil)
  4802. (org-adapt-indentation t))
  4803. (org-promote))
  4804. (forward-line)
  4805. (org-get-indentation))))
  4806. ;; When `org-adapt-indentation' is non-nil, log drawers are
  4807. ;; adjusted.
  4808. (should
  4809. (equal
  4810. "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4811. (org-test-with-temp-text "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4812. (let ((org-odd-levels-only nil)
  4813. (org-adapt-indentation t))
  4814. (org-promote))
  4815. (buffer-string))))
  4816. (should
  4817. (equal
  4818. "* H\n :LOGBOOK:\n - a\n :END:\n b"
  4819. (org-test-with-temp-text "** H\n :LOGBOOK:\n - a\n :END:\n b"
  4820. (let ((org-odd-levels-only nil)
  4821. (org-adapt-indentation 'headline-data))
  4822. (org-promote))
  4823. (buffer-string))))
  4824. (should
  4825. (equal
  4826. "* H\n:LOGBOOK:\n- a\n:END:"
  4827. (org-test-with-temp-text "** H\n:LOGBOOK:\n- a\n:END:"
  4828. (let ((org-odd-levels-only nil)
  4829. (org-adapt-indentation t))
  4830. (org-promote))
  4831. (buffer-string))))
  4832. (should
  4833. (equal
  4834. "# H\n:LOGBOOK:\n- a\n:END:"
  4835. (org-test-with-temp-text "* H\n:LOGBOOK:\n- a\n:END:"
  4836. (let ((org-odd-levels-only nil)
  4837. (org-allow-promoting-top-level-subtree t)
  4838. (org-adapt-indentation t))
  4839. (org-promote))
  4840. (buffer-string))))
  4841. ;; Ignore contents of source blocks or example blocks when
  4842. ;; indentation should be preserved (through
  4843. ;; `org-src-preserve-indentation' or "-i" flag).
  4844. (should-not
  4845. (zerop
  4846. (org-test-with-temp-text
  4847. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  4848. (let ((org-adapt-indentation t)
  4849. (org-src-preserve-indentation nil)
  4850. (org-odd-levels-only nil))
  4851. (org-promote))
  4852. (forward-line)
  4853. (org-get-indentation))))
  4854. (should
  4855. (zerop
  4856. (org-test-with-temp-text
  4857. "** H\n #+BEGIN_EXAMPLE\nContents\n #+END_EXAMPLE"
  4858. (let ((org-adapt-indentation t)
  4859. (org-src-preserve-indentation t)
  4860. (org-odd-levels-only nil))
  4861. (org-promote))
  4862. (forward-line)
  4863. (org-get-indentation))))
  4864. (should
  4865. (zerop
  4866. (org-test-with-temp-text
  4867. "** H\n #+BEGIN_SRC emacs-lisp\n(+ 1 1)\n #+END_SRC"
  4868. (let ((org-adapt-indentation t)
  4869. (org-src-preserve-indentation t)
  4870. (org-odd-levels-only nil))
  4871. (org-promote))
  4872. (forward-line)
  4873. (org-get-indentation))))
  4874. (should
  4875. (zerop
  4876. (org-test-with-temp-text
  4877. "** H\n #+BEGIN_SRC emacs-lisp -i\n(+ 1 1)\n #+END_SRC"
  4878. (let ((org-adapt-indentation t)
  4879. (org-src-preserve-indentation nil)
  4880. (org-odd-levels-only nil))
  4881. (org-promote))
  4882. (forward-line)
  4883. (org-get-indentation)))))
  4884. (ert-deftest test-org/org-get-valid-level ()
  4885. "Test function `org-get-valid-level' specifications."
  4886. (let ((org-odd-levels-only nil))
  4887. (should (equal 1 (org-get-valid-level 0 0)))
  4888. (should (equal 1 (org-get-valid-level 0 1)))
  4889. (should (equal 2 (org-get-valid-level 0 2)))
  4890. (should (equal 3 (org-get-valid-level 0 3)))
  4891. (should (equal 1 (org-get-valid-level 1 0)))
  4892. (should (equal 2 (org-get-valid-level 1 1)))
  4893. (should (equal 23 (org-get-valid-level 1 22)))
  4894. (should (equal 1 (org-get-valid-level 1 -1)))
  4895. (should (equal 1 (org-get-valid-level 2 -1))))
  4896. (let ((org-odd-levels-only t))
  4897. (should (equal 1 (org-get-valid-level 0 0)))
  4898. (should (equal 1 (org-get-valid-level 0 1)))
  4899. (should (equal 3 (org-get-valid-level 0 2)))
  4900. (should (equal 5 (org-get-valid-level 0 3)))
  4901. (should (equal 1 (org-get-valid-level 1 0)))
  4902. (should (equal 3 (org-get-valid-level 1 1)))
  4903. (should (equal 3 (org-get-valid-level 2 1)))
  4904. (should (equal 5 (org-get-valid-level 3 1)))
  4905. (should (equal 5 (org-get-valid-level 4 1)))
  4906. (should (equal 43 (org-get-valid-level 1 21)))
  4907. (should (equal 1 (org-get-valid-level 1 -1)))
  4908. (should (equal 1 (org-get-valid-level 2 -1)))
  4909. (should (equal 1 (org-get-valid-level 3 -1)))
  4910. (should (equal 3 (org-get-valid-level 4 -1)))
  4911. (should (equal 3 (org-get-valid-level 5 -1)))))
  4912. ;;; Planning
  4913. (ert-deftest test-org/at-planning-p ()
  4914. "Test `org-at-planning-p' specifications."
  4915. ;; Regular test.
  4916. (should
  4917. (org-test-with-temp-text "* Headline\n<point>DEADLINE: <2014-03-04 tue.>"
  4918. (org-at-planning-p)))
  4919. (should-not
  4920. (org-test-with-temp-text "DEADLINE: <2014-03-04 tue.>"
  4921. (org-at-planning-p)))
  4922. ;; Correctly find planning attached to inlinetasks.
  4923. (when (featurep 'org-inlinetask)
  4924. (should
  4925. (org-test-with-temp-text
  4926. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>\n*** END"
  4927. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4928. (should-not
  4929. (org-test-with-temp-text
  4930. "*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  4931. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4932. (should-not
  4933. (org-test-with-temp-text
  4934. "* Headline\n*** Inlinetask\n<point>DEADLINE: <2014-03-04 tue.>"
  4935. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))
  4936. (should-not
  4937. (org-test-with-temp-text
  4938. "* Headline\n*** Inlinetask\n*** END\n<point>DEADLINE: <2014-03-04 tue.>"
  4939. (let ((org-inlinetask-min-level 3)) (org-at-planning-p))))))
  4940. (ert-deftest test-org/add-planning-info ()
  4941. "Test `org-add-planning-info'."
  4942. ;; Create deadline when `org-adapt-indentation' is non-nil.
  4943. (should
  4944. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4945. (org-test-with-temp-text "* H\nParagraph<point>"
  4946. (let ((org-adapt-indentation t))
  4947. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4948. (replace-regexp-in-string
  4949. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4950. nil nil 1))))
  4951. ;; Create deadline when `org-adapt-indentation' is nil.
  4952. (should
  4953. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  4954. (org-test-with-temp-text "* H\nParagraph<point>"
  4955. (let ((org-adapt-indentation nil))
  4956. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4957. (replace-regexp-in-string
  4958. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4959. nil nil 1))))
  4960. ;; Update deadline when `org-adapt-indentation' is non-nil.
  4961. (should
  4962. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  4963. (org-test-with-temp-text "\
  4964. * H
  4965. DEADLINE: <2015-06-24 Wed>
  4966. Paragraph<point>"
  4967. (let ((org-adapt-indentation t))
  4968. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4969. (replace-regexp-in-string
  4970. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4971. nil nil 1))))
  4972. ;; Update deadline when `org-adapt-indentation' is nil.
  4973. (should
  4974. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  4975. (org-test-with-temp-text "\
  4976. * H
  4977. DEADLINE: <2015-06-24 Wed>
  4978. Paragraph<point>"
  4979. (let ((org-adapt-indentation nil))
  4980. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  4981. (replace-regexp-in-string
  4982. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4983. nil nil 1))))
  4984. ;; Schedule when `org-adapt-indentation' is non-nil.
  4985. (should
  4986. (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
  4987. (org-test-with-temp-text "* H\nParagraph<point>"
  4988. (let ((org-adapt-indentation t))
  4989. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  4990. (replace-regexp-in-string
  4991. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  4992. nil nil 1))))
  4993. ;; Schedule when `org-adapt-indentation' is nil.
  4994. (should
  4995. (equal "* H\nSCHEDULED: <2015-06-25>\nParagraph"
  4996. (org-test-with-temp-text "* H\nParagraph<point>"
  4997. (let ((org-adapt-indentation nil))
  4998. (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
  4999. (replace-regexp-in-string
  5000. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5001. nil nil 1))))
  5002. ;; Add deadline when scheduled.
  5003. (should
  5004. (equal "\
  5005. * H
  5006. DEADLINE: <2015-06-25> SCHEDULED: <2015-06-24>
  5007. Paragraph"
  5008. (org-test-with-temp-text "\
  5009. * H
  5010. SCHEDULED: <2015-06-24 Wed>
  5011. Paragraph<point>"
  5012. (let ((org-adapt-indentation t))
  5013. (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
  5014. (replace-regexp-in-string
  5015. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5016. nil nil 1))))
  5017. ;; Remove middle entry.
  5018. (should
  5019. (equal "\
  5020. * H
  5021. CLOSED: [2015-06-24] SCHEDULED: <2015-06-24>
  5022. Paragraph"
  5023. (org-test-with-temp-text "\
  5024. * H
  5025. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  5026. Paragraph<point>"
  5027. (let ((org-adapt-indentation t))
  5028. (org-add-planning-info nil nil 'deadline))
  5029. (replace-regexp-in-string
  5030. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  5031. nil nil 1))))
  5032. ;; Remove last entry and then middle entry (order should not
  5033. ;; matter).
  5034. (should
  5035. (equal "\
  5036. * H
  5037. CLOSED: [2015-06-24]
  5038. Paragraph"
  5039. (org-test-with-temp-text "\
  5040. * H
  5041. CLOSED: [2015-06-24 Wed] DEADLINE: <2015-06-25 Thu> SCHEDULED: <2015-06-24 Wed>
  5042. Paragraph<point>"
  5043. (let ((org-adapt-indentation t))
  5044. (org-add-planning-info nil nil 'scheduled 'deadline))
  5045. (replace-regexp-in-string
  5046. "\\( [.A-Za-z]+\\)[]>]" "" (buffer-string)
  5047. nil nil 1))))
  5048. ;; Remove closed when `org-adapt-indentation' is non-nil.
  5049. (should
  5050. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5051. (org-test-with-temp-text "\
  5052. * H
  5053. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  5054. Paragraph<point>"
  5055. (let ((org-adapt-indentation t))
  5056. (org-add-planning-info nil nil 'closed))
  5057. (replace-regexp-in-string
  5058. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5059. nil nil 1))))
  5060. (should
  5061. (equal "* H\n Paragraph"
  5062. (org-test-with-temp-text "\
  5063. * H
  5064. CLOSED: [2015-06-25 Thu]
  5065. Paragraph<point>"
  5066. (let ((org-adapt-indentation t))
  5067. (org-add-planning-info nil nil 'closed))
  5068. (replace-regexp-in-string
  5069. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5070. nil nil 1))))
  5071. ;; Remove closed when `org-adapt-indentation' is nil.
  5072. (should
  5073. (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
  5074. (org-test-with-temp-text "\
  5075. * H
  5076. CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
  5077. Paragraph<point>"
  5078. (let ((org-adapt-indentation nil))
  5079. (org-add-planning-info nil nil 'closed))
  5080. (replace-regexp-in-string
  5081. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5082. nil nil 1))))
  5083. (should
  5084. (equal "* H\nParagraph"
  5085. (org-test-with-temp-text "\
  5086. * H
  5087. CLOSED: [2015-06-25 Thu]
  5088. Paragraph<point>"
  5089. (let ((org-adapt-indentation nil))
  5090. (org-add-planning-info nil nil 'closed))
  5091. (replace-regexp-in-string
  5092. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5093. nil nil 1))))
  5094. ;; Remove closed entry and delete empty line.
  5095. (should
  5096. (equal "\
  5097. * H
  5098. Paragraph"
  5099. (org-test-with-temp-text "\
  5100. * H
  5101. CLOSED: [2015-06-24 Wed]
  5102. Paragraph<point>"
  5103. (let ((org-adapt-indentation t))
  5104. (org-add-planning-info nil nil 'closed))
  5105. (replace-regexp-in-string
  5106. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5107. nil nil 1))))
  5108. ;; Remove one entry and update another.
  5109. (should
  5110. (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
  5111. (org-test-with-temp-text "\
  5112. * H
  5113. SCHEDULED: <2015-06-23 Tue> DEADLINE: <2015-06-24 Wed>
  5114. Paragraph<point>"
  5115. (let ((org-adapt-indentation t))
  5116. (org-add-planning-info 'deadline "<2015-06-25 Thu>" 'scheduled))
  5117. (replace-regexp-in-string
  5118. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5119. nil nil 1)))))
  5120. (ert-deftest test-org/deadline ()
  5121. "Test `org-deadline' specifications."
  5122. ;; Insert a new value or replace existing one.
  5123. (should
  5124. (equal "* H\nDEADLINE: <2012-03-29>"
  5125. (org-test-with-temp-text "* H"
  5126. (let ((org-adapt-indentation nil)
  5127. (org-last-inserted-timestamp nil))
  5128. (org-deadline nil "<2012-03-29 Tue>"))
  5129. (replace-regexp-in-string
  5130. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5131. nil nil 1))))
  5132. (should
  5133. (equal "* H\nDEADLINE: <2014-03-04>"
  5134. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5135. (let ((org-adapt-indentation nil)
  5136. (org-last-inserted-timestamp nil))
  5137. (org-deadline nil "<2014-03-04 Thu>"))
  5138. (replace-regexp-in-string
  5139. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5140. nil nil 1))))
  5141. ;; Accept delta time, e.g., "+2d".
  5142. (should
  5143. (equal "* H\nDEADLINE: <2015-03-04>"
  5144. (org-test-at-time "2014-03-04"
  5145. (org-test-with-temp-text "* H"
  5146. (let ((org-adapt-indentation nil)
  5147. (org-last-inserted-timestamp nil))
  5148. (org-deadline nil "+1y"))
  5149. (replace-regexp-in-string
  5150. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5151. ;; Preserve repeater.
  5152. (should
  5153. (equal "* H\nDEADLINE: <2012-03-29 +2y>"
  5154. (org-test-with-temp-text "* H"
  5155. (let ((org-adapt-indentation nil)
  5156. (org-last-inserted-timestamp nil))
  5157. (org-deadline nil "<2012-03-29 Tue +2y>"))
  5158. (replace-regexp-in-string
  5159. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5160. ;; Remove CLOSED keyword, if any.
  5161. (should
  5162. (equal "* H\nDEADLINE: <2012-03-29>"
  5163. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  5164. (let ((org-adapt-indentation nil)
  5165. (org-last-inserted-timestamp nil))
  5166. (org-deadline nil "<2012-03-29 Tue>"))
  5167. (replace-regexp-in-string
  5168. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5169. ;; With C-u argument, remove DEADLINE keyword.
  5170. (should
  5171. (equal "* H\n"
  5172. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5173. (let ((org-adapt-indentation nil)
  5174. (org-last-inserted-timestamp nil))
  5175. (org-deadline '(4)))
  5176. (buffer-string))))
  5177. (should
  5178. (equal "* H"
  5179. (org-test-with-temp-text "* H"
  5180. (let ((org-adapt-indentation nil)
  5181. (org-last-inserted-timestamp nil))
  5182. (org-deadline '(4)))
  5183. (buffer-string))))
  5184. ;; With C-u C-u argument, prompt for a delay cookie.
  5185. (should
  5186. (equal "* H\nDEADLINE: <2012-03-29 -705d>"
  5187. (cl-letf (((symbol-function 'org-read-date)
  5188. (lambda (&rest args)
  5189. (apply #'encode-time
  5190. (org-parse-time-string "2014-03-04")))))
  5191. (org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
  5192. (let ((org-adapt-indentation nil)
  5193. (org-last-inserted-timestamp nil))
  5194. (org-deadline '(16)))
  5195. (buffer-string)))))
  5196. (should-error
  5197. (cl-letf (((symbol-function 'org-read-date)
  5198. (lambda (&rest args)
  5199. (apply #'encode-time
  5200. (org-parse-time-string "2014-03-04")))))
  5201. (org-test-with-temp-text "* H"
  5202. (let ((org-adapt-indentation nil)
  5203. (org-last-inserted-timestamp nil))
  5204. (org-deadline '(16)))
  5205. (buffer-string))))
  5206. ;; When a region is active and
  5207. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5208. ;; same value in all headlines in region.
  5209. (should
  5210. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5211. (org-test-with-temp-text "* H1\n* H2"
  5212. (let ((org-adapt-indentation nil)
  5213. (org-last-inserted-timestamp nil)
  5214. (org-loop-over-headlines-in-active-region t))
  5215. (transient-mark-mode 1)
  5216. (push-mark (point) t t)
  5217. (goto-char (point-max))
  5218. (org-deadline nil "2012-03-29"))
  5219. (replace-regexp-in-string
  5220. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5221. (should-not
  5222. (equal "* H1\nDEADLINE: <2012-03-29>\n* H2\nDEADLINE: <2012-03-29>"
  5223. (org-test-with-temp-text "* H1\n* H2"
  5224. (let ((org-adapt-indentation nil)
  5225. (org-last-inserted-timestamp nil)
  5226. (org-loop-over-headlines-in-active-region nil))
  5227. (transient-mark-mode 1)
  5228. (push-mark (point) t t)
  5229. (goto-char (point-max))
  5230. (org-deadline nil "2012-03-29"))
  5231. (replace-regexp-in-string
  5232. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5233. (ert-deftest test-org/schedule ()
  5234. "Test `org-schedule' specifications."
  5235. ;; Insert a new value or replace existing one.
  5236. (should
  5237. (equal "* H\nSCHEDULED: <2012-03-29>"
  5238. (org-test-with-temp-text "* H"
  5239. (let ((org-adapt-indentation nil)
  5240. (org-last-inserted-timestamp nil))
  5241. (org-schedule nil "<2012-03-29 Tue>"))
  5242. (replace-regexp-in-string
  5243. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5244. nil nil 1))))
  5245. (should
  5246. (equal "* H\nSCHEDULED: <2014-03-04>"
  5247. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5248. (let ((org-adapt-indentation nil)
  5249. (org-last-inserted-timestamp nil))
  5250. (org-schedule nil "<2014-03-04 Thu>"))
  5251. (replace-regexp-in-string
  5252. "\\( [.A-Za-z]+\\)>" "" (buffer-string)
  5253. nil nil 1))))
  5254. ;; Accept delta time, e.g., "+2d".
  5255. (should
  5256. (equal "* H\nSCHEDULED: <2015-03-04>"
  5257. (org-test-at-time "2014-03-04"
  5258. (org-test-with-temp-text "* H"
  5259. (let ((org-adapt-indentation nil)
  5260. (org-last-inserted-timestamp nil))
  5261. (org-schedule nil "+1y"))
  5262. (replace-regexp-in-string
  5263. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
  5264. ;; Preserve repeater.
  5265. (should
  5266. (equal "* H\nSCHEDULED: <2012-03-29 +2y>"
  5267. (org-test-with-temp-text "* H"
  5268. (let ((org-adapt-indentation nil)
  5269. (org-last-inserted-timestamp nil))
  5270. (org-schedule nil "<2012-03-29 Tue +2y>"))
  5271. (replace-regexp-in-string
  5272. "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
  5273. ;; Remove CLOSED keyword, if any.
  5274. (should
  5275. (equal "* H\nSCHEDULED: <2012-03-29>"
  5276. (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
  5277. (let ((org-adapt-indentation nil)
  5278. (org-last-inserted-timestamp nil))
  5279. (org-schedule nil "<2012-03-29 Tue>"))
  5280. (replace-regexp-in-string
  5281. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5282. ;; With C-u argument, remove SCHEDULED keyword.
  5283. (should
  5284. (equal "* H\n"
  5285. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5286. (let ((org-adapt-indentation nil)
  5287. (org-last-inserted-timestamp nil))
  5288. (org-schedule '(4)))
  5289. (buffer-string))))
  5290. (should
  5291. (equal "* H"
  5292. (org-test-with-temp-text "* H"
  5293. (let ((org-adapt-indentation nil)
  5294. (org-last-inserted-timestamp nil))
  5295. (org-schedule '(4)))
  5296. (buffer-string))))
  5297. ;; With C-u C-u argument, prompt for a delay cookie.
  5298. (should
  5299. (equal "* H\nSCHEDULED: <2012-03-29 -705d>"
  5300. (cl-letf (((symbol-function 'org-read-date)
  5301. (lambda (&rest args)
  5302. (apply #'encode-time
  5303. (org-parse-time-string "2014-03-04")))))
  5304. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
  5305. (let ((org-adapt-indentation nil)
  5306. (org-last-inserted-timestamp nil))
  5307. (org-schedule '(16)))
  5308. (buffer-string)))))
  5309. (should-error
  5310. (cl-letf (((symbol-function 'org-read-date)
  5311. (lambda (&rest args)
  5312. (apply #'encode-time
  5313. (org-parse-time-string "2014-03-04")))))
  5314. (org-test-with-temp-text "* H"
  5315. (let ((org-adapt-indentation nil)
  5316. (org-last-inserted-timestamp nil))
  5317. (org-schedule '(16)))
  5318. (buffer-string))))
  5319. ;; When a region is active and
  5320. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  5321. ;; same value in all headlines in region.
  5322. (should
  5323. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5324. (org-test-with-temp-text "* H1\n* H2"
  5325. (let ((org-adapt-indentation nil)
  5326. (org-last-inserted-timestamp nil)
  5327. (org-loop-over-headlines-in-active-region t))
  5328. (transient-mark-mode 1)
  5329. (push-mark (point) t t)
  5330. (goto-char (point-max))
  5331. (org-schedule nil "2012-03-29"))
  5332. (replace-regexp-in-string
  5333. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5334. (should-not
  5335. (equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
  5336. (org-test-with-temp-text "* H1\n* H2"
  5337. (let ((org-adapt-indentation nil)
  5338. (org-last-inserted-timestamp nil)
  5339. (org-loop-over-headlines-in-active-region nil))
  5340. (transient-mark-mode 1)
  5341. (push-mark (point) t t)
  5342. (goto-char (point-max))
  5343. (org-schedule nil "2012-03-29"))
  5344. (replace-regexp-in-string
  5345. "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
  5346. (should
  5347. ;; check if a repeater survives re-scheduling.
  5348. (string-match-p
  5349. "\\* H\nSCHEDULED: <2017-02-01 [.A-Za-z]* \\+\\+7d>\n"
  5350. (org-test-with-temp-text "* H\nSCHEDULED: <2017-01-19 ++7d>\n"
  5351. (let ((org-adapt-indentation nil)
  5352. (org-last-inserted-timestamp nil))
  5353. (org-schedule nil "2017-02-01"))
  5354. (buffer-string)))))
  5355. ;;; Property API
  5356. (ert-deftest test-org/buffer-property-keys ()
  5357. "Test `org-buffer-property-keys' specifications."
  5358. ;; Retrieve properties across siblings.
  5359. (should
  5360. (equal '("A" "B")
  5361. (org-test-with-temp-text "
  5362. * H1
  5363. :PROPERTIES:
  5364. :A: 1
  5365. :END:
  5366. * H2
  5367. :PROPERTIES:
  5368. :B: 1
  5369. :END:"
  5370. (org-buffer-property-keys))))
  5371. ;; Retrieve properties across children.
  5372. (should
  5373. (equal '("A" "B")
  5374. (org-test-with-temp-text "
  5375. * H1
  5376. :PROPERTIES:
  5377. :A: 1
  5378. :END:
  5379. ** H2
  5380. :PROPERTIES:
  5381. :B: 1
  5382. :END:"
  5383. (org-buffer-property-keys))))
  5384. ;; Retrieve muliple properties in the same drawer.
  5385. (should
  5386. (equal '("A" "B")
  5387. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5388. (org-buffer-property-keys))))
  5389. ;; Ignore extension symbol in property name.
  5390. (should
  5391. (equal '("A")
  5392. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5393. (org-buffer-property-keys))))
  5394. ;; Add bare property if xxx_ALL property is there
  5395. (should
  5396. (equal '("A" "B" "B_ALL")
  5397. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B_ALL: foo bar\n:END:"
  5398. (org-buffer-property-keys))))
  5399. ;; Add bare property if xxx_ALL property is there - check dupes
  5400. (should
  5401. (equal '("A" "B" "B_ALL")
  5402. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:B_ALL: foo bar\n:END:"
  5403. (org-buffer-property-keys))))
  5404. ;; Retrieve properties from #+PROPERTY keyword lines
  5405. (should
  5406. (equal '("A" "C")
  5407. (org-test-with-temp-text "#+PROPERTY: C foo\n* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5408. (org-buffer-property-keys))))
  5409. ;; Retrieve properties from #+PROPERTY keyword lines - make sure an _ALL property also
  5410. ;; adds the bare property
  5411. (should
  5412. (equal '("A" "C" "C_ALL")
  5413. (org-test-with-temp-text "#+PROPERTY: C_ALL foo bar\n* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5414. (org-buffer-property-keys))))
  5415. ;; With non-nil COLUMNS, extract property names from columns.
  5416. (should
  5417. (equal '("A" "B")
  5418. (org-test-with-temp-text "#+COLUMNS: %25ITEM %A %20B"
  5419. (org-buffer-property-keys nil nil t))))
  5420. (should
  5421. (equal '("A" "B" "COLUMNS")
  5422. (org-test-with-temp-text
  5423. "* H\n:PROPERTIES:\n:COLUMNS: %25ITEM %A %20B\n:END:"
  5424. (org-buffer-property-keys nil nil t))))
  5425. ;; In COLUMNS, ignore title and summary-type.
  5426. (should
  5427. (equal '("A")
  5428. (org-test-with-temp-text "#+COLUMNS: %A(Foo)"
  5429. (org-buffer-property-keys nil nil t))))
  5430. (should
  5431. (equal '("A")
  5432. (org-test-with-temp-text "#+COLUMNS: %A{Foo}"
  5433. (org-buffer-property-keys nil nil t))))
  5434. (should
  5435. (equal '("A")
  5436. (org-test-with-temp-text "#+COLUMNS: %A(Foo){Bar}"
  5437. (org-buffer-property-keys nil nil t)))))
  5438. (ert-deftest test-org/property-values ()
  5439. "Test `org-property-values' specifications."
  5440. ;; Regular test.
  5441. (should
  5442. (equal '("2" "1")
  5443. (org-test-with-temp-text
  5444. "* H\n:PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A: 2\n:END:"
  5445. (org-property-values "A"))))
  5446. ;; Ignore empty values.
  5447. (should-not
  5448. (org-test-with-temp-text
  5449. "* H1\n:PROPERTIES:\n:A:\n:END:\n* H2\n:PROPERTIES:\n:A: \n:END:"
  5450. (org-property-values "A")))
  5451. ;; Take into consideration extended values.
  5452. (should
  5453. (equal '("1 2")
  5454. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
  5455. (org-property-values "A")))))
  5456. (ert-deftest test-org/set-property ()
  5457. "Test `org-set-property' specifications."
  5458. (should
  5459. (equal
  5460. ":PROPERTIES:\n:TEST: t\n:END:\n"
  5461. (org-test-with-temp-text ""
  5462. (let ((org-property-format "%s %s"))
  5463. (org-set-property "TEST" "t"))
  5464. (buffer-string))))
  5465. (should
  5466. (equal
  5467. "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5468. (org-test-with-temp-text "* H"
  5469. (let ((org-adapt-indentation nil)
  5470. (org-property-format "%s %s"))
  5471. (org-set-property "TEST" "t"))
  5472. (buffer-string)))))
  5473. (ert-deftest test-org/delete-property ()
  5474. "Test `org-delete-property' specifications."
  5475. (should
  5476. (equal
  5477. ""
  5478. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5479. (org-delete-property "TEST")
  5480. (buffer-string))))
  5481. (should
  5482. (equal
  5483. ":PROPERTIES:\n:TEST1: t\n:END:\n"
  5484. (org-test-with-temp-text ":PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5485. (org-delete-property "TEST2")
  5486. (buffer-string))))
  5487. (should
  5488. (equal
  5489. "* H\n"
  5490. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
  5491. (org-delete-property "TEST")
  5492. (buffer-string))))
  5493. (should
  5494. (equal
  5495. "* H\n:PROPERTIES:\n:TEST1: t\n:END:\n"
  5496. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TEST1: t\n:TEST2: t\n:END:\n"
  5497. (org-delete-property "TEST2")
  5498. (buffer-string)))))
  5499. (ert-deftest test-org/delete-property-globally ()
  5500. "Test `org-delete-property-global' specifications."
  5501. (should
  5502. (equal
  5503. ""
  5504. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n"
  5505. (org-delete-property-globally "TEST")
  5506. (buffer-string))))
  5507. (should
  5508. (equal
  5509. "* H\n"
  5510. (org-test-with-temp-text ":PROPERTIES:\n:TEST: t\n:END:\n* H\n:PROPERTIES:\n:TEST: nil\n:END:"
  5511. (org-delete-property-globally "TEST")
  5512. (buffer-string)))))
  5513. (ert-deftest test-org/find-property ()
  5514. "Test `org-find-property' specifications."
  5515. ;; Regular test.
  5516. (should
  5517. (= 1
  5518. (org-test-with-temp-text "* H\n:PROPERTIES:\n:PROP: value\n:END:"
  5519. (org-find-property "prop"))))
  5520. ;; Find properties in top-level property drawer.
  5521. (should
  5522. (= 1
  5523. (org-test-with-temp-text ":PROPERTIES:\n:PROP: value\n:END:"
  5524. (org-find-property "prop"))))
  5525. ;; Ignore false positives.
  5526. (should
  5527. (= 27
  5528. (org-test-with-temp-text
  5529. "* H1\n:DRAWER:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 1\n:END:"
  5530. (org-find-property "A"))))
  5531. ;; Return first entry found in buffer.
  5532. (should
  5533. (= 1
  5534. (org-test-with-temp-text
  5535. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5536. (org-find-property "A"))))
  5537. ;; Only search visible part of the buffer.
  5538. (should
  5539. (= 31
  5540. (org-test-with-temp-text
  5541. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:<point>A: 1\n:END:"
  5542. (org-narrow-to-subtree)
  5543. (org-find-property "A"))))
  5544. ;; With optional argument, only find entries with a specific value.
  5545. (should-not
  5546. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5547. (org-find-property "A" "2")))
  5548. (should
  5549. (= 31
  5550. (org-test-with-temp-text
  5551. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: 2\n:END:"
  5552. (org-find-property "A" "2"))))
  5553. ;; Use "nil" for explicit nil values.
  5554. (should
  5555. (= 31
  5556. (org-test-with-temp-text
  5557. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2\n:PROPERTIES:\n:A: nil\n:END:"
  5558. (org-find-property "A" "nil")))))
  5559. (ert-deftest test-org/entry-delete ()
  5560. "Test `org-entry-delete' specifications."
  5561. ;; Regular test.
  5562. (should
  5563. (string-match
  5564. " *:PROPERTIES:\n *:B: +2\n *:END:"
  5565. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5566. (org-entry-delete (point) "A")
  5567. (buffer-string))))
  5568. ;; Also remove accumulated properties.
  5569. (should-not
  5570. (string-match
  5571. ":A"
  5572. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B: 3\n:END:"
  5573. (org-entry-delete (point) "A")
  5574. (buffer-string))))
  5575. ;; When last property is removed, remove the property drawer.
  5576. (should-not
  5577. (string-match
  5578. ":PROPERTIES:"
  5579. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\nParagraph"
  5580. (org-entry-delete (point) "A")
  5581. (buffer-string))))
  5582. ;; Return a non-nil value when some property was removed.
  5583. (should
  5584. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5585. (org-entry-delete (point) "A")))
  5586. (should-not
  5587. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  5588. (org-entry-delete (point) "C")))
  5589. ;; Special properties cannot be located in a drawer. Allow to
  5590. ;; remove them anyway, in case of user error.
  5591. (should
  5592. (org-test-with-temp-text "* H\n:PROPERTIES:\n:SCHEDULED: 1\n:END:"
  5593. (org-entry-delete (point) "SCHEDULED"))))
  5594. (ert-deftest test-org/entry-get ()
  5595. "Test `org-entry-get' specifications."
  5596. ;; Regular test.
  5597. (should
  5598. (equal "1"
  5599. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:"
  5600. (org-entry-get (point) "A"))))
  5601. (should
  5602. (equal "1"
  5603. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5604. (org-entry-get (point) "A"))))
  5605. ;; Ignore case.
  5606. (should
  5607. (equal "1"
  5608. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5609. (org-entry-get (point) "a"))))
  5610. ;; Handle extended values, both before and after base value.
  5611. (should
  5612. (equal "1 2 3"
  5613. (org-test-with-temp-text
  5614. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5615. (org-entry-get (point) "A"))))
  5616. ;; Empty values are returned as the empty string.
  5617. (should
  5618. (equal ""
  5619. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A:\n:END:"
  5620. (org-entry-get (point) "A"))))
  5621. ;; Special nil value. If LITERAL-NIL is non-nil, return "nil",
  5622. ;; otherwise, return nil.
  5623. (should-not
  5624. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5625. (org-entry-get (point) "A")))
  5626. (should
  5627. (equal "nil"
  5628. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: nil\n:END:"
  5629. (org-entry-get (point) "A" nil t))))
  5630. ;; Return nil when no property is found, independently on the
  5631. ;; LITERAL-NIL argument.
  5632. (should-not
  5633. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5634. (org-entry-get (point) "B")))
  5635. (should-not
  5636. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5637. (org-entry-get (point) "B" nil t)))
  5638. ;; Handle inheritance, when allowed. Include extended values and
  5639. ;; possibly global values.
  5640. (should
  5641. (equal
  5642. "1"
  5643. (org-test-with-temp-text ":PROPERTIES:\n:A: 1\n:END:\n* H"
  5644. (org-entry-get (point-max) "A" t))))
  5645. (should
  5646. (equal
  5647. "1"
  5648. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5649. (org-entry-get (point-max) "A" t))))
  5650. (should
  5651. (equal
  5652. "1"
  5653. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5654. (let ((org-use-property-inheritance t))
  5655. (org-entry-get (point-max) "A" 'selective)))))
  5656. (should-not
  5657. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2"
  5658. (let ((org-use-property-inheritance nil))
  5659. (org-entry-get (point-max) "A" 'selective))))
  5660. (should
  5661. (equal
  5662. "1 2"
  5663. (org-test-with-temp-text
  5664. ":PROPERTIES:\n:A: 1\n:END:\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5665. (org-entry-get (point-max) "A" t))))
  5666. (should
  5667. (equal
  5668. "1 2"
  5669. (org-test-with-temp-text
  5670. "* H\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5671. (org-entry-get (point-max) "A" t))))
  5672. (should
  5673. (equal
  5674. "1 2"
  5675. (org-test-with-temp-text
  5676. ":PROPERTIES:\n:A: 1\n:END:\n* H1\n* H2\n:PROPERTIES:\n:A+: 2\n:END:"
  5677. (org-entry-get (point-max) "A" t))))
  5678. (should
  5679. (equal
  5680. "1 2"
  5681. (org-test-with-temp-text
  5682. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n* H2.1\n* H2.2\n:PROPERTIES:\n:A+: 2\n:END:"
  5683. (org-entry-get (point-max) "A" t))))
  5684. (should
  5685. (equal "1"
  5686. (org-test-with-temp-text
  5687. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A: 1\n:END:"
  5688. (org-mode-restart)
  5689. (org-entry-get (point-max) "A" t))))
  5690. (should
  5691. (equal "0 1"
  5692. (org-test-with-temp-text
  5693. "#+PROPERTY: A 0\n* H\n:PROPERTIES:\n:A+: 1\n:END:"
  5694. (org-mode-restart)
  5695. (org-entry-get (point-max) "A" t))))
  5696. ;; document level property-drawer has precedance over
  5697. ;; global-property by PROPERTY-keyword.
  5698. (should
  5699. (equal "0 2"
  5700. (org-test-with-temp-text
  5701. ":PROPERTIES:\n:A: 0\n:END:\n#+PROPERTY: A 1\n* H\n:PROPERTIES:\n:A+: 2\n:END:"
  5702. (org-mode-restart)
  5703. (org-entry-get (point-max) "A" t)))))
  5704. (ert-deftest test-org/entry-properties ()
  5705. "Test `org-entry-properties' specifications."
  5706. ;; Get "ITEM" property.
  5707. (should
  5708. (equal "H"
  5709. (org-test-with-temp-text "* TODO H"
  5710. (cdr (assoc "ITEM" (org-entry-properties nil "ITEM"))))))
  5711. (should
  5712. (equal "H"
  5713. (org-test-with-temp-text "* TODO H"
  5714. (cdr (assoc "ITEM" (org-entry-properties))))))
  5715. ;; Get "TODO" property. TODO keywords are case sensitive.
  5716. (should
  5717. (equal "TODO"
  5718. (org-test-with-temp-text "* TODO H"
  5719. (cdr (assoc "TODO" (org-entry-properties nil "TODO"))))))
  5720. (should
  5721. (equal "TODO"
  5722. (org-test-with-temp-text "* TODO H"
  5723. (cdr (assoc "TODO" (org-entry-properties))))))
  5724. (should-not
  5725. (org-test-with-temp-text "* H"
  5726. (assoc "TODO" (org-entry-properties nil "TODO"))))
  5727. (should-not
  5728. (org-test-with-temp-text "* todo H"
  5729. (assoc "TODO" (org-entry-properties nil "TODO"))))
  5730. ;; Get "PRIORITY" property.
  5731. (should
  5732. (equal "A"
  5733. (org-test-with-temp-text "* [#A] H"
  5734. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  5735. (should
  5736. (equal "A"
  5737. (org-test-with-temp-text "* [#A] H"
  5738. (cdr (assoc "PRIORITY" (org-entry-properties))))))
  5739. (should
  5740. (equal (char-to-string org-priority-default)
  5741. (org-test-with-temp-text "* H"
  5742. (cdr (assoc "PRIORITY" (org-entry-properties nil "PRIORITY"))))))
  5743. ;; Get "FILE" property.
  5744. (should
  5745. (org-test-with-temp-text-in-file "* H\nParagraph"
  5746. (file-equal-p (cdr (assoc "FILE" (org-entry-properties nil "FILE")))
  5747. (buffer-file-name))))
  5748. (should
  5749. (org-test-with-temp-text-in-file "* H\nParagraph"
  5750. (file-equal-p (cdr (assoc "FILE" (org-entry-properties)))
  5751. (buffer-file-name))))
  5752. (should-not
  5753. (org-test-with-temp-text "* H\nParagraph"
  5754. (cdr (assoc "FILE" (org-entry-properties nil "FILE")))))
  5755. ;; Get "TAGS" property.
  5756. (should
  5757. (equal ":tag1:tag2:"
  5758. (org-test-with-temp-text "* H :tag1:tag2:"
  5759. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS"))))))
  5760. (should
  5761. (equal ":tag1:tag2:"
  5762. (org-test-with-temp-text "* H :tag1:tag2:"
  5763. (cdr (assoc "TAGS" (org-entry-properties))))))
  5764. (should-not
  5765. (org-test-with-temp-text "* H"
  5766. (cdr (assoc "TAGS" (org-entry-properties nil "TAGS")))))
  5767. ;; Get "ALLTAGS" property.
  5768. (should
  5769. (equal ":tag1:tag2:"
  5770. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  5771. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS"))))))
  5772. (should
  5773. (equal ":tag1:tag2:"
  5774. (org-test-with-temp-text "* H :tag1:\n<point>** H2 :tag2:"
  5775. (cdr (assoc "ALLTAGS" (org-entry-properties))))))
  5776. (should-not
  5777. (org-test-with-temp-text "* H"
  5778. (cdr (assoc "ALLTAGS" (org-entry-properties nil "ALLTAGS")))))
  5779. ;; Get "BLOCKED" property.
  5780. (should
  5781. (equal "t"
  5782. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** TODO two"
  5783. (let ((org-enforce-todo-dependencies t)
  5784. (org-blocker-hook
  5785. '(org-block-todo-from-children-or-siblings-or-parent)))
  5786. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  5787. (should
  5788. (equal ""
  5789. (org-test-with-temp-text "* TODO Blocked\n** DONE one\n** DONE two"
  5790. (let ((org-enforce-todo-dependencies t)
  5791. (org-blocker-hook
  5792. '(org-block-todo-from-children-or-siblings-or-parent)))
  5793. (cdr (assoc "BLOCKED" (org-entry-properties nil "BLOCKED")))))))
  5794. ;; Get "CLOSED", "DEADLINE" and "SCHEDULED" properties.
  5795. (should
  5796. (equal
  5797. "[2012-03-29 thu.]"
  5798. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  5799. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED"))))))
  5800. (should
  5801. (equal
  5802. "[2012-03-29 thu.]"
  5803. (org-test-with-temp-text "* H\nCLOSED: [2012-03-29 thu.]"
  5804. (cdr (assoc "CLOSED" (org-entry-properties))))))
  5805. (should-not
  5806. (org-test-with-temp-text "* H"
  5807. (cdr (assoc "CLOSED" (org-entry-properties nil "CLOSED")))))
  5808. (should
  5809. (equal
  5810. "<2014-03-04 tue.>"
  5811. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5812. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE"))))))
  5813. (should
  5814. (equal
  5815. "<2014-03-04 tue.>"
  5816. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5817. (cdr (assoc "DEADLINE" (org-entry-properties))))))
  5818. (should-not
  5819. (org-test-with-temp-text "* H"
  5820. (cdr (assoc "DEADLINE" (org-entry-properties nil "DEADLINE")))))
  5821. (should
  5822. (equal
  5823. "<2014-03-04 tue.>"
  5824. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5825. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED"))))))
  5826. (should
  5827. (equal
  5828. "<2014-03-04 tue.>"
  5829. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5830. (cdr (assoc "SCHEDULED" (org-entry-properties))))))
  5831. (should-not
  5832. (org-test-with-temp-text "* H"
  5833. (cdr (assoc "SCHEDULED" (org-entry-properties nil "SCHEDULED")))))
  5834. ;; Get "CATEGORY"
  5835. (should
  5836. (equal "cat"
  5837. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  5838. (cdr (assoc "CATEGORY" (org-entry-properties))))))
  5839. (should
  5840. (equal "cat"
  5841. (org-test-with-temp-text "#+CATEGORY: cat\n<point>* H"
  5842. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5843. (should
  5844. (equal "cat"
  5845. (org-test-with-temp-text "* H\n:PROPERTIES:\n:CATEGORY: cat\n:END:"
  5846. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5847. (should
  5848. (equal "cat2"
  5849. (org-test-with-temp-text
  5850. (concat "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  5851. "\n"
  5852. "** H2\n:PROPERTIES:\n:CATEGORY: cat2\n:END:<point>")
  5853. (cdr (assoc "CATEGORY" (org-entry-properties nil "CATEGORY"))))))
  5854. ;; Get "TIMESTAMP" and "TIMESTAMP_IA" properties.
  5855. (should
  5856. (equal "<2012-03-29 thu.>"
  5857. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>"
  5858. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  5859. (should
  5860. (equal "[2012-03-29 thu.]"
  5861. (org-test-with-temp-text "* Entry\n[2012-03-29 thu.]"
  5862. (cdr (assoc "TIMESTAMP_IA" (org-entry-properties))))))
  5863. (should
  5864. (equal "<2012-03-29 thu.>"
  5865. (org-test-with-temp-text "* Entry\n[2014-03-04 tue.]<2012-03-29 thu.>"
  5866. (cdr (assoc "TIMESTAMP" (org-entry-properties nil "TIMESTAMP"))))))
  5867. (should
  5868. (equal "[2014-03-04 tue.]"
  5869. (org-test-with-temp-text "* Entry\n<2012-03-29 thu.>[2014-03-04 tue.]"
  5870. (cdr (assoc "TIMESTAMP_IA"
  5871. (org-entry-properties nil "TIMESTAMP_IA"))))))
  5872. (should-not
  5873. (equal "<2012-03-29 thu.>"
  5874. (org-test-with-temp-text "* Current\n* Next\n<2012-03-29 thu.>"
  5875. (cdr (assoc "TIMESTAMP" (org-entry-properties))))))
  5876. ;; Get standard properties.
  5877. (should
  5878. (equal "1"
  5879. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5880. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5881. ;; Handle extended properties.
  5882. (should
  5883. (equal "1 2 3"
  5884. (org-test-with-temp-text
  5885. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:A+: 3\n:END:"
  5886. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5887. (should
  5888. (equal "1 2 3"
  5889. (org-test-with-temp-text
  5890. "* H\n:PROPERTIES:\n:A+: 2\n:A: 1\n:a+: 3\n:END:"
  5891. (cdr (assoc "A" (org-entry-properties nil 'standard))))))
  5892. ;; Ignore forbidden (special) properties.
  5893. (should-not
  5894. (org-test-with-temp-text "* H\n:PROPERTIES:\n:TODO: foo\n:END:"
  5895. (cdr (assoc "TODO" (org-entry-properties nil 'standard))))))
  5896. (ert-deftest test-org/entry-put ()
  5897. "Test `org-entry-put' specifications."
  5898. ;; Error when not a string or nil.
  5899. (should-error
  5900. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5901. (org-entry-put 1 "test" 2)))
  5902. ;; Error when property name is invalid.
  5903. (should-error
  5904. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5905. (org-entry-put 1 "no space" "value")))
  5906. (should-error
  5907. (org-test-with-temp-text "* H\n:PROPERTIES:\n:test: 1\n:END:"
  5908. (org-entry-put 1 "" "value")))
  5909. ;; Set "TODO" property.
  5910. (should
  5911. (string-match (regexp-quote " TODO H")
  5912. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  5913. (org-entry-put (point) "TODO" "TODO")
  5914. (buffer-string))))
  5915. (should
  5916. (string-match (regexp-quote "* H")
  5917. (org-test-with-temp-text "#+TODO: TODO | DONE\n<point>* H"
  5918. (org-entry-put (point) "TODO" nil)
  5919. (buffer-string))))
  5920. ;; Set "PRIORITY" property.
  5921. (should
  5922. (equal "* [#A] H"
  5923. (org-test-with-temp-text "* [#B] H"
  5924. (org-entry-put (point) "PRIORITY" "A")
  5925. (buffer-string))))
  5926. (should
  5927. (equal "* H"
  5928. (org-test-with-temp-text "* [#B] H"
  5929. (org-entry-put (point) "PRIORITY" nil)
  5930. (buffer-string))))
  5931. ;; Set "SCHEDULED" property.
  5932. (should
  5933. (string-match "* H\n *SCHEDULED: <2014-03-04 .*?>"
  5934. (org-test-with-temp-text "* H"
  5935. (org-entry-put (point) "SCHEDULED" "2014-03-04")
  5936. (buffer-string))))
  5937. (should
  5938. (string= "* H\n"
  5939. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5940. (org-entry-put (point) "SCHEDULED" nil)
  5941. (buffer-string))))
  5942. (should
  5943. (string-match "* H\n *SCHEDULED: <2014-03-03 .*?>"
  5944. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5945. (org-entry-put (point) "SCHEDULED" "earlier")
  5946. (buffer-string))))
  5947. (should
  5948. (string-match "^ *SCHEDULED: <2014-03-05 .*?>"
  5949. (org-test-with-temp-text "* H\nSCHEDULED: <2014-03-04 tue.>"
  5950. (org-entry-put (point) "SCHEDULED" "later")
  5951. (buffer-string))))
  5952. ;; Set "DEADLINE" property.
  5953. (should
  5954. (string-match "^ *DEADLINE: <2014-03-04 .*?>"
  5955. (org-test-with-temp-text "* H"
  5956. (org-entry-put (point) "DEADLINE" "2014-03-04")
  5957. (buffer-string))))
  5958. (should
  5959. (string= "* H\n"
  5960. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5961. (org-entry-put (point) "DEADLINE" nil)
  5962. (buffer-string))))
  5963. (should
  5964. (string-match "^ *DEADLINE: <2014-03-03 .*?>"
  5965. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5966. (org-entry-put (point) "DEADLINE" "earlier")
  5967. (buffer-string))))
  5968. (should
  5969. (string-match "^ *DEADLINE: <2014-03-05 .*?>"
  5970. (org-test-with-temp-text "* H\nDEADLINE: <2014-03-04 tue.>"
  5971. (org-entry-put (point) "DEADLINE" "later")
  5972. (buffer-string))))
  5973. ;; Set "CATEGORY" property
  5974. (should
  5975. (string-match "^ *:CATEGORY: cat"
  5976. (org-test-with-temp-text "* H"
  5977. (org-entry-put (point) "CATEGORY" "cat")
  5978. (buffer-string))))
  5979. ;; Regular properties, with or without pre-existing drawer.
  5980. (should
  5981. (string-match "^ *:A: +2$"
  5982. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  5983. (org-entry-put (point) "A" "2")
  5984. (buffer-string))))
  5985. (should
  5986. (string-match "^ *:A: +1$"
  5987. (org-test-with-temp-text "* H"
  5988. (org-entry-put (point) "A" "1")
  5989. (buffer-string))))
  5990. ;; Special case: two consecutive headlines.
  5991. (should
  5992. (string-match "\\* A\n *:PROPERTIES:"
  5993. (org-test-with-temp-text "* A\n** B"
  5994. (org-entry-put (point) "A" "1")
  5995. (buffer-string)))))
  5996. (ert-deftest test-org/refresh-properties ()
  5997. "Test `org-refresh-properties' specifications."
  5998. (should
  5999. (equal "1"
  6000. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6001. (org-refresh-properties "A" 'org-test)
  6002. (get-text-property (point) 'org-test))))
  6003. (should-not
  6004. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  6005. (org-refresh-properties "B" 'org-test)
  6006. (get-text-property (point) 'org-test)))
  6007. ;; Handle properties only defined with extension syntax, i.e.,
  6008. ;; "PROPERTY+".
  6009. (should
  6010. (equal "1"
  6011. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A+: 1\n:END:"
  6012. (org-refresh-properties "A" 'org-test)
  6013. (get-text-property (point) 'org-test))))
  6014. ;; When property is inherited, add text property to the whole
  6015. ;; sub-tree.
  6016. (should
  6017. (equal "1"
  6018. (org-test-with-temp-text
  6019. "* H1\n:PROPERTIES:\n:A: 1\n:END:\n<point>** H2"
  6020. (let ((org-use-property-inheritance t))
  6021. (org-refresh-properties "A" 'org-test))
  6022. (get-text-property (point) 'org-test))))
  6023. ;; When a document level property-drawer is used, those properties
  6024. ;; should work exactly like headline-properties as if at a
  6025. ;; headline-level 0.
  6026. (should
  6027. (equal "1"
  6028. (org-test-with-temp-text
  6029. ":PROPERTIES:\n:A: 1\n:END:\n"
  6030. (org-mode-restart)
  6031. (let ((org-use-property-inheritance t))
  6032. (org-refresh-properties "A" 'org-test))
  6033. (get-text-property (point) 'org-test))))
  6034. (should-not
  6035. (equal "1"
  6036. (org-test-with-temp-text
  6037. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  6038. (org-mode-restart)
  6039. (let ((org-use-property-inheritance nil))
  6040. (org-refresh-properties "A" 'org-test))
  6041. (get-text-property (point) 'org-test))))
  6042. (should
  6043. (equal "1"
  6044. (org-test-with-temp-text
  6045. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1"
  6046. (org-mode-restart)
  6047. (let ((org-use-property-inheritance t))
  6048. (org-refresh-properties "A" 'org-test))
  6049. (get-text-property (point) 'org-test))))
  6050. (should
  6051. (equal "2"
  6052. (org-test-with-temp-text
  6053. ":PROPERTIES:\n:A: 1\n:END:\n<point>* H1\n:PROPERTIES:\n:A: 2\n:END:"
  6054. (org-mode-restart)
  6055. (let ((org-use-property-inheritance t))
  6056. (org-refresh-properties "A" 'org-test))
  6057. (get-text-property (point) 'org-test))))
  6058. ;; When property is inherited, use global value across the whole
  6059. ;; buffer. However local values have precedence, as well as the
  6060. ;; document level property-drawer.
  6061. (should-not
  6062. (equal "1"
  6063. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  6064. (org-mode-restart)
  6065. (let ((org-use-property-inheritance nil))
  6066. (org-refresh-properties "A" 'org-test))
  6067. (get-text-property (point) 'org-test))))
  6068. (should
  6069. (equal "1"
  6070. (org-test-with-temp-text "#+PROPERTY: A 1\n<point>* H1"
  6071. (org-mode-restart)
  6072. (let ((org-use-property-inheritance t))
  6073. (org-refresh-properties "A" 'org-test))
  6074. (get-text-property (point) 'org-test))))
  6075. (should
  6076. (equal "2"
  6077. (org-test-with-temp-text
  6078. "#+PROPERTY: A 1\n<point>* H\n:PROPERTIES:\n:A: 2\n:END:"
  6079. (org-mode-restart)
  6080. (let ((org-use-property-inheritance t))
  6081. (org-refresh-properties "A" 'org-test))
  6082. (get-text-property (point) 'org-test))))
  6083. ;; When both keyword-property and document-level property-block is
  6084. ;; defined, the property-block has precedance.
  6085. (should
  6086. (equal "1"
  6087. (org-test-with-temp-text
  6088. ":PROPERTIES:\n:A: 1\n:END:\n#+PROPERTY: A 2\n<point>* H1"
  6089. (org-mode-restart)
  6090. (let ((org-use-property-inheritance t))
  6091. (org-refresh-properties "A" 'org-test))
  6092. (get-text-property (point) 'org-test)))))
  6093. (ert-deftest test-org/refresh-category-properties ()
  6094. "Test `org-refresh-category-properties' specifications"
  6095. (should
  6096. (equal "cat1"
  6097. (org-test-with-temp-text
  6098. ":PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6099. (org-refresh-category-properties)
  6100. (get-text-property (point) 'org-category))))
  6101. (should
  6102. (equal "cat1"
  6103. (org-test-with-temp-text
  6104. "* H\n:PROPERTIES:\n:CATEGORY: cat1\n:END:"
  6105. (org-refresh-category-properties)
  6106. (get-text-property (point) 'org-category))))
  6107. ;; Even though property-inheritance is deactivated, category
  6108. ;; property should be inherited. As described in
  6109. ;; `org-use-property-inheritance'.
  6110. (should
  6111. (equal "cat1"
  6112. (org-test-with-temp-text
  6113. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  6114. (org-mode-restart)
  6115. (let ((org-use-property-inheritance nil))
  6116. (org-refresh-category-properties))
  6117. (get-text-property (point) 'org-category))))
  6118. (should
  6119. (equal "cat1"
  6120. (org-test-with-temp-text
  6121. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H"
  6122. (org-mode-restart)
  6123. (let ((org-use-property-inheritance t))
  6124. (org-refresh-category-properties))
  6125. (get-text-property (point) 'org-category))))
  6126. (should
  6127. (equal "cat2"
  6128. (org-test-with-temp-text
  6129. ":PROPERTIES:\n:CATEGORY: cat1\n:END:\n<point>* H\n:PROPERTIES:\n:CATEGORY: cat2\n:END:\n"
  6130. (org-mode-restart)
  6131. (let ((org-use-property-inheritance t))
  6132. (org-refresh-category-properties))
  6133. (get-text-property (point) 'org-category)))))
  6134. ;;; Refile
  6135. (ert-deftest test-org/refile-get-targets ()
  6136. "Test `org-refile-get-targets' specifications."
  6137. ;; :maxlevel includes all headings above specified value.
  6138. (should
  6139. (equal '("H1" "H2" "H3")
  6140. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6141. (let ((org-refile-use-outline-path nil)
  6142. (org-refile-targets `((nil :maxlevel . 3))))
  6143. (mapcar #'car (org-refile-get-targets))))))
  6144. (should
  6145. (equal '("H1" "H2")
  6146. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6147. (let ((org-refile-use-outline-path nil)
  6148. (org-refile-targets `((nil :maxlevel . 2))))
  6149. (mapcar #'car (org-refile-get-targets))))))
  6150. ;; :level limits targets to headlines with the specified level.
  6151. (should
  6152. (equal '("H2")
  6153. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6154. (let ((org-refile-use-outline-path nil)
  6155. (org-refile-targets `((nil :level . 2))))
  6156. (mapcar #'car (org-refile-get-targets))))))
  6157. ;; :tag limits targets to headlines with specified tag.
  6158. (should
  6159. (equal '("H1")
  6160. (org-test-with-temp-text "* H1 :foo:\n** H2\n*** H3 :bar:"
  6161. (let ((org-refile-use-outline-path nil)
  6162. (org-refile-targets `((nil :tag . "foo"))))
  6163. (mapcar #'car (org-refile-get-targets))))))
  6164. ;; :todo limits targets to headlines with specified TODO keyword.
  6165. (should
  6166. (equal '("H2")
  6167. (org-test-with-temp-text "* H1\n** TODO H2\n*** DONE H3"
  6168. (let ((org-refile-use-outline-path nil)
  6169. (org-refile-targets `((nil :todo . "TODO"))))
  6170. (mapcar #'car (org-refile-get-targets))))))
  6171. ;; :regexp filters targets matching provided regexp.
  6172. (should
  6173. (equal '("F2" "F3")
  6174. (org-test-with-temp-text "* H1\n** F2\n*** F3"
  6175. (let ((org-refile-use-outline-path nil)
  6176. (org-refile-targets `((nil :regexp . "F"))))
  6177. (mapcar #'car (org-refile-get-targets))))))
  6178. ;; A nil `org-refile-targets' includes only top level headlines in
  6179. ;; current buffer.
  6180. (should
  6181. (equal '("H1" "H2")
  6182. (org-test-with-temp-text "* H1\n** S1\n* H2"
  6183. (let ((org-refile-use-outline-path nil)
  6184. (org-refile-targets nil))
  6185. (mapcar #'car (org-refile-get-targets))))))
  6186. ;; Return value is the union of the targets according to all the
  6187. ;; defined rules. However, prevent duplicates.
  6188. (should
  6189. (equal '("F2" "F3" "H1")
  6190. (org-test-with-temp-text "* TODO H1\n** F2\n*** F3"
  6191. (let ((org-refile-use-outline-path nil)
  6192. (org-refile-targets `((nil :regexp . "F")
  6193. (nil :todo . "TODO"))))
  6194. (mapcar #'car (org-refile-get-targets))))))
  6195. (should
  6196. (equal '("F2" "F3" "H1")
  6197. (org-test-with-temp-text "* TODO H1\n** TODO F2\n*** F3"
  6198. (let ((org-refile-use-outline-path nil)
  6199. (org-refile-targets `((nil :regexp . "F")
  6200. (nil :todo . "TODO"))))
  6201. (mapcar #'car (org-refile-get-targets))))))
  6202. ;; When `org-refile-use-outline-path' is non-nil, provide targets as
  6203. ;; paths.
  6204. (should
  6205. (equal '("H1" "H1/H2" "H1/H2/H3")
  6206. (org-test-with-temp-text "* H1\n** H2\n*** H3"
  6207. (let ((org-refile-use-outline-path t)
  6208. (org-refile-targets `((nil :maxlevel . 3))))
  6209. (mapcar #'car (org-refile-get-targets))))))
  6210. ;; When providing targets as paths, escape forward slashes in
  6211. ;; headings with backslashes.
  6212. (should
  6213. (equal '("H1\\/foo")
  6214. (org-test-with-temp-text "* H1/foo"
  6215. (let ((org-refile-use-outline-path t)
  6216. (org-refile-targets `((nil :maxlevel . 1))))
  6217. (mapcar #'car (org-refile-get-targets))))))
  6218. ;; When `org-refile-use-outline-path' is `file', include file name
  6219. ;; without directory in targets.
  6220. (should
  6221. (org-test-with-temp-text-in-file "* H1"
  6222. (let* ((filename (buffer-file-name))
  6223. (org-refile-use-outline-path 'file)
  6224. (org-refile-targets `(((,filename) :level . 1))))
  6225. (member (file-name-nondirectory filename)
  6226. (mapcar #'car (org-refile-get-targets))))))
  6227. ;; When `org-refile-use-outline-path' is `full-file-path', include
  6228. ;; full file name.
  6229. (should
  6230. (org-test-with-temp-text-in-file "* H1"
  6231. (let* ((filename (file-truename (buffer-file-name)))
  6232. (org-refile-use-outline-path 'full-file-path)
  6233. (org-refile-targets `(((,filename) :level . 1))))
  6234. (member filename (mapcar #'car (org-refile-get-targets))))))
  6235. ;; When `org-refile-use-outline-path' is `buffer-name', include
  6236. ;; buffer name.
  6237. (should
  6238. (org-test-with-temp-text "* H1"
  6239. (let* ((org-refile-use-outline-path 'buffer-name)
  6240. (org-refile-targets `((nil :level . 1))))
  6241. (member (buffer-name) (mapcar #'car (org-refile-get-targets)))))))
  6242. ;;; Sparse trees
  6243. (ert-deftest test-org/match-sparse-tree ()
  6244. "Test `org-match-sparse-tree' specifications."
  6245. ;; Match tags.
  6246. (should-not
  6247. (org-test-with-temp-text "* H\n** H1 :tag:"
  6248. (org-match-sparse-tree nil "tag")
  6249. (search-forward "H1")
  6250. (org-invisible-p2)))
  6251. (should
  6252. (org-test-with-temp-text "* H\n** H1 :tag:\n** H2 :tag2:"
  6253. (org-match-sparse-tree nil "tag")
  6254. (search-forward "H2")
  6255. (org-invisible-p2)))
  6256. ;; "-" operator for tags.
  6257. (should-not
  6258. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6259. (org-match-sparse-tree nil "tag1-tag2")
  6260. (search-forward "H1")
  6261. (org-invisible-p2)))
  6262. (should
  6263. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6264. (org-match-sparse-tree nil "tag1-tag2")
  6265. (search-forward "H2")
  6266. (org-invisible-p2)))
  6267. ;; "&" operator for tags.
  6268. (should
  6269. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6270. (org-match-sparse-tree nil "tag1&tag2")
  6271. (search-forward "H1")
  6272. (org-invisible-p2)))
  6273. (should-not
  6274. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6275. (org-match-sparse-tree nil "tag1&tag2")
  6276. (search-forward "H2")
  6277. (org-invisible-p2)))
  6278. ;; "|" operator for tags.
  6279. (should-not
  6280. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6281. (org-match-sparse-tree nil "tag1|tag2")
  6282. (search-forward "H1")
  6283. (org-invisible-p2)))
  6284. (should-not
  6285. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :tag1:tag2:"
  6286. (org-match-sparse-tree nil "tag1|tag2")
  6287. (search-forward "H2")
  6288. (org-invisible-p2)))
  6289. ;; Regexp match on tags.
  6290. (should-not
  6291. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6292. (org-match-sparse-tree nil "{^tag.*}")
  6293. (search-forward "H1")
  6294. (org-invisible-p2)))
  6295. (should
  6296. (org-test-with-temp-text "* H\n** H1 :tag1:\n** H2 :foo:"
  6297. (org-match-sparse-tree nil "{^tag.*}")
  6298. (search-forward "H2")
  6299. (org-invisible-p2)))
  6300. ;; Match group tags.
  6301. (should-not
  6302. (org-test-with-temp-text
  6303. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6304. (org-match-sparse-tree nil "work")
  6305. (search-forward "H1")
  6306. (org-invisible-p2)))
  6307. (should-not
  6308. (org-test-with-temp-text
  6309. "#+TAGS: { work : lab }\n* H\n** H1 :work:\n** H2 :lab:"
  6310. (org-match-sparse-tree nil "work")
  6311. (search-forward "H2")
  6312. (org-invisible-p2)))
  6313. ;; Match group tags with hard brackets.
  6314. (should-not
  6315. (org-test-with-temp-text
  6316. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6317. (org-match-sparse-tree nil "work")
  6318. (search-forward "H1")
  6319. (org-invisible-p2)))
  6320. (should-not
  6321. (org-test-with-temp-text
  6322. "#+TAGS: [ work : lab ]\n* H\n** H1 :work:\n** H2 :lab:"
  6323. (org-match-sparse-tree nil "work")
  6324. (search-forward "H2")
  6325. (org-invisible-p2)))
  6326. ;; Match tags in hierarchies
  6327. (should-not
  6328. (org-test-with-temp-text
  6329. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6330. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6331. #+TAGS: { Lev_3 : Lev_4 }\n
  6332. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6333. (org-match-sparse-tree nil "Lev_1")
  6334. (search-forward "H4")
  6335. (org-invisible-p2)))
  6336. (should-not
  6337. (org-test-with-temp-text
  6338. "#+TAGS: [ Lev_1 : Lev_2 ]\n
  6339. #+TAGS: [ Lev_2 : Lev_3 ]\n
  6340. #+TAGS: { Lev_3 : Lev_4 }\n
  6341. * H\n** H1 :Lev_1:\n** H2 :Lev_2:\n** H3 :Lev_3:\n** H4 :Lev_4:"
  6342. (org-match-sparse-tree nil "Lev_1+Lev_3")
  6343. (search-forward "H4")
  6344. (org-invisible-p2)))
  6345. ;; Match regular expressions in tags
  6346. (should-not
  6347. (org-test-with-temp-text
  6348. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_1:"
  6349. (org-match-sparse-tree nil "Lev")
  6350. (search-forward "H1")
  6351. (org-invisible-p2)))
  6352. (should
  6353. (org-test-with-temp-text
  6354. "#+TAGS: [ Lev : {Lev_[0-9]} ]\n* H\n** H1 :Lev_n:"
  6355. (org-match-sparse-tree nil "Lev")
  6356. (search-forward "H1")
  6357. (org-invisible-p2)))
  6358. ;; Match properties.
  6359. (should
  6360. (org-test-with-temp-text
  6361. "* H\n** H1\n:PROPERTIES:\n:A: 1\n:END:\n** H2\n:PROPERTIES:\n:A: 2\n:END:"
  6362. (org-match-sparse-tree nil "A=\"1\"")
  6363. (search-forward "H2")
  6364. (org-invisible-p2)))
  6365. (should-not
  6366. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6367. (org-match-sparse-tree nil "A=\"1\"")
  6368. (search-forward "H2")
  6369. (org-invisible-p2)))
  6370. ;; Case is not significant when matching properties.
  6371. (should-not
  6372. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:A: 1\n:END:"
  6373. (org-match-sparse-tree nil "a=\"1\"")
  6374. (search-forward "H2")
  6375. (org-invisible-p2)))
  6376. (should-not
  6377. (org-test-with-temp-text "* H1\n** H2\n:PROPERTIES:\n:a: 1\n:END:"
  6378. (org-match-sparse-tree nil "A=\"1\"")
  6379. (search-forward "H2")
  6380. (org-invisible-p2)))
  6381. ;; Match special LEVEL property.
  6382. (should-not
  6383. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6384. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6385. (search-forward "H1")
  6386. (org-invisible-p2)))
  6387. (should
  6388. (org-test-with-temp-text "* H\n** H1\n*** H2"
  6389. (let ((org-odd-levels-only nil)) (org-match-sparse-tree nil "LEVEL=2"))
  6390. (search-forward "H2")
  6391. (org-invisible-p2)))
  6392. ;; Comparison operators when matching properties.
  6393. (should
  6394. (org-test-with-temp-text
  6395. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6396. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6397. (search-forward "H1")
  6398. (org-invisible-p2)))
  6399. (should-not
  6400. (org-test-with-temp-text
  6401. "* H\n** H1\nSCHEDULED: <2014-03-04 tue.>\n** H2\nSCHEDULED: <2012-03-29 thu.>"
  6402. (org-match-sparse-tree nil "SCHEDULED<=\"<2013-01-01>\"")
  6403. (search-forward "H2")
  6404. (org-invisible-p2)))
  6405. ;; Regexp match on properties values.
  6406. (should-not
  6407. (org-test-with-temp-text
  6408. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6409. (org-match-sparse-tree nil "A={f.*}")
  6410. (search-forward "H1")
  6411. (org-invisible-p2)))
  6412. (should
  6413. (org-test-with-temp-text
  6414. "* H\n** H1\n:PROPERTIES:\n:A: foo\n:END:\n** H2\n:PROPERTIES:\n:A: bar\n:END:"
  6415. (org-match-sparse-tree nil "A={f.*}")
  6416. (search-forward "H2")
  6417. (org-invisible-p2)))
  6418. ;; With an optional argument, limit match to TODO entries.
  6419. (should-not
  6420. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6421. (org-match-sparse-tree t "tag")
  6422. (search-forward "H1")
  6423. (org-invisible-p2)))
  6424. (should
  6425. (org-test-with-temp-text "* H\n** TODO H1 :tag:\n** H2 :tag:"
  6426. (org-match-sparse-tree t "tag")
  6427. (search-forward "H2")
  6428. (org-invisible-p2))))
  6429. (ert-deftest test-org/occur ()
  6430. "Test `org-occur' specifications."
  6431. ;; Count number of matches.
  6432. (should
  6433. (= 1
  6434. (org-test-with-temp-text "* H\nA\n* H2"
  6435. (org-occur "A"))))
  6436. (should
  6437. (= 2
  6438. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6439. (org-occur "A"))))
  6440. ;; Test CALLBACK optional argument.
  6441. (should
  6442. (= 0
  6443. (org-test-with-temp-text "* H\nA\n* H2"
  6444. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6445. (should
  6446. (= 1
  6447. (org-test-with-temp-text "* H\nA\n* H2\nA"
  6448. (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
  6449. ;; Case-fold searches according to `org-occur-case-fold-search'.
  6450. (should
  6451. (= 2
  6452. (org-test-with-temp-text "Aa"
  6453. (let ((org-occur-case-fold-search t)) (org-occur "A")))))
  6454. (should
  6455. (= 2
  6456. (org-test-with-temp-text "Aa"
  6457. (let ((org-occur-case-fold-search t)) (org-occur "a")))))
  6458. (should
  6459. (= 1
  6460. (org-test-with-temp-text "Aa"
  6461. (let ((org-occur-case-fold-search nil)) (org-occur "A")))))
  6462. (should
  6463. (= 1
  6464. (org-test-with-temp-text "Aa"
  6465. (let ((org-occur-case-fold-search nil)) (org-occur "a")))))
  6466. (should
  6467. (= 1
  6468. (org-test-with-temp-text "Aa"
  6469. (let ((org-occur-case-fold-search 'smart)) (org-occur "A")))))
  6470. (should
  6471. (= 2
  6472. (org-test-with-temp-text "Aa"
  6473. (let ((org-occur-case-fold-search 'smart)) (org-occur "a"))))))
  6474. ;;; Tags
  6475. (ert-deftest test-org/tag-string-to-alist ()
  6476. "Test `org-tag-string-to-alist' specifications."
  6477. ;; Tag without selection key.
  6478. (should (equal (org-tag-string-to-alist "tag1") '(("tag1"))))
  6479. ;; Tag with selection key.
  6480. (should (equal (org-tag-string-to-alist "tag1(t)") '(("tag1" . ?t))))
  6481. ;; Tag group.
  6482. (should
  6483. (equal
  6484. (org-tag-string-to-alist "[ group : t1 t2 ]")
  6485. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag))))
  6486. ;; Mutually exclusive tags.
  6487. (should (equal (org-tag-string-to-alist "{ tag1 tag2 }")
  6488. '((:startgroup) ("tag1") ("tag2") (:endgroup))))
  6489. (should
  6490. (equal
  6491. (org-tag-string-to-alist "{ group : tag1 tag2 }")
  6492. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))))
  6493. (ert-deftest test-org/tag-alist-to-string ()
  6494. "Test `org-tag-alist-to-string' specifications."
  6495. (should (equal (org-tag-alist-to-string '(("tag1"))) "tag1"))
  6496. (should (equal (org-tag-alist-to-string '(("tag1" . ?t))) "tag1(t)"))
  6497. (should
  6498. (equal
  6499. (org-tag-alist-to-string
  6500. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6501. "[ group : t1 t2 ]"))
  6502. (should
  6503. (equal (org-tag-alist-to-string
  6504. '((:startgroup) ("tag1") ("tag2") (:endgroup)))
  6505. "{ tag1 tag2 }"))
  6506. (should
  6507. (equal
  6508. (org-tag-alist-to-string
  6509. '((:startgroup) ("group") (:grouptags) ("tag1") ("tag2") (:endgroup)))
  6510. "{ group : tag1 tag2 }")))
  6511. (ert-deftest test-org/tag-alist-to-groups ()
  6512. "Test `org-tag-alist-to-groups' specifications."
  6513. (should
  6514. (equal (org-tag-alist-to-groups
  6515. '((:startgroup) ("group") (:grouptags) ("t1") ("t2") (:endgroup)))
  6516. '(("group" "t1" "t2"))))
  6517. (should
  6518. (equal
  6519. (org-tag-alist-to-groups
  6520. '((:startgrouptag) ("group") (:grouptags) ("t1") ("t2") (:endgrouptag)))
  6521. '(("group" "t1" "t2"))))
  6522. (should-not
  6523. (org-tag-alist-to-groups
  6524. '((:startgroup) ("group") ("t1") ("t2") (:endgroup)))))
  6525. (ert-deftest test-org/tag-align ()
  6526. "Test tags alignment."
  6527. ;; Test aligning tags with different display width.
  6528. (should
  6529. ;; 12345678901234567890
  6530. (equal "* Test :abc:"
  6531. (org-test-with-temp-text "* Test :abc:"
  6532. (let ((org-tags-column -20)
  6533. (indent-tabs-mode nil))
  6534. (org-fix-tags-on-the-fly))
  6535. (buffer-string))))
  6536. (should
  6537. ;; 12345678901234567890
  6538. (equal "* Test :日本語:"
  6539. (org-test-with-temp-text "* Test :日本語:"
  6540. (let ((org-tags-column -20)
  6541. (indent-tabs-mode nil))
  6542. (org-fix-tags-on-the-fly))
  6543. (buffer-string))))
  6544. ;; Make sure aligning tags do not skip invisible text.
  6545. (should
  6546. (equal "* [[linkx]] :tag:"
  6547. (org-test-with-temp-text "* [[link<point>]] :tag:"
  6548. (let ((org-tags-column 0))
  6549. (org-fix-tags-on-the-fly)
  6550. (insert "x")
  6551. (buffer-string)))))
  6552. ;; Aligning tags preserve position.
  6553. (should
  6554. (= 6 (org-test-with-temp-text "* 345 <point> :tag:"
  6555. (let ((org-tags-column 78)
  6556. (indent-tabs-mode nil))
  6557. (org-fix-tags-on-the-fly))
  6558. (current-column))))
  6559. ;; Aligning all tags in visible buffer.
  6560. (should
  6561. ;; 12345678901234567890
  6562. (equal (concat "* Level 1 :abc:\n"
  6563. "** Level 2 :def:")
  6564. (org-test-with-temp-text (concat "* Level 1 :abc:\n"
  6565. "** Level 2 :def:")
  6566. (let ((org-tags-column -20)
  6567. (indent-tabs-mode nil))
  6568. ;; (org-align-tags :all) must work even when the point
  6569. ;; is at the end of the buffer.
  6570. (goto-char (point-max))
  6571. (org-align-tags :all))
  6572. (buffer-string)))))
  6573. (ert-deftest test-org/get-tags ()
  6574. "Test `org-get-tags' specifications."
  6575. ;; Standard test.
  6576. (should
  6577. (equal '("foo")
  6578. (org-test-with-temp-text "* Test :foo:" (org-get-tags))))
  6579. (should
  6580. (equal '("foo" "bar")
  6581. (org-test-with-temp-text "* Test :foo:bar:" (org-get-tags))))
  6582. ;; Return nil when there is no tag.
  6583. (should-not
  6584. (org-test-with-temp-text "* Test" (org-get-tags)))
  6585. ;; Tags are inherited from parent headlines.
  6586. (should
  6587. (equal '("tag")
  6588. (let ((org-use-tag-inheritance t))
  6589. (org-test-with-temp-text "* H0 :foo:\n* H1 :tag:\n<point>** H2"
  6590. (org-get-tags)))))
  6591. ;; Tags are inherited from `org-file-tags'.
  6592. (should
  6593. (equal '("tag")
  6594. (org-test-with-temp-text "* H1"
  6595. (let ((org-file-tags '("tag"))
  6596. (org-use-tag-inheritance t))
  6597. (org-get-tags)))))
  6598. ;; Only inherited tags have the `inherited' text property.
  6599. (should
  6600. (get-text-property 0 'inherited
  6601. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6602. (let ((org-use-tag-inheritance t))
  6603. (assoc-string "foo" (org-get-tags))))))
  6604. (should-not
  6605. (get-text-property 0 'inherited
  6606. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6607. (let ((org-use-tag-inheritance t))
  6608. (assoc-string "bar" (org-get-tags))))))
  6609. ;; Obey to `org-use-tag-inheritance'.
  6610. (should-not
  6611. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6612. (let ((org-use-tag-inheritance nil))
  6613. (assoc-string "foo" (org-get-tags)))))
  6614. (should-not
  6615. (org-test-with-temp-text "* H1 :foo:\n** <point>H2 :bar:"
  6616. (let ((org-use-tag-inheritance nil)
  6617. (org-file-tags '("foo")))
  6618. (assoc-string "foo" (org-get-tags)))))
  6619. (should-not
  6620. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6621. (let ((org-use-tag-inheritance '("bar")))
  6622. (assoc-string "foo" (org-get-tags)))))
  6623. (should
  6624. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6625. (let ((org-use-tag-inheritance '("bar")))
  6626. (assoc-string "bar" (org-get-tags)))))
  6627. (should-not
  6628. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6629. (let ((org-use-tag-inheritance "b.*"))
  6630. (assoc-string "foo" (org-get-tags)))))
  6631. (should
  6632. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6633. (let ((org-use-tag-inheritance "b.*"))
  6634. (assoc-string "bar" (org-get-tags)))))
  6635. ;; When optional argument LOCAL is non-nil, ignore tag inheritance.
  6636. (should
  6637. (equal '("baz")
  6638. (org-test-with-temp-text "* H1 :foo:bar:\n** <point>H2 :baz:"
  6639. (let ((org-use-tag-inheritance t))
  6640. (org-get-tags nil t)))))
  6641. ;; When optional argument POS is non-nil, get tags there instead.
  6642. (should
  6643. (equal '("foo")
  6644. (org-test-with-temp-text "* H1 :foo:\n* <point>H2 :bar:"
  6645. (org-get-tags 1))))
  6646. ;; Make sure tags excluded from inheritance are returned if local
  6647. (should
  6648. (equal '("foo")
  6649. (org-test-with-temp-text "* Test :foo:"
  6650. (let ((org-use-tag-inheritance t)
  6651. (org-tags-exclude-from-inheritance '("foo")))
  6652. (org-get-tags)))))
  6653. ;; Test the collection of tags from #+filetags and parent tags.
  6654. (should
  6655. (equal '("a" "b" "c" "d")
  6656. (org-test-with-temp-text (concat "#+filetags: a\n"
  6657. "* Level 1 :b:\n"
  6658. "** Level 2 :c:\n"
  6659. "*** Level 3 :d:\n"
  6660. "<point>")
  6661. (let ((org-use-tag-inheritance t))
  6662. (org-mode-restart) ;So that `org-file-tags' get populated from #+filetags
  6663. (org-get-tags)))))
  6664. ;; Pathological case: tagged headline with an empty body.
  6665. (should (org-test-with-temp-text "* :tag:" (org-get-tags))))
  6666. (ert-deftest test-org/set-tags ()
  6667. "Test `org-set-tags' specifications."
  6668. ;; Throw an error on invalid data.
  6669. (should-error
  6670. (org-test-with-temp-text "* H"
  6671. (org-set-tags 'foo)))
  6672. ;; `nil', an empty, and a blank string remove all tags.
  6673. (should
  6674. (equal "* H"
  6675. (org-test-with-temp-text "* H :tag1:tag2:"
  6676. (org-set-tags nil)
  6677. (buffer-string))))
  6678. (should
  6679. (equal "* H"
  6680. (org-test-with-temp-text "* H :tag1:tag2:"
  6681. (org-set-tags "")
  6682. (buffer-string))))
  6683. (should
  6684. (equal "* H"
  6685. (org-test-with-temp-text "* H :tag1:tag2:"
  6686. (org-set-tags " ")
  6687. (buffer-string))))
  6688. ;; If there's nothing to remove, just bail out.
  6689. (should
  6690. (equal "* H"
  6691. (org-test-with-temp-text "* H"
  6692. (org-set-tags nil)
  6693. (buffer-string))))
  6694. (should
  6695. (equal "* "
  6696. (org-test-with-temp-text "* "
  6697. (org-set-tags nil)
  6698. (buffer-string))))
  6699. ;; If DATA is a tag string, set current tags to it, even if it means
  6700. ;; replacing old tags.
  6701. (should
  6702. (equal "* H :tag0:"
  6703. (org-test-with-temp-text "* H :tag1:tag2:"
  6704. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  6705. (buffer-string))))
  6706. (should
  6707. (equal "* H :tag0:"
  6708. (org-test-with-temp-text "* H"
  6709. (let ((org-tags-column 1)) (org-set-tags ":tag0:"))
  6710. (buffer-string))))
  6711. ;; If DATA is a list, set tags to this list, even if it means
  6712. ;; replacing old tags.
  6713. (should
  6714. (equal "* H :tag0:"
  6715. (org-test-with-temp-text "* H :tag1:tag2:"
  6716. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6717. (buffer-string))))
  6718. (should
  6719. (equal "* H :tag0:"
  6720. (org-test-with-temp-text "* H"
  6721. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6722. (buffer-string))))
  6723. ;; When set, apply `org-tags-sort-function'.
  6724. (should
  6725. (equal "* H :a:b:"
  6726. (org-test-with-temp-text "* H"
  6727. (let ((org-tags-column 1)
  6728. (org-tags-sort-function #'string<))
  6729. (org-set-tags '("b" "a"))
  6730. (buffer-string)))))
  6731. ;; When new tags are identical to the previous ones, still align.
  6732. (should
  6733. (equal "* H :foo:"
  6734. (org-test-with-temp-text "* H :foo:"
  6735. (let ((org-tags-column 1))
  6736. (org-set-tags '("foo"))
  6737. (buffer-string)))))
  6738. ;; When tags have been changed, run `org-after-tags-change-hook'.
  6739. (should
  6740. (catch :return
  6741. (org-test-with-temp-text "* H :foo:"
  6742. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  6743. (org-set-tags '("bar"))
  6744. nil))))
  6745. (should-not
  6746. (catch :return
  6747. (org-test-with-temp-text "* H :foo:"
  6748. (let ((org-after-tags-change-hook (lambda () (throw :return t))))
  6749. (org-set-tags '("foo"))
  6750. nil))))
  6751. ;; Special case: handle empty headlines.
  6752. (should
  6753. (equal "* :tag0:"
  6754. (org-test-with-temp-text "* "
  6755. (let ((org-tags-column 1)) (org-set-tags '("tag0")))
  6756. (buffer-string))))
  6757. ;; Modify buffer only when a tag change happens or alignment is
  6758. ;; done.
  6759. (should-not
  6760. (org-test-with-temp-text "* H :foo:"
  6761. (set-buffer-modified-p nil)
  6762. (let ((org-tags-column 1)) (org-set-tags '("foo")))
  6763. (buffer-modified-p)))
  6764. (should
  6765. (org-test-with-temp-text "* H :foo:"
  6766. (set-buffer-modified-p nil)
  6767. (let ((org-tags-column 10)) (org-set-tags '("foo")))
  6768. (buffer-modified-p)))
  6769. (should
  6770. (org-test-with-temp-text "* H :foo:"
  6771. (set-buffer-modified-p nil)
  6772. (let ((org-tags-column 10)) (org-set-tags '("bar")))
  6773. (buffer-modified-p)))
  6774. ;; Pathological case: when setting tags of a folded headline, do not
  6775. ;; let new tags being sucked into invisibility.
  6776. (should-not
  6777. (org-test-with-temp-text "* H1\nContent\n* H2\n\n Other Content"
  6778. ;; Show only headlines
  6779. (org-content)
  6780. ;; Set NEXT tag on current entry
  6781. (org-set-tags ":NEXT:")
  6782. ;; Move point to that NEXT tag
  6783. (search-forward "NEXT") (backward-word)
  6784. ;; And it should be visible (i.e. no overlays)
  6785. (overlays-at (point)))))
  6786. (ert-deftest test-org/set-tags-command ()
  6787. "Test `org-set-tags-command' specifications"
  6788. ;; Set tags at current headline.
  6789. (should
  6790. (equal "* H1 :foo:"
  6791. (org-test-with-temp-text "* H1"
  6792. (cl-letf (((symbol-function 'completing-read)
  6793. (lambda (&rest args) ":foo:")))
  6794. (let ((org-use-fast-tag-selection nil)
  6795. (org-tags-column 1))
  6796. (org-set-tags-command)))
  6797. (buffer-string))))
  6798. ;; Preserve position when called from the section below.
  6799. (should
  6800. (equal "* H1 :foo:\nContents"
  6801. (org-test-with-temp-text "* H1\n<point>Contents"
  6802. (cl-letf (((symbol-function 'completing-read)
  6803. (lambda (&rest args) ":foo:")))
  6804. (let ((org-use-fast-tag-selection nil)
  6805. (org-tags-column 1))
  6806. (org-set-tags-command)))
  6807. (buffer-string))))
  6808. (should-not
  6809. (equal "* H1 :foo:\nContents2"
  6810. (org-test-with-temp-text "* H1\n<point>Contents2"
  6811. (cl-letf (((symbol-function 'completing-read)
  6812. (lambda (&rest args) ":foo:")))
  6813. (let ((org-use-fast-tag-selection nil)
  6814. (org-tags-column 1))
  6815. (org-set-tags-command)))
  6816. (org-at-heading-p))))
  6817. ;; Strip all forbidden characters from user-entered tags.
  6818. (should
  6819. (equal "* H1 :foo:"
  6820. (org-test-with-temp-text "* H1"
  6821. (cl-letf (((symbol-function 'completing-read)
  6822. (lambda (&rest args) ": foo *:")))
  6823. (let ((org-use-fast-tag-selection nil)
  6824. (org-tags-column 1))
  6825. (org-set-tags-command)))
  6826. (buffer-string))))
  6827. ;; When a region is active and
  6828. ;; `org-loop-over-headlines-in-active-region' is non-nil, insert the
  6829. ;; same value in all headlines in region.
  6830. (should
  6831. (equal "* H1 :foo:\nContents\n* H2 :foo:"
  6832. (org-test-with-temp-text "* H1\nContents\n* H2"
  6833. (cl-letf (((symbol-function 'completing-read)
  6834. (lambda (&rest args) ":foo:")))
  6835. (let ((org-use-fast-tag-selection nil)
  6836. (org-loop-over-headlines-in-active-region t)
  6837. (org-tags-column 1))
  6838. (transient-mark-mode 1)
  6839. (push-mark (point) t t)
  6840. (goto-char (point-max))
  6841. (org-set-tags-command)))
  6842. (buffer-string))))
  6843. (should
  6844. (equal "* H1\nContents\n* H2 :foo:"
  6845. (org-test-with-temp-text "* H1\nContents\n* H2"
  6846. (cl-letf (((symbol-function 'completing-read)
  6847. (lambda (&rest args) ":foo:")))
  6848. (let ((org-use-fast-tag-selection nil)
  6849. (org-loop-over-headlines-in-active-region nil)
  6850. (org-tags-column 1))
  6851. (transient-mark-mode 1)
  6852. (push-mark (point) t t)
  6853. (goto-char (point-max))
  6854. (org-set-tags-command)))
  6855. (buffer-string))))
  6856. ;; With a C-u prefix argument, align all tags in the buffer.
  6857. (should
  6858. (equal "* H1 :foo:\n* H2 :bar:"
  6859. (org-test-with-temp-text "* H1 :foo:\n* H2 :bar:"
  6860. (let ((org-tags-column 1)) (org-set-tags-command '(4)))
  6861. (buffer-string))))
  6862. ;; Point does not move with empty headline.
  6863. (should
  6864. (equal ":foo:"
  6865. (org-test-with-temp-text "* <point>"
  6866. (cl-letf (((symbol-function 'completing-read)
  6867. (lambda (&rest args) ":foo:")))
  6868. (let ((org-use-fast-tag-selection nil)
  6869. (org-tags-column 1))
  6870. (org-set-tags-command)))
  6871. (buffer-substring (point) (line-end-position)))))
  6872. ;; Point does not move at start of line.
  6873. (should
  6874. (equal "* H1 :foo:"
  6875. (org-test-with-temp-text "* H1"
  6876. (cl-letf (((symbol-function 'completing-read)
  6877. (lambda (&rest args) ":foo:")))
  6878. (let ((org-use-fast-tag-selection nil)
  6879. (org-tags-column 1))
  6880. (org-set-tags-command)))
  6881. (buffer-substring (point) (line-end-position)))))
  6882. ;; Point does not move when within *'s.
  6883. (should
  6884. (equal "* H1 :foo:"
  6885. (org-test-with-temp-text "*<point>* H1"
  6886. (cl-letf (((symbol-function 'completing-read)
  6887. (lambda (&rest args) ":foo:")))
  6888. (let ((org-use-fast-tag-selection nil)
  6889. (org-tags-column 1))
  6890. (org-set-tags-command)))
  6891. (buffer-substring (point) (line-end-position)))))
  6892. ;; Point workaround does not get fooled when looking at a space.
  6893. (should
  6894. (equal " b :foo:"
  6895. (org-test-with-temp-text "* a<point> b"
  6896. (cl-letf (((symbol-function 'completing-read)
  6897. (lambda (&rest args) ":foo:")))
  6898. (let ((org-use-fast-tag-selection nil)
  6899. (org-tags-column 1))
  6900. (org-set-tags-command)))
  6901. (buffer-substring (point) (line-end-position)))))
  6902. ;; Handle tags both set locally and inherited.
  6903. (should
  6904. (equal "b :foo:"
  6905. (org-test-with-temp-text "* a :foo:\n** <point>b :foo:"
  6906. (cl-letf (((symbol-function 'completing-read)
  6907. (lambda (prompt coll &optional pred req initial &rest args)
  6908. initial)))
  6909. (let ((org-use-fast-tag-selection nil)
  6910. (org-tags-column 1))
  6911. (org-set-tags-command)))
  6912. (buffer-substring (point) (line-end-position))))))
  6913. (ert-deftest test-org/toggle-tag ()
  6914. "Test `org-toggle-tag' specifications."
  6915. ;; Insert missing tag.
  6916. (should
  6917. (equal "* H :tag:"
  6918. (org-test-with-temp-text "* H"
  6919. (let ((org-tags-column 1)) (org-toggle-tag "tag"))
  6920. (buffer-string))))
  6921. (should
  6922. (equal "* H :tag1:tag2:"
  6923. (org-test-with-temp-text "* H :tag1:"
  6924. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  6925. (buffer-string))))
  6926. ;; Remove existing tag.
  6927. (should
  6928. (equal "* H"
  6929. (org-test-with-temp-text "* H :tag:"
  6930. (org-toggle-tag "tag")
  6931. (buffer-string))))
  6932. (should
  6933. (equal "* H :tag1:"
  6934. (org-test-with-temp-text "* H :tag1:tag2:"
  6935. (let ((org-tags-column 1)) (org-toggle-tag "tag2"))
  6936. (buffer-string))))
  6937. (should
  6938. (equal "* H :tag2:"
  6939. (org-test-with-temp-text "* H :tag1:tag2:"
  6940. (let ((org-tags-column 1)) (org-toggle-tag "tag1"))
  6941. (buffer-string))))
  6942. ;; With optional argument ONOFF set to `on', try to insert the tag,
  6943. ;; even if its already there.
  6944. (should
  6945. (equal "* H :tag:"
  6946. (org-test-with-temp-text "* H"
  6947. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  6948. (buffer-string))))
  6949. (should
  6950. (equal "* H :tag:"
  6951. (org-test-with-temp-text "* H :tag:"
  6952. (let ((org-tags-column 1)) (org-toggle-tag "tag" 'on))
  6953. (buffer-string))))
  6954. ;; With optional argument ONOFF set to `off', try to remove the tag,
  6955. ;; even if its not there.
  6956. (should
  6957. (equal "* H"
  6958. (org-test-with-temp-text "* H :tag:"
  6959. (org-toggle-tag "tag" 'off)
  6960. (buffer-string))))
  6961. (should
  6962. (equal "* H :tag:"
  6963. (org-test-with-temp-text "* H :tag:"
  6964. (let ((org-tags-column 1)) (org-toggle-tag "foo" 'off))
  6965. (buffer-string))))
  6966. ;; Special case: Handle properly tag inheritance. In particular, do
  6967. ;; not set inherited tags.
  6968. (should
  6969. (equal "* H1 :tag:\n** H2 :tag2:tag:"
  6970. (org-test-with-temp-text "* H1 :tag:\n** <point>H2 :tag2:"
  6971. (let ((org-use-tag-inheritance t)
  6972. (org-tags-column 1))
  6973. (org-toggle-tag "tag"))
  6974. (buffer-string))))
  6975. (should
  6976. (equal "* H1 :tag1:tag2:\n** H2 :foo:"
  6977. (org-test-with-temp-text "* H1 :tag1:tag2:\n** <point>H2"
  6978. (let ((org-use-tag-inheritance t)
  6979. (org-tags-column 1))
  6980. (org-toggle-tag "foo"))
  6981. (buffer-string)))))
  6982. (ert-deftest test-org/tags-expand ()
  6983. "Test `org-tags-expand' specifications."
  6984. ;; Expand tag groups as a regexp enclosed within curly brackets.
  6985. (should
  6986. (equal "{\\<[ABC]\\>}"
  6987. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6988. (org-mode-restart)
  6989. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  6990. (should
  6991. (equal "{\\<\\(?:Aa\\|Bb\\|Cc\\)\\>}"
  6992. (org-test-with-temp-text "#+TAGS: [ Aa : Bb Cc ]"
  6993. (org-mode-restart)
  6994. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "Aa")))))
  6995. ;; Preserve operator before the regexp.
  6996. (should
  6997. (equal "+{\\<[ABC]\\>}"
  6998. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  6999. (org-mode-restart)
  7000. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "+A")))))
  7001. (should
  7002. (equal "-{\\<[ABC]\\>}"
  7003. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7004. (org-mode-restart)
  7005. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "-A")))))
  7006. ;; Handle "|" syntax.
  7007. (should
  7008. (equal "{\\<[ABC]\\>}|D"
  7009. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7010. (org-mode-restart)
  7011. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|D")))))
  7012. ;; Handle nested groups.
  7013. (should
  7014. (equal "{\\<[A-D]\\>}"
  7015. (org-test-with-temp-text "#+TAGS: [ A : B C ]\n#+TAGS: [ B : D ]"
  7016. (org-mode-restart)
  7017. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A")))))
  7018. ;; Expand multiple occurrences of the same group.
  7019. (should
  7020. (equal "{\\<[ABC]\\>}|{\\<[ABC]\\>}"
  7021. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7022. (org-mode-restart)
  7023. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "A|A")))))
  7024. ;; Preserve regexp matches.
  7025. (should
  7026. (equal "{A+}"
  7027. (org-test-with-temp-text "#+TAGS: [ A : B C ]"
  7028. (org-mode-restart)
  7029. (let ((org-tag-alist-for-agenda nil)) (org-tags-expand "{A+}"))))))
  7030. ;;; TODO keywords
  7031. (ert-deftest test-org/auto-repeat-maybe ()
  7032. "Test `org-auto-repeat-maybe' specifications."
  7033. ;; Do not auto repeat when there is no valid time stamp with
  7034. ;; a repeater in the entry.
  7035. (should-not
  7036. (string-prefix-p
  7037. "* TODO H"
  7038. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7039. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu>"
  7040. (org-todo "DONE")
  7041. (buffer-string)))))
  7042. (should-not
  7043. (string-prefix-p
  7044. "* TODO H"
  7045. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7046. (org-test-with-temp-text "* TODO H\n# <2012-03-29 Thu>"
  7047. (org-todo "DONE")
  7048. (buffer-string)))))
  7049. ;; When switching to DONE state, switch back to first TODO keyword
  7050. ;; in sequence, or the same keyword if they have different types.
  7051. (should
  7052. (string-prefix-p
  7053. "* TODO H"
  7054. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7055. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7056. (org-todo "DONE")
  7057. (buffer-string)))))
  7058. (should
  7059. (string-prefix-p
  7060. "* KWD1 H"
  7061. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  7062. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  7063. (org-todo "DONE")
  7064. (buffer-string)))))
  7065. (should
  7066. (string-prefix-p
  7067. "* KWD2 H"
  7068. (let ((org-todo-keywords '((type "KWD1" "KWD2" "DONE"))))
  7069. (org-test-with-temp-text "* KWD2 H\n<2012-03-29 Thu +2y>"
  7070. (org-todo "DONE")
  7071. (buffer-string)))))
  7072. ;; If there was no TODO keyword in the first place, do not insert
  7073. ;; any either.
  7074. (should
  7075. (string-prefix-p
  7076. "* H"
  7077. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7078. (org-test-with-temp-text "* H\n<2012-03-29 Thu +2y>"
  7079. (org-todo "DONE")
  7080. (buffer-string)))))
  7081. ;; Revert to REPEAT_TO_STATE, if set.
  7082. (should
  7083. (string-prefix-p
  7084. "* KWD2 H"
  7085. (let ((org-todo-keywords '((sequence "KWD1" "KWD2" "DONE"))))
  7086. (org-test-with-temp-text
  7087. "* KWD2 H
  7088. :PROPERTIES:
  7089. :REPEAT_TO_STATE: KWD2
  7090. :END:
  7091. <2012-03-29 Thu +2y>"
  7092. (org-todo "DONE")
  7093. (buffer-string)))))
  7094. ;; When switching to DONE state, update base date. If there are
  7095. ;; multiple repeated time stamps, update them all.
  7096. (should
  7097. (string-match-p
  7098. "<2014-03-29 .* \\+2y>"
  7099. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7100. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2y>"
  7101. (org-todo "DONE")
  7102. (buffer-string)))))
  7103. (should
  7104. (string-match-p
  7105. "<2015-03-04 .* \\+1y>"
  7106. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7107. (org-test-with-temp-text
  7108. "* TODO H\n<2012-03-29 Thu. +2y>\n<2014-03-04 Tue +1y>"
  7109. (org-todo "DONE")
  7110. (buffer-string)))))
  7111. ;; Throw an error if repeater unit is the hour and no time is
  7112. ;; provided in the time-stamp.
  7113. (should-error
  7114. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7115. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu +2h>"
  7116. (org-todo "DONE")
  7117. (buffer-string))))
  7118. ;; Handle every repeater type using hours step.
  7119. (should
  7120. (string-match-p
  7121. "2014-03-04 .* 02:00"
  7122. (org-test-at-time "<2014-03-04 02:35>"
  7123. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 +8h>"
  7124. (org-todo "DONE")
  7125. (buffer-string)))))
  7126. (should
  7127. (string-match-p
  7128. "2014-03-04 .* 10:00"
  7129. (org-test-at-time "<2014-03-04 02:35>"
  7130. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 ++8h>"
  7131. (org-todo "DONE")
  7132. (buffer-string)))))
  7133. (should
  7134. (string-match-p
  7135. "2014-03-04 .* 10:35"
  7136. (org-test-at-time "<2014-03-04 02:35>"
  7137. (org-test-with-temp-text "* TODO H\n<2014-03-03 18:00 .+8h>"
  7138. (org-todo "DONE")
  7139. (buffer-string)))))
  7140. ;; Do not repeat inactive time stamps with a repeater.
  7141. (should-not
  7142. (string-match-p
  7143. "\\[2014-03-29 .* \\+2y\\]"
  7144. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7145. (org-test-with-temp-text
  7146. "* TODO H\n[2012-03-29 Thu. +2y]"
  7147. (org-todo "DONE")
  7148. (buffer-string)))))
  7149. ;; Do not repeat commented time stamps.
  7150. (should-not
  7151. (string-prefix-p
  7152. "<2015-03-04 .* \\+1y>"
  7153. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7154. (org-test-with-temp-text
  7155. "* TODO H\n<2012-03-29 Thu +2y>\n# <2014-03-04 Tue +1y>"
  7156. (org-todo "DONE")
  7157. (buffer-string)))))
  7158. (should-not
  7159. (string-prefix-p
  7160. "<2015-03-04 .* \\+1y>"
  7161. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7162. (org-test-with-temp-text
  7163. "* TODO H
  7164. <2012-03-29 Thu. +2y>
  7165. #+BEGIN_EXAMPLE
  7166. <2014-03-04 Tue +1y>
  7167. #+END_EXAMPLE"
  7168. (org-todo "DONE")
  7169. (buffer-string)))))
  7170. ;; When `org-log-repeat' is non-nil or there is a CLOCK in the
  7171. ;; entry, record time of last repeat.
  7172. (should-not
  7173. (string-match-p
  7174. ":LAST_REPEAT:"
  7175. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  7176. (org-log-repeat nil))
  7177. (cl-letf (((symbol-function 'org-add-log-setup)
  7178. (lambda (&rest args) nil)))
  7179. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  7180. (org-todo "DONE")
  7181. (buffer-string))))))
  7182. (should
  7183. (string-match-p
  7184. ":LAST_REPEAT:"
  7185. (let ((org-todo-keywords '((sequence "TODO" "DONE")))
  7186. (org-log-repeat t))
  7187. (cl-letf (((symbol-function 'org-add-log-setup)
  7188. (lambda (&rest args) nil)))
  7189. (org-test-with-temp-text "* TODO H\n<2012-03-29 Thu. +2y>"
  7190. (org-todo "DONE")
  7191. (buffer-string))))))
  7192. (should
  7193. (string-match-p
  7194. ":LAST_REPEAT:"
  7195. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7196. (cl-letf (((symbol-function 'org-add-log-setup)
  7197. (lambda (&rest args) nil)))
  7198. (org-test-with-temp-text
  7199. "* TODO H\n<2012-03-29 Thu +2y>\nCLOCK: [2012-03-29 Thu 16:40]"
  7200. (org-todo "DONE")
  7201. (buffer-string))))))
  7202. ;; When a SCHEDULED entry has no repeater, remove it upon repeating
  7203. ;; the entry as it is no longer relevant.
  7204. (should-not
  7205. (string-match-p
  7206. "^SCHEDULED:"
  7207. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  7208. (org-test-with-temp-text
  7209. "* TODO H\nSCHEDULED: <2014-03-04 Tue>\n<2012-03-29 Thu +2y>"
  7210. (org-todo "DONE")
  7211. (buffer-string)))))
  7212. ;; Properly advance repeater even when a clock entry is specified
  7213. ;; and `org-log-repeat' is nil.
  7214. (should
  7215. (string-match-p
  7216. "SCHEDULED: <2014-03-29"
  7217. (let ((org-log-repeat nil)
  7218. (org-todo-keywords '((sequence "TODO" "DONE"))))
  7219. (org-test-with-temp-text
  7220. "* TODO H
  7221. SCHEDULED: <2012-03-29 Thu +2y>
  7222. CLOCK: [2012-03-29 Thu 10:00]--[2012-03-29 Thu 16:40] => 6:40"
  7223. (org-todo "DONE")
  7224. (buffer-string))))))
  7225. ;;; Timestamps API
  7226. (ert-deftest test-org/at-timestamp-p ()
  7227. "Test `org-at-timestamp-p' specifications."
  7228. (should
  7229. (org-test-with-temp-text "<2012-03-29 Thu>"
  7230. (org-at-timestamp-p)))
  7231. (should-not
  7232. (org-test-with-temp-text "2012-03-29 Thu"
  7233. (org-at-timestamp-p)))
  7234. ;; Test return values.
  7235. (should
  7236. (eq 'bracket
  7237. (org-test-with-temp-text "<2012-03-29 Thu>"
  7238. (org-at-timestamp-p))))
  7239. (should
  7240. (eq 'year
  7241. (org-test-with-temp-text "<<point>2012-03-29 Thu>"
  7242. (org-at-timestamp-p))))
  7243. (should
  7244. (eq 'month
  7245. (org-test-with-temp-text "<2012-<point>03-29 Thu>"
  7246. (org-at-timestamp-p))))
  7247. (should
  7248. (eq 'day
  7249. (org-test-with-temp-text "<2012-03-<point>29 Thu>"
  7250. (org-at-timestamp-p))))
  7251. (should
  7252. (eq 'day
  7253. (org-test-with-temp-text "<2012-03-29 T<point>hu>"
  7254. (org-at-timestamp-p))))
  7255. (should
  7256. (wholenump
  7257. (org-test-with-temp-text "<2012-03-29 Thu +2<point>y>"
  7258. (org-at-timestamp-p))))
  7259. (should
  7260. (eq 'bracket
  7261. (org-test-with-temp-text "<2012-03-29 Thu<point>>"
  7262. (org-at-timestamp-p))))
  7263. (should
  7264. (eq 'after
  7265. (org-test-with-temp-text "<2012-03-29 Thu><point>»"
  7266. (org-at-timestamp-p))))
  7267. ;; Test `inactive' optional argument.
  7268. (should
  7269. (org-test-with-temp-text "[2012-03-29 Thu]"
  7270. (org-at-timestamp-p 'inactive)))
  7271. (should-not
  7272. (org-test-with-temp-text "[2012-03-29 Thu]"
  7273. (org-at-timestamp-p)))
  7274. ;; When optional argument is `agenda', recognize time-stamps in
  7275. ;; planning info line, property drawers and clocks.
  7276. (should
  7277. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7278. (org-at-timestamp-p 'agenda)))
  7279. (should-not
  7280. (org-test-with-temp-text "* H\nSCHEDULED: <point><2012-03-29 Thu>"
  7281. (org-at-timestamp-p)))
  7282. (should
  7283. (org-test-with-temp-text
  7284. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7285. (org-at-timestamp-p 'agenda)))
  7286. (should-not
  7287. (org-test-with-temp-text
  7288. "* H\n:PROPERTIES:\n:PROP: <point><2012-03-29 Thu>\n:END:"
  7289. (org-at-timestamp-p)))
  7290. (should
  7291. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7292. (let ((org-agenda-include-inactive-timestamps t))
  7293. (org-at-timestamp-p 'agenda))))
  7294. (should-not
  7295. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7296. (let ((org-agenda-include-inactive-timestamps t))
  7297. (org-at-timestamp-p))))
  7298. (should-not
  7299. (org-test-with-temp-text "CLOCK: <point>[2012-03-29 Thu]"
  7300. (let ((org-agenda-include-inactive-timestamps t))
  7301. (org-at-timestamp-p 'inactive))))
  7302. ;; When optional argument is `lax', match any part of the document
  7303. ;; with Org timestamp syntax.
  7304. (should
  7305. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7306. (org-at-timestamp-p 'lax)))
  7307. (should-not
  7308. (org-test-with-temp-text "# <2012-03-29 Thu><point>"
  7309. (org-at-timestamp-p)))
  7310. (should
  7311. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7312. (org-at-timestamp-p 'lax)))
  7313. (should-not
  7314. (org-test-with-temp-text ": <2012-03-29 Thu><point>"
  7315. (org-at-timestamp-p)))
  7316. (should
  7317. (org-test-with-temp-text
  7318. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7319. (org-at-timestamp-p 'lax)))
  7320. (should-not
  7321. (org-test-with-temp-text
  7322. "#+BEGIN_EXAMPLE\n<2012-03-29 Thu><point>\n#+END_EXAMPLE"
  7323. (org-at-timestamp-p)))
  7324. ;; Optional argument `lax' also matches inactive timestamps.
  7325. (should
  7326. (org-test-with-temp-text "# [2012-03-29 Thu]<point>"
  7327. (org-at-timestamp-p 'lax))))
  7328. (ert-deftest test-org/time-stamp ()
  7329. "Test `org-time-stamp' specifications."
  7330. ;; Insert chosen time stamp at point.
  7331. (should
  7332. (string-match
  7333. "Te<2014-03-04 .*?>xt"
  7334. (org-test-with-temp-text "Te<point>xt"
  7335. (cl-letf (((symbol-function 'org-read-date)
  7336. (lambda (&rest args)
  7337. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7338. (org-time-stamp nil)
  7339. (buffer-string)))))
  7340. ;; With a prefix argument, also insert time.
  7341. (should
  7342. (string-match
  7343. "Te<2014-03-04 .*? 00:41>xt"
  7344. (org-test-with-temp-text "Te<point>xt"
  7345. (cl-letf (((symbol-function 'org-read-date)
  7346. (lambda (&rest args)
  7347. (apply #'encode-time
  7348. (org-parse-time-string "2014-03-04 00:41")))))
  7349. (org-time-stamp '(4))
  7350. (buffer-string)))))
  7351. ;; With two universal prefix arguments, insert an active timestamp
  7352. ;; with the current time without prompting the user.
  7353. (should
  7354. (string-match
  7355. "Te<2014-03-04 .*? 00:41>xt"
  7356. (org-test-with-temp-text "Te<point>xt"
  7357. (org-test-at-time "2014-03-04 00:41"
  7358. (org-time-stamp '(16))
  7359. (buffer-string)))))
  7360. ;; When optional argument is non-nil, insert an inactive timestamp.
  7361. (should
  7362. (string-match
  7363. "Te\\[2014-03-04 .*?\\]xt"
  7364. (org-test-with-temp-text "Te<point>xt"
  7365. (cl-letf (((symbol-function 'org-read-date)
  7366. (lambda (&rest args)
  7367. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7368. (org-time-stamp nil t)
  7369. (buffer-string)))))
  7370. ;; When called from a timestamp, replace existing one.
  7371. (should
  7372. (string-match
  7373. "<2014-03-04 .*?>"
  7374. (org-test-with-temp-text "<2012-03-29<point> thu.>"
  7375. (cl-letf (((symbol-function 'org-read-date)
  7376. (lambda (&rest args)
  7377. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7378. (org-time-stamp nil)
  7379. (buffer-string)))))
  7380. (should
  7381. (string-match
  7382. "<2014-03-04 .*?>--<2014-03-04 .*?>"
  7383. (org-test-with-temp-text "<2012-03-29<point> thu.>--<2014-03-04 tue.>"
  7384. (cl-letf (((symbol-function 'org-read-date)
  7385. (lambda (&rest args)
  7386. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7387. (org-time-stamp nil)
  7388. (buffer-string)))))
  7389. ;; When replacing a timestamp, preserve repeater, if any.
  7390. (should
  7391. (string-match
  7392. "<2014-03-04 .*? \\+2y>"
  7393. (org-test-with-temp-text "<2012-03-29<point> thu. +2y>"
  7394. (cl-letf (((symbol-function 'org-read-date)
  7395. (lambda (&rest args)
  7396. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7397. (org-time-stamp nil)
  7398. (buffer-string)))))
  7399. ;; When called twice in a raw, build a date range.
  7400. (should
  7401. (string-match
  7402. "<2012-03-29 .*?>--<2014-03-04 .*?>"
  7403. (org-test-with-temp-text "<2012-03-29 thu.><point>"
  7404. (cl-letf (((symbol-function 'org-read-date)
  7405. (lambda (&rest args)
  7406. (apply #'encode-time (org-parse-time-string "2014-03-04")))))
  7407. (let ((last-command 'org-time-stamp)
  7408. (this-command 'org-time-stamp))
  7409. (org-time-stamp nil))
  7410. (buffer-string))))))
  7411. (ert-deftest test-org/timestamp-has-time-p ()
  7412. "Test `org-timestamp-has-time-p' specifications."
  7413. ;; With time.
  7414. (should
  7415. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7416. (org-timestamp-has-time-p (org-element-context))))
  7417. ;; Without time.
  7418. (should-not
  7419. (org-test-with-temp-text "<2012-03-29 Thu>"
  7420. (org-timestamp-has-time-p (org-element-context)))))
  7421. (ert-deftest test-org/get-repeat ()
  7422. "Test `org-get-repeat' specifications."
  7423. (should
  7424. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40 +2y>"
  7425. (org-get-repeat)))
  7426. (should-not
  7427. (org-test-with-temp-text "* H\n<2012-03-29 Thu 16:40>"
  7428. (org-get-repeat)))
  7429. ;; Return proper repeat string.
  7430. (should
  7431. (equal "+2y"
  7432. (org-test-with-temp-text "* H\n<2014-03-04 Tue 16:40 +2y>"
  7433. (org-get-repeat))))
  7434. ;; Prevent false positive (commented or verbatim time stamps)
  7435. (should-not
  7436. (org-test-with-temp-text "* H\n# <2012-03-29 Thu 16:40>"
  7437. (org-get-repeat)))
  7438. (should-not
  7439. (org-test-with-temp-text
  7440. "* H\n#+BEGIN_EXAMPLE\n<2012-03-29 Thu 16:40>\n#+END_EXAMPLE"
  7441. (org-get-repeat)))
  7442. ;; Return nil when called before first heading.
  7443. (should-not
  7444. (org-test-with-temp-text "<2012-03-29 Thu 16:40 +2y>"
  7445. (org-get-repeat)))
  7446. ;; When called with an optional argument, extract repeater from that
  7447. ;; string instead.
  7448. (should (equal "+2y" (org-get-repeat "<2012-03-29 Thu 16:40 +2y>")))
  7449. (should-not (org-get-repeat "<2012-03-29 Thu 16:40>")))
  7450. (ert-deftest test-org/timestamp-format ()
  7451. "Test `org-timestamp-format' specifications."
  7452. ;; Regular test.
  7453. (should
  7454. (equal
  7455. "2012-03-29 16:40"
  7456. (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
  7457. (org-timestamp-format (org-element-context) "%Y-%m-%d %R"))))
  7458. ;; Range end.
  7459. (should
  7460. (equal
  7461. "2012-03-29"
  7462. (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
  7463. (org-timestamp-format (org-element-context) "%Y-%m-%d" t)))))
  7464. (ert-deftest test-org/timestamp-split-range ()
  7465. "Test `org-timestamp-split-range' specifications."
  7466. ;; Extract range start (active).
  7467. (should
  7468. (equal '(2012 3 29)
  7469. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7470. (let ((ts (org-timestamp-split-range (org-element-context))))
  7471. (mapcar (lambda (p) (org-element-property p ts))
  7472. '(:year-end :month-end :day-end))))))
  7473. ;; Extract range start (inactive)
  7474. (should
  7475. (equal '(2012 3 29)
  7476. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7477. (let ((ts (org-timestamp-split-range (org-element-context))))
  7478. (mapcar (lambda (p) (org-element-property p ts))
  7479. '(:year-end :month-end :day-end))))))
  7480. ;; Extract range end (active).
  7481. (should
  7482. (equal '(2012 3 30)
  7483. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7484. (let ((ts (org-timestamp-split-range
  7485. (org-element-context) t)))
  7486. (mapcar (lambda (p) (org-element-property p ts))
  7487. '(:year-end :month-end :day-end))))))
  7488. ;; Extract range end (inactive)
  7489. (should
  7490. (equal '(2012 3 30)
  7491. (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
  7492. (let ((ts (org-timestamp-split-range
  7493. (org-element-context) t)))
  7494. (mapcar (lambda (p) (org-element-property p ts))
  7495. '(:year-end :month-end :day-end))))))
  7496. ;; Return the timestamp if not a range.
  7497. (should
  7498. (org-test-with-temp-text "[2012-03-29 Thu]"
  7499. (let* ((ts-orig (org-element-context))
  7500. (ts-copy (org-timestamp-split-range ts-orig)))
  7501. (eq ts-orig ts-copy))))
  7502. (should
  7503. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7504. (let* ((ts-orig (org-element-context))
  7505. (ts-copy (org-timestamp-split-range ts-orig)))
  7506. (eq ts-orig ts-copy)))))
  7507. (ert-deftest test-org/timestamp-translate ()
  7508. "Test `org-timestamp-translate' specifications."
  7509. ;; Translate whole date range.
  7510. (should
  7511. (equal "<29>--<30>"
  7512. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7513. (let ((org-display-custom-times t)
  7514. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7515. (org-timestamp-translate (org-element-context))))))
  7516. ;; Translate date range start.
  7517. (should
  7518. (equal "<29>"
  7519. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7520. (let ((org-display-custom-times t)
  7521. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7522. (org-timestamp-translate (org-element-context) 'start)))))
  7523. ;; Translate date range end.
  7524. (should
  7525. (equal "<30>"
  7526. (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
  7527. (let ((org-display-custom-times t)
  7528. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7529. (org-timestamp-translate (org-element-context) 'end)))))
  7530. ;; Translate time range.
  7531. (should
  7532. (equal "<08>--<16>"
  7533. (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
  7534. (let ((org-display-custom-times t)
  7535. (org-time-stamp-custom-formats '("<%d>" . "<%H>")))
  7536. (org-timestamp-translate (org-element-context))))))
  7537. ;; Translate non-range timestamp.
  7538. (should
  7539. (equal "<29>"
  7540. (org-test-with-temp-text "<2012-03-29 Thu>"
  7541. (let ((org-display-custom-times t)
  7542. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7543. (org-timestamp-translate (org-element-context))))))
  7544. ;; Do not change `diary' timestamps.
  7545. (should
  7546. (equal "<%%(org-float t 4 2)>"
  7547. (org-test-with-temp-text "<%%(org-float t 4 2)>"
  7548. (let ((org-display-custom-times t)
  7549. (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
  7550. (org-timestamp-translate (org-element-context)))))))
  7551. (ert-deftest test-org/timestamp-from-string ()
  7552. "Test `org-timestamp-from-string' specifications."
  7553. ;; Return nil if argument is not a valid Org timestamp.
  7554. (should-not (org-timestamp-from-string ""))
  7555. (should-not (org-timestamp-from-string nil))
  7556. (should-not (org-timestamp-from-string "<2012-03-29"))
  7557. ;; Otherwise, return a valid Org timestamp object.
  7558. (should
  7559. (string-match-p "<2012-03-29 .+>"
  7560. (org-element-interpret-data
  7561. (org-timestamp-from-string "<2012-03-29 Thu>"))))
  7562. (should
  7563. (string-match-p "[2014-03-04 .+]"
  7564. (org-element-interpret-data
  7565. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  7566. (ert-deftest test-org/timestamp-from-time ()
  7567. "Test `org-timestamp-from-time' specifications."
  7568. ;; Standard test.
  7569. (should
  7570. (string-match-p
  7571. "<2012-03-29 .+>"
  7572. (org-element-interpret-data
  7573. (org-timestamp-from-time
  7574. (apply #'encode-time
  7575. (org-parse-time-string "<2012-03-29 Thu 16:40>"))))))
  7576. ;; When optional argument WITH-TIME is non-nil, provide time
  7577. ;; information.
  7578. (should
  7579. (string-match-p
  7580. "<2012-03-29 .+ 16:40>"
  7581. (org-element-interpret-data
  7582. (org-timestamp-from-time
  7583. (apply #'encode-time
  7584. (org-parse-time-string "<2012-03-29 Thu 16:40>"))
  7585. t))))
  7586. ;; When optional argument INACTIVE is non-nil, return an inactive
  7587. ;; timestamp.
  7588. (should
  7589. (string-match-p
  7590. "[2012-03-29 .+]"
  7591. (org-element-interpret-data
  7592. (org-timestamp-from-time
  7593. (apply #'encode-time
  7594. (org-parse-time-string "<2012-03-29 Thu 16:40>"))
  7595. nil t)))))
  7596. (ert-deftest test-org/timestamp-to-time ()
  7597. "Test `org-timestamp-to-time' specifications."
  7598. (should
  7599. (equal "2014-03-04"
  7600. (format-time-string
  7601. "%Y-%m-%d"
  7602. (org-timestamp-to-time
  7603. (org-timestamp-from-string "<2014-03-04 Tue>")))))
  7604. (should
  7605. (equal "2014-03-04"
  7606. (format-time-string
  7607. "%Y-%m-%d"
  7608. (org-timestamp-to-time
  7609. (org-timestamp-from-string "[2014-03-04 Tue]")))))
  7610. (should
  7611. (equal "2012-03-29 08:30"
  7612. (format-time-string
  7613. "%Y-%m-%d %H:%M"
  7614. (org-timestamp-to-time
  7615. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")))))
  7616. (should
  7617. (equal "2012-03-29"
  7618. (format-time-string
  7619. "%Y-%m-%d"
  7620. (org-timestamp-to-time
  7621. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")))))
  7622. (should
  7623. (equal "2012-03-29"
  7624. (format-time-string
  7625. "%Y-%m-%d"
  7626. (org-timestamp-to-time
  7627. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")))))
  7628. ;; When optional argument END is non-nil, use end of date range or
  7629. ;; time range.
  7630. (should
  7631. (equal "2012-03-29 16:40"
  7632. (format-time-string
  7633. "%Y-%m-%d %H:%M"
  7634. (org-timestamp-to-time
  7635. (org-timestamp-from-string "<2012-03-29 Thu 08:30-16:40>")
  7636. t))))
  7637. (should
  7638. (equal "2014-03-04"
  7639. (format-time-string
  7640. "%Y-%m-%d"
  7641. (org-timestamp-to-time
  7642. (org-timestamp-from-string "<2012-03-29 Thu>--<2014-03-04 Tue>")
  7643. t))))
  7644. (should
  7645. (equal "2014-03-04"
  7646. (format-time-string
  7647. "%Y-%m-%d"
  7648. (org-timestamp-to-time
  7649. (org-timestamp-from-string "[2012-03-29 Thu]--[2014-03-04 Tue]")
  7650. t)))))
  7651. ;;; Visibility
  7652. (ert-deftest test-org/hide-drawer-toggle ()
  7653. "Test `org-hide-drawer-toggle' specifications."
  7654. ;; Error when not at a drawer.
  7655. (should-error
  7656. (org-test-with-temp-text ":fake-drawer:\ncontents"
  7657. (org-hide-drawer-toggle 'off)
  7658. (get-char-property (line-end-position) 'invisible)))
  7659. (should-error
  7660. (org-test-with-temp-text
  7661. "#+begin_example\n<point>:D:\nc\n:END:\n#+end_example"
  7662. (org-hide-drawer-toggle t)))
  7663. ;; Hide drawer.
  7664. (should
  7665. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7666. (org-hide-drawer-toggle)
  7667. (get-char-property (line-end-position) 'invisible)))
  7668. ;; Show drawer unconditionally when optional argument is `off'.
  7669. (should-not
  7670. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7671. (org-hide-drawer-toggle)
  7672. (org-hide-drawer-toggle 'off)
  7673. (get-char-property (line-end-position) 'invisible)))
  7674. ;; Hide drawer unconditionally when optional argument is non-nil.
  7675. (should
  7676. (org-test-with-temp-text ":drawer:\ncontents\n:end:"
  7677. (org-hide-drawer-toggle t)
  7678. (get-char-property (line-end-position) 'invisible)))
  7679. ;; Do not hide drawer when called from final blank lines.
  7680. (should-not
  7681. (org-test-with-temp-text ":drawer:\ncontents\n:end:\n\n<point>"
  7682. (org-hide-drawer-toggle)
  7683. (goto-char (point-min))
  7684. (get-char-property (line-end-position) 'invisible)))
  7685. ;; Don't leave point in an invisible part of the buffer when hiding
  7686. ;; a drawer away.
  7687. (should-not
  7688. (org-test-with-temp-text ":drawer:\ncontents\n<point>:end:"
  7689. (org-hide-drawer-toggle)
  7690. (get-char-property (point) 'invisible))))
  7691. (ert-deftest test-org/hide-block-toggle ()
  7692. "Test `org-hide-block-toggle' specifications."
  7693. ;; Error when not at a block.
  7694. (should-error
  7695. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents"
  7696. (org-hide-block-toggle 'off)
  7697. (get-char-property (line-end-position) 'invisible)))
  7698. ;; Hide block.
  7699. (should
  7700. (org-test-with-temp-text "#+BEGIN_CENTER\ncontents\n#+END_CENTER"
  7701. (org-hide-block-toggle)
  7702. (get-char-property (line-end-position) 'invisible)))
  7703. (should
  7704. (org-test-with-temp-text "#+BEGIN_EXAMPLE\ncontents\n#+END_EXAMPLE"
  7705. (org-hide-block-toggle)
  7706. (get-char-property (line-end-position) 'invisible)))
  7707. ;; Show block unconditionally when optional argument is `off'.
  7708. (should-not
  7709. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7710. (org-hide-block-toggle)
  7711. (org-hide-block-toggle 'off)
  7712. (get-char-property (line-end-position) 'invisible)))
  7713. (should-not
  7714. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7715. (org-hide-block-toggle 'off)
  7716. (get-char-property (line-end-position) 'invisible)))
  7717. ;; Hide block unconditionally when optional argument is non-nil.
  7718. (should
  7719. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7720. (org-hide-block-toggle t)
  7721. (get-char-property (line-end-position) 'invisible)))
  7722. (should
  7723. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE"
  7724. (org-hide-block-toggle)
  7725. (org-hide-block-toggle t)
  7726. (get-char-property (line-end-position) 'invisible)))
  7727. ;; Do not hide block when called from final blank lines.
  7728. (should-not
  7729. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n#+END_QUOTE\n\n<point>"
  7730. (org-hide-block-toggle)
  7731. (goto-char (point-min))
  7732. (get-char-property (line-end-position) 'invisible)))
  7733. ;; Don't leave point in an invisible part of the buffer when hiding
  7734. ;; a block away.
  7735. (should-not
  7736. (org-test-with-temp-text "#+BEGIN_QUOTE\ncontents\n<point>#+END_QUOTE"
  7737. (org-hide-block-toggle)
  7738. (get-char-property (point) 'invisible))))
  7739. (ert-deftest test-org/hide-block-toggle-maybe ()
  7740. "Test `org-hide-block-toggle-maybe' specifications."
  7741. (should
  7742. (org-test-with-temp-text "#+BEGIN: dynamic\nContents\n#+END:"
  7743. (org-hide-block-toggle-maybe)))
  7744. (should-not
  7745. (org-test-with-temp-text "Paragraph" (org-hide-block-toggle-maybe))))
  7746. (ert-deftest test-org/show-set-visibility ()
  7747. "Test `org-show-set-visibility' specifications."
  7748. ;; Do not throw an error before first heading.
  7749. (should
  7750. (org-test-with-temp-text "Preamble\n* Headline"
  7751. (org-show-set-visibility 'tree)
  7752. t))
  7753. ;; Test all visibility spans, both on headline and in entry.
  7754. (let ((list-visible-lines
  7755. (lambda (state headerp)
  7756. (org-test-with-temp-text "* Grandmother (0)
  7757. ** Uncle (1)
  7758. *** Heir (2)
  7759. ** Father (3)
  7760. Ancestor text (4)
  7761. *** Sister (5)
  7762. Sibling text (6)
  7763. *** Self (7)
  7764. Match (8)
  7765. **** First born (9)
  7766. Child text (10)
  7767. **** The other child (11)
  7768. *** Brother (12)
  7769. ** Aunt (13)
  7770. "
  7771. (org-cycle t)
  7772. (search-forward (if headerp "Self" "Match"))
  7773. (org-show-set-visibility state)
  7774. (goto-char (point-min))
  7775. (let (result (line 0))
  7776. (while (not (eobp))
  7777. (unless (org-invisible-p2) (push line result))
  7778. (cl-incf line)
  7779. (forward-line))
  7780. (nreverse result))))))
  7781. (should (equal '(0 7) (funcall list-visible-lines 'minimal t)))
  7782. (should (equal '(0 7 8) (funcall list-visible-lines 'minimal nil)))
  7783. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local t)))
  7784. (should (equal '(0 7 8 9) (funcall list-visible-lines 'local nil)))
  7785. (should (equal '(0 3 7) (funcall list-visible-lines 'ancestors t)))
  7786. (should (equal '(0 3 7 8) (funcall list-visible-lines 'ancestors nil)))
  7787. (should (equal '(0 3 7 8 9 10 11)
  7788. (funcall list-visible-lines 'ancestors-full t)))
  7789. (should (equal '(0 3 7 8 9 10 11)
  7790. (funcall list-visible-lines 'ancestors-full nil)))
  7791. (should (equal '(0 3 5 7 12) (funcall list-visible-lines 'lineage t)))
  7792. (should (equal '(0 3 5 7 8 9 12) (funcall list-visible-lines 'lineage nil)))
  7793. (should (equal '(0 1 3 5 7 12 13) (funcall list-visible-lines 'tree t)))
  7794. (should (equal '(0 1 3 5 7 8 9 11 12 13)
  7795. (funcall list-visible-lines 'tree nil)))
  7796. (should (equal '(0 1 3 4 5 7 12 13)
  7797. (funcall list-visible-lines 'canonical t)))
  7798. (should (equal '(0 1 3 4 5 7 8 9 11 12 13)
  7799. (funcall list-visible-lines 'canonical nil))))
  7800. ;; When point is hidden in a drawer or a block, make sure to make it
  7801. ;; visible.
  7802. (should-not
  7803. (org-test-with-temp-text "#+BEGIN_QUOTE\nText\n#+END_QUOTE"
  7804. (org-hide-block-toggle)
  7805. (search-forward "Text")
  7806. (org-show-set-visibility 'minimal)
  7807. (org-invisible-p2)))
  7808. (should-not
  7809. (org-test-with-temp-text ":DRAWER:\nText\n:END:"
  7810. (org-hide-drawer-toggle)
  7811. (search-forward "Text")
  7812. (org-show-set-visibility 'minimal)
  7813. (org-invisible-p2)))
  7814. (should-not
  7815. (org-test-with-temp-text
  7816. "#+BEGIN_QUOTE\n<point>:DRAWER:\nText\n:END:\n#+END_QUOTE"
  7817. (org-hide-drawer-toggle)
  7818. (forward-line -1)
  7819. (org-hide-block-toggle)
  7820. (search-forward "Text")
  7821. (org-show-set-visibility 'minimal)
  7822. (org-invisible-p2))))
  7823. (defun test-org/copy-visible ()
  7824. "Test `org-copy-visible' specifications."
  7825. (should
  7826. (equal "Foo"
  7827. (org-test-with-temp-text "Foo"
  7828. (let ((kill-ring nil))
  7829. (org-copy-visible (point-min) (point-max))
  7830. (current-kill 0 t)))))
  7831. ;; Skip invisible characters by text property.
  7832. (should
  7833. (equal "Foo"
  7834. (org-test-with-temp-text #("F<hidden>oo" 1 7 (invisible t))
  7835. (let ((kill-ring nil))
  7836. (org-copy-visible (point-min) (point-max))
  7837. (current-kill 0 t)))))
  7838. ;; Skip invisible characters by overlay.
  7839. (should
  7840. (equal "Foo"
  7841. (org-test-with-temp-text "F<hidden>oo"
  7842. (let ((o (make-overlay 2 10)))
  7843. (overlay-put o 'invisible t))
  7844. (let ((kill-ring nil))
  7845. (org-copy-visible (point-min) (point-max))
  7846. (current-kill 0 t)))))
  7847. ;; Handle invisible characters at the beginning and the end of the
  7848. ;; buffer.
  7849. (should
  7850. (equal "Foo"
  7851. (org-test-with-temp-text #("<hidden>Foo" 0 8 (invisible t))
  7852. (let ((kill-ring nil))
  7853. (org-copy-visible (point-min) (point-max))
  7854. (current-kill 0 t)))))
  7855. (should
  7856. (equal "Foo"
  7857. (org-test-with-temp-text #("Foo<hidden>" 3 11 (invisible t))
  7858. (let ((kill-ring nil))
  7859. (org-copy-visible (point-min) (point-max))
  7860. (current-kill 0 t)))))
  7861. ;; Handle multiple visible parts.
  7862. (should
  7863. (equal "abc"
  7864. (org-test-with-temp-text
  7865. #("aXbXc" 1 2 (invisible t) 3 4 (invisible t))
  7866. (let ((kill-ring nil))
  7867. (org-copy-visible (point-min) (point-max))
  7868. (current-kill 0 t))))))
  7869. (ert-deftest test-org/set-visibility-according-to-property ()
  7870. "Test `org-set-visibility-according-to-property' specifications."
  7871. ;; "folded" state.
  7872. (should
  7873. (org-test-with-temp-text
  7874. "
  7875. * a
  7876. :PROPERTIES:
  7877. :VISIBILITY: folded
  7878. :END:
  7879. ** <point>b"
  7880. (org-set-visibility-according-to-property)
  7881. (invisible-p (point))))
  7882. ;; "children" state.
  7883. (should
  7884. (org-test-with-temp-text
  7885. "
  7886. * a
  7887. :PROPERTIES:
  7888. :VISIBILITY: children
  7889. :END:
  7890. ** b
  7891. <point>Contents
  7892. ** c"
  7893. (org-set-visibility-according-to-property)
  7894. (invisible-p (point))))
  7895. (should
  7896. (org-test-with-temp-text
  7897. "
  7898. * a
  7899. :PROPERTIES:
  7900. :VISIBILITY: children
  7901. :END:
  7902. ** b
  7903. Contents
  7904. *** <point>c"
  7905. (org-set-visibility-according-to-property)
  7906. (invisible-p (point))))
  7907. ;; "content" state.
  7908. (should
  7909. (org-test-with-temp-text
  7910. "
  7911. * a
  7912. :PROPERTIES:
  7913. :VISIBILITY: content
  7914. :END:
  7915. ** b
  7916. <point>Contents
  7917. *** c"
  7918. (org-set-visibility-according-to-property)
  7919. (invisible-p (point))))
  7920. (should
  7921. (org-test-with-temp-text
  7922. "
  7923. * a
  7924. :PROPERTIES:
  7925. :VISIBILITY: content
  7926. :END:
  7927. ** b
  7928. Contents
  7929. *** <point>c"
  7930. (org-set-visibility-according-to-property)
  7931. (not (invisible-p (point)))))
  7932. ;; "showall" state.
  7933. (should
  7934. (org-test-with-temp-text
  7935. "
  7936. * a
  7937. :PROPERTIES:
  7938. :VISIBILITY: showall
  7939. :END:
  7940. ** b
  7941. <point>Contents
  7942. *** c"
  7943. (org-set-visibility-according-to-property)
  7944. (not (invisible-p (point)))))
  7945. (should
  7946. (org-test-with-temp-text
  7947. "
  7948. * a
  7949. :PROPERTIES:
  7950. :VISIBILITY: showall
  7951. :END:
  7952. ** b
  7953. Contents
  7954. *** <point>c"
  7955. (org-set-visibility-according-to-property)
  7956. (not (invisible-p (point)))))
  7957. ;; When VISIBILITY properties are nested, ignore inner ones.
  7958. (should
  7959. (org-test-with-temp-text
  7960. "
  7961. * A
  7962. :PROPERTIES:
  7963. :VISIBILITY: folded
  7964. :END:
  7965. ** <point>B
  7966. :PROPERTIES:
  7967. :VISIBILITY: folded
  7968. :END:"
  7969. (org-set-visibility-according-to-property)
  7970. (invisible-p (point)))))
  7971. (ert-deftest test-org/visibility-show-branches ()
  7972. "Test visibility of inline archived subtrees."
  7973. (org-test-with-temp-text
  7974. "* Foo<point>
  7975. ** Bar :ARCHIVE:
  7976. *** Baz
  7977. "
  7978. (org-kill-note-or-show-branches)
  7979. (should (org-invisible-p (- (point-max) 2)))))
  7980. ;;; Yank and Kill
  7981. (ert-deftest test-org/paste-subtree ()
  7982. "Test `org-paste-subtree' specifications."
  7983. ;; Return an error if text to yank is not a set of subtrees.
  7984. (should-error (org-paste-subtree nil "Text"))
  7985. ;; Adjust level according to current one.
  7986. (should
  7987. (equal "* H\n* Text\n"
  7988. (org-test-with-temp-text "* H\n<point>"
  7989. (org-paste-subtree nil "* Text")
  7990. (buffer-string))))
  7991. (should
  7992. (equal "* H1\n** H2\n** Text\n"
  7993. (org-test-with-temp-text "* H1\n** H2\n<point>"
  7994. (org-paste-subtree nil "* Text")
  7995. (buffer-string))))
  7996. ;; When not on a heading, move to next heading before yanking.
  7997. (should
  7998. (equal "* H1\nParagraph\n* Text\n* H2"
  7999. (org-test-with-temp-text "* H1\n<point>Paragraph\n* H2"
  8000. (org-paste-subtree nil "* Text")
  8001. (buffer-string))))
  8002. ;; If point is between two headings, use the deepest level.
  8003. (should
  8004. (equal "* H1\n\n* Text\n* H2"
  8005. (org-test-with-temp-text "* H1\n<point>\n* H2"
  8006. (org-paste-subtree nil "* Text")
  8007. (buffer-string))))
  8008. (should
  8009. (equal "** H1\n\n** Text\n* H2"
  8010. (org-test-with-temp-text "** H1\n<point>\n* H2"
  8011. (org-paste-subtree nil "* Text")
  8012. (buffer-string))))
  8013. (should
  8014. (equal "* H1\n\n** Text\n** H2"
  8015. (org-test-with-temp-text "* H1\n<point>\n** H2"
  8016. (org-paste-subtree nil "* Text")
  8017. (buffer-string))))
  8018. ;; When on an empty heading, after the stars, deduce the new level
  8019. ;; from the number of stars.
  8020. (should
  8021. (equal "*** Text\n"
  8022. (org-test-with-temp-text "*** <point>"
  8023. (org-paste-subtree nil "* Text")
  8024. (buffer-string))))
  8025. ;; Optional argument LEVEL forces a level for the subtree.
  8026. (should
  8027. (equal "* H\n*** Text\n"
  8028. (org-test-with-temp-text "* H<point>"
  8029. (org-paste-subtree 3 "* Text")
  8030. (buffer-string)))))
  8031. (ert-deftest test-org/cut-and-paste-subtree ()
  8032. "Test `org-cut-subtree' and `org-paste-subtree'."
  8033. (should
  8034. (equal
  8035. "* Two
  8036. two
  8037. * One
  8038. "
  8039. (org-test-with-temp-text
  8040. "* One
  8041. <point>* Two
  8042. two
  8043. "
  8044. (call-interactively #'org-cut-subtree)
  8045. (goto-char (point-min))
  8046. (call-interactively #'org-paste-subtree)
  8047. (buffer-string))))
  8048. (should
  8049. (equal
  8050. "* One
  8051. * Two
  8052. "
  8053. (org-test-with-temp-text
  8054. "* One
  8055. <point>* Two
  8056. "
  8057. (call-interactively #'org-cut-subtree)
  8058. (backward-char)
  8059. (call-interactively #'org-paste-subtree)
  8060. (buffer-string)))))
  8061. (provide 'test-org)
  8062. ;;; test-org.el ends here