test-org.el 248 KB

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