test-org.el 264 KB

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