test-org.el 268 KB

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