test-org.el 248 KB

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